2007-10-07 17:14:02 +05:30
|
|
|
/*
|
2008-04-27 06:10:09 +05:30
|
|
|
* Copyright (c) 1989 - 1994, Julianne Frances Haugh
|
|
|
|
* Copyright (c) 1996 - 2000, Marek Michałkiewicz
|
|
|
|
* Copyright (c) 2001 - 2006, Tomasz Kłoczko
|
|
|
|
* Copyright (c) 2007 - 2008, Nicolas François
|
2007-10-07 17:14:02 +05:30
|
|
|
* 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.
|
2008-04-27 06:10:09 +05:30
|
|
|
* 3. The name of the copyright holders or contributors may not be used to
|
|
|
|
* endorse or promote products derived from this software without
|
|
|
|
* specific prior written permission.
|
2007-10-07 17:14:02 +05:30
|
|
|
*
|
2008-04-27 06:10:09 +05:30
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS 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 ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
|
|
|
* HOLDERS OR CONTRIBUTORS BE LIABLE 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.
|
2007-10-07 17:14:02 +05:30
|
|
|
*/
|
|
|
|
|
|
|
|
#include <config.h>
|
|
|
|
|
2007-11-11 05:16:11 +05:30
|
|
|
#ident "$Id$"
|
2007-10-07 17:17:01 +05:30
|
|
|
|
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>
|
2007-10-07 17:16:07 +05:30
|
|
|
#ifdef WITH_SELINUX
|
|
|
|
#include <selinux/selinux.h>
|
|
|
|
#include <selinux/av_permissions.h>
|
|
|
|
#endif
|
2007-10-07 17:16:52 +05:30
|
|
|
#include "defines.h"
|
|
|
|
#include "exitcodes.h"
|
|
|
|
#include "getdef.h"
|
|
|
|
#include "nscd.h"
|
|
|
|
#ifdef USE_PAM
|
|
|
|
#include "pam_defs.h"
|
|
|
|
#endif
|
|
|
|
#include "prototypes.h"
|
|
|
|
#include "pwauth.h"
|
|
|
|
#include "pwio.h"
|
2007-10-07 17:14:02 +05:30
|
|
|
/*
|
|
|
|
* Global variables.
|
|
|
|
*/
|
|
|
|
static char *Prog;
|
|
|
|
static char fullnm[BUFSIZ];
|
|
|
|
static char roomno[BUFSIZ];
|
|
|
|
static char workph[BUFSIZ];
|
|
|
|
static char homeph[BUFSIZ];
|
|
|
|
static char slop[BUFSIZ];
|
2008-06-10 01:35:13 +05:30
|
|
|
static bool amroot;
|
2007-12-31 19:13:04 +05:30
|
|
|
/* Flags */
|
2008-06-10 01:35:13 +05:30
|
|
|
static bool fflg = false; /* -f - set full name */
|
|
|
|
static bool rflg = false; /* -r - set room number */
|
|
|
|
static bool wflg = false; /* -w - set work phone number */
|
|
|
|
static bool hflg = false; /* -h - set home phone number */
|
|
|
|
static bool oflg = false; /* -o - set other information */
|
2007-12-31 19:13:04 +05:30
|
|
|
#ifdef USE_PAM
|
|
|
|
static pam_handle_t *pamh = NULL;
|
|
|
|
#endif
|
* src/chfn.c, src/chgpasswd.c, src/chpasswd.c, src/gpasswd.c,
src/groupadd.c, src/groupdel.c, src/groupmems.c, src/groupmod.c,
src/grpconv.c, src/grpunconv.c, src/newusers.c, src/pwconv.c,
src/pwunconv.c, src/useradd.c, src/userdel.c: Harmonize the name
of the variables keeping the lock status, to match the shadow
library prefixes.
2008-08-22 07:52:34 +05:30
|
|
|
static bool pw_locked = false;
|
2007-10-07 17:14:02 +05:30
|
|
|
|
|
|
|
/*
|
|
|
|
* External identifiers
|
|
|
|
*/
|
|
|
|
|
|
|
|
/* local function prototypes */
|
2008-08-07 13:31:44 +05:30
|
|
|
static void fail_exit (int code);
|
2007-10-07 17:14:59 +05:30
|
|
|
static void usage (void);
|
2008-06-10 01:35:13 +05:30
|
|
|
static bool may_change_field (int);
|
2007-10-07 17:14:59 +05:30
|
|
|
static void new_fields (void);
|
|
|
|
static char *copy_field (char *, char *, char *);
|
2007-12-31 19:13:04 +05:30
|
|
|
static void process_flags (int argc, char **argv);
|
|
|
|
static void check_perms (const struct passwd *pw);
|
|
|
|
static void update_gecos (const char *user, char *gecos);
|
|
|
|
static void get_old_fields (const char *gecos);
|
2007-10-07 17:14:02 +05:30
|
|
|
|
2008-08-07 13:31:44 +05:30
|
|
|
/*
|
|
|
|
* fail_exit - exit with an error and do some cleanup
|
|
|
|
*/
|
|
|
|
static void fail_exit (int code)
|
|
|
|
{
|
* src/chfn.c, src/chgpasswd.c, src/chpasswd.c, src/gpasswd.c,
src/groupadd.c, src/groupdel.c, src/groupmems.c, src/groupmod.c,
src/grpconv.c, src/grpunconv.c, src/newusers.c, src/pwconv.c,
src/pwunconv.c, src/useradd.c, src/userdel.c: Harmonize the name
of the variables keeping the lock status, to match the shadow
library prefixes.
2008-08-22 07:52:34 +05:30
|
|
|
if (pw_locked) {
|
2008-08-07 13:31:44 +05:30
|
|
|
if (pw_unlock () == 0) {
|
|
|
|
fprintf (stderr, _("%s: failed to unlock %s\n"), Prog, pw_dbname ());
|
|
|
|
SYSLOG ((LOG_ERR, "failed to unlock %s", pw_dbname ()));
|
|
|
|
/* continue */
|
|
|
|
}
|
|
|
|
}
|
* src/chfn.c, src/chgpasswd.c, src/chpasswd.c, src/gpasswd.c,
src/groupadd.c, src/groupdel.c, src/groupmems.c, src/groupmod.c,
src/grpconv.c, src/grpunconv.c, src/newusers.c, src/pwconv.c,
src/pwunconv.c, src/useradd.c, src/userdel.c: Harmonize the name
of the variables keeping the lock status, to match the shadow
library prefixes.
2008-08-22 07:52:34 +05:30
|
|
|
pw_locked = false;
|
2008-08-07 13:31:44 +05:30
|
|
|
|
|
|
|
closelog ();
|
|
|
|
|
|
|
|
exit (code);
|
|
|
|
}
|
|
|
|
|
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-12-31 19:18:48 +05:30
|
|
|
if (amroot) {
|
2007-10-07 17:14:59 +05:30
|
|
|
fprintf (stderr,
|
2007-12-31 21:04:29 +05:30
|
|
|
_("Usage: %s [-f full_name] [-r room_no] "
|
|
|
|
"[-w work_ph]\n"
|
|
|
|
"\t[-h home_ph] [-o other] [user]\n"), Prog);
|
2007-12-31 19:18:48 +05:30
|
|
|
} else {
|
2007-10-07 17:14:59 +05:30
|
|
|
fprintf (stderr,
|
2007-12-31 21:04:29 +05:30
|
|
|
_("Usage: %s [-f full_name] [-r room_no] "
|
|
|
|
"[-w work_ph] [-h home_ph]\n"), Prog);
|
2007-12-31 19:18:48 +05:30
|
|
|
}
|
2007-10-07 17:16:52 +05:30
|
|
|
exit (E_USAGE);
|
2007-10-07 17:14:02 +05:30
|
|
|
}
|
|
|
|
|
2007-12-31 19:33:14 +05:30
|
|
|
/*
|
|
|
|
* may_change_field - indicate if the user is allowed to change a given field
|
|
|
|
* of her gecos information
|
|
|
|
*
|
|
|
|
* root can change any field.
|
|
|
|
*
|
|
|
|
* field should be one of 'f', 'r', 'w', 'h'
|
|
|
|
*
|
2008-06-10 01:35:13 +05:30
|
|
|
* Return true if the user can change the field and false otherwise.
|
2007-12-31 19:33:14 +05:30
|
|
|
*/
|
2008-06-10 01:35:13 +05:30
|
|
|
static bool may_change_field (int field)
|
2007-10-07 17:14:02 +05:30
|
|
|
{
|
|
|
|
const char *cp;
|
|
|
|
|
|
|
|
/*
|
2007-10-07 17:14:59 +05:30
|
|
|
* CHFN_RESTRICT can now specify exactly which fields may be changed
|
|
|
|
* by regular users, by using any combination of the following
|
|
|
|
* letters:
|
2007-10-07 17:14:02 +05:30
|
|
|
* f - full name
|
|
|
|
* r - room number
|
|
|
|
* w - work phone
|
|
|
|
* h - home phone
|
|
|
|
*
|
|
|
|
* This makes it possible to disallow changing the room number
|
2007-10-07 17:14:59 +05:30
|
|
|
* information, for example - this feature was suggested by Maciej
|
|
|
|
* 'Tycoon' Majchrowski.
|
2007-10-07 17:14:02 +05:30
|
|
|
*
|
|
|
|
* For backward compatibility, "yes" is equivalent to "rwh",
|
2007-10-07 17:14:59 +05:30
|
|
|
* "no" is equivalent to "frwh". Only root can change anything
|
2007-10-07 17:14:02 +05:30
|
|
|
* if the string is empty or not defined at all.
|
|
|
|
*/
|
2007-12-31 19:18:48 +05:30
|
|
|
if (amroot) {
|
2008-06-10 01:35:13 +05:30
|
|
|
return true;
|
2007-12-31 19:18:48 +05:30
|
|
|
}
|
|
|
|
|
2007-10-07 17:14:59 +05:30
|
|
|
cp = getdef_str ("CHFN_RESTRICT");
|
2007-12-31 19:45:29 +05:30
|
|
|
if (NULL == cp) {
|
2007-10-07 17:14:02 +05:30
|
|
|
cp = "";
|
2007-12-31 19:18:48 +05:30
|
|
|
} else if (strcmp (cp, "yes") == 0) {
|
2007-10-07 17:14:02 +05:30
|
|
|
cp = "rwh";
|
2007-12-31 19:18:48 +05:30
|
|
|
} else if (strcmp (cp, "no") == 0) {
|
2007-10-07 17:14:02 +05:30
|
|
|
cp = "frwh";
|
2007-12-31 19:18:48 +05:30
|
|
|
}
|
|
|
|
|
2007-12-31 19:45:29 +05:30
|
|
|
if (strchr (cp, field) != NULL) {
|
2008-06-10 01:35:13 +05:30
|
|
|
return true;
|
2007-12-31 19:18:48 +05:30
|
|
|
}
|
|
|
|
|
2008-06-10 01:35:13 +05:30
|
|
|
return false;
|
2007-10-07 17:14:02 +05:30
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* new_fields - change the user's GECOS information interactively
|
|
|
|
*
|
2007-10-07 17:14:59 +05:30
|
|
|
* prompt the user for each of the four fields and fill in the fields from
|
|
|
|
* the user's response, or leave alone if nothing was entered.
|
2007-10-07 17:14:02 +05:30
|
|
|
*/
|
2007-10-07 17:14:59 +05:30
|
|
|
static void new_fields (void)
|
2007-10-07 17:14:02 +05:30
|
|
|
{
|
* libmisc/age.c, libmisc/yesno.c, src/lastlog.c, src/grpck.c,
src/chfn.c, src/passwd.c, src/chage.c, src/login.c, src/sulogin.c,
src/chsh.c: Fix call to puts (remove end of line, or use fputs).
* po/*.po: Unfuzzy PO files according to above change.
2008-02-03 21:58:03 +05:30
|
|
|
puts (_("Enter the new value, or press ENTER for the default"));
|
2007-10-07 17:14:02 +05:30
|
|
|
|
2007-12-31 19:18:48 +05:30
|
|
|
if (may_change_field ('f')) {
|
2007-10-07 17:14:59 +05:30
|
|
|
change_field (fullnm, sizeof fullnm, _("Full Name"));
|
2007-12-31 19:18:48 +05:30
|
|
|
} else {
|
2007-10-07 17:14:59 +05:30
|
|
|
printf (_("\tFull Name: %s\n"), fullnm);
|
2007-12-31 19:18:48 +05:30
|
|
|
}
|
2007-10-07 17:14:02 +05:30
|
|
|
|
2007-12-31 19:18:48 +05:30
|
|
|
if (may_change_field ('r')) {
|
2007-10-07 17:14:59 +05:30
|
|
|
change_field (roomno, sizeof roomno, _("Room Number"));
|
2007-12-31 19:18:48 +05:30
|
|
|
} else {
|
2007-10-07 17:16:52 +05:30
|
|
|
printf (_("\tRoom Number: %s\n"), roomno);
|
2007-12-31 19:18:48 +05:30
|
|
|
}
|
2007-10-07 17:14:02 +05:30
|
|
|
|
2007-12-31 19:18:48 +05:30
|
|
|
if (may_change_field ('w')) {
|
2007-10-07 17:14:59 +05:30
|
|
|
change_field (workph, sizeof workph, _("Work Phone"));
|
2007-12-31 19:18:48 +05:30
|
|
|
} else {
|
2007-10-07 17:16:52 +05:30
|
|
|
printf (_("\tWork Phone: %s\n"), workph);
|
2007-12-31 19:18:48 +05:30
|
|
|
}
|
2007-10-07 17:14:02 +05:30
|
|
|
|
2007-12-31 19:18:48 +05:30
|
|
|
if (may_change_field ('h')) {
|
2007-10-07 17:14:59 +05:30
|
|
|
change_field (homeph, sizeof homeph, _("Home Phone"));
|
2007-12-31 19:18:48 +05:30
|
|
|
} else {
|
2007-10-07 17:16:52 +05:30
|
|
|
printf (_("\tHome Phone: %s\n"), homeph);
|
2007-12-31 19:18:48 +05:30
|
|
|
}
|
2007-10-07 17:14:02 +05:30
|
|
|
|
2007-12-31 19:18:48 +05:30
|
|
|
if (amroot) {
|
2007-10-07 17:14:59 +05:30
|
|
|
change_field (slop, sizeof slop, _("Other"));
|
2007-12-31 19:18:48 +05:30
|
|
|
}
|
2007-10-07 17:14:02 +05:30
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* copy_field - get the next field from the gecos field
|
|
|
|
*
|
|
|
|
* copy_field copies the next field from the gecos field, returning a
|
2007-10-07 17:14:59 +05:30
|
|
|
* pointer to the field which follows, or NULL if there are no more fields.
|
2007-10-07 17:14:02 +05:30
|
|
|
*
|
|
|
|
* in - the current GECOS field
|
|
|
|
* out - where to copy the field to
|
|
|
|
* extra - fields with '=' get copied here
|
|
|
|
*/
|
2007-10-07 17:14:59 +05:30
|
|
|
static char *copy_field (char *in, char *out, char *extra)
|
2007-10-07 17:14:02 +05:30
|
|
|
{
|
|
|
|
char *cp = NULL;
|
|
|
|
|
2007-12-31 19:45:29 +05:30
|
|
|
while (NULL != in) {
|
2007-12-31 20:07:24 +05:30
|
|
|
cp = strchr (in, ',');
|
|
|
|
if (NULL != cp) {
|
2007-10-07 17:14:02 +05:30
|
|
|
*cp++ = '\0';
|
2007-12-31 19:18:48 +05:30
|
|
|
}
|
2007-10-07 17:14:02 +05:30
|
|
|
|
2007-12-31 19:45:29 +05:30
|
|
|
if (strchr (in, '=') == NULL) {
|
2007-10-07 17:14:02 +05:30
|
|
|
break;
|
2007-12-31 19:18:48 +05:30
|
|
|
}
|
2007-10-07 17:14:02 +05:30
|
|
|
|
2007-12-31 19:45:29 +05:30
|
|
|
if (NULL != extra) {
|
|
|
|
if ('\0' != extra[0]) {
|
2007-10-07 17:14:02 +05:30
|
|
|
strcat (extra, ",");
|
2007-12-31 19:18:48 +05:30
|
|
|
}
|
2007-10-07 17:14:02 +05:30
|
|
|
|
|
|
|
strcat (extra, in);
|
|
|
|
}
|
|
|
|
in = cp;
|
|
|
|
}
|
2007-12-31 19:45:29 +05:30
|
|
|
if ((NULL != in) && (NULL != out)) {
|
2007-10-07 17:14:02 +05:30
|
|
|
strcpy (out, in);
|
2007-12-31 19:18:48 +05:30
|
|
|
}
|
2007-10-07 17:14:02 +05:30
|
|
|
|
|
|
|
return cp;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
2007-12-31 19:13:04 +05:30
|
|
|
* process_flags - parse the command line options
|
2007-10-07 17:14:02 +05:30
|
|
|
*
|
2007-12-31 19:13:04 +05:30
|
|
|
* It will not return if an error is encountered.
|
2007-10-07 17:14:02 +05:30
|
|
|
*/
|
2007-12-31 19:13:04 +05:30
|
|
|
static void process_flags (int argc, char **argv)
|
2007-10-07 17:14:02 +05:30
|
|
|
{
|
2007-10-07 17:14:59 +05:30
|
|
|
int flag; /* flag currently being processed */
|
2007-10-07 17:14:02 +05:30
|
|
|
|
|
|
|
/*
|
2007-10-07 17:14:59 +05:30
|
|
|
* The remaining arguments will be processed one by one and executed
|
|
|
|
* by this command. The name is the last argument if it does not
|
|
|
|
* begin with a "-", otherwise the name is determined from the
|
|
|
|
* environment and must agree with the real UID. Also, the UID will
|
|
|
|
* be checked for any commands which are restricted to root only.
|
2007-10-07 17:14:02 +05:30
|
|
|
*/
|
|
|
|
while ((flag = getopt (argc, argv, "f:r:w:h:o:")) != EOF) {
|
|
|
|
switch (flag) {
|
2007-10-07 17:14:59 +05:30
|
|
|
case 'f':
|
|
|
|
if (!may_change_field ('f')) {
|
|
|
|
fprintf (stderr,
|
2007-12-31 21:04:29 +05:30
|
|
|
_("%s: Permission denied.\n"), Prog);
|
2007-10-07 17:16:52 +05:30
|
|
|
exit (E_NOPERM);
|
2007-10-07 17:14:59 +05:30
|
|
|
}
|
2008-06-10 01:35:13 +05:30
|
|
|
fflg = true;
|
2007-10-07 17:14:59 +05:30
|
|
|
STRFCPY (fullnm, optarg);
|
|
|
|
break;
|
2007-10-07 17:16:34 +05:30
|
|
|
case 'h':
|
|
|
|
if (!may_change_field ('h')) {
|
2007-10-07 17:14:59 +05:30
|
|
|
fprintf (stderr,
|
2007-12-31 21:04:29 +05:30
|
|
|
_("%s: Permission denied.\n"), Prog);
|
2007-10-07 17:16:52 +05:30
|
|
|
exit (E_NOPERM);
|
2007-10-07 17:14:59 +05:30
|
|
|
}
|
2008-06-10 01:35:13 +05:30
|
|
|
hflg = true;
|
2007-10-07 17:16:34 +05:30
|
|
|
STRFCPY (homeph, optarg);
|
2007-10-07 17:14:59 +05:30
|
|
|
break;
|
2007-10-07 17:16:34 +05:30
|
|
|
case 'r':
|
|
|
|
if (!may_change_field ('r')) {
|
2007-10-07 17:14:59 +05:30
|
|
|
fprintf (stderr,
|
2007-12-31 21:04:29 +05:30
|
|
|
_("%s: Permission denied.\n"), Prog);
|
2007-10-07 17:16:52 +05:30
|
|
|
exit (E_NOPERM);
|
2007-10-07 17:14:59 +05:30
|
|
|
}
|
2008-06-10 01:35:13 +05:30
|
|
|
rflg = true;
|
2007-10-07 17:16:34 +05:30
|
|
|
STRFCPY (roomno, optarg);
|
2007-10-07 17:14:59 +05:30
|
|
|
break;
|
2007-10-07 17:16:34 +05:30
|
|
|
case 'o':
|
|
|
|
if (!amroot) {
|
2007-10-07 17:14:59 +05:30
|
|
|
fprintf (stderr,
|
2007-12-31 21:04:29 +05:30
|
|
|
_("%s: Permission denied.\n"), Prog);
|
2007-10-07 17:16:52 +05:30
|
|
|
exit (E_NOPERM);
|
2007-10-07 17:14:59 +05:30
|
|
|
}
|
2008-06-10 01:35:13 +05:30
|
|
|
oflg = true;
|
2007-10-07 17:16:34 +05:30
|
|
|
STRFCPY (slop, optarg);
|
2007-10-07 17:14:59 +05:30
|
|
|
break;
|
2007-10-07 17:16:34 +05:30
|
|
|
case 'w':
|
|
|
|
if (!may_change_field ('w')) {
|
2007-10-07 17:14:59 +05:30
|
|
|
fprintf (stderr,
|
2007-12-31 21:04:29 +05:30
|
|
|
_("%s: Permission denied.\n"), Prog);
|
2007-10-07 17:16:52 +05:30
|
|
|
exit (E_NOPERM);
|
2007-10-07 17:14:59 +05:30
|
|
|
}
|
2008-06-10 01:35:13 +05:30
|
|
|
wflg = true;
|
2007-10-07 17:16:34 +05:30
|
|
|
STRFCPY (workph, optarg);
|
2007-10-07 17:14:59 +05:30
|
|
|
break;
|
|
|
|
default:
|
|
|
|
usage ();
|
2007-10-07 17:14:02 +05:30
|
|
|
}
|
|
|
|
}
|
2007-12-31 19:13:04 +05:30
|
|
|
}
|
2007-10-07 17:14:02 +05:30
|
|
|
|
2007-12-31 19:13:04 +05:30
|
|
|
/*
|
|
|
|
* check_perms - check if the caller is allowed to add a group
|
|
|
|
*
|
|
|
|
* Non-root users are only allowed to change their gecos field.
|
|
|
|
* (see also may_change_field())
|
|
|
|
*
|
|
|
|
* Non-root users must be authenticated.
|
|
|
|
*
|
|
|
|
* It will not return if the user is not allowed.
|
|
|
|
*/
|
|
|
|
static void check_perms (const struct passwd *pw)
|
|
|
|
{
|
|
|
|
#ifdef USE_PAM
|
|
|
|
int retval;
|
|
|
|
struct passwd *pampw;
|
2007-10-07 17:14:02 +05:30
|
|
|
#endif
|
|
|
|
|
|
|
|
/*
|
2007-10-07 17:14:59 +05:30
|
|
|
* Non-privileged users are only allowed to change the gecos field
|
|
|
|
* 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 ()) {
|
2007-10-07 17:16:25 +05:30
|
|
|
fprintf (stderr, _("%s: Permission denied.\n"), Prog);
|
2007-10-07 17:14:59 +05:30
|
|
|
closelog ();
|
2007-10-07 17:16:52 +05:30
|
|
|
exit (E_NOPERM);
|
2007-10-07 17:14:02 +05:30
|
|
|
}
|
2007-10-07 17:16:07 +05:30
|
|
|
#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:22 +05:30
|
|
|
&& (is_selinux_enabled () > 0)
|
2007-10-07 17:17:01 +05:30
|
|
|
&& (selinux_check_passwd_access (PASSWD__CHFN) != 0)) {
|
2007-10-07 17:16:07 +05:30
|
|
|
fprintf (stderr, _("%s: Permission denied.\n"), Prog);
|
|
|
|
closelog ();
|
2007-10-07 17:16:52 +05:30
|
|
|
exit (E_NOPERM);
|
2007-10-07 17:16:07 +05:30
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifndef USE_PAM
|
2007-10-07 17:14:02 +05:30
|
|
|
/*
|
2007-10-07 17:14:59 +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:02 +05:30
|
|
|
*/
|
2007-12-31 19:18:48 +05:30
|
|
|
if (!amroot && getdef_bool ("CHFN_AUTH")) {
|
2007-10-07 17:14:59 +05:30
|
|
|
passwd_check (pw->pw_name, pw->pw_passwd, "chfn");
|
2007-12-31 19:18:48 +05:30
|
|
|
}
|
2007-10-07 17:14:59 +05:30
|
|
|
|
2007-10-07 17:17:01 +05:30
|
|
|
#else /* !USE_PAM */
|
|
|
|
retval = PAM_SUCCESS;
|
|
|
|
|
2007-12-31 19:13:04 +05:30
|
|
|
pampw = getpwuid (getuid ()); /* local, no need for xgetpwuid */
|
|
|
|
if (pampw == NULL) {
|
|
|
|
retval = PAM_USER_UNKNOWN;
|
|
|
|
}
|
2007-10-07 17:17:01 +05:30
|
|
|
|
2007-12-31 19:13:04 +05:30
|
|
|
if (retval == PAM_SUCCESS) {
|
|
|
|
retval = pam_start ("chfn", pampw->pw_name, &conv, &pamh);
|
2007-10-07 17:17:01 +05:30
|
|
|
}
|
|
|
|
|
|
|
|
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-12-31 19:13:04 +05:30
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* update_gecos - update the gecos fields in the password database
|
|
|
|
*
|
|
|
|
* Commit the user's entry after changing her gecos field.
|
|
|
|
*/
|
|
|
|
static void update_gecos (const char *user, char *gecos)
|
|
|
|
{
|
|
|
|
const struct passwd *pw; /* The user's password file entry */
|
|
|
|
struct passwd pwent; /* modified password file entry */
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Before going any further, raise the ulimit to prevent colliding
|
|
|
|
* into a lowered ulimit, and set the real UID to root to protect
|
|
|
|
* against unexpected signals. Any keyboard signals are set to be
|
|
|
|
* ignored.
|
|
|
|
*/
|
2007-12-31 19:45:29 +05:30
|
|
|
if (setuid (0) != 0) {
|
2008-01-25 00:09:05 +05:30
|
|
|
fputs (_("Cannot change ID to root.\n"), stderr);
|
2007-12-31 19:13:04 +05:30
|
|
|
SYSLOG ((LOG_ERR, "can't setuid(0)"));
|
2008-08-07 13:31:44 +05:30
|
|
|
fail_exit (E_NOPERM);
|
2007-12-31 19:13:04 +05:30
|
|
|
}
|
|
|
|
pwd_init ();
|
|
|
|
|
|
|
|
/*
|
|
|
|
* The passwd entry is now ready to be committed back to the
|
|
|
|
* password file. Get a lock on the file and open it.
|
|
|
|
*/
|
2007-12-31 19:45:29 +05:30
|
|
|
if (pw_lock () == 0) {
|
* lib/groupio.c, lib/groupio.h, lib/pwio.c, lib/pwio.h,
lib/sgroupio.c, lib/sgroupio.h, lib/shadowio.c, lib/shadowio.h:
Added *_dbname() functions to retrieve the name of the databases.
* lib/groupio.c, lib/groupio.h, lib/pwio.c, lib/pwio.h,
lib/sgroupio.c, lib/sgroupio.h, lib/shadowio.c, lib/shadowio.h:
*_name() functions renamed *setname().
* src/grpck.c, src/pwck.c: Likewise.
* lib/groupio.h, lib/pwio.h, lib/sgroupio.h, lib/shadowio.h: Added
the name of the arguments to the prototypes.
* src/chage, src/chfn.c, src/chgpasswd.c, src/chpasswd.c,
src/chsh.c, src/gpasswd.c, src/groupadd.c, src/groupdel.c,
src/groupmod.c, src/grpck.c, src/grpconv.c, src/grpunconv.c,
src/newusers.c, src/passwd.c, src/pwck.c, src/pwconv.c,
src/pwunconv.c, src/useradd.c, src/userdel.c, src/usermod.c:
Harmonize the erro & syslog messages in case of failure of the
*_lock(), *_open(), *_close(), *_unlock(), *_remove() functions.
* src/chgpasswd.c, src/chpasswd.c, src/usermod.c: Avoid
capitalized messages.
* src/chpasswd.c, src/useradd.c, src/usermod.c: Harmonize messages
in case of inexistent entries.
* src/usermod.c: Harmonize messages in case of already existing
entries.
* src/newusers.c, src/useradd.c: Simplify PAM error handling.
* src/useradd.c: Report failures to unlock files (stderr, syslog,
and audit). But do not fail (continue).
* src/useradd.c (open_files): Do not report to syslog & audit
failures to lock or open the databases. This might be harmless,
and the logs were not already informed that a change was
requested.
* src/usermod.c: It's not the account which is unlocked, but its
password.
2008-08-06 21:27:31 +05:30
|
|
|
fprintf (stderr,
|
|
|
|
_("%s: cannot lock %s; try again later.\n"),
|
|
|
|
Prog, pw_dbname ());
|
2008-08-07 13:31:44 +05:30
|
|
|
fail_exit (E_NOPERM);
|
2007-12-31 19:13:04 +05:30
|
|
|
}
|
* src/chfn.c, src/chgpasswd.c, src/chpasswd.c, src/gpasswd.c,
src/groupadd.c, src/groupdel.c, src/groupmems.c, src/groupmod.c,
src/grpconv.c, src/grpunconv.c, src/newusers.c, src/pwconv.c,
src/pwunconv.c, src/useradd.c, src/userdel.c: Harmonize the name
of the variables keeping the lock status, to match the shadow
library prefixes.
2008-08-22 07:52:34 +05:30
|
|
|
pw_locked = true;
|
2007-12-31 19:45:29 +05:30
|
|
|
if (pw_open (O_RDWR) == 0) {
|
* lib/groupio.c, lib/groupio.h, lib/pwio.c, lib/pwio.h,
lib/sgroupio.c, lib/sgroupio.h, lib/shadowio.c, lib/shadowio.h:
Added *_dbname() functions to retrieve the name of the databases.
* lib/groupio.c, lib/groupio.h, lib/pwio.c, lib/pwio.h,
lib/sgroupio.c, lib/sgroupio.h, lib/shadowio.c, lib/shadowio.h:
*_name() functions renamed *setname().
* src/grpck.c, src/pwck.c: Likewise.
* lib/groupio.h, lib/pwio.h, lib/sgroupio.h, lib/shadowio.h: Added
the name of the arguments to the prototypes.
* src/chage, src/chfn.c, src/chgpasswd.c, src/chpasswd.c,
src/chsh.c, src/gpasswd.c, src/groupadd.c, src/groupdel.c,
src/groupmod.c, src/grpck.c, src/grpconv.c, src/grpunconv.c,
src/newusers.c, src/passwd.c, src/pwck.c, src/pwconv.c,
src/pwunconv.c, src/useradd.c, src/userdel.c, src/usermod.c:
Harmonize the erro & syslog messages in case of failure of the
*_lock(), *_open(), *_close(), *_unlock(), *_remove() functions.
* src/chgpasswd.c, src/chpasswd.c, src/usermod.c: Avoid
capitalized messages.
* src/chpasswd.c, src/useradd.c, src/usermod.c: Harmonize messages
in case of inexistent entries.
* src/usermod.c: Harmonize messages in case of already existing
entries.
* src/newusers.c, src/useradd.c: Simplify PAM error handling.
* src/useradd.c: Report failures to unlock files (stderr, syslog,
and audit). But do not fail (continue).
* src/useradd.c (open_files): Do not report to syslog & audit
failures to lock or open the databases. This might be harmless,
and the logs were not already informed that a change was
requested.
* src/usermod.c: It's not the account which is unlocked, but its
password.
2008-08-06 21:27:31 +05:30
|
|
|
fprintf (stderr,
|
|
|
|
_("%s: cannot open %s\n"), Prog, pw_dbname ());
|
2008-08-07 13:31:44 +05:30
|
|
|
fail_exit (E_NOPERM);
|
2007-12-31 19:13:04 +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
|
|
|
|
*/
|
|
|
|
pw = pw_locate (user);
|
2007-12-31 19:45:29 +05:30
|
|
|
if (NULL == pw) {
|
2007-12-31 19:13:04 +05:30
|
|
|
fprintf (stderr,
|
* lib/groupio.c, lib/groupio.h, lib/pwio.c, lib/pwio.h,
lib/sgroupio.c, lib/sgroupio.h, lib/shadowio.c, lib/shadowio.h:
Added *_dbname() functions to retrieve the name of the databases.
* lib/groupio.c, lib/groupio.h, lib/pwio.c, lib/pwio.h,
lib/sgroupio.c, lib/sgroupio.h, lib/shadowio.c, lib/shadowio.h:
*_name() functions renamed *setname().
* src/grpck.c, src/pwck.c: Likewise.
* lib/groupio.h, lib/pwio.h, lib/sgroupio.h, lib/shadowio.h: Added
the name of the arguments to the prototypes.
* src/chage, src/chfn.c, src/chgpasswd.c, src/chpasswd.c,
src/chsh.c, src/gpasswd.c, src/groupadd.c, src/groupdel.c,
src/groupmod.c, src/grpck.c, src/grpconv.c, src/grpunconv.c,
src/newusers.c, src/passwd.c, src/pwck.c, src/pwconv.c,
src/pwunconv.c, src/useradd.c, src/userdel.c, src/usermod.c:
Harmonize the erro & syslog messages in case of failure of the
*_lock(), *_open(), *_close(), *_unlock(), *_remove() functions.
* src/chgpasswd.c, src/chpasswd.c, src/usermod.c: Avoid
capitalized messages.
* src/chpasswd.c, src/useradd.c, src/usermod.c: Harmonize messages
in case of inexistent entries.
* src/usermod.c: Harmonize messages in case of already existing
entries.
* src/newusers.c, src/useradd.c: Simplify PAM error handling.
* src/useradd.c: Report failures to unlock files (stderr, syslog,
and audit). But do not fail (continue).
* src/useradd.c (open_files): Do not report to syslog & audit
failures to lock or open the databases. This might be harmless,
and the logs were not already informed that a change was
requested.
* src/usermod.c: It's not the account which is unlocked, but its
password.
2008-08-06 21:27:31 +05:30
|
|
|
_("%s: user '%s' does not exist in %s\n"),
|
|
|
|
Prog, user, pw_dbname ());
|
2008-08-07 13:31:44 +05:30
|
|
|
fail_exit (E_NOPERM);
|
2007-12-31 19:13:04 +05:30
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Make a copy of the entry, then change the gecos field. The other
|
|
|
|
* fields remain unchanged.
|
|
|
|
*/
|
|
|
|
pwent = *pw;
|
|
|
|
pwent.pw_gecos = gecos;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Update the passwd file entry. If there is a DBM file, update that
|
|
|
|
* entry as well.
|
|
|
|
*/
|
2007-12-31 19:45:29 +05:30
|
|
|
if (pw_update (&pwent) == 0) {
|
2008-01-25 00:09:05 +05:30
|
|
|
fputs (_("Error updating the password entry.\n"), stderr);
|
2008-08-07 13:31:44 +05:30
|
|
|
fail_exit (E_NOPERM);
|
2007-12-31 19:13:04 +05:30
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Changes have all been made, so commit them and unlock the file.
|
|
|
|
*/
|
2007-12-31 19:45:29 +05:30
|
|
|
if (pw_close () == 0) {
|
* lib/groupio.c, lib/groupio.h, lib/pwio.c, lib/pwio.h,
lib/sgroupio.c, lib/sgroupio.h, lib/shadowio.c, lib/shadowio.h:
Added *_dbname() functions to retrieve the name of the databases.
* lib/groupio.c, lib/groupio.h, lib/pwio.c, lib/pwio.h,
lib/sgroupio.c, lib/sgroupio.h, lib/shadowio.c, lib/shadowio.h:
*_name() functions renamed *setname().
* src/grpck.c, src/pwck.c: Likewise.
* lib/groupio.h, lib/pwio.h, lib/sgroupio.h, lib/shadowio.h: Added
the name of the arguments to the prototypes.
* src/chage, src/chfn.c, src/chgpasswd.c, src/chpasswd.c,
src/chsh.c, src/gpasswd.c, src/groupadd.c, src/groupdel.c,
src/groupmod.c, src/grpck.c, src/grpconv.c, src/grpunconv.c,
src/newusers.c, src/passwd.c, src/pwck.c, src/pwconv.c,
src/pwunconv.c, src/useradd.c, src/userdel.c, src/usermod.c:
Harmonize the erro & syslog messages in case of failure of the
*_lock(), *_open(), *_close(), *_unlock(), *_remove() functions.
* src/chgpasswd.c, src/chpasswd.c, src/usermod.c: Avoid
capitalized messages.
* src/chpasswd.c, src/useradd.c, src/usermod.c: Harmonize messages
in case of inexistent entries.
* src/usermod.c: Harmonize messages in case of already existing
entries.
* src/newusers.c, src/useradd.c: Simplify PAM error handling.
* src/useradd.c: Report failures to unlock files (stderr, syslog,
and audit). But do not fail (continue).
* src/useradd.c (open_files): Do not report to syslog & audit
failures to lock or open the databases. This might be harmless,
and the logs were not already informed that a change was
requested.
* src/usermod.c: It's not the account which is unlocked, but its
password.
2008-08-06 21:27:31 +05:30
|
|
|
fprintf (stderr, _("%s: failure while writing changes to %s\n"), Prog, pw_dbname ());
|
|
|
|
SYSLOG ((LOG_ERR, "failure while writing changes to %s", pw_dbname ()));
|
2008-08-07 13:31:44 +05:30
|
|
|
fail_exit (E_NOPERM);
|
2007-12-31 19:13:04 +05:30
|
|
|
}
|
* src/chfn.c, src/chgpasswd.c, src/chpasswd.c, src/gpasswd.c,
src/groupadd.c, src/groupdel.c, src/groupmems.c, src/groupmod.c,
src/grpconv.c, src/grpunconv.c, src/newusers.c, src/pwconv.c,
src/pwunconv.c, src/useradd.c, src/userdel.c: Harmonize the name
of the variables keeping the lock status, to match the shadow
library prefixes.
2008-08-22 07:52:34 +05:30
|
|
|
pw_locked = false; /* If we fail to unlock, do not retry */
|
2007-12-31 19:45:29 +05:30
|
|
|
if (pw_unlock () == 0) {
|
* lib/groupio.c, lib/groupio.h, lib/pwio.c, lib/pwio.h,
lib/sgroupio.c, lib/sgroupio.h, lib/shadowio.c, lib/shadowio.h:
Added *_dbname() functions to retrieve the name of the databases.
* lib/groupio.c, lib/groupio.h, lib/pwio.c, lib/pwio.h,
lib/sgroupio.c, lib/sgroupio.h, lib/shadowio.c, lib/shadowio.h:
*_name() functions renamed *setname().
* src/grpck.c, src/pwck.c: Likewise.
* lib/groupio.h, lib/pwio.h, lib/sgroupio.h, lib/shadowio.h: Added
the name of the arguments to the prototypes.
* src/chage, src/chfn.c, src/chgpasswd.c, src/chpasswd.c,
src/chsh.c, src/gpasswd.c, src/groupadd.c, src/groupdel.c,
src/groupmod.c, src/grpck.c, src/grpconv.c, src/grpunconv.c,
src/newusers.c, src/passwd.c, src/pwck.c, src/pwconv.c,
src/pwunconv.c, src/useradd.c, src/userdel.c, src/usermod.c:
Harmonize the erro & syslog messages in case of failure of the
*_lock(), *_open(), *_close(), *_unlock(), *_remove() functions.
* src/chgpasswd.c, src/chpasswd.c, src/usermod.c: Avoid
capitalized messages.
* src/chpasswd.c, src/useradd.c, src/usermod.c: Harmonize messages
in case of inexistent entries.
* src/usermod.c: Harmonize messages in case of already existing
entries.
* src/newusers.c, src/useradd.c: Simplify PAM error handling.
* src/useradd.c: Report failures to unlock files (stderr, syslog,
and audit). But do not fail (continue).
* src/useradd.c (open_files): Do not report to syslog & audit
failures to lock or open the databases. This might be harmless,
and the logs were not already informed that a change was
requested.
* src/usermod.c: It's not the account which is unlocked, but its
password.
2008-08-06 21:27:31 +05:30
|
|
|
fprintf (stderr, _("%s: failed to unlock %s\n"), Prog, pw_dbname ());
|
|
|
|
SYSLOG ((LOG_ERR, "failed to unlock %s", pw_dbname ()));
|
2008-08-07 13:31:44 +05:30
|
|
|
fail_exit (E_NOPERM);
|
2007-12-31 19:13:04 +05:30
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* get_old_fields - parse the old gecos and use the old value for the fields
|
|
|
|
* which are not set on the command line
|
|
|
|
*/
|
|
|
|
static void get_old_fields (const char *gecos)
|
|
|
|
{
|
|
|
|
char *cp; /* temporary character pointer */
|
|
|
|
char old_gecos[BUFSIZ]; /* buffer for old GECOS fields */
|
|
|
|
STRFCPY (old_gecos, gecos);
|
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 full name. It is the first comma separated field in
|
|
|
|
* the GECOS field.
|
2007-10-07 17:14:02 +05:30
|
|
|
*/
|
2007-10-07 17:14:59 +05:30
|
|
|
cp = copy_field (old_gecos, fflg ? (char *) 0 : fullnm, slop);
|
2007-10-07 17:14:02 +05:30
|
|
|
|
|
|
|
/*
|
2007-10-07 17:14:59 +05:30
|
|
|
* Now get the room number. It is the next comma separated field,
|
2007-10-07 17:14:02 +05:30
|
|
|
* if there is indeed one.
|
|
|
|
*/
|
2007-12-31 19:45:29 +05:30
|
|
|
if (NULL != cp) {
|
2007-10-07 17:14:59 +05:30
|
|
|
cp = copy_field (cp, rflg ? (char *) 0 : roomno, slop);
|
2007-12-31 19:18:48 +05:30
|
|
|
}
|
2007-10-07 17:14:02 +05:30
|
|
|
|
|
|
|
/*
|
2007-10-07 17:14:59 +05:30
|
|
|
* Now get the work phone number. It is the third field.
|
2007-10-07 17:14:02 +05:30
|
|
|
*/
|
2007-12-31 19:45:29 +05:30
|
|
|
if (NULL != cp) {
|
2007-10-07 17:14:59 +05:30
|
|
|
cp = copy_field (cp, wflg ? (char *) 0 : workph, slop);
|
2007-12-31 19:18:48 +05:30
|
|
|
}
|
2007-10-07 17:14:02 +05:30
|
|
|
|
|
|
|
/*
|
2007-10-07 17:14:59 +05:30
|
|
|
* Now get the home phone number. It is the fourth field.
|
2007-10-07 17:14:02 +05:30
|
|
|
*/
|
2007-12-31 19:45:29 +05:30
|
|
|
if (NULL != cp) {
|
2007-10-07 17:14:59 +05:30
|
|
|
cp = copy_field (cp, hflg ? (char *) 0 : homeph, slop);
|
2007-12-31 19:18:48 +05:30
|
|
|
}
|
2007-10-07 17:14:02 +05:30
|
|
|
|
|
|
|
/*
|
|
|
|
* Anything left over is "slop".
|
|
|
|
*/
|
2007-12-31 19:45:29 +05:30
|
|
|
if ((NULL != cp) && !oflg) {
|
|
|
|
if ('\0' != slop[0]) {
|
2007-10-07 17:14:02 +05:30
|
|
|
strcat (slop, ",");
|
2007-12-31 19:18:48 +05:30
|
|
|
}
|
2007-10-07 17:14:02 +05:30
|
|
|
|
|
|
|
strcat (slop, cp);
|
|
|
|
}
|
2007-12-31 19:13:04 +05:30
|
|
|
}
|
2007-10-07 17:14:02 +05:30
|
|
|
|
2007-12-31 19:13:04 +05:30
|
|
|
/*
|
|
|
|
* check_fields - check all of the fields for valid information
|
|
|
|
*
|
|
|
|
* It will not return if a field is not valid.
|
|
|
|
*/
|
|
|
|
static void check_fields (void)
|
|
|
|
{
|
2008-04-27 05:54:49 +05:30
|
|
|
int err;
|
|
|
|
err = valid_field (fullnm, ":,=");
|
|
|
|
if (err > 0) {
|
|
|
|
fprintf (stderr, _("%s: name with non-ASCII characters: '%s'\n"), Prog, fullnm);
|
|
|
|
} else if (err < 0) {
|
2007-10-07 17:17:33 +05:30
|
|
|
fprintf (stderr, _("%s: invalid name: '%s'\n"), Prog, fullnm);
|
2008-08-07 13:31:44 +05:30
|
|
|
fail_exit (E_NOPERM);
|
2007-10-07 17:14:02 +05:30
|
|
|
}
|
2008-04-27 05:54:49 +05:30
|
|
|
err = valid_field (roomno, ":,=");
|
|
|
|
if (err > 0) {
|
|
|
|
fprintf (stderr, _("%s: room number with non-ASCII characters: '%s'\n"), Prog, roomno);
|
|
|
|
} else if (err < 0) {
|
2007-10-07 17:17:33 +05:30
|
|
|
fprintf (stderr, _("%s: invalid room number: '%s'\n"),
|
2007-12-31 21:04:29 +05:30
|
|
|
Prog, roomno);
|
2008-08-07 13:31:44 +05:30
|
|
|
fail_exit (E_NOPERM);
|
2007-10-07 17:14:02 +05:30
|
|
|
}
|
2008-06-10 01:35:13 +05:30
|
|
|
if (valid_field (workph, ":,=") != 0) {
|
2007-10-07 17:17:33 +05:30
|
|
|
fprintf (stderr, _("%s: invalid work phone: '%s'\n"),
|
2007-12-31 21:04:29 +05:30
|
|
|
Prog, workph);
|
2008-08-07 13:31:44 +05:30
|
|
|
fail_exit (E_NOPERM);
|
2007-10-07 17:14:02 +05:30
|
|
|
}
|
2008-06-10 01:35:13 +05:30
|
|
|
if (valid_field (homeph, ":,=") != 0) {
|
2007-10-07 17:17:33 +05:30
|
|
|
fprintf (stderr, _("%s: invalid home phone: '%s'\n"),
|
2007-12-31 21:04:29 +05:30
|
|
|
Prog, homeph);
|
2008-08-07 13:31:44 +05:30
|
|
|
fail_exit (E_NOPERM);
|
2007-10-07 17:14:02 +05:30
|
|
|
}
|
2008-04-27 05:54:49 +05:30
|
|
|
err = valid_field (slop, ":");
|
|
|
|
if (err > 0) {
|
|
|
|
fprintf (stderr, _("%s: '%s' contains non-ASCII characters\n"), Prog, slop);
|
|
|
|
} else if (err < 0) {
|
2007-10-07 17:14:59 +05:30
|
|
|
fprintf (stderr,
|
2007-12-31 21:04:29 +05:30
|
|
|
_("%s: '%s' contains illegal characters\n"),
|
|
|
|
Prog, slop);
|
2008-08-07 13:31:44 +05:30
|
|
|
fail_exit (E_NOPERM);
|
2007-10-07 17:14:02 +05:30
|
|
|
}
|
2007-12-31 19:13:04 +05:30
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* chfn - change a user's password file information
|
|
|
|
*
|
|
|
|
* This command controls the GECOS field information in the password
|
|
|
|
* file entry.
|
|
|
|
*
|
|
|
|
* The valid options are
|
|
|
|
*
|
|
|
|
* -f full name
|
|
|
|
* -r room number
|
|
|
|
* -w work phone number
|
|
|
|
* -h home phone number
|
|
|
|
* -o other information (*)
|
|
|
|
*
|
|
|
|
* (*) requires root permission to execute.
|
|
|
|
*/
|
|
|
|
int main (int argc, char **argv)
|
|
|
|
{
|
|
|
|
const struct passwd *pw; /* password file entry */
|
|
|
|
char new_gecos[BUFSIZ]; /* buffer for new GECOS fields */
|
|
|
|
char *user;
|
|
|
|
|
|
|
|
sanitize_env ();
|
2008-06-10 01:35:13 +05:30
|
|
|
(void) setlocale (LC_ALL, "");
|
|
|
|
(void) bindtextdomain (PACKAGE, LOCALEDIR);
|
|
|
|
(void) textdomain (PACKAGE);
|
2007-10-07 17:14:02 +05:30
|
|
|
|
|
|
|
/*
|
2007-12-31 19:13:04 +05:30
|
|
|
* This command behaves different for root and non-root
|
|
|
|
* users.
|
2007-10-07 17:14:02 +05:30
|
|
|
*/
|
2007-12-31 19:13:04 +05:30
|
|
|
amroot = (getuid () == 0);
|
2007-10-07 17:14:02 +05:30
|
|
|
|
|
|
|
/*
|
2007-12-31 19:13:04 +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-12-31 19:13:04 +05:30
|
|
|
Prog = Basename (argv[0]);
|
|
|
|
|
|
|
|
OPENLOG ("chfn");
|
|
|
|
|
|
|
|
/* parse the command line options */
|
|
|
|
process_flags (argc, argv);
|
2007-10-07 17:14:02 +05:30
|
|
|
|
|
|
|
/*
|
2007-12-31 19:13:04 +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
|
|
|
*/
|
2007-12-31 19:13:04 +05:30
|
|
|
if (optind < argc) {
|
|
|
|
user = argv[optind];
|
|
|
|
pw = xgetpwnam (user);
|
2007-12-31 19:45:29 +05:30
|
|
|
if (NULL == pw) {
|
* lib/groupio.c, lib/groupio.h, lib/pwio.c, lib/pwio.h,
lib/sgroupio.c, lib/sgroupio.h, lib/shadowio.c, lib/shadowio.h:
Added *_dbname() functions to retrieve the name of the databases.
* lib/groupio.c, lib/groupio.h, lib/pwio.c, lib/pwio.h,
lib/sgroupio.c, lib/sgroupio.h, lib/shadowio.c, lib/shadowio.h:
*_name() functions renamed *setname().
* src/grpck.c, src/pwck.c: Likewise.
* lib/groupio.h, lib/pwio.h, lib/sgroupio.h, lib/shadowio.h: Added
the name of the arguments to the prototypes.
* src/chage, src/chfn.c, src/chgpasswd.c, src/chpasswd.c,
src/chsh.c, src/gpasswd.c, src/groupadd.c, src/groupdel.c,
src/groupmod.c, src/grpck.c, src/grpconv.c, src/grpunconv.c,
src/newusers.c, src/passwd.c, src/pwck.c, src/pwconv.c,
src/pwunconv.c, src/useradd.c, src/userdel.c, src/usermod.c:
Harmonize the erro & syslog messages in case of failure of the
*_lock(), *_open(), *_close(), *_unlock(), *_remove() functions.
* src/chgpasswd.c, src/chpasswd.c, src/usermod.c: Avoid
capitalized messages.
* src/chpasswd.c, src/useradd.c, src/usermod.c: Harmonize messages
in case of inexistent entries.
* src/usermod.c: Harmonize messages in case of already existing
entries.
* src/newusers.c, src/useradd.c: Simplify PAM error handling.
* src/useradd.c: Report failures to unlock files (stderr, syslog,
and audit). But do not fail (continue).
* src/useradd.c (open_files): Do not report to syslog & audit
failures to lock or open the databases. This might be harmless,
and the logs were not already informed that a change was
requested.
* src/usermod.c: It's not the account which is unlocked, but its
password.
2008-08-06 21:27:31 +05:30
|
|
|
fprintf (stderr, _("%s: user '%s' does not exist\n"), Prog,
|
2007-12-31 21:04:29 +05:30
|
|
|
user);
|
2008-08-07 13:31:44 +05:30
|
|
|
fail_exit (E_NOPERM);
|
2007-12-31 19:13:04 +05:30
|
|
|
}
|
|
|
|
} else {
|
|
|
|
pw = get_my_pwent ();
|
2007-12-31 19:45:29 +05:30
|
|
|
if (NULL == pw) {
|
2007-12-31 19:13:04 +05:30
|
|
|
fprintf (stderr,
|
* lib/groupio.c, lib/groupio.h, lib/pwio.c, lib/pwio.h,
lib/sgroupio.c, lib/sgroupio.h, lib/shadowio.c, lib/shadowio.h:
Added *_dbname() functions to retrieve the name of the databases.
* lib/groupio.c, lib/groupio.h, lib/pwio.c, lib/pwio.h,
lib/sgroupio.c, lib/sgroupio.h, lib/shadowio.c, lib/shadowio.h:
*_name() functions renamed *setname().
* src/grpck.c, src/pwck.c: Likewise.
* lib/groupio.h, lib/pwio.h, lib/sgroupio.h, lib/shadowio.h: Added
the name of the arguments to the prototypes.
* src/chage, src/chfn.c, src/chgpasswd.c, src/chpasswd.c,
src/chsh.c, src/gpasswd.c, src/groupadd.c, src/groupdel.c,
src/groupmod.c, src/grpck.c, src/grpconv.c, src/grpunconv.c,
src/newusers.c, src/passwd.c, src/pwck.c, src/pwconv.c,
src/pwunconv.c, src/useradd.c, src/userdel.c, src/usermod.c:
Harmonize the erro & syslog messages in case of failure of the
*_lock(), *_open(), *_close(), *_unlock(), *_remove() functions.
* src/chgpasswd.c, src/chpasswd.c, src/usermod.c: Avoid
capitalized messages.
* src/chpasswd.c, src/useradd.c, src/usermod.c: Harmonize messages
in case of inexistent entries.
* src/usermod.c: Harmonize messages in case of already existing
entries.
* src/newusers.c, src/useradd.c: Simplify PAM error handling.
* src/useradd.c: Report failures to unlock files (stderr, syslog,
and audit). But do not fail (continue).
* src/useradd.c (open_files): Do not report to syslog & audit
failures to lock or open the databases. This might be harmless,
and the logs were not already informed that a change was
requested.
* src/usermod.c: It's not the account which is unlocked, but its
password.
2008-08-06 21:27:31 +05:30
|
|
|
_("%s: Cannot determine your user name.\n"),
|
2007-12-31 21:04:29 +05:30
|
|
|
Prog);
|
2008-08-07 13:31:44 +05:30
|
|
|
fail_exit (E_NOPERM);
|
2007-12-31 19:13:04 +05:30
|
|
|
}
|
|
|
|
user = xstrdup (pw->pw_name);
|
2007-10-07 17:14:02 +05:30
|
|
|
}
|
|
|
|
|
2007-12-31 19:13:04 +05:30
|
|
|
#ifdef USE_NIS
|
2007-10-07 17:14:02 +05:30
|
|
|
/*
|
2007-12-31 19:13:04 +05:30
|
|
|
* Now we make sure this is a LOCAL password entry for this user ...
|
2007-10-07 17:14:02 +05:30
|
|
|
*/
|
2007-12-31 19:13:04 +05:30
|
|
|
if (__ispwNIS ()) {
|
|
|
|
char *nis_domain;
|
|
|
|
char *nis_master;
|
|
|
|
|
2007-10-07 17:14:59 +05:30
|
|
|
fprintf (stderr,
|
2007-12-31 21:04:29 +05:30
|
|
|
_("%s: cannot change user '%s' on NIS client.\n"),
|
|
|
|
Prog, user);
|
2007-12-31 19:13:04 +05:30
|
|
|
|
|
|
|
if (!yp_get_default_domain (&nis_domain) &&
|
|
|
|
!yp_master (nis_domain, "passwd.byname", &nis_master)) {
|
|
|
|
fprintf (stderr,
|
2007-12-31 21:04:29 +05:30
|
|
|
_
|
|
|
|
("%s: '%s' is the NIS master for this client.\n"),
|
|
|
|
Prog, nis_master);
|
2007-12-31 19:13:04 +05:30
|
|
|
}
|
2008-08-07 13:31:44 +05:30
|
|
|
fail_exit (E_NOPERM);
|
2007-10-07 17:14:02 +05:30
|
|
|
}
|
2007-12-31 19:13:04 +05:30
|
|
|
#endif
|
|
|
|
|
|
|
|
/* Check that the caller is allowed to change the gecos of the
|
|
|
|
* specified user */
|
|
|
|
check_perms (pw);
|
|
|
|
|
|
|
|
/* If some fields were not set on the command line, load the value from
|
|
|
|
* the old gecos fields. */
|
|
|
|
get_old_fields (pw->pw_gecos);
|
2007-10-07 17:14:02 +05:30
|
|
|
|
|
|
|
/*
|
2007-12-31 19:13:04 +05:30
|
|
|
* If none of the fields were changed from the command line, let the
|
|
|
|
* user interactively change them.
|
2007-10-07 17:14:02 +05:30
|
|
|
*/
|
2007-12-31 19:13:04 +05:30
|
|
|
if (!fflg && !rflg && !wflg && !hflg && !oflg) {
|
|
|
|
printf (_("Changing the user information for %s\n"), user);
|
|
|
|
new_fields ();
|
|
|
|
}
|
2007-10-07 17:14:02 +05:30
|
|
|
|
|
|
|
/*
|
2007-12-31 19:13:04 +05:30
|
|
|
* Check all of the fields for valid information
|
2007-10-07 17:14:02 +05:30
|
|
|
*/
|
2007-12-31 19:13:04 +05:30
|
|
|
check_fields ();
|
2007-10-07 17:14:02 +05:30
|
|
|
|
|
|
|
/*
|
2007-12-31 19:13:04 +05:30
|
|
|
* Build the new GECOS field by plastering all the pieces together,
|
|
|
|
* if they will fit ...
|
2007-10-07 17:14:02 +05:30
|
|
|
*/
|
2007-12-31 19:45:29 +05:30
|
|
|
if ((strlen (fullnm) + strlen (roomno) + strlen (workph) +
|
|
|
|
strlen (homeph) + strlen (slop)) > (unsigned int) 80) {
|
2007-12-31 19:13:04 +05:30
|
|
|
fprintf (stderr, _("%s: fields too long\n"), Prog);
|
2008-08-07 13:31:44 +05:30
|
|
|
fail_exit (E_NOPERM);
|
2007-10-07 17:14:02 +05:30
|
|
|
}
|
2007-12-31 19:13:04 +05:30
|
|
|
snprintf (new_gecos, sizeof new_gecos, "%s,%s,%s,%s%s%s",
|
2008-06-10 01:35:13 +05:30
|
|
|
fullnm, roomno, workph, homeph,
|
|
|
|
('\0' != slop[0]) ? "," : "", slop);
|
2007-12-31 19:13:04 +05:30
|
|
|
|
|
|
|
/* Rewrite the user's gecos in the passwd file */
|
|
|
|
update_gecos (user, new_gecos);
|
|
|
|
|
* src/chfn.c, src/chsh.c, src/groupdel.c, src/groupmems.c,
src/groupmod.c, src/grpck.c, src/login.c, src/logoutd.c,
src/newgrp.c, src/newusers.c, src/passwd.c, src/pwck.c,
src/suauth.c, src/useradd.c, src/userdel.c, src/usermod.c,
src/vipw.c: Complete the switch from the `' quotation style to ''.
Do it also in SYSLOG messages. Quote some parameters. All this
permits to merge some messages.
2008-08-06 21:21:52 +05:30
|
|
|
SYSLOG ((LOG_INFO, "changed user '%s' information", user));
|
2007-10-07 17:15:23 +05:30
|
|
|
|
|
|
|
nscd_flush_cache ("passwd");
|
|
|
|
|
2007-10-07 17:17:01 +05:30
|
|
|
#ifdef USE_PAM
|
2008-08-07 13:31:44 +05:30
|
|
|
(void) pam_end (pamh, PAM_SUCCESS);
|
2007-10-07 17:17:01 +05:30
|
|
|
#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
|
|
|
}
|
2007-12-31 19:45:29 +05:30
|
|
|
|