replace stat with ls (sigh) and make su more portable.
[monkeysphere.git] / src / monkeysphere-server
index e590f3cdd3469ab0104ce231ff054bed45542d20..6798fab185da534060695843f09efbe12a676c3e 100755 (executable)
@@ -67,7 +67,7 @@ EOF
 }
 
 su_monkeysphere_user() {
-    su --preserve-environment "$MONKEYSPHERE_USER" -- -c "$@"
+    su -m "$MONKEYSPHERE_USER" -c "$@"
 }
 
 # function to interact with the host gnupg keyring
@@ -267,7 +267,7 @@ gen_key() {
     revoker=
 
     # get options
-    TEMP=$(getopt -o e:l:r -l expire:,length:,revoker: -n "$PGRM" -- "$@")
+    TEMP=$(PATH="/usr/local/bin:$PATH" getopt -o e:l:r -l expire:,length:,revoker: -n "$PGRM" -- "$@") || failure "getopt failed!  Does your getopt support GNU-style long options?"
 
     if [ $? != 0 ] ; then
        exit 1
@@ -299,7 +299,7 @@ gen_key() {
        esac
     done
 
-    hostName=${1:-$(hostname --fqdn)}
+    hostName=${1:-$(hostname -f)}
     userID="ssh://${hostName}"
 
     # check for presense of key with user ID
@@ -545,6 +545,7 @@ publish_server_key() {
     gpg_authentication "--keyserver $KEYSERVER --send-keys '0x${fingerprint}!'"
 }
 
+
 diagnostics() {
 #  * check on the status and validity of the key and public certificates
     local seckey
@@ -566,7 +567,7 @@ diagnostics() {
     curdate=$(date +%s)
     # warn when anything is 2 months away from expiration
     warnwindow='2 months'
-    warndate=$(date +%s -d "$warnwindow")
+    warndate=$(advance_date $warnwindow +%s)
 
     if ! id monkeysphere >/dev/null ; then
        echo "! No monkeysphere user found!  Please create a monkeysphere system user."
@@ -593,7 +594,7 @@ diagnostics() {
                echo "! Host key is expired."
                echo " - Recommendation: extend lifetime of key with 'monkeysphere-server extend-key'"
            elif (( "$expire" < "$warndate" )); then
-               echo "! Host key expires in less than $warnwindow:" $(date -d "$(( $expire - $curdate )) seconds" +%F)
+               echo "! Host key expires in less than $warnwindow:" $(advance_date $(( $expire - $curdate )) seconds +%F)
                echo " - Recommendation: extend lifetime of key with 'monkeysphere-server extend-key'"
            fi
        fi
@@ -619,7 +620,7 @@ diagnostics() {
                    echo "! User ID '$uid' is expired."
                        # FIXME: recommend a way to resolve this
                elif (( "$expire" < "$warndate" )); then
-                   echo "! User ID '$uid' expires in less than $warnwindow:" $(date -d "$(( $expire - $curdate )) seconds" +%F)                
+                   echo "! User ID '$uid' expires in less than $warnwindow:" $(advance_date $(( $expire - $curdate )) seconds +%F)             
                    # FIXME: recommend a way to resolve this
                fi
            fi
@@ -641,7 +642,7 @@ diagnostics() {
        if [ ! -s "${VARLIB}/ssh_host_rsa_key" ] ; then
            echo "! The host key as prepared for SSH (${VARLIB}/ssh_host_rsa_key) is missing or empty."
        else
-           if [ $(stat -c '%a' "${VARLIB}/ssh_host_rsa_key") != 600 ] ; then
+           if [ $(ls -l "${VARLIB}/ssh_host_rsa_key" | cut -f1 -d\ ) != '-rw-------' ] ; then
                echo "! Permissions seem wrong for ${VARLIB}/ssh_host_rsa_key -- should be 0600."
            fi
 
@@ -698,7 +699,7 @@ add_certifier() {
     depth=1
 
     # get options
-    TEMP=$(getopt -o n:t:d: -l domain:,trust:,depth: -n "$PGRM" -- "$@")
+    TEMP=$(PATH="/usr/local/bin:$PATH" getopt -o n:t:d: -l domain:,trust:,depth: -n "$PGRM" -- "$@") || failure "getopt failed!  Does your getopt support GNU-style long options?"
 
     if [ $? != 0 ] ; then
        exit 1