"""
global active_policy
- try:
- active_policy = acm.policy()
- except:
- active_policy = "INACTIVE"
+ active_policy = 'INACCESSIBLE'
+ if os.access("/proc/xen/privcmd", os.R_OK|os.W_OK):
+ try:
+ active_policy = acm.policy()
+ except:
+ active_policy = "INACTIVE"
# now set active_policy
refresh_security_policy()
maps current policy to default directory
to find mapping file """
- if policyname in ['NULL', 'INACTIVE', 'DEFAULT']:
+ if policyname in ['NULL', 'INACTIVE', 'DEFAULT', 'INACCESSIBLE' ]:
err("Cannot translate labels for \'" + policyname + "\' policy.")
allowed_types = ['ANY']
def dump_policy():
- if active_policy in ['NULL', 'INACTIVE']:
+ if active_policy in ['NULL', 'INACTIVE', 'INACCESSIBLE' ]:
err("\'" + active_policy + "\' policy. Nothing to dump.")
(ret, output) = commands.getstatusoutput(xensec_tool + " getpolicy")
def list_labels(policy_name, condition):
- if (not policy_name) and (active_policy) in ["NULL", "INACTIVE", "DEFAULT"]:
+ if (not policy_name) and active_policy in \
+ [ 'NULL', 'INACTIVE', 'DEFAULT', 'INACCESSIBLE' ]:
err("Current policy \'" + active_policy + "\' has no labels defined.\n")
(primary, secondary, f, pol_exists) = getmapfile(policy_name)
policy = active_policy
if active_policy in ['NULL', 'INACTIVE', 'DEFAULT']:
raise OptionError('No policy active, you must specify a <policy>')
+ if active_policy in ['INACCESSIBLE']:
+ raise OptionError('Cannot access the policy. Try as root.')
if not ptype or ptype == 'dom':
condition = vm_label_re
for n in names:
print n
elif int(policystate['type']) == 0:
- print "No policy installed on the system."
+ err("No policy installed on the system.")
else:
- print "Unsupported type of policy installed on the system."
+ err("Unsupported type of policy installed on the system.")
if __name__ == '__main__':
main(sys.argv)