From 09582826dbf74b0a7c8e5a47d00aaf7636344d28 Mon Sep 17 00:00:00 2001 From: Jasper Lievisse Adriaanse Date: Mon, 3 Jul 2023 08:32:21 +0000 Subject: when shutting down a vm, handle the VM id in the same way as a VM name argument ok dv@ --- usr.sbin/vmd/vmd.c | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) (limited to 'usr.sbin/vmd/vmd.c') diff --git a/usr.sbin/vmd/vmd.c b/usr.sbin/vmd/vmd.c index 3ba9c6792fd..1b7cc3270c5 100644 --- a/usr.sbin/vmd/vmd.c +++ b/usr.sbin/vmd/vmd.c @@ -1,4 +1,4 @@ -/* $OpenBSD: vmd.c,v 1.150 2023/06/18 11:45:11 op Exp $ */ +/* $OpenBSD: vmd.c,v 1.151 2023/07/03 08:32:20 jasper Exp $ */ /* * Copyright (c) 2015 Reyk Floeter @@ -159,20 +159,22 @@ vmd_dispatch_control(int fd, struct privsep_proc *p, struct imsg *imsg) if ((vm = vm_getbyname(vid.vid_name)) == NULL) { res = ENOENT; break; - } else if ((vm->vm_state & VM_STATE_SHUTDOWN) && - (flags & VMOP_FORCE) == 0) { - res = EALREADY; - break; - } else if (!(vm->vm_state & VM_STATE_RUNNING)) { - res = EINVAL; - break; } id = vm->vm_vmid; } else if ((vm = vm_getbyvmid(id)) == NULL) { res = ENOENT; break; } - if (vm_checkperm(vm, &vm->vm_params.vmc_owner, vid.vid_uid)) { + + /* Validate curent state of vm */ + if ((vm->vm_state & VM_STATE_SHUTDOWN) && + (flags & VMOP_FORCE) == 0) { + res = EALREADY; + break; + } else if (!(vm->vm_state & VM_STATE_RUNNING)) { + res = EINVAL; + break; + } else if (vm_checkperm(vm, &vm->vm_params.vmc_owner, vid.vid_uid)) { res = EPERM; break; } -- cgit v1.2.3