Browse Source

Accept a share number in the share parameter.

Expand the use of the share parameter to accept a numeric value in
addition to the keywords 'no' and 'full'. That value is interpreted as
the share number, and takes precedence over the filename's extension.
master
Damien Goutte-Gattat 3 months ago
parent
commit
4806854437
  1. 23
      src/secretcfg.c

23
src/secretcfg.c

@ -162,6 +162,21 @@ parse_sha256(const char *hex, size_t len, unsigned char **sha256)
return 0;
}
static int
parse_share_number(const char *str, size_t len, unsigned short *nr)
{
char *endptr;
*nr = strtoul(str, &endptr, 10);
if ( endptr != (str + len) )
return GFSEC_ERR_CONFIG_INVALID_SHARENR;
if ( *nr == 0 || *nr > 255 )
return GFSEC_ERR_CONFIG_INVALID_SHARENR;
return 0;
}
/**
* Parses a name=value parameter in the provided string.
*
@ -196,7 +211,7 @@ parse_parameter(const char **uri, gfsec_share_t *share)
else if ( strncmp(eq, "full", amp - eq) == 0 )
share->number = GFSEC_SHARE_NUMBER_FULL;
else
return GFSEC_ERR_CONFIG_INVALID_SHARENR;
rc = parse_share_number(eq, amp - eq, &(share->number));
*uri = amp;
}
else if ( strncmp(*uri, "sha256", eq - *uri) == 0 ) {
@ -292,10 +307,8 @@ gfsec_parse_uri(const char *uri, gfsec_secret_t *secret, int assign)
while ( rc == 0 && *p )
rc = parse_parameter(&p, share);
if ( rc == 0 && ! gfsec_share_is_full(share) ) {
if ( assign )
share->number = GFSEC_SHARE_NUMBER_AUTOASSIGN;
else if ( (share->number = get_share_number_from_path(share->path)) == 0 )
if ( rc == 0 && share->number == GFSEC_SHARE_NUMBER_AUTOASSIGN && ! assign ) {
if ( (share->number = get_share_number_from_path(share->path)) == 0 )
rc = GFSEC_ERR_CONFIG_INVALID_URI;
}

Loading…
Cancel
Save