summaryrefslogtreecommitdiffstats
path: root/login-utils/chsh.c
diff options
context:
space:
mode:
authorCody Maloney2013-02-07 07:22:20 +0100
committerKarel Zak2013-02-13 09:37:15 +0100
commit6adb1ef279537875495d10f7c74f35101dd335fd (patch)
tree0c3680cdc91be62969d805c03591c0dd5ec9ffb3 /login-utils/chsh.c
parentchsh-chfn: Move pam auth to its own function, factoring out common code (diff)
downloadkernel-qcow2-util-linux-6adb1ef279537875495d10f7c74f35101dd335fd.tar.gz
kernel-qcow2-util-linux-6adb1ef279537875495d10f7c74f35101dd335fd.tar.xz
kernel-qcow2-util-linux-6adb1ef279537875495d10f7c74f35101dd335fd.zip
chsh: Add libuser support
This is based directly on lchsh which is a part of libuser. libuser.{c,h} exist because exactly the same code is needed for both chsh and chfn. [kzak@redhat.com: cleanup err() usage] Signed-off-by: Cody Maloney <cmaloney@theoreticalchaos.com> Signed-off-by: Karel Zak <kzak@redhat.com>
Diffstat (limited to 'login-utils/chsh.c')
-rw-r--r--login-utils/chsh.c22
1 files changed, 21 insertions, 1 deletions
diff --git a/login-utils/chsh.c b/login-utils/chsh.c
index 7d3963fc0..66800ca94 100644
--- a/login-utils/chsh.c
+++ b/login-utils/chsh.c
@@ -1,6 +1,7 @@
/*
* chsh.c -- change your login shell
* (c) 1994 by salvatore valente <svalente@athena.mit.edu>
+ * (c) 2012 by Cody Maloney <cmaloney@theoreticalchaos.com>
*
* this program is free software. you can redistribute it and
* modify it under the terms of the gnu general public license.
@@ -32,7 +33,6 @@
#include <sys/types.h>
#include <unistd.h>
-#include "auth.h"
#include "c.h"
#include "env.h"
#include "closestream.h"
@@ -48,6 +48,14 @@
# include "selinux_utils.h"
#endif
+
+#ifdef HAVE_LIBUSER
+# include <libuser/user.h>
+# include "libuser.h"
+#else
+# include "auth.h"
+#endif
+
struct sinfo {
char *username;
char *shell;
@@ -131,7 +139,12 @@ int main(int argc, char **argv)
oldshell = _PATH_BSHELL; /* default */
/* reality check */
+#ifdef HAVE_LIBUSER
+ /* If we're setuid and not really root, disallow the password change. */
+ if (geteuid() != getuid() && uid != pw->pw_uid) {
+#else
if (uid != 0 && uid != pw->pw_uid) {
+#endif
errno = EACCES;
err(EXIT_FAILURE,
_("running UID doesn't match UID of user we're "
@@ -147,9 +160,11 @@ int main(int argc, char **argv)
printf(_("Changing shell for %s.\n"), pw->pw_name);
+#ifndef HAVE_LIBUSER
if(!auth_pam("chsh", uid, pw->pw_name)) {
return EXIT_FAILURE;
}
+#endif
if (!shell) {
shell = prompt(_("New shell"), oldshell);
@@ -162,10 +177,15 @@ int main(int argc, char **argv)
if (strcmp(oldshell, shell) == 0)
errx(EXIT_SUCCESS, _("Shell not changed."));
+
+#ifdef HAVE_LIBUSER
+ set_value_libuser("chsh", pw->pw_name, uid, LU_LOGINSHELL, shell);
+#else
pw->pw_shell = shell;
if (setpwnam(pw) < 0)
err(EXIT_FAILURE, _("setpwnam failed\n"
"Shell *NOT* changed. Try again later."));
+#endif
printf(_("Shell changed.\n"));
return EXIT_SUCCESS;