Fix bug #7288 - SMB job IDs in CUPS job names wrong.
authorJeremy Allison <jra@samba.org>
Fri, 26 Mar 2010 01:22:16 +0000 (18:22 -0700)
committerKarolin Seeger <kseeger@samba.org>
Mon, 17 May 2010 07:50:13 +0000 (09:50 +0200)
Based on a patch from Michael Karcher <samba@mkarcher.dialup.fu-berlin.de>.

I think this is the correct fix. It causes cups_job_submit to use
print_parse_jobid(), which I've moved into printing/lpq_parse.c (to allow the
link to work).

It turns out the old print_parse_jobid() was *broken*, in that the pjob
filename was set as an absolute path - not relative to the sharename (due to it
not going through the VFS calls).

This meant that the original code doing a strncmp on the first part of the
filename would always fail - it starts with a "/", not the relative pathname of
PRINT_SPOOL_PREFIX ("smbprn.").

This fix could fix some other mysterious printing bugs - probably the ones
Guenther noticed where job control fails on non-cups backends.

Contains c79ca41baf15b4ef7eb287d343b17a53ba41e852 and
92332fb2368c641db1552d1f2a2f7b3deaa11519 from master.

Jeremy.
(cherry picked from commit 12936bfeb36ae867b52fe48d0f6d3d17d5c8b110)

source3/include/proto.h
source3/printing/lpq_parse.c
source3/printing/print_cups.c
source3/printing/printing.c

index 31d0aa665434e1a8ec277e3ea4f789d182e8d79c..0813f0ce650b692b4e548e878845038765c6f48e 100644 (file)
@@ -4777,6 +4777,7 @@ void load_printers(void);
 bool parse_lpq_entry(enum printing_types printing_type,char *line,
                     print_queue_struct *buf,
                     print_status_struct *status,bool first);
+uint32_t print_parse_jobid(const char *fname);
 
 /* The following definitions come from printing/notify.c  */
 
index addf2d14aac6c62974c8cab251ef4941ed625984..16b9b09fef32f5f8d136cf0770cd7ecdc2a68abf 100644 (file)
@@ -18,6 +18,7 @@
 */
 
 #include "includes.h"
+#include "printing.h"
 
 static const char *Months[13] = { "Jan", "Feb", "Mar", "Apr", "May", "Jun",
                              "Jul", "Aug", "Sep", "Oct", "Nov", "Dec", "Err"};
@@ -1150,3 +1151,23 @@ bool parse_lpq_entry(enum printing_types printing_type,char *line,
 
        return ret;
 }
+
+/****************************************************************************
+ Parse a file name from the system spooler to generate a jobid.
+****************************************************************************/
+
+uint32_t print_parse_jobid(const char *fname)
+{
+       int jobid;
+       const char *p = strstr_m(fname,PRINT_SPOOL_PREFIX);
+
+       if (!p) {
+               return (uint32_t)-1;
+       }
+       p += strlen(PRINT_SPOOL_PREFIX);
+       jobid = atoi(p);
+       if (jobid <= 0) {
+               return (uint32_t)-1;
+       }
+       return (uint32_t)jobid;
+}
index 69d874285e0aae489dc44eec9912ca3115d73b7f..4c24e4465aef58fe7860613e0b641586564b7013 100644 (file)
@@ -918,6 +918,7 @@ static int cups_job_submit(int snum, struct printjob *pjob)
        char *cupsoptions = NULL;
        char *filename = NULL;
        size_t size;
+       uint32_t jobid = (uint32_t)-1;
        char addr[INET6_ADDRSTRLEN];
 
        DEBUG(5,("cups_job_submit(%d, %p)\n", snum, pjob));
@@ -984,12 +985,20 @@ static int cups_job_submit(int snum, struct printjob *pjob)
                     "job-originating-host-name", NULL,
                      clientname);
 
+       /* Get the jobid from the filename. */
+       jobid = print_parse_jobid(pjob->filename);
+       if (jobid == (uint32_t)-1) {
+               DEBUG(0,("cups_job_submit: failed to parse jobid from name %s\n",
+                               pjob->filename ));
+               jobid = 0;
+       }
+
        if (!push_utf8_talloc(frame, &jobname, pjob->jobname, &size)) {
                goto out;
        }
        new_jobname = talloc_asprintf(frame,
                        "%s%.8u %s", PRINT_SPOOL_PREFIX,
-                       (unsigned int)pjob->smbjob,
+                       (unsigned int)jobid,
                        jobname);
        if (new_jobname == NULL) {
                goto out;
index b5b8a56dd01291d003fbcbad8ff648fb8b3f1e5a..addd53f0e51ce5f087c23af4c3805248a2391aef 100644 (file)
@@ -643,25 +643,6 @@ void pjob_delete(const char* sharename, uint32 jobid)
        rap_jobid_delete(sharename, jobid);
 }
 
-/****************************************************************************
- Parse a file name from the system spooler to generate a jobid.
-****************************************************************************/
-
-static uint32 print_parse_jobid(char *fname)
-{
-       int jobid;
-
-       if (strncmp(fname,PRINT_SPOOL_PREFIX,strlen(PRINT_SPOOL_PREFIX)) != 0)
-               return (uint32)-1;
-       fname += strlen(PRINT_SPOOL_PREFIX);
-
-       jobid = atoi(fname);
-       if (jobid <= 0)
-               return (uint32)-1;
-
-       return (uint32)jobid;
-}
-
 /****************************************************************************
  List a unix job in the print database.
 ****************************************************************************/
@@ -2610,8 +2591,6 @@ bool print_job_end(int snum, uint32 jobid, enum file_close_type close_type)
                return True;
        }
 
-       pjob->smbjob = jobid;
-
        ret = (*(current_printif->job_submit))(snum, pjob);
 
        if (ret)