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
31NTSTATUS 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	NTSTATUS result = NT_STATUS_UNSUCCESSFUL;
40
41	if (msg == NULL) return NT_STATUS_INVALID_PARAMETER;
42
43	ZERO_STRUCT (q_s);
44	ZERO_STRUCT (r_s);
45
46	prs_init(&qbuf , MAX_PDU_FRAG_LEN, mem_ctx, MARSHALL);
47	prs_init(&rbuf, 0, mem_ctx, UNMARSHALL);
48
49	/* Marshall data and send request */
50
51	init_shutdown_q_init(&q_s, msg, timeout, do_reboot, force);
52
53	if (!shutdown_io_q_init("", &q_s, &qbuf, 0) ||
54	    !rpc_api_pipe_req(cli, PI_SHUTDOWN, SHUTDOWN_INIT, &qbuf, &rbuf))
55		goto done;
56
57	/* Unmarshall response */
58
59	if(shutdown_io_r_init("", &r_s, &rbuf, 0))
60		result = r_s.status;
61
62done:
63	prs_mem_free(&rbuf);
64	prs_mem_free(&qbuf);
65
66	return result;
67}
68
69
70/* Abort a server shutdown */
71
72NTSTATUS cli_shutdown_abort(struct cli_state * cli, TALLOC_CTX *mem_ctx)
73{
74	prs_struct rbuf;
75	prs_struct qbuf;
76	SHUTDOWN_Q_ABORT q_s;
77	SHUTDOWN_R_ABORT r_s;
78	NTSTATUS result = NT_STATUS_UNSUCCESSFUL;
79
80	ZERO_STRUCT (q_s);
81	ZERO_STRUCT (r_s);
82
83	prs_init(&qbuf , MAX_PDU_FRAG_LEN, mem_ctx, MARSHALL);
84	prs_init(&rbuf, 0, mem_ctx, UNMARSHALL);
85
86	/* Marshall data and send request */
87
88	init_shutdown_q_abort(&q_s);
89
90	if (!shutdown_io_q_abort("", &q_s, &qbuf, 0) ||
91	    !rpc_api_pipe_req(cli, PI_SHUTDOWN, SHUTDOWN_ABORT, &qbuf, &rbuf))
92	    	goto done;
93
94		/* Unmarshall response */
95
96	if (shutdown_io_r_abort("", &r_s, &rbuf, 0))
97		result = r_s.status;
98
99done:
100	prs_mem_free(&rbuf);
101	prs_mem_free(&qbuf );
102
103	return result;
104}
105