Browse Source

gfsec-split: Add the -o, --output option.

Add an option to override the default location where the secret
should be reconstructed.
master
Damien Goutte-Gattat 4 years ago
parent
commit
5b26c65fe1
  1. 19
      src/gfsec-split.c
  2. 13
      src/secret.c
  3. 2
      src/secret.h
  4. 3
      src/secretcfg.c

19
src/gfsec-split.c

@ -65,6 +65,12 @@ Split the specified file for later use with gfsec-use.\n"));
puts(_("\
-k, --keep Do not delete the original file.\n"));
puts(_("\
-o, --output FILE Specify the location where the file will\n\
be reconstructed by gfsec-use. The default\n\
is to reconstruct the file at its original\n\
location.\n"));
puts(_("\
-l, --list-supports List available supports and exit.\n"));
@ -241,7 +247,7 @@ main(int argc, char **argv)
{
int c, list_mode, interactive;
unsigned threshold, keep_original;
char *config_path, *secret_file;
char *config_path, *secret_file, *output_file;
gfsec_secret_t *cfg;
struct option options[] = {
@ -252,6 +258,7 @@ main(int argc, char **argv)
{ "interactive", 0, NULL, 'i' },
{ "config", 1, NULL, 'c' },
{ "keep", 0, NULL, 'k' },
{ "output", 1, NULL, 'o' },
{ "list-supports", 0, NULL, 'l' },
{ NULL, 0, NULL, 0 }
};
@ -259,7 +266,7 @@ main(int argc, char **argv)
setprogname(argv[0]);
threshold = 2;
keep_original = list_mode = interactive = 0;
config_path = NULL;
config_path = output_file = NULL;
setlocale(LC_ALL, "");
bindtextdomain(PACKAGE, LOCALEDIR);
@ -269,7 +276,7 @@ main(int argc, char **argv)
cfg = gfsec_secret_new();
while ( (c = getopt_long(argc, argv, "hvn:s:ic:kl",
while ( (c = getopt_long(argc, argv, "hvn:s:ic:ko:l",
options, NULL)) != -1 ) {
switch ( c ) {
case 'h':
@ -305,6 +312,10 @@ main(int argc, char **argv)
keep_original = 1;
break;
case 'o':
output_file = optarg;
break;
case 'l':
list_mode = 1;
break;
@ -345,7 +356,7 @@ main(int argc, char **argv)
if ( file_exists(config_path) != -1 )
errx(EXIT_FAILURE, _("Configuration file %s already exists"), config_path);
if ( (c = gfsec_secret_set_secret_file(cfg, secret_file)) != 0 )
if ( (c = gfsec_secret_set_secret_file(cfg, secret_file, output_file)) != 0 )
errx(EXIT_FAILURE, _("Cannot set secret: %s"), gfsec_error_string(c));
while ( optind < argc ) {

13
src/secret.c

@ -42,7 +42,7 @@
* Create a secret object and fills it with the secret data:
* \code
* gfsec_secret_t *secret = gfsec_secret_new();
* gfsec_secret_set_secret_file(secret, filename);
* gfsec_secret_set_secret_file(secret, filename, filename);
* \endcode
*
* Create share objects describing the shares to split the
@ -306,18 +306,25 @@ gfsec_secret_new(void)
*
* @param secret The secret object.
* @param filename The location of the file to read the secret from.
* @param confname The location where the reconstructed secret will
* be written to. If NULL, this is set to the
* location of the original file.
*
* @return 0 if successful, or one of the GFSEC_ERR_SYSTEM_ERROR if
* an I/O error occured.
*/
int
gfsec_secret_set_secret_file(gfsec_secret_t *secret,
const char *filename)
const char *filename,
const char *confname)
{
assert(secret != NULL);
assert(filename != NULL);
secret->filename = xstrdup(filename);
if ( confname )
secret->filename = *confname ? xstrdup(confname) : NULL;
else
secret->filename = xstrdup(filename);
if ( ! (secret->data = read_file(filename, &(secret->len),
GFSEC_SECRET_MAX_SIZE)) )

2
src/secret.h

@ -123,7 +123,7 @@ gfsec_secret_t *
gfsec_secret_new(void);
int
gfsec_secret_set_secret_file(gfsec_secret_t *, const char *);
gfsec_secret_set_secret_file(gfsec_secret_t *, const char *, const char *);
int
gfsec_secret_add_share(gfsec_secret_t *, gfsec_share_t *);

3
src/secretcfg.c

@ -409,7 +409,8 @@ gfsec_write_config(gfsec_secret_t *cfg, const char *filename)
if ( ! (f = fopen(filename, "w")) )
return GFSEC_ERR_SYSTEM_ERROR;
fprintf(f, "OUTFILE=%s\n", cfg->filename);
if ( cfg->filename )
fprintf(f, "OUTFILE=%s\n", cfg->filename);
fprintf(f, "MINSHARES=%u\n", cfg->threshold);
for ( n = 0; n < cfg->n_shares; n++ ) {

Loading…
Cancel
Save