Implement qvm-copy-to-vm and qvm-move-to-vm utilities
QubesOS/qubes-issues#1324
This commit is contained in:
parent
520e250966
commit
4e498c90e6
8
file-copy-vm/Makefile
Normal file
8
file-copy-vm/Makefile
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
CFLAGS=-g -O2 -Wall -Wextra -Werror -I. -fPIC -pie
|
||||||
|
all: qfile-dom0-agent
|
||||||
|
qfile-dom0-agent: qfile-dom0-agent.o
|
||||||
|
$(CC) -pie -g -o $@ $^ -lqubes-rpc-filecopy
|
||||||
|
|
||||||
|
clean:
|
||||||
|
rm -f qfile-dom0-agent *.o
|
||||||
|
|
94
file-copy-vm/qfile-dom0-agent.c
Normal file
94
file-copy-vm/qfile-dom0-agent.c
Normal file
@ -0,0 +1,94 @@
|
|||||||
|
#define _GNU_SOURCE
|
||||||
|
#include <dirent.h>
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <string.h>
|
||||||
|
#include <sys/stat.h>
|
||||||
|
#include <signal.h>
|
||||||
|
#include <fcntl.h>
|
||||||
|
#include <malloc.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <unistd.h>
|
||||||
|
#include <errno.h>
|
||||||
|
#include <libqubes-rpc-filecopy.h>
|
||||||
|
|
||||||
|
void display_error(const char *fmt, va_list args) {
|
||||||
|
char *dialog_cmd;
|
||||||
|
char buf[1024];
|
||||||
|
struct stat st_buf;
|
||||||
|
int ret;
|
||||||
|
|
||||||
|
(void) vsnprintf(buf, sizeof(buf), fmt, args);
|
||||||
|
ret = stat("/usr/bin/kdialog", &st_buf);
|
||||||
|
#define KDIALOG_CMD "kdialog --title 'File copy/move error' --sorry "
|
||||||
|
#define ZENITY_CMD "zenity --title 'File copy/move error' --warning --text "
|
||||||
|
if (asprintf(&dialog_cmd, "%s '%s: %s (error type: %s)'",
|
||||||
|
ret==0 ? KDIALOG_CMD : ZENITY_CMD,
|
||||||
|
program_invocation_short_name, buf, strerror(errno)) < 0) {
|
||||||
|
fprintf(stderr, "Failed to allocate memory for error message :(\n");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
#undef KDIALOG_CMD
|
||||||
|
#undef ZENITY_CMD
|
||||||
|
fprintf(stderr, "%s\n", buf);
|
||||||
|
system(dialog_cmd);
|
||||||
|
}
|
||||||
|
|
||||||
|
_Noreturn void gui_fatal(const char *fmt, ...) {
|
||||||
|
va_list args;
|
||||||
|
va_start(args, fmt);
|
||||||
|
display_error(fmt, args);
|
||||||
|
va_end(args);
|
||||||
|
exit(1);
|
||||||
|
}
|
||||||
|
|
||||||
|
char *get_abs_path(const char *cwd, const char *pathname)
|
||||||
|
{
|
||||||
|
char *ret;
|
||||||
|
if (pathname[0] == '/')
|
||||||
|
return strdup(pathname);
|
||||||
|
if (asprintf(&ret, "%s/%s", cwd, pathname) < 0)
|
||||||
|
return NULL;
|
||||||
|
else
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
int main(int argc, char **argv)
|
||||||
|
{
|
||||||
|
int i;
|
||||||
|
char *entry;
|
||||||
|
char *cwd;
|
||||||
|
char *sep;
|
||||||
|
int ignore_symlinks = 0;
|
||||||
|
|
||||||
|
qfile_pack_init();
|
||||||
|
register_error_handler(display_error);
|
||||||
|
cwd = getcwd(NULL, 0);
|
||||||
|
for (i = 1; i < argc; i++) {
|
||||||
|
if (strcmp(argv[i], "--ignore-symlinks")==0) {
|
||||||
|
ignore_symlinks = 1;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
entry = get_abs_path(cwd, argv[i]);
|
||||||
|
|
||||||
|
do {
|
||||||
|
sep = rindex(entry, '/');
|
||||||
|
if (!sep)
|
||||||
|
gui_fatal
|
||||||
|
("Internal error: nonabsolute filenames not allowed");
|
||||||
|
*sep = 0;
|
||||||
|
} while (sep[1] == 0);
|
||||||
|
if (entry[0] == 0) {
|
||||||
|
if (chdir("/") < 0) {
|
||||||
|
gui_fatal("Internal error: chdir(\"/\") failed?!");
|
||||||
|
}
|
||||||
|
} else if (chdir(entry))
|
||||||
|
gui_fatal("chdir to %s", entry);
|
||||||
|
do_fs_walk(sep + 1, ignore_symlinks);
|
||||||
|
free(entry);
|
||||||
|
}
|
||||||
|
notify_end_and_wait_for_result();
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
31
file-copy-vm/qvm-copy-to-vm
Normal file
31
file-copy-vm/qvm-copy-to-vm
Normal file
@ -0,0 +1,31 @@
|
|||||||
|
#!/bin/sh
|
||||||
|
#
|
||||||
|
# The Qubes OS Project, http://www.qubes-os.org
|
||||||
|
#
|
||||||
|
# Copyright (C) 2015 Marek Marczykowski-Górecki <marmarek@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 'dest_vmname file [file]+'
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
VM="$1"
|
||||||
|
shift
|
||||||
|
|
||||||
|
exec /usr/bin/qvm-run --pass-io --localcmd "/usr/lib/qubes/qfile-dom0-agent $@" "$VM" "QUBESRPC qubes.Filecopy dom0"
|
33
file-copy-vm/qvm-move-to-vm
Normal file
33
file-copy-vm/qvm-move-to-vm
Normal file
@ -0,0 +1,33 @@
|
|||||||
|
#!/bin/sh
|
||||||
|
#
|
||||||
|
# The Qubes OS Project, http://www.qubes-os.org
|
||||||
|
#
|
||||||
|
# Copyright (C) 2015 Marek Marczykowski-Górecki <marmarek@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 'dest_vmname file [file]+'
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
VM="$1"
|
||||||
|
shift
|
||||||
|
|
||||||
|
set -e
|
||||||
|
/usr/bin/qvm-run --pass-io --localcmd "/usr/lib/qubes/qfile-dom0-agent $@" "$VM" "QUBESRPC qubes.Filecopy dom0"
|
||||||
|
rm -rf -- "$@"
|
@ -79,6 +79,7 @@ python -m compileall appmenus-scripts
|
|||||||
python -O -m compileall appmenus-scripts
|
python -O -m compileall appmenus-scripts
|
||||||
(cd dom0-updates; make)
|
(cd dom0-updates; make)
|
||||||
(cd qrexec; make)
|
(cd qrexec; make)
|
||||||
|
(cd file-copy-vm; make)
|
||||||
(cd doc; make manpages)
|
(cd doc; make manpages)
|
||||||
|
|
||||||
%install
|
%install
|
||||||
@ -154,6 +155,11 @@ install -m 755 -D system-config/kernel-grub2.install $RPM_BUILD_ROOT/usr/lib/ker
|
|||||||
install -m 755 -D system-config/kernel-xen-efi.install $RPM_BUILD_ROOT/usr/lib/kernel/install.d/90-xen-efi.install
|
install -m 755 -D system-config/kernel-xen-efi.install $RPM_BUILD_ROOT/usr/lib/kernel/install.d/90-xen-efi.install
|
||||||
install -m 755 -D system-config/kernel-remove-bls.install $RPM_BUILD_ROOT/usr/lib/kernel/install.d/99-remove-bls.install
|
install -m 755 -D system-config/kernel-remove-bls.install $RPM_BUILD_ROOT/usr/lib/kernel/install.d/99-remove-bls.install
|
||||||
|
|
||||||
|
# file copy to VM
|
||||||
|
install -m 755 file-copy-vm/qfile-dom0-agent $RPM_BUILD_ROOT/usr/lib/qubes/
|
||||||
|
install -m 755 file-copy-vm/qvm-copy-to-vm $RPM_BUILD_ROOT/usr/bin/
|
||||||
|
install -m 755 file-copy-vm/qvm-move-to-vm $RPM_BUILD_ROOT/usr/bin/
|
||||||
|
|
||||||
### Icons
|
### Icons
|
||||||
mkdir -p $RPM_BUILD_ROOT/usr/share/qubes/icons
|
mkdir -p $RPM_BUILD_ROOT/usr/share/qubes/icons
|
||||||
for icon in icons/*.png; do
|
for icon in icons/*.png; do
|
||||||
@ -256,6 +262,10 @@ chmod -x /etc/grub.d/10_linux
|
|||||||
/usr/lib/qubes/qrexec_client
|
/usr/lib/qubes/qrexec_client
|
||||||
/usr/lib/qubes/qubes-rpc-multiplexer
|
/usr/lib/qubes/qubes-rpc-multiplexer
|
||||||
/usr/lib/qubes/qrexec-policy
|
/usr/lib/qubes/qrexec-policy
|
||||||
|
# file copy
|
||||||
|
/usr/bin/qvm-copy-to-vm
|
||||||
|
/usr/bin/qvm-move-to-vm
|
||||||
|
/usr/lib/qubes/qfile-dom0-agent
|
||||||
# pm-utils
|
# pm-utils
|
||||||
/usr/lib64/pm-utils/sleep.d/01qubes-sync-vms-clock
|
/usr/lib64/pm-utils/sleep.d/01qubes-sync-vms-clock
|
||||||
/usr/lib64/pm-utils/sleep.d/51qubes-suspend-netvm
|
/usr/lib64/pm-utils/sleep.d/51qubes-suspend-netvm
|
||||||
|
Loading…
Reference in New Issue
Block a user