2007-10-07 11:44:02 +00:00
|
|
|
/*
|
2021-12-05 09:35:27 -06:00
|
|
|
* SPDX-FileCopyrightText: 1991 - 1994, Julianne Frances Haugh
|
|
|
|
* SPDX-FileCopyrightText: 1996 - 2000, Marek Michałkiewicz
|
|
|
|
* SPDX-FileCopyrightText: 2000 - 2006, Tomasz Kłoczko
|
|
|
|
* SPDX-FileCopyrightText: 2007 - 2011, Nicolas François
|
2007-10-07 11:44:02 +00:00
|
|
|
*
|
2021-12-05 09:35:27 -06:00
|
|
|
* SPDX-License-Identifier: BSD-3-Clause
|
2007-10-07 11:44:02 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include <config.h>
|
|
|
|
|
2007-11-10 23:46:11 +00:00
|
|
|
#ident "$Id$"
|
2007-10-07 11:47:01 +00:00
|
|
|
|
2007-10-07 11:44:02 +00:00
|
|
|
#include <ctype.h>
|
|
|
|
#include <fcntl.h>
|
2007-10-07 11:47:01 +00:00
|
|
|
#include <grp.h>
|
2007-10-07 11:44:02 +00:00
|
|
|
#include <pwd.h>
|
* configure.in: Added option --enable-account-tools-setuid to
enable/disable the usage of PAM to authenticate the callers of
account management tools: chage, chgpasswd, chpasswd, groupadd,
groupdel, groupmod, useradd, userdel, usermod.
* src/Makefile.am: Do not link the above tools with libpam if
account-tools-setuid is disabled.
* src/userdel.c, src/newusers.c, src/chpasswd.c, src/usermod.c,
src/groupdel.c, src/chgpasswd.c, src/useradd.c, src/groupmod.c,
src/groupadd.c, src/chage.c: Implement ACCT_TOOLS_SETUID
(--enable-account-tools-setuid).
* etc/pam.d/Makefile.am: Install the pam service file for the
above tools only when needed.
* src/useradd.c, src/userdel.c, src/usermod.c: It is no more
needed to initialize retval to PAM_SUCCESS.
2008-09-06 21:35:37 +00:00
|
|
|
#ifdef ACCT_TOOLS_SETUID
|
2007-10-07 11:44:38 +00:00
|
|
|
#ifdef USE_PAM
|
2007-10-07 11:47:11 +00:00
|
|
|
#include "pam_defs.h"
|
2007-10-07 11:45:23 +00:00
|
|
|
#endif /* USE_PAM */
|
* configure.in: Added option --enable-account-tools-setuid to
enable/disable the usage of PAM to authenticate the callers of
account management tools: chage, chgpasswd, chpasswd, groupadd,
groupdel, groupmod, useradd, userdel, usermod.
* src/Makefile.am: Do not link the above tools with libpam if
account-tools-setuid is disabled.
* src/userdel.c, src/newusers.c, src/chpasswd.c, src/usermod.c,
src/groupdel.c, src/chgpasswd.c, src/useradd.c, src/groupmod.c,
src/groupadd.c, src/chage.c: Implement ACCT_TOOLS_SETUID
(--enable-account-tools-setuid).
* etc/pam.d/Makefile.am: Install the pam service file for the
above tools only when needed.
* src/useradd.c, src/userdel.c, src/usermod.c: It is no more
needed to initialize retval to PAM_SUCCESS.
2008-09-06 21:35:37 +00:00
|
|
|
#endif /* ACCT_TOOLS_SETUID */
|
2007-10-07 11:47:01 +00:00
|
|
|
#include <stdio.h>
|
|
|
|
#include <sys/types.h>
|
2011-11-06 18:37:57 +00:00
|
|
|
#include <getopt.h>
|
2007-10-07 11:47:01 +00:00
|
|
|
#include "defines.h"
|
|
|
|
#include "groupio.h"
|
2007-10-07 11:45:23 +00:00
|
|
|
#include "nscd.h"
|
Flush sssd caches in addition to nscd caches
Some distributions, notably Fedora, have the following order of nsswitch
modules by default:
passwd: sss files
group: sss files
The advantage of serving local users through SSSD is that the nss_sss
module has a fast mmapped-cache that speeds up NSS lookups compared to
accessing the disk an opening the files on each NSS request.
Traditionally, this has been done with the help of nscd, but using nscd
in parallel with sssd is cumbersome, as both SSSD and nscd use their own
independent caching, so using nscd in setups where sssd is also serving
users from some remote domain (LDAP, AD, ...) can result in a bit of
unpredictability.
More details about why Fedora chose to use sss before files can be found
on e.g.:
https://fedoraproject.org//wiki/Changes/SSSDCacheForLocalUsers
or:
https://docs.pagure.org/SSSD.sssd/design_pages/files_provider.html
Now, even though sssd watches the passwd and group files with the help
of inotify, there can still be a small window where someone requests a
user or a group, finds that it doesn't exist, adds the entry and checks
again. Without some support in shadow-utils that would explicitly drop
the sssd caches, the inotify watch can fire a little late, so a
combination of commands like this:
getent passwd user || useradd user; getent passwd user
can result in the second getent passwd not finding the newly added user
as the racy behaviour might still return the cached negative hit from
the first getent passwd.
This patch more or less copies the already existing support that
shadow-utils had for dropping nscd caches, except using the "sss_cache"
tool that sssd ships.
2018-09-12 14:22:11 +02:00
|
|
|
#include "sssd.h"
|
2007-10-07 11:44:02 +00:00
|
|
|
#include "prototypes.h"
|
2007-10-07 11:47:01 +00:00
|
|
|
#ifdef SHADOWGRP
|
|
|
|
#include "sgroupio.h"
|
|
|
|
#endif
|
2021-11-28 17:37:53 -06:00
|
|
|
#include "shadowlog.h"
|
2007-10-07 11:47:01 +00:00
|
|
|
/*
|
|
|
|
* Global variables
|
|
|
|
*/
|
* src/newgrp.c, src/userdel.c, src/grpck.c, src/gpasswd.c,
src/newusers.c, src/pwconv.c, src/chpasswd.c, src/logoutd.c,
src/chfn.c, src/groupmems.c, src/usermod.c, src/pwunconv.c,
src/expiry.c, src/groupdel.c, src/chgpasswd.c, src/useradd.c,
src/su.c, src/groupmod.c, src/passwd.c, src/pwck.c, src/chage.c,
src/groupadd.c, src/login.c, src/grpconv.c, src/groups.c,
src/grpunconv.c, src/chsh.c: Prog changed to a constant string.
2010-08-22 19:36:09 +00:00
|
|
|
const char *Prog;
|
* src/newgrp.c, src/userdel.c, src/grpck.c, src/gpasswd.c,
src/newusers.c, src/pwconv.c, src/chpasswd.c, src/logoutd.c,
src/chfn.c, src/groupmems.c, src/usermod.c, src/pwunconv.c,
src/expiry.c, src/groupdel.c, src/chgpasswd.c, src/useradd.c,
src/su.c, src/groupmod.c, src/passwd.c, src/pwck.c,
src/groupadd.c, src/chage.c, src/login.c, src/grpconv.c,
src/groups.c, src/grpunconv.c, src/chsh.c: Prog is now global (not
static to the file) so that it can be used by the helper functions
of libmisc.
* lib/prototypes.h: Added extern char *Prog.
* libmisc/find_new_gid.c, libmisc/find_new_uid.c: Indicate the
program name with the warning.
2008-09-06 12:51:53 +00:00
|
|
|
|
2007-10-07 11:45:23 +00:00
|
|
|
static char *group_name;
|
2007-10-07 11:47:01 +00:00
|
|
|
static gid_t group_id = -1;
|
2015-06-12 17:32:50 -05:00
|
|
|
static bool check_group_busy = true;
|
2007-10-07 11:44:02 +00:00
|
|
|
|
2016-05-15 15:49:39 +02:00
|
|
|
static const char* prefix = "";
|
|
|
|
|
2007-10-07 11:44:02 +00:00
|
|
|
#ifdef SHADOWGRP
|
2008-06-09 20:54:04 +00:00
|
|
|
static bool is_shadow_grp;
|
2007-10-07 11:44:02 +00:00
|
|
|
#endif
|
|
|
|
|
|
|
|
/*
|
|
|
|
* exit status values
|
|
|
|
*/
|
* src/newgrp.c, src/chfn.c, src/groupmems.c, src/usermod.c,
src/userdel.c, src/chpasswd.c, src/grpck.c, src/gpasswd.c,
src/groupdel.c, src/chgpasswd.c, src/vipw.c, src/useradd.c,
src/su.c, src/groupmod.c, src/passwd.c, src/pwck.c,
src/groupadd.c, src/chage.c, src/login.c, src/faillog.c,
src/sulogin.c, src/chsh.c, src/pwconv.c: Added splint annotations.
* src/userdel.c, src/pwconv.c, src/lastlog.c, src/grpck.c,
src/vipw.c, src/groupmod.c, src/passwd.c, src/pwck.c, src/login.c,
src/sulogin.c, src/usermod.c: Use return instead of exit at the
end of main().
* src/gpasswd.c, src/passwd.c, src/faillog.c: Use the exitcodes.h
exit codes.
* src/chpasswd.c: Added missing ||.
* src/nologin.c: Do not include exitcodes.h.
* src/nologin.c: Added brackets.
* src/nologin.c: Avoid assignments in comparisons.
2009-04-30 21:39:38 +00:00
|
|
|
/*@-exitarg@*/
|
2007-10-07 11:44:02 +00:00
|
|
|
#define E_SUCCESS 0 /* success */
|
|
|
|
#define E_USAGE 2 /* invalid command syntax */
|
|
|
|
#define E_NOTFOUND 6 /* specified group doesn't exist */
|
|
|
|
#define E_GROUP_BUSY 8 /* can't remove user's primary group */
|
|
|
|
#define E_GRP_UPDATE 10 /* can't update group file */
|
|
|
|
|
|
|
|
/* local function prototypes */
|
2011-11-06 18:37:57 +00:00
|
|
|
static /*@noreturn@*/void usage (int status);
|
2007-10-07 11:45:23 +00:00
|
|
|
static void grp_update (void);
|
|
|
|
static void close_files (void);
|
|
|
|
static void open_files (void);
|
2011-11-06 18:37:57 +00:00
|
|
|
static void group_busy (gid_t gid);
|
|
|
|
static void process_flags (int argc, char **argv);
|
2007-10-07 11:44:02 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* usage - display usage message and exit
|
|
|
|
*/
|
2011-11-06 18:37:57 +00:00
|
|
|
static /*@noreturn@*/void usage (int status)
|
2007-10-07 11:44:02 +00:00
|
|
|
{
|
2011-11-06 18:37:57 +00:00
|
|
|
FILE *usageout = (E_SUCCESS != status) ? stderr : stdout;
|
|
|
|
(void) fprintf (usageout,
|
|
|
|
_("Usage: %s [options] GROUP\n"
|
|
|
|
"\n"
|
|
|
|
"Options:\n"),
|
|
|
|
Prog);
|
|
|
|
(void) fputs (_(" -h, --help display this help message and exit\n"), usageout);
|
|
|
|
(void) fputs (_(" -R, --root CHROOT_DIR directory to chroot into\n"), usageout);
|
2016-05-15 15:49:39 +02:00
|
|
|
(void) fputs (_(" -P, --prefix PREFIX_DIR prefix directory where are located the /etc/* files\n"), usageout);
|
2015-06-12 17:32:50 -05:00
|
|
|
(void) fputs (_(" -f, --force delete group even if it is the primary group of a user\n"), usageout);
|
2011-11-06 18:37:57 +00:00
|
|
|
(void) fputs ("\n", usageout);
|
|
|
|
exit (status);
|
2007-10-07 11:44:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* grp_update - update group file entries
|
|
|
|
*
|
|
|
|
* grp_update() writes the new records to the group files.
|
|
|
|
*/
|
2007-10-07 11:45:23 +00:00
|
|
|
static void grp_update (void)
|
2007-10-07 11:44:02 +00:00
|
|
|
{
|
2008-12-22 21:52:43 +00:00
|
|
|
/*
|
|
|
|
* To add the group, we need to update /etc/group.
|
|
|
|
* Make sure failures will be reported.
|
|
|
|
*/
|
|
|
|
add_cleanup (cleanup_report_del_group_group, group_name);
|
|
|
|
#ifdef SHADOWGRP
|
|
|
|
if (is_shadow_grp) {
|
|
|
|
/* We also need to update /etc/gshadow */
|
|
|
|
add_cleanup (cleanup_report_del_group_gshadow, group_name);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Delete the group entry.
|
|
|
|
*/
|
2008-06-09 20:54:04 +00:00
|
|
|
if (gr_remove (group_name) == 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 15:57:31 +00:00
|
|
|
fprintf (stderr,
|
|
|
|
_("%s: cannot remove entry '%s' from %s\n"),
|
|
|
|
Prog, group_name, gr_dbname ());
|
2008-12-22 21:52:43 +00:00
|
|
|
exit (E_GRP_UPDATE);
|
2007-10-07 11:44:02 +00:00
|
|
|
}
|
2008-12-22 21:52:43 +00:00
|
|
|
|
2007-10-07 11:44:02 +00:00
|
|
|
#ifdef SHADOWGRP
|
|
|
|
/*
|
|
|
|
* Delete the shadow group entries as well.
|
|
|
|
*/
|
2008-03-08 16:17:07 +00:00
|
|
|
if (is_shadow_grp && (sgr_locate (group_name) != NULL)) {
|
2008-06-09 20:54:04 +00:00
|
|
|
if (sgr_remove (group_name) == 0) {
|
2008-03-08 16:17:07 +00:00
|
|
|
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 15:57:31 +00:00
|
|
|
_("%s: cannot remove entry '%s' from %s\n"),
|
|
|
|
Prog, group_name, sgr_dbname ());
|
2008-12-22 21:52:43 +00:00
|
|
|
exit (E_GRP_UPDATE);
|
2008-03-08 16:17:07 +00:00
|
|
|
}
|
2007-10-07 11:44:02 +00:00
|
|
|
}
|
2007-10-07 11:45:23 +00:00
|
|
|
#endif /* SHADOWGRP */
|
2007-10-07 11:44:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* close_files - close all of the files that were opened
|
|
|
|
*
|
|
|
|
* close_files() closes all of the files that were opened for this
|
|
|
|
* new group. This causes any modified entries to be written out.
|
|
|
|
*/
|
2007-10-07 11:45:23 +00:00
|
|
|
static void close_files (void)
|
2007-10-07 11:44:02 +00:00
|
|
|
{
|
2008-12-22 21:52:43 +00:00
|
|
|
/* First, write the changes in the regular group database */
|
|
|
|
if (gr_close () == 0) {
|
|
|
|
fprintf (stderr,
|
|
|
|
_("%s: failure while writing changes to %s\n"),
|
|
|
|
Prog, gr_dbname ());
|
|
|
|
exit (E_GRP_UPDATE);
|
|
|
|
}
|
|
|
|
|
2008-03-08 16:20:55 +00:00
|
|
|
#ifdef WITH_AUDIT
|
2008-09-03 21:02:32 +00:00
|
|
|
audit_logger (AUDIT_DEL_GROUP, Prog,
|
2008-12-22 21:52:43 +00:00
|
|
|
"removing group from /etc/group",
|
2008-09-04 19:35:48 +00:00
|
|
|
group_name, (unsigned int) group_id,
|
|
|
|
SHADOW_AUDIT_SUCCESS);
|
2008-03-08 16:20:55 +00:00
|
|
|
#endif
|
2008-12-22 21:52:43 +00:00
|
|
|
SYSLOG ((LOG_INFO,
|
|
|
|
"group '%s' removed from %s",
|
|
|
|
group_name, gr_dbname ()));
|
|
|
|
del_cleanup (cleanup_report_del_group_group);
|
2008-03-08 16:20:55 +00:00
|
|
|
|
2008-12-22 21:52:43 +00:00
|
|
|
cleanup_unlock_group (NULL);
|
|
|
|
del_cleanup (cleanup_unlock_group);
|
|
|
|
|
|
|
|
|
|
|
|
/* Then, write the changes in the shadow database */
|
2007-10-07 11:44:02 +00:00
|
|
|
#ifdef SHADOWGRP
|
2008-08-06 15:54:49 +00:00
|
|
|
if (is_shadow_grp) {
|
2008-08-22 02:31:55 +00:00
|
|
|
if (sgr_close () == 0) {
|
2008-08-06 15:54:49 +00:00
|
|
|
fprintf (stderr,
|
2008-08-22 02:31:55 +00:00
|
|
|
_("%s: failure while writing changes to %s\n"),
|
|
|
|
Prog, sgr_dbname ());
|
2008-12-22 21:52:43 +00:00
|
|
|
exit (E_GRP_UPDATE);
|
2008-08-06 15:54:49 +00:00
|
|
|
}
|
2008-12-22 21:52:43 +00:00
|
|
|
|
2008-08-06 15:54:49 +00:00
|
|
|
#ifdef WITH_AUDIT
|
2008-12-22 21:52:43 +00:00
|
|
|
audit_logger (AUDIT_DEL_GROUP, Prog,
|
|
|
|
"removing group from /etc/gshadow",
|
|
|
|
group_name, (unsigned int) group_id,
|
|
|
|
SHADOW_AUDIT_SUCCESS);
|
2008-08-06 15:54:49 +00:00
|
|
|
#endif
|
2008-12-22 21:52:43 +00:00
|
|
|
SYSLOG ((LOG_INFO,
|
|
|
|
"group '%s' removed from %s",
|
|
|
|
group_name, sgr_dbname ()));
|
|
|
|
del_cleanup (cleanup_report_del_group_gshadow);
|
|
|
|
|
|
|
|
cleanup_unlock_gshadow (NULL);
|
|
|
|
del_cleanup (cleanup_unlock_gshadow);
|
2007-10-07 11:44:02 +00:00
|
|
|
}
|
2007-10-07 11:45:23 +00:00
|
|
|
#endif /* SHADOWGRP */
|
2008-12-22 21:52:43 +00:00
|
|
|
|
|
|
|
/* Report success at the system level */
|
|
|
|
#ifdef WITH_AUDIT
|
|
|
|
audit_logger (AUDIT_DEL_GROUP, Prog,
|
|
|
|
"",
|
|
|
|
group_name, (unsigned int) group_id,
|
|
|
|
SHADOW_AUDIT_SUCCESS);
|
|
|
|
#endif
|
|
|
|
SYSLOG ((LOG_INFO, "group '%s' removed\n", group_name));
|
|
|
|
del_cleanup (cleanup_report_del_group);
|
2007-10-07 11:44:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* open_files - lock and open the group files
|
|
|
|
*
|
|
|
|
* open_files() opens the two group files.
|
|
|
|
*/
|
2007-10-07 11:45:23 +00:00
|
|
|
static void open_files (void)
|
2007-10-07 11:44:02 +00:00
|
|
|
{
|
2008-12-22 21:52:43 +00:00
|
|
|
/* First, lock the databases */
|
2008-06-09 20:54:04 +00:00
|
|
|
if (gr_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 15:57:31 +00:00
|
|
|
fprintf (stderr,
|
* src/chage.c, src/chgpasswd.c, src/chpasswd.c, src/chsh.c,
src/gpasswd.c, src/groupadd.c, src/groupdel.c, src/groupmems.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: In
case of a lock failure, indicate to the user that she can try
again later. Do not log to syslog.
2008-08-22 02:20:53 +00:00
|
|
|
_("%s: cannot lock %s; try again later.\n"),
|
|
|
|
Prog, gr_dbname ());
|
2008-12-22 21:52:43 +00:00
|
|
|
exit (E_GRP_UPDATE);
|
2007-10-07 11:44:02 +00:00
|
|
|
}
|
2008-12-22 21:52:43 +00:00
|
|
|
add_cleanup (cleanup_unlock_group, NULL);
|
2007-10-07 11:44:02 +00:00
|
|
|
#ifdef SHADOWGRP
|
2008-08-06 15:54:49 +00:00
|
|
|
if (is_shadow_grp) {
|
2008-08-22 02:31:55 +00:00
|
|
|
if (sgr_lock () == 0) {
|
2008-08-06 15:54:49 +00:00
|
|
|
fprintf (stderr,
|
* src/chage.c, src/chgpasswd.c, src/chpasswd.c, src/chsh.c,
src/gpasswd.c, src/groupadd.c, src/groupdel.c, src/groupmems.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: In
case of a lock failure, indicate to the user that she can try
again later. Do not log to syslog.
2008-08-22 02:20:53 +00:00
|
|
|
_("%s: cannot lock %s; try again later.\n"),
|
* 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 15:57:31 +00:00
|
|
|
Prog, sgr_dbname ());
|
2008-12-22 21:52:43 +00:00
|
|
|
exit (E_GRP_UPDATE);
|
2008-08-06 15:54:49 +00:00
|
|
|
}
|
2008-12-22 21:52:43 +00:00
|
|
|
add_cleanup (cleanup_unlock_gshadow, NULL);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Now, if the group is not removed, it's our fault.
|
|
|
|
* Make sure failures will be reported.
|
|
|
|
*/
|
|
|
|
add_cleanup (cleanup_report_del_group, group_name);
|
|
|
|
|
|
|
|
/* An now open the databases */
|
2015-02-27 13:17:25 +00:00
|
|
|
if (gr_open (O_CREAT | O_RDWR) == 0) {
|
2008-12-22 21:52:43 +00:00
|
|
|
fprintf (stderr,
|
2008-12-22 22:07:12 +00:00
|
|
|
_("%s: cannot open %s\n"),
|
|
|
|
Prog, gr_dbname ());
|
2008-12-22 21:52:43 +00:00
|
|
|
SYSLOG ((LOG_WARN, "cannot open %s", gr_dbname ()));
|
|
|
|
exit (E_GRP_UPDATE);
|
|
|
|
}
|
|
|
|
#ifdef SHADOWGRP
|
|
|
|
if (is_shadow_grp) {
|
2015-02-27 13:17:25 +00:00
|
|
|
if (sgr_open (O_CREAT | O_RDWR) == 0) {
|
2008-08-06 15:54:49 +00:00
|
|
|
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 15:57:31 +00:00
|
|
|
_("%s: cannot open %s\n"),
|
|
|
|
Prog, sgr_dbname ());
|
|
|
|
SYSLOG ((LOG_WARN, "cannot open %s", sgr_dbname ()));
|
2008-12-22 21:52:43 +00:00
|
|
|
exit (E_GRP_UPDATE);
|
2008-08-06 15:54:49 +00:00
|
|
|
}
|
2007-10-07 11:44:02 +00:00
|
|
|
}
|
2007-10-07 11:45:23 +00:00
|
|
|
#endif /* SHADOWGRP */
|
2007-10-07 11:44:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* group_busy - check if this is any user's primary group
|
|
|
|
*
|
|
|
|
* group_busy verifies that this group is not the primary group
|
|
|
|
* for any user. You must remove all users before you remove
|
|
|
|
* the group.
|
|
|
|
*/
|
2007-10-07 11:45:23 +00:00
|
|
|
static void group_busy (gid_t gid)
|
2007-10-07 11:44:02 +00:00
|
|
|
{
|
2007-10-07 11:45:23 +00:00
|
|
|
struct passwd *pwd;
|
2007-10-07 11:44:02 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Nice slow linear search.
|
|
|
|
*/
|
|
|
|
|
2016-05-15 15:49:39 +02:00
|
|
|
prefix_setpwent ();
|
2007-10-07 11:44:02 +00:00
|
|
|
|
2016-05-15 15:49:39 +02:00
|
|
|
while ( ((pwd = prefix_getpwent ()) != NULL) && (pwd->pw_gid != gid) );
|
2007-10-07 11:44:02 +00:00
|
|
|
|
2016-05-15 15:49:39 +02:00
|
|
|
prefix_endpwent ();
|
2007-10-07 11:44:02 +00:00
|
|
|
|
|
|
|
/*
|
* lib/prototypes.h, configure.in, libmisc/Makefile.am,
libmisc/xgetXXbyYY.c, libmisc/xgetpwnam.c, libmisc/xgetpwuid.c,
libmisc/xgetgrnam.c, libmisc/xgetgrgid.c, libmisc/xgetspnam.c:
Added functions xgetpwnam(), xgetpwuid(), xgetgrnam(),
xgetgrgid(), and xgetspnam(). They allocate memory for the
returned structure and are more robust to successive calls. They
are implemented with the libc's getxxyyy_r() functions if
available.
* libmisc/limits.c, libmisc/entry.c, libmisc/chowntty.c,
libmisc/addgrps.c, libmisc/myname.c, libmisc/rlogin.c,
libmisc/pwdcheck.c, src/newgrp.c, src/login_nopam.c,
src/userdel.c, src/lastlog.c, src/grpck.c, src/gpasswd.c,
src/newusers.c, src/chpasswd.c, src/chfn.c, src/groupmems.c,
src/usermod.c, src/expiry.c, src/groupdel.c, src/chgpasswd.c,
src/su.c, src/useradd.c, src/groupmod.c, src/passwd.c, src/pwck.c,
src/groupadd.c, src/chage.c, src/login.c, src/suauth.c,
src/faillog.c, src/groups.c, src/chsh.c, src/id.c: Review all the
usage of one of the getpwnam(), getpwuid(), getgrnam(),
getgrgid(), and getspnam() functions. It was noticed on
http://bugs.debian.org/341230 that chfn and chsh use a passwd
structure after calling a pam function, which result in using
information from the passwd structure requested by pam, not the
original one. It is much easier to use the new xget... functions
to avoid these issues. I've checked which call to the original
get... functions could be left (reducing the scope of the
structure if possible), and I've left comments to ease future
reviews (e.g. /* local, no need for xgetpwnam */).
Note: the getpwent/getgrent calls should probably be checked also.
* src/groupdel.c, src/expiry.c: Fix typos in comments.
* src/groupmod.c: Re-indent.
* libmisc/Makefile.am, lib/groupmem.c, lib/groupio.c, lib/pwmem.c,
lib/pwio.c, lib/shadowmem.c, lib/shadowio.c: Move the __<xx>_dup
functions (used by the xget... functions) from the <xx>io.c files
to the new <xx>mem.c files. This avoid linking some utils against
the SELinux library.
2007-11-18 23:15:26 +00:00
|
|
|
* If pwd isn't NULL, it stopped because the gid's matched.
|
2007-10-07 11:44:02 +00:00
|
|
|
*/
|
|
|
|
|
2008-08-06 15:54:49 +00:00
|
|
|
if (pwd == (struct passwd *) 0) {
|
2007-10-07 11:44:02 +00:00
|
|
|
return;
|
2008-08-06 15:54:49 +00:00
|
|
|
}
|
2007-10-07 11:44:02 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Can't remove the group.
|
|
|
|
*/
|
2008-12-22 21:52:43 +00:00
|
|
|
fprintf (stderr,
|
|
|
|
_("%s: cannot remove the primary group of user '%s'\n"),
|
|
|
|
Prog, pwd->pw_name);
|
|
|
|
exit (E_GROUP_BUSY);
|
2007-10-07 11:44:02 +00:00
|
|
|
}
|
|
|
|
|
2011-11-06 18:37:57 +00:00
|
|
|
/*
|
|
|
|
* process_flags - parse the command line options
|
|
|
|
*
|
|
|
|
* It will not return if an error is encountered.
|
|
|
|
*/
|
|
|
|
static void process_flags (int argc, char **argv)
|
|
|
|
{
|
|
|
|
/*
|
|
|
|
* Parse the command line options.
|
|
|
|
*/
|
|
|
|
int c;
|
|
|
|
static struct option long_options[] = {
|
* src/chage.c, src/chgpasswd.c, src/chpasswd.c, src/chsh.c,
src/faillog.c, src/gpasswd.c, src/groupadd.c, src/groupdel.c,
src/groupmems.c, src/groupmod.c, src/grpconv.c, src/grpunconv.c,
src/lastlog.c, src/newusers.c, src/passwd.c, src/pwconv.c,
src/pwunconv.c, src/su.c, src/useradd.c, src/userdel.c,
src/usermod.c, src/vipw.c: Align and sort options.
2011-11-06 18:39:59 +00:00
|
|
|
{"help", no_argument, NULL, 'h'},
|
2020-10-17 09:18:30 -07:00
|
|
|
{"force", no_argument, NULL, 'f'},
|
2011-11-06 18:37:57 +00:00
|
|
|
{"root", required_argument, NULL, 'R'},
|
2016-05-15 15:49:39 +02:00
|
|
|
{"prefix", required_argument, NULL, 'P'},
|
2011-11-06 18:37:57 +00:00
|
|
|
{NULL, 0, NULL, '\0'}
|
|
|
|
};
|
|
|
|
|
2016-05-15 15:49:39 +02:00
|
|
|
while ((c = getopt_long (argc, argv, "hfR:P:",
|
2011-11-06 18:37:57 +00:00
|
|
|
long_options, NULL)) != -1) {
|
|
|
|
switch (c) {
|
|
|
|
case 'h':
|
|
|
|
usage (E_SUCCESS);
|
|
|
|
/*@notreached@*/break;
|
|
|
|
case 'R': /* no-op, handled in process_root_flag () */
|
|
|
|
break;
|
2016-05-15 15:49:39 +02:00
|
|
|
case 'P': /* no-op, handled in process_prefix_flag () */
|
|
|
|
break;
|
2015-06-12 17:32:50 -05:00
|
|
|
case 'f':
|
|
|
|
check_group_busy = false;
|
|
|
|
break;
|
2011-11-06 18:37:57 +00:00
|
|
|
default:
|
|
|
|
usage (E_USAGE);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (optind != argc - 1) {
|
|
|
|
usage (E_USAGE);
|
|
|
|
}
|
|
|
|
group_name = argv[optind];
|
|
|
|
}
|
|
|
|
|
2007-10-07 11:44:02 +00:00
|
|
|
/*
|
|
|
|
* main - groupdel command
|
|
|
|
*
|
|
|
|
* The syntax of the groupdel command is
|
2021-09-13 17:23:17 +01:00
|
|
|
*
|
2007-10-07 11:44:02 +00:00
|
|
|
* groupdel group
|
|
|
|
*
|
|
|
|
* The named group will be deleted.
|
|
|
|
*/
|
|
|
|
|
2007-10-07 11:45:23 +00:00
|
|
|
int main (int argc, char **argv)
|
2007-10-07 11:44:02 +00:00
|
|
|
{
|
* configure.in: Added option --enable-account-tools-setuid to
enable/disable the usage of PAM to authenticate the callers of
account management tools: chage, chgpasswd, chpasswd, groupadd,
groupdel, groupmod, useradd, userdel, usermod.
* src/Makefile.am: Do not link the above tools with libpam if
account-tools-setuid is disabled.
* src/userdel.c, src/newusers.c, src/chpasswd.c, src/usermod.c,
src/groupdel.c, src/chgpasswd.c, src/useradd.c, src/groupmod.c,
src/groupadd.c, src/chage.c: Implement ACCT_TOOLS_SETUID
(--enable-account-tools-setuid).
* etc/pam.d/Makefile.am: Install the pam service file for the
above tools only when needed.
* src/useradd.c, src/userdel.c, src/usermod.c: It is no more
needed to initialize retval to PAM_SUCCESS.
2008-09-06 21:35:37 +00:00
|
|
|
#ifdef ACCT_TOOLS_SETUID
|
2007-10-07 11:44:38 +00:00
|
|
|
#ifdef USE_PAM
|
|
|
|
pam_handle_t *pamh = NULL;
|
|
|
|
int retval;
|
* configure.in: Added option --enable-account-tools-setuid to
enable/disable the usage of PAM to authenticate the callers of
account management tools: chage, chgpasswd, chpasswd, groupadd,
groupdel, groupmod, useradd, userdel, usermod.
* src/Makefile.am: Do not link the above tools with libpam if
account-tools-setuid is disabled.
* src/userdel.c, src/newusers.c, src/chpasswd.c, src/usermod.c,
src/groupdel.c, src/chgpasswd.c, src/useradd.c, src/groupmod.c,
src/groupadd.c, src/chage.c: Implement ACCT_TOOLS_SETUID
(--enable-account-tools-setuid).
* etc/pam.d/Makefile.am: Install the pam service file for the
above tools only when needed.
* src/useradd.c, src/userdel.c, src/usermod.c: It is no more
needed to initialize retval to PAM_SUCCESS.
2008-09-06 21:35:37 +00:00
|
|
|
#endif /* USE_PAM */
|
|
|
|
#endif /* ACCT_TOOLS_SETUID */
|
2007-10-07 11:44:02 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Get my name so that I can use it to report errors.
|
|
|
|
*/
|
2007-10-07 11:45:23 +00:00
|
|
|
Prog = Basename (argv[0]);
|
2021-11-28 17:37:53 -06:00
|
|
|
log_set_progname(Prog);
|
|
|
|
log_set_logfd(stderr);
|
2007-10-07 11:44:02 +00:00
|
|
|
|
2008-06-09 20:54:04 +00:00
|
|
|
(void) setlocale (LC_ALL, "");
|
|
|
|
(void) bindtextdomain (PACKAGE, LOCALEDIR);
|
|
|
|
(void) textdomain (PACKAGE);
|
2007-10-07 11:44:02 +00:00
|
|
|
|
2011-11-06 18:37:57 +00:00
|
|
|
process_root_flag ("-R", argc, argv);
|
2016-05-15 15:49:39 +02:00
|
|
|
prefix = process_prefix_flag ("-P", argc, argv);
|
2007-10-07 11:45:40 +00:00
|
|
|
|
2007-10-07 11:46:52 +00:00
|
|
|
OPENLOG ("groupdel");
|
2011-11-06 18:37:57 +00:00
|
|
|
#ifdef WITH_AUDIT
|
|
|
|
audit_help_open ();
|
|
|
|
#endif
|
|
|
|
|
|
|
|
if (atexit (do_cleanups) != 0) {
|
|
|
|
fprintf (stderr,
|
|
|
|
_("%s: Cannot setup cleanup service.\n"),
|
|
|
|
Prog);
|
|
|
|
exit (1);
|
|
|
|
}
|
|
|
|
|
|
|
|
process_flags (argc, argv);
|
2007-10-07 11:46:52 +00:00
|
|
|
|
* configure.in: Added option --enable-account-tools-setuid to
enable/disable the usage of PAM to authenticate the callers of
account management tools: chage, chgpasswd, chpasswd, groupadd,
groupdel, groupmod, useradd, userdel, usermod.
* src/Makefile.am: Do not link the above tools with libpam if
account-tools-setuid is disabled.
* src/userdel.c, src/newusers.c, src/chpasswd.c, src/usermod.c,
src/groupdel.c, src/chgpasswd.c, src/useradd.c, src/groupmod.c,
src/groupadd.c, src/chage.c: Implement ACCT_TOOLS_SETUID
(--enable-account-tools-setuid).
* etc/pam.d/Makefile.am: Install the pam service file for the
above tools only when needed.
* src/useradd.c, src/userdel.c, src/usermod.c: It is no more
needed to initialize retval to PAM_SUCCESS.
2008-09-06 21:35:37 +00:00
|
|
|
#ifdef ACCT_TOOLS_SETUID
|
2007-10-07 11:44:38 +00:00
|
|
|
#ifdef USE_PAM
|
* lib/prototypes.h, configure.in, libmisc/Makefile.am,
libmisc/xgetXXbyYY.c, libmisc/xgetpwnam.c, libmisc/xgetpwuid.c,
libmisc/xgetgrnam.c, libmisc/xgetgrgid.c, libmisc/xgetspnam.c:
Added functions xgetpwnam(), xgetpwuid(), xgetgrnam(),
xgetgrgid(), and xgetspnam(). They allocate memory for the
returned structure and are more robust to successive calls. They
are implemented with the libc's getxxyyy_r() functions if
available.
* libmisc/limits.c, libmisc/entry.c, libmisc/chowntty.c,
libmisc/addgrps.c, libmisc/myname.c, libmisc/rlogin.c,
libmisc/pwdcheck.c, src/newgrp.c, src/login_nopam.c,
src/userdel.c, src/lastlog.c, src/grpck.c, src/gpasswd.c,
src/newusers.c, src/chpasswd.c, src/chfn.c, src/groupmems.c,
src/usermod.c, src/expiry.c, src/groupdel.c, src/chgpasswd.c,
src/su.c, src/useradd.c, src/groupmod.c, src/passwd.c, src/pwck.c,
src/groupadd.c, src/chage.c, src/login.c, src/suauth.c,
src/faillog.c, src/groups.c, src/chsh.c, src/id.c: Review all the
usage of one of the getpwnam(), getpwuid(), getgrnam(),
getgrgid(), and getspnam() functions. It was noticed on
http://bugs.debian.org/341230 that chfn and chsh use a passwd
structure after calling a pam function, which result in using
information from the passwd structure requested by pam, not the
original one. It is much easier to use the new xget... functions
to avoid these issues. I've checked which call to the original
get... functions could be left (reducing the scope of the
structure if possible), and I've left comments to ease future
reviews (e.g. /* local, no need for xgetpwnam */).
Note: the getpwent/getgrent calls should probably be checked also.
* src/groupdel.c, src/expiry.c: Fix typos in comments.
* src/groupmod.c: Re-indent.
* libmisc/Makefile.am, lib/groupmem.c, lib/groupio.c, lib/pwmem.c,
lib/pwio.c, lib/shadowmem.c, lib/shadowio.c: Move the __<xx>_dup
functions (used by the xget... functions) from the <xx>io.c files
to the new <xx>mem.c files. This avoid linking some utils against
the SELinux library.
2007-11-18 23:15:26 +00:00
|
|
|
{
|
|
|
|
struct passwd *pampw;
|
|
|
|
pampw = getpwuid (getuid ()); /* local, no need for xgetpwuid */
|
|
|
|
if (pampw == NULL) {
|
Additional PAM cleanup:
* src/userdel.c, src/newusers.c, src/chpasswd.c, src/chfn.c,
src/groupmems.c, src/usermod.c, src/groupdel.c, src/chgpasswd.c,
src/useradd.c, src/groupmod.c, src/groupadd.c, src/chage.c,
src/chsh.c: If the username cannot be determined, report it as
such (not a PAM authentication failure).
2008-09-06 23:46:44 +00:00
|
|
|
fprintf (stderr,
|
|
|
|
_("%s: Cannot determine your user name.\n"),
|
|
|
|
Prog);
|
|
|
|
exit (1);
|
* lib/prototypes.h, configure.in, libmisc/Makefile.am,
libmisc/xgetXXbyYY.c, libmisc/xgetpwnam.c, libmisc/xgetpwuid.c,
libmisc/xgetgrnam.c, libmisc/xgetgrgid.c, libmisc/xgetspnam.c:
Added functions xgetpwnam(), xgetpwuid(), xgetgrnam(),
xgetgrgid(), and xgetspnam(). They allocate memory for the
returned structure and are more robust to successive calls. They
are implemented with the libc's getxxyyy_r() functions if
available.
* libmisc/limits.c, libmisc/entry.c, libmisc/chowntty.c,
libmisc/addgrps.c, libmisc/myname.c, libmisc/rlogin.c,
libmisc/pwdcheck.c, src/newgrp.c, src/login_nopam.c,
src/userdel.c, src/lastlog.c, src/grpck.c, src/gpasswd.c,
src/newusers.c, src/chpasswd.c, src/chfn.c, src/groupmems.c,
src/usermod.c, src/expiry.c, src/groupdel.c, src/chgpasswd.c,
src/su.c, src/useradd.c, src/groupmod.c, src/passwd.c, src/pwck.c,
src/groupadd.c, src/chage.c, src/login.c, src/suauth.c,
src/faillog.c, src/groups.c, src/chsh.c, src/id.c: Review all the
usage of one of the getpwnam(), getpwuid(), getgrnam(),
getgrgid(), and getspnam() functions. It was noticed on
http://bugs.debian.org/341230 that chfn and chsh use a passwd
structure after calling a pam function, which result in using
information from the passwd structure requested by pam, not the
original one. It is much easier to use the new xget... functions
to avoid these issues. I've checked which call to the original
get... functions could be left (reducing the scope of the
structure if possible), and I've left comments to ease future
reviews (e.g. /* local, no need for xgetpwnam */).
Note: the getpwent/getgrent calls should probably be checked also.
* src/groupdel.c, src/expiry.c: Fix typos in comments.
* src/groupmod.c: Re-indent.
* libmisc/Makefile.am, lib/groupmem.c, lib/groupio.c, lib/pwmem.c,
lib/pwio.c, lib/shadowmem.c, lib/shadowio.c: Move the __<xx>_dup
functions (used by the xget... functions) from the <xx>io.c files
to the new <xx>mem.c files. This avoid linking some utils against
the SELinux library.
2007-11-18 23:15:26 +00:00
|
|
|
}
|
Additional PAM cleanup:
* src/userdel.c, src/newusers.c, src/chpasswd.c, src/chfn.c,
src/groupmems.c, src/usermod.c, src/groupdel.c, src/chgpasswd.c,
src/useradd.c, src/groupmod.c, src/groupadd.c, src/chage.c,
src/chsh.c: If the username cannot be determined, report it as
such (not a PAM authentication failure).
2008-09-06 23:46:44 +00:00
|
|
|
|
|
|
|
retval = pam_start ("groupdel", pampw->pw_name, &conv, &pamh);
|
2007-10-07 11:44:38 +00:00
|
|
|
}
|
|
|
|
|
2008-06-09 20:54:04 +00:00
|
|
|
if (PAM_SUCCESS == retval) {
|
2007-10-07 11:45:23 +00:00
|
|
|
retval = pam_authenticate (pamh, 0);
|
2007-10-07 11:44:38 +00:00
|
|
|
}
|
|
|
|
|
2008-06-09 20:54:04 +00:00
|
|
|
if (PAM_SUCCESS == retval) {
|
2007-10-07 11:45:23 +00:00
|
|
|
retval = pam_acct_mgmt (pamh, 0);
|
2007-10-07 11:44:38 +00:00
|
|
|
}
|
|
|
|
|
* src/userdel.c, src/newusers.c, src/chpasswd.c, src/chfn.c,
src/groupmems.c, src/usermod.c, src/groupdel.c, src/chgpasswd.c,
src/useradd.c, src/groupmod.c, src/groupadd.c, src/chage.c,
src/chsh.c: Simplify the PAM error handling. Do not keep the pamh
handle, but terminate the PAM transaction as soon as possible if
there are no PAM session opened.
2008-09-06 13:28:02 +00:00
|
|
|
if (PAM_SUCCESS != retval) {
|
* src/chage.c, src/chfn.c, src/chgpasswd.c, src/chpasswd.c,
src/chsh.c, src/groupadd.c, src/groupdel.c, src/groupmems.c,
src/groupmod.c, src/newusers.c, src/useradd.c, src/userdel.c,
src/usermod.c: Provide the PAM error
message instead of our own, and log error to syslog.
* src/groupmems.c: Exit with exit rather than fail_exit in usage().
* src/newusers.c: Check the number of arguments.
* src/newusers.c: Do not create the home directory when it is not
changed.
* src/useradd.c: Set the group password to "!" rather "x" if there
are no gshadow file.
2011-11-13 16:24:57 +00:00
|
|
|
fprintf (stderr, _("%s: PAM: %s\n"),
|
|
|
|
Prog, pam_strerror (pamh, retval));
|
|
|
|
SYSLOG((LOG_ERR, "%s", pam_strerror (pamh, retval)));
|
|
|
|
if (NULL != pamh) {
|
|
|
|
(void) pam_end (pamh, retval);
|
|
|
|
}
|
2007-10-07 11:44:38 +00:00
|
|
|
exit (1);
|
|
|
|
}
|
* src/chage.c, src/chfn.c, src/chgpasswd.c, src/chpasswd.c,
src/chsh.c, src/groupadd.c, src/groupdel.c, src/groupmems.c,
src/groupmod.c, src/newusers.c, src/useradd.c, src/userdel.c,
src/usermod.c: Provide the PAM error
message instead of our own, and log error to syslog.
* src/groupmems.c: Exit with exit rather than fail_exit in usage().
* src/newusers.c: Check the number of arguments.
* src/newusers.c: Do not create the home directory when it is not
changed.
* src/useradd.c: Set the group password to "!" rather "x" if there
are no gshadow file.
2011-11-13 16:24:57 +00:00
|
|
|
(void) pam_end (pamh, retval);
|
2007-10-07 11:45:23 +00:00
|
|
|
#endif /* USE_PAM */
|
* configure.in: Added option --enable-account-tools-setuid to
enable/disable the usage of PAM to authenticate the callers of
account management tools: chage, chgpasswd, chpasswd, groupadd,
groupdel, groupmod, useradd, userdel, usermod.
* src/Makefile.am: Do not link the above tools with libpam if
account-tools-setuid is disabled.
* src/userdel.c, src/newusers.c, src/chpasswd.c, src/usermod.c,
src/groupdel.c, src/chgpasswd.c, src/useradd.c, src/groupmod.c,
src/groupadd.c, src/chage.c: Implement ACCT_TOOLS_SETUID
(--enable-account-tools-setuid).
* etc/pam.d/Makefile.am: Install the pam service file for the
above tools only when needed.
* src/useradd.c, src/userdel.c, src/usermod.c: It is no more
needed to initialize retval to PAM_SUCCESS.
2008-09-06 21:35:37 +00:00
|
|
|
#endif /* ACCT_TOOLS_SETUID */
|
2007-10-07 11:44:38 +00:00
|
|
|
|
2007-10-07 11:44:02 +00:00
|
|
|
#ifdef SHADOWGRP
|
2007-10-07 11:45:23 +00:00
|
|
|
is_shadow_grp = sgr_file_present ();
|
2007-10-07 11:44:02 +00:00
|
|
|
#endif
|
|
|
|
|
* lib/prototypes.h, configure.in, libmisc/Makefile.am,
libmisc/xgetXXbyYY.c, libmisc/xgetpwnam.c, libmisc/xgetpwuid.c,
libmisc/xgetgrnam.c, libmisc/xgetgrgid.c, libmisc/xgetspnam.c:
Added functions xgetpwnam(), xgetpwuid(), xgetgrnam(),
xgetgrgid(), and xgetspnam(). They allocate memory for the
returned structure and are more robust to successive calls. They
are implemented with the libc's getxxyyy_r() functions if
available.
* libmisc/limits.c, libmisc/entry.c, libmisc/chowntty.c,
libmisc/addgrps.c, libmisc/myname.c, libmisc/rlogin.c,
libmisc/pwdcheck.c, src/newgrp.c, src/login_nopam.c,
src/userdel.c, src/lastlog.c, src/grpck.c, src/gpasswd.c,
src/newusers.c, src/chpasswd.c, src/chfn.c, src/groupmems.c,
src/usermod.c, src/expiry.c, src/groupdel.c, src/chgpasswd.c,
src/su.c, src/useradd.c, src/groupmod.c, src/passwd.c, src/pwck.c,
src/groupadd.c, src/chage.c, src/login.c, src/suauth.c,
src/faillog.c, src/groups.c, src/chsh.c, src/id.c: Review all the
usage of one of the getpwnam(), getpwuid(), getgrnam(),
getgrgid(), and getspnam() functions. It was noticed on
http://bugs.debian.org/341230 that chfn and chsh use a passwd
structure after calling a pam function, which result in using
information from the passwd structure requested by pam, not the
original one. It is much easier to use the new xget... functions
to avoid these issues. I've checked which call to the original
get... functions could be left (reducing the scope of the
structure if possible), and I've left comments to ease future
reviews (e.g. /* local, no need for xgetpwnam */).
Note: the getpwent/getgrent calls should probably be checked also.
* src/groupdel.c, src/expiry.c: Fix typos in comments.
* src/groupmod.c: Re-indent.
* libmisc/Makefile.am, lib/groupmem.c, lib/groupio.c, lib/pwmem.c,
lib/pwio.c, lib/shadowmem.c, lib/shadowio.c: Move the __<xx>_dup
functions (used by the xget... functions) from the <xx>io.c files
to the new <xx>mem.c files. This avoid linking some utils against
the SELinux library.
2007-11-18 23:15:26 +00:00
|
|
|
{
|
|
|
|
struct group *grp;
|
|
|
|
/*
|
|
|
|
* Start with a quick check to see if the group exists.
|
|
|
|
*/
|
2016-05-15 15:49:39 +02:00
|
|
|
grp = prefix_getgrnam (group_name); /* local, no need for xgetgrnam */
|
2008-06-09 20:54:04 +00:00
|
|
|
if (NULL == grp) {
|
2008-12-22 21:52:43 +00:00
|
|
|
fprintf (stderr,
|
|
|
|
_("%s: group '%s' does not exist\n"),
|
|
|
|
Prog, group_name);
|
* lib/prototypes.h, configure.in, libmisc/Makefile.am,
libmisc/xgetXXbyYY.c, libmisc/xgetpwnam.c, libmisc/xgetpwuid.c,
libmisc/xgetgrnam.c, libmisc/xgetgrgid.c, libmisc/xgetspnam.c:
Added functions xgetpwnam(), xgetpwuid(), xgetgrnam(),
xgetgrgid(), and xgetspnam(). They allocate memory for the
returned structure and are more robust to successive calls. They
are implemented with the libc's getxxyyy_r() functions if
available.
* libmisc/limits.c, libmisc/entry.c, libmisc/chowntty.c,
libmisc/addgrps.c, libmisc/myname.c, libmisc/rlogin.c,
libmisc/pwdcheck.c, src/newgrp.c, src/login_nopam.c,
src/userdel.c, src/lastlog.c, src/grpck.c, src/gpasswd.c,
src/newusers.c, src/chpasswd.c, src/chfn.c, src/groupmems.c,
src/usermod.c, src/expiry.c, src/groupdel.c, src/chgpasswd.c,
src/su.c, src/useradd.c, src/groupmod.c, src/passwd.c, src/pwck.c,
src/groupadd.c, src/chage.c, src/login.c, src/suauth.c,
src/faillog.c, src/groups.c, src/chsh.c, src/id.c: Review all the
usage of one of the getpwnam(), getpwuid(), getgrnam(),
getgrgid(), and getspnam() functions. It was noticed on
http://bugs.debian.org/341230 that chfn and chsh use a passwd
structure after calling a pam function, which result in using
information from the passwd structure requested by pam, not the
original one. It is much easier to use the new xget... functions
to avoid these issues. I've checked which call to the original
get... functions could be left (reducing the scope of the
structure if possible), and I've left comments to ease future
reviews (e.g. /* local, no need for xgetpwnam */).
Note: the getpwent/getgrent calls should probably be checked also.
* src/groupdel.c, src/expiry.c: Fix typos in comments.
* src/groupmod.c: Re-indent.
* libmisc/Makefile.am, lib/groupmem.c, lib/groupio.c, lib/pwmem.c,
lib/pwio.c, lib/shadowmem.c, lib/shadowio.c: Move the __<xx>_dup
functions (used by the xget... functions) from the <xx>io.c files
to the new <xx>mem.c files. This avoid linking some utils against
the SELinux library.
2007-11-18 23:15:26 +00:00
|
|
|
exit (E_NOTFOUND);
|
|
|
|
}
|
2007-10-07 11:47:01 +00:00
|
|
|
|
2008-12-22 21:52:43 +00:00
|
|
|
group_id = grp->gr_gid;
|
* lib/prototypes.h, configure.in, libmisc/Makefile.am,
libmisc/xgetXXbyYY.c, libmisc/xgetpwnam.c, libmisc/xgetpwuid.c,
libmisc/xgetgrnam.c, libmisc/xgetgrgid.c, libmisc/xgetspnam.c:
Added functions xgetpwnam(), xgetpwuid(), xgetgrnam(),
xgetgrgid(), and xgetspnam(). They allocate memory for the
returned structure and are more robust to successive calls. They
are implemented with the libc's getxxyyy_r() functions if
available.
* libmisc/limits.c, libmisc/entry.c, libmisc/chowntty.c,
libmisc/addgrps.c, libmisc/myname.c, libmisc/rlogin.c,
libmisc/pwdcheck.c, src/newgrp.c, src/login_nopam.c,
src/userdel.c, src/lastlog.c, src/grpck.c, src/gpasswd.c,
src/newusers.c, src/chpasswd.c, src/chfn.c, src/groupmems.c,
src/usermod.c, src/expiry.c, src/groupdel.c, src/chgpasswd.c,
src/su.c, src/useradd.c, src/groupmod.c, src/passwd.c, src/pwck.c,
src/groupadd.c, src/chage.c, src/login.c, src/suauth.c,
src/faillog.c, src/groups.c, src/chsh.c, src/id.c: Review all the
usage of one of the getpwnam(), getpwuid(), getgrnam(),
getgrgid(), and getspnam() functions. It was noticed on
http://bugs.debian.org/341230 that chfn and chsh use a passwd
structure after calling a pam function, which result in using
information from the passwd structure requested by pam, not the
original one. It is much easier to use the new xget... functions
to avoid these issues. I've checked which call to the original
get... functions could be left (reducing the scope of the
structure if possible), and I've left comments to ease future
reviews (e.g. /* local, no need for xgetpwnam */).
Note: the getpwent/getgrent calls should probably be checked also.
* src/groupdel.c, src/expiry.c: Fix typos in comments.
* src/groupmod.c: Re-indent.
* libmisc/Makefile.am, lib/groupmem.c, lib/groupio.c, lib/pwmem.c,
lib/pwio.c, lib/shadowmem.c, lib/shadowio.c: Move the __<xx>_dup
functions (used by the xget... functions) from the <xx>io.c files
to the new <xx>mem.c files. This avoid linking some utils against
the SELinux library.
2007-11-18 23:15:26 +00:00
|
|
|
}
|
2007-10-07 11:47:01 +00:00
|
|
|
|
2007-10-07 11:46:07 +00:00
|
|
|
#ifdef USE_NIS
|
2007-10-07 11:44:02 +00:00
|
|
|
/*
|
|
|
|
* Make sure this isn't a NIS group
|
|
|
|
*/
|
|
|
|
if (__isgrNIS ()) {
|
2007-10-07 11:45:23 +00:00
|
|
|
char *nis_domain;
|
|
|
|
char *nis_master;
|
2007-10-07 11:44:02 +00:00
|
|
|
|
2008-12-22 22:07:12 +00:00
|
|
|
fprintf (stderr,
|
|
|
|
_("%s: group '%s' is a NIS group\n"),
|
|
|
|
Prog, group_name);
|
2007-10-07 11:44:02 +00:00
|
|
|
|
2007-10-07 11:45:23 +00:00
|
|
|
if (!yp_get_default_domain (&nis_domain) &&
|
|
|
|
!yp_master (nis_domain, "group.byname", &nis_master)) {
|
2008-12-22 22:07:12 +00:00
|
|
|
fprintf (stderr,
|
|
|
|
_("%s: %s is the NIS master\n"),
|
|
|
|
Prog, nis_master);
|
2007-10-07 11:44:02 +00:00
|
|
|
}
|
2007-10-07 11:45:23 +00:00
|
|
|
exit (E_NOTFOUND);
|
2007-10-07 11:44:02 +00:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/*
|
2008-08-06 15:54:49 +00:00
|
|
|
* Make sure this isn't the primary group of anyone.
|
2007-10-07 11:44:02 +00:00
|
|
|
*/
|
2015-06-12 17:32:50 -05:00
|
|
|
if (check_group_busy) {
|
|
|
|
group_busy (group_id);
|
|
|
|
}
|
2007-10-07 11:44:02 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Do the hard stuff - open the files, delete the group entries,
|
|
|
|
* then close and update the files.
|
|
|
|
*/
|
|
|
|
open_files ();
|
|
|
|
|
|
|
|
grp_update ();
|
2008-03-08 21:13:54 +00:00
|
|
|
|
|
|
|
close_files ();
|
|
|
|
|
|
|
|
nscd_flush_cache ("group");
|
Flush sssd caches in addition to nscd caches
Some distributions, notably Fedora, have the following order of nsswitch
modules by default:
passwd: sss files
group: sss files
The advantage of serving local users through SSSD is that the nss_sss
module has a fast mmapped-cache that speeds up NSS lookups compared to
accessing the disk an opening the files on each NSS request.
Traditionally, this has been done with the help of nscd, but using nscd
in parallel with sssd is cumbersome, as both SSSD and nscd use their own
independent caching, so using nscd in setups where sssd is also serving
users from some remote domain (LDAP, AD, ...) can result in a bit of
unpredictability.
More details about why Fedora chose to use sss before files can be found
on e.g.:
https://fedoraproject.org//wiki/Changes/SSSDCacheForLocalUsers
or:
https://docs.pagure.org/SSSD.sssd/design_pages/files_provider.html
Now, even though sssd watches the passwd and group files with the help
of inotify, there can still be a small window where someone requests a
user or a group, finds that it doesn't exist, adds the entry and checks
again. Without some support in shadow-utils that would explicitly drop
the sssd caches, the inotify watch can fire a little late, so a
combination of commands like this:
getent passwd user || useradd user; getent passwd user
can result in the second getent passwd not finding the newly added user
as the racy behaviour might still return the cached negative hit from
the first getent passwd.
This patch more or less copies the already existing support that
shadow-utils had for dropping nscd caches, except using the "sss_cache"
tool that sssd ships.
2018-09-12 14:22:11 +02:00
|
|
|
sssd_flush_cache (SSSD_DB_GROUP);
|
2007-10-07 14:36:51 +00:00
|
|
|
|
2008-03-08 21:13:54 +00:00
|
|
|
return E_SUCCESS;
|
2007-10-07 11:44:02 +00:00
|
|
|
}
|
2008-03-08 21:13:54 +00:00
|
|
|
|