s3:registry: Initialize struct security_ace ace[]
[samba4-gss.git] / source3 / rpcclient / cmd_clusapi.c
blob7f208a1ca1a7b4ebcfd85ae27e7445df04c4d21e
1 /*
2 Unix SMB/CIFS implementation.
3 RPC pipe client
5 Copyright (C) Günther Deschner 2015
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.
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.
17 You should have received a copy of the GNU General Public License
18 along with this program. If not, see <http://www.gnu.org/licenses/>.
21 #include "includes.h"
22 #include "rpcclient.h"
23 #include "../librpc/gen_ndr/ndr_clusapi_c.h"
25 static WERROR cmd_clusapi_open_cluster(struct rpc_pipe_client *cli,
26 TALLOC_CTX *mem_ctx,
27 int argc,
28 const char **argv)
30 struct dcerpc_binding_handle *b = cli->binding_handle;
31 NTSTATUS status;
32 WERROR error;
33 struct policy_handle Cluster;
35 status = dcerpc_clusapi_OpenCluster(b, mem_ctx,
36 &error,
37 &Cluster);
38 if (!NT_STATUS_IS_OK(status)) {
39 return ntstatus_to_werror(status);
42 if (!W_ERROR_IS_OK(error)) {
43 printf("error: %s\n", win_errstr(error));
44 return error;
47 printf("successfully opened cluster\n");
49 status = dcerpc_clusapi_CloseCluster(b, mem_ctx,
50 &Cluster,
51 &error);
52 if (!NT_STATUS_IS_OK(status)) {
53 return ntstatus_to_werror(status);
56 if (!W_ERROR_IS_OK(error)) {
57 printf("error: %s\n", win_errstr(error));
58 return error;
61 printf("successfully closed cluster\n");
63 return WERR_OK;
66 static WERROR cmd_clusapi_get_cluster_name(struct rpc_pipe_client *cli,
67 TALLOC_CTX *mem_ctx,
68 int argc,
69 const char **argv)
71 struct dcerpc_binding_handle *b = cli->binding_handle;
72 NTSTATUS status;
73 WERROR error;
74 const char *ClusterName;
75 const char *NodeName;
77 status = dcerpc_clusapi_GetClusterName(b, mem_ctx,
78 &ClusterName,
79 &NodeName,
80 &error);
81 if (!NT_STATUS_IS_OK(status)) {
82 return ntstatus_to_werror(status);
85 if (!W_ERROR_IS_OK(error)) {
86 printf("error: %s\n", win_errstr(error));
87 return error;
90 printf("ClusterName: %s\n", ClusterName);
91 printf("NodeName: %s\n", NodeName);
93 return WERR_OK;
96 static WERROR cmd_clusapi_get_cluster_version(struct rpc_pipe_client *cli,
97 TALLOC_CTX *mem_ctx,
98 int argc,
99 const char **argv)
101 struct dcerpc_binding_handle *b = cli->binding_handle;
102 NTSTATUS status;
103 WERROR error;
104 uint16_t lpwMajorVersion;
105 uint16_t lpwMinorVersion;
106 uint16_t lpwBuildNumber;
107 const char *lpszVendorId;
108 const char *lpszCSDVersion;
110 status = dcerpc_clusapi_GetClusterVersion(b, mem_ctx,
111 &lpwMajorVersion,
112 &lpwMinorVersion,
113 &lpwBuildNumber,
114 &lpszVendorId,
115 &lpszCSDVersion,
116 &error);
117 if (!NT_STATUS_IS_OK(status)) {
118 return ntstatus_to_werror(status);
121 if (!W_ERROR_IS_OK(error)) {
122 printf("error: %s\n", win_errstr(error));
123 return error;
126 printf("lpwMajorVersion: %d\n", lpwMajorVersion);
127 printf("lpwMinorVersion: %d\n", lpwMinorVersion);
128 printf("lpwBuildNumber: %d\n", lpwBuildNumber);
129 printf("lpszVendorId: %s\n", lpszVendorId);
130 printf("lpszCSDVersion: %s\n", lpszCSDVersion);
132 return WERR_OK;
135 static WERROR cmd_clusapi_get_quorum_resource(struct rpc_pipe_client *cli,
136 TALLOC_CTX *mem_ctx,
137 int argc,
138 const char **argv)
140 struct dcerpc_binding_handle *b = cli->binding_handle;
141 NTSTATUS status;
142 WERROR error;
143 const char *lpszResourceName;
144 const char *lpszDeviceName;
145 uint32_t pdwMaxQuorumLogSize;
146 WERROR rpc_status;
148 status = dcerpc_clusapi_GetQuorumResource(b, mem_ctx,
149 &lpszResourceName,
150 &lpszDeviceName,
151 &pdwMaxQuorumLogSize,
152 &rpc_status,
153 &error);
154 if (!NT_STATUS_IS_OK(status)) {
155 return ntstatus_to_werror(status);
158 if (!W_ERROR_IS_OK(error)) {
159 printf("error: %s\n", win_errstr(error));
160 return error;
163 printf("lpszResourceName: %s\n", lpszResourceName);
164 printf("lpszDeviceName: %s\n", lpszDeviceName);
165 printf("pdwMaxQuorumLogSize: %d\n", pdwMaxQuorumLogSize);
166 printf("rpc_status: %s\n", win_errstr(rpc_status));
168 return WERR_OK;
171 static WERROR cmd_clusapi_create_enum(struct rpc_pipe_client *cli,
172 TALLOC_CTX *mem_ctx,
173 int argc,
174 const char **argv)
176 struct dcerpc_binding_handle *b = cli->binding_handle;
177 NTSTATUS status;
178 WERROR error;
179 uint32_t dwType = 1;
180 struct ENUM_LIST *ReturnEnum;
181 WERROR rpc_status;
183 if (argc >= 2) {
184 sscanf(argv[1],"%x",&dwType);
187 status = dcerpc_clusapi_CreateEnum(b, mem_ctx,
188 dwType,
189 &ReturnEnum,
190 &rpc_status,
191 &error);
192 if (!NT_STATUS_IS_OK(status)) {
193 return ntstatus_to_werror(status);
196 if (!W_ERROR_IS_OK(error)) {
197 printf("error: %s\n", win_errstr(error));
198 return error;
201 printf("rpc_status: %s\n", win_errstr(rpc_status));
203 return WERR_OK;
206 static WERROR cmd_clusapi_create_enumex(struct rpc_pipe_client *cli,
207 TALLOC_CTX *mem_ctx,
208 int argc,
209 const char **argv)
211 struct dcerpc_binding_handle *b = cli->binding_handle;
212 NTSTATUS status;
213 WERROR error;
214 uint32_t dwType = 1;
215 struct ENUM_LIST *ReturnIdEnum;
216 struct ENUM_LIST *ReturnNameEnum;
217 WERROR rpc_status, ignore;
218 struct policy_handle Cluster;
220 status = dcerpc_clusapi_OpenCluster(b, mem_ctx,
221 &error,
222 &Cluster);
223 if (!NT_STATUS_IS_OK(status)) {
224 return ntstatus_to_werror(status);
227 if (!W_ERROR_IS_OK(error)) {
228 printf("error: %s\n", win_errstr(error));
229 return error;
232 if (argc >= 2) {
233 sscanf(argv[1],"%x",&dwType);
236 status = dcerpc_clusapi_CreateEnumEx(b, mem_ctx,
237 Cluster,
238 dwType,
240 &ReturnIdEnum,
241 &ReturnNameEnum,
242 &rpc_status,
243 &error);
244 dcerpc_clusapi_CloseCluster(b, mem_ctx,
245 &Cluster,
246 &ignore);
248 if (!NT_STATUS_IS_OK(status)) {
249 return ntstatus_to_werror(status);
252 if (!W_ERROR_IS_OK(error)) {
253 printf("error: %s\n", win_errstr(error));
254 return error;
257 printf("rpc_status: %s\n", win_errstr(rpc_status));
259 return WERR_OK;
263 static WERROR cmd_clusapi_open_resource(struct rpc_pipe_client *cli,
264 TALLOC_CTX *mem_ctx,
265 int argc,
266 const char **argv)
268 struct dcerpc_binding_handle *b = cli->binding_handle;
269 NTSTATUS status;
270 const char *lpszResourceName = "Cluster Name";
271 WERROR Status;
272 struct policy_handle hResource;
273 WERROR rpc_status, ignore;
275 if (argc >= 2) {
276 lpszResourceName = argv[1];
279 status = dcerpc_clusapi_OpenResource(b, mem_ctx,
280 lpszResourceName,
281 &Status,
282 &rpc_status,
283 &hResource);
284 if (!NT_STATUS_IS_OK(status)) {
285 return ntstatus_to_werror(status);
288 if (!W_ERROR_IS_OK(Status)) {
289 printf("Status: %s\n", win_errstr(Status));
290 return Status;
293 printf("rpc_status: %s\n", win_errstr(rpc_status));
295 dcerpc_clusapi_CloseResource(b, mem_ctx,
296 &hResource,
297 &ignore);
299 return WERR_OK;
302 static WERROR cmd_clusapi_online_resource(struct rpc_pipe_client *cli,
303 TALLOC_CTX *mem_ctx,
304 int argc,
305 const char **argv)
307 struct dcerpc_binding_handle *b = cli->binding_handle;
308 NTSTATUS status;
309 const char *lpszResourceName = "Cluster Name";
310 WERROR Status;
311 struct policy_handle hResource;
312 WERROR rpc_status, ignore;
314 if (argc >= 2) {
315 lpszResourceName = argv[1];
318 status = dcerpc_clusapi_OpenResource(b, mem_ctx,
319 lpszResourceName,
320 &Status,
321 &rpc_status,
322 &hResource);
323 if (!NT_STATUS_IS_OK(status)) {
324 return ntstatus_to_werror(status);
327 if (!W_ERROR_IS_OK(Status)) {
328 printf("Status: %s\n", win_errstr(Status));
329 return Status;
332 status = dcerpc_clusapi_OnlineResource(b, mem_ctx,
333 hResource,
334 &Status,
335 &rpc_status);
336 dcerpc_clusapi_CloseResource(b, mem_ctx,
337 &hResource,
338 &ignore);
340 if (!NT_STATUS_IS_OK(status)) {
341 return ntstatus_to_werror(status);
344 if (!W_ERROR_IS_OK(Status)) {
345 printf("Status: %s\n", win_errstr(Status));
346 return Status;
349 printf("rpc_status: %s\n", win_errstr(rpc_status));
351 return WERR_OK;
354 static WERROR cmd_clusapi_offline_resource(struct rpc_pipe_client *cli,
355 TALLOC_CTX *mem_ctx,
356 int argc,
357 const char **argv)
359 struct dcerpc_binding_handle *b = cli->binding_handle;
360 NTSTATUS status;
361 const char *lpszResourceName = "Cluster Name";
362 WERROR Status;
363 struct policy_handle hResource;
364 WERROR rpc_status, ignore;
366 if (argc >= 2) {
367 lpszResourceName = argv[1];
370 status = dcerpc_clusapi_OpenResource(b, mem_ctx,
371 lpszResourceName,
372 &Status,
373 &rpc_status,
374 &hResource);
375 if (!NT_STATUS_IS_OK(status)) {
376 return ntstatus_to_werror(status);
379 if (!W_ERROR_IS_OK(Status)) {
380 printf("Status: %s\n", win_errstr(Status));
381 return Status;
384 status = dcerpc_clusapi_OfflineResource(b, mem_ctx,
385 hResource,
386 &Status,
387 &rpc_status);
388 dcerpc_clusapi_CloseResource(b, mem_ctx,
389 &hResource,
390 &ignore);
392 if (!NT_STATUS_IS_OK(status)) {
393 return ntstatus_to_werror(status);
396 if (!W_ERROR_IS_OK(Status)) {
397 printf("Status: %s\n", win_errstr(Status));
398 return Status;
401 printf("rpc_status: %s\n", win_errstr(rpc_status));
403 return WERR_OK;
406 static WERROR cmd_clusapi_get_resource_state(struct rpc_pipe_client *cli,
407 TALLOC_CTX *mem_ctx,
408 int argc,
409 const char **argv)
411 struct dcerpc_binding_handle *b = cli->binding_handle;
412 NTSTATUS status;
413 const char *lpszResourceName = "Cluster Name";
414 WERROR Status;
415 struct policy_handle hResource;
416 WERROR rpc_status;
417 enum clusapi_ClusterResourceState State;
418 const char *NodeName;
419 const char *GroupName;
420 WERROR result, ignore;
422 if (argc >= 2) {
423 lpszResourceName = argv[1];
426 status = dcerpc_clusapi_OpenResource(b, mem_ctx,
427 lpszResourceName,
428 &Status,
429 &rpc_status,
430 &hResource);
431 if (!NT_STATUS_IS_OK(status)) {
432 return ntstatus_to_werror(status);
435 if (!W_ERROR_IS_OK(Status)) {
436 printf("Status: %s\n", win_errstr(Status));
437 return Status;
440 status = dcerpc_clusapi_GetResourceState(b, mem_ctx,
441 hResource,
442 &State,
443 &NodeName,
444 &GroupName,
445 &rpc_status,
446 &result);
447 dcerpc_clusapi_CloseResource(b, mem_ctx,
448 &hResource,
449 &ignore);
451 if (!NT_STATUS_IS_OK(status)) {
452 return ntstatus_to_werror(status);
455 if (!W_ERROR_IS_OK(Status)) {
456 printf("Status: %s\n", win_errstr(Status));
457 return Status;
460 printf("rpc_status: %s\n", win_errstr(rpc_status));
462 return WERR_OK;
465 static WERROR cmd_clusapi_get_cluster_version2(struct rpc_pipe_client *cli,
466 TALLOC_CTX *mem_ctx,
467 int argc,
468 const char **argv)
470 struct dcerpc_binding_handle *b = cli->binding_handle;
471 NTSTATUS status;
472 uint16_t lpwMajorVersion;
473 uint16_t lpwMinorVersion;
474 uint16_t lpwBuildNumber;
475 const char *lpszVendorId;
476 const char *lpszCSDVersion;
477 struct CLUSTER_OPERATIONAL_VERSION_INFO *ppClusterOpVerInfo;
478 WERROR rpc_status;
479 WERROR result;
481 status = dcerpc_clusapi_GetClusterVersion2(b, mem_ctx,
482 &lpwMajorVersion,
483 &lpwMinorVersion,
484 &lpwBuildNumber,
485 &lpszVendorId,
486 &lpszCSDVersion,
487 &ppClusterOpVerInfo,
488 &rpc_status,
489 &result);
490 if (!NT_STATUS_IS_OK(status)) {
491 return ntstatus_to_werror(status);
494 if (!W_ERROR_IS_OK(result)) {
495 printf("result: %s\n", win_errstr(result));
496 return result;
499 printf("rpc_status: %s\n", win_errstr(rpc_status));
501 return WERR_OK;
504 static WERROR cmd_clusapi_pause_node(struct rpc_pipe_client *cli,
505 TALLOC_CTX *mem_ctx,
506 int argc,
507 const char **argv)
509 struct dcerpc_binding_handle *b = cli->binding_handle;
510 NTSTATUS status;
511 const char *lpszNodeName = "CTDB_NODE_0";
512 WERROR Status;
513 struct policy_handle hNode;
514 WERROR rpc_status;
515 WERROR result, ignore;
517 if (argc >= 2) {
518 lpszNodeName = argv[1];
521 status = dcerpc_clusapi_OpenNode(b, mem_ctx,
522 lpszNodeName,
523 &Status,
524 &rpc_status,
525 &hNode);
526 if (!NT_STATUS_IS_OK(status)) {
527 return ntstatus_to_werror(status);
530 if (!W_ERROR_IS_OK(Status)) {
531 printf("Failed to open node %s\n", lpszNodeName);
532 printf("Status: %s\n", win_errstr(Status));
533 return Status;
536 status = dcerpc_clusapi_PauseNode(b, mem_ctx,
537 hNode,
538 &rpc_status,
539 &result);
540 if (!NT_STATUS_IS_OK(status)) {
541 return ntstatus_to_werror(status);
543 if (!W_ERROR_IS_OK(result)) {
544 printf("Failed to pause node %s\n", lpszNodeName);
545 printf("Status: %s\n", win_errstr(result));
546 return result;
549 dcerpc_clusapi_CloseNode(b, mem_ctx,
550 &hNode,
551 &ignore);
553 printf("Cluster node %s has been paused\n", lpszNodeName);
554 printf("rpc_status: %s\n", win_errstr(rpc_status));
556 return WERR_OK;
559 static WERROR cmd_clusapi_resume_node(struct rpc_pipe_client *cli,
560 TALLOC_CTX *mem_ctx,
561 int argc,
562 const char **argv)
564 struct dcerpc_binding_handle *b = cli->binding_handle;
565 NTSTATUS status;
566 const char *lpszNodeName = "CTDB_NODE_0";
567 WERROR Status;
568 struct policy_handle hNode;
569 WERROR rpc_status;
570 WERROR result, ignore;
572 if (argc >= 2) {
573 lpszNodeName = argv[1];
576 status = dcerpc_clusapi_OpenNode(b, mem_ctx,
577 lpszNodeName,
578 &Status,
579 &rpc_status,
580 &hNode);
581 if (!NT_STATUS_IS_OK(status)) {
582 return ntstatus_to_werror(status);
585 if (!W_ERROR_IS_OK(Status)) {
586 printf("Failed to open node %s\n", lpszNodeName);
587 printf("Status: %s\n", win_errstr(Status));
588 return Status;
591 status = dcerpc_clusapi_ResumeNode(b, mem_ctx,
592 hNode,
593 &rpc_status,
594 &result);
595 if (!NT_STATUS_IS_OK(status)) {
596 return ntstatus_to_werror(status);
598 if (!W_ERROR_IS_OK(result)) {
599 printf("Failed to resume node %s\n", lpszNodeName);
600 printf("Status: %s\n", win_errstr(result));
601 return result;
604 dcerpc_clusapi_CloseNode(b, mem_ctx,
605 &hNode,
606 &ignore);
608 printf("Cluster node %s has been resumed\n", lpszNodeName);
609 printf("rpc_status: %s\n", win_errstr(rpc_status));
611 return WERR_OK;
615 struct cmd_set clusapi_commands[] = {
618 .name = "CLUSAPI",
621 .name = "clusapi_open_cluster",
622 .returntype = RPC_RTYPE_WERROR,
623 .ntfn = NULL,
624 .wfn = cmd_clusapi_open_cluster,
625 .table = &ndr_table_clusapi,
626 .rpc_pipe = NULL,
627 .description = "Open cluster",
628 .usage = "",
631 .name = "clusapi_get_cluster_name",
632 .returntype = RPC_RTYPE_WERROR,
633 .ntfn = NULL,
634 .wfn = cmd_clusapi_get_cluster_name,
635 .table = &ndr_table_clusapi,
636 .rpc_pipe = NULL,
637 .description = "Get cluster name",
638 .usage = "",
641 .name = "clusapi_get_cluster_version",
642 .returntype = RPC_RTYPE_WERROR,
643 .ntfn = NULL,
644 .wfn = cmd_clusapi_get_cluster_version,
645 .table = &ndr_table_clusapi,
646 .rpc_pipe = NULL,
647 .description = "Get cluster version",
648 .usage = "",
651 .name = "clusapi_get_quorum_resource",
652 .returntype = RPC_RTYPE_WERROR,
653 .ntfn = NULL,
654 .wfn = cmd_clusapi_get_quorum_resource,
655 .table = &ndr_table_clusapi,
656 .rpc_pipe = NULL,
657 .description = "Get quorum resource",
658 .usage = "",
661 .name = "clusapi_create_enum",
662 .returntype = RPC_RTYPE_WERROR,
663 .ntfn = NULL,
664 .wfn = cmd_clusapi_create_enum,
665 .table = &ndr_table_clusapi,
666 .rpc_pipe = NULL,
667 .description = "Create enum query",
668 .usage = "",
671 .name = "clusapi_create_enumex",
672 .returntype = RPC_RTYPE_WERROR,
673 .ntfn = NULL,
674 .wfn = cmd_clusapi_create_enumex,
675 .table = &ndr_table_clusapi,
676 .rpc_pipe = NULL,
677 .description = "Create enumex query",
678 .usage = "",
681 .name = "clusapi_open_resource",
682 .returntype = RPC_RTYPE_WERROR,
683 .ntfn = NULL,
684 .wfn = cmd_clusapi_open_resource,
685 .table = &ndr_table_clusapi,
686 .rpc_pipe = NULL,
687 .description = "Open cluster resource",
688 .usage = "",
691 .name = "clusapi_online_resource",
692 .returntype = RPC_RTYPE_WERROR,
693 .ntfn = NULL,
694 .wfn = cmd_clusapi_online_resource,
695 .table = &ndr_table_clusapi,
696 .rpc_pipe = NULL,
697 .description = "Set cluster resource online",
698 .usage = "",
701 .name = "clusapi_offline_resource",
702 .returntype = RPC_RTYPE_WERROR,
703 .ntfn = NULL,
704 .wfn = cmd_clusapi_offline_resource,
705 .table = &ndr_table_clusapi,
706 .rpc_pipe = NULL,
707 .description = "Set cluster resource offline",
708 .usage = "",
711 .name = "clusapi_get_resource_state",
712 .returntype = RPC_RTYPE_WERROR,
713 .ntfn = NULL,
714 .wfn = cmd_clusapi_get_resource_state,
715 .table = &ndr_table_clusapi,
716 .rpc_pipe = NULL,
717 .description = "Get cluster resource state",
718 .usage = "",
721 .name = "clusapi_get_cluster_version2",
722 .returntype = RPC_RTYPE_WERROR,
723 .ntfn = NULL,
724 .wfn = cmd_clusapi_get_cluster_version2,
725 .table = &ndr_table_clusapi,
726 .rpc_pipe = NULL,
727 .description = "Get cluster version2",
728 .usage = "",
731 .name = "clusapi_pause_node",
732 .returntype = RPC_RTYPE_WERROR,
733 .ntfn = NULL,
734 .wfn = cmd_clusapi_pause_node,
735 .table = &ndr_table_clusapi,
736 .rpc_pipe = NULL,
737 .description = "Pause cluster node",
738 .usage = "",
741 .name = "clusapi_resume_node",
742 .returntype = RPC_RTYPE_WERROR,
743 .ntfn = NULL,
744 .wfn = cmd_clusapi_resume_node,
745 .table = &ndr_table_clusapi,
746 .rpc_pipe = NULL,
747 .description = "Resume cluster node",
748 .usage = "",
751 .name = NULL,