git.fiddlerwoaroof.com
logger.cc
a9690b1d
 /* Copyright (C) CJ Affiliate
  *
  * You may use, distribute and modify this code under  the
  * terms of the  GNU General Public License  version 2  or
  * later.
  *
  * You should have received a copy of the license with this
  * file. If not, you will find a copy in the "LICENSE" file
  * at https://github.com/cjdev/dual-control.
  */
 
 #include <syslog.h>
9526a1d3
 #include <security/pam_modules.h>
a9690b1d
 
 #include "sys_syslog.h"
 #include "logger.h"
 
bc6c3d35
 namespace
 {
 class impl : public logger_ifc
 {
 private:
     sys_syslog syslog_;
 public:
     impl (const sys_syslog &sys_syslog) : syslog_ (sys_syslog) {}
706636a4
     void log (int result, const std::string &requester_user_name,
               const std::string &authorizer_user_name,
3fc168fa
               const std::string &token, const std::string &reason) override
bc6c3d35
     {
         std::string message;
         int facility;
         int priority;
 
         switch (result) {
         case PAM_SUCCESS:
             facility = LOG_AUTHPRIV;
             priority = LOG_NOTICE;
8804b544
             message = requester_user_name + " " + authorizer_user_name +
531238a7
                       " " + reason + " " + "success";
bc6c3d35
             break;
 
         case PAM_AUTH_ERR:
             facility = LOG_AUTHPRIV;
             priority = LOG_NOTICE;
8804b544
             message = requester_user_name + " " + authorizer_user_name +
3fc168fa
                       " " + reason + " " + "fail";
bc6c3d35
             break;
 
         default:
             facility = LOG_AUTH;
             priority = LOG_ERR;
706636a4
             message = requester_user_name + " " + authorizer_user_name +
3fc168fa
                       " " + reason + " " + "pam returned error";
bc6c3d35
             break;
         }
 
         syslog_.openlog ("dual-control", 0, facility);
         syslog_.syslog (priority, message.c_str());
         syslog_.closelog();
     }
 };
a9690b1d
 }
 
bc6c3d35
 logger logger::create (const sys_syslog &sys_syslog)
 {
     return logger (delegate (new impl (sys_syslog)));
a9690b1d
 }
bc6c3d35