Commit Graph

34 Commits

Author SHA1 Message Date
Frediano Ziglio
2d6bcd9181 file_xfer: Return detailed error for invalid filename
A literal constant is used for error type as the project is not
dependent on glib2 and that Visual Studio and CMake are supported
so it would make the compilation on some environment more complicated
than actually is just for a constant.

Signed-off-by: Frediano Ziglio <fziglio@redhat.com>
Acked-by: Kevin Pouget <kpouget@redhat.com>
Acked-by: Victor Toso <victortoso@redhat.com>
2020-05-25 15:29:49 +01:00
Frediano Ziglio
dd05463f9b Use SPICE_N_ELEMENTS instead of a constant for file_path size
Allows to easily change the size if needed

Signed-off-by: Frediano Ziglio <fziglio@redhat.com>
2020-04-24 11:22:37 +01:00
Frediano Ziglio
b4776f4291 file_xfer: Return detailed error for no space
Signed-off-by: Frediano Ziglio <fziglio@redhat.com>
2020-04-24 10:33:34 +01:00
Frediano Ziglio
a914784295 vdagent: Allow to return detailed message for file transfer
Reuse AgentFileXferStatusMessageFull and agent_prepare_filexfer_status

Signed-off-by: Frediano Ziglio <fziglio@redhat.com>
2020-04-24 10:33:34 +01:00
Frediano Ziglio
f920c23e2e file_xfer: Remove a warning
Avoids:

warning C4267: '=': conversion from 'size_t' to 'int', possible loss of data

Signed-off-by: Frediano Ziglio <fziglio@redhat.com>
2020-03-23 12:36:55 +00:00
Uri Lublin
1da442ad73 file-xfer: handle_start: use snprintf instead of sprintf_s
When building with older mingw, sprintf_s does not
always work as expected, but snprintf does.

Also it's more consistent in the file.

Note that when building with VS, snprintf becomes sprintf_s

Related: rhbz#1410181

Signed-off-by: Uri Lublin <uril@redhat.com>
Acked-by: Frediano Ziglio <fziglio@redhat.com>
2019-12-06 09:42:39 +00:00
Frediano Ziglio
9207d821d2 file_xfer: Open Download directory after a file transfer is finished
Have the same behaviour of Linux machines.
The directory is not opened again and again, only is not already
opened.
This is done checking the directory opened in explorer.

Signed-off-by: Frediano Ziglio <fziglio@redhat.com>
2019-11-18 10:30:14 +00:00
Frediano Ziglio
8064ae397a file_xfer: Save files in Downloads directory
Signed-off-by: Frediano Ziglio <fziglio@redhat.com>
2019-11-07 16:13:52 +00:00
Frediano Ziglio
5fbeb1af4e file_xfer: Separate code to get download directory location
Allows to reuse code to get download directory.

Signed-off-by: Frediano Ziglio <fziglio@redhat.com>
2019-11-07 16:12:35 +00:00
Frediano Ziglio
7b0c48b15b file_xfer: Use shared_ptr to simplify memory management
Clear automatically tasks items.

Signed-off-by: Frediano Ziglio <fziglio@redhat.com>
Acked-by: Christophe Fergeau <cfergeau@redhat.com>
2018-05-28 16:27:12 +01:00
Frediano Ziglio
aefc220c02 file_xfer: Use destructor for FileXferTask
Limit too much manual work.
By default delete the file, unless success() is called.

Signed-off-by: Frediano Ziglio <fziglio@redhat.com>
Acked-by: Christophe Fergeau <cfergeau@redhat.com>
2018-05-28 16:27:12 +01:00
Frediano Ziglio
e2ced9f094 Avoid to use names with reserved characters.
Some characters are reserved and should not be used in Windows
independently by the file system used.
This avoid to use paths in the filename which could lead to some
nasty hacks (like names like "..\hack.txt").
The return statement cause the file transfer to be aborted with
VD_AGENT_FILE_XFER_STATUS_ERROR as status.

":" is used to separate filenames from stream names and can be used
to create hidden streams. Also is used for drive separator (A:)
or device names (NUL:).
"/" and "\" are reserved for components (directory, filename, drive,
share, server) separators.
"*" and "?" are wildcards (which on Windows are supported by
different APIs too).
"<", ">", """ and "|" are reserved for shell usage.

More information on "Naming Files, Paths, and Namespaces" page at
https://msdn.microsoft.com/en-us/library/windows/desktop/aa365247(v=vs.85).aspx

This fixes also https://bugzilla.redhat.com/show_bug.cgi?id=1520393.

Signed-off-by: Frediano Ziglio <fziglio@redhat.com>
Acked-by: Christophe Fergeau <cfergeau@redhat.com>
2018-05-25 14:04:49 +01:00
Jakub Janků
3b1d9ab0a0 Use sprintf_s instead of sprintf to not crash
Acked-by: Frediano Ziglio <fziglio@redhat.com>
2017-05-18 11:03:55 +01:00
Frediano Ziglio
241425b7da Support file transfer for existing files
Previously, if the user attempted to transfer a file that had the same
name as a file that already exists on the guest, we would just fail the
transfer. This patch tries to match the behavior of the linux vdagent
where we try to append an integer onto the name of the new file to make
it unique. For example, if you tried to transfer 'file.doc' to the guest
and that file already existed, it would try to create 'file (1).doc'
instead. If that also failed, it would attempt 'file (2).doc', etc, up
to 63.

Resolves: rhbz#1410181
Acked-by: Jonathon Jongsma <jjongsma@redhat.com>
2017-05-02 14:49:36 -05: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
Victor Toso
8ae139f363 vdagent: remove whitespaces
Acked-by: Frediano Ziglio <fziglio@redhat.com>
2016-08-12 09:41:41 +01:00
Victor Toso
d6919c6c07 file-transfer: fix typo
Signed-off-by: Victor Toso <victortoso@redhat.com>
Acked-by: Frediano Ziglio <fziglio@redhat.com>
2016-08-11 14:34:32 +01:00
Frediano Ziglio
7fb2e2becc vdagent-win: Fix compile under MingW
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>
2015-04-30 14:01:01 +02:00
Frediano Ziglio
ae4a4f0035 Use wide characters in drap&drop code
This allows username to contain any extended characters (username is
embedded in the directory name).

Signed-off-by: Frediano Ziglio <fziglio@redhat.com>
2015-04-30 13:21:48 +02:00
Christophe Fergeau
5aa999320f Use new vdagent_{strncpy,strcat}_s helpers 2015-03-20 10:45:12 +01:00
Uri Lublin
d1c8d152f4 g_key_get_string: use size_t for pointer difference
The 64 bit Visual Studio build complains that:
  .\file_xfer.cpp(223) : warning C4244:
    '=' : conversion from '__int64' to 'unsigned int', possible loss of data
2014-12-30 17:42:17 +02:00
Uri Lublin
88b9b74d95 Fix building with Visual Studio (inttypes.h)
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.
2014-12-30 17:17:24 +02:00
Uri Lublin
eb276f4b45 Fix compiler warning (missing backslash in FileXfer::handle_start)
Visual Studio complains:
vdagent\file_xfer.cpp(85) : warning C4129: '%' : unrecognized character escape sequence

Replace "%s\%s" with "%s\\%s"
2014-12-30 17:16:53 +02:00
Cody Chan
6c070843cb Fix g_key_get_string() failure when string contains '['
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!
2014-11-13 16:52:19 +01:00
Cody Chan
21b79679c1 Fix dragging of files with CJK characters in name
I submitted a patch several months ago about this issue,
here http://lists.freedesktop.org/archives/spice-devel/2014-February/016158.html
I check it again, and find that the value of
g_key_file_to_data(keyfile,...) is always utf-8, for the value of
g_uri_list_extract_uris() is utf8 urlencode.

So the display problem is caused by vd_agent, but how it displays
depends on the language of system, the following two screenshots show
the difference:

http://int64ago-tmp.qiniudn.com/guest-Chinese.png
http://int64ago-tmp.qiniudn.com/guest-English.png
2014-11-13 16:52:18 +01:00
Uri Lublin
4335b0d43a vdagent: file_xfer: make g_key_get_string safer
By providing the size of the destination string buffer.
2013-11-13 10:39:57 +02:00
Uri Lublin
066f614cee vdagent: file-xfer: make user desktop the target directory
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.
2013-11-13 10:39:47 +02:00
Uri Lublin
71193f6581 file_xfer: create file with user privileges 2013-11-13 10:39:37 +02:00
Marc-André Lureau
4b9e9b1d28 Remove usage of more _s functions
Even before this change, it should have handled error conditions. We'd
be better off allocating those strings and failing on io op later on.
2013-07-17 21:20:47 +02:00
Marc-André Lureau
492ee05a6b Replace sscanf_s by sscanf
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.
2013-07-17 20:45:22 +02:00
Marc-André Lureau
b9d6baec2d Fix task could be used uninitialized 2013-07-17 20:45:21 +02:00
Marc-André Lureau
462295d9f8 Fix invalid print format for uint64_t values
format '%lu' expects argument of type 'long unsigned int', but argument
9 has type 'uint64_t
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