aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorrhatto <rhatto>2006-10-07 18:10:40 +0000
committerrhatto <rhatto>2006-10-07 18:10:40 +0000
commit231438b784d32f1c0c8b3479de452cd36e323552 (patch)
treedb3d00f72a45036b7ed6ada74ad62e74bdc82c7d
parent69dd36908b6b0d8d092e780334d4355f0a917dbe (diff)
downloadfirma-231438b784d32f1c0c8b3479de452cd36e323552.tar.gz
firma-231438b784d32f1c0c8b3479de452cd36e323552.tar.bz2
new function LogMessage and fixes on permission checking
-rwxr-xr-xfirma41
1 files changed, 27 insertions, 14 deletions
diff --git a/firma b/firma
index cba270f..1f75e8a 100755
--- a/firma
+++ b/firma
@@ -1090,12 +1090,7 @@ function CheckPermission {
local perms="`ls -ld $file`"
perms=${perms:4:6}
if [ "$perms" != "------" ]; then
- ERROR_MESSAGE="WARNING: Configuration files must not be group or world writable/readable! Dying on file $file"
- if [[ "$LOG_TO_SYSLOG" == 1 ]]; then
- echo "$ERROR_MESSAGE" | $LOGGER_BINARY -p "$SYSLOG_PRIORITY" -t "$BASENAME"
- else
- echo $ERROR_MESSAGE
- fi
+ LogMessage "WARNING: Configuration files must not be group or world writable/readable! Dying on file $file"
return 1
fi
@@ -1127,8 +1122,8 @@ function CheckListPermissions {
folder="`dirname $1`"
config="`basename $1`"
for file in $config pubring.gpg pubring.gpg~ random_seed secring.gpg trustdb.gpg; do
- if CheckPermission $folder/$file; then
- echo "Fixing permission and ownership for $folder/$file"
+ if ! CheckPermission $folder/$file; then
+ LogMessage "Fixing permission and ownership for $folder/$file"
chmod 600 $folder/$file
chown $USER.$GROUP $folder/$file
fi
@@ -1161,6 +1156,27 @@ function UnsubscribeUser {
true
}
+
+function LogMessage {
+ #-------------------------------------------------------------
+ # write a log message to stdout or to syslog
+ #
+ # parameter(s): string
+ # depends on function(s): none
+ # returns: 0
+ #-------------------------------------------------------------
+
+ local error_message
+ error_message="$*"
+ if [[ "$LOG_TO_SYSLOG" == 1 ]]; then
+ echo "$error_message" | $LOGGER_BINARY -p "$SYSLOG_PRIORITY" -t "$BASENAME"
+ else
+ echo >&2 "$BASENAME: $error_message"
+ fi
+
+ return 0
+}
+
#-------------------------------------------------------------
# main()
#-------------------------------------------------------------
@@ -1223,7 +1239,8 @@ FUNCTIONS="
ChooseUid
CheckPermission
CheckListPermissions
- UnsubscribeUser"
+ UnsubscribeUser
+ LogMessage"
for VAR in $GLOBAL_VARS; do
declare $VAR
@@ -1394,11 +1411,7 @@ esac
# print/log error message, if any
if [[ -n "$ERROR_MESSAGE" ]]; then
- if [[ "$LOG_TO_SYSLOG" == 1 ]]; then
- echo "$ERROR_MESSAGE" | $LOGGER_BINARY -p "$SYSLOG_PRIORITY" -t "$BASENAME"
- else
- echo >&2 "$(basename $0): $ERROR_MESSAGE"
- fi
+ LogMessage $ERROR_MESSAGE
fi
# erase all functions and global variables