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
));
59 memset(inf
, 0, returned
*sizeof(PRINTER_INFO_0
));
61 prs_set_offset(&buffer
->prs
,0);
63 for (i
=0; i
<returned
; i
++) {
64 smb_io_printer_info_0("", buffer
, &inf
[i
], 0);
70 /**********************************************************************
71 **********************************************************************/
72 static void decode_printer_info_1(TALLOC_CTX
*mem_ctx
, NEW_BUFFER
*buffer
,
73 uint32 returned
, PRINTER_INFO_1
**info
)
78 inf
=(PRINTER_INFO_1
*)talloc(mem_ctx
, returned
*sizeof(PRINTER_INFO_1
));
79 memset(inf
, 0, returned
*sizeof(PRINTER_INFO_1
));
81 prs_set_offset(&buffer
->prs
,0);
83 for (i
=0; i
<returned
; i
++) {
84 smb_io_printer_info_1("", buffer
, &inf
[i
], 0);
90 /**********************************************************************
91 **********************************************************************/
92 static void decode_printer_info_2(TALLOC_CTX
*mem_ctx
, NEW_BUFFER
*buffer
,
93 uint32 returned
, PRINTER_INFO_2
**info
)
98 inf
=(PRINTER_INFO_2
*)talloc(mem_ctx
, returned
*sizeof(PRINTER_INFO_2
));
99 memset(inf
, 0, returned
*sizeof(PRINTER_INFO_2
));
101 prs_set_offset(&buffer
->prs
,0);
103 for (i
=0; i
<returned
; i
++) {
104 /* a little initialization as we go */
105 inf
[i
].secdesc
= NULL
;
106 smb_io_printer_info_2("", buffer
, &inf
[i
], 0);
112 /**********************************************************************
113 **********************************************************************/
114 static void decode_printer_info_3(TALLOC_CTX
*mem_ctx
, NEW_BUFFER
*buffer
,
115 uint32 returned
, PRINTER_INFO_3
**info
)
120 inf
=(PRINTER_INFO_3
*)talloc(mem_ctx
, returned
*sizeof(PRINTER_INFO_3
));
121 memset(inf
, 0, returned
*sizeof(PRINTER_INFO_3
));
123 prs_set_offset(&buffer
->prs
,0);
125 for (i
=0; i
<returned
; i
++) {
126 inf
[i
].secdesc
= NULL
;
127 smb_io_printer_info_3("", buffer
, &inf
[i
], 0);
133 /**********************************************************************
134 **********************************************************************/
135 static void decode_port_info_1(TALLOC_CTX
*mem_ctx
, NEW_BUFFER
*buffer
,
136 uint32 returned
, PORT_INFO_1
**info
)
141 inf
=(PORT_INFO_1
*)talloc(mem_ctx
, returned
*sizeof(PORT_INFO_1
));
142 memset(inf
, 0, returned
*sizeof(PORT_INFO_1
));
144 prs_set_offset(&buffer
->prs
, 0);
146 for (i
=0; i
<returned
; i
++) {
147 smb_io_port_info_1("", buffer
, &(inf
[i
]), 0);
153 /**********************************************************************
154 **********************************************************************/
155 static void decode_port_info_2(TALLOC_CTX
*mem_ctx
, NEW_BUFFER
*buffer
,
156 uint32 returned
, PORT_INFO_2
**info
)
161 inf
=(PORT_INFO_2
*)talloc(mem_ctx
, returned
*sizeof(PORT_INFO_2
));
162 memset(inf
, 0, returned
*sizeof(PORT_INFO_2
));
164 prs_set_offset(&buffer
->prs
, 0);
166 for (i
=0; i
<returned
; i
++) {
167 smb_io_port_info_2("", buffer
, &(inf
[i
]), 0);
173 /**********************************************************************
174 **********************************************************************/
175 static void decode_printer_driver_1(TALLOC_CTX
*mem_ctx
, NEW_BUFFER
*buffer
,
176 uint32 returned
, DRIVER_INFO_1
**info
)
181 inf
=(DRIVER_INFO_1
*)talloc(mem_ctx
, returned
*sizeof(DRIVER_INFO_1
));
182 memset(inf
, 0, returned
*sizeof(DRIVER_INFO_1
));
184 prs_set_offset(&buffer
->prs
,0);
186 for (i
=0; i
<returned
; i
++) {
187 smb_io_printer_driver_info_1("", buffer
, &(inf
[i
]), 0);
193 /**********************************************************************
194 **********************************************************************/
195 static void decode_printer_driver_2(TALLOC_CTX
*mem_ctx
, NEW_BUFFER
*buffer
,
196 uint32 returned
, DRIVER_INFO_2
**info
)
201 inf
=(DRIVER_INFO_2
*)talloc(mem_ctx
, returned
*sizeof(DRIVER_INFO_2
));
202 memset(inf
, 0, returned
*sizeof(DRIVER_INFO_2
));
204 prs_set_offset(&buffer
->prs
,0);
206 for (i
=0; i
<returned
; i
++) {
207 smb_io_printer_driver_info_2("", buffer
, &(inf
[i
]), 0);
213 /**********************************************************************
214 **********************************************************************/
215 static void decode_printer_driver_3(TALLOC_CTX
*mem_ctx
, NEW_BUFFER
*buffer
,
216 uint32 returned
, DRIVER_INFO_3
**info
)
221 inf
=(DRIVER_INFO_3
*)talloc(mem_ctx
, returned
*sizeof(DRIVER_INFO_3
));
222 memset(inf
, 0, returned
*sizeof(DRIVER_INFO_3
));
224 prs_set_offset(&buffer
->prs
,0);
226 for (i
=0; i
<returned
; i
++) {
227 smb_io_printer_driver_info_3("", buffer
, &(inf
[i
]), 0);
233 /**********************************************************************
234 **********************************************************************/
235 static void decode_printerdriverdir_1 (TALLOC_CTX
*mem_ctx
, NEW_BUFFER
*buffer
,
236 uint32 returned
, DRIVER_DIRECTORY_1
**info
239 DRIVER_DIRECTORY_1
*inf
;
241 inf
=(DRIVER_DIRECTORY_1
*)talloc(mem_ctx
, sizeof(DRIVER_DIRECTORY_1
));
242 memset(inf
, 0, sizeof(DRIVER_DIRECTORY_1
));
244 prs_set_offset(&buffer
->prs
, 0);
246 smb_io_driverdir_1("", buffer
, inf
, 0);
251 /** Return a handle to the specified printer or print server.
253 * @param cli Pointer to client state structure which is open
254 * on the SPOOLSS pipe.
256 * @param mem_ctx Pointer to an initialised talloc context.
258 * @param printername The name of the printer or print server to be
259 * opened in UNC format.
261 * @param datatype Specifies the default data type for the printer.
263 * @param access_required The access rights requested on the printer or
266 * @param station The UNC name of the requesting workstation.
268 * @param username The name of the user requesting the open.
270 * @param pol Returned policy handle.
273 /*********************************************************************************
274 Win32 API - OpenPrinter()
275 ********************************************************************************/
277 WERROR
cli_spoolss_open_printer_ex(struct cli_state
*cli
, TALLOC_CTX
*mem_ctx
,
278 const char *printername
, const char *datatype
, uint32 access_required
,
279 const char *station
, const char *username
, POLICY_HND
*pol
)
281 prs_struct qbuf
, rbuf
;
282 SPOOL_Q_OPEN_PRINTER_EX q
;
283 SPOOL_R_OPEN_PRINTER_EX r
;
284 WERROR result
= W_ERROR(ERRgeneral
);
289 /* Initialise parse structures */
291 prs_init(&qbuf
, MAX_PDU_FRAG_LEN
, mem_ctx
, MARSHALL
);
292 prs_init(&rbuf
, 0, mem_ctx
, UNMARSHALL
);
294 /* Initialise input parameters */
296 make_spoolss_q_open_printer_ex(&q
, printername
, datatype
,
297 access_required
, station
, username
);
299 /* Marshall data and send request */
301 if (!spoolss_io_q_open_printer_ex("", &q
, &qbuf
, 0) ||
302 !rpc_api_pipe_req(cli
, SPOOLSS_OPENPRINTEREX
, &qbuf
, &rbuf
))
305 /* Unmarshall response */
307 if (!spoolss_io_r_open_printer_ex("", &r
, &rbuf
, 0))
310 /* Return output parameters */
314 if (W_ERROR_IS_OK(result
))
324 /** Close a printer handle
326 * @param cli Pointer to client state structure which is open
327 * on the SPOOLSS pipe.
329 * @param mem_ctx Pointer to an initialised talloc context.
331 * @param pol Policy handle of printer or print server to close.
333 /*********************************************************************************
334 Win32 API - ClosePrinter()
335 ********************************************************************************/
337 WERROR
cli_spoolss_close_printer(struct cli_state
*cli
, TALLOC_CTX
*mem_ctx
,
340 prs_struct qbuf
, rbuf
;
341 SPOOL_Q_CLOSEPRINTER q
;
342 SPOOL_R_CLOSEPRINTER r
;
343 WERROR result
= W_ERROR(ERRgeneral
);
348 /* Initialise parse structures */
350 prs_init(&qbuf
, MAX_PDU_FRAG_LEN
, mem_ctx
, MARSHALL
);
351 prs_init(&rbuf
, 0, mem_ctx
, UNMARSHALL
);
353 /* Initialise input parameters */
355 make_spoolss_q_closeprinter(&q
, pol
);
357 /* Marshall data and send request */
359 if (!spoolss_io_q_closeprinter("", &q
, &qbuf
, 0) ||
360 !rpc_api_pipe_req(cli
, SPOOLSS_CLOSEPRINTER
, &qbuf
, &rbuf
))
363 /* Unmarshall response */
365 if (!spoolss_io_r_closeprinter("", &r
, &rbuf
, 0))
368 /* Return output parameters */
372 if (W_ERROR_IS_OK(result
))
382 /** Enumerate printers on a print server.
384 * @param cli Pointer to client state structure which is open
385 * on the SPOOLSS pipe.
386 * @param mem_ctx Pointer to an initialised talloc context.
388 * @param offered Buffer size offered in the request.
389 * @param needed Number of bytes needed to complete the request.
392 * @param flags Selected from PRINTER_ENUM_* flags.
393 * @param level Request information level.
395 * @param num_printers Pointer to number of printers returned. May be
397 * @param ctr Return structure for printer information. May
400 /*********************************************************************************
401 Win32 API - EnumPrinters()
402 ********************************************************************************/
404 WERROR
cli_spoolss_enum_printers(struct cli_state
*cli
, TALLOC_CTX
*mem_ctx
,
405 uint32 offered
, uint32
*needed
,
406 char *name
, uint32 flags
, uint32 level
,
407 uint32
*num_printers
, PRINTER_INFO_CTR
*ctr
)
409 prs_struct qbuf
, rbuf
;
410 SPOOL_Q_ENUMPRINTERS q
;
411 SPOOL_R_ENUMPRINTERS r
;
413 WERROR result
= W_ERROR(ERRgeneral
);
418 /* Initialise input parameters */
420 init_buffer(&buffer
, offered
, mem_ctx
);
422 prs_init(&qbuf
, MAX_PDU_FRAG_LEN
, mem_ctx
, MARSHALL
);
423 prs_init(&rbuf
, 0, mem_ctx
, UNMARSHALL
);
425 make_spoolss_q_enumprinters(&q
, flags
, name
, level
, &buffer
,
428 /* Marshall data and send request */
430 if (!spoolss_io_q_enumprinters("", &q
, &qbuf
, 0) ||
431 !rpc_api_pipe_req(cli
, SPOOLSS_ENUMPRINTERS
, &qbuf
, &rbuf
))
434 /* Unmarshall response */
436 if (spoolss_io_r_enumprinters("", &r
, &rbuf
, 0)) {
443 /* Return output parameters */
445 if (!W_ERROR_IS_OK(r
.status
))
449 *num_printers
= r
.returned
;
456 decode_printer_info_0(mem_ctx
, r
.buffer
, r
.returned
,
460 decode_printer_info_1(mem_ctx
, r
.buffer
, r
.returned
,
464 decode_printer_info_2(mem_ctx
, r
.buffer
, r
.returned
,
468 decode_printer_info_3(mem_ctx
, r
.buffer
, r
.returned
,
480 /*********************************************************************************
481 Win32 API - EnumPorts()
482 ********************************************************************************/
483 /** Enumerate printer ports on a print server.
485 * @param cli Pointer to client state structure which is open
486 * on the SPOOLSS pipe.
487 * @param mem_ctx Pointer to an initialised talloc context.
489 * @param offered Buffer size offered in the request.
490 * @param needed Number of bytes needed to complete the request.
493 * @param level Requested information level.
495 * @param num_ports Pointer to number of ports returned. May be NULL.
496 * @param ctr Pointer to structure holding port information.
500 WERROR
cli_spoolss_enum_ports(struct cli_state
*cli
, TALLOC_CTX
*mem_ctx
,
501 uint32 offered
, uint32
*needed
,
502 uint32 level
, uint32
*num_ports
, PORT_INFO_CTR
*ctr
)
504 prs_struct qbuf
, rbuf
;
508 WERROR result
= W_ERROR(ERRgeneral
);
514 slprintf(server
, sizeof(fstring
)-1, "\\\\%s", cli
->desthost
);
517 /* Initialise input parameters */
519 init_buffer(&buffer
, offered
, mem_ctx
);
521 prs_init(&qbuf
, MAX_PDU_FRAG_LEN
, mem_ctx
, MARSHALL
);
522 prs_init(&rbuf
, 0, mem_ctx
, UNMARSHALL
);
524 make_spoolss_q_enumports(&q
, server
, level
, &buffer
, offered
);
526 /* Marshall data and send request */
528 if (!spoolss_io_q_enumports("", &q
, &qbuf
, 0) ||
529 !rpc_api_pipe_req(cli
, SPOOLSS_ENUMPORTS
, &qbuf
, &rbuf
))
532 /* Unmarshall response */
534 if (spoolss_io_r_enumports("", &r
, &rbuf
, 0)) {
541 /* Return output parameters */
543 if (!W_ERROR_IS_OK(result
))
547 *num_ports
= r
.returned
;
554 decode_port_info_1(mem_ctx
, r
.buffer
, r
.returned
,
558 decode_port_info_2(mem_ctx
, r
.buffer
, r
.returned
,
570 /*********************************************************************************
571 Win32 API - GetPrinter()
572 ********************************************************************************/
574 WERROR
cli_spoolss_getprinter(struct cli_state
*cli
, TALLOC_CTX
*mem_ctx
,
575 uint32 offered
, uint32
*needed
,
576 POLICY_HND
*pol
, uint32 level
,
577 PRINTER_INFO_CTR
*ctr
)
579 prs_struct qbuf
, rbuf
;
580 SPOOL_Q_GETPRINTER q
;
581 SPOOL_R_GETPRINTER r
;
583 WERROR result
= W_ERROR(ERRgeneral
);
588 /* Initialise input parameters */
590 init_buffer(&buffer
, offered
, mem_ctx
);
592 prs_init(&qbuf
, MAX_PDU_FRAG_LEN
, mem_ctx
, MARSHALL
);
593 prs_init(&rbuf
, 0, mem_ctx
, UNMARSHALL
);
595 make_spoolss_q_getprinter(mem_ctx
, &q
, pol
, level
, &buffer
, offered
);
597 /* Marshall data and send request */
599 if (!spoolss_io_q_getprinter("", &q
, &qbuf
, 0) ||
600 !rpc_api_pipe_req(cli
, SPOOLSS_GETPRINTER
, &qbuf
, &rbuf
))
603 /* Unmarshall response */
605 if (!spoolss_io_r_getprinter("", &r
, &rbuf
, 0))
611 /* Return output parameters */
615 if (W_ERROR_IS_OK(result
)) {
618 decode_printer_info_0(mem_ctx
, r
.buffer
, 1, &ctr
->printers_0
);
621 decode_printer_info_1(mem_ctx
, r
.buffer
, 1, &ctr
->printers_1
);
624 decode_printer_info_2(mem_ctx
, r
.buffer
, 1, &ctr
->printers_2
);
627 decode_printer_info_3(mem_ctx
, r
.buffer
, 1, &ctr
->printers_3
);
639 /*********************************************************************************
640 Win32 API - SetPrinter()
641 ********************************************************************************/
644 * @param cli Pointer to client state structure which is open
645 * on the SPOOLSS pipe.
646 * @param mem_ctx Pointer to an initialised talloc context.
648 * @param pol Policy handle on printer to set info.
649 * @param level Information level to set.
650 * @param ctr Pointer to structure holding printer information.
651 * @param command Specifies the action performed. See
652 * http://msdn.microsoft.com/library/default.asp?url=/library/en-us/gdi/prntspol_13ua.asp
657 WERROR
cli_spoolss_setprinter(struct cli_state
*cli
, TALLOC_CTX
*mem_ctx
,
658 POLICY_HND
*pol
, uint32 level
,
659 PRINTER_INFO_CTR
*ctr
, uint32 command
)
661 prs_struct qbuf
, rbuf
;
662 SPOOL_Q_SETPRINTER q
;
663 SPOOL_R_SETPRINTER r
;
664 WERROR result
= W_ERROR(ERRgeneral
);
669 /* Initialise input parameters */
671 prs_init(&qbuf
, MAX_PDU_FRAG_LEN
, mem_ctx
, MARSHALL
);
672 prs_init(&rbuf
, 0, mem_ctx
, UNMARSHALL
);
674 if (!make_spoolss_q_setprinter(mem_ctx
, &q
, pol
, level
, ctr
, command
))
677 /* Marshall data and send request */
679 if (!spoolss_io_q_setprinter("", &q
, &qbuf
, 0) ||
680 !rpc_api_pipe_req(cli
, SPOOLSS_SETPRINTER
, &qbuf
, &rbuf
))
683 /* Unmarshall response */
685 if (!spoolss_io_r_setprinter("", &r
, &rbuf
, 0))
697 /*********************************************************************************
698 Win32 API - GetPrinterDriver()
699 ********************************************************************************/
700 /** Get installed printer drivers for a given printer
702 * @param cli Pointer to client state structure which is open
703 * on the SPOOLSS pipe.
705 * @param mem_ctx Pointer to an initialised talloc context.
707 * @param offered Buffer size offered in the request.
708 * @param needed Number of bytes needed to complete the request.
711 * @param pol Pointer to an open policy handle for the printer
712 * opened with cli_spoolss_open_printer_ex().
713 * @param level Requested information level.
714 * @param env The print environment or archictecture. This is
715 * "Windows NT x86" for NT4.
716 * @param ctr Returned printer driver information.
719 WERROR
cli_spoolss_getprinterdriver(struct cli_state
*cli
,
721 uint32 offered
, uint32
*needed
,
722 POLICY_HND
*pol
, uint32 level
,
723 const char *env
, int version
, PRINTER_DRIVER_CTR
*ctr
)
725 prs_struct qbuf
, rbuf
;
726 SPOOL_Q_GETPRINTERDRIVER2 q
;
727 SPOOL_R_GETPRINTERDRIVER2 r
;
729 WERROR result
= W_ERROR(ERRgeneral
);
735 fstrcpy(server
, cli
->desthost
);
738 /* Initialise input parameters */
740 init_buffer(&buffer
, offered
, mem_ctx
);
742 prs_init(&qbuf
, MAX_PDU_FRAG_LEN
, mem_ctx
, MARSHALL
);
743 prs_init(&rbuf
, 0, mem_ctx
, UNMARSHALL
);
745 make_spoolss_q_getprinterdriver2(&q
, pol
, env
, level
, version
, 2,
748 /* Marshall data and send request */
750 if (!spoolss_io_q_getprinterdriver2 ("", &q
, &qbuf
, 0) ||
751 !rpc_api_pipe_req (cli
, SPOOLSS_GETPRINTERDRIVER2
, &qbuf
, &rbuf
))
754 /* Unmarshall response */
756 if (spoolss_io_r_getprinterdriver2 ("", &r
, &rbuf
, 0)) {
763 /* Return output parameters */
765 if (!W_ERROR_IS_OK(result
))
773 decode_printer_driver_1(mem_ctx
, r
.buffer
, 1, &ctr
->info1
);
776 decode_printer_driver_2(mem_ctx
, r
.buffer
, 1, &ctr
->info2
);
779 decode_printer_driver_3(mem_ctx
, r
.buffer
, 1, &ctr
->info3
);
782 DEBUG(10, ("cli_spoolss_getprinterdriver: unknown info level %d", level
));
783 return WERR_UNKNOWN_LEVEL
;
793 /*********************************************************************************
794 Win32 API - EnumPrinterDrivers()
795 ********************************************************************************/
796 /**********************************************************************
797 * Get installed printer drivers for a given printer
799 WERROR
cli_spoolss_enumprinterdrivers (struct cli_state
*cli
,
801 uint32 offered
, uint32
*needed
,
802 uint32 level
, const char *env
,
804 PRINTER_DRIVER_CTR
*ctr
)
806 prs_struct qbuf
, rbuf
;
807 SPOOL_Q_ENUMPRINTERDRIVERS q
;
808 SPOOL_R_ENUMPRINTERDRIVERS r
;
810 WERROR result
= W_ERROR(ERRgeneral
);
816 slprintf(server
, sizeof(fstring
)-1, "\\\\%s", cli
->desthost
);
819 /* Initialise input parameters */
821 init_buffer(&buffer
, offered
, mem_ctx
);
823 prs_init(&qbuf
, MAX_PDU_FRAG_LEN
, mem_ctx
, MARSHALL
);
824 prs_init(&rbuf
, 0, mem_ctx
, UNMARSHALL
);
826 /* Write the request */
828 make_spoolss_q_enumprinterdrivers(&q
, server
, env
, level
, &buffer
,
831 /* Marshall data and send request */
833 if (!spoolss_io_q_enumprinterdrivers ("", &q
, &qbuf
, 0) ||
834 !rpc_api_pipe_req (cli
, SPOOLSS_ENUMPRINTERDRIVERS
, &qbuf
, &rbuf
))
837 /* Unmarshall response */
839 if (!spoolss_io_r_enumprinterdrivers ("", &r
, &rbuf
, 0))
846 *num_drivers
= r
.returned
;
850 /* Return output parameters */
852 if (W_ERROR_IS_OK(result
) && (r
.returned
!= 0)) {
853 *num_drivers
= r
.returned
;
857 decode_printer_driver_1(mem_ctx
, r
.buffer
, r
.returned
, &ctr
->info1
);
860 decode_printer_driver_2(mem_ctx
, r
.buffer
, r
.returned
, &ctr
->info2
);
863 decode_printer_driver_3(mem_ctx
, r
.buffer
, r
.returned
, &ctr
->info3
);
866 DEBUG(10, ("cli_spoolss_enumprinterdrivers: unknown info level %d\n",
868 return WERR_UNKNOWN_LEVEL
;
880 /*********************************************************************************
881 Win32 API - GetPrinterDriverDirectory()
882 ********************************************************************************/
883 /**********************************************************************
884 * Get installed printer drivers for a given printer
886 WERROR
cli_spoolss_getprinterdriverdir (struct cli_state
*cli
,
888 uint32 offered
, uint32
*needed
,
889 uint32 level
, char *env
,
890 DRIVER_DIRECTORY_CTR
*ctr
)
892 prs_struct qbuf
, rbuf
;
893 SPOOL_Q_GETPRINTERDRIVERDIR q
;
894 SPOOL_R_GETPRINTERDRIVERDIR r
;
896 WERROR result
= W_ERROR(ERRgeneral
);
902 slprintf(server
, sizeof(fstring
)-1, "\\\\%s", cli
->desthost
);
905 /* Initialise input parameters */
907 init_buffer(&buffer
, offered
, mem_ctx
);
909 prs_init(&qbuf
, MAX_PDU_FRAG_LEN
, mem_ctx
, MARSHALL
);
910 prs_init(&rbuf
, 0, mem_ctx
, UNMARSHALL
);
912 /* Write the request */
914 make_spoolss_q_getprinterdriverdir(&q
, server
, env
, level
, &buffer
,
917 /* Marshall data and send request */
919 if (!spoolss_io_q_getprinterdriverdir ("", &q
, &qbuf
, 0) ||
920 !rpc_api_pipe_req (cli
, SPOOLSS_GETPRINTERDRIVERDIRECTORY
,
924 /* Unmarshall response */
926 if (spoolss_io_r_getprinterdriverdir ("", &r
, &rbuf
, 0)) {
931 /* Return output parameters */
935 if (W_ERROR_IS_OK(result
)) {
938 decode_printerdriverdir_1(mem_ctx
, r
.buffer
, 1,
951 /*********************************************************************************
952 Win32 API - AddPrinterDriver()
953 ********************************************************************************/
954 /**********************************************************************
955 * Install a printer driver
957 WERROR
cli_spoolss_addprinterdriver (struct cli_state
*cli
,
958 TALLOC_CTX
*mem_ctx
, uint32 level
,
959 PRINTER_DRIVER_CTR
*ctr
)
961 prs_struct qbuf
, rbuf
;
962 SPOOL_Q_ADDPRINTERDRIVER q
;
963 SPOOL_R_ADDPRINTERDRIVER r
;
964 WERROR result
= W_ERROR(ERRgeneral
);
970 slprintf(server
, sizeof(fstring
)-1, "\\\\%s", cli
->desthost
);
973 /* Initialise input parameters */
975 prs_init(&qbuf
, MAX_PDU_FRAG_LEN
, mem_ctx
, MARSHALL
);
976 prs_init(&rbuf
, 0, mem_ctx
, UNMARSHALL
);
978 /* Write the request */
980 make_spoolss_q_addprinterdriver (mem_ctx
, &q
, server
, level
, ctr
);
982 /* Marshall data and send request */
984 if (!spoolss_io_q_addprinterdriver ("", &q
, &qbuf
, 0) ||
985 !rpc_api_pipe_req (cli
, SPOOLSS_ADDPRINTERDRIVER
, &qbuf
, &rbuf
))
988 /* Unmarshall response */
990 if (!spoolss_io_r_addprinterdriver ("", &r
, &rbuf
, 0))
993 /* Return output parameters */
1004 /*********************************************************************************
1005 Win32 API - AddPrinter()
1006 ********************************************************************************/
1007 /**********************************************************************
1010 WERROR
cli_spoolss_addprinterex (struct cli_state
*cli
, TALLOC_CTX
*mem_ctx
,
1011 uint32 level
, PRINTER_INFO_CTR
*ctr
)
1013 prs_struct qbuf
, rbuf
;
1014 SPOOL_Q_ADDPRINTEREX q
;
1015 SPOOL_R_ADDPRINTEREX r
;
1016 WERROR result
= W_ERROR(ERRgeneral
);
1024 slprintf(client
, sizeof(fstring
)-1, "\\\\%s", cli
->desthost
);
1026 slprintf(server
, sizeof(fstring
)-1, "\\\\%s", cli
->desthost
);
1028 fstrcpy (user
, cli
->user_name
);
1030 /* Initialise input parameters */
1032 prs_init(&qbuf
, MAX_PDU_FRAG_LEN
, mem_ctx
, MARSHALL
);
1033 prs_init(&rbuf
, 0, mem_ctx
, UNMARSHALL
);
1035 /* Write the request */
1037 make_spoolss_q_addprinterex (mem_ctx
, &q
, server
, client
, user
,
1040 /* Marshall data and send request */
1042 if (!spoolss_io_q_addprinterex ("", &q
, &qbuf
, 0) ||
1043 !rpc_api_pipe_req (cli
, SPOOLSS_ADDPRINTEREX
, &qbuf
, &rbuf
))
1046 /* Unmarshall response */
1048 if (!spoolss_io_r_addprinterex ("", &r
, &rbuf
, 0))
1051 /* Return output parameters */
1056 prs_mem_free(&qbuf
);
1057 prs_mem_free(&rbuf
);
1062 /*********************************************************************************
1063 Win32 API - DeltePrinterDriver()
1064 ********************************************************************************/
1065 /**********************************************************************
1066 * Delete a Printer Driver from the server (does not remove
1069 WERROR
cli_spoolss_deleteprinterdriver (struct cli_state
*cli
,
1070 TALLOC_CTX
*mem_ctx
, const char *arch
,
1073 prs_struct qbuf
, rbuf
;
1074 SPOOL_Q_DELETEPRINTERDRIVER q
;
1075 SPOOL_R_DELETEPRINTERDRIVER r
;
1076 WERROR result
= W_ERROR(ERRgeneral
);
1083 /* Initialise input parameters */
1084 prs_init(&qbuf
, MAX_PDU_FRAG_LEN
, mem_ctx
, MARSHALL
);
1085 prs_init(&rbuf
, 0, mem_ctx
, UNMARSHALL
);
1087 slprintf(server
, sizeof(fstring
)-1, "\\\\%s", cli
->desthost
);
1090 /* Write the request */
1092 make_spoolss_q_deleteprinterdriver(mem_ctx
, &q
, server
, arch
, driver
);
1094 /* Marshall data and send request */
1096 if (!spoolss_io_q_deleteprinterdriver ("", &q
, &qbuf
, 0) ||
1097 !rpc_api_pipe_req (cli
,SPOOLSS_DELETEPRINTERDRIVER
, &qbuf
, &rbuf
))
1100 /* Unmarshall response */
1102 if (!spoolss_io_r_deleteprinterdriver ("", &r
, &rbuf
, 0))
1105 /* Return output parameters */
1110 prs_mem_free(&qbuf
);
1111 prs_mem_free(&rbuf
);
1116 /*********************************************************************************
1117 Win32 API - GetPrinterProcessorDirectory()
1118 ********************************************************************************/
1120 WERROR
cli_spoolss_getprintprocessordirectory(struct cli_state
*cli
,
1121 TALLOC_CTX
*mem_ctx
,
1122 uint32 offered
, uint32
*needed
,
1123 char *name
, char *environment
,
1126 prs_struct qbuf
, rbuf
;
1127 SPOOL_Q_GETPRINTPROCESSORDIRECTORY q
;
1128 SPOOL_R_GETPRINTPROCESSORDIRECTORY r
;
1130 WERROR result
= W_ERROR(ERRgeneral
);
1136 /* Initialise parse structures */
1138 prs_init(&qbuf
, MAX_PDU_FRAG_LEN
, mem_ctx
, MARSHALL
);
1139 prs_init(&rbuf
, 0, mem_ctx
, UNMARSHALL
);
1141 /* Initialise input parameters */
1143 init_buffer(&buffer
, offered
, mem_ctx
);
1145 make_spoolss_q_getprintprocessordirectory(
1146 &q
, name
, environment
, level
, &buffer
, offered
);
1148 /* Marshall data and send request */
1150 if (!spoolss_io_q_getprintprocessordirectory("", &q
, &qbuf
, 0) ||
1151 !rpc_api_pipe_req(cli
, SPOOLSS_GETPRINTPROCESSORDIRECTORY
,
1155 /* Unmarshall response */
1157 if (!spoolss_io_r_getprintprocessordirectory("", &r
, &rbuf
, 0))
1160 /* Return output parameters */
1167 if (W_ERROR_IS_OK(result
))
1168 fstrcpy(procdir
, "Not implemented!");
1171 prs_mem_free(&qbuf
);
1172 prs_mem_free(&rbuf
);
1177 /** Add a form to a printer.
1179 * @param cli Pointer to client state structure which is open
1180 * on the SPOOLSS pipe.
1181 * @param mem_ctx Pointer to an initialised talloc context.
1183 * @param handle Policy handle opened with cli_spoolss_open_printer_ex
1184 * or cli_spoolss_addprinterex.
1185 * @param level Form info level to add - should always be 1.
1186 * @param form A pointer to the form to be added.
1190 WERROR
cli_spoolss_addform(struct cli_state
*cli
, TALLOC_CTX
*mem_ctx
,
1191 POLICY_HND
*handle
, uint32 level
, FORM
*form
)
1193 prs_struct qbuf
, rbuf
;
1196 WERROR result
= W_ERROR(ERRgeneral
);
1201 /* Initialise parse structures */
1203 prs_init(&qbuf
, MAX_PDU_FRAG_LEN
, mem_ctx
, MARSHALL
);
1204 prs_init(&rbuf
, 0, mem_ctx
, UNMARSHALL
);
1206 /* Initialise input parameters */
1208 make_spoolss_q_addform(&q
, handle
, level
, form
);
1210 /* Marshall data and send request */
1212 if (!spoolss_io_q_addform("", &q
, &qbuf
, 0) ||
1213 !rpc_api_pipe_req(cli
, SPOOLSS_ADDFORM
, &qbuf
, &rbuf
))
1216 /* Unmarshall response */
1218 if (!spoolss_io_r_addform("", &r
, &rbuf
, 0))
1221 /* Return output parameters */
1226 prs_mem_free(&qbuf
);
1227 prs_mem_free(&rbuf
);
1232 /** Set a form on a printer.
1234 * @param cli Pointer to client state structure which is open
1235 * on the SPOOLSS pipe.
1236 * @param mem_ctx Pointer to an initialised talloc context.
1238 * @param handle Policy handle opened with cli_spoolss_open_printer_ex
1239 * or cli_spoolss_addprinterex.
1240 * @param level Form info level to set - should always be 1.
1241 * @param form A pointer to the form to be set.
1245 WERROR
cli_spoolss_setform(struct cli_state
*cli
, TALLOC_CTX
*mem_ctx
,
1246 POLICY_HND
*handle
, uint32 level
,
1247 const char *form_name
, FORM
*form
)
1249 prs_struct qbuf
, rbuf
;
1252 WERROR result
= W_ERROR(ERRgeneral
);
1257 /* Initialise parse structures */
1259 prs_init(&qbuf
, MAX_PDU_FRAG_LEN
, mem_ctx
, MARSHALL
);
1260 prs_init(&rbuf
, 0, mem_ctx
, UNMARSHALL
);
1262 /* Initialise input parameters */
1264 make_spoolss_q_setform(&q
, handle
, level
, form_name
, form
);
1266 /* Marshall data and send request */
1268 if (!spoolss_io_q_setform("", &q
, &qbuf
, 0) ||
1269 !rpc_api_pipe_req(cli
, SPOOLSS_SETFORM
, &qbuf
, &rbuf
))
1272 /* Unmarshall response */
1274 if (!spoolss_io_r_setform("", &r
, &rbuf
, 0))
1277 /* Return output parameters */
1281 if (!W_ERROR_IS_OK(result
))
1287 prs_mem_free(&qbuf
);
1288 prs_mem_free(&rbuf
);
1293 /** Get a form on a printer.
1295 * @param cli Pointer to client state structure which is open
1296 * on the SPOOLSS pipe.
1297 * @param mem_ctx Pointer to an initialised talloc context.
1299 * @param handle Policy handle opened with cli_spoolss_open_printer_ex
1300 * or cli_spoolss_addprinterex.
1301 * @param formname Name of the form to get
1302 * @param level Form info level to get - should always be 1.
1306 WERROR
cli_spoolss_getform(struct cli_state
*cli
, TALLOC_CTX
*mem_ctx
,
1307 uint32 offered
, uint32
*needed
,
1308 POLICY_HND
*handle
, const char *formname
,
1309 uint32 level
, FORM_1
*form
)
1311 prs_struct qbuf
, rbuf
;
1314 WERROR result
= W_ERROR(ERRgeneral
);
1320 /* Initialise parse structures */
1322 init_buffer(&buffer
, offered
, mem_ctx
);
1324 prs_init(&qbuf
, MAX_PDU_FRAG_LEN
, mem_ctx
, MARSHALL
);
1325 prs_init(&rbuf
, 0, mem_ctx
, UNMARSHALL
);
1327 /* Initialise input parameters */
1329 make_spoolss_q_getform(&q
, handle
, formname
, level
, &buffer
, offered
);
1331 /* Marshall data and send request */
1333 if (!spoolss_io_q_getform("", &q
, &qbuf
, 0) ||
1334 !rpc_api_pipe_req(cli
, SPOOLSS_GETFORM
, &qbuf
, &rbuf
))
1337 /* Unmarshall response */
1339 if (!spoolss_io_r_getform("", &r
, &rbuf
, 0))
1342 /* Return output parameters */
1349 if (W_ERROR_IS_OK(result
)) {
1352 smb_io_form_1("", r
.buffer
, form
, 0);
1355 DEBUG(10, ("cli_spoolss_getform: unknown info level %d", level
));
1356 return WERR_UNKNOWN_LEVEL
;
1361 prs_mem_free(&qbuf
);
1362 prs_mem_free(&rbuf
);
1367 /** Delete a form on a printer.
1369 * @param cli Pointer to client state structure which is open
1370 * on the SPOOLSS pipe.
1371 * @param mem_ctx Pointer to an initialised talloc context.
1373 * @param handle Policy handle opened with cli_spoolss_open_printer_ex
1374 * or cli_spoolss_addprinterex.
1375 * @param form The name of the form to delete.
1379 WERROR
cli_spoolss_deleteform(struct cli_state
*cli
, TALLOC_CTX
*mem_ctx
,
1380 POLICY_HND
*handle
, const char *form_name
)
1382 prs_struct qbuf
, rbuf
;
1383 SPOOL_Q_DELETEFORM q
;
1384 SPOOL_R_DELETEFORM r
;
1385 WERROR result
= W_ERROR(ERRgeneral
);
1390 /* Initialise parse structures */
1392 prs_init(&qbuf
, MAX_PDU_FRAG_LEN
, mem_ctx
, MARSHALL
);
1393 prs_init(&rbuf
, 0, mem_ctx
, UNMARSHALL
);
1395 /* Initialise input parameters */
1397 make_spoolss_q_deleteform(&q
, handle
, form_name
);
1399 /* Marshall data and send request */
1401 if (!spoolss_io_q_deleteform("", &q
, &qbuf
, 0) ||
1402 !rpc_api_pipe_req(cli
, SPOOLSS_DELETEFORM
, &qbuf
, &rbuf
))
1405 /* Unmarshall response */
1407 if (!spoolss_io_r_deleteform("", &r
, &rbuf
, 0))
1410 /* Return output parameters */
1415 prs_mem_free(&qbuf
);
1416 prs_mem_free(&rbuf
);
1421 static void decode_forms_1(TALLOC_CTX
*mem_ctx
, NEW_BUFFER
*buffer
,
1422 uint32 num_forms
, FORM_1
**forms
)
1426 *forms
= (FORM_1
*)talloc(mem_ctx
, num_forms
* sizeof(FORM_1
));
1427 prs_set_offset(&buffer
->prs
,0);
1429 for (i
= 0; i
< num_forms
; i
++)
1430 smb_io_form_1("", buffer
, &((*forms
)[i
]), 0);
1435 * @param cli Pointer to client state structure which is open
1436 * on the SPOOLSS pipe.
1437 * @param mem_ctx Pointer to an initialised talloc context.
1439 * @param offered Buffer size offered in the request.
1440 * @param needed Number of bytes needed to complete the request.
1442 * or cli_spoolss_addprinterex.
1443 * @param level Form info level to get - should always be 1.
1444 * @param handle Open policy handle
1448 WERROR
cli_spoolss_enumforms(struct cli_state
*cli
, TALLOC_CTX
*mem_ctx
,
1449 uint32 offered
, uint32
*needed
,
1450 POLICY_HND
*handle
, int level
, uint32
*num_forms
,
1453 prs_struct qbuf
, rbuf
;
1454 SPOOL_Q_ENUMFORMS q
;
1455 SPOOL_R_ENUMFORMS r
;
1456 WERROR result
= W_ERROR(ERRgeneral
);
1462 /* Initialise parse structures */
1464 init_buffer(&buffer
, offered
, mem_ctx
);
1466 prs_init(&qbuf
, MAX_PDU_FRAG_LEN
, mem_ctx
, MARSHALL
);
1467 prs_init(&rbuf
, 0, mem_ctx
, UNMARSHALL
);
1469 /* Initialise input parameters */
1471 make_spoolss_q_enumforms(&q
, handle
, level
, &buffer
, offered
);
1473 /* Marshall data and send request */
1475 if (!spoolss_io_q_enumforms("", &q
, &qbuf
, 0) ||
1476 !rpc_api_pipe_req(cli
, SPOOLSS_ENUMFORMS
, &qbuf
, &rbuf
))
1479 /* Unmarshall response */
1481 if (!spoolss_io_r_enumforms("", &r
, &rbuf
, 0))
1484 /* Return output parameters */
1492 *num_forms
= r
.numofforms
;
1494 decode_forms_1(mem_ctx
, r
.buffer
, *num_forms
, forms
);
1497 prs_mem_free(&qbuf
);
1498 prs_mem_free(&rbuf
);
1503 static void decode_jobs_1(TALLOC_CTX
*mem_ctx
, NEW_BUFFER
*buffer
,
1504 uint32 num_jobs
, JOB_INFO_1
**jobs
)
1508 *jobs
= (JOB_INFO_1
*)talloc(mem_ctx
, num_jobs
* sizeof(JOB_INFO_1
));
1509 prs_set_offset(&buffer
->prs
,0);
1511 for (i
= 0; i
< num_jobs
; i
++)
1512 smb_io_job_info_1("", buffer
, &((*jobs
)[i
]), 0);
1515 static void decode_jobs_2(TALLOC_CTX
*mem_ctx
, NEW_BUFFER
*buffer
,
1516 uint32 num_jobs
, JOB_INFO_2
**jobs
)
1520 *jobs
= (JOB_INFO_2
*)talloc(mem_ctx
, num_jobs
* sizeof(JOB_INFO_2
));
1521 prs_set_offset(&buffer
->prs
,0);
1523 for (i
= 0; i
< num_jobs
; i
++)
1524 smb_io_job_info_2("", buffer
, &((*jobs
)[i
]), 0);
1527 /* Enumerate jobs */
1529 WERROR
cli_spoolss_enumjobs(struct cli_state
*cli
, TALLOC_CTX
*mem_ctx
,
1530 uint32 offered
, uint32
*needed
,
1531 POLICY_HND
*hnd
, uint32 level
, uint32 firstjob
,
1532 uint32 num_jobs
, uint32
*returned
, JOB_INFO_CTR
*ctr
)
1534 prs_struct qbuf
, rbuf
;
1537 WERROR result
= W_ERROR(ERRgeneral
);
1543 /* Initialise parse structures */
1545 init_buffer(&buffer
, offered
, mem_ctx
);
1547 prs_init(&qbuf
, MAX_PDU_FRAG_LEN
, mem_ctx
, MARSHALL
);
1548 prs_init(&rbuf
, 0, mem_ctx
, UNMARSHALL
);
1550 /* Initialise input parameters */
1552 make_spoolss_q_enumjobs(&q
, hnd
, firstjob
, num_jobs
, level
, &buffer
,
1555 /* Marshall data and send request */
1557 if (!spoolss_io_q_enumjobs("", &q
, &qbuf
, 0) ||
1558 !rpc_api_pipe_req(cli
, SPOOLSS_ENUMJOBS
, &qbuf
, &rbuf
))
1561 /* Unmarshall response */
1563 if (!spoolss_io_r_enumjobs("", &r
, &rbuf
, 0))
1566 /* Return output parameters */
1573 if (!W_ERROR_IS_OK(r
.status
))
1576 *returned
= r
.returned
;
1580 decode_jobs_1(mem_ctx
, r
.buffer
, r
.returned
,
1581 &ctr
->job
.job_info_1
);
1584 decode_jobs_2(mem_ctx
, r
.buffer
, r
.returned
,
1585 &ctr
->job
.job_info_2
);
1588 DEBUG(3, ("unsupported info level %d", level
));
1593 prs_mem_free(&qbuf
);
1594 prs_mem_free(&rbuf
);
1601 WERROR
cli_spoolss_setjob(struct cli_state
*cli
, TALLOC_CTX
*mem_ctx
,
1602 POLICY_HND
*hnd
, uint32 jobid
, uint32 level
,
1605 prs_struct qbuf
, rbuf
;
1608 WERROR result
= W_ERROR(ERRgeneral
);
1613 /* Initialise parse structures */
1615 prs_init(&qbuf
, MAX_PDU_FRAG_LEN
, mem_ctx
, MARSHALL
);
1616 prs_init(&rbuf
, 0, mem_ctx
, UNMARSHALL
);
1618 /* Initialise input parameters */
1620 make_spoolss_q_setjob(&q
, hnd
, jobid
, level
, command
);
1622 /* Marshall data and send request */
1624 if (!spoolss_io_q_setjob("", &q
, &qbuf
, 0) ||
1625 !rpc_api_pipe_req(cli
, SPOOLSS_SETJOB
, &qbuf
, &rbuf
))
1628 /* Unmarshall response */
1630 if (!spoolss_io_r_setjob("", &r
, &rbuf
, 0))
1633 /* Return output parameters */
1638 prs_mem_free(&qbuf
);
1639 prs_mem_free(&rbuf
);
1646 WERROR
cli_spoolss_getjob(struct cli_state
*cli
, TALLOC_CTX
*mem_ctx
,
1647 uint32 offered
, uint32
*needed
,
1648 POLICY_HND
*hnd
, uint32 jobid
, uint32 level
,
1651 prs_struct qbuf
, rbuf
;
1654 WERROR result
= W_ERROR(ERRgeneral
);
1660 /* Initialise parse structures */
1662 init_buffer(&buffer
, offered
, mem_ctx
);
1664 prs_init(&qbuf
, MAX_PDU_FRAG_LEN
, mem_ctx
, MARSHALL
);
1665 prs_init(&rbuf
, 0, mem_ctx
, UNMARSHALL
);
1667 /* Initialise input parameters */
1669 make_spoolss_q_getjob(&q
, hnd
, jobid
, level
, &buffer
, offered
);
1671 /* Marshall data and send request */
1673 if (!spoolss_io_q_getjob("", &q
, &qbuf
, 0) ||
1674 !rpc_api_pipe_req(cli
, SPOOLSS_GETJOB
, &qbuf
, &rbuf
))
1677 /* Unmarshall response */
1679 if (!spoolss_io_r_getjob("", &r
, &rbuf
, 0))
1682 /* Return output parameters */
1689 if (!W_ERROR_IS_OK(r
.status
))
1694 decode_jobs_1(mem_ctx
, r
.buffer
, 1, &ctr
->job
.job_info_1
);
1697 decode_jobs_2(mem_ctx
, r
.buffer
, 1, &ctr
->job
.job_info_2
);
1700 DEBUG(3, ("unsupported info level %d", level
));
1705 prs_mem_free(&qbuf
);
1706 prs_mem_free(&rbuf
);
1711 /* Startpageprinter. Sent to notify the spooler when a page is about to be
1712 sent to a printer. */
1714 WERROR
cli_spoolss_startpageprinter(struct cli_state
*cli
, TALLOC_CTX
*mem_ctx
,
1717 prs_struct qbuf
, rbuf
;
1718 SPOOL_Q_STARTPAGEPRINTER q
;
1719 SPOOL_R_STARTPAGEPRINTER r
;
1720 WERROR result
= W_ERROR(ERRgeneral
);
1725 /* Initialise parse structures */
1727 prs_init(&qbuf
, MAX_PDU_FRAG_LEN
, mem_ctx
, MARSHALL
);
1728 prs_init(&rbuf
, 0, mem_ctx
, UNMARSHALL
);
1730 /* Initialise input parameters */
1732 make_spoolss_q_startpageprinter(&q
, hnd
);
1734 /* Marshall data and send request */
1736 if (!spoolss_io_q_startpageprinter("", &q
, &qbuf
, 0) ||
1737 !rpc_api_pipe_req(cli
, SPOOLSS_STARTPAGEPRINTER
, &qbuf
, &rbuf
))
1740 /* Unmarshall response */
1742 if (!spoolss_io_r_startpageprinter("", &r
, &rbuf
, 0))
1745 /* Return output parameters */
1750 prs_mem_free(&qbuf
);
1751 prs_mem_free(&rbuf
);
1756 /* Endpageprinter. Sent to notify the spooler when a page has finished
1757 being sent to a printer. */
1759 WERROR
cli_spoolss_endpageprinter(struct cli_state
*cli
, TALLOC_CTX
*mem_ctx
,
1762 prs_struct qbuf
, rbuf
;
1763 SPOOL_Q_ENDPAGEPRINTER q
;
1764 SPOOL_R_ENDPAGEPRINTER r
;
1765 WERROR result
= W_ERROR(ERRgeneral
);
1770 /* Initialise parse structures */
1772 prs_init(&qbuf
, MAX_PDU_FRAG_LEN
, mem_ctx
, MARSHALL
);
1773 prs_init(&rbuf
, 0, mem_ctx
, UNMARSHALL
);
1775 /* Initialise input parameters */
1777 make_spoolss_q_endpageprinter(&q
, hnd
);
1779 /* Marshall data and send request */
1781 if (!spoolss_io_q_endpageprinter("", &q
, &qbuf
, 0) ||
1782 !rpc_api_pipe_req(cli
, SPOOLSS_ENDPAGEPRINTER
, &qbuf
, &rbuf
))
1785 /* Unmarshall response */
1787 if (!spoolss_io_r_endpageprinter("", &r
, &rbuf
, 0))
1790 /* Return output parameters */
1795 prs_mem_free(&qbuf
);
1796 prs_mem_free(&rbuf
);
1801 /* Startdocprinter. Sent to notify the spooler that a document is about
1802 to be spooled for printing. */
1804 WERROR
cli_spoolss_startdocprinter(struct cli_state
*cli
, TALLOC_CTX
*mem_ctx
,
1805 POLICY_HND
*hnd
, char *docname
,
1806 char *outputfile
, char *datatype
,
1809 prs_struct qbuf
, rbuf
;
1810 SPOOL_Q_STARTDOCPRINTER q
;
1811 SPOOL_R_STARTDOCPRINTER r
;
1812 WERROR result
= W_ERROR(ERRgeneral
);
1818 /* Initialise parse structures */
1820 prs_init(&qbuf
, MAX_PDU_FRAG_LEN
, mem_ctx
, MARSHALL
);
1821 prs_init(&rbuf
, 0, mem_ctx
, UNMARSHALL
);
1823 /* Initialise input parameters */
1825 make_spoolss_q_startdocprinter(&q
, hnd
, level
, docname
, outputfile
,
1828 /* Marshall data and send request */
1830 if (!spoolss_io_q_startdocprinter("", &q
, &qbuf
, 0) ||
1831 !rpc_api_pipe_req(cli
, SPOOLSS_STARTDOCPRINTER
, &qbuf
, &rbuf
))
1834 /* Unmarshall response */
1836 if (!spoolss_io_r_startdocprinter("", &r
, &rbuf
, 0))
1839 /* Return output parameters */
1843 if (W_ERROR_IS_OK(result
))
1847 prs_mem_free(&qbuf
);
1848 prs_mem_free(&rbuf
);
1853 /* Enddocprinter. Sent to notify the spooler that a document has finished
1856 WERROR
cli_spoolss_enddocprinter(struct cli_state
*cli
, TALLOC_CTX
*mem_ctx
,
1859 prs_struct qbuf
, rbuf
;
1860 SPOOL_Q_ENDDOCPRINTER q
;
1861 SPOOL_R_ENDDOCPRINTER r
;
1862 WERROR result
= W_ERROR(ERRgeneral
);
1867 /* Initialise parse structures */
1869 prs_init(&qbuf
, MAX_PDU_FRAG_LEN
, mem_ctx
, MARSHALL
);
1870 prs_init(&rbuf
, 0, mem_ctx
, UNMARSHALL
);
1872 /* Initialise input parameters */
1874 make_spoolss_q_enddocprinter(&q
, hnd
);
1876 /* Marshall data and send request */
1878 if (!spoolss_io_q_enddocprinter("", &q
, &qbuf
, 0) ||
1879 !rpc_api_pipe_req(cli
, SPOOLSS_ENDDOCPRINTER
, &qbuf
, &rbuf
))
1882 /* Unmarshall response */
1884 if (!spoolss_io_r_enddocprinter("", &r
, &rbuf
, 0))
1887 /* Return output parameters */
1892 prs_mem_free(&qbuf
);
1893 prs_mem_free(&rbuf
);
1898 /* Get printer data */
1900 WERROR
cli_spoolss_getprinterdata(struct cli_state
*cli
, TALLOC_CTX
*mem_ctx
,
1901 uint32 offered
, uint32
*needed
,
1902 POLICY_HND
*hnd
, const char *valuename
,
1903 REGISTRY_VALUE
*value
)
1905 prs_struct qbuf
, rbuf
;
1906 SPOOL_Q_GETPRINTERDATA q
;
1907 SPOOL_R_GETPRINTERDATA r
;
1908 WERROR result
= W_ERROR(ERRgeneral
);
1913 /* Initialise parse structures */
1915 prs_init(&qbuf
, MAX_PDU_FRAG_LEN
, mem_ctx
, MARSHALL
);
1916 prs_init(&rbuf
, 0, mem_ctx
, UNMARSHALL
);
1918 /* Initialise input parameters */
1920 make_spoolss_q_getprinterdata(&q
, hnd
, valuename
, offered
);
1922 /* Marshall data and send request */
1924 if (!spoolss_io_q_getprinterdata("", &q
, &qbuf
, 0) ||
1925 !rpc_api_pipe_req(cli
, SPOOLSS_GETPRINTERDATA
, &qbuf
, &rbuf
))
1928 /* Unmarshall response */
1930 if (!spoolss_io_r_getprinterdata("", &r
, &rbuf
, 0))
1938 if (!W_ERROR_IS_OK(r
.status
))
1941 /* Return output parameters */
1943 value
->data_p
= talloc_memdup(mem_ctx
, r
.data
, r
.needed
);
1944 value
->type
= r
.type
;
1945 value
->size
= r
.size
;
1948 prs_mem_free(&qbuf
);
1949 prs_mem_free(&rbuf
);
1954 WERROR
cli_spoolss_getprinterdataex(struct cli_state
*cli
, TALLOC_CTX
*mem_ctx
,
1955 uint32 offered
, uint32
*needed
,
1956 POLICY_HND
*hnd
, const char *keyname
,
1957 const char *valuename
,
1958 REGISTRY_VALUE
*value
)
1960 prs_struct qbuf
, rbuf
;
1961 SPOOL_Q_GETPRINTERDATAEX q
;
1962 SPOOL_R_GETPRINTERDATAEX r
;
1963 WERROR result
= W_ERROR(ERRgeneral
);
1968 /* Initialise parse structures */
1970 prs_init(&qbuf
, MAX_PDU_FRAG_LEN
, mem_ctx
, MARSHALL
);
1971 prs_init(&rbuf
, 0, mem_ctx
, UNMARSHALL
);
1973 /* Initialise input parameters */
1975 make_spoolss_q_getprinterdataex(&q
, hnd
, keyname
, valuename
, offered
);
1977 /* Marshall data and send request */
1979 if (!spoolss_io_q_getprinterdataex("", &q
, &qbuf
, 0) ||
1980 !rpc_api_pipe_req(cli
, SPOOLSS_GETPRINTERDATAEX
, &qbuf
, &rbuf
))
1983 /* Unmarshall response */
1985 if (!spoolss_io_r_getprinterdataex("", &r
, &rbuf
, 0))
1993 if (!W_ERROR_IS_OK(r
.status
))
1996 /* Return output parameters */
1998 value
->data_p
= talloc_memdup(mem_ctx
, r
.data
, r
.needed
);
1999 value
->type
= r
.type
;
2000 value
->size
= r
.needed
;
2003 prs_mem_free(&qbuf
);
2004 prs_mem_free(&rbuf
);
2009 /* Set printer data */
2011 WERROR
cli_spoolss_setprinterdata(struct cli_state
*cli
, TALLOC_CTX
*mem_ctx
,
2012 POLICY_HND
*hnd
, REGISTRY_VALUE
*value
)
2014 prs_struct qbuf
, rbuf
;
2015 SPOOL_Q_SETPRINTERDATA q
;
2016 SPOOL_R_SETPRINTERDATA r
;
2017 WERROR result
= W_ERROR(ERRgeneral
);
2022 /* Initialise parse structures */
2024 prs_init(&qbuf
, MAX_PDU_FRAG_LEN
, mem_ctx
, MARSHALL
);
2025 prs_init(&rbuf
, 0, mem_ctx
, UNMARSHALL
);
2027 /* Initialise input parameters */
2029 make_spoolss_q_setprinterdata(
2030 &q
, hnd
, value
->valuename
, value
->type
, (char *)value
->data_p
, value
->size
);
2032 /* Marshall data and send request */
2034 if (!spoolss_io_q_setprinterdata("", &q
, &qbuf
, 0) ||
2035 !rpc_api_pipe_req(cli
, SPOOLSS_SETPRINTERDATA
, &qbuf
, &rbuf
))
2038 /* Unmarshall response */
2040 if (!spoolss_io_r_setprinterdata("", &r
, &rbuf
, 0))
2045 if (!W_ERROR_IS_OK(r
.status
))
2049 prs_mem_free(&qbuf
);
2050 prs_mem_free(&rbuf
);
2055 WERROR
cli_spoolss_setprinterdataex(struct cli_state
*cli
, TALLOC_CTX
*mem_ctx
,
2056 POLICY_HND
*hnd
, char *keyname
,
2057 REGISTRY_VALUE
*value
)
2059 prs_struct qbuf
, rbuf
;
2060 SPOOL_Q_SETPRINTERDATAEX q
;
2061 SPOOL_R_SETPRINTERDATAEX r
;
2062 WERROR result
= W_ERROR(ERRgeneral
);
2067 /* Initialise parse structures */
2069 prs_init(&qbuf
, MAX_PDU_FRAG_LEN
, mem_ctx
, MARSHALL
);
2070 prs_init(&rbuf
, 0, mem_ctx
, UNMARSHALL
);
2072 /* Initialise input parameters */
2074 make_spoolss_q_setprinterdataex(
2075 &q
, hnd
, keyname
, value
->valuename
, value
->type
, (char *)value
->data_p
,
2078 /* Marshall data and send request */
2080 if (!spoolss_io_q_setprinterdataex("", &q
, &qbuf
, 0) ||
2081 !rpc_api_pipe_req(cli
, SPOOLSS_SETPRINTERDATAEX
, &qbuf
, &rbuf
))
2084 /* Unmarshall response */
2086 if (!spoolss_io_r_setprinterdataex("", &r
, &rbuf
, 0))
2091 if (!W_ERROR_IS_OK(r
.status
))
2095 prs_mem_free(&qbuf
);
2096 prs_mem_free(&rbuf
);
2101 /* Enum printer data */
2103 WERROR
cli_spoolss_enumprinterdata(struct cli_state
*cli
, TALLOC_CTX
*mem_ctx
,
2104 POLICY_HND
*hnd
, uint32 ndx
,
2105 uint32 value_offered
, uint32 data_offered
,
2106 uint32
*value_needed
, uint32
*data_needed
,
2107 REGISTRY_VALUE
*value
)
2109 prs_struct qbuf
, rbuf
;
2110 SPOOL_Q_ENUMPRINTERDATA q
;
2111 SPOOL_R_ENUMPRINTERDATA r
;
2112 WERROR result
= W_ERROR(ERRgeneral
);
2117 /* Initialise parse structures */
2119 prs_init(&qbuf
, MAX_PDU_FRAG_LEN
, mem_ctx
, MARSHALL
);
2120 prs_init(&rbuf
, 0, mem_ctx
, UNMARSHALL
);
2122 /* Initialise input parameters */
2124 make_spoolss_q_enumprinterdata(&q
, hnd
, ndx
, value_offered
, data_offered
);
2126 /* Marshall data and send request */
2128 if (!spoolss_io_q_enumprinterdata("", &q
, &qbuf
, 0) ||
2129 !rpc_api_pipe_req(cli
, SPOOLSS_ENUMPRINTERDATA
, &qbuf
, &rbuf
))
2132 /* Unmarshall response */
2134 if (!spoolss_io_r_enumprinterdata("", &r
, &rbuf
, 0))
2139 if (!W_ERROR_IS_OK(r
.status
))
2145 *value_needed
= r
.realvaluesize
;
2148 *data_needed
= r
.realdatasize
;
2151 rpcstr_pull(value
->valuename
, r
.value
, sizeof(value
->valuename
), -1,
2153 value
->data_p
= talloc_memdup(mem_ctx
, r
.data
, r
.realdatasize
);
2154 value
->type
= r
.type
;
2155 value
->size
= r
.realdatasize
;
2159 prs_mem_free(&qbuf
);
2160 prs_mem_free(&rbuf
);
2165 WERROR
cli_spoolss_enumprinterdataex(struct cli_state
*cli
, TALLOC_CTX
*mem_ctx
,
2166 uint32 offered
, uint32
*needed
,
2167 POLICY_HND
*hnd
, const char *keyname
,
2170 prs_struct qbuf
, rbuf
;
2171 SPOOL_Q_ENUMPRINTERDATAEX q
;
2172 SPOOL_R_ENUMPRINTERDATAEX r
;
2173 WERROR result
= W_ERROR(ERRgeneral
);
2179 /* Initialise parse structures */
2181 prs_init(&qbuf
, MAX_PDU_FRAG_LEN
, mem_ctx
, MARSHALL
);
2182 prs_init(&rbuf
, 0, mem_ctx
, UNMARSHALL
);
2184 /* Initialise input parameters */
2186 make_spoolss_q_enumprinterdataex(&q
, hnd
, keyname
, offered
);
2188 /* Marshall data and send request */
2190 if (!spoolss_io_q_enumprinterdataex("", &q
, &qbuf
, 0) ||
2191 !rpc_api_pipe_req(cli
, SPOOLSS_ENUMPRINTERDATAEX
, &qbuf
, &rbuf
))
2194 /* Unmarshall response */
2196 if (!spoolss_io_r_enumprinterdataex("", &r
, &rbuf
, 0))
2204 if (!W_ERROR_IS_OK(r
.status
))
2210 regval_ctr_init(ctr
);
2212 for (i
= 0; i
< r
.returned
; i
++) {
2213 PRINTER_ENUM_VALUES
*v
= &r
.ctr
.values
[i
];
2216 rpcstr_pull(name
, v
->valuename
.buffer
, sizeof(name
), -1,
2218 regval_ctr_addvalue(ctr
, name
, v
->type
, (const char *)v
->data
, v
->data_len
);
2222 prs_mem_free(&qbuf
);
2223 prs_mem_free(&rbuf
);
2228 /* Write data to printer */
2230 WERROR
cli_spoolss_writeprinter(struct cli_state
*cli
, TALLOC_CTX
*mem_ctx
,
2231 POLICY_HND
*hnd
, uint32 data_size
, char *data
,
2232 uint32
*num_written
)
2234 prs_struct qbuf
, rbuf
;
2235 SPOOL_Q_WRITEPRINTER q
;
2236 SPOOL_R_WRITEPRINTER r
;
2237 WERROR result
= W_ERROR(ERRgeneral
);
2242 /* Initialise parse structures */
2244 prs_init(&qbuf
, MAX_PDU_FRAG_LEN
, mem_ctx
, MARSHALL
);
2245 prs_init(&rbuf
, 0, mem_ctx
, UNMARSHALL
);
2247 /* Initialise input parameters */
2249 make_spoolss_q_writeprinter(&q
, hnd
, data_size
, data
);
2251 /* Marshall data and send request */
2253 if (!spoolss_io_q_writeprinter("", &q
, &qbuf
, 0) ||
2254 !rpc_api_pipe_req(cli
, SPOOLSS_WRITEPRINTER
, &qbuf
, &rbuf
))
2257 /* Unmarshall response */
2259 if (!spoolss_io_r_writeprinter("", &r
, &rbuf
, 0))
2264 if (!W_ERROR_IS_OK(r
.status
))
2268 *num_written
= r
.buffer_written
;
2271 prs_mem_free(&qbuf
);
2272 prs_mem_free(&rbuf
);
2277 /* Delete printer data */
2279 WERROR
cli_spoolss_deleteprinterdata(struct cli_state
*cli
, TALLOC_CTX
*mem_ctx
,
2280 POLICY_HND
*hnd
, char *valuename
)
2282 prs_struct qbuf
, rbuf
;
2283 SPOOL_Q_DELETEPRINTERDATA q
;
2284 SPOOL_R_DELETEPRINTERDATA r
;
2285 WERROR result
= W_ERROR(ERRgeneral
);
2290 /* Initialise parse structures */
2292 prs_init(&qbuf
, MAX_PDU_FRAG_LEN
, mem_ctx
, MARSHALL
);
2293 prs_init(&rbuf
, 0, mem_ctx
, UNMARSHALL
);
2295 /* Initialise input parameters */
2297 make_spoolss_q_deleteprinterdata(&q
, hnd
, valuename
);
2299 /* Marshall data and send request */
2301 if (!spoolss_io_q_deleteprinterdata("", &q
, &qbuf
, 0) ||
2302 !rpc_api_pipe_req(cli
, SPOOLSS_DELETEPRINTERDATA
, &qbuf
, &rbuf
))
2305 /* Unmarshall response */
2307 if (!spoolss_io_r_deleteprinterdata("", &r
, &rbuf
, 0))
2312 if (!W_ERROR_IS_OK(r
.status
))
2316 prs_mem_free(&qbuf
);
2317 prs_mem_free(&rbuf
);
2322 WERROR
cli_spoolss_deleteprinterdataex(struct cli_state
*cli
, TALLOC_CTX
*mem_ctx
,
2323 POLICY_HND
*hnd
, char *keyname
,
2326 prs_struct qbuf
, rbuf
;
2327 SPOOL_Q_DELETEPRINTERDATAEX q
;
2328 SPOOL_R_DELETEPRINTERDATAEX r
;
2329 WERROR result
= W_ERROR(ERRgeneral
);
2334 /* Initialise parse structures */
2336 prs_init(&qbuf
, MAX_PDU_FRAG_LEN
, mem_ctx
, MARSHALL
);
2337 prs_init(&rbuf
, 0, mem_ctx
, UNMARSHALL
);
2339 /* Initialise input parameters */
2341 make_spoolss_q_deleteprinterdataex(&q
, hnd
, keyname
, valuename
);
2343 /* Marshall data and send request */
2345 if (!spoolss_io_q_deleteprinterdataex("", &q
, &qbuf
, 0) ||
2346 !rpc_api_pipe_req(cli
, SPOOLSS_DELETEPRINTERDATAEX
, &qbuf
, &rbuf
))
2349 /* Unmarshall response */
2351 if (!spoolss_io_r_deleteprinterdataex("", &r
, &rbuf
, 0))
2356 if (!W_ERROR_IS_OK(r
.status
))
2360 prs_mem_free(&qbuf
);
2361 prs_mem_free(&rbuf
);
2366 WERROR
cli_spoolss_enumprinterkey(struct cli_state
*cli
, TALLOC_CTX
*mem_ctx
,
2367 uint32 offered
, uint32
*needed
,
2368 POLICY_HND
*hnd
, const char *keyname
,
2369 uint16
**keylist
, uint32
*len
)
2371 prs_struct qbuf
, rbuf
;
2372 SPOOL_Q_ENUMPRINTERKEY q
;
2373 SPOOL_R_ENUMPRINTERKEY r
;
2374 WERROR result
= W_ERROR(ERRgeneral
);
2379 /* Initialise parse structures */
2381 prs_init(&qbuf
, MAX_PDU_FRAG_LEN
, mem_ctx
, MARSHALL
);
2382 prs_init(&rbuf
, 0, mem_ctx
, UNMARSHALL
);
2384 /* Initialise input parameters */
2386 make_spoolss_q_enumprinterkey(&q
, hnd
, keyname
, offered
);
2388 /* Marshall data and send request */
2390 if (!spoolss_io_q_enumprinterkey("", &q
, &qbuf
, 0) ||
2391 !rpc_api_pipe_req(cli
, SPOOLSS_ENUMPRINTERKEY
, &qbuf
, &rbuf
))
2394 /* Unmarshall response */
2396 if (!spoolss_io_r_enumprinterkey("", &r
, &rbuf
, 0))
2404 if (!W_ERROR_IS_OK(r
.status
))
2410 *keylist
= (uint16
*)malloc(r
.keys
.buf_len
* 2);
2411 memcpy(*keylist
, r
.keys
.buffer
, r
.keys
.buf_len
* 2);
2413 *len
= r
.keys
.buf_len
* 2;
2417 prs_mem_free(&qbuf
);
2418 prs_mem_free(&rbuf
);
2423 WERROR
cli_spoolss_deleteprinterkey(struct cli_state
*cli
, TALLOC_CTX
*mem_ctx
,
2424 POLICY_HND
*hnd
, char *keyname
)
2426 prs_struct qbuf
, rbuf
;
2427 SPOOL_Q_DELETEPRINTERKEY q
;
2428 SPOOL_R_DELETEPRINTERKEY r
;
2429 WERROR result
= W_ERROR(ERRgeneral
);
2434 /* Initialise parse structures */
2436 prs_init(&qbuf
, MAX_PDU_FRAG_LEN
, mem_ctx
, MARSHALL
);
2437 prs_init(&rbuf
, 0, mem_ctx
, UNMARSHALL
);
2439 /* Initialise input parameters */
2441 make_spoolss_q_deleteprinterkey(&q
, hnd
, keyname
);
2443 /* Marshall data and send request */
2445 if (!spoolss_io_q_deleteprinterkey("", &q
, &qbuf
, 0) ||
2446 !rpc_api_pipe_req(cli
, SPOOLSS_DELETEPRINTERKEY
, &qbuf
, &rbuf
))
2449 /* Unmarshall response */
2451 if (!spoolss_io_r_deleteprinterkey("", &r
, &rbuf
, 0))
2456 if (!W_ERROR_IS_OK(r
.status
))
2460 prs_mem_free(&qbuf
);
2461 prs_mem_free(&rbuf
);