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

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