s4-smbtorture: add missing error code check in test_netsessionenum().
[Samba/gbeck.git] / source4 / torture / rap / rap.c
blobc31979f0b28283403db763178e3629561e91d0c3
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 bool torture_rap_scan(struct torture_context *torture, struct smbcli_state *cli)
154 int callno;
156 for (callno = 0; callno < 0xffff; callno++) {
157 struct rap_call *call = new_rap_cli_call(torture, callno);
158 NTSTATUS result;
160 result = rap_cli_do_call(cli->tree, call);
162 if (!NT_STATUS_EQUAL(result, NT_STATUS_INVALID_PARAMETER))
163 continue;
165 printf("callno %d is RAP call\n", callno);
168 return true;
171 NTSTATUS torture_rap_init(void)
173 struct torture_suite *suite = torture_suite_create(talloc_autofree_context(), "rap");
174 struct torture_suite *suite_basic = torture_suite_create(suite, "basic");
176 torture_suite_add_suite(suite, suite_basic);
177 torture_suite_add_suite(suite, torture_rap_rpc(suite));
178 torture_suite_add_suite(suite, torture_rap_printing(suite));
179 torture_suite_add_suite(suite, torture_rap_sam(suite));
181 torture_suite_add_1smb_test(suite_basic, "netserverenum",
182 test_netserverenum);
183 torture_suite_add_1smb_test(suite_basic, "netshareenum",
184 test_netshareenum);
185 torture_suite_add_1smb_test(suite_basic, "netservergetinfo",
186 test_netservergetinfo);
187 torture_suite_add_1smb_test(suite_basic, "netsessionenum",
188 test_netsessionenum);
190 torture_suite_add_1smb_test(suite, "scan", torture_rap_scan);
192 suite->description = talloc_strdup(suite,
193 "Remote Administration Protocol tests");
195 torture_register_suite(suite);
197 return NT_STATUS_OK;