We already log to syslog using pam_syslog() for logs generated directly
within our pam plugins. However, any logs generated by our generic logging
macros that are invoked within a pam plugin will log to the console. Let's
make sure our generic logging macros are set up to log to syslog as well.
AcquireHomeFlags flags = 0;
bool debug = false;
+ pam_log_setup();
+
if (parse_env(handle, &flags) < 0)
return PAM_AUTH_ERR;
bool debug = false;
int r;
+ pam_log_setup();
+
if (parse_env(handle, &flags) < 0)
return PAM_SESSION_ERR;
bool debug = false;
int r;
+ pam_log_setup();
+
if (parse_argv(handle,
argc, argv,
NULL,
usec_t t;
int r;
+ pam_log_setup();
+
if (parse_env(handle, &flags) < 0)
return PAM_AUTH_ERR;
bool debug = false;
int r;
+ pam_log_setup();
+
if (parse_argv(handle,
argc, argv,
NULL,
assert(handle);
+ pam_log_setup();
+
if (parse_argv(handle,
argc, argv,
&class_pam,
assert(handle);
+ pam_log_setup();
+
if (parse_argv(handle,
argc, argv,
NULL,
assert(handle);
+ pam_log_setup();
+
/* Parse argv. */
assert(argc >= 0);
#include "stdio-util.h"
#include "string-util.h"
+void pam_log_setup(void) {
+ /* Make sure we don't leak the syslog fd we open by opening/closing the fd each time. */
+ log_set_open_when_needed(true);
+
+ /* pam logs to syslog so let's make our generic logging functions do the same thing. */
+ log_set_target(LOG_TARGET_SYSLOG);
+}
+
int pam_syslog_errno(pam_handle_t *handle, int level, int error, const char *format, ...) {
va_list ap;
#include "sd-bus.h"
+void pam_log_setup(void);
+
int pam_syslog_errno(pam_handle_t *handle, int level, int error, const char *format, ...) _printf_(4,5);
int pam_syslog_pam_error(pam_handle_t *handle, int level, int error, const char *format, ...) _printf_(4,5);