2007-10-07 17:14:02 +05:30
|
|
|
/*
|
|
|
|
* Copyright 1989 - 1994, Julianne Frances Haugh
|
|
|
|
* All rights reserved.
|
|
|
|
*
|
|
|
|
* Redistribution and use in source and binary forms, with or without
|
|
|
|
* modification, are permitted provided that the following conditions
|
|
|
|
* are met:
|
|
|
|
* 1. Redistributions of source code must retain the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer.
|
|
|
|
* 2. Redistributions in binary form must reproduce the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer in the
|
|
|
|
* documentation and/or other materials provided with the distribution.
|
|
|
|
* 3. Neither the name of Julianne F. Haugh nor the names of its contributors
|
|
|
|
* may be used to endorse or promote products derived from this software
|
|
|
|
* without specific prior written permission.
|
|
|
|
*
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY JULIE HAUGH AND CONTRIBUTORS ``AS IS'' AND
|
|
|
|
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|
|
|
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
2007-10-07 17:14:59 +05:30
|
|
|
* ARE DISCLAIMED. IN NO EVENT SHALL JULIE HAUGH OR CONTRIBUTORS BE LIABLE
|
2007-10-07 17:14:02 +05:30
|
|
|
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
|
|
|
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
|
|
|
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
|
|
|
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
|
|
|
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
|
|
|
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
|
|
|
* SUCH DAMAGE.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <config.h>
|
|
|
|
|
2007-10-07 17:17:01 +05:30
|
|
|
#ident "$Id: chsh.c,v 1.35 2005/10/04 21:02:22 kloczek Exp $"
|
|
|
|
|
2007-10-07 17:14:02 +05:30
|
|
|
#include <fcntl.h>
|
|
|
|
#include <pwd.h>
|
2007-10-07 17:16:52 +05:30
|
|
|
#include <signal.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <sys/types.h>
|
|
|
|
#ifdef WITH_SELINUX
|
|
|
|
#include <selinux/selinux.h>
|
|
|
|
#include <selinux/av_permissions.h>
|
|
|
|
#endif
|
2007-10-07 17:14:02 +05:30
|
|
|
#ifdef HAVE_SHADOW_H
|
|
|
|
#include <shadow.h>
|
|
|
|
#endif
|
2007-10-07 17:16:52 +05:30
|
|
|
#include "defines.h"
|
|
|
|
#include "exitcodes.h"
|
|
|
|
#include "getdef.h"
|
|
|
|
#include "nscd.h"
|
|
|
|
#include "prototypes.h"
|
|
|
|
#include "pwauth.h"
|
|
|
|
#include "pwio.h"
|
2007-10-07 17:14:02 +05:30
|
|
|
#ifdef USE_PAM
|
|
|
|
#include "pam_defs.h"
|
|
|
|
#endif
|
|
|
|
#ifndef SHELLS_FILE
|
|
|
|
#define SHELLS_FILE "/etc/shells"
|
|
|
|
#endif
|
2007-10-07 17:17:01 +05:30
|
|
|
/*
|
|
|
|
* Global variables
|
|
|
|
*/
|
2007-10-07 17:14:59 +05:30
|
|
|
static char *Prog; /* Program name */
|
|
|
|
static int amroot; /* Real UID is root */
|
|
|
|
static char loginsh[BUFSIZ]; /* Name of new login shell */
|
2007-10-07 17:14:02 +05:30
|
|
|
|
2007-10-07 17:14:59 +05:30
|
|
|
/* external identifiers */
|
2007-10-07 17:14:02 +05:30
|
|
|
|
|
|
|
/* local function prototypes */
|
2007-10-07 17:14:59 +05:30
|
|
|
static void usage (void);
|
|
|
|
static void new_fields (void);
|
|
|
|
static int restricted_shell (const char *);
|
2007-10-07 17:14:02 +05:30
|
|
|
|
|
|
|
/*
|
|
|
|
* usage - print command line syntax and exit
|
|
|
|
*/
|
2007-10-07 17:14:59 +05:30
|
|
|
static void usage (void)
|
2007-10-07 17:14:02 +05:30
|
|
|
{
|
2007-10-07 17:14:59 +05:30
|
|
|
fprintf (stderr, _("Usage: %s [-s shell] [name]\n"), Prog);
|
2007-10-07 17:16:52 +05:30
|
|
|
exit (E_USAGE);
|
2007-10-07 17:14:02 +05:30
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* new_fields - change the user's login shell information interactively
|
|
|
|
*
|
|
|
|
* prompt the user for the login shell and change it according to the
|
|
|
|
* response, or leave it alone if nothing was entered.
|
|
|
|
*/
|
2007-10-07 17:14:59 +05:30
|
|
|
static void new_fields (void)
|
2007-10-07 17:14:02 +05:30
|
|
|
{
|
2007-10-07 17:16:07 +05:30
|
|
|
printf (_("Enter the new value, or press ENTER for the default\n"));
|
2007-10-07 17:14:59 +05:30
|
|
|
change_field (loginsh, sizeof loginsh, _("Login Shell"));
|
2007-10-07 17:14:02 +05:30
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* restricted_shell - return true if the named shell begins with 'r' or 'R'
|
|
|
|
*
|
|
|
|
* If the first letter of the filename is 'r' or 'R', the shell is
|
|
|
|
* considered to be restricted.
|
|
|
|
*/
|
2007-10-07 17:14:59 +05:30
|
|
|
static int restricted_shell (const char *sh)
|
2007-10-07 17:14:02 +05:30
|
|
|
{
|
|
|
|
/*
|
2007-10-07 17:14:59 +05:30
|
|
|
* Shells not listed in /etc/shells are considered to be restricted.
|
|
|
|
* Changed this to avoid confusion with "rc" (the plan9 shell - not
|
|
|
|
* restricted despite the name starting with 'r'). --marekm
|
2007-10-07 17:14:02 +05:30
|
|
|
*/
|
2007-10-07 17:14:59 +05:30
|
|
|
return !check_shell (sh);
|
2007-10-07 17:14:02 +05:30
|
|
|
}
|
|
|
|
|
2007-10-07 17:17:01 +05:30
|
|
|
#ifdef USE_PAM
|
|
|
|
static struct pam_conv conv = {
|
|
|
|
misc_conv,
|
|
|
|
NULL
|
|
|
|
};
|
|
|
|
#endif /* USE_PAM */
|
2007-10-07 17:14:02 +05:30
|
|
|
|
|
|
|
/*
|
|
|
|
* chsh - this command controls changes to the user's shell
|
|
|
|
*
|
2007-10-07 17:14:59 +05:30
|
|
|
* The only supported option is -s which permits the the login shell to
|
|
|
|
* be set from the command line.
|
2007-10-07 17:14:02 +05:30
|
|
|
*/
|
2007-10-07 17:14:59 +05:30
|
|
|
int main (int argc, char **argv)
|
2007-10-07 17:14:02 +05:30
|
|
|
{
|
2007-10-07 17:14:59 +05:30
|
|
|
char *user; /* User name */
|
|
|
|
int flag; /* Current command line flag */
|
|
|
|
int sflg = 0; /* -s - set shell from command line */
|
2007-10-07 17:14:02 +05:30
|
|
|
const struct passwd *pw; /* Password entry from /etc/passwd */
|
2007-10-07 17:14:59 +05:30
|
|
|
struct passwd pwent; /* New password entry */
|
2007-10-07 17:14:02 +05:30
|
|
|
|
2007-10-07 17:17:01 +05:30
|
|
|
#ifdef USE_PAM
|
|
|
|
pam_handle_t *pamh = NULL;
|
|
|
|
struct passwd *pampw;
|
|
|
|
int retval;
|
|
|
|
#endif
|
|
|
|
|
2007-10-07 17:14:59 +05:30
|
|
|
sanitize_env ();
|
2007-10-07 17:14:02 +05:30
|
|
|
|
2007-10-07 17:14:59 +05:30
|
|
|
setlocale (LC_ALL, "");
|
|
|
|
bindtextdomain (PACKAGE, LOCALEDIR);
|
|
|
|
textdomain (PACKAGE);
|
2007-10-07 17:14:02 +05:30
|
|
|
|
|
|
|
/*
|
2007-10-07 17:14:59 +05:30
|
|
|
* This command behaves different for root and non-root users.
|
2007-10-07 17:14:02 +05:30
|
|
|
*/
|
|
|
|
amroot = getuid () == 0;
|
|
|
|
|
|
|
|
/*
|
2007-10-07 17:14:59 +05:30
|
|
|
* Get the program name. The program name is used as a prefix to
|
|
|
|
* most error messages.
|
2007-10-07 17:14:02 +05:30
|
|
|
*/
|
2007-10-07 17:14:59 +05:30
|
|
|
Prog = Basename (argv[0]);
|
2007-10-07 17:14:02 +05:30
|
|
|
|
2007-10-07 17:14:59 +05:30
|
|
|
OPENLOG ("chsh");
|
2007-10-07 17:14:02 +05:30
|
|
|
|
|
|
|
/*
|
|
|
|
* There is only one option, but use getopt() anyway to
|
|
|
|
* keep things consistent.
|
|
|
|
*/
|
|
|
|
|
|
|
|
while ((flag = getopt (argc, argv, "s:")) != EOF) {
|
|
|
|
switch (flag) {
|
2007-10-07 17:14:59 +05:30
|
|
|
case 's':
|
|
|
|
sflg++;
|
|
|
|
STRFCPY (loginsh, optarg);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
usage ();
|
2007-10-07 17:14:02 +05:30
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
2007-10-07 17:14:59 +05:30
|
|
|
* There should be only one remaining argument at most and it should
|
|
|
|
* be the user's name.
|
2007-10-07 17:14:02 +05:30
|
|
|
*/
|
|
|
|
if (argc > optind + 1)
|
|
|
|
usage ();
|
|
|
|
|
|
|
|
/*
|
2007-10-07 17:14:59 +05:30
|
|
|
* Get the name of the user to check. It is either the command line
|
|
|
|
* name, or the name getlogin() returns.
|
2007-10-07 17:14:02 +05:30
|
|
|
*/
|
|
|
|
if (optind < argc) {
|
|
|
|
user = argv[optind];
|
2007-10-07 17:14:59 +05:30
|
|
|
pw = getpwnam (user);
|
2007-10-07 17:14:02 +05:30
|
|
|
if (!pw) {
|
2007-10-07 17:14:59 +05:30
|
|
|
fprintf (stderr,
|
2007-10-07 17:15:58 +05:30
|
|
|
_("%s: unknown user %s\n"), Prog, user);
|
2007-10-07 17:14:59 +05:30
|
|
|
exit (1);
|
2007-10-07 17:14:02 +05:30
|
|
|
}
|
|
|
|
} else {
|
2007-10-07 17:14:59 +05:30
|
|
|
pw = get_my_pwent ();
|
2007-10-07 17:14:02 +05:30
|
|
|
if (!pw) {
|
2007-10-07 17:14:59 +05:30
|
|
|
fprintf (stderr,
|
|
|
|
_
|
|
|
|
("%s: Cannot determine your user name.\n"),
|
|
|
|
Prog);
|
|
|
|
exit (1);
|
2007-10-07 17:14:02 +05:30
|
|
|
}
|
2007-10-07 17:14:59 +05:30
|
|
|
user = xstrdup (pw->pw_name);
|
2007-10-07 17:14:02 +05:30
|
|
|
}
|
|
|
|
|
|
|
|
#ifdef USE_NIS
|
|
|
|
/*
|
2007-10-07 17:14:59 +05:30
|
|
|
* Now we make sure this is a LOCAL password entry for this user ...
|
2007-10-07 17:14:02 +05:30
|
|
|
*/
|
|
|
|
if (__ispwNIS ()) {
|
2007-10-07 17:14:59 +05:30
|
|
|
char *nis_domain;
|
|
|
|
char *nis_master;
|
2007-10-07 17:14:02 +05:30
|
|
|
|
2007-10-07 17:14:59 +05:30
|
|
|
fprintf (stderr,
|
|
|
|
_("%s: cannot change user `%s' on NIS client.\n"),
|
|
|
|
Prog, user);
|
2007-10-07 17:14:02 +05:30
|
|
|
|
2007-10-07 17:14:59 +05:30
|
|
|
if (!yp_get_default_domain (&nis_domain) &&
|
2007-10-07 17:16:07 +05:30
|
|
|
!yp_master (nis_domain, "passwd.byname", &nis_master)) {
|
2007-10-07 17:14:59 +05:30
|
|
|
fprintf (stderr,
|
|
|
|
_
|
|
|
|
("%s: `%s' is the NIS master for this client.\n"),
|
|
|
|
Prog, nis_master);
|
2007-10-07 17:14:02 +05:30
|
|
|
}
|
|
|
|
exit (1);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/*
|
2007-10-07 17:14:59 +05:30
|
|
|
* Non-privileged users are only allowed to change the shell if the
|
|
|
|
* UID of the user matches the current real UID.
|
2007-10-07 17:14:02 +05:30
|
|
|
*/
|
2007-10-07 17:14:59 +05:30
|
|
|
if (!amroot && pw->pw_uid != getuid ()) {
|
|
|
|
SYSLOG ((LOG_WARN, "can't change shell for `%s'", user));
|
|
|
|
closelog ();
|
|
|
|
fprintf (stderr,
|
2007-10-07 17:16:07 +05:30
|
|
|
_("You may not change the shell for %s.\n"), user);
|
2007-10-07 17:14:59 +05:30
|
|
|
exit (1);
|
2007-10-07 17:14:02 +05:30
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
2007-10-07 17:14:59 +05:30
|
|
|
* Non-privileged users are only allowed to change the shell if it
|
|
|
|
* is not a restricted one.
|
2007-10-07 17:14:02 +05:30
|
|
|
*/
|
2007-10-07 17:14:59 +05:30
|
|
|
if (!amroot && restricted_shell (pw->pw_shell)) {
|
|
|
|
SYSLOG ((LOG_WARN, "can't change shell for `%s'", user));
|
|
|
|
closelog ();
|
|
|
|
fprintf (stderr,
|
2007-10-07 17:16:07 +05:30
|
|
|
_("You may not change the shell for %s.\n"), user);
|
|
|
|
exit (1);
|
|
|
|
}
|
|
|
|
#ifdef WITH_SELINUX
|
|
|
|
/*
|
|
|
|
* If the UID of the user does not match the current real UID,
|
|
|
|
* check if the change is allowed by SELinux policy.
|
|
|
|
*/
|
|
|
|
if ((pw->pw_uid != getuid ())
|
2007-10-07 17:17:01 +05:30
|
|
|
&& (selinux_check_passwd_access (PASSWD__CHSH) != 0)) {
|
2007-10-07 17:16:07 +05:30
|
|
|
SYSLOG ((LOG_WARN, "can't change shell for `%s'", user));
|
|
|
|
closelog ();
|
|
|
|
fprintf (stderr,
|
|
|
|
_("You may not change the shell for %s.\n"), user);
|
2007-10-07 17:14:59 +05:30
|
|
|
exit (1);
|
2007-10-07 17:14:02 +05:30
|
|
|
}
|
2007-10-07 17:16:07 +05:30
|
|
|
#endif
|
2007-10-07 17:14:02 +05:30
|
|
|
|
2007-10-07 17:16:07 +05:30
|
|
|
#ifndef USE_PAM
|
2007-10-07 17:14:02 +05:30
|
|
|
/*
|
2007-10-07 17:15:23 +05:30
|
|
|
* Non-privileged users are optionally authenticated (must enter
|
|
|
|
* the password of the user whose information is being changed)
|
|
|
|
* before any changes can be made. Idea from util-linux
|
|
|
|
* chfn/chsh. --marekm
|
2007-10-07 17:14:59 +05:30
|
|
|
*/
|
2007-10-07 17:16:07 +05:30
|
|
|
if (!amroot && getdef_bool ("CHSH_AUTH"))
|
2007-10-07 17:14:59 +05:30
|
|
|
passwd_check (pw->pw_name, pw->pw_passwd, "chsh");
|
2007-10-07 17:14:02 +05:30
|
|
|
|
2007-10-07 17:17:01 +05:30
|
|
|
#else /* !USE_PAM */
|
|
|
|
retval = PAM_SUCCESS;
|
|
|
|
|
|
|
|
pampw = getpwuid (getuid ());
|
|
|
|
if (pampw == NULL) {
|
|
|
|
retval = PAM_USER_UNKNOWN;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (retval == PAM_SUCCESS) {
|
|
|
|
retval = pam_start ("chsh", pampw->pw_name, &conv, &pamh);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (retval == PAM_SUCCESS) {
|
|
|
|
retval = pam_authenticate (pamh, 0);
|
|
|
|
if (retval != PAM_SUCCESS) {
|
|
|
|
pam_end (pamh, retval);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (retval == PAM_SUCCESS) {
|
|
|
|
retval = pam_acct_mgmt (pamh, 0);
|
|
|
|
if (retval != PAM_SUCCESS) {
|
|
|
|
pam_end (pamh, retval);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (retval != PAM_SUCCESS) {
|
|
|
|
fprintf (stderr, _("%s: PAM authentication failed\n"), Prog);
|
|
|
|
exit (E_NOPERM);
|
|
|
|
}
|
|
|
|
#endif /* USE_PAM */
|
2007-10-07 17:16:07 +05:30
|
|
|
|
2007-10-07 17:14:02 +05:30
|
|
|
/*
|
2007-10-07 17:14:59 +05:30
|
|
|
* Now get the login shell. Either get it from the password
|
2007-10-07 17:14:02 +05:30
|
|
|
* file, or use the value from the command line.
|
|
|
|
*/
|
2007-10-07 17:14:59 +05:30
|
|
|
if (!sflg)
|
|
|
|
STRFCPY (loginsh, pw->pw_shell);
|
2007-10-07 17:14:02 +05:30
|
|
|
|
|
|
|
/*
|
2007-10-07 17:14:59 +05:30
|
|
|
* If the login shell was not set on the command line, let the user
|
|
|
|
* interactively change it.
|
2007-10-07 17:14:02 +05:30
|
|
|
*/
|
2007-10-07 17:14:59 +05:30
|
|
|
if (!sflg) {
|
|
|
|
printf (_("Changing the login shell for %s\n"), user);
|
|
|
|
new_fields ();
|
2007-10-07 17:14:02 +05:30
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
2007-10-07 17:14:59 +05:30
|
|
|
* Check all of the fields for valid information. The shell
|
|
|
|
* field may not contain any illegal characters. Non-privileged
|
2007-10-07 17:14:02 +05:30
|
|
|
* users are restricted to using the shells in /etc/shells.
|
|
|
|
* The shell must be executable by the user.
|
|
|
|
*/
|
|
|
|
if (valid_field (loginsh, ":,=")) {
|
2007-10-07 17:16:07 +05:30
|
|
|
fprintf (stderr, _("%s: Invalid entry: %s\n"), Prog, loginsh);
|
2007-10-07 17:14:59 +05:30
|
|
|
closelog ();
|
|
|
|
exit (1);
|
2007-10-07 17:14:02 +05:30
|
|
|
}
|
2007-10-07 17:16:07 +05:30
|
|
|
if (!amroot && (!check_shell (loginsh) || access (loginsh, X_OK) != 0)) {
|
2007-10-07 17:14:59 +05:30
|
|
|
fprintf (stderr, _("%s is an invalid shell.\n"), loginsh);
|
|
|
|
closelog ();
|
|
|
|
exit (1);
|
2007-10-07 17:14:02 +05:30
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Before going any further, raise the ulimit to prevent
|
|
|
|
* colliding into a lowered ulimit, and set the real UID
|
2007-10-07 17:14:59 +05:30
|
|
|
* to root to protect against unexpected signals. Any
|
2007-10-07 17:14:02 +05:30
|
|
|
* keyboard signals are set to be ignored.
|
|
|
|
*/
|
2007-10-07 17:14:59 +05:30
|
|
|
if (setuid (0)) {
|
|
|
|
SYSLOG ((LOG_ERR, "can't setuid(0)"));
|
|
|
|
closelog ();
|
2007-10-07 17:14:02 +05:30
|
|
|
fprintf (stderr, _("Cannot change ID to root.\n"));
|
2007-10-07 17:14:59 +05:30
|
|
|
exit (1);
|
2007-10-07 17:14:02 +05:30
|
|
|
}
|
2007-10-07 17:14:59 +05:30
|
|
|
pwd_init ();
|
2007-10-07 17:14:02 +05:30
|
|
|
|
|
|
|
/*
|
|
|
|
* The passwd entry is now ready to be committed back to
|
2007-10-07 17:14:59 +05:30
|
|
|
* the password file. Get a lock on the file and open it.
|
2007-10-07 17:14:02 +05:30
|
|
|
*/
|
2007-10-07 17:14:59 +05:30
|
|
|
if (!pw_lock ()) {
|
|
|
|
SYSLOG ((LOG_WARN, "can't lock /etc/passwd"));
|
|
|
|
closelog ();
|
|
|
|
fprintf (stderr,
|
|
|
|
_
|
|
|
|
("Cannot lock the password file; try again later.\n"));
|
|
|
|
exit (1);
|
2007-10-07 17:14:02 +05:30
|
|
|
}
|
2007-10-07 17:14:59 +05:30
|
|
|
if (!pw_open (O_RDWR)) {
|
|
|
|
SYSLOG ((LOG_ERR, "can't open /etc/passwd"));
|
|
|
|
closelog ();
|
|
|
|
fprintf (stderr, _("Cannot open the password file.\n"));
|
|
|
|
pw_unlock ();
|
|
|
|
exit (1);
|
2007-10-07 17:14:02 +05:30
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Get the entry to update using pw_locate() - we want the real
|
|
|
|
* one from /etc/passwd, not the one from getpwnam() which could
|
|
|
|
* contain the shadow password if (despite the warnings) someone
|
|
|
|
* enables AUTOSHADOW (or SHADOW_COMPAT in libc). --marekm
|
|
|
|
*/
|
2007-10-07 17:14:59 +05:30
|
|
|
pw = pw_locate (user);
|
2007-10-07 17:14:02 +05:30
|
|
|
if (!pw) {
|
2007-10-07 17:14:59 +05:30
|
|
|
pw_unlock ();
|
|
|
|
fprintf (stderr,
|
2007-10-07 17:16:07 +05:30
|
|
|
_("%s: %s not found in /etc/passwd\n"), Prog, user);
|
2007-10-07 17:14:59 +05:30
|
|
|
exit (1);
|
2007-10-07 17:14:02 +05:30
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
2007-10-07 17:14:59 +05:30
|
|
|
* Make a copy of the entry, then change the shell field. The other
|
2007-10-07 17:14:02 +05:30
|
|
|
* fields remain unchanged.
|
|
|
|
*/
|
|
|
|
pwent = *pw;
|
|
|
|
pwent.pw_shell = loginsh;
|
|
|
|
|
|
|
|
/*
|
2007-10-07 17:14:59 +05:30
|
|
|
* Update the passwd file entry. If there is a DBM file, update
|
|
|
|
* that entry as well.
|
2007-10-07 17:14:02 +05:30
|
|
|
*/
|
2007-10-07 17:14:59 +05:30
|
|
|
if (!pw_update (&pwent)) {
|
|
|
|
SYSLOG ((LOG_ERR, "error updating passwd entry"));
|
|
|
|
closelog ();
|
2007-10-07 17:16:07 +05:30
|
|
|
fprintf (stderr, _("Error updating the password entry.\n"));
|
2007-10-07 17:14:59 +05:30
|
|
|
pw_unlock ();
|
|
|
|
exit (1);
|
2007-10-07 17:14:02 +05:30
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
2007-10-07 17:14:59 +05:30
|
|
|
* Changes have all been made, so commit them and unlock the file.
|
2007-10-07 17:14:02 +05:30
|
|
|
*/
|
2007-10-07 17:14:59 +05:30
|
|
|
if (!pw_close ()) {
|
|
|
|
SYSLOG ((LOG_ERR, "can't rewrite /etc/passwd"));
|
|
|
|
closelog ();
|
2007-10-07 17:16:07 +05:30
|
|
|
fprintf (stderr, _("Cannot commit password file changes.\n"));
|
2007-10-07 17:14:59 +05:30
|
|
|
pw_unlock ();
|
|
|
|
exit (1);
|
2007-10-07 17:14:02 +05:30
|
|
|
}
|
2007-10-07 17:14:59 +05:30
|
|
|
if (!pw_unlock ()) {
|
|
|
|
SYSLOG ((LOG_ERR, "can't unlock /etc/passwd"));
|
|
|
|
closelog ();
|
|
|
|
fprintf (stderr, _("Cannot unlock the password file.\n"));
|
|
|
|
exit (1);
|
2007-10-07 17:14:02 +05:30
|
|
|
}
|
2007-10-07 17:16:07 +05:30
|
|
|
SYSLOG ((LOG_INFO, "changed user `%s' shell to `%s'", user, loginsh));
|
2007-10-07 17:15:23 +05:30
|
|
|
|
|
|
|
nscd_flush_cache ("passwd");
|
|
|
|
|
2007-10-07 17:17:01 +05:30
|
|
|
#ifdef USE_PAM
|
|
|
|
if (retval == PAM_SUCCESS)
|
|
|
|
pam_end (pamh, PAM_SUCCESS);
|
|
|
|
#endif /* USE_PAM */
|
|
|
|
|
2007-10-07 17:14:59 +05:30
|
|
|
closelog ();
|
2007-10-07 17:16:52 +05:30
|
|
|
exit (E_SUCCESS);
|
2007-10-07 17:14:02 +05:30
|
|
|
}
|