/* Closes a file IO handle for test data * Returns 0 if successful or -1 on error */ int agdb_test_close_file_io_handle( libbfio_handle_t **file_io_handle, libcerror_error_t **error ) { static char *function = "agdb_test_close_file_io_handle"; int result = 0; if( file_io_handle == NULL ) { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_ARGUMENTS, LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, "%s: invalid file IO handle.", function ); return( -1 ); } if( libbfio_handle_close( *file_io_handle, error ) != 0 ) { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_IO, LIBCERROR_IO_ERROR_CLOSE_FAILED, "%s: unable to close file IO handle.", function ); result = -1; } if( libbfio_handle_free( file_io_handle, error ) != 1 ) { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_RUNTIME, LIBCERROR_RUNTIME_ERROR_FINALIZE_FAILED, "%s: unable to free file IO handle.", function ); result = -1; } return( result ); }
/* Closes a file * Returns 0 if successful or -1 on error */ int libevtx_file_close( libevtx_file_t *file, libcerror_error_t **error ) { libevtx_internal_file_t *internal_file = NULL; static char *function = "libevtx_file_close"; int result = 0; if( file == NULL ) { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_ARGUMENTS, LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, "%s: invalid file.", function ); return( -1 ); } internal_file = (libevtx_internal_file_t *) file; if( internal_file->file_io_handle == NULL ) { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_RUNTIME, LIBCERROR_RUNTIME_ERROR_VALUE_MISSING, "%s: invalid file - missing file IO handle.", function ); return( -1 ); } #if defined( HAVE_DEBUG_OUTPUT ) if( libcnotify_verbose != 0 ) { if( internal_file->file_io_handle_created_in_library != 0 ) { if( libevtx_debug_print_read_offsets( internal_file->file_io_handle, error ) != 1 ) { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_RUNTIME, LIBCERROR_RUNTIME_ERROR_PRINT_FAILED, "%s: unable to print the read offsets.", function ); result = -1; } } } #endif if( internal_file->file_io_handle_opened_in_library != 0 ) { if( libbfio_handle_close( internal_file->file_io_handle, error ) != 0 ) { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_IO, LIBCERROR_IO_ERROR_CLOSE_FAILED, "%s: unable to close file IO handle.", function ); result = -1; } internal_file->file_io_handle_opened_in_library = 0; } if( internal_file->file_io_handle_created_in_library != 0 ) { if( libbfio_handle_free( &( internal_file->file_io_handle ), error ) != 1 ) { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_RUNTIME, LIBCERROR_RUNTIME_ERROR_FINALIZE_FAILED, "%s: unable to free file IO handle.", function ); result = -1; } internal_file->file_io_handle_created_in_library = 0; } internal_file->file_io_handle = NULL; if( libevtx_io_handle_clear( internal_file->io_handle, error ) != 1 ) { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_RUNTIME, LIBCERROR_RUNTIME_ERROR_FINALIZE_FAILED, "%s: unable to clear IO handle.", function ); result = -1; } if( libfdata_list_free( &( internal_file->recovered_records_list ), error ) != 1 ) { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_RUNTIME, LIBCERROR_RUNTIME_ERROR_FINALIZE_FAILED, "%s: unable to free recovered records list.", function ); result = -1; } if( libfdata_list_free( &( internal_file->records_list ), error ) != 1 ) { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_RUNTIME, LIBCERROR_RUNTIME_ERROR_FINALIZE_FAILED, "%s: unable to free records list.", function ); result = -1; } if( libfcache_cache_free( &( internal_file->records_cache ), error ) != 1 ) { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_RUNTIME, LIBCERROR_RUNTIME_ERROR_FINALIZE_FAILED, "%s: unable to free records cache.", function ); result = -1; } if( libfdata_vector_free( &( internal_file->chunks_vector ), error ) != 1 ) { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_RUNTIME, LIBCERROR_RUNTIME_ERROR_FINALIZE_FAILED, "%s: unable to free chunks vector.", function ); result = -1; } if( libfcache_cache_free( &( internal_file->chunks_cache ), error ) != 1 ) { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_RUNTIME, LIBCERROR_RUNTIME_ERROR_FINALIZE_FAILED, "%s: unable to free chunks cache.", function ); result = -1; } return( result ); }
/* Determines if a file contains a BDE volume signature using a Basic File IO (bfio) handle * Returns 1 if true, 0 if not or -1 on error */ int libbde_check_volume_signature_file_io_handle( libbfio_handle_t *file_io_handle, libcerror_error_t **error ) { uint8_t signature[ 12 ]; static char *function = "libbde_check_volume_signature_file_io_handle"; ssize_t read_count = 0; int file_io_handle_is_open = 0; if( file_io_handle == NULL ) { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_ARGUMENTS, LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, "%s: invalid file IO handle.", function ); return( -1 ); } file_io_handle_is_open = libbfio_handle_is_open( file_io_handle, error ); if( file_io_handle_is_open == -1 ) { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_IO, LIBCERROR_IO_ERROR_OPEN_FAILED, "%s: unable to open file.", function ); return( -1 ); } else if( file_io_handle_is_open == 0 ) { if( libbfio_handle_open( file_io_handle, LIBBFIO_OPEN_READ, error ) != 1 ) { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_IO, LIBCERROR_IO_ERROR_OPEN_FAILED, "%s: unable to open file.", function ); return( -1 ); } } if( libbfio_handle_seek_offset( file_io_handle, 0, SEEK_SET, error ) == -1 ) { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_IO, LIBCERROR_IO_ERROR_SEEK_FAILED, "%s: unable to seek file header offset: 0.", function ); if( file_io_handle_is_open == 0 ) { libbfio_handle_close( file_io_handle, error ); } return( -1 ); } read_count = libbfio_handle_read_buffer( file_io_handle, signature, 12, error ); if( read_count != 12 ) { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_IO, LIBCERROR_IO_ERROR_READ_FAILED, "%s: unable to read signature.", function ); if( file_io_handle_is_open == 0 ) { libbfio_handle_close( file_io_handle, error ); } return( -1 ); } if( file_io_handle_is_open == 0 ) { if( libbfio_handle_close( file_io_handle, error ) != 0 ) { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_IO, LIBCERROR_IO_ERROR_CLOSE_FAILED, "%s: unable to close file.", function ); return( -1 ); } } if( memory_compare( bde_signature, &( signature[ 3 ] ), 8 ) == 0 ) { return( 1 ); } return( 0 ); }
/* Closes a handle * Returns 0 if successful or -1 on error */ int libvsmbr_handle_close( libvsmbr_handle_t *handle, libcerror_error_t **error ) { libvsmbr_internal_handle_t *internal_handle = NULL; static char *function = "libvsmbr_handle_close"; int result = 0; if( handle == NULL ) { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_ARGUMENTS, LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, "%s: invalid handle.", function ); return( -1 ); } internal_handle = (libvsmbr_internal_handle_t *) handle; if( internal_handle->file_io_handle == NULL ) { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_RUNTIME, LIBCERROR_RUNTIME_ERROR_VALUE_MISSING, "%s: invalid handle - missing file IO handle.", function ); return( -1 ); } if( internal_handle->file_io_handle_created_in_library != 0 ) { #if defined( HAVE_DEBUG_OUTPUT ) if( libcnotify_verbose != 0 ) { if( libvsmbr_debug_print_read_offsets( internal_handle->file_io_handle, error ) != 1 ) { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_RUNTIME, LIBCERROR_RUNTIME_ERROR_PRINT_FAILED, "%s: unable to print the read offsets.", function ); result = -1; } } #endif if( libbfio_handle_close( internal_handle->file_io_handle, error ) != 0 ) { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_IO, LIBCERROR_IO_ERROR_CLOSE_FAILED, "%s: unable to close file IO handle.", function ); result = -1; } if( libbfio_handle_free( &( internal_handle->file_io_handle ), error ) != 1 ) { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_RUNTIME, LIBCERROR_RUNTIME_ERROR_FINALIZE_FAILED, "%s: unable to free file IO handle.", function ); result = -1; } } internal_handle->file_io_handle = NULL; internal_handle->file_io_handle_created_in_library = 0; if( libcdata_array_empty( internal_handle->partitions_array, (int (*)(intptr_t **, libcerror_error_t **)) &libvsmbr_partition_values_free, error ) != 1 ) { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_RUNTIME, LIBCERROR_RUNTIME_ERROR_RESIZE_FAILED, "%s: unable to empty the partitions array.", function ); result = -1; } if( libcdata_array_empty( internal_handle->sections_array, (int (*)(intptr_t **, libcerror_error_t **)) &libvsmbr_section_values_free, error ) != 1 ) { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_RUNTIME, LIBCERROR_RUNTIME_ERROR_RESIZE_FAILED, "%s: unable to empty the sections array.", function ); result = -1; } return( result ); }
/* Opens the wipekey handle * Returns 1 if successful, 0 if the keys could not be read or -1 on error */ int wipekey_handle_open_input( wipekey_handle_t *wipekey_handle, const libcstring_system_character_t *filename, libcerror_error_t **error ) { static char *function = "wipekey_handle_open_input"; size_t filename_length = 0; int result = 0; if( wipekey_handle == NULL ) { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_ARGUMENTS, LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, "%s: invalid wipekey handle.", function ); return( -1 ); } filename_length = libcstring_system_string_length( filename ); #if defined( LIBCSTRING_HAVE_WIDE_SYSTEM_CHARACTER ) if( libbfio_file_set_name_wide( wipekey_handle->input_file_io_handle, filename, filename_length, error ) != 1 ) #else if( libbfio_file_set_name( wipekey_handle->input_file_io_handle, filename, filename_length, error ) != 1 ) #endif { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_IO, LIBCERROR_IO_ERROR_OPEN_FAILED, "%s: unable to open set file name.", function ); goto on_error; } if( libbfio_handle_open( wipekey_handle->input_file_io_handle, LIBBFIO_OPEN_READ, error ) != 1 ) { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_IO, LIBCERROR_IO_ERROR_OPEN_FAILED, "%s: unable to open input file.", function ); goto on_error; } if( libfvde_encryption_context_plist_initialize( &( wipekey_handle->encrypted_root_plist ), error ) != 1 ) { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_RUNTIME, LIBCERROR_RUNTIME_ERROR_INITIALIZE_FAILED, "%s: unable to create encrypted root plist.", function ); goto on_error; } if( libfvde_encryption_context_plist_read_file_io_handle( wipekey_handle->encrypted_root_plist, wipekey_handle->input_file_io_handle, error ) != 1 ) { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_IO, LIBCERROR_IO_ERROR_GENERIC, "%s: unable to read encrypted root plist.", function ); goto on_error; } if( libbfio_handle_close( wipekey_handle->input_file_io_handle, error ) != 0 ) { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_IO, LIBCERROR_IO_ERROR_CLOSE_FAILED, "%s: unable to close input file IO handle.", function ); goto on_error; } result = libfvde_encryption_context_plist_decrypt( wipekey_handle->encrypted_root_plist, wipekey_handle->volume_key_data, 128, error ); if( result == -1 ) { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_ENCRYPTION, LIBCERROR_ENCRYPTION_ERROR_DECRYPT_FAILED, "%s: unable to decrypt encrypted root plist.", function ); goto on_error; } if( memory_set( wipekey_handle->volume_key_data, 0, 16 ) == NULL ) { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_MEMORY, LIBCERROR_MEMORY_ERROR_SET_FAILED, "%s: unable to clear volume key data.", function ); goto on_error; } return( result ); on_error: if( wipekey_handle->encrypted_root_plist != NULL ) { libfvde_encryption_context_plist_free( &( wipekey_handle->encrypted_root_plist ), NULL ); } return( -1 ); }
/* Determines if a file is a Windows Event Log file (check for the EVT file signature) using a Basic File IO (bfio) handle * Returns 1 if true, 0 if not or -1 on error */ int libevt_check_file_signature_file_io_handle( libbfio_handle_t *file_io_handle, libcerror_error_t **error ) { uint8_t signature[ 8 ]; static char *function = "libevt_check_file_signature_file_io_handle"; ssize_t read_count = 0; int file_io_handle_is_open = 0; if( file_io_handle == NULL ) { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_ARGUMENTS, LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, "%s: invalid file IO handle.", function ); return( -1 ); } file_io_handle_is_open = libbfio_handle_is_open( file_io_handle, error ); if( file_io_handle_is_open == -1 ) { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_IO, LIBCERROR_IO_ERROR_OPEN_FAILED, "%s: unable to open file.", function ); return( -1 ); } else if( file_io_handle_is_open == 0 ) { if( libbfio_handle_open( file_io_handle, LIBBFIO_OPEN_READ, error ) != 1 ) { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_IO, LIBCERROR_IO_ERROR_OPEN_FAILED, "%s: unable to open file.", function ); return( -1 ); } } read_count = libbfio_handle_read_buffer( file_io_handle, signature, 8, error ); if( read_count != 8 ) { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_IO, LIBCERROR_IO_ERROR_READ_FAILED, "%s: unable to read signature.", function ); libbfio_handle_close( file_io_handle, NULL ); return( -1 ); } if( file_io_handle_is_open == 0 ) { if( libbfio_handle_close( file_io_handle, error ) != 0 ) { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_IO, LIBCERROR_IO_ERROR_CLOSE_FAILED, "%s: unable to close file.", function ); return( -1 ); } } if( memory_compare( evt_file_signature, &( signature[ 4 ] ), 4 ) == 0 ) { return( 1 ); } return( 0 ); }
/* Tests the libesedb_check_file_signature_file_io_handle function * Returns 1 if successful or 0 if not */ int esedb_test_check_file_signature_file_io_handle( const system_character_t *source ) { uint8_t empty_block[ 8192 ]; libbfio_handle_t *file_io_handle = NULL; libcerror_error_t *error = NULL; void *memset_result = NULL; size_t source_length = 0; int result = 0; /* Initialize test */ memset_result = memory_set( empty_block, 0, sizeof( uint8_t ) * 8192 ); ESEDB_TEST_ASSERT_IS_NOT_NULL( "memset_result", memset_result ); if( source != NULL ) { /* Initialize test */ result = libbfio_file_initialize( &file_io_handle, &error ); ESEDB_TEST_ASSERT_EQUAL_INT( "result", result, 1 ); ESEDB_TEST_ASSERT_IS_NOT_NULL( "file_io_handle", file_io_handle ); ESEDB_TEST_ASSERT_IS_NULL( "error", error ); source_length = system_string_length( source ); #if defined( HAVE_WIDE_SYSTEM_CHARACTER ) result = libbfio_file_set_name_wide( file_io_handle, source, source_length, &error ); #else result = libbfio_file_set_name( file_io_handle, source, source_length, &error ); #endif ESEDB_TEST_ASSERT_EQUAL_INT( "result", result, 1 ); ESEDB_TEST_ASSERT_IS_NULL( "error", error ); result = libbfio_handle_open( file_io_handle, LIBBFIO_OPEN_READ, &error ); ESEDB_TEST_ASSERT_EQUAL_INT( "result", result, 1 ); ESEDB_TEST_ASSERT_IS_NULL( "error", error ); /* Test check file signature */ result = libesedb_check_file_signature_file_io_handle( file_io_handle, &error ); ESEDB_TEST_ASSERT_EQUAL_INT( "result", result, 1 ); ESEDB_TEST_ASSERT_IS_NULL( "error", error ); } /* Test error cases */ result = libesedb_check_file_signature_file_io_handle( NULL, &error ); ESEDB_TEST_ASSERT_EQUAL_INT( "result", result, -1 ); ESEDB_TEST_ASSERT_IS_NOT_NULL( "error", error ); libcerror_error_free( &error ); /* Clean up */ if( source != NULL ) { result = libbfio_handle_close( file_io_handle, &error ); ESEDB_TEST_ASSERT_EQUAL_INT( "result", result, 0 ); ESEDB_TEST_ASSERT_IS_NULL( "error", error ); result = libbfio_handle_free( &file_io_handle, &error ); ESEDB_TEST_ASSERT_EQUAL_INT( "result", result, 1 ); ESEDB_TEST_ASSERT_IS_NULL( "file_io_handle", file_io_handle ); ESEDB_TEST_ASSERT_IS_NULL( "error", error ); } /* Test check file signature with data too small */ result = esedb_test_open_file_io_handle( &file_io_handle, empty_block, sizeof( uint8_t ) * 1, &error ); ESEDB_TEST_ASSERT_EQUAL_INT( "result", result, 1 ); ESEDB_TEST_ASSERT_IS_NOT_NULL( "file_io_handle", file_io_handle ); ESEDB_TEST_ASSERT_IS_NULL( "error", error ); result = libesedb_check_file_signature_file_io_handle( file_io_handle, &error ); ESEDB_TEST_ASSERT_EQUAL_INT( "result", result, -1 ); ESEDB_TEST_ASSERT_IS_NOT_NULL( "error", error ); libcerror_error_free( &error ); result = esedb_test_close_file_io_handle( &file_io_handle, &error ); ESEDB_TEST_ASSERT_EQUAL_INT( "result", result, 0 ); ESEDB_TEST_ASSERT_IS_NULL( "error", error ); /* Test check file signature with empty block */ result = esedb_test_open_file_io_handle( &file_io_handle, empty_block, sizeof( uint8_t ) * 8192, &error ); ESEDB_TEST_ASSERT_EQUAL_INT( "result", result, 1 ); ESEDB_TEST_ASSERT_IS_NOT_NULL( "file_io_handle", file_io_handle ); ESEDB_TEST_ASSERT_IS_NULL( "error", error ); result = libesedb_check_file_signature_file_io_handle( file_io_handle, &error ); ESEDB_TEST_ASSERT_EQUAL_INT( "result", result, 0 ); ESEDB_TEST_ASSERT_IS_NULL( "error", error ); result = esedb_test_close_file_io_handle( &file_io_handle, &error ); ESEDB_TEST_ASSERT_EQUAL_INT( "result", result, 0 ); ESEDB_TEST_ASSERT_IS_NULL( "error", error ); return( 1 ); on_error: if( error != NULL ) { libcerror_error_free( &error ); } if( file_io_handle != NULL ) { libbfio_handle_free( &file_io_handle, NULL ); } return( 0 ); }
/* Frees a resource * Returns 1 if successful or -1 on error */ int libwrc_resource_free( libwrc_resource_t **resource, libcerror_error_t **error ) { libwrc_internal_resource_t *internal_resource = NULL; static char *function = "libwrc_resource_free"; int result = 1; if( resource == NULL ) { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_ARGUMENTS, LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, "%s: invalid resource.", function ); return( -1 ); } if( *resource != NULL ) { internal_resource = (libwrc_internal_resource_t *) *resource; *resource = NULL; /* The io_handle, resource_node and resource_values references are freed elsewhere */ if( ( internal_resource->flags & LIBWRC_RESOURCE_FLAG_MANAGED_FILE_IO_HANDLE ) != 0 ) { if( internal_resource->file_io_handle != NULL ) { if( libbfio_handle_close( internal_resource->file_io_handle, error ) != 0 ) { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_IO, LIBCERROR_IO_ERROR_CLOSE_FAILED, "%s: unable to close file IO handle.", function ); result = -1; } if( libbfio_handle_free( &( internal_resource->file_io_handle ), error ) != 1 ) { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_RUNTIME, LIBCERROR_RUNTIME_ERROR_FINALIZE_FAILED, "%s: unable to free file IO handle.", function ); result = -1; } } } if( internal_resource->value != NULL ) { if( internal_resource->free_value != NULL ) { if( internal_resource->free_value( &( internal_resource->value ), error ) != 1 ) { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_RUNTIME, LIBCERROR_RUNTIME_ERROR_FINALIZE_FAILED, "%s: unable to free resource value.", function ); result = -1; } } } memory_free( internal_resource ); } return( result ); }
/* Closes a handle in the pool * Returns 0 if successful or -1 on error */ int libbfio_pool_close( libbfio_pool_t *pool, int entry, liberror_error_t **error ) { libbfio_internal_pool_t *internal_pool = NULL; libbfio_list_element_t *last_used_list_element = NULL; static char *function = "libbfio_pool_close"; if( pool == NULL ) { liberror_error_set( error, LIBERROR_ERROR_DOMAIN_ARGUMENTS, LIBERROR_ARGUMENT_ERROR_INVALID_VALUE, "%s: invalid pool.", function ); return( -1 ); } internal_pool = (libbfio_internal_pool_t *) pool; if( internal_pool->handles == NULL ) { liberror_error_set( error, LIBERROR_ERROR_DOMAIN_RUNTIME, LIBERROR_RUNTIME_ERROR_VALUE_MISSING, "%s: invalid pool - missing handles.", function ); return( -1 ); } if( ( entry < 0 ) || ( entry >= internal_pool->amount_of_handles ) ) { liberror_error_set( error, LIBERROR_ERROR_DOMAIN_ARGUMENTS, LIBERROR_ARGUMENT_ERROR_VALUE_OUT_OF_RANGE, "%s: invalid entry.", function ); return( -1 ); } if( internal_pool->handles[ entry ] == NULL ) { liberror_error_set( error, LIBERROR_ERROR_DOMAIN_RUNTIME, LIBERROR_RUNTIME_ERROR_VALUE_MISSING, "%s: invalid pool - missing handle for entry: %d.", function, entry ); return( -1 ); } if( internal_pool->maximum_amount_of_open_handles != LIBBFIO_POOL_UNLIMITED_AMOUNT_OF_OPEN_HANDLES ) { last_used_list_element = ( (libbfio_internal_handle_t *) internal_pool->handles[ entry ] )->pool_last_used_list_element; if( libbfio_pool_remove_handle_from_last_used_list( internal_pool, last_used_list_element, error ) != 1 ) { liberror_error_set( error, LIBERROR_ERROR_DOMAIN_IO, LIBERROR_IO_ERROR_CLOSE_FAILED, "%s: unable to remove a handle from the last used list.", function ); return( -1 ); } memory_free( last_used_list_element ); } if( libbfio_handle_close( internal_pool->handles[ entry ], error ) != 0 ) { liberror_error_set( error, LIBERROR_ERROR_DOMAIN_IO, LIBERROR_IO_ERROR_CLOSE_FAILED, "%s: unable to close handle for entry: %d.", function, entry ); return( -1 ); } return( 0 ); }
/* Adds the handle to the last used list * Closes the less frequently used handle if necessary * Returns 1 if successful or -1 on error */ int libbfio_pool_add_handle_to_last_used_list( libbfio_internal_pool_t *internal_pool, libbfio_handle_t *handle, liberror_error_t **error ) { libbfio_list_element_t *last_used_list_element = NULL; static char *function = "libbfio_pool_add_handle_to_last_used_list"; if( internal_pool == NULL ) { liberror_error_set( error, LIBERROR_ERROR_DOMAIN_ARGUMENTS, LIBERROR_ARGUMENT_ERROR_INVALID_VALUE, "%s: invalid pool.", function ); return( -1 ); } if( internal_pool->last_used_list == NULL ) { liberror_error_set( error, LIBERROR_ERROR_DOMAIN_RUNTIME, LIBERROR_RUNTIME_ERROR_VALUE_MISSING, "%s: invalid pool - missing last used list.", function ); return( -1 ); } if( handle == NULL ) { liberror_error_set( error, LIBERROR_ERROR_DOMAIN_ARGUMENTS, LIBERROR_ARGUMENT_ERROR_INVALID_VALUE, "%s: invalid handle.", function ); return( -1 ); } /* Check if there is room in the pool for another open handle */ if( ( internal_pool->maximum_amount_of_open_handles != LIBBFIO_POOL_UNLIMITED_AMOUNT_OF_OPEN_HANDLES ) && ( ( internal_pool->amount_of_open_handles + 1 ) >= internal_pool->maximum_amount_of_open_handles ) ) { last_used_list_element = internal_pool->last_used_list->last; if( libbfio_pool_remove_handle_from_last_used_list( internal_pool, last_used_list_element, error ) != 1 ) { liberror_error_set( error, LIBERROR_ERROR_DOMAIN_IO, LIBERROR_IO_ERROR_CLOSE_FAILED, "%s: unable to remove a handle from the last used list.", function ); return( -1 ); } if( libbfio_handle_close( (libbfio_handle_t *) ( last_used_list_element->value ), error ) != 0 ) { liberror_error_set( error, LIBERROR_ERROR_DOMAIN_IO, LIBERROR_IO_ERROR_CLOSE_FAILED, "%s: unable to close handle.", function ); memory_free( last_used_list_element ); return( -1 ); } /* Make sure the truncate flag is removed from the handle */ ( (libbfio_internal_handle_t *) ( last_used_list_element->value ) )->flags &= ~LIBBFIO_FLAG_TRUNCATE; /* The last used list element is reused to contain the new last used entry */ } else { last_used_list_element = (libbfio_list_element_t *) memory_allocate( sizeof( libbfio_list_element_t ) ); if( last_used_list_element == NULL ) { liberror_error_set( error, LIBERROR_ERROR_DOMAIN_MEMORY, LIBERROR_MEMORY_ERROR_INSUFFICIENT, "%s: unable to create last used list element.", function ); return( -1 ); } if( memory_set( last_used_list_element, 0, sizeof( libbfio_list_element_t ) ) == NULL ) { liberror_error_set( error, LIBERROR_ERROR_DOMAIN_MEMORY, LIBERROR_MEMORY_ERROR_SET_FAILED, "%s: unable to clear last used list element.", function ); memory_free( last_used_list_element ); return( -1 ); } } last_used_list_element->value = (intptr_t *) handle; ( (libbfio_internal_handle_t *) handle )->pool_last_used_list_element = last_used_list_element; if( libbfio_list_prepend_element( internal_pool->last_used_list, last_used_list_element, error ) != 1 ) { liberror_error_set( error, LIBERROR_ERROR_DOMAIN_RUNTIME, LIBERROR_RUNTIME_ERROR_APPEND_FAILED, "%s: unable to prepend last used list element to list.", function ); memory_free( last_used_list_element ); return( -1 ); } return( 1 ); }
/* Closes a volume * Returns 0 if successful or -1 on error */ int libvshadow_volume_close( libvshadow_volume_t *volume, libcerror_error_t **error ) { libvshadow_internal_volume_t *internal_volume = NULL; static char *function = "libvshadow_volume_close"; int result = 0; if( volume == NULL ) { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_ARGUMENTS, LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, "%s: invalid volume.", function ); return( -1 ); } internal_volume = (libvshadow_internal_volume_t *) volume; if( internal_volume->io_handle == NULL ) { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_RUNTIME, LIBCERROR_RUNTIME_ERROR_VALUE_MISSING, "%s: invalid volume - missing IO handle.", function ); return( -1 ); } #if defined( HAVE_LIBVSHADOW_MULTI_THREAD_SUPPORT ) if( libcthreads_read_write_lock_grab_for_write( internal_volume->read_write_lock, error ) != 1 ) { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_RUNTIME, LIBCERROR_RUNTIME_ERROR_SET_FAILED, "%s: unable to grab read/write lock for writing.", function ); return( -1 ); } #endif #if defined( HAVE_DEBUG_OUTPUT ) if( libcnotify_verbose != 0 ) { if( internal_volume->file_io_handle_created_in_library != 0 ) { if( libvshadow_debug_print_read_offsets( internal_volume->file_io_handle, error ) != 1 ) { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_RUNTIME, LIBCERROR_RUNTIME_ERROR_PRINT_FAILED, "%s: unable to print the read offsets.", function ); } } } #endif if( internal_volume->file_io_handle_opened_in_library != 0 ) { if( libbfio_handle_close( internal_volume->file_io_handle, error ) != 0 ) { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_IO, LIBCERROR_IO_ERROR_CLOSE_FAILED, "%s: unable to close file IO handle.", function ); result = -1; } internal_volume->file_io_handle_opened_in_library = 0; } if( internal_volume->file_io_handle_created_in_library != 0 ) { if( libbfio_handle_free( &( internal_volume->file_io_handle ), error ) != 1 ) { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_RUNTIME, LIBCERROR_RUNTIME_ERROR_FINALIZE_FAILED, "%s: unable to free file IO handle.", function ); result = -1; } internal_volume->file_io_handle_created_in_library = 0; } internal_volume->file_io_handle = NULL; internal_volume->size = 0; if( libvshadow_io_handle_clear( internal_volume->io_handle, error ) != 1 ) { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_RUNTIME, LIBCERROR_RUNTIME_ERROR_FINALIZE_FAILED, "%s: unable to clear IO handle.", function ); result = -1; } if( libcdata_array_empty( internal_volume->store_descriptors_array, (int (*)(intptr_t **, libcerror_error_t **)) &libvshadow_store_descriptor_free, error ) != 1 ) { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_RUNTIME, LIBCERROR_RUNTIME_ERROR_FINALIZE_FAILED, "%s: unable to empty store descriptors array.", function ); result = -1; } #if defined( HAVE_LIBVSHADOW_MULTI_THREAD_SUPPORT ) if( libcthreads_read_write_lock_release_for_write( internal_volume->read_write_lock, error ) != 1 ) { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_RUNTIME, LIBCERROR_RUNTIME_ERROR_SET_FAILED, "%s: unable to release read/write lock for writing.", function ); return( -1 ); } #endif return( result ); }
/* Opens a volume using a Basic File IO (bfio) handle * Returns 1 if successful or -1 on error */ int libvshadow_volume_open_file_io_handle( libvshadow_volume_t *volume, libbfio_handle_t *file_io_handle, int access_flags, libcerror_error_t **error ) { libvshadow_internal_volume_t *internal_volume = NULL; static char *function = "libvshadow_volume_open_file_io_handle"; int bfio_access_flags = 0; int file_io_handle_is_open = 0; int file_io_handle_opened_in_library = 0; if( volume == NULL ) { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_ARGUMENTS, LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, "%s: invalid volume.", function ); return( -1 ); } internal_volume = (libvshadow_internal_volume_t *) volume; if( file_io_handle == NULL ) { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_ARGUMENTS, LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, "%s: invalid file IO handle.", function ); return( -1 ); } if( ( ( access_flags & LIBVSHADOW_ACCESS_FLAG_READ ) == 0 ) && ( ( access_flags & LIBVSHADOW_ACCESS_FLAG_WRITE ) == 0 ) ) { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_ARGUMENTS, LIBCERROR_ARGUMENT_ERROR_UNSUPPORTED_VALUE, "%s: unsupported access flags.", function ); return( -1 ); } if( ( access_flags & LIBVSHADOW_ACCESS_FLAG_WRITE ) != 0 ) { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_ARGUMENTS, LIBCERROR_ARGUMENT_ERROR_UNSUPPORTED_VALUE, "%s: write access currently not supported.", function ); return( -1 ); } if( ( access_flags & LIBVSHADOW_ACCESS_FLAG_READ ) != 0 ) { bfio_access_flags = LIBBFIO_ACCESS_FLAG_READ; } file_io_handle_is_open = libbfio_handle_is_open( file_io_handle, error ); if( file_io_handle_is_open == -1 ) { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_IO, LIBCERROR_IO_ERROR_OPEN_FAILED, "%s: unable to determine if file IO handle is open.", function ); goto on_error; } else if( file_io_handle_is_open == 0 ) { if( libbfio_handle_open( file_io_handle, bfio_access_flags, error ) != 1 ) { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_IO, LIBCERROR_IO_ERROR_OPEN_FAILED, "%s: unable to open file IO handle.", function ); goto on_error; } file_io_handle_opened_in_library = 1; } if( libvshadow_volume_open_read( internal_volume, file_io_handle, error ) != 1 ) { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_IO, LIBCERROR_IO_ERROR_READ_FAILED, "%s: unable to read from file IO handle.", function ); goto on_error; } #if defined( HAVE_LIBVSHADOW_MULTI_THREAD_SUPPORT ) if( libcthreads_read_write_lock_grab_for_write( internal_volume->read_write_lock, error ) != 1 ) { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_RUNTIME, LIBCERROR_RUNTIME_ERROR_SET_FAILED, "%s: unable to grab read/write lock for writing.", function ); return( -1 ); } #endif internal_volume->file_io_handle = file_io_handle; internal_volume->file_io_handle_opened_in_library = file_io_handle_opened_in_library; #if defined( HAVE_LIBVSHADOW_MULTI_THREAD_SUPPORT ) if( libcthreads_read_write_lock_release_for_write( internal_volume->read_write_lock, error ) != 1 ) { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_RUNTIME, LIBCERROR_RUNTIME_ERROR_SET_FAILED, "%s: unable to release read/write lock for writing.", function ); return( -1 ); } #endif return( 1 ); on_error: if( file_io_handle_opened_in_library != 0 ) { libbfio_handle_close( file_io_handle, NULL ); } return( -1 ); }
/* Determines if a file contains an EWF file signature using a Basic File IO (bfio) handle * Returns 1 if true, 0 if not or -1 on error */ int libewf_check_file_signature_file_io_handle( libbfio_handle_t *file_io_handle, libcerror_error_t **error ) { uint8_t signature[ 8 ]; static char *function = "libewf_check_file_signature_file_io_handle"; ssize_t read_count = 0; int file_io_handle_is_open = 0; if( file_io_handle == NULL ) { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_ARGUMENTS, LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, "%s: invalid file IO handle.", function ); return( -1 ); } file_io_handle_is_open = libbfio_handle_is_open( file_io_handle, error ); if( file_io_handle_is_open == -1 ) { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_IO, LIBCERROR_IO_ERROR_OPEN_FAILED, "%s: unable to open file.", function ); return( -1 ); } else if( file_io_handle_is_open == 0 ) { if( libbfio_handle_open( file_io_handle, LIBBFIO_OPEN_READ, error ) != 1 ) { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_IO, LIBCERROR_IO_ERROR_OPEN_FAILED, "%s: unable to open file.", function ); return( -1 ); } } if( libbfio_handle_seek_offset( file_io_handle, 0, SEEK_SET, error ) == -1 ) { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_IO, LIBCERROR_IO_ERROR_SEEK_FAILED, "%s: unable to seek file header offset: 0.", function ); if( file_io_handle_is_open == 0 ) { libbfio_handle_close( file_io_handle, error ); } return( -1 ); } read_count = libbfio_handle_read_buffer( file_io_handle, signature, 8, error ); if( read_count != 8 ) { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_IO, LIBCERROR_IO_ERROR_READ_FAILED, "%s: unable to read signature.", function ); libbfio_handle_close( file_io_handle, NULL ); return( -1 ); } if( file_io_handle_is_open == 0 ) { if( libbfio_handle_close( file_io_handle, error ) != 0 ) { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_IO, LIBCERROR_IO_ERROR_CLOSE_FAILED, "%s: unable to close file.", function ); return( -1 ); } } /* The number of EWF segment files will be the largest */ if( memory_compare( ewf1_evf_file_signature, signature, 8 ) == 0 ) { return( 1 ); } else if( memory_compare( ewf1_lvf_file_signature, signature, 8 ) == 0 ) { return( 1 ); } else if( memory_compare( ewf2_evf_file_signature, signature, 8 ) == 0 ) { return( 1 ); } else if( memory_compare( ewf2_lef_file_signature, signature, 8 ) == 0 ) { return( 1 ); } else if( memory_compare( ewf1_dvf_file_signature, signature, 8 ) == 0 ) { return( 1 ); } return( 0 ); }
/* Opens a file using a Basic File IO (bfio) handle * Returns 1 if successful or -1 on error */ int libmsiecf_file_open_file_io_handle( libmsiecf_file_t *file, libbfio_handle_t *file_io_handle, int access_flags, libcerror_error_t **error ) { libmsiecf_internal_file_t *internal_file = NULL; static char *function = "libmsiecf_file_open_file_io_handle"; int bfio_access_flags = 0; int file_io_handle_is_open = 0; if( file == NULL ) { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_ARGUMENTS, LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, "%s: invalid file.", function ); return( -1 ); } internal_file = (libmsiecf_internal_file_t *) file; if( internal_file->file_io_handle != NULL ) { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_RUNTIME, LIBCERROR_RUNTIME_ERROR_VALUE_ALREADY_SET, "%s: invalid file - file IO handle already set.", function ); return( -1 ); } if( file_io_handle == NULL ) { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_ARGUMENTS, LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, "%s: invalid file IO handle.", function ); return( -1 ); } if( ( ( access_flags & LIBMSIECF_ACCESS_FLAG_READ ) == 0 ) && ( ( access_flags & LIBMSIECF_ACCESS_FLAG_WRITE ) == 0 ) ) { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_ARGUMENTS, LIBCERROR_ARGUMENT_ERROR_UNSUPPORTED_VALUE, "%s: unsupported access flags.", function ); return( -1 ); } if( ( access_flags & LIBMSIECF_ACCESS_FLAG_WRITE ) != 0 ) { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_ARGUMENTS, LIBCERROR_ARGUMENT_ERROR_UNSUPPORTED_VALUE, "%s: write access currently not supported.", function ); return( -1 ); } if( ( access_flags & LIBMSIECF_ACCESS_FLAG_READ ) != 0 ) { bfio_access_flags = LIBBFIO_ACCESS_FLAG_READ; } file_io_handle_is_open = libbfio_handle_is_open( file_io_handle, error ); if( file_io_handle_is_open == -1 ) { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_IO, LIBCERROR_IO_ERROR_OPEN_FAILED, "%s: unable to open file.", function ); goto on_error; } else if( file_io_handle_is_open == 0 ) { if( libbfio_handle_open( file_io_handle, bfio_access_flags, error ) != 1 ) { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_IO, LIBCERROR_IO_ERROR_OPEN_FAILED, "%s: unable to open file IO handle.", function ); goto on_error; } internal_file->file_io_handle_opened_in_library = 1; } internal_file->file_io_handle = file_io_handle; if( libmsiecf_file_open_read( internal_file, file_io_handle, error ) != 1 ) { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_IO, LIBCERROR_IO_ERROR_READ_FAILED, "%s: unable to read from file handle.", function ); goto on_error; } return( 1 ); on_error: if( ( file_io_handle_is_open == 0 ) && ( internal_file->file_io_handle_opened_in_library != 0 ) ) { libbfio_handle_close( file_io_handle, error ); } internal_file->file_io_handle = NULL; return( -1 ); }
/* Closes a volume * Returns 0 if successful or -1 on error */ int libfshfs_volume_close( libfshfs_volume_t *volume, libcerror_error_t **error ) { libfshfs_internal_volume_t *internal_volume = NULL; static char *function = "libfshfs_volume_close"; int result = 0; if( volume == NULL ) { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_ARGUMENTS, LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, "%s: invalid volume.", function ); return( -1 ); } internal_volume = (libfshfs_internal_volume_t *) volume; if( internal_volume->io_handle == NULL ) { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_RUNTIME, LIBCERROR_RUNTIME_ERROR_VALUE_MISSING, "%s: invalid volume - missing IO handle.", function ); return( -1 ); } #if defined( HAVE_DEBUG_OUTPUT ) if( libcnotify_verbose != 0 ) { if( internal_volume->file_io_handle_created_in_library != 0 ) { if( libfshfs_debug_print_read_offsets( internal_volume->file_io_handle, error ) != 1 ) { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_RUNTIME, LIBCERROR_RUNTIME_ERROR_PRINT_FAILED, "%s: unable to print the read offsets.", function ); result = -1; } } } #endif if( internal_volume->file_io_handle_opened_in_library != 0 ) { if( libbfio_handle_close( internal_volume->file_io_handle, error ) != 0 ) { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_IO, LIBCERROR_IO_ERROR_CLOSE_FAILED, "%s: unable to close file IO handle.", function ); result = -1; } internal_volume->file_io_handle_opened_in_library = 0; } if( internal_volume->file_io_handle_created_in_library != 0 ) { if( libbfio_handle_free( &( internal_volume->file_io_handle ), error ) != 1 ) { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_RUNTIME, LIBCERROR_RUNTIME_ERROR_FINALIZE_FAILED, "%s: unable to free file IO handle.", function ); result = -1; } internal_volume->file_io_handle_created_in_library = 0; } internal_volume->file_io_handle = NULL; if( libfshfs_io_handle_clear( internal_volume->io_handle, error ) != 1 ) { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_RUNTIME, LIBCERROR_RUNTIME_ERROR_FINALIZE_FAILED, "%s: unable to clear IO handle.", function ); result = -1; } if( libfshfs_fork_descriptor_free( &( internal_volume->allocation_file_fork_descriptor ), error ) != 1 ) { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_RUNTIME, LIBCERROR_RUNTIME_ERROR_FINALIZE_FAILED, "%s: unable to free allocation file fork descriptor.", function ); result = -1; } if( libfshfs_fork_descriptor_free( &( internal_volume->extents_file_fork_descriptor ), error ) != 1 ) { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_RUNTIME, LIBCERROR_RUNTIME_ERROR_FINALIZE_FAILED, "%s: unable to free extents file fork descriptor.", function ); result = -1; } if( libfshfs_fork_descriptor_free( &( internal_volume->catalog_file_fork_descriptor ), error ) != 1 ) { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_RUNTIME, LIBCERROR_RUNTIME_ERROR_FINALIZE_FAILED, "%s: unable to free catalog file fork descriptor.", function ); result = -1; } if( libfshfs_fork_descriptor_free( &( internal_volume->attributes_file_fork_descriptor ), error ) != 1 ) { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_RUNTIME, LIBCERROR_RUNTIME_ERROR_FINALIZE_FAILED, "%s: unable to free attributes file fork descriptor.", function ); result = -1; } if( libfshfs_fork_descriptor_free( &( internal_volume->startup_file_fork_descriptor ), error ) != 1 ) { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_RUNTIME, LIBCERROR_RUNTIME_ERROR_FINALIZE_FAILED, "%s: unable to free startup file fork descriptor.", function ); result = -1; } return( result ); }
/* Closes a file * Returns 0 if successful or -1 on error */ int libmsiecf_file_close( libmsiecf_file_t *file, libcerror_error_t **error ) { libmsiecf_internal_file_t *internal_file = NULL; static char *function = "libmsiecf_file_close"; int result = 0; if( file == NULL ) { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_ARGUMENTS, LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, "%s: invalid file.", function ); return( -1 ); } internal_file = (libmsiecf_internal_file_t *) file; if( internal_file->file_io_handle == NULL ) { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_RUNTIME, LIBCERROR_RUNTIME_ERROR_VALUE_MISSING, "%s: invalid file - missing file IO handle.", function ); return( -1 ); } #if defined( HAVE_DEBUG_OUTPUT ) if( libcnotify_verbose != 0 ) { if( internal_file->file_io_handle_created_in_library != 0 ) { if( libmsiecf_debug_print_read_offsets( internal_file->file_io_handle, error ) != 1 ) { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_RUNTIME, LIBCERROR_RUNTIME_ERROR_PRINT_FAILED, "%s: unable to print the read offsets.", function ); } } } #endif if( internal_file->file_io_handle_opened_in_library != 0 ) { if( libbfio_handle_close( internal_file->file_io_handle, error ) != 0 ) { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_IO, LIBCERROR_IO_ERROR_CLOSE_FAILED, "%s: unable to close file IO handle.", function ); result = -1; } internal_file->file_io_handle_opened_in_library = 0; } if( internal_file->file_io_handle_created_in_library != 0 ) { if( libbfio_handle_free( &( internal_file->file_io_handle ), error ) != 1 ) { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_RUNTIME, LIBCERROR_RUNTIME_ERROR_FINALIZE_FAILED, "%s: unable to free file IO handle.", function ); result = -1; } internal_file->file_io_handle_created_in_library = 0; } internal_file->file_io_handle = NULL; if( libmsiecf_io_handle_clear( internal_file->io_handle, error ) != 1 ) { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_RUNTIME, LIBCERROR_RUNTIME_ERROR_FINALIZE_FAILED, "%s: unable to clear IO handle.", function ); result = -1; } if( internal_file->directory_array != NULL ) { if( libcdata_array_free( &( internal_file->directory_array ), (int (*)(intptr_t **, libcerror_error_t **)) &libmsiecf_directory_descriptor_free, error ) != 1 ) { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_RUNTIME, LIBCERROR_RUNTIME_ERROR_FINALIZE_FAILED, "%s: unable to free directory array.", function ); result = -1; } } if( internal_file->item_array != NULL ) { if( libcdata_array_free( &( internal_file->item_array ), (int (*)(intptr_t **, libcerror_error_t **)) &libmsiecf_item_descriptor_free, error ) != 1 ) { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_RUNTIME, LIBCERROR_RUNTIME_ERROR_FINALIZE_FAILED, "%s: unable to free item array.", function ); result = -1; } } if( internal_file->recovered_item_array != NULL ) { if( libcdata_array_free( &( internal_file->recovered_item_array ), (int (*)(intptr_t **, libcerror_error_t **)) &libmsiecf_item_descriptor_free, error ) != 1 ) { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_RUNTIME, LIBCERROR_RUNTIME_ERROR_FINALIZE_FAILED, "%s: unable to free recovered item array.", function ); result = -1; } } if( internal_file->unallocated_block_list != NULL ) { if( libcdata_range_list_free( &( internal_file->unallocated_block_list ), NULL, error ) != 1 ) { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_RUNTIME, LIBCERROR_RUNTIME_ERROR_FINALIZE_FAILED, "%s: unable to free unallocated block list.", function ); result = -1; } } return( result ); }
/* Closes a stream * Returns 0 if successful or -1 on error */ int libwrc_stream_close( libwrc_stream_t *stream, libcerror_error_t **error ) { libwrc_internal_stream_t *internal_stream = NULL; static char *function = "libwrc_stream_close"; int result = 0; if( stream == NULL ) { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_ARGUMENTS, LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, "%s: invalid stream.", function ); return( -1 ); } internal_stream = (libwrc_internal_stream_t *) stream; if( internal_stream->file_io_handle == NULL ) { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_RUNTIME, LIBCERROR_RUNTIME_ERROR_VALUE_MISSING, "%s: invalid stream - missing file IO handle.", function ); return( -1 ); } #if defined( HAVE_DEBUG_OUTPUT ) if( libcnotify_verbose != 0 ) { if( internal_stream->file_io_handle_created_in_library != 0 ) { if( libwrc_debug_print_read_offsets( internal_stream->file_io_handle, error ) != 1 ) { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_RUNTIME, LIBCERROR_RUNTIME_ERROR_PRINT_FAILED, "%s: unable to print the read offsets.", function ); result = -1; } } } #endif if( internal_stream->file_io_handle_opened_in_library != 0 ) { if( libbfio_handle_close( internal_stream->file_io_handle, error ) != 0 ) { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_IO, LIBCERROR_IO_ERROR_CLOSE_FAILED, "%s: unable to close file IO handle.", function ); result = -1; } internal_stream->file_io_handle_opened_in_library = 0; } if( internal_stream->file_io_handle_created_in_library != 0 ) { if( libbfio_handle_free( &( internal_stream->file_io_handle ), error ) != 1 ) { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_RUNTIME, LIBCERROR_RUNTIME_ERROR_FINALIZE_FAILED, "%s: unable to free file IO handle.", function ); result = -1; } internal_stream->file_io_handle_created_in_library = 0; } internal_stream->file_io_handle = NULL; if( libwrc_io_handle_clear( internal_stream->io_handle, error ) != 1 ) { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_RUNTIME, LIBCERROR_RUNTIME_ERROR_FINALIZE_FAILED, "%s: unable to clear IO handle.", function ); result = -1; } if( libcdata_tree_node_free( &( internal_stream->resources_root_node ), (int (*)(intptr_t **, libcerror_error_t **)) &libwrc_resource_values_free, error ) != 1 ) { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_RUNTIME, LIBCERROR_RUNTIME_ERROR_FINALIZE_FAILED, "%s: unable to free resources root node.", function ); result = -1; } return( result ); }