Gentoo Websites Logo
Go to: Gentoo Home Documentation Forums Lists Bugs Planet Store Wiki Get Gentoo!
View | Details | Raw Unified | Return to bug 556566
Collapse All | Expand All

(-)a/bin/named/Makefile.in (-3 / +3 lines)
Lines 34-43 top_srcdir = @top_srcdir@ Link Here
34
#
34
#
35
# Add database drivers here.
35
# Add database drivers here.
36
#
36
#
37
DBDRIVER_OBJS =
37
DBDRIVER_OBJS =	ldapdb.@O@
38
DBDRIVER_SRCS =
38
DBDRIVER_SRCS =	ldapdb.c
39
DBDRIVER_INCLUDES =
39
DBDRIVER_INCLUDES =
40
DBDRIVER_LIBS =
40
DBDRIVER_LIBS =	-lldap -llber -ldb
41
41
42
DLZ_DRIVER_DIR =	${top_srcdir}/contrib/dlz/drivers
42
DLZ_DRIVER_DIR =	${top_srcdir}/contrib/dlz/drivers
43
43
(-)a/bin/named/main.c (+23 lines)
Lines 90-95 Link Here
90
 * Include header files for database drivers here.
90
 * Include header files for database drivers here.
91
 */
91
 */
92
/* #include "xxdb.h" */
92
/* #include "xxdb.h" */
93
#include "ldapdb.h"
93
94
94
#ifdef CONTRIB_DLZ
95
#ifdef CONTRIB_DLZ
95
/*
96
/*
Lines 803-808 dump_symboltable(void) { Link Here
803
	if (!isc_log_wouldlog(ns_g_lctx, ISC_LOG_DEBUG(99)))
804
	if (!isc_log_wouldlog(ns_g_lctx, ISC_LOG_DEBUG(99)))
804
		return;
805
		return;
805
806
807
	ldapdb_clear();
808
806
	isc_log_write(ns_g_lctx, NS_LOGCATEGORY_GENERAL, NS_LOGMODULE_MAIN,
809
	isc_log_write(ns_g_lctx, NS_LOGCATEGORY_GENERAL, NS_LOGMODULE_MAIN,
807
		      ISC_LOG_DEBUG(99), "Symbol table:");
810
		      ISC_LOG_DEBUG(99), "Symbol table:");
808
811
Lines 1084-1089 setup(void) { Link Here
1084
				   isc_result_totext(result));
1087
				   isc_result_totext(result));
1085
#endif
1088
#endif
1086
1089
1090
        result = ldapdb_init();
1091
        if (result != ISC_R_SUCCESS)
1092
        {
1093
            isc_log_write(ns_g_lctx, NS_LOGCATEGORY_GENERAL, NS_LOGMODULE_MAIN,
1094
                          ISC_LOG_ERROR, 
1095
                          "SDB ldap module initialisation failed: %s.",
1096
                          isc_result_totext(result)
1097
                );
1098
            isc_log_write(ns_g_lctx, NS_LOGCATEGORY_GENERAL, NS_LOGMODULE_MAIN,
1099
                          ISC_LOG_ERROR, 
1100
                          "SDB ldap zone database will be unavailable."
1101
                );
1102
        }else
1103
            isc_log_write(ns_g_lctx, NS_LOGCATEGORY_GENERAL, NS_LOGMODULE_MAIN,
1104
                          ISC_LOG_NOTICE, "SDB ldap zone database module loaded."
1105
                         );
1106
1107
1087
	ns_server_create(ns_g_mctx, &ns_g_server);
1108
	ns_server_create(ns_g_mctx, &ns_g_server);
1088
1109
1089
#ifdef HAVE_LIBSECCOMP
1110
#ifdef HAVE_LIBSECCOMP
Lines 1119-1124 cleanup(void) { Link Here
1119
1140
1120
	dns_name_destroy();
1141
	dns_name_destroy();
1121
1142
1143
        ldapdb_clear();
1144
1122
	isc_log_write(ns_g_lctx, NS_LOGCATEGORY_GENERAL, NS_LOGMODULE_MAIN,
1145
	isc_log_write(ns_g_lctx, NS_LOGCATEGORY_GENERAL, NS_LOGMODULE_MAIN,
1123
		      ISC_LOG_NOTICE, "exiting");
1146
		      ISC_LOG_NOTICE, "exiting");
1124
	ns_log_shutdown();
1147
	ns_log_shutdown();
(-)a/bin/tools/Makefile.in (-7 / +27 lines)
Lines 23-55 top_srcdir = @top_srcdir@ Link Here
23
CINCLUDES =	${DNS_INCLUDES} ${ISC_INCLUDES} ${ISCCFG_INCLUDES} \
23
CINCLUDES =	${DNS_INCLUDES} ${ISC_INCLUDES} ${ISCCFG_INCLUDES} \
24
		${LWRES_INCLUDES} ${OMAPI_INCLUDES}
24
		${LWRES_INCLUDES} ${OMAPI_INCLUDES}
25
25
26
CDEFINES =
26
CDEFINES = -DBIND9
27
CWARNINGS =
27
CWARNINGS =
28
28
29
DNSLIBS =	../../lib/dns/libdns.@A@ @DNS_CRYPTO_LIBS@
29
DNSLIBS =	../../lib/dns/libdns.@A@ @DNS_CRYPTO_LIBS@
30
ISCCFGLIBS =	../../lib/isccfg/libisccfg.@A@
31
ISCCCLIBS =	../../lib/isccc/libisccc.@A@
30
ISCLIBS =	../../lib/isc/libisc.@A@ @DNS_CRYPTO_LIBS@
32
ISCLIBS =	../../lib/isc/libisc.@A@ @DNS_CRYPTO_LIBS@
31
ISCNOSYMLIBS =	../../lib/isc/libisc-nosymtbl.@A@
33
ISCNOSYMLIBS =	../../lib/isc/libisc-nosymtbl.@A@
32
ISCCFGLIBS = 	../../lib/isccfg/libisccfg.@A@
33
LWRESLIBS =	../../lib/lwres/liblwres.@A@
34
LWRESLIBS =	../../lib/lwres/liblwres.@A@
35
BIND9LIBS =	../../lib/bind9/libbind9.@A@
34
36
35
DNSDEPLIBS =	../../lib/dns/libdns.@A@
37
DNSDEPLIBS =	../../lib/dns/libdns.@A@
38
ISCCFGDEPLIBS =	../../lib/isccfg/libisccfg.@A@
39
ISCCCDEPLIBS =	../../lib/isccc/libisccc.@A@
36
ISCDEPLIBS =	../../lib/isc/libisc.@A@
40
ISCDEPLIBS =	../../lib/isc/libisc.@A@
37
ISCCFGDEPLIBS = ../../lib/isccfg/libisccfg.@A@
38
LWRESDEPLIBS =	../../lib/lwres/liblwres.@A@
41
LWRESDEPLIBS =	../../lib/lwres/liblwres.@A@
42
BIND9DEPLIBS =	../../lib/bind9/libbind9.@A@
43
DEPLIBS =	${LWRESDEPLIBS} ${DNSDEPLIBS} ${BIND9DEPLIBS} \
44
		${ISCCFGDEPLIBS} ${ISCCCDEPLIBS} ${ISCDEPLIBS}
45
46
LIBS =		${LWRESLIBS} ${DNSLIBS} ${BIND9LIBS} \
47
		${ISCCFGLIBS} ${ISCCCLIBS} ${ISCLIBS} ${DBDRIVER_LIBS} @LIBS@
48
39
49
40
LIBS =		${ISCLIBS} @LIBS@
41
NOSYMLIBS =	${ISCNOSYMLIBS} @LIBS@
50
NOSYMLIBS =	${ISCNOSYMLIBS} @LIBS@
42
51
43
SUBDIRS = 
52
SUBDIRS = 
44
53
45
TARGETS =	arpaname@EXEEXT@ named-journalprint@EXEEXT@ \
54
TARGETS =	arpaname@EXEEXT@ named-journalprint@EXEEXT@ \
46
		named-rrchecker@EXEEXT@  nsec3hash@EXEEXT@ \
55
		named-rrchecker@EXEEXT@  nsec3hash@EXEEXT@ \
47
		genrandom@EXEEXT@ isc-hmac-fixup@EXEEXT@
56
		genrandom@EXEEXT@ isc-hmac-fixup@EXEEXT@ ldap2zone@EXEEXT@ \
57
		zone2ldap@EXEEXT@
48
SRCS =		arpaname.c named-journalprint.c named-rrchecker.c \
58
SRCS =		arpaname.c named-journalprint.c named-rrchecker.c \
49
		nsec3hash.c genrandom.c isc-hmac-fixup.c
59
		nsec3hash.c genrandom.c isc-hmac-fixup.c ldap2zone.c zone2ldap.c
50
60
51
MANPAGES =	arpaname.1 named-journalprint.8 named-rrchecker.1 nsec3hash.8 \
61
MANPAGES =	arpaname.1 named-journalprint.8 named-rrchecker.1 nsec3hash.8 \
52
		genrandom.8 isc-hmac-fixup.8
62
		genrandom.8 isc-hmac-fixup.8 ldap2zone.1 zone2ldap.1
53
HTMLPAGES =	arpaname.html named-journalprint.html named-rrchecker.html \
63
HTMLPAGES =	arpaname.html named-journalprint.html named-rrchecker.html \
54
		nsec3hash.html genrandom.html isc-hmac-fixup.html
64
		nsec3hash.html genrandom.html isc-hmac-fixup.html
55
MANOBJS =	${MANPAGES} ${HTMLPAGES}
65
MANOBJS =	${MANPAGES} ${HTMLPAGES}
Lines 84-89 genrandom@EXEEXT@: genrandom.@O@ Link Here
84
	${LIBTOOL_MODE_LINK} ${PURIFY} ${CC} ${CFLAGS} ${LDFLAGS} \
94
	${LIBTOOL_MODE_LINK} ${PURIFY} ${CC} ${CFLAGS} ${LDFLAGS} \
85
		-o $@ genrandom.@O@ @GENRANDOMLIB@ ${LIBS}
95
		-o $@ genrandom.@O@ @GENRANDOMLIB@ ${LIBS}
86
96
97
ldap2zone@EXEEXT@: ldap2zone.@O@ ${DEPLIBS}
98
	${LIBTOOL_MODE_LINK} ${PURIFY} ${CC} ${CFLAGS} ${LDFLAGS} -o $@ ldap2zone.@O@ -lldap -llber ${LIBS}
99
100
zone2ldap@EXEEXT@: zone2ldap.@O@ ${DEPLIBS}
101
	${LIBTOOL_MODE_LINK} ${PURIFY} ${CC} ${CFLAGS} ${LDFLAGS} -o $@ zone2ldap.@O@ -lldap -llber ${LIBS}
102
87
doc man:: ${MANOBJS}
103
doc man:: ${MANOBJS}
88
104
89
docclean manclean maintainer-clean::
105
docclean manclean maintainer-clean::
Lines 107-113 install:: ${TARGETS} installdirs Link Here
107
		${DESTDIR}${sbindir}
123
		${DESTDIR}${sbindir}
108
	${LIBTOOL_MODE_INSTALL} ${INSTALL_PROGRAM} isc-hmac-fixup@EXEEXT@ \
124
	${LIBTOOL_MODE_INSTALL} ${INSTALL_PROGRAM} isc-hmac-fixup@EXEEXT@ \
109
		${DESTDIR}${sbindir}
125
		${DESTDIR}${sbindir}
126
	${LIBTOOL_MODE_INSTALL} ${INSTALL_PROGRAM} zone2ldap@EXEEXT@ ${DESTDIR}${sbindir}
127
	${LIBTOOL_MODE_INSTALL} ${INSTALL_PROGRAM} ldap2zone@EXEEXT@ ${DESTDIR}${sbindir}
110
	${INSTALL_DATA} ${srcdir}/arpaname.1 ${DESTDIR}${mandir}/man1
128
	${INSTALL_DATA} ${srcdir}/arpaname.1 ${DESTDIR}${mandir}/man1
129
	${INSTALL_DATA} ${srcdir}/zone2ldap.1 ${DESTDIR}${mandir}/man1
130
	${INSTALL_DATA} ${srcdir}/ldap2zone.1 ${DESTDIR}${mandir}/man1
111
	${INSTALL_DATA} ${srcdir}/isc-hmac-fixup.8 ${DESTDIR}${mandir}/man8
131
	${INSTALL_DATA} ${srcdir}/isc-hmac-fixup.8 ${DESTDIR}${mandir}/man8
112
	${INSTALL_DATA} ${srcdir}/named-journalprint.8 ${DESTDIR}${mandir}/man8
132
	${INSTALL_DATA} ${srcdir}/named-journalprint.8 ${DESTDIR}${mandir}/man8
113
	${INSTALL_DATA} ${srcdir}/named-rrchecker.1 ${DESTDIR}${mandir}/man1
133
	${INSTALL_DATA} ${srcdir}/named-rrchecker.1 ${DESTDIR}${mandir}/man1
(-)a/contrib/sdb/ldap/ldap2zone.1 (+41 lines)
Line 0 Link Here
1
.\" Copyright (C) 2004, 2005 Stig Venaas <venaas@uninett.no>
2
.\" 
3
.\" Permission to use, copy, modify, and distribute this software for any
4
.\" purpose with or without fee is hereby granted, provided that the above
5
.\" copyright notice and this permission notice appear in all copies.
6
.\" Manpage written by Jan Gorig
7
.TH ldap2zone 1 "15 March 2010" "BIND9"
8
.SH NAME
9
ldap2zone - Creates zone file from LDAP dnszone information
10
.SH SYNOPSIS
11
.B ldap2zone zone-name LDAP-URL default-ttl [serial]
12
.SH DESCRIPTION
13
ldap2zone is a tool that reads info for a zone from LDAP and constructs a standard plain ascii zone file that is written to the standard output. The LDAP information has to be stored using the dnszone schema. The schema is used by BIND with LDAP back-end.
14
15
\fBzone-name\fR
16
.RS 4
17
Name of the zone, eg "mydomain.net."
18
.RE
19
.PP
20
\fBLDAP-URL\fR
21
.RS 4
22
LDAP URL to dnszone information
23
.RE
24
.PP
25
\fBdefault-ttl\fR
26
.RS 4
27
Default TTL value to be used in zone
28
.RE
29
.PP
30
\fBserial\fR
31
.RS 4
32
(optional) Program checks this number to be different than SOA serial number.
33
.RE
34
35
.SH "EXIT STATUS"
36
Exits with 0 on success or 1 on failure.
37
.SH "SEE ALSO"
38
named(8) ldap(3) 
39
http://www.venaas.no/dns/ldap2zone/
40
.SH "COPYRIGHT"
41
Copyright (C) 2004, 2005 Stig Venaas
(-)a/contrib/sdb/ldap/ldap2zone.c (+411 lines)
Line 0 Link Here
1
/*
2
 * Copyright (C) 2004, 2005 Stig Venaas <venaas@uninett.no>
3
 * $Id: ldap2zone.c,v 1.1 2007/07/24 15:18:00 atkac Exp $
4
 *
5
 * Permission to use, copy, modify, and distribute this software for any
6
 * purpose with or without fee is hereby granted, provided that the above
7
 * copyright notice and this permission notice appear in all copies.
8
 */
9
10
#define LDAP_DEPRECATED 1
11
12
#include <sys/types.h>
13
#include <stdio.h>
14
#include <stdlib.h>
15
#include <ctype.h>
16
17
#include <ldap.h>
18
19
struct string {
20
    void *data;
21
    size_t len;
22
};
23
24
struct assstack_entry {
25
    struct string key;
26
    struct string val;
27
    struct assstack_entry *next;
28
};
29
30
struct assstack_entry *assstack_find(struct assstack_entry *stack, struct string *key);
31
void assstack_push(struct assstack_entry **stack, struct assstack_entry *item);
32
void assstack_insertbottom(struct assstack_entry **stack, struct assstack_entry *item);
33
void printsoa(struct string *soa);
34
void printrrs(char *defaultttl, struct assstack_entry *item);
35
void print_zone(char *defaultttl, struct assstack_entry *stack);
36
void usage(char *name);
37
void err(char *name, const char *msg);
38
int putrr(struct assstack_entry **stack, struct berval *name, char *type, char *ttl, struct berval *val);
39
40
struct assstack_entry *assstack_find(struct assstack_entry *stack, struct string *key) {
41
    for (; stack; stack = stack->next)
42
	if (stack->key.len == key->len && !memcmp(stack->key.data, key->data, key->len))
43
	    return stack;
44
    return NULL;
45
}
46
47
void assstack_push(struct assstack_entry **stack, struct assstack_entry *item) {
48
    item->next = *stack;
49
    *stack = item;
50
}
51
52
void assstack_insertbottom(struct assstack_entry **stack, struct assstack_entry *item) {
53
    struct assstack_entry *p;
54
    
55
    item->next = NULL;
56
    if (!*stack) {
57
	*stack = item;
58
	return;
59
    }
60
    /* find end, should keep track of end somewhere */
61
    /* really a queue, not a stack */
62
    p = *stack;
63
    while (p->next)
64
	p = p->next;
65
    p->next = item;
66
}
67
68
void printsoa(struct string *soa) {
69
    char *s;
70
    size_t i;
71
    
72
    s = (char *)soa->data;
73
    i = 0;
74
    while (i < soa->len) {
75
	putchar(s[i]);
76
	if (s[i++] == ' ')
77
	    break;
78
    }
79
    while (i < soa->len) {
80
	putchar(s[i]);
81
	if (s[i++] == ' ')
82
	    break;
83
    } 
84
    printf("(\n\t\t\t\t");
85
    while (i < soa->len) {
86
	putchar(s[i]);
87
	if (s[i++] == ' ')
88
	    break;
89
    }
90
    printf("; Serialnumber\n\t\t\t\t");
91
    while (i < soa->len) {
92
	if (s[i] == ' ')
93
	    break;
94
	putchar(s[i++]);
95
    }
96
    i++;
97
    printf("\t; Refresh\n\t\t\t\t");
98
    while (i < soa->len) {
99
	if (s[i] == ' ')
100
	    break;
101
	putchar(s[i++]);
102
    }
103
    i++;
104
    printf("\t; Retry\n\t\t\t\t");
105
    while (i < soa->len) {
106
	if (s[i] == ' ')
107
	    break;
108
	putchar(s[i++]);
109
    }
110
    i++;
111
    printf("\t; Expire\n\t\t\t\t");
112
    while (i < soa->len) {
113
	putchar(s[i++]);
114
    }
115
    printf(" )\t; Minimum TTL\n");
116
}
117
118
void printrrs(char *defaultttl, struct assstack_entry *item) {
119
    struct assstack_entry *stack;
120
    char *s;
121
    int first;
122
    size_t i;
123
    char *ttl, *type;
124
    int top;
125
    
126
    s = (char *)item->key.data;
127
128
    if (item->key.len == 1 && *s == '@') {
129
	top = 1;
130
	printf("@\t");
131
    } else {
132
	top = 0;
133
	for (i = 0; i < item->key.len; i++)
134
	    putchar(s[i]);
135
	if (item->key.len < 8)
136
	    putchar('\t');
137
	putchar('\t');
138
    }
139
    
140
    first = 1;
141
    for (stack = (struct assstack_entry *) item->val.data; stack; stack = stack->next) {
142
	ttl = (char *)stack->key.data;
143
	s = strchr(ttl, ' ');
144
	*s++ = '\0';
145
	type = s;
146
	
147
	if (first)
148
	    first = 0;
149
        else
150
	    printf("\t\t");
151
	    
152
	if (strcmp(defaultttl, ttl))
153
	    printf("%s", ttl);
154
	putchar('\t');
155
	
156
	if (top) {
157
	    top = 0;
158
	    printf("IN\t%s\t", type);
159
	    /* Should always be SOA here */
160
	    if (!strcmp(type, "SOA")) {
161
		printsoa(&stack->val);
162
		continue;
163
	    }
164
	} else
165
	    printf("%s\t", type);
166
167
	s = (char *)stack->val.data;
168
	for (i = 0; i < stack->val.len; i++)
169
	    putchar(s[i]);
170
	putchar('\n');
171
    }
172
}
173
174
void print_zone(char *defaultttl, struct assstack_entry *stack) {
175
    printf("$TTL %s\n", defaultttl);
176
    for (; stack; stack = stack->next)
177
	printrrs(defaultttl, stack);
178
};
179
180
void usage(char *name) {
181
    fprintf(stderr, "Usage:%s zone-name LDAP-URL default-ttl [serial]\n", name);
182
    exit(1);
183
};
184
185
void err(char *name, const char *msg) {
186
    fprintf(stderr, "%s: %s\n", name, msg);
187
    exit(1);
188
};
189
190
int putrr(struct assstack_entry **stack, struct berval *name, char *type, char *ttl, struct berval *val) {
191
    struct string key;
192
    struct assstack_entry *rr, *rrdata;
193
    
194
    /* Do nothing if name or value have 0 length */
195
    if (!name->bv_len || !val->bv_len)
196
	return 0;
197
198
    /* see if already have an entry for this name */
199
    key.len = name->bv_len;
200
    key.data = name->bv_val;
201
202
    rr = assstack_find(*stack, &key);
203
    if (!rr) {
204
	/* Not found, create and push new entry */
205
	rr = (struct assstack_entry *) malloc(sizeof(struct assstack_entry));
206
	if (!rr)
207
	    return -1;
208
	rr->key.len = name->bv_len;
209
	rr->key.data = (void *) malloc(rr->key.len);
210
	if (!rr->key.data) {
211
	    free(rr);
212
	    return -1;
213
	}
214
	memcpy(rr->key.data, name->bv_val, name->bv_len);
215
	rr->val.len = sizeof(void *);
216
	rr->val.data = NULL;
217
	if (name->bv_len == 1 && *(char *)name->bv_val == '@')
218
	    assstack_push(stack, rr);
219
	else
220
	    assstack_insertbottom(stack, rr);
221
    }
222
223
    rrdata = (struct assstack_entry *) malloc(sizeof(struct assstack_entry));
224
    if (!rrdata) {
225
	free(rr->key.data);
226
	free(rr);
227
	return -1;
228
    }
229
    rrdata->key.len = strlen(type) + strlen(ttl) + 1;
230
    rrdata->key.data = (void *) malloc(rrdata->key.len);
231
    if (!rrdata->key.data) {
232
	free(rrdata);
233
	free(rr->key.data);
234
	free(rr);
235
	return -1;
236
    }
237
    sprintf((char *)rrdata->key.data, "%s %s", ttl, type);
238
	
239
    rrdata->val.len = val->bv_len;
240
    rrdata->val.data = (void *) malloc(val->bv_len);
241
    if (!rrdata->val.data) {
242
	free(rrdata->key.data);
243
	free(rrdata);
244
	free(rr->key.data);
245
	free(rr);
246
	return -1;
247
    }
248
    memcpy(rrdata->val.data, val->bv_val, val->bv_len);
249
250
    if (!strcmp(type, "SOA"))
251
	assstack_push((struct assstack_entry **) &(rr->val.data), rrdata);
252
    else
253
	assstack_insertbottom((struct assstack_entry **) &(rr->val.data), rrdata);
254
    return 0;
255
}
256
257
int main(int argc, char **argv) {
258
    char *s, *hostporturl, *base = NULL;
259
    char *ttl, *defaultttl;
260
    LDAP *ld;
261
    char *fltr = NULL;
262
    LDAPMessage *res, *e;
263
    char *a, **ttlvals, **soavals, *serial;
264
    struct berval **vals, **names;
265
    char type[64];
266
    BerElement *ptr;
267
    int i, j, rc, msgid;
268
    struct assstack_entry *zone = NULL;
269
    
270
    if (argc < 4 || argc > 5)
271
        usage(argv[0]);
272
273
    hostporturl = argv[2];
274
275
    if (hostporturl != strstr( hostporturl, "ldap"))
276
	err(argv[0], "Not an LDAP URL");
277
278
    s = strchr(hostporturl, ':');
279
280
    if (!s || strlen(s) < 3 || s[1] != '/' || s[2] != '/')
281
	err(argv[0], "Not an LDAP URL");
282
283
    s = strchr(s+3, '/');
284
    if (s) {
285
	*s++ = '\0';
286
	base = s;
287
	s = strchr(base, '?');
288
	if (s)
289
	    err(argv[0], "LDAP URL can only contain host, port and base");
290
    }
291
292
    defaultttl = argv[3];
293
    
294
    rc = ldap_initialize(&ld, hostporturl);
295
    if (rc != LDAP_SUCCESS)
296
	err(argv[0], "ldap_initialize() failed");
297
298
    if (argc == 5) {
299
	/* serial number specified, check if different from one in SOA */
300
	fltr = (char *)malloc(strlen(argv[1]) + strlen("(&(relativeDomainName=@)(zoneName=))") + 1);
301
	sprintf(fltr, "(&(relativeDomainName=@)(zoneName=%s))", argv[1]);
302
	msgid = ldap_search(ld, base, LDAP_SCOPE_SUBTREE, fltr, NULL, 0);
303
	if (msgid == -1)
304
	    err(argv[0], "ldap_search() failed");
305
306
	while ((rc = ldap_result(ld, msgid, 0, NULL, &res)) != LDAP_RES_SEARCH_RESULT ) {
307
	    /* not supporting continuation references at present */
308
	    if (rc != LDAP_RES_SEARCH_ENTRY)
309
		err(argv[0], "ldap_result() returned cont.ref? Exiting");
310
311
	    /* only one entry per result message */
312
	    e = ldap_first_entry(ld, res);
313
	    if (e == NULL) {
314
		ldap_msgfree(res);
315
		err(argv[0], "ldap_first_entry() failed");
316
	    }
317
	
318
	    soavals = ldap_get_values(ld, e, "SOARecord");
319
	    if (soavals)
320
		break;
321
	}
322
323
	ldap_msgfree(res);
324
	if (!soavals) {
325
		err(argv[0], "No SOA Record found");
326
	}
327
	
328
	/* We have a SOA, compare serial numbers */
329
	/* Only checkinf first value, should be only one */
330
	s = strchr(soavals[0], ' ');
331
	s++;
332
	s = strchr(s, ' ');
333
	s++;
334
	serial = s;
335
	s = strchr(s, ' ');
336
	*s = '\0';
337
	if (!strcmp(serial, argv[4])) {
338
	    ldap_value_free(soavals);
339
	    err(argv[0], "serial numbers match");
340
	}
341
	ldap_value_free(soavals);
342
    }
343
344
    if (!fltr)
345
	fltr = (char *)malloc(strlen(argv[1]) + strlen("(zoneName=)") + 1);
346
    if (!fltr)
347
	err(argv[0], "Malloc failed");
348
    sprintf(fltr, "(zoneName=%s)", argv[1]);
349
350
    msgid = ldap_search(ld, base, LDAP_SCOPE_SUBTREE, fltr, NULL, 0);
351
    if (msgid == -1)
352
	err(argv[0], "ldap_search() failed");
353
354
    while ((rc = ldap_result(ld, msgid, 0, NULL, &res)) != LDAP_RES_SEARCH_RESULT ) {
355
	/* not supporting continuation references at present */
356
	if (rc != LDAP_RES_SEARCH_ENTRY)
357
	    err(argv[0], "ldap_result() returned cont.ref? Exiting");
358
359
	/* only one entry per result message */
360
	e = ldap_first_entry(ld, res);
361
	if (e == NULL) {
362
	    ldap_msgfree(res);
363
	    err(argv[0], "ldap_first_entry() failed");
364
	}
365
	
366
	names = ldap_get_values_len(ld, e, "relativeDomainName");
367
	if (!names)
368
	    continue;
369
	
370
	ttlvals = ldap_get_values(ld, e, "dNSTTL");
371
	ttl = ttlvals ? ttlvals[0] : defaultttl;
372
373
	for (a = ldap_first_attribute(ld, e, &ptr); a != NULL; a = ldap_next_attribute(ld, e, ptr)) {
374
	    char *s;
375
376
	    for (s = a; *s; s++)
377
		*s = toupper(*s);
378
	    s = strstr(a, "RECORD");
379
	    if ((s == NULL) || (s == a) || (s - a >= (signed int)sizeof(type))) {
380
		ldap_memfree(a);
381
		continue;
382
	    }
383
			
384
	    strncpy(type, a, s - a);
385
	    type[s - a] = '\0';
386
	    vals = ldap_get_values_len(ld, e, a);
387
	    if (vals) {
388
		for (i = 0; vals[i]; i++)
389
		    for (j = 0; names[j]; j++)
390
			if (putrr(&zone, names[j], type, ttl, vals[i]))
391
			    err(argv[0], "malloc failed");
392
		ldap_value_free_len(vals);
393
	    }
394
	    ldap_memfree(a);
395
	}
396
397
	if (ptr)
398
	    ber_free(ptr, 0);
399
	if (ttlvals)
400
	    ldap_value_free(ttlvals);
401
	ldap_value_free_len(names);
402
	/* free this result */
403
	ldap_msgfree(res);
404
    }
405
406
    /* free final result */
407
    ldap_msgfree(res);
408
409
    print_zone(defaultttl, zone);
410
    return 0;
411
}
(-)a/contrib/sdb/ldap/ldapdb.c (+1 lines)
Lines 25-30 Link Here
25
/* Using LDAPv3 by default, change this if you want v2 */
25
/* Using LDAPv3 by default, change this if you want v2 */
26
#ifndef LDAPDB_LDAP_VERSION
26
#ifndef LDAPDB_LDAP_VERSION
27
#define LDAPDB_LDAP_VERSION 3
27
#define LDAPDB_LDAP_VERSION 3
28
#define LDAP_DEPRECATED 1
28
#endif
29
#endif
29
30
30
#include <config.h>
31
#include <config.h>
(-)a/contrib/sdb/ldap/zone2ldap.c (-87 / +208 lines)
Lines 13-18 Link Here
13
 * ditched dNSDomain2 schema support. Version 0.3-ALPHA
13
 * ditched dNSDomain2 schema support. Version 0.3-ALPHA
14
 */
14
 */
15
15
16
#define LDAP_DEPRECATED 1
17
16
#include <errno.h>
18
#include <errno.h>
17
#include <string.h>
19
#include <string.h>
18
#include <stdlib.h>
20
#include <stdlib.h>
Lines 24-29 Link Here
24
#include <isc/hash.h>
26
#include <isc/hash.h>
25
#include <isc/mem.h>
27
#include <isc/mem.h>
26
#include <isc/print.h>
28
#include <isc/print.h>
29
#include <isc/hash.h>
27
#include <isc/result.h>
30
#include <isc/result.h>
28
31
29
#include <dns/db.h>
32
#include <dns/db.h>
Lines 59-74 typedef struct LDAP_INFO Link Here
59
ldap_info;
62
ldap_info;
60
63
61
/* usage Info */
64
/* usage Info */
62
void usage ();
65
void usage (void);
66
67
/* Check for existence of (and possibly add) containing dNSZone objects */
68
int lookup_dns_zones( ldap_info *ldinfo);
63
69
64
/* Add to the ldap dit */
70
/* Add to the ldap dit */
65
void add_ldap_values (ldap_info * ldinfo);
71
void add_ldap_values (ldap_info * ldinfo);
66
72
67
/* Init an ldap connection */
73
/* Init an ldap connection */
68
void init_ldap_conn ();
74
void init_ldap_conn (void);
69
75
70
/* Ldap error checking */
76
/* Ldap error checking */
71
void ldap_result_check (char *msg, char *dn, int err);
77
void ldap_result_check (const char *msg, char *dn, int err);
72
78
73
/* Put a hostname into a char ** array */
79
/* Put a hostname into a char ** array */
74
char **hostname_to_dn_list (char *hostname, char *zone, unsigned int flags);
80
char **hostname_to_dn_list (char *hostname, char *zone, unsigned int flags);
Lines 77-90 char **hostname_to_dn_list (char *hostname, char *zone, unsigned int flags); Link Here
77
int get_attr_list_size (char **tmp);
83
int get_attr_list_size (char **tmp);
78
84
79
/* Get a DN */
85
/* Get a DN */
80
char *build_dn_from_dc_list (char **dc_list, unsigned int ttl, int flag);
86
char *build_dn_from_dc_list (char **dc_list, unsigned int ttl, int flag, char *zone);
81
87
82
/* Add to RR list */
88
/* Add to RR list */
83
void add_to_rr_list (char *dn, char *name, char *type, char *data,
89
void add_to_rr_list (char *dn, char *name, char *type, char *data,
84
		     unsigned int ttl, unsigned int flags);
90
		     unsigned int ttl, unsigned int flags);
85
91
86
/* Error checking */
92
/* Error checking */
87
void isc_result_check (isc_result_t res, char *errorstr);
93
void isc_result_check (isc_result_t res, const char *errorstr);
88
94
89
/* Generate LDIF Format files */
95
/* Generate LDIF Format files */
90
void generate_ldap (dns_name_t * dnsname, dns_rdata_t * rdata,
96
void generate_ldap (dns_name_t * dnsname, dns_rdata_t * rdata,
Lines 93-103 void generate_ldap (dns_name_t * dnsname, dns_rdata_t * rdata, Link Here
93
/* head pointer to the list */
99
/* head pointer to the list */
94
ldap_info *ldap_info_base = NULL;
100
ldap_info *ldap_info_base = NULL;
95
101
96
char *argzone, *ldapbase, *binddn, *bindpw = NULL;
102
ldap_info *
97
char *ldapsystem = "localhost";
103
locate_by_dn (char *dn);
98
static char *objectClasses[] =
104
void
99
  { "top", "dNSZone", NULL };
105
init_ldap_conn ();
100
static char *topObjectClasses[] = { "top", NULL };
106
void usage();
107
108
static char *argzone, *ldapbase, *binddn, *bindpw = NULL;
109
110
/* these are needed to placate gcc4's const-ness const-ernations : */
111
static char localhost[] = "localhost";
112
static char *ldapsystem=&(localhost[0]);
113
/* dnszone schema class names: */
114
static char topClass    [] ="top";
115
static char dNSZoneClass[] ="dNSZone";
116
static char objectClass [] ="objectClass";
117
static char dcObjectClass[]="dcObject";
118
/* dnszone schema attribute names: */
119
static char relativeDomainName[]="relativeDomainName";
120
static char dNSTTL            []="dNSTTL";
121
static char zoneName          []="zoneName";
122
static char dc                []="dc";
123
static char sameZone          []="@";
124
/* LDAPMod mod_values: */
125
static char *objectClasses    []= { &(topClass[0]), &(dNSZoneClass[0]), NULL };
126
static char *topObjectClasses []= { &(topClass[0]), &(dcObjectClass[0]), &(dNSZoneClass[0]), NULL };
127
static char *dn_buffer      [64]={NULL};
128
101
LDAP *conn;
129
LDAP *conn;
102
unsigned int debug = 0;
130
unsigned int debug = 0;
103
131
Lines 106-124 debug = 1; Link Here
106
#endif
134
#endif
107
135
108
int
136
int
109
main (int *argc, char **argv)
137
main (int argc, char **argv)
110
{
138
{
111
  isc_mem_t *mctx = NULL;
139
  isc_mem_t *mctx = NULL;
112
  isc_entropy_t *ectx = NULL;
140
  isc_entropy_t *ectx = NULL;
113
  isc_result_t result;
141
  isc_result_t result;
114
  char *basedn;
142
  char *basedn;
115
  ldap_info *tmp;
143
  ldap_info *tmp;
116
  LDAPMod *base_attrs[2];
144
  LDAPMod *base_attrs[5];
117
  LDAPMod base;
145
  LDAPMod base, dcBase, znBase, rdnBase;
118
  isc_buffer_t buff;
146
  isc_buffer_t buff;
119
  char *zonefile;
147
  char *zonefile=0L;
120
  char fullbasedn[1024];
148
  char fullbasedn[1024];
121
  char *ctmp;
149
  char *ctmp, *zn, *dcp[2], *znp[2], *rdn[2];
122
  dns_fixedname_t fixedzone, fixedname;
150
  dns_fixedname_t fixedzone, fixedname;
123
  dns_rdataset_t rdataset;
151
  dns_rdataset_t rdataset;
124
  char **dc_list;
152
  char **dc_list;
Lines 131-137 main (int *argc, char **argv) Link Here
131
  extern char *optarg;
159
  extern char *optarg;
132
  extern int optind, opterr, optopt;
160
  extern int optind, opterr, optopt;
133
  int create_base = 0;
161
  int create_base = 0;
134
  int topt;
162
  int topt, dcn, zdn, znlen;
135
163
136
  if ((int) argc < 2)
164
  if ((int) argc < 2)
137
    {
165
    {
Lines 139-145 main (int *argc, char **argv) Link Here
139
      exit (-1);
167
      exit (-1);
140
    }
168
    }
141
169
142
  while ((topt = getopt ((int) argc, argv, "D:w:b:z:f:h:?dcv")) != -1)
170
  while ((topt = getopt ((int) argc, argv, "D:Ww:b:z:f:h:?dcv")) != -1)
143
    {
171
    {
144
      switch (topt)
172
      switch (topt)
145
	{
173
	{
Lines 158-165 main (int *argc, char **argv) Link Here
158
	case 'w':
186
	case 'w':
159
	  bindpw = strdup (optarg);
187
	  bindpw = strdup (optarg);
160
	  break;
188
	  break;
189
	case 'W':
190
	  bindpw = getpass("Enter LDAP Password: ");
191
	  break;
161
	case 'b':
192
	case 'b':
162
	  ldapbase = strdup (optarg);
193
          ldapbase = strdup (optarg);
163
	  break;
194
	  break;
164
	case 'z':
195
	case 'z':
165
	  argzone = strdup (optarg);
196
	  argzone = strdup (optarg);
Lines 271-297 main (int *argc, char **argv) Link Here
271
    {
302
    {
272
      if (debug)
303
      if (debug)
273
	printf ("Creating base zone DN %s\n", argzone);
304
	printf ("Creating base zone DN %s\n", argzone);
274
305
      
275
      dc_list = hostname_to_dn_list (argzone, argzone, DNS_TOP);
306
      dc_list = hostname_to_dn_list (argzone, argzone, DNS_TOP);
276
      basedn = build_dn_from_dc_list (dc_list, 0, NO_SPEC);
277
307
278
      for (ctmp = &basedn[strlen (basedn)]; ctmp >= &basedn[0]; ctmp--)
308
      basedn = build_dn_from_dc_list (dc_list, 0, NO_SPEC, argzone);
309
      if (debug)
310
	printf ("base DN %s\n", basedn);
311
312
      for (ctmp = &basedn[strlen (basedn)], dcn=0; ctmp >= &basedn[0]; ctmp--)
279
	{
313
	{
280
	  if ((*ctmp == ',') || (ctmp == &basedn[0]))
314
	    if ((*ctmp == ',') || (ctmp == &basedn[0]))
281
	    {
315
	    {
316
282
	      base.mod_op = LDAP_MOD_ADD;
317
	      base.mod_op = LDAP_MOD_ADD;
283
	      base.mod_type = "objectClass";
318
	      base.mod_type = objectClass;
284
	      base.mod_values = topObjectClasses;
319
	      base.mod_values = topObjectClasses;
285
	      base_attrs[0] = &base;
320
	      base_attrs[0] = (void*)&base;
286
	      base_attrs[1] = NULL;
321
	     
322
	      dcBase.mod_op = LDAP_MOD_ADD;
323
	      dcBase.mod_type = dc;
324
	      dcp[0]=dc_list[dcn];
325
	      dcp[1]=0L;
326
	      dcBase.mod_values=dcp;
327
	      base_attrs[1] = (void*)&dcBase;
328
329
	      znBase.mod_op = LDAP_MOD_ADD;
330
	      znBase.mod_type = zoneName;	      
331
	      for( zdn = dcn, znlen = 0; zdn >= 0; zdn-- )
332
		  znlen += strlen(dc_list[zdn])+1;
333
	      znp[0] = (char*)malloc(znlen+1);
334
	      znp[1] = 0L;
335
	      for( zdn = dcn, zn=znp[0]; zdn >= 0; zdn-- )		  
336
		  zn+=sprintf(zn,"%s%s",dc_list[zdn], 
337
			      ((zdn > 0) && (*(dc_list[zdn-1])!='.')) ? "." : ""
338
		             );
339
340
	      znBase.mod_values = znp;
341
	      base_attrs[2] = (void*)&znBase;
342
343
	      rdnBase.mod_op = LDAP_MOD_ADD;
344
	      rdnBase.mod_type = relativeDomainName;
345
	      rdn[0] = strdup(sameZone);
346
	      rdn[1] = 0L;
347
	      rdnBase.mod_values = rdn;
348
	      base_attrs[3] = (void*)&rdnBase;
349
	      
350
	      dcn++;
287
351
352
	      base.mod_values = topObjectClasses;
353
	      base_attrs[4] = NULL;	      
354
	      
288
	      if (ldapbase)
355
	      if (ldapbase)
289
		{
356
		{
290
		  if (ctmp != &basedn[0])
357
		  if (ctmp != &basedn[0])
291
		    sprintf (fullbasedn, "%s,%s", ctmp + 1, ldapbase);
358
		    sprintf (fullbasedn, "%s,%s", ctmp + 1, ldapbase);
292
		  else
359
		  else
293
		    sprintf (fullbasedn, "%s,%s", ctmp, ldapbase);
360
		    sprintf (fullbasedn, "%s,%s", ctmp, ldapbase);		  
294
295
		}
361
		}
296
	      else
362
	      else
297
		{
363
		{
Lines 300-307 main (int *argc, char **argv) Link Here
300
		  else
366
		  else
301
		    sprintf (fullbasedn, "%s", ctmp);
367
		    sprintf (fullbasedn, "%s", ctmp);
302
		}
368
		}
369
370
	      if( debug )
371
		  printf("Full base dn: %s\n", fullbasedn);
372
303
	      result = ldap_add_s (conn, fullbasedn, base_attrs);
373
	      result = ldap_add_s (conn, fullbasedn, base_attrs);
304
	      ldap_result_check ("intial ldap_add_s", fullbasedn, result);
374
	      ldap_result_check ("intial ldap_add_s", fullbasedn, result);
375
305
	    }
376
	    }
306
377
307
	}
378
	}
Lines 339-345 main (int *argc, char **argv) Link Here
339
 * I should probably rename this function, as not to cause any
410
 * I should probably rename this function, as not to cause any
340
 * confusion with the isc* routines. Will exit on error. */
411
 * confusion with the isc* routines. Will exit on error. */
341
void
412
void
342
isc_result_check (isc_result_t res, char *errorstr)
413
isc_result_check (isc_result_t res, const char *errorstr)
343
{
414
{
344
  if (res != ISC_R_SUCCESS)
415
  if (res != ISC_R_SUCCESS)
345
    {
416
    {
Lines 379-392 generate_ldap (dns_name_t * dnsname, dns_rdata_t * rdata, unsigned int ttl) Link Here
379
  isc_result_check (result, "dns_rdata_totext");
450
  isc_result_check (result, "dns_rdata_totext");
380
  data[isc_buffer_usedlength (&buff)] = 0;
451
  data[isc_buffer_usedlength (&buff)] = 0;
381
452
382
  dc_list = hostname_to_dn_list (name, argzone, DNS_OBJECT);
453
  dc_list = hostname_to_dn_list ((char*)name, argzone, DNS_OBJECT);
383
  len = (get_attr_list_size (dc_list) - 2);
454
  len = (get_attr_list_size (dc_list) - 2);
384
  dn = build_dn_from_dc_list (dc_list, ttl, WI_SPEC);
455
  dn = build_dn_from_dc_list (dc_list, ttl, WI_SPEC, argzone);
385
456
386
  if (debug)
457
  if (debug)
387
    printf ("Adding %s (%s %s) to run queue list.\n", dn, type, data);
458
    printf ("Adding %s (%s %s) to run queue list.\n", dn, type, data);
388
459
389
  add_to_rr_list (dn, dc_list[len], type, data, ttl, DNS_OBJECT);
460
  add_to_rr_list (dn, dc_list[len], (char*)type, (char*)data, ttl, DNS_OBJECT);
390
}
461
}
391
462
392
463
Lines 426-432 add_to_rr_list (char *dn, char *name, char *type, Link Here
426
  int attrlist;
497
  int attrlist;
427
  char ldap_type_buffer[128];
498
  char ldap_type_buffer[128];
428
  char charttl[64];
499
  char charttl[64];
429
500
  char *zn;
501
  int znlen;
430
502
431
  if ((tmp = locate_by_dn (dn)) == NULL)
503
  if ((tmp = locate_by_dn (dn)) == NULL)
432
    {
504
    {
Lines 451-457 add_to_rr_list (char *dn, char *name, char *type, Link Here
451
	  exit (-1);
523
	  exit (-1);
452
	}
524
	}
453
525
454
      for (i = 0; i < flags; i++)
526
      for (i = 0; i < (int)flags; i++)
455
	{
527
	{
456
	  tmp->attrs[i] = (LDAPMod *) malloc (sizeof (LDAPMod));
528
	  tmp->attrs[i] = (LDAPMod *) malloc (sizeof (LDAPMod));
457
	  if (tmp->attrs[i] == (LDAPMod *) NULL)
529
	  if (tmp->attrs[i] == (LDAPMod *) NULL)
Lines 461-473 add_to_rr_list (char *dn, char *name, char *type, Link Here
461
	    }
533
	    }
462
	}
534
	}
463
      tmp->attrs[0]->mod_op = LDAP_MOD_ADD;
535
      tmp->attrs[0]->mod_op = LDAP_MOD_ADD;
464
      tmp->attrs[0]->mod_type = "objectClass";
536
      tmp->attrs[0]->mod_type = objectClass;
465
537
466
      if (flags == DNS_OBJECT)
538
      if (flags == DNS_OBJECT)
467
	tmp->attrs[0]->mod_values = objectClasses;
539
	tmp->attrs[0]->mod_values = objectClasses;
468
      else
540
      else
469
	{
541
	{
470
	  tmp->attrs[0]->mod_values = topObjectClasses;
542
	  tmp->attrs[0]->mod_values =topObjectClasses;
471
	  tmp->attrs[1] = NULL;
543
	  tmp->attrs[1] = NULL;
472
	  tmp->attrcnt = 2;
544
	  tmp->attrcnt = 2;
473
	  tmp->next = ldap_info_base;
545
	  tmp->next = ldap_info_base;
Lines 476-482 add_to_rr_list (char *dn, char *name, char *type, Link Here
476
	}
548
	}
477
549
478
      tmp->attrs[1]->mod_op = LDAP_MOD_ADD;
550
      tmp->attrs[1]->mod_op = LDAP_MOD_ADD;
479
      tmp->attrs[1]->mod_type = "relativeDomainName";
551
      tmp->attrs[1]->mod_type = relativeDomainName;
480
      tmp->attrs[1]->mod_values = (char **) calloc (sizeof (char *), 2);
552
      tmp->attrs[1]->mod_values = (char **) calloc (sizeof (char *), 2);
481
553
482
      if (tmp->attrs[1]->mod_values == (char **)NULL)
554
      if (tmp->attrs[1]->mod_values == (char **)NULL)
Lines 498-504 add_to_rr_list (char *dn, char *name, char *type, Link Here
498
      tmp->attrs[2]->mod_values[1] = NULL;
570
      tmp->attrs[2]->mod_values[1] = NULL;
499
571
500
      tmp->attrs[3]->mod_op = LDAP_MOD_ADD;
572
      tmp->attrs[3]->mod_op = LDAP_MOD_ADD;
501
      tmp->attrs[3]->mod_type = "dNSTTL";
573
      tmp->attrs[3]->mod_type = dNSTTL;
502
      tmp->attrs[3]->mod_values = (char **) calloc (sizeof (char *), 2);
574
      tmp->attrs[3]->mod_values = (char **) calloc (sizeof (char *), 2);
503
575
504
      if (tmp->attrs[3]->mod_values == (char **)NULL)
576
      if (tmp->attrs[3]->mod_values == (char **)NULL)
Lines 508-517 add_to_rr_list (char *dn, char *name, char *type, Link Here
508
      tmp->attrs[3]->mod_values[0] = strdup (charttl);
580
      tmp->attrs[3]->mod_values[0] = strdup (charttl);
509
      tmp->attrs[3]->mod_values[1] = NULL;
581
      tmp->attrs[3]->mod_values[1] = NULL;
510
582
583
      znlen=strlen(gbl_zone);      
584
      if ( *(gbl_zone + (znlen-1)) == '.' )
585
      { /* ldapdb MUST search by relative zone name */
586
	  zn = (char*)malloc(znlen);
587
	  strncpy(zn,gbl_zone,znlen-1);
588
	  *(zn + (znlen-1))='\0';	  
589
      }else
590
      {
591
	  zn = gbl_zone;
592
      }
593
511
      tmp->attrs[4]->mod_op = LDAP_MOD_ADD;
594
      tmp->attrs[4]->mod_op = LDAP_MOD_ADD;
512
      tmp->attrs[4]->mod_type = "zoneName";
595
      tmp->attrs[4]->mod_type = zoneName;
513
      tmp->attrs[4]->mod_values = (char **)calloc(sizeof(char *), 2);
596
      tmp->attrs[4]->mod_values = (char **)calloc(sizeof(char *), 2);
514
      tmp->attrs[4]->mod_values[0] = gbl_zone;
597
      tmp->attrs[4]->mod_values[0] = zn;
515
      tmp->attrs[4]->mod_values[1] = NULL;
598
      tmp->attrs[4]->mod_values[1] = NULL;
516
599
517
      tmp->attrs[5] = NULL;
600
      tmp->attrs[5] = NULL;
Lines 522-528 add_to_rr_list (char *dn, char *name, char *type, Link Here
522
  else
605
  else
523
    {
606
    {
524
607
525
      for (i = 0; tmp->attrs[i] != NULL; i++)
608
	for (i = 0; tmp->attrs[i] != NULL; i++)
526
	{
609
	{
527
	  sprintf (ldap_type_buffer, "%sRecord", type);
610
	  sprintf (ldap_type_buffer, "%sRecord", type);
528
	  if (!strncmp
611
	  if (!strncmp
Lines 591-659 char ** Link Here
591
hostname_to_dn_list (char *hostname, char *zone, unsigned int flags)
674
hostname_to_dn_list (char *hostname, char *zone, unsigned int flags)
592
{
675
{
593
  char *tmp;
676
  char *tmp;
594
  static char *dn_buffer[64];
595
  int i = 0;
677
  int i = 0;
596
  char *zname;
678
  char *hname=0L, *last=0L;
597
  char *hnamebuff;
679
  int hlen=strlen(hostname), zlen=(strlen(zone));
598
680
599
  zname = strdup (hostname);
681
/*  printf("hostname: %s zone: %s\n",hostname, zone); */
600
682
  hname=0L;
601
  if (flags == DNS_OBJECT)
683
  if(flags == DNS_OBJECT)
602
    {
684
  {
603
685
      if( (zone[ zlen - 1 ] == '.') && (hostname[hlen - 1] != '.') )
604
      if (strlen (zname) != strlen (zone))
686
      {
605
	{
687
	  hname=(char*)malloc(hlen + 1);
606
	  tmp = &zname[strlen (zname) - strlen (zone)];
688
	  hlen += 1;
607
	  *--tmp = '\0';
689
	  sprintf(hname, "%s.", hostname);
608
	  hnamebuff = strdup (zname);
690
	  hostname = hname;
609
	  zname = ++tmp;
691
      }
610
	}
692
      if(strcmp(hostname, zone) == 0)
611
      else
693
      {
612
	hnamebuff = "@";
694
	  if( hname == 0 )
613
    }
695
	      hname=strdup(hostname);
614
  else
696
  	  last = strdup(sameZone);
615
    {
697
      }else
616
      zname = zone;
698
      {	   
617
      hnamebuff = NULL;
699
	  if(  (hlen < zlen) 
618
    }
700
	     ||( strcmp( hostname + (hlen - zlen), zone ) != 0)
619
701
	    )
620
  for (tmp = strrchr (zname, '.'); tmp != (char *) 0;
702
	  {
621
       tmp = strrchr (zname, '.'))
703
	      if( hname != 0 )
622
    {
704
		  free(hname);
623
      *tmp++ = '\0';
705
	      hname=(char*)malloc( hlen + zlen + 1);
624
      dn_buffer[i++] = tmp;
706
	      if( *zone == '.' )
625
    }
707
		  sprintf(hname, "%s%s", hostname, zone);
626
  dn_buffer[i++] = zname;
708
	      else
627
  dn_buffer[i++] = hnamebuff;
709
		  sprintf(hname,"%s",zone);
710
	  }else
711
	  {
712
	      if( hname == 0 )
713
		  hname = strdup(hostname);
714
	  }
715
	  last = hname;
716
      }
717
  }else
718
  { /* flags == DNS_TOP */
719
      hname = strdup(zone);
720
      last = hname;
721
  }
722
723
  for (tmp = strrchr (hname, '.'); tmp != (char *) 0;
724
       tmp = strrchr (hname, '.'))
725
  {
726
      if( *( tmp + 1 ) != '\0' )
727
      {
728
	  *tmp = '\0';
729
	  dn_buffer[i++] = ++tmp;
730
      }else
731
      { /* trailing '.' ! */
732
	  dn_buffer[i++] = strdup(".");
733
	  *tmp = '\0';
734
	  if( tmp == hname )
735
	      break;
736
      }	  
737
  }
738
  if( ( last != hname ) && (tmp != hname) )
739
      dn_buffer[i++] = hname;
740
  dn_buffer[i++] = last;
628
  dn_buffer[i] = NULL;
741
  dn_buffer[i] = NULL;
629
630
  return dn_buffer;
742
  return dn_buffer;
631
}
743
}
632
744
633
634
/* build an sdb compatible LDAP DN from a "dc_list" (char **).
745
/* build an sdb compatible LDAP DN from a "dc_list" (char **).
635
 * will append dNSTTL information to each RR Record, with the 
746
 * will append dNSTTL information to each RR Record, with the 
636
 * exception of "@"/SOA. */
747
 * exception of "@"/SOA. */
637
748
638
char *
749
char *
639
build_dn_from_dc_list (char **dc_list, unsigned int ttl, int flag)
750
build_dn_from_dc_list (char **dc_list, unsigned int ttl, int flag, char *zone)
640
{
751
{
641
  int size;
752
  int size;
642
  int x;
753
  int x, znlen;
643
  static char dn[1024];
754
  static char dn[1024];
644
  char tmp[128];
755
  char tmp[128];
756
  char zn[DNS_NAME_MAXTEXT+1];
645
757
646
  bzero (tmp, sizeof (tmp));
758
  bzero (tmp, sizeof (tmp));
647
  bzero (dn, sizeof (dn));
759
  bzero (dn, sizeof (dn));
648
  size = get_attr_list_size (dc_list);
760
  size = get_attr_list_size (dc_list);
761
  znlen = strlen(zone);
762
  if ( *(zone + (znlen-1)) == '.' )
763
  { /* ldapdb MUST search by relative zone name */
764
      memcpy(&(zn[0]),zone,znlen-1);
765
      *(zn + (znlen-1))='\0';
766
      zone = zn;
767
  }
649
  for (x = size - 2; x > 0; x--)
768
  for (x = size - 2; x > 0; x--)
650
    {
769
    {
651
    if (flag == WI_SPEC)
770
    if (flag == WI_SPEC)
652
    {
771
    {
653
      if (x == (size - 2) && (strncmp (dc_list[x], "@", 1) == 0) && (ttl))
772
      if (x == (size - 2) && (strncmp (dc_list[x], "@", 1) == 0) && (ttl))
654
	sprintf (tmp, "relativeDomainName=%s + dNSTTL=%d,", dc_list[x], ttl);
773
	sprintf (tmp, "zoneName=%s + relativeDomainName=%s,", zone, dc_list[x]);
655
      else if (x == (size - 2))
774
      else if (x == (size - 2))
656
	      sprintf(tmp, "relativeDomainName=%s,",dc_list[x]);
775
	      sprintf(tmp, "zoneName=%s + relativeDomainName=%s,", zone, dc_list[x]);
657
      else
776
      else
658
	      sprintf(tmp,"dc=%s,", dc_list[x]);
777
	      sprintf(tmp,"dc=%s,", dc_list[x]);
659
    }
778
    }
Lines 679-684 void Link Here
679
init_ldap_conn ()
798
init_ldap_conn ()
680
{
799
{
681
  int result;
800
  int result;
801
  char ldb_tag[]="LDAP Bind";
682
  conn = ldap_open (ldapsystem, LDAP_PORT);
802
  conn = ldap_open (ldapsystem, LDAP_PORT);
683
  if (conn == NULL)
803
  if (conn == NULL)
684
    {
804
    {
Lines 688-699 init_ldap_conn () Link Here
688
    }
808
    }
689
809
690
  result = ldap_simple_bind_s (conn, binddn, bindpw);
810
  result = ldap_simple_bind_s (conn, binddn, bindpw);
691
  ldap_result_check ("ldap_simple_bind_s", "LDAP Bind", result);
811
  ldap_result_check ("ldap_simple_bind_s", ldb_tag , result);
692
}
812
}
693
813
694
/* Like isc_result_check, only for LDAP */
814
/* Like isc_result_check, only for LDAP */
695
void
815
void
696
ldap_result_check (char *msg, char *dn, int err)
816
ldap_result_check (const char *msg, char *dn, int err)
697
{
817
{
698
  if ((err != LDAP_SUCCESS) && (err != LDAP_ALREADY_EXISTS))
818
  if ((err != LDAP_SUCCESS) && (err != LDAP_ALREADY_EXISTS))
699
    {
819
    {
Lines 705-712 ldap_result_check (char *msg, char *dn, int err) Link Here
705
    }
825
    }
706
}
826
}
707
827
708
709
710
/* For running the ldap_info run queue. */
828
/* For running the ldap_info run queue. */
711
void
829
void
712
add_ldap_values (ldap_info * ldinfo)
830
add_ldap_values (ldap_info * ldinfo)
Lines 714-727 add_ldap_values (ldap_info * ldinfo) Link Here
714
  int result;
832
  int result;
715
  char dnbuffer[1024];
833
  char dnbuffer[1024];
716
834
717
718
  if (ldapbase != NULL)
835
  if (ldapbase != NULL)
719
    sprintf (dnbuffer, "%s,%s", ldinfo->dn, ldapbase);
836
    sprintf (dnbuffer, "%s,%s", ldinfo->dn, ldapbase);
720
  else
837
  else
721
    sprintf (dnbuffer, "%s", ldinfo->dn);
838
    sprintf (dnbuffer, "%s", ldinfo->dn);
722
839
723
  result = ldap_add_s (conn, dnbuffer, ldinfo->attrs);
840
  result = ldap_add_s (conn, dnbuffer, ldinfo->attrs);
724
  ldap_result_check ("ldap_add_s", dnbuffer, result);
841
    ldap_result_check ("ldap_add_s", dnbuffer, result);
842
725
}
843
}
726
844
727
845
Lines 732-736 void Link Here
732
usage ()
850
usage ()
733
{
851
{
734
  fprintf (stderr,
852
  fprintf (stderr,
735
	   "zone2ldap -D [BIND DN] -w [BIND PASSWORD] -b [BASE DN] -z [ZONE] -f [ZONE FILE] -h [LDAP HOST]
853
	   "zone2ldap -D [BIND DN] [-w BIND PASSWORD | -W:prompt] -b [BASE DN] -z [ZONE] -f [ZONE FILE] -h [LDAP HOST]\n"
736
	   [-c Create LDAP Base structure][-d Debug Output (lots !)] \n ");}
854
	   "\t[-c Create LDAP Base structure][-d Debug Output (lots !)]\n "
855
          );
856
}
857

Return to bug 556566