Add two new compatibility functions:
authorJameson Graef Rollins <jrollins@finestructure.net>
Tue, 7 Apr 2009 05:40:08 +0000 (22:40 -0700)
committerJameson Graef Rollins <jrollins@finestructure.net>
Tue, 7 Apr 2009 05:40:08 +0000 (22:40 -0700)
- list_user to list all users on the system
- get_homedir to return the path to a users home directory
These functions should provide compatibility on linux, FreeBSD and
Darwin systems.

src/share/common
src/share/ma/update_users

index ac0b5d6382a9dd2c345209d0b18d605b1ee84d27..f954bb94a071d6d78891878d526be950bbe488b1 100644 (file)
@@ -390,7 +390,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"}
@@ -458,6 +458,23 @@ 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
+    fi
+}
+
+# return the path to the home directory of a user
+get_homedir() {
+    local uname=${1:-`whoami`}
+    eval "echo ~${uname}"
+}
+
 ### CONVERSION UTILITIES
 
 # output the ssh key for a given key ID
index 3a5c006e8f560f6ba2a58130bdb59bf47af659d4..c5c74cf7bbfaedff9d410146b08ccb6a8193b153 100644 (file)
@@ -24,7 +24,7 @@ if [ "$1" ] ; then
     unames="$@"
 else        
     # or just look at all users if none specified
-    unames=$(getent passwd | cut -d: -f1)
+    unames=$(list_users)
 fi
 
 # set mode