[SSSD] [PATCH] GPO: Extract server hostname after connecting

Jakub Hrozek jhrozek at redhat.com
Wed Jan 7 10:47:49 UTC 2015


Hi,

the attached patch is related to GPO offline functionality, please check
the commit message.

To reproduce, set up an AD client with GPOs, make sure credential
caching is enabled. Log in as a permitted user to cache the credentials.
Go offline, in my case by pointing resolv.conf to a DNS server that
doesn't know the AD domain. Attempt to log in.
-------------- next part --------------
>From fae1b6ba56d39126ef60f1de3a8449e244f9be26 Mon Sep 17 00:00:00 2001
From: Jakub Hrozek <jhrozek at redhat.com>
Date: Tue, 6 Jan 2015 13:03:34 +0100
Subject: [PATCH] GPO: Extract server hostname after connecting

https://fedorahosted.org/sssd/ticket/2543

The LDAP URI is not valid prior to connecting to LDAP. Moreover,
reconnecting to a different server might invalidate the URI.

Move reading the URI after the connection has been established.
---
 src/providers/ad/ad_gpo.c | 58 +++++++++++++++++++++++------------------------
 1 file changed, 29 insertions(+), 29 deletions(-)

diff --git a/src/providers/ad/ad_gpo.c b/src/providers/ad/ad_gpo.c
index 62715861c91484fa2a57e7cc13ba403c9096d9a7..01dfa1c07953e88477dbd1f30b65ea81531c4f68 100644
--- a/src/providers/ad/ad_gpo.c
+++ b/src/providers/ad/ad_gpo.c
@@ -1486,8 +1486,6 @@ ad_gpo_access_send(TALLOC_CTX *mem_ctx,
     struct tevent_req *req;
     struct tevent_req *subreq;
     struct ad_gpo_access_state *state;
-    char *server_uri;
-    LDAPURLDesc *lud;
     errno_t ret;
     int hret;
     hash_key_t key;
@@ -1577,33 +1575,6 @@ ad_gpo_access_send(TALLOC_CTX *mem_ctx,
         goto immediately;
     }
 
-    /* extract server_hostname from server_uri */
-    server_uri = state->conn->service->uri;
-    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);
-
     subreq = sdap_id_op_connect_send(state->sdap_op, state, &ret);
     if (subreq == NULL) {
         DEBUG(SSSDBG_OP_FAILURE,
@@ -1663,6 +1634,8 @@ ad_gpo_connect_done(struct tevent_req *subreq)
     char *domain_dn;
     int dp_error;
     errno_t ret;
+    char *server_uri;
+    LDAPURLDesc *lud;
 
     const char *attrs[] = {AD_AT_DN, AD_AT_UAC, NULL};
 
@@ -1699,6 +1672,33 @@ ad_gpo_connect_done(struct tevent_req *subreq)
         }
     }
 
+    /* extract server_hostname from server_uri */
+    server_uri = state->conn->service->uri;
+    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 done;
+    }
+
+    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 done;
+    }
+
+    state->server_hostname = talloc_strdup(state, lud->lud_host);
+    ldap_free_urldesc(lud);
+    if (!state->server_hostname) {
+        ret = ENOMEM;
+        goto done;
+    }
+    DEBUG(SSSDBG_TRACE_ALL, "server_hostname from uri: %s\n",
+          state->server_hostname);
+
     sam_account_name = sss_krb5_get_primary(state, "%S$", state->ad_hostname);
     if (sam_account_name == NULL) {
         ret = ENOMEM;
-- 
1.9.3



More information about the sssd-devel mailing list