[Midnightbsd-cvs] src [10722] trunk/usr.sbin/lpr/lpc: sync

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


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

Modified Paths:
--------------
    trunk/usr.sbin/lpr/lpc/Makefile
    trunk/usr.sbin/lpr/lpc/cmds.c
    trunk/usr.sbin/lpr/lpc/cmdtab.c
    trunk/usr.sbin/lpr/lpc/extern.h
    trunk/usr.sbin/lpr/lpc/lpc.8
    trunk/usr.sbin/lpr/lpc/lpc.c
    trunk/usr.sbin/lpr/lpc/movejobs.c

Property Changed:
----------------
    trunk/usr.sbin/lpr/lpc/lpc.8

Modified: trunk/usr.sbin/lpr/lpc/Makefile
===================================================================
--- trunk/usr.sbin/lpr/lpc/Makefile	2018-06-09 21:54:42 UTC (rev 10721)
+++ trunk/usr.sbin/lpr/lpc/Makefile	2018-06-09 21:55:16 UTC (rev 10722)
@@ -1,7 +1,8 @@
+# $MidnightBSD$
 #	From: @(#)Makefile	8.1 (Berkeley) 6/6/93
-# $MidnightBSD$
+# $FreeBSD: stable/10/usr.sbin/lpr/lpc/Makefile 321275 2017-07-20 01:07:02Z ngie $
 
-.PATH: ${.CURDIR}/../common_source
+.PATH: ${.CURDIR:H}/common_source
 
 PROG=	lpc
 MAN=	lpc.8
@@ -9,7 +10,7 @@
 BINGRP=	daemon
 BINMODE= 2555
 
-CFLAGS+= -I${.CURDIR}/../common_source
+CFLAGS+= -I${.CURDIR:H}/common_source
 
 WARNS?=	0
 

Modified: trunk/usr.sbin/lpr/lpc/cmds.c
===================================================================
--- trunk/usr.sbin/lpr/lpc/cmds.c	2018-06-09 21:54:42 UTC (rev 10721)
+++ trunk/usr.sbin/lpr/lpc/cmds.c	2018-06-09 21:55:16 UTC (rev 10722)
@@ -1,3 +1,4 @@
+/* $MidnightBSD$ */
 /*
  * Copyright (c) 1983, 1993
  *	The Regents of the University of California.  All rights reserved.
@@ -41,7 +42,7 @@
 #endif
 
 #include "lp.cdefs.h"		/* A cross-platform version of <sys/cdefs.h> */
-__MBSDID("$MidnightBSD$");
+__FBSDID("$FreeBSD: stable/10/usr.sbin/lpr/lpc/cmds.c 241852 2012-10-22 03:31:22Z eadler $");
 
 /*
  * lpc -- line printer control program -- commands:
@@ -54,6 +55,7 @@
 
 #include <signal.h>
 #include <fcntl.h>
+#include <err.h>
 #include <errno.h>
 #include <dirent.h>
 #include <unistd.h>
@@ -77,7 +79,7 @@
 
 static char	*args2line(int argc, char **argv);
 static int	 doarg(char *_job);
-static int	 doselect(struct dirent *_d);
+static int	 doselect(const struct dirent *_d);
 static int	 kill_qtask(const char *lf);
 static int	 sortq(const struct dirent **a, const struct dirent **b);
 static int	 touch(struct jobqueue *_jq);
@@ -163,6 +165,14 @@
 				break;
 			}
 		}
+		if (argc < 1) {
+			printf("error: No printer name(s) specified before"
+			    " '-msg'.\n");
+			printf("usage: %s  {all | printer ...}",
+			    generic_cmdname);
+			printf(" [-msg <text> ...]\n");
+			return;
+		}
 	}
 
 	/* call initialization routine, if there is one for this cmd */
@@ -280,10 +290,10 @@
 	pid_t pid;
 	int errsav, killres, lockres, res;
 
-	seteuid(euid);
+	PRIV_START
 	fp = fopen(lf, "r");
 	errsav = errno;
-	seteuid(uid);
+	PRIV_END
 	res = KQT_NODAEMON;
 	if (fp == NULL) {
 		/*
@@ -321,10 +331,10 @@
 		goto killdone;
 	}
 
-	seteuid(uid);
+	PRIV_END
 	killres = kill(pid, SIGTERM);
 	errsav = errno;
-	seteuid(uid);
+	PRIV_END
 	if (killres == 0) {
 		res = KQT_KILLOK;
 		printf("\tdaemon (pid %d) killed\n", pid);
@@ -368,15 +378,15 @@
 
 	status_file_name(pp, statfile, sizeof statfile);
 	umask(0);
-	seteuid(euid);
+	PRIV_START
 	fd = open(statfile, O_WRONLY|O_CREAT|O_EXLOCK, STAT_FILE_MODE);
-	seteuid(uid);
+	PRIV_END
 	if (fd < 0) {
 		printf("\tcannot create status file: %s\n", strerror(errno));
 		return;
 	}
 	(void) ftruncate(fd, 0);
-	if (msg == (char *)NULL)
+	if (msg == NULL)
 		(void) write(fd, "\n", 1);
 	else
 		(void) write(fd, msg, strlen(msg));
@@ -451,7 +461,7 @@
 static int 	 cln_testonly;		/* remove-files vs just-print-info */
 
 static int
-doselect(struct dirent *d)
+doselect(const struct dirent *d)
 {
 	int c = d->d_name[0];
 
@@ -496,7 +506,7 @@
 	fname_b = (*b)->d_name;
 
 	/*
-	 * First separate filenames into cagatories.  Catagories are
+	 * First separate filenames into categories.  Categories are
 	 * legitimate `cf', `df', `rf' & `tf' filenames, and "other" - in
 	 * that order.  It is critical that the mapping be exactly the
 	 * same for 'a' vs 'b', so define a macro for the job.
@@ -562,7 +572,7 @@
 
 	/*
 	 * We have two files which belong to the same job.  Sort based
-	 * on the catagory of file (`c' before `d', etc).
+	 * on the category of file (`c' before `d', etc).
 	 */
 	if (cat_a < cat_b) {
 		res = a_lt_b;
@@ -573,8 +583,8 @@
 	}
 
 	/*
-	 * Two files in the same catagory for a single job.  Sort based
-	 * on the sequence letter(s).  (usually `A' thru `Z', etc).
+	 * Two files in the same category for a single job.  Sort based
+	 * on the sequence letter(s).  (usually `A' through `Z', etc).
 	 */
 	if (seq_a < seq_b) {
 		res = a_lt_b;
@@ -675,9 +685,9 @@
 	linerem = sizeof(line) - (lp - line);
 
 	cln_foundcore = 0;
-	seteuid(euid);
+	PRIV_START
 	nitems = scandir(pp->spool_dir, &queue, doselect, sortq);
-	seteuid(uid);
+	PRIV_END
 	if (nitems < 0) {
 		if (!didhead) {
 			printf("%s:\n", pp->printer);
@@ -787,9 +797,9 @@
 	 * that case, we need to check the last-mod time of the symlink, and
 	 * not the file that the symlink is pointed at.
 	 */
-	seteuid(euid);
+	PRIV_START
 	res = lstat(name, &stbuf);
-	seteuid(uid);
+	PRIV_END
 	if (res < 0) {
 		printf("\terror return from stat(%s):\n", name);
 		printf("\t      %s\n", strerror(errno));
@@ -811,9 +821,9 @@
 	 * symlink before unlink-ing the file itself
 	 */
 	if (S_ISLNK(stbuf.st_mode)) {
-		seteuid(euid);
+		PRIV_START
 		res = readlink(name, linkbuf, sizeof(linkbuf));
-		seteuid(uid);
+		PRIV_END
 		if (res < 0) {
 			printf("\terror return from readlink(%s):\n", name);
 			printf("\t      %s\n", strerror(errno));
@@ -833,9 +843,9 @@
 			printf("\t    (which is a symlink to %s)\n", linkbuf);
 		}
 	} else {
-		seteuid(euid);
+		PRIV_START
 		res = unlink(name);
-		seteuid(uid);
+		PRIV_END
 		if (res < 0)
 			printf("\tcannot remove %s (!)\n", name);
 		else
@@ -975,9 +985,9 @@
 	/* make sure the queue is set to print jobs */
 	setres = set_qstate(SQS_STARTP, lf);
 
-	seteuid(euid);
+	PRIV_START
 	startok = startdaemon(pp);
-	seteuid(uid);
+	PRIV_END
 	if (!startok)
 		printf("\tcouldn't restart daemon\n");
 	else
@@ -1001,6 +1011,8 @@
 void
 setstatus_q(struct printer *pp)
 {
+	struct stat stbuf;
+	int not_shown;
 	char lf[MAXPATHLEN];
 
 	lock_file_name(pp, lf, sizeof lf);
@@ -1007,6 +1019,22 @@
 	printf("%s:\n", pp->printer);
 
 	upstat(pp, generic_msg, 1);
+
+	/*
+	 * Warn the user if 'lpq' will not display this new status-message.
+	 * Note that if lock file does not exist, then the queue is enabled
+	 * for both queuing and printing.
+	 */
+	not_shown = 1;
+	if (stat(lf, &stbuf) >= 0) {
+		if (stbuf.st_mode & LFM_PRINT_DIS)
+			not_shown = 0;
+	}
+	if (not_shown) {
+		printf("\tnote: This queue currently has printing enabled,\n");
+		printf("\t    so this -msg will only be shown by 'lpq' if\n");
+		printf("\t    a job is actively printing on it.\n");
+	}
 }
 
 /*
@@ -1023,14 +1051,14 @@
 
 	setres = set_qstate(SQS_STARTP, lf);
 
-	seteuid(euid);
+	PRIV_START
 	startok = startdaemon(pp);
-	seteuid(uid);
+	PRIV_END
 	if (!startok)
 		printf("\tcouldn't start daemon\n");
 	else
 		printf("\tdaemon started\n");
-	seteuid(uid);
+	PRIV_END
 }
 
 /*
@@ -1152,12 +1180,12 @@
 	}
 	printf("%s:\n", pp->printer);
 
-	seteuid(euid);
+	PRIV_START
 	if (chdir(pp->spool_dir) < 0) {
 		printf("\tcannot chdir to %s\n", pp->spool_dir);
 		goto out;
 	}
-	seteuid(uid);
+	PRIV_END
 	nitems = getq(pp, &queue);
 	if (nitems == 0)
 		return;
@@ -1181,12 +1209,12 @@
 	 * Turn on the public execute bit of the lock file to
 	 * get lpd to rebuild the queue after the current job.
 	 */
-	seteuid(euid);
+	PRIV_START
 	if (changed && stat(pp->lock_file, &stbuf) >= 0)
 		(void) chmod(pp->lock_file, stbuf.st_mode | LFM_RESET_QUE);
 
 out:
-	seteuid(uid);
+	PRIV_END
 } 
 
 /*
@@ -1201,9 +1229,9 @@
 
 	tvp[0].tv_sec = tvp[1].tv_sec = --mtime;
 	tvp[0].tv_usec = tvp[1].tv_usec = 0;
-	seteuid(euid);
+	PRIV_START
 	ret = utimes(jq->job_cfname, tvp);
-	seteuid(uid);
+	PRIV_END
 	return (ret);
 }
 
@@ -1260,9 +1288,9 @@
 	 * Process item consisting of owner's name (example: henry).
 	 */
 	for (qq = queue + nitems; --qq >= queue; ) {
-		seteuid(euid);
+		PRIV_START
 		fp = fopen((*qq)->job_cfname, "r");
-		seteuid(uid);
+		PRIV_END
 		if (fp == NULL)
 			continue;
 		while (getline(fp) > 0)
@@ -1293,9 +1321,9 @@
 
 	setres = set_qstate(SQS_ENABLEQ+SQS_STARTP, lf);
 
-	seteuid(euid);
+	PRIV_START
 	startok = startdaemon(pp);
-	seteuid(uid);
+	PRIV_END
 	if (!startok)
 		printf("\tcouldn't start daemon\n");
 	else

Modified: trunk/usr.sbin/lpr/lpc/cmdtab.c
===================================================================
--- trunk/usr.sbin/lpr/lpc/cmdtab.c	2018-06-09 21:54:42 UTC (rev 10721)
+++ trunk/usr.sbin/lpr/lpc/cmdtab.c	2018-06-09 21:55:16 UTC (rev 10722)
@@ -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/lpc/cmdtab.c 216372 2010-12-11 09:38:12Z joel $");
 
 #include "lpc.h"
 #include "extern.h"

Modified: trunk/usr.sbin/lpr/lpc/extern.h
===================================================================
--- trunk/usr.sbin/lpr/lpc/extern.h	2018-06-09 21:54:42 UTC (rev 10721)
+++ trunk/usr.sbin/lpr/lpc/extern.h	2018-06-09 21:55:16 UTC (rev 10722)
@@ -1,3 +1,4 @@
+/* $MidnightBSD$ */
 /*
  * Copyright (c) 1989, 1993
  *	The Regents of the University of California.  All rights reserved.
@@ -29,7 +30,7 @@
  *
  *      @(#)extern.h	8.1 (Berkeley) 6/6/93
  *
- * $MidnightBSD$
+ * $FreeBSD: stable/10/usr.sbin/lpr/lpc/extern.h 216372 2010-12-11 09:38:12Z joel $
  */
 
 

Modified: trunk/usr.sbin/lpr/lpc/lpc.8
===================================================================
--- trunk/usr.sbin/lpr/lpc/lpc.8	2018-06-09 21:54:42 UTC (rev 10721)
+++ trunk/usr.sbin/lpr/lpc/lpc.8	2018-06-09 21:55:16 UTC (rev 10722)
@@ -1,3 +1,4 @@
+.\" $MidnightBSD$
 .\" Copyright (c) 1983, 1991, 1993
 .\"	The Regents of the University of California.  All rights reserved.
 .\"
@@ -26,7 +27,7 @@
 .\" SUCH DAMAGE.
 .\"
 .\"     @(#)lpc.8	8.5 (Berkeley) 4/28/95
-.\" $MidnightBSD$
+.\" $FreeBSD: stable/10/usr.sbin/lpr/lpc/lpc.8 216372 2010-12-11 09:38:12Z joel $
 .\"
 .Dd July 16, 2002
 .Dt LPC 8


Property changes on: trunk/usr.sbin/lpr/lpc/lpc.8
___________________________________________________________________
Added: svn:keywords
## -0,0 +1 ##
+MidnightBSD=%H
\ No newline at end of property
Modified: trunk/usr.sbin/lpr/lpc/lpc.c
===================================================================
--- trunk/usr.sbin/lpr/lpc/lpc.c	2018-06-09 21:54:42 UTC (rev 10721)
+++ trunk/usr.sbin/lpr/lpc/lpc.c	2018-06-09 21:55:16 UTC (rev 10722)
@@ -1,3 +1,4 @@
+/* $MidnightBSD$ */
 /*
  * Copyright (c) 1983, 1993
  *	The Regents of the University of California.  All rights reserved.
@@ -41,7 +42,7 @@
 #endif
 
 #include "lp.cdefs.h"		/* A cross-platform version of <sys/cdefs.h> */
-__MBSDID("$MidnightBSD$");
+__FBSDID("$FreeBSD: stable/10/usr.sbin/lpr/lpc/lpc.c 241852 2012-10-22 03:31:22Z eadler $");
 
 #include <sys/param.h>
 
@@ -93,7 +94,7 @@
 
 	euid = geteuid();
 	uid = getuid();
-	seteuid(uid);
+	PRIV_END
 	progname = argv[0];
 	openlog("lpd", 0, LOG_LPR);
 
@@ -188,7 +189,7 @@
 			history(hist, &he, H_ENTER, bp);
 
 		} else {
-			if (fgets(cmdline, MAX_CMDLINE, stdin) == 0)
+			if (fgets(cmdline, MAX_CMDLINE, stdin) == NULL)
 				quit(0, NULL);
 			if (cmdline[0] == 0 || cmdline[0] == '\n')
 				break;
@@ -405,9 +406,9 @@
 		printf("%s:\n", pp->printer);
 
 	if (sump_opts & SUMP_CHDIR_SD) {
-		seteuid(euid);
+		PRIV_START
 		cdres = chdir(pp->spool_dir);
-		seteuid(uid);
+		PRIV_END
 		if (cdres < 0) {
 			printf("\tcannot chdir to %s\n", pp->spool_dir);
 			free_printer(pp);

Modified: trunk/usr.sbin/lpr/lpc/movejobs.c
===================================================================
--- trunk/usr.sbin/lpr/lpc/movejobs.c	2018-06-09 21:54:42 UTC (rev 10721)
+++ trunk/usr.sbin/lpr/lpc/movejobs.c	2018-06-09 21:55:16 UTC (rev 10722)
@@ -1,3 +1,4 @@
+/* $MidnightBSD$ */
 /*
  * ------+---------+---------+---------+---------+---------+---------+---------*
  * Copyright (c) 2002   - 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/lpc/movejobs.c 241852 2012-10-22 03:31:22Z eadler $");
 
 /*
  * movejobs.c - The lpc commands which move jobs around.
@@ -47,6 +48,7 @@
 
 #include <ctype.h>
 #include <dirent.h>	/* just for MAXNAMLEN, for job_cfname in lp.h! */
+#include <err.h>
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
@@ -147,9 +149,9 @@
 	touch_info = myinfo;
 	tvp[0].tv_sec = tvp[1].tv_sec = ++touch_info->newtime;
 	tvp[0].tv_usec = tvp[1].tv_usec = 0;
-	seteuid(euid);
+	PRIV_START
 	ret = utimes(jq->job_cfname, tvp);
-	seteuid(uid);
+	PRIV_END
 
 	if (ret == 0) {
 		if (jspec->matcheduser)



More information about the Midnightbsd-cvs mailing list