1996-05-04 11:50:46 +04:00
/*
2002-01-30 09:08:46 +03:00
Unix SMB / CIFS implementation .
2000-04-16 10:20:02 +04:00
printing backend routines
Copyright ( C ) Andrew Tridgell 1992 - 2000
1996-05-04 11:50:46 +04:00
This program is free software ; you can redistribute it and / or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation ; either version 2 of the License , or
( at your option ) any later version .
This program is distributed in the hope that it will be useful ,
but WITHOUT ANY WARRANTY ; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE . See the
GNU General Public License for more details .
You should have received a copy of the GNU General Public License
along with this program ; if not , write to the Free Software
Foundation , Inc . , 675 Mass Ave , Cambridge , MA 0213 9 , USA .
*/
2001-03-16 08:55:30 +03:00
# include "printing.h"
2000-11-08 02:05:53 +03:00
2001-03-16 08:55:30 +03:00
/* Current printer interface */
struct printif * current_printif = & generic_printif ;
2000-04-16 10:20:02 +04:00
/*
the printing backend revolves around a tdb database that stores the
SMB view of the print queue
The key for this database is a jobid - a internally generated number that
uniquely identifies a print job
1996-05-04 11:50:46 +04:00
2000-04-16 10:20:02 +04:00
reading the print queue involves two steps :
- possibly running lpq and updating the internal database from that
- reading entries from the database
jobids are assigned when a job starts spooling .
*/
/* the open printing.tdb database */
static TDB_CONTEXT * tdb ;
static pid_t local_pid ;
2000-11-21 03:30:15 +03:00
static int get_queue_status ( int , print_status_struct * ) ;
2000-04-16 10:20:02 +04:00
/****************************************************************************
2002-01-09 07:13:30 +03:00
Initialise the printing backend . Called once at startup .
Does not survive a fork
2000-04-16 10:20:02 +04:00
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
2002-01-09 07:13:30 +03:00
2000-04-16 10:20:02 +04:00
BOOL print_backend_init ( void )
{
2000-10-10 10:45:09 +04:00
char * sversion = " INFO/version " ;
2000-05-02 06:23:41 +04:00
if ( tdb & & local_pid = = sys_getpid ( ) ) return True ;
2001-09-07 02:08:19 +04:00
tdb = tdb_open_log ( lock_path ( " printing.tdb " ) , 0 , TDB_DEFAULT , O_RDWR | O_CREAT , 0600 ) ;
2000-04-16 10:20:02 +04:00
if ( ! tdb ) {
2002-04-22 22:48:45 +04:00
DEBUG ( 0 , ( " print_backend_init: Failed to open printing backend database %s \n " ,
lock_path ( " printing.tdb " ) ) ) ;
2001-02-15 22:33:57 +03:00
return False ;
2000-04-16 10:20:02 +04:00
}
2000-05-02 06:23:41 +04:00
local_pid = sys_getpid ( ) ;
2000-04-16 10:20:02 +04:00
/* handle a Samba upgrade */
2000-10-10 10:45:09 +04:00
tdb_lock_bystring ( tdb , sversion ) ;
2002-01-09 07:13:30 +03:00
if ( tdb_fetch_int32 ( tdb , sversion ) ! = PRINT_DATABASE_VERSION ) {
2002-01-04 01:48:48 +03:00
tdb_traverse ( tdb , tdb_traverse_delete_fn , NULL ) ;
2002-01-09 07:13:30 +03:00
tdb_store_int32 ( tdb , sversion , PRINT_DATABASE_VERSION ) ;
2000-04-16 10:20:02 +04:00
}
2000-10-10 10:45:09 +04:00
tdb_unlock_bystring ( tdb , sversion ) ;
2000-04-16 10:20:02 +04:00
2001-03-16 08:55:30 +03:00
/* select the appropriate printing interface... */
2001-08-23 23:06:20 +04:00
# ifdef HAVE_CUPS
2001-03-16 08:55:30 +03:00
if ( strcmp ( lp_printcapname ( ) , " cups " ) = = 0 )
current_printif = & cups_printif ;
2001-08-23 23:06:20 +04:00
# endif /* HAVE_CUPS */
2001-03-16 08:55:30 +03:00
/* do NT print initialization... */
2000-05-24 10:10:21 +04:00
return nt_printing_init ( ) ;
1996-05-04 11:50:46 +04:00
}
2000-04-16 10:20:02 +04:00
/****************************************************************************
useful function to generate a tdb key
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
static TDB_DATA print_key ( int jobid )
1996-05-04 11:50:46 +04:00
{
2000-04-16 10:20:02 +04:00
static int j ;
TDB_DATA ret ;
j = jobid ;
ret . dptr = ( void * ) & j ;
ret . dsize = sizeof ( j ) ;
return ret ;
1996-05-04 11:50:46 +04:00
}
2000-04-16 10:20:02 +04:00
/****************************************************************************
useful function to find a print job in the database
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
static struct printjob * print_job_find ( int jobid )
{
static struct printjob pjob ;
TDB_DATA ret ;
ret = tdb_fetch ( tdb , print_key ( jobid ) ) ;
if ( ! ret . dptr | | ret . dsize ! = sizeof ( pjob ) ) return NULL ;
memcpy ( & pjob , ret . dptr , sizeof ( pjob ) ) ;
free ( ret . dptr ) ;
return & pjob ;
}
1996-05-04 11:50:46 +04:00
/****************************************************************************
2000-04-16 10:20:02 +04:00
store a job structure back to the database
1996-05-04 11:50:46 +04:00
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
2000-04-16 10:20:02 +04:00
static BOOL print_job_store ( int jobid , struct printjob * pjob )
1996-05-04 11:50:46 +04:00
{
2000-04-16 10:20:02 +04:00
TDB_DATA d ;
2002-03-21 01:39:30 +03:00
BOOL ret ;
2000-04-16 10:20:02 +04:00
d . dptr = ( void * ) pjob ;
d . dsize = sizeof ( * pjob ) ;
2002-03-21 01:39:30 +03:00
ret = ( tdb_store ( tdb , print_key ( jobid ) , d , TDB_REPLACE ) = = 0 ) ;
return ret ;
2000-04-16 10:20:02 +04:00
}
1996-05-04 11:50:46 +04:00
/****************************************************************************
2000-04-16 10:20:02 +04:00
parse a file name from the system spooler to generate a jobid
1996-05-04 11:50:46 +04:00
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
2000-04-16 10:20:02 +04:00
static int print_parse_jobid ( char * fname )
1996-05-04 11:50:46 +04:00
{
2000-04-16 10:20:02 +04:00
int jobid ;
1996-05-04 11:50:46 +04:00
2000-04-16 10:20:02 +04:00
if ( strncmp ( fname , PRINT_SPOOL_PREFIX , strlen ( PRINT_SPOOL_PREFIX ) ) ! = 0 ) return - 1 ;
fname + = strlen ( PRINT_SPOOL_PREFIX ) ;
1996-05-04 11:50:46 +04:00
2000-04-16 10:20:02 +04:00
jobid = atoi ( fname ) ;
if ( jobid < = 0 ) return - 1 ;
1996-05-04 11:50:46 +04:00
2000-04-16 10:20:02 +04:00
return jobid ;
1996-05-04 11:50:46 +04:00
}
/****************************************************************************
2000-04-16 10:20:02 +04:00
list a unix job in the print database
1996-05-04 11:50:46 +04:00
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
2000-04-16 10:20:02 +04:00
static void print_unix_job ( int snum , print_queue_struct * q )
1996-05-04 11:50:46 +04:00
{
2000-04-16 10:20:02 +04:00
int jobid = q - > job + UNIX_JOB_START ;
2000-11-08 02:05:53 +03:00
struct printjob pj , * old_pj ;
2000-04-16 10:20:02 +04:00
2000-11-08 02:05:53 +03:00
/* Preserve the timestamp on an existing unix print job */
2000-11-04 22:48:53 +03:00
2000-11-08 02:05:53 +03:00
old_pj = print_job_find ( jobid ) ;
2000-11-04 22:48:53 +03:00
2000-04-16 10:20:02 +04:00
ZERO_STRUCT ( pj ) ;
pj . pid = ( pid_t ) - 1 ;
pj . sysjob = q - > job ;
pj . fd = - 1 ;
2000-11-08 02:05:53 +03:00
pj . starttime = old_pj ? old_pj - > starttime : q - > time ;
2000-04-16 10:20:02 +04:00
pj . status = q - > status ;
pj . size = q - > size ;
pj . spooled = True ;
pj . smbjob = False ;
fstrcpy ( pj . filename , " " ) ;
2002-03-15 11:14:10 +03:00
fstrcpy ( pj . jobname , q - > fs_file ) ;
fstrcpy ( pj . user , q - > fs_user ) ;
2002-03-21 00:55:57 +03:00
fstrcpy ( pj . queuename , lp_servicename ( snum ) ) ;
2000-04-16 10:20:02 +04:00
print_job_store ( jobid , & pj ) ;
}
1996-05-04 11:50:46 +04:00
2000-04-16 10:20:02 +04:00
struct traverse_struct {
print_queue_struct * queue ;
2001-01-23 23:25:25 +03:00
int qcount , snum , maxcount , total_jobs ;
2000-04-16 10:20:02 +04:00
} ;
2000-04-16 12:03:37 +04:00
/* utility fn to delete any jobs that are no longer active */
2000-04-16 10:20:02 +04:00
static int traverse_fn_delete ( TDB_CONTEXT * t , TDB_DATA key , TDB_DATA data , void * state )
{
struct traverse_struct * ts = ( struct traverse_struct * ) state ;
struct printjob pjob ;
int i , jobid ;
if ( data . dsize ! = sizeof ( pjob ) | | key . dsize ! = sizeof ( int ) ) return 0 ;
memcpy ( & jobid , key . dptr , sizeof ( jobid ) ) ;
memcpy ( & pjob , data . dptr , sizeof ( pjob ) ) ;
1996-05-04 11:50:46 +04:00
2002-03-21 01:39:30 +03:00
if ( ts - > snum ! = lp_servicenumber ( pjob . queuename ) ) {
2000-04-16 10:20:02 +04:00
/* this isn't for the queue we are looking at */
2001-01-23 23:25:25 +03:00
ts - > total_jobs + + ;
2000-04-16 10:20:02 +04:00
return 0 ;
1998-08-14 21:38:29 +04:00
}
1996-05-04 11:50:46 +04:00
2000-04-16 10:20:02 +04:00
if ( ! pjob . smbjob ) {
2001-01-23 23:25:25 +03:00
/* remove a unix job if it isn't in the system queue any more */
2000-11-08 02:05:53 +03:00
2000-04-16 10:20:02 +04:00
for ( i = 0 ; i < ts - > qcount ; i + + ) {
if ( jobid = = ts - > queue [ i ] . job + UNIX_JOB_START ) break ;
}
2001-01-23 23:25:25 +03:00
if ( i = = ts - > qcount )
tdb_delete ( tdb , key ) ;
else
ts - > total_jobs + + ;
2000-04-16 10:20:02 +04:00
return 0 ;
}
1996-05-04 11:50:46 +04:00
2000-04-16 10:20:02 +04:00
/* maybe it hasn't been spooled yet */
if ( ! pjob . spooled ) {
/* if a job is not spooled and the process doesn't
exist then kill it . This cleans up after smbd
deaths */
2001-01-23 23:25:25 +03:00
if ( ! process_exists ( pjob . pid ) )
2000-04-16 10:20:02 +04:00
tdb_delete ( tdb , key ) ;
2001-01-23 23:25:25 +03:00
else
ts - > total_jobs + + ;
2000-04-16 10:20:02 +04:00
return 0 ;
1996-05-04 11:50:46 +04:00
}
2000-04-16 10:20:02 +04:00
for ( i = 0 ; i < ts - > qcount ; i + + ) {
2002-03-15 11:14:10 +03:00
int qid = print_parse_jobid ( ts - > queue [ i ] . fs_file ) ;
2000-04-16 10:20:02 +04:00
if ( jobid = = qid ) break ;
1998-08-14 21:38:29 +04:00
}
2000-11-15 04:11:38 +03:00
/* The job isn't in the system queue - we have to assume it has
completed , so delete the database entry . */
2000-04-16 10:20:02 +04:00
if ( i = = ts - > qcount ) {
2000-11-15 04:11:38 +03:00
time_t cur_t = time ( NULL ) ;
/* A race can occur between the time a job is spooled and
when it appears in the lpq output . This happens when
the job is added to printing . tdb when another smbd
running print_queue_update ( ) has completed a lpq and
is currently traversing the printing tdb and deleting jobs .
A workaround is to not delete the job if it has been
submitted less than lp_lpqcachetime ( ) seconds ago . */
2001-01-23 23:25:25 +03:00
if ( ( cur_t - pjob . starttime ) > lp_lpqcachetime ( ) )
2000-11-15 04:11:38 +03:00
tdb_delete ( t , key ) ;
2001-01-23 23:25:25 +03:00
else
ts - > total_jobs + + ;
2000-04-16 10:20:02 +04:00
}
2001-01-23 23:25:25 +03:00
else
ts - > total_jobs + + ;
2000-04-16 10:20:02 +04:00
return 0 ;
}
/****************************************************************************
check if the print queue has been updated recently enough
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
static void print_cache_flush ( int snum )
{
fstring key ;
2001-04-09 00:22:39 +04:00
slprintf ( key , sizeof ( key ) - 1 , " CACHE/%s " , lp_servicename ( snum ) ) ;
2002-01-09 07:13:30 +03:00
tdb_store_int32 ( tdb , key , - 1 ) ;
2000-04-16 10:20:02 +04:00
}
2001-02-22 20:39:36 +03:00
/****************************************************************************
Check if someone already thinks they are doing the update .
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
static pid_t get_updating_pid ( fstring printer_name )
{
fstring keystr ;
TDB_DATA data , key ;
pid_t updating_pid ;
2001-04-09 00:22:39 +04:00
slprintf ( keystr , sizeof ( keystr ) - 1 , " UPDATING/%s " , printer_name ) ;
2001-02-22 20:39:36 +03:00
key . dptr = keystr ;
key . dsize = strlen ( keystr ) ;
data = tdb_fetch ( tdb , key ) ;
if ( ! data . dptr | | data . dsize ! = sizeof ( pid_t ) )
return ( pid_t ) - 1 ;
memcpy ( & updating_pid , data . dptr , sizeof ( pid_t ) ) ;
free ( data . dptr ) ;
if ( process_exists ( updating_pid ) )
return updating_pid ;
return ( pid_t ) - 1 ;
}
/****************************************************************************
Set the fact that we ' re doing the update , or have finished doing the update
in th tdb .
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
static void set_updating_pid ( fstring printer_name , BOOL delete )
{
fstring keystr ;
TDB_DATA key ;
TDB_DATA data ;
2002-03-14 04:53:04 +03:00
pid_t updating_pid = sys_getpid ( ) ;
2001-02-22 20:39:36 +03:00
2001-04-09 00:22:39 +04:00
slprintf ( keystr , sizeof ( keystr ) - 1 , " UPDATING/%s " , printer_name ) ;
2001-02-22 20:39:36 +03:00
key . dptr = keystr ;
key . dsize = strlen ( keystr ) ;
if ( delete ) {
tdb_delete ( tdb , key ) ;
return ;
}
data . dptr = ( void * ) & updating_pid ;
data . dsize = sizeof ( pid_t ) ;
tdb_store ( tdb , key , data , TDB_REPLACE ) ;
}
2002-02-26 06:12:09 +03:00
/****************************************************************************
Send a message saying the queue changed .
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
static void send_queue_message ( const char * printer_name , uint32 high , uint32 low )
{
char msg [ 8 + sizeof ( fstring ) ] ;
SIVAL ( msg , 0 , low ) ;
SIVAL ( msg , 4 , high ) ;
fstrcpy ( & msg [ 8 ] , printer_name ) ;
message_send_all ( conn_tdb_ctx ( ) , MSG_PRINTER_NOTIFY , msg , 8 + strlen ( printer_name ) + 1 , False , NULL ) ;
}
2000-04-16 10:20:02 +04:00
/****************************************************************************
2001-10-17 03:16:00 +04:00
update the internal database from the system print queue for a queue in the background
2000-04-16 10:20:02 +04:00
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
2001-02-22 20:39:36 +03:00
2001-10-17 03:16:00 +04:00
static void print_queue_update_background ( int snum )
2000-04-16 10:20:02 +04:00
{
2001-03-16 08:55:30 +03:00
int i , qcount ;
2000-04-16 10:20:02 +04:00
print_queue_struct * queue = NULL ;
print_status_struct status ;
2000-11-21 03:30:15 +03:00
print_status_struct old_status ;
2000-04-16 10:20:02 +04:00
struct printjob * pjob ;
struct traverse_struct tstruct ;
2001-02-22 20:39:36 +03:00
fstring keystr , printer_name , cachestr ;
2000-04-16 10:20:02 +04:00
TDB_DATA data , key ;
2001-02-22 20:39:36 +03:00
2000-11-15 00:56:32 +03:00
fstrcpy ( printer_name , lp_servicename ( snum ) ) ;
2000-10-11 01:52:31 +04:00
/*
2001-02-22 20:39:36 +03:00
* Check to see if someone else is doing this update .
* This is essentially a mutex on the update .
2000-10-11 01:52:31 +04:00
*/
2001-02-23 06:59:37 +03:00
if ( get_updating_pid ( printer_name ) ! = - 1 )
return ;
2001-02-22 20:39:36 +03:00
2001-02-23 06:59:37 +03:00
/* Lock the queue for the database update */
2001-02-22 20:39:36 +03:00
2001-02-23 06:59:37 +03:00
slprintf ( keystr , sizeof ( keystr ) - 1 , " LOCK/%s " , printer_name ) ;
tdb_lock_bystring ( tdb , keystr ) ;
2001-02-22 20:39:36 +03:00
2001-02-23 06:59:37 +03:00
/*
* Ensure that no one else got in here .
* If the updating pid is still - 1 then we are
* the winner .
*/
2001-02-22 20:39:36 +03:00
2001-02-23 06:59:37 +03:00
if ( get_updating_pid ( printer_name ) ! = - 1 ) {
2001-02-22 20:39:36 +03:00
/*
2001-02-23 06:59:37 +03:00
* Someone else is doing the update , exit .
2001-02-22 20:39:36 +03:00
*/
2001-02-23 06:59:37 +03:00
tdb_unlock_bystring ( tdb , keystr ) ;
return ;
}
2001-02-22 20:39:36 +03:00
2001-02-23 06:59:37 +03:00
/*
* We ' re going to do the update ourselves .
*/
2001-02-22 20:39:36 +03:00
2001-02-23 06:59:37 +03:00
/* Tell others we're doing the update. */
set_updating_pid ( printer_name , False ) ;
2001-02-22 20:39:36 +03:00
2001-02-23 06:59:37 +03:00
/*
* Allow others to enter and notice we ' re doing
* the update .
*/
2001-02-22 20:39:36 +03:00
2001-02-23 06:59:37 +03:00
tdb_unlock_bystring ( tdb , keystr ) ;
2001-02-22 20:39:36 +03:00
2001-02-23 06:59:37 +03:00
/*
* Update the cache time FIRST ! Stops others even
* attempting to get the lock and doing this
* if the lpq takes a long time .
*/
2001-02-22 20:39:36 +03:00
2001-04-09 00:22:39 +04:00
slprintf ( cachestr , sizeof ( cachestr ) - 1 , " CACHE/%s " , printer_name ) ;
2002-01-09 07:13:30 +03:00
tdb_store_int32 ( tdb , cachestr , ( int ) time ( NULL ) ) ;
2000-10-11 01:52:31 +04:00
2001-03-16 08:55:30 +03:00
/* get the current queue using the appropriate interface */
2000-04-16 10:20:02 +04:00
ZERO_STRUCT ( status ) ;
2001-03-16 08:55:30 +03:00
2001-04-18 09:12:46 +04:00
qcount = ( * ( current_printif - > queue_get ) ) ( snum , & queue , & status ) ;
2000-04-16 10:20:02 +04:00
2000-11-11 01:05:08 +03:00
DEBUG ( 3 , ( " %d job%s in queue for %s \n " , qcount , ( qcount ! = 1 ) ?
2000-11-15 00:56:32 +03:00
" s " : " " , printer_name ) ) ;
2000-11-11 01:05:08 +03:00
2000-04-16 10:20:02 +04:00
/*
any job in the internal database that is marked as spooled
and doesn ' t exist in the system queue is considered finished
and removed from the database
any job in the system database but not in the internal database
is added as a unix job
fill in any system job numbers as we go
*/
for ( i = 0 ; i < qcount ; i + + ) {
2002-03-15 11:14:10 +03:00
int jobid = print_parse_jobid ( queue [ i ] . fs_file ) ;
2000-04-16 10:20:02 +04:00
if ( jobid = = - 1 ) {
/* assume its a unix print job */
print_unix_job ( snum , & queue [ i ] ) ;
continue ;
}
1998-08-14 21:38:29 +04:00
2000-04-16 10:20:02 +04:00
/* we have an active SMB print job - update its status */
pjob = print_job_find ( jobid ) ;
if ( ! pjob ) {
/* err, somethings wrong. Probably smbd was restarted
with jobs in the queue . All we can do is treat them
like unix jobs . Pity . */
print_unix_job ( snum , & queue [ i ] ) ;
1998-08-14 21:38:29 +04:00
continue ;
2000-04-16 10:20:02 +04:00
}
1998-08-14 21:38:29 +04:00
2000-04-16 10:20:02 +04:00
pjob - > sysjob = queue [ i ] . job ;
pjob - > status = queue [ i ] . status ;
print_job_store ( jobid , pjob ) ;
1998-08-14 21:38:29 +04:00
}
2000-04-16 10:20:02 +04:00
/* now delete any queued entries that don't appear in the
system queue */
tstruct . queue = queue ;
tstruct . qcount = qcount ;
tstruct . snum = snum ;
2001-01-23 23:25:25 +03:00
tstruct . total_jobs = 0 ;
2000-04-16 10:20:02 +04:00
tdb_traverse ( tdb , traverse_fn_delete , ( void * ) & tstruct ) ;
safe_free ( tstruct . queue ) ;
2002-01-09 07:13:30 +03:00
tdb_store_int32 ( tdb , " INFO/total_jobs " , tstruct . total_jobs ) ;
2001-01-23 23:25:25 +03:00
2000-11-21 03:30:15 +03:00
/*
* Get the old print status . We will use this to compare the
* number of jobs . If they have changed we need to send a
* " changed " message to the smbds .
*/
if ( qcount ! = get_queue_status ( snum , & old_status ) ) {
DEBUG ( 10 , ( " print_queue_update: queue status change %d jobs -> %d jobs for printer %s \n " ,
old_status . qcount , qcount , printer_name ) ) ;
2002-02-26 06:12:09 +03:00
send_queue_message ( printer_name , 0 , PRINTER_CHANGE_JOB ) ;
2000-11-21 03:30:15 +03:00
}
/* store the new queue status structure */
2001-04-09 00:22:39 +04:00
slprintf ( keystr , sizeof ( keystr ) - 1 , " STATUS/%s " , printer_name ) ;
2001-02-22 20:39:36 +03:00
key . dptr = keystr ;
2000-04-16 10:20:02 +04:00
key . dsize = strlen ( keystr ) ;
2000-11-21 03:30:15 +03:00
status . qcount = qcount ;
data . dptr = ( void * ) & status ;
data . dsize = sizeof ( status ) ;
2000-04-16 10:20:02 +04:00
tdb_store ( tdb , key , data , TDB_REPLACE ) ;
2000-10-11 01:52:31 +04:00
/*
* Update the cache time again . We want to do this call
* as little as possible . . .
*/
2001-04-09 00:22:39 +04:00
slprintf ( keystr , sizeof ( keystr ) - 1 , " CACHE/%s " , printer_name ) ;
2002-01-09 07:13:30 +03:00
tdb_store_int32 ( tdb , keystr , ( int ) time ( NULL ) ) ;
2001-02-22 20:39:36 +03:00
/* Delete our pid from the db. */
set_updating_pid ( printer_name , True ) ;
2000-04-16 10:20:02 +04:00
}
2001-10-17 03:16:00 +04:00
/****************************************************************************
this is the receive function of the background lpq updater
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
static void print_queue_receive ( int msg_type , pid_t src , void * buf , size_t len )
{
int snum ;
snum = * ( ( int * ) buf ) ;
print_queue_update_background ( snum ) ;
}
2001-10-17 03:52:14 +04:00
static pid_t background_lpq_updater_pid ;
2001-10-17 03:16:00 +04:00
/****************************************************************************
main thread of the background lpq updater
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
void start_background_queue ( void )
{
2001-10-17 03:52:14 +04:00
DEBUG ( 3 , ( " start_background_queue: Starting background LPQ thread \n " ) ) ;
background_lpq_updater_pid = sys_fork ( ) ;
if ( background_lpq_updater_pid = = - 1 ) {
DEBUG ( 5 , ( " start_background_queue: background LPQ thread failed to start. %s \n " , strerror ( errno ) ) ) ;
exit ( 1 ) ;
}
if ( background_lpq_updater_pid = = 0 ) {
/* Child. */
DEBUG ( 5 , ( " start_background_queue: background LPQ thread started \n " ) ) ;
2001-10-17 03:16:00 +04:00
2002-01-14 22:34:28 +03:00
claim_connection ( NULL , " smbd lpq backend " , 0 , False ) ;
2001-10-17 03:16:00 +04:00
2002-01-14 22:34:28 +03:00
if ( ! locking_init ( 0 ) )
2001-10-17 03:16:00 +04:00
exit ( 1 ) ;
2002-01-14 22:34:28 +03:00
if ( ! print_backend_init ( ) )
2001-10-17 03:16:00 +04:00
exit ( 1 ) ;
message_register ( MSG_PRINTER_UPDATE , print_queue_receive ) ;
2001-10-17 03:52:14 +04:00
DEBUG ( 5 , ( " start_background_queue: background LPQ thread waiting for messages \n " ) ) ;
2001-10-17 03:16:00 +04:00
while ( 1 ) {
pause ( ) ;
2001-10-17 03:52:14 +04:00
DEBUG ( 10 , ( " start_background_queue: background LPQ thread got a message \n " ) ) ;
2001-10-17 03:16:00 +04:00
message_dispatch ( ) ;
}
}
}
/****************************************************************************
update the internal database from the system print queue for a queue
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
static void print_queue_update ( int snum )
{
2002-04-22 22:48:45 +04:00
if ( background_lpq_updater_pid > 0 ) {
message_send_pid ( background_lpq_updater_pid , MSG_PRINTER_UPDATE ,
& snum , sizeof ( snum ) , False ) ;
}
2001-10-17 03:16:00 +04:00
}
2000-04-16 10:20:02 +04:00
/****************************************************************************
check if a jobid is valid . It is valid if it exists in the database
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
BOOL print_job_exists ( int jobid )
{
return tdb_exists ( tdb , print_key ( jobid ) ) ;
1996-05-04 11:50:46 +04:00
}
/****************************************************************************
2000-04-16 10:20:02 +04:00
work out which service a jobid is for
note that we have to look up by queue name to ensure that it works for
other than the process that started the job
1996-05-04 11:50:46 +04:00
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
2000-04-16 10:20:02 +04:00
int print_job_snum ( int jobid )
{
struct printjob * pjob = print_job_find ( jobid ) ;
if ( ! pjob ) return - 1 ;
2002-03-21 00:55:57 +03:00
return find_service ( pjob - > queuename ) ;
1996-05-04 11:50:46 +04:00
}
/****************************************************************************
2000-04-16 10:20:02 +04:00
give the fd used for a jobid
1996-05-04 11:50:46 +04:00
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
2000-04-16 10:20:02 +04:00
int print_job_fd ( int jobid )
{
struct printjob * pjob = print_job_find ( jobid ) ;
if ( ! pjob ) return - 1 ;
/* don't allow another process to get this info - it is meaningless */
if ( pjob - > pid ! = local_pid ) return - 1 ;
return pjob - > fd ;
1996-05-04 11:50:46 +04:00
}
2000-04-16 10:20:02 +04:00
/****************************************************************************
give the filename used for a jobid
only valid for the process doing the spooling and when the job
has not been spooled
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
char * print_job_fname ( int jobid )
{
struct printjob * pjob = print_job_find ( jobid ) ;
if ( ! pjob | | pjob - > spooled | | pjob - > pid ! = local_pid ) return NULL ;
return pjob - > filename ;
}
1996-05-04 11:50:46 +04:00
1997-08-31 06:18:59 +04:00
/****************************************************************************
2000-04-16 10:20:02 +04:00
set the place in the queue for a job
1997-08-31 06:18:59 +04:00
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
2000-04-16 10:20:02 +04:00
BOOL print_job_set_place ( int jobid , int place )
1997-08-31 06:18:59 +04:00
{
2000-04-16 10:20:02 +04:00
DEBUG ( 2 , ( " print_job_set_place not implemented yet \n " ) ) ;
return False ;
1997-08-31 06:18:59 +04:00
}
/****************************************************************************
2000-04-16 10:20:02 +04:00
set the name of a job . Only possible for owner
1997-08-31 06:18:59 +04:00
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
2000-04-16 10:20:02 +04:00
BOOL print_job_set_name ( int jobid , char * name )
1997-08-31 06:18:59 +04:00
{
2000-04-16 10:20:02 +04:00
struct printjob * pjob = print_job_find ( jobid ) ;
if ( ! pjob | | pjob - > pid ! = local_pid ) return False ;
fstrcpy ( pjob - > jobname , name ) ;
return print_job_store ( jobid , pjob ) ;
1997-08-31 06:18:59 +04:00
}
1998-07-16 04:06:29 +04:00
2000-04-16 10:20:02 +04:00
1998-07-16 04:06:29 +04:00
/****************************************************************************
2000-04-16 10:20:02 +04:00
delete a print job - don ' t update queue
1998-07-16 04:06:29 +04:00
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
2000-04-16 10:20:02 +04:00
static BOOL print_job_delete1 ( int jobid )
1998-07-16 04:06:29 +04:00
{
2000-04-16 10:20:02 +04:00
struct printjob * pjob = print_job_find ( jobid ) ;
2001-01-24 19:46:08 +03:00
int snum , result = 0 ;
1998-07-16 04:06:29 +04:00
2000-04-16 10:20:02 +04:00
if ( ! pjob ) return False ;
1998-07-16 04:06:29 +04:00
2001-02-23 06:59:37 +03:00
/*
* If already deleting just return .
*/
if ( pjob - > status = = LPQ_DELETING )
return True ;
2000-04-16 10:20:02 +04:00
snum = print_job_snum ( jobid ) ;
2002-03-21 00:55:57 +03:00
if ( snum = = - 1 ) {
DEBUG ( 5 , ( " print_job_delete1: unknown service number for jobid %d \n " , jobid ) ) ;
return False ;
}
1998-07-16 04:06:29 +04:00
2001-01-22 19:59:24 +03:00
/* Hrm - we need to be able to cope with deleting a job before it
has reached the spooler . */
if ( pjob - > sysjob = = - 1 ) {
DEBUG ( 5 , ( " attempt to delete job %d not seen by lpr \n " ,
jobid ) ) ;
}
2001-02-23 06:59:37 +03:00
/* Set the tdb entry to be deleting. */
pjob - > status = LPQ_DELETING ;
print_job_store ( jobid , pjob ) ;
2001-03-16 08:55:30 +03:00
if ( pjob - > spooled & & pjob - > sysjob ! = - 1 )
2001-04-18 09:12:46 +04:00
result = ( * ( current_printif - > job_delete ) ) ( snum , pjob ) ;
2001-03-16 08:55:30 +03:00
/* Delete the tdb entry if the delete suceeded or the job hasn't
been spooled . */
if ( result = = 0 ) {
tdb_delete ( tdb , print_key ( jobid ) ) ;
2001-01-24 19:46:08 +03:00
}
return ( result = = 0 ) ;
1998-07-16 04:06:29 +04:00
}
1998-08-14 21:38:29 +04:00
2000-07-17 06:42:25 +04:00
/****************************************************************************
2000-09-13 08:42:06 +04:00
return true if the current user owns the print job
2000-07-17 06:42:25 +04:00
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
2000-09-13 08:42:06 +04:00
static BOOL is_owner ( struct current_user * user , int jobid )
2000-07-10 09:08:21 +04:00
{
struct printjob * pjob = print_job_find ( jobid ) ;
2000-09-13 08:42:06 +04:00
user_struct * vuser ;
2000-07-10 09:08:21 +04:00
2000-09-13 08:42:06 +04:00
if ( ! pjob | | ! user ) return False ;
2000-07-10 09:08:21 +04:00
2000-09-13 08:42:06 +04:00
if ( ( vuser = get_valid_user_struct ( user - > vuid ) ) ! = NULL ) {
2001-07-04 11:15:53 +04:00
return strequal ( pjob - > user , vuser - > user . smb_name ) ;
2000-09-13 08:42:06 +04:00
} else {
2001-07-04 11:15:53 +04:00
return strequal ( pjob - > user , uidtoname ( user - > uid ) ) ;
2000-09-13 08:42:06 +04:00
}
2000-07-10 09:08:21 +04:00
}
2000-04-16 10:20:02 +04:00
/****************************************************************************
delete a print job
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
2001-09-03 14:38:13 +04:00
BOOL print_job_delete ( struct current_user * user , int jobid , WERROR * errcode )
1998-08-14 21:38:29 +04:00
{
2000-04-16 10:20:02 +04:00
int snum = print_job_snum ( jobid ) ;
2000-11-08 02:05:53 +03:00
char * printer_name ;
2000-07-17 06:42:25 +04:00
BOOL owner ;
2002-03-21 00:55:57 +03:00
if ( snum = = - 1 ) {
DEBUG ( 5 , ( " print_job_delete: unknown service number for jobid %d \n " , jobid ) ) ;
return False ;
}
2000-09-13 08:42:06 +04:00
owner = is_owner ( user , jobid ) ;
2000-07-17 06:42:25 +04:00
2000-07-10 09:08:21 +04:00
/* Check access against security descriptor or whether the user
owns their job . */
2000-07-17 06:42:25 +04:00
if ( ! owner & &
2001-01-19 19:57:39 +03:00
! print_access_check ( user , snum , JOB_ACCESS_ADMINISTER ) ) {
2000-06-16 12:21:51 +04:00
DEBUG ( 3 , ( " delete denied by security descriptor \n " ) ) ;
2001-09-03 14:38:13 +04:00
* errcode = WERR_ACCESS_DENIED ;
2000-06-16 12:21:51 +04:00
return False ;
}
2000-04-16 10:20:02 +04:00
if ( ! print_job_delete1 ( jobid ) ) return False ;
1998-08-14 21:38:29 +04:00
2000-04-16 10:20:02 +04:00
/* force update the database and say the delete failed if the
job still exists */
2000-07-17 06:42:25 +04:00
2000-04-16 10:20:02 +04:00
print_queue_update ( snum ) ;
1998-08-14 21:38:29 +04:00
2000-11-08 02:05:53 +03:00
/* Send a printer notify message */
printer_name = PRINTERNAME ( snum ) ;
2002-02-26 06:12:09 +03:00
send_queue_message ( printer_name , 0 , PRINTER_CHANGE_JOB ) ;
2000-11-08 02:05:53 +03:00
2000-04-16 10:20:02 +04:00
return ! print_job_exists ( jobid ) ;
1998-08-14 21:38:29 +04:00
}
2000-04-16 10:20:02 +04:00
/****************************************************************************
pause a job
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
2001-09-03 14:38:13 +04:00
BOOL print_job_pause ( struct current_user * user , int jobid , WERROR * errcode )
1998-08-14 21:38:29 +04:00
{
2000-04-16 10:20:02 +04:00
struct printjob * pjob = print_job_find ( jobid ) ;
2000-04-16 12:03:37 +04:00
int snum , ret = - 1 ;
2000-11-08 02:05:53 +03:00
char * printer_name ;
2000-07-17 06:42:25 +04:00
if ( ! pjob | | ! user ) return False ;
2000-04-16 10:20:02 +04:00
2000-04-16 12:03:37 +04:00
if ( ! pjob - > spooled | | pjob - > sysjob = = - 1 ) return False ;
2000-04-16 10:20:02 +04:00
snum = print_job_snum ( jobid ) ;
2002-03-21 00:55:57 +03:00
if ( snum = = - 1 ) {
DEBUG ( 5 , ( " print_job_pause: unknown service number for jobid %d \n " , jobid ) ) ;
return False ;
}
if ( snum = = - 1 ) {
DEBUG ( 5 , ( " print_job_resume: unknown service number for jobid %d \n " , jobid ) ) ;
return False ;
}
2000-04-16 10:20:02 +04:00
2001-03-16 08:55:30 +03:00
if ( ! is_owner ( user , jobid ) & &
2001-01-19 19:57:39 +03:00
! print_access_check ( user , snum , JOB_ACCESS_ADMINISTER ) ) {
2000-06-16 12:21:51 +04:00
DEBUG ( 3 , ( " pause denied by security descriptor \n " ) ) ;
2001-09-04 11:13:01 +04:00
* errcode = WERR_ACCESS_DENIED ;
2000-06-16 12:21:51 +04:00
return False ;
}
2000-04-16 12:03:37 +04:00
/* need to pause the spooled entry */
2001-04-18 09:12:46 +04:00
ret = ( * ( current_printif - > job_pause ) ) ( snum , pjob ) ;
1998-08-14 21:38:29 +04:00
2000-11-08 02:05:53 +03:00
if ( ret ! = 0 ) {
2001-09-04 11:13:01 +04:00
* errcode = WERR_INVALID_PARAM ;
2000-11-08 02:05:53 +03:00
return False ;
}
2000-04-16 10:20:02 +04:00
/* force update the database */
print_cache_flush ( snum ) ;
1998-08-14 21:38:29 +04:00
2000-11-08 02:05:53 +03:00
/* Send a printer notify message */
printer_name = PRINTERNAME ( snum ) ;
2002-02-26 06:12:09 +03:00
send_queue_message ( printer_name , 0 , PRINTER_CHANGE_JOB ) ;
2000-11-08 02:05:53 +03:00
2000-04-16 10:20:02 +04:00
/* how do we tell if this succeeded? */
2000-11-08 02:05:53 +03:00
return True ;
2000-04-16 10:20:02 +04:00
}
1998-08-14 21:38:29 +04:00
2000-04-16 10:20:02 +04:00
/****************************************************************************
resume a job
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
2001-09-03 14:38:13 +04:00
BOOL print_job_resume ( struct current_user * user , int jobid , WERROR * errcode )
2000-04-16 10:20:02 +04:00
{
struct printjob * pjob = print_job_find ( jobid ) ;
2000-11-08 02:05:53 +03:00
char * printer_name ;
2000-04-16 12:03:37 +04:00
int snum , ret ;
2000-07-17 06:42:25 +04:00
if ( ! pjob | | ! user ) return False ;
2000-04-16 10:20:02 +04:00
2000-04-16 12:03:37 +04:00
if ( ! pjob - > spooled | | pjob - > sysjob = = - 1 ) return False ;
2000-04-16 10:20:02 +04:00
snum = print_job_snum ( jobid ) ;
2000-09-13 08:42:06 +04:00
if ( ! is_owner ( user , jobid ) & &
2001-01-19 19:57:39 +03:00
! print_access_check ( user , snum , JOB_ACCESS_ADMINISTER ) ) {
2000-06-16 12:21:51 +04:00
DEBUG ( 3 , ( " resume denied by security descriptor \n " ) ) ;
2001-09-04 11:13:01 +04:00
* errcode = WERR_ACCESS_DENIED ;
2000-06-16 12:21:51 +04:00
return False ;
}
2001-03-16 08:55:30 +03:00
ret = ( * ( current_printif - > job_resume ) ) ( snum , pjob ) ;
2000-04-16 10:20:02 +04:00
2000-11-08 02:05:53 +03:00
if ( ret ! = 0 ) {
2001-09-04 11:13:01 +04:00
* errcode = WERR_INVALID_PARAM ;
2000-11-08 02:05:53 +03:00
return False ;
}
2000-04-16 10:20:02 +04:00
/* force update the database */
print_cache_flush ( snum ) ;
2000-11-08 02:05:53 +03:00
/* Send a printer notify message */
printer_name = PRINTERNAME ( snum ) ;
2002-02-26 06:12:09 +03:00
send_queue_message ( printer_name , 0 , PRINTER_CHANGE_JOB ) ;
2000-11-08 02:05:53 +03:00
return True ;
1998-08-14 21:38:29 +04:00
}
2000-04-16 10:20:02 +04:00
/****************************************************************************
write to a print file
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
int print_job_write ( int jobid , const char * buf , int size )
1998-08-14 21:38:29 +04:00
{
2002-03-19 05:35:12 +03:00
int return_code ;
struct printjob * pjob = print_job_find ( jobid ) ;
2000-04-16 10:20:02 +04:00
2002-03-19 05:35:12 +03:00
if ( ! pjob )
return - 1 ;
/* don't allow another process to get this info - it is meaningless */
if ( pjob - > pid ! = local_pid )
return - 1 ;
2000-04-16 10:20:02 +04:00
2002-03-19 05:35:12 +03:00
return_code = write ( pjob - > fd , buf , size ) ;
if ( return_code > 0 ) {
pjob - > size + = size ;
print_job_store ( jobid , pjob ) ;
}
return return_code ;
1998-08-14 21:38:29 +04:00
}
2000-04-10 17:00:12 +04:00
2000-10-11 06:26:27 +04:00
/****************************************************************************
Check if the print queue has been updated recently enough .
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
static BOOL print_cache_expired ( int snum )
{
fstring key ;
2002-03-08 00:51:59 +03:00
time_t last_qscan_time , time_now = time ( NULL ) ;
2000-11-11 01:05:08 +03:00
2002-03-08 00:51:59 +03:00
slprintf ( key , sizeof ( key ) , " CACHE/%s " , lp_servicename ( snum ) ) ;
last_qscan_time = ( time_t ) tdb_fetch_int32 ( tdb , key ) ;
/*
* Invalidate the queue for 3 reasons .
* ( 1 ) . last queue scan time = = - 1.
* ( 2 ) . Current time - last queue scan time > allowed cache time .
* ( 3 ) . last queue scan time > current time + MAX_CACHE_VALID_TIME ( 1 hour by default ) .
* This last test picks up machines for which the clock has been moved
* forward , an lpq scan done and then the clock moved back . Otherwise
* that last lpq scan would stay around for a loooong loooong time . . . : - ) . JRA .
*/
if ( last_qscan_time = = ( ( time_t ) - 1 ) | | ( time_now - last_qscan_time ) > = lp_lpqcachetime ( ) | |
last_qscan_time > ( time_now + MAX_CACHE_VALID_TIME ) ) {
2001-12-05 03:54:33 +03:00
DEBUG ( 3 , ( " print cache expired for queue %s \
2002-03-08 00:51:59 +03:00
( last_qscan_time = % d , time now = % d , qcachetime = % d ) \ n " , lp_servicename(snum),
( int ) last_qscan_time , ( int ) time_now , ( int ) lp_lpqcachetime ( ) ) ) ;
2000-10-11 06:26:27 +04:00
return True ;
}
return False ;
}
/****************************************************************************
2000-11-21 03:30:15 +03:00
Get the queue status - do not update if db is out of date .
2000-10-11 06:26:27 +04:00
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
2000-11-21 03:30:15 +03:00
static int get_queue_status ( int snum , print_status_struct * status )
2000-10-11 06:26:27 +04:00
{
fstring keystr ;
TDB_DATA data , key ;
2000-11-21 03:30:15 +03:00
ZERO_STRUCTP ( status ) ;
2001-04-09 00:22:39 +04:00
slprintf ( keystr , sizeof ( keystr ) - 1 , " STATUS/%s " , lp_servicename ( snum ) ) ;
2000-10-11 06:26:27 +04:00
key . dptr = keystr ;
key . dsize = strlen ( keystr ) ;
data = tdb_fetch ( tdb , key ) ;
if ( data . dptr ) {
2000-11-21 03:30:15 +03:00
if ( data . dsize = = sizeof ( print_status_struct ) ) {
memcpy ( status , data . dptr , sizeof ( print_status_struct ) ) ;
2000-10-11 06:26:27 +04:00
}
free ( data . dptr ) ;
}
2000-11-21 03:30:15 +03:00
return status - > qcount ;
}
/****************************************************************************
Determine the number of jobs in a queue .
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
2001-12-05 03:54:33 +03:00
int print_queue_length ( int snum , print_status_struct * pstatus )
2000-11-21 03:30:15 +03:00
{
print_status_struct status ;
2001-12-05 03:54:33 +03:00
int len ;
2000-11-21 03:30:15 +03:00
/* make sure the database is up to date */
2001-12-05 03:54:33 +03:00
if ( print_cache_expired ( snum ) )
print_queue_update ( snum ) ;
2000-11-21 03:30:15 +03:00
/* also fetch the queue status */
2001-12-05 05:11:03 +03:00
memset ( & status , 0 , sizeof ( status ) ) ;
2001-12-05 03:54:33 +03:00
len = get_queue_status ( snum , & status ) ;
if ( pstatus )
* pstatus = status ;
return len ;
2000-10-11 06:26:27 +04:00
}
2000-04-10 17:00:12 +04:00
2001-01-23 23:25:25 +03:00
/****************************************************************************
Determine the number of jobs in all queues .
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
static int get_total_jobs ( int snum )
{
int total_jobs ;
/* make sure the database is up to date */
if ( print_cache_expired ( snum ) ) print_queue_update ( snum ) ;
2002-01-09 07:13:30 +03:00
total_jobs = tdb_fetch_int32 ( tdb , " INFO/total_jobs " ) ;
2001-01-23 23:25:25 +03:00
if ( total_jobs > 0 )
return total_jobs ;
else
return 0 ;
}
2000-04-16 10:20:02 +04:00
/***************************************************************************
start spooling a job - return the jobid
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
2000-07-06 11:06:05 +04:00
int print_job_start ( struct current_user * user , int snum , char * jobname )
2000-04-10 17:00:12 +04:00
{
2000-04-16 10:20:02 +04:00
int jobid ;
char * path ;
struct printjob pjob ;
int next_jobid ;
2000-09-13 08:42:06 +04:00
user_struct * vuser ;
2001-12-18 08:08:48 +03:00
int njobs = 0 ;
2000-04-10 17:00:12 +04:00
2000-08-24 03:05:49 +04:00
errno = 0 ;
2000-09-01 22:49:26 +04:00
if ( ! print_access_check ( user , snum , PRINTER_ACCESS_USE ) ) {
2000-09-13 06:24:35 +04:00
DEBUG ( 3 , ( " print_job_start: job start denied by security descriptor \n " ) ) ;
return - 1 ;
}
if ( ! print_time_access_check ( snum ) ) {
DEBUG ( 3 , ( " print_job_start: job start denied by time check \n " ) ) ;
2000-09-01 22:49:26 +04:00
return - 1 ;
2000-06-16 12:21:51 +04:00
}
2000-04-16 10:20:02 +04:00
path = lp_pathname ( snum ) ;
2000-04-10 17:00:12 +04:00
/* see if we have sufficient disk space */
2000-04-16 10:20:02 +04:00
if ( lp_minprintspace ( snum ) ) {
2000-04-19 12:44:56 +04:00
SMB_BIG_UINT dspace , dsize ;
if ( sys_fsusage ( path , & dspace , & dsize ) = = 0 & &
dspace < 2 * ( SMB_BIG_UINT ) lp_minprintspace ( snum ) ) {
2001-06-28 23:23:43 +04:00
DEBUG ( 3 , ( " print_job_start: disk space check failed. \n " ) ) ;
2000-04-10 17:00:12 +04:00
errno = ENOSPC ;
2000-04-16 10:20:02 +04:00
return - 1 ;
2000-04-10 17:00:12 +04:00
}
}
2000-05-10 15:49:06 +04:00
/* for autoloaded printers, check that the printcap entry still exists */
if ( lp_autoloaded ( snum ) & & ! pcap_printername_ok ( lp_servicename ( snum ) , NULL ) ) {
2001-06-28 23:23:43 +04:00
DEBUG ( 3 , ( " print_job_start: printer name %s check failed. \n " , lp_servicename ( snum ) ) ) ;
2000-05-10 15:49:06 +04:00
errno = ENOENT ;
return - 1 ;
}
2001-01-23 23:25:25 +03:00
/* Insure the maximum queue size is not violated */
2001-12-05 03:54:33 +03:00
if ( lp_maxprintjobs ( snum ) & & ( njobs = print_queue_length ( snum , NULL ) ) > lp_maxprintjobs ( snum ) ) {
2001-06-28 23:23:43 +04:00
DEBUG ( 3 , ( " print_job_start: number of jobs (%d) larger than max printjobs per queue (%d). \n " ,
2001-12-05 03:54:33 +03:00
njobs , lp_maxprintjobs ( snum ) ) ) ;
2000-10-11 06:26:27 +04:00
errno = ENOSPC ;
return - 1 ;
}
2001-01-23 23:25:25 +03:00
/* Insure the maximum print jobs in the system is not violated */
if ( lp_totalprintjobs ( ) & & get_total_jobs ( snum ) > lp_totalprintjobs ( ) ) {
2001-06-28 23:23:43 +04:00
DEBUG ( 3 , ( " print_job_start: number of jobs (%d) larger than max printjobs per system (%d). \n " ,
2001-12-05 03:54:33 +03:00
njobs , lp_totalprintjobs ( ) ) ) ;
2001-01-23 23:25:25 +03:00
errno = ENOSPC ;
return - 1 ;
}
2000-04-16 10:20:02 +04:00
/* create the database entry */
ZERO_STRUCT ( pjob ) ;
pjob . pid = local_pid ;
pjob . sysjob = - 1 ;
pjob . fd = - 1 ;
pjob . starttime = time ( NULL ) ;
2001-02-23 06:59:37 +03:00
pjob . status = LPQ_SPOOLING ;
2000-04-16 10:20:02 +04:00
pjob . size = 0 ;
pjob . spooled = False ;
pjob . smbjob = True ;
fstrcpy ( pjob . jobname , jobname ) ;
2000-09-13 08:42:06 +04:00
if ( ( vuser = get_valid_user_struct ( user - > vuid ) ) ! = NULL ) {
2001-07-04 11:15:53 +04:00
fstrcpy ( pjob . user , vuser - > user . smb_name ) ;
2000-09-13 08:42:06 +04:00
} else {
2001-07-04 11:15:53 +04:00
fstrcpy ( pjob . user , uidtoname ( user - > uid ) ) ;
2000-09-13 08:42:06 +04:00
}
2002-03-21 00:55:57 +03:00
fstrcpy ( pjob . queuename , lp_servicename ( snum ) ) ;
2000-04-16 10:20:02 +04:00
/* lock the database */
2000-10-10 10:45:09 +04:00
tdb_lock_bystring ( tdb , " INFO/nextjob " ) ;
2000-04-16 10:20:02 +04:00
2002-01-09 07:13:30 +03:00
next_jobid = tdb_fetch_int32 ( tdb , " INFO/nextjob " ) ;
2001-06-28 23:23:43 +04:00
if ( next_jobid = = - 1 )
next_jobid = 1 ;
2000-04-16 10:20:02 +04:00
2001-02-22 04:31:55 +03:00
for ( jobid = NEXT_JOBID ( next_jobid ) ; jobid ! = next_jobid ; jobid = NEXT_JOBID ( jobid ) ) {
2001-06-28 23:23:43 +04:00
if ( ! print_job_exists ( jobid ) )
break ;
2000-04-16 10:20:02 +04:00
}
if ( jobid = = next_jobid | | ! print_job_store ( jobid , & pjob ) ) {
2001-06-28 23:23:43 +04:00
DEBUG ( 3 , ( " print_job_start: either jobid (%d)==next_jobid(%d) or print_job_store failed. \n " ,
jobid , next_jobid ) ) ;
2000-04-16 10:20:02 +04:00
jobid = - 1 ;
goto fail ;
2000-04-10 17:00:12 +04:00
}
2002-01-09 07:13:30 +03:00
tdb_store_int32 ( tdb , " INFO/nextjob " , jobid ) ;
2000-04-10 17:00:12 +04:00
2001-04-18 09:12:46 +04:00
/* we have a job entry - now create the spool file */
2001-07-17 03:39:26 +04:00
slprintf ( pjob . filename , sizeof ( pjob . filename ) - 1 , " %s/%s%.6d.XXXXXX " ,
path , PRINT_SPOOL_PREFIX , jobid ) ;
2001-04-18 09:12:46 +04:00
pjob . fd = smb_mkstemp ( pjob . filename ) ;
2001-03-27 02:15:40 +04:00
if ( pjob . fd = = - 1 ) {
if ( errno = = EACCES ) {
/* Common setup error, force a report. */
DEBUG ( 0 , ( " print_job_start: insufficient permissions \
to open spool file % s . \ n " , pjob.filename));
} else {
/* Normal case, report at level 3 and above. */
DEBUG ( 3 , ( " print_job_start: can't open spool file %s, \n " , pjob . filename ) ) ;
DEBUGADD ( 3 , ( " errno = %d (%s). \n " , errno , strerror ( errno ) ) ) ;
}
goto fail ;
}
2000-04-16 10:20:02 +04:00
print_job_store ( jobid , & pjob ) ;
2000-10-10 10:45:09 +04:00
tdb_unlock_bystring ( tdb , " INFO/nextjob " ) ;
2000-09-01 22:49:26 +04:00
2000-04-10 17:00:12 +04:00
/*
* If the printer is marked as postscript output a leading
* file identifier to ensure the file is treated as a raw
* postscript file .
* This has a similar effect as CtrlD = 0 in WIN . INI file .
* tim @ fsg . com 09 / 06 / 94
*/
2000-04-16 10:20:02 +04:00
if ( lp_postscript ( snum ) ) {
print_job_write ( jobid , " %! \n " , 3 ) ;
2000-04-10 17:00:12 +04:00
}
2000-04-16 10:20:02 +04:00
return jobid ;
fail :
if ( jobid ! = - 1 ) {
tdb_delete ( tdb , print_key ( jobid ) ) ;
}
2000-10-10 10:45:09 +04:00
tdb_unlock_bystring ( tdb , " INFO/nextjob " ) ;
2001-06-28 23:23:43 +04:00
DEBUG ( 3 , ( " print_job_start: returning fail. Error = %s \n " , strerror ( errno ) ) ) ;
2000-08-24 03:05:49 +04:00
return - 1 ;
2000-04-16 10:20:02 +04:00
}
2002-03-19 05:35:12 +03:00
/****************************************************************************
Update the number of pages spooled to jobid
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
void print_job_endpage ( int jobid )
{
struct printjob * pjob = print_job_find ( jobid ) ;
if ( ! pjob )
return ;
/* don't allow another process to get this info - it is meaningless */
if ( pjob - > pid ! = local_pid )
return ;
pjob - > page_count + + ;
print_job_store ( jobid , pjob ) ;
}
2000-04-16 10:20:02 +04:00
/****************************************************************************
2000-08-01 04:41:19 +04:00
Print a file - called on closing the file . This spools the job .
2001-01-30 00:34:08 +03:00
If normal close is false then we ' re tearing down the jobs - treat as an
error .
2000-04-16 10:20:02 +04:00
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
2000-08-01 04:41:19 +04:00
2001-01-30 00:34:08 +03:00
BOOL print_job_end ( int jobid , BOOL normal_close )
2000-04-16 10:20:02 +04:00
{
struct printjob * pjob = print_job_find ( jobid ) ;
2001-01-22 19:59:24 +03:00
int snum , ret ;
2000-04-16 10:20:02 +04:00
SMB_STRUCT_STAT sbuf ;
2000-08-01 04:41:19 +04:00
if ( ! pjob )
return False ;
2000-04-16 10:20:02 +04:00
2000-08-01 04:41:19 +04:00
if ( pjob - > spooled | | pjob - > pid ! = local_pid )
return False ;
2000-04-16 10:20:02 +04:00
snum = print_job_snum ( jobid ) ;
2002-03-21 00:55:57 +03:00
if ( snum = = - 1 ) {
DEBUG ( 5 , ( " print_job_end: unknown service number for jobid %d \n " , jobid ) ) ;
return False ;
}
2000-04-16 10:20:02 +04:00
2001-01-30 00:34:08 +03:00
if ( normal_close & & ( sys_fstat ( pjob - > fd , & sbuf ) = = 0 ) ) {
2000-08-01 04:41:19 +04:00
pjob - > size = sbuf . st_size ;
2001-01-19 19:57:39 +03:00
close ( pjob - > fd ) ;
pjob - > fd = - 1 ;
} else {
2001-01-30 00:34:08 +03:00
/*
* Not a normal close or we couldn ' t stat the job file ,
* so something has gone wrong . Cleanup .
*/
2001-02-22 04:31:55 +03:00
close ( pjob - > fd ) ;
pjob - > fd = - 1 ;
2001-06-28 23:23:43 +04:00
DEBUG ( 3 , ( " print_job_end: failed to stat file for jobid %d \n " , jobid ) ) ;
2001-02-22 04:31:55 +03:00
goto fail ;
2001-01-19 19:57:39 +03:00
}
2001-02-22 04:31:55 +03:00
/* Technically, this is not quit right. If the printer has a separator
* page turned on , the NT spooler prints the separator page even if the
* print job is 0 bytes . 010215 JRR */
2001-02-23 06:59:37 +03:00
if ( pjob - > size = = 0 | | pjob - > status = = LPQ_DELETING ) {
/* don't bother spooling empty files or something being deleted. */
DEBUG ( 5 , ( " print_job_end: canceling spool of %s (%s) \n " ,
pjob - > filename , pjob - > size ? " deleted " : " zero length " ) ) ;
2000-04-16 10:20:02 +04:00
unlink ( pjob - > filename ) ;
tdb_delete ( tdb , print_key ( jobid ) ) ;
return True ;
}
2001-03-16 08:55:30 +03:00
ret = ( * ( current_printif - > job_submit ) ) ( snum , pjob ) ;
2000-04-16 10:20:02 +04:00
2001-06-28 23:23:43 +04:00
if ( ret )
goto fail ;
2001-02-22 04:31:55 +03:00
/* The print job has been sucessfully handed over to the back-end */
pjob - > spooled = True ;
2001-02-23 06:59:37 +03:00
pjob - > status = LPQ_QUEUED ;
2001-02-22 04:31:55 +03:00
print_job_store ( jobid , pjob ) ;
/* make sure the database is up to date */
2001-06-28 23:23:43 +04:00
if ( print_cache_expired ( snum ) )
print_queue_update ( snum ) ;
2001-02-22 04:31:55 +03:00
return True ;
fail :
2001-06-28 23:23:43 +04:00
2001-02-22 04:31:55 +03:00
/* The print job was not succesfully started. Cleanup */
/* Still need to add proper error return propagation! 010122:JRR */
unlink ( pjob - > filename ) ;
tdb_delete ( tdb , print_key ( jobid ) ) ;
return False ;
2000-04-16 10:20:02 +04:00
}
2000-04-16 12:03:37 +04:00
/* utility fn to enumerate the print queue */
2000-04-16 10:20:02 +04:00
static int traverse_fn_queue ( TDB_CONTEXT * t , TDB_DATA key , TDB_DATA data , void * state )
{
struct traverse_struct * ts = ( struct traverse_struct * ) state ;
struct printjob pjob ;
int i , jobid ;
if ( data . dsize ! = sizeof ( pjob ) | | key . dsize ! = sizeof ( int ) ) return 0 ;
memcpy ( & jobid , key . dptr , sizeof ( jobid ) ) ;
memcpy ( & pjob , data . dptr , sizeof ( pjob ) ) ;
/* maybe it isn't for this queue */
2002-03-21 01:39:30 +03:00
if ( ts - > snum ! = lp_servicenumber ( pjob . queuename ) )
2002-03-21 00:55:57 +03:00
return 0 ;
2000-04-16 10:20:02 +04:00
2000-10-10 22:40:03 +04:00
if ( ts - > qcount > = ts - > maxcount ) return 0 ;
2000-04-16 10:20:02 +04:00
i = ts - > qcount ;
ts - > queue [ i ] . job = jobid ;
ts - > queue [ i ] . size = pjob . size ;
2002-03-19 05:35:12 +03:00
ts - > queue [ i ] . page_count = pjob . page_count ;
2000-04-16 10:20:02 +04:00
ts - > queue [ i ] . status = pjob . status ;
2000-07-07 03:31:46 +04:00
ts - > queue [ i ] . priority = 1 ;
2000-04-16 10:20:02 +04:00
ts - > queue [ i ] . time = pjob . starttime ;
2002-03-15 11:14:10 +03:00
fstrcpy ( ts - > queue [ i ] . fs_user , pjob . user ) ;
fstrcpy ( ts - > queue [ i ] . fs_file , pjob . jobname ) ;
2000-04-16 10:20:02 +04:00
ts - > qcount + + ;
return 0 ;
}
2000-10-10 22:40:03 +04:00
struct traverse_count_struct {
int snum , count ;
} ;
/* utility fn to count the number of entries in the print queue */
static int traverse_count_fn_queue ( TDB_CONTEXT * t , TDB_DATA key , TDB_DATA data , void * state )
{
struct traverse_count_struct * ts = ( struct traverse_count_struct * ) state ;
struct printjob pjob ;
int jobid ;
if ( data . dsize ! = sizeof ( pjob ) | | key . dsize ! = sizeof ( int ) ) return 0 ;
memcpy ( & jobid , key . dptr , sizeof ( jobid ) ) ;
memcpy ( & pjob , data . dptr , sizeof ( pjob ) ) ;
/* maybe it isn't for this queue */
2002-03-21 01:39:30 +03:00
if ( ts - > snum ! = lp_servicenumber ( pjob . queuename ) )
2002-03-21 00:55:57 +03:00
return 0 ;
2000-10-10 22:40:03 +04:00
ts - > count + + ;
return 0 ;
}
2000-11-04 21:24:15 +03:00
/* Sort print jobs by submittal time */
static int printjob_comp ( print_queue_struct * j1 , print_queue_struct * j2 )
{
/* Silly cases */
if ( ! j1 & & ! j2 ) return 0 ;
if ( ! j1 ) return - 1 ;
if ( ! j2 ) return 1 ;
/* Sort on job start time */
if ( j1 - > time = = j2 - > time ) return 0 ;
return ( j1 - > time > j2 - > time ) ? 1 : - 1 ;
}
2000-04-16 10:20:02 +04:00
/****************************************************************************
get a printer queue listing
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
int print_queue_status ( int snum ,
print_queue_struct * * queue ,
print_status_struct * status )
{
struct traverse_struct tstruct ;
2000-10-10 22:40:03 +04:00
struct traverse_count_struct tsc ;
2000-04-16 10:20:02 +04:00
fstring keystr ;
TDB_DATA data , key ;
/* make sure the database is up to date */
if ( print_cache_expired ( snum ) ) print_queue_update ( snum ) ;
2000-11-10 22:36:34 +03:00
* queue = NULL ;
2000-04-16 10:20:02 +04:00
2000-10-10 22:40:03 +04:00
/*
2000-12-14 00:24:06 +03:00
* Fetch the queue status . We must do this first , as there may
* be no jobs in the queue .
*/
ZERO_STRUCTP ( status ) ;
2001-04-09 00:22:39 +04:00
slprintf ( keystr , sizeof ( keystr ) - 1 , " STATUS/%s " , lp_servicename ( snum ) ) ;
2000-12-14 00:24:06 +03:00
key . dptr = keystr ;
key . dsize = strlen ( keystr ) ;
data = tdb_fetch ( tdb , key ) ;
if ( data . dptr ) {
if ( data . dsize = = sizeof ( * status ) ) {
memcpy ( status , data . dptr , sizeof ( * status ) ) ;
}
free ( data . dptr ) ;
}
/*
* Now , fetch the print queue information . We first count the number
* of entries , and then only retrieve the queue if necessary .
2000-10-10 22:40:03 +04:00
*/
tsc . count = 0 ;
tsc . snum = snum ;
2000-12-14 00:24:06 +03:00
2000-10-10 22:40:03 +04:00
tdb_traverse ( tdb , traverse_count_fn_queue , ( void * ) & tsc ) ;
2000-11-10 22:36:34 +03:00
if ( tsc . count = = 0 )
return 0 ;
2000-10-10 22:40:03 +04:00
/* Allocate the queue size. */
2000-11-15 00:56:32 +03:00
if ( ( tstruct . queue = ( print_queue_struct * )
malloc ( sizeof ( print_queue_struct ) * tsc . count ) )
2000-10-10 22:40:03 +04:00
= = NULL )
return 0 ;
/*
* Fill in the queue .
* We need maxcount as the queue size may have changed between
* the two calls to tdb_traverse .
*/
2000-04-16 10:20:02 +04:00
tstruct . qcount = 0 ;
2000-10-10 22:40:03 +04:00
tstruct . maxcount = tsc . count ;
2000-04-16 10:20:02 +04:00
tstruct . snum = snum ;
tdb_traverse ( tdb , traverse_fn_queue , ( void * ) & tstruct ) ;
2000-11-04 21:24:15 +03:00
/* Sort the queue by submission time otherwise they are displayed
in hash order . */
qsort ( tstruct . queue , tstruct . qcount , sizeof ( print_queue_struct ) ,
QSORT_CAST ( printjob_comp ) ) ;
2000-04-16 10:20:02 +04:00
* queue = tstruct . queue ;
return tstruct . qcount ;
}
/****************************************************************************
turn a queue name into a snum
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
int print_queue_snum ( char * qname )
{
int snum = lp_servicenumber ( qname ) ;
if ( snum = = - 1 | | ! lp_print_ok ( snum ) ) return - 1 ;
return snum ;
}
/****************************************************************************
pause a queue
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
2001-09-03 14:38:13 +04:00
BOOL print_queue_pause ( struct current_user * user , int snum , WERROR * errcode )
2000-04-16 10:20:02 +04:00
{
2000-11-08 02:05:53 +03:00
char * printer_name ;
2000-06-16 12:21:51 +04:00
int ret ;
2000-07-17 06:42:25 +04:00
2000-09-01 22:49:26 +04:00
if ( ! print_access_check ( user , snum , PRINTER_ACCESS_ADMINISTER ) ) {
2001-09-03 14:38:13 +04:00
* errcode = WERR_ACCESS_DENIED ;
2000-06-16 12:21:51 +04:00
return False ;
}
2001-03-16 08:55:30 +03:00
ret = ( * ( current_printif - > queue_pause ) ) ( snum ) ;
2000-04-16 12:03:37 +04:00
2000-11-08 02:05:53 +03:00
if ( ret ! = 0 ) {
2001-09-03 14:38:13 +04:00
* errcode = WERR_INVALID_PARAM ;
2000-11-08 02:05:53 +03:00
return False ;
}
2000-04-16 12:03:37 +04:00
/* force update the database */
print_cache_flush ( snum ) ;
2000-11-04 21:24:15 +03:00
/* Send a printer notify message */
2000-11-08 02:05:53 +03:00
printer_name = PRINTERNAME ( snum ) ;
2000-11-04 21:24:15 +03:00
2002-02-26 06:12:09 +03:00
send_queue_message ( printer_name , 0 , PRINTER_CHANGE_JOB ) ;
2000-11-04 21:24:15 +03:00
2000-11-08 02:05:53 +03:00
return True ;
2000-04-16 10:20:02 +04:00
}
/****************************************************************************
resume a queue
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
2001-09-03 14:38:13 +04:00
BOOL print_queue_resume ( struct current_user * user , int snum , WERROR * errcode )
2000-04-16 10:20:02 +04:00
{
2000-11-08 02:05:53 +03:00
char * printer_name ;
2000-06-16 12:21:51 +04:00
int ret ;
2000-09-01 22:49:26 +04:00
if ( ! print_access_check ( user , snum , PRINTER_ACCESS_ADMINISTER ) ) {
2001-09-03 14:38:13 +04:00
* errcode = WERR_ACCESS_DENIED ;
2000-06-16 12:21:51 +04:00
return False ;
}
2001-03-16 08:55:30 +03:00
ret = ( * ( current_printif - > queue_resume ) ) ( snum ) ;
2000-04-16 12:03:37 +04:00
2000-11-08 02:05:53 +03:00
if ( ret ! = 0 ) {
2001-09-03 14:38:13 +04:00
* errcode = WERR_INVALID_PARAM ;
2000-11-08 02:05:53 +03:00
return False ;
}
2001-01-19 19:57:39 +03:00
/* make sure the database is up to date */
if ( print_cache_expired ( snum ) ) print_queue_update ( snum ) ;
2000-04-16 12:03:37 +04:00
2000-11-04 21:24:15 +03:00
/* Send a printer notify message */
2000-11-08 02:05:53 +03:00
printer_name = PRINTERNAME ( snum ) ;
2000-11-04 21:24:15 +03:00
2002-02-26 06:12:09 +03:00
send_queue_message ( printer_name , 0 , PRINTER_CHANGE_JOB ) ;
2000-11-04 21:24:15 +03:00
2000-11-08 02:05:53 +03:00
return True ;
2000-04-16 10:20:02 +04:00
}
/****************************************************************************
purge a queue - implemented by deleting all jobs that we can delete
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
2001-09-03 14:38:13 +04:00
BOOL print_queue_purge ( struct current_user * user , int snum , WERROR * errcode )
2000-04-16 10:20:02 +04:00
{
print_queue_struct * queue ;
print_status_struct status ;
2000-11-04 21:24:15 +03:00
char * printer_name ;
2000-04-16 10:20:02 +04:00
int njobs , i ;
2001-01-22 19:59:24 +03:00
BOOL can_job_admin ;
2000-04-16 10:20:02 +04:00
2001-01-23 20:39:03 +03:00
/* Force and update so the count is accurate (i.e. not a cached count) */
print_queue_update ( snum ) ;
2001-01-22 19:59:24 +03:00
can_job_admin = print_access_check ( user , snum , JOB_ACCESS_ADMINISTER ) ;
2000-04-16 10:20:02 +04:00
njobs = print_queue_status ( snum , & queue , & status ) ;
2001-01-11 23:41:19 +03:00
2001-01-22 19:59:24 +03:00
for ( i = 0 ; i < njobs ; i + + ) {
BOOL owner = is_owner ( user , queue [ i ] . job ) ;
if ( owner | | can_job_admin ) {
2000-09-01 22:49:26 +04:00
print_job_delete1 ( queue [ i ] . job ) ;
}
2000-04-16 10:20:02 +04:00
}
2000-10-11 01:52:31 +04:00
safe_free ( queue ) ;
2000-04-16 10:20:02 +04:00
2000-11-04 21:24:15 +03:00
/* Send a printer notify message */
printer_name = PRINTERNAME ( snum ) ;
2002-02-26 06:12:09 +03:00
send_queue_message ( printer_name , 0 , PRINTER_CHANGE_JOB ) ;
2000-11-04 21:24:15 +03:00
2000-04-16 10:20:02 +04:00
return True ;
}