Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions etc/rc.conf
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,11 @@
# set to YES.
#rc_interactive="YES"

# Set to "NO" if you don't want pam_openrc autostarting user services. This
# effectively disables the pam module, without the need of removing it from
# the pam configuration files.
#rc_autostart_user="YES"

# If we need to drop to a shell, you can specify it here.
# If not specified we use $SHELL, otherwise the one specified in /etc/passwd,
# otherwise /bin/sh
Expand Down
16 changes: 12 additions & 4 deletions src/pam_openrc/pam_openrc.c
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
#include "einfo.h"

static int
exec_openrc(pam_handle_t *pamh, bool opening)
exec_openrc(pam_handle_t *pamh, bool opening, bool quiet)
{
char *svc_name, *pam_lock, *logins, *script = NULL;
const char *username = NULL, *session = NULL;
Expand All @@ -23,8 +23,17 @@ exec_openrc(pam_handle_t *pamh, bool opening)
struct passwd *user;
pid_t pid = -1;

errno = 0;
if (!rc_yesno(rc_conf_value("rc_autostart_user")) && errno == 0)
return PAM_SUCCESS;

setenv("EINFO_LOG", "pam_openrc", true);

if (quiet) {
setenv("EINFO_QUIET", "yes", true);
setenv("EERROR_QUIET", "yes", true);
}

if (pam_get_item(pamh, PAM_SERVICE, (const void **)&session) != PAM_SUCCESS) {
elog(LOG_ERR, "Failed to get PAM_SERVICE");
return PAM_SESSION_ERR;
Expand Down Expand Up @@ -123,15 +132,14 @@ exec_openrc(pam_handle_t *pamh, bool opening)
PAM_EXTERN int pam_sm_open_session(pam_handle_t *pamh, int flags, int argc, const char **argv) {
(void) argc;
(void) argv;
(void) flags;

return exec_openrc(pamh, true);
return exec_openrc(pamh, true, flags & PAM_SILENT);
}

PAM_EXTERN int pam_sm_close_session(pam_handle_t *pamh, int flags, int argc, const char **argv) {
(void) argc;
(void) argv;
(void) flags;

return exec_openrc(pamh, false);
return exec_openrc(pamh, false, flags & PAM_SILENT);
}