smbd: uid: Don't crash if 'force group' is added to an existing share connection.
authorJeremy Allison <jra@samba.org>
Fri, 18 Jan 2019 22:24:30 +0000 (14:24 -0800)
committerKarolin Seeger <kseeger@samba.org>
Thu, 21 Feb 2019 11:31:46 +0000 (12:31 +0100)
smbd could crash if "force group" is added to a
share definition whilst an existing connection
to that share exists. In that case, don't change
the existing credentials for force group, only
do so for new connections.

Remove knownfail from regression test.

BUG: https://bugzilla.samba.org/show_bug.cgi?id=13690

Signed-off-by: Jeremy Allison <jra@samba.org>
Reviewed-by: Ralph Boehme <slow@samba.org>
Autobuild-User(master): Ralph Böhme <slow@samba.org>
Autobuild-Date(master): Fri Jan 25 16:31:27 CET 2019 on sn-devel-144

(cherry picked from commit e37f9956c1f2416408bad048a4618f6366086b6a)

selftest/knownfail
source3/smbd/uid.c

index ca2f79d768c8b59296366a5c1b9228e7adfdd9dd..baf3d57a31a0f58e565018ef8709adc3399b42ac 100644 (file)
 # Disabling NTLM means you can't use samr to change the password
 ^samba.tests.ntlmdisabled.python\(ktest\).ntlmdisabled.NtlmDisabledTests.test_samr_change_password\(ktest\)
 ^samba.tests.ntlmdisabled.python\(ad_dc_no_ntlm\).ntlmdisabled.NtlmDisabledTests.test_ntlm_connection\(ad_dc_no_ntlm\)
-# BUG:https://bugzilla.samba.org/show_bug.cgi?id=13690
-^samba3.blackbox.force_group_change.*
index 9d5321cf4ccc7772f81158a3356e6a8c0bd7c41d..ced2d450f8e79c5145dce3773ec52fbc488cf101 100644 (file)
@@ -296,6 +296,7 @@ static bool change_to_user_internal(connection_struct *conn,
        int snum;
        gid_t gid;
        uid_t uid;
+       const char *force_group_name;
        char group_c;
        int num_groups = 0;
        gid_t *group_list = NULL;
@@ -335,9 +336,39 @@ static bool change_to_user_internal(connection_struct *conn,
         * See if we should force group for this service. If so this overrides
         * any group set in the force user code.
         */
-       if((group_c = *lp_force_group(talloc_tos(), snum))) {
+       force_group_name = lp_force_group(talloc_tos(), snum);
+       group_c = *force_group_name;
 
-               SMB_ASSERT(conn->force_group_gid != (gid_t)-1);
+       if ((group_c != '\0') && (conn->force_group_gid == (gid_t)-1)) {
+               /*
+                * This can happen if "force group" is added to a
+                * share definition whilst an existing connection
+                * to that share exists. In that case, don't change
+                * the existing credentials for force group, only
+                * do so for new connections.
+                *
+                * BUG: https://bugzilla.samba.org/show_bug.cgi?id=13690
+                */
+               DBG_INFO("Not forcing group %s on existing connection to "
+                       "share %s for SMB user %s (unix user %s)\n",
+                       force_group_name,
+                       lp_const_servicename(snum),
+                       session_info->unix_info->sanitized_username,
+                       session_info->unix_info->unix_name);
+       }
+
+       if((group_c != '\0') && (conn->force_group_gid != (gid_t)-1)) {
+               /*
+                * Only force group for connections where
+                * conn->force_group_gid has already been set
+                * to the correct value (i.e. the connection
+                * happened after the 'force group' definition
+                * was added to the share definition. Connections
+                * that were made before force group was added
+                * should stay with their existing credentials.
+                *
+                * BUG: https://bugzilla.samba.org/show_bug.cgi?id=13690
+                */
 
                if (group_c == '+') {
                        int i;