summaryrefslogtreecommitdiff
path: root/source4/torture/rpc/ntsvcs.c
blob: a25129d3dae1034bd371e39cacf37c143f94397e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
/*
   Unix SMB/CIFS implementation.
   test suite for rpc ntsvcs operations

   Copyright (C) Guenther Deschner 2008

   This program is free software; you can redistribute it and/or modify
   it under the terms of the GNU General Public License as published by
   the Free Software Foundation; either version 3 of the License, or
   (at your option) any later version.

   This program is distributed in the hope that it will be useful,
   but WITHOUT ANY WARRANTY; without even the implied warranty of
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   GNU General Public License for more details.

   You should have received a copy of the GNU General Public License
   along with this program; if not, write to the Free Software
   Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/

#include "includes.h"
#include "torture/rpc/torture_rpc.h"
#include "librpc/gen_ndr/ndr_ntsvcs_c.h"

static bool test_PNP_GetVersion(struct torture_context *tctx,
				struct dcerpc_pipe *p)
{
	struct dcerpc_binding_handle *b = p->binding_handle;
	NTSTATUS status;
	struct PNP_GetVersion r;
	uint16_t version = 0;

	r.out.version = &version;

	status = dcerpc_PNP_GetVersion_r(b, tctx, &r);

	torture_assert_ntstatus_ok(tctx, status, "PNP_GetVersion");
	torture_assert_werr_ok(tctx, r.out.result, "PNP_GetVersion");
	torture_assert_int_equal(tctx, version, 0x400, "invalid version");

	return true;
}

static bool test_PNP_GetDeviceListSize(struct torture_context *tctx,
				       struct dcerpc_pipe *p)
{
	struct dcerpc_binding_handle *b = p->binding_handle;
	struct PNP_GetDeviceListSize r;
	uint32_t size = 0;

	r.in.devicename = NULL;
	r.in.flags = CM_GETIDLIST_FILTER_SERVICE;
	r.out.size = &size;

	torture_assert_ntstatus_ok(tctx,
		dcerpc_PNP_GetDeviceListSize_r(b, tctx, &r),
		"PNP_GetDeviceListSize");
	torture_assert_werr_equal(tctx, r.out.result, WERR_CM_INVALID_POINTER,
		"PNP_GetDeviceListSize");

	r.in.devicename = "Spooler";

	torture_assert_ntstatus_ok(tctx,
		dcerpc_PNP_GetDeviceListSize_r(b, tctx, &r),
		"PNP_GetDeviceListSize");
	torture_assert_werr_ok(tctx, r.out.result,
		"PNP_GetDeviceListSize");

	return true;
}

static bool test_PNP_GetDeviceList(struct torture_context *tctx,
				   struct dcerpc_pipe *p)
{
	struct dcerpc_binding_handle *b = p->binding_handle;
	struct PNP_GetDeviceList r;
	uint16_t *buffer = NULL;
	uint32_t length = 0;

	buffer = talloc_array(tctx, uint16_t, 0);

	r.in.filter = NULL;
	r.in.flags = CM_GETIDLIST_FILTER_SERVICE;
	r.in.length = &length;
	r.out.length = &length;
	r.out.buffer = buffer;

	torture_assert_ntstatus_ok(tctx,
		dcerpc_PNP_GetDeviceList_r(b, tctx, &r),
		"PNP_GetDeviceList failed");
	torture_assert_werr_equal(tctx, r.out.result, WERR_CM_INVALID_POINTER,
		"PNP_GetDeviceList failed");

	r.in.filter = "Spooler";

	torture_assert_ntstatus_ok(tctx,
		dcerpc_PNP_GetDeviceList_r(b, tctx, &r),
		"PNP_GetDeviceList failed");

	if (W_ERROR_EQUAL(r.out.result, WERR_CM_BUFFER_SMALL)) {
		struct PNP_GetDeviceListSize s;

		s.in.devicename = "Spooler";
		s.in.flags = CM_GETIDLIST_FILTER_SERVICE;
		s.out.size = &length;

		torture_assert_ntstatus_ok(tctx,
			dcerpc_PNP_GetDeviceListSize_r(b, tctx, &s),
			"PNP_GetDeviceListSize failed");
		torture_assert_werr_ok(tctx, s.out.result,
			"PNP_GetDeviceListSize failed");
	}

	buffer = talloc_array(tctx, uint16_t, length);

	r.in.length = &length;
	r.out.length = &length;
	r.out.buffer = buffer;

	torture_assert_ntstatus_ok(tctx,
		dcerpc_PNP_GetDeviceList_r(b, tctx, &r),
		"PNP_GetDeviceList failed");

	torture_assert_werr_ok(tctx, r.out.result,
		"PNP_GetDeviceList failed");

	return true;
}

static bool test_PNP_GetDeviceRegProp(struct torture_context *tctx,
				      struct dcerpc_pipe *p)
{
	struct dcerpc_binding_handle *b = p->binding_handle;
	NTSTATUS status;
	struct PNP_GetDeviceRegProp r;

	enum winreg_Type reg_data_type = REG_NONE;
	uint32_t buffer_size = 0;
	uint32_t needed = 0;
	uint8_t *buffer;

	buffer = talloc(tctx, uint8_t);

	r.in.devicepath = "ACPI\\ACPI0003\\1";
	r.in.property = DEV_REGPROP_DESC;
	r.in.flags = 0;
	r.in.reg_data_type = &reg_data_type;
	r.in.buffer_size = &buffer_size;
	r.in.needed = &needed;
	r.out.buffer = buffer;
	r.out.reg_data_type = &reg_data_type;
	r.out.buffer_size = &buffer_size;
	r.out.needed = &needed;

	status = dcerpc_PNP_GetDeviceRegProp_r(b, tctx, &r);
	torture_assert_ntstatus_ok(tctx, status, "PNP_GetDeviceRegProp");

	if (W_ERROR_EQUAL(r.out.result, WERR_CM_BUFFER_SMALL)) {

		buffer = talloc_array(tctx, uint8_t, needed);
		r.in.buffer_size = &needed;

		status = dcerpc_PNP_GetDeviceRegProp_r(b, tctx, &r);
		torture_assert_ntstatus_ok(tctx, status, "PNP_GetDeviceRegProp");
	}

	return true;
}

struct torture_suite *torture_rpc_ntsvcs(TALLOC_CTX *mem_ctx)
{
	struct torture_rpc_tcase *tcase;
	struct torture_suite *suite = torture_suite_create(mem_ctx, "ntsvcs");

	tcase = torture_suite_add_rpc_iface_tcase(suite, "ntsvcs",
						  &ndr_table_ntsvcs);

	torture_rpc_tcase_add_test(tcase, "PNP_GetDeviceRegProp",
				   test_PNP_GetDeviceRegProp);
	torture_rpc_tcase_add_test(tcase, "PNP_GetDeviceList",
				   test_PNP_GetDeviceList);
	torture_rpc_tcase_add_test(tcase, "PNP_GetDeviceListSize",
				   test_PNP_GetDeviceListSize);
	torture_rpc_tcase_add_test(tcase, "PNP_GetVersion",
				   test_PNP_GetVersion);

	return suite;
}