aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorrhatto <rhatto>2006-10-09 16:21:06 +0000
committerrhatto <rhatto>2006-10-09 16:21:06 +0000
commite577c4ae2870618788936b4120aab68b0eef73ee (patch)
tree80e04bcaff6836e06328c2999a86344a4e0d476b
parentb6d24c61907994e13763af19581c48ebffde82f3 (diff)
downloadfirma-e577c4ae2870618788936b4120aab68b0eef73ee.tar.gz
firma-e577c4ae2870618788936b4120aab68b0eef73ee.tar.bz2
added subscribe and send keys functions
-rwxr-xr-xfirma167
1 files changed, 153 insertions, 14 deletions
diff --git a/firma b/firma
index 51edd34..82169dc 100755
--- a/firma
+++ b/firma
@@ -53,6 +53,8 @@
# messages on all lists running under firma
# (space separated case-insensitive entries)
# (may include regexps (e.g., X-.*)
+# KEYSERVER= default keyserver to import/export keys
+# (defaults to keyserver.noreply.org)
#
# And the list configuration file should contain:
#
@@ -73,6 +75,8 @@
# messages (message not signed/encrypted,
# sender not subscribed to the list, etc.)
# instead of sending bounces back to sender
+# KEYSERVER= default keyserver to import/export keys
+# (defaults to keyserver.noreply.org)
#
# NOTE: The passphrase _has_ to be enclosed in single quotes and _cannot_
# contain any additional single quote as part of itself. It has to be at least
@@ -196,6 +200,10 @@ WARNING: Setting LOG_TO_SYSLOG to '0'."
FIRMA_GROUP="`grep "^GROUP=" $FIRMA_CONFIG_FILE | sed -e 's/"//g' -e "s/'//g" | cut -d = -f 2`"
fi
+ if [ -z "$KEYSERVER" ]; then
+ KEYSERVER="keyserver.noreply.org"
+ fi
+
return $return_code
}
@@ -929,7 +937,8 @@ function ListAdministration {
# process administrative tasks
#
# parameter(s): task to be performed (plus its argument(s))
- # depends on function(s): ChooseUid
+ # depends on function(s): ChooseUid, CheckValidEmail, UbsubscribeUser
+ # SubscribeUsers, SendListPubkey
# returns: 0 if task is executed successfully,
# 1 if task can't be executed (command not found, too many/missing arguments, etc.),
# 2 if a quit command is entered
@@ -943,11 +952,14 @@ function ListAdministration {
help)
# this will be printed to STDOUT, so no indentation here
echo "
- 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
- unsub EMAIL-ADDRESS unsubscribe an email from the list
+ quit quit this prompt
+ help show this help
+ list show list subscribers
+ sendkey <subscriber> send list pubkey to subscriber
+ subscribe [..] subscribe users ('subscribe help' for options)
+ use EMAIL-ADDRESS use the given address for message delivery instead
+ of the primary address on key
+ unsub EMAIL-ADDRESS unsubscribe an email from the list
"
;;
quit)
@@ -961,6 +973,18 @@ function ListAdministration {
echo >&2 "$1: missing arguments (try \"help\")"
return_code=1
;;
+ list)
+ # use GetSubscribersList instead or leave a more verbose listing?
+ $GPG_LIST_KEYS
+ ;;
+ subscribe)
+ echo >&2 "$1: missing arguments (try \"subscribe help\")"
+ return_code=1
+ ;;
+ sendkey)
+ echo >&2 "$1: missing argument: subsciber email address."
+ return_code=1
+ ;;
*)
echo >&2 "Command not found -- $1 (try \"help\")"
return_code=1
@@ -987,6 +1011,15 @@ function ListAdministration {
return_code=1
fi
;;
+ subscribe)
+ shift
+ SubscribeUsers $*
+ return_code=$?
+ ;;
+ sendkey)
+ SendListPubkey $2
+ return_code=$?
+ ;;
help|quit)
echo >&2 "$1: too many arguments -- $@ (try \"help\")"
return_code=1
@@ -1103,12 +1136,12 @@ function CheckPermission {
local perms="`ls -ld $file`"
perms=${perms:4:6}
if [ "$perms" != "------" ]; then
- LogMessage "WARNING: Configuration files must not be group or world writable/readable! Dying on file $file"
+ LogMessage "WARNING: Configuration files must not be group or world writable/readable! Wrong permission for file $file"
return 1
fi
if [ `ls -ld $file | awk '{print $3}'` != "$FIRMA_USER" ]; then
- echo "WARNING: Configuration files must be owned by $FIRMA_USER! Dying on file $file"
+ echo "WARNING: Configuration files must be owned by $FIRMA_USER! Wrong ownership for file $file"
fi
return 0
@@ -1178,13 +1211,13 @@ function UnsubscribeUser {
local -i return_code=0
local keyid="$($GPG_LIST_KEYS --with-fingerprint $1 2> /dev/null | grep ^fpr | cut -d : -f 10)"
+ # check if user is trying to unsubscribe the list key
if [ "$1" == "$LIST_ADDRESS" ]; then
- # check if user is trying to unsubscribe the list key
+ echo >&2 "unsub: can't delete the list pubkey."
return_code=1
- echo >&2 "can't delete the list pubkey."
+ # check if supplied address is associated with a public key
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."
+ echo >&2 "unsub: \"$1\" is not associated with any public key on this keyring."
return_code=1
else
for key in $keyid; do
@@ -1194,7 +1227,7 @@ function UnsubscribeUser {
# now just update the trust db
$GPG_LIST_KEYS &> /dev/null
else
- echo >&2 "error deleting key id $key for $1"
+ echo >&2 "unsub: error deleting key id $key for $1"
return_code=1
fi
done
@@ -1225,6 +1258,111 @@ function LogMessage {
return 0
}
+
+function SubscribeUsers {
+ #-------------------------------------------------------------
+ # subscribe users to the list importing their pubkeys
+ #
+ # parameter(s): $1: help, stdin, keyserver or file
+ # $2: where to fetch the pubkeys
+ # $3: keyid (keyserver only)
+ # depends on function(s): none
+ # returns: 0 on success
+ # 1 on failure
+ #-------------------------------------------------------------
+
+ local -i return_code=0
+ local keyserver
+
+ if [ "$1" == "help" ]; then
+ echo "
+ help show this help
+ stdin waits for key material from stdin
+ file <file-name> import pubkeys from file
+ keyserver [server-address] <key-id> import <key-id> from <server-address>
+"
+ elif [ "$1" == "stdin" ]; then
+ echo "please paste the key material here, finninshing with Ctrl-D sequence..."
+ $GPG --import
+ elif [ "$1" == "file" ]; then
+ if [ ! -z "$2" ]; then
+ if [ -f "$2" ]; then
+ $GPG --import < $2
+ else
+ echo >&2 "subscribe: cant add subscribers from $1: no such file or directory"
+ return_code=1
+ fi
+ else
+ echo >&2 "subscribe: missing parameters: subscribe file requires a file name"
+ return_code=1
+ fi
+ elif [ "$1" == "keyserver" ]; then
+ if [ ! -z "$2" ]; then
+ if [ -z "$3" ]; then
+ keyserver="$KEYSERVER"
+ else
+ keyserver="$2"
+ shift
+ fi
+ $GPG --keyserver $keyserver --recv-keys $2
+ return_code=$?
+ else
+ echo >&2 "subscribe: missing parameters: type subscribe help"
+ return_code=1
+ fi
+ else
+ echo >&2 "subscribe: wrong option: type subscribe help"
+ return_code=1
+ fi
+
+ chown -R $FIRMA_USER.$FIRMA_GROUP $LIST_PATH
+ return $return_code
+}
+
+
+function SendListPubkey {
+ #-------------------------------------------------------------
+ # send list pubkey to a given subscriber
+ #
+ # parameter(s): subscriber email
+ # depends on function(s): GetMessage, GetSenderAddress, AssembleMessage
+ # returns: 0 on success
+ # 1 on failure
+ #-------------------------------------------------------------
+
+ local keyid="$($GPG_LIST_KEYS --with-fingerprint $1 2> /dev/null | grep ^fpr | cut -d : -f 10)"
+
+ if [ -z "$1" ]; then
+ echo >&2 "sendkey: missing argument: subscriber email address."
+ return 1
+ elif ! CheckValidEmail $1
+ echo >&2 "sendkey: \"$1\" is not an email address."
+ return 1
+ 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 "sendkey: \"$1\" is not associated with any public key on this keyring."
+ return 1
+ fi
+
+ recipients="$1"
+
+ # these are the headers of the message to be sent, so no indentation here
+ MESSAGE_HEADERS="\
+From: $LIST_ADDRESS
+Subject: List public key for $LIST_ADDRESS
+To: $recipients"
+
+ # this is the body of the message to be sent
+ MESSAGE_BODY="`$GPG --armor --export $LIST_ADDRESS`"
+
+ AssembleMessage
+
+ # send message
+ echo "$MESSAGE" | $MAIL_AGENT $MAIL_AGENT_ARGS $recipients
+ return $?
+
+}
+
#-------------------------------------------------------------
# main()
#-------------------------------------------------------------
@@ -1290,7 +1428,8 @@ FUNCTIONS="
CheckPermission
CheckListPermissions
UnsubscribeUser
- LogMessage"
+ LogMessage
+ SubscribeUsers"
for VAR in $GLOBAL_VARS; do
declare $VAR