adding error checking in parsing code
[samba.git] / source / include / rpc_misc.h
1 /* 
2    Unix SMB/Netbios implementation.
3    Version 1.9.
4    SMB parameters and setup
5    Copyright (C) Andrew Tridgell 1992-1997
6    Copyright (C) Luke Kenneth Casson Leighton 1996-1997
7    Copyright (C) Paul Ashton 1997
8    
9    This program is free software; you can redistribute it and/or modify
10    it under the terms of the GNU General Public License as published by
11    the Free Software Foundation; either version 2 of the License, or
12    (at your option) any later version.
13    
14    This program is distributed in the hope that it will be useful,
15    but WITHOUT ANY WARRANTY; without even the implied warranty of
16    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17    GNU General Public License for more details.
18    
19    You should have received a copy of the GNU General Public License
20    along with this program; if not, write to the Free Software
21    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
22 */
23
24 #ifndef _RPC_MISC_H /* _RPC_MISC_H */
25 #define _RPC_MISC_H 
26
27 /*
28  * macros to wrap prs_xxxx routines.
29  */
30 #define prs_uint8(name, ps, depth, data8) \
31         if (!_prs_uint8(name, ps, depth, data8)) \
32         {\
33                 ps->offset = 0;\
34                 return False;\
35         }
36 #define prs_uint16(name, ps, depth, data16) \
37         if (!_prs_uint16(name, ps, depth, data16)) \
38         {\
39                 ps->offset = 0;\
40                 return False;\
41         }
42 #define prs_hash1(x_ps, x_offset, x_sess_key) \
43         if (!_prs_hash1(x_ps, x_offset, x_sess_key)) \
44         {\
45                 x_ps->offset = 0;\
46                 return False;\
47         }
48 #define prs_uint32(name, ps, depth, data32) \
49         if (!_prs_uint32(name, ps, depth, data32)) \
50         {\
51                 ps->offset = 0;\
52                 return False;\
53         }
54 #define prs_uint8s(charmode, name, ps, depth, data8s, len) \
55         if (!_prs_uint8s(charmode, name, ps, depth, data8s, len)) \
56         {\
57                 ps->offset = 0;\
58                 return False;\
59         }
60 #define prs_uint16s(charmode, name, ps, depth, data16s, len) \
61         if (!_prs_uint16s(charmode, name, ps, depth, data16s, len)) \
62         {\
63                 ps->offset = 0;\
64                 return False;\
65         }
66 #define prs_uint32s(charmode, name, ps, depth, data32s, len) \
67         if (!_prs_uint32s(charmode, name, ps, depth, data32s, len)) \
68         {\
69                 ps->offset = 0;\
70                 return False;\
71         }
72 #define prs_buffer2(charmode, name, ps, depth, str) \
73         if (!_prs_buffer2(charmode, name, ps, depth, str)) \
74         {\
75                 ps->offset = 0;\
76                 return False;\
77         }
78 #define prs_string2(charmode, name, ps, depth, str) \
79         if (!_prs_string2(charmode, name, ps, depth, str)) \
80         {\
81                 ps->offset = 0;\
82                 return False;\
83         }
84 #define prs_unistr2(charmode, name, ps, depth, str) \
85         if (!_prs_unistr2(charmode, name, ps, depth, str)) \
86         {\
87                 ps->offset = 0;\
88                 return False;\
89         }
90 #define prs_unistr3(charmode, name, str, ps, depth) \
91         if (!_prs_unistr3(charmode, name, str, ps, depth)) \
92         {\
93                 ps->offset = 0;\
94                 return False;\
95         }
96 #define prs_unistr(name, ps, depth, str) \
97         if (!_prs_unistr(name, ps, depth, str)) \
98         {\
99                 ps->offset = 0;\
100                 return False;\
101         }
102 #define prs_string(name, ps, depth, str, len, max_buf_size) \
103         if (!_prs_string(name, ps, depth, str, len, max_buf_size)) \
104         {\
105                 ps->offset = 0;\
106                 return False;\
107         }
108 #define prs_uint16_pre(x_name, x_ps, x_depth, x_data16, x_offset) \
109         if (!_prs_uint16_pre(x_name, x_ps, x_depth, x_data16, x_offset)) \
110         {\
111                 x_ps->offset = 0;\
112                 return False;\
113         }
114 #define prs_uint16_post(name, ps, depth, data16, ptr_uint16, data_size) \
115         if (!_prs_uint16_post(name, ps, depth, data16, ptr_uint16, data_size)) \
116         {\
117                 ps->offset = 0;\
118                 return False;\
119         }
120 #define prs_uint32_pre(x_name, x_ps, x_depth, x_data32, x_offset) \
121         if (!_prs_uint32_pre(x_name, x_ps, x_depth, x_data32, x_offset)) \
122         {\
123                 x_ps->offset = 0;\
124                 return False;\
125         }
126 #define prs_uint32_post(name, ps, depth, data32, ptr_uint32, data_size) \
127         if (!_prs_uint32_post(name, ps, depth, data32, ptr_uint32, data_size)) \
128         {\
129                 ps->offset = 0;\
130                 return False;\
131         }
132
133 #include "rpc_dce.h"
134
135 /* well-known RIDs - Relative IDs */
136
137 /* RIDs - Well-known users ... */
138 #define DOMAIN_USER_RID_ADMIN          (0x000001F4L)
139 #define DOMAIN_USER_RID_GUEST          (0x000001F5L)
140
141 /* RIDs - well-known groups ... */
142 #define DOMAIN_GROUP_RID_ADMINS        (0x00000200L)
143 #define DOMAIN_GROUP_RID_USERS         (0x00000201L)
144 #define DOMAIN_GROUP_RID_GUESTS        (0x00000202L)
145
146 /* RIDs - well-known aliases ... */
147 #define BUILTIN_ALIAS_RID_ADMINS        (0x00000220L)
148 #define BUILTIN_ALIAS_RID_USERS         (0x00000221L)
149 #define BUILTIN_ALIAS_RID_GUESTS        (0x00000222L)
150 #define BUILTIN_ALIAS_RID_POWER_USERS   (0x00000223L)
151 #define BUILTIN_ALIAS_RID_ACCOUNT_OPS   (0x00000224L)
152 #define BUILTIN_ALIAS_RID_SYSTEM_OPS    (0x00000225L)
153 #define BUILTIN_ALIAS_RID_PRINT_OPS     (0x00000226L)
154 #define BUILTIN_ALIAS_RID_BACKUP_OPS    (0x00000227L)
155 #define BUILTIN_ALIAS_RID_REPLICATOR    (0x00000228L)
156
157 /*
158  * Masks for mappings between unix uid and gid types and
159  * NT RIDS.
160  */
161
162 /* Take the bottom bits. */
163 #define RID_TYPE_MASK 2
164 #define RID_MULTIPLIER 4
165
166 /* The three common types. */
167 #define RID_TYPE_USER    0
168 #define RID_TYPE_GROUP   1
169 #define RID_TYPE_ALIAS   2
170
171 /* BIGINT - NT-style 64-bit integer */
172 typedef struct bigint_info
173 {
174         uint32 low;
175         uint32 high;
176
177 } BIGINT;
178
179
180 /* ENUM_HND */
181 typedef struct enum_hnd_info
182 {
183         uint32 ptr_hnd;          /* pointer to enumeration handle */
184         uint32 handle;           /* enumeration handle */
185
186 } ENUM_HND;
187
188 /* LOOKUP_LEVEL - switch value */
189 typedef struct lookup_level_info
190 {
191   uint16 value;
192
193 } LOOKUP_LEVEL;
194
195 /* DOM_SID2 - security id */
196 typedef struct sid_info_2
197 {
198         uint32 num_auths; /* length, bytes, including length of len :-) */
199
200         DOM_SID sid;
201
202 } DOM_SID2;
203
204 /* STRHDR - string header */
205 typedef struct header_info
206 {
207   uint16 str_str_len;
208   uint16 str_max_len;
209   uint32 buffer; /* non-zero */
210
211 } STRHDR;
212
213 /* STRHDR2 - string header, 32-bit lengths */
214 typedef struct header2_info
215 {
216   uint32 str_str_len;
217   uint32 str_max_len;
218   uint32 buffer;
219
220 } STRHDR2;
221
222 /* UNIHDR - unicode string header */
223 typedef struct unihdr_info
224 {
225   uint16 uni_str_len;
226   uint16 uni_max_len;
227   uint32 buffer; /* usually has a value of 4 */
228
229 } UNIHDR;
230
231 /* UNIHDR2 - unicode string header and undocumented buffer */
232 typedef struct unihdr2_info
233 {
234   UNIHDR unihdr;
235   uint32 buffer; /* 32 bit buffer pointer */
236
237 } UNIHDR2;
238
239 /* clueless as to what maximum length should be */
240 #define MAX_UNISTRLEN 256
241 #define MAX_STRINGLEN 256
242 #define MAX_BUFFERLEN 512
243
244 /* UNISTR - unicode string size and buffer */
245 typedef struct unistr_info
246 {
247   uint16 buffer[MAX_UNISTRLEN]; /* unicode characters. ***MUST*** be null-terminated */
248
249 } UNISTR;
250
251 /* BUFHDR - buffer header */
252 typedef struct bufhdr_info
253 {
254   uint32 buf_max_len;
255   uint32 buf_len;
256
257 } BUFHDR;
258
259 /* BUFHDR2 - another buffer header, with info level */
260 typedef struct bufhdr2_info
261 {
262   uint32 info_level;
263   uint32 length; /* uint8 chars */
264   uint32 buffer;
265
266 } BUFHDR2;
267
268 /* BUFFER2 - unicode string, size (in uint8 ascii chars) and buffer */
269 /* pathetic.  some stupid team of \PIPE\winreg writers got the concept */
270 /* of a unicode string different from the other \PIPE\ writers */
271 typedef struct buffer2_info
272 {
273   uint32 buf_max_len;
274   uint32 undoc;
275   uint32 buf_len;
276   uint8 buffer[MAX_UNISTRLEN];
277
278 } BUFFER2;
279
280 /* BUFFER3 */
281 typedef struct buffer3_info
282 {
283   uint32 buf_max_len;
284   uint8  buffer[MAX_BUFFERLEN]; /* data */
285   uint32 buf_len;
286
287 } BUFFER3;
288
289 /* BUFFER4 - simple length and buffer */
290 typedef struct buffer4_info
291 {
292   uint32 buf_len;
293   uint8  buffer[MAX_BUFFERLEN];
294
295 } BUFFER4;
296
297 /* BUFFER5 */
298 typedef struct buffer5_info
299 {
300   uint32 buf_len;
301   uint16 *buffer; /* data */
302 } BUFFER5;
303
304 /* UNISTR2 - unicode string size (in uint16 unicode chars) and buffer */
305 typedef struct unistr2_info
306 {
307   uint32 uni_max_len;
308   uint32 undoc;
309   uint32 uni_str_len;
310   uint16 buffer[MAX_UNISTRLEN]; /* unicode characters. **NOT** necessarily null-terminated */
311
312 } UNISTR2;
313
314 /* STRING2 - string size (in uint8 chars) and buffer */
315 typedef struct string2_info
316 {
317   uint32 str_max_len;
318   uint32 undoc;
319   uint32 str_str_len;
320   uint8  buffer[MAX_STRINGLEN]; /* uint8 characters. **NOT** necessarily null-terminated */
321
322 } STRING2;
323
324 /* UNISTR3 - XXXX not sure about this structure */
325 typedef struct unistr3_info
326 {
327         uint32 uni_str_len;
328         UNISTR str;
329
330 } UNISTR3;
331
332
333 /* DOM_RID2 - domain RID structure for ntlsa pipe */
334 typedef struct domrid2_info
335 {
336         uint8 type; /* value is SID_NAME_USE enum */
337         uint32 rid;
338         uint32 rid_idx; /* referenced domain index */
339
340 } DOM_RID2;
341
342 /* DOM_RID3 - domain RID structure for samr pipe */
343 typedef struct domrid3_info
344 {
345         uint32 rid;        /* domain-relative (to a SID) id */
346         uint32 type1;      /* value is 0x1 */
347         uint32 ptr_type;   /* undocumented pointer */
348         uint32 type2;      /* value is 0x1 */
349         uint32 unk; /* value is 0x2 */
350
351 } DOM_RID3;
352
353 /* DOM_CLNT_SRV - client / server names */
354 typedef struct clnt_srv_info
355 {
356   uint32  undoc_buffer; /* undocumented 32 bit buffer pointer */
357   UNISTR2 uni_logon_srv; /* logon server name */
358   uint32  undoc_buffer2; /* undocumented 32 bit buffer pointer */
359   UNISTR2 uni_comp_name; /* client machine name */
360
361 } DOM_CLNT_SRV;
362
363 /* DOM_LOG_INFO - login info */
364 typedef struct log_info
365 {
366   uint32  undoc_buffer; /* undocumented 32 bit buffer pointer */
367   UNISTR2 uni_logon_srv; /* logon server name */
368   UNISTR2 uni_acct_name; /* account name */
369   uint16  sec_chan;      /* secure channel type */
370   UNISTR2 uni_comp_name; /* client machine name */
371
372 } DOM_LOG_INFO;
373
374 /* DOM_CLNT_INFO - client info */
375 typedef struct clnt_info
376 {
377   DOM_LOG_INFO login;
378   DOM_CRED     cred;
379
380 } DOM_CLNT_INFO;
381
382 /* DOM_CLNT_INFO2 - client info */
383 typedef struct clnt_info2
384 {
385   DOM_CLNT_SRV login;
386   uint32        ptr_cred;
387   DOM_CRED      cred;
388
389 } DOM_CLNT_INFO2;
390
391 /* DOM_LOGON_ID - logon id */
392 typedef struct logon_info
393 {
394   uint32 low;
395   uint32 high;
396
397 } DOM_LOGON_ID;
398
399 /* OWF INFO */
400 typedef struct owf_info
401 {
402   uint8 data[16];
403
404 } OWF_INFO;
405
406
407 /* DOM_GID - group id + user attributes */
408 typedef struct gid_info
409 {
410   uint32 g_rid;  /* a group RID */
411   uint32 attr;
412
413 } DOM_GID;
414
415 #define POL_HND_SIZE 20
416
417 /* POLICY_HND */
418 typedef struct lsa_policy_info
419 {
420   uint8 data[POL_HND_SIZE]; /* policy handle */
421
422 } POLICY_HND;
423
424 #endif /* _RPC_MISC_H */
425