projects
/
monkeysphere.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
get rid of getopts.
[monkeysphere.git]
/
src
/
monkeysphere
diff --git
a/src/monkeysphere
b/src/monkeysphere
index e8ca9e2b08d4c7ca8c23fef1495cdba22c41bb92..c00370640356edcbfd859dfed2e7057b339b9ca5 100755
(executable)
--- a/
src/monkeysphere
+++ b/
src/monkeysphere
@@
-1,4
+1,4
@@
-#!/
bin/
bash
+#!/
usr/bin/env
bash
# monkeysphere: MonkeySphere client tool
#
# monkeysphere: MonkeySphere client tool
#
@@
-13,9
+13,9
@@
########################################################################
PGRM=$(basename $0)
########################################################################
PGRM=$(basename $0)
-S
HARE=${MONKEYSPHERE_SHARE
:-"/usr/share/monkeysphere"}
-export S
HARE
-. "${S
HARE
}/common" || exit 1
+S
YSSHAREDIR=${MONKEYSPHERE_SYSSHAREDIR
:-"/usr/share/monkeysphere"}
+export S
YSSHAREDIR
+. "${S
YSSHAREDIR
}/common" || exit 1
# UTC date in ISO 8601 format if needed
DATE=$(date -u '+%FT%T')
# UTC date in ISO 8601 format if needed
DATE=$(date -u '+%FT%T')
@@
-36,7
+36,7
@@
umask 077
usage() {
cat <<EOF >&2
usage: $PGRM <subcommand> [options] [args]
usage() {
cat <<EOF >&2
usage: $PGRM <subcommand> [options] [args]
-Monkey
S
phere client tool.
+Monkey
s
phere client tool.
subcommands:
update-known_hosts (k) [HOST]... update known_hosts file
subcommands:
update-known_hosts (k) [HOST]... update known_hosts file
@@
-63,15
+63,6
@@
gen_subkey(){
keyExpire=
# get options
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)
while true ; do
case "$1" in
-l|--length)
@@
-82,10
+73,11
@@
gen_subkey(){
keyExpire="$2"
shift 2
;;
keyExpire="$2"
shift 2
;;
- --)
- shift
- ;;
- *)
+ *)
+ if [ "$(echo "$1" | cut -c 1)" = '-' ] ; then
+ failure "Unknown option '$1'.
+Type '$PGRM help' for usage."
+ fi
break
;;
esac
break
;;
esac
@@
-147,7
+139,7
@@
EOF
)
log verbose "generating subkey..."
)
log verbose "generating subkey..."
- fifoDir=$(mktemp -d)
+ 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" &
(umask 077 && mkfifo "$fifoDir/pass")
echo "$editCommands" | gpg --passphrase-fd 3 3< "$fifoDir/pass" --expert --command-fd 0 --edit-key "$keyID" &
@@
-158,7
+150,7
@@
EOF
log verbose "done."
}
log verbose "done."
}
-
function
subkey_to_ssh_agent() {
+subkey_to_ssh_agent() {
# try to add all authentication subkeys to the agent:
local sshaddresponse
# try to add all authentication subkeys to the agent:
local sshaddresponse
@@
-172,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.
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"
For more details, see:
http://lists.gnu.org/archive/html/gnutls-devel/2008-08/msg00005.html"
@@
-210,7
+202,7
@@
You might want to run 'gpg --gen-key'."
You might want to 'monkeysphere gen-subkey'"
fi
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
umask 077
mkfifo "$workingdir/passphrase"
keysuccess=1
@@
-270,7
+262,7
@@
unset HASH_KNOWN_HOSTS
unset AUTHORIZED_KEYS
# load global config
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}/.monkeysphere"}
# set monkeysphere home directory
MONKEYSPHERE_HOME=${MONKEYSPHERE_HOME:="${HOME}/.monkeysphere"}
@@
-318,10
+310,12
@@
case $COMMAND in
'update-known_hosts'|'update-known-hosts'|'k')
MODE='known_hosts'
'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
# 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
# if hosts are specified on the command line, process just
# those hosts
@@
-347,14
+341,10
@@
case $COMMAND in
MODE='authorized_keys'
# check permissions on the authorized_user_ids file path
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
# 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
# exit if the authorized_user_ids file is empty
if [ ! -e "$AUTHORIZED_USER_IDS" ] ; then