Commit Graph

78 Commits

Author SHA1 Message Date
Uri Lublin
64f771fef1 event_dispatcher: vd_printf calls -- remove __func__
vd_printf adds __FUNCTION__

Signed-off-by: Uri Lublin <uril@redhat.com>
Acked-by: Frediano Ziglio <fziglio@redhat.com>
2017-07-14 11:16:48 +01:00
Uri Lublin
32bb5cbeb0 clipboard: log format used
Signed-off-by: Uri Lublin <uril@redhat.com>
Acked-by: Frediano Ziglio <fziglio@redhat.com>
2017-07-14 11:16:42 +01:00
kunming.xie
f80ee415c1 Fix hdesk handle leak in vdagent
Signed-off-by: kunming.xie <kunming.xie@hotmail.com>
Acked-by: Frediano Ziglio <fziglio@redhat.com>
2017-05-23 16:35:04 +01:00
Jonathon Jongsma
a2b4da90a1 Don't exit vdagent when a client disconnects
Previously, when a client disconnects, the vdagent executable exited.
The agent was restarted immediately in order to be ready for the next
client to reconnect.

This is generally fine, but there are certain situations
where it causes issues. For example, if client A is connected to a guest
and client B connects to the same guest, client A will be forcibly
disconnected and causes the the vdagent to restart. This scenario is
racy because the agent can take some time to exit and restart. Client B
may think that the agent is connected at startup and may send agent
messages to the guest.  At some point the server will recieve
notification that the agent has exited and send an AGENT_DISCONNECTED
message to client B. After the agent has been fully restarted, an
AGENT_CONNECTED message will be sent to the client, but any messages
sent between client connection and the AGENT_DISCONNECTED message will
be lost. This causes problems especially with fullscreen mode in
virt-viewer.

The solution is to not exit and restart the agent when a client
disconnects. This is how the linux vdagent behaves. Instead, we simply
cancel all ongoing file transfers and reset the clipboard when a client
is disconnected.

Fixes: rhbz#1064495
Signed-off-by: Jonathon Jongsma <jjongsma@redhat.com>
Acked-by: Pavel Grunt <pgrunt@redhat.com>
2017-04-05 10:30:00 -05:00
Frediano Ziglio
75a0033f42 Use simpler classes for mutex handling
Signed-off-by: Frediano Ziglio <fziglio@redhat.com>
Acked-by: Christophe Fergeau <cfergeau@redhat.com>
2016-09-01 15:50:14 +01:00
Frediano Ziglio
ec0a2352b1 Use std::vector for agent capabilities
Signed-off-by: Frediano Ziglio <fziglio@redhat.com>
Acked-by: Christophe Fergeau <cfergeau@redhat.com>
2016-09-01 15:50:14 +01:00
Frediano Ziglio
25ef634202 Make some members constant
Signed-off-by: Frediano Ziglio <fziglio@redhat.com>
Acked-by: Christophe Fergeau <cfergeau@redhat.com>
2016-09-01 15:46:50 +01:00
Frediano Ziglio
2cb102280a Make static and constant some lookup arrays
Make clipboard_formats and image_types static and constant.

Signed-off-by: Frediano Ziglio <fziglio@redhat.com>
Acked-by: Christophe Fergeau <cfergeau@redhat.com>
2016-09-01 15:46:50 +01:00
Frediano Ziglio
7555e21545 Reuse SPICE_N_ELEMENTS macro
Signed-off-by: Frediano Ziglio <fziglio@redhat.com>
Acked-by: Christophe Fergeau <cfergeau@redhat.com>
2016-09-01 15:46:50 +01:00
Sameeh Jubran
9c561ca8fe Update the displays only when needed
This patch updates the display configurations only when needed.
Currently vdagent updates the display configurations almost on every
"VD_AGENT_MONITORS_CONFIG" request, this approach is redundant as some
"VD_AGENT_MONITORS_CONFIG" requests don't apply any change to the
display configurations.

A good example of why this is needed, is the 'resize-guest' feature of
the spice-widget which when enabled causes the client to send periodic
"VD_AGENT_MONITORS_CONFIG" requests in order to resize the guest even
when no change is required. Prior to this patch the screen would
periodically flicker when using Virt-manager or Spicy due to this issue.

Signed-off-by: Sameeh Jubran <sameeh@daynix.com>
Acked-by: Frediano Ziglio <fziglio@redhat.com>
2016-08-30 17:15:11 +01:00
Frediano Ziglio
f96d575659 Pass class pointer using thread parameter
Signed-off-by: Frediano Ziglio <fziglio@redhat.com>
Acked-by: Victor Toso <victortoso@redhat.com>
2016-08-16 15:43:21 +01:00
Frediano Ziglio
2ab513267b Don't use _singleton if we already have the right this pointer
Signed-off-by: Frediano Ziglio <fziglio@redhat.com>
Acked-by: Victor Toso <victortoso@redhat.com>
2016-08-16 15:43:19 +01:00
Victor Toso
3bddbd19fd vdagent: rework on event_dispatcher
As _stop_event is not mandatory, we are initializing the events array
with something that might be NULL. The problem is with the following
patch as I'm introducing a new non mandatory event and logic starts to
get a bit hard to follow.

So this patch makes explicit if we are setting or receiving a
_stop_event or not and uses an auxiliary enum and array 'actions' to
work around this non mandatory events and the return value of
MsgWaitForMultipleObjectsEx()

Signed-off-by: Victor Toso <victortoso@redhat.com>
Acked-by: Frediano Ziglio <fziglio@redhat.com>
2016-08-13 17:47:49 +02:00
Victor Toso
8ae139f363 vdagent: remove whitespaces
Acked-by: Frediano Ziglio <fziglio@redhat.com>
2016-08-12 09:41:41 +01:00
Victor Toso
5907b6cbb5 vdagent-win: check for locked session
>From WTSRegisterSessionNotification() we are aware of session changes
(WM_WTSSESSION_CHANGE) such as Lock/Unlock events.

We can use that to disable features such as drag-and-drop.
Tested on: Windows 7, Windows XP

Resolves: https://bugzilla.redhat.com/show_bug.cgi?id=1323628
Acked-by: Pavel Grunt <pgrunt@redhat.com>
2016-05-09 12:40:24 +02:00
Uri Lublin
5edf7433a4 handle_mouse_event: fix off-by-one when normalizing mouse coordinates
Mouse coordinates can be 0..(width-1) and 0..(height-1)

Normalization of mouse coordinates (for SendInput) was done
against w,h and thus right-most and down-most coordinates
could never be reached.

Fix it by normalizing against (w-1) and (h-1).

Also added protection against a case of 0 or 1 (for any of w,h)
Fixes rhbz#1032037
2016-05-05 11:47:20 +03:00
Sandy Stutsman
259d6b5bdb Check for set-monitors-position capability from client.
If the client hasn't been updated to handle multi-monitor configurations
that are not multi-head, vd_agent won't issue the MONITORS_CONFIG driver
escape.

These changes will ensure that the new MONITORS_CONFIG escape in commit:
6023630562 will not break with an older
client.

This resolves: https://bugzilla.redhat.com/show_bug.cgi?id=1248196
2015-08-06 12:01:45 +02:00
Uri Lublin
dd53b1766e vdagent::handle_max_clipboard fix vd_printf format
Using unsigned long to print a size_t.
2014-12-30 17:17:24 +02:00
Marc-André Lureau
6d1c038a8c Don't refresh displays config when updating
wnd_proc() is called during ChangeDisplaySettings(), when handling
monitors config. However, calling get_displays() will overwrite the
desired config.

So, while updating from 1 to 4 enabled monitors, when the 2nd monitor
config is enabled, the current config is read, and overwrite the rest of
the config, so first time only 2nd monitor is enabled, second time, 3rd
monitor etc.

https://bugzilla.redhat.com/show_bug.cgi?id=1111144
2014-06-19 19:15:39 +02:00
Uri Lublin
4171d11bb6 vdagent: clipboard: Add VD_AGENT_CAP_MAX_CLIPBOARD support
Do not send clipboard data bigger than last received
VDAgentMaxClipboard.

If a larger amount of data needs to be transferred between client and guest,
a different mechanism should be used, not clipboard.

The spice-protocol git-submodule is updated to include VD_AGENT_MAX_CLIPBOARD
and related definitions.
2014-03-09 18:55:42 +02:00
Uri Lublin
aed39aeccf vdagent: clipboard: GlobalUnlock on handle_request failure
Moved clipboard definition to the beginning of the function, as
mingw-gcc complains about gotos that jump over definitions.
2014-03-09 18:55:40 +02:00
Marc-André Lureau
5129f33899 Add suggested parentheses
vdagent/vdagent.cpp: In member function 'void
VDAgent::on_clipboard_grab()':
vdagent/vdagent.cpp:951:52: warning: suggest parentheses around
assignment used as truth value [-Wparentheses]
2013-07-17 20:45:22 +02:00
Marc-André Lureau
b52c9ddfa8 Fix wrong DWORD print fmt
format '%u' expects argument of type 'unsigned int', but argument 8 has type 'DWORD
2013-07-17 20:45:21 +02:00
Marc-André Lureau
3bf46bc2b2 dos2unix 2013-07-17 20:45:21 +02:00
Arnon Gilboa
c751e8fda0 vdagent: add support for client -> guest file transfers
rhbz#956146
2013-06-27 14:23:49 +03:00
Arnon Gilboa
f7968d5035 cleanup dispatch_message() 2013-06-27 13:24:21 +03:00
Arnon Gilboa
631c8623e3 vdagent: advertise CRLF line-ending
rhbz#872252
2013-06-20 17:36:17 +03:00
Uri Lublin
08a23eb45b vdagent: protect against NULL entry in _displays
rhbz#958051

It may be that a _displays entry will be NULL.
I encountered it when running with multiple QXL devices, for one of
which the driver failed to load since it was "out of resources".

Iterations over _displays should handle that case.
We found four such iterations, and fixed them in this patch.
2013-05-12 12:43:25 +03:00
Arnon Gilboa
b72b943309 vdagent: drop clipboard received after timeout
rhbz #951618
2013-05-09 14:19:11 +03:00
Arnon Gilboa
e55103589a vdagent: add support for VD_AGENT_CLIENT_DISCONNECTED
vdagent is stopped, so a new instance is to be launched by vdservice.
imho, this seems simpler than cleaning agent in/out msg state and
reseting the vio-serial device to cleanup pending msgs.

rhbz #956133
2013-05-09 14:19:11 +03:00
Arnon Gilboa
877ee81f81 vdagent: support sparse monitors config
rhbz #953973
2013-05-09 14:19:11 +03:00
Marc-André Lureau
4ca71770f2 build-sys: fix mingw build 2013-04-24 14:21:50 +02:00
Marc-André Lureau
de672f8cf2 Revert "Refresh monitor config only when needed"
This reverts commit 67c1bcf493.

Also add a comment why the refresh is necessary there. The original
issue, reentering call, doesn't seem reproducible...

https://bugzilla.redhat.com/show_bug.cgi?id=912793
2013-04-24 12:02:23 +03:00
Arnon Gilboa
0074ebcfb1 Revert "vdagent: add vdagent_helper to support mouse when UAC dialog takes focus"
This reverts commit dd9d1f41ca.
2013-04-22 11:17:40 +03:00
Arnon Gilboa
dd9d1f41ca vdagent: add vdagent_helper to support mouse when UAC dialog takes focus
Running the helper with ShellExecute(..."runas"...) is the way to SendInput()
to the UAC dialog in Windows Vista and above.

http://stackoverflow.com/questions/2426594/starting-a-uac-elevated-process-
from-a-non-interactive-service-win32-net-power

http://www.microsoft-questions.com/microsoft/Platform-SDK-Security/29620442/
how-to-proper-use-sendinput-to-a-elevated-window-from-a-service.aspx

rhbz #908422
2013-03-18 15:38:20 +02:00
Arnon Gilboa
136c8d3c94 vdagent: don't terminate if stop event cannot be opened
so vdagent can keep running as standalone without dependency on vdservice.

Regression was due to commit c1807e.

rhbz #903379
2013-03-18 14:13:04 +02:00
Arnon Gilboa
e364fa7799 vdagent: log unsupported grabbed clipboard formats
rhbz #919451 debugging, useful anyway
2013-03-18 13:21:14 +02:00
Arnon Gilboa
482a4980f4 vdagent: for Win7 class, use ClipboardFormatListener api
(Win7 class includes Win8/Vista/Server2012/Server2008/R2)

This new api was introduced in Vista/2K8 to keep track of clipboard changes,
without the need to trust the (mis)behavior of other applications registered
to the clipboard.

If the issue is reproduced on XP as well, it can be hacked by a periodic call
to ChangeClipboardChain & SetClipboardViewer as described in
http://social.msdn.microsoft.com/Forums/en-US/csharplanguage/thread/
521183dc-7872-472e-8104-8c0d75b1bf53

rhbz #919451
2013-03-18 13:16:22 +02:00
Arnon Gilboa
9b05b948fc vdagent: on encoding only, use HBITMAP to keep the correct palette
for decoding, keep using CF_DIB and CxImage.CopyToHandle() as before.

Regression was due to commit da07ce (rhbz #919150)

rhbz #921980
2013-03-18 12:45:25 +02:00
Marc-André Lureau
67c1bcf493 Refresh monitor config only when needed
Somehow wnd_proc()->get_display() may be reentered during ChangeDisplaySettings
2013-03-16 00:55:15 +01:00
Arnon Gilboa
da07ced71c vdagent: use HBITMAP instead of DIB for image encoding
CxImage DIB to PNG encoding seems to ignore pallete in some scenarios.
This issue happens when copying a png from FireFox, but with IE it's ok.

rhbz #919150
2013-03-12 13:09:50 +02:00
Arnon Gilboa
2d03cc5c2c vdservice stops vdagent via event
Terminate agent politely instead of ugly TerminateProcess(), so now
VD_AGENT_CLIPBOARD_RELEASE is sent (if guest owned the clipboard),
followed by cleanup.

rhbz #903379
2013-01-31 11:34:14 +02:00
Arnon Gilboa
f1873dfa9b vdagent: remove vdi_port, use vio_serial directly 2012-12-09 11:33:25 +02:00
Arnon Gilboa
9b5954165d vdagent: when SetClipboardData fails, set clipboard control event to stop wait
Currently, a SetClipboardData failure is followed by useless wait for timeout
(VD_CLIPBOARD_TIMEOUT_MS).

In addition, we remove the clipboard open-empty-set-close retry, which became
irrelevant with the current on_clipboard_request().
2012-12-09 11:24:27 +02:00
Arnon Gilboa
7330f5132a vdagent: remove a wrong return 2012-11-18 12:13:40 +02:00
Arnon Gilboa
a69af07da3 vdagent: set timeout for next clipboard chunk instead of complete reception
currently:
-handling client disconnect during clipboard data trasfer is buggy
-agent also timeouts on large paste from client (>10sec)

therfore:
-reduce VD_CLIPBOARD_TIMEOUT_MS to 3sec from previous clipboard chunk
-remove _clipboard_event and use _control_event(CONTROL_CLIPBOARD) instead
-use _clipboard_tick for clipboard timeout, updated on each clipboard chunk
-use cleanup_in_msg() to reset incoming message state

rhbz#833835
2012-11-14 10:50:52 +02:00
Arnon Gilboa
f71197330c vdagent: extract event_dispatcher from input_desktop_message_loop 2012-11-14 10:50:51 +02:00
Arnon Gilboa
22d25256fd vdagent: use virtio-serial, remove pipe usage 2012-11-14 10:50:51 +02:00
Arnon Gilboa
900ef2b4db vdagent: don't stop due to UIPI blocking
User Interface Privilege Isolation is usually used only for specific windows of
system security applications (anti-viruses etc.), so with this patch mouse will
be irresponsive for these windows but keep working for the rest. A complete
solution might be switching to server mouse mode while the agent is still active.
2012-09-10 10:17:23 +03:00
Arnon Gilboa
4e95b73ecf vdagent: add message_queue for messages written to pipe
This is only part of the message corruption solution.
The other part is fixing virtio-serial / spice-qemu-char throttling code.

-replace write_[lock/unlock/completion] calls with [new/enqueue]_message
-remove clipboard specific _out_msg_* class members
-remove ugly loop - while (a->_out_msg && a->write_clipboard());
-add _message_mutex for message queue
-fix pending_write race using _write_mutex
-TODO: enqueue large message without dividing it to chunks in advance

rhbz #846427
2012-09-10 09:48:46 +03:00