2 Unix SMB/CIFS implementation.
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/>.
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
,
30 struct dcerpc_binding_handle
*b
= cli
->binding_handle
;
33 struct policy_handle Cluster
;
35 status
= dcerpc_clusapi_OpenCluster(b
, mem_ctx
,
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
));
47 printf("successfully opened cluster\n");
49 status
= dcerpc_clusapi_CloseCluster(b
, mem_ctx
,
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
));
61 printf("successfully closed cluster\n");
66 static WERROR
cmd_clusapi_get_cluster_name(struct rpc_pipe_client
*cli
,
71 struct dcerpc_binding_handle
*b
= cli
->binding_handle
;
74 const char *ClusterName
;
77 status
= dcerpc_clusapi_GetClusterName(b
, mem_ctx
,
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
));
90 printf("ClusterName: %s\n", ClusterName
);
91 printf("NodeName: %s\n", NodeName
);
96 static WERROR
cmd_clusapi_get_cluster_version(struct rpc_pipe_client
*cli
,
101 struct dcerpc_binding_handle
*b
= cli
->binding_handle
;
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
,
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
));
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
);
135 static WERROR
cmd_clusapi_get_quorum_resource(struct rpc_pipe_client
*cli
,
140 struct dcerpc_binding_handle
*b
= cli
->binding_handle
;
143 const char *lpszResourceName
;
144 const char *lpszDeviceName
;
145 uint32_t pdwMaxQuorumLogSize
;
148 status
= dcerpc_clusapi_GetQuorumResource(b
, mem_ctx
,
151 &pdwMaxQuorumLogSize
,
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
));
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
));
171 static WERROR
cmd_clusapi_create_enum(struct rpc_pipe_client
*cli
,
176 struct dcerpc_binding_handle
*b
= cli
->binding_handle
;
180 struct ENUM_LIST
*ReturnEnum
;
184 sscanf(argv
[1],"%x",&dwType
);
187 status
= dcerpc_clusapi_CreateEnum(b
, mem_ctx
,
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
));
201 printf("rpc_status: %s\n", win_errstr(rpc_status
));
206 static WERROR
cmd_clusapi_create_enumex(struct rpc_pipe_client
*cli
,
211 struct dcerpc_binding_handle
*b
= cli
->binding_handle
;
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
,
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
));
233 sscanf(argv
[1],"%x",&dwType
);
236 status
= dcerpc_clusapi_CreateEnumEx(b
, mem_ctx
,
244 dcerpc_clusapi_CloseCluster(b
, mem_ctx
,
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
));
257 printf("rpc_status: %s\n", win_errstr(rpc_status
));
263 static WERROR
cmd_clusapi_open_resource(struct rpc_pipe_client
*cli
,
268 struct dcerpc_binding_handle
*b
= cli
->binding_handle
;
270 const char *lpszResourceName
= "Cluster Name";
272 struct policy_handle hResource
;
273 WERROR rpc_status
, ignore
;
276 lpszResourceName
= argv
[1];
279 status
= dcerpc_clusapi_OpenResource(b
, mem_ctx
,
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
));
293 printf("rpc_status: %s\n", win_errstr(rpc_status
));
295 dcerpc_clusapi_CloseResource(b
, mem_ctx
,
302 static WERROR
cmd_clusapi_online_resource(struct rpc_pipe_client
*cli
,
307 struct dcerpc_binding_handle
*b
= cli
->binding_handle
;
309 const char *lpszResourceName
= "Cluster Name";
311 struct policy_handle hResource
;
312 WERROR rpc_status
, ignore
;
315 lpszResourceName
= argv
[1];
318 status
= dcerpc_clusapi_OpenResource(b
, mem_ctx
,
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
));
332 status
= dcerpc_clusapi_OnlineResource(b
, mem_ctx
,
336 dcerpc_clusapi_CloseResource(b
, mem_ctx
,
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
));
349 printf("rpc_status: %s\n", win_errstr(rpc_status
));
354 static WERROR
cmd_clusapi_offline_resource(struct rpc_pipe_client
*cli
,
359 struct dcerpc_binding_handle
*b
= cli
->binding_handle
;
361 const char *lpszResourceName
= "Cluster Name";
363 struct policy_handle hResource
;
364 WERROR rpc_status
, ignore
;
367 lpszResourceName
= argv
[1];
370 status
= dcerpc_clusapi_OpenResource(b
, mem_ctx
,
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
));
384 status
= dcerpc_clusapi_OfflineResource(b
, mem_ctx
,
388 dcerpc_clusapi_CloseResource(b
, mem_ctx
,
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
));
401 printf("rpc_status: %s\n", win_errstr(rpc_status
));
406 static WERROR
cmd_clusapi_get_resource_state(struct rpc_pipe_client
*cli
,
411 struct dcerpc_binding_handle
*b
= cli
->binding_handle
;
413 const char *lpszResourceName
= "Cluster Name";
415 struct policy_handle hResource
;
417 enum clusapi_ClusterResourceState State
;
418 const char *NodeName
;
419 const char *GroupName
;
420 WERROR result
, ignore
;
423 lpszResourceName
= argv
[1];
426 status
= dcerpc_clusapi_OpenResource(b
, mem_ctx
,
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
));
440 status
= dcerpc_clusapi_GetResourceState(b
, mem_ctx
,
447 dcerpc_clusapi_CloseResource(b
, mem_ctx
,
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
));
460 printf("rpc_status: %s\n", win_errstr(rpc_status
));
465 static WERROR
cmd_clusapi_get_cluster_version2(struct rpc_pipe_client
*cli
,
470 struct dcerpc_binding_handle
*b
= cli
->binding_handle
;
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
;
481 status
= dcerpc_clusapi_GetClusterVersion2(b
, mem_ctx
,
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
));
499 printf("rpc_status: %s\n", win_errstr(rpc_status
));
504 static WERROR
cmd_clusapi_pause_node(struct rpc_pipe_client
*cli
,
509 struct dcerpc_binding_handle
*b
= cli
->binding_handle
;
511 const char *lpszNodeName
= "CTDB_NODE_0";
513 struct policy_handle hNode
;
515 WERROR result
, ignore
;
518 lpszNodeName
= argv
[1];
521 status
= dcerpc_clusapi_OpenNode(b
, mem_ctx
,
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
));
536 status
= dcerpc_clusapi_PauseNode(b
, mem_ctx
,
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
));
549 dcerpc_clusapi_CloseNode(b
, mem_ctx
,
553 printf("Cluster node %s has been paused\n", lpszNodeName
);
554 printf("rpc_status: %s\n", win_errstr(rpc_status
));
559 static WERROR
cmd_clusapi_resume_node(struct rpc_pipe_client
*cli
,
564 struct dcerpc_binding_handle
*b
= cli
->binding_handle
;
566 const char *lpszNodeName
= "CTDB_NODE_0";
568 struct policy_handle hNode
;
570 WERROR result
, ignore
;
573 lpszNodeName
= argv
[1];
576 status
= dcerpc_clusapi_OpenNode(b
, mem_ctx
,
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
));
591 status
= dcerpc_clusapi_ResumeNode(b
, mem_ctx
,
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
));
604 dcerpc_clusapi_CloseNode(b
, mem_ctx
,
608 printf("Cluster node %s has been resumed\n", lpszNodeName
);
609 printf("rpc_status: %s\n", win_errstr(rpc_status
));
615 struct cmd_set clusapi_commands
[] = {
621 .name
= "clusapi_open_cluster",
622 .returntype
= RPC_RTYPE_WERROR
,
624 .wfn
= cmd_clusapi_open_cluster
,
625 .table
= &ndr_table_clusapi
,
627 .description
= "Open cluster",
631 .name
= "clusapi_get_cluster_name",
632 .returntype
= RPC_RTYPE_WERROR
,
634 .wfn
= cmd_clusapi_get_cluster_name
,
635 .table
= &ndr_table_clusapi
,
637 .description
= "Get cluster name",
641 .name
= "clusapi_get_cluster_version",
642 .returntype
= RPC_RTYPE_WERROR
,
644 .wfn
= cmd_clusapi_get_cluster_version
,
645 .table
= &ndr_table_clusapi
,
647 .description
= "Get cluster version",
651 .name
= "clusapi_get_quorum_resource",
652 .returntype
= RPC_RTYPE_WERROR
,
654 .wfn
= cmd_clusapi_get_quorum_resource
,
655 .table
= &ndr_table_clusapi
,
657 .description
= "Get quorum resource",
661 .name
= "clusapi_create_enum",
662 .returntype
= RPC_RTYPE_WERROR
,
664 .wfn
= cmd_clusapi_create_enum
,
665 .table
= &ndr_table_clusapi
,
667 .description
= "Create enum query",
671 .name
= "clusapi_create_enumex",
672 .returntype
= RPC_RTYPE_WERROR
,
674 .wfn
= cmd_clusapi_create_enumex
,
675 .table
= &ndr_table_clusapi
,
677 .description
= "Create enumex query",
681 .name
= "clusapi_open_resource",
682 .returntype
= RPC_RTYPE_WERROR
,
684 .wfn
= cmd_clusapi_open_resource
,
685 .table
= &ndr_table_clusapi
,
687 .description
= "Open cluster resource",
691 .name
= "clusapi_online_resource",
692 .returntype
= RPC_RTYPE_WERROR
,
694 .wfn
= cmd_clusapi_online_resource
,
695 .table
= &ndr_table_clusapi
,
697 .description
= "Set cluster resource online",
701 .name
= "clusapi_offline_resource",
702 .returntype
= RPC_RTYPE_WERROR
,
704 .wfn
= cmd_clusapi_offline_resource
,
705 .table
= &ndr_table_clusapi
,
707 .description
= "Set cluster resource offline",
711 .name
= "clusapi_get_resource_state",
712 .returntype
= RPC_RTYPE_WERROR
,
714 .wfn
= cmd_clusapi_get_resource_state
,
715 .table
= &ndr_table_clusapi
,
717 .description
= "Get cluster resource state",
721 .name
= "clusapi_get_cluster_version2",
722 .returntype
= RPC_RTYPE_WERROR
,
724 .wfn
= cmd_clusapi_get_cluster_version2
,
725 .table
= &ndr_table_clusapi
,
727 .description
= "Get cluster version2",
731 .name
= "clusapi_pause_node",
732 .returntype
= RPC_RTYPE_WERROR
,
734 .wfn
= cmd_clusapi_pause_node
,
735 .table
= &ndr_table_clusapi
,
737 .description
= "Pause cluster node",
741 .name
= "clusapi_resume_node",
742 .returntype
= RPC_RTYPE_WERROR
,
744 .wfn
= cmd_clusapi_resume_node
,
745 .table
= &ndr_table_clusapi
,
747 .description
= "Resume cluster node",