Merge remote-tracking branch 'qubesos/pr/24'
* qubesos/pr/24: Prompt to create policy file for qubes-rpc if not present.
This commit is contained in:
commit
b629cbfe9e
@ -148,24 +148,43 @@ def add_always_allow(domain, target, service_name, options):
|
|||||||
f.close()
|
f.close()
|
||||||
|
|
||||||
def info_dialog(msg_type, text):
|
def info_dialog(msg_type, text):
|
||||||
if msg_type not in ['info', 'warning', 'error']:
|
if msg_type not in ['info', 'warning', 'error', 'entry']:
|
||||||
raise ValueError("Invalid msg_type value")
|
raise ValueError("Invalid msg_type value")
|
||||||
try:
|
if msg_type in ['info', 'warning', 'error']:
|
||||||
subprocess.call(["/usr/bin/zenity", "--{}".format(msg_type), "--text",
|
try:
|
||||||
|
subprocess.call(["/usr/bin/zenity", "--{}".format(msg_type), "--text",
|
||||||
text])
|
text])
|
||||||
except OSError:
|
except OSError:
|
||||||
kdialog_msg_type = {
|
kdialog_msg_type = {
|
||||||
'info': 'msgbox',
|
'info': 'msgbox',
|
||||||
'warning': 'sorry',
|
'warning': 'sorry',
|
||||||
'error': 'error'
|
'error': 'error'
|
||||||
}[msg_type]
|
}[msg_type]
|
||||||
subprocess.call(["/usr/bin/kdialog", "--{}".format(kdialog_msg_type),
|
subprocess.call(["/usr/bin/kdialog", "--{}".format(kdialog_msg_type), text])
|
||||||
|
else:
|
||||||
|
response = subprocess.check_output(["/usr/bin/zenity", "--{}".format(msg_type), "--text",
|
||||||
text])
|
text])
|
||||||
|
return response
|
||||||
|
|
||||||
|
|
||||||
def policy_editor(domain, target, service_name):
|
def policy_editor(domain, target, service_name):
|
||||||
text = "No policy definition found for " + service_name + " action. "
|
text = "No policy definition found for " + service_name + " action. \n"
|
||||||
text+= "Please create a policy file in Dom0 in " + POLICY_FILE_DIR + "/" + service_name
|
text+= "Type YES if you want to create a default policy file"
|
||||||
info_dialog("warning", text)
|
response = info_dialog('entry', text)
|
||||||
|
if response.strip() == 'YES':
|
||||||
|
create_policy(service_name)
|
||||||
|
|
||||||
|
|
||||||
|
def create_policy(service_name):
|
||||||
|
policyFile = "/etc/qubes-rpc/policy/"+service_name
|
||||||
|
policy = open(policyFile, "w")
|
||||||
|
policy.write("## Note that policy parsing stops at the first match,\n")
|
||||||
|
policy.write("## so adding anything below \"$anyvm $anyvm action\" line will have no effect\n")
|
||||||
|
policy.write("\n")
|
||||||
|
policy.write("## Please use a single # to start your custom comments\n")
|
||||||
|
policy.write("\n")
|
||||||
|
policy.write("$anyvm $anyvm ask\n")
|
||||||
|
policy.close()
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
usage = "usage: %prog [options] <src-domain-id> <src-domain> <target-domain> <service> <process-ident>"
|
usage = "usage: %prog [options] <src-domain-id> <src-domain> <target-domain> <service> <process-ident>"
|
||||||
|
Loading…
Reference in New Issue
Block a user