Skip to content

Commit 7bc0bd2

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 56e0c24 commit 7bc0bd2

File tree

3 files changed

+48
-0
lines changed

3 files changed

+48
-0
lines changed

ChangeLog

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,13 @@
4040
Replace call to unix_run_helper_binary() with run_chkpwd_binary().
4141
* progs/tcb_chkpwd.c: Refactor the helper program to also perform
4242
verifications for the expiration of user accounts.
43+
* pam_tcb/pam_unix_acct.c (pam_sm_acct_mgmt): Perform expiration
44+
verification of a user account through an external helper binary
45+
if the verification fails for insufficient credentials.
46+
* pam_tcb/pam_unix_acct.c (run_chkpwd_binary): New static function
47+
wrapper around unix_run_helper_binary().
48+
* pam_tcb/Makefile: Add custom rule with "CHKPWD_HELPER" macro
49+
definined to compile pam_unix_acct.o.
4350

4451
2021-09-30 Björn Esser <besser82 at fedoraproject.org>
4552

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: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,35 @@ 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];
86+
int retval_helper;
87+
88+
if (!pam_unix_param.helper)
89+
goto end;
90+
91+
if (on(UNIX_SHADOW)) {
92+
memcpy(config, "shadow\0\0", 8);
93+
} else {
94+
memcpy(config, "passwd\0\0", 8);
95+
}
96+
97+
if (unix_run_helper_binary (user, "NULL", pam_unix_param.helper,
98+
argv, config, (void *)&retval_helper,
99+
sizeof(retval_helper)))
100+
goto end;
101+
102+
return retval_helper;
103+
104+
end:
105+
return ACCT_0;
106+
}
107+
79108
/*
80109
* The account management entry point.
81110
*/
@@ -112,6 +141,14 @@ PAM_EXTERN int pam_sm_acct_mgmt(pam_handle_t *pamh, int flags,
112141
retval = acct_shadow(pamh, user);
113142
else
114143
retval = _unix_fork(pamh, acct_shadow, user);
144+
if (retval == ACCT_2) {
145+
uid_t uid = getuid();
146+
if (uid == geteuid() && (uid == pw->pw_uid || uid == 0)) {
147+
/* We are not privileged enough perhaps this is the reason? */
148+
D(("running helper binary"));
149+
retval = run_chkpwd_binary(user);
150+
}
151+
}
115152
if (retval > 255) {
116153
daysleft = retval / 256;
117154
retval %= 256;

0 commit comments

Comments
 (0)