9a2f518535b96e87515384399a68f7655b75ac35
[gd/samba-autobuild/.git] / source4 / torture / rpc / wkssvc.c
1 /*
2    Unix SMB/CIFS implementation.
3    test suite for wkssvc rpc operations
4
5    Copyright (C) Andrew Tridgell 2003
6    Copyright (C) G√ľnther Deschner 2007
7
8    This program is free software; you can redistribute it and/or modify
9    it under the terms of the GNU General Public License as published by
10    the Free Software Foundation; either version 3 of the License, or
11    (at your option) any later version.
12
13    This program is distributed in the hope that it will be useful,
14    but WITHOUT ANY WARRANTY; without even the implied warranty of
15    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16    GNU General Public License for more details.
17
18    You should have received a copy of the GNU General Public License
19    along with this program.  If not, see <http://www.gnu.org/licenses/>.
20 */
21
22 #include "includes.h"
23 #include "torture/torture.h"
24 #include "librpc/gen_ndr/ndr_wkssvc_c.h"
25 #include "torture/rpc/rpc.h"
26 #include "lib/cmdline/popt_common.h"
27 #include "param/param.h"
28 #include "lib/crypto/crypto.h"
29 #include "libcli/auth/libcli_auth.h"
30
31 #define SMBTORTURE_MACHINE_NAME "smbtrt_name"
32 #define SMBTORTURE_ALTERNATE_NAME "smbtrt_altname"
33 #define SMBTORTURE_TRANSPORT_NAME "\\Device\\smbtrt_transport_name"
34 #define SMBTORTURE_USE_NAME "S:"
35 #define SMBTORTURE_MESSAGE "You are currently tortured by Samba"
36
37 static bool test_NetWkstaGetInfo(struct torture_context *tctx,
38                                  struct dcerpc_pipe *p)
39 {
40         NTSTATUS status;
41         struct wkssvc_NetWkstaGetInfo r;
42         union wkssvc_NetWkstaInfo info;
43         uint16_t levels[] = {100, 101, 102, 502};
44         int i;
45
46         r.in.server_name = dcerpc_server_name(p);
47         r.out.info = &info;
48
49         for (i=0;i<ARRAY_SIZE(levels);i++) {
50                 r.in.level = levels[i];
51                 torture_comment(tctx, "testing NetWkstaGetInfo level %u\n",
52                                 r.in.level);
53                 status = dcerpc_wkssvc_NetWkstaGetInfo(p, tctx, &r);
54                 torture_assert_ntstatus_ok(tctx, status,
55                         talloc_asprintf(tctx, "NetWkstaGetInfo level %u failed",
56                                         r.in.level));
57                 torture_assert_werr_ok(tctx, r.out.result,
58                         talloc_asprintf(tctx, "NetWkstaGetInfo level %u failed",
59                                         r.in.level));
60         }
61
62         return true;
63 }
64
65 static bool test_NetWkstaTransportEnum(struct torture_context *tctx,
66                                        struct dcerpc_pipe *p)
67 {
68         NTSTATUS status;
69         struct wkssvc_NetWkstaTransportEnum r;
70         uint32_t resume_handle = 0;
71         struct wkssvc_NetWkstaTransportInfo info;
72         union wkssvc_NetWkstaTransportCtr ctr;
73         struct wkssvc_NetWkstaTransportCtr0 ctr0;
74         uint32_t total_entries = 0;
75
76         ZERO_STRUCT(ctr0);
77         ctr.ctr0 = &ctr0;
78
79         info.level = 0;
80         info.ctr = ctr;
81
82         r.in.server_name = dcerpc_server_name(p);
83         r.in.info = &info;
84         r.in.max_buffer = (uint32_t)-1;
85         r.in.resume_handle = &resume_handle;
86         r.out.total_entries = &total_entries;
87         r.out.info = &info;
88         r.out.resume_handle = &resume_handle;
89
90         torture_comment(tctx, "testing NetWkstaTransportEnum level 0\n");
91
92         status = dcerpc_wkssvc_NetWkstaTransportEnum(p, tctx, &r);
93         torture_assert_ntstatus_ok(tctx, status,
94                                    "NetWkstaTransportEnum failed");
95         torture_assert_werr_ok(tctx, r.out.result, talloc_asprintf(tctx,
96                                "NetWkstaTransportEnum level %u failed",
97                                info.level));
98
99         return true;
100 }
101
102 static bool test_NetrWkstaTransportAdd(struct torture_context *tctx,
103                                        struct dcerpc_pipe *p)
104 {
105         NTSTATUS status;
106         struct wkssvc_NetrWkstaTransportAdd r;
107         struct wkssvc_NetWkstaTransportInfo0 info0;
108         uint32_t parm_err = 0;
109
110         ZERO_STRUCT(info0);
111
112         info0.quality_of_service = 0xffff;
113         info0.vc_count = 0;
114         info0.name = SMBTORTURE_TRANSPORT_NAME;
115         info0.address = "000000000000";
116         info0.wan_link = 0x400;
117
118         r.in.server_name = dcerpc_server_name(p);
119         r.in.level = 0;
120         r.in.info0 = &info0;
121         r.in.parm_err = r.out.parm_err = &parm_err;
122
123         torture_comment(tctx, "testing NetrWkstaTransportAdd level 0\n");
124
125         status = dcerpc_wkssvc_NetrWkstaTransportAdd(p, tctx, &r);
126         torture_assert_ntstatus_ok(tctx, status,
127                                    "NetrWkstaTransportAdd failed");
128         torture_assert_werr_equal(tctx, r.out.result,
129                                   WERR_INVALID_PARAM,
130                                   "NetrWkstaTransportAdd level 0 failed");
131
132         return true;
133 }
134
135 static bool test_NetrWkstaTransportDel(struct torture_context *tctx,
136                                        struct dcerpc_pipe *p)
137 {
138         NTSTATUS status;
139         struct wkssvc_NetrWkstaTransportDel r;
140
141         r.in.server_name = dcerpc_server_name(p);
142         r.in.transport_name = SMBTORTURE_TRANSPORT_NAME;
143         r.in.unknown3 = 0;
144
145         torture_comment(tctx, "testing NetrWkstaTransportDel\n");
146
147         status = dcerpc_wkssvc_NetrWkstaTransportDel(p, tctx, &r);
148         torture_assert_ntstatus_ok(tctx, status,
149                                    "NetrWkstaTransportDel failed");
150         torture_assert_werr_ok(tctx, r.out.result,
151                                "NetrWkstaTransportDel");
152
153         return true;
154 }
155
156 static bool test_NetWkstaEnumUsers(struct torture_context *tctx,
157                                    struct dcerpc_pipe *p)
158 {
159         NTSTATUS status;
160         struct wkssvc_NetWkstaEnumUsers r;
161         uint32_t handle = 0;
162         uint32_t entries_read = 0;
163         struct wkssvc_NetWkstaEnumUsersInfo info;
164         struct wkssvc_NetWkstaEnumUsersCtr0 *user0;
165         struct wkssvc_NetWkstaEnumUsersCtr1 *user1;
166         uint32_t levels[] = { 0, 1 };
167         int i;
168
169         for (i=0; i<ARRAY_SIZE(levels); i++) {
170
171                 ZERO_STRUCT(info);
172
173                 info.level = levels[i];
174                 switch (info.level) {
175                 case 0:
176                         user0 = talloc_zero(tctx,
177                                             struct wkssvc_NetWkstaEnumUsersCtr0);
178                         info.ctr.user0 = user0;
179                         break;
180                 case 1:
181                         user1 = talloc_zero(tctx,
182                                             struct wkssvc_NetWkstaEnumUsersCtr1);
183                         info.ctr.user1 = user1;
184                         break;
185                 default:
186                         break;
187                 }
188
189                 r.in.server_name = dcerpc_server_name(p);
190                 r.in.prefmaxlen = (uint32_t)-1;
191                 r.in.info = r.out.info = &info;
192                 r.in.resume_handle = r.out.resume_handle = &handle;
193
194                 r.out.entries_read = &entries_read;
195
196                 torture_comment(tctx, "testing NetWkstaEnumUsers level %u\n",
197                                 levels[i]);
198
199                 status = dcerpc_wkssvc_NetWkstaEnumUsers(p, tctx, &r);
200                 torture_assert_ntstatus_ok(tctx, status,
201                                            "NetWkstaEnumUsers failed");
202                 torture_assert_werr_ok(tctx, r.out.result,
203                                        "NetWkstaEnumUsers failed");
204         }
205
206         return true;
207 }
208
209 static bool test_NetrWkstaUserGetInfo(struct torture_context *tctx,
210                                       struct dcerpc_pipe *p)
211 {
212         NTSTATUS status;
213         struct wkssvc_NetrWkstaUserGetInfo r;
214         union wkssvc_NetrWkstaUserInfo info;
215         const char *dom = lp_workgroup(global_loadparm);
216         struct cli_credentials *creds = cmdline_credentials;
217         const char *user = cli_credentials_get_username(creds);
218         int i;
219
220         const struct {
221                 const char *unknown;
222                 uint32_t level;
223                 WERROR result;
224         } tests[] = {
225                 { NULL, 0, WERR_NO_SUCH_LOGON_SESSION },
226                 { NULL, 1, WERR_NO_SUCH_LOGON_SESSION },
227                 { NULL, 1101, WERR_OK },
228                 { dom, 0, WERR_INVALID_PARAM },
229                 { dom, 1, WERR_INVALID_PARAM },
230                 { dom, 1101, WERR_INVALID_PARAM },
231                 { user, 0, WERR_INVALID_PARAM },
232                 { user, 1, WERR_INVALID_PARAM },
233                 { user, 1101, WERR_INVALID_PARAM },
234         };
235
236         for (i=0; i<ARRAY_SIZE(tests); i++) {
237                 r.in.unknown = tests[i].unknown;
238                 r.in.level = tests[i].level;
239                 r.out.info = &info;
240
241                 torture_comment(tctx, "testing NetrWkstaUserGetInfo level %u\n",
242                                 r.in.level);
243
244                 status = dcerpc_wkssvc_NetrWkstaUserGetInfo(p, tctx, &r);
245                 torture_assert_ntstatus_ok(tctx, status,
246                                            "NetrWkstaUserGetInfo failed");
247                 torture_assert_werr_equal(tctx, r.out.result,
248                                           tests[i].result,
249                                           "NetrWkstaUserGetInfo failed");
250         }
251
252         return true;
253 }
254
255 static bool test_NetrUseEnum(struct torture_context *tctx,
256                              struct dcerpc_pipe *p)
257 {
258         NTSTATUS status;
259         struct wkssvc_NetrUseEnum r;
260         uint32_t handle = 0;
261         uint32_t entries_read = 0;
262         struct wkssvc_NetrUseEnumInfo info;
263         struct wkssvc_NetrUseEnumCtr0 *use0;
264         struct wkssvc_NetrUseEnumCtr1 *use1;
265         struct wkssvc_NetrUseEnumCtr2 *use2;
266         uint32_t levels[] = { 0, 1, 2 };
267         int i;
268
269         for (i=0; i<ARRAY_SIZE(levels); i++) {
270
271                 ZERO_STRUCT(info);
272
273                 info.level = levels[i];
274                 switch (info.level) {
275                 case 0:
276                         use0 = talloc_zero(tctx, struct wkssvc_NetrUseEnumCtr0);
277                         info.ctr.ctr0 = use0;
278                         break;
279                 case 1:
280                         use1 = talloc_zero(tctx, struct wkssvc_NetrUseEnumCtr1);
281                         info.ctr.ctr1 = use1;
282                         break;
283                 case 2:
284                         use2 = talloc_zero(tctx, struct wkssvc_NetrUseEnumCtr2);
285                         info.ctr.ctr2 = use2;
286                         break;
287                 default:
288                         break;
289                 }
290
291                 r.in.server_name = talloc_asprintf(tctx, "\\\\%s", dcerpc_server_name(p));
292                 r.in.prefmaxlen = (uint32_t)-1;
293                 r.in.info = r.out.info = &info;
294                 r.in.resume_handle = r.out.resume_handle = &handle;
295
296                 r.out.entries_read = &entries_read;
297
298                 torture_comment(tctx, "testing NetrUseEnum level %u\n",
299                                 levels[i]);
300
301                 status = dcerpc_wkssvc_NetrUseEnum(p, tctx, &r);
302                 torture_assert_ntstatus_ok(tctx, status,
303                                            "NetrUseEnum failed");
304                 torture_assert_werr_ok(tctx, r.out.result,
305                                        "NetrUseEnum failed");
306         }
307
308         return true;
309 }
310
311 static bool test_NetrUseAdd(struct torture_context *tctx,
312                             struct dcerpc_pipe *p)
313 {
314         NTSTATUS status;
315         struct wkssvc_NetrUseAdd r;
316         struct wkssvc_NetrUseInfo0 info0;
317         struct wkssvc_NetrUseInfo1 info1;
318         union wkssvc_NetrUseGetInfoCtr *ctr;
319         uint32_t parm_err = 0;
320
321         ctr = talloc(tctx, union wkssvc_NetrUseGetInfoCtr);
322
323         ZERO_STRUCT(info0);
324
325         info0.local = SMBTORTURE_USE_NAME;
326         info0.remote = "\\\\localhost\\c$";
327
328         ctr->info0 = &info0;
329
330         r.in.server_name = talloc_asprintf(tctx, "\\\\%s", dcerpc_server_name(p));
331         r.in.level = 0;
332         r.in.ctr = ctr;
333         r.in.parm_err = r.out.parm_err = &parm_err;
334
335         torture_comment(tctx, "testing NetrUseAdd level %u\n",
336                         r.in.level);
337
338         status = dcerpc_wkssvc_NetrUseAdd(p, tctx, &r);
339         torture_assert_ntstatus_ok(tctx, status,
340                                    "NetrUseAdd failed");
341         torture_assert_werr_equal(tctx, r.out.result, WERR_UNKNOWN_LEVEL,
342                                "NetrUseAdd failed");
343
344         ZERO_STRUCT(r);
345         ZERO_STRUCT(info1);
346
347         info1.local = SMBTORTURE_USE_NAME;
348         info1.remote = "\\\\localhost\\sysvol";
349         info1.password = NULL;
350
351         ctr->info1 = &info1;
352
353         r.in.server_name = talloc_asprintf(tctx, "\\\\%s", dcerpc_server_name(p));
354         r.in.level = 1;
355         r.in.ctr = ctr;
356         r.in.parm_err = r.out.parm_err = &parm_err;
357
358         torture_comment(tctx, "testing NetrUseAdd level %u\n",
359                         r.in.level);
360
361         status = dcerpc_wkssvc_NetrUseAdd(p, tctx, &r);
362         torture_assert_ntstatus_ok(tctx, status,
363                                    "NetrUseAdd failed");
364         torture_assert_werr_ok(tctx, r.out.result,
365                                "NetrUseAdd failed");
366
367         return true;
368 }
369
370 static bool test_NetrUseDel(struct torture_context *tctx,
371                             struct dcerpc_pipe *p)
372 {
373         NTSTATUS status;
374         struct wkssvc_NetrUseDel r;
375
376         r.in.server_name = talloc_asprintf(tctx, "\\\\%s", dcerpc_server_name(p));
377         r.in.use_name = SMBTORTURE_USE_NAME;
378         r.in.force_cond = 0;
379
380         torture_comment(tctx, "testing NetrUseDel\n");
381
382         status = dcerpc_wkssvc_NetrUseDel(p, tctx, &r);
383         torture_assert_ntstatus_ok(tctx, status,
384                                    "NetrUseDel failed");
385         torture_assert_werr_ok(tctx, r.out.result,
386                                "NetrUseDel failed");
387         return true;
388 }
389
390 static bool test_NetrUseGetInfo_level(struct torture_context *tctx,
391                                       struct dcerpc_pipe *p,
392                                       const char *use_name,
393                                       uint32_t level,
394                                       WERROR werr)
395 {
396         NTSTATUS status;
397         struct wkssvc_NetrUseGetInfo r;
398         union wkssvc_NetrUseGetInfoCtr ctr;
399
400         ZERO_STRUCT(ctr);
401
402         r.in.server_name = talloc_asprintf(tctx, "\\\\%s", dcerpc_server_name(p));
403         r.in.use_name = use_name;
404         r.in.level = level;
405         r.out.ctr = &ctr;
406         status = dcerpc_wkssvc_NetrUseGetInfo(p, tctx, &r);
407
408         torture_assert_ntstatus_ok(tctx, status,
409                                    "NetrUseGetInfo failed");
410         torture_assert_werr_equal(tctx, r.out.result, werr,
411                                   "NetrUseGetInfo failed");
412         return true;
413 }
414
415 static bool test_NetrUseGetInfo(struct torture_context *tctx,
416                                 struct dcerpc_pipe *p)
417 {
418         NTSTATUS status;
419         struct wkssvc_NetrUseEnum r;
420         uint32_t handle = 0;
421         uint32_t entries_read = 0;
422         struct wkssvc_NetrUseEnumInfo info;
423         struct wkssvc_NetrUseEnumCtr0 *use0;
424         uint32_t levels[] = { 0, 1, 2 };
425         const char *use_name = NULL;
426         int i, k;
427
428         ZERO_STRUCT(info);
429
430         info.level = 0;
431         use0 = talloc_zero(tctx, struct wkssvc_NetrUseEnumCtr0);
432         info.ctr.ctr0 = use0;
433
434         r.in.server_name = talloc_asprintf(tctx, "\\\\%s", dcerpc_server_name(p));
435         r.in.prefmaxlen = (uint32_t)-1;
436         r.in.info = r.out.info = &info;
437         r.in.resume_handle = r.out.resume_handle = &handle;
438         r.out.entries_read = &entries_read;
439
440         status = dcerpc_wkssvc_NetrUseEnum(p, tctx, &r);
441         torture_assert_ntstatus_ok(tctx, status,
442                                    "NetrUseEnum failed");
443         torture_assert_werr_ok(tctx, r.out.result,
444                                "NetrUseEnum failed");
445
446         for (k=0; k < r.out.info->ctr.ctr0->count; k++) {
447
448                 use_name = r.out.info->ctr.ctr0->array[k].local;
449
450                 for (i=0; i<ARRAY_SIZE(levels); i++) {
451
452                         if (!test_NetrUseGetInfo_level(tctx, p, use_name,
453                                                        levels[i],
454                                                        WERR_OK))
455                         {
456                                 if (levels[i] != 0) {
457                                         return false;
458                                 }
459                         }
460                 }
461
462                 use_name = r.out.info->ctr.ctr0->array[k].remote;
463
464                 for (i=0; i<ARRAY_SIZE(levels); i++) {
465
466                         if (!test_NetrUseGetInfo_level(tctx, p, use_name,
467                                                        levels[i],
468                                                        WERR_NOT_CONNECTED))
469                         {
470                                 if (levels[i] != 0) {
471                                         return false;
472                                 }
473                         }
474                 }
475         }
476
477         return true;
478 }
479
480 static bool test_NetrLogonDomainNameAdd(struct torture_context *tctx,
481                                         struct dcerpc_pipe *p)
482 {
483         NTSTATUS status;
484         struct wkssvc_NetrLogonDomainNameAdd r;
485
486         r.in.domain_name = lp_workgroup(global_loadparm);
487
488         torture_comment(tctx, "testing NetrLogonDomainNameAdd\n");
489
490         status = dcerpc_wkssvc_NetrLogonDomainNameAdd(p, tctx, &r);
491         torture_assert_ntstatus_ok(tctx, status,
492                                    "NetrLogonDomainNameAdd failed");
493         torture_assert_werr_equal(tctx, r.out.result, WERR_NOT_SUPPORTED,
494                                   "NetrLogonDomainNameAdd failed");
495         return true;
496 }
497
498 static bool test_NetrLogonDomainNameDel(struct torture_context *tctx,
499                                         struct dcerpc_pipe *p)
500 {
501         NTSTATUS status;
502         struct wkssvc_NetrLogonDomainNameDel r;
503
504         r.in.domain_name = lp_workgroup(global_loadparm);
505
506         torture_comment(tctx, "testing NetrLogonDomainNameDel\n");
507
508         status = dcerpc_wkssvc_NetrLogonDomainNameDel(p, tctx, &r);
509         torture_assert_ntstatus_ok(tctx, status,
510                                    "NetrLogonDomainNameDel failed");
511         torture_assert_werr_equal(tctx, r.out.result, WERR_NOT_SUPPORTED,
512                                   "NetrLogonDomainNameDel failed");
513         return true;
514 }
515
516 static bool test_NetrEnumerateComputerNames_level(struct torture_context *tctx,
517                                                   struct dcerpc_pipe *p,
518                                                   uint16_t level,
519                                                   const char ***names,
520                                                   int *num_names)
521 {
522         NTSTATUS status;
523         struct wkssvc_NetrEnumerateComputerNames r;
524         struct wkssvc_ComputerNamesCtr *ctr;
525         int i;
526
527         ctr = talloc_zero(tctx, struct wkssvc_ComputerNamesCtr);
528
529         r.in.server_name = dcerpc_server_name(p);
530         r.in.name_type = level;
531         r.in.Reserved = 0;
532         r.out.ctr = &ctr;
533
534         torture_comment(tctx, "testing NetrEnumerateComputerNames level %u\n",
535                         r.in.name_type);
536
537         status = dcerpc_wkssvc_NetrEnumerateComputerNames(p, tctx, &r);
538         torture_assert_ntstatus_ok(tctx, status,
539                                    "NetrEnumerateComputerNames failed");
540         torture_assert_werr_ok(tctx, r.out.result,
541                                "NetrEnumerateComputerNames failed");
542
543         if ((level == NetPrimaryComputerName) && ctr->count != 1) {
544                 torture_comment(tctx,
545                                 "NetrEnumerateComputerNames did not return one "
546                                 "name but %u\n", ctr->count);
547                 return false;
548         }
549
550         if (names && num_names) {
551                 *num_names = 0;
552                 *names = NULL;
553                 for (i=0; i<ctr->count; i++) {
554                         if (!add_string_to_array(tctx,
555                                                  ctr->computer_name[i].string,
556                                                  names,
557                                                  num_names))
558                         {
559                                 return false;
560                         }
561                 }
562         }
563
564         return true;
565 }
566
567 static bool test_NetrEnumerateComputerNames(struct torture_context *tctx,
568                                             struct dcerpc_pipe *p)
569 {
570         uint16_t levels[] = {0,1,2};
571         int i;
572
573         for (i=0; i<ARRAY_SIZE(levels); i++) {
574
575                 if (!test_NetrEnumerateComputerNames_level(tctx,
576                                                            p,
577                                                            levels[i],
578                                                            NULL, NULL))
579                 {
580                         return false;
581                 }
582         }
583
584         return true;
585 }
586
587 static bool test_NetrValidateName(struct torture_context *tctx,
588                                   struct dcerpc_pipe *p)
589 {
590         NTSTATUS status;
591         struct wkssvc_NetrValidateName r;
592         uint16_t levels[] = {0,1,2,3,4,5};
593         int i;
594
595         for (i=0; i<ARRAY_SIZE(levels); i++) {
596
597                 r.in.server_name = talloc_asprintf(tctx, "\\\\%s", dcerpc_server_name(p));
598                 r.in.name = lp_workgroup(global_loadparm);
599                 r.in.Account = NULL;
600                 r.in.Password = NULL;
601                 r.in.name_type = levels[i];
602
603                 torture_comment(tctx, "testing NetrValidateName level %u\n",
604                                 r.in.name_type);
605
606                 status = dcerpc_wkssvc_NetrValidateName(p, tctx, &r);
607                 torture_assert_ntstatus_ok(tctx, status,
608                                            "NetrValidateName failed");
609                 torture_assert_werr_equal(tctx, r.out.result,
610                                           WERR_NOT_SUPPORTED,
611                                           "NetrValidateName failed");
612         }
613
614         return true;
615 }
616
617 static bool test_NetrValidateName2(struct torture_context *tctx,
618                                    struct dcerpc_pipe *p)
619 {
620         NTSTATUS status;
621         struct wkssvc_NetrValidateName2 r;
622         uint16_t levels[] = {0,1,2,3,4,5};
623         int i;
624
625         for (i=0; i<ARRAY_SIZE(levels); i++) {
626
627                 r.in.server_name = talloc_asprintf(tctx, "\\\\%s", dcerpc_server_name(p));
628                 r.in.name = lp_workgroup(global_loadparm);
629                 r.in.Account = NULL;
630                 r.in.EncryptedPassword = NULL;
631                 r.in.name_type = levels[i];
632
633                 torture_comment(tctx, "testing NetrValidateName2 level %u\n",
634                                 r.in.name_type);
635
636                 status = dcerpc_wkssvc_NetrValidateName2(p, tctx, &r);
637                 torture_assert_ntstatus_ok(tctx, status,
638                                            "NetrValidateName2 failed");
639                 torture_assert_werr_equal(tctx, r.out.result,
640                                           WERR_RPC_E_REMOTE_DISABLED,
641                                           "NetrValidateName2 failed");
642         }
643
644         return true;
645 }
646
647 static bool test_NetrAddAlternateComputerName(struct torture_context *tctx,
648                                               struct dcerpc_pipe *p)
649 {
650         NTSTATUS status;
651         struct wkssvc_NetrAddAlternateComputerName r;
652         const char **names = NULL;
653         int num_names = 0;
654         int i;
655
656         r.in.server_name = dcerpc_server_name(p);
657         r.in.NewAlternateMachineName = SMBTORTURE_ALTERNATE_NAME;
658         r.in.Account = NULL;
659         r.in.EncryptedPassword = NULL;
660         r.in.Reserved = 0;
661
662         torture_comment(tctx, "testing NetrAddAlternateComputerName\n");
663
664         status = dcerpc_wkssvc_NetrAddAlternateComputerName(p, tctx, &r);
665         torture_assert_ntstatus_ok(tctx, status,
666                                    "NetrAddAlternateComputerName failed");
667         torture_assert_werr_ok(tctx, r.out.result,
668                                "NetrAddAlternateComputerName failed");
669
670         if (!test_NetrEnumerateComputerNames_level(tctx, p,
671                                                    NetAlternateComputerNames,
672                                                    &names, &num_names))
673         {
674                 return false;
675         }
676
677         for (i=0; i<num_names; i++) {
678                 if (strequal(names[i], SMBTORTURE_ALTERNATE_NAME)) {
679                         return true;
680                 }
681         }
682
683         torture_comment(tctx, "new alternate name not set\n");
684
685         return false;
686 }
687
688 static bool test_NetrRemoveAlternateComputerName(struct torture_context *tctx,
689                                                  struct dcerpc_pipe *p)
690 {
691         NTSTATUS status;
692         struct wkssvc_NetrRemoveAlternateComputerName r;
693         const char **names = NULL;
694         int num_names = 0;
695         int i;
696
697         r.in.server_name = dcerpc_server_name(p);
698         r.in.AlternateMachineNameToRemove = SMBTORTURE_ALTERNATE_NAME;
699         r.in.Account = NULL;
700         r.in.EncryptedPassword = NULL;
701         r.in.Reserved = 0;
702
703         torture_comment(tctx, "testing NetrRemoveAlternateComputerName\n");
704
705         status = dcerpc_wkssvc_NetrRemoveAlternateComputerName(p, tctx, &r);
706         torture_assert_ntstatus_ok(tctx, status,
707                                    "NetrRemoveAlternateComputerName failed");
708         torture_assert_werr_ok(tctx, r.out.result,
709                                "NetrRemoveAlternateComputerName failed");
710
711         if (!test_NetrEnumerateComputerNames_level(tctx, p,
712                                                    NetAlternateComputerNames,
713                                                    &names, &num_names))
714         {
715                 return false;
716         }
717
718         for (i=0; i<num_names; i++) {
719                 if (strequal(names[i], SMBTORTURE_ALTERNATE_NAME)) {
720                         return false;
721                 }
722         }
723
724         return true;
725 }
726
727 static bool test_NetrSetPrimaryComputername_name(struct torture_context *tctx,
728                                                  struct dcerpc_pipe *p,
729                                                  const char *name)
730 {
731         NTSTATUS status;
732         struct wkssvc_NetrSetPrimaryComputername r;
733
734         r.in.server_name = dcerpc_server_name(p);
735         r.in.primary_name = name;
736         r.in.Account = NULL;
737         r.in.EncryptedPassword = NULL;
738         r.in.Reserved = 0;
739
740         status = dcerpc_wkssvc_NetrSetPrimaryComputername(p, tctx, &r);
741         torture_assert_ntstatus_ok(tctx, status,
742                                    "NetrSetPrimaryComputername failed");
743         torture_assert_werr_ok(tctx, r.out.result,
744                                "NetrSetPrimaryComputername failed");
745         return true;
746 }
747
748
749 static bool test_NetrSetPrimaryComputername(struct torture_context *tctx,
750                                             struct dcerpc_pipe *p)
751 {
752         /*
753           add alternate,
754           check if there
755           store old primary
756           set new primary (alternate)
757           check if there
758           later: check if del is possible
759           set primary back to origin
760           check if there
761           del alternate
762         */
763
764         const char **names_o = NULL, **names = NULL;
765         int num_names_o = 0, num_names = 0;
766
767         torture_comment(tctx, "testing NetrSetPrimaryComputername\n");
768
769         if (!test_NetrAddAlternateComputerName(tctx, p)) {
770                 return false;
771         }
772
773         if (!test_NetrEnumerateComputerNames_level(tctx, p,
774                                                    NetPrimaryComputerName,
775                                                    &names_o, &num_names_o))
776         {
777                 return false;
778         }
779
780         if (num_names_o != 1) {
781                 return false;
782         }
783
784         if (!test_NetrSetPrimaryComputername_name(tctx, p,
785                                                   SMBTORTURE_ALTERNATE_NAME))
786         {
787                 return false;
788         }
789
790         if (!test_NetrEnumerateComputerNames_level(tctx, p,
791                                                    NetPrimaryComputerName,
792                                                    &names, &num_names))
793         {
794                 return false;
795         }
796
797         if (num_names != 1) {
798                 return false;
799         }
800
801         if (!strequal(names[0], SMBTORTURE_ALTERNATE_NAME)) {
802                 torture_comment(tctx,
803                                 "name mismatch (%s != %s) after NetrSetPrimaryComputername!\n",
804                                 names[0], SMBTORTURE_ALTERNATE_NAME);
805                 /*return false */;
806         }
807
808         if (!test_NetrSetPrimaryComputername_name(tctx, p,
809                                                   names_o[0]))
810         {
811                 return false;
812         }
813
814         if (!test_NetrRemoveAlternateComputerName(tctx, p)) {
815                 return false;
816         }
817
818
819         return true;
820 }
821
822 static bool test_NetrRenameMachineInDomain(struct torture_context *tctx,
823                                            struct dcerpc_pipe *p)
824 {
825         NTSTATUS status;
826         struct wkssvc_NetrRenameMachineInDomain r;
827
828         r.in.server_name = dcerpc_server_name(p);
829         r.in.NewMachineName = SMBTORTURE_MACHINE_NAME;
830         r.in.Account = NULL;
831         r.in.password = NULL;
832         r.in.RenameOptions = 0;
833
834         torture_comment(tctx, "testing NetrRenameMachineInDomain\n");
835
836         status = dcerpc_wkssvc_NetrRenameMachineInDomain(p, tctx, &r);
837         torture_assert_ntstatus_ok(tctx, status,
838                                    "NetrRenameMachineInDomain failed");
839         torture_assert_werr_equal(tctx, r.out.result, WERR_NOT_SUPPORTED,
840                                   "NetrRenameMachineInDomain failed");
841         return true;
842 }
843
844 static bool test_NetrRenameMachineInDomain2_name(struct torture_context *tctx,
845                                                  struct dcerpc_pipe *p,
846                                                  const char *new_name)
847 {
848         NTSTATUS status;
849         struct wkssvc_NetrRenameMachineInDomain2 r;
850
851         r.in.server_name = dcerpc_server_name(p);
852         r.in.NewMachineName = new_name;
853         r.in.Account = NULL;
854         r.in.EncryptedPassword = NULL;
855         r.in.RenameOptions = 0;
856
857         status = dcerpc_wkssvc_NetrRenameMachineInDomain2(p, tctx, &r);
858         torture_assert_ntstatus_ok(tctx, status,
859                                    "NetrRenameMachineInDomain2 failed");
860         torture_assert_werr_ok(tctx, r.out.result,
861                                "NetrRenameMachineInDomain2 failed");
862         return true;
863 }
864
865 static bool test_NetrRenameMachineInDomain2(struct torture_context *tctx,
866                                             struct dcerpc_pipe *p)
867 {
868         const char **names_o = NULL, **names = NULL;
869         int num_names_o = 0, num_names = 0;
870
871         torture_comment(tctx, "testing NetrRenameMachineInDomain2\n");
872
873         if (!test_NetrEnumerateComputerNames_level(tctx, p,
874                                                    NetPrimaryComputerName,
875                                                    &names_o, &num_names_o))
876         {
877                 return false;
878         }
879
880         if (num_names_o != 1) {
881                 return false;
882         }
883
884         if (!test_NetrRenameMachineInDomain2_name(tctx, p,
885                                                   SMBTORTURE_MACHINE_NAME))
886         {
887                 return false;
888         }
889
890         if (!test_NetrEnumerateComputerNames_level(tctx, p,
891                                                    NetPrimaryComputerName,
892                                                    &names, &num_names))
893         {
894                 return false;
895         }
896
897         if (num_names != 1) {
898                 return false;
899         }
900
901         if (strequal(names[0], names_o[0])) {
902                 test_NetrRenameMachineInDomain2_name(tctx, p, names_o[0]);
903                 return false;
904         }
905
906         if (!strequal(names[0], SMBTORTURE_MACHINE_NAME)) {
907                 test_NetrRenameMachineInDomain2_name(tctx, p, names_o[0]);
908                 return false;
909         }
910
911         if (!test_NetrRenameMachineInDomain2_name(tctx, p, names_o[0]))
912         {
913                 return false;
914         }
915
916         if (!test_NetrEnumerateComputerNames_level(tctx, p,
917                                                    NetPrimaryComputerName,
918                                                    &names, &num_names))
919         {
920                 return false;
921         }
922
923         if (num_names != 1) {
924                 return false;
925         }
926
927         if (!strequal(names[0], names_o[0])) {
928                 return false;
929         }
930
931         return true;
932 }
933
934 static bool test_NetrWorkstationStatisticsGet(struct torture_context *tctx,
935                                               struct dcerpc_pipe *p)
936 {
937         NTSTATUS status;
938         struct wkssvc_NetrWorkstationStatisticsGet r;
939         struct wkssvc_NetrWorkstationStatistics *info;
940
941         ZERO_STRUCT(r);
942
943         info = talloc_zero(tctx, struct wkssvc_NetrWorkstationStatistics);
944
945         r.in.server_name = dcerpc_server_name(p);
946         r.out.info = &info;
947
948         torture_comment(tctx, "testing NetrWorkstationStatisticsGet\n");
949
950         status = dcerpc_wkssvc_NetrWorkstationStatisticsGet(p, tctx, &r);
951         torture_assert_ntstatus_ok(tctx, status,
952                                    "NetrWorkstationStatisticsGet failed");
953         torture_assert_werr_ok(tctx, r.out.result,
954                                "NetrWorkstationStatisticsGet failed");
955         return true;
956 }
957
958 /* only succeeds as long as the local messenger service is running - Guenther */
959
960 static bool test_NetrMessageBufferSend(struct torture_context *tctx,
961                                        struct dcerpc_pipe *p)
962 {
963         NTSTATUS status;
964         struct wkssvc_NetrMessageBufferSend r;
965         const char *message = SMBTORTURE_MESSAGE;
966         size_t size;
967         uint8_t *msg;
968
969         size = push_ucs2_talloc(tctx, (void **)&msg, message);
970
971         r.in.server_name = dcerpc_server_name(p);
972         r.in.message_name = dcerpc_server_name(p);
973         r.in.message_sender_name = dcerpc_server_name(p);
974         r.in.message_buffer = msg;
975         r.in.message_size = size;
976
977         torture_comment(tctx, "testing NetrMessageBufferSend\n");
978
979         status = dcerpc_wkssvc_NetrMessageBufferSend(p, tctx, &r);
980         torture_assert_ntstatus_ok(tctx, status,
981                                    "NetrMessageBufferSend failed");
982         torture_assert_werr_ok(tctx, r.out.result,
983                                "NetrMessageBufferSend failed");
984         return true;
985 }
986
987 static bool test_NetrGetJoinInformation(struct torture_context *tctx,
988                                         struct dcerpc_pipe *p)
989 {
990         NTSTATUS status;
991         struct wkssvc_NetrGetJoinInformation r;
992         enum wkssvc_NetJoinStatus join_status;
993         const char *name_buffer = "";
994
995         r.in.server_name = dcerpc_server_name(p);
996         r.in.name_buffer = r.out.name_buffer = &name_buffer;
997         r.out.name_type = &join_status;
998
999         torture_comment(tctx, "testing NetrGetJoinInformation\n");
1000
1001         status = dcerpc_wkssvc_NetrGetJoinInformation(p, tctx, &r);
1002         torture_assert_ntstatus_ok(tctx, status,
1003                                    "NetrGetJoinInformation failed");
1004         torture_assert_werr_ok(tctx, r.out.result,
1005                                "NetrGetJoinInformation failed");
1006         return true;
1007 }
1008
1009 static bool test_GetJoinInformation(struct torture_context *tctx,
1010                                     struct dcerpc_pipe *p,
1011                                     enum wkssvc_NetJoinStatus *join_status_p,
1012                                     const char **name)
1013 {
1014         NTSTATUS status;
1015         struct wkssvc_NetrGetJoinInformation r;
1016         enum wkssvc_NetJoinStatus join_status;
1017         const char *name_buffer = "";
1018
1019         r.in.server_name = dcerpc_server_name(p);
1020         r.in.name_buffer = r.out.name_buffer = &name_buffer;
1021         r.out.name_type = &join_status;
1022
1023         status = dcerpc_wkssvc_NetrGetJoinInformation(p, tctx, &r);
1024         torture_assert_ntstatus_ok(tctx, status,
1025                                    "NetrGetJoinInformation failed");
1026         torture_assert_werr_ok(tctx, r.out.result,
1027                                "NetrGetJoinInformation failed");
1028
1029         if (join_status_p) {
1030                 *join_status_p = join_status;
1031         }
1032
1033         if (*name) {
1034                 *name = talloc_strdup(tctx, name_buffer);
1035         }
1036
1037         return true;
1038
1039 }
1040
1041 static bool test_NetrGetJoinableOus(struct torture_context *tctx,
1042                                     struct dcerpc_pipe *p)
1043 {
1044         NTSTATUS status;
1045         struct wkssvc_NetrGetJoinableOus r;
1046         uint32_t num_ous = 0;
1047         const char **ous = NULL;
1048
1049         r.in.server_name = dcerpc_server_name(p);
1050         r.in.domain_name = lp_workgroup(global_loadparm);
1051         r.in.Account = NULL;
1052         r.in.unknown = NULL;
1053         r.in.num_ous = r.out.num_ous = &num_ous;
1054         r.out.ous = &ous;
1055
1056         torture_comment(tctx, "testing NetrGetJoinableOus\n");
1057
1058         status = dcerpc_wkssvc_NetrGetJoinableOus(p, tctx, &r);
1059         torture_assert_ntstatus_ok(tctx, status, "NetrGetJoinableOus failed");
1060         torture_assert_werr_equal(tctx, r.out.result,
1061                                   WERR_NOT_SUPPORTED,
1062                                   "NetrGetJoinableOus failed");
1063
1064         return true;
1065 }
1066
1067 static bool test_NetrGetJoinableOus2(struct torture_context *tctx,
1068                                      struct dcerpc_pipe *p)
1069 {
1070         NTSTATUS status;
1071         struct wkssvc_NetrGetJoinableOus2 r;
1072         uint32_t num_ous = 0;
1073         const char **ous = NULL;
1074
1075         r.in.server_name = dcerpc_server_name(p);
1076         r.in.domain_name = lp_workgroup(global_loadparm);
1077         r.in.Account = NULL;
1078         r.in.EncryptedPassword = NULL;
1079         r.in.num_ous = r.out.num_ous = &num_ous;
1080         r.out.ous = &ous;
1081
1082         torture_comment(tctx, "testing NetrGetJoinableOus2\n");
1083
1084         status = dcerpc_wkssvc_NetrGetJoinableOus2(p, tctx, &r);
1085         torture_assert_ntstatus_ok(tctx, status, "NetrGetJoinableOus2 failed");
1086         torture_assert_werr_equal(tctx, r.out.result,
1087                                   WERR_RPC_E_REMOTE_DISABLED,
1088                                   "NetrGetJoinableOus2 failed");
1089
1090         return true;
1091 }
1092
1093 static bool test_NetrUnjoinDomain(struct torture_context *tctx,
1094                                   struct dcerpc_pipe *p)
1095 {
1096         NTSTATUS status;
1097         struct wkssvc_NetrUnjoinDomain r;
1098         struct cli_credentials *creds = cmdline_credentials;
1099         const char *user = cli_credentials_get_username(creds);
1100         const char *admin_account = NULL;
1101
1102         admin_account = talloc_asprintf(tctx, "%s\\%s",
1103                                         lp_workgroup(global_loadparm),
1104                                         user);
1105
1106         r.in.server_name = dcerpc_server_name(p);
1107         r.in.Account = admin_account;
1108         r.in.password = NULL;
1109         r.in.unjoin_flags = 0;
1110
1111         torture_comment(tctx, "testing NetrUnjoinDomain\n");
1112
1113         status = dcerpc_wkssvc_NetrUnjoinDomain(p, tctx, &r);
1114         torture_assert_ntstatus_ok(tctx, status,
1115                                    "NetrUnjoinDomain failed");
1116         torture_assert_werr_equal(tctx, r.out.result, WERR_NOT_SUPPORTED,
1117                                   "NetrUnjoinDomain failed");
1118         return true;
1119 }
1120
1121 static bool test_NetrJoinDomain(struct torture_context *tctx,
1122                                 struct dcerpc_pipe *p)
1123 {
1124         NTSTATUS status;
1125         struct wkssvc_NetrJoinDomain r;
1126         struct cli_credentials *creds = cmdline_credentials;
1127         const char *user = cli_credentials_get_username(creds);
1128         const char *admin_account = NULL;
1129
1130         admin_account = talloc_asprintf(tctx, "%s\\%s",
1131                                         lp_workgroup(global_loadparm),
1132                                         user);
1133
1134         r.in.server_name = dcerpc_server_name(p);
1135         r.in.domain_name = lp_realm(global_loadparm);
1136         r.in.account_ou = NULL;
1137         r.in.Account = admin_account;
1138         r.in.password = NULL;
1139         r.in.join_flags = 0;
1140
1141         torture_comment(tctx, "testing NetrJoinDomain\n");
1142
1143         status = dcerpc_wkssvc_NetrJoinDomain(p, tctx, &r);
1144         torture_assert_ntstatus_ok(tctx, status,
1145                                    "NetrJoinDomain failed");
1146         torture_assert_werr_equal(tctx, r.out.result, WERR_NOT_SUPPORTED,
1147                                   "NetrJoinDomain failed");
1148         return true;
1149 }
1150
1151 /* encode a wkssvc_PasswordBuffer for remote joining/unjoining:
1152  *
1153  * similar to samr_CryptPasswordEx. Different: 8byte confounder (instead of
1154  * 16byte), confounder in front of the 516 byte buffer (instead of after that
1155  * buffer), calling MD5Update() first with session_key and then with confounder
1156  * (vice versa in samr) - Guenther */
1157
1158 static void encode_wkssvc_join_password_buffer(TALLOC_CTX *mem_ctx,
1159                                                const char *pwd,
1160                                                DATA_BLOB *session_key,
1161                                                struct wkssvc_PasswordBuffer *pwd_buf)
1162 {
1163         uint8_t buffer[516];
1164         struct MD5Context ctx;
1165
1166         DATA_BLOB confounded_session_key = data_blob_talloc(mem_ctx, NULL, 16);
1167
1168         int confounder_len = 8;
1169         uint8_t confounder[8];
1170
1171         encode_pw_buffer(buffer, pwd, STR_UNICODE);
1172
1173         generate_random_buffer((uint8_t *)confounder, confounder_len);
1174
1175         MD5Init(&ctx);
1176         MD5Update(&ctx, session_key->data, session_key->length);
1177         MD5Update(&ctx, confounder, confounder_len);
1178         MD5Final(confounded_session_key.data, &ctx);
1179
1180         arcfour_crypt_blob(buffer, 516, &confounded_session_key);
1181
1182         memcpy(&pwd_buf->data[0], confounder, confounder_len);
1183         memcpy(&pwd_buf->data[8], buffer, 516);
1184
1185         data_blob_free(&confounded_session_key);
1186 }
1187
1188 /*
1189  * prerequisites for remotely joining an unjoined XP SP2 workstation:
1190  * - firewall needs to be disabled (or open for ncacn_np access)
1191  * - HKLM\System\CurrentControlSet\Control\Lsa\forceguest needs to 0
1192  * see also:
1193  * http://support.microsoft.com/kb/294355/EN-US/ and
1194  * http://support.microsoft.com/kb/290403/EN-US/
1195  */
1196
1197 static bool test_NetrJoinDomain2(struct torture_context *tctx,
1198                                  struct dcerpc_pipe *p)
1199 {
1200         NTSTATUS status;
1201         struct wkssvc_NetrJoinDomain2 r;
1202         const char *domain_admin_account = NULL;
1203         const char *domain_admin_password = NULL;
1204         const char *domain_name = NULL;
1205         struct wkssvc_PasswordBuffer pwd_buf;
1206         enum wkssvc_NetJoinStatus join_status;
1207         const char *join_name = NULL;
1208         WERROR expected_err;
1209         DATA_BLOB session_key;
1210
1211         /* FIXME: this test assumes to join workstations / servers and does not
1212          * handle DCs (WERR_SETUP_DOMAIN_CONTROLLER) */
1213
1214         if (!test_GetJoinInformation(tctx, p, &join_status, &join_name))
1215         {
1216                 return false;
1217         }
1218
1219         switch (join_status) {
1220                 case NetSetupDomainName:
1221                         expected_err = WERR_SETUP_ALREADY_JOINED;
1222                         break;
1223                 case NetSetupUnknownStatus:
1224                 case NetSetupUnjoined:
1225                 case NetSetupWorkgroupName:
1226                 default:
1227                         expected_err = WERR_OK;
1228                         break;
1229         }
1230
1231         domain_admin_account = torture_setting_string(tctx, "domain_admin_account", NULL);
1232
1233         domain_admin_password = torture_setting_string(tctx, "domain_admin_password", NULL);
1234
1235         domain_name = torture_setting_string(tctx, "domain_name", NULL);
1236
1237         if ((domain_admin_account == NULL) ||
1238             (domain_admin_password == NULL) ||
1239             (domain_name == NULL)) {
1240                 torture_comment(tctx, "not enough input parameter\n");
1241                 return false;
1242         }
1243
1244         status = dcerpc_fetch_session_key(p, &session_key);
1245         if (!NT_STATUS_IS_OK(status)) {
1246                 return false;
1247         }
1248
1249         encode_wkssvc_join_password_buffer(tctx, domain_admin_password,
1250                                            &session_key, &pwd_buf);
1251
1252         r.in.server_name = dcerpc_server_name(p);
1253         r.in.domain_name = domain_name;
1254         r.in.account_ou = NULL;
1255         r.in.admin_account = domain_admin_account;
1256         r.in.encrypted_password = &pwd_buf;
1257         r.in.join_flags = WKSSVC_JOIN_FLAGS_JOIN_TYPE |
1258                           WKSSVC_JOIN_FLAGS_ACCOUNT_CREATE;
1259
1260         torture_comment(tctx, "testing NetrJoinDomain2 (assuming non-DC)\n");
1261
1262         status = dcerpc_wkssvc_NetrJoinDomain2(p, tctx, &r);
1263         torture_assert_ntstatus_ok(tctx, status,
1264                                    "NetrJoinDomain2 failed");
1265         torture_assert_werr_equal(tctx, r.out.result, expected_err,
1266                                   "NetrJoinDomain2 failed");
1267
1268         if (!test_GetJoinInformation(tctx, p, &join_status, &join_name))
1269         {
1270                 return false;
1271         }
1272
1273         if (join_status != NetSetupDomainName) {
1274                 torture_comment(tctx,
1275                                 "Join verify failed: got %d\n", join_status);
1276                 return false;
1277         }
1278
1279         return true;
1280 }
1281
1282 static bool test_NetrUnjoinDomain2(struct torture_context *tctx,
1283                                    struct dcerpc_pipe *p)
1284 {
1285         NTSTATUS status;
1286         struct wkssvc_NetrUnjoinDomain2 r;
1287         const char *domain_admin_account = NULL;
1288         const char *domain_admin_password = NULL;
1289         struct wkssvc_PasswordBuffer pwd_buf;
1290         enum wkssvc_NetJoinStatus join_status;
1291         const char *join_name = NULL;
1292         WERROR expected_err;
1293         DATA_BLOB session_key;
1294
1295         /* FIXME: this test assumes to join workstations / servers and does not
1296          * handle DCs (WERR_SETUP_DOMAIN_CONTROLLER) */
1297
1298         if (!test_GetJoinInformation(tctx, p, &join_status, &join_name))
1299         {
1300                 return false;
1301         }
1302
1303         switch (join_status) {
1304                 case NetSetupUnjoined:
1305                         expected_err = WERR_SETUP_NOT_JOINED;
1306                         break;
1307                 case NetSetupDomainName:
1308                 case NetSetupUnknownStatus:
1309                 case NetSetupWorkgroupName:
1310                 default:
1311                         expected_err = WERR_OK;
1312                         break;
1313         }
1314
1315         domain_admin_account = torture_setting_string(tctx, "domain_admin_account", NULL);
1316
1317         domain_admin_password = torture_setting_string(tctx, "domain_admin_password", NULL);
1318
1319         if ((domain_admin_account == NULL) ||
1320             (domain_admin_password == NULL)) {
1321                 torture_comment(tctx, "not enough input parameter\n");
1322                 return false;
1323         }
1324
1325         status = dcerpc_fetch_session_key(p, &session_key);
1326         if (!NT_STATUS_IS_OK(status)) {
1327                 return false;
1328         }
1329
1330         encode_wkssvc_join_password_buffer(tctx, domain_admin_password,
1331                                            &session_key, &pwd_buf);
1332
1333         r.in.server_name = dcerpc_server_name(p);
1334         r.in.account = domain_admin_account;
1335         r.in.encrypted_password = &pwd_buf;
1336         r.in.unjoin_flags = 0;
1337
1338         torture_comment(tctx, "testing NetrUnjoinDomain2 (assuming non-DC)\n");
1339
1340         status = dcerpc_wkssvc_NetrUnjoinDomain2(p, tctx, &r);
1341         torture_assert_ntstatus_ok(tctx, status,
1342                                    "NetrUnjoinDomain2 failed");
1343         torture_assert_werr_equal(tctx, r.out.result, expected_err,
1344                                   "NetrUnjoinDomain2 failed");
1345
1346         if (!test_GetJoinInformation(tctx, p, &join_status, &join_name))
1347         {
1348                 return false;
1349         }
1350
1351         switch (join_status) {
1352                 case NetSetupUnjoined:
1353                 case NetSetupWorkgroupName:
1354                         break;
1355                 case NetSetupUnknown:
1356                 case NetSetupDomainName:
1357                 default:
1358                         torture_comment(tctx,
1359                                 "Unjoin verify failed: got %d\n", join_status);
1360                         return false;
1361         }
1362
1363         return true;
1364 }
1365
1366
1367 struct torture_suite *torture_rpc_wkssvc(TALLOC_CTX *mem_ctx)
1368 {
1369         struct torture_suite *suite;
1370         struct torture_rpc_tcase *tcase;
1371         struct torture_test *test;
1372
1373         suite = torture_suite_create(mem_ctx, "WKSSVC");
1374         tcase = torture_suite_add_rpc_iface_tcase(suite, "wkssvc",
1375                                                   &ndr_table_wkssvc);
1376
1377         torture_rpc_tcase_add_test(tcase, "NetWkstaGetInfo",
1378                                    test_NetWkstaGetInfo);
1379
1380         torture_rpc_tcase_add_test(tcase, "NetWkstaTransportEnum",
1381                                    test_NetWkstaTransportEnum);
1382         torture_rpc_tcase_add_test(tcase, "NetrWkstaTransportDel",
1383                                    test_NetrWkstaTransportDel);
1384         torture_rpc_tcase_add_test(tcase, "NetrWkstaTransportAdd",
1385                                    test_NetrWkstaTransportAdd);
1386
1387         torture_rpc_tcase_add_test(tcase, "NetWkstaEnumUsers",
1388                                    test_NetWkstaEnumUsers);
1389         torture_rpc_tcase_add_test(tcase, "NetrWkstaUserGetInfo",
1390                                    test_NetrWkstaUserGetInfo);
1391
1392         torture_rpc_tcase_add_test(tcase, "NetrUseDel",
1393                                    test_NetrUseDel);
1394         torture_rpc_tcase_add_test(tcase, "NetrUseGetInfo",
1395                                    test_NetrUseGetInfo);
1396         torture_rpc_tcase_add_test(tcase, "NetrUseEnum",
1397                                    test_NetrUseEnum);
1398         torture_rpc_tcase_add_test(tcase, "NetrUseAdd",
1399                                    test_NetrUseAdd);
1400
1401         torture_rpc_tcase_add_test(tcase, "NetrValidateName",
1402                                    test_NetrValidateName);
1403         torture_rpc_tcase_add_test(tcase, "NetrValidateName2",
1404                                    test_NetrValidateName2);
1405         torture_rpc_tcase_add_test(tcase, "NetrLogonDomainNameDel",
1406                                    test_NetrLogonDomainNameDel);
1407         torture_rpc_tcase_add_test(tcase, "NetrLogonDomainNameAdd",
1408                                    test_NetrLogonDomainNameAdd);
1409         torture_rpc_tcase_add_test(tcase, "NetrRemoveAlternateComputerName",
1410                                    test_NetrRemoveAlternateComputerName);
1411         torture_rpc_tcase_add_test(tcase, "NetrAddAlternateComputerName",
1412                                    test_NetrAddAlternateComputerName);
1413         test = torture_rpc_tcase_add_test(tcase, "NetrSetPrimaryComputername",
1414                                           test_NetrSetPrimaryComputername);
1415         test->dangerous = true;
1416         test = torture_rpc_tcase_add_test(tcase, "NetrRenameMachineInDomain",
1417                                           test_NetrRenameMachineInDomain);
1418         test->dangerous = true;
1419         test = torture_rpc_tcase_add_test(tcase, "NetrRenameMachineInDomain2",
1420                                           test_NetrRenameMachineInDomain2);
1421         test->dangerous = true;
1422         torture_rpc_tcase_add_test(tcase, "NetrEnumerateComputerNames",
1423                                    test_NetrEnumerateComputerNames);
1424
1425         test = torture_rpc_tcase_add_test(tcase, "NetrJoinDomain2",
1426                                           test_NetrJoinDomain2);
1427         test->dangerous = true;
1428         test = torture_rpc_tcase_add_test(tcase, "NetrUnjoinDomain2",
1429                                           test_NetrUnjoinDomain2);
1430         test->dangerous = true;
1431
1432         torture_rpc_tcase_add_test(tcase, "NetrJoinDomain",
1433                                    test_NetrJoinDomain);
1434         test->dangerous = true;
1435         torture_rpc_tcase_add_test(tcase, "NetrUnjoinDomain",
1436                                    test_NetrUnjoinDomain);
1437         test->dangerous = true;
1438         torture_rpc_tcase_add_test(tcase, "NetrGetJoinInformation",
1439                                    test_NetrGetJoinInformation);
1440         torture_rpc_tcase_add_test(tcase, "NetrGetJoinableOus",
1441                                    test_NetrGetJoinableOus);
1442         torture_rpc_tcase_add_test(tcase, "NetrGetJoinableOus2",
1443                                    test_NetrGetJoinableOus2);
1444
1445         torture_rpc_tcase_add_test(tcase, "NetrWorkstationStatisticsGet",
1446                                    test_NetrWorkstationStatisticsGet);
1447         torture_rpc_tcase_add_test(tcase, "NetrMessageBufferSend",
1448                                    test_NetrMessageBufferSend);
1449
1450         return suite;
1451 }