From wkwu@ccduty.csie.nctu.edu.tw  Tue Dec 17 05:04:45 2002
Return-Path: <wkwu@ccduty.csie.nctu.edu.tw>
Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125])
	by hub.freebsd.org (Postfix) with ESMTP id 62E4A37B401
	for <FreeBSD-gnats-submit@freebsd.org>; Tue, 17 Dec 2002 05:04:45 -0800 (PST)
Received: from ccduty.csie.nctu.edu.tw (ccduty.csie.nctu.edu.tw [140.113.209.6])
	by mx1.FreeBSD.org (Postfix) with ESMTP id 7C5AB43ED1
	for <FreeBSD-gnats-submit@freebsd.org>; Tue, 17 Dec 2002 05:04:44 -0800 (PST)
	(envelope-from wkwu@ccduty.csie.nctu.edu.tw)
Received: from ccduty.csie.nctu.edu.tw (wkwu@localhost [127.0.0.1])
	by ccduty.csie.nctu.edu.tw (8.12.6/8.12.3) with ESMTP id gBHD4hHB033550
	for <FreeBSD-gnats-submit@freebsd.org>; Tue, 17 Dec 2002 21:04:43 +0800 (CST)
Received: (from wkwu@localhost)
	by ccduty.csie.nctu.edu.tw (8.12.6/8.12.6/Submit) id gBHD4hTh033549;
	Tue, 17 Dec 2002 21:04:43 +0800 (CST)
Message-Id: <200212171304.gBHD4hTh033549@ccduty.csie.nctu.edu.tw>
Date: Tue, 17 Dec 2002 21:04:43 +0800 (CST)
From: Wei-Kai Wu <wkwu@csie.nctu.edu.tw>
Reply-To: Wei-Kai Wu <wkwu@csie.nctu.edu.tw>
To: FreeBSD-gnats-submit@freebsd.org
Cc:
Subject: patch for lpd
X-Send-Pr-Version: 3.113
X-GNATS-Notify:

>Number:         46328
>Category:       bin
>Synopsis:       [patch] patch for lpd(8)
>Confidential:   no
>Severity:       non-critical
>Priority:       low
>Responsible:    gad
>State:          open
>Quarter:        
>Keywords:       
>Date-Required:  
>Class:          change-request
>Submitter-Id:   current-users
>Arrival-Date:   Tue Dec 17 05:10:01 PST 2002
>Closed-Date:    
>Last-Modified:  Wed May 21 22:02:49 UTC 2008
>Originator:     Wei-Kai Wu
>Release:        FreeBSD 4.7-STABLE i386
>Organization:
Kavalan
>Environment:
>Description:
I need to log the printed job for security reason.

The man page of 'printcap' told me that when I specify the 'if'
(input filter), it will invoke with arguments:

if [-c] -wwidth -llength -iindent -n login -h host acct-file

so I think it will be better if adding an additional argument:

	-j jobname

I modify the usr.sbin/lpr/lpd/printjob.c as below:

>How-To-Repeat:
>Fix:


--- usr.sbin/lpr/lpd/printjob.c	Thu Jun 20 16:27:38 2002
+++ usr.sbin/lpr/lpd/printjob.c.new	Tue Dec 17 20:50:50 2002
@@ -882,6 +882,24 @@
 	int dfcopies, err, i;
 	char *cp, last[BUFSIZ];
 
+	/* 
+	 * FreeBSD's cf files may put the 'N'(or 'J') after the 'f' line
+	 * open control file for Parsing the jobname first
+	 */
+	if ((cfp = fopen(file, "r")) == NULL)
+		return (OK);
+
+	while (getline(cfp)) {
+		if (line[0] == 'J' || line[0] == 'N') {
+                        if (line[1] != '\0') {
+                                strlcpy(jobname, line + 1, sizeof(jobname));
+                        } else
+                                strcpy(jobname, "(standard in)");
+			break;
+		}
+	}
+	fclose(cfp);
+
 	/*
 	 * open control file
 	 */
@@ -988,8 +1006,8 @@
 {
 	int i, amt;
 	struct stat stb;
-	char *av[15], *filtcmd;
-	char buf[BUFSIZ], opt_c[4], opt_h[4], opt_n[4];
+	char *av[17], *filtcmd;
+	char buf[BUFSIZ], opt_c[4], opt_h[4], opt_j[4], opt_n[4];
 	int copycnt, filtstat, narg, resp, sfd, sfres, sizerr, statrc;
 
 	statrc = lstat(file, &stb);
@@ -1048,6 +1066,7 @@
 			narg = 0;
 			strcpy(opt_c, "-c");
 			strcpy(opt_h, "-h");
+			strcpy(opt_j, "-j");
 			strcpy(opt_n, "-n");
 			if (format == 'l')
 				av[++narg] = opt_c;
@@ -1058,6 +1077,8 @@
 			av[++narg] = logname;
 			av[++narg] = opt_h;
 			av[++narg] = origin_host;
+			av[++narg] = opt_j;
+			av[++narg] = jobname;
 			av[++narg] = pp->acct_file;
 			av[++narg] = NULL;
 		} else if (pp->filters[LPF_OUTPUT]) {

>Release-Note:
>Audit-Trail:
Responsible-Changed-From-To: freebsd-bugs->gad 
Responsible-Changed-By: johan 
Responsible-Changed-When: Thu Dec 19 10:44:38 PST 2002 
Responsible-Changed-Why:  
Over to lpr maintainer. 

http://www.freebsd.org/cgi/query-pr.cgi?pr=46328 

From: Garance A Drosehn <gad@FreeBSD.org>
To: freebsd-gnats-submit@FreeBSD.org, wkwu@csie.nctu.edu.tw
Cc:  
Subject: Re: misc/46328: patch for lpd
Date: Mon, 27 Jan 2003 22:50:57 -0500

 I am reluctant to add any new parameters to the filters that lpd starts 
 up.  I appreciate that you have a valuable feature you want to add, but 
 there are many lpd-filters which already exist, and some of them will 
 break if they are passed a new parameter that they are not expecting.
 
 What I intend to do is to have lpd set a number of environment 
 variables before starting up the scripts.  That way the values will be 
 there for any script which wants to look for them, but will not break 
 any scripts which are not expecting to be called with any new 
 parameters.
 
 -- 
 Garance Alistair Drosehn     =      gad@gilead.netel.rpi.edu
 Senior Systems Programmer               or   gad@FreeBSD.org
 Rensselaer Polytechnic Institute;             Troy, NY;  USA
 
>Unformatted:
 
