diff --git a/ChangeLog b/ChangeLog index f63c1ae5..36947bba 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +2009-04-22 Nicolas François + + * src/login.c: Added update_utmp() to group the prepare_utmp and + setutmp (and the utmpx versions). + 2009-04-22 Nicolas François * src/login.c: Do not include netdb.h. gethostbyname() is no more diff --git a/src/login.c b/src/login.c index cba0e614..90b08082 100644 --- a/src/login.c +++ b/src/login.c @@ -118,6 +118,10 @@ static void usage (void); static void setup_tty (void); static void process_flags (int, char *const *); static const char *get_failent_user (const char *user); +static void update_utmp (const char *username, + const char *tty, + const char *hostname, + const struct utmp *utent); #ifndef USE_PAM static struct faillog faillog; @@ -438,6 +442,32 @@ static const char *get_failent_user (const char *user) return failent_user; } +/* + * update_utmp - Update or create an utmp entry in utmp, wtmp, utmpw, and + * wtmpx + * + * utent should be the utmp entry returned by get_current_utmp (or + * NULL). + */ +static void update_utmp (const char *username, + const char *tty, + const char *hostname, + /*@null@*/const struct utmp *utent) +{ + struct utmp *ut = prepare_utmp (username, tty, hostname, utent); +#ifdef HAVE_UTMPX_H + struct utmpx *utx = prepare_utmpx (username, tty, hostname, utent); +#endif /* HAVE_UTMPX_H */ + + (void) setutmp (ut); /* make entry in the utmp & wtmp files */ + free (ut); + +#ifdef HAVE_UTMPX_H + (void) setutmpx (utx); /* make entry in the utmpx & wtmpx files */ + free (utx); +#endif /* HAVE_UTMPX_H */ +} + /* * login - create a new login session for a user * @@ -1051,14 +1081,7 @@ int main (int argc, char **argv) addenv ("IFS= \t\n", NULL); /* ... instead, set a safe IFS */ } - struct utmp *ut = prepare_utmp (username, tty, hostname, utent); - (void) setutmp (ut); /* make entry in the utmp & wtmp files */ - free (ut); -#ifdef HAVE_UTMPX_H - struct utmpx *utx = prepare_utmpx (username, tty, hostname, utent); - (void) setutmpx (utx); /* make entry in the utmpx & wtmpx files */ - free (utx); -#endif /* HAVE_UTMPX_H */ + update_utmp (username, tty, hostname, utent); if (pwd->pw_shell[0] == '*') { /* subsystem root */ pwd->pw_shell++; /* skip the '*' */