* src/usermod.c: get_number() replaced by getlong().

* src/usermod.c: When the user is renamed, make sure we do not
	override an user with the same name (in passwd or shadow).
This commit is contained in:
nekral-guest 2009-03-15 21:34:20 +00:00
parent 780af2653a
commit a402c4db3b
2 changed files with 25 additions and 18 deletions

View File

@ -1,3 +1,9 @@
2009-03-15 Nicolas François <nicolas.francois@centraliens.net>
* src/usermod.c: get_number() replaced by getlong().
* src/usermod.c: When the user is renamed, make sure we do not
override an user with the same name (in passwd or shadow).
2009-03-15 Nicolas François <nicolas.francois@centraliens.net> 2009-03-15 Nicolas François <nicolas.francois@centraliens.net>
* src/gpasswd.c: log_gpasswd_success_gshadow is in the cleanup * src/gpasswd.c: log_gpasswd_success_gshadow is in the cleanup

View File

@ -153,7 +153,6 @@ static void update_gshadow (void);
#endif #endif
static void grp_update (void); static void grp_update (void);
static long get_number (const char *);
static void process_flags (int, char **); static void process_flags (int, char **);
static void close_files (void); static void close_files (void);
static void open_files (void); static void open_files (void);
@ -400,6 +399,12 @@ static char *new_pw_passwd (char *pw_pass)
static void new_pwent (struct passwd *pwent) static void new_pwent (struct passwd *pwent)
{ {
if (lflg) { if (lflg) {
if (pw_locate (user_newname) != NULL) {
fprintf (stderr,
_("%s: user '%s' already exists in %s\n"),
Prog, user_newname, pw_dbname ());
fail_exit (E_NAME_IN_USE);
}
#ifdef WITH_AUDIT #ifdef WITH_AUDIT
audit_logger (AUDIT_USER_CHAUTHTOK, Prog, audit_logger (AUDIT_USER_CHAUTHTOK, Prog,
"changing name", "changing name",
@ -410,8 +415,7 @@ static void new_pwent (struct passwd *pwent)
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) {
@ -477,6 +481,12 @@ 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) {
if (spw_locate (user_newname) != NULL) {
fprintf (stderr,
_("%s: user '%s' already exists in %s\n"),
Prog, user_newname, spw_dbname ());
fail_exit (E_NAME_IN_USE);
}
spent->sp_namp = xstrdup (user_newname); spent->sp_namp = xstrdup (user_newname);
} }
@ -784,20 +794,6 @@ static void grp_update (void)
#endif #endif
} }
static long get_number (const char *numstr)
{
long val;
char *endptr;
val = strtol (numstr, &endptr, 10);
if (('\0' != *endptr) || (ERANGE == errno)) {
fprintf (stderr, _("%s: invalid numeric argument '%s'\n"), Prog,
numstr);
exit (E_BAD_ARG);
}
return val;
}
/* /*
* process_flags - perform command line argument setting * process_flags - perform command line argument setting
* *
@ -938,7 +934,12 @@ static void process_flags (int argc, char **argv)
eflg = true; eflg = true;
break; break;
case 'f': case 'f':
user_newinactive = get_number (optarg); if (getlong (optarg, &user_newinactive) == 0) {
fprintf (stderr,
_("%s: invalid numeric argument '%s'\n"),
Prog, optarg);
usage ();
}
fflg = true; fflg = true;
break; break;
case 'g': case 'g':