From dc33f0c9a7d8c50a9619964207a98c8101557eba Mon Sep 17 00:00:00 2001 From: Rafal Wojtczuk Date: Wed, 6 Jul 2011 12:32:20 +0200 Subject: [PATCH] qrexec: adjust DispVM code to the new qrexec API Note, we have qvm-open-in-vm totally for free. --- appvm/Makefile | 8 ++-- appvm/{qfile-agent-dvm.c => qopen-in-vm.c} | 46 ++----------------- appvm/qubes.OpenInVM | 1 + appvm/qubes.OpenInVM.policy | 2 + appvm/qvm-open-in-dvm2 | 14 +----- appvm/qvm-open-in-vm | 28 +++++++++++ appvm/{dvm_file_editor.c => vm-file-editor.c} | 0 rpm_spec/core-appvm.spec | 11 +++-- 8 files changed, 48 insertions(+), 62 deletions(-) rename appvm/{qfile-agent-dvm.c => qopen-in-vm.c} (68%) create mode 100644 appvm/qubes.OpenInVM create mode 100644 appvm/qubes.OpenInVM.policy create mode 100755 appvm/qvm-open-in-vm rename appvm/{dvm_file_editor.c => vm-file-editor.c} (100%) diff --git a/appvm/Makefile b/appvm/Makefile index d1e1040..42bb636 100644 --- a/appvm/Makefile +++ b/appvm/Makefile @@ -1,9 +1,9 @@ CC=gcc CFLAGS=-g -Wall -I../common -fPIC -pie -all: dvm_file_editor qfile-agent-dvm qfile-agent qfile-unpacker -dvm_file_editor: dvm_file_editor.o ../common/ioall.o +all: vm-file-editor qopen-in-vm qfile-agent qfile-unpacker +vm-file-editor: vm-file-editor.o ../common/ioall.o $(CC) -pie -g -o $@ $^ -qfile-agent-dvm: qfile-agent-dvm.o ../common/ioall.o ../common/gui-fatal.o +qopen-in-vm: qopen-in-vm.o ../common/ioall.o ../common/gui-fatal.o $(CC) -pie -g -o $@ $^ qfile-agent: qfile-agent.o ../common/ioall.o ../common/gui-fatal.o ../common/copy_file.o ../common/crc32.o $(CC) -pie -g -o $@ $^ @@ -11,4 +11,4 @@ qfile-unpacker: qfile-unpacker.o ../common/ioall.o ../common/gui-fatal.o ../comm $(CC) -pie -g -o $@ $^ clean: - rm -f qfile-agent-dvm qfile-agent qfile-unpacker dvm_file_editor *.o *~ + rm -f qopen-in-vm qfile-agent qfile-unpacker vm-file-editor *.o *~ diff --git a/appvm/qfile-agent-dvm.c b/appvm/qopen-in-vm.c similarity index 68% rename from appvm/qfile-agent-dvm.c rename to appvm/qopen-in-vm.c index 5db430c..80f99c3 100644 --- a/appvm/qfile-agent-dvm.c +++ b/appvm/qopen-in-vm.c @@ -93,47 +93,11 @@ void talk_to_daemon(char *fname) recv_file(fname); } -void process_spoolentry(char *entry_name) -{ - char *abs_spool_entry_name; - int entry_fd; - struct stat st; - char *filename; - int entry_size; - asprintf(&abs_spool_entry_name, "%s/%s", DVM_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 dvm_entry"); - entry_size = st.st_size; - filename = calloc(1, entry_size + DVM_FILENAME_SIZE); - if (!filename) - gui_fatal("malloc"); - if (!read_all(entry_fd, filename, entry_size)) - gui_fatal("read dvm entry %s", abs_spool_entry_name); - close(entry_fd); - talk_to_daemon(filename); -} - -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 (!strcmp(fname, ".") || !strcmp(fname, "..")) - continue; - process_spoolentry(fname); - break; - } - closedir(dir); -} - -int main() +int main(int argc, char ** argv) { signal(SIGPIPE, SIG_IGN); - scan_spool(DVM_SPOOL); + if (argc!=2) + gui_fatal("OpenInVM - no file given?"); + talk_to_daemon(argv[1]); return 0; -} +} diff --git a/appvm/qubes.OpenInVM b/appvm/qubes.OpenInVM new file mode 100644 index 0000000..48db906 --- /dev/null +++ b/appvm/qubes.OpenInVM @@ -0,0 +1 @@ +/usr/lib/qubes/vm-file-editor diff --git a/appvm/qubes.OpenInVM.policy b/appvm/qubes.OpenInVM.policy new file mode 100644 index 0000000..e103d39 --- /dev/null +++ b/appvm/qubes.OpenInVM.policy @@ -0,0 +1,2 @@ +anyvm dispvm allow +anyvm anyvm ask diff --git a/appvm/qvm-open-in-dvm2 b/appvm/qvm-open-in-dvm2 index eb0d4e2..365c564 100755 --- a/appvm/qvm-open-in-dvm2 +++ b/appvm/qvm-open-in-dvm2 @@ -25,16 +25,4 @@ if ! [ $# = 1 ] ; then exit 1 fi -FILE="$1" -if ! [ "X""${FILE:0:1}" = X/ ] ; then - FILE="$PWD"/"$1" -fi - -DVMSPOOL=/home/user/.dvmspool -if ! [ -e $DVMSPOOL ] ; then - mkdir $DVMSPOOL || exit 1 -fi - -echo -n "$FILE" > $DVMSPOOL/req.$$ -echo -n DVMR > /var/run/qubes/qrexec_agent - +exec /usr/lib/qubes/qrexec_client_vm "/usr/lib/qubes/qopen-in-vm" dispvm qubes.OpenInVM "$1" diff --git a/appvm/qvm-open-in-vm b/appvm/qvm-open-in-vm new file mode 100755 index 0000000..dc77ffe --- /dev/null +++ b/appvm/qvm-open-in-vm @@ -0,0 +1,28 @@ +#!/bin/bash +# +# 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 ! [ $# = 2 ] ; then + echo "Usage: $0 vmname filename" + exit 1 +fi + +exec /usr/lib/qubes/qrexec_client_vm "/usr/lib/qubes/qopen-in-vm" "$1" qubes.OpenInVM "$2" diff --git a/appvm/dvm_file_editor.c b/appvm/vm-file-editor.c similarity index 100% rename from appvm/dvm_file_editor.c rename to appvm/vm-file-editor.c diff --git a/rpm_spec/core-appvm.spec b/rpm_spec/core-appvm.spec index 7786259..ce783b2 100644 --- a/rpm_spec/core-appvm.spec +++ b/rpm_spec/core-appvm.spec @@ -75,6 +75,7 @@ cp qubes_core_appvm $RPM_BUILD_ROOT/etc/init.d/ mkdir -p $RPM_BUILD_ROOT/var/lib/qubes mkdir -p $RPM_BUILD_ROOT/usr/bin cp qubes_timestamp qvm-open-in-dvm2 $RPM_BUILD_ROOT/usr/bin +cp qvm-open-in-vm $RPM_BUILD_ROOT/usr/bin 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 @@ -82,14 +83,14 @@ cp qvm-copy-to-vm2.gnome $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 -cp dvm_file_editor qfile-agent qfile-agent-dvm qfile-unpacker $RPM_BUILD_ROOT/usr/lib/qubes +cp vm-file-editor qfile-agent qopen-in-vm qfile-unpacker $RPM_BUILD_ROOT/usr/lib/qubes cp ../common/meminfo-writer $RPM_BUILD_ROOT/usr/lib/qubes 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 - +cp qubes.OpenInVM $RPM_BUILD_ROOT/etc/qubes_rpc mkdir -p $RPM_BUILD_ROOT/etc/X11 cp xorg-preload-apps.conf $RPM_BUILD_ROOT/etc/X11 @@ -140,19 +141,21 @@ rm -rf $RPM_BUILD_ROOT /usr/lib/qubes/qvm-copy-to-vm2.kde /usr/lib/qubes/qvm-copy-to-vm2.gnome /usr/bin/qvm-open-in-dvm2 +/usr/bin/qvm-open-in-vm /usr/lib/qubes/meminfo-writer -/usr/lib/qubes/dvm_file_editor +/usr/lib/qubes/vm-file-editor %{kde_service_dir}/qvm-copy.desktop %{kde_service_dir}/qvm-dvm.desktop /usr/lib/qubes/qrexec_agent /usr/lib/qubes/qrexec_client_vm /usr/lib/qubes/qubes_rpc_multiplexer /usr/lib/qubes/qfile-agent -/usr/lib/qubes/qfile-agent-dvm +/usr/lib/qubes/qopen-in-vm /usr/lib/qubes/qfile-unpacker %dir /mnt/removable %dir /etc/qubes_rpc /etc/qubes_rpc/qubes.Filecopy +/etc/qubes_rpc/qubes.OpenInVM /usr/bin/qubes_timestamp %dir /home_volatile %attr(700,user,user) /home_volatile/user