]> granicus.if.org Git - shadow/commitdiff
* src/login.c: Added update_utmp() to group the prepare_utmp and
authornekral-guest <nekral-guest@5a98b0ae-9ef6-0310-add3-de5d479b70d7>
Wed, 22 Apr 2009 19:58:39 +0000 (19:58 +0000)
committernekral-guest <nekral-guest@5a98b0ae-9ef6-0310-add3-de5d479b70d7>
Wed, 22 Apr 2009 19:58:39 +0000 (19:58 +0000)
setutmp (and the utmpx versions).

ChangeLog
src/login.c

index f63c1ae5a57c7adb1cb599b27ae7d8e2bc6a55b1..36947bba52370879485d782b4b17c722adeef7bf 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,8 @@
+2009-04-22  Nicolas François  <nicolas.francois@centraliens.net>
+
+       * src/login.c: Added update_utmp() to group the prepare_utmp and
+       setutmp (and the utmpx versions).
+
 2009-04-22  Nicolas François  <nicolas.francois@centraliens.net>
 
        * src/login.c: Do not include netdb.h. gethostbyname() is no more
index cba0e614b936d71598784570f6abab157b57a36a..90b08082591ac4e52a5f1c50695a415096233d86 100644 (file)
@@ -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 '*' */