For some reason this call does not behave correctly.
This was causing vdservice to fail to run the agent if compiled
with MingW.
Provide a proper swprintf_s replacement.
Signed-off-by: Frediano Ziglio <fziglio@redhat.com>
Acked-by: Victor Toso <victortoso@redhat.com>
The function "SystemParametersInfo" expects the size of the
buffer in characters. When wchar is used instead of char - two
bytes instead of one byte per character -, then "sizeof" returns wrong
number of characters (twice as much). A suitable solution would be to use
SPICE_N_ELEMENTS.
Based on patch by Sandy Stutsman <sstutsma@redhat.com>
Signed-off-by: Dmitry Fleytman <dfleytma@redhat.com>
Signed-off-by: Sameeh Jubran <sameeh@daynix.com>
>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>
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
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
When a Windows guest uses the "Set Resolution" applet to change
resolutions and/or monitor positions, this escape sends the new monitor
configurations to the client via a new QXL driver escape.
Addresses: https://bugzilla.redhat.com/show_bug.cgi?id=1202419
Fixes https://bugzilla.redhat.com/show_bug.cgi?id=1174129.
Windows considers the monitor positioned at (0,0) to be primary. VDAgent
normalizes the monitor positions so that there are no negative
coordinates. If the normalized positions are passed to the Windows APIs,
the leftmost monitor will always be set to primary. We need to keep
track of the original primary monitor and its normalized position to be
able to adjust the coordinates that are passed to Windows.
Including directly shlobj.h in some MingW environment lead to some missing
definitions error. Including windows.h before fix the problem.
Signed-off-by: Frediano Ziglio <fziglio@redhat.com>
This allows username to contain any extended characters (username is
embedded in the directory name).
Signed-off-by: Frediano Ziglio <fziglio@redhat.com>
Having this file pregenerated is useful if one wants to use it to
generate a package from tarball with:
tar xf vdagent-win-$version.tar.xz mingw-virt-viewer.spec
rpmbuild mingw-virt-viewer.spec
This is more convenient than extracting the whole tarball, and configuring
it in order to generate mingw-virt-viewer.spec
We currently have macros silently replacing use of strncpy/strcat with
strcpy_s/strcat_s when using MSVC++. However, these macros can have
unexpected effects as they use sizeof to find out the maximum size of
the destination string. This is a very significant difference from
strncpy/strcat, which can lead to subtle bugs as the behaviour is
different between mingw and MSVC++.
Now that we have our implementation of strcpy_s/strcat_s, we don't need
these #defines.
These security functions are available when building with MSVC++. With
mingw, they can be used at build time, but their availability will
depend on the version of MSVCRT the user has installed on their system.
In particular, a default install of Windows XP will not have a new
enough MSVCRT version, causing runtime failures as the binary built with
mingw and using strcat_s will not be able to find the necessary entry
point in the MSVCRT runtime.
This commit adds some strcat_s/strcpy_s-like functions used with mingw
which will always be available.
The 64 bit Visual Studio build complains that:
.\file_xfer.cpp(223) : warning C4244:
'=' : conversion from '__int64' to 'unsigned int', possible loss of data
This is a follow-up to commits 492ee05a6b and 4b9e9b1d28
Visual Studio complains:
.\file_xfer.cpp(90) : warning C4996: 'strcat': This function or variable
may be unsafe. Consider using strcat_s instead.
To disable deprecation, use _CRT_SECURE_NO_WARNINGS.
See online help for details.
And a similar complain for sscanf.
Replace them with the secure function when compiling with Visual Studio.
Note that the size provided is sizeof(d), which means all calls to
sscanf and strcat must be done with the first param (destination) being
an array and not a pointer.
Visual Studio complains:
vdagent\file_xfer.h(28) : warning C4996: 'strncpy': This function or variable may
Consider using strncpy_s instead.
To disable deprecation, use _CRT_SECURE_NO_WARNINGS.
See online help for details.
Replace strncpy with strcpy_s when building with Visual Studio.
Adjust parameter order and difference in meaning of length:
- length param is last in strncpy and second in strcpy_s
- many calls to strncpy are given length param n-1, as
strncpy does not guarantee that destination ends with '\0'
- it's safer to set length param not larger than sizeof(d)
(assuming d is an array not a pointer)
Trying to use strcpy_s for both Visual Studio and mingw
failed as strcpy_s is missing from the default msvcrt.dll
on WinXP (See OLDMSVCRT in common/vdcommon.h).
This commit is an addition to 4b9e9b1d28
Building with Visual Studio breaks as snprintf is not implemented:
vdagent\file_xfer.cpp(198) : error C3861: 'snprintf': identifier not found
Replace it with sprintf_s for Visual Studio.
Trying to use sprintf_s for both Visual Studio and mingw
failed for mingw64 (build succeeds but runtime error appears).
As a followup of commit 462295d9f8.
Building with Visual Studio, fails as there is no inttypes.h file:
vdagent\file_xfer.cpp(21) : fatal error C1083: Cannot open
include file: 'inttypes.h': No such file or directory
This commit prevents including inttypes.h when building with Visual Studio,
and defines PRIu64 that is defined in inttypes.h for mingw compiler.
Fixes the following error:
====
In file included from vdagent/vdagent.cpp:18:0:
./common/vdcommon.h:51:0: warning: "_ftime_s" redefined
#define _ftime_s(timeb) _ftime(timeb)
^
In file included from /usr/x86_64-w64-mingw32/sys-root/mingw/include/sys/timeb.h:124:0,
=====
Fixes compiler warning that starts with:
In file included from vdagent/as_user.cpp:19:0:
vdagent/as_user.h: In constructor 'AsUser::AsUser(DWORD)':
vdagent/as_user.h:35:10: warning: 'AsUser::_started' will be initialized after [-Wreorder]
bool _started;
In vd_agent/file_xfer.cpp is implemented a simple g_key_get_string,
but when dragging a file with a name containing '[' (like te[st.txt),
it will fail.
From source code,
>next_group_pos = strstr(group_pos + strlen(group_pfx), "[");
> if (next_group_pos && key_pos > next_group_pos) return false;
we know that it tries to find the end of current group by '[' label,
if we drag a file named te[st.txt, the key_string will be like:
[vdagent-file-xfer]
name=te[st.txt
size=10
so, it will fail when meta parsing and returns the
VD_AGENT_FILE_XFER_STATUS_ERROR message.
Here's the elegant method Christophe proposed and test ok, thanks to
him again!
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
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.
Before, the target directory was a public one (for all users),
as file creation was not done with user privileges.
Now that the file is created with user privileges, it's
better to make the user desktop the target directory.
The class calls Impersonate upon begin(), and Revert
upon end() or destruction.
The user is the current user that is logged in.
create mode 100644 vdagent/as_user.cpp
create mode 100644 vdagent/as_user.h
vdagent/display_setting.cpp:469:50: warning: cast to pointer from
integer of different size [-Wint-to-pointer-cast]
if (!SystemParametersInfo(action, 0, (PVOID)param, 0)) {
vdagent/desktop_layout.cpp:121:763: warning: format '%u' expects
argument of type 'unsigned int', but argument 8 has type
'std::vector<DisplayMode*>::size_type {aka long long unsigned int}'
[-Wformat=]
The _s functions need a recent msvcrt version, not shipped in XP by
default.
Furthermore, it appears that their sscanf_s usage was missing the extra
buffer size argument.
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]