qrexec: adjust intervm file copy code to the new qrexec API
This commit is contained in:
parent
b5d30a9d54
commit
b87da183ce
@ -20,24 +20,33 @@ enum {
|
|||||||
};
|
};
|
||||||
|
|
||||||
unsigned long crc32_sum;
|
unsigned long crc32_sum;
|
||||||
int write_all_with_crc(int fd, void *buf, int size) {
|
int write_all_with_crc(int fd, void *buf, int size)
|
||||||
|
{
|
||||||
crc32_sum = Crc32_ComputeBuf(crc32_sum, buf, size);
|
crc32_sum = Crc32_ComputeBuf(crc32_sum, buf, size);
|
||||||
return write_all(fd, buf, size);
|
return write_all(fd, buf, size);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
char *client_flags;
|
|
||||||
void do_notify_progress(long long total, int flag)
|
void do_notify_progress(long long total, int flag)
|
||||||
{
|
{
|
||||||
FILE *progress;
|
char *du_size_env = getenv("FILECOPY_TOTAL_SIZE");
|
||||||
if (!client_flags[0])
|
char *progress_type_env = getenv("PROGRESS_TYPE");
|
||||||
|
char *saved_stdout_env = getenv("SAVED_FD_1");
|
||||||
|
if (!progress_type_env)
|
||||||
return;
|
return;
|
||||||
progress = fopen(client_flags, "w");
|
if (!strcmp(progress_type_env, "console") && du_size_env) {
|
||||||
if (!progress)
|
char msg[256];
|
||||||
return;
|
snprintf(msg, sizeof(msg), "sent %lld/%lld KB\r",
|
||||||
fprintf(progress, "%d %lld %s", getpid(), total,
|
total / 1024, strtoull(du_size_env, NULL, 0));
|
||||||
flag == PROGRESS_FLAG_DONE ? "DONE" : "BUSY");
|
write(2, msg, strlen(msg));
|
||||||
fclose(progress);
|
if (flag == PROGRESS_FLAG_DONE)
|
||||||
|
write(2, "\n", 1);
|
||||||
|
}
|
||||||
|
if (!strcmp(progress_type_env, "gui") && saved_stdout_env) {
|
||||||
|
char msg[256];
|
||||||
|
snprintf(msg, sizeof(msg), "%lld\n", total);
|
||||||
|
write(strtoul(saved_stdout_env, NULL, 0), msg,
|
||||||
|
strlen(msg));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void notify_progress(int size, int flag)
|
void notify_progress(int size, int flag)
|
||||||
@ -136,25 +145,6 @@ int do_fs_walk(char *file)
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
void send_vmname(char *vmname)
|
|
||||||
{
|
|
||||||
char buf[FILECOPY_VMNAME_SIZE];
|
|
||||||
memset(buf, 0, sizeof(buf));
|
|
||||||
strncat(buf, vmname, sizeof(buf) - 1);
|
|
||||||
if (!write_all(1, buf, sizeof buf))
|
|
||||||
exit(1);
|
|
||||||
}
|
|
||||||
|
|
||||||
char *get_item(char *data, char **current, int size)
|
|
||||||
{
|
|
||||||
char *ret;
|
|
||||||
if ((unsigned long) *current >= (unsigned long) data + size)
|
|
||||||
return NULL;
|
|
||||||
ret = *current;
|
|
||||||
*current += strlen(ret) + 1;
|
|
||||||
return ret;
|
|
||||||
}
|
|
||||||
|
|
||||||
void notify_end_and_wait_for_result()
|
void notify_end_and_wait_for_result()
|
||||||
{
|
{
|
||||||
struct result_header hdr;
|
struct result_header hdr;
|
||||||
@ -168,26 +158,40 @@ void notify_end_and_wait_for_result()
|
|||||||
|
|
||||||
/* wait for result */
|
/* wait for result */
|
||||||
if (!read_all(0, &hdr, sizeof(hdr))) {
|
if (!read_all(0, &hdr, sizeof(hdr))) {
|
||||||
exit(1); // hopefully remote has produced error message
|
exit(1); // hopefully remote has produced error message
|
||||||
}
|
}
|
||||||
if (hdr.error_code != 0) {
|
if (hdr.error_code != 0) {
|
||||||
gui_fatal("Error writing files: %s", strerror(hdr.error_code));
|
gui_fatal("Error writing files: %s",
|
||||||
|
strerror(hdr.error_code));
|
||||||
}
|
}
|
||||||
if (hdr.crc32 != crc32_sum) {
|
if (hdr.crc32 != crc32_sum) {
|
||||||
gui_fatal("File transfer failed: checksum mismatch");
|
gui_fatal("File transfer failed: checksum mismatch");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void parse_entry(char *data, int datasize)
|
char *get_abs_path(char *cwd, char *pathname)
|
||||||
{
|
{
|
||||||
char *current = data;
|
char *ret;
|
||||||
char *vmname, *entry, *sep;
|
if (pathname[0] == '/')
|
||||||
vmname = get_item(data, ¤t, datasize);
|
return strdup(pathname);
|
||||||
client_flags = get_item(data, ¤t, datasize);
|
asprintf(&ret, "%s/%s", cwd, pathname);
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
int main(int argc, char **argv)
|
||||||
|
{
|
||||||
|
int i;
|
||||||
|
char *entry;
|
||||||
|
char *cwd;
|
||||||
|
char *sep;
|
||||||
|
|
||||||
|
signal(SIGPIPE, SIG_IGN);
|
||||||
notify_progress(0, PROGRESS_FLAG_INIT);
|
notify_progress(0, PROGRESS_FLAG_INIT);
|
||||||
send_vmname(vmname);
|
|
||||||
crc32_sum = 0;
|
crc32_sum = 0;
|
||||||
while ((entry = get_item(data, ¤t, datasize))) {
|
cwd = getcwd(NULL, 0);
|
||||||
|
for (i = 1; i < argc; i++) {
|
||||||
|
entry = get_abs_path(cwd, argv[i]);
|
||||||
|
|
||||||
do {
|
do {
|
||||||
sep = rindex(entry, '/');
|
sep = rindex(entry, '/');
|
||||||
if (!sep)
|
if (!sep)
|
||||||
@ -200,53 +204,9 @@ void parse_entry(char *data, int datasize)
|
|||||||
else if (chdir(entry))
|
else if (chdir(entry))
|
||||||
gui_fatal("chdir to %s", entry);
|
gui_fatal("chdir to %s", entry);
|
||||||
do_fs_walk(sep + 1);
|
do_fs_walk(sep + 1);
|
||||||
|
free(entry);
|
||||||
}
|
}
|
||||||
notify_end_and_wait_for_result();
|
notify_end_and_wait_for_result();
|
||||||
notify_progress(0, PROGRESS_FLAG_DONE);
|
notify_progress(0, PROGRESS_FLAG_DONE);
|
||||||
}
|
|
||||||
|
|
||||||
void process_spoolentry(char *entry_name)
|
|
||||||
{
|
|
||||||
char *abs_spool_entry_name;
|
|
||||||
int entry_fd;
|
|
||||||
struct stat st;
|
|
||||||
char *entry;
|
|
||||||
int entry_size;
|
|
||||||
asprintf(&abs_spool_entry_name, "%s/%s", FILECOPY_SPOOL,
|
|
||||||
entry_name);
|
|
||||||
entry_fd = open(abs_spool_entry_name, O_RDONLY);
|
|
||||||
unlink(abs_spool_entry_name);
|
|
||||||
if (entry_fd < 0 || fstat(entry_fd, &st))
|
|
||||||
gui_fatal("bad file copy spool entry");
|
|
||||||
entry_size = st.st_size;
|
|
||||||
entry = calloc(1, entry_size + 1);
|
|
||||||
if (!entry)
|
|
||||||
gui_fatal("malloc");
|
|
||||||
if (!read_all(entry_fd, entry, entry_size))
|
|
||||||
gui_fatal("read filecopy entry");
|
|
||||||
close(entry_fd);
|
|
||||||
parse_entry(entry, entry_size);
|
|
||||||
}
|
|
||||||
|
|
||||||
void scan_spool(char *name)
|
|
||||||
{
|
|
||||||
struct dirent *ent;
|
|
||||||
DIR *dir = opendir(name);
|
|
||||||
if (!dir)
|
|
||||||
gui_fatal("opendir %s", name);
|
|
||||||
while ((ent = readdir(dir))) {
|
|
||||||
char *fname = ent->d_name;
|
|
||||||
if (fname[0] != '.') {
|
|
||||||
process_spoolentry(fname);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
closedir(dir);
|
|
||||||
}
|
|
||||||
|
|
||||||
int main()
|
|
||||||
{
|
|
||||||
signal(SIGPIPE, SIG_IGN);
|
|
||||||
scan_spool(FILECOPY_SPOOL);
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
@ -20,50 +20,24 @@
|
|||||||
#
|
#
|
||||||
#
|
#
|
||||||
|
|
||||||
if [ x"$1" = "x--without-progress" ] ; then
|
|
||||||
DO_PROGRESS=0
|
|
||||||
shift
|
|
||||||
else
|
|
||||||
DO_PROGRESS=1
|
|
||||||
fi
|
|
||||||
|
|
||||||
if [ $# -lt 2 ] ; then
|
if [ $# -lt 2 ] ; then
|
||||||
echo usage: $0 '[--without-progress] dest_vmname file [file]+'
|
echo usage: $0 '[--without-progress] dest_vmname file [file]+'
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
if [ x"$1" = "x--without-progress" ] ; then
|
||||||
|
export PROGRESS_TYPE=none
|
||||||
|
shift
|
||||||
|
else
|
||||||
|
export PROGRESS_TYPE=console
|
||||||
|
fi
|
||||||
|
|
||||||
|
|
||||||
VM="$1"
|
VM="$1"
|
||||||
shift
|
shift
|
||||||
|
|
||||||
if [ $DO_PROGRESS = 1 ] ; then
|
if [ $PROGRESS_TYPE = console ] ; then
|
||||||
SIZE=$(du --apparent-size -c "$@" | tail -1 | cut -f 1)
|
export FILECOPY_TOTAL_SIZE=$(du --apparent-size -c "$@" | tail -1 | cut -f 1)
|
||||||
fi
|
fi
|
||||||
|
|
||||||
export PROGRESS_FILE=$(mktemp)
|
exec /usr/lib/qubes/qrexec_client_vm /usr/lib/qubes/qfile-agent $VM qubes.Filecopy "$@"
|
||||||
/usr/lib/qubes/qvm-trigger-copy-to-vm $VM "$@"
|
|
||||||
while ! [ -s $PROGRESS_FILE ] ; do
|
|
||||||
sleep 0.1
|
|
||||||
done
|
|
||||||
|
|
||||||
while true ; do
|
|
||||||
read agentpid sentsize agentstatus < $PROGRESS_FILE
|
|
||||||
if [ "x"$agentstatus = x ] ; then continue ; fi
|
|
||||||
if ! [ -e /proc/$agentpid ] ; then break ; fi
|
|
||||||
if [ "x"$agentstatus = xDONE ] ; then break ; fi
|
|
||||||
CURRSIZE=$(($sentsize/1024))
|
|
||||||
if [ $DO_PROGRESS = 1 ] ; then
|
|
||||||
echo -ne "\r sent $CURRSIZE/$SIZE KB "
|
|
||||||
fi
|
|
||||||
sleep 0.4
|
|
||||||
done
|
|
||||||
|
|
||||||
rm -f $PROGRESS_FILE
|
|
||||||
if [ $DO_PROGRESS = 1 ] ; then
|
|
||||||
echo
|
|
||||||
fi
|
|
||||||
|
|
||||||
if ! [ "x"$agentstatus = xDONE ] ; then
|
|
||||||
exit 1
|
|
||||||
else
|
|
||||||
exit 0
|
|
||||||
fi
|
|
||||||
|
@ -25,19 +25,11 @@ if [ X$VM = X ] ; then exit 0 ; fi
|
|||||||
|
|
||||||
SIZE=$(du --apparent-size -c "$@" | tail -1 | cut -f 1)
|
SIZE=$(du --apparent-size -c "$@" | tail -1 | cut -f 1)
|
||||||
|
|
||||||
export PROGRESS_FILE=$(mktemp)
|
export PROGRESS_TYPE=gui
|
||||||
/usr/lib/qubes/qvm-trigger-copy-to-vm $VM "$@"
|
|
||||||
while ! [ -s $PROGRESS_FILE ] ; do
|
/usr/lib/qubes/qrexec_client_vm /usr/lib/qubes/qfile-agent \
|
||||||
sleep 0.1
|
$VM qubes.Filecopy "$@" |
|
||||||
done
|
(while read sentsize ; do
|
||||||
(while true ; do
|
|
||||||
read agentpid sentsize agentstatus < $PROGRESS_FILE
|
|
||||||
if [ "x"$agentstatus = x ] ; then continue ; fi
|
|
||||||
if ! [ -e /proc/$agentpid ] ; then break ; fi
|
|
||||||
if [ "x"$agentstatus = xdone ] ; then break ; fi
|
|
||||||
CURRSIZE=$(($sentsize/1024))
|
CURRSIZE=$(($sentsize/1024))
|
||||||
echo $((100*$CURRSIZE/$SIZE))
|
echo $((100*$CURRSIZE/$SIZE))
|
||||||
sleep 0.1
|
|
||||||
done) | zenity --progress --text="Copying files to domain: $VM..." --auto-close
|
done) | zenity --progress --text="Copying files to domain: $VM..." --auto-close
|
||||||
|
|
||||||
rm -f $PROGRESS_FILE
|
|
||||||
|
@ -27,23 +27,16 @@ SIZE=$(du --apparent-size -c "$@" | tail -1 | cut -f 1)
|
|||||||
REF=$(kdialog --progressbar "Copy progress")
|
REF=$(kdialog --progressbar "Copy progress")
|
||||||
qdbus $REF org.freedesktop.DBus.Properties.Set "" maximum $SIZE
|
qdbus $REF org.freedesktop.DBus.Properties.Set "" maximum $SIZE
|
||||||
|
|
||||||
export PROGRESS_FILE=$(mktemp)
|
export PROGRESS_TYPE=gui
|
||||||
/usr/lib/qubes/qvm-trigger-copy-to-vm $VM "$@"
|
|
||||||
while ! [ -s $PROGRESS_FILE ] ; do
|
/usr/lib/qubes/qrexec_client_vm /usr/lib/qubes/qfile-agent \
|
||||||
sleep 0.1
|
$VM qubes.Filecopy "$@" |
|
||||||
done
|
(while read sentsize ; do
|
||||||
while true ; do
|
|
||||||
read agentpid sentsize agentstatus < $PROGRESS_FILE
|
|
||||||
if [ "x"$agentstatus = x ] ; then continue ; fi
|
|
||||||
if ! [ -e /proc/$agentpid ] ; then break ; fi
|
|
||||||
if [ "x"$agentstatus = xdone ] ; then break ; fi
|
|
||||||
CURRSIZE=$(($sentsize/1024))
|
CURRSIZE=$(($sentsize/1024))
|
||||||
qdbus $REF org.freedesktop.DBus.Properties.Set "" value $CURRSIZE
|
qdbus $REF org.freedesktop.DBus.Properties.Set "" value $CURRSIZE
|
||||||
sleep 0.4
|
done)
|
||||||
done
|
|
||||||
|
|
||||||
qdbus $REF close
|
qdbus $REF close
|
||||||
rm -f $PROGRESS_FILE
|
|
||||||
# we do not want a dozen error messages, do we
|
# we do not want a dozen error messages, do we
|
||||||
# if ! [ "x"$agentstatus = xDONE ] ; then
|
# if ! [ "x"$agentstatus = xDONE ] ; then
|
||||||
# kdialog --sorry 'Abnormal file copy termination; see /var/log/qubes/qrexec.xid.log in dom0 for more details'
|
# kdialog --sorry 'Abnormal file copy termination; see /var/log/qubes/qrexec.xid.log in dom0 for more details'
|
||||||
|
@ -1,46 +0,0 @@
|
|||||||
#!/bin/sh
|
|
||||||
#
|
|
||||||
# The Qubes OS Project, http://www.qubes-os.org
|
|
||||||
#
|
|
||||||
# Copyright (C) 2010 Rafal Wojtczuk <rafal@invisiblethingslab.com>
|
|
||||||
#
|
|
||||||
# This program is free software; you can redistribute it and/or
|
|
||||||
# modify it under the terms of the GNU General Public License
|
|
||||||
# as published by the Free Software Foundation; either version 2
|
|
||||||
# of the License, or (at your option) any later version.
|
|
||||||
#
|
|
||||||
# This program is distributed in the hope that it will be useful,
|
|
||||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
# GNU General Public License for more details.
|
|
||||||
#
|
|
||||||
# You should have received a copy of the GNU General Public License
|
|
||||||
# along with this program; if not, write to the Free Software
|
|
||||||
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
|
||||||
#
|
|
||||||
#
|
|
||||||
|
|
||||||
if [ $# -lt 2 ] ; then
|
|
||||||
echo usage: $0 'vmname file [file]*'
|
|
||||||
exit 1
|
|
||||||
fi
|
|
||||||
|
|
||||||
FILECOPY_SPOOL=/home/user/.filecopyspool
|
|
||||||
if ! [ -e $FILECOPY_SPOOL ] ; then
|
|
||||||
mkdir $FILECOPY_SPOOL
|
|
||||||
fi
|
|
||||||
|
|
||||||
REQ_FILE_TMP=$FILECOPY_SPOOL/.req.$$
|
|
||||||
echo -ne "$1""\x00" > $REQ_FILE_TMP
|
|
||||||
echo -ne "$PROGRESS_FILE""\x00" >> $REQ_FILE_TMP
|
|
||||||
|
|
||||||
shift
|
|
||||||
for FILE in "$@" ; do
|
|
||||||
if ! [ "X""${FILE:0:1}" = X/ ] ; then
|
|
||||||
FILE="$PWD"/"$FILE"
|
|
||||||
fi
|
|
||||||
echo -ne "$FILE""\x00" >> $REQ_FILE_TMP
|
|
||||||
done
|
|
||||||
|
|
||||||
mv $REQ_FILE_TMP $FILECOPY_SPOOL/req.$$
|
|
||||||
echo -n FCPR > /var/run/qubes/qrexec_agent
|
|
@ -79,7 +79,6 @@ cp qvm-copy-to-vm $RPM_BUILD_ROOT/usr/bin
|
|||||||
mkdir -p $RPM_BUILD_ROOT/usr/lib/qubes
|
mkdir -p $RPM_BUILD_ROOT/usr/lib/qubes
|
||||||
cp qvm-copy-to-vm2.kde $RPM_BUILD_ROOT/usr/lib/qubes
|
cp qvm-copy-to-vm2.kde $RPM_BUILD_ROOT/usr/lib/qubes
|
||||||
cp qvm-copy-to-vm2.gnome $RPM_BUILD_ROOT/usr/lib/qubes
|
cp qvm-copy-to-vm2.gnome $RPM_BUILD_ROOT/usr/lib/qubes
|
||||||
cp qvm-trigger-copy-to-vm $RPM_BUILD_ROOT/usr/lib/qubes
|
|
||||||
cp ../qrexec/qrexec_agent $RPM_BUILD_ROOT/usr/lib/qubes
|
cp ../qrexec/qrexec_agent $RPM_BUILD_ROOT/usr/lib/qubes
|
||||||
cp ../qrexec/qrexec_client_vm $RPM_BUILD_ROOT/usr/lib/qubes
|
cp ../qrexec/qrexec_client_vm $RPM_BUILD_ROOT/usr/lib/qubes
|
||||||
cp ../qrexec/qubes_rpc_multiplexer $RPM_BUILD_ROOT/usr/lib/qubes
|
cp ../qrexec/qubes_rpc_multiplexer $RPM_BUILD_ROOT/usr/lib/qubes
|
||||||
@ -89,6 +88,7 @@ mkdir -p $RPM_BUILD_ROOT/%{kde_service_dir}
|
|||||||
cp qvm-copy.desktop qvm-dvm.desktop $RPM_BUILD_ROOT/%{kde_service_dir}
|
cp qvm-copy.desktop qvm-dvm.desktop $RPM_BUILD_ROOT/%{kde_service_dir}
|
||||||
mkdir -p $RPM_BUILD_ROOT/mnt/removable
|
mkdir -p $RPM_BUILD_ROOT/mnt/removable
|
||||||
mkdir -p $RPM_BUILD_ROOT/etc/qubes_rpc
|
mkdir -p $RPM_BUILD_ROOT/etc/qubes_rpc
|
||||||
|
cp qubes.Filecopy $RPM_BUILD_ROOT/etc/qubes_rpc
|
||||||
|
|
||||||
|
|
||||||
mkdir -p $RPM_BUILD_ROOT/etc/X11
|
mkdir -p $RPM_BUILD_ROOT/etc/X11
|
||||||
@ -144,7 +144,6 @@ rm -rf $RPM_BUILD_ROOT
|
|||||||
/usr/lib/qubes/dvm_file_editor
|
/usr/lib/qubes/dvm_file_editor
|
||||||
%{kde_service_dir}/qvm-copy.desktop
|
%{kde_service_dir}/qvm-copy.desktop
|
||||||
%{kde_service_dir}/qvm-dvm.desktop
|
%{kde_service_dir}/qvm-dvm.desktop
|
||||||
/usr/lib/qubes/qvm-trigger-copy-to-vm
|
|
||||||
/usr/lib/qubes/qrexec_agent
|
/usr/lib/qubes/qrexec_agent
|
||||||
/usr/lib/qubes/qrexec_client_vm
|
/usr/lib/qubes/qrexec_client_vm
|
||||||
/usr/lib/qubes/qubes_rpc_multiplexer
|
/usr/lib/qubes/qubes_rpc_multiplexer
|
||||||
@ -153,6 +152,7 @@ rm -rf $RPM_BUILD_ROOT
|
|||||||
/usr/lib/qubes/qfile-unpacker
|
/usr/lib/qubes/qfile-unpacker
|
||||||
%dir /mnt/removable
|
%dir /mnt/removable
|
||||||
%dir /etc/qubes_rpc
|
%dir /etc/qubes_rpc
|
||||||
|
/etc/qubes_rpc/qubes.Filecopy
|
||||||
/usr/bin/qubes_timestamp
|
/usr/bin/qubes_timestamp
|
||||||
%dir /home_volatile
|
%dir /home_volatile
|
||||||
%attr(700,user,user) /home_volatile/user
|
%attr(700,user,user) /home_volatile/user
|
||||||
|
Loading…
Reference in New Issue
Block a user