From 4419853b94ae819988b6eb36ff028c9cb4d338c1 Mon Sep 17 00:00:00 2001 From: Michael Adam Date: Thu, 21 Jan 2010 23:55:51 +0100 Subject: [PATCH] s4:torture: refactor setting account flags out into test_SetUserInfo_acct_flags() MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit and use this in four places (enabling/disabling accounts). Michael Signed-off-by: Günther Deschner --- source4/torture/rpc/samr.c | 96 ++++++++++++++++++++++------------------------ 1 file changed, 46 insertions(+), 50 deletions(-) diff --git a/source4/torture/rpc/samr.c b/source4/torture/rpc/samr.c index c2b973e5519..ecf09ffe1ac 100644 --- a/source4/torture/rpc/samr.c +++ b/source4/torture/rpc/samr.c @@ -3403,29 +3403,43 @@ static bool test_QueryUserInfo_badpwdcount(struct dcerpc_pipe *p, return true; } -static bool test_reset_badpwdcount(struct dcerpc_pipe *p, - struct torture_context *tctx, - struct policy_handle *user_handle, - uint32_t acct_flags, - char **password) +static bool test_SetUserInfo_acct_flags(struct dcerpc_pipe *p, + struct torture_context *tctx, + struct policy_handle *user_handle, + uint32_t acct_flags) { struct samr_SetUserInfo r; union samr_UserInfo user_info; - torture_assert(tctx, test_SetUserPass(p, tctx, user_handle, password), - "failed to set password"); - - torture_comment(tctx, "Testing SetUserInfo level 16 (enable account)\n"); + torture_comment(tctx, "Testing SetUserInfo level 16\n"); user_info.info16.acct_flags = acct_flags; - user_info.info16.acct_flags &= ~ACB_DISABLED; r.in.user_handle = user_handle; r.in.level = 16; r.in.info = &user_info; torture_assert_ntstatus_ok(tctx, dcerpc_samr_SetUserInfo(p, tctx, &r), - "failed to enable user"); + "failed to set account flags"); + + return true; +} + +static bool test_reset_badpwdcount(struct dcerpc_pipe *p, + struct torture_context *tctx, + struct policy_handle *user_handle, + uint32_t acct_flags, + char **password) +{ + torture_assert(tctx, test_SetUserPass(p, tctx, user_handle, password), + "failed to set password"); + + torture_comment(tctx, "Testing SetUserInfo level 16 (enable account)\n"); + + torture_assert(tctx, + test_SetUserInfo_acct_flags(p, tctx, user_handle, + acct_flags & ~ACB_DISABLED), + "failed to enable user"); torture_assert(tctx, test_SetUserPass(p, tctx, user_handle, password), "failed to set password"); @@ -3503,26 +3517,16 @@ static bool test_Password_badpwdcount(struct dcerpc_pipe *p, /* enable or disable account */ - { - struct samr_SetUserInfo r; - union samr_UserInfo user_info; - - torture_comment(tctx, "Testing SetUserInfo level 16 (%s account)\n", - disable ? "disable" : "enable"); - - user_info.info16.acct_flags = acct_flags; - if (disable) { - user_info.info16.acct_flags |= ACB_DISABLED; - } else { - user_info.info16.acct_flags &= ~ACB_DISABLED; - } - - r.in.user_handle = user_handle; - r.in.level = 16; - r.in.info = &user_info; - - torture_assert_ntstatus_ok(tctx, dcerpc_samr_SetUserInfo(p, tctx, &r), - "failed to enable user"); + if (disable) { + torture_assert(tctx, + test_SetUserInfo_acct_flags(p, tctx, user_handle, + acct_flags | ACB_DISABLED), + "failed to disable user"); + } else { + torture_assert(tctx, + test_SetUserInfo_acct_flags(p, tctx, user_handle, + acct_flags & ~ACB_DISABLED), + "failed to enable user"); } @@ -3918,28 +3922,20 @@ static bool test_Password_lockout(struct dcerpc_pipe *p, /* enable or disable account */ - { - struct samr_SetUserInfo r; - union samr_UserInfo user_info; - - torture_comment(tctx, "Testing SetUserInfo level 16 (%s account)\n", - disable ? "disable" : "enable"); - - user_info.info16.acct_flags = acct_flags; - if (disable) { - user_info.info16.acct_flags |= ACB_DISABLED; - } else { - user_info.info16.acct_flags &= ~ACB_DISABLED; - } - - r.in.user_handle = user_handle; - r.in.level = 16; - r.in.info = &user_info; - torture_assert_ntstatus_ok(tctx, dcerpc_samr_SetUserInfo(p, tctx, &r), - "failed to enable user"); + if (disable) { + torture_assert(tctx, + test_SetUserInfo_acct_flags(p, tctx, user_handle, + acct_flags | ACB_DISABLED), + "failed to disable user"); + } else { + torture_assert(tctx, + test_SetUserInfo_acct_flags(p, tctx, user_handle, + acct_flags & ~ACB_DISABLED), + "failed to enable user"); } + /* test logon with right password */ if (!test_SamLogon_with_creds(tctx, np, machine_credentials, -- 2.11.4.GIT