1
0
mirror of https://github.com/systemd/systemd.git synced 2025-03-29 06:50:16 +03:00

pam: Setup logging to syslog

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.
This commit is contained in:
Daan De Meyer 2024-04-28 21:27:23 +02:00
parent d682bc1dae
commit 4eae58b3d3
5 changed files with 26 additions and 0 deletions

View File

@ -750,6 +750,8 @@ _public_ PAM_EXTERN int pam_sm_authenticate(
AcquireHomeFlags flags = 0;
bool debug = false;
pam_log_setup();
if (parse_env(handle, &flags) < 0)
return PAM_AUTH_ERR;
@ -811,6 +813,8 @@ _public_ PAM_EXTERN int pam_sm_open_session(
bool debug = false;
int r;
pam_log_setup();
if (parse_env(handle, &flags) < 0)
return PAM_SESSION_ERR;
@ -862,6 +866,8 @@ _public_ PAM_EXTERN int pam_sm_close_session(
bool debug = false;
int r;
pam_log_setup();
if (parse_argv(handle,
argc, argv,
NULL,
@ -922,6 +928,8 @@ _public_ PAM_EXTERN int pam_sm_acct_mgmt(
usec_t t;
int r;
pam_log_setup();
if (parse_env(handle, &flags) < 0)
return PAM_AUTH_ERR;
@ -1039,6 +1047,8 @@ _public_ PAM_EXTERN int pam_sm_chauthtok(
bool debug = false;
int r;
pam_log_setup();
if (parse_argv(handle,
argc, argv,
NULL,

View File

@ -929,6 +929,8 @@ _public_ PAM_EXTERN int pam_sm_open_session(
assert(handle);
pam_log_setup();
if (parse_argv(handle,
argc, argv,
&class_pam,
@ -1230,6 +1232,8 @@ _public_ PAM_EXTERN int pam_sm_close_session(
assert(handle);
pam_log_setup();
if (parse_argv(handle,
argc, argv,
NULL,

View File

@ -25,6 +25,8 @@ _public_ int pam_sm_authenticate(
assert(handle);
pam_log_setup();
/* Parse argv. */
assert(argc >= 0);

View File

@ -14,6 +14,14 @@
#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;

View File

@ -5,6 +5,8 @@
#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);