📄 cmd_spoolss.c
字号:
/* Unix SMB/CIFS implementation. RPC pipe client Copyright (C) Gerald Carter 2001-2005 Copyright (C) Tim Potter 2000 Copyright (C) Andrew Tridgell 1992-1999 Copyright (C) Luke Kenneth Casson Leighton 1996-1999 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 02139, USA.*/#include "includes.h"#include "rpcclient.h"struct table_node { const char *long_archi; const char *short_archi; int version;}; /* The version int is used by getdrivers. Note that all architecture strings that support mutliple versions must be grouped together since enumdrivers uses this property to prevent issuing multiple enumdriver calls for the same arch */static const struct table_node archi_table[]= { {"Windows 4.0", "WIN40", 0 }, {"Windows NT x86", "W32X86", 2 }, {"Windows NT x86", "W32X86", 3 }, {"Windows NT R4000", "W32MIPS", 2 }, {"Windows NT Alpha_AXP", "W32ALPHA", 2 }, {"Windows NT PowerPC", "W32PPC", 2 }, {"Windows IA64", "IA64", 3 }, {"Windows x64", "x64", 3 }, {NULL, "", -1 }};/** * @file * * rpcclient module for SPOOLSS rpc pipe. * * This generally just parses and checks command lines, and then calls * a cli_spoolss function. **//**************************************************************************** function to do the mapping between the long architecture name and the short one.****************************************************************************/static const char *cmd_spoolss_get_short_archi(const char *long_archi){ int i=-1; DEBUG(107,("Getting architecture dependant directory\n")); do { i++; } while ( (archi_table[i].long_archi!=NULL ) && StrCaseCmp(long_archi, archi_table[i].long_archi) ); if (archi_table[i].long_archi==NULL) { DEBUGADD(10,("Unknown architecture [%s] !\n", long_archi)); return NULL; } /* this might be client code - but shouldn't this be an fstrcpy etc? */ DEBUGADD(108,("index: [%d]\n", i)); DEBUGADD(108,("long architecture: [%s]\n", archi_table[i].long_archi)); DEBUGADD(108,("short architecture: [%s]\n", archi_table[i].short_archi)); return archi_table[i].short_archi;}/********************************************************************************************************************************************************/static WERROR cmd_spoolss_open_printer_ex(struct rpc_pipe_client *cli, TALLOC_CTX *mem_ctx, int argc, const char **argv){ WERROR werror; fstring printername; fstring servername, user; POLICY_HND hnd; if (argc != 2) { printf("Usage: %s <printername>\n", argv[0]); return WERR_OK; } if (!cli) return WERR_GENERAL_FAILURE; slprintf(servername, sizeof(servername)-1, "\\\\%s", cli->cli->desthost); strupper_m(servername); fstrcpy(user, cli->user_name); fstrcpy(printername, argv[1]); /* Open the printer handle */ werror = rpccli_spoolss_open_printer_ex(cli, mem_ctx, printername, "", PRINTER_ALL_ACCESS, servername, user, &hnd); if (W_ERROR_IS_OK(werror)) { printf("Printer %s opened successfully\n", printername); werror = rpccli_spoolss_close_printer(cli, mem_ctx, &hnd); if (!W_ERROR_IS_OK(werror)) { printf("Error closing printer handle! (%s)\n", get_dos_error_msg(werror)); } } return werror;}/********************************************************************************************************************************************************/static void display_print_info_0(PRINTER_INFO_0 *i0){ fstring name = ""; fstring servername = ""; if (!i0) return; rpcstr_pull(name, i0->printername.buffer, sizeof(name), -1, STR_TERMINATE); rpcstr_pull(servername, i0->servername.buffer, sizeof(servername), -1,STR_TERMINATE); printf("\tprintername:[%s]\n", name); printf("\tservername:[%s]\n", servername); printf("\tcjobs:[0x%x]\n", i0->cjobs); printf("\ttotal_jobs:[0x%x]\n", i0->total_jobs); printf("\t:date: [%d]-[%d]-[%d] (%d)\n", i0->year, i0->month, i0->day, i0->dayofweek); printf("\t:time: [%d]-[%d]-[%d]-[%d]\n", i0->hour, i0->minute, i0->second, i0->milliseconds); printf("\tglobal_counter:[0x%x]\n", i0->global_counter); printf("\ttotal_pages:[0x%x]\n", i0->total_pages); printf("\tmajorversion:[0x%x]\n", i0->major_version); printf("\tbuildversion:[0x%x]\n", i0->build_version); printf("\tunknown7:[0x%x]\n", i0->unknown7); printf("\tunknown8:[0x%x]\n", i0->unknown8); printf("\tunknown9:[0x%x]\n", i0->unknown9); printf("\tsession_counter:[0x%x]\n", i0->session_counter); printf("\tunknown11:[0x%x]\n", i0->unknown11); printf("\tprinter_errors:[0x%x]\n", i0->printer_errors); printf("\tunknown13:[0x%x]\n", i0->unknown13); printf("\tunknown14:[0x%x]\n", i0->unknown14); printf("\tunknown15:[0x%x]\n", i0->unknown15); printf("\tunknown16:[0x%x]\n", i0->unknown16); printf("\tchange_id:[0x%x]\n", i0->change_id); printf("\tunknown18:[0x%x]\n", i0->unknown18); printf("\tstatus:[0x%x]\n", i0->status); printf("\tunknown20:[0x%x]\n", i0->unknown20); printf("\tc_setprinter:[0x%x]\n", i0->c_setprinter); printf("\tunknown22:[0x%x]\n", i0->unknown22); printf("\tunknown23:[0x%x]\n", i0->unknown23); printf("\tunknown24:[0x%x]\n", i0->unknown24); printf("\tunknown25:[0x%x]\n", i0->unknown25); printf("\tunknown26:[0x%x]\n", i0->unknown26); printf("\tunknown27:[0x%x]\n", i0->unknown27); printf("\tunknown28:[0x%x]\n", i0->unknown28); printf("\tunknown29:[0x%x]\n", i0->unknown29); printf("\n");}/********************************************************************************************************************************************************/static void display_print_info_1(PRINTER_INFO_1 *i1){ fstring desc = ""; fstring name = ""; fstring comm = ""; rpcstr_pull(desc, i1->description.buffer, sizeof(desc), -1, STR_TERMINATE); rpcstr_pull(name, i1->name.buffer, sizeof(name), -1, STR_TERMINATE); rpcstr_pull(comm, i1->comment.buffer, sizeof(comm), -1, STR_TERMINATE); printf("\tflags:[0x%x]\n", i1->flags); printf("\tname:[%s]\n", name); printf("\tdescription:[%s]\n", desc); printf("\tcomment:[%s]\n", comm); printf("\n");}/********************************************************************************************************************************************************/static void display_print_info_2(PRINTER_INFO_2 *i2){ fstring servername = ""; fstring printername = ""; fstring sharename = ""; fstring portname = ""; fstring drivername = ""; fstring comment = ""; fstring location = ""; fstring sepfile = ""; fstring printprocessor = ""; fstring datatype = ""; fstring parameters = ""; rpcstr_pull(servername, i2->servername.buffer,sizeof(servername), -1, STR_TERMINATE); rpcstr_pull(printername, i2->printername.buffer,sizeof(printername), -1, STR_TERMINATE); rpcstr_pull(sharename, i2->sharename.buffer,sizeof(sharename), -1, STR_TERMINATE); rpcstr_pull(portname, i2->portname.buffer,sizeof(portname), -1, STR_TERMINATE); rpcstr_pull(drivername, i2->drivername.buffer,sizeof(drivername), -1, STR_TERMINATE); rpcstr_pull(comment, i2->comment.buffer,sizeof(comment), -1, STR_TERMINATE); rpcstr_pull(location, i2->location.buffer,sizeof(location), -1, STR_TERMINATE); rpcstr_pull(sepfile, i2->sepfile.buffer,sizeof(sepfile), -1, STR_TERMINATE); rpcstr_pull(printprocessor, i2->printprocessor.buffer,sizeof(printprocessor), -1, STR_TERMINATE); rpcstr_pull(datatype, i2->datatype.buffer,sizeof(datatype), -1, STR_TERMINATE); rpcstr_pull(parameters, i2->parameters.buffer,sizeof(parameters), -1, STR_TERMINATE); printf("\tservername:[%s]\n", servername); printf("\tprintername:[%s]\n", printername); printf("\tsharename:[%s]\n", sharename); printf("\tportname:[%s]\n", portname); printf("\tdrivername:[%s]\n", drivername); printf("\tcomment:[%s]\n", comment); printf("\tlocation:[%s]\n", location); printf("\tsepfile:[%s]\n", sepfile); printf("\tprintprocessor:[%s]\n", printprocessor); printf("\tdatatype:[%s]\n", datatype); printf("\tparameters:[%s]\n", parameters); printf("\tattributes:[0x%x]\n", i2->attributes); printf("\tpriority:[0x%x]\n", i2->priority); printf("\tdefaultpriority:[0x%x]\n", i2->defaultpriority); printf("\tstarttime:[0x%x]\n", i2->starttime); printf("\tuntiltime:[0x%x]\n", i2->untiltime); printf("\tstatus:[0x%x]\n", i2->status); printf("\tcjobs:[0x%x]\n", i2->cjobs); printf("\taverageppm:[0x%x]\n", i2->averageppm); if (i2->secdesc) display_sec_desc(i2->secdesc); printf("\n");}/********************************************************************************************************************************************************/static void display_print_info_3(PRINTER_INFO_3 *i3){ printf("\tflags:[0x%x]\n", i3->flags); display_sec_desc(i3->secdesc); printf("\n");}/********************************************************************************************************************************************************/static void display_print_info_7(PRINTER_INFO_7 *i7){ fstring guid = ""; rpcstr_pull(guid, i7->guid.buffer,sizeof(guid), -1, STR_TERMINATE); printf("\tguid:[%s]\n", guid); printf("\taction:[0x%x]\n", i7->action);}/********************************************************************************************************************************************************/static WERROR cmd_spoolss_enum_printers(struct rpc_pipe_client *cli, TALLOC_CTX *mem_ctx, int argc, const char **argv){ WERROR result; uint32 info_level = 1; PRINTER_INFO_CTR ctr; uint32 i = 0, num_printers; fstring name; if (argc > 3) { printf("Usage: %s [level] [name]\n", argv[0]); return WERR_OK; } if (argc >= 2) info_level = atoi(argv[1]); if (argc == 3) fstrcpy(name, argv[2]); else { slprintf(name, sizeof(name)-1, "\\\\%s", cli->cli->desthost); strupper_m(name); } ZERO_STRUCT(ctr); result = rpccli_spoolss_enum_printers(cli, mem_ctx, name, PRINTER_ENUM_LOCAL, info_level, &num_printers, &ctr); if (W_ERROR_IS_OK(result)) { if (!num_printers) { printf ("No printers returned.\n"); goto done; } for (i = 0; i < num_printers; i++) { switch(info_level) { case 0: display_print_info_0(&ctr.printers_0[i]); break; case 1: display_print_info_1(&ctr.printers_1[i]); break; case 2: display_print_info_2(&ctr.printers_2[i]); break; case 3: display_print_info_3(&ctr.printers_3[i]); break; default: printf("unknown info level %d\n", info_level); goto done; } } } done: return result;}/********************************************************************************************************************************************************/static void display_port_info_1(PORT_INFO_1 *i1){ fstring buffer; rpcstr_pull(buffer, i1->port_name.buffer, sizeof(buffer), -1, STR_TERMINATE); printf("\tPort Name:\t[%s]\n", buffer);}/********************************************************************************************************************************************************/static void display_port_info_2(PORT_INFO_2 *i2){ fstring buffer; rpcstr_pull(buffer, i2->port_name.buffer, sizeof(buffer), -1, STR_TERMINATE); printf("\tPort Name:\t[%s]\n", buffer); rpcstr_pull(buffer, i2->monitor_name.buffer, sizeof(buffer), -1, STR_TERMINATE); printf("\tMonitor Name:\t[%s]\n", buffer); rpcstr_pull(buffer, i2->description.buffer, sizeof(buffer), -1, STR_TERMINATE); printf("\tDescription:\t[%s]\n", buffer); printf("\tPort Type:\t" ); if ( i2->port_type ) { int comma = 0; /* hack */ printf( "[" ); if ( i2->port_type & PORT_TYPE_READ ) { printf( "Read" ); comma = 1; } if ( i2->port_type & PORT_TYPE_WRITE ) { printf( "%sWrite", comma ? ", " : "" ); comma = 1; } /* These two have slightly different interpretations on 95/98/ME but I'm disregarding that for now */ if ( i2->port_type & PORT_TYPE_REDIRECTED ) { printf( "%sRedirected", comma ? ", " : "" ); comma = 1; } if ( i2->port_type & PORT_TYPE_NET_ATTACHED ) { printf( "%sNet-Attached", comma ? ", " : "" ); } printf( "]\n" ); } else { printf( "[Unset]\n" ); } printf("\tReserved:\t[%d]\n", i2->reserved); printf("\n");}/********************************************************************************************************************************************************/static WERROR cmd_spoolss_enum_ports(struct rpc_pipe_client *cli, TALLOC_CTX *mem_ctx, int argc, const char **argv){ WERROR result; uint32 info_level = 1; PORT_INFO_CTR ctr; uint32 returned; if (argc > 2) { printf("Usage: %s [level]\n", argv[0]); return WERR_OK; } if (argc == 2) info_level = atoi(argv[1]); /* Enumerate ports */ ZERO_STRUCT(ctr); result = rpccli_spoolss_enum_ports(cli, mem_ctx, info_level, &returned, &ctr); if (W_ERROR_IS_OK(result)) { int i; for (i = 0; i < returned; i++) { switch (info_level) { case 1: display_port_info_1(&ctr.port.info_1[i]); break; case 2: display_port_info_2(&ctr.port.info_2[i]); break; default: printf("unknown info level %d\n", info_level); break; } } } return result;}/********************************************************************************************************************************************************/static WERROR cmd_spoolss_setprinter(struct rpc_pipe_client *cli, TALLOC_CTX *mem_ctx, int argc, const char **argv){ POLICY_HND pol; WERROR result; uint32 info_level = 2; BOOL opened_hnd = False; PRINTER_INFO_CTR ctr; fstring printername, servername, user, comment; if (argc == 1 || argc > 3) { printf("Usage: %s printername comment\n", argv[0]); return WERR_OK; } /* Open a printer handle */ if (argc == 3) { fstrcpy(comment, argv[2]);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -