libsmbconf: Document smbconf_get_config().
[Samba.git] / source4 / torture / rap / rap.c
blob5c1c5e196c680500705856f42abcd107cbcd467c
1 /*
2 Unix SMB/CIFS implementation.
3 test suite for various RAP operations
4 Copyright (C) Volker Lendecke 2004
5 Copyright (C) Tim Potter 2005
6 Copyright (C) Jelmer Vernooij 2007
7 Copyright (C) Guenther Deschner 2010
9 This program is free software; you can redistribute it and/or modify
10 it under the terms of the GNU General Public License as published by
11 the Free Software Foundation; either version 3 of the License, or
12 (at your option) any later version.
14 This program is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 GNU General Public License for more details.
19 You should have received a copy of the GNU General Public License
20 along with this program. If not, see <http://www.gnu.org/licenses/>.
23 #include "includes.h"
24 #include "libcli/libcli.h"
25 #include "torture/smbtorture.h"
26 #include "torture/util.h"
27 #include "param/param.h"
28 #include "libcli/rap/rap.h"
29 #include "torture/rap/proto.h"
31 static bool test_netshareenum(struct torture_context *tctx,
32 struct smbcli_state *cli)
34 struct rap_NetShareEnum r;
35 int i;
37 r.in.level = 1;
38 r.in.bufsize = 8192;
40 torture_assert_ntstatus_ok(tctx,
41 smbcli_rap_netshareenum(cli->tree, tctx, &r), "");
43 for (i=0; i<r.out.count; i++) {
44 printf("%s %d %s\n", r.out.info[i].info1.share_name,
45 r.out.info[i].info1.share_type,
46 r.out.info[i].info1.comment);
49 return true;
52 static bool test_netserverenum(struct torture_context *tctx,
53 struct smbcli_state *cli)
55 struct rap_NetServerEnum2 r;
56 int i;
58 r.in.level = 0;
59 r.in.bufsize = 8192;
60 r.in.servertype = 0xffffffff;
61 r.in.servertype = 0x80000000;
62 r.in.domain = NULL;
64 torture_assert_ntstatus_ok(tctx,
65 smbcli_rap_netserverenum2(cli->tree, tctx, &r), "");
67 for (i=0; i<r.out.count; i++) {
68 switch (r.in.level) {
69 case 0:
70 printf("%s\n", r.out.info[i].info0.name);
71 break;
72 case 1:
73 printf("%s %x %s\n", r.out.info[i].info1.name,
74 r.out.info[i].info1.servertype,
75 r.out.info[i].info1.comment);
76 break;
80 return true;
83 static bool test_netservergetinfo(struct torture_context *tctx,
84 struct smbcli_state *cli)
86 struct rap_WserverGetInfo r;
87 bool res = true;
89 r.in.bufsize = 0xffff;
91 r.in.level = 0;
92 torture_assert_ntstatus_ok(tctx,
93 smbcli_rap_netservergetinfo(cli->tree, tctx, &r),
94 "rap_netservergetinfo level 0 failed");
95 torture_assert_werr_ok(tctx, W_ERROR(r.out.status),
96 "rap_netservergetinfo level 0 failed");
98 r.in.level = 1;
99 torture_assert_ntstatus_ok(tctx,
100 smbcli_rap_netservergetinfo(cli->tree, tctx, &r),
101 "rap_netservergetinfo level 1 failed");
102 torture_assert_werr_ok(tctx, W_ERROR(r.out.status),
103 "rap_netservergetinfo level 1 failed");
105 return res;
108 static bool test_netsessionenum(struct torture_context *tctx,
109 struct smbcli_state *cli)
111 struct rap_NetSessionEnum r;
112 int i,n;
113 uint16_t levels[] = { 2 };
115 for (i=0; i < ARRAY_SIZE(levels); i++) {
117 r.in.level = levels[i];
118 r.in.bufsize = 8192;
120 torture_comment(tctx,
121 "Testing rap_NetSessionEnum level %d\n", r.in.level);
123 torture_assert_ntstatus_ok(tctx,
124 smbcli_rap_netsessionenum(cli->tree, tctx, &r),
125 "smbcli_rap_netsessionenum failed");
126 torture_assert_werr_ok(tctx, W_ERROR(r.out.status),
127 "smbcli_rap_netsessionenum failed");
129 for (n=0; n < r.out.count; n++) {
130 switch (r.in.level) {
131 case 2:
132 torture_comment(tctx, "ComputerName: %s\n",
133 r.out.info[n].info2.ComputerName);
135 torture_comment(tctx, "UserName: %s\n",
136 r.out.info[n].info2.UserName);
138 torture_assert(tctx, r.out.info[n].info2.ComputerName,
139 "ComputerName empty");
140 torture_assert(tctx, r.out.info[n].info2.UserName,
141 "UserName empty");
142 break;
143 default:
144 break;
149 return true;
152 static bool test_netsessiongetinfo_bysession(struct torture_context *tctx,
153 struct smbcli_state *cli,
154 const char *session)
156 struct rap_NetSessionGetInfo r;
157 int i;
158 uint16_t levels[] = { 2 };
160 if (session && session[0] == '\\' && session[1] == '\\') {
161 r.in.SessionName = session;
162 } else {
163 r.in.SessionName = talloc_asprintf(tctx, "\\\\%s", session);
165 r.in.bufsize = 0xffff;
167 for (i=0; i < ARRAY_SIZE(levels); i++) {
169 r.in.level = levels[i];
171 torture_assert_ntstatus_ok(tctx,
172 smbcli_rap_netsessiongetinfo(cli->tree, tctx, &r),
173 "rap_netsessiongetinfo failed");
174 torture_assert_werr_ok(tctx, W_ERROR(r.out.status),
175 "rap_netsessiongetinfo failed");
178 return true;
181 static bool test_netsessiongetinfo(struct torture_context *tctx,
182 struct smbcli_state *cli)
184 struct rap_NetSessionEnum r;
185 int i,n;
186 uint16_t levels[] = { 2 };
188 for (i=0; i < ARRAY_SIZE(levels); i++) {
190 r.in.level = levels[i];
191 r.in.bufsize = 8192;
193 torture_assert_ntstatus_ok(tctx,
194 smbcli_rap_netsessionenum(cli->tree, tctx, &r),
195 "smbcli_rap_netsessionenum failed");
196 torture_assert_werr_ok(tctx, W_ERROR(r.out.status),
197 "smbcli_rap_netsessionenum failed");
199 for (n=0; n < r.out.count; n++) {
200 torture_assert(tctx,
201 test_netsessiongetinfo_bysession(tctx, cli, r.out.info[n].info2.ComputerName),
202 "failed to query sessioninfo");
206 return true;
210 bool torture_rap_scan(struct torture_context *torture, struct smbcli_state *cli)
212 int callno;
214 for (callno = 0; callno < 0xffff; callno++) {
215 struct rap_call *call = new_rap_cli_call(torture, callno);
216 NTSTATUS result;
218 result = rap_cli_do_call(cli->tree, call);
220 if (!NT_STATUS_EQUAL(result, NT_STATUS_INVALID_PARAMETER))
221 continue;
223 printf("callno %d is RAP call\n", callno);
226 return true;
229 NTSTATUS torture_rap_init(void)
231 struct torture_suite *suite = torture_suite_create(talloc_autofree_context(), "rap");
232 struct torture_suite *suite_basic = torture_suite_create(suite, "basic");
234 torture_suite_add_suite(suite, suite_basic);
235 torture_suite_add_suite(suite, torture_rap_rpc(suite));
236 torture_suite_add_suite(suite, torture_rap_printing(suite));
237 torture_suite_add_suite(suite, torture_rap_sam(suite));
239 torture_suite_add_1smb_test(suite_basic, "netserverenum",
240 test_netserverenum);
241 torture_suite_add_1smb_test(suite_basic, "netshareenum",
242 test_netshareenum);
243 torture_suite_add_1smb_test(suite_basic, "netservergetinfo",
244 test_netservergetinfo);
245 torture_suite_add_1smb_test(suite_basic, "netsessionenum",
246 test_netsessionenum);
247 torture_suite_add_1smb_test(suite_basic, "netsessiongetinfo",
248 test_netsessiongetinfo);
250 torture_suite_add_1smb_test(suite, "scan", torture_rap_scan);
252 suite->description = talloc_strdup(suite,
253 "Remote Administration Protocol tests");
255 torture_register_suite(suite);
257 return NT_STATUS_OK;