2000-07-07 10:18:00 +04:00
/*
Unix SMB / Netbios implementation .
2001-01-12 01:49:30 +03:00
Version 2.2
RPC pipe client
Copyright ( C ) Tim Potter 2000
Copyright ( C ) Andrew Tridgell 1992 - 1999
Copyright ( C ) Luke Kenneth Casson Leighton 1996 - 1999
2000-07-07 10:18:00 +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 .
*/
# include "includes.h"
extern int DEBUGLEVEL ;
2001-01-12 01:49:30 +03:00
extern pstring server ;
extern pstring global_myname ;
extern pstring username , password ;
extern pstring workgroup ;
2000-07-07 10:18:00 +04:00
2000-08-08 10:57:48 +04:00
/****************************************************************************
2001-01-12 01:49:30 +03:00
display sec_ace structure
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
static void display_sec_ace ( SEC_ACE * ace )
2000-08-08 10:57:48 +04:00
{
2001-01-12 01:49:30 +03:00
fstring sid_str ;
2000-08-08 10:57:48 +04:00
2001-01-12 01:49:30 +03:00
sid_to_string ( sid_str , & ace - > sid ) ;
printf ( " \t \t SID: %s \n " , sid_str ) ;
2000-07-07 10:18:00 +04:00
2001-01-12 01:49:30 +03:00
printf ( " \t \t type:[%d], flags:[0x%02x], mask:[0x%08x] \n " ,
ace - > type , ace - > flags , ace - > info . mask ) ;
2000-07-21 23:59:51 +04:00
}
/****************************************************************************
2001-01-12 01:49:30 +03:00
display sec_acl structure
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
static void display_sec_acl ( SEC_ACL * acl )
2000-07-21 23:59:51 +04:00
{
2001-01-12 01:49:30 +03:00
if ( acl - > size ! = 0 & & acl - > num_aces ! = 0 ) {
int i ;
2000-07-21 23:59:51 +04:00
2001-01-12 01:49:30 +03:00
printf ( " \t \t Revision:[%d] \n " , acl - > revision ) ;
for ( i = 0 ; i < acl - > num_aces ; i + + ) {
display_sec_ace ( & acl - > ace [ i ] ) ;
}
}
2000-07-07 10:18:00 +04:00
}
2000-07-14 20:29:22 +04:00
/****************************************************************************
2001-01-12 01:49:30 +03:00
display sec_desc structure
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
static void display_sec_desc ( SEC_DESC * sec )
2000-07-14 20:29:22 +04:00
{
2001-01-12 01:49:30 +03:00
fstring sid_str ;
2000-07-14 20:29:22 +04:00
2001-01-12 01:49:30 +03:00
printf ( " \t Revision:[%d] \n " , sec - > revision ) ;
2000-07-14 20:29:22 +04:00
2001-01-12 01:49:30 +03:00
if ( sec - > off_owner_sid ) {
sid_to_string ( sid_str , sec - > owner_sid ) ;
printf ( " \t Owner SID: %s \n " , sid_str ) ;
2000-07-14 20:29:22 +04:00
}
2001-01-12 01:49:30 +03:00
if ( sec - > off_grp_sid ) {
sid_to_string ( sid_str , sec - > grp_sid ) ;
printf ( " \t Group SID: %s \n " , sid_str ) ;
2000-07-14 20:29:22 +04:00
}
2001-01-12 01:49:30 +03:00
if ( sec - > off_sacl ) display_sec_acl ( sec - > sacl ) ;
if ( sec - > off_dacl ) display_sec_acl ( sec - > dacl ) ;
2000-07-14 20:29:22 +04:00
}
/****************************************************************************
2001-01-12 01:49:30 +03:00
printer info level 0 display function
2000-07-14 20:29:22 +04:00
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
2001-01-12 01:49:30 +03:00
static void display_print_info_0 ( PRINTER_INFO_0 * i1 )
2000-07-14 20:29:22 +04:00
{
2001-01-12 01:49:30 +03:00
fstring name ;
fstring the_server ;
2000-07-14 20:29:22 +04:00
2001-01-12 01:49:30 +03:00
unistr_to_ascii ( name , i1 - > printername . buffer , sizeof ( name ) - 1 ) ;
unistr_to_ascii ( server , i1 - > servername . buffer , sizeof ( the_server ) - 1 ) ;
2000-07-14 20:29:22 +04:00
2001-01-12 01:49:30 +03:00
printf ( " \t printername:[%s] \n " , name ) ;
printf ( " \t servername:[%s] \n " , the_server ) ;
printf ( " \t cjobs:[0x%x] \n " , i1 - > cjobs ) ;
printf ( " \t total_jobs:[0x%x] \n " , i1 - > total_jobs ) ;
printf ( " \t :date: [%d]-[%d]-[%d] (%d) \n " , i1 - > year , i1 - > month ,
i1 - > day , i1 - > dayofweek ) ;
printf ( " \t :time: [%d]-[%d]-[%d]-[%d] \n " , i1 - > hour , i1 - > minute ,
i1 - > second , i1 - > milliseconds ) ;
printf ( " \t global_counter:[0x%x] \n " , i1 - > global_counter ) ;
printf ( " \t total_pages:[0x%x] \n " , i1 - > total_pages ) ;
printf ( " \t majorversion:[0x%x] \n " , i1 - > major_version ) ;
printf ( " \t buildversion:[0x%x] \n " , i1 - > build_version ) ;
printf ( " \t unknown7:[0x%x] \n " , i1 - > unknown7 ) ;
printf ( " \t unknown8:[0x%x] \n " , i1 - > unknown8 ) ;
printf ( " \t unknown9:[0x%x] \n " , i1 - > unknown9 ) ;
printf ( " \t session_counter:[0x%x] \n " , i1 - > session_counter ) ;
printf ( " \t unknown11:[0x%x] \n " , i1 - > unknown11 ) ;
printf ( " \t printer_errors:[0x%x] \n " , i1 - > printer_errors ) ;
printf ( " \t unknown13:[0x%x] \n " , i1 - > unknown13 ) ;
printf ( " \t unknown14:[0x%x] \n " , i1 - > unknown14 ) ;
printf ( " \t unknown15:[0x%x] \n " , i1 - > unknown15 ) ;
printf ( " \t unknown16:[0x%x] \n " , i1 - > unknown16 ) ;
printf ( " \t change_id:[0x%x] \n " , i1 - > change_id ) ;
printf ( " \t unknown18:[0x%x] \n " , i1 - > unknown18 ) ;
printf ( " \t status:[0x%x] \n " , i1 - > status ) ;
printf ( " \t unknown20:[0x%x] \n " , i1 - > unknown20 ) ;
printf ( " \t c_setprinter:[0x%x] \n " , i1 - > c_setprinter ) ;
printf ( " \t unknown22:[0x%x] \n " , i1 - > unknown22 ) ;
printf ( " \t unknown23:[0x%x] \n " , i1 - > unknown23 ) ;
printf ( " \t unknown24:[0x%x] \n " , i1 - > unknown24 ) ;
printf ( " \t unknown25:[0x%x] \n " , i1 - > unknown25 ) ;
printf ( " \t unknown26:[0x%x] \n " , i1 - > unknown26 ) ;
printf ( " \t unknown27:[0x%x] \n " , i1 - > unknown27 ) ;
printf ( " \t unknown28:[0x%x] \n " , i1 - > unknown28 ) ;
printf ( " \t unknown29:[0x%x] \n " , i1 - > unknown29 ) ;
2000-07-14 20:29:22 +04:00
}
/****************************************************************************
2001-01-12 01:49:30 +03:00
printer info level 1 display function
2000-07-14 20:29:22 +04:00
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
2001-01-12 01:49:30 +03:00
static void display_print_info_1 ( PRINTER_INFO_1 * i1 )
2000-07-14 20:29:22 +04:00
{
2001-01-12 01:49:30 +03:00
fstring desc ;
fstring name ;
fstring comm ;
unistr_to_ascii ( desc , i1 - > description . buffer , sizeof ( desc ) - 1 ) ;
unistr_to_ascii ( name , i1 - > name . buffer , sizeof ( name ) - 1 ) ;
unistr_to_ascii ( comm , i1 - > comment . buffer , sizeof ( comm ) - 1 ) ;
printf ( " \t flags:[0x%x] \n " , i1 - > flags ) ;
printf ( " \t name:[%s] \n " , name ) ;
printf ( " \t description:[%s] \n " , desc ) ;
printf ( " \t comment:[%s] \n \n " , comm ) ;
2000-07-14 20:29:22 +04:00
}
/****************************************************************************
2001-01-12 01:49:30 +03:00
printer info level 2 display function
2000-07-14 20:29:22 +04:00
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
2001-01-12 01:49:30 +03:00
static void display_print_info_2 ( PRINTER_INFO_2 * i2 )
2000-07-14 20:29:22 +04:00
{
2001-01-12 01:49:30 +03:00
fstring servername ;
fstring printername ;
fstring sharename ;
fstring portname ;
fstring drivername ;
fstring comment ;
fstring location ;
fstring sepfile ;
fstring printprocessor ;
fstring datatype ;
fstring parameters ;
unistr_to_ascii ( servername , i2 - > servername . buffer ,
sizeof ( servername ) - 1 ) ;
unistr_to_ascii ( printername , i2 - > printername . buffer ,
sizeof ( printername ) - 1 ) ;
unistr_to_ascii ( sharename , i2 - > sharename . buffer ,
sizeof ( sharename ) - 1 ) ;
unistr_to_ascii ( portname , i2 - > portname . buffer , sizeof ( portname ) - 1 ) ;
unistr_to_ascii ( drivername , i2 - > drivername . buffer ,
sizeof ( drivername ) - 1 ) ;
unistr_to_ascii ( comment , i2 - > comment . buffer , sizeof ( comment ) - 1 ) ;
unistr_to_ascii ( location , i2 - > location . buffer , sizeof ( location ) - 1 ) ;
unistr_to_ascii ( sepfile , i2 - > sepfile . buffer , sizeof ( sepfile ) - 1 ) ;
unistr_to_ascii ( printprocessor , i2 - > printprocessor . buffer ,
sizeof ( printprocessor ) - 1 ) ;
unistr_to_ascii ( datatype , i2 - > datatype . buffer , sizeof ( datatype ) - 1 ) ;
unistr_to_ascii ( parameters , i2 - > parameters . buffer ,
sizeof ( parameters ) - 1 ) ;
printf ( " \t servername:[%s] \n " , servername ) ;
printf ( " \t printername:[%s] \n " , printername ) ;
printf ( " \t sharename:[%s] \n " , sharename ) ;
printf ( " \t portname:[%s] \n " , portname ) ;
printf ( " \t drivername:[%s] \n " , drivername ) ;
printf ( " \t comment:[%s] \n " , comment ) ;
printf ( " \t location:[%s] \n " , location ) ;
printf ( " \t sepfile:[%s] \n " , sepfile ) ;
printf ( " \t printprocessor:[%s] \n " , printprocessor ) ;
printf ( " \t datatype:[%s] \n " , datatype ) ;
printf ( " \t parameters:[%s] \n " , parameters ) ;
printf ( " \t attributes:[0x%x] \n " , i2 - > attributes ) ;
printf ( " \t priority:[0x%x] \n " , i2 - > priority ) ;
printf ( " \t defaultpriority:[0x%x] \n " , i2 - > defaultpriority ) ;
printf ( " \t starttime:[0x%x] \n " , i2 - > starttime ) ;
printf ( " \t untiltime:[0x%x] \n " , i2 - > untiltime ) ;
printf ( " \t status:[0x%x] \n " , i2 - > status ) ;
printf ( " \t cjobs:[0x%x] \n " , i2 - > cjobs ) ;
printf ( " \t averageppm:[0x%x] \n " , i2 - > averageppm ) ;
if ( i2 - > secdesc ) display_sec_desc ( i2 - > secdesc ) ;
2000-07-14 20:29:22 +04:00
}
/****************************************************************************
2001-01-12 01:49:30 +03:00
printer info level 3 display function
2000-07-14 20:29:22 +04:00
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
2001-01-12 01:49:30 +03:00
static void display_print_info_3 ( PRINTER_INFO_3 * i3 )
2000-07-14 20:29:22 +04:00
{
2001-01-12 01:49:30 +03:00
printf ( " \t flags:[0x%x] \n " , i3 - > flags ) ;
2000-07-14 20:29:22 +04:00
2001-01-12 01:49:30 +03:00
display_sec_desc ( i3 - > secdesc ) ;
2000-07-14 20:29:22 +04:00
}
2001-01-12 01:49:30 +03:00
/* Enumerate printers */
static uint32 cmd_spoolss_enum_printers ( int argc , char * * argv )
2000-07-14 20:29:22 +04:00
{
2001-01-12 01:49:30 +03:00
uint32 result = NT_STATUS_UNSUCCESSFUL , info_level = 1 ;
struct cli_state cli ;
struct ntuser_creds creds ;
PRINTER_INFO_CTR ctr ;
int returned ;
if ( argc > 2 ) {
printf ( " Usage: enumprinters \n " ) ;
return NT_STATUS_NOPROBLEMO ;
}
if ( argc = = 2 ) {
info_level = atoi ( argv [ 1 ] ) ;
}
/* Initialise RPC connection */
2000-07-14 20:29:22 +04:00
2001-01-12 01:49:30 +03:00
ZERO_STRUCT ( cli ) ;
init_rpcclient_creds ( & creds ) ;
2000-07-14 20:29:22 +04:00
2001-01-12 01:49:30 +03:00
if ( cli_spoolss_initialise ( & cli , server , & creds ) = = NULL ) {
goto done ;
}
/* Enumerate printers */
ZERO_STRUCT ( ctr ) ;
2000-07-14 20:29:22 +04:00
2001-01-12 01:49:30 +03:00
result = cli_spoolss_enum_printers ( & cli , PRINTER_ENUM_LOCAL ,
info_level , & returned , & ctr ) ;
2000-07-14 20:29:22 +04:00
2001-01-12 01:49:30 +03:00
if ( result = = NT_STATUS_NOPROBLEMO ) {
switch ( info_level ) {
case 0 :
display_print_info_0 ( ctr . printers_0 ) ;
break ;
case 1 :
display_print_info_1 ( ctr . printers_1 ) ;
break ;
case 2 :
display_print_info_2 ( ctr . printers_2 ) ;
break ;
case 3 :
display_print_info_3 ( ctr . printers_3 ) ;
break ;
default :
printf ( " unknown info level %d \n " , info_level ) ;
break ;
}
}
done :
return result ;
2000-07-14 20:29:22 +04:00
}
/****************************************************************************
2001-01-12 01:49:30 +03:00
port info level 1 display function
2000-07-14 20:29:22 +04:00
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
2001-01-12 01:49:30 +03:00
static void display_port_info_1 ( PORT_INFO_1 * i1 )
2000-07-14 20:29:22 +04:00
{
2001-01-12 01:49:30 +03:00
fstring buffer ;
unistr_to_ascii ( buffer , i1 - > port_name . buffer , sizeof ( buffer ) - 1 ) ;
printf ( " \t Port Name: \t [%s] \n " , buffer ) ;
}
2000-07-14 20:29:22 +04:00
2001-01-12 01:49:30 +03:00
/****************************************************************************
port info level 2 display function
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
static void display_port_info_2 ( PORT_INFO_2 * i2 )
{
fstring buffer ;
unistr_to_ascii ( buffer , i2 - > port_name . buffer , sizeof ( buffer ) - 1 ) ;
printf ( " \t Port Name: \t [%s] \n " , buffer ) ;
unistr_to_ascii ( buffer , i2 - > monitor_name . buffer , sizeof ( buffer ) - 1 ) ;
printf ( " \t Monitor Name: \t [%s] \n " , buffer ) ;
unistr_to_ascii ( buffer , i2 - > description . buffer , sizeof ( buffer ) - 1 ) ;
printf ( " \t Description: \t [%s] \n " , buffer ) ;
printf ( " \t Port Type: \t [%d] \n " , i2 - > port_type ) ;
printf ( " \t Reserved: \t [%d] \n " , i2 - > reserved ) ;
printf ( " \n " ) ;
}
2000-07-14 20:29:22 +04:00
2001-01-12 01:49:30 +03:00
/* Enumerate ports */
2000-07-14 20:29:22 +04:00
2001-01-12 01:49:30 +03:00
static uint32 cmd_spoolss_enum_ports ( int argc , char * * argv )
{
uint32 result = NT_STATUS_UNSUCCESSFUL , info_level = 1 ;
struct cli_state cli ;
struct ntuser_creds creds ;
PORT_INFO_CTR ctr ;
int returned ;
if ( argc = = 1 | | argc < 2 ) {
printf ( " Usage: enumports [level] \n " ) ;
return NT_STATUS_NOPROBLEMO ;
}
2000-07-14 20:29:22 +04:00
2001-01-12 01:49:30 +03:00
if ( argc = = 2 ) {
info_level = atoi ( argv [ 1 ] ) ;
}
2000-07-14 20:29:22 +04:00
2001-01-12 01:49:30 +03:00
/* Initialise RPC connection */
2000-07-14 20:29:22 +04:00
2001-01-12 01:49:30 +03:00
ZERO_STRUCT ( cli ) ;
init_rpcclient_creds ( & creds ) ;
2000-07-14 20:29:22 +04:00
2001-01-12 01:49:30 +03:00
if ( cli_spoolss_initialise ( & cli , server , & creds ) = = NULL ) {
goto done ;
}
2000-07-14 20:29:22 +04:00
2001-01-12 01:49:30 +03:00
/* Enumerate printers */
2000-07-14 20:29:22 +04:00
2001-01-12 01:49:30 +03:00
ZERO_STRUCT ( ctr ) ;
result = cli_spoolss_enum_ports ( & cli , info_level , & returned , & ctr ) ;
if ( result = = NT_STATUS_NOPROBLEMO ) {
int i ;
for ( i = 0 ; i < returned ; i + + ) {
switch ( info_level ) {
case 1 :
display_port_info_1 ( & ctr . port . info_1 [ i ] ) ;
2000-07-26 01:07:46 +04:00
break ;
2001-01-12 01:49:30 +03:00
case 2 :
display_port_info_2 ( & ctr . port . info_2 [ i ] ) ;
break ;
default :
printf ( " unknown info level %s \n " , info_level ) ;
break ;
}
2000-07-26 01:07:46 +04:00
}
}
2001-01-12 01:49:30 +03:00
done :
return result ;
2000-07-26 01:07:46 +04:00
}
2000-08-08 10:57:48 +04:00
2001-01-12 01:49:30 +03:00
/* Get printer information */
static uint32 cmd_spoolss_getprinter ( int argc , char * * argv )
2000-08-08 10:57:48 +04:00
{
2001-01-12 01:49:30 +03:00
struct cli_state cli ;
POLICY_HND pol ;
uint32 result , info_level = 1 ;
BOOL opened_hnd = False ;
struct ntuser_creds creds ;
PRINTER_INFO_CTR ctr ;
int * returned ;
if ( argc = = 1 | | argc > 3 ) {
printf ( " Usage: %s printername [level] \n " , argv [ 0 ] ) ;
return NT_STATUS_NOPROBLEMO ;
2000-08-08 10:57:48 +04:00
}
2001-01-12 01:49:30 +03:00
/* Initialise RPC connection */
2000-08-10 00:14:29 +04:00
2001-01-12 01:49:30 +03:00
ZERO_STRUCT ( cli ) ;
init_rpcclient_creds ( & creds ) ;
2000-08-10 00:14:29 +04:00
2001-01-12 01:49:30 +03:00
if ( cli_spoolss_initialise ( & cli , server , & creds ) = = NULL ) {
goto done ;
}
2000-08-10 00:14:29 +04:00
2001-01-12 01:49:30 +03:00
/* Open a printer handle */
2000-08-10 00:14:29 +04:00
2001-01-12 01:49:30 +03:00
if ( argc = = 3 ) {
info_level = atoi ( argv [ 2 ] ) ;
}
2000-08-10 00:14:29 +04:00
2001-01-12 01:49:30 +03:00
if ( ( result = cli_spoolss_open_printer_ex (
2001-01-12 05:58:29 +03:00
& cli , argv [ 1 ] , " " , MAXIMUM_ALLOWED_ACCESS , global_myname ,
2001-01-12 01:49:30 +03:00
username , & pol ) ) ! = NT_STATUS_NOPROBLEMO ) {
goto done ;
2000-08-08 10:57:48 +04:00
}
2001-01-12 01:49:30 +03:00
opened_hnd = True ;
/* Get printer info */
if ( ( result = cli_spoolss_getprinter ( & cli , & pol , info_level , & ctr ) )
! = NT_STATUS_NOPROBLEMO ) {
goto done ;
2000-08-08 10:57:48 +04:00
}
2001-01-12 01:49:30 +03:00
/* Display printer info */
switch ( info_level ) {
case 0 :
display_print_info_0 ( ctr . printers_0 ) ;
break ;
case 1 :
display_print_info_1 ( ctr . printers_1 ) ;
break ;
case 2 :
display_print_info_2 ( ctr . printers_2 ) ;
break ;
case 3 :
display_print_info_3 ( ctr . printers_3 ) ;
break ;
default :
printf ( " unknown info level %d \n " , info_level ) ;
break ;
2000-08-08 10:57:48 +04:00
}
2001-01-12 01:49:30 +03:00
done :
if ( opened_hnd ) cli_spoolss_closeprinter ( & cli , & pol ) ;
cli_spoolss_shutdown ( & cli ) ;
2000-08-08 10:57:48 +04:00
2001-01-12 01:49:30 +03:00
return result ;
2000-08-08 10:57:48 +04:00
}
2000-08-10 00:14:29 +04:00
2001-01-12 01:49:30 +03:00
/* List of commands exported by this module */
struct cmd_set spoolss_commands [ ] = {
2000-08-10 00:14:29 +04:00
2001-01-12 01:49:30 +03:00
{ " enumprinters " , cmd_spoolss_enum_printers , " Enumerate printers " } ,
{ " enumports " , cmd_spoolss_enum_ports , " Enumerate printer ports " } ,
{ " getprinter " , cmd_spoolss_getprinter , " Get printer info " } ,
2000-08-10 00:14:29 +04:00
2001-01-12 01:49:30 +03:00
{ NULL , NULL , NULL }
} ;