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
;
319 printf("Usage: %s [level]\n", argv
[0]);
324 info_level
= atoi(argv
[1]);
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
, 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
, 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
);
370 return W_ERROR_IS_OK(result
) ? NT_STATUS_OK
: NT_STATUS_UNSUCCESSFUL
;
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[%d]\n", i2
->port_type
);
400 printf("\tReserved:\t[%d]\n", i2
->reserved
);
404 /* Enumerate ports */
406 static NTSTATUS
cmd_spoolss_enum_ports(struct cli_state
*cli
,
407 TALLOC_CTX
*mem_ctx
, int argc
,
411 uint32 needed
, info_level
= 1;
416 printf("Usage: %s [level]\n", argv
[0]);
421 info_level
= atoi(argv
[1]);
423 /* Enumerate ports */
427 result
= cli_spoolss_enum_ports(cli
, mem_ctx
, 0, &needed
, info_level
,
430 if (W_ERROR_V(result
) == ERRinsufficientbuffer
)
431 result
= cli_spoolss_enum_ports(cli
, mem_ctx
, needed
, NULL
,
432 info_level
, &returned
, &ctr
);
434 if (W_ERROR_IS_OK(result
)) {
437 for (i
= 0; i
< returned
; i
++) {
438 switch (info_level
) {
440 display_port_info_1(&ctr
.port
.info_1
[i
]);
443 display_port_info_2(&ctr
.port
.info_2
[i
]);
446 printf("unknown info level %d\n", info_level
);
452 return W_ERROR_IS_OK(result
) ? NT_STATUS_OK
: NT_STATUS_UNSUCCESSFUL
;
455 /***********************************************************************
456 * Set printer comment - use a level2 set.
458 static NTSTATUS
cmd_spoolss_setprinter(struct cli_state
*cli
,
460 int argc
, char **argv
)
465 uint32 info_level
= 2;
466 BOOL opened_hnd
= False
;
467 PRINTER_INFO_CTR ctr
;
473 if (argc
== 1 || argc
> 3) {
474 printf("Usage: %s printername comment\n", argv
[0]);
479 /* Open a printer handle */
481 fstrcpy(comment
, argv
[2]);
484 slprintf (servername
, sizeof(fstring
)-1, "\\\\%s", cli
->desthost
);
485 strupper (servername
);
486 fstrcpy (printername
, argv
[1]);
487 fstrcpy (user
, cli
->user_name
);
489 /* get a printer handle */
490 result
= cli_spoolss_open_printer_ex(cli
, mem_ctx
, printername
, "",
491 MAXIMUM_ALLOWED_ACCESS
, servername
,
494 if (!W_ERROR_IS_OK(result
))
499 /* Get printer info */
500 result
= cli_spoolss_getprinter(cli
, mem_ctx
, 0, &needed
, &pol
, info_level
, &ctr
);
502 if (W_ERROR_V(result
) == ERRinsufficientbuffer
)
503 result
= cli_spoolss_getprinter(cli
, mem_ctx
, needed
, NULL
, &pol
, info_level
, &ctr
);
505 if (!W_ERROR_IS_OK(result
))
509 /* Modify the comment. */
510 init_unistr(&ctr
.printers_2
->comment
, comment
);
511 ctr
.printers_2
->devmode
= NULL
;
512 ctr
.printers_2
->secdesc
= NULL
;
514 result
= cli_spoolss_setprinter(cli
, mem_ctx
, &pol
, info_level
, &ctr
, 0);
515 if (W_ERROR_IS_OK(result
))
516 printf("Success in setting comment.\n");
520 cli_spoolss_close_printer(cli
, mem_ctx
, &pol
);
522 return W_ERROR_IS_OK(result
) ? NT_STATUS_OK
: NT_STATUS_UNSUCCESSFUL
;
525 /***********************************************************************
526 * Get printer information
528 static NTSTATUS
cmd_spoolss_getprinter(struct cli_state
*cli
,
530 int argc
, char **argv
)
534 uint32 info_level
= 1;
535 BOOL opened_hnd
= False
;
536 PRINTER_INFO_CTR ctr
;
542 if (argc
== 1 || argc
> 3) {
543 printf("Usage: %s <printername> [level]\n", argv
[0]);
547 /* Open a printer handle */
549 info_level
= atoi(argv
[2]);
552 slprintf (servername
, sizeof(fstring
)-1, "\\\\%s", cli
->desthost
);
553 strupper (servername
);
554 slprintf (printername
, sizeof(fstring
)-1, "%s\\%s", servername
, argv
[1]);
555 fstrcpy (user
, cli
->user_name
);
557 /* get a printer handle */
559 result
= cli_spoolss_open_printer_ex(cli
, mem_ctx
, printername
,
560 "", MAXIMUM_ALLOWED_ACCESS
,
561 servername
, user
, &pol
);
563 if (!W_ERROR_IS_OK(result
))
568 /* Get printer info */
570 result
= cli_spoolss_getprinter(cli
, mem_ctx
, 0, &needed
,
571 &pol
, info_level
, &ctr
);
573 if (W_ERROR_V(result
) == ERRinsufficientbuffer
)
574 result
= cli_spoolss_getprinter(
575 cli
, mem_ctx
, needed
, NULL
, &pol
, info_level
, &ctr
);
577 if (!W_ERROR_IS_OK(result
))
580 /* Display printer info */
582 switch (info_level
) {
584 display_print_info_0(ctr
.printers_0
);
587 display_print_info_1(ctr
.printers_1
);
590 display_print_info_2(ctr
.printers_2
);
593 display_print_info_3(ctr
.printers_3
);
596 printf("unknown info level %d\n", info_level
);
602 cli_spoolss_close_printer(cli
, mem_ctx
, &pol
);
604 return W_ERROR_IS_OK(result
) ? NT_STATUS_OK
: NT_STATUS_UNSUCCESSFUL
;
607 /****************************************************************************
608 printer info level 0 display function
609 ****************************************************************************/
610 static void display_print_driver_1(DRIVER_INFO_1
*i1
)
616 rpcstr_pull(name
, i1
->name
.buffer
, sizeof(name
), -1, STR_TERMINATE
);
618 printf ("Printer Driver Info 1:\n");
619 printf ("\tDriver Name: [%s]\n\n", name
);
624 /****************************************************************************
625 printer info level 1 display function
626 ****************************************************************************/
627 static void display_print_driver_2(DRIVER_INFO_2
*i1
)
630 fstring architecture
;
637 rpcstr_pull(name
, i1
->name
.buffer
, sizeof(name
), -1, STR_TERMINATE
);
638 rpcstr_pull(architecture
, i1
->architecture
.buffer
, sizeof(architecture
), -1, STR_TERMINATE
);
639 rpcstr_pull(driverpath
, i1
->driverpath
.buffer
, sizeof(driverpath
), -1, STR_TERMINATE
);
640 rpcstr_pull(datafile
, i1
->datafile
.buffer
, sizeof(datafile
), -1, STR_TERMINATE
);
641 rpcstr_pull(configfile
, i1
->configfile
.buffer
, sizeof(configfile
), -1, STR_TERMINATE
);
643 printf ("Printer Driver Info 2:\n");
644 printf ("\tVersion: [%x]\n", i1
->version
);
645 printf ("\tDriver Name: [%s]\n", name
);
646 printf ("\tArchitecture: [%s]\n", architecture
);
647 printf ("\tDriver Path: [%s]\n", driverpath
);
648 printf ("\tDatafile: [%s]\n", datafile
);
649 printf ("\tConfigfile: [%s]\n\n", configfile
);
654 /****************************************************************************
655 printer info level 2 display function
656 ****************************************************************************/
657 static void display_print_driver_3(DRIVER_INFO_3
*i1
)
660 fstring architecture
;
665 fstring dependentfiles
;
667 fstring defaultdatatype
;
675 rpcstr_pull(name
, i1
->name
.buffer
, sizeof(name
), -1, STR_TERMINATE
);
676 rpcstr_pull(architecture
, i1
->architecture
.buffer
, sizeof(architecture
), -1, STR_TERMINATE
);
677 rpcstr_pull(driverpath
, i1
->driverpath
.buffer
, sizeof(driverpath
), -1, STR_TERMINATE
);
678 rpcstr_pull(datafile
, i1
->datafile
.buffer
, sizeof(datafile
), -1, STR_TERMINATE
);
679 rpcstr_pull(configfile
, i1
->configfile
.buffer
, sizeof(configfile
), -1, STR_TERMINATE
);
680 rpcstr_pull(helpfile
, i1
->helpfile
.buffer
, sizeof(helpfile
), -1, STR_TERMINATE
);
681 rpcstr_pull(monitorname
, i1
->monitorname
.buffer
, sizeof(monitorname
), -1, STR_TERMINATE
);
682 rpcstr_pull(defaultdatatype
, i1
->defaultdatatype
.buffer
, sizeof(defaultdatatype
), -1, STR_TERMINATE
);
684 printf ("Printer Driver Info 3:\n");
685 printf ("\tVersion: [%x]\n", i1
->version
);
686 printf ("\tDriver Name: [%s]\n",name
);
687 printf ("\tArchitecture: [%s]\n", architecture
);
688 printf ("\tDriver Path: [%s]\n", driverpath
);
689 printf ("\tDatafile: [%s]\n", datafile
);
690 printf ("\tConfigfile: [%s]\n", configfile
);
691 printf ("\tHelpfile: [%s]\n\n", helpfile
);
695 rpcstr_pull(dependentfiles
, i1
->dependentfiles
+length
, sizeof(dependentfiles
), -1, STR_TERMINATE
);
697 length
+=strlen(dependentfiles
)+1;
699 if (strlen(dependentfiles
) > 0)
701 printf ("\tDependentfiles: [%s]\n", dependentfiles
);
711 printf ("\tMonitorname: [%s]\n", monitorname
);
712 printf ("\tDefaultdatatype: [%s]\n\n", defaultdatatype
);
717 /***********************************************************************
718 * Get printer information
720 static NTSTATUS
cmd_spoolss_getdriver(struct cli_state
*cli
,
722 int argc
, char **argv
)
727 uint32 info_level
= 3;
728 BOOL opened_hnd
= False
;
729 PRINTER_DRIVER_CTR ctr
;
735 if ((argc
== 1) || (argc
> 3))
737 printf("Usage: %s <printername> [level]\n", argv
[0]);
741 /* get the arguments need to open the printer handle */
742 slprintf (servername
, sizeof(fstring
)-1, "\\\\%s", cli
->desthost
);
743 strupper (servername
);
744 fstrcpy (user
, cli
->user_name
);
745 fstrcpy (printername
, argv
[1]);
747 info_level
= atoi(argv
[2]);
749 /* Open a printer handle */
751 werror
= cli_spoolss_open_printer_ex(cli
, mem_ctx
, printername
, "",
753 servername
, user
, &pol
);
755 result
= W_ERROR_IS_OK(werror
) ? NT_STATUS_OK
: NT_STATUS_UNSUCCESSFUL
;
757 if (!NT_STATUS_IS_OK(result
)) {
758 printf("Error opening printer handle for %s!\n", printername
);
764 /* loop through and print driver info level for each architecture */
766 for (i
=0; archi_table
[i
].long_archi
!=NULL
; i
++) {
769 werror
= cli_spoolss_getprinterdriver(
770 cli
, mem_ctx
, 0, &needed
, &pol
, info_level
,
771 archi_table
[i
].long_archi
, &ctr
);
773 if (W_ERROR_V(werror
) == ERRinsufficientbuffer
)
774 werror
= cli_spoolss_getprinterdriver(
775 cli
, mem_ctx
, needed
, NULL
, &pol
, info_level
,
776 archi_table
[i
].long_archi
, &ctr
);
778 if (!W_ERROR_IS_OK(werror
))
781 printf ("\n[%s]\n", archi_table
[i
].long_archi
);
783 switch (info_level
) {
785 display_print_driver_1 (ctr
.info1
);
788 display_print_driver_2 (ctr
.info2
);
791 display_print_driver_3 (ctr
.info3
);
794 printf("unknown info level %d\n", info_level
);
802 cli_spoolss_close_printer (cli
, mem_ctx
, &pol
);
804 return W_ERROR_IS_OK(result
) ? NT_STATUS_OK
: NT_STATUS_UNSUCCESSFUL
;
807 /***********************************************************************
808 * Get printer information
810 static NTSTATUS
cmd_spoolss_enum_drivers(struct cli_state
*cli
,
812 int argc
, char **argv
)
815 uint32 info_level
= 1;
816 PRINTER_DRIVER_CTR ctr
;
822 printf("Usage: enumdrivers [level]\n");
827 info_level
= atoi(argv
[1]);
830 /* loop through and print driver info level for each architecture */
831 for (i
=0; archi_table
[i
].long_archi
!=NULL
; i
++)
835 werror
= cli_spoolss_enumprinterdrivers(
836 cli
, mem_ctx
, 0, &needed
, info_level
,
837 archi_table
[i
].long_archi
, &returned
, &ctr
);
839 if (W_ERROR_V(werror
) == ERRinsufficientbuffer
)
840 werror
= cli_spoolss_enumprinterdrivers(
841 cli
, mem_ctx
, needed
, NULL
, info_level
,
842 archi_table
[i
].long_archi
, &returned
, &ctr
);
847 if (!W_ERROR_IS_OK(werror
)) {
848 printf ("Error getting driver for environment [%s] - %d\n",
849 archi_table
[i
].long_archi
, W_ERROR_V(werror
));
853 printf ("\n[%s]\n", archi_table
[i
].long_archi
);
858 for (j
=0; j
< returned
; j
++) {
859 display_print_driver_1 (&(ctr
.info1
[j
]));
863 for (j
=0; j
< returned
; j
++) {
864 display_print_driver_2 (&(ctr
.info2
[j
]));
868 for (j
=0; j
< returned
; j
++) {
869 display_print_driver_3 (&(ctr
.info3
[j
]));
873 printf("unknown info level %d\n", info_level
);
878 return W_ERROR_IS_OK(werror
) ? NT_STATUS_OK
: NT_STATUS_UNSUCCESSFUL
;
881 /****************************************************************************
882 printer info level 1 display function
883 ****************************************************************************/
884 static void display_printdriverdir_1(DRIVER_DIRECTORY_1
*i1
)
890 rpcstr_pull(name
, i1
->name
.buffer
, sizeof(name
), -1, STR_TERMINATE
);
892 printf ("\tDirectory Name:[%s]\n", name
);
895 /***********************************************************************
896 * Get printer driver directory information
898 static NTSTATUS
cmd_spoolss_getdriverdir(struct cli_state
*cli
,
900 int argc
, char **argv
)
904 DRIVER_DIRECTORY_CTR ctr
;
908 printf("Usage: %s [environment]\n", argv
[0]);
912 /* Get the arguments need to open the printer handle */
915 fstrcpy (env
, argv
[1]);
917 fstrcpy (env
, "Windows NT x86");
919 /* Get the directory. Only use Info level 1 */
921 result
= cli_spoolss_getprinterdriverdir(
922 cli
, mem_ctx
, 0, &needed
, 1, env
, &ctr
);
924 if (W_ERROR_V(result
) == ERRinsufficientbuffer
)
925 result
= cli_spoolss_getprinterdriverdir(
926 cli
, mem_ctx
, needed
, NULL
, 1, env
, &ctr
);
928 if (W_ERROR_IS_OK(result
))
929 display_printdriverdir_1(ctr
.info1
);
931 return W_ERROR_IS_OK(result
) ? NT_STATUS_OK
: NT_STATUS_UNSUCCESSFUL
;
934 /*******************************************************************************
935 set the version and environment fields of a DRIVER_INFO_3 struct
936 ******************************************************************************/
937 void set_drv_info_3_env (DRIVER_INFO_3
*info
, const char *arch
)
942 for (i
=0; archi_table
[i
].long_archi
!= NULL
; i
++)
944 if (strcmp(arch
, archi_table
[i
].short_archi
) == 0)
946 info
->version
= archi_table
[i
].version
;
947 init_unistr (&info
->architecture
, archi_table
[i
].long_archi
);
952 if (archi_table
[i
].long_archi
== NULL
)
954 DEBUG(0, ("set_drv_info_3_env: Unknown arch [%s]\n", arch
));
961 /**************************************************************************
962 wrapper for strtok to get the next parameter from a delimited list.
963 Needed to handle the empty parameter string denoted by "NULL"
964 *************************************************************************/
965 static char* get_driver_3_param (char* str
, char* delim
, UNISTR
* dest
)
969 /* get the next token */
970 ptr
= strtok(str
, delim
);
972 /* a string of 'NULL' is used to represent an empty
973 parameter because two consecutive delimiters
974 will not return an empty string. See man strtok(3)
976 if (StrCaseCmp(ptr
, "NULL") == 0)
980 init_unistr(dest
, ptr
);
985 /********************************************************************************
986 fill in the members of a DRIVER_INFO_3 struct using a character
987 string in the form of
988 <Long Printer Name>:<Driver File Name>:<Data File Name>:\
989 <Config File Name>:<Help File Name>:<Language Monitor Name>:\
990 <Default Data Type>:<Comma Separated list of Files>
991 *******************************************************************************/
992 static BOOL
init_drv_info_3_members (
1001 /* fill in the UNISTR fields */
1002 str
= get_driver_3_param (args
, ":", &info
->name
);
1003 str
= get_driver_3_param (NULL
, ":", &info
->driverpath
);
1004 str
= get_driver_3_param (NULL
, ":", &info
->datafile
);
1005 str
= get_driver_3_param (NULL
, ":", &info
->configfile
);
1006 str
= get_driver_3_param (NULL
, ":", &info
->helpfile
);
1007 str
= get_driver_3_param (NULL
, ":", &info
->monitorname
);
1008 str
= get_driver_3_param (NULL
, ":", &info
->defaultdatatype
);
1010 /* <Comma Separated List of Dependent Files> */
1011 str2
= get_driver_3_param (NULL
, ":", NULL
); /* save the beginning of the string */
1014 /* begin to strip out each filename */
1015 str
= strtok(str
, ",");
1019 /* keep a cumlative count of the str lengths */
1020 len
+= strlen(str
)+1;
1021 str
= strtok(NULL
, ",");
1024 /* allocate the space; add one extra slot for a terminating NULL.
1025 Each filename is NULL terminated and the end contains a double
1027 if ((info
->dependentfiles
=(uint16
*)talloc(mem_ctx
, (len
+1)*sizeof(uint16
))) == NULL
)
1029 DEBUG(0,("init_drv_info_3_members: Unable to malloc memory for dependenfiles\n"));
1032 for (i
=0; i
<len
; i
++)
1034 info
->dependentfiles
[i
] = SSVAL(&info
->dependentfiles
[i
], 0, str2
[i
]);
1036 info
->dependentfiles
[len
] = '\0';
1042 static NTSTATUS
cmd_spoolss_addprinterdriver(struct cli_state
*cli
,
1043 TALLOC_CTX
*mem_ctx
,
1044 int argc
, char **argv
)
1048 PRINTER_DRIVER_CTR ctr
;
1049 DRIVER_INFO_3 info3
;
1051 fstring driver_name
;
1053 /* parse the command arguements */
1056 printf ("Usage: %s <Environment>\\\n", argv
[0]);
1057 printf ("\t<Long Printer Name>:<Driver File Name>:<Data File Name>:\\\n");
1058 printf ("\t<Config File Name>:<Help File Name>:<Language Monitor Name>:\\\n");
1059 printf ("\t<Default Data Type>:<Comma Separated list of Files>\n");
1061 return NT_STATUS_OK
;
1064 /* Fill in the DRIVER_INFO_3 struct */
1066 if (!get_short_archi(arch
, argv
[1]))
1068 printf ("Error Unknown architechture [%s]\n", argv
[1]);
1069 return NT_STATUS_INVALID_PARAMETER
;
1072 set_drv_info_3_env(&info3
, arch
);
1074 if (!init_drv_info_3_members(mem_ctx
, &info3
, argv
[2]))
1076 printf ("Error Invalid parameter list - %s.\n", argv
[2]);
1077 return NT_STATUS_INVALID_PARAMETER
;
1082 result
= cli_spoolss_addprinterdriver (cli
, mem_ctx
, level
, &ctr
);
1084 if (W_ERROR_IS_OK(result
)) {
1085 rpcstr_pull(driver_name
, info3
.name
.buffer
,
1086 sizeof(driver_name
), -1, STR_TERMINATE
);
1087 printf ("Printer Driver %s successfully installed.\n",
1091 return W_ERROR_IS_OK(result
) ? NT_STATUS_OK
: NT_STATUS_UNSUCCESSFUL
;
1095 static NTSTATUS
cmd_spoolss_addprinterex(struct cli_state
*cli
,
1096 TALLOC_CTX
*mem_ctx
,
1097 int argc
, char **argv
)
1101 PRINTER_INFO_CTR ctr
;
1102 PRINTER_INFO_2 info2
;
1105 /* parse the command arguements */
1108 printf ("Usage: %s <name> <shared name> <driver> <port>\n", argv
[0]);
1109 return NT_STATUS_OK
;
1112 slprintf (servername
, sizeof(fstring
)-1, "\\\\%s", cli
->desthost
);
1113 strupper (servername
);
1115 /* Fill in the DRIVER_INFO_3 struct */
1118 init_unistr( &info2
.servername
, servername
);
1120 init_unistr( &info2
.printername
, argv
[1]);
1121 init_unistr( &info2
.sharename
, argv
[2]);
1122 init_unistr( &info2
.drivername
, argv
[3]);
1123 init_unistr( &info2
.portname
, argv
[4]);
1124 init_unistr( &info2
.comment
, "Created by rpcclient");
1125 init_unistr( &info2
.printprocessor
, "winprint");
1126 init_unistr( &info2
.datatype
, "RAW");
1127 info2
.devmode
= NULL
;
1128 info2
.secdesc
= NULL
;
1129 info2
.attributes
= PRINTER_ATTRIBUTE_SHARED
;
1131 info2
.defaultpriority
= 0;
1132 info2
.starttime
= 0;
1133 info2
.untiltime
= 0;
1135 /* These three fields must not be used by AddPrinter()
1136 as defined in the MS Platform SDK documentation..
1140 info2.averageppm = 0;
1143 ctr
.printers_2
= &info2
;
1144 result
= cli_spoolss_addprinterex (cli
, mem_ctx
, level
, &ctr
);
1146 if (W_ERROR_IS_OK(result
))
1147 printf ("Printer %s successfully installed.\n", argv
[1]);
1149 return W_ERROR_IS_OK(result
) ? NT_STATUS_OK
: NT_STATUS_UNSUCCESSFUL
;
1152 static NTSTATUS
cmd_spoolss_setdriver(struct cli_state
*cli
,
1153 TALLOC_CTX
*mem_ctx
,
1154 int argc
, char **argv
)
1159 BOOL opened_hnd
= False
;
1160 PRINTER_INFO_CTR ctr
;
1161 PRINTER_INFO_2 info2
;
1167 /* parse the command arguements */
1170 printf ("Usage: %s <printer> <driver>\n", argv
[0]);
1171 return NT_STATUS_OK
;
1174 slprintf (servername
, sizeof(fstring
)-1, "\\\\%s", cli
->desthost
);
1175 strupper (servername
);
1176 slprintf (printername
, sizeof(fstring
)-1, "%s\\%s", servername
, argv
[1]);
1177 fstrcpy (user
, cli
->user_name
);
1179 /* Get a printer handle */
1181 result
= cli_spoolss_open_printer_ex(cli
, mem_ctx
, printername
, "",
1182 MAXIMUM_ALLOWED_ACCESS
,
1183 servername
, user
, &pol
);
1185 if (!W_ERROR_IS_OK(result
))
1190 /* Get printer info */
1192 ZERO_STRUCT (info2
);
1193 ctr
.printers_2
= &info2
;
1195 result
= cli_spoolss_getprinter(cli
, mem_ctx
, 0, &needed
,
1198 if (W_ERROR_V(result
) == ERRinsufficientbuffer
)
1199 result
= cli_spoolss_getprinter(
1200 cli
, mem_ctx
, needed
, NULL
, &pol
, level
, &ctr
);
1202 if (!W_ERROR_IS_OK(result
)) {
1203 printf ("Unable to retrieve printer information!\n");
1207 /* Set the printer driver */
1209 init_unistr(&ctr
.printers_2
->drivername
, argv
[2]);
1211 result
= cli_spoolss_setprinter(cli
, mem_ctx
, &pol
, level
, &ctr
, 0);
1213 if (!W_ERROR_IS_OK(result
)) {
1214 printf("SetPrinter call failed!\n");
1218 printf("Succesfully set %s to driver %s.\n", argv
[1], argv
[2]);
1224 cli_spoolss_close_printer(cli
, mem_ctx
, &pol
);
1226 return W_ERROR_IS_OK(result
) ? NT_STATUS_OK
: NT_STATUS_UNSUCCESSFUL
;
1230 static NTSTATUS
cmd_spoolss_deletedriver(struct cli_state
*cli
,
1231 TALLOC_CTX
*mem_ctx
,
1232 int argc
, char **argv
)
1238 /* parse the command arguements */
1241 printf ("Usage: %s <driver>\n", argv
[0]);
1242 return NT_STATUS_OK
;
1245 slprintf (servername
, sizeof(fstring
)-1, "\\\\%s", cli
->desthost
);
1246 strupper (servername
);
1248 /* delete the driver for all architectures */
1249 for (i
=0; archi_table
[i
].long_archi
; i
++)
1251 /* make the call to remove the driver */
1252 result
= cli_spoolss_deleteprinterdriver(
1253 cli
, mem_ctx
, archi_table
[i
].long_archi
, argv
[1]);
1255 if (!W_ERROR_IS_OK(result
)) {
1256 printf ("Failed to remove driver %s for arch [%s] - error 0x%x!\n",
1257 argv
[1], archi_table
[i
].long_archi
,
1260 printf ("Driver %s removed for arch [%s].\n", argv
[1],
1261 archi_table
[i
].long_archi
);
1264 return W_ERROR_IS_OK(result
) ? NT_STATUS_OK
: NT_STATUS_UNSUCCESSFUL
;
1267 static NTSTATUS
cmd_spoolss_getprintprocdir(struct cli_state
*cli
,
1268 TALLOC_CTX
*mem_ctx
,
1269 int argc
, char **argv
)
1272 char *servername
= NULL
, *environment
= NULL
;
1276 /* parse the command arguements */
1278 printf ("Usage: %s [environment]\n", argv
[0]);
1279 return NT_STATUS_OK
;
1282 if (asprintf(&servername
, "\\\\%s", cli
->desthost
) < 0)
1283 return NT_STATUS_NO_MEMORY
;
1284 strupper(servername
);
1286 if (asprintf(&environment
, "%s", (argc
== 2) ? argv
[1] :
1287 PRINTER_DRIVER_ARCHITECTURE
) < 0) {
1288 SAFE_FREE(servername
);
1289 return NT_STATUS_NO_MEMORY
;
1292 result
= cli_spoolss_getprintprocessordirectory(
1293 cli
, mem_ctx
, 0, &needed
, servername
, environment
, procdir
);
1295 if (W_ERROR_V(result
) == ERRinsufficientbuffer
)
1296 result
= cli_spoolss_getprintprocessordirectory(
1297 cli
, mem_ctx
, needed
, NULL
, servername
, environment
,
1300 if (W_ERROR_IS_OK(result
))
1301 printf("%s\n", procdir
);
1303 SAFE_FREE(servername
);
1304 SAFE_FREE(environment
);
1306 return W_ERROR_IS_OK(result
) ? NT_STATUS_OK
: NT_STATUS_UNSUCCESSFUL
;
1311 static NTSTATUS
cmd_spoolss_addform(struct cli_state
*cli
, TALLOC_CTX
*mem_ctx
,
1312 int argc
, char **argv
)
1316 char *servername
= NULL
, *printername
= NULL
;
1318 BOOL got_handle
= False
;
1320 /* Parse the command arguements */
1323 printf ("Usage: %s <printer> <formname>\n", argv
[0]);
1324 return NT_STATUS_OK
;
1327 /* Get a printer handle */
1329 asprintf(&servername
, "\\\\%s", cli
->desthost
);
1330 strupper(servername
);
1331 asprintf(&printername
, "%s\\%s", servername
, argv
[1]);
1333 werror
= cli_spoolss_open_printer_ex(cli
, mem_ctx
, printername
, "",
1334 MAXIMUM_ALLOWED_ACCESS
,
1335 servername
, cli
->user_name
, &handle
);
1337 if (!W_ERROR_IS_OK(werror
))
1342 /* Dummy up some values for the form data */
1344 form
.flags
= FORM_USER
;
1345 form
.size_x
= form
.size_y
= 100;
1351 init_unistr2(&form
.name
, argv
[2], strlen(argv
[2]) + 1);
1356 werror
= cli_spoolss_addform(cli
, mem_ctx
, &handle
, 1, &form
);
1360 cli_spoolss_close_printer(cli
, mem_ctx
, &handle
);
1362 SAFE_FREE(servername
);
1363 SAFE_FREE(printername
);
1365 return W_ERROR_IS_OK(werror
) ? NT_STATUS_OK
: NT_STATUS_UNSUCCESSFUL
;
1370 static NTSTATUS
cmd_spoolss_setform(struct cli_state
*cli
, TALLOC_CTX
*mem_ctx
,
1371 int argc
, char **argv
)
1375 char *servername
= NULL
, *printername
= NULL
;
1377 BOOL got_handle
= False
;
1379 /* Parse the command arguements */
1382 printf ("Usage: %s <printer> <formname>\n", argv
[0]);
1383 return NT_STATUS_OK
;
1386 /* Get a printer handle */
1388 asprintf(&servername
, "\\\\%s", cli
->desthost
);
1389 strupper(servername
);
1390 asprintf(&printername
, "%s\\%s", servername
, argv
[1]);
1392 werror
= cli_spoolss_open_printer_ex(
1393 cli
, mem_ctx
, printername
, "", MAXIMUM_ALLOWED_ACCESS
,
1394 servername
, cli
->user_name
, &handle
);
1396 if (!W_ERROR_IS_OK(werror
))
1401 /* Dummy up some values for the form data */
1403 form
.flags
= FORM_PRINTER
;
1404 form
.size_x
= form
.size_y
= 100;
1410 init_unistr2(&form
.name
, argv
[2], strlen(argv
[2]) + 1);
1414 werror
= cli_spoolss_setform(cli
, mem_ctx
, &handle
, 1, argv
[2], &form
);
1418 cli_spoolss_close_printer(cli
, mem_ctx
, &handle
);
1420 SAFE_FREE(servername
);
1421 SAFE_FREE(printername
);
1423 return W_ERROR_IS_OK(werror
) ? NT_STATUS_OK
: NT_STATUS_UNSUCCESSFUL
;
1428 static NTSTATUS
cmd_spoolss_getform(struct cli_state
*cli
, TALLOC_CTX
*mem_ctx
,
1429 int argc
, char **argv
)
1433 char *servername
= NULL
, *printername
= NULL
;
1435 BOOL got_handle
= False
;
1438 /* Parse the command arguements */
1441 printf ("Usage: %s <printer> <formname>\n", argv
[0]);
1442 return NT_STATUS_OK
;
1445 /* Get a printer handle */
1447 asprintf(&servername
, "\\\\%s", cli
->desthost
);
1448 strupper(servername
);
1449 asprintf(&printername
, "%s\\%s", servername
, argv
[1]);
1451 werror
= cli_spoolss_open_printer_ex(
1452 cli
, mem_ctx
, printername
, "", MAXIMUM_ALLOWED_ACCESS
,
1453 servername
, cli
->user_name
, &handle
);
1455 if (!W_ERROR_IS_OK(werror
))
1462 werror
= cli_spoolss_getform(cli
, mem_ctx
, 0, &needed
,
1463 &handle
, argv
[2], 1, &form
);
1465 if (W_ERROR_V(werror
) == ERRinsufficientbuffer
)
1466 werror
= cli_spoolss_getform(cli
, mem_ctx
, needed
, NULL
,
1467 &handle
, argv
[2], 1, &form
);
1469 if (!W_ERROR_IS_OK(werror
))
1472 printf("width: %d\n", form
.width
);
1473 printf("length: %d\n", form
.length
);
1474 printf("left: %d\n", form
.left
);
1475 printf("top: %d\n", form
.top
);
1476 printf("right: %d\n", form
.right
);
1477 printf("bottom: %d\n", form
.bottom
);
1481 cli_spoolss_close_printer(cli
, mem_ctx
, &handle
);
1483 SAFE_FREE(servername
);
1484 SAFE_FREE(printername
);
1486 return W_ERROR_IS_OK(werror
) ? NT_STATUS_OK
: NT_STATUS_UNSUCCESSFUL
;
1491 static NTSTATUS
cmd_spoolss_deleteform(struct cli_state
*cli
,
1492 TALLOC_CTX
*mem_ctx
, int argc
,
1497 char *servername
= NULL
, *printername
= NULL
;
1498 BOOL got_handle
= False
;
1500 /* Parse the command arguements */
1503 printf ("Usage: %s <printer> <formname>\n", argv
[0]);
1504 return NT_STATUS_OK
;
1507 /* Get a printer handle */
1509 asprintf(&servername
, "\\\\%s", cli
->desthost
);
1510 strupper(servername
);
1511 asprintf(&printername
, "%s\\%s", servername
, argv
[1]);
1513 werror
= cli_spoolss_open_printer_ex(
1514 cli
, mem_ctx
, printername
, "", MAXIMUM_ALLOWED_ACCESS
,
1515 servername
, cli
->user_name
, &handle
);
1517 if (!W_ERROR_IS_OK(werror
))
1522 /* Delete the form */
1524 werror
= cli_spoolss_deleteform(cli
, mem_ctx
, &handle
, argv
[2]);
1528 cli_spoolss_close_printer(cli
, mem_ctx
, &handle
);
1530 SAFE_FREE(servername
);
1531 SAFE_FREE(printername
);
1533 return W_ERROR_IS_OK(werror
) ? NT_STATUS_OK
: NT_STATUS_UNSUCCESSFUL
;
1536 /* Enumerate forms */
1538 static NTSTATUS
cmd_spoolss_enum_forms(struct cli_state
*cli
,
1539 TALLOC_CTX
*mem_ctx
, int argc
,
1544 char *servername
= NULL
, *printername
= NULL
;
1545 BOOL got_handle
= False
;
1546 uint32 needed
, num_forms
, level
= 1, i
;
1549 /* Parse the command arguements */
1552 printf ("Usage: %s <printer>\n", argv
[0]);
1553 return NT_STATUS_OK
;
1556 /* Get a printer handle */
1558 asprintf(&servername
, "\\\\%s", cli
->desthost
);
1559 strupper(servername
);
1560 asprintf(&printername
, "%s\\%s", servername
, argv
[1]);
1562 werror
= cli_spoolss_open_printer_ex(
1563 cli
, mem_ctx
, printername
, "", MAXIMUM_ALLOWED_ACCESS
,
1564 servername
, cli
->user_name
, &handle
);
1566 if (!W_ERROR_IS_OK(werror
))
1571 /* Enumerate forms */
1573 werror
= cli_spoolss_enumforms(
1574 cli
, mem_ctx
, 0, &needed
, &handle
, level
, &num_forms
, &forms
);
1576 if (W_ERROR_V(werror
) == ERRinsufficientbuffer
)
1577 werror
= cli_spoolss_enumforms(
1578 cli
, mem_ctx
, needed
, NULL
, &handle
, level
,
1579 &num_forms
, &forms
);
1581 if (!W_ERROR_IS_OK(werror
))
1584 /* Display output */
1586 for (i
= 0; i
< num_forms
; i
++) {
1589 if (forms
[i
].name
.buffer
)
1590 rpcstr_pull(form_name
, forms
[i
].name
.buffer
,
1591 sizeof(form_name
), -1, STR_TERMINATE
);
1593 printf("%s\n", form_name
);
1598 cli_spoolss_close_printer(cli
, mem_ctx
, &handle
);
1600 SAFE_FREE(servername
);
1601 SAFE_FREE(printername
);
1603 return W_ERROR_IS_OK(werror
) ? NT_STATUS_OK
: NT_STATUS_UNSUCCESSFUL
;
1606 static NTSTATUS
cmd_spoolss_setprinterdata(struct cli_state
*cli
,
1607 TALLOC_CTX
*mem_ctx
,
1608 int argc
, char **argv
)
1612 fstring servername
, printername
, user
;
1614 BOOL opened_hnd
= False
;
1615 PRINTER_INFO_CTR ctr
;
1616 PRINTER_INFO_0
*info
= NULL
;
1618 /* parse the command arguements */
1620 printf ("Usage: %s <printer> <value> <data>\n", argv
[0]);
1621 return NT_STATUS_OK
;
1624 slprintf (servername
, sizeof(fstring
)-1, "\\\\%s", cli
->desthost
);
1625 strupper (servername
);
1626 slprintf (printername
, sizeof(fstring
)-1, "%s\\%s", servername
, argv
[1]);
1627 fstrcpy (user
, cli
->user_name
);
1629 /* get a printer handle */
1630 result
= cli_spoolss_open_printer_ex(cli
, mem_ctx
, printername
, "",
1631 MAXIMUM_ALLOWED_ACCESS
, servername
,
1633 if (!W_ERROR_IS_OK(result
))
1638 result
= cli_spoolss_getprinter(cli
, mem_ctx
, 0, &needed
,
1641 if (W_ERROR_V(result
) == ERRinsufficientbuffer
)
1642 result
= cli_spoolss_getprinter(cli
, mem_ctx
, needed
, NULL
, &pol
, 0, &ctr
);
1644 if (!W_ERROR_IS_OK(result
))
1647 printf("%s\n", timestring(True
));
1648 printf("\tchange_id (before set)\t:[0x%x]\n", info
->change_id
);
1650 /* Set the printer data */
1652 result
= cli_spoolss_setprinterdata(
1653 cli
, mem_ctx
, &pol
, argv
[2], REG_SZ
, argv
[3],
1654 strlen(argv
[3]) + 1);
1656 if (!W_ERROR_IS_OK(result
)) {
1657 printf ("Unable to set [%s=%s]!\n", argv
[2], argv
[3]);
1660 printf("\tSetPrinterData succeeded [%s: %s]\n", argv
[2], argv
[3]);
1662 result
= cli_spoolss_getprinter(cli
, mem_ctx
, 0, &needed
, &pol
, 0, &ctr
);
1664 if (W_ERROR_V(result
) == ERRinsufficientbuffer
)
1665 result
= cli_spoolss_getprinter(cli
, mem_ctx
, needed
, NULL
, &pol
, 0, &ctr
);
1667 if (!W_ERROR_IS_OK(result
))
1670 printf("%s\n", timestring(True
));
1671 printf("\tchange_id (after set)\t:[0x%x]\n", info
->change_id
);
1676 cli_spoolss_close_printer(cli
, mem_ctx
, &pol
);
1678 return W_ERROR_IS_OK(result
) ? NT_STATUS_OK
: NT_STATUS_UNSUCCESSFUL
;
1681 static void display_job_info_1(JOB_INFO_1
*job
)
1683 fstring username
= "", document
= "", text_status
= "";
1685 if (job
->username
.buffer
)
1686 rpcstr_pull(username
, job
->username
.buffer
,
1687 sizeof(username
), -1, STR_TERMINATE
);
1689 if (job
->document
.buffer
)
1690 rpcstr_pull(document
, job
->document
.buffer
,
1691 sizeof(document
), -1, STR_TERMINATE
);
1693 if (job
->text_status
.buffer
)
1694 rpcstr_pull(text_status
, job
->text_status
.buffer
,
1695 sizeof(text_status
), -1, STR_TERMINATE
);
1697 printf("%d: jobid[%d]: %s %s %s %d/%d pages\n", job
->position
, job
->jobid
,
1698 username
, document
, text_status
, job
->pagesprinted
,
1702 static void display_job_info_2(JOB_INFO_2
*job
)
1704 fstring username
= "", document
= "", text_status
= "";
1706 if (job
->username
.buffer
)
1707 rpcstr_pull(username
, job
->username
.buffer
,
1708 sizeof(username
), -1, STR_TERMINATE
);
1710 if (job
->document
.buffer
)
1711 rpcstr_pull(document
, job
->document
.buffer
,
1712 sizeof(document
), -1, STR_TERMINATE
);
1714 if (job
->text_status
.buffer
)
1715 rpcstr_pull(text_status
, job
->text_status
.buffer
,
1716 sizeof(text_status
), -1, STR_TERMINATE
);
1718 printf("%d: jobid[%d]: %s %s %s %d/%d pages, %d bytes\n", job
->position
, job
->jobid
,
1719 username
, document
, text_status
, job
->pagesprinted
,
1720 job
->totalpages
, job
->size
);
1723 /* Enumerate jobs */
1725 static NTSTATUS
cmd_spoolss_enum_jobs(struct cli_state
*cli
,
1726 TALLOC_CTX
*mem_ctx
, int argc
,
1730 uint32 needed
, level
= 1, num_jobs
, i
;
1731 BOOL got_hnd
= False
;
1732 pstring printername
;
1733 fstring servername
, user
;
1737 if (argc
< 2 || argc
> 3) {
1738 printf("Usage: %s printername [level]\n", argv
[0]);
1739 return NT_STATUS_OK
;
1743 level
= atoi(argv
[2]);
1745 /* Open printer handle */
1747 slprintf(servername
, sizeof(fstring
)-1, "\\\\%s", cli
->desthost
);
1748 strupper(servername
);
1749 fstrcpy(user
, cli
->user_name
);
1750 fstrcpy(printername
, argv
[1]);
1751 slprintf(printername
, sizeof(pstring
)-1, "\\\\%s\\", cli
->desthost
);
1752 strupper(printername
);
1753 pstrcat(printername
, argv
[1]);
1755 result
= cli_spoolss_open_printer_ex(cli
, mem_ctx
, printername
,
1756 "", MAXIMUM_ALLOWED_ACCESS
,
1757 servername
, user
, &hnd
);
1759 if (!W_ERROR_IS_OK(result
))
1764 /* Enumerate ports */
1766 result
= cli_spoolss_enumjobs(
1767 cli
, mem_ctx
, 0, &needed
, &hnd
, level
, 0, 1000,
1770 if (W_ERROR_V(result
) == ERRinsufficientbuffer
)
1771 result
= cli_spoolss_enumjobs(
1772 cli
, mem_ctx
, needed
, NULL
, &hnd
, level
, 0,
1773 1000, &num_jobs
, &ctr
);
1775 if (!W_ERROR_IS_OK(result
))
1778 for (i
= 0; i
< num_jobs
; i
++) {
1781 display_job_info_1(ctr
.job
.job_info_1
[i
]);
1784 display_job_info_2(ctr
.job
.job_info_2
[i
]);
1787 d_printf("unknown info level %d\n", level
);
1794 cli_spoolss_close_printer(cli
, mem_ctx
, &hnd
);
1796 return W_ERROR_IS_OK(result
) ? NT_STATUS_OK
: NT_STATUS_UNSUCCESSFUL
;
1799 /* List of commands exported by this module */
1800 struct cmd_set spoolss_commands
[] = {
1804 { "adddriver", cmd_spoolss_addprinterdriver
, PIPE_SPOOLSS
, "Add a print driver", "" },
1805 { "addprinter", cmd_spoolss_addprinterex
, PIPE_SPOOLSS
, "Add a printer", "" },
1806 { "deldriver", cmd_spoolss_deletedriver
, PIPE_SPOOLSS
, "Delete a printer driver", "" },
1807 { "enumdata", cmd_spoolss_not_implemented
, PIPE_SPOOLSS
, "Enumerate printer data (*)", "" },
1808 { "enumjobs", cmd_spoolss_enum_jobs
, PIPE_SPOOLSS
, "Enumerate print jobs", "" },
1809 { "enumports", cmd_spoolss_enum_ports
, PIPE_SPOOLSS
, "Enumerate printer ports", "" },
1810 { "enumdrivers", cmd_spoolss_enum_drivers
, PIPE_SPOOLSS
, "Enumerate installed printer drivers", "" },
1811 { "enumprinters", cmd_spoolss_enum_printers
, PIPE_SPOOLSS
, "Enumerate printers", "" },
1812 { "getdata", cmd_spoolss_not_implemented
, PIPE_SPOOLSS
, "Get print driver data (*)", "" },
1813 { "getdriver", cmd_spoolss_getdriver
, PIPE_SPOOLSS
, "Get print driver information", "" },
1814 { "getdriverdir", cmd_spoolss_getdriverdir
, PIPE_SPOOLSS
, "Get print driver upload directory", "" },
1815 { "getprinter", cmd_spoolss_getprinter
, PIPE_SPOOLSS
, "Get printer info", "" },
1816 { "getprintprocdir", cmd_spoolss_getprintprocdir
, PIPE_SPOOLSS
, "Get print processor directory", "" },
1817 { "openprinter", cmd_spoolss_open_printer_ex
, PIPE_SPOOLSS
, "Open printer handle", "" },
1818 { "setdriver", cmd_spoolss_setdriver
, PIPE_SPOOLSS
, "Set printer driver", "" },
1819 { "getprintprocdir", cmd_spoolss_getprintprocdir
, PIPE_SPOOLSS
, "Get print processor directory", "" },
1820 { "addform", cmd_spoolss_addform
, PIPE_SPOOLSS
, "Add form", "" },
1821 { "setform", cmd_spoolss_setform
, PIPE_SPOOLSS
, "Set form", "" },
1822 { "getform", cmd_spoolss_getform
, PIPE_SPOOLSS
, "Get form", "" },
1823 { "deleteform", cmd_spoolss_deleteform
, PIPE_SPOOLSS
, "Delete form", "" },
1824 { "enumforms", cmd_spoolss_enum_forms
, PIPE_SPOOLSS
, "Enumerate forms", "" },
1825 { "setprinter", cmd_spoolss_setprinter
, PIPE_SPOOLSS
, "Set printer comment", "" },
1826 { "setprinterdata", cmd_spoolss_setprinterdata
, PIPE_SPOOLSS
, "Set REG_SZ printer data", "" },