b88b3532ef7ec9429b40294c3aaaf3f5c6c4ab1d
[ira/wip.git] / source3 / libsmb / cli_reg.c
1 /* 
2    Unix SMB/Netbios implementation.
3    Version 2.2
4    RPC Pipe client
5  
6    Copyright (C) Andrew Tridgell              1992-1998,
7    Copyright (C) Luke Kenneth Casson Leighton 1996-1998,
8    Copyright (C) Paul Ashton                  1997-1998.
9    Copyright (C) Jeremy Allison                    1999.
10    Copyright (C) Simo Sorce                        2001
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 /* Opens a SMB connection to the WINREG pipe */
30
31 struct cli_state *cli_winreg_initialise(struct cli_state *cli, 
32                                         char *system_name,
33                                         struct ntuser_creds *creds)
34 {
35         return cli_pipe_initialise(cli, system_name, PIPE_WINREG, creds);
36 }
37
38 /* Shutdown a server */
39
40 NTSTATUS cli_reg_shutdown(struct cli_state * cli, TALLOC_CTX *mem_ctx,
41                           const char *msg, uint32 timeout, uint16 flags)
42 {
43         prs_struct qbuf;
44         prs_struct rbuf; 
45         REG_Q_SHUTDOWN q_s;
46         REG_R_SHUTDOWN r_s;
47         NTSTATUS result = NT_STATUS_UNSUCCESSFUL;
48
49         if (msg == NULL) return NT_STATUS_INVALID_PARAMETER;
50
51         ZERO_STRUCT (q_s);
52         ZERO_STRUCT (r_s);
53
54         prs_init(&qbuf , MAX_PDU_FRAG_LEN, mem_ctx, MARSHALL);
55         prs_init(&rbuf, 0, mem_ctx, UNMARSHALL);
56
57         /* Marshall data and send request */
58
59         init_reg_q_shutdown(&q_s, msg, timeout, flags);
60
61         if (!reg_io_q_shutdown("", &q_s, &qbuf, 0) ||
62             !rpc_api_pipe_req(cli, REG_SHUTDOWN, &qbuf, &rbuf))
63                 goto done;
64         
65         /* Unmarshall response */
66         
67         if(reg_io_r_shutdown("", &r_s, &rbuf, 0))
68                 result = r_s.status;
69
70 done:
71         prs_mem_free(&rbuf);
72         prs_mem_free(&qbuf);
73
74         return result;
75 }
76
77
78 /* Abort a server shutdown */
79
80 NTSTATUS cli_reg_abort_shutdown(struct cli_state * cli, TALLOC_CTX *mem_ctx)
81 {
82         prs_struct rbuf;
83         prs_struct qbuf; 
84         REG_Q_ABORT_SHUTDOWN q_s;
85         REG_R_ABORT_SHUTDOWN r_s;
86         NTSTATUS result = NT_STATUS_UNSUCCESSFUL;
87
88         ZERO_STRUCT (q_s);
89         ZERO_STRUCT (r_s);
90
91         prs_init(&qbuf , MAX_PDU_FRAG_LEN, mem_ctx, MARSHALL);
92         prs_init(&rbuf, 0, mem_ctx, UNMARSHALL);
93         
94         /* Marshall data and send request */
95
96         init_reg_q_abort_shutdown(&q_s);
97
98         if (!reg_io_q_abort_shutdown("", &q_s, &qbuf, 0) ||
99             !rpc_api_pipe_req(cli, REG_ABORT_SHUTDOWN, &qbuf, &rbuf))
100                 goto done;
101         
102                 /* Unmarshall response */
103         
104         if (reg_io_r_abort_shutdown("", &r_s, &rbuf, 0))
105                 result = r_s.status;
106
107 done:
108         prs_mem_free(&rbuf);
109         prs_mem_free(&qbuf );
110
111         return result;
112 }