summaryrefslogtreecommitdiff
path: root/source3/libads
diff options
context:
space:
mode:
authorGünther Deschner <gd@samba.org>2007-07-09 16:03:00 +0000
committerGerald (Jerry) Carter <jerry@samba.org>2007-10-10 12:23:55 -0500
commit221d06d6f3e9789bf3efc6fa52dd94e68b1804cf (patch)
treeb035602569944df0eba9c1ec02f0bf3532e529c8 /source3/libads
parent3438f7d5337905fc26d313bbbb086236d5f6ce6b (diff)
downloadsamba-221d06d6f3e9789bf3efc6fa52dd94e68b1804cf.tar.gz
samba-221d06d6f3e9789bf3efc6fa52dd94e68b1804cf.tar.bz2
samba-221d06d6f3e9789bf3efc6fa52dd94e68b1804cf.zip
r23772: Add ads_find_samaccount() helper function.
Guenther (This used to be commit 6fafa64bea4ce6a7a5917fa02ed9c564a7c93ffb)
Diffstat (limited to 'source3/libads')
-rw-r--r--source3/libads/ldap.c60
1 files changed, 60 insertions, 0 deletions
diff --git a/source3/libads/ldap.c b/source3/libads/ldap.c
index d60afcd0d5..6f0ca3452c 100644
--- a/source3/libads/ldap.c
+++ b/source3/libads/ldap.c
@@ -3272,4 +3272,64 @@ ADS_STATUS ads_leave_realm(ADS_STRUCT *ads, const char *hostname)
return ADS_ERROR_LDAP(LDAP_SUCCESS);
}
+ADS_STATUS ads_find_samaccount(ADS_STRUCT *ads,
+ TALLOC_CTX *mem_ctx,
+ const char *samaccountname,
+ uint32 *uac_ret,
+ const char **dn_ret)
+{
+ ADS_STATUS status;
+ const char *attrs[] = { "userAccountControl", NULL };
+ const char *filter;
+ LDAPMessage *res = NULL;
+ char *dn = NULL;
+ uint32 uac = 0;
+
+ filter = talloc_asprintf(mem_ctx, "(&(objectclass=user)(sAMAccountName=%s))",
+ samaccountname);
+ if (filter == NULL) {
+ goto out;
+ }
+
+ status = ads_do_search_all(ads, ads->config.bind_path,
+ LDAP_SCOPE_SUBTREE,
+ filter, attrs, &res);
+
+ if (!ADS_ERR_OK(status)) {
+ goto out;
+ }
+
+ if (ads_count_replies(ads, res) != 1) {
+ printf("no result\n");
+ goto out;
+ }
+
+ dn = ads_get_dn(ads, res);
+ if (dn == NULL) {
+ status = ADS_ERROR(LDAP_NO_MEMORY);
+ goto out;
+ }
+
+ if (!ads_pull_uint32(ads, res, "userAccountControl", &uac)) {
+ status = ADS_ERROR(LDAP_NO_SUCH_ATTRIBUTE);
+ goto out;
+ }
+
+ if (uac_ret) {
+ *uac_ret = uac;
+ }
+
+ if (dn_ret) {
+ *dn_ret = talloc_strdup(mem_ctx, dn);
+ if (!*dn_ret) {
+ status = ADS_ERROR(LDAP_NO_MEMORY);
+ goto out;
+ }
+ }
+ out:
+ ads_memfree(ads, dn);
+ ads_msgfree(ads, res);
+
+ return status;
+}
#endif