Skip to content

Commit fa4b72d

Browse files
committed
pam_tcb: Use helper binary for expiration verification of a user account.
Perform verification through an external helper binary to possibly gain higher privileges if the verification fails for insufficient credentials in the first time. Signed-off-by: Björn Esser <[email protected]>
1 parent f058b14 commit fa4b72d

File tree

3 files changed

+42
-0
lines changed

3 files changed

+42
-0
lines changed

ChangeLog

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,13 @@
5050
Replace call to unix_run_helper_binary() with run_chkpwd_binary().
5151
* progs/tcb_chkpwd.c: Refactor the helper program to also perform
5252
verifications for the expiration of user accounts.
53+
* pam_tcb/pam_unix_acct.c (pam_sm_acct_mgmt): Perform expiration
54+
verification of a user account through an external helper binary
55+
if the verification fails for insufficient credentials.
56+
* pam_tcb/pam_unix_acct.c (run_chkpwd_binary): New static function
57+
wrapper around unix_run_helper_binary().
58+
* pam_tcb/Makefile: Add custom rule with "CHKPWD_HELPER" macro
59+
definined to compile pam_unix_acct.o.
5360

5461
2021-09-30 Björn Esser <besser82 at fedoraproject.org>
5562

pam_tcb/Makefile

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,10 @@ $(PAM_TCB): $(LIBOBJ) $(PAM_MAP)
2323
.c.o:
2424
$(CC) $(CFLAGS) -fPIC -c $< -o $@
2525

26+
pam_unix_acct.o: pam_unix_acct.c
27+
$(CC) $(CFLAGS) -DCHKPWD_HELPER=\"$(LIBEXECDIR)/chkpwd/tcb_chkpwd\" \
28+
-fPIC -c $< -o $@
29+
2630
support.o: support.c
2731
$(CC) $(CFLAGS) -DCHKPWD_HELPER=\"$(LIBEXECDIR)/chkpwd/tcb_chkpwd\" \
2832
-fPIC -c $< -o $@

pam_tcb/pam_unix_acct.c

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,29 @@ static int acct_shadow(unused pam_handle_t *pamh, const void *void_user)
7676
return ACCT_SUCCESS;
7777
}
7878

79+
/*
80+
* Use an external helper binary to perform account management.
81+
*/
82+
static int run_chkpwd_binary(const char *user)
83+
{
84+
char *argv[] = { CHKPWD_HELPER, "chkacct", NULL };
85+
char config[8] = "shadow\0\0";
86+
int retval_helper;
87+
88+
if (!pam_unix_param.helper)
89+
goto end;
90+
91+
if (unix_run_helper_binary (user, "NULL", pam_unix_param.helper,
92+
argv, config, (void *)&retval_helper,
93+
sizeof(retval_helper)))
94+
goto end;
95+
96+
return retval_helper;
97+
98+
end:
99+
return ACCT_0;
100+
}
101+
79102
/*
80103
* The account management entry point.
81104
*/
@@ -112,6 +135,14 @@ PAM_EXTERN int pam_sm_acct_mgmt(pam_handle_t *pamh, int flags,
112135
retval = acct_shadow(pamh, user);
113136
else
114137
retval = _unix_fork(pamh, acct_shadow, user);
138+
if (retval == ACCT_2) {
139+
uid_t uid = getuid();
140+
if (uid == geteuid() && (uid == pw->pw_uid || uid == 0)) {
141+
/* We are not privileged enough perhaps this is the reason? */
142+
D(("running helper binary"));
143+
retval = run_chkpwd_binary(user);
144+
}
145+
}
115146
if (retval > 255) {
116147
daysleft = retval / 256;
117148
retval %= 256;

0 commit comments

Comments
 (0)