From bf5de8c5d66552721fefe08de849c115ca366b56 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= Date: Mon, 6 Mar 2023 16:27:45 +0400 Subject: qmp: 'add_client' actually expects sockets MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Whether it is SPICE, VNC, D-Bus, or the socket chardev, they all actually expect a socket kind or will fail in different ways at runtime. Throw an error early if the given 'add_client' fd is not a socket, and close it to avoid leaks. This allows to replace the close() call with a more correct & portable closesocket() version. (this will allow importing sockets on Windows with a specialized command in the following patch, while keeping the remaining monitor associated sockets/add_client code & usage untouched) Signed-off-by: Marc-André Lureau Reviewed-by: Philippe Mathieu-Daudé Acked-by: Markus Armbruster Message-Id: <20230306122751.2355515-6-marcandre.lureau@redhat.com> --- qapi/misc.json | 3 +++ 1 file changed, 3 insertions(+) (limited to 'qapi') diff --git a/qapi/misc.json b/qapi/misc.json index 27ef5a2..f0217cf 100644 --- a/qapi/misc.json +++ b/qapi/misc.json @@ -14,6 +14,9 @@ # Allow client connections for VNC, Spice and socket based # character devices to be passed in to QEMU via SCM_RIGHTS. # +# If the FD associated with @fdname is not a socket, the command will fail and +# the FD will be closed. +# # @protocol: protocol name. Valid names are "vnc", "spice", "@dbus-display" or # the name of a character device (eg. from -chardev id=XXXX) # -- cgit v1.1 From 4cda177c6016565dda1f1c3f6cff8ab85ef0d016 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= Date: Mon, 6 Mar 2023 16:27:48 +0400 Subject: qmp: add 'get-win32-socket' MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit A process with enough capabilities can duplicate a socket to QEMU. Add a QMP command to import it and add it to the monitor fd list, so it can be later used by other commands. Signed-off-by: Marc-André Lureau Acked-by: Markus Armbruster Message-Id: <20230306122751.2355515-9-marcandre.lureau@redhat.com> --- qapi/misc.json | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) (limited to 'qapi') diff --git a/qapi/misc.json b/qapi/misc.json index f0217cf..5ef6286 100644 --- a/qapi/misc.json +++ b/qapi/misc.json @@ -276,6 +276,37 @@ { 'command': 'getfd', 'data': {'fdname': 'str'} } ## +# @get-win32-socket: +# +# Add a socket that was duplicated to QEMU process with +# WSADuplicateSocketW() via WSASocket() & WSAPROTOCOL_INFOW structure +# and assign it a name (the SOCKET is associated with a CRT file +# descriptor) +# +# @info: the WSAPROTOCOL_INFOW structure (encoded in base64) +# +# @fdname: file descriptor name +# +# Returns: Nothing on success +# +# Since: 8.0 +# +# Notes: If @fdname already exists, the file descriptor assigned to +# it will be closed and replaced by the received file +# descriptor. +# +# The 'closefd' command can be used to explicitly close the +# file descriptor when it is no longer needed. +# +# Example: +# +# -> { "execute": "get-win32-socket", "arguments": { "info": "abcd123..", fdname": "skclient" } } +# <- { "return": {} } +# +## +{ 'command': 'get-win32-socket', 'data': {'info': 'str', 'fdname': 'str'}, 'if': 'CONFIG_WIN32' } + +## # @closefd: # # Close a file descriptor previously passed via SCM rights -- cgit v1.1 From 4bf21c7f748bee42b6f4692f8c37a11d1033b2d1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= Date: Thu, 2 Mar 2023 19:05:41 +0400 Subject: monitor: restrict command getfd to POSIX hosts MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Currently, the function will simply fail if ancillary fds are not provided, for ex on unsupported platforms. This changes the failure from: {"error": {"class": "GenericError", "desc": "No file descriptor supplied via SCM_RIGHTS"}} to: {"error": {"class": "CommandNotFound", "desc": "The command getfd has not been found"}} Signed-off-by: Marc-André Lureau Reviewed-by: Markus Armbruster --- qapi/misc.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'qapi') diff --git a/qapi/misc.json b/qapi/misc.json index 5ef6286..6ddd16e 100644 --- a/qapi/misc.json +++ b/qapi/misc.json @@ -273,7 +273,7 @@ # <- { "return": {} } # ## -{ 'command': 'getfd', 'data': {'fdname': 'str'} } +{ 'command': 'getfd', 'data': {'fdname': 'str'}, 'if': 'CONFIG_POSIX' } ## # @get-win32-socket: -- cgit v1.1