Skip to content

login: Clean up PAM resource handling#1599

Open
stoeckmann wants to merge 3 commits intoshadow-maint:masterfrom
stoeckmann:login_pam
Open

login: Clean up PAM resource handling#1599
stoeckmann wants to merge 3 commits intoshadow-maint:masterfrom
stoeckmann:login_pam

Conversation

@stoeckmann
Copy link
Copy Markdown
Contributor

  • login opens session first, then sets credentials. This follows an old RFC but violates Linux-PAM's pam_setcred(3) manual page. It also violates su's cred/session order. Other examples of cred/session tools: util-linux login and su, and gdm
  • Do not call pam_close_session if pam_open_session was never called
  • Delete credentials if pam_open_session fails

See pam_setcred(3):
https://github.com/linux-pam/linux-pam/blob/cf2fc5ff7b4a8555fda2a5ebe5f6ab0e45c22996/doc/man/pam_setcred.3.xml#L33-L43

According to Linux-PAM's pam_setcred manual page and shadow's su
implementation, credentials shall be set before session is opened.

Adjust login to follow this rule, which is also applied by util-linux
login/su and at least gdm (didn't check more implementations).

Signed-off-by: Tobias Stoeckmann <tobias@stoeckmann.org>
If authentication fails, call pam_end without pam_close_session, since
at this point, pam_open_session was never called.

Only two callers of PAM_END benefit from the macro, which is not worth
it. Inlined PAM_END instead.

Signed-off-by: Tobias Stoeckmann <tobias@stoeckmann.org>
Call pam_setcreds if pam_open_session fails. This deletes credentials
which are allocated with a previous pam_setcreds call.

Signed-off-by: Tobias Stoeckmann <tobias@stoeckmann.org>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant