s3-passdb: Use struct unixid in sids_to_unix_ids
authorAndrew Bartlett <abartlet@samba.org>
Fri, 23 Mar 2012 06:30:34 +0000 (17:30 +1100)
committerMichael Adam <obnox@samba.org>
Wed, 2 May 2012 10:45:30 +0000 (12:45 +0200)
This avoids the union in the struct wbcUnixId and moves us to using only struct unixid
internally.

Andrew Bartlett

Signed-off-by: Michael Adam <obnox@samba.org>
source3/auth/auth_util.c
source3/passdb/lookup_sid.c
source3/passdb/lookup_sid.h

index 4f6ebfa4a4afb4a78740d564148b70f58012c32b..07ed9c1077001ea6063742ff75b300aee1a61e7b 100644 (file)
@@ -32,6 +32,7 @@
 #include "passdb.h"
 #include "../librpc/gen_ndr/ndr_auth.h"
 #include "../auth/auth_sam_reply.h"
+#include "../librpc/gen_ndr/idmap.h"
 
 #undef DBGC_CLASS
 #define DBGC_CLASS DBGC_AUTH
@@ -465,7 +466,7 @@ NTSTATUS create_local_token(TALLOC_CTX *mem_ctx,
        size_t i;
        struct dom_sid tmp_sid;
        struct auth_session_info *session_info;
-       struct wbcUnixId *ids;
+       struct unixid *ids;
        fstring tmp;
 
        /* Ensure we can't possible take a code path leading to a
@@ -593,7 +594,7 @@ NTSTATUS create_local_token(TALLOC_CTX *mem_ctx,
 
        t = session_info->security_token;
 
-       ids = talloc_array(talloc_tos(), struct wbcUnixId,
+       ids = talloc_array(talloc_tos(), struct unixid,
                           t->num_sids);
        if (ids == NULL) {
                return NT_STATUS_NO_MEMORY;
@@ -606,18 +607,18 @@ NTSTATUS create_local_token(TALLOC_CTX *mem_ctx,
 
        for (i=0; i<t->num_sids; i++) {
 
-               if (i == 0 && ids[i].type != WBC_ID_TYPE_BOTH) {
+               if (i == 0 && ids[i].type != ID_TYPE_BOTH) {
                        continue;
                }
 
-               if (ids[i].type != WBC_ID_TYPE_GID &&
-                   ids[i].type != WBC_ID_TYPE_BOTH) {
+               if (ids[i].type != ID_TYPE_GID &&
+                   ids[i].type != ID_TYPE_BOTH) {
                        DEBUG(10, ("Could not convert SID %s to gid, "
                                   "ignoring it\n",
                                   sid_string_dbg(&t->sids[i])));
                        continue;
                }
-               if (!add_gid_to_array_unique(session_info, ids[i].id.gid,
+               if (!add_gid_to_array_unique(session_info, ids[i].id,
                                             &session_info->unix_token->groups,
                                             &session_info->unix_token->ngroups)) {
                        return NT_STATUS_NO_MEMORY;
index a70d31791f774305970ee3674e576c8a4c06dec4..a4af67771430f8fec3ceb59d37909f7f60e02604 100644 (file)
@@ -1253,7 +1253,7 @@ void gid_to_sid(struct dom_sid *psid, gid_t gid)
 }
 
 bool sids_to_unix_ids(const struct dom_sid *sids, uint32_t num_sids,
-                     struct wbcUnixId *ids)
+                     struct unixid *ids)
 {
        struct wbcDomainSid *wbc_sids = NULL;
        struct wbcUnixId *wbc_ids = NULL;
@@ -1274,29 +1274,29 @@ bool sids_to_unix_ids(const struct dom_sid *sids, uint32_t num_sids,
 
                if (sid_peek_check_rid(&global_sid_Unix_Users,
                                       &sids[i], &rid)) {
-                       ids[i].type = WBC_ID_TYPE_UID;
-                       ids[i].id.uid = rid;
+                       ids[i].type = ID_TYPE_UID;
+                       ids[i].id = rid;
                        continue;
                }
                if (sid_peek_check_rid(&global_sid_Unix_Groups,
                                       &sids[i], &rid)) {
-                       ids[i].type = WBC_ID_TYPE_GID;
-                       ids[i].id.gid = rid;
+                       ids[i].type = ID_TYPE_GID;
+                       ids[i].id = rid;
                        continue;
                }
-               if (idmap_cache_find_sid2uid(&sids[i], &ids[i].id.uid,
+               if (idmap_cache_find_sid2uid(&sids[i], &ids[i].id,
                                             &expired)
                    && !expired) {
-                       ids[i].type = WBC_ID_TYPE_UID;
+                       ids[i].type = ID_TYPE_UID;
                        continue;
                }
-               if (idmap_cache_find_sid2gid(&sids[i], &ids[i].id.gid,
+               if (idmap_cache_find_sid2gid(&sids[i], &ids[i].id,
                                             &expired)
                    && !expired) {
-                       ids[i].type = WBC_ID_TYPE_GID;
+                       ids[i].type = ID_TYPE_GID;
                        continue;
                }
-               ids[i].type = WBC_ID_TYPE_NOT_SPECIFIED;
+               ids[i].type = ID_TYPE_NOT_SPECIFIED;
                memcpy(&wbc_sids[num_not_cached], &sids[i],
                       ndr_size_dom_sid(&sids[i], 0));
                num_not_cached += 1;
@@ -1320,22 +1320,36 @@ bool sids_to_unix_ids(const struct dom_sid *sids, uint32_t num_sids,
        num_not_cached = 0;
 
        for (i=0; i<num_sids; i++) {
-               if (ids[i].type == WBC_ID_TYPE_NOT_SPECIFIED) {
-                       ids[i] = wbc_ids[num_not_cached];
+               if (ids[i].type == ID_TYPE_NOT_SPECIFIED) {
+                       switch (wbc_ids[num_not_cached].type) {
+                       case ID_TYPE_UID:
+                               ids[i].type = WBC_ID_TYPE_UID;
+                               ids[i].id = wbc_ids[num_not_cached].id.uid;
+                               break;
+                       case ID_TYPE_GID:
+                               ids[i].type = WBC_ID_TYPE_GID;
+                               ids[i].id = wbc_ids[num_not_cached].id.gid;
+                               break;
+                       default:
+                               /* The types match, and wbcUnixId -> id is a union anyway */
+                               ids[i].type = wbc_ids[num_not_cached].type;
+                               ids[i].id = wbc_ids[num_not_cached].id.gid;
+                               break;
+                       }
                        num_not_cached += 1;
                }
        }
 
        for (i=0; i<num_sids; i++) {
-               if (ids[i].type != WBC_ID_TYPE_NOT_SPECIFIED) {
+               if (ids[i].type != ID_TYPE_NOT_SPECIFIED) {
                        continue;
                }
-               if (legacy_sid_to_gid(&sids[i], &ids[i].id.gid)) {
-                       ids[i].type = WBC_ID_TYPE_GID;
+               if (legacy_sid_to_gid(&sids[i], &ids[i].id)) {
+                       ids[i].type = ID_TYPE_GID;
                        continue;
                }
-               if (legacy_sid_to_uid(&sids[i], &ids[i].id.uid)) {
-                       ids[i].type = WBC_ID_TYPE_UID;
+               if (legacy_sid_to_uid(&sids[i], &ids[i].id)) {
+                       ids[i].type = ID_TYPE_UID;
                        continue;
                }
        }
index 65444c39a653ef8a0015863b4397a95938d64fe8..068e499664809fb39cbaf75ef375fa41d77a637d 100644 (file)
@@ -87,7 +87,7 @@ bool sid_to_uid(const struct dom_sid *psid, uid_t *puid);
 bool sid_to_gid(const struct dom_sid *psid, gid_t *pgid);
 struct wbcUnixId;
 bool sids_to_unix_ids(const struct dom_sid *sids, uint32_t num_sids,
-                     struct wbcUnixId *ids);
+                     struct unixid *ids);
 NTSTATUS get_primary_group_sid(TALLOC_CTX *mem_ctx,
                                const char *username,
                                struct passwd **_pwd,