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"
34 struct table_node archi_table
[]= {
36 {"Windows 4.0", "WIN40", 0 },
37 {"Windows NT x86", "W32X86", 2 },
38 {"Windows NT R4000", "W32MIPS", 2 },
39 {"Windows NT Alpha_AXP", "W32ALPHA", 2 },
40 {"Windows NT PowerPC", "W32PPC", 2 },
44 /****************************************************************************
45 function to do the mapping between the long architecture name and
47 ****************************************************************************/
48 BOOL
get_short_archi(char *short_archi
, char *long_archi
)
52 DEBUG(107,("Getting architecture dependant directory\n"));
55 } while ( (archi_table
[i
].long_archi
!=NULL
) &&
56 StrCaseCmp(long_archi
, archi_table
[i
].long_archi
) );
58 if (archi_table
[i
].long_archi
==NULL
) {
59 DEBUGADD(10,("Unknown architecture [%s] !\n", long_archi
));
63 StrnCpy (short_archi
, archi_table
[i
].short_archi
, strlen(archi_table
[i
].short_archi
));
65 DEBUGADD(108,("index: [%d]\n", i
));
66 DEBUGADD(108,("long architecture: [%s]\n", long_archi
));
67 DEBUGADD(108,("short architecture: [%s]\n", short_archi
));
73 /**********************************************************************
74 * dummy function -- placeholder
76 static NTSTATUS
cmd_spoolss_not_implemented(struct cli_state
*cli
,
78 int argc
, char **argv
)
80 printf ("(*) This command is not currently implemented.\n");
84 /***********************************************************************
85 * Get printer information
87 static NTSTATUS
cmd_spoolss_open_printer_ex(struct cli_state
*cli
,
89 int argc
, char **argv
)
93 fstring servername
, user
;
97 printf("Usage: %s <printername>\n", argv
[0]);
102 return NT_STATUS_UNSUCCESSFUL
;
104 slprintf (servername
, sizeof(fstring
)-1, "\\\\%s", cli
->desthost
);
105 strupper (servername
);
106 fstrcpy (user
, cli
->user_name
);
107 fstrcpy (printername
, argv
[1]);
109 /* Open the printer handle */
111 werror
= cli_spoolss_open_printer_ex(cli
, mem_ctx
, printername
,
112 "", MAXIMUM_ALLOWED_ACCESS
,
113 servername
, user
, &hnd
);
115 if (W_ERROR_IS_OK(werror
)) {
116 printf("Printer %s opened successfully\n", printername
);
117 werror
= cli_spoolss_close_printer(cli
, mem_ctx
, &hnd
);
119 if (!W_ERROR_IS_OK(werror
)) {
120 printf("Error closing printer handle! (%s)\n",
121 get_dos_error_msg(werror
));
125 return W_ERROR_IS_OK(werror
) ? NT_STATUS_OK
: NT_STATUS_UNSUCCESSFUL
;
129 /****************************************************************************
130 printer info level 0 display function
131 ****************************************************************************/
132 static void display_print_info_0(PRINTER_INFO_0
*i0
)
135 fstring servername
= "";
140 if (i0
->printername
.buffer
)
141 rpcstr_pull(name
, i0
->printername
.buffer
, sizeof(name
), -1, STR_TERMINATE
);
143 if (i0
->servername
.buffer
)
144 rpcstr_pull(servername
, i0
->servername
.buffer
, sizeof(servername
), -1,STR_TERMINATE
);
146 printf("\tprintername:[%s]\n", name
);
147 printf("\tservername:[%s]\n", servername
);
148 printf("\tcjobs:[0x%x]\n", i0
->cjobs
);
149 printf("\ttotal_jobs:[0x%x]\n", i0
->total_jobs
);
151 printf("\t:date: [%d]-[%d]-[%d] (%d)\n", i0
->year
, i0
->month
,
152 i0
->day
, i0
->dayofweek
);
153 printf("\t:time: [%d]-[%d]-[%d]-[%d]\n", i0
->hour
, i0
->minute
,
154 i0
->second
, i0
->milliseconds
);
156 printf("\tglobal_counter:[0x%x]\n", i0
->global_counter
);
157 printf("\ttotal_pages:[0x%x]\n", i0
->total_pages
);
159 printf("\tmajorversion:[0x%x]\n", i0
->major_version
);
160 printf("\tbuildversion:[0x%x]\n", i0
->build_version
);
162 printf("\tunknown7:[0x%x]\n", i0
->unknown7
);
163 printf("\tunknown8:[0x%x]\n", i0
->unknown8
);
164 printf("\tunknown9:[0x%x]\n", i0
->unknown9
);
165 printf("\tsession_counter:[0x%x]\n", i0
->session_counter
);
166 printf("\tunknown11:[0x%x]\n", i0
->unknown11
);
167 printf("\tprinter_errors:[0x%x]\n", i0
->printer_errors
);
168 printf("\tunknown13:[0x%x]\n", i0
->unknown13
);
169 printf("\tunknown14:[0x%x]\n", i0
->unknown14
);
170 printf("\tunknown15:[0x%x]\n", i0
->unknown15
);
171 printf("\tunknown16:[0x%x]\n", i0
->unknown16
);
172 printf("\tchange_id:[0x%x]\n", i0
->change_id
);
173 printf("\tunknown18:[0x%x]\n", i0
->unknown18
);
174 printf("\tstatus:[0x%x]\n", i0
->status
);
175 printf("\tunknown20:[0x%x]\n", i0
->unknown20
);
176 printf("\tc_setprinter:[0x%x]\n", i0
->c_setprinter
);
177 printf("\tunknown22:[0x%x]\n", i0
->unknown22
);
178 printf("\tunknown23:[0x%x]\n", i0
->unknown23
);
179 printf("\tunknown24:[0x%x]\n", i0
->unknown24
);
180 printf("\tunknown25:[0x%x]\n", i0
->unknown25
);
181 printf("\tunknown26:[0x%x]\n", i0
->unknown26
);
182 printf("\tunknown27:[0x%x]\n", i0
->unknown27
);
183 printf("\tunknown28:[0x%x]\n", i0
->unknown28
);
184 printf("\tunknown29:[0x%x]\n", i0
->unknown29
);
189 /****************************************************************************
190 printer info level 1 display function
191 ****************************************************************************/
192 static void display_print_info_1(PRINTER_INFO_1
*i1
)
198 if (i1
->description
.buffer
)
199 rpcstr_pull(desc
, i1
->description
.buffer
, sizeof(desc
), -1,
203 rpcstr_pull(name
, i1
->name
.buffer
, sizeof(name
), -1,
206 if (i1
->comment
.buffer
)
207 rpcstr_pull(comm
, i1
->comment
.buffer
, sizeof(comm
), -1,
210 printf("\tflags:[0x%x]\n", i1
->flags
);
211 printf("\tname:[%s]\n", name
);
212 printf("\tdescription:[%s]\n", desc
);
213 printf("\tcomment:[%s]\n", comm
);
218 /****************************************************************************
219 printer info level 2 display function
220 ****************************************************************************/
221 static void display_print_info_2(PRINTER_INFO_2
*i2
)
223 fstring servername
= "";
224 fstring printername
= "";
225 fstring sharename
= "";
226 fstring portname
= "";
227 fstring drivername
= "";
228 fstring comment
= "";
229 fstring location
= "";
230 fstring sepfile
= "";
231 fstring printprocessor
= "";
232 fstring datatype
= "";
233 fstring parameters
= "";
235 if (i2
->servername
.buffer
)
236 rpcstr_pull(servername
, i2
->servername
.buffer
,sizeof(servername
), -1, STR_TERMINATE
);
238 if (i2
->printername
.buffer
)
239 rpcstr_pull(printername
, i2
->printername
.buffer
,sizeof(printername
), -1, STR_TERMINATE
);
241 if (i2
->sharename
.buffer
)
242 rpcstr_pull(sharename
, i2
->sharename
.buffer
,sizeof(sharename
), -1, STR_TERMINATE
);
244 if (i2
->portname
.buffer
)
245 rpcstr_pull(portname
, i2
->portname
.buffer
,sizeof(portname
), -1, STR_TERMINATE
);
247 if (i2
->drivername
.buffer
)
248 rpcstr_pull(drivername
, i2
->drivername
.buffer
,sizeof(drivername
), -1, STR_TERMINATE
);
250 if (i2
->comment
.buffer
)
251 rpcstr_pull(comment
, i2
->comment
.buffer
,sizeof(comment
), -1, STR_TERMINATE
);
253 if (i2
->location
.buffer
)
254 rpcstr_pull(location
, i2
->location
.buffer
,sizeof(location
), -1, STR_TERMINATE
);
256 if (i2
->sepfile
.buffer
)
257 rpcstr_pull(sepfile
, i2
->sepfile
.buffer
,sizeof(sepfile
), -1, STR_TERMINATE
);
259 if (i2
->printprocessor
.buffer
)
260 rpcstr_pull(printprocessor
, i2
->printprocessor
.buffer
,sizeof(printprocessor
), -1, STR_TERMINATE
);
262 if (i2
->datatype
.buffer
)
263 rpcstr_pull(datatype
, i2
->datatype
.buffer
,sizeof(datatype
), -1, STR_TERMINATE
);
265 if (i2
->parameters
.buffer
)
266 rpcstr_pull(parameters
, i2
->parameters
.buffer
,sizeof(parameters
), -1, STR_TERMINATE
);
268 printf("\tservername:[%s]\n", servername
);
269 printf("\tprintername:[%s]\n", printername
);
270 printf("\tsharename:[%s]\n", sharename
);
271 printf("\tportname:[%s]\n", portname
);
272 printf("\tdrivername:[%s]\n", drivername
);
273 printf("\tcomment:[%s]\n", comment
);
274 printf("\tlocation:[%s]\n", location
);
275 printf("\tsepfile:[%s]\n", sepfile
);
276 printf("\tprintprocessor:[%s]\n", printprocessor
);
277 printf("\tdatatype:[%s]\n", datatype
);
278 printf("\tparameters:[%s]\n", parameters
);
279 printf("\tattributes:[0x%x]\n", i2
->attributes
);
280 printf("\tpriority:[0x%x]\n", i2
->priority
);
281 printf("\tdefaultpriority:[0x%x]\n", i2
->defaultpriority
);
282 printf("\tstarttime:[0x%x]\n", i2
->starttime
);
283 printf("\tuntiltime:[0x%x]\n", i2
->untiltime
);
284 printf("\tstatus:[0x%x]\n", i2
->status
);
285 printf("\tcjobs:[0x%x]\n", i2
->cjobs
);
286 printf("\taverageppm:[0x%x]\n", i2
->averageppm
);
289 display_sec_desc(i2
->secdesc
);
294 /****************************************************************************
295 printer info level 3 display function
296 ****************************************************************************/
297 static void display_print_info_3(PRINTER_INFO_3
*i3
)
299 printf("\tflags:[0x%x]\n", i3
->flags
);
301 display_sec_desc(i3
->secdesc
);
306 /* Enumerate printers */
308 static NTSTATUS
cmd_spoolss_enum_printers(struct cli_state
*cli
,
310 int argc
, char **argv
)
313 uint32 info_level
= 1;
314 PRINTER_INFO_CTR ctr
;
315 uint32 i
= 0, num_printers
, needed
;
320 printf("Usage: %s [level] [name]\n", argv
[0]);
325 info_level
= atoi(argv
[1]);
328 fstrcpy(name
, argv
[2]);
330 slprintf(name
, sizeof(name
)-1, "\\\\%s", cli
->desthost
);
334 /* Enumerate printers -- Should we enumerate types other
335 than PRINTER_ENUM_LOCAL? Maybe accept as a parameter? --jerry */
339 result
= cli_spoolss_enum_printers(
340 cli
, mem_ctx
, 0, &needed
, name
, PRINTER_ENUM_LOCAL
,
341 info_level
, &num_printers
, &ctr
);
343 if (W_ERROR_V(result
) == ERRinsufficientbuffer
)
344 result
= cli_spoolss_enum_printers(
345 cli
, mem_ctx
, needed
, NULL
, name
, PRINTER_ENUM_LOCAL
,
346 info_level
, &num_printers
, &ctr
);
348 if (W_ERROR_IS_OK(result
)) {
351 printf ("No printers returned.\n");
355 for (i
= 0; i
< num_printers
; i
++) {
358 display_print_info_0(&ctr
.printers_0
[i
]);
361 display_print_info_1(&ctr
.printers_1
[i
]);
364 display_print_info_2(&ctr
.printers_2
[i
]);
367 display_print_info_3(&ctr
.printers_3
[i
]);
370 printf("unknown info level %d\n", info_level
);
377 return W_ERROR_IS_OK(result
) ? NT_STATUS_OK
: NT_STATUS_UNSUCCESSFUL
;
380 /****************************************************************************
381 port info level 1 display function
382 ****************************************************************************/
383 static void display_port_info_1(PORT_INFO_1
*i1
)
387 rpcstr_pull(buffer
, i1
->port_name
.buffer
, sizeof(buffer
), -1, STR_TERMINATE
);
388 printf("\tPort Name:\t[%s]\n", buffer
);
391 /****************************************************************************
392 port info level 2 display function
393 ****************************************************************************/
394 static void display_port_info_2(PORT_INFO_2
*i2
)
398 rpcstr_pull(buffer
, i2
->port_name
.buffer
, sizeof(buffer
), -1, STR_TERMINATE
);
399 printf("\tPort Name:\t[%s]\n", buffer
);
400 rpcstr_pull(buffer
, i2
->monitor_name
.buffer
, sizeof(buffer
), -1, STR_TERMINATE
);
402 printf("\tMonitor Name:\t[%s]\n", buffer
);
403 rpcstr_pull(buffer
, i2
->description
.buffer
, sizeof(buffer
), -1, STR_TERMINATE
);
405 printf("\tDescription:\t[%s]\n", buffer
);
406 printf("\tPort Type:\t[%d]\n", i2
->port_type
);
407 printf("\tReserved:\t[%d]\n", i2
->reserved
);
411 /* Enumerate ports */
413 static NTSTATUS
cmd_spoolss_enum_ports(struct cli_state
*cli
,
414 TALLOC_CTX
*mem_ctx
, int argc
,
418 uint32 needed
, info_level
= 1;
423 printf("Usage: %s [level]\n", argv
[0]);
428 info_level
= atoi(argv
[1]);
430 /* Enumerate ports */
434 result
= cli_spoolss_enum_ports(cli
, mem_ctx
, 0, &needed
, info_level
,
437 if (W_ERROR_V(result
) == ERRinsufficientbuffer
)
438 result
= cli_spoolss_enum_ports(cli
, mem_ctx
, needed
, NULL
,
439 info_level
, &returned
, &ctr
);
441 if (W_ERROR_IS_OK(result
)) {
444 for (i
= 0; i
< returned
; i
++) {
445 switch (info_level
) {
447 display_port_info_1(&ctr
.port
.info_1
[i
]);
450 display_port_info_2(&ctr
.port
.info_2
[i
]);
453 printf("unknown info level %d\n", info_level
);
459 return W_ERROR_IS_OK(result
) ? NT_STATUS_OK
: NT_STATUS_UNSUCCESSFUL
;
462 /***********************************************************************
463 * Set printer comment - use a level2 set.
465 static NTSTATUS
cmd_spoolss_setprinter(struct cli_state
*cli
,
467 int argc
, char **argv
)
472 uint32 info_level
= 2;
473 BOOL opened_hnd
= False
;
474 PRINTER_INFO_CTR ctr
;
480 if (argc
== 1 || argc
> 3) {
481 printf("Usage: %s printername comment\n", argv
[0]);
486 /* Open a printer handle */
488 fstrcpy(comment
, argv
[2]);
491 slprintf (servername
, sizeof(fstring
)-1, "\\\\%s", cli
->desthost
);
492 strupper (servername
);
493 fstrcpy (printername
, argv
[1]);
494 fstrcpy (user
, cli
->user_name
);
496 /* get a printer handle */
497 result
= cli_spoolss_open_printer_ex(cli
, mem_ctx
, printername
, "",
498 MAXIMUM_ALLOWED_ACCESS
, servername
,
501 if (!W_ERROR_IS_OK(result
))
506 /* Get printer info */
507 result
= cli_spoolss_getprinter(cli
, mem_ctx
, 0, &needed
, &pol
, info_level
, &ctr
);
509 if (W_ERROR_V(result
) == ERRinsufficientbuffer
)
510 result
= cli_spoolss_getprinter(cli
, mem_ctx
, needed
, NULL
, &pol
, info_level
, &ctr
);
512 if (!W_ERROR_IS_OK(result
))
516 /* Modify the comment. */
517 init_unistr(&ctr
.printers_2
->comment
, comment
);
518 ctr
.printers_2
->devmode
= NULL
;
519 ctr
.printers_2
->secdesc
= NULL
;
521 result
= cli_spoolss_setprinter(cli
, mem_ctx
, &pol
, info_level
, &ctr
, 0);
522 if (W_ERROR_IS_OK(result
))
523 printf("Success in setting comment.\n");
527 cli_spoolss_close_printer(cli
, mem_ctx
, &pol
);
529 return W_ERROR_IS_OK(result
) ? NT_STATUS_OK
: NT_STATUS_UNSUCCESSFUL
;
532 /***********************************************************************
533 * Get printer information
535 static NTSTATUS
cmd_spoolss_getprinter(struct cli_state
*cli
,
537 int argc
, char **argv
)
541 uint32 info_level
= 1;
542 BOOL opened_hnd
= False
;
543 PRINTER_INFO_CTR ctr
;
549 if (argc
== 1 || argc
> 3) {
550 printf("Usage: %s <printername> [level]\n", argv
[0]);
554 /* Open a printer handle */
556 info_level
= atoi(argv
[2]);
559 slprintf (servername
, sizeof(fstring
)-1, "\\\\%s", cli
->desthost
);
560 strupper (servername
);
561 slprintf (printername
, sizeof(fstring
)-1, "%s\\%s", servername
, argv
[1]);
562 fstrcpy (user
, cli
->user_name
);
564 /* get a printer handle */
566 result
= cli_spoolss_open_printer_ex(cli
, mem_ctx
, printername
,
567 "", MAXIMUM_ALLOWED_ACCESS
,
568 servername
, user
, &pol
);
570 if (!W_ERROR_IS_OK(result
))
575 /* Get printer info */
577 result
= cli_spoolss_getprinter(cli
, mem_ctx
, 0, &needed
,
578 &pol
, info_level
, &ctr
);
580 if (W_ERROR_V(result
) == ERRinsufficientbuffer
)
581 result
= cli_spoolss_getprinter(
582 cli
, mem_ctx
, needed
, NULL
, &pol
, info_level
, &ctr
);
584 if (!W_ERROR_IS_OK(result
))
587 /* Display printer info */
589 switch (info_level
) {
591 display_print_info_0(ctr
.printers_0
);
594 display_print_info_1(ctr
.printers_1
);
597 display_print_info_2(ctr
.printers_2
);
600 display_print_info_3(ctr
.printers_3
);
603 printf("unknown info level %d\n", info_level
);
609 cli_spoolss_close_printer(cli
, mem_ctx
, &pol
);
611 return W_ERROR_IS_OK(result
) ? NT_STATUS_OK
: NT_STATUS_UNSUCCESSFUL
;
614 /****************************************************************************
615 printer info level 0 display function
616 ****************************************************************************/
617 static void display_print_driver_1(DRIVER_INFO_1
*i1
)
623 rpcstr_pull(name
, i1
->name
.buffer
, sizeof(name
), -1, STR_TERMINATE
);
625 printf ("Printer Driver Info 1:\n");
626 printf ("\tDriver Name: [%s]\n\n", name
);
631 /****************************************************************************
632 printer info level 1 display function
633 ****************************************************************************/
634 static void display_print_driver_2(DRIVER_INFO_2
*i1
)
637 fstring architecture
;
644 rpcstr_pull(name
, i1
->name
.buffer
, sizeof(name
), -1, STR_TERMINATE
);
645 rpcstr_pull(architecture
, i1
->architecture
.buffer
, sizeof(architecture
), -1, STR_TERMINATE
);
646 rpcstr_pull(driverpath
, i1
->driverpath
.buffer
, sizeof(driverpath
), -1, STR_TERMINATE
);
647 rpcstr_pull(datafile
, i1
->datafile
.buffer
, sizeof(datafile
), -1, STR_TERMINATE
);
648 rpcstr_pull(configfile
, i1
->configfile
.buffer
, sizeof(configfile
), -1, STR_TERMINATE
);
650 printf ("Printer Driver Info 2:\n");
651 printf ("\tVersion: [%x]\n", i1
->version
);
652 printf ("\tDriver Name: [%s]\n", name
);
653 printf ("\tArchitecture: [%s]\n", architecture
);
654 printf ("\tDriver Path: [%s]\n", driverpath
);
655 printf ("\tDatafile: [%s]\n", datafile
);
656 printf ("\tConfigfile: [%s]\n\n", configfile
);
661 /****************************************************************************
662 printer info level 2 display function
663 ****************************************************************************/
664 static void display_print_driver_3(DRIVER_INFO_3
*i1
)
667 fstring architecture
;
672 fstring dependentfiles
;
674 fstring defaultdatatype
;
682 rpcstr_pull(name
, i1
->name
.buffer
, sizeof(name
), -1, STR_TERMINATE
);
683 rpcstr_pull(architecture
, i1
->architecture
.buffer
, sizeof(architecture
), -1, STR_TERMINATE
);
684 rpcstr_pull(driverpath
, i1
->driverpath
.buffer
, sizeof(driverpath
), -1, STR_TERMINATE
);
685 rpcstr_pull(datafile
, i1
->datafile
.buffer
, sizeof(datafile
), -1, STR_TERMINATE
);
686 rpcstr_pull(configfile
, i1
->configfile
.buffer
, sizeof(configfile
), -1, STR_TERMINATE
);
687 rpcstr_pull(helpfile
, i1
->helpfile
.buffer
, sizeof(helpfile
), -1, STR_TERMINATE
);
688 rpcstr_pull(monitorname
, i1
->monitorname
.buffer
, sizeof(monitorname
), -1, STR_TERMINATE
);
689 rpcstr_pull(defaultdatatype
, i1
->defaultdatatype
.buffer
, sizeof(defaultdatatype
), -1, STR_TERMINATE
);
691 printf ("Printer Driver Info 3:\n");
692 printf ("\tVersion: [%x]\n", i1
->version
);
693 printf ("\tDriver Name: [%s]\n",name
);
694 printf ("\tArchitecture: [%s]\n", architecture
);
695 printf ("\tDriver Path: [%s]\n", driverpath
);
696 printf ("\tDatafile: [%s]\n", datafile
);
697 printf ("\tConfigfile: [%s]\n", configfile
);
698 printf ("\tHelpfile: [%s]\n\n", helpfile
);
702 rpcstr_pull(dependentfiles
, i1
->dependentfiles
+length
, sizeof(dependentfiles
), -1, STR_TERMINATE
);
704 length
+=strlen(dependentfiles
)+1;
706 if (strlen(dependentfiles
) > 0)
708 printf ("\tDependentfiles: [%s]\n", dependentfiles
);
718 printf ("\tMonitorname: [%s]\n", monitorname
);
719 printf ("\tDefaultdatatype: [%s]\n\n", defaultdatatype
);
724 /***********************************************************************
725 * Get printer information
727 static NTSTATUS
cmd_spoolss_getdriver(struct cli_state
*cli
,
729 int argc
, char **argv
)
734 uint32 info_level
= 3;
735 BOOL opened_hnd
= False
;
736 PRINTER_DRIVER_CTR ctr
;
742 if ((argc
== 1) || (argc
> 3))
744 printf("Usage: %s <printername> [level]\n", argv
[0]);
748 /* get the arguments need to open the printer handle */
749 slprintf (servername
, sizeof(fstring
)-1, "\\\\%s", cli
->desthost
);
750 strupper (servername
);
751 fstrcpy (user
, cli
->user_name
);
752 fstrcpy (printername
, argv
[1]);
754 info_level
= atoi(argv
[2]);
756 /* Open a printer handle */
758 werror
= cli_spoolss_open_printer_ex(cli
, mem_ctx
, printername
, "",
760 servername
, user
, &pol
);
762 result
= W_ERROR_IS_OK(werror
) ? NT_STATUS_OK
: NT_STATUS_UNSUCCESSFUL
;
764 if (!NT_STATUS_IS_OK(result
)) {
765 printf("Error opening printer handle for %s!\n", printername
);
771 /* loop through and print driver info level for each architecture */
773 for (i
=0; archi_table
[i
].long_archi
!=NULL
; i
++) {
776 werror
= cli_spoolss_getprinterdriver(
777 cli
, mem_ctx
, 0, &needed
, &pol
, info_level
,
778 archi_table
[i
].long_archi
, &ctr
);
780 if (W_ERROR_V(werror
) == ERRinsufficientbuffer
)
781 werror
= cli_spoolss_getprinterdriver(
782 cli
, mem_ctx
, needed
, NULL
, &pol
, info_level
,
783 archi_table
[i
].long_archi
, &ctr
);
785 if (!W_ERROR_IS_OK(werror
))
788 printf ("\n[%s]\n", archi_table
[i
].long_archi
);
790 switch (info_level
) {
792 display_print_driver_1 (ctr
.info1
);
795 display_print_driver_2 (ctr
.info2
);
798 display_print_driver_3 (ctr
.info3
);
801 printf("unknown info level %d\n", info_level
);
809 cli_spoolss_close_printer (cli
, mem_ctx
, &pol
);
811 return W_ERROR_IS_OK(result
) ? NT_STATUS_OK
: NT_STATUS_UNSUCCESSFUL
;
814 /***********************************************************************
815 * Get printer information
817 static NTSTATUS
cmd_spoolss_enum_drivers(struct cli_state
*cli
,
819 int argc
, char **argv
)
822 uint32 info_level
= 1;
823 PRINTER_DRIVER_CTR ctr
;
829 printf("Usage: enumdrivers [level]\n");
834 info_level
= atoi(argv
[1]);
837 /* loop through and print driver info level for each architecture */
838 for (i
=0; archi_table
[i
].long_archi
!=NULL
; i
++)
842 werror
= cli_spoolss_enumprinterdrivers(
843 cli
, mem_ctx
, 0, &needed
, info_level
,
844 archi_table
[i
].long_archi
, &returned
, &ctr
);
846 if (W_ERROR_V(werror
) == ERRinsufficientbuffer
)
847 werror
= cli_spoolss_enumprinterdrivers(
848 cli
, mem_ctx
, needed
, NULL
, info_level
,
849 archi_table
[i
].long_archi
, &returned
, &ctr
);
854 if (!W_ERROR_IS_OK(werror
)) {
855 printf ("Error getting driver for environment [%s] - %d\n",
856 archi_table
[i
].long_archi
, W_ERROR_V(werror
));
860 printf ("\n[%s]\n", archi_table
[i
].long_archi
);
865 for (j
=0; j
< returned
; j
++) {
866 display_print_driver_1 (&(ctr
.info1
[j
]));
870 for (j
=0; j
< returned
; j
++) {
871 display_print_driver_2 (&(ctr
.info2
[j
]));
875 for (j
=0; j
< returned
; j
++) {
876 display_print_driver_3 (&(ctr
.info3
[j
]));
880 printf("unknown info level %d\n", info_level
);
885 return W_ERROR_IS_OK(werror
) ? NT_STATUS_OK
: NT_STATUS_UNSUCCESSFUL
;
888 /****************************************************************************
889 printer info level 1 display function
890 ****************************************************************************/
891 static void display_printdriverdir_1(DRIVER_DIRECTORY_1
*i1
)
897 rpcstr_pull(name
, i1
->name
.buffer
, sizeof(name
), -1, STR_TERMINATE
);
899 printf ("\tDirectory Name:[%s]\n", name
);
902 /***********************************************************************
903 * Get printer driver directory information
905 static NTSTATUS
cmd_spoolss_getdriverdir(struct cli_state
*cli
,
907 int argc
, char **argv
)
911 DRIVER_DIRECTORY_CTR ctr
;
915 printf("Usage: %s [environment]\n", argv
[0]);
919 /* Get the arguments need to open the printer handle */
922 fstrcpy (env
, argv
[1]);
924 fstrcpy (env
, "Windows NT x86");
926 /* Get the directory. Only use Info level 1 */
928 result
= cli_spoolss_getprinterdriverdir(
929 cli
, mem_ctx
, 0, &needed
, 1, env
, &ctr
);
931 if (W_ERROR_V(result
) == ERRinsufficientbuffer
)
932 result
= cli_spoolss_getprinterdriverdir(
933 cli
, mem_ctx
, needed
, NULL
, 1, env
, &ctr
);
935 if (W_ERROR_IS_OK(result
))
936 display_printdriverdir_1(ctr
.info1
);
938 return W_ERROR_IS_OK(result
) ? NT_STATUS_OK
: NT_STATUS_UNSUCCESSFUL
;
941 /*******************************************************************************
942 set the version and environment fields of a DRIVER_INFO_3 struct
943 ******************************************************************************/
944 void set_drv_info_3_env (DRIVER_INFO_3
*info
, const char *arch
)
949 for (i
=0; archi_table
[i
].long_archi
!= NULL
; i
++)
951 if (strcmp(arch
, archi_table
[i
].short_archi
) == 0)
953 info
->version
= archi_table
[i
].version
;
954 init_unistr (&info
->architecture
, archi_table
[i
].long_archi
);
959 if (archi_table
[i
].long_archi
== NULL
)
961 DEBUG(0, ("set_drv_info_3_env: Unknown arch [%s]\n", arch
));
968 /**************************************************************************
969 wrapper for strtok to get the next parameter from a delimited list.
970 Needed to handle the empty parameter string denoted by "NULL"
971 *************************************************************************/
972 static char* get_driver_3_param (char* str
, char* delim
, UNISTR
* dest
)
976 /* get the next token */
977 ptr
= strtok(str
, delim
);
979 /* a string of 'NULL' is used to represent an empty
980 parameter because two consecutive delimiters
981 will not return an empty string. See man strtok(3)
983 if (StrCaseCmp(ptr
, "NULL") == 0)
987 init_unistr(dest
, ptr
);
992 /********************************************************************************
993 fill in the members of a DRIVER_INFO_3 struct using a character
994 string in the form of
995 <Long Printer Name>:<Driver File Name>:<Data File Name>:\
996 <Config File Name>:<Help File Name>:<Language Monitor Name>:\
997 <Default Data Type>:<Comma Separated list of Files>
998 *******************************************************************************/
999 static BOOL
init_drv_info_3_members (
1000 TALLOC_CTX
*mem_ctx
,
1001 DRIVER_INFO_3
*info
,
1008 /* fill in the UNISTR fields */
1009 str
= get_driver_3_param (args
, ":", &info
->name
);
1010 str
= get_driver_3_param (NULL
, ":", &info
->driverpath
);
1011 str
= get_driver_3_param (NULL
, ":", &info
->datafile
);
1012 str
= get_driver_3_param (NULL
, ":", &info
->configfile
);
1013 str
= get_driver_3_param (NULL
, ":", &info
->helpfile
);
1014 str
= get_driver_3_param (NULL
, ":", &info
->monitorname
);
1015 str
= get_driver_3_param (NULL
, ":", &info
->defaultdatatype
);
1017 /* <Comma Separated List of Dependent Files> */
1018 str2
= get_driver_3_param (NULL
, ":", NULL
); /* save the beginning of the string */
1021 /* begin to strip out each filename */
1022 str
= strtok(str
, ",");
1026 /* keep a cumlative count of the str lengths */
1027 len
+= strlen(str
)+1;
1028 str
= strtok(NULL
, ",");
1031 /* allocate the space; add one extra slot for a terminating NULL.
1032 Each filename is NULL terminated and the end contains a double
1034 if ((info
->dependentfiles
=(uint16
*)talloc(mem_ctx
, (len
+1)*sizeof(uint16
))) == NULL
)
1036 DEBUG(0,("init_drv_info_3_members: Unable to malloc memory for dependenfiles\n"));
1039 for (i
=0; i
<len
; i
++)
1041 info
->dependentfiles
[i
] = SSVAL(&info
->dependentfiles
[i
], 0, str2
[i
]);
1043 info
->dependentfiles
[len
] = '\0';
1049 static NTSTATUS
cmd_spoolss_addprinterdriver(struct cli_state
*cli
,
1050 TALLOC_CTX
*mem_ctx
,
1051 int argc
, char **argv
)
1055 PRINTER_DRIVER_CTR ctr
;
1056 DRIVER_INFO_3 info3
;
1058 fstring driver_name
;
1060 /* parse the command arguements */
1063 printf ("Usage: %s <Environment>\\\n", argv
[0]);
1064 printf ("\t<Long Printer Name>:<Driver File Name>:<Data File Name>:\\\n");
1065 printf ("\t<Config File Name>:<Help File Name>:<Language Monitor Name>:\\\n");
1066 printf ("\t<Default Data Type>:<Comma Separated list of Files>\n");
1068 return NT_STATUS_OK
;
1071 /* Fill in the DRIVER_INFO_3 struct */
1073 if (!get_short_archi(arch
, argv
[1]))
1075 printf ("Error Unknown architechture [%s]\n", argv
[1]);
1076 return NT_STATUS_INVALID_PARAMETER
;
1079 set_drv_info_3_env(&info3
, arch
);
1081 if (!init_drv_info_3_members(mem_ctx
, &info3
, argv
[2]))
1083 printf ("Error Invalid parameter list - %s.\n", argv
[2]);
1084 return NT_STATUS_INVALID_PARAMETER
;
1089 result
= cli_spoolss_addprinterdriver (cli
, mem_ctx
, level
, &ctr
);
1091 if (W_ERROR_IS_OK(result
)) {
1092 rpcstr_pull(driver_name
, info3
.name
.buffer
,
1093 sizeof(driver_name
), -1, STR_TERMINATE
);
1094 printf ("Printer Driver %s successfully installed.\n",
1098 return W_ERROR_IS_OK(result
) ? NT_STATUS_OK
: NT_STATUS_UNSUCCESSFUL
;
1102 static NTSTATUS
cmd_spoolss_addprinterex(struct cli_state
*cli
,
1103 TALLOC_CTX
*mem_ctx
,
1104 int argc
, char **argv
)
1108 PRINTER_INFO_CTR ctr
;
1109 PRINTER_INFO_2 info2
;
1112 /* parse the command arguements */
1115 printf ("Usage: %s <name> <shared name> <driver> <port>\n", argv
[0]);
1116 return NT_STATUS_OK
;
1119 slprintf (servername
, sizeof(fstring
)-1, "\\\\%s", cli
->desthost
);
1120 strupper (servername
);
1122 /* Fill in the DRIVER_INFO_3 struct */
1125 init_unistr( &info2
.servername
, servername
);
1127 init_unistr( &info2
.printername
, argv
[1]);
1128 init_unistr( &info2
.sharename
, argv
[2]);
1129 init_unistr( &info2
.drivername
, argv
[3]);
1130 init_unistr( &info2
.portname
, argv
[4]);
1131 init_unistr( &info2
.comment
, "Created by rpcclient");
1132 init_unistr( &info2
.printprocessor
, "winprint");
1133 init_unistr( &info2
.datatype
, "RAW");
1134 info2
.devmode
= NULL
;
1135 info2
.secdesc
= NULL
;
1136 info2
.attributes
= PRINTER_ATTRIBUTE_SHARED
;
1138 info2
.defaultpriority
= 0;
1139 info2
.starttime
= 0;
1140 info2
.untiltime
= 0;
1142 /* These three fields must not be used by AddPrinter()
1143 as defined in the MS Platform SDK documentation..
1147 info2.averageppm = 0;
1150 ctr
.printers_2
= &info2
;
1151 result
= cli_spoolss_addprinterex (cli
, mem_ctx
, level
, &ctr
);
1153 if (W_ERROR_IS_OK(result
))
1154 printf ("Printer %s successfully installed.\n", argv
[1]);
1156 return W_ERROR_IS_OK(result
) ? NT_STATUS_OK
: NT_STATUS_UNSUCCESSFUL
;
1159 static NTSTATUS
cmd_spoolss_setdriver(struct cli_state
*cli
,
1160 TALLOC_CTX
*mem_ctx
,
1161 int argc
, char **argv
)
1166 BOOL opened_hnd
= False
;
1167 PRINTER_INFO_CTR ctr
;
1168 PRINTER_INFO_2 info2
;
1174 /* parse the command arguements */
1177 printf ("Usage: %s <printer> <driver>\n", argv
[0]);
1178 return NT_STATUS_OK
;
1181 slprintf (servername
, sizeof(fstring
)-1, "\\\\%s", cli
->desthost
);
1182 strupper (servername
);
1183 slprintf (printername
, sizeof(fstring
)-1, "%s\\%s", servername
, argv
[1]);
1184 fstrcpy (user
, cli
->user_name
);
1186 /* Get a printer handle */
1188 result
= cli_spoolss_open_printer_ex(cli
, mem_ctx
, printername
, "",
1189 MAXIMUM_ALLOWED_ACCESS
,
1190 servername
, user
, &pol
);
1192 if (!W_ERROR_IS_OK(result
))
1197 /* Get printer info */
1199 ZERO_STRUCT (info2
);
1200 ctr
.printers_2
= &info2
;
1202 result
= cli_spoolss_getprinter(cli
, mem_ctx
, 0, &needed
,
1205 if (W_ERROR_V(result
) == ERRinsufficientbuffer
)
1206 result
= cli_spoolss_getprinter(
1207 cli
, mem_ctx
, needed
, NULL
, &pol
, level
, &ctr
);
1209 if (!W_ERROR_IS_OK(result
)) {
1210 printf ("Unable to retrieve printer information!\n");
1214 /* Set the printer driver */
1216 init_unistr(&ctr
.printers_2
->drivername
, argv
[2]);
1218 result
= cli_spoolss_setprinter(cli
, mem_ctx
, &pol
, level
, &ctr
, 0);
1220 if (!W_ERROR_IS_OK(result
)) {
1221 printf("SetPrinter call failed!\n");
1225 printf("Succesfully set %s to driver %s.\n", argv
[1], argv
[2]);
1231 cli_spoolss_close_printer(cli
, mem_ctx
, &pol
);
1233 return W_ERROR_IS_OK(result
) ? NT_STATUS_OK
: NT_STATUS_UNSUCCESSFUL
;
1237 static NTSTATUS
cmd_spoolss_deletedriver(struct cli_state
*cli
,
1238 TALLOC_CTX
*mem_ctx
,
1239 int argc
, char **argv
)
1245 /* parse the command arguements */
1248 printf ("Usage: %s <driver>\n", argv
[0]);
1249 return NT_STATUS_OK
;
1252 slprintf (servername
, sizeof(fstring
)-1, "\\\\%s", cli
->desthost
);
1253 strupper (servername
);
1255 /* delete the driver for all architectures */
1256 for (i
=0; archi_table
[i
].long_archi
; i
++)
1258 /* make the call to remove the driver */
1259 result
= cli_spoolss_deleteprinterdriver(
1260 cli
, mem_ctx
, archi_table
[i
].long_archi
, argv
[1]);
1262 if (!W_ERROR_IS_OK(result
)) {
1263 printf ("Failed to remove driver %s for arch [%s] - error 0x%x!\n",
1264 argv
[1], archi_table
[i
].long_archi
,
1267 printf ("Driver %s removed for arch [%s].\n", argv
[1],
1268 archi_table
[i
].long_archi
);
1271 return W_ERROR_IS_OK(result
) ? NT_STATUS_OK
: NT_STATUS_UNSUCCESSFUL
;
1274 static NTSTATUS
cmd_spoolss_getprintprocdir(struct cli_state
*cli
,
1275 TALLOC_CTX
*mem_ctx
,
1276 int argc
, char **argv
)
1279 char *servername
= NULL
, *environment
= NULL
;
1283 /* parse the command arguements */
1285 printf ("Usage: %s [environment]\n", argv
[0]);
1286 return NT_STATUS_OK
;
1289 if (asprintf(&servername
, "\\\\%s", cli
->desthost
) < 0)
1290 return NT_STATUS_NO_MEMORY
;
1291 strupper(servername
);
1293 if (asprintf(&environment
, "%s", (argc
== 2) ? argv
[1] :
1294 PRINTER_DRIVER_ARCHITECTURE
) < 0) {
1295 SAFE_FREE(servername
);
1296 return NT_STATUS_NO_MEMORY
;
1299 result
= cli_spoolss_getprintprocessordirectory(
1300 cli
, mem_ctx
, 0, &needed
, servername
, environment
, procdir
);
1302 if (W_ERROR_V(result
) == ERRinsufficientbuffer
)
1303 result
= cli_spoolss_getprintprocessordirectory(
1304 cli
, mem_ctx
, needed
, NULL
, servername
, environment
,
1307 if (W_ERROR_IS_OK(result
))
1308 printf("%s\n", procdir
);
1310 SAFE_FREE(servername
);
1311 SAFE_FREE(environment
);
1313 return W_ERROR_IS_OK(result
) ? NT_STATUS_OK
: NT_STATUS_UNSUCCESSFUL
;
1318 static NTSTATUS
cmd_spoolss_addform(struct cli_state
*cli
, TALLOC_CTX
*mem_ctx
,
1319 int argc
, char **argv
)
1323 char *servername
= NULL
, *printername
= NULL
;
1325 BOOL got_handle
= False
;
1327 /* Parse the command arguements */
1330 printf ("Usage: %s <printer> <formname>\n", argv
[0]);
1331 return NT_STATUS_OK
;
1334 /* Get a printer handle */
1336 asprintf(&servername
, "\\\\%s", cli
->desthost
);
1337 strupper(servername
);
1338 asprintf(&printername
, "%s\\%s", servername
, argv
[1]);
1340 werror
= cli_spoolss_open_printer_ex(cli
, mem_ctx
, printername
, "",
1341 MAXIMUM_ALLOWED_ACCESS
,
1342 servername
, cli
->user_name
, &handle
);
1344 if (!W_ERROR_IS_OK(werror
))
1349 /* Dummy up some values for the form data */
1351 form
.flags
= FORM_USER
;
1352 form
.size_x
= form
.size_y
= 100;
1358 init_unistr2(&form
.name
, argv
[2], strlen(argv
[2]) + 1);
1363 werror
= cli_spoolss_addform(cli
, mem_ctx
, &handle
, 1, &form
);
1367 cli_spoolss_close_printer(cli
, mem_ctx
, &handle
);
1369 SAFE_FREE(servername
);
1370 SAFE_FREE(printername
);
1372 return W_ERROR_IS_OK(werror
) ? NT_STATUS_OK
: NT_STATUS_UNSUCCESSFUL
;
1377 static NTSTATUS
cmd_spoolss_setform(struct cli_state
*cli
, TALLOC_CTX
*mem_ctx
,
1378 int argc
, char **argv
)
1382 char *servername
= NULL
, *printername
= NULL
;
1384 BOOL got_handle
= False
;
1386 /* Parse the command arguements */
1389 printf ("Usage: %s <printer> <formname>\n", argv
[0]);
1390 return NT_STATUS_OK
;
1393 /* Get a printer handle */
1395 asprintf(&servername
, "\\\\%s", cli
->desthost
);
1396 strupper(servername
);
1397 asprintf(&printername
, "%s\\%s", servername
, argv
[1]);
1399 werror
= cli_spoolss_open_printer_ex(
1400 cli
, mem_ctx
, printername
, "", MAXIMUM_ALLOWED_ACCESS
,
1401 servername
, cli
->user_name
, &handle
);
1403 if (!W_ERROR_IS_OK(werror
))
1408 /* Dummy up some values for the form data */
1410 form
.flags
= FORM_PRINTER
;
1411 form
.size_x
= form
.size_y
= 100;
1417 init_unistr2(&form
.name
, argv
[2], strlen(argv
[2]) + 1);
1421 werror
= cli_spoolss_setform(cli
, mem_ctx
, &handle
, 1, argv
[2], &form
);
1425 cli_spoolss_close_printer(cli
, mem_ctx
, &handle
);
1427 SAFE_FREE(servername
);
1428 SAFE_FREE(printername
);
1430 return W_ERROR_IS_OK(werror
) ? NT_STATUS_OK
: NT_STATUS_UNSUCCESSFUL
;
1435 static NTSTATUS
cmd_spoolss_getform(struct cli_state
*cli
, TALLOC_CTX
*mem_ctx
,
1436 int argc
, char **argv
)
1440 char *servername
= NULL
, *printername
= NULL
;
1442 BOOL got_handle
= False
;
1445 /* Parse the command arguements */
1448 printf ("Usage: %s <printer> <formname>\n", argv
[0]);
1449 return NT_STATUS_OK
;
1452 /* Get a printer handle */
1454 asprintf(&servername
, "\\\\%s", cli
->desthost
);
1455 strupper(servername
);
1456 asprintf(&printername
, "%s\\%s", servername
, argv
[1]);
1458 werror
= cli_spoolss_open_printer_ex(
1459 cli
, mem_ctx
, printername
, "", MAXIMUM_ALLOWED_ACCESS
,
1460 servername
, cli
->user_name
, &handle
);
1462 if (!W_ERROR_IS_OK(werror
))
1469 werror
= cli_spoolss_getform(cli
, mem_ctx
, 0, &needed
,
1470 &handle
, argv
[2], 1, &form
);
1472 if (W_ERROR_V(werror
) == ERRinsufficientbuffer
)
1473 werror
= cli_spoolss_getform(cli
, mem_ctx
, needed
, NULL
,
1474 &handle
, argv
[2], 1, &form
);
1476 if (!W_ERROR_IS_OK(werror
))
1479 printf("width: %d\n", form
.width
);
1480 printf("length: %d\n", form
.length
);
1481 printf("left: %d\n", form
.left
);
1482 printf("top: %d\n", form
.top
);
1483 printf("right: %d\n", form
.right
);
1484 printf("bottom: %d\n", form
.bottom
);
1488 cli_spoolss_close_printer(cli
, mem_ctx
, &handle
);
1490 SAFE_FREE(servername
);
1491 SAFE_FREE(printername
);
1493 return W_ERROR_IS_OK(werror
) ? NT_STATUS_OK
: NT_STATUS_UNSUCCESSFUL
;
1498 static NTSTATUS
cmd_spoolss_deleteform(struct cli_state
*cli
,
1499 TALLOC_CTX
*mem_ctx
, int argc
,
1504 char *servername
= NULL
, *printername
= NULL
;
1505 BOOL got_handle
= False
;
1507 /* Parse the command arguements */
1510 printf ("Usage: %s <printer> <formname>\n", argv
[0]);
1511 return NT_STATUS_OK
;
1514 /* Get a printer handle */
1516 asprintf(&servername
, "\\\\%s", cli
->desthost
);
1517 strupper(servername
);
1518 asprintf(&printername
, "%s\\%s", servername
, argv
[1]);
1520 werror
= cli_spoolss_open_printer_ex(
1521 cli
, mem_ctx
, printername
, "", MAXIMUM_ALLOWED_ACCESS
,
1522 servername
, cli
->user_name
, &handle
);
1524 if (!W_ERROR_IS_OK(werror
))
1529 /* Delete the form */
1531 werror
= cli_spoolss_deleteform(cli
, mem_ctx
, &handle
, argv
[2]);
1535 cli_spoolss_close_printer(cli
, mem_ctx
, &handle
);
1537 SAFE_FREE(servername
);
1538 SAFE_FREE(printername
);
1540 return W_ERROR_IS_OK(werror
) ? NT_STATUS_OK
: NT_STATUS_UNSUCCESSFUL
;
1543 /* Enumerate forms */
1545 static NTSTATUS
cmd_spoolss_enum_forms(struct cli_state
*cli
,
1546 TALLOC_CTX
*mem_ctx
, int argc
,
1551 char *servername
= NULL
, *printername
= NULL
;
1552 BOOL got_handle
= False
;
1553 uint32 needed
, num_forms
, level
= 1, i
;
1556 /* Parse the command arguements */
1559 printf ("Usage: %s <printer>\n", argv
[0]);
1560 return NT_STATUS_OK
;
1563 /* Get a printer handle */
1565 asprintf(&servername
, "\\\\%s", cli
->desthost
);
1566 strupper(servername
);
1567 asprintf(&printername
, "%s\\%s", servername
, argv
[1]);
1569 werror
= cli_spoolss_open_printer_ex(
1570 cli
, mem_ctx
, printername
, "", MAXIMUM_ALLOWED_ACCESS
,
1571 servername
, cli
->user_name
, &handle
);
1573 if (!W_ERROR_IS_OK(werror
))
1578 /* Enumerate forms */
1580 werror
= cli_spoolss_enumforms(
1581 cli
, mem_ctx
, 0, &needed
, &handle
, level
, &num_forms
, &forms
);
1583 if (W_ERROR_V(werror
) == ERRinsufficientbuffer
)
1584 werror
= cli_spoolss_enumforms(
1585 cli
, mem_ctx
, needed
, NULL
, &handle
, level
,
1586 &num_forms
, &forms
);
1588 if (!W_ERROR_IS_OK(werror
))
1591 /* Display output */
1593 for (i
= 0; i
< num_forms
; i
++) {
1596 if (forms
[i
].name
.buffer
)
1597 rpcstr_pull(form_name
, forms
[i
].name
.buffer
,
1598 sizeof(form_name
), -1, STR_TERMINATE
);
1600 printf("%s\n", form_name
);
1605 cli_spoolss_close_printer(cli
, mem_ctx
, &handle
);
1607 SAFE_FREE(servername
);
1608 SAFE_FREE(printername
);
1610 return W_ERROR_IS_OK(werror
) ? NT_STATUS_OK
: NT_STATUS_UNSUCCESSFUL
;
1613 static NTSTATUS
cmd_spoolss_setprinterdata(struct cli_state
*cli
,
1614 TALLOC_CTX
*mem_ctx
,
1615 int argc
, char **argv
)
1619 fstring servername
, printername
, user
;
1621 BOOL opened_hnd
= False
;
1622 PRINTER_INFO_CTR ctr
;
1623 PRINTER_INFO_0 info
;
1624 REGISTRY_VALUE value
;
1626 /* parse the command arguements */
1628 printf ("Usage: %s <printer> <value> <data>\n", argv
[0]);
1629 return NT_STATUS_OK
;
1632 slprintf (servername
, sizeof(fstring
)-1, "\\\\%s", cli
->desthost
);
1633 strupper (servername
);
1634 slprintf (printername
, sizeof(fstring
)-1, "%s\\%s", servername
, argv
[1]);
1635 fstrcpy (user
, cli
->user_name
);
1637 /* get a printer handle */
1638 result
= cli_spoolss_open_printer_ex(cli
, mem_ctx
, printername
, "",
1639 MAXIMUM_ALLOWED_ACCESS
, servername
,
1641 if (!W_ERROR_IS_OK(result
))
1646 ctr
.printers_0
= &info
;
1648 result
= cli_spoolss_getprinter(cli
, mem_ctx
, 0, &needed
,
1651 if (W_ERROR_V(result
) == ERRinsufficientbuffer
)
1652 result
= cli_spoolss_getprinter(cli
, mem_ctx
, needed
, NULL
, &pol
, 0, &ctr
);
1654 if (!W_ERROR_IS_OK(result
))
1657 printf("%s\n", timestring(True
));
1658 printf("\tchange_id (before set)\t:[0x%x]\n", info
.change_id
);
1660 /* Set the printer data */
1662 fstrcpy(value
.valuename
, argv
[2]);
1663 value
.type
= REG_SZ
;
1664 value
.size
= strlen(argv
[3]) + 1;
1665 value
.data_p
= talloc_memdup(mem_ctx
, argv
[3], value
.size
);
1667 result
= cli_spoolss_setprinterdata(cli
, mem_ctx
, &pol
, &value
);
1669 if (!W_ERROR_IS_OK(result
)) {
1670 printf ("Unable to set [%s=%s]!\n", argv
[2], argv
[3]);
1673 printf("\tSetPrinterData succeeded [%s: %s]\n", argv
[2], argv
[3]);
1675 result
= cli_spoolss_getprinter(cli
, mem_ctx
, 0, &needed
, &pol
, 0, &ctr
);
1677 if (W_ERROR_V(result
) == ERRinsufficientbuffer
)
1678 result
= cli_spoolss_getprinter(cli
, mem_ctx
, needed
, NULL
, &pol
, 0, &ctr
);
1680 if (!W_ERROR_IS_OK(result
))
1683 printf("%s\n", timestring(True
));
1684 printf("\tchange_id (after set)\t:[0x%x]\n", info
.change_id
);
1689 cli_spoolss_close_printer(cli
, mem_ctx
, &pol
);
1691 return W_ERROR_IS_OK(result
) ? NT_STATUS_OK
: NT_STATUS_UNSUCCESSFUL
;
1694 static void display_job_info_1(JOB_INFO_1
*job
)
1696 fstring username
= "", document
= "", text_status
= "";
1698 if (job
->username
.buffer
)
1699 rpcstr_pull(username
, job
->username
.buffer
,
1700 sizeof(username
), -1, STR_TERMINATE
);
1702 if (job
->document
.buffer
)
1703 rpcstr_pull(document
, job
->document
.buffer
,
1704 sizeof(document
), -1, STR_TERMINATE
);
1706 if (job
->text_status
.buffer
)
1707 rpcstr_pull(text_status
, job
->text_status
.buffer
,
1708 sizeof(text_status
), -1, STR_TERMINATE
);
1710 printf("%d: jobid[%d]: %s %s %s %d/%d pages\n", job
->position
, job
->jobid
,
1711 username
, document
, text_status
, job
->pagesprinted
,
1715 static void display_job_info_2(JOB_INFO_2
*job
)
1717 fstring username
= "", document
= "", text_status
= "";
1719 if (job
->username
.buffer
)
1720 rpcstr_pull(username
, job
->username
.buffer
,
1721 sizeof(username
), -1, STR_TERMINATE
);
1723 if (job
->document
.buffer
)
1724 rpcstr_pull(document
, job
->document
.buffer
,
1725 sizeof(document
), -1, STR_TERMINATE
);
1727 if (job
->text_status
.buffer
)
1728 rpcstr_pull(text_status
, job
->text_status
.buffer
,
1729 sizeof(text_status
), -1, STR_TERMINATE
);
1731 printf("%d: jobid[%d]: %s %s %s %d/%d pages, %d bytes\n", job
->position
, job
->jobid
,
1732 username
, document
, text_status
, job
->pagesprinted
,
1733 job
->totalpages
, job
->size
);
1736 /* Enumerate jobs */
1738 static NTSTATUS
cmd_spoolss_enum_jobs(struct cli_state
*cli
,
1739 TALLOC_CTX
*mem_ctx
, int argc
,
1743 uint32 needed
, level
= 1, num_jobs
, i
;
1744 BOOL got_hnd
= False
;
1745 pstring printername
;
1746 fstring servername
, user
;
1750 if (argc
< 2 || argc
> 3) {
1751 printf("Usage: %s printername [level]\n", argv
[0]);
1752 return NT_STATUS_OK
;
1756 level
= atoi(argv
[2]);
1758 /* Open printer handle */
1760 slprintf(servername
, sizeof(fstring
)-1, "\\\\%s", cli
->desthost
);
1761 strupper(servername
);
1762 fstrcpy(user
, cli
->user_name
);
1763 fstrcpy(printername
, argv
[1]);
1764 slprintf(printername
, sizeof(pstring
)-1, "\\\\%s\\", cli
->desthost
);
1765 strupper(printername
);
1766 pstrcat(printername
, argv
[1]);
1768 result
= cli_spoolss_open_printer_ex(cli
, mem_ctx
, printername
,
1769 "", MAXIMUM_ALLOWED_ACCESS
,
1770 servername
, user
, &hnd
);
1772 if (!W_ERROR_IS_OK(result
))
1777 /* Enumerate ports */
1779 result
= cli_spoolss_enumjobs(
1780 cli
, mem_ctx
, 0, &needed
, &hnd
, level
, 0, 1000,
1783 if (W_ERROR_V(result
) == ERRinsufficientbuffer
)
1784 result
= cli_spoolss_enumjobs(
1785 cli
, mem_ctx
, needed
, NULL
, &hnd
, level
, 0,
1786 1000, &num_jobs
, &ctr
);
1788 if (!W_ERROR_IS_OK(result
))
1791 for (i
= 0; i
< num_jobs
; i
++) {
1794 display_job_info_1(&ctr
.job
.job_info_1
[i
]);
1797 display_job_info_2(&ctr
.job
.job_info_2
[i
]);
1800 d_printf("unknown info level %d\n", level
);
1807 cli_spoolss_close_printer(cli
, mem_ctx
, &hnd
);
1809 return W_ERROR_IS_OK(result
) ? NT_STATUS_OK
: NT_STATUS_UNSUCCESSFUL
;
1812 static void display_reg_value(REGISTRY_VALUE value
)
1816 switch(value
.type
) {
1818 printf("%s: REG_DWORD: 0x%08x\n", value
.valuename
,
1819 *((uint32
*) value
.data_p
));
1822 rpcstr_pull(text
, value
.data_p
, sizeof(text
), value
.size
,
1824 printf("%s: REG_SZ: %s\n", value
.valuename
, text
);
1827 printf("%s: REG_BINARY: unknown length value not displayed\n",
1830 case REG_MULTI_SZ
: {
1831 uint16
*curstr
= (uint16
*) value
.data_p
;
1832 uint8
*start
= value
.data_p
;
1833 printf("%s: REG_MULTI_SZ:\n", value
.valuename
);
1834 while ((*curstr
!= 0) &&
1835 ((uint8
*) curstr
< start
+ value
.size
)) {
1836 rpcstr_pull(text
, curstr
, sizeof(text
), -1,
1838 printf(" %s\n", text
);
1839 curstr
+= strlen(text
) + 1;
1844 printf("%s: unknown type %d\n", value
.valuename
, value
.type
);
1848 /* enumerate data */
1850 static NTSTATUS
cmd_spoolss_enum_data( struct cli_state
*cli
,
1851 TALLOC_CTX
*mem_ctx
, int argc
,
1855 uint32 i
=0, val_needed
, data_needed
;
1856 BOOL got_hnd
= False
;
1857 pstring printername
;
1858 fstring servername
, user
;
1862 printf("Usage: %s printername\n", argv
[0]);
1863 return NT_STATUS_OK
;
1866 /* Open printer handle */
1868 slprintf(servername
, sizeof(fstring
)-1, "\\\\%s", cli
->desthost
);
1869 strupper(servername
);
1870 fstrcpy(user
, cli
->user_name
);
1871 fstrcpy(printername
, argv
[1]);
1872 slprintf(printername
, sizeof(pstring
)-1, "\\\\%s\\", cli
->desthost
);
1873 strupper(printername
);
1874 pstrcat(printername
, argv
[1]);
1876 result
= cli_spoolss_open_printer_ex(cli
, mem_ctx
, printername
,
1877 "", MAXIMUM_ALLOWED_ACCESS
,
1878 servername
, user
, &hnd
);
1880 if (!W_ERROR_IS_OK(result
))
1885 /* Enumerate data */
1887 result
= cli_spoolss_enumprinterdata(cli
, mem_ctx
, &hnd
, i
, 0, 0,
1888 &val_needed
, &data_needed
,
1890 while (W_ERROR_IS_OK(result
)) {
1891 REGISTRY_VALUE value
;
1892 result
= cli_spoolss_enumprinterdata(
1893 cli
, mem_ctx
, &hnd
, i
++, val_needed
,
1894 data_needed
, 0, 0, &value
);
1895 if (W_ERROR_IS_OK(result
))
1896 display_reg_value(value
);
1898 if (W_ERROR_V(result
) == ERRnomoreitems
)
1899 result
= W_ERROR(ERRsuccess
);
1903 cli_spoolss_close_printer(cli
, mem_ctx
, &hnd
);
1905 return W_ERROR_IS_OK(result
) ? NT_STATUS_OK
: NT_STATUS_UNSUCCESSFUL
;
1908 /* enumerate data for a given key */
1910 static NTSTATUS
cmd_spoolss_enum_data_ex( struct cli_state
*cli
,
1911 TALLOC_CTX
*mem_ctx
, int argc
,
1916 BOOL got_hnd
= False
;
1917 pstring printername
;
1918 fstring servername
, user
;
1919 char *keyname
= NULL
;
1924 printf("Usage: %s printername <keyname>\n", argv
[0]);
1925 return NT_STATUS_OK
;
1930 /* Open printer handle */
1932 slprintf(servername
, sizeof(fstring
)-1, "\\\\%s", cli
->desthost
);
1933 strupper(servername
);
1934 fstrcpy(user
, cli
->user_name
);
1935 fstrcpy(printername
, argv
[1]);
1936 slprintf(printername
, sizeof(pstring
)-1, "\\\\%s\\", cli
->desthost
);
1937 strupper(printername
);
1938 pstrcat(printername
, argv
[1]);
1940 result
= cli_spoolss_open_printer_ex(cli
, mem_ctx
, printername
,
1941 "", MAXIMUM_ALLOWED_ACCESS
,
1942 servername
, user
, &hnd
);
1944 if (!W_ERROR_IS_OK(result
))
1949 /* Enumerate subkeys */
1951 result
= cli_spoolss_enumprinterdataex(
1952 cli
, mem_ctx
, 0, &needed
, &hnd
, keyname
, NULL
);
1954 if (W_ERROR_V(result
) == ERRmoredata
)
1955 result
= cli_spoolss_enumprinterdataex(
1956 cli
, mem_ctx
, needed
, NULL
, &hnd
, keyname
, &ctr
);
1958 if (!W_ERROR_IS_OK(result
))
1961 for (i
=0; i
< ctr
.num_values
; i
++) {
1962 display_reg_value(*(ctr
.values
[i
]));
1965 regval_ctr_destroy(&ctr
);
1969 cli_spoolss_close_printer(cli
, mem_ctx
, &hnd
);
1971 return W_ERROR_IS_OK(result
) ? NT_STATUS_OK
: NT_STATUS_UNSUCCESSFUL
;
1974 /* enumerate subkeys */
1976 static NTSTATUS
cmd_spoolss_enum_printerkey( struct cli_state
*cli
,
1977 TALLOC_CTX
*mem_ctx
, int argc
,
1981 uint32 needed
, returned
;
1982 BOOL got_hnd
= False
;
1983 pstring printername
;
1984 fstring servername
, user
;
1985 char *keyname
= NULL
;
1987 uint16
*keylist
= NULL
, *curkey
;
1989 if (argc
< 2 || argc
> 3) {
1990 printf("Usage: %s printername [keyname]\n", argv
[0]);
1991 return NT_STATUS_OK
;
1999 /* Open printer handle */
2001 slprintf(servername
, sizeof(fstring
)-1, "\\\\%s", cli
->desthost
);
2002 strupper(servername
);
2003 fstrcpy(user
, cli
->user_name
);
2004 fstrcpy(printername
, argv
[1]);
2005 slprintf(printername
, sizeof(pstring
)-1, "\\\\%s\\", cli
->desthost
);
2006 strupper(printername
);
2007 pstrcat(printername
, argv
[1]);
2009 result
= cli_spoolss_open_printer_ex(cli
, mem_ctx
, printername
,
2010 "", MAXIMUM_ALLOWED_ACCESS
,
2011 servername
, user
, &hnd
);
2013 if (!W_ERROR_IS_OK(result
))
2018 /* Enumerate subkeys */
2020 result
= cli_spoolss_enumprinterkey(
2021 cli
, mem_ctx
, 0, &needed
, &hnd
, keyname
, NULL
, NULL
);
2023 if (W_ERROR_V(result
) == ERRmoredata
)
2024 result
= cli_spoolss_enumprinterkey(
2025 cli
, mem_ctx
, needed
, NULL
, &hnd
, keyname
, &keylist
,
2028 if (!W_ERROR_IS_OK(result
))
2032 while (*curkey
!= 0) {
2034 rpcstr_pull(subkey
, curkey
, sizeof(subkey
), -1,
2036 printf("%s\n", subkey
);
2037 curkey
+= strlen(subkey
) + 1;
2044 cli_spoolss_close_printer(cli
, mem_ctx
, &hnd
);
2046 return W_ERROR_IS_OK(result
) ? NT_STATUS_OK
: NT_STATUS_UNSUCCESSFUL
;
2049 static NTSTATUS
cmd_spoolss_rffpcnex(struct cli_state
*cli
,
2050 TALLOC_CTX
*mem_ctx
, int argc
,
2053 fstring servername
, printername
;
2055 BOOL got_hnd
= False
;
2057 SPOOL_NOTIFY_OPTION option
;
2060 printf("Usage: %s printername\n", argv
[0]);
2067 slprintf(servername
, sizeof(fstring
) - 1, "\\\\%s", cli
->desthost
);
2068 strupper(servername
);
2070 slprintf(printername
, sizeof(fstring
) - 1, "\\\\%s\\%s", cli
->desthost
,
2072 strupper(printername
);
2074 result
= cli_spoolss_open_printer_ex(
2075 cli
, mem_ctx
, printername
, "", MAXIMUM_ALLOWED_ACCESS
,
2076 servername
, cli
->user_name
, &hnd
);
2078 if (!W_ERROR_IS_OK(result
)) {
2079 printf("Error opening %s\n", argv
[1]);
2085 /* Create spool options */
2087 ZERO_STRUCT(option
);
2090 option
.option_type_ptr
= 1;
2091 option
.count
= option
.ctr
.count
= 2;
2093 option
.ctr
.type
= (SPOOL_NOTIFY_OPTION_TYPE
*)talloc(
2094 mem_ctx
, sizeof(SPOOL_NOTIFY_OPTION_TYPE
) * 2);
2096 ZERO_STRUCT(option
.ctr
.type
[0]);
2097 option
.ctr
.type
[0].type
= PRINTER_NOTIFY_TYPE
;
2098 option
.ctr
.type
[0].count
= option
.ctr
.type
[0].count2
= 1;
2099 option
.ctr
.type
[0].fields_ptr
= 1;
2100 option
.ctr
.type
[0].fields
[0] = PRINTER_NOTIFY_SERVER_NAME
;
2102 ZERO_STRUCT(option
.ctr
.type
[1]);
2103 option
.ctr
.type
[1].type
= JOB_NOTIFY_TYPE
;
2104 option
.ctr
.type
[1].count
= option
.ctr
.type
[1].count2
= 1;
2105 option
.ctr
.type
[1].fields_ptr
= 1;
2106 option
.ctr
.type
[1].fields
[0] = JOB_NOTIFY_PRINTER_NAME
;
2110 slprintf(servername
, sizeof(fstring
) - 1, "\\\\%s", myhostname());
2111 strupper(servername
);
2113 result
= cli_spoolss_rffpcnex(
2114 cli
, mem_ctx
, &hnd
, 0, 0, servername
, 123, &option
);
2116 if (!W_ERROR_IS_OK(result
)) {
2117 printf("Error rffpcnex %s\n", argv
[1]);
2123 cli_spoolss_close_printer(cli
, mem_ctx
, &hnd
);
2125 return W_ERROR_IS_OK(result
) ? NT_STATUS_OK
: NT_STATUS_UNSUCCESSFUL
;
2128 /* List of commands exported by this module */
2129 struct cmd_set spoolss_commands
[] = {
2133 { "adddriver", cmd_spoolss_addprinterdriver
, PI_SPOOLSS
, "Add a print driver", "" },
2134 { "addprinter", cmd_spoolss_addprinterex
, PI_SPOOLSS
, "Add a printer", "" },
2135 { "deldriver", cmd_spoolss_deletedriver
, PI_SPOOLSS
, "Delete a printer driver", "" },
2136 { "enumdata", cmd_spoolss_enum_data
, PI_SPOOLSS
, "Enumerate printer data", "" },
2137 { "enumdataex", cmd_spoolss_enum_data_ex
, PI_SPOOLSS
, "Enumerate printer data for a key", "" },
2138 { "enumkey", cmd_spoolss_enum_printerkey
, PI_SPOOLSS
, "Enumerate printer keys", "" },
2139 { "enumjobs", cmd_spoolss_enum_jobs
, PI_SPOOLSS
, "Enumerate print jobs", "" },
2140 { "enumports", cmd_spoolss_enum_ports
, PI_SPOOLSS
, "Enumerate printer ports", "" },
2141 { "enumdrivers", cmd_spoolss_enum_drivers
, PI_SPOOLSS
, "Enumerate installed printer drivers", "" },
2142 { "enumprinters", cmd_spoolss_enum_printers
, PI_SPOOLSS
, "Enumerate printers", "" },
2143 { "getdata", cmd_spoolss_not_implemented
, PI_SPOOLSS
, "Get print driver data (*)", "" },
2144 { "getdriver", cmd_spoolss_getdriver
, PI_SPOOLSS
, "Get print driver information", "" },
2145 { "getdriverdir", cmd_spoolss_getdriverdir
, PI_SPOOLSS
, "Get print driver upload directory", "" },
2146 { "getprinter", cmd_spoolss_getprinter
, PI_SPOOLSS
, "Get printer info", "" },
2147 { "getprintprocdir", cmd_spoolss_getprintprocdir
, PI_SPOOLSS
, "Get print processor directory", "" },
2148 { "openprinter", cmd_spoolss_open_printer_ex
, PI_SPOOLSS
, "Open printer handle", "" },
2149 { "setdriver", cmd_spoolss_setdriver
, PI_SPOOLSS
, "Set printer driver", "" },
2150 { "getprintprocdir", cmd_spoolss_getprintprocdir
, PI_SPOOLSS
, "Get print processor directory", "" },
2151 { "addform", cmd_spoolss_addform
, PI_SPOOLSS
, "Add form", "" },
2152 { "setform", cmd_spoolss_setform
, PI_SPOOLSS
, "Set form", "" },
2153 { "getform", cmd_spoolss_getform
, PI_SPOOLSS
, "Get form", "" },
2154 { "deleteform", cmd_spoolss_deleteform
, PI_SPOOLSS
, "Delete form", "" },
2155 { "enumforms", cmd_spoolss_enum_forms
, PI_SPOOLSS
, "Enumerate forms", "" },
2156 { "setprinter", cmd_spoolss_setprinter
, PI_SPOOLSS
, "Set printer comment", "" },
2157 { "setprinterdata", cmd_spoolss_setprinterdata
, PI_SPOOLSS
, "Set REG_SZ printer data", "" },
2158 { "rffpcnex", cmd_spoolss_rffpcnex
, PI_SPOOLSS
, "Rffpcnex test", "" },