]> git.ipfire.org Git - thirdparty/mdadm.git/commitdiff
Assemble: improve tests for matching --name= request.
authorNeilBrown <neilb@suse.de>
Tue, 21 Jul 2015 23:24:36 +0000 (09:24 +1000)
committerNeilBrown <neilb@suse.de>
Tue, 21 Jul 2015 23:24:36 +0000 (09:24 +1000)
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>
Assemble.c

index 1960927340e66378b08f6cc9378d18f063facafc..a3d020d0cbc5586a08124b1d9c9e2ca9b7e2c72e 100644 (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
         * 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;