2 Unix SMB/CIFS implementation.
5 Copyright (C) Gerald Carter 2001-2002,
6 Copyright (C) Tim Potter 2000-2002,
7 Copyright (C) Andrew Tridgell 1994-2000,
8 Copyright (C) Luke Kenneth Casson Leighton 1996-2000,
9 Copyright (C) Jean-Francois Micouleau 1999-2000.
11 This program is free software; you can redistribute it and/or modify
12 it under the terms of the GNU General Public License as published by
13 the Free Software Foundation; either version 2 of the License, or
14 (at your option) any later version.
16 This program is distributed in the hope that it will be useful,
17 but WITHOUT ANY WARRANTY; without even the implied warranty of
18 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 GNU General Public License for more details.
21 You should have received a copy of the GNU General Public License
22 along with this program; if not, write to the Free Software
23 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
28 /** @defgroup spoolss SPOOLSS - NT printing routines
34 /**********************************************************************
35 Initialize a new spoolss buff for use by a client rpc
36 **********************************************************************/
37 static void init_buffer(NEW_BUFFER
*buffer
, uint32 size
, TALLOC_CTX
*ctx
)
39 buffer
->ptr
= (size
!= 0);
41 buffer
->string_at_end
= size
;
42 prs_init(&buffer
->prs
, size
, ctx
, MARSHALL
);
43 buffer
->struct_start
= prs_offset(&buffer
->prs
);
46 /*********************************************************************
47 Decode various spoolss rpc's and info levels
48 ********************************************************************/
50 /**********************************************************************
51 **********************************************************************/
52 static void decode_printer_info_0(TALLOC_CTX
*mem_ctx
, NEW_BUFFER
*buffer
,
53 uint32 returned
, PRINTER_INFO_0
**info
)
58 inf
=(PRINTER_INFO_0
*)talloc(mem_ctx
, returned
*sizeof(PRINTER_INFO_0
));
60 buffer
->prs
.data_offset
=0;
62 for (i
=0; i
<returned
; i
++) {
63 smb_io_printer_info_0("", buffer
, &inf
[i
], 0);
69 /**********************************************************************
70 **********************************************************************/
71 static void decode_printer_info_1(TALLOC_CTX
*mem_ctx
, NEW_BUFFER
*buffer
,
72 uint32 returned
, PRINTER_INFO_1
**info
)
77 inf
=(PRINTER_INFO_1
*)talloc(mem_ctx
, returned
*sizeof(PRINTER_INFO_1
));
79 buffer
->prs
.data_offset
=0;
81 for (i
=0; i
<returned
; i
++) {
82 smb_io_printer_info_1("", buffer
, &inf
[i
], 0);
88 /**********************************************************************
89 **********************************************************************/
90 static void decode_printer_info_2(TALLOC_CTX
*mem_ctx
, NEW_BUFFER
*buffer
,
91 uint32 returned
, PRINTER_INFO_2
**info
)
96 inf
=(PRINTER_INFO_2
*)talloc(mem_ctx
, returned
*sizeof(PRINTER_INFO_2
));
98 buffer
->prs
.data_offset
=0;
100 for (i
=0; i
<returned
; i
++) {
101 /* a little initialization as we go */
102 inf
[i
].secdesc
= NULL
;
103 smb_io_printer_info_2("", buffer
, &inf
[i
], 0);
109 /**********************************************************************
110 **********************************************************************/
111 static void decode_printer_info_3(TALLOC_CTX
*mem_ctx
, NEW_BUFFER
*buffer
,
112 uint32 returned
, PRINTER_INFO_3
**info
)
117 inf
=(PRINTER_INFO_3
*)talloc(mem_ctx
, returned
*sizeof(PRINTER_INFO_3
));
119 buffer
->prs
.data_offset
=0;
121 for (i
=0; i
<returned
; i
++) {
122 inf
[i
].secdesc
= NULL
;
123 smb_io_printer_info_3("", buffer
, &inf
[i
], 0);
129 /**********************************************************************
130 **********************************************************************/
131 static void decode_port_info_1(TALLOC_CTX
*mem_ctx
, NEW_BUFFER
*buffer
,
132 uint32 returned
, PORT_INFO_1
**info
)
137 inf
=(PORT_INFO_1
*)talloc(mem_ctx
, returned
*sizeof(PORT_INFO_1
));
139 prs_set_offset(&buffer
->prs
, 0);
141 for (i
=0; i
<returned
; i
++) {
142 smb_io_port_info_1("", buffer
, &(inf
[i
]), 0);
148 /**********************************************************************
149 **********************************************************************/
150 static void decode_port_info_2(TALLOC_CTX
*mem_ctx
, NEW_BUFFER
*buffer
,
151 uint32 returned
, PORT_INFO_2
**info
)
156 inf
=(PORT_INFO_2
*)talloc(mem_ctx
, returned
*sizeof(PORT_INFO_2
));
158 prs_set_offset(&buffer
->prs
, 0);
160 for (i
=0; i
<returned
; i
++) {
161 smb_io_port_info_2("", buffer
, &(inf
[i
]), 0);
167 /**********************************************************************
168 **********************************************************************/
169 static void decode_printer_driver_1(TALLOC_CTX
*mem_ctx
, NEW_BUFFER
*buffer
,
170 uint32 returned
, DRIVER_INFO_1
**info
)
175 inf
=(DRIVER_INFO_1
*)talloc(mem_ctx
, returned
*sizeof(DRIVER_INFO_1
));
177 buffer
->prs
.data_offset
=0;
179 for (i
=0; i
<returned
; i
++) {
180 smb_io_printer_driver_info_1("", buffer
, &(inf
[i
]), 0);
186 /**********************************************************************
187 **********************************************************************/
188 static void decode_printer_driver_2(TALLOC_CTX
*mem_ctx
, NEW_BUFFER
*buffer
,
189 uint32 returned
, DRIVER_INFO_2
**info
)
194 inf
=(DRIVER_INFO_2
*)talloc(mem_ctx
, returned
*sizeof(DRIVER_INFO_2
));
196 buffer
->prs
.data_offset
=0;
198 for (i
=0; i
<returned
; i
++) {
199 smb_io_printer_driver_info_2("", buffer
, &(inf
[i
]), 0);
205 /**********************************************************************
206 **********************************************************************/
207 static void decode_printer_driver_3(TALLOC_CTX
*mem_ctx
, NEW_BUFFER
*buffer
,
208 uint32 returned
, DRIVER_INFO_3
**info
)
213 inf
=(DRIVER_INFO_3
*)talloc(mem_ctx
, returned
*sizeof(DRIVER_INFO_3
));
215 buffer
->prs
.data_offset
=0;
217 for (i
=0; i
<returned
; i
++) {
218 smb_io_printer_driver_info_3("", buffer
, &(inf
[i
]), 0);
224 /**********************************************************************
225 **********************************************************************/
226 static void decode_printerdriverdir_1 (TALLOC_CTX
*mem_ctx
, NEW_BUFFER
*buffer
,
227 uint32 returned
, DRIVER_DIRECTORY_1
**info
230 DRIVER_DIRECTORY_1
*inf
;
232 inf
=(DRIVER_DIRECTORY_1
*)talloc(mem_ctx
, sizeof(DRIVER_DIRECTORY_1
));
234 prs_set_offset(&buffer
->prs
, 0);
236 smb_io_driverdir_1("", buffer
, inf
, 0);
241 /** Return a handle to the specified printer or print server.
243 * @param cli Pointer to client state structure which is open
244 * on the SPOOLSS pipe.
246 * @param mem_ctx Pointer to an initialised talloc context.
248 * @param printername The name of the printer or print server to be
249 * opened in UNC format.
251 * @param datatype Specifies the default data type for the printer.
253 * @param access_required The access rights requested on the printer or
256 * @param station The UNC name of the requesting workstation.
258 * @param username The name of the user requesting the open.
260 * @param pol Returned policy handle.
263 /*********************************************************************************
264 Win32 API - OpenPrinter()
265 ********************************************************************************/
267 WERROR
cli_spoolss_open_printer_ex(struct cli_state
*cli
, TALLOC_CTX
*mem_ctx
,
268 char *printername
, char *datatype
, uint32 access_required
,
269 char *station
, char *username
, POLICY_HND
*pol
)
271 prs_struct qbuf
, rbuf
;
272 SPOOL_Q_OPEN_PRINTER_EX q
;
273 SPOOL_R_OPEN_PRINTER_EX r
;
274 WERROR result
= W_ERROR(ERRgeneral
);
279 /* Initialise parse structures */
281 prs_init(&qbuf
, MAX_PDU_FRAG_LEN
, mem_ctx
, MARSHALL
);
282 prs_init(&rbuf
, 0, mem_ctx
, UNMARSHALL
);
284 /* Initialise input parameters */
286 make_spoolss_q_open_printer_ex(&q
, printername
, datatype
,
287 access_required
, station
, username
);
289 /* Marshall data and send request */
291 if (!spoolss_io_q_open_printer_ex("", &q
, &qbuf
, 0) ||
292 !rpc_api_pipe_req(cli
, SPOOLSS_OPENPRINTEREX
, &qbuf
, &rbuf
))
295 /* Unmarshall response */
297 if (!spoolss_io_r_open_printer_ex("", &r
, &rbuf
, 0))
300 /* Return output parameters */
304 if (W_ERROR_IS_OK(result
))
314 /** Close a printer handle
316 * @param cli Pointer to client state structure which is open
317 * on the SPOOLSS pipe.
319 * @param mem_ctx Pointer to an initialised talloc context.
321 * @param pol Policy handle of printer or print server to close.
323 /*********************************************************************************
324 Win32 API - ClosePrinter()
325 ********************************************************************************/
327 WERROR
cli_spoolss_close_printer(struct cli_state
*cli
, TALLOC_CTX
*mem_ctx
,
330 prs_struct qbuf
, rbuf
;
331 SPOOL_Q_CLOSEPRINTER q
;
332 SPOOL_R_CLOSEPRINTER r
;
333 WERROR result
= W_ERROR(ERRgeneral
);
338 /* Initialise parse structures */
340 prs_init(&qbuf
, MAX_PDU_FRAG_LEN
, mem_ctx
, MARSHALL
);
341 prs_init(&rbuf
, 0, mem_ctx
, UNMARSHALL
);
343 /* Initialise input parameters */
345 make_spoolss_q_closeprinter(&q
, pol
);
347 /* Marshall data and send request */
349 if (!spoolss_io_q_closeprinter("", &q
, &qbuf
, 0) ||
350 !rpc_api_pipe_req(cli
, SPOOLSS_CLOSEPRINTER
, &qbuf
, &rbuf
))
353 /* Unmarshall response */
355 if (!spoolss_io_r_closeprinter("", &r
, &rbuf
, 0))
358 /* Return output parameters */
362 if (W_ERROR_IS_OK(result
))
372 /** Enumerate printers on a print server.
374 * @param cli Pointer to client state structure which is open
375 * on the SPOOLSS pipe.
376 * @param mem_ctx Pointer to an initialised talloc context.
378 * @param offered Buffer size offered in the request.
379 * @param needed Number of bytes needed to complete the request.
382 * @param flags Selected from PRINTER_ENUM_* flags.
383 * @param level Request information level.
385 * @param num_printers Pointer to number of printers returned. May be
387 * @param ctr Return structure for printer information. May
390 /*********************************************************************************
391 Win32 API - EnumPrinters()
392 ********************************************************************************/
394 WERROR
cli_spoolss_enum_printers(struct cli_state
*cli
, TALLOC_CTX
*mem_ctx
,
395 uint32 offered
, uint32
*needed
,
396 char *name
, uint32 flags
, uint32 level
,
397 uint32
*num_printers
, PRINTER_INFO_CTR
*ctr
)
399 prs_struct qbuf
, rbuf
;
400 SPOOL_Q_ENUMPRINTERS q
;
401 SPOOL_R_ENUMPRINTERS r
;
403 WERROR result
= W_ERROR(ERRgeneral
);
408 /* Initialise input parameters */
410 init_buffer(&buffer
, offered
, mem_ctx
);
412 prs_init(&qbuf
, MAX_PDU_FRAG_LEN
, mem_ctx
, MARSHALL
);
413 prs_init(&rbuf
, 0, mem_ctx
, UNMARSHALL
);
415 make_spoolss_q_enumprinters(&q
, flags
, name
, level
, &buffer
,
418 /* Marshall data and send request */
420 if (!spoolss_io_q_enumprinters("", &q
, &qbuf
, 0) ||
421 !rpc_api_pipe_req(cli
, SPOOLSS_ENUMPRINTERS
, &qbuf
, &rbuf
))
424 /* Unmarshall response */
426 if (spoolss_io_r_enumprinters("", &r
, &rbuf
, 0)) {
433 /* Return output parameters */
435 if (!W_ERROR_IS_OK(r
.status
))
439 *num_printers
= r
.returned
;
446 decode_printer_info_0(mem_ctx
, r
.buffer
, r
.returned
,
450 decode_printer_info_1(mem_ctx
, r
.buffer
, r
.returned
,
454 decode_printer_info_2(mem_ctx
, r
.buffer
, r
.returned
,
458 decode_printer_info_3(mem_ctx
, r
.buffer
, r
.returned
,
470 /*********************************************************************************
471 Win32 API - EnumPorts()
472 ********************************************************************************/
473 /** Enumerate printer ports on a print server.
475 * @param cli Pointer to client state structure which is open
476 * on the SPOOLSS pipe.
477 * @param mem_ctx Pointer to an initialised talloc context.
479 * @param offered Buffer size offered in the request.
480 * @param needed Number of bytes needed to complete the request.
483 * @param level Requested information level.
485 * @param num_ports Pointer to number of ports returned. May be NULL.
486 * @param ctr Pointer to structure holding port information.
490 WERROR
cli_spoolss_enum_ports(struct cli_state
*cli
, TALLOC_CTX
*mem_ctx
,
491 uint32 offered
, uint32
*needed
,
492 uint32 level
, int *num_ports
, PORT_INFO_CTR
*ctr
)
494 prs_struct qbuf
, rbuf
;
498 WERROR result
= W_ERROR(ERRgeneral
);
504 slprintf (server
, sizeof(fstring
)-1, "\\\\%s", cli
->desthost
);
507 /* Initialise input parameters */
509 init_buffer(&buffer
, offered
, mem_ctx
);
511 prs_init(&qbuf
, MAX_PDU_FRAG_LEN
, mem_ctx
, MARSHALL
);
512 prs_init(&rbuf
, 0, mem_ctx
, UNMARSHALL
);
514 make_spoolss_q_enumports(&q
, server
, level
, &buffer
, offered
);
516 /* Marshall data and send request */
518 if (!spoolss_io_q_enumports("", &q
, &qbuf
, 0) ||
519 !rpc_api_pipe_req(cli
, SPOOLSS_ENUMPORTS
, &qbuf
, &rbuf
))
522 /* Unmarshall response */
524 if (spoolss_io_r_enumports("", &r
, &rbuf
, 0)) {
531 /* Return output parameters */
533 if (!W_ERROR_IS_OK(result
))
537 *num_ports
= r
.returned
;
544 decode_port_info_1(mem_ctx
, r
.buffer
, r
.returned
,
548 decode_port_info_2(mem_ctx
, r
.buffer
, r
.returned
,
560 /*********************************************************************************
561 Win32 API - GetPrinter()
562 ********************************************************************************/
564 WERROR
cli_spoolss_getprinter(struct cli_state
*cli
, TALLOC_CTX
*mem_ctx
,
565 uint32 offered
, uint32
*needed
,
566 POLICY_HND
*pol
, uint32 level
,
567 PRINTER_INFO_CTR
*ctr
)
569 prs_struct qbuf
, rbuf
;
570 SPOOL_Q_GETPRINTER q
;
571 SPOOL_R_GETPRINTER r
;
573 WERROR result
= W_ERROR(ERRgeneral
);
578 /* Initialise input parameters */
580 init_buffer(&buffer
, offered
, mem_ctx
);
582 prs_init(&qbuf
, MAX_PDU_FRAG_LEN
, mem_ctx
, MARSHALL
);
583 prs_init(&rbuf
, 0, mem_ctx
, UNMARSHALL
);
585 make_spoolss_q_getprinter(mem_ctx
, &q
, pol
, level
, &buffer
, offered
);
587 /* Marshall data and send request */
589 if (!spoolss_io_q_getprinter("", &q
, &qbuf
, 0) ||
590 !rpc_api_pipe_req(cli
, SPOOLSS_GETPRINTER
, &qbuf
, &rbuf
))
593 /* Unmarshall response */
595 if (!spoolss_io_r_getprinter("", &r
, &rbuf
, 0))
601 /* Return output parameters */
605 if (W_ERROR_IS_OK(result
)) {
608 decode_printer_info_0(mem_ctx
, r
.buffer
, 1, &ctr
->printers_0
);
611 decode_printer_info_1(mem_ctx
, r
.buffer
, 1, &ctr
->printers_1
);
614 decode_printer_info_2(mem_ctx
, r
.buffer
, 1, &ctr
->printers_2
);
617 decode_printer_info_3(mem_ctx
, r
.buffer
, 1, &ctr
->printers_3
);
629 /*********************************************************************************
630 Win32 API - SetPrinter()
631 ********************************************************************************/
634 * @param cli Pointer to client state structure which is open
635 * on the SPOOLSS pipe.
636 * @param mem_ctx Pointer to an initialised talloc context.
638 * @param pol Policy handle on printer to set info.
639 * @param level Information level to set.
640 * @param ctr Pointer to structure holding printer information.
641 * @param command Specifies the action performed. See
642 * http://msdn.microsoft.com/library/default.asp?url=/library/en-us/gdi/prntspol_13ua.asp
647 WERROR
cli_spoolss_setprinter(struct cli_state
*cli
, TALLOC_CTX
*mem_ctx
,
648 POLICY_HND
*pol
, uint32 level
,
649 PRINTER_INFO_CTR
*ctr
, uint32 command
)
651 prs_struct qbuf
, rbuf
;
652 SPOOL_Q_SETPRINTER q
;
653 SPOOL_R_SETPRINTER r
;
654 WERROR result
= W_ERROR(ERRgeneral
);
659 /* Initialise input parameters */
661 prs_init(&qbuf
, MAX_PDU_FRAG_LEN
, mem_ctx
, MARSHALL
);
662 prs_init(&rbuf
, 0, mem_ctx
, UNMARSHALL
);
664 if (!make_spoolss_q_setprinter(mem_ctx
, &q
, pol
, level
, ctr
, command
))
667 /* Marshall data and send request */
669 if (!spoolss_io_q_setprinter("", &q
, &qbuf
, 0) ||
670 !rpc_api_pipe_req(cli
, SPOOLSS_SETPRINTER
, &qbuf
, &rbuf
))
673 /* Unmarshall response */
675 if (!spoolss_io_r_setprinter("", &r
, &rbuf
, 0))
687 /*********************************************************************************
688 Win32 API - GetPrinterDriver()
689 ********************************************************************************/
690 /** Get installed printer drivers for a given printer
692 * @param cli Pointer to client state structure which is open
693 * on the SPOOLSS pipe.
695 * @param mem_ctx Pointer to an initialised talloc context.
697 * @param offered Buffer size offered in the request.
698 * @param needed Number of bytes needed to complete the request.
701 * @param pol Pointer to an open policy handle for the printer
702 * opened with cli_spoolss_open_printer_ex().
703 * @param level Requested information level.
704 * @param env The print environment or archictecture. This is
705 * "Windows NT x86" for NT4.
706 * @param ctr Returned printer driver information.
709 WERROR
cli_spoolss_getprinterdriver(struct cli_state
*cli
,
711 uint32 offered
, uint32
*needed
,
712 POLICY_HND
*pol
, uint32 level
,
713 char *env
, PRINTER_DRIVER_CTR
*ctr
)
715 prs_struct qbuf
, rbuf
;
716 SPOOL_Q_GETPRINTERDRIVER2 q
;
717 SPOOL_R_GETPRINTERDRIVER2 r
;
719 WERROR result
= W_ERROR(ERRgeneral
);
725 fstrcpy (server
, cli
->desthost
);
728 /* Initialise input parameters */
730 init_buffer(&buffer
, offered
, mem_ctx
);
732 prs_init(&qbuf
, MAX_PDU_FRAG_LEN
, mem_ctx
, MARSHALL
);
733 prs_init(&rbuf
, 0, mem_ctx
, UNMARSHALL
);
735 make_spoolss_q_getprinterdriver2(&q
, pol
, env
, level
, 2, 2,
738 /* Marshall data and send request */
740 if (!spoolss_io_q_getprinterdriver2 ("", &q
, &qbuf
, 0) ||
741 !rpc_api_pipe_req (cli
, SPOOLSS_GETPRINTERDRIVER2
, &qbuf
, &rbuf
))
744 /* Unmarshall response */
746 if (spoolss_io_r_getprinterdriver2 ("", &r
, &rbuf
, 0)) {
753 /* Return output parameters */
755 if (!W_ERROR_IS_OK(result
))
763 decode_printer_driver_1(mem_ctx
, r
.buffer
, 1, &ctr
->info1
);
766 decode_printer_driver_2(mem_ctx
, r
.buffer
, 1, &ctr
->info2
);
769 decode_printer_driver_3(mem_ctx
, r
.buffer
, 1, &ctr
->info3
);
772 DEBUG(10, ("cli_spoolss_getprinterdriver: unknown info level %d", level
));
773 return WERR_UNKNOWN_LEVEL
;
783 /*********************************************************************************
784 Win32 API - EnumPrinterDrivers()
785 ********************************************************************************/
786 /**********************************************************************
787 * Get installed printer drivers for a given printer
789 WERROR
cli_spoolss_enumprinterdrivers (struct cli_state
*cli
,
791 uint32 offered
, uint32
*needed
,
792 uint32 level
, char *env
,
794 PRINTER_DRIVER_CTR
*ctr
)
796 prs_struct qbuf
, rbuf
;
797 SPOOL_Q_ENUMPRINTERDRIVERS q
;
798 SPOOL_R_ENUMPRINTERDRIVERS r
;
800 WERROR result
= W_ERROR(ERRgeneral
);
806 slprintf (server
, sizeof(fstring
)-1, "\\\\%s", cli
->desthost
);
809 /* Initialise input parameters */
811 init_buffer(&buffer
, offered
, mem_ctx
);
813 prs_init(&qbuf
, MAX_PDU_FRAG_LEN
, mem_ctx
, MARSHALL
);
814 prs_init(&rbuf
, 0, mem_ctx
, UNMARSHALL
);
816 /* Write the request */
818 make_spoolss_q_enumprinterdrivers(&q
, server
, env
, level
, &buffer
,
821 /* Marshall data and send request */
823 if (!spoolss_io_q_enumprinterdrivers ("", &q
, &qbuf
, 0) ||
824 !rpc_api_pipe_req (cli
, SPOOLSS_ENUMPRINTERDRIVERS
, &qbuf
, &rbuf
))
827 /* Unmarshall response */
829 if (!spoolss_io_r_enumprinterdrivers ("", &r
, &rbuf
, 0))
836 *num_drivers
= r
.returned
;
840 /* Return output parameters */
842 if (W_ERROR_IS_OK(result
) && (r
.returned
!= 0)) {
843 *num_drivers
= r
.returned
;
847 decode_printer_driver_1(mem_ctx
, r
.buffer
, r
.returned
, &ctr
->info1
);
850 decode_printer_driver_2(mem_ctx
, r
.buffer
, r
.returned
, &ctr
->info2
);
853 decode_printer_driver_3(mem_ctx
, r
.buffer
, r
.returned
, &ctr
->info3
);
856 DEBUG(10, ("cli_spoolss_enumprinterdrivers: unknown info level %d\n",
858 return WERR_UNKNOWN_LEVEL
;
870 /*********************************************************************************
871 Win32 API - GetPrinterDriverDirectory()
872 ********************************************************************************/
873 /**********************************************************************
874 * Get installed printer drivers for a given printer
876 WERROR
cli_spoolss_getprinterdriverdir (struct cli_state
*cli
,
878 uint32 offered
, uint32
*needed
,
879 uint32 level
, char *env
,
880 DRIVER_DIRECTORY_CTR
*ctr
)
882 prs_struct qbuf
, rbuf
;
883 SPOOL_Q_GETPRINTERDRIVERDIR q
;
884 SPOOL_R_GETPRINTERDRIVERDIR r
;
886 WERROR result
= W_ERROR(ERRgeneral
);
892 slprintf (server
, sizeof(fstring
)-1, "\\\\%s", cli
->desthost
);
895 /* Initialise input parameters */
897 init_buffer(&buffer
, offered
, mem_ctx
);
899 prs_init(&qbuf
, MAX_PDU_FRAG_LEN
, mem_ctx
, MARSHALL
);
900 prs_init(&rbuf
, 0, mem_ctx
, UNMARSHALL
);
902 /* Write the request */
904 make_spoolss_q_getprinterdriverdir(&q
, server
, env
, level
, &buffer
,
907 /* Marshall data and send request */
909 if (!spoolss_io_q_getprinterdriverdir ("", &q
, &qbuf
, 0) ||
910 !rpc_api_pipe_req (cli
, SPOOLSS_GETPRINTERDRIVERDIRECTORY
,
914 /* Unmarshall response */
916 if (spoolss_io_r_getprinterdriverdir ("", &r
, &rbuf
, 0)) {
921 /* Return output parameters */
925 if (W_ERROR_IS_OK(result
)) {
928 decode_printerdriverdir_1(mem_ctx
, r
.buffer
, 1,
941 /*********************************************************************************
942 Win32 API - AddPrinterDriver()
943 ********************************************************************************/
944 /**********************************************************************
945 * Install a printer driver
947 WERROR
cli_spoolss_addprinterdriver (struct cli_state
*cli
,
948 TALLOC_CTX
*mem_ctx
, uint32 level
,
949 PRINTER_DRIVER_CTR
*ctr
)
951 prs_struct qbuf
, rbuf
;
952 SPOOL_Q_ADDPRINTERDRIVER q
;
953 SPOOL_R_ADDPRINTERDRIVER r
;
954 WERROR result
= W_ERROR(ERRgeneral
);
960 slprintf (server
, sizeof(fstring
)-1, "\\\\%s", cli
->desthost
);
963 /* Initialise input parameters */
965 prs_init(&qbuf
, MAX_PDU_FRAG_LEN
, mem_ctx
, MARSHALL
);
966 prs_init(&rbuf
, 0, mem_ctx
, UNMARSHALL
);
968 /* Write the request */
970 make_spoolss_q_addprinterdriver (mem_ctx
, &q
, server
, level
, ctr
);
972 /* Marshall data and send request */
974 if (!spoolss_io_q_addprinterdriver ("", &q
, &qbuf
, 0) ||
975 !rpc_api_pipe_req (cli
, SPOOLSS_ADDPRINTERDRIVER
, &qbuf
, &rbuf
))
978 /* Unmarshall response */
980 if (!spoolss_io_r_addprinterdriver ("", &r
, &rbuf
, 0))
983 /* Return output parameters */
994 /*********************************************************************************
995 Win32 API - AddPrinter()
996 ********************************************************************************/
997 /**********************************************************************
1000 WERROR
cli_spoolss_addprinterex (struct cli_state
*cli
, TALLOC_CTX
*mem_ctx
,
1001 uint32 level
, PRINTER_INFO_CTR
*ctr
)
1003 prs_struct qbuf
, rbuf
;
1004 SPOOL_Q_ADDPRINTEREX q
;
1005 SPOOL_R_ADDPRINTEREX r
;
1006 WERROR result
= W_ERROR(ERRgeneral
);
1014 slprintf (client
, sizeof(fstring
)-1, "\\\\%s", cli
->desthost
);
1016 slprintf (server
, sizeof(fstring
)-1, "\\\\%s", cli
->desthost
);
1018 fstrcpy (user
, cli
->user_name
);
1020 /* Initialise input parameters */
1022 prs_init(&qbuf
, MAX_PDU_FRAG_LEN
, mem_ctx
, MARSHALL
);
1023 prs_init(&rbuf
, 0, mem_ctx
, UNMARSHALL
);
1025 /* Write the request */
1027 make_spoolss_q_addprinterex (mem_ctx
, &q
, server
, client
, user
,
1030 /* Marshall data and send request */
1032 if (!spoolss_io_q_addprinterex ("", &q
, &qbuf
, 0) ||
1033 !rpc_api_pipe_req (cli
, SPOOLSS_ADDPRINTEREX
, &qbuf
, &rbuf
))
1036 /* Unmarshall response */
1038 if (!spoolss_io_r_addprinterex ("", &r
, &rbuf
, 0))
1041 /* Return output parameters */
1046 prs_mem_free(&qbuf
);
1047 prs_mem_free(&rbuf
);
1052 /*********************************************************************************
1053 Win32 API - DeltePrinterDriver()
1054 ********************************************************************************/
1055 /**********************************************************************
1056 * Delete a Printer Driver from the server (does not remove
1059 WERROR
cli_spoolss_deleteprinterdriver (struct cli_state
*cli
,
1060 TALLOC_CTX
*mem_ctx
, char *arch
,
1063 prs_struct qbuf
, rbuf
;
1064 SPOOL_Q_DELETEPRINTERDRIVER q
;
1065 SPOOL_R_DELETEPRINTERDRIVER r
;
1066 WERROR result
= W_ERROR(ERRgeneral
);
1073 /* Initialise input parameters */
1074 prs_init(&qbuf
, MAX_PDU_FRAG_LEN
, mem_ctx
, MARSHALL
);
1075 prs_init(&rbuf
, 0, mem_ctx
, UNMARSHALL
);
1077 slprintf (server
, sizeof(fstring
)-1, "\\\\%s", cli
->desthost
);
1080 /* Write the request */
1082 make_spoolss_q_deleteprinterdriver(mem_ctx
, &q
, server
, arch
, driver
);
1084 /* Marshall data and send request */
1086 if (!spoolss_io_q_deleteprinterdriver ("", &q
, &qbuf
, 0) ||
1087 !rpc_api_pipe_req (cli
,SPOOLSS_DELETEPRINTERDRIVER
, &qbuf
, &rbuf
))
1090 /* Unmarshall response */
1092 if (!spoolss_io_r_deleteprinterdriver ("", &r
, &rbuf
, 0))
1095 /* Return output parameters */
1100 prs_mem_free(&qbuf
);
1101 prs_mem_free(&rbuf
);
1106 /*********************************************************************************
1107 Win32 API - GetPrinterProcessorDirectory()
1108 ********************************************************************************/
1110 WERROR
cli_spoolss_getprintprocessordirectory(struct cli_state
*cli
,
1111 TALLOC_CTX
*mem_ctx
,
1112 uint32 offered
, uint32
*needed
,
1113 char *name
, char *environment
,
1116 prs_struct qbuf
, rbuf
;
1117 SPOOL_Q_GETPRINTPROCESSORDIRECTORY q
;
1118 SPOOL_R_GETPRINTPROCESSORDIRECTORY r
;
1120 WERROR result
= W_ERROR(ERRgeneral
);
1126 /* Initialise parse structures */
1128 prs_init(&qbuf
, MAX_PDU_FRAG_LEN
, mem_ctx
, MARSHALL
);
1129 prs_init(&rbuf
, 0, mem_ctx
, UNMARSHALL
);
1131 /* Initialise input parameters */
1133 init_buffer(&buffer
, offered
, mem_ctx
);
1135 make_spoolss_q_getprintprocessordirectory(
1136 &q
, name
, environment
, level
, &buffer
, offered
);
1138 /* Marshall data and send request */
1140 if (!spoolss_io_q_getprintprocessordirectory("", &q
, &qbuf
, 0) ||
1141 !rpc_api_pipe_req(cli
, SPOOLSS_GETPRINTPROCESSORDIRECTORY
,
1145 /* Unmarshall response */
1147 if (!spoolss_io_r_getprintprocessordirectory("", &r
, &rbuf
, 0))
1150 /* Return output parameters */
1157 if (W_ERROR_IS_OK(result
))
1158 fstrcpy(procdir
, "Not implemented!");
1161 prs_mem_free(&qbuf
);
1162 prs_mem_free(&rbuf
);
1167 /** Add a form to a printer.
1169 * @param cli Pointer to client state structure which is open
1170 * on the SPOOLSS pipe.
1171 * @param mem_ctx Pointer to an initialised talloc context.
1173 * @param handle Policy handle opened with cli_spoolss_open_printer_ex
1174 * or cli_spoolss_addprinterex.
1175 * @param level Form info level to add - should always be 1.
1176 * @param form A pointer to the form to be added.
1180 WERROR
cli_spoolss_addform(struct cli_state
*cli
, TALLOC_CTX
*mem_ctx
,
1181 POLICY_HND
*handle
, uint32 level
, FORM
*form
)
1183 prs_struct qbuf
, rbuf
;
1186 WERROR result
= W_ERROR(ERRgeneral
);
1191 /* Initialise parse structures */
1193 prs_init(&qbuf
, MAX_PDU_FRAG_LEN
, mem_ctx
, MARSHALL
);
1194 prs_init(&rbuf
, 0, mem_ctx
, UNMARSHALL
);
1196 /* Initialise input parameters */
1198 make_spoolss_q_addform(&q
, handle
, level
, form
);
1200 /* Marshall data and send request */
1202 if (!spoolss_io_q_addform("", &q
, &qbuf
, 0) ||
1203 !rpc_api_pipe_req(cli
, SPOOLSS_ADDFORM
, &qbuf
, &rbuf
))
1206 /* Unmarshall response */
1208 if (!spoolss_io_r_addform("", &r
, &rbuf
, 0))
1211 /* Return output parameters */
1216 prs_mem_free(&qbuf
);
1217 prs_mem_free(&rbuf
);
1222 /** Set a form on a printer.
1224 * @param cli Pointer to client state structure which is open
1225 * on the SPOOLSS pipe.
1226 * @param mem_ctx Pointer to an initialised talloc context.
1228 * @param handle Policy handle opened with cli_spoolss_open_printer_ex
1229 * or cli_spoolss_addprinterex.
1230 * @param level Form info level to set - should always be 1.
1231 * @param form A pointer to the form to be set.
1235 WERROR
cli_spoolss_setform(struct cli_state
*cli
, TALLOC_CTX
*mem_ctx
,
1236 POLICY_HND
*handle
, uint32 level
, char *form_name
,
1239 prs_struct qbuf
, rbuf
;
1242 WERROR result
= W_ERROR(ERRgeneral
);
1247 /* Initialise parse structures */
1249 prs_init(&qbuf
, MAX_PDU_FRAG_LEN
, mem_ctx
, MARSHALL
);
1250 prs_init(&rbuf
, 0, mem_ctx
, UNMARSHALL
);
1252 /* Initialise input parameters */
1254 make_spoolss_q_setform(&q
, handle
, level
, form_name
, form
);
1256 /* Marshall data and send request */
1258 if (!spoolss_io_q_setform("", &q
, &qbuf
, 0) ||
1259 !rpc_api_pipe_req(cli
, SPOOLSS_SETFORM
, &qbuf
, &rbuf
))
1262 /* Unmarshall response */
1264 if (!spoolss_io_r_setform("", &r
, &rbuf
, 0))
1267 /* Return output parameters */
1271 if (!W_ERROR_IS_OK(result
))
1277 prs_mem_free(&qbuf
);
1278 prs_mem_free(&rbuf
);
1283 /** Get a form on a printer.
1285 * @param cli Pointer to client state structure which is open
1286 * on the SPOOLSS pipe.
1287 * @param mem_ctx Pointer to an initialised talloc context.
1289 * @param handle Policy handle opened with cli_spoolss_open_printer_ex
1290 * or cli_spoolss_addprinterex.
1291 * @param formname Name of the form to get
1292 * @param level Form info level to get - should always be 1.
1296 WERROR
cli_spoolss_getform(struct cli_state
*cli
, TALLOC_CTX
*mem_ctx
,
1297 uint32 offered
, uint32
*needed
,
1298 POLICY_HND
*handle
, char *formname
, uint32 level
,
1301 prs_struct qbuf
, rbuf
;
1304 WERROR result
= W_ERROR(ERRgeneral
);
1310 /* Initialise parse structures */
1312 init_buffer(&buffer
, offered
, mem_ctx
);
1314 prs_init(&qbuf
, MAX_PDU_FRAG_LEN
, mem_ctx
, MARSHALL
);
1315 prs_init(&rbuf
, 0, mem_ctx
, UNMARSHALL
);
1317 /* Initialise input parameters */
1319 make_spoolss_q_getform(&q
, handle
, formname
, level
, &buffer
, offered
);
1321 /* Marshall data and send request */
1323 if (!spoolss_io_q_getform("", &q
, &qbuf
, 0) ||
1324 !rpc_api_pipe_req(cli
, SPOOLSS_GETFORM
, &qbuf
, &rbuf
))
1327 /* Unmarshall response */
1329 if (!spoolss_io_r_getform("", &r
, &rbuf
, 0))
1332 /* Return output parameters */
1339 if (W_ERROR_IS_OK(result
)) {
1342 smb_io_form_1("", r
.buffer
, form
, 0);
1345 DEBUG(10, ("cli_spoolss_getform: unknown info level %d", level
));
1346 return WERR_UNKNOWN_LEVEL
;
1351 prs_mem_free(&qbuf
);
1352 prs_mem_free(&rbuf
);
1357 /** Delete a form on a printer.
1359 * @param cli Pointer to client state structure which is open
1360 * on the SPOOLSS pipe.
1361 * @param mem_ctx Pointer to an initialised talloc context.
1363 * @param handle Policy handle opened with cli_spoolss_open_printer_ex
1364 * or cli_spoolss_addprinterex.
1365 * @param form The name of the form to delete.
1369 WERROR
cli_spoolss_deleteform(struct cli_state
*cli
, TALLOC_CTX
*mem_ctx
,
1370 POLICY_HND
*handle
, char *form_name
)
1372 prs_struct qbuf
, rbuf
;
1373 SPOOL_Q_DELETEFORM q
;
1374 SPOOL_R_DELETEFORM r
;
1375 WERROR result
= W_ERROR(ERRgeneral
);
1380 /* Initialise parse structures */
1382 prs_init(&qbuf
, MAX_PDU_FRAG_LEN
, mem_ctx
, MARSHALL
);
1383 prs_init(&rbuf
, 0, mem_ctx
, UNMARSHALL
);
1385 /* Initialise input parameters */
1387 make_spoolss_q_deleteform(&q
, handle
, form_name
);
1389 /* Marshall data and send request */
1391 if (!spoolss_io_q_deleteform("", &q
, &qbuf
, 0) ||
1392 !rpc_api_pipe_req(cli
, SPOOLSS_DELETEFORM
, &qbuf
, &rbuf
))
1395 /* Unmarshall response */
1397 if (!spoolss_io_r_deleteform("", &r
, &rbuf
, 0))
1400 /* Return output parameters */
1405 prs_mem_free(&qbuf
);
1406 prs_mem_free(&rbuf
);
1411 static void decode_forms_1(TALLOC_CTX
*mem_ctx
, NEW_BUFFER
*buffer
,
1412 uint32 num_forms
, FORM_1
**forms
)
1416 *forms
= (FORM_1
*)talloc(mem_ctx
, num_forms
* sizeof(FORM_1
));
1417 buffer
->prs
.data_offset
= 0;
1419 for (i
= 0; i
< num_forms
; i
++)
1420 smb_io_form_1("", buffer
, &((*forms
)[i
]), 0);
1425 * @param cli Pointer to client state structure which is open
1426 * on the SPOOLSS pipe.
1427 * @param mem_ctx Pointer to an initialised talloc context.
1429 * @param offered Buffer size offered in the request.
1430 * @param needed Number of bytes needed to complete the request.
1432 * or cli_spoolss_addprinterex.
1433 * @param level Form info level to get - should always be 1.
1434 * @param handle Open policy handle
1438 WERROR
cli_spoolss_enumforms(struct cli_state
*cli
, TALLOC_CTX
*mem_ctx
,
1439 uint32 offered
, uint32
*needed
,
1440 POLICY_HND
*handle
, int level
, uint32
*num_forms
,
1443 prs_struct qbuf
, rbuf
;
1444 SPOOL_Q_ENUMFORMS q
;
1445 SPOOL_R_ENUMFORMS r
;
1446 WERROR result
= W_ERROR(ERRgeneral
);
1452 /* Initialise parse structures */
1454 init_buffer(&buffer
, offered
, mem_ctx
);
1456 prs_init(&qbuf
, MAX_PDU_FRAG_LEN
, mem_ctx
, MARSHALL
);
1457 prs_init(&rbuf
, 0, mem_ctx
, UNMARSHALL
);
1459 /* Initialise input parameters */
1461 make_spoolss_q_enumforms(&q
, handle
, level
, &buffer
, offered
);
1463 /* Marshall data and send request */
1465 if (!spoolss_io_q_enumforms("", &q
, &qbuf
, 0) ||
1466 !rpc_api_pipe_req(cli
, SPOOLSS_ENUMFORMS
, &qbuf
, &rbuf
))
1469 /* Unmarshall response */
1471 if (!spoolss_io_r_enumforms("", &r
, &rbuf
, 0))
1474 /* Return output parameters */
1482 *num_forms
= r
.numofforms
;
1484 decode_forms_1(mem_ctx
, r
.buffer
, *num_forms
, forms
);
1487 prs_mem_free(&qbuf
);
1488 prs_mem_free(&rbuf
);
1493 static void decode_jobs_1(TALLOC_CTX
*mem_ctx
, NEW_BUFFER
*buffer
,
1494 uint32 num_jobs
, JOB_INFO_1
**jobs
)
1498 *jobs
= (JOB_INFO_1
*)talloc(mem_ctx
, num_jobs
* sizeof(JOB_INFO_1
));
1499 buffer
->prs
.data_offset
= 0;
1501 for (i
= 0; i
< num_jobs
; i
++)
1502 smb_io_job_info_1("", buffer
, &((*jobs
)[i
]), 0);
1505 static void decode_jobs_2(TALLOC_CTX
*mem_ctx
, NEW_BUFFER
*buffer
,
1506 uint32 num_jobs
, JOB_INFO_2
**jobs
)
1510 *jobs
= (JOB_INFO_2
*)talloc(mem_ctx
, num_jobs
* sizeof(JOB_INFO_2
));
1511 buffer
->prs
.data_offset
= 0;
1513 for (i
= 0; i
< num_jobs
; i
++)
1514 smb_io_job_info_2("", buffer
, &((*jobs
)[i
]), 0);
1517 /* Enumerate jobs */
1519 WERROR
cli_spoolss_enumjobs(struct cli_state
*cli
, TALLOC_CTX
*mem_ctx
,
1520 uint32 offered
, uint32
*needed
,
1521 POLICY_HND
*hnd
, uint32 level
, uint32 firstjob
,
1522 uint32 num_jobs
, uint32
*returned
, JOB_INFO_CTR
*ctr
)
1524 prs_struct qbuf
, rbuf
;
1527 WERROR result
= W_ERROR(ERRgeneral
);
1533 /* Initialise parse structures */
1535 init_buffer(&buffer
, offered
, mem_ctx
);
1537 prs_init(&qbuf
, MAX_PDU_FRAG_LEN
, mem_ctx
, MARSHALL
);
1538 prs_init(&rbuf
, 0, mem_ctx
, UNMARSHALL
);
1540 /* Initialise input parameters */
1542 make_spoolss_q_enumjobs(&q
, hnd
, firstjob
, num_jobs
, level
, &buffer
,
1545 /* Marshall data and send request */
1547 if (!spoolss_io_q_enumjobs("", &q
, &qbuf
, 0) ||
1548 !rpc_api_pipe_req(cli
, SPOOLSS_ENUMJOBS
, &qbuf
, &rbuf
))
1551 /* Unmarshall response */
1553 if (!spoolss_io_r_enumjobs("", &r
, &rbuf
, 0))
1556 /* Return output parameters */
1563 if (!W_ERROR_IS_OK(r
.status
))
1566 *returned
= r
.returned
;
1570 decode_jobs_1(mem_ctx
, r
.buffer
, r
.returned
,
1571 &ctr
->job
.job_info_1
);
1574 decode_jobs_2(mem_ctx
, r
.buffer
, r
.returned
,
1575 &ctr
->job
.job_info_2
);
1578 DEBUG(3, ("unsupported info level %d", level
));
1583 prs_mem_free(&qbuf
);
1584 prs_mem_free(&rbuf
);
1591 WERROR
cli_spoolss_setjob(struct cli_state
*cli
, TALLOC_CTX
*mem_ctx
,
1592 POLICY_HND
*hnd
, uint32 jobid
, uint32 level
,
1595 prs_struct qbuf
, rbuf
;
1598 WERROR result
= W_ERROR(ERRgeneral
);
1603 /* Initialise parse structures */
1605 prs_init(&qbuf
, MAX_PDU_FRAG_LEN
, mem_ctx
, MARSHALL
);
1606 prs_init(&rbuf
, 0, mem_ctx
, UNMARSHALL
);
1608 /* Initialise input parameters */
1610 make_spoolss_q_setjob(&q
, hnd
, jobid
, level
, command
);
1612 /* Marshall data and send request */
1614 if (!spoolss_io_q_setjob("", &q
, &qbuf
, 0) ||
1615 !rpc_api_pipe_req(cli
, SPOOLSS_SETJOB
, &qbuf
, &rbuf
))
1618 /* Unmarshall response */
1620 if (!spoolss_io_r_setjob("", &r
, &rbuf
, 0))
1623 /* Return output parameters */
1628 prs_mem_free(&qbuf
);
1629 prs_mem_free(&rbuf
);
1636 WERROR
cli_spoolss_getjob(struct cli_state
*cli
, TALLOC_CTX
*mem_ctx
,
1637 uint32 offered
, uint32
*needed
,
1638 POLICY_HND
*hnd
, uint32 jobid
, uint32 level
,
1641 prs_struct qbuf
, rbuf
;
1644 WERROR result
= W_ERROR(ERRgeneral
);
1650 /* Initialise parse structures */
1652 init_buffer(&buffer
, offered
, mem_ctx
);
1654 prs_init(&qbuf
, MAX_PDU_FRAG_LEN
, mem_ctx
, MARSHALL
);
1655 prs_init(&rbuf
, 0, mem_ctx
, UNMARSHALL
);
1657 /* Initialise input parameters */
1659 make_spoolss_q_getjob(&q
, hnd
, jobid
, level
, &buffer
, offered
);
1661 /* Marshall data and send request */
1663 if (!spoolss_io_q_getjob("", &q
, &qbuf
, 0) ||
1664 !rpc_api_pipe_req(cli
, SPOOLSS_GETJOB
, &qbuf
, &rbuf
))
1667 /* Unmarshall response */
1669 if (!spoolss_io_r_getjob("", &r
, &rbuf
, 0))
1672 /* Return output parameters */
1679 if (!W_ERROR_IS_OK(r
.status
))
1684 decode_jobs_1(mem_ctx
, r
.buffer
, 1, &ctr
->job
.job_info_1
);
1687 decode_jobs_2(mem_ctx
, r
.buffer
, 1, &ctr
->job
.job_info_2
);
1690 DEBUG(3, ("unsupported info level %d", level
));
1695 prs_mem_free(&qbuf
);
1696 prs_mem_free(&rbuf
);
1701 /* Startpageprinter. Sent to notify the spooler when a page is about to be
1702 sent to a printer. */
1704 WERROR
cli_spoolss_startpageprinter(struct cli_state
*cli
, TALLOC_CTX
*mem_ctx
,
1707 prs_struct qbuf
, rbuf
;
1708 SPOOL_Q_STARTPAGEPRINTER q
;
1709 SPOOL_R_STARTPAGEPRINTER r
;
1710 WERROR result
= W_ERROR(ERRgeneral
);
1715 /* Initialise parse structures */
1717 prs_init(&qbuf
, MAX_PDU_FRAG_LEN
, mem_ctx
, MARSHALL
);
1718 prs_init(&rbuf
, 0, mem_ctx
, UNMARSHALL
);
1720 /* Initialise input parameters */
1722 make_spoolss_q_startpageprinter(&q
, hnd
);
1724 /* Marshall data and send request */
1726 if (!spoolss_io_q_startpageprinter("", &q
, &qbuf
, 0) ||
1727 !rpc_api_pipe_req(cli
, SPOOLSS_STARTPAGEPRINTER
, &qbuf
, &rbuf
))
1730 /* Unmarshall response */
1732 if (!spoolss_io_r_startpageprinter("", &r
, &rbuf
, 0))
1735 /* Return output parameters */
1740 prs_mem_free(&qbuf
);
1741 prs_mem_free(&rbuf
);
1746 /* Endpageprinter. Sent to notify the spooler when a page has finished
1747 being sent to a printer. */
1749 WERROR
cli_spoolss_endpageprinter(struct cli_state
*cli
, TALLOC_CTX
*mem_ctx
,
1752 prs_struct qbuf
, rbuf
;
1753 SPOOL_Q_ENDPAGEPRINTER q
;
1754 SPOOL_R_ENDPAGEPRINTER r
;
1755 WERROR result
= W_ERROR(ERRgeneral
);
1760 /* Initialise parse structures */
1762 prs_init(&qbuf
, MAX_PDU_FRAG_LEN
, mem_ctx
, MARSHALL
);
1763 prs_init(&rbuf
, 0, mem_ctx
, UNMARSHALL
);
1765 /* Initialise input parameters */
1767 make_spoolss_q_endpageprinter(&q
, hnd
);
1769 /* Marshall data and send request */
1771 if (!spoolss_io_q_endpageprinter("", &q
, &qbuf
, 0) ||
1772 !rpc_api_pipe_req(cli
, SPOOLSS_ENDPAGEPRINTER
, &qbuf
, &rbuf
))
1775 /* Unmarshall response */
1777 if (!spoolss_io_r_endpageprinter("", &r
, &rbuf
, 0))
1780 /* Return output parameters */
1785 prs_mem_free(&qbuf
);
1786 prs_mem_free(&rbuf
);
1791 /* Startdocprinter. Sent to notify the spooler that a document is about
1792 to be spooled for printing. */
1794 WERROR
cli_spoolss_startdocprinter(struct cli_state
*cli
, TALLOC_CTX
*mem_ctx
,
1795 POLICY_HND
*hnd
, char *docname
,
1796 char *outputfile
, char *datatype
,
1799 prs_struct qbuf
, rbuf
;
1800 SPOOL_Q_STARTDOCPRINTER q
;
1801 SPOOL_R_STARTDOCPRINTER r
;
1802 WERROR result
= W_ERROR(ERRgeneral
);
1808 /* Initialise parse structures */
1810 prs_init(&qbuf
, MAX_PDU_FRAG_LEN
, mem_ctx
, MARSHALL
);
1811 prs_init(&rbuf
, 0, mem_ctx
, UNMARSHALL
);
1813 /* Initialise input parameters */
1815 make_spoolss_q_startdocprinter(&q
, hnd
, level
, docname
, outputfile
,
1818 /* Marshall data and send request */
1820 if (!spoolss_io_q_startdocprinter("", &q
, &qbuf
, 0) ||
1821 !rpc_api_pipe_req(cli
, SPOOLSS_STARTDOCPRINTER
, &qbuf
, &rbuf
))
1824 /* Unmarshall response */
1826 if (!spoolss_io_r_startdocprinter("", &r
, &rbuf
, 0))
1829 /* Return output parameters */
1833 if (W_ERROR_IS_OK(result
))
1837 prs_mem_free(&qbuf
);
1838 prs_mem_free(&rbuf
);
1843 /* Enddocprinter. Sent to notify the spooler that a document has finished
1846 WERROR
cli_spoolss_enddocprinter(struct cli_state
*cli
, TALLOC_CTX
*mem_ctx
,
1849 prs_struct qbuf
, rbuf
;
1850 SPOOL_Q_ENDDOCPRINTER q
;
1851 SPOOL_R_ENDDOCPRINTER r
;
1852 WERROR result
= W_ERROR(ERRgeneral
);
1857 /* Initialise parse structures */
1859 prs_init(&qbuf
, MAX_PDU_FRAG_LEN
, mem_ctx
, MARSHALL
);
1860 prs_init(&rbuf
, 0, mem_ctx
, UNMARSHALL
);
1862 /* Initialise input parameters */
1864 make_spoolss_q_enddocprinter(&q
, hnd
);
1866 /* Marshall data and send request */
1868 if (!spoolss_io_q_enddocprinter("", &q
, &qbuf
, 0) ||
1869 !rpc_api_pipe_req(cli
, SPOOLSS_ENDDOCPRINTER
, &qbuf
, &rbuf
))
1872 /* Unmarshall response */
1874 if (!spoolss_io_r_enddocprinter("", &r
, &rbuf
, 0))
1877 /* Return output parameters */
1882 prs_mem_free(&qbuf
);
1883 prs_mem_free(&rbuf
);
1888 /* Get printer data */
1890 WERROR
cli_spoolss_getprinterdata(struct cli_state
*cli
, TALLOC_CTX
*mem_ctx
,
1891 uint32 offered
, uint32
*needed
,
1892 POLICY_HND
*hnd
, char *valuename
,
1893 REGISTRY_VALUE
*value
)
1895 prs_struct qbuf
, rbuf
;
1896 SPOOL_Q_GETPRINTERDATA q
;
1897 SPOOL_R_GETPRINTERDATA r
;
1898 WERROR result
= W_ERROR(ERRgeneral
);
1903 /* Initialise parse structures */
1905 prs_init(&qbuf
, MAX_PDU_FRAG_LEN
, mem_ctx
, MARSHALL
);
1906 prs_init(&rbuf
, 0, mem_ctx
, UNMARSHALL
);
1908 /* Initialise input parameters */
1910 make_spoolss_q_getprinterdata(&q
, hnd
, valuename
, offered
);
1912 /* Marshall data and send request */
1914 if (!spoolss_io_q_getprinterdata("", &q
, &qbuf
, 0) ||
1915 !rpc_api_pipe_req(cli
, SPOOLSS_GETPRINTERDATA
, &qbuf
, &rbuf
))
1918 /* Unmarshall response */
1920 if (!spoolss_io_r_getprinterdata("", &r
, &rbuf
, 0))
1928 if (!W_ERROR_IS_OK(r
.status
))
1931 /* Return output parameters */
1933 value
->data_p
= talloc_memdup(mem_ctx
, r
.data
, r
.needed
);
1934 value
->type
= r
.type
;
1935 value
->size
= r
.size
;
1938 prs_mem_free(&qbuf
);
1939 prs_mem_free(&rbuf
);
1944 WERROR
cli_spoolss_getprinterdataex(struct cli_state
*cli
, TALLOC_CTX
*mem_ctx
,
1945 uint32 offered
, uint32
*needed
,
1946 POLICY_HND
*hnd
, char *keyname
,
1947 char *valuename
, REGISTRY_VALUE
*value
)
1949 prs_struct qbuf
, rbuf
;
1950 SPOOL_Q_GETPRINTERDATAEX q
;
1951 SPOOL_R_GETPRINTERDATAEX r
;
1952 WERROR result
= W_ERROR(ERRgeneral
);
1957 /* Initialise parse structures */
1959 prs_init(&qbuf
, MAX_PDU_FRAG_LEN
, mem_ctx
, MARSHALL
);
1960 prs_init(&rbuf
, 0, mem_ctx
, UNMARSHALL
);
1962 /* Initialise input parameters */
1964 make_spoolss_q_getprinterdataex(&q
, hnd
, keyname
, valuename
, offered
);
1966 /* Marshall data and send request */
1968 if (!spoolss_io_q_getprinterdataex("", &q
, &qbuf
, 0) ||
1969 !rpc_api_pipe_req(cli
, SPOOLSS_GETPRINTERDATAEX
, &qbuf
, &rbuf
))
1972 /* Unmarshall response */
1974 if (!spoolss_io_r_getprinterdataex("", &r
, &rbuf
, 0))
1982 if (!W_ERROR_IS_OK(r
.status
))
1985 /* Return output parameters */
1987 value
->data_p
= talloc_memdup(mem_ctx
, r
.data
, r
.needed
);
1988 value
->type
= r
.type
;
1989 value
->size
= r
.needed
;
1992 prs_mem_free(&qbuf
);
1993 prs_mem_free(&rbuf
);
1998 /* Set printer data */
2000 WERROR
cli_spoolss_setprinterdata(struct cli_state
*cli
, TALLOC_CTX
*mem_ctx
,
2001 POLICY_HND
*hnd
, REGISTRY_VALUE
*value
)
2003 prs_struct qbuf
, rbuf
;
2004 SPOOL_Q_SETPRINTERDATA q
;
2005 SPOOL_R_SETPRINTERDATA r
;
2006 WERROR result
= W_ERROR(ERRgeneral
);
2011 /* Initialise parse structures */
2013 prs_init(&qbuf
, MAX_PDU_FRAG_LEN
, mem_ctx
, MARSHALL
);
2014 prs_init(&rbuf
, 0, mem_ctx
, UNMARSHALL
);
2016 /* Initialise input parameters */
2018 make_spoolss_q_setprinterdata(
2019 &q
, hnd
, value
->valuename
, value
->type
, value
->data_p
, value
->size
);
2021 /* Marshall data and send request */
2023 if (!spoolss_io_q_setprinterdata("", &q
, &qbuf
, 0) ||
2024 !rpc_api_pipe_req(cli
, SPOOLSS_SETPRINTERDATA
, &qbuf
, &rbuf
))
2027 /* Unmarshall response */
2029 if (!spoolss_io_r_setprinterdata("", &r
, &rbuf
, 0))
2034 if (!W_ERROR_IS_OK(r
.status
))
2038 prs_mem_free(&qbuf
);
2039 prs_mem_free(&rbuf
);
2044 WERROR
cli_spoolss_setprinterdataex(struct cli_state
*cli
, TALLOC_CTX
*mem_ctx
,
2045 POLICY_HND
*hnd
, char *keyname
,
2046 REGISTRY_VALUE
*value
)
2048 prs_struct qbuf
, rbuf
;
2049 SPOOL_Q_SETPRINTERDATAEX q
;
2050 SPOOL_R_SETPRINTERDATAEX r
;
2051 WERROR result
= W_ERROR(ERRgeneral
);
2056 /* Initialise parse structures */
2058 prs_init(&qbuf
, MAX_PDU_FRAG_LEN
, mem_ctx
, MARSHALL
);
2059 prs_init(&rbuf
, 0, mem_ctx
, UNMARSHALL
);
2061 /* Initialise input parameters */
2063 make_spoolss_q_setprinterdataex(
2064 &q
, hnd
, keyname
, value
->valuename
, value
->type
, value
->data_p
,
2067 /* Marshall data and send request */
2069 if (!spoolss_io_q_setprinterdataex("", &q
, &qbuf
, 0) ||
2070 !rpc_api_pipe_req(cli
, SPOOLSS_SETPRINTERDATAEX
, &qbuf
, &rbuf
))
2073 /* Unmarshall response */
2075 if (!spoolss_io_r_setprinterdataex("", &r
, &rbuf
, 0))
2080 if (!W_ERROR_IS_OK(r
.status
))
2084 prs_mem_free(&qbuf
);
2085 prs_mem_free(&rbuf
);
2090 /* Enum printer data */
2092 WERROR
cli_spoolss_enumprinterdata(struct cli_state
*cli
, TALLOC_CTX
*mem_ctx
,
2093 POLICY_HND
*hnd
, uint32 ndx
,
2094 uint32 value_offered
, uint32 data_offered
,
2095 uint32
*value_needed
, uint32
*data_needed
,
2096 REGISTRY_VALUE
*value
)
2098 prs_struct qbuf
, rbuf
;
2099 SPOOL_Q_ENUMPRINTERDATA q
;
2100 SPOOL_R_ENUMPRINTERDATA r
;
2101 WERROR result
= W_ERROR(ERRgeneral
);
2106 /* Initialise parse structures */
2108 prs_init(&qbuf
, MAX_PDU_FRAG_LEN
, mem_ctx
, MARSHALL
);
2109 prs_init(&rbuf
, 0, mem_ctx
, UNMARSHALL
);
2111 /* Initialise input parameters */
2113 make_spoolss_q_enumprinterdata(&q
, hnd
, ndx
, value_offered
, data_offered
);
2115 /* Marshall data and send request */
2117 if (!spoolss_io_q_enumprinterdata("", &q
, &qbuf
, 0) ||
2118 !rpc_api_pipe_req(cli
, SPOOLSS_ENUMPRINTERDATA
, &qbuf
, &rbuf
))
2121 /* Unmarshall response */
2123 if (!spoolss_io_r_enumprinterdata("", &r
, &rbuf
, 0))
2128 if (!W_ERROR_IS_OK(r
.status
))
2134 *value_needed
= r
.realvaluesize
;
2137 *data_needed
= r
.realdatasize
;
2140 rpcstr_pull(value
->valuename
, r
.value
, sizeof(value
->valuename
), -1,
2142 value
->data_p
= talloc_memdup(mem_ctx
, r
.data
, r
.realdatasize
);
2143 value
->type
= r
.type
;
2144 value
->size
= r
.realdatasize
;
2148 prs_mem_free(&qbuf
);
2149 prs_mem_free(&rbuf
);
2154 WERROR
cli_spoolss_enumprinterdataex(struct cli_state
*cli
, TALLOC_CTX
*mem_ctx
,
2155 uint32 offered
, uint32
*needed
,
2156 POLICY_HND
*hnd
, char *keyname
,
2159 prs_struct qbuf
, rbuf
;
2160 SPOOL_Q_ENUMPRINTERDATAEX q
;
2161 SPOOL_R_ENUMPRINTERDATAEX r
;
2162 WERROR result
= W_ERROR(ERRgeneral
);
2168 /* Initialise parse structures */
2170 prs_init(&qbuf
, MAX_PDU_FRAG_LEN
, mem_ctx
, MARSHALL
);
2171 prs_init(&rbuf
, 0, mem_ctx
, UNMARSHALL
);
2173 /* Initialise input parameters */
2175 make_spoolss_q_enumprinterdataex(&q
, hnd
, keyname
, offered
);
2177 /* Marshall data and send request */
2179 if (!spoolss_io_q_enumprinterdataex("", &q
, &qbuf
, 0) ||
2180 !rpc_api_pipe_req(cli
, SPOOLSS_ENUMPRINTERDATAEX
, &qbuf
, &rbuf
))
2183 /* Unmarshall response */
2185 if (!spoolss_io_r_enumprinterdataex("", &r
, &rbuf
, 0))
2193 if (!W_ERROR_IS_OK(r
.status
))
2199 regval_ctr_init(ctr
);
2201 for (i
= 0; i
< r
.returned
; i
++) {
2202 PRINTER_ENUM_VALUES
*v
= &r
.ctr
.values
[i
];
2205 rpcstr_pull(name
, v
->valuename
.buffer
, sizeof(name
), -1,
2207 regval_ctr_addvalue(ctr
, name
, v
->type
, v
->data
, v
->data_len
);
2211 prs_mem_free(&qbuf
);
2212 prs_mem_free(&rbuf
);
2217 /* Write data to printer */
2219 WERROR
cli_spoolss_writeprinter(struct cli_state
*cli
, TALLOC_CTX
*mem_ctx
,
2220 POLICY_HND
*hnd
, uint32 data_size
, char *data
,
2221 uint32
*num_written
)
2223 prs_struct qbuf
, rbuf
;
2224 SPOOL_Q_WRITEPRINTER q
;
2225 SPOOL_R_WRITEPRINTER r
;
2226 WERROR result
= W_ERROR(ERRgeneral
);
2231 /* Initialise parse structures */
2233 prs_init(&qbuf
, MAX_PDU_FRAG_LEN
, mem_ctx
, MARSHALL
);
2234 prs_init(&rbuf
, 0, mem_ctx
, UNMARSHALL
);
2236 /* Initialise input parameters */
2238 make_spoolss_q_writeprinter(&q
, hnd
, data_size
, data
);
2240 /* Marshall data and send request */
2242 if (!spoolss_io_q_writeprinter("", &q
, &qbuf
, 0) ||
2243 !rpc_api_pipe_req(cli
, SPOOLSS_WRITEPRINTER
, &qbuf
, &rbuf
))
2246 /* Unmarshall response */
2248 if (!spoolss_io_r_writeprinter("", &r
, &rbuf
, 0))
2253 if (!W_ERROR_IS_OK(r
.status
))
2257 *num_written
= r
.buffer_written
;
2260 prs_mem_free(&qbuf
);
2261 prs_mem_free(&rbuf
);
2266 /* Delete printer data */
2268 WERROR
cli_spoolss_deleteprinterdata(struct cli_state
*cli
, TALLOC_CTX
*mem_ctx
,
2269 POLICY_HND
*hnd
, char *valuename
)
2271 prs_struct qbuf
, rbuf
;
2272 SPOOL_Q_DELETEPRINTERDATA q
;
2273 SPOOL_R_DELETEPRINTERDATA r
;
2274 WERROR result
= W_ERROR(ERRgeneral
);
2279 /* Initialise parse structures */
2281 prs_init(&qbuf
, MAX_PDU_FRAG_LEN
, mem_ctx
, MARSHALL
);
2282 prs_init(&rbuf
, 0, mem_ctx
, UNMARSHALL
);
2284 /* Initialise input parameters */
2286 make_spoolss_q_deleteprinterdata(&q
, hnd
, valuename
);
2288 /* Marshall data and send request */
2290 if (!spoolss_io_q_deleteprinterdata("", &q
, &qbuf
, 0) ||
2291 !rpc_api_pipe_req(cli
, SPOOLSS_DELETEPRINTERDATA
, &qbuf
, &rbuf
))
2294 /* Unmarshall response */
2296 if (!spoolss_io_r_deleteprinterdata("", &r
, &rbuf
, 0))
2301 if (!W_ERROR_IS_OK(r
.status
))
2305 prs_mem_free(&qbuf
);
2306 prs_mem_free(&rbuf
);
2311 WERROR
cli_spoolss_deleteprinterdataex(struct cli_state
*cli
, TALLOC_CTX
*mem_ctx
,
2312 POLICY_HND
*hnd
, char *keyname
,
2315 prs_struct qbuf
, rbuf
;
2316 SPOOL_Q_DELETEPRINTERDATAEX q
;
2317 SPOOL_R_DELETEPRINTERDATAEX r
;
2318 WERROR result
= W_ERROR(ERRgeneral
);
2323 /* Initialise parse structures */
2325 prs_init(&qbuf
, MAX_PDU_FRAG_LEN
, mem_ctx
, MARSHALL
);
2326 prs_init(&rbuf
, 0, mem_ctx
, UNMARSHALL
);
2328 /* Initialise input parameters */
2330 make_spoolss_q_deleteprinterdataex(&q
, hnd
, keyname
, valuename
);
2332 /* Marshall data and send request */
2334 if (!spoolss_io_q_deleteprinterdataex("", &q
, &qbuf
, 0) ||
2335 !rpc_api_pipe_req(cli
, SPOOLSS_DELETEPRINTERDATAEX
, &qbuf
, &rbuf
))
2338 /* Unmarshall response */
2340 if (!spoolss_io_r_deleteprinterdataex("", &r
, &rbuf
, 0))
2345 if (!W_ERROR_IS_OK(r
.status
))
2349 prs_mem_free(&qbuf
);
2350 prs_mem_free(&rbuf
);