mirror of
https://github.com/xen-project/xen.git
synced 2026-10-28 10:11:27 +01:00
131 lines
2.8 KiB
Bash
131 lines
2.8 KiB
Bash
#!/bin/sh
|
|
# *
|
|
# * getlabel
|
|
# *
|
|
# * Copyright (C) 2005 IBM Corporation
|
|
# *
|
|
# * Authors:
|
|
# * Stefan Berger <stefanb@us.ibm.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, version 2 of the
|
|
# * License.
|
|
# *
|
|
# * 'getlabel' tries to find the labels corresponding to the ssidref
|
|
# *
|
|
# * 'getlabel -?' shows the usage of the program
|
|
# *
|
|
# * 'getlabel -sid <ssidref> [<policy name>]' lists the label corresponding
|
|
# * to the given ssidref.
|
|
# *
|
|
# * 'getlabel -dom <domain id> [<policy name>]' lists the label of the
|
|
# * domain with given id
|
|
# *
|
|
#
|
|
|
|
if [ -z "$runbash" ]; then
|
|
runbash="1"
|
|
export runbash
|
|
exec sh -c "bash $0 $*"
|
|
fi
|
|
|
|
|
|
export PATH=$PATH:.
|
|
source labelfuncs.sh
|
|
|
|
usage ()
|
|
{
|
|
echo "Usage: $0 -sid <ssidref> [<policy name>] or"
|
|
echo " $0 -dom <domid> [<policy name>] "
|
|
echo ""
|
|
echo "policy name : the name of the policy, i.e. 'chwall'"
|
|
echo " If the policy name is omitted, the grub.conf"
|
|
echo " entry of the running system is tried to be read"
|
|
echo " and the policy name determined from there."
|
|
echo "ssidref : an ssidref in hex or decimal format, i.e., '0x00010002'"
|
|
echo " or '65538'"
|
|
echo "domid : id of the domain, i.e., '1'; Use numbers from the 2nd"
|
|
echo " column shown when invoking 'xm list'"
|
|
echo ""
|
|
}
|
|
|
|
|
|
|
|
if [ "$1" == "-?" ]; then
|
|
mode="usage"
|
|
elif [ "$1" == "-dom" ]; then
|
|
mode="domid"
|
|
shift
|
|
elif [ "$1" == "-sid" ]; then
|
|
mode="sid"
|
|
shift
|
|
elif [ "$1" == "" ]; then
|
|
usage
|
|
exit -1
|
|
fi
|
|
|
|
|
|
if [ "$mode" == "usage" ]; then
|
|
usage
|
|
elif [ "$mode" == "domid" ]; then
|
|
if [ "$2" == "" ]; then
|
|
findGrubConf
|
|
ret=$?
|
|
if [ $ret -eq 0 ]; then
|
|
echo "Could not find grub.conf"
|
|
exit -1;
|
|
fi
|
|
findPolicyInGrub $grubconf
|
|
if [ "$policy" != "" ]; then
|
|
echo "Assuming policy to be '$policy'.";
|
|
else
|
|
echo "Could not find policy."
|
|
exit -1;
|
|
fi
|
|
else
|
|
policy=$2
|
|
fi
|
|
findMapFile $policy
|
|
res=$?
|
|
if [ "$res" != "0" ]; then
|
|
getSSIDUsingSecpolTool $1
|
|
res=$?
|
|
if [ "$res" != "0" ]; then
|
|
translateSSIDREF $ssid $mapfile
|
|
else
|
|
echo "Could not determine the SSID of the domain."
|
|
fi
|
|
else
|
|
echo "Could not find map file for policy '$policy'."
|
|
fi
|
|
elif [ "$mode" == "sid" ]; then
|
|
if [ "$2" == "" ]; then
|
|
findGrubConf
|
|
ret=$?
|
|
if [ $ret -eq 0 ]; then
|
|
echo "Could not find grub.conf"
|
|
exit -1;
|
|
fi
|
|
findPolicyInGrub $grubconf
|
|
if [ "$policy" != "" ]; then
|
|
echo "Assuming policy to be '$policy'.";
|
|
else
|
|
echo "Could not find policy."
|
|
exit -1;
|
|
fi
|
|
else
|
|
policy=$2
|
|
fi
|
|
findMapFile $policy
|
|
res=$?
|
|
if [ "$res" != "0" ]; then
|
|
translateSSIDREF $1 $mapfile
|
|
else
|
|
echo "Could not find map file for policy '$policy'."
|
|
fi
|
|
|
|
else
|
|
usage
|
|
fi
|