From: Cody Maloney <cmaloney@theoreticalchaos.com>
To: util-linux@vger.kernel.org
Cc: mitr@redhat.com, Cody Maloney <cmaloney@theoreticalchaos.com>
Subject: [PATCH 2/3] chsh: Move pam auth to its own function.
Date: Sun, 13 Jan 2013 02:12:22 -0700 [thread overview]
Message-ID: <1358068345-773-3-git-send-email-cmaloney@theoreticalchaos.com> (raw)
In-Reply-To: <1358068345-773-1-git-send-email-cmaloney@theoreticalchaos.com>
In-Reply-To: <1357183321-24637-1-git-send-email-cmaloney@theoreticalchaos.com>
This makes it easier to add support for libuser, which needs the same PAM
authentication.
Signed-off-by: Cody Maloney <cmaloney@theoreticalchaos.com>
---
login-utils/chsh.c | 54 +++++++++++++++++++++++++++++++-----------------------
1 file changed, 31 insertions(+), 23 deletions(-)
diff --git a/login-utils/chsh.c b/login-utils/chsh.c
index 6e9325d..b5c3e2e 100644
--- a/login-utils/chsh.c
+++ b/login-utils/chsh.c
@@ -53,6 +53,7 @@ struct sinfo {
char *shell;
};
+static int auth_pam(uid_t uid, struct passwd *pw);
static void parse_argv(int argc, char **argv, struct sinfo *pinfo);
static char *prompt(char *question, char *def_val);
static int check_shell(char *shell);
@@ -147,6 +148,31 @@ int main(int argc, char **argv)
printf(_("Changing shell for %s.\n"), pw->pw_name);
+ if(!auth_pam(uid, pw)) {
+ return EXIT_FAILURE;
+ }
+
+ if (!shell) {
+ shell = prompt(_("New shell"), oldshell);
+ if (!shell)
+ return EXIT_SUCCESS;
+ }
+
+ if (check_shell(shell) < 0)
+ return EXIT_FAILURE;
+
+ if (strcmp(oldshell, shell) == 0)
+ errx(EXIT_SUCCESS, _("Shell not changed."));
+ pw->pw_shell = shell;
+ if (setpwnam(pw) < 0)
+ err(EXIT_FAILURE, _("setpwnam failed\n"
+ "Shell *NOT* changed. Try again later."));
+
+ printf(_("Shell changed.\n"));
+ return EXIT_SUCCESS;
+}
+
+int auth_pam(uid_t uid, struct passwd *pw) {
#ifdef REQUIRE_PASSWORD
if (uid != 0) {
pam_handle_t *pamh = NULL;
@@ -155,47 +181,29 @@ int main(int argc, char **argv)
retcode = pam_start("chsh", pw->pw_name, &conv, &pamh);
if (pam_fail_check(pamh, retcode))
- return EXIT_FAILURE;
+ return FALSE;
retcode = pam_authenticate(pamh, 0);
if (pam_fail_check(pamh, retcode))
- return EXIT_FAILURE;
+ return FALSE;
retcode = pam_acct_mgmt(pamh, 0);
if (retcode == PAM_NEW_AUTHTOK_REQD)
retcode =
pam_chauthtok(pamh, PAM_CHANGE_EXPIRED_AUTHTOK);
if (pam_fail_check(pamh, retcode))
- return EXIT_FAILURE;
+ return FALSE;
retcode = pam_setcred(pamh, 0);
if (pam_fail_check(pamh, retcode))
- return EXIT_FAILURE;
+ return FALSE;
pam_end(pamh, 0);
/* no need to establish a session; this isn't a
* session-oriented activity... */
}
+ return TRUE;
#endif /* REQUIRE_PASSWORD */
-
- if (!shell) {
- shell = prompt(_("New shell"), oldshell);
- if (!shell)
- return EXIT_SUCCESS;
- }
-
- if (check_shell(shell) < 0)
- return EXIT_FAILURE;
-
- if (strcmp(oldshell, shell) == 0)
- errx(EXIT_SUCCESS, _("Shell not changed."));
- pw->pw_shell = shell;
- if (setpwnam(pw) < 0)
- err(EXIT_FAILURE, _("setpwnam failed\n"
- "Shell *NOT* changed. Try again later."));
-
- printf(_("Shell changed.\n"));
- return EXIT_SUCCESS;
}
/*
--
1.8.1
next prev parent reply other threads:[~2013-01-13 9:12 UTC|newest]
Thread overview: 19+ messages / expand[flat|nested] mbox.gz Atom feed top
2013-01-13 9:12 [PATCH v2 0/4] Add support for using libuser to chsh and chfn Cody Maloney
2013-01-03 3:21 ` [PATCH 0/3] Add support for using libuser to chsh Cody Maloney
2013-01-03 3:21 ` [PATCH 1/3] chsh-chfn: Add flag for enabling/disabling libuser support Cody Maloney
2013-01-03 3:22 ` [PATCH 2/3] chsh: Move pam auth to its own function Cody Maloney
2013-01-03 3:22 ` [PATCH 3/3] chsh: Add libuser support Cody Maloney
2013-01-03 16:34 ` Miloslav Trmac
2013-01-07 11:51 ` Karel Zak
2013-01-08 6:15 ` Cody Maloney
2013-01-08 6:17 ` Cody Maloney
2013-01-08 6:18 ` Cody Maloney
2013-01-13 9:12 ` Cody Maloney [this message]
2013-01-13 9:12 ` [PATCH v2 1/4] chsh-chfn: Add flag for enabling/disabling " Cody Maloney
2013-01-13 9:12 ` [PATCH v2 2/4] chsh-chfn: Move pam auth to its own function, factoring out common code Cody Maloney
2013-01-13 9:12 ` [PATCH v2 3/4] chsh: Add libuser support Cody Maloney
2013-01-14 18:16 ` Miloslav Trmac
2013-01-17 0:52 ` Cody Maloney
2013-01-28 22:01 ` Miloslav Trmac
2013-01-13 9:12 ` [PATCH v2 4/4] chfn: " Cody Maloney
[not found] ` <50F2FBBE.7000305@gmail.com>
2013-01-13 19:31 ` [PATCH v2 0/4] Add support for using libuser to chsh and chfn Cody Maloney
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1358068345-773-3-git-send-email-cmaloney@theoreticalchaos.com \
--to=cmaloney@theoreticalchaos.com \
--cc=mitr@redhat.com \
--cc=util-linux@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox