From: Marc-André Lureau <marcandre.lureau@redhat.com>
A process with enough capabilities can duplicate a socket to QEMU.
Modify 'getfd' to import it and add it to the monitor fd list, so it can
be later used by other commands.
Note that we actually store the SOCKET in the FD list, appropriate care
must now be taken to use the correct socket functions (similar approach
is taken by our io/ code and in glib, this is internal and shouldn't
affect the QEMU/QMP users)
Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
---
qapi/misc.json | 16 ++++++++--
monitor/fds.c | 79 ++++++++++++++++++++++++++++++++++++----------
monitor/hmp-cmds.c | 6 +++-
3 files changed, 81 insertions(+), 20 deletions(-)
+#endif
+ Error **errp)
+{
+ Monitor *cur_mon = monitor_cur();
+ int fd;
+
+#ifdef WIN32
+ if (wsa_info) {
+ g_autofree WSAPROTOCOL_INFOW *info = NULL;
+ gsize len;
+ SOCKET sk;
+
+ info = (void *)g_base64_decode(wsa_info, &len);
+ if (len != sizeof(*info)) {
+ error_setg(errp, "Invalid WSAPROTOCOL_INFOW value");
+ return;
+ }
+
+ sk = WSASocketW(FROM_PROTOCOL_INFO, FROM_PROTOCOL_INFO,
+ FROM_PROTOCOL_INFO, info, 0, 0);
+ if (sk == INVALID_SOCKET) {
+ g_autofree gchar *emsg = g_win32_error_message(WSAGetLastError());
+ error_setg(errp, "Couldn't create socket: %s", emsg);
+ return;
+ }
+
+ return monitor_add_fd(cur_mon, sk, fdname, errp);
+ }
+#endif
+
+ fd = qemu_chr_fe_get_msgfd(&cur_mon->chr);
+ if (fd == -1) {
+ error_setg(errp, "No file descriptor supplied via SCM_RIGHTS");
+ return;
+ }
+
+ return monitor_add_fd(cur_mon, fd, fdname, errp);
}