* 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.
This commit is contained in:
parent
b0fe7d3a0b
commit
7fc596fb8a
34
ChangeLog
34
ChangeLog
@ -1,3 +1,37 @@
|
|||||||
|
2008-08-06 Nicolas François <nicolas.francois@centraliens.net>
|
||||||
|
|
||||||
|
* 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-02 Nicolas François <nicolas.francois@centraliens.net>
|
2008-08-02 Nicolas François <nicolas.francois@centraliens.net>
|
||||||
|
|
||||||
* src/groupadd.c: Harmonize error & syslog messages.
|
* src/groupadd.c: Harmonize error & syslog messages.
|
||||||
|
@ -126,11 +126,16 @@ static struct commonio_db group_db = {
|
|||||||
false /* readonly */
|
false /* readonly */
|
||||||
};
|
};
|
||||||
|
|
||||||
int gr_name (const char *filename)
|
int gr_setdbname (const char *filename)
|
||||||
{
|
{
|
||||||
return commonio_setname (&group_db, filename);
|
return commonio_setname (&group_db, filename);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const char *gr_dbname (void)
|
||||||
|
{
|
||||||
|
return group_db.filename;
|
||||||
|
}
|
||||||
|
|
||||||
int gr_lock (void)
|
int gr_lock (void)
|
||||||
{
|
{
|
||||||
return commonio_lock (&group_db);
|
return commonio_lock (&group_db);
|
||||||
|
@ -38,16 +38,17 @@
|
|||||||
#include <grp.h>
|
#include <grp.h>
|
||||||
|
|
||||||
extern int gr_close (void);
|
extern int gr_close (void);
|
||||||
extern const struct group *gr_locate (const char *);
|
extern const struct group *gr_locate (const char *name);
|
||||||
extern const struct group *gr_locate_gid (gid_t gid);
|
extern const struct group *gr_locate_gid (gid_t gid);
|
||||||
extern int gr_lock (void);
|
extern int gr_lock (void);
|
||||||
extern int gr_name (const char *);
|
extern int gr_setdbname (const char *filename);
|
||||||
|
extern const char *gr_dbname (void);
|
||||||
extern const struct group *gr_next (void);
|
extern const struct group *gr_next (void);
|
||||||
extern int gr_open (int);
|
extern int gr_open (int mode);
|
||||||
extern int gr_remove (const char *);
|
extern int gr_remove (const char *name);
|
||||||
extern int gr_rewind (void);
|
extern int gr_rewind (void);
|
||||||
extern int gr_unlock (void);
|
extern int gr_unlock (void);
|
||||||
extern int gr_update (const struct group *);
|
extern int gr_update (const struct group *gr);
|
||||||
extern int gr_sort (void);
|
extern int gr_sort (void);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
@ -108,11 +108,16 @@ static struct commonio_db passwd_db = {
|
|||||||
false /* readonly */
|
false /* readonly */
|
||||||
};
|
};
|
||||||
|
|
||||||
int pw_name (const char *filename)
|
int pw_setdbname (const char *filename)
|
||||||
{
|
{
|
||||||
return commonio_setname (&passwd_db, filename);
|
return commonio_setname (&passwd_db, filename);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const char *pw_dbname (void)
|
||||||
|
{
|
||||||
|
return passwd_db.filename;
|
||||||
|
}
|
||||||
|
|
||||||
int pw_lock (void)
|
int pw_lock (void)
|
||||||
{
|
{
|
||||||
return commonio_lock (&passwd_db);
|
return commonio_lock (&passwd_db);
|
||||||
|
11
lib/pwio.h
11
lib/pwio.h
@ -37,16 +37,17 @@
|
|||||||
|
|
||||||
#include <pwd.h>
|
#include <pwd.h>
|
||||||
extern int pw_close (void);
|
extern int pw_close (void);
|
||||||
extern const struct passwd *pw_locate (const char *);
|
extern const struct passwd *pw_locate (const char *name);
|
||||||
extern const struct passwd *pw_locate_uid (uid_t uid);
|
extern const struct passwd *pw_locate_uid (uid_t uid);
|
||||||
extern int pw_lock (void);
|
extern int pw_lock (void);
|
||||||
extern int pw_name (const char *);
|
extern int pw_setdbname (const char *filename);
|
||||||
|
extern const char *pw_dbname (void);
|
||||||
extern const struct passwd *pw_next (void);
|
extern const struct passwd *pw_next (void);
|
||||||
extern int pw_open (int);
|
extern int pw_open (int mode);
|
||||||
extern int pw_remove (const char *);
|
extern int pw_remove (const char *name);
|
||||||
extern int pw_rewind (void);
|
extern int pw_rewind (void);
|
||||||
extern int pw_unlock (void);
|
extern int pw_unlock (void);
|
||||||
extern int pw_update (const struct passwd *);
|
extern int pw_update (const struct passwd *pw);
|
||||||
extern int pw_sort (void);
|
extern int pw_sort (void);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
@ -161,11 +161,16 @@ static struct commonio_db gshadow_db = {
|
|||||||
false /* readonly */
|
false /* readonly */
|
||||||
};
|
};
|
||||||
|
|
||||||
int sgr_name (const char *filename)
|
int sgr_setdbname (const char *filename)
|
||||||
{
|
{
|
||||||
return commonio_setname (&gshadow_db, filename);
|
return commonio_setname (&gshadow_db, filename);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const char *sgr_dbname (void)
|
||||||
|
{
|
||||||
|
return gshadow_db.filename;
|
||||||
|
}
|
||||||
|
|
||||||
bool sgr_file_present (void)
|
bool sgr_file_present (void)
|
||||||
{
|
{
|
||||||
return commonio_present (&gshadow_db);
|
return commonio_present (&gshadow_db);
|
||||||
|
@ -37,15 +37,16 @@
|
|||||||
|
|
||||||
extern int sgr_close (void);
|
extern int sgr_close (void);
|
||||||
extern bool sgr_file_present (void);
|
extern bool sgr_file_present (void);
|
||||||
extern const struct sgrp *sgr_locate (const char *);
|
extern const struct sgrp *sgr_locate (const char *name);
|
||||||
extern int sgr_lock (void);
|
extern int sgr_lock (void);
|
||||||
extern int sgr_name (const char *);
|
extern int sgr_setdbname (const char *filename);
|
||||||
|
extern const char *sgr_dbname (void);
|
||||||
extern const struct sgrp *sgr_next (void);
|
extern const struct sgrp *sgr_next (void);
|
||||||
extern int sgr_open (int);
|
extern int sgr_open (int mode);
|
||||||
extern int sgr_remove (const char *);
|
extern int sgr_remove (const char *name);
|
||||||
extern int sgr_rewind (void);
|
extern int sgr_rewind (void);
|
||||||
extern int sgr_unlock (void);
|
extern int sgr_unlock (void);
|
||||||
extern int sgr_update (const struct sgrp *);
|
extern int sgr_update (const struct sgrp *sg);
|
||||||
extern int sgr_sort (void);
|
extern int sgr_sort (void);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
@ -105,11 +105,16 @@ static struct commonio_db shadow_db = {
|
|||||||
false /* readonly */
|
false /* readonly */
|
||||||
};
|
};
|
||||||
|
|
||||||
int spw_name (const char *filename)
|
int spw_setdbname (const char *filename)
|
||||||
{
|
{
|
||||||
return commonio_setname (&shadow_db, filename);
|
return commonio_setname (&shadow_db, filename);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const char *spw_dbname (void)
|
||||||
|
{
|
||||||
|
return shadow_db.filename;
|
||||||
|
}
|
||||||
|
|
||||||
bool spw_file_present (void)
|
bool spw_file_present (void)
|
||||||
{
|
{
|
||||||
return commonio_present (&shadow_db);
|
return commonio_present (&shadow_db);
|
||||||
|
@ -38,15 +38,16 @@
|
|||||||
|
|
||||||
extern int spw_close (void);
|
extern int spw_close (void);
|
||||||
extern bool spw_file_present (void);
|
extern bool spw_file_present (void);
|
||||||
extern const struct spwd *spw_locate (const char *);
|
extern const struct spwd *spw_locate (const char *name);
|
||||||
extern int spw_lock (void);
|
extern int spw_lock (void);
|
||||||
extern int spw_name (const char *);
|
extern int spw_setdbname (const char *filename);
|
||||||
|
extern const char *spw_dbname (void);
|
||||||
extern const struct spwd *spw_next (void);
|
extern const struct spwd *spw_next (void);
|
||||||
extern int spw_open (int);
|
extern int spw_open (int mode);
|
||||||
extern int spw_remove (const char *);
|
extern int spw_remove (const char *name);
|
||||||
extern int spw_rewind (void);
|
extern int spw_rewind (void);
|
||||||
extern int spw_unlock (void);
|
extern int spw_unlock (void);
|
||||||
extern int spw_update (const struct spwd *);
|
extern int spw_update (const struct spwd *sp);
|
||||||
extern int spw_sort (void);
|
extern int spw_sort (void);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
36
src/chage.c
36
src/chage.c
@ -555,16 +555,16 @@ static void open_files (bool readonly)
|
|||||||
*/
|
*/
|
||||||
if (!readonly && (pw_lock () == 0)) {
|
if (!readonly && (pw_lock () == 0)) {
|
||||||
fprintf (stderr,
|
fprintf (stderr,
|
||||||
_("%s: can't lock password file\n"), Prog);
|
_("%s: cannot lock %s\n"), Prog, pw_dbname ());
|
||||||
SYSLOG ((LOG_ERR, "failed locking %s", PASSWD_FILE));
|
SYSLOG ((LOG_ERR, "cannot lock %s", pw_dbname ()));
|
||||||
fail_exit (E_NOPERM);
|
fail_exit (E_NOPERM);
|
||||||
}
|
}
|
||||||
if (!readonly) {
|
if (!readonly) {
|
||||||
pw_locked = true;
|
pw_locked = true;
|
||||||
}
|
}
|
||||||
if (pw_open (readonly ? O_RDONLY: O_RDWR) == 0) {
|
if (pw_open (readonly ? O_RDONLY: O_RDWR) == 0) {
|
||||||
fprintf (stderr, _("%s: can't open password file\n"), Prog);
|
fprintf (stderr, _("%s: cannot open %s\n"), Prog, pw_dbname ());
|
||||||
SYSLOG ((LOG_ERR, "failed opening %s", PASSWD_FILE));
|
SYSLOG ((LOG_ERR, "cannot open %s", pw_dbname ()));
|
||||||
fail_exit (E_NOPERM);
|
fail_exit (E_NOPERM);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -576,8 +576,8 @@ static void open_files (bool readonly)
|
|||||||
*/
|
*/
|
||||||
if (!readonly && (spw_lock () == 0)) {
|
if (!readonly && (spw_lock () == 0)) {
|
||||||
fprintf (stderr,
|
fprintf (stderr,
|
||||||
_("%s: can't lock shadow password file\n"), Prog);
|
_("%s: cannot lock %s\n"), Prog, spw_dbname ());
|
||||||
SYSLOG ((LOG_ERR, "failed locking %s", SHADOW_FILE));
|
SYSLOG ((LOG_ERR, "cannot lock %s", spw_dbname ()));
|
||||||
fail_exit (E_NOPERM);
|
fail_exit (E_NOPERM);
|
||||||
}
|
}
|
||||||
if (!readonly) {
|
if (!readonly) {
|
||||||
@ -585,8 +585,8 @@ static void open_files (bool readonly)
|
|||||||
}
|
}
|
||||||
if (spw_open (readonly ? O_RDONLY: O_RDWR) == 0) {
|
if (spw_open (readonly ? O_RDONLY: O_RDWR) == 0) {
|
||||||
fprintf (stderr,
|
fprintf (stderr,
|
||||||
_("%s: can't open shadow password file\n"), Prog);
|
_("%s: cannot open %s\n"), Prog, spw_dbname ());
|
||||||
SYSLOG ((LOG_ERR, "failed opening %s", SHADOW_FILE));
|
SYSLOG ((LOG_ERR, "cannot open %s", spw_dbname ()));
|
||||||
fail_exit (E_NOPERM);
|
fail_exit (E_NOPERM);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -602,8 +602,8 @@ static void close_files (void)
|
|||||||
*/
|
*/
|
||||||
if (spw_close () == 0) {
|
if (spw_close () == 0) {
|
||||||
fprintf (stderr,
|
fprintf (stderr,
|
||||||
_("%s: can't rewrite shadow password file\n"), Prog);
|
_("%s: failure while writing changes to %s\n"), Prog, spw_dbname ());
|
||||||
SYSLOG ((LOG_ERR, "failed rewriting %s", SHADOW_FILE));
|
SYSLOG ((LOG_ERR, "failure while writing changes to %s", spw_dbname ()));
|
||||||
fail_exit (E_NOPERM);
|
fail_exit (E_NOPERM);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -612,8 +612,8 @@ static void close_files (void)
|
|||||||
* will be re-written.
|
* will be re-written.
|
||||||
*/
|
*/
|
||||||
if (pw_close () == 0) {
|
if (pw_close () == 0) {
|
||||||
fprintf (stderr, _("%s: can't rewrite password file\n"), Prog);
|
fprintf (stderr, _("%s: failure while writing changes to %s\n"), Prog, pw_dbname ());
|
||||||
SYSLOG ((LOG_ERR, "failed rewriting %s", PASSWD_FILE));
|
SYSLOG ((LOG_ERR, "failure while writing changes to %s", pw_dbname ()));
|
||||||
fail_exit (E_NOPERM);
|
fail_exit (E_NOPERM);
|
||||||
}
|
}
|
||||||
spw_unlock ();
|
spw_unlock ();
|
||||||
@ -647,8 +647,8 @@ static void update_age (const struct spwd *sp, const struct passwd *pw)
|
|||||||
pwent.pw_passwd = SHADOW_PASSWD_STRING; /* XXX warning: const */
|
pwent.pw_passwd = SHADOW_PASSWD_STRING; /* XXX warning: const */
|
||||||
if (pw_update (&pwent) == 0) {
|
if (pw_update (&pwent) == 0) {
|
||||||
fprintf (stderr,
|
fprintf (stderr,
|
||||||
_("%s: can't update password file\n"), Prog);
|
_("%s: cannot update %s\n"), Prog, pw_dbname ());
|
||||||
SYSLOG ((LOG_ERR, "failed updating %s", PASSWD_FILE));
|
SYSLOG ((LOG_ERR, "cannot update %s", pw_dbname ()));
|
||||||
fail_exit (E_NOPERM);
|
fail_exit (E_NOPERM);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
@ -671,8 +671,8 @@ static void update_age (const struct spwd *sp, const struct passwd *pw)
|
|||||||
|
|
||||||
if (spw_update (&spwent) == 0) {
|
if (spw_update (&spwent) == 0) {
|
||||||
fprintf (stderr,
|
fprintf (stderr,
|
||||||
_("%s: can't update shadow password file\n"), Prog);
|
_("%s: cannot update %s\n"), Prog, spw_dbname ());
|
||||||
SYSLOG ((LOG_ERR, "failed updating %s", SHADOW_FILE));
|
SYSLOG ((LOG_ERR, "cannot update %s", spw_dbname ()));
|
||||||
fail_exit (E_NOPERM);
|
fail_exit (E_NOPERM);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -808,8 +808,8 @@ int main (int argc, char **argv)
|
|||||||
|
|
||||||
pw = pw_locate (argv[optind]);
|
pw = pw_locate (argv[optind]);
|
||||||
if (NULL == pw) {
|
if (NULL == pw) {
|
||||||
fprintf (stderr, _("%s: unknown user %s\n"), Prog,
|
fprintf (stderr, _("%s: user '%s' does not exist in %s\n"),
|
||||||
argv[optind]);
|
Prog, argv[optind], pw_dbname ());
|
||||||
closelog ();
|
closelog ();
|
||||||
exit (E_NOPERM);
|
exit (E_NOPERM);
|
||||||
}
|
}
|
||||||
|
28
src/chfn.c
28
src/chfn.c
@ -417,16 +417,18 @@ static void update_gecos (const char *user, char *gecos)
|
|||||||
* password file. Get a lock on the file and open it.
|
* password file. Get a lock on the file and open it.
|
||||||
*/
|
*/
|
||||||
if (pw_lock () == 0) {
|
if (pw_lock () == 0) {
|
||||||
fputs (_("Cannot lock the password file; try again later.\n"),
|
fprintf (stderr,
|
||||||
stderr);
|
_("%s: cannot lock %s; try again later.\n"),
|
||||||
SYSLOG ((LOG_WARN, "can't lock /etc/passwd"));
|
Prog, pw_dbname ());
|
||||||
|
SYSLOG ((LOG_WARN, "cannot lock %s", pw_dbname ()));
|
||||||
closelog ();
|
closelog ();
|
||||||
exit (E_NOPERM);
|
exit (E_NOPERM);
|
||||||
}
|
}
|
||||||
if (pw_open (O_RDWR) == 0) {
|
if (pw_open (O_RDWR) == 0) {
|
||||||
fputs (_("Cannot open the password file.\n"), stderr);
|
fprintf (stderr,
|
||||||
|
_("%s: cannot open %s\n"), Prog, pw_dbname ());
|
||||||
pw_unlock ();
|
pw_unlock ();
|
||||||
SYSLOG ((LOG_ERR, "can't open /etc/passwd"));
|
SYSLOG ((LOG_ERR, "cannot open %s", pw_dbname ()));
|
||||||
closelog ();
|
closelog ();
|
||||||
exit (E_NOPERM);
|
exit (E_NOPERM);
|
||||||
}
|
}
|
||||||
@ -441,7 +443,8 @@ static void update_gecos (const char *user, char *gecos)
|
|||||||
if (NULL == pw) {
|
if (NULL == pw) {
|
||||||
pw_unlock ();
|
pw_unlock ();
|
||||||
fprintf (stderr,
|
fprintf (stderr,
|
||||||
_("%s: %s not found in /etc/passwd\n"), Prog, user);
|
_("%s: user '%s' does not exist in %s\n"),
|
||||||
|
Prog, user, pw_dbname ());
|
||||||
exit (E_NOPERM);
|
exit (E_NOPERM);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -468,15 +471,15 @@ static void update_gecos (const char *user, char *gecos)
|
|||||||
* Changes have all been made, so commit them and unlock the file.
|
* Changes have all been made, so commit them and unlock the file.
|
||||||
*/
|
*/
|
||||||
if (pw_close () == 0) {
|
if (pw_close () == 0) {
|
||||||
fputs (_("Cannot commit password file changes.\n"), stderr);
|
fprintf (stderr, _("%s: failure while writing changes to %s\n"), Prog, pw_dbname ());
|
||||||
pw_unlock ();
|
pw_unlock ();
|
||||||
SYSLOG ((LOG_ERR, "can't rewrite /etc/passwd"));
|
SYSLOG ((LOG_ERR, "failure while writing changes to %s", pw_dbname ()));
|
||||||
closelog ();
|
closelog ();
|
||||||
exit (E_NOPERM);
|
exit (E_NOPERM);
|
||||||
}
|
}
|
||||||
if (pw_unlock () == 0) {
|
if (pw_unlock () == 0) {
|
||||||
fputs (_("Cannot unlock the password file.\n"), stderr);
|
fprintf (stderr, _("%s: failed to unlock %s\n"), Prog, pw_dbname ());
|
||||||
SYSLOG ((LOG_ERR, "can't unlock /etc/passwd"));
|
SYSLOG ((LOG_ERR, "failed to unlock %s", pw_dbname ()));
|
||||||
closelog ();
|
closelog ();
|
||||||
exit (E_NOPERM);
|
exit (E_NOPERM);
|
||||||
}
|
}
|
||||||
@ -633,7 +636,7 @@ int main (int argc, char **argv)
|
|||||||
user = argv[optind];
|
user = argv[optind];
|
||||||
pw = xgetpwnam (user);
|
pw = xgetpwnam (user);
|
||||||
if (NULL == pw) {
|
if (NULL == pw) {
|
||||||
fprintf (stderr, _("%s: unknown user %s\n"), Prog,
|
fprintf (stderr, _("%s: user '%s' does not exist\n"), Prog,
|
||||||
user);
|
user);
|
||||||
exit (E_NOPERM);
|
exit (E_NOPERM);
|
||||||
}
|
}
|
||||||
@ -641,8 +644,7 @@ int main (int argc, char **argv)
|
|||||||
pw = get_my_pwent ();
|
pw = get_my_pwent ();
|
||||||
if (NULL == pw) {
|
if (NULL == pw) {
|
||||||
fprintf (stderr,
|
fprintf (stderr,
|
||||||
_
|
_("%s: Cannot determine your user name.\n"),
|
||||||
("%s: Cannot determine your user name.\n"),
|
|
||||||
Prog);
|
Prog);
|
||||||
exit (E_NOPERM);
|
exit (E_NOPERM);
|
||||||
}
|
}
|
||||||
|
@ -178,7 +178,7 @@ static void check_flags (void)
|
|||||||
{
|
{
|
||||||
if (sflg && !cflg) {
|
if (sflg && !cflg) {
|
||||||
fprintf (stderr,
|
fprintf (stderr,
|
||||||
_("%s: %s flag is ONLY allowed with the %s flag\n"),
|
_("%s: %s flag is only allowed with the %s flag\n"),
|
||||||
Prog, "-s", "-c");
|
Prog, "-s", "-c");
|
||||||
usage ();
|
usage ();
|
||||||
}
|
}
|
||||||
@ -264,11 +264,13 @@ static void open_files (void)
|
|||||||
* bring all of the entries into memory where they may be updated.
|
* bring all of the entries into memory where they may be updated.
|
||||||
*/
|
*/
|
||||||
if (gr_lock () == 0) {
|
if (gr_lock () == 0) {
|
||||||
fprintf (stderr, _("%s: can't lock group file\n"), Prog);
|
fprintf (stderr,
|
||||||
|
_("%s: cannot lock %s\n"), Prog, gr_dbname ());
|
||||||
exit (1);
|
exit (1);
|
||||||
}
|
}
|
||||||
if (gr_open (O_RDWR) == 0) {
|
if (gr_open (O_RDWR) == 0) {
|
||||||
fprintf (stderr, _("%s: can't open group file\n"), Prog);
|
fprintf (stderr,
|
||||||
|
_("%s: cannot open %s\n"), Prog, gr_dbname ());
|
||||||
gr_unlock ();
|
gr_unlock ();
|
||||||
exit (1);
|
exit (1);
|
||||||
}
|
}
|
||||||
@ -277,14 +279,14 @@ static void open_files (void)
|
|||||||
/* Do the same for the shadowed database, if it exist */
|
/* Do the same for the shadowed database, if it exist */
|
||||||
if (is_shadow_grp) {
|
if (is_shadow_grp) {
|
||||||
if (sgr_lock () == 0) {
|
if (sgr_lock () == 0) {
|
||||||
fprintf (stderr, _("%s: can't lock gshadow file\n"),
|
fprintf (stderr, _("%s: cannot lock %s\n"),
|
||||||
Prog);
|
Prog, sgr_dbname ());
|
||||||
gr_unlock ();
|
gr_unlock ();
|
||||||
exit (1);
|
exit (1);
|
||||||
}
|
}
|
||||||
if (sgr_open (O_RDWR) == 0) {
|
if (sgr_open (O_RDWR) == 0) {
|
||||||
fprintf (stderr, _("%s: can't open shadow file\n"),
|
fprintf (stderr, _("%s: cannot open %s\n"),
|
||||||
Prog);
|
Prog, sgr_dbname ());
|
||||||
gr_unlock ();
|
gr_unlock ();
|
||||||
sgr_unlock ();
|
sgr_unlock ();
|
||||||
exit (1);
|
exit (1);
|
||||||
@ -302,7 +304,8 @@ static void close_files (void)
|
|||||||
if (is_shadow_grp) {
|
if (is_shadow_grp) {
|
||||||
if (sgr_close () == 0) {
|
if (sgr_close () == 0) {
|
||||||
fprintf (stderr,
|
fprintf (stderr,
|
||||||
_("%s: error updating gshadow file\n"), Prog);
|
_("%s: failure while writing changes to %s\n"),
|
||||||
|
Prog, sgr_dbname ());
|
||||||
gr_unlock ();
|
gr_unlock ();
|
||||||
exit (1);
|
exit (1);
|
||||||
}
|
}
|
||||||
@ -311,7 +314,9 @@ static void close_files (void)
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
if (gr_close () == 0) {
|
if (gr_close () == 0) {
|
||||||
fprintf (stderr, _("%s: error updating group file\n"), Prog);
|
fprintf (stderr,
|
||||||
|
_("%s: failure while writing changes to %s\n"),
|
||||||
|
Prog, gr_dbname ());
|
||||||
exit (1);
|
exit (1);
|
||||||
}
|
}
|
||||||
gr_unlock ();
|
gr_unlock ();
|
||||||
@ -414,7 +419,7 @@ int main (int argc, char **argv)
|
|||||||
gr = gr_locate (name);
|
gr = gr_locate (name);
|
||||||
if (NULL == gr) {
|
if (NULL == gr) {
|
||||||
fprintf (stderr,
|
fprintf (stderr,
|
||||||
_("%s: line %d: unknown group %s\n"), Prog,
|
_("%s: line %d: group '%s' does not exist\n"), Prog,
|
||||||
line, name);
|
line, name);
|
||||||
errors++;
|
errors++;
|
||||||
continue;
|
continue;
|
||||||
|
@ -175,7 +175,7 @@ static void check_flags (void)
|
|||||||
{
|
{
|
||||||
if (sflg && !cflg) {
|
if (sflg && !cflg) {
|
||||||
fprintf (stderr,
|
fprintf (stderr,
|
||||||
_("%s: %s flag is ONLY allowed with the %s flag\n"),
|
_("%s: %s flag is only allowed with the %s flag\n"),
|
||||||
Prog, "-s", "-c");
|
Prog, "-s", "-c");
|
||||||
usage ();
|
usage ();
|
||||||
}
|
}
|
||||||
@ -261,11 +261,13 @@ static void open_files (void)
|
|||||||
* will bring all of the entries into memory where they may be updated.
|
* will bring all of the entries into memory where they may be updated.
|
||||||
*/
|
*/
|
||||||
if (pw_lock () == 0) {
|
if (pw_lock () == 0) {
|
||||||
fprintf (stderr, _("%s: can't lock password file\n"), Prog);
|
fprintf (stderr,
|
||||||
|
_("%s: cannot lock %s\n"), Prog, pw_dbname ());
|
||||||
exit (1);
|
exit (1);
|
||||||
}
|
}
|
||||||
if (pw_open (O_RDWR) == 0) {
|
if (pw_open (O_RDWR) == 0) {
|
||||||
fprintf (stderr, _("%s: can't open password file\n"), Prog);
|
fprintf (stderr,
|
||||||
|
_("%s: cannot open %s\n"), Prog, pw_dbname ());
|
||||||
pw_unlock ();
|
pw_unlock ();
|
||||||
exit (1);
|
exit (1);
|
||||||
}
|
}
|
||||||
@ -273,14 +275,16 @@ static void open_files (void)
|
|||||||
/* Do the same for the shadowed database, if it exist */
|
/* Do the same for the shadowed database, if it exist */
|
||||||
if (is_shadow_pwd) {
|
if (is_shadow_pwd) {
|
||||||
if (spw_lock () == 0) {
|
if (spw_lock () == 0) {
|
||||||
fprintf (stderr, _("%s: can't lock shadow file\n"),
|
fprintf (stderr,
|
||||||
Prog);
|
_("%s: cannot lock %s\n"),
|
||||||
|
Prog, spw_dbname ());
|
||||||
pw_unlock ();
|
pw_unlock ();
|
||||||
exit (1);
|
exit (1);
|
||||||
}
|
}
|
||||||
if (spw_open (O_RDWR) == 0) {
|
if (spw_open (O_RDWR) == 0) {
|
||||||
fprintf (stderr, _("%s: can't open shadow file\n"),
|
fprintf (stderr,
|
||||||
Prog);
|
_("%s: cannot open %s\n"),
|
||||||
|
Prog, spw_dbname ());
|
||||||
pw_unlock ();
|
pw_unlock ();
|
||||||
spw_unlock ();
|
spw_unlock ();
|
||||||
exit (1);
|
exit (1);
|
||||||
@ -296,7 +300,8 @@ static void close_files (void)
|
|||||||
if (is_shadow_pwd) {
|
if (is_shadow_pwd) {
|
||||||
if (spw_close () == 0) {
|
if (spw_close () == 0) {
|
||||||
fprintf (stderr,
|
fprintf (stderr,
|
||||||
_("%s: error updating shadow file\n"), Prog);
|
_("%s: failure while writing changes to %s\n"),
|
||||||
|
Prog, spw_dbname ());
|
||||||
pw_unlock ();
|
pw_unlock ();
|
||||||
exit (1);
|
exit (1);
|
||||||
}
|
}
|
||||||
@ -304,7 +309,9 @@ static void close_files (void)
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (pw_close () == 0) {
|
if (pw_close () == 0) {
|
||||||
fprintf (stderr, _("%s: error updating password file\n"), Prog);
|
fprintf (stderr,
|
||||||
|
_("%s: failure while writing changes to %s\n"),
|
||||||
|
Prog, pw_dbname ());
|
||||||
exit (1);
|
exit (1);
|
||||||
}
|
}
|
||||||
pw_unlock ();
|
pw_unlock ();
|
||||||
@ -407,7 +414,7 @@ int main (int argc, char **argv)
|
|||||||
pw = pw_locate (name);
|
pw = pw_locate (name);
|
||||||
if (NULL == pw) {
|
if (NULL == pw) {
|
||||||
fprintf (stderr,
|
fprintf (stderr,
|
||||||
_("%s: line %d: unknown user %s\n"), Prog,
|
_("%s: line %d: user '%s' does not exist\n"), Prog,
|
||||||
line, name);
|
line, name);
|
||||||
errors++;
|
errors++;
|
||||||
continue;
|
continue;
|
||||||
@ -445,8 +452,7 @@ int main (int argc, char **argv)
|
|||||||
|
|
||||||
if (0 == ok) {
|
if (0 == ok) {
|
||||||
fprintf (stderr,
|
fprintf (stderr,
|
||||||
_
|
_("%s: line %d: cannot update password entry\n"),
|
||||||
("%s: line %d: cannot update password entry\n"),
|
|
||||||
Prog, line);
|
Prog, line);
|
||||||
errors++;
|
errors++;
|
||||||
continue;
|
continue;
|
||||||
|
24
src/chsh.c
24
src/chsh.c
@ -352,16 +352,16 @@ static void update_shell (const char *user, char *newshell)
|
|||||||
* the password file. Get a lock on the file and open it.
|
* the password file. Get a lock on the file and open it.
|
||||||
*/
|
*/
|
||||||
if (pw_lock () == 0) {
|
if (pw_lock () == 0) {
|
||||||
SYSLOG ((LOG_WARN, "can't lock /etc/passwd"));
|
SYSLOG ((LOG_WARN, "cannot lock %s", pw_dbname ()));
|
||||||
closelog ();
|
closelog ();
|
||||||
fputs (_("Cannot lock the password file; try again later.\n"),
|
fprintf (stderr, _("%s: cannot lock %s; try again later.\n"),
|
||||||
stderr);
|
Prog, pw_dbname ());
|
||||||
exit (1);
|
exit (1);
|
||||||
}
|
}
|
||||||
if (pw_open (O_RDWR) == 0) {
|
if (pw_open (O_RDWR) == 0) {
|
||||||
SYSLOG ((LOG_ERR, "can't open /etc/passwd"));
|
SYSLOG ((LOG_ERR, "cannot open %s", pw_dbname ()));
|
||||||
closelog ();
|
closelog ();
|
||||||
fputs (_("Cannot open the password file.\n"), stderr);
|
fprintf (stderr, _("%s: cannot open %s\n"), Prog, pw_dbname ());
|
||||||
pw_unlock ();
|
pw_unlock ();
|
||||||
exit (1);
|
exit (1);
|
||||||
}
|
}
|
||||||
@ -376,7 +376,8 @@ static void update_shell (const char *user, char *newshell)
|
|||||||
if (NULL == pw) {
|
if (NULL == pw) {
|
||||||
pw_unlock ();
|
pw_unlock ();
|
||||||
fprintf (stderr,
|
fprintf (stderr,
|
||||||
_("%s: %s not found in /etc/passwd\n"), Prog, user);
|
_("%s: user '%s' does not exist in %s\n"),
|
||||||
|
Prog, user, pw_dbname ());
|
||||||
exit (1);
|
exit (1);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -403,16 +404,17 @@ static void update_shell (const char *user, char *newshell)
|
|||||||
* Changes have all been made, so commit them and unlock the file.
|
* Changes have all been made, so commit them and unlock the file.
|
||||||
*/
|
*/
|
||||||
if (pw_close () == 0) {
|
if (pw_close () == 0) {
|
||||||
SYSLOG ((LOG_ERR, "can't rewrite /etc/passwd"));
|
SYSLOG ((LOG_ERR, "failure while writing changes to %s", pw_dbname ()));
|
||||||
closelog ();
|
closelog ();
|
||||||
fputs (_("Cannot commit password file changes.\n"), stderr);
|
fprintf (stderr, _("%s: failure while writing changes to %s\n"), Prog, pw_dbname ());
|
||||||
pw_unlock ();
|
pw_unlock ();
|
||||||
exit (1);
|
exit (1);
|
||||||
}
|
}
|
||||||
if (pw_unlock () == 0) {
|
if (pw_unlock () == 0) {
|
||||||
SYSLOG ((LOG_ERR, "can't unlock /etc/passwd"));
|
SYSLOG ((LOG_ERR, "failed to unlock %s", pw_dbname ()));
|
||||||
closelog ();
|
closelog ();
|
||||||
fputs (_("Cannot unlock the password file.\n"), stderr);
|
fprintf (stderr,
|
||||||
|
_("%s: failed to unlock %s\n"), Prog, pw_dbname ());
|
||||||
exit (1);
|
exit (1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -459,7 +461,7 @@ int main (int argc, char **argv)
|
|||||||
pw = xgetpwnam (user);
|
pw = xgetpwnam (user);
|
||||||
if (NULL == pw) {
|
if (NULL == pw) {
|
||||||
fprintf (stderr,
|
fprintf (stderr,
|
||||||
_("%s: unknown user %s\n"), Prog, user);
|
_("%s: user '%s' does not exist\n"), Prog, user);
|
||||||
exit (1);
|
exit (1);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
@ -162,8 +162,8 @@ static void fail_exit (int status)
|
|||||||
{
|
{
|
||||||
if (group_locked) {
|
if (group_locked) {
|
||||||
if (gr_unlock () == 0) {
|
if (gr_unlock () == 0) {
|
||||||
fprintf (stderr, _("%s: cannot unlock the group file\n"), Prog);
|
fprintf (stderr, _("%s: failed to unlock %s\n"), Prog, gr_dbname ());
|
||||||
SYSLOG ((LOG_WARN, "cannot unlock the group file"));
|
SYSLOG ((LOG_WARN, "failed to unlock %s", gr_dbname ()));
|
||||||
#ifdef WITH_AUDIT
|
#ifdef WITH_AUDIT
|
||||||
audit_logger (AUDIT_USER_CHAUTHTOK, Prog,
|
audit_logger (AUDIT_USER_CHAUTHTOK, Prog,
|
||||||
"unlocking group file",
|
"unlocking group file",
|
||||||
@ -174,8 +174,8 @@ static void fail_exit (int status)
|
|||||||
#ifdef SHADOWGRP
|
#ifdef SHADOWGRP
|
||||||
if (gshadow_locked) {
|
if (gshadow_locked) {
|
||||||
if (sgr_unlock () == 0) {
|
if (sgr_unlock () == 0) {
|
||||||
fprintf (stderr, _("%s: cannot unlock the shadow group file\n"), Prog);
|
fprintf (stderr, _("%s: failed to unlock %s\n"), Prog, sgr_dbname ());
|
||||||
SYSLOG ((LOG_WARN, "cannot unlock the shadow group file"));
|
SYSLOG ((LOG_WARN, "failed to unlock %s", sgr_dbname ()));
|
||||||
#ifdef WITH_AUDIT
|
#ifdef WITH_AUDIT
|
||||||
audit_logger (AUDIT_USER_CHAUTHTOK, Prog,
|
audit_logger (AUDIT_USER_CHAUTHTOK, Prog,
|
||||||
"unlocking gshadow file",
|
"unlocking gshadow file",
|
||||||
@ -368,8 +368,8 @@ static void check_flags (int argc, int opt_index)
|
|||||||
static void open_files (void)
|
static void open_files (void)
|
||||||
{
|
{
|
||||||
if (gr_lock () == 0) {
|
if (gr_lock () == 0) {
|
||||||
fprintf (stderr, _("%s: cannot lock the group file\n"), Prog);
|
fprintf (stderr, _("%s: cannot lock %s\n"), Prog, gr_dbname ());
|
||||||
SYSLOG ((LOG_WARN, "cannot lock the group file"));
|
SYSLOG ((LOG_WARN, "cannot lock %s", gr_dbname ()));
|
||||||
#ifdef WITH_AUDIT
|
#ifdef WITH_AUDIT
|
||||||
audit_logger (AUDIT_USER_CHAUTHTOK, Prog,
|
audit_logger (AUDIT_USER_CHAUTHTOK, Prog,
|
||||||
"locking /etc/group",
|
"locking /etc/group",
|
||||||
@ -382,8 +382,8 @@ static void open_files (void)
|
|||||||
if (is_shadowgrp) {
|
if (is_shadowgrp) {
|
||||||
if (sgr_lock () == 0) {
|
if (sgr_lock () == 0) {
|
||||||
fprintf (stderr,
|
fprintf (stderr,
|
||||||
_("%s: cannot lock the shadow group file\n"), Prog);
|
_("%s: cannot lock %s\n"), Prog, sgr_dbname ());
|
||||||
SYSLOG ((LOG_WARN, "cannot lock the shadow group file"));
|
SYSLOG ((LOG_WARN, "cannot lock %s", sgr_dbname ()));
|
||||||
#ifdef WITH_AUDIT
|
#ifdef WITH_AUDIT
|
||||||
audit_logger (AUDIT_USER_CHAUTHTOK, Prog,
|
audit_logger (AUDIT_USER_CHAUTHTOK, Prog,
|
||||||
"locking /etc/gshadow",
|
"locking /etc/gshadow",
|
||||||
@ -395,8 +395,8 @@ static void open_files (void)
|
|||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
if (gr_open (O_RDWR) == 0) {
|
if (gr_open (O_RDWR) == 0) {
|
||||||
fprintf (stderr, _("%s: cannot open the group file\n"), Prog);
|
fprintf (stderr, _("%s: cannot open %s\n"), Prog, gr_dbname ());
|
||||||
SYSLOG ((LOG_WARN, "cannot open the group file"));
|
SYSLOG ((LOG_WARN, "cannot open %s", gr_dbname ()));
|
||||||
#ifdef WITH_AUDIT
|
#ifdef WITH_AUDIT
|
||||||
audit_logger (AUDIT_USER_CHAUTHTOK, Prog,
|
audit_logger (AUDIT_USER_CHAUTHTOK, Prog,
|
||||||
"opening /etc/group",
|
"opening /etc/group",
|
||||||
@ -406,8 +406,8 @@ static void open_files (void)
|
|||||||
}
|
}
|
||||||
#ifdef SHADOWGRP
|
#ifdef SHADOWGRP
|
||||||
if (is_shadowgrp && (sgr_open (O_RDWR) == 0)) {
|
if (is_shadowgrp && (sgr_open (O_RDWR) == 0)) {
|
||||||
fprintf (stderr, _("%s: cannot open the shadow group file\n"), Prog);
|
fprintf (stderr, _("%s: cannot open %s\n"), Prog, sgr_dbname ());
|
||||||
SYSLOG ((LOG_WARN, "cannot open the shadow group file"));
|
SYSLOG ((LOG_WARN, "cannot open %s", sgr_dbname ()));
|
||||||
#ifdef WITH_AUDIT
|
#ifdef WITH_AUDIT
|
||||||
audit_logger (AUDIT_USER_CHAUTHTOK, Prog,
|
audit_logger (AUDIT_USER_CHAUTHTOK, Prog,
|
||||||
"opening /etc/gshadow",
|
"opening /etc/gshadow",
|
||||||
@ -428,8 +428,8 @@ static void open_files (void)
|
|||||||
static void close_files (void)
|
static void close_files (void)
|
||||||
{
|
{
|
||||||
if (gr_close () == 0) {
|
if (gr_close () == 0) {
|
||||||
fprintf (stderr, _("%s: cannot rewrite the group file\n"), Prog);
|
fprintf (stderr, _("%s: failure while writing changes to %s\n"), Prog, gr_dbname ());
|
||||||
SYSLOG ((LOG_WARN, "cannot rewrite the group file"));
|
SYSLOG ((LOG_WARN, "failure while writing changes to %s", gr_dbname ()));
|
||||||
#ifdef WITH_AUDIT
|
#ifdef WITH_AUDIT
|
||||||
audit_logger (AUDIT_USER_CHAUTHTOK, Prog,
|
audit_logger (AUDIT_USER_CHAUTHTOK, Prog,
|
||||||
"rewriting /etc/group",
|
"rewriting /etc/group",
|
||||||
@ -440,8 +440,8 @@ static void close_files (void)
|
|||||||
#ifdef SHADOWGRP
|
#ifdef SHADOWGRP
|
||||||
if (is_shadowgrp) {
|
if (is_shadowgrp) {
|
||||||
if (sgr_close () == 0) {
|
if (sgr_close () == 0) {
|
||||||
fprintf (stderr, _("%s: cannot rewrite the shadow group file\n"), Prog);
|
fprintf (stderr, _("%s: failure while writing changes to %s\n"), Prog, sgr_dbname ());
|
||||||
SYSLOG ((LOG_WARN, "cannot rewrite the shadow group file"));
|
SYSLOG ((LOG_WARN, "failure while writing changes to %s", sgr_dbname ()));
|
||||||
#ifdef WITH_AUDIT
|
#ifdef WITH_AUDIT
|
||||||
audit_logger (AUDIT_USER_CHAUTHTOK, Prog,
|
audit_logger (AUDIT_USER_CHAUTHTOK, Prog,
|
||||||
"rewriting /etc/gshadow",
|
"rewriting /etc/gshadow",
|
||||||
@ -450,8 +450,8 @@ static void close_files (void)
|
|||||||
fail_exit (1);
|
fail_exit (1);
|
||||||
}
|
}
|
||||||
if (sgr_unlock () == 0) {
|
if (sgr_unlock () == 0) {
|
||||||
fprintf (stderr, _("%s: cannot unlock the shadow group file\n"), Prog);
|
fprintf (stderr, _("%s: failed to unlock %s\n"), Prog, sgr_dbname ());
|
||||||
SYSLOG ((LOG_WARN, "cannot unlock the shadow group file"));
|
SYSLOG ((LOG_WARN, "failed to unlock %s", sgr_dbname ()));
|
||||||
#ifdef WITH_AUDIT
|
#ifdef WITH_AUDIT
|
||||||
audit_logger (AUDIT_USER_CHAUTHTOK, Prog,
|
audit_logger (AUDIT_USER_CHAUTHTOK, Prog,
|
||||||
"unlocking gshadow file",
|
"unlocking gshadow file",
|
||||||
@ -463,8 +463,8 @@ static void close_files (void)
|
|||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
if (gr_unlock () == 0) {
|
if (gr_unlock () == 0) {
|
||||||
fprintf (stderr, _("%s: cannot unlock the group file\n"), Prog);
|
fprintf (stderr, _("%s: failed to unlock %s\n"), Prog, gr_dbname ());
|
||||||
SYSLOG ((LOG_WARN, "cannot unlock the group file"));
|
SYSLOG ((LOG_WARN, "failed to unlock %s", gr_dbname ()));
|
||||||
#ifdef WITH_AUDIT
|
#ifdef WITH_AUDIT
|
||||||
audit_logger (AUDIT_USER_CHAUTHTOK, Prog,
|
audit_logger (AUDIT_USER_CHAUTHTOK, Prog,
|
||||||
"unlocking group file",
|
"unlocking group file",
|
||||||
@ -564,8 +564,10 @@ static void update_group (struct group *gr)
|
|||||||
#endif
|
#endif
|
||||||
{
|
{
|
||||||
if (gr_update (gr) == 0) {
|
if (gr_update (gr) == 0) {
|
||||||
fprintf (stderr, _("%s: cannot update the entry of '%s' in the group file\n"), Prog, gr->gr_name);
|
fprintf (stderr,
|
||||||
SYSLOG ((LOG_WARN, "cannot update the entry of '%s' in the group file", gr->gr_name));
|
_("%s: cannot update entry '%s' in %s\n"),
|
||||||
|
Prog, gr->gr_name, gr_dbname ());
|
||||||
|
SYSLOG ((LOG_WARN, "cannot update entry '%s' in %s", gr->gr_name, gr_dbname ()));
|
||||||
#ifdef WITH_AUDIT
|
#ifdef WITH_AUDIT
|
||||||
audit_logger (AUDIT_USER_CHAUTHTOK, Prog,
|
audit_logger (AUDIT_USER_CHAUTHTOK, Prog,
|
||||||
"updating /etc/group",
|
"updating /etc/group",
|
||||||
@ -575,8 +577,8 @@ static void update_group (struct group *gr)
|
|||||||
}
|
}
|
||||||
#ifdef SHADOWGRP
|
#ifdef SHADOWGRP
|
||||||
if (is_shadowgrp && (sgr_update (sg) == 0)) {
|
if (is_shadowgrp && (sgr_update (sg) == 0)) {
|
||||||
fprintf (stderr, _("%s: cannot update the entry of '%s' in the shadow group file\n"), Prog, sg->sg_name);
|
fprintf (stderr, _("%s: cannot update entry '%s' in %s\n"), Prog, sg->sg_name, sgr_dbname ());
|
||||||
SYSLOG ((LOG_WARN, "cannot update the entry of '%s' in the shadow group file", sg->sg_name));
|
SYSLOG ((LOG_WARN, "cannot update entry '%s' in %s", sg->sg_name, sgr_dbname ()));
|
||||||
#ifdef WITH_AUDIT
|
#ifdef WITH_AUDIT
|
||||||
audit_logger (AUDIT_USER_CHAUTHTOK, Prog,
|
audit_logger (AUDIT_USER_CHAUTHTOK, Prog,
|
||||||
"updating /etc/gshadow",
|
"updating /etc/gshadow",
|
||||||
@ -605,8 +607,8 @@ static void get_group (struct group *gr)
|
|||||||
struct sgrp const*tmpsg = NULL;
|
struct sgrp const*tmpsg = NULL;
|
||||||
|
|
||||||
if (gr_open (O_RDONLY) == 0) {
|
if (gr_open (O_RDONLY) == 0) {
|
||||||
fprintf (stderr, _("%s: cannot open the group file\n"), Prog);
|
fprintf (stderr, _("%s: cannot open %s\n"), Prog, gr_dbname ());
|
||||||
SYSLOG ((LOG_WARN, "cannot open the group file"));
|
SYSLOG ((LOG_WARN, "cannot open %s", gr_dbname ()));
|
||||||
#ifdef WITH_AUDIT
|
#ifdef WITH_AUDIT
|
||||||
audit_logger (AUDIT_USER_CHAUTHTOK, Prog,
|
audit_logger (AUDIT_USER_CHAUTHTOK, Prog,
|
||||||
"opening /etc/group",
|
"opening /etc/group",
|
||||||
@ -617,7 +619,7 @@ static void get_group (struct group *gr)
|
|||||||
|
|
||||||
tmpgr = gr_locate (group);
|
tmpgr = gr_locate (group);
|
||||||
if (NULL == tmpgr) {
|
if (NULL == tmpgr) {
|
||||||
fprintf (stderr, _("%s: group '%s' does not exist in the group file\n"), Prog, group);
|
fprintf (stderr, _("%s: group '%s' does not exist in %s\n"), Prog, group, gr_dbname ());
|
||||||
#ifdef WITH_AUDIT
|
#ifdef WITH_AUDIT
|
||||||
audit_logger (AUDIT_USER_CHAUTHTOK, Prog,
|
audit_logger (AUDIT_USER_CHAUTHTOK, Prog,
|
||||||
"group lookup",
|
"group lookup",
|
||||||
@ -632,8 +634,8 @@ static void get_group (struct group *gr)
|
|||||||
gr->gr_mem = dup_list (tmpgr->gr_mem);
|
gr->gr_mem = dup_list (tmpgr->gr_mem);
|
||||||
|
|
||||||
if (gr_close () == 0) {
|
if (gr_close () == 0) {
|
||||||
fprintf (stderr, _("%s: cannot rewrite the group file\n"), Prog);
|
fprintf (stderr, _("%s: failure while writing changes to %s\n"), Prog, gr_dbname ());
|
||||||
SYSLOG ((LOG_WARN, "cannot rewrite the group file"));
|
SYSLOG ((LOG_WARN, "failure while writing changes to %s", gr_dbname ()));
|
||||||
#ifdef WITH_AUDIT
|
#ifdef WITH_AUDIT
|
||||||
audit_logger (AUDIT_USER_CHAUTHTOK, Prog,
|
audit_logger (AUDIT_USER_CHAUTHTOK, Prog,
|
||||||
"closing /etc/group",
|
"closing /etc/group",
|
||||||
@ -646,8 +648,8 @@ static void get_group (struct group *gr)
|
|||||||
if (is_shadowgrp) {
|
if (is_shadowgrp) {
|
||||||
if (sgr_open (O_RDONLY) == 0) {
|
if (sgr_open (O_RDONLY) == 0) {
|
||||||
fprintf (stderr,
|
fprintf (stderr,
|
||||||
_("%s: cannot open the shadow group file\n"), Prog);
|
_("%s: cannot open %s\n"), Prog, sgr_dbmane ());
|
||||||
SYSLOG ((LOG_WARN, "cannot open the shadow group file"));
|
SYSLOG ((LOG_WARN, "cannot open %s", sgr_dbname ()));
|
||||||
#ifdef WITH_AUDIT
|
#ifdef WITH_AUDIT
|
||||||
audit_logger (AUDIT_USER_CHAUTHTOK, Prog,
|
audit_logger (AUDIT_USER_CHAUTHTOK, Prog,
|
||||||
"opening /etc/gshadow",
|
"opening /etc/gshadow",
|
||||||
@ -684,8 +686,8 @@ static void get_group (struct group *gr)
|
|||||||
}
|
}
|
||||||
if (sgr_close () == 0) {
|
if (sgr_close () == 0) {
|
||||||
fprintf (stderr,
|
fprintf (stderr,
|
||||||
_("%s: cannot rewrite the shadow group file\n"), Prog);
|
_("%s: failure while writing changes to %s\n"), Prog, sgr_dbname ());
|
||||||
SYSLOG ((LOG_WARN, "cannot rewrite the shadow group file"));
|
SYSLOG ((LOG_WARN, "failure while writing changes to %s", sgr_dbname ()));
|
||||||
#ifdef WITH_AUDIT
|
#ifdef WITH_AUDIT
|
||||||
audit_logger (AUDIT_USER_CHAUTHTOK, Prog,
|
audit_logger (AUDIT_USER_CHAUTHTOK, Prog,
|
||||||
"closing /etc/gshadow",
|
"closing /etc/gshadow",
|
||||||
|
@ -198,8 +198,8 @@ static void grp_update (void)
|
|||||||
* Write out the new group file entry.
|
* Write out the new group file entry.
|
||||||
*/
|
*/
|
||||||
if (gr_update (&grp) == 0) {
|
if (gr_update (&grp) == 0) {
|
||||||
fprintf (stderr, _("%s: error adding new entry '%s' in the group file\n"), Prog, grp.gr_name);
|
fprintf (stderr, _("%s: error adding new entry '%s' in %s\n"), Prog, grp.gr_name, gr_dbname ());
|
||||||
SYSLOG ((LOG_WARN, "error adding new entry '%s' in the group file", grp.gr_name));
|
SYSLOG ((LOG_WARN, "error adding new entry '%s' in %s", grp.gr_name, gr_dbname ()));
|
||||||
fail_exit (E_GRP_UPDATE);
|
fail_exit (E_GRP_UPDATE);
|
||||||
}
|
}
|
||||||
#ifdef SHADOWGRP
|
#ifdef SHADOWGRP
|
||||||
@ -207,8 +207,8 @@ static void grp_update (void)
|
|||||||
* Write out the new shadow group entries as well.
|
* Write out the new shadow group entries as well.
|
||||||
*/
|
*/
|
||||||
if (is_shadow_grp && (sgr_update (&sgrp) == 0)) {
|
if (is_shadow_grp && (sgr_update (&sgrp) == 0)) {
|
||||||
fprintf (stderr, _("%s: error adding new entry '%s' in the shadow group file\n"), Prog, sgrp.sg_name);
|
fprintf (stderr, _("%s: error adding new entry '%s' in %s\n"), Prog, sgrp.sg_name, sgr_dbname ());
|
||||||
SYSLOG ((LOG_WARN, "error adding new entry '%s' in the shadow group file", sgrp.sg_name));
|
SYSLOG ((LOG_WARN, "error adding new entry '%s' in %s", sgrp.sg_name, sgr_dbname ()));
|
||||||
fail_exit (E_GRP_UPDATE);
|
fail_exit (E_GRP_UPDATE);
|
||||||
}
|
}
|
||||||
#endif /* SHADOWGRP */
|
#endif /* SHADOWGRP */
|
||||||
@ -252,13 +252,13 @@ static void check_new_name (void)
|
|||||||
static void close_files (void)
|
static void close_files (void)
|
||||||
{
|
{
|
||||||
if (gr_close () == 0) {
|
if (gr_close () == 0) {
|
||||||
fprintf (stderr, _("%s: cannot rewrite the group file\n"), Prog);
|
fprintf (stderr, _("%s: failure while writing changes to %s\n"), Prog, gr_dbname ());
|
||||||
SYSLOG ((LOG_WARN, "cannot rewrite the group file"));
|
SYSLOG ((LOG_WARN, "failure while writing changes to %s", gr_dbname ()));
|
||||||
fail_exit (E_GRP_UPDATE);
|
fail_exit (E_GRP_UPDATE);
|
||||||
}
|
}
|
||||||
if (gr_unlock () == 0) {
|
if (gr_unlock () == 0) {
|
||||||
fprintf (stderr, _("%s: cannot unlock the group file\n"), Prog);
|
fprintf (stderr, _("%s: failed to unlock %s\n"), Prog, gr_dbname ());
|
||||||
SYSLOG ((LOG_WARN, "cannot unlock the group file"));
|
SYSLOG ((LOG_WARN, "failed to unlock %s", gr_dbname ()));
|
||||||
#ifdef WITH_AUDIT
|
#ifdef WITH_AUDIT
|
||||||
audit_logger (AUDIT_USER_CHAUTHTOK, Prog,
|
audit_logger (AUDIT_USER_CHAUTHTOK, Prog,
|
||||||
"unlocking group file",
|
"unlocking group file",
|
||||||
@ -271,13 +271,13 @@ static void close_files (void)
|
|||||||
if (is_shadow_grp) {
|
if (is_shadow_grp) {
|
||||||
if (sgr_close () == 0) {
|
if (sgr_close () == 0) {
|
||||||
fprintf (stderr,
|
fprintf (stderr,
|
||||||
_("%s: cannot rewrite the shadow group file\n"), Prog);
|
_("%s: failure while writing changes to %s\n"), Prog, sgr_dbname ());
|
||||||
SYSLOG ((LOG_WARN, "cannot rewrite the shadow group file"));
|
SYSLOG ((LOG_WARN, "failure while writing changes to %s", sgr_dbname ()));
|
||||||
fail_exit (E_GRP_UPDATE);
|
fail_exit (E_GRP_UPDATE);
|
||||||
}
|
}
|
||||||
if (sgr_unlock () == 0) {
|
if (sgr_unlock () == 0) {
|
||||||
fprintf (stderr, _("%s: cannot unlock the shadow group file\n"), Prog);
|
fprintf (stderr, _("%s: failed to unlock %s\n"), Prog, sgr_dbname ());
|
||||||
SYSLOG ((LOG_WARN, "cannot unlock the shadow group file"));
|
SYSLOG ((LOG_WARN, "failed to unlock %s", sgr_dbname ()));
|
||||||
#ifdef WITH_AUDIT
|
#ifdef WITH_AUDIT
|
||||||
audit_logger (AUDIT_USER_CHAUTHTOK, Prog,
|
audit_logger (AUDIT_USER_CHAUTHTOK, Prog,
|
||||||
"unlocking gshadow file",
|
"unlocking gshadow file",
|
||||||
@ -298,8 +298,8 @@ static void close_files (void)
|
|||||||
static void open_files (void)
|
static void open_files (void)
|
||||||
{
|
{
|
||||||
if (gr_lock () == 0) {
|
if (gr_lock () == 0) {
|
||||||
fprintf (stderr, _("%s: cannot lock the group file\n"), Prog);
|
fprintf (stderr, _("%s: cannot lock %s\n"), Prog, gr_dbname ());
|
||||||
SYSLOG ((LOG_WARN, "cannot lock the group file"));
|
SYSLOG ((LOG_WARN, "cannot lock %s", gr_dbname ()));
|
||||||
#ifdef WITH_AUDIT
|
#ifdef WITH_AUDIT
|
||||||
audit_logger (AUDIT_USER_CHAUTHTOK, Prog,
|
audit_logger (AUDIT_USER_CHAUTHTOK, Prog,
|
||||||
"locking group file",
|
"locking group file",
|
||||||
@ -309,8 +309,8 @@ static void open_files (void)
|
|||||||
}
|
}
|
||||||
group_locked = true;
|
group_locked = true;
|
||||||
if (gr_open (O_RDWR) == 0) {
|
if (gr_open (O_RDWR) == 0) {
|
||||||
fprintf (stderr, _("%s: cannot open the group file\n"), Prog);
|
fprintf (stderr, _("%s: cannot open %s\n"), Prog, gr_dbname ());
|
||||||
SYSLOG ((LOG_WARN, "cannot open the group file"));
|
SYSLOG ((LOG_WARN, "cannot open %s", gr_dbname ()));
|
||||||
#ifdef WITH_AUDIT
|
#ifdef WITH_AUDIT
|
||||||
audit_logger (AUDIT_USER_CHAUTHTOK, Prog,
|
audit_logger (AUDIT_USER_CHAUTHTOK, Prog,
|
||||||
"opening group file",
|
"opening group file",
|
||||||
@ -322,8 +322,8 @@ static void open_files (void)
|
|||||||
if (is_shadow_grp) {
|
if (is_shadow_grp) {
|
||||||
if (sgr_lock () == 0) {
|
if (sgr_lock () == 0) {
|
||||||
fprintf (stderr,
|
fprintf (stderr,
|
||||||
_("%s: cannot lock the shadow group file\n"), Prog);
|
_("%s: cannot lock %s\n"), Prog, sgr_dbname ());
|
||||||
SYSLOG ((LOG_WARN, "cannot lock the shadow group file"));
|
SYSLOG ((LOG_WARN, "cannot lock %s", sgr_dbname ()));
|
||||||
#ifdef WITH_AUDIT
|
#ifdef WITH_AUDIT
|
||||||
audit_logger (AUDIT_USER_CHAUTHTOK, Prog,
|
audit_logger (AUDIT_USER_CHAUTHTOK, Prog,
|
||||||
"locking gshadow file",
|
"locking gshadow file",
|
||||||
@ -334,8 +334,8 @@ static void open_files (void)
|
|||||||
gshadow_locked = true;
|
gshadow_locked = true;
|
||||||
if (sgr_open (O_RDWR) == 0) {
|
if (sgr_open (O_RDWR) == 0) {
|
||||||
fprintf (stderr,
|
fprintf (stderr,
|
||||||
_("%s: cannot open the shadow group file\n"), Prog);
|
_("%s: cannot open %s\n"), Prog, sgr_dbname ());
|
||||||
SYSLOG ((LOG_WARN, "cannot open the shadow group file"));
|
SYSLOG ((LOG_WARN, "cannot open %s", sgr_dbname ()));
|
||||||
#ifdef WITH_AUDIT
|
#ifdef WITH_AUDIT
|
||||||
audit_logger (AUDIT_USER_CHAUTHTOK, Prog,
|
audit_logger (AUDIT_USER_CHAUTHTOK, Prog,
|
||||||
"opening gshadow file",
|
"opening gshadow file",
|
||||||
@ -354,8 +354,8 @@ static void fail_exit (int code)
|
|||||||
{
|
{
|
||||||
if (group_locked) {
|
if (group_locked) {
|
||||||
if (gr_unlock () == 0) {
|
if (gr_unlock () == 0) {
|
||||||
fprintf (stderr, _("%s: cannot unlock the group file\n"), Prog);
|
fprintf (stderr, _("%s: failed to unlock %s\n"), Prog, gr_dbname ());
|
||||||
SYSLOG ((LOG_WARN, "cannot unlock the group file"));
|
SYSLOG ((LOG_WARN, "failed to unlock %s", gr_dbname ()));
|
||||||
#ifdef WITH_AUDIT
|
#ifdef WITH_AUDIT
|
||||||
audit_logger (AUDIT_USER_CHAUTHTOK, Prog,
|
audit_logger (AUDIT_USER_CHAUTHTOK, Prog,
|
||||||
"unlocking group file",
|
"unlocking group file",
|
||||||
@ -367,8 +367,8 @@ static void fail_exit (int code)
|
|||||||
#ifdef SHADOWGRP
|
#ifdef SHADOWGRP
|
||||||
if (gshadow_locked) {
|
if (gshadow_locked) {
|
||||||
if (sgr_unlock () == 0) {
|
if (sgr_unlock () == 0) {
|
||||||
fprintf (stderr, _("%s: cannot unlock the shadow group file\n"), Prog);
|
fprintf (stderr, _("%s: failed to unlock %s\n"), Prog, sgr_dbname ());
|
||||||
SYSLOG ((LOG_WARN, "cannot unlock the shadow group file"));
|
SYSLOG ((LOG_WARN, "failed to unlock %s", sgr_dbname ()));
|
||||||
#ifdef WITH_AUDIT
|
#ifdef WITH_AUDIT
|
||||||
audit_logger (AUDIT_USER_CHAUTHTOK, Prog,
|
audit_logger (AUDIT_USER_CHAUTHTOK, Prog,
|
||||||
"unlocking gshadow file",
|
"unlocking gshadow file",
|
||||||
@ -469,8 +469,7 @@ static void process_flags (int argc, char **argv)
|
|||||||
cp = strchr (optarg, '=');
|
cp = strchr (optarg, '=');
|
||||||
if (NULL == cp) {
|
if (NULL == cp) {
|
||||||
fprintf (stderr,
|
fprintf (stderr,
|
||||||
_
|
_("%s: -K requires KEY=VALUE\n"),
|
||||||
("%s: -K requires KEY=VALUE\n"),
|
|
||||||
Prog);
|
Prog);
|
||||||
exit (E_BAD_ARG);
|
exit (E_BAD_ARG);
|
||||||
}
|
}
|
||||||
@ -547,8 +546,8 @@ static void check_flags (void)
|
|||||||
/* Turn off -g, we can use any GID */
|
/* Turn off -g, we can use any GID */
|
||||||
gflg = false;
|
gflg = false;
|
||||||
} else {
|
} else {
|
||||||
fprintf (stderr, _("%s: GID '%u' already exists\n"),
|
fprintf (stderr, _("%s: GID '%lu' already exists\n"),
|
||||||
Prog, (unsigned int) group_id);
|
Prog, (unsigned long int) group_id);
|
||||||
fail_exit (E_GID_IN_USE);
|
fail_exit (E_GID_IN_USE);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -96,8 +96,8 @@ static void fail_exit (int code)
|
|||||||
{
|
{
|
||||||
if (group_locked) {
|
if (group_locked) {
|
||||||
if (gr_unlock () == 0) {
|
if (gr_unlock () == 0) {
|
||||||
fprintf (stderr, _("%s: cannot unlock the group file\n"), Prog);
|
fprintf (stderr, _("%s: failed to unlock %s\n"), Prog, gr_dbname ());
|
||||||
SYSLOG ((LOG_WARN, "cannot unlock the group file"));
|
SYSLOG ((LOG_WARN, "failed to unlock %s", gr_dbname ()));
|
||||||
#ifdef WITH_AUDIT
|
#ifdef WITH_AUDIT
|
||||||
audit_logger (AUDIT_USER_CHAUTHTOK, Prog,
|
audit_logger (AUDIT_USER_CHAUTHTOK, Prog,
|
||||||
"unlocking group file",
|
"unlocking group file",
|
||||||
@ -109,8 +109,8 @@ static void fail_exit (int code)
|
|||||||
#ifdef SHADOWGRP
|
#ifdef SHADOWGRP
|
||||||
if (gshadow_locked) {
|
if (gshadow_locked) {
|
||||||
if (sgr_unlock () == 0) {
|
if (sgr_unlock () == 0) {
|
||||||
fprintf (stderr, _("%s: cannot unlock the shadow group file\n"), Prog);
|
fprintf (stderr, _("%s: failed to unlock %s\n"), Prog, sgr_dbname ());
|
||||||
SYSLOG ((LOG_WARN, "cannot unlock the shadow group file"));
|
SYSLOG ((LOG_WARN, "failed to unlock %s", sgr_dbname ()));
|
||||||
#ifdef WITH_AUDIT
|
#ifdef WITH_AUDIT
|
||||||
audit_logger (AUDIT_USER_CHAUTHTOK, Prog,
|
audit_logger (AUDIT_USER_CHAUTHTOK, Prog,
|
||||||
"unlocking gshadow file",
|
"unlocking gshadow file",
|
||||||
@ -138,7 +138,9 @@ static void fail_exit (int code)
|
|||||||
static void grp_update (void)
|
static void grp_update (void)
|
||||||
{
|
{
|
||||||
if (gr_remove (group_name) == 0) {
|
if (gr_remove (group_name) == 0) {
|
||||||
fprintf (stderr, _("%s: cannot remove group '%s' from the group database\n"), Prog, group_name);
|
fprintf (stderr,
|
||||||
|
_("%s: cannot remove entry '%s' from %s\n"),
|
||||||
|
Prog, group_name, gr_dbname ());
|
||||||
fail_exit (E_GRP_UPDATE);
|
fail_exit (E_GRP_UPDATE);
|
||||||
}
|
}
|
||||||
#ifdef SHADOWGRP
|
#ifdef SHADOWGRP
|
||||||
@ -148,8 +150,8 @@ static void grp_update (void)
|
|||||||
if (is_shadow_grp && (sgr_locate (group_name) != NULL)) {
|
if (is_shadow_grp && (sgr_locate (group_name) != NULL)) {
|
||||||
if (sgr_remove (group_name) == 0) {
|
if (sgr_remove (group_name) == 0) {
|
||||||
fprintf (stderr,
|
fprintf (stderr,
|
||||||
_("%s: cannot remove group '%s' from the shadow group database\n"),
|
_("%s: cannot remove entry '%s' from %s\n"),
|
||||||
Prog, group_name);
|
Prog, group_name, sgr_dbname ());
|
||||||
fail_exit (E_GRP_UPDATE);
|
fail_exit (E_GRP_UPDATE);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -173,13 +175,13 @@ static void close_files (void)
|
|||||||
SYSLOG ((LOG_INFO, "remove group '%s'\n", group_name));
|
SYSLOG ((LOG_INFO, "remove group '%s'\n", group_name));
|
||||||
|
|
||||||
if (gr_close () == 0) {
|
if (gr_close () == 0) {
|
||||||
fprintf (stderr, _("%s: cannot rewrite the group file\n"), Prog);
|
fprintf (stderr, _("%s: failure while writing changes to %s\n"), Prog, gr_dbname ());
|
||||||
SYSLOG ((LOG_WARN, "cannot rewrite the group file"));
|
SYSLOG ((LOG_WARN, "failure while writing changes to %s", gr_dbname ()));
|
||||||
fail_exit (E_GRP_UPDATE);
|
fail_exit (E_GRP_UPDATE);
|
||||||
}
|
}
|
||||||
if (gr_unlock () == 0) {
|
if (gr_unlock () == 0) {
|
||||||
fprintf (stderr, _("%s: cannot unlock the group file\n"), Prog);
|
fprintf (stderr, _("%s: failed to unlock %s\n"), Prog, gr_dbname ());
|
||||||
SYSLOG ((LOG_WARN, "cannot unlock the group file"));
|
SYSLOG ((LOG_WARN, "failed to unlock %s", gr_dbname ()));
|
||||||
#ifdef WITH_AUDIT
|
#ifdef WITH_AUDIT
|
||||||
audit_logger (AUDIT_USER_CHAUTHTOK, Prog,
|
audit_logger (AUDIT_USER_CHAUTHTOK, Prog,
|
||||||
"unlocking group file",
|
"unlocking group file",
|
||||||
@ -192,13 +194,13 @@ static void close_files (void)
|
|||||||
if (is_shadow_grp) {
|
if (is_shadow_grp) {
|
||||||
if (sgr_close () == 0)) {
|
if (sgr_close () == 0)) {
|
||||||
fprintf (stderr,
|
fprintf (stderr,
|
||||||
_("%s: cannot rewrite the shadow group file\n"), Prog);
|
_("%s: failure while writing changes to %s\n"), Prog, sgr_dbname ());
|
||||||
SYSLOG ((LOG_WARN, "cannot rewrite the shadow group file"));
|
SYSLOG ((LOG_WARN, "failure while writing changes to %s", sgr_dbname ()));
|
||||||
fail_exit (E_GRP_UPDATE);
|
fail_exit (E_GRP_UPDATE);
|
||||||
}
|
}
|
||||||
if (sgr_unlock () == 0) {
|
if (sgr_unlock () == 0) {
|
||||||
fprintf (stderr, _("%s: cannot unlock the shadow group file\n"), Prog);
|
fprintf (stderr, _("%s: failed to unlock %s\n"), Prog, sgr_dbname ());
|
||||||
SYSLOG ((LOG_WARN, "cannot unlock the shadow group file"));
|
SYSLOG ((LOG_WARN, "failed to unlock %s", sgr_dbname ()));
|
||||||
#ifdef WITH_AUDIT
|
#ifdef WITH_AUDIT
|
||||||
audit_logger (AUDIT_USER_CHAUTHTOK, Prog,
|
audit_logger (AUDIT_USER_CHAUTHTOK, Prog,
|
||||||
"unlocking gshadow file",
|
"unlocking gshadow file",
|
||||||
@ -219,29 +221,33 @@ static void close_files (void)
|
|||||||
static void open_files (void)
|
static void open_files (void)
|
||||||
{
|
{
|
||||||
if (gr_lock () == 0) {
|
if (gr_lock () == 0) {
|
||||||
fprintf (stderr, _("%s: cannot lock the group file\n"), Prog);
|
fprintf (stderr,
|
||||||
SYSLOG ((LOG_WARN, "cannot lock the group file"));
|
_("%s: cannot lock %s\n"), Prog, gr_dbname ());
|
||||||
|
SYSLOG ((LOG_WARN, "cannot lock %s",gr_dbname ()));
|
||||||
fail_exit (E_GRP_UPDATE);
|
fail_exit (E_GRP_UPDATE);
|
||||||
}
|
}
|
||||||
group_locked = true;
|
group_locked = true;
|
||||||
if (gr_open (O_RDWR) == 0) {
|
if (gr_open (O_RDWR) == 0) {
|
||||||
fprintf (stderr, _("%s: cannot open the group file\n"), Prog);
|
fprintf (stderr,
|
||||||
SYSLOG ((LOG_WARN, "cannot open the group file"));
|
_("%s: cannot open %s\n"), Prog, gr_dbname ());
|
||||||
|
SYSLOG ((LOG_WARN, "cannot open %s", gr_dbname ()));
|
||||||
fail_exit (E_GRP_UPDATE);
|
fail_exit (E_GRP_UPDATE);
|
||||||
}
|
}
|
||||||
#ifdef SHADOWGRP
|
#ifdef SHADOWGRP
|
||||||
if (is_shadow_grp) {
|
if (is_shadow_grp) {
|
||||||
if (sgr_lock () == 0)) {
|
if (sgr_lock () == 0)) {
|
||||||
fprintf (stderr,
|
fprintf (stderr,
|
||||||
_("%s: cannot lock the shadow group file\n"), Prog);
|
_("%s: cannot lock %s\n"),
|
||||||
SYSLOG ((LOG_WARN, "cannot lock the shadow group file"));
|
Prog, sgr_dbname ());
|
||||||
|
SYSLOG ((LOG_WARN, "cannot lock %s", sgr_dbname ()));
|
||||||
fail_exit (E_GRP_UPDATE);
|
fail_exit (E_GRP_UPDATE);
|
||||||
}
|
}
|
||||||
gshadow_locked = true;
|
gshadow_locked = true;
|
||||||
if (sgr_open (O_RDWR) == 0)) {
|
if (sgr_open (O_RDWR) == 0)) {
|
||||||
fprintf (stderr,
|
fprintf (stderr,
|
||||||
_("%s: cannot open the shadow group file\n"), Prog);
|
_("%s: cannot open %s\n"),
|
||||||
SYSLOG ((LOG_WARN, "cannot open the shadow group file"));
|
Prog, sgr_dbname ());
|
||||||
|
SYSLOG ((LOG_WARN, "cannot open %s", sgr_dbname ()));
|
||||||
fail_exit (E_GRP_UPDATE);
|
fail_exit (E_GRP_UPDATE);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -125,8 +125,8 @@ static void fail_exit (int status)
|
|||||||
{
|
{
|
||||||
if (group_locked) {
|
if (group_locked) {
|
||||||
if (gr_unlock () == 0) {
|
if (gr_unlock () == 0) {
|
||||||
fprintf (stderr, _("%s: cannot unlock the group file\n"), Prog);
|
fprintf (stderr, _("%s: failed to unlock %s\n"), Prog, gr_dbname ());
|
||||||
SYSLOG ((LOG_WARN, "cannot unlock the group file"));
|
SYSLOG ((LOG_WARN, "failed to unlock %s", gr_dbname ()));
|
||||||
#ifdef WITH_AUDIT
|
#ifdef WITH_AUDIT
|
||||||
audit_logger (AUDIT_USER_CHAUTHTOK, Prog,
|
audit_logger (AUDIT_USER_CHAUTHTOK, Prog,
|
||||||
"unlocking group file",
|
"unlocking group file",
|
||||||
@ -138,8 +138,8 @@ static void fail_exit (int status)
|
|||||||
#ifdef SHADOWGRP
|
#ifdef SHADOWGRP
|
||||||
if (gshadow_locked) {
|
if (gshadow_locked) {
|
||||||
if (sgr_unlock () == 0) {
|
if (sgr_unlock () == 0) {
|
||||||
fprintf (stderr, _("%s: cannot unlock the shadow group file\n"), Prog);
|
fprintf (stderr, _("%s: failed to unlock %s\n"), Prog, sgr_dbname ());
|
||||||
SYSLOG ((LOG_WARN, "cannot unlock the shadow group file"));
|
SYSLOG ((LOG_WARN, "failed to unlock %s", sgr_dbname ()));
|
||||||
#ifdef WITH_AUDIT
|
#ifdef WITH_AUDIT
|
||||||
audit_logger (AUDIT_USER_CHAUTHTOK, Prog,
|
audit_logger (AUDIT_USER_CHAUTHTOK, Prog,
|
||||||
"unlocking gshadow file",
|
"unlocking gshadow file",
|
||||||
@ -151,8 +151,8 @@ static void fail_exit (int status)
|
|||||||
#endif /* SHADOWGRP */
|
#endif /* SHADOWGRP */
|
||||||
if (passwd_locked) {
|
if (passwd_locked) {
|
||||||
if (pw_unlock () == 0) {
|
if (pw_unlock () == 0) {
|
||||||
fprintf (stderr, _("%s: cannot unlock the passwd file\n"), Prog);
|
fprintf (stderr, _("%s: failed to unlock %s\n"), Prog, pw_dbname ());
|
||||||
SYSLOG ((LOG_WARN, "cannot unlock the passwd file"));
|
SYSLOG ((LOG_WARN, "failed to unlock %s", pw_dbname ()));
|
||||||
#ifdef WITH_AUDIT
|
#ifdef WITH_AUDIT
|
||||||
audit_logger (AUDIT_USER_CHAUTHTOK, Prog,
|
audit_logger (AUDIT_USER_CHAUTHTOK, Prog,
|
||||||
"unlocking passwd file",
|
"unlocking passwd file",
|
||||||
@ -225,8 +225,8 @@ static void grp_update (void)
|
|||||||
ogrp = gr_locate (group_name);
|
ogrp = gr_locate (group_name);
|
||||||
if (!ogrp) {
|
if (!ogrp) {
|
||||||
fprintf (stderr,
|
fprintf (stderr,
|
||||||
_("%s: group '%s' does not exist in the group file\n"),
|
_("%s: group '%s' does not exist in %s\n"),
|
||||||
Prog, group_name);
|
Prog, group_name, gr_dbname ());
|
||||||
#ifdef WITH_AUDIT
|
#ifdef WITH_AUDIT
|
||||||
audit_logger (AUDIT_USER_CHAUTHTOK, Prog,
|
audit_logger (AUDIT_USER_CHAUTHTOK, Prog,
|
||||||
"modifying group",
|
"modifying group",
|
||||||
@ -257,7 +257,9 @@ static void grp_update (void)
|
|||||||
* Write out the new group file entry.
|
* Write out the new group file entry.
|
||||||
*/
|
*/
|
||||||
if (gr_update (&grp) == 0) {
|
if (gr_update (&grp) == 0) {
|
||||||
fprintf (stderr, _("%s: cannot add entry '%s' to the group database\n"), Prog, grp.gr_name);
|
fprintf (stderr,
|
||||||
|
_("%s: cannot add entry '%s' to %s\n"),
|
||||||
|
Prog, grp.gr_name, gr_dbname ());
|
||||||
#ifdef WITH_AUDIT
|
#ifdef WITH_AUDIT
|
||||||
audit_logger (AUDIT_USER_CHAUTHTOK, Prog,
|
audit_logger (AUDIT_USER_CHAUTHTOK, Prog,
|
||||||
"adding group",
|
"adding group",
|
||||||
@ -266,7 +268,9 @@ static void grp_update (void)
|
|||||||
fail_exit (E_GRP_UPDATE);
|
fail_exit (E_GRP_UPDATE);
|
||||||
}
|
}
|
||||||
if (nflg && (gr_remove (group_name) == 0)) {
|
if (nflg && (gr_remove (group_name) == 0)) {
|
||||||
fprintf (stderr, _("%s: cannot remove the entry of '%s' from the group database\n"), Prog, grp.gr_name);
|
fprintf (stderr,
|
||||||
|
_("%s: cannot remove entry '%s' from %s\n"),
|
||||||
|
Prog, grp.gr_name, gr_dbname ());
|
||||||
#ifdef WITH_AUDIT
|
#ifdef WITH_AUDIT
|
||||||
audit_logger (AUDIT_USER_CHAUTHTOK, Prog,
|
audit_logger (AUDIT_USER_CHAUTHTOK, Prog,
|
||||||
"deleting group",
|
"deleting group",
|
||||||
@ -281,14 +285,15 @@ static void grp_update (void)
|
|||||||
* "out" if there wasn't. Can't just return because there might be
|
* "out" if there wasn't. Can't just return because there might be
|
||||||
* some syslogging to do.
|
* some syslogging to do.
|
||||||
*/
|
*/
|
||||||
if (NULL == osgrp)
|
if (NULL == osgrp) {
|
||||||
goto out;
|
goto out;
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Write out the new shadow group entries as well.
|
* Write out the new shadow group entries as well.
|
||||||
*/
|
*/
|
||||||
if (is_shadow_grp && (sgr_update (&sgrp) == 0)) {
|
if (is_shadow_grp && (sgr_update (&sgrp) == 0)) {
|
||||||
fprintf (stderr, _("%s: cannot add entry '%s' to the shadow group database\n"), Prog, sgrp.sg_name);
|
fprintf (stderr, _("%s: cannot add entry '%s' to %s\n"), Prog, sgrp.sg_name, sgr_dbname ());
|
||||||
#ifdef WITH_AUDIT
|
#ifdef WITH_AUDIT
|
||||||
audit_logger (AUDIT_USER_CHAUTHTOK, Prog,
|
audit_logger (AUDIT_USER_CHAUTHTOK, Prog,
|
||||||
"adding group",
|
"adding group",
|
||||||
@ -297,7 +302,9 @@ static void grp_update (void)
|
|||||||
fail_exit (E_GRP_UPDATE);
|
fail_exit (E_GRP_UPDATE);
|
||||||
}
|
}
|
||||||
if (is_shadow_grp && nflg && (sgr_remove (group_name) == 0)) {
|
if (is_shadow_grp && nflg && (sgr_remove (group_name) == 0)) {
|
||||||
fprintf (stderr, _("%s: cannot remove the entry of '%s' from the shadow group database\n"), Prog);
|
fprintf (stderr,
|
||||||
|
_("%s: cannot remove entry '%s' from %s\n"),
|
||||||
|
Prog, sgr_dbname ());
|
||||||
#ifdef WITH_AUDIT
|
#ifdef WITH_AUDIT
|
||||||
audit_logger (AUDIT_USER_CHAUTHTOK, Prog,
|
audit_logger (AUDIT_USER_CHAUTHTOK, Prog,
|
||||||
"deleting group",
|
"deleting group",
|
||||||
@ -499,8 +506,8 @@ static void process_flags (int argc, char **argv)
|
|||||||
static void close_files (void)
|
static void close_files (void)
|
||||||
{
|
{
|
||||||
if (gr_close () == 0) {
|
if (gr_close () == 0) {
|
||||||
fprintf (stderr, _("%s: cannot rewrite group file\n"), Prog);
|
fprintf (stderr, _("%s: failure while writing changes to %s\n"), Prog, gr_dbname ());
|
||||||
SYSLOG ((LOG_WARN, "cannot rewrite the group file"));
|
SYSLOG ((LOG_WARN, "failure while writing changes to %s", gr_dbname ()));
|
||||||
#ifdef WITH_AUDIT
|
#ifdef WITH_AUDIT
|
||||||
audit_logger (AUDIT_USER_CHAUTHTOK, Prog,
|
audit_logger (AUDIT_USER_CHAUTHTOK, Prog,
|
||||||
"rewrite group file",
|
"rewrite group file",
|
||||||
@ -509,8 +516,8 @@ static void close_files (void)
|
|||||||
fail_exit (E_GRP_UPDATE);
|
fail_exit (E_GRP_UPDATE);
|
||||||
}
|
}
|
||||||
if (gr_unlock () == 0) {
|
if (gr_unlock () == 0) {
|
||||||
fprintf (stderr, _("%s: cannot unlock the group file\n"), Prog);
|
fprintf (stderr, _("%s: failed to unlock %s\n"), Prog, gr_dbname ());
|
||||||
SYSLOG ((LOG_WARN, "cannot unlock the group file"));
|
SYSLOG ((LOG_WARN, "failed to unlock %s", gr_dbname ()));
|
||||||
#ifdef WITH_AUDIT
|
#ifdef WITH_AUDIT
|
||||||
audit_logger (AUDIT_USER_CHAUTHTOK, Prog,
|
audit_logger (AUDIT_USER_CHAUTHTOK, Prog,
|
||||||
"unlocking group file",
|
"unlocking group file",
|
||||||
@ -523,8 +530,8 @@ static void close_files (void)
|
|||||||
if (is_shadow_grp) {
|
if (is_shadow_grp) {
|
||||||
if (sgr_close () == 0)) {
|
if (sgr_close () == 0)) {
|
||||||
fprintf (stderr,
|
fprintf (stderr,
|
||||||
_("%s: cannot rewrite the shadow group file\n"), Prog);
|
_("%s: failure while writing changes to %s\n"), Prog, sgr_dbname ());
|
||||||
SYSLOG ((LOG_WARN, "cannot rewrite the shadow group file"));
|
SYSLOG ((LOG_WARN, "failure while writing changes to %s", sgr_dbname ()));
|
||||||
#ifdef WITH_AUDIT
|
#ifdef WITH_AUDIT
|
||||||
audit_logger (AUDIT_USER_CHAUTHTOK, Prog,
|
audit_logger (AUDIT_USER_CHAUTHTOK, Prog,
|
||||||
"rewrite gshadow file",
|
"rewrite gshadow file",
|
||||||
@ -533,8 +540,8 @@ static void close_files (void)
|
|||||||
fail_exit (E_GRP_UPDATE);
|
fail_exit (E_GRP_UPDATE);
|
||||||
}
|
}
|
||||||
if (sgr_unlock () == 0) {
|
if (sgr_unlock () == 0) {
|
||||||
fprintf (stderr, _("%s: cannot unlock the shadow group file\n"), Prog);
|
fprintf (stderr, _("%s: failed to unlock %s\n"), Prog, sgr_dbname ());
|
||||||
SYSLOG ((LOG_WARN, "cannot unlock the shadow group file"));
|
SYSLOG ((LOG_WARN, "failed to unlock %s", sgr_dbname ()));
|
||||||
#ifdef WITH_AUDIT
|
#ifdef WITH_AUDIT
|
||||||
audit_logger (AUDIT_USER_CHAUTHTOK, Prog,
|
audit_logger (AUDIT_USER_CHAUTHTOK, Prog,
|
||||||
"unlocking gshadow file",
|
"unlocking gshadow file",
|
||||||
@ -548,8 +555,8 @@ static void close_files (void)
|
|||||||
if (gflg) {
|
if (gflg) {
|
||||||
if (pw_close () == 0) {
|
if (pw_close () == 0) {
|
||||||
fprintf (stderr,
|
fprintf (stderr,
|
||||||
_("%s: cannot rewrite the passwd file\n"), Prog);
|
_("%s: failure while writing changes to %s\n"), Prog, pw_dbname ());
|
||||||
SYSLOG ((LOG_WARN, "cannot rewrite the passwd file"));
|
SYSLOG ((LOG_WARN, "failure while writing changes to %s", pw_dbname ()));
|
||||||
#ifdef WITH_AUDIT
|
#ifdef WITH_AUDIT
|
||||||
audit_logger (AUDIT_USER_CHAUTHTOK, Prog,
|
audit_logger (AUDIT_USER_CHAUTHTOK, Prog,
|
||||||
"rewrite passwd file",
|
"rewrite passwd file",
|
||||||
@ -558,8 +565,8 @@ static void close_files (void)
|
|||||||
fail_exit (E_GRP_UPDATE);
|
fail_exit (E_GRP_UPDATE);
|
||||||
}
|
}
|
||||||
if (pw_unlock () == 0) {
|
if (pw_unlock () == 0) {
|
||||||
fprintf (stderr, _("%s: cannot unlock the passwd file\n"), Prog);
|
fprintf (stderr, _("%s: failed to unlock %s\n"), Prog, pw_dbname ());
|
||||||
SYSLOG ((LOG_WARN, "cannot unlock the passwd file"));
|
SYSLOG ((LOG_WARN, "failed to unlock %s", pw_dbname ()));
|
||||||
#ifdef WITH_AUDIT
|
#ifdef WITH_AUDIT
|
||||||
audit_logger (AUDIT_USER_CHAUTHTOK, Prog,
|
audit_logger (AUDIT_USER_CHAUTHTOK, Prog,
|
||||||
"unlocking passwd file",
|
"unlocking passwd file",
|
||||||
@ -579,31 +586,31 @@ static void close_files (void)
|
|||||||
static void open_files (void)
|
static void open_files (void)
|
||||||
{
|
{
|
||||||
if (gr_lock () == 0) {
|
if (gr_lock () == 0) {
|
||||||
fprintf (stderr, _("%s: cannot lock the group file\n"), Prog);
|
fprintf (stderr, _("%s: cannot lock %s\n"), Prog, gr_dbname ());
|
||||||
SYSLOG ((LOG_WARN, "cannot lock the group file"));
|
SYSLOG ((LOG_WARN, "cannot lock %s", gr_dbname ()));
|
||||||
fail_exit (E_GRP_UPDATE);
|
fail_exit (E_GRP_UPDATE);
|
||||||
}
|
}
|
||||||
group_locked = true;
|
group_locked = true;
|
||||||
if (gr_open (O_RDWR) == 0) {
|
if (gr_open (O_RDWR) == 0) {
|
||||||
fprintf (stderr, _("%s: cannot open the group file\n"), Prog);
|
fprintf (stderr, _("%s: cannot open %s\n"), Prog, gr_dbname ());
|
||||||
SYSLOG ((LOG_WARN, "cannot open the group file"));
|
SYSLOG ((LOG_WARN, "cannot open %s", gr_dbname ()));
|
||||||
fail_exit (E_GRP_UPDATE);
|
fail_exit (E_GRP_UPDATE);
|
||||||
}
|
}
|
||||||
#ifdef SHADOWGRP
|
#ifdef SHADOWGRP
|
||||||
if (is_shadow_grp) {
|
if (is_shadow_grp) {
|
||||||
if (sgr_lock () == 0) {
|
if (sgr_lock () == 0) {
|
||||||
fprintf (stderr,
|
fprintf (stderr,
|
||||||
_("%s: cannot lock the shadow group file\n"),
|
_("%s: cannot lock %s\n"),
|
||||||
Prog);
|
Prog, sgr_dbname ());
|
||||||
SYSLOG ((LOG_WARN, "cannot lock the shadow group file"));
|
SYSLOG ((LOG_WARN, "cannot lock %s", sgr_dbname ()));
|
||||||
fail_exit (E_GRP_UPDATE);
|
fail_exit (E_GRP_UPDATE);
|
||||||
}
|
}
|
||||||
gshadow_locked = true;
|
gshadow_locked = true;
|
||||||
if (sgr_open (O_RDWR) == 0) {
|
if (sgr_open (O_RDWR) == 0) {
|
||||||
fprintf (stderr,
|
fprintf (stderr,
|
||||||
_("%s: cannot open the shadow group file\n"),
|
_("%s: cannot open %s\n"),
|
||||||
Prog);
|
Prog, sgr_dbname ());
|
||||||
SYSLOG ((LOG_WARN, "cannot open the shadow group file"));
|
SYSLOG ((LOG_WARN, "cannot open %s", sgr_dbname ()));
|
||||||
fail_exit (E_GRP_UPDATE);
|
fail_exit (E_GRP_UPDATE);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -611,17 +618,17 @@ static void open_files (void)
|
|||||||
if (gflg) {
|
if (gflg) {
|
||||||
if (pw_lock () == 0) {
|
if (pw_lock () == 0) {
|
||||||
fprintf (stderr,
|
fprintf (stderr,
|
||||||
_("%s: cannot lock the passwd file\n"),
|
_("%s: cannot lock %s\n"),
|
||||||
Prog);
|
Prog, pw_dbname ());
|
||||||
SYSLOG ((LOG_WARN, "cannot lock the passwd file"));
|
SYSLOG ((LOG_WARN, "cannot lock %s", pw_dbname ()));
|
||||||
fail_exit (E_GRP_UPDATE);
|
fail_exit (E_GRP_UPDATE);
|
||||||
}
|
}
|
||||||
passwd_locked = true;
|
passwd_locked = true;
|
||||||
if (pw_open (O_RDWR) == 0) {
|
if (pw_open (O_RDWR) == 0) {
|
||||||
fprintf (stderr,
|
fprintf (stderr,
|
||||||
_("%s: cannot open the passwd file\n"),
|
_("%s: cannot open %s\n"),
|
||||||
Prog);
|
Prog, pw_dbname ());
|
||||||
SYSLOG ((LOG_WARN, "cannot open the passwd file"));
|
SYSLOG ((LOG_WARN, "cannot open %s", gr_dbname ()));
|
||||||
fail_exit (E_GRP_UPDATE);
|
fail_exit (E_GRP_UPDATE);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -639,10 +646,11 @@ void update_primary_groups (gid_t ogid, gid_t ngid)
|
|||||||
lpwd = pw_locate (pwd->pw_name);
|
lpwd = pw_locate (pwd->pw_name);
|
||||||
if (NULL == lpwd) {
|
if (NULL == lpwd) {
|
||||||
fprintf (stderr,
|
fprintf (stderr,
|
||||||
_("%s: cannot change the primary group of user '%s' from %lu to %lu, since it is not in the passwd file.\n"),
|
_("%s: cannot change the primary group of user '%s' from %lu to %lu, since it is not in %s.\n"),
|
||||||
Prog, pwd->pw_name,
|
Prog, pwd->pw_name,
|
||||||
(unsigned long) ogid,
|
(unsigned long) ogid,
|
||||||
(unsigned long) ngid);
|
(unsigned long) ngid,
|
||||||
|
pw_dbname ());
|
||||||
fail_exit (E_GRP_UPDATE);
|
fail_exit (E_GRP_UPDATE);
|
||||||
} else {
|
} else {
|
||||||
npwd = *lpwd;
|
npwd = *lpwd;
|
||||||
|
16
src/grpck.c
16
src/grpck.c
@ -183,13 +183,13 @@ static void process_flags (int argc, char **argv)
|
|||||||
*/
|
*/
|
||||||
if (optind != argc) {
|
if (optind != argc) {
|
||||||
grp_file = argv[optind];
|
grp_file = argv[optind];
|
||||||
gr_name (grp_file);
|
gr_setdbname (grp_file);
|
||||||
use_system_grp_file = false;
|
use_system_grp_file = false;
|
||||||
}
|
}
|
||||||
#ifdef SHADOWGRP
|
#ifdef SHADOWGRP
|
||||||
if ((optind + 2) == argc) {
|
if ((optind + 2) == argc) {
|
||||||
sgr_file = argv[optind + 1];
|
sgr_file = argv[optind + 1];
|
||||||
sgr_name (sgr_file);
|
sgr_setdbname (sgr_file);
|
||||||
is_shadow = true;
|
is_shadow = true;
|
||||||
use_system_sgr_file = false;
|
use_system_sgr_file = false;
|
||||||
} else if (optind == argc) {
|
} else if (optind == argc) {
|
||||||
@ -211,7 +211,7 @@ static void open_files (void)
|
|||||||
*/
|
*/
|
||||||
if (!read_only) {
|
if (!read_only) {
|
||||||
if (gr_lock () == 0) {
|
if (gr_lock () == 0) {
|
||||||
fprintf (stderr, _("%s: cannot lock file %s\n"),
|
fprintf (stderr, _("%s: cannot lock %s\n"),
|
||||||
Prog, grp_file);
|
Prog, grp_file);
|
||||||
if (use_system_grp_file) {
|
if (use_system_grp_file) {
|
||||||
SYSLOG ((LOG_WARN, "cannot lock %s", grp_file));
|
SYSLOG ((LOG_WARN, "cannot lock %s", grp_file));
|
||||||
@ -221,7 +221,7 @@ static void open_files (void)
|
|||||||
}
|
}
|
||||||
#ifdef SHADOWGRP
|
#ifdef SHADOWGRP
|
||||||
if (is_shadow && (sgr_lock () == 0)) {
|
if (is_shadow && (sgr_lock () == 0)) {
|
||||||
fprintf (stderr, _("%s: cannot lock file %s\n"),
|
fprintf (stderr, _("%s: cannot lock %s\n"),
|
||||||
Prog, sgr_file);
|
Prog, sgr_file);
|
||||||
if (use_system_sgr_file) {
|
if (use_system_sgr_file) {
|
||||||
SYSLOG ((LOG_WARN, "cannot lock %s", sgr_file));
|
SYSLOG ((LOG_WARN, "cannot lock %s", sgr_file));
|
||||||
@ -237,7 +237,7 @@ static void open_files (void)
|
|||||||
* O_RDWR otherwise.
|
* O_RDWR otherwise.
|
||||||
*/
|
*/
|
||||||
if (gr_open (read_only ? O_RDONLY : O_RDWR) == 0) {
|
if (gr_open (read_only ? O_RDONLY : O_RDWR) == 0) {
|
||||||
fprintf (stderr, _("%s: cannot open file %s\n"), Prog,
|
fprintf (stderr, _("%s: cannot open %s\n"), Prog,
|
||||||
grp_file);
|
grp_file);
|
||||||
if (use_system_grp_file) {
|
if (use_system_grp_file) {
|
||||||
SYSLOG ((LOG_WARN, "cannot open %s", grp_file));
|
SYSLOG ((LOG_WARN, "cannot open %s", grp_file));
|
||||||
@ -247,7 +247,7 @@ static void open_files (void)
|
|||||||
}
|
}
|
||||||
#ifdef SHADOWGRP
|
#ifdef SHADOWGRP
|
||||||
if (is_shadow && (sgr_open (read_only ? O_RDONLY : O_RDWR) == 0)) {
|
if (is_shadow && (sgr_open (read_only ? O_RDONLY : O_RDWR) == 0)) {
|
||||||
fprintf (stderr, _("%s: cannot open file %s\n"), Prog,
|
fprintf (stderr, _("%s: cannot open %s\n"), Prog,
|
||||||
sgr_file);
|
sgr_file);
|
||||||
if (use_system_sgr_file) {
|
if (use_system_sgr_file) {
|
||||||
SYSLOG ((LOG_WARN, "cannot open %s", sgr_file));
|
SYSLOG ((LOG_WARN, "cannot open %s", sgr_file));
|
||||||
@ -273,13 +273,13 @@ static void close_files (bool changed)
|
|||||||
*/
|
*/
|
||||||
if (changed) {
|
if (changed) {
|
||||||
if (gr_close () == 0) {
|
if (gr_close () == 0) {
|
||||||
fprintf (stderr, _("%s: cannot update file %s\n"),
|
fprintf (stderr, _("%s: failure while writing changes to %s\n"),
|
||||||
Prog, grp_file);
|
Prog, grp_file);
|
||||||
exit (E_CANT_UPDATE);
|
exit (E_CANT_UPDATE);
|
||||||
}
|
}
|
||||||
#ifdef SHADOWGRP
|
#ifdef SHADOWGRP
|
||||||
if (is_shadow && (sgr_close () == 0)) {
|
if (is_shadow && (sgr_close () == 0)) {
|
||||||
fprintf (stderr, _("%s: cannot update file %s\n"),
|
fprintf (stderr, _("%s: failure while writing changes to %s\n"),
|
||||||
Prog, sgr_file);
|
Prog, sgr_file);
|
||||||
exit (E_CANT_UPDATE);
|
exit (E_CANT_UPDATE);
|
||||||
}
|
}
|
||||||
|
@ -83,22 +83,22 @@ int main (int argc, char **argv)
|
|||||||
(void) textdomain (PACKAGE);
|
(void) textdomain (PACKAGE);
|
||||||
|
|
||||||
if (gr_lock () == 0) {
|
if (gr_lock () == 0) {
|
||||||
fprintf (stderr, _("%s: can't lock group file\n"), Prog);
|
fprintf (stderr, _("%s: cannot lock %s\n"), Prog, gr_dbname ());
|
||||||
fail_exit (5);
|
fail_exit (5);
|
||||||
}
|
}
|
||||||
group_locked = true;
|
group_locked = true;
|
||||||
if (gr_open (O_RDWR) == 0) {
|
if (gr_open (O_RDWR) == 0) {
|
||||||
fprintf (stderr, _("%s: can't open group file\n"), Prog);
|
fprintf (stderr, _("%s: cannot open %s\n"), Prog, gr_dbname ());
|
||||||
fail_exit (1);
|
fail_exit (1);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (sgr_lock () == 0) {
|
if (sgr_lock () == 0) {
|
||||||
fprintf (stderr, _("%s: can't lock shadow group file\n"), Prog);
|
fprintf (stderr, _("%s: cannot lock %s\n"), Prog, sgr_dbname ());
|
||||||
fail_exit (5);
|
fail_exit (5);
|
||||||
}
|
}
|
||||||
gshadow_locked = true;
|
gshadow_locked = true;
|
||||||
if (sgr_open (O_CREAT | O_RDWR) == 0) {
|
if (sgr_open (O_CREAT | O_RDWR) == 0) {
|
||||||
fprintf (stderr, _("%s: can't open shadow group file\n"), Prog);
|
fprintf (stderr, _("%s: cannot open %s\n"), Prog, sgr_dbname ());
|
||||||
fail_exit (1);
|
fail_exit (1);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -116,8 +116,8 @@ int main (int argc, char **argv)
|
|||||||
* This shouldn't happen (the entry exists) but...
|
* This shouldn't happen (the entry exists) but...
|
||||||
*/
|
*/
|
||||||
fprintf (stderr,
|
fprintf (stderr,
|
||||||
_("%s: can't remove shadow group %s\n"),
|
_("%s: cannot remove entry '%s' from %s\n"),
|
||||||
Prog, sg->sg_name);
|
Prog, sg->sg_name, sgr_dbname ());
|
||||||
fail_exit (3);
|
fail_exit (3);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -171,12 +171,15 @@ int main (int argc, char **argv)
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (sgr_close () == 0) {
|
if (sgr_close () == 0) {
|
||||||
fprintf (stderr, _("%s: can't update shadow group file\n"),
|
fprintf (stderr,
|
||||||
Prog);
|
_("%s: failure while writing changes to %s\n"),
|
||||||
|
Prog, sgr_dbname ());
|
||||||
fail_exit (3);
|
fail_exit (3);
|
||||||
}
|
}
|
||||||
if (gr_close () == 0) {
|
if (gr_close () == 0) {
|
||||||
fprintf (stderr, _("%s: can't update group file\n"), Prog);
|
fprintf (stderr,
|
||||||
|
_("%s: failure while writing changes to %s\n"),
|
||||||
|
Prog, gr_dbname ());
|
||||||
fail_exit (3);
|
fail_exit (3);
|
||||||
}
|
}
|
||||||
sgr_unlock ();
|
sgr_unlock ();
|
||||||
|
@ -2,6 +2,7 @@
|
|||||||
* Copyright (c) 1996 , Michael Meskes
|
* Copyright (c) 1996 , Michael Meskes
|
||||||
* Copyright (c) 1996 - 2000, Marek Michałkiewicz
|
* Copyright (c) 1996 - 2000, Marek Michałkiewicz
|
||||||
* Copyright (c) 2002 - 2006, Tomasz Kłoczko
|
* Copyright (c) 2002 - 2006, Tomasz Kłoczko
|
||||||
|
* Copyright (c) 2008 , Nicolas François
|
||||||
* All rights reserved.
|
* All rights reserved.
|
||||||
*
|
*
|
||||||
* Redistribution and use in source and binary forms, with or without
|
* Redistribution and use in source and binary forms, with or without
|
||||||
@ -86,22 +87,26 @@ int main (int argc, char **argv)
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (gr_lock () == 0) {
|
if (gr_lock () == 0) {
|
||||||
fprintf (stderr, _("%s: can't lock group file\n"), Prog);
|
fprintf (stderr,
|
||||||
|
_("%s: cannot lock %s\n"), Prog, gr_dbname ());
|
||||||
fail_exit (5);
|
fail_exit (5);
|
||||||
}
|
}
|
||||||
group_locked = true;
|
group_locked = true;
|
||||||
if (gr_open (O_RDWR) == 0) {
|
if (gr_open (O_RDWR) == 0) {
|
||||||
fprintf (stderr, _("%s: can't open group file\n"), Prog);
|
fprintf (stderr,
|
||||||
|
_("%s: cannot open %s\n"), Prog, gr_dbname ());
|
||||||
fail_exit (1);
|
fail_exit (1);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (sgr_lock () == 0) {
|
if (sgr_lock () == 0) {
|
||||||
fprintf (stderr, _("%s: can't lock shadow group file\n"), Prog);
|
fprintf (stderr,
|
||||||
|
_("%s: cannot lock %s\n"), Prog, sgr_dbname ());
|
||||||
fail_exit (5);
|
fail_exit (5);
|
||||||
}
|
}
|
||||||
gshadow_locked = true;
|
gshadow_locked = true;
|
||||||
if (sgr_open (O_RDWR) == 0) {
|
if (sgr_open (O_RDWR) == 0) {
|
||||||
fprintf (stderr, _("%s: can't open shadow group file\n"), Prog);
|
fprintf (stderr,
|
||||||
|
_("%s: cannot open %s\n"), Prog, sgr_dbname ());
|
||||||
fail_exit (1);
|
fail_exit (1);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -127,19 +132,23 @@ int main (int argc, char **argv)
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (sgr_close () == 0) {
|
if (sgr_close () == 0) {
|
||||||
fprintf (stderr, _("%s: can't update shadow group file\n"),
|
fprintf (stderr,
|
||||||
Prog);
|
_("%s: failure while writing changes to %s\n"),
|
||||||
|
Prog, sgr_dbname ());
|
||||||
fail_exit (3);
|
fail_exit (3);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (gr_close () == 0) {
|
if (gr_close () == 0) {
|
||||||
fprintf (stderr, _("%s: can't update group file\n"), Prog);
|
fprintf (stderr,
|
||||||
|
_("%s: failure while writing changes to %s\n"),
|
||||||
|
Prog, gr_dbname ());
|
||||||
fail_exit (3);
|
fail_exit (3);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (unlink (SGROUP_FILE) != 0) {
|
if (unlink (SGROUP_FILE) != 0) {
|
||||||
fprintf (stderr, _("%s: can't delete shadow group file\n"),
|
fprintf (stderr,
|
||||||
Prog);
|
_("%s: cannot delete %s\n"),
|
||||||
|
Prog, SGROUP_FILE);
|
||||||
fail_exit (3);
|
fail_exit (3);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -158,3 +167,4 @@ int main (int argc, char **argv)
|
|||||||
exit (1);
|
exit (1);
|
||||||
}
|
}
|
||||||
#endif /* !SHADOWGRP */
|
#endif /* !SHADOWGRP */
|
||||||
|
|
||||||
|
@ -517,7 +517,7 @@ static void check_flags (void)
|
|||||||
{
|
{
|
||||||
if (sflg && !cflg) {
|
if (sflg && !cflg) {
|
||||||
fprintf (stderr,
|
fprintf (stderr,
|
||||||
_("%s: %s flag is ONLY allowed with the %s flag\n"),
|
_("%s: %s flag is only allowed with the %s flag\n"),
|
||||||
Prog, "-s", "-c");
|
Prog, "-s", "-c");
|
||||||
usage ();
|
usage ();
|
||||||
}
|
}
|
||||||
@ -556,29 +556,24 @@ static void check_perms (void)
|
|||||||
struct passwd *pampw;
|
struct passwd *pampw;
|
||||||
|
|
||||||
pampw = getpwuid (getuid ()); /* local, no need for xgetpwuid */
|
pampw = getpwuid (getuid ()); /* local, no need for xgetpwuid */
|
||||||
if (pampw == NULL) {
|
if (NULL == pampw) {
|
||||||
retval = PAM_USER_UNKNOWN;
|
retval = PAM_USER_UNKNOWN;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (retval == PAM_SUCCESS) {
|
if (PAM_SUCCESS == retval) {
|
||||||
retval = pam_start ("newusers", pampw->pw_name, &conv, &pamh);
|
retval = pam_start ("newusers", pampw->pw_name, &conv, &pamh);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (retval == PAM_SUCCESS) {
|
if (PAM_SUCCESS == retval) {
|
||||||
retval = pam_authenticate (pamh, 0);
|
retval = pam_authenticate (pamh, 0);
|
||||||
if (retval != PAM_SUCCESS) {
|
|
||||||
(void) pam_end (pamh, retval);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (retval == PAM_SUCCESS) {
|
if (PAM_SUCCESS == retval) {
|
||||||
retval = pam_acct_mgmt (pamh, 0);
|
retval = pam_acct_mgmt (pamh, 0);
|
||||||
if (retval != PAM_SUCCESS) {
|
|
||||||
(void) pam_end (pamh, retval);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (retval != PAM_SUCCESS) {
|
if (PAM_SUCCESS != retval) {
|
||||||
|
(void) pam_end (pamh, retval);
|
||||||
fprintf (stderr, _("%s: PAM authentication failed\n"), Prog);
|
fprintf (stderr, _("%s: PAM authentication failed\n"), Prog);
|
||||||
fail_exit (1);
|
fail_exit (1);
|
||||||
}
|
}
|
||||||
@ -597,23 +592,23 @@ static void open_files (void)
|
|||||||
* it gets locked, assume the others can be locked right away.
|
* it gets locked, assume the others can be locked right away.
|
||||||
*/
|
*/
|
||||||
if (pw_lock () == 0) {
|
if (pw_lock () == 0) {
|
||||||
fprintf (stderr, _("%s: can't lock /etc/passwd.\n"), Prog);
|
fprintf (stderr, _("%s: cannot lock %s\n"), Prog, pw_dbname ());
|
||||||
fail_exit (1);
|
fail_exit (1);
|
||||||
}
|
}
|
||||||
passwd_locked = true;
|
passwd_locked = true;
|
||||||
if (is_shadow && (spw_lock () == 0)) {
|
if (is_shadow && (spw_lock () == 0)) {
|
||||||
fprintf (stderr, _("%s: can't lock /etc/shadow.\n"), Prog);
|
fprintf (stderr, _("%s: cannot lock %s\n"), Prog, spw_dbname ());
|
||||||
fail_exit (1);
|
fail_exit (1);
|
||||||
}
|
}
|
||||||
shadow_locked = true;
|
shadow_locked = true;
|
||||||
if (gr_lock () == 0) {
|
if (gr_lock () == 0) {
|
||||||
fprintf (stderr, _("%s: can't lock /etc/group.\n"), Prog);
|
fprintf (stderr, _("%s: cannot lock %s\n"), Prog, gr_dbname ());
|
||||||
fail_exit (1);
|
fail_exit (1);
|
||||||
}
|
}
|
||||||
group_locked = true;
|
group_locked = true;
|
||||||
#ifdef SHADOWGRP
|
#ifdef SHADOWGRP
|
||||||
if (is_shadow_grp && (sgr_lock () == 0)) {
|
if (is_shadow_grp && (sgr_lock () == 0)) {
|
||||||
fprintf (stderr, _("%s: can't lock /etc/gshadow.\n"), Prog);
|
fprintf (stderr, _("%s: cannot lock %s\n"), Prog, sgr_dbname ());
|
||||||
fail_exit (1);
|
fail_exit (1);
|
||||||
}
|
}
|
||||||
gshadow_locked = true;
|
gshadow_locked = true;
|
||||||
@ -800,8 +795,8 @@ int main (int argc, char **argv)
|
|||||||
pw = pw_locate (fields[0]);
|
pw = pw_locate (fields[0]);
|
||||||
if (NULL == pw) {
|
if (NULL == pw) {
|
||||||
fprintf (stderr,
|
fprintf (stderr,
|
||||||
_("%s: line %d: cannot find user %s\n"),
|
_("%s: line %d: user '%s' does not exist in %s\n"),
|
||||||
Prog, line, fields[0]);
|
Prog, line, fields[0], pw_dbname ());
|
||||||
errors++;
|
errors++;
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
49
src/passwd.c
49
src/passwd.c
@ -512,20 +512,24 @@ static void update_noshadow (void)
|
|||||||
struct passwd *npw;
|
struct passwd *npw;
|
||||||
|
|
||||||
if (pw_lock () == 0) {
|
if (pw_lock () == 0) {
|
||||||
fputs (_("Cannot lock the password file; try again later.\n"),
|
fprintf (stderr,
|
||||||
stderr);
|
_("%s: cannot lock %s; try again later.\n"),
|
||||||
SYSLOG ((LOG_WARN, "can't lock password file"));
|
Prog, pw_dbname ());
|
||||||
|
SYSLOG ((LOG_WARN, "cannot lock %s", pw_dbname ()));
|
||||||
exit (E_PWDBUSY);
|
exit (E_PWDBUSY);
|
||||||
}
|
}
|
||||||
if (pw_open (O_RDWR) == 0) {
|
if (pw_open (O_RDWR) == 0) {
|
||||||
fputs (_("Cannot open the password file.\n"), stderr);
|
fprintf (stderr,
|
||||||
SYSLOG ((LOG_ERR, "can't open password file"));
|
_("%s: cannot open %s\n"),
|
||||||
|
Prog, pw_dbname ());
|
||||||
|
SYSLOG ((LOG_ERR, "cannot open %s", pw_dbname ()));
|
||||||
fail_exit (E_MISSING);
|
fail_exit (E_MISSING);
|
||||||
}
|
}
|
||||||
pw = pw_locate (name);
|
pw = pw_locate (name);
|
||||||
if (NULL == pw) {
|
if (NULL == pw) {
|
||||||
fprintf (stderr, _("%s: %s not found in /etc/passwd\n"),
|
fprintf (stderr,
|
||||||
Prog, name);
|
_("%s: user '%s' does not exist in %s\n"),
|
||||||
|
Prog, name, pw_dbname ());
|
||||||
fail_exit (E_NOPERM);
|
fail_exit (E_NOPERM);
|
||||||
}
|
}
|
||||||
npw = __pw_dup (pw);
|
npw = __pw_dup (pw);
|
||||||
@ -539,8 +543,10 @@ static void update_noshadow (void)
|
|||||||
fail_exit (E_FAILURE);
|
fail_exit (E_FAILURE);
|
||||||
}
|
}
|
||||||
if (pw_close () == 0) {
|
if (pw_close () == 0) {
|
||||||
fputs (_("Cannot commit password file changes.\n"), stderr);
|
fprintf (stderr,
|
||||||
SYSLOG ((LOG_ERR, "can't rewrite password file"));
|
_("%s: failure while writing changes to %s\n"),
|
||||||
|
Prog, pw_dbname ());
|
||||||
|
SYSLOG ((LOG_ERR, "failure while writing changes to %s", pw_dbname ()));
|
||||||
fail_exit (E_FAILURE);
|
fail_exit (E_FAILURE);
|
||||||
}
|
}
|
||||||
pw_unlock ();
|
pw_unlock ();
|
||||||
@ -552,14 +558,15 @@ static void update_shadow (void)
|
|||||||
struct spwd *nsp;
|
struct spwd *nsp;
|
||||||
|
|
||||||
if (spw_lock () == 0) {
|
if (spw_lock () == 0) {
|
||||||
fputs (_("Cannot lock the password file; try again later.\n"),
|
fprintf (stderr,
|
||||||
stderr);
|
_("%s: cannot lock %s; try again later.\n"),
|
||||||
SYSLOG ((LOG_WARN, "can't lock password file"));
|
Prog, spw_dbname ());
|
||||||
|
SYSLOG ((LOG_WARN, "cannot lock %s", spw_dbname ()));
|
||||||
exit (E_PWDBUSY);
|
exit (E_PWDBUSY);
|
||||||
}
|
}
|
||||||
if (spw_open (O_RDWR) == 0) {
|
if (spw_open (O_RDWR) == 0) {
|
||||||
fputs (_("Cannot open the password file.\n"), stderr);
|
fprintf (stderr, _("%s: cannot open %s\n"), Prog, spw_dbname ());
|
||||||
SYSLOG ((LOG_ERR, "can't open password file"));
|
SYSLOG ((LOG_ERR, "cannot open %s", spw_dbname ()));
|
||||||
fail_exit (E_FAILURE);
|
fail_exit (E_FAILURE);
|
||||||
}
|
}
|
||||||
sp = spw_locate (name);
|
sp = spw_locate (name);
|
||||||
@ -614,8 +621,10 @@ static void update_shadow (void)
|
|||||||
fail_exit (E_FAILURE);
|
fail_exit (E_FAILURE);
|
||||||
}
|
}
|
||||||
if (spw_close () == 0) {
|
if (spw_close () == 0) {
|
||||||
fputs (_("Cannot commit password file changes.\n"), stderr);
|
fprintf (stderr,
|
||||||
SYSLOG ((LOG_ERR, "can't rewrite password file"));
|
_("%s: failure while writing changes to %s\n"),
|
||||||
|
Prog, spw_dbname ());
|
||||||
|
SYSLOG ((LOG_ERR, "failure while writing changes to %s", spw_dbname ()));
|
||||||
fail_exit (E_FAILURE);
|
fail_exit (E_FAILURE);
|
||||||
}
|
}
|
||||||
spw_unlock ();
|
spw_unlock ();
|
||||||
@ -809,8 +818,7 @@ int main (int argc, char **argv)
|
|||||||
/* only "files" supported for now */
|
/* only "files" supported for now */
|
||||||
if (strcmp (optarg, "files") != 0) {
|
if (strcmp (optarg, "files") != 0) {
|
||||||
fprintf (stderr,
|
fprintf (stderr,
|
||||||
_
|
_("%s: repository %s not supported\n"),
|
||||||
("%s: repository %s not supported\n"),
|
|
||||||
Prog, optarg);
|
Prog, optarg);
|
||||||
exit (E_BAD_ARG);
|
exit (E_BAD_ARG);
|
||||||
}
|
}
|
||||||
@ -920,7 +928,7 @@ int main (int argc, char **argv)
|
|||||||
|
|
||||||
pw = xgetpwnam (name);
|
pw = xgetpwnam (name);
|
||||||
if (NULL == pw) {
|
if (NULL == pw) {
|
||||||
fprintf (stderr, _("%s: unknown user %s\n"), Prog, name);
|
fprintf (stderr, _("%s: user '%s' does not exist\n"), Prog, name);
|
||||||
exit (E_NOPERM);
|
exit (E_NOPERM);
|
||||||
}
|
}
|
||||||
#ifdef WITH_SELINUX
|
#ifdef WITH_SELINUX
|
||||||
@ -949,8 +957,7 @@ int main (int argc, char **argv)
|
|||||||
*/
|
*/
|
||||||
if (!amroot && (pw->pw_uid != getuid ())) {
|
if (!amroot && (pw->pw_uid != getuid ())) {
|
||||||
fprintf (stderr,
|
fprintf (stderr,
|
||||||
_
|
_("%s: You may not view or modify password information for %s.\n"),
|
||||||
("%s: You may not view or modify password information for %s.\n"),
|
|
||||||
Prog, name);
|
Prog, name);
|
||||||
SYSLOG ((LOG_WARN,
|
SYSLOG ((LOG_WARN,
|
||||||
"%s: can't view or modify password information for %s",
|
"%s: can't view or modify password information for %s",
|
||||||
|
20
src/pwck.c
20
src/pwck.c
@ -141,12 +141,12 @@ static void process_flags (int argc, char **argv)
|
|||||||
*/
|
*/
|
||||||
if (optind != argc) {
|
if (optind != argc) {
|
||||||
pwd_file = argv[optind];
|
pwd_file = argv[optind];
|
||||||
pw_name (pwd_file);
|
pw_setdbname (pwd_file);
|
||||||
use_system_pw_file = false;
|
use_system_pw_file = false;
|
||||||
}
|
}
|
||||||
if ((optind + 2) == argc) {
|
if ((optind + 2) == argc) {
|
||||||
spw_file = argv[optind + 1];
|
spw_file = argv[optind + 1];
|
||||||
spw_name (spw_file);
|
spw_setdbname (spw_file);
|
||||||
is_shadow = true;
|
is_shadow = true;
|
||||||
use_system_spw_file = false;
|
use_system_spw_file = false;
|
||||||
} else if (optind == argc) {
|
} else if (optind == argc) {
|
||||||
@ -167,7 +167,7 @@ static void open_files (void)
|
|||||||
*/
|
*/
|
||||||
if (!read_only) {
|
if (!read_only) {
|
||||||
if (pw_lock () == 0) {
|
if (pw_lock () == 0) {
|
||||||
fprintf (stderr, _("%s: cannot lock file %s\n"),
|
fprintf (stderr, _("%s: cannot lock %s\n"),
|
||||||
Prog, pwd_file);
|
Prog, pwd_file);
|
||||||
if (use_system_pw_file) {
|
if (use_system_pw_file) {
|
||||||
SYSLOG ((LOG_WARN, "cannot lock %s", pwd_file));
|
SYSLOG ((LOG_WARN, "cannot lock %s", pwd_file));
|
||||||
@ -176,7 +176,7 @@ static void open_files (void)
|
|||||||
exit (E_CANTLOCK);
|
exit (E_CANTLOCK);
|
||||||
}
|
}
|
||||||
if (is_shadow && (spw_lock () == 0)) {
|
if (is_shadow && (spw_lock () == 0)) {
|
||||||
fprintf (stderr, _("%s: cannot lock file %s\n"),
|
fprintf (stderr, _("%s: cannot lock %s\n"),
|
||||||
Prog, spw_file);
|
Prog, spw_file);
|
||||||
if (use_system_spw_file) {
|
if (use_system_spw_file) {
|
||||||
SYSLOG ((LOG_WARN, "cannot lock %s", spw_file));
|
SYSLOG ((LOG_WARN, "cannot lock %s", spw_file));
|
||||||
@ -191,7 +191,7 @@ static void open_files (void)
|
|||||||
* otherwise.
|
* otherwise.
|
||||||
*/
|
*/
|
||||||
if (pw_open (read_only ? O_RDONLY : O_RDWR) == 0) {
|
if (pw_open (read_only ? O_RDONLY : O_RDWR) == 0) {
|
||||||
fprintf (stderr, _("%s: cannot open file %s\n"),
|
fprintf (stderr, _("%s: cannot open %s\n"),
|
||||||
Prog, pwd_file);
|
Prog, pwd_file);
|
||||||
if (use_system_pw_file) {
|
if (use_system_pw_file) {
|
||||||
SYSLOG ((LOG_WARN, "cannot open %s", pwd_file));
|
SYSLOG ((LOG_WARN, "cannot open %s", pwd_file));
|
||||||
@ -200,7 +200,7 @@ static void open_files (void)
|
|||||||
exit (E_CANTOPEN);
|
exit (E_CANTOPEN);
|
||||||
}
|
}
|
||||||
if (is_shadow && (spw_open (read_only ? O_RDONLY : O_RDWR) == 0)) {
|
if (is_shadow && (spw_open (read_only ? O_RDONLY : O_RDWR) == 0)) {
|
||||||
fprintf (stderr, _("%s: cannot open file %s\n"),
|
fprintf (stderr, _("%s: cannot open %s\n"),
|
||||||
Prog, spw_file);
|
Prog, spw_file);
|
||||||
if (use_system_spw_file) {
|
if (use_system_spw_file) {
|
||||||
SYSLOG ((LOG_WARN, "cannot open %s", spw_file));
|
SYSLOG ((LOG_WARN, "cannot open %s", spw_file));
|
||||||
@ -225,16 +225,16 @@ static void close_files (bool changed)
|
|||||||
*/
|
*/
|
||||||
if (changed) {
|
if (changed) {
|
||||||
if (pw_close () == 0) {
|
if (pw_close () == 0) {
|
||||||
fprintf (stderr, _("%s: cannot update file %s\n"),
|
fprintf (stderr, _("%s: failure while writing changes to %s\n"),
|
||||||
Prog, pwd_file);
|
Prog, pwd_file);
|
||||||
SYSLOG ((LOG_WARN, "cannot update %s", pwd_file));
|
SYSLOG ((LOG_WARN, "failure while writing changes to %s", pwd_file));
|
||||||
closelog ();
|
closelog ();
|
||||||
exit (E_CANTUPDATE);
|
exit (E_CANTUPDATE);
|
||||||
}
|
}
|
||||||
if (is_shadow && (spw_close () == 0)) {
|
if (is_shadow && (spw_close () == 0)) {
|
||||||
fprintf (stderr, _("%s: cannot update file %s\n"),
|
fprintf (stderr, _("%s: failure while writing changes to %s\n"),
|
||||||
Prog, spw_file);
|
Prog, spw_file);
|
||||||
SYSLOG ((LOG_WARN, "cannot update %s", spw_file));
|
SYSLOG ((LOG_WARN, "failure while writing changes to %s", spw_file));
|
||||||
closelog ();
|
closelog ();
|
||||||
exit (E_CANTUPDATE);
|
exit (E_CANTUPDATE);
|
||||||
}
|
}
|
||||||
|
25
src/pwconv.c
25
src/pwconv.c
@ -113,22 +113,26 @@ int main (int argc, char **argv)
|
|||||||
(void) textdomain (PACKAGE);
|
(void) textdomain (PACKAGE);
|
||||||
|
|
||||||
if (pw_lock () == 0) {
|
if (pw_lock () == 0) {
|
||||||
fprintf (stderr, _("%s: can't lock passwd file\n"), Prog);
|
fprintf (stderr,
|
||||||
|
_("%s: cannot lock %s\n"), Prog, pw_dbname ());
|
||||||
fail_exit (E_PWDBUSY);
|
fail_exit (E_PWDBUSY);
|
||||||
}
|
}
|
||||||
passwd_locked = true;
|
passwd_locked = true;
|
||||||
if (pw_open (O_RDWR) == 0) {
|
if (pw_open (O_RDWR) == 0) {
|
||||||
fprintf (stderr, _("%s: can't open passwd file\n"), Prog);
|
fprintf (stderr,
|
||||||
|
_("%s: cannot open %s\n"), Prog, pw_dbname ());
|
||||||
fail_exit (E_MISSING);
|
fail_exit (E_MISSING);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (spw_lock () == 0) {
|
if (spw_lock () == 0) {
|
||||||
fprintf (stderr, _("%s: can't lock shadow file\n"), Prog);
|
fprintf (stderr,
|
||||||
|
_("%s: cannot lock %s\n"), Prog, spw_dbname ());
|
||||||
fail_exit (E_PWDBUSY);
|
fail_exit (E_PWDBUSY);
|
||||||
}
|
}
|
||||||
shadow_locked = true;
|
shadow_locked = true;
|
||||||
if (spw_open (O_CREAT | O_RDWR) == 0) {
|
if (spw_open (O_CREAT | O_RDWR) == 0) {
|
||||||
fprintf (stderr, _("%s: can't open shadow file\n"), Prog);
|
fprintf (stderr,
|
||||||
|
_("%s: cannot open %s\n"), Prog, spw_dbname ());
|
||||||
fail_exit (E_FAILURE);
|
fail_exit (E_FAILURE);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -146,9 +150,8 @@ int main (int argc, char **argv)
|
|||||||
* This shouldn't happen (the entry exists) but...
|
* This shouldn't happen (the entry exists) but...
|
||||||
*/
|
*/
|
||||||
fprintf (stderr,
|
fprintf (stderr,
|
||||||
_
|
_("%s: cannot remove entry '%s' from %s\n"),
|
||||||
("%s: can't remove shadow entry for %s\n"),
|
Prog, sp->sp_namp, spw_dbname ());
|
||||||
Prog, sp->sp_namp);
|
|
||||||
fail_exit (E_FAILURE);
|
fail_exit (E_FAILURE);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -201,11 +204,15 @@ int main (int argc, char **argv)
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (spw_close () == 0) {
|
if (spw_close () == 0) {
|
||||||
fprintf (stderr, _("%s: can't update shadow file\n"), Prog);
|
fprintf (stderr,
|
||||||
|
_("%s: failure while writing changes to %s\n"),
|
||||||
|
Prog, spw_dbname ());
|
||||||
fail_exit (E_FAILURE);
|
fail_exit (E_FAILURE);
|
||||||
}
|
}
|
||||||
if (pw_close () == 0) {
|
if (pw_close () == 0) {
|
||||||
fprintf (stderr, _("%s: can't update passwd file\n"), Prog);
|
fprintf (stderr,
|
||||||
|
_("%s: failure while writing changes to %s\n"),
|
||||||
|
Prog, pw_dbname ());
|
||||||
fail_exit (E_FAILURE);
|
fail_exit (E_FAILURE);
|
||||||
}
|
}
|
||||||
chmod (PASSWD_FILE "-", 0600); /* /etc/passwd- (backup file) */
|
chmod (PASSWD_FILE "-", 0600); /* /etc/passwd- (backup file) */
|
||||||
|
@ -83,22 +83,30 @@ int main (int argc, char **argv)
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (pw_lock () == 0) {
|
if (pw_lock () == 0) {
|
||||||
fprintf (stderr, _("%s: can't lock passwd file\n"), Prog);
|
fprintf (stderr,
|
||||||
|
_("%s: cannot lock %s\n"),
|
||||||
|
Prog, pw_dbname ());
|
||||||
fail_exit (5);
|
fail_exit (5);
|
||||||
}
|
}
|
||||||
passwd_locked = true;
|
passwd_locked = true;
|
||||||
if (pw_open (O_RDWR) == 0) {
|
if (pw_open (O_RDWR) == 0) {
|
||||||
fprintf (stderr, _("%s: can't open passwd file\n"), Prog);
|
fprintf (stderr,
|
||||||
|
_("%s: cannot open %s\n"),
|
||||||
|
Prog, pw_dbname ());
|
||||||
fail_exit (1);
|
fail_exit (1);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (spw_lock () == 0) {
|
if (spw_lock () == 0) {
|
||||||
fprintf (stderr, _("%s: can't lock shadow file\n"), Prog);
|
fprintf (stderr,
|
||||||
|
_("%s: cannot lock %s\n"),
|
||||||
|
Prog, spw_dbname ());
|
||||||
fail_exit (5);
|
fail_exit (5);
|
||||||
}
|
}
|
||||||
shadow_locked = true;
|
shadow_locked = true;
|
||||||
if (spw_open (O_RDWR) == 0) {
|
if (spw_open (O_RDWR) == 0) {
|
||||||
fprintf (stderr, _("%s: can't open shadow file\n"), Prog);
|
fprintf (stderr,
|
||||||
|
_("%s: cannot open %s\n"),
|
||||||
|
Prog, spw_dbname ());
|
||||||
fail_exit (1);
|
fail_exit (1);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -138,18 +146,21 @@ int main (int argc, char **argv)
|
|||||||
|
|
||||||
if (spw_close () == 0) {
|
if (spw_close () == 0) {
|
||||||
fprintf (stderr,
|
fprintf (stderr,
|
||||||
_("%s: can't update shadow password file\n"), Prog);
|
_("%s: failure while writing changes to %s\n"),
|
||||||
|
Prog, spw_dbname ());
|
||||||
fail_exit (3);
|
fail_exit (3);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (pw_close () == 0) {
|
if (pw_close () == 0) {
|
||||||
fprintf (stderr, _("%s: can't update password file\n"), Prog);
|
fprintf (stderr,
|
||||||
|
_("%s: failure while writing changes to %s\n"),
|
||||||
|
Prog, pw_dbname ());
|
||||||
fail_exit (3);
|
fail_exit (3);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (unlink (SHADOW) != 0) {
|
if (unlink (SHADOW) != 0) {
|
||||||
fprintf (stderr,
|
fprintf (stderr,
|
||||||
_("%s: can't delete shadow password file\n"), Prog);
|
_("%s: cannot delete %s\n"), Prog, SHADOW);
|
||||||
fail_exit (3);
|
fail_exit (3);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
272
src/useradd.c
272
src/useradd.c
@ -194,21 +194,58 @@ static void create_mail (void);
|
|||||||
*/
|
*/
|
||||||
static void fail_exit (int code)
|
static void fail_exit (int code)
|
||||||
{
|
{
|
||||||
if (home_added)
|
if (home_added) {
|
||||||
rmdir (user_home);
|
rmdir (user_home);
|
||||||
|
}
|
||||||
|
|
||||||
if (shadow_locked) {
|
if (shadow_locked) {
|
||||||
spw_unlock ();
|
if (spw_unlock () == 0) {
|
||||||
|
fprintf (stderr, _("%s: failed to unlock %s\n"), Prog, spw_dbname ());
|
||||||
|
SYSLOG ((LOG_WARN, "failed to unlock %s", spw_dbname ()));
|
||||||
|
#ifdef WITH_AUDIT
|
||||||
|
audit_logger (AUDIT_USER_CHAUTHTOK, Prog,
|
||||||
|
"unlocking shadow file",
|
||||||
|
user_name, AUDIT_NO_ID, 0);
|
||||||
|
#endif
|
||||||
|
/* continue */
|
||||||
|
}
|
||||||
}
|
}
|
||||||
if (passwd_locked) {
|
if (passwd_locked) {
|
||||||
pw_unlock ();
|
if (pw_unlock () == 0) {
|
||||||
|
fprintf (stderr, _("%s: failed to unlock %s\n"), Prog, pw_dbname ());
|
||||||
|
SYSLOG ((LOG_WARN, "failed to unlock %s", pw_dbname ()));
|
||||||
|
#ifdef WITH_AUDIT
|
||||||
|
audit_logger (AUDIT_USER_CHAUTHTOK, Prog,
|
||||||
|
"unlocking passwd file",
|
||||||
|
user_name, AUDIT_NO_ID, 0);
|
||||||
|
#endif
|
||||||
|
/* continue */
|
||||||
|
}
|
||||||
}
|
}
|
||||||
if (group_locked) {
|
if (group_locked) {
|
||||||
gr_unlock ();
|
if (gr_unlock () == 0) {
|
||||||
|
fprintf (stderr, _("%s: failed to unlock %s\n"), Prog, gr_dbname ());
|
||||||
|
SYSLOG ((LOG_WARN, "failed to unlock %s", gr_dbname ()));
|
||||||
|
#ifdef WITH_AUDIT
|
||||||
|
audit_logger (AUDIT_USER_CHAUTHTOK, Prog,
|
||||||
|
"unlocking group file",
|
||||||
|
user_name, AUDIT_NO_ID, 0);
|
||||||
|
#endif
|
||||||
|
/* continue */
|
||||||
|
}
|
||||||
}
|
}
|
||||||
#ifdef SHADOWGRP
|
#ifdef SHADOWGRP
|
||||||
if (gshadow_locked) {
|
if (gshadow_locked) {
|
||||||
sgr_unlock ();
|
if (sgr_unlock () == 0) {
|
||||||
|
fprintf (stderr, _("%s: failed to unlock %s\n"), Prog, sgr_dbname ());
|
||||||
|
SYSLOG ((LOG_WARN, "failed to unlock %s", sgr_dbname ()));
|
||||||
|
#ifdef WITH_AUDIT
|
||||||
|
audit_logger (AUDIT_USER_CHAUTHTOK, Prog,
|
||||||
|
"unlocking gshadow file",
|
||||||
|
user_name, AUDIT_NO_ID, 0);
|
||||||
|
#endif
|
||||||
|
/* continue */
|
||||||
|
}
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
@ -318,7 +355,7 @@ static void get_defaults (void)
|
|||||||
def_gname = xstrdup (grp->gr_name);
|
def_gname = xstrdup (grp->gr_name);
|
||||||
} else {
|
} else {
|
||||||
fprintf (stderr,
|
fprintf (stderr,
|
||||||
_("%s: unknown GID %s\n"),
|
_("%s: GID '%s' does not exist\n"),
|
||||||
Prog, cp);
|
Prog, cp);
|
||||||
}
|
}
|
||||||
/* local, no need for xgetgrnam */
|
/* local, no need for xgetgrnam */
|
||||||
@ -327,7 +364,7 @@ static void get_defaults (void)
|
|||||||
def_gname = xstrdup (cp);
|
def_gname = xstrdup (cp);
|
||||||
} else {
|
} else {
|
||||||
fprintf (stderr,
|
fprintf (stderr,
|
||||||
_("%s: unknown group %s\n"), Prog, cp);
|
_("%s: group '%s' does not exist\n"), Prog, cp);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -599,7 +636,7 @@ static int get_groups (char *list)
|
|||||||
* string name.
|
* string name.
|
||||||
*/
|
*/
|
||||||
if (NULL == grp) {
|
if (NULL == grp) {
|
||||||
fprintf (stderr, _("%s: unknown group %s\n"),
|
fprintf (stderr, _("%s: group '%s' does not exist\n"),
|
||||||
Prog, list);
|
Prog, list);
|
||||||
errors++;
|
errors++;
|
||||||
}
|
}
|
||||||
@ -703,10 +740,11 @@ static void new_pwent (struct passwd *pwent)
|
|||||||
{
|
{
|
||||||
memzero (pwent, sizeof *pwent);
|
memzero (pwent, sizeof *pwent);
|
||||||
pwent->pw_name = (char *) user_name;
|
pwent->pw_name = (char *) user_name;
|
||||||
if (is_shadow_pwd)
|
if (is_shadow_pwd) {
|
||||||
pwent->pw_passwd = (char *) SHADOW_PASSWD_STRING;
|
pwent->pw_passwd = (char *) SHADOW_PASSWD_STRING;
|
||||||
else
|
} else {
|
||||||
pwent->pw_passwd = (char *) user_pass;
|
pwent->pw_passwd = (char *) user_pass;
|
||||||
|
}
|
||||||
|
|
||||||
pwent->pw_uid = user_id;
|
pwent->pw_uid = user_id;
|
||||||
pwent->pw_gid = user_gid;
|
pwent->pw_gid = user_gid;
|
||||||
@ -717,8 +755,9 @@ static void new_pwent (struct passwd *pwent)
|
|||||||
|
|
||||||
static long scale_age (long x)
|
static long scale_age (long x)
|
||||||
{
|
{
|
||||||
if (x <= 0)
|
if (x <= 0) {
|
||||||
return x;
|
return x;
|
||||||
|
}
|
||||||
|
|
||||||
return x * (DAY / SCALE);
|
return x * (DAY / SCALE);
|
||||||
}
|
}
|
||||||
@ -776,14 +815,15 @@ static void grp_update (void)
|
|||||||
* Scan through the entire group file looking for the groups that
|
* Scan through the entire group file looking for the groups that
|
||||||
* the user is a member of.
|
* the user is a member of.
|
||||||
*/
|
*/
|
||||||
for (gr_rewind (), grp = gr_next (); grp; grp = gr_next ()) {
|
for (gr_rewind (), grp = gr_next (); NULL != grp; grp = gr_next ()) {
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* See if the user specified this group as one of their
|
* See if the user specified this group as one of their
|
||||||
* concurrent groups.
|
* concurrent groups.
|
||||||
*/
|
*/
|
||||||
if (!is_on_list (user_groups, grp->gr_name))
|
if (!is_on_list (user_groups, grp->gr_name)) {
|
||||||
continue;
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Make a copy - gr_update() will free() everything
|
* Make a copy - gr_update() will free() everything
|
||||||
@ -831,11 +871,13 @@ static void grp_update (void)
|
|||||||
* See if the user specified this group as one of their
|
* See if the user specified this group as one of their
|
||||||
* concurrent groups.
|
* concurrent groups.
|
||||||
*/
|
*/
|
||||||
if (gr_locate (sgrp->sg_name) == NULL)
|
if (gr_locate (sgrp->sg_name) == NULL) {
|
||||||
continue;
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
if (!is_on_list (user_groups, sgrp->sg_name))
|
if (!is_on_list (user_groups, sgrp->sg_name)) {
|
||||||
continue;
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Make a copy - sgr_update() will free() everything
|
* Make a copy - sgr_update() will free() everything
|
||||||
@ -844,8 +886,8 @@ static void grp_update (void)
|
|||||||
nsgrp = __sgr_dup (sgrp);
|
nsgrp = __sgr_dup (sgrp);
|
||||||
if (NULL == nsgrp) {
|
if (NULL == nsgrp) {
|
||||||
fprintf (stderr,
|
fprintf (stderr,
|
||||||
_("%s: Out of memory. Cannot update the shadow group database.\n"),
|
_("%s: Out of memory. Cannot update %s.\n"),
|
||||||
Prog);
|
Prog, sgr_dbname ());
|
||||||
fail_exit (E_GRP_UPDATE); /* XXX */
|
fail_exit (E_GRP_UPDATE); /* XXX */
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -856,7 +898,7 @@ static void grp_update (void)
|
|||||||
nsgrp->sg_mem = add_list (nsgrp->sg_mem, user_name);
|
nsgrp->sg_mem = add_list (nsgrp->sg_mem, user_name);
|
||||||
if (sgr_update (nsgrp) == 0) {
|
if (sgr_update (nsgrp) == 0) {
|
||||||
fprintf (stderr,
|
fprintf (stderr,
|
||||||
_("%s: error adding new group entry\n"), Prog);
|
_("%s: error adding new entry to %s\n"), Prog, sgr_dbname ());
|
||||||
fail_exit (E_GRP_UPDATE);
|
fail_exit (E_GRP_UPDATE);
|
||||||
}
|
}
|
||||||
#ifdef WITH_AUDIT
|
#ifdef WITH_AUDIT
|
||||||
@ -915,11 +957,10 @@ static void process_flags (int argc, char **argv)
|
|||||||
long_options, NULL)) != -1) {
|
long_options, NULL)) != -1) {
|
||||||
switch (c) {
|
switch (c) {
|
||||||
case 'b':
|
case 'b':
|
||||||
if (!VALID (optarg)
|
if ( ( !VALID (optarg) )
|
||||||
|| optarg[0] != '/') {
|
|| ( optarg[0] != '/' )) {
|
||||||
fprintf (stderr,
|
fprintf (stderr,
|
||||||
_
|
_("%s: invalid base directory '%s'\n"),
|
||||||
("%s: invalid base directory '%s'\n"),
|
|
||||||
Prog, optarg);
|
Prog, optarg);
|
||||||
exit (E_BAD_ARG);
|
exit (E_BAD_ARG);
|
||||||
}
|
}
|
||||||
@ -929,8 +970,7 @@ static void process_flags (int argc, char **argv)
|
|||||||
case 'c':
|
case 'c':
|
||||||
if (!VALID (optarg)) {
|
if (!VALID (optarg)) {
|
||||||
fprintf (stderr,
|
fprintf (stderr,
|
||||||
_
|
_("%s: invalid comment '%s'\n"),
|
||||||
("%s: invalid comment '%s'\n"),
|
|
||||||
Prog, optarg);
|
Prog, optarg);
|
||||||
exit (E_BAD_ARG);
|
exit (E_BAD_ARG);
|
||||||
}
|
}
|
||||||
@ -938,11 +978,10 @@ static void process_flags (int argc, char **argv)
|
|||||||
cflg = true;
|
cflg = true;
|
||||||
break;
|
break;
|
||||||
case 'd':
|
case 'd':
|
||||||
if (!VALID (optarg)
|
if ( ( !VALID (optarg) )
|
||||||
|| optarg[0] != '/') {
|
|| ( optarg[0] != '/' )) {
|
||||||
fprintf (stderr,
|
fprintf (stderr,
|
||||||
_
|
_("%s: invalid home directory '%s'\n"),
|
||||||
("%s: invalid home directory '%s'\n"),
|
|
||||||
Prog, optarg);
|
Prog, optarg);
|
||||||
exit (E_BAD_ARG);
|
exit (E_BAD_ARG);
|
||||||
}
|
}
|
||||||
@ -950,8 +989,9 @@ static void process_flags (int argc, char **argv)
|
|||||||
dflg = true;
|
dflg = true;
|
||||||
break;
|
break;
|
||||||
case 'D':
|
case 'D':
|
||||||
if (anyflag)
|
if (anyflag) {
|
||||||
usage ();
|
usage ();
|
||||||
|
}
|
||||||
Dflg = true;
|
Dflg = true;
|
||||||
break;
|
break;
|
||||||
case 'e':
|
case 'e':
|
||||||
@ -959,26 +999,26 @@ static void process_flags (int argc, char **argv)
|
|||||||
user_expire = strtoday (optarg);
|
user_expire = strtoday (optarg);
|
||||||
if (user_expire == -1) {
|
if (user_expire == -1) {
|
||||||
fprintf (stderr,
|
fprintf (stderr,
|
||||||
_
|
_("%s: invalid date '%s'\n"),
|
||||||
("%s: invalid date '%s'\n"),
|
|
||||||
Prog, optarg);
|
Prog, optarg);
|
||||||
exit (E_BAD_ARG);
|
exit (E_BAD_ARG);
|
||||||
}
|
}
|
||||||
} else
|
} else {
|
||||||
user_expire = -1;
|
user_expire = -1;
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* -e "" is allowed - it's a no-op without /etc/shadow
|
* -e "" is allowed - it's a no-op without /etc/shadow
|
||||||
*/
|
*/
|
||||||
if (('\0' != *optarg) && !is_shadow_pwd) {
|
if (('\0' != *optarg) && !is_shadow_pwd) {
|
||||||
fprintf (stderr,
|
fprintf (stderr,
|
||||||
_
|
_("%s: shadow passwords required for -e\n"),
|
||||||
("%s: shadow passwords required for -e\n"),
|
|
||||||
Prog);
|
Prog);
|
||||||
exit (E_USAGE);
|
exit (E_USAGE);
|
||||||
}
|
}
|
||||||
if (Dflg)
|
if (Dflg) {
|
||||||
def_expire = optarg;
|
def_expire = optarg;
|
||||||
|
}
|
||||||
eflg = true;
|
eflg = true;
|
||||||
break;
|
break;
|
||||||
case 'f':
|
case 'f':
|
||||||
@ -1037,16 +1077,16 @@ static void process_flags (int argc, char **argv)
|
|||||||
cp = strchr (optarg, '=');
|
cp = strchr (optarg, '=');
|
||||||
if (NULL == cp) {
|
if (NULL == cp) {
|
||||||
fprintf (stderr,
|
fprintf (stderr,
|
||||||
_
|
_("%s: -K requires KEY=VALUE\n"),
|
||||||
("%s: -K requires KEY=VALUE\n"),
|
|
||||||
Prog);
|
Prog);
|
||||||
exit (E_BAD_ARG);
|
exit (E_BAD_ARG);
|
||||||
}
|
}
|
||||||
/* terminate name, point to value */
|
/* terminate name, point to value */
|
||||||
*cp = '\0';
|
*cp = '\0';
|
||||||
cp++;
|
cp++;
|
||||||
if (putdef_str (optarg, cp) < 0)
|
if (putdef_str (optarg, cp) < 0) {
|
||||||
exit (E_BAD_ARG);
|
exit (E_BAD_ARG);
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
case 'l':
|
case 'l':
|
||||||
lflg = true;
|
lflg = true;
|
||||||
@ -1063,8 +1103,7 @@ static void process_flags (int argc, char **argv)
|
|||||||
case 'p': /* set encrypted password */
|
case 'p': /* set encrypted password */
|
||||||
if (!VALID (optarg)) {
|
if (!VALID (optarg)) {
|
||||||
fprintf (stderr,
|
fprintf (stderr,
|
||||||
_
|
_("%s: invalid field '%s'\n"),
|
||||||
("%s: invalid field '%s'\n"),
|
|
||||||
Prog, optarg);
|
Prog, optarg);
|
||||||
exit (E_BAD_ARG);
|
exit (E_BAD_ARG);
|
||||||
}
|
}
|
||||||
@ -1074,13 +1113,12 @@ static void process_flags (int argc, char **argv)
|
|||||||
rflg = true;
|
rflg = true;
|
||||||
break;
|
break;
|
||||||
case 's':
|
case 's':
|
||||||
if (!VALID (optarg)
|
if ( ( !VALID (optarg) )
|
||||||
|| ( ('\0' != optarg[0])
|
|| ( ('\0' != optarg[0])
|
||||||
&& ('/' != optarg[0])
|
&& ('/' != optarg[0])
|
||||||
&& ('*' != optarg[0]))) {
|
&& ('*' != optarg[0]) )) {
|
||||||
fprintf (stderr,
|
fprintf (stderr,
|
||||||
_
|
_("%s: invalid shell '%s'\n"),
|
||||||
("%s: invalid shell '%s'\n"),
|
|
||||||
Prog, optarg);
|
Prog, optarg);
|
||||||
exit (E_BAD_ARG);
|
exit (E_BAD_ARG);
|
||||||
}
|
}
|
||||||
@ -1113,13 +1151,13 @@ static void process_flags (int argc, char **argv)
|
|||||||
*/
|
*/
|
||||||
if (oflg && !uflg) {
|
if (oflg && !uflg) {
|
||||||
fprintf (stderr,
|
fprintf (stderr,
|
||||||
_("%s: %s flag is ONLY allowed with the %s flag\n"),
|
_("%s: %s flag is only allowed with the %s flag\n"),
|
||||||
Prog, "-o", "-u");
|
Prog, "-o", "-u");
|
||||||
usage ();
|
usage ();
|
||||||
}
|
}
|
||||||
if (kflg && !mflg) {
|
if (kflg && !mflg) {
|
||||||
fprintf (stderr,
|
fprintf (stderr,
|
||||||
_("%s: %s flag is ONLY allowed with the %s flag\n"),
|
_("%s: %s flag is only allowed with the %s flag\n"),
|
||||||
Prog, "-k", "-m");
|
Prog, "-k", "-m");
|
||||||
usage ();
|
usage ();
|
||||||
}
|
}
|
||||||
@ -1141,20 +1179,22 @@ static void process_flags (int argc, char **argv)
|
|||||||
* for the -b, -e, -f, -g, -s options only.
|
* for the -b, -e, -f, -g, -s options only.
|
||||||
*/
|
*/
|
||||||
if (Dflg) {
|
if (Dflg) {
|
||||||
if (optind != argc)
|
if (optind != argc) {
|
||||||
usage ();
|
usage ();
|
||||||
|
}
|
||||||
|
|
||||||
if (uflg || oflg || Gflg || dflg || cflg || mflg)
|
if (uflg || oflg || Gflg || dflg || cflg || mflg) {
|
||||||
usage ();
|
usage ();
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
if (optind != argc - 1)
|
if (optind != argc - 1) {
|
||||||
usage ();
|
usage ();
|
||||||
|
}
|
||||||
|
|
||||||
user_name = argv[optind];
|
user_name = argv[optind];
|
||||||
if (!is_valid_user_name (user_name)) {
|
if (!is_valid_user_name (user_name)) {
|
||||||
fprintf (stderr,
|
fprintf (stderr,
|
||||||
_
|
_("%s: invalid user name '%s'\n"),
|
||||||
("%s: invalid user name '%s'\n"),
|
|
||||||
Prog, user_name);
|
Prog, user_name);
|
||||||
#ifdef WITH_AUDIT
|
#ifdef WITH_AUDIT
|
||||||
audit_logger (AUDIT_USER_CHAUTHTOK, Prog,
|
audit_logger (AUDIT_USER_CHAUTHTOK, Prog,
|
||||||
@ -1173,14 +1213,17 @@ static void process_flags (int argc, char **argv)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!eflg)
|
if (!eflg) {
|
||||||
user_expire = strtoday (def_expire);
|
user_expire = strtoday (def_expire);
|
||||||
|
}
|
||||||
|
|
||||||
if (!gflg)
|
if (!gflg) {
|
||||||
user_gid = def_group;
|
user_gid = def_group;
|
||||||
|
}
|
||||||
|
|
||||||
if (!sflg)
|
if (!sflg) {
|
||||||
user_shell = def_shell;
|
user_shell = def_shell;
|
||||||
|
}
|
||||||
|
|
||||||
/* TODO: add handle change default spool mail creation by
|
/* TODO: add handle change default spool mail creation by
|
||||||
-K CREATE_MAIL_SPOOL={yes,no}. It need rewrite internal API for handle
|
-K CREATE_MAIL_SPOOL={yes,no}. It need rewrite internal API for handle
|
||||||
@ -1197,41 +1240,80 @@ static void process_flags (int argc, char **argv)
|
|||||||
static void close_files (void)
|
static void close_files (void)
|
||||||
{
|
{
|
||||||
if (pw_close () == 0) {
|
if (pw_close () == 0) {
|
||||||
fprintf (stderr, _("%s: cannot rewrite password file\n"), Prog);
|
fprintf (stderr, _("%s: failure while writing changes to %s\n"), Prog, pw_dbname ());
|
||||||
|
SYSLOG ((LOG_WARN, "failure while writing changes to %s", pw_dbname ()));
|
||||||
fail_exit (E_PW_UPDATE);
|
fail_exit (E_PW_UPDATE);
|
||||||
}
|
}
|
||||||
if (is_shadow_pwd && (spw_close () == 0)) {
|
if (is_shadow_pwd && (spw_close () == 0)) {
|
||||||
fprintf (stderr,
|
fprintf (stderr,
|
||||||
_("%s: cannot rewrite shadow password file\n"), Prog);
|
_("%s: failure while writing changes to %s\n"), Prog, spw_dbname ());
|
||||||
|
SYSLOG ((LOG_WARN, "failure while writing changes to %s", spw_dbname ()));
|
||||||
fail_exit (E_PW_UPDATE);
|
fail_exit (E_PW_UPDATE);
|
||||||
}
|
}
|
||||||
if (do_grp_update) {
|
if (do_grp_update) {
|
||||||
if (gr_close () == 0) {
|
if (gr_close () == 0) {
|
||||||
fprintf (stderr,
|
fprintf (stderr,
|
||||||
_("%s: cannot rewrite group file\n"), Prog);
|
_("%s: failure while writing changes to %s\n"), Prog, gr_dbname ());
|
||||||
|
SYSLOG ((LOG_WARN, "failure while writing changes to %s", gr_dbname ()));
|
||||||
fail_exit (E_GRP_UPDATE);
|
fail_exit (E_GRP_UPDATE);
|
||||||
}
|
}
|
||||||
#ifdef SHADOWGRP
|
#ifdef SHADOWGRP
|
||||||
if (is_shadow_grp && (sgr_close () == 0)) {
|
if (is_shadow_grp && (sgr_close () == 0)) {
|
||||||
fprintf (stderr,
|
fprintf (stderr,
|
||||||
_
|
_("%s: failure while writing changes to %s\n"),
|
||||||
("%s: cannot rewrite shadow group file\n"),
|
Prog, sgr_dbname ());
|
||||||
Prog);
|
SYSLOG ((LOG_WARN, "failure while writing changes to %s", sgr_dbname ()));
|
||||||
fail_exit (E_GRP_UPDATE);
|
fail_exit (E_GRP_UPDATE);
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
if (is_shadow_pwd) {
|
if (is_shadow_pwd) {
|
||||||
spw_unlock ();
|
if (spw_unlock () == 0) {
|
||||||
|
fprintf (stderr, _("%s: failed to unlock %s\n"), Prog, spw_dbname ());
|
||||||
|
SYSLOG ((LOG_WARN, "failed to unlock %s", spw_dbname ()));
|
||||||
|
#ifdef WITH_AUDIT
|
||||||
|
audit_logger (AUDIT_USER_CHAUTHTOK, Prog,
|
||||||
|
"unlocking shadow file",
|
||||||
|
user_name, AUDIT_NO_ID, 0);
|
||||||
|
#endif
|
||||||
|
/* continue */
|
||||||
|
}
|
||||||
shadow_locked = false;
|
shadow_locked = false;
|
||||||
}
|
}
|
||||||
pw_unlock ();
|
if (pw_unlock () == 0) {
|
||||||
|
fprintf (stderr, _("%s: failed to unlock %s\n"), Prog, pw_dbname ());
|
||||||
|
SYSLOG ((LOG_WARN, "failed to unlock %s", pw_dbname ()));
|
||||||
|
#ifdef WITH_AUDIT
|
||||||
|
audit_logger (AUDIT_USER_CHAUTHTOK, Prog,
|
||||||
|
"unlocking passwd file",
|
||||||
|
user_name, AUDIT_NO_ID, 0);
|
||||||
|
#endif
|
||||||
|
/* continue */
|
||||||
|
}
|
||||||
passwd_locked = false;
|
passwd_locked = false;
|
||||||
gr_unlock ();
|
if (gr_unlock () == 0) {
|
||||||
|
fprintf (stderr, _("%s: failed to unlock %s\n"), Prog, gr_dbname ());
|
||||||
|
SYSLOG ((LOG_WARN, "failed to unlock %s", gr_dbname ()));
|
||||||
|
#ifdef WITH_AUDIT
|
||||||
|
audit_logger (AUDIT_USER_CHAUTHTOK, Prog,
|
||||||
|
"unlocking group file",
|
||||||
|
user_name, AUDIT_NO_ID, 0);
|
||||||
|
#endif
|
||||||
|
/* continue */
|
||||||
|
}
|
||||||
group_locked = false;
|
group_locked = false;
|
||||||
#ifdef SHADOWGRP
|
#ifdef SHADOWGRP
|
||||||
if (is_shadow_grp) {
|
if (is_shadow_grp) {
|
||||||
sgr_unlock ();
|
if (sgr_unlock () == 0) {
|
||||||
|
fprintf (stderr, _("%s: failed to unlock %s\n"), Prog, sgr_dbname ());
|
||||||
|
SYSLOG ((LOG_WARN, "failed to unlock %s", sgr_dbname ()));
|
||||||
|
#ifdef WITH_AUDIT
|
||||||
|
audit_logger (AUDIT_USER_CHAUTHTOK, Prog,
|
||||||
|
"unlocking gshadow file",
|
||||||
|
user_name, AUDIT_NO_ID, 0);
|
||||||
|
#endif
|
||||||
|
/* continue */
|
||||||
|
}
|
||||||
gshadow_locked = false;
|
gshadow_locked = false;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
@ -1245,46 +1327,26 @@ static void close_files (void)
|
|||||||
static void open_files (void)
|
static void open_files (void)
|
||||||
{
|
{
|
||||||
if (pw_lock () == 0) {
|
if (pw_lock () == 0) {
|
||||||
fprintf (stderr, _("%s: unable to lock password file\n"), Prog);
|
fprintf (stderr, _("%s: cannot lock %s\n"), Prog, pw_dbname ());
|
||||||
#ifdef WITH_AUDIT
|
|
||||||
audit_logger (AUDIT_USER_CHAUTHTOK, Prog,
|
|
||||||
"locking password file",
|
|
||||||
user_name, (unsigned int) user_id, 0);
|
|
||||||
#endif
|
|
||||||
exit (E_PW_UPDATE);
|
exit (E_PW_UPDATE);
|
||||||
}
|
}
|
||||||
passwd_locked = true;
|
passwd_locked = true;
|
||||||
if (pw_open (O_RDWR) == 0) {
|
if (pw_open (O_RDWR) == 0) {
|
||||||
fprintf (stderr, _("%s: unable to open password file\n"), Prog);
|
fprintf (stderr, _("%s: cannot open %s\n"), Prog, pw_dbname ());
|
||||||
#ifdef WITH_AUDIT
|
|
||||||
audit_logger (AUDIT_USER_CHAUTHTOK, Prog,
|
|
||||||
"opening password file",
|
|
||||||
user_name, (unsigned int) user_id, 0);
|
|
||||||
#endif
|
|
||||||
fail_exit (E_PW_UPDATE);
|
fail_exit (E_PW_UPDATE);
|
||||||
}
|
}
|
||||||
if (is_shadow_pwd) {
|
if (is_shadow_pwd) {
|
||||||
if (spw_lock () == 0) {
|
if (spw_lock () == 0) {
|
||||||
fprintf (stderr,
|
fprintf (stderr,
|
||||||
_("%s: cannot lock shadow password file\n"),
|
_("%s: cannot lock %s\n"),
|
||||||
Prog);
|
Prog, spw_dbname ());
|
||||||
#ifdef WITH_AUDIT
|
|
||||||
audit_logger (AUDIT_USER_CHAUTHTOK, Prog,
|
|
||||||
"locking shadow password file",
|
|
||||||
user_name, (unsigned int) user_id, 0);
|
|
||||||
#endif
|
|
||||||
fail_exit (E_PW_UPDATE);
|
fail_exit (E_PW_UPDATE);
|
||||||
}
|
}
|
||||||
shadow_locked = true;
|
shadow_locked = true;
|
||||||
if (spw_open (O_RDWR) == 0) {
|
if (spw_open (O_RDWR) == 0) {
|
||||||
fprintf (stderr,
|
fprintf (stderr,
|
||||||
_("%s: cannot open shadow password file\n"),
|
_("%s: cannot open %s\n"),
|
||||||
Prog);
|
Prog, spw_dbname ());
|
||||||
#ifdef WITH_AUDIT
|
|
||||||
audit_logger (AUDIT_USER_CHAUTHTOK, Prog,
|
|
||||||
"opening shadow password file",
|
|
||||||
user_name, (unsigned int) user_id, 0);
|
|
||||||
#endif
|
|
||||||
fail_exit (E_PW_UPDATE);
|
fail_exit (E_PW_UPDATE);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -1293,27 +1355,27 @@ static void open_files (void)
|
|||||||
* Lock and open the group file.
|
* Lock and open the group file.
|
||||||
*/
|
*/
|
||||||
if (gr_lock () == 0) {
|
if (gr_lock () == 0) {
|
||||||
fprintf (stderr, _("%s: error locking group file\n"), Prog);
|
fprintf (stderr, _("%s: cannot lock %s\n"), Prog, gr_dbname ());
|
||||||
fail_exit (E_GRP_UPDATE);
|
fail_exit (E_GRP_UPDATE);
|
||||||
}
|
}
|
||||||
group_locked = true;
|
group_locked = true;
|
||||||
if (gr_open (O_RDWR) == 0) {
|
if (gr_open (O_RDWR) == 0) {
|
||||||
fprintf (stderr, _("%s: error opening group file\n"), Prog);
|
fprintf (stderr, _("%s: cannot open %s\n"), Prog, gr_dbname ());
|
||||||
fail_exit (E_GRP_UPDATE);
|
fail_exit (E_GRP_UPDATE);
|
||||||
}
|
}
|
||||||
#ifdef SHADOWGRP
|
#ifdef SHADOWGRP
|
||||||
if (is_shadow_grp) {
|
if (is_shadow_grp) {
|
||||||
if (sgr_lock () == 0) {
|
if (sgr_lock () == 0) {
|
||||||
fprintf (stderr,
|
fprintf (stderr,
|
||||||
_("%s: error locking shadow group file\n"),
|
_("%s: cannot lock %s\n"),
|
||||||
Prog);
|
Prog, sgr_dbname ());
|
||||||
fail_exit (E_GRP_UPDATE);
|
fail_exit (E_GRP_UPDATE);
|
||||||
}
|
}
|
||||||
gshadow_locked = true;
|
gshadow_locked = true;
|
||||||
if (sgr_open (O_RDWR) == 0) {
|
if (sgr_open (O_RDWR) == 0) {
|
||||||
fprintf (stderr,
|
fprintf (stderr,
|
||||||
_("%s: error opening shadow group file\n"),
|
_("%s: cannot open %s\n"),
|
||||||
Prog);
|
Prog, sgr_dbname ());
|
||||||
fail_exit (E_GRP_UPDATE);
|
fail_exit (E_GRP_UPDATE);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -1419,6 +1481,8 @@ static void faillog_reset (uid_t uid)
|
|||||||
fprintf (stderr,
|
fprintf (stderr,
|
||||||
_("%s: failed to reset the faillog entry of UID %lu: %s\n"),
|
_("%s: failed to reset the faillog entry of UID %lu: %s\n"),
|
||||||
Prog, (unsigned long) uid, strerror (errno));
|
Prog, (unsigned long) uid, strerror (errno));
|
||||||
|
SYSLOG ((LOG_WARN, "failed to reset the faillog entry of UID %lu", (unsigned long) uid));
|
||||||
|
/* continue */
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1442,6 +1506,8 @@ static void lastlog_reset (uid_t uid)
|
|||||||
fprintf (stderr,
|
fprintf (stderr,
|
||||||
_("%s: failed to reset the lastlog entry of UID %lu: %s\n"),
|
_("%s: failed to reset the lastlog entry of UID %lu: %s\n"),
|
||||||
Prog, (unsigned long) uid, strerror (errno));
|
Prog, (unsigned long) uid, strerror (errno));
|
||||||
|
SYSLOG ((LOG_WARN, "failed to reset the lastlog entry of UID %lu", (unsigned long) uid));
|
||||||
|
/* continue */
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1665,19 +1731,14 @@ int main (int argc, char **argv)
|
|||||||
|
|
||||||
if (PAM_SUCCESS == retval) {
|
if (PAM_SUCCESS == retval) {
|
||||||
retval = pam_authenticate (pamh, 0);
|
retval = pam_authenticate (pamh, 0);
|
||||||
if (PAM_SUCCESS != retval) {
|
|
||||||
(void) pam_end (pamh, retval);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (PAM_SUCCESS == retval) {
|
if (PAM_SUCCESS == retval) {
|
||||||
retval = pam_acct_mgmt (pamh, 0);
|
retval = pam_acct_mgmt (pamh, 0);
|
||||||
if (PAM_SUCCESS != retval) {
|
|
||||||
(void) pam_end (pamh, retval);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (PAM_SUCCESS != retval) {
|
if (PAM_SUCCESS != retval) {
|
||||||
|
(void) pam_end (pamh, retval);
|
||||||
fprintf (stderr, _("%s: PAM authentication failed\n"), Prog);
|
fprintf (stderr, _("%s: PAM authentication failed\n"), Prog);
|
||||||
fail_exit (1);
|
fail_exit (1);
|
||||||
}
|
}
|
||||||
@ -1700,7 +1761,7 @@ int main (int argc, char **argv)
|
|||||||
* Start with a quick check to see if the user exists.
|
* Start with a quick check to see if the user exists.
|
||||||
*/
|
*/
|
||||||
if (getpwnam (user_name) != NULL) { /* local, no need for xgetpwnam */
|
if (getpwnam (user_name) != NULL) { /* local, no need for xgetpwnam */
|
||||||
fprintf (stderr, _("%s: user %s exists\n"), Prog, user_name);
|
fprintf (stderr, _("%s: user '%s' already exists\n"), Prog, user_name);
|
||||||
#ifdef WITH_AUDIT
|
#ifdef WITH_AUDIT
|
||||||
audit_logger (AUDIT_USER_CHAUTHTOK, Prog,
|
audit_logger (AUDIT_USER_CHAUTHTOK, Prog,
|
||||||
"adding user",
|
"adding user",
|
||||||
@ -1719,8 +1780,7 @@ int main (int argc, char **argv)
|
|||||||
/* local, no need for xgetgrnam */
|
/* local, no need for xgetgrnam */
|
||||||
if (getgrnam (user_name) != NULL) {
|
if (getgrnam (user_name) != NULL) {
|
||||||
fprintf (stderr,
|
fprintf (stderr,
|
||||||
_
|
_("%s: group %s exists - if you want to add this user to that group, use -g.\n"),
|
||||||
("%s: group %s exists - if you want to add this user to that group, use -g.\n"),
|
|
||||||
Prog, user_name);
|
Prog, user_name);
|
||||||
#ifdef WITH_AUDIT
|
#ifdef WITH_AUDIT
|
||||||
audit_logger (AUDIT_USER_CHAUTHTOK, Prog,
|
audit_logger (AUDIT_USER_CHAUTHTOK, Prog,
|
||||||
@ -1818,9 +1878,7 @@ int main (int argc, char **argv)
|
|||||||
nscd_flush_cache ("group");
|
nscd_flush_cache ("group");
|
||||||
|
|
||||||
#ifdef USE_PAM
|
#ifdef USE_PAM
|
||||||
if (PAM_SUCCESS == retval) {
|
|
||||||
(void) pam_end (pamh, PAM_SUCCESS);
|
(void) pam_end (pamh, PAM_SUCCESS);
|
||||||
}
|
|
||||||
#endif /* USE_PAM */
|
#endif /* USE_PAM */
|
||||||
|
|
||||||
return E_SUCCESS;
|
return E_SUCCESS;
|
||||||
|
@ -146,8 +146,9 @@ static void update_groups (void)
|
|||||||
* See if the user specified this group as one of their
|
* See if the user specified this group as one of their
|
||||||
* concurrent groups.
|
* concurrent groups.
|
||||||
*/
|
*/
|
||||||
if (!is_on_list (grp->gr_mem, user_name))
|
if (!is_on_list (grp->gr_mem, user_name)) {
|
||||||
continue;
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Delete the username from the list of group members and
|
* Delete the username from the list of group members and
|
||||||
@ -156,8 +157,8 @@ static void update_groups (void)
|
|||||||
ngrp = __gr_dup (grp);
|
ngrp = __gr_dup (grp);
|
||||||
if (NULL == ngrp) {
|
if (NULL == ngrp) {
|
||||||
fprintf (stderr,
|
fprintf (stderr,
|
||||||
_("%s: Out of memory. Cannot update the group database.\n"),
|
_("%s: Out of memory. Cannot update %s.\n"),
|
||||||
Prog);
|
Prog, gr_dbname ());
|
||||||
exit (13); /* XXX */
|
exit (13); /* XXX */
|
||||||
}
|
}
|
||||||
ngrp->gr_mem = del_list (ngrp->gr_mem, user_name);
|
ngrp->gr_mem = del_list (ngrp->gr_mem, user_name);
|
||||||
@ -202,8 +203,7 @@ static void update_groups (void)
|
|||||||
}
|
}
|
||||||
if (pwd->pw_gid == grp->gr_gid) {
|
if (pwd->pw_gid == grp->gr_gid) {
|
||||||
fprintf (stderr,
|
fprintf (stderr,
|
||||||
_
|
_("%s: Cannot remove group %s which is a primary group for another user.\n"),
|
||||||
("%s: Cannot remove group %s which is a primary group for another user.\n"),
|
|
||||||
Prog, grp->gr_name);
|
Prog, grp->gr_name);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@ -261,8 +261,8 @@ static void update_groups (void)
|
|||||||
nsgrp = __sgr_dup (sgrp);
|
nsgrp = __sgr_dup (sgrp);
|
||||||
if (NULL == nsgrp) {
|
if (NULL == nsgrp) {
|
||||||
fprintf (stderr,
|
fprintf (stderr,
|
||||||
_("%s: Out of memory. Cannot update the shadow group database.\n"),
|
_("%s: Out of memory. Cannot update %s.\n"),
|
||||||
Prog);
|
Prog, sgr_dbname ());
|
||||||
exit (13); /* XXX */
|
exit (13); /* XXX */
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -288,8 +288,9 @@ static void update_groups (void)
|
|||||||
user_name, nsgrp->sg_name));
|
user_name, nsgrp->sg_name));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (deleted_user_group)
|
if (deleted_user_group) {
|
||||||
sgr_remove (user_name);
|
sgr_remove (user_name);
|
||||||
|
}
|
||||||
#endif /* SHADOWGRP */
|
#endif /* SHADOWGRP */
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -301,19 +302,23 @@ static void update_groups (void)
|
|||||||
*/
|
*/
|
||||||
static void close_files (void)
|
static void close_files (void)
|
||||||
{
|
{
|
||||||
if (pw_close () == 0)
|
if (pw_close () == 0) {
|
||||||
fprintf (stderr, _("%s: cannot rewrite password file\n"), Prog);
|
fprintf (stderr, _("%s: failure while writing changes to %s\n"), Prog, pw_dbname ());
|
||||||
if (is_shadow_pwd && (spw_close () == 0))
|
}
|
||||||
|
if (is_shadow_pwd && (spw_close () == 0)) {
|
||||||
fprintf (stderr,
|
fprintf (stderr,
|
||||||
_("%s: cannot rewrite shadow password file\n"), Prog);
|
_("%s: failure while writing changes to %s\n"), Prog, spw_dbname ());
|
||||||
if (gr_close () == 0)
|
}
|
||||||
fprintf (stderr, _("%s: cannot rewrite group file\n"), Prog);
|
if (gr_close () == 0) {
|
||||||
|
fprintf (stderr, _("%s: failure while writing changes to %s\n"), Prog, gr_dbname ());
|
||||||
|
}
|
||||||
|
|
||||||
gr_unlock ();
|
gr_unlock ();
|
||||||
#ifdef SHADOWGRP
|
#ifdef SHADOWGRP
|
||||||
if (is_shadow_grp && (sgr_close () == 0))
|
if (is_shadow_grp && (sgr_close () == 0)) {
|
||||||
fprintf (stderr,
|
fprintf (stderr,
|
||||||
_("%s: cannot rewrite shadow group file\n"), Prog);
|
_("%s: failure while writing changes to %s\n"), Prog, sgr_dbname ());
|
||||||
|
}
|
||||||
|
|
||||||
if (is_shadow_grp) {
|
if (is_shadow_grp) {
|
||||||
sgr_unlock ();
|
sgr_unlock ();
|
||||||
@ -357,7 +362,7 @@ static void fail_exit (int code)
|
|||||||
static void open_files (void)
|
static void open_files (void)
|
||||||
{
|
{
|
||||||
if (pw_lock () == 0) {
|
if (pw_lock () == 0) {
|
||||||
fprintf (stderr, _("%s: unable to lock password file\n"), Prog);
|
fprintf (stderr, _("%s: cannot lock %s\n"), Prog, pw_dbname ());
|
||||||
#ifdef WITH_AUDIT
|
#ifdef WITH_AUDIT
|
||||||
audit_logger (AUDIT_USER_CHAUTHTOK, Prog,
|
audit_logger (AUDIT_USER_CHAUTHTOK, Prog,
|
||||||
"locking password file",
|
"locking password file",
|
||||||
@ -366,7 +371,8 @@ static void open_files (void)
|
|||||||
exit (E_PW_UPDATE);
|
exit (E_PW_UPDATE);
|
||||||
}
|
}
|
||||||
if (pw_open (O_RDWR) == 0) {
|
if (pw_open (O_RDWR) == 0) {
|
||||||
fprintf (stderr, _("%s: unable to open password file\n"), Prog);
|
fprintf (stderr,
|
||||||
|
_("%s: cannot open %s\n"), Prog, pw_dbname ());
|
||||||
#ifdef WITH_AUDIT
|
#ifdef WITH_AUDIT
|
||||||
audit_logger (AUDIT_USER_CHAUTHTOK, Prog,
|
audit_logger (AUDIT_USER_CHAUTHTOK, Prog,
|
||||||
"opening password file",
|
"opening password file",
|
||||||
@ -376,7 +382,7 @@ static void open_files (void)
|
|||||||
}
|
}
|
||||||
if (is_shadow_pwd && (spw_lock () == 0)) {
|
if (is_shadow_pwd && (spw_lock () == 0)) {
|
||||||
fprintf (stderr,
|
fprintf (stderr,
|
||||||
_("%s: cannot lock shadow password file\n"), Prog);
|
_("%s: cannot lock %s\n"), Prog, spw_dbname ());
|
||||||
#ifdef WITH_AUDIT
|
#ifdef WITH_AUDIT
|
||||||
audit_logger (AUDIT_USER_CHAUTHTOK, Prog,
|
audit_logger (AUDIT_USER_CHAUTHTOK, Prog,
|
||||||
"locking shadow password file",
|
"locking shadow password file",
|
||||||
@ -386,7 +392,7 @@ static void open_files (void)
|
|||||||
}
|
}
|
||||||
if (is_shadow_pwd && (spw_open (O_RDWR) == 0)) {
|
if (is_shadow_pwd && (spw_open (O_RDWR) == 0)) {
|
||||||
fprintf (stderr,
|
fprintf (stderr,
|
||||||
_("%s: cannot open shadow password file\n"), Prog);
|
_("%s: cannot open %s\n"), Prog, spw_dbname ());
|
||||||
#ifdef WITH_AUDIT
|
#ifdef WITH_AUDIT
|
||||||
audit_logger (AUDIT_USER_CHAUTHTOK, Prog,
|
audit_logger (AUDIT_USER_CHAUTHTOK, Prog,
|
||||||
"opening shadow password file",
|
"opening shadow password file",
|
||||||
@ -395,7 +401,8 @@ static void open_files (void)
|
|||||||
fail_exit (E_PW_UPDATE);
|
fail_exit (E_PW_UPDATE);
|
||||||
}
|
}
|
||||||
if (gr_lock () == 0) {
|
if (gr_lock () == 0) {
|
||||||
fprintf (stderr, _("%s: unable to lock group file\n"), Prog);
|
fprintf (stderr,
|
||||||
|
_("%s: cannot lock %s\n"), Prog, gr_dbname ());
|
||||||
#ifdef WITH_AUDIT
|
#ifdef WITH_AUDIT
|
||||||
audit_logger (AUDIT_USER_CHAUTHTOK, Prog,
|
audit_logger (AUDIT_USER_CHAUTHTOK, Prog,
|
||||||
"locking group file",
|
"locking group file",
|
||||||
@ -404,7 +411,7 @@ static void open_files (void)
|
|||||||
fail_exit (E_GRP_UPDATE);
|
fail_exit (E_GRP_UPDATE);
|
||||||
}
|
}
|
||||||
if (gr_open (O_RDWR) == 0) {
|
if (gr_open (O_RDWR) == 0) {
|
||||||
fprintf (stderr, _("%s: cannot open group file\n"), Prog);
|
fprintf (stderr, _("%s: cannot open %s\n"), Prog, gr_dbname ());
|
||||||
#ifdef WITH_AUDIT
|
#ifdef WITH_AUDIT
|
||||||
audit_logger (AUDIT_USER_CHAUTHTOK, Prog,
|
audit_logger (AUDIT_USER_CHAUTHTOK, Prog,
|
||||||
"opening group file",
|
"opening group file",
|
||||||
@ -415,7 +422,7 @@ static void open_files (void)
|
|||||||
#ifdef SHADOWGRP
|
#ifdef SHADOWGRP
|
||||||
if (is_shadow_grp && (sgr_lock () == 0)) {
|
if (is_shadow_grp && (sgr_lock () == 0)) {
|
||||||
fprintf (stderr,
|
fprintf (stderr,
|
||||||
_("%s: unable to lock shadow group file\n"), Prog);
|
_("%s: cannot lock %s\n"), Prog, sgr_dbname ());
|
||||||
#ifdef WITH_AUDIT
|
#ifdef WITH_AUDIT
|
||||||
audit_logger (AUDIT_USER_CHAUTHTOK, Prog,
|
audit_logger (AUDIT_USER_CHAUTHTOK, Prog,
|
||||||
"locking shadow group file",
|
"locking shadow group file",
|
||||||
@ -424,8 +431,8 @@ static void open_files (void)
|
|||||||
fail_exit (E_GRP_UPDATE);
|
fail_exit (E_GRP_UPDATE);
|
||||||
}
|
}
|
||||||
if (is_shadow_grp && (sgr_open (O_RDWR) == 0)) {
|
if (is_shadow_grp && (sgr_open (O_RDWR) == 0)) {
|
||||||
fprintf (stderr, _("%s: cannot open shadow group file\n"),
|
fprintf (stderr, _("%s: cannot open %s\n"),
|
||||||
Prog);
|
Prog, sgr_dbname ());
|
||||||
#ifdef WITH_AUDIT
|
#ifdef WITH_AUDIT
|
||||||
audit_logger (AUDIT_USER_CHAUTHTOK, Prog,
|
audit_logger (AUDIT_USER_CHAUTHTOK, Prog,
|
||||||
"opening shadow group file",
|
"opening shadow group file",
|
||||||
@ -446,12 +453,14 @@ static void update_user (void)
|
|||||||
{
|
{
|
||||||
if (pw_remove (user_name) == 0) {
|
if (pw_remove (user_name) == 0) {
|
||||||
fprintf (stderr,
|
fprintf (stderr,
|
||||||
_("%s: error deleting password entry\n"), Prog);
|
_("%s: cannot remove entry '%s' from %s\n"),
|
||||||
|
Prog, user_name, pw_dbname ());
|
||||||
fail_exit (E_PW_UPDATE);
|
fail_exit (E_PW_UPDATE);
|
||||||
}
|
}
|
||||||
if (is_shadow_pwd && (spw_remove (user_name) == 0)) {
|
if (is_shadow_pwd && (spw_remove (user_name) == 0)) {
|
||||||
fprintf (stderr,
|
fprintf (stderr,
|
||||||
_("%s: error deleting shadow password entry\n"), Prog);
|
_("%s: cannot remove entry '%s' from %s\n"),
|
||||||
|
Prog, user_name, spw_dbname ());
|
||||||
fail_exit (E_PW_UPDATE);
|
fail_exit (E_PW_UPDATE);
|
||||||
}
|
}
|
||||||
#ifdef WITH_AUDIT
|
#ifdef WITH_AUDIT
|
||||||
@ -709,21 +718,16 @@ int main (int argc, char **argv)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (retval == PAM_SUCCESS) {
|
if (PAM_SUCCESS == retval) {
|
||||||
retval = pam_authenticate (pamh, 0);
|
retval = pam_authenticate (pamh, 0);
|
||||||
if (retval != PAM_SUCCESS) {
|
|
||||||
(void) pam_end (pamh, retval);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (retval == PAM_SUCCESS) {
|
if (PAM_SUCCESS == retval) {
|
||||||
retval = pam_acct_mgmt (pamh, 0);
|
retval = pam_acct_mgmt (pamh, 0);
|
||||||
if (retval != PAM_SUCCESS) {
|
|
||||||
(void) pam_end (pamh, retval);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (retval != PAM_SUCCESS) {
|
if (PAM_SUCCESS != retval) {
|
||||||
|
(void) pam_end (pamh, retval);
|
||||||
fprintf (stderr, _("%s: PAM authentication failed\n"), Prog);
|
fprintf (stderr, _("%s: PAM authentication failed\n"), Prog);
|
||||||
exit (E_PW_UPDATE);
|
exit (E_PW_UPDATE);
|
||||||
}
|
}
|
||||||
@ -858,9 +862,7 @@ int main (int argc, char **argv)
|
|||||||
nscd_flush_cache ("group");
|
nscd_flush_cache ("group");
|
||||||
|
|
||||||
#ifdef USE_PAM
|
#ifdef USE_PAM
|
||||||
if (retval == PAM_SUCCESS) {
|
|
||||||
(void) pam_end (pamh, PAM_SUCCESS);
|
(void) pam_end (pamh, PAM_SUCCESS);
|
||||||
}
|
|
||||||
#endif /* USE_PAM */
|
#endif /* USE_PAM */
|
||||||
#ifdef WITH_AUDIT
|
#ifdef WITH_AUDIT
|
||||||
if (0 != errors) {
|
if (0 != errors) {
|
||||||
|
114
src/usermod.c
114
src/usermod.c
@ -279,8 +279,7 @@ static int get_groups (char *list)
|
|||||||
|
|
||||||
if (ngroups == sys_ngroups) {
|
if (ngroups == sys_ngroups) {
|
||||||
fprintf (stderr,
|
fprintf (stderr,
|
||||||
_
|
_("%s: too many groups specified (max %d).\n"),
|
||||||
("%s: too many groups specified (max %d).\n"),
|
|
||||||
Prog, ngroups);
|
Prog, ngroups);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@ -358,8 +357,8 @@ static char *new_pw_passwd (char *pw_pass)
|
|||||||
|
|
||||||
if (pw_pass[1] == '\0') {
|
if (pw_pass[1] == '\0') {
|
||||||
fprintf (stderr,
|
fprintf (stderr,
|
||||||
_("%s: unlocking the user would result in a passwordless account.\n"
|
_("%s: unlocking the user's password would result in a passwordless account.\n"
|
||||||
"You should set a password with usermod -p to unlock this user account.\n"),
|
"You should set a password with usermod -p to unlock this user's password.\n"),
|
||||||
Prog);
|
Prog);
|
||||||
return pw_pass;
|
return pw_pass;
|
||||||
}
|
}
|
||||||
@ -569,8 +568,8 @@ static void update_group (void)
|
|||||||
ngrp = __gr_dup (grp);
|
ngrp = __gr_dup (grp);
|
||||||
if (NULL == ngrp) {
|
if (NULL == ngrp) {
|
||||||
fprintf (stderr,
|
fprintf (stderr,
|
||||||
_("%s: Out of memory. Cannot update the group database.\n"),
|
_("%s: Out of memory. Cannot update %s.\n"),
|
||||||
Prog);
|
Prog, gr_dbname ());
|
||||||
fail_exit (E_GRP_UPDATE);
|
fail_exit (E_GRP_UPDATE);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -619,8 +618,9 @@ static void update_group (void)
|
|||||||
changed = false;
|
changed = false;
|
||||||
if (gr_update (ngrp) == 0) {
|
if (gr_update (ngrp) == 0) {
|
||||||
fprintf (stderr,
|
fprintf (stderr,
|
||||||
_("%s: error adding new group entry\n"), Prog);
|
_("%s: error adding new entry '%s' in %s\n"),
|
||||||
SYSLOG ((LOG_ERR, "error adding new group entry"));
|
Prog, ngrp->gr_name, gr_dbname ());
|
||||||
|
SYSLOG ((LOG_ERR, "error adding new entry '%s' in %s", ngrp->gr_name, gr_dbname ()));
|
||||||
fail_exit (E_GRP_UPDATE);
|
fail_exit (E_GRP_UPDATE);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -669,8 +669,8 @@ static void update_gshadow (void)
|
|||||||
nsgrp = __sgr_dup (sgrp);
|
nsgrp = __sgr_dup (sgrp);
|
||||||
if (NULL == nsgrp) {
|
if (NULL == nsgrp) {
|
||||||
fprintf (stderr,
|
fprintf (stderr,
|
||||||
_("%s: Out of memory. Cannot update the shadow group database.\n"),
|
_("%s: Out of memory. Cannot update %s.\n"),
|
||||||
Prog);
|
Prog, sgr_dbname ());
|
||||||
fail_exit (E_GRP_UPDATE);
|
fail_exit (E_GRP_UPDATE);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -737,8 +737,10 @@ static void update_gshadow (void)
|
|||||||
*/
|
*/
|
||||||
if (sgr_update (nsgrp) == 0) {
|
if (sgr_update (nsgrp) == 0) {
|
||||||
fprintf (stderr,
|
fprintf (stderr,
|
||||||
_("%s: error adding new shadow group entry\n"), Prog);
|
_("%s: error adding new entry '%s' in '%s\n"),
|
||||||
SYSLOG ((LOG_ERR, "error adding shadow group entry"));
|
Prog, nsgrp->sg_name, sgr_dbname ());
|
||||||
|
SYSLOG ((LOG_ERR, "error adding new entry '%s' in %s",
|
||||||
|
nsgrp->sg_name, sgr_dbname ()));
|
||||||
fail_exit (E_GRP_UPDATE);
|
fail_exit (E_GRP_UPDATE);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -1048,7 +1050,7 @@ static void process_flags (int argc, char **argv)
|
|||||||
|
|
||||||
if (aflg && (!Gflg)) {
|
if (aflg && (!Gflg)) {
|
||||||
fprintf (stderr,
|
fprintf (stderr,
|
||||||
_("%s: %s flag is ONLY allowed with the %s flag\n"),
|
_("%s: %s flag is only allowed with the %s flag\n"),
|
||||||
Prog, "-a", "-G");
|
Prog, "-a", "-G");
|
||||||
usage ();
|
usage ();
|
||||||
exit (E_USAGE);
|
exit (E_USAGE);
|
||||||
@ -1064,7 +1066,7 @@ static void process_flags (int argc, char **argv)
|
|||||||
|
|
||||||
if (oflg && !uflg) {
|
if (oflg && !uflg) {
|
||||||
fprintf (stderr,
|
fprintf (stderr,
|
||||||
_("%s: %s flag is ONLY allowed with the %s flag\n"),
|
_("%s: %s flag is only allowed with the %s flag\n"),
|
||||||
Prog, "-o", "-u");
|
Prog, "-o", "-u");
|
||||||
usage ();
|
usage ();
|
||||||
exit (E_USAGE);
|
exit (E_USAGE);
|
||||||
@ -1072,7 +1074,7 @@ static void process_flags (int argc, char **argv)
|
|||||||
|
|
||||||
if (mflg && !dflg) {
|
if (mflg && !dflg) {
|
||||||
fprintf (stderr,
|
fprintf (stderr,
|
||||||
_("%s: %s flag is ONLY allowed with the %s flag\n"),
|
_("%s: %s flag is only allowed with the %s flag\n"),
|
||||||
Prog, "-m", "-d");
|
Prog, "-m", "-d");
|
||||||
usage ();
|
usage ();
|
||||||
exit (E_USAGE);
|
exit (E_USAGE);
|
||||||
@ -1080,13 +1082,13 @@ static void process_flags (int argc, char **argv)
|
|||||||
|
|
||||||
/* local, no need for xgetpwnam */
|
/* local, no need for xgetpwnam */
|
||||||
if (lflg && (getpwnam (user_newname) != NULL)) {
|
if (lflg && (getpwnam (user_newname) != NULL)) {
|
||||||
fprintf (stderr, _("%s: user %s exists\n"), Prog, user_newname);
|
fprintf (stderr, _("%s: user '%s' already exists\n"), Prog, user_newname);
|
||||||
exit (E_NAME_IN_USE);
|
exit (E_NAME_IN_USE);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* local, no need for xgetpwuid */
|
/* local, no need for xgetpwuid */
|
||||||
if (uflg && !oflg && (getpwuid (user_newid) != NULL)) {
|
if (uflg && !oflg && (getpwuid (user_newid) != NULL)) {
|
||||||
fprintf (stderr, _("%s: uid %lu is not unique\n"),
|
fprintf (stderr, _("%s: UID '%lu' already exists\n"),
|
||||||
Prog, (unsigned long) user_newid);
|
Prog, (unsigned long) user_newid);
|
||||||
exit (E_UID_IN_USE);
|
exit (E_UID_IN_USE);
|
||||||
}
|
}
|
||||||
@ -1101,26 +1103,28 @@ static void process_flags (int argc, char **argv)
|
|||||||
static void close_files (void)
|
static void close_files (void)
|
||||||
{
|
{
|
||||||
if (pw_close () == 0) {
|
if (pw_close () == 0) {
|
||||||
fprintf (stderr, _("%s: cannot rewrite password file\n"), Prog);
|
fprintf (stderr,
|
||||||
|
_("%s: failure while writing changes to %s\n"), Prog, pw_dbname ());
|
||||||
fail_exit (E_PW_UPDATE);
|
fail_exit (E_PW_UPDATE);
|
||||||
}
|
}
|
||||||
if (is_shadow_pwd && (spw_close () == 0)) {
|
if (is_shadow_pwd && (spw_close () == 0)) {
|
||||||
fprintf (stderr,
|
fprintf (stderr,
|
||||||
_("%s: cannot rewrite shadow password file\n"), Prog);
|
_("%s: failure while writing changes to %s\n"), Prog, spw_dbname ());
|
||||||
fail_exit (E_PW_UPDATE);
|
fail_exit (E_PW_UPDATE);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (Gflg || lflg) {
|
if (Gflg || lflg) {
|
||||||
if (gr_close () == 0) {
|
if (gr_close () == 0) {
|
||||||
fprintf (stderr, _("%s: cannot rewrite group file\n"),
|
fprintf (stderr,
|
||||||
Prog);
|
_("%s: failure while writing changes to %s\n"),
|
||||||
|
Prog, gr_dbname ());
|
||||||
fail_exit (E_GRP_UPDATE);
|
fail_exit (E_GRP_UPDATE);
|
||||||
}
|
}
|
||||||
#ifdef SHADOWGRP
|
#ifdef SHADOWGRP
|
||||||
if (is_shadow_grp && (sgr_close () == 0)) {
|
if (is_shadow_grp && (sgr_close () == 0)) {
|
||||||
fprintf (stderr,
|
fprintf (stderr,
|
||||||
_("%s: cannot rewrite shadow group file\n"),
|
_("%s: failure while writing changes to %s\n"),
|
||||||
Prog);
|
Prog, sgr_dbname ());
|
||||||
fail_exit (E_GRP_UPDATE);
|
fail_exit (E_GRP_UPDATE);
|
||||||
}
|
}
|
||||||
if (is_shadow_grp) {
|
if (is_shadow_grp) {
|
||||||
@ -1161,23 +1165,25 @@ static void close_files (void)
|
|||||||
static void open_files (void)
|
static void open_files (void)
|
||||||
{
|
{
|
||||||
if (pw_lock () == 0) {
|
if (pw_lock () == 0) {
|
||||||
fprintf (stderr, _("%s: unable to lock password file\n"), Prog);
|
fprintf (stderr,
|
||||||
|
_("%s: cannot lock %s\n"), Prog, pw_dbname ());
|
||||||
fail_exit (E_PW_UPDATE);
|
fail_exit (E_PW_UPDATE);
|
||||||
}
|
}
|
||||||
pw_locked = true;
|
pw_locked = true;
|
||||||
if (pw_open (O_RDWR) == 0) {
|
if (pw_open (O_RDWR) == 0) {
|
||||||
fprintf (stderr, _("%s: unable to open password file\n"), Prog);
|
fprintf (stderr,
|
||||||
|
_("%s: cannot open %s\n"), Prog, pw_dbname ());
|
||||||
fail_exit (E_PW_UPDATE);
|
fail_exit (E_PW_UPDATE);
|
||||||
}
|
}
|
||||||
if (is_shadow_pwd && (spw_lock () == 0)) {
|
if (is_shadow_pwd && (spw_lock () == 0)) {
|
||||||
fprintf (stderr,
|
fprintf (stderr,
|
||||||
_("%s: cannot lock shadow password file\n"), Prog);
|
_("%s: cannot lock %s\n"), Prog, spw_dbname ());
|
||||||
fail_exit (E_PW_UPDATE);
|
fail_exit (E_PW_UPDATE);
|
||||||
}
|
}
|
||||||
spw_locked = true;
|
spw_locked = true;
|
||||||
if (is_shadow_pwd && (spw_open (O_RDWR) == 0)) {
|
if (is_shadow_pwd && (spw_open (O_RDWR) == 0)) {
|
||||||
fprintf (stderr,
|
fprintf (stderr,
|
||||||
_("%s: cannot open shadow password file\n"), Prog);
|
_("%s: cannot open %s\n"), Prog, spw_dbname ());
|
||||||
fail_exit (E_PW_UPDATE);
|
fail_exit (E_PW_UPDATE);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1187,28 +1193,26 @@ static void open_files (void)
|
|||||||
* group entries.
|
* group entries.
|
||||||
*/
|
*/
|
||||||
if (gr_lock () == 0) {
|
if (gr_lock () == 0) {
|
||||||
fprintf (stderr, _("%s: error locking group file\n"),
|
fprintf (stderr,
|
||||||
Prog);
|
_("%s: cannot lock %s\n"), Prog, gr_dbname ());
|
||||||
fail_exit (E_GRP_UPDATE);
|
fail_exit (E_GRP_UPDATE);
|
||||||
}
|
}
|
||||||
gr_locked = true;
|
gr_locked = true;
|
||||||
if (gr_open (O_RDWR) == 0) {
|
if (gr_open (O_RDWR) == 0) {
|
||||||
fprintf (stderr, _("%s: error opening group file\n"),
|
fprintf (stderr,
|
||||||
Prog);
|
_("%s: cannot open %s\n"), Prog, gr_dbname ());
|
||||||
fail_exit (E_GRP_UPDATE);
|
fail_exit (E_GRP_UPDATE);
|
||||||
}
|
}
|
||||||
#ifdef SHADOWGRP
|
#ifdef SHADOWGRP
|
||||||
if (is_shadow_grp && (sgr_lock () == 0)) {
|
if (is_shadow_grp && (sgr_lock () == 0)) {
|
||||||
fprintf (stderr,
|
fprintf (stderr,
|
||||||
_("%s: error locking shadow group file\n"),
|
_("%s: cannot lock %s\n"), Prog, sgr_dbname ());
|
||||||
Prog);
|
|
||||||
fail_exit (E_GRP_UPDATE);
|
fail_exit (E_GRP_UPDATE);
|
||||||
}
|
}
|
||||||
sgr_locked = true;
|
sgr_locked = true;
|
||||||
if (is_shadow_grp && (sgr_open (O_RDWR) == 0)) {
|
if (is_shadow_grp && (sgr_open (O_RDWR) == 0)) {
|
||||||
fprintf (stderr,
|
fprintf (stderr,
|
||||||
_("%s: error opening shadow group file\n"),
|
_("%s: cannot open %s\n"), Prog, sgr_dbname ());
|
||||||
Prog);
|
|
||||||
fail_exit (E_GRP_UPDATE);
|
fail_exit (E_GRP_UPDATE);
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
@ -1234,8 +1238,8 @@ static void usr_update (void)
|
|||||||
*/
|
*/
|
||||||
pwd = pw_locate (user_name);
|
pwd = pw_locate (user_name);
|
||||||
if (NULL == pwd) {
|
if (NULL == pwd) {
|
||||||
fprintf (stderr, _("%s: %s not found in /etc/passwd\n"),
|
fprintf (stderr, _("%s: user '%s' does not exist in %s\n"),
|
||||||
Prog, user_name);
|
Prog, user_name, pw_dbname ());
|
||||||
fail_exit (E_NOTFOUND);
|
fail_exit (E_NOTFOUND);
|
||||||
}
|
}
|
||||||
pwent = *pwd;
|
pwent = *pwd;
|
||||||
@ -1255,30 +1259,28 @@ static void usr_update (void)
|
|||||||
|| Lflg || Uflg) {
|
|| Lflg || Uflg) {
|
||||||
if (pw_update (&pwent) == 0) {
|
if (pw_update (&pwent) == 0) {
|
||||||
fprintf (stderr,
|
fprintf (stderr,
|
||||||
_("%s: error changing password entry\n"),
|
_("%s: cannot add new entry '%s' in %s\n"),
|
||||||
Prog);
|
Prog, pwent.pw_name, pw_dbname ());
|
||||||
fail_exit (E_PW_UPDATE);
|
fail_exit (E_PW_UPDATE);
|
||||||
}
|
}
|
||||||
if (lflg && (pw_remove (user_name) == 0)) {
|
if (lflg && (pw_remove (user_name) == 0)) {
|
||||||
fprintf (stderr,
|
fprintf (stderr,
|
||||||
_("%s: error removing password entry\n"),
|
_("%s: cannot remove entry '%s' from %s\n"),
|
||||||
Prog);
|
Prog, user_name, pw_dbname ());
|
||||||
fail_exit (E_PW_UPDATE);
|
fail_exit (E_PW_UPDATE);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if ((NULL != spwd) && (lflg || eflg || fflg || pflg || Lflg || Uflg)) {
|
if ((NULL != spwd) && (lflg || eflg || fflg || pflg || Lflg || Uflg)) {
|
||||||
if (spw_update (&spent) == 0) {
|
if (spw_update (&spent) == 0) {
|
||||||
fprintf (stderr,
|
fprintf (stderr,
|
||||||
_
|
_("%s: cannot add new entry '%s' in %s\n"),
|
||||||
("%s: error adding new shadow password entry\n"),
|
Prog, spent.sp_namp, spw_dbname ());
|
||||||
Prog);
|
|
||||||
fail_exit (E_PW_UPDATE);
|
fail_exit (E_PW_UPDATE);
|
||||||
}
|
}
|
||||||
if (lflg && (spw_remove (user_name) == 0)) {
|
if (lflg && (spw_remove (user_name) == 0)) {
|
||||||
fprintf (stderr,
|
fprintf (stderr,
|
||||||
_
|
_("%s: cannot remove entry '%s' from %s\n"),
|
||||||
("%s: error removing shadow password entry\n"),
|
Prog, user_name, spw_dbname ());
|
||||||
Prog);
|
|
||||||
fail_exit (E_PW_UPDATE);
|
fail_exit (E_PW_UPDATE);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -1311,8 +1313,7 @@ static void move_home (void)
|
|||||||
if (errno == EXDEV) {
|
if (errno == EXDEV) {
|
||||||
if (mkdir (user_newhome, sb.st_mode & 0777) != 0) {
|
if (mkdir (user_newhome, sb.st_mode & 0777) != 0) {
|
||||||
fprintf (stderr,
|
fprintf (stderr,
|
||||||
_
|
_("%s: can't create %s\n"),
|
||||||
("%s: can't create %s\n"),
|
|
||||||
Prog, user_newhome);
|
Prog, user_newhome);
|
||||||
}
|
}
|
||||||
if (chown (user_newhome, sb.st_uid, sb.st_gid) != 0) {
|
if (chown (user_newhome, sb.st_uid, sb.st_gid) != 0) {
|
||||||
@ -1347,8 +1348,7 @@ static void move_home (void)
|
|||||||
(void) remove_tree (user_newhome);
|
(void) remove_tree (user_newhome);
|
||||||
}
|
}
|
||||||
fprintf (stderr,
|
fprintf (stderr,
|
||||||
_
|
_("%s: cannot rename directory %s to %s\n"),
|
||||||
("%s: cannot rename directory %s to %s\n"),
|
|
||||||
Prog, user_home, user_newhome);
|
Prog, user_home, user_newhome);
|
||||||
fail_exit (E_HOMEDIR);
|
fail_exit (E_HOMEDIR);
|
||||||
}
|
}
|
||||||
@ -1523,8 +1523,9 @@ static void move_mailbox (void)
|
|||||||
fd = open (mailfile, O_RDONLY | O_NONBLOCK, 0);
|
fd = open (mailfile, O_RDONLY | O_NONBLOCK, 0);
|
||||||
if (fd < 0) {
|
if (fd < 0) {
|
||||||
/* no need for warnings if the mailbox doesn't exist */
|
/* no need for warnings if the mailbox doesn't exist */
|
||||||
if (errno != ENOENT)
|
if (errno != ENOENT) {
|
||||||
perror (mailfile);
|
perror (mailfile);
|
||||||
|
}
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (fstat (fd, &st) < 0) {
|
if (fstat (fd, &st) < 0) {
|
||||||
@ -1626,19 +1627,14 @@ int main (int argc, char **argv)
|
|||||||
|
|
||||||
if (PAM_SUCCESS == retval) {
|
if (PAM_SUCCESS == retval) {
|
||||||
retval = pam_authenticate (pamh, 0);
|
retval = pam_authenticate (pamh, 0);
|
||||||
if (PAM_SUCCESS != retval) {
|
|
||||||
(void) pam_end (pamh, retval);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (PAM_SUCCESS == retval) {
|
if (PAM_SUCCESS == retval) {
|
||||||
retval = pam_acct_mgmt (pamh, 0);
|
retval = pam_acct_mgmt (pamh, 0);
|
||||||
if (PAM_SUCCESS != retval) {
|
|
||||||
(void) pam_end (pamh, retval);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (PAM_SUCCESS != retval) {
|
if (PAM_SUCCESS != retval) {
|
||||||
|
(void) pam_end (pamh, retval);
|
||||||
fprintf (stderr, _("%s: PAM authentication failed\n"), Prog);
|
fprintf (stderr, _("%s: PAM authentication failed\n"), Prog);
|
||||||
exit (1);
|
exit (1);
|
||||||
}
|
}
|
||||||
@ -1685,9 +1681,7 @@ int main (int argc, char **argv)
|
|||||||
}
|
}
|
||||||
|
|
||||||
#ifdef USE_PAM
|
#ifdef USE_PAM
|
||||||
if (PAM_SUCCESS == retval) {
|
|
||||||
(void) pam_end (pamh, PAM_SUCCESS);
|
(void) pam_end (pamh, PAM_SUCCESS);
|
||||||
}
|
|
||||||
#endif /* USE_PAM */
|
#endif /* USE_PAM */
|
||||||
|
|
||||||
exit (E_SUCCESS);
|
exit (E_SUCCESS);
|
||||||
|
Loading…
Reference in New Issue
Block a user