Add smbldap_talloc_single_blob()
authorVolker Lendecke <vl@samba.org>
Fri, 29 May 2009 19:27:53 +0000 (21:27 +0200)
committerVolker Lendecke <vl@samba.org>
Fri, 29 May 2009 19:29:24 +0000 (21:29 +0200)
source3/include/smbldap.h
source3/lib/smbldap.c

index c28d43d53ba9ebfd26c38513b610710618cb2161..7135c0be79cddeadbd000e510f32946f7523f2cc 100644 (file)
@@ -214,6 +214,9 @@ char * smbldap_talloc_single_attribute(LDAP *ldap_struct, LDAPMessage *entry,
 char * smbldap_talloc_smallest_attribute(LDAP *ldap_struct, LDAPMessage *entry,
                                         const char *attribute,
                                         TALLOC_CTX *mem_ctx);
+bool smbldap_talloc_single_blob(TALLOC_CTX *mem_ctx, LDAP *ld,
+                               LDAPMessage *msg, const char *attrib,
+                               DATA_BLOB *blob);
 bool smbldap_pull_sid(LDAP *ld, LDAPMessage *msg, const char *attrib,
                      struct dom_sid *sid);
 void talloc_autofree_ldapmsg(TALLOC_CTX *mem_ctx, LDAPMessage *result);
index b6921c329c0301af3edb51795d4fbf0f19271b6a..b3b5fa758230aa6323e7c72394f7f42b0c4d18ac 100644 (file)
@@ -389,23 +389,42 @@ ATTRIB_MAP_ENTRY sidmap_attr_list[] = {
        return result;
 }
 
- bool smbldap_pull_sid(LDAP *ld, LDAPMessage *msg, const char *attrib,
-                      struct dom_sid *sid)
+ bool smbldap_talloc_single_blob(TALLOC_CTX *mem_ctx, LDAP *ld,
+                                LDAPMessage *msg, const char *attrib,
+                                DATA_BLOB *blob)
 {
        struct berval **values;
-       bool ret = False;
 
        values = ldap_get_values_len(ld, msg, attrib);
-
        if (!values) {
                return false;
        }
 
-       if (values[0] != NULL) {
-               ret = sid_parse(values[0]->bv_val, values[0]->bv_len, sid);
+       if (ldap_count_values_len(values) != 1) {
+               DEBUG(10, ("Expected one value for %s, got %d\n", attrib,
+                          ldap_count_values_len(values)));
+               return false;
        }
 
+       *blob = data_blob_talloc(mem_ctx, values[0]->bv_val,
+                                values[0]->bv_len);
        ldap_value_free_len(values);
+
+       return (blob->data != NULL);
+}
+
+ bool smbldap_pull_sid(LDAP *ld, LDAPMessage *msg, const char *attrib,
+                      struct dom_sid *sid)
+{
+       DATA_BLOB blob;
+       bool ret;
+
+       if (!smbldap_talloc_single_blob(talloc_tos(), ld, msg, attrib,
+                                       &blob)) {
+               return false;
+       }
+       ret = sid_parse((char *)blob.data, blob.length, sid);
+       TALLOC_FREE(blob.data);
        return ret;
 }