improve function to get primary group to make it more portable
[monkeysphere.git] / src / share / common
index f954bb94a071d6d78891878d526be950bbe488b1..76b539f4ab89dc9ddd8d585a751f64ed4f514430 100644 (file)
@@ -425,6 +425,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'."
@@ -466,6 +472,8 @@ list_users() {
     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
 }
 
@@ -475,6 +483,12 @@ get_homedir() {
     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