Update qubes.xml with DVM

Also, pass correct parameters to DVM's qubes_guid (taken from
qubes.xml).
This commit is contained in:
Rafal Wojtczuk 2010-07-13 01:51:33 +02:00 committed by Joanna Rutkowska
parent de4ff20448
commit 6ee594f972
2 changed files with 71 additions and 22 deletions

View File

@ -185,13 +185,39 @@ class DomainState:
return True return True
def handle_transfer_disposable(self, transaction_seq): def handle_transfer_disposable(self, transaction_seq):
retcode = subprocess.call(['/usr/bin/qubes_restore', '/dev/shm/qubes/disposable_savefile'])
qvm_collection = QubesVmCollection()
qvm_collection.lock_db_for_writing()
qvm_collection.load()
vm = qvm_collection.get_vm_by_name(self.name)
if vm is None:
logproc( 'Domain ' + vmname + ' does not exist ?')
qvm_collection.unlock_db()
return False
retcode = subprocess.call(['/usr/bin/qubes_restore',
'/dev/shm/qubes/disposable_savefile',
'-c', vm.label.color,
'-i', vm.label.icon,
'-l', str(vm.label.index)])
if retcode != 0: if retcode != 0:
subprocess.call(['/usr/bin/kdialog', '--sorry', 'DisposableVM creation failed, see qubes_restore.log']) subprocess.call(['/usr/bin/kdialog', '--sorry', 'DisposableVM creation failed, see qubes_restore.log'])
qvm_collection.unlock_db()
return False return False
f=open('/var/run/qubes/dispVM_xid', 'r'); f = open('/var/run/qubes/dispVM_xid', 'r');
disp_xid = f.readline() disp_xid = f.readline().rstrip('\n')
disp_name = f.readline().rstrip('\n')
disptempl = f.readline().rstrip('\n')
f.close() f.close()
vm_disptempl = qvm_collection.get_vm_by_name(disptempl);
if vm_disptempl is None:
logproc( 'Domain ' + disptempl + ' does not exist ?')
qvm_collection.unlock_db()
return False
qvm_collection.add_new_appvm(disp_name, vm_disptempl.template_vm, label=vm.label)
qvm_collection.save()
qvm_collection.unlock_db()
dispdom = DomainState(disp_xid, self.domdict) dispdom = DomainState(disp_xid, self.domdict)
disposable_domains_dict[disp_xid] = dispdom disposable_domains_dict[disp_xid] = dispdom
retcode = subprocess.call([pen_cmd, 'send', self.domain_id, disp_xid, self.send_seq, transaction_seq]) retcode = subprocess.call([pen_cmd, 'send', self.domain_id, disp_xid, self.send_seq, transaction_seq])
@ -221,7 +247,6 @@ class XS_Watcher:
for i in only_in_first_list(curr, self.domdict.keys()): for i in only_in_first_list(curr, self.domdict.keys()):
if disposable_domains_dict.has_key(i): if disposable_domains_dict.has_key(i):
newdom = disposable_domains_dict[i] newdom = disposable_domains_dict[i]
disposable_domains_dict.pop(i)
else: else:
newdom = DomainState(i, self.domdict) newdom = DomainState(i, self.domdict)
newdom.name = '' newdom.name = ''
@ -232,6 +257,9 @@ class XS_Watcher:
self.handle.watch(get_name_node(i), newdom.watch_name) self.handle.watch(get_name_node(i), newdom.watch_name)
logproc( 'added domain ' + i) logproc( 'added domain ' + i)
for i in only_in_first_list(self.domdict.keys(), curr): for i in only_in_first_list(self.domdict.keys(), curr):
if disposable_domains_dict.has_key(i):
self.remove_disposable_from_qdb(self.domdict[i].name)
disposable_domains_dict.pop(i)
self.handle.unwatch(get_req_node(i), self.domdict[i].watch_token) self.handle.unwatch(get_req_node(i), self.domdict[i].watch_token)
self.handle.unwatch(get_name_node(i), self.domdict[i].watch_name) self.handle.unwatch(get_name_node(i), self.domdict[i].watch_name)
self.domdict.pop(i) self.domdict.pop(i)
@ -247,6 +275,20 @@ class XS_Watcher:
domain_param.name = ret domain_param.name = ret
logproc( 'Name for domain xid ' + domain_param.domain_id + ' is ' + ret ) logproc( 'Name for domain xid ' + domain_param.domain_id + ' is ' + ret )
def remove_disposable_from_qdb(self, name):
qvm_collection = QubesVmCollection()
qvm_collection.lock_db_for_writing()
qvm_collection.load()
vm = qvm_collection.get_vm_by_name(name)
if vm is None:
logproc( 'remove_disposable_from_qdb: Domain ' + vmname + ' does not exist ?')
qvm_collection.unlock_db()
return False
qvm_collection.pop(vm.qid)
qvm_collection.save()
qvm_collection.unlock_db()
def watch_loop(self): def watch_loop(self):
sys.stderr = file('/var/log/qubes/qfileexchgd.errors', 'a') sys.stderr = file('/var/log/qubes/qfileexchgd.errors', 'a')
while True: while True:

View File

@ -184,15 +184,18 @@ int xend_connect()
void start_guid(int domid, int argc, char **argv) void start_guid(int domid, int argc, char **argv)
{ {
int i;
char dstr[40]; char dstr[40];
char *guid_args[argc + 2];
snprintf(dstr, sizeof(dstr), "%d", domid); snprintf(dstr, sizeof(dstr), "%d", domid);
if (argc == 2) guid_args[0] = "qubes_guid";
execl("/usr/bin/qubes_guid", "guid", "-d", dstr, "-c", guid_args[1] = "-d";
"red", "-i", "red", NULL); guid_args[2] = dstr;
else for (i = 2; i < argc; i++)
execl("/usr/bin/qubes_guid", "guid", "-d", dstr, "-c", guid_args[i + 1] = argv[i];
"red", "-i", "red", "-e", argv[2], NULL); guid_args[argc + 1] = NULL;
perror("execl"); execv("/usr/bin/qubes_guid", guid_args);
perror("execv");
} }
void fix_savefile(int fd, char *buf, char *pattern, char *val) void fix_savefile(int fd, char *buf, char *pattern, char *val)
@ -218,9 +221,12 @@ void fix_savefile(int fd, char *buf, char *pattern, char *val)
} }
char * dispname_by_dispid(int dispid)
{
static char retbuf[16];
snprintf(retbuf, sizeof(retbuf), "disp%d", dispid);
return retbuf;
}
#define NAME_PATTERN "/root-cow.img" #define NAME_PATTERN "/root-cow.img"
char *fix_savefile_and_get_vmname(int fd, int dispid) char *fix_savefile_and_get_vmname(int fd, int dispid)
@ -237,8 +243,7 @@ char *fix_savefile_and_get_vmname(int fd, int dispid)
snprintf(val, sizeof(val), snprintf(val, sizeof(val),
"064cd14c-95ad-4fc2-a4c9-cf9f522e5b%02x", dispid); "064cd14c-95ad-4fc2-a4c9-cf9f522e5b%02x", dispid);
fix_savefile(fd, buf, "(uuid ", val); fix_savefile(fd, buf, "(uuid ", val);
snprintf(val, sizeof(val), "disp%02d", dispid); fix_savefile(fd, buf, "(name ", dispname_by_dispid(dispid));
fix_savefile(fd, buf, "(name ", val);
snprintf(val, sizeof(val), "00:16:3e:7c:8b:%02x", dispid); snprintf(val, sizeof(val), "00:16:3e:7c:8b:%02x", dispid);
fix_savefile(fd, buf, "(mac ", val); fix_savefile(fd, buf, "(mac ", val);
lseek(fd, 0, SEEK_SET); lseek(fd, 0, SEEK_SET);
@ -351,14 +356,14 @@ int get_next_disposable_id()
return seq; return seq;
} }
void write_varrun_domid(int domid) void write_varrun_domid(int domid, char * dispname, char *orig)
{ {
FILE *f = fopen("/var/run/qubes/dispVM_xid", "w"); FILE *f = fopen("/var/run/qubes/dispVM_xid", "w");
if (!f) { if (!f) {
perror("fopen dispVM_xid"); perror("fopen dispVM_xid");
exit(1); exit(1);
} }
fprintf(f, "%d", domid); fprintf(f, "%d\n%s\n%s\n", domid, dispname, orig);
fclose(f); fclose(f);
} }
@ -366,7 +371,8 @@ void write_varrun_domid(int domid)
void redirect_stderr() void redirect_stderr()
{ {
int fd = int fd =
open("/var/run/qubes/qubes_restore.log", O_CREAT | O_TRUNC | O_WRONLY, 0600); open("/var/run/qubes/qubes_restore.log",
O_CREAT | O_TRUNC | O_WRONLY, 0600);
if (fd < 0) { if (fd < 0) {
syslog(LOG_DAEMON | LOG_ERR, "open qubes_restore.log"); syslog(LOG_DAEMON | LOG_ERR, "open qubes_restore.log");
exit(1); exit(1);
@ -380,8 +386,9 @@ int main(int argc, char **argv)
int fd, domid, dispid; int fd, domid, dispid;
char *resp; char *resp;
char *name; char *name;
if (argc != 2 && argc != 3) { if (argc < 2) {
fprintf(stderr, "usage: %s savefile [cmd] \n", argv[0]); fprintf(stderr, "usage: %s savefile [guid args] \n",
argv[0]);
exit(1); exit(1);
} }
redirect_stderr(); redirect_stderr();
@ -403,7 +410,7 @@ int main(int argc, char **argv)
send_req_restore(fd, argv[1]); send_req_restore(fd, argv[1]);
resp = recv_resp(fd); resp = recv_resp(fd);
domid = parse_resp(resp); domid = parse_resp(resp);
write_varrun_domid(domid); write_varrun_domid(domid, dispname_by_dispid(dispid), name);
fprintf(stderr, fprintf(stderr,
"time=%s, created domid=%d, executing set_mem 400\n", "time=%s, created domid=%d, executing set_mem 400\n",
gettime(), domid); gettime(), domid);