return setup_runtime_directory(handle, ur, runtime_directory, area);
}
-static int open_osc_context(pam_handle_t *handle, const char *session_type, UserRecord *ur) {
+static int open_osc_context(pam_handle_t *handle, const char *session_type, UserRecord *ur, bool debug) {
int r;
assert(handle);
* so that we don't delay tty hang-up. */
_cleanup_close_ int tty_opath_fd = fd_reopen(STDOUT_FILENO, O_PATH|O_CLOEXEC);
if (tty_opath_fd < 0)
- pam_syslog_errno(handle, LOG_DEBUG, tty_opath_fd, "Failed to pin TTY, ignoring: %m");
+ pam_debug_syslog_errno(handle, debug, tty_opath_fd, "Failed to pin TTY, ignoring: %m");
else
tty_opath_fd = fd_move_above_stdio(tty_opath_fd);
return PAM_SUCCESS;
}
-static int close_osc_context(pam_handle_t *handle) {
+static int close_osc_context(pam_handle_t *handle, bool debug) {
int r;
assert(handle);
/* Now open the original TTY again, so that we can write on it */
_cleanup_close_ int fd = fd_reopen(tty_opath_fd, O_WRONLY|O_CLOEXEC|O_NONBLOCK|O_NOCTTY);
if (fd < 0) {
- pam_syslog_errno(handle, LOG_DEBUG, fd, "Failed to reopen TTY, ignoring: %m");
+ pam_debug_syslog_errno(handle, debug, fd, "Failed to reopen TTY, ignoring: %m");
return PAM_SUCCESS;
}
/* When we are closing things, the TTY might not take our writes anymore. Accept that gracefully. */
r = loop_write(fd, osc, SIZE_MAX);
if (r < 0)
- pam_syslog_errno(handle, LOG_DEBUG, r, "Failed to write OSC sequence to TTY, ignoring: %m");
+ pam_debug_syslog_errno(handle, debug, r, "Failed to write OSC sequence to TTY, ignoring: %m");
return PAM_SUCCESS;
}
if (r != PAM_SUCCESS)
return r;
- return open_osc_context(handle, c.type, ur);
+ return open_osc_context(handle, c.type, ur, debug);
}
_public_ PAM_EXTERN int pam_sm_close_session(
return pam_syslog_pam_error(handle, LOG_ERR, r,
"Failed to get PAM systemd.existing data: @PAMERR@");
- (void) close_osc_context(handle);
+ (void) close_osc_context(handle, debug);
id = pam_getenv(handle, "XDG_SESSION_ID");
if (id && !existing) {
int pam_syslog_pam_error(pam_handle_t *handle, int level, int error, const char *format, ...) _printf_(4,5);
-/* Call pam_vsyslog if debug is enabled */
+/* Call sym_pam_syslog if debug is enabled */
#define pam_debug_syslog(handle, debug, fmt, ...) \
({ \
if (debug) \
sym_pam_syslog(handle, LOG_DEBUG, fmt, ## __VA_ARGS__); \
})
+/* Call pam_syslog_errno if debug is enabled */
+#define pam_debug_syslog_errno(handle, debug, error, fmt, ...) \
+ ({ \
+ if (debug) \
+ pam_syslog_errno(handle, LOG_DEBUG, error, fmt, ## __VA_ARGS__); \
+ })
+
static inline int pam_log_oom(pam_handle_t *handle) {
/* This is like log_oom(), but uses PAM logging */
return pam_syslog_errno(handle, LOG_ERR, ENOMEM, "Out of memory.");