s3-idmap: convert most idmap_cache callers to unixid API
authorAndrew Bartlett <abartlet@samba.org>
Fri, 23 Mar 2012 10:11:33 +0000 (21:11 +1100)
committerMichael Adam <obnox@samba.org>
Wed, 2 May 2012 11:18:03 +0000 (13:18 +0200)
This will eventually allow the struct unixid to be passed all the way up
and down the stack.

Andrew Bartlett

Signed-off-by: Michael Adam <obnox@samba.org>
source3/passdb/lookup_sid.c
source3/passdb/pdb_ldap.c
source3/winbindd/idmap_util.c
source3/winbindd/winbindd_sids_to_xids.c

index a72cbd098667b21c18adc691b4707a09c9946808..4ceba3cdd2d2f0d45fd6b0208e7133e11050e50a 100644 (file)
@@ -1284,16 +1284,9 @@ bool sids_to_unixids(const struct dom_sid *sids, uint32_t num_sids,
                        ids[i].id = rid;
                        continue;
                }
-               if (idmap_cache_find_sid2uid(&sids[i], &ids[i].id,
-                                            &expired)
-                   && !expired) {
-                       ids[i].type = ID_TYPE_UID;
-                       continue;
-               }
-               if (idmap_cache_find_sid2gid(&sids[i], &ids[i].id,
-                                            &expired)
-                   && !expired) {
-                       ids[i].type = ID_TYPE_GID;
+               if (idmap_cache_find_sid2unixid(&sids[i], &ids[i], &expired)
+                   && !expired)
+               {
                        continue;
                }
                ids[i].type = ID_TYPE_NOT_SPECIFIED;
index 89e05c0169c80e0c2b31306ab8a7f2b6f560c38b..1ebfa15029899ed0989d966bf4e247262576ace0 100644 (file)
@@ -1008,6 +1008,7 @@ static bool init_sam_from_ldap(struct ldapsam_privates *ldap_state,
                bool have_gid = false;
                struct dom_sid mapped_gsid;
                const struct dom_sid *primary_gsid;
+               struct unixid id;
 
                ZERO_STRUCT(unix_pw);
 
@@ -1071,14 +1072,18 @@ static bool init_sam_from_ldap(struct ldapsam_privates *ldap_state,
                        goto fn_exit;
                }
 
-               idmap_cache_set_sid2uid(pdb_get_user_sid(sampass),
-                                       sampass->unix_pw->pw_uid);
+               id.id = sampass->unix_pw->pw_uid;
+               id.type = ID_TYPE_UID;
+
+               idmap_cache_set_sid2unixid(pdb_get_user_sid(sampass), &id);
 
                gid_to_sid(&mapped_gsid, sampass->unix_pw->pw_gid);
                primary_gsid = pdb_get_group_sid(sampass);
                if (primary_gsid && dom_sid_equal(primary_gsid, &mapped_gsid)) {
-                       idmap_cache_set_sid2gid(primary_gsid,
-                                               sampass->unix_pw->pw_gid);
+                       id.id = sampass->unix_pw->pw_gid;
+                       id.type = ID_TYPE_GID;
+
+                       idmap_cache_set_sid2unixid(primary_gsid, &id);
                }
        }
 
@@ -2476,7 +2481,11 @@ for gidNumber(%lu)\n",(unsigned long)map->gid));
        }
 
        if (lp_parm_bool(-1, "ldapsam", "trusted", false)) {
-               idmap_cache_set_sid2gid(&map->sid, map->gid);
+               struct unixid id;
+               id.id = map->gid;
+               id.type = ID_TYPE_GID;
+
+               idmap_cache_set_sid2unixid(&map->sid, &id);
        }
 
        TALLOC_FREE(ctx);
@@ -5035,7 +5044,7 @@ static bool ldapsam_sid_to_id(struct pdb_methods *methods,
 
                id->id = strtoul(gid_str, NULL, 10);
                id->type = ID_TYPE_GID;
-               idmap_cache_set_sid2gid(sid, id->id);
+               idmap_cache_set_sid2unixid(sid, id);
                ret = True;
                goto done;
        }
@@ -5052,7 +5061,7 @@ static bool ldapsam_sid_to_id(struct pdb_methods *methods,
 
        id->id = strtoul(value, NULL, 10);
        id->type = ID_TYPE_UID;
-       idmap_cache_set_sid2uid(sid, id->id);
+       idmap_cache_set_sid2unixid(sid, id);
 
        ret = True;
  done:
@@ -5078,6 +5087,7 @@ static bool ldapsam_uid_to_sid(struct pdb_methods *methods, uid_t uid,
        struct dom_sid user_sid;
        int rc;
        TALLOC_CTX *tmp_ctx = talloc_stackframe();
+       struct unixid id;
 
        filter = talloc_asprintf(tmp_ctx,
                                 "(&(uidNumber=%u)"
@@ -5122,7 +5132,10 @@ static bool ldapsam_uid_to_sid(struct pdb_methods *methods, uid_t uid,
 
        sid_copy(sid, &user_sid);
 
-       idmap_cache_set_sid2uid(sid, uid);
+       id.id = uid;
+       id.type = ID_TYPE_UID;
+
+       idmap_cache_set_sid2unixid(sid, &id);
 
        ret = true;
 
@@ -5149,6 +5162,7 @@ static bool ldapsam_gid_to_sid(struct pdb_methods *methods, gid_t gid,
        struct dom_sid group_sid;
        int rc;
        TALLOC_CTX *tmp_ctx = talloc_stackframe();
+       struct unixid id;
 
        filter = talloc_asprintf(tmp_ctx,
                                 "(&(gidNumber=%u)"
@@ -5191,7 +5205,10 @@ static bool ldapsam_gid_to_sid(struct pdb_methods *methods, gid_t gid,
 
        sid_copy(sid, &group_sid);
 
-       idmap_cache_set_sid2gid(sid, gid);
+       id.id = gid;
+       id.type = ID_TYPE_GID;
+
+       idmap_cache_set_sid2unixid(sid, &id);
 
        ret = true;
 
index 2ddf576dc83e2b2481465a6e06f5d3959c537af7..8e9d468dc5875a4a9be5201199159945db59dcc1 100644 (file)
@@ -74,15 +74,18 @@ backend:
        if (map.status != ID_MAPPED) {
                if (winbindd_use_idmap_cache()) {
                        struct dom_sid null_sid;
+                       struct unixid id;
+                       id.type = ID_TYPE_UID;
+                       id.id = uid;
                        ZERO_STRUCT(null_sid);
-                       idmap_cache_set_sid2uid(&null_sid, uid);
+                       idmap_cache_set_sid2unixid(&null_sid, &id);
                }
                DEBUG(10, ("uid [%lu] not mapped\n", (unsigned long)uid));
                return NT_STATUS_NONE_MAPPED;
        }
 
        if (winbindd_use_idmap_cache()) {
-               idmap_cache_set_sid2uid(sid, uid);
+               idmap_cache_set_sid2unixid(sid, &map.xid);
        }
 
        return NT_STATUS_OK;
@@ -134,15 +137,18 @@ backend:
        if (map.status != ID_MAPPED) {
                if (winbindd_use_idmap_cache()) {
                        struct dom_sid null_sid;
+                       struct unixid id;
+                       id.type = ID_TYPE_GID;
+                       id.id = gid;
                        ZERO_STRUCT(null_sid);
-                       idmap_cache_set_sid2gid(&null_sid, gid);
+                       idmap_cache_set_sid2unixid(&null_sid, &id);
                }
                DEBUG(10, ("gid [%lu] not mapped\n", (unsigned long)gid));
                return NT_STATUS_NONE_MAPPED;
        }
 
        if (winbindd_use_idmap_cache()) {
-               idmap_cache_set_sid2gid(sid, gid);
+               idmap_cache_set_sid2unixid(sid, &map.xid);
        }
 
        return NT_STATUS_OK;
@@ -217,7 +223,7 @@ backend:
 
        *uid = (uid_t)map.xid.id;
        if (winbindd_use_idmap_cache()) {
-               idmap_cache_set_sid2uid(sid, *uid);
+               idmap_cache_set_sid2unixid(sid, &map.xid);
        }
        return NT_STATUS_OK;
 }
@@ -291,7 +297,7 @@ backend:
 
        *gid = map.xid.id;
        if (winbindd_use_idmap_cache()) {
-               idmap_cache_set_sid2gid(sid, *gid);
+               idmap_cache_set_sid2unixid(sid, &map.xid);
        }
        return NT_STATUS_OK;
 }
index 2df5f54e750e2d53e215c9c9a13df3218b3c3e33..8201739a96a44725370093c103d48593243bce16 100644 (file)
@@ -123,34 +123,18 @@ struct tevent_req *winbindd_sids_to_xids_send(TALLOC_CTX *mem_ctx,
 static bool winbindd_sids_to_xids_in_cache(struct dom_sid *sid,
                                           struct id_map *map)
 {
-       uid_t uid;
-       gid_t gid;
+       struct unixid id;
        bool expired;
 
        if (!winbindd_use_idmap_cache()) {
                return false;
        }
-       /*
-        * SIDS_TO_XIDS is primarily used to resolve the user's group
-        * sids. So we check groups before users.
-        */
-       if (idmap_cache_find_sid2gid(sid, &gid, &expired)) {
+       if (idmap_cache_find_sid2unixid(sid, &id, &expired)) {
                if (expired && is_domain_offline(find_our_domain())) {
                        return false;
                }
                map->sid = sid;
-               map->xid.id = gid;
-               map->xid.type = ID_TYPE_GID;
-               map->status = ID_MAPPED;
-               return true;
-       }
-       if (idmap_cache_find_sid2uid(sid, &uid, &expired)) {
-               if (expired && is_domain_online(find_our_domain())) {
-                       return false;
-               }
-               map->sid = sid;
-               map->xid.id = uid;
-               map->xid.type = ID_TYPE_UID;
+               map->xid = id;
                map->status = ID_MAPPED;
                return true;
        }
@@ -267,30 +251,27 @@ NTSTATUS winbindd_sids_to_xids_recv(struct tevent_req *req,
                                type = 'G';
                        }
                } else {
-
+                       struct unixid id;
                        unix_id = state->ids.ids[num_non_cached].unix_id;
                        if (unix_id == -1) {
                                found = false;
                        }
 
-                       switch(state->ids.ids[num_non_cached].type) {
+                       id.id = unix_id;
+                       id.type = state->ids.ids[num_non_cached].type;
+                       idmap_cache_set_sid2unixid(
+                               &state->non_cached[num_non_cached],
+                               &id);
+
+                       switch (id.type) {
                        case ID_TYPE_UID:
                                type = 'U';
-                               idmap_cache_set_sid2uid(
-                                       &state->non_cached[num_non_cached],
-                                       unix_id);
                                break;
                        case ID_TYPE_GID:
                                type = 'G';
-                               idmap_cache_set_sid2gid(
-                                       &state->non_cached[num_non_cached],
-                                       unix_id);
                                break;
                        case ID_TYPE_BOTH:
                                type = 'B';
-                               idmap_cache_set_sid2both(
-                                       &state->non_cached[num_non_cached],
-                                       unix_id);
                                break;
                        default:
                                found = false;