10c1ce21f344fa08b7311f69ef9ee3ee72c99481
[gd/samba-autobuild/.git] / source4 / torture / rpc / ntsvcs.c
1 /*
2    Unix SMB/CIFS implementation.
3    test suite for rpc ntsvcs operations
4
5    Copyright (C) Guenther Deschner 2008
6
7    This program is free software; you can redistribute it and/or modify
8    it under the terms of the GNU General Public License as published by
9    the Free Software Foundation; either version 3 of the License, or
10    (at your option) any later version.
11
12    This program is distributed in the hope that it will be useful,
13    but WITHOUT ANY WARRANTY; without even the implied warranty of
14    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15    GNU General Public License for more details.
16
17    You should have received a copy of the GNU General Public License
18    along with this program; if not, write to the Free Software
19    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
20 */
21
22 #include "includes.h"
23 #include "torture/torture.h"
24 #include "torture/rpc/rpc.h"
25 #include "librpc/gen_ndr/ndr_ntsvcs_c.h"
26 #include "torture/util.h"
27 #include "param/param.h"
28
29 static bool test_PNP_GetVersion(struct torture_context *tctx,
30                                 struct dcerpc_pipe *p)
31 {
32         NTSTATUS status;
33         struct PNP_GetVersion r;
34         uint16_t version = 0;
35
36         r.out.version = &version;
37
38         status = dcerpc_PNP_GetVersion(p, tctx, &r);
39
40         torture_assert_ntstatus_ok(tctx, status, "PNP_GetVersion");
41         torture_assert_werr_ok(tctx, r.out.result, "PNP_GetVersion");
42         torture_assert_int_equal(tctx, version, 0x400, "invalid version");
43
44         return true;
45 }
46
47 static bool test_PNP_GetDeviceListSize(struct torture_context *tctx,
48                                        struct dcerpc_pipe *p)
49 {
50         NTSTATUS status;
51         struct PNP_GetDeviceListSize r;
52         uint32_t size = 0;
53
54         r.in.devicename = NULL;
55         r.in.flags = 0;
56         r.out.size = &size;
57
58         status = dcerpc_PNP_GetDeviceListSize(p, tctx, &r);
59
60         torture_assert_ntstatus_ok(tctx, status, "PNP_GetDeviceListSize");
61         torture_assert_werr_ok(tctx, r.out.result, "PNP_GetDeviceListSize");
62
63         return true;
64 }
65
66 static bool test_PNP_GetDeviceList(struct torture_context *tctx,
67                                    struct dcerpc_pipe *p)
68 {
69         NTSTATUS status;
70         struct PNP_GetDeviceList r;
71         uint16_t *buffer = NULL;
72         uint32_t length = 0;
73
74         buffer = talloc_array(tctx, uint16_t, 0);
75
76         r.in.filter = NULL;
77         r.in.flags = 0;
78         r.in.length = &length;
79         r.out.length = &length;
80         r.out.buffer = buffer;
81
82         status = dcerpc_PNP_GetDeviceList(p, tctx, &r);
83         torture_assert_ntstatus_ok(tctx, status, "PNP_GetDeviceList");
84
85         if (W_ERROR_EQUAL(r.out.result, WERR_CM_BUFFER_SMALL)) {
86                 struct PNP_GetDeviceListSize s;
87
88                 s.in.devicename = NULL;
89                 s.in.flags = 0;
90                 s.out.size = &length;
91
92                 status = dcerpc_PNP_GetDeviceListSize(p, tctx, &s);
93
94                 torture_assert_ntstatus_ok(tctx, status, "PNP_GetDeviceListSize");
95                 torture_assert_werr_ok(tctx, s.out.result, "PNP_GetDeviceListSize");
96         }
97
98         buffer = talloc_array(tctx, uint16_t, length);
99
100         r.in.length = &length;
101         r.out.length = &length;
102         r.out.buffer = buffer;
103
104         status = dcerpc_PNP_GetDeviceList(p, tctx, &r);
105         torture_assert_ntstatus_ok(tctx, status, "PNP_GetDeviceList");
106         torture_assert_werr_ok(tctx, r.out.result, "PNP_GetDeviceList");
107
108         return true;
109 }
110
111
112 struct torture_suite *torture_rpc_ntsvcs(TALLOC_CTX *mem_ctx)
113 {
114         struct torture_rpc_tcase *tcase;
115         struct torture_suite *suite = torture_suite_create(mem_ctx, "NTSVCS");
116         struct torture_test *test;
117
118         tcase = torture_suite_add_rpc_iface_tcase(suite, "ntsvcs",
119                                                   &ndr_table_ntsvcs);
120
121         test = torture_rpc_tcase_add_test(tcase, "PNP_GetDeviceList",
122                                           test_PNP_GetDeviceList);
123         test = torture_rpc_tcase_add_test(tcase, "PNP_GetDeviceListSize",
124                                           test_PNP_GetDeviceListSize);
125         test = torture_rpc_tcase_add_test(tcase, "PNP_GetVersion",
126                                           test_PNP_GetVersion);
127
128         return suite;
129 }