The branch, master has been updated
       via  d098b6c s3: auth - tests: Add test for "force user" being a 
unix-only user, not in passdb.
       via  83066ed s3: auth: Add previously missing allocation fail check.
       via  60895e6 s3: auth: Plumb in the SamInfo3_handle_sids() utility 
function into passwd_to_SamInfo3().
       via  d20b2d3 s3: auth: Convert samu_to_SamInfo3() to use the new utility 
function.
       via  9395243 s3: auth: Add a utility function - SamInfo3_handle_sids() 
that factors out the code to handle "Unix Users" and "Unix Groups".
      from  42aee0e rwrap: Bump version to 1.1.2.

https://git.samba.org/?p=samba.git;a=shortlog;h=master


- Log -----------------------------------------------------------------
commit d098b6c877629af0f23070481deaccdf65acd249
Author: Jeremy Allison <[email protected]>
Date:   Tue Jan 13 13:49:58 2015 -0800

    s3: auth - tests: Add test for "force user" being a unix-only user, not in 
passdb.
    
    https://bugzilla.samba.org/show_bug.cgi?id=11044
    
    Signed-off-by: Jeremy Allison <[email protected]>
    Reviewed-by: Volker Lendecke <[email protected]>
    
    Autobuild-User(master): Volker Lendecke <[email protected]>
    Autobuild-Date(master): Wed Jan 14 08:46:08 CET 2015 on sn-devel-104

commit 83066ed539658a9fa6deb897b15b20a0624227fe
Author: Jeremy Allison <[email protected]>
Date:   Tue Jan 13 13:49:36 2015 -0800

    s3: auth: Add previously missing allocation fail check.
    
    Signed-off-by: Jeremy Allison <[email protected]>
    Reviewed-by: Volker Lendecke <[email protected]>

commit 60895e62fe21e41cf4a09ec8a92239b8f015b450
Author: Jeremy Allison <[email protected]>
Date:   Tue Jan 13 13:45:16 2015 -0800

    s3: auth: Plumb in the SamInfo3_handle_sids() utility function into 
passwd_to_SamInfo3().
    
    Core fix for:
    
    https://bugzilla.samba.org/show_bug.cgi?id=11044
    
    Based on code from Michael Zeis <[email protected]>
    
    Signed-off-by: Jeremy Allison <[email protected]>
    Reviewed-by: Volker Lendecke <[email protected]>

commit d20b2d397205c1ab85a43f54bc95360a732265f3
Author: Jeremy Allison <[email protected]>
Date:   Tue Jan 13 13:39:21 2015 -0800

    s3: auth: Convert samu_to_SamInfo3() to use the new utility function.
    
    Based on code from Michael Zeis <[email protected]>
    
    https://bugzilla.samba.org/show_bug.cgi?id=11044
    
    Signed-off-by: Jeremy Allison <[email protected]>
    Reviewed-by: Volker Lendecke <[email protected]>

commit 9395243890aff5bb2166e18e33492afb28850097
Author: Jeremy Allison <[email protected]>
Date:   Tue Jan 13 13:35:56 2015 -0800

    s3: auth: Add a utility function - SamInfo3_handle_sids() that factors out 
the code to handle "Unix Users" and "Unix Groups".
    
    Based on code from Michael Zeis <[email protected]>
    
    https://bugzilla.samba.org/show_bug.cgi?id=11044
    
    Signed-off-by: Jeremy Allison <[email protected]>
    Reviewed-by: Volker Lendecke <[email protected]>

-----------------------------------------------------------------------

Summary of changes:
 selftest/target/Samba3.pm                   |   4 +
 source3/auth/auth_util.c                    |   3 +-
 source3/auth/proto.h                        |   3 +-
 source3/auth/server_info.c                  | 156 +++++++++++++++++-----------
 source3/script/tests/test_smbclient_auth.sh |   1 +
 5 files changed, 105 insertions(+), 62 deletions(-)


Changeset truncated at 500 lines:

diff --git a/selftest/target/Samba3.pm b/selftest/target/Samba3.pm
index 289e464..8926ae1 100755
--- a/selftest/target/Samba3.pm
+++ b/selftest/target/Samba3.pm
@@ -1182,6 +1182,10 @@ sub provision($$$$$$$$)
        path = $shrdir
         force user = $unix_name
         guest ok = yes
+[forceuser_unixonly]
+       path = $shrdir
+       force user = pdbtest
+       guest ok = yes
 [forcegroup]
        path = $shrdir
         force group = nogroup
diff --git a/source3/auth/auth_util.c b/source3/auth/auth_util.c
index dbc7d24..585afd3 100644
--- a/source3/auth/auth_util.c
+++ b/source3/auth/auth_util.c
@@ -671,7 +671,8 @@ NTSTATUS make_server_info_pw(TALLOC_CTX *mem_ctx,
        status = passwd_to_SamInfo3(result,
                                    unix_username,
                                    pwd,
-                                   &result->info3);
+                                   &result->info3,
+                                   &result->extra);
        if (!NT_STATUS_IS_OK(status)) {
                goto done;
        }
diff --git a/source3/auth/proto.h b/source3/auth/proto.h
index da3c099..792e96d 100644
--- a/source3/auth/proto.h
+++ b/source3/auth/proto.h
@@ -305,7 +305,8 @@ NTSTATUS samu_to_SamInfo3(TALLOC_CTX *mem_ctx,
 NTSTATUS passwd_to_SamInfo3(TALLOC_CTX *mem_ctx,
                            const char *unix_username,
                            const struct passwd *pwd,
-                           struct netr_SamInfo3 **pinfo3);
+                           struct netr_SamInfo3 **pinfo3,
+                           struct extra_auth_info *extra);
 struct netr_SamInfo3 *copy_netr_SamInfo3(TALLOC_CTX *mem_ctx,
                                         const struct netr_SamInfo3 *orig);
 
diff --git a/source3/auth/server_info.c b/source3/auth/server_info.c
index 8fd3b0d..b537390 100644
--- a/source3/auth/server_info.c
+++ b/source3/auth/server_info.c
@@ -330,46 +330,19 @@ NTSTATUS create_info3_from_pac_logon_info(TALLOC_CTX 
*mem_ctx,
        return NT_STATUS_OK;
 }
 
-#define RET_NOMEM(ptr) do { \
-       if (!ptr) { \
-               TALLOC_FREE(info3); \
-               return NT_STATUS_NO_MEMORY; \
-       } } while(0)
+/*
+ * Check if this is a "Unix Users" domain user, or a
+ * "Unix Groups" domain group, we need to handle it
+ * in a special way if that's the case.
+ */
 
-NTSTATUS samu_to_SamInfo3(TALLOC_CTX *mem_ctx,
-                         struct samu *samu,
-                         const char *login_server,
-                         struct netr_SamInfo3 **_info3,
-                         struct extra_auth_info *extra)
+static NTSTATUS SamInfo3_handle_sids(const char *username,
+                       const struct dom_sid *user_sid,
+                       const struct dom_sid *group_sid,
+                       struct netr_SamInfo3 *info3,
+                       struct dom_sid *domain_sid,
+                       struct extra_auth_info *extra)
 {
-       struct netr_SamInfo3 *info3;
-       const struct dom_sid *user_sid;
-       const struct dom_sid *group_sid;
-       struct dom_sid domain_sid;
-       struct dom_sid *group_sids;
-       uint32_t num_group_sids = 0;
-       const char *tmp;
-       gid_t *gids;
-       NTSTATUS status;
-       bool ok;
-
-       user_sid = pdb_get_user_sid(samu);
-       group_sid = pdb_get_group_sid(samu);
-
-       if (!user_sid || !group_sid) {
-               DEBUG(1, ("Sam account is missing sids!\n"));
-               return NT_STATUS_UNSUCCESSFUL;
-       }
-
-       info3 = talloc_zero(mem_ctx, struct netr_SamInfo3);
-       if (!info3) {
-               return NT_STATUS_NO_MEMORY;
-       }
-
-       ZERO_STRUCT(domain_sid);
-
-       /* check if this is a "Unix Users" domain user,
-        * we need to handle it in a special way if that's the case */
        if (sid_check_is_in_unix_users(user_sid)) {
                /* in info3 you can only set rids for the user and the
                 * primary group, and the domain sid must be that of
@@ -382,16 +355,16 @@ NTSTATUS samu_to_SamInfo3(TALLOC_CTX *mem_ctx,
                info3->base.rid = (uint32_t)(-1);
                sid_copy(&extra->user_sid, user_sid);
 
-               DEBUG(10, ("Unix User found in struct samu. Rid marked as "
-                          "special and sid (%s) saved as extra sid\n",
-                          sid_string_dbg(user_sid)));
+               DEBUG(10, ("Unix User found. Rid marked as "
+                       "special and sid (%s) saved as extra sid\n",
+                       sid_string_dbg(user_sid)));
        } else {
-               sid_copy(&domain_sid, user_sid);
-               sid_split_rid(&domain_sid, &info3->base.rid);
+               sid_copy(domain_sid, user_sid);
+               sid_split_rid(domain_sid, &info3->base.rid);
        }
 
-       if (is_null_sid(&domain_sid)) {
-               sid_copy(&domain_sid, get_global_sam_sid());
+       if (is_null_sid(domain_sid)) {
+               sid_copy(domain_sid, get_global_sam_sid());
        }
 
        /* check if this is a "Unix Groups" domain group,
@@ -408,24 +381,73 @@ NTSTATUS samu_to_SamInfo3(TALLOC_CTX *mem_ctx,
                info3->base.primary_gid = (uint32_t)(-1);
                sid_copy(&extra->pgid_sid, group_sid);
 
-               DEBUG(10, ("Unix Group found in struct samu. Rid marked as "
-                          "special and sid (%s) saved as extra sid\n",
-                          sid_string_dbg(group_sid)));
-
+               DEBUG(10, ("Unix Group found. Rid marked as "
+                       "special and sid (%s) saved as extra sid\n",
+                       sid_string_dbg(group_sid)));
        } else {
-               ok = sid_peek_check_rid(&domain_sid, group_sid,
+               bool ok = sid_peek_check_rid(domain_sid, group_sid,
                                        &info3->base.primary_gid);
                if (!ok) {
                        DEBUG(1, ("The primary group domain sid(%s) does not "
-                                 "match the domain sid(%s) for %s(%s)\n",
-                                 sid_string_dbg(group_sid),
-                                 sid_string_dbg(&domain_sid),
-                                 pdb_get_username(samu),
-                                 sid_string_dbg(user_sid)));
-                       TALLOC_FREE(info3);
-                       return NT_STATUS_UNSUCCESSFUL;
+                               "match the domain sid(%s) for %s(%s)\n",
+                               sid_string_dbg(group_sid),
+                               sid_string_dbg(domain_sid),
+                               username,
+                               sid_string_dbg(user_sid)));
+                       return NT_STATUS_INVALID_SID;
                }
        }
+       return NT_STATUS_OK;
+}
+
+#define RET_NOMEM(ptr) do { \
+       if (!ptr) { \
+               TALLOC_FREE(info3); \
+               return NT_STATUS_NO_MEMORY; \
+       } } while(0)
+
+NTSTATUS samu_to_SamInfo3(TALLOC_CTX *mem_ctx,
+                         struct samu *samu,
+                         const char *login_server,
+                         struct netr_SamInfo3 **_info3,
+                         struct extra_auth_info *extra)
+{
+       struct netr_SamInfo3 *info3;
+       const struct dom_sid *user_sid;
+       const struct dom_sid *group_sid;
+       struct dom_sid domain_sid;
+       struct dom_sid *group_sids;
+       uint32_t num_group_sids = 0;
+       const char *tmp;
+       gid_t *gids;
+       NTSTATUS status;
+
+       user_sid = pdb_get_user_sid(samu);
+       group_sid = pdb_get_group_sid(samu);
+
+       if (!user_sid || !group_sid) {
+               DEBUG(1, ("Sam account is missing sids!\n"));
+               return NT_STATUS_UNSUCCESSFUL;
+       }
+
+       info3 = talloc_zero(mem_ctx, struct netr_SamInfo3);
+       if (!info3) {
+               return NT_STATUS_NO_MEMORY;
+       }
+
+       ZERO_STRUCT(domain_sid);
+
+       status = SamInfo3_handle_sids(pdb_get_username(samu),
+                               user_sid,
+                               group_sid,
+                               info3,
+                               &domain_sid,
+                               extra);
+
+       if (!NT_STATUS_IS_OK(status)) {
+               TALLOC_FREE(info3);
+               return status;
+       }
 
        unix_to_nt_time(&info3->base.logon_time, pdb_get_logon_time(samu));
        unix_to_nt_time(&info3->base.logoff_time, get_time_t_max());
@@ -517,7 +539,8 @@ NTSTATUS samu_to_SamInfo3(TALLOC_CTX *mem_ctx,
 NTSTATUS passwd_to_SamInfo3(TALLOC_CTX *mem_ctx,
                            const char *unix_username,
                            const struct passwd *pwd,
-                           struct netr_SamInfo3 **pinfo3)
+                           struct netr_SamInfo3 **pinfo3,
+                           struct extra_auth_info *extra)
 {
        struct netr_SamInfo3 *info3;
        NTSTATUS status;
@@ -613,9 +636,22 @@ NTSTATUS passwd_to_SamInfo3(TALLOC_CTX *mem_ctx,
 
        ZERO_STRUCT(domain_sid);
 
-       sid_copy(&domain_sid, &user_sid);
-       sid_split_rid(&domain_sid, &info3->base.rid);
+       status = SamInfo3_handle_sids(unix_username,
+                               &user_sid,
+                               &group_sid,
+                               info3,
+                               &domain_sid,
+                               extra);
+
+       if (!NT_STATUS_IS_OK(status)) {
+               goto done;
+       }
+
        info3->base.domain_sid = dom_sid_dup(info3, &domain_sid);
+       if (info3->base.domain_sid == NULL) {
+               status = NT_STATUS_NO_MEMORY;
+               goto done;
+       }
 
        ok = sid_peek_check_rid(&domain_sid, &group_sid,
                                &info3->base.primary_gid);
diff --git a/source3/script/tests/test_smbclient_auth.sh 
b/source3/script/tests/test_smbclient_auth.sh
index 3988095..24e98b1 100755
--- a/source3/script/tests/test_smbclient_auth.sh
+++ b/source3/script/tests/test_smbclient_auth.sh
@@ -27,5 +27,6 @@ testit "smbclient //$SERVER/tmpguest" $SMBCLIENT 
//$SERVER/tmpguest $CONFIGURATI
 testit "smbclient //$SERVER/tmpguest as anon" $SMBCLIENT //$SERVER/tmpguest 
$CONFIGURATION -U% -I $SERVER_IP -p 139 -c quit $ADDARGS
 testit "smbclient //$SERVER/forceuser" $SMBCLIENT //$SERVER/forceuser 
$CONFIGURATION -U$USERNAME%$PASSWORD -I $SERVER_IP -p 139 -c quit $ADDARGS
 testit "smbclient //$SERVER/forceuser as anon" $SMBCLIENT //$SERVER/forceuser 
$CONFIGURATION -U% -I $SERVER_IP -p 139 -c quit $ADDARGS
+testit "smbclient //$SERVER/forceuser_unixonly" $SMBCLIENT 
//$SERVER/forceuser_unixonly $CONFIGURATION -U$USERNAME%$PASSWORD -I $SERVER_IP 
-p 139 -c quit $ADDARGS
 testit "smbclient //$SERVER/forcegroup" $SMBCLIENT //$SERVER/forcegroup 
$CONFIGURATION -U$USERNAME%$PASSWORD -I $SERVER_IP -p 139 -c quit $ADDARGS
 testit "smbclient //$SERVER/forcegroup as anon" $SMBCLIENT 
//$SERVER/forcegroup $CONFIGURATION -U% -I $SERVER_IP -p 139 -c quit $ADDARGS


-- 
Samba Shared Repository

Reply via email to