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

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