From d42c47a22854a97d8bc6d54aebfa93371ac1bd19 Mon Sep 17 00:00:00 2001 From: Sumit Bose Date: Fri, 25 Feb 2011 12:52:59 +0100 Subject: [PATCH] Fixes for dynamic DNS update The current code assumed that only one server is given in the ipa_server config option and fails if multiple servers were given. To fix this the IP address of the currently active LDAP server is used. If there is no default realm given in /etc/krb5.conf nsupdate start trying to find a realm based on the DNS domain which might lead to wrong results. To be on the safe side the realm was added to the message send to nsupdate. --- src/providers/ipa/ipa_dyndns.c | 21 +++++++++++++++++---- 1 files changed, 17 insertions(+), 4 deletions(-) diff --git a/src/providers/ipa/ipa_dyndns.c b/src/providers/ipa/ipa_dyndns.c index af94283..372771f 100644 --- a/src/providers/ipa/ipa_dyndns.c +++ b/src/providers/ipa/ipa_dyndns.c @@ -353,17 +353,27 @@ static int create_nsupdate_message(struct ipa_nsupdate_ctx *ctx) { int ret, i; char *servername; + char *realm; char *zone; char ip_addr[INET6_ADDRSTRLEN]; const char *ip; struct ipa_ipaddress *new_record; - servername = dp_opt_get_string(ctx->dyndns_ctx->ipa_ctx->basic, - IPA_SERVER); + if (strncmp(ctx->dyndns_ctx->ipa_ctx->service->sdap->uri, + "ldap://", 7) != 0) { + DEBUG(1, ("Unexpected format of LDAP URI.\n")); + return EIO; + } + servername = ctx->dyndns_ctx->ipa_ctx->service->sdap->uri + 7; if (!servername) { return EIO; } + realm = dp_opt_get_string(ctx->dyndns_ctx->ipa_ctx->basic, IPA_KRB5_REALM); + if (!realm) { + return EIO; + } + zone = dp_opt_get_string(ctx->dyndns_ctx->ipa_ctx->basic, IPA_DOMAIN); if (!zone) { @@ -377,9 +387,12 @@ static int create_nsupdate_message(struct ipa_nsupdate_ctx *ctx) zone[i] = tolower(zone[i]); } + DEBUG(9, ("Creating update message for server [%s], realm [%s] " + "and zone [%s].\n", servername, realm, zone)); + /* Add the server and zone headers */ - ctx->update_msg = talloc_asprintf(ctx, "server %s\nzone %s.\n", - servername, + ctx->update_msg = talloc_asprintf(ctx, "server %s\nrealm %s\nzone %s.\n", + servername, realm, zone); if (ctx->update_msg == NULL) { ret = ENOMEM; -- 1.7.4