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 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
);
409 slprintf (server
, sizeof(fstring
)-1, "\\\\%s", cli
->desthost
);
412 /* Initialise input parameters */
414 init_buffer(&buffer
, offered
, mem_ctx
);
416 prs_init(&qbuf
, MAX_PDU_FRAG_LEN
, mem_ctx
, MARSHALL
);
417 prs_init(&rbuf
, 0, mem_ctx
, UNMARSHALL
);
419 make_spoolss_q_enumprinters(&q
, flags
, server
, level
, &buffer
,
422 /* Marshall data and send request */
424 if (!spoolss_io_q_enumprinters("", &q
, &qbuf
, 0) ||
425 !rpc_api_pipe_req(cli
, SPOOLSS_ENUMPRINTERS
, &qbuf
, &rbuf
))
428 /* Unmarshall response */
430 if (spoolss_io_r_enumprinters("", &r
, &rbuf
, 0)) {
437 /* Return output parameters */
439 if (!W_ERROR_IS_OK(r
.status
))
443 *num_printers
= r
.returned
;
450 decode_printer_info_0(mem_ctx
, r
.buffer
, r
.returned
,
454 decode_printer_info_1(mem_ctx
, r
.buffer
, r
.returned
,
458 decode_printer_info_2(mem_ctx
, r
.buffer
, r
.returned
,
462 decode_printer_info_3(mem_ctx
, r
.buffer
, r
.returned
,
474 /*********************************************************************************
475 Win32 API - EnumPorts()
476 ********************************************************************************/
477 /** Enumerate printer ports on a print server.
479 * @param cli Pointer to client state structure which is open
480 * on the SPOOLSS pipe.
481 * @param mem_ctx Pointer to an initialised talloc context.
483 * @param offered Buffer size offered in the request.
484 * @param needed Number of bytes needed to complete the request.
487 * @param level Requested information level.
489 * @param num_ports Pointer to number of ports returned. May be NULL.
490 * @param ctr Pointer to structure holding port information.
494 WERROR
cli_spoolss_enum_ports(struct cli_state
*cli
, TALLOC_CTX
*mem_ctx
,
495 uint32 offered
, uint32
*needed
,
496 uint32 level
, int *num_ports
, PORT_INFO_CTR
*ctr
)
498 prs_struct qbuf
, rbuf
;
502 WERROR result
= W_ERROR(ERRgeneral
);
508 slprintf (server
, sizeof(fstring
)-1, "\\\\%s", cli
->desthost
);
511 /* Initialise input parameters */
513 init_buffer(&buffer
, offered
, mem_ctx
);
515 prs_init(&qbuf
, MAX_PDU_FRAG_LEN
, mem_ctx
, MARSHALL
);
516 prs_init(&rbuf
, 0, mem_ctx
, UNMARSHALL
);
518 make_spoolss_q_enumports(&q
, server
, level
, &buffer
, offered
);
520 /* Marshall data and send request */
522 if (!spoolss_io_q_enumports("", &q
, &qbuf
, 0) ||
523 !rpc_api_pipe_req(cli
, SPOOLSS_ENUMPORTS
, &qbuf
, &rbuf
))
526 /* Unmarshall response */
528 if (spoolss_io_r_enumports("", &r
, &rbuf
, 0)) {
535 /* Return output parameters */
537 if (!W_ERROR_IS_OK(result
))
541 *num_ports
= r
.returned
;
548 decode_port_info_1(mem_ctx
, r
.buffer
, r
.returned
,
552 decode_port_info_2(mem_ctx
, r
.buffer
, r
.returned
,
564 /*********************************************************************************
565 Win32 API - GetPrinter()
566 ********************************************************************************/
568 WERROR
cli_spoolss_getprinter(struct cli_state
*cli
, TALLOC_CTX
*mem_ctx
,
569 uint32 offered
, uint32
*needed
,
570 POLICY_HND
*pol
, uint32 level
,
571 PRINTER_INFO_CTR
*ctr
)
573 prs_struct qbuf
, rbuf
;
574 SPOOL_Q_GETPRINTER q
;
575 SPOOL_R_GETPRINTER r
;
577 WERROR result
= W_ERROR(ERRgeneral
);
582 /* Initialise input parameters */
584 init_buffer(&buffer
, offered
, mem_ctx
);
586 prs_init(&qbuf
, MAX_PDU_FRAG_LEN
, mem_ctx
, MARSHALL
);
587 prs_init(&rbuf
, 0, mem_ctx
, UNMARSHALL
);
589 make_spoolss_q_getprinter(mem_ctx
, &q
, pol
, level
, &buffer
, offered
);
591 /* Marshall data and send request */
593 if (!spoolss_io_q_getprinter("", &q
, &qbuf
, 0) ||
594 !rpc_api_pipe_req(cli
, SPOOLSS_GETPRINTER
, &qbuf
, &rbuf
))
597 /* Unmarshall response */
599 if (!spoolss_io_r_getprinter("", &r
, &rbuf
, 0))
605 /* Return output parameters */
609 if (W_ERROR_IS_OK(result
)) {
612 decode_printer_info_0(mem_ctx
, r
.buffer
, 1, &ctr
->printers_0
);
615 decode_printer_info_1(mem_ctx
, r
.buffer
, 1, &ctr
->printers_1
);
618 decode_printer_info_2(mem_ctx
, r
.buffer
, 1, &ctr
->printers_2
);
621 decode_printer_info_3(mem_ctx
, r
.buffer
, 1, &ctr
->printers_3
);
633 /*********************************************************************************
634 Win32 API - SetPrinter()
635 ********************************************************************************/
638 * @param cli Pointer to client state structure which is open
639 * on the SPOOLSS pipe.
640 * @param mem_ctx Pointer to an initialised talloc context.
642 * @param pol Policy handle on printer to set info.
643 * @param level Information level to set.
644 * @param ctr Pointer to structure holding printer information.
645 * @param command Specifies the action performed. See
646 * http://msdn.microsoft.com/library/default.asp?url=/library/en-us/gdi/prntspol_13ua.asp
651 WERROR
cli_spoolss_setprinter(struct cli_state
*cli
, TALLOC_CTX
*mem_ctx
,
652 POLICY_HND
*pol
, uint32 level
,
653 PRINTER_INFO_CTR
*ctr
, uint32 command
)
655 prs_struct qbuf
, rbuf
;
656 SPOOL_Q_SETPRINTER q
;
657 SPOOL_R_SETPRINTER r
;
658 WERROR result
= W_ERROR(ERRgeneral
);
663 /* Initialise input parameters */
665 prs_init(&qbuf
, MAX_PDU_FRAG_LEN
, mem_ctx
, MARSHALL
);
666 prs_init(&rbuf
, 0, mem_ctx
, UNMARSHALL
);
668 make_spoolss_q_setprinter(mem_ctx
, &q
, pol
, level
, ctr
, command
);
670 /* Marshall data and send request */
672 if (!spoolss_io_q_setprinter("", &q
, &qbuf
, 0) ||
673 !rpc_api_pipe_req(cli
, SPOOLSS_SETPRINTER
, &qbuf
, &rbuf
))
676 /* Unmarshall response */
678 if (!spoolss_io_r_setprinter("", &r
, &rbuf
, 0))
690 /*********************************************************************************
691 Win32 API - GetPrinterDriver()
692 ********************************************************************************/
693 /** Get installed printer drivers for a given printer
695 * @param cli Pointer to client state structure which is open
696 * on the SPOOLSS pipe.
698 * @param mem_ctx Pointer to an initialised talloc context.
700 * @param offered Buffer size offered in the request.
701 * @param needed Number of bytes needed to complete the request.
704 * @param pol Pointer to an open policy handle for the printer
705 * opened with cli_spoolss_open_printer_ex().
706 * @param level Requested information level.
707 * @param env The print environment or archictecture. This is
708 * "Windows NT x86" for NT4.
709 * @param ctr Returned printer driver information.
712 WERROR
cli_spoolss_getprinterdriver(struct cli_state
*cli
,
714 uint32 offered
, uint32
*needed
,
715 POLICY_HND
*pol
, uint32 level
,
716 char *env
, PRINTER_DRIVER_CTR
*ctr
)
718 prs_struct qbuf
, rbuf
;
719 SPOOL_Q_GETPRINTERDRIVER2 q
;
720 SPOOL_R_GETPRINTERDRIVER2 r
;
722 WERROR result
= W_ERROR(ERRgeneral
);
728 fstrcpy (server
, cli
->desthost
);
731 /* Initialise input parameters */
733 init_buffer(&buffer
, offered
, mem_ctx
);
735 prs_init(&qbuf
, MAX_PDU_FRAG_LEN
, mem_ctx
, MARSHALL
);
736 prs_init(&rbuf
, 0, mem_ctx
, UNMARSHALL
);
738 make_spoolss_q_getprinterdriver2(&q
, pol
, env
, level
, 2, 2,
741 /* Marshall data and send request */
743 if (!spoolss_io_q_getprinterdriver2 ("", &q
, &qbuf
, 0) ||
744 !rpc_api_pipe_req (cli
, SPOOLSS_GETPRINTERDRIVER2
, &qbuf
, &rbuf
))
747 /* Unmarshall response */
749 if (spoolss_io_r_getprinterdriver2 ("", &r
, &rbuf
, 0)) {
756 /* Return output parameters */
758 if (!W_ERROR_IS_OK(result
))
766 decode_printer_driver_1(mem_ctx
, r
.buffer
, 1, &ctr
->info1
);
769 decode_printer_driver_2(mem_ctx
, r
.buffer
, 1, &ctr
->info2
);
772 decode_printer_driver_3(mem_ctx
, r
.buffer
, 1, &ctr
->info3
);
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
);
866 /*********************************************************************************
867 Win32 API - GetPrinterDriverDirectory()
868 ********************************************************************************/
869 /**********************************************************************
870 * Get installed printer drivers for a given printer
872 WERROR
cli_spoolss_getprinterdriverdir (struct cli_state
*cli
,
874 uint32 offered
, uint32
*needed
,
875 uint32 level
, char *env
,
876 DRIVER_DIRECTORY_CTR
*ctr
)
878 prs_struct qbuf
, rbuf
;
879 SPOOL_Q_GETPRINTERDRIVERDIR q
;
880 SPOOL_R_GETPRINTERDRIVERDIR r
;
882 WERROR result
= W_ERROR(ERRgeneral
);
888 slprintf (server
, sizeof(fstring
)-1, "\\\\%s", cli
->desthost
);
891 /* Initialise input parameters */
893 init_buffer(&buffer
, offered
, mem_ctx
);
895 prs_init(&qbuf
, MAX_PDU_FRAG_LEN
, mem_ctx
, MARSHALL
);
896 prs_init(&rbuf
, 0, mem_ctx
, UNMARSHALL
);
898 /* Write the request */
900 make_spoolss_q_getprinterdriverdir(&q
, server
, env
, level
, &buffer
,
903 /* Marshall data and send request */
905 if (!spoolss_io_q_getprinterdriverdir ("", &q
, &qbuf
, 0) ||
906 !rpc_api_pipe_req (cli
, SPOOLSS_GETPRINTERDRIVERDIRECTORY
,
910 /* Unmarshall response */
912 if (spoolss_io_r_getprinterdriverdir ("", &r
, &rbuf
, 0)) {
917 /* Return output parameters */
921 if (W_ERROR_IS_OK(result
)) {
924 decode_printerdriverdir_1(mem_ctx
, r
.buffer
, 1,
937 /*********************************************************************************
938 Win32 API - AddPrinterDriver()
939 ********************************************************************************/
940 /**********************************************************************
941 * Install a printer driver
943 WERROR
cli_spoolss_addprinterdriver (struct cli_state
*cli
,
944 TALLOC_CTX
*mem_ctx
, uint32 level
,
945 PRINTER_DRIVER_CTR
*ctr
)
947 prs_struct qbuf
, rbuf
;
948 SPOOL_Q_ADDPRINTERDRIVER q
;
949 SPOOL_R_ADDPRINTERDRIVER r
;
950 WERROR result
= W_ERROR(ERRgeneral
);
956 slprintf (server
, sizeof(fstring
)-1, "\\\\%s", cli
->desthost
);
959 /* Initialise input parameters */
961 prs_init(&qbuf
, MAX_PDU_FRAG_LEN
, mem_ctx
, MARSHALL
);
962 prs_init(&rbuf
, 0, mem_ctx
, UNMARSHALL
);
964 /* Write the request */
966 make_spoolss_q_addprinterdriver (mem_ctx
, &q
, server
, level
, ctr
);
968 /* Marshall data and send request */
970 if (!spoolss_io_q_addprinterdriver ("", &q
, &qbuf
, 0) ||
971 !rpc_api_pipe_req (cli
, SPOOLSS_ADDPRINTERDRIVER
, &qbuf
, &rbuf
))
974 /* Unmarshall response */
976 if (!spoolss_io_r_addprinterdriver ("", &r
, &rbuf
, 0))
979 /* Return output parameters */
990 /*********************************************************************************
991 Win32 API - AddPrinter()
992 ********************************************************************************/
993 /**********************************************************************
996 WERROR
cli_spoolss_addprinterex (struct cli_state
*cli
, TALLOC_CTX
*mem_ctx
,
997 uint32 level
, PRINTER_INFO_CTR
*ctr
)
999 prs_struct qbuf
, rbuf
;
1000 SPOOL_Q_ADDPRINTEREX q
;
1001 SPOOL_R_ADDPRINTEREX r
;
1002 WERROR result
= W_ERROR(ERRgeneral
);
1010 slprintf (client
, sizeof(fstring
)-1, "\\\\%s", cli
->desthost
);
1012 slprintf (server
, sizeof(fstring
)-1, "\\\\%s", cli
->desthost
);
1014 fstrcpy (user
, cli
->user_name
);
1016 /* Initialise input parameters */
1018 prs_init(&qbuf
, MAX_PDU_FRAG_LEN
, mem_ctx
, MARSHALL
);
1019 prs_init(&rbuf
, 0, mem_ctx
, UNMARSHALL
);
1021 /* Write the request */
1023 make_spoolss_q_addprinterex (mem_ctx
, &q
, server
, client
, user
,
1026 /* Marshall data and send request */
1028 if (!spoolss_io_q_addprinterex ("", &q
, &qbuf
, 0) ||
1029 !rpc_api_pipe_req (cli
, SPOOLSS_ADDPRINTEREX
, &qbuf
, &rbuf
))
1032 /* Unmarshall response */
1034 if (!spoolss_io_r_addprinterex ("", &r
, &rbuf
, 0))
1037 /* Return output parameters */
1042 prs_mem_free(&qbuf
);
1043 prs_mem_free(&rbuf
);
1048 /*********************************************************************************
1049 Win32 API - DeltePrinterDriver()
1050 ********************************************************************************/
1051 /**********************************************************************
1052 * Delete a Printer Driver from the server (does not remove
1055 WERROR
cli_spoolss_deleteprinterdriver (struct cli_state
*cli
,
1056 TALLOC_CTX
*mem_ctx
, char *arch
,
1059 prs_struct qbuf
, rbuf
;
1060 SPOOL_Q_DELETEPRINTERDRIVER q
;
1061 SPOOL_R_DELETEPRINTERDRIVER r
;
1062 WERROR result
= W_ERROR(ERRgeneral
);
1069 /* Initialise input parameters */
1070 prs_init(&qbuf
, MAX_PDU_FRAG_LEN
, mem_ctx
, MARSHALL
);
1071 prs_init(&rbuf
, 0, mem_ctx
, UNMARSHALL
);
1073 slprintf (server
, sizeof(fstring
)-1, "\\\\%s", cli
->desthost
);
1076 /* Write the request */
1078 make_spoolss_q_deleteprinterdriver(mem_ctx
, &q
, server
, arch
, driver
);
1080 /* Marshall data and send request */
1082 if (!spoolss_io_q_deleteprinterdriver ("", &q
, &qbuf
, 0) ||
1083 !rpc_api_pipe_req (cli
,SPOOLSS_DELETEPRINTERDRIVER
, &qbuf
, &rbuf
))
1086 /* Unmarshall response */
1088 if (!spoolss_io_r_deleteprinterdriver ("", &r
, &rbuf
, 0))
1091 /* Return output parameters */
1096 prs_mem_free(&qbuf
);
1097 prs_mem_free(&rbuf
);
1102 /*********************************************************************************
1103 Win32 API - GetPrinterProcessorDirectory()
1104 ********************************************************************************/
1106 WERROR
cli_spoolss_getprintprocessordirectory(struct cli_state
*cli
,
1107 TALLOC_CTX
*mem_ctx
,
1108 uint32 offered
, uint32
*needed
,
1109 char *name
, char *environment
,
1112 prs_struct qbuf
, rbuf
;
1113 SPOOL_Q_GETPRINTPROCESSORDIRECTORY q
;
1114 SPOOL_R_GETPRINTPROCESSORDIRECTORY r
;
1116 WERROR result
= W_ERROR(ERRgeneral
);
1122 /* Initialise parse structures */
1124 prs_init(&qbuf
, MAX_PDU_FRAG_LEN
, mem_ctx
, MARSHALL
);
1125 prs_init(&rbuf
, 0, mem_ctx
, UNMARSHALL
);
1127 /* Initialise input parameters */
1129 init_buffer(&buffer
, offered
, mem_ctx
);
1131 make_spoolss_q_getprintprocessordirectory(
1132 &q
, name
, environment
, level
, &buffer
, offered
);
1134 /* Marshall data and send request */
1136 if (!spoolss_io_q_getprintprocessordirectory("", &q
, &qbuf
, 0) ||
1137 !rpc_api_pipe_req(cli
, SPOOLSS_GETPRINTPROCESSORDIRECTORY
,
1141 /* Unmarshall response */
1143 if (!spoolss_io_r_getprintprocessordirectory("", &r
, &rbuf
, 0))
1146 /* Return output parameters */
1153 if (W_ERROR_IS_OK(result
))
1154 fstrcpy(procdir
, "Not implemented!");
1157 prs_mem_free(&qbuf
);
1158 prs_mem_free(&rbuf
);
1163 /** Add a form to a printer.
1165 * @param cli Pointer to client state structure which is open
1166 * on the SPOOLSS pipe.
1167 * @param mem_ctx Pointer to an initialised talloc context.
1169 * @param handle Policy handle opened with cli_spoolss_open_printer_ex
1170 * or cli_spoolss_addprinterex.
1171 * @param level Form info level to add - should always be 1.
1172 * @param form A pointer to the form to be added.
1176 WERROR
cli_spoolss_addform(struct cli_state
*cli
, TALLOC_CTX
*mem_ctx
,
1177 POLICY_HND
*handle
, uint32 level
, FORM
*form
)
1179 prs_struct qbuf
, rbuf
;
1182 WERROR result
= W_ERROR(ERRgeneral
);
1187 /* Initialise parse structures */
1189 prs_init(&qbuf
, MAX_PDU_FRAG_LEN
, mem_ctx
, MARSHALL
);
1190 prs_init(&rbuf
, 0, mem_ctx
, UNMARSHALL
);
1192 /* Initialise input parameters */
1194 make_spoolss_q_addform(&q
, handle
, level
, form
);
1196 /* Marshall data and send request */
1198 if (!spoolss_io_q_addform("", &q
, &qbuf
, 0) ||
1199 !rpc_api_pipe_req(cli
, SPOOLSS_ADDFORM
, &qbuf
, &rbuf
))
1202 /* Unmarshall response */
1204 if (!spoolss_io_r_addform("", &r
, &rbuf
, 0))
1207 /* Return output parameters */
1212 prs_mem_free(&qbuf
);
1213 prs_mem_free(&rbuf
);
1218 /** Set a form on a printer.
1220 * @param cli Pointer to client state structure which is open
1221 * on the SPOOLSS pipe.
1222 * @param mem_ctx Pointer to an initialised talloc context.
1224 * @param handle Policy handle opened with cli_spoolss_open_printer_ex
1225 * or cli_spoolss_addprinterex.
1226 * @param level Form info level to set - should always be 1.
1227 * @param form A pointer to the form to be set.
1231 WERROR
cli_spoolss_setform(struct cli_state
*cli
, TALLOC_CTX
*mem_ctx
,
1232 POLICY_HND
*handle
, uint32 level
, char *form_name
,
1235 prs_struct qbuf
, rbuf
;
1238 WERROR result
= W_ERROR(ERRgeneral
);
1243 /* Initialise parse structures */
1245 prs_init(&qbuf
, MAX_PDU_FRAG_LEN
, mem_ctx
, MARSHALL
);
1246 prs_init(&rbuf
, 0, mem_ctx
, UNMARSHALL
);
1248 /* Initialise input parameters */
1250 make_spoolss_q_setform(&q
, handle
, level
, form_name
, form
);
1252 /* Marshall data and send request */
1254 if (!spoolss_io_q_setform("", &q
, &qbuf
, 0) ||
1255 !rpc_api_pipe_req(cli
, SPOOLSS_SETFORM
, &qbuf
, &rbuf
))
1258 /* Unmarshall response */
1260 if (!spoolss_io_r_setform("", &r
, &rbuf
, 0))
1263 /* Return output parameters */
1267 if (!W_ERROR_IS_OK(result
))
1273 prs_mem_free(&qbuf
);
1274 prs_mem_free(&rbuf
);
1279 /** Get a form on a printer.
1281 * @param cli Pointer to client state structure which is open
1282 * on the SPOOLSS pipe.
1283 * @param mem_ctx Pointer to an initialised talloc context.
1285 * @param handle Policy handle opened with cli_spoolss_open_printer_ex
1286 * or cli_spoolss_addprinterex.
1287 * @param formname Name of the form to get
1288 * @param level Form info level to get - should always be 1.
1292 WERROR
cli_spoolss_getform(struct cli_state
*cli
, TALLOC_CTX
*mem_ctx
,
1293 uint32 offered
, uint32
*needed
,
1294 POLICY_HND
*handle
, char *formname
, uint32 level
,
1297 prs_struct qbuf
, rbuf
;
1300 WERROR result
= W_ERROR(ERRgeneral
);
1306 /* Initialise parse structures */
1308 init_buffer(&buffer
, offered
, mem_ctx
);
1310 prs_init(&qbuf
, MAX_PDU_FRAG_LEN
, mem_ctx
, MARSHALL
);
1311 prs_init(&rbuf
, 0, mem_ctx
, UNMARSHALL
);
1313 /* Initialise input parameters */
1315 make_spoolss_q_getform(&q
, handle
, formname
, level
, &buffer
, offered
);
1317 /* Marshall data and send request */
1319 if (!spoolss_io_q_getform("", &q
, &qbuf
, 0) ||
1320 !rpc_api_pipe_req(cli
, SPOOLSS_GETFORM
, &qbuf
, &rbuf
))
1323 /* Unmarshall response */
1325 if (!spoolss_io_r_getform("", &r
, &rbuf
, 0))
1328 /* Return output parameters */
1335 if (W_ERROR_IS_OK(result
))
1336 smb_io_form_1("", r
.buffer
, form
, 0);
1339 prs_mem_free(&qbuf
);
1340 prs_mem_free(&rbuf
);
1345 /** Delete a form on a printer.
1347 * @param cli Pointer to client state structure which is open
1348 * on the SPOOLSS pipe.
1349 * @param mem_ctx Pointer to an initialised talloc context.
1351 * @param handle Policy handle opened with cli_spoolss_open_printer_ex
1352 * or cli_spoolss_addprinterex.
1353 * @param form The name of the form to delete.
1357 WERROR
cli_spoolss_deleteform(struct cli_state
*cli
, TALLOC_CTX
*mem_ctx
,
1358 POLICY_HND
*handle
, char *form_name
)
1360 prs_struct qbuf
, rbuf
;
1361 SPOOL_Q_DELETEFORM q
;
1362 SPOOL_R_DELETEFORM r
;
1363 WERROR result
= W_ERROR(ERRgeneral
);
1368 /* Initialise parse structures */
1370 prs_init(&qbuf
, MAX_PDU_FRAG_LEN
, mem_ctx
, MARSHALL
);
1371 prs_init(&rbuf
, 0, mem_ctx
, UNMARSHALL
);
1373 /* Initialise input parameters */
1375 make_spoolss_q_deleteform(&q
, handle
, form_name
);
1377 /* Marshall data and send request */
1379 if (!spoolss_io_q_deleteform("", &q
, &qbuf
, 0) ||
1380 !rpc_api_pipe_req(cli
, SPOOLSS_DELETEFORM
, &qbuf
, &rbuf
))
1383 /* Unmarshall response */
1385 if (!spoolss_io_r_deleteform("", &r
, &rbuf
, 0))
1388 /* Return output parameters */
1393 prs_mem_free(&qbuf
);
1394 prs_mem_free(&rbuf
);
1399 static void decode_forms_1(TALLOC_CTX
*mem_ctx
, NEW_BUFFER
*buffer
,
1400 uint32 num_forms
, FORM_1
**forms
)
1404 *forms
= (FORM_1
*)talloc(mem_ctx
, num_forms
* sizeof(FORM_1
));
1405 buffer
->prs
.data_offset
= 0;
1407 for (i
= 0; i
< num_forms
; i
++)
1408 smb_io_form_1("", buffer
, &((*forms
)[i
]), 0);
1413 * @param cli Pointer to client state structure which is open
1414 * on the SPOOLSS pipe.
1415 * @param mem_ctx Pointer to an initialised talloc context.
1417 * @param offered Buffer size offered in the request.
1418 * @param needed Number of bytes needed to complete the request.
1420 * or cli_spoolss_addprinterex.
1421 * @param level Form info level to get - should always be 1.
1422 * @param handle Open policy handle
1426 WERROR
cli_spoolss_enumforms(struct cli_state
*cli
, TALLOC_CTX
*mem_ctx
,
1427 uint32 offered
, uint32
*needed
,
1428 POLICY_HND
*handle
, int level
, uint32
*num_forms
,
1431 prs_struct qbuf
, rbuf
;
1432 SPOOL_Q_ENUMFORMS q
;
1433 SPOOL_R_ENUMFORMS r
;
1434 WERROR result
= W_ERROR(ERRgeneral
);
1440 /* Initialise parse structures */
1442 init_buffer(&buffer
, offered
, mem_ctx
);
1444 prs_init(&qbuf
, MAX_PDU_FRAG_LEN
, mem_ctx
, MARSHALL
);
1445 prs_init(&rbuf
, 0, mem_ctx
, UNMARSHALL
);
1447 /* Initialise input parameters */
1449 make_spoolss_q_enumforms(&q
, handle
, level
, &buffer
, offered
);
1451 /* Marshall data and send request */
1453 if (!spoolss_io_q_enumforms("", &q
, &qbuf
, 0) ||
1454 !rpc_api_pipe_req(cli
, SPOOLSS_ENUMFORMS
, &qbuf
, &rbuf
))
1457 /* Unmarshall response */
1459 if (!spoolss_io_r_enumforms("", &r
, &rbuf
, 0))
1462 /* Return output parameters */
1470 *num_forms
= r
.numofforms
;
1472 decode_forms_1(mem_ctx
, r
.buffer
, *num_forms
, forms
);
1475 prs_mem_free(&qbuf
);
1476 prs_mem_free(&rbuf
);
1481 static void decode_jobs_1(TALLOC_CTX
*mem_ctx
, NEW_BUFFER
*buffer
,
1482 uint32 num_jobs
, JOB_INFO_1
**jobs
)
1486 *jobs
= (JOB_INFO_1
*)talloc(mem_ctx
, num_jobs
* sizeof(JOB_INFO_1
));
1487 buffer
->prs
.data_offset
= 0;
1489 for (i
= 0; i
< num_jobs
; i
++)
1490 smb_io_job_info_1("", buffer
, &((*jobs
)[i
]), 0);
1493 static void decode_jobs_2(TALLOC_CTX
*mem_ctx
, NEW_BUFFER
*buffer
,
1494 uint32 num_jobs
, JOB_INFO_2
**jobs
)
1498 *jobs
= (JOB_INFO_2
*)talloc(mem_ctx
, num_jobs
* sizeof(JOB_INFO_2
));
1499 buffer
->prs
.data_offset
= 0;
1501 for (i
= 0; i
< num_jobs
; i
++)
1502 smb_io_job_info_2("", buffer
, &((*jobs
)[i
]), 0);
1505 /* Enumerate jobs */
1507 WERROR
cli_spoolss_enumjobs(struct cli_state
*cli
, TALLOC_CTX
*mem_ctx
,
1508 uint32 offered
, uint32
*needed
,
1509 POLICY_HND
*hnd
, uint32 level
, uint32 firstjob
,
1510 uint32 num_jobs
, uint32
*returned
, JOB_INFO_CTR
*ctr
)
1512 prs_struct qbuf
, rbuf
;
1515 WERROR result
= W_ERROR(ERRgeneral
);
1521 /* Initialise parse structures */
1523 init_buffer(&buffer
, offered
, mem_ctx
);
1525 prs_init(&qbuf
, MAX_PDU_FRAG_LEN
, mem_ctx
, MARSHALL
);
1526 prs_init(&rbuf
, 0, mem_ctx
, UNMARSHALL
);
1528 /* Initialise input parameters */
1530 make_spoolss_q_enumjobs(&q
, hnd
, firstjob
, num_jobs
, level
, &buffer
,
1533 /* Marshall data and send request */
1535 if (!spoolss_io_q_enumjobs("", &q
, &qbuf
, 0) ||
1536 !rpc_api_pipe_req(cli
, SPOOLSS_ENUMJOBS
, &qbuf
, &rbuf
))
1539 /* Unmarshall response */
1541 if (!spoolss_io_r_enumjobs("", &r
, &rbuf
, 0))
1544 /* Return output parameters */
1551 if (!W_ERROR_IS_OK(r
.status
))
1554 *returned
= r
.returned
;
1558 decode_jobs_1(mem_ctx
, r
.buffer
, r
.returned
,
1559 ctr
->job
.job_info_1
);
1562 decode_jobs_2(mem_ctx
, r
.buffer
, r
.returned
,
1563 ctr
->job
.job_info_2
);
1566 DEBUG(3, ("unsupported info level %d", level
));
1571 prs_mem_free(&qbuf
);
1572 prs_mem_free(&rbuf
);
1579 WERROR
cli_spoolss_setjob(struct cli_state
*cli
, TALLOC_CTX
*mem_ctx
,
1580 POLICY_HND
*hnd
, uint32 jobid
, uint32 level
,
1583 prs_struct qbuf
, rbuf
;
1586 WERROR result
= W_ERROR(ERRgeneral
);
1591 /* Initialise parse structures */
1593 prs_init(&qbuf
, MAX_PDU_FRAG_LEN
, mem_ctx
, MARSHALL
);
1594 prs_init(&rbuf
, 0, mem_ctx
, UNMARSHALL
);
1596 /* Initialise input parameters */
1598 make_spoolss_q_setjob(&q
, hnd
, jobid
, level
, command
);
1600 /* Marshall data and send request */
1602 if (!spoolss_io_q_setjob("", &q
, &qbuf
, 0) ||
1603 !rpc_api_pipe_req(cli
, SPOOLSS_SETJOB
, &qbuf
, &rbuf
))
1606 /* Unmarshall response */
1608 if (!spoolss_io_r_setjob("", &r
, &rbuf
, 0))
1611 /* Return output parameters */
1616 prs_mem_free(&qbuf
);
1617 prs_mem_free(&rbuf
);
1624 WERROR
cli_spoolss_getjob(struct cli_state
*cli
, TALLOC_CTX
*mem_ctx
,
1625 uint32 offered
, uint32
*needed
,
1626 POLICY_HND
*hnd
, uint32 jobid
, uint32 level
,
1629 prs_struct qbuf
, rbuf
;
1632 WERROR result
= W_ERROR(ERRgeneral
);
1638 /* Initialise parse structures */
1640 init_buffer(&buffer
, offered
, mem_ctx
);
1642 prs_init(&qbuf
, MAX_PDU_FRAG_LEN
, mem_ctx
, MARSHALL
);
1643 prs_init(&rbuf
, 0, mem_ctx
, UNMARSHALL
);
1645 /* Initialise input parameters */
1647 make_spoolss_q_getjob(&q
, hnd
, jobid
, level
, &buffer
, offered
);
1649 /* Marshall data and send request */
1651 if (!spoolss_io_q_getjob("", &q
, &qbuf
, 0) ||
1652 !rpc_api_pipe_req(cli
, SPOOLSS_GETJOB
, &qbuf
, &rbuf
))
1655 /* Unmarshall response */
1657 if (!spoolss_io_r_getjob("", &r
, &rbuf
, 0))
1660 /* Return output parameters */
1667 if (!W_ERROR_IS_OK(r
.status
))
1672 decode_jobs_1(mem_ctx
, r
.buffer
, 1, ctr
->job
.job_info_1
);
1675 decode_jobs_2(mem_ctx
, r
.buffer
, 1, ctr
->job
.job_info_2
);
1678 DEBUG(3, ("unsupported info level %d", level
));
1683 prs_mem_free(&qbuf
);
1684 prs_mem_free(&rbuf
);
1689 /* Startpageprinter. Sent to notify the spooler when a page is about to be
1690 sent to a printer. */
1692 WERROR
cli_spoolss_startpageprinter(struct cli_state
*cli
, TALLOC_CTX
*mem_ctx
,
1695 prs_struct qbuf
, rbuf
;
1696 SPOOL_Q_STARTPAGEPRINTER q
;
1697 SPOOL_R_STARTPAGEPRINTER r
;
1698 WERROR result
= W_ERROR(ERRgeneral
);
1703 /* Initialise parse structures */
1705 prs_init(&qbuf
, MAX_PDU_FRAG_LEN
, mem_ctx
, MARSHALL
);
1706 prs_init(&rbuf
, 0, mem_ctx
, UNMARSHALL
);
1708 /* Initialise input parameters */
1710 make_spoolss_q_startpageprinter(&q
, hnd
);
1712 /* Marshall data and send request */
1714 if (!spoolss_io_q_startpageprinter("", &q
, &qbuf
, 0) ||
1715 !rpc_api_pipe_req(cli
, SPOOLSS_STARTPAGEPRINTER
, &qbuf
, &rbuf
))
1718 /* Unmarshall response */
1720 if (!spoolss_io_r_startpageprinter("", &r
, &rbuf
, 0))
1723 /* Return output parameters */
1728 prs_mem_free(&qbuf
);
1729 prs_mem_free(&rbuf
);
1734 /* Endpageprinter. Sent to notify the spooler when a page has finished
1735 being sent to a printer. */
1737 WERROR
cli_spoolss_endpageprinter(struct cli_state
*cli
, TALLOC_CTX
*mem_ctx
,
1740 prs_struct qbuf
, rbuf
;
1741 SPOOL_Q_ENDPAGEPRINTER q
;
1742 SPOOL_R_ENDPAGEPRINTER r
;
1743 WERROR result
= W_ERROR(ERRgeneral
);
1748 /* Initialise parse structures */
1750 prs_init(&qbuf
, MAX_PDU_FRAG_LEN
, mem_ctx
, MARSHALL
);
1751 prs_init(&rbuf
, 0, mem_ctx
, UNMARSHALL
);
1753 /* Initialise input parameters */
1755 make_spoolss_q_endpageprinter(&q
, hnd
);
1757 /* Marshall data and send request */
1759 if (!spoolss_io_q_endpageprinter("", &q
, &qbuf
, 0) ||
1760 !rpc_api_pipe_req(cli
, SPOOLSS_ENDPAGEPRINTER
, &qbuf
, &rbuf
))
1763 /* Unmarshall response */
1765 if (!spoolss_io_r_endpageprinter("", &r
, &rbuf
, 0))
1768 /* Return output parameters */
1773 prs_mem_free(&qbuf
);
1774 prs_mem_free(&rbuf
);
1779 /* Startdocprinter. Sent to notify the spooler that a document is about
1780 to be spooled for printing. */
1782 WERROR
cli_spoolss_startdocprinter(struct cli_state
*cli
, TALLOC_CTX
*mem_ctx
,
1783 POLICY_HND
*hnd
, char *docname
,
1784 char *outputfile
, char *datatype
,
1787 prs_struct qbuf
, rbuf
;
1788 SPOOL_Q_STARTDOCPRINTER q
;
1789 SPOOL_R_STARTDOCPRINTER r
;
1790 WERROR result
= W_ERROR(ERRgeneral
);
1796 /* Initialise parse structures */
1798 prs_init(&qbuf
, MAX_PDU_FRAG_LEN
, mem_ctx
, MARSHALL
);
1799 prs_init(&rbuf
, 0, mem_ctx
, UNMARSHALL
);
1801 /* Initialise input parameters */
1803 make_spoolss_q_startdocprinter(&q
, hnd
, level
, docname
, outputfile
,
1806 /* Marshall data and send request */
1808 if (!spoolss_io_q_startdocprinter("", &q
, &qbuf
, 0) ||
1809 !rpc_api_pipe_req(cli
, SPOOLSS_STARTDOCPRINTER
, &qbuf
, &rbuf
))
1812 /* Unmarshall response */
1814 if (!spoolss_io_r_startdocprinter("", &r
, &rbuf
, 0))
1817 /* Return output parameters */
1821 if (W_ERROR_IS_OK(result
))
1825 prs_mem_free(&qbuf
);
1826 prs_mem_free(&rbuf
);
1831 /* Enddocprinter. Sent to notify the spooler that a document has finished
1834 WERROR
cli_spoolss_enddocprinter(struct cli_state
*cli
, TALLOC_CTX
*mem_ctx
,
1837 prs_struct qbuf
, rbuf
;
1838 SPOOL_Q_ENDDOCPRINTER q
;
1839 SPOOL_R_ENDDOCPRINTER r
;
1840 WERROR result
= W_ERROR(ERRgeneral
);
1845 /* Initialise parse structures */
1847 prs_init(&qbuf
, MAX_PDU_FRAG_LEN
, mem_ctx
, MARSHALL
);
1848 prs_init(&rbuf
, 0, mem_ctx
, UNMARSHALL
);
1850 /* Initialise input parameters */
1852 make_spoolss_q_enddocprinter(&q
, hnd
);
1854 /* Marshall data and send request */
1856 if (!spoolss_io_q_enddocprinter("", &q
, &qbuf
, 0) ||
1857 !rpc_api_pipe_req(cli
, SPOOLSS_ENDDOCPRINTER
, &qbuf
, &rbuf
))
1860 /* Unmarshall response */
1862 if (!spoolss_io_r_enddocprinter("", &r
, &rbuf
, 0))
1865 /* Return output parameters */
1870 prs_mem_free(&qbuf
);
1871 prs_mem_free(&rbuf
);
1876 /* Get printer data */
1878 WERROR
cli_spoolss_getprinterdata(struct cli_state
*cli
, TALLOC_CTX
*mem_ctx
,
1879 uint32 offered
, uint32
*needed
,
1880 POLICY_HND
*hnd
, char *valuename
,
1881 uint32
*data_type
, char **data
,
1884 prs_struct qbuf
, rbuf
;
1885 SPOOL_Q_GETPRINTERDATA q
;
1886 SPOOL_R_GETPRINTERDATA r
;
1887 WERROR result
= W_ERROR(ERRgeneral
);
1892 /* Initialise parse structures */
1894 prs_init(&qbuf
, MAX_PDU_FRAG_LEN
, mem_ctx
, MARSHALL
);
1895 prs_init(&rbuf
, 0, mem_ctx
, UNMARSHALL
);
1897 /* Initialise input parameters */
1899 make_spoolss_q_getprinterdata(&q
, hnd
, valuename
, offered
);
1901 /* Marshall data and send request */
1903 if (!spoolss_io_q_getprinterdata("", &q
, &qbuf
, 0) ||
1904 !rpc_api_pipe_req(cli
, SPOOLSS_GETPRINTERDATA
, &qbuf
, &rbuf
))
1907 /* Unmarshall response */
1909 if (!spoolss_io_r_getprinterdata("", &r
, &rbuf
, 0))
1917 if (!W_ERROR_IS_OK(r
.status
))
1920 /* Return output parameters */
1923 *data_type
= r
.type
;
1926 *data
= (char *)talloc(mem_ctx
, r
.needed
);
1927 memcpy(*data
, r
.data
, r
.needed
);
1931 *data_size
= r
.needed
;
1934 prs_mem_free(&qbuf
);
1935 prs_mem_free(&rbuf
);
1940 /* Set printer data */
1942 WERROR
cli_spoolss_setprinterdata(struct cli_state
*cli
, TALLOC_CTX
*mem_ctx
,
1943 POLICY_HND
*hnd
, char *value
,
1944 uint32 data_type
, char *data
,
1947 prs_struct qbuf
, rbuf
;
1948 SPOOL_Q_SETPRINTERDATA q
;
1949 SPOOL_R_SETPRINTERDATA r
;
1950 WERROR result
= W_ERROR(ERRgeneral
);
1955 /* Initialise parse structures */
1957 prs_init(&qbuf
, MAX_PDU_FRAG_LEN
, mem_ctx
, MARSHALL
);
1958 prs_init(&rbuf
, 0, mem_ctx
, UNMARSHALL
);
1960 /* Initialise input parameters */
1962 make_spoolss_q_setprinterdata(&q
, hnd
, value
, data
, data_size
);
1964 /* Marshall data and send request */
1966 if (!spoolss_io_q_setprinterdata("", &q
, &qbuf
, 0) ||
1967 !rpc_api_pipe_req(cli
, SPOOLSS_SETPRINTERDATA
, &qbuf
, &rbuf
))
1970 /* Unmarshall response */
1972 if (!spoolss_io_r_setprinterdata("", &r
, &rbuf
, 0))
1977 if (!W_ERROR_IS_OK(r
.status
))
1981 prs_mem_free(&qbuf
);
1982 prs_mem_free(&rbuf
);
1987 /* Enum printer data */
1989 WERROR
cli_spoolss_enumprinterdata(struct cli_state
*cli
, TALLOC_CTX
*mem_ctx
,
1990 POLICY_HND
*hnd
, uint32 ndx
,
1991 uint32 value_offered
, uint32 data_offered
,
1992 uint32
*value_needed
, uint32
*data_needed
,
1993 char **value
, uint32
*data_type
, char **data
,
1996 prs_struct qbuf
, rbuf
;
1997 SPOOL_Q_ENUMPRINTERDATA q
;
1998 SPOOL_R_ENUMPRINTERDATA r
;
1999 WERROR result
= W_ERROR(ERRgeneral
);
2004 /* Initialise parse structures */
2006 prs_init(&qbuf
, MAX_PDU_FRAG_LEN
, mem_ctx
, MARSHALL
);
2007 prs_init(&rbuf
, 0, mem_ctx
, UNMARSHALL
);
2009 /* Initialise input parameters */
2011 make_spoolss_q_enumprinterdata(&q
, hnd
, ndx
, value_offered
, data_offered
);
2013 /* Marshall data and send request */
2015 if (!spoolss_io_q_enumprinterdata("", &q
, &qbuf
, 0) ||
2016 !rpc_api_pipe_req(cli
, SPOOLSS_ENUMPRINTERDATA
, &qbuf
, &rbuf
))
2019 /* Unmarshall response */
2021 if (!spoolss_io_r_enumprinterdata("", &r
, &rbuf
, 0))
2026 if (!W_ERROR_IS_OK(r
.status
))
2032 *value_needed
= r
.realvaluesize
;
2035 *data_needed
= r
.realdatasize
;
2038 *data_type
= r
.type
;
2043 rpcstr_pull(the_value
, r
.value
, sizeof(the_value
), -1,
2046 *value
= talloc_strdup(mem_ctx
, the_value
);
2050 *data
= talloc_memdup(mem_ctx
, r
.data
, r
.realdatasize
);
2053 *data_size
= r
.realdatasize
;
2056 prs_mem_free(&qbuf
);
2057 prs_mem_free(&rbuf
);
2062 /* Write data to printer */
2064 WERROR
cli_spoolss_writeprinter(struct cli_state
*cli
, TALLOC_CTX
*mem_ctx
,
2065 POLICY_HND
*hnd
, uint32 data_size
, char *data
,
2066 uint32
*num_written
)
2068 prs_struct qbuf
, rbuf
;
2069 SPOOL_Q_WRITEPRINTER q
;
2070 SPOOL_R_WRITEPRINTER r
;
2071 WERROR result
= W_ERROR(ERRgeneral
);
2076 /* Initialise parse structures */
2078 prs_init(&qbuf
, MAX_PDU_FRAG_LEN
, mem_ctx
, MARSHALL
);
2079 prs_init(&rbuf
, 0, mem_ctx
, UNMARSHALL
);
2081 /* Initialise input parameters */
2083 make_spoolss_q_writeprinter(&q
, hnd
, data_size
, data
);
2085 /* Marshall data and send request */
2087 if (!spoolss_io_q_writeprinter("", &q
, &qbuf
, 0) ||
2088 !rpc_api_pipe_req(cli
, SPOOLSS_WRITEPRINTER
, &qbuf
, &rbuf
))
2091 /* Unmarshall response */
2093 if (!spoolss_io_r_writeprinter("", &r
, &rbuf
, 0))
2098 if (!W_ERROR_IS_OK(r
.status
))
2102 *num_written
= r
.buffer_written
;
2105 prs_mem_free(&qbuf
);
2106 prs_mem_free(&rbuf
);
2111 /* Delete printer data */
2113 WERROR
cli_spoolss_deleteprinterdata(struct cli_state
*cli
, TALLOC_CTX
*mem_ctx
,
2114 POLICY_HND
*hnd
, char *valuename
)
2116 prs_struct qbuf
, rbuf
;
2117 SPOOL_Q_DELETEPRINTERDATA q
;
2118 SPOOL_R_DELETEPRINTERDATA r
;
2119 WERROR result
= W_ERROR(ERRgeneral
);
2124 /* Initialise parse structures */
2126 prs_init(&qbuf
, MAX_PDU_FRAG_LEN
, mem_ctx
, MARSHALL
);
2127 prs_init(&rbuf
, 0, mem_ctx
, UNMARSHALL
);
2129 /* Initialise input parameters */
2131 make_spoolss_q_deleteprinterdata(&q
, hnd
, valuename
);
2133 /* Marshall data and send request */
2135 if (!spoolss_io_q_deleteprinterdata("", &q
, &qbuf
, 0) ||
2136 !rpc_api_pipe_req(cli
, SPOOLSS_DELETEPRINTERDATA
, &qbuf
, &rbuf
))
2139 /* Unmarshall response */
2141 if (!spoolss_io_r_deleteprinterdata("", &r
, &rbuf
, 0))
2146 if (!W_ERROR_IS_OK(r
.status
))
2150 prs_mem_free(&qbuf
);
2151 prs_mem_free(&rbuf
);