diff options
author | Stefan Metzmacher <metze@samba.org> | 2010-01-05 13:30:19 +0100 |
---|---|---|
committer | Karolin Seeger <kseeger@samba.org> | 2010-01-13 14:01:06 +0100 |
commit | a1c58a8f96f0c5ede36e25a1c6aced175bec6a9d (patch) | |
tree | d387b0199057eca197492dc169db16017c230aff | |
parent | 2dbe990fe492872d3a9e63cc1115e6f8b363faa1 (diff) | |
download | samba-a1c58a8f96f0c5ede36e25a1c6aced175bec6a9d.tar.gz samba-a1c58a8f96f0c5ede36e25a1c6aced175bec6a9d.tar.xz samba-a1c58a8f96f0c5ede36e25a1c6aced175bec6a9d.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-- | source/include/smbldap.h | 3 | ||||
-rw-r--r-- | source/lib/smbldap.c | 34 |
2 files changed, 37 insertions, 0 deletions
diff --git a/source/include/smbldap.h b/source/include/smbldap.h index e312bb2899e..0fe1d6cccd1 100644 --- a/source/include/smbldap.h +++ b/source/include/smbldap.h @@ -212,6 +212,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/source/lib/smbldap.c b/source/lib/smbldap.c index 704a51640a5..6678ad9b8d0 100644 --- a/source/lib/smbldap.c +++ b/source/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) |