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