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