From: Volker Lendecke Date: Thu, 12 Mar 2009 16:23:17 +0000 (+0100) Subject: Fix bug 6157 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=47333fc8785457239a499a298536664f152b681d;p=thirdparty%2Fsamba.git Fix bug 6157 This patch picks the alphabetically smallest one of the multi-value attribute "uid". This fixes a regression against 3.0 and also becomes deterministic. --- diff --git a/source/include/smbldap.h b/source/include/smbldap.h index a2cb8c5eea4..e312bb2899e 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_smallest_attribute(LDAP *ldap_struct, LDAPMessage *entry, + const char *attribute, + TALLOC_CTX *mem_ctx); void talloc_autofree_ldapmsg(TALLOC_CTX *mem_ctx, LDAPMessage *result); void talloc_autofree_ldapmod(TALLOC_CTX *mem_ctx, LDAPMod **mod); const char *smbldap_talloc_dn(TALLOC_CTX *mem_ctx, LDAP *ld, diff --git a/source/lib/smbldap.c b/source/lib/smbldap.c index 7e9f1ac9158..03c657356e2 100644 --- a/source/lib/smbldap.c +++ b/source/lib/smbldap.c @@ -333,6 +333,62 @@ ATTRIB_MAP_ENTRY sidmap_attr_list[] = { return result; } + char * smbldap_talloc_smallest_attribute(LDAP *ldap_struct, LDAPMessage *entry, + const char *attribute, + TALLOC_CTX *mem_ctx) +{ + char **values; + char *result; + size_t converted_size; + int i, num_values; + + 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; + } + + num_values = ldap_count_values(values); + + for (i=1; i