s3-selftest: add RAP-RPC testsuite for crosschecking RAP and DCERPC calls.
[amitay/samba.git] / source4 / torture / rap / rpc.c
1 /*
2    Unix SMB/CIFS implementation.
3    test suite for RAP / DCERPC consistency
4    Copyright (C) Guenther Deschner 2010
5
6    This program is free software; you can redistribute it and/or modify
7    it under the terms of the GNU General Public License as published by
8    the Free Software Foundation; either version 3 of the License, or
9    (at your option) any later version.
10
11    This program is distributed in the hope that it will be useful,
12    but WITHOUT ANY WARRANTY; without even the implied warranty of
13    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14    GNU General Public License for more details.
15
16    You should have received a copy of the GNU General Public License
17    along with this program.  If not, see <http://www.gnu.org/licenses/>.
18 */
19
20 #include "includes.h"
21 #include "libcli/libcli.h"
22 #include "torture/smbtorture.h"
23 #include "torture/util.h"
24 #include "libcli/rap/rap.h"
25 #include "torture/rap/proto.h"
26 #include "param/param.h"
27 #include "torture/rpc/rpc.h"
28 #include "librpc/gen_ndr/ndr_srvsvc_c.h"
29
30 static bool test_rpc_netservergetinfo(struct torture_context *tctx,
31                                       struct smbcli_state *cli)
32 {
33         struct rap_WserverGetInfo r;
34         struct dcerpc_pipe *p;
35         struct dcerpc_binding_handle *b;
36         struct srvsvc_NetSrvGetInfo s;
37         union srvsvc_NetSrvInfo info;
38
39         const char *server_name;
40
41         torture_assert_ntstatus_ok(tctx,
42                 torture_rpc_connection(tctx, &p, &ndr_table_srvsvc),
43                 "failed to open srvsvc");
44
45         b = p->binding_handle;
46
47         s.in.server_unc = NULL;
48         s.in.level = 101;
49         s.out.info = &info;
50
51         torture_assert_ntstatus_ok(tctx,
52                 dcerpc_srvsvc_NetSrvGetInfo_r(b, tctx, &s),
53                 "srvsvc_NetSrvGetInfo level 101 failed");
54         torture_assert_werr_ok(tctx, s.out.result,
55                 "srvsvc_NetSrvGetInfo level 101 failed");
56
57         r.in.bufsize = 0xffff;
58         r.in.level = 0;
59
60         torture_assert_ntstatus_ok(tctx,
61                 smbcli_rap_netservergetinfo(cli->tree, lp_iconv_convenience(tctx->lp_ctx), tctx, &r),
62                 "rap_netservergetinfo level 0 failed");
63         torture_assert_int_equal(tctx, r.out.status, 0,
64                 "rap_netservergetinfo level 0 failed");
65
66         server_name = talloc_strndup(tctx, info.info101->server_name, 16);
67
68         torture_assert_str_equal(tctx, r.out.info.info0.name, server_name, "server name");
69
70         if (torture_setting_bool(tctx, "samba3", false)) {
71                 torture_skip(tctx, "skipping netservergetinfo level 1 against samba3");
72         }
73
74         r.in.level = 1;
75
76         torture_assert_ntstatus_ok(tctx,
77                 smbcli_rap_netservergetinfo(cli->tree, lp_iconv_convenience(tctx->lp_ctx), tctx, &r),
78                 "rap_netservergetinfo level 1 failed");
79         torture_assert_int_equal(tctx, r.out.status, 0,
80                 "rap_netservergetinfo level 1 failed");
81
82         torture_assert_str_equal(tctx, r.out.info.info1.name, server_name, "server name");
83         torture_assert_int_equal(tctx, r.out.info.info1.version_major, info.info101->version_major, "version major");
84         torture_assert_int_equal(tctx, r.out.info.info1.version_minor, info.info101->version_minor, "version minor");
85         torture_assert_int_equal(tctx, r.out.info.info1.servertype, info.info101->server_type, "server_type");
86         torture_assert_str_equal(tctx, r.out.info.info1.comment, info.info101->comment, "comment");
87
88         talloc_free(p);
89
90         return true;
91 }
92
93 struct torture_suite *torture_rap_rpc(TALLOC_CTX *mem_ctx)
94 {
95         struct torture_suite *suite = torture_suite_create(mem_ctx, "RPC");
96
97         torture_suite_add_1smb_test(suite, "netservergetinfo",
98                                     test_rpc_netservergetinfo);
99
100         suite->description = talloc_strdup(suite,
101                                            "RAP / DCERPC consistency tests");
102
103         return suite;
104 }