[Midnightbsd-cvs] src [10726] trunk/usr.sbin/lpr/common_source: sync

laffer1 at midnightbsd.org laffer1 at midnightbsd.org
Sat Jun 9 17:56:58 EDT 2018


Revision: 10726
          http://svnweb.midnightbsd.org/src/?rev=10726
Author:   laffer1
Date:     2018-06-09 17:56:57 -0400 (Sat, 09 Jun 2018)
Log Message:
-----------
sync

Modified Paths:
--------------
    trunk/usr.sbin/lpr/common_source/Makefile
    trunk/usr.sbin/lpr/common_source/common.c
    trunk/usr.sbin/lpr/common_source/ctlinfo.c
    trunk/usr.sbin/lpr/common_source/ctlinfo.h
    trunk/usr.sbin/lpr/common_source/displayq.c
    trunk/usr.sbin/lpr/common_source/lp.cdefs.h
    trunk/usr.sbin/lpr/common_source/lp.h
    trunk/usr.sbin/lpr/common_source/lp.local.h
    trunk/usr.sbin/lpr/common_source/matchjobs.c
    trunk/usr.sbin/lpr/common_source/matchjobs.h
    trunk/usr.sbin/lpr/common_source/net.c
    trunk/usr.sbin/lpr/common_source/pathnames.h
    trunk/usr.sbin/lpr/common_source/printcap.c
    trunk/usr.sbin/lpr/common_source/request.c
    trunk/usr.sbin/lpr/common_source/rmjob.c
    trunk/usr.sbin/lpr/common_source/startdaemon.c

Modified: trunk/usr.sbin/lpr/common_source/Makefile
===================================================================
--- trunk/usr.sbin/lpr/common_source/Makefile	2018-06-09 21:56:28 UTC (rev 10725)
+++ trunk/usr.sbin/lpr/common_source/Makefile	2018-06-09 21:56:57 UTC (rev 10726)
@@ -1,4 +1,5 @@
 # $MidnightBSD$
+# $FreeBSD: stable/10/usr.sbin/lpr/common_source/Makefile 201390 2010-01-02 11:07:44Z ed $
 
 #
 # Library of internal routines for the print spooler suite.

Modified: trunk/usr.sbin/lpr/common_source/common.c
===================================================================
--- trunk/usr.sbin/lpr/common_source/common.c	2018-06-09 21:56:28 UTC (rev 10725)
+++ trunk/usr.sbin/lpr/common_source/common.c	2018-06-09 21:56:57 UTC (rev 10726)
@@ -1,3 +1,4 @@
+/* $MidnightBSD$ */
 /*
  * Copyright (c) 1983, 1993
  *	The Regents of the University of California.  All rights reserved.
@@ -43,7 +44,7 @@
 #endif
 
 #include "lp.cdefs.h"		/* A cross-platform version of <sys/cdefs.h> */
-__MBSDID("$MidnightBSD$");
+__FBSDID("$FreeBSD: stable/10/usr.sbin/lpr/common_source/common.c 251044 2013-05-27 22:19:01Z gad $");
 
 #include <sys/param.h>
 #include <sys/stat.h>
@@ -52,6 +53,7 @@
 
 #include <ctype.h>
 #include <dirent.h>
+#include <err.h>
 #include <errno.h>
 #include <fcntl.h>
 #include <stdio.h>
@@ -69,8 +71,6 @@
 char	line[BUFSIZ];
 const char	*progname;		/* program name */
 
-extern uid_t	uid, euid;
-
 static int compar(const void *_p1, const void *_p2);
 
 /*
@@ -125,14 +125,14 @@
 	DIR *dirp;
 	int statres;
 
-	seteuid(euid);
+	PRIV_START
 	if ((dirp = opendir(pp->spool_dir)) == NULL) {
-		seteuid(uid);
+		PRIV_END
 		return (-1);
 	}
-	if (fstat(dirp->dd_fd, &stbuf) < 0)
+	if (fstat(dirfd(dirp), &stbuf) < 0)
 		goto errdone;
-	seteuid(uid);
+	PRIV_END
 
 	/*
 	 * Estimate the array size by taking the size of the directory file
@@ -149,9 +149,9 @@
 	while ((d = readdir(dirp)) != NULL) {
 		if (d->d_name[0] != 'c' || d->d_name[1] != 'f')
 			continue;	/* daemon control files only */
-		seteuid(euid);
+		PRIV_START
 		statres = stat(d->d_name, &stbuf);
-		seteuid(uid);
+		PRIV_END
 		if (statres < 0)
 			continue;	/* Doesn't exist */
 		entrysz = sizeof(struct jobqueue) - sizeof(q->job_cfname) +
@@ -184,7 +184,7 @@
 
 errdone:
 	closedir(dirp);
-	seteuid(uid);
+	PRIV_END
 	return (-1);
 }
 
@@ -340,10 +340,10 @@
 	 * Find what the current access-bits are.
 	 */
 	memset(&stbuf, 0, sizeof(stbuf));
-	seteuid(euid);
+	PRIV_START
 	statres = stat(lfname, &stbuf);
 	errsav = errno;
-	seteuid(uid);
+	PRIV_END
 	if ((statres < 0) && (errsav != ENOENT)) {
 		printf("\tcannot stat() lock file\n");
 		return (SQS_STATFAIL);
@@ -402,10 +402,10 @@
 	res = 0;
 	if (statres >= 0) {
 		/* The file already exists, so change the access. */
-		seteuid(euid);
+		PRIV_START
 		chres = chmod(lfname, chgbits);
 		errsav = errno;
-		seteuid(uid);
+		PRIV_END
 		res = SQS_CHGOK;
 		if (chres < 0)
 			res = SQS_CHGFAIL;
@@ -424,10 +424,10 @@
 		 * all the read/write bits are set as desired.
 		 */
 		oldmask = umask(S_IWOTH);
-		seteuid(euid);
+		PRIV_START
 		fd = open(lfname, O_WRONLY|O_CREAT, newbits);
 		errsav = errno;
-		seteuid(uid);
+		PRIV_END
 		umask(oldmask);
 		res = SQS_CREFAIL;
 		if (fd >= 0) {
@@ -758,16 +758,22 @@
 
 /*
  * Close all file descriptors from START on up.
- * This is a horrific kluge, since getdtablesize() might return
- * ``infinity'', in which case we will be spending a long time
- * closing ``files'' which were never open.  Perhaps it would
- * be better to close the first N fds, for some small value of N.
  */
 void
 closeallfds(int start)
 {
-	int stop = getdtablesize();
-	for (; start < stop; start++)
-		close(start);
+	int stop;
+
+	if (USE_CLOSEFROM)		/* The faster, modern solution */
+		closefrom(start);
+	else {
+		/* This older logic can be pretty awful on some OS's.  The
+		 * getdtablesize() might return ``infinity'', and then this
+		 * will waste a lot of time closing file descriptors which
+		 * had never been open()-ed. */
+		stop = getdtablesize();
+		for (; start < stop; start++)
+			close(start);
+	}
 }
 

Modified: trunk/usr.sbin/lpr/common_source/ctlinfo.c
===================================================================
--- trunk/usr.sbin/lpr/common_source/ctlinfo.c	2018-06-09 21:56:28 UTC (rev 10725)
+++ trunk/usr.sbin/lpr/common_source/ctlinfo.c	2018-06-09 21:56:57 UTC (rev 10726)
@@ -1,3 +1,4 @@
+/* $MidnightBSD$ */
 /*
  * ------+---------+---------+---------+---------+---------+---------+---------*
  * Copyright (c) 2001,2011  - Garance Alistair Drosehn <gad at FreeBSD.org>.
@@ -32,7 +33,7 @@
  */
 
 #include "lp.cdefs.h"		/* A cross-platform version of <sys/cdefs.h> */
-__MBSDID("$MidnightBSD$");
+__FBSDID("$FreeBSD: stable/10/usr.sbin/lpr/common_source/ctlinfo.c 220586 2011-04-13 00:36:19Z gad $");
 
 /*
  * ctlinfo - This collection of routines will know everything there is to

Modified: trunk/usr.sbin/lpr/common_source/ctlinfo.h
===================================================================
--- trunk/usr.sbin/lpr/common_source/ctlinfo.h	2018-06-09 21:56:28 UTC (rev 10725)
+++ trunk/usr.sbin/lpr/common_source/ctlinfo.h	2018-06-09 21:56:57 UTC (rev 10726)
@@ -1,3 +1,4 @@
+/* $MidnightBSD$ */
 /*
  * ------+---------+---------+---------+---------+---------+---------+---------*
  * Copyright (c) 2001,2011  - Garance Alistair Drosehn <gad at FreeBSD.org>.
@@ -29,7 +30,7 @@
  * official policies, either expressed or implied, of the FreeBSD Project.
  *
  * ------+---------+---------+---------+---------+---------+---------+---------*
- * $MidnightBSD$
+ * $FreeBSD: stable/10/usr.sbin/lpr/common_source/ctlinfo.h 220586 2011-04-13 00:36:19Z gad $
  * ------+---------+---------+---------+---------+---------+---------+---------*
  */
 

Modified: trunk/usr.sbin/lpr/common_source/displayq.c
===================================================================
--- trunk/usr.sbin/lpr/common_source/displayq.c	2018-06-09 21:56:28 UTC (rev 10725)
+++ trunk/usr.sbin/lpr/common_source/displayq.c	2018-06-09 21:56:57 UTC (rev 10726)
@@ -1,3 +1,4 @@
+/* $MidnightBSD$ */
 /*
  * Copyright (c) 1983, 1993
  *	The Regents of the University of California.  All rights reserved.
@@ -34,7 +35,7 @@
 #endif
 
 #include "lp.cdefs.h"		/* A cross-platform version of <sys/cdefs.h> */
-__MBSDID("$MidnightBSD$");
+__FBSDID("$FreeBSD: stable/10/usr.sbin/lpr/common_source/displayq.c 242091 2012-10-25 20:16:38Z ed $");
 
 #include <sys/param.h>
 #include <sys/stat.h>
@@ -41,6 +42,7 @@
 
 #include <ctype.h>
 #include <dirent.h>
+#include <err.h>
 #include <errno.h>
 #include <fcntl.h>
 #include <signal.h>
@@ -74,8 +76,6 @@
 /*
  * Stuff for handling job specifications
  */
-extern uid_t	uid, euid;
-
 static int	col;		/* column on screen */
 static char	current[MAXNAMLEN+1];	/* current file being printed */
 static char	file[MAXNAMLEN+1];	/* print file name */
@@ -90,7 +90,7 @@
 
 static void	alarmhandler(int _signo);
 static void	filtered_write(char *_obuffer, int _wlen, FILE *_wstream);
-static void	warn(const struct printer *_pp);
+static void	daemonwarn(const struct printer *_pp);
 
 /*
  * Display the current state of the queue. Format = 1 if long format.
@@ -119,24 +119,24 @@
 	 * Print out local queue
 	 * Find all the control files in the spooling directory
 	 */
-	seteuid(euid);
+	PRIV_START
 	if (chdir(pp->spool_dir) < 0)
 		fatal(pp, "cannot chdir to spooling directory: %s",
 		      strerror(errno));
-	seteuid(uid);
+	PRIV_END
 	if ((nitems = getq(pp, &queue)) < 0)
 		fatal(pp, "cannot examine spooling area\n");
-	seteuid(euid);
+	PRIV_START
 	ret = stat(pp->lock_file, &statb);
-	seteuid(uid);
+	PRIV_END
 	if (ret >= 0) {
 		if (statb.st_mode & LFM_PRINT_DIS) {
 			if (pp->remote)
 				printf("%s: ", local_host);
 			printf("Warning: %s is down: ", pp->printer);
-			seteuid(euid);
+			PRIV_START
 			fd = open(pp->status_file, O_RDONLY|O_SHLOCK);
-			seteuid(uid);
+			PRIV_END
 			if (fd >= 0) {
 				while ((i = read(fd, line, sizeof(line))) > 0)
 					(void) fwrite(line, 1, i, stdout);
@@ -153,11 +153,11 @@
 	}
 
 	if (nitems) {
-		seteuid(euid);
+		PRIV_START
 		fp = fopen(pp->lock_file, "r");
-		seteuid(uid);
+		PRIV_END
 		if (fp == NULL)
-			warn(pp);
+			daemonwarn(pp);
 		else {
 			/* get daemon pid */
 			cp = current;
@@ -171,12 +171,12 @@
 			if (i <= 0) {
 				ret = -1;
 			} else {
-				seteuid(euid);
+				PRIV_START
 				ret = kill(i, 0);
-				seteuid(uid);
+				PRIV_END
 			}
 			if (ret < 0) {
-				warn(pp);
+				daemonwarn(pp);
 			} else {
 				/* read current file name */
 				cp = current;
@@ -191,9 +191,9 @@
 				 */
 				if (pp->remote)
 					printf("%s: ", local_host);
-				seteuid(euid);
+				PRIV_START
 				fd = open(pp->status_file, O_RDONLY|O_SHLOCK);
-				seteuid(uid);
+				PRIV_END
 				if (fd >= 0) {
 					while ((i = read(fd, line,
 							 sizeof(line))) > 0)
@@ -360,7 +360,7 @@
  * Print a warning message if there is no daemon present.
  */
 static void
-warn(const struct printer *pp)
+daemonwarn(const struct printer *pp)
 {
 	if (pp->remote)
 		printf("%s: ", local_host);
@@ -391,10 +391,10 @@
 	 * There's a chance the control file has gone away
 	 * in the meantime; if this is the case just keep going
 	 */
-	seteuid(euid);
+	PRIV_START
 	if ((cfp = fopen(cf, "r")) == NULL)
 		return;
-	seteuid(uid);
+	PRIV_END
 
 	if (rank < 0)
 		rank = 0;
@@ -578,10 +578,10 @@
 	}
 	first = 0;
 
-	seteuid(euid);
+	PRIV_START
 	if (*datafile && !stat(datafile, &lbuf))
 		totsize += copies * lbuf.st_size;
-	seteuid(uid);
+	PRIV_END
 }
 
 /*

Modified: trunk/usr.sbin/lpr/common_source/lp.cdefs.h
===================================================================
--- trunk/usr.sbin/lpr/common_source/lp.cdefs.h	2018-06-09 21:56:28 UTC (rev 10725)
+++ trunk/usr.sbin/lpr/common_source/lp.cdefs.h	2018-06-09 21:56:57 UTC (rev 10726)
@@ -1,6 +1,7 @@
+/* $MidnightBSD$ */
 /*-
  * ------+---------+---------+---------+---------+---------+---------+---------*
- * Copyright (c) 2003  - Garance Alistair Drosehn <gad at FreeBSD.org>.
+ * Copyright (c) 2003,2013  - Garance Alistair Drosehn <gad at FreeBSD.org>.
  * All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
@@ -29,7 +30,7 @@
  * official policies, either expressed or implied, of the FreeBSD Project.
  *
  * ------+---------+---------+---------+---------+---------+---------+---------*
- * $MidnightBSD$
+ * $FreeBSD: stable/10/usr.sbin/lpr/common_source/lp.cdefs.h 251044 2013-05-27 22:19:01Z gad $
  * ------+---------+---------+---------+---------+---------+---------+---------*
  */
 
@@ -56,6 +57,21 @@
 #endif
 
 /*
+ * FreeBSD added a closefrom() routine in release 8.0.  When compiling
+ * `lpr' on other platforms you might want to include bsd-closefrom.c
+ * from the portable-openssh project.
+ */
+#ifndef	USE_CLOSEFROM
+#  if defined(__FreeBSD__) || defined(__NetBSD__) || defined(__OpenBSD__)
+#    define	USE_CLOSEFROM	1
+#  endif
+#endif
+/* The macro USE_CLOSEFROM must be defined with a value of 0 or 1. */
+#ifndef	USE_CLOSEFROM
+#  define	USE_CLOSEFROM	0
+#endif
+
+/*
  * __unused is a compiler-specific trick which can be used to avoid
  * warnings about a variable which is defined but never referenced.
  * Some lpr files use this, so define a null version if it was not
@@ -66,18 +82,18 @@
 #endif
 
 /*
- * All the lpr source files will want to reference __MBSDID() to
+ * All the lpr source files will want to reference __FBSDID() to
  * handle rcs id's.
  */
-#if !defined(__MBSDID)
+#if !defined(__FBSDID)
 #  if defined(lint) || defined(STRIP_FBSDID)
-#    define	__MBSDID(s)	struct skip_rcsid_struct
+#    define	__FBSDID(s)	struct skip_rcsid_struct
 #  elif defined(__IDSTRING)			/* NetBSD */
-#    define	__MBSDID(s)	__IDSTRING(rcsid,s)
+#    define	__FBSDID(s)	__IDSTRING(rcsid,s)
 #  else
-#    define	__MBSDID(s)	static const char rcsid[] __unused = s
+#    define	__FBSDID(s)	static const char rcsid[] __unused = s
 #  endif
-#endif /* __MBSDID */
+#endif /* __FBSDID */
 
 /*
  * Some lpr include files use __BEGIN_DECLS and __END_DECLS.

Modified: trunk/usr.sbin/lpr/common_source/lp.h
===================================================================
--- trunk/usr.sbin/lpr/common_source/lp.h	2018-06-09 21:56:28 UTC (rev 10725)
+++ trunk/usr.sbin/lpr/common_source/lp.h	2018-06-09 21:56:57 UTC (rev 10726)
@@ -1,3 +1,4 @@
+/* $MidnightBSD$ */
 /*
  * Copyright (c) 1983, 1993
  *	The Regents of the University of California.  All rights reserved.
@@ -27,7 +28,7 @@
  * SUCH DAMAGE.
  *
  * 	From: @(#)lp.h	8.2 (Berkeley) 4/28/95
- * $MidnightBSD$
+ * $FreeBSD: stable/10/usr.sbin/lpr/common_source/lp.h 242091 2012-10-25 20:16:38Z ed $
  */
 
 #include <sys/queue.h>
@@ -249,6 +250,20 @@
 #define	CMD_SHOWQ_LONG	'\4'
 #define	CMD_RMJOB	'\5'
 
+/*
+ * seteuid() macros.
+*/
+
+extern uid_t	uid, euid;
+
+#define PRIV_START { \
+    if (seteuid(euid) != 0) err(1, "seteuid failed"); \
+}
+#define PRIV_END { \
+    if (seteuid(uid) != 0) err(1, "seteuid failed"); \
+}
+
+
 #include "lp.cdefs.h"		/* A cross-platform version of <sys/cdefs.h> */
 
 __BEGIN_DECLS

Modified: trunk/usr.sbin/lpr/common_source/lp.local.h
===================================================================
--- trunk/usr.sbin/lpr/common_source/lp.local.h	2018-06-09 21:56:28 UTC (rev 10725)
+++ trunk/usr.sbin/lpr/common_source/lp.local.h	2018-06-09 21:56:57 UTC (rev 10726)
@@ -1,3 +1,4 @@
+/* $MidnightBSD$ */
 /*
  * Copyright (c) 1983, 1993
  *	The Regents of the University of California.  All rights reserved.
@@ -27,7 +28,7 @@
  * SUCH DAMAGE.
  *
  *	@(#)lp.local.h	8.1 (Berkeley) 6/6/93
- * $MidnightBSD$
+ * $FreeBSD: stable/10/usr.sbin/lpr/common_source/lp.local.h 216372 2010-12-11 09:38:12Z joel $
  */
 
 /*

Modified: trunk/usr.sbin/lpr/common_source/matchjobs.c
===================================================================
--- trunk/usr.sbin/lpr/common_source/matchjobs.c	2018-06-09 21:56:28 UTC (rev 10725)
+++ trunk/usr.sbin/lpr/common_source/matchjobs.c	2018-06-09 21:56:57 UTC (rev 10726)
@@ -1,3 +1,4 @@
+/* $MidnightBSD$ */
 /*
  * ------+---------+---------+---------+---------+---------+---------+---------*
  * Copyright (c) 2002,2011   - Garance Alistair Drosehn <gad at FreeBSD.org>.
@@ -33,7 +34,7 @@
  */
 
 #include "lp.cdefs.h"		/* A cross-platform version of <sys/cdefs.h> */
-__MBSDID("$MidnightBSD$");
+__FBSDID("$FreeBSD: stable/10/usr.sbin/lpr/common_source/matchjobs.c 220586 2011-04-13 00:36:19Z gad $");
 
 /*
  * movejobs.c - The lpc commands which move jobs around.

Modified: trunk/usr.sbin/lpr/common_source/matchjobs.h
===================================================================
--- trunk/usr.sbin/lpr/common_source/matchjobs.h	2018-06-09 21:56:28 UTC (rev 10725)
+++ trunk/usr.sbin/lpr/common_source/matchjobs.h	2018-06-09 21:56:57 UTC (rev 10726)
@@ -1,3 +1,4 @@
+/* $MidnightBSD$ */
 /*
  * ------+---------+---------+---------+---------+---------+---------+---------*
  * Copyright (c) 2002  - Garance Alistair Drosehn <gad at FreeBSD.org>.
@@ -30,7 +31,7 @@
  * or FreeBSD, Inc.
  *
  * ------+---------+---------+---------+---------+---------+---------+---------*
- * $MidnightBSD$
+ * $FreeBSD: stable/10/usr.sbin/lpr/common_source/matchjobs.h 117541 2003-07-14 05:15:21Z gad $
  * ------+---------+---------+---------+---------+---------+---------+---------*
  */
 

Modified: trunk/usr.sbin/lpr/common_source/net.c
===================================================================
--- trunk/usr.sbin/lpr/common_source/net.c	2018-06-09 21:56:28 UTC (rev 10725)
+++ trunk/usr.sbin/lpr/common_source/net.c	2018-06-09 21:56:57 UTC (rev 10726)
@@ -1,3 +1,4 @@
+/* $MidnightBSD$ */
 /*
  * Copyright (c) 1983, 1993
  *	The Regents of the University of California.  All rights reserved.
@@ -39,7 +40,7 @@
  */
 
 #include "lp.cdefs.h"		/* A cross-platform version of <sys/cdefs.h> */
-__MBSDID("$MidnightBSD$");
+__FBSDID("$FreeBSD: stable/10/usr.sbin/lpr/common_source/net.c 242091 2012-10-25 20:16:38Z ed $");
 
 #include <sys/param.h>
 #include <sys/socket.h>
@@ -52,6 +53,7 @@
 #include <netdb.h>
 
 #include <dirent.h>		/* required for lp.h, not used here */
+#include <err.h>
 #include <errno.h>
 #include <stdarg.h>
 #include <stdio.h>
@@ -79,8 +81,6 @@
 u_char	family = PF_INET;
 #endif
 
-extern uid_t	uid, euid;
-
 /*
  * Create a TCP connection to host "rhost" at port "rport".
  * If rport == 0, then use the printer service port.
@@ -91,7 +91,7 @@
 {
 	struct addrinfo hints, *res, *ai;
 	int s, timo = 1, lport = IPPORT_RESERVED - 1;
-	int err, refused = 0;
+	int error, refused = 0;
 
 	/*
 	 * Get the host address and port number to connect to.
@@ -102,10 +102,10 @@
 	hints.ai_family = family;
 	hints.ai_socktype = SOCK_STREAM;
 	hints.ai_protocol = 0;
-	err = getaddrinfo(rhost, (rport == 0 ? "printer" : NULL),
+	error = getaddrinfo(rhost, (rport == 0 ? "printer" : NULL),
 			  &hints, &res);
-	if (err)
-		fatal(pp, "%s\n", gai_strerror(err));
+	if (error)
+		fatal(pp, "%s\n", gai_strerror(error));
 	if (rport != 0)
 		((struct sockaddr_in *) res->ai_addr)->sin_port = htons(rport);
 
@@ -114,9 +114,9 @@
 	 */
 	ai = res;
 retry:
-	seteuid(euid);
+	PRIV_START
 	s = rresvport_af(&lport, ai->ai_family);
-	seteuid(uid);
+	PRIV_END
 	if (s < 0) {
 		if (errno != EAGAIN) {
 			if (ai->ai_next) {
@@ -135,9 +135,9 @@
 		return(-1);
 	}
 	if (connect(s, ai->ai_addr, ai->ai_addrlen) < 0) {
-		err = errno;
+		error = errno;
 		(void) close(s);
-		errno = err;
+		errno = error;
 		/*
 		 * This used to decrement lport, but the current semantics
 		 * of rresvport do not provide such a function (in fact,
@@ -184,8 +184,8 @@
 {
 	char lclhost[MAXHOSTNAMELEN];
 	struct addrinfo hints, *local_res, *remote_res, *lr, *rr;
-	char *err;
-	int ncommonaddrs, error;
+	char *error;
+	int ncommonaddrs, errno;
 	char h1[NI_MAXHOST], h2[NI_MAXHOST];
 
 	if (!pp->rp_matches_local) { /* Remote printer doesn't match local */
@@ -205,11 +205,11 @@
 	hints.ai_family = family;
 	hints.ai_socktype = SOCK_STREAM;
 	hints.ai_flags = AI_PASSIVE;
-	if ((error = getaddrinfo(lclhost, NULL, &hints, &local_res)) != 0) {
-		asprintf(&err, "unable to get official name "
+	if ((errno = getaddrinfo(lclhost, NULL, &hints, &local_res)) != 0) {
+		asprintf(&error, "unable to get official name "
 			 "for local machine %s: %s",
-			 lclhost, gai_strerror(error));
-		return err;
+			 lclhost, gai_strerror(errno));
+		return error;
 	}
 
 	/* get the official name of RM */
@@ -217,13 +217,13 @@
 	hints.ai_family = family;
 	hints.ai_socktype = SOCK_STREAM;
 	hints.ai_flags = AI_PASSIVE;
-	if ((error = getaddrinfo(pp->remote_host, NULL,
+	if ((errno = getaddrinfo(pp->remote_host, NULL,
 				 &hints, &remote_res)) != 0) {
-		asprintf(&err, "unable to get address list for "
+		asprintf(&error, "unable to get address list for "
 			 "remote machine %s: %s",
-			 pp->remote_host, gai_strerror(error));
+			 pp->remote_host, gai_strerror(errno));
 		freeaddrinfo(local_res);
-		return err;
+		return error;
 	}
 
 	ncommonaddrs = 0;

Modified: trunk/usr.sbin/lpr/common_source/pathnames.h
===================================================================
--- trunk/usr.sbin/lpr/common_source/pathnames.h	2018-06-09 21:56:28 UTC (rev 10725)
+++ trunk/usr.sbin/lpr/common_source/pathnames.h	2018-06-09 21:56:57 UTC (rev 10726)
@@ -1,3 +1,4 @@
+/* $MidnightBSD$ */
 /*
  * Copyright (c) 1989, 1993
  *	The Regents of the University of California.  All rights reserved.
@@ -26,7 +27,7 @@
  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  * SUCH DAMAGE.
  *
- * $MidnightBSD$
+ * $FreeBSD: stable/10/usr.sbin/lpr/common_source/pathnames.h 216372 2010-12-11 09:38:12Z joel $
  *
  *      @(#)pathnames.h	8.1 (Berkeley) 6/6/93
  */

Modified: trunk/usr.sbin/lpr/common_source/printcap.c
===================================================================
--- trunk/usr.sbin/lpr/common_source/printcap.c	2018-06-09 21:56:28 UTC (rev 10725)
+++ trunk/usr.sbin/lpr/common_source/printcap.c	2018-06-09 21:56:57 UTC (rev 10726)
@@ -1,3 +1,4 @@
+/* $MidnightBSD$ */
 /*
  * Copyright (c) 1983, 1993
  *	The Regents of the University of California.  All rights reserved.
@@ -43,7 +44,7 @@
 #endif
 
 #include "lp.cdefs.h"		/* A cross-platform version of <sys/cdefs.h> */
-__MBSDID("$MidnightBSD$");
+__FBSDID("$FreeBSD: stable/10/usr.sbin/lpr/common_source/printcap.c 117590 2003-07-14 20:17:55Z gad $");
 
 #include <errno.h>
 #include <stdio.h>

Modified: trunk/usr.sbin/lpr/common_source/request.c
===================================================================
--- trunk/usr.sbin/lpr/common_source/request.c	2018-06-09 21:56:28 UTC (rev 10725)
+++ trunk/usr.sbin/lpr/common_source/request.c	2018-06-09 21:56:57 UTC (rev 10726)
@@ -1,3 +1,4 @@
+/* $MidnightBSD$ */
 /*
  * Copyright 1997 Massachusetts Institute of Technology
  *
@@ -31,7 +32,7 @@
 	"Copyright (C) 1997, Massachusetts Institute of Technology\r\n";
 
 #include "lp.cdefs.h"		/* A cross-platform version of <sys/cdefs.h> */
-__MBSDID("$MidnightBSD$");
+__FBSDID("$FreeBSD: stable/10/usr.sbin/lpr/common_source/request.c 117592 2003-07-14 20:20:58Z gad $");
 
 #include <sys/types.h>
 #include <sys/stat.h>

Modified: trunk/usr.sbin/lpr/common_source/rmjob.c
===================================================================
--- trunk/usr.sbin/lpr/common_source/rmjob.c	2018-06-09 21:56:28 UTC (rev 10725)
+++ trunk/usr.sbin/lpr/common_source/rmjob.c	2018-06-09 21:56:57 UTC (rev 10726)
@@ -1,3 +1,4 @@
+/* $MidnightBSD$ */
 /*
  * Copyright (c) 1983, 1993
  *	The Regents of the University of California.  All rights reserved.
@@ -34,7 +35,7 @@
 #endif
 
 #include "lp.cdefs.h"		/* A cross-platform version of <sys/cdefs.h> */
-__MBSDID("$MidnightBSD$");
+__FBSDID("$FreeBSD: stable/10/usr.sbin/lpr/common_source/rmjob.c 242091 2012-10-25 20:16:38Z ed $");
 
 #include <sys/param.h>
 #include <sys/uio.h>
@@ -41,6 +42,7 @@
 
 #include <ctype.h>
 #include <dirent.h>
+#include <err.h>
 #include <errno.h>
 #include <signal.h>
 #include <stdio.h>
@@ -68,8 +70,6 @@
 static int	cur_daemon;		/* daemon's pid */
 static char	current[7+MAXHOSTNAMELEN];  /* active control file name */
 
-extern uid_t	uid, euid;		/* real and effective user id's */
-
 static	void	alarmhandler(int _signo);
 static	void	do_unlink(char *_file);
 static int	 isowner(char *_owner, char *_file, const char *_cfhost);
@@ -78,7 +78,7 @@
 rmjob(const char *printer)
 {
 	register int i, nitems;
-	int assasinated = 0;
+	int assassinated = 0;
 	struct dirent **files;
 	char *cp;
 	struct printer myprinter, *pp = &myprinter;
@@ -110,12 +110,12 @@
 		person = root;
 	}
 
-	seteuid(euid);
+	PRIV_START
 	if (chdir(pp->spool_dir) < 0)
 		fatal(pp, "cannot chdir to spool directory");
 	if ((nitems = scandir(".", &files, iscf, NULL)) < 0)
 		fatal(pp, "cannot access spool directory");
-	seteuid(uid);
+	PRIV_END
 
 	if (nitems) {
 		/*
@@ -124,10 +124,10 @@
 		 *  (after which we have to restart the daemon).
 		 */
 		if (lockchk(pp, pp->lock_file) && chk(current)) {
-			seteuid(euid);
-			assasinated = kill(cur_daemon, SIGINT) == 0;
-			seteuid(uid);
-			if (!assasinated)
+			PRIV_START
+			assassinated = kill(cur_daemon, SIGINT) == 0;
+			PRIV_END
+			if (!assassinated)
 				fatal(pp, "cannot kill printer daemon");
 		}
 		/*
@@ -140,7 +140,7 @@
 	/*
 	 * Restart the printer daemon if it was killed
 	 */
-	if (assasinated && !startdaemon(pp))
+	if (assassinated && !startdaemon(pp))
 		fatal(pp, "cannot restart printer daemon\n");
 	exit(0);
 }
@@ -156,7 +156,7 @@
 	register FILE *fp;
 	register int i, n;
 
-	seteuid(euid);
+	PRIV_START
 	if ((fp = fopen(slockf, "r")) == NULL) {
 		if (errno == EACCES)
 			fatal(pp, "%s: %s", slockf, strerror(errno));
@@ -163,7 +163,7 @@
 		else
 			return(0);
 	}
-	seteuid(uid);
+	PRIV_END
 	if (!getline(fp)) {
 		(void) fclose(fp);
 		return(0);		/* no daemon present */
@@ -195,10 +195,10 @@
 
 	if (!chk(file))
 		return;
-	seteuid(euid);
+	PRIV_START
 	if ((cfp = fopen(file, "r")) == NULL)
 		fatal(pp, "cannot open %s", file);
-	seteuid(uid);
+	PRIV_END
 	while (getline(cfp)) {
 		switch (line[0]) {
 		case 'U':  /* unlink associated files */
@@ -218,9 +218,9 @@
 
 	if (from_host != local_host)
 		printf("%s: ", local_host);
-	seteuid(euid);
+	PRIV_START
 	ret = unlink(file);
-	seteuid(uid);
+	PRIV_END
 	printf(ret ? "cannot dequeue %s\n" : "%s dequeued\n", file);
 }
 
@@ -248,10 +248,10 @@
 	/*
 	 * get the owner's name from the control file.
 	 */
-	seteuid(euid);
+	PRIV_START
 	if ((cfp = fopen(file, "r")) == NULL)
 		return(0);
-	seteuid(uid);
+	PRIV_END
 	while (getline(cfp)) {
 		if (line[0] == 'P')
 			break;

Modified: trunk/usr.sbin/lpr/common_source/startdaemon.c
===================================================================
--- trunk/usr.sbin/lpr/common_source/startdaemon.c	2018-06-09 21:56:28 UTC (rev 10725)
+++ trunk/usr.sbin/lpr/common_source/startdaemon.c	2018-06-09 21:56:57 UTC (rev 10726)
@@ -1,3 +1,4 @@
+/* $MidnightBSD$ */
 /*
  * Copyright (c) 1983, 1993, 1994
  *	The Regents of the University of California.  All rights reserved.
@@ -34,7 +35,7 @@
 #endif
 
 #include "lp.cdefs.h"		/* A cross-platform version of <sys/cdefs.h> */
-__MBSDID("$MidnightBSD$");
+__FBSDID("$FreeBSD: stable/10/usr.sbin/lpr/common_source/startdaemon.c 242091 2012-10-25 20:16:38Z ed $");
 
 #include <sys/param.h>
 #include <sys/socket.h>
@@ -49,8 +50,6 @@
 #include "lp.h"
 #include "pathnames.h"
 
-extern uid_t	uid, euid;
-
 /*
  * Tell the printer daemon that there are new files in the spool directory.
  */
@@ -74,9 +73,9 @@
 #ifndef SUN_LEN
 #define SUN_LEN(unp) (strlen((unp)->sun_path) + 2)
 #endif
-	seteuid(euid);
+	PRIV_START
 	connectres = connect(s, (struct sockaddr *)&un, SUN_LEN(&un));
-	seteuid(uid);
+	PRIV_END
 	if (connectres < 0) {
 		warn("Unable to connect to %s", _PATH_SOCKETNAME);
 		warnx("Check to see if the master 'lpd' process is running.");



More information about the Midnightbsd-cvs mailing list