don't log passwords by default, but make password logging optional
[bpdyndnsd] / src / logger.cpp
index 7e3beb8..4775f98 100644 (file)
@@ -31,6 +31,7 @@ Logger::Logger()
     , Syslog(false)
     , ExternalWarningLevel(0)
     , ExternalLogOnlyOnce(false)
+    , LogPasswords(false)
 {
     set_log_facility(Loglevel,Syslog,ExternalWarningLog,ExternalWarningLevel,ExternalLogOnlyOnce);
 }
@@ -44,6 +45,8 @@ Logger::~Logger()
 }
 
 
+
+
 /**
  * Decides if a external log message can be send.
  * @param msg The message to log.
@@ -155,6 +158,16 @@ void Logger::set_external_log_only_once( const bool _external_log_only_once )
 
 
 /**
+ * Setter for member LogPasswords.
+ * @param _log_passwords If we want to log passwords or not.
+ */
+void Logger::set_log_passwords( const bool _log_passwords )
+{
+    LogPasswords = _log_passwords;
+}
+
+
+/**
  * Setter for member Loglevel.
  * @param _loglevel Value to set Loglevel to.
  */
@@ -827,7 +840,12 @@ void Logger::print_service_object(const string& message, const string& protocol,
         msg << "\t" << "Protocol:         " << protocol << endl;
         msg << "\t" << "Hostname:         " << hostname << endl;
         msg << "\t" << "Login:            " << login << endl;
-        msg << "\t" << "Password:         " << password << endl;
+
+        if (LogPasswords)
+            msg << "\t" << "Password:         " << password << endl;
+        else
+            msg << "\t" << "Password:         (*hidden*)" << endl;
+
         msg << "\t" << "Update Interval:  " << update_interval << endl;
         msg << "\t" << "Max Updates:      " << max_updates_within_interval << endl;
         msg << "\t" << "Max equal Updates:" << max_equal_updates_in_succession << endl;
@@ -1440,7 +1458,13 @@ void Logger::print_service_not_authorized(const string& service, const string& u
     if ( level <= Loglevel )
     {
         ostringstream msg;
-        msg << "Not authorized to perform update operation on service: " << service << " Please check username and password: " << username << ":" << password << endl;
+        msg << "Not authorized to perform update operation on service: " << service << " Please check username and password: " << username << ":";
+
+        if (LogPasswords)
+            msg << password << endl;
+        else
+            msg << "(*hidden*)" << endl;
+
         log_notice(msg.str());
     }
 }