simplifying find_host_user_id function.
[monkeysphere.git] / src / share / mh / revoke_hostname
1 # -*-shell-script-*-
2 # This should be sourced by bash (though we welcome changes to make it POSIX sh compliant)
3
4 # Monkeysphere host revoke-hostname subcommand
5 #
6 # The monkeysphere scripts are written by:
7 # Jameson Rollins <jrollins@finestructure.net>
8 # Jamie McClelland <jm@mayfirst.org>
9 # Daniel Kahn Gillmor <dkg@fifthhorseman.net>
10 #
11 # They are Copyright 2008-2009, and are all released under the GPL,
12 # version 3 or later.
13
14 # revoke hostname user ID from host key
15
16 revoke_hostname() {
17
18 local userID
19 local fingerprint
20 local tmpuidMatch
21 local line
22 local message
23 local revuidCommand
24
25 if [ -z "$1" ] ; then
26     failure "You must specify a hostname to revoke."
27 fi
28
29 userID="ssh://${1}"
30
31 # make sure the user ID to revoke
32 find_host_userid "$userID" || \
33     failure "No non-revoked user ID found matching '$userID'."
34
35 if [ "$PROMPT" = "true" ] ; then
36     printf "The following host key user ID will be revoked:\n  %s\nAre you sure you would like to revoke this user ID? (Y/n) " "$userID" >&2
37     read OK; OK=${OK:=Y}
38     if [ "${OK/y/Y}" != 'Y' ] ; then
39         failure "User ID not revoked."
40     fi
41 else
42     log debug "revoking user ID without prompting."
43 fi
44
45 # actually revoke:
46 if <"$GNUPGHOME_HOST/secring.gpg" "$SYSSHAREDIR/keytrans" revokeuserid \
47     "$HOST_FINGERPRINT" "$userID" | gpg_host --import ; then
48     gpg_host --check-trustdb
49
50     update_gpg_pub_file
51
52     show_key
53
54     echo
55     echo "NOTE: User ID revoked, but revocation not published."
56     echo "Run '$PGRM publish-key' to publish the revocation."
57 else
58     failure "Problem revoking user ID."
59 fi
60
61 }