summaryrefslogtreecommitdiff
path: root/source3/rpcclient/cmd_clusapi.c
blob: 0f6f469b3c4d262c8fa409b7795debc013290211 (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
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
/*
   Unix SMB/CIFS implementation.
   RPC pipe client

   Copyright (C) Günther Deschner 2015

   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, see <http://www.gnu.org/licenses/>.
*/

#include "includes.h"
#include "rpcclient.h"
#include "../librpc/gen_ndr/ndr_clusapi_c.h"

static WERROR cmd_clusapi_open_cluster(struct rpc_pipe_client *cli,
				       TALLOC_CTX *mem_ctx,
				       int argc,
				       const char **argv)
{
	struct dcerpc_binding_handle *b = cli->binding_handle;
	NTSTATUS status;
	uint32_t error;
	struct policy_handle Cluster;

	status = dcerpc_clusapi_OpenCluster(b, mem_ctx,
					    &error,
					    &Cluster);
	if (!NT_STATUS_IS_OK(status)) {
		return ntstatus_to_werror(status);
	}

	if (error) {
		printf("error: %d\n", error);
		return W_ERROR(error);
	}

	printf("successfully opened cluster\n");

	status = dcerpc_clusapi_CloseCluster(b, mem_ctx,
					     &Cluster,
					     &error);
	if (!NT_STATUS_IS_OK(status)) {
		return ntstatus_to_werror(status);
	}

	if (error) {
		printf("error: %d\n", error);
		return W_ERROR(error);
	}

	printf("successfully closed cluster\n");

	return WERR_OK;
}

static WERROR cmd_clusapi_get_cluster_name(struct rpc_pipe_client *cli,
					   TALLOC_CTX *mem_ctx,
					   int argc,
					   const char **argv)
{
	struct dcerpc_binding_handle *b = cli->binding_handle;
	NTSTATUS status;
	uint32_t error;
	const char *ClusterName;
	const char *NodeName;

	status = dcerpc_clusapi_GetClusterName(b, mem_ctx,
					       &ClusterName,
					       &NodeName,
					       &error);
	if (!NT_STATUS_IS_OK(status)) {
		return ntstatus_to_werror(status);
	}

	if (error) {
		printf("error: %d\n", error);
		return W_ERROR(error);
	}

	printf("ClusterName: %s\n", ClusterName);
	printf("NodeName: %s\n", NodeName);

	return WERR_OK;
}

static WERROR cmd_clusapi_get_cluster_version(struct rpc_pipe_client *cli,
					      TALLOC_CTX *mem_ctx,
					      int argc,
					      const char **argv)
{
	struct dcerpc_binding_handle *b = cli->binding_handle;
	NTSTATUS status;
	uint32_t error;
	uint16_t lpwMajorVersion;
	uint16_t lpwMinorVersion;
	uint16_t lpwBuildNumber;
	const char *lpszVendorId;
	const char *lpszCSDVersion;

	status = dcerpc_clusapi_GetClusterVersion(b, mem_ctx,
						  &lpwMajorVersion,
						  &lpwMinorVersion,
						  &lpwBuildNumber,
						  &lpszVendorId,
						  &lpszCSDVersion,
						  &error);
	if (!NT_STATUS_IS_OK(status)) {
		return ntstatus_to_werror(status);
	}

	if (error) {
		printf("error: %d\n", error);
		return W_ERROR(error);
	}

	printf("lpwMajorVersion: %d\n", lpwMajorVersion);
	printf("lpwMinorVersion: %d\n", lpwMinorVersion);
	printf("lpwBuildNumber: %d\n", lpwBuildNumber);
	printf("lpszVendorId: %s\n", lpszVendorId);
	printf("lpszCSDVersion: %s\n", lpszCSDVersion);

	return WERR_OK;
}

static WERROR cmd_clusapi_get_quorum_resource(struct rpc_pipe_client *cli,
					      TALLOC_CTX *mem_ctx,
					      int argc,
					      const char **argv)
{
	struct dcerpc_binding_handle *b = cli->binding_handle;
	NTSTATUS status;
	uint32_t error;
	const char *lpszResourceName;
	const char *lpszDeviceName;
	uint32_t pdwMaxQuorumLogSize;
	uint32_t rpc_status;

	status = dcerpc_clusapi_GetQuorumResource(b, mem_ctx,
						  &lpszResourceName,
						  &lpszDeviceName,
						  &pdwMaxQuorumLogSize,
						  &rpc_status,
						  &error);
	if (!NT_STATUS_IS_OK(status)) {
		return ntstatus_to_werror(status);
	}

	if (error) {
		printf("error: %d\n", error);
		return W_ERROR(error);
	}

	printf("lpszResourceName: %s\n", lpszResourceName);
	printf("lpszDeviceName: %s\n", lpszDeviceName);
	printf("pdwMaxQuorumLogSize: %d\n", pdwMaxQuorumLogSize);
	printf("rpc_status: %d\n", rpc_status);

	return WERR_OK;
}

static WERROR cmd_clusapi_create_enum(struct rpc_pipe_client *cli,
				      TALLOC_CTX *mem_ctx,
				      int argc,
				      const char **argv)
{
	struct dcerpc_binding_handle *b = cli->binding_handle;
	NTSTATUS status;
	uint32_t error;
	uint32_t dwType = 1;
	struct ENUM_LIST *ReturnEnum;
	uint32_t rpc_status;

	if (argc >= 2) {
		sscanf(argv[1],"%x",&dwType);
	}

	status = dcerpc_clusapi_CreateEnum(b, mem_ctx,
					   dwType,
					   &ReturnEnum,
					   &rpc_status,
					   &error);
	if (!NT_STATUS_IS_OK(status)) {
		return ntstatus_to_werror(status);
	}

	if (error) {
		printf("error: %d\n", error);
		return W_ERROR(error);
	}

	printf("rpc_status: %d\n", rpc_status);

	return WERR_OK;
}

static WERROR cmd_clusapi_open_resource(struct rpc_pipe_client *cli,
					TALLOC_CTX *mem_ctx,
					int argc,
					const char **argv)
{
	struct dcerpc_binding_handle *b = cli->binding_handle;
	NTSTATUS status;
	const char *lpszResourceName = "Cluster Name";
	uint32_t Status;
	struct policy_handle hResource;
	uint32_t rpc_status;

	if (argc >= 2) {
		lpszResourceName = argv[1];
	}

	status = dcerpc_clusapi_OpenResource(b, mem_ctx,
					     lpszResourceName,
					     &Status,
					     &rpc_status,
					     &hResource);
	if (!NT_STATUS_IS_OK(status)) {
		return ntstatus_to_werror(status);
	}

	if (Status) {
		printf("Status: %d\n", Status);
		return W_ERROR(Status);
	}

	printf("rpc_status: %d\n", rpc_status);

	return WERR_OK;
}

struct cmd_set clusapi_commands[] = {

	{ "CLUSAPI" },
	{ "clusapi_open_cluster", RPC_RTYPE_WERROR, NULL, cmd_clusapi_open_cluster, &ndr_table_clusapi, NULL, "bla", "" },
	{ "clusapi_get_cluster_name", RPC_RTYPE_WERROR, NULL, cmd_clusapi_get_cluster_name, &ndr_table_clusapi, NULL, "bla", "" },
	{ "clusapi_get_cluster_version", RPC_RTYPE_WERROR, NULL, cmd_clusapi_get_cluster_version, &ndr_table_clusapi, NULL, "bla", "" },
	{ "clusapi_get_quorum_resource", RPC_RTYPE_WERROR, NULL, cmd_clusapi_get_quorum_resource, &ndr_table_clusapi, NULL, "bla", "" },
	{ "clusapi_create_enum", RPC_RTYPE_WERROR, NULL, cmd_clusapi_create_enum, &ndr_table_clusapi, NULL, "bla", "" },
	{ "clusapi_open_resource", RPC_RTYPE_WERROR, NULL, cmd_clusapi_open_resource, &ndr_table_clusapi, NULL, "bla", "" },
	{ NULL }
};