summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLee Duncan <lduncan@suse.com>2022-04-08 08:25:18 -0700
committerLee Duncan <lduncan@suse.com>2022-04-08 08:25:18 -0700
commite1c491d59ffaeac367966b703f91eab4972a54f6 (patch)
treeefa94d391675800887c85247e9f66908b2dae382
parent92c2677008610d282d3f6240eab740f79a41a3dc (diff)
downloadopen-iscsi-e1c491d59ffaeac367966b703f91eab4972a54f6.tar.gz
Check for root in iscsi-gen-initiatorname
The man page is also updated
-rw-r--r--doc/iscsi-gen-initiatorname.8.template6
-rw-r--r--utils/iscsi-gen-initiatorname.sh.template16
2 files changed, 16 insertions, 6 deletions
diff --git a/doc/iscsi-gen-initiatorname.8.template b/doc/iscsi-gen-initiatorname.8.template
index cd26f2d..97a6e21 100644
--- a/doc/iscsi-gen-initiatorname.8.template
+++ b/doc/iscsi-gen-initiatorname.8.template
@@ -20,6 +20,12 @@ It is an error if both the kernel command-line Initiator Name
and the iBFT Initiator Name are both set, and they are different.
it is also an error to try to write over an Initiator Name file
if it read-only, or to create one if its directory is not writable.
+.P
+You
+.B must
+be
+.I root
+to run this command.
.SH OPTIONS
.TP
.BI [-h]
diff --git a/utils/iscsi-gen-initiatorname.sh.template b/utils/iscsi-gen-initiatorname.sh.template
index a06d6d0..5c2bfdf 100644
--- a/utils/iscsi-gen-initiatorname.sh.template
+++ b/utils/iscsi-gen-initiatorname.sh.template
@@ -77,7 +77,7 @@ usage_and_exit()
echo "Where OPTIONS are from:"
echo " -h print usage and exit"
echo " -f overwrite existing InitiatorName, if any"
- echo " -p IQN-PRE set the prefix for the IQN generated (default ${DEFAULT_IQN_PREFIX})"
+ echo " -p IQN-PRE set prefix for generated IQN (default ${DEFAULT_IQN_PREFIX})"
exit $xit_val
}
@@ -112,7 +112,12 @@ done
shift $(($OPTIND-1))
if [ "$#" -gt 0 ] ; then
- echo "Invalid argument(s): $*"
+ echo "Error: Invalid argument(s): $*" 1>&2
+ usage_and_exit 1
+fi
+
+if [ "$EUID" -ne 0 ] ; then
+ echo "Error: You must be root to run this command" 1>&2
usage_and_exit 1
fi
@@ -131,21 +136,20 @@ KERNEL_INAME="$(kernel_supplied_initiatorname)"
# if we have a local initiator name and "force" is not set end it now
if [ "$InitiatorName" -a -z "$FORCE" ] ; then
echo "Error: you cannot overwrite the current InitiatorName unless 'force' is set." 1>&2
- echo "Please call '$NAME -f' to update iSCSI InitiatorName, if needed." 1>&2
- exit 1
+ usage_and_exit 1
fi
# ensure we can write the initiator name file
if [ -r "$INAME_FILE" ] ; then
if [ ! -w "$INAME_FILE" ] ; then
echo "Error: cannot update InitiatorName, write protected: $INAME_FILE" 1>&1
- echo "Please ensure you are root and filesystem is read/write." 1>&2
+ echo "Please ensure the filesystem is read/write." 1>&2
exit 1
fi
# the file exists but we can write over it
elif [ ! -w "$INAME_DIR" ] ; then
echo "Error: no write permission in directory: $INAME_DIR" 1>&2
- echo "Please ensure you are root and filesystem is read/write." 1>&2
+ echo "Please ensure the filesystem is read/write." 1>&2
exit 1
fi