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