2007-11-30 00:24:54 +03:00
/*
2002-01-30 09:08:46 +03:00
Unix SMB / CIFS implementation .
2000-04-25 18:04:06 +04:00
client print routines
Copyright ( C ) Andrew Tridgell 1994 - 1998
2007-11-30 00:24:54 +03:00
2000-04-25 18:04:06 +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
2007-07-09 23:25:36 +04:00
the Free Software Foundation ; either version 3 of the License , or
2000-04-25 18:04:06 +04:00
( at your option ) any later version .
2007-11-30 00:24:54 +03:00
2000-04-25 18:04:06 +04:00
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 .
2007-11-30 00:24:54 +03:00
2000-04-25 18:04:06 +04:00
You should have received a copy of the GNU General Public License
2007-07-10 04:52:41 +04:00
along with this program . If not , see < http : //www.gnu.org/licenses/>.
2000-04-25 18:04:06 +04:00
*/
# include "includes.h"
2011-05-06 13:47:43 +04:00
# include "libsmb/libsmb.h"
2011-02-24 12:46:55 +03:00
# include "libsmb/clirap.h"
2012-05-19 20:50:27 +04:00
# include "../libcli/smb/smbXcli_base.h"
2020-08-07 21:17:34 +03:00
# include "lib/util/string_wrappers.h"
2000-04-25 18:04:06 +04:00
/*****************************************************************************
Convert a character pointer in a cli_call_api ( ) response to a form we can use .
2007-11-30 00:24:54 +03:00
This function contains code to prevent core dumps if the server returns
2000-04-25 18:04:06 +04:00
invalid data .
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
2007-11-30 00:24:54 +03:00
static const char * fix_char_ptr ( unsigned int datap , unsigned int converter ,
2000-04-25 18:04:06 +04:00
char * rdata , int rdrcnt )
{
2009-11-12 22:44:37 +03:00
unsigned int offset ;
2007-11-30 00:24:54 +03:00
if ( datap = = 0 ) {
/* turn NULL pointers into zero length strings */
2000-04-25 18:04:06 +04:00
return " " ;
2009-11-12 22:44:37 +03:00
}
offset = datap - converter ;
2000-04-25 18:04:06 +04:00
2009-11-12 22:44:37 +03:00
if ( offset > = rdrcnt ) {
2023-08-07 07:37:19 +03:00
DEBUG ( 1 , ( " bad char ptr: datap=%u, converter=%u rdrcnt=%d> \n " ,
2009-11-12 22:44:37 +03:00
datap , converter , rdrcnt ) ) ;
return " <ERROR> " ;
2000-04-25 18:04:06 +04:00
}
2009-11-12 22:44:37 +03:00
return & rdata [ offset ] ;
2000-04-25 18:04:06 +04:00
}
/****************************************************************************
call fn ( ) on each entry in a print queue
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
2007-11-30 00:24:54 +03:00
2022-02-13 11:21:47 +03:00
NTSTATUS cli_print_queue ( struct cli_state * cli ,
void ( * fn ) ( struct print_job_info * ) )
2000-04-25 18:04:06 +04:00
{
2022-02-13 11:21:47 +03:00
uint8_t * rparam = NULL ;
uint8_t * rdata = NULL ;
char * p = NULL ;
uint32_t rdrcnt , rprcnt ;
2007-11-30 00:24:54 +03:00
char param [ 1024 ] ;
2022-02-13 11:21:47 +03:00
int converter ;
2000-04-25 18:04:06 +04:00
int result_code = 0 ;
int i = - 1 ;
2022-02-13 11:21:47 +03:00
NTSTATUS status ;
2007-11-30 00:24:54 +03:00
2000-04-25 18:04:06 +04:00
memset ( param , ' \0 ' , sizeof ( param ) ) ;
p = param ;
SSVAL ( p , 0 , 76 ) ; /* API function number 76 (DosPrintJobEnum) */
p + = 2 ;
2011-05-04 00:14:46 +04:00
strlcpy_base ( p , " zWrLeh " , param , sizeof ( param ) ) ; /* parameter description? */
2007-04-03 00:10:21 +04:00
p = skip_string ( param , sizeof ( param ) , p ) ;
2011-05-04 00:14:46 +04:00
strlcpy_base ( p , " WWzWWDDzz " , param , sizeof ( param ) ) ; /* returned data format */
2007-04-03 00:10:21 +04:00
p = skip_string ( param , sizeof ( param ) , p ) ;
2011-05-04 00:14:46 +04:00
strlcpy_base ( p , cli - > share , param , sizeof ( param ) ) ; /* name of queue */
2007-04-03 00:10:21 +04:00
p = skip_string ( param , sizeof ( param ) , p ) ;
2000-04-25 18:04:06 +04:00
SSVAL ( p , 0 , 2 ) ; /* API function level 2, PRJINFO_2 data structure */
SSVAL ( p , 2 , 1000 ) ; /* size of bytes of returned data buffer */
p + = 4 ;
2011-05-04 00:14:46 +04:00
strlcpy_base ( p , " " , param , sizeof ( param ) ) ; /* subformat */
2007-04-03 00:10:21 +04:00
p = skip_string ( param , sizeof ( param ) , p ) ;
2000-04-25 18:04:06 +04:00
DEBUG ( 4 , ( " doing cli_print_queue for %s \n " , cli - > share ) ) ;
2022-02-13 11:21:47 +03:00
status = cli_trans (
talloc_tos ( ) ,
cli ,
SMBtrans , /* trans_cmd */
" \\ PIPE \\ LANMAN " , /* name */
0 , /* fid */
0 , /* function */
0 , /* flags */
NULL , /* setup */
0 , /* num_setup */
0 , /* max_setup */
( uint8_t * ) param , /* param */
PTR_DIFF ( p , param ) , /* num_param */
1024 , /* max_param */
NULL , /* data */
0 , /* num_data */
CLI_BUFFER_SIZE , /* max_data */
NULL , /* recv_flags2 */
NULL , /* rsetup */
0 , /* min_rsetup */
NULL , /* num_rsetup */
& rparam , /* rparam */
8 , /* min_rparam */
& rprcnt , /* num_rparam */
& rdata , /* rdata */
0 , /* min_rdata */
& rdrcnt ) ; /* num_rdata */
if ( ! NT_STATUS_IS_OK ( status ) ) {
cli - > raw_status = status ;
return status ;
}
result_code = SVAL ( rparam , 0 ) ;
converter = SVAL ( rparam , 2 ) ; /* conversion factor */
if ( result_code = = 0 ) {
struct print_job_info job ;
p = ( char * ) rdata ;
for ( i = 0 ; i < SVAL ( rparam , 4 ) ; + + i ) {
job . id = SVAL ( p , 0 ) ;
job . priority = SVAL ( p , 2 ) ;
fstrcpy ( job . user ,
fix_char_ptr ( SVAL ( p , 4 ) , converter ,
( char * ) rdata , rdrcnt ) ) ;
job . t = make_unix_date3 (
p + 12 , smb1cli_conn_server_time_zone ( cli - > conn ) ) ;
job . size = IVAL ( p , 16 ) ;
fstrcpy ( job . name , fix_char_ptr ( SVAL ( p , 24 ) ,
converter ,
( char * ) rdata , rdrcnt ) ) ;
fn ( & job ) ;
p + = 28 ;
2000-04-25 18:04:06 +04:00
}
}
/* If any parameters or data were returned, free the storage. */
2022-02-13 11:21:47 +03:00
TALLOC_FREE ( rparam ) ;
TALLOC_FREE ( rdata ) ;
2000-04-25 18:04:06 +04:00
2022-02-13 11:21:47 +03:00
return NT_STATUS_OK ;
2000-04-25 18:04:06 +04:00
}
/****************************************************************************
cancel a print job
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
2007-11-30 00:24:54 +03:00
2000-04-25 18:04:06 +04:00
int cli_printjob_del ( struct cli_state * cli , int job )
{
char * rparam = NULL ;
char * rdata = NULL ;
char * p ;
2003-08-15 05:42:30 +04:00
unsigned int rdrcnt , rprcnt ;
int ret = - 1 ;
2007-11-30 00:24:54 +03:00
char param [ 1024 ] ;
2000-04-25 18:04:06 +04:00
memset ( param , ' \0 ' , sizeof ( param ) ) ;
p = param ;
SSVAL ( p , 0 , 81 ) ; /* DosPrintJobDel() */
p + = 2 ;
2011-05-04 00:14:46 +04:00
strlcpy_base ( p , " W " , param , sizeof ( param ) ) ;
2007-04-03 00:10:21 +04:00
p = skip_string ( param , sizeof ( param ) , p ) ;
2011-05-04 00:14:46 +04:00
strlcpy_base ( p , " " , param , sizeof ( param ) ) ;
2007-04-03 00:10:21 +04:00
p = skip_string ( param , sizeof ( param ) , p ) ;
2007-11-30 00:24:54 +03:00
SSVAL ( p , 0 , job ) ;
2000-04-25 18:04:06 +04:00
p + = 2 ;
2007-11-30 00:24:54 +03:00
if ( cli_api ( cli ,
2000-04-25 18:04:06 +04:00
param , PTR_DIFF ( p , param ) , 1024 , /* Param, length, maxlen */
NULL , 0 , CLI_BUFFER_SIZE , /* data, length, maxlen */
& rparam , & rprcnt , /* return params, length */
& rdata , & rdrcnt ) ) { /* return data, length */
ret = SVAL ( rparam , 0 ) ;
}
2001-09-17 07:33:37 +04:00
SAFE_FREE ( rparam ) ;
SAFE_FREE ( rdata ) ;
2000-04-25 18:04:06 +04:00
return ret ;
}