bind/SOURCES/bind-9.11-zone2ldap.patch

196 lines
5.7 KiB
Diff
Raw Normal View History

2020-07-28 07:51:19 +00:00
From 9683a4d2524b870c4cee09259cb5eb7b8075a507 Mon Sep 17 00:00:00 2001
2019-08-05 14:40:24 +00:00
From: =?UTF-8?q?Petr=20Men=C5=A1=C3=ADk?= <pemensik@redhat.com>
Date: Tue, 18 Dec 2018 16:06:26 +0100
Subject: [PATCH] Make absolute hostname by dns API instead of strings
Duplicate all strings in dc_list. Free allocated memory on each record.
---
2020-07-28 07:51:19 +00:00
bin/sdb_tools/zone2ldap.c | 70 +++++++++++++++++++++++++--------------
1 file changed, 45 insertions(+), 25 deletions(-)
2019-08-05 14:40:24 +00:00
diff --git a/bin/sdb_tools/zone2ldap.c b/bin/sdb_tools/zone2ldap.c
2020-07-28 07:51:19 +00:00
index d59936c..9ba73b8 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
@@ -84,6 +84,10 @@ int get_attr_list_size (char **tmp);
2019-08-05 14:40:24 +00:00
/* Get a DN */
char *build_dn_from_dc_list (char **dc_list, unsigned int ttl, int flag, char *zone);
+/* Free a DN list */
+static void
+free_dc_list(char **dc_list);
+
/* Add to RR list */
void add_to_rr_list (char *dn, char *name, char *type, char *data,
unsigned int ttl, unsigned int flags);
2020-07-28 07:51:19 +00:00
@@ -120,6 +124,7 @@ static char dNSTTL []="dNSTTL";
2019-08-05 14:40:24 +00:00
static char zoneName []="zoneName";
static char dc []="dc";
static char sameZone []="@";
+static char dot []=".";
/* LDAPMod mod_values: */
static char *objectClasses []= { &(topClass[0]), &(dNSZoneClass[0]), NULL };
static char *topObjectClasses []= { &(topClass[0]), &(dcObjectClass[0]), &(dNSZoneClass[0]), NULL };
2020-07-28 07:51:19 +00:00
@@ -391,6 +396,8 @@ main (int argc, char **argv)
2019-08-05 14:40:24 +00:00
}
}
+
+ free_dc_list(dc_list);
}
else
{
2020-07-28 07:51:19 +00:00
@@ -446,12 +453,18 @@ generate_ldap (dns_name_t * dnsname, dns_rdata_t * rdata, unsigned int ttl)
2019-08-05 14:40:24 +00:00
char data[2048];
char **dc_list;
char *dn;
+ size_t argzone_len;
2020-01-21 22:30:08 +00:00
+ bool omit_dot;
2019-08-05 14:40:24 +00:00
isc_buffer_t buff;
isc_result_t result;
isc_buffer_init (&buff, name, sizeof (name));
2020-01-21 22:30:08 +00:00
result = dns_name_totext (dnsname, true, &buff);
2019-08-05 14:40:24 +00:00
+ argzone_len = strlen(argzone);
+ /* If argzone is absolute, output absolute name too */
2020-01-21 22:30:08 +00:00
+ omit_dot = (!(argzone_len > 0 && argzone[argzone_len-1] == '.'));
2019-08-05 14:40:24 +00:00
+ result = dns_name_totext (dnsname, omit_dot, &buff);
isc_result_check (result, "dns_name_totext");
name[isc_buffer_usedlength (&buff)] = 0;
2020-07-28 07:51:19 +00:00
@@ -473,6 +486,7 @@ generate_ldap (dns_name_t * dnsname, dns_rdata_t * rdata, unsigned int ttl)
2019-08-05 14:40:24 +00:00
printf ("Adding %s (%s %s) to run queue list.\n", dn, type, data);
add_to_rr_list (dn, dc_list[len], (char*)type, (char*)data, ttl, DNS_OBJECT);
+ free_dc_list(dc_list);
}
2020-07-28 07:51:19 +00:00
@@ -533,12 +547,9 @@ add_to_rr_list (char *dn, char *name, char *type,
2019-08-05 14:40:24 +00:00
if (tmp->attrs == (LDAPMod **) NULL)
fatal("calloc");
- for (i = 0; i < (int)flags; i++)
- {
- tmp->attrs[i] = (LDAPMod *) malloc (sizeof (LDAPMod));
- if (tmp->attrs[i] == (LDAPMod *) NULL)
- fatal("malloc");
- }
+ tmp->attrs[0] = (LDAPMod *) malloc (sizeof (LDAPMod));
+ if (tmp->attrs[0] == (LDAPMod *) NULL)
+ fatal("malloc");
tmp->attrs[0]->mod_op = LDAP_MOD_ADD;
tmp->attrs[0]->mod_type = objectClass;
2020-07-28 07:51:19 +00:00
@@ -554,9 +565,18 @@ add_to_rr_list (char *dn, char *name, char *type,
2019-08-05 14:40:24 +00:00
return;
}
+ for (i = 1; i < (int)flags-1; i++)
+ {
+ tmp->attrs[i] = (LDAPMod *) malloc (sizeof (LDAPMod));
+ if (tmp->attrs[i] == (LDAPMod *) NULL)
+ fatal("malloc");
+ }
+ tmp->attrs[i] = NULL;
+
+
tmp->attrs[1]->mod_op = LDAP_MOD_ADD;
tmp->attrs[1]->mod_type = relativeDomainName;
- tmp->attrs[1]->mod_values = (char **) calloc (sizeof (char *), 2);
+ tmp->attrs[1]->mod_values = (char **) calloc (sizeof (char *), 3);
if (tmp->attrs[1]->mod_values == (char **)NULL)
fatal("calloc");
2020-07-28 07:51:19 +00:00
@@ -701,24 +721,16 @@ hostname_to_dn_list (char *hostname, char *zone, unsigned int flags)
2019-08-05 14:40:24 +00:00
{
char *tmp;
2020-07-28 07:51:19 +00:00
int i = 0;
+ int j = 0;
2019-08-05 14:40:24 +00:00
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
+ hname= strdup(hostname);
last = strdup(sameZone);
2019-08-05 14:40:24 +00:00
}else
2020-07-28 07:51:19 +00:00
{
@@ -726,8 +738,6 @@ hostname_to_dn_list (char *hostname, char *zone, unsigned int flags)
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);
2020-07-28 07:51:19 +00:00
@@ -735,8 +745,7 @@ hostname_to_dn_list (char *hostname, char *zone, unsigned int flags)
2019-08-05 14:40:24 +00:00
sprintf(hname,"%s",zone);
}else
{
- if( hname == 0 )
- hname = strdup(hostname);
+ hname = strdup(hostname);
}
last = hname;
}
2020-07-28 07:51:19 +00:00
@@ -749,18 +758,21 @@ hostname_to_dn_list (char *hostname, char *zone, unsigned int flags)
2019-08-05 14:40:24 +00:00
for (tmp = strrchr (hname, '.'); tmp != (char *) 0;
tmp = strrchr (hname, '.'))
{
- if( *( tmp + 1 ) != '\0' )
+ tmp[0] = '\0';
+ if( tmp[1] != '\0' )
{
- *tmp = '\0';
dn_buffer[i++] = ++tmp;
}else
{ /* trailing '.' ! */
- dn_buffer[i++] = strdup(".");
- *tmp = '\0';
+ dn_buffer[i++] = dot;
if( tmp == hname )
break;
2020-07-28 07:51:19 +00:00
}
2019-08-05 14:40:24 +00:00
}
+ for (j=0; j<i; j++)
+ {
+ dn_buffer[j] = strdup(dn_buffer[j]);
+ }
if( ( last != hname ) && (tmp != hname) )
dn_buffer[i++] = hname;
dn_buffer[i++] = last;
2020-07-28 07:51:19 +00:00
@@ -820,6 +832,14 @@ build_dn_from_dc_list (char **dc_list, unsigned int ttl, int flag, char *zone)
2019-08-05 14:40:24 +00:00
return dn;
}
+static void
+free_dc_list(char **dc_list)
+{
+ for (; *dc_list; dc_list++) {
+ free(*dc_list);
+ *dc_list=NULL;
+ }
+}
/* Initialize LDAP Conn */
void
--
2020-07-28 07:51:19 +00:00
2.21.1
2019-08-05 14:40:24 +00:00