1 | /* |
---|
2 | * This file contains miscellaneous pieces of code which regfio.c |
---|
3 | * depends upon, from the Samba Subversion tree. See: |
---|
4 | * http://websvn.samba.org/cgi-bin/viewcvs.cgi/trunk/source/ |
---|
5 | * |
---|
6 | * Copyright (C) 2005 Timothy D. Morgan |
---|
7 | * Copyright (C) 1992-2005 Samba development team |
---|
8 | * (see individual files under Subversion for details.) |
---|
9 | * |
---|
10 | * This program is free software; you can redistribute it and/or modify |
---|
11 | * it under the terms of the GNU General Public License as published by |
---|
12 | * the Free Software Foundation; version 2 of the License. |
---|
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 | * $Id: smb_deps.h 53 2005-09-04 21:04:58Z tim $ |
---|
24 | */ |
---|
25 | |
---|
26 | #include <stdlib.h> |
---|
27 | #include <stdbool.h> |
---|
28 | #include <stdio.h> |
---|
29 | #include <string.h> |
---|
30 | #include <errno.h> |
---|
31 | #include <fcntl.h> |
---|
32 | #include <sys/stat.h> |
---|
33 | #include <sys/types.h> |
---|
34 | #include <unistd.h> |
---|
35 | |
---|
36 | #include "byteorder.h" |
---|
37 | |
---|
38 | #define DEBUG(lvl,body) 0 |
---|
39 | |
---|
40 | void* zalloc(size_t size); |
---|
41 | void* zcalloc(size_t size, unsigned int count); |
---|
42 | |
---|
43 | /* From includes.h */ |
---|
44 | |
---|
45 | #define uint8 unsigned char |
---|
46 | #define int16 short |
---|
47 | #define uint16 unsigned short |
---|
48 | #define int32 int |
---|
49 | #define uint32 unsigned int |
---|
50 | |
---|
51 | #define SMB_STRUCT_STAT struct stat |
---|
52 | #define QSORT_CAST (int (*)(const void *, const void *)) |
---|
53 | |
---|
54 | #define MIN(a,b) ((a)<(b)?(a):(b)) |
---|
55 | #define MAX(a,b) ((a)>(b)?(a):(b)) |
---|
56 | |
---|
57 | extern int DEBUGLEVEL; |
---|
58 | |
---|
59 | #define DLIST_ADD(list, p) \ |
---|
60 | { \ |
---|
61 | if (!(list)) { \ |
---|
62 | (list) = (p); \ |
---|
63 | (p)->next = (p)->prev = NULL; \ |
---|
64 | } else { \ |
---|
65 | (list)->prev = (p); \ |
---|
66 | (p)->next = (list); \ |
---|
67 | (p)->prev = NULL; \ |
---|
68 | (list) = (p); \ |
---|
69 | }\ |
---|
70 | } |
---|
71 | |
---|
72 | /* End of stuff from includes.h */ |
---|
73 | |
---|
74 | /* From smb.h */ |
---|
75 | |
---|
76 | #define MAXSUBAUTHS 15 |
---|
77 | |
---|
78 | typedef struct sid_info |
---|
79 | { |
---|
80 | uint8 sid_rev_num; /**< SID revision number */ |
---|
81 | uint8 num_auths; /**< Number of sub-authorities */ |
---|
82 | uint8 id_auth[6]; /**< Identifier Authority */ |
---|
83 | /* |
---|
84 | * Pointer to sub-authorities. |
---|
85 | * |
---|
86 | * @note The values in these uint32's are in *native* byteorder, not |
---|
87 | * neccessarily little-endian...... JRA. |
---|
88 | */ |
---|
89 | uint32 sub_auths[MAXSUBAUTHS]; |
---|
90 | } DOM_SID; |
---|
91 | |
---|
92 | typedef struct nttime_info |
---|
93 | { |
---|
94 | uint32 low; |
---|
95 | uint32 high; |
---|
96 | } NTTIME; |
---|
97 | |
---|
98 | /* End of stuff from smb.h */ |
---|
99 | |
---|
100 | /* From smb_macros.h */ |
---|
101 | |
---|
102 | #define TALLOC_ZERO_P(ctx, type) (type *)_talloc_zero(ctx, sizeof(type), #type) |
---|
103 | #define SMB_MALLOC_P(type) (type *)malloc_(sizeof(type)) |
---|
104 | #define TALLOC_ARRAY(ctx, type, count) (type *)_talloc_array(ctx, sizeof(type), count, #type) |
---|
105 | #define TALLOC_ZERO_ARRAY(ctx, type, count) (type *)_talloc_zero_array(ctx, sizeof(type), count, #type) |
---|
106 | #define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0) |
---|
107 | |
---|
108 | /* End of stuff from smb_macros.h */ |
---|
109 | |
---|
110 | /* From ntdomain.h */ |
---|
111 | |
---|
112 | struct uuid { |
---|
113 | uint32 time_low; |
---|
114 | uint16 time_mid; |
---|
115 | uint16 time_hi_and_version; |
---|
116 | uint8 clock_seq[2]; |
---|
117 | uint8 node[6]; |
---|
118 | }; |
---|
119 | |
---|
120 | typedef struct _prs_struct { |
---|
121 | bool io; /* parsing in or out of data stream */ |
---|
122 | /* |
---|
123 | * If the (incoming) data is big-endian. On output we are |
---|
124 | * always little-endian. |
---|
125 | */ |
---|
126 | bool bigendian_data; |
---|
127 | uint8 align; /* data alignment */ |
---|
128 | bool is_dynamic; /* Do we own this memory or not ? */ |
---|
129 | uint32 data_offset; /* Current working offset into data. */ |
---|
130 | uint32 buffer_size; /* Current allocated size of the buffer. */ |
---|
131 | uint32 grow_size; /* size requested via prs_grow() calls */ |
---|
132 | char *data_p; /* The buffer itself. */ |
---|
133 | void *mem_ctx; /* When unmarshalling, use this.... */ |
---|
134 | } prs_struct; |
---|
135 | |
---|
136 | #define MARSHALL 0 |
---|
137 | #define UNMARSHALL 1 |
---|
138 | |
---|
139 | #define RPC_LITTLE_ENDIAN 0 |
---|
140 | #define RPC_PARSE_ALIGN 4 |
---|
141 | |
---|
142 | |
---|
143 | /* End of stuff from ntdomain.h */ |
---|
144 | |
---|
145 | /* From nt_status.h */ |
---|
146 | |
---|
147 | typedef uint32 NTSTATUS; |
---|
148 | typedef uint32 WERROR; |
---|
149 | |
---|
150 | /* End of stuff from nt_status.h */ |
---|
151 | |
---|
152 | /* From lib/time.c */ |
---|
153 | |
---|
154 | #define CHAR_BIT 8 |
---|
155 | #define TIME_T_MIN ((time_t)0 < (time_t) -1 ? (time_t) 0 \ |
---|
156 | : ~ (time_t) 0 << (sizeof (time_t) * CHAR_BIT - 1)) |
---|
157 | #define TIME_T_MAX (~ (time_t) 0 - TIME_T_MIN) |
---|
158 | #define TIME_FIXUP_CONSTANT (369.0*365.25*24*60*60-(3.0*24*60*60+6.0*60*60)) |
---|
159 | |
---|
160 | void unix_to_nt_time(NTTIME *nt, time_t t); |
---|
161 | time_t nt_time_to_unix(NTTIME *nt); |
---|
162 | |
---|
163 | /* End of stuff from lib/time.c */ |
---|
164 | |
---|
165 | /* From rpc_dce.h */ |
---|
166 | |
---|
167 | #define MAX_PDU_FRAG_LEN 0x10b8 /* this is what w2k sets */ |
---|
168 | |
---|
169 | /* End of stuff from rpc_dce.h */ |
---|
170 | |
---|
171 | /* From parse_prs.h */ |
---|
172 | |
---|
173 | bool prs_grow(prs_struct *ps, uint32 extra_space); |
---|
174 | bool prs_align(prs_struct *ps); |
---|
175 | bool prs_init(prs_struct *ps, uint32 size, void *ctx, bool io); |
---|
176 | char *prs_mem_get(prs_struct *ps, uint32 extra_size); |
---|
177 | bool prs_uint32(const char *name, prs_struct *ps, int depth, uint32 *data32); |
---|
178 | bool prs_uint32s(bool charmode, const char *name, prs_struct *ps, |
---|
179 | int depth, uint32 *data32s, int len); |
---|
180 | bool prs_uint16(const char *name, prs_struct *ps, int depth, uint16 *data16); |
---|
181 | bool prs_uint16_pre(const char *name, prs_struct *ps, int depth, |
---|
182 | uint16 *data16, uint32 *offset); |
---|
183 | bool prs_uint16_post(const char *name, prs_struct *ps, int depth, |
---|
184 | uint16 *data16, uint32 ptr_uint16, uint32 start_offset); |
---|
185 | bool prs_uint8(const char *name, prs_struct *ps, int depth, uint8 *data8); |
---|
186 | bool prs_uint8s(bool charmode, const char *name, prs_struct *ps, int depth, |
---|
187 | uint8* data8s, int len); |
---|
188 | bool prs_set_offset(prs_struct *ps, uint32 offset); |
---|
189 | |
---|
190 | /* End of stuff from parse_prs.h */ |
---|
191 | |
---|
192 | |
---|
193 | |
---|
194 | /* buffer used by \winreg\ calls to fill in arbitrary REG_XXX values. |
---|
195 | It *may* look like a UNISTR2 but it is *not*. This is not a goof |
---|
196 | by the winreg developers. It is a generic buffer. buffer length |
---|
197 | is stored in bytes (not # of uint16's) */ |
---|
198 | |
---|
199 | typedef struct { |
---|
200 | uint32 buf_max_len; |
---|
201 | uint32 offset; |
---|
202 | uint32 buf_len; |
---|
203 | uint16 *buffer; |
---|
204 | } REGVAL_BUFFER; |
---|
205 | |
---|
206 | typedef struct { |
---|
207 | uint32 buf_len; |
---|
208 | uint16 *buffer; /* data */ |
---|
209 | } BUFFER5; |
---|
210 | |
---|
211 | |
---|
212 | /********************************************************************** |
---|
213 | * UNICODE string variations |
---|
214 | **********************************************************************/ |
---|
215 | |
---|
216 | |
---|
217 | typedef struct { /* UNISTR - unicode string size and buffer */ |
---|
218 | uint16 *buffer; /* unicode characters. ***MUST*** be |
---|
219 | little-endian. ***MUST*** be null-terminated */ |
---|
220 | } UNISTR; |
---|
221 | |
---|
222 | typedef struct { /* UNISTR2 - unicode string size (in |
---|
223 | uint16 unicode chars) and buffer */ |
---|
224 | uint32 uni_max_len; |
---|
225 | uint32 offset; |
---|
226 | uint32 uni_str_len; |
---|
227 | uint16 *buffer; /* unicode characters. ***MUST*** be little-endian. |
---|
228 | **must** be null-terminated and the uni_str_len |
---|
229 | should include the NULL character */ |
---|
230 | } UNISTR2; |
---|
231 | |
---|
232 | /* i think this is the same as a BUFFER5 used in the spoolss code --jerry */ |
---|
233 | /* not sure about how the termination matches between the uint16 buffers thought */ |
---|
234 | |
---|
235 | typedef struct { /* UNISTR3 - XXXX not sure about this structure */ |
---|
236 | uint32 uni_str_len; |
---|
237 | UNISTR str; |
---|
238 | } UNISTR3; |
---|
239 | |
---|
240 | typedef struct { /* Buffer wrapped around a UNISTR2 */ |
---|
241 | uint16 length; /* number of bytes not counting NULL terminatation */ |
---|
242 | uint16 size; /* number of bytes including NULL terminatation */ |
---|
243 | UNISTR2 *string; |
---|
244 | } UNISTR4; |
---|
245 | |
---|
246 | typedef struct { |
---|
247 | uint32 count; |
---|
248 | UNISTR4 *strings; |
---|
249 | } UNISTR4_ARRAY; |
---|
250 | |
---|
251 | |
---|
252 | /********************************************************************** |
---|
253 | * String variations |
---|
254 | **********************************************************************/ |
---|
255 | |
---|
256 | typedef struct { /* STRING2 - string size (in uint8 chars) and buffer */ |
---|
257 | uint32 str_max_len; |
---|
258 | uint32 offset; |
---|
259 | uint32 str_str_len; |
---|
260 | uint8 *buffer; /* uint8 characters. **NOT** necessarily null-terminated */ |
---|
261 | } STRING2; |
---|
262 | |
---|
263 | |
---|
264 | /* From rpc_secdesc.h */ |
---|
265 | |
---|
266 | typedef struct security_info_info |
---|
267 | { |
---|
268 | uint32 mask; |
---|
269 | |
---|
270 | } SEC_ACCESS; |
---|
271 | |
---|
272 | typedef struct security_ace_info |
---|
273 | { |
---|
274 | uint8 type; /* xxxx_xxxx_ACE_TYPE - e.g allowed / denied etc */ |
---|
275 | uint8 flags; /* xxxx_INHERIT_xxxx - e.g OBJECT_INHERIT_ACE */ |
---|
276 | uint16 size; |
---|
277 | |
---|
278 | SEC_ACCESS info; |
---|
279 | |
---|
280 | /* this stuff may be present when type is XXXX_TYPE_XXXX_OBJECT */ |
---|
281 | uint32 obj_flags; /* xxxx_ACE_OBJECT_xxxx e.g present/inherited present etc */ |
---|
282 | struct uuid obj_guid; /* object GUID */ |
---|
283 | struct uuid inh_guid; /* inherited object GUID */ |
---|
284 | /* eof object stuff */ |
---|
285 | |
---|
286 | DOM_SID trustee; |
---|
287 | |
---|
288 | } SEC_ACE; |
---|
289 | |
---|
290 | typedef struct security_acl_info |
---|
291 | { |
---|
292 | uint16 revision; /* 0x0003 */ |
---|
293 | uint16 size; /* size in bytes of the entire ACL structure */ |
---|
294 | uint32 num_aces; /* number of Access Control Entries */ |
---|
295 | |
---|
296 | SEC_ACE *ace; |
---|
297 | |
---|
298 | } SEC_ACL; |
---|
299 | |
---|
300 | typedef struct security_descriptor_info |
---|
301 | { |
---|
302 | uint16 revision; /* 0x0001 */ |
---|
303 | uint16 type; /* SEC_DESC_xxxx flags */ |
---|
304 | |
---|
305 | uint32 off_owner_sid; /* offset to owner sid */ |
---|
306 | uint32 off_grp_sid ; /* offset to group sid */ |
---|
307 | uint32 off_sacl ; /* offset to system list of permissions */ |
---|
308 | uint32 off_dacl ; /* offset to list of permissions */ |
---|
309 | |
---|
310 | SEC_ACL *dacl; /* user ACL */ |
---|
311 | SEC_ACL *sacl; /* system ACL */ |
---|
312 | DOM_SID *owner_sid; |
---|
313 | DOM_SID *grp_sid; |
---|
314 | |
---|
315 | } SEC_DESC; |
---|
316 | |
---|
317 | /* End of stuff from rpc_secdesc.h */ |
---|
318 | |
---|
319 | |
---|
320 | /* From pstring.h */ |
---|
321 | |
---|
322 | #define PSTRING_LEN 1024 |
---|
323 | #define FSTRING_LEN 256 |
---|
324 | |
---|
325 | typedef char pstring[PSTRING_LEN]; |
---|
326 | typedef char fstring[FSTRING_LEN]; |
---|
327 | |
---|
328 | /* End of stuff from pstring.h */ |
---|
329 | |
---|
330 | /* From reg_objects.h */ |
---|
331 | |
---|
332 | typedef struct _REGISTRY_VALUE { |
---|
333 | fstring valuename; |
---|
334 | uint16 type; |
---|
335 | /* this should be encapsulated in an RPC_DATA_BLOB */ |
---|
336 | uint32 size; /* in bytes */ |
---|
337 | uint8 *data_p; |
---|
338 | } REGISTRY_VALUE; |
---|
339 | |
---|
340 | /* container for registry values */ |
---|
341 | typedef struct { |
---|
342 | void *ctx; |
---|
343 | uint32 num_values; |
---|
344 | REGISTRY_VALUE **values; |
---|
345 | } REGVAL_CTR; |
---|
346 | |
---|
347 | /* container for registry subkey names */ |
---|
348 | typedef struct { |
---|
349 | void *ctx; |
---|
350 | uint32 num_subkeys; |
---|
351 | char **subkeys; |
---|
352 | } REGSUBKEY_CTR; |
---|
353 | |
---|
354 | /* represent a registry key with all its subkeys and values */ |
---|
355 | struct _regobj_key; |
---|
356 | |
---|
357 | typedef struct _regobj_key { |
---|
358 | void *ctx; |
---|
359 | |
---|
360 | char *name; |
---|
361 | |
---|
362 | REGVAL_CTR values; |
---|
363 | REGSUBKEY_CTR subkeys; |
---|
364 | } REGOBJ_KEY; |
---|
365 | |
---|
366 | /* End of stuff from reg_objects.h */ |
---|
367 | |
---|
368 | /* From rpc_secdes.h */ |
---|
369 | |
---|
370 | #define SEC_DESC_DACL_PRESENT 0x0004 |
---|
371 | #define SEC_DESC_SACL_PRESENT 0x0010 |
---|
372 | #define SEC_DESC_HEADER_SIZE (2 * sizeof(uint16) + 4 * sizeof(uint32)) |
---|
373 | /* thanks for Jim McDonough <jmcd@us.ibm.com> */ |
---|
374 | #define SEC_ACE_OBJECT_PRESENT 0x00000001 |
---|
375 | #define SEC_ACE_OBJECT_INHERITED_PRESENT 0x00000002 |
---|
376 | |
---|
377 | #define SEC_ACE_TYPE_ACCESS_ALLOWED_OBJECT 0x5 |
---|
378 | #define SEC_ACE_TYPE_ACCESS_DENIED_OBJECT 0x6 |
---|
379 | #define SEC_ACE_TYPE_SYSTEM_AUDIT_OBJECT 0x7 |
---|
380 | #define SEC_ACE_TYPE_SYSTEM_ALARM_OBJECT 0x8 |
---|
381 | |
---|
382 | /* End of stuff from rpc_secdes.h */ |
---|
383 | |
---|
384 | /* From rpc_parse/parse_misc.c */ |
---|
385 | |
---|
386 | bool smb_io_uuid(const char *desc, struct uuid *uuid, |
---|
387 | prs_struct *ps, int depth); |
---|
388 | bool smb_io_time(const char *desc, NTTIME *nttime, prs_struct *ps, int depth); |
---|
389 | bool smb_io_dom_sid(const char *desc, DOM_SID *sid, prs_struct *ps, int depth); |
---|
390 | |
---|
391 | /* End of stuff from rpc_parse/parse_misc.c */ |
---|
392 | |
---|
393 | /* From lib/util_sid.c */ |
---|
394 | |
---|
395 | size_t sid_size(const DOM_SID *sid); |
---|
396 | int sid_compare_auth(const DOM_SID *sid1, const DOM_SID *sid2); |
---|
397 | int sid_compare(const DOM_SID *sid1, const DOM_SID *sid2); |
---|
398 | bool sid_equal(const DOM_SID *sid1, const DOM_SID *sid2); |
---|
399 | |
---|
400 | /* End of stuff from lib/util_sid.c */ |
---|
401 | |
---|
402 | /* From lib/secace.c */ |
---|
403 | |
---|
404 | bool sec_ace_object(uint8 type); |
---|
405 | |
---|
406 | /* End of stuff from lib/secace.c */ |
---|
407 | |
---|
408 | /* From rpc_parse/parse_sec.c */ |
---|
409 | |
---|
410 | bool sec_io_access(const char *desc, SEC_ACCESS *t, prs_struct *ps, int depth); |
---|
411 | bool sec_io_ace(const char *desc, SEC_ACE *psa, prs_struct *ps, int depth); |
---|
412 | bool sec_io_acl(const char *desc, SEC_ACL **ppsa, prs_struct *ps, int depth); |
---|
413 | bool sec_io_desc(const char *desc, SEC_DESC **ppsd, prs_struct *ps, int depth); |
---|
414 | |
---|
415 | /* End of stuff from rpc_parse/parse_sec.c */ |
---|
416 | |
---|
417 | /* From lib/secace.c */ |
---|
418 | |
---|
419 | bool sec_ace_equal(SEC_ACE *s1, SEC_ACE *s2); |
---|
420 | |
---|
421 | /* End of stuff from lib/secace.c */ |
---|
422 | |
---|
423 | /* From lib/secacl.c */ |
---|
424 | |
---|
425 | bool sec_acl_equal(SEC_ACL *s1, SEC_ACL *s2); |
---|
426 | |
---|
427 | /* End of stuff from lib/secacl.c */ |
---|
428 | |
---|
429 | /* From lib/secdesc.c */ |
---|
430 | |
---|
431 | bool sec_desc_equal(SEC_DESC *s1, SEC_DESC *s2); |
---|
432 | |
---|
433 | /* End of stuff from lib/secdesc.c */ |
---|