Initial import
[samba] / source / rpc_parse / parse_shutdown.c
1 /*
2  *  Unix SMB/CIFS implementation.
3  *  RPC Pipe client / server routines
4  *  Copyright (C) Jim McDonough (jmcd@us.ibm.com)   2003.
5  *  Copyright (C) Gerald (Jerry) Carter             2002-2005.
6  *  
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 2 of the License, or
10  *  (at your option) any later version.
11  *  
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.
16  *  
17  *  You should have received a copy of the GNU General Public License
18  *  along with this program; if not, write to the Free Software
19  *  Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
20  */
21
22 #include "includes.h"
23
24 #undef DBGC_CLASS
25 #define DBGC_CLASS DBGC_RPC_PARSE
26
27 /*******************************************************************
28 Inits a structure.
29 ********************************************************************/
30
31 void init_shutdown_q_init(SHUTDOWN_Q_INIT *q_s, const char *msg,
32                         uint32 timeout, BOOL do_reboot, BOOL force)
33 {
34         q_s->server = TALLOC_P( get_talloc_ctx(), uint16 );
35         *q_s->server = 0x1;
36
37         q_s->message = TALLOC_ZERO_P( get_talloc_ctx(), UNISTR4 );
38
39         if ( msg && *msg ) {
40                 init_unistr4( q_s->message, msg, UNI_FLAGS_NONE );
41
42                 /* Win2000 is apparently very sensitive to these lengths */
43                 /* do a special case here */
44
45                 q_s->message->string->uni_max_len++;
46                 q_s->message->size += 2;
47         }
48
49         q_s->timeout = timeout;
50
51         q_s->reboot = do_reboot ? 1 : 0;
52         q_s->force = force ? 1 : 0;
53 }
54
55 /*******************************************************************
56 ********************************************************************/
57
58 void init_shutdown_q_init_ex(SHUTDOWN_Q_INIT_EX * q_u_ex, const char *msg,
59                         uint32 timeout, BOOL do_reboot, BOOL force, uint32 reason)
60 {
61         SHUTDOWN_Q_INIT q_u;
62         
63         ZERO_STRUCT( q_u );
64         
65         init_shutdown_q_init( &q_u, msg, timeout, do_reboot, force );
66         
67         /* steal memory */
68         
69         q_u_ex->server  = q_u.server;
70         q_u_ex->message = q_u.message;
71         
72         q_u_ex->reboot  = q_u.reboot;
73         q_u_ex->force   = q_u.force;
74         
75         q_u_ex->reason = reason;
76 }
77
78 /*******************************************************************
79 reads or writes a structure.
80 ********************************************************************/
81
82 BOOL shutdown_io_q_init(const char *desc, SHUTDOWN_Q_INIT *q_s, prs_struct *ps,
83                         int depth)
84 {
85         if (q_s == NULL)
86                 return False;
87
88         prs_debug(ps, depth, desc, "shutdown_io_q_init");
89         depth++;
90
91         if (!prs_align(ps))
92                 return False;
93
94         if (!prs_pointer("server", ps, depth, (void**)&q_s->server, sizeof(uint16), (PRS_POINTER_CAST)prs_uint16))
95                 return False;
96         if (!prs_align(ps))
97                 return False;
98
99         if (!prs_pointer("message", ps, depth, (void**)&q_s->message, sizeof(UNISTR4), (PRS_POINTER_CAST)prs_unistr4))
100                 return False;
101
102         if (!prs_align(ps))
103                 return False;
104
105         if (!prs_uint32("timeout", ps, depth, &(q_s->timeout)))
106                 return False;
107
108         if (!prs_uint8("force  ", ps, depth, &(q_s->force)))
109                 return False;
110         if (!prs_uint8("reboot ", ps, depth, &(q_s->reboot)))
111                 return False;
112
113         return True;
114 }
115
116 /*******************************************************************
117 reads or writes a structure.
118 ********************************************************************/
119 BOOL shutdown_io_r_init(const char *desc, SHUTDOWN_R_INIT* r_s, prs_struct *ps,
120                         int depth)
121 {
122         if (r_s == NULL)
123                 return False;
124
125         prs_debug(ps, depth, desc, "shutdown_io_r_init");
126         depth++;
127
128         if(!prs_align(ps))
129                 return False;
130
131         if(!prs_werror("status", ps, depth, &r_s->status))
132                 return False;
133
134         return True;
135 }
136
137 /*******************************************************************
138 reads or writes a REG_Q_SHUTDOWN_EX structure.
139 ********************************************************************/
140
141 BOOL shutdown_io_q_init_ex(const char *desc, SHUTDOWN_Q_INIT_EX * q_s, prs_struct *ps,
142                        int depth)
143 {
144         if (q_s == NULL)
145                 return False;
146
147         prs_debug(ps, depth, desc, "shutdown_io_q_init_ex");
148         depth++;
149
150         if (!prs_align(ps))
151                 return False;
152
153         if (!prs_pointer("server", ps, depth, (void**)&q_s->server, sizeof(uint16), (PRS_POINTER_CAST)prs_uint16))
154                 return False;
155         if (!prs_align(ps))
156                 return False;
157
158         if (!prs_pointer("message", ps, depth, (void**)&q_s->message, sizeof(UNISTR4), (PRS_POINTER_CAST)prs_unistr4))
159                 return False;
160
161         if (!prs_align(ps))
162                 return False;
163
164         if (!prs_uint32("timeout", ps, depth, &(q_s->timeout)))
165                 return False;
166
167         if (!prs_uint8("force  ", ps, depth, &(q_s->force)))
168                 return False;
169         if (!prs_uint8("reboot ", ps, depth, &(q_s->reboot)))
170                 return False;
171
172         if (!prs_align(ps))
173                 return False;
174         if (!prs_uint32("reason", ps, depth, &(q_s->reason)))
175                 return False;
176
177
178         return True;
179 }
180
181 /*******************************************************************
182 reads or writes a REG_R_SHUTDOWN_EX structure.
183 ********************************************************************/
184 BOOL shutdown_io_r_init_ex(const char *desc, SHUTDOWN_R_INIT_EX * r_s, prs_struct *ps,
185                        int depth)
186 {
187         if (r_s == NULL)
188                 return False;
189
190         prs_debug(ps, depth, desc, "shutdown_io_r_init_ex");
191         depth++;
192
193         if(!prs_align(ps))
194                 return False;
195
196         if(!prs_werror("status", ps, depth, &r_s->status))
197                 return False;
198
199         return True;
200 }
201
202
203 /*******************************************************************
204 Inits a structure.
205 ********************************************************************/
206 void init_shutdown_q_abort(SHUTDOWN_Q_ABORT *q_s)
207 {
208         q_s->server = TALLOC_P( get_talloc_ctx(), uint16 );
209         *q_s->server = 0x1;
210 }
211
212 /*******************************************************************
213 reads or writes a structure.
214 ********************************************************************/
215 BOOL shutdown_io_q_abort(const char *desc, SHUTDOWN_Q_ABORT *q_s,
216                          prs_struct *ps, int depth)
217 {
218         if (q_s == NULL)
219                 return False;
220
221         prs_debug(ps, depth, desc, "shutdown_io_q_abort");
222         depth++;
223
224         if (!prs_align(ps))
225                 return False;
226
227         if (!prs_pointer("server", ps, depth, (void**)&q_s->server, sizeof(uint16), (PRS_POINTER_CAST)prs_uint16))
228                 return False;
229         if (!prs_align(ps))
230                 return False;
231
232         return True;
233 }
234
235 /*******************************************************************
236 reads or writes a structure.
237 ********************************************************************/
238 BOOL shutdown_io_r_abort(const char *desc, SHUTDOWN_R_ABORT *r_s,
239                          prs_struct *ps, int depth)
240 {
241         if (r_s == NULL)
242                 return False;
243
244         prs_debug(ps, depth, desc, "shutdown_io_r_abort");
245         depth++;
246
247         if (!prs_align(ps))
248                 return False;
249
250         if (!prs_werror("status", ps, depth, &r_s->status))
251                 return False;
252
253         return True;
254 }