Browse Source

Move function to format share name into secret

develop
Damien Goutte-Gattat 5 years ago
parent
commit
95d6dec0ff
  1. 38
      src/gfsec-use.c
  2. 19
      src/secret.c
  3. 3
      src/secret.h

38
src/gfsec-use.c

@ -123,25 +123,12 @@ get_config_file(const char *filename, char *buffer, size_t len)
return rc;
}
static char *
get_share_display_name(gfsec_share_t *share)
{
static char buffer[256];
char *schemes[] = { "file://", "uuid://", "label://", "mtp://" };
snprintf(buffer, sizeof(buffer), "%s%s%s",
schemes[share->scheme],
share->authority ? share->authority : "",
share->path);
return buffer;
}
static int
get_share_data(gfsec_share_t *share)
{
int rc = -1;
unsigned char *data;
char buffer[256];
size_t len;
switch ( share->scheme ) {
@ -169,12 +156,19 @@ get_share_data(gfsec_share_t *share)
break;
}
if ( rc == 0 && gfsec_share_set_data(share, data, len) != 0 ) {
warnx("Incorrect hash value for share %s\n", get_share_display_name(share));
free(data);
rc = -1;
if ( rc == 0 ) {
gfsec_share_get_uri(share, buffer, sizeof(buffer));
if ( gfsec_share_set_data(share, data, len) != 0 ) {
warnx("Incorrect hash value for share %s\n", buffer);
free(data);
rc = -1;
}
else
printf("Found share data in %s\n", buffer);
}
return rc;
}
@ -241,12 +235,8 @@ main(int argc, char **argv)
if ( ! output_file && ! (output_file = cfg->filename) )
errx(EXIT_FAILURE, "No output file specified");
for ( u = 0; u < cfg->n_shares; u++ ) {
share = cfg->shares[u];
if ( get_share_data(share) == 0 )
printf("Found share data in %s\n", get_share_display_name(share));
}
for ( u = 0; u < cfg->n_shares; u++ )
get_share_data(cfg->shares[u]);
if ( gfsec_secret_can_combine(cfg) != 0 )
errx(EXIT_FAILURE, "Cannot reconstitute secret");

19
src/secret.c

@ -109,6 +109,25 @@ gfsec_share_set_data(gfsec_share_t *share,
return ret;
}
int
gfsec_share_get_uri(gfsec_share_t *share,
char *buffer,
size_t len)
{
static char *schemes[] = { "file://", "uuid://", "label://", "mtp://" };
int ret;
if ( ! share || ! buffer )
return GFSEC_ERR_INVALID_CALL;
ret = snprintf(buffer, len, "%s%s%s",
schemes[share->scheme],
share->authority ? share->authority : "",
share->path);
return ret;
}
void
gfsec_share_free(gfsec_share_t *share)
{

3
src/secret.h

@ -87,6 +87,9 @@ gfsec_share_set_data(gfsec_share_t *,
unsigned char *,
size_t);
int
gfsec_share_get_uri(gfsec_share_t *, char *, size_t);
void
gfsec_share_free(gfsec_share_t *);

Loading…
Cancel
Save