2 Unix SMB/Netbios implementation.
4 printing backend routines
5 Copyright (C) Andrew Tridgell 1992-2000
6 Copyright (C) Jeremy Allison 2002
8 This program is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 3 of the License, or
11 (at your option) any later version.
13 This program is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with this program. If not, see <http://www.gnu.org/licenses/>.
23 #include "system/syslog.h"
24 #include "system/filesys.h"
26 #include "../librpc/gen_ndr/ndr_spoolss.h"
27 #include "nt_printing.h"
28 #include "../librpc/gen_ndr/netlogon.h"
29 #include "printing/notify.h"
30 #include "printing/pcap.h"
31 #include "printing/printer_list.h"
32 #include "printing/queue_process.h"
34 #include "smbd/smbd.h"
38 #include "lib/param/loadparm.h"
40 extern struct current_user current_user
;
41 extern userdom_struct current_user_info
;
43 /* Current printer interface */
44 static bool remove_from_jobs_added(const char* sharename
, uint32 jobid
);
47 the printing backend revolves around a tdb database that stores the
48 SMB view of the print queue
50 The key for this database is a jobid - a internally generated number that
51 uniquely identifies a print job
53 reading the print queue involves two steps:
54 - possibly running lpq and updating the internal database from that
55 - reading entries from the database
57 jobids are assigned when a job starts spooling.
60 static TDB_CONTEXT
*rap_tdb
;
61 static uint16 next_rap_jobid
;
62 struct rap_jobid_key
{
67 /***************************************************************************
68 Nightmare. LANMAN jobid's are 16 bit numbers..... We must map them to 32
69 bit RPC jobids.... JRA.
70 ***************************************************************************/
72 uint16
pjobid_to_rap(const char* sharename
, uint32 jobid
)
76 struct rap_jobid_key jinfo
;
79 DEBUG(10,("pjobid_to_rap: called.\n"));
82 /* Create the in-memory tdb. */
83 rap_tdb
= tdb_open_log(NULL
, 0, TDB_INTERNAL
, (O_RDWR
|O_CREAT
), 0644);
89 fstrcpy( jinfo
.sharename
, sharename
);
91 key
.dptr
= (uint8
*)&jinfo
;
92 key
.dsize
= sizeof(jinfo
);
94 data
= tdb_fetch_compat(rap_tdb
, key
);
95 if (data
.dptr
&& data
.dsize
== sizeof(uint16
)) {
96 rap_jobid
= SVAL(data
.dptr
, 0);
98 DEBUG(10,("pjobid_to_rap: jobid %u maps to RAP jobid %u\n",
99 (unsigned int)jobid
, (unsigned int)rap_jobid
));
102 SAFE_FREE(data
.dptr
);
103 /* Not found - create and store mapping. */
104 rap_jobid
= ++next_rap_jobid
;
106 rap_jobid
= ++next_rap_jobid
;
107 SSVAL(buf
,0,rap_jobid
);
109 data
.dsize
= sizeof(rap_jobid
);
110 tdb_store(rap_tdb
, key
, data
, TDB_REPLACE
);
111 tdb_store(rap_tdb
, data
, key
, TDB_REPLACE
);
113 DEBUG(10,("pjobid_to_rap: created jobid %u maps to RAP jobid %u\n",
114 (unsigned int)jobid
, (unsigned int)rap_jobid
));
118 bool rap_to_pjobid(uint16 rap_jobid
, fstring sharename
, uint32
*pjobid
)
123 DEBUG(10,("rap_to_pjobid called.\n"));
128 SSVAL(buf
,0,rap_jobid
);
130 key
.dsize
= sizeof(rap_jobid
);
131 data
= tdb_fetch_compat(rap_tdb
, key
);
132 if ( data
.dptr
&& data
.dsize
== sizeof(struct rap_jobid_key
) )
134 struct rap_jobid_key
*jinfo
= (struct rap_jobid_key
*)data
.dptr
;
135 if (sharename
!= NULL
) {
136 fstrcpy( sharename
, jinfo
->sharename
);
138 *pjobid
= jinfo
->jobid
;
139 DEBUG(10,("rap_to_pjobid: jobid %u maps to RAP jobid %u\n",
140 (unsigned int)*pjobid
, (unsigned int)rap_jobid
));
141 SAFE_FREE(data
.dptr
);
145 DEBUG(10,("rap_to_pjobid: Failed to lookup RAP jobid %u\n",
146 (unsigned int)rap_jobid
));
147 SAFE_FREE(data
.dptr
);
151 void rap_jobid_delete(const char* sharename
, uint32 jobid
)
155 struct rap_jobid_key jinfo
;
158 DEBUG(10,("rap_jobid_delete: called.\n"));
163 ZERO_STRUCT( jinfo
);
164 fstrcpy( jinfo
.sharename
, sharename
);
166 key
.dptr
= (uint8
*)&jinfo
;
167 key
.dsize
= sizeof(jinfo
);
169 data
= tdb_fetch_compat(rap_tdb
, key
);
170 if (!data
.dptr
|| (data
.dsize
!= sizeof(uint16
))) {
171 DEBUG(10,("rap_jobid_delete: cannot find jobid %u\n",
172 (unsigned int)jobid
));
173 SAFE_FREE(data
.dptr
);
177 DEBUG(10,("rap_jobid_delete: deleting jobid %u\n",
178 (unsigned int)jobid
));
180 rap_jobid
= SVAL(data
.dptr
, 0);
181 SAFE_FREE(data
.dptr
);
182 SSVAL(buf
,0,rap_jobid
);
184 data
.dsize
= sizeof(rap_jobid
);
185 tdb_delete(rap_tdb
, key
);
186 tdb_delete(rap_tdb
, data
);
189 static int get_queue_status(const char* sharename
, print_status_struct
*);
191 /****************************************************************************
192 Initialise the printing backend. Called once at startup before the fork().
193 ****************************************************************************/
195 bool print_backend_init(struct messaging_context
*msg_ctx
)
197 const char *sversion
= "INFO/version";
198 int services
= lp_numservices();
201 if (!printer_list_parent_init()) {
205 unlink(cache_path("printing.tdb"));
206 mkdir(cache_path("printing"),0755);
208 /* handle a Samba upgrade */
210 for (snum
= 0; snum
< services
; snum
++) {
211 struct tdb_print_db
*pdb
;
212 if (!lp_print_ok(snum
))
215 pdb
= get_print_db_byname(lp_const_servicename(snum
));
218 if (tdb_lock_bystring(pdb
->tdb
, sversion
) != 0) {
219 DEBUG(0,("print_backend_init: Failed to open printer %s database\n", lp_const_servicename(snum
) ));
220 release_print_db(pdb
);
223 if (tdb_fetch_int32(pdb
->tdb
, sversion
) != PRINT_DATABASE_VERSION
) {
224 tdb_wipe_all(pdb
->tdb
);
225 tdb_store_int32(pdb
->tdb
, sversion
, PRINT_DATABASE_VERSION
);
227 tdb_unlock_bystring(pdb
->tdb
, sversion
);
228 release_print_db(pdb
);
231 close_all_print_db(); /* Don't leave any open. */
233 /* do NT print initialization... */
234 return nt_printing_init(msg_ctx
);
237 /****************************************************************************
238 Shut down printing backend. Called once at shutdown to close the tdb.
239 ****************************************************************************/
241 void printing_end(void)
243 close_all_print_db(); /* Don't leave any open. */
246 /****************************************************************************
247 Retrieve the set of printing functions for a given service. This allows
248 us to set the printer function table based on the value of the 'printing'
251 Use the generic interface as the default and only use cups interface only
252 when asked for (and only when supported)
253 ****************************************************************************/
255 static struct printif
*get_printer_fns_from_type( enum printing_types type
)
257 struct printif
*printer_fns
= &generic_printif
;
260 if ( type
== PRINT_CUPS
) {
261 printer_fns
= &cups_printif
;
263 #endif /* HAVE_CUPS */
266 if ( type
== PRINT_IPRINT
) {
267 printer_fns
= &iprint_printif
;
269 #endif /* HAVE_IPRINT */
271 printer_fns
->type
= type
;
276 static struct printif
*get_printer_fns( int snum
)
278 return get_printer_fns_from_type( (enum printing_types
)lp_printing(snum
) );
282 /****************************************************************************
283 Useful function to generate a tdb key.
284 ****************************************************************************/
286 static TDB_DATA
print_key(uint32 jobid
, uint32
*tmp
)
290 SIVAL(tmp
, 0, jobid
);
291 ret
.dptr
= (uint8
*)tmp
;
292 ret
.dsize
= sizeof(*tmp
);
296 /****************************************************************************
297 Pack the devicemode to store it in a tdb.
298 ****************************************************************************/
299 static int pack_devicemode(struct spoolss_DeviceMode
*devmode
, uint8
*buf
, int buflen
)
301 enum ndr_err_code ndr_err
;
306 ndr_err
= ndr_push_struct_blob(&blob
, talloc_tos(),
308 (ndr_push_flags_fn_t
)
309 ndr_push_spoolss_DeviceMode
);
310 if (!NDR_ERR_CODE_IS_SUCCESS(ndr_err
)) {
311 DEBUG(10, ("pack_devicemode: "
312 "error encoding spoolss_DeviceMode\n"));
319 len
= tdb_pack(buf
, buflen
, "B", blob
.length
, blob
.data
);
322 DEBUG(8, ("Packed devicemode [%s]\n", devmode
->formname
));
329 /****************************************************************************
330 Unpack the devicemode to store it in a tdb.
331 ****************************************************************************/
332 static int unpack_devicemode(TALLOC_CTX
*mem_ctx
,
333 const uint8
*buf
, int buflen
,
334 struct spoolss_DeviceMode
**devmode
)
336 struct spoolss_DeviceMode
*dm
;
337 enum ndr_err_code ndr_err
;
345 len
= tdb_unpack(buf
, buflen
, "B", &data_len
, &data
);
350 dm
= talloc_zero(mem_ctx
, struct spoolss_DeviceMode
);
355 blob
= data_blob_const(data
, data_len
);
357 ndr_err
= ndr_pull_struct_blob(&blob
, dm
, dm
,
358 (ndr_pull_flags_fn_t
)ndr_pull_spoolss_DeviceMode
);
359 if (!NDR_ERR_CODE_IS_SUCCESS(ndr_err
)) {
360 DEBUG(10, ("unpack_devicemode: "
361 "error parsing spoolss_DeviceMode\n"));
365 DEBUG(8, ("Unpacked devicemode [%s](%s)\n",
366 dm
->devicename
, dm
->formname
));
367 if (dm
->driverextra_data
.data
) {
368 DEBUG(8, ("with a private section of %d bytes\n",
369 dm
->__driverextra_length
));
379 /***********************************************************************
380 unpack a pjob from a tdb buffer
381 ***********************************************************************/
383 static int unpack_pjob(TALLOC_CTX
*mem_ctx
, uint8
*buf
, int buflen
,
384 struct printjob
*pjob
)
388 uint32 pjpid
, pjjobid
, pjsysjob
, pjfd
, pjstarttime
, pjstatus
;
389 uint32 pjsize
, pjpage_count
, pjspooled
, pjsmbjob
;
395 len
+= tdb_unpack(buf
+len
, buflen
-len
, "ddddddddddfffff",
416 used
= unpack_devicemode(mem_ctx
, buf
+len
, buflen
-len
, &pjob
->devmode
);
424 pjob
->jobid
= pjjobid
;
425 pjob
->sysjob
= pjsysjob
;
427 pjob
->starttime
= pjstarttime
;
428 pjob
->status
= pjstatus
;
430 pjob
->page_count
= pjpage_count
;
431 pjob
->spooled
= pjspooled
;
432 pjob
->smbjob
= pjsmbjob
;
438 /****************************************************************************
439 Useful function to find a print job in the database.
440 ****************************************************************************/
442 static struct printjob
*print_job_find(TALLOC_CTX
*mem_ctx
,
443 const char *sharename
,
446 struct printjob
*pjob
;
449 struct tdb_print_db
*pdb
= get_print_db_byname(sharename
);
451 DEBUG(10,("print_job_find: looking up job %u for share %s\n",
452 (unsigned int)jobid
, sharename
));
458 ret
= tdb_fetch_compat(pdb
->tdb
, print_key(jobid
, &tmp
));
459 release_print_db(pdb
);
462 DEBUG(10, ("print_job_find: failed to find jobid %u.\n",
467 pjob
= talloc_zero(mem_ctx
, struct printjob
);
472 if (unpack_pjob(mem_ctx
, ret
.dptr
, ret
.dsize
, pjob
) == -1) {
473 DEBUG(10, ("failed to unpack jobid %u.\n", jobid
));
479 DEBUG(10,("print_job_find: returning system job %d for jobid %u.\n",
480 pjob
->sysjob
, jobid
));
481 SMB_ASSERT(pjob
->jobid
== jobid
);
488 /* Convert a unix jobid to a smb jobid */
490 struct unixjob_traverse_state
{
492 uint32 sysjob_to_jobid_value
;
495 static int unixjob_traverse_fn(TDB_CONTEXT
*the_tdb
, TDB_DATA key
,
496 TDB_DATA data
, void *private_data
)
498 struct printjob
*pjob
;
499 struct unixjob_traverse_state
*state
=
500 (struct unixjob_traverse_state
*)private_data
;
502 if (!data
.dptr
|| data
.dsize
== 0)
505 pjob
= (struct printjob
*)data
.dptr
;
506 if (key
.dsize
!= sizeof(uint32
))
509 if (state
->sysjob
== pjob
->sysjob
) {
510 state
->sysjob_to_jobid_value
= pjob
->jobid
;
517 static uint32
sysjob_to_jobid_pdb(struct tdb_print_db
*pdb
, int sysjob
)
519 struct unixjob_traverse_state state
;
521 state
.sysjob
= sysjob
;
522 state
.sysjob_to_jobid_value
= (uint32
)-1;
524 tdb_traverse(pdb
->tdb
, unixjob_traverse_fn
, &state
);
526 return state
.sysjob_to_jobid_value
;
529 /****************************************************************************
530 This is a *horribly expensive call as we have to iterate through all the
531 current printer tdb's. Don't do this often ! JRA.
532 ****************************************************************************/
534 uint32
sysjob_to_jobid(int unix_jobid
)
536 int services
= lp_numservices();
538 struct unixjob_traverse_state state
;
540 state
.sysjob
= unix_jobid
;
541 state
.sysjob_to_jobid_value
= (uint32
)-1;
543 for (snum
= 0; snum
< services
; snum
++) {
544 struct tdb_print_db
*pdb
;
545 if (!lp_print_ok(snum
))
547 pdb
= get_print_db_byname(lp_const_servicename(snum
));
551 tdb_traverse(pdb
->tdb
, unixjob_traverse_fn
, &state
);
552 release_print_db(pdb
);
553 if (state
.sysjob_to_jobid_value
!= (uint32
)-1)
554 return state
.sysjob_to_jobid_value
;
559 /****************************************************************************
560 Send notifications based on what has changed after a pjob_store.
561 ****************************************************************************/
563 static const struct {
565 uint32_t spoolss_status
;
566 } lpq_to_spoolss_status_map
[] = {
567 { LPQ_QUEUED
, JOB_STATUS_QUEUED
},
568 { LPQ_PAUSED
, JOB_STATUS_PAUSED
},
569 { LPQ_SPOOLING
, JOB_STATUS_SPOOLING
},
570 { LPQ_PRINTING
, JOB_STATUS_PRINTING
},
571 { LPQ_DELETING
, JOB_STATUS_DELETING
},
572 { LPQ_OFFLINE
, JOB_STATUS_OFFLINE
},
573 { LPQ_PAPEROUT
, JOB_STATUS_PAPEROUT
},
574 { LPQ_PRINTED
, JOB_STATUS_PRINTED
},
575 { LPQ_DELETED
, JOB_STATUS_DELETED
},
576 { LPQ_BLOCKED
, JOB_STATUS_BLOCKED_DEVQ
},
577 { LPQ_USER_INTERVENTION
, JOB_STATUS_USER_INTERVENTION
},
581 /* Convert a lpq status value stored in printing.tdb into the
582 appropriate win32 API constant. */
584 static uint32
map_to_spoolss_status(uint32 lpq_status
)
588 while (lpq_to_spoolss_status_map
[i
].lpq_status
!= -1) {
589 if (lpq_to_spoolss_status_map
[i
].lpq_status
== lpq_status
)
590 return lpq_to_spoolss_status_map
[i
].spoolss_status
;
597 /***************************************************************************
598 Append a jobid to the 'jobs changed' list.
599 ***************************************************************************/
601 static bool add_to_jobs_changed(struct tdb_print_db
*pdb
, uint32_t jobid
)
604 uint32_t store_jobid
;
606 SIVAL(&store_jobid
, 0, jobid
);
607 data
.dptr
= (uint8
*) &store_jobid
;
610 DEBUG(10,("add_to_jobs_added: Added jobid %u\n", (unsigned int)jobid
));
612 return (tdb_append(pdb
->tdb
, string_tdb_data("INFO/jobs_changed"),
616 /***************************************************************************
617 Remove a jobid from the 'jobs changed' list.
618 ***************************************************************************/
620 static bool remove_from_jobs_changed(const char* sharename
, uint32_t jobid
)
622 struct tdb_print_db
*pdb
= get_print_db_byname(sharename
);
626 bool gotlock
= False
;
634 key
= string_tdb_data("INFO/jobs_changed");
636 if (tdb_chainlock_with_timeout(pdb
->tdb
, key
, 5) != 0)
641 data
= tdb_fetch_compat(pdb
->tdb
, key
);
643 if (data
.dptr
== NULL
|| data
.dsize
== 0 || (data
.dsize
% 4 != 0))
646 job_count
= data
.dsize
/ 4;
647 for (i
= 0; i
< job_count
; i
++) {
650 ch_jobid
= IVAL(data
.dptr
, i
*4);
651 if (ch_jobid
== jobid
) {
652 if (i
< job_count
-1 )
653 memmove(data
.dptr
+ (i
*4), data
.dptr
+ (i
*4) + 4, (job_count
- i
- 1)*4 );
655 if (tdb_store(pdb
->tdb
, key
, data
, TDB_REPLACE
) != 0)
665 tdb_chainunlock(pdb
->tdb
, key
);
666 SAFE_FREE(data
.dptr
);
667 release_print_db(pdb
);
669 DEBUG(10,("remove_from_jobs_changed: removed jobid %u\n", (unsigned int)jobid
));
671 DEBUG(10,("remove_from_jobs_changed: Failed to remove jobid %u\n", (unsigned int)jobid
));
675 static void pjob_store_notify(struct tevent_context
*ev
,
676 struct messaging_context
*msg_ctx
,
677 const char* sharename
, uint32 jobid
,
678 struct printjob
*old_data
,
679 struct printjob
*new_data
,
682 bool new_job
= false;
683 bool changed
= false;
685 if (old_data
== NULL
) {
689 /* ACHTUNG! Due to a bug in Samba's spoolss parsing of the
690 NOTIFY_INFO_DATA buffer, we *have* to send the job submission
691 time first or else we'll end up with potential alignment
692 errors. I don't think the systemtime should be spooled as
693 a string, but this gets us around that error.
694 --jerry (i'll feel dirty for this) */
697 notify_job_submitted(ev
, msg_ctx
,
698 sharename
, jobid
, new_data
->starttime
);
699 notify_job_username(ev
, msg_ctx
,
700 sharename
, jobid
, new_data
->user
);
701 notify_job_name(ev
, msg_ctx
,
702 sharename
, jobid
, new_data
->jobname
);
703 notify_job_status(ev
, msg_ctx
,
704 sharename
, jobid
, map_to_spoolss_status(new_data
->status
));
705 notify_job_total_bytes(ev
, msg_ctx
,
706 sharename
, jobid
, new_data
->size
);
707 notify_job_total_pages(ev
, msg_ctx
,
708 sharename
, jobid
, new_data
->page_count
);
710 if (!strequal(old_data
->jobname
, new_data
->jobname
)) {
711 notify_job_name(ev
, msg_ctx
, sharename
,
712 jobid
, new_data
->jobname
);
716 if (old_data
->status
!= new_data
->status
) {
717 notify_job_status(ev
, msg_ctx
,
719 map_to_spoolss_status(new_data
->status
));
722 if (old_data
->size
!= new_data
->size
) {
723 notify_job_total_bytes(ev
, msg_ctx
,
724 sharename
, jobid
, new_data
->size
);
727 if (old_data
->page_count
!= new_data
->page_count
) {
728 notify_job_total_pages(ev
, msg_ctx
,
730 new_data
->page_count
);
737 /****************************************************************************
738 Store a job structure back to the database.
739 ****************************************************************************/
741 static bool pjob_store(struct tevent_context
*ev
,
742 struct messaging_context
*msg_ctx
,
743 const char* sharename
, uint32 jobid
,
744 struct printjob
*pjob
)
747 TDB_DATA old_data
, new_data
;
749 struct tdb_print_db
*pdb
= get_print_db_byname(sharename
);
751 int len
, newlen
, buflen
;
759 old_data
= tdb_fetch_compat(pdb
->tdb
, print_key(jobid
, &tmp
));
761 /* Doh! Now we have to pack/unpack data since the NT_DEVICEMODE was added */
768 len
+= tdb_pack(buf
+len
, buflen
-len
, "ddddddddddfffff",
771 (uint32
)pjob
->sysjob
,
773 (uint32
)pjob
->starttime
,
774 (uint32
)pjob
->status
,
776 (uint32
)pjob
->page_count
,
777 (uint32
)pjob
->spooled
,
778 (uint32
)pjob
->smbjob
,
785 len
+= pack_devicemode(pjob
->devmode
, buf
+len
, buflen
-len
);
788 buf
= (uint8
*)SMB_REALLOC(buf
, len
);
790 DEBUG(0,("pjob_store: failed to enlarge buffer!\n"));
795 } while ( buflen
!= len
);
801 new_data
.dsize
= len
;
802 ret
= (tdb_store(pdb
->tdb
, print_key(jobid
, &tmp
), new_data
,
805 /* Send notify updates for what has changed */
808 bool changed
= false;
809 struct printjob old_pjob
;
811 if (old_data
.dsize
) {
812 TALLOC_CTX
*tmp_ctx
= talloc_new(ev
);
816 len
= unpack_pjob(tmp_ctx
, old_data
.dptr
,
817 old_data
.dsize
, &old_pjob
);
819 pjob_store_notify(ev
,
821 sharename
, jobid
, &old_pjob
,
825 add_to_jobs_changed(pdb
, jobid
);
828 talloc_free(tmp_ctx
);
832 pjob_store_notify(ev
, msg_ctx
,
833 sharename
, jobid
, NULL
, pjob
,
839 release_print_db(pdb
);
840 SAFE_FREE( old_data
.dptr
);
846 /****************************************************************************
847 Remove a job structure from the database.
848 ****************************************************************************/
850 static void pjob_delete(struct tevent_context
*ev
,
851 struct messaging_context
*msg_ctx
,
852 const char* sharename
, uint32 jobid
)
855 struct printjob
*pjob
;
856 uint32 job_status
= 0;
857 struct tdb_print_db
*pdb
;
858 TALLOC_CTX
*tmp_ctx
= talloc_new(ev
);
859 if (tmp_ctx
== NULL
) {
863 pdb
= get_print_db_byname(sharename
);
868 pjob
= print_job_find(tmp_ctx
, sharename
, jobid
);
870 DEBUG(5, ("we were asked to delete nonexistent job %u\n",
875 /* We must cycle through JOB_STATUS_DELETING and
876 JOB_STATUS_DELETED for the port monitor to delete the job
879 job_status
= JOB_STATUS_DELETING
|JOB_STATUS_DELETED
;
880 notify_job_status(ev
, msg_ctx
, sharename
, jobid
, job_status
);
882 /* Remove from printing.tdb */
884 tdb_delete(pdb
->tdb
, print_key(jobid
, &tmp
));
885 remove_from_jobs_added(sharename
, jobid
);
886 rap_jobid_delete(sharename
, jobid
);
888 release_print_db(pdb
);
890 talloc_free(tmp_ctx
);
893 /****************************************************************************
894 List a unix job in the print database.
895 ****************************************************************************/
897 static void print_unix_job(struct tevent_context
*ev
,
898 struct messaging_context
*msg_ctx
,
899 const char *sharename
, print_queue_struct
*q
,
902 struct printjob pj
, *old_pj
;
903 TALLOC_CTX
*tmp_ctx
= talloc_new(ev
);
904 if (tmp_ctx
== NULL
) {
908 if (jobid
== (uint32
)-1) {
909 jobid
= q
->sysjob
+ UNIX_JOB_START
;
912 /* Preserve the timestamp on an existing unix print job */
914 old_pj
= print_job_find(tmp_ctx
, sharename
, jobid
);
920 pj
.sysjob
= q
->sysjob
;
922 pj
.starttime
= old_pj
? old_pj
->starttime
: q
->time
;
923 pj
.status
= q
->status
;
926 fstrcpy(pj
.filename
, old_pj
? old_pj
->filename
: "");
927 if (jobid
< UNIX_JOB_START
) {
929 fstrcpy(pj
.jobname
, old_pj
? old_pj
->jobname
: "Remote Downlevel Document");
932 fstrcpy(pj
.jobname
, old_pj
? old_pj
->jobname
: q
->fs_file
);
934 fstrcpy(pj
.user
, old_pj
? old_pj
->user
: q
->fs_user
);
935 fstrcpy(pj
.queuename
, old_pj
? old_pj
->queuename
: sharename
);
937 pjob_store(ev
, msg_ctx
, sharename
, jobid
, &pj
);
938 talloc_free(tmp_ctx
);
942 struct traverse_struct
{
943 print_queue_struct
*queue
;
944 int qcount
, snum
, maxcount
, total_jobs
;
945 const char *sharename
;
947 const char *lprm_command
;
948 struct printif
*print_if
;
949 struct tevent_context
*ev
;
950 struct messaging_context
*msg_ctx
;
954 /****************************************************************************
955 Utility fn to delete any jobs that are no longer active.
956 ****************************************************************************/
958 static int traverse_fn_delete(TDB_CONTEXT
*t
, TDB_DATA key
, TDB_DATA data
, void *state
)
960 struct traverse_struct
*ts
= (struct traverse_struct
*)state
;
961 struct printjob pjob
;
965 if ( key
.dsize
!= sizeof(jobid
) )
968 if (unpack_pjob(ts
->mem_ctx
, data
.dptr
, data
.dsize
, &pjob
) == -1)
970 talloc_free(pjob
.devmode
);
974 /* remove a unix job if it isn't in the system queue any more */
975 for (i
=0;i
<ts
->qcount
;i
++) {
976 if (ts
->queue
[i
].sysjob
== pjob
.sysjob
) {
980 if (i
== ts
->qcount
) {
981 DEBUG(10,("traverse_fn_delete: pjob %u deleted due to !smbjob\n",
982 (unsigned int)jobid
));
983 pjob_delete(ts
->ev
, ts
->msg_ctx
,
984 ts
->sharename
, jobid
);
988 /* need to continue the the bottom of the function to
989 save the correct attributes */
992 /* maybe it hasn't been spooled yet */
994 /* if a job is not spooled and the process doesn't
995 exist then kill it. This cleans up after smbd
997 if (!process_exists_by_pid(pjob
.pid
)) {
998 DEBUG(10,("traverse_fn_delete: pjob %u deleted due to !process_exists (%u)\n",
999 (unsigned int)jobid
, (unsigned int)pjob
.pid
));
1000 pjob_delete(ts
->ev
, ts
->msg_ctx
,
1001 ts
->sharename
, jobid
);
1007 /* this check only makes sense for jobs submitted from Windows clients */
1010 for (i
=0;i
<ts
->qcount
;i
++) {
1011 if ( pjob
.status
== LPQ_DELETED
)
1014 if (ts
->queue
[i
].sysjob
== pjob
.sysjob
) {
1016 /* try to clean up any jobs that need to be deleted */
1018 if ( pjob
.status
== LPQ_DELETING
) {
1021 result
= (*(ts
->print_if
->job_delete
))(
1022 ts
->sharename
, ts
->lprm_command
, &pjob
);
1024 if ( result
!= 0 ) {
1025 /* if we can't delete, then reset the job status */
1026 pjob
.status
= LPQ_QUEUED
;
1027 pjob_store(ts
->ev
, ts
->msg_ctx
,
1028 ts
->sharename
, jobid
, &pjob
);
1031 /* if we deleted the job, the remove the tdb record */
1034 ts
->sharename
, jobid
);
1035 pjob
.status
= LPQ_DELETED
;
1045 /* The job isn't in the system queue - we have to assume it has
1046 completed, so delete the database entry. */
1048 if (i
== ts
->qcount
) {
1050 /* A race can occur between the time a job is spooled and
1051 when it appears in the lpq output. This happens when
1052 the job is added to printing.tdb when another smbd
1053 running print_queue_update() has completed a lpq and
1054 is currently traversing the printing tdb and deleting jobs.
1055 Don't delete the job if it was submitted after the lpq_time. */
1057 if (pjob
.starttime
< ts
->lpq_time
) {
1058 DEBUG(10,("traverse_fn_delete: pjob %u deleted due to pjob.starttime (%u) < ts->lpq_time (%u)\n",
1059 (unsigned int)jobid
,
1060 (unsigned int)pjob
.starttime
,
1061 (unsigned int)ts
->lpq_time
));
1062 pjob_delete(ts
->ev
, ts
->msg_ctx
,
1063 ts
->sharename
, jobid
);
1069 /* Save the pjob attributes we will store. */
1070 ts
->queue
[i
].sysjob
= pjob
.sysjob
;
1071 ts
->queue
[i
].size
= pjob
.size
;
1072 ts
->queue
[i
].page_count
= pjob
.page_count
;
1073 ts
->queue
[i
].status
= pjob
.status
;
1074 ts
->queue
[i
].priority
= 1;
1075 ts
->queue
[i
].time
= pjob
.starttime
;
1076 fstrcpy(ts
->queue
[i
].fs_user
, pjob
.user
);
1077 fstrcpy(ts
->queue
[i
].fs_file
, pjob
.jobname
);
1084 /****************************************************************************
1085 Check if the print queue has been updated recently enough.
1086 ****************************************************************************/
1088 static void print_cache_flush(const char *sharename
)
1091 struct tdb_print_db
*pdb
= get_print_db_byname(sharename
);
1095 slprintf(key
, sizeof(key
)-1, "CACHE/%s", sharename
);
1096 tdb_store_int32(pdb
->tdb
, key
, -1);
1097 release_print_db(pdb
);
1100 /****************************************************************************
1101 Check if someone already thinks they are doing the update.
1102 ****************************************************************************/
1104 static pid_t
get_updating_pid(const char *sharename
)
1109 struct tdb_print_db
*pdb
= get_print_db_byname(sharename
);
1113 slprintf(keystr
, sizeof(keystr
)-1, "UPDATING/%s", sharename
);
1114 key
= string_tdb_data(keystr
);
1116 data
= tdb_fetch_compat(pdb
->tdb
, key
);
1117 release_print_db(pdb
);
1118 if (!data
.dptr
|| data
.dsize
!= sizeof(pid_t
)) {
1119 SAFE_FREE(data
.dptr
);
1123 updating_pid
= IVAL(data
.dptr
, 0);
1124 SAFE_FREE(data
.dptr
);
1126 if (process_exists_by_pid(updating_pid
))
1127 return updating_pid
;
1132 /****************************************************************************
1133 Set the fact that we're doing the update, or have finished doing the update
1135 ****************************************************************************/
1137 static void set_updating_pid(const fstring sharename
, bool updating
)
1142 pid_t updating_pid
= getpid();
1145 struct tdb_print_db
*pdb
= get_print_db_byname(sharename
);
1150 slprintf(keystr
, sizeof(keystr
)-1, "UPDATING/%s", sharename
);
1151 key
= string_tdb_data(keystr
);
1153 DEBUG(5, ("set_updating_pid: %s updating lpq cache for print share %s\n",
1154 updating
? "" : "not ",
1158 tdb_delete(pdb
->tdb
, key
);
1159 release_print_db(pdb
);
1163 SIVAL( buffer
, 0, updating_pid
);
1165 data
.dsize
= 4; /* we always assume this is a 4 byte value */
1167 tdb_store(pdb
->tdb
, key
, data
, TDB_REPLACE
);
1168 release_print_db(pdb
);
1171 /****************************************************************************
1172 Sort print jobs by submittal time.
1173 ****************************************************************************/
1175 static int printjob_comp(print_queue_struct
*j1
, print_queue_struct
*j2
)
1186 /* Sort on job start time */
1188 if (j1
->time
== j2
->time
)
1190 return (j1
->time
> j2
->time
) ? 1 : -1;
1193 /****************************************************************************
1194 Store the sorted queue representation for later portmon retrieval.
1196 ****************************************************************************/
1198 static void store_queue_struct(struct tdb_print_db
*pdb
, struct traverse_struct
*pts
)
1201 int max_reported_jobs
= lp_max_reported_jobs(pts
->snum
);
1202 print_queue_struct
*queue
= pts
->queue
;
1205 unsigned int qcount
;
1207 if (max_reported_jobs
&& (max_reported_jobs
< pts
->qcount
))
1208 pts
->qcount
= max_reported_jobs
;
1211 /* Work out the size. */
1213 data
.dsize
+= tdb_pack(NULL
, 0, "d", qcount
);
1215 for (i
= 0; i
< pts
->qcount
; i
++) {
1216 if ( queue
[i
].status
== LPQ_DELETED
)
1220 data
.dsize
+= tdb_pack(NULL
, 0, "ddddddff",
1221 (uint32
)queue
[i
].sysjob
,
1222 (uint32
)queue
[i
].size
,
1223 (uint32
)queue
[i
].page_count
,
1224 (uint32
)queue
[i
].status
,
1225 (uint32
)queue
[i
].priority
,
1226 (uint32
)queue
[i
].time
,
1231 if ((data
.dptr
= (uint8
*)SMB_MALLOC(data
.dsize
)) == NULL
)
1235 len
+= tdb_pack(data
.dptr
+ len
, data
.dsize
- len
, "d", qcount
);
1236 for (i
= 0; i
< pts
->qcount
; i
++) {
1237 if ( queue
[i
].status
== LPQ_DELETED
)
1240 len
+= tdb_pack(data
.dptr
+ len
, data
.dsize
- len
, "ddddddff",
1241 (uint32
)queue
[i
].sysjob
,
1242 (uint32
)queue
[i
].size
,
1243 (uint32
)queue
[i
].page_count
,
1244 (uint32
)queue
[i
].status
,
1245 (uint32
)queue
[i
].priority
,
1246 (uint32
)queue
[i
].time
,
1251 tdb_store(pdb
->tdb
, string_tdb_data("INFO/linear_queue_array"), data
,
1253 SAFE_FREE(data
.dptr
);
1257 static TDB_DATA
get_jobs_added_data(struct tdb_print_db
*pdb
)
1263 data
= tdb_fetch_compat(pdb
->tdb
, string_tdb_data("INFO/jobs_added"));
1264 if (data
.dptr
== NULL
|| data
.dsize
== 0 || (data
.dsize
% 4 != 0)) {
1265 SAFE_FREE(data
.dptr
);
1272 static void check_job_added(const char *sharename
, TDB_DATA data
, uint32 jobid
)
1275 unsigned int job_count
= data
.dsize
/ 4;
1277 for (i
= 0; i
< job_count
; i
++) {
1280 ch_jobid
= IVAL(data
.dptr
, i
*4);
1281 if (ch_jobid
== jobid
)
1282 remove_from_jobs_added(sharename
, jobid
);
1286 /****************************************************************************
1287 Check if the print queue has been updated recently enough.
1288 ****************************************************************************/
1290 static bool print_cache_expired(const char *sharename
, bool check_pending
)
1293 time_t last_qscan_time
, time_now
= time(NULL
);
1294 struct tdb_print_db
*pdb
= get_print_db_byname(sharename
);
1295 bool result
= False
;
1300 snprintf(key
, sizeof(key
), "CACHE/%s", sharename
);
1301 last_qscan_time
= (time_t)tdb_fetch_int32(pdb
->tdb
, key
);
1304 * Invalidate the queue for 3 reasons.
1305 * (1). last queue scan time == -1.
1306 * (2). Current time - last queue scan time > allowed cache time.
1307 * (3). last queue scan time > current time + MAX_CACHE_VALID_TIME (1 hour by default).
1308 * This last test picks up machines for which the clock has been moved
1309 * forward, an lpq scan done and then the clock moved back. Otherwise
1310 * that last lpq scan would stay around for a loooong loooong time... :-). JRA.
1313 if (last_qscan_time
== ((time_t)-1)
1314 || (time_now
- last_qscan_time
) >= lp_lpqcachetime()
1315 || last_qscan_time
> (time_now
+ MAX_CACHE_VALID_TIME
))
1318 time_t msg_pending_time
;
1320 DEBUG(4, ("print_cache_expired: cache expired for queue %s "
1321 "(last_qscan_time = %d, time now = %d, qcachetime = %d)\n",
1322 sharename
, (int)last_qscan_time
, (int)time_now
,
1323 (int)lp_lpqcachetime() ));
1325 /* check if another smbd has already sent a message to update the
1326 queue. Give the pending message one minute to clear and
1327 then send another message anyways. Make sure to check for
1328 clocks that have been run forward and then back again. */
1330 snprintf(key
, sizeof(key
), "MSG_PENDING/%s", sharename
);
1333 && tdb_fetch_uint32( pdb
->tdb
, key
, &u
)
1334 && (msg_pending_time
=u
) > 0
1335 && msg_pending_time
<= time_now
1336 && (time_now
- msg_pending_time
) < 60 )
1338 DEBUG(4,("print_cache_expired: message already pending for %s. Accepting cache\n",
1347 release_print_db(pdb
);
1351 /****************************************************************************
1352 main work for updating the lpq cache for a printer queue
1353 ****************************************************************************/
1355 static void print_queue_update_internal(struct tevent_context
*ev
,
1356 struct messaging_context
*msg_ctx
,
1357 const char *sharename
,
1358 struct printif
*current_printif
,
1359 char *lpq_command
, char *lprm_command
)
1362 print_queue_struct
*queue
= NULL
;
1363 print_status_struct status
;
1364 print_status_struct old_status
;
1365 struct printjob
*pjob
;
1366 struct traverse_struct tstruct
;
1369 fstring keystr
, cachestr
;
1370 struct tdb_print_db
*pdb
= get_print_db_byname(sharename
);
1371 TALLOC_CTX
*tmp_ctx
= talloc_new(ev
);
1373 if ((pdb
== NULL
) || (tmp_ctx
== NULL
)) {
1377 DEBUG(5,("print_queue_update_internal: printer = %s, type = %d, lpq command = [%s]\n",
1378 sharename
, current_printif
->type
, lpq_command
));
1381 * Update the cache time FIRST ! Stops others even
1382 * attempting to get the lock and doing this
1383 * if the lpq takes a long time.
1386 slprintf(cachestr
, sizeof(cachestr
)-1, "CACHE/%s", sharename
);
1387 tdb_store_int32(pdb
->tdb
, cachestr
, (int)time(NULL
));
1389 /* get the current queue using the appropriate interface */
1390 ZERO_STRUCT(status
);
1392 qcount
= (*(current_printif
->queue_get
))(sharename
,
1393 current_printif
->type
,
1394 lpq_command
, &queue
, &status
);
1396 DEBUG(3, ("print_queue_update_internal: %d job%s in queue for %s\n",
1397 qcount
, (qcount
!= 1) ? "s" : "", sharename
));
1399 /* Sort the queue by submission time otherwise they are displayed
1402 TYPESAFE_QSORT(queue
, qcount
, printjob_comp
);
1405 any job in the internal database that is marked as spooled
1406 and doesn't exist in the system queue is considered finished
1407 and removed from the database
1409 any job in the system database but not in the internal database
1410 is added as a unix job
1412 fill in any system job numbers as we go
1414 jcdata
= get_jobs_added_data(pdb
);
1416 for (i
=0; i
<qcount
; i
++) {
1417 uint32 jobid
= sysjob_to_jobid_pdb(pdb
, queue
[i
].sysjob
);
1418 if (jobid
== (uint32
)-1) {
1419 /* assume its a unix print job */
1420 print_unix_job(ev
, msg_ctx
,
1421 sharename
, &queue
[i
], jobid
);
1425 /* we have an active SMB print job - update its status */
1426 pjob
= print_job_find(tmp_ctx
, sharename
, jobid
);
1428 /* err, somethings wrong. Probably smbd was restarted
1429 with jobs in the queue. All we can do is treat them
1430 like unix jobs. Pity. */
1431 DEBUG(1, ("queued print job %d not found in jobs list, "
1432 "assuming unix job\n", jobid
));
1433 print_unix_job(ev
, msg_ctx
,
1434 sharename
, &queue
[i
], jobid
);
1438 /* don't reset the status on jobs to be deleted */
1440 if ( pjob
->status
!= LPQ_DELETING
)
1441 pjob
->status
= queue
[i
].status
;
1443 pjob_store(ev
, msg_ctx
, sharename
, jobid
, pjob
);
1445 check_job_added(sharename
, jcdata
, jobid
);
1448 SAFE_FREE(jcdata
.dptr
);
1450 /* now delete any queued entries that don't appear in the
1452 tstruct
.queue
= queue
;
1453 tstruct
.qcount
= qcount
;
1455 tstruct
.total_jobs
= 0;
1456 tstruct
.lpq_time
= time(NULL
);
1457 tstruct
.sharename
= sharename
;
1458 tstruct
.lprm_command
= lprm_command
;
1459 tstruct
.print_if
= current_printif
;
1461 tstruct
.msg_ctx
= msg_ctx
;
1462 tstruct
.mem_ctx
= tmp_ctx
;
1464 tdb_traverse(pdb
->tdb
, traverse_fn_delete
, (void *)&tstruct
);
1466 /* Store the linearised queue, max jobs only. */
1467 store_queue_struct(pdb
, &tstruct
);
1469 SAFE_FREE(tstruct
.queue
);
1470 talloc_free(tmp_ctx
);
1472 DEBUG(10,("print_queue_update_internal: printer %s INFO/total_jobs = %d\n",
1473 sharename
, tstruct
.total_jobs
));
1475 tdb_store_int32(pdb
->tdb
, "INFO/total_jobs", tstruct
.total_jobs
);
1477 get_queue_status(sharename
, &old_status
);
1478 if (old_status
.qcount
!= qcount
)
1479 DEBUG(10,("print_queue_update_internal: queue status change %d jobs -> %d jobs for printer %s\n",
1480 old_status
.qcount
, qcount
, sharename
));
1482 /* store the new queue status structure */
1483 slprintf(keystr
, sizeof(keystr
)-1, "STATUS/%s", sharename
);
1484 key
= string_tdb_data(keystr
);
1486 status
.qcount
= qcount
;
1487 data
.dptr
= (uint8
*)&status
;
1488 data
.dsize
= sizeof(status
);
1489 tdb_store(pdb
->tdb
, key
, data
, TDB_REPLACE
);
1492 * Update the cache time again. We want to do this call
1493 * as little as possible...
1496 slprintf(keystr
, sizeof(keystr
)-1, "CACHE/%s", sharename
);
1497 tdb_store_int32(pdb
->tdb
, keystr
, (int32
)time(NULL
));
1499 /* clear the msg pending record for this queue */
1501 snprintf(keystr
, sizeof(keystr
), "MSG_PENDING/%s", sharename
);
1503 if ( !tdb_store_uint32( pdb
->tdb
, keystr
, 0 ) ) {
1504 /* log a message but continue on */
1506 DEBUG(0,("print_queue_update: failed to store MSG_PENDING flag for [%s]!\n",
1510 release_print_db( pdb
);
1515 /****************************************************************************
1516 Update the internal database from the system print queue for a queue.
1517 obtain a lock on the print queue before proceeding (needed when mutiple
1518 smbd processes maytry to update the lpq cache concurrently).
1519 ****************************************************************************/
1521 static void print_queue_update_with_lock( struct tevent_context
*ev
,
1522 struct messaging_context
*msg_ctx
,
1523 const char *sharename
,
1524 struct printif
*current_printif
,
1525 char *lpq_command
, char *lprm_command
)
1528 struct tdb_print_db
*pdb
;
1530 DEBUG(5,("print_queue_update_with_lock: printer share = %s\n", sharename
));
1531 pdb
= get_print_db_byname(sharename
);
1535 if ( !print_cache_expired(sharename
, False
) ) {
1536 DEBUG(5,("print_queue_update_with_lock: print cache for %s is still ok\n", sharename
));
1537 release_print_db(pdb
);
1542 * Check to see if someone else is doing this update.
1543 * This is essentially a mutex on the update.
1546 if (get_updating_pid(sharename
) != -1) {
1547 release_print_db(pdb
);
1551 /* Lock the queue for the database update */
1553 slprintf(keystr
, sizeof(keystr
) - 1, "LOCK/%s", sharename
);
1554 /* Only wait 10 seconds for this. */
1555 if (tdb_lock_bystring_with_timeout(pdb
->tdb
, keystr
, 10) != 0) {
1556 DEBUG(0,("print_queue_update_with_lock: Failed to lock printer %s database\n", sharename
));
1557 release_print_db(pdb
);
1562 * Ensure that no one else got in here.
1563 * If the updating pid is still -1 then we are
1567 if (get_updating_pid(sharename
) != -1) {
1569 * Someone else is doing the update, exit.
1571 tdb_unlock_bystring(pdb
->tdb
, keystr
);
1572 release_print_db(pdb
);
1577 * We're going to do the update ourselves.
1580 /* Tell others we're doing the update. */
1581 set_updating_pid(sharename
, True
);
1584 * Allow others to enter and notice we're doing
1588 tdb_unlock_bystring(pdb
->tdb
, keystr
);
1590 /* do the main work now */
1592 print_queue_update_internal(ev
, msg_ctx
,
1593 sharename
, current_printif
,
1594 lpq_command
, lprm_command
);
1596 /* Delete our pid from the db. */
1597 set_updating_pid(sharename
, False
);
1598 release_print_db(pdb
);
1601 /****************************************************************************
1602 this is the receive function of the background lpq updater
1603 ****************************************************************************/
1604 void print_queue_receive(struct messaging_context
*msg
,
1607 struct server_id server_id
,
1611 char *lpqcommand
= NULL
, *lprmcommand
= NULL
;
1615 len
= tdb_unpack( (uint8
*)data
->data
, data
->length
, "fdPP",
1622 SAFE_FREE(lpqcommand
);
1623 SAFE_FREE(lprmcommand
);
1624 DEBUG(0,("print_queue_receive: Got invalid print queue update message\n"));
1628 print_queue_update_with_lock(server_event_context(), msg
, sharename
,
1629 get_printer_fns_from_type((enum printing_types
)printing_type
),
1630 lpqcommand
, lprmcommand
);
1632 SAFE_FREE(lpqcommand
);
1633 SAFE_FREE(lprmcommand
);
1637 /****************************************************************************
1638 update the internal database from the system print queue for a queue
1639 ****************************************************************************/
1641 extern pid_t background_lpq_updater_pid
;
1643 static void print_queue_update(struct messaging_context
*msg_ctx
,
1644 int snum
, bool force
)
1648 char *lpqcommand
= NULL
;
1649 char *lprmcommand
= NULL
;
1650 uint8
*buffer
= NULL
;
1653 struct tdb_print_db
*pdb
;
1655 struct printif
*current_printif
;
1656 TALLOC_CTX
*ctx
= talloc_tos();
1658 fstrcpy( sharename
, lp_const_servicename(snum
));
1660 /* don't strip out characters like '$' from the printername */
1662 lpqcommand
= talloc_string_sub2(ctx
,
1663 lp_lpqcommand(talloc_tos(), snum
),
1665 lp_printername(talloc_tos(), snum
),
1666 false, false, false);
1670 lpqcommand
= talloc_sub_advanced(ctx
,
1671 lp_servicename(talloc_tos(), snum
),
1672 current_user_info
.unix_name
,
1674 current_user
.ut
.gid
,
1675 get_current_username(),
1676 current_user_info
.domain
,
1682 lprmcommand
= talloc_string_sub2(ctx
,
1683 lp_lprmcommand(talloc_tos(), snum
),
1685 lp_printername(talloc_tos(), snum
),
1686 false, false, false);
1690 lprmcommand
= talloc_sub_advanced(ctx
,
1691 lp_servicename(talloc_tos(), snum
),
1692 current_user_info
.unix_name
,
1694 current_user
.ut
.gid
,
1695 get_current_username(),
1696 current_user_info
.domain
,
1703 * Make sure that the background queue process exists.
1704 * Otherwise just do the update ourselves
1707 if ( force
|| background_lpq_updater_pid
== -1 ) {
1708 DEBUG(4,("print_queue_update: updating queue [%s] myself\n", sharename
));
1709 current_printif
= get_printer_fns( snum
);
1710 print_queue_update_with_lock(server_event_context(), msg_ctx
,
1711 sharename
, current_printif
,
1712 lpqcommand
, lprmcommand
);
1717 type
= lp_printing(snum
);
1719 /* get the length */
1721 len
= tdb_pack( NULL
, 0, "fdPP",
1727 buffer
= SMB_XMALLOC_ARRAY( uint8
, len
);
1729 /* now pack the buffer */
1730 newlen
= tdb_pack( buffer
, len
, "fdPP",
1736 SMB_ASSERT( newlen
== len
);
1738 DEBUG(10,("print_queue_update: Sending message -> printer = %s, "
1739 "type = %d, lpq command = [%s] lprm command = [%s]\n",
1740 sharename
, type
, lpqcommand
, lprmcommand
));
1742 /* here we set a msg pending record for other smbd processes
1743 to throttle the number of duplicate print_queue_update msgs
1746 pdb
= get_print_db_byname(sharename
);
1752 snprintf(key
, sizeof(key
), "MSG_PENDING/%s", sharename
);
1754 if ( !tdb_store_uint32( pdb
->tdb
, key
, time(NULL
) ) ) {
1755 /* log a message but continue on */
1757 DEBUG(0,("print_queue_update: failed to store MSG_PENDING flag for [%s]!\n",
1761 release_print_db( pdb
);
1763 /* finally send the message */
1765 messaging_send_buf(msg_ctx
, pid_to_procid(background_lpq_updater_pid
),
1766 MSG_PRINTER_UPDATE
, (uint8
*)buffer
, len
);
1768 SAFE_FREE( buffer
);
1773 /****************************************************************************
1774 Create/Update an entry in the print tdb that will allow us to send notify
1775 updates only to interested smbd's.
1776 ****************************************************************************/
1778 bool print_notify_register_pid(int snum
)
1781 struct tdb_print_db
*pdb
= NULL
;
1782 TDB_CONTEXT
*tdb
= NULL
;
1783 const char *printername
;
1784 uint32_t mypid
= (uint32_t)getpid();
1788 /* if (snum == -1), then the change notify request was
1789 on a print server handle and we need to register on
1794 int num_services
= lp_numservices();
1797 for ( idx
=0; idx
<num_services
; idx
++ ) {
1798 if (lp_snum_ok(idx
) && lp_print_ok(idx
) )
1799 print_notify_register_pid(idx
);
1804 else /* register for a specific printer */
1806 printername
= lp_const_servicename(snum
);
1807 pdb
= get_print_db_byname(printername
);
1813 if (tdb_lock_bystring_with_timeout(tdb
, NOTIFY_PID_LIST_KEY
, 10) != 0) {
1814 DEBUG(0,("print_notify_register_pid: Failed to lock printer %s\n",
1817 release_print_db(pdb
);
1821 data
= get_printer_notify_pid_list( tdb
, printername
, True
);
1823 /* Add ourselves and increase the refcount. */
1825 for (i
= 0; i
< data
.dsize
; i
+= 8) {
1826 if (IVAL(data
.dptr
,i
) == mypid
) {
1827 uint32 new_refcount
= IVAL(data
.dptr
, i
+4) + 1;
1828 SIVAL(data
.dptr
, i
+4, new_refcount
);
1833 if (i
== data
.dsize
) {
1834 /* We weren't in the list. Realloc. */
1835 data
.dptr
= (uint8
*)SMB_REALLOC(data
.dptr
, data
.dsize
+ 8);
1837 DEBUG(0,("print_notify_register_pid: Relloc fail for printer %s\n",
1842 SIVAL(data
.dptr
,data
.dsize
- 8,mypid
);
1843 SIVAL(data
.dptr
,data
.dsize
- 4,1); /* Refcount. */
1846 /* Store back the record. */
1847 if (tdb_store_bystring(tdb
, NOTIFY_PID_LIST_KEY
, data
, TDB_REPLACE
) != 0) {
1848 DEBUG(0,("print_notify_register_pid: Failed to update pid \
1849 list for printer %s\n", printername
));
1857 tdb_unlock_bystring(tdb
, NOTIFY_PID_LIST_KEY
);
1859 release_print_db(pdb
);
1860 SAFE_FREE(data
.dptr
);
1864 /****************************************************************************
1865 Update an entry in the print tdb that will allow us to send notify
1866 updates only to interested smbd's.
1867 ****************************************************************************/
1869 bool print_notify_deregister_pid(int snum
)
1872 struct tdb_print_db
*pdb
= NULL
;
1873 TDB_CONTEXT
*tdb
= NULL
;
1874 const char *printername
;
1875 uint32_t mypid
= (uint32_t)getpid();
1879 /* if ( snum == -1 ), we are deregister a print server handle
1880 which means to deregister on all print queues */
1884 int num_services
= lp_numservices();
1887 for ( idx
=0; idx
<num_services
; idx
++ ) {
1888 if ( lp_snum_ok(idx
) && lp_print_ok(idx
) )
1889 print_notify_deregister_pid(idx
);
1894 else /* deregister a specific printer */
1896 printername
= lp_const_servicename(snum
);
1897 pdb
= get_print_db_byname(printername
);
1903 if (tdb_lock_bystring_with_timeout(tdb
, NOTIFY_PID_LIST_KEY
, 10) != 0) {
1904 DEBUG(0,("print_notify_register_pid: Failed to lock \
1905 printer %s database\n", printername
));
1907 release_print_db(pdb
);
1911 data
= get_printer_notify_pid_list( tdb
, printername
, True
);
1913 /* Reduce refcount. Remove ourselves if zero. */
1915 for (i
= 0; i
< data
.dsize
; ) {
1916 if (IVAL(data
.dptr
,i
) == mypid
) {
1917 uint32 refcount
= IVAL(data
.dptr
, i
+4);
1921 if (refcount
== 0) {
1922 if (data
.dsize
- i
> 8)
1923 memmove( &data
.dptr
[i
], &data
.dptr
[i
+8], data
.dsize
- i
- 8);
1927 SIVAL(data
.dptr
, i
+4, refcount
);
1933 if (data
.dsize
== 0)
1934 SAFE_FREE(data
.dptr
);
1936 /* Store back the record. */
1937 if (tdb_store_bystring(tdb
, NOTIFY_PID_LIST_KEY
, data
, TDB_REPLACE
) != 0) {
1938 DEBUG(0,("print_notify_register_pid: Failed to update pid \
1939 list for printer %s\n", printername
));
1947 tdb_unlock_bystring(tdb
, NOTIFY_PID_LIST_KEY
);
1949 release_print_db(pdb
);
1950 SAFE_FREE(data
.dptr
);
1954 /****************************************************************************
1955 Check if a jobid is valid. It is valid if it exists in the database.
1956 ****************************************************************************/
1958 bool print_job_exists(const char* sharename
, uint32 jobid
)
1960 struct tdb_print_db
*pdb
= get_print_db_byname(sharename
);
1966 ret
= tdb_exists(pdb
->tdb
, print_key(jobid
, &tmp
));
1967 release_print_db(pdb
);
1971 /****************************************************************************
1972 Return the device mode asigned to a specific print job.
1973 Only valid for the process doing the spooling and when the job
1974 has not been spooled.
1975 ****************************************************************************/
1977 struct spoolss_DeviceMode
*print_job_devmode(TALLOC_CTX
*mem_ctx
,
1978 const char *sharename
,
1981 struct printjob
*pjob
= print_job_find(mem_ctx
, sharename
, jobid
);
1986 return pjob
->devmode
;
1989 /****************************************************************************
1990 Set the name of a job. Only possible for owner.
1991 ****************************************************************************/
1993 bool print_job_set_name(struct tevent_context
*ev
,
1994 struct messaging_context
*msg_ctx
,
1995 const char *sharename
, uint32 jobid
, const char *name
)
1997 struct printjob
*pjob
;
1999 TALLOC_CTX
*tmp_ctx
= talloc_new(ev
);
2000 if (tmp_ctx
== NULL
) {
2004 pjob
= print_job_find(tmp_ctx
, sharename
, jobid
);
2005 if (!pjob
|| pjob
->pid
!= getpid()) {
2010 fstrcpy(pjob
->jobname
, name
);
2011 ret
= pjob_store(ev
, msg_ctx
, sharename
, jobid
, pjob
);
2013 talloc_free(tmp_ctx
);
2017 /****************************************************************************
2018 Get the name of a job. Only possible for owner.
2019 ****************************************************************************/
2021 bool print_job_get_name(TALLOC_CTX
*mem_ctx
, const char *sharename
, uint32_t jobid
, char **name
)
2023 struct printjob
*pjob
;
2025 pjob
= print_job_find(mem_ctx
, sharename
, jobid
);
2026 if (!pjob
|| pjob
->pid
!= getpid()) {
2030 *name
= pjob
->jobname
;
2035 /***************************************************************************
2036 Remove a jobid from the 'jobs added' list.
2037 ***************************************************************************/
2039 static bool remove_from_jobs_added(const char* sharename
, uint32 jobid
)
2041 struct tdb_print_db
*pdb
= get_print_db_byname(sharename
);
2043 size_t job_count
, i
;
2045 bool gotlock
= False
;
2053 key
= string_tdb_data("INFO/jobs_added");
2055 if (tdb_chainlock_with_timeout(pdb
->tdb
, key
, 5) != 0)
2060 data
= tdb_fetch_compat(pdb
->tdb
, key
);
2062 if (data
.dptr
== NULL
|| data
.dsize
== 0 || (data
.dsize
% 4 != 0))
2065 job_count
= data
.dsize
/ 4;
2066 for (i
= 0; i
< job_count
; i
++) {
2069 ch_jobid
= IVAL(data
.dptr
, i
*4);
2070 if (ch_jobid
== jobid
) {
2071 if (i
< job_count
-1 )
2072 memmove(data
.dptr
+ (i
*4), data
.dptr
+ (i
*4) + 4, (job_count
- i
- 1)*4 );
2074 if (tdb_store(pdb
->tdb
, key
, data
, TDB_REPLACE
) != 0)
2084 tdb_chainunlock(pdb
->tdb
, key
);
2085 SAFE_FREE(data
.dptr
);
2086 release_print_db(pdb
);
2088 DEBUG(10,("remove_from_jobs_added: removed jobid %u\n", (unsigned int)jobid
));
2090 DEBUG(10,("remove_from_jobs_added: Failed to remove jobid %u\n", (unsigned int)jobid
));
2094 /****************************************************************************
2095 Delete a print job - don't update queue.
2096 ****************************************************************************/
2098 static bool print_job_delete1(struct tevent_context
*ev
,
2099 struct messaging_context
*msg_ctx
,
2100 int snum
, uint32 jobid
)
2102 const char* sharename
= lp_const_servicename(snum
);
2103 struct printjob
*pjob
;
2105 struct printif
*current_printif
= get_printer_fns( snum
);
2107 TALLOC_CTX
*tmp_ctx
= talloc_new(ev
);
2108 if (tmp_ctx
== NULL
) {
2112 pjob
= print_job_find(tmp_ctx
, sharename
, jobid
);
2119 * If already deleting just return.
2122 if (pjob
->status
== LPQ_DELETING
) {
2127 /* Hrm - we need to be able to cope with deleting a job before it
2128 has reached the spooler. Just mark it as LPQ_DELETING and
2129 let the print_queue_update() code rmeove the record */
2132 if (pjob
->sysjob
== -1) {
2133 DEBUG(5, ("attempt to delete job %u not seen by lpr\n", (unsigned int)jobid
));
2136 /* Set the tdb entry to be deleting. */
2138 pjob
->status
= LPQ_DELETING
;
2139 pjob_store(ev
, msg_ctx
, sharename
, jobid
, pjob
);
2141 if (pjob
->spooled
&& pjob
->sysjob
!= -1)
2143 result
= (*(current_printif
->job_delete
))(
2144 lp_printername(talloc_tos(), snum
),
2145 lp_lprmcommand(talloc_tos(), snum
),
2148 /* Delete the tdb entry if the delete succeeded or the job hasn't
2152 struct tdb_print_db
*pdb
= get_print_db_byname(sharename
);
2159 pjob_delete(ev
, msg_ctx
, sharename
, jobid
);
2160 /* Ensure we keep a rough count of the number of total jobs... */
2161 tdb_change_int32_atomic(pdb
->tdb
, "INFO/total_jobs", &njobs
, -1);
2162 release_print_db(pdb
);
2166 remove_from_jobs_added( sharename
, jobid
);
2168 ret
= (result
== 0);
2170 talloc_free(tmp_ctx
);
2174 /****************************************************************************
2175 Return true if the current user owns the print job.
2176 ****************************************************************************/
2178 static bool is_owner(const struct auth_session_info
*server_info
,
2179 const char *servicename
,
2182 struct printjob
*pjob
;
2184 TALLOC_CTX
*tmp_ctx
= talloc_new(server_info
);
2185 if (tmp_ctx
== NULL
) {
2189 pjob
= print_job_find(tmp_ctx
, servicename
, jobid
);
2190 if (!pjob
|| !server_info
) {
2195 ret
= strequal(pjob
->user
, server_info
->unix_info
->sanitized_username
);
2197 talloc_free(tmp_ctx
);
2201 /****************************************************************************
2203 ****************************************************************************/
2205 WERROR
print_job_delete(const struct auth_session_info
*server_info
,
2206 struct messaging_context
*msg_ctx
,
2207 int snum
, uint32_t jobid
)
2209 const char* sharename
= lp_const_servicename(snum
);
2210 struct printjob
*pjob
;
2213 TALLOC_CTX
*tmp_ctx
= talloc_new(msg_ctx
);
2214 if (tmp_ctx
== NULL
) {
2215 return WERR_NOT_ENOUGH_MEMORY
;
2218 owner
= is_owner(server_info
, lp_const_servicename(snum
), jobid
);
2220 /* Check access against security descriptor or whether the user
2224 !print_access_check(server_info
, msg_ctx
, snum
,
2225 JOB_ACCESS_ADMINISTER
)) {
2226 DEBUG(3, ("delete denied by security descriptor\n"));
2228 /* BEGIN_ADMIN_LOG */
2229 sys_adminlog( LOG_ERR
,
2230 "Permission denied-- user not allowed to delete, \
2231 pause, or resume print job. User name: %s. Printer name: %s.",
2232 uidtoname(server_info
->unix_token
->uid
),
2233 lp_printername(talloc_tos(), snum
) );
2236 werr
= WERR_ACCESS_DENIED
;
2241 * get the spooled filename of the print job
2242 * if this works, then the file has not been spooled
2243 * to the underlying print system. Just delete the
2244 * spool file & return.
2247 pjob
= print_job_find(tmp_ctx
, sharename
, jobid
);
2248 if (!pjob
|| pjob
->spooled
|| pjob
->pid
!= getpid()) {
2249 DEBUG(10, ("Skipping spool file removal for job %u\n", jobid
));
2251 DEBUG(10, ("Removing spool file [%s]\n", pjob
->filename
));
2252 if (unlink(pjob
->filename
) == -1) {
2253 werr
= map_werror_from_unix(errno
);
2258 if (!print_job_delete1(server_event_context(), msg_ctx
, snum
, jobid
)) {
2259 werr
= WERR_ACCESS_DENIED
;
2263 /* force update the database and say the delete failed if the
2266 print_queue_update(msg_ctx
, snum
, True
);
2268 pjob
= print_job_find(tmp_ctx
, sharename
, jobid
);
2269 if (pjob
&& (pjob
->status
!= LPQ_DELETING
)) {
2270 werr
= WERR_ACCESS_DENIED
;
2273 werr
= WERR_PRINTER_HAS_JOBS_QUEUED
;
2276 talloc_free(tmp_ctx
);
2280 /****************************************************************************
2282 ****************************************************************************/
2284 WERROR
print_job_pause(const struct auth_session_info
*server_info
,
2285 struct messaging_context
*msg_ctx
,
2286 int snum
, uint32 jobid
)
2288 const char* sharename
= lp_const_servicename(snum
);
2289 struct printjob
*pjob
;
2291 struct printif
*current_printif
= get_printer_fns( snum
);
2293 TALLOC_CTX
*tmp_ctx
= talloc_new(msg_ctx
);
2294 if (tmp_ctx
== NULL
) {
2295 return WERR_NOT_ENOUGH_MEMORY
;
2298 pjob
= print_job_find(tmp_ctx
, sharename
, jobid
);
2299 if (!pjob
|| !server_info
) {
2300 DEBUG(10, ("print_job_pause: no pjob or user for jobid %u\n",
2301 (unsigned int)jobid
));
2302 werr
= WERR_INVALID_PARAM
;
2306 if (!pjob
->spooled
|| pjob
->sysjob
== -1) {
2307 DEBUG(10, ("print_job_pause: not spooled or bad sysjob = %d for jobid %u\n",
2308 (int)pjob
->sysjob
, (unsigned int)jobid
));
2309 werr
= WERR_INVALID_PARAM
;
2313 if (!is_owner(server_info
, lp_const_servicename(snum
), jobid
) &&
2314 !print_access_check(server_info
, msg_ctx
, snum
,
2315 JOB_ACCESS_ADMINISTER
)) {
2316 DEBUG(3, ("pause denied by security descriptor\n"));
2318 /* BEGIN_ADMIN_LOG */
2319 sys_adminlog( LOG_ERR
,
2320 "Permission denied-- user not allowed to delete, \
2321 pause, or resume print job. User name: %s. Printer name: %s.",
2322 uidtoname(server_info
->unix_token
->uid
),
2323 lp_printername(talloc_tos(), snum
) );
2326 werr
= WERR_ACCESS_DENIED
;
2330 /* need to pause the spooled entry */
2331 ret
= (*(current_printif
->job_pause
))(snum
, pjob
);
2334 werr
= WERR_INVALID_PARAM
;
2338 /* force update the database */
2339 print_cache_flush(lp_const_servicename(snum
));
2341 /* Send a printer notify message */
2343 notify_job_status(server_event_context(), msg_ctx
, sharename
, jobid
,
2346 /* how do we tell if this succeeded? */
2349 talloc_free(tmp_ctx
);
2353 /****************************************************************************
2355 ****************************************************************************/
2357 WERROR
print_job_resume(const struct auth_session_info
*server_info
,
2358 struct messaging_context
*msg_ctx
,
2359 int snum
, uint32 jobid
)
2361 const char *sharename
= lp_const_servicename(snum
);
2362 struct printjob
*pjob
;
2364 struct printif
*current_printif
= get_printer_fns( snum
);
2366 TALLOC_CTX
*tmp_ctx
= talloc_new(msg_ctx
);
2367 if (tmp_ctx
== NULL
)
2368 return WERR_NOT_ENOUGH_MEMORY
;
2370 pjob
= print_job_find(tmp_ctx
, sharename
, jobid
);
2371 if (!pjob
|| !server_info
) {
2372 DEBUG(10, ("print_job_resume: no pjob or user for jobid %u\n",
2373 (unsigned int)jobid
));
2374 werr
= WERR_INVALID_PARAM
;
2378 if (!pjob
->spooled
|| pjob
->sysjob
== -1) {
2379 DEBUG(10, ("print_job_resume: not spooled or bad sysjob = %d for jobid %u\n",
2380 (int)pjob
->sysjob
, (unsigned int)jobid
));
2381 werr
= WERR_INVALID_PARAM
;
2385 if (!is_owner(server_info
, lp_const_servicename(snum
), jobid
) &&
2386 !print_access_check(server_info
, msg_ctx
, snum
,
2387 JOB_ACCESS_ADMINISTER
)) {
2388 DEBUG(3, ("resume denied by security descriptor\n"));
2390 /* BEGIN_ADMIN_LOG */
2391 sys_adminlog( LOG_ERR
,
2392 "Permission denied-- user not allowed to delete, \
2393 pause, or resume print job. User name: %s. Printer name: %s.",
2394 uidtoname(server_info
->unix_token
->uid
),
2395 lp_printername(talloc_tos(), snum
) );
2397 werr
= WERR_ACCESS_DENIED
;
2401 ret
= (*(current_printif
->job_resume
))(snum
, pjob
);
2404 werr
= WERR_INVALID_PARAM
;
2408 /* force update the database */
2409 print_cache_flush(lp_const_servicename(snum
));
2411 /* Send a printer notify message */
2413 notify_job_status(server_event_context(), msg_ctx
, sharename
, jobid
,
2418 talloc_free(tmp_ctx
);
2422 /****************************************************************************
2423 Write to a print file.
2424 ****************************************************************************/
2426 ssize_t
print_job_write(struct tevent_context
*ev
,
2427 struct messaging_context
*msg_ctx
,
2428 int snum
, uint32 jobid
, const char *buf
, size_t size
)
2430 const char* sharename
= lp_const_servicename(snum
);
2431 ssize_t return_code
;
2432 struct printjob
*pjob
;
2433 TALLOC_CTX
*tmp_ctx
= talloc_new(ev
);
2434 if (tmp_ctx
== NULL
) {
2438 pjob
= print_job_find(tmp_ctx
, sharename
, jobid
);
2444 /* don't allow another process to get this info - it is meaningless */
2445 if (pjob
->pid
!= getpid()) {
2450 /* if SMBD is spooling this can't be allowed */
2451 if (pjob
->status
== PJOB_SMBD_SPOOLING
) {
2456 return_code
= write_data(pjob
->fd
, buf
, size
);
2457 if (return_code
> 0) {
2459 pjob_store(ev
, msg_ctx
, sharename
, jobid
, pjob
);
2462 talloc_free(tmp_ctx
);
2466 /****************************************************************************
2467 Get the queue status - do not update if db is out of date.
2468 ****************************************************************************/
2470 static int get_queue_status(const char* sharename
, print_status_struct
*status
)
2474 struct tdb_print_db
*pdb
= get_print_db_byname(sharename
);
2478 ZERO_STRUCTP(status
);
2485 fstr_sprintf(keystr
, "STATUS/%s", sharename
);
2486 data
= tdb_fetch_compat(pdb
->tdb
, string_tdb_data(keystr
));
2488 if (data
.dsize
== sizeof(print_status_struct
))
2489 /* this memcpy is ok since the status struct was
2490 not packed before storing it in the tdb */
2491 memcpy(status
, data
.dptr
, sizeof(print_status_struct
));
2492 SAFE_FREE(data
.dptr
);
2495 len
= tdb_fetch_int32(pdb
->tdb
, "INFO/total_jobs");
2496 release_print_db(pdb
);
2497 return (len
== -1 ? 0 : len
);
2500 /****************************************************************************
2501 Determine the number of jobs in a queue.
2502 ****************************************************************************/
2504 int print_queue_length(struct messaging_context
*msg_ctx
, int snum
,
2505 print_status_struct
*pstatus
)
2507 const char* sharename
= lp_const_servicename( snum
);
2508 print_status_struct status
;
2511 ZERO_STRUCT( status
);
2513 /* make sure the database is up to date */
2514 if (print_cache_expired(lp_const_servicename(snum
), True
))
2515 print_queue_update(msg_ctx
, snum
, False
);
2517 /* also fetch the queue status */
2518 memset(&status
, 0, sizeof(status
));
2519 len
= get_queue_status(sharename
, &status
);
2527 /***************************************************************************
2528 Allocate a jobid. Hold the lock for as short a time as possible.
2529 ***************************************************************************/
2531 static WERROR
allocate_print_jobid(struct tdb_print_db
*pdb
, int snum
,
2532 const char *sharename
, uint32
*pjobid
)
2536 enum TDB_ERROR terr
;
2539 *pjobid
= (uint32
)-1;
2541 for (i
= 0; i
< 3; i
++) {
2542 /* Lock the database - only wait 20 seconds. */
2543 ret
= tdb_lock_bystring_with_timeout(pdb
->tdb
,
2544 "INFO/nextjob", 20);
2546 DEBUG(0, ("allocate_print_jobid: "
2547 "Failed to lock printing database %s\n",
2549 terr
= tdb_error(pdb
->tdb
);
2550 return ntstatus_to_werror(map_nt_error_from_tdb(terr
));
2553 if (!tdb_fetch_uint32(pdb
->tdb
, "INFO/nextjob", &jobid
)) {
2554 terr
= tdb_error(pdb
->tdb
);
2555 if (terr
!= TDB_ERR_NOEXIST
) {
2556 DEBUG(0, ("allocate_print_jobid: "
2557 "Failed to fetch INFO/nextjob "
2558 "for print queue %s\n", sharename
));
2559 tdb_unlock_bystring(pdb
->tdb
, "INFO/nextjob");
2560 return ntstatus_to_werror(map_nt_error_from_tdb(terr
));
2562 DEBUG(10, ("allocate_print_jobid: "
2563 "No existing jobid in %s\n", sharename
));
2567 DEBUG(10, ("allocate_print_jobid: "
2568 "Read jobid %u from %s\n", jobid
, sharename
));
2570 jobid
= NEXT_JOBID(jobid
);
2572 ret
= tdb_store_int32(pdb
->tdb
, "INFO/nextjob", jobid
);
2574 terr
= tdb_error(pdb
->tdb
);
2575 DEBUG(3, ("allocate_print_jobid: "
2576 "Failed to store INFO/nextjob.\n"));
2577 tdb_unlock_bystring(pdb
->tdb
, "INFO/nextjob");
2578 return ntstatus_to_werror(map_nt_error_from_tdb(terr
));
2581 /* We've finished with the INFO/nextjob lock. */
2582 tdb_unlock_bystring(pdb
->tdb
, "INFO/nextjob");
2584 if (!print_job_exists(sharename
, jobid
)) {
2587 DEBUG(10, ("allocate_print_jobid: "
2588 "Found jobid %u in %s\n", jobid
, sharename
));
2592 DEBUG(0, ("allocate_print_jobid: "
2593 "Failed to allocate a print job for queue %s\n",
2595 /* Probably full... */
2596 return WERR_NO_SPOOL_SPACE
;
2599 /* Store a dummy placeholder. */
2605 if (tdb_store(pdb
->tdb
, print_key(jobid
, &tmp
), dum
,
2607 DEBUG(3, ("allocate_print_jobid: "
2608 "jobid (%d) failed to store placeholder.\n",
2610 terr
= tdb_error(pdb
->tdb
);
2611 return ntstatus_to_werror(map_nt_error_from_tdb(terr
));
2619 /***************************************************************************
2620 Append a jobid to the 'jobs added' list.
2621 ***************************************************************************/
2623 static bool add_to_jobs_added(struct tdb_print_db
*pdb
, uint32 jobid
)
2628 SIVAL(&store_jobid
, 0, jobid
);
2629 data
.dptr
= (uint8
*)&store_jobid
;
2632 DEBUG(10,("add_to_jobs_added: Added jobid %u\n", (unsigned int)jobid
));
2634 return (tdb_append(pdb
->tdb
, string_tdb_data("INFO/jobs_added"),
2639 /***************************************************************************
2640 Do all checks needed to determine if we can start a job.
2641 ***************************************************************************/
2643 static WERROR
print_job_checks(const struct auth_session_info
*server_info
,
2644 struct messaging_context
*msg_ctx
,
2645 int snum
, int *njobs
)
2647 const char *sharename
= lp_const_servicename(snum
);
2648 uint64_t dspace
, dsize
;
2652 if (!print_access_check(server_info
, msg_ctx
, snum
,
2653 PRINTER_ACCESS_USE
)) {
2654 DEBUG(3, ("print_job_checks: "
2655 "job start denied by security descriptor\n"));
2656 return WERR_ACCESS_DENIED
;
2659 if (!print_time_access_check(server_info
, msg_ctx
, sharename
)) {
2660 DEBUG(3, ("print_job_checks: "
2661 "job start denied by time check\n"));
2662 return WERR_ACCESS_DENIED
;
2665 /* see if we have sufficient disk space */
2666 if (lp_minprintspace(snum
)) {
2667 minspace
= lp_minprintspace(snum
);
2668 ret
= sys_fsusage(lp_pathname(talloc_tos(), snum
), &dspace
, &dsize
);
2669 if (ret
== 0 && dspace
< 2*minspace
) {
2670 DEBUG(3, ("print_job_checks: "
2671 "disk space check failed.\n"));
2672 return WERR_NO_SPOOL_SPACE
;
2676 /* for autoloaded printers, check that the printcap entry still exists */
2677 if (lp_autoloaded(snum
) && !pcap_printername_ok(sharename
)) {
2678 DEBUG(3, ("print_job_checks: printer name %s check failed.\n",
2680 return WERR_ACCESS_DENIED
;
2683 /* Insure the maximum queue size is not violated */
2684 *njobs
= print_queue_length(msg_ctx
, snum
, NULL
);
2685 if (*njobs
> lp_maxprintjobs(snum
)) {
2686 DEBUG(3, ("print_job_checks: Queue %s number of jobs (%d) "
2687 "larger than max printjobs per queue (%d).\n",
2688 sharename
, *njobs
, lp_maxprintjobs(snum
)));
2689 return WERR_NO_SPOOL_SPACE
;
2695 /***************************************************************************
2697 ***************************************************************************/
2699 static WERROR
print_job_spool_file(int snum
, uint32_t jobid
,
2700 const char *output_file
,
2701 struct printjob
*pjob
)
2708 /* if this file is within the printer path, it means that smbd
2709 * is spooling it and will pass us control when it is finished.
2710 * Verify that the file name is ok, within path, and it is
2711 * already already there */
2713 path
= lp_pathname(talloc_tos(), snum
);
2715 if (strncmp(output_file
, path
, len
) == 0 &&
2716 (output_file
[len
- 1] == '/' || output_file
[len
] == '/')) {
2718 /* verify path is not too long */
2719 if (strlen(output_file
) >= sizeof(pjob
->filename
)) {
2720 return WERR_INVALID_NAME
;
2723 /* verify that the file exists */
2724 if (sys_stat(output_file
, &st
, false) != 0) {
2725 return WERR_INVALID_NAME
;
2728 fstrcpy(pjob
->filename
, output_file
);
2730 DEBUG(3, ("print_job_spool_file:"
2731 "External spooling activated"));
2733 /* we do not open the file until spooling is done */
2735 pjob
->status
= PJOB_SMBD_SPOOLING
;
2741 slprintf(pjob
->filename
, sizeof(pjob
->filename
)-1,
2742 "%s/%sXXXXXX", lp_pathname(talloc_tos(), snum
),
2743 PRINT_SPOOL_PREFIX
);
2744 pjob
->fd
= mkstemp(pjob
->filename
);
2746 if (pjob
->fd
== -1) {
2747 werr
= map_werror_from_unix(errno
);
2748 if (W_ERROR_EQUAL(werr
, WERR_ACCESS_DENIED
)) {
2749 /* Common setup error, force a report. */
2750 DEBUG(0, ("print_job_spool_file: "
2751 "insufficient permissions to open spool "
2752 "file %s.\n", pjob
->filename
));
2754 /* Normal case, report at level 3 and above. */
2755 DEBUG(3, ("print_job_spool_file: "
2756 "can't open spool file %s\n",
2765 /***************************************************************************
2766 Start spooling a job - return the jobid.
2767 ***************************************************************************/
2769 WERROR
print_job_start(const struct auth_session_info
*server_info
,
2770 struct messaging_context
*msg_ctx
,
2771 const char *clientmachine
,
2772 int snum
, const char *docname
, const char *filename
,
2773 struct spoolss_DeviceMode
*devmode
, uint32_t *_jobid
)
2777 struct printjob pjob
;
2778 const char *sharename
= lp_const_servicename(snum
);
2779 struct tdb_print_db
*pdb
= get_print_db_byname(sharename
);
2784 return WERR_INTERNAL_DB_CORRUPTION
;
2787 path
= lp_pathname(talloc_tos(), snum
);
2789 werr
= print_job_checks(server_info
, msg_ctx
, snum
, &njobs
);
2790 if (!W_ERROR_IS_OK(werr
)) {
2791 release_print_db(pdb
);
2795 DEBUG(10, ("print_job_start: "
2796 "Queue %s number of jobs (%d), max printjobs = %d\n",
2797 sharename
, njobs
, lp_maxprintjobs(snum
)));
2799 werr
= allocate_print_jobid(pdb
, snum
, sharename
, &jobid
);
2800 if (!W_ERROR_IS_OK(werr
)) {
2804 /* create the database entry */
2808 pjob
.pid
= getpid();
2812 pjob
.starttime
= time(NULL
);
2813 pjob
.status
= LPQ_SPOOLING
;
2815 pjob
.spooled
= False
;
2817 pjob
.devmode
= devmode
;
2819 fstrcpy(pjob
.jobname
, docname
);
2821 fstrcpy(pjob
.clientmachine
, clientmachine
);
2823 fstrcpy(pjob
.user
, lp_printjob_username(snum
));
2824 standard_sub_advanced(sharename
, server_info
->unix_info
->sanitized_username
,
2825 path
, server_info
->unix_token
->gid
,
2826 server_info
->unix_info
->sanitized_username
,
2827 server_info
->info
->domain_name
,
2828 pjob
.user
, sizeof(pjob
.user
));
2830 fstrcpy(pjob
.queuename
, lp_const_servicename(snum
));
2832 /* we have a job entry - now create the spool file */
2833 werr
= print_job_spool_file(snum
, jobid
, filename
, &pjob
);
2834 if (!W_ERROR_IS_OK(werr
)) {
2838 pjob_store(server_event_context(), msg_ctx
, sharename
, jobid
, &pjob
);
2840 /* Update the 'jobs added' entry used by print_queue_status. */
2841 add_to_jobs_added(pdb
, jobid
);
2843 /* Ensure we keep a rough count of the number of total jobs... */
2844 tdb_change_int32_atomic(pdb
->tdb
, "INFO/total_jobs", &njobs
, 1);
2846 release_print_db(pdb
);
2853 pjob_delete(server_event_context(), msg_ctx
, sharename
, jobid
);
2856 release_print_db(pdb
);
2858 DEBUG(3, ("print_job_start: returning fail. "
2859 "Error = %s\n", win_errstr(werr
)));
2863 /****************************************************************************
2864 Update the number of pages spooled to jobid
2865 ****************************************************************************/
2867 void print_job_endpage(struct messaging_context
*msg_ctx
,
2868 int snum
, uint32 jobid
)
2870 const char* sharename
= lp_const_servicename(snum
);
2871 struct printjob
*pjob
;
2872 TALLOC_CTX
*tmp_ctx
= talloc_new(msg_ctx
);
2873 if (tmp_ctx
== NULL
) {
2877 pjob
= print_job_find(tmp_ctx
, sharename
, jobid
);
2881 /* don't allow another process to get this info - it is meaningless */
2882 if (pjob
->pid
!= getpid()) {
2887 pjob_store(server_event_context(), msg_ctx
, sharename
, jobid
, pjob
);
2889 talloc_free(tmp_ctx
);
2892 /****************************************************************************
2893 Print a file - called on closing the file. This spools the job.
2894 If normal close is false then we're tearing down the jobs - treat as an
2896 ****************************************************************************/
2898 NTSTATUS
print_job_end(struct messaging_context
*msg_ctx
, int snum
,
2899 uint32 jobid
, enum file_close_type close_type
)
2901 const char* sharename
= lp_const_servicename(snum
);
2902 struct printjob
*pjob
;
2904 SMB_STRUCT_STAT sbuf
;
2905 struct printif
*current_printif
= get_printer_fns(snum
);
2906 NTSTATUS status
= NT_STATUS_UNSUCCESSFUL
;
2908 TALLOC_CTX
*tmp_ctx
= talloc_new(msg_ctx
);
2909 if (tmp_ctx
== NULL
) {
2910 return NT_STATUS_NO_MEMORY
;
2913 pjob
= print_job_find(tmp_ctx
, sharename
, jobid
);
2915 status
= NT_STATUS_PRINT_CANCELLED
;
2919 if (pjob
->spooled
|| pjob
->pid
!= getpid()) {
2920 status
= NT_STATUS_ACCESS_DENIED
;
2924 if (close_type
== NORMAL_CLOSE
|| close_type
== SHUTDOWN_CLOSE
) {
2925 if (pjob
->status
== PJOB_SMBD_SPOOLING
) {
2926 /* take over the file now, smbd is done */
2927 if (sys_stat(pjob
->filename
, &sbuf
, false) != 0) {
2928 status
= map_nt_error_from_unix(errno
);
2929 DEBUG(3, ("print_job_end: "
2930 "stat file failed for jobid %d\n",
2935 pjob
->status
= LPQ_SPOOLING
;
2939 if ((sys_fstat(pjob
->fd
, &sbuf
, false) != 0)) {
2940 status
= map_nt_error_from_unix(errno
);
2942 DEBUG(3, ("print_job_end: "
2943 "stat file failed for jobid %d\n",
2951 pjob
->size
= sbuf
.st_ex_size
;
2955 * Not a normal close, something has gone wrong. Cleanup.
2957 if (pjob
->fd
!= -1) {
2963 /* Technically, this is not quite right. If the printer has a separator
2964 * page turned on, the NT spooler prints the separator page even if the
2965 * print job is 0 bytes. 010215 JRR */
2966 if (pjob
->size
== 0 || pjob
->status
== LPQ_DELETING
) {
2967 /* don't bother spooling empty files or something being deleted. */
2968 DEBUG(5,("print_job_end: canceling spool of %s (%s)\n",
2969 pjob
->filename
, pjob
->size
? "deleted" : "zero length" ));
2970 unlink(pjob
->filename
);
2971 pjob_delete(server_event_context(), msg_ctx
, sharename
, jobid
);
2972 return NT_STATUS_OK
;
2975 /* don't strip out characters like '$' from the printername */
2976 lpq_cmd
= talloc_string_sub2(tmp_ctx
,
2977 lp_lpqcommand(talloc_tos(), snum
),
2979 lp_printername(talloc_tos(), snum
),
2980 false, false, false);
2981 if (lpq_cmd
== NULL
) {
2982 status
= NT_STATUS_PRINT_CANCELLED
;
2985 lpq_cmd
= talloc_sub_advanced(tmp_ctx
,
2986 lp_servicename(talloc_tos(), snum
),
2987 current_user_info
.unix_name
,
2989 current_user
.ut
.gid
,
2990 get_current_username(),
2991 current_user_info
.domain
,
2993 if (lpq_cmd
== NULL
) {
2994 status
= NT_STATUS_PRINT_CANCELLED
;
2998 ret
= (*(current_printif
->job_submit
))(snum
, pjob
,
2999 current_printif
->type
, lpq_cmd
);
3001 status
= NT_STATUS_PRINT_CANCELLED
;
3005 /* The print job has been successfully handed over to the back-end */
3007 pjob
->spooled
= True
;
3008 pjob
->status
= LPQ_QUEUED
;
3009 pjob_store(server_event_context(), msg_ctx
, sharename
, jobid
, pjob
);
3011 /* make sure the database is up to date */
3012 if (print_cache_expired(lp_const_servicename(snum
), True
))
3013 print_queue_update(msg_ctx
, snum
, False
);
3015 return NT_STATUS_OK
;
3019 /* The print job was not successfully started. Cleanup */
3020 /* Still need to add proper error return propagation! 010122:JRR */
3022 unlink(pjob
->filename
);
3023 pjob_delete(server_event_context(), msg_ctx
, sharename
, jobid
);
3025 talloc_free(tmp_ctx
);
3029 /****************************************************************************
3030 Get a snapshot of jobs in the system without traversing.
3031 ****************************************************************************/
3033 static bool get_stored_queue_info(struct messaging_context
*msg_ctx
,
3034 struct tdb_print_db
*pdb
, int snum
,
3035 int *pcount
, print_queue_struct
**ppqueue
)
3037 TDB_DATA data
, cgdata
, jcdata
;
3038 print_queue_struct
*queue
= NULL
;
3040 uint32 extra_count
= 0;
3041 uint32_t changed_count
= 0;
3042 int total_count
= 0;
3045 int max_reported_jobs
= lp_max_reported_jobs(snum
);
3047 const char* sharename
= lp_servicename(talloc_tos(), snum
);
3048 TALLOC_CTX
*tmp_ctx
= talloc_new(msg_ctx
);
3049 if (tmp_ctx
== NULL
) {
3053 /* make sure the database is up to date */
3054 if (print_cache_expired(lp_const_servicename(snum
), True
))
3055 print_queue_update(msg_ctx
, snum
, False
);
3061 ZERO_STRUCT(cgdata
);
3063 /* Get the stored queue data. */
3064 data
= tdb_fetch_compat(pdb
->tdb
, string_tdb_data("INFO/linear_queue_array"));
3066 if (data
.dptr
&& data
.dsize
>= sizeof(qcount
))
3067 len
+= tdb_unpack(data
.dptr
+ len
, data
.dsize
- len
, "d", &qcount
);
3069 /* Get the added jobs list. */
3070 cgdata
= tdb_fetch_compat(pdb
->tdb
, string_tdb_data("INFO/jobs_added"));
3071 if (cgdata
.dptr
!= NULL
&& (cgdata
.dsize
% 4 == 0))
3072 extra_count
= cgdata
.dsize
/4;
3074 /* Get the changed jobs list. */
3075 jcdata
= tdb_fetch_compat(pdb
->tdb
, string_tdb_data("INFO/jobs_changed"));
3076 if (jcdata
.dptr
!= NULL
&& (jcdata
.dsize
% 4 == 0))
3077 changed_count
= jcdata
.dsize
/ 4;
3079 DEBUG(5,("get_stored_queue_info: qcount = %u, extra_count = %u\n", (unsigned int)qcount
, (unsigned int)extra_count
));
3081 /* Allocate the queue size. */
3082 if (qcount
== 0 && extra_count
== 0)
3085 if ((queue
= SMB_MALLOC_ARRAY(print_queue_struct
, qcount
+ extra_count
)) == NULL
)
3088 /* Retrieve the linearised queue data. */
3090 for( i
= 0; i
< qcount
; i
++) {
3091 uint32 qjob
, qsize
, qpage_count
, qstatus
, qpriority
, qtime
;
3092 len
+= tdb_unpack(data
.dptr
+ len
, data
.dsize
- len
, "ddddddff",
3101 queue
[i
].sysjob
= qjob
;
3102 queue
[i
].size
= qsize
;
3103 queue
[i
].page_count
= qpage_count
;
3104 queue
[i
].status
= qstatus
;
3105 queue
[i
].priority
= qpriority
;
3106 queue
[i
].time
= qtime
;
3109 total_count
= qcount
;
3111 /* Add new jobids to the queue. */
3112 for( i
= 0; i
< extra_count
; i
++) {
3114 struct printjob
*pjob
;
3116 jobid
= IVAL(cgdata
.dptr
, i
*4);
3117 DEBUG(5,("get_stored_queue_info: added job = %u\n", (unsigned int)jobid
));
3118 pjob
= print_job_find(tmp_ctx
, lp_const_servicename(snum
), jobid
);
3120 DEBUG(5,("get_stored_queue_info: failed to find added job = %u\n", (unsigned int)jobid
));
3121 remove_from_jobs_added(sharename
, jobid
);
3125 queue
[total_count
].sysjob
= jobid
;
3126 queue
[total_count
].size
= pjob
->size
;
3127 queue
[total_count
].page_count
= pjob
->page_count
;
3128 queue
[total_count
].status
= pjob
->status
;
3129 queue
[total_count
].priority
= 1;
3130 queue
[total_count
].time
= pjob
->starttime
;
3131 fstrcpy(queue
[total_count
].fs_user
, pjob
->user
);
3132 fstrcpy(queue
[total_count
].fs_file
, pjob
->jobname
);
3137 /* Update the changed jobids. */
3138 for (i
= 0; i
< changed_count
; i
++) {
3139 uint32_t jobid
= IVAL(jcdata
.dptr
, i
* 4);
3143 for (j
= 0; j
< total_count
; j
++) {
3144 if (queue
[j
].sysjob
== jobid
) {
3151 struct printjob
*pjob
;
3153 DEBUG(5,("get_stored_queue_info: changed job: %u\n",
3154 (unsigned int) jobid
));
3156 pjob
= print_job_find(tmp_ctx
, sharename
, jobid
);
3158 DEBUG(5,("get_stored_queue_info: failed to find "
3159 "changed job = %u\n",
3160 (unsigned int) jobid
));
3161 remove_from_jobs_changed(sharename
, jobid
);
3165 queue
[j
].sysjob
= jobid
;
3166 queue
[j
].size
= pjob
->size
;
3167 queue
[j
].page_count
= pjob
->page_count
;
3168 queue
[j
].status
= pjob
->status
;
3169 queue
[j
].priority
= 1;
3170 queue
[j
].time
= pjob
->starttime
;
3171 fstrcpy(queue
[j
].fs_user
, pjob
->user
);
3172 fstrcpy(queue
[j
].fs_file
, pjob
->jobname
);
3175 DEBUG(5,("get_stored_queue_info: updated queue[%u], jobid: %u, jobname: %s\n",
3176 (unsigned int) j
, (unsigned int) jobid
, pjob
->jobname
));
3179 remove_from_jobs_changed(sharename
, jobid
);
3182 /* Sort the queue by submission time otherwise they are displayed
3185 TYPESAFE_QSORT(queue
, total_count
, printjob_comp
);
3187 DEBUG(5,("get_stored_queue_info: total_count = %u\n", (unsigned int)total_count
));
3189 if (max_reported_jobs
&& total_count
> max_reported_jobs
)
3190 total_count
= max_reported_jobs
;
3193 *pcount
= total_count
;
3199 SAFE_FREE(data
.dptr
);
3200 SAFE_FREE(cgdata
.dptr
);
3201 talloc_free(tmp_ctx
);
3205 /****************************************************************************
3206 Get a printer queue listing.
3207 set queue = NULL and status = NULL if you just want to update the cache
3208 ****************************************************************************/
3210 int print_queue_status(struct messaging_context
*msg_ctx
, int snum
,
3211 print_queue_struct
**ppqueue
,
3212 print_status_struct
*status
)
3216 const char *sharename
;
3217 struct tdb_print_db
*pdb
;
3220 /* make sure the database is up to date */
3222 if (print_cache_expired(lp_const_servicename(snum
), True
))
3223 print_queue_update(msg_ctx
, snum
, False
);
3225 /* return if we are done */
3226 if ( !ppqueue
|| !status
)
3230 sharename
= lp_const_servicename(snum
);
3231 pdb
= get_print_db_byname(sharename
);
3237 * Fetch the queue status. We must do this first, as there may
3238 * be no jobs in the queue.
3241 ZERO_STRUCTP(status
);
3242 slprintf(keystr
, sizeof(keystr
)-1, "STATUS/%s", sharename
);
3243 key
= string_tdb_data(keystr
);
3245 data
= tdb_fetch_compat(pdb
->tdb
, key
);
3247 if (data
.dsize
== sizeof(*status
)) {
3248 /* this memcpy is ok since the status struct was
3249 not packed before storing it in the tdb */
3250 memcpy(status
, data
.dptr
, sizeof(*status
));
3252 SAFE_FREE(data
.dptr
);
3256 * Now, fetch the print queue information. We first count the number
3257 * of entries, and then only retrieve the queue if necessary.
3260 if (!get_stored_queue_info(msg_ctx
, pdb
, snum
, &count
, ppqueue
)) {
3261 release_print_db(pdb
);
3265 release_print_db(pdb
);
3269 /****************************************************************************
3271 ****************************************************************************/
3273 WERROR
print_queue_pause(const struct auth_session_info
*server_info
,
3274 struct messaging_context
*msg_ctx
, int snum
)
3277 struct printif
*current_printif
= get_printer_fns( snum
);
3279 if (!print_access_check(server_info
, msg_ctx
, snum
,
3280 PRINTER_ACCESS_ADMINISTER
)) {
3281 return WERR_ACCESS_DENIED
;
3287 ret
= (*(current_printif
->queue_pause
))(snum
);
3292 return WERR_INVALID_PARAM
;
3295 /* force update the database */
3296 print_cache_flush(lp_const_servicename(snum
));
3298 /* Send a printer notify message */
3300 notify_printer_status(server_event_context(), msg_ctx
, snum
,
3301 PRINTER_STATUS_PAUSED
);
3306 /****************************************************************************
3308 ****************************************************************************/
3310 WERROR
print_queue_resume(const struct auth_session_info
*server_info
,
3311 struct messaging_context
*msg_ctx
, int snum
)
3314 struct printif
*current_printif
= get_printer_fns( snum
);
3316 if (!print_access_check(server_info
, msg_ctx
, snum
,
3317 PRINTER_ACCESS_ADMINISTER
)) {
3318 return WERR_ACCESS_DENIED
;
3323 ret
= (*(current_printif
->queue_resume
))(snum
);
3328 return WERR_INVALID_PARAM
;
3331 /* make sure the database is up to date */
3332 if (print_cache_expired(lp_const_servicename(snum
), True
))
3333 print_queue_update(msg_ctx
, snum
, True
);
3335 /* Send a printer notify message */
3337 notify_printer_status(server_event_context(), msg_ctx
, snum
,
3343 /****************************************************************************
3344 Purge a queue - implemented by deleting all jobs that we can delete.
3345 ****************************************************************************/
3347 WERROR
print_queue_purge(const struct auth_session_info
*server_info
,
3348 struct messaging_context
*msg_ctx
, int snum
)
3350 print_queue_struct
*queue
;
3351 print_status_struct status
;
3355 /* Force and update so the count is accurate (i.e. not a cached count) */
3356 print_queue_update(msg_ctx
, snum
, True
);
3358 can_job_admin
= print_access_check(server_info
,
3361 JOB_ACCESS_ADMINISTER
);
3362 njobs
= print_queue_status(msg_ctx
, snum
, &queue
, &status
);
3364 if ( can_job_admin
)
3367 for (i
=0;i
<njobs
;i
++) {
3368 bool owner
= is_owner(server_info
, lp_const_servicename(snum
),
3371 if (owner
|| can_job_admin
) {
3372 print_job_delete1(server_event_context(), msg_ctx
,
3373 snum
, queue
[i
].sysjob
);
3377 if ( can_job_admin
)
3380 /* update the cache */
3381 print_queue_update(msg_ctx
, snum
, True
);