c342f255a9fec0e829f6445adbdc29e73c8e16a4
[vlendec/samba-autobuild/.git] / source3 / rpc_client / cli_shutdown.c
1 /* 
2    Unix SMB/CIFS implementation.
3    RPC Pipe client
4  
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.
11    
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.
16    
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.
21    
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.
25 */
26
27 #include "includes.h"
28
29 /* Shutdown a server */
30
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)
34 {
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;
40
41         if (msg == NULL) 
42                 return NT_STATUS_INVALID_PARAMETER;
43
44         ZERO_STRUCT (q_s);
45         ZERO_STRUCT (r_s);
46
47         prs_init(&qbuf , MAX_PDU_FRAG_LEN, mem_ctx, MARSHALL);
48         prs_init(&rbuf, 0, mem_ctx, UNMARSHALL);
49
50         /* Marshall data and send request */
51
52         init_shutdown_q_init(&q_s, msg, timeout, do_reboot, force);
53
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;
57         
58         /* Unmarshall response */
59         
60         if(shutdown_io_r_init("", &r_s, &rbuf, 0))
61                 result = r_s.status;
62
63 done:
64         prs_mem_free(&rbuf);
65         prs_mem_free(&qbuf);
66
67         return werror_to_ntstatus(result);
68 }
69
70 /* Shutdown a server */
71
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)
75 {
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;
81
82         if (msg == NULL) 
83                 return NT_STATUS_INVALID_PARAMETER;
84
85         ZERO_STRUCT (q_s);
86         ZERO_STRUCT (r_s);
87
88         prs_init(&qbuf , MAX_PDU_FRAG_LEN, mem_ctx, MARSHALL);
89         prs_init(&rbuf, 0, mem_ctx, UNMARSHALL);
90
91         /* Marshall data and send request */
92
93         init_shutdown_q_init_ex(&q_s, msg, timeout, do_reboot, force, reason);
94
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;
98         
99         /* Unmarshall response */
100         
101         if(shutdown_io_r_init_ex("", &r_s, &rbuf, 0))
102                 result = r_s.status;
103
104 done:
105         prs_mem_free(&rbuf);
106         prs_mem_free(&qbuf);
107
108         return werror_to_ntstatus(result);
109 }
110
111
112 /* Abort a server shutdown */
113
114 NTSTATUS cli_shutdown_abort(struct cli_state * cli, TALLOC_CTX *mem_ctx)
115 {
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;
121
122         ZERO_STRUCT (q_s);
123         ZERO_STRUCT (r_s);
124
125         prs_init(&qbuf , MAX_PDU_FRAG_LEN, mem_ctx, MARSHALL);
126         prs_init(&rbuf, 0, mem_ctx, UNMARSHALL);
127         
128         /* Marshall data and send request */
129
130         init_shutdown_q_abort(&q_s);
131
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;
135         
136                 /* Unmarshall response */
137         
138         if (shutdown_io_r_abort("", &r_s, &rbuf, 0))
139                 result = r_s.status;
140
141 done:
142         prs_mem_free(&rbuf);
143         prs_mem_free(&qbuf );
144
145         return werror_to_ntstatus(result);
146 }