diff options
author | Jakub Hrozek <jhrozek@redhat.com> | 2013-05-17 14:33:26 +0200 |
---|---|---|
committer | Jakub Hrozek <jhrozek@redhat.com> | 2013-05-28 15:11:32 +0200 |
commit | 2338eef6ec830dcbbc7e9f7bcebf31656e8742ec (patch) | |
tree | 8410ae4e71a2a8df1ecf4f3e8ca93a186e8fe04a /src | |
parent | 7a5a121ae04e3609628855b8383a5d74d405a70d (diff) | |
download | sssd-2338eef6ec830dcbbc7e9f7bcebf31656e8742ec.tar.gz sssd-2338eef6ec830dcbbc7e9f7bcebf31656e8742ec.tar.bz2 sssd-2338eef6ec830dcbbc7e9f7bcebf31656e8742ec.zip |
AD dyndns: extract the host name from URI
Diffstat (limited to 'src')
-rw-r--r-- | src/providers/ad/ad_dyndns.c | 40 |
1 files changed, 31 insertions, 9 deletions
diff --git a/src/providers/ad/ad_dyndns.c b/src/providers/ad/ad_dyndns.c index 4e9ed852..da01426c 100644 --- a/src/providers/ad/ad_dyndns.c +++ b/src/providers/ad/ad_dyndns.c @@ -159,6 +159,7 @@ static void ad_dyndns_nsupdate_done(struct tevent_req *req) struct ad_dyndns_update_state { struct ad_options *ad_ctx; + const char *servername; }; static void ad_dyndns_sdap_update_done(struct tevent_req *subreq); @@ -170,7 +171,7 @@ ad_dyndns_update_send(struct ad_options *ctx) struct ad_dyndns_update_state *state; struct tevent_req *req, *subreq; struct sdap_id_ctx *sdap_ctx = ctx->id_ctx->sdap_id_ctx; - const char *servername; + LDAPURLDesc *lud; DEBUG(SSSDBG_TRACE_FUNC, ("Performing update\n")); @@ -190,15 +191,36 @@ ad_dyndns_update_send(struct ad_options *ctx) } state->ad_ctx->dyndns_ctx->last_refresh = time(NULL); - if (strncmp(ctx->service->sdap->uri, - "ldap://", 7) != 0) { - DEBUG(SSSDBG_CRIT_FAILURE, ("Unexpected format of LDAP URI.\n")); - ret = EIO; + ret = ldap_url_parse(ctx->service->sdap->uri, &lud); + if (ret != LDAP_SUCCESS) { + DEBUG(SSSDBG_CRIT_FAILURE, + ("Failed to parse ldap URI (%s)!\n", ctx->service->sdap->uri)); + ret = EINVAL; goto done; } - servername = ctx->service->sdap->uri + 7; - if (!servername) { - ret = EIO; + + if (lud->lud_scheme != NULL && + strcasecmp(lud->lud_scheme, "ldapi") == 0) { + DEBUG(SSSDBG_CRIT_FAILURE, + ("The LDAP scheme is ldapi://, cannot proceed with update\n")); + ldap_free_urldesc(lud); + ret = EINVAL; + goto done; + } + + if (lud->lud_host == NULL) { + DEBUG(SSSDBG_CRIT_FAILURE, + ("The LDAP URI (%s) did not contain a host name\n", + ctx->service->sdap->uri)); + ldap_free_urldesc(lud); + ret = EINVAL; + goto done; + } + + state->servername = talloc_strdup(state, lud->lud_host); + ldap_free_urldesc(lud); + if (!state->servername) { + ret = ENOMEM; goto done; } @@ -214,7 +236,7 @@ ad_dyndns_update_send(struct ad_options *ctx) NULL, dp_opt_get_string(ctx->basic, AD_KRB5_REALM), - servername, + state->servername, dp_opt_get_int(ctx->dyndns_ctx->opts, DP_OPT_DYNDNS_TTL), false); |