Assemble: improve tests for matching --name= request.

If the name in the array has a home-host, then
require that it matches, or is "any", or requested
homehost is "any".

Signed-off-by: NeilBrown <neilb@suse.com>
This commit is contained in:
NeilBrown 2015-07-22 09:24:36 +10:00
parent 12ee2a8d75
commit 00f23a8861
1 changed files with 12 additions and 7 deletions

View File

@ -30,16 +30,21 @@ static int name_matches(char *found, char *required, char *homehost)
/* See if the name found matches the required name, possibly /* See if the name found matches the required name, possibly
* prefixed with 'homehost' * prefixed with 'homehost'
*/ */
char fnd[33]; char *sep;
unsigned int l;
strncpy(fnd, found, 32);
fnd[32] = 0;
if (strcmp(found, required)==0) if (strcmp(found, required)==0)
return 1; return 1;
if (homehost) { sep = strchr(found, ':');
int l = strlen(homehost); if (!sep)
if (l < 32 && fnd[l] == ':' && return 0;
strcmp(fnd+l+1, required)==0) l = sep - found;
if (strncmp(found, "any:", 4) == 0 ||
(homehost && strcmp(homehost, "any") == 0) ||
(homehost && strlen(homehost) == l &&
strncmp(found, homehost, l) == 0)) {
/* matching homehost */
if (strcmp(sep+1, required) == 0)
return 1; return 1;
} }
return 0; return 0;