fa2969
diff -up shadow-4.1.5.1/man/lastlog.8.xml.unexpire shadow-4.1.5.1/man/lastlog.8.xml
fa2969
--- shadow-4.1.5.1/man/lastlog.8.xml.unexpire	2012-05-25 13:45:28.000000000 +0200
fa2969
+++ shadow-4.1.5.1/man/lastlog.8.xml	2016-04-28 15:09:11.026084219 +0200
fa2969
@@ -105,6 +105,17 @@
fa2969
       </varlistentry>
fa2969
       <varlistentry>
fa2969
 	<term>
fa2969
+	  <option>-C</option>, <option>--clear</option>
fa2969
+	</term>
fa2969
+	<listitem>
fa2969
+	  <para>
fa2969
+	    Clear lastlog record of an user. This option can be used only together
fa2969
+	    with <option>-u</option> (<option>--user</option>)).
fa2969
+	  </para>
fa2969
+	</listitem>
fa2969
+      </varlistentry>
fa2969
+      <varlistentry>
fa2969
+	<term>
fa2969
 	  <option>-h</option>, <option>--help</option>
fa2969
 	</term>
fa2969
 	<listitem>
fa2969
@@ -124,6 +135,17 @@
fa2969
 	  </para>
fa2969
 	</listitem>
fa2969
       </varlistentry>
fa2969
+      <varlistentry>
fa2969
+	<term>
fa2969
+	  <option>-S</option>, <option>--set</option>
fa2969
+	</term>
fa2969
+	<listitem>
fa2969
+	  <para>
fa2969
+	    Set lastlog record of an user to the current time. This option can be
fa2969
+	    used only together with <option>-u</option> (<option>--user</option>)).
fa2969
+	  </para>
fa2969
+	</listitem>
fa2969
+      </varlistentry>
fa2969
       <varlistentry>
fa2969
 	<term>
fa2969
 	  <option>-t</option>, <option>--time</option>
fa2969
diff -up shadow-4.1.5.1/src/lastlog.c.unexpire shadow-4.1.5.1/src/lastlog.c
fa2969
--- shadow-4.1.5.1/src/lastlog.c.unexpire	2011-11-06 21:54:18.000000000 +0100
fa2969
+++ shadow-4.1.5.1/src/lastlog.c	2016-04-28 15:49:30.253371990 +0200
fa2969
@@ -55,6 +55,13 @@
fa2969
 #endif
fa2969
 
fa2969
 /*
fa2969
+ * Needed for systems with older audit library.
fa2969
+ */
fa2969
+#ifndef AUDIT_ACCT_UNLOCK
fa2969
+#define AUDIT_ACCT_UNLOCK       1136
fa2969
+#endif
fa2969
+
fa2969
+/*
fa2969
  * Global variables
fa2969
  */
fa2969
 const char *Prog;		/* Program name */
fa2969
@@ -71,6 +78,8 @@ static struct stat statbuf;	/* fstat buf
fa2969
 static bool uflg = false;	/* print only an user of range of users */
fa2969
 static bool tflg = false;	/* print is restricted to most recent days */
fa2969
 static bool bflg = false;	/* print excludes most recent days */
fa2969
+static bool Cflg = false;	/* clear record for user */
fa2969
+static bool Sflg = false;	/* set record for user */
fa2969
 
fa2969
 #define	NOW	(time ((time_t *) 0))
fa2969
 
fa2969
@@ -83,8 +92,10 @@ static /*@noreturn@*/void usage (int sta
fa2969
 	                  "Options:\n"),
fa2969
 	                Prog);
fa2969
 	(void) fputs (_("  -b, --before DAYS             print only lastlog records older than DAYS\n"), usageout);
fa2969
+	(void) fputs (_("  -C, --clear                   clear lastlog record of an user (usable only with -u)\n"), usageout);
fa2969
 	(void) fputs (_("  -h, --help                    display this help message and exit\n"), usageout);
fa2969
 	(void) fputs (_("  -R, --root CHROOT_DIR         directory to chroot into\n"), usageout);
fa2969
+	(void) fputs (_("  -S, --set                     set lastlog record to current time (usable only with -u)\n"), usageout);
fa2969
 	(void) fputs (_("  -t, --time DAYS               print only lastlog records more recent than DAYS\n"), usageout);
fa2969
 	(void) fputs (_("  -u, --user LOGIN              print lastlog record of the specified LOGIN\n"), usageout);
fa2969
 	(void) fputs ("\n", usageout);
fa2969
@@ -194,6 +205,80 @@ static void print (void)
fa2969
 	}
fa2969
 }
fa2969
 
fa2969
+static void update_one (/*@null@*/const struct passwd *pw)
fa2969
+{
fa2969
+	off_t offset;
fa2969
+	struct lastlog ll;
fa2969
+	int err;
fa2969
+
fa2969
+	if (NULL == pw) {
fa2969
+		return;
fa2969
+	}
fa2969
+
fa2969
+	offset = (off_t) pw->pw_uid * sizeof (ll);
fa2969
+	/* fseeko errors are not really relevant for us. */
fa2969
+	err = fseeko (lastlogfile, offset, SEEK_SET);
fa2969
+	assert (0 == err);
fa2969
+
fa2969
+	memzero (&ll, sizeof (ll));
fa2969
+
fa2969
+	if (Sflg) {
fa2969
+		ll.ll_time = NOW;
fa2969
+#ifdef HAVE_LL_HOST
fa2969
+		strcpy (ll.ll_host, "localhost");
fa2969
+#endif
fa2969
+		strcpy (ll.ll_line, "lastlog");
fa2969
+#ifdef WITH_AUDIT
fa2969
+		audit_logger (AUDIT_ACCT_UNLOCK, Prog,
fa2969
+			"clearing-lastlog",
fa2969
+			pw->pw_name, (unsigned int) pw->pw_uid, SHADOW_AUDIT_SUCCESS);
fa2969
+#endif
fa2969
+	}
fa2969
+#ifdef WITH_AUDIT
fa2969
+	else {
fa2969
+		audit_logger (AUDIT_ACCT_UNLOCK, Prog,
fa2969
+			"refreshing-lastlog",
fa2969
+			pw->pw_name, (unsigned int) pw->pw_uid, SHADOW_AUDIT_SUCCESS);
fa2969
+	}
fa2969
+#endif
fa2969
+
fa2969
+	if (fwrite (&ll, sizeof(ll), 1, lastlogfile) != 1) {
fa2969
+			fprintf (stderr,
fa2969
+			         _("%s: Failed to update the entry for UID %lu\n"),
fa2969
+			         Prog, (unsigned long int)pw->pw_uid);
fa2969
+			exit (EXIT_FAILURE);
fa2969
+	}
fa2969
+}
fa2969
+
fa2969
+static void update (void)
fa2969
+{
fa2969
+	const struct passwd *pwent;
fa2969
+
fa2969
+	if (!uflg) /* safety measure */
fa2969
+		return;
fa2969
+
fa2969
+	if (has_umin && has_umax && (umin == umax)) {
fa2969
+		update_one (getpwuid ((uid_t)umin));
fa2969
+	} else {
fa2969
+		setpwent ();
fa2969
+		while ( (pwent = getpwent ()) != NULL ) {
fa2969
+			if ((has_umin && (pwent->pw_uid < (uid_t)umin))
fa2969
+				|| (has_umax && (pwent->pw_uid > (uid_t)umax))) {
fa2969
+				continue;
fa2969
+			}
fa2969
+			update_one (pwent);
fa2969
+		}
fa2969
+		endpwent ();
fa2969
+	}
fa2969
+
fa2969
+	if (fflush (lastlogfile) != 0 || fsync (fileno (lastlogfile)) != 0) {
fa2969
+			fprintf (stderr,
fa2969
+			         _("%s: Failed to update the lastlog file\n"),
fa2969
+			         Prog);
fa2969
+			exit (EXIT_FAILURE);
fa2969
+	}
fa2969
+}
fa2969
+
fa2969
 int main (int argc, char **argv)
fa2969
 {
fa2969
 	/*
fa2969
@@ -208,18 +293,24 @@ int main (int argc, char **argv)
fa2969
 
fa2969
 	process_root_flag ("-R", argc, argv);
fa2969
 
fa2969
+#ifdef WITH_AUDIT
fa2969
+	audit_help_open ();
fa2969
+#endif
fa2969
+
fa2969
 	{
fa2969
 		int c;
fa2969
 		static struct option const longopts[] = {
fa2969
 			{"before", required_argument, NULL, 'b'},
fa2969
+			{"clear",  no_argument,       NULL, 'C'},
fa2969
 			{"help",   no_argument,       NULL, 'h'},
fa2969
 			{"root",   required_argument, NULL, 'R'},
fa2969
+			{"set",    no_argument,       NULL, 'S'},
fa2969
 			{"time",   required_argument, NULL, 't'},
fa2969
 			{"user",   required_argument, NULL, 'u'},
fa2969
 			{NULL, 0, NULL, '\0'}
fa2969
 		};
fa2969
 
fa2969
-		while ((c = getopt_long (argc, argv, "b:hR:t:u:", longopts,
fa2969
+		while ((c = getopt_long (argc, argv, "b:ChR:St:u:", longopts,
fa2969
 		                         NULL)) != -1) {
fa2969
 			switch (c) {
fa2969
 			case 'b':
fa2969
@@ -235,11 +326,21 @@ int main (int argc, char **argv)
fa2969
 				bflg = true;
fa2969
 				break;
fa2969
 			}
fa2969
+			case 'C':
fa2969
+			{
fa2969
+				Cflg = true;
fa2969
+				break;
fa2969
+			}
fa2969
 			case 'h':
fa2969
 				usage (EXIT_SUCCESS);
fa2969
 				/*@notreached@*/break;
fa2969
 			case 'R': /* no-op, handled in process_root_flag () */
fa2969
 				break;
fa2969
+			case 'S':
fa2969
+			{
fa2969
+				Sflg = true;
fa2969
+				break;
fa2969
+			}
fa2969
 			case 't':
fa2969
 			{
fa2969
 				unsigned long days;
fa2969
@@ -294,9 +395,21 @@ int main (int argc, char **argv)
fa2969
 			         Prog, argv[optind]);
fa2969
 			usage (EXIT_FAILURE);
fa2969
 		}
fa2969
+		if (Cflg && Sflg) {
fa2969
+			fprintf (stderr,
fa2969
+			         _("%s: Option -C cannot be used together with option -S\n"),
fa2969
+			         Prog);
fa2969
+			usage (EXIT_FAILURE);
fa2969
+		}
fa2969
+		if ((Cflg || Sflg) && !uflg) {
fa2969
+			fprintf (stderr,
fa2969
+			         _("%s: Options -C and -S require option -u to specify the user\n"),
fa2969
+			         Prog);
fa2969
+			usage (EXIT_FAILURE);
fa2969
+		}
fa2969
 	}
fa2969
 
fa2969
-	lastlogfile = fopen (LASTLOG_FILE, "r");
fa2969
+	lastlogfile = fopen (LASTLOG_FILE, (Cflg || Sflg)?"r+":"r");
fa2969
 	if (NULL == lastlogfile) {
fa2969
 		perror (LASTLOG_FILE);
fa2969
 		exit (EXIT_FAILURE);
fa2969
@@ -310,7 +423,10 @@ int main (int argc, char **argv)
fa2969
 		exit (EXIT_FAILURE);
fa2969
 	}
fa2969
 
fa2969
-	print ();
fa2969
+	if (Cflg || Sflg)
fa2969
+		update ();
fa2969
+	else
fa2969
+		print ();
fa2969
 
fa2969
 	(void) fclose (lastlogfile);
fa2969
 
fa2969
diff -up shadow-4.1.5.1/src/Makefile.am.unexpire shadow-4.1.5.1/src/Makefile.am
fa2969
--- shadow-4.1.5.1/src/Makefile.am.unexpire	2011-11-18 22:23:30.000000000 +0100
fa2969
+++ shadow-4.1.5.1/src/Makefile.am	2016-04-28 15:09:11.027084241 +0200
fa2969
@@ -90,6 +90,7 @@ groupmod_LDADD = $(LDADD) $(LIBPAM_SUID)
fa2969
 grpck_LDADD    = $(LDADD) $(LIBSELINUX)
fa2969
 grpconv_LDADD  = $(LDADD) $(LIBSELINUX)
fa2969
 grpunconv_LDADD = $(LDADD) $(LIBSELINUX)
fa2969
+lastlog_LDADD   = $(LDADD) $(LIBAUDIT)
fa2969
 login_SOURCES  = \
fa2969
 	login.c \
fa2969
 	login_nopam.c
fa2969
diff -up shadow-4.1.5.1/src/Makefile.in.unexpire shadow-4.1.5.1/src/Makefile.in
fa2969
--- shadow-4.1.5.1/src/Makefile.in.unexpire	2012-05-25 13:56:51.000000000 +0200
fa2969
+++ shadow-4.1.5.1/src/Makefile.in	2016-04-28 15:09:11.027084241 +0200
fa2969
@@ -162,7 +162,7 @@ id_DEPENDENCIES = $(am__DEPENDENCIES_1)
fa2969
 	$(top_builddir)/lib/libshadow.la
fa2969
 lastlog_SOURCES = lastlog.c
fa2969
 lastlog_OBJECTS = lastlog.$(OBJEXT)
fa2969
-lastlog_LDADD = $(LDADD)
fa2969
+lastlog_LDADD = $(LDADD) $(LIBAUDIT)
fa2969
 lastlog_DEPENDENCIES = $(am__DEPENDENCIES_1) $(am__DEPENDENCIES_1) \
fa2969
 	$(top_builddir)/libmisc/libmisc.a \
fa2969
 	$(top_builddir)/lib/libshadow.la