Blame SOURCES/0005-library-add-lookup_domain_sid.patch

776d17
From 43fe15cc27ebf5f33234c30067a295ef0bd864bb Mon Sep 17 00:00:00 2001
776d17
From: Sumit Bose <sbose@redhat.com>
776d17
Date: Tue, 30 Jan 2018 14:40:46 +0100
776d17
Subject: [PATCH 5/9] library: add lookup_domain_sid()
776d17
776d17
Read the domain SID from the default naming context AD object and store
776d17
it in adcli_conn.
776d17
776d17
https://bugs.freedesktop.org/show_bug.cgi?id=100118
776d17
776d17
Reviewed-by: Jakub Hrozek <jhrozek@redhat.com>
776d17
---
776d17
 library/adconn.c | 28 ++++++++++++++++++++++++++++
776d17
 1 file changed, 28 insertions(+)
776d17
776d17
diff --git a/library/adconn.c b/library/adconn.c
776d17
index 67bdfd9..6b84b88 100644
776d17
--- a/library/adconn.c
776d17
+++ b/library/adconn.c
776d17
@@ -72,6 +72,7 @@ struct _adcli_conn_ctx {
776d17
 	char *domain_controller;
776d17
 	char *canonical_host;
776d17
 	char *domain_short;
776d17
+	char *domain_sid;
776d17
 	adcli_disco *domain_disco;
776d17
 	char *default_naming_context;
776d17
 	char *configuration_naming_context;
776d17
@@ -1068,6 +1069,32 @@ lookup_short_name (adcli_conn *conn)
776d17
 	}
776d17
 }
776d17
 
776d17
+static void
776d17
+lookup_domain_sid (adcli_conn *conn)
776d17
+{
776d17
+	char *attrs[] = { "objectSid", NULL, };
776d17
+	LDAPMessage *results;
776d17
+	int ret;
776d17
+
776d17
+	free (conn->domain_sid);
776d17
+	conn->domain_sid = NULL;
776d17
+
776d17
+	ret = ldap_search_ext_s (conn->ldap, conn->default_naming_context, LDAP_SCOPE_BASE,
776d17
+	                         NULL, attrs, 0, NULL, NULL, NULL, -1, &results);
776d17
+	if (ret == LDAP_SUCCESS) {
776d17
+		conn->domain_sid = _adcli_ldap_parse_sid (conn->ldap, results, "objectSid");
776d17
+		ldap_msgfree (results);
776d17
+
776d17
+		if (conn->domain_sid)
776d17
+			_adcli_info ("Looked up domain SID: %s", conn->domain_sid);
776d17
+		else
776d17
+			_adcli_err ("No domain SID found");
776d17
+	} else {
776d17
+		_adcli_ldap_handle_failure (conn->ldap, ADCLI_ERR_DIRECTORY,
776d17
+		                            "Couldn't lookup domain SID");
776d17
+	}
776d17
+}
776d17
+
776d17
 static void
776d17
 conn_clear_state (adcli_conn *conn)
776d17
 {
776d17
@@ -1148,6 +1175,7 @@ adcli_conn_connect (adcli_conn *conn)
776d17
 		return res;
776d17
 
776d17
 	lookup_short_name (conn);
776d17
+	lookup_domain_sid (conn);
776d17
 	return ADCLI_SUCCESS;
776d17
 }
776d17
 
776d17
-- 
776d17
2.14.4
776d17