]> git.ipfire.org Git - thirdparty/libvirt.git/commitdiff
virsh: Fix logical error in cmdSetUserSSHKeys()
authorMichal Privoznik <mprivozn@redhat.com>
Tue, 8 Dec 2020 12:42:28 +0000 (13:42 +0100)
committerMichal Privoznik <mprivozn@redhat.com>
Tue, 8 Dec 2020 13:39:04 +0000 (14:39 +0100)
In v6.10.0-rc1~104 I've added a virsh command that exposes
virDomainAuthorizedSSHKeysSet() API under "set-user-sshkeys"
command. The command accepts mutually exclusive "--reset" and
"--remove" options (among others). While the former controls the
VIR_DOMAIN_AUTHORIZED_SSH_KEYS_SET_APPEND flag, the latter
controls the VIR_DOMAIN_AUTHORIZED_SSH_KEYS_SET_REMOVE flag.
These flags are also mutually exclusive. But the code that sets
them has a logical error which may result in both flags being
set. In fact, this results in user being not able to set just the
remove flag.

Fixes: 87d12effbea8b414c250b6fefd93154c62a99370
Resolves: https://bugzilla.redhat.com/show_bug.cgi?id=1904674
Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
tools/virsh-domain.c

index 1fb4189b4b25efebe68c47543251154a3df3cb74..6266c7acd257c28ad6edbb39cb7a6f92a2f21a69 100644 (file)
@@ -14375,18 +14375,19 @@ cmdSetUserSSHKeys(vshControl *ctl, const vshCmd *cmd)
     if (vshCommandOptStringReq(ctl, cmd, "file", &from) < 0)
         goto cleanup;
 
-    if (!vshCommandOptBool(cmd, "reset")) {
-        flags |= VIR_DOMAIN_AUTHORIZED_SSH_KEYS_SET_APPEND;
+    if (vshCommandOptBool(cmd, "remove")) {
+        flags |= VIR_DOMAIN_AUTHORIZED_SSH_KEYS_SET_REMOVE;
+    } else {
+        if (!vshCommandOptBool(cmd, "reset")) {
+            flags |= VIR_DOMAIN_AUTHORIZED_SSH_KEYS_SET_APPEND;
 
-        if (!from) {
-            vshError(ctl, _("Option --file is required"));
-            goto cleanup;
+            if (!from) {
+                vshError(ctl, _("Option --file is required"));
+                goto cleanup;
+            }
         }
     }
 
-    if (vshCommandOptBool(cmd, "remove"))
-        flags |= VIR_DOMAIN_AUTHORIZED_SSH_KEYS_SET_REMOVE;
-
     if (from) {
         if (virFileReadAll(from, VSH_MAX_XML_FILE, &buffer) < 0) {
             vshSaveLibvirtError();