Always define user_newcomment, user_newshell, user_newexpire, and

user_newinactive. It is more simple to always have user_<x> as the old
field, and user_new<x> as the new field (even if the field did not change)
instead of changing the algorithm depending on WITH_AUDIT.
This commit is contained in:
nekral-guest 2008-01-23 21:19:08 +00:00
parent 294e3a632e
commit 0d1be15e0f
2 changed files with 23 additions and 75 deletions

View File

@ -1,3 +1,11 @@
2008-01-23 Nicolas François <nicolas.francois@centraliens.net>
* src/usermod.c: Always define user_newcomment, user_newshell,
user_newexpire, and user_newinactive. It is more simple to always
have user_<x> as the old field, and user_new<x> as the new field
(even if the field did not change) instead of changing the
algorithm depending on WITH_AUDIT.
2008-01-23 Nicolas François <nicolas.francois@centraliens.net> 2008-01-23 Nicolas François <nicolas.francois@centraliens.net>
* src/usermod.c: user_newname can only be used in WITH_AUDIT code * src/usermod.c: user_newname can only be used in WITH_AUDIT code

View File

@ -87,21 +87,18 @@ static uid_t user_newid;
static gid_t user_gid; static gid_t user_gid;
static gid_t user_newgid; static gid_t user_newgid;
static char *user_comment; static char *user_comment;
static char *user_newcomment;
static char *user_home; static char *user_home;
static char *user_newhome; static char *user_newhome;
static char *user_shell; static char *user_shell;
static char *user_newshell;
static long user_expire; static long user_expire;
static long user_newexpire;
static long user_inactive; static long user_inactive;
static long user_newinactive;
static long sys_ngroups; static long sys_ngroups;
static char **user_groups; /* NULL-terminated list */ static char **user_groups; /* NULL-terminated list */
#ifdef WITH_AUDIT
static char *user_newcomment; /* Audit */
static char *user_newshell; /* Audit */
static long user_newexpire; /* Audit */
static long user_newinactive; /* Audit */
#endif
static char *Prog; static char *Prog;
static int static int
@ -319,8 +316,7 @@ static char *new_pw_passwd (char *pw_pass)
audit_logger (AUDIT_USER_CHAUTHTOK, Prog, "updating passwd", audit_logger (AUDIT_USER_CHAUTHTOK, Prog, "updating passwd",
user_newname, user_newid, 0); user_newname, user_newid, 0);
#endif #endif
SYSLOG ((LOG_INFO, "lock user `%s' password", SYSLOG ((LOG_INFO, "lock user `%s' password", user_newname));
lflg ? user_newname : user_name));
strcpy (buf, "!"); strcpy (buf, "!");
strcat (buf, pw_pass); strcat (buf, pw_pass);
pw_pass = buf; pw_pass = buf;
@ -339,8 +335,7 @@ static char *new_pw_passwd (char *pw_pass)
audit_logger (AUDIT_USER_CHAUTHTOK, Prog, "updating password", audit_logger (AUDIT_USER_CHAUTHTOK, Prog, "updating password",
user_newname, user_newid, 0); user_newname, user_newid, 0);
#endif #endif
SYSLOG ((LOG_INFO, "unlock user `%s' password", SYSLOG ((LOG_INFO, "unlock user `%s' password", user_newname));
lflg ? user_newname : user_name));
s = pw_pass; s = pw_pass;
while (*s) { while (*s) {
*s = *(s + 1); *s = *(s + 1);
@ -351,8 +346,7 @@ static char *new_pw_passwd (char *pw_pass)
audit_logger (AUDIT_USER_CHAUTHTOK, Prog, "changing password", audit_logger (AUDIT_USER_CHAUTHTOK, Prog, "changing password",
user_newname, user_newid, 1); user_newname, user_newid, 1);
#endif #endif
SYSLOG ((LOG_INFO, "change user `%s' password", SYSLOG ((LOG_INFO, "change user `%s' password", user_newname));
lflg ? user_newname : user_name));
pw_pass = xstrdup (user_pass); pw_pass = xstrdup (user_pass);
} }
return pw_pass; return pw_pass;
@ -404,10 +398,8 @@ static void new_pwent (struct passwd *pwent)
#ifdef WITH_AUDIT #ifdef WITH_AUDIT
audit_logger (AUDIT_USER_CHAUTHTOK, Prog, "changing comment", audit_logger (AUDIT_USER_CHAUTHTOK, Prog, "changing comment",
user_newname, user_newid, 1); user_newname, user_newid, 1);
pwent->pw_gecos = user_newcomment;
#else
pwent->pw_gecos = user_comment;
#endif #endif
pwent->pw_gecos = user_newcomment;
} }
if (dflg) { if (dflg) {
@ -425,15 +417,10 @@ static void new_pwent (struct passwd *pwent)
#ifdef WITH_AUDIT #ifdef WITH_AUDIT
audit_logger (AUDIT_USER_CHAUTHTOK, Prog, "changing user shell", audit_logger (AUDIT_USER_CHAUTHTOK, Prog, "changing user shell",
user_newname, user_newid, 1); user_newname, user_newid, 1);
#endif
SYSLOG ((LOG_INFO, "change user `%s' shell from `%s' to `%s'", SYSLOG ((LOG_INFO, "change user `%s' shell from `%s' to `%s'",
pwent->pw_name, pwent->pw_shell, user_newshell)); pwent->pw_name, pwent->pw_shell, user_newshell));
pwent->pw_shell = user_newshell; pwent->pw_shell = user_newshell;
#else
SYSLOG ((LOG_INFO,
"change user `%s' shell from `%s' to `%s'",
pwent->pw_name, pwent->pw_shell, user_shell));
pwent->pw_shell = user_shell;
#endif
} }
} }
@ -453,17 +440,11 @@ static void new_spent (struct spwd *spent)
audit_logger (AUDIT_USER_CHAUTHTOK, Prog, audit_logger (AUDIT_USER_CHAUTHTOK, Prog,
"changing inactive days", user_newname, "changing inactive days", user_newname,
user_newid, 1); user_newid, 1);
#endif
SYSLOG ((LOG_INFO, SYSLOG ((LOG_INFO,
"change user `%s' inactive from `%ld' to `%ld'", "change user `%s' inactive from `%ld' to `%ld'",
spent->sp_namp, spent->sp_inact, user_newinactive)); spent->sp_namp, spent->sp_inact, user_newinactive));
spent->sp_inact = user_newinactive; spent->sp_inact = user_newinactive;
#else
SYSLOG ((LOG_INFO,
"change user `%s' inactive from `%ld' to `%ld'",
spent->sp_namp, spent->sp_inact, user_inactive));
spent->sp_inact = user_inactive;
#endif
} }
if (eflg) { if (eflg) {
/* XXX - dates might be better than numbers of days. --marekm */ /* XXX - dates might be better than numbers of days. --marekm */
@ -510,17 +491,11 @@ static void new_spent (struct spwd *spent)
"changing expiration date", user_newname, "changing expiration date", user_newname,
user_newid, 1); user_newid, 1);
} }
#endif
SYSLOG ((LOG_INFO, SYSLOG ((LOG_INFO,
"change user `%s' expiration from `%ld' to `%ld'", "change user `%s' expiration from `%ld' to `%ld'",
spent->sp_namp, spent->sp_expire, user_newexpire)); spent->sp_namp, spent->sp_expire, user_newexpire));
spent->sp_expire = user_newexpire; spent->sp_expire = user_newexpire;
#else
SYSLOG ((LOG_INFO,
"change user `%s' expiration from `%ld' to `%ld'",
spent->sp_namp, spent->sp_expire, user_expire));
spent->sp_expire = user_expire;
#endif
} }
spent->sp_pwdp = new_pw_passwd (spent->sp_pwdp); spent->sp_pwdp = new_pw_passwd (spent->sp_pwdp);
if (pflg) if (pflg)
@ -612,17 +587,14 @@ static void update_group (void)
SYSLOG ((LOG_INFO, "delete `%s' from group `%s'", SYSLOG ((LOG_INFO, "delete `%s' from group `%s'",
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, ngrp->gr_mem = add_list (ngrp->gr_mem, user_newname);
lflg ? user_newname :
user_name);
changed = 1; changed = 1;
#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);
#endif #endif
SYSLOG ((LOG_INFO, "add `%s' to group `%s'", SYSLOG ((LOG_INFO, "add `%s' to group `%s'",
lflg ? user_newname : user_name, user_newname, ngrp->gr_name));
ngrp->gr_name));
} }
if (!changed) if (!changed)
continue; continue;
@ -724,9 +696,7 @@ static void update_gshadow (void)
"delete `%s' from shadow group `%s'", "delete `%s' from shadow group `%s'",
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, nsgrp->sg_mem = add_list (nsgrp->sg_mem, user_newname);
lflg ? user_newname :
user_name);
changed = 1; changed = 1;
#ifdef WITH_AUDIT #ifdef WITH_AUDIT
audit_logger (AUDIT_USER_CHAUTHTOK, Prog, audit_logger (AUDIT_USER_CHAUTHTOK, Prog,
@ -734,8 +704,7 @@ static void update_gshadow (void)
user_newname, -1, 1); user_newname, -1, 1);
#endif #endif
SYSLOG ((LOG_INFO, "add `%s' to shadow group `%s'", SYSLOG ((LOG_INFO, "add `%s' to shadow group `%s'",
lflg ? user_newname : user_name, user_newname, nsgrp->sg_name));
nsgrp->sg_name));
} }
if (!changed) if (!changed)
continue; continue;
@ -830,14 +799,12 @@ static void process_flags (int argc, char **argv)
user_home = xstrdup (pwd->pw_dir); user_home = xstrdup (pwd->pw_dir);
user_shell = xstrdup (pwd->pw_shell); user_shell = xstrdup (pwd->pw_shell);
} }
#ifdef WITH_AUDIT
user_newname = user_name; user_newname = user_name;
user_newid = user_id; user_newid = user_id;
user_newgid = user_gid; user_newgid = user_gid;
user_newcomment = user_comment; user_newcomment = user_comment;
user_newhome = user_home; user_newhome = user_home;
user_newshell = user_shell; user_newshell = user_shell;
#endif
#ifdef USE_NIS #ifdef USE_NIS
/* /*
@ -865,10 +832,8 @@ static void process_flags (int argc, char **argv)
if (is_shadow_pwd && (spwd = getspnam (user_name))) { if (is_shadow_pwd && (spwd = getspnam (user_name))) {
user_expire = spwd->sp_expire; user_expire = spwd->sp_expire;
user_inactive = spwd->sp_inact; user_inactive = spwd->sp_inact;
#ifdef WITH_AUDIT
user_newexpire = user_expire; user_newexpire = user_expire;
user_newinactive = user_inactive; user_newinactive = user_inactive;
#endif
} }
} }
@ -910,11 +875,7 @@ static void process_flags (int argc, char **argv)
Prog, optarg); Prog, optarg);
exit (E_BAD_ARG); exit (E_BAD_ARG);
} }
#ifdef WITH_AUDIT
user_newcomment = optarg; user_newcomment = optarg;
#else
user_comment = optarg;
#endif
cflg++; cflg++;
break; break;
case 'd': case 'd':
@ -929,38 +890,21 @@ static void process_flags (int argc, char **argv)
break; break;
case 'e': case 'e':
if (*optarg) { if (*optarg) {
#ifdef WITH_AUDIT
user_newexpire = strtoday (optarg); user_newexpire = strtoday (optarg);
if (user_newexpire == -1) { if (user_newexpire == -1) {
#else /* } */
user_expire = strtoday (optarg);
if (user_expire == -1) {
#endif
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);
} }
#ifdef WITH_AUDIT
user_newexpire *= DAY / SCALE; user_newexpire *= DAY / SCALE;
#else
user_expire *= DAY / SCALE;
#endif
} else } else
#ifdef WITH_AUDIT
user_newexpire = -1; user_newexpire = -1;
#else
user_expire = -1;
#endif
eflg++; eflg++;
break; break;
case 'f': case 'f':
#ifdef WITH_AUDIT
user_newinactive = get_number (optarg); user_newinactive = get_number (optarg);
#else
user_inactive = get_number (optarg);
#endif
fflg++; fflg++;
break; break;
case 'g': case 'g':
@ -1017,11 +961,7 @@ static void process_flags (int argc, char **argv)
Prog, optarg); Prog, optarg);
exit (E_BAD_ARG); exit (E_BAD_ARG);
} }
#ifdef WITH_AUDIT
user_newshell = optarg; user_newshell = optarg;
#else
user_shell = optarg;
#endif
sflg++; sflg++;
break; break;
case 'u': case 'u':