The branch, master has been updated
       via  420be02 s3: Read uidNumber/gidNumber in pdb_ads_sid_to_id
       via  b0667f7 s3: Remove some unused code
       via  a4d7b3a s3: "hex_encode" does the same as "binary_string"
      from  7c83f69 s4-rpc: added dcesrv_call_account_name()

http://gitweb.samba.org/?p=samba.git;a=shortlog;h=master


- Log -----------------------------------------------------------------
commit 420be02a60ee989f27a0eebea575fd64f98742fe
Author: Volker Lendecke <[email protected]>
Date:   Mon Mar 14 21:47:18 2011 +0100

    s3: Read uidNumber/gidNumber in pdb_ads_sid_to_id
    
    Question: How shall we allocate those? Something like the rid allocator?
    
    Autobuild-User: Volker Lendecke <[email protected]>
    Autobuild-Date: Tue Mar 15 09:59:55 CET 2011 on sn-devel-104

commit b0667f7fda5d8f7fd110645f885c5503281d67f8
Author: Volker Lendecke <[email protected]>
Date:   Mon Mar 14 08:10:13 2011 +0100

    s3: Remove some unused code

commit a4d7b3a1dfddc95c1825588cddaee5b4039fa5e2
Author: Volker Lendecke <[email protected]>
Date:   Mon Mar 14 08:09:21 2011 +0100

    s3: "hex_encode" does the same as "binary_string"

-----------------------------------------------------------------------

Summary of changes:
 source3/include/proto.h  |    2 -
 source3/lib/util_sid.c   |    2 +-
 source3/lib/util_str.c   |   41 -------------------------
 source3/passdb/pdb_ads.c |   74 ++++++++++++++++++++++++++++------------------
 4 files changed, 46 insertions(+), 73 deletions(-)


Changeset truncated at 500 lines:

diff --git a/source3/include/proto.h b/source3/include/proto.h
index 199ee48..2cb21f5 100644
--- a/source3/include/proto.h
+++ b/source3/include/proto.h
@@ -1435,8 +1435,6 @@ size_t strlen_m_ext_term(const char *s, const charset_t 
src_charset,
 size_t strlen_m(const char *s);
 size_t strlen_m_term(const char *s);
 size_t strlen_m_term_null(const char *s);
-char *binary_string_rfc2254(TALLOC_CTX *mem_ctx, const uint8_t *buf, int len);
-char *binary_string(char *buf, int len);
 int fstr_sprintf(fstring s, const char *fmt, ...);
 bool str_list_sub_basic( char **list, const char *smb_name,
                         const char *domain_name );
diff --git a/source3/lib/util_sid.c b/source3/lib/util_sid.c
index f6210c1..ef46a38 100644
--- a/source3/lib/util_sid.c
+++ b/source3/lib/util_sid.c
@@ -121,7 +121,7 @@ char *sid_binstring_hex(const struct dom_sid *sid)
        if (!buf)
                return NULL;
        sid_linearize(buf, len, sid);
-       s = binary_string(buf, len);
+       hex_encode(buf, len, &s);
        free(buf);
        return s;
 }
diff --git a/source3/lib/util_str.c b/source3/lib/util_str.c
index b26bde8..6a17297 100644
--- a/source3/lib/util_str.c
+++ b/source3/lib/util_str.c
@@ -1576,47 +1576,6 @@ size_t strlen_m_term_null(const char *s)
 
        return len+1;
 }
-/**
- Return a RFC2254 binary string representation of a buffer.
- Used in LDAP filters.
- Caller must free.
-**/
-
-char *binary_string_rfc2254(TALLOC_CTX *mem_ctx, const uint8_t *buf, int len)
-{
-       char *s;
-       int i, j;
-       const char *hex = "0123456789ABCDEF";
-       s = talloc_array(mem_ctx, char, len * 3 + 1);
-       if (s == NULL) {
-               return NULL;
-       }
-       for (j=i=0;i<len;i++) {
-               s[j] = '\\';
-               s[j+1] = hex[((unsigned char)buf[i]) >> 4];
-               s[j+2] = hex[((unsigned char)buf[i]) & 0xF];
-               j += 3;
-       }
-       s[j] = 0;
-       return s;
-}
-
-char *binary_string(char *buf, int len)
-{
-       char *s;
-       int i, j;
-       const char *hex = "0123456789ABCDEF";
-       s = (char *)SMB_MALLOC(len * 2 + 1);
-       if (!s)
-               return NULL;
-       for (j=i=0;i<len;i++) {
-               s[j]   = hex[((unsigned char)buf[i]) >> 4];
-               s[j+1] = hex[((unsigned char)buf[i]) & 0xF];
-               j += 2;
-       }
-       s[j] = 0;
-       return s;
-}
 
 /**
  Just a typesafety wrapper for snprintf into a fstring.
diff --git a/source3/passdb/pdb_ads.c b/source3/passdb/pdb_ads.c
index ba2193b..5afad1c 100644
--- a/source3/passdb/pdb_ads.c
+++ b/source3/passdb/pdb_ads.c
@@ -2203,46 +2203,62 @@ static bool pdb_ads_sid_to_id(struct pdb_methods *m, 
const struct dom_sid *sid,
 {
        struct pdb_ads_state *state = talloc_get_type_abort(
                m->private_data, struct pdb_ads_state);
+       const char *attrs[4] = { "objectClass", "samAccountType",
+                                "uidNumber", "gidNumber" };
        struct tldap_message **msg;
-       char *sidstr;
-       uint32_t rid;
+       char *sidstr, *base;
+       uint32_t atype;
        int rc;
+       bool ret = false;
 
-       /*
-        * This is a big, big hack: Just hard-code the rid as uid/gid.
-        */
-
-       sid_peek_rid(sid, &rid);
-
-       sidstr = ldap_encode_ndr_dom_sid(talloc_tos(), sid);
+       sidstr = sid_binstring_hex(sid);
        if (sidstr == NULL) {
                return false;
        }
+       base = talloc_asprintf(talloc_tos(), "<SID=%s>", sidstr);
+       SAFE_FREE(sidstr);
 
        rc = pdb_ads_search_fmt(
-               state, state->domaindn, TLDAP_SCOPE_SUB,
-               NULL, 0, 0, talloc_tos(), &msg,
-               "(&(objectsid=%s)(objectclass=user))", sidstr);
-       if ((rc == TLDAP_SUCCESS) && (talloc_array_length(msg) > 0)) {
-               id->uid = rid;
-               *type = SID_NAME_USER;
-               TALLOC_FREE(sidstr);
-               return true;
-       }
+               state, base, TLDAP_SCOPE_BASE,
+               attrs, ARRAY_SIZE(attrs), 0, talloc_tos(), &msg,
+               "(objectclass=*)");
+       TALLOC_FREE(base);
 
-       rc = pdb_ads_search_fmt(
-               state, state->domaindn, TLDAP_SCOPE_SUB,
-               NULL, 0, 0, talloc_tos(), &msg,
-               "(&(objectsid=%s)(objectclass=group))", sidstr);
-       if ((rc == TLDAP_SUCCESS) && (talloc_array_length(msg) > 0)) {
-               id->gid = rid;
+       if (rc != TLDAP_SUCCESS) {
+               DEBUG(10, ("pdb_ads_search_fmt failed: %s\n",
+                          tldap_errstr(talloc_tos(), state->ld, rc)));
+               return false;
+       }
+       if (talloc_array_length(msg) != 1) {
+               DEBUG(10, ("Got %d objects, expected 1\n",
+                          talloc_array_length(msg)));
+               goto fail;
+       }
+       if (!tldap_pull_uint32(msg[0], "samAccountType", &atype)) {
+               DEBUG(10, ("samAccountType not found\n"));
+               goto fail;
+       }
+       if (atype == ATYPE_ACCOUNT) {
+               uint32_t uid;
+               *type = SID_NAME_USER;
+               if (!tldap_pull_uint32(msg[0], "uidNumber", &uid)) {
+                       DEBUG(10, ("Did not find uidNumber\n"));
+                       goto fail;
+               }
+               id->uid = uid;
+       } else {
+               uint32_t gid;
                *type = SID_NAME_DOM_GRP;
-               TALLOC_FREE(sidstr);
-               return true;
+               if (!tldap_pull_uint32(msg[0], "gidNumber", &gid)) {
+                       DEBUG(10, ("Did not find gidNumber\n"));
+                       goto fail;
+               }
+               id->gid = gid;
        }
-
-       TALLOC_FREE(sidstr);
-       return false;
+       ret = true;
+fail:
+       TALLOC_FREE(msg);
+       return ret;
 }
 
 static uint32_t pdb_ads_capabilities(struct pdb_methods *m)


-- 
Samba Shared Repository

Reply via email to