+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>
* src/gpasswd.c: log_gpasswd_success_gshadow is in the cleanup
#endif
static void grp_update (void);
-static long get_number (const char *);
static void process_flags (int, char **);
static void close_files (void);
static void open_files (void);
static void new_pwent (struct passwd *pwent)
{
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
audit_logger (AUDIT_USER_CHAUTHTOK, Prog,
"changing name",
pwent->pw_name = xstrdup (user_newname);
}
if (!is_shadow_pwd) {
- pwent->pw_passwd =
- new_pw_passwd (pwent->pw_passwd);
+ pwent->pw_passwd = new_pw_passwd (pwent->pw_passwd);
}
if (uflg) {
static void new_spent (struct spwd *spent)
{
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);
}
#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
*
eflg = true;
break;
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;
break;
case 'g':