r16865: This is a proposal to fix bug 3915. Before sending patches around, this is
authorVolker Lendecke <vlendec@samba.org>
Fri, 7 Jul 2006 18:53:19 +0000 (18:53 +0000)
committerGerald (Jerry) Carter <jerry@samba.org>
Wed, 10 Oct 2007 16:19:12 +0000 (11:19 -0500)
what svn is for.

The idea is that we fall back to a pure unix user with S-1-22 SIDs in the
token in case anything weird is going on with the 'force user'.

Volker
(This used to be commit 9ec5ccfe851ac8a1f88b88c8c8461a5cf75b4c57)

source3/auth/auth_util.c
source3/passdb/lookup_sid.c
source3/passdb/util_unixsids.c

index 1c629bca82f34de6044098a7104182f28b55535b..493d7393d072eb0ab046f94c77cc79b67d3e943f 100644 (file)
@@ -1081,14 +1081,13 @@ NTSTATUS create_token_from_username(TALLOC_CTX *mem_ctx, const char *username,
                if (!pdb_getsampwsid(sam_acct, &user_sid)) {
                        DEBUG(1, ("pdb_getsampwsid(%s) for user %s failed\n",
                                  sid_string_static(&user_sid), username));
-                       result = NT_STATUS_NO_SUCH_USER;
-                       goto done;
+                       DEBUGADD(1, ("Fall back to unix user %s\n", username));
+                       goto unix_user;
                }
 
                gr_sid = pdb_get_group_sid(sam_acct);
                if (!gr_sid) {
-                       result = NT_STATUS_NO_MEMORY;
-                       goto done;
+                       goto unix_user;
                }
 
                sid_copy(&primary_group_sid, gr_sid);
@@ -1096,7 +1095,8 @@ NTSTATUS create_token_from_username(TALLOC_CTX *mem_ctx, const char *username,
                if (!sid_to_gid(&primary_group_sid, gid)) {
                        DEBUG(1, ("sid_to_gid(%s) failed\n",
                                  sid_string_static(&primary_group_sid)));
-                       goto done;
+                       DEBUGADD(1, ("Fall back to unix user %s\n", username));
+                       goto unix_user;
                }
 
                result = pdb_enum_group_memberships(tmp_ctx, sam_acct,
@@ -1105,7 +1105,8 @@ NTSTATUS create_token_from_username(TALLOC_CTX *mem_ctx, const char *username,
                if (!NT_STATUS_IS_OK(result)) {
                        DEBUG(10, ("enum_group_memberships failed for %s\n",
                                   username));
-                       goto done;
+                       DEBUGADD(1, ("Fall back to unix user %s\n", username));
+                       goto unix_user;
                }
 
                *found_username = talloc_strdup(mem_ctx,
@@ -1119,6 +1120,16 @@ NTSTATUS create_token_from_username(TALLOC_CTX *mem_ctx, const char *username,
                struct passwd *pass;
                size_t i;
 
+               /*
+                * This goto target is used as a fallback for the passdb
+                * case. The concrete bug report is when passdb gave us an
+                * unmapped gid.
+                */
+
+       unix_user:
+
+               uid_to_unix_users_sid(*uid, &user_sid);
+
                pass = getpwuid_alloc(tmp_ctx, *uid);
                if (pass == NULL) {
                        DEBUG(1, ("getpwuid(%d) for user %s failed\n",
index 38ca51eaa866c57eb3b0fe14b818ed16f8af18e6..29b83e4faa22cba481d440607bd91c091e251f72 100644 (file)
@@ -1074,8 +1074,7 @@ void uid_to_sid(DOM_SID *psid, uid_t uid)
                sid_append_rid(psid, algorithmic_pdb_uid_to_user_rid(uid));
                goto done;
        } else {
-               sid_copy(psid, &global_sid_Unix_Users);
-               sid_append_rid(psid, uid);
+               uid_to_unix_users_sid(psid, uid);
                goto done;
        }
 
index 2a4818e3aec95f0ccc5c108b7ec2970e039d5d65..d3f0999d6ac09496b65f7b5cb17ce351b0b7ec7f 100644 (file)
@@ -36,6 +36,12 @@ BOOL sid_check_is_in_unix_users(const DOM_SID *sid)
        return sid_check_is_unix_users(&dom_sid);
 }
 
+BOOL uid_to_unix_users_sid(uid_t uid, DOM_SID *sid)
+{
+       sid_copy(sid, &global_sid_Unix_Users);
+       return sid_append_rid(sid, uid);
+}
+
 const char *unix_users_domain_name(void)
 {
        return "Unix User";