/src/libfsext/libfsext/libfsext_attribute_values.c
Line | Count | Source (jump to first uncovered line) |
1 | | /* |
2 | | * Extended attribute values functions |
3 | | * |
4 | | * Copyright (C) 2010-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 <types.h> |
27 | | |
28 | | #include "libfsext_attribute_values.h" |
29 | | #include "libfsext_debug.h" |
30 | | #include "libfsext_libcerror.h" |
31 | | #include "libfsext_libcnotify.h" |
32 | | #include "libfsext_libuna.h" |
33 | | |
34 | | #include "fsext_attributes.h" |
35 | | |
36 | | /* Creates a attribute values |
37 | | * Make sure the value attribute_values is referencing, is set to NULL |
38 | | * Returns 1 if successful or -1 on error |
39 | | */ |
40 | | int libfsext_attribute_values_initialize( |
41 | | libfsext_attribute_values_t **attribute_values, |
42 | | libcerror_error_t **error ) |
43 | 2.47k | { |
44 | 2.47k | static char *function = "libfsext_attribute_values_initialize"; |
45 | | |
46 | 2.47k | if( attribute_values == NULL ) |
47 | 0 | { |
48 | 0 | libcerror_error_set( |
49 | 0 | error, |
50 | 0 | LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
51 | 0 | LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, |
52 | 0 | "%s: invalid attribute values.", |
53 | 0 | function ); |
54 | |
|
55 | 0 | return( -1 ); |
56 | 0 | } |
57 | 2.47k | if( *attribute_values != NULL ) |
58 | 0 | { |
59 | 0 | libcerror_error_set( |
60 | 0 | error, |
61 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
62 | 0 | LIBCERROR_RUNTIME_ERROR_VALUE_ALREADY_SET, |
63 | 0 | "%s: invalid attribute values value already set.", |
64 | 0 | function ); |
65 | |
|
66 | 0 | return( -1 ); |
67 | 0 | } |
68 | 2.47k | *attribute_values = memory_allocate_structure( |
69 | 2.47k | libfsext_attribute_values_t ); |
70 | | |
71 | 2.47k | if( *attribute_values == NULL ) |
72 | 0 | { |
73 | 0 | libcerror_error_set( |
74 | 0 | error, |
75 | 0 | LIBCERROR_ERROR_DOMAIN_MEMORY, |
76 | 0 | LIBCERROR_MEMORY_ERROR_INSUFFICIENT, |
77 | 0 | "%s: unable to create attribute values.", |
78 | 0 | function ); |
79 | |
|
80 | 0 | goto on_error; |
81 | 0 | } |
82 | 2.47k | if( memory_set( |
83 | 2.47k | *attribute_values, |
84 | 2.47k | 0, |
85 | 2.47k | sizeof( libfsext_attribute_values_t ) ) == NULL ) |
86 | 0 | { |
87 | 0 | libcerror_error_set( |
88 | 0 | error, |
89 | 0 | LIBCERROR_ERROR_DOMAIN_MEMORY, |
90 | 0 | LIBCERROR_MEMORY_ERROR_SET_FAILED, |
91 | 0 | "%s: unable to clear attribute values.", |
92 | 0 | function ); |
93 | |
|
94 | 0 | goto on_error; |
95 | 0 | } |
96 | 2.47k | return( 1 ); |
97 | | |
98 | 0 | on_error: |
99 | 0 | if( *attribute_values != NULL ) |
100 | 0 | { |
101 | 0 | memory_free( |
102 | 0 | *attribute_values ); |
103 | |
|
104 | 0 | *attribute_values = NULL; |
105 | 0 | } |
106 | 0 | return( -1 ); |
107 | 2.47k | } |
108 | | |
109 | | /* Frees a attribute values |
110 | | * Returns 1 if successful or -1 on error |
111 | | */ |
112 | | int libfsext_attribute_values_free( |
113 | | libfsext_attribute_values_t **attribute_values, |
114 | | libcerror_error_t **error ) |
115 | 2.47k | { |
116 | 2.47k | static char *function = "libfsext_attribute_values_free"; |
117 | | |
118 | 2.47k | if( attribute_values == NULL ) |
119 | 0 | { |
120 | 0 | libcerror_error_set( |
121 | 0 | error, |
122 | 0 | LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
123 | 0 | LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, |
124 | 0 | "%s: invalid attribute values.", |
125 | 0 | function ); |
126 | |
|
127 | 0 | return( -1 ); |
128 | 0 | } |
129 | 2.47k | if( *attribute_values != NULL ) |
130 | 2.47k | { |
131 | 2.47k | if( ( *attribute_values )->value_data != NULL ) |
132 | 198 | { |
133 | 198 | memory_free( |
134 | 198 | ( *attribute_values )->value_data ); |
135 | 198 | } |
136 | 2.47k | if( ( *attribute_values )->name != NULL ) |
137 | 1.64k | { |
138 | 1.64k | memory_free( |
139 | 1.64k | ( *attribute_values )->name ); |
140 | 1.64k | } |
141 | 2.47k | memory_free( |
142 | 2.47k | *attribute_values ); |
143 | | |
144 | 2.47k | *attribute_values = NULL; |
145 | 2.47k | } |
146 | 2.47k | return( 1 ); |
147 | 2.47k | } |
148 | | |
149 | | /* Reads the attribute values data |
150 | | * Returns 1 if successful or -1 on error |
151 | | */ |
152 | | int libfsext_attribute_values_read_data( |
153 | | libfsext_attribute_values_t *attribute_values, |
154 | | const uint8_t *data, |
155 | | size_t data_size, |
156 | | libcerror_error_t **error ) |
157 | 2.47k | { |
158 | 2.47k | static char *function = "libfsext_attribute_values_read_data"; |
159 | 2.47k | const char *name_prefix = NULL; |
160 | 2.47k | size_t name_prefix_length = 0; |
161 | 2.47k | uint8_t name_index = 0; |
162 | 2.47k | uint8_t name_size = 0; |
163 | | |
164 | | #if defined( HAVE_DEBUG_OUTPUT ) |
165 | | uint32_t value_32bit = 0; |
166 | | #endif |
167 | | |
168 | 2.47k | if( attribute_values == NULL ) |
169 | 0 | { |
170 | 0 | libcerror_error_set( |
171 | 0 | error, |
172 | 0 | LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
173 | 0 | LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, |
174 | 0 | "%s: invalid attribute values.", |
175 | 0 | function ); |
176 | |
|
177 | 0 | return( -1 ); |
178 | 0 | } |
179 | 2.47k | if( data == NULL ) |
180 | 0 | { |
181 | 0 | libcerror_error_set( |
182 | 0 | error, |
183 | 0 | LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
184 | 0 | LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, |
185 | 0 | "%s: invalid data.", |
186 | 0 | function ); |
187 | |
|
188 | 0 | return( -1 ); |
189 | 0 | } |
190 | 2.47k | if( ( data_size < sizeof( fsext_attributes_entry_t ) ) |
191 | 2.47k | || ( data_size > (size_t) SSIZE_MAX ) ) |
192 | 0 | { |
193 | 0 | libcerror_error_set( |
194 | 0 | error, |
195 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
196 | 0 | LIBCERROR_RUNTIME_ERROR_VALUE_OUT_OF_BOUNDS, |
197 | 0 | "%s: invalid data size value out of bounds.", |
198 | 0 | function ); |
199 | |
|
200 | 0 | return( -1 ); |
201 | 0 | } |
202 | 2.47k | name_size = ( (fsext_attributes_entry_t *) data )->name_size; |
203 | | |
204 | 2.47k | if( name_size > ( data_size - sizeof( fsext_attributes_entry_t ) ) ) |
205 | 12 | { |
206 | 12 | libcerror_error_set( |
207 | 12 | error, |
208 | 12 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
209 | 12 | LIBCERROR_RUNTIME_ERROR_VALUE_OUT_OF_BOUNDS, |
210 | 12 | "%s: invalid name size value out of bounds.", |
211 | 12 | function ); |
212 | | |
213 | 12 | goto on_error; |
214 | 12 | } |
215 | | #if defined( HAVE_DEBUG_OUTPUT ) |
216 | | if( libcnotify_verbose != 0 ) |
217 | | { |
218 | | libcnotify_printf( |
219 | | "%s: extended attributes entry data:\n", |
220 | | function ); |
221 | | libcnotify_print_data( |
222 | | data, |
223 | | sizeof( fsext_attributes_entry_t ) + name_size, |
224 | | LIBCNOTIFY_PRINT_DATA_FLAG_GROUP_DATA ); |
225 | | } |
226 | | #endif /* defined( HAVE_DEBUG_OUTPUT ) */ |
227 | | |
228 | 2.46k | name_index = ( (fsext_attributes_entry_t *) data )->name_index; |
229 | | |
230 | 2.46k | byte_stream_copy_to_uint16_little_endian( |
231 | 2.46k | ( (fsext_attributes_entry_t *) data )->value_data_offset, |
232 | 2.46k | attribute_values->value_data_offset ); |
233 | | |
234 | 2.46k | byte_stream_copy_to_uint32_little_endian( |
235 | 2.46k | ( (fsext_attributes_entry_t *) data )->value_data_inode_number, |
236 | 2.46k | attribute_values->value_data_inode_number ); |
237 | | |
238 | 2.46k | byte_stream_copy_to_uint32_little_endian( |
239 | 2.46k | ( (fsext_attributes_entry_t *) data )->value_data_size, |
240 | 2.46k | attribute_values->value_data_size ); |
241 | | |
242 | | #if defined( HAVE_DEBUG_OUTPUT ) |
243 | | if( libcnotify_verbose != 0 ) |
244 | | { |
245 | | libcnotify_printf( |
246 | | "%s: name size\t\t\t\t: %" PRIu8 "\n", |
247 | | function, |
248 | | name_size ); |
249 | | |
250 | | libcnotify_printf( |
251 | | "%s: name index\t\t\t\t: %" PRIu8 "\n", |
252 | | function, |
253 | | name_index ); |
254 | | |
255 | | libcnotify_printf( |
256 | | "%s: value data offset\t\t\t: %" PRIu16 "\n", |
257 | | function, |
258 | | attribute_values->value_data_offset ); |
259 | | |
260 | | libcnotify_printf( |
261 | | "%s: value data inode number\t\t: %" PRIu32 "\n", |
262 | | function, |
263 | | attribute_values->value_data_inode_number ); |
264 | | |
265 | | libcnotify_printf( |
266 | | "%s: value data size\t\t\t: %" PRIu32 "\n", |
267 | | function, |
268 | | attribute_values->value_data_size ); |
269 | | |
270 | | byte_stream_copy_to_uint32_little_endian( |
271 | | ( (fsext_attributes_entry_t *) data )->attribute_hash, |
272 | | value_32bit ); |
273 | | libcnotify_printf( |
274 | | "%s: attribute hash\t\t\t: 0x%08" PRIx32 "\n", |
275 | | function, |
276 | | value_32bit ); |
277 | | } |
278 | | #endif /* defined( HAVE_DEBUG_OUTPUT ) */ |
279 | | |
280 | 2.46k | switch( name_index ) |
281 | 2.46k | { |
282 | 1.33k | case 0: |
283 | 1.33k | name_prefix = ""; |
284 | 1.33k | break; |
285 | | |
286 | 499 | case 1: |
287 | 499 | name_prefix = "user."; |
288 | 499 | break; |
289 | | |
290 | 202 | case 2: |
291 | 202 | name_prefix = "system.posix_acl_access"; |
292 | 202 | break; |
293 | | |
294 | 133 | case 3: |
295 | 133 | name_prefix = "system.posix_acl_default"; |
296 | 133 | break; |
297 | | |
298 | 81 | case 4: |
299 | 81 | name_prefix = "trusted."; |
300 | 81 | break; |
301 | | |
302 | 38 | case 6: |
303 | 38 | name_prefix = "security."; |
304 | 38 | break; |
305 | | |
306 | 31 | case 7: |
307 | 31 | name_prefix = "system."; |
308 | 31 | break; |
309 | | |
310 | 123 | case 8: |
311 | 123 | name_prefix = "system.richacl"; |
312 | 123 | break; |
313 | | |
314 | 21 | default: |
315 | 21 | libcerror_error_set( |
316 | 21 | error, |
317 | 21 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
318 | 21 | LIBCERROR_RUNTIME_ERROR_UNSUPPORTED_VALUE, |
319 | 21 | "%s: unsupported name index: %" PRIu8 ".", |
320 | 21 | function, |
321 | 21 | name_index ); |
322 | | |
323 | 21 | return( -1 ); |
324 | 2.46k | } |
325 | 2.44k | name_prefix_length = narrow_string_length( |
326 | 2.44k | name_prefix ); |
327 | | |
328 | 2.44k | if( ( name_prefix_length > 0 ) || ( name_size > 0 ) ) |
329 | 1.64k | { |
330 | 1.64k | attribute_values->name_size = name_prefix_length + name_size + 1; |
331 | | |
332 | 1.64k | if( attribute_values->name_size > (size_t) MEMORY_MAXIMUM_ALLOCATION_SIZE ) |
333 | 0 | { |
334 | 0 | libcerror_error_set( |
335 | 0 | error, |
336 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
337 | 0 | LIBCERROR_RUNTIME_ERROR_VALUE_OUT_OF_BOUNDS, |
338 | 0 | "%s: invalid name size value out of bounds.", |
339 | 0 | function ); |
340 | |
|
341 | 0 | return( -1 ); |
342 | 0 | } |
343 | 1.64k | attribute_values->name = (uint8_t *) memory_allocate( |
344 | 1.64k | sizeof( uint8_t ) * attribute_values->name_size ); |
345 | | |
346 | 1.64k | if( attribute_values->name == NULL ) |
347 | 0 | { |
348 | 0 | libcerror_error_set( |
349 | 0 | error, |
350 | 0 | LIBCERROR_ERROR_DOMAIN_MEMORY, |
351 | 0 | LIBCERROR_MEMORY_ERROR_INSUFFICIENT, |
352 | 0 | "%s: unable to create name.", |
353 | 0 | function ); |
354 | |
|
355 | 0 | goto on_error; |
356 | 0 | } |
357 | 1.64k | if( name_prefix_length > 0 ) |
358 | 1.10k | { |
359 | 1.10k | if( memory_copy( |
360 | 1.10k | attribute_values->name, |
361 | 1.10k | name_prefix, |
362 | 1.10k | name_prefix_length ) == NULL ) |
363 | 0 | { |
364 | 0 | libcerror_error_set( |
365 | 0 | error, |
366 | 0 | LIBCERROR_ERROR_DOMAIN_MEMORY, |
367 | 0 | LIBCERROR_MEMORY_ERROR_COPY_FAILED, |
368 | 0 | "%s: unable to copy name prefix to extended attribute name.", |
369 | 0 | function ); |
370 | |
|
371 | 0 | goto on_error; |
372 | 0 | } |
373 | 1.10k | } |
374 | 1.64k | if( name_size > 0 ) |
375 | 1.05k | { |
376 | 1.05k | if( memory_copy( |
377 | 1.05k | &( ( attribute_values->name )[ name_prefix_length ] ), |
378 | 1.05k | &( data[ sizeof( fsext_attributes_entry_t ) ] ), |
379 | 1.05k | name_size ) == NULL ) |
380 | 0 | { |
381 | 0 | libcerror_error_set( |
382 | 0 | error, |
383 | 0 | LIBCERROR_ERROR_DOMAIN_MEMORY, |
384 | 0 | LIBCERROR_MEMORY_ERROR_COPY_FAILED, |
385 | 0 | "%s: unable to copy name to extended attribute name.", |
386 | 0 | function ); |
387 | |
|
388 | 0 | goto on_error; |
389 | 0 | } |
390 | 1.05k | } |
391 | 1.64k | ( attribute_values->name )[ attribute_values->name_size - 1 ] = 0; |
392 | | |
393 | | #if defined( HAVE_DEBUG_OUTPUT ) |
394 | | if( libcnotify_verbose != 0 ) |
395 | | { |
396 | | if( libfsext_debug_print_utf8_string_value( |
397 | | function, |
398 | | "name\t\t\t\t", |
399 | | attribute_values->name, |
400 | | attribute_values->name_size, |
401 | | error ) != 1 ) |
402 | | { |
403 | | libcerror_error_set( |
404 | | error, |
405 | | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
406 | | LIBCERROR_RUNTIME_ERROR_PRINT_FAILED, |
407 | | "%s: unable to print UTF-8 string value.", |
408 | | function ); |
409 | | |
410 | | goto on_error; |
411 | | } |
412 | | } |
413 | | #endif /* defined( HAVE_DEBUG_OUTPUT ) */ |
414 | 1.64k | } |
415 | | |
416 | | #if defined( HAVE_DEBUG_OUTPUT ) |
417 | | if( libcnotify_verbose != 0 ) |
418 | | { |
419 | | libcnotify_printf( |
420 | | "\n" ); |
421 | | } |
422 | | #endif /* defined( HAVE_DEBUG_OUTPUT ) */ |
423 | | |
424 | 2.44k | return( 1 ); |
425 | | |
426 | 12 | on_error: |
427 | 12 | if( attribute_values->name != NULL ) |
428 | 0 | { |
429 | 0 | memory_free( |
430 | 0 | attribute_values->name ); |
431 | |
|
432 | 0 | attribute_values->name = NULL; |
433 | 0 | } |
434 | 12 | attribute_values->name_size = 0; |
435 | | |
436 | 12 | return( -1 ); |
437 | 2.44k | } |
438 | | |
439 | | /* Compares an UTF-8 string with an attribute name |
440 | | * Returns LIBUNA_COMPARE_LESS, LIBUNA_COMPARE_EQUAL, LIBUNA_COMPARE_GREATER if successful or -1 on error |
441 | | */ |
442 | | int libfsext_attribute_values_compare_name_with_utf8_string( |
443 | | libfsext_attribute_values_t *attribute_values, |
444 | | const uint8_t *utf8_string, |
445 | | size_t utf8_string_length, |
446 | | libcerror_error_t **error ) |
447 | 0 | { |
448 | 0 | static char *function = "libfsext_attribute_values_compare_name_with_utf8_string"; |
449 | 0 | int result = 0; |
450 | |
|
451 | 0 | if( attribute_values == NULL ) |
452 | 0 | { |
453 | 0 | libcerror_error_set( |
454 | 0 | error, |
455 | 0 | LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
456 | 0 | LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, |
457 | 0 | "%s: invalid attribute values.", |
458 | 0 | function ); |
459 | |
|
460 | 0 | return( -1 ); |
461 | 0 | } |
462 | 0 | result = libuna_utf8_string_compare_with_utf8_stream( |
463 | 0 | utf8_string, |
464 | 0 | utf8_string_length, |
465 | 0 | attribute_values->name, |
466 | 0 | attribute_values->name_size, |
467 | 0 | error ); |
468 | |
|
469 | 0 | if( result == -1 ) |
470 | 0 | { |
471 | 0 | libcerror_error_set( |
472 | 0 | error, |
473 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
474 | 0 | LIBCERROR_RUNTIME_ERROR_GENERIC, |
475 | 0 | "%s: unable to compare UTF-8 string with name.", |
476 | 0 | function ); |
477 | |
|
478 | 0 | return( -1 ); |
479 | 0 | } |
480 | 0 | return( result ); |
481 | 0 | } |
482 | | |
483 | | /* Retrieves the size of the UTF-8 encoded name |
484 | | * The returned size includes the end of string character |
485 | | * Returns 1 if successfulor -1 on error |
486 | | */ |
487 | | int libfsext_attribute_values_get_utf8_name_size( |
488 | | libfsext_attribute_values_t *attribute_values, |
489 | | size_t *utf8_string_size, |
490 | | libcerror_error_t **error ) |
491 | 0 | { |
492 | 0 | static char *function = "libfsext_attribute_values_get_utf8_name_size"; |
493 | |
|
494 | 0 | if( attribute_values == NULL ) |
495 | 0 | { |
496 | 0 | libcerror_error_set( |
497 | 0 | error, |
498 | 0 | LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
499 | 0 | LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, |
500 | 0 | "%s: invalid attribute values.", |
501 | 0 | function ); |
502 | |
|
503 | 0 | return( -1 ); |
504 | 0 | } |
505 | 0 | if( attribute_values->name == NULL ) |
506 | 0 | { |
507 | 0 | if( utf8_string_size == NULL ) |
508 | 0 | { |
509 | 0 | libcerror_error_set( |
510 | 0 | error, |
511 | 0 | LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
512 | 0 | LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, |
513 | 0 | "%s: invalid UTF-8 string size.", |
514 | 0 | function ); |
515 | |
|
516 | 0 | return( -1 ); |
517 | 0 | } |
518 | 0 | *utf8_string_size = 0; |
519 | 0 | } |
520 | 0 | else |
521 | 0 | { |
522 | 0 | if( libuna_utf8_string_size_from_utf8_stream( |
523 | 0 | attribute_values->name, |
524 | 0 | (size_t) attribute_values->name_size, |
525 | 0 | utf8_string_size, |
526 | 0 | error ) != 1 ) |
527 | 0 | { |
528 | 0 | libcerror_error_set( |
529 | 0 | error, |
530 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
531 | 0 | LIBCERROR_RUNTIME_ERROR_GET_FAILED, |
532 | 0 | "%s: unable to retrieve UTF-8 string size.", |
533 | 0 | function ); |
534 | |
|
535 | 0 | return( -1 ); |
536 | 0 | } |
537 | 0 | } |
538 | 0 | return( 1 ); |
539 | 0 | } |
540 | | |
541 | | /* Retrieves the UTF-8 encoded name |
542 | | * The size should include the end of string character |
543 | | * Returns 1 if successful or -1 on error |
544 | | */ |
545 | | int libfsext_attribute_values_get_utf8_name( |
546 | | libfsext_attribute_values_t *attribute_values, |
547 | | uint8_t *utf8_string, |
548 | | size_t utf8_string_size, |
549 | | libcerror_error_t **error ) |
550 | 0 | { |
551 | 0 | static char *function = "libfsext_attribute_values_get_utf8_name"; |
552 | |
|
553 | 0 | if( attribute_values == NULL ) |
554 | 0 | { |
555 | 0 | libcerror_error_set( |
556 | 0 | error, |
557 | 0 | LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
558 | 0 | LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, |
559 | 0 | "%s: invalid attribute values.", |
560 | 0 | function ); |
561 | |
|
562 | 0 | return( -1 ); |
563 | 0 | } |
564 | 0 | if( libuna_utf8_string_copy_from_utf8_stream( |
565 | 0 | utf8_string, |
566 | 0 | utf8_string_size, |
567 | 0 | attribute_values->name, |
568 | 0 | (size_t) attribute_values->name_size, |
569 | 0 | error ) != 1 ) |
570 | 0 | { |
571 | 0 | libcerror_error_set( |
572 | 0 | error, |
573 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
574 | 0 | LIBCERROR_RUNTIME_ERROR_GET_FAILED, |
575 | 0 | "%s: unable to retrieve UTF-8 string.", |
576 | 0 | function ); |
577 | |
|
578 | 0 | return( -1 ); |
579 | 0 | } |
580 | 0 | return( 1 ); |
581 | 0 | } |
582 | | |
583 | | /* Compares an UTF-16 string with an attribute name |
584 | | * Returns LIBUNA_COMPARE_LESS, LIBUNA_COMPARE_EQUAL, LIBUNA_COMPARE_GREATER if successful or -1 on error |
585 | | */ |
586 | | int libfsext_attribute_values_compare_name_with_utf16_string( |
587 | | libfsext_attribute_values_t *attribute_values, |
588 | | const uint16_t *utf16_string, |
589 | | size_t utf16_string_length, |
590 | | libcerror_error_t **error ) |
591 | 0 | { |
592 | 0 | static char *function = "libfsext_attribute_values_compare_name_with_utf16_string"; |
593 | 0 | int result = 0; |
594 | |
|
595 | 0 | if( attribute_values == NULL ) |
596 | 0 | { |
597 | 0 | libcerror_error_set( |
598 | 0 | error, |
599 | 0 | LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
600 | 0 | LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, |
601 | 0 | "%s: invalid attribute values.", |
602 | 0 | function ); |
603 | |
|
604 | 0 | return( -1 ); |
605 | 0 | } |
606 | 0 | result = libuna_utf16_string_compare_with_utf8_stream( |
607 | 0 | utf16_string, |
608 | 0 | utf16_string_length, |
609 | 0 | attribute_values->name, |
610 | 0 | attribute_values->name_size, |
611 | 0 | error ); |
612 | |
|
613 | 0 | if( result == -1 ) |
614 | 0 | { |
615 | 0 | libcerror_error_set( |
616 | 0 | error, |
617 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
618 | 0 | LIBCERROR_RUNTIME_ERROR_GENERIC, |
619 | 0 | "%s: unable to compare UTF-16 string with name.", |
620 | 0 | function ); |
621 | |
|
622 | 0 | return( -1 ); |
623 | 0 | } |
624 | 0 | return( result ); |
625 | 0 | } |
626 | | |
627 | | /* Retrieves the size of the UTF-16 encoded name |
628 | | * The returned size includes the end of string character |
629 | | * Returns 1 if successful or -1 on error |
630 | | */ |
631 | | int libfsext_attribute_values_get_utf16_name_size( |
632 | | libfsext_attribute_values_t *attribute_values, |
633 | | size_t *utf16_string_size, |
634 | | libcerror_error_t **error ) |
635 | 0 | { |
636 | 0 | static char *function = "libfsext_attribute_values_get_utf16_name_size"; |
637 | |
|
638 | 0 | if( attribute_values == NULL ) |
639 | 0 | { |
640 | 0 | libcerror_error_set( |
641 | 0 | error, |
642 | 0 | LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
643 | 0 | LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, |
644 | 0 | "%s: invalid attribute values.", |
645 | 0 | function ); |
646 | |
|
647 | 0 | return( -1 ); |
648 | 0 | } |
649 | 0 | if( attribute_values->name == NULL ) |
650 | 0 | { |
651 | 0 | if( utf16_string_size == NULL ) |
652 | 0 | { |
653 | 0 | libcerror_error_set( |
654 | 0 | error, |
655 | 0 | LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
656 | 0 | LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, |
657 | 0 | "%s: invalid UTF-16 string size.", |
658 | 0 | function ); |
659 | |
|
660 | 0 | return( -1 ); |
661 | 0 | } |
662 | 0 | *utf16_string_size = 0; |
663 | 0 | } |
664 | 0 | else |
665 | 0 | { |
666 | 0 | if( libuna_utf16_string_size_from_utf8_stream( |
667 | 0 | attribute_values->name, |
668 | 0 | (size_t) attribute_values->name_size, |
669 | 0 | utf16_string_size, |
670 | 0 | error ) != 1 ) |
671 | 0 | { |
672 | 0 | libcerror_error_set( |
673 | 0 | error, |
674 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
675 | 0 | LIBCERROR_RUNTIME_ERROR_GET_FAILED, |
676 | 0 | "%s: unable to retrieve UTF-16 string size.", |
677 | 0 | function ); |
678 | |
|
679 | 0 | return( -1 ); |
680 | 0 | } |
681 | 0 | } |
682 | 0 | return( 1 ); |
683 | 0 | } |
684 | | |
685 | | /* Retrieves the UTF-16 encoded name |
686 | | * The size should include the end of string character |
687 | | * Returns 1 if successful or -1 on error |
688 | | */ |
689 | | int libfsext_attribute_values_get_utf16_name( |
690 | | libfsext_attribute_values_t *attribute_values, |
691 | | uint16_t *utf16_string, |
692 | | size_t utf16_string_size, |
693 | | libcerror_error_t **error ) |
694 | 0 | { |
695 | 0 | static char *function = "libfsext_attribute_values_get_utf16_name"; |
696 | |
|
697 | 0 | if( attribute_values == NULL ) |
698 | 0 | { |
699 | 0 | libcerror_error_set( |
700 | 0 | error, |
701 | 0 | LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
702 | 0 | LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, |
703 | 0 | "%s: invalid attribute values.", |
704 | 0 | function ); |
705 | |
|
706 | 0 | return( -1 ); |
707 | 0 | } |
708 | 0 | if( libuna_utf16_string_copy_from_utf8_stream( |
709 | 0 | utf16_string, |
710 | 0 | utf16_string_size, |
711 | 0 | attribute_values->name, |
712 | 0 | (size_t) attribute_values->name_size, |
713 | 0 | error ) != 1 ) |
714 | 0 | { |
715 | 0 | libcerror_error_set( |
716 | 0 | error, |
717 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
718 | 0 | LIBCERROR_RUNTIME_ERROR_GET_FAILED, |
719 | 0 | "%s: unable to retrieve UTF-16 string.", |
720 | 0 | function ); |
721 | |
|
722 | 0 | return( -1 ); |
723 | 0 | } |
724 | 0 | return( 1 ); |
725 | 0 | } |
726 | | |