2 Unix SMB/CIFS implementation.
5 Copyright (C) Gerald Carter 2001
6 Copyright (C) Tim Potter 2000
7 Copyright (C) Andrew Tridgell 1992-1999
8 Copyright (C) Luke Kenneth Casson Leighton 1996-1999
10 This program is free software; you can redistribute it and/or modify
11 it under the terms of the GNU General Public License as published by
12 the Free Software Foundation; either version 2 of the License, or
13 (at your option) any later version.
15 This program is distributed in the hope that it will be useful,
16 but WITHOUT ANY WARRANTY; without even the implied warranty of
17 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 GNU General Public License for more details.
20 You should have received a copy of the GNU General Public License
21 along with this program; if not, write to the Free Software
22 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
26 #include "rpcclient.h"
29 const char *long_archi
;
30 const char *short_archi
;
34 static const struct table_node archi_table
[]= {
36 {"Windows 4.0", "WIN40", 0 },
37 {"Windows NT x86", "W32X86", 2 },
38 {"Windows NT x86", "W32X86", 3 },
39 {"Windows NT R4000", "W32MIPS", 2 },
40 {"Windows NT Alpha_AXP", "W32ALPHA", 2 },
41 {"Windows NT PowerPC", "W32PPC", 2 },
48 * rpcclient module for SPOOLSS rpc pipe.
50 * This generally just parses and checks command lines, and then calls
51 * a cli_spoolss function.
54 /****************************************************************************
55 function to do the mapping between the long architecture name and
57 ****************************************************************************/
58 static const char *cmd_spoolss_get_short_archi(const char *long_archi
)
62 DEBUG(107,("Getting architecture dependant directory\n"));
65 } while ( (archi_table
[i
].long_archi
!=NULL
) &&
66 StrCaseCmp(long_archi
, archi_table
[i
].long_archi
) );
68 if (archi_table
[i
].long_archi
==NULL
) {
69 DEBUGADD(10,("Unknown architecture [%s] !\n", long_archi
));
73 /* this might be client code - but shouldn't this be an fstrcpy etc? */
76 DEBUGADD(108,("index: [%d]\n", i
));
77 DEBUGADD(108,("long architecture: [%s]\n", archi_table
[i
].long_archi
));
78 DEBUGADD(108,("short architecture: [%s]\n", archi_table
[i
].short_archi
));
80 return archi_table
[i
].short_archi
;
84 /**********************************************************************
85 * dummy function -- placeholder
87 static WERROR
cmd_spoolss_not_implemented(struct cli_state
*cli
,
89 int argc
, const char **argv
)
91 printf ("(*) This command is not currently implemented.\n");
96 /***********************************************************************
97 * Get printer information
99 static WERROR
cmd_spoolss_open_printer_ex(struct cli_state
*cli
,
101 int argc
, const char **argv
)
105 fstring servername
, user
;
109 printf("Usage: %s <printername>\n", argv
[0]);
114 return WERR_GENERAL_FAILURE
;
116 slprintf(servername
, sizeof(servername
)-1, "\\\\%s", cli
->desthost
);
117 strupper_m(servername
);
118 fstrcpy(user
, cli
->user_name
);
119 fstrcpy(printername
, argv
[1]);
121 /* Open the printer handle */
123 werror
= cli_spoolss_open_printer_ex(cli
, mem_ctx
, printername
,
124 "", PRINTER_ALL_ACCESS
,
125 servername
, user
, &hnd
);
127 if (W_ERROR_IS_OK(werror
)) {
128 printf("Printer %s opened successfully\n", printername
);
129 werror
= cli_spoolss_close_printer(cli
, mem_ctx
, &hnd
);
131 if (!W_ERROR_IS_OK(werror
)) {
132 printf("Error closing printer handle! (%s)\n",
133 get_dos_error_msg(werror
));
141 /****************************************************************************
142 printer info level 0 display function
143 ****************************************************************************/
144 static void display_print_info_0(PRINTER_INFO_0
*i0
)
147 fstring servername
= "";
152 rpcstr_pull(name
, i0
->printername
.buffer
, sizeof(name
), -1, STR_TERMINATE
);
154 rpcstr_pull(servername
, i0
->servername
.buffer
, sizeof(servername
), -1,STR_TERMINATE
);
156 printf("\tprintername:[%s]\n", name
);
157 printf("\tservername:[%s]\n", servername
);
158 printf("\tcjobs:[0x%x]\n", i0
->cjobs
);
159 printf("\ttotal_jobs:[0x%x]\n", i0
->total_jobs
);
161 printf("\t:date: [%d]-[%d]-[%d] (%d)\n", i0
->year
, i0
->month
,
162 i0
->day
, i0
->dayofweek
);
163 printf("\t:time: [%d]-[%d]-[%d]-[%d]\n", i0
->hour
, i0
->minute
,
164 i0
->second
, i0
->milliseconds
);
166 printf("\tglobal_counter:[0x%x]\n", i0
->global_counter
);
167 printf("\ttotal_pages:[0x%x]\n", i0
->total_pages
);
169 printf("\tmajorversion:[0x%x]\n", i0
->major_version
);
170 printf("\tbuildversion:[0x%x]\n", i0
->build_version
);
172 printf("\tunknown7:[0x%x]\n", i0
->unknown7
);
173 printf("\tunknown8:[0x%x]\n", i0
->unknown8
);
174 printf("\tunknown9:[0x%x]\n", i0
->unknown9
);
175 printf("\tsession_counter:[0x%x]\n", i0
->session_counter
);
176 printf("\tunknown11:[0x%x]\n", i0
->unknown11
);
177 printf("\tprinter_errors:[0x%x]\n", i0
->printer_errors
);
178 printf("\tunknown13:[0x%x]\n", i0
->unknown13
);
179 printf("\tunknown14:[0x%x]\n", i0
->unknown14
);
180 printf("\tunknown15:[0x%x]\n", i0
->unknown15
);
181 printf("\tunknown16:[0x%x]\n", i0
->unknown16
);
182 printf("\tchange_id:[0x%x]\n", i0
->change_id
);
183 printf("\tunknown18:[0x%x]\n", i0
->unknown18
);
184 printf("\tstatus:[0x%x]\n", i0
->status
);
185 printf("\tunknown20:[0x%x]\n", i0
->unknown20
);
186 printf("\tc_setprinter:[0x%x]\n", i0
->c_setprinter
);
187 printf("\tunknown22:[0x%x]\n", i0
->unknown22
);
188 printf("\tunknown23:[0x%x]\n", i0
->unknown23
);
189 printf("\tunknown24:[0x%x]\n", i0
->unknown24
);
190 printf("\tunknown25:[0x%x]\n", i0
->unknown25
);
191 printf("\tunknown26:[0x%x]\n", i0
->unknown26
);
192 printf("\tunknown27:[0x%x]\n", i0
->unknown27
);
193 printf("\tunknown28:[0x%x]\n", i0
->unknown28
);
194 printf("\tunknown29:[0x%x]\n", i0
->unknown29
);
199 /****************************************************************************
200 printer info level 1 display function
201 ****************************************************************************/
202 static void display_print_info_1(PRINTER_INFO_1
*i1
)
208 rpcstr_pull(desc
, i1
->description
.buffer
, sizeof(desc
), -1,
211 rpcstr_pull(name
, i1
->name
.buffer
, sizeof(name
), -1, STR_TERMINATE
);
212 rpcstr_pull(comm
, i1
->comment
.buffer
, sizeof(comm
), -1, STR_TERMINATE
);
214 printf("\tflags:[0x%x]\n", i1
->flags
);
215 printf("\tname:[%s]\n", name
);
216 printf("\tdescription:[%s]\n", desc
);
217 printf("\tcomment:[%s]\n", comm
);
222 /****************************************************************************
223 printer info level 2 display function
224 ****************************************************************************/
225 static void display_print_info_2(PRINTER_INFO_2
*i2
)
227 fstring servername
= "";
228 fstring printername
= "";
229 fstring sharename
= "";
230 fstring portname
= "";
231 fstring drivername
= "";
232 fstring comment
= "";
233 fstring location
= "";
234 fstring sepfile
= "";
235 fstring printprocessor
= "";
236 fstring datatype
= "";
237 fstring parameters
= "";
239 rpcstr_pull(servername
, i2
->servername
.buffer
,sizeof(servername
), -1, STR_TERMINATE
);
241 rpcstr_pull(printername
, i2
->printername
.buffer
,sizeof(printername
), -1, STR_TERMINATE
);
243 rpcstr_pull(sharename
, i2
->sharename
.buffer
,sizeof(sharename
), -1, STR_TERMINATE
);
245 rpcstr_pull(portname
, i2
->portname
.buffer
,sizeof(portname
), -1, STR_TERMINATE
);
247 rpcstr_pull(drivername
, i2
->drivername
.buffer
,sizeof(drivername
), -1, STR_TERMINATE
);
249 rpcstr_pull(comment
, i2
->comment
.buffer
,sizeof(comment
), -1, STR_TERMINATE
);
251 rpcstr_pull(location
, i2
->location
.buffer
,sizeof(location
), -1, STR_TERMINATE
);
253 rpcstr_pull(sepfile
, i2
->sepfile
.buffer
,sizeof(sepfile
), -1, STR_TERMINATE
);
255 rpcstr_pull(printprocessor
, i2
->printprocessor
.buffer
,sizeof(printprocessor
), -1, STR_TERMINATE
);
257 rpcstr_pull(datatype
, i2
->datatype
.buffer
,sizeof(datatype
), -1, STR_TERMINATE
);
259 rpcstr_pull(parameters
, i2
->parameters
.buffer
,sizeof(parameters
), -1, STR_TERMINATE
);
261 printf("\tservername:[%s]\n", servername
);
262 printf("\tprintername:[%s]\n", printername
);
263 printf("\tsharename:[%s]\n", sharename
);
264 printf("\tportname:[%s]\n", portname
);
265 printf("\tdrivername:[%s]\n", drivername
);
266 printf("\tcomment:[%s]\n", comment
);
267 printf("\tlocation:[%s]\n", location
);
268 printf("\tsepfile:[%s]\n", sepfile
);
269 printf("\tprintprocessor:[%s]\n", printprocessor
);
270 printf("\tdatatype:[%s]\n", datatype
);
271 printf("\tparameters:[%s]\n", parameters
);
272 printf("\tattributes:[0x%x]\n", i2
->attributes
);
273 printf("\tpriority:[0x%x]\n", i2
->priority
);
274 printf("\tdefaultpriority:[0x%x]\n", i2
->defaultpriority
);
275 printf("\tstarttime:[0x%x]\n", i2
->starttime
);
276 printf("\tuntiltime:[0x%x]\n", i2
->untiltime
);
277 printf("\tstatus:[0x%x]\n", i2
->status
);
278 printf("\tcjobs:[0x%x]\n", i2
->cjobs
);
279 printf("\taverageppm:[0x%x]\n", i2
->averageppm
);
282 display_sec_desc(i2
->secdesc
);
287 /****************************************************************************
288 printer info level 3 display function
289 ****************************************************************************/
290 static void display_print_info_3(PRINTER_INFO_3
*i3
)
292 printf("\tflags:[0x%x]\n", i3
->flags
);
294 display_sec_desc(i3
->secdesc
);
299 /* Enumerate printers */
301 static WERROR
cmd_spoolss_enum_printers(struct cli_state
*cli
,
303 int argc
, const char **argv
)
306 uint32 info_level
= 1;
307 PRINTER_INFO_CTR ctr
;
308 uint32 i
= 0, num_printers
, needed
;
313 printf("Usage: %s [level] [name]\n", argv
[0]);
318 info_level
= atoi(argv
[1]);
321 fstrcpy(name
, argv
[2]);
323 slprintf(name
, sizeof(name
)-1, "\\\\%s", cli
->desthost
);
327 /* Enumerate printers -- Should we enumerate types other
328 than PRINTER_ENUM_LOCAL? Maybe accept as a parameter? --jerry */
332 result
= cli_spoolss_enum_printers(
333 cli
, mem_ctx
, 0, &needed
, name
, PRINTER_ENUM_LOCAL
,
334 info_level
, &num_printers
, &ctr
);
336 if (W_ERROR_V(result
) == ERRinsufficientbuffer
)
337 result
= cli_spoolss_enum_printers(
338 cli
, mem_ctx
, needed
, NULL
, name
, PRINTER_ENUM_LOCAL
,
339 info_level
, &num_printers
, &ctr
);
341 if (W_ERROR_IS_OK(result
)) {
344 printf ("No printers returned.\n");
348 for (i
= 0; i
< num_printers
; i
++) {
351 display_print_info_0(&ctr
.printers_0
[i
]);
354 display_print_info_1(&ctr
.printers_1
[i
]);
357 display_print_info_2(&ctr
.printers_2
[i
]);
360 display_print_info_3(&ctr
.printers_3
[i
]);
363 printf("unknown info level %d\n", info_level
);
373 /****************************************************************************
374 port info level 1 display function
375 ****************************************************************************/
376 static void display_port_info_1(PORT_INFO_1
*i1
)
380 rpcstr_pull(buffer
, i1
->port_name
.buffer
, sizeof(buffer
), -1, STR_TERMINATE
);
381 printf("\tPort Name:\t[%s]\n", buffer
);
384 /****************************************************************************
385 port info level 2 display function
386 ****************************************************************************/
387 static void display_port_info_2(PORT_INFO_2
*i2
)
391 rpcstr_pull(buffer
, i2
->port_name
.buffer
, sizeof(buffer
), -1, STR_TERMINATE
);
392 printf("\tPort Name:\t[%s]\n", buffer
);
393 rpcstr_pull(buffer
, i2
->monitor_name
.buffer
, sizeof(buffer
), -1, STR_TERMINATE
);
395 printf("\tMonitor Name:\t[%s]\n", buffer
);
396 rpcstr_pull(buffer
, i2
->description
.buffer
, sizeof(buffer
), -1, STR_TERMINATE
);
398 printf("\tDescription:\t[%s]\n", buffer
);
399 printf("\tPort Type:\t" );
400 if ( i2
->port_type
) {
401 int comma
= 0; /* hack */
403 if ( i2
->port_type
& PORT_TYPE_READ
) {
407 if ( i2
->port_type
& PORT_TYPE_WRITE
) {
408 printf( "%sWrite", comma
? ", " : "" );
411 /* These two have slightly different interpretations
412 on 95/98/ME but I'm disregarding that for now */
413 if ( i2
->port_type
& PORT_TYPE_REDIRECTED
) {
414 printf( "%sRedirected", comma
? ", " : "" );
417 if ( i2
->port_type
& PORT_TYPE_NET_ATTACHED
) {
418 printf( "%sNet-Attached", comma
? ", " : "" );
422 printf( "[Unset]\n" );
424 printf("\tReserved:\t[%d]\n", i2
->reserved
);
428 /* Enumerate ports */
430 static WERROR
cmd_spoolss_enum_ports(struct cli_state
*cli
,
431 TALLOC_CTX
*mem_ctx
, int argc
,
435 uint32 needed
, info_level
= 1;
440 printf("Usage: %s [level]\n", argv
[0]);
445 info_level
= atoi(argv
[1]);
447 /* Enumerate ports */
451 result
= cli_spoolss_enum_ports(cli
, mem_ctx
, 0, &needed
, info_level
,
454 if (W_ERROR_V(result
) == ERRinsufficientbuffer
)
455 result
= cli_spoolss_enum_ports(cli
, mem_ctx
, needed
, NULL
,
456 info_level
, &returned
, &ctr
);
458 if (W_ERROR_IS_OK(result
)) {
461 for (i
= 0; i
< returned
; i
++) {
462 switch (info_level
) {
464 display_port_info_1(&ctr
.port
.info_1
[i
]);
467 display_port_info_2(&ctr
.port
.info_2
[i
]);
470 printf("unknown info level %d\n", info_level
);
479 /***********************************************************************
480 * Set printer comment - use a level2 set.
482 static WERROR
cmd_spoolss_setprinter(struct cli_state
*cli
,
484 int argc
, const char **argv
)
489 uint32 info_level
= 2;
490 BOOL opened_hnd
= False
;
491 PRINTER_INFO_CTR ctr
;
497 if (argc
== 1 || argc
> 3) {
498 printf("Usage: %s printername comment\n", argv
[0]);
503 /* Open a printer handle */
505 fstrcpy(comment
, argv
[2]);
508 slprintf(servername
, sizeof(servername
)-1, "\\\\%s", cli
->desthost
);
509 strupper_m(servername
);
510 fstrcpy(printername
, argv
[1]);
511 fstrcpy(user
, cli
->user_name
);
513 /* get a printer handle */
514 result
= cli_spoolss_open_printer_ex(cli
, mem_ctx
, printername
, "",
515 PRINTER_ALL_ACCESS
, servername
,
518 if (!W_ERROR_IS_OK(result
))
523 /* Get printer info */
524 result
= cli_spoolss_getprinter(cli
, mem_ctx
, 0, &needed
, &pol
, info_level
, &ctr
);
526 if (W_ERROR_V(result
) == ERRinsufficientbuffer
)
527 result
= cli_spoolss_getprinter(cli
, mem_ctx
, needed
, NULL
, &pol
, info_level
, &ctr
);
529 if (!W_ERROR_IS_OK(result
))
533 /* Modify the comment. */
534 init_unistr(&ctr
.printers_2
->comment
, comment
);
535 ctr
.printers_2
->devmode
= NULL
;
536 ctr
.printers_2
->secdesc
= NULL
;
538 result
= cli_spoolss_setprinter(cli
, mem_ctx
, &pol
, info_level
, &ctr
, 0);
539 if (W_ERROR_IS_OK(result
))
540 printf("Success in setting comment.\n");
544 cli_spoolss_close_printer(cli
, mem_ctx
, &pol
);
549 /***********************************************************************
550 * Get printer information
552 static WERROR
cmd_spoolss_getprinter(struct cli_state
*cli
,
554 int argc
, const char **argv
)
558 uint32 info_level
= 1;
559 BOOL opened_hnd
= False
;
560 PRINTER_INFO_CTR ctr
;
566 if (argc
== 1 || argc
> 3) {
567 printf("Usage: %s <printername> [level]\n", argv
[0]);
571 /* Open a printer handle */
573 info_level
= atoi(argv
[2]);
576 slprintf(servername
, sizeof(servername
)-1, "\\\\%s", cli
->desthost
);
577 strupper_m(servername
);
578 slprintf(printername
, sizeof(printername
)-1, "%s\\%s", servername
, argv
[1]);
579 fstrcpy(user
, cli
->user_name
);
581 /* get a printer handle */
583 result
= cli_spoolss_open_printer_ex(cli
, mem_ctx
, printername
,
584 "", MAXIMUM_ALLOWED_ACCESS
,
585 servername
, user
, &pol
);
587 if (!W_ERROR_IS_OK(result
))
592 /* Get printer info */
594 result
= cli_spoolss_getprinter(cli
, mem_ctx
, 0, &needed
,
595 &pol
, info_level
, &ctr
);
597 if (W_ERROR_V(result
) == ERRinsufficientbuffer
)
598 result
= cli_spoolss_getprinter(
599 cli
, mem_ctx
, needed
, NULL
, &pol
, info_level
, &ctr
);
601 if (!W_ERROR_IS_OK(result
))
604 /* Display printer info */
606 switch (info_level
) {
608 display_print_info_0(ctr
.printers_0
);
611 display_print_info_1(ctr
.printers_1
);
614 display_print_info_2(ctr
.printers_2
);
617 display_print_info_3(ctr
.printers_3
);
620 printf("unknown info level %d\n", info_level
);
626 cli_spoolss_close_printer(cli
, mem_ctx
, &pol
);
631 static void display_reg_value(REGISTRY_VALUE value
)
637 printf("%s: REG_DWORD: 0x%08x\n", value
.valuename
,
638 *((uint32
*) value
.data_p
));
641 rpcstr_pull(text
, value
.data_p
, sizeof(text
), value
.size
,
643 printf("%s: REG_SZ: %s\n", value
.valuename
, text
);
646 printf("%s: REG_BINARY: unknown length value not displayed\n",
650 uint16
*curstr
= (uint16
*) value
.data_p
;
651 uint8
*start
= value
.data_p
;
652 printf("%s: REG_MULTI_SZ:\n", value
.valuename
);
653 while ((*curstr
!= 0) &&
654 ((uint8
*) curstr
< start
+ value
.size
)) {
655 rpcstr_pull(text
, curstr
, sizeof(text
), -1,
657 printf(" %s\n", text
);
658 curstr
+= strlen(text
) + 1;
663 printf("%s: unknown type %d\n", value
.valuename
, value
.type
);
668 /***********************************************************************
671 static WERROR
cmd_spoolss_getprinterdata(struct cli_state
*cli
,
673 int argc
, const char **argv
)
677 BOOL opened_hnd
= False
;
682 const char *valuename
;
683 REGISTRY_VALUE value
;
686 printf("Usage: %s <printername> <valuename>\n", argv
[0]);
687 printf("<printername> of . queries print server\n");
692 /* Open a printer handle */
694 slprintf(servername
, sizeof(servername
)-1, "\\\\%s", cli
->desthost
);
695 strupper_m(servername
);
696 if (strncmp(argv
[1], ".", sizeof(".")) == 0)
697 fstrcpy(printername
, servername
);
699 slprintf(printername
, sizeof(servername
)-1, "%s\\%s",
700 servername
, argv
[1]);
701 fstrcpy(user
, cli
->user_name
);
703 /* get a printer handle */
705 result
= cli_spoolss_open_printer_ex(cli
, mem_ctx
, printername
,
706 "", MAXIMUM_ALLOWED_ACCESS
,
707 servername
, user
, &pol
);
709 if (!W_ERROR_IS_OK(result
))
714 /* Get printer info */
716 result
= cli_spoolss_getprinterdata(cli
, mem_ctx
, 0, &needed
,
717 &pol
, valuename
, &value
);
719 if (W_ERROR_V(result
) == ERRmoredata
)
720 result
= cli_spoolss_getprinterdata(
721 cli
, mem_ctx
, needed
, NULL
, &pol
, valuename
, &value
);
723 if (!W_ERROR_IS_OK(result
))
726 /* Display printer data */
728 fstrcpy(value
.valuename
, valuename
);
729 display_reg_value(value
);
734 cli_spoolss_close_printer(cli
, mem_ctx
, &pol
);
739 /***********************************************************************
742 static WERROR
cmd_spoolss_getprinterdataex(struct cli_state
*cli
,
744 int argc
, const char **argv
)
748 BOOL opened_hnd
= False
;
753 const char *valuename
, *keyname
;
754 REGISTRY_VALUE value
;
757 printf("Usage: %s <printername> <keyname> <valuename>\n",
759 printf("<printername> of . queries print server\n");
765 /* Open a printer handle */
767 slprintf(servername
, sizeof(servername
)-1, "\\\\%s", cli
->desthost
);
768 strupper_m(servername
);
769 if (strncmp(argv
[1], ".", sizeof(".")) == 0)
770 fstrcpy(printername
, servername
);
772 slprintf(printername
, sizeof(printername
)-1, "%s\\%s",
773 servername
, argv
[1]);
774 fstrcpy(user
, cli
->user_name
);
776 /* get a printer handle */
778 result
= cli_spoolss_open_printer_ex(cli
, mem_ctx
, printername
,
779 "", MAXIMUM_ALLOWED_ACCESS
,
780 servername
, user
, &pol
);
782 if (!W_ERROR_IS_OK(result
))
787 /* Get printer info */
789 result
= cli_spoolss_getprinterdataex(cli
, mem_ctx
, 0, &needed
,
790 &pol
, keyname
, valuename
,
793 if (W_ERROR_V(result
) == ERRmoredata
)
794 result
= cli_spoolss_getprinterdataex(cli
, mem_ctx
, needed
,
798 if (!W_ERROR_IS_OK(result
))
801 /* Display printer data */
803 fstrcpy(value
.valuename
, valuename
);
804 display_reg_value(value
);
809 cli_spoolss_close_printer(cli
, mem_ctx
, &pol
);
814 /****************************************************************************
815 printer info level 0 display function
816 ****************************************************************************/
817 static void display_print_driver_1(DRIVER_INFO_1
*i1
)
823 rpcstr_pull(name
, i1
->name
.buffer
, sizeof(name
), -1, STR_TERMINATE
);
825 printf ("Printer Driver Info 1:\n");
826 printf ("\tDriver Name: [%s]\n\n", name
);
831 /****************************************************************************
832 printer info level 1 display function
833 ****************************************************************************/
834 static void display_print_driver_2(DRIVER_INFO_2
*i1
)
837 fstring architecture
;
844 rpcstr_pull(name
, i1
->name
.buffer
, sizeof(name
), -1, STR_TERMINATE
);
845 rpcstr_pull(architecture
, i1
->architecture
.buffer
, sizeof(architecture
), -1, STR_TERMINATE
);
846 rpcstr_pull(driverpath
, i1
->driverpath
.buffer
, sizeof(driverpath
), -1, STR_TERMINATE
);
847 rpcstr_pull(datafile
, i1
->datafile
.buffer
, sizeof(datafile
), -1, STR_TERMINATE
);
848 rpcstr_pull(configfile
, i1
->configfile
.buffer
, sizeof(configfile
), -1, STR_TERMINATE
);
850 printf ("Printer Driver Info 2:\n");
851 printf ("\tVersion: [%x]\n", i1
->version
);
852 printf ("\tDriver Name: [%s]\n", name
);
853 printf ("\tArchitecture: [%s]\n", architecture
);
854 printf ("\tDriver Path: [%s]\n", driverpath
);
855 printf ("\tDatafile: [%s]\n", datafile
);
856 printf ("\tConfigfile: [%s]\n\n", configfile
);
861 /****************************************************************************
862 printer info level 2 display function
863 ****************************************************************************/
864 static void display_print_driver_3(DRIVER_INFO_3
*i1
)
867 fstring architecture
= "";
868 fstring driverpath
= "";
869 fstring datafile
= "";
870 fstring configfile
= "";
871 fstring helpfile
= "";
872 fstring dependentfiles
= "";
873 fstring monitorname
= "";
874 fstring defaultdatatype
= "";
882 rpcstr_pull(name
, i1
->name
.buffer
, sizeof(name
), -1, STR_TERMINATE
);
883 rpcstr_pull(architecture
, i1
->architecture
.buffer
, sizeof(architecture
), -1, STR_TERMINATE
);
884 rpcstr_pull(driverpath
, i1
->driverpath
.buffer
, sizeof(driverpath
), -1, STR_TERMINATE
);
885 rpcstr_pull(datafile
, i1
->datafile
.buffer
, sizeof(datafile
), -1, STR_TERMINATE
);
886 rpcstr_pull(configfile
, i1
->configfile
.buffer
, sizeof(configfile
), -1, STR_TERMINATE
);
887 rpcstr_pull(helpfile
, i1
->helpfile
.buffer
, sizeof(helpfile
), -1, STR_TERMINATE
);
888 rpcstr_pull(monitorname
, i1
->monitorname
.buffer
, sizeof(monitorname
), -1, STR_TERMINATE
);
889 rpcstr_pull(defaultdatatype
, i1
->defaultdatatype
.buffer
, sizeof(defaultdatatype
), -1, STR_TERMINATE
);
891 printf ("Printer Driver Info 3:\n");
892 printf ("\tVersion: [%x]\n", i1
->version
);
893 printf ("\tDriver Name: [%s]\n",name
);
894 printf ("\tArchitecture: [%s]\n", architecture
);
895 printf ("\tDriver Path: [%s]\n", driverpath
);
896 printf ("\tDatafile: [%s]\n", datafile
);
897 printf ("\tConfigfile: [%s]\n", configfile
);
898 printf ("\tHelpfile: [%s]\n\n", helpfile
);
902 rpcstr_pull(dependentfiles
, i1
->dependentfiles
+length
, sizeof(dependentfiles
), -1, STR_TERMINATE
);
904 length
+=strlen(dependentfiles
)+1;
906 if (strlen(dependentfiles
) > 0)
908 printf ("\tDependentfiles: [%s]\n", dependentfiles
);
918 printf ("\tMonitorname: [%s]\n", monitorname
);
919 printf ("\tDefaultdatatype: [%s]\n\n", defaultdatatype
);
924 /***********************************************************************
925 * Get printer information
927 static WERROR
cmd_spoolss_getdriver(struct cli_state
*cli
,
929 int argc
, const char **argv
)
933 uint32 info_level
= 3;
934 BOOL opened_hnd
= False
;
935 PRINTER_DRIVER_CTR ctr
;
940 BOOL success
= False
;
942 if ((argc
== 1) || (argc
> 3))
944 printf("Usage: %s <printername> [level]\n", argv
[0]);
948 /* get the arguments need to open the printer handle */
949 slprintf(servername
, sizeof(servername
)-1, "\\\\%s", cli
->desthost
);
950 strupper_m(servername
);
951 fstrcpy(user
, cli
->user_name
);
952 fstrcpy(printername
, argv
[1]);
954 info_level
= atoi(argv
[2]);
956 /* Open a printer handle */
958 werror
= cli_spoolss_open_printer_ex(cli
, mem_ctx
, printername
, "",
960 servername
, user
, &pol
);
962 if (!W_ERROR_IS_OK(werror
)) {
963 printf("Error opening printer handle for %s!\n", printername
);
969 /* loop through and print driver info level for each architecture */
971 for (i
=0; archi_table
[i
].long_archi
!=NULL
; i
++) {
974 werror
= cli_spoolss_getprinterdriver(
975 cli
, mem_ctx
, 0, &needed
, &pol
, info_level
,
976 archi_table
[i
].long_archi
, archi_table
[i
].version
,
979 if (W_ERROR_V(werror
) == ERRinsufficientbuffer
) {
980 werror
= cli_spoolss_getprinterdriver(
981 cli
, mem_ctx
, needed
, NULL
, &pol
, info_level
,
982 archi_table
[i
].long_archi
, archi_table
[i
].version
,
986 if (!W_ERROR_IS_OK(werror
))
989 /* need at least one success */
993 printf ("\n[%s]\n", archi_table
[i
].long_archi
);
995 switch (info_level
) {
997 display_print_driver_1 (ctr
.info1
);
1000 display_print_driver_2 (ctr
.info2
);
1003 display_print_driver_3 (ctr
.info3
);
1006 printf("unknown info level %d\n", info_level
);
1014 cli_spoolss_close_printer (cli
, mem_ctx
, &pol
);
1022 /***********************************************************************
1023 * Get printer information
1025 static WERROR
cmd_spoolss_enum_drivers(struct cli_state
*cli
,
1026 TALLOC_CTX
*mem_ctx
,
1027 int argc
, const char **argv
)
1030 uint32 info_level
= 1;
1031 PRINTER_DRIVER_CTR ctr
;
1037 printf("Usage: enumdrivers [level]\n");
1042 info_level
= atoi(argv
[1]);
1045 /* loop through and print driver info level for each architecture */
1046 for (i
=0; archi_table
[i
].long_archi
!=NULL
; i
++)
1050 werror
= cli_spoolss_enumprinterdrivers(
1051 cli
, mem_ctx
, 0, &needed
, info_level
,
1052 archi_table
[i
].long_archi
, &returned
, &ctr
);
1054 if (W_ERROR_V(werror
) == ERRinsufficientbuffer
)
1055 werror
= cli_spoolss_enumprinterdrivers(
1056 cli
, mem_ctx
, needed
, NULL
, info_level
,
1057 archi_table
[i
].long_archi
, &returned
, &ctr
);
1062 if (!W_ERROR_IS_OK(werror
)) {
1063 printf ("Error getting driver for environment [%s] - %d\n",
1064 archi_table
[i
].long_archi
, W_ERROR_V(werror
));
1068 printf ("\n[%s]\n", archi_table
[i
].long_archi
);
1073 for (j
=0; j
< returned
; j
++) {
1074 display_print_driver_1 (&(ctr
.info1
[j
]));
1078 for (j
=0; j
< returned
; j
++) {
1079 display_print_driver_2 (&(ctr
.info2
[j
]));
1083 for (j
=0; j
< returned
; j
++) {
1084 display_print_driver_3 (&(ctr
.info3
[j
]));
1088 printf("unknown info level %d\n", info_level
);
1096 /****************************************************************************
1097 printer info level 1 display function
1098 ****************************************************************************/
1099 static void display_printdriverdir_1(DRIVER_DIRECTORY_1
*i1
)
1105 rpcstr_pull(name
, i1
->name
.buffer
, sizeof(name
), -1, STR_TERMINATE
);
1107 printf ("\tDirectory Name:[%s]\n", name
);
1110 /***********************************************************************
1111 * Get printer driver directory information
1113 static WERROR
cmd_spoolss_getdriverdir(struct cli_state
*cli
,
1114 TALLOC_CTX
*mem_ctx
,
1115 int argc
, const char **argv
)
1119 DRIVER_DIRECTORY_CTR ctr
;
1123 printf("Usage: %s [environment]\n", argv
[0]);
1127 /* Get the arguments need to open the printer handle */
1130 fstrcpy (env
, argv
[1]);
1132 fstrcpy (env
, "Windows NT x86");
1134 /* Get the directory. Only use Info level 1 */
1136 result
= cli_spoolss_getprinterdriverdir(
1137 cli
, mem_ctx
, 0, &needed
, 1, env
, &ctr
);
1139 if (W_ERROR_V(result
) == ERRinsufficientbuffer
)
1140 result
= cli_spoolss_getprinterdriverdir(
1141 cli
, mem_ctx
, needed
, NULL
, 1, env
, &ctr
);
1143 if (W_ERROR_IS_OK(result
))
1144 display_printdriverdir_1(ctr
.info1
);
1149 /*******************************************************************************
1150 set the version and environment fields of a DRIVER_INFO_3 struct
1151 ******************************************************************************/
1152 void set_drv_info_3_env (DRIVER_INFO_3
*info
, const char *arch
)
1157 for (i
=0; archi_table
[i
].long_archi
!= NULL
; i
++)
1159 if (strcmp(arch
, archi_table
[i
].short_archi
) == 0)
1161 info
->version
= archi_table
[i
].version
;
1162 init_unistr (&info
->architecture
, archi_table
[i
].long_archi
);
1167 if (archi_table
[i
].long_archi
== NULL
)
1169 DEBUG(0, ("set_drv_info_3_env: Unknown arch [%s]\n", arch
));
1176 /**************************************************************************
1177 wrapper for strtok to get the next parameter from a delimited list.
1178 Needed to handle the empty parameter string denoted by "NULL"
1179 *************************************************************************/
1180 static char* get_driver_3_param (const char* str
, const char* delim
, UNISTR
* dest
)
1184 /* get the next token */
1185 ptr
= strtok(str
, delim
);
1187 /* a string of 'NULL' is used to represent an empty
1188 parameter because two consecutive delimiters
1189 will not return an empty string. See man strtok(3)
1191 if (ptr
&& (StrCaseCmp(ptr
, "NULL") == 0))
1195 init_unistr(dest
, ptr
);
1200 /********************************************************************************
1201 fill in the members of a DRIVER_INFO_3 struct using a character
1202 string in the form of
1203 <Long Printer Name>:<Driver File Name>:<Data File Name>:\
1204 <Config File Name>:<Help File Name>:<Language Monitor Name>:\
1205 <Default Data Type>:<Comma Separated list of Files>
1206 *******************************************************************************/
1207 static BOOL
init_drv_info_3_members (
1208 TALLOC_CTX
*mem_ctx
,
1209 DRIVER_INFO_3
*info
,
1216 /* fill in the UNISTR fields */
1217 str
= get_driver_3_param (args
, ":", &info
->name
);
1218 str
= get_driver_3_param (NULL
, ":", &info
->driverpath
);
1219 str
= get_driver_3_param (NULL
, ":", &info
->datafile
);
1220 str
= get_driver_3_param (NULL
, ":", &info
->configfile
);
1221 str
= get_driver_3_param (NULL
, ":", &info
->helpfile
);
1222 str
= get_driver_3_param (NULL
, ":", &info
->monitorname
);
1223 str
= get_driver_3_param (NULL
, ":", &info
->defaultdatatype
);
1225 /* <Comma Separated List of Dependent Files> */
1226 str2
= get_driver_3_param (NULL
, ":", NULL
); /* save the beginning of the string */
1229 /* begin to strip out each filename */
1230 str
= strtok(str
, ",");
1234 /* keep a cumlative count of the str lengths */
1235 len
+= strlen(str
)+1;
1236 str
= strtok(NULL
, ",");
1239 /* allocate the space; add one extra slot for a terminating NULL.
1240 Each filename is NULL terminated and the end contains a double
1242 if ((info
->dependentfiles
=(uint16
*)talloc(mem_ctx
, (len
+1)*sizeof(uint16
))) == NULL
)
1244 DEBUG(0,("init_drv_info_3_members: Unable to malloc memory for dependenfiles\n"));
1247 for (i
=0; i
<len
; i
++)
1249 SSVAL(&info
->dependentfiles
[i
], 0, str2
[i
]);
1251 info
->dependentfiles
[len
] = '\0';
1257 static WERROR
cmd_spoolss_addprinterdriver(struct cli_state
*cli
,
1258 TALLOC_CTX
*mem_ctx
,
1259 int argc
, const char **argv
)
1263 PRINTER_DRIVER_CTR ctr
;
1264 DRIVER_INFO_3 info3
;
1266 fstring driver_name
;
1268 /* parse the command arguements */
1271 printf ("Usage: %s <Environment>\\\n", argv
[0]);
1272 printf ("\t<Long Printer Name>:<Driver File Name>:<Data File Name>:\\\n");
1273 printf ("\t<Config File Name>:<Help File Name>:<Language Monitor Name>:\\\n");
1274 printf ("\t<Default Data Type>:<Comma Separated list of Files>\n");
1279 /* Fill in the DRIVER_INFO_3 struct */
1281 if (!(arch
= cmd_spoolss_get_short_archi(argv
[1])))
1283 printf ("Error Unknown architechture [%s]\n", argv
[1]);
1284 return WERR_INVALID_PARAM
;
1287 set_drv_info_3_env(&info3
, arch
);
1289 if (!init_drv_info_3_members(mem_ctx
, &info3
, argv
[2]))
1291 printf ("Error Invalid parameter list - %s.\n", argv
[2]);
1292 return WERR_INVALID_PARAM
;
1297 result
= cli_spoolss_addprinterdriver (cli
, mem_ctx
, level
, &ctr
);
1299 if (W_ERROR_IS_OK(result
)) {
1300 rpcstr_pull(driver_name
, info3
.name
.buffer
,
1301 sizeof(driver_name
), -1, STR_TERMINATE
);
1302 printf ("Printer Driver %s successfully installed.\n",
1310 static WERROR
cmd_spoolss_addprinterex(struct cli_state
*cli
,
1311 TALLOC_CTX
*mem_ctx
,
1312 int argc
, const char **argv
)
1316 PRINTER_INFO_CTR ctr
;
1317 PRINTER_INFO_2 info2
;
1320 /* parse the command arguements */
1323 printf ("Usage: %s <name> <shared name> <driver> <port>\n", argv
[0]);
1327 slprintf(servername
, sizeof(servername
)-1, "\\\\%s", cli
->desthost
);
1328 strupper_m(servername
);
1330 /* Fill in the DRIVER_INFO_3 struct */
1333 init_unistr( &info2
.servername
, servername
);
1335 init_unistr( &info2
.printername
, argv
[1]);
1336 init_unistr( &info2
.sharename
, argv
[2]);
1337 init_unistr( &info2
.drivername
, argv
[3]);
1338 init_unistr( &info2
.portname
, argv
[4]);
1339 init_unistr( &info2
.comment
, "Created by rpcclient");
1340 init_unistr( &info2
.printprocessor
, "winprint");
1341 init_unistr( &info2
.datatype
, "RAW");
1342 info2
.devmode
= NULL
;
1343 info2
.secdesc
= NULL
;
1344 info2
.attributes
= PRINTER_ATTRIBUTE_SHARED
;
1346 info2
.defaultpriority
= 0;
1347 info2
.starttime
= 0;
1348 info2
.untiltime
= 0;
1350 /* These three fields must not be used by AddPrinter()
1351 as defined in the MS Platform SDK documentation..
1355 info2.averageppm = 0;
1358 ctr
.printers_2
= &info2
;
1359 result
= cli_spoolss_addprinterex (cli
, mem_ctx
, level
, &ctr
);
1361 if (W_ERROR_IS_OK(result
))
1362 printf ("Printer %s successfully installed.\n", argv
[1]);
1367 static WERROR
cmd_spoolss_setdriver(struct cli_state
*cli
,
1368 TALLOC_CTX
*mem_ctx
,
1369 int argc
, const char **argv
)
1374 BOOL opened_hnd
= False
;
1375 PRINTER_INFO_CTR ctr
;
1376 PRINTER_INFO_2 info2
;
1382 /* parse the command arguements */
1385 printf ("Usage: %s <printer> <driver>\n", argv
[0]);
1389 slprintf(servername
, sizeof(servername
)-1, "\\\\%s", cli
->desthost
);
1390 strupper_m(servername
);
1391 slprintf(printername
, sizeof(printername
)-1, "%s\\%s", servername
, argv
[1]);
1392 fstrcpy(user
, cli
->user_name
);
1394 /* Get a printer handle */
1396 result
= cli_spoolss_open_printer_ex(cli
, mem_ctx
, printername
, "",
1398 servername
, user
, &pol
);
1400 if (!W_ERROR_IS_OK(result
))
1405 /* Get printer info */
1407 ZERO_STRUCT (info2
);
1408 ctr
.printers_2
= &info2
;
1410 result
= cli_spoolss_getprinter(cli
, mem_ctx
, 0, &needed
,
1413 if (W_ERROR_V(result
) == ERRinsufficientbuffer
)
1414 result
= cli_spoolss_getprinter(
1415 cli
, mem_ctx
, needed
, NULL
, &pol
, level
, &ctr
);
1417 if (!W_ERROR_IS_OK(result
)) {
1418 printf ("Unable to retrieve printer information!\n");
1422 /* Set the printer driver */
1424 init_unistr(&ctr
.printers_2
->drivername
, argv
[2]);
1426 result
= cli_spoolss_setprinter(cli
, mem_ctx
, &pol
, level
, &ctr
, 0);
1428 if (!W_ERROR_IS_OK(result
)) {
1429 printf("SetPrinter call failed!\n");
1433 printf("Succesfully set %s to driver %s.\n", argv
[1], argv
[2]);
1439 cli_spoolss_close_printer(cli
, mem_ctx
, &pol
);
1445 static WERROR
cmd_spoolss_deletedriver(struct cli_state
*cli
,
1446 TALLOC_CTX
*mem_ctx
,
1447 int argc
, const char **argv
)
1453 /* parse the command arguements */
1456 printf ("Usage: %s <driver>\n", argv
[0]);
1460 slprintf(servername
, sizeof(servername
)-1, "\\\\%s", cli
->desthost
);
1461 strupper_m(servername
);
1463 /* delete the driver for all architectures */
1464 for (i
=0; archi_table
[i
].long_archi
; i
++)
1466 /* make the call to remove the driver */
1467 result
= cli_spoolss_deleteprinterdriver(
1468 cli
, mem_ctx
, archi_table
[i
].long_archi
, argv
[1]);
1470 if ( !W_ERROR_IS_OK(result
) ) {
1471 if ( !W_ERROR_EQUAL(result
, WERR_UNKNOWN_PRINTER_DRIVER
) ) {
1472 printf ("Failed to remove driver %s for arch [%s] - error 0x%x!\n",
1473 argv
[1], archi_table
[i
].long_archi
,
1479 printf ("Driver %s removed for arch [%s].\n", argv
[1],
1480 archi_table
[i
].long_archi
);
1487 static WERROR
cmd_spoolss_getprintprocdir(struct cli_state
*cli
,
1488 TALLOC_CTX
*mem_ctx
,
1489 int argc
, const char **argv
)
1492 char *servername
= NULL
, *environment
= NULL
;
1496 /* parse the command arguements */
1498 printf ("Usage: %s [environment]\n", argv
[0]);
1502 if (asprintf(&servername
, "\\\\%s", cli
->desthost
) < 0)
1504 strupper_m(servername
);
1506 if (asprintf(&environment
, "%s", (argc
== 2) ? argv
[1] :
1507 PRINTER_DRIVER_ARCHITECTURE
) < 0) {
1508 SAFE_FREE(servername
);
1512 result
= cli_spoolss_getprintprocessordirectory(
1513 cli
, mem_ctx
, 0, &needed
, servername
, environment
, procdir
);
1515 if (W_ERROR_V(result
) == ERRinsufficientbuffer
)
1516 result
= cli_spoolss_getprintprocessordirectory(
1517 cli
, mem_ctx
, needed
, NULL
, servername
, environment
,
1520 if (W_ERROR_IS_OK(result
))
1521 printf("%s\n", procdir
);
1523 SAFE_FREE(servername
);
1524 SAFE_FREE(environment
);
1531 static WERROR
cmd_spoolss_addform(struct cli_state
*cli
, TALLOC_CTX
*mem_ctx
,
1532 int argc
, const char **argv
)
1536 char *servername
= NULL
, *printername
= NULL
;
1538 BOOL got_handle
= False
;
1540 /* Parse the command arguements */
1543 printf ("Usage: %s <printer> <formname>\n", argv
[0]);
1547 /* Get a printer handle */
1549 asprintf(&servername
, "\\\\%s", cli
->desthost
);
1550 strupper_m(servername
);
1551 asprintf(&printername
, "%s\\%s", servername
, argv
[1]);
1553 werror
= cli_spoolss_open_printer_ex(cli
, mem_ctx
, printername
, "",
1554 MAXIMUM_ALLOWED_ACCESS
,
1555 servername
, cli
->user_name
, &handle
);
1557 if (!W_ERROR_IS_OK(werror
))
1562 /* Dummy up some values for the form data */
1564 form
.flags
= FORM_USER
;
1565 form
.size_x
= form
.size_y
= 100;
1571 init_unistr2(&form
.name
, argv
[2], UNI_STR_TERMINATE
);
1576 werror
= cli_spoolss_addform(cli
, mem_ctx
, &handle
, 1, &form
);
1580 cli_spoolss_close_printer(cli
, mem_ctx
, &handle
);
1582 SAFE_FREE(servername
);
1583 SAFE_FREE(printername
);
1590 static WERROR
cmd_spoolss_setform(struct cli_state
*cli
, TALLOC_CTX
*mem_ctx
,
1591 int argc
, const char **argv
)
1595 char *servername
= NULL
, *printername
= NULL
;
1597 BOOL got_handle
= False
;
1599 /* Parse the command arguements */
1602 printf ("Usage: %s <printer> <formname>\n", argv
[0]);
1606 /* Get a printer handle */
1608 asprintf(&servername
, "\\\\%s", cli
->desthost
);
1609 strupper_m(servername
);
1610 asprintf(&printername
, "%s\\%s", servername
, argv
[1]);
1612 werror
= cli_spoolss_open_printer_ex(
1613 cli
, mem_ctx
, printername
, "", MAXIMUM_ALLOWED_ACCESS
,
1614 servername
, cli
->user_name
, &handle
);
1616 if (!W_ERROR_IS_OK(werror
))
1621 /* Dummy up some values for the form data */
1623 form
.flags
= FORM_PRINTER
;
1624 form
.size_x
= form
.size_y
= 100;
1630 init_unistr2(&form
.name
, argv
[2], UNI_STR_TERMINATE
);
1634 werror
= cli_spoolss_setform(cli
, mem_ctx
, &handle
, 1, argv
[2], &form
);
1638 cli_spoolss_close_printer(cli
, mem_ctx
, &handle
);
1640 SAFE_FREE(servername
);
1641 SAFE_FREE(printername
);
1648 static WERROR
cmd_spoolss_getform(struct cli_state
*cli
, TALLOC_CTX
*mem_ctx
,
1649 int argc
, const char **argv
)
1653 char *servername
= NULL
, *printername
= NULL
;
1655 BOOL got_handle
= False
;
1658 /* Parse the command arguements */
1661 printf ("Usage: %s <printer> <formname>\n", argv
[0]);
1665 /* Get a printer handle */
1667 asprintf(&servername
, "\\\\%s", cli
->desthost
);
1668 strupper_m(servername
);
1669 asprintf(&printername
, "%s\\%s", servername
, argv
[1]);
1671 werror
= cli_spoolss_open_printer_ex(
1672 cli
, mem_ctx
, printername
, "", MAXIMUM_ALLOWED_ACCESS
,
1673 servername
, cli
->user_name
, &handle
);
1675 if (!W_ERROR_IS_OK(werror
))
1682 werror
= cli_spoolss_getform(cli
, mem_ctx
, 0, &needed
,
1683 &handle
, argv
[2], 1, &form
);
1685 if (W_ERROR_V(werror
) == ERRinsufficientbuffer
)
1686 werror
= cli_spoolss_getform(cli
, mem_ctx
, needed
, NULL
,
1687 &handle
, argv
[2], 1, &form
);
1689 if (!W_ERROR_IS_OK(werror
))
1692 printf("width: %d\n", form
.width
);
1693 printf("length: %d\n", form
.length
);
1694 printf("left: %d\n", form
.left
);
1695 printf("top: %d\n", form
.top
);
1696 printf("right: %d\n", form
.right
);
1697 printf("bottom: %d\n", form
.bottom
);
1701 cli_spoolss_close_printer(cli
, mem_ctx
, &handle
);
1703 SAFE_FREE(servername
);
1704 SAFE_FREE(printername
);
1711 static WERROR
cmd_spoolss_deleteform(struct cli_state
*cli
,
1712 TALLOC_CTX
*mem_ctx
, int argc
,
1717 char *servername
= NULL
, *printername
= NULL
;
1718 BOOL got_handle
= False
;
1720 /* Parse the command arguements */
1723 printf ("Usage: %s <printer> <formname>\n", argv
[0]);
1727 /* Get a printer handle */
1729 asprintf(&servername
, "\\\\%s", cli
->desthost
);
1730 strupper_m(servername
);
1731 asprintf(&printername
, "%s\\%s", servername
, argv
[1]);
1733 werror
= cli_spoolss_open_printer_ex(
1734 cli
, mem_ctx
, printername
, "", MAXIMUM_ALLOWED_ACCESS
,
1735 servername
, cli
->user_name
, &handle
);
1737 if (!W_ERROR_IS_OK(werror
))
1742 /* Delete the form */
1744 werror
= cli_spoolss_deleteform(cli
, mem_ctx
, &handle
, argv
[2]);
1748 cli_spoolss_close_printer(cli
, mem_ctx
, &handle
);
1750 SAFE_FREE(servername
);
1751 SAFE_FREE(printername
);
1756 /* Enumerate forms */
1758 static WERROR
cmd_spoolss_enum_forms(struct cli_state
*cli
,
1759 TALLOC_CTX
*mem_ctx
, int argc
,
1764 char *servername
= NULL
, *printername
= NULL
;
1765 BOOL got_handle
= False
;
1766 uint32 needed
, num_forms
, level
= 1, i
;
1769 /* Parse the command arguements */
1772 printf ("Usage: %s <printer>\n", argv
[0]);
1776 /* Get a printer handle */
1778 asprintf(&servername
, "\\\\%s", cli
->desthost
);
1779 strupper_m(servername
);
1780 asprintf(&printername
, "%s\\%s", servername
, argv
[1]);
1782 werror
= cli_spoolss_open_printer_ex(
1783 cli
, mem_ctx
, printername
, "", MAXIMUM_ALLOWED_ACCESS
,
1784 servername
, cli
->user_name
, &handle
);
1786 if (!W_ERROR_IS_OK(werror
))
1791 /* Enumerate forms */
1793 werror
= cli_spoolss_enumforms(
1794 cli
, mem_ctx
, 0, &needed
, &handle
, level
, &num_forms
, &forms
);
1796 if (W_ERROR_V(werror
) == ERRinsufficientbuffer
)
1797 werror
= cli_spoolss_enumforms(
1798 cli
, mem_ctx
, needed
, NULL
, &handle
, level
,
1799 &num_forms
, &forms
);
1801 if (!W_ERROR_IS_OK(werror
))
1804 /* Display output */
1806 for (i
= 0; i
< num_forms
; i
++) {
1809 if (forms
[i
].name
.buffer
)
1810 rpcstr_pull(form_name
, forms
[i
].name
.buffer
,
1811 sizeof(form_name
), -1, STR_TERMINATE
);
1813 printf("%s\n", form_name
);
1818 cli_spoolss_close_printer(cli
, mem_ctx
, &handle
);
1820 SAFE_FREE(servername
);
1821 SAFE_FREE(printername
);
1826 static WERROR
cmd_spoolss_setprinterdata(struct cli_state
*cli
,
1827 TALLOC_CTX
*mem_ctx
,
1828 int argc
, const char **argv
)
1832 fstring servername
, printername
, user
;
1834 BOOL opened_hnd
= False
;
1835 PRINTER_INFO_CTR ctr
;
1836 PRINTER_INFO_0 info
;
1837 REGISTRY_VALUE value
;
1839 /* parse the command arguements */
1841 printf ("Usage: %s <printer> <value> <data>\n", argv
[0]);
1845 slprintf(servername
, sizeof(servername
)-1, "\\\\%s", cli
->desthost
);
1846 strupper_m(servername
);
1847 slprintf(printername
, sizeof(servername
)-1, "%s\\%s", servername
, argv
[1]);
1848 fstrcpy(user
, cli
->user_name
);
1850 /* get a printer handle */
1851 result
= cli_spoolss_open_printer_ex(cli
, mem_ctx
, printername
, "",
1852 MAXIMUM_ALLOWED_ACCESS
, servername
,
1854 if (!W_ERROR_IS_OK(result
))
1859 ctr
.printers_0
= &info
;
1861 result
= cli_spoolss_getprinter(cli
, mem_ctx
, 0, &needed
,
1864 if (W_ERROR_V(result
) == ERRinsufficientbuffer
)
1865 result
= cli_spoolss_getprinter(cli
, mem_ctx
, needed
, NULL
, &pol
, 0, &ctr
);
1867 if (!W_ERROR_IS_OK(result
))
1870 printf("%s\n", timestring(True
));
1871 printf("\tchange_id (before set)\t:[0x%x]\n", info
.change_id
);
1873 /* Set the printer data */
1875 fstrcpy(value
.valuename
, argv
[2]);
1876 value
.type
= REG_SZ
;
1877 value
.size
= strlen(argv
[3]) + 1;
1878 value
.data_p
= talloc_memdup(mem_ctx
, argv
[3], value
.size
);
1880 result
= cli_spoolss_setprinterdata(cli
, mem_ctx
, &pol
, &value
);
1882 if (!W_ERROR_IS_OK(result
)) {
1883 printf ("Unable to set [%s=%s]!\n", argv
[2], argv
[3]);
1886 printf("\tSetPrinterData succeeded [%s: %s]\n", argv
[2], argv
[3]);
1888 result
= cli_spoolss_getprinter(cli
, mem_ctx
, 0, &needed
, &pol
, 0, &ctr
);
1890 if (W_ERROR_V(result
) == ERRinsufficientbuffer
)
1891 result
= cli_spoolss_getprinter(cli
, mem_ctx
, needed
, NULL
, &pol
, 0, &ctr
);
1893 if (!W_ERROR_IS_OK(result
))
1896 printf("%s\n", timestring(True
));
1897 printf("\tchange_id (after set)\t:[0x%x]\n", info
.change_id
);
1902 cli_spoolss_close_printer(cli
, mem_ctx
, &pol
);
1907 static void display_job_info_1(JOB_INFO_1
*job
)
1909 fstring username
= "", document
= "", text_status
= "";
1911 rpcstr_pull(username
, job
->username
.buffer
,
1912 sizeof(username
), -1, STR_TERMINATE
);
1914 rpcstr_pull(document
, job
->document
.buffer
,
1915 sizeof(document
), -1, STR_TERMINATE
);
1917 rpcstr_pull(text_status
, job
->text_status
.buffer
,
1918 sizeof(text_status
), -1, STR_TERMINATE
);
1920 printf("%d: jobid[%d]: %s %s %s %d/%d pages\n", job
->position
, job
->jobid
,
1921 username
, document
, text_status
, job
->pagesprinted
,
1925 static void display_job_info_2(JOB_INFO_2
*job
)
1927 fstring username
= "", document
= "", text_status
= "";
1929 rpcstr_pull(username
, job
->username
.buffer
,
1930 sizeof(username
), -1, STR_TERMINATE
);
1932 rpcstr_pull(document
, job
->document
.buffer
,
1933 sizeof(document
), -1, STR_TERMINATE
);
1935 rpcstr_pull(text_status
, job
->text_status
.buffer
,
1936 sizeof(text_status
), -1, STR_TERMINATE
);
1938 printf("%d: jobid[%d]: %s %s %s %d/%d pages, %d bytes\n", job
->position
, job
->jobid
,
1939 username
, document
, text_status
, job
->pagesprinted
,
1940 job
->totalpages
, job
->size
);
1943 /* Enumerate jobs */
1945 static WERROR
cmd_spoolss_enum_jobs(struct cli_state
*cli
,
1946 TALLOC_CTX
*mem_ctx
, int argc
,
1950 uint32 needed
, level
= 1, num_jobs
, i
;
1951 BOOL got_hnd
= False
;
1952 pstring printername
;
1953 fstring servername
, user
;
1957 if (argc
< 2 || argc
> 3) {
1958 printf("Usage: %s printername [level]\n", argv
[0]);
1963 level
= atoi(argv
[2]);
1965 /* Open printer handle */
1967 slprintf(servername
, sizeof(servername
)-1, "\\\\%s", cli
->desthost
);
1968 strupper_m(servername
);
1969 fstrcpy(user
, cli
->user_name
);
1970 slprintf(printername
, sizeof(servername
)-1, "\\\\%s\\", cli
->desthost
);
1971 strupper_m(printername
);
1972 pstrcat(printername
, argv
[1]);
1974 result
= cli_spoolss_open_printer_ex(cli
, mem_ctx
, printername
,
1975 "", MAXIMUM_ALLOWED_ACCESS
,
1976 servername
, user
, &hnd
);
1978 if (!W_ERROR_IS_OK(result
))
1983 /* Enumerate ports */
1985 result
= cli_spoolss_enumjobs(
1986 cli
, mem_ctx
, 0, &needed
, &hnd
, level
, 0, 1000,
1989 if (W_ERROR_V(result
) == ERRinsufficientbuffer
)
1990 result
= cli_spoolss_enumjobs(
1991 cli
, mem_ctx
, needed
, NULL
, &hnd
, level
, 0,
1992 1000, &num_jobs
, &ctr
);
1994 if (!W_ERROR_IS_OK(result
))
1997 for (i
= 0; i
< num_jobs
; i
++) {
2000 display_job_info_1(&ctr
.job
.job_info_1
[i
]);
2003 display_job_info_2(&ctr
.job
.job_info_2
[i
]);
2006 d_printf("unknown info level %d\n", level
);
2013 cli_spoolss_close_printer(cli
, mem_ctx
, &hnd
);
2018 /* enumerate data */
2020 static WERROR
cmd_spoolss_enum_data( struct cli_state
*cli
,
2021 TALLOC_CTX
*mem_ctx
, int argc
,
2025 uint32 i
=0, val_needed
, data_needed
;
2026 BOOL got_hnd
= False
;
2027 pstring printername
;
2028 fstring servername
, user
;
2032 printf("Usage: %s printername\n", argv
[0]);
2036 /* Open printer handle */
2038 slprintf(servername
, sizeof(servername
)-1, "\\\\%s", cli
->desthost
);
2039 strupper_m(servername
);
2040 fstrcpy(user
, cli
->user_name
);
2041 slprintf(printername
, sizeof(printername
)-1, "\\\\%s\\", cli
->desthost
);
2042 strupper_m(printername
);
2043 pstrcat(printername
, argv
[1]);
2045 result
= cli_spoolss_open_printer_ex(cli
, mem_ctx
, printername
,
2046 "", MAXIMUM_ALLOWED_ACCESS
,
2047 servername
, user
, &hnd
);
2049 if (!W_ERROR_IS_OK(result
))
2054 /* Enumerate data */
2056 result
= cli_spoolss_enumprinterdata(cli
, mem_ctx
, &hnd
, i
, 0, 0,
2057 &val_needed
, &data_needed
,
2059 while (W_ERROR_IS_OK(result
)) {
2060 REGISTRY_VALUE value
;
2061 result
= cli_spoolss_enumprinterdata(
2062 cli
, mem_ctx
, &hnd
, i
++, val_needed
,
2063 data_needed
, 0, 0, &value
);
2064 if (W_ERROR_IS_OK(result
))
2065 display_reg_value(value
);
2067 if (W_ERROR_V(result
) == ERRnomoreitems
)
2068 result
= W_ERROR(ERRsuccess
);
2072 cli_spoolss_close_printer(cli
, mem_ctx
, &hnd
);
2077 /* enumerate data for a given key */
2079 static WERROR
cmd_spoolss_enum_data_ex( struct cli_state
*cli
,
2080 TALLOC_CTX
*mem_ctx
, int argc
,
2085 BOOL got_hnd
= False
;
2086 pstring printername
;
2087 fstring servername
, user
;
2088 const char *keyname
= NULL
;
2093 printf("Usage: %s printername <keyname>\n", argv
[0]);
2099 /* Open printer handle */
2101 slprintf(servername
, sizeof(servername
)-1, "\\\\%s", cli
->desthost
);
2102 strupper_m(servername
);
2103 fstrcpy(user
, cli
->user_name
);
2104 slprintf(printername
, sizeof(printername
)-1, "\\\\%s\\", cli
->desthost
);
2105 strupper_m(printername
);
2106 pstrcat(printername
, argv
[1]);
2108 result
= cli_spoolss_open_printer_ex(cli
, mem_ctx
, printername
,
2109 "", MAXIMUM_ALLOWED_ACCESS
,
2110 servername
, user
, &hnd
);
2112 if (!W_ERROR_IS_OK(result
))
2117 /* Enumerate subkeys */
2119 result
= cli_spoolss_enumprinterdataex(
2120 cli
, mem_ctx
, 0, &needed
, &hnd
, keyname
, NULL
);
2122 if (W_ERROR_V(result
) == ERRmoredata
)
2123 result
= cli_spoolss_enumprinterdataex(
2124 cli
, mem_ctx
, needed
, NULL
, &hnd
, keyname
, &ctr
);
2126 if (!W_ERROR_IS_OK(result
))
2129 for (i
=0; i
< ctr
.num_values
; i
++) {
2130 display_reg_value(*(ctr
.values
[i
]));
2133 regval_ctr_destroy(&ctr
);
2137 cli_spoolss_close_printer(cli
, mem_ctx
, &hnd
);
2142 /* enumerate subkeys */
2144 static WERROR
cmd_spoolss_enum_printerkey( struct cli_state
*cli
,
2145 TALLOC_CTX
*mem_ctx
, int argc
,
2149 uint32 needed
, returned
;
2150 BOOL got_hnd
= False
;
2151 pstring printername
;
2152 fstring servername
, user
;
2153 const char *keyname
= NULL
;
2155 uint16
*keylist
= NULL
, *curkey
;
2157 if (argc
< 2 || argc
> 3) {
2158 printf("Usage: %s printername [keyname]\n", argv
[0]);
2167 /* Open printer handle */
2169 slprintf(servername
, sizeof(servername
)-1, "\\\\%s", cli
->desthost
);
2170 strupper_m(servername
);
2171 fstrcpy(user
, cli
->user_name
);
2172 slprintf(printername
, sizeof(printername
)-1, "\\\\%s\\", cli
->desthost
);
2173 strupper_m(printername
);
2174 pstrcat(printername
, argv
[1]);
2176 result
= cli_spoolss_open_printer_ex(cli
, mem_ctx
, printername
,
2177 "", MAXIMUM_ALLOWED_ACCESS
,
2178 servername
, user
, &hnd
);
2180 if (!W_ERROR_IS_OK(result
))
2185 /* Enumerate subkeys */
2187 result
= cli_spoolss_enumprinterkey(
2188 cli
, mem_ctx
, 0, &needed
, &hnd
, keyname
, NULL
, NULL
);
2190 if (W_ERROR_V(result
) == ERRmoredata
)
2191 result
= cli_spoolss_enumprinterkey(
2192 cli
, mem_ctx
, needed
, NULL
, &hnd
, keyname
, &keylist
,
2195 if (!W_ERROR_IS_OK(result
))
2199 while (*curkey
!= 0) {
2201 rpcstr_pull(subkey
, curkey
, sizeof(subkey
), -1,
2203 printf("%s\n", subkey
);
2204 curkey
+= strlen(subkey
) + 1;
2211 cli_spoolss_close_printer(cli
, mem_ctx
, &hnd
);
2216 static WERROR
cmd_spoolss_rffpcnex(struct cli_state
*cli
,
2217 TALLOC_CTX
*mem_ctx
, int argc
,
2220 fstring servername
, printername
;
2222 BOOL got_hnd
= False
;
2224 SPOOL_NOTIFY_OPTION option
;
2227 printf("Usage: %s printername\n", argv
[0]);
2234 slprintf(servername
, sizeof(servername
) - 1, "\\\\%s", cli
->desthost
);
2235 strupper_m(servername
);
2237 slprintf(printername
, sizeof(printername
) - 1, "\\\\%s\\%s", cli
->desthost
,
2239 strupper_m(printername
);
2241 result
= cli_spoolss_open_printer_ex(
2242 cli
, mem_ctx
, printername
, "", MAXIMUM_ALLOWED_ACCESS
,
2243 servername
, cli
->user_name
, &hnd
);
2245 if (!W_ERROR_IS_OK(result
)) {
2246 printf("Error opening %s\n", argv
[1]);
2252 /* Create spool options */
2254 ZERO_STRUCT(option
);
2257 option
.option_type_ptr
= 1;
2258 option
.count
= option
.ctr
.count
= 2;
2260 option
.ctr
.type
= (SPOOL_NOTIFY_OPTION_TYPE
*)talloc(
2261 mem_ctx
, sizeof(SPOOL_NOTIFY_OPTION_TYPE
) * 2);
2263 ZERO_STRUCT(option
.ctr
.type
[0]);
2264 option
.ctr
.type
[0].type
= PRINTER_NOTIFY_TYPE
;
2265 option
.ctr
.type
[0].count
= option
.ctr
.type
[0].count2
= 1;
2266 option
.ctr
.type
[0].fields_ptr
= 1;
2267 option
.ctr
.type
[0].fields
[0] = PRINTER_NOTIFY_SERVER_NAME
;
2269 ZERO_STRUCT(option
.ctr
.type
[1]);
2270 option
.ctr
.type
[1].type
= JOB_NOTIFY_TYPE
;
2271 option
.ctr
.type
[1].count
= option
.ctr
.type
[1].count2
= 1;
2272 option
.ctr
.type
[1].fields_ptr
= 1;
2273 option
.ctr
.type
[1].fields
[0] = JOB_NOTIFY_PRINTER_NAME
;
2277 slprintf(servername
, sizeof(servername
) - 1, "\\\\%s", myhostname());
2278 strupper_m(servername
);
2280 result
= cli_spoolss_rffpcnex(
2281 cli
, mem_ctx
, &hnd
, 0, 0, servername
, 123, &option
);
2283 if (!W_ERROR_IS_OK(result
)) {
2284 printf("Error rffpcnex %s\n", argv
[1]);
2290 cli_spoolss_close_printer(cli
, mem_ctx
, &hnd
);
2295 /* List of commands exported by this module */
2296 struct cmd_set spoolss_commands
[] = {
2300 { "adddriver", RPC_RTYPE_WERROR
, NULL
, cmd_spoolss_addprinterdriver
, PI_SPOOLSS
, "Add a print driver", "" },
2301 { "addprinter", RPC_RTYPE_WERROR
, NULL
, cmd_spoolss_addprinterex
, PI_SPOOLSS
, "Add a printer", "" },
2302 { "deldriver", RPC_RTYPE_WERROR
, NULL
, cmd_spoolss_deletedriver
, PI_SPOOLSS
, "Delete a printer driver", "" },
2303 { "enumdata", RPC_RTYPE_WERROR
, NULL
, cmd_spoolss_enum_data
, PI_SPOOLSS
, "Enumerate printer data", "" },
2304 { "enumdataex", RPC_RTYPE_WERROR
, NULL
, cmd_spoolss_enum_data_ex
, PI_SPOOLSS
, "Enumerate printer data for a key", "" },
2305 { "enumkey", RPC_RTYPE_WERROR
, NULL
, cmd_spoolss_enum_printerkey
, PI_SPOOLSS
, "Enumerate printer keys", "" },
2306 { "enumjobs", RPC_RTYPE_WERROR
, NULL
, cmd_spoolss_enum_jobs
, PI_SPOOLSS
, "Enumerate print jobs", "" },
2307 { "enumports", RPC_RTYPE_WERROR
, NULL
, cmd_spoolss_enum_ports
, PI_SPOOLSS
, "Enumerate printer ports", "" },
2308 { "enumdrivers", RPC_RTYPE_WERROR
, NULL
, cmd_spoolss_enum_drivers
, PI_SPOOLSS
, "Enumerate installed printer drivers", "" },
2309 { "enumprinters", RPC_RTYPE_WERROR
, NULL
, cmd_spoolss_enum_printers
, PI_SPOOLSS
, "Enumerate printers", "" },
2310 { "getdata", RPC_RTYPE_WERROR
, NULL
, cmd_spoolss_getprinterdata
, PI_SPOOLSS
, "Get print driver data", "" },
2311 { "getdataex", RPC_RTYPE_WERROR
, NULL
, cmd_spoolss_getprinterdataex
, PI_SPOOLSS
, "Get printer driver data with keyname", ""},
2312 { "getdriver", RPC_RTYPE_WERROR
, NULL
, cmd_spoolss_getdriver
, PI_SPOOLSS
, "Get print driver information", "" },
2313 { "getdriverdir", RPC_RTYPE_WERROR
, NULL
, cmd_spoolss_getdriverdir
, PI_SPOOLSS
, "Get print driver upload directory", "" },
2314 { "getprinter", RPC_RTYPE_WERROR
, NULL
, cmd_spoolss_getprinter
, PI_SPOOLSS
, "Get printer info", "" },
2315 { "getprintprocdir",RPC_RTYPE_WERROR
, NULL
, cmd_spoolss_getprintprocdir
, PI_SPOOLSS
, "Get print processor directory", "" },
2316 { "openprinter", RPC_RTYPE_WERROR
, NULL
, cmd_spoolss_open_printer_ex
, PI_SPOOLSS
, "Open printer handle", "" },
2317 { "setdriver", RPC_RTYPE_WERROR
, NULL
, cmd_spoolss_setdriver
, PI_SPOOLSS
, "Set printer driver", "" },
2318 { "getprintprocdir", RPC_RTYPE_WERROR
, NULL
, cmd_spoolss_getprintprocdir
, PI_SPOOLSS
, "Get print processor directory", "" },
2319 { "addform", RPC_RTYPE_WERROR
, NULL
, cmd_spoolss_addform
, PI_SPOOLSS
, "Add form", "" },
2320 { "setform", RPC_RTYPE_WERROR
, NULL
, cmd_spoolss_setform
, PI_SPOOLSS
, "Set form", "" },
2321 { "getform", RPC_RTYPE_WERROR
, NULL
, cmd_spoolss_getform
, PI_SPOOLSS
, "Get form", "" },
2322 { "deleteform", RPC_RTYPE_WERROR
, NULL
, cmd_spoolss_deleteform
, PI_SPOOLSS
, "Delete form", "" },
2323 { "enumforms", RPC_RTYPE_WERROR
, NULL
, cmd_spoolss_enum_forms
, PI_SPOOLSS
, "Enumerate forms", "" },
2324 { "setprinter", RPC_RTYPE_WERROR
, NULL
, cmd_spoolss_setprinter
, PI_SPOOLSS
, "Set printer comment", "" },
2325 { "setprinterdata", RPC_RTYPE_WERROR
, NULL
, cmd_spoolss_setprinterdata
, PI_SPOOLSS
, "Set REG_SZ printer data", "" },
2326 { "rffpcnex", RPC_RTYPE_WERROR
, NULL
, cmd_spoolss_rffpcnex
, PI_SPOOLSS
, "Rffpcnex test", "" },