summaryrefslogtreecommitdiff
path: root/plugin/dnsnotify.c
diff options
context:
space:
mode:
Diffstat (limited to 'plugin/dnsnotify.c')
-rw-r--r--plugin/dnsnotify.c85
1 files changed, 32 insertions, 53 deletions
diff --git a/plugin/dnsnotify.c b/plugin/dnsnotify.c
index a81feb1..61c8efa 100644
--- a/plugin/dnsnotify.c
+++ b/plugin/dnsnotify.c
@@ -21,6 +21,7 @@
static const char *dnsnotify_soa_attribute = "sOARecord";
static const char *dnsnotify_ns_attribute = "nSRecord";
+static const char *dnsnotify_zone_attribute = "associatedDomain";
static int dnsnotify_enable = 1;
static int dnsnotify_delay = 5;
@@ -34,24 +35,24 @@ static pid_t dnsnotify_pid = -1;
*/
static int
-load_soa_ns_attributes (const char *dn, char **soa_result, char ***ns_result)
+load_zone_attributes (const char *dn, char **zone_result, char ***ns_result)
{
Slapi_Entry **entries;
struct berval **values, **v;
Slapi_PBlock *pb;
Slapi_Attr *attr;
LDAPControl *ctrl;
- char *attrs[3];
- char *soa, **ns;
+ char *attrs[4];
+ char *zone, **ns;
int rc, code, num, i;
trace (dn);
assert (dn && dn[0]);
- assert (dnsnotify_soa_attribute);
assert (dnsnotify_ns_attribute);
+ assert (dnsnotify_zone_attribute);
ctrl = NULL; /* No controls */
- attrs[0] = (char*)dnsnotify_soa_attribute;
+ attrs[0] = (char*)dnsnotify_zone_attribute;
attrs[1] = (char*)dnsnotify_ns_attribute;
attrs[2] = NULL;
@@ -66,7 +67,7 @@ load_soa_ns_attributes (const char *dn, char **soa_result, char ***ns_result)
rc = slapi_pblock_get (pb, SLAPI_PLUGIN_INTOP_RESULT, &code);
return_val_if_fail (rc >= 0, 0);
if (code != LDAP_SUCCESS) {
- log_plugin ("error loading attribute %s from %s (code %d)", dnsnotify_soa_attribute, dn, code);
+ log_plugin ("error loading attribute %s from %s (code %d)", dnsnotify_zone_attribute, dn, code);
slapi_pblock_destroy (pb);
trace ("failure");
return 0;
@@ -77,17 +78,17 @@ load_soa_ns_attributes (const char *dn, char **soa_result, char ***ns_result)
slapi_pblock_get (pb, SLAPI_PLUGIN_INTOP_SEARCH_ENTRIES, &entries);
return_val_if_fail (entries, 0);
- soa = NULL;
+ zone = NULL;
ns = NULL;
if (entries[0]) {
- if (slapi_entry_attr_find (entries[0], (char*)dnsnotify_soa_attribute, &attr) >= 0 && attr &&
+ if (slapi_entry_attr_find (entries[0], (char*)dnsnotify_zone_attribute, &attr) >= 0 && attr &&
slapi_attr_get_values (attr, &values) >= 0 && values && values[0]) {
/* Convert the berval into a string */
- soa = slapi_ch_malloc (values[0]->bv_len + 1);
+ zone = slapi_ch_malloc (values[0]->bv_len + 1);
if (values[0]->bv_len)
- memcpy (soa, values[0]->bv_val, values[0]->bv_len);
- soa[values[0]->bv_len] = 0;
+ memcpy (zone, values[0]->bv_val, values[0]->bv_len);
+ zone[values[0]->bv_len] = 0;
}
if (slapi_entry_attr_find (entries[0], (char*)dnsnotify_ns_attribute, &attr) >= 0 && attr &&
@@ -113,13 +114,13 @@ load_soa_ns_attributes (const char *dn, char **soa_result, char ***ns_result)
slapi_pblock_destroy (pb);
/* Only proceed if we have all the data we need */
- if (soa && soa[0] && ns && ns[0]) {
- *soa_result = soa;
+ if (zone && zone[0] && ns && ns[0]) {
+ *zone_result = zone;
*ns_result = ns;
return 1;
}
- slapi_ch_free_string (&soa);
+ slapi_ch_free_string (&zone);
slapi_ch_array_free (ns);
return 0;
@@ -231,45 +232,20 @@ write_all (int fd, const void *b, size_t len)
return len;
}
-static char*
-prep_soa_domain (char *soa)
-{
- size_t at;
-
- assert (soa && soa[0]);
-
- /* Find the first space in the SOA and cut it off there */
- while (soa[0] && isspace (soa[0]))
- ++soa;
- at = strcspn (soa, " \t\n\r\v");
- if (at == 0) {
- log_plugin ("invalid SOA present");
- return NULL;
- }
-
- soa[at] = 0;
- trace (soa);
- return soa;
-}
-
static void
-notify_dns_slaves (char *soa, char **ns)
+notify_dns_slaves (char *zone, char **ns)
{
int i, complete = 1;
char *n;
- trace (soa);
+ trace (zone);
assert (ns);
- assert (soa && soa[0]);
+ assert (zone && zone[0]);
if (!*ns)
return;
- soa = prep_soa_domain (soa);
- if (!soa)
- return;
-
slapi_lock_mutex (dnsnotify_mutex);
/* Try this twice in case things have closed up shop */
@@ -291,7 +267,7 @@ notify_dns_slaves (char *soa, char **ns)
continue;
if (write_all (dnsnotify_pipe, "NOTIFY: ", 8) < 0 ||
- write_all (dnsnotify_pipe, soa, strlen (soa)) < 0 ||
+ write_all (dnsnotify_pipe, zone, strlen (zone)) < 0 ||
write_all (dnsnotify_pipe, " ", 1) < 0 ||
write_all (dnsnotify_pipe, *ns, strlen (*ns)) < 0 ||
write_all (dnsnotify_pipe, "\n", 1) < 0) {
@@ -314,7 +290,7 @@ void
dnsnotify_post_modify (const char *dn, LDAPMod **mods)
{
LDAPMod **m, *mod;
- char *soa, **ns;
+ char *zone, **ns;
return_if_fail (dn && dn[0]);
return_if_fail (mods);
@@ -326,10 +302,10 @@ dnsnotify_post_modify (const char *dn, LDAPMod **mods)
mod = *m;
trace (mod->mod_type);
if (strcasecmp (mod->mod_type, dnsnotify_soa_attribute) == 0) {
- if (load_soa_ns_attributes (dn, &soa, &ns)) {
- notify_dns_slaves (soa, ns);
+ if (load_zone_attributes (dn, &zone, &ns)) {
+ notify_dns_slaves (zone, ns);
slapi_ch_array_free (ns);
- slapi_ch_free_string (&soa);
+ slapi_ch_free_string (&zone);
}
break;
}
@@ -339,7 +315,7 @@ dnsnotify_post_modify (const char *dn, LDAPMod **mods)
void
dnsnotify_post_add (const char *dn)
{
- char *soa, **ns;
+ char *zone, **ns;
return_if_fail (dn);
@@ -347,9 +323,9 @@ dnsnotify_post_add (const char *dn)
return;
/* A DN that is an SOA? */
- if (load_soa_ns_attributes (dn, &soa, &ns)) {
- notify_dns_slaves (soa, ns);
- slapi_ch_free_string (&soa);
+ if (load_zone_attributes (dn, &zone, &ns)) {
+ notify_dns_slaves (zone, ns);
+ slapi_ch_free_string (&zone);
slapi_ch_array_free (ns);
}
}
@@ -362,11 +338,14 @@ dnsnotify_config (const char *name, const char *value)
if (strcmp (name, "soa-attribute") == 0 && value) {
dnsnotify_soa_attribute = value;
return 1;
- }
- else if (strcmp (name, "ns-attribute") == 0 && value) {
+ } else if (strcmp (name, "ns-attribute") == 0 && value) {
dnsnotify_ns_attribute = value;
return 1;
+
+ } else if (strcmp (name, "zone-attribute") == 0 && value) {
+ dnsnotify_zone_attribute = value;
+ return 1;
}
else if (strcmp (name, "notify-delay") == 0 && value) {