vos: Add missing -partition requires -server checks 05/14005/7
authorMichael Meffie <mmeffie@sinenomine.net>
Mon, 23 Dec 2019 23:37:21 +0000 (18:37 -0500)
committerBenjamin Kaduk <kaduk@mit.edu>
Fri, 13 Nov 2020 16:07:08 +0000 (11:07 -0500)
The `vos remove` command was missing a check for the -server option when
the -partition option is given. This command requires the -server option
when the -partition is given, as documented in the man page.

The `vos syncvldb` command performed the check for the -server option
when the -partition option is given, but in the wrong location.

As documented, the `vos unlockvldb` command permits the -partition
option without a -server option, in which case all of the volumes listed
in the VLDB with sites on the specified partition are unlocked.
However, this command incorrectly issued an RPC to a volume server at
address 0.0.0.0 when only the partition is given.

Change-Id: I6b878678e28b34250e63d2d082747f6fd416972d
Reviewed-on: https://gerrit.openafs.org/14005
Reviewed-by: Benjamin Kaduk <kaduk@mit.edu>
Tested-by: BuildBot <buildbot@rampaginggeek.com>
Reviewed-by: Michael Meffie <mmeffie@sinenomine.net>

src/volser/vos.c

index be487b2..da09a32 100644 (file)
@@ -2081,6 +2081,11 @@ DeleteVolume(struct cmd_syndesc *as, void *arock)
     char pname[10];
     afs_int32 idx, j;
 
+    if (as->parms[1].items && !as->parms[0].items) {
+       fprintf(STDERR, "vos: The -partition option requires the -server option.\n");
+       return EINVAL;
+    }
+
     if (as->parms[0].items) {
        server = GetServer(as->parms[0].items->data);
        if (!server) {
@@ -3812,6 +3817,12 @@ SyncVldb(struct cmd_syndesc *as, void *arock)
     afs_uint32 tserver;
 
     tserver = 0;
+
+    if (as->parms[1].items && !as->parms[0].items) {
+       fprintf(STDERR, "vos: The -partition option requires the -server option.\n");
+       exit(1);
+    }
+
     if (as->parms[0].items) {
        tserver = GetServer(as->parms[0].items->data);
        if (!tserver) {
@@ -3838,12 +3849,6 @@ SyncVldb(struct cmd_syndesc *as, void *arock)
            exit(1);
        }
        flags = 1;
-
-       if (!tserver) {
-           fprintf(STDERR,
-                   "The -partition option requires a -server option\n");
-           exit(1);
-       }
     }
 
     if (as->parms[3].items) {
@@ -5047,14 +5052,17 @@ UnlockVLDB(struct cmd_syndesc *as, void *arock)
                    as->parms[1].items->data);
            exit(1);
        }
-       if (!IsPartValid(apart, aserver, &code)) {      /*check for validity of the partition */
-           if (code)
-               PrintError("", code);
-           else
-               fprintf(STDERR,
-                       "vos : partition %s does not exist on the server\n",
-                       as->parms[1].items->data);
-           exit(1);
+       if (aserver) {
+           /* Check for validity of the partition if a server was given. */
+           if (!IsPartValid(apart, aserver, &code)) {
+               if (code)
+                   PrintError("", code);
+               else
+                   fprintf(STDERR,
+                           "vos : partition %s does not exist on the server\n",
+                           as->parms[1].items->data);
+               exit(1);
+           }
        }
        attributes.partition = apart;
        attributes.Mask |= VLLIST_PARTITION;