Bug 2676

Summary: Printer job was not unlinked
Product: [Retired] Red Hat Linux Reporter: genec
Component: lprAssignee: David Lawrence <dkl>
Status: CLOSED NEXTRELEASE QA Contact:
Severity: medium Docs Contact:
Priority: high    
Version: 6.0   
Target Milestone: ---   
Target Release: ---   
Hardware: All   
OS: Linux   
Whiteboard:
Fixed In Version: Doc Type: Bug Fix
Doc Text:
Story Points: ---
Clone Of: Environment:
Last Closed: 1999-06-17 21:18:37 UTC Type: ---
Regression: --- Mount Type: ---
Documentation: --- CRM:
Verified Versions: Category: ---
oVirt Team: --- RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: ---

Description genec 1999-05-09 01:39:24 UTC
I am reporting this for RedHat 6.0 but it also occurs under
5.2.

I recently changed my printer connection from a parallel
port connection one via an HP JETDIRECT EX PLUS box -- the
printer (HP 4000) remained the same.

Linux is configured with the printer as an LPD remote at an
IP address (e.g., 10.10.10.100) and queue pscript [this name
does not seem to matter).  Everthing works fine in that
output is properly printed BUT every print job results in an
email msg sent to the user whose job was printed:

From: bin <bin@xxx.home>
Subject: lp printer job "<unknown>"

Your printer job
was not unlinked: primission denied

Gene

Comment 1 Bill Nottingham 1999-05-10 16:32:59 UTC
Is the message coming from the local machine or the JetDirect box?

------- Email Received From  "Gene C." <genec@mindspring.com> 05/10/99 18:49 -------

Comment 2 Bill Nottingham 1999-05-11 14:19:59 UTC
What are the permissions on the files still remaining in the spool
directory? (and the permissions on the spool directory)

Comment 3 genec 1999-05-22 03:17:59 UTC
After a bit of looking at the my sitution I have located the bugs in
the lpr code -- specifically in lpd/printjob.c.

1. The code supporting network printers (or spooling to another lpd
system) is really kludgy!!  This stuff needs a rewrite bigtime.  I am
not sure if the patches will work in "all" cases but they "seem to fix
the basic problems.

2. Ths first bug is the use of fputs rather than fprintf which causes
two cpf lines to be merged.

diff -uNr lpr-0.36.orig/lpd/printjob.c lpr-0.36/lpd/printjob.c
--- lpr-0.36.orig/lpd/printjob.c	Mon May 10 11:06:22 1999
+++ lpr-0.36/lpd/printjob.c	Fri May 21 20:58:03 1999
@@ -896,7 +896,7 @@
                         else
     		         {
 			  if (dup_cfp)
-			    fputs(line, dup_cfp);
+			    fprintf(dup_cfp, "%s\n", line);
                          }

                         sendresult = sendfile('\3', last+1);


3. The second bug is that the code really trys to delete a file twice.
This patch ignore an error indicating that the unlink is for a file
which does not exist.

diff -uNr lpr-0.36.orig/lpd/printjob.c lpr-0.36/lpd/printjob.c
--- lpr-0.36.orig/lpd/printjob.c	Fri May 21 21:16:26 1999
+++ lpr-0.36/lpd/printjob.c	Fri May 21 21:55:34 1999
@@ -1191,6 +1191,21 @@
 	char *host;
 	char *user;
 {
+	/* this hack duplicates some code but things should work
better */
+	/* if the file does not exist, do not worry about doing unlink
*/
+	int ret;
+	extern int errno;
+	if ((strchr(file,'/') == NULL) &&
+	    (strstr(file,"..") == NULL)) {
+		ret = unlink(file);
+		if (ret == 0)
+			return;
+		if (errno == 2)
+			return;
+		syslog(LOG_ERR,"unlink file=%s, ret=%i, errno=%i",
+			file, ret, errno);
+	}
+
 	if (dounlink(file, host, user))
 		sendmail(user, UNLINK);
 }


These patches were created against source obtained from 1.3.7 of
rawhide.



------- Email Received From  "Gene C." <genec@mindspring.com> 05/21/99 23:22 -------

Comment 4 Bill Nottingham 1999-06-17 21:17:59 UTC
fixed in lpr-0.37...