[Midnightbsd-cvs] src [11493] trunk/usr.bin/login: sync with freebsd.

laffer1 at midnightbsd.org laffer1 at midnightbsd.org
Sat Jul 7 13:32:55 EDT 2018


Revision: 11493
          http://svnweb.midnightbsd.org/src/?rev=11493
Author:   laffer1
Date:     2018-07-07 13:32:54 -0400 (Sat, 07 Jul 2018)
Log Message:
-----------
sync with freebsd.

Modified Paths:
--------------
    trunk/usr.bin/login/Makefile
    trunk/usr.bin/login/login.1
    trunk/usr.bin/login/login.c
    trunk/usr.bin/login/login.h
    trunk/usr.bin/login/login_audit.c
    trunk/usr.bin/login/login_fbtab.c
    trunk/usr.bin/login/pathnames.h

Property Changed:
----------------
    trunk/usr.bin/login/login.1

Modified: trunk/usr.bin/login/Makefile
===================================================================
--- trunk/usr.bin/login/Makefile	2018-07-07 17:32:26 UTC (rev 11492)
+++ trunk/usr.bin/login/Makefile	2018-07-07 17:32:54 UTC (rev 11493)
@@ -1,5 +1,6 @@
+# $MidnightBSD$
 # 	@(#)Makefile	8.1 (Berkeley) 7/19/93
-# $MidnightBSD$
+# $FreeBSD: stable/10/usr.bin/login/Makefile 201386 2010-01-02 10:27:05Z ed $
 
 .include <bsd.own.mk>
 

Modified: trunk/usr.bin/login/login.1
===================================================================
--- trunk/usr.bin/login/login.1	2018-07-07 17:32:26 UTC (rev 11492)
+++ trunk/usr.bin/login/login.1	2018-07-07 17:32:54 UTC (rev 11493)
@@ -1,3 +1,4 @@
+.\" $MidnightBSD$
 .\" Copyright (c) 1980, 1990, 1993
 .\"	The Regents of the University of California.  All rights reserved.
 .\"
@@ -26,7 +27,7 @@
 .\" SUCH DAMAGE.
 .\"
 .\"	@(#)login.1	8.2 (Berkeley) 5/5/94
-.\" $MidnightBSD$
+.\" $FreeBSD: stable/10/usr.bin/login/login.1 236892 2012-06-11 16:18:39Z des $
 .\"
 .Dd September 13, 2006
 .Dt LOGIN 1


Property changes on: trunk/usr.bin/login/login.1
___________________________________________________________________
Added: svn:keywords
## -0,0 +1 ##
+MidnightBSD=%H
\ No newline at end of property
Modified: trunk/usr.bin/login/login.c
===================================================================
--- trunk/usr.bin/login/login.c	2018-07-07 17:32:26 UTC (rev 11492)
+++ trunk/usr.bin/login/login.c	2018-07-07 17:32:54 UTC (rev 11493)
@@ -1,3 +1,4 @@
+/* $MidnightBSD$ */
 /*-
  * Copyright (c) 1980, 1987, 1988, 1991, 1993, 1994
  *	The Regents of the University of California.  All rights reserved.
@@ -45,7 +46,7 @@
 #endif
 
 #include <sys/cdefs.h>
-__MBSDID("$MidnightBSD$");
+__FBSDID("$FreeBSD: stable/10/usr.bin/login/login.c 288164 2015-09-24 00:54:46Z delphij $");
 
 /*
  * login [ name ]
@@ -63,7 +64,6 @@
 #include <err.h>
 #include <errno.h>
 #include <grp.h>
-#include <libutil.h>
 #include <login_cap.h>
 #include <pwd.h>
 #include <setjmp.h>
@@ -83,6 +83,7 @@
 
 static int		 auth_pam(void);
 static void		 bail(int, int);
+static void		 bail_internal(int, int, int);
 static int		 export(const char *);
 static void		 export_pam_environment(void);
 static int		 motd(const char *);
@@ -94,6 +95,7 @@
 static const char	*stypeof(char *);
 static void		 sigint(int);
 static void		 timedout(int);
+static void		 bail_sig(int);
 static void		 usage(void);
 
 #define	TTYGRPNAME		"tty"			/* group to own ttys */
@@ -172,13 +174,18 @@
 	login_cap_t *lc = NULL;
 	login_cap_t *lc_user = NULL;
 	pid_t pid;
+	sigset_t mask, omask;
+	struct sigaction sa;
 #ifdef USE_BSM_AUDIT
 	char auditsuccess = 1;
 #endif
 
-	(void)signal(SIGQUIT, SIG_IGN);
-	(void)signal(SIGINT, SIG_IGN);
-	(void)signal(SIGHUP, SIG_IGN);
+	sa.sa_flags = SA_RESTART;
+	(void)sigfillset(&sa.sa_mask);
+	sa.sa_handler = SIG_IGN;
+	(void)sigaction(SIGQUIT, &sa, NULL);
+	(void)sigaction(SIGINT, &sa, NULL);
+	(void)sigaction(SIGHUP, &sa, NULL);
 	if (setjmp(timeout_buf)) {
 		if (failures)
 			badlogin(username);
@@ -186,7 +193,8 @@
 		    timeout);
 		bail(NO_SLEEP_EXIT, 0);
 	}
-	(void)signal(SIGALRM, timedout);
+	sa.sa_handler = timedout;
+	(void)sigaction(SIGALRM, &sa, NULL);
 	(void)alarm(timeout);
 	(void)setpriority(PRIO_PROCESS, 0, 0);
 
@@ -370,8 +378,15 @@
 
 	/* committed to login -- turn off timeout */
 	(void)alarm((u_int)0);
-	(void)signal(SIGHUP, SIG_DFL);
 
+	(void)sigemptyset(&mask);
+	(void)sigaddset(&mask, SIGHUP);
+	(void)sigaddset(&mask, SIGTERM);
+	(void)sigprocmask(SIG_BLOCK, &mask, &omask);
+	sa.sa_handler = bail_sig;
+	(void)sigaction(SIGHUP, &sa, NULL);
+	(void)sigaction(SIGTERM, &sa, NULL);
+
 	endpwent();
 
 #ifdef USE_BSM_AUDIT
@@ -550,10 +565,17 @@
 		/*
 		 * Parent: wait for child to finish, then clean up
 		 * session.
+		 *
+		 * If we get SIGHUP or SIGTERM, clean up the session
+		 * and exit right away. This will make the terminal
+		 * inaccessible and send SIGHUP to the foreground
+		 * process group.
 		 */
 		int status;
 		setproctitle("-%s [pam]", getprogname());
+		(void)sigprocmask(SIG_SETMASK, &omask, NULL);
 		waitpid(pid, &status, 0);
+		(void)sigprocmask(SIG_BLOCK, &mask, NULL);
 		bail(NO_SLEEP_EXIT, 0);
 	}
 
@@ -627,10 +649,15 @@
 	login_close(lc_user);
 	login_close(lc);
 
-	(void)signal(SIGALRM, SIG_DFL);
-	(void)signal(SIGQUIT, SIG_DFL);
-	(void)signal(SIGINT, SIG_DFL);
-	(void)signal(SIGTSTP, SIG_IGN);
+	sa.sa_handler = SIG_DFL;
+	(void)sigaction(SIGALRM, &sa, NULL);
+	(void)sigaction(SIGQUIT, &sa, NULL);
+	(void)sigaction(SIGINT, &sa, NULL);
+	(void)sigaction(SIGTERM, &sa, NULL);
+	(void)sigaction(SIGHUP, &sa, NULL);
+	sa.sa_handler = SIG_IGN;
+	(void)sigaction(SIGTSTP, &sa, NULL);
+	(void)sigprocmask(SIG_SETMASK, &omask, NULL);
 
 	/*
 	 * Login shells have a leading '-' in front of argv[0]
@@ -847,7 +874,7 @@
 static int
 motd(const char *motdfile)
 {
-	sig_t oldint;
+	struct sigaction newint, oldint;
 	FILE *f;
 	int ch;
 
@@ -854,10 +881,13 @@
 	if ((f = fopen(motdfile, "r")) == NULL)
 		return (-1);
 	motdinterrupt = 0;
-	oldint = signal(SIGINT, sigint);
+	newint.sa_handler = sigint;
+	newint.sa_flags = 0;
+	sigfillset(&newint.sa_mask);
+	sigaction(SIGINT, &newint, &oldint);
 	while ((ch = fgetc(f)) != EOF && !motdinterrupt)
 		putchar(ch);
-	signal(SIGINT, oldint);
+	sigaction(SIGINT, &oldint, NULL);
 	if (ch != EOF || ferror(f)) {
 		fclose(f);
 		return (-1);
@@ -966,12 +996,10 @@
 	}
 }
 
-/*
- * Exit, optionally after sleeping a few seconds
- */
-void
-bail(int sec, int eval)
+static void
+bail_internal(int sec, int eval, int signo)
 {
+	struct sigaction sa;
 
 	pam_cleanup();
 #ifdef USE_BSM_AUDIT
@@ -979,5 +1007,36 @@
 		audit_logout();
 #endif
 	(void)sleep(sec);
-	exit(eval);
+	if (signo == 0)
+		exit(eval);
+	else {
+		sa.sa_handler = SIG_DFL;
+		sa.sa_flags = 0;
+		(void)sigemptyset(&sa.sa_mask);
+		(void)sigaction(signo, &sa, NULL);
+		(void)sigaddset(&sa.sa_mask, signo);
+		(void)sigprocmask(SIG_UNBLOCK, &sa.sa_mask, NULL);
+		raise(signo);
+		exit(128 + signo);
+	}
 }
+
+/*
+ * Exit, optionally after sleeping a few seconds
+ */
+static void
+bail(int sec, int eval)
+{
+	bail_internal(sec, eval, 0);
+}
+
+/*
+ * Exit because of a signal.
+ * This is not async-signal safe, so only call async-signal safe functions
+ * while the signal is unmasked.
+ */
+static void
+bail_sig(int signo)
+{
+	bail_internal(NO_SLEEP_EXIT, 0, signo);
+}

Modified: trunk/usr.bin/login/login.h
===================================================================
--- trunk/usr.bin/login/login.h	2018-07-07 17:32:26 UTC (rev 11492)
+++ trunk/usr.bin/login/login.h	2018-07-07 17:32:54 UTC (rev 11493)
@@ -1,3 +1,4 @@
+/* $MidnightBSD$ */
 /*-
  * Copyright (c) 2001 FreeBSD, Inc
  *
@@ -22,7 +23,7 @@
  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  * SUCH DAMAGE.
  *
- * $MidnightBSD$
+ * $FreeBSD: stable/10/usr.bin/login/login.h 169342 2007-05-07 11:01:36Z dwmalone $
  */
 
 void	login_fbtab(char *, uid_t, gid_t);

Modified: trunk/usr.bin/login/login_audit.c
===================================================================
--- trunk/usr.bin/login/login_audit.c	2018-07-07 17:32:26 UTC (rev 11492)
+++ trunk/usr.bin/login/login_audit.c	2018-07-07 17:32:54 UTC (rev 11493)
@@ -1,3 +1,4 @@
+/* $MidnightBSD$ */
 /*
  * Copyright (c) 2005 Apple Computer, Inc.
  * All rights reserved.
@@ -32,7 +33,7 @@
  */
 
 #include <sys/cdefs.h>
-__MBSDID("$MidnightBSD$");
+__FBSDID("$FreeBSD: stable/10/usr.bin/login/login_audit.c 191297 2009-04-19 23:34:22Z rwatson $");
 
 #include <sys/types.h>
 

Modified: trunk/usr.bin/login/login_fbtab.c
===================================================================
--- trunk/usr.bin/login/login_fbtab.c	2018-07-07 17:32:26 UTC (rev 11492)
+++ trunk/usr.bin/login/login_fbtab.c	2018-07-07 17:32:54 UTC (rev 11493)
@@ -1,3 +1,4 @@
+/* $MidnightBSD$ */
 /************************************************************************
 * Copyright 1995 by Wietse Venema.  All rights reserved.
 *
@@ -25,7 +26,7 @@
 	SunOS 4.1.x fbtab(5) and SunOS 5.x logindevperm(4) manual
 	pages. The program first looks for /etc/fbtab. If that file
 	cannot be opened it attempts to process /etc/logindevperm.
-	We expect entries with the folowing format:
+	We expect entries with the following format:
 
 	    Comments start with a # and extend to the end of the line.
 
@@ -59,13 +60,12 @@
  */
 
 #include <sys/cdefs.h>
-__MBSDID("$MidnightBSD$");
+__FBSDID("$FreeBSD: stable/10/usr.bin/login/login_fbtab.c 288164 2015-09-24 00:54:46Z delphij $");
 
 #include <sys/types.h>
 #include <sys/stat.h>
 #include <errno.h>
 #include <glob.h>
-#include <paths.h>
 #include <stdio.h>
 #include <string.h>
 #include <syslog.h>
@@ -100,17 +100,17 @@
 	if ((cp = devname = strtok(buf, WSPACE)) == 0)
 	    continue;				/* empty or comment */
 	if (strncmp(devname, _PATH_DEV, sizeof _PATH_DEV - 1) != 0
-	       || (cp = strtok((char *) 0, WSPACE)) == 0
+	       || (cp = strtok(NULL, WSPACE)) == 0
 	       || *cp != '0'
 	       || sscanf(cp, "%o", &prot) == 0
 	       || prot == 0
 	       || (prot & 0777) != prot
-	       || (cp = strtok((char *) 0, WSPACE)) == 0) {
+	       || (cp = strtok(NULL, WSPACE)) == 0) {
 	    syslog(LOG_ERR, "%s: bad entry: %s", table, cp ? cp : "(null)");
 	    continue;
 	}
 	if (strcmp(devname + 5, tty) == 0) {
-	    for (cp = strtok(cp, ":"); cp; cp = strtok((char *) 0, ":")) {
+	    for (cp = strtok(cp, ":"); cp; cp = strtok(NULL, ":")) {
 		login_protect(table, cp, prot, uid, gid);
 	    }
 	}
@@ -120,7 +120,7 @@
 
 /* login_protect - protect one device entry */
 
-void
+static void
 login_protect(const char *table, char *pattern, int mask, uid_t uid, gid_t gid)
 {
     glob_t  gl;

Modified: trunk/usr.bin/login/pathnames.h
===================================================================
--- trunk/usr.bin/login/pathnames.h	2018-07-07 17:32:26 UTC (rev 11492)
+++ trunk/usr.bin/login/pathnames.h	2018-07-07 17:32:54 UTC (rev 11493)
@@ -1,3 +1,4 @@
+/* $MidnightBSD$ */
 /*-
  * Copyright (c) 1989, 1993
  *	The Regents of the University of California.  All rights reserved.
@@ -27,7 +28,7 @@
  * SUCH DAMAGE.
  *
  *	@(#)pathnames.h	8.1 (Berkeley) 6/9/93
- * $MidnightBSD$
+ * $FreeBSD: stable/10/usr.bin/login/pathnames.h 216370 2010-12-11 08:32:16Z joel $
  */
 
 #include <paths.h>



More information about the Midnightbsd-cvs mailing list