From f43eb2af062c46cce0ae9787ccb58599734db0b4 Mon Sep 17 00:00:00 2001 From: rhatto Date: Mon, 9 Oct 2006 12:45:06 +0000 Subject: added function UnsubscribeUser --- firma | 46 ++++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 42 insertions(+), 4 deletions(-) (limited to 'firma') diff --git a/firma b/firma index 1f75e8a..d676bd6 100755 --- a/firma +++ b/firma @@ -934,7 +934,8 @@ function ListAdministration { quit quit this prompt help show this help use EMAIL-ADDRESS use the given address for message delivery instead - of the primary address on key + of the primary address on key + unsub EMAIL-ADDRESS unsubscribe an email from the list " ;; quit) @@ -1151,9 +1152,46 @@ function CheckValidEmail { function UnsubscribeUser { - # TODO: usubscribe if $1 is subscriber - # always fix list folder permissions - true + #------------------------------------------------------------- + # unsubscribe a user and remove its pubkey from + #+the list keyring + # + # parameter(s): chosen email address + # depends on function(s): DeclareGpgVars + # returns: 0 on success, + # 1 if task can't be executed (public key not found, etc.) + #------------------------------------------------------------- + + local key + local -i return_code=0 + local keyid="$($GPG_LIST_KEYS --with-fingerprint $1 2> /dev/null | grep ^fpr | cut -d : -f 10)" + local uid_count="$($GPG_LIST_KEYS --fixed-list-mode $keyid 2> /dev/null | grep ^uid | wc -l)" + local chosen_uid_number="$($GPG_LIST_KEYS --fixed-list-mode $keyid 2> /dev/null | grep ^uid | grep -ni "$1" | cut -d : -f 1)" + + if [ "$1" == "$LIST_ADDRESS" ]; then + # check if user is trying to unsubscribe the list key + return_code=1 + echo >&2 "can't delete the list pubkey." + elif [[ -z "$($GPG_LIST_KEYS --fixed-list-mode "<$1>" 2> /dev/null | grep -v '^tru:')" ]]; then + # check if supplied address is associated with a public key + echo >&2 "use: \"$1\" is not associated with any public key on this keyring." + return_code=1 + else + for key in $keyid; do + $GPG --batch --delete-key --yes $key + if [ "$?" == "0" ]; then + echo >&2 "deleted key id $key for $1" + # now just update the trust db + $GPG_LIST_KEYS &> /dev/null + else + echo >&2 "error deleting key id $key for $1" + return_code=1 + fi + done + fi + + chown -R $USER.$GROUP $LIST_PATH + return $return_code } -- cgit v1.2.3