summaryrefslogtreecommitdiffstats
path: root/login-utils
diff options
context:
space:
mode:
authorKarel Zak2018-07-23 12:21:33 +0200
committerKarel Zak2018-07-23 12:21:33 +0200
commit088d487612091c121bf0d4c3981186993517f95c (patch)
tree0db02c415e1cd029a2868df3fa51b2e280ade94e /login-utils
parentlibmount: (utils) fix compiler warnings [-Wcast-qual] (diff)
downloadkernel-qcow2-util-linux-088d487612091c121bf0d4c3981186993517f95c.tar.gz
kernel-qcow2-util-linux-088d487612091c121bf0d4c3981186993517f95c.tar.xz
kernel-qcow2-util-linux-088d487612091c121bf0d4c3981186993517f95c.zip
login: use const qualifier for username from PAM or struct passwd [-Wcast-qual]
It seems more robust to use 'const' qualifier for username if this variable points to external resources like PAM or struct passwd. The patch introduces new variable cmd_username for username specified on login(1) command line. Signed-off-by: Karel Zak <kzak@redhat.com>
Diffstat (limited to 'login-utils')
-rw-r--r--login-utils/login.c17
1 files changed, 11 insertions, 6 deletions
diff --git a/login-utils/login.c b/login-utils/login.c
index 09ee8f8ea..9aef3d804 100644
--- a/login-utils/login.c
+++ b/login-utils/login.c
@@ -105,7 +105,9 @@ struct login_context {
const char *tty_number; /* end of the tty_path */
mode_t tty_mode; /* chmod() mode */
- char *username; /* from command line or PAM */
+ const char *username; /* points to PAM, pwd or cmd_username */
+ char *cmd_username; /* username specified on command line */
+
struct passwd *pwd; /* user info */
char *pwdbuf; /* pwd strings */
@@ -655,12 +657,12 @@ static void log_syslog(struct login_context *cxt)
}
/* encapsulate stupid "void **" pam_get_item() API */
-static int loginpam_get_username(pam_handle_t *pamh, char **name)
+static int loginpam_get_username(pam_handle_t *pamh, const char **name)
{
- const void *item = (void *)*name;
+ const void *item = (const void *)*name;
int rc;
rc = pam_get_item(pamh, PAM_USER, &item);
- *name = (char *)item;
+ *name = (const char *)item;
return rc;
}
@@ -740,7 +742,6 @@ static pam_handle_t *init_loginpam(struct login_context *cxt)
loginpam_err(pamh, rc);
/* We don't need the original username. We have to follow PAM. */
- free(cxt->username);
cxt->username = NULL;
cxt->pamh = pamh;
@@ -1204,7 +1205,11 @@ int main(int argc, char **argv)
if (*argv) {
char *p = *argv;
- cxt.username = xstrdup(p);
+
+ /* username from command line */
+ cxt.cmd_username = xstrdup(p);
+ /* used temporary, it'll be replaced by username from PAM or/and cxt->pwd */
+ cxt.username = cxt.cmd_username;
/* Wipe the name - some people mistype their password here. */
/* (Of course we are too late, but perhaps this helps a little...) */