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