|
|
3ce7d3 |
diff --git a/bin/sdb_tools/Makefile.in b/bin/sdb_tools/Makefile.in
|
|
|
3ce7d3 |
index 95ab742..6069f09 100644
|
|
|
3ce7d3 |
--- a/bin/sdb_tools/Makefile.in
|
|
|
3ce7d3 |
+++ b/bin/sdb_tools/Makefile.in
|
|
|
3ce7d3 |
@@ -32,11 +32,11 @@ DEPLIBS = ${LWRESDEPLIBS} ${DNSDEPLIBS} ${BIND9DEPLIBS} \
|
|
|
bc5dde |
LIBS = ${LWRESLIBS} ${DNSLIBS} ${BIND9LIBS} \
|
|
|
bc5dde |
${ISCCFGLIBS} ${ISCCCLIBS} ${ISCLIBS} ${DBDRIVER_LIBS} @LIBS@
|
|
|
bc5dde |
|
|
|
3ce7d3 |
-TARGETS = zone2ldap@EXEEXT@ zonetodb@EXEEXT@ zone2sqlite@EXEEXT@
|
|
|
3ce7d3 |
+TARGETS = zone2ldap@EXEEXT@ ldap2zone@EXEEXT@ zonetodb@EXEEXT@ zone2sqlite@EXEEXT@
|
|
|
bc5dde |
|
|
|
3ce7d3 |
-OBJS = zone2ldap.@O@ zonetodb.@O@ zone2sqlite.@O@
|
|
|
3ce7d3 |
+OBJS = zone2ldap.@O@ ldap2zone.@O@ zonetodb.@O@ zone2sqlite.@O@
|
|
|
bc5dde |
|
|
|
3ce7d3 |
-SRCS = zone2ldap.c zonetodb.c zone2sqlite.c
|
|
|
3ce7d3 |
+SRCS = zone2ldap.c ldap2zone.c zonetodb.c zone2sqlite.c
|
|
|
bc5dde |
|
|
|
bc5dde |
MANPAGES = zone2ldap.1
|
|
|
bc5dde |
|
|
|
3ce7d3 |
@@ -53,6 +53,9 @@ zonetodb@EXEEXT@: zonetodb.@O@ ${DEPLIBS}
|
|
|
3ce7d3 |
zone2sqlite@EXEEXT@: zone2sqlite.@O@ ${DEPLIBS}
|
|
|
3ce7d3 |
${LIBTOOL_MODE_LINK} ${PURIFY} ${CC} ${ALL_CFLAGS} ${LDFLAGS} -o $@ zone2sqlite.@O@ -lsqlite3 -lssl ${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 |
|
|
|
3ce7d3 |
@@ -62,6 +65,7 @@ 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}
|
|
|
3ce7d3 |
${LIBTOOL_MODE_INSTALL} ${INSTALL_PROGRAM} zone2sqlite@EXEEXT@ ${DESTDIR}${sbindir}
|
|
|
bc5dde |
${INSTALL_DATA} ${srcdir}/zone2ldap.1 ${DESTDIR}${mandir}/man1/zone2ldap.1
|
|
|
3ce7d3 |
diff --git a/bin/sdb_tools/zone2ldap.c b/bin/sdb_tools/zone2ldap.c
|
|
|
3ce7d3 |
index 23dd873..d56bc56 100644
|
|
|
3ce7d3 |
--- a/bin/sdb_tools/zone2ldap.c
|
|
|
3ce7d3 |
+++ b/bin/sdb_tools/zone2ldap.c
|
|
|
3ce7d3 |
@@ -65,6 +66,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 |
|
|
|
3ce7d3 |
@@ -81,7 +85,7 @@ char **hostname_to_dn_list (char *hostname, char *zone, unsigned int flags);
|
|
|
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,
|
|
|
3ce7d3 |
@@ -103,11 +107,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 |
|
|
|
3ce7d3 |
@@ -131,12 +151,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;
|
|
|
3ce7d3 |
@@ -149,7 +169,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 |
|
|
|
3ce7d3 |
if (argc < 2)
|
|
|
bc5dde |
{
|
|
|
3ce7d3 |
@@ -157,7 +177,7 @@ main (int argc, char **argv)
|
|
|
bc5dde |
exit (-1);
|
|
|
bc5dde |
}
|
|
|
bc5dde |
|
|
|
3ce7d3 |
- while ((topt = getopt (argc, argv, "D:w:b:z:f:h:?dcv")) != -1)
|
|
|
3ce7d3 |
+ while ((topt = getopt (argc, argv, "D:Ww:b:z:f:h:?dcv")) != -1)
|
|
|
bc5dde |
{
|
|
|
bc5dde |
switch (topt)
|
|
|
bc5dde |
{
|
|
|
3ce7d3 |
@@ -180,6 +200,9 @@ main (int argc, char **argv)
|
|
|
3ce7d3 |
if (bindpw == NULL)
|
|
|
3ce7d3 |
fatal("strdup");
|
|
|
bc5dde |
break;
|
|
|
bc5dde |
+ case 'W':
|
|
|
bc5dde |
+ bindpw = getpass("Enter LDAP Password: ");
|
|
|
bc5dde |
+ break;
|
|
|
bc5dde |
case 'b':
|
|
|
3ce7d3 |
ldapbase = strdup (optarg);
|
|
|
3ce7d3 |
if (ldapbase == NULL)
|
|
|
3ce7d3 |
@@ -301,27 +324,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 |
{
|
|
|
3ce7d3 |
@@ -330,8 +388,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 |
}
|
|
|
3ce7d3 |
@@ -409,14 +472,14 @@ generate_ldap (dns_name_t * dnsname, dns_rdata_t * rdata, unsigned int ttl)
|
|
|
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 |
|
|
|
3ce7d3 |
@@ -456,7 +519,8 @@ add_to_rr_list (char *dn, char *name, char *type,
|
|
|
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 |
{
|
|
|
3ce7d3 |
@@ -483,13 +547,13 @@ add_to_rr_list (char *dn, char *name, char *type,
|
|
|
3ce7d3 |
fatal("malloc");
|
|
|
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;
|
|
|
3ce7d3 |
@@ -498,7 +562,7 @@ add_to_rr_list (char *dn, char *name, char *type,
|
|
|
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)
|
|
|
3ce7d3 |
@@ -527,7 +591,7 @@ add_to_rr_list (char *dn, char *name, char *type,
|
|
|
3ce7d3 |
fatal("strdup");
|
|
|
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)
|
|
|
3ce7d3 |
@@ -540,14 +604,25 @@ add_to_rr_list (char *dn, char *name, char *type,
|
|
|
3ce7d3 |
if (tmp->attrs[3]->mod_values[0] == NULL)
|
|
|
3ce7d3 |
fatal("strdup");
|
|
|
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);
|
|
|
3ce7d3 |
|
|
|
3ce7d3 |
if (tmp->attrs[4]->mod_values == (char **)NULL)
|
|
|
3ce7d3 |
fatal("calloc");
|
|
|
3ce7d3 |
|
|
|
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;
|
|
|
3ce7d3 |
@@ -558,7 +633,7 @@ add_to_rr_list (char *dn, char *name, char *type,
|
|
|
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
|
|
|
3ce7d3 |
@@ -632,44 +707,70 @@ 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);
|
|
|
3ce7d3 |
- if (zname == NULL)
|
|
|
3ce7d3 |
- fatal("strdup");
|
|
|
bc5dde |
-
|
|
|
bc5dde |
- if (flags == DNS_OBJECT)
|
|
|
bc5dde |
- {
|
|
|
3ce7d3 |
-
|
|
|
bc5dde |
- if (strlen (zname) != strlen (zone))
|
|
|
bc5dde |
- {
|
|
|
bc5dde |
- tmp = &zname[strlen (zname) - strlen (zone)];
|
|
|
bc5dde |
- *--tmp = '\0';
|
|
|
bc5dde |
- hnamebuff = strdup (zname);
|
|
|
3ce7d3 |
- if (hnamebuff == NULL)
|
|
|
3ce7d3 |
- fatal("strdup");
|
|
|
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;
|
|
|
3ce7d3 |
+ char *hname=0L, *last=0L;
|
|
|
3ce7d3 |
+ int hlen=strlen(hostname), zlen=(strlen(zone));
|
|
|
3ce7d3 |
+
|
|
|
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 |
|
|
|
3ce7d3 |
return dn_buffer;
|
|
|
3ce7d3 |
@@ -681,24 +782,32 @@ hostname_to_dn_list (char *hostname, char *zone, unsigned int flags)
|
|
|
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 |
}
|
|
|
3ce7d3 |
@@ -724,6 +833,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 |
{
|
|
|
3ce7d3 |
@@ -733,7 +843,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 */
|
|
|
3ce7d3 |
@@ -750,8 +860,6 @@ ldap_result_check (const char *msg, char *dn, int err)
|
|
|
bc5dde |
}
|
|
|
bc5dde |
}
|
|
|
bc5dde |
|
|
|
bc5dde |
-
|
|
|
bc5dde |
-
|
|
|
bc5dde |
/* For running the ldap_info run queue. */
|
|
|
bc5dde |
void
|
|
|
bc5dde |
add_ldap_values (ldap_info * ldinfo)
|
|
|
3ce7d3 |
@@ -759,14 +867,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 |
|
|
|
3ce7d3 |
@@ -777,5 +885,5 @@ void
|
|
|
bc5dde |
usage ()
|
|
|
bc5dde |
{
|
|
|
bc5dde |
fprintf (stderr,
|
|
|
3ce7d3 |
- "zone2ldap -D [BIND DN] -w [BIND PASSWORD] -b [BASE DN] -z [ZONE] -f [ZONE FILE] -h [LDAP HOST] "
|
|
|
3ce7d3 |
+ "zone2ldap -D [BIND DN] [-w BIND PASSWORD | -W:prompt] -b [BASE DN] -z [ZONE] -f [ZONE FILE] -h [LDAP HOST] "
|
|
|
3ce7d3 |
"[-c Create LDAP Base structure][-d Debug Output (lots !)] \n ");}
|