Skip to content

Commit f46ca81

Browse files
besser82solardiz
authored andcommitted
pam_tcb: Fix "-Wpedantic".
ISO C forbids omitting the middle term of a '?:' expression. Signed-off-by: Björn Esser <[email protected]>
1 parent 85d29f4 commit f46ca81

File tree

6 files changed

+27
-6
lines changed

6 files changed

+27
-6
lines changed

ChangeLog

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,15 @@
1+
2021-09-30 Björn Esser <besser82 at fedoraproject.org>
2+
3+
pam_tcb: Fix "-Wpedantic".
4+
* pam_tcb/pam_unix_auth.c (pam_sm_authenticate): ISO C forbids
5+
omitting the middle term of a '?:' expression.
6+
* pam_tcb/pam_unix_sess.c (pam_sm_open_session): Likewise.
7+
* pam_tcb/pam_unix_passwd.c (pam_sm_chauthtok): Likewise.
8+
* pam_tcb/pam_unix_passwd.c (unix_prelim): Likewise.
9+
* pam_tcb/support.c (_set_ctrl): Likewise.
10+
* pam_tcb/support.h (pam_tcb_getlogin): New function.
11+
Small static inline wrapper around getlogin(3).
12+
113
2021-09-25 Björn Esser <besser82 at fedoraproject.org>
214

315
* pam_tcb/support.c (_set_ctrl): Request automatic prefix only if

pam_tcb/pam_unix_auth.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ PAM_EXTERN int pam_sm_authenticate(pam_handle_t *pamh, int flags,
128128
pam_syslog(pamh, retval == PAM_SUCCESS ? LOG_INFO : LOG_NOTICE,
129129
"Authentication %s for %s from %s(uid=%u)",
130130
retval == PAM_SUCCESS ? "passed" : "failed", user,
131-
getlogin() ?: "", getuid());
131+
pam_tcb_getlogin(), getuid());
132132
}
133133

134134
D(("done [%s]", pam_strerror(pamh, retval)));

pam_tcb/pam_unix_passwd.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -435,7 +435,7 @@ static int unix_prelim(pam_handle_t *pamh, const char *user)
435435
"Authentication %s for %s from %s(uid=%u)"
436436
", for password management",
437437
retval == PAM_SUCCESS ? "passed" : "failed", user,
438-
getlogin() ?: "", getuid());
438+
pam_tcb_getlogin(), getuid());
439439

440440
return retval;
441441
}
@@ -576,7 +576,7 @@ PAM_EXTERN int pam_sm_chauthtok(pam_handle_t *pamh, int flags,
576576
if (retval == PAM_SUCCESS) {
577577
pam_syslog(pamh, LOG_INFO,
578578
"Password for %s changed by %s(uid=%u)",
579-
user, getlogin() ?: "", getuid());
579+
user, pam_tcb_getlogin(), getuid());
580580
}
581581

582582
D(("retval was %d", retval));

pam_tcb/pam_unix_sess.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ PAM_EXTERN int pam_sm_open_session(pam_handle_t *pamh, int flags,
4242
}
4343

4444
pam_syslog(pamh, LOG_INFO, "Session opened for %s by %s(uid=%u)",
45-
user, getlogin() ?: "", getuid());
45+
user, pam_tcb_getlogin(), getuid());
4646

4747
return PAM_SUCCESS;
4848
}

pam_tcb/support.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -576,7 +576,7 @@ static int do_record_failure(pam_handle_t *pamh, const char *user, int retval)
576576
new->user = strdup(getpwnam(user) ?
577577
user : "UNKNOWN USER");
578578
new->id = getuid();
579-
new->name = strdup(getlogin() ?: "");
579+
new->name = strdup(pam_tcb_getlogin());
580580

581581
/* any previous failures for this user? */
582582
if (pam_get_data(pamh, data_name, &item)
@@ -847,7 +847,7 @@ int _set_ctrl(pam_handle_t *pamh, int flags, int argc, const char **argv)
847847
#endif
848848

849849
param = get_optval("helper=", the_cmdline_opts);
850-
pam_unix_param.helper = param ?: CHKPWD_HELPER;
850+
pam_unix_param.helper = param ? param : CHKPWD_HELPER;
851851

852852
param = get_optval("count=", the_cmdline_opts);
853853
if (param) {

pam_tcb/support.h

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -178,4 +178,13 @@ extern int unix_getspnam(struct spwd **, const struct passwd *);
178178
extern char *crypt_wrapper(pam_handle_t *, const char *, const char *);
179179
extern char *do_crypt(pam_handle_t *, const char *);
180180

181+
/* Helper function around getlogin() */
182+
static inline char *pam_tcb_getlogin(void)
183+
{
184+
char *login = getlogin();
185+
if (!login)
186+
return "";
187+
return login;
188+
}
189+
181190
#endif

0 commit comments

Comments
 (0)