Browse Source

Print warning if calculated hash is incorrect

If the calculated hash of a share does not match the configured
hash, give the user a warning.
develop
Damien Goutte-Gattat 5 years ago
parent
commit
36f07f66c6
  1. 29
      src/gfsec-use.c

29
src/gfsec-use.c

@ -124,6 +124,20 @@ 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, gcry_md_hd_t md)
{
@ -161,6 +175,7 @@ get_share_data(gfsec_share_t *share, gcry_md_hd_t md)
md_val = gcry_md_read(md, 0);
if ( memcmp(share->sha256, md_val, 32) != 0 ) {
warnx("Incorrect hash value for share %s\n", get_share_display_name(share));
free(share->data);
share->data = NULL;
rc = -1;
@ -172,20 +187,6 @@ get_share_data(gfsec_share_t *share, gcry_md_hd_t md)
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;
}
int
main(int argc, char **argv)
{

Loading…
Cancel
Save