2 Unix SMB/CIFS implementation.
3 test suite for RAP sam operations
5 Copyright (C) Guenther Deschner 2010
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 3 of the License, or
10 (at your option) any later version.
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with this program. If not, see <http://www.gnu.org/licenses/>.
22 #include "libcli/libcli.h"
23 #include "torture/torture.h"
24 #include "torture/util.h"
25 #include "torture/smbtorture.h"
26 #include "torture/util.h"
27 #include "../librpc/gen_ndr/rap.h"
28 #include "torture/rap/proto.h"
29 #include "param/param.h"
30 #include "../lib/crypto/crypto.h"
31 #include "../libcli/auth/libcli_auth.h"
32 #include "torture/rpc/torture_rpc.h"
34 #define TEST_RAP_USER "torture_rap_user"
36 static char *samr_rand_pass(TALLOC_CTX
*mem_ctx
, int min_len
)
38 size_t len
= MAX(8, min_len
);
39 char *s
= generate_random_password(mem_ctx
, len
, len
+6);
40 printf("Generated password '%s'\n", s
);
44 static bool test_userpasswordset2_args(struct torture_context
*tctx
,
45 struct smbcli_state
*cli
,
47 const char **password
)
49 struct rap_NetUserPasswordSet2 r
;
50 char *newpass
= samr_rand_pass(tctx
, 8);
52 r
.in
.UserName
= username
;
53 r
.in
.OldPassword
= *password
;
54 r
.in
.NewPassword
= newpass
;
55 r
.in
.EncryptedPassword
= 0;
56 r
.in
.RealPasswordLength
= strlen(r
.in
.NewPassword
);
58 torture_comment(tctx
, "Testing rap_NetUserPasswordSet2(%s)\n", r
.in
.UserName
);
60 torture_assert_ntstatus_ok(tctx
,
61 smbcli_rap_netuserpasswordset2(cli
->tree
, lp_iconv_convenience(tctx
->lp_ctx
), tctx
, &r
),
62 "smbcli_rap_netuserpasswordset2 failed");
63 if (!W_ERROR_IS_OK(W_ERROR(r
.out
.status
))) {
64 torture_warning(tctx
, "RAP NetUserPasswordSet2 gave: %s\n",
65 win_errstr(W_ERROR(r
.out
.status
)));
73 static bool test_userpasswordset2(struct torture_context
*tctx
,
74 struct smbcli_state
*cli
)
76 struct test_join
*join_ctx
;
80 join_ctx
= torture_create_testuser_max_pwlen(tctx
, TEST_RAP_USER
,
81 torture_setting_string(tctx
, "workgroup", NULL
),
84 if (join_ctx
== NULL
) {
85 torture_fail(tctx
, "failed to create user\n");
88 ret
= test_userpasswordset2_args(tctx
, cli
, TEST_RAP_USER
, &password
);
90 torture_leave_domain(tctx
, join_ctx
);
95 static bool test_oemchangepassword_args(struct torture_context
*tctx
,
96 struct smbcli_state
*cli
,
98 const char **password
)
100 struct rap_NetOEMChangePassword r
;
102 const char *oldpass
= *password
;
103 char *newpass
= samr_rand_pass(tctx
, 9);
104 uint8_t old_pw_hash
[16];
105 uint8_t new_pw_hash
[16];
107 r
.in
.UserName
= username
;
109 E_deshash(oldpass
, old_pw_hash
);
110 E_deshash(newpass
, new_pw_hash
);
112 encode_pw_buffer(r
.in
.crypt_password
, newpass
, STR_ASCII
);
113 arcfour_crypt(r
.in
.crypt_password
, old_pw_hash
, 516);
114 E_old_pw_hash(new_pw_hash
, old_pw_hash
, r
.in
.password_hash
);
116 torture_comment(tctx
, "Testing rap_NetOEMChangePassword(%s)\n", r
.in
.UserName
);
118 torture_assert_ntstatus_ok(tctx
,
119 smbcli_rap_netoemchangepassword(cli
->tree
, lp_iconv_convenience(tctx
->lp_ctx
), tctx
, &r
),
120 "smbcli_rap_netoemchangepassword failed");
121 if (!W_ERROR_IS_OK(W_ERROR(r
.out
.status
))) {
122 torture_warning(tctx
, "RAP NetOEMChangePassword gave: %s\n",
123 win_errstr(W_ERROR(r
.out
.status
)));
131 static bool test_oemchangepassword(struct torture_context
*tctx
,
132 struct smbcli_state
*cli
)
135 struct test_join
*join_ctx
;
136 const char *password
;
139 join_ctx
= torture_create_testuser_max_pwlen(tctx
, TEST_RAP_USER
,
140 torture_setting_string(tctx
, "workgroup", NULL
),
143 if (join_ctx
== NULL
) {
144 torture_fail(tctx
, "failed to create user\n");
147 ret
= test_oemchangepassword_args(tctx
, cli
, TEST_RAP_USER
, &password
);
149 torture_leave_domain(tctx
, join_ctx
);
154 struct torture_suite
*torture_rap_sam(TALLOC_CTX
*mem_ctx
)
156 struct torture_suite
*suite
= torture_suite_create(mem_ctx
, "SAM");
158 torture_suite_add_1smb_test(suite
, "userpasswordset2", test_userpasswordset2
);
159 torture_suite_add_1smb_test(suite
, "oemchangepassword", test_oemchangepassword
);