X-Git-Url: https://codewiz.org/gitweb?a=blobdiff_plain;f=src%2Fmonkeysphere;h=c00370640356edcbfd859dfed2e7057b339b9ca5;hb=691e5d2ec8efeb4d77b17b1ad852fdbec31ce136;hp=da10c204e5ca9cb86dbec3c19666e40ed09f064e;hpb=f12a516aa8dce8d1e951f3c47481abe960366f5b;p=monkeysphere.git diff --git a/src/monkeysphere b/src/monkeysphere index da10c20..c003706 100755 --- a/src/monkeysphere +++ b/src/monkeysphere @@ -1,9 +1,11 @@ -#!/bin/bash +#!/usr/bin/env bash # monkeysphere: MonkeySphere client tool # # The monkeysphere scripts are written by: # Jameson Rollins +# Jamie McClelland +# Daniel Kahn Gillmor # # They are Copyright 2008, and are all released under the GPL, version 3 # or later. @@ -11,11 +13,11 @@ ######################################################################## PGRM=$(basename $0) -SHARE=${MONKEYSPHERE_SHARE:-"/usr/share/monkeysphere"} -export SHARE -. "${SHARE}/common" || exit 1 +SYSSHAREDIR=${MONKEYSPHERE_SYSSHAREDIR:-"/usr/share/monkeysphere"} +export SYSSHAREDIR +. "${SYSSHAREDIR}/common" || exit 1 -# date in UTF format if needed +# UTC date in ISO 8601 format if needed DATE=$(date -u '+%FT%T') # unset some environment variables that could screw things up @@ -32,9 +34,9 @@ umask 077 ######################################################################## usage() { - cat <&2 usage: $PGRM [options] [args] -MonkeySphere client tool. +Monkeysphere client tool. subcommands: update-known_hosts (k) [HOST]... update known_hosts file @@ -61,15 +63,6 @@ gen_subkey(){ keyExpire= # get options - TEMP=$(getopt -o l:e: -l length:,expire: -n "$PGRM" -- "$@") - - if [ $? != 0 ] ; then - exit 1 - fi - - # Note the quotes around `$TEMP': they are essential! - eval set -- "$TEMP" - while true ; do case "$1" in -l|--length) @@ -80,10 +73,11 @@ gen_subkey(){ keyExpire="$2" shift 2 ;; - --) - shift - ;; - *) + *) + if [ "$(echo "$1" | cut -c 1)" = '-' ] ; then + failure "Unknown option '$1'. +Type '$PGRM help' for usage." + fi break ;; esac @@ -91,7 +85,7 @@ gen_subkey(){ if [ -z "$1" ] ; then # find all secret keys - keyID=$(gpg --with-colons --list-secret-keys | grep ^sec | cut -f5 -d:) + keyID=$(gpg --with-colons --list-secret-keys | grep ^sec | cut -f5 -d: | sort -u) # if multiple sec keys exist, fail if (( $(echo "$keyID" | wc -l) > 1 )) ; then echo "Multiple secret keys found:" @@ -113,7 +107,7 @@ key before joining the monkeysphere. You can do this with: # fail if multiple sec lines are returned, which means the id # given is not unique - if [ $(echo "$gpgOut" | grep '^sec:' | wc -l) -gt '1' ] ; then + if [ $(echo "$gpgOut" | grep -c '^sec:') -gt '1' ] ; then failure "Key ID '$keyID' is not unique." fi @@ -144,8 +138,8 @@ save EOF ) - log "generating subkey..." - fifoDir=$(mktemp -d) + log verbose "generating subkey..." + fifoDir=$(mktemp -d ${TMPDIR:-/tmp}/tmp.XXXXXXXXXX) (umask 077 && mkfifo "$fifoDir/pass") echo "$editCommands" | gpg --passphrase-fd 3 3< "$fifoDir/pass" --expert --command-fd 0 --edit-key "$keyID" & @@ -153,10 +147,10 @@ EOF rm -rf "$fifoDir" wait - log "done." + log verbose "done." } -function subkey_to_ssh_agent() { +subkey_to_ssh_agent() { # try to add all authentication subkeys to the agent: local sshaddresponse @@ -170,7 +164,7 @@ function subkey_to_ssh_agent() { if ! test_gnu_dummy_s2k_extension ; then failure "Your version of GnuTLS does not seem capable of using with gpg's exported subkeys. -You may want to consider patching or upgrading. +You may want to consider patching or upgrading to GnuTLS 2.6 or later. For more details, see: http://lists.gnu.org/archive/html/gnutls-devel/2008-08/msg00005.html" @@ -208,7 +202,7 @@ You might want to run 'gpg --gen-key'." You might want to 'monkeysphere gen-subkey'" fi - workingdir=$(mktemp -d) + workingdir=$(mktemp -d ${TMPDIR:-/tmp}/tmp.XXXXXXXXXX) umask 077 mkfifo "$workingdir/passphrase" keysuccess=1 @@ -268,10 +262,10 @@ unset HASH_KNOWN_HOSTS unset AUTHORIZED_KEYS # load global config -[ -r "${ETC}/monkeysphere.conf" ] && . "${ETC}/monkeysphere.conf" +[ -r "${SYSCONFIGDIR}/monkeysphere.conf" ] && . "${SYSCONFIGDIR}/monkeysphere.conf" # set monkeysphere home directory -MONKEYSPHERE_HOME=${MONKEYSPHERE_HOME:="${HOME}/.config/monkeysphere"} +MONKEYSPHERE_HOME=${MONKEYSPHERE_HOME:="${HOME}/.monkeysphere"} mkdir -p -m 0700 "$MONKEYSPHERE_HOME" # load local config @@ -279,6 +273,7 @@ mkdir -p -m 0700 "$MONKEYSPHERE_HOME" # set empty config variables with ones from the environment, or from # config file, or with defaults +LOG_LEVEL=${MONKEYSPHERE_LOG_LEVEL:=${LOG_LEVEL:="INFO"}} GNUPGHOME=${MONKEYSPHERE_GNUPGHOME:=${GNUPGHOME:="${HOME}/.gnupg"}} KEYSERVER=${MONKEYSPHERE_KEYSERVER:="$KEYSERVER"} # if keyserver not specified in env or monkeysphere.conf, @@ -304,6 +299,7 @@ REQUIRED_USER_KEY_CAPABILITY=${MONKEYSPHERE_REQUIRED_USER_KEY_CAPABILITY:="a"} # permissions export GNUPGHOME mkdir -p -m 0700 "$GNUPGHOME" +export LOG_LEVEL # get subcommand COMMAND="$1" @@ -314,10 +310,12 @@ case $COMMAND in 'update-known_hosts'|'update-known-hosts'|'k') MODE='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") + # check permissions on the known_hosts file path - if ! check_key_file_permissions "$USER" "$KNOWN_HOSTS" ; then - failure "Improper permissions on known_hosts file path." - fi + check_key_file_permissions "$USER" "$KNOWN_HOSTS" || failure # if hosts are specified on the command line, process just # those hosts @@ -330,7 +328,7 @@ case $COMMAND in else # exit if the known_hosts file does not exist if [ ! -e "$KNOWN_HOSTS" ] ; then - log "known_hosts file '$KNOWN_HOSTS' does not exist." + log error "known_hosts file '$KNOWN_HOSTS' does not exist." exit fi @@ -343,18 +341,14 @@ case $COMMAND in MODE='authorized_keys' # check permissions on the authorized_user_ids file path - if ! check_key_file_permissions "$USER" "$AUTHORIZED_USER_IDS" ; then - failure "Improper permissions on authorized_user_ids file path." - fi + check_key_file_permissions "$USER" "$AUTHORIZED_USER_IDS" || failure # check permissions on the authorized_keys file path - if ! check_key_file_permissions "$USER" "$AUTHORIZED_KEYS" ; then - failure "Improper permissions on authorized_keys file path." - fi + check_key_file_permissions "$USER" "$AUTHORIZED_KEYS" || failure # exit if the authorized_user_ids file is empty if [ ! -e "$AUTHORIZED_USER_IDS" ] ; then - log "authorized_user_ids file '$AUTHORIZED_USER_IDS' does not exist." + log error "authorized_user_ids file '$AUTHORIZED_USER_IDS' does not exist." exit fi