* src/usermod.c: Use a bool when possible instead of int integers.
* src/usermod.c: Add brackets and parenthesis. * src/usermod.c: Avoid implicit conversion of pointers / integers / chars to booleans. * src/usermod.c: Avoid assignments in comparisons. * src/usermod.c: Ignore return value of setlocale(), bindtextdomain(), and textdomain(). * src/usermod.c: Ignore the return value of pam_end() before exiting.
This commit is contained in:
parent
d48973bbc8
commit
a9f1ce0db1
12
ChangeLog
12
ChangeLog
@ -1,3 +1,15 @@
|
|||||||
|
2008-06-09 Nicolas François <nicolas.francois@centraliens.net>
|
||||||
|
|
||||||
|
* src/usermod.c: Use a bool when possible instead of int integers.
|
||||||
|
* src/usermod.c: Add brackets and parenthesis.
|
||||||
|
* src/usermod.c: Avoid implicit conversion of pointers / integers
|
||||||
|
/ chars to booleans.
|
||||||
|
* src/usermod.c: Avoid assignments in comparisons.
|
||||||
|
* src/usermod.c: Ignore return value of setlocale(),
|
||||||
|
bindtextdomain(), and textdomain().
|
||||||
|
* src/usermod.c: Ignore the return value of pam_end() before
|
||||||
|
exiting.
|
||||||
|
|
||||||
2008-06-09 Nicolas François <nicolas.francois@centraliens.net>
|
2008-06-09 Nicolas François <nicolas.francois@centraliens.net>
|
||||||
|
|
||||||
* src/groupmems.c: Move the declaration of option_index and
|
* src/groupmems.c: Move the declaration of option_index and
|
||||||
|
361
src/usermod.c
361
src/usermod.c
@ -104,34 +104,34 @@ static char **user_groups; /* NULL-terminated list */
|
|||||||
|
|
||||||
static char *Prog;
|
static char *Prog;
|
||||||
|
|
||||||
static int
|
static bool
|
||||||
aflg = 0, /* append to existing secondary group set */
|
aflg = false, /* append to existing secondary group set */
|
||||||
cflg = 0, /* new comment (GECOS) field */
|
cflg = false, /* new comment (GECOS) field */
|
||||||
dflg = 0, /* new home directory */
|
dflg = false, /* new home directory */
|
||||||
eflg = 0, /* days since 1970-01-01 when account becomes expired */
|
eflg = false, /* days since 1970-01-01 when account becomes expired */
|
||||||
fflg = 0, /* days until account with expired password is locked */
|
fflg = false, /* days until account with expired password is locked */
|
||||||
gflg = 0, /* new primary group ID */
|
gflg = false, /* new primary group ID */
|
||||||
Gflg = 0, /* new secondary group set */
|
Gflg = false, /* new secondary group set */
|
||||||
Lflg = 0, /* lock the password */
|
Lflg = false, /* lock the password */
|
||||||
lflg = 0, /* new user name */
|
lflg = false, /* new user name */
|
||||||
mflg = 0, /* create user's home directory if it doesn't exist */
|
mflg = false, /* create user's home directory if it doesn't exist */
|
||||||
oflg = 0, /* permit non-unique user ID to be specified with -u */
|
oflg = false, /* permit non-unique user ID to be specified with -u */
|
||||||
pflg = 0, /* new encrypted password */
|
pflg = false, /* new encrypted password */
|
||||||
sflg = 0, /* new shell program */
|
sflg = false, /* new shell program */
|
||||||
uflg = 0, /* specify new user ID */
|
uflg = false, /* specify new user ID */
|
||||||
Uflg = 0; /* unlock the password */
|
Uflg = false; /* unlock the password */
|
||||||
|
|
||||||
static int is_shadow_pwd;
|
static bool is_shadow_pwd;
|
||||||
|
|
||||||
#ifdef SHADOWGRP
|
#ifdef SHADOWGRP
|
||||||
static int is_shadow_grp;
|
static bool is_shadow_grp;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
static int pw_locked = 0;
|
static bool pw_locked = false;
|
||||||
static int spw_locked = 0;
|
static bool spw_locked = false;
|
||||||
static int gr_locked = 0;
|
static bool gr_locked = false;
|
||||||
#ifdef SHADOWGRP
|
#ifdef SHADOWGRP
|
||||||
static int sgr_locked = 0;
|
static bool sgr_locked = false;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
@ -194,8 +194,9 @@ static struct group *getgr_nam_gid (const char *grname)
|
|||||||
char *errptr;
|
char *errptr;
|
||||||
|
|
||||||
val = strtol (grname, &errptr, 10);
|
val = strtol (grname, &errptr, 10);
|
||||||
if (*grname != '\0' && *errptr == '\0' && errno != ERANGE && val >= 0)
|
if (*grname != '\0' && *errptr == '\0' && errno != ERANGE && val >= 0) {
|
||||||
return xgetgrgid (val);
|
return xgetgrgid (val);
|
||||||
|
}
|
||||||
return xgetgrnam (grname);
|
return xgetgrnam (grname);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -218,8 +219,9 @@ static int get_groups (char *list)
|
|||||||
*/
|
*/
|
||||||
user_groups[0] = (char *) 0;
|
user_groups[0] = (char *) 0;
|
||||||
|
|
||||||
if (!*list)
|
if ('\0' == *list) {
|
||||||
return 0;
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* So long as there is some data to be converted, strip off each
|
* So long as there is some data to be converted, strip off each
|
||||||
@ -230,8 +232,11 @@ static int get_groups (char *list)
|
|||||||
/*
|
/*
|
||||||
* Strip off a single name from the list
|
* Strip off a single name from the list
|
||||||
*/
|
*/
|
||||||
if ((cp = strchr (list, ',')))
|
cp = strchr (list, ',');
|
||||||
*cp++ = '\0';
|
if (NULL != cp) {
|
||||||
|
*cp = '\0';
|
||||||
|
cp++;
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Names starting with digits are treated as numerical GID
|
* Names starting with digits are treated as numerical GID
|
||||||
@ -243,7 +248,7 @@ static int get_groups (char *list)
|
|||||||
* There must be a match, either by GID value or by
|
* There must be a match, either by GID value or by
|
||||||
* string name.
|
* string name.
|
||||||
*/
|
*/
|
||||||
if (!grp) {
|
if (NULL == grp) {
|
||||||
fprintf (stderr, _("%s: unknown group %s\n"),
|
fprintf (stderr, _("%s: unknown group %s\n"),
|
||||||
Prog, list);
|
Prog, list);
|
||||||
errors++;
|
errors++;
|
||||||
@ -254,8 +259,9 @@ static int get_groups (char *list)
|
|||||||
* If the group doesn't exist, don't dump core. Instead,
|
* If the group doesn't exist, don't dump core. Instead,
|
||||||
* try the next one. --marekm
|
* try the next one. --marekm
|
||||||
*/
|
*/
|
||||||
if (!grp)
|
if (NULL == grp) {
|
||||||
continue;
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
#ifdef USE_NIS
|
#ifdef USE_NIS
|
||||||
/*
|
/*
|
||||||
@ -282,15 +288,16 @@ static int get_groups (char *list)
|
|||||||
* Add the group name to the user's list of groups.
|
* Add the group name to the user's list of groups.
|
||||||
*/
|
*/
|
||||||
user_groups[ngroups++] = xstrdup (grp->gr_name);
|
user_groups[ngroups++] = xstrdup (grp->gr_name);
|
||||||
} while (list);
|
} while (NULL != list);
|
||||||
|
|
||||||
user_groups[ngroups] = (char *) 0;
|
user_groups[ngroups] = (char *) 0;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Any errors in finding group names are fatal
|
* Any errors in finding group names are fatal
|
||||||
*/
|
*/
|
||||||
if (errors)
|
if (0 != errors) {
|
||||||
return -1;
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
@ -333,7 +340,7 @@ static void usage (void)
|
|||||||
*/
|
*/
|
||||||
static char *new_pw_passwd (char *pw_pass)
|
static char *new_pw_passwd (char *pw_pass)
|
||||||
{
|
{
|
||||||
if (Lflg && pw_pass[0] != '!') {
|
if (Lflg && ('!' != pw_pass[0])) {
|
||||||
char *buf = xmalloc (strlen (pw_pass) + 2);
|
char *buf = xmalloc (strlen (pw_pass) + 2);
|
||||||
|
|
||||||
#ifdef WITH_AUDIT
|
#ifdef WITH_AUDIT
|
||||||
@ -361,7 +368,7 @@ static char *new_pw_passwd (char *pw_pass)
|
|||||||
#endif
|
#endif
|
||||||
SYSLOG ((LOG_INFO, "unlock user `%s' password", user_newname));
|
SYSLOG ((LOG_INFO, "unlock user `%s' password", user_newname));
|
||||||
s = pw_pass;
|
s = pw_pass;
|
||||||
while (*s) {
|
while ('\0' != *s) {
|
||||||
*s = *(s + 1);
|
*s = *(s + 1);
|
||||||
s++;
|
s++;
|
||||||
}
|
}
|
||||||
@ -393,9 +400,10 @@ static void new_pwent (struct passwd *pwent)
|
|||||||
pwent->pw_name, user_newname));
|
pwent->pw_name, user_newname));
|
||||||
pwent->pw_name = xstrdup (user_newname);
|
pwent->pw_name = xstrdup (user_newname);
|
||||||
}
|
}
|
||||||
if (!is_shadow_pwd)
|
if (!is_shadow_pwd) {
|
||||||
pwent->pw_passwd =
|
pwent->pw_passwd =
|
||||||
new_pw_passwd (pwent->pw_passwd);
|
new_pw_passwd (pwent->pw_passwd);
|
||||||
|
}
|
||||||
|
|
||||||
if (uflg) {
|
if (uflg) {
|
||||||
#ifdef WITH_AUDIT
|
#ifdef WITH_AUDIT
|
||||||
@ -456,8 +464,9 @@ static void new_pwent (struct passwd *pwent)
|
|||||||
*/
|
*/
|
||||||
static void new_spent (struct spwd *spent)
|
static void new_spent (struct spwd *spent)
|
||||||
{
|
{
|
||||||
if (lflg)
|
if (lflg) {
|
||||||
spent->sp_namp = xstrdup (user_newname);
|
spent->sp_namp = xstrdup (user_newname);
|
||||||
|
}
|
||||||
|
|
||||||
if (fflg) {
|
if (fflg) {
|
||||||
#ifdef WITH_AUDIT
|
#ifdef WITH_AUDIT
|
||||||
@ -488,8 +497,9 @@ static void new_spent (struct spwd *spent)
|
|||||||
spent->sp_expire = user_newexpire;
|
spent->sp_expire = user_newexpire;
|
||||||
}
|
}
|
||||||
spent->sp_pwdp = new_pw_passwd (spent->sp_pwdp);
|
spent->sp_pwdp = new_pw_passwd (spent->sp_pwdp);
|
||||||
if (pflg)
|
if (pflg) {
|
||||||
spent->sp_lstchg = time ((time_t *) 0) / SCALE;
|
spent->sp_lstchg = time ((time_t *) 0) / SCALE;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@ -497,16 +507,20 @@ static void new_spent (struct spwd *spent)
|
|||||||
*/
|
*/
|
||||||
static void fail_exit (int code)
|
static void fail_exit (int code)
|
||||||
{
|
{
|
||||||
if (gr_locked)
|
if (gr_locked) {
|
||||||
gr_unlock ();
|
gr_unlock ();
|
||||||
|
}
|
||||||
#ifdef SHADOWGRP
|
#ifdef SHADOWGRP
|
||||||
if (sgr_locked)
|
if (sgr_locked) {
|
||||||
sgr_unlock ();
|
sgr_unlock ();
|
||||||
|
}
|
||||||
#endif
|
#endif
|
||||||
if (spw_locked)
|
if (spw_locked) {
|
||||||
spw_unlock ();
|
spw_unlock ();
|
||||||
if (pw_locked)
|
}
|
||||||
|
if (pw_locked) {
|
||||||
pw_unlock ();
|
pw_unlock ();
|
||||||
|
}
|
||||||
|
|
||||||
#ifdef WITH_AUDIT
|
#ifdef WITH_AUDIT
|
||||||
audit_logger (AUDIT_USER_CHAUTHTOK, Prog, "modifying account",
|
audit_logger (AUDIT_USER_CHAUTHTOK, Prog, "modifying account",
|
||||||
@ -518,19 +532,19 @@ static void fail_exit (int code)
|
|||||||
|
|
||||||
static void update_group (void)
|
static void update_group (void)
|
||||||
{
|
{
|
||||||
int is_member;
|
bool is_member;
|
||||||
int was_member;
|
bool was_member;
|
||||||
int changed;
|
bool changed;
|
||||||
const struct group *grp;
|
const struct group *grp;
|
||||||
struct group *ngrp;
|
struct group *ngrp;
|
||||||
|
|
||||||
changed = 0;
|
changed = false;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* 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.
|
||||||
*/
|
*/
|
||||||
while ((grp = gr_next ())) {
|
while ((grp = gr_next ()) != NULL) {
|
||||||
/*
|
/*
|
||||||
* 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.
|
||||||
@ -539,11 +553,12 @@ static void update_group (void)
|
|||||||
is_member = Gflg && ( (was_member && aflg)
|
is_member = Gflg && ( (was_member && aflg)
|
||||||
|| is_on_list (user_groups, grp->gr_name));
|
|| is_on_list (user_groups, grp->gr_name));
|
||||||
|
|
||||||
if (!was_member && !is_member)
|
if (!was_member && !is_member) {
|
||||||
continue;
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
ngrp = __gr_dup (grp);
|
ngrp = __gr_dup (grp);
|
||||||
if (!ngrp) {
|
if (NULL == ngrp) {
|
||||||
fprintf (stderr,
|
fprintf (stderr,
|
||||||
_("%s: Out of memory. Cannot update the group database.\n"),
|
_("%s: Out of memory. Cannot update the group database.\n"),
|
||||||
Prog);
|
Prog);
|
||||||
@ -556,7 +571,7 @@ static void update_group (void)
|
|||||||
user_name);
|
user_name);
|
||||||
ngrp->gr_mem = add_list (ngrp->gr_mem,
|
ngrp->gr_mem = add_list (ngrp->gr_mem,
|
||||||
user_newname);
|
user_newname);
|
||||||
changed = 1;
|
changed = true;
|
||||||
#ifdef WITH_AUDIT
|
#ifdef WITH_AUDIT
|
||||||
audit_logger (AUDIT_USER_CHAUTHTOK, Prog,
|
audit_logger (AUDIT_USER_CHAUTHTOK, Prog,
|
||||||
"changing group member",
|
"changing group member",
|
||||||
@ -569,7 +584,7 @@ static void update_group (void)
|
|||||||
}
|
}
|
||||||
} else if (was_member && !aflg && Gflg && !is_member) {
|
} else if (was_member && !aflg && Gflg && !is_member) {
|
||||||
ngrp->gr_mem = del_list (ngrp->gr_mem, user_name);
|
ngrp->gr_mem = del_list (ngrp->gr_mem, user_name);
|
||||||
changed = 1;
|
changed = true;
|
||||||
#ifdef WITH_AUDIT
|
#ifdef WITH_AUDIT
|
||||||
audit_logger (AUDIT_USER_CHAUTHTOK, Prog,
|
audit_logger (AUDIT_USER_CHAUTHTOK, Prog,
|
||||||
"removing group member", user_name, -1,
|
"removing group member", user_name, -1,
|
||||||
@ -579,7 +594,7 @@ static void update_group (void)
|
|||||||
user_name, ngrp->gr_name));
|
user_name, ngrp->gr_name));
|
||||||
} else if (!was_member && Gflg && is_member) {
|
} else if (!was_member && Gflg && is_member) {
|
||||||
ngrp->gr_mem = add_list (ngrp->gr_mem, user_newname);
|
ngrp->gr_mem = add_list (ngrp->gr_mem, user_newname);
|
||||||
changed = 1;
|
changed = true;
|
||||||
#ifdef WITH_AUDIT
|
#ifdef WITH_AUDIT
|
||||||
audit_logger (AUDIT_USER_CHAUTHTOK, Prog,
|
audit_logger (AUDIT_USER_CHAUTHTOK, Prog,
|
||||||
"adding user to group", user_name, -1, 1);
|
"adding user to group", user_name, -1, 1);
|
||||||
@ -590,8 +605,8 @@ static void update_group (void)
|
|||||||
if (!changed)
|
if (!changed)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
changed = 0;
|
changed = false;
|
||||||
if (!gr_update (ngrp)) {
|
if (gr_update (ngrp) == 0) {
|
||||||
fprintf (stderr,
|
fprintf (stderr,
|
||||||
_("%s: error adding new group entry\n"), Prog);
|
_("%s: error adding new group entry\n"), Prog);
|
||||||
SYSLOG ((LOG_ERR, "error adding new group entry"));
|
SYSLOG ((LOG_ERR, "error adding new group entry"));
|
||||||
@ -603,20 +618,20 @@ static void update_group (void)
|
|||||||
#ifdef SHADOWGRP
|
#ifdef SHADOWGRP
|
||||||
static void update_gshadow (void)
|
static void update_gshadow (void)
|
||||||
{
|
{
|
||||||
int is_member;
|
bool is_member;
|
||||||
int was_member;
|
bool was_member;
|
||||||
int was_admin;
|
bool was_admin;
|
||||||
int changed;
|
bool changed;
|
||||||
const struct sgrp *sgrp;
|
const struct sgrp *sgrp;
|
||||||
struct sgrp *nsgrp;
|
struct sgrp *nsgrp;
|
||||||
|
|
||||||
changed = 0;
|
changed = false;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Scan through the entire shadow group file looking for the groups
|
* Scan through the entire shadow group file looking for the groups
|
||||||
* that the user is a member of.
|
* that the user is a member of.
|
||||||
*/
|
*/
|
||||||
while ((sgrp = sgr_next ())) {
|
while ((sgrp = sgr_next ()) != NULL) {
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* See if the user was a member of this group
|
* See if the user was a member of this group
|
||||||
@ -636,11 +651,12 @@ static void update_gshadow (void)
|
|||||||
is_member = Gflg && ( (was_member && aflg)
|
is_member = Gflg && ( (was_member && aflg)
|
||||||
|| is_on_list (user_groups, sgrp->sg_name));
|
|| is_on_list (user_groups, sgrp->sg_name));
|
||||||
|
|
||||||
if (!was_member && !was_admin && !is_member)
|
if (!was_member && !was_admin && !is_member) {
|
||||||
continue;
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
nsgrp = __sgr_dup (sgrp);
|
nsgrp = __sgr_dup (sgrp);
|
||||||
if (!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 the shadow group database.\n"),
|
||||||
Prog);
|
Prog);
|
||||||
@ -650,7 +666,7 @@ static void update_gshadow (void)
|
|||||||
if (was_admin && lflg) {
|
if (was_admin && lflg) {
|
||||||
nsgrp->sg_adm = del_list (nsgrp->sg_adm, user_name);
|
nsgrp->sg_adm = del_list (nsgrp->sg_adm, user_name);
|
||||||
nsgrp->sg_adm = add_list (nsgrp->sg_adm, user_newname);
|
nsgrp->sg_adm = add_list (nsgrp->sg_adm, user_newname);
|
||||||
changed = 1;
|
changed = true;
|
||||||
#ifdef WITH_AUDIT
|
#ifdef WITH_AUDIT
|
||||||
audit_logger (AUDIT_USER_CHAUTHTOK, Prog,
|
audit_logger (AUDIT_USER_CHAUTHTOK, Prog,
|
||||||
"changing admin name in shadow group",
|
"changing admin name in shadow group",
|
||||||
@ -666,7 +682,7 @@ static void update_gshadow (void)
|
|||||||
user_name);
|
user_name);
|
||||||
nsgrp->sg_mem = add_list (nsgrp->sg_mem,
|
nsgrp->sg_mem = add_list (nsgrp->sg_mem,
|
||||||
user_newname);
|
user_newname);
|
||||||
changed = 1;
|
changed = true;
|
||||||
#ifdef WITH_AUDIT
|
#ifdef WITH_AUDIT
|
||||||
audit_logger (AUDIT_USER_CHAUTHTOK, Prog,
|
audit_logger (AUDIT_USER_CHAUTHTOK, Prog,
|
||||||
"changing member in shadow group",
|
"changing member in shadow group",
|
||||||
@ -679,7 +695,7 @@ static void update_gshadow (void)
|
|||||||
}
|
}
|
||||||
} else if (was_member && !aflg && Gflg && !is_member) {
|
} else if (was_member && !aflg && Gflg && !is_member) {
|
||||||
nsgrp->sg_mem = del_list (nsgrp->sg_mem, user_name);
|
nsgrp->sg_mem = del_list (nsgrp->sg_mem, user_name);
|
||||||
changed = 1;
|
changed = true;
|
||||||
#ifdef WITH_AUDIT
|
#ifdef WITH_AUDIT
|
||||||
audit_logger (AUDIT_USER_CHAUTHTOK, Prog,
|
audit_logger (AUDIT_USER_CHAUTHTOK, Prog,
|
||||||
"removing user from shadow group",
|
"removing user from shadow group",
|
||||||
@ -690,7 +706,7 @@ static void update_gshadow (void)
|
|||||||
user_name, nsgrp->sg_name));
|
user_name, nsgrp->sg_name));
|
||||||
} else if (!was_member && Gflg && is_member) {
|
} else if (!was_member && Gflg && is_member) {
|
||||||
nsgrp->sg_mem = add_list (nsgrp->sg_mem, user_newname);
|
nsgrp->sg_mem = add_list (nsgrp->sg_mem, user_newname);
|
||||||
changed = 1;
|
changed = true;
|
||||||
#ifdef WITH_AUDIT
|
#ifdef WITH_AUDIT
|
||||||
audit_logger (AUDIT_USER_CHAUTHTOK, Prog,
|
audit_logger (AUDIT_USER_CHAUTHTOK, Prog,
|
||||||
"adding user to shadow group",
|
"adding user to shadow group",
|
||||||
@ -699,15 +715,16 @@ static void update_gshadow (void)
|
|||||||
SYSLOG ((LOG_INFO, "add `%s' to shadow group `%s'",
|
SYSLOG ((LOG_INFO, "add `%s' to shadow group `%s'",
|
||||||
user_newname, nsgrp->sg_name));
|
user_newname, nsgrp->sg_name));
|
||||||
}
|
}
|
||||||
if (!changed)
|
if (!changed) {
|
||||||
continue;
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
changed = 0;
|
changed = false;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Update the group entry to reflect the changes.
|
* Update the group entry to reflect the changes.
|
||||||
*/
|
*/
|
||||||
if (!sgr_update (nsgrp)) {
|
if (sgr_update (nsgrp) == 0) {
|
||||||
fprintf (stderr,
|
fprintf (stderr,
|
||||||
_("%s: error adding new shadow group entry\n"), Prog);
|
_("%s: error adding new shadow group entry\n"), Prog);
|
||||||
SYSLOG ((LOG_ERR, "error adding shadow group entry"));
|
SYSLOG ((LOG_ERR, "error adding shadow group entry"));
|
||||||
@ -727,8 +744,9 @@ static void grp_update (void)
|
|||||||
{
|
{
|
||||||
update_group ();
|
update_group ();
|
||||||
#ifdef SHADOWGRP
|
#ifdef SHADOWGRP
|
||||||
if (is_shadow_grp)
|
if (is_shadow_grp) {
|
||||||
update_gshadow ();
|
update_gshadow ();
|
||||||
|
}
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -738,7 +756,7 @@ static long get_number (const char *numstr)
|
|||||||
char *errptr;
|
char *errptr;
|
||||||
|
|
||||||
val = strtol (numstr, &errptr, 10);
|
val = strtol (numstr, &errptr, 10);
|
||||||
if (*errptr || errno == ERANGE) {
|
if (('\0' != *errptr) || (ERANGE == errno)) {
|
||||||
fprintf (stderr, _("%s: invalid numeric argument '%s'\n"), Prog,
|
fprintf (stderr, _("%s: invalid numeric argument '%s'\n"), Prog,
|
||||||
numstr);
|
numstr);
|
||||||
exit (E_BAD_ARG);
|
exit (E_BAD_ARG);
|
||||||
@ -752,7 +770,7 @@ static uid_t get_id (const char *uidstr)
|
|||||||
char *errptr;
|
char *errptr;
|
||||||
|
|
||||||
val = strtol (uidstr, &errptr, 10);
|
val = strtol (uidstr, &errptr, 10);
|
||||||
if (*errptr || errno == ERANGE || val < 0) {
|
if (('\0' != *errptr) || (ERANGE == errno) || (val < 0)) {
|
||||||
fprintf (stderr, _("%s: invalid numeric argument '%s'\n"), Prog,
|
fprintf (stderr, _("%s: invalid numeric argument '%s'\n"), Prog,
|
||||||
uidstr);
|
uidstr);
|
||||||
exit (E_BAD_ARG);
|
exit (E_BAD_ARG);
|
||||||
@ -771,15 +789,16 @@ static void process_flags (int argc, char **argv)
|
|||||||
{
|
{
|
||||||
const struct group *grp;
|
const struct group *grp;
|
||||||
|
|
||||||
int anyflag = 0;
|
bool anyflag = false;
|
||||||
|
|
||||||
if (argc == 1 || argv[argc - 1][0] == '-')
|
if ((1 == argc) || ('-' == argv[argc - 1][0]))
|
||||||
usage ();
|
usage ();
|
||||||
|
|
||||||
{
|
{
|
||||||
const struct passwd *pwd;
|
const struct passwd *pwd;
|
||||||
/* local, no need for xgetpwnam */
|
/* local, no need for xgetpwnam */
|
||||||
if (!(pwd = getpwnam (argv[argc - 1]))) {
|
pwd = getpwnam (argv[argc - 1]);
|
||||||
|
if (NULL == pwd) {
|
||||||
fprintf (stderr, _("%s: user %s does not exist\n"),
|
fprintf (stderr, _("%s: user %s does not exist\n"),
|
||||||
Prog, argv[argc - 1]);
|
Prog, argv[argc - 1]);
|
||||||
exit (E_NOTFOUND);
|
exit (E_NOTFOUND);
|
||||||
@ -810,8 +829,8 @@ static void process_flags (int argc, char **argv)
|
|||||||
fprintf (stderr, _("%s: user %s is a NIS user\n"),
|
fprintf (stderr, _("%s: user %s is a NIS user\n"),
|
||||||
Prog, user_name);
|
Prog, user_name);
|
||||||
|
|
||||||
if (!yp_get_default_domain (&nis_domain) &&
|
if ( !yp_get_default_domain (&nis_domain)
|
||||||
!yp_master (nis_domain, "passwd.byname", &nis_master)) {
|
&& !yp_master (nis_domain, "passwd.byname", &nis_master)) {
|
||||||
fprintf (stderr, _("%s: %s is the NIS master\n"),
|
fprintf (stderr, _("%s: %s is the NIS master\n"),
|
||||||
Prog, nis_master);
|
Prog, nis_master);
|
||||||
}
|
}
|
||||||
@ -822,7 +841,7 @@ static void process_flags (int argc, char **argv)
|
|||||||
{
|
{
|
||||||
const struct spwd *spwd = NULL;
|
const struct spwd *spwd = NULL;
|
||||||
/* local, no need for xgetspnam */
|
/* local, no need for xgetspnam */
|
||||||
if (is_shadow_pwd && (spwd = getspnam (user_name))) {
|
if (is_shadow_pwd && ((spwd = getspnam (user_name)) != NULL)) {
|
||||||
user_expire = spwd->sp_expire;
|
user_expire = spwd->sp_expire;
|
||||||
user_inactive = spwd->sp_inact;
|
user_inactive = spwd->sp_inact;
|
||||||
user_newexpire = user_expire;
|
user_newexpire = user_expire;
|
||||||
@ -859,7 +878,7 @@ static void process_flags (int argc, char **argv)
|
|||||||
long_options, NULL)) != -1) {
|
long_options, NULL)) != -1) {
|
||||||
switch (c) {
|
switch (c) {
|
||||||
case 'a':
|
case 'a':
|
||||||
aflg++;
|
aflg = true;
|
||||||
break;
|
break;
|
||||||
case 'c':
|
case 'c':
|
||||||
if (!VALID (optarg)) {
|
if (!VALID (optarg)) {
|
||||||
@ -869,7 +888,7 @@ static void process_flags (int argc, char **argv)
|
|||||||
exit (E_BAD_ARG);
|
exit (E_BAD_ARG);
|
||||||
}
|
}
|
||||||
user_newcomment = optarg;
|
user_newcomment = optarg;
|
||||||
cflg++;
|
cflg = true;
|
||||||
break;
|
break;
|
||||||
case 'd':
|
case 'd':
|
||||||
if (!VALID (optarg)) {
|
if (!VALID (optarg)) {
|
||||||
@ -878,11 +897,11 @@ static void process_flags (int argc, char **argv)
|
|||||||
Prog, optarg);
|
Prog, optarg);
|
||||||
exit (E_BAD_ARG);
|
exit (E_BAD_ARG);
|
||||||
}
|
}
|
||||||
dflg++;
|
dflg = true;
|
||||||
user_newhome = optarg;
|
user_newhome = optarg;
|
||||||
break;
|
break;
|
||||||
case 'e':
|
case 'e':
|
||||||
if (*optarg) {
|
if ('\0' != *optarg) {
|
||||||
user_newexpire = strtoday (optarg);
|
user_newexpire = strtoday (optarg);
|
||||||
if (user_newexpire == -1) {
|
if (user_newexpire == -1) {
|
||||||
fprintf (stderr,
|
fprintf (stderr,
|
||||||
@ -892,29 +911,31 @@ static void process_flags (int argc, char **argv)
|
|||||||
exit (E_BAD_ARG);
|
exit (E_BAD_ARG);
|
||||||
}
|
}
|
||||||
user_newexpire *= DAY / SCALE;
|
user_newexpire *= DAY / SCALE;
|
||||||
} else
|
} else {
|
||||||
user_newexpire = -1;
|
user_newexpire = -1;
|
||||||
eflg++;
|
}
|
||||||
|
eflg = true;
|
||||||
break;
|
break;
|
||||||
case 'f':
|
case 'f':
|
||||||
user_newinactive = get_number (optarg);
|
user_newinactive = get_number (optarg);
|
||||||
fflg++;
|
fflg = true;
|
||||||
break;
|
break;
|
||||||
case 'g':
|
case 'g':
|
||||||
grp = getgr_nam_gid (optarg);
|
grp = getgr_nam_gid (optarg);
|
||||||
if (!grp) {
|
if (NULL == grp) {
|
||||||
fprintf (stderr,
|
fprintf (stderr,
|
||||||
_("%s: unknown group %s\n"),
|
_("%s: unknown group %s\n"),
|
||||||
Prog, optarg);
|
Prog, optarg);
|
||||||
exit (E_NOTFOUND);
|
exit (E_NOTFOUND);
|
||||||
}
|
}
|
||||||
user_newgid = grp->gr_gid;
|
user_newgid = grp->gr_gid;
|
||||||
gflg++;
|
gflg = true;
|
||||||
break;
|
break;
|
||||||
case 'G':
|
case 'G':
|
||||||
if (get_groups (optarg))
|
if (get_groups (optarg) != 0) {
|
||||||
exit (E_NOTFOUND);
|
exit (E_NOTFOUND);
|
||||||
Gflg++;
|
}
|
||||||
|
Gflg = true;
|
||||||
break;
|
break;
|
||||||
case 'l':
|
case 'l':
|
||||||
if (!is_valid_user_name (optarg)) {
|
if (!is_valid_user_name (optarg)) {
|
||||||
@ -923,21 +944,21 @@ static void process_flags (int argc, char **argv)
|
|||||||
Prog, optarg);
|
Prog, optarg);
|
||||||
exit (E_BAD_ARG);
|
exit (E_BAD_ARG);
|
||||||
}
|
}
|
||||||
lflg++;
|
lflg = true;
|
||||||
user_newname = optarg;
|
user_newname = optarg;
|
||||||
break;
|
break;
|
||||||
case 'L':
|
case 'L':
|
||||||
Lflg++;
|
Lflg = true;
|
||||||
break;
|
break;
|
||||||
case 'm':
|
case 'm':
|
||||||
mflg++;
|
mflg = true;
|
||||||
break;
|
break;
|
||||||
case 'o':
|
case 'o':
|
||||||
oflg++;
|
oflg = true;
|
||||||
break;
|
break;
|
||||||
case 'p':
|
case 'p':
|
||||||
user_pass = optarg;
|
user_pass = optarg;
|
||||||
pflg++;
|
pflg = true;
|
||||||
break;
|
break;
|
||||||
case 's':
|
case 's':
|
||||||
if (!VALID (optarg)) {
|
if (!VALID (optarg)) {
|
||||||
@ -947,56 +968,56 @@ static void process_flags (int argc, char **argv)
|
|||||||
exit (E_BAD_ARG);
|
exit (E_BAD_ARG);
|
||||||
}
|
}
|
||||||
user_newshell = optarg;
|
user_newshell = optarg;
|
||||||
sflg++;
|
sflg = true;
|
||||||
break;
|
break;
|
||||||
case 'u':
|
case 'u':
|
||||||
user_newid = get_id (optarg);
|
user_newid = get_id (optarg);
|
||||||
uflg++;
|
uflg = true;
|
||||||
break;
|
break;
|
||||||
case 'U':
|
case 'U':
|
||||||
Uflg++;
|
Uflg = true;
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
usage ();
|
usage ();
|
||||||
}
|
}
|
||||||
anyflag++;
|
anyflag = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (anyflag == 0) {
|
if (!anyflag) {
|
||||||
fprintf (stderr, _("%s: no flags given\n"), Prog);
|
fprintf (stderr, _("%s: no flags given\n"), Prog);
|
||||||
exit (E_USAGE);
|
exit (E_USAGE);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (user_newid == user_id) {
|
if (user_newid == user_id) {
|
||||||
uflg = 0;
|
uflg = false;
|
||||||
oflg = 0;
|
oflg = false;
|
||||||
}
|
}
|
||||||
if (user_newgid == user_gid) {
|
if (user_newgid == user_gid) {
|
||||||
gflg = 0;
|
gflg = false;
|
||||||
}
|
}
|
||||||
if (strcmp (user_newshell, user_shell) == 0) {
|
if (strcmp (user_newshell, user_shell) == 0) {
|
||||||
sflg = 0;
|
sflg = false;
|
||||||
}
|
}
|
||||||
if (strcmp (user_newname, user_name) == 0) {
|
if (strcmp (user_newname, user_name) == 0) {
|
||||||
lflg = 0;
|
lflg = false;
|
||||||
}
|
}
|
||||||
if (user_newinactive == user_inactive) {
|
if (user_newinactive == user_inactive) {
|
||||||
fflg = 0;
|
fflg = false;
|
||||||
}
|
}
|
||||||
if (user_newexpire == user_expire) {
|
if (user_newexpire == user_expire) {
|
||||||
eflg = 0;
|
eflg = false;
|
||||||
}
|
}
|
||||||
if (strcmp (user_newhome, user_home) == 0) {
|
if (strcmp (user_newhome, user_home) == 0) {
|
||||||
dflg = 0;
|
dflg = false;
|
||||||
mflg = 0;
|
mflg = false;
|
||||||
}
|
}
|
||||||
if (strcmp (user_newcomment, user_comment) == 0) {
|
if (strcmp (user_newcomment, user_comment) == 0) {
|
||||||
cflg = 0;
|
cflg = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (Uflg + uflg + sflg + pflg + oflg + mflg + Lflg + lflg + Gflg +
|
if (!(Uflg || uflg || sflg || pflg || oflg || mflg || Lflg ||
|
||||||
gflg + fflg + eflg + dflg + cflg == 0) {
|
lflg || Gflg || gflg || fflg || eflg || dflg || cflg)) {
|
||||||
fprintf (stderr, _("%s: no changes\n"), Prog);
|
fprintf (stderr, _("%s: no changes\n"), Prog);
|
||||||
exit (E_SUCCESS);
|
exit (E_SUCCESS);
|
||||||
}
|
}
|
||||||
@ -1045,13 +1066,13 @@ static void process_flags (int argc, char **argv)
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* local, no need for xgetpwnam */
|
/* local, no need for xgetpwnam */
|
||||||
if (lflg && getpwnam (user_newname)) {
|
if (lflg && (getpwnam (user_newname) != NULL)) {
|
||||||
fprintf (stderr, _("%s: user %s exists\n"), Prog, user_newname);
|
fprintf (stderr, _("%s: user %s 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)) {
|
if (uflg && !oflg && (getpwuid (user_newid) != NULL)) {
|
||||||
fprintf (stderr, _("%s: uid %lu is not unique\n"),
|
fprintf (stderr, _("%s: uid %lu is not unique\n"),
|
||||||
Prog, (unsigned long) user_newid);
|
Prog, (unsigned long) user_newid);
|
||||||
exit (E_UID_IN_USE);
|
exit (E_UID_IN_USE);
|
||||||
@ -1066,44 +1087,46 @@ static void process_flags (int argc, char **argv)
|
|||||||
*/
|
*/
|
||||||
static void close_files (void)
|
static void close_files (void)
|
||||||
{
|
{
|
||||||
if (!pw_close ()) {
|
if (pw_close () == 0) {
|
||||||
fprintf (stderr, _("%s: cannot rewrite password file\n"), Prog);
|
fprintf (stderr, _("%s: cannot rewrite password file\n"), Prog);
|
||||||
fail_exit (E_PW_UPDATE);
|
fail_exit (E_PW_UPDATE);
|
||||||
}
|
}
|
||||||
if (is_shadow_pwd && !spw_close ()) {
|
if (is_shadow_pwd && (spw_close () == 0)) {
|
||||||
fprintf (stderr,
|
fprintf (stderr,
|
||||||
_("%s: cannot rewrite shadow password file\n"), Prog);
|
_("%s: cannot rewrite shadow password file\n"), Prog);
|
||||||
fail_exit (E_PW_UPDATE);
|
fail_exit (E_PW_UPDATE);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (Gflg || lflg) {
|
if (Gflg || lflg) {
|
||||||
if (!gr_close ()) {
|
if (gr_close () == 0) {
|
||||||
fprintf (stderr, _("%s: cannot rewrite group file\n"),
|
fprintf (stderr, _("%s: cannot rewrite group file\n"),
|
||||||
Prog);
|
Prog);
|
||||||
fail_exit (E_GRP_UPDATE);
|
fail_exit (E_GRP_UPDATE);
|
||||||
}
|
}
|
||||||
#ifdef SHADOWGRP
|
#ifdef SHADOWGRP
|
||||||
if (is_shadow_grp && !sgr_close ()) {
|
if (is_shadow_grp && (sgr_close () == 0)) {
|
||||||
fprintf (stderr,
|
fprintf (stderr,
|
||||||
_("%s: cannot rewrite shadow group file\n"),
|
_("%s: cannot rewrite shadow group file\n"),
|
||||||
Prog);
|
Prog);
|
||||||
fail_exit (E_GRP_UPDATE);
|
fail_exit (E_GRP_UPDATE);
|
||||||
}
|
}
|
||||||
if (is_shadow_grp)
|
if (is_shadow_grp) {
|
||||||
sgr_unlock ();
|
sgr_unlock ();
|
||||||
|
}
|
||||||
#endif
|
#endif
|
||||||
gr_unlock ();
|
gr_unlock ();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (is_shadow_pwd)
|
if (is_shadow_pwd) {
|
||||||
spw_unlock ();
|
spw_unlock ();
|
||||||
|
}
|
||||||
pw_unlock ();
|
pw_unlock ();
|
||||||
|
|
||||||
pw_locked = 0;
|
pw_locked = false;
|
||||||
spw_locked = 0;
|
spw_locked = false;
|
||||||
gr_locked = 0;
|
gr_locked = false;
|
||||||
#ifdef SHADOWGRP
|
#ifdef SHADOWGRP
|
||||||
sgr_locked = 0;
|
sgr_locked = false;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@ -1124,22 +1147,22 @@ static void close_files (void)
|
|||||||
*/
|
*/
|
||||||
static void open_files (void)
|
static void open_files (void)
|
||||||
{
|
{
|
||||||
if (!pw_lock ()) {
|
if (pw_lock () == 0) {
|
||||||
fprintf (stderr, _("%s: unable to lock password file\n"), Prog);
|
fprintf (stderr, _("%s: unable to lock password file\n"), Prog);
|
||||||
fail_exit (E_PW_UPDATE);
|
fail_exit (E_PW_UPDATE);
|
||||||
}
|
}
|
||||||
pw_locked = 1;
|
pw_locked = true;
|
||||||
if (!pw_open (O_RDWR)) {
|
if (pw_open (O_RDWR) == 0) {
|
||||||
fprintf (stderr, _("%s: unable to open password file\n"), Prog);
|
fprintf (stderr, _("%s: unable to open password file\n"), Prog);
|
||||||
fail_exit (E_PW_UPDATE);
|
fail_exit (E_PW_UPDATE);
|
||||||
}
|
}
|
||||||
if (is_shadow_pwd && !spw_lock ()) {
|
if (is_shadow_pwd && (spw_lock () == 0)) {
|
||||||
fprintf (stderr,
|
fprintf (stderr,
|
||||||
_("%s: cannot lock shadow password file\n"), Prog);
|
_("%s: cannot lock shadow password file\n"), Prog);
|
||||||
fail_exit (E_PW_UPDATE);
|
fail_exit (E_PW_UPDATE);
|
||||||
}
|
}
|
||||||
spw_locked = 1;
|
spw_locked = true;
|
||||||
if (is_shadow_pwd && !spw_open (O_RDWR)) {
|
if (is_shadow_pwd && (spw_open (O_RDWR) == 0)) {
|
||||||
fprintf (stderr,
|
fprintf (stderr,
|
||||||
_("%s: cannot open shadow password file\n"), Prog);
|
_("%s: cannot open shadow password file\n"), Prog);
|
||||||
fail_exit (E_PW_UPDATE);
|
fail_exit (E_PW_UPDATE);
|
||||||
@ -1150,26 +1173,26 @@ static void open_files (void)
|
|||||||
* Lock and open the group file. This will load all of the
|
* Lock and open the group file. This will load all of the
|
||||||
* group entries.
|
* group entries.
|
||||||
*/
|
*/
|
||||||
if (!gr_lock ()) {
|
if (gr_lock () == 0) {
|
||||||
fprintf (stderr, _("%s: error locking group file\n"),
|
fprintf (stderr, _("%s: error locking group file\n"),
|
||||||
Prog);
|
Prog);
|
||||||
fail_exit (E_GRP_UPDATE);
|
fail_exit (E_GRP_UPDATE);
|
||||||
}
|
}
|
||||||
gr_locked = 1;
|
gr_locked = true;
|
||||||
if (!gr_open (O_RDWR)) {
|
if (gr_open (O_RDWR) == 0) {
|
||||||
fprintf (stderr, _("%s: error opening group file\n"),
|
fprintf (stderr, _("%s: error opening group file\n"),
|
||||||
Prog);
|
Prog);
|
||||||
fail_exit (E_GRP_UPDATE);
|
fail_exit (E_GRP_UPDATE);
|
||||||
}
|
}
|
||||||
#ifdef SHADOWGRP
|
#ifdef SHADOWGRP
|
||||||
if (is_shadow_grp && !sgr_lock ()) {
|
if (is_shadow_grp && (sgr_lock () == 0)) {
|
||||||
fprintf (stderr,
|
fprintf (stderr,
|
||||||
_("%s: error locking shadow group file\n"),
|
_("%s: error locking shadow group file\n"),
|
||||||
Prog);
|
Prog);
|
||||||
fail_exit (E_GRP_UPDATE);
|
fail_exit (E_GRP_UPDATE);
|
||||||
}
|
}
|
||||||
sgr_locked = 1;
|
sgr_locked = true;
|
||||||
if (is_shadow_grp && !sgr_open (O_RDWR)) {
|
if (is_shadow_grp && (sgr_open (O_RDWR) == 0)) {
|
||||||
fprintf (stderr,
|
fprintf (stderr,
|
||||||
_("%s: error opening shadow group file\n"),
|
_("%s: error opening shadow group file\n"),
|
||||||
Prog);
|
Prog);
|
||||||
@ -1197,7 +1220,7 @@ static void usr_update (void)
|
|||||||
* Locate the entry in /etc/passwd, which MUST exist.
|
* Locate the entry in /etc/passwd, which MUST exist.
|
||||||
*/
|
*/
|
||||||
pwd = pw_locate (user_name);
|
pwd = pw_locate (user_name);
|
||||||
if (!pwd) {
|
if (NULL == pwd) {
|
||||||
fprintf (stderr, _("%s: %s not found in /etc/passwd\n"),
|
fprintf (stderr, _("%s: %s not found in /etc/passwd\n"),
|
||||||
Prog, user_name);
|
Prog, user_name);
|
||||||
fail_exit (E_NOTFOUND);
|
fail_exit (E_NOTFOUND);
|
||||||
@ -1210,35 +1233,35 @@ static void usr_update (void)
|
|||||||
* Locate the entry in /etc/shadow. It doesn't have to exist, and
|
* Locate the entry in /etc/shadow. It doesn't have to exist, and
|
||||||
* won't be created if it doesn't.
|
* won't be created if it doesn't.
|
||||||
*/
|
*/
|
||||||
if (is_shadow_pwd && (spwd = spw_locate (user_name))) {
|
if (is_shadow_pwd && ((spwd = spw_locate (user_name)) != NULL)) {
|
||||||
spent = *spwd;
|
spent = *spwd;
|
||||||
new_spent (&spent);
|
new_spent (&spent);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (lflg || uflg || gflg || cflg || dflg || sflg || pflg
|
if (lflg || uflg || gflg || cflg || dflg || sflg || pflg
|
||||||
|| Lflg || Uflg) {
|
|| Lflg || Uflg) {
|
||||||
if (!pw_update (&pwent)) {
|
if (pw_update (&pwent) == 0) {
|
||||||
fprintf (stderr,
|
fprintf (stderr,
|
||||||
_("%s: error changing password entry\n"),
|
_("%s: error changing password entry\n"),
|
||||||
Prog);
|
Prog);
|
||||||
fail_exit (E_PW_UPDATE);
|
fail_exit (E_PW_UPDATE);
|
||||||
}
|
}
|
||||||
if (lflg && !pw_remove (user_name)) {
|
if (lflg && (pw_remove (user_name) == 0)) {
|
||||||
fprintf (stderr,
|
fprintf (stderr,
|
||||||
_("%s: error removing password entry\n"),
|
_("%s: error removing password entry\n"),
|
||||||
Prog);
|
Prog);
|
||||||
fail_exit (E_PW_UPDATE);
|
fail_exit (E_PW_UPDATE);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (spwd && (lflg || eflg || fflg || pflg || Lflg || Uflg)) {
|
if ((NULL != spwd) && (lflg || eflg || fflg || pflg || Lflg || Uflg)) {
|
||||||
if (!spw_update (&spent)) {
|
if (spw_update (&spent) == 0) {
|
||||||
fprintf (stderr,
|
fprintf (stderr,
|
||||||
_
|
_
|
||||||
("%s: error adding new shadow password entry\n"),
|
("%s: error adding new shadow password entry\n"),
|
||||||
Prog);
|
Prog);
|
||||||
fail_exit (E_PW_UPDATE);
|
fail_exit (E_PW_UPDATE);
|
||||||
}
|
}
|
||||||
if (lflg && !spw_remove (user_name)) {
|
if (lflg && (spw_remove (user_name) == 0)) {
|
||||||
fprintf (stderr,
|
fprintf (stderr,
|
||||||
_
|
_
|
||||||
("%s: error removing shadow password entry\n"),
|
("%s: error removing shadow password entry\n"),
|
||||||
@ -1258,7 +1281,7 @@ static void move_home (void)
|
|||||||
{
|
{
|
||||||
struct stat sb;
|
struct stat sb;
|
||||||
|
|
||||||
if (mflg && stat (user_home, &sb) == 0) {
|
if (mflg && (stat (user_home, &sb) == 0)) {
|
||||||
/*
|
/*
|
||||||
* Don't try to move it if it is not a directory
|
* Don't try to move it if it is not a directory
|
||||||
* (but /dev/null for example). --marekm
|
* (but /dev/null for example). --marekm
|
||||||
@ -1270,15 +1293,15 @@ static void move_home (void)
|
|||||||
fprintf (stderr, _("%s: directory %s exists\n"),
|
fprintf (stderr, _("%s: directory %s exists\n"),
|
||||||
Prog, user_newhome);
|
Prog, user_newhome);
|
||||||
fail_exit (E_HOMEDIR);
|
fail_exit (E_HOMEDIR);
|
||||||
} else if (rename (user_home, user_newhome)) {
|
} else if (rename (user_home, user_newhome) != 0) {
|
||||||
if (errno == EXDEV) {
|
if (errno == EXDEV) {
|
||||||
if (mkdir (user_newhome, sb.st_mode & 0777)) {
|
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)) {
|
if (chown (user_newhome, sb.st_uid, sb.st_gid) != 0) {
|
||||||
fprintf (stderr,
|
fprintf (stderr,
|
||||||
_("%s: can't chown %s\n"),
|
_("%s: can't chown %s\n"),
|
||||||
Prog, user_newhome);
|
Prog, user_newhome);
|
||||||
@ -1346,7 +1369,8 @@ static void update_files (void)
|
|||||||
* left alone in case the UID was shared. It doesn't hurt anything
|
* left alone in case the UID was shared. It doesn't hurt anything
|
||||||
* to just leave it be.
|
* to just leave it be.
|
||||||
*/
|
*/
|
||||||
if ((fd = open (LASTLOG_FILE, O_RDWR)) != -1) {
|
fd = open (LASTLOG_FILE, O_RDWR);
|
||||||
|
if (-1 != fd) {
|
||||||
lseek (fd, (off_t) user_id * sizeof ll, SEEK_SET);
|
lseek (fd, (off_t) user_id * sizeof ll, SEEK_SET);
|
||||||
if (read (fd, (char *) &ll, sizeof ll) == sizeof ll) {
|
if (read (fd, (char *) &ll, sizeof ll) == sizeof ll) {
|
||||||
lseek (fd, (off_t) user_newid * sizeof ll, SEEK_SET);
|
lseek (fd, (off_t) user_newid * sizeof ll, SEEK_SET);
|
||||||
@ -1358,7 +1382,8 @@ static void update_files (void)
|
|||||||
/*
|
/*
|
||||||
* Relocate the "faillog" entries in the same manner.
|
* Relocate the "faillog" entries in the same manner.
|
||||||
*/
|
*/
|
||||||
if ((fd = open (FAILLOG_FILE, O_RDWR)) != -1) {
|
fd = open (FAILLOG_FILE, O_RDWR);
|
||||||
|
if (-1 != fd) {
|
||||||
lseek (fd, (off_t) user_id * sizeof fl, SEEK_SET);
|
lseek (fd, (off_t) user_id * sizeof fl, SEEK_SET);
|
||||||
if (read (fd, (char *) &fl, sizeof fl) == sizeof fl) {
|
if (read (fd, (char *) &fl, sizeof fl) == sizeof fl) {
|
||||||
lseek (fd, (off_t) user_newid * sizeof fl, SEEK_SET);
|
lseek (fd, (off_t) user_newid * sizeof fl, SEEK_SET);
|
||||||
@ -1385,11 +1410,13 @@ static void move_mailbox (void)
|
|||||||
|
|
||||||
maildir = getdef_str ("MAIL_DIR");
|
maildir = getdef_str ("MAIL_DIR");
|
||||||
#ifdef MAIL_SPOOL_DIR
|
#ifdef MAIL_SPOOL_DIR
|
||||||
if (!maildir && !getdef_str ("MAIL_FILE"))
|
if ((NULL == maildir) && (getdef_str ("MAIL_FILE") == NULL)) {
|
||||||
maildir = MAIL_SPOOL_DIR;
|
maildir = MAIL_SPOOL_DIR;
|
||||||
|
}
|
||||||
#endif
|
#endif
|
||||||
if (!maildir)
|
if (NULL == maildir) {
|
||||||
return;
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* O_NONBLOCK is to make sure open won't hang on mandatory locks.
|
* O_NONBLOCK is to make sure open won't hang on mandatory locks.
|
||||||
@ -1435,7 +1462,8 @@ static void move_mailbox (void)
|
|||||||
if (lflg) {
|
if (lflg) {
|
||||||
snprintf (newmailfile, sizeof newmailfile, "%s/%s",
|
snprintf (newmailfile, sizeof newmailfile, "%s/%s",
|
||||||
maildir, user_newname);
|
maildir, user_newname);
|
||||||
if (link (mailfile, newmailfile) || unlink (mailfile)) {
|
if ( (link (mailfile, newmailfile) != 0)
|
||||||
|
|| (unlink (mailfile) != 0)) {
|
||||||
perror (_("failed to rename mailbox"));
|
perror (_("failed to rename mailbox"));
|
||||||
}
|
}
|
||||||
#ifdef WITH_AUDIT
|
#ifdef WITH_AUDIT
|
||||||
@ -1468,9 +1496,9 @@ int main (int argc, char **argv)
|
|||||||
*/
|
*/
|
||||||
Prog = Basename (argv[0]);
|
Prog = Basename (argv[0]);
|
||||||
|
|
||||||
setlocale (LC_ALL, "");
|
(void) setlocale (LC_ALL, "");
|
||||||
bindtextdomain (PACKAGE, LOCALEDIR);
|
(void) bindtextdomain (PACKAGE, LOCALEDIR);
|
||||||
textdomain (PACKAGE);
|
(void) textdomain (PACKAGE);
|
||||||
|
|
||||||
sys_ngroups = sysconf (_SC_NGROUPS_MAX);
|
sys_ngroups = sysconf (_SC_NGROUPS_MAX);
|
||||||
user_groups = malloc ((1 + sys_ngroups) * sizeof (char *));
|
user_groups = malloc ((1 + sys_ngroups) * sizeof (char *));
|
||||||
@ -1495,27 +1523,27 @@ int main (int argc, char **argv)
|
|||||||
retval = PAM_USER_UNKNOWN;
|
retval = PAM_USER_UNKNOWN;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (retval == PAM_SUCCESS) {
|
if (PAM_SUCCESS == retval) {
|
||||||
retval = pam_start ("usermod", pampw->pw_name,
|
retval = pam_start ("usermod", pampw->pw_name,
|
||||||
&conv, &pamh);
|
&conv, &pamh);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (retval == PAM_SUCCESS) {
|
if (PAM_SUCCESS == retval) {
|
||||||
retval = pam_authenticate (pamh, 0);
|
retval = pam_authenticate (pamh, 0);
|
||||||
if (retval != PAM_SUCCESS) {
|
if (PAM_SUCCESS != retval) {
|
||||||
pam_end (pamh, retval);
|
(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) {
|
if (PAM_SUCCESS != retval) {
|
||||||
pam_end (pamh, retval);
|
(void) pam_end (pamh, retval);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (retval != PAM_SUCCESS) {
|
if (PAM_SUCCESS != retval) {
|
||||||
fprintf (stderr, _("%s: PAM authentication failed\n"), Prog);
|
fprintf (stderr, _("%s: PAM authentication failed\n"), Prog);
|
||||||
exit (1);
|
exit (1);
|
||||||
}
|
}
|
||||||
@ -1527,19 +1555,22 @@ int main (int argc, char **argv)
|
|||||||
*/
|
*/
|
||||||
open_files ();
|
open_files ();
|
||||||
usr_update ();
|
usr_update ();
|
||||||
if (Gflg || lflg)
|
if (Gflg || lflg) {
|
||||||
grp_update ();
|
grp_update ();
|
||||||
|
}
|
||||||
close_files ();
|
close_files ();
|
||||||
|
|
||||||
nscd_flush_cache ("passwd");
|
nscd_flush_cache ("passwd");
|
||||||
nscd_flush_cache ("group");
|
nscd_flush_cache ("group");
|
||||||
|
|
||||||
if (mflg)
|
if (mflg) {
|
||||||
move_home ();
|
move_home ();
|
||||||
|
}
|
||||||
|
|
||||||
#ifndef NO_MOVE_MAILBOX
|
#ifndef NO_MOVE_MAILBOX
|
||||||
if (lflg || uflg)
|
if (lflg || uflg) {
|
||||||
move_mailbox ();
|
move_mailbox ();
|
||||||
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
if (uflg) {
|
if (uflg) {
|
||||||
@ -1555,10 +1586,12 @@ int main (int argc, char **argv)
|
|||||||
}
|
}
|
||||||
|
|
||||||
#ifdef USE_PAM
|
#ifdef USE_PAM
|
||||||
if (retval == PAM_SUCCESS)
|
if (PAM_SUCCESS == retval) {
|
||||||
pam_end (pamh, PAM_SUCCESS);
|
(void) pam_end (pamh, PAM_SUCCESS);
|
||||||
|
}
|
||||||
#endif /* USE_PAM */
|
#endif /* USE_PAM */
|
||||||
|
|
||||||
exit (E_SUCCESS);
|
exit (E_SUCCESS);
|
||||||
/* NOT REACHED */
|
/* NOT REACHED */
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user