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