Goal: Log login failures to the btmp file

Notes:
 * I'm not sure login should add an entry in the FTMP file when PAM is used.
   (but nothing in /etc/login.defs indicates that the failure is not logged)

Index: shadow-4.1.0/src/login.c
===================================================================
--- shadow-4.1.0.orig/src/login.c
+++ shadow-4.1.0/src/login.c
@@ -722,6 +722,29 @@
 #endif				/* WITH_AUDIT */
 
 			fprintf (stderr, "\nLogin incorrect\n");
+			  if (getdef_str("FTMP_FILE") != NULL) {
+#if HAVE_UTMPX_H
+			    failent = utxent;
+			    if (sizeof (failent.ut_tv) == sizeof (struct timeval))
+				    gettimeofday((struct timeval *)
+				                 &failent.ut_tv, NULL);
+			    else {
+				    struct timeval tv;
+
+				    gettimeofday (&tv, NULL);
+				    failent.ut_tv.tv_sec = tv.tv_sec;
+				    failent.ut_tv.tv_usec = tv.tv_usec;
+			    }
+#else
+			    failent = utent;
+			    failent.ut_time = time(NULL);
+#endif
+			    strncpy(failent.ut_user, failent_user, sizeof(failent.ut_user));
+#ifdef USER_PROCESS
+			    failent.ut_type = USER_PROCESS;
+#endif
+			    failtmp(&failent);
+			  }
 
 			/*
 			 * Let's give it another go around.
Index: shadow-4.1.0/lib/getdef.c
===================================================================
--- shadow-4.1.0.orig/lib/getdef.c
+++ shadow-4.1.0/lib/getdef.c
@@ -58,6 +58,7 @@
 	{"ERASECHAR", NULL},
 	{"FAIL_DELAY", NULL},
 	{"FAKE_SHELL", NULL},
+	{"FTMP_FILE", NULL},
 	{"GID_MAX", NULL},
 	{"GID_MIN", NULL},
 	{"HUSHLOGIN_FILE", NULL},
@@ -93,7 +94,6 @@
 	{"ENVIRON_FILE", NULL},
 	{"ENV_TZ", NULL},
 	{"FAILLOG_ENAB", NULL},
-	{"FTMP_FILE", NULL},
 	{"ISSUE_FILE", NULL},
 	{"LASTLOG_ENAB", NULL},
 	{"LOGIN_STRING", NULL},
