bc5dde
diff -up bind-9.5.1b1/bin/sdb_tools/Makefile.in.fix_sdb_ldap bind-9.5.1b1/bin/sdb_tools/Makefile.in
bc5dde
--- bind-9.5.1b1/bin/sdb_tools/Makefile.in.fix_sdb_ldap	2008-07-21 12:14:00.000000000 +0200
bc5dde
+++ bind-9.5.1b1/bin/sdb_tools/Makefile.in	2008-07-21 12:17:51.000000000 +0200
bc5dde
@@ -30,11 +30,11 @@ DEPLIBS =	${LWRESDEPLIBS} ${DNSDEPLIBS} 
bc5dde
 LIBS =		${LWRESLIBS} ${DNSLIBS} ${BIND9LIBS} \
bc5dde
 		${ISCCFGLIBS} ${ISCCCLIBS} ${ISCLIBS} ${DBDRIVER_LIBS} @LIBS@
bc5dde
 
bc5dde
-TARGETS =	zone2ldap@EXEEXT@ zonetodb@EXEEXT@
bc5dde
+TARGETS =	zone2ldap@EXEEXT@ ldap2zone@EXEEXT@ zonetodb@EXEEXT@
bc5dde
 
bc5dde
-OBJS	=	zone2ldap.@O@ zonetodb.@O@
bc5dde
+OBJS	=	zone2ldap.@O@ ldap2zone.@O@ zonetodb.@O@
bc5dde
 
bc5dde
-SRCS    =       zone2ldap.c zonetodb.c
bc5dde
+SRCS    =       zone2ldap.c ldap2zone.c zonetodb.c
bc5dde
 
bc5dde
 MANPAGES =      zone2ldap.1
bc5dde
 
bc5dde
@@ -48,6 +48,9 @@ zone2ldap@EXEEXT@: zone2ldap.@O@ ${DEPLI
bc5dde
 zonetodb@EXEEXT@: zonetodb.@O@  ${DEPLIBS}
bc5dde
 	${LIBTOOL_MODE_LINK} ${PURIFY} ${CC} ${CFLAGS} ${LDFLAGS} -o $@ zonetodb.@O@ -lpq ${LIBS}
bc5dde
 
bc5dde
+ldap2zone@EXEEXT@: ldap2zone.@O@ ${DEPLIBS}
bc5dde
+	${LIBTOOL_MODE_LINK} ${PURIFY} ${CC} ${ALL_CFLAGS} ${LDFLAGS} -o $@ ldap2zone.@O@ -lldap -llber ${LIBS}
bc5dde
+
bc5dde
 clean distclean manclean maintainer-clean::
bc5dde
 	rm -f ${TARGETS} ${OBJS}
bc5dde
 
bc5dde
@@ -57,5 +60,6 @@ installdirs:
bc5dde
 
bc5dde
 install:: ${TARGETS} installdirs
bc5dde
 	${LIBTOOL_MODE_INSTALL} ${INSTALL_PROGRAM} zone2ldap@EXEEXT@ ${DESTDIR}${sbindir}
bc5dde
+	${LIBTOOL_MODE_INSTALL} ${INSTALL_PROGRAM} ldap2zone@EXEEXT@ ${DESTDIR}${sbindir}
bc5dde
 	${LIBTOOL_MODE_INSTALL} ${INSTALL_PROGRAM} zonetodb@EXEEXT@  ${DESTDIR}${sbindir}
bc5dde
 	${INSTALL_DATA} ${srcdir}/zone2ldap.1 ${DESTDIR}${mandir}/man1/zone2ldap.1
bc5dde
diff -up bind-9.5.1b1/bin/sdb_tools/zone2ldap.c.fix_sdb_ldap bind-9.5.1b1/bin/sdb_tools/zone2ldap.c
bc5dde
--- bind-9.5.1b1/bin/sdb_tools/zone2ldap.c.fix_sdb_ldap	2008-07-21 12:14:00.000000000 +0200
bc5dde
+++ bind-9.5.1b1/bin/sdb_tools/zone2ldap.c	2008-07-21 12:14:00.000000000 +0200
bc5dde
@@ -24,6 +24,7 @@
bc5dde
 #include <isc/hash.h>
bc5dde
 #include <isc/mem.h>
bc5dde
 #include <isc/print.h>
bc5dde
+#include <isc/hash.h>
bc5dde
 #include <isc/result.h>
bc5dde
 
bc5dde
 #include <dns/db.h>
bc5dde
@@ -61,6 +62,9 @@ ldap_info;
bc5dde
 /* usage Info */
bc5dde
 void usage (void);
bc5dde
 
bc5dde
+/* Check for existence of (and possibly add) containing dNSZone objects */
bc5dde
+int lookup_dns_zones( ldap_info *ldinfo);
bc5dde
+
bc5dde
 /* Add to the ldap dit */
bc5dde
 void add_ldap_values (ldap_info * ldinfo);
bc5dde
 
bc5dde
@@ -77,7 +81,7 @@ char **hostname_to_dn_list (char *hostna
bc5dde
 int get_attr_list_size (char **tmp);
bc5dde
 
bc5dde
 /* Get a DN */
bc5dde
-char *build_dn_from_dc_list (char **dc_list, unsigned int ttl, int flag);
bc5dde
+char *build_dn_from_dc_list (char **dc_list, unsigned int ttl, int flag, char *zone);
bc5dde
 
bc5dde
 /* Add to RR list */
bc5dde
 void add_to_rr_list (char *dn, char *name, char *type, char *data,
bc5dde
@@ -99,11 +103,27 @@ void
bc5dde
 init_ldap_conn ();
bc5dde
 void usage();
bc5dde
 
bc5dde
-char *argzone, *ldapbase, *binddn, *bindpw = NULL;
bc5dde
-const char *ldapsystem = "localhost";
bc5dde
-static const char *objectClasses[] =
bc5dde
-  { "top", "dNSZone", NULL };
bc5dde
-static const char *topObjectClasses[] = { "top", NULL };
bc5dde
+static char *argzone, *ldapbase, *binddn, *bindpw = NULL;
bc5dde
+
bc5dde
+/* these are needed to placate gcc4's const-ness const-ernations : */
bc5dde
+static char localhost[] = "localhost";
bc5dde
+static char *ldapsystem=&(localhost[0]);
bc5dde
+/* dnszone schema class names: */
bc5dde
+static char topClass    [] ="top";
bc5dde
+static char dNSZoneClass[] ="dNSZone";
bc5dde
+static char objectClass [] ="objectClass";
bc5dde
+static char dcObjectClass[]="dcObject";
bc5dde
+/* dnszone schema attribute names: */
bc5dde
+static char relativeDomainName[]="relativeDomainName";
bc5dde
+static char dNSTTL            []="dNSTTL";
bc5dde
+static char zoneName          []="zoneName";
bc5dde
+static char dc                []="dc";
bc5dde
+static char sameZone          []="@";
bc5dde
+/* LDAPMod mod_values: */
bc5dde
+static char *objectClasses    []= { &(topClass[0]), &(dNSZoneClass[0]), NULL };
bc5dde
+static char *topObjectClasses []= { &(topClass[0]), &(dcObjectClass[0]), &(dNSZoneClass[0]), NULL };
bc5dde
+static char *dn_buffer      [64]={NULL};
bc5dde
+
bc5dde
 LDAP *conn;
bc5dde
 unsigned int debug = 0;
bc5dde
 
bc5dde
@@ -119,12 +139,12 @@ main (int argc, char **argv)
bc5dde
   isc_result_t result;
bc5dde
   char *basedn;
bc5dde
   ldap_info *tmp;
bc5dde
-  LDAPMod *base_attrs[2];
bc5dde
-  LDAPMod base;
bc5dde
+  LDAPMod *base_attrs[5];
bc5dde
+  LDAPMod base, dcBase, znBase, rdnBase;
bc5dde
   isc_buffer_t buff;
bc5dde
   char *zonefile=0L;
bc5dde
   char fullbasedn[1024];
bc5dde
-  char *ctmp;
bc5dde
+  char *ctmp, *zn, *dcp[2], *znp[2], *rdn[2];
bc5dde
   dns_fixedname_t fixedzone, fixedname;
bc5dde
   dns_rdataset_t rdataset;
bc5dde
   char **dc_list;
bc5dde
@@ -137,7 +157,7 @@ main (int argc, char **argv)
bc5dde
   extern char *optarg;
bc5dde
   extern int optind, opterr, optopt;
bc5dde
   int create_base = 0;
bc5dde
-  int topt;
bc5dde
+  int topt, dcn, zdn, znlen;
bc5dde
 
bc5dde
   if ((int) argc < 2)
bc5dde
     {
bc5dde
@@ -145,7 +165,7 @@ main (int argc, char **argv)
bc5dde
       exit (-1);
bc5dde
     }
bc5dde
 
bc5dde
-  while ((topt = getopt ((int) argc, argv, "D:w:b:z:f:h:?dcv")) != -1)
bc5dde
+  while ((topt = getopt ((int) argc, argv, "D:Ww:b:z:f:h:?dcv")) != -1)
bc5dde
     {
bc5dde
       switch (topt)
bc5dde
 	{
bc5dde
@@ -164,8 +184,11 @@ main (int argc, char **argv)
bc5dde
 	case 'w':
bc5dde
 	  bindpw = strdup (optarg);
bc5dde
 	  break;
bc5dde
+	case 'W':
bc5dde
+	  bindpw = getpass("Enter LDAP Password: ");
bc5dde
+	  break;
bc5dde
 	case 'b':
bc5dde
-	  ldapbase = strdup (optarg);
bc5dde
+          ldapbase = strdup (optarg);
bc5dde
 	  break;
bc5dde
 	case 'z':
bc5dde
 	  argzone = strdup (optarg);
bc5dde
@@ -277,27 +300,62 @@ main (int argc, char **argv)
bc5dde
     {
bc5dde
       if (debug)
bc5dde
 	printf ("Creating base zone DN %s\n", argzone);
bc5dde
-
bc5dde
+      
bc5dde
       dc_list = hostname_to_dn_list (argzone, argzone, DNS_TOP);
bc5dde
-      basedn = build_dn_from_dc_list (dc_list, 0, NO_SPEC);
bc5dde
 
bc5dde
-      for (ctmp = &basedn[strlen (basedn)]; ctmp >= &basedn[0]; ctmp--)
bc5dde
+      basedn = build_dn_from_dc_list (dc_list, 0, NO_SPEC, argzone);
bc5dde
+      if (debug)
bc5dde
+	printf ("base DN %s\n", basedn);
bc5dde
+
bc5dde
+      for (ctmp = &basedn[strlen (basedn)], dcn=0; ctmp >= &basedn[0]; ctmp--)
bc5dde
 	{
bc5dde
-	  if ((*ctmp == ',') || (ctmp == &basedn[0]))
bc5dde
+	    if ((*ctmp == ',') || (ctmp == &basedn[0]))
bc5dde
 	    {
bc5dde
+
bc5dde
 	      base.mod_op = LDAP_MOD_ADD;
bc5dde
-	      base.mod_type = (char*)"objectClass";
bc5dde
-	      base.mod_values = (char**)topObjectClasses;
bc5dde
+	      base.mod_type = objectClass;
bc5dde
+	      base.mod_values = topObjectClasses;
bc5dde
 	      base_attrs[0] = (void*)&bas;;
bc5dde
-	      base_attrs[1] = NULL;
bc5dde
-
bc5dde
+	     
bc5dde
+	      dcBase.mod_op = LDAP_MOD_ADD;
bc5dde
+	      dcBase.mod_type = dc;
bc5dde
+	      dcp[0]=dc_list[dcn];
bc5dde
+	      dcp[1]=0L;
bc5dde
+	      dcBase.mod_values=dcp;
bc5dde
+	      base_attrs[1] = (void*)&dcBase;
bc5dde
+
bc5dde
+	      znBase.mod_op = LDAP_MOD_ADD;
bc5dde
+	      znBase.mod_type = zoneName;	      
bc5dde
+	      for( zdn = dcn, znlen = 0; zdn >= 0; zdn-- )
bc5dde
+		  znlen += strlen(dc_list[zdn])+1;
bc5dde
+	      znp[0] = (char*)malloc(znlen+1);
bc5dde
+	      znp[1] = 0L;
bc5dde
+	      for( zdn = dcn, zn=znp[0]; zdn >= 0; zdn-- )		  
bc5dde
+		  zn+=sprintf(zn,"%s%s",dc_list[zdn], 
bc5dde
+			      ((zdn > 0) && (*(dc_list[zdn-1])!='.')) ? "." : ""
bc5dde
+		             );
bc5dde
+
bc5dde
+	      znBase.mod_values = znp;
bc5dde
+	      base_attrs[2] = (void*)&znBase;
bc5dde
+
bc5dde
+	      rdnBase.mod_op = LDAP_MOD_ADD;
bc5dde
+	      rdnBase.mod_type = relativeDomainName;
bc5dde
+	      rdn[0] = strdup(sameZone);
bc5dde
+	      rdn[1] = 0L;
bc5dde
+	      rdnBase.mod_values = rdn;
bc5dde
+	      base_attrs[3] = (void*)&rdnBase;
bc5dde
+	      
bc5dde
+	      dcn++;
bc5dde
+
bc5dde
+	      base.mod_values = topObjectClasses;
bc5dde
+	      base_attrs[4] = NULL;	      
bc5dde
+	      
bc5dde
 	      if (ldapbase)
bc5dde
 		{
bc5dde
 		  if (ctmp != &basedn[0])
bc5dde
 		    sprintf (fullbasedn, "%s,%s", ctmp + 1, ldapbase);
bc5dde
 		  else
bc5dde
-		    sprintf (fullbasedn, "%s,%s", ctmp, ldapbase);
bc5dde
-
bc5dde
+		    sprintf (fullbasedn, "%s,%s", ctmp, ldapbase);		  
bc5dde
 		}
bc5dde
 	      else
bc5dde
 		{
bc5dde
@@ -306,8 +364,13 @@ main (int argc, char **argv)
bc5dde
 		  else
bc5dde
 		    sprintf (fullbasedn, "%s", ctmp);
bc5dde
 		}
bc5dde
+
bc5dde
+	      if( debug )
bc5dde
+		  printf("Full base dn: %s\n", fullbasedn);
bc5dde
+
bc5dde
 	      result = ldap_add_s (conn, fullbasedn, base_attrs);
bc5dde
 	      ldap_result_check ("intial ldap_add_s", fullbasedn, result);
bc5dde
+
bc5dde
 	    }
bc5dde
 
bc5dde
 	}
bc5dde
@@ -383,14 +446,14 @@ generate_ldap (dns_name_t * dnsname, dns
bc5dde
   isc_result_check (result, "dns_rdata_totext");
bc5dde
   data[isc_buffer_usedlength (&buff)] = 0;
bc5dde
 
bc5dde
-  dc_list = hostname_to_dn_list (name, argzone, DNS_OBJECT);
bc5dde
+  dc_list = hostname_to_dn_list ((char*)name, argzone, DNS_OBJECT);
bc5dde
   len = (get_attr_list_size (dc_list) - 2);
bc5dde
-  dn = build_dn_from_dc_list (dc_list, ttl, WI_SPEC);
bc5dde
+  dn = build_dn_from_dc_list (dc_list, ttl, WI_SPEC, argzone);
bc5dde
 
bc5dde
   if (debug)
bc5dde
     printf ("Adding %s (%s %s) to run queue list.\n", dn, type, data);
bc5dde
 
bc5dde
-  add_to_rr_list (dn, dc_list[len], type, data, ttl, DNS_OBJECT);
bc5dde
+  add_to_rr_list (dn, dc_list[len], (char*)type, (char*)data, ttl, DNS_OBJECT);
bc5dde
 }
bc5dde
 
bc5dde
 
bc5dde
@@ -430,7 +493,8 @@ add_to_rr_list (char *dn, char *name, ch
bc5dde
   int attrlist;
bc5dde
   char ldap_type_buffer[128];
bc5dde
   char charttl[64];
bc5dde
-
bc5dde
+  char *zn;
bc5dde
+  int znlen;
bc5dde
 
bc5dde
   if ((tmp = locate_by_dn (dn)) == NULL)
bc5dde
     {
bc5dde
@@ -465,13 +529,13 @@ add_to_rr_list (char *dn, char *name, ch
bc5dde
 	    }
bc5dde
 	}
bc5dde
       tmp->attrs[0]->mod_op = LDAP_MOD_ADD;
bc5dde
-      tmp->attrs[0]->mod_type = (char*)"objectClass";
bc5dde
+      tmp->attrs[0]->mod_type = objectClass;
bc5dde
 
bc5dde
       if (flags == DNS_OBJECT)
bc5dde
-	tmp->attrs[0]->mod_values = (char**)objectClasses;
bc5dde
+	tmp->attrs[0]->mod_values = objectClasses;
bc5dde
       else
bc5dde
 	{
bc5dde
-	  tmp->attrs[0]->mod_values = (char**)topObjectClasses;
bc5dde
+	  tmp->attrs[0]->mod_values =topObjectClasses;
bc5dde
 	  tmp->attrs[1] = NULL;
bc5dde
 	  tmp->attrcnt = 2;
bc5dde
 	  tmp->next = ldap_info_base;
bc5dde
@@ -480,7 +544,7 @@ add_to_rr_list (char *dn, char *name, ch
bc5dde
 	}
bc5dde
 
bc5dde
       tmp->attrs[1]->mod_op = LDAP_MOD_ADD;
bc5dde
-      tmp->attrs[1]->mod_type = (char*)"relativeDomainName";
bc5dde
+      tmp->attrs[1]->mod_type = relativeDomainName;
bc5dde
       tmp->attrs[1]->mod_values = (char **) calloc (sizeof (char *), 2);
bc5dde
 
bc5dde
       if (tmp->attrs[1]->mod_values == (char **)NULL)
bc5dde
@@ -502,7 +566,7 @@ add_to_rr_list (char *dn, char *name, ch
bc5dde
       tmp->attrs[2]->mod_values[1] = NULL;
bc5dde
 
bc5dde
       tmp->attrs[3]->mod_op = LDAP_MOD_ADD;
bc5dde
-      tmp->attrs[3]->mod_type = (char*)"dNSTTL";
bc5dde
+      tmp->attrs[3]->mod_type = dNSTTL;
bc5dde
       tmp->attrs[3]->mod_values = (char **) calloc (sizeof (char *), 2);
bc5dde
 
bc5dde
       if (tmp->attrs[3]->mod_values == (char **)NULL)
bc5dde
@@ -512,10 +576,21 @@ add_to_rr_list (char *dn, char *name, ch
bc5dde
       tmp->attrs[3]->mod_values[0] = strdup (charttl);
bc5dde
       tmp->attrs[3]->mod_values[1] = NULL;
bc5dde
 
bc5dde
+      znlen=strlen(gbl_zone);      
bc5dde
+      if ( *(gbl_zone + (znlen-1)) == '.' )
bc5dde
+      { /* ldapdb MUST search by relative zone name */
bc5dde
+	  zn = (char*)malloc(znlen);
bc5dde
+	  strncpy(zn,gbl_zone,znlen-1);
bc5dde
+	  *(zn + (znlen-1))='\0';	  
bc5dde
+      }else
bc5dde
+      {
bc5dde
+	  zn = gbl_zone;
bc5dde
+      }
bc5dde
+
bc5dde
       tmp->attrs[4]->mod_op = LDAP_MOD_ADD;
bc5dde
-      tmp->attrs[4]->mod_type = (char*)"zoneName";
bc5dde
+      tmp->attrs[4]->mod_type = zoneName;
bc5dde
       tmp->attrs[4]->mod_values = (char **)calloc(sizeof(char *), 2);
bc5dde
-      tmp->attrs[4]->mod_values[0] = gbl_zone;
bc5dde
+      tmp->attrs[4]->mod_values[0] = zn;
bc5dde
       tmp->attrs[4]->mod_values[1] = NULL;
bc5dde
 
bc5dde
       tmp->attrs[5] = NULL;
bc5dde
@@ -526,7 +601,7 @@ add_to_rr_list (char *dn, char *name, ch
bc5dde
   else
bc5dde
     {
bc5dde
 
bc5dde
-      for (i = 0; tmp->attrs[i] != NULL; i++)
bc5dde
+	for (i = 0; tmp->attrs[i] != NULL; i++)
bc5dde
 	{
bc5dde
 	  sprintf (ldap_type_buffer, "%sRecord", type);
bc5dde
 	  if (!strncmp
bc5dde
@@ -595,69 +670,105 @@ char **
bc5dde
 hostname_to_dn_list (char *hostname, char *zone, unsigned int flags)
bc5dde
 {
bc5dde
   char *tmp;
bc5dde
-  static char *dn_buffer[64];
bc5dde
   int i = 0;
bc5dde
-  char *zname;
bc5dde
-  char *hnamebuff;
bc5dde
-
bc5dde
-  zname = strdup (hostname);
bc5dde
-
bc5dde
-  if (flags == DNS_OBJECT)
bc5dde
-    {
bc5dde
+  char *hname=0L, *last=0L;
bc5dde
+  int hlen=strlen(hostname), zlen=(strlen(zone));
bc5dde
 
bc5dde
-      if (strlen (zname) != strlen (zone))
bc5dde
-	{
bc5dde
-	  tmp = &zname[strlen (zname) - strlen (zone)];
bc5dde
-	  *--tmp = '\0';
bc5dde
-	  hnamebuff = strdup (zname);
bc5dde
-	  zname = ++tmp;
bc5dde
-	}
bc5dde
-      else
bc5dde
-	hnamebuff = (char*)"@";
bc5dde
-    }
bc5dde
-  else
bc5dde
-    {
bc5dde
-      zname = zone;
bc5dde
-      hnamebuff = NULL;
bc5dde
-    }
bc5dde
-
bc5dde
-  for (tmp = strrchr (zname, '.'); tmp != (char *) 0;
bc5dde
-       tmp = strrchr (zname, '.'))
bc5dde
-    {
bc5dde
-      *tmp++ = '\0';
bc5dde
-      dn_buffer[i++] = tmp;
bc5dde
-    }
bc5dde
-  dn_buffer[i++] = zname;
bc5dde
-  dn_buffer[i++] = hnamebuff;
bc5dde
+/*  printf("hostname: %s zone: %s\n",hostname, zone); */
bc5dde
+  hname=0L;
bc5dde
+  if(flags == DNS_OBJECT)
bc5dde
+  {
bc5dde
+      if( (zone[ zlen - 1 ] == '.') && (hostname[hlen - 1] != '.') )
bc5dde
+      {
bc5dde
+	  hname=(char*)malloc(hlen + 1);
bc5dde
+	  hlen += 1;
bc5dde
+	  sprintf(hname, "%s.", hostname);
bc5dde
+	  hostname = hname;
bc5dde
+      }
bc5dde
+      if(strcmp(hostname, zone) == 0)
bc5dde
+      {
bc5dde
+	  if( hname == 0 )
bc5dde
+	      hname=strdup(hostname);
bc5dde
+  	  last = strdup(sameZone);
bc5dde
+      }else
bc5dde
+      {	   
bc5dde
+	  if(  (hlen < zlen) 
bc5dde
+	     ||( strcmp( hostname + (hlen - zlen), zone ) != 0)
bc5dde
+	    )
bc5dde
+	  {
bc5dde
+	      if( hname != 0 )
bc5dde
+		  free(hname);
bc5dde
+	      hname=(char*)malloc( hlen + zlen + 1);
bc5dde
+	      if( *zone == '.' )
bc5dde
+		  sprintf(hname, "%s%s", hostname, zone);
bc5dde
+	      else
bc5dde
+		  sprintf(hname,"%s",zone);
bc5dde
+	  }else
bc5dde
+	  {
bc5dde
+	      if( hname == 0 )
bc5dde
+		  hname = strdup(hostname);
bc5dde
+	  }
bc5dde
+	  last = hname;
bc5dde
+      }
bc5dde
+  }else
bc5dde
+  { /* flags == DNS_TOP */
bc5dde
+      hname = strdup(zone);
bc5dde
+      last = hname;
bc5dde
+  }
bc5dde
+
bc5dde
+  for (tmp = strrchr (hname, '.'); tmp != (char *) 0;
bc5dde
+       tmp = strrchr (hname, '.'))
bc5dde
+  {
bc5dde
+      if( *( tmp + 1 ) != '\0' )
bc5dde
+      {
bc5dde
+	  *tmp = '\0';
bc5dde
+	  dn_buffer[i++] = ++tmp;
bc5dde
+      }else
bc5dde
+      { /* trailing '.' ! */
bc5dde
+	  dn_buffer[i++] = strdup(".");
bc5dde
+	  *tmp = '\0';
bc5dde
+	  if( tmp == hname )
bc5dde
+	      break;
bc5dde
+      }	  
bc5dde
+  }
bc5dde
+  if( ( last != hname ) && (tmp != hname) )
bc5dde
+      dn_buffer[i++] = hname;
bc5dde
+  dn_buffer[i++] = last;
bc5dde
   dn_buffer[i] = NULL;
bc5dde
-
bc5dde
   return dn_buffer;
bc5dde
 }
bc5dde
 
bc5dde
-
bc5dde
 /* build an sdb compatible LDAP DN from a "dc_list" (char **).
bc5dde
  * will append dNSTTL information to each RR Record, with the 
bc5dde
  * exception of "@"/SOA. */
bc5dde
 
bc5dde
 char *
bc5dde
-build_dn_from_dc_list (char **dc_list, unsigned int ttl, int flag)
bc5dde
+build_dn_from_dc_list (char **dc_list, unsigned int ttl, int flag, char *zone)
bc5dde
 {
bc5dde
   int size;
bc5dde
-  int x;
bc5dde
+  int x, znlen;
bc5dde
   static char dn[1024];
bc5dde
   char tmp[128];
bc5dde
+  char zn[DNS_NAME_MAXTEXT+1];
bc5dde
 
bc5dde
   bzero (tmp, sizeof (tmp));
bc5dde
   bzero (dn, sizeof (dn));
bc5dde
   size = get_attr_list_size (dc_list);
bc5dde
+  znlen = strlen(zone);
bc5dde
+  if ( *(zone + (znlen-1)) == '.' )
bc5dde
+  { /* ldapdb MUST search by relative zone name */
bc5dde
+      memcpy(&(zn[0]),zone,znlen-1);
bc5dde
+      *(zn + (znlen-1))='\0';
bc5dde
+      zone = zn;
bc5dde
+  }
bc5dde
   for (x = size - 2; x > 0; x--)
bc5dde
     {
bc5dde
     if (flag == WI_SPEC)
bc5dde
     {
bc5dde
       if (x == (size - 2) && (strncmp (dc_list[x], "@", 1) == 0) && (ttl))
bc5dde
-	sprintf (tmp, "relativeDomainName=%s + dNSTTL=%d,", dc_list[x], ttl);
bc5dde
+	sprintf (tmp, "zoneName=%s + relativeDomainName=%s,", zone, dc_list[x]);
bc5dde
       else if (x == (size - 2))
bc5dde
-	      sprintf(tmp, "relativeDomainName=%s,",dc_list[x]);
bc5dde
+	      sprintf(tmp, "zoneName=%s + relativeDomainName=%s,", zone, dc_list[x]);
bc5dde
       else
bc5dde
 	      sprintf(tmp,"dc=%s,", dc_list[x]);
bc5dde
     }
bc5dde
@@ -683,6 +794,7 @@ void
bc5dde
 init_ldap_conn ()
bc5dde
 {
bc5dde
   int result;
bc5dde
+  char ldb_tag[]="LDAP Bind";
bc5dde
   conn = ldap_open (ldapsystem, LDAP_PORT);
bc5dde
   if (conn == NULL)
bc5dde
     {
bc5dde
@@ -692,7 +804,7 @@ init_ldap_conn ()
bc5dde
     }
bc5dde
 
bc5dde
   result = ldap_simple_bind_s (conn, binddn, bindpw);
bc5dde
-  ldap_result_check ("ldap_simple_bind_s", (char*)"LDAP Bind", result);
bc5dde
+  ldap_result_check ("ldap_simple_bind_s", ldb_tag , result);
bc5dde
 }
bc5dde
 
bc5dde
 /* Like isc_result_check, only for LDAP */
bc5dde
@@ -709,8 +821,6 @@ ldap_result_check (const char *msg, char
bc5dde
     }
bc5dde
 }
bc5dde
 
bc5dde
-
bc5dde
-
bc5dde
 /* For running the ldap_info run queue. */
bc5dde
 void
bc5dde
 add_ldap_values (ldap_info * ldinfo)
bc5dde
@@ -718,14 +828,14 @@ add_ldap_values (ldap_info * ldinfo)
bc5dde
   int result;
bc5dde
   char dnbuffer[1024];
bc5dde
 
bc5dde
-
bc5dde
   if (ldapbase != NULL)
bc5dde
     sprintf (dnbuffer, "%s,%s", ldinfo->dn, ldapbase);
bc5dde
   else
bc5dde
     sprintf (dnbuffer, "%s", ldinfo->dn);
bc5dde
 
bc5dde
   result = ldap_add_s (conn, dnbuffer, ldinfo->attrs);
bc5dde
-  ldap_result_check ("ldap_add_s", dnbuffer, result);
bc5dde
+    ldap_result_check ("ldap_add_s", dnbuffer, result);
bc5dde
+
bc5dde
 }
bc5dde
 
bc5dde
 
bc5dde
@@ -736,7 +846,7 @@ void
bc5dde
 usage ()
bc5dde
 {
bc5dde
   fprintf (stderr,
bc5dde
-	   "zone2ldap -D [BIND DN] -w [BIND PASSWORD] -b [BASE DN] -z [ZONE] -f [ZONE FILE] -h [LDAP HOST]\n"
bc5dde
+	   "zone2ldap -D [BIND DN] [-w BIND PASSWORD | -W:prompt] -b [BASE DN] -z [ZONE] -f [ZONE FILE] -h [LDAP HOST]\n"
bc5dde
 	   "\t[-c Create LDAP Base structure][-d Debug Output (lots !)]\n "
bc5dde
           );
bc5dde
 }