s3:smbldap: add smbldap_talloc_first_attribute()
authorStefan Metzmacher <metze@samba.org>
Tue, 5 Jan 2010 12:30:19 +0000 (13:30 +0100)
committerKarolin Seeger <kseeger@samba.org>
Wed, 13 Jan 2010 13:01:06 +0000 (14:01 +0100)
metze

Signed-off-by: Stefan Metzmacher <metze@samba.org>
(cherry picked from commit c992127f8a96c37940a6d298c7c6859c47f83d9b)

source/include/smbldap.h
source/lib/smbldap.c

index e312bb2899e575c08bb767a63df5e613ab05fc1b..0fe1d6cccd1288ed50d15932b1a1411a1e3d6758 100644 (file)
@@ -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);
index 704a51640a5e42f9f7f6caff59b68c561cbf89e6..6678ad9b8d0dca4a43c00855db3faff6a908dfdb 100644 (file)
@@ -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)