aboutsummaryrefslogtreecommitdiff
path: root/firma
diff options
context:
space:
mode:
authorrhatto <rhatto>2006-10-12 18:24:29 +0000
committerrhatto <rhatto>2006-10-12 18:24:29 +0000
commitad25db92e7977f381b1b98a428560cd607b2476d (patch)
tree27c1beb56381a601d016e36cfa8b376db32f9c7d /firma
parent534f3e939ccddda3639ab0eae3bb2acf60924484 (diff)
downloadfirma-ad25db92e7977f381b1b98a428560cd607b2476d.tar.gz
firma-ad25db92e7977f381b1b98a428560cd607b2476d.tar.bz2
new config file evaluation scheme
Diffstat (limited to 'firma')
-rwxr-xr-xfirma246
1 files changed, 169 insertions, 77 deletions
diff --git a/firma b/firma
index 0d70a62..1e96e2d 100755
--- a/firma
+++ b/firma
@@ -16,78 +16,6 @@
# this program; if not, write to the Free Software Foundation, Inc., 59 Temple
# Place - Suite 330, Boston, MA 02111-1307, USA
#
-# Usage:
-#
-# All firma parameters are passed through two different configuration files:
-# firma.conf, containing general parameters needed to run the script, and a list
-# specific file, containing its address, administrator(s), etc. In both files
-# you should enter PARAMETER='value' (without spaces before or after the equal
-# sign).
-#
-# firma.conf should contain the following parameters:
-#
-# GPG_BINARY= path to the GnuPG binary
-# MAIL_AGENT= path to the mail transport agent to be used (e.g., sendmail)
-# MAIL_AGENT_ARGS= command-line arguments to be passed to the command above
-# LISTS_DIR= path to the mailing lists directory
-#
-# And it may contain the following optional parameters:
-#
-# USER= user that runs firma (usually the same as your MTA user);
-# defaults to "nobody"; you can also specify this parameter
-# in each mailing list config file if you plan to have one
-# user per mailing list
-# GROUP= group that runs firma (usually the same as your MTA group);
-# defaults to "nobody"; you can also specify this parameter
-# in each mailing list config file if you plan to have one
-# group per mailing list
-# LOG_TO_SYSLOG= set to "1" to log errors and warnings to syslog, else firma
-# will print errors to STDERR
-# LOGGER_BINARY= if logging to syslog, set the path to logger's binary
-# SYSLOG_PRIORITY= if logging to syslog, set a priority for the error messages
-# (defaults to "user.err")
-# USE_GPG_HIDDEN_RECIPIENT_OPTION= set to '1' to use GnuPG's --hidden-recipient
-# option, available from version 1.4.0 onwards
-# (try 'man gpg' for more information)
-# REMOVE_THESE_HEADERS_ON_ALL_LISTS= headers that should be stripped from list
-# 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:
-#
-# LIST_ADDRESS= list's email address
-# LIST_ADMIN= list's administrators email addresses (space separated)
-# LIST_HOMEDIR= list's GnuPG homedir, where the list's keyrings are located
-# PASSPHRASE= passphrase for the list's private keyring
-#
-# And it may contain the following optional parameters:
-#
-# SUBJECT_PREFIX= prefix to be included in the subject of list messages
-# REMOVE_THESE_HEADERS= headers that should be stripped from list messages
-# (space separated case-insensitive entries)
-# (may include regexps (e.g., X-.*)
-# REPLIES_SHOULD_GO_TO_LIST= set to '1' to add a Reply-To header containing the
-# list address
-# SILENTLY_DISCARD_INVALID_MESSAGES= set to '1' to silently discard invalid
-# 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)
-# REQUIRE_SIGNATURE= wheter messages sent to the list should be (yes) or dont
-# need to be signed to be processed (no); defaults to yes;
-# this doesnt affect the way email administration works,
-# when signature is mandatory
-#
-# 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
-# 25 characters long, combining numbers, upper and lower case letters and at
-# least 5 special characters. Also, no character can be sequentially repeated
-# more than 4 times.
-#
function Usage {
#-------------------------------------------------------------
@@ -116,6 +44,8 @@ Tasks can be one or more of the following:
use EMAIL-ADDRESS use the given address for message delivery instead
of the primary address on key
+For help in config file paramaters, type $(basename $0) --help config
+
Report bugs to <firma@sarava.org>, encrypting the message using the
public key 0xD68AFEDC available at keyserver.noreply.org."
}
@@ -1921,6 +1851,155 @@ Content-Transfer-Encoding: quoted-printable
$MESSAGE_BODY"
}
+
+function EvalConfigParameter {
+ #-------------------------------------------------------------
+ # eval parameters from a config file
+ #
+ # parameter(s): <config-file> <parameter>
+ # depends on function(s): none
+ # returns: 0 on success
+ # 1 if config file not found or missing parameter
+ #-------------------------------------------------------------
+
+ if [ ! -f "$1" ]; then
+ echo "WARNING: file not found: $1"
+ return 1
+ elif [ -z "$2" ]; then
+ echo "WARNING: missing parameters on EvalConfigParameters."
+ return 1
+ fi
+
+ echo `grep -e "^$2=" $1 | cut -d = -f 2 | sed -e 's/"//g' -e "s/'//g" | cut -d "#" -f 1 | sort -r | head -n 1`
+}
+
+
+function SourceFirmaConfig {
+ #-------------------------------------------------------------
+ # load firma.conf and set up global variables
+ #
+ # parameter(s): none for evaluation, help to show all config parameters
+ # depends on function(s): none
+ # returns: 0
+ #-------------------------------------------------------------
+
+ [ "$1" == "help" ] && echo -e "List mandatory firma config parameters\n\n"
+
+ [ "$1" == "help" ] && echo "GPG_BINARY= path to the GnuPG binary" || \
+ GPG_BINARY="`EvalConfigParameter $FIRMA_CONFIG_FILE GPG_BINARY`"
+
+ [ "$1" == "help" ] && echo "MAIL_AGENT= path to the mail transport agent to be used (e.g., sendmail)" || \
+ MAIL_AGENT="`EvalConfigParameter $FIRMA_CONFIG_FILE MAIL_AGENT`"
+
+ [ "$1" == "help" ] && echo "MAIL_AGENT_ARGS= command-line arguments to be passed to the command above" || \
+ MAIL_AGENT_ARGS="`EvalConfigParameter $FIRMA_CONFIG_FILE MAIL_AGENT_ARGS`"
+
+ [ "$1" == "help" ] && echo "LISTS_DIR= path to the mailing lists directory" || \
+ LISTS_DIR="`EvalConfigParameter $FIRMA_CONFIG_FILE LISTS_DIR`"
+
+ [ "$1" == "help" ] && echo -e "List optional firma config parameters\n\n"
+
+ [ "$1" == "help" ] && echo "USER= user that runs firma (usually the same as your MTA user);
+ defaults to "nobody"; you can also specify this parameter
+ in each mailing list config file if you plan to have one
+ user per mailing list" || \
+ USER="`EvalConfigParameter $FIRMA_CONFIG_FILE USER`"
+
+ [ "$1" == "help" ] && echo "GROUP= group that runs firma (usually the same as your MTA group);
+ defaults to "nobody"; you can also specify this parameter
+ in each mailing list config file if you plan to have one
+ group per mailing list" || \
+ GROUP="`EvalConfigParameter $FIRMA_CONFIG_FILE GROUP`"
+
+ [ "$1" == "help" ] && echo "LOG_TO_SYSLOG= set to "1" to log errors and warnings to syslog, else firma
+ will print errors to STDERR" || \
+ LOG_TO_SYSLOG="`EvalConfigParameter $FIRMA_CONFIG_FILE LOG_TO_SYSLOG`"
+
+ [ "$1" == "help" ] && echo "LOGGER_BINARY= if logging to syslog, set the path to logger's binary" || \
+ LOGGER_BINARY="`EvalConfigParameter $FIRMA_CONFIG_FILE LOGGER_BINARY`"
+
+ [ "$1" == "help" ] && echo "SYSLOG_PRIORITY= if logging to syslog, set a priority for the error messages
+ (defaults to "user.err")" || \
+ SYSLOG_PRIORITY="`EvalConfigParameter $FIRMA_CONFIG_FILE SYSLOG_PRIORITY`"
+
+ [ "$1" == "help" ] && echo "USE_GPG_HIDDEN_RECIPIENT_OPTION= set to '1' to use GnuPG's --hidden-recipient
+ option, available from version 1.4.0 onwards
+ (try 'man gpg' for more information)" || \
+ USE_GPG_HIDDEN_RECIPIENT_OPTION="`EvalConfigParameter $FIRMA_CONFIG_FILE USE_GPG_HIDDEN_RECIPIENT_OPTION`"
+
+ [ "$1" == "help" ] && echo "REMOVE_THESE_HEADERS_ON_ALL_LISTS= headers that should be stripped from list
+ messages on all lists running under firma
+ (space separated case-insensitive entries)
+ (may include regexps (e.g., X-.*)" || \
+ REMOVE_THESE_HEADERS_ON_ALL_LISTS="`EvalConfigParameter $FIRMA_CONFIG_FILE REMOVE_THESE_HEADERS_ON_ALL_LISTS`"
+
+ [ "$1" == "help" ] && echo "KEYSERVER= default keyserver to import/export keys
+ (defaults to keyserver.noreply.org)" || \
+ KEYSERVER="`EvalConfigParameter $FIRMA_CONFIG_FILE KEYSERVER`"
+}
+
+
+function SourceListConfig {
+ #-------------------------------------------------------------
+ # load list.conf and set up global variables
+ #
+ # parameter(s): none for evaluation, help to show all config parameters
+ # depends on function(s): none
+ # returns: 0
+ #-------------------------------------------------------------
+
+ [ "$1" == "help" ] && echo -e "List mandatory list config parameters\n\n"
+
+ [ "$1" == "help" ] && echo "LIST_ADDRESS= list's email address" || \
+ LIST_ADDRESS="`EvalConfigParameter $LIST_CONFIG_FILE LIST_ADDRESS`"
+
+ [ "$1" == "help" ] && echo "LIST_ADMIN= list's administrators email addresses (space separated)" || \
+ LIST_ADMIN="`EvalConfigParameter $LIST_CONFIG_FILE LIST_ADMIN`"
+
+ [ "$1" == "help" ] && echo "LIST_HOMEDIR= list's GnuPG homedir, where the list's keyrings are located" || \
+ LIST_HOMEDIR="`EvalConfigParameter $LIST_CONFIG_FILE LIST_HOMEDIR`"
+
+ [ "$1" == "help" ] && echo " PASSPHRASE= passphrase for the list's private keyring
+
+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
+25 characters long, combining numbers, upper and lower case letters and at
+least 5 special characters. Also, no character can be sequentially repeated
+more than 4 times." || \
+ LIST_PASSPHRASE="`EvalConfigParameter $LIST_CONFIG_FILE LIST_PASSPHRASE`"
+
+ [ "$1" == "help" ] && echo -e "List optional list config parameters\n\n"
+
+ [ "$1" == "help" ] && echo "SUBJECT_PREFIX= prefix to be included in the subject of list messages" || \
+ SUBJECT_PREFIX="`EvalConfigParameter $LIST_CONFIG_FILE SUBJECT_PREFIX`"
+
+ [ "$1" == "help" ] && \
+ echo "REMOVE_THESE_HEADERS= headers that should be stripped from list messages
+ (space separated case-insensitive entries)
+ (may include regexps (e.g., X-.*)" || \
+ REMOVE_THESE_HEADERS="`EvalConfigParameter $LIST_CONFIG_FILE REMOVE_THESE_HEADERS`"
+
+ [ "$1" == "help" ] && echo "REPLIES_SHOULD_GO_TO_LIST= set to '1' to add a Reply-To header containing the list address" || \
+ REPLIES_SHOULD_GO_TO_LIST="`EvalConfigParameter $LIST_CONFIG_FILE REPLIES_SHOULD_GO_TO_LIST`"
+
+ [ "$1" == "help" ] && \
+ echo "SILENTLY_DISCARD_INVALID_MESSAGES= set to '1' to silently discard invalid
+ messages (message not signed/encrypted,
+ sender not subscribed to the list, etc.)
+ instead of sending bounces back to sender" || \
+ SILENTLY_DISCARD_INVALID_MESSAGES="`EvalConfigParameter $LIST_CONFIG_FILE SILENTLY_DISCARD_INVALID_MESSAGES`"
+
+ [ "$1" == "help" ] && echo "KEYSERVER= default keyserver to import/export keys
+ (defaults to keyserver.noreply.org)" || \
+ KEYSERVER="`EvalConfigParameter $LIST_CONFIG_FILE KEYSERVER`"
+
+ [ "$1" == "help" ] && echo "REQUIRE_SIGNATURE= wheter messages sent to the list should be (yes) or dont
+ need to be signed to be processed (no); defaults to yes;
+ this doesnt affect the way email administration works,
+ when signature is mandatory" || \
+ REQUIRE_SIGNATURE="`EvalConfigParameter $LIST_CONFIG_FILE REQUIRE_SIGNATURE`"
+}
+
#-------------------------------------------------------------
# main()
#-------------------------------------------------------------
@@ -1998,7 +2077,11 @@ FUNCTIONS="
RandomString
AdminLog
EmailListAdministration
- MimeWrapMessage"
+ MimeWrapMessage
+ CreateMessageBodyPart
+ EvalConfigParameter
+ SourceFirmaConfig
+ SourceListConfig"
for VAR in $GLOBAL_VARS; do
declare $VAR
@@ -2049,7 +2132,7 @@ case $# in
if [ -f "$FIRMA_CONFIG_FILE" ]; then
# evaluate its parameters
- shopt -u sourcepath && source "$FIRMA_CONFIG_FILE"
+ SourceFirmaConfig
# set SYSLOG_PRIORITY to the default value, if needed
if [[ "$LOG_TO_SYSLOG" == 1 ]]; then
@@ -2074,9 +2157,8 @@ case $# in
# if config file exists but has wrong permissions or ownership
if [[ -f "$LIST_CONFIG_FILE" ]]; then
- # if the configuration file exists, disable bash's
- #+sourcepath and evaluate list parameters
- shopt -u sourcepath && source "$LIST_CONFIG_FILE"
+ # eval list parameters
+ SourceListConfig
CheckListPermissions $LIST_CONFIG_FILE
@@ -2128,6 +2210,16 @@ case $# in
;;
# valid option called with too many arguments
-h|--help|-v|--version)
+ if [ "$1" == "-h" ] || [ "$1" == "--help" ]; then
+ if [ "$2" == "config" ]; then
+ echo "All firma parameters are passed through two different configuration files:"
+ echo "firma.conf, containing general parameters needed to run the script, and a list"
+ echo "specific file, containing its address, administrator(s), etc. In both files"
+ echo "you should enter PARAMETER='value' (without spaces before or after the equal sign)."
+ SourceFirmaConfig help
+ SourceListConfig help
+ fi
+ fi
echo >&2 "$(basename $0): too many arguments -- $@"
Usage
EXIT_CODE=1