Browse code
log handles non-auth errors
Greg Wiley authored on 26/04/2017 18:08:33
Showing 2 changed files
Showing 2 changed files
... | ... |
@@ -23,11 +23,29 @@ namespace { |
23 | 23 |
impl(const sys_syslog &sys_syslog) : syslog_(sys_syslog) {} |
24 | 24 |
void log (int result, const std::string &user_name, |
25 | 25 |
const std::string &token) { |
26 |
- std::string pam_result = result == PAM_SUCCESS ? "success" : "fail"; |
|
27 |
- std::string message(user_name + " " + token + " " + pam_result); |
|
26 |
+ std::string message; |
|
27 |
+ int facility; |
|
28 |
+ int priority; |
|
29 |
+ switch (result) { |
|
30 |
+ case PAM_SUCCESS: |
|
31 |
+ facility = LOG_AUTHPRIV; |
|
32 |
+ priority = LOG_NOTICE; |
|
33 |
+ message = user_name + " " + token + " " + "success"; |
|
34 |
+ break; |
|
35 |
+ case PAM_AUTH_ERR: |
|
36 |
+ facility = LOG_AUTHPRIV; |
|
37 |
+ priority = LOG_NOTICE; |
|
38 |
+ message = user_name + " " + token + " " + "fail"; |
|
39 |
+ break; |
|
40 |
+ default: |
|
41 |
+ facility = LOG_AUTH; |
|
42 |
+ priority = LOG_ERR; |
|
43 |
+ message = "pam returned error"; |
|
44 |
+ break; |
|
45 |
+ } |
|
28 | 46 |
|
29 |
- syslog_.openlog("dual-control", 0, LOG_AUTHPRIV); |
|
30 |
- syslog_.syslog(LOG_NOTICE, message.c_str()); |
|
47 |
+ syslog_.openlog("dual-control", 0, facility); |
|
48 |
+ syslog_.syslog(priority, message.c_str()); |
|
31 | 49 |
syslog_.closelog(); |
32 | 50 |
} |
33 | 51 |
}; |
... | ... |
@@ -85,6 +85,27 @@ int logs_failure() { |
85 | 85 |
succeed(); |
86 | 86 |
} |
87 | 87 |
|
88 |
+int logs_pam_service_error() { |
|
89 |
+ //given |
|
90 |
+ mock_syslog *capture = new mock_syslog; |
|
91 |
+ sys_syslog::delegate test_delegate(capture); |
|
92 |
+ sys_syslog test_syslog(test_delegate); |
|
93 |
+ logger logger = logger::create(test_syslog); |
|
94 |
+ std::string user("user"); |
|
95 |
+ std::string token("token"); |
|
96 |
+ |
|
97 |
+ //when |
|
98 |
+ logger.log(PAM_SERVICE_ERR, user, token); |
|
99 |
+ |
|
100 |
+ //then |
|
101 |
+ check(capture->facility == LOG_AUTH, "facility does not match"); |
|
102 |
+ check(capture->message == "pam returned error", "message does not match"); |
|
103 |
+ check(capture->priority == LOG_ERR, "priority does not match"); |
|
104 |
+ check(capture->closed, "syslog not closed"); |
|
105 |
+ check(capture->ident == "dual-control", "dual-control"); |
|
106 |
+ succeed(); |
|
107 |
+} |
|
108 |
+ |
|
88 | 109 |
RESET_VARS_START |
89 | 110 |
RESET_VARS_END |
90 | 111 |
|
... | ... |
@@ -92,6 +113,7 @@ int run_tests() |
92 | 113 |
{ |
93 | 114 |
test (logs_success); |
94 | 115 |
test (logs_failure); |
116 |
+ test (logs_pam_service_error); |
|
95 | 117 |
succeed(); |
96 | 118 |
} |
97 | 119 |
|