Commit Graph

54 Commits

Author SHA1 Message Date
Frediano Ziglio
981b5f0dd1 build: Do not generate CMake config.h in source directory
Allows to build out-of-tree and have a clean working directory.
Autoconf used to work with out-of-tree and "config.h" in the
build directory as a "common" directory in the build directory
was created, so including "../config.h" in version.rc and having
"-I $(top_builddir)/common" used to work.
CMake does not create "common" under the build directory so the
"../config.h" inclusion fails.

Signed-off-by: Frediano Ziglio <fziglio@redhat.com>
2019-12-06 09:42:52 +00:00
Frediano Ziglio
7aa46954fd vdlog: Fix compatibility with MSVC
_wstat64 documentation states that we should include sys/types.h
and sys/stat.h.

Signed-off-by: Frediano Ziglio <fziglio@redhat.com>
2019-12-06 09:42:52 +00:00
Frediano Ziglio
dc185029ff vdcommon: Do not use GetVersionEx to get Windows version
GetVersionEx was deprecated by Microsoft in favour of utilities
in versionhelpers.h.
The new function returns the same results as:
- GetVersionEx returns maximum 6.2 version and also 6.0 version
  is Vista, not Windows 7 so SYS_VER_WIN_7_CLASS was returned
  for all system from Windows Vista;
- We don't support version earlier than Windows XP and no Windows
  versions had version >= 5.2 and < 6.0 so SYS_VER_WIN_XP_CLASS
  was returned from Windows XP;
- we don't support any system before Windows XP.

Tested under Windows XP, 7 and 10.

Signed-off-by: Frediano Ziglio <fziglio@redhat.com>
2019-12-03 17:43:17 +00:00
Frediano Ziglio
615cd463e0 vdlog: Use _wstat64 instead of GetFileSize
This has different advantages:
- code is shorter and more readable;
- does not need to open the file and close;
- works on files bigger than 4gb.

Signed-off-by: Frediano Ziglio <fziglio@redhat.com>
Acked-by: Victor Toso <victortoso@redhat.com>
2019-11-21 14:48:32 +00:00
Frediano Ziglio
4d4977611f Remove some unused definitions
_ftime_s, vdagent_strcat_s and vdagent_strcpy_s are not used.
Code is using different string functions.

Signed-off-by: Frediano Ziglio <fziglio@redhat.com>
Acked-by: Victor Toso <victortoso@redhat.com>
2019-04-30 09:22:11 +01:00
Frediano Ziglio
9ddddf205f vdlog: Use GetLocalTime instead of multiple C functions
The GetLocalTime function already returns all information we
need for the log, no needs to call multiple C functions.

Signed-off-by: Frediano Ziglio <fziglio@redhat.com>
Acked-by: Jonathon Jongsma <jjongsma@redhat.com>
2018-07-08 20:19:21 +01:00
Frediano Ziglio
df20de186c vdlog: Factor our a "logf" function to avoid long "LOG" macro
Signed-off-by: Frediano Ziglio <fziglio@redhat.com>
Acked-by: Jonathon Jongsma <jjongsma@redhat.com>
2018-07-08 20:19:21 +01:00
Frediano Ziglio
c4b8c5349e vdlog: Remove the lookup table for log types
As log type is passed as constant in some macros and the lockup
is basically using this name without the prefix pass to the macro
the name without the prefix.

Signed-off-by: Frediano Ziglio <fziglio@redhat.com>
Acked-by: Jonathon Jongsma <jjongsma@redhat.com>
2018-07-08 20:19:21 +01:00
Frediano Ziglio
531dd85f60 Reuse spice-protocol macros instead of defining new ones for alignment
Signed-off-by: Frediano Ziglio <fziglio@redhat.com>
Acked-by: Jonathon Jongsma <jjongsma@redhat.com>
2018-06-28 02:17:32 +01:00
Frediano Ziglio
d827d0ab51 Add a test for logging functions
Signed-off-by: Frediano Ziglio <fziglio@redhat.com>
Acked-by: Christophe Fergeau <cfergeau@redhat.com>
2017-07-26 16:16:16 +01:00
Frediano Ziglio
cc1534a3a0 Expand PRINT_LINE macros
This complicated macro was used as an helper for LOG macro
which expand PRINT_LINE macro twice. Now that LOG expand PRINT_LINE
only once there's no need to have this macro which make logging code
more complicated.

Signed-off-by: Frediano Ziglio <fziglio@redhat.com>
Acked-by: Christophe Fergeau <cfergeau@redhat.com>
2017-07-26 15:35:12 +01:00
Frediano Ziglio
6a60c1dccc Make VDLog::printf static
VDLog::printf is called only using a VDLog pointer.
Since this class is a singleton, there can only be one instance of it,
so LOG() does not really need to deal with it, VDLog::printf can
do that instead.
This simplifies LOG macros by not having to choose between printf and
VDLog::printf.

The manual GNU __attribute__ is used as the format to use is
not the standard __printf__ format used in SPICE_GNUC_PRINTF
but you need to use the gnu_printf format. For instance the "%llu"
syntax is accepted by gnu_print format but not by __printf__ one.
MinGW C++ by default uses gnu_printf format for all formatting
functions.

Signed-off-by: Frediano Ziglio <fziglio@redhat.com>
Acked-by: Christophe Fergeau <cfergeau@redhat.com>
2017-07-26 15:35:01 +01:00
Frediano Ziglio
78099ae2bf log: add comment to make code clearer
Signed-off-by: Frediano Ziglio <fziglio@redhat.com>
Acked-by: Christophe Fergeau <cfergeau@redhat.com>
2017-07-24 16:45:38 +01:00
Frediano Ziglio
1a0bc10cbe log: rewrite log_version using config.h definitions
Instead of having to get the version information from the
executable resources get from the build configuration file.
The same version is used to build the version information
resource.
This also remove a bug in log_version where "throw" statements
were used to raise again a not existing exception on case
of failures.

Signed-off-by: Frediano Ziglio <fziglio@redhat.com>
Acked-by: Christophe Fergeau <cfergeau@redhat.com>
2017-07-24 13:42:01 +01:00
Frediano Ziglio
8f47080fa8 Remove small memory leak in log_version
log_version() declares 2 info_buf variables, the inner one is used to
hold allocated memory, but then we free the outer one, which is NULL.

Signed-off-by: Frediano Ziglio <fziglio@redhat.com>
Acked-by: Christophe Fergeau <cfergeau@redhat.com>
2017-07-22 09:34:36 +01:00
Frediano Ziglio
61830ede2d Avoid log_level warning using a static const
Compiler warnings for unused static variable.
Not for constants.

Signed-off-by: Frediano Ziglio <fziglio@redhat.com>
Acked-by: Pavel Grunt <pgrunt@redhat.com>
2017-07-10 13:20:35 +01:00
Frediano Ziglio
a814ff95c1 build: Automatically update version/copyright in version.rc
The versions/copyright in version.rc are very outdated.
Updating them automatically at configure time should ensure they are
updated more often.
Looks a bit weird to distribute config.h file however in this
case it contain only version information and the file is
useful to compile under Windows.

This patch is inspired by a work of Christophe Fergeau

Signed-off-by: Frediano Ziglio <fziglio@redhat.com>
Acked-by: Christophe Fergeau <cfergeau@redhat.com>
2016-11-17 13:17:20 +00:00
Frediano Ziglio
4fbd7b485e Move common resource code to a common file
Allows to reuse code. Differences between the two
version information are managed using additional defines
in the top rc files.

Signed-off-by: Frediano Ziglio <fziglio@redhat.com>
Acked-by: Christophe Fergeau <cfergeau@redhat.com>
2016-11-17 13:17:18 +00: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
71f6d00a78 Use enumeration for supported_system_version return type
Signed-off-by: Frediano Ziglio <fziglio@redhat.com>
Acked-by: Victor Toso <victortoso@redhat.com>
2016-08-10 11:13:39 +01:00
Frediano Ziglio
9ab74bb67a Fix swprintf_s call under MingW
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>
2016-08-10 11:13:15 +01:00
Christophe Fergeau
20d66f85ce Remove MSVC++ strncpy/strcat fallbacks
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.
2015-03-20 10:45:12 +01:00
Christophe Fergeau
a4f082b0d1 Add strcat_s/strcpy_s fallbacks
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.
2015-03-20 10:45:12 +01:00
Uri Lublin
e04ffbc608 Fix Visual Studio compiler warning (strcat and sscanf)
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.
2014-12-30 17:42:17 +02:00
Uri Lublin
d752a5b6e0 Fix Visual Studio compiler warning (strncpy)
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).
2014-12-30 17:37:26 +02:00
Uri Lublin
c76e541bba Fix building with Visual Studio (snprintf)
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).
2014-12-30 17:17:25 +02:00
Uri Lublin
cf747c07e6 vdcommon.h: consolidate defines under OLDMSVCRT 2014-12-30 17:17:24 +02:00
Uri Lublin
c678c4f26b vdcommon.h: do not redefine _ftime_s
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,
=====
2014-12-30 17:17:24 +02:00
Uri Lublin
a6383f29dc vdcommon.h: add comment about OLDMSVCRT 2014-12-30 17:17:24 +02: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
877e52386e vdservice: extract supported_system_version() to vdcommon
rhbz #919451 preparation
2013-03-18 12:54:04 +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
Christophe Fergeau
05af7a9786 Add OLDMSVCRT fallback for _ftime_s
Aliasing _ftime_s to _ftime when OLDMSVCRT is defined makes it
possible to remove the timestamp-less implementation of LOG()
while still getting a binary working on Windows XP. I've tested
this with a MinGW build, hopefully this won't break VC++ builds...
2013-01-22 12:43:51 +01:00
Christophe Fergeau
1e543873ea vdlog: Get swprinft_s definition from vdcommon.h
vdlog.cpp has an #ifdef check for OLDMSVC to choose between using
swprintf or swprintf_s. Since vdcommon.h provides a compat #define
for swprintf_s when OLDMSVC is set, it's better to use this one.
2013-01-22 12:43:44 +01:00
Arnon Gilboa
5f1e7630ae vdagent: remove pipe common defs 2012-11-14 10:50:51 +02:00
Marc-André Lureau
60e850c6e4 mingw: don't use *_s msvcrt variants
Apparently, it comes with a recent version of C library (msvcrt90?),
but I don't know if we can/should ship also a MS dll. Probably it used
to work with an inlined version with VS headers.

The build can be tweaked to use the -non-_s variant with -DOLDMSVCRT
CFLAGS.
2012-05-24 13:55:31 +02:00
Christophe Fergeau
84628d5475 mingw: workaround _ftime_s bug
mingw has a _ftime_s prototype in its headers, but no corresponding
symbol available at link time. Workaround this issue for now by
 #defining it to _ftime. This is untested on win64 where the workaround
may not be needed.
2012-03-01 12:59:05 +01:00
Christophe Fergeau
5e55cc27b2 mingw: use gcc attributes for struct packing
It automatically chooses between using the gcc construct or the
visual-c++ construct at compile-time.
2012-02-23 19:03:25 +01:00
Christophe Fergeau
89422a3a41 mingw: disable vc-specific #pragma 2012-02-23 19:03:25 +01:00
Christophe Fergeau
a343a280a9 mingw: don't redefine SIZE_MAX
mingw already has SIZE_MAX defined so don't try to redefine it to
avoid a warning.
2012-02-23 19:03:25 +01:00
Christophe Fergeau
df3fe9cb90 mingw: fix format string warnings
Most of them are caused by not using %lu to print a DWORD (which
is an unsigned long).
2012-02-23 19:03:25 +01:00
Arnon Gilboa
017482d779 vdlog: change log times to human readable date & time rhbz#672828
-use RHEV log format
-add log levels & macros
-remove LOG_ENABLED ifdefs
2011-11-21 14:10:55 +02:00
Alon Levy
0f92cbea70 vdi_port refactor: introduce old pci_vdi_port
This patch is a little dirty due to EOL convertion to windows format.

 + add pci_vdi_port with PCIVDIPort taken from last commit before
  changing to virtio-serial (a17ccbf323)
 + move handle_error to VDIPort (identical in VIRTIOVDIPort and PCIVDIPort)
 + make VDService create first a virtio, then init, the pci, then init,
  stopping when the first init succeeds, and reporting to log which was
  created.
2011-01-11 17:18:47 +02:00
Arnon Gilboa
875cc05292 Revert "vdservice: add missing vdcommon.cpp"
This reverts commit 53b32d4db3 which becomes irrelevant due to previous revert.
2010-11-09 20:52:52 +02:00
Arnon Gilboa
35d1b7c835 Revert "vdservice: don't start when no qxl device present"
This reverts commit 349e6a5bf8 which breaks vsdervice on Windows 7
2010-11-09 20:50:21 +02:00
Alon Levy
53b32d4db3 vdservice: add missing vdcommon.cpp 2010-08-29 15:07:47 +03:00
Alon Levy
349e6a5bf8 vdservice: don't start when no qxl device present 2010-08-24 14:56:28 +03:00
Yonit Halperin
5833dc9760 Controlling Windows display settings (e.g., wallpaper, UI effects and font smoothing)
The configuration is received from Spice client.
The main usage of this option is for disabling display features in order to accelerate Spice performance over limited network connections.
2010-08-24 10:36:05 +03:00
Arnon Gilboa
81cd5620d2 vdservice/vdagent: fixes leading to clipboard (aka large) message handling
-add VDAgent::dispatch_message()
-in VDAgent::read_completion() handle multi-chunk msgs
-fix chunk size bug in VDService::handle_pipe_data()
-add size to VDPipeMessage
2010-08-23 18:54:25 +03:00