r9038: Revert svn rev 414. Discussed with Jerry and Metze.
[Samba.git] / source / rpc_client / cli_shutdown.c
blobc342f255a9fec0e829f6445adbdc29e73c8e16a4
1 /*
2 Unix SMB/CIFS implementation.
3 RPC Pipe client
5 Copyright (C) Andrew Tridgell 1992-1998,
6 Copyright (C) Luke Kenneth Casson Leighton 1996-1998,
7 Copyright (C) Paul Ashton 1997-1998.
8 Copyright (C) Jeremy Allison 1999,
9 Copyright (C) Simo Sorce 2001,
10 Copyright (C) Jim McDonough (jmcd@us.ibm.com) 2003.
12 This program is free software; you can redistribute it and/or modify
13 it under the terms of the GNU General Public License as published by
14 the Free Software Foundation; either version 2 of the License, or
15 (at your option) any later version.
17 This program is distributed in the hope that it will be useful,
18 but WITHOUT ANY WARRANTY; without even the implied warranty of
19 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 GNU General Public License for more details.
22 You should have received a copy of the GNU General Public License
23 along with this program; if not, write to the Free Software
24 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
27 #include "includes.h"
29 /* Shutdown a server */
31 NTSTATUS cli_shutdown_init(struct cli_state * cli, TALLOC_CTX *mem_ctx,
32 const char *msg, uint32 timeout, BOOL do_reboot,
33 BOOL force)
35 prs_struct qbuf;
36 prs_struct rbuf;
37 SHUTDOWN_Q_INIT q_s;
38 SHUTDOWN_R_INIT r_s;
39 WERROR result = WERR_GENERAL_FAILURE;
41 if (msg == NULL)
42 return NT_STATUS_INVALID_PARAMETER;
44 ZERO_STRUCT (q_s);
45 ZERO_STRUCT (r_s);
47 prs_init(&qbuf , MAX_PDU_FRAG_LEN, mem_ctx, MARSHALL);
48 prs_init(&rbuf, 0, mem_ctx, UNMARSHALL);
50 /* Marshall data and send request */
52 init_shutdown_q_init(&q_s, msg, timeout, do_reboot, force);
54 if (!shutdown_io_q_init("", &q_s, &qbuf, 0) ||
55 !rpc_api_pipe_req(cli, PI_SHUTDOWN, SHUTDOWN_INIT, &qbuf, &rbuf))
56 goto done;
58 /* Unmarshall response */
60 if(shutdown_io_r_init("", &r_s, &rbuf, 0))
61 result = r_s.status;
63 done:
64 prs_mem_free(&rbuf);
65 prs_mem_free(&qbuf);
67 return werror_to_ntstatus(result);
70 /* Shutdown a server */
72 NTSTATUS cli_shutdown_init_ex(struct cli_state * cli, TALLOC_CTX *mem_ctx,
73 const char *msg, uint32 timeout, BOOL do_reboot,
74 BOOL force, uint32 reason)
76 prs_struct qbuf;
77 prs_struct rbuf;
78 SHUTDOWN_Q_INIT_EX q_s;
79 SHUTDOWN_R_INIT_EX r_s;
80 WERROR result = WERR_GENERAL_FAILURE;
82 if (msg == NULL)
83 return NT_STATUS_INVALID_PARAMETER;
85 ZERO_STRUCT (q_s);
86 ZERO_STRUCT (r_s);
88 prs_init(&qbuf , MAX_PDU_FRAG_LEN, mem_ctx, MARSHALL);
89 prs_init(&rbuf, 0, mem_ctx, UNMARSHALL);
91 /* Marshall data and send request */
93 init_shutdown_q_init_ex(&q_s, msg, timeout, do_reboot, force, reason);
95 if (!shutdown_io_q_init_ex("", &q_s, &qbuf, 0) ||
96 !rpc_api_pipe_req(cli, PI_SHUTDOWN, SHUTDOWN_INIT_EX, &qbuf, &rbuf))
97 goto done;
99 /* Unmarshall response */
101 if(shutdown_io_r_init_ex("", &r_s, &rbuf, 0))
102 result = r_s.status;
104 done:
105 prs_mem_free(&rbuf);
106 prs_mem_free(&qbuf);
108 return werror_to_ntstatus(result);
112 /* Abort a server shutdown */
114 NTSTATUS cli_shutdown_abort(struct cli_state * cli, TALLOC_CTX *mem_ctx)
116 prs_struct rbuf;
117 prs_struct qbuf;
118 SHUTDOWN_Q_ABORT q_s;
119 SHUTDOWN_R_ABORT r_s;
120 WERROR result = WERR_GENERAL_FAILURE;
122 ZERO_STRUCT (q_s);
123 ZERO_STRUCT (r_s);
125 prs_init(&qbuf , MAX_PDU_FRAG_LEN, mem_ctx, MARSHALL);
126 prs_init(&rbuf, 0, mem_ctx, UNMARSHALL);
128 /* Marshall data and send request */
130 init_shutdown_q_abort(&q_s);
132 if (!shutdown_io_q_abort("", &q_s, &qbuf, 0) ||
133 !rpc_api_pipe_req(cli, PI_SHUTDOWN, SHUTDOWN_ABORT, &qbuf, &rbuf))
134 goto done;
136 /* Unmarshall response */
138 if (shutdown_io_r_abort("", &r_s, &rbuf, 0))
139 result = r_s.status;
141 done:
142 prs_mem_free(&rbuf);
143 prs_mem_free(&qbuf );
145 return werror_to_ntstatus(result);