]> git.ipfire.org Git - thirdparty/samba.git/commitdiff
s3-passdb: Simplify idmap wrapper in pdb_samba4
authorAndrew Bartlett <abartlet@samba.org>
Tue, 7 Aug 2012 04:17:09 +0000 (14:17 +1000)
committerAndrew Bartlett <abartlet@samba.org>
Tue, 7 Aug 2012 04:57:33 +0000 (14:57 +1000)
The source3 consumers of this API are now quite happy to be given an answer
of ID_TYPE_BOTH, so we do not need this extra code to try and force the
answer to UID or GID.

Andrew Bartlett

source3/passdb/pdb_samba4.c

index 40827df4efa9f5fdd050de203bed8c1f926895f6..01eb4baad7a9eafe59fd02fb99b75ea842aeac82 100644 (file)
@@ -2058,67 +2058,26 @@ static bool pdb_samba4_sid_to_id(struct pdb_methods *m, const struct dom_sid *si
                m->private_data, struct pdb_samba4_state);
        struct id_map id_map;
        struct id_map *id_maps[2];
-       const char *attrs[] = { "objectClass", NULL };
-       struct ldb_message *msg;
-       struct ldb_dn *dn;
        NTSTATUS status;
-       int rc;
        TALLOC_CTX *tmp_ctx = talloc_stackframe();
        if (!tmp_ctx) {
                return false;
        }
 
        ZERO_STRUCT(id_map);
+       id_map.sid = sid;
+       id_maps[0] = &id_map;
+       id_maps[1] = NULL;
 
-       dn = ldb_dn_new_fmt(tmp_ctx, state->ldb, "<SID=%s>", dom_sid_string(tmp_ctx, sid));
-       if (!dn || !ldb_dn_validate(dn)) {
-               talloc_free(tmp_ctx);
+       status = idmap_sids_to_xids(state->idmap_ctx, tmp_ctx, id_maps);
+       talloc_free(tmp_ctx);
+       if (!NT_STATUS_IS_OK(status)) {
                return false;
        }
-       rc = dsdb_search_one(state->ldb, tmp_ctx, &msg, dn, LDB_SCOPE_BASE, attrs, 0, NULL);
-       if (rc == LDB_ERR_NO_SUCH_OBJECT) {
-               DEBUG(5, (__location__ "SID to Unix ID lookup failed because SID %s could not be found in the samdb\n", dom_sid_string(tmp_ctx, sid)));
-               talloc_free(tmp_ctx);
-               return false;
+       if (id_map.xid.type != ID_TYPE_NOT_SPECIFIED) {
+               *id = id_map.xid;
+               return true;
        }
-       if (samdb_find_attribute(state->ldb, msg, "objectClass", "group")) {
-               id->type = ID_TYPE_GID;
-
-               ZERO_STRUCT(id_map);
-               id_map.sid = sid;
-               id_maps[0] = &id_map;
-               id_maps[1] = NULL;
-               
-               status = idmap_sids_to_xids(state->idmap_ctx, tmp_ctx, id_maps);
-               talloc_free(tmp_ctx);
-               if (!NT_STATUS_IS_OK(status)) {
-                       return false;
-               }
-               if (id_map.xid.type == ID_TYPE_GID || id_map.xid.type == ID_TYPE_BOTH) {
-                       id->id = id_map.xid.id;
-                       return true;
-               }
-               return false;
-       } else if (samdb_find_attribute(state->ldb, msg, "objectClass", "user")) {
-               id->type = ID_TYPE_UID;
-               ZERO_STRUCT(id_map);
-               id_map.sid = sid;
-               id_maps[0] = &id_map;
-               id_maps[1] = NULL;
-               
-               status = idmap_sids_to_xids(state->idmap_ctx, tmp_ctx, id_maps);
-               talloc_free(tmp_ctx);
-               if (!NT_STATUS_IS_OK(status)) {
-                       return false;
-               }
-               if (id_map.xid.type == ID_TYPE_UID || id_map.xid.type == ID_TYPE_BOTH) {
-                       id->id = id_map.xid.id;
-                       return true;
-               }
-               return false;
-       }
-       DEBUG(5, (__location__ "SID to Unix ID lookup failed because SID %s was found, but was not a user or group\n", dom_sid_string(tmp_ctx, sid)));
-       talloc_free(tmp_ctx);
        return false;
 }