~lefteris-nikoltsios/+junk/samba-lp1016895

« back to all changes in this revision

Viewing changes to source4/torture/rpc/testjoin.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:
25
25
*/
26
26
 
27
27
#include "includes.h"
28
 
#include "torture/torture.h"
29
28
#include "system/time.h"
30
29
#include "../lib/crypto/crypto.h"
31
30
#include "libnet/libnet.h"
32
31
#include "lib/cmdline/popt_common.h"
33
 
#include "lib/ldb/include/ldb.h"
34
32
#include "librpc/gen_ndr/ndr_samr_c.h"
35
33
 
36
34
#include "libcli/auth/libcli_auth.h"
37
 
#include "torture/rpc/rpc.h"
 
35
#include "torture/rpc/torture_rpc.h"
38
36
#include "libcli/security/security.h"
39
37
#include "param/param.h"
40
38
 
51
49
};
52
50
 
53
51
 
54
 
static NTSTATUS DeleteUser_byname(struct dcerpc_pipe *p, TALLOC_CTX *mem_ctx, 
 
52
static NTSTATUS DeleteUser_byname(struct dcerpc_binding_handle *b,
 
53
                                  TALLOC_CTX *mem_ctx,
55
54
                                  struct policy_handle *handle, const char *name)
56
55
{
57
56
        NTSTATUS status;
71
70
        n.out.rids = &rids;
72
71
        n.out.types = &types;
73
72
 
74
 
        status = dcerpc_samr_LookupNames(p, mem_ctx, &n);
75
 
        if (NT_STATUS_IS_OK(status)) {
 
73
        status = dcerpc_samr_LookupNames_r(b, mem_ctx, &n);
 
74
        if (!NT_STATUS_IS_OK(status)) {
 
75
                return status;
 
76
        }
 
77
        if (NT_STATUS_IS_OK(n.out.result)) {
76
78
                rid = n.out.rids->ids[0];
77
79
        } else {
78
 
                return status;
 
80
                return n.out.result;
79
81
        }
80
82
 
81
83
        r.in.domain_handle = handle;
83
85
        r.in.rid = rid;
84
86
        r.out.user_handle = &user_handle;
85
87
 
86
 
        status = dcerpc_samr_OpenUser(p, mem_ctx, &r);
 
88
        status = dcerpc_samr_OpenUser_r(b, mem_ctx, &r);
87
89
        if (!NT_STATUS_IS_OK(status)) {
88
90
                printf("OpenUser(%s) failed - %s\n", name, nt_errstr(status));
89
91
                return status;
90
92
        }
 
93
        if (!NT_STATUS_IS_OK(r.out.result)) {
 
94
                printf("OpenUser(%s) failed - %s\n", name, nt_errstr(r.out.result));
 
95
                return r.out.result;
 
96
        }
91
97
 
92
98
        d.in.user_handle = &user_handle;
93
99
        d.out.user_handle = &user_handle;
94
 
        status = dcerpc_samr_DeleteUser(p, mem_ctx, &d);
 
100
        status = dcerpc_samr_DeleteUser_r(b, mem_ctx, &d);
95
101
        if (!NT_STATUS_IS_OK(status)) {
96
102
                return status;
97
103
        }
 
104
        if (!NT_STATUS_IS_OK(d.out.result)) {
 
105
                return d.out.result;
 
106
        }
98
107
 
99
108
        return NT_STATUS_OK;
100
109
}
105
114
  when finished
106
115
*/
107
116
 
108
 
struct test_join *torture_create_testuser(struct torture_context *torture,
109
 
                                          const char *username, 
110
 
                                          const char *domain,
111
 
                                          uint16_t acct_type,
112
 
                                          const char **random_password)
 
117
struct test_join *torture_create_testuser_max_pwlen(struct torture_context *torture,
 
118
                                                    const char *username,
 
119
                                                    const char *domain,
 
120
                                                    uint16_t acct_type,
 
121
                                                    const char **random_password,
 
122
                                                    int max_pw_len)
113
123
{
114
124
        NTSTATUS status;
115
125
        struct samr_Connect c;
132
142
        struct test_join *join;
133
143
        char *random_pw;
134
144
        const char *dc_binding = torture_setting_string(torture, "dc_binding", NULL);
 
145
        struct dcerpc_binding_handle *b = NULL;
135
146
 
136
147
        join = talloc(NULL, struct test_join);
137
148
        if (join == NULL) {
157
168
        if (!NT_STATUS_IS_OK(status)) {
158
169
                return NULL;
159
170
        }
 
171
        b = join->p->binding_handle;
160
172
 
161
173
        c.in.system_name = NULL;
162
174
        c.in.access_mask = SEC_FLAG_MAXIMUM_ALLOWED;
163
175
        c.out.connect_handle = &handle;
164
176
 
165
 
        status = dcerpc_samr_Connect(join->p, join, &c);
 
177
        status = dcerpc_samr_Connect_r(b, join, &c);
166
178
        if (!NT_STATUS_IS_OK(status)) {
167
179
                const char *errstr = nt_errstr(status);
168
 
                if (NT_STATUS_EQUAL(status, NT_STATUS_NET_WRITE_FAULT)) {
169
 
                        errstr = dcerpc_errstr(join, join->p->last_fault_code);
170
 
                }
171
 
                printf("samr_Connect failed - %s\n", errstr);
172
 
                return NULL;
173
 
        }
174
 
 
175
 
        printf("Opening domain %s\n", domain);
176
 
 
177
 
        name.string = domain;
178
 
        l.in.connect_handle = &handle;
179
 
        l.in.domain_name = &name;
180
 
        l.out.sid = &sid;
181
 
 
182
 
        status = dcerpc_samr_LookupDomain(join->p, join, &l);
183
 
        if (!NT_STATUS_IS_OK(status)) {
184
 
                printf("LookupDomain failed - %s\n", nt_errstr(status));
185
 
                goto failed;
 
180
                printf("samr_Connect failed - %s\n", errstr);
 
181
                return NULL;
 
182
        }
 
183
        if (!NT_STATUS_IS_OK(c.out.result)) {
 
184
                const char *errstr = nt_errstr(c.out.result);
 
185
                printf("samr_Connect failed - %s\n", errstr);
 
186
                return NULL;
 
187
        }
 
188
 
 
189
        if (domain) {
 
190
                printf("Opening domain %s\n", domain);
 
191
 
 
192
                name.string = domain;
 
193
                l.in.connect_handle = &handle;
 
194
                l.in.domain_name = &name;
 
195
                l.out.sid = &sid;
 
196
 
 
197
                status = dcerpc_samr_LookupDomain_r(b, join, &l);
 
198
                if (!NT_STATUS_IS_OK(status)) {
 
199
                        printf("LookupDomain failed - %s\n", nt_errstr(status));
 
200
                        goto failed;
 
201
                }
 
202
                if (!NT_STATUS_IS_OK(l.out.result)) {
 
203
                        printf("LookupDomain failed - %s\n", nt_errstr(l.out.result));
 
204
                        goto failed;
 
205
                }
 
206
        } else {
 
207
                struct samr_EnumDomains e;
 
208
                uint32_t resume_handle = 0, num_entries;
 
209
                struct samr_SamArray *sam;
 
210
                int i;
 
211
 
 
212
                e.in.connect_handle = &handle;
 
213
                e.in.buf_size = (uint32_t)-1;
 
214
                e.in.resume_handle = &resume_handle;
 
215
                e.out.sam = &sam;
 
216
                e.out.num_entries = &num_entries;
 
217
                e.out.resume_handle = &resume_handle;
 
218
 
 
219
                status = dcerpc_samr_EnumDomains_r(b, join, &e);
 
220
                if (!NT_STATUS_IS_OK(status)) {
 
221
                        printf("EnumDomains failed - %s\n", nt_errstr(status));
 
222
                        goto failed;
 
223
                }
 
224
                if (!NT_STATUS_IS_OK(e.out.result)) {
 
225
                        printf("EnumDomains failed - %s\n", nt_errstr(e.out.result));
 
226
                        goto failed;
 
227
                }
 
228
                if ((num_entries != 2) || (sam && sam->count != 2)) {
 
229
                        printf("unexpected number of domains\n");
 
230
                        goto failed;
 
231
                }
 
232
                for (i=0; i < 2; i++) {
 
233
                        if (!strequal(sam->entries[i].name.string, "builtin")) {
 
234
                                domain = sam->entries[i].name.string;
 
235
                                break;
 
236
                        }
 
237
                }
 
238
                if (domain) {
 
239
                        printf("Opening domain %s\n", domain);
 
240
 
 
241
                        name.string = domain;
 
242
                        l.in.connect_handle = &handle;
 
243
                        l.in.domain_name = &name;
 
244
                        l.out.sid = &sid;
 
245
 
 
246
                        status = dcerpc_samr_LookupDomain_r(b, join, &l);
 
247
                        if (!NT_STATUS_IS_OK(status)) {
 
248
                                printf("LookupDomain failed - %s\n", nt_errstr(status));
 
249
                                goto failed;
 
250
                        }
 
251
                        if (!NT_STATUS_IS_OK(l.out.result)) {
 
252
                                printf("LookupDomain failed - %s\n", nt_errstr(l.out.result));
 
253
                                goto failed;
 
254
                        }
 
255
                } else {
 
256
                        printf("cannot proceed without domain name\n");
 
257
                        goto failed;
 
258
                }
186
259
        }
187
260
 
188
261
        talloc_steal(join, *l.out.sid);
195
268
        o.in.sid = *l.out.sid;
196
269
        o.out.domain_handle = &domain_handle;
197
270
 
198
 
        status = dcerpc_samr_OpenDomain(join->p, join, &o);
 
271
        status = dcerpc_samr_OpenDomain_r(b, join, &o);
199
272
        if (!NT_STATUS_IS_OK(status)) {
200
273
                printf("OpenDomain failed - %s\n", nt_errstr(status));
201
274
                goto failed;
202
275
        }
 
276
        if (!NT_STATUS_IS_OK(o.out.result)) {
 
277
                printf("OpenDomain failed - %s\n", nt_errstr(o.out.result));
 
278
                goto failed;
 
279
        }
203
280
 
204
281
        printf("Creating account %s\n", username);
205
282
 
213
290
        r.out.access_granted = &access_granted;
214
291
        r.out.rid = &rid;
215
292
 
216
 
        status = dcerpc_samr_CreateUser2(join->p, join, &r);
 
293
        status = dcerpc_samr_CreateUser2_r(b, join, &r);
 
294
        if (!NT_STATUS_IS_OK(status)) {
 
295
                printf("CreateUser2 failed - %s\n", nt_errstr(status));
 
296
                goto failed;
 
297
        }
217
298
 
218
 
        if (NT_STATUS_EQUAL(status, NT_STATUS_USER_EXISTS)) {
219
 
                status = DeleteUser_byname(join->p, join, &domain_handle, name.string);
 
299
        if (NT_STATUS_EQUAL(r.out.result, NT_STATUS_USER_EXISTS)) {
 
300
                status = DeleteUser_byname(b, join, &domain_handle, name.string);
220
301
                if (NT_STATUS_IS_OK(status)) {
221
302
                        goto again;
222
303
                }
223
304
        }
224
305
 
225
 
        if (!NT_STATUS_IS_OK(status)) {
226
 
                printf("CreateUser2 failed - %s\n", nt_errstr(status));
 
306
        if (!NT_STATUS_IS_OK(r.out.result)) {
 
307
                printf("CreateUser2 failed - %s\n", nt_errstr(r.out.result));
227
308
                goto failed;
228
309
        }
229
310
 
232
313
        pwp.in.user_handle = &join->user_handle;
233
314
        pwp.out.info = &info;
234
315
 
235
 
        status = dcerpc_samr_GetUserPwInfo(join->p, join, &pwp);
236
 
        if (NT_STATUS_IS_OK(status)) {
 
316
        status = dcerpc_samr_GetUserPwInfo_r(b, join, &pwp);
 
317
        if (NT_STATUS_IS_OK(status) && NT_STATUS_IS_OK(pwp.out.result)) {
237
318
                policy_min_pw_len = pwp.out.info->min_password_length;
238
319
        }
239
320
 
240
 
        random_pw = generate_random_str(join, MAX(8, policy_min_pw_len));
 
321
        random_pw = generate_random_password(join, MAX(8, policy_min_pw_len), max_pw_len);
241
322
 
242
323
        printf("Setting account password '%s'\n", random_pw);
243
324
 
259
340
 
260
341
        arcfour_crypt_blob(u.info24.password.data, 516, &session_key);
261
342
 
262
 
        status = dcerpc_samr_SetUserInfo(join->p, join, &s);
 
343
        status = dcerpc_samr_SetUserInfo_r(b, join, &s);
263
344
        if (!NT_STATUS_IS_OK(status)) {
264
345
                printf("SetUserInfo failed - %s\n", nt_errstr(status));
265
346
                goto failed;
266
347
        }
 
348
        if (!NT_STATUS_IS_OK(s.out.result)) {
 
349
                printf("SetUserInfo failed - %s\n", nt_errstr(s.out.result));
 
350
                goto failed;
 
351
        }
267
352
 
268
353
        ZERO_STRUCT(u);
269
354
        s.in.user_handle = &join->user_handle;
283
368
        
284
369
        u.info21.description.string = talloc_asprintf(join, 
285
370
                                         "Samba4 torture account created by host %s: %s", 
286
 
                                         lp_netbios_name(torture->lp_ctx), 
 
371
                                         lpcfg_netbios_name(torture->lp_ctx),
287
372
                                         timestring(join, time(NULL)));
288
373
 
289
374
        printf("Resetting ACB flags, force pw change time\n");
290
375
 
291
 
        status = dcerpc_samr_SetUserInfo(join->p, join, &s);
 
376
        status = dcerpc_samr_SetUserInfo_r(b, join, &s);
292
377
        if (!NT_STATUS_IS_OK(status)) {
293
378
                printf("SetUserInfo failed - %s\n", nt_errstr(status));
294
379
                goto failed;
295
380
        }
 
381
        if (!NT_STATUS_IS_OK(s.out.result)) {
 
382
                printf("SetUserInfo failed - %s\n", nt_errstr(s.out.result));
 
383
                goto failed;
 
384
        }
296
385
 
297
386
        if (random_password) {
298
387
                *random_password = random_pw;
306
395
}
307
396
 
308
397
 
 
398
struct test_join *torture_create_testuser(struct torture_context *torture,
 
399
                                          const char *username,
 
400
                                          const char *domain,
 
401
                                          uint16_t acct_type,
 
402
                                          const char **random_password)
 
403
{
 
404
        return torture_create_testuser_max_pwlen(torture, username, domain, acct_type, random_password, 255);
 
405
}
 
406
 
309
407
_PUBLIC_ struct test_join *torture_join_domain(struct torture_context *tctx,
310
408
                                               const char *machine_name, 
311
409
                                      uint32_t acct_flags,
327
425
                return NULL;
328
426
        }
329
427
        
330
 
        libnet_ctx = libnet_context_init(tctx->ev, tctx->lp_ctx);       
 
428
        libnet_ctx = libnet_context_init(tctx->ev, tctx->lp_ctx);
331
429
        if (!libnet_ctx) {
332
430
                talloc_free(tj);
333
431
                return NULL;
391
489
        
392
490
        u.info21.description.string = talloc_asprintf(tj, 
393
491
                                                      "Samba4 torture account created by host %s: %s", 
394
 
                                                      lp_netbios_name(tctx->lp_ctx), timestring(tj, time(NULL)));
 
492
                                                      lpcfg_netbios_name(tctx->lp_ctx), timestring(tj, time(NULL)));
395
493
 
396
 
        status = dcerpc_samr_SetUserInfo(tj->p, tj, &s);
 
494
        status = dcerpc_samr_SetUserInfo_r(tj->p->binding_handle, tj, &s);
397
495
        if (!NT_STATUS_IS_OK(status)) {
398
496
                printf("SetUserInfo (non-critical) failed - %s\n", nt_errstr(status));
399
497
        }
 
498
        if (!NT_STATUS_IS_OK(s.out.result)) {
 
499
                printf("SetUserInfo (non-critical) failed - %s\n", nt_errstr(s.out.result));
 
500
        }
400
501
 
401
502
        *machine_credentials = cli_credentials_init(tj);
402
503
        cli_credentials_set_conf(*machine_credentials, tctx->lp_ctx);
517
618
        d.out.user_handle = &join->user_handle;
518
619
 
519
620
        /* Delete machine account */
520
 
        status = dcerpc_samr_DeleteUser(join->p, join, &d);
 
621
        status = dcerpc_samr_DeleteUser_r(join->p->binding_handle, join, &d);
521
622
        if (!NT_STATUS_IS_OK(status)) {
 
623
                printf("DeleteUser failed\n");
 
624
        }
 
625
        if (!NT_STATUS_IS_OK(d.out.result)) {
522
626
                printf("Delete of machine account %s failed\n",
523
627
                       join->netbios_name);
524
628
        } else {