X-Git-Url: https://codewiz.org/gitweb?a=blobdiff_plain;f=src%2Fmonkeysphere-server;h=693c062d5554fd858a8671e1fb303536d86a6f4c;hb=e4c99f298bd4e7451b3ba0a9d08a4eda9583d544;hp=ffb34522bd60ab264b0d05ef8a8bc778defee4f5;hpb=ad0a9cc0958b30f5be851453ea22c151097fad0c;p=monkeysphere.git diff --git a/src/monkeysphere-server b/src/monkeysphere-server index ffb3452..693c062 100755 --- a/src/monkeysphere-server +++ b/src/monkeysphere-server @@ -1,4 +1,4 @@ -#!/bin/sh +#!/bin/bash # monkeysphere-server: MonkeySphere server admin tool # @@ -28,14 +28,14 @@ GREP_OPTIONS= usage() { cat < [args] -Monkeysphere server admin tool. +MonkeySphere server admin tool. subcommands: update-users (s) [USER]... update users authorized_keys files - gen-key (g) generate gpg key for the server + gen-key (g) [HOSTNAME] generate gpg key for the server + show-fingerprint (f) show server's host key fingerprint publish-key (p) publish server key to keyserver trust-keys (t) KEYID... mark keyids as trusted - update-user-userids (u) USER UID... add/update userids for a user help (h,?) this help EOF @@ -43,14 +43,26 @@ EOF # generate server gpg key gen_key() { + local hostName + + hostName=${1:-$(hostname --fqdn)} + # set key defaults KEY_TYPE=${KEY_TYPE:-"RSA"} KEY_LENGTH=${KEY_LENGTH:-"2048"} - KEY_USAGE=${KEY_USAGE:-"encrypt,auth"} - SERVICE=${SERVICE:-"ssh"} - HOSTNAME_FQDN=${HOSTNAME_FQDN:-$(hostname -f)} + KEY_USAGE=${KEY_USAGE:-"auth"} + cat < = key expires in n days + w = key expires in n weeks + m = key expires in n months + y = key expires in n years +EOF + read -p "Key is valid for? ($EXPIRE) " EXPIRE; EXPIRE=${EXPIRE:-"0"} - USERID=${USERID:-"$SERVICE"://"$HOSTNAME_FQDN"} + SERVICE=${SERVICE:-"ssh"} + USERID=${USERID:-"$SERVICE"://"$hostName"} # set key parameters keyParameters=$(cat </dev/null ; then + error "----- unknown user '$uname' -----" + continue + fi + + # set authorized_user_ids variable, + # translate ssh-style path variables + authorizedUserIDs=$(translate_ssh_variables "$uname" "$AUTHORIZED_USER_IDS") + + # skip user if authorized_user_ids file does not exist + if [ ! -f "$authorizedUserIDs" ] ; then + continue + fi + log "----- user: $uname -----" - AUTHORIZED_USER_IDS="$MS_HOME"/authorized_user_ids/"$uname" - msAuthorizedKeys="$CACHE"/"$uname"/authorized_keys - cacheDir="$CACHE"/"$uname"/user_keys + # temporary authorized_keys file + AUTHORIZED_KEYS=$(mktemp) - # make sure authorized_user_ids file exists - if [ ! -s "$AUTHORIZED_USER_IDS" ] ; then - log "authorized_user_ids file for '$uname' is empty or does not exist." + # skip if the user's authorized_user_ids file is empty + if [ ! -s "$authorizedUserIDs" ] ; then + log "authorized_user_ids file '$authorizedUserIDs' is empty." continue fi - # set user-controlled authorized_keys file path - if [ "$USER_CONTROLLED_AUTHORIZED_KEYS" ] ; then - userHome=$(getent passwd "$uname" | cut -d: -f6) - userAuthorizedKeys=${USER_CONTROLLED_AUTHORIZED_KEYS/\%h/"$userHome"} + # process authorized_user_ids file + log "processing authorized_user_ids file..." + process_authorized_user_ids "$authorizedUserIDs" + + # add user-controlled authorized_keys file path if specified + if [ "$USER_CONTROLLED_AUTHORIZED_KEYS" != '-' ] ; then + userAuthorizedKeys=$(translate_ssh_variables "$uname" "$USER_CONTROLLED_AUTHORIZED_KEYS") + if [ -f "$userAuthorizedKeys" ] ; then + log -n "adding user's authorized_keys file... " + cat "$userAuthorizedKeys" >> "$AUTHORIZED_KEYS" + loge "done." + fi fi - # update authorized_keys - update_authorized_keys "$msAuthorizedKeys" "$userAuthorizedKeys" "$cacheDir" - done + # move the temp authorized_keys file into place + mv -f "$AUTHORIZED_KEYS" "${CACHE}/authorized_keys/${uname}" - log "----- done. -----" + log "authorized_keys file updated." + done ;; 'gen-key'|'g') - gen_key + gen_key "$1" + ;; + + 'show-fingerprint'|'f') + fingerprint_server_key ;; 'publish-key'|'p') publish_server_key ;; - 'trust-keys'|'t') + 'trust-keys'|'trust-key'|'t') if [ -z "$1" ] ; then - failure "you must specify at least one key to trust." + failure "You must specify at least one key to trust." fi + + # process key IDs for keyID ; do trust_key "$keyID" done ;; - 'update-user-userids'|'u') - uname="$1" - shift - if [ -z "$uname" ] ; then - failure "you must specify user." - fi - if [ -z "$1" ] ; then - failure "you must specify at least one userid." - fi - AUTHORIZED_USER_IDS="$MS_HOME"/authorized_user_ids/"$uname" - cacheDir="$CACHE"/"$uname"/user_keys - for userID ; do - update_userid "$userID" "$cacheDir" - done - ;; - 'help'|'h'|'?') usage ;; @@ -198,3 +241,5 @@ case $COMMAND in Type '$PGRM help' for usage." ;; esac + +exit "$ERR"