summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNeilBrown <neilb@suse.de>2015-07-22 09:24:36 +1000
committerNeilBrown <neilb@suse.de>2015-07-22 09:24:36 +1000
commit00f23a886134f1278aa61da3342f58d26f23f4d3 (patch)
tree3d86c6ef654de2470b6ff24cd4fe61b64708d221
parent12ee2a8d75067a9cadfedecf2af36f6c2aedf25d (diff)
downloadmdadm-00f23a886134f1278aa61da3342f58d26f23f4d3.tar.gz
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>
-rw-r--r--Assemble.c19
1 files changed, 12 insertions, 7 deletions
diff --git a/Assemble.c b/Assemble.c
index 1960927..a3d020d 100644
--- a/Assemble.c
+++ b/Assemble.c
@@ -30,16 +30,21 @@ static int name_matches(char *found, char *required, char *homehost)
/* See if the name found matches the required name, possibly
* prefixed with 'homehost'
*/
- char fnd[33];
+ char *sep;
+ unsigned int l;
- strncpy(fnd, found, 32);
- fnd[32] = 0;
if (strcmp(found, required)==0)
return 1;
- if (homehost) {
- int l = strlen(homehost);
- if (l < 32 && fnd[l] == ':' &&
- strcmp(fnd+l+1, required)==0)
+ sep = strchr(found, ':');
+ if (!sep)
+ return 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 0;