summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorStefan Metzmacher <metze@samba.org>2010-01-05 13:30:19 +0100
committerStefan Metzmacher <metze@samba.org>2010-01-14 02:26:29 +0100
commit915b7552b71904baf6a452bdc1649e76d8286a14 (patch)
tree0a652e3f1c53bbe2abaf3c3ab1854b3d186ca34a
parent204e4b26aecb7e51da80cbf63efe952d17bbe856 (diff)
downloadsamba-915b7552b71904baf6a452bdc1649e76d8286a14.tar.gz
samba-915b7552b71904baf6a452bdc1649e76d8286a14.tar.bz2
samba-915b7552b71904baf6a452bdc1649e76d8286a14.zip
s3:smbldap: add smbldap_talloc_first_attribute()
metze Signed-off-by: Stefan Metzmacher <metze@samba.org> (cherry picked from commit c992127f8a96c37940a6d298c7c6859c47f83d9b)
-rw-r--r--source3/include/smbldap.h3
-rw-r--r--source3/lib/smbldap.c34
2 files changed, 37 insertions, 0 deletions
diff --git a/source3/include/smbldap.h b/source3/include/smbldap.h
index 8710e77f3d..e3b03d4948 100644
--- a/source3/include/smbldap.h
+++ b/source3/include/smbldap.h
@@ -211,6 +211,9 @@ const char** get_userattr_list( TALLOC_CTX *mem_ctx, int schema_ver );
char * smbldap_talloc_single_attribute(LDAP *ldap_struct, LDAPMessage *entry,
const char *attribute,
TALLOC_CTX *mem_ctx);
+char * smbldap_talloc_first_attribute(LDAP *ldap_struct, LDAPMessage *entry,
+ const char *attribute,
+ TALLOC_CTX *mem_ctx);
char * smbldap_talloc_smallest_attribute(LDAP *ldap_struct, LDAPMessage *entry,
const char *attribute,
TALLOC_CTX *mem_ctx);
diff --git a/source3/lib/smbldap.c b/source3/lib/smbldap.c
index 4727c1593e..7aa36bac0b 100644
--- a/source3/lib/smbldap.c
+++ b/source3/lib/smbldap.c
@@ -333,6 +333,40 @@ ATTRIB_MAP_ENTRY sidmap_attr_list[] = {
return result;
}
+ char * smbldap_talloc_first_attribute(LDAP *ldap_struct, LDAPMessage *entry,
+ const char *attribute,
+ TALLOC_CTX *mem_ctx)
+{
+ char **values;
+ char *result;
+ size_t converted_size;
+
+ if (attribute == NULL) {
+ return NULL;
+ }
+
+ values = ldap_get_values(ldap_struct, entry, attribute);
+
+ if (values == NULL) {
+ DEBUG(10, ("attribute %s does not exist\n", attribute));
+ return NULL;
+ }
+
+ if (!pull_utf8_talloc(mem_ctx, &result, values[0], &converted_size)) {
+ DEBUG(10, ("pull_utf8_talloc failed\n"));
+ ldap_value_free(values);
+ return NULL;
+ }
+
+ ldap_value_free(values);
+
+#ifdef DEBUG_PASSWORDS
+ DEBUG (100, ("smbldap_get_first_attribute: [%s] = [%s]\n",
+ attribute, result));
+#endif
+ return result;
+}
+
char * smbldap_talloc_smallest_attribute(LDAP *ldap_struct, LDAPMessage *entry,
const char *attribute,
TALLOC_CTX *mem_ctx)