|
|
e55890 |
diff --git a/bin/sdb_tools/Makefile.in b/bin/sdb_tools/Makefile.in
|
|
|
b9f8ff |
index 95ab742..5059a17 100644
|
|
|
e55890 |
--- a/bin/sdb_tools/Makefile.in
|
|
|
e55890 |
+++ b/bin/sdb_tools/Makefile.in
|
|
|
e55890 |
@@ -32,11 +32,11 @@ DEPLIBS = ${LWRESDEPLIBS} ${DNSDEPLIBS} ${BIND9DEPLIBS} \
|
|
|
e55890 |
LIBS = ${LWRESLIBS} ${DNSLIBS} ${BIND9LIBS} \
|
|
|
e55890 |
${ISCCFGLIBS} ${ISCCCLIBS} ${ISCLIBS} ${DBDRIVER_LIBS} @LIBS@
|
|
|
e55890 |
|
|
|
e55890 |
-TARGETS = zone2ldap@EXEEXT@ zonetodb@EXEEXT@ zone2sqlite@EXEEXT@
|
|
|
b9f8ff |
+TARGETS = zone2ldap@EXEEXT@ zonetodb@EXEEXT@ zone2sqlite@EXEEXT@ ldap2zone@EXEEXT@
|
|
|
e55890 |
|
|
|
e55890 |
-OBJS = zone2ldap.@O@ zonetodb.@O@ zone2sqlite.@O@
|
|
|
b9f8ff |
+OBJS = zone2ldap.@O@ zonetodb.@O@ zone2sqlite.@O@ ldap2zone.@O@
|
|
|
e55890 |
|
|
|
e55890 |
-SRCS = zone2ldap.c zonetodb.c zone2sqlite.c
|
|
|
b9f8ff |
+SRCS = zone2ldap.c zonetodb.c zone2sqlite.c ldap2zone.c
|
|
|
e55890 |
|
|
|
e55890 |
MANPAGES = zone2ldap.1
|
|
|
e55890 |
|
|
|
b9f8ff |
@@ -47,6 +47,9 @@ EXT_CFLAGS =
|
|
|
b9f8ff |
zone2ldap@EXEEXT@: zone2ldap.@O@ ${DEPLIBS}
|
|
|
b9f8ff |
${LIBTOOL_MODE_LINK} ${PURIFY} ${CC} ${CFLAGS} ${LDFLAGS} -o $@ zone2ldap.@O@ -lldap -llber ${LIBS}
|
|
|
e55890 |
|
|
|
e55890 |
+ldap2zone@EXEEXT@: ldap2zone.@O@ ${DEPLIBS}
|
|
|
e55890 |
+ ${LIBTOOL_MODE_LINK} ${PURIFY} ${CC} ${ALL_CFLAGS} ${LDFLAGS} -o $@ ldap2zone.@O@ -lldap -llber ${LIBS}
|
|
|
e55890 |
+
|
|
|
b9f8ff |
zonetodb@EXEEXT@: zonetodb.@O@ ${DEPLIBS}
|
|
|
b9f8ff |
${LIBTOOL_MODE_LINK} ${PURIFY} ${CC} ${CFLAGS} ${LDFLAGS} -o $@ zonetodb.@O@ -lpq ${LIBS}
|
|
|
e55890 |
|
|
|
b9f8ff |
@@ -64,4 +67,5 @@ install:: ${TARGETS} installdirs
|
|
|
e55890 |
${LIBTOOL_MODE_INSTALL} ${INSTALL_PROGRAM} zone2ldap@EXEEXT@ ${DESTDIR}${sbindir}
|
|
|
e55890 |
${LIBTOOL_MODE_INSTALL} ${INSTALL_PROGRAM} zonetodb@EXEEXT@ ${DESTDIR}${sbindir}
|
|
|
e55890 |
${LIBTOOL_MODE_INSTALL} ${INSTALL_PROGRAM} zone2sqlite@EXEEXT@ ${DESTDIR}${sbindir}
|
|
|
b9f8ff |
+ ${LIBTOOL_MODE_INSTALL} ${INSTALL_PROGRAM} ldap2zone@EXEEXT@ ${DESTDIR}${sbindir}
|
|
|
e55890 |
${INSTALL_DATA} ${srcdir}/zone2ldap.1 ${DESTDIR}${mandir}/man1/zone2ldap.1
|
|
|
e55890 |
diff --git a/bin/sdb_tools/zone2ldap.c b/bin/sdb_tools/zone2ldap.c
|
|
|
b9f8ff |
index e0e9207..d59936c 100644
|
|
|
e55890 |
--- a/bin/sdb_tools/zone2ldap.c
|
|
|
e55890 |
+++ b/bin/sdb_tools/zone2ldap.c
|
|
|
b9f8ff |
@@ -73,7 +73,7 @@ void add_ldap_values (ldap_info * ldinfo);
|
|
|
b9f8ff |
void init_ldap_conn (void);
|
|
|
e55890 |
|
|
|
b9f8ff |
/* Ldap error checking */
|
|
|
b9f8ff |
-void ldap_result_check (const char *msg, char *dn, int err);
|
|
|
b9f8ff |
+void ldap_result_check (const char *msg, const char *dn, int err);
|
|
|
e55890 |
|
|
|
b9f8ff |
/* Put a hostname into a char ** array */
|
|
|
b9f8ff |
char **hostname_to_dn_list (char *hostname, char *zone, unsigned int flags);
|
|
|
b9f8ff |
@@ -82,7 +82,7 @@ char **hostname_to_dn_list (char *hostname, char *zone, unsigned int flags);
|
|
|
e55890 |
int get_attr_list_size (char **tmp);
|
|
|
e55890 |
|
|
|
e55890 |
/* Get a DN */
|
|
|
e55890 |
-char *build_dn_from_dc_list (char **dc_list, unsigned int ttl, int flag);
|
|
|
e55890 |
+char *build_dn_from_dc_list (char **dc_list, unsigned int ttl, int flag, char *zone);
|
|
|
e55890 |
|
|
|
e55890 |
/* Add to RR list */
|
|
|
e55890 |
void add_to_rr_list (char *dn, char *name, char *type, char *data,
|
|
|
b9f8ff |
@@ -104,11 +104,26 @@ void
|
|
|
e55890 |
init_ldap_conn ();
|
|
|
e55890 |
void usage();
|
|
|
e55890 |
|
|
|
e55890 |
-char *argzone, *ldapbase, *binddn, *bindpw = NULL;
|
|
|
e55890 |
-const char *ldapsystem = "localhost";
|
|
|
e55890 |
-static const char *objectClasses[] =
|
|
|
e55890 |
- { "top", "dNSZone", NULL };
|
|
|
e55890 |
-static const char *topObjectClasses[] = { "top", NULL };
|
|
|
e55890 |
+static char *argzone, *ldapbase, *binddn, *bindpw = NULL;
|
|
|
e55890 |
+
|
|
|
e55890 |
+/* these are needed to placate gcc4's const-ness const-ernations : */
|
|
|
e55890 |
+static char localhost[] = "localhost";
|
|
|
e55890 |
+static char *ldapsystem=&(localhost[0]);
|
|
|
e55890 |
+/* dnszone schema class names: */
|
|
|
e55890 |
+static char topClass [] ="top";
|
|
|
e55890 |
+static char dNSZoneClass[] ="dNSZone";
|
|
|
e55890 |
+static char objectClass [] ="objectClass";
|
|
|
e55890 |
+static char dcObjectClass[]="dcObject";
|
|
|
e55890 |
+/* dnszone schema attribute names: */
|
|
|
e55890 |
+static char relativeDomainName[]="relativeDomainName";
|
|
|
e55890 |
+static char dNSTTL []="dNSTTL";
|
|
|
e55890 |
+static char zoneName []="zoneName";
|
|
|
e55890 |
+static char dc []="dc";
|
|
|
e55890 |
+static char sameZone []="@";
|
|
|
e55890 |
+/* LDAPMod mod_values: */
|
|
|
e55890 |
+static char *objectClasses []= { &(topClass[0]), &(dNSZoneClass[0]), NULL };
|
|
|
e55890 |
+static char *topObjectClasses []= { &(topClass[0]), &(dcObjectClass[0]), &(dNSZoneClass[0]), NULL };
|
|
|
e55890 |
+static char *dn_buffer [64]={NULL};
|
|
|
e55890 |
LDAP *conn;
|
|
|
e55890 |
unsigned int debug = 0;
|
|
|
e55890 |
|
|
|
b9f8ff |
@@ -120,7 +135,7 @@ static void
|
|
|
b9f8ff |
fatal(const char *msg) {
|
|
|
b9f8ff |
perror(msg);
|
|
|
b9f8ff |
if (conn != NULL)
|
|
|
b9f8ff |
- ldap_unbind_s(conn);
|
|
|
b9f8ff |
+ ldap_unbind_ext_s(conn, NULL, NULL);
|
|
|
b9f8ff |
exit(1);
|
|
|
b9f8ff |
}
|
|
|
b9f8ff |
|
|
|
b9f8ff |
@@ -132,12 +147,13 @@ main (int argc, char **argv)
|
|
|
e55890 |
isc_result_t result;
|
|
|
e55890 |
char *basedn;
|
|
|
e55890 |
ldap_info *tmp;
|
|
|
e55890 |
- LDAPMod *base_attrs[2];
|
|
|
e55890 |
- LDAPMod base;
|
|
|
e55890 |
+ LDAPMod *base_attrs[5];
|
|
|
e55890 |
+ LDAPMod base, dcBase, znBase, rdnBase;
|
|
|
e55890 |
isc_buffer_t buff;
|
|
|
e55890 |
char *zonefile=0L;
|
|
|
e55890 |
char fullbasedn[1024];
|
|
|
b9f8ff |
char *ctmp;
|
|
|
b9f8ff |
+ char *zn, *dcp[2], *znp[2], *rdn[2];
|
|
|
e55890 |
dns_fixedname_t fixedzone, fixedname;
|
|
|
e55890 |
dns_rdataset_t rdataset;
|
|
|
e55890 |
char **dc_list;
|
|
|
b9f8ff |
@@ -150,7 +166,7 @@ main (int argc, char **argv)
|
|
|
e55890 |
extern char *optarg;
|
|
|
e55890 |
extern int optind, opterr, optopt;
|
|
|
e55890 |
int create_base = 0;
|
|
|
e55890 |
- int topt;
|
|
|
e55890 |
+ int topt, dcn, zdn, znlen;
|
|
|
e55890 |
|
|
|
e55890 |
if (argc < 2)
|
|
|
e55890 |
{
|
|
|
b9f8ff |
@@ -158,7 +174,7 @@ main (int argc, char **argv)
|
|
|
e55890 |
exit (-1);
|
|
|
e55890 |
}
|
|
|
e55890 |
|
|
|
e55890 |
- while ((topt = getopt (argc, argv, "D:w:b:z:f:h:?dcv")) != -1)
|
|
|
e55890 |
+ while ((topt = getopt (argc, argv, "D:Ww:b:z:f:h:?dcv")) != -1)
|
|
|
e55890 |
{
|
|
|
e55890 |
switch (topt)
|
|
|
e55890 |
{
|
|
|
b9f8ff |
@@ -181,6 +197,9 @@ main (int argc, char **argv)
|
|
|
e55890 |
if (bindpw == NULL)
|
|
|
e55890 |
fatal("strdup");
|
|
|
e55890 |
break;
|
|
|
e55890 |
+ case 'W':
|
|
|
e55890 |
+ bindpw = getpass("Enter LDAP Password: ");
|
|
|
e55890 |
+ break;
|
|
|
e55890 |
case 'b':
|
|
|
e55890 |
ldapbase = strdup (optarg);
|
|
|
e55890 |
if (ldapbase == NULL)
|
|
|
b9f8ff |
@@ -302,17 +321,51 @@ main (int argc, char **argv)
|
|
|
e55890 |
printf ("Creating base zone DN %s\n", argzone);
|
|
|
b9f8ff |
|
|
|
e55890 |
dc_list = hostname_to_dn_list (argzone, argzone, DNS_TOP);
|
|
|
e55890 |
- basedn = build_dn_from_dc_list (dc_list, 0, NO_SPEC);
|
|
|
e55890 |
+ basedn = build_dn_from_dc_list (dc_list, 0, NO_SPEC, argzone);
|
|
|
e55890 |
+ if (debug)
|
|
|
e55890 |
+ printf ("base DN %s\n", basedn);
|
|
|
b9f8ff |
|
|
|
b9f8ff |
- for (ctmp = &basedn[strlen (basedn)]; ctmp >= &basedn[0]; ctmp--)
|
|
|
e55890 |
+ for (ctmp = &basedn[strlen (basedn)], dcn=0; ctmp >= &basedn[0]; ctmp--)
|
|
|
e55890 |
{
|
|
|
b9f8ff |
if ((*ctmp == ',') || (ctmp == &basedn[0]))
|
|
|
e55890 |
{
|
|
|
e55890 |
base.mod_op = LDAP_MOD_ADD;
|
|
|
e55890 |
- base.mod_type = (char*)"objectClass";
|
|
|
e55890 |
+ base.mod_type = objectClass;
|
|
|
b9f8ff |
base.mod_values = (char**)topObjectClasses;
|
|
|
e55890 |
base_attrs[0] = (void*)&bas;;
|
|
|
e55890 |
- base_attrs[1] = NULL;
|
|
|
b9f8ff |
+
|
|
|
e55890 |
+ dcBase.mod_op = LDAP_MOD_ADD;
|
|
|
e55890 |
+ dcBase.mod_type = dc;
|
|
|
e55890 |
+ dcp[0]=dc_list[dcn];
|
|
|
e55890 |
+ dcp[1]=0L;
|
|
|
e55890 |
+ dcBase.mod_values=dcp;
|
|
|
e55890 |
+ base_attrs[1] = (void*)&dcBase;
|
|
|
e55890 |
+
|
|
|
e55890 |
+ znBase.mod_op = LDAP_MOD_ADD;
|
|
|
b9f8ff |
+ znBase.mod_type = zoneName;
|
|
|
e55890 |
+ for( zdn = dcn, znlen = 0; zdn >= 0; zdn-- )
|
|
|
e55890 |
+ znlen += strlen(dc_list[zdn])+1;
|
|
|
e55890 |
+ znp[0] = (char*)malloc(znlen+1);
|
|
|
e55890 |
+ znp[1] = 0L;
|
|
|
b9f8ff |
+ for( zdn = dcn, zn=znp[0]; zdn >= 0; zdn-- )
|
|
|
b9f8ff |
+ zn+=sprintf(zn,"%s%s",dc_list[zdn],
|
|
|
e55890 |
+ ((zdn > 0) && (*(dc_list[zdn-1])!='.')) ? "." : ""
|
|
|
e55890 |
+ );
|
|
|
e55890 |
+
|
|
|
e55890 |
+ znBase.mod_values = znp;
|
|
|
e55890 |
+ base_attrs[2] = (void*)&znBase;
|
|
|
e55890 |
+
|
|
|
e55890 |
+ rdnBase.mod_op = LDAP_MOD_ADD;
|
|
|
e55890 |
+ rdnBase.mod_type = relativeDomainName;
|
|
|
e55890 |
+ rdn[0] = strdup(sameZone);
|
|
|
e55890 |
+ rdn[1] = 0L;
|
|
|
e55890 |
+ rdnBase.mod_values = rdn;
|
|
|
e55890 |
+ base_attrs[3] = (void*)&rdnBase;
|
|
|
b9f8ff |
+
|
|
|
e55890 |
+ dcn++;
|
|
|
e55890 |
+
|
|
|
e55890 |
+ base.mod_values = topObjectClasses;
|
|
|
b9f8ff |
+ base_attrs[4] = NULL;
|
|
|
b9f8ff |
|
|
|
e55890 |
if (ldapbase)
|
|
|
e55890 |
{
|
|
|
b9f8ff |
@@ -329,6 +382,10 @@ main (int argc, char **argv)
|
|
|
e55890 |
else
|
|
|
e55890 |
sprintf (fullbasedn, "%s", ctmp);
|
|
|
e55890 |
}
|
|
|
e55890 |
+
|
|
|
e55890 |
+ if( debug )
|
|
|
e55890 |
+ printf("Full base dn: %s\n", fullbasedn);
|
|
|
e55890 |
+
|
|
|
e55890 |
result = ldap_add_s (conn, fullbasedn, base_attrs);
|
|
|
b9f8ff |
ldap_result_check ("initial ldap_add_s", fullbasedn, result);
|
|
|
e55890 |
}
|
|
|
b9f8ff |
@@ -408,14 +465,14 @@ generate_ldap (dns_name_t * dnsname, dns_rdata_t * rdata, unsigned int ttl)
|
|
|
e55890 |
isc_result_check (result, "dns_rdata_totext");
|
|
|
e55890 |
data[isc_buffer_usedlength (&buff)] = 0;
|
|
|
e55890 |
|
|
|
e55890 |
- dc_list = hostname_to_dn_list (name, argzone, DNS_OBJECT);
|
|
|
e55890 |
+ dc_list = hostname_to_dn_list ((char*)name, argzone, DNS_OBJECT);
|
|
|
e55890 |
len = (get_attr_list_size (dc_list) - 2);
|
|
|
e55890 |
- dn = build_dn_from_dc_list (dc_list, ttl, WI_SPEC);
|
|
|
e55890 |
+ dn = build_dn_from_dc_list (dc_list, ttl, WI_SPEC, argzone);
|
|
|
e55890 |
|
|
|
e55890 |
if (debug)
|
|
|
e55890 |
printf ("Adding %s (%s %s) to run queue list.\n", dn, type, data);
|
|
|
e55890 |
|
|
|
e55890 |
- add_to_rr_list (dn, dc_list[len], type, data, ttl, DNS_OBJECT);
|
|
|
e55890 |
+ add_to_rr_list (dn, dc_list[len], (char*)type, (char*)data, ttl, DNS_OBJECT);
|
|
|
e55890 |
}
|
|
|
e55890 |
|
|
|
e55890 |
|
|
|
b9f8ff |
@@ -455,7 +512,8 @@ add_to_rr_list (char *dn, char *name, char *type,
|
|
|
e55890 |
int attrlist;
|
|
|
e55890 |
char ldap_type_buffer[128];
|
|
|
e55890 |
char charttl[64];
|
|
|
e55890 |
-
|
|
|
e55890 |
+ char *zn;
|
|
|
e55890 |
+ int znlen;
|
|
|
e55890 |
|
|
|
e55890 |
if ((tmp = locate_by_dn (dn)) == NULL)
|
|
|
e55890 |
{
|
|
|
b9f8ff |
@@ -482,10 +540,10 @@ add_to_rr_list (char *dn, char *name, char *type,
|
|
|
e55890 |
fatal("malloc");
|
|
|
e55890 |
}
|
|
|
e55890 |
tmp->attrs[0]->mod_op = LDAP_MOD_ADD;
|
|
|
e55890 |
- tmp->attrs[0]->mod_type = (char*)"objectClass";
|
|
|
e55890 |
+ tmp->attrs[0]->mod_type = objectClass;
|
|
|
e55890 |
|
|
|
e55890 |
if (flags == DNS_OBJECT)
|
|
|
e55890 |
- tmp->attrs[0]->mod_values = (char**)objectClasses;
|
|
|
e55890 |
+ tmp->attrs[0]->mod_values = objectClasses;
|
|
|
e55890 |
else
|
|
|
e55890 |
{
|
|
|
b9f8ff |
tmp->attrs[0]->mod_values = (char**)topObjectClasses;
|
|
|
b9f8ff |
@@ -497,7 +555,7 @@ add_to_rr_list (char *dn, char *name, char *type,
|
|
|
e55890 |
}
|
|
|
e55890 |
|
|
|
e55890 |
tmp->attrs[1]->mod_op = LDAP_MOD_ADD;
|
|
|
e55890 |
- tmp->attrs[1]->mod_type = (char*)"relativeDomainName";
|
|
|
e55890 |
+ tmp->attrs[1]->mod_type = relativeDomainName;
|
|
|
e55890 |
tmp->attrs[1]->mod_values = (char **) calloc (sizeof (char *), 2);
|
|
|
e55890 |
|
|
|
e55890 |
if (tmp->attrs[1]->mod_values == (char **)NULL)
|
|
|
b9f8ff |
@@ -526,7 +584,7 @@ add_to_rr_list (char *dn, char *name, char *type,
|
|
|
e55890 |
fatal("strdup");
|
|
|
e55890 |
|
|
|
e55890 |
tmp->attrs[3]->mod_op = LDAP_MOD_ADD;
|
|
|
e55890 |
- tmp->attrs[3]->mod_type = (char*)"dNSTTL";
|
|
|
e55890 |
+ tmp->attrs[3]->mod_type = dNSTTL;
|
|
|
e55890 |
tmp->attrs[3]->mod_values = (char **) calloc (sizeof (char *), 2);
|
|
|
e55890 |
|
|
|
e55890 |
if (tmp->attrs[3]->mod_values == (char **)NULL)
|
|
|
b9f8ff |
@@ -539,14 +597,25 @@ add_to_rr_list (char *dn, char *name, char *type,
|
|
|
e55890 |
if (tmp->attrs[3]->mod_values[0] == NULL)
|
|
|
e55890 |
fatal("strdup");
|
|
|
e55890 |
|
|
|
b9f8ff |
+ znlen=strlen(gbl_zone);
|
|
|
b9f8ff |
+ if ( gbl_zone[znlen-1] == '.' )
|
|
|
e55890 |
+ { /* ldapdb MUST search by relative zone name */
|
|
|
e55890 |
+ zn = (char*)malloc(znlen);
|
|
|
b9f8ff |
+ memcpy(zn, gbl_zone, znlen-1);
|
|
|
b9f8ff |
+ zn[znlen-1]='\0';
|
|
|
e55890 |
+ }else
|
|
|
e55890 |
+ {
|
|
|
e55890 |
+ zn = gbl_zone;
|
|
|
e55890 |
+ }
|
|
|
e55890 |
+
|
|
|
e55890 |
tmp->attrs[4]->mod_op = LDAP_MOD_ADD;
|
|
|
e55890 |
- tmp->attrs[4]->mod_type = (char*)"zoneName";
|
|
|
e55890 |
+ tmp->attrs[4]->mod_type = zoneName;
|
|
|
e55890 |
tmp->attrs[4]->mod_values = (char **)calloc(sizeof(char *), 2);
|
|
|
e55890 |
|
|
|
e55890 |
if (tmp->attrs[4]->mod_values == (char **)NULL)
|
|
|
e55890 |
fatal("calloc");
|
|
|
e55890 |
|
|
|
e55890 |
- tmp->attrs[4]->mod_values[0] = gbl_zone;
|
|
|
e55890 |
+ tmp->attrs[4]->mod_values[0] = zn;
|
|
|
e55890 |
tmp->attrs[4]->mod_values[1] = NULL;
|
|
|
e55890 |
|
|
|
e55890 |
tmp->attrs[5] = NULL;
|
|
|
b9f8ff |
@@ -557,7 +626,7 @@ add_to_rr_list (char *dn, char *name, char *type,
|
|
|
e55890 |
else
|
|
|
e55890 |
{
|
|
|
e55890 |
|
|
|
e55890 |
- for (i = 0; tmp->attrs[i] != NULL; i++)
|
|
|
e55890 |
+ for (i = 0; tmp->attrs[i] != NULL; i++)
|
|
|
e55890 |
{
|
|
|
e55890 |
sprintf (ldap_type_buffer, "%sRecord", type);
|
|
|
e55890 |
if (!strncmp
|
|
|
b9f8ff |
@@ -631,44 +700,70 @@ char **
|
|
|
e55890 |
hostname_to_dn_list (char *hostname, char *zone, unsigned int flags)
|
|
|
e55890 |
{
|
|
|
e55890 |
char *tmp;
|
|
|
e55890 |
- static char *dn_buffer[64];
|
|
|
e55890 |
int i = 0;
|
|
|
e55890 |
- char *zname;
|
|
|
e55890 |
- char *hnamebuff;
|
|
|
e55890 |
-
|
|
|
e55890 |
- zname = strdup (hostname);
|
|
|
e55890 |
- if (zname == NULL)
|
|
|
e55890 |
- fatal("strdup");
|
|
|
e55890 |
-
|
|
|
e55890 |
- if (flags == DNS_OBJECT)
|
|
|
e55890 |
- {
|
|
|
e55890 |
-
|
|
|
e55890 |
- if (strlen (zname) != strlen (zone))
|
|
|
e55890 |
- {
|
|
|
e55890 |
- tmp = &zname[strlen (zname) - strlen (zone)];
|
|
|
e55890 |
- *--tmp = '\0';
|
|
|
e55890 |
- hnamebuff = strdup (zname);
|
|
|
e55890 |
- if (hnamebuff == NULL)
|
|
|
e55890 |
- fatal("strdup");
|
|
|
e55890 |
- zname = ++tmp;
|
|
|
e55890 |
- }
|
|
|
e55890 |
- else
|
|
|
e55890 |
- hnamebuff = (char*)"@";
|
|
|
e55890 |
- }
|
|
|
e55890 |
- else
|
|
|
e55890 |
- {
|
|
|
e55890 |
- zname = zone;
|
|
|
e55890 |
- hnamebuff = NULL;
|
|
|
e55890 |
- }
|
|
|
e55890 |
-
|
|
|
e55890 |
- for (tmp = strrchr (zname, '.'); tmp != (char *) 0;
|
|
|
e55890 |
- tmp = strrchr (zname, '.'))
|
|
|
e55890 |
- {
|
|
|
e55890 |
- *tmp++ = '\0';
|
|
|
e55890 |
- dn_buffer[i++] = tmp;
|
|
|
e55890 |
- }
|
|
|
e55890 |
- dn_buffer[i++] = zname;
|
|
|
e55890 |
- dn_buffer[i++] = hnamebuff;
|
|
|
e55890 |
+ char *hname=0L, *last=0L;
|
|
|
e55890 |
+ int hlen=strlen(hostname), zlen=(strlen(zone));
|
|
|
e55890 |
+
|
|
|
e55890 |
+/* printf("hostname: %s zone: %s\n",hostname, zone); */
|
|
|
e55890 |
+ hname=0L;
|
|
|
e55890 |
+ if(flags == DNS_OBJECT)
|
|
|
e55890 |
+ {
|
|
|
e55890 |
+ if( (zone[ zlen - 1 ] == '.') && (hostname[hlen - 1] != '.') )
|
|
|
e55890 |
+ {
|
|
|
e55890 |
+ hname=(char*)malloc(hlen + 1);
|
|
|
e55890 |
+ hlen += 1;
|
|
|
e55890 |
+ sprintf(hname, "%s.", hostname);
|
|
|
e55890 |
+ hostname = hname;
|
|
|
e55890 |
+ }
|
|
|
e55890 |
+ if(strcmp(hostname, zone) == 0)
|
|
|
e55890 |
+ {
|
|
|
e55890 |
+ if( hname == 0 )
|
|
|
e55890 |
+ hname=strdup(hostname);
|
|
|
b9f8ff |
+ last = strdup(sameZone);
|
|
|
e55890 |
+ }else
|
|
|
b9f8ff |
+ {
|
|
|
b9f8ff |
+ if( (hlen < zlen)
|
|
|
e55890 |
+ ||( strcmp( hostname + (hlen - zlen), zone ) != 0)
|
|
|
e55890 |
+ )
|
|
|
e55890 |
+ {
|
|
|
e55890 |
+ if( hname != 0 )
|
|
|
e55890 |
+ free(hname);
|
|
|
e55890 |
+ hname=(char*)malloc( hlen + zlen + 1);
|
|
|
e55890 |
+ if( *zone == '.' )
|
|
|
e55890 |
+ sprintf(hname, "%s%s", hostname, zone);
|
|
|
e55890 |
+ else
|
|
|
e55890 |
+ sprintf(hname,"%s",zone);
|
|
|
e55890 |
+ }else
|
|
|
e55890 |
+ {
|
|
|
e55890 |
+ if( hname == 0 )
|
|
|
e55890 |
+ hname = strdup(hostname);
|
|
|
e55890 |
+ }
|
|
|
e55890 |
+ last = hname;
|
|
|
e55890 |
+ }
|
|
|
e55890 |
+ }else
|
|
|
e55890 |
+ { /* flags == DNS_TOP */
|
|
|
e55890 |
+ hname = strdup(zone);
|
|
|
e55890 |
+ last = hname;
|
|
|
e55890 |
+ }
|
|
|
e55890 |
+
|
|
|
e55890 |
+ for (tmp = strrchr (hname, '.'); tmp != (char *) 0;
|
|
|
e55890 |
+ tmp = strrchr (hname, '.'))
|
|
|
e55890 |
+ {
|
|
|
e55890 |
+ if( *( tmp + 1 ) != '\0' )
|
|
|
e55890 |
+ {
|
|
|
e55890 |
+ *tmp = '\0';
|
|
|
e55890 |
+ dn_buffer[i++] = ++tmp;
|
|
|
e55890 |
+ }else
|
|
|
e55890 |
+ { /* trailing '.' ! */
|
|
|
e55890 |
+ dn_buffer[i++] = strdup(".");
|
|
|
e55890 |
+ *tmp = '\0';
|
|
|
e55890 |
+ if( tmp == hname )
|
|
|
e55890 |
+ break;
|
|
|
b9f8ff |
+ }
|
|
|
e55890 |
+ }
|
|
|
e55890 |
+ if( ( last != hname ) && (tmp != hname) )
|
|
|
e55890 |
+ dn_buffer[i++] = hname;
|
|
|
e55890 |
+ dn_buffer[i++] = last;
|
|
|
e55890 |
dn_buffer[i] = NULL;
|
|
|
e55890 |
|
|
|
e55890 |
return dn_buffer;
|
|
|
b9f8ff |
@@ -680,30 +775,38 @@ hostname_to_dn_list (char *hostname, char *zone, unsigned int flags)
|
|
|
e55890 |
* exception of "@"/SOA. */
|
|
|
e55890 |
|
|
|
e55890 |
char *
|
|
|
e55890 |
-build_dn_from_dc_list (char **dc_list, unsigned int ttl, int flag)
|
|
|
e55890 |
+build_dn_from_dc_list (char **dc_list, unsigned int ttl, int flag, char *zone)
|
|
|
e55890 |
{
|
|
|
e55890 |
int size;
|
|
|
e55890 |
- int x;
|
|
|
b9f8ff |
- static char dn[1024];
|
|
|
b9f8ff |
- char tmp[128];
|
|
|
e55890 |
+ int x, znlen;
|
|
|
b9f8ff |
+ static char dn[DNS_NAME_MAXTEXT*3/2];
|
|
|
b9f8ff |
+ char tmp[DNS_NAME_MAXTEXT*3/2];
|
|
|
e55890 |
+ char zn[DNS_NAME_MAXTEXT+1];
|
|
|
e55890 |
|
|
|
e55890 |
bzero (tmp, sizeof (tmp));
|
|
|
e55890 |
bzero (dn, sizeof (dn));
|
|
|
e55890 |
size = get_attr_list_size (dc_list);
|
|
|
e55890 |
+ znlen = strlen(zone);
|
|
|
b9f8ff |
+ if ( zone[znlen-1] == '.' )
|
|
|
e55890 |
+ { /* ldapdb MUST search by relative zone name */
|
|
|
e55890 |
+ memcpy(&(zn[0]),zone,znlen-1);
|
|
|
b9f8ff |
+ zn[znlen-1]='\0';
|
|
|
e55890 |
+ zone = zn;
|
|
|
e55890 |
+ }
|
|
|
e55890 |
for (x = size - 2; x > 0; x--)
|
|
|
e55890 |
{
|
|
|
e55890 |
if (flag == WI_SPEC)
|
|
|
e55890 |
{
|
|
|
e55890 |
if (x == (size - 2) && (strncmp (dc_list[x], "@", 1) == 0) && (ttl))
|
|
|
27025e |
- sprintf (tmp, "relativeDomainName=%s + dNSTTL=%u,", dc_list[x], ttl);
|
|
|
b9f8ff |
+ snprintf (tmp, sizeof(tmp), "zoneName=%s + relativeDomainName=%s,", zone, dc_list[x]);
|
|
|
e55890 |
else if (x == (size - 2))
|
|
|
e55890 |
- sprintf(tmp, "relativeDomainName=%s,",dc_list[x]);
|
|
|
b9f8ff |
+ snprintf(tmp, sizeof(tmp), "zoneName=%s + relativeDomainName=%s,", zone, dc_list[x]);
|
|
|
e55890 |
else
|
|
|
b9f8ff |
- sprintf(tmp,"dc=%s,", dc_list[x]);
|
|
|
b9f8ff |
+ snprintf(tmp, sizeof(tmp), "dc=%s,", dc_list[x]);
|
|
|
e55890 |
}
|
|
|
b9f8ff |
else
|
|
|
e55890 |
{
|
|
|
b9f8ff |
- sprintf(tmp, "dc=%s,", dc_list[x]);
|
|
|
b9f8ff |
+ snprintf(tmp, sizeof(tmp), "dc=%s,", dc_list[x]);
|
|
|
b9f8ff |
}
|
|
|
b9f8ff |
|
|
|
b9f8ff |
|
|
|
b9f8ff |
@@ -732,19 +835,18 @@ init_ldap_conn ()
|
|
|
e55890 |
}
|
|
|
e55890 |
|
|
|
e55890 |
result = ldap_simple_bind_s (conn, binddn, bindpw);
|
|
|
e55890 |
- ldap_result_check ("ldap_simple_bind_s", (char*)"LDAP Bind", result);
|
|
|
b9f8ff |
+ ldap_result_check ("ldap_simple_bind_s", "LDAP Bind", result);
|
|
|
e55890 |
}
|
|
|
e55890 |
|
|
|
e55890 |
/* Like isc_result_check, only for LDAP */
|
|
|
b9f8ff |
void
|
|
|
b9f8ff |
-ldap_result_check (const char *msg, char *dn, int err)
|
|
|
b9f8ff |
+ldap_result_check (const char *msg, const char *dn, int err)
|
|
|
b9f8ff |
{
|
|
|
b9f8ff |
if ((err != LDAP_SUCCESS) && (err != LDAP_ALREADY_EXISTS))
|
|
|
b9f8ff |
{
|
|
|
b9f8ff |
- fprintf(stderr, "Error while adding %s (%s):\n",
|
|
|
b9f8ff |
- dn, msg);
|
|
|
b9f8ff |
- ldap_perror (conn, dn);
|
|
|
b9f8ff |
- ldap_unbind_s (conn);
|
|
|
b9f8ff |
+ fprintf(stderr, "Error while adding %s (%s):\n%s",
|
|
|
b9f8ff |
+ dn, msg, ldap_err2string(err));
|
|
|
b9f8ff |
+ ldap_unbind_ext_s (conn, NULL, NULL);
|
|
|
b9f8ff |
exit (-1);
|
|
|
e55890 |
}
|
|
|
e55890 |
}
|
|
|
b9f8ff |
@@ -758,16 +860,15 @@ add_ldap_values (ldap_info * ldinfo)
|
|
|
e55890 |
int result;
|
|
|
e55890 |
char dnbuffer[1024];
|
|
|
e55890 |
|
|
|
e55890 |
-
|
|
|
e55890 |
if (ldapbase != NULL)
|
|
|
e55890 |
sprintf (dnbuffer, "%s,%s", ldinfo->dn, ldapbase);
|
|
|
e55890 |
else
|
|
|
e55890 |
sprintf (dnbuffer, "%s", ldinfo->dn);
|
|
|
e55890 |
|
|
|
e55890 |
result = ldap_add_s (conn, dnbuffer, ldinfo->attrs);
|
|
|
e55890 |
- ldap_result_check ("ldap_add_s", dnbuffer, result);
|
|
|
b9f8ff |
-}
|
|
|
e55890 |
+ ldap_result_check ("ldap_add_s", dnbuffer, result);
|
|
|
b9f8ff |
|
|
|
b9f8ff |
+}
|
|
|
b9f8ff |
|
|
|
e55890 |
|
|
|
e55890 |
|
|
|
b9f8ff |
@@ -776,5 +877,5 @@ void
|
|
|
e55890 |
usage ()
|
|
|
e55890 |
{
|
|
|
e55890 |
fprintf (stderr,
|
|
|
e55890 |
- "zone2ldap -D [BIND DN] -w [BIND PASSWORD] -b [BASE DN] -z [ZONE] -f [ZONE FILE] -h [LDAP HOST] "
|
|
|
e55890 |
+ "zone2ldap -D [BIND DN] [-w BIND PASSWORD | -W:prompt] -b [BASE DN] -z [ZONE] -f [ZONE FILE] -h [LDAP HOST] "
|
|
|
e55890 |
"[-c Create LDAP Base structure][-d Debug Output (lots !)] \n ");}
|