Hide the dislocker's context structure

This structure shouldn't be messed with, so we put it in a private
header - dislocker.priv.h. This is the occasion to put the config
structure in a private header too. Although there's no incomplete type
for the config structure in the public header so developers would use
the dislocker context structure only.
This commit is contained in:
Aorimn
2015-03-14 23:41:38 +01:00
parent 3f52b17765
commit 53ca6e4264
8 changed files with 61 additions and 152 deletions
+1 -1
View File
@@ -24,7 +24,7 @@
#define ACCESSES_H
#include "dislocker/dislocker.h"
#include "dislocker/dislocker.priv.h"
+7 -97
View File
@@ -24,41 +24,10 @@
#define DISLOCKER_CFG_H
#include "dislocker/return_values.h"
#include "dislocker/xstd/xstdio.h"
#include <sys/types.h>
#include <unistd.h>
#include "dislocker/dislocker.h"
/**
* Different methods to decrypt the VMK
*/
typedef enum {
DIS_USE_CLEAR_KEY = (1 << 0),
DIS_USE_USER_PASSWORD = (1 << 1),
DIS_USE_RECOVERY_PASSWORD = (1 << 2),
DIS_USE_BEKFILE = (1 << 3),
DIS_USE_FVEKFILE = (1 << 4)
} DIS_DECRYPT_MEAN;
/* Don't use this as a decryption mean, but as the last one */
#define LAST_MEAN (1 << 5)
/**
* Just an enum not to have a random constant written everytime we use this
*/
typedef enum {
/* Make the volume read-only, in order not to corrupt it */
DIS_FLAG_READ_ONLY = (1 << 0),
/*
* By default, dislocker will check for unstable state that may corrupt data
* if mounted using fuse
*/
DIS_FLAG_DONT_CHECK_VOLUME_STATE = (1 << 1),
} dis_flags_e;
typedef enum {
/* Below are options dis_getopts() can parse out of the command line */
@@ -98,76 +67,17 @@ typedef enum {
} dis_state_e;
#define checkupdate_dis_state(ctx, state) \
do { \
(ctx)->curr_state = (state); \
if((state) == (ctx)->cfg.init_stop_at) { \
xprintf(L_DEBUG, "Exiting at state %d\n", (state)); \
return DIS_RET_SUCCESS; \
} \
} while(0);
/**
* Structure containing command line options
*/
typedef struct _dis_cfg {
/* BitLocker-volume-to-mount path */
char* volume_path;
/* Which method to use to decrypt */
DIS_DECRYPT_MEAN decryption_mean;
/* Path to the .bek file in case of using the BEKFILE DECRYPT_MEAN */
char* bek_file;
/*
* Recovery password to use in case of using the RECOVERY_PASSWORD
* DECRYPT_MEAN
*/
uint8_t* recovery_password;
/* User password to use in case of using the USER_PASSWORD DECRYPT_MEAN */
uint8_t* user_password;
/* Use directly the FVEK file DECRYPT_MEAN */
char* fvek_file;
/* Output verbosity */
DIS_LOGS verbosity;
/* Output file */
char* log_file;
/* Use this block of metadata and not another one (begin at 1) */
unsigned char force_block;
/*
* Begin to read the BitLocker volume at this offset, making this offset the
* zero-one
*/
off_t offset;
/*
* Various flags one can use. See dis_flags_e enum above for possible values
*/
dis_flags_e flags;
/* Where dis_initialize() should stop */
dis_state_e init_stop_at;
} dis_config_t;
/*
* Function's prototypes
*/
void dis_usage();
int dis_getopts(dis_config_t* cfg, int argc, char** argv);
int dis_setopt(dis_config_t* cfg, dis_opt_e opt_name, const void* opt_value);
void dis_free_args(dis_config_t* cfg);
void dis_print_args(dis_config_t* cfg);
int dis_getopts(dis_context_t dis_ctx, int argc, char** argv);
int dis_setopt(dis_context_t dis_ctx, dis_opt_e opt_name, const void* opt_value);
void dis_free_args(dis_context_t dis_ctx);
void dis_print_args(dis_context_t dis_ctx);
int dis_is_read_only(dis_config_t* cfg);
int dis_is_volume_state_checked(dis_config_t* cfg);
int dis_is_read_only(dis_context_t dis_ctx);
int dis_is_volume_state_checked(dis_context_t dis_ctx);
#endif /* DISLOCKER_CFG_H */
+2 -22
View File
@@ -24,10 +24,7 @@
#define DISLOCKER_MAIN_H
#include <stdint.h>
#include "dislocker/config.h"
#include "dislocker/outputs/sectors.h"
#include "dislocker/xstd/xstdio.h" // Only for off_t
@@ -35,24 +32,7 @@
* Main structure to pass to dislocker functions. These keeps various
* information in it.
*/
typedef struct _dis_ctx {
/*
* Dislocker's configuration.
* Note that there's the dis_getopts() function to fill this structure from
* command-line's arguments and the dis_setopt() function
*/
dis_config_t cfg;
/*
* Structure needed for dec/encryption processes.
*/
dis_iodata_t io_data;
/*
* States dislocker initialisation is at or will be stopped at.
*/
dis_state_e curr_state;
} *dis_context_t;
typedef struct _dis_ctx* dis_context_t;
+1 -1
View File
@@ -25,7 +25,7 @@
#include "dislocker/common.h"
#include "dislocker/config.h"
#include "dislocker/config.priv.h"
#include "dislocker/metadata/guid.h"
#include "dislocker/ntfs/clock.h"
+2 -2
View File
@@ -26,8 +26,8 @@
#include <stdint.h>
#include "dislocker/dislocker.h"
#include "dislocker/config.h"
#include "dislocker/dislocker.priv.h"
#include "dislocker/config.priv.h"
#include "dislocker/encryption/encommon.h"
#include "dislocker/metadata/datums.h"
#include "dislocker/metadata/metadata.h"
+43 -25
View File
@@ -25,7 +25,8 @@
#include <getopt.h>
#include "dislocker/common.h"
#include "dislocker/config.h"
#include "dislocker/config.priv.h"
#include "dislocker/dislocker.priv.h"
@@ -100,7 +101,7 @@ static void hide_opt(char* opt)
* @return Return the number of arguments which are still waiting to be studied.
* If -1 is returned, then an error occurred and the configuration isn't set.
*/
int dis_getopts(dis_config_t* cfg, int argc, char** argv)
int dis_getopts(dis_context_t dis_ctx, int argc, char** argv)
{
/** See man getopt_long(3) */
extern int optind;
@@ -132,6 +133,11 @@ int dis_getopts(dis_config_t* cfg, int argc, char** argv)
{0, 0, 0, 0}
};
if(!dis_ctx || !argv)
return -1;
dis_config_t* cfg = &dis_ctx->cfg;
while((optchar=getopt_long(argc, argv, short_opts, long_opts, NULL)) != -1)
{
@@ -140,12 +146,12 @@ int dis_getopts(dis_config_t* cfg, int argc, char** argv)
case 'c':
{
int t = TRUE;
dis_setopt(cfg, DIS_OPT_CLEAR_KEY, &t);
dis_setopt(dis_ctx, DIS_OPT_CLEAR_KEY, &t);
break;
}
case 'f':
{
dis_setopt(cfg, DIS_OPT_BEK_FILE_PATH, optarg);
dis_setopt(dis_ctx, DIS_OPT_BEK_FILE_PATH, optarg);
break;
}
case 'F':
@@ -155,58 +161,58 @@ int dis_getopts(dis_config_t* cfg, int argc, char** argv)
force = (unsigned char) strtol(optarg, NULL, 10);
else
force = 1;
dis_setopt(cfg, DIS_OPT_FORCE_BLOCK, &force);
dis_setopt(dis_ctx, DIS_OPT_FORCE_BLOCK, &force);
break;
}
case 'h':
{
dis_usage();
dis_free_args(cfg);
dis_free_args(dis_ctx);
exit(EXIT_SUCCESS);
}
case 'k':
{
dis_setopt(cfg, DIS_OPT_FVEK_FILE_PATH, optarg);
dis_setopt(dis_ctx, DIS_OPT_FVEK_FILE_PATH, optarg);
break;
}
case 'l':
{
dis_setopt(cfg, DIS_OPT_LOG_FILE_PATH, optarg);
dis_setopt(dis_ctx, DIS_OPT_LOG_FILE_PATH, optarg);
break;
}
case 'o':
{
off_t offset = (off_t) strtoll(optarg, NULL, 10);
dis_setopt(cfg, DIS_OPT_VOLUME_OFFSET, &offset);
dis_setopt(dis_ctx, DIS_OPT_VOLUME_OFFSET, &offset);
break;
}
case 'p':
{
dis_setopt(cfg, DIS_OPT_RECOVERY_PASSWORD, optarg);
dis_setopt(dis_ctx, DIS_OPT_RECOVERY_PASSWORD, optarg);
hide_opt(optarg);
break;
}
case 'q':
{
DIS_LOGS l = L_QUIET;
dis_setopt(cfg, DIS_OPT_VERBOSITY, &l);
dis_setopt(dis_ctx, DIS_OPT_VERBOSITY, &l);
break;
}
case 'r':
{
int t = TRUE;
dis_setopt(cfg, DIS_OPT_READ_ONLY, &t);
dis_setopt(dis_ctx, DIS_OPT_READ_ONLY, &t);
break;
}
case 's':
{
int t = TRUE;
dis_setopt(cfg, DIS_OPT_DONT_CHECK_VOLUME_STATE, &t);
dis_setopt(dis_ctx, DIS_OPT_DONT_CHECK_VOLUME_STATE, &t);
break;
}
case 'u':
{
dis_setopt(cfg, DIS_OPT_USER_PASSWORD, optarg);
dis_setopt(dis_ctx, DIS_OPT_USER_PASSWORD, optarg);
hide_opt(optarg);
break;
}
@@ -218,14 +224,14 @@ int dis_getopts(dis_config_t* cfg, int argc, char** argv)
}
case 'V':
{
dis_setopt(cfg, DIS_OPT_VOLUME_PATH, optarg);
dis_setopt(dis_ctx, DIS_OPT_VOLUME_PATH, optarg);
break;
}
case '?':
default:
{
dis_usage();
dis_free_args(cfg);
dis_free_args(dis_ctx);
return -1;
}
}
@@ -259,11 +265,12 @@ int dis_getopts(dis_config_t* cfg, int argc, char** argv)
* @param opt_value The new value of the option. Note that this is a pointer. If
* NULL, the default value -which is not necessarily usable- will be set.
*/
int dis_setopt(dis_config_t* cfg, dis_opt_e opt_name, const void* opt_value)
int dis_setopt(dis_context_t dis_ctx, dis_opt_e opt_name, const void* opt_value)
{
if (!cfg)
if (!dis_ctx || !opt_value)
return FALSE;
dis_config_t* cfg = &dis_ctx->cfg;
switch(opt_name)
{
@@ -429,11 +436,13 @@ int dis_setopt(dis_config_t* cfg, dis_opt_e opt_name, const void* opt_value)
*
* @param cfg Dislocker's config
*/
void dis_free_args(dis_config_t* cfg)
void dis_free_args(dis_context_t dis_ctx)
{
if (!cfg)
if (!dis_ctx)
return;
dis_config_t* cfg = &dis_ctx->cfg;
if(cfg->recovery_password)
memclean(cfg->recovery_password,
strlen((char*)cfg->recovery_password) + sizeof(char));
@@ -459,8 +468,13 @@ void dis_free_args(dis_config_t* cfg)
/**
* Print read configuration
*/
void dis_print_args(dis_config_t* cfg)
void dis_print_args(dis_context_t dis_ctx)
{
if(!dis_ctx)
return;
dis_config_t* cfg = &dis_ctx->cfg;
xprintf(L_DEBUG, "--- Config...\n");
xprintf(L_DEBUG, " Verbosity: %d\n", cfg->verbosity);
xprintf(L_DEBUG, " Trying to decrypt '%s'\n", cfg->volume_path);
@@ -515,13 +529,17 @@ void dis_print_args(dis_config_t* cfg)
/**
* Getters for the flags
*/
int dis_is_read_only(dis_config_t* cfg)
int dis_is_read_only(dis_context_t dis_ctx)
{
return (cfg->flags & DIS_FLAG_READ_ONLY);
if(!dis_ctx)
return -1;
return (dis_ctx->cfg.flags & DIS_FLAG_READ_ONLY);
}
int dis_is_volume_state_checked(dis_config_t* cfg)
int dis_is_volume_state_checked(dis_context_t dis_ctx)
{
return !(cfg->flags & DIS_FLAG_DONT_CHECK_VOLUME_STATE);
if(!dis_ctx)
return -1;
return !(dis_ctx->cfg.flags & DIS_FLAG_DONT_CHECK_VOLUME_STATE);
}
+4 -4
View File
@@ -46,8 +46,8 @@
#include "dislocker/xstd/xstdio.h"
#include "dislocker/return_values.h"
#include "dislocker/config.h"
#include "dislocker/dislocker.h"
#include "dislocker/config.priv.h"
#include "dislocker/dislocker.priv.h"
#include <locale.h>
@@ -111,7 +111,7 @@ int dis_initialize(dis_context_t dis_ctx)
xstdio_init(dis_ctx->cfg.verbosity, dis_ctx->cfg.log_file);
if(dis_ctx->cfg.verbosity >= L_DEBUG)
dis_print_args(&dis_ctx->cfg);
dis_print_args(dis_ctx);
/*
@@ -798,7 +798,7 @@ int dis_destroy(dis_context_t dis_ctx)
pthread_mutex_destroy(&dis_ctx->io_data.mutex_lseek_rw);
dis_free_args(&dis_ctx->cfg);
dis_free_args(dis_ctx);
xclose(dis_ctx->io_data.volume_fd);
+1
View File
@@ -23,6 +23,7 @@
#define _GNU_SOURCE
#include <unistd.h>
#include <errno.h>
#include "dislocker/common.h"