X-Git-Url: https://codewiz.org/gitweb?a=blobdiff_plain;ds=sidebyside;f=src%2Fshare%2Fcommon;h=c10e71b5c3f87485ef9e64966db50a3af8948a8d;hb=72721ebd269341e82b8e477d78a7f041d3639129;hp=1ce07fc3e70fcb2417a62ccefb9f4204466b614e;hpb=792b299e0850dfa3ab1072760f9e82febd81c366;p=monkeysphere.git diff --git a/src/share/common b/src/share/common index 1ce07fc..c10e71b 100644 --- a/src/share/common +++ b/src/share/common @@ -254,7 +254,7 @@ check_capability() { file_hash() { if type md5sum &>/dev/null ; then md5sum "$1" - elif type lockfile &>/dev/null ; then + elif type md5 &>/dev/null ; then md5 "$1" else failure "Neither md5sum nor md5 are in the path!" @@ -291,7 +291,8 @@ Please specify how long the key should be valid. y = key expires in n years EOF while [ -z "$keyExpire" ] ; do - read -p "Key is valid for? (0) " keyExpire + printf "Key is valid for? (0) " >&2 + read keyExpire if ! test_gpg_expire ${keyExpire:=0} ; then echo "invalid value" >&2 unset keyExpire @@ -390,7 +391,7 @@ translate_ssh_variables() { path="$2" # get the user's home directory - userHome=$(getent passwd "$uname" | cut -d: -f6) + userHome=$(get_homedir "$uname") # translate '%u' to user name path=${path/\%u/"$uname"} @@ -425,6 +426,12 @@ check_key_file_permissions() { log debug "checking path permission '$path'..." + # rewrite path if it points to a symlink + if [ -h "$path" ] ; then + path=$(readlink -f "$path") + log debug "checking path symlink '$path'..." + fi + # return 255 if cannot stat file if ! stat=$(ls -ld "$path" 2>/dev/null) ; then log error "could not stat path '$path'." @@ -458,6 +465,31 @@ check_key_file_permissions() { fi } +# return a list of all users on the system +list_users() { + if type getent &>/dev/null ; then + # for linux and FreeBSD systems + getent passwd | cut -d: -f1 + elif type dscl &>/dev/null ; then + # for Darwin systems + dscl localhost -list /Search/Users + else + failure "Neither getent or dscl is in the path! Could not determine list of users." + fi +} + +# return the path to the home directory of a user +get_homedir() { + local uname=${1:-`whoami`} + eval "echo ~${uname}" +} + +# return the primary group of a user +get_primary_group() { + local uname=${1:-`whoami`} + groups "$uname" | sed 's/^..* : //' | awk '{ print $1 }' +} + ### CONVERSION UTILITIES # output the ssh key for a given key ID @@ -864,7 +896,10 @@ update_known_hosts() { # touch the known_hosts file so that the file permission check # below won't fail upon not finding the file - (umask 0022 && touch "$KNOWN_HOSTS") + if [ ! -f "$KNOWN_HOSTS" ]; then + [ -d $(dirname "$KNOWN_HOSTS") ] || mkdir -m 0700 $(dirname "$KNOWN_HOSTS") + touch "$KNOWN_HOSTS" + fi # check permissions on the known_hosts file path check_key_file_permissions $(whoami) "$KNOWN_HOSTS" || failure