r6014: rather large change set....
[ira/wip.git] / source3 / include / rpc_misc.h
1 /* 
2    Unix SMB/CIFS implementation.
3
4    Copyright (C) Andrew Tridgell 1992-1997
5    Copyright (C) Luke Kenneth Casson Leighton 1996-1997
6    Copyright (C) Paul Ashton 1997
7    
8    This program is free software; you can redistribute it and/or modify
9    it under the terms of the GNU General Public License as published by
10    the Free Software Foundation; either version 2 of the License, or
11    (at your option) any later version.
12    
13    This program is distributed in the hope that it will be useful,
14    but WITHOUT ANY WARRANTY; without even the implied warranty of
15    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16    GNU General Public License for more details.
17    
18    You should have received a copy of the GNU General Public License
19    along with this program; if not, write to the Free Software
20    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
21 */
22
23 #include "ntdomain.h"
24 #include "rpc_dce.h"
25
26 #ifndef _RPC_MISC_H /* _RPC_MISC_H */
27 #define _RPC_MISC_H 
28
29 #define SMB_RPC_INTERFACE_VERSION 1
30
31 #define PRS_POINTER_CAST BOOL (*)(const char*, prs_struct*, int, void*)
32
33
34 /* well-known RIDs - Relative IDs */
35
36 /* RIDs - Well-known users ... */
37 #define DOMAIN_USER_RID_ADMIN          (0x000001F4L)
38 #define DOMAIN_USER_RID_GUEST          (0x000001F5L)
39 #define DOMAIN_USER_RID_KRBTGT         (0x000001F6L)
40
41 /* RIDs - well-known groups ... */
42 #define DOMAIN_GROUP_RID_ADMINS        (0x00000200L)
43 #define DOMAIN_GROUP_RID_USERS         (0x00000201L)
44 #define DOMAIN_GROUP_RID_GUESTS        (0x00000202L)
45 #define DOMAIN_GROUP_RID_COMPUTERS     (0x00000203L)
46
47 #define DOMAIN_GROUP_RID_CONTROLLERS   (0x00000204L)
48 #define DOMAIN_GROUP_RID_CERT_ADMINS   (0x00000205L)
49 #define DOMAIN_GROUP_RID_SCHEMA_ADMINS (0x00000206L)
50 #define DOMAIN_GROUP_RID_ENTERPRISE_ADMINS (0x00000207L)
51
52 /* is the following the right number? I bet it is  --simo
53 #define DOMAIN_GROUP_RID_POLICY_ADMINS (0x00000208L)
54 */
55
56 /* RIDs - well-known aliases ... */
57 #define BUILTIN_ALIAS_RID_ADMINS        (0x00000220L)
58 #define BUILTIN_ALIAS_RID_USERS         (0x00000221L)
59 #define BUILTIN_ALIAS_RID_GUESTS        (0x00000222L)
60 #define BUILTIN_ALIAS_RID_POWER_USERS   (0x00000223L)
61
62 #define BUILTIN_ALIAS_RID_ACCOUNT_OPS   (0x00000224L)
63 #define BUILTIN_ALIAS_RID_SYSTEM_OPS    (0x00000225L)
64 #define BUILTIN_ALIAS_RID_PRINT_OPS     (0x00000226L)
65 #define BUILTIN_ALIAS_RID_BACKUP_OPS    (0x00000227L)
66
67 #define BUILTIN_ALIAS_RID_REPLICATOR    (0x00000228L)
68 #define BUILTIN_ALIAS_RID_RAS_SERVERS   (0x00000229L)
69 #define BUILTIN_ALIAS_RID_PRE_2K_ACCESS (0x0000022aL)
70
71 /*
72  * Masks for mappings between unix uid and gid types and
73  * NT RIDS.
74  */
75
76
77 #define BASE_RID (0x000003E8L)
78
79 /* Take the bottom bit. */
80 #define RID_TYPE_MASK 1
81 #define RID_MULTIPLIER 2
82
83 /* The two common types. */
84 #define USER_RID_TYPE 0
85 #define GROUP_RID_TYPE 1
86
87 /* ENUM_HND */
88 typedef struct enum_hnd_info
89 {
90         uint32 ptr_hnd;          /* pointer to enumeration handle */
91         uint32 handle;           /* enumeration handle */
92 } ENUM_HND;
93
94 /* DOM_SID2 - security id */
95 typedef struct sid_info_2
96 {
97         uint32 num_auths; /* length, bytes, including length of len :-) */
98         DOM_SID sid;
99 } DOM_SID2;
100
101 /* STRHDR - string header */
102 typedef struct header_info
103 {
104         uint16 str_str_len;
105         uint16 str_max_len;
106         uint32 buffer; /* non-zero */
107 } STRHDR;
108
109 /* UNIHDR - unicode string header */
110 typedef struct unihdr_info
111 {
112         uint16 uni_str_len;
113         uint16 uni_max_len;
114         uint32 buffer; /* usually has a value of 4 */
115 } UNIHDR;
116
117 /* UNIHDR2 - unicode string header and undocumented buffer */
118 typedef struct unihdr2_info
119 {
120         UNIHDR unihdr;
121         uint32 buffer; /* 32 bit buffer pointer */
122 } UNIHDR2;
123
124 /* UNISTR - unicode string size and buffer */
125 typedef struct unistr_info
126 {
127         /* unicode characters. ***MUST*** be little-endian. ***MUST*** be null-terminated */
128         uint16 *buffer;
129 } UNISTR;
130
131 /* BUFHDR - buffer header */
132 typedef struct bufhdr_info
133 {
134         uint32 buf_max_len;
135         uint32 buf_len;
136 } BUFHDR;
137
138 /* 
139    OLD COMMENT: 
140       BUFFER2 - unicode string, size (in uint8 ascii chars) and buffer 
141       pathetic.  some stupid team of \PIPE\winreg writers got the concept
142       of a unicode string different from the other \PIPE\ writers
143
144    NEW COMMENT: 
145       buffer used by \winreg\ calls to fill in arbitrary REG_XXX values.
146       It *may* look like a UNISTR2 but it is *not*.  This is not a goof
147       by the winreg developers.  It is a generic buffer 
148 */
149
150 typedef struct {
151         uint32 buf_max_len;
152         uint32 offset;
153         uint32 buf_len;
154         /* unicode characters. ***MUST*** be little-endian. **NOT** necessarily null-terminated */
155         uint16 *buffer;
156 } REGVAL_BUFFER;
157
158 /* BUFFER3 */
159 typedef struct buffer3_info
160 {
161         uint32 buf_max_len;
162         uint8  *buffer; /* Data */
163         uint32 buf_len;
164 } BUFFER3;
165
166 /* BUFFER5 */
167 typedef struct buffer5_info
168 {
169         uint32 buf_len;
170         uint16 *buffer; /* data */
171 } BUFFER5;
172
173 /* UNISTR2 - unicode string size (in uint16 unicode chars) and buffer */
174 typedef struct unistr2_info
175 {
176         uint32 uni_max_len;
177         uint32 offset;
178         uint32 uni_str_len;
179         /* unicode characters. ***MUST*** be little-endian. 
180                 **must** be null-terminated and the uni_str_len should include
181                 the NULL character */
182         uint16 *buffer;
183 } UNISTR2;
184
185 /* UNIHDR + UNISTR2* */
186 typedef struct {
187         uint16 length;  /* number of bytes not counting NULL terminatation */
188         uint16 size;    /* number of bytes including NULL terminatation */
189         UNISTR2 *string;
190 } UNISTR4;
191
192 /* STRING2 - string size (in uint8 chars) and buffer */
193 typedef struct string2_info
194 {
195         uint32 str_max_len;
196         uint32 offset;
197         uint32 str_str_len;
198         uint8  *buffer; /* uint8 characters. **NOT** necessarily null-terminated */
199 } STRING2;
200
201 /* UNISTR3 - XXXX not sure about this structure */
202 typedef struct unistr3_info
203 {
204         uint32 uni_str_len;
205         UNISTR str;
206
207 } UNISTR3;
208
209 /* an element in a unicode string array */
210 typedef struct
211 {
212         uint16 length;
213         uint16 size;
214         uint32 ref_id;
215         UNISTR2 string;
216 } UNISTR2_ARRAY_EL;
217
218 /* an array of unicode strings */
219 typedef struct 
220 {
221         uint32 ref_id;
222         uint32 count;
223         UNISTR2_ARRAY_EL *strings;
224 } UNISTR2_ARRAY;
225
226
227 /* an element in a sid array */
228 typedef struct
229 {
230         uint32 ref_id;
231         DOM_SID2 sid;
232 } SID_ARRAY_EL;
233
234 /* an array of sids */
235 typedef struct 
236 {
237         uint32 ref_id;
238         uint32 count;
239         SID_ARRAY_EL *sids;
240 } SID_ARRAY;
241
242 /* DOM_RID2 - domain RID structure for ntlsa pipe */
243 typedef struct domrid2_info
244 {
245         uint8 type; /* value is SID_NAME_USE enum */
246         uint32 rid;
247         uint32 rid_idx; /* referenced domain index */
248
249 } DOM_RID2;
250
251 /* DOM_RID3 - domain RID structure for samr pipe */
252 typedef struct domrid3_info
253 {
254         uint32 rid;        /* domain-relative (to a SID) id */
255         uint32 type1;      /* value is 0x1 */
256         uint32 ptr_type;   /* undocumented pointer */
257         uint32 type2;      /* value is 0x1 */
258         uint32 unk; /* value is 0x2 */
259
260 } DOM_RID3;
261
262 /* DOM_RID4 - rid + user attributes */
263 typedef struct domrid4_info
264 {
265         uint32 unknown;
266         uint16 attr;
267         uint32 rid;  /* user RID */
268 } DOM_RID4;
269
270 /* DOM_CLNT_SRV - client / server names */
271 typedef struct clnt_srv_info
272 {
273         uint32  undoc_buffer; /* undocumented 32 bit buffer pointer */
274         UNISTR2 uni_logon_srv; /* logon server name */
275         uint32  undoc_buffer2; /* undocumented 32 bit buffer pointer */
276         UNISTR2 uni_comp_name; /* client machine name */
277 } DOM_CLNT_SRV;
278
279 /* DOM_LOG_INFO - login info */
280 typedef struct log_info
281 {
282         uint32  undoc_buffer; /* undocumented 32 bit buffer pointer */
283         UNISTR2 uni_logon_srv; /* logon server name */
284         UNISTR2 uni_acct_name; /* account name */
285         uint16  sec_chan;      /* secure channel type */
286         UNISTR2 uni_comp_name; /* client machine name */
287 } DOM_LOG_INFO;
288
289 /* DOM_CHAL - challenge info */
290 typedef struct chal_info
291 {
292         uchar data[8]; /* credentials */
293 } DOM_CHAL;
294  
295 /* DOM_CREDs - timestamped client or server credentials */
296 typedef struct cred_info
297 {
298         DOM_CHAL challenge; /* credentials */
299         UTIME timestamp;    /* credential time-stamp */
300 } DOM_CRED;
301
302 /* DOM_CLNT_INFO - client info */
303 typedef struct clnt_info
304 {
305         DOM_LOG_INFO login;
306         DOM_CRED     cred;
307 } DOM_CLNT_INFO;
308
309 /* DOM_CLNT_INFO2 - client info */
310 typedef struct clnt_info2
311 {
312         DOM_CLNT_SRV login;
313         uint32        ptr_cred;
314         DOM_CRED      cred;
315 } DOM_CLNT_INFO2;
316
317 /* DOM_LOGON_ID - logon id */
318 typedef struct logon_info
319 {
320         uint32 low;
321         uint32 high;
322 } DOM_LOGON_ID;
323
324 /* OWF INFO */
325 typedef struct owf_info
326 {
327         uint8 data[16];
328 } OWF_INFO;
329
330
331 /* DOM_GID - group id + user attributes */
332 typedef struct gid_info
333 {
334         uint32 g_rid;  /* a group RID */
335         uint32 attr;
336 } DOM_GID;
337
338 /* POLICY_HND */
339 typedef struct lsa_policy_info
340 {
341         uint32 data1;
342         uint32 data2;
343         uint16 data3;
344         uint16 data4;
345         uint8 data5[8];
346 #ifdef __INSURE__
347
348         /* To prevent the leakage of policy handles mallocate a bit of
349            memory when a policy handle is created and free it when the
350            handle is closed.  This should cause Insure to flag an error
351            when policy handles are overwritten or fall out of scope without
352            being freed. */
353
354         char *marker;
355 #endif
356 } POLICY_HND;
357
358 /*
359  * A client connection's state, pipe name, 
360  * user credentials, etc...
361  */
362 typedef struct _cli_auth_fns cli_auth_fns;
363 struct user_creds;
364 struct cli_connection {
365
366         char                    *srv_name;
367         char                    *pipe_name;
368         struct user_creds       usr_creds;
369
370         struct cli_state        *pCli_state;
371
372         cli_auth_fns            *auth;
373
374         void                    *auth_info;
375         void                    *auth_creds;
376 };
377
378
379 /* 
380  * Associate a POLICY_HND with a cli_connection
381  */
382 typedef struct rpc_hnd_node {
383
384         POLICY_HND              hnd;
385         struct cli_connection   *cli;
386
387 } RPC_HND_NODE;
388
389 typedef struct uint64_s
390 {
391         uint32 low;
392         uint32 high;
393 } UINT64_S;
394
395 /* BUFHDR2 - another buffer header, with info level */
396 typedef struct bufhdr2_info
397 {
398         uint32 info_level;
399         uint32 length;          /* uint8 chars */
400         uint32 buffer;
401
402 }
403 BUFHDR2;
404
405 /* BUFHDR4 - another buffer header */
406 typedef struct bufhdr4_info
407 {
408         uint32 size;
409         uint32 buffer;
410
411 }
412 BUFHDR4;
413
414 /* BUFFER4 - simple length and buffer */
415 typedef struct buffer4_info
416 {
417         uint32 buf_len;
418         uint8 *buffer;
419
420 }
421 BUFFER4;
422
423 enum unistr2_term_codes { UNI_FLAGS_NONE = 0, UNI_STR_TERMINATE = 1, UNI_MAXLEN_TERMINATE = 2, UNI_BROKEN_NON_NULL = 3 };
424 #endif /* _RPC_MISC_H */