/src/libewf/libewf/libewf_single_files.c
Line | Count | Source |
1 | | /* |
2 | | * Single file entries functions |
3 | | * |
4 | | * Copyright (C) 2006-2026, 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 <memory.h> |
24 | | #include <narrow_string.h> |
25 | | #include <types.h> |
26 | | |
27 | | #include "libewf_definitions.h" |
28 | | #include "libewf_lef_file_entry.h" |
29 | | #include "libewf_lef_permission.h" |
30 | | #include "libewf_lef_source.h" |
31 | | #include "libewf_lef_subject.h" |
32 | | #include "libewf_libbfio.h" |
33 | | #include "libewf_libcdata.h" |
34 | | #include "libewf_libcerror.h" |
35 | | #include "libewf_libcnotify.h" |
36 | | #include "libewf_libfdata.h" |
37 | | #include "libewf_libfvalue.h" |
38 | | #include "libewf_libuna.h" |
39 | | #include "libewf_line_reader.h" |
40 | | #include "libewf_permission_group.h" |
41 | | #include "libewf_single_files.h" |
42 | | |
43 | | /* Creates single files |
44 | | * Make sure the value single_files is referencing, is set to NULL |
45 | | * Returns 1 if successful or -1 on error |
46 | | */ |
47 | | int libewf_single_files_initialize( |
48 | | libewf_single_files_t **single_files, |
49 | | libcerror_error_t **error ) |
50 | 305 | { |
51 | 305 | static char *function = "libewf_single_files_initialize"; |
52 | | |
53 | 305 | if( single_files == NULL ) |
54 | 0 | { |
55 | 0 | libcerror_error_set( |
56 | 0 | error, |
57 | 0 | LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
58 | 0 | LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, |
59 | 0 | "%s: invalid single files.", |
60 | 0 | function ); |
61 | |
|
62 | 0 | return( -1 ); |
63 | 0 | } |
64 | 305 | if( *single_files != NULL ) |
65 | 0 | { |
66 | 0 | libcerror_error_set( |
67 | 0 | error, |
68 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
69 | 0 | LIBCERROR_RUNTIME_ERROR_VALUE_ALREADY_SET, |
70 | 0 | "%s: invalid single files value already set.", |
71 | 0 | function ); |
72 | |
|
73 | 0 | return( -1 ); |
74 | 0 | } |
75 | 305 | *single_files = memory_allocate_structure( |
76 | 305 | libewf_single_files_t ); |
77 | | |
78 | 305 | if( *single_files == NULL ) |
79 | 0 | { |
80 | 0 | libcerror_error_set( |
81 | 0 | error, |
82 | 0 | LIBCERROR_ERROR_DOMAIN_MEMORY, |
83 | 0 | LIBCERROR_MEMORY_ERROR_INSUFFICIENT, |
84 | 0 | "%s: unable to create single files.", |
85 | 0 | function ); |
86 | |
|
87 | 0 | goto on_error; |
88 | 0 | } |
89 | 305 | if( memory_set( |
90 | 305 | *single_files, |
91 | 305 | 0, |
92 | 305 | sizeof( libewf_single_files_t ) ) == NULL ) |
93 | 0 | { |
94 | 0 | libcerror_error_set( |
95 | 0 | error, |
96 | 0 | LIBCERROR_ERROR_DOMAIN_MEMORY, |
97 | 0 | LIBCERROR_MEMORY_ERROR_SET_FAILED, |
98 | 0 | "%s: unable to clear single files.", |
99 | 0 | function ); |
100 | |
|
101 | 0 | memory_free( |
102 | 0 | *single_files ); |
103 | |
|
104 | 0 | *single_files = NULL; |
105 | |
|
106 | 0 | return( -1 ); |
107 | 0 | } |
108 | 305 | if( libcdata_array_initialize( |
109 | 305 | &( ( *single_files )->permission_groups ), |
110 | 305 | 0, |
111 | 305 | error ) != 1 ) |
112 | 0 | { |
113 | 0 | libcerror_error_set( |
114 | 0 | error, |
115 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
116 | 0 | LIBCERROR_RUNTIME_ERROR_INITIALIZE_FAILED, |
117 | 0 | "%s: unable to create permission groups array.", |
118 | 0 | function ); |
119 | |
|
120 | 0 | goto on_error; |
121 | 0 | } |
122 | 305 | if( libcdata_array_initialize( |
123 | 305 | &( ( *single_files )->sources ), |
124 | 305 | 0, |
125 | 305 | error ) != 1 ) |
126 | 0 | { |
127 | 0 | libcerror_error_set( |
128 | 0 | error, |
129 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
130 | 0 | LIBCERROR_RUNTIME_ERROR_INITIALIZE_FAILED, |
131 | 0 | "%s: unable to create sources array.", |
132 | 0 | function ); |
133 | |
|
134 | 0 | goto on_error; |
135 | 0 | } |
136 | 305 | return( 1 ); |
137 | | |
138 | 0 | on_error: |
139 | 0 | if( *single_files != NULL ) |
140 | 0 | { |
141 | 0 | if( ( *single_files )->permission_groups != NULL ) |
142 | 0 | { |
143 | 0 | libcdata_array_free( |
144 | 0 | &( ( *single_files )->permission_groups ), |
145 | 0 | (int (*)(intptr_t **, libcerror_error_t **)) &libewf_permission_group_free, |
146 | 0 | NULL ); |
147 | 0 | } |
148 | 0 | memory_free( |
149 | 0 | *single_files ); |
150 | |
|
151 | 0 | *single_files = NULL; |
152 | 0 | } |
153 | 0 | return( -1 ); |
154 | 305 | } |
155 | | |
156 | | /* Frees single files |
157 | | * Returns 1 if successful or -1 on error |
158 | | */ |
159 | | int libewf_single_files_free( |
160 | | libewf_single_files_t **single_files, |
161 | | libcerror_error_t **error ) |
162 | 305 | { |
163 | 305 | static char *function = "libewf_single_files_free"; |
164 | 305 | int result = 1; |
165 | | |
166 | 305 | if( single_files == NULL ) |
167 | 0 | { |
168 | 0 | libcerror_error_set( |
169 | 0 | error, |
170 | 0 | LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
171 | 0 | LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, |
172 | 0 | "%s: invalid single files.", |
173 | 0 | function ); |
174 | |
|
175 | 0 | return( -1 ); |
176 | 0 | } |
177 | 305 | if( *single_files != NULL ) |
178 | 305 | { |
179 | 305 | if( ( *single_files )->file_entry_tree_root_node != NULL ) |
180 | 0 | { |
181 | 0 | if( libcdata_tree_node_free( |
182 | 0 | &( ( *single_files )->file_entry_tree_root_node ), |
183 | 0 | (int (*)(intptr_t **, libcerror_error_t **)) &libewf_lef_file_entry_free, |
184 | 0 | error ) != 1 ) |
185 | 0 | { |
186 | 0 | libcerror_error_set( |
187 | 0 | error, |
188 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
189 | 0 | LIBCERROR_RUNTIME_ERROR_FINALIZE_FAILED, |
190 | 0 | "%s: unable to free file entry tree root node.", |
191 | 0 | function ); |
192 | |
|
193 | 0 | result = -1; |
194 | 0 | } |
195 | 0 | } |
196 | 305 | if( libcdata_array_free( |
197 | 305 | &( ( *single_files )->sources ), |
198 | 305 | (int (*)(intptr_t **, libcerror_error_t **)) &libewf_lef_source_free, |
199 | 305 | error ) != 1 ) |
200 | 0 | { |
201 | 0 | libcerror_error_set( |
202 | 0 | error, |
203 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
204 | 0 | LIBCERROR_RUNTIME_ERROR_FINALIZE_FAILED, |
205 | 0 | "%s: unable to free sources array.", |
206 | 0 | function ); |
207 | |
|
208 | 0 | result = -1; |
209 | 0 | } |
210 | 305 | if( libcdata_array_free( |
211 | 305 | &( ( *single_files )->permission_groups ), |
212 | 305 | (int (*)(intptr_t **, libcerror_error_t **)) &libewf_permission_group_free, |
213 | 305 | error ) != 1 ) |
214 | 0 | { |
215 | 0 | libcerror_error_set( |
216 | 0 | error, |
217 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
218 | 0 | LIBCERROR_RUNTIME_ERROR_FINALIZE_FAILED, |
219 | 0 | "%s: unable to free permission groups array.", |
220 | 0 | function ); |
221 | |
|
222 | 0 | result = -1; |
223 | 0 | } |
224 | 305 | memory_free( |
225 | 305 | *single_files ); |
226 | | |
227 | 305 | *single_files = NULL; |
228 | 305 | } |
229 | 305 | return( result ); |
230 | 305 | } |
231 | | |
232 | | /* Clones the single files |
233 | | * Returns 1 if successful or -1 on error |
234 | | */ |
235 | | int libewf_single_files_clone( |
236 | | libewf_single_files_t **destination_single_files, |
237 | | libewf_single_files_t *source_single_files, |
238 | | libcerror_error_t **error ) |
239 | 0 | { |
240 | 0 | static char *function = "libewf_single_files_clone"; |
241 | |
|
242 | 0 | if( destination_single_files == NULL ) |
243 | 0 | { |
244 | 0 | libcerror_error_set( |
245 | 0 | error, |
246 | 0 | LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
247 | 0 | LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, |
248 | 0 | "%s: invalid destination single files.", |
249 | 0 | function ); |
250 | |
|
251 | 0 | return( -1 ); |
252 | 0 | } |
253 | 0 | if( *destination_single_files != NULL ) |
254 | 0 | { |
255 | 0 | libcerror_error_set( |
256 | 0 | error, |
257 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
258 | 0 | LIBCERROR_RUNTIME_ERROR_VALUE_ALREADY_SET, |
259 | 0 | "%s: invalid destination single files value already set.", |
260 | 0 | function ); |
261 | |
|
262 | 0 | return( -1 ); |
263 | 0 | } |
264 | 0 | if( source_single_files == NULL ) |
265 | 0 | { |
266 | 0 | *destination_single_files = NULL; |
267 | |
|
268 | 0 | return( 1 ); |
269 | 0 | } |
270 | 0 | *destination_single_files = memory_allocate_structure( |
271 | 0 | libewf_single_files_t ); |
272 | |
|
273 | 0 | if( *destination_single_files == NULL ) |
274 | 0 | { |
275 | 0 | libcerror_error_set( |
276 | 0 | error, |
277 | 0 | LIBCERROR_ERROR_DOMAIN_MEMORY, |
278 | 0 | LIBCERROR_MEMORY_ERROR_INSUFFICIENT, |
279 | 0 | "%s: unable to create destination single files.", |
280 | 0 | function ); |
281 | |
|
282 | 0 | goto on_error; |
283 | 0 | } |
284 | 0 | ( *destination_single_files )->permission_groups = NULL; |
285 | 0 | ( *destination_single_files )->sources = NULL; |
286 | 0 | ( *destination_single_files )->file_entry_tree_root_node = NULL; |
287 | |
|
288 | 0 | if( libcdata_array_clone( |
289 | 0 | &( ( *destination_single_files )->permission_groups ), |
290 | 0 | source_single_files->permission_groups, |
291 | 0 | (int (*)(intptr_t **, libcerror_error_t **)) &libewf_permission_group_free, |
292 | 0 | (int (*)(intptr_t **, intptr_t *, libcerror_error_t **)) &libewf_permission_group_clone, |
293 | 0 | error ) != 1 ) |
294 | 0 | { |
295 | 0 | libcerror_error_set( |
296 | 0 | error, |
297 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
298 | 0 | LIBCERROR_RUNTIME_ERROR_INITIALIZE_FAILED, |
299 | 0 | "%s: unable to create destination permission groups array.", |
300 | 0 | function ); |
301 | |
|
302 | 0 | goto on_error; |
303 | 0 | } |
304 | 0 | if( libcdata_array_clone( |
305 | 0 | &( ( *destination_single_files )->sources ), |
306 | 0 | source_single_files->sources, |
307 | 0 | (int (*)(intptr_t **, libcerror_error_t **)) &libewf_lef_source_free, |
308 | 0 | (int (*)(intptr_t **, intptr_t *, libcerror_error_t **)) &libewf_lef_source_clone, |
309 | 0 | error ) != 1 ) |
310 | 0 | { |
311 | 0 | libcerror_error_set( |
312 | 0 | error, |
313 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
314 | 0 | LIBCERROR_RUNTIME_ERROR_INITIALIZE_FAILED, |
315 | 0 | "%s: unable to create destination sources array.", |
316 | 0 | function ); |
317 | |
|
318 | 0 | goto on_error; |
319 | 0 | } |
320 | 0 | if( libcdata_tree_node_clone( |
321 | 0 | &( ( *destination_single_files )->file_entry_tree_root_node ), |
322 | 0 | source_single_files->file_entry_tree_root_node, |
323 | 0 | (int (*)(intptr_t **, libcerror_error_t **)) &libewf_lef_file_entry_free, |
324 | 0 | (int (*)(intptr_t **, intptr_t *, libcerror_error_t **)) &libewf_lef_file_entry_clone, |
325 | 0 | error ) != 1 ) |
326 | 0 | { |
327 | 0 | libcerror_error_set( |
328 | 0 | error, |
329 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
330 | 0 | LIBCERROR_RUNTIME_ERROR_INITIALIZE_FAILED, |
331 | 0 | "%s: unable to create destination file entry tree root node.", |
332 | 0 | function ); |
333 | |
|
334 | 0 | goto on_error; |
335 | 0 | } |
336 | 0 | return( 1 ); |
337 | | |
338 | 0 | on_error: |
339 | 0 | if( *destination_single_files != NULL ) |
340 | 0 | { |
341 | 0 | libewf_single_files_free( |
342 | 0 | destination_single_files, |
343 | 0 | NULL ); |
344 | 0 | } |
345 | 0 | return( -1 ); |
346 | 0 | } |
347 | | |
348 | | /* Parses the number of entries in a category |
349 | | * Returns 1 if successful or -1 on error |
350 | | */ |
351 | | int libewf_single_files_parse_category_number_of_entries( |
352 | | libewf_single_files_t *single_files, |
353 | | libewf_line_reader_t *line_reader, |
354 | | int *number_of_entries, |
355 | | libcerror_error_t **error ) |
356 | 15 | { |
357 | 15 | libfvalue_split_utf8_string_t *values = NULL; |
358 | 15 | uint8_t *line_string = NULL; |
359 | 15 | uint8_t *value_string = NULL; |
360 | 15 | static char *function = "libewf_single_files_parse_category_number_of_entries"; |
361 | 15 | size_t line_string_size = 0; |
362 | 15 | size_t value_string_size = 0; |
363 | 15 | uint64_t value_64bit = 0; |
364 | 15 | int number_of_values = 0; |
365 | | |
366 | 15 | if( single_files == NULL ) |
367 | 0 | { |
368 | 0 | libcerror_error_set( |
369 | 0 | error, |
370 | 0 | LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
371 | 0 | LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, |
372 | 0 | "%s: invalid single files.", |
373 | 0 | function ); |
374 | |
|
375 | 0 | return( -1 ); |
376 | 0 | } |
377 | 15 | if( line_reader == NULL ) |
378 | 0 | { |
379 | 0 | libcerror_error_set( |
380 | 0 | error, |
381 | 0 | LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
382 | 0 | LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, |
383 | 0 | "%s: invalid line reader.", |
384 | 0 | function ); |
385 | |
|
386 | 0 | return( -1 ); |
387 | 0 | } |
388 | 15 | if( number_of_entries == NULL ) |
389 | 0 | { |
390 | 0 | libcerror_error_set( |
391 | 0 | error, |
392 | 0 | LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
393 | 0 | LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, |
394 | 0 | "%s: invalid number of entries.", |
395 | 0 | function ); |
396 | |
|
397 | 0 | return( -1 ); |
398 | 0 | } |
399 | 15 | if( libewf_line_reader_read_utf8_string( |
400 | 15 | line_reader, |
401 | 15 | &line_string, |
402 | 15 | &line_string_size, |
403 | 15 | error ) != 1 ) |
404 | 1 | { |
405 | 1 | libcerror_error_set( |
406 | 1 | error, |
407 | 1 | LIBCERROR_ERROR_DOMAIN_IO, |
408 | 1 | LIBCERROR_IO_ERROR_READ_FAILED, |
409 | 1 | "%s: unable to read line: %d.", |
410 | 1 | function, |
411 | 1 | line_reader->line_index ); |
412 | | |
413 | 1 | goto on_error; |
414 | 1 | } |
415 | 14 | if( libfvalue_utf8_string_split( |
416 | 14 | line_string, |
417 | 14 | line_string_size, |
418 | 14 | (uint8_t) '\t', |
419 | 14 | &values, |
420 | 14 | error ) != 1 ) |
421 | 0 | { |
422 | 0 | libcerror_error_set( |
423 | 0 | error, |
424 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
425 | 0 | LIBCERROR_RUNTIME_ERROR_INITIALIZE_FAILED, |
426 | 0 | "%s: unable to split line: %d string into values.", |
427 | 0 | function, |
428 | 0 | line_reader->line_index - 1 ); |
429 | |
|
430 | 0 | goto on_error; |
431 | 0 | } |
432 | 14 | if( libfvalue_split_utf8_string_get_number_of_segments( |
433 | 14 | values, |
434 | 14 | &number_of_values, |
435 | 14 | error ) != 1 ) |
436 | 2 | { |
437 | 2 | libcerror_error_set( |
438 | 2 | error, |
439 | 2 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
440 | 2 | LIBCERROR_RUNTIME_ERROR_GET_FAILED, |
441 | 2 | "%s: unable to retrieve number of values", |
442 | 2 | function ); |
443 | | |
444 | 2 | goto on_error; |
445 | 2 | } |
446 | 12 | if( number_of_values != 2 ) |
447 | 3 | { |
448 | 3 | libcerror_error_set( |
449 | 3 | error, |
450 | 3 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
451 | 3 | LIBCERROR_RUNTIME_ERROR_UNSUPPORTED_VALUE, |
452 | 3 | "%s: unsupported number of values.", |
453 | 3 | function ); |
454 | | |
455 | 3 | goto on_error; |
456 | 3 | } |
457 | 9 | if( libfvalue_split_utf8_string_get_segment_by_index( |
458 | 9 | values, |
459 | 9 | 1, |
460 | 9 | &value_string, |
461 | 9 | &value_string_size, |
462 | 9 | error ) != 1 ) |
463 | 0 | { |
464 | 0 | libcerror_error_set( |
465 | 0 | error, |
466 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
467 | 0 | LIBCERROR_RUNTIME_ERROR_GET_FAILED, |
468 | 0 | "%s: unable to retrieve value string: 1.", |
469 | 0 | function ); |
470 | |
|
471 | 0 | goto on_error; |
472 | 0 | } |
473 | 9 | if( ( value_string_size != 2 ) |
474 | 8 | || ( value_string[ 0 ] != (uint8_t) '1' ) ) |
475 | 8 | { |
476 | 8 | libcerror_error_set( |
477 | 8 | error, |
478 | 8 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
479 | 8 | LIBCERROR_RUNTIME_ERROR_UNSUPPORTED_VALUE, |
480 | 8 | "%s: unsupported second value: %s.", |
481 | 8 | function, |
482 | 8 | value_string ); |
483 | | |
484 | 8 | goto on_error; |
485 | 8 | } |
486 | 1 | if( libfvalue_split_utf8_string_get_segment_by_index( |
487 | 1 | values, |
488 | 1 | 0, |
489 | 1 | &value_string, |
490 | 1 | &value_string_size, |
491 | 1 | error ) != 1 ) |
492 | 0 | { |
493 | 0 | libcerror_error_set( |
494 | 0 | error, |
495 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
496 | 0 | LIBCERROR_RUNTIME_ERROR_GET_FAILED, |
497 | 0 | "%s: unable to retrieve value string: 0.", |
498 | 0 | function ); |
499 | |
|
500 | 0 | goto on_error; |
501 | 0 | } |
502 | 1 | if( libfvalue_utf8_string_copy_to_integer( |
503 | 1 | value_string, |
504 | 1 | value_string_size, |
505 | 1 | &value_64bit, |
506 | 1 | 64, |
507 | 1 | LIBFVALUE_INTEGER_FORMAT_TYPE_DECIMAL_UNSIGNED, |
508 | 1 | error ) != 1 ) |
509 | 1 | { |
510 | 1 | libcerror_error_set( |
511 | 1 | error, |
512 | 1 | LIBCERROR_ERROR_DOMAIN_MEMORY, |
513 | 1 | LIBCERROR_MEMORY_ERROR_SET_FAILED, |
514 | 1 | "%s: unable to set number of entries.", |
515 | 1 | function ); |
516 | | |
517 | 1 | goto on_error; |
518 | 1 | } |
519 | 0 | if( value_64bit > (uint64_t) INT_MAX ) |
520 | 0 | { |
521 | 0 | libcerror_error_set( |
522 | 0 | error, |
523 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
524 | 0 | LIBCERROR_RUNTIME_ERROR_VALUE_OUT_OF_BOUNDS, |
525 | 0 | "%s: invalid number of entries value out of bounds.", |
526 | 0 | function ); |
527 | |
|
528 | 0 | goto on_error; |
529 | 0 | } |
530 | 0 | if( libfvalue_split_utf8_string_free( |
531 | 0 | &values, |
532 | 0 | error ) != 1 ) |
533 | 0 | { |
534 | 0 | libcerror_error_set( |
535 | 0 | error, |
536 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
537 | 0 | LIBCERROR_RUNTIME_ERROR_FINALIZE_FAILED, |
538 | 0 | "%s: unable to free split values.", |
539 | 0 | function ); |
540 | |
|
541 | 0 | goto on_error; |
542 | 0 | } |
543 | 0 | *number_of_entries = (int) value_64bit; |
544 | |
|
545 | 0 | return( 1 ); |
546 | | |
547 | 15 | on_error: |
548 | 15 | if( values != NULL ) |
549 | 12 | { |
550 | 12 | libfvalue_split_utf8_string_free( |
551 | 12 | &values, |
552 | 12 | NULL ); |
553 | 12 | } |
554 | 15 | return( -1 ); |
555 | 0 | } |
556 | | |
557 | | /* Parses the types of a category |
558 | | * Returns 1 if successful or -1 on error |
559 | | */ |
560 | | int libewf_single_files_parse_category_types( |
561 | | libewf_single_files_t *single_files, |
562 | | libewf_line_reader_t *line_reader, |
563 | | libfvalue_split_utf8_string_t **types, |
564 | | libcerror_error_t **error ) |
565 | 0 | { |
566 | 0 | uint8_t *line_string = NULL; |
567 | 0 | static char *function = "libewf_single_files_parse_category_types"; |
568 | 0 | size_t line_string_size = 0; |
569 | |
|
570 | 0 | if( single_files == NULL ) |
571 | 0 | { |
572 | 0 | libcerror_error_set( |
573 | 0 | error, |
574 | 0 | LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
575 | 0 | LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, |
576 | 0 | "%s: invalid single files.", |
577 | 0 | function ); |
578 | |
|
579 | 0 | return( -1 ); |
580 | 0 | } |
581 | 0 | if( line_reader == NULL ) |
582 | 0 | { |
583 | 0 | libcerror_error_set( |
584 | 0 | error, |
585 | 0 | LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
586 | 0 | LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, |
587 | 0 | "%s: invalid line reader.", |
588 | 0 | function ); |
589 | |
|
590 | 0 | return( -1 ); |
591 | 0 | } |
592 | 0 | if( libewf_line_reader_read_utf8_string( |
593 | 0 | line_reader, |
594 | 0 | &line_string, |
595 | 0 | &line_string_size, |
596 | 0 | error ) != 1 ) |
597 | 0 | { |
598 | 0 | libcerror_error_set( |
599 | 0 | error, |
600 | 0 | LIBCERROR_ERROR_DOMAIN_IO, |
601 | 0 | LIBCERROR_IO_ERROR_READ_FAILED, |
602 | 0 | "%s: unable to read line: %d.", |
603 | 0 | function, |
604 | 0 | line_reader->line_index ); |
605 | |
|
606 | 0 | return( -1 ); |
607 | 0 | } |
608 | 0 | if( libfvalue_utf8_string_split( |
609 | 0 | line_string, |
610 | 0 | line_string_size, |
611 | 0 | (uint8_t) '\t', |
612 | 0 | types, |
613 | 0 | error ) != 1 ) |
614 | 0 | { |
615 | 0 | libcerror_error_set( |
616 | 0 | error, |
617 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
618 | 0 | LIBCERROR_RUNTIME_ERROR_INITIALIZE_FAILED, |
619 | 0 | "%s: unable to split line: %d into types.", |
620 | 0 | function, |
621 | 0 | line_reader->line_index - 1 ); |
622 | |
|
623 | 0 | return( -1 ); |
624 | 0 | } |
625 | 0 | return( 1 ); |
626 | 0 | } |
627 | | |
628 | | /* Parses the number of entries |
629 | | * Returns 1 if successful or -1 on error |
630 | | */ |
631 | | int libewf_single_files_parse_number_of_entries( |
632 | | libewf_single_files_t *single_files, |
633 | | libewf_line_reader_t *line_reader, |
634 | | int *number_of_entries, |
635 | | libcerror_error_t **error ) |
636 | 0 | { |
637 | 0 | libfvalue_split_utf8_string_t *values = NULL; |
638 | 0 | uint8_t *line_string = NULL; |
639 | 0 | uint8_t *value_string = NULL; |
640 | 0 | static char *function = "libewf_single_files_parse_number_of_entries"; |
641 | 0 | size_t line_string_size = 0; |
642 | 0 | size_t value_string_size = 0; |
643 | 0 | uint64_t value_64bit = 0; |
644 | 0 | int number_of_values = 0; |
645 | |
|
646 | 0 | if( single_files == NULL ) |
647 | 0 | { |
648 | 0 | libcerror_error_set( |
649 | 0 | error, |
650 | 0 | LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
651 | 0 | LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, |
652 | 0 | "%s: invalid single files.", |
653 | 0 | function ); |
654 | |
|
655 | 0 | return( -1 ); |
656 | 0 | } |
657 | 0 | if( line_reader == NULL ) |
658 | 0 | { |
659 | 0 | libcerror_error_set( |
660 | 0 | error, |
661 | 0 | LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
662 | 0 | LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, |
663 | 0 | "%s: invalid line reader.", |
664 | 0 | function ); |
665 | |
|
666 | 0 | return( -1 ); |
667 | 0 | } |
668 | 0 | if( number_of_entries == NULL ) |
669 | 0 | { |
670 | 0 | libcerror_error_set( |
671 | 0 | error, |
672 | 0 | LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
673 | 0 | LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, |
674 | 0 | "%s: invalid number of entries.", |
675 | 0 | function ); |
676 | |
|
677 | 0 | return( -1 ); |
678 | 0 | } |
679 | 0 | if( libewf_line_reader_read_utf8_string( |
680 | 0 | line_reader, |
681 | 0 | &line_string, |
682 | 0 | &line_string_size, |
683 | 0 | error ) != 1 ) |
684 | 0 | { |
685 | 0 | libcerror_error_set( |
686 | 0 | error, |
687 | 0 | LIBCERROR_ERROR_DOMAIN_IO, |
688 | 0 | LIBCERROR_IO_ERROR_READ_FAILED, |
689 | 0 | "%s: unable to read line: %d.", |
690 | 0 | function, |
691 | 0 | line_reader->line_index ); |
692 | |
|
693 | 0 | return( -1 ); |
694 | 0 | } |
695 | 0 | if( libfvalue_utf8_string_split( |
696 | 0 | line_string, |
697 | 0 | line_string_size, |
698 | 0 | (uint8_t) '\t', |
699 | 0 | &values, |
700 | 0 | 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 split line: %d string into values.", |
707 | 0 | function, |
708 | 0 | line_reader->line_index - 1 ); |
709 | |
|
710 | 0 | goto on_error; |
711 | 0 | } |
712 | 0 | if( libfvalue_split_utf8_string_get_number_of_segments( |
713 | 0 | values, |
714 | 0 | &number_of_values, |
715 | 0 | error ) != 1 ) |
716 | 0 | { |
717 | 0 | libcerror_error_set( |
718 | 0 | error, |
719 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
720 | 0 | LIBCERROR_RUNTIME_ERROR_GET_FAILED, |
721 | 0 | "%s: unable to retrieve number of values", |
722 | 0 | function ); |
723 | |
|
724 | 0 | goto on_error; |
725 | 0 | } |
726 | 0 | if( number_of_values != 2 ) |
727 | 0 | { |
728 | 0 | libcerror_error_set( |
729 | 0 | error, |
730 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
731 | 0 | LIBCERROR_RUNTIME_ERROR_UNSUPPORTED_VALUE, |
732 | 0 | "%s: unsupported number of values.", |
733 | 0 | function ); |
734 | |
|
735 | 0 | goto on_error; |
736 | 0 | } |
737 | 0 | if( libfvalue_split_utf8_string_get_segment_by_index( |
738 | 0 | values, |
739 | 0 | 0, |
740 | 0 | &value_string, |
741 | 0 | &value_string_size, |
742 | 0 | error ) != 1 ) |
743 | 0 | { |
744 | 0 | libcerror_error_set( |
745 | 0 | error, |
746 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
747 | 0 | LIBCERROR_RUNTIME_ERROR_GET_FAILED, |
748 | 0 | "%s: unable to retrieve value string: 0.", |
749 | 0 | function ); |
750 | |
|
751 | 0 | goto on_error; |
752 | 0 | } |
753 | 0 | if( ( value_string_size != 2 ) |
754 | 0 | || ( value_string[ 0 ] != (uint8_t) '0' ) ) |
755 | 0 | { |
756 | 0 | libcerror_error_set( |
757 | 0 | error, |
758 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
759 | 0 | LIBCERROR_RUNTIME_ERROR_UNSUPPORTED_VALUE, |
760 | 0 | "%s: unsupported first value: %s.", |
761 | 0 | function, |
762 | 0 | value_string ); |
763 | |
|
764 | 0 | goto on_error; |
765 | 0 | } |
766 | 0 | if( libfvalue_split_utf8_string_get_segment_by_index( |
767 | 0 | values, |
768 | 0 | 1, |
769 | 0 | &value_string, |
770 | 0 | &value_string_size, |
771 | 0 | error ) != 1 ) |
772 | 0 | { |
773 | 0 | libcerror_error_set( |
774 | 0 | error, |
775 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
776 | 0 | LIBCERROR_RUNTIME_ERROR_GET_FAILED, |
777 | 0 | "%s: unable to retrieve value string: 1.", |
778 | 0 | function ); |
779 | |
|
780 | 0 | goto on_error; |
781 | 0 | } |
782 | 0 | if( libfvalue_utf8_string_copy_to_integer( |
783 | 0 | value_string, |
784 | 0 | value_string_size, |
785 | 0 | &value_64bit, |
786 | 0 | 64, |
787 | 0 | LIBFVALUE_INTEGER_FORMAT_TYPE_DECIMAL_UNSIGNED, |
788 | 0 | error ) != 1 ) |
789 | 0 | { |
790 | 0 | libcerror_error_set( |
791 | 0 | error, |
792 | 0 | LIBCERROR_ERROR_DOMAIN_MEMORY, |
793 | 0 | LIBCERROR_MEMORY_ERROR_SET_FAILED, |
794 | 0 | "%s: unable to set number of entries.", |
795 | 0 | function ); |
796 | |
|
797 | 0 | goto on_error; |
798 | 0 | } |
799 | 0 | if( value_64bit > (uint64_t) INT_MAX ) |
800 | 0 | { |
801 | 0 | libcerror_error_set( |
802 | 0 | error, |
803 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
804 | 0 | LIBCERROR_RUNTIME_ERROR_VALUE_OUT_OF_BOUNDS, |
805 | 0 | "%s: invalid number of entries value out of bounds.", |
806 | 0 | function ); |
807 | |
|
808 | 0 | goto on_error; |
809 | 0 | } |
810 | 0 | if( libfvalue_split_utf8_string_free( |
811 | 0 | &values, |
812 | 0 | error ) != 1 ) |
813 | 0 | { |
814 | 0 | libcerror_error_set( |
815 | 0 | error, |
816 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
817 | 0 | LIBCERROR_RUNTIME_ERROR_FINALIZE_FAILED, |
818 | 0 | "%s: unable to free split values.", |
819 | 0 | function ); |
820 | |
|
821 | 0 | goto on_error; |
822 | 0 | } |
823 | 0 | *number_of_entries = (int) value_64bit; |
824 | |
|
825 | 0 | return( 1 ); |
826 | | |
827 | 0 | on_error: |
828 | 0 | if( values != NULL ) |
829 | 0 | { |
830 | 0 | libfvalue_split_utf8_string_free( |
831 | 0 | &values, |
832 | 0 | NULL ); |
833 | 0 | } |
834 | 0 | return( -1 ); |
835 | 0 | } |
836 | | |
837 | | /* Determines the EWF format based on the entry types |
838 | | * Returns 1 if successful or -1 on error |
839 | | */ |
840 | | int libewf_single_files_parse_format( |
841 | | libfvalue_split_utf8_string_t *types, |
842 | | uint8_t *format, |
843 | | libcerror_error_t **error ) |
844 | 0 | { |
845 | 0 | uint8_t *type_string = NULL; |
846 | 0 | static char *function = "libewf_single_files_parse_format"; |
847 | 0 | size_t type_string_size = 0; |
848 | 0 | int number_of_types = 0; |
849 | 0 | int value_index = 0; |
850 | |
|
851 | 0 | if( format == NULL ) |
852 | 0 | { |
853 | 0 | libcerror_error_set( |
854 | 0 | error, |
855 | 0 | LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
856 | 0 | LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, |
857 | 0 | "%s: invalid format.", |
858 | 0 | function ); |
859 | |
|
860 | 0 | return( -1 ); |
861 | 0 | } |
862 | 0 | if( libfvalue_split_utf8_string_get_number_of_segments( |
863 | 0 | types, |
864 | 0 | &number_of_types, |
865 | 0 | error ) != 1 ) |
866 | 0 | { |
867 | 0 | libcerror_error_set( |
868 | 0 | error, |
869 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
870 | 0 | LIBCERROR_RUNTIME_ERROR_GET_FAILED, |
871 | 0 | "%s: unable to retrieve number of types", |
872 | 0 | function ); |
873 | |
|
874 | 0 | return( -1 ); |
875 | 0 | } |
876 | 0 | for( value_index = 0; |
877 | 0 | value_index < number_of_types; |
878 | 0 | value_index++ ) |
879 | 0 | { |
880 | 0 | if( libfvalue_split_utf8_string_get_segment_by_index( |
881 | 0 | types, |
882 | 0 | value_index, |
883 | 0 | &type_string, |
884 | 0 | &type_string_size, |
885 | 0 | error ) != 1 ) |
886 | 0 | { |
887 | 0 | libcerror_error_set( |
888 | 0 | error, |
889 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
890 | 0 | LIBCERROR_RUNTIME_ERROR_GET_FAILED, |
891 | 0 | "%s: unable to retrieve type string: %d.", |
892 | 0 | function, |
893 | 0 | value_index ); |
894 | |
|
895 | 0 | return( -1 ); |
896 | 0 | } |
897 | 0 | if( ( type_string == NULL ) |
898 | 0 | || ( type_string_size < 2 ) |
899 | 0 | || ( type_string[ 0 ] == 0 ) ) |
900 | 0 | { |
901 | 0 | libcerror_error_set( |
902 | 0 | error, |
903 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
904 | 0 | LIBCERROR_RUNTIME_ERROR_VALUE_MISSING, |
905 | 0 | "%s: missing type string: %d.", |
906 | 0 | function, |
907 | 0 | value_index ); |
908 | |
|
909 | 0 | return( -1 ); |
910 | 0 | } |
911 | 0 | if( type_string_size == 3 ) |
912 | 0 | { |
913 | | /* Data offset |
914 | | * consist of: unknown, offset and size |
915 | | */ |
916 | 0 | if( ( type_string[ 0 ] == (uint8_t) 'b' ) |
917 | 0 | && ( type_string[ 1 ] == (uint8_t) 'e' ) ) |
918 | 0 | { |
919 | 0 | if( value_index == 19 ) |
920 | 0 | { |
921 | 0 | *format = LIBEWF_FORMAT_LOGICAL_ENCASE5; |
922 | 0 | } |
923 | 0 | else if( ( value_index == 20 ) |
924 | 0 | || ( value_index == 21 ) ) |
925 | 0 | { |
926 | 0 | *format = LIBEWF_FORMAT_LOGICAL_ENCASE6; |
927 | 0 | } |
928 | 0 | else if( value_index == 2 ) |
929 | 0 | { |
930 | 0 | *format = LIBEWF_FORMAT_LOGICAL_ENCASE7; |
931 | 0 | } |
932 | 0 | } |
933 | 0 | } |
934 | 0 | } |
935 | 0 | return( 1 ); |
936 | 0 | } |
937 | | |
938 | | /* Parses the "rec" category |
939 | | * Returns 1 if successful or -1 on error |
940 | | */ |
941 | | int libewf_single_files_parse_rec_category( |
942 | | libewf_single_files_t *single_files, |
943 | | libewf_line_reader_t *line_reader, |
944 | | size64_t *media_size, |
945 | | libcerror_error_t **error ) |
946 | 82 | { |
947 | 82 | static char *function = "libewf_single_files_parse_rec_category"; |
948 | | |
949 | 82 | if( libewf_single_files_parse_record_values( |
950 | 82 | single_files, |
951 | 82 | line_reader, |
952 | 82 | media_size, |
953 | 82 | error ) != 1 ) |
954 | 11 | { |
955 | 11 | libcerror_error_set( |
956 | 11 | error, |
957 | 11 | LIBCERROR_ERROR_DOMAIN_CONVERSION, |
958 | 11 | LIBCERROR_CONVERSION_ERROR_GENERIC, |
959 | 11 | "%s: unable to parse record values.", |
960 | 11 | function ); |
961 | | |
962 | 11 | return( -1 ); |
963 | 11 | } |
964 | 71 | return( 1 ); |
965 | 82 | } |
966 | | |
967 | | /* Parses a record string for the values |
968 | | * Returns 1 if successful or -1 on error |
969 | | */ |
970 | | int libewf_single_files_parse_record_values( |
971 | | libewf_single_files_t *single_files, |
972 | | libewf_line_reader_t *line_reader, |
973 | | size64_t *media_size, |
974 | | libcerror_error_t **error ) |
975 | 82 | { |
976 | 82 | libfvalue_split_utf8_string_t *types = NULL; |
977 | 82 | libfvalue_split_utf8_string_t *values = NULL; |
978 | 82 | uint8_t *line_string = NULL; |
979 | 82 | uint8_t *type_string = NULL; |
980 | 82 | uint8_t *value_string = NULL; |
981 | 82 | static char *function = "libewf_single_files_parse_record_values"; |
982 | 82 | size_t line_string_size = 0; |
983 | 82 | size_t type_string_size = 0; |
984 | 82 | size_t value_string_size = 0; |
985 | 82 | uint64_t value_64bit = 0; |
986 | 82 | int number_of_types = 0; |
987 | 82 | int number_of_values = 0; |
988 | 82 | int value_index = 0; |
989 | | |
990 | 82 | if( single_files == NULL ) |
991 | 0 | { |
992 | 0 | libcerror_error_set( |
993 | 0 | error, |
994 | 0 | LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
995 | 0 | LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, |
996 | 0 | "%s: invalid single files.", |
997 | 0 | function ); |
998 | |
|
999 | 0 | return( -1 ); |
1000 | 0 | } |
1001 | 82 | if( line_reader == NULL ) |
1002 | 0 | { |
1003 | 0 | libcerror_error_set( |
1004 | 0 | error, |
1005 | 0 | LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
1006 | 0 | LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, |
1007 | 0 | "%s: invalid line reader.", |
1008 | 0 | function ); |
1009 | |
|
1010 | 0 | return( -1 ); |
1011 | 0 | } |
1012 | 82 | if( media_size == NULL ) |
1013 | 0 | { |
1014 | 0 | libcerror_error_set( |
1015 | 0 | error, |
1016 | 0 | LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
1017 | 0 | LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, |
1018 | 0 | "%s: invalid media size.", |
1019 | 0 | function ); |
1020 | |
|
1021 | 0 | return( -1 ); |
1022 | 0 | } |
1023 | 82 | if( libewf_line_reader_read_utf8_string( |
1024 | 82 | line_reader, |
1025 | 82 | &line_string, |
1026 | 82 | &line_string_size, |
1027 | 82 | error ) != 1 ) |
1028 | 1 | { |
1029 | 1 | libcerror_error_set( |
1030 | 1 | error, |
1031 | 1 | LIBCERROR_ERROR_DOMAIN_IO, |
1032 | 1 | LIBCERROR_IO_ERROR_READ_FAILED, |
1033 | 1 | "%s: unable to read line: %d.", |
1034 | 1 | function, |
1035 | 1 | line_reader->line_index ); |
1036 | | |
1037 | 1 | goto on_error; |
1038 | 1 | } |
1039 | 81 | if( libfvalue_utf8_string_split( |
1040 | 81 | line_string, |
1041 | 81 | line_string_size, |
1042 | 81 | (uint8_t) '\t', |
1043 | 81 | &types, |
1044 | 81 | error ) != 1 ) |
1045 | 0 | { |
1046 | 0 | libcerror_error_set( |
1047 | 0 | error, |
1048 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
1049 | 0 | LIBCERROR_RUNTIME_ERROR_INITIALIZE_FAILED, |
1050 | 0 | "%s: unable to split line string into types.", |
1051 | 0 | function ); |
1052 | |
|
1053 | 0 | goto on_error; |
1054 | 0 | } |
1055 | 81 | if( libfvalue_split_utf8_string_get_number_of_segments( |
1056 | 81 | types, |
1057 | 81 | &number_of_types, |
1058 | 81 | error ) != 1 ) |
1059 | 1 | { |
1060 | 1 | libcerror_error_set( |
1061 | 1 | error, |
1062 | 1 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
1063 | 1 | LIBCERROR_RUNTIME_ERROR_GET_FAILED, |
1064 | 1 | "%s: unable to retrieve number of types", |
1065 | 1 | function ); |
1066 | | |
1067 | 1 | goto on_error; |
1068 | 1 | } |
1069 | 80 | if( libewf_line_reader_read_utf8_string( |
1070 | 80 | line_reader, |
1071 | 80 | &line_string, |
1072 | 80 | &line_string_size, |
1073 | 80 | error ) != 1 ) |
1074 | 2 | { |
1075 | 2 | libcerror_error_set( |
1076 | 2 | error, |
1077 | 2 | LIBCERROR_ERROR_DOMAIN_IO, |
1078 | 2 | LIBCERROR_IO_ERROR_READ_FAILED, |
1079 | 2 | "%s: unable to read line: %d.", |
1080 | 2 | function, |
1081 | 2 | line_reader->line_index ); |
1082 | | |
1083 | 2 | goto on_error; |
1084 | 2 | } |
1085 | 78 | if( libfvalue_utf8_string_split( |
1086 | 78 | line_string, |
1087 | 78 | line_string_size, |
1088 | 78 | (uint8_t) '\t', |
1089 | 78 | &values, |
1090 | 78 | error ) != 1 ) |
1091 | 0 | { |
1092 | 0 | libcerror_error_set( |
1093 | 0 | error, |
1094 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
1095 | 0 | LIBCERROR_RUNTIME_ERROR_INITIALIZE_FAILED, |
1096 | 0 | "%s: unable to split line string into values.", |
1097 | 0 | function ); |
1098 | |
|
1099 | 0 | goto on_error; |
1100 | 0 | } |
1101 | 78 | if( libfvalue_split_utf8_string_get_number_of_segments( |
1102 | 78 | values, |
1103 | 78 | &number_of_values, |
1104 | 78 | error ) != 1 ) |
1105 | 1 | { |
1106 | 1 | libcerror_error_set( |
1107 | 1 | error, |
1108 | 1 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
1109 | 1 | LIBCERROR_RUNTIME_ERROR_GET_FAILED, |
1110 | 1 | "%s: unable to retrieve number of values", |
1111 | 1 | function ); |
1112 | | |
1113 | 1 | goto on_error; |
1114 | 1 | } |
1115 | | #if defined( HAVE_VERBOSE_OUTPUT ) |
1116 | | if( number_of_types != number_of_values ) |
1117 | | { |
1118 | | if( libcnotify_verbose != 0 ) |
1119 | | { |
1120 | | libcnotify_printf( |
1121 | | "%s: mismatch in number of types and values.\n", |
1122 | | function ); |
1123 | | } |
1124 | | } |
1125 | | #endif |
1126 | 77 | for( value_index = 0; |
1127 | 408 | value_index < number_of_types; |
1128 | 331 | value_index++ ) |
1129 | 337 | { |
1130 | 337 | if( libfvalue_split_utf8_string_get_segment_by_index( |
1131 | 337 | types, |
1132 | 337 | value_index, |
1133 | 337 | &type_string, |
1134 | 337 | &type_string_size, |
1135 | 337 | error ) != 1 ) |
1136 | 0 | { |
1137 | 0 | libcerror_error_set( |
1138 | 0 | error, |
1139 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
1140 | 0 | LIBCERROR_RUNTIME_ERROR_GET_FAILED, |
1141 | 0 | "%s: unable to retrieve type string: %d.", |
1142 | 0 | function, |
1143 | 0 | value_index ); |
1144 | |
|
1145 | 0 | goto on_error; |
1146 | 0 | } |
1147 | 337 | if( ( type_string == NULL ) |
1148 | 337 | || ( type_string_size < 2 ) |
1149 | 335 | || ( type_string[ 0 ] == 0 ) ) |
1150 | 2 | { |
1151 | 2 | libcerror_error_set( |
1152 | 2 | error, |
1153 | 2 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
1154 | 2 | LIBCERROR_RUNTIME_ERROR_VALUE_MISSING, |
1155 | 2 | "%s: missing type string: %d.", |
1156 | 2 | function, |
1157 | 2 | value_index ); |
1158 | | |
1159 | 2 | goto on_error; |
1160 | 2 | } |
1161 | 335 | if( value_index >= number_of_values ) |
1162 | 125 | { |
1163 | 125 | value_string = NULL; |
1164 | 125 | value_string_size = 0; |
1165 | 125 | } |
1166 | 210 | else |
1167 | 210 | { |
1168 | 210 | if( libfvalue_split_utf8_string_get_segment_by_index( |
1169 | 210 | values, |
1170 | 210 | value_index, |
1171 | 210 | &value_string, |
1172 | 210 | &value_string_size, |
1173 | 210 | error ) != 1 ) |
1174 | 0 | { |
1175 | 0 | libcerror_error_set( |
1176 | 0 | error, |
1177 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
1178 | 0 | LIBCERROR_RUNTIME_ERROR_GET_FAILED, |
1179 | 0 | "%s: unable to retrieve value string: %d.", |
1180 | 0 | function, |
1181 | 0 | value_index ); |
1182 | |
|
1183 | 0 | goto on_error; |
1184 | 0 | } |
1185 | 210 | if( ( value_string == NULL ) |
1186 | 210 | || ( value_string_size < 2 ) |
1187 | 189 | || ( value_string[ 0 ] == 0 ) ) |
1188 | 21 | { |
1189 | 21 | value_string = NULL; |
1190 | 21 | value_string_size = 0; |
1191 | 21 | } |
1192 | 210 | } |
1193 | | #if defined( HAVE_DEBUG_OUTPUT ) |
1194 | | if( libcnotify_verbose != 0 ) |
1195 | | { |
1196 | | libcnotify_printf( |
1197 | | "%s: type: %3s with value\t\t:", |
1198 | | function, |
1199 | | (char *) type_string ); |
1200 | | |
1201 | | if( value_string != NULL ) |
1202 | | { |
1203 | | libcnotify_printf( |
1204 | | " %s", |
1205 | | (char *) value_string ); |
1206 | | } |
1207 | | libcnotify_printf( |
1208 | | "\n" ); |
1209 | | } |
1210 | | #endif |
1211 | | /* Ignore empty values |
1212 | | */ |
1213 | 335 | if( value_string == NULL ) |
1214 | 146 | { |
1215 | 146 | continue; |
1216 | 146 | } |
1217 | 189 | if( type_string_size == 3 ) |
1218 | 54 | { |
1219 | 54 | if( ( type_string[ 0 ] == (uint8_t) 'c' ) |
1220 | 5 | && ( type_string[ 1 ] == (uint8_t) 'l' ) ) |
1221 | 1 | { |
1222 | 1 | } |
1223 | 53 | else if( ( type_string[ 0 ] == (uint8_t) 't' ) |
1224 | 13 | && ( type_string[ 1 ] == (uint8_t) 'b' ) ) |
1225 | 5 | { |
1226 | 5 | if( libfvalue_utf8_string_copy_to_integer( |
1227 | 5 | value_string, |
1228 | 5 | value_string_size, |
1229 | 5 | &value_64bit, |
1230 | 5 | 64, |
1231 | 5 | LIBFVALUE_INTEGER_FORMAT_TYPE_DECIMAL_UNSIGNED, |
1232 | 5 | error ) != 1 ) |
1233 | 4 | { |
1234 | 4 | libcerror_error_set( |
1235 | 4 | error, |
1236 | 4 | LIBCERROR_ERROR_DOMAIN_MEMORY, |
1237 | 4 | LIBCERROR_MEMORY_ERROR_SET_FAILED, |
1238 | 4 | "%s: unable to set media size.", |
1239 | 4 | function ); |
1240 | | |
1241 | 4 | goto on_error; |
1242 | 4 | } |
1243 | 1 | *media_size = (size64_t) value_64bit; |
1244 | 1 | } |
1245 | 54 | } |
1246 | 189 | } |
1247 | 71 | if( libfvalue_split_utf8_string_free( |
1248 | 71 | &values, |
1249 | 71 | error ) != 1 ) |
1250 | 0 | { |
1251 | 0 | libcerror_error_set( |
1252 | 0 | error, |
1253 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
1254 | 0 | LIBCERROR_RUNTIME_ERROR_FINALIZE_FAILED, |
1255 | 0 | "%s: unable to free split values.", |
1256 | 0 | function ); |
1257 | |
|
1258 | 0 | goto on_error; |
1259 | 0 | } |
1260 | 71 | if( libfvalue_split_utf8_string_free( |
1261 | 71 | &types, |
1262 | 71 | error ) != 1 ) |
1263 | 0 | { |
1264 | 0 | libcerror_error_set( |
1265 | 0 | error, |
1266 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
1267 | 0 | LIBCERROR_RUNTIME_ERROR_FINALIZE_FAILED, |
1268 | 0 | "%s: unable to free split types.", |
1269 | 0 | function ); |
1270 | |
|
1271 | 0 | goto on_error; |
1272 | 0 | } |
1273 | | #if defined( HAVE_DEBUG_OUTPUT ) |
1274 | | if( libcnotify_verbose != 0 ) |
1275 | | { |
1276 | | libcnotify_printf( |
1277 | | "\n" ); |
1278 | | } |
1279 | | #endif |
1280 | 71 | return( 1 ); |
1281 | | |
1282 | 11 | on_error: |
1283 | 11 | if( values != NULL ) |
1284 | 6 | { |
1285 | 6 | libfvalue_split_utf8_string_free( |
1286 | 6 | &values, |
1287 | 6 | NULL ); |
1288 | 6 | } |
1289 | 11 | if( types != NULL ) |
1290 | 9 | { |
1291 | 9 | libfvalue_split_utf8_string_free( |
1292 | 9 | &types, |
1293 | 9 | NULL ); |
1294 | 9 | } |
1295 | 11 | return( -1 ); |
1296 | 71 | } |
1297 | | |
1298 | | /* Parses the "perm" category |
1299 | | * Returns 1 if successful or -1 on error |
1300 | | */ |
1301 | | int libewf_single_files_parse_perm_category( |
1302 | | libewf_single_files_t *single_files, |
1303 | | libewf_line_reader_t *line_reader, |
1304 | | libcerror_error_t **error ) |
1305 | 1 | { |
1306 | 1 | libewf_lef_permission_t *lef_permission = NULL; |
1307 | 1 | libewf_permission_group_t *permission_group = NULL; |
1308 | 1 | libfvalue_split_utf8_string_t *types = NULL; |
1309 | 1 | uint8_t *line_string = NULL; |
1310 | 1 | static char *function = "libewf_single_files_parse_perm_category"; |
1311 | 1 | size_t line_string_size = 0; |
1312 | 1 | int copy_of_number_of_permission_groups = 0; |
1313 | 1 | int entry_index = 0; |
1314 | 1 | int number_of_permission_groups = 0; |
1315 | 1 | int permission_group_index = 0; |
1316 | | |
1317 | 1 | if( single_files == NULL ) |
1318 | 0 | { |
1319 | 0 | libcerror_error_set( |
1320 | 0 | error, |
1321 | 0 | LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
1322 | 0 | LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, |
1323 | 0 | "%s: invalid single files.", |
1324 | 0 | function ); |
1325 | |
|
1326 | 0 | return( -1 ); |
1327 | 0 | } |
1328 | 1 | if( line_reader == NULL ) |
1329 | 0 | { |
1330 | 0 | libcerror_error_set( |
1331 | 0 | error, |
1332 | 0 | LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
1333 | 0 | LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, |
1334 | 0 | "%s: invalid line reader.", |
1335 | 0 | function ); |
1336 | |
|
1337 | 0 | return( -1 ); |
1338 | 0 | } |
1339 | 1 | if( libewf_single_files_parse_category_number_of_entries( |
1340 | 1 | single_files, |
1341 | 1 | line_reader, |
1342 | 1 | &number_of_permission_groups, |
1343 | 1 | error ) != 1 ) |
1344 | 1 | { |
1345 | 1 | libcerror_error_set( |
1346 | 1 | error, |
1347 | 1 | LIBCERROR_ERROR_DOMAIN_CONVERSION, |
1348 | 1 | LIBCERROR_CONVERSION_ERROR_GENERIC, |
1349 | 1 | "%s: unable to parse number of permission groups in line: %d.", |
1350 | 1 | function, |
1351 | 1 | line_reader->line_index ); |
1352 | | |
1353 | 1 | goto on_error; |
1354 | 1 | } |
1355 | 0 | if( libewf_single_files_parse_category_types( |
1356 | 0 | single_files, |
1357 | 0 | line_reader, |
1358 | 0 | &types, |
1359 | 0 | error ) != 1 ) |
1360 | 0 | { |
1361 | 0 | libcerror_error_set( |
1362 | 0 | error, |
1363 | 0 | LIBCERROR_ERROR_DOMAIN_CONVERSION, |
1364 | 0 | LIBCERROR_CONVERSION_ERROR_GENERIC, |
1365 | 0 | "%s: unable to parse types in line: %d.", |
1366 | 0 | function, |
1367 | 0 | line_reader->line_index ); |
1368 | |
|
1369 | 0 | goto on_error; |
1370 | 0 | } |
1371 | 0 | if( libewf_single_files_parse_number_of_entries( |
1372 | 0 | single_files, |
1373 | 0 | line_reader, |
1374 | 0 | ©_of_number_of_permission_groups, |
1375 | 0 | error ) != 1 ) |
1376 | 0 | { |
1377 | 0 | libcerror_error_set( |
1378 | 0 | error, |
1379 | 0 | LIBCERROR_ERROR_DOMAIN_CONVERSION, |
1380 | 0 | LIBCERROR_CONVERSION_ERROR_GENERIC, |
1381 | 0 | "%s: unable to parse number of permission groups in line: %d.", |
1382 | 0 | function, |
1383 | 0 | line_reader->line_index ); |
1384 | |
|
1385 | 0 | goto on_error; |
1386 | 0 | } |
1387 | 0 | if( number_of_permission_groups != copy_of_number_of_permission_groups ) |
1388 | 0 | { |
1389 | 0 | libcerror_error_set( |
1390 | 0 | error, |
1391 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
1392 | 0 | LIBCERROR_RUNTIME_ERROR_VALUE_OUT_OF_BOUNDS, |
1393 | 0 | "%s: mismatch between number of permission groups and copy.", |
1394 | 0 | function ); |
1395 | |
|
1396 | 0 | goto on_error; |
1397 | 0 | } |
1398 | | /* Parse the category root entry |
1399 | | */ |
1400 | 0 | if( libewf_line_reader_read_utf8_string( |
1401 | 0 | line_reader, |
1402 | 0 | &line_string, |
1403 | 0 | &line_string_size, |
1404 | 0 | error ) != 1 ) |
1405 | 0 | { |
1406 | 0 | libcerror_error_set( |
1407 | 0 | error, |
1408 | 0 | LIBCERROR_ERROR_DOMAIN_IO, |
1409 | 0 | LIBCERROR_IO_ERROR_READ_FAILED, |
1410 | 0 | "%s: unable to read line: %d.", |
1411 | 0 | function, |
1412 | 0 | line_reader->line_index ); |
1413 | |
|
1414 | 0 | goto on_error; |
1415 | 0 | } |
1416 | 0 | if( libewf_lef_permission_initialize( |
1417 | 0 | &lef_permission, |
1418 | 0 | error ) != 1 ) |
1419 | 0 | { |
1420 | 0 | libcerror_error_set( |
1421 | 0 | error, |
1422 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
1423 | 0 | LIBCERROR_RUNTIME_ERROR_INITIALIZE_FAILED, |
1424 | 0 | "%s: unable to create permission.", |
1425 | 0 | function ); |
1426 | |
|
1427 | 0 | goto on_error; |
1428 | 0 | } |
1429 | 0 | if( libewf_lef_permission_read_data( |
1430 | 0 | lef_permission, |
1431 | 0 | types, |
1432 | 0 | line_string, |
1433 | 0 | line_string_size, |
1434 | 0 | error ) != 1 ) |
1435 | 0 | { |
1436 | 0 | libcerror_error_set( |
1437 | 0 | error, |
1438 | 0 | LIBCERROR_ERROR_DOMAIN_IO, |
1439 | 0 | LIBCERROR_IO_ERROR_READ_FAILED, |
1440 | 0 | "%s: unable to read permission.", |
1441 | 0 | function ); |
1442 | |
|
1443 | 0 | goto on_error; |
1444 | 0 | } |
1445 | 0 | if( lef_permission->property_type != 10 ) |
1446 | 0 | { |
1447 | 0 | libcerror_error_set( |
1448 | 0 | error, |
1449 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
1450 | 0 | LIBCERROR_RUNTIME_ERROR_UNSUPPORTED_VALUE, |
1451 | 0 | "%s: unsupported permission group type.", |
1452 | 0 | function ); |
1453 | |
|
1454 | 0 | goto on_error; |
1455 | 0 | } |
1456 | 0 | if( libewf_lef_permission_free( |
1457 | 0 | &lef_permission, |
1458 | 0 | error ) != 1 ) |
1459 | 0 | { |
1460 | 0 | libcerror_error_set( |
1461 | 0 | error, |
1462 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
1463 | 0 | LIBCERROR_RUNTIME_ERROR_INITIALIZE_FAILED, |
1464 | 0 | "%s: unable to free permission.", |
1465 | 0 | function ); |
1466 | |
|
1467 | 0 | goto on_error; |
1468 | 0 | } |
1469 | 0 | for( permission_group_index = 0; |
1470 | 0 | permission_group_index < number_of_permission_groups; |
1471 | 0 | permission_group_index++ ) |
1472 | 0 | { |
1473 | 0 | if( libewf_permission_group_initialize( |
1474 | 0 | &permission_group, |
1475 | 0 | error ) != 1 ) |
1476 | 0 | { |
1477 | 0 | libcerror_error_set( |
1478 | 0 | error, |
1479 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
1480 | 0 | LIBCERROR_RUNTIME_ERROR_INITIALIZE_FAILED, |
1481 | 0 | "%s: unable to create permission group.", |
1482 | 0 | function ); |
1483 | |
|
1484 | 0 | goto on_error; |
1485 | 0 | } |
1486 | 0 | if( libewf_single_files_parse_permission_group( |
1487 | 0 | single_files, |
1488 | 0 | line_reader, |
1489 | 0 | types, |
1490 | 0 | permission_group, |
1491 | 0 | error ) != 1 ) |
1492 | 0 | { |
1493 | 0 | libcerror_error_set( |
1494 | 0 | error, |
1495 | 0 | LIBCERROR_ERROR_DOMAIN_CONVERSION, |
1496 | 0 | LIBCERROR_CONVERSION_ERROR_GENERIC, |
1497 | 0 | "%s: unable to parse permission group: %d.", |
1498 | 0 | function, |
1499 | 0 | permission_group_index ); |
1500 | |
|
1501 | 0 | goto on_error; |
1502 | 0 | } |
1503 | 0 | if( libcdata_array_append_entry( |
1504 | 0 | single_files->permission_groups, |
1505 | 0 | &entry_index, |
1506 | 0 | (intptr_t *) permission_group, |
1507 | 0 | error ) != 1 ) |
1508 | 0 | { |
1509 | 0 | libcerror_error_set( |
1510 | 0 | error, |
1511 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
1512 | 0 | LIBCERROR_RUNTIME_ERROR_APPEND_FAILED, |
1513 | 0 | "%s: unable to append permission group: %d to array.", |
1514 | 0 | function, |
1515 | 0 | permission_group_index ); |
1516 | |
|
1517 | 0 | goto on_error; |
1518 | 0 | } |
1519 | 0 | permission_group = NULL; |
1520 | 0 | } |
1521 | 0 | if( libfvalue_split_utf8_string_free( |
1522 | 0 | &types, |
1523 | 0 | error ) != 1 ) |
1524 | 0 | { |
1525 | 0 | libcerror_error_set( |
1526 | 0 | error, |
1527 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
1528 | 0 | LIBCERROR_RUNTIME_ERROR_FINALIZE_FAILED, |
1529 | 0 | "%s: unable to free split types.", |
1530 | 0 | function ); |
1531 | |
|
1532 | 0 | goto on_error; |
1533 | 0 | } |
1534 | 0 | return( 1 ); |
1535 | | |
1536 | 1 | on_error: |
1537 | 1 | if( permission_group != NULL ) |
1538 | 0 | { |
1539 | 0 | libewf_permission_group_free( |
1540 | 0 | &permission_group, |
1541 | 0 | NULL ); |
1542 | 0 | } |
1543 | 1 | if( lef_permission != NULL ) |
1544 | 0 | { |
1545 | 0 | libewf_lef_permission_free( |
1546 | 0 | &lef_permission, |
1547 | 0 | NULL ); |
1548 | 0 | } |
1549 | 1 | if( types != NULL ) |
1550 | 0 | { |
1551 | 0 | libfvalue_split_utf8_string_free( |
1552 | 0 | &types, |
1553 | 0 | NULL ); |
1554 | 0 | } |
1555 | 1 | return( -1 ); |
1556 | 0 | } |
1557 | | |
1558 | | /* Parses a permission group |
1559 | | * Returns 1 if successful or -1 on error |
1560 | | */ |
1561 | | int libewf_single_files_parse_permission_group( |
1562 | | libewf_single_files_t *single_files, |
1563 | | libewf_line_reader_t *line_reader, |
1564 | | libfvalue_split_utf8_string_t *types, |
1565 | | libewf_permission_group_t *permission_group, |
1566 | | libcerror_error_t **error ) |
1567 | 0 | { |
1568 | 0 | libewf_lef_permission_t *lef_permission = NULL; |
1569 | 0 | uint8_t *line_string = NULL; |
1570 | 0 | static char *function = "libewf_single_files_parse_permission_group"; |
1571 | 0 | size_t line_string_size = 0; |
1572 | 0 | int number_of_entries = 0; |
1573 | 0 | int number_of_permissions = 0; |
1574 | 0 | int permission_index = 0; |
1575 | |
|
1576 | 0 | if( single_files == NULL ) |
1577 | 0 | { |
1578 | 0 | libcerror_error_set( |
1579 | 0 | error, |
1580 | 0 | LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
1581 | 0 | LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, |
1582 | 0 | "%s: invalid single files.", |
1583 | 0 | function ); |
1584 | |
|
1585 | 0 | return( -1 ); |
1586 | 0 | } |
1587 | 0 | if( line_reader == NULL ) |
1588 | 0 | { |
1589 | 0 | libcerror_error_set( |
1590 | 0 | error, |
1591 | 0 | LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
1592 | 0 | LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, |
1593 | 0 | "%s: invalid line reader.", |
1594 | 0 | function ); |
1595 | |
|
1596 | 0 | return( -1 ); |
1597 | 0 | } |
1598 | 0 | if( libewf_single_files_parse_number_of_entries( |
1599 | 0 | single_files, |
1600 | 0 | line_reader, |
1601 | 0 | &number_of_permissions, |
1602 | 0 | error ) != 1 ) |
1603 | 0 | { |
1604 | 0 | libcerror_error_set( |
1605 | 0 | error, |
1606 | 0 | LIBCERROR_ERROR_DOMAIN_CONVERSION, |
1607 | 0 | LIBCERROR_CONVERSION_ERROR_GENERIC, |
1608 | 0 | "%s: unable to parse number of permissions in line: %d.", |
1609 | 0 | function, |
1610 | 0 | line_reader->line_index ); |
1611 | |
|
1612 | 0 | goto on_error; |
1613 | 0 | } |
1614 | | /* Parse the permission group entry |
1615 | | */ |
1616 | 0 | if( libewf_line_reader_read_utf8_string( |
1617 | 0 | line_reader, |
1618 | 0 | &line_string, |
1619 | 0 | &line_string_size, |
1620 | 0 | error ) != 1 ) |
1621 | 0 | { |
1622 | 0 | libcerror_error_set( |
1623 | 0 | error, |
1624 | 0 | LIBCERROR_ERROR_DOMAIN_IO, |
1625 | 0 | LIBCERROR_IO_ERROR_READ_FAILED, |
1626 | 0 | "%s: unable to read line: %d.", |
1627 | 0 | function, |
1628 | 0 | line_reader->line_index ); |
1629 | |
|
1630 | 0 | goto on_error; |
1631 | 0 | } |
1632 | 0 | if( libewf_lef_permission_initialize( |
1633 | 0 | &lef_permission, |
1634 | 0 | error ) != 1 ) |
1635 | 0 | { |
1636 | 0 | libcerror_error_set( |
1637 | 0 | error, |
1638 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
1639 | 0 | LIBCERROR_RUNTIME_ERROR_INITIALIZE_FAILED, |
1640 | 0 | "%s: unable to create permission.", |
1641 | 0 | function ); |
1642 | |
|
1643 | 0 | goto on_error; |
1644 | 0 | } |
1645 | 0 | if( libewf_lef_permission_read_data( |
1646 | 0 | lef_permission, |
1647 | 0 | types, |
1648 | 0 | line_string, |
1649 | 0 | line_string_size, |
1650 | 0 | error ) != 1 ) |
1651 | 0 | { |
1652 | 0 | libcerror_error_set( |
1653 | 0 | error, |
1654 | 0 | LIBCERROR_ERROR_DOMAIN_IO, |
1655 | 0 | LIBCERROR_IO_ERROR_READ_FAILED, |
1656 | 0 | "%s: unable to read permission", |
1657 | 0 | function ); |
1658 | |
|
1659 | 0 | goto on_error; |
1660 | 0 | } |
1661 | 0 | if( lef_permission->property_type != 10 ) |
1662 | 0 | { |
1663 | 0 | libcerror_error_set( |
1664 | 0 | error, |
1665 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
1666 | 0 | LIBCERROR_RUNTIME_ERROR_UNSUPPORTED_VALUE, |
1667 | 0 | "%s: unsupported permission group type.", |
1668 | 0 | function ); |
1669 | |
|
1670 | 0 | goto on_error; |
1671 | 0 | } |
1672 | 0 | if( libewf_lef_permission_free( |
1673 | 0 | &lef_permission, |
1674 | 0 | error ) != 1 ) |
1675 | 0 | { |
1676 | 0 | libcerror_error_set( |
1677 | 0 | error, |
1678 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
1679 | 0 | LIBCERROR_RUNTIME_ERROR_INITIALIZE_FAILED, |
1680 | 0 | "%s: unable to free permission.", |
1681 | 0 | function ); |
1682 | |
|
1683 | 0 | goto on_error; |
1684 | 0 | } |
1685 | 0 | for( permission_index = 0; |
1686 | 0 | permission_index < number_of_permissions; |
1687 | 0 | permission_index++ ) |
1688 | 0 | { |
1689 | 0 | if( libewf_single_files_parse_number_of_entries( |
1690 | 0 | single_files, |
1691 | 0 | line_reader, |
1692 | 0 | &number_of_entries, |
1693 | 0 | error ) != 1 ) |
1694 | 0 | { |
1695 | 0 | libcerror_error_set( |
1696 | 0 | error, |
1697 | 0 | LIBCERROR_ERROR_DOMAIN_CONVERSION, |
1698 | 0 | LIBCERROR_CONVERSION_ERROR_GENERIC, |
1699 | 0 | "%s: unable to parse number of entries in line: %d.", |
1700 | 0 | function, |
1701 | 0 | line_reader->line_index ); |
1702 | |
|
1703 | 0 | goto on_error; |
1704 | 0 | } |
1705 | 0 | if( number_of_entries != 0 ) |
1706 | 0 | { |
1707 | 0 | libcerror_error_set( |
1708 | 0 | error, |
1709 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
1710 | 0 | LIBCERROR_RUNTIME_ERROR_VALUE_OUT_OF_BOUNDS, |
1711 | 0 | "%s: invalid number of entries value out of bounds.", |
1712 | 0 | function ); |
1713 | |
|
1714 | 0 | goto on_error; |
1715 | 0 | } |
1716 | | /* Parse the permission entry |
1717 | | */ |
1718 | 0 | if( libewf_line_reader_read_utf8_string( |
1719 | 0 | line_reader, |
1720 | 0 | &line_string, |
1721 | 0 | &line_string_size, |
1722 | 0 | error ) != 1 ) |
1723 | 0 | { |
1724 | 0 | libcerror_error_set( |
1725 | 0 | error, |
1726 | 0 | LIBCERROR_ERROR_DOMAIN_IO, |
1727 | 0 | LIBCERROR_IO_ERROR_READ_FAILED, |
1728 | 0 | "%s: unable to read line: %d.", |
1729 | 0 | function, |
1730 | 0 | line_reader->line_index ); |
1731 | |
|
1732 | 0 | goto on_error; |
1733 | 0 | } |
1734 | 0 | if( libewf_lef_permission_initialize( |
1735 | 0 | &lef_permission, |
1736 | 0 | error ) != 1 ) |
1737 | 0 | { |
1738 | 0 | libcerror_error_set( |
1739 | 0 | error, |
1740 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
1741 | 0 | LIBCERROR_RUNTIME_ERROR_INITIALIZE_FAILED, |
1742 | 0 | "%s: unable to create permission: %d.", |
1743 | 0 | function, |
1744 | 0 | permission_index ); |
1745 | |
|
1746 | 0 | goto on_error; |
1747 | 0 | } |
1748 | 0 | if( libewf_lef_permission_read_data( |
1749 | 0 | lef_permission, |
1750 | 0 | types, |
1751 | 0 | line_string, |
1752 | 0 | line_string_size, |
1753 | 0 | error ) != 1 ) |
1754 | 0 | { |
1755 | 0 | libcerror_error_set( |
1756 | 0 | error, |
1757 | 0 | LIBCERROR_ERROR_DOMAIN_IO, |
1758 | 0 | LIBCERROR_IO_ERROR_READ_FAILED, |
1759 | 0 | "%s: unable to read permission: %d", |
1760 | 0 | function, |
1761 | 0 | permission_index ); |
1762 | |
|
1763 | 0 | goto on_error; |
1764 | 0 | } |
1765 | 0 | if( libewf_permission_group_append_permission( |
1766 | 0 | permission_group, |
1767 | 0 | lef_permission, |
1768 | 0 | error ) != 1 ) |
1769 | 0 | { |
1770 | 0 | libcerror_error_set( |
1771 | 0 | error, |
1772 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
1773 | 0 | LIBCERROR_RUNTIME_ERROR_APPEND_FAILED, |
1774 | 0 | "%s: unable to append permission: %d to group.", |
1775 | 0 | function, |
1776 | 0 | permission_index ); |
1777 | |
|
1778 | 0 | goto on_error; |
1779 | 0 | } |
1780 | 0 | lef_permission = NULL; |
1781 | 0 | } |
1782 | 0 | return( 1 ); |
1783 | | |
1784 | 0 | on_error: |
1785 | 0 | if( lef_permission != NULL ) |
1786 | 0 | { |
1787 | 0 | libewf_lef_permission_free( |
1788 | 0 | &lef_permission, |
1789 | 0 | NULL ); |
1790 | 0 | } |
1791 | 0 | return( -1 ); |
1792 | 0 | } |
1793 | | |
1794 | | /* Parses the "srce" category |
1795 | | * Returns 1 if successful or -1 on error |
1796 | | */ |
1797 | | int libewf_single_files_parse_srce_category( |
1798 | | libewf_single_files_t *single_files, |
1799 | | libewf_line_reader_t *line_reader, |
1800 | | libcerror_error_t **error ) |
1801 | 1 | { |
1802 | 1 | libewf_lef_source_t *lef_source = NULL; |
1803 | 1 | libfvalue_split_utf8_string_t *types = NULL; |
1804 | 1 | uint8_t *line_string = NULL; |
1805 | 1 | static char *function = "libewf_single_files_parse_srce_category"; |
1806 | 1 | size_t line_string_size = 0; |
1807 | 1 | int copy_of_number_of_sources = 0; |
1808 | 1 | int entry_index = 0; |
1809 | 1 | int number_of_entries = 0; |
1810 | 1 | int number_of_sources = 0; |
1811 | 1 | int source_identifier = 0; |
1812 | 1 | int source_index = 0; |
1813 | | |
1814 | 1 | if( single_files == NULL ) |
1815 | 0 | { |
1816 | 0 | libcerror_error_set( |
1817 | 0 | error, |
1818 | 0 | LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
1819 | 0 | LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, |
1820 | 0 | "%s: invalid single files.", |
1821 | 0 | function ); |
1822 | |
|
1823 | 0 | return( -1 ); |
1824 | 0 | } |
1825 | 1 | if( line_reader == NULL ) |
1826 | 0 | { |
1827 | 0 | libcerror_error_set( |
1828 | 0 | error, |
1829 | 0 | LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
1830 | 0 | LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, |
1831 | 0 | "%s: invalid line reader.", |
1832 | 0 | function ); |
1833 | |
|
1834 | 0 | return( -1 ); |
1835 | 0 | } |
1836 | 1 | if( libewf_single_files_parse_category_number_of_entries( |
1837 | 1 | single_files, |
1838 | 1 | line_reader, |
1839 | 1 | &number_of_sources, |
1840 | 1 | error ) != 1 ) |
1841 | 1 | { |
1842 | 1 | libcerror_error_set( |
1843 | 1 | error, |
1844 | 1 | LIBCERROR_ERROR_DOMAIN_CONVERSION, |
1845 | 1 | LIBCERROR_CONVERSION_ERROR_GENERIC, |
1846 | 1 | "%s: unable to parse number of sources in line: %d.", |
1847 | 1 | function, |
1848 | 1 | line_reader->line_index ); |
1849 | | |
1850 | 1 | goto on_error; |
1851 | 1 | } |
1852 | 0 | if( libewf_single_files_parse_category_types( |
1853 | 0 | single_files, |
1854 | 0 | line_reader, |
1855 | 0 | &types, |
1856 | 0 | error ) != 1 ) |
1857 | 0 | { |
1858 | 0 | libcerror_error_set( |
1859 | 0 | error, |
1860 | 0 | LIBCERROR_ERROR_DOMAIN_CONVERSION, |
1861 | 0 | LIBCERROR_CONVERSION_ERROR_GENERIC, |
1862 | 0 | "%s: unable to parse types in line: %d.", |
1863 | 0 | function, |
1864 | 0 | line_reader->line_index ); |
1865 | |
|
1866 | 0 | goto on_error; |
1867 | 0 | } |
1868 | 0 | if( libewf_single_files_parse_number_of_entries( |
1869 | 0 | single_files, |
1870 | 0 | line_reader, |
1871 | 0 | ©_of_number_of_sources, |
1872 | 0 | error ) != 1 ) |
1873 | 0 | { |
1874 | 0 | libcerror_error_set( |
1875 | 0 | error, |
1876 | 0 | LIBCERROR_ERROR_DOMAIN_CONVERSION, |
1877 | 0 | LIBCERROR_CONVERSION_ERROR_GENERIC, |
1878 | 0 | "%s: unable to parse number of sources in line: %d.", |
1879 | 0 | function, |
1880 | 0 | line_reader->line_index ); |
1881 | |
|
1882 | 0 | goto on_error; |
1883 | 0 | } |
1884 | 0 | if( number_of_sources != copy_of_number_of_sources ) |
1885 | 0 | { |
1886 | 0 | libcerror_error_set( |
1887 | 0 | error, |
1888 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
1889 | 0 | LIBCERROR_RUNTIME_ERROR_VALUE_OUT_OF_BOUNDS, |
1890 | 0 | "%s: mismatch between number of sources and copy.", |
1891 | 0 | function ); |
1892 | |
|
1893 | 0 | goto on_error; |
1894 | 0 | } |
1895 | | /* Parse the category root entry |
1896 | | */ |
1897 | 0 | if( libewf_line_reader_read_utf8_string( |
1898 | 0 | line_reader, |
1899 | 0 | &line_string, |
1900 | 0 | &line_string_size, |
1901 | 0 | error ) != 1 ) |
1902 | 0 | { |
1903 | 0 | libcerror_error_set( |
1904 | 0 | error, |
1905 | 0 | LIBCERROR_ERROR_DOMAIN_IO, |
1906 | 0 | LIBCERROR_IO_ERROR_READ_FAILED, |
1907 | 0 | "%s: unable to read line: %d.", |
1908 | 0 | function, |
1909 | 0 | line_reader->line_index ); |
1910 | |
|
1911 | 0 | goto on_error; |
1912 | 0 | } |
1913 | 0 | if( libewf_lef_source_initialize( |
1914 | 0 | &lef_source, |
1915 | 0 | error ) != 1 ) |
1916 | 0 | { |
1917 | 0 | libcerror_error_set( |
1918 | 0 | error, |
1919 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
1920 | 0 | LIBCERROR_RUNTIME_ERROR_INITIALIZE_FAILED, |
1921 | 0 | "%s: unable to create source.", |
1922 | 0 | function ); |
1923 | |
|
1924 | 0 | goto on_error; |
1925 | 0 | } |
1926 | 0 | if( libewf_lef_source_read_data( |
1927 | 0 | lef_source, |
1928 | 0 | types, |
1929 | 0 | line_string, |
1930 | 0 | line_string_size, |
1931 | 0 | error ) != 1 ) |
1932 | 0 | { |
1933 | 0 | libcerror_error_set( |
1934 | 0 | error, |
1935 | 0 | LIBCERROR_ERROR_DOMAIN_IO, |
1936 | 0 | LIBCERROR_IO_ERROR_READ_FAILED, |
1937 | 0 | "%s: unable to read source", |
1938 | 0 | function ); |
1939 | |
|
1940 | 0 | goto on_error; |
1941 | 0 | } |
1942 | | /* Append the category root so that the source identifiers and array entries align |
1943 | | */ |
1944 | 0 | if( libcdata_array_append_entry( |
1945 | 0 | single_files->sources, |
1946 | 0 | &entry_index, |
1947 | 0 | (intptr_t *) lef_source, |
1948 | 0 | error ) != 1 ) |
1949 | 0 | { |
1950 | 0 | libcerror_error_set( |
1951 | 0 | error, |
1952 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
1953 | 0 | LIBCERROR_RUNTIME_ERROR_APPEND_FAILED, |
1954 | 0 | "%s: unable to append category root source to array.", |
1955 | 0 | function ); |
1956 | |
|
1957 | 0 | goto on_error; |
1958 | 0 | } |
1959 | 0 | lef_source = NULL; |
1960 | |
|
1961 | 0 | for( source_index = 0; |
1962 | 0 | source_index < number_of_sources; |
1963 | 0 | source_index++ ) |
1964 | 0 | { |
1965 | 0 | if( libewf_single_files_parse_number_of_entries( |
1966 | 0 | single_files, |
1967 | 0 | line_reader, |
1968 | 0 | &number_of_entries, |
1969 | 0 | error ) != 1 ) |
1970 | 0 | { |
1971 | 0 | libcerror_error_set( |
1972 | 0 | error, |
1973 | 0 | LIBCERROR_ERROR_DOMAIN_CONVERSION, |
1974 | 0 | LIBCERROR_CONVERSION_ERROR_GENERIC, |
1975 | 0 | "%s: unable to parse number of entries in line: %d.", |
1976 | 0 | function, |
1977 | 0 | line_reader->line_index ); |
1978 | |
|
1979 | 0 | goto on_error; |
1980 | 0 | } |
1981 | 0 | if( number_of_entries != 0 ) |
1982 | 0 | { |
1983 | 0 | libcerror_error_set( |
1984 | 0 | error, |
1985 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
1986 | 0 | LIBCERROR_RUNTIME_ERROR_VALUE_OUT_OF_BOUNDS, |
1987 | 0 | "%s: invalid number of entries value out of bounds.", |
1988 | 0 | function ); |
1989 | |
|
1990 | 0 | goto on_error; |
1991 | 0 | } |
1992 | | /* Parse the source entry |
1993 | | */ |
1994 | 0 | if( libewf_line_reader_read_utf8_string( |
1995 | 0 | line_reader, |
1996 | 0 | &line_string, |
1997 | 0 | &line_string_size, |
1998 | 0 | error ) != 1 ) |
1999 | 0 | { |
2000 | 0 | libcerror_error_set( |
2001 | 0 | error, |
2002 | 0 | LIBCERROR_ERROR_DOMAIN_IO, |
2003 | 0 | LIBCERROR_IO_ERROR_READ_FAILED, |
2004 | 0 | "%s: unable to read line: %d.", |
2005 | 0 | function, |
2006 | 0 | line_reader->line_index ); |
2007 | |
|
2008 | 0 | goto on_error; |
2009 | 0 | } |
2010 | 0 | if( libewf_lef_source_initialize( |
2011 | 0 | &lef_source, |
2012 | 0 | error ) != 1 ) |
2013 | 0 | { |
2014 | 0 | libcerror_error_set( |
2015 | 0 | error, |
2016 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
2017 | 0 | LIBCERROR_RUNTIME_ERROR_INITIALIZE_FAILED, |
2018 | 0 | "%s: unable to create source: %d.", |
2019 | 0 | function, |
2020 | 0 | source_index ); |
2021 | |
|
2022 | 0 | goto on_error; |
2023 | 0 | } |
2024 | 0 | if( libewf_lef_source_read_data( |
2025 | 0 | lef_source, |
2026 | 0 | types, |
2027 | 0 | line_string, |
2028 | 0 | line_string_size, |
2029 | 0 | error ) != 1 ) |
2030 | 0 | { |
2031 | 0 | libcerror_error_set( |
2032 | 0 | error, |
2033 | 0 | LIBCERROR_ERROR_DOMAIN_IO, |
2034 | 0 | LIBCERROR_IO_ERROR_READ_FAILED, |
2035 | 0 | "%s: unable to read source: %d", |
2036 | 0 | function, |
2037 | 0 | source_index ); |
2038 | |
|
2039 | 0 | goto on_error; |
2040 | 0 | } |
2041 | 0 | if( libewf_lef_source_get_identifier( |
2042 | 0 | lef_source, |
2043 | 0 | &source_identifier, |
2044 | 0 | error ) != 1 ) |
2045 | 0 | { |
2046 | 0 | libcerror_error_set( |
2047 | 0 | error, |
2048 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
2049 | 0 | LIBCERROR_RUNTIME_ERROR_GET_FAILED, |
2050 | 0 | "%s: unable to retrieve source: %d identifier.", |
2051 | 0 | function, |
2052 | 0 | line_reader->line_index ); |
2053 | |
|
2054 | 0 | goto on_error; |
2055 | 0 | } |
2056 | 0 | if( source_identifier != ( source_index + 1 ) ) |
2057 | 0 | { |
2058 | 0 | libcerror_error_set( |
2059 | 0 | error, |
2060 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
2061 | 0 | LIBCERROR_RUNTIME_ERROR_UNSUPPORTED_VALUE, |
2062 | 0 | "%s: mismatch between source identifier and index.", |
2063 | 0 | function ); |
2064 | |
|
2065 | 0 | goto on_error; |
2066 | 0 | } |
2067 | 0 | if( libcdata_array_append_entry( |
2068 | 0 | single_files->sources, |
2069 | 0 | &entry_index, |
2070 | 0 | (intptr_t *) lef_source, |
2071 | 0 | error ) != 1 ) |
2072 | 0 | { |
2073 | 0 | libcerror_error_set( |
2074 | 0 | error, |
2075 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
2076 | 0 | LIBCERROR_RUNTIME_ERROR_APPEND_FAILED, |
2077 | 0 | "%s: unable to append source: %d to array.", |
2078 | 0 | function, |
2079 | 0 | source_index ); |
2080 | |
|
2081 | 0 | goto on_error; |
2082 | 0 | } |
2083 | 0 | lef_source = NULL; |
2084 | 0 | } |
2085 | 0 | if( libfvalue_split_utf8_string_free( |
2086 | 0 | &types, |
2087 | 0 | error ) != 1 ) |
2088 | 0 | { |
2089 | 0 | libcerror_error_set( |
2090 | 0 | error, |
2091 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
2092 | 0 | LIBCERROR_RUNTIME_ERROR_FINALIZE_FAILED, |
2093 | 0 | "%s: unable to free split types.", |
2094 | 0 | function ); |
2095 | |
|
2096 | 0 | goto on_error; |
2097 | 0 | } |
2098 | 0 | return( 1 ); |
2099 | | |
2100 | 1 | on_error: |
2101 | 1 | if( lef_source != NULL ) |
2102 | 0 | { |
2103 | 0 | libewf_lef_source_free( |
2104 | 0 | &lef_source, |
2105 | 0 | NULL ); |
2106 | 0 | } |
2107 | 1 | if( types != NULL ) |
2108 | 0 | { |
2109 | 0 | libfvalue_split_utf8_string_free( |
2110 | 0 | &types, |
2111 | 0 | NULL ); |
2112 | 0 | } |
2113 | 1 | return( -1 ); |
2114 | 0 | } |
2115 | | |
2116 | | /* Parses the "sub" category |
2117 | | * Returns 1 if successful or -1 on error |
2118 | | */ |
2119 | | int libewf_single_files_parse_sub_category( |
2120 | | libewf_single_files_t *single_files, |
2121 | | libewf_line_reader_t *line_reader, |
2122 | | libcerror_error_t **error ) |
2123 | 13 | { |
2124 | 13 | libewf_lef_subject_t *lef_subject = NULL; |
2125 | 13 | libfvalue_split_utf8_string_t *types = NULL; |
2126 | 13 | uint8_t *line_string = NULL; |
2127 | 13 | static char *function = "libewf_single_files_parse_sub_category"; |
2128 | 13 | size_t line_string_size = 0; |
2129 | 13 | int copy_of_number_of_subjects = 0; |
2130 | 13 | int number_of_entries = 0; |
2131 | 13 | int number_of_subjects = 0; |
2132 | 13 | int subject_index = 0; |
2133 | | |
2134 | 13 | if( single_files == NULL ) |
2135 | 0 | { |
2136 | 0 | libcerror_error_set( |
2137 | 0 | error, |
2138 | 0 | LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
2139 | 0 | LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, |
2140 | 0 | "%s: invalid single files.", |
2141 | 0 | function ); |
2142 | |
|
2143 | 0 | return( -1 ); |
2144 | 0 | } |
2145 | 13 | if( line_reader == NULL ) |
2146 | 0 | { |
2147 | 0 | libcerror_error_set( |
2148 | 0 | error, |
2149 | 0 | LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
2150 | 0 | LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, |
2151 | 0 | "%s: invalid line reader.", |
2152 | 0 | function ); |
2153 | |
|
2154 | 0 | return( -1 ); |
2155 | 0 | } |
2156 | 13 | if( libewf_single_files_parse_category_number_of_entries( |
2157 | 13 | single_files, |
2158 | 13 | line_reader, |
2159 | 13 | &number_of_subjects, |
2160 | 13 | error ) != 1 ) |
2161 | 13 | { |
2162 | 13 | libcerror_error_set( |
2163 | 13 | error, |
2164 | 13 | LIBCERROR_ERROR_DOMAIN_CONVERSION, |
2165 | 13 | LIBCERROR_CONVERSION_ERROR_GENERIC, |
2166 | 13 | "%s: unable to parse number of subjects in line: %d.", |
2167 | 13 | function, |
2168 | 13 | line_reader->line_index ); |
2169 | | |
2170 | 13 | goto on_error; |
2171 | 13 | } |
2172 | 0 | if( libewf_single_files_parse_category_types( |
2173 | 0 | single_files, |
2174 | 0 | line_reader, |
2175 | 0 | &types, |
2176 | 0 | error ) != 1 ) |
2177 | 0 | { |
2178 | 0 | libcerror_error_set( |
2179 | 0 | error, |
2180 | 0 | LIBCERROR_ERROR_DOMAIN_CONVERSION, |
2181 | 0 | LIBCERROR_CONVERSION_ERROR_GENERIC, |
2182 | 0 | "%s: unable to parse types in line: %d.", |
2183 | 0 | function, |
2184 | 0 | line_reader->line_index ); |
2185 | |
|
2186 | 0 | goto on_error; |
2187 | 0 | } |
2188 | 0 | if( libewf_single_files_parse_number_of_entries( |
2189 | 0 | single_files, |
2190 | 0 | line_reader, |
2191 | 0 | ©_of_number_of_subjects, |
2192 | 0 | error ) != 1 ) |
2193 | 0 | { |
2194 | 0 | libcerror_error_set( |
2195 | 0 | error, |
2196 | 0 | LIBCERROR_ERROR_DOMAIN_CONVERSION, |
2197 | 0 | LIBCERROR_CONVERSION_ERROR_GENERIC, |
2198 | 0 | "%s: unable to parse number of subjects in line: %d.", |
2199 | 0 | function, |
2200 | 0 | line_reader->line_index ); |
2201 | |
|
2202 | 0 | goto on_error; |
2203 | 0 | } |
2204 | 0 | if( number_of_subjects != copy_of_number_of_subjects ) |
2205 | 0 | { |
2206 | 0 | libcerror_error_set( |
2207 | 0 | error, |
2208 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
2209 | 0 | LIBCERROR_RUNTIME_ERROR_VALUE_OUT_OF_BOUNDS, |
2210 | 0 | "%s: mismatch between number of subjects and copy.", |
2211 | 0 | function ); |
2212 | |
|
2213 | 0 | goto on_error; |
2214 | 0 | } |
2215 | | /* Parse the category root entry |
2216 | | */ |
2217 | 0 | if( libewf_line_reader_read_utf8_string( |
2218 | 0 | line_reader, |
2219 | 0 | &line_string, |
2220 | 0 | &line_string_size, |
2221 | 0 | error ) != 1 ) |
2222 | 0 | { |
2223 | 0 | libcerror_error_set( |
2224 | 0 | error, |
2225 | 0 | LIBCERROR_ERROR_DOMAIN_IO, |
2226 | 0 | LIBCERROR_IO_ERROR_READ_FAILED, |
2227 | 0 | "%s: unable to read line: %d.", |
2228 | 0 | function, |
2229 | 0 | line_reader->line_index ); |
2230 | |
|
2231 | 0 | goto on_error; |
2232 | 0 | } |
2233 | 0 | if( libewf_lef_subject_initialize( |
2234 | 0 | &lef_subject, |
2235 | 0 | error ) != 1 ) |
2236 | 0 | { |
2237 | 0 | libcerror_error_set( |
2238 | 0 | error, |
2239 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
2240 | 0 | LIBCERROR_RUNTIME_ERROR_INITIALIZE_FAILED, |
2241 | 0 | "%s: unable to create subject.", |
2242 | 0 | function ); |
2243 | |
|
2244 | 0 | goto on_error; |
2245 | 0 | } |
2246 | 0 | if( libewf_lef_subject_read_data( |
2247 | 0 | lef_subject, |
2248 | 0 | types, |
2249 | 0 | line_string, |
2250 | 0 | line_string_size, |
2251 | 0 | error ) != 1 ) |
2252 | 0 | { |
2253 | 0 | libcerror_error_set( |
2254 | 0 | error, |
2255 | 0 | LIBCERROR_ERROR_DOMAIN_IO, |
2256 | 0 | LIBCERROR_IO_ERROR_READ_FAILED, |
2257 | 0 | "%s: unable to read subject", |
2258 | 0 | function ); |
2259 | |
|
2260 | 0 | goto on_error; |
2261 | 0 | } |
2262 | | /* TODO implement */ |
2263 | | |
2264 | 0 | if( libewf_lef_subject_free( |
2265 | 0 | &lef_subject, |
2266 | 0 | error ) != 1 ) |
2267 | 0 | { |
2268 | 0 | libcerror_error_set( |
2269 | 0 | error, |
2270 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
2271 | 0 | LIBCERROR_RUNTIME_ERROR_INITIALIZE_FAILED, |
2272 | 0 | "%s: unable to free subject.", |
2273 | 0 | function ); |
2274 | |
|
2275 | 0 | goto on_error; |
2276 | 0 | } |
2277 | 0 | for( subject_index = 0; |
2278 | 0 | subject_index < number_of_subjects; |
2279 | 0 | subject_index++ ) |
2280 | 0 | { |
2281 | 0 | if( libewf_single_files_parse_number_of_entries( |
2282 | 0 | single_files, |
2283 | 0 | line_reader, |
2284 | 0 | &number_of_entries, |
2285 | 0 | error ) != 1 ) |
2286 | 0 | { |
2287 | 0 | libcerror_error_set( |
2288 | 0 | error, |
2289 | 0 | LIBCERROR_ERROR_DOMAIN_CONVERSION, |
2290 | 0 | LIBCERROR_CONVERSION_ERROR_GENERIC, |
2291 | 0 | "%s: unable to parse number of entries in line: %d.", |
2292 | 0 | function, |
2293 | 0 | line_reader->line_index ); |
2294 | |
|
2295 | 0 | goto on_error; |
2296 | 0 | } |
2297 | 0 | if( number_of_entries != 0 ) |
2298 | 0 | { |
2299 | 0 | libcerror_error_set( |
2300 | 0 | error, |
2301 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
2302 | 0 | LIBCERROR_RUNTIME_ERROR_VALUE_OUT_OF_BOUNDS, |
2303 | 0 | "%s: invalid number of entries value out of bounds.", |
2304 | 0 | function ); |
2305 | |
|
2306 | 0 | goto on_error; |
2307 | 0 | } |
2308 | | /* Parse the subject entry |
2309 | | */ |
2310 | 0 | if( libewf_line_reader_read_utf8_string( |
2311 | 0 | line_reader, |
2312 | 0 | &line_string, |
2313 | 0 | &line_string_size, |
2314 | 0 | error ) != 1 ) |
2315 | 0 | { |
2316 | 0 | libcerror_error_set( |
2317 | 0 | error, |
2318 | 0 | LIBCERROR_ERROR_DOMAIN_IO, |
2319 | 0 | LIBCERROR_IO_ERROR_READ_FAILED, |
2320 | 0 | "%s: unable to read line: %d.", |
2321 | 0 | function, |
2322 | 0 | line_reader->line_index ); |
2323 | |
|
2324 | 0 | goto on_error; |
2325 | 0 | } |
2326 | 0 | if( libewf_lef_subject_initialize( |
2327 | 0 | &lef_subject, |
2328 | 0 | error ) != 1 ) |
2329 | 0 | { |
2330 | 0 | libcerror_error_set( |
2331 | 0 | error, |
2332 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
2333 | 0 | LIBCERROR_RUNTIME_ERROR_INITIALIZE_FAILED, |
2334 | 0 | "%s: unable to create subject: %d.", |
2335 | 0 | function, |
2336 | 0 | subject_index ); |
2337 | |
|
2338 | 0 | goto on_error; |
2339 | 0 | } |
2340 | 0 | if( libewf_lef_subject_read_data( |
2341 | 0 | lef_subject, |
2342 | 0 | types, |
2343 | 0 | line_string, |
2344 | 0 | line_string_size, |
2345 | 0 | error ) != 1 ) |
2346 | 0 | { |
2347 | 0 | libcerror_error_set( |
2348 | 0 | error, |
2349 | 0 | LIBCERROR_ERROR_DOMAIN_IO, |
2350 | 0 | LIBCERROR_IO_ERROR_READ_FAILED, |
2351 | 0 | "%s: unable to read subject: %d", |
2352 | 0 | function, |
2353 | 0 | subject_index ); |
2354 | |
|
2355 | 0 | goto on_error; |
2356 | 0 | } |
2357 | | /* TODO implement append subject to array */ |
2358 | | |
2359 | 0 | if( libewf_lef_subject_free( |
2360 | 0 | &lef_subject, |
2361 | 0 | error ) != 1 ) |
2362 | 0 | { |
2363 | 0 | libcerror_error_set( |
2364 | 0 | error, |
2365 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
2366 | 0 | LIBCERROR_RUNTIME_ERROR_INITIALIZE_FAILED, |
2367 | 0 | "%s: unable to free subject.", |
2368 | 0 | function ); |
2369 | |
|
2370 | 0 | goto on_error; |
2371 | 0 | } |
2372 | 0 | } |
2373 | 0 | if( libfvalue_split_utf8_string_free( |
2374 | 0 | &types, |
2375 | 0 | error ) != 1 ) |
2376 | 0 | { |
2377 | 0 | libcerror_error_set( |
2378 | 0 | error, |
2379 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
2380 | 0 | LIBCERROR_RUNTIME_ERROR_FINALIZE_FAILED, |
2381 | 0 | "%s: unable to free split types.", |
2382 | 0 | function ); |
2383 | |
|
2384 | 0 | goto on_error; |
2385 | 0 | } |
2386 | 0 | return( 1 ); |
2387 | | |
2388 | 13 | on_error: |
2389 | 13 | if( lef_subject != NULL ) |
2390 | 0 | { |
2391 | 0 | libewf_lef_subject_free( |
2392 | 0 | &lef_subject, |
2393 | 0 | NULL ); |
2394 | 0 | } |
2395 | 13 | if( types != NULL ) |
2396 | 0 | { |
2397 | 0 | libfvalue_split_utf8_string_free( |
2398 | 0 | &types, |
2399 | 0 | NULL ); |
2400 | 0 | } |
2401 | 13 | return( -1 ); |
2402 | 0 | } |
2403 | | |
2404 | | /* Parses the "entry" category |
2405 | | * Returns 1 if successful or -1 on error |
2406 | | */ |
2407 | | int libewf_single_files_parse_entry_category( |
2408 | | libewf_single_files_t *single_files, |
2409 | | libewf_line_reader_t *line_reader, |
2410 | | uint8_t *format, |
2411 | | libcerror_error_t **error ) |
2412 | 0 | { |
2413 | 0 | libfvalue_split_utf8_string_t *types = NULL; |
2414 | 0 | static char *function = "libewf_single_files_parse_entry_category"; |
2415 | 0 | int number_of_sub_entries = 0; |
2416 | |
|
2417 | 0 | if( single_files == NULL ) |
2418 | 0 | { |
2419 | 0 | libcerror_error_set( |
2420 | 0 | error, |
2421 | 0 | LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
2422 | 0 | LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, |
2423 | 0 | "%s: invalid single files.", |
2424 | 0 | function ); |
2425 | |
|
2426 | 0 | return( -1 ); |
2427 | 0 | } |
2428 | 0 | if( single_files->file_entry_tree_root_node != NULL ) |
2429 | 0 | { |
2430 | 0 | libcerror_error_set( |
2431 | 0 | error, |
2432 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
2433 | 0 | LIBCERROR_RUNTIME_ERROR_VALUE_ALREADY_SET, |
2434 | 0 | "%s: invalid single files - file entry tree root node value already set.", |
2435 | 0 | function ); |
2436 | |
|
2437 | 0 | return( -1 ); |
2438 | 0 | } |
2439 | 0 | if( line_reader == NULL ) |
2440 | 0 | { |
2441 | 0 | libcerror_error_set( |
2442 | 0 | error, |
2443 | 0 | LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
2444 | 0 | LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, |
2445 | 0 | "%s: invalid line reader.", |
2446 | 0 | function ); |
2447 | |
|
2448 | 0 | return( -1 ); |
2449 | 0 | } |
2450 | 0 | if( libewf_single_files_parse_category_number_of_entries( |
2451 | 0 | single_files, |
2452 | 0 | line_reader, |
2453 | 0 | &number_of_sub_entries, |
2454 | 0 | error ) != 1 ) |
2455 | 0 | { |
2456 | 0 | libcerror_error_set( |
2457 | 0 | error, |
2458 | 0 | LIBCERROR_ERROR_DOMAIN_CONVERSION, |
2459 | 0 | LIBCERROR_CONVERSION_ERROR_GENERIC, |
2460 | 0 | "%s: unable to parse number of entries in line: %d.", |
2461 | 0 | function, |
2462 | 0 | line_reader->line_index ); |
2463 | |
|
2464 | 0 | goto on_error; |
2465 | 0 | } |
2466 | 0 | if( libewf_single_files_parse_category_types( |
2467 | 0 | single_files, |
2468 | 0 | line_reader, |
2469 | 0 | &types, |
2470 | 0 | error ) != 1 ) |
2471 | 0 | { |
2472 | 0 | libcerror_error_set( |
2473 | 0 | error, |
2474 | 0 | LIBCERROR_ERROR_DOMAIN_CONVERSION, |
2475 | 0 | LIBCERROR_CONVERSION_ERROR_GENERIC, |
2476 | 0 | "%s: unable to parse types in line: %d.", |
2477 | 0 | function, |
2478 | 0 | line_reader->line_index ); |
2479 | |
|
2480 | 0 | goto on_error; |
2481 | 0 | } |
2482 | 0 | if( libewf_single_files_parse_format( |
2483 | 0 | types, |
2484 | 0 | format, |
2485 | 0 | error ) != 1 ) |
2486 | 0 | { |
2487 | 0 | libcerror_error_set( |
2488 | 0 | error, |
2489 | 0 | LIBCERROR_ERROR_DOMAIN_CONVERSION, |
2490 | 0 | LIBCERROR_CONVERSION_ERROR_GENERIC, |
2491 | 0 | "%s: unable to parse format.", |
2492 | 0 | function ); |
2493 | |
|
2494 | 0 | goto on_error; |
2495 | 0 | } |
2496 | 0 | if( libcdata_tree_node_initialize( |
2497 | 0 | &( single_files->file_entry_tree_root_node ), |
2498 | 0 | error ) != 1 ) |
2499 | 0 | { |
2500 | 0 | libcerror_error_set( |
2501 | 0 | error, |
2502 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
2503 | 0 | LIBCERROR_RUNTIME_ERROR_INITIALIZE_FAILED, |
2504 | 0 | "%s: unable to create file entry tree root node.", |
2505 | 0 | function ); |
2506 | |
|
2507 | 0 | goto on_error; |
2508 | 0 | } |
2509 | 0 | if( libewf_single_files_parse_file_entry( |
2510 | 0 | single_files, |
2511 | 0 | line_reader, |
2512 | 0 | single_files->file_entry_tree_root_node, |
2513 | 0 | types, |
2514 | 0 | 0, |
2515 | 0 | error ) != 1 ) |
2516 | 0 | { |
2517 | 0 | libcerror_error_set( |
2518 | 0 | error, |
2519 | 0 | LIBCERROR_ERROR_DOMAIN_CONVERSION, |
2520 | 0 | LIBCERROR_CONVERSION_ERROR_GENERIC, |
2521 | 0 | "%s: unable to parse file entry.", |
2522 | 0 | function ); |
2523 | |
|
2524 | 0 | goto on_error; |
2525 | 0 | } |
2526 | 0 | if( libfvalue_split_utf8_string_free( |
2527 | 0 | &types, |
2528 | 0 | error ) != 1 ) |
2529 | 0 | { |
2530 | 0 | libcerror_error_set( |
2531 | 0 | error, |
2532 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
2533 | 0 | LIBCERROR_RUNTIME_ERROR_FINALIZE_FAILED, |
2534 | 0 | "%s: unable to free split types.", |
2535 | 0 | function ); |
2536 | |
|
2537 | 0 | goto on_error; |
2538 | 0 | } |
2539 | 0 | return( 1 ); |
2540 | | |
2541 | 0 | on_error: |
2542 | 0 | if( single_files->file_entry_tree_root_node != NULL ) |
2543 | 0 | { |
2544 | 0 | libcdata_tree_node_free( |
2545 | 0 | &( single_files->file_entry_tree_root_node ), |
2546 | 0 | (int (*)(intptr_t **, libcerror_error_t **)) &libewf_lef_file_entry_free, |
2547 | 0 | NULL ); |
2548 | 0 | } |
2549 | 0 | if( types != NULL ) |
2550 | 0 | { |
2551 | 0 | libfvalue_split_utf8_string_free( |
2552 | 0 | &types, |
2553 | 0 | NULL ); |
2554 | 0 | } |
2555 | 0 | return( -1 ); |
2556 | 0 | } |
2557 | | |
2558 | | /* Parses a file entry string for the values |
2559 | | * Returns 1 if successful or -1 on error |
2560 | | */ |
2561 | | int libewf_single_files_parse_file_entry( |
2562 | | libewf_single_files_t *single_files, |
2563 | | libewf_line_reader_t *line_reader, |
2564 | | libcdata_tree_node_t *parent_file_entry_node, |
2565 | | libfvalue_split_utf8_string_t *types, |
2566 | | int recursion_depth, |
2567 | | libcerror_error_t **error ) |
2568 | 0 | { |
2569 | 0 | libcdata_tree_node_t *file_entry_node = NULL; |
2570 | 0 | libewf_lef_file_entry_t *lef_file_entry = NULL; |
2571 | 0 | libfvalue_split_utf8_string_t *values = NULL; |
2572 | 0 | const uint8_t *line_data = NULL; |
2573 | 0 | static char *function = "libewf_single_files_parse_file_entry"; |
2574 | 0 | size_t line_data_size = 0; |
2575 | 0 | int number_of_sub_entries = 0; |
2576 | 0 | int sub_entry_index = 0; |
2577 | |
|
2578 | 0 | if( single_files == NULL ) |
2579 | 0 | { |
2580 | 0 | libcerror_error_set( |
2581 | 0 | error, |
2582 | 0 | LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
2583 | 0 | LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, |
2584 | 0 | "%s: invalid single files.", |
2585 | 0 | function ); |
2586 | |
|
2587 | 0 | return( -1 ); |
2588 | 0 | } |
2589 | 0 | if( line_reader == NULL ) |
2590 | 0 | { |
2591 | 0 | libcerror_error_set( |
2592 | 0 | error, |
2593 | 0 | LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
2594 | 0 | LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, |
2595 | 0 | "%s: invalid line reader.", |
2596 | 0 | function ); |
2597 | |
|
2598 | 0 | return( -1 ); |
2599 | 0 | } |
2600 | 0 | if( parent_file_entry_node == NULL ) |
2601 | 0 | { |
2602 | 0 | libcerror_error_set( |
2603 | 0 | error, |
2604 | 0 | LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
2605 | 0 | LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, |
2606 | 0 | "%s: invalid parent file entry node.", |
2607 | 0 | function ); |
2608 | |
|
2609 | 0 | return( -1 ); |
2610 | 0 | } |
2611 | 0 | if( ( recursion_depth < 0 ) |
2612 | 0 | || ( recursion_depth > LIBEWF_MAXIMUM_RECURSION_DEPTH ) ) |
2613 | 0 | { |
2614 | 0 | libcerror_error_set( |
2615 | 0 | error, |
2616 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
2617 | 0 | LIBCERROR_RUNTIME_ERROR_VALUE_OUT_OF_BOUNDS, |
2618 | 0 | "%s: invalid recursion depth value out of bounds.", |
2619 | 0 | function ); |
2620 | |
|
2621 | 0 | return( -1 ); |
2622 | 0 | } |
2623 | 0 | if( libewf_single_files_parse_file_entry_number_of_sub_entries( |
2624 | 0 | single_files, |
2625 | 0 | line_reader, |
2626 | 0 | &number_of_sub_entries, |
2627 | 0 | error ) != 1 ) |
2628 | 0 | { |
2629 | 0 | libcerror_error_set( |
2630 | 0 | error, |
2631 | 0 | LIBCERROR_ERROR_DOMAIN_CONVERSION, |
2632 | 0 | LIBCERROR_CONVERSION_ERROR_GENERIC, |
2633 | 0 | "%s: unable to parse file entry number of sub entries.", |
2634 | 0 | function ); |
2635 | |
|
2636 | 0 | goto on_error; |
2637 | 0 | } |
2638 | 0 | if( libewf_line_reader_read_data( |
2639 | 0 | line_reader, |
2640 | 0 | &line_data, |
2641 | 0 | &line_data_size, |
2642 | 0 | error ) != 1 ) |
2643 | 0 | { |
2644 | 0 | libcerror_error_set( |
2645 | 0 | error, |
2646 | 0 | LIBCERROR_ERROR_DOMAIN_IO, |
2647 | 0 | LIBCERROR_IO_ERROR_READ_FAILED, |
2648 | 0 | "%s: unable to read line: %d data.", |
2649 | 0 | function, |
2650 | 0 | line_reader->line_index ); |
2651 | |
|
2652 | 0 | goto on_error; |
2653 | 0 | } |
2654 | 0 | if( libewf_lef_file_entry_initialize( |
2655 | 0 | &lef_file_entry, |
2656 | 0 | error ) != 1 ) |
2657 | 0 | { |
2658 | 0 | libcerror_error_set( |
2659 | 0 | error, |
2660 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
2661 | 0 | LIBCERROR_RUNTIME_ERROR_INITIALIZE_FAILED, |
2662 | 0 | "%s: unable to create file entry.", |
2663 | 0 | function ); |
2664 | |
|
2665 | 0 | goto on_error; |
2666 | 0 | } |
2667 | 0 | if( libewf_lef_file_entry_read_data( |
2668 | 0 | lef_file_entry, |
2669 | 0 | types, |
2670 | 0 | line_data, |
2671 | 0 | line_data_size, |
2672 | 0 | error ) != 1 ) |
2673 | 0 | { |
2674 | 0 | libcerror_error_set( |
2675 | 0 | error, |
2676 | 0 | LIBCERROR_ERROR_DOMAIN_IO, |
2677 | 0 | LIBCERROR_IO_ERROR_READ_FAILED, |
2678 | 0 | "%s: unable to read file entry", |
2679 | 0 | function ); |
2680 | |
|
2681 | 0 | goto on_error; |
2682 | 0 | } |
2683 | 0 | if( libcdata_tree_node_set_value( |
2684 | 0 | parent_file_entry_node, |
2685 | 0 | (intptr_t *) lef_file_entry, |
2686 | 0 | error ) != 1 ) |
2687 | 0 | { |
2688 | 0 | libcerror_error_set( |
2689 | 0 | error, |
2690 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
2691 | 0 | LIBCERROR_RUNTIME_ERROR_SET_FAILED, |
2692 | 0 | "%s: unable to set file entry in node.", |
2693 | 0 | function ); |
2694 | |
|
2695 | 0 | goto on_error; |
2696 | 0 | } |
2697 | 0 | lef_file_entry = NULL; |
2698 | |
|
2699 | 0 | for( sub_entry_index = 0; |
2700 | 0 | sub_entry_index < number_of_sub_entries; |
2701 | 0 | sub_entry_index++ ) |
2702 | 0 | { |
2703 | 0 | if( libcdata_tree_node_initialize( |
2704 | 0 | &file_entry_node, |
2705 | 0 | error ) != 1 ) |
2706 | 0 | { |
2707 | 0 | libcerror_error_set( |
2708 | 0 | error, |
2709 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
2710 | 0 | LIBCERROR_RUNTIME_ERROR_INITIALIZE_FAILED, |
2711 | 0 | "%s: unable to create sub file entry: %d node.", |
2712 | 0 | function, |
2713 | 0 | sub_entry_index ); |
2714 | |
|
2715 | 0 | goto on_error; |
2716 | 0 | } |
2717 | 0 | if( libewf_single_files_parse_file_entry( |
2718 | 0 | single_files, |
2719 | 0 | line_reader, |
2720 | 0 | file_entry_node, |
2721 | 0 | types, |
2722 | 0 | recursion_depth + 1, |
2723 | 0 | error ) != 1 ) |
2724 | 0 | { |
2725 | 0 | libcerror_error_set( |
2726 | 0 | error, |
2727 | 0 | LIBCERROR_ERROR_DOMAIN_CONVERSION, |
2728 | 0 | LIBCERROR_CONVERSION_ERROR_GENERIC, |
2729 | 0 | "%s: unable to parse sub file entry: %d.", |
2730 | 0 | function, |
2731 | 0 | sub_entry_index ); |
2732 | |
|
2733 | 0 | goto on_error; |
2734 | 0 | } |
2735 | 0 | if( libcdata_tree_node_append_node( |
2736 | 0 | parent_file_entry_node, |
2737 | 0 | file_entry_node, |
2738 | 0 | error ) != 1 ) |
2739 | 0 | { |
2740 | 0 | libcerror_error_set( |
2741 | 0 | error, |
2742 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
2743 | 0 | LIBCERROR_RUNTIME_ERROR_APPEND_FAILED, |
2744 | 0 | "%s: unable to append sub file entry: %d node to parent.", |
2745 | 0 | function, |
2746 | 0 | sub_entry_index ); |
2747 | |
|
2748 | 0 | goto on_error; |
2749 | 0 | } |
2750 | 0 | file_entry_node = NULL; |
2751 | 0 | } |
2752 | 0 | return( 1 ); |
2753 | | |
2754 | 0 | on_error: |
2755 | 0 | if( file_entry_node != NULL ) |
2756 | 0 | { |
2757 | 0 | libcdata_tree_node_free( |
2758 | 0 | &file_entry_node, |
2759 | 0 | (int (*)(intptr_t **, libcerror_error_t **)) &libewf_lef_file_entry_free, |
2760 | 0 | NULL ); |
2761 | 0 | } |
2762 | 0 | if( lef_file_entry != NULL ) |
2763 | 0 | { |
2764 | 0 | libewf_lef_file_entry_free( |
2765 | 0 | &lef_file_entry, |
2766 | 0 | NULL ); |
2767 | 0 | } |
2768 | 0 | if( values != NULL ) |
2769 | 0 | { |
2770 | 0 | libfvalue_split_utf8_string_free( |
2771 | 0 | &values, |
2772 | 0 | NULL ); |
2773 | 0 | } |
2774 | 0 | return( -1 ); |
2775 | 0 | } |
2776 | | |
2777 | | /* Parses a file entry string for the number of sub entries |
2778 | | * Returns 1 if successful or -1 on error |
2779 | | */ |
2780 | | int libewf_single_files_parse_file_entry_number_of_sub_entries( |
2781 | | libewf_single_files_t *single_files, |
2782 | | libewf_line_reader_t *line_reader, |
2783 | | int *number_of_sub_entries, |
2784 | | libcerror_error_t **error ) |
2785 | 0 | { |
2786 | 0 | libfvalue_split_utf8_string_t *values = NULL; |
2787 | 0 | uint8_t *line_string = NULL; |
2788 | 0 | uint8_t *value_string = NULL; |
2789 | 0 | static char *function = "libewf_single_files_parse_file_entry_number_of_sub_entries"; |
2790 | 0 | size_t line_string_size = 0; |
2791 | 0 | size_t value_string_size = 0; |
2792 | 0 | uint64_t value_64bit = 0; |
2793 | 0 | int number_of_values = 0; |
2794 | |
|
2795 | 0 | if( single_files == NULL ) |
2796 | 0 | { |
2797 | 0 | libcerror_error_set( |
2798 | 0 | error, |
2799 | 0 | LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
2800 | 0 | LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, |
2801 | 0 | "%s: invalid single files.", |
2802 | 0 | function ); |
2803 | |
|
2804 | 0 | return( -1 ); |
2805 | 0 | } |
2806 | 0 | if( line_reader == NULL ) |
2807 | 0 | { |
2808 | 0 | libcerror_error_set( |
2809 | 0 | error, |
2810 | 0 | LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
2811 | 0 | LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, |
2812 | 0 | "%s: invalid line reader.", |
2813 | 0 | function ); |
2814 | |
|
2815 | 0 | return( -1 ); |
2816 | 0 | } |
2817 | 0 | if( number_of_sub_entries == NULL ) |
2818 | 0 | { |
2819 | 0 | libcerror_error_set( |
2820 | 0 | error, |
2821 | 0 | LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
2822 | 0 | LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, |
2823 | 0 | "%s: invalid number of sub entries.", |
2824 | 0 | function ); |
2825 | |
|
2826 | 0 | return( -1 ); |
2827 | 0 | } |
2828 | 0 | if( libewf_line_reader_read_utf8_string( |
2829 | 0 | line_reader, |
2830 | 0 | &line_string, |
2831 | 0 | &line_string_size, |
2832 | 0 | error ) != 1 ) |
2833 | 0 | { |
2834 | 0 | libcerror_error_set( |
2835 | 0 | error, |
2836 | 0 | LIBCERROR_ERROR_DOMAIN_IO, |
2837 | 0 | LIBCERROR_IO_ERROR_READ_FAILED, |
2838 | 0 | "%s: unable to read line: %d.", |
2839 | 0 | function, |
2840 | 0 | line_reader->line_index ); |
2841 | |
|
2842 | 0 | goto on_error; |
2843 | 0 | } |
2844 | 0 | if( libfvalue_utf8_string_split( |
2845 | 0 | line_string, |
2846 | 0 | line_string_size, |
2847 | 0 | (uint8_t) '\t', |
2848 | 0 | &values, |
2849 | 0 | error ) != 1 ) |
2850 | 0 | { |
2851 | 0 | libcerror_error_set( |
2852 | 0 | error, |
2853 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
2854 | 0 | LIBCERROR_RUNTIME_ERROR_INITIALIZE_FAILED, |
2855 | 0 | "%s: unable to split line string into values.", |
2856 | 0 | function ); |
2857 | |
|
2858 | 0 | goto on_error; |
2859 | 0 | } |
2860 | 0 | if( libfvalue_split_utf8_string_get_number_of_segments( |
2861 | 0 | values, |
2862 | 0 | &number_of_values, |
2863 | 0 | error ) != 1 ) |
2864 | 0 | { |
2865 | 0 | libcerror_error_set( |
2866 | 0 | error, |
2867 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
2868 | 0 | LIBCERROR_RUNTIME_ERROR_GET_FAILED, |
2869 | 0 | "%s: unable to retrieve number of values", |
2870 | 0 | function ); |
2871 | |
|
2872 | 0 | goto on_error; |
2873 | 0 | } |
2874 | 0 | if( number_of_values != 2 ) |
2875 | 0 | { |
2876 | 0 | libcerror_error_set( |
2877 | 0 | error, |
2878 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
2879 | 0 | LIBCERROR_RUNTIME_ERROR_UNSUPPORTED_VALUE, |
2880 | 0 | "%s: unsupported number of values.", |
2881 | 0 | function ); |
2882 | |
|
2883 | 0 | goto on_error; |
2884 | 0 | } |
2885 | 0 | if( libfvalue_split_utf8_string_get_segment_by_index( |
2886 | 0 | values, |
2887 | 0 | 0, |
2888 | 0 | &value_string, |
2889 | 0 | &value_string_size, |
2890 | 0 | error ) != 1 ) |
2891 | 0 | { |
2892 | 0 | libcerror_error_set( |
2893 | 0 | error, |
2894 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
2895 | 0 | LIBCERROR_RUNTIME_ERROR_GET_FAILED, |
2896 | 0 | "%s: unable to retrieve value string: 0.", |
2897 | 0 | function ); |
2898 | |
|
2899 | 0 | goto on_error; |
2900 | 0 | } |
2901 | 0 | if( libfvalue_split_utf8_string_get_segment_by_index( |
2902 | 0 | values, |
2903 | 0 | 0, |
2904 | 0 | &value_string, |
2905 | 0 | &value_string_size, |
2906 | 0 | error ) != 1 ) |
2907 | 0 | { |
2908 | 0 | libcerror_error_set( |
2909 | 0 | error, |
2910 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
2911 | 0 | LIBCERROR_RUNTIME_ERROR_GET_FAILED, |
2912 | 0 | "%s: unable to retrieve value string: 0.", |
2913 | 0 | function ); |
2914 | |
|
2915 | 0 | goto on_error; |
2916 | 0 | } |
2917 | 0 | if( libfvalue_utf8_string_copy_to_integer( |
2918 | 0 | value_string, |
2919 | 0 | value_string_size, |
2920 | 0 | &value_64bit, |
2921 | 0 | 64, |
2922 | 0 | LIBFVALUE_INTEGER_FORMAT_TYPE_DECIMAL_UNSIGNED, |
2923 | 0 | error ) != 1 ) |
2924 | 0 | { |
2925 | 0 | libcerror_error_set( |
2926 | 0 | error, |
2927 | 0 | LIBCERROR_ERROR_DOMAIN_MEMORY, |
2928 | 0 | LIBCERROR_MEMORY_ERROR_SET_FAILED, |
2929 | 0 | "%s: unable to set number of entries in parent value.", |
2930 | 0 | function ); |
2931 | |
|
2932 | 0 | goto on_error; |
2933 | 0 | } |
2934 | 0 | if( value_64bit > (uint64_t) INT_MAX ) |
2935 | 0 | { |
2936 | 0 | libcerror_error_set( |
2937 | 0 | error, |
2938 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
2939 | 0 | LIBCERROR_RUNTIME_ERROR_VALUE_OUT_OF_BOUNDS, |
2940 | 0 | "%s: invalid number of entries in parent value out of bounds.", |
2941 | 0 | function ); |
2942 | |
|
2943 | 0 | goto on_error; |
2944 | 0 | } |
2945 | 0 | if( ( value_64bit != 0 ) |
2946 | 0 | && ( value_64bit != 26 ) ) |
2947 | 0 | { |
2948 | 0 | libcerror_error_set( |
2949 | 0 | error, |
2950 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
2951 | 0 | LIBCERROR_RUNTIME_ERROR_UNSUPPORTED_VALUE, |
2952 | 0 | "%s: unsupported number of entries in parent value.", |
2953 | 0 | function ); |
2954 | |
|
2955 | 0 | goto on_error; |
2956 | 0 | } |
2957 | 0 | if( libfvalue_split_utf8_string_get_segment_by_index( |
2958 | 0 | values, |
2959 | 0 | 1, |
2960 | 0 | &value_string, |
2961 | 0 | &value_string_size, |
2962 | 0 | error ) != 1 ) |
2963 | 0 | { |
2964 | 0 | libcerror_error_set( |
2965 | 0 | error, |
2966 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
2967 | 0 | LIBCERROR_RUNTIME_ERROR_GET_FAILED, |
2968 | 0 | "%s: unable to retrieve value string: 1.", |
2969 | 0 | function ); |
2970 | |
|
2971 | 0 | goto on_error; |
2972 | 0 | } |
2973 | 0 | if( libfvalue_utf8_string_copy_to_integer( |
2974 | 0 | value_string, |
2975 | 0 | value_string_size, |
2976 | 0 | &value_64bit, |
2977 | 0 | 64, |
2978 | 0 | LIBFVALUE_INTEGER_FORMAT_TYPE_DECIMAL_UNSIGNED, |
2979 | 0 | error ) != 1 ) |
2980 | 0 | { |
2981 | 0 | libcerror_error_set( |
2982 | 0 | error, |
2983 | 0 | LIBCERROR_ERROR_DOMAIN_MEMORY, |
2984 | 0 | LIBCERROR_MEMORY_ERROR_SET_FAILED, |
2985 | 0 | "%s: unable to set number of sub entries.", |
2986 | 0 | function ); |
2987 | |
|
2988 | 0 | goto on_error; |
2989 | 0 | } |
2990 | 0 | if( value_64bit > (uint64_t) INT_MAX ) |
2991 | 0 | { |
2992 | 0 | libcerror_error_set( |
2993 | 0 | error, |
2994 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
2995 | 0 | LIBCERROR_RUNTIME_ERROR_VALUE_OUT_OF_BOUNDS, |
2996 | 0 | "%s: invalid number of sub entries value out of bounds.", |
2997 | 0 | function ); |
2998 | |
|
2999 | 0 | goto on_error; |
3000 | 0 | } |
3001 | 0 | if( libfvalue_split_utf8_string_free( |
3002 | 0 | &values, |
3003 | 0 | error ) != 1 ) |
3004 | 0 | { |
3005 | 0 | libcerror_error_set( |
3006 | 0 | error, |
3007 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
3008 | 0 | LIBCERROR_RUNTIME_ERROR_FINALIZE_FAILED, |
3009 | 0 | "%s: unable to free split values.", |
3010 | 0 | function ); |
3011 | |
|
3012 | 0 | goto on_error; |
3013 | 0 | } |
3014 | 0 | *number_of_sub_entries = (int) value_64bit; |
3015 | |
|
3016 | 0 | return( 1 ); |
3017 | | |
3018 | 0 | on_error: |
3019 | 0 | if( values != NULL ) |
3020 | 0 | { |
3021 | 0 | libfvalue_split_utf8_string_free( |
3022 | 0 | &values, |
3023 | 0 | NULL ); |
3024 | 0 | } |
3025 | 0 | return( -1 ); |
3026 | 0 | } |
3027 | | |
3028 | | /* Reads the single files |
3029 | | * Returns 1 if successful or -1 on error |
3030 | | */ |
3031 | | int libewf_single_files_read_data_stream( |
3032 | | libewf_single_files_t *single_files, |
3033 | | libfdata_stream_t *data_stream, |
3034 | | libbfio_pool_t *file_io_pool, |
3035 | | size64_t *media_size, |
3036 | | uint8_t *format, |
3037 | | libcerror_error_t **error ) |
3038 | 305 | { |
3039 | 305 | libewf_line_reader_t *line_reader = NULL; |
3040 | 305 | uint8_t *line_string = NULL; |
3041 | 305 | static char *function = "libewf_single_files_read_data_stream"; |
3042 | 305 | size_t line_string_size = 0; |
3043 | 305 | ssize_t bytes_remaining = 0; |
3044 | 305 | int category = 0; |
3045 | 305 | int has_category_entry = 0; |
3046 | 305 | int has_category_perm = 0; |
3047 | 305 | int has_category_rec = 0; |
3048 | 305 | int has_category_srce = 0; |
3049 | 305 | int has_category_sub = 0; |
3050 | | |
3051 | 305 | if( single_files == NULL ) |
3052 | 0 | { |
3053 | 0 | libcerror_error_set( |
3054 | 0 | error, |
3055 | 0 | LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
3056 | 0 | LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, |
3057 | 0 | "%s: invalid single files.", |
3058 | 0 | function ); |
3059 | |
|
3060 | 0 | return( -1 ); |
3061 | 0 | } |
3062 | 305 | if( libewf_line_reader_initialize( |
3063 | 305 | &line_reader, |
3064 | 305 | data_stream, |
3065 | 305 | file_io_pool, |
3066 | 305 | error ) != 1 ) |
3067 | 0 | { |
3068 | 0 | libcerror_error_set( |
3069 | 0 | error, |
3070 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
3071 | 0 | LIBCERROR_RUNTIME_ERROR_INITIALIZE_FAILED, |
3072 | 0 | "%s: unable to create line reader.", |
3073 | 0 | function ); |
3074 | |
|
3075 | 0 | goto on_error; |
3076 | 0 | } |
3077 | 305 | if( libewf_line_reader_read_utf8_string( |
3078 | 305 | line_reader, |
3079 | 305 | &line_string, |
3080 | 305 | &line_string_size, |
3081 | 305 | error ) != 1 ) |
3082 | 16 | { |
3083 | 16 | libcerror_error_set( |
3084 | 16 | error, |
3085 | 16 | LIBCERROR_ERROR_DOMAIN_IO, |
3086 | 16 | LIBCERROR_IO_ERROR_READ_FAILED, |
3087 | 16 | "%s: unable to read line: %d.", |
3088 | 16 | function, |
3089 | 16 | line_reader->line_index ); |
3090 | | |
3091 | 16 | goto on_error; |
3092 | 16 | } |
3093 | 289 | if( ( line_string_size != 2 ) |
3094 | 223 | || ( line_string[ 0 ] != (uint8_t) '5' ) ) |
3095 | 83 | { |
3096 | 83 | libcerror_error_set( |
3097 | 83 | error, |
3098 | 83 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
3099 | 83 | LIBCERROR_RUNTIME_ERROR_UNSUPPORTED_VALUE, |
3100 | 83 | "%s: unsupported number of categories string.", |
3101 | 83 | function ); |
3102 | | |
3103 | 83 | goto on_error; |
3104 | 83 | } |
3105 | 206 | do |
3106 | 224 | { |
3107 | 224 | if( libewf_line_reader_read_utf8_string( |
3108 | 224 | line_reader, |
3109 | 224 | &line_string, |
3110 | 224 | &line_string_size, |
3111 | 224 | error ) != 1 ) |
3112 | 3 | { |
3113 | 3 | libcerror_error_set( |
3114 | 3 | error, |
3115 | 3 | LIBCERROR_ERROR_DOMAIN_IO, |
3116 | 3 | LIBCERROR_IO_ERROR_READ_FAILED, |
3117 | 3 | "%s: unable to read line: %d.", |
3118 | 3 | function, |
3119 | 3 | line_reader->line_index ); |
3120 | | |
3121 | 3 | goto on_error; |
3122 | 3 | } |
3123 | 221 | category = LIBEWF_SINGLE_FILES_CATEGORY_UNDEFINED; |
3124 | | |
3125 | 221 | if( line_string_size == 0 ) |
3126 | 1 | { |
3127 | 1 | break; |
3128 | 1 | } |
3129 | 220 | if( line_string_size == 4 ) |
3130 | 137 | { |
3131 | 137 | if( ( line_string[ 0 ] == (uint8_t) 'r' ) |
3132 | 98 | && ( line_string[ 1 ] == (uint8_t) 'e' ) |
3133 | 89 | && ( line_string[ 2 ] == (uint8_t) 'c' ) ) |
3134 | 83 | { |
3135 | 83 | category = LIBEWF_SINGLE_FILES_CATEGORY_REC; |
3136 | 83 | } |
3137 | 54 | else if( ( line_string[ 0 ] == (uint8_t) 's' ) |
3138 | 30 | && ( line_string[ 1 ] == (uint8_t) 'u' ) |
3139 | 21 | && ( line_string[ 2 ] == (uint8_t) 'b' ) ) |
3140 | 13 | { |
3141 | 13 | category = LIBEWF_SINGLE_FILES_CATEGORY_SUB; |
3142 | 13 | } |
3143 | 137 | } |
3144 | 83 | else if( line_string_size == 5 ) |
3145 | 39 | { |
3146 | 39 | if( ( line_string[ 0 ] == (uint8_t) 'p' ) |
3147 | 21 | && ( line_string[ 1 ] == (uint8_t) 'e' ) |
3148 | 18 | && ( line_string[ 2 ] == (uint8_t) 'r' ) |
3149 | 8 | && ( line_string[ 3 ] == (uint8_t) 'm' ) ) |
3150 | 1 | { |
3151 | 1 | category = LIBEWF_SINGLE_FILES_CATEGORY_PERM; |
3152 | 1 | } |
3153 | 38 | else if( ( line_string[ 0 ] == (uint8_t) 's' ) |
3154 | 8 | && ( line_string[ 1 ] == (uint8_t) 'r' ) |
3155 | 7 | && ( line_string[ 2 ] == (uint8_t) 'c' ) |
3156 | 6 | && ( line_string[ 3 ] == (uint8_t) 'e' ) ) |
3157 | 1 | { |
3158 | 1 | category = LIBEWF_SINGLE_FILES_CATEGORY_SRCE; |
3159 | 1 | } |
3160 | 39 | } |
3161 | 44 | else if( line_string_size == 6 ) |
3162 | 17 | { |
3163 | 17 | if( ( line_string[ 0 ] == (uint8_t) 'e' ) |
3164 | 9 | && ( line_string[ 1 ] == (uint8_t) 'n' ) |
3165 | 3 | && ( line_string[ 2 ] == (uint8_t) 't' ) |
3166 | 0 | && ( line_string[ 3 ] == (uint8_t) 'r' ) |
3167 | 0 | && ( line_string[ 4 ] == (uint8_t) 'y' ) ) |
3168 | 0 | { |
3169 | 0 | category = LIBEWF_SINGLE_FILES_CATEGORY_ENTRY; |
3170 | 0 | } |
3171 | 17 | } |
3172 | 220 | if( ( category == LIBEWF_SINGLE_FILES_CATEGORY_UNDEFINED ) |
3173 | 122 | && ( has_category_entry != 0 ) |
3174 | 0 | && ( has_category_perm != 0 ) |
3175 | 0 | && ( has_category_rec != 0 ) |
3176 | 0 | && ( has_category_srce != 0 ) |
3177 | 0 | && ( has_category_sub != 0 ) ) |
3178 | 0 | { |
3179 | | /* TODO debug print trailing data */ |
3180 | 0 | break; |
3181 | 0 | } |
3182 | 220 | switch( category ) |
3183 | 220 | { |
3184 | 0 | case LIBEWF_SINGLE_FILES_CATEGORY_ENTRY: |
3185 | 0 | if( has_category_entry != 0 ) |
3186 | 0 | { |
3187 | 0 | libcerror_error_set( |
3188 | 0 | error, |
3189 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
3190 | 0 | LIBCERROR_RUNTIME_ERROR_VALUE_ALREADY_SET, |
3191 | 0 | "%s: invalid single files - category entry already read.", |
3192 | 0 | function ); |
3193 | |
|
3194 | 0 | goto on_error; |
3195 | 0 | } |
3196 | 0 | if( libewf_single_files_parse_entry_category( |
3197 | 0 | single_files, |
3198 | 0 | line_reader, |
3199 | 0 | format, |
3200 | 0 | error ) != 1 ) |
3201 | 0 | { |
3202 | 0 | libcerror_error_set( |
3203 | 0 | error, |
3204 | 0 | LIBCERROR_ERROR_DOMAIN_CONVERSION, |
3205 | 0 | LIBCERROR_CONVERSION_ERROR_GENERIC, |
3206 | 0 | "%s: unable to parse entry category.", |
3207 | 0 | function ); |
3208 | |
|
3209 | 0 | goto on_error; |
3210 | 0 | } |
3211 | 0 | has_category_entry = 1; |
3212 | |
|
3213 | 0 | break; |
3214 | | |
3215 | 1 | case LIBEWF_SINGLE_FILES_CATEGORY_PERM: |
3216 | 1 | if( has_category_perm != 0 ) |
3217 | 0 | { |
3218 | 0 | libcerror_error_set( |
3219 | 0 | error, |
3220 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
3221 | 0 | LIBCERROR_RUNTIME_ERROR_VALUE_ALREADY_SET, |
3222 | 0 | "%s: invalid single files - category perm already read.", |
3223 | 0 | function ); |
3224 | |
|
3225 | 0 | goto on_error; |
3226 | 0 | } |
3227 | 1 | if( libewf_single_files_parse_perm_category( |
3228 | 1 | single_files, |
3229 | 1 | line_reader, |
3230 | 1 | error ) != 1 ) |
3231 | 1 | { |
3232 | 1 | libcerror_error_set( |
3233 | 1 | error, |
3234 | 1 | LIBCERROR_ERROR_DOMAIN_CONVERSION, |
3235 | 1 | LIBCERROR_CONVERSION_ERROR_GENERIC, |
3236 | 1 | "%s: unable to parse perm category.", |
3237 | 1 | function ); |
3238 | | |
3239 | 1 | goto on_error; |
3240 | 1 | } |
3241 | 0 | has_category_perm = 1; |
3242 | |
|
3243 | 0 | break; |
3244 | | |
3245 | 83 | case LIBEWF_SINGLE_FILES_CATEGORY_REC: |
3246 | 83 | if( has_category_rec != 0 ) |
3247 | 1 | { |
3248 | 1 | libcerror_error_set( |
3249 | 1 | error, |
3250 | 1 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
3251 | 1 | LIBCERROR_RUNTIME_ERROR_VALUE_ALREADY_SET, |
3252 | 1 | "%s: invalid single files - category rec already read.", |
3253 | 1 | function ); |
3254 | | |
3255 | 1 | goto on_error; |
3256 | 1 | } |
3257 | 82 | if( libewf_single_files_parse_rec_category( |
3258 | 82 | single_files, |
3259 | 82 | line_reader, |
3260 | 82 | media_size, |
3261 | 82 | error ) != 1 ) |
3262 | 11 | { |
3263 | 11 | libcerror_error_set( |
3264 | 11 | error, |
3265 | 11 | LIBCERROR_ERROR_DOMAIN_CONVERSION, |
3266 | 11 | LIBCERROR_CONVERSION_ERROR_GENERIC, |
3267 | 11 | "%s: unable to parse rec category.", |
3268 | 11 | function ); |
3269 | | |
3270 | 11 | goto on_error; |
3271 | 11 | } |
3272 | 71 | has_category_rec = 1; |
3273 | | |
3274 | 71 | break; |
3275 | | |
3276 | 1 | case LIBEWF_SINGLE_FILES_CATEGORY_SRCE: |
3277 | 1 | if( has_category_srce != 0 ) |
3278 | 0 | { |
3279 | 0 | libcerror_error_set( |
3280 | 0 | error, |
3281 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
3282 | 0 | LIBCERROR_RUNTIME_ERROR_VALUE_ALREADY_SET, |
3283 | 0 | "%s: invalid single files - category srce already read.", |
3284 | 0 | function ); |
3285 | |
|
3286 | 0 | goto on_error; |
3287 | 0 | } |
3288 | 1 | if( libewf_single_files_parse_srce_category( |
3289 | 1 | single_files, |
3290 | 1 | line_reader, |
3291 | 1 | error ) != 1 ) |
3292 | 1 | { |
3293 | 1 | libcerror_error_set( |
3294 | 1 | error, |
3295 | 1 | LIBCERROR_ERROR_DOMAIN_CONVERSION, |
3296 | 1 | LIBCERROR_CONVERSION_ERROR_GENERIC, |
3297 | 1 | "%s: unable to parse srce category.", |
3298 | 1 | function ); |
3299 | | |
3300 | 1 | goto on_error; |
3301 | 1 | } |
3302 | 0 | has_category_srce = 1; |
3303 | |
|
3304 | 0 | break; |
3305 | | |
3306 | 13 | case LIBEWF_SINGLE_FILES_CATEGORY_SUB: |
3307 | 13 | if( has_category_sub != 0 ) |
3308 | 0 | { |
3309 | 0 | libcerror_error_set( |
3310 | 0 | error, |
3311 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
3312 | 0 | LIBCERROR_RUNTIME_ERROR_VALUE_ALREADY_SET, |
3313 | 0 | "%s: invalid single files - category sub already read.", |
3314 | 0 | function ); |
3315 | |
|
3316 | 0 | goto on_error; |
3317 | 0 | } |
3318 | 13 | if( libewf_single_files_parse_sub_category( |
3319 | 13 | single_files, |
3320 | 13 | line_reader, |
3321 | 13 | error ) != 1 ) |
3322 | 13 | { |
3323 | 13 | libcerror_error_set( |
3324 | 13 | error, |
3325 | 13 | LIBCERROR_ERROR_DOMAIN_CONVERSION, |
3326 | 13 | LIBCERROR_CONVERSION_ERROR_GENERIC, |
3327 | 13 | "%s: unable to parse sub category.", |
3328 | 13 | function ); |
3329 | | |
3330 | 13 | goto on_error; |
3331 | 13 | } |
3332 | 0 | has_category_sub = 1; |
3333 | |
|
3334 | 0 | break; |
3335 | | |
3336 | 122 | default: |
3337 | 122 | libcerror_error_set( |
3338 | 122 | error, |
3339 | 122 | LIBCERROR_ERROR_DOMAIN_CONVERSION, |
3340 | 122 | LIBCERROR_CONVERSION_ERROR_GENERIC, |
3341 | 122 | "%s: unsupported category.", |
3342 | 122 | function ); |
3343 | | |
3344 | 122 | goto on_error; |
3345 | 220 | } |
3346 | | /* The category should be followed by an empty line |
3347 | | */ |
3348 | 71 | if( libewf_line_reader_read_utf8_string( |
3349 | 71 | line_reader, |
3350 | 71 | &line_string, |
3351 | 71 | &line_string_size, |
3352 | 71 | error ) != 1 ) |
3353 | 16 | { |
3354 | 16 | libcerror_error_set( |
3355 | 16 | error, |
3356 | 16 | LIBCERROR_ERROR_DOMAIN_IO, |
3357 | 16 | LIBCERROR_IO_ERROR_READ_FAILED, |
3358 | 16 | "%s: unable to read line: %d.", |
3359 | 16 | function, |
3360 | 16 | line_reader->line_index ); |
3361 | | |
3362 | 16 | goto on_error; |
3363 | 16 | } |
3364 | 55 | if( ( line_string_size != 1 ) |
3365 | 21 | || ( line_string[ 0 ] != 0 ) ) |
3366 | 34 | { |
3367 | 34 | libcerror_error_set( |
3368 | 34 | error, |
3369 | 34 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
3370 | 34 | LIBCERROR_RUNTIME_ERROR_UNSUPPORTED_VALUE, |
3371 | 34 | "%s: unsupported empty line string: %d - not empty.", |
3372 | 34 | function, |
3373 | 34 | line_reader->line_index - 1 ); |
3374 | | |
3375 | 34 | goto on_error; |
3376 | 34 | } |
3377 | 21 | bytes_remaining = libewf_line_reader_get_remaining_size( |
3378 | 21 | line_reader, |
3379 | 21 | error ); |
3380 | | |
3381 | 21 | if( bytes_remaining < 0 ) |
3382 | 0 | { |
3383 | 0 | libcerror_error_set( |
3384 | 0 | error, |
3385 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
3386 | 0 | LIBCERROR_RUNTIME_ERROR_GET_FAILED, |
3387 | 0 | "%s: unable to determine number of bytes remaining.", |
3388 | 0 | function ); |
3389 | |
|
3390 | 0 | goto on_error; |
3391 | 0 | } |
3392 | 21 | } |
3393 | 206 | while( bytes_remaining > 5 ); |
3394 | | |
3395 | 4 | if( has_category_entry == 0 ) |
3396 | 4 | { |
3397 | 4 | libcerror_error_set( |
3398 | 4 | error, |
3399 | 4 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
3400 | 4 | LIBCERROR_RUNTIME_ERROR_VALUE_MISSING, |
3401 | 4 | "%s: invalid single files - missing category entry.", |
3402 | 4 | function ); |
3403 | | |
3404 | 4 | goto on_error; |
3405 | 4 | } |
3406 | 0 | if( has_category_perm == 0 ) |
3407 | 0 | { |
3408 | 0 | libcerror_error_set( |
3409 | 0 | error, |
3410 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
3411 | 0 | LIBCERROR_RUNTIME_ERROR_VALUE_MISSING, |
3412 | 0 | "%s: invalid single files - missing category perm.", |
3413 | 0 | function ); |
3414 | |
|
3415 | 0 | goto on_error; |
3416 | 0 | } |
3417 | 0 | if( has_category_rec == 0 ) |
3418 | 0 | { |
3419 | 0 | libcerror_error_set( |
3420 | 0 | error, |
3421 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
3422 | 0 | LIBCERROR_RUNTIME_ERROR_VALUE_MISSING, |
3423 | 0 | "%s: invalid single files - missing category rec.", |
3424 | 0 | function ); |
3425 | |
|
3426 | 0 | goto on_error; |
3427 | 0 | } |
3428 | 0 | if( has_category_srce == 0 ) |
3429 | 0 | { |
3430 | 0 | libcerror_error_set( |
3431 | 0 | error, |
3432 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
3433 | 0 | LIBCERROR_RUNTIME_ERROR_VALUE_MISSING, |
3434 | 0 | "%s: invalid single files - missing category srce.", |
3435 | 0 | function ); |
3436 | |
|
3437 | 0 | goto on_error; |
3438 | 0 | } |
3439 | 0 | if( has_category_sub == 0 ) |
3440 | 0 | { |
3441 | 0 | libcerror_error_set( |
3442 | 0 | error, |
3443 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
3444 | 0 | LIBCERROR_RUNTIME_ERROR_VALUE_MISSING, |
3445 | 0 | "%s: invalid single files - missing category sub.", |
3446 | 0 | function ); |
3447 | |
|
3448 | 0 | goto on_error; |
3449 | 0 | } |
3450 | 0 | if( libewf_line_reader_free( |
3451 | 0 | &line_reader, |
3452 | 0 | error ) != 1 ) |
3453 | 0 | { |
3454 | 0 | libcerror_error_set( |
3455 | 0 | error, |
3456 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
3457 | 0 | LIBCERROR_RUNTIME_ERROR_FINALIZE_FAILED, |
3458 | 0 | "%s: unable to free line reader.", |
3459 | 0 | function ); |
3460 | |
|
3461 | 0 | goto on_error; |
3462 | 0 | } |
3463 | 0 | return( 1 ); |
3464 | | |
3465 | 305 | on_error: |
3466 | 305 | if( line_reader != NULL ) |
3467 | 305 | { |
3468 | 305 | libewf_line_reader_free( |
3469 | 305 | &line_reader, |
3470 | 305 | NULL ); |
3471 | 305 | } |
3472 | 305 | return( -1 ); |
3473 | 0 | } |
3474 | | |
3475 | | /* Retrieves the file entry tree root node |
3476 | | * Returns 1 if successful or -1 on error |
3477 | | */ |
3478 | | int libewf_single_files_get_file_entry_tree_root_node( |
3479 | | libewf_single_files_t *single_files, |
3480 | | libcdata_tree_node_t **root_node, |
3481 | | libcerror_error_t **error ) |
3482 | 0 | { |
3483 | 0 | static char *function = "libewf_single_files_get_file_entry_tree_root_node"; |
3484 | |
|
3485 | 0 | if( single_files == NULL ) |
3486 | 0 | { |
3487 | 0 | libcerror_error_set( |
3488 | 0 | error, |
3489 | 0 | LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
3490 | 0 | LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, |
3491 | 0 | "%s: invalid single files.", |
3492 | 0 | function ); |
3493 | |
|
3494 | 0 | return( -1 ); |
3495 | 0 | } |
3496 | 0 | if( root_node == NULL ) |
3497 | 0 | { |
3498 | 0 | libcerror_error_set( |
3499 | 0 | error, |
3500 | 0 | LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
3501 | 0 | LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, |
3502 | 0 | "%s: invalid root node.", |
3503 | 0 | function ); |
3504 | |
|
3505 | 0 | return( -1 ); |
3506 | 0 | } |
3507 | 0 | *root_node = single_files->file_entry_tree_root_node; |
3508 | |
|
3509 | 0 | return( 1 ); |
3510 | 0 | } |
3511 | | |
3512 | | /* Retrieves the number of permission groups |
3513 | | * Returns 1 if successful or -1 on error |
3514 | | */ |
3515 | | int libewf_single_files_get_number_of_permission_groups( |
3516 | | libewf_single_files_t *single_files, |
3517 | | int *number_of_permission_groups, |
3518 | | libcerror_error_t **error ) |
3519 | 0 | { |
3520 | 0 | static char *function = "libewf_single_files_get_number_of_permission_groups"; |
3521 | |
|
3522 | 0 | if( single_files == NULL ) |
3523 | 0 | { |
3524 | 0 | libcerror_error_set( |
3525 | 0 | error, |
3526 | 0 | LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
3527 | 0 | LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, |
3528 | 0 | "%s: invalid single files.", |
3529 | 0 | function ); |
3530 | |
|
3531 | 0 | return( -1 ); |
3532 | 0 | } |
3533 | 0 | if( libcdata_array_get_number_of_entries( |
3534 | 0 | single_files->permission_groups, |
3535 | 0 | number_of_permission_groups, |
3536 | 0 | error ) != 1 ) |
3537 | 0 | { |
3538 | 0 | libcerror_error_set( |
3539 | 0 | error, |
3540 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
3541 | 0 | LIBCERROR_RUNTIME_ERROR_GET_FAILED, |
3542 | 0 | "%s: unable to retrieve number of entries of permission groups array.", |
3543 | 0 | function ); |
3544 | |
|
3545 | 0 | return( -1 ); |
3546 | 0 | } |
3547 | 0 | return( 1 ); |
3548 | 0 | } |
3549 | | |
3550 | | /* Retrieves a specific permission group |
3551 | | * Returns 1 if successful or -1 on error |
3552 | | */ |
3553 | | int libewf_single_files_get_permission_group_by_index( |
3554 | | libewf_single_files_t *single_files, |
3555 | | int permission_group_index, |
3556 | | libewf_permission_group_t **permission_group, |
3557 | | libcerror_error_t **error ) |
3558 | 0 | { |
3559 | 0 | static char *function = "libewf_single_files_get_permission_group_by_index"; |
3560 | |
|
3561 | 0 | if( single_files == NULL ) |
3562 | 0 | { |
3563 | 0 | libcerror_error_set( |
3564 | 0 | error, |
3565 | 0 | LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
3566 | 0 | LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, |
3567 | 0 | "%s: invalid single files.", |
3568 | 0 | function ); |
3569 | |
|
3570 | 0 | return( -1 ); |
3571 | 0 | } |
3572 | 0 | if( libcdata_array_get_entry_by_index( |
3573 | 0 | single_files->permission_groups, |
3574 | 0 | permission_group_index, |
3575 | 0 | (intptr_t **) permission_group, |
3576 | 0 | error ) != 1 ) |
3577 | 0 | { |
3578 | 0 | libcerror_error_set( |
3579 | 0 | error, |
3580 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
3581 | 0 | LIBCERROR_RUNTIME_ERROR_GET_FAILED, |
3582 | 0 | "%s: unable to retrieve entry: %d from permission groups array.", |
3583 | 0 | function, |
3584 | 0 | permission_group_index ); |
3585 | |
|
3586 | 0 | return( -1 ); |
3587 | 0 | } |
3588 | 0 | return( 1 ); |
3589 | 0 | } |
3590 | | |
3591 | | /* Retrieves a specific source |
3592 | | * Returns 1 if successful or -1 on error |
3593 | | */ |
3594 | | int libewf_single_files_get_source_by_index( |
3595 | | libewf_single_files_t *single_files, |
3596 | | int source_index, |
3597 | | libewf_lef_source_t **lef_source, |
3598 | | libcerror_error_t **error ) |
3599 | 0 | { |
3600 | 0 | static char *function = "libewf_single_files_get_source_by_index"; |
3601 | |
|
3602 | 0 | if( single_files == NULL ) |
3603 | 0 | { |
3604 | 0 | libcerror_error_set( |
3605 | 0 | error, |
3606 | 0 | LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
3607 | 0 | LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, |
3608 | 0 | "%s: invalid single files.", |
3609 | 0 | function ); |
3610 | |
|
3611 | 0 | return( -1 ); |
3612 | 0 | } |
3613 | 0 | if( libcdata_array_get_entry_by_index( |
3614 | 0 | single_files->sources, |
3615 | 0 | source_index, |
3616 | 0 | (intptr_t **) lef_source, |
3617 | 0 | error ) != 1 ) |
3618 | 0 | { |
3619 | 0 | libcerror_error_set( |
3620 | 0 | error, |
3621 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
3622 | 0 | LIBCERROR_RUNTIME_ERROR_GET_FAILED, |
3623 | 0 | "%s: unable to retrieve entry: %d from sources array.", |
3624 | 0 | function, |
3625 | 0 | source_index ); |
3626 | |
|
3627 | 0 | return( -1 ); |
3628 | 0 | } |
3629 | 0 | return( 1 ); |
3630 | 0 | } |
3631 | | |