summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndrew Bartlett <abartlet@samba.org>2004-01-05 00:13:00 +0000
committerAndrew Bartlett <abartlet@samba.org>2004-01-05 00:13:00 +0000
commit39c7d3dc4a89f41c9463963366e9b92442a38e30 (patch)
tree1dc0189dd5ed79c794d808509c24173d6e27ea9d
parentd4954eff579517f4a2189565bf7d49f119c886a2 (diff)
downloadsamba-39c7d3dc4a89f41c9463963366e9b92442a38e30.tar.gz
samba-39c7d3dc4a89f41c9463963366e9b92442a38e30.tar.bz2
samba-39c7d3dc4a89f41c9463963366e9b92442a38e30.zip
Add a utilty function for converting a sid to a DN.
Andrew Bartlett (This used to be commit 49a7a3fd17cfeef439e2049a51dbfcbc037f1a93)
-rw-r--r--source3/libads/ads_ldap.c74
1 files changed, 74 insertions, 0 deletions
diff --git a/source3/libads/ads_ldap.c b/source3/libads/ads_ldap.c
index dcceaaeb83..177e8632f6 100644
--- a/source3/libads/ads_ldap.c
+++ b/source3/libads/ads_ldap.c
@@ -152,4 +152,78 @@ done:
return status;
}
+/* convert a sid to a DN */
+
+NTSTATUS ads_sid_to_dn(ADS_STRUCT *ads,
+ TALLOC_CTX *mem_ctx,
+ const DOM_SID *sid,
+ char **dn)
+{
+ ADS_STATUS rc;
+ LDAPMessage *msg = NULL;
+ LDAPMessage *entry = NULL;
+ char *ldap_exp = NULL;
+ char *sidstr = NULL;
+ int count;
+ char *dn2;
+ NTSTATUS status = NT_STATUS_UNSUCCESSFUL;
+
+ if (!(sidstr = sid_binstring(sid))) {
+ DEBUG(1,("ads_sid_to_dn: sid_binstring failed!\n"));
+ status = NT_STATUS_NO_MEMORY;
+ goto done;
+ }
+
+ if (asprintf(&ldap_exp, "(objectSid=%s)", sidstr) == -1) {
+ DEBUG(1,("ads_sid_to_dn: asprintf failed!\n"));
+ status = NT_STATUS_NO_MEMORY;
+ goto done;
+ }
+
+ rc = ads_search_retry(ads, &msg, ldap_exp, NULL);
+ if (!ADS_ERR_OK(rc)) {
+ status = ads_ntstatus(rc);
+ DEBUG(1,("ads_sid_to_dn ads_search: %s\n", ads_errstr(rc)));
+ goto done;
+ }
+
+ if ((count = ads_count_replies(msg)) != 1) {
+ DEBUG(1,("ads_sid_to_dn (sid=%s): Not found (count=%d)\n",
+ sid_to_string(sid_string, sid)), count);
+ status = NT_STATUS_UNSUCCESSFUL;
+ goto done;
+ }
+
+ entry = ads_first_entry(msg);
+
+ dn2 = ads_get_dn(ads, entry);
+
+ if (!dn2) {
+ status = NT_STATUS_NO_MEMORY;
+ goto done;
+ }
+
+ *dn = talloc_strdup(mem_ctx, dn2);
+
+ if (!*dn) {
+ SAFE_FREE(dn2);
+ status = NT_STATUS_NO_MEMORY;
+ goto done;
+ }
+
+ status = NT_STATUS_OK;
+
+ DEBUG(3,("ads sid_to_dn mapped %s\n", *dn2));
+
+ SAFE_FREE(dn2);
+done:
+ if (msg) ads_msgfree(ads, msg);
+
+ SAFE_FREE(ldap_exp);
+ SAFE_FREE(sidstr);
+
+ return status;
+}
+
+
#endif