/src/libfwnt/libfwnt/libfwnt_security_descriptor.c
Line | Count | Source (jump to first uncovered line) |
1 | | /* |
2 | | * Windows NT Security Descriptor functions |
3 | | * |
4 | | * Copyright (C) 2009-2024, Joachim Metz <joachim.metz@gmail.com> |
5 | | * |
6 | | * Refer to AUTHORS for acknowledgements. |
7 | | * |
8 | | * This program is free software: you can redistribute it and/or modify |
9 | | * it under the terms of the GNU Lesser General Public License as published by |
10 | | * the Free Software Foundation, either version 3 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 Lesser General Public License |
19 | | * along with this program. If not, see <https://www.gnu.org/licenses/>. |
20 | | */ |
21 | | |
22 | | #include <common.h> |
23 | | #include <byte_stream.h> |
24 | | #include <memory.h> |
25 | | #include <narrow_string.h> |
26 | | #include <system_string.h> |
27 | | #include <types.h> |
28 | | #include <wide_string.h> |
29 | | |
30 | | #include "libfwnt_access_control_list.h" |
31 | | #include "libfwnt_debug.h" |
32 | | #include "libfwnt_definitions.h" |
33 | | #include "libfwnt_libcerror.h" |
34 | | #include "libfwnt_libcnotify.h" |
35 | | #include "libfwnt_security_descriptor.h" |
36 | | #include "libfwnt_security_identifier.h" |
37 | | #include "libfwnt_types.h" |
38 | | |
39 | | /* Creates a security descriptor |
40 | | * Make sure the value security_descriptor is referencing, is set to NULL |
41 | | * Returns 1 if successful or -1 on error |
42 | | */ |
43 | | int libfwnt_security_descriptor_initialize( |
44 | | libfwnt_security_descriptor_t **security_descriptor, |
45 | | libcerror_error_t **error ) |
46 | 742 | { |
47 | 742 | libfwnt_internal_security_descriptor_t *internal_security_descriptor = NULL; |
48 | 742 | static char *function = "libfwnt_security_descriptor_initialize"; |
49 | | |
50 | 742 | if( security_descriptor == NULL ) |
51 | 0 | { |
52 | 0 | libcerror_error_set( |
53 | 0 | error, |
54 | 0 | LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
55 | 0 | LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, |
56 | 0 | "%s: invalid security descriptor.", |
57 | 0 | function ); |
58 | |
|
59 | 0 | return( -1 ); |
60 | 0 | } |
61 | 742 | if( *security_descriptor != NULL ) |
62 | 0 | { |
63 | 0 | libcerror_error_set( |
64 | 0 | error, |
65 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
66 | 0 | LIBCERROR_RUNTIME_ERROR_VALUE_ALREADY_SET, |
67 | 0 | "%s: invalid security descriptor value already set.", |
68 | 0 | function ); |
69 | |
|
70 | 0 | return( -1 ); |
71 | 0 | } |
72 | 742 | internal_security_descriptor = memory_allocate_structure( |
73 | 742 | libfwnt_internal_security_descriptor_t ); |
74 | | |
75 | 742 | if( internal_security_descriptor == NULL ) |
76 | 0 | { |
77 | 0 | libcerror_error_set( |
78 | 0 | error, |
79 | 0 | LIBCERROR_ERROR_DOMAIN_MEMORY, |
80 | 0 | LIBCERROR_MEMORY_ERROR_INSUFFICIENT, |
81 | 0 | "%s: unable to create security descriptor.", |
82 | 0 | function ); |
83 | |
|
84 | 0 | goto on_error; |
85 | 0 | } |
86 | 742 | if( memory_set( |
87 | 742 | internal_security_descriptor, |
88 | 742 | 0, |
89 | 742 | sizeof( libfwnt_internal_security_descriptor_t ) ) == NULL ) |
90 | 0 | { |
91 | 0 | libcerror_error_set( |
92 | 0 | error, |
93 | 0 | LIBCERROR_ERROR_DOMAIN_MEMORY, |
94 | 0 | LIBCERROR_MEMORY_ERROR_SET_FAILED, |
95 | 0 | "%s: unable to clear security descriptor.", |
96 | 0 | function ); |
97 | |
|
98 | 0 | goto on_error; |
99 | 0 | } |
100 | 742 | *security_descriptor = (libfwnt_security_descriptor_t *) internal_security_descriptor; |
101 | | |
102 | 742 | return( 1 ); |
103 | | |
104 | 0 | on_error: |
105 | 0 | if( internal_security_descriptor != NULL ) |
106 | 0 | { |
107 | 0 | memory_free( |
108 | 0 | internal_security_descriptor ); |
109 | 0 | } |
110 | 0 | return( -1 ); |
111 | 742 | } |
112 | | |
113 | | /* Frees a security descriptor |
114 | | * Returns 1 if successful or -1 on error |
115 | | */ |
116 | | int libfwnt_security_descriptor_free( |
117 | | libfwnt_security_descriptor_t **security_descriptor, |
118 | | libcerror_error_t **error ) |
119 | 742 | { |
120 | 742 | libfwnt_internal_security_descriptor_t *internal_security_descriptor = NULL; |
121 | 742 | static char *function = "libfwnt_security_descriptor_free"; |
122 | 742 | int result = 1; |
123 | | |
124 | 742 | if( security_descriptor == NULL ) |
125 | 0 | { |
126 | 0 | libcerror_error_set( |
127 | 0 | error, |
128 | 0 | LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
129 | 0 | LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, |
130 | 0 | "%s: invalid security descriptor.", |
131 | 0 | function ); |
132 | |
|
133 | 0 | return( -1 ); |
134 | 0 | } |
135 | 742 | if( *security_descriptor != NULL ) |
136 | 742 | { |
137 | 742 | internal_security_descriptor = (libfwnt_internal_security_descriptor_t *) *security_descriptor; |
138 | 742 | *security_descriptor = NULL; |
139 | | |
140 | 742 | if( internal_security_descriptor->owner_sid != NULL ) |
141 | 30 | { |
142 | 30 | if( libfwnt_internal_security_identifier_free( |
143 | 30 | (libfwnt_internal_security_identifier_t **) &( internal_security_descriptor->owner_sid ), |
144 | 30 | error ) != 1 ) |
145 | 0 | { |
146 | 0 | libcerror_error_set( |
147 | 0 | error, |
148 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
149 | 0 | LIBCERROR_RUNTIME_ERROR_FINALIZE_FAILED, |
150 | 0 | "%s: unable to free owner security identifier.", |
151 | 0 | function ); |
152 | |
|
153 | 0 | result = -1; |
154 | 0 | } |
155 | 30 | } |
156 | 742 | if( internal_security_descriptor->group_sid != NULL ) |
157 | 28 | { |
158 | 28 | if( libfwnt_internal_security_identifier_free( |
159 | 28 | (libfwnt_internal_security_identifier_t **) &( internal_security_descriptor->group_sid ), |
160 | 28 | error ) != 1 ) |
161 | 0 | { |
162 | 0 | libcerror_error_set( |
163 | 0 | error, |
164 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
165 | 0 | LIBCERROR_RUNTIME_ERROR_FINALIZE_FAILED, |
166 | 0 | "%s: unable to free group security identifier.", |
167 | 0 | function ); |
168 | |
|
169 | 0 | result = -1; |
170 | 0 | } |
171 | 28 | } |
172 | 742 | if( internal_security_descriptor->system_acl != NULL ) |
173 | 83 | { |
174 | 83 | if( libfwnt_internal_access_control_list_free( |
175 | 83 | (libfwnt_internal_access_control_list_t ** ) &( internal_security_descriptor->system_acl ), |
176 | 83 | error ) != 1 ) |
177 | 0 | { |
178 | 0 | libcerror_error_set( |
179 | 0 | error, |
180 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
181 | 0 | LIBCERROR_RUNTIME_ERROR_FINALIZE_FAILED, |
182 | 0 | "%s: unable to free system ACL.", |
183 | 0 | function ); |
184 | |
|
185 | 0 | result = -1; |
186 | 0 | } |
187 | 83 | } |
188 | 742 | if( internal_security_descriptor->discretionary_acl != NULL ) |
189 | 83 | { |
190 | 83 | if( libfwnt_internal_access_control_list_free( |
191 | 83 | (libfwnt_internal_access_control_list_t ** ) &( internal_security_descriptor->discretionary_acl ), |
192 | 83 | error ) != 1 ) |
193 | 0 | { |
194 | 0 | libcerror_error_set( |
195 | 0 | error, |
196 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
197 | 0 | LIBCERROR_RUNTIME_ERROR_FINALIZE_FAILED, |
198 | 0 | "%s: unable to free discretionary ACL.", |
199 | 0 | function ); |
200 | |
|
201 | 0 | result = -1; |
202 | 0 | } |
203 | 83 | } |
204 | 742 | memory_free( |
205 | 742 | internal_security_descriptor ); |
206 | 742 | } |
207 | 742 | return( result ); |
208 | 742 | } |
209 | | |
210 | | /* Converts a security descriptor stored in a byte stream into a runtime version |
211 | | * Returns 1 if successful or -1 on error |
212 | | */ |
213 | | int libfwnt_security_descriptor_copy_from_byte_stream( |
214 | | libfwnt_security_descriptor_t *security_descriptor, |
215 | | const uint8_t *byte_stream, |
216 | | size_t byte_stream_size, |
217 | | int byte_order, |
218 | | libcerror_error_t **error ) |
219 | 742 | { |
220 | 742 | libfwnt_internal_security_descriptor_t *internal_security_descriptor = NULL; |
221 | 742 | static char *function = "libfwnt_security_descriptor_copy_from_byte_stream"; |
222 | 742 | uint32_t discretionary_acl_offset = 0; |
223 | 742 | uint32_t group_sid_offset = 0; |
224 | 742 | uint32_t owner_sid_offset = 0; |
225 | 742 | uint32_t system_acl_offset = 0; |
226 | 742 | uint16_t control_flags = 0; |
227 | | |
228 | | #if defined( HAVE_DEBUG_OUTPUT ) |
229 | | system_character_t *sid_string = NULL; |
230 | | size_t sid_string_size = 0; |
231 | | int result = 0; |
232 | | #endif |
233 | | |
234 | 742 | if( security_descriptor == NULL ) |
235 | 0 | { |
236 | 0 | libcerror_error_set( |
237 | 0 | error, |
238 | 0 | LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
239 | 0 | LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, |
240 | 0 | "%s: invalid security descriptor.", |
241 | 0 | function ); |
242 | |
|
243 | 0 | return( -1 ); |
244 | 0 | } |
245 | 742 | internal_security_descriptor = (libfwnt_internal_security_descriptor_t *) security_descriptor; |
246 | | |
247 | 742 | if( internal_security_descriptor->owner_sid != NULL ) |
248 | 0 | { |
249 | 0 | libcerror_error_set( |
250 | 0 | error, |
251 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
252 | 0 | LIBCERROR_RUNTIME_ERROR_VALUE_ALREADY_SET, |
253 | 0 | "%s: invalid security descriptor - owner SID value already set.", |
254 | 0 | function ); |
255 | |
|
256 | 0 | return( -1 ); |
257 | 0 | } |
258 | 742 | if( internal_security_descriptor->group_sid != NULL ) |
259 | 0 | { |
260 | 0 | libcerror_error_set( |
261 | 0 | error, |
262 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
263 | 0 | LIBCERROR_RUNTIME_ERROR_VALUE_ALREADY_SET, |
264 | 0 | "%s: invalid security descriptor - group SID value already set.", |
265 | 0 | function ); |
266 | |
|
267 | 0 | return( -1 ); |
268 | 0 | } |
269 | 742 | if( internal_security_descriptor->system_acl != NULL ) |
270 | 0 | { |
271 | 0 | libcerror_error_set( |
272 | 0 | error, |
273 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
274 | 0 | LIBCERROR_RUNTIME_ERROR_VALUE_ALREADY_SET, |
275 | 0 | "%s: invalid security descriptor - system ACL value already set.", |
276 | 0 | function ); |
277 | |
|
278 | 0 | return( -1 ); |
279 | 0 | } |
280 | 742 | if( internal_security_descriptor->discretionary_acl != NULL ) |
281 | 0 | { |
282 | 0 | libcerror_error_set( |
283 | 0 | error, |
284 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
285 | 0 | LIBCERROR_RUNTIME_ERROR_VALUE_ALREADY_SET, |
286 | 0 | "%s: invalid security descriptor - discretionary ACL value already set.", |
287 | 0 | function ); |
288 | |
|
289 | 0 | return( -1 ); |
290 | 0 | } |
291 | 742 | if( byte_stream == NULL ) |
292 | 0 | { |
293 | 0 | libcerror_error_set( |
294 | 0 | error, |
295 | 0 | LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
296 | 0 | LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, |
297 | 0 | "%s: invalid byte stream.", |
298 | 0 | function ); |
299 | |
|
300 | 0 | return( -1 ); |
301 | 0 | } |
302 | 742 | if( byte_stream_size < 20 ) |
303 | 8 | { |
304 | 8 | libcerror_error_set( |
305 | 8 | error, |
306 | 8 | LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
307 | 8 | LIBCERROR_ARGUMENT_ERROR_VALUE_TOO_SMALL, |
308 | 8 | "%s: byte stream too small.", |
309 | 8 | function ); |
310 | | |
311 | 8 | return( -1 ); |
312 | 8 | } |
313 | 734 | if( byte_stream_size > (size_t) SSIZE_MAX ) |
314 | 0 | { |
315 | 0 | libcerror_error_set( |
316 | 0 | error, |
317 | 0 | LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
318 | 0 | LIBCERROR_ARGUMENT_ERROR_VALUE_EXCEEDS_MAXIMUM, |
319 | 0 | "%s: byte stream size exceeds maximum.", |
320 | 0 | function ); |
321 | |
|
322 | 0 | return( -1 ); |
323 | 0 | } |
324 | 734 | if( byte_order != LIBFWNT_ENDIAN_LITTLE ) |
325 | 0 | { |
326 | 0 | libcerror_error_set( |
327 | 0 | error, |
328 | 0 | LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
329 | 0 | LIBCERROR_ARGUMENT_ERROR_UNSUPPORTED_VALUE, |
330 | 0 | "%s: unsupported byte order.", |
331 | 0 | function ); |
332 | |
|
333 | 0 | return( -1 ); |
334 | 0 | } |
335 | | #if defined( HAVE_DEBUG_OUTPUT ) |
336 | | if( libcnotify_verbose != 0 ) |
337 | | { |
338 | | libcnotify_printf( |
339 | | "%s: header data:\n", |
340 | | function ); |
341 | | libcnotify_print_data( |
342 | | byte_stream, |
343 | | 20, |
344 | | 0 ); |
345 | | } |
346 | | #endif |
347 | 734 | internal_security_descriptor->revision_number = byte_stream[ 0 ]; |
348 | | |
349 | 734 | byte_stream_copy_to_uint16_little_endian( |
350 | 734 | &( byte_stream[ 2 ] ), |
351 | 734 | control_flags ); |
352 | | |
353 | 734 | byte_stream_copy_to_uint32_little_endian( |
354 | 734 | &( byte_stream[ 4 ] ), |
355 | 734 | owner_sid_offset ); |
356 | | |
357 | 734 | byte_stream_copy_to_uint32_little_endian( |
358 | 734 | &( byte_stream[ 8 ] ), |
359 | 734 | group_sid_offset ); |
360 | | |
361 | 734 | byte_stream_copy_to_uint32_little_endian( |
362 | 734 | &( byte_stream[ 12 ] ), |
363 | 734 | system_acl_offset ); |
364 | | |
365 | 734 | byte_stream_copy_to_uint32_little_endian( |
366 | 734 | &( byte_stream[ 16 ] ), |
367 | 734 | discretionary_acl_offset ); |
368 | | |
369 | | #if defined( HAVE_DEBUG_OUTPUT ) |
370 | | if( libcnotify_verbose != 0 ) |
371 | | { |
372 | | libcnotify_printf( |
373 | | "%s: revision number\t\t: %" PRIu8 "\n", |
374 | | function, |
375 | | internal_security_descriptor->revision_number ); |
376 | | |
377 | | libcnotify_printf( |
378 | | "%s: padding\t\t\t: 0x%02" PRIx8 "\n", |
379 | | function, |
380 | | byte_stream[ 1 ] ); |
381 | | |
382 | | libcnotify_printf( |
383 | | "%s: control flags\t\t: 0x%04" PRIx16 "\n", |
384 | | function, |
385 | | control_flags ); |
386 | | libfwnt_debug_print_security_descriptor_control_flags( |
387 | | control_flags ); |
388 | | libcnotify_printf( |
389 | | "\n" ); |
390 | | |
391 | | libcnotify_printf( |
392 | | "%s: owner SID offset\t\t: 0x%08" PRIx32 "\n", |
393 | | function, |
394 | | owner_sid_offset ); |
395 | | |
396 | | libcnotify_printf( |
397 | | "%s: group SID offset\t\t: 0x%08" PRIx32 "\n", |
398 | | function, |
399 | | group_sid_offset ); |
400 | | |
401 | | libcnotify_printf( |
402 | | "%s: system ACL offset\t\t: 0x%08" PRIx32 "\n", |
403 | | function, |
404 | | system_acl_offset ); |
405 | | |
406 | | libcnotify_printf( |
407 | | "%s: discretionary ACL offset\t: 0x%08" PRIx32 "\n", |
408 | | function, |
409 | | discretionary_acl_offset ); |
410 | | |
411 | | libcnotify_printf( |
412 | | "\n" ); |
413 | | } |
414 | | #endif /* defined( HAVE_DEBUG_OUTPUT ) */ |
415 | | |
416 | 734 | if( owner_sid_offset != 0 ) |
417 | 258 | { |
418 | 258 | if( ( owner_sid_offset < 20 ) |
419 | 258 | || ( (size_t) owner_sid_offset > byte_stream_size ) ) |
420 | 79 | { |
421 | 79 | libcerror_error_set( |
422 | 79 | error, |
423 | 79 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
424 | 79 | LIBCERROR_RUNTIME_ERROR_VALUE_OUT_OF_BOUNDS, |
425 | 79 | "%s: owner SID offset value out of bounds.", |
426 | 79 | function ); |
427 | | |
428 | 79 | goto on_error; |
429 | 79 | } |
430 | 179 | if( libfwnt_security_identifier_initialize( |
431 | 179 | &( internal_security_descriptor->owner_sid ), |
432 | 179 | error ) != 1 ) |
433 | 0 | { |
434 | 0 | libcerror_error_set( |
435 | 0 | error, |
436 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
437 | 0 | LIBCERROR_RUNTIME_ERROR_INITIALIZE_FAILED, |
438 | 0 | "%s: unable to create owner security identifier.", |
439 | 0 | function ); |
440 | |
|
441 | 0 | goto on_error; |
442 | 0 | } |
443 | 179 | if( internal_security_descriptor->owner_sid == NULL ) |
444 | 0 | { |
445 | 0 | libcerror_error_set( |
446 | 0 | error, |
447 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
448 | 0 | LIBCERROR_RUNTIME_ERROR_VALUE_MISSING, |
449 | 0 | "%s: invalid security descriptor - missing owner security identifier.", |
450 | 0 | function ); |
451 | |
|
452 | 0 | goto on_error; |
453 | 0 | } |
454 | 179 | ( (libfwnt_internal_security_identifier_t *) internal_security_descriptor->owner_sid )->is_managed = 1; |
455 | | |
456 | 179 | if( libfwnt_security_identifier_copy_from_byte_stream( |
457 | 179 | internal_security_descriptor->owner_sid, |
458 | 179 | &( byte_stream[ owner_sid_offset ] ), |
459 | 179 | byte_stream_size - owner_sid_offset, |
460 | 179 | LIBFWNT_ENDIAN_LITTLE, |
461 | 179 | error ) != 1 ) |
462 | 18 | { |
463 | 18 | libcerror_error_set( |
464 | 18 | error, |
465 | 18 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
466 | 18 | LIBCERROR_RUNTIME_ERROR_COPY_FAILED, |
467 | 18 | "%s: unable to copy owner security identifier from byte stream.", |
468 | 18 | function ); |
469 | | |
470 | 18 | goto on_error; |
471 | 18 | } |
472 | | #if defined( HAVE_DEBUG_OUTPUT ) |
473 | | if( libcnotify_verbose != 0 ) |
474 | | { |
475 | | if( libfwnt_security_identifier_get_string_size( |
476 | | internal_security_descriptor->owner_sid, |
477 | | &sid_string_size, |
478 | | 0, |
479 | | error ) != 1 ) |
480 | | { |
481 | | libcerror_error_set( |
482 | | error, |
483 | | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
484 | | LIBCERROR_RUNTIME_ERROR_GET_FAILED, |
485 | | "%s: unable to retrieve owner security identifier string size.", |
486 | | function ); |
487 | | |
488 | | goto on_error; |
489 | | } |
490 | | libcnotify_printf( |
491 | | "%s: owner SID\t\t\t: ", |
492 | | function ); |
493 | | |
494 | | if( sid_string_size > 0 ) |
495 | | { |
496 | | sid_string = system_string_allocate( |
497 | | sid_string_size ); |
498 | | |
499 | | if( sid_string == NULL ) |
500 | | { |
501 | | libcerror_error_set( |
502 | | error, |
503 | | LIBCERROR_ERROR_DOMAIN_MEMORY, |
504 | | LIBCERROR_MEMORY_ERROR_INSUFFICIENT, |
505 | | "%s: unable to create owner security identifier string.", |
506 | | function ); |
507 | | |
508 | | goto on_error; |
509 | | } |
510 | | #if defined( HAVE_WIDE_SYSTEM_CHARACTER ) |
511 | | result = libfwnt_security_identifier_copy_to_utf16_string( |
512 | | internal_security_descriptor->owner_sid, |
513 | | (uint16_t *) sid_string, |
514 | | sid_string_size, |
515 | | 0, |
516 | | error ); |
517 | | #else |
518 | | result = libfwnt_security_identifier_copy_to_utf8_string( |
519 | | internal_security_descriptor->owner_sid, |
520 | | (uint8_t *) sid_string, |
521 | | sid_string_size, |
522 | | 0, |
523 | | error ); |
524 | | #endif |
525 | | if( result != 1 ) |
526 | | { |
527 | | libcerror_error_set( |
528 | | error, |
529 | | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
530 | | LIBCERROR_RUNTIME_ERROR_COPY_FAILED, |
531 | | "%s: unable to copy owner security identifier to string.", |
532 | | function ); |
533 | | |
534 | | goto on_error; |
535 | | } |
536 | | libcnotify_printf( |
537 | | "%" PRIs_SYSTEM "", |
538 | | sid_string ); |
539 | | |
540 | | memory_free( |
541 | | sid_string ); |
542 | | |
543 | | sid_string = NULL; |
544 | | } |
545 | | libcnotify_printf( |
546 | | "\n" ); |
547 | | } |
548 | | #endif |
549 | 179 | } |
550 | 637 | if( group_sid_offset != 0 ) |
551 | 236 | { |
552 | 236 | if( ( group_sid_offset < 20 ) |
553 | 236 | || ( (size_t) group_sid_offset > byte_stream_size ) ) |
554 | 77 | { |
555 | 77 | libcerror_error_set( |
556 | 77 | error, |
557 | 77 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
558 | 77 | LIBCERROR_RUNTIME_ERROR_VALUE_OUT_OF_BOUNDS, |
559 | 77 | "%s: group security identifier offset value out of bounds.", |
560 | 77 | function ); |
561 | | |
562 | 77 | goto on_error; |
563 | 77 | } |
564 | 159 | if( libfwnt_security_identifier_initialize( |
565 | 159 | &( internal_security_descriptor->group_sid ), |
566 | 159 | error ) != 1 ) |
567 | 0 | { |
568 | 0 | libcerror_error_set( |
569 | 0 | error, |
570 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
571 | 0 | LIBCERROR_RUNTIME_ERROR_INITIALIZE_FAILED, |
572 | 0 | "%s: unable to create group security identifier.", |
573 | 0 | function ); |
574 | |
|
575 | 0 | goto on_error; |
576 | 0 | } |
577 | 159 | if( internal_security_descriptor->group_sid == NULL ) |
578 | 0 | { |
579 | 0 | libcerror_error_set( |
580 | 0 | error, |
581 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
582 | 0 | LIBCERROR_RUNTIME_ERROR_VALUE_MISSING, |
583 | 0 | "%s: invalid security descriptor - missing group security identifier.", |
584 | 0 | function ); |
585 | |
|
586 | 0 | goto on_error; |
587 | 0 | } |
588 | 159 | ( (libfwnt_internal_security_identifier_t *) internal_security_descriptor->group_sid )->is_managed = 1; |
589 | | |
590 | 159 | if( libfwnt_security_identifier_copy_from_byte_stream( |
591 | 159 | internal_security_descriptor->group_sid, |
592 | 159 | &( byte_stream[ group_sid_offset ] ), |
593 | 159 | byte_stream_size - group_sid_offset, |
594 | 159 | LIBFWNT_ENDIAN_LITTLE, |
595 | 159 | error ) != 1 ) |
596 | 7 | { |
597 | 7 | libcerror_error_set( |
598 | 7 | error, |
599 | 7 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
600 | 7 | LIBCERROR_RUNTIME_ERROR_COPY_FAILED, |
601 | 7 | "%s: unable to copy group security identifier from byte stream.", |
602 | 7 | function ); |
603 | | |
604 | 7 | goto on_error; |
605 | 7 | } |
606 | | #if defined( HAVE_DEBUG_OUTPUT ) |
607 | | if( libcnotify_verbose != 0 ) |
608 | | { |
609 | | if( libfwnt_security_identifier_get_string_size( |
610 | | internal_security_descriptor->group_sid, |
611 | | &sid_string_size, |
612 | | 0, |
613 | | error ) != 1 ) |
614 | | { |
615 | | libcerror_error_set( |
616 | | error, |
617 | | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
618 | | LIBCERROR_RUNTIME_ERROR_GET_FAILED, |
619 | | "%s: unable to retrieve group security identifier string size.", |
620 | | function ); |
621 | | |
622 | | goto on_error; |
623 | | } |
624 | | libcnotify_printf( |
625 | | "%s: group SID\t\t\t: ", |
626 | | function ); |
627 | | |
628 | | if( sid_string_size > 0 ) |
629 | | { |
630 | | sid_string = system_string_allocate( |
631 | | sid_string_size ); |
632 | | |
633 | | if( sid_string == NULL ) |
634 | | { |
635 | | libcerror_error_set( |
636 | | error, |
637 | | LIBCERROR_ERROR_DOMAIN_MEMORY, |
638 | | LIBCERROR_MEMORY_ERROR_INSUFFICIENT, |
639 | | "%s: unable to create group security identifier string.", |
640 | | function ); |
641 | | |
642 | | goto on_error; |
643 | | } |
644 | | #if defined( HAVE_WIDE_SYSTEM_CHARACTER ) |
645 | | result = libfwnt_security_identifier_copy_to_utf16_string( |
646 | | internal_security_descriptor->group_sid, |
647 | | (uint16_t *) sid_string, |
648 | | sid_string_size, |
649 | | 0, |
650 | | error ); |
651 | | #else |
652 | | result = libfwnt_security_identifier_copy_to_utf8_string( |
653 | | internal_security_descriptor->group_sid, |
654 | | (uint8_t *) sid_string, |
655 | | sid_string_size, |
656 | | 0, |
657 | | error ); |
658 | | #endif |
659 | | if( result != 1 ) |
660 | | { |
661 | | libcerror_error_set( |
662 | | error, |
663 | | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
664 | | LIBCERROR_RUNTIME_ERROR_COPY_FAILED, |
665 | | "%s: unable to copy group security identifier to string.", |
666 | | function ); |
667 | | |
668 | | goto on_error; |
669 | | } |
670 | | libcnotify_printf( |
671 | | "%" PRIs_SYSTEM "", |
672 | | sid_string ); |
673 | | |
674 | | memory_free( |
675 | | sid_string ); |
676 | | |
677 | | sid_string = NULL; |
678 | | } |
679 | | libcnotify_printf( |
680 | | "\n" ); |
681 | | } |
682 | | #endif |
683 | 159 | } |
684 | 553 | if( system_acl_offset != 0 ) |
685 | 447 | { |
686 | 447 | if( ( system_acl_offset < 20 ) |
687 | 447 | || ( (size_t) system_acl_offset > byte_stream_size ) ) |
688 | 87 | { |
689 | 87 | libcerror_error_set( |
690 | 87 | error, |
691 | 87 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
692 | 87 | LIBCERROR_RUNTIME_ERROR_VALUE_OUT_OF_BOUNDS, |
693 | 87 | "%s: system ACL offset value out of bounds.", |
694 | 87 | function ); |
695 | | |
696 | 87 | goto on_error; |
697 | 87 | } |
698 | 360 | if( libfwnt_access_control_list_initialize( |
699 | 360 | &( internal_security_descriptor->system_acl ), |
700 | 360 | error ) != 1 ) |
701 | 0 | { |
702 | 0 | libcerror_error_set( |
703 | 0 | error, |
704 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
705 | 0 | LIBCERROR_RUNTIME_ERROR_INITIALIZE_FAILED, |
706 | 0 | "%s: unable to create system ACL.", |
707 | 0 | function ); |
708 | |
|
709 | 0 | goto on_error; |
710 | 0 | } |
711 | 360 | if( libfwnt_access_control_list_copy_from_byte_stream( |
712 | 360 | internal_security_descriptor->system_acl, |
713 | 360 | &( byte_stream[ system_acl_offset ] ), |
714 | 360 | byte_stream_size - system_acl_offset, |
715 | 360 | LIBFWNT_ENDIAN_LITTLE, |
716 | 360 | error ) != 1 ) |
717 | 222 | { |
718 | 222 | libcerror_error_set( |
719 | 222 | error, |
720 | 222 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
721 | 222 | LIBCERROR_RUNTIME_ERROR_COPY_FAILED, |
722 | 222 | "%s: unable to copy system ACL from byte stream.", |
723 | 222 | function ); |
724 | | |
725 | 222 | goto on_error; |
726 | 222 | } |
727 | 360 | } |
728 | 244 | if( discretionary_acl_offset != 0 ) |
729 | 242 | { |
730 | 242 | if( ( discretionary_acl_offset < 20 ) |
731 | 242 | || ( (size_t) discretionary_acl_offset > byte_stream_size ) ) |
732 | 81 | { |
733 | 81 | libcerror_error_set( |
734 | 81 | error, |
735 | 81 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
736 | 81 | LIBCERROR_RUNTIME_ERROR_VALUE_OUT_OF_BOUNDS, |
737 | 81 | "%s: discretionary ACL offset value out of bounds.", |
738 | 81 | function ); |
739 | | |
740 | 81 | goto on_error; |
741 | 81 | } |
742 | 161 | if( libfwnt_access_control_list_initialize( |
743 | 161 | &( internal_security_descriptor->discretionary_acl ), |
744 | 161 | error ) != 1 ) |
745 | 0 | { |
746 | 0 | libcerror_error_set( |
747 | 0 | error, |
748 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
749 | 0 | LIBCERROR_RUNTIME_ERROR_INITIALIZE_FAILED, |
750 | 0 | "%s: unable to create discretionary ACL.", |
751 | 0 | function ); |
752 | |
|
753 | 0 | goto on_error; |
754 | 0 | } |
755 | 161 | if( libfwnt_access_control_list_copy_from_byte_stream( |
756 | 161 | internal_security_descriptor->discretionary_acl, |
757 | 161 | &( byte_stream[ discretionary_acl_offset ] ), |
758 | 161 | byte_stream_size - discretionary_acl_offset, |
759 | 161 | LIBFWNT_ENDIAN_LITTLE, |
760 | 161 | error ) != 1 ) |
761 | 78 | { |
762 | 78 | libcerror_error_set( |
763 | 78 | error, |
764 | 78 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
765 | 78 | LIBCERROR_RUNTIME_ERROR_COPY_FAILED, |
766 | 78 | "%s: unable to copy discretionary ACL from byte stream.", |
767 | 78 | function ); |
768 | | |
769 | 78 | goto on_error; |
770 | 78 | } |
771 | 161 | } |
772 | 85 | return( 1 ); |
773 | | |
774 | 649 | on_error: |
775 | | #if defined( HAVE_DEBUG_OUTPUT ) |
776 | | if( sid_string != NULL ) |
777 | | { |
778 | | memory_free( |
779 | | sid_string ); |
780 | | } |
781 | | #endif |
782 | 649 | if( internal_security_descriptor->discretionary_acl != NULL ) |
783 | 78 | { |
784 | 78 | libfwnt_internal_access_control_list_free( |
785 | 78 | (libfwnt_internal_access_control_list_t ** ) &( internal_security_descriptor->discretionary_acl ), |
786 | 78 | NULL ); |
787 | 78 | } |
788 | 649 | if( internal_security_descriptor->system_acl != NULL ) |
789 | 277 | { |
790 | 277 | libfwnt_internal_access_control_list_free( |
791 | 277 | (libfwnt_internal_access_control_list_t ** ) &( internal_security_descriptor->system_acl ), |
792 | 277 | NULL ); |
793 | 277 | } |
794 | 649 | if( internal_security_descriptor->group_sid != NULL ) |
795 | 131 | { |
796 | 131 | libfwnt_internal_security_identifier_free( |
797 | 131 | (libfwnt_internal_security_identifier_t **) &( internal_security_descriptor->group_sid ), |
798 | 131 | NULL ); |
799 | 131 | } |
800 | 649 | if( internal_security_descriptor->owner_sid != NULL ) |
801 | 149 | { |
802 | 149 | libfwnt_internal_security_identifier_free( |
803 | 149 | (libfwnt_internal_security_identifier_t **) &( internal_security_descriptor->owner_sid ), |
804 | 149 | NULL ); |
805 | 149 | } |
806 | 649 | return( -1 ); |
807 | 244 | } |
808 | | |
809 | | /* Retrieves the owner security identifier (SID) |
810 | | * Returns 1 if successful, 0 if not available or -1 on error |
811 | | */ |
812 | | int libfwnt_security_descriptor_get_owner( |
813 | | libfwnt_security_descriptor_t *security_descriptor, |
814 | | libfwnt_security_identifier_t **security_identifier, |
815 | | libcerror_error_t **error ) |
816 | 0 | { |
817 | 0 | libfwnt_internal_security_descriptor_t *internal_security_descriptor = NULL; |
818 | 0 | static char *function = "libfwnt_security_descriptor_get_owner"; |
819 | |
|
820 | 0 | if( security_descriptor == NULL ) |
821 | 0 | { |
822 | 0 | libcerror_error_set( |
823 | 0 | error, |
824 | 0 | LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
825 | 0 | LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, |
826 | 0 | "%s: invalid security descriptor.", |
827 | 0 | function ); |
828 | |
|
829 | 0 | return( -1 ); |
830 | 0 | } |
831 | 0 | internal_security_descriptor = (libfwnt_internal_security_descriptor_t *) security_descriptor; |
832 | |
|
833 | 0 | if( security_identifier == NULL ) |
834 | 0 | { |
835 | 0 | libcerror_error_set( |
836 | 0 | error, |
837 | 0 | LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
838 | 0 | LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, |
839 | 0 | "%s: invalid security identifier.", |
840 | 0 | function ); |
841 | |
|
842 | 0 | return( -1 ); |
843 | 0 | } |
844 | 0 | if( *security_identifier != NULL ) |
845 | 0 | { |
846 | 0 | libcerror_error_set( |
847 | 0 | error, |
848 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
849 | 0 | LIBCERROR_RUNTIME_ERROR_VALUE_ALREADY_SET, |
850 | 0 | "%s: invalid security identifier value already set.", |
851 | 0 | function ); |
852 | |
|
853 | 0 | return( -1 ); |
854 | 0 | } |
855 | 0 | if( internal_security_descriptor->owner_sid == NULL ) |
856 | 0 | { |
857 | 0 | return( 0 ); |
858 | 0 | } |
859 | 0 | *security_identifier = internal_security_descriptor->owner_sid; |
860 | |
|
861 | 0 | return( 1 ); |
862 | 0 | } |
863 | | |
864 | | /* Retrieves the group security identifier (SID) |
865 | | * Returns 1 if successful, 0 if not available or -1 on error |
866 | | */ |
867 | | int libfwnt_security_descriptor_get_group( |
868 | | libfwnt_security_descriptor_t *security_descriptor, |
869 | | libfwnt_security_identifier_t **security_identifier, |
870 | | libcerror_error_t **error ) |
871 | 0 | { |
872 | 0 | libfwnt_internal_security_descriptor_t *internal_security_descriptor = NULL; |
873 | 0 | static char *function = "libfwnt_security_descriptor_get_group"; |
874 | |
|
875 | 0 | if( security_descriptor == NULL ) |
876 | 0 | { |
877 | 0 | libcerror_error_set( |
878 | 0 | error, |
879 | 0 | LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
880 | 0 | LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, |
881 | 0 | "%s: invalid security descriptor.", |
882 | 0 | function ); |
883 | |
|
884 | 0 | return( -1 ); |
885 | 0 | } |
886 | 0 | internal_security_descriptor = (libfwnt_internal_security_descriptor_t *) security_descriptor; |
887 | |
|
888 | 0 | if( security_identifier == NULL ) |
889 | 0 | { |
890 | 0 | libcerror_error_set( |
891 | 0 | error, |
892 | 0 | LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
893 | 0 | LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, |
894 | 0 | "%s: invalid security identifier.", |
895 | 0 | function ); |
896 | |
|
897 | 0 | return( -1 ); |
898 | 0 | } |
899 | 0 | if( *security_identifier != NULL ) |
900 | 0 | { |
901 | 0 | libcerror_error_set( |
902 | 0 | error, |
903 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
904 | 0 | LIBCERROR_RUNTIME_ERROR_VALUE_ALREADY_SET, |
905 | 0 | "%s: invalid security identifier value already set.", |
906 | 0 | function ); |
907 | |
|
908 | 0 | return( -1 ); |
909 | 0 | } |
910 | 0 | if( internal_security_descriptor->group_sid == NULL ) |
911 | 0 | { |
912 | 0 | return( 0 ); |
913 | 0 | } |
914 | 0 | *security_identifier = internal_security_descriptor->group_sid; |
915 | |
|
916 | 0 | return( 1 ); |
917 | 0 | } |
918 | | |
919 | | /* Retrieves the discretionary access control list (ACL) |
920 | | * Returns 1 if successful, 0 if not available or -1 on error |
921 | | */ |
922 | | int libfwnt_security_descriptor_get_discretionary_acl( |
923 | | libfwnt_security_descriptor_t *security_descriptor, |
924 | | libfwnt_access_control_list_t **access_control_list, |
925 | | libcerror_error_t **error ) |
926 | 0 | { |
927 | 0 | libfwnt_internal_security_descriptor_t *internal_security_descriptor = NULL; |
928 | 0 | static char *function = "libfwnt_security_descriptor_get_discretionary_acl"; |
929 | |
|
930 | 0 | if( security_descriptor == NULL ) |
931 | 0 | { |
932 | 0 | libcerror_error_set( |
933 | 0 | error, |
934 | 0 | LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
935 | 0 | LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, |
936 | 0 | "%s: invalid security descriptor.", |
937 | 0 | function ); |
938 | |
|
939 | 0 | return( -1 ); |
940 | 0 | } |
941 | 0 | internal_security_descriptor = (libfwnt_internal_security_descriptor_t *) security_descriptor; |
942 | |
|
943 | 0 | if( access_control_list == NULL ) |
944 | 0 | { |
945 | 0 | libcerror_error_set( |
946 | 0 | error, |
947 | 0 | LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
948 | 0 | LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, |
949 | 0 | "%s: invalid access control list.", |
950 | 0 | function ); |
951 | |
|
952 | 0 | return( -1 ); |
953 | 0 | } |
954 | 0 | if( *access_control_list != NULL ) |
955 | 0 | { |
956 | 0 | libcerror_error_set( |
957 | 0 | error, |
958 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
959 | 0 | LIBCERROR_RUNTIME_ERROR_VALUE_ALREADY_SET, |
960 | 0 | "%s: invalid access control list value already set.", |
961 | 0 | function ); |
962 | |
|
963 | 0 | return( -1 ); |
964 | 0 | } |
965 | 0 | if( internal_security_descriptor->discretionary_acl == NULL ) |
966 | 0 | { |
967 | 0 | return( 0 ); |
968 | 0 | } |
969 | 0 | *access_control_list = internal_security_descriptor->discretionary_acl; |
970 | |
|
971 | 0 | return( 1 ); |
972 | 0 | } |
973 | | |
974 | | /* Retrieves the system access control list (ACL) |
975 | | * Returns 1 if successful, 0 if not available or -1 on error |
976 | | */ |
977 | | int libfwnt_security_descriptor_get_system_acl( |
978 | | libfwnt_security_descriptor_t *security_descriptor, |
979 | | libfwnt_access_control_list_t **access_control_list, |
980 | | libcerror_error_t **error ) |
981 | 0 | { |
982 | 0 | libfwnt_internal_security_descriptor_t *internal_security_descriptor = NULL; |
983 | 0 | static char *function = "libfwnt_security_descriptor_get_system_acl"; |
984 | |
|
985 | 0 | if( security_descriptor == NULL ) |
986 | 0 | { |
987 | 0 | libcerror_error_set( |
988 | 0 | error, |
989 | 0 | LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
990 | 0 | LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, |
991 | 0 | "%s: invalid security descriptor.", |
992 | 0 | function ); |
993 | |
|
994 | 0 | return( -1 ); |
995 | 0 | } |
996 | 0 | internal_security_descriptor = (libfwnt_internal_security_descriptor_t *) security_descriptor; |
997 | |
|
998 | 0 | if( access_control_list == NULL ) |
999 | 0 | { |
1000 | 0 | libcerror_error_set( |
1001 | 0 | error, |
1002 | 0 | LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
1003 | 0 | LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, |
1004 | 0 | "%s: invalid access control list.", |
1005 | 0 | function ); |
1006 | |
|
1007 | 0 | return( -1 ); |
1008 | 0 | } |
1009 | 0 | if( *access_control_list != NULL ) |
1010 | 0 | { |
1011 | 0 | libcerror_error_set( |
1012 | 0 | error, |
1013 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
1014 | 0 | LIBCERROR_RUNTIME_ERROR_VALUE_ALREADY_SET, |
1015 | 0 | "%s: invalid access control list value already set.", |
1016 | 0 | function ); |
1017 | |
|
1018 | 0 | return( -1 ); |
1019 | 0 | } |
1020 | 0 | if( internal_security_descriptor->system_acl == NULL ) |
1021 | 0 | { |
1022 | 0 | return( 0 ); |
1023 | 0 | } |
1024 | 0 | *access_control_list = internal_security_descriptor->system_acl; |
1025 | |
|
1026 | 0 | return( 1 ); |
1027 | 0 | } |
1028 | | |