summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorYassir Elley <yelley@redhat.com>2014-06-18 13:42:50 -0400
committerJakub Hrozek <jhrozek@redhat.com>2014-07-01 11:29:10 +0200
commitd3ca320a1ddea52fe86c052dd5521b8f98bb4f9f (patch)
tree085565232aefcde7744e529412f48739e7fd0d1e
parent19d3aba12c70528708be9440aca66038a291f29e (diff)
downloadsssd-d3ca320a1ddea52fe86c052dd5521b8f98bb4f9f.tar.gz
sssd-d3ca320a1ddea52fe86c052dd5521b8f98bb4f9f.tar.xz
sssd-d3ca320a1ddea52fe86c052dd5521b8f98bb4f9f.zip
Use ldap_url_parse to extract hostname from ldap uri
Reviewed-by: Sumit Bose <sbose@redhat.com>
-rw-r--r--src/providers/ad/ad_gpo.c25
1 files changed, 20 insertions, 5 deletions
diff --git a/src/providers/ad/ad_gpo.c b/src/providers/ad/ad_gpo.c
index 7928e6faa..02387f48f 100644
--- a/src/providers/ad/ad_gpo.c
+++ b/src/providers/ad/ad_gpo.c
@@ -864,6 +864,7 @@ ad_gpo_access_send(TALLOC_CTX *mem_ctx,
struct tevent_req *subreq;
struct ad_gpo_access_state *state;
char *server_uri;
+ LDAPURLDesc *lud;
errno_t ret;
/* setup logging for gpo child */
@@ -897,14 +898,28 @@ ad_gpo_access_send(TALLOC_CTX *mem_ctx,
/* extract server_hostname from server_uri */
server_uri = state->conn->service->uri;
- if (strncasecmp(server_uri, LDAP_STANDARD_URI, strlen(LDAP_STANDARD_URI)) == 0) {
- state->server_hostname = server_uri + strlen(LDAP_STANDARD_URI);
- } else if (strncasecmp(server_uri, LDAP_SSL_URI, strlen(LDAP_SSL_URI)) == 0) {
- state->server_hostname = server_uri + strlen(LDAP_SSL_URI);
- } else {
+ ret = ldap_url_parse(server_uri, &lud);
+ if (ret != LDAP_SUCCESS) {
+ DEBUG(SSSDBG_CRIT_FAILURE,
+ "Failed to parse ldap URI (%s)!\n", server_uri);
ret = EINVAL;
goto immediately;
}
+
+ if (lud->lud_host == NULL) {
+ DEBUG(SSSDBG_CRIT_FAILURE,
+ "The LDAP URI (%s) did not contain a host name\n", server_uri);
+ ldap_free_urldesc(lud);
+ ret = EINVAL;
+ goto immediately;
+ }
+
+ state->server_hostname = talloc_strdup(state, lud->lud_host);
+ ldap_free_urldesc(lud);
+ if (!state->server_hostname) {
+ ret = ENOMEM;
+ goto immediately;
+ }
DEBUG(SSSDBG_TRACE_ALL, "server_hostname from uri: %s\n",
state->server_hostname);