Blame SOURCES/shadow-4.1.5.1-lastlog-unexpire.patch

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