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