diff --git a/appvm/qfile-agent.c b/appvm/qfile-agent.c index 530bbb2d..4b37738f 100644 --- a/appvm/qfile-agent.c +++ b/appvm/qfile-agent.c @@ -20,24 +20,33 @@ enum { }; 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); return write_all(fd, buf, size); } - -char *client_flags; void do_notify_progress(long long total, int flag) { - FILE *progress; - if (!client_flags[0]) + char *du_size_env = getenv("FILECOPY_TOTAL_SIZE"); + char *progress_type_env = getenv("PROGRESS_TYPE"); + char *saved_stdout_env = getenv("SAVED_FD_1"); + if (!progress_type_env) return; - progress = fopen(client_flags, "w"); - if (!progress) - return; - fprintf(progress, "%d %lld %s", getpid(), total, - flag == PROGRESS_FLAG_DONE ? "DONE" : "BUSY"); - fclose(progress); + if (!strcmp(progress_type_env, "console") && du_size_env) { + char msg[256]; + snprintf(msg, sizeof(msg), "sent %lld/%lld KB\r", + total / 1024, strtoull(du_size_env, NULL, 0)); + write(2, msg, strlen(msg)); + 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) @@ -136,25 +145,6 @@ int do_fs_walk(char *file) 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() { struct result_header hdr; @@ -168,26 +158,40 @@ void notify_end_and_wait_for_result() /* wait for result */ 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) { - 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) { 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 *vmname, *entry, *sep; - vmname = get_item(data, ¤t, datasize); - client_flags = get_item(data, ¤t, datasize); + char *ret; + if (pathname[0] == '/') + return strdup(pathname); + 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); - send_vmname(vmname); 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 { sep = rindex(entry, '/'); if (!sep) @@ -200,53 +204,9 @@ void parse_entry(char *data, int datasize) else if (chdir(entry)) gui_fatal("chdir to %s", entry); do_fs_walk(sep + 1); + free(entry); } notify_end_and_wait_for_result(); 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; } diff --git a/appvm/qvm-copy-to-vm b/appvm/qvm-copy-to-vm index eaf8c8f7..bcf333d0 100755 --- a/appvm/qvm-copy-to-vm +++ b/appvm/qvm-copy-to-vm @@ -20,50 +20,24 @@ # # -if [ x"$1" = "x--without-progress" ] ; then - DO_PROGRESS=0 - shift -else - DO_PROGRESS=1 -fi - if [ $# -lt 2 ] ; then echo usage: $0 '[--without-progress] dest_vmname file [file]+' exit 1 fi +if [ x"$1" = "x--without-progress" ] ; then + export PROGRESS_TYPE=none + shift +else + export PROGRESS_TYPE=console +fi + + VM="$1" shift -if [ $DO_PROGRESS = 1 ] ; then - SIZE=$(du --apparent-size -c "$@" | tail -1 | cut -f 1) +if [ $PROGRESS_TYPE = console ] ; then + export FILECOPY_TOTAL_SIZE=$(du --apparent-size -c "$@" | tail -1 | cut -f 1) fi -export PROGRESS_FILE=$(mktemp) -/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 +exec /usr/lib/qubes/qrexec_client_vm /usr/lib/qubes/qfile-agent $VM qubes.Filecopy "$@" diff --git a/appvm/qvm-copy-to-vm2.gnome b/appvm/qvm-copy-to-vm2.gnome index 8fabd2d0..be9dc7ed 100755 --- a/appvm/qvm-copy-to-vm2.gnome +++ b/appvm/qvm-copy-to-vm2.gnome @@ -25,19 +25,11 @@ if [ X$VM = X ] ; then exit 0 ; fi SIZE=$(du --apparent-size -c "$@" | tail -1 | cut -f 1) -export PROGRESS_FILE=$(mktemp) -/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 +export PROGRESS_TYPE=gui + +/usr/lib/qubes/qrexec_client_vm /usr/lib/qubes/qfile-agent \ + $VM qubes.Filecopy "$@" | +(while read sentsize ; do CURRSIZE=$(($sentsize/1024)) echo $((100*$CURRSIZE/$SIZE)) - sleep 0.1 done) | zenity --progress --text="Copying files to domain: $VM..." --auto-close - -rm -f $PROGRESS_FILE diff --git a/appvm/qvm-copy-to-vm2.kde b/appvm/qvm-copy-to-vm2.kde index 7600bb56..478df92d 100755 --- a/appvm/qvm-copy-to-vm2.kde +++ b/appvm/qvm-copy-to-vm2.kde @@ -27,23 +27,16 @@ SIZE=$(du --apparent-size -c "$@" | tail -1 | cut -f 1) REF=$(kdialog --progressbar "Copy progress") qdbus $REF org.freedesktop.DBus.Properties.Set "" maximum $SIZE -export PROGRESS_FILE=$(mktemp) -/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 +export PROGRESS_TYPE=gui + +/usr/lib/qubes/qrexec_client_vm /usr/lib/qubes/qfile-agent \ + $VM qubes.Filecopy "$@" | +(while read sentsize ; do CURRSIZE=$(($sentsize/1024)) qdbus $REF org.freedesktop.DBus.Properties.Set "" value $CURRSIZE - sleep 0.4 -done +done) qdbus $REF close -rm -f $PROGRESS_FILE # we do not want a dozen error messages, do we # if ! [ "x"$agentstatus = xDONE ] ; then # kdialog --sorry 'Abnormal file copy termination; see /var/log/qubes/qrexec.xid.log in dom0 for more details' diff --git a/appvm/qvm-trigger-copy-to-vm b/appvm/qvm-trigger-copy-to-vm deleted file mode 100755 index 56dcdef8..00000000 --- a/appvm/qvm-trigger-copy-to-vm +++ /dev/null @@ -1,46 +0,0 @@ -#!/bin/sh -# -# The Qubes OS Project, http://www.qubes-os.org -# -# Copyright (C) 2010 Rafal Wojtczuk -# -# 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 diff --git a/dom0/restore/qfile-daemon b/dom0/restore/qfile-daemon deleted file mode 100755 index aca6f25f..00000000 --- a/dom0/restore/qfile-daemon +++ /dev/null @@ -1,99 +0,0 @@ -#!/usr/bin/python2.6 -# -# The Qubes OS Project, http://www.qubes-os.org -# -# Copyright (C) 2010 Rafal Wojtczuk -# -# 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. -# -# -import os -import sys -import subprocess -import shutil -import glob -from qubes.qubes import QubesVmCollection - -updates_dir = "/var/lib/qubes/updates" -updates_rpm_dir = updates_dir + "/rpm" - -def is_copy_allowed(vm): -# if vm.copy_allowed: -# return True - q = 'Do you authorize file copy from ' - q+= os.getenv("QREXEC_REMOTE_DOMAIN") - q+= ' to ' + vm.name + ' ?' - retcode = subprocess.call(['/usr/bin/kdialog', '--yesno', q, '--title', 'File transfer confirmation']) - return retcode == 0 - -def dom0updates_fatal(msg): - print >> sys.stderr, msg - shutil.rmtree(updates_rpm_dir) - exit(1) - -def handle_dom0updates(updatevm): - source=os.getenv("QREXEC_REMOTE_DOMAIN") - if source != updatevm.name: - print >> sys.stderr, 'Domain ' + source + ' not allowed to send dom0 updates' - exit(1) - # Clean old packages - if os.path.exists(updates_rpm_dir): - shutil.rmtree(updates_rpm_dir) - subprocess.check_call(["/usr/lib/qubes/qfile-dom0-unpacker", os.getlogin(), updates_rpm_dir]) - # Verify received files - for f in os.listdir(updates_rpm_dir): - if glob.fnmatch.fnmatch(f, "*.rpm"): - p = subprocess.Popen (["/bin/rpm", "-K", updates_rpm_dir + "/" + f], - stdout=subprocess.PIPE) - output = p.communicate()[0] - if p.returncode != 0: - dom0updates_fatal('Error while verifing %s signature: %s' % (f, output)) - if output.find("pgp") < 0: - dom0updates_fatal('Domain ' + source + ' sent not signed rpm: ' + f) - else: - dom0updates_fatal('Domain ' + source + ' sent unexpected file: ' + f) - # After updates received - create repo metadata - subprocess.check_call(["/usr/bin/createrepo", "-q", "/var/lib/qubes/updates"]) - exit(0) - -def main(): - FILECOPY_VMNAME_SIZE = 32 - blob=os.read(0, FILECOPY_VMNAME_SIZE) - vmname = blob.split("\x00")[0] - - qvm_collection = QubesVmCollection() - qvm_collection.lock_db_for_reading() - qvm_collection.load() - qvm_collection.unlock_db() - - if vmname == '@dom0updates': - updatevm = qvm_collection.get_updatevm_vm() - handle_dom0updates(updatevm) - # handle_dom0updates never returns - - vm = qvm_collection.get_vm_by_name(vmname) -# we do not want to flood dom0 with error windows; so just log to stderr - if vm is None: - print >> sys.stderr, 'Domain ' + vmname + ' does not exist ?' - exit(1) - if not vm.is_running(): - print >> sys.stderr, 'Domain ' + vmname + ' is not running ?' - exit(1) - if not is_copy_allowed(vm): - exit(1) - cmd = "root:/usr/lib/qubes/qfile-unpacker " + os.getenv("QREXEC_REMOTE_DOMAIN") - os.execl("/usr/lib/qubes/qrexec_client", "qrexec_client", "-d", vmname, cmd) - -main() diff --git a/qrexec/qrexec_policy b/qrexec/qrexec_policy index 146c4767..ba87f7cf 100755 --- a/qrexec/qrexec_policy +++ b/qrexec/qrexec_policy @@ -33,7 +33,7 @@ def apply_policy(policy, domain, target): return (None, None) def do_execute(domain, target, exec_index, process_ident): - cmd= "qvm-run -q -a --pass_io "+target + cmd= "qvm-run -uroot -q -a --pass_io "+target cmd+=" '/usr/lib/qubes/qubes_rpc_multiplexer "+exec_index + " " + domain + "'" os.execl(QREXEC_CLIENT, "qrexec_client", "-d", domain, "-l", cmd, "-c", process_ident) diff --git a/rpm_spec/core-appvm.spec b/rpm_spec/core-appvm.spec index dfc7e061..77862597 100644 --- a/rpm_spec/core-appvm.spec +++ b/rpm_spec/core-appvm.spec @@ -79,7 +79,6 @@ cp qvm-copy-to-vm $RPM_BUILD_ROOT/usr/bin 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.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_client_vm $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} mkdir -p $RPM_BUILD_ROOT/mnt/removable mkdir -p $RPM_BUILD_ROOT/etc/qubes_rpc +cp qubes.Filecopy $RPM_BUILD_ROOT/etc/qubes_rpc mkdir -p $RPM_BUILD_ROOT/etc/X11 @@ -144,7 +144,6 @@ rm -rf $RPM_BUILD_ROOT /usr/lib/qubes/dvm_file_editor %{kde_service_dir}/qvm-copy.desktop %{kde_service_dir}/qvm-dvm.desktop -/usr/lib/qubes/qvm-trigger-copy-to-vm /usr/lib/qubes/qrexec_agent /usr/lib/qubes/qrexec_client_vm /usr/lib/qubes/qubes_rpc_multiplexer @@ -153,6 +152,7 @@ rm -rf $RPM_BUILD_ROOT /usr/lib/qubes/qfile-unpacker %dir /mnt/removable %dir /etc/qubes_rpc +/etc/qubes_rpc/qubes.Filecopy /usr/bin/qubes_timestamp %dir /home_volatile %attr(700,user,user) /home_volatile/user diff --git a/rpm_spec/core-dom0.spec b/rpm_spec/core-dom0.spec index 7a5d90b3..0a806547 100644 --- a/rpm_spec/core-dom0.spec +++ b/rpm_spec/core-dom0.spec @@ -100,13 +100,13 @@ cp ../qrexec/qrexec_policy $RPM_BUILD_ROOT/usr/lib/qubes/ cp aux-tools/qfile-dom0-unpacker $RPM_BUILD_ROOT/usr/lib/qubes/ mkdir -p $RPM_BUILD_ROOT/etc/qubes_rpc/policy +cp ../appvm/qubes.Filecopy.policy $RPM_BUILD_ROOT/etc/qubes_rpc/policy/qubes.Filecopy cp restore/qvm-create-default-dvm $RPM_BUILD_ROOT/usr/bin cp restore/xenstore-watch $RPM_BUILD_ROOT/usr/bin/xenstore-watch-qubes cp restore/qubes_restore restore/xenfreepages $RPM_BUILD_ROOT/usr/lib/qubes cp restore/qubes_prepare_saved_domain.sh $RPM_BUILD_ROOT/usr/lib/qubes cp restore/qfile-daemon-dvm $RPM_BUILD_ROOT/usr/lib/qubes -cp restore/qfile-daemon $RPM_BUILD_ROOT/usr/lib/qubes mkdir -p $RPM_BUILD_ROOT/etc/yum.real.repos.d cp qubes-cached.repo $RPM_BUILD_ROOT/etc/yum.real.repos.d/ @@ -292,7 +292,6 @@ fi /usr/lib/qubes/qmemman_daemon.py* /usr/lib/qubes/meminfo-writer /usr/lib/qubes/qfile-daemon-dvm* -/usr/lib/qubes/qfile-daemon /usr/lib/qubes/sync_rpmdb_updatevm.sh %attr(4750,root,qubes) /usr/lib/qubes/qfile-dom0-unpacker %attr(770,root,qubes) %dir /var/lib/qubes @@ -326,6 +325,7 @@ fi /usr/lib/qubes/qrexec_client /usr/lib/qubes/qrexec_policy %dir /etc/qubes_rpc/policy +/etc/qubes_rpc/policy/qubes.Filecopy %attr(4750,root,qubes) /usr/lib/qubes/qrexec_daemon %attr(4750,root,qubes) /usr/lib/qubes/xenfreepages %attr(2770,root,qubes) %dir /var/log/qubes