]> gitweb.fluxo.info Git - firma.git/commitdiff
new function LogMessage and fixes on permission checking
authorrhatto <rhatto>
Sat, 7 Oct 2006 18:10:40 +0000 (18:10 +0000)
committerrhatto <rhatto>
Sat, 7 Oct 2006 18:10:40 +0000 (18:10 +0000)
firma

diff --git a/firma b/firma
index cba270f6f19d18cb546bb8ba3c4fdf059ca707f4..1f75e8a7b10b4bedc7f5c15cf11e765e7c33f787 100755 (executable)
--- 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