Skip to content

Commit ef19341

Browse files
committed
pam_openrc: add aditional logging
1 parent 01ba72b commit ef19341

2 files changed

Lines changed: 14 additions & 7 deletions

File tree

src/openrc-user/openrc-user.c

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -84,8 +84,6 @@ int main(int argc, char **argv) {
8484
setenv("EINFO_LOG", log, true);
8585
free(log);
8686

87-
elog(LOG_INFO, "uid %ud, gid %ud, euid %ud, egid %ud.", getuid(), getgid(), geteuid(), getegid());
88-
8987
#ifdef HAVE_PAM
9088
if ((rc = pam_start("openrc-user", user->pw_name, &conv, &pamh)) != PAM_SUCCESS)
9189
elog(LOG_ERR, "Failed to start pam: %s", pam_strerror(pamh, rc));
@@ -107,8 +105,6 @@ int main(int argc, char **argv) {
107105
}
108106
#endif
109107

110-
elog(LOG_INFO, "uid %ud, gid %ud, euid %ud, egid %ud.", getuid(), getgid(), geteuid(), getegid());
111-
112108
if (!spawn_openrc(user, true)) {
113109
ret = -1;
114110
goto out;

src/pam_openrc/pam_openrc.c

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,24 +16,35 @@ static int
1616
exec_openrc(pam_handle_t *pamh, bool opening)
1717
{
1818
char *svc_name, *pam_lock, *logins, *script = NULL;
19-
const char *username, *session;
19+
const char *username = NULL, *session = NULL;
2020
RC_SERVICE service_status;
2121
int count = 0, fd, status;
2222
int ret = PAM_SUCCESS;
2323
struct passwd *user;
2424
pid_t pid = -1;
2525

26-
if (pam_get_item(pamh, PAM_SERVICE, (const void **)&session) != PAM_SUCCESS)
26+
setenv("EINFO_LOG", "pam_openrc", true);
27+
28+
if (pam_get_item(pamh, PAM_SERVICE, (const void **)&session) != PAM_SUCCESS) {
29+
elog(LOG_ERR, "Failed to get PAM_SERVICE");
2730
return PAM_SESSION_ERR;
31+
}
2832

2933
if (session && strcmp(session, "openrc-user") == 0)
3034
return PAM_SUCCESS;
3135

3236
if (pam_get_item(pamh, PAM_USER, (const void **)&username) != PAM_SUCCESS)
3337
return PAM_SESSION_ERR;
3438

35-
if (!username || !(user = getpwnam(username)))
39+
if (!username) {
40+
elog(LOG_ERR, "PAM_USER unset.");
41+
return PAM_SESSION_ERR;
42+
}
43+
44+
if (!(user = getpwnam(username))) {
45+
elog(LOG_ERR, "User '%s' not found.", username);
3646
return PAM_SESSION_ERR;
47+
}
3748

3849
if (user->pw_uid == 0)
3950
return PAM_SUCCESS;

0 commit comments

Comments
 (0)