aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rwxr-xr-xfirma46
1 files changed, 42 insertions, 4 deletions
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
}