Skip to content

Commit

Permalink
Make mountable of the decrypted volume
Browse files Browse the repository at this point in the history
  • Loading branch information
jclab-joseph committed Apr 13, 2021
1 parent ceae24f commit c3d4dbc
Show file tree
Hide file tree
Showing 6 changed files with 16 additions and 4 deletions.
1 change: 1 addition & 0 deletions include/dislocker/metadata/metadata.h
Original file line number Diff line number Diff line change
Expand Up @@ -92,5 +92,6 @@ uint64_t dis_metadata_mftmirror(dis_metadata_t dis_meta);

uint32_t dis_metadata_backup_sectors_count(dis_metadata_t dis_meta);

int dis_metadata_is_decrypted_state(dis_metadata_t dis_meta);

#endif // METADATA_H
3 changes: 3 additions & 0 deletions include/dislocker/metadata/metadata_config.h
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,9 @@ struct _dis_metadata_config {
/* States dislocker's metadata initialisation is at or will be stopped at */
dis_state_e curr_state;
dis_state_e init_stop_at;

/* Readonly mode for EOW support */
int readonly;
};


Expand Down
1 change: 1 addition & 0 deletions src/dislocker-metadata.c
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,7 @@ int main(int argc, char **argv)
dis_meta_cfg = dis_metadata_config_new();
dis_meta_cfg->fve_fd = fve_fd;
dis_meta_cfg->offset = offset;
dis_meta_cfg->readonly = 1;

dis_metadata = dis_metadata_new(dis_meta_cfg);
if(dis_metadata_initialize(dis_metadata) != DIS_RET_SUCCESS)
Expand Down
4 changes: 3 additions & 1 deletion src/dislocker.c
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,8 @@ int dis_initialize(dis_context_t dis_ctx)
return DIS_RET_ERROR_ALLOC;
}

dis_ctx->metadata->cfg->readonly = (dis_ctx->cfg.flags & DIS_FLAG_READ_ONLY) ? 1 : 0;

ret = dis_metadata_initialize(dis_ctx->metadata);
dis_ctx->curr_state = dis_meta_cfg->curr_state;
if(ret != DIS_RET_SUCCESS)
Expand Down Expand Up @@ -326,7 +328,7 @@ int dislock(dis_context_t dis_ctx, uint8_t* buffer, off_t offset, size_t size)
return -EFAULT;
}

if(offset >= (off_t)dis_ctx->io_data.volume_size)
if((offset >= (off_t)dis_ctx->io_data.volume_size) && !dis_metadata_is_decrypted_state(dis_ctx->io_data.metadata))
{
dis_printf(
L_ERROR,
Expand Down
2 changes: 1 addition & 1 deletion src/inouts/prepare.c
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ int prepare_crypt(dis_context_t dis_ctx)
* Get volume size directly from dis_metadata_t, which is more accurate.
*/
io_data->volume_size = io_data->encrypted_volume_size;
if(io_data->volume_size == 0)
if(io_data->volume_size == 0 && !dis_metadata_is_decrypted_state(io_data->metadata))
{
dis_printf(L_ERROR, "Can't initialize the volume's size\n");
return DIS_RET_ERROR_VOLUME_SIZE_NOT_FOUND;
Expand Down
9 changes: 7 additions & 2 deletions src/metadata/metadata.c
Original file line number Diff line number Diff line change
Expand Up @@ -454,8 +454,10 @@ static int check_volume_header(dis_metadata_t dis_meta, int volume_fd, off_t dis
" failed\n", source);
}

dis_printf(L_ERROR, "EOW volume GUID not supported.\n");
return FALSE;
if (!dis_meta->cfg->readonly) {
dis_printf(L_ERROR, "EOW volume GUID not supported for writing.\n");
return FALSE;
}
}
else
{
Expand Down Expand Up @@ -1325,6 +1327,9 @@ uint32_t dis_metadata_backup_sectors_count(dis_metadata_t dis_meta)
return dis_meta->information->nb_backup_sectors;
}

int dis_metadata_is_decrypted_state(dis_metadata_t dis_meta) {
return dis_meta->information->curr_state == METADATA_STATE_DECRYPTED;
}

#ifdef _HAVE_RUBY
#include <sys/types.h>
Expand Down

0 comments on commit c3d4dbc

Please sign in to comment.