/[packages]/cauldron/bind/current/SOURCES/bind-9.3.2b1-fix_sdb_ldap.patch
ViewVC logotype

Contents of /cauldron/bind/current/SOURCES/bind-9.3.2b1-fix_sdb_ldap.patch

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1418613 - (show annotations) (download)
Thu Jul 4 20:00:06 2019 UTC (5 months, 1 week ago) by guillomovitch
File size: 15864 byte(s)
- new version 9.11.8
- sync patches with Fedora

1 diff --git a/bin/sdb_tools/Makefile.in b/bin/sdb_tools/Makefile.in
2 index 95ab742..6069f09 100644
3 --- a/bin/sdb_tools/Makefile.in
4 +++ b/bin/sdb_tools/Makefile.in
5 @@ -32,11 +32,11 @@ DEPLIBS = ${LWRESDEPLIBS} ${DNSDEPLIBS} ${BIND9DEPLIBS} \
6 LIBS = ${LWRESLIBS} ${DNSLIBS} ${BIND9LIBS} \
7 ${ISCCFGLIBS} ${ISCCCLIBS} ${ISCLIBS} ${DBDRIVER_LIBS} @LIBS@
8
9 -TARGETS = zone2ldap@EXEEXT@ zonetodb@EXEEXT@ zone2sqlite@EXEEXT@
10 +TARGETS = zone2ldap@EXEEXT@ ldap2zone@EXEEXT@ zonetodb@EXEEXT@ zone2sqlite@EXEEXT@
11
12 -OBJS = zone2ldap.@O@ zonetodb.@O@ zone2sqlite.@O@
13 +OBJS = zone2ldap.@O@ ldap2zone.@O@ zonetodb.@O@ zone2sqlite.@O@
14
15 -SRCS = zone2ldap.c zonetodb.c zone2sqlite.c
16 +SRCS = zone2ldap.c ldap2zone.c zonetodb.c zone2sqlite.c
17
18 MANPAGES = zone2ldap.1
19
20 @@ -53,6 +53,9 @@ zonetodb@EXEEXT@: zonetodb.@O@ ${DEPLIBS}
21 zone2sqlite@EXEEXT@: zone2sqlite.@O@ ${DEPLIBS}
22 ${LIBTOOL_MODE_LINK} ${PURIFY} ${CC} ${ALL_CFLAGS} ${LDFLAGS} -o $@ zone2sqlite.@O@ -lsqlite3 -lssl ${LIBS}
23
24 +ldap2zone@EXEEXT@: ldap2zone.@O@ ${DEPLIBS}
25 + ${LIBTOOL_MODE_LINK} ${PURIFY} ${CC} ${ALL_CFLAGS} ${LDFLAGS} -o $@ ldap2zone.@O@ -lldap -llber ${LIBS}
26 +
27 clean distclean manclean maintainer-clean::
28 rm -f ${TARGETS} ${OBJS}
29
30 @@ -62,6 +65,7 @@ installdirs:
31
32 install:: ${TARGETS} installdirs
33 ${LIBTOOL_MODE_INSTALL} ${INSTALL_PROGRAM} zone2ldap@EXEEXT@ ${DESTDIR}${sbindir}
34 + ${LIBTOOL_MODE_INSTALL} ${INSTALL_PROGRAM} ldap2zone@EXEEXT@ ${DESTDIR}${sbindir}
35 ${LIBTOOL_MODE_INSTALL} ${INSTALL_PROGRAM} zonetodb@EXEEXT@ ${DESTDIR}${sbindir}
36 ${LIBTOOL_MODE_INSTALL} ${INSTALL_PROGRAM} zone2sqlite@EXEEXT@ ${DESTDIR}${sbindir}
37 ${INSTALL_DATA} ${srcdir}/zone2ldap.1 ${DESTDIR}${mandir}/man1/zone2ldap.1
38 diff --git a/bin/sdb_tools/zone2ldap.c b/bin/sdb_tools/zone2ldap.c
39 index aa2c711..76186b5 100644
40 --- a/bin/sdb_tools/zone2ldap.c
41 +++ b/bin/sdb_tools/zone2ldap.c
42 @@ -66,6 +66,9 @@ ldap_info;
43 /* usage Info */
44 void usage (void);
45
46 +/* Check for existence of (and possibly add) containing dNSZone objects */
47 +int lookup_dns_zones( ldap_info *ldinfo);
48 +
49 /* Add to the ldap dit */
50 void add_ldap_values (ldap_info * ldinfo);
51
52 @@ -82,7 +85,7 @@ char **hostname_to_dn_list (char *hostname, char *zone, unsigned int flags);
53 int get_attr_list_size (char **tmp);
54
55 /* Get a DN */
56 -char *build_dn_from_dc_list (char **dc_list, unsigned int ttl, int flag);
57 +char *build_dn_from_dc_list (char **dc_list, unsigned int ttl, int flag, char *zone);
58
59 /* Add to RR list */
60 void add_to_rr_list (char *dn, char *name, char *type, char *data,
61 @@ -104,11 +107,27 @@ void
62 init_ldap_conn ();
63 void usage();
64
65 -char *argzone, *ldapbase, *binddn, *bindpw = NULL;
66 -const char *ldapsystem = "localhost";
67 -static const char *objectClasses[] =
68 - { "top", "dNSZone", NULL };
69 -static const char *topObjectClasses[] = { "top", NULL };
70 +static char *argzone, *ldapbase, *binddn, *bindpw = NULL;
71 +
72 +/* these are needed to placate gcc4's const-ness const-ernations : */
73 +static char localhost[] = "localhost";
74 +static char *ldapsystem=&(localhost[0]);
75 +/* dnszone schema class names: */
76 +static char topClass [] ="top";
77 +static char dNSZoneClass[] ="dNSZone";
78 +static char objectClass [] ="objectClass";
79 +static char dcObjectClass[]="dcObject";
80 +/* dnszone schema attribute names: */
81 +static char relativeDomainName[]="relativeDomainName";
82 +static char dNSTTL []="dNSTTL";
83 +static char zoneName []="zoneName";
84 +static char dc []="dc";
85 +static char sameZone []="@";
86 +/* LDAPMod mod_values: */
87 +static char *objectClasses []= { &(topClass[0]), &(dNSZoneClass[0]), NULL };
88 +static char *topObjectClasses []= { &(topClass[0]), &(dcObjectClass[0]), &(dNSZoneClass[0]), NULL };
89 +static char *dn_buffer [64]={NULL};
90 +
91 LDAP *conn;
92 unsigned int debug = 0;
93
94 @@ -132,12 +151,12 @@ main (int argc, char **argv)
95 isc_result_t result;
96 char *basedn;
97 ldap_info *tmp;
98 - LDAPMod *base_attrs[2];
99 - LDAPMod base;
100 + LDAPMod *base_attrs[5];
101 + LDAPMod base, dcBase, znBase, rdnBase;
102 isc_buffer_t buff;
103 char *zonefile=0L;
104 char fullbasedn[1024];
105 - char *ctmp;
106 + char *ctmp, *zn, *dcp[2], *znp[2], *rdn[2];
107 dns_fixedname_t fixedzone, fixedname;
108 dns_rdataset_t rdataset;
109 char **dc_list;
110 @@ -150,7 +169,7 @@ main (int argc, char **argv)
111 extern char *optarg;
112 extern int optind, opterr, optopt;
113 int create_base = 0;
114 - int topt;
115 + int topt, dcn, zdn, znlen;
116
117 if (argc < 2)
118 {
119 @@ -158,7 +177,7 @@ main (int argc, char **argv)
120 exit (-1);
121 }
122
123 - while ((topt = getopt (argc, argv, "D:w:b:z:f:h:?dcv")) != -1)
124 + while ((topt = getopt (argc, argv, "D:Ww:b:z:f:h:?dcv")) != -1)
125 {
126 switch (topt)
127 {
128 @@ -181,6 +200,9 @@ main (int argc, char **argv)
129 if (bindpw == NULL)
130 fatal("strdup");
131 break;
132 + case 'W':
133 + bindpw = getpass("Enter LDAP Password: ");
134 + break;
135 case 'b':
136 ldapbase = strdup (optarg);
137 if (ldapbase == NULL)
138 @@ -300,27 +322,62 @@ main (int argc, char **argv)
139 {
140 if (debug)
141 printf ("Creating base zone DN %s\n", argzone);
142 -
143 +
144 dc_list = hostname_to_dn_list (argzone, argzone, DNS_TOP);
145 - basedn = build_dn_from_dc_list (dc_list, 0, NO_SPEC);
146
147 - for (ctmp = &basedn[strlen (basedn)]; ctmp >= &basedn[0]; ctmp--)
148 + basedn = build_dn_from_dc_list (dc_list, 0, NO_SPEC, argzone);
149 + if (debug)
150 + printf ("base DN %s\n", basedn);
151 +
152 + for (ctmp = &basedn[strlen (basedn)], dcn=0; ctmp >= &basedn[0]; ctmp--)
153 {
154 - if ((*ctmp == ',') || (ctmp == &basedn[0]))
155 + if ((*ctmp == ',') || (ctmp == &basedn[0]))
156 {
157 +
158 base.mod_op = LDAP_MOD_ADD;
159 - base.mod_type = (char*)"objectClass";
160 - base.mod_values = (char**)topObjectClasses;
161 + base.mod_type = objectClass;
162 + base.mod_values = topObjectClasses;
163 base_attrs[0] = (void*)&base;
164 - base_attrs[1] = NULL;
165 -
166 +
167 + dcBase.mod_op = LDAP_MOD_ADD;
168 + dcBase.mod_type = dc;
169 + dcp[0]=dc_list[dcn];
170 + dcp[1]=0L;
171 + dcBase.mod_values=dcp;
172 + base_attrs[1] = (void*)&dcBase;
173 +
174 + znBase.mod_op = LDAP_MOD_ADD;
175 + znBase.mod_type = zoneName;
176 + for( zdn = dcn, znlen = 0; zdn >= 0; zdn-- )
177 + znlen += strlen(dc_list[zdn])+1;
178 + znp[0] = (char*)malloc(znlen+1);
179 + znp[1] = 0L;
180 + for( zdn = dcn, zn=znp[0]; zdn >= 0; zdn-- )
181 + zn+=sprintf(zn,"%s%s",dc_list[zdn],
182 + ((zdn > 0) && (*(dc_list[zdn-1])!='.')) ? "." : ""
183 + );
184 +
185 + znBase.mod_values = znp;
186 + base_attrs[2] = (void*)&znBase;
187 +
188 + rdnBase.mod_op = LDAP_MOD_ADD;
189 + rdnBase.mod_type = relativeDomainName;
190 + rdn[0] = strdup(sameZone);
191 + rdn[1] = 0L;
192 + rdnBase.mod_values = rdn;
193 + base_attrs[3] = (void*)&rdnBase;
194 +
195 + dcn++;
196 +
197 + base.mod_values = topObjectClasses;
198 + base_attrs[4] = NULL;
199 +
200 if (ldapbase)
201 {
202 if (ctmp != &basedn[0])
203 sprintf (fullbasedn, "%s,%s", ctmp + 1, ldapbase);
204 else
205 - sprintf (fullbasedn, "%s,%s", ctmp, ldapbase);
206 -
207 + sprintf (fullbasedn, "%s,%s", ctmp, ldapbase);
208 }
209 else
210 {
211 @@ -329,8 +386,13 @@ main (int argc, char **argv)
212 else
213 sprintf (fullbasedn, "%s", ctmp);
214 }
215 +
216 + if( debug )
217 + printf("Full base dn: %s\n", fullbasedn);
218 +
219 result = ldap_add_s (conn, fullbasedn, base_attrs);
220 ldap_result_check ("intial ldap_add_s", fullbasedn, result);
221 +
222 }
223
224 }
225 @@ -408,14 +470,14 @@ generate_ldap (dns_name_t * dnsname, dns_rdata_t * rdata, unsigned int ttl)
226 isc_result_check (result, "dns_rdata_totext");
227 data[isc_buffer_usedlength (&buff)] = 0;
228
229 - dc_list = hostname_to_dn_list (name, argzone, DNS_OBJECT);
230 + dc_list = hostname_to_dn_list ((char*)name, argzone, DNS_OBJECT);
231 len = (get_attr_list_size (dc_list) - 2);
232 - dn = build_dn_from_dc_list (dc_list, ttl, WI_SPEC);
233 + dn = build_dn_from_dc_list (dc_list, ttl, WI_SPEC, argzone);
234
235 if (debug)
236 printf ("Adding %s (%s %s) to run queue list.\n", dn, type, data);
237
238 - add_to_rr_list (dn, dc_list[len], type, data, ttl, DNS_OBJECT);
239 + add_to_rr_list (dn, dc_list[len], (char*)type, (char*)data, ttl, DNS_OBJECT);
240 }
241
242
243 @@ -455,7 +517,8 @@ add_to_rr_list (char *dn, char *name, char *type,
244 int attrlist;
245 char ldap_type_buffer[128];
246 char charttl[64];
247 -
248 + char *zn;
249 + int znlen;
250
251 if ((tmp = locate_by_dn (dn)) == NULL)
252 {
253 @@ -482,13 +545,13 @@ add_to_rr_list (char *dn, char *name, char *type,
254 fatal("malloc");
255 }
256 tmp->attrs[0]->mod_op = LDAP_MOD_ADD;
257 - tmp->attrs[0]->mod_type = (char*)"objectClass";
258 + tmp->attrs[0]->mod_type = objectClass;
259
260 if (flags == DNS_OBJECT)
261 - tmp->attrs[0]->mod_values = (char**)objectClasses;
262 + tmp->attrs[0]->mod_values = objectClasses;
263 else
264 {
265 - tmp->attrs[0]->mod_values = (char**)topObjectClasses;
266 + tmp->attrs[0]->mod_values =topObjectClasses;
267 tmp->attrs[1] = NULL;
268 tmp->attrcnt = 2;
269 tmp->next = ldap_info_base;
270 @@ -497,7 +560,7 @@ add_to_rr_list (char *dn, char *name, char *type,
271 }
272
273 tmp->attrs[1]->mod_op = LDAP_MOD_ADD;
274 - tmp->attrs[1]->mod_type = (char*)"relativeDomainName";
275 + tmp->attrs[1]->mod_type = relativeDomainName;
276 tmp->attrs[1]->mod_values = (char **) calloc (sizeof (char *), 2);
277
278 if (tmp->attrs[1]->mod_values == (char **)NULL)
279 @@ -526,7 +589,7 @@ add_to_rr_list (char *dn, char *name, char *type,
280 fatal("strdup");
281
282 tmp->attrs[3]->mod_op = LDAP_MOD_ADD;
283 - tmp->attrs[3]->mod_type = (char*)"dNSTTL";
284 + tmp->attrs[3]->mod_type = dNSTTL;
285 tmp->attrs[3]->mod_values = (char **) calloc (sizeof (char *), 2);
286
287 if (tmp->attrs[3]->mod_values == (char **)NULL)
288 @@ -539,14 +602,25 @@ add_to_rr_list (char *dn, char *name, char *type,
289 if (tmp->attrs[3]->mod_values[0] == NULL)
290 fatal("strdup");
291
292 + znlen=strlen(gbl_zone);
293 + if ( *(gbl_zone + (znlen-1)) == '.' )
294 + { /* ldapdb MUST search by relative zone name */
295 + zn = (char*)malloc(znlen);
296 + strncpy(zn,gbl_zone,znlen-1);
297 + *(zn + (znlen-1))='\0';
298 + }else
299 + {
300 + zn = gbl_zone;
301 + }
302 +
303 tmp->attrs[4]->mod_op = LDAP_MOD_ADD;
304 - tmp->attrs[4]->mod_type = (char*)"zoneName";
305 + tmp->attrs[4]->mod_type = zoneName;
306 tmp->attrs[4]->mod_values = (char **)calloc(sizeof(char *), 2);
307
308 if (tmp->attrs[4]->mod_values == (char **)NULL)
309 fatal("calloc");
310
311 - tmp->attrs[4]->mod_values[0] = gbl_zone;
312 + tmp->attrs[4]->mod_values[0] = zn;
313 tmp->attrs[4]->mod_values[1] = NULL;
314
315 tmp->attrs[5] = NULL;
316 @@ -557,7 +631,7 @@ add_to_rr_list (char *dn, char *name, char *type,
317 else
318 {
319
320 - for (i = 0; tmp->attrs[i] != NULL; i++)
321 + for (i = 0; tmp->attrs[i] != NULL; i++)
322 {
323 sprintf (ldap_type_buffer, "%sRecord", type);
324 if (!strncmp
325 @@ -631,44 +705,70 @@ char **
326 hostname_to_dn_list (char *hostname, char *zone, unsigned int flags)
327 {
328 char *tmp;
329 - static char *dn_buffer[64];
330 int i = 0;
331 - char *zname;
332 - char *hnamebuff;
333 -
334 - zname = strdup (hostname);
335 - if (zname == NULL)
336 - fatal("strdup");
337 -
338 - if (flags == DNS_OBJECT)
339 - {
340 -
341 - if (strlen (zname) != strlen (zone))
342 - {
343 - tmp = &zname[strlen (zname) - strlen (zone)];
344 - *--tmp = '\0';
345 - hnamebuff = strdup (zname);
346 - if (hnamebuff == NULL)
347 - fatal("strdup");
348 - zname = ++tmp;
349 - }
350 - else
351 - hnamebuff = (char*)"@";
352 - }
353 - else
354 - {
355 - zname = zone;
356 - hnamebuff = NULL;
357 - }
358 -
359 - for (tmp = strrchr (zname, '.'); tmp != (char *) 0;
360 - tmp = strrchr (zname, '.'))
361 - {
362 - *tmp++ = '\0';
363 - dn_buffer[i++] = tmp;
364 - }
365 - dn_buffer[i++] = zname;
366 - dn_buffer[i++] = hnamebuff;
367 + char *hname=0L, *last=0L;
368 + int hlen=strlen(hostname), zlen=(strlen(zone));
369 +
370 +/* printf("hostname: %s zone: %s\n",hostname, zone); */
371 + hname=0L;
372 + if(flags == DNS_OBJECT)
373 + {
374 + if( (zone[ zlen - 1 ] == '.') && (hostname[hlen - 1] != '.') )
375 + {
376 + hname=(char*)malloc(hlen + 1);
377 + hlen += 1;
378 + sprintf(hname, "%s.", hostname);
379 + hostname = hname;
380 + }
381 + if(strcmp(hostname, zone) == 0)
382 + {
383 + if( hname == 0 )
384 + hname=strdup(hostname);
385 + last = strdup(sameZone);
386 + }else
387 + {
388 + if( (hlen < zlen)
389 + ||( strcmp( hostname + (hlen - zlen), zone ) != 0)
390 + )
391 + {
392 + if( hname != 0 )
393 + free(hname);
394 + hname=(char*)malloc( hlen + zlen + 1);
395 + if( *zone == '.' )
396 + sprintf(hname, "%s%s", hostname, zone);
397 + else
398 + sprintf(hname,"%s",zone);
399 + }else
400 + {
401 + if( hname == 0 )
402 + hname = strdup(hostname);
403 + }
404 + last = hname;
405 + }
406 + }else
407 + { /* flags == DNS_TOP */
408 + hname = strdup(zone);
409 + last = hname;
410 + }
411 +
412 + for (tmp = strrchr (hname, '.'); tmp != (char *) 0;
413 + tmp = strrchr (hname, '.'))
414 + {
415 + if( *( tmp + 1 ) != '\0' )
416 + {
417 + *tmp = '\0';
418 + dn_buffer[i++] = ++tmp;
419 + }else
420 + { /* trailing '.' ! */
421 + dn_buffer[i++] = strdup(".");
422 + *tmp = '\0';
423 + if( tmp == hname )
424 + break;
425 + }
426 + }
427 + if( ( last != hname ) && (tmp != hname) )
428 + dn_buffer[i++] = hname;
429 + dn_buffer[i++] = last;
430 dn_buffer[i] = NULL;
431
432 return dn_buffer;
433 @@ -680,24 +780,32 @@ hostname_to_dn_list (char *hostname, char *zone, unsigned int flags)
434 * exception of "@"/SOA. */
435
436 char *
437 -build_dn_from_dc_list (char **dc_list, unsigned int ttl, int flag)
438 +build_dn_from_dc_list (char **dc_list, unsigned int ttl, int flag, char *zone)
439 {
440 int size;
441 - int x;
442 + int x, znlen;
443 static char dn[1024];
444 char tmp[128];
445 + char zn[DNS_NAME_MAXTEXT+1];
446
447 bzero (tmp, sizeof (tmp));
448 bzero (dn, sizeof (dn));
449 size = get_attr_list_size (dc_list);
450 + znlen = strlen(zone);
451 + if ( *(zone + (znlen-1)) == '.' )
452 + { /* ldapdb MUST search by relative zone name */
453 + memcpy(&(zn[0]),zone,znlen-1);
454 + *(zn + (znlen-1))='\0';
455 + zone = zn;
456 + }
457 for (x = size - 2; x > 0; x--)
458 {
459 if (flag == WI_SPEC)
460 {
461 if (x == (size - 2) && (strncmp (dc_list[x], "@", 1) == 0) && (ttl))
462 - sprintf (tmp, "relativeDomainName=%s + dNSTTL=%u,", dc_list[x], ttl);
463 + sprintf (tmp, "zoneName=%s + relativeDomainName=%s,", zone, dc_list[x]);
464 else if (x == (size - 2))
465 - sprintf(tmp, "relativeDomainName=%s,",dc_list[x]);
466 + sprintf(tmp, "zoneName=%s + relativeDomainName=%s,", zone, dc_list[x]);
467 else
468 sprintf(tmp,"dc=%s,", dc_list[x]);
469 }
470 @@ -723,6 +831,7 @@ void
471 init_ldap_conn ()
472 {
473 int result;
474 + char ldb_tag[]="LDAP Bind";
475 conn = ldap_open (ldapsystem, LDAP_PORT);
476 if (conn == NULL)
477 {
478 @@ -732,7 +841,7 @@ init_ldap_conn ()
479 }
480
481 result = ldap_simple_bind_s (conn, binddn, bindpw);
482 - ldap_result_check ("ldap_simple_bind_s", (char*)"LDAP Bind", result);
483 + ldap_result_check ("ldap_simple_bind_s", ldb_tag , result);
484 }
485
486 /* Like isc_result_check, only for LDAP */
487 @@ -749,8 +858,6 @@ ldap_result_check (const char *msg, char *dn, int err)
488 }
489 }
490
491 -
492 -
493 /* For running the ldap_info run queue. */
494 void
495 add_ldap_values (ldap_info * ldinfo)
496 @@ -758,14 +865,14 @@ add_ldap_values (ldap_info * ldinfo)
497 int result;
498 char dnbuffer[1024];
499
500 -
501 if (ldapbase != NULL)
502 sprintf (dnbuffer, "%s,%s", ldinfo->dn, ldapbase);
503 else
504 sprintf (dnbuffer, "%s", ldinfo->dn);
505
506 result = ldap_add_s (conn, dnbuffer, ldinfo->attrs);
507 - ldap_result_check ("ldap_add_s", dnbuffer, result);
508 + ldap_result_check ("ldap_add_s", dnbuffer, result);
509 +
510 }
511
512
513 @@ -776,5 +883,5 @@ void
514 usage ()
515 {
516 fprintf (stderr,
517 - "zone2ldap -D [BIND DN] -w [BIND PASSWORD] -b [BASE DN] -z [ZONE] -f [ZONE FILE] -h [LDAP HOST] "
518 + "zone2ldap -D [BIND DN] [-w BIND PASSWORD | -W:prompt] -b [BASE DN] -z [ZONE] -f [ZONE FILE] -h [LDAP HOST] "
519 "[-c Create LDAP Base structure][-d Debug Output (lots !)] \n ");}

  ViewVC Help
Powered by ViewVC 1.1.26