~ubuntu-branches/ubuntu/vivid/samba/vivid

« back to all changes in this revision

Viewing changes to source4/torture/rpc/samba3rpc.c

  • Committer: Package Import Robot
  • Author(s): Chuck Short
  • Date: 2011-12-21 13:18:04 UTC
  • mfrom: (0.39.21 sid)
  • Revision ID: package-import@ubuntu.com-20111221131804-xtlr39wx6njehxxr
Tags: 2:3.6.1-3ubuntu1
* Merge from Debian testing.  Remaining changes:
  + debian/patches/VERSION.patch:
    - set SAMBA_VERSION_SUFFIX to Ubuntu.
  + debian/patches/error-trans.fix-276472:
    - Add the translation of Unix Error code -ENOTSUP to NT Error Code
    - NT_STATUS_NOT_SUPPORTED to prevent the Permission denied error.
  + debian/smb.conf:
    - add "(Samba, Ubuntu)" to server string.
    - comment out the default [homes] share, and add a comment about
      "valid users = %S" to show users how to restrict access to
      \\server\username to only username.
    - Set 'usershare allow guests', so that usershare admins are 
      allowed to create public shares in addition to authenticated
      ones.
    - add map to guest = Bad user, maps bad username to guest access.
  + debian/samba-common.config:
    - Do not change priority to high if dhclient3 is installed.
    - Use priority medium instead of high for the workgroup question.
  + debian/control:
    - Don't build against or suggest ctdb.
    - Add dependency on samba-common-bin to samba.
  + Add ufw integration:
    - Created debian/samba.ufw.profile
    - debian/rules, debian/samba.dirs, debian/samba.files: install
      profile
    - debian/control: have samba suggest ufw
  + Add apport hook:
    - Created debian/source_samba.py.
    - debian/rules, debian/samba.dirs, debian/samba-common-bin.files: install
  + Switch to upstart:
    - Add debian/samba.{nmbd,smbd}.upstart.
  + debian/samba.logrotate, debian/samba-common.dhcp, debian/samba.if-up:
    - Make them upstart compatible
  + debian/samba.postinst: 
    - Avoid scary pdbedit warnings on first import.
  + debian/samba-common.postinst: Add more informative error message for
    the case where smb.conf was manually deleted
  + debian/patches/fix-debuglevel-name-conflict.patch: don't use 'debug_level'
    as a global variable name in an NSS module 
  + Dropped:
    - debian/patches/error-trans.fix-276472
    - debian/patches/fix-debuglevel-name-conflict.patch

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/* 
 
1
/*
2
2
   Unix SMB/CIFS implementation.
3
3
 
4
4
   dcerpc torture tests, designed to walk Samba3 code paths
9
9
   it under the terms of the GNU General Public License as published by
10
10
   the Free Software Foundation; either version 3 of the License, or
11
11
   (at your option) any later version.
12
 
   
 
12
 
13
13
   This program is distributed in the hope that it will be useful,
14
14
   but WITHOUT ANY WARRANTY; without even the implied warranty of
15
15
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16
16
   GNU General Public License for more details.
17
 
   
 
17
 
18
18
   You should have received a copy of the GNU General Public License
19
19
   along with this program.  If not, see <http://www.gnu.org/licenses/>.
20
20
*/
22
22
#include "includes.h"
23
23
#include "libcli/raw/libcliraw.h"
24
24
#include "libcli/raw/raw_proto.h"
 
25
#include "torture/util.h"
25
26
#include "libcli/rap/rap.h"
26
 
#include "torture/torture.h"
27
 
#include "torture/util.h"
28
 
#include "torture/rap/proto.h"
29
 
#include "librpc/gen_ndr/ndr_lsa.h"
30
27
#include "librpc/gen_ndr/ndr_lsa_c.h"
31
 
#include "librpc/gen_ndr/ndr_samr.h"
32
28
#include "librpc/gen_ndr/ndr_samr_c.h"
33
 
#include "librpc/gen_ndr/ndr_netlogon.h"
34
29
#include "librpc/gen_ndr/ndr_netlogon_c.h"
35
 
#include "librpc/gen_ndr/ndr_srvsvc.h"
36
30
#include "librpc/gen_ndr/ndr_srvsvc_c.h"
37
 
#include "librpc/gen_ndr/ndr_spoolss.h"
38
31
#include "librpc/gen_ndr/ndr_spoolss_c.h"
39
 
#include "librpc/gen_ndr/ndr_winreg.h"
40
32
#include "librpc/gen_ndr/ndr_winreg_c.h"
41
 
#include "librpc/gen_ndr/ndr_wkssvc.h"
42
33
#include "librpc/gen_ndr/ndr_wkssvc_c.h"
43
34
#include "lib/cmdline/popt_common.h"
44
 
#include "librpc/rpc/dcerpc.h"
45
 
#include "torture/rpc/rpc.h"
 
35
#include "torture/rpc/torture_rpc.h"
46
36
#include "libcli/libcli.h"
47
 
#include "libcli/composite/composite.h"
48
37
#include "libcli/smb_composite/smb_composite.h"
49
38
#include "libcli/auth/libcli_auth.h"
50
39
#include "../lib/crypto/crypto.h"
51
 
#include "auth/ntlmssp/ntlmssp.h"
52
40
#include "libcli/security/security.h"
53
41
#include "param/param.h"
54
42
#include "lib/registry/registry.h"
55
43
#include "libcli/resolve/resolve.h"
 
44
#include "torture/ndr/ndr.h"
56
45
 
57
46
/*
58
47
 * This tests a RPC call using an invalid vuid
59
48
 */
60
49
 
61
 
bool torture_bind_authcontext(struct torture_context *torture) 
 
50
bool torture_bind_authcontext(struct torture_context *torture)
62
51
{
63
52
        TALLOC_CTX *mem_ctx;
64
53
        NTSTATUS status;
71
60
        struct smbcli_session *session2;
72
61
        struct smbcli_state *cli;
73
62
        struct dcerpc_pipe *lsa_pipe;
 
63
        struct dcerpc_binding_handle *lsa_handle;
74
64
        struct cli_credentials *anon_creds;
75
65
        struct smb_composite_sesssetup setup;
76
66
        struct smbcli_options options;
79
69
        mem_ctx = talloc_init("torture_bind_authcontext");
80
70
 
81
71
        if (mem_ctx == NULL) {
82
 
                d_printf("talloc_init failed\n");
 
72
                torture_comment(torture, "talloc_init failed\n");
83
73
                return false;
84
74
        }
85
75
 
86
 
        lp_smbcli_options(torture->lp_ctx, &options);
87
 
        lp_smbcli_session_options(torture->lp_ctx, &session_options);
 
76
        lpcfg_smbcli_options(torture->lp_ctx, &options);
 
77
        lpcfg_smbcli_session_options(torture->lp_ctx, &session_options);
88
78
 
89
79
        status = smbcli_full_connection(mem_ctx, &cli,
90
80
                                        torture_setting_string(torture, "host", NULL),
91
 
                                        lp_smb_ports(torture->lp_ctx),
92
 
                                        "IPC$", NULL, 
93
 
                                        lp_socket_options(torture->lp_ctx),
 
81
                                        lpcfg_smb_ports(torture->lp_ctx),
 
82
                                        "IPC$", NULL,
 
83
                                        lpcfg_socket_options(torture->lp_ctx),
94
84
                                        cmdline_credentials,
95
 
                                        lp_resolve_context(torture->lp_ctx),
 
85
                                        lpcfg_resolve_context(torture->lp_ctx),
96
86
                                        torture->ev, &options, &session_options,
97
 
                                        lp_iconv_convenience(torture->lp_ctx),
98
 
                                        lp_gensec_settings(torture, torture->lp_ctx));
 
87
                                        lpcfg_gensec_settings(torture, torture->lp_ctx));
99
88
        if (!NT_STATUS_IS_OK(status)) {
100
 
                d_printf("smbcli_full_connection failed: %s\n",
 
89
                torture_comment(torture, "smbcli_full_connection failed: %s\n",
101
90
                         nt_errstr(status));
102
91
                goto done;
103
92
        }
104
93
 
105
 
        lsa_pipe = dcerpc_pipe_init(mem_ctx, cli->transport->socket->event.ctx,
106
 
                                    lp_iconv_convenience(torture->lp_ctx));
 
94
        lsa_pipe = dcerpc_pipe_init(mem_ctx, cli->transport->socket->event.ctx);
107
95
        if (lsa_pipe == NULL) {
108
 
                d_printf("dcerpc_pipe_init failed\n");
 
96
                torture_comment(torture, "dcerpc_pipe_init failed\n");
109
97
                goto done;
110
98
        }
 
99
        lsa_handle = lsa_pipe->binding_handle;
111
100
 
112
101
        status = dcerpc_pipe_open_smb(lsa_pipe, cli->tree, "\\lsarpc");
113
102
        if (!NT_STATUS_IS_OK(status)) {
114
 
                d_printf("dcerpc_pipe_open_smb failed: %s\n",
 
103
                torture_comment(torture, "dcerpc_pipe_open_smb failed: %s\n",
115
104
                         nt_errstr(status));
116
105
                goto done;
117
106
        }
118
107
 
119
108
        status = dcerpc_bind_auth_none(lsa_pipe, &ndr_table_lsarpc);
120
109
        if (!NT_STATUS_IS_OK(status)) {
121
 
                d_printf("dcerpc_bind_auth_none failed: %s\n",
 
110
                torture_comment(torture, "dcerpc_bind_auth_none failed: %s\n",
122
111
                         nt_errstr(status));
123
112
                goto done;
124
113
        }
130
119
        openpolicy.in.access_mask = SEC_FLAG_MAXIMUM_ALLOWED;
131
120
        openpolicy.out.handle = &handle;
132
121
 
133
 
        status = dcerpc_lsa_OpenPolicy2(lsa_pipe, mem_ctx, &openpolicy);
 
122
        status = dcerpc_lsa_OpenPolicy2_r(lsa_handle, mem_ctx, &openpolicy);
134
123
 
135
124
        if (!NT_STATUS_IS_OK(status)) {
136
 
                d_printf("dcerpc_lsa_OpenPolicy2 failed: %s\n",
 
125
                torture_comment(torture, "dcerpc_lsa_OpenPolicy2 failed: %s\n",
137
126
                         nt_errstr(status));
138
127
                goto done;
139
128
        }
 
129
        if (!NT_STATUS_IS_OK(openpolicy.out.result)) {
 
130
                torture_comment(torture, "dcerpc_lsa_OpenPolicy2 failed: %s\n",
 
131
                         nt_errstr(openpolicy.out.result));
 
132
                goto done;
 
133
        }
140
134
 
141
135
        close_handle.in.handle = &handle;
142
136
        close_handle.out.handle = &handle;
143
137
 
144
 
        status = dcerpc_lsa_Close(lsa_pipe, mem_ctx, &close_handle);
 
138
        status = dcerpc_lsa_Close_r(lsa_handle, mem_ctx, &close_handle);
145
139
        if (!NT_STATUS_IS_OK(status)) {
146
 
                d_printf("dcerpc_lsa_Close failed: %s\n",
 
140
                torture_comment(torture, "dcerpc_lsa_Close failed: %s\n",
147
141
                         nt_errstr(status));
148
142
                goto done;
149
143
        }
 
144
        if (!NT_STATUS_IS_OK(close_handle.out.result)) {
 
145
                torture_comment(torture, "dcerpc_lsa_Close failed: %s\n",
 
146
                         nt_errstr(close_handle.out.result));
 
147
                goto done;
 
148
        }
150
149
 
151
150
        session2 = smbcli_session_init(cli->transport, mem_ctx, false, session_options);
152
151
        if (session2 == NULL) {
153
 
                d_printf("smbcli_session_init failed\n");
 
152
                torture_comment(torture, "smbcli_session_init failed\n");
154
153
                goto done;
155
154
        }
156
155
 
157
156
        if (!(anon_creds = cli_credentials_init_anon(mem_ctx))) {
158
 
                d_printf("create_anon_creds failed\n");
 
157
                torture_comment(torture, "create_anon_creds failed\n");
159
158
                goto done;
160
159
        }
161
160
 
163
162
        setup.in.capabilities = cli->transport->negotiate.capabilities;
164
163
        setup.in.workgroup = "";
165
164
        setup.in.credentials = anon_creds;
166
 
        setup.in.gensec_settings = lp_gensec_settings(torture, torture->lp_ctx);
 
165
        setup.in.gensec_settings = lpcfg_gensec_settings(torture, torture->lp_ctx);
167
166
 
168
167
        status = smb_composite_sesssetup(session2, &setup);
169
168
        if (!NT_STATUS_IS_OK(status)) {
170
 
                d_printf("anon session setup failed: %s\n",
 
169
                torture_comment(torture, "anon session setup failed: %s\n",
171
170
                         nt_errstr(status));
172
171
                goto done;
173
172
        }
176
175
        tmp = cli->tree->session;
177
176
        cli->tree->session = session2;
178
177
 
179
 
        status = dcerpc_lsa_OpenPolicy2(lsa_pipe, mem_ctx, &openpolicy);
 
178
        status = dcerpc_lsa_OpenPolicy2_r(lsa_handle, mem_ctx, &openpolicy);
180
179
 
181
180
        cli->tree->session = tmp;
182
181
        talloc_free(lsa_pipe);
183
182
        lsa_pipe = NULL;
184
183
 
185
184
        if (!NT_STATUS_EQUAL(status, NT_STATUS_INVALID_HANDLE)) {
186
 
                d_printf("dcerpc_lsa_OpenPolicy2 with wrong vuid gave %s, "
 
185
                torture_comment(torture, "dcerpc_lsa_OpenPolicy2 with wrong vuid gave %s, "
187
186
                         "expected NT_STATUS_INVALID_HANDLE\n",
188
187
                         nt_errstr(status));
189
188
                goto done;
199
198
 * Bind to lsa using a specific auth method
200
199
 */
201
200
 
202
 
static bool bindtest(struct smbcli_state *cli,
 
201
static bool bindtest(struct torture_context *tctx,
 
202
                     struct smbcli_state *cli,
203
203
                     struct cli_credentials *credentials,
204
 
                     struct loadparm_context *lp_ctx,
205
204
                     uint8_t auth_type, uint8_t auth_level)
206
205
{
207
206
        TALLOC_CTX *mem_ctx;
209
208
        NTSTATUS status;
210
209
 
211
210
        struct dcerpc_pipe *lsa_pipe;
 
211
        struct dcerpc_binding_handle *lsa_handle;
212
212
        struct lsa_ObjectAttribute objectattr;
213
213
        struct lsa_OpenPolicy2 openpolicy;
214
214
        struct lsa_QueryInfoPolicy query;
217
217
        struct lsa_Close close_handle;
218
218
 
219
219
        if ((mem_ctx = talloc_init("bindtest")) == NULL) {
220
 
                d_printf("talloc_init failed\n");
 
220
                torture_comment(tctx, "talloc_init failed\n");
221
221
                return false;
222
222
        }
223
223
 
224
224
        lsa_pipe = dcerpc_pipe_init(mem_ctx,
225
 
                                    cli->transport->socket->event.ctx,
226
 
                                    lp_iconv_convenience(lp_ctx));
 
225
                                    cli->transport->socket->event.ctx); 
227
226
        if (lsa_pipe == NULL) {
228
 
                d_printf("dcerpc_pipe_init failed\n");
 
227
                torture_comment(tctx, "dcerpc_pipe_init failed\n");
229
228
                goto done;
230
229
        }
 
230
        lsa_handle = lsa_pipe->binding_handle;
231
231
 
232
232
        status = dcerpc_pipe_open_smb(lsa_pipe, cli->tree, "\\lsarpc");
233
233
        if (!NT_STATUS_IS_OK(status)) {
234
 
                d_printf("dcerpc_pipe_open_smb failed: %s\n",
 
234
                torture_comment(tctx, "dcerpc_pipe_open_smb failed: %s\n",
235
235
                         nt_errstr(status));
236
236
                goto done;
237
237
        }
238
238
 
239
239
        status = dcerpc_bind_auth(lsa_pipe, &ndr_table_lsarpc,
240
 
                                  credentials, lp_gensec_settings(lp_ctx, lp_ctx), auth_type, auth_level,
 
240
                                  credentials, lpcfg_gensec_settings(tctx->lp_ctx, tctx->lp_ctx), auth_type, auth_level,
241
241
                                  NULL);
242
242
        if (!NT_STATUS_IS_OK(status)) {
243
 
                d_printf("dcerpc_bind_auth failed: %s\n", nt_errstr(status));
 
243
                torture_comment(tctx, "dcerpc_bind_auth failed: %s\n", nt_errstr(status));
244
244
                goto done;
245
245
        }
246
246
 
251
251
        openpolicy.in.access_mask = SEC_FLAG_MAXIMUM_ALLOWED;
252
252
        openpolicy.out.handle = &handle;
253
253
 
254
 
        status = dcerpc_lsa_OpenPolicy2(lsa_pipe, mem_ctx, &openpolicy);
 
254
        status = dcerpc_lsa_OpenPolicy2_r(lsa_handle, mem_ctx, &openpolicy);
255
255
 
256
256
        if (!NT_STATUS_IS_OK(status)) {
257
 
                d_printf("dcerpc_lsa_OpenPolicy2 failed: %s\n",
 
257
                torture_comment(tctx, "dcerpc_lsa_OpenPolicy2 failed: %s\n",
258
258
                         nt_errstr(status));
259
259
                goto done;
260
260
        }
 
261
        if (!NT_STATUS_IS_OK(openpolicy.out.result)) {
 
262
                torture_comment(tctx, "dcerpc_lsa_OpenPolicy2 failed: %s\n",
 
263
                         nt_errstr(openpolicy.out.result));
 
264
                goto done;
 
265
        }
261
266
 
262
267
        query.in.handle = &handle;
263
268
        query.in.level = LSA_POLICY_INFO_DOMAIN;
264
269
        query.out.info = &info;
265
270
 
266
 
        status = dcerpc_lsa_QueryInfoPolicy(lsa_pipe, mem_ctx, &query);
 
271
        status = dcerpc_lsa_QueryInfoPolicy_r(lsa_handle, mem_ctx, &query);
267
272
        if (!NT_STATUS_IS_OK(status)) {
268
 
                d_printf("dcerpc_lsa_QueryInfoPolicy failed: %s\n",
 
273
                torture_comment(tctx, "dcerpc_lsa_QueryInfoPolicy failed: %s\n",
269
274
                         nt_errstr(status));
270
275
                goto done;
271
276
        }
 
277
        if (!NT_STATUS_IS_OK(query.out.result)) {
 
278
                torture_comment(tctx, "dcerpc_lsa_QueryInfoPolicy failed: %s\n",
 
279
                         nt_errstr(query.out.result));
 
280
                goto done;
 
281
        }
272
282
 
273
283
        close_handle.in.handle = &handle;
274
284
        close_handle.out.handle = &handle;
275
285
 
276
 
        status = dcerpc_lsa_Close(lsa_pipe, mem_ctx, &close_handle);
 
286
        status = dcerpc_lsa_Close_r(lsa_handle, mem_ctx, &close_handle);
277
287
        if (!NT_STATUS_IS_OK(status)) {
278
 
                d_printf("dcerpc_lsa_Close failed: %s\n",
 
288
                torture_comment(tctx, "dcerpc_lsa_Close failed: %s\n",
279
289
                         nt_errstr(status));
280
290
                goto done;
281
291
        }
 
292
        if (!NT_STATUS_IS_OK(close_handle.out.result)) {
 
293
                torture_comment(tctx, "dcerpc_lsa_Close failed: %s\n",
 
294
                         nt_errstr(close_handle.out.result));
 
295
                goto done;
 
296
        }
 
297
 
282
298
 
283
299
        ret = true;
284
300
 done:
290
306
 * test authenticated RPC binds with the variants Samba3 does support
291
307
 */
292
308
 
293
 
bool torture_bind_samba3(struct torture_context *torture) 
 
309
static bool torture_bind_samba3(struct torture_context *torture)
294
310
{
295
311
        TALLOC_CTX *mem_ctx;
296
312
        NTSTATUS status;
302
318
        mem_ctx = talloc_init("torture_bind_authcontext");
303
319
 
304
320
        if (mem_ctx == NULL) {
305
 
                d_printf("talloc_init failed\n");
 
321
                torture_comment(torture, "talloc_init failed\n");
306
322
                return false;
307
323
        }
308
324
 
309
 
        lp_smbcli_options(torture->lp_ctx, &options);
310
 
        lp_smbcli_session_options(torture->lp_ctx, &session_options);
 
325
        lpcfg_smbcli_options(torture->lp_ctx, &options);
 
326
        lpcfg_smbcli_session_options(torture->lp_ctx, &session_options);
311
327
 
312
328
        status = smbcli_full_connection(mem_ctx, &cli,
313
329
                                        torture_setting_string(torture, "host", NULL),
314
 
                                        lp_smb_ports(torture->lp_ctx),
315
 
                                        "IPC$", NULL, 
316
 
                                        lp_socket_options(torture->lp_ctx),
 
330
                                        lpcfg_smb_ports(torture->lp_ctx),
 
331
                                        "IPC$", NULL,
 
332
                                        lpcfg_socket_options(torture->lp_ctx),
317
333
                                        cmdline_credentials,
318
 
                                        lp_resolve_context(torture->lp_ctx),
 
334
                                        lpcfg_resolve_context(torture->lp_ctx),
319
335
                                        torture->ev, &options, &session_options,
320
 
                                        lp_iconv_convenience(torture->lp_ctx),
321
 
                                        lp_gensec_settings(torture, torture->lp_ctx));
 
336
                                        lpcfg_gensec_settings(torture, torture->lp_ctx));
322
337
        if (!NT_STATUS_IS_OK(status)) {
323
 
                d_printf("smbcli_full_connection failed: %s\n",
 
338
                torture_comment(torture, "smbcli_full_connection failed: %s\n",
324
339
                         nt_errstr(status));
325
340
                goto done;
326
341
        }
327
342
 
328
343
        ret = true;
329
344
 
330
 
        ret &= bindtest(cli, cmdline_credentials, torture->lp_ctx, DCERPC_AUTH_TYPE_NTLMSSP,
 
345
        ret &= bindtest(torture, cli, cmdline_credentials, DCERPC_AUTH_TYPE_NTLMSSP,
331
346
                        DCERPC_AUTH_LEVEL_INTEGRITY);
332
 
        ret &= bindtest(cli, cmdline_credentials, torture->lp_ctx, DCERPC_AUTH_TYPE_NTLMSSP,
 
347
        ret &= bindtest(torture, cli, cmdline_credentials, DCERPC_AUTH_TYPE_NTLMSSP,
333
348
                        DCERPC_AUTH_LEVEL_PRIVACY);
334
 
        ret &= bindtest(cli, cmdline_credentials, torture->lp_ctx, DCERPC_AUTH_TYPE_SPNEGO,
 
349
        ret &= bindtest(torture, cli, cmdline_credentials, DCERPC_AUTH_TYPE_SPNEGO,
335
350
                        DCERPC_AUTH_LEVEL_INTEGRITY);
336
 
        ret &= bindtest(cli, cmdline_credentials, torture->lp_ctx, DCERPC_AUTH_TYPE_SPNEGO,
 
351
        ret &= bindtest(torture, cli, cmdline_credentials, DCERPC_AUTH_TYPE_SPNEGO,
337
352
                        DCERPC_AUTH_LEVEL_PRIVACY);
338
353
 
339
354
 done:
345
360
 * Lookup or create a user and return all necessary info
346
361
 */
347
362
 
348
 
static NTSTATUS get_usr_handle(struct smbcli_state *cli,
349
 
                               TALLOC_CTX *mem_ctx,
350
 
                               struct loadparm_context *lp_ctx,
351
 
                               struct cli_credentials *admin_creds,
352
 
                               uint8_t auth_type,
353
 
                               uint8_t auth_level,
354
 
                               const char *username,
355
 
                               char **domain,
356
 
                               struct dcerpc_pipe **result_pipe,
357
 
                               struct policy_handle **result_handle,
358
 
                               struct dom_sid **sid_p)
 
363
static bool get_usr_handle(struct torture_context *tctx,
 
364
                           struct smbcli_state *cli,
 
365
                           TALLOC_CTX *mem_ctx,
 
366
                           struct cli_credentials *admin_creds,
 
367
                           uint8_t auth_type,
 
368
                           uint8_t auth_level,
 
369
                           const char *username,
 
370
                           char **domain,
 
371
                           struct dcerpc_pipe **result_pipe,
 
372
                           struct policy_handle **result_handle,
 
373
                           struct dom_sid **sid_p)
359
374
{
360
375
        struct dcerpc_pipe *samr_pipe;
 
376
        struct dcerpc_binding_handle *samr_handle;
361
377
        NTSTATUS status;
362
378
        struct policy_handle conn_handle;
363
379
        struct policy_handle domain_handle;
377
393
        uint32_t user_rid,access_granted;
378
394
 
379
395
        samr_pipe = dcerpc_pipe_init(mem_ctx,
380
 
                                     cli->transport->socket->event.ctx,
381
 
                                     lp_iconv_convenience(lp_ctx));
382
 
        if (samr_pipe == NULL) {
383
 
                d_printf("dcerpc_pipe_init failed\n");
384
 
                status = NT_STATUS_NO_MEMORY;
385
 
                goto fail;
386
 
        }
387
 
 
388
 
        status = dcerpc_pipe_open_smb(samr_pipe, cli->tree, "\\samr");
389
 
        if (!NT_STATUS_IS_OK(status)) {
390
 
                d_printf("dcerpc_pipe_open_smb failed: %s\n",
391
 
                         nt_errstr(status));
392
 
                goto fail;
393
 
        }
 
396
                                     cli->transport->socket->event.ctx);
 
397
        torture_assert(tctx, samr_pipe, "dcerpc_pipe_init failed");
 
398
 
 
399
        samr_handle = samr_pipe->binding_handle;
 
400
 
 
401
        torture_assert_ntstatus_ok(tctx,
 
402
                dcerpc_pipe_open_smb(samr_pipe, cli->tree, "\\samr"),
 
403
                "dcerpc_pipe_open_smb failed");
394
404
 
395
405
        if (admin_creds != NULL) {
396
 
                status = dcerpc_bind_auth(samr_pipe, &ndr_table_samr,
397
 
                                          admin_creds, lp_gensec_settings(lp_ctx, lp_ctx), auth_type, auth_level,
398
 
                                          NULL);
399
 
                if (!NT_STATUS_IS_OK(status)) {
400
 
                        d_printf("dcerpc_bind_auth failed: %s\n",
401
 
                                 nt_errstr(status));
402
 
                        goto fail;
403
 
                }
 
406
                torture_assert_ntstatus_ok(tctx,
 
407
                        dcerpc_bind_auth(samr_pipe, &ndr_table_samr,
 
408
                                          admin_creds, lpcfg_gensec_settings(tctx->lp_ctx, tctx->lp_ctx), auth_type, auth_level,
 
409
                                          NULL),
 
410
                        "dcerpc_bind_auth failed");
404
411
        } else {
405
412
                /* We must have an authenticated SMB connection */
406
 
                status = dcerpc_bind_auth_none(samr_pipe, &ndr_table_samr);
407
 
                if (!NT_STATUS_IS_OK(status)) {
408
 
                        d_printf("dcerpc_bind_auth_none failed: %s\n",
409
 
                                 nt_errstr(status));
410
 
                        goto fail;
411
 
                }
 
413
                torture_assert_ntstatus_ok(tctx,
 
414
                        dcerpc_bind_auth_none(samr_pipe, &ndr_table_samr),
 
415
                        "dcerpc_bind_auth_none failed");
412
416
        }
413
417
 
414
418
        conn.in.system_name = talloc_asprintf(
416
420
        conn.in.access_mask = SEC_FLAG_MAXIMUM_ALLOWED;
417
421
        conn.out.connect_handle = &conn_handle;
418
422
 
419
 
        status = dcerpc_samr_Connect2(samr_pipe, mem_ctx, &conn);
420
 
        if (!NT_STATUS_IS_OK(status)) {
421
 
                d_printf("samr_Connect2 failed: %s\n", nt_errstr(status));
422
 
                goto fail;
423
 
        }
 
423
        torture_assert_ntstatus_ok(tctx,
 
424
                dcerpc_samr_Connect2_r(samr_handle, mem_ctx, &conn),
 
425
                "samr_Connect2 failed");
 
426
        torture_assert_ntstatus_ok(tctx, conn.out.result,
 
427
                "samr_Connect2 failed");
424
428
 
425
429
        enumdom.in.connect_handle = &conn_handle;
426
430
        enumdom.in.resume_handle = &resume_handle;
429
433
        enumdom.out.num_entries = &num_entries;
430
434
        enumdom.out.sam = &sam;
431
435
 
432
 
        status = dcerpc_samr_EnumDomains(samr_pipe, mem_ctx, &enumdom);
433
 
        if (!NT_STATUS_IS_OK(status)) {
434
 
                d_printf("samr_EnumDomains failed: %s\n", nt_errstr(status));
435
 
                goto fail;
436
 
        }
 
436
        torture_assert_ntstatus_ok(tctx,
 
437
                dcerpc_samr_EnumDomains_r(samr_handle, mem_ctx, &enumdom),
 
438
                "samr_EnumDomains failed");
 
439
        torture_assert_ntstatus_ok(tctx, enumdom.out.result,
 
440
                "samr_EnumDomains failed");
437
441
 
438
 
        if (*enumdom.out.num_entries != 2) {
439
 
                d_printf("samr_EnumDomains returned %d entries, expected 2\n",
440
 
                         *enumdom.out.num_entries);
441
 
                status = NT_STATUS_UNSUCCESSFUL;
442
 
                goto fail;
443
 
        }
 
442
        torture_assert_int_equal(tctx, *enumdom.out.num_entries, 2,
 
443
                "samr_EnumDomains returned unexpected num_entries");
444
444
 
445
445
        dom_idx = strequal(sam->entries[0].name.string,
446
446
                           "builtin") ? 1:0;
451
451
        l.in.domain_name = &domain_name;
452
452
        l.out.sid = &sid;
453
453
 
454
 
        status = dcerpc_samr_LookupDomain(samr_pipe, mem_ctx, &l);
455
 
        if (!NT_STATUS_IS_OK(status)) {
456
 
                d_printf("samr_LookupDomain failed: %s\n", nt_errstr(status));
457
 
                goto fail;
458
 
        }
 
454
        torture_assert_ntstatus_ok(tctx,
 
455
                dcerpc_samr_LookupDomain_r(samr_handle, mem_ctx, &l),
 
456
                "samr_LookupDomain failed");
 
457
        torture_assert_ntstatus_ok(tctx, l.out.result,
 
458
                "samr_LookupDomain failed");
459
459
 
460
460
        o.in.connect_handle = &conn_handle;
461
461
        o.in.access_mask = SEC_FLAG_MAXIMUM_ALLOWED;
462
462
        o.in.sid = *l.out.sid;
463
463
        o.out.domain_handle = &domain_handle;
464
464
 
465
 
        status = dcerpc_samr_OpenDomain(samr_pipe, mem_ctx, &o);
466
 
        if (!NT_STATUS_IS_OK(status)) {
467
 
                d_printf("samr_OpenDomain failed: %s\n", nt_errstr(status));
468
 
                goto fail;
469
 
        }
 
465
        torture_assert_ntstatus_ok(tctx,
 
466
                dcerpc_samr_OpenDomain_r(samr_handle, mem_ctx, &o),
 
467
                "samr_OpenDomain failed");
 
468
        torture_assert_ntstatus_ok(tctx, o.out.result,
 
469
                "samr_OpenDomain failed");
470
470
 
471
471
        c.in.domain_handle = &domain_handle;
472
472
        user_name.string = username;
478
478
        c.out.access_granted = &access_granted;
479
479
        c.out.rid = &user_rid;
480
480
 
481
 
        status = dcerpc_samr_CreateUser2(samr_pipe, mem_ctx, &c);
 
481
        torture_assert_ntstatus_ok(tctx,
 
482
                dcerpc_samr_CreateUser2_r(samr_handle, mem_ctx, &c),
 
483
                "samr_CreateUser2 failed");
482
484
 
483
 
        if (NT_STATUS_EQUAL(status, NT_STATUS_USER_EXISTS)) {
 
485
        if (NT_STATUS_EQUAL(c.out.result, NT_STATUS_USER_EXISTS)) {
484
486
                struct samr_LookupNames ln;
485
487
                struct samr_OpenUser ou;
486
488
                struct samr_Ids rids, types;
491
493
                ln.out.rids = &rids;
492
494
                ln.out.types = &types;
493
495
 
494
 
                status = dcerpc_samr_LookupNames(samr_pipe, mem_ctx, &ln);
495
 
                if (!NT_STATUS_IS_OK(status)) {
496
 
                        d_printf("samr_LookupNames failed: %s\n",
497
 
                                 nt_errstr(status));
498
 
                        goto fail;
499
 
                }
 
496
                torture_assert_ntstatus_ok(tctx,
 
497
                        dcerpc_samr_LookupNames_r(samr_handle, mem_ctx, &ln),
 
498
                        "samr_LookupNames failed");
 
499
                torture_assert_ntstatus_ok(tctx, ln.out.result,
 
500
                        "samr_LookupNames failed");
500
501
 
501
502
                ou.in.domain_handle = &domain_handle;
502
503
                ou.in.access_mask = SEC_FLAG_MAXIMUM_ALLOWED;
503
504
                user_rid = ou.in.rid = ln.out.rids->ids[0];
504
505
                ou.out.user_handle = user_handle;
505
506
 
506
 
                status = dcerpc_samr_OpenUser(samr_pipe, mem_ctx, &ou);
507
 
                if (!NT_STATUS_IS_OK(status)) {
508
 
                        d_printf("samr_OpenUser failed: %s\n",
509
 
                                 nt_errstr(status));
510
 
                        goto fail;
511
 
                }
 
507
                torture_assert_ntstatus_ok(tctx,
 
508
                        dcerpc_samr_OpenUser_r(samr_handle, mem_ctx, &ou),
 
509
                        "samr_OpenUser failed");
 
510
                status = ou.out.result;
 
511
        } else {
 
512
                status = c.out.result;
512
513
        }
513
514
 
514
 
        if (!NT_STATUS_IS_OK(status)) {
515
 
                d_printf("samr_CreateUser failed: %s\n", nt_errstr(status));
516
 
                goto fail;
517
 
        }
 
515
        torture_assert_ntstatus_ok(tctx, status,
 
516
                "samr_CreateUser failed");
518
517
 
519
518
        *result_pipe = samr_pipe;
520
519
        *result_handle = user_handle;
521
520
        if (sid_p != NULL) {
522
521
                *sid_p = dom_sid_add_rid(mem_ctx, *l.out.sid, user_rid);
523
522
        }
524
 
        return NT_STATUS_OK;
 
523
        return true;
525
524
 
526
 
 fail:
527
 
        return status;
528
525
}
529
526
 
530
527
/*
531
528
 * Create a test user
532
529
 */
533
530
 
534
 
static bool create_user(TALLOC_CTX *mem_ctx, struct smbcli_state *cli,
535
 
                        struct loadparm_context *lp_ctx,
 
531
static bool create_user(struct torture_context *tctx,
 
532
                        TALLOC_CTX *mem_ctx, struct smbcli_state *cli,
536
533
                        struct cli_credentials *admin_creds,
537
534
                        const char *username, const char *password,
538
535
                        char **domain_name,
541
538
        TALLOC_CTX *tmp_ctx;
542
539
        NTSTATUS status;
543
540
        struct dcerpc_pipe *samr_pipe;
 
541
        struct dcerpc_binding_handle *samr_handle;
544
542
        struct policy_handle *wks_handle;
545
543
        bool ret = false;
546
544
 
547
545
        if (!(tmp_ctx = talloc_new(mem_ctx))) {
548
 
                d_printf("talloc_init failed\n");
 
546
                torture_comment(tctx, "talloc_init failed\n");
549
547
                return false;
550
548
        }
551
549
 
552
 
        status = get_usr_handle(cli, tmp_ctx, lp_ctx, admin_creds,
553
 
                                DCERPC_AUTH_TYPE_NTLMSSP,
554
 
                                DCERPC_AUTH_LEVEL_INTEGRITY,
555
 
                                username, domain_name, &samr_pipe, &wks_handle,
556
 
                                user_sid);
557
 
        if (!NT_STATUS_IS_OK(status)) {
558
 
                d_printf("get_usr_handle failed: %s\n", nt_errstr(status));
 
550
        ret = get_usr_handle(tctx, cli, tmp_ctx, admin_creds,
 
551
                             DCERPC_AUTH_TYPE_NTLMSSP,
 
552
                             DCERPC_AUTH_LEVEL_INTEGRITY,
 
553
                             username, domain_name, &samr_pipe, &wks_handle,
 
554
                             user_sid);
 
555
        if (ret == false) {
 
556
                torture_comment(tctx, "get_usr_handle failed\n");
559
557
                goto done;
560
558
        }
 
559
        samr_handle = samr_pipe->binding_handle;
561
560
 
562
561
        {
563
562
                struct samr_SetUserInfo2 sui2;
574
573
 
575
574
                status = dcerpc_fetch_session_key(samr_pipe, &session_key);
576
575
                if (!NT_STATUS_IS_OK(status)) {
577
 
                        d_printf("dcerpc_fetch_session_key failed\n");
 
576
                        torture_comment(tctx, "dcerpc_fetch_session_key failed\n");
578
577
                        goto done;
579
578
                }
580
579
                arcfour_crypt_blob(u_info.info23.password.data, 516,
587
586
                sui2.in.info = &u_info;
588
587
                sui2.in.level = 23;
589
588
 
590
 
                status = dcerpc_samr_SetUserInfo2(samr_pipe, tmp_ctx, &sui2);
 
589
                status = dcerpc_samr_SetUserInfo2_r(samr_handle, tmp_ctx, &sui2);
591
590
                if (!NT_STATUS_IS_OK(status)) {
592
 
                        d_printf("samr_SetUserInfo(23) failed: %s\n",
 
591
                        torture_comment(tctx, "samr_SetUserInfo(23) failed: %s\n",
593
592
                                 nt_errstr(status));
594
593
                        goto done;
595
594
                }
 
595
                if (!NT_STATUS_IS_OK(sui2.out.result)) {
 
596
                        torture_comment(tctx, "samr_SetUserInfo(23) failed: %s\n",
 
597
                                 nt_errstr(sui2.out.result));
 
598
                        goto done;
 
599
                }
596
600
 
597
601
                u_info.info16.acct_flags = ACB_NORMAL;
598
602
                sui.in.user_handle = wks_handle;
599
603
                sui.in.info = &u_info;
600
604
                sui.in.level = 16;
601
605
 
602
 
                status = dcerpc_samr_SetUserInfo(samr_pipe, tmp_ctx, &sui);
603
 
                if (!NT_STATUS_IS_OK(status)) {
604
 
                        d_printf("samr_SetUserInfo(16) failed\n");
 
606
                status = dcerpc_samr_SetUserInfo_r(samr_handle, tmp_ctx, &sui);
 
607
                if (!NT_STATUS_IS_OK(status) || !NT_STATUS_IS_OK(sui.out.result)) {
 
608
                        torture_comment(tctx, "samr_SetUserInfo(16) failed\n");
605
609
                        goto done;
606
610
                }
607
611
 
609
613
                qui.in.level = 21;
610
614
                qui.out.info = &info;
611
615
 
612
 
                status = dcerpc_samr_QueryUserInfo(samr_pipe, tmp_ctx, &qui);
613
 
                if (!NT_STATUS_IS_OK(status)) {
614
 
                        d_printf("samr_QueryUserInfo(21) failed\n");
 
616
                status = dcerpc_samr_QueryUserInfo_r(samr_handle, tmp_ctx, &qui);
 
617
                if (!NT_STATUS_IS_OK(status) || !NT_STATUS_IS_OK(qui.out.result)) {
 
618
                        torture_comment(tctx, "samr_QueryUserInfo(21) failed\n");
615
619
                        goto done;
616
620
                }
617
621
 
627
631
                sui.in.info = &u_info;
628
632
                sui.in.level = 21;
629
633
 
630
 
                status = dcerpc_samr_SetUserInfo(samr_pipe, tmp_ctx, &sui);
631
 
                if (!NT_STATUS_IS_OK(status)) {
632
 
                        d_printf("samr_SetUserInfo(21) failed\n");
 
634
                status = dcerpc_samr_SetUserInfo_r(samr_handle, tmp_ctx, &sui);
 
635
                if (!NT_STATUS_IS_OK(status) || !NT_STATUS_IS_OK(sui.out.result)) {
 
636
                        torture_comment(tctx, "samr_SetUserInfo(21) failed\n");
633
637
                        goto done;
634
638
                }
635
639
        }
646
650
 * Delete a test user
647
651
 */
648
652
 
649
 
static bool delete_user(struct smbcli_state *cli,
650
 
                        struct loadparm_context *lp_ctx,
 
653
static bool delete_user(struct torture_context *tctx,
 
654
                        struct smbcli_state *cli,
651
655
                        struct cli_credentials *admin_creds,
652
656
                        const char *username)
653
657
{
655
659
        NTSTATUS status;
656
660
        char *dom_name;
657
661
        struct dcerpc_pipe *samr_pipe;
 
662
        struct dcerpc_binding_handle *samr_handle;
658
663
        struct policy_handle *user_handle;
659
664
        bool ret = false;
660
665
 
661
666
        if ((mem_ctx = talloc_init("leave")) == NULL) {
662
 
                d_printf("talloc_init failed\n");
 
667
                torture_comment(tctx, "talloc_init failed\n");
663
668
                return false;
664
669
        }
665
670
 
666
 
        status = get_usr_handle(cli, mem_ctx, lp_ctx, admin_creds,
667
 
                                DCERPC_AUTH_TYPE_NTLMSSP,
668
 
                                DCERPC_AUTH_LEVEL_INTEGRITY,
669
 
                                username, &dom_name, &samr_pipe,
670
 
                                &user_handle, NULL);
671
 
 
672
 
        if (!NT_STATUS_IS_OK(status)) {
673
 
                d_printf("get_wks_handle failed: %s\n", nt_errstr(status));
 
671
        ret = get_usr_handle(tctx, cli, mem_ctx, admin_creds,
 
672
                             DCERPC_AUTH_TYPE_NTLMSSP,
 
673
                             DCERPC_AUTH_LEVEL_INTEGRITY,
 
674
                             username, &dom_name, &samr_pipe,
 
675
                             &user_handle, NULL);
 
676
        if (ret == false) {
 
677
                torture_comment(tctx, "get_wks_handle failed\n");
674
678
                goto done;
675
679
        }
 
680
        samr_handle = samr_pipe->binding_handle;
676
681
 
677
682
        {
678
683
                struct samr_DeleteUser d;
680
685
                d.in.user_handle = user_handle;
681
686
                d.out.user_handle = user_handle;
682
687
 
683
 
                status = dcerpc_samr_DeleteUser(samr_pipe, mem_ctx, &d);
 
688
                status = dcerpc_samr_DeleteUser_r(samr_handle, mem_ctx, &d);
684
689
                if (!NT_STATUS_IS_OK(status)) {
685
 
                        d_printf("samr_DeleteUser failed %s\n", nt_errstr(status));
686
 
                        goto done;
687
 
                }
 
690
                        torture_comment(tctx, "samr_DeleteUser failed %s\n", nt_errstr(status));
 
691
                        goto done;
 
692
                }
 
693
                if (!NT_STATUS_IS_OK(d.out.result)) {
 
694
                        torture_comment(tctx, "samr_DeleteUser failed %s\n", nt_errstr(d.out.result));
 
695
                        goto done;
 
696
                }
 
697
 
688
698
        }
689
699
 
690
700
        ret = true;
698
708
 * Do a Samba3-style join
699
709
 */
700
710
 
701
 
static bool join3(struct smbcli_state *cli,
702
 
                  struct loadparm_context *lp_ctx,
 
711
static bool join3(struct torture_context *tctx,
 
712
                  struct smbcli_state *cli,
703
713
                  bool use_level25,
704
714
                  struct cli_credentials *admin_creds,
705
715
                  struct cli_credentials *wks_creds)
708
718
        NTSTATUS status;
709
719
        char *dom_name;
710
720
        struct dcerpc_pipe *samr_pipe;
 
721
        struct dcerpc_binding_handle *samr_handle;
711
722
        struct policy_handle *wks_handle;
712
723
        bool ret = false;
713
724
        NTTIME last_password_change;
714
725
 
715
726
        if ((mem_ctx = talloc_init("join3")) == NULL) {
716
 
                d_printf("talloc_init failed\n");
 
727
                torture_comment(tctx, "talloc_init failed\n");
717
728
                return false;
718
729
        }
719
730
 
720
 
        status = get_usr_handle(
721
 
                cli, mem_ctx, lp_ctx, admin_creds,
 
731
        ret = get_usr_handle(
 
732
                tctx, cli, mem_ctx, admin_creds,
722
733
                DCERPC_AUTH_TYPE_NTLMSSP,
723
734
                DCERPC_AUTH_LEVEL_PRIVACY,
724
735
                talloc_asprintf(mem_ctx, "%s$",
725
736
                                cli_credentials_get_workstation(wks_creds)),
726
737
                &dom_name, &samr_pipe, &wks_handle, NULL);
727
 
 
728
 
        if (!NT_STATUS_IS_OK(status)) {
729
 
                d_printf("get_wks_handle failed: %s\n", nt_errstr(status));
 
738
        if (ret == false) {
 
739
                torture_comment(tctx, "get_wks_handle failed\n");
730
740
                goto done;
731
741
        }
 
742
        samr_handle = samr_pipe->binding_handle;
732
743
 
733
744
        {
734
745
                struct samr_QueryUserInfo q;
738
749
                q.in.level = 21;
739
750
                q.out.info = &info;
740
751
 
741
 
                status = dcerpc_samr_QueryUserInfo(samr_pipe, mem_ctx, &q);
 
752
                status = dcerpc_samr_QueryUserInfo_r(samr_handle, mem_ctx, &q);
742
753
                if (!NT_STATUS_IS_OK(status)) {
743
 
                        d_printf("(%s) QueryUserInfo failed: %s\n",
744
 
                                  __location__, nt_errstr(status));
745
 
                        goto done;
746
 
                }
 
754
                        torture_warning(tctx, "QueryUserInfo failed: %s\n",
 
755
                                  nt_errstr(status));
 
756
                        goto done;
 
757
                }
 
758
                if (!NT_STATUS_IS_OK(q.out.result)) {
 
759
                        torture_warning(tctx, "QueryUserInfo failed: %s\n",
 
760
                                  nt_errstr(q.out.result));
 
761
                        goto done;
 
762
                }
 
763
 
747
764
 
748
765
                last_password_change = info->info21.last_password_change;
749
766
        }
778
795
                                 STR_UNICODE);
779
796
                status = dcerpc_fetch_session_key(samr_pipe, &session_key);
780
797
                if (!NT_STATUS_IS_OK(status)) {
781
 
                        d_printf("dcerpc_fetch_session_key failed: %s\n",
 
798
                        torture_comment(tctx, "dcerpc_fetch_session_key failed: %s\n",
782
799
                                 nt_errstr(status));
783
800
                        goto done;
784
801
                }
797
814
                sui2.in.level = 25;
798
815
                sui2.in.info = &u_info;
799
816
 
800
 
                status = dcerpc_samr_SetUserInfo2(samr_pipe, mem_ctx, &sui2);
 
817
                status = dcerpc_samr_SetUserInfo2_r(samr_handle, mem_ctx, &sui2);
801
818
                if (!NT_STATUS_IS_OK(status)) {
802
 
                        d_printf("samr_SetUserInfo2(25) failed: %s\n",
 
819
                        torture_comment(tctx, "samr_SetUserInfo2(25) failed: %s\n",
803
820
                                 nt_errstr(status));
804
821
                        goto done;
805
822
                }
 
823
                if (!NT_STATUS_IS_OK(sui2.out.result)) {
 
824
                        torture_comment(tctx, "samr_SetUserInfo2(25) failed: %s\n",
 
825
                                 nt_errstr(sui2.out.result));
 
826
                        goto done;
 
827
                }
806
828
        } else {
807
829
                struct samr_SetUserInfo2 sui2;
808
830
                struct samr_SetUserInfo sui;
817
839
 
818
840
                status = dcerpc_fetch_session_key(samr_pipe, &session_key);
819
841
                if (!NT_STATUS_IS_OK(status)) {
820
 
                        d_printf("dcerpc_fetch_session_key failed\n");
 
842
                        torture_comment(tctx, "dcerpc_fetch_session_key failed\n");
821
843
                        goto done;
822
844
                }
823
845
                arcfour_crypt_blob(u_info.info24.password.data, 516,
826
848
                sui2.in.info = &u_info;
827
849
                sui2.in.level = 24;
828
850
 
829
 
                status = dcerpc_samr_SetUserInfo2(samr_pipe, mem_ctx, &sui2);
 
851
                status = dcerpc_samr_SetUserInfo2_r(samr_handle, mem_ctx, &sui2);
830
852
                if (!NT_STATUS_IS_OK(status)) {
831
 
                        d_printf("samr_SetUserInfo(24) failed: %s\n",
 
853
                        torture_comment(tctx, "samr_SetUserInfo(24) failed: %s\n",
832
854
                                 nt_errstr(status));
833
855
                        goto done;
834
856
                }
 
857
                if (!NT_STATUS_IS_OK(sui2.out.result)) {
 
858
                        torture_comment(tctx, "samr_SetUserInfo(24) failed: %s\n",
 
859
                                 nt_errstr(sui2.out.result));
 
860
                        goto done;
 
861
                }
835
862
 
836
863
                u_info.info16.acct_flags = ACB_WSTRUST;
837
864
                sui.in.user_handle = wks_handle;
838
865
                sui.in.info = &u_info;
839
866
                sui.in.level = 16;
840
867
 
841
 
                status = dcerpc_samr_SetUserInfo(samr_pipe, mem_ctx, &sui);
842
 
                if (!NT_STATUS_IS_OK(status)) {
843
 
                        d_printf("samr_SetUserInfo(16) failed\n");
 
868
                status = dcerpc_samr_SetUserInfo_r(samr_handle, mem_ctx, &sui);
 
869
                if (!NT_STATUS_IS_OK(status) || !NT_STATUS_IS_OK(sui.out.result)) {
 
870
                        torture_comment(tctx, "samr_SetUserInfo(16) failed\n");
844
871
                        goto done;
845
872
                }
846
873
        }
853
880
                q.in.level = 21;
854
881
                q.out.info = &info;
855
882
 
856
 
                status = dcerpc_samr_QueryUserInfo(samr_pipe, mem_ctx, &q);
 
883
                status = dcerpc_samr_QueryUserInfo_r(samr_handle, mem_ctx, &q);
857
884
                if (!NT_STATUS_IS_OK(status)) {
858
 
                        d_printf("(%s) QueryUserInfo failed: %s\n",
859
 
                                  __location__, nt_errstr(status));
 
885
                        torture_warning(tctx, "QueryUserInfo failed: %s\n",
 
886
                                  nt_errstr(status));
 
887
                        goto done;
 
888
                }
 
889
                if (!NT_STATUS_IS_OK(q.out.result)) {
 
890
                        torture_warning(tctx, "QueryUserInfo failed: %s\n",
 
891
                                  nt_errstr(q.out.result));
860
892
                        goto done;
861
893
                }
862
894
 
863
895
                if (use_level25) {
864
896
                        if (last_password_change
865
897
                            == info->info21.last_password_change) {
866
 
                                d_printf("(%s) last_password_change unchanged "
 
898
                                torture_warning(tctx, "last_password_change unchanged "
867
899
                                         "during join, level25 must change "
868
 
                                         "it\n", __location__);
 
900
                                         "it\n");
869
901
                                goto done;
870
902
                        }
871
903
                }
872
904
                else {
873
905
                        if (last_password_change
874
906
                            != info->info21.last_password_change) {
875
 
                                d_printf("(%s) last_password_change changed "
 
907
                                torture_warning(tctx, "last_password_change changed "
876
908
                                         "during join, level24 doesn't "
877
 
                                         "change it\n", __location__);
 
909
                                         "change it\n");
878
910
                                goto done;
879
911
                        }
880
912
                }
891
923
 * Do a ReqChallenge/Auth2 and get the wks creds
892
924
 */
893
925
 
894
 
static bool auth2(struct smbcli_state *cli,
895
 
                  struct loadparm_context *lp_ctx,
 
926
static bool auth2(struct torture_context *tctx,
 
927
                  struct smbcli_state *cli,
896
928
                  struct cli_credentials *wks_cred)
897
929
{
898
930
        TALLOC_CTX *mem_ctx;
899
931
        struct dcerpc_pipe *net_pipe;
 
932
        struct dcerpc_binding_handle *net_handle;
900
933
        bool result = false;
901
934
        NTSTATUS status;
902
935
        struct netr_ServerReqChallenge r;
910
943
 
911
944
        mem_ctx = talloc_new(NULL);
912
945
        if (mem_ctx == NULL) {
913
 
                d_printf("talloc_new failed\n");
 
946
                torture_comment(tctx, "talloc_new failed\n");
914
947
                return false;
915
948
        }
916
949
 
917
950
        net_pipe = dcerpc_pipe_init(mem_ctx,
918
 
                                    cli->transport->socket->event.ctx,
919
 
                                    lp_iconv_convenience(lp_ctx));
 
951
                                    cli->transport->socket->event.ctx);
920
952
        if (net_pipe == NULL) {
921
 
                d_printf("dcerpc_pipe_init failed\n");
 
953
                torture_comment(tctx, "dcerpc_pipe_init failed\n");
922
954
                goto done;
923
955
        }
 
956
        net_handle = net_pipe->binding_handle;
924
957
 
925
958
        status = dcerpc_pipe_open_smb(net_pipe, cli->tree, "\\netlogon");
926
959
        if (!NT_STATUS_IS_OK(status)) {
927
 
                d_printf("dcerpc_pipe_open_smb failed: %s\n",
 
960
                torture_comment(tctx, "dcerpc_pipe_open_smb failed: %s\n",
928
961
                         nt_errstr(status));
929
962
                goto done;
930
963
        }
931
964
 
932
965
        status = dcerpc_bind_auth_none(net_pipe, &ndr_table_netlogon);
933
966
        if (!NT_STATUS_IS_OK(status)) {
934
 
                d_printf("dcerpc_bind_auth_none failed: %s\n",
 
967
                torture_comment(tctx, "dcerpc_bind_auth_none failed: %s\n",
935
968
                         nt_errstr(status));
936
969
                goto done;
937
970
        }
940
973
        r.in.server_name = talloc_asprintf(
941
974
                mem_ctx, "\\\\%s", dcerpc_server_name(net_pipe));
942
975
        if (r.in.server_name == NULL) {
943
 
                d_printf("talloc_asprintf failed\n");
 
976
                torture_comment(tctx, "talloc_asprintf failed\n");
944
977
                goto done;
945
978
        }
946
979
        generate_random_buffer(netr_cli_creds.data,
948
981
        r.in.credentials = &netr_cli_creds;
949
982
        r.out.return_credentials = &netr_srv_creds;
950
983
 
951
 
        status = dcerpc_netr_ServerReqChallenge(net_pipe, mem_ctx, &r);
 
984
        status = dcerpc_netr_ServerReqChallenge_r(net_handle, mem_ctx, &r);
952
985
        if (!NT_STATUS_IS_OK(status)) {
953
 
                d_printf("netr_ServerReqChallenge failed: %s\n",
 
986
                torture_comment(tctx, "netr_ServerReqChallenge failed: %s\n",
954
987
                         nt_errstr(status));
955
988
                goto done;
956
989
        }
 
990
        if (!NT_STATUS_IS_OK(r.out.result)) {
 
991
                torture_comment(tctx, "netr_ServerReqChallenge failed: %s\n",
 
992
                         nt_errstr(r.out.result));
 
993
                goto done;
 
994
        }
957
995
 
958
996
        negotiate_flags = NETLOGON_NEG_AUTH2_FLAGS;
959
997
        E_md4hash(cli_credentials_get_password(wks_cred), mach_pw.hash);
969
1007
        a.in.credentials = &netr_cred;
970
1008
        a.out.return_credentials = &netr_cred;
971
1009
 
972
 
        creds_state = netlogon_creds_client_init(mem_ctx, 
973
 
                                                 a.in.account_name, 
 
1010
        creds_state = netlogon_creds_client_init(mem_ctx,
 
1011
                                                 a.in.account_name,
974
1012
                                                 a.in.computer_name,
975
1013
                                                 r.in.credentials,
976
1014
                                                 r.out.return_credentials, &mach_pw,
977
1015
                                                 &netr_cred, negotiate_flags);
978
1016
 
979
 
        status = dcerpc_netr_ServerAuthenticate2(net_pipe, mem_ctx, &a);
 
1017
        status = dcerpc_netr_ServerAuthenticate2_r(net_handle, mem_ctx, &a);
980
1018
        if (!NT_STATUS_IS_OK(status)) {
981
 
                d_printf("netr_ServerServerAuthenticate2 failed: %s\n",
 
1019
                torture_comment(tctx, "netr_ServerServerAuthenticate2 failed: %s\n",
982
1020
                         nt_errstr(status));
983
1021
                goto done;
984
1022
        }
 
1023
        if (!NT_STATUS_IS_OK(a.out.result)) {
 
1024
                torture_comment(tctx, "netr_ServerServerAuthenticate2 failed: %s\n",
 
1025
                         nt_errstr(a.out.result));
 
1026
                goto done;
 
1027
        }
985
1028
 
986
1029
        if (!netlogon_creds_client_check(creds_state, a.out.return_credentials)) {
987
 
                d_printf("creds_client_check failed\n");
 
1030
                torture_comment(tctx, "creds_client_check failed\n");
988
1031
                goto done;
989
1032
        }
990
1033
 
1002
1045
 * login, and change the wks password
1003
1046
 */
1004
1047
 
1005
 
static bool schan(struct smbcli_state *cli,
1006
 
                  struct loadparm_context *lp_ctx,
 
1048
static bool schan(struct torture_context *tctx,
 
1049
                  struct smbcli_state *cli,
1007
1050
                  struct cli_credentials *wks_creds,
1008
1051
                  struct cli_credentials *user_creds)
1009
1052
{
1011
1054
        NTSTATUS status;
1012
1055
        bool ret = false;
1013
1056
        struct dcerpc_pipe *net_pipe;
 
1057
        struct dcerpc_binding_handle *net_handle;
1014
1058
        int i;
1015
 
        
 
1059
 
1016
1060
        mem_ctx = talloc_new(NULL);
1017
1061
        if (mem_ctx == NULL) {
1018
 
                d_printf("talloc_new failed\n");
 
1062
                torture_comment(tctx, "talloc_new failed\n");
1019
1063
                return false;
1020
1064
        }
1021
1065
 
1022
1066
        net_pipe = dcerpc_pipe_init(mem_ctx,
1023
 
                                    cli->transport->socket->event.ctx,
1024
 
                                    lp_iconv_convenience(lp_ctx));
 
1067
                                    cli->transport->socket->event.ctx);
1025
1068
        if (net_pipe == NULL) {
1026
 
                d_printf("dcerpc_pipe_init failed\n");
 
1069
                torture_comment(tctx, "dcerpc_pipe_init failed\n");
1027
1070
                goto done;
1028
1071
        }
 
1072
        net_handle = net_pipe->binding_handle;
1029
1073
 
1030
1074
        status = dcerpc_pipe_open_smb(net_pipe, cli->tree, "\\netlogon");
1031
1075
        if (!NT_STATUS_IS_OK(status)) {
1032
 
                d_printf("dcerpc_pipe_open_smb failed: %s\n",
 
1076
                torture_comment(tctx, "dcerpc_pipe_open_smb failed: %s\n",
1033
1077
                         nt_errstr(status));
1034
1078
                goto done;
1035
1079
        }
1041
1085
#if 1
1042
1086
        net_pipe->conn->flags |= (DCERPC_SIGN | DCERPC_SEAL);
1043
1087
        status = dcerpc_bind_auth(net_pipe, &ndr_table_netlogon,
1044
 
                                  wks_creds, lp_gensec_settings(lp_ctx, lp_ctx), DCERPC_AUTH_TYPE_SCHANNEL,
 
1088
                                  wks_creds, lpcfg_gensec_settings(tctx->lp_ctx, tctx->lp_ctx), DCERPC_AUTH_TYPE_SCHANNEL,
1045
1089
                                  DCERPC_AUTH_LEVEL_PRIVACY,
1046
1090
                                  NULL);
1047
1091
#else
1048
1092
        status = dcerpc_bind_auth_none(net_pipe, &ndr_table_netlogon);
1049
1093
#endif
1050
1094
        if (!NT_STATUS_IS_OK(status)) {
1051
 
                d_printf("schannel bind failed: %s\n", nt_errstr(status));
 
1095
                torture_comment(tctx, "schannel bind failed: %s\n", nt_errstr(status));
1052
1096
                goto done;
1053
1097
        }
1054
1098
 
1071
1115
 
1072
1116
                chal = data_blob_talloc(mem_ctx, NULL, 8);
1073
1117
                if (chal.data == NULL) {
1074
 
                        d_printf("data_blob_talloc failed\n");
 
1118
                        torture_comment(tctx, "data_blob_talloc failed\n");
1075
1119
                        goto done;
1076
1120
                }
1077
1121
 
1078
1122
                generate_random_buffer(chal.data, chal.length);
1079
1123
                names_blob = NTLMv2_generate_names_blob(
1080
 
                        mem_ctx, 
 
1124
                        mem_ctx,
1081
1125
                        cli_credentials_get_workstation(user_creds),
1082
1126
                        cli_credentials_get_domain(user_creds));
1083
1127
                status = cli_credentials_get_ntlm_response(
1084
1128
                        user_creds, mem_ctx, &flags, chal, names_blob,
1085
1129
                        &lm_resp, &nt_resp, NULL, NULL);
1086
1130
                if (!NT_STATUS_IS_OK(status)) {
1087
 
                        d_printf("cli_credentials_get_ntlm_response failed:"
 
1131
                        torture_comment(tctx, "cli_credentials_get_ntlm_response failed:"
1088
1132
                                 " %s\n", nt_errstr(status));
1089
1133
                        goto done;
1090
1134
                }
1123
1167
                r.out.authoritative = &authoritative;
1124
1168
                r.out.return_authenticator = &return_authenticator;
1125
1169
 
1126
 
                status = dcerpc_netr_LogonSamLogon(net_pipe, mem_ctx, &r);
 
1170
                status = dcerpc_netr_LogonSamLogon_r(net_handle, mem_ctx, &r);
1127
1171
                if (!NT_STATUS_IS_OK(status)) {
1128
 
                        d_printf("netr_LogonSamLogon failed: %s\n",
 
1172
                        torture_comment(tctx, "netr_LogonSamLogon failed: %s\n",
1129
1173
                                 nt_errstr(status));
1130
1174
                        goto done;
1131
1175
                }
 
1176
                if (!NT_STATUS_IS_OK(r.out.result)) {
 
1177
                        torture_comment(tctx, "netr_LogonSamLogon failed: %s\n",
 
1178
                                 nt_errstr(r.out.result));
 
1179
                        goto done;
 
1180
                }
1132
1181
 
1133
1182
                if ((r.out.return_authenticator == NULL) ||
1134
1183
                    (!netlogon_creds_client_check(creds_state,
1135
1184
                                         &r.out.return_authenticator->cred))) {
1136
 
                        d_printf("Credentials check failed!\n");
 
1185
                        torture_comment(tctx, "Credentials check failed!\n");
1137
1186
                        goto done;
1138
1187
                }
1139
1188
 
1155
1204
                r.in.logon = &logon;
1156
1205
                r.out.return_authenticator = &return_authenticator;
1157
1206
 
1158
 
                status = dcerpc_netr_LogonSamLogon(net_pipe, mem_ctx, &r);
 
1207
                status = dcerpc_netr_LogonSamLogon_r(net_handle, mem_ctx, &r);
1159
1208
                if (!NT_STATUS_IS_OK(status)) {
1160
 
                        d_printf("netr_LogonSamLogon failed: %s\n",
 
1209
                        torture_comment(tctx, "netr_LogonSamLogon failed: %s\n",
1161
1210
                                 nt_errstr(status));
1162
1211
                        goto done;
1163
1212
                }
 
1213
                if (!NT_STATUS_IS_OK(r.out.result)) {
 
1214
                        torture_comment(tctx, "netr_LogonSamLogon failed: %s\n",
 
1215
                                 nt_errstr(r.out.result));
 
1216
                        goto done;
 
1217
                }
1164
1218
 
1165
1219
                if ((r.out.return_authenticator == NULL) ||
1166
1220
                    (!netlogon_creds_client_check(creds_state,
1167
1221
                                         &r.out.return_authenticator->cred))) {
1168
 
                        d_printf("Credentials check failed!\n");
 
1222
                        torture_comment(tctx, "Credentials check failed!\n");
1169
1223
                        goto done;
1170
1224
                }
1171
1225
        }
1172
1226
 
1173
1227
        {
1174
1228
                struct netr_ServerPasswordSet s;
1175
 
                char *password = generate_random_str(wks_creds, 8);
 
1229
                char *password = generate_random_password(wks_creds, 8, 255);
1176
1230
                struct netlogon_creds_CredentialState *creds_state;
1177
1231
                struct netr_Authenticator credential, return_authenticator;
1178
1232
                struct samr_Password new_password;
1193
1247
                netlogon_creds_des_encrypt(creds_state, &new_password);
1194
1248
                netlogon_creds_client_authenticator(creds_state, &credential);
1195
1249
 
1196
 
                status = dcerpc_netr_ServerPasswordSet(net_pipe, mem_ctx, &s);
 
1250
                status = dcerpc_netr_ServerPasswordSet_r(net_handle, mem_ctx, &s);
1197
1251
                if (!NT_STATUS_IS_OK(status)) {
1198
 
                        printf("ServerPasswordSet - %s\n", nt_errstr(status));
 
1252
                        torture_comment(tctx, "ServerPasswordSet - %s\n", nt_errstr(status));
 
1253
                        goto done;
 
1254
                }
 
1255
                if (!NT_STATUS_IS_OK(s.out.result)) {
 
1256
                        torture_comment(tctx, "ServerPasswordSet - %s\n", nt_errstr(s.out.result));
1199
1257
                        goto done;
1200
1258
                }
1201
1259
 
1202
1260
                if (!netlogon_creds_client_check(creds_state,
1203
1261
                                                 &s.out.return_authenticator->cred)) {
1204
 
                        printf("Credential chaining failed\n");
 
1262
                        torture_comment(tctx, "Credential chaining failed\n");
1205
1263
                }
1206
1264
 
1207
1265
                cli_credentials_set_password(wks_creds, password,
1218
1276
 * Delete the wks account again
1219
1277
 */
1220
1278
 
1221
 
static bool leave(struct smbcli_state *cli,
1222
 
                  struct loadparm_context *lp_ctx,
 
1279
static bool leave(struct torture_context *tctx,
 
1280
                  struct smbcli_state *cli,
1223
1281
                  struct cli_credentials *admin_creds,
1224
1282
                  struct cli_credentials *wks_creds)
1225
1283
{
1227
1285
                NULL, "%s$", cli_credentials_get_workstation(wks_creds));
1228
1286
        bool ret;
1229
1287
 
1230
 
        ret = delete_user(cli, lp_ctx, admin_creds, wks_name);
 
1288
        ret = delete_user(tctx, cli, admin_creds, wks_name);
1231
1289
        talloc_free(wks_name);
1232
1290
        return ret;
1233
1291
}
1236
1294
 * Test the Samba3 DC code a bit. Join, do some schan netlogon ops, leave
1237
1295
 */
1238
1296
 
1239
 
bool torture_netlogon_samba3(struct torture_context *torture)
 
1297
static bool torture_netlogon_samba3(struct torture_context *torture)
1240
1298
{
1241
 
        TALLOC_CTX *mem_ctx;
1242
1299
        NTSTATUS status;
1243
 
        bool ret = false;
1244
1300
        struct smbcli_state *cli;
1245
1301
        struct cli_credentials *anon_creds;
1246
1302
        struct cli_credentials *wks_creds;
1254
1310
                wks_name = get_myname(torture);
1255
1311
        }
1256
1312
 
1257
 
        mem_ctx = talloc_init("torture_netlogon_samba3");
1258
 
 
1259
 
        if (mem_ctx == NULL) {
1260
 
                d_printf("talloc_init failed\n");
1261
 
                return false;
1262
 
        }
1263
 
 
1264
 
        if (!(anon_creds = cli_credentials_init_anon(mem_ctx))) {
1265
 
                d_printf("create_anon_creds failed\n");
1266
 
                goto done;
1267
 
        }
1268
 
 
1269
 
        lp_smbcli_options(torture->lp_ctx, &options);
1270
 
        lp_smbcli_session_options(torture->lp_ctx, &session_options);
1271
 
 
1272
 
        status = smbcli_full_connection(mem_ctx, &cli,
 
1313
        if (!(anon_creds = cli_credentials_init_anon(torture))) {
 
1314
                torture_fail(torture, "create_anon_creds failed\n");
 
1315
        }
 
1316
 
 
1317
        lpcfg_smbcli_options(torture->lp_ctx, &options);
 
1318
        lpcfg_smbcli_session_options(torture->lp_ctx, &session_options);
 
1319
 
 
1320
        status = smbcli_full_connection(torture, &cli,
1273
1321
                                        torture_setting_string(torture, "host", NULL),
1274
 
                                        lp_smb_ports(torture->lp_ctx),
1275
 
                                        "IPC$", NULL, 
1276
 
                                        lp_socket_options(torture->lp_ctx),
1277
 
                                        anon_creds, 
1278
 
                                        lp_resolve_context(torture->lp_ctx),
 
1322
                                        lpcfg_smb_ports(torture->lp_ctx),
 
1323
                                        "IPC$", NULL,
 
1324
                                        lpcfg_socket_options(torture->lp_ctx),
 
1325
                                        anon_creds,
 
1326
                                        lpcfg_resolve_context(torture->lp_ctx),
1279
1327
                                        torture->ev, &options, &session_options,
1280
 
                                        lp_iconv_convenience(torture->lp_ctx),
1281
 
                                        lp_gensec_settings(torture, torture->lp_ctx));
1282
 
        if (!NT_STATUS_IS_OK(status)) {
1283
 
                d_printf("smbcli_full_connection failed: %s\n",
1284
 
                         nt_errstr(status));
1285
 
                goto done;
1286
 
        }
 
1328
                                        lpcfg_gensec_settings(torture, torture->lp_ctx));
 
1329
        torture_assert_ntstatus_ok(torture, status, "smbcli_full_connection failed\n");
1287
1330
 
1288
 
        wks_creds = cli_credentials_init(mem_ctx);
 
1331
        wks_creds = cli_credentials_init(torture);
1289
1332
        if (wks_creds == NULL) {
1290
 
                d_printf("cli_credentials_init failed\n");
1291
 
                goto done;
 
1333
                torture_fail(torture, "cli_credentials_init failed\n");
1292
1334
        }
1293
1335
 
1294
1336
        cli_credentials_set_conf(wks_creds, torture->lp_ctx);
1296
1338
        cli_credentials_set_username(wks_creds, wks_name, CRED_SPECIFIED);
1297
1339
        cli_credentials_set_workstation(wks_creds, wks_name, CRED_SPECIFIED);
1298
1340
        cli_credentials_set_password(wks_creds,
1299
 
                                     generate_random_str(wks_creds, 8),
 
1341
                                     generate_random_password(wks_creds, 8, 255),
1300
1342
                                     CRED_SPECIFIED);
1301
1343
 
1302
 
        if (!join3(cli, torture->lp_ctx, false, cmdline_credentials, wks_creds)) {
1303
 
                d_printf("join failed\n");
1304
 
                goto done;
1305
 
        }
 
1344
        torture_assert(torture,
 
1345
                join3(torture, cli, false, cmdline_credentials, wks_creds),
 
1346
                "join failed");
1306
1347
 
1307
1348
        cli_credentials_set_domain(
1308
1349
                cmdline_credentials, cli_credentials_get_domain(wks_creds),
1316
1357
 
1317
1358
                int j;
1318
1359
 
1319
 
                if (!auth2(cli, torture->lp_ctx, wks_creds)) {
1320
 
                        d_printf("auth2 failed\n");
1321
 
                        goto done;
1322
 
                }
 
1360
                torture_assert(torture,
 
1361
                        auth2(torture, cli, wks_creds),
 
1362
                        "auth2 failed");
1323
1363
 
1324
1364
                for (j=0; j<2; j++) {
1325
 
                        if (!schan(cli, torture->lp_ctx, wks_creds, cmdline_credentials)) {
1326
 
                                d_printf("schan failed\n");
1327
 
                                goto done;
1328
 
                        }
 
1365
                        torture_assert(torture,
 
1366
                                schan(torture, cli, wks_creds, cmdline_credentials),
 
1367
                                "schan failed");
1329
1368
                }
1330
1369
        }
1331
1370
 
1332
 
        if (!leave(cli, torture->lp_ctx, cmdline_credentials, wks_creds)) {
1333
 
                d_printf("leave failed\n");
1334
 
                goto done;
1335
 
        }
1336
 
 
1337
 
        ret = true;
1338
 
 
1339
 
 done:
1340
 
        talloc_free(mem_ctx);
1341
 
        return ret;
 
1371
        torture_assert(torture,
 
1372
                leave(torture, cli, cmdline_credentials, wks_creds),
 
1373
                "leave failed");
 
1374
 
 
1375
        return true;
1342
1376
}
1343
1377
 
1344
1378
/*
1353
1387
                       const char *wks_name)
1354
1388
{
1355
1389
        NTSTATUS status;
1356
 
        bool ret = false;
1357
1390
        struct smbcli_state *cli;
1358
1391
        struct cli_credentials *wks_creds;
1359
1392
        struct smbcli_options options;
1360
1393
        struct smbcli_session_options session_options;
1361
1394
 
1362
 
        lp_smbcli_options(tctx->lp_ctx, &options);
1363
 
        lp_smbcli_session_options(tctx->lp_ctx, &session_options);
 
1395
        lpcfg_smbcli_options(tctx->lp_ctx, &options);
 
1396
        lpcfg_smbcli_session_options(tctx->lp_ctx, &session_options);
1364
1397
 
1365
1398
        status = smbcli_full_connection(tctx, &cli,
1366
1399
                                        torture_setting_string(tctx, "host", NULL),
1367
 
                                        lp_smb_ports(tctx->lp_ctx),
1368
 
                                        "IPC$", NULL, lp_socket_options(tctx->lp_ctx),
1369
 
                                        smb_creds, lp_resolve_context(tctx->lp_ctx),
 
1400
                                        lpcfg_smb_ports(tctx->lp_ctx),
 
1401
                                        "IPC$", NULL, lpcfg_socket_options(tctx->lp_ctx),
 
1402
                                        smb_creds, lpcfg_resolve_context(tctx->lp_ctx),
1370
1403
                                        tctx->ev, &options, &session_options,
1371
 
                                        lp_iconv_convenience(tctx->lp_ctx),
1372
 
                                        lp_gensec_settings(tctx, tctx->lp_ctx));
1373
 
        if (!NT_STATUS_IS_OK(status)) {
1374
 
                d_printf("smbcli_full_connection failed: %s\n",
1375
 
                         nt_errstr(status));
1376
 
                goto done;
1377
 
        }
 
1404
                                        lpcfg_gensec_settings(tctx, tctx->lp_ctx));
 
1405
        torture_assert_ntstatus_ok(tctx, status,
 
1406
                "smbcli_full_connection failed");
1378
1407
 
1379
1408
        wks_creds = cli_credentials_init(cli);
1380
 
        if (wks_creds == NULL) {
1381
 
                d_printf("cli_credentials_init failed\n");
1382
 
                goto done;
1383
 
        }
 
1409
        torture_assert(tctx, wks_creds, "cli_credentials_init failed");
1384
1410
 
1385
1411
        cli_credentials_set_conf(wks_creds, tctx->lp_ctx);
1386
1412
        cli_credentials_set_secure_channel_type(wks_creds, SEC_CHAN_WKSTA);
1387
1413
        cli_credentials_set_username(wks_creds, wks_name, CRED_SPECIFIED);
1388
1414
        cli_credentials_set_workstation(wks_creds, wks_name, CRED_SPECIFIED);
1389
1415
        cli_credentials_set_password(wks_creds,
1390
 
                                     generate_random_str(wks_creds, 8),
 
1416
                                     generate_random_password(wks_creds, 8, 255),
1391
1417
                                     CRED_SPECIFIED);
1392
1418
 
1393
 
        if (!join3(cli, tctx->lp_ctx, use_level25, samr_creds, wks_creds)) {
1394
 
                d_printf("join failed\n");
1395
 
                goto done;
1396
 
        }
 
1419
        torture_assert(tctx,
 
1420
                join3(tctx, cli, use_level25, samr_creds, wks_creds),
 
1421
                "join failed");
1397
1422
 
1398
1423
        cli_credentials_set_domain(
1399
1424
                cmdline_credentials, cli_credentials_get_domain(wks_creds),
1400
1425
                CRED_SPECIFIED);
1401
1426
 
1402
 
        if (!auth2(cli, tctx->lp_ctx, wks_creds)) {
1403
 
                d_printf("auth2 failed\n");
1404
 
                goto done;
1405
 
        }
 
1427
        torture_assert(tctx,
 
1428
                auth2(tctx, cli, wks_creds),
 
1429
                "auth2 failed");
1406
1430
 
1407
 
        if (!leave(cli, tctx->lp_ctx, samr_creds, wks_creds)) {
1408
 
                d_printf("leave failed\n");
1409
 
                goto done;
1410
 
        }
 
1431
        torture_assert(tctx,
 
1432
                leave(tctx, cli, samr_creds, wks_creds),
 
1433
                "leave failed");
1411
1434
 
1412
1435
        talloc_free(cli);
1413
1436
 
1414
 
        ret = true;
1415
 
 
1416
 
 done:
1417
 
        return ret;
 
1437
        return true;
1418
1438
}
1419
1439
 
1420
1440
/*
1422
1442
 * session key in the setpassword routine. Test the join by doing the auth2.
1423
1443
 */
1424
1444
 
1425
 
bool torture_samba3_sessionkey(struct torture_context *torture)
 
1445
static bool torture_samba3_sessionkey(struct torture_context *torture)
1426
1446
{
1427
 
        bool ret = false;
1428
1447
        struct cli_credentials *anon_creds;
1429
1448
        const char *wks_name;
1430
1449
 
1431
1450
        wks_name = torture_setting_string(torture, "wksname", get_myname(torture));
1432
1451
 
1433
1452
        if (!(anon_creds = cli_credentials_init_anon(torture))) {
1434
 
                d_printf("create_anon_creds failed\n");
1435
 
                goto done;
 
1453
                torture_fail(torture, "create_anon_creds failed\n");
1436
1454
        }
1437
1455
 
1438
1456
        cli_credentials_set_workstation(anon_creds, wks_name, CRED_SPECIFIED);
1439
1457
 
1440
 
        ret = true;
1441
1458
 
1442
1459
        if (!torture_setting_bool(torture, "samba3", false)) {
1443
1460
 
1445
1462
                 * to fix :-) */
1446
1463
 
1447
1464
                if (test_join3(torture, false, anon_creds, NULL, wks_name)) {
1448
 
                        d_printf("join using anonymous bind on an anonymous smb "
 
1465
                        torture_fail(torture, "join using anonymous bind on an anonymous smb "
1449
1466
                                 "connection succeeded -- HUH??\n");
1450
 
                        ret = false;
1451
1467
                }
1452
1468
        }
1453
1469
 
1454
 
        if (!test_join3(torture, false, anon_creds, cmdline_credentials,
1455
 
                        wks_name)) {
1456
 
                d_printf("join using ntlmssp bind on an anonymous smb "
1457
 
                         "connection failed\n");
1458
 
                ret = false;
1459
 
        }
1460
 
 
1461
 
        if (!test_join3(torture, false, cmdline_credentials, NULL, wks_name)) {
1462
 
                d_printf("join using anonymous bind on an authenticated smb "
1463
 
                         "connection failed\n");
1464
 
                ret = false;
1465
 
        }
1466
 
 
1467
 
        if (!test_join3(torture, false, cmdline_credentials,
1468
 
                        cmdline_credentials,
1469
 
                        wks_name)) {
1470
 
                d_printf("join using ntlmssp bind on an authenticated smb "
1471
 
                         "connection failed\n");
1472
 
                ret = false;
1473
 
        }
 
1470
        torture_assert(torture,
 
1471
                test_join3(torture, false, anon_creds, cmdline_credentials, wks_name),
 
1472
                "join using ntlmssp bind on an anonymous smb connection failed");
 
1473
 
 
1474
        torture_assert(torture,
 
1475
                test_join3(torture, false, cmdline_credentials, NULL, wks_name),
 
1476
                "join using anonymous bind on an authenticated smb connection failed");
 
1477
 
 
1478
        torture_assert(torture,
 
1479
                test_join3(torture, false, cmdline_credentials, cmdline_credentials, wks_name),
 
1480
                "join using ntlmssp bind on an authenticated smb connection failed");
1474
1481
 
1475
1482
        /*
1476
1483
         * The following two are tests for setuserinfolevel 25
1477
1484
         */
1478
1485
 
1479
 
        if (!test_join3(torture, true, anon_creds, cmdline_credentials,
1480
 
                        wks_name)) {
1481
 
                d_printf("join using ntlmssp bind on an anonymous smb "
1482
 
                         "connection failed\n");
1483
 
                ret = false;
1484
 
        }
1485
 
 
1486
 
        if (!test_join3(torture, true, cmdline_credentials, NULL, wks_name)) {
1487
 
                d_printf("join using anonymous bind on an authenticated smb "
1488
 
                         "connection failed\n");
1489
 
                ret = false;
1490
 
        }
1491
 
 
1492
 
 done:
1493
 
 
1494
 
        return ret;
 
1486
        torture_assert(torture,
 
1487
                test_join3(torture, true, anon_creds, cmdline_credentials, wks_name),
 
1488
                "join using ntlmssp bind on an anonymous smb connection failed");
 
1489
 
 
1490
        torture_assert(torture,
 
1491
                test_join3(torture, true, cmdline_credentials, NULL, wks_name),
 
1492
                "join using anonymous bind on an authenticated smb connection failed");
 
1493
 
 
1494
        return true;
1495
1495
}
1496
1496
 
1497
1497
/*
1498
1498
 * open pipe and bind, given an IPC$ context
1499
1499
 */
1500
1500
 
1501
 
static NTSTATUS pipe_bind_smb(TALLOC_CTX *mem_ctx,
1502
 
                              struct loadparm_context *lp_ctx,
 
1501
static NTSTATUS pipe_bind_smb(struct torture_context *tctx,
 
1502
                              TALLOC_CTX *mem_ctx,
1503
1503
                              struct smbcli_tree *tree,
1504
1504
                              const char *pipe_name,
1505
1505
                              const struct ndr_interface_table *iface,
1509
1509
        NTSTATUS status;
1510
1510
 
1511
1511
        if (!(result = dcerpc_pipe_init(
1512
 
                      mem_ctx, tree->session->transport->socket->event.ctx, 
1513
 
                      lp_iconv_convenience(lp_ctx)))) {
 
1512
                      mem_ctx, tree->session->transport->socket->event.ctx))) {
1514
1513
                return NT_STATUS_NO_MEMORY;
1515
1514
        }
1516
1515
 
1517
1516
        status = dcerpc_pipe_open_smb(result, tree, pipe_name);
1518
1517
        if (!NT_STATUS_IS_OK(status)) {
1519
 
                d_printf("dcerpc_pipe_open_smb failed: %s\n",
 
1518
                torture_comment(tctx, "dcerpc_pipe_open_smb failed: %s\n",
1520
1519
                         nt_errstr(status));
1521
1520
                talloc_free(result);
1522
1521
                return status;
1524
1523
 
1525
1524
        status = dcerpc_bind_auth_none(result, iface);
1526
1525
        if (!NT_STATUS_IS_OK(status)) {
1527
 
                d_printf("schannel bind failed: %s\n", nt_errstr(status));
 
1526
                torture_comment(tctx, "schannel bind failed: %s\n", nt_errstr(status));
1528
1527
                talloc_free(result);
1529
1528
                return status;
1530
1529
        }
1537
1536
 * Sane wrapper around lsa_LookupNames
1538
1537
 */
1539
1538
 
1540
 
static struct dom_sid *name2sid(TALLOC_CTX *mem_ctx,
 
1539
static struct dom_sid *name2sid(struct torture_context *tctx,
 
1540
                                TALLOC_CTX *mem_ctx,
1541
1541
                                struct dcerpc_pipe *p,
1542
1542
                                const char *name,
1543
1543
                                const char *domain)
1555
1555
        uint32_t count = 0;
1556
1556
        struct dom_sid *result;
1557
1557
        TALLOC_CTX *tmp_ctx;
 
1558
        struct dcerpc_binding_handle *b = p->binding_handle;
1558
1559
 
1559
1560
        if (!(tmp_ctx = talloc_new(mem_ctx))) {
1560
1561
                return NULL;
1577
1578
        r.in.access_mask = SEC_FLAG_MAXIMUM_ALLOWED;
1578
1579
        r.out.handle = &handle;
1579
1580
 
1580
 
        status = dcerpc_lsa_OpenPolicy2(p, tmp_ctx, &r);
 
1581
        status = dcerpc_lsa_OpenPolicy2_r(b, tmp_ctx, &r);
1581
1582
        if (!NT_STATUS_IS_OK(status)) {
1582
 
                printf("OpenPolicy2 failed - %s\n", nt_errstr(status));
 
1583
                torture_comment(tctx, "OpenPolicy2 failed - %s\n", nt_errstr(status));
 
1584
                talloc_free(tmp_ctx);
 
1585
                return NULL;
 
1586
        }
 
1587
        if (!NT_STATUS_IS_OK(r.out.result)) {
 
1588
                torture_comment(tctx, "OpenPolicy2 failed - %s\n", nt_errstr(r.out.result));
1583
1589
                talloc_free(tmp_ctx);
1584
1590
                return NULL;
1585
1591
        }
1599
1605
        l.out.sids = &sids;
1600
1606
        l.out.domains = &domains;
1601
1607
 
1602
 
        status = dcerpc_lsa_LookupNames(p, tmp_ctx, &l);
 
1608
        status = dcerpc_lsa_LookupNames_r(b, tmp_ctx, &l);
1603
1609
        if (!NT_STATUS_IS_OK(status)) {
1604
 
                printf("LookupNames of %s failed - %s\n", lsa_name.string, 
 
1610
                torture_comment(tctx, "LookupNames of %s failed - %s\n", lsa_name.string,
1605
1611
                       nt_errstr(status));
1606
1612
                talloc_free(tmp_ctx);
1607
1613
                return NULL;
1608
1614
        }
 
1615
        if (!NT_STATUS_IS_OK(l.out.result)) {
 
1616
                torture_comment(tctx, "LookupNames of %s failed - %s\n", lsa_name.string,
 
1617
                       nt_errstr(l.out.result));
 
1618
                talloc_free(tmp_ctx);
 
1619
                return NULL;
 
1620
        }
1609
1621
 
1610
1622
        result = dom_sid_add_rid(mem_ctx, domains->domains[0].sid,
1611
1623
                                 l.out.sids->sids[0].rid);
1613
1625
        c.in.handle = &handle;
1614
1626
        c.out.handle = &handle;
1615
1627
 
1616
 
        status = dcerpc_lsa_Close(p, tmp_ctx, &c);
 
1628
        status = dcerpc_lsa_Close_r(b, tmp_ctx, &c);
1617
1629
        if (!NT_STATUS_IS_OK(status)) {
1618
 
                printf("dcerpc_lsa_Close failed - %s\n", nt_errstr(status));
1619
 
                talloc_free(tmp_ctx);
1620
 
                return NULL;
1621
 
        }
1622
 
        
 
1630
                torture_comment(tctx, "dcerpc_lsa_Close failed - %s\n", nt_errstr(status));
 
1631
                talloc_free(tmp_ctx);
 
1632
                return NULL;
 
1633
        }
 
1634
        if (!NT_STATUS_IS_OK(c.out.result)) {
 
1635
                torture_comment(tctx, "dcerpc_lsa_Close failed - %s\n", nt_errstr(c.out.result));
 
1636
                talloc_free(tmp_ctx);
 
1637
                return NULL;
 
1638
        }
 
1639
 
1623
1640
        talloc_free(tmp_ctx);
1624
1641
        return result;
1625
1642
}
1628
1645
 * Find out the user SID on this connection
1629
1646
 */
1630
1647
 
1631
 
static struct dom_sid *whoami(TALLOC_CTX *mem_ctx, 
1632
 
                              struct loadparm_context *lp_ctx, 
 
1648
static struct dom_sid *whoami(struct torture_context *tctx,
 
1649
                              TALLOC_CTX *mem_ctx,
1633
1650
                              struct smbcli_tree *tree)
1634
1651
{
1635
1652
        struct dcerpc_pipe *lsa;
 
1653
        struct dcerpc_binding_handle *lsa_handle;
1636
1654
        struct lsa_GetUserName r;
1637
1655
        NTSTATUS status;
1638
1656
        struct lsa_String *authority_name_p = NULL;
1639
1657
        struct lsa_String *account_name_p = NULL;
1640
1658
        struct dom_sid *result;
1641
1659
 
1642
 
        status = pipe_bind_smb(mem_ctx, lp_ctx, tree, "\\pipe\\lsarpc",
 
1660
        status = pipe_bind_smb(tctx, mem_ctx, tree, "\\pipe\\lsarpc",
1643
1661
                               &ndr_table_lsarpc, &lsa);
1644
1662
        if (!NT_STATUS_IS_OK(status)) {
1645
 
                d_printf("(%s) Could not bind to LSA: %s\n",
1646
 
                         __location__, nt_errstr(status));
 
1663
                torture_warning(tctx, "Could not bind to LSA: %s\n",
 
1664
                         nt_errstr(status));
1647
1665
                return NULL;
1648
1666
        }
 
1667
        lsa_handle = lsa->binding_handle;
1649
1668
 
1650
1669
        r.in.system_name = "\\";
1651
1670
        r.in.account_name = &account_name_p;
1652
1671
        r.in.authority_name = &authority_name_p;
1653
1672
        r.out.account_name = &account_name_p;
1654
1673
 
1655
 
        status = dcerpc_lsa_GetUserName(lsa, mem_ctx, &r);
 
1674
        status = dcerpc_lsa_GetUserName_r(lsa_handle, mem_ctx, &r);
1656
1675
 
1657
1676
        authority_name_p = *r.out.authority_name;
1658
1677
 
1659
1678
        if (!NT_STATUS_IS_OK(status)) {
1660
 
                printf("(%s) GetUserName failed - %s\n",
1661
 
                       __location__, nt_errstr(status));
 
1679
                torture_warning(tctx, "GetUserName failed - %s\n",
 
1680
                       nt_errstr(status));
 
1681
                talloc_free(lsa);
 
1682
                return NULL;
 
1683
        }
 
1684
        if (!NT_STATUS_IS_OK(r.out.result)) {
 
1685
                torture_warning(tctx, "GetUserName failed - %s\n",
 
1686
                       nt_errstr(r.out.result));
1662
1687
                talloc_free(lsa);
1663
1688
                return NULL;
1664
1689
        }
1665
1690
 
1666
 
        result = name2sid(mem_ctx, lsa, account_name_p->string,
 
1691
        result = name2sid(tctx, mem_ctx, lsa, account_name_p->string,
1667
1692
                          authority_name_p->string);
1668
1693
 
1669
1694
        talloc_free(lsa);
1680
1705
 * Do a tcon, given a session
1681
1706
 */
1682
1707
 
1683
 
NTSTATUS secondary_tcon(TALLOC_CTX *mem_ctx,
1684
 
                        struct smbcli_session *session,
1685
 
                        const char *sharename,
1686
 
                        struct smbcli_tree **res)
 
1708
static NTSTATUS secondary_tcon(struct torture_context *tctx,
 
1709
                               TALLOC_CTX *mem_ctx,
 
1710
                               struct smbcli_session *session,
 
1711
                               const char *sharename,
 
1712
                               struct smbcli_tree **res)
1687
1713
{
1688
1714
        struct smbcli_tree *result;
1689
1715
        TALLOC_CTX *tmp_ctx;
1707
1733
 
1708
1734
        status = smb_raw_tcon(result, tmp_ctx, &tcon);
1709
1735
        if (!NT_STATUS_IS_OK(status)) {
1710
 
                d_printf("(%s) smb_raw_tcon failed: %s\n", __location__,
 
1736
                torture_warning(tctx, "smb_raw_tcon failed: %s\n",
1711
1737
                         nt_errstr(status));
1712
1738
                talloc_free(tmp_ctx);
1713
1739
                return status;
1725
1751
 * Test the getusername behaviour
1726
1752
 */
1727
1753
 
1728
 
bool torture_samba3_rpc_getusername(struct torture_context *torture)
 
1754
static bool torture_samba3_rpc_getusername(struct torture_context *torture)
1729
1755
{
1730
1756
        NTSTATUS status;
1731
1757
        struct smbcli_state *cli;
1732
 
        TALLOC_CTX *mem_ctx;
1733
1758
        bool ret = true;
1734
1759
        struct dom_sid *user_sid;
1735
1760
        struct dom_sid *created_sid;
1739
1764
        struct smbcli_options options;
1740
1765
        struct smbcli_session_options session_options;
1741
1766
 
1742
 
        if (!(mem_ctx = talloc_new(torture))) {
1743
 
                return false;
1744
 
        }
1745
 
 
1746
 
        lp_smbcli_options(torture->lp_ctx, &options);
1747
 
        lp_smbcli_session_options(torture->lp_ctx, &session_options);
 
1767
        lpcfg_smbcli_options(torture->lp_ctx, &options);
 
1768
        lpcfg_smbcli_session_options(torture->lp_ctx, &session_options);
1748
1769
 
1749
1770
        status = smbcli_full_connection(
1750
 
                mem_ctx, &cli, torture_setting_string(torture, "host", NULL),
1751
 
                lp_smb_ports(torture->lp_ctx),
1752
 
                "IPC$", NULL, lp_socket_options(torture->lp_ctx), cmdline_credentials, 
1753
 
                lp_resolve_context(torture->lp_ctx),
1754
 
                torture->ev, &options, &session_options,
1755
 
                lp_iconv_convenience(torture->lp_ctx),
1756
 
                lp_gensec_settings(torture, torture->lp_ctx));
1757
 
        if (!NT_STATUS_IS_OK(status)) {
1758
 
                d_printf("(%s) smbcli_full_connection failed: %s\n",
1759
 
                         __location__, nt_errstr(status));
1760
 
                ret = false;
1761
 
                goto done;
1762
 
        }
 
1771
                torture, &cli, torture_setting_string(torture, "host", NULL),
 
1772
                lpcfg_smb_ports(torture->lp_ctx),
 
1773
                "IPC$", NULL, lpcfg_socket_options(torture->lp_ctx), cmdline_credentials,
 
1774
                lpcfg_resolve_context(torture->lp_ctx), torture->ev, &options,
 
1775
                &session_options, lpcfg_gensec_settings(torture, torture->lp_ctx));
 
1776
        torture_assert_ntstatus_ok(torture, status, "smbcli_full_connection failed\n");
1763
1777
 
1764
 
        if (!(user_sid = whoami(mem_ctx, torture->lp_ctx, cli->tree))) {
1765
 
                d_printf("(%s) whoami on auth'ed connection failed\n",
1766
 
                         __location__);
1767
 
                ret = false;
 
1778
        if (!(user_sid = whoami(torture, torture, cli->tree))) {
 
1779
                torture_fail(torture, "whoami on auth'ed connection failed\n");
1768
1780
        }
1769
1781
 
1770
1782
        talloc_free(cli);
1771
1783
 
1772
 
        if (!(anon_creds = cli_credentials_init_anon(mem_ctx))) {
1773
 
                d_printf("(%s) create_anon_creds failed\n", __location__);
1774
 
                ret = false;
1775
 
                goto done;
 
1784
        if (!(anon_creds = cli_credentials_init_anon(torture))) {
 
1785
                torture_fail(torture, "create_anon_creds failed\n");
1776
1786
        }
1777
1787
 
1778
1788
        status = smbcli_full_connection(
1779
 
                mem_ctx, &cli, torture_setting_string(torture, "host", NULL),
1780
 
                lp_smb_ports(torture->lp_ctx), "IPC$", NULL, 
1781
 
                lp_socket_options(torture->lp_ctx), anon_creds, 
1782
 
                lp_resolve_context(torture->lp_ctx),
 
1789
                torture, &cli, torture_setting_string(torture, "host", NULL),
 
1790
                lpcfg_smb_ports(torture->lp_ctx), "IPC$", NULL,
 
1791
                lpcfg_socket_options(torture->lp_ctx), anon_creds,
 
1792
                lpcfg_resolve_context(torture->lp_ctx),
1783
1793
                torture->ev, &options, &session_options,
1784
 
                lp_iconv_convenience(torture->lp_ctx),
1785
 
                lp_gensec_settings(torture, torture->lp_ctx));
1786
 
        if (!NT_STATUS_IS_OK(status)) {
1787
 
                d_printf("(%s) anon smbcli_full_connection failed: %s\n",
1788
 
                         __location__, nt_errstr(status));
1789
 
                ret = false;
1790
 
                goto done;
1791
 
        }
1792
 
 
1793
 
        if (!(user_sid = whoami(mem_ctx, torture->lp_ctx, cli->tree))) {
1794
 
                d_printf("(%s) whoami on anon connection failed\n",
1795
 
                         __location__);
1796
 
                ret = false;
1797
 
                goto done;
1798
 
        }
1799
 
 
1800
 
        if (!dom_sid_equal(user_sid,
1801
 
                           dom_sid_parse_talloc(mem_ctx, "s-1-5-7"))) {
1802
 
                d_printf("(%s) Anon lsa_GetUserName returned %s, expected "
1803
 
                         "S-1-5-7", __location__,
1804
 
                         dom_sid_string(mem_ctx, user_sid));
1805
 
                ret = false;
1806
 
        }
1807
 
 
1808
 
        if (!(user_creds = cli_credentials_init(mem_ctx))) {
1809
 
                d_printf("(%s) cli_credentials_init failed\n", __location__);
1810
 
                ret = false;
1811
 
                goto done;
 
1794
                lpcfg_gensec_settings(torture, torture->lp_ctx));
 
1795
        torture_assert_ntstatus_ok(torture, status, "anon smbcli_full_connection failed\n");
 
1796
 
 
1797
        if (!(user_sid = whoami(torture, torture, cli->tree))) {
 
1798
                torture_fail(torture, "whoami on anon connection failed\n");
 
1799
        }
 
1800
 
 
1801
        torture_assert_sid_equal(torture, user_sid, dom_sid_parse_talloc(torture, "s-1-5-7"),
 
1802
                "Anon lsa_GetUserName returned unexpected SID");
 
1803
 
 
1804
        if (!(user_creds = cli_credentials_init(torture))) {
 
1805
                torture_fail(torture, "cli_credentials_init failed\n");
1812
1806
        }
1813
1807
 
1814
1808
        cli_credentials_set_conf(user_creds, torture->lp_ctx);
1815
1809
        cli_credentials_set_username(user_creds, "torture_username",
1816
1810
                                     CRED_SPECIFIED);
1817
1811
        cli_credentials_set_password(user_creds,
1818
 
                                     generate_random_str(user_creds, 8),
 
1812
                                     generate_random_password(user_creds, 8, 255),
1819
1813
                                     CRED_SPECIFIED);
1820
1814
 
1821
 
        if (!create_user(mem_ctx, cli, torture->lp_ctx, cmdline_credentials,
 
1815
        if (!create_user(torture, torture, cli, cmdline_credentials,
1822
1816
                         cli_credentials_get_username(user_creds),
1823
1817
                         cli_credentials_get_password(user_creds),
1824
1818
                         &domain_name, &created_sid)) {
1825
 
                d_printf("(%s) create_user failed\n", __location__);
1826
 
                ret = false;
1827
 
                goto done;
 
1819
                torture_fail(torture, "create_user failed\n");
1828
1820
        }
1829
1821
 
1830
1822
        cli_credentials_set_domain(user_creds, domain_name,
1835
1827
                struct smb_composite_sesssetup setup;
1836
1828
                struct smbcli_tree *tree;
1837
1829
 
1838
 
                session2 = smbcli_session_init(cli->transport, mem_ctx, false, session_options);
 
1830
                session2 = smbcli_session_init(cli->transport, torture, false, session_options);
1839
1831
                if (session2 == NULL) {
1840
 
                        d_printf("(%s) smbcli_session_init failed\n",
1841
 
                                 __location__);
1842
 
                        goto done;
 
1832
                        torture_fail(torture, "smbcli_session_init failed\n");
1843
1833
                }
1844
1834
 
1845
1835
                setup.in.sesskey = cli->transport->negotiate.sesskey;
1846
1836
                setup.in.capabilities = cli->transport->negotiate.capabilities;
1847
1837
                setup.in.workgroup = "";
1848
1838
                setup.in.credentials = user_creds;
1849
 
                setup.in.gensec_settings = lp_gensec_settings(torture, torture->lp_ctx);
 
1839
                setup.in.gensec_settings = lpcfg_gensec_settings(torture, torture->lp_ctx);
1850
1840
 
1851
1841
                status = smb_composite_sesssetup(session2, &setup);
1852
 
                if (!NT_STATUS_IS_OK(status)) {
1853
 
                        d_printf("(%s) session setup with new user failed: "
1854
 
                                 "%s\n", __location__, nt_errstr(status));
1855
 
                        ret = false;
1856
 
                        goto done;
1857
 
                }
 
1842
                torture_assert_ntstatus_ok(torture, status, "session setup with new user failed");
 
1843
 
1858
1844
                session2->vuid = setup.out.vuid;
1859
1845
 
1860
 
                if (!NT_STATUS_IS_OK(secondary_tcon(mem_ctx, session2,
 
1846
                if (!NT_STATUS_IS_OK(secondary_tcon(torture, torture, session2,
1861
1847
                                                    "IPC$", &tree))) {
1862
 
                        d_printf("(%s) secondary_tcon failed\n",
1863
 
                                 __location__);
1864
 
                        ret = false;
1865
 
                        goto done;
 
1848
                        torture_fail(torture, "secondary_tcon failed\n");
1866
1849
                }
1867
1850
 
1868
 
                if (!(user_sid = whoami(mem_ctx, torture->lp_ctx, tree))) {
1869
 
                        d_printf("(%s) whoami on user connection failed\n",
1870
 
                                 __location__);
 
1851
                if (!(user_sid = whoami(torture, torture, tree))) {
 
1852
                        torture_fail_goto(torture, del, "whoami on user connection failed\n");
1871
1853
                        ret = false;
1872
1854
                        goto del;
1873
1855
                }
1875
1857
                talloc_free(tree);
1876
1858
        }
1877
1859
 
1878
 
        d_printf("Created %s, found %s\n",
1879
 
                 dom_sid_string(mem_ctx, created_sid),
1880
 
                 dom_sid_string(mem_ctx, user_sid));
 
1860
        torture_comment(torture, "Created %s, found %s\n",
 
1861
                 dom_sid_string(torture, created_sid),
 
1862
                 dom_sid_string(torture, user_sid));
1881
1863
 
1882
1864
        if (!dom_sid_equal(created_sid, user_sid)) {
1883
1865
                ret = false;
1884
1866
        }
1885
1867
 
1886
1868
 del:
1887
 
        if (!delete_user(cli, torture->lp_ctx, 
 
1869
        if (!delete_user(torture, cli,
1888
1870
                         cmdline_credentials,
1889
1871
                         cli_credentials_get_username(user_creds))) {
1890
 
                d_printf("(%s) delete_user failed\n", __location__);
1891
 
                ret = false;
 
1872
                torture_fail(torture, "delete_user failed\n");
1892
1873
        }
1893
1874
 
1894
 
 done:
1895
 
        talloc_free(mem_ctx);
1896
1875
        return ret;
1897
1876
}
1898
1877
 
1899
 
static bool test_NetShareGetInfo(struct dcerpc_pipe *p, TALLOC_CTX *mem_ctx,
 
1878
static bool test_NetShareGetInfo(struct torture_context *tctx,
 
1879
                                 struct dcerpc_pipe *p,
1900
1880
                                 const char *sharename)
1901
1881
{
1902
1882
        NTSTATUS status;
1905
1885
        uint32_t levels[] = { 0, 1, 2, 501, 502, 1004, 1005, 1006, 1007, 1501 };
1906
1886
        int i;
1907
1887
        bool ret = true;
 
1888
        struct dcerpc_binding_handle *b = p->binding_handle;
1908
1889
 
1909
 
        r.in.server_unc = talloc_asprintf(mem_ctx, "\\\\%s",
 
1890
        r.in.server_unc = talloc_asprintf(tctx, "\\\\%s",
1910
1891
                                          dcerpc_server_name(p));
1911
1892
        r.in.share_name = sharename;
1912
1893
        r.out.info = &info;
1914
1895
        for (i=0;i<ARRAY_SIZE(levels);i++) {
1915
1896
                r.in.level = levels[i];
1916
1897
 
1917
 
                printf("testing NetShareGetInfo level %u on share '%s'\n", 
 
1898
                torture_comment(tctx, "Testing NetShareGetInfo level %u on share '%s'\n",
1918
1899
                       r.in.level, r.in.share_name);
1919
1900
 
1920
 
                status = dcerpc_srvsvc_NetShareGetInfo(p, mem_ctx, &r);
 
1901
                status = dcerpc_srvsvc_NetShareGetInfo_r(b, tctx, &r);
1921
1902
                if (!NT_STATUS_IS_OK(status)) {
1922
 
                        printf("NetShareGetInfo level %u on share '%s' failed"
 
1903
                        torture_warning(tctx, "NetShareGetInfo level %u on share '%s' failed"
1923
1904
                               " - %s\n", r.in.level, r.in.share_name,
1924
1905
                               nt_errstr(status));
1925
1906
                        ret = false;
1926
1907
                        continue;
1927
1908
                }
1928
1909
                if (!W_ERROR_IS_OK(r.out.result)) {
1929
 
                        printf("NetShareGetInfo level %u on share '%s' failed "
 
1910
                        torture_warning(tctx, "NetShareGetInfo level %u on share '%s' failed "
1930
1911
                               "- %s\n", r.in.level, r.in.share_name,
1931
1912
                               win_errstr(r.out.result));
1932
1913
                        ret = false;
1937
1918
        return ret;
1938
1919
}
1939
1920
 
1940
 
static bool test_NetShareEnum(struct dcerpc_pipe *p, TALLOC_CTX *mem_ctx,
 
1921
static bool test_NetShareEnum(struct torture_context *tctx,
 
1922
                              struct dcerpc_pipe *p,
1941
1923
                              const char **one_sharename)
1942
1924
{
1943
1925
        NTSTATUS status;
1956
1938
        uint32_t levels[] = { 0, 1, 2, 501, 502, 1004, 1005, 1006, 1007 };
1957
1939
        int i;
1958
1940
        bool ret = true;
 
1941
        struct dcerpc_binding_handle *b = p->binding_handle;
1959
1942
 
1960
1943
        ZERO_STRUCT(info_ctr);
1961
1944
 
1962
 
        r.in.server_unc = talloc_asprintf(mem_ctx,"\\\\%s",dcerpc_server_name(p));
 
1945
        r.in.server_unc = talloc_asprintf(tctx,"\\\\%s",dcerpc_server_name(p));
1963
1946
        r.in.info_ctr = &info_ctr;
1964
1947
        r.in.max_buffer = (uint32_t)-1;
1965
1948
        r.in.resume_handle = NULL;
2008
1991
                        break;
2009
1992
                }
2010
1993
 
2011
 
                printf("testing NetShareEnum level %u\n", info_ctr.level);
2012
 
                status = dcerpc_srvsvc_NetShareEnum(p, mem_ctx, &r);
 
1994
                torture_comment(tctx, "Testing NetShareEnum level %u\n", info_ctr.level);
 
1995
 
 
1996
                status = dcerpc_srvsvc_NetShareEnum_r(b, tctx, &r);
2013
1997
                if (!NT_STATUS_IS_OK(status)) {
2014
 
                        printf("NetShareEnum level %u failed - %s\n",
 
1998
                        torture_warning(tctx, "NetShareEnum level %u failed - %s\n",
2015
1999
                               info_ctr.level, nt_errstr(status));
2016
2000
                        ret = false;
2017
2001
                        continue;
2018
2002
                }
2019
2003
                if (!W_ERROR_IS_OK(r.out.result)) {
2020
 
                        printf("NetShareEnum level %u failed - %s\n",
 
2004
                        torture_warning(tctx, "NetShareEnum level %u failed - %s\n",
2021
2005
                               info_ctr.level, win_errstr(r.out.result));
2022
2006
                        continue;
2023
2007
                }
2032
2016
        return ret;
2033
2017
}
2034
2018
 
2035
 
bool torture_samba3_rpc_srvsvc(struct torture_context *torture)
 
2019
static bool torture_samba3_rpc_srvsvc(struct torture_context *torture)
2036
2020
{
2037
2021
        struct dcerpc_pipe *p;
2038
 
        TALLOC_CTX *mem_ctx;
2039
 
        bool ret = true;
2040
2022
        const char *sharename = NULL;
2041
 
        struct smbcli_state *cli;
2042
 
        NTSTATUS status;
2043
 
 
2044
 
        if (!(mem_ctx = talloc_new(torture))) {
2045
 
                return false;
2046
 
        }
2047
 
 
2048
 
        if (!(torture_open_connection_share(
2049
 
                      mem_ctx, &cli, torture, torture_setting_string(torture, "host", NULL),
2050
 
                      "IPC$", torture->ev))) {
2051
 
                talloc_free(mem_ctx);
2052
 
                return false;
2053
 
        }
2054
 
 
2055
 
        status = pipe_bind_smb(mem_ctx, torture->lp_ctx, cli->tree, 
2056
 
                               "\\pipe\\srvsvc", &ndr_table_srvsvc, &p);
2057
 
        if (!NT_STATUS_IS_OK(status)) {
2058
 
                d_printf("(%s) could not bind to srvsvc pipe: %s\n",
2059
 
                         __location__, nt_errstr(status));
2060
 
                ret = false;
2061
 
                goto done;
2062
 
        }
2063
 
 
2064
 
        ret &= test_NetShareEnum(p, mem_ctx, &sharename);
 
2023
        bool ret = true;
 
2024
 
 
2025
        torture_assert_ntstatus_ok(torture,
 
2026
                torture_rpc_connection(torture, &p, &ndr_table_srvsvc),
 
2027
                "failed to open srvsvc");
 
2028
 
 
2029
        ret &= test_NetShareEnum(torture, p, &sharename);
2065
2030
        if (sharename == NULL) {
2066
 
                printf("did not get sharename\n");
 
2031
                torture_comment(torture, "did not get sharename\n");
2067
2032
        } else {
2068
 
                ret &= test_NetShareGetInfo(p, mem_ctx, sharename);
 
2033
                ret &= test_NetShareGetInfo(torture, p, sharename);
2069
2034
        }
2070
2035
 
2071
 
 done:
2072
 
        talloc_free(mem_ctx);
2073
2036
        return ret;
2074
2037
}
2075
2038
 
2078
2041
 * NT_STATUS_NO_SAM_ACCOUNT
2079
2042
 */
2080
2043
 
2081
 
bool torture_samba3_rpc_randomauth2(struct torture_context *torture)
 
2044
static bool torture_samba3_rpc_randomauth2(struct torture_context *torture)
2082
2045
{
2083
2046
        TALLOC_CTX *mem_ctx;
2084
2047
        struct dcerpc_pipe *net_pipe;
 
2048
        struct dcerpc_binding_handle *net_handle;
2085
2049
        char *wksname;
2086
2050
        bool result = false;
2087
2051
        NTSTATUS status;
2096
2060
        struct smbcli_state *cli;
2097
2061
 
2098
2062
        if (!(mem_ctx = talloc_new(torture))) {
2099
 
                d_printf("talloc_new failed\n");
 
2063
                torture_comment(torture, "talloc_new failed\n");
2100
2064
                return false;
2101
2065
        }
2102
2066
 
2103
2067
        if (!(wksname = generate_random_str_list(
2104
2068
                      mem_ctx, 14, "ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789"))) {
2105
 
                d_printf("generate_random_str_list failed\n");
 
2069
                torture_comment(torture, "generate_random_str_list failed\n");
2106
2070
                goto done;
2107
2071
        }
2108
2072
 
2110
2074
                      mem_ctx, &cli,
2111
2075
                      torture, torture_setting_string(torture, "host", NULL),
2112
2076
                      "IPC$", torture->ev))) {
2113
 
                d_printf("IPC$ connection failed\n");
 
2077
                torture_comment(torture, "IPC$ connection failed\n");
2114
2078
                goto done;
2115
2079
        }
2116
2080
 
2117
2081
        if (!(net_pipe = dcerpc_pipe_init(
2118
 
                      mem_ctx, cli->transport->socket->event.ctx,
2119
 
                      lp_iconv_convenience(torture->lp_ctx)))) {
2120
 
                d_printf("dcerpc_pipe_init failed\n");
 
2082
                      mem_ctx, cli->transport->socket->event.ctx))) {
 
2083
                torture_comment(torture, "dcerpc_pipe_init failed\n");
2121
2084
                goto done;
2122
2085
        }
 
2086
        net_handle = net_pipe->binding_handle;
2123
2087
 
2124
2088
        status = dcerpc_pipe_open_smb(net_pipe, cli->tree, "\\netlogon");
2125
2089
        if (!NT_STATUS_IS_OK(status)) {
2126
 
                d_printf("dcerpc_pipe_open_smb failed: %s\n",
 
2090
                torture_comment(torture, "dcerpc_pipe_open_smb failed: %s\n",
2127
2091
                         nt_errstr(status));
2128
2092
                goto done;
2129
2093
        }
2130
2094
 
2131
2095
        status = dcerpc_bind_auth_none(net_pipe, &ndr_table_netlogon);
2132
2096
        if (!NT_STATUS_IS_OK(status)) {
2133
 
                d_printf("dcerpc_bind_auth_none failed: %s\n",
 
2097
                torture_comment(torture, "dcerpc_bind_auth_none failed: %s\n",
2134
2098
                         nt_errstr(status));
2135
2099
                goto done;
2136
2100
        }
2139
2103
        r.in.server_name = talloc_asprintf(
2140
2104
                mem_ctx, "\\\\%s", dcerpc_server_name(net_pipe));
2141
2105
        if (r.in.server_name == NULL) {
2142
 
                d_printf("talloc_asprintf failed\n");
 
2106
                torture_comment(torture, "talloc_asprintf failed\n");
2143
2107
                goto done;
2144
2108
        }
2145
2109
        generate_random_buffer(netr_cli_creds.data,
2147
2111
        r.in.credentials = &netr_cli_creds;
2148
2112
        r.out.return_credentials = &netr_srv_creds;
2149
2113
 
2150
 
        status = dcerpc_netr_ServerReqChallenge(net_pipe, mem_ctx, &r);
 
2114
        status = dcerpc_netr_ServerReqChallenge_r(net_handle, mem_ctx, &r);
2151
2115
        if (!NT_STATUS_IS_OK(status)) {
2152
 
                d_printf("netr_ServerReqChallenge failed: %s\n",
 
2116
                torture_comment(torture, "netr_ServerReqChallenge failed: %s\n",
2153
2117
                         nt_errstr(status));
2154
2118
                goto done;
2155
2119
        }
 
2120
        if (!NT_STATUS_IS_OK(r.out.result)) {
 
2121
                torture_comment(torture, "netr_ServerReqChallenge failed: %s\n",
 
2122
                         nt_errstr(r.out.result));
 
2123
                goto done;
 
2124
        }
2156
2125
 
2157
2126
        negotiate_flags = NETLOGON_NEG_AUTH2_FLAGS;
2158
2127
        E_md4hash("foobar", mach_pw.hash);
2168
2137
        a.in.credentials = &netr_cred;
2169
2138
        a.out.return_credentials = &netr_cred;
2170
2139
 
2171
 
        creds_state = netlogon_creds_client_init(mem_ctx, 
 
2140
        creds_state = netlogon_creds_client_init(mem_ctx,
2172
2141
                                                 a.in.account_name,
2173
2142
                                                 a.in.computer_name,
2174
2143
                                                 r.in.credentials,
2175
2144
                                                 r.out.return_credentials, &mach_pw,
2176
2145
                                                 &netr_cred, negotiate_flags);
2177
 
        
2178
 
 
2179
 
        status = dcerpc_netr_ServerAuthenticate2(net_pipe, mem_ctx, &a);
2180
 
 
2181
 
        if (!NT_STATUS_EQUAL(status, NT_STATUS_NO_TRUST_SAM_ACCOUNT)) {
2182
 
                d_printf("dcerpc_netr_ServerAuthenticate2 returned %s, "
 
2146
 
 
2147
 
 
2148
        status = dcerpc_netr_ServerAuthenticate2_r(net_handle, mem_ctx, &a);
 
2149
        if (!NT_STATUS_IS_OK(status)) {
 
2150
                goto done;
 
2151
        }
 
2152
        if (!NT_STATUS_EQUAL(a.out.result, NT_STATUS_NO_TRUST_SAM_ACCOUNT)) {
 
2153
                torture_comment(torture, "dcerpc_netr_ServerAuthenticate2 returned %s, "
2183
2154
                         "expected NT_STATUS_NO_TRUST_SAM_ACCOUNT\n",
2184
 
                         nt_errstr(status));
 
2155
                         nt_errstr(a.out.result));
2185
2156
                goto done;
2186
2157
        }
2187
2158
 
2191
2162
        return result;
2192
2163
}
2193
2164
 
2194
 
static struct security_descriptor *get_sharesec(TALLOC_CTX *mem_ctx,
2195
 
                                                struct loadparm_context *lp_ctx,
 
2165
static struct security_descriptor *get_sharesec(struct torture_context *tctx,
 
2166
                                                TALLOC_CTX *mem_ctx,
2196
2167
                                                struct smbcli_session *sess,
2197
2168
                                                const char *sharename)
2198
2169
{
2199
2170
        struct smbcli_tree *tree;
2200
2171
        TALLOC_CTX *tmp_ctx;
2201
2172
        struct dcerpc_pipe *p;
 
2173
        struct dcerpc_binding_handle *b;
2202
2174
        NTSTATUS status;
2203
2175
        struct srvsvc_NetShareGetInfo r;
2204
2176
        union srvsvc_NetShareInfo info;
2205
2177
        struct security_descriptor *result;
2206
2178
 
2207
2179
        if (!(tmp_ctx = talloc_new(mem_ctx))) {
2208
 
                d_printf("talloc_new failed\n");
 
2180
                torture_comment(tctx, "talloc_new failed\n");
2209
2181
                return NULL;
2210
2182
        }
2211
2183
 
2212
 
        if (!NT_STATUS_IS_OK(secondary_tcon(tmp_ctx, sess, "IPC$", &tree))) {
2213
 
                d_printf("secondary_tcon failed\n");
 
2184
        if (!NT_STATUS_IS_OK(secondary_tcon(tctx, tmp_ctx, sess, "IPC$", &tree))) {
 
2185
                torture_comment(tctx, "secondary_tcon failed\n");
2214
2186
                talloc_free(tmp_ctx);
2215
2187
                return NULL;
2216
2188
        }
2217
2189
 
2218
 
        status = pipe_bind_smb(mem_ctx, lp_ctx, tree, "\\pipe\\srvsvc",
 
2190
        status = pipe_bind_smb(tctx, mem_ctx, tree, "\\pipe\\srvsvc",
2219
2191
                               &ndr_table_srvsvc, &p);
2220
2192
        if (!NT_STATUS_IS_OK(status)) {
2221
 
                d_printf("(%s) could not bind to srvsvc pipe: %s\n",
2222
 
                         __location__, nt_errstr(status));
 
2193
                torture_warning(tctx, "could not bind to srvsvc pipe: %s\n",
 
2194
                         nt_errstr(status));
2223
2195
                talloc_free(tmp_ctx);
2224
2196
                return NULL;
2225
2197
        }
 
2198
        b = p->binding_handle;
2226
2199
 
2227
2200
#if 0
2228
2201
        p->conn->flags |= DCERPC_DEBUG_PRINT_IN | DCERPC_DEBUG_PRINT_OUT;
2234
2207
        r.in.level = 502;
2235
2208
        r.out.info = &info;
2236
2209
 
2237
 
        status = dcerpc_srvsvc_NetShareGetInfo(p, tmp_ctx, &r);
 
2210
        status = dcerpc_srvsvc_NetShareGetInfo_r(b, tmp_ctx, &r);
2238
2211
        if (!NT_STATUS_IS_OK(status)) {
2239
 
                d_printf("srvsvc_NetShareGetInfo failed: %s\n",
 
2212
                torture_comment(tctx, "srvsvc_NetShareGetInfo failed: %s\n",
2240
2213
                         nt_errstr(status));
2241
2214
                talloc_free(tmp_ctx);
2242
2215
                return NULL;
2243
2216
        }
 
2217
        if (!W_ERROR_IS_OK(r.out.result)) {
 
2218
                torture_comment(tctx, "srvsvc_NetShareGetInfo failed: %s\n",
 
2219
                         win_errstr(r.out.result));
 
2220
                talloc_free(tmp_ctx);
 
2221
                return NULL;
 
2222
        }
2244
2223
 
2245
2224
        result = talloc_steal(mem_ctx, info.info502->sd_buf.sd);
2246
2225
        talloc_free(tmp_ctx);
2247
2226
        return result;
2248
2227
}
2249
2228
 
2250
 
static NTSTATUS set_sharesec(TALLOC_CTX *mem_ctx,
2251
 
                             struct loadparm_context *lp_ctx,
 
2229
static NTSTATUS set_sharesec(struct torture_context *tctx,
 
2230
                             TALLOC_CTX *mem_ctx,
2252
2231
                             struct smbcli_session *sess,
2253
2232
                             const char *sharename,
2254
2233
                             struct security_descriptor *sd)
2256
2235
        struct smbcli_tree *tree;
2257
2236
        TALLOC_CTX *tmp_ctx;
2258
2237
        struct dcerpc_pipe *p;
 
2238
        struct dcerpc_binding_handle *b;
2259
2239
        NTSTATUS status;
2260
2240
        struct sec_desc_buf i;
2261
2241
        struct srvsvc_NetShareSetInfo r;
2263
2243
        uint32_t error = 0;
2264
2244
 
2265
2245
        if (!(tmp_ctx = talloc_new(mem_ctx))) {
2266
 
                d_printf("talloc_new failed\n");
 
2246
                torture_comment(tctx, "talloc_new failed\n");
2267
2247
                return NT_STATUS_NO_MEMORY;
2268
2248
        }
2269
2249
 
2270
 
        if (!NT_STATUS_IS_OK(secondary_tcon(tmp_ctx, sess, "IPC$", &tree))) {
2271
 
                d_printf("secondary_tcon failed\n");
 
2250
        if (!NT_STATUS_IS_OK(secondary_tcon(tctx, tmp_ctx, sess, "IPC$", &tree))) {
 
2251
                torture_comment(tctx, "secondary_tcon failed\n");
2272
2252
                talloc_free(tmp_ctx);
2273
2253
                return NT_STATUS_UNSUCCESSFUL;
2274
2254
        }
2275
2255
 
2276
 
        status = pipe_bind_smb(mem_ctx, lp_ctx, tree, "\\pipe\\srvsvc",
 
2256
        status = pipe_bind_smb(tctx, mem_ctx, tree, "\\pipe\\srvsvc",
2277
2257
                               &ndr_table_srvsvc, &p);
2278
2258
        if (!NT_STATUS_IS_OK(status)) {
2279
 
                d_printf("(%s) could not bind to srvsvc pipe: %s\n",
2280
 
                         __location__, nt_errstr(status));
 
2259
                torture_warning(tctx, "could not bind to srvsvc pipe: %s\n",
 
2260
                         nt_errstr(status));
2281
2261
                talloc_free(tmp_ctx);
2282
2262
                return NT_STATUS_UNSUCCESSFUL;
2283
2263
        }
 
2264
        b = p->binding_handle;
2284
2265
 
2285
2266
#if 0
2286
2267
        p->conn->flags |= DCERPC_DEBUG_PRINT_IN | DCERPC_DEBUG_PRINT_OUT;
2295
2276
        r.in.info = &info;
2296
2277
        r.in.parm_error = &error;
2297
2278
 
2298
 
        status = dcerpc_srvsvc_NetShareSetInfo(p, tmp_ctx, &r);
 
2279
        status = dcerpc_srvsvc_NetShareSetInfo_r(b, tmp_ctx, &r);
2299
2280
        if (!NT_STATUS_IS_OK(status)) {
2300
 
                d_printf("srvsvc_NetShareSetInfo failed: %s\n",
 
2281
                torture_comment(tctx, "srvsvc_NetShareSetInfo failed: %s\n",
2301
2282
                         nt_errstr(status));
2302
2283
        }
2303
 
 
 
2284
        if (!W_ERROR_IS_OK(r.out.result)) {
 
2285
                torture_comment(tctx, "srvsvc_NetShareSetInfo failed: %s\n",
 
2286
                        win_errstr(r.out.result));
 
2287
                status = werror_to_ntstatus(r.out.result);
 
2288
        }
2304
2289
        talloc_free(tmp_ctx);
2305
2290
        return status;
2306
2291
}
2307
2292
 
2308
 
bool try_tcon(TALLOC_CTX *mem_ctx,
2309
 
              struct loadparm_context *lp_ctx,
 
2293
bool try_tcon(struct torture_context *tctx,
 
2294
              TALLOC_CTX *mem_ctx,
2310
2295
              struct security_descriptor *orig_sd,
2311
2296
              struct smbcli_session *session,
2312
2297
              const char *sharename, const struct dom_sid *user_sid,
2322
2307
        bool ret = true;
2323
2308
 
2324
2309
        if (!(tmp_ctx = talloc_new(mem_ctx))) {
2325
 
                d_printf("talloc_new failed\n");
 
2310
                torture_comment(tctx, "talloc_new failed\n");
2326
2311
                return false;
2327
2312
        }
2328
2313
 
2329
 
        status = secondary_tcon(tmp_ctx, session, sharename, &rmdir_tree);
 
2314
        status = secondary_tcon(tctx, tmp_ctx, session, sharename, &rmdir_tree);
2330
2315
        if (!NT_STATUS_IS_OK(status)) {
2331
 
                d_printf("first tcon to delete dir failed\n");
 
2316
                torture_comment(tctx, "first tcon to delete dir failed\n");
2332
2317
                talloc_free(tmp_ctx);
2333
2318
                return false;
2334
2319
        }
2337
2322
 
2338
2323
        if (!NT_STATUS_IS_OK(dom_sid_split_rid(tmp_ctx, user_sid,
2339
2324
                                               &domain_sid, &rid))) {
2340
 
                d_printf("dom_sid_split_rid failed\n");
 
2325
                torture_comment(tctx, "dom_sid_split_rid failed\n");
2341
2326
                talloc_free(tmp_ctx);
2342
2327
                return false;
2343
2328
        }
2349
2334
                dom_sid_string(mem_ctx, user_sid),
2350
2335
                SEC_ACE_TYPE_ACCESS_ALLOWED, access_mask, 0, NULL);
2351
2336
        if (sd == NULL) {
2352
 
                d_printf("security_descriptor_dacl_create failed\n");
 
2337
                torture_comment(tctx, "security_descriptor_dacl_create failed\n");
2353
2338
                talloc_free(tmp_ctx);
2354
2339
                return false;
2355
2340
        }
2356
2341
 
2357
 
        status = set_sharesec(mem_ctx, lp_ctx, session, sharename, sd);
 
2342
        status = set_sharesec(tctx, mem_ctx, session, sharename, sd);
2358
2343
        if (!NT_STATUS_IS_OK(status)) {
2359
 
                d_printf("custom set_sharesec failed: %s\n",
 
2344
                torture_comment(tctx, "custom set_sharesec failed: %s\n",
2360
2345
                         nt_errstr(status));
2361
2346
                talloc_free(tmp_ctx);
2362
2347
                return false;
2363
2348
        }
2364
2349
 
2365
 
        status = secondary_tcon(tmp_ctx, session, sharename, &tree);
 
2350
        status = secondary_tcon(tctx, tmp_ctx, session, sharename, &tree);
2366
2351
        if (!NT_STATUS_EQUAL(status, expected_tcon)) {
2367
 
                d_printf("Expected %s, got %s\n", nt_errstr(expected_tcon),
 
2352
                torture_comment(tctx, "Expected %s, got %s\n", nt_errstr(expected_tcon),
2368
2353
                         nt_errstr(status));
2369
2354
                ret = false;
2370
2355
                goto done;
2377
2362
 
2378
2363
        status = smbcli_mkdir(tree, "sharesec_testdir");
2379
2364
        if (!NT_STATUS_EQUAL(status, expected_mkdir)) {
2380
 
                d_printf("(%s) Expected %s, got %s\n", __location__,
 
2365
                torture_warning(tctx, "Expected %s, got %s\n",
2381
2366
                         nt_errstr(expected_mkdir), nt_errstr(status));
2382
2367
                ret = false;
2383
2368
        }
2385
2370
 done:
2386
2371
        smbcli_rmdir(rmdir_tree, "sharesec_testdir");
2387
2372
 
2388
 
        status = set_sharesec(mem_ctx, lp_ctx, session, sharename, orig_sd);
 
2373
        status = set_sharesec(tctx, mem_ctx, session, sharename, orig_sd);
2389
2374
        if (!NT_STATUS_IS_OK(status)) {
2390
 
                d_printf("custom set_sharesec failed: %s\n",
 
2375
                torture_comment(tctx, "custom set_sharesec failed: %s\n",
2391
2376
                         nt_errstr(status));
2392
2377
                talloc_free(tmp_ctx);
2393
2378
                return false;
2397
2382
        return ret;
2398
2383
}
2399
2384
 
2400
 
bool torture_samba3_rpc_sharesec(struct torture_context *torture)
 
2385
static bool torture_samba3_rpc_sharesec(struct torture_context *torture)
2401
2386
{
2402
 
        TALLOC_CTX *mem_ctx;
2403
 
        bool ret = true;
2404
2387
        struct smbcli_state *cli;
2405
2388
        struct security_descriptor *sd;
2406
2389
        struct dom_sid *user_sid;
2407
2390
 
2408
 
        if (!(mem_ctx = talloc_new(torture))) {
2409
 
                return false;
2410
 
        }
2411
 
 
2412
2391
        if (!(torture_open_connection_share(
2413
 
                      mem_ctx, &cli, torture, torture_setting_string(torture, "host", NULL),
 
2392
                      torture, &cli, torture, torture_setting_string(torture, "host", NULL),
2414
2393
                      "IPC$", torture->ev))) {
2415
 
                d_printf("IPC$ connection failed\n");
2416
 
                talloc_free(mem_ctx);
2417
 
                return false;
2418
 
        }
2419
 
 
2420
 
        if (!(user_sid = whoami(mem_ctx, torture->lp_ctx, cli->tree))) {
2421
 
                d_printf("whoami failed\n");
2422
 
                talloc_free(mem_ctx);
2423
 
                return false;
2424
 
        }
2425
 
 
2426
 
        sd = get_sharesec(mem_ctx, torture->lp_ctx, cli->session, 
 
2394
                torture_fail(torture, "IPC$ connection failed\n");
 
2395
        }
 
2396
 
 
2397
        if (!(user_sid = whoami(torture, torture, cli->tree))) {
 
2398
                torture_fail(torture, "whoami failed\n");
 
2399
        }
 
2400
 
 
2401
        sd = get_sharesec(torture, torture, cli->session,
2427
2402
                          torture_setting_string(torture, "share", NULL));
2428
2403
 
2429
 
        ret &= try_tcon(mem_ctx, torture->lp_ctx, sd, cli->session,
 
2404
        torture_assert(torture, try_tcon(
 
2405
                        torture, torture, sd, cli->session,
2430
2406
                        torture_setting_string(torture, "share", NULL),
2431
 
                        user_sid, 0, NT_STATUS_ACCESS_DENIED, NT_STATUS_OK);
 
2407
                        user_sid, 0, NT_STATUS_ACCESS_DENIED, NT_STATUS_OK),
 
2408
                        "failed to test tcon with 0 access_mask");
2432
2409
 
2433
 
        ret &= try_tcon(mem_ctx, torture->lp_ctx, sd, cli->session,
 
2410
        torture_assert(torture, try_tcon(
 
2411
                        torture, torture, sd, cli->session,
2434
2412
                        torture_setting_string(torture, "share", NULL),
2435
2413
                        user_sid, SEC_FILE_READ_DATA, NT_STATUS_OK,
2436
 
                        NT_STATUS_MEDIA_WRITE_PROTECTED);
 
2414
                        NT_STATUS_MEDIA_WRITE_PROTECTED),
 
2415
                        "failed to test tcon with SEC_FILE_READ_DATA access_mask");
2437
2416
 
2438
 
        ret &= try_tcon(mem_ctx, torture->lp_ctx, sd, cli->session,
 
2417
        torture_assert(torture, try_tcon(
 
2418
                        torture, torture, sd, cli->session,
2439
2419
                        torture_setting_string(torture, "share", NULL),
2440
 
                        user_sid, SEC_FILE_ALL, NT_STATUS_OK, NT_STATUS_OK);
 
2420
                        user_sid, SEC_FILE_ALL, NT_STATUS_OK, NT_STATUS_OK),
 
2421
                        "failed to test tcon with SEC_FILE_ALL access_mask")
2441
2422
 
2442
 
        talloc_free(mem_ctx);
2443
 
        return ret;
 
2423
        return true;
2444
2424
}
2445
2425
 
2446
 
bool torture_samba3_rpc_lsa(struct torture_context *torture)
 
2426
static bool torture_samba3_rpc_lsa(struct torture_context *torture)
2447
2427
{
2448
 
        TALLOC_CTX *mem_ctx;
2449
 
        bool ret = true;
2450
 
        struct smbcli_state *cli;
2451
2428
        struct dcerpc_pipe *p;
 
2429
        struct dcerpc_binding_handle *b;
2452
2430
        struct policy_handle lsa_handle;
2453
 
        NTSTATUS status;
2454
 
        struct dom_sid *domain_sid;
2455
 
 
2456
 
        if (!(mem_ctx = talloc_new(torture))) {
2457
 
                return false;
2458
 
        }
2459
 
 
2460
 
        if (!(torture_open_connection_share(
2461
 
                      mem_ctx, &cli, torture, torture_setting_string(torture, "host", NULL),
2462
 
                      "IPC$", torture->ev))) {
2463
 
                d_printf("IPC$ connection failed\n");
2464
 
                talloc_free(mem_ctx);
2465
 
                return false;
2466
 
        }
2467
 
 
2468
 
        status = pipe_bind_smb(mem_ctx, torture->lp_ctx, cli->tree, "\\lsarpc",
2469
 
                               &ndr_table_lsarpc, &p);
2470
 
        if (!NT_STATUS_IS_OK(status)) {
2471
 
                d_printf("(%s) pipe_bind_smb failed: %s\n", __location__,
2472
 
                         nt_errstr(status));
2473
 
                talloc_free(mem_ctx);
2474
 
                return false;
2475
 
        }
 
2431
 
 
2432
        torture_assert_ntstatus_ok(torture,
 
2433
                torture_rpc_connection(torture, &p, &ndr_table_lsarpc),
 
2434
                "failed to setup lsarpc");
 
2435
 
 
2436
        b = p->binding_handle;
2476
2437
 
2477
2438
        {
2478
2439
                struct lsa_ObjectAttribute attr;
2479
2440
                struct lsa_OpenPolicy2 o;
2480
2441
                o.in.system_name = talloc_asprintf(
2481
 
                        mem_ctx, "\\\\%s", dcerpc_server_name(p));
 
2442
                        torture, "\\\\%s", dcerpc_server_name(p));
2482
2443
                ZERO_STRUCT(attr);
2483
2444
                o.in.attr = &attr;
2484
2445
                o.in.access_mask = SEC_FLAG_MAXIMUM_ALLOWED;
2485
2446
                o.out.handle = &lsa_handle;
2486
 
                status = dcerpc_lsa_OpenPolicy2(p, mem_ctx, &o);
2487
 
                if (!NT_STATUS_IS_OK(status)) {
2488
 
                        d_printf("(%s) dcerpc_lsa_OpenPolicy2 failed: %s\n",
2489
 
                                 __location__, nt_errstr(status));
2490
 
                        talloc_free(mem_ctx);
2491
 
                        return false;
2492
 
                }
 
2447
 
 
2448
                torture_assert_ntstatus_ok(torture,
 
2449
                        dcerpc_lsa_OpenPolicy2_r(b, torture, &o),
 
2450
                        "dcerpc_lsa_OpenPolicy2 failed");
 
2451
                torture_assert_ntstatus_ok(torture, o.out.result,
 
2452
                        "dcerpc_lsa_OpenPolicy2 failed");
2493
2453
        }
2494
2454
 
2495
 
#if 0
2496
 
        p->conn->flags |= DCERPC_DEBUG_PRINT_IN | DCERPC_DEBUG_PRINT_OUT;
2497
 
#endif
2498
 
 
2499
2455
        {
2500
2456
                int i;
2501
2457
                int levels[] = { 2,3,5,6 };
2506
2462
                        r.in.handle = &lsa_handle;
2507
2463
                        r.in.level = levels[i];
2508
2464
                        r.out.info = &info;
2509
 
                        status = dcerpc_lsa_QueryInfoPolicy(p, mem_ctx, &r);
2510
 
                        if (!NT_STATUS_IS_OK(status)) {
2511
 
                                d_printf("(%s) dcerpc_lsa_QueryInfoPolicy %d "
2512
 
                                         "failed: %s\n", __location__,
2513
 
                                         levels[i], nt_errstr(status));
2514
 
                                talloc_free(mem_ctx);
2515
 
                                return false;
2516
 
                        }
2517
 
                        if (levels[i] == 5) {
2518
 
                                domain_sid = info->account_domain.sid;
2519
 
                        }
 
2465
 
 
2466
                        torture_assert_ntstatus_ok(torture,
 
2467
                                dcerpc_lsa_QueryInfoPolicy_r(b, torture, &r),
 
2468
                                talloc_asprintf(torture, "dcerpc_lsa_QueryInfoPolicy level %d failed", levels[i]));
 
2469
                        torture_assert_ntstatus_ok(torture, r.out.result,
 
2470
                                talloc_asprintf(torture, "dcerpc_lsa_QueryInfoPolicy level %d failed", levels[i]));
2520
2471
                }
2521
2472
        }
2522
2473
 
2523
 
        return ret;
 
2474
        return true;
2524
2475
}
2525
2476
 
2526
2477
static NTSTATUS get_servername(TALLOC_CTX *mem_ctx, struct smbcli_tree *tree,
2527
 
                               struct smb_iconv_convenience *iconv_convenience,
2528
2478
                               char **name)
2529
2479
{
2530
2480
        struct rap_WserverGetInfo r;
2534
2484
        r.in.level = 0;
2535
2485
        r.in.bufsize = 0xffff;
2536
2486
 
2537
 
        status = smbcli_rap_netservergetinfo(tree, iconv_convenience, mem_ctx, &r);
 
2487
        status = smbcli_rap_netservergetinfo(tree, mem_ctx, &r);
2538
2488
        if (!NT_STATUS_IS_OK(status)) {
2539
2489
                return status;
2540
2490
        }
2549
2499
        return NT_STATUS_OK;
2550
2500
}
2551
2501
 
2552
 
 
2553
 
static NTSTATUS find_printers(TALLOC_CTX *ctx, struct loadparm_context *lp_ctx,
2554
 
                              struct smbcli_tree *tree,
2555
 
                              const char ***printers, int *num_printers)
2556
 
{
2557
 
        TALLOC_CTX *mem_ctx;
2558
 
        NTSTATUS status;
2559
 
        struct dcerpc_pipe *p;
 
2502
static bool rap_get_servername(struct torture_context *tctx,
 
2503
                               char **servername)
 
2504
{
 
2505
        struct smbcli_state *cli;
 
2506
 
 
2507
        torture_assert(tctx,
 
2508
                torture_open_connection_share(tctx, &cli, tctx, torture_setting_string(tctx, "host", NULL),
 
2509
                                              "IPC$", tctx->ev),
 
2510
                "IPC$ connection failed");
 
2511
 
 
2512
        torture_assert_ntstatus_ok(tctx,
 
2513
                get_servername(tctx, cli->tree, servername),
 
2514
                "get_servername failed");
 
2515
 
 
2516
        talloc_free(cli);
 
2517
 
 
2518
        return true;
 
2519
}
 
2520
 
 
2521
static bool find_printers(struct torture_context *tctx,
 
2522
                          struct dcerpc_pipe *p,
 
2523
                          const char ***printers,
 
2524
                          int *num_printers)
 
2525
{
2560
2526
        struct srvsvc_NetShareEnum r;
2561
2527
        struct srvsvc_NetShareInfoCtr info_ctr;
2562
2528
        struct srvsvc_NetShareCtr1 c1_in;
2563
2529
        struct srvsvc_NetShareCtr1 *c1;
2564
2530
        uint32_t totalentries = 0;
2565
2531
        int i;
2566
 
 
2567
 
        mem_ctx = talloc_new(ctx);
2568
 
        if (mem_ctx == NULL) {
2569
 
                return NT_STATUS_NO_MEMORY;
2570
 
        }
2571
 
 
2572
 
        status = pipe_bind_smb(mem_ctx, lp_ctx, 
2573
 
                               tree, "\\srvsvc", &ndr_table_srvsvc,
2574
 
                               &p);
2575
 
        if (!NT_STATUS_IS_OK(status)) {
2576
 
                d_printf("could not bind to srvsvc pipe\n");
2577
 
                talloc_free(mem_ctx);
2578
 
                return status;
2579
 
        }
 
2532
        struct dcerpc_binding_handle *b = p->binding_handle;
2580
2533
 
2581
2534
        ZERO_STRUCT(c1_in);
2582
2535
        info_ctr.level = 1;
2583
2536
        info_ctr.ctr.ctr1 = &c1_in;
2584
2537
 
2585
2538
        r.in.server_unc = talloc_asprintf(
2586
 
                mem_ctx, "\\\\%s", dcerpc_server_name(p));
 
2539
                tctx, "\\\\%s", dcerpc_server_name(p));
2587
2540
        r.in.info_ctr = &info_ctr;
2588
2541
        r.in.max_buffer = (uint32_t)-1;
2589
2542
        r.in.resume_handle = NULL;
2590
2543
        r.out.totalentries = &totalentries;
2591
2544
        r.out.info_ctr = &info_ctr;
2592
2545
 
2593
 
        status = dcerpc_srvsvc_NetShareEnum(p, mem_ctx, &r);
2594
 
        if (!NT_STATUS_IS_OK(status)) {
2595
 
                d_printf("NetShareEnum level %u failed - %s\n",
2596
 
                         info_ctr.level, nt_errstr(status));
2597
 
                talloc_free(mem_ctx);
2598
 
                return status;
2599
 
        }
 
2546
        torture_assert_ntstatus_ok(tctx,
 
2547
                dcerpc_srvsvc_NetShareEnum_r(b, tctx, &r),
 
2548
                "NetShareEnum level 1 failed");
 
2549
        torture_assert_werr_ok(tctx, r.out.result,
 
2550
                "NetShareEnum level 1 failed");
2600
2551
 
2601
2552
        *printers = NULL;
2602
2553
        *num_printers = 0;
2605
2556
                if (c1->array[i].type != STYPE_PRINTQ) {
2606
2557
                        continue;
2607
2558
                }
2608
 
                if (!add_string_to_array(ctx, c1->array[i].name,
 
2559
                if (!add_string_to_array(tctx, c1->array[i].name,
2609
2560
                                         printers, num_printers)) {
2610
 
                        talloc_free(ctx);
2611
 
                        return NT_STATUS_NO_MEMORY;
 
2561
                        return false;
2612
2562
                }
2613
2563
        }
2614
2564
 
2615
 
        talloc_free(mem_ctx);
2616
 
        return NT_STATUS_OK;
 
2565
        return true;
2617
2566
}
2618
2567
 
2619
 
static bool enumprinters(TALLOC_CTX *mem_ctx, struct dcerpc_pipe *pipe,
 
2568
static bool enumprinters(struct torture_context *tctx,
 
2569
                         struct dcerpc_binding_handle *b,
2620
2570
                         const char *servername, int level, int *num_printers)
2621
2571
{
2622
2572
        struct spoolss_EnumPrinters r;
2623
 
        NTSTATUS status;
2624
2573
        DATA_BLOB blob;
2625
2574
        uint32_t needed;
2626
2575
        uint32_t count;
2627
2576
        union spoolss_PrinterInfo *info;
2628
2577
 
2629
2578
        r.in.flags = PRINTER_ENUM_LOCAL;
2630
 
        r.in.server = talloc_asprintf(mem_ctx, "\\\\%s", servername);
 
2579
        r.in.server = talloc_asprintf(tctx, "\\\\%s", servername);
2631
2580
        r.in.level = level;
2632
2581
        r.in.buffer = NULL;
2633
2582
        r.in.offered = 0;
2635
2584
        r.out.count = &count;
2636
2585
        r.out.info = &info;
2637
2586
 
2638
 
        status = dcerpc_spoolss_EnumPrinters(pipe, mem_ctx, &r);
2639
 
        if (!NT_STATUS_IS_OK(status)) {
2640
 
                d_printf("(%s) dcerpc_spoolss_EnumPrinters failed: %s\n",
2641
 
                         __location__, nt_errstr(status));
2642
 
                return false;
2643
 
        }
2644
 
 
2645
 
        if (!W_ERROR_EQUAL(r.out.result, WERR_INSUFFICIENT_BUFFER)) {
2646
 
                d_printf("(%s) EnumPrinters unexpected return code %s, should "
2647
 
                         "be WERR_INSUFFICIENT_BUFFER\n", __location__,
2648
 
                         win_errstr(r.out.result));
2649
 
                return false;
2650
 
        }
2651
 
 
2652
 
        blob = data_blob_talloc_zero(mem_ctx, needed);
 
2587
        torture_assert_ntstatus_ok(tctx,
 
2588
                dcerpc_spoolss_EnumPrinters_r(b, tctx, &r),
 
2589
                "dcerpc_spoolss_EnumPrinters failed");
 
2590
        torture_assert_werr_equal(tctx, r.out.result, WERR_INSUFFICIENT_BUFFER,
 
2591
                "EnumPrinters unexpected return code should be WERR_INSUFFICIENT_BUFFER");
 
2592
 
 
2593
        blob = data_blob_talloc_zero(tctx, needed);
2653
2594
        if (blob.data == NULL) {
2654
 
                d_printf("(%s) data_blob_talloc failed\n", __location__);
2655
2595
                return false;
2656
2596
        }
2657
2597
 
2658
2598
        r.in.buffer = &blob;
2659
2599
        r.in.offered = needed;
2660
2600
 
2661
 
        status = dcerpc_spoolss_EnumPrinters(pipe, mem_ctx, &r);
2662
 
        if (!NT_STATUS_IS_OK(status) || !W_ERROR_IS_OK(r.out.result)) {
2663
 
                d_printf("(%s) dcerpc_spoolss_EnumPrinters failed: %s, "
2664
 
                         "%s\n", __location__, nt_errstr(status),
2665
 
                         win_errstr(r.out.result));
2666
 
                return false;
2667
 
        }
 
2601
        torture_assert_ntstatus_ok(tctx,
 
2602
                dcerpc_spoolss_EnumPrinters_r(b, tctx, &r),
 
2603
                "dcerpc_spoolss_EnumPrinters failed");
 
2604
        torture_assert_werr_ok(tctx, r.out.result,
 
2605
                "dcerpc_spoolss_EnumPrinters failed");
2668
2606
 
2669
2607
        *num_printers = count;
2670
2608
 
2671
2609
        return true;
2672
2610
}
2673
2611
 
2674
 
static NTSTATUS getprinterinfo(TALLOC_CTX *ctx, struct dcerpc_pipe *pipe,
2675
 
                               struct policy_handle *handle, int level,
2676
 
                               union spoolss_PrinterInfo **res)
 
2612
static bool getprinterinfo(struct torture_context *tctx,
 
2613
                           struct dcerpc_binding_handle *b,
 
2614
                           struct policy_handle *handle, int level,
 
2615
                           union spoolss_PrinterInfo **res)
2677
2616
{
2678
 
        TALLOC_CTX *mem_ctx;
2679
2617
        struct spoolss_GetPrinter r;
2680
2618
        DATA_BLOB blob;
2681
 
        NTSTATUS status;
2682
2619
        uint32_t needed;
2683
2620
 
2684
 
        mem_ctx = talloc_new(ctx);
2685
 
        if (mem_ctx == NULL) {
2686
 
                return NT_STATUS_NO_MEMORY;
2687
 
        }
2688
 
 
2689
2621
        r.in.handle = handle;
2690
2622
        r.in.level = level;
2691
2623
        r.in.buffer = NULL;
2692
2624
        r.in.offered = 0;
2693
2625
        r.out.needed = &needed;
2694
2626
 
2695
 
        status = dcerpc_spoolss_GetPrinter(pipe, mem_ctx, &r);
2696
 
        if (!NT_STATUS_IS_OK(status)) {
2697
 
                d_printf("(%s) dcerpc_spoolss_GetPrinter failed: %s\n",
2698
 
                         __location__, nt_errstr(status));
2699
 
                talloc_free(mem_ctx);
2700
 
                return status;
2701
 
        }
2702
 
 
2703
 
        if (!W_ERROR_EQUAL(r.out.result, WERR_INSUFFICIENT_BUFFER)) {
2704
 
                printf("GetPrinter unexpected return code %s, should "
2705
 
                       "be WERR_INSUFFICIENT_BUFFER\n",
2706
 
                       win_errstr(r.out.result));
2707
 
                talloc_free(mem_ctx);
2708
 
                return NT_STATUS_UNSUCCESSFUL;
2709
 
        }
 
2627
        torture_assert_ntstatus_ok(tctx,
 
2628
                dcerpc_spoolss_GetPrinter_r(b, tctx, &r),
 
2629
                "dcerpc_spoolss_GetPrinter failed");
 
2630
        torture_assert_werr_equal(tctx, r.out.result, WERR_INSUFFICIENT_BUFFER,
 
2631
                "GetPrinter unexpected return code should be WERR_INSUFFICIENT_BUFFER");
2710
2632
 
2711
2633
        r.in.handle = handle;
2712
2634
        r.in.level = level;
2713
 
        blob = data_blob_talloc(mem_ctx, NULL, needed);
 
2635
        blob = data_blob_talloc_zero(tctx, needed);
2714
2636
        if (blob.data == NULL) {
2715
 
                talloc_free(mem_ctx);
2716
 
                return NT_STATUS_NO_MEMORY;
 
2637
                return false;
2717
2638
        }
2718
 
        memset(blob.data, 0, blob.length);
2719
2639
        r.in.buffer = &blob;
2720
2640
        r.in.offered = needed;
2721
2641
 
2722
 
        status = dcerpc_spoolss_GetPrinter(pipe, mem_ctx, &r);
2723
 
        if (!NT_STATUS_IS_OK(status) || !W_ERROR_IS_OK(r.out.result)) {
2724
 
                d_printf("(%s) dcerpc_spoolss_GetPrinter failed: %s, "
2725
 
                         "%s\n", __location__, nt_errstr(status),
2726
 
                         win_errstr(r.out.result));
2727
 
                talloc_free(mem_ctx);
2728
 
                return NT_STATUS_IS_OK(status) ?
2729
 
                        NT_STATUS_UNSUCCESSFUL : status;
2730
 
        }
 
2642
        torture_assert_ntstatus_ok(tctx,
 
2643
                dcerpc_spoolss_GetPrinter_r(b, tctx, &r),
 
2644
                "dcerpc_spoolss_GetPrinter failed");
 
2645
        torture_assert_werr_ok(tctx, r.out.result,
 
2646
                "dcerpc_spoolss_GetPrinter failed");
2731
2647
 
2732
2648
        if (res != NULL) {
2733
 
                *res = talloc_steal(ctx, r.out.info);
 
2649
                *res = talloc_steal(tctx, r.out.info);
2734
2650
        }
2735
2651
 
2736
 
        talloc_free(mem_ctx);
2737
 
        return NT_STATUS_OK;
 
2652
        return true;
2738
2653
}
2739
2654
 
2740
 
bool torture_samba3_rpc_spoolss(struct torture_context *torture)
 
2655
static bool torture_samba3_rpc_spoolss(struct torture_context *torture)
2741
2656
{
2742
 
        TALLOC_CTX *mem_ctx;
2743
 
        bool ret = true;
2744
 
        struct smbcli_state *cli;
2745
 
        struct dcerpc_pipe *p;
2746
 
        NTSTATUS status;
 
2657
        struct dcerpc_pipe *p, *p2;
 
2658
        struct dcerpc_binding_handle *b;
2747
2659
        struct policy_handle server_handle, printer_handle;
2748
2660
        const char **printers;
2749
2661
        int num_printers;
2750
2662
        struct spoolss_UserLevel1 userlevel1;
2751
2663
        char *servername;
2752
2664
 
2753
 
        if (!(mem_ctx = talloc_new(torture))) {
2754
 
                return false;
2755
 
        }
2756
 
 
2757
 
        if (!(torture_open_connection_share(
2758
 
                      mem_ctx, &cli, torture, torture_setting_string(torture, "host", NULL),
2759
 
                      "IPC$", torture->ev))) {
2760
 
                d_printf("IPC$ connection failed\n");
2761
 
                talloc_free(mem_ctx);
2762
 
                return false;
2763
 
        }
2764
 
 
2765
 
        status = get_servername(mem_ctx, cli->tree, lp_iconv_convenience(torture->lp_ctx), &servername);
2766
 
        if (!NT_STATUS_IS_OK(status)) {
2767
 
                d_fprintf(stderr, "(%s) get_servername returned %s\n",
2768
 
                          __location__, nt_errstr(status));
2769
 
                talloc_free(mem_ctx);
2770
 
                return false;
2771
 
        }
2772
 
 
2773
 
        if (!NT_STATUS_IS_OK(find_printers(mem_ctx, torture->lp_ctx, cli->tree,
2774
 
                                           &printers, &num_printers))) {
2775
 
                talloc_free(mem_ctx);
2776
 
                return false;
2777
 
        }
 
2665
        torture_assert(torture,
 
2666
                rap_get_servername(torture, &servername),
 
2667
                "failed to rap servername");
 
2668
 
 
2669
        torture_assert_ntstatus_ok(torture,
 
2670
                torture_rpc_connection(torture, &p2, &ndr_table_srvsvc),
 
2671
                "failed to setup srvsvc");
 
2672
 
 
2673
        torture_assert(torture,
 
2674
                find_printers(torture, p2, &printers, &num_printers),
 
2675
                "failed to find printers via srvsvc");
 
2676
 
 
2677
        talloc_free(p2);
2778
2678
 
2779
2679
        if (num_printers == 0) {
2780
 
                d_printf("Did not find printers\n");
2781
 
                talloc_free(mem_ctx);
 
2680
                torture_skip(torture, "Did not find printers\n");
2782
2681
                return true;
2783
2682
        }
2784
2683
 
2785
 
        status = pipe_bind_smb(mem_ctx, torture->lp_ctx, cli->tree, "\\spoolss",
2786
 
                               &ndr_table_spoolss, &p);
2787
 
        if (!NT_STATUS_IS_OK(status)) {
2788
 
                d_printf("(%s) pipe_bind_smb failed: %s\n", __location__,
2789
 
                         nt_errstr(status));
2790
 
                talloc_free(mem_ctx);
2791
 
                return false;
2792
 
        }
 
2684
        torture_assert_ntstatus_ok(torture,
 
2685
                torture_rpc_connection(torture, &p, &ndr_table_spoolss),
 
2686
                "failed to setup spoolss");
 
2687
 
 
2688
        b = p->binding_handle;
2793
2689
 
2794
2690
        ZERO_STRUCT(userlevel1);
2795
2691
        userlevel1.client = talloc_asprintf(
2796
 
                mem_ctx, "\\\\%s", lp_netbios_name(torture->lp_ctx));
 
2692
                torture, "\\\\%s", lpcfg_netbios_name(torture->lp_ctx));
2797
2693
        userlevel1.user = cli_credentials_get_username(cmdline_credentials);
2798
2694
        userlevel1.build = 2600;
2799
2695
        userlevel1.major = 3;
2804
2700
                struct spoolss_OpenPrinterEx r;
2805
2701
 
2806
2702
                ZERO_STRUCT(r);
2807
 
                r.in.printername = talloc_asprintf(mem_ctx, "\\\\%s",
 
2703
                r.in.printername = talloc_asprintf(torture, "\\\\%s",
2808
2704
                                                   servername);
2809
2705
                r.in.datatype = NULL;
2810
2706
                r.in.access_mask = 0;
2812
2708
                r.in.userlevel.level1 = &userlevel1;
2813
2709
                r.out.handle = &server_handle;
2814
2710
 
2815
 
                status = dcerpc_spoolss_OpenPrinterEx(p, mem_ctx, &r);
2816
 
                if (!NT_STATUS_IS_OK(status) || !W_ERROR_IS_OK(r.out.result)) {
2817
 
                        d_printf("(%s) dcerpc_spoolss_OpenPrinterEx failed: "
2818
 
                                 "%s, %s\n", __location__, nt_errstr(status),
2819
 
                                 win_errstr(r.out.result));
2820
 
                        talloc_free(mem_ctx);
2821
 
                        return false;
2822
 
                }
 
2711
                torture_assert_ntstatus_ok(torture,
 
2712
                        dcerpc_spoolss_OpenPrinterEx_r(b, torture, &r),
 
2713
                        "dcerpc_spoolss_OpenPrinterEx failed");
 
2714
                torture_assert_werr_ok(torture, r.out.result,
 
2715
                        "dcerpc_spoolss_OpenPrinterEx failed");
2823
2716
        }
2824
2717
 
2825
2718
        {
2828
2721
                r.in.handle = &server_handle;
2829
2722
                r.out.handle = &server_handle;
2830
2723
 
2831
 
                status = dcerpc_spoolss_ClosePrinter(p, mem_ctx, &r);
2832
 
                if (!NT_STATUS_IS_OK(status) || !W_ERROR_IS_OK(r.out.result)) {
2833
 
                        d_printf("(%s) dcerpc_spoolss_ClosePrinter failed: "
2834
 
                                 "%s, %s\n", __location__, nt_errstr(status),
2835
 
                                 win_errstr(r.out.result));
2836
 
                        talloc_free(mem_ctx);
2837
 
                        return false;
2838
 
                }
 
2724
                torture_assert_ntstatus_ok(torture,
 
2725
                        dcerpc_spoolss_ClosePrinter_r(b, torture, &r),
 
2726
                        "dcerpc_spoolss_ClosePrinter failed");
 
2727
                torture_assert_werr_ok(torture, r.out.result,
 
2728
                        "dcerpc_spoolss_ClosePrinter failed");
2839
2729
        }
2840
2730
 
2841
2731
        {
2843
2733
 
2844
2734
                ZERO_STRUCT(r);
2845
2735
                r.in.printername = talloc_asprintf(
2846
 
                        mem_ctx, "\\\\%s\\%s", servername, printers[0]);
 
2736
                        torture, "\\\\%s\\%s", servername, printers[0]);
2847
2737
                r.in.datatype = NULL;
2848
2738
                r.in.access_mask = 0;
2849
2739
                r.in.level = 1;
2850
2740
                r.in.userlevel.level1 = &userlevel1;
2851
2741
                r.out.handle = &printer_handle;
2852
2742
 
2853
 
                status = dcerpc_spoolss_OpenPrinterEx(p, mem_ctx, &r);
2854
 
                if (!NT_STATUS_IS_OK(status) || !W_ERROR_IS_OK(r.out.result)) {
2855
 
                        d_printf("(%s) dcerpc_spoolss_OpenPrinterEx failed: "
2856
 
                                 "%s, %s\n", __location__, nt_errstr(status),
2857
 
                                 win_errstr(r.out.result));
2858
 
                        talloc_free(mem_ctx);
2859
 
                        return false;
2860
 
                }
 
2743
                torture_assert_ntstatus_ok(torture,
 
2744
                        dcerpc_spoolss_OpenPrinterEx_r(b, torture, &r),
 
2745
                        "dcerpc_spoolss_OpenPrinterEx failed");
 
2746
                torture_assert_werr_ok(torture, r.out.result,
 
2747
                        "dcerpc_spoolss_OpenPrinterEx failed");
2861
2748
        }
2862
2749
 
2863
2750
        {
2864
2751
                int i;
2865
2752
 
2866
2753
                for (i=0; i<8; i++) {
2867
 
                        status = getprinterinfo(mem_ctx, p, &printer_handle,
2868
 
                                                i, NULL);
2869
 
                        if (!NT_STATUS_IS_OK(status)) {
2870
 
                                d_printf("(%s) getprinterinfo %d failed: %s\n",
2871
 
                                         __location__, i, nt_errstr(status));
2872
 
                                ret = false;
2873
 
                        }
 
2754
                        torture_assert(torture,
 
2755
                                getprinterinfo(torture, b, &printer_handle, i, NULL),
 
2756
                                talloc_asprintf(torture, "getprinterinfo %d failed", i));
2874
2757
                }
2875
2758
        }
2876
2759
 
2880
2763
                r.in.handle = &printer_handle;
2881
2764
                r.out.handle = &printer_handle;
2882
2765
 
2883
 
                status = dcerpc_spoolss_ClosePrinter(p, mem_ctx, &r);
2884
 
                if (!NT_STATUS_IS_OK(status)) {
2885
 
                        d_printf("(%s) dcerpc_spoolss_ClosePrinter failed: "
2886
 
                                 "%s\n", __location__, nt_errstr(status));
2887
 
                        talloc_free(mem_ctx);
2888
 
                        return false;
2889
 
                }
2890
 
        }
2891
 
 
2892
 
        {
2893
 
                int num_enumerated;
2894
 
                if (!enumprinters(mem_ctx, p, servername, 1,
2895
 
                                  &num_enumerated)) {
2896
 
                        d_printf("(%s) enumprinters failed\n", __location__);
2897
 
                        talloc_free(mem_ctx);
2898
 
                        return false;
2899
 
                }
2900
 
                if (num_printers != num_enumerated) {
2901
 
                        d_printf("(%s) netshareenum gave %d printers, "
2902
 
                                 "enumprinters lvl 1 gave %d\n", __location__,
2903
 
                                 num_printers, num_enumerated);
2904
 
                        talloc_free(mem_ctx);
2905
 
                        return false;
2906
 
                }
2907
 
        }
2908
 
 
2909
 
        {
2910
 
                int num_enumerated;
2911
 
                if (!enumprinters(mem_ctx, p, servername, 2,
2912
 
                                  &num_enumerated)) {
2913
 
                        d_printf("(%s) enumprinters failed\n", __location__);
2914
 
                        talloc_free(mem_ctx);
2915
 
                        return false;
2916
 
                }
2917
 
                if (num_printers != num_enumerated) {
2918
 
                        d_printf("(%s) netshareenum gave %d printers, "
2919
 
                                 "enumprinters lvl 2 gave %d\n", __location__,
2920
 
                                 num_printers, num_enumerated);
2921
 
                        talloc_free(mem_ctx);
2922
 
                        return false;
2923
 
                }
2924
 
        }
2925
 
 
2926
 
        talloc_free(mem_ctx);
2927
 
 
2928
 
        return ret;
 
2766
                torture_assert_ntstatus_ok(torture,
 
2767
                        dcerpc_spoolss_ClosePrinter_r(b, torture, &r),
 
2768
                        "dcerpc_spoolss_ClosePrinter failed");
 
2769
                torture_assert_werr_ok(torture, r.out.result,
 
2770
                        "dcerpc_spoolss_ClosePrinter failed");
 
2771
        }
 
2772
 
 
2773
        {
 
2774
                int num_enumerated;
 
2775
 
 
2776
                torture_assert(torture,
 
2777
                        enumprinters(torture, b, servername, 1, &num_enumerated),
 
2778
                        "enumprinters failed");
 
2779
 
 
2780
                torture_assert_int_equal(torture, num_printers, num_enumerated,
 
2781
                        "netshareenum / enumprinters lvl 1 numprinter mismatch");
 
2782
        }
 
2783
 
 
2784
        {
 
2785
                int num_enumerated;
 
2786
 
 
2787
                torture_assert(torture,
 
2788
                        enumprinters(torture, b, servername, 2, &num_enumerated),
 
2789
                        "enumprinters failed");
 
2790
 
 
2791
                torture_assert_int_equal(torture, num_printers, num_enumerated,
 
2792
                        "netshareenum / enumprinters lvl 2 numprinter mismatch");
 
2793
        }
 
2794
 
 
2795
        return true;
2929
2796
}
2930
2797
 
2931
 
bool torture_samba3_rpc_wkssvc(struct torture_context *torture)
 
2798
static bool torture_samba3_rpc_wkssvc(struct torture_context *torture)
2932
2799
{
2933
 
        TALLOC_CTX *mem_ctx;
2934
 
        struct smbcli_state *cli;
2935
2800
        struct dcerpc_pipe *p;
2936
 
        NTSTATUS status;
 
2801
        struct dcerpc_binding_handle *b;
2937
2802
        char *servername;
2938
2803
 
2939
 
        if (!(mem_ctx = talloc_new(torture))) {
2940
 
                return false;
2941
 
        }
2942
 
 
2943
 
        if (!(torture_open_connection_share(
2944
 
                      mem_ctx, &cli, torture, torture_setting_string(torture, "host", NULL),
2945
 
                      "IPC$", torture->ev))) {
2946
 
                d_printf("IPC$ connection failed\n");
2947
 
                talloc_free(mem_ctx);
2948
 
                return false;
2949
 
        }
2950
 
 
2951
 
        status = get_servername(mem_ctx, cli->tree, lp_iconv_convenience(torture->lp_ctx), &servername);
2952
 
        if (!NT_STATUS_IS_OK(status)) {
2953
 
                d_fprintf(stderr, "(%s) get_servername returned %s\n",
2954
 
                          __location__, nt_errstr(status));
2955
 
                talloc_free(mem_ctx);
2956
 
                return false;
2957
 
        }
2958
 
 
2959
 
        status = pipe_bind_smb(mem_ctx, torture->lp_ctx, cli->tree, "\\wkssvc",
2960
 
                               &ndr_table_wkssvc, &p);
2961
 
        if (!NT_STATUS_IS_OK(status)) {
2962
 
                d_printf("(%s) pipe_bind_smb failed: %s\n", __location__,
2963
 
                         nt_errstr(status));
2964
 
                talloc_free(mem_ctx);
2965
 
                return false;
2966
 
        }
 
2804
        torture_assert(torture,
 
2805
                rap_get_servername(torture, &servername),
 
2806
                "failed to rap servername");
 
2807
 
 
2808
        torture_assert_ntstatus_ok(torture,
 
2809
                torture_rpc_connection(torture, &p, &ndr_table_wkssvc),
 
2810
                "failed to setup wkssvc");
 
2811
 
 
2812
        b = p->binding_handle;
2967
2813
 
2968
2814
        {
2969
2815
                struct wkssvc_NetWkstaInfo100 wks100;
2975
2821
                info.info100 = &wks100;
2976
2822
                r.out.info = &info;
2977
2823
 
2978
 
                status = dcerpc_wkssvc_NetWkstaGetInfo(p, mem_ctx, &r);
2979
 
                if (!NT_STATUS_IS_OK(status) || !W_ERROR_IS_OK(r.out.result)) {
2980
 
                        d_printf("(%s) dcerpc_wkssvc_NetWksGetInfo failed: "
2981
 
                                 "%s, %s\n", __location__, nt_errstr(status),
2982
 
                                 win_errstr(r.out.result));
2983
 
                        talloc_free(mem_ctx);
2984
 
                        return false;
2985
 
                }
 
2824
                torture_assert_ntstatus_ok(torture,
 
2825
                        dcerpc_wkssvc_NetWkstaGetInfo_r(b, torture, &r),
 
2826
                        "dcerpc_wkssvc_NetWksGetInfo failed");
 
2827
                torture_assert_werr_ok(torture, r.out.result,
 
2828
                        "dcerpc_wkssvc_NetWksGetInfo failed");
2986
2829
 
2987
 
                if (strcmp(servername,
2988
 
                           r.out.info->info100->server_name) != 0) {
2989
 
                        d_printf("(%s) servername inconsistency: RAP=%s, "
2990
 
                                 "dcerpc_wkssvc_NetWksGetInfo=%s",
2991
 
                                 __location__, servername,
2992
 
                                 r.out.info->info100->server_name);
2993
 
                        talloc_free(mem_ctx);
2994
 
                        return false;
2995
 
                }
 
2830
                torture_assert_str_equal(torture, servername, r.out.info->info100->server_name,
 
2831
                        "servername RAP / DCERPC inconsistency");
2996
2832
        }
2997
2833
 
2998
 
        talloc_free(mem_ctx);
2999
2834
        return true;
3000
2835
}
3001
2836
 
3002
 
static NTSTATUS winreg_close(struct dcerpc_pipe *p,
3003
 
                             struct policy_handle *handle)
 
2837
static bool winreg_close(struct torture_context *tctx,
 
2838
                         struct dcerpc_binding_handle *b,
 
2839
                         struct policy_handle *handle)
3004
2840
{
3005
2841
        struct winreg_CloseKey c;
3006
 
        NTSTATUS status;
3007
 
        TALLOC_CTX *mem_ctx;
3008
2842
 
3009
2843
        c.in.handle = c.out.handle = handle;
3010
2844
 
3011
 
        if (!(mem_ctx = talloc_new(p))) {
3012
 
                return NT_STATUS_NO_MEMORY;
3013
 
        }
3014
 
 
3015
 
        status = dcerpc_winreg_CloseKey(p, mem_ctx, &c);
3016
 
        talloc_free(mem_ctx);
3017
 
 
3018
 
        if (!NT_STATUS_IS_OK(status)) {
3019
 
                return status;
3020
 
        }
3021
 
 
3022
 
        if (!W_ERROR_IS_OK(c.out.result)) {
3023
 
                return werror_to_ntstatus(c.out.result);
3024
 
        }
3025
 
 
3026
 
        return NT_STATUS_OK;
 
2845
        torture_assert_ntstatus_ok(tctx,
 
2846
                dcerpc_winreg_CloseKey_r(b, tctx, &c),
 
2847
                "winreg_CloseKey failed");
 
2848
        torture_assert_werr_ok(tctx, c.out.result,
 
2849
                "winreg_CloseKey failed");
 
2850
 
 
2851
        return true;
3027
2852
}
3028
2853
 
3029
 
static NTSTATUS enumvalues(struct dcerpc_pipe *p, struct policy_handle *handle,
3030
 
                           TALLOC_CTX *mem_ctx)
 
2854
static bool enumvalues(struct torture_context *tctx,
 
2855
                       struct dcerpc_binding_handle *b,
 
2856
                       struct policy_handle *handle)
3031
2857
{
3032
2858
        uint32_t enum_index = 0;
3033
2859
 
3038
2864
                uint8_t buf8[1024];
3039
2865
                NTSTATUS status;
3040
2866
                uint32_t size, length;
3041
 
                
 
2867
 
3042
2868
                r.in.handle = handle;
3043
2869
                r.in.enum_index = enum_index;
3044
2870
                name.name = "";
3051
2877
                r.in.size = &size;
3052
2878
                r.in.length = &length;
3053
2879
 
3054
 
                status = dcerpc_winreg_EnumValue(p, mem_ctx, &r);
 
2880
                status = dcerpc_winreg_EnumValue_r(b, tctx, &r);
3055
2881
                if (!NT_STATUS_IS_OK(status) || !W_ERROR_IS_OK(r.out.result)) {
3056
 
                        return NT_STATUS_OK;
 
2882
                        return true;
3057
2883
                }
3058
2884
                enum_index += 1;
3059
2885
        }
3060
2886
}
3061
2887
 
3062
 
static NTSTATUS enumkeys(struct dcerpc_pipe *p, struct policy_handle *handle, 
3063
 
                         TALLOC_CTX *mem_ctx, int depth)
 
2888
static bool enumkeys(struct torture_context *tctx,
 
2889
                     struct dcerpc_binding_handle *b,
 
2890
                     struct policy_handle *handle,
 
2891
                     int depth)
3064
2892
{
3065
2893
        struct winreg_EnumKey r;
3066
2894
        struct winreg_StringBuf kclass, name;
3068
2896
        NTTIME t = 0;
3069
2897
 
3070
2898
        if (depth <= 0) {
3071
 
                return NT_STATUS_OK;
 
2899
                return true;
3072
2900
        }
3073
2901
 
3074
2902
        kclass.name   = "";
3082
2910
        r.in.last_changed_time = &t;
3083
2911
 
3084
2912
        do {
3085
 
                TALLOC_CTX *tmp_ctx;
3086
2913
                struct winreg_OpenKey o;
3087
2914
                struct policy_handle key_handle;
3088
2915
                int i;
3089
2916
 
3090
 
                if (!(tmp_ctx = talloc_new(mem_ctx))) {
3091
 
                        return NT_STATUS_NO_MEMORY;
3092
 
                }
3093
 
 
3094
2917
                name.name = NULL;
3095
2918
                name.size = 1024;
3096
2919
 
3097
 
                status = dcerpc_winreg_EnumKey(p, tmp_ctx, &r);
 
2920
                status = dcerpc_winreg_EnumKey_r(b, tctx, &r);
3098
2921
                if (!NT_STATUS_IS_OK(status) || !W_ERROR_IS_OK(r.out.result)) {
3099
2922
                        /* We're done enumerating */
3100
 
                        talloc_free(tmp_ctx);
3101
 
                        return NT_STATUS_OK;
 
2923
                        return true;
3102
2924
                }
3103
2925
 
3104
 
                for (i=0; i<10-depth; i++)
3105
 
                        printf(" ");
3106
 
                printf("%s\n", r.out.name->name);
3107
 
                        
 
2926
                for (i=0; i<10-depth; i++) {
 
2927
                        torture_comment(tctx, " ");
 
2928
                }
 
2929
                torture_comment(tctx, "%s\n", r.out.name->name);
3108
2930
 
3109
2931
                o.in.parent_handle = handle;
3110
2932
                o.in.keyname.name = r.out.name->name;
3111
 
                o.in.unknown = 0;
 
2933
                o.in.options = 0;
3112
2934
                o.in.access_mask = SEC_FLAG_MAXIMUM_ALLOWED;
3113
2935
                o.out.handle = &key_handle;
3114
2936
 
3115
 
                status = dcerpc_winreg_OpenKey(p, tmp_ctx, &o);
 
2937
                status = dcerpc_winreg_OpenKey_r(b, tctx, &o);
3116
2938
                if (NT_STATUS_IS_OK(status) && W_ERROR_IS_OK(o.out.result)) {
3117
 
                        enumkeys(p, &key_handle, tmp_ctx, depth-1);
3118
 
                        enumvalues(p, &key_handle, tmp_ctx);
3119
 
                        status = winreg_close(p, &key_handle);
3120
 
                        if (!NT_STATUS_IS_OK(status)) {
3121
 
                                return status;
3122
 
                        }
 
2939
                        enumkeys(tctx, b, &key_handle, depth-1);
 
2940
                        enumvalues(tctx, b, &key_handle);
 
2941
                        torture_assert(tctx, winreg_close(tctx, b, &key_handle), "");
3123
2942
                }
3124
2943
 
3125
 
                talloc_free(tmp_ctx);
3126
 
 
3127
2944
                r.in.enum_index += 1;
3128
2945
        } while(true);
3129
2946
 
3130
 
        return NT_STATUS_OK;
 
2947
        return true;
3131
2948
}
3132
2949
 
3133
 
typedef NTSTATUS (*winreg_open_fn)(struct dcerpc_pipe *, TALLOC_CTX *, void *);
 
2950
typedef NTSTATUS (*winreg_open_fn)(struct dcerpc_binding_handle *, TALLOC_CTX *, void *);
3134
2951
 
3135
 
static bool test_Open3(struct dcerpc_pipe *p, TALLOC_CTX *mem_ctx, 
 
2952
static bool test_Open3(struct torture_context *tctx,
 
2953
                       struct dcerpc_binding_handle *b,
3136
2954
                       const char *name, winreg_open_fn open_fn)
3137
2955
{
3138
2956
        struct policy_handle handle;
3139
2957
        struct winreg_OpenHKLM r;
3140
 
        NTSTATUS status;
3141
2958
 
3142
2959
        r.in.system_name = 0;
3143
2960
        r.in.access_mask = SEC_FLAG_MAXIMUM_ALLOWED;
3144
2961
        r.out.handle = &handle;
3145
 
        
3146
 
        status = open_fn(p, mem_ctx, &r);
3147
 
        if (!NT_STATUS_IS_OK(status) || !W_ERROR_IS_OK(r.out.result)) {
3148
 
                d_printf("(%s) %s failed: %s, %s\n", __location__, name,
3149
 
                         nt_errstr(status), win_errstr(r.out.result));
3150
 
                return false;
3151
 
        }
3152
 
 
3153
 
        enumkeys(p, &handle, mem_ctx, 4);
3154
 
 
3155
 
        status = winreg_close(p, &handle);
3156
 
        if (!NT_STATUS_IS_OK(status)) {
3157
 
                d_printf("(%s) dcerpc_CloseKey failed: %s\n",
3158
 
                         __location__, nt_errstr(status));
3159
 
                return false;
3160
 
        }
 
2962
 
 
2963
        torture_assert_ntstatus_ok(tctx,
 
2964
                open_fn(b, tctx, &r),
 
2965
                talloc_asprintf(tctx, "%s failed", name));
 
2966
        torture_assert_werr_ok(tctx, r.out.result,
 
2967
                talloc_asprintf(tctx, "%s failed", name));
 
2968
 
 
2969
        enumkeys(tctx, b, &handle, 4);
 
2970
 
 
2971
        torture_assert(tctx,
 
2972
                winreg_close(tctx, b, &handle),
 
2973
                "dcerpc_CloseKey failed");
3161
2974
 
3162
2975
        return true;
3163
2976
}
3164
2977
 
3165
 
bool torture_samba3_rpc_winreg(struct torture_context *torture)
 
2978
static bool torture_samba3_rpc_winreg(struct torture_context *torture)
3166
2979
{
3167
 
        NTSTATUS status;
3168
2980
        struct dcerpc_pipe *p;
3169
 
        TALLOC_CTX *mem_ctx;
 
2981
        struct dcerpc_binding_handle *b;
3170
2982
        bool ret = true;
3171
2983
        struct {
3172
2984
                const char *name;
3173
2985
                winreg_open_fn fn;
3174
2986
        } open_fns[] = {
3175
 
                {"OpenHKLM", (winreg_open_fn)dcerpc_winreg_OpenHKLM },
3176
 
                {"OpenHKU",  (winreg_open_fn)dcerpc_winreg_OpenHKU },
3177
 
                {"OpenHKPD", (winreg_open_fn)dcerpc_winreg_OpenHKPD },
3178
 
                {"OpenHKPT", (winreg_open_fn)dcerpc_winreg_OpenHKPT },
3179
 
                {"OpenHKCR", (winreg_open_fn)dcerpc_winreg_OpenHKCR }};
 
2987
                {"OpenHKLM", (winreg_open_fn)dcerpc_winreg_OpenHKLM_r },
 
2988
                {"OpenHKU",  (winreg_open_fn)dcerpc_winreg_OpenHKU_r },
 
2989
                {"OpenHKPD", (winreg_open_fn)dcerpc_winreg_OpenHKPD_r },
 
2990
                {"OpenHKPT", (winreg_open_fn)dcerpc_winreg_OpenHKPT_r },
 
2991
                {"OpenHKCR", (winreg_open_fn)dcerpc_winreg_OpenHKCR_r }};
3180
2992
#if 0
3181
2993
        int i;
3182
2994
#endif
3183
2995
 
3184
 
        mem_ctx = talloc_init("torture_rpc_winreg");
3185
 
 
3186
 
        status = torture_rpc_connection(torture, &p, &ndr_table_winreg);
3187
 
 
3188
 
        if (!NT_STATUS_IS_OK(status)) {
3189
 
                talloc_free(mem_ctx);
3190
 
                return false;
3191
 
        }
 
2996
        torture_assert_ntstatus_ok(torture,
 
2997
                torture_rpc_connection(torture, &p, &ndr_table_winreg),
 
2998
                "failed to setup winreg");
 
2999
 
 
3000
        b = p->binding_handle;
3192
3001
 
3193
3002
#if 1
3194
 
        ret = test_Open3(p, mem_ctx, open_fns[0].name, open_fns[0].fn);
 
3003
        ret = test_Open3(torture, b, open_fns[0].name, open_fns[0].fn);
3195
3004
#else
3196
3005
        for (i = 0; i < ARRAY_SIZE(open_fns); i++) {
3197
 
                if (!test_Open3(p, mem_ctx, open_fns[i].name, open_fns[i].fn))
 
3006
                if (!test_Open3(torture, b, open_fns[i].name, open_fns[i].fn))
3198
3007
                        ret = false;
3199
3008
        }
3200
3009
#endif
3201
 
 
3202
 
        talloc_free(mem_ctx);
3203
 
 
3204
3010
        return ret;
3205
3011
}
3206
3012
 
3207
 
static NTSTATUS get_shareinfo(TALLOC_CTX *mem_ctx,
3208
 
                              struct loadparm_context *lp_ctx,
3209
 
                              struct smbcli_state *cli,
3210
 
                              const char *share,
3211
 
                              struct srvsvc_NetShareInfo502 **info502)
 
3013
static bool get_shareinfo(struct torture_context *tctx,
 
3014
                          struct dcerpc_binding_handle *b,
 
3015
                          const char *servername,
 
3016
                          const char *share,
 
3017
                          struct srvsvc_NetShareInfo502 **info502)
3212
3018
{
3213
 
        struct smbcli_tree *ipc;
3214
 
        struct dcerpc_pipe *p;
3215
3019
        struct srvsvc_NetShareGetInfo r;
3216
3020
        union srvsvc_NetShareInfo info;
3217
 
        NTSTATUS status;
3218
 
 
3219
 
        if (!(p = dcerpc_pipe_init(cli,
3220
 
                                   cli->transport->socket->event.ctx,
3221
 
                                   lp_iconv_convenience(lp_ctx)))) {
3222
 
                status = NT_STATUS_NO_MEMORY;
3223
 
                goto fail;
3224
 
        }
3225
 
 
3226
 
        status = secondary_tcon(p, cli->session, "IPC$", &ipc);
3227
 
        if (!NT_STATUS_IS_OK(status)) {
3228
 
                goto fail;
3229
 
        }
3230
 
 
3231
 
        status = dcerpc_pipe_open_smb(p, ipc, "\\pipe\\srvsvc");
3232
 
        if (!NT_STATUS_IS_OK(status)) {
3233
 
                d_printf("dcerpc_pipe_open_smb failed: %s\n",
3234
 
                         nt_errstr(status));
3235
 
                goto fail;
3236
 
        }
3237
 
 
3238
 
        status = dcerpc_bind_auth_none(p, &ndr_table_srvsvc);
3239
 
        if (!NT_STATUS_IS_OK(status)) {
3240
 
                d_printf("dcerpc_bind_auth_none failed: %s\n",
3241
 
                         nt_errstr(status));
3242
 
                goto fail;
3243
 
        }
3244
 
 
3245
 
        r.in.server_unc = talloc_asprintf(mem_ctx, "\\\\%s",
3246
 
                                          dcerpc_server_name(p));
 
3021
 
 
3022
        r.in.server_unc = talloc_asprintf(tctx, "\\\\%s", servername);
3247
3023
        r.in.share_name = share;
3248
3024
        r.in.level = 502;
3249
3025
        r.out.info = &info;
3250
3026
 
3251
 
        status = dcerpc_srvsvc_NetShareGetInfo(p, p, &r);
3252
 
        if (!NT_STATUS_IS_OK(status) || !W_ERROR_IS_OK(r.out.result)) {
3253
 
                d_printf("(%s) srvsvc_NetShareGetInfo failed: %s, %s\n", __location__,
3254
 
                         nt_errstr(status), win_errstr(r.out.result));
3255
 
                status = NT_STATUS_IS_OK(status) ? werror_to_ntstatus(r.out.result) : status;
3256
 
                goto fail;
3257
 
        }
3258
 
 
3259
 
        *info502 = talloc_move(mem_ctx, &info.info502);
3260
 
        return NT_STATUS_OK;
3261
 
 
3262
 
fail:
3263
 
        talloc_free(p);
3264
 
        return status;
 
3027
        torture_assert_ntstatus_ok(tctx,
 
3028
                dcerpc_srvsvc_NetShareGetInfo_r(b, tctx, &r),
 
3029
                "srvsvc_NetShareGetInfo failed");
 
3030
        torture_assert_werr_ok(tctx, r.out.result,
 
3031
                "srvsvc_NetShareGetInfo failed");
 
3032
 
 
3033
        *info502 = talloc_move(tctx, &info.info502);
 
3034
 
 
3035
        return true;
3265
3036
}
3266
3037
 
3267
3038
/*
3268
3039
 * Get us a handle on HKLM\
3269
3040
 */
3270
3041
 
3271
 
static NTSTATUS get_hklm_handle(TALLOC_CTX *mem_ctx,
3272
 
                                struct smbcli_state *cli,
3273
 
                                struct smb_iconv_convenience *iconv_convenience,
3274
 
                                struct dcerpc_pipe **pipe_p,
3275
 
                                struct policy_handle **handle)
 
3042
static bool get_hklm_handle(struct torture_context *tctx,
 
3043
                            struct dcerpc_binding_handle *b,
 
3044
                            struct policy_handle *handle)
3276
3045
{
3277
 
        struct smbcli_tree *ipc;
3278
 
        struct dcerpc_pipe *p;
3279
3046
        struct winreg_OpenHKLM r;
3280
 
        NTSTATUS status;
3281
 
        struct policy_handle *result;
3282
 
 
3283
 
        result = talloc(mem_ctx, struct policy_handle);
3284
 
 
3285
 
        if (result == NULL) {
3286
 
                return NT_STATUS_NO_MEMORY;
3287
 
        }
3288
 
 
3289
 
        if (!(p = dcerpc_pipe_init(result,
3290
 
                                   cli->transport->socket->event.ctx,
3291
 
                                   iconv_convenience))) {
3292
 
                status = NT_STATUS_NO_MEMORY;
3293
 
                goto fail;
3294
 
        }
3295
 
 
3296
 
        status = secondary_tcon(p, cli->session, "IPC$", &ipc);
3297
 
        if (!NT_STATUS_IS_OK(status)) {
3298
 
                goto fail;
3299
 
        }
3300
 
 
3301
 
        status = dcerpc_pipe_open_smb(p, ipc, "\\winreg");
3302
 
        if (!NT_STATUS_IS_OK(status)) {
3303
 
                d_printf("dcerpc_pipe_open_smb failed: %s\n",
3304
 
                         nt_errstr(status));
3305
 
                goto fail;
3306
 
        }
3307
 
 
3308
 
        status = dcerpc_bind_auth_none(p, &ndr_table_winreg);
3309
 
        if (!NT_STATUS_IS_OK(status)) {
3310
 
                d_printf("dcerpc_bind_auth_none failed: %s\n",
3311
 
                         nt_errstr(status));
3312
 
                goto fail;
3313
 
        }
 
3047
        struct policy_handle result;
3314
3048
 
3315
3049
        r.in.system_name = 0;
3316
3050
        r.in.access_mask = SEC_FLAG_MAXIMUM_ALLOWED;
3317
 
        r.out.handle = result;
3318
 
 
3319
 
        status = dcerpc_winreg_OpenHKLM(p, p, &r);
3320
 
        if (!NT_STATUS_IS_OK(status) || !W_ERROR_IS_OK(r.out.result)) {
3321
 
                d_printf("(%s) OpenHKLM failed: %s, %s\n", __location__,
3322
 
                         nt_errstr(status), win_errstr(r.out.result));
3323
 
                status = NT_STATUS_IS_OK(status) ? werror_to_ntstatus(r.out.result) : status;
3324
 
                goto fail;
3325
 
        }
3326
 
 
3327
 
        *pipe_p = p;
 
3051
        r.out.handle = &result;
 
3052
 
 
3053
        torture_assert_ntstatus_ok(tctx,
 
3054
                dcerpc_winreg_OpenHKLM_r(b, tctx, &r),
 
3055
                "OpenHKLM failed");
 
3056
        torture_assert_werr_ok(tctx, r.out.result,
 
3057
                "OpenHKLM failed");
 
3058
 
3328
3059
        *handle = result;
3329
 
        return NT_STATUS_OK;
3330
3060
 
3331
 
 fail:
3332
 
        talloc_free(result);
3333
 
        return status;
 
3061
        return true;
3334
3062
}
3335
3063
 
3336
 
static NTSTATUS torture_samba3_createshare(struct smbcli_state *cli,
3337
 
                                           struct smb_iconv_convenience *iconv_convenience,
3338
 
                                           const char *sharename)
 
3064
static bool torture_samba3_createshare(struct torture_context *tctx,
 
3065
                                       struct dcerpc_binding_handle *b,
 
3066
                                       const char *sharename)
3339
3067
{
3340
 
        struct dcerpc_pipe *p;
3341
 
        struct policy_handle *hklm = NULL;
 
3068
        struct policy_handle hklm;
3342
3069
        struct policy_handle new_handle;
3343
3070
        struct winreg_CreateKey c;
3344
3071
        struct winreg_CloseKey cl;
3345
3072
        enum winreg_CreateAction action_taken;
3346
 
        NTSTATUS status;
3347
 
        TALLOC_CTX *mem_ctx;
3348
 
 
3349
 
        mem_ctx = talloc_new(cli);
3350
 
        NT_STATUS_HAVE_NO_MEMORY(mem_ctx);
3351
 
 
3352
 
        status = get_hklm_handle(mem_ctx, cli, iconv_convenience, &p, &hklm);
3353
 
        if (!NT_STATUS_IS_OK(status)) {
3354
 
                d_printf("get_hklm_handle failed: %s\n", nt_errstr(status));
3355
 
                goto fail;
3356
 
        }
3357
 
 
3358
 
        c.in.handle = hklm;
 
3073
 
 
3074
        c.in.handle = &hklm;
3359
3075
        c.in.name.name = talloc_asprintf(
3360
 
                mem_ctx, "software\\samba\\smbconf\\%s", sharename);
3361
 
        if (c.in.name.name == NULL) {
3362
 
                d_printf("talloc_asprintf failed\n");
3363
 
                status = NT_STATUS_NO_MEMORY;
3364
 
                goto fail;
3365
 
        }
 
3076
                tctx, "software\\samba\\smbconf\\%s", sharename);
 
3077
        torture_assert(tctx, c.in.name.name, "talloc_asprintf failed");
 
3078
 
3366
3079
        c.in.keyclass.name = "";
3367
3080
        c.in.options = 0;
3368
3081
        c.in.access_mask = SEC_FLAG_MAXIMUM_ALLOWED;
3371
3084
        c.out.new_handle = &new_handle;
3372
3085
        c.out.action_taken = &action_taken;
3373
3086
 
3374
 
        status = dcerpc_winreg_CreateKey(p, p, &c);
3375
 
        if (!NT_STATUS_IS_OK(status) || !W_ERROR_IS_OK(c.out.result)) {
3376
 
                d_printf("(%s) OpenKey failed: %s, %s\n", __location__,
3377
 
                         nt_errstr(status), win_errstr(c.out.result));
3378
 
                status = NT_STATUS_IS_OK(status) ? werror_to_ntstatus(c.out.result) : status;
3379
 
                goto fail;
3380
 
        }
 
3087
        torture_assert_ntstatus_ok(tctx,
 
3088
                dcerpc_winreg_CreateKey_r(b, tctx, &c),
 
3089
                "OpenKey failed");
 
3090
        torture_assert_werr_ok(tctx, c.out.result,
 
3091
                "OpenKey failed");
3381
3092
 
3382
3093
        cl.in.handle = &new_handle;
3383
3094
        cl.out.handle = &new_handle;
3384
 
        status = dcerpc_winreg_CloseKey(p, p, &cl);
3385
 
        if (!NT_STATUS_IS_OK(status) || !W_ERROR_IS_OK(cl.out.result)) {
3386
 
                d_printf("(%s) OpenKey failed: %s, %s\n", __location__,
3387
 
                         nt_errstr(status), win_errstr(cl.out.result));
3388
 
                status = NT_STATUS_IS_OK(status) ? werror_to_ntstatus(cl.out.result) : status;
3389
 
                goto fail;
3390
 
        }
3391
 
 
3392
 
 
3393
 
fail:
3394
 
        talloc_free(mem_ctx);
3395
 
        return status;
 
3095
 
 
3096
        torture_assert_ntstatus_ok(tctx,
 
3097
                dcerpc_winreg_CloseKey_r(b, tctx, &cl),
 
3098
                "CloseKey failed");
 
3099
        torture_assert_werr_ok(tctx, cl.out.result,
 
3100
                "CloseKey failed");
 
3101
 
 
3102
        return true;
3396
3103
}
3397
3104
 
3398
 
static NTSTATUS torture_samba3_deleteshare(struct torture_context *torture,
3399
 
                                           struct smbcli_state *cli,
3400
 
                                           const char *sharename)
 
3105
static bool torture_samba3_deleteshare(struct torture_context *tctx,
 
3106
                                       struct dcerpc_binding_handle *b,
 
3107
                                       const char *sharename)
3401
3108
{
3402
 
        struct dcerpc_pipe *p;
3403
 
        struct policy_handle *hklm = NULL;
 
3109
        struct policy_handle hklm;
3404
3110
        struct winreg_DeleteKey d;
3405
 
        NTSTATUS status;
3406
 
        TALLOC_CTX *mem_ctx;
3407
 
 
3408
 
        mem_ctx = talloc_new(cli);
3409
 
        NT_STATUS_HAVE_NO_MEMORY(mem_ctx);
3410
 
 
3411
 
        status = get_hklm_handle(cli, cli, lp_iconv_convenience(torture->lp_ctx),
3412
 
                                 &p, &hklm);
3413
 
        if (!NT_STATUS_IS_OK(status)) {
3414
 
                d_printf("get_hklm_handle failed: %s\n", nt_errstr(status));
3415
 
                goto fail;
3416
 
        }
3417
 
 
3418
 
        d.in.handle = hklm;
 
3111
 
 
3112
        torture_assert(tctx,
 
3113
                get_hklm_handle(tctx, b, &hklm),
 
3114
                "get_hklm_handle failed");
 
3115
 
 
3116
        d.in.handle = &hklm;
3419
3117
        d.in.key.name = talloc_asprintf(
3420
 
                mem_ctx, "software\\samba\\smbconf\\%s", sharename);
3421
 
        if (d.in.key.name == NULL) {
3422
 
                d_printf("talloc_asprintf failed\n");
3423
 
                status = NT_STATUS_NO_MEMORY;
3424
 
                goto fail;
3425
 
        }
3426
 
        status = dcerpc_winreg_DeleteKey(p, p, &d);
3427
 
        if (!NT_STATUS_IS_OK(status) || !W_ERROR_IS_OK(d.out.result)) {
3428
 
                d_printf("(%s) OpenKey failed: %s, %s\n", __location__,
3429
 
                         nt_errstr(status), win_errstr(d.out.result));
3430
 
                status = NT_STATUS_IS_OK(status) ? werror_to_ntstatus(d.out.result) : status;
3431
 
                goto fail;
3432
 
        }
3433
 
 
3434
 
fail:
3435
 
        talloc_free(mem_ctx);
3436
 
        return status;
 
3118
                tctx, "software\\samba\\smbconf\\%s", sharename);
 
3119
        torture_assert(tctx, d.in.key.name, "talloc_asprintf failed");
 
3120
 
 
3121
        torture_assert_ntstatus_ok(tctx,
 
3122
                dcerpc_winreg_DeleteKey_r(b, tctx, &d),
 
3123
                "DeleteKey failed");
 
3124
        torture_assert_werr_ok(tctx, d.out.result,
 
3125
                "DeleteKey failed");
 
3126
 
 
3127
        return true;
3437
3128
}
3438
3129
 
3439
 
static NTSTATUS torture_samba3_setconfig(struct smbcli_state *cli,
3440
 
                                         struct loadparm_context *lp_ctx,
3441
 
                                         const char *sharename,
3442
 
                                         const char *parameter,
3443
 
                                         const char *value)
 
3130
static bool torture_samba3_setconfig(struct torture_context *tctx,
 
3131
                                     struct dcerpc_binding_handle *b,
 
3132
                                     const char *sharename,
 
3133
                                     const char *parameter,
 
3134
                                     const char *value)
3444
3135
{
3445
 
        struct dcerpc_pipe *p = NULL;
3446
 
        struct policy_handle *hklm = NULL, key_handle;
 
3136
        struct policy_handle hklm, key_handle;
3447
3137
        struct winreg_OpenKey o;
3448
3138
        struct winreg_SetValue s;
3449
3139
        uint32_t type;
3450
3140
        DATA_BLOB val;
3451
 
        NTSTATUS status;
3452
 
 
3453
 
        status = get_hklm_handle(cli, cli, lp_iconv_convenience(lp_ctx), &p, &hklm);
3454
 
        if (!NT_STATUS_IS_OK(status)) {
3455
 
                d_printf("get_hklm_handle failed: %s\n", nt_errstr(status));
3456
 
                return status;;
3457
 
        }
3458
 
 
3459
 
        o.in.parent_handle = hklm;
 
3141
 
 
3142
        torture_assert(tctx,
 
3143
                get_hklm_handle(tctx, b, &hklm),
 
3144
                "get_hklm_handle failed");
 
3145
 
 
3146
        o.in.parent_handle = &hklm;
3460
3147
        o.in.keyname.name = talloc_asprintf(
3461
 
                hklm, "software\\samba\\smbconf\\%s", sharename);
3462
 
        if (o.in.keyname.name == NULL) {
3463
 
                d_printf("talloc_asprintf failed\n");
3464
 
                status = NT_STATUS_NO_MEMORY;
3465
 
                goto done;
3466
 
        }
3467
 
        o.in.unknown = 0;
 
3148
                tctx, "software\\samba\\smbconf\\%s", sharename);
 
3149
        torture_assert(tctx, o.in.keyname.name, "talloc_asprintf failed");
 
3150
 
 
3151
        o.in.options = 0;
3468
3152
        o.in.access_mask = SEC_FLAG_MAXIMUM_ALLOWED;
3469
3153
        o.out.handle = &key_handle;
3470
3154
 
3471
 
        status = dcerpc_winreg_OpenKey(p, p, &o);
3472
 
        if (!NT_STATUS_IS_OK(status) || !W_ERROR_IS_OK(o.out.result)) {
3473
 
                d_printf("(%s) OpenKey failed: %s, %s\n", __location__,
3474
 
                         nt_errstr(status), win_errstr(o.out.result));
3475
 
                status = NT_STATUS_IS_OK(status) ? werror_to_ntstatus(o.out.result) : status;
3476
 
                goto done;
3477
 
        }
 
3155
        torture_assert_ntstatus_ok(tctx,
 
3156
                dcerpc_winreg_OpenKey_r(b, tctx, &o),
 
3157
                "OpenKey failed");
 
3158
        torture_assert_werr_ok(tctx, o.out.result,
 
3159
                "OpenKey failed");
3478
3160
 
3479
 
        if (!reg_string_to_val(hklm, lp_iconv_convenience(lp_ctx), "REG_SZ", 
3480
 
                               value, &type, &val)) {
3481
 
                d_printf("(%s) reg_string_to_val failed\n", __location__);
3482
 
                goto done;
3483
 
        }
 
3161
        torture_assert(tctx,
 
3162
                reg_string_to_val(tctx, "REG_SZ", value, &type, &val),
 
3163
                "reg_string_to_val failed");
3484
3164
 
3485
3165
        s.in.handle = &key_handle;
3486
3166
        s.in.name.name = parameter;
3488
3168
        s.in.data = val.data;
3489
3169
        s.in.size = val.length;
3490
3170
 
3491
 
        status = dcerpc_winreg_SetValue(p, p, &s);
3492
 
        if (!NT_STATUS_IS_OK(status) || !W_ERROR_IS_OK(s.out.result)) {
3493
 
                d_printf("(%s) SetValue failed: %s, %s\n", __location__,
3494
 
                         nt_errstr(status), win_errstr(s.out.result));
3495
 
                status = NT_STATUS_IS_OK(status) ? werror_to_ntstatus(s.out.result) : status;
3496
 
                goto done;
3497
 
        }
 
3171
        torture_assert_ntstatus_ok(tctx,
 
3172
                dcerpc_winreg_SetValue_r(b, tctx, &s),
 
3173
                "SetValue failed");
 
3174
        torture_assert_werr_ok(tctx, s.out.result,
 
3175
                "SetValue failed");
3498
3176
 
3499
 
done:
3500
 
        talloc_free(hklm);
3501
 
        return status;
 
3177
        return true;
3502
3178
}
3503
3179
 
3504
 
bool torture_samba3_regconfig(struct torture_context *torture)
 
3180
static bool torture_samba3_regconfig(struct torture_context *torture)
3505
3181
{
3506
 
        struct smbcli_state *cli;
3507
3182
        struct srvsvc_NetShareInfo502 *i = NULL;
3508
 
        NTSTATUS status;
3509
 
        bool ret = false;
3510
3183
        const char *comment = "Dummer Kommentar";
3511
 
 
3512
 
        if (!(torture_open_connection(&cli, torture, 0))) {
3513
 
                return false;
3514
 
        }
3515
 
 
3516
 
        status = torture_samba3_createshare(cli, lp_iconv_convenience(torture->lp_ctx), "blubber");
3517
 
        if (!NT_STATUS_IS_OK(status)) {
3518
 
                torture_warning(torture, "torture_samba3_createshare failed: "
3519
 
                                "%s\n", nt_errstr(status));
3520
 
                goto done;
3521
 
        }
3522
 
 
3523
 
        status = torture_samba3_setconfig(cli, torture->lp_ctx, "blubber", "comment", comment);
3524
 
        if (!NT_STATUS_IS_OK(status)) {
3525
 
                torture_warning(torture, "torture_samba3_setconfig failed: "
3526
 
                                "%s\n", nt_errstr(status));
3527
 
                goto done;
3528
 
        }
3529
 
 
3530
 
        status = get_shareinfo(torture, torture->lp_ctx, cli, "blubber", &i);
3531
 
        if (!NT_STATUS_IS_OK(status)) {
3532
 
                torture_warning(torture, "get_shareinfo failed: "
3533
 
                                "%s\n", nt_errstr(status));
3534
 
                goto done;
3535
 
        }
3536
 
 
3537
 
        if (strcmp(comment, i->comment) != 0) {
3538
 
                torture_warning(torture, "Expected comment [%s], got [%s]\n",
3539
 
                                comment, i->comment);
3540
 
                goto done;
3541
 
        }
3542
 
 
3543
 
        status = torture_samba3_deleteshare(torture, cli, "blubber");
3544
 
        if (!NT_STATUS_IS_OK(status)) {
3545
 
                torture_warning(torture, "torture_samba3_deleteshare failed: "
3546
 
                                "%s\n", nt_errstr(status));
3547
 
                goto done;
3548
 
        }
3549
 
 
3550
 
        ret = true;
3551
 
 done:
3552
 
        talloc_free(cli);
3553
 
        return ret;
 
3184
        struct dcerpc_pipe *srvsvc_pipe, *winreg_pipe;
 
3185
 
 
3186
        torture_assert_ntstatus_ok(torture,
 
3187
                torture_rpc_connection(torture, &srvsvc_pipe, &ndr_table_srvsvc),
 
3188
                "failed to setup srvsvc");
 
3189
 
 
3190
        torture_assert_ntstatus_ok(torture,
 
3191
                torture_rpc_connection(torture, &winreg_pipe, &ndr_table_winreg),
 
3192
                "failed to setup winreg");
 
3193
 
 
3194
        torture_assert(torture,
 
3195
                torture_samba3_createshare(torture, winreg_pipe->binding_handle, "blubber"),
 
3196
                "torture_samba3_createshare failed");
 
3197
 
 
3198
        torture_assert(torture,
 
3199
                torture_samba3_setconfig(torture, winreg_pipe->binding_handle, "blubber", "comment", comment),
 
3200
                "torture_samba3_setconfig failed");
 
3201
 
 
3202
        torture_assert(torture,
 
3203
                get_shareinfo(torture, srvsvc_pipe->binding_handle, dcerpc_server_name(srvsvc_pipe), "blubber", &i),
 
3204
                "get_shareinfo failed");
 
3205
 
 
3206
        torture_assert_str_equal(torture, comment, i->comment,
 
3207
                "got unexpected comment");
 
3208
 
 
3209
        torture_assert(torture,
 
3210
                torture_samba3_deleteshare(torture, winreg_pipe->binding_handle, "blubber"),
 
3211
                "torture_samba3_deleteshare failed");
 
3212
 
 
3213
        return true;
 
3214
}
 
3215
 
 
3216
/*
 
3217
 * Test that even with a result of 0 rids the array is returned as a
 
3218
 * non-NULL pointer. Yes, XP does notice.
 
3219
 */
 
3220
 
 
3221
bool torture_samba3_getaliasmembership_0(struct torture_context *torture)
 
3222
{
 
3223
        struct dcerpc_pipe *p;
 
3224
        struct dcerpc_binding_handle *b;
 
3225
        struct samr_Connect2 c;
 
3226
        struct samr_OpenDomain o;
 
3227
        struct dom_sid sid;
 
3228
        struct lsa_SidPtr ptr;
 
3229
        struct lsa_SidArray sids;
 
3230
        struct samr_GetAliasMembership g;
 
3231
        struct samr_Ids rids;
 
3232
        struct policy_handle samr, domain;
 
3233
 
 
3234
        torture_assert_ntstatus_ok(torture,
 
3235
                torture_rpc_connection(torture, &p, &ndr_table_samr),
 
3236
                "failed to setup samr");
 
3237
 
 
3238
        b = p->binding_handle;
 
3239
 
 
3240
        c.in.system_name = NULL;
 
3241
        c.in.access_mask = SAMR_ACCESS_LOOKUP_DOMAIN;
 
3242
        c.out.connect_handle = &samr;
 
3243
        torture_assert_ntstatus_ok(torture,
 
3244
                dcerpc_samr_Connect2_r(b, torture, &c),
 
3245
                "");
 
3246
        torture_assert_ntstatus_ok(torture, c.out.result,
 
3247
                "");
 
3248
        dom_sid_parse("S-1-5-32", &sid);
 
3249
        o.in.connect_handle = &samr;
 
3250
        o.in.access_mask = SAMR_DOMAIN_ACCESS_LOOKUP_ALIAS;
 
3251
        o.in.sid = &sid;
 
3252
        o.out.domain_handle = &domain;
 
3253
        torture_assert_ntstatus_ok(torture,
 
3254
                dcerpc_samr_OpenDomain_r(b, torture, &o),
 
3255
                "");
 
3256
        torture_assert_ntstatus_ok(torture, o.out.result,
 
3257
                "");
 
3258
        dom_sid_parse("S-1-2-3-4-5", &sid);
 
3259
        ptr.sid = &sid;
 
3260
        sids.num_sids = 1;
 
3261
        sids.sids = &ptr;
 
3262
        g.in.domain_handle = &domain;
 
3263
        g.in.sids = &sids;
 
3264
        g.out.rids = &rids;
 
3265
        torture_assert_ntstatus_ok(torture,
 
3266
                dcerpc_samr_GetAliasMembership_r(b, torture, &g),
 
3267
                "");
 
3268
        torture_assert_ntstatus_ok(torture, g.out.result,
 
3269
                "");
 
3270
        if (rids.ids == NULL) {
 
3271
                /* This is the piece to test here */
 
3272
                torture_fail(torture,
 
3273
                        "torture_samba3_getaliasmembership_0: "
 
3274
                        "Server returns NULL rids array\n");
 
3275
        }
 
3276
 
 
3277
        return true;
 
3278
}
 
3279
 
 
3280
struct torture_suite *torture_rpc_samba3(TALLOC_CTX *mem_ctx)
 
3281
{
 
3282
        struct torture_suite *suite = torture_suite_create(mem_ctx, "samba3");
 
3283
 
 
3284
        torture_suite_add_simple_test(suite, "bind", torture_bind_samba3);
 
3285
        torture_suite_add_simple_test(suite, "netlogon", torture_netlogon_samba3);
 
3286
        torture_suite_add_simple_test(suite, "sessionkey", torture_samba3_sessionkey);
 
3287
        torture_suite_add_simple_test(suite, "srvsvc", torture_samba3_rpc_srvsvc);
 
3288
        torture_suite_add_simple_test(suite, "sharesec", torture_samba3_rpc_sharesec);
 
3289
        torture_suite_add_simple_test(suite, "getusername", torture_samba3_rpc_getusername);
 
3290
        torture_suite_add_simple_test(suite, "randomauth2", torture_samba3_rpc_randomauth2);
 
3291
        torture_suite_add_simple_test(suite, "lsa", torture_samba3_rpc_lsa);
 
3292
        torture_suite_add_simple_test(suite, "spoolss", torture_samba3_rpc_spoolss);
 
3293
        torture_suite_add_simple_test(suite, "wkssvc", torture_samba3_rpc_wkssvc);
 
3294
        torture_suite_add_simple_test(suite, "winreg", torture_samba3_rpc_winreg);
 
3295
        torture_suite_add_simple_test(suite, "getaliasmembership-0", torture_samba3_getaliasmembership_0);
 
3296
        torture_suite_add_simple_test(suite, "regconfig", torture_samba3_regconfig);
 
3297
 
 
3298
        suite->description = talloc_strdup(suite, "samba3 DCERPC interface tests");
 
3299
 
 
3300
        return suite;
3554
3301
}