From nobody Thu May 15 18:12:38 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) client-ip=209.132.183.28; envelope-from=libvir-list-bounces@redhat.com; helo=mx1.redhat.com; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1508879369828447.9261544407659; Tue, 24 Oct 2017 14:09:29 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 299A9C070147; Tue, 24 Oct 2017 21:09:28 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.21]) by smtp.corp.redhat.com (Postfix) with ESMTPS id C47315D6A2; Tue, 24 Oct 2017 21:09:27 +0000 (UTC) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by colo-mx.corp.redhat.com (Postfix) with ESMTP id 5C4DA6EF21; Tue, 24 Oct 2017 21:09:25 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id v9OL9NU5023715 for ; Tue, 24 Oct 2017 17:09:23 -0400 Received: by smtp.corp.redhat.com (Postfix) id C2C275D6A2; Tue, 24 Oct 2017 21:09:23 +0000 (UTC) Received: from mx1.redhat.com (ext-mx10.extmail.prod.ext.phx2.redhat.com [10.5.110.39]) by smtp.corp.redhat.com (Postfix) with ESMTPS id BA3FF5D6A8 for ; Tue, 24 Oct 2017 21:09:22 +0000 (UTC) Received: from mail-qk0-f193.google.com (mail-qk0-f193.google.com [209.85.220.193]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 3233833A167 for ; Tue, 24 Oct 2017 21:09:21 +0000 (UTC) Received: by mail-qk0-f193.google.com with SMTP id b15so28062201qkg.9 for ; Tue, 24 Oct 2017 14:09:21 -0700 (PDT) Received: from dawid-fedora.datto.lan ([47.19.105.250]) by smtp.gmail.com with ESMTPSA id e43sm901453qte.74.2017.10.24.14.09.19 for (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Tue, 24 Oct 2017 14:09:19 -0700 (PDT) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 299A9C070147 Authentication-Results: ext-mx07.extmail.prod.ext.phx2.redhat.com; dmarc=fail (p=none dis=none) header.from=datto.com Authentication-Results: ext-mx07.extmail.prod.ext.phx2.redhat.com; spf=fail smtp.mailfrom=libvir-list-bounces@redhat.com DKIM-Filter: OpenDKIM Filter v2.11.0 mx1.redhat.com 299A9C070147 Authentication-Results: mx1.redhat.com; dkim=fail reason="signature verification failed" (2048-bit key) header.d=datto-com.20150623.gappssmtp.com header.i=@datto-com.20150623.gappssmtp.com header.b="WejZDTTA" DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 3233833A167 Authentication-Results: ext-mx10.extmail.prod.ext.phx2.redhat.com; dmarc=pass (p=none dis=none) header.from=datto.com Authentication-Results: ext-mx10.extmail.prod.ext.phx2.redhat.com; spf=pass smtp.mailfrom=dzamirski@datto.com DKIM-Filter: OpenDKIM Filter v2.11.0 mx1.redhat.com 3233833A167 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=datto-com.20150623.gappssmtp.com; s=20150623; h=from:to:subject:date:message-id:in-reply-to:references; bh=I4/LSYQmwZNRQ8JoHoFR2FRD8G/BhWA0zRyd9pEJVn8=; b=WejZDTTArvobaPNZqJyOH6ViF1N0Wy/wgHWihIzyf/Wl+VL6eqkdt1sUDdiZtBW4yi Ey11yU10e96NYKkrC+Yv20E+f8vk5m/VE8zm+xCxwLuosY+N+DYJZnAvvRF0Lf+f/jAq 7+we4vKPQipbBYfWqlI/NzsUD6IFTAVDA0PmBoIEQCxI5HJw0VjqERgj18XkbZ8RODjX jFWL8Y9m125dEYFQTVp5l2EK3AKu/WOa9WGdeqTQMB6J2EqUHU99VpysvQLJB6lJN2ph 4oVQ9+FXvIu9BkJOP36yhnPXZL6ASt8vDPgQntBK8q96Nf8hzLdYnzPLRuhaNAB/NJ8o TquQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references; bh=I4/LSYQmwZNRQ8JoHoFR2FRD8G/BhWA0zRyd9pEJVn8=; b=K76iAwOXS9B4w/6yFnjO4JKk9LO0q315g3lU7nEMGtWhZZ2/XnxFEBZfD0Usp2qXXW 8qM4UVGlgeq/t/sDpd58yo6Dl+bxyxsrJLY01DIdalS/Wlf6mAeTH6jpbeLO/rxxnCqt K/31tK82thyp6ZWVvPzYV/XftqJhQ3i6HagfKNx8WtEYA9zBXhKCOA3P1iaAWw0B8Ppw 5f8l3nhh4ngwZ4fUefuwsQ19Ry1fvCaUYjdebka12UtsKjgeNtoVd0XhE6w66AQyy5vj yztM91m4jizMQ/U2FCXXoQQsMarXbSRcMXnsbbSvJpHtebkWusPkpHWgitWjeOwDals7 XS/w== X-Gm-Message-State: AMCzsaWDkIMXPeC+TGAAFEZXD9D78rtLdYGtBGUQz9KH02D4PUHN3pVe 15d9Izhc6dw/Z2RvHXPc4DlTwnXHtMY= X-Google-Smtp-Source: ABhQp+TrzmxEx8TvEnlcuiBhgKxydpkXqQ6sSHmxOmAPJOmpxIbGA4u9YGA4HoGHvYe7bm2wc+Q17w== X-Received: by 10.55.214.201 with SMTP id p70mr26077028qkl.21.1508879360174; Tue, 24 Oct 2017 14:09:20 -0700 (PDT) From: Dawid Zamirski To: libvir-list@redhat.com Date: Tue, 24 Oct 2017 17:09:17 -0400 Message-Id: <20171024210917.7728-4-dzamirski@datto.com> In-Reply-To: <20171024210917.7728-1-dzamirski@datto.com> References: <20171024210917.7728-1-dzamirski@datto.com> X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.39]); Tue, 24 Oct 2017 21:09:21 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.39]); Tue, 24 Oct 2017 21:09:21 +0000 (UTC) for IP:'209.85.220.193' DOMAIN:'mail-qk0-f193.google.com' HELO:'mail-qk0-f193.google.com' FROM:'dzamirski@datto.com' RCPT:'' X-RedHat-Spam-Score: 0.469 (DKIM_SIGNED, DKIM_VALID, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H3, RCVD_IN_MSPIKE_WL, RCVD_IN_SORBS_SPAM, SPF_PASS) 209.85.220.193 mail-qk0-f193.google.com 209.85.220.193 mail-qk0-f193.google.com X-Scanned-By: MIMEDefang 2.78 on 10.5.110.39 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH v2 3/3] vbox: Read runtime RDP port and handle autoport X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.31]); Tue, 24 Oct 2017 21:09:28 +0000 (UTC) X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZohoMail: RDKM_2 RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" VirutalBox has a IVRDEServerInfo structure available that gives the effective runtime port that the VM is using when it's running. This is useful when the "TCP/Ports" VBox property was set to port range (e.g. via autoport =3D "yes" or via VBoxManage) in which case it would be impossible to get the "active" port otherwise. Reviewed-by: John Ferlan --- src/vbox/vbox_common.c | 3 +- src/vbox/vbox_tmpl.c | 134 +++++++++++++++++++++++++++++++-------= ---- src/vbox/vbox_uniformed_api.h | 2 +- 3 files changed, 104 insertions(+), 35 deletions(-) diff --git a/src/vbox/vbox_common.c b/src/vbox/vbox_common.c index 92ee37164..d542f2b76 100644 --- a/src/vbox/vbox_common.c +++ b/src/vbox/vbox_common.c @@ -3326,7 +3326,8 @@ vboxDumpDisplay(virDomainDefPtr def, vboxDriverPtr da= ta, IMachine *machine) if (VIR_ALLOC(graphics) < 0) goto cleanup; =20 - gVBoxAPI.UIVRDEServer.GetPorts(data, VRDEServer, graphics); + gVBoxAPI.UIVRDEServer.GetPorts(data, VRDEServer, machine, graphics= ); + gVBoxAPI.UISession.Close(data->vboxSession); =20 graphics->type =3D VIR_DOMAIN_GRAPHICS_TYPE_RDP; =20 diff --git a/src/vbox/vbox_tmpl.c b/src/vbox/vbox_tmpl.c index 2b3f2e3eb..c7682f13c 100644 --- a/src/vbox/vbox_tmpl.c +++ b/src/vbox/vbox_tmpl.c @@ -221,29 +221,6 @@ _vboxIIDFromArrayItem(vboxDriverPtr data, vboxIID *iid, _vboxIIDFromArrayItem(data, iid, array, idx) #define DEBUGIID(msg, strUtf16) DEBUGPRUnichar(msg, strUtf16) =20 -/** - * Converts Utf-16 string to int - */ -static int PRUnicharToInt(PCVBOXXPCOM pFuncs, PRUnichar *strUtf16) -{ - char *strUtf8 =3D NULL; - int ret =3D 0; - - if (!strUtf16) - return -1; - - pFuncs->pfnUtf16ToUtf8(strUtf16, &strUtf8); - if (!strUtf8) - return -1; - - if (virStrToLong_i(strUtf8, NULL, 10, &ret) < 0) - ret =3D -1; - - pFuncs->pfnUtf8Free(strUtf8); - - return ret; -} - /** * Converts int to Utf-16 string */ @@ -280,6 +257,54 @@ static virDomainState _vboxConvertState(PRUint32 state) } } =20 + +static int +vboxGetActiveVRDEServerPort(ISession *session, IMachine *machine) +{ + nsresult rc; + PRInt32 port =3D -1; + IVRDEServerInfo *vrdeInfo =3D NULL; + IConsole *console =3D NULL; + + rc =3D machine->vtbl->LockMachine(machine, session, LockType_Shared); + if (NS_FAILED(rc)) { + VIR_WARN("Could not obtain shared lock on VBox VM, rc=3D%08x", rc); + return -1; + } + + rc =3D session->vtbl->GetConsole(session, &console); + if (NS_FAILED(rc)) { + VIR_WARN("Could not get VBox session console, rc=3D%08x", rc); + goto cleanup; + } + + /* it may be null if VM is not running */ + if (!console) + goto cleanup; + + rc =3D console->vtbl->GetVRDEServerInfo(console, &vrdeInfo); + + if (NS_FAILED(rc) || !vrdeInfo) { + VIR_WARN("Could not get VBox VM VRDEServerInfo, rc=3D%08x", rc); + goto cleanup; + } + + rc =3D vrdeInfo->vtbl->GetPort(vrdeInfo, &port); + + if (NS_FAILED(rc)) { + VIR_WARN("Could not read port from VRDEServerInfo, rc=3D%08x", rc); + goto cleanup; + } + + cleanup: + VBOX_RELEASE(console); + VBOX_RELEASE(vrdeInfo); + session->vtbl->UnlockMachine(session); + + return port; +} + + static int _vboxDomainSnapshotRestore(virDomainPtr dom, IMachine *machine, @@ -1576,24 +1601,67 @@ _vrdeServerSetEnabled(IVRDEServer *VRDEServer, PRBo= ol enabled) } =20 static nsresult -_vrdeServerGetPorts(vboxDriverPtr data ATTRIBUTE_UNUSED, - IVRDEServer *VRDEServer, virDomainGraphicsDefPtr graph= ics) +_vrdeServerGetPorts(vboxDriverPtr data, IVRDEServer *VRDEServer, + IMachine *machine, virDomainGraphicsDefPtr graphics) { nsresult rc; PRUnichar *VRDEPortsKey =3D NULL; PRUnichar *VRDEPortsValue =3D NULL; + PRInt32 port =3D -1; + ssize_t nmatches =3D 0; + char **matches =3D NULL; + char *portUtf8 =3D NULL; + + /* get active (effective) port - available only when VM is running and= has + * the VBOX extensions installed (without extenstions RDP server + * functionality is disabled) + */ + port =3D vboxGetActiveVRDEServerPort(data->vboxSession, machine); =20 + if (port > 0) + graphics->data.rdp.port =3D port; + + /* get the port (or port range) set in VM properties, this info will + * be used to determine whether to set autoport flag + */ VBOX_UTF8_TO_UTF16("TCP/Ports", &VRDEPortsKey); - rc =3D VRDEServer->vtbl->GetVRDEProperty(VRDEServer, VRDEPortsKey, &VR= DEPortsValue); - VBOX_UTF16_FREE(VRDEPortsKey); - if (VRDEPortsValue) { - /* even if vbox supports mutilpe ports, single port for now here */ - graphics->data.rdp.port =3D PRUnicharToInt(data->pFuncs, VRDEPorts= Value); - VBOX_UTF16_FREE(VRDEPortsValue); - } else { - graphics->data.rdp.autoport =3D true; + rc =3D VRDEServer->vtbl->GetVRDEProperty(VRDEServer, VRDEPortsKey, + &VRDEPortsValue); + + if (NS_FAILED(rc)) { + virReportError(VIR_ERR_INTERNAL_ERROR, + _("Failed to read RDP port value, rc=3D%08x"), + (unsigned) rc); + goto cleanup; } =20 + VBOX_UTF16_TO_UTF8(VRDEPortsValue, &portUtf8); + + if (portUtf8) { + /* does the string contain digits only */ + nmatches =3D virStringSearch(portUtf8, "(^[[:digit:]]+$)", 1, &mat= ches); + + /* the port property is not numeric, then it must be a port range = or + * port list or combination of the two, either way it's an autoport + */ + if (nmatches !=3D 1) + graphics->data.rdp.autoport =3D true; + + /* no active port available, e.g. VM is powered off, try to get it= from + * the property string + */ + if (port < 0) { + if (nmatches =3D=3D 1 && virStrToLong_i(portUtf8, NULL, 10, &p= ort) =3D=3D 0) + graphics->data.rdp.port =3D port; + } + } + + cleanup: + virStringListFree(matches); + VBOX_UTF8_FREE(portUtf8); + VBOX_UTF16_FREE(VRDEPortsValue); + VBOX_UTF16_FREE(VRDEPortsKey); + return rc; } =20 diff --git a/src/vbox/vbox_uniformed_api.h b/src/vbox/vbox_uniformed_api.h index 2ccaf43e8..8cf27789b 100644 --- a/src/vbox/vbox_uniformed_api.h +++ b/src/vbox/vbox_uniformed_api.h @@ -341,7 +341,7 @@ typedef struct { nsresult (*GetEnabled)(IVRDEServer *VRDEServer, PRBool *enabled); nsresult (*SetEnabled)(IVRDEServer *VRDEServer, PRBool enabled); nsresult (*GetPorts)(vboxDriverPtr driver, IVRDEServer *VRDEServer, - virDomainGraphicsDefPtr graphics); + IMachine *machine, virDomainGraphicsDefPtr graphi= cs); nsresult (*SetPorts)(vboxDriverPtr driver, IVRDEServer *VRDEServer, virDomainGraphicsDefPtr graphics); nsresult (*GetReuseSingleConnection)(IVRDEServer *VRDEServer, PRBool *= enabled); --=20 2.14.2 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list