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 Decode various spoolss rpc's and info levels
36 ********************************************************************/
38 /**********************************************************************
39 **********************************************************************/
40 static void decode_printer_info_0(TALLOC_CTX *mem_ctx, RPC_BUFFER *buffer,
41 uint32 returned, PRINTER_INFO_0 **info)
46 inf=TALLOC_ARRAY(mem_ctx, PRINTER_INFO_0, returned);
47 memset(inf, 0, returned*sizeof(PRINTER_INFO_0));
49 prs_set_offset(&buffer->prs,0);
51 for (i=0; i<returned; i++) {
52 smb_io_printer_info_0("", buffer, &inf[i], 0);
58 /**********************************************************************
59 **********************************************************************/
60 static void decode_printer_info_1(TALLOC_CTX *mem_ctx, RPC_BUFFER *buffer,
61 uint32 returned, PRINTER_INFO_1 **info)
66 inf=TALLOC_ARRAY(mem_ctx, PRINTER_INFO_1, returned);
67 memset(inf, 0, returned*sizeof(PRINTER_INFO_1));
69 prs_set_offset(&buffer->prs,0);
71 for (i=0; i<returned; i++) {
72 smb_io_printer_info_1("", buffer, &inf[i], 0);
78 /**********************************************************************
79 **********************************************************************/
80 static void decode_printer_info_2(TALLOC_CTX *mem_ctx, RPC_BUFFER *buffer,
81 uint32 returned, PRINTER_INFO_2 **info)
86 inf=TALLOC_ARRAY(mem_ctx, PRINTER_INFO_2, returned);
87 memset(inf, 0, returned*sizeof(PRINTER_INFO_2));
89 prs_set_offset(&buffer->prs,0);
91 for (i=0; i<returned; i++) {
92 /* a little initialization as we go */
93 inf[i].secdesc = NULL;
94 smb_io_printer_info_2("", buffer, &inf[i], 0);
100 /**********************************************************************
101 **********************************************************************/
102 static void decode_printer_info_3(TALLOC_CTX *mem_ctx, RPC_BUFFER *buffer,
103 uint32 returned, PRINTER_INFO_3 **info)
108 inf=TALLOC_ARRAY(mem_ctx, PRINTER_INFO_3, returned);
109 memset(inf, 0, returned*sizeof(PRINTER_INFO_3));
111 prs_set_offset(&buffer->prs,0);
113 for (i=0; i<returned; i++) {
114 inf[i].secdesc = NULL;
115 smb_io_printer_info_3("", buffer, &inf[i], 0);
121 /**********************************************************************
122 **********************************************************************/
123 static void decode_printer_info_7(TALLOC_CTX *mem_ctx, RPC_BUFFER *buffer,
124 uint32 returned, PRINTER_INFO_7 **info)
129 inf=TALLOC_ARRAY(mem_ctx, PRINTER_INFO_7, returned);
130 memset(inf, 0, returned*sizeof(PRINTER_INFO_7));
132 prs_set_offset(&buffer->prs,0);
134 for (i=0; i<returned; i++) {
135 smb_io_printer_info_7("", buffer, &inf[i], 0);
142 /**********************************************************************
143 **********************************************************************/
144 static void decode_port_info_1(TALLOC_CTX *mem_ctx, RPC_BUFFER *buffer,
145 uint32 returned, PORT_INFO_1 **info)
150 inf=TALLOC_ARRAY(mem_ctx, PORT_INFO_1, returned);
151 memset(inf, 0, returned*sizeof(PORT_INFO_1));
153 prs_set_offset(&buffer->prs, 0);
155 for (i=0; i<returned; i++) {
156 smb_io_port_info_1("", buffer, &(inf[i]), 0);
162 /**********************************************************************
163 **********************************************************************/
164 static void decode_port_info_2(TALLOC_CTX *mem_ctx, RPC_BUFFER *buffer,
165 uint32 returned, PORT_INFO_2 **info)
170 inf=TALLOC_ARRAY(mem_ctx, PORT_INFO_2, returned);
171 memset(inf, 0, returned*sizeof(PORT_INFO_2));
173 prs_set_offset(&buffer->prs, 0);
175 for (i=0; i<returned; i++) {
176 smb_io_port_info_2("", buffer, &(inf[i]), 0);
182 /**********************************************************************
183 **********************************************************************/
184 static void decode_printer_driver_1(TALLOC_CTX *mem_ctx, RPC_BUFFER *buffer,
185 uint32 returned, DRIVER_INFO_1 **info)
190 inf=TALLOC_ARRAY(mem_ctx, DRIVER_INFO_1, returned);
191 memset(inf, 0, returned*sizeof(DRIVER_INFO_1));
193 prs_set_offset(&buffer->prs,0);
195 for (i=0; i<returned; i++) {
196 smb_io_printer_driver_info_1("", buffer, &(inf[i]), 0);
202 /**********************************************************************
203 **********************************************************************/
204 static void decode_printer_driver_2(TALLOC_CTX *mem_ctx, RPC_BUFFER *buffer,
205 uint32 returned, DRIVER_INFO_2 **info)
210 inf=TALLOC_ARRAY(mem_ctx, DRIVER_INFO_2, returned);
211 memset(inf, 0, returned*sizeof(DRIVER_INFO_2));
213 prs_set_offset(&buffer->prs,0);
215 for (i=0; i<returned; i++) {
216 smb_io_printer_driver_info_2("", buffer, &(inf[i]), 0);
222 /**********************************************************************
223 **********************************************************************/
224 static void decode_printer_driver_3(TALLOC_CTX *mem_ctx, RPC_BUFFER *buffer,
225 uint32 returned, DRIVER_INFO_3 **info)
230 inf=TALLOC_ARRAY(mem_ctx, DRIVER_INFO_3, returned);
231 memset(inf, 0, returned*sizeof(DRIVER_INFO_3));
233 prs_set_offset(&buffer->prs,0);
235 for (i=0; i<returned; i++) {
236 smb_io_printer_driver_info_3("", buffer, &(inf[i]), 0);
242 /**********************************************************************
243 **********************************************************************/
244 static void decode_printerdriverdir_1 (TALLOC_CTX *mem_ctx, RPC_BUFFER *buffer,
245 uint32 returned, DRIVER_DIRECTORY_1 **info
248 DRIVER_DIRECTORY_1 *inf;
250 inf=TALLOC_P(mem_ctx, DRIVER_DIRECTORY_1);
251 memset(inf, 0, sizeof(DRIVER_DIRECTORY_1));
253 prs_set_offset(&buffer->prs, 0);
255 smb_io_driverdir_1("", buffer, inf, 0);
260 /** Return a handle to the specified printer or print server.
262 * @param cli Pointer to client state structure which is open
263 * on the SPOOLSS pipe.
265 * @param mem_ctx Pointer to an initialised talloc context.
267 * @param printername The name of the printer or print server to be
268 * opened in UNC format.
270 * @param datatype Specifies the default data type for the printer.
272 * @param access_required The access rights requested on the printer or
275 * @param station The UNC name of the requesting workstation.
277 * @param username The name of the user requesting the open.
279 * @param pol Returned policy handle.
282 /*********************************************************************************
283 Win32 API - OpenPrinter()
284 ********************************************************************************/
286 WERROR cli_spoolss_open_printer_ex(struct cli_state *cli, TALLOC_CTX *mem_ctx,
287 const char *printername, const char *datatype, uint32 access_required,
288 const char *station, const char *username, POLICY_HND *pol)
290 prs_struct qbuf, rbuf;
291 SPOOL_Q_OPEN_PRINTER_EX q;
292 SPOOL_R_OPEN_PRINTER_EX r;
293 WERROR result = W_ERROR(ERRgeneral);
298 /* Initialise parse structures */
300 prs_init(&qbuf, MAX_PDU_FRAG_LEN, mem_ctx, MARSHALL);
301 prs_init(&rbuf, 0, mem_ctx, UNMARSHALL);
303 /* Initialise input parameters */
305 make_spoolss_q_open_printer_ex(&q, printername, datatype,
306 access_required, station, username);
308 /* Marshall data and send request */
310 if (!spoolss_io_q_open_printer_ex("", &q, &qbuf, 0) ||
311 !rpc_api_pipe_req(cli, PI_SPOOLSS, SPOOLSS_OPENPRINTEREX, &qbuf, &rbuf))
314 /* Unmarshall response */
316 if (!spoolss_io_r_open_printer_ex("", &r, &rbuf, 0))
319 /* Return output parameters */
323 if (W_ERROR_IS_OK(result))
333 /** Close a printer handle
335 * @param cli Pointer to client state structure which is open
336 * on the SPOOLSS pipe.
338 * @param mem_ctx Pointer to an initialised talloc context.
340 * @param pol Policy handle of printer or print server to close.
342 /*********************************************************************************
343 Win32 API - ClosePrinter()
344 ********************************************************************************/
346 WERROR cli_spoolss_close_printer(struct cli_state *cli, TALLOC_CTX *mem_ctx,
349 prs_struct qbuf, rbuf;
350 SPOOL_Q_CLOSEPRINTER q;
351 SPOOL_R_CLOSEPRINTER r;
352 WERROR result = W_ERROR(ERRgeneral);
357 /* Initialise parse structures */
359 prs_init(&qbuf, MAX_PDU_FRAG_LEN, mem_ctx, MARSHALL);
360 prs_init(&rbuf, 0, mem_ctx, UNMARSHALL);
362 /* Initialise input parameters */
364 make_spoolss_q_closeprinter(&q, pol);
366 /* Marshall data and send request */
368 if (!spoolss_io_q_closeprinter("", &q, &qbuf, 0) ||
369 !rpc_api_pipe_req(cli, PI_SPOOLSS, SPOOLSS_CLOSEPRINTER, &qbuf, &rbuf))
372 /* Unmarshall response */
374 if (!spoolss_io_r_closeprinter("", &r, &rbuf, 0))
377 /* Return output parameters */
381 if (W_ERROR_IS_OK(result))
391 /** Enumerate printers on a print server.
393 * @param cli Pointer to client state structure which is open
394 * on the SPOOLSS pipe.
395 * @param mem_ctx Pointer to an initialised talloc context.
397 * @param offered Buffer size offered in the request.
398 * @param needed Number of bytes needed to complete the request.
401 * @param flags Selected from PRINTER_ENUM_* flags.
402 * @param level Request information level.
404 * @param num_printers Pointer to number of printers returned. May be
406 * @param ctr Return structure for printer information. May
409 /*********************************************************************************
410 Win32 API - EnumPrinters()
411 ********************************************************************************/
413 WERROR cli_spoolss_enum_printers(struct cli_state *cli, TALLOC_CTX *mem_ctx,
414 uint32 offered, uint32 *needed,
415 char *name, uint32 flags, uint32 level,
416 uint32 *num_printers, PRINTER_INFO_CTR *ctr)
418 prs_struct qbuf, rbuf;
419 SPOOL_Q_ENUMPRINTERS q;
420 SPOOL_R_ENUMPRINTERS r;
422 WERROR result = W_ERROR(ERRgeneral);
427 /* Initialise input parameters */
429 rpcbuf_init(&buffer, offered, mem_ctx);
431 prs_init(&qbuf, MAX_PDU_FRAG_LEN, mem_ctx, MARSHALL);
432 prs_init(&rbuf, 0, mem_ctx, UNMARSHALL);
434 make_spoolss_q_enumprinters(&q, flags, name, level, &buffer,
437 /* Marshall data and send request */
439 if (!spoolss_io_q_enumprinters("", &q, &qbuf, 0) ||
440 !rpc_api_pipe_req(cli, PI_SPOOLSS, SPOOLSS_ENUMPRINTERS, &qbuf, &rbuf))
443 /* Unmarshall response */
445 if (spoolss_io_r_enumprinters("", &r, &rbuf, 0)) {
452 /* Return output parameters */
454 if (!W_ERROR_IS_OK(r.status))
458 *num_printers = r.returned;
465 decode_printer_info_0(mem_ctx, r.buffer, r.returned,
469 decode_printer_info_1(mem_ctx, r.buffer, r.returned,
473 decode_printer_info_2(mem_ctx, r.buffer, r.returned,
477 decode_printer_info_3(mem_ctx, r.buffer, r.returned,
489 /*********************************************************************************
490 Win32 API - EnumPorts()
491 ********************************************************************************/
492 /** Enumerate printer ports on a print server.
494 * @param cli Pointer to client state structure which is open
495 * on the SPOOLSS pipe.
496 * @param mem_ctx Pointer to an initialised talloc context.
498 * @param offered Buffer size offered in the request.
499 * @param needed Number of bytes needed to complete the request.
502 * @param level Requested information level.
504 * @param num_ports Pointer to number of ports returned. May be NULL.
505 * @param ctr Pointer to structure holding port information.
509 WERROR cli_spoolss_enum_ports(struct cli_state *cli, TALLOC_CTX *mem_ctx,
510 uint32 offered, uint32 *needed,
511 uint32 level, uint32 *num_ports, PORT_INFO_CTR *ctr)
513 prs_struct qbuf, rbuf;
517 WERROR result = W_ERROR(ERRgeneral);
523 slprintf(server, sizeof(fstring)-1, "\\\\%s", cli->desthost);
526 /* Initialise input parameters */
528 rpcbuf_init(&buffer, offered, mem_ctx);
530 prs_init(&qbuf, MAX_PDU_FRAG_LEN, mem_ctx, MARSHALL);
531 prs_init(&rbuf, 0, mem_ctx, UNMARSHALL);
533 make_spoolss_q_enumports(&q, server, level, &buffer, offered);
535 /* Marshall data and send request */
537 if (!spoolss_io_q_enumports("", &q, &qbuf, 0) ||
538 !rpc_api_pipe_req(cli, PI_SPOOLSS, SPOOLSS_ENUMPORTS, &qbuf, &rbuf))
541 /* Unmarshall response */
543 if (spoolss_io_r_enumports("", &r, &rbuf, 0)) {
550 /* Return output parameters */
552 if (!W_ERROR_IS_OK(result))
556 *num_ports = r.returned;
563 decode_port_info_1(mem_ctx, r.buffer, r.returned,
567 decode_port_info_2(mem_ctx, r.buffer, r.returned,
579 /*********************************************************************************
580 Win32 API - GetPrinter()
581 ********************************************************************************/
583 WERROR cli_spoolss_getprinter(struct cli_state *cli, TALLOC_CTX *mem_ctx,
584 uint32 offered, uint32 *needed,
585 POLICY_HND *pol, uint32 level,
586 PRINTER_INFO_CTR *ctr)
588 prs_struct qbuf, rbuf;
589 SPOOL_Q_GETPRINTER q;
590 SPOOL_R_GETPRINTER r;
592 WERROR result = W_ERROR(ERRgeneral);
597 /* Initialise input parameters */
599 rpcbuf_init(&buffer, offered, mem_ctx);
601 prs_init(&qbuf, MAX_PDU_FRAG_LEN, mem_ctx, MARSHALL);
602 prs_init(&rbuf, 0, mem_ctx, UNMARSHALL);
604 make_spoolss_q_getprinter(mem_ctx, &q, pol, level, &buffer, offered);
606 /* Marshall data and send request */
608 if (!spoolss_io_q_getprinter("", &q, &qbuf, 0) ||
609 !rpc_api_pipe_req(cli, PI_SPOOLSS, SPOOLSS_GETPRINTER, &qbuf, &rbuf))
612 /* Unmarshall response */
614 if (!spoolss_io_r_getprinter("", &r, &rbuf, 0))
620 /* Return output parameters */
624 if (W_ERROR_IS_OK(result)) {
627 decode_printer_info_0(mem_ctx, r.buffer, 1, &ctr->printers_0);
630 decode_printer_info_1(mem_ctx, r.buffer, 1, &ctr->printers_1);
633 decode_printer_info_2(mem_ctx, r.buffer, 1, &ctr->printers_2);
636 decode_printer_info_3(mem_ctx, r.buffer, 1, &ctr->printers_3);
639 decode_printer_info_7(mem_ctx, r.buffer, 1, &ctr->printers_7);
651 /*********************************************************************************
652 Win32 API - SetPrinter()
653 ********************************************************************************/
656 * @param cli Pointer to client state structure which is open
657 * on the SPOOLSS pipe.
658 * @param mem_ctx Pointer to an initialised talloc context.
660 * @param pol Policy handle on printer to set info.
661 * @param level Information level to set.
662 * @param ctr Pointer to structure holding printer information.
663 * @param command Specifies the action performed. See
664 * http://msdn.microsoft.com/library/default.asp?url=/library/en-us/gdi/prntspol_13ua.asp
669 WERROR cli_spoolss_setprinter(struct cli_state *cli, TALLOC_CTX *mem_ctx,
670 POLICY_HND *pol, uint32 level,
671 PRINTER_INFO_CTR *ctr, uint32 command)
673 prs_struct qbuf, rbuf;
674 SPOOL_Q_SETPRINTER q;
675 SPOOL_R_SETPRINTER r;
676 WERROR result = W_ERROR(ERRgeneral);
681 /* Initialise input parameters */
683 prs_init(&qbuf, MAX_PDU_FRAG_LEN, mem_ctx, MARSHALL);
684 prs_init(&rbuf, 0, mem_ctx, UNMARSHALL);
686 if (!make_spoolss_q_setprinter(mem_ctx, &q, pol, level, ctr, command))
689 /* Marshall data and send request */
691 if (!spoolss_io_q_setprinter("", &q, &qbuf, 0) ||
692 !rpc_api_pipe_req(cli, PI_SPOOLSS, SPOOLSS_SETPRINTER, &qbuf, &rbuf))
695 /* Unmarshall response */
697 if (!spoolss_io_r_setprinter("", &r, &rbuf, 0))
709 /*********************************************************************************
710 Win32 API - GetPrinterDriver()
711 ********************************************************************************/
712 /** Get installed printer drivers for a given printer
714 * @param cli Pointer to client state structure which is open
715 * on the SPOOLSS pipe.
717 * @param mem_ctx Pointer to an initialised talloc context.
719 * @param offered Buffer size offered in the request.
720 * @param needed Number of bytes needed to complete the request.
723 * @param pol Pointer to an open policy handle for the printer
724 * opened with cli_spoolss_open_printer_ex().
725 * @param level Requested information level.
726 * @param env The print environment or archictecture. This is
727 * "Windows NT x86" for NT4.
728 * @param ctr Returned printer driver information.
731 WERROR cli_spoolss_getprinterdriver(struct cli_state *cli,
733 uint32 offered, uint32 *needed,
734 POLICY_HND *pol, uint32 level,
735 const char *env, int version, PRINTER_DRIVER_CTR *ctr)
737 prs_struct qbuf, rbuf;
738 SPOOL_Q_GETPRINTERDRIVER2 q;
739 SPOOL_R_GETPRINTERDRIVER2 r;
741 WERROR result = W_ERROR(ERRgeneral);
747 fstrcpy(server, cli->desthost);
750 /* Initialise input parameters */
752 rpcbuf_init(&buffer, offered, mem_ctx);
754 prs_init(&qbuf, MAX_PDU_FRAG_LEN, mem_ctx, MARSHALL);
755 prs_init(&rbuf, 0, mem_ctx, UNMARSHALL);
757 make_spoolss_q_getprinterdriver2(&q, pol, env, level, version, 2,
760 /* Marshall data and send request */
762 if (!spoolss_io_q_getprinterdriver2 ("", &q, &qbuf, 0) ||
763 !rpc_api_pipe_req (cli, PI_SPOOLSS, SPOOLSS_GETPRINTERDRIVER2, &qbuf, &rbuf))
766 /* Unmarshall response */
768 if (spoolss_io_r_getprinterdriver2 ("", &r, &rbuf, 0)) {
775 /* Return output parameters */
777 if (!W_ERROR_IS_OK(result))
785 decode_printer_driver_1(mem_ctx, r.buffer, 1, &ctr->info1);
788 decode_printer_driver_2(mem_ctx, r.buffer, 1, &ctr->info2);
791 decode_printer_driver_3(mem_ctx, r.buffer, 1, &ctr->info3);
794 DEBUG(10, ("cli_spoolss_getprinterdriver: unknown info level %d", level));
795 return WERR_UNKNOWN_LEVEL;
805 /*********************************************************************************
806 Win32 API - EnumPrinterDrivers()
807 ********************************************************************************/
808 /**********************************************************************
809 * Get installed printer drivers for a given printer
811 WERROR cli_spoolss_enumprinterdrivers (struct cli_state *cli,
813 uint32 offered, uint32 *needed,
814 uint32 level, const char *env,
816 PRINTER_DRIVER_CTR *ctr)
818 prs_struct qbuf, rbuf;
819 SPOOL_Q_ENUMPRINTERDRIVERS q;
820 SPOOL_R_ENUMPRINTERDRIVERS r;
822 WERROR result = W_ERROR(ERRgeneral);
828 slprintf(server, sizeof(fstring)-1, "\\\\%s", cli->desthost);
831 /* Initialise input parameters */
833 rpcbuf_init(&buffer, offered, mem_ctx);
835 prs_init(&qbuf, MAX_PDU_FRAG_LEN, mem_ctx, MARSHALL);
836 prs_init(&rbuf, 0, mem_ctx, UNMARSHALL);
838 /* Write the request */
840 make_spoolss_q_enumprinterdrivers(&q, server, env, level, &buffer,
843 /* Marshall data and send request */
845 if (!spoolss_io_q_enumprinterdrivers ("", &q, &qbuf, 0) ||
846 !rpc_api_pipe_req (cli, PI_SPOOLSS, SPOOLSS_ENUMPRINTERDRIVERS, &qbuf, &rbuf))
849 /* Unmarshall response */
851 if (!spoolss_io_r_enumprinterdrivers ("", &r, &rbuf, 0))
858 *num_drivers = r.returned;
862 /* Return output parameters */
864 if (W_ERROR_IS_OK(result) && (r.returned != 0)) {
865 *num_drivers = r.returned;
869 decode_printer_driver_1(mem_ctx, r.buffer, r.returned, &ctr->info1);
872 decode_printer_driver_2(mem_ctx, r.buffer, r.returned, &ctr->info2);
875 decode_printer_driver_3(mem_ctx, r.buffer, r.returned, &ctr->info3);
878 DEBUG(10, ("cli_spoolss_enumprinterdrivers: unknown info level %d\n",
880 return WERR_UNKNOWN_LEVEL;
892 /*********************************************************************************
893 Win32 API - GetPrinterDriverDirectory()
894 ********************************************************************************/
895 /**********************************************************************
896 * Get installed printer drivers for a given printer
898 WERROR cli_spoolss_getprinterdriverdir (struct cli_state *cli,
900 uint32 offered, uint32 *needed,
901 uint32 level, char *env,
902 DRIVER_DIRECTORY_CTR *ctr)
904 prs_struct qbuf, rbuf;
905 SPOOL_Q_GETPRINTERDRIVERDIR q;
906 SPOOL_R_GETPRINTERDRIVERDIR r;
908 WERROR result = W_ERROR(ERRgeneral);
914 slprintf(server, sizeof(fstring)-1, "\\\\%s", cli->desthost);
917 /* Initialise input parameters */
919 rpcbuf_init(&buffer, offered, mem_ctx);
921 prs_init(&qbuf, MAX_PDU_FRAG_LEN, mem_ctx, MARSHALL);
922 prs_init(&rbuf, 0, mem_ctx, UNMARSHALL);
924 /* Write the request */
926 make_spoolss_q_getprinterdriverdir(&q, server, env, level, &buffer,
929 /* Marshall data and send request */
931 if (!spoolss_io_q_getprinterdriverdir ("", &q, &qbuf, 0) ||
932 !rpc_api_pipe_req (cli, PI_SPOOLSS, SPOOLSS_GETPRINTERDRIVERDIRECTORY,
936 /* Unmarshall response */
938 if (spoolss_io_r_getprinterdriverdir ("", &r, &rbuf, 0)) {
943 /* Return output parameters */
947 if (W_ERROR_IS_OK(result)) {
950 decode_printerdriverdir_1(mem_ctx, r.buffer, 1,
963 /*********************************************************************************
964 Win32 API - AddPrinterDriver()
965 ********************************************************************************/
966 /**********************************************************************
967 * Install a printer driver
969 WERROR cli_spoolss_addprinterdriver (struct cli_state *cli,
970 TALLOC_CTX *mem_ctx, uint32 level,
971 PRINTER_DRIVER_CTR *ctr)
973 prs_struct qbuf, rbuf;
974 SPOOL_Q_ADDPRINTERDRIVER q;
975 SPOOL_R_ADDPRINTERDRIVER r;
976 WERROR result = W_ERROR(ERRgeneral);
982 slprintf(server, sizeof(fstring)-1, "\\\\%s", cli->desthost);
985 /* Initialise input parameters */
987 prs_init(&qbuf, MAX_PDU_FRAG_LEN, mem_ctx, MARSHALL);
988 prs_init(&rbuf, 0, mem_ctx, UNMARSHALL);
990 /* Write the request */
992 make_spoolss_q_addprinterdriver (mem_ctx, &q, server, level, ctr);
994 /* Marshall data and send request */
996 if (!spoolss_io_q_addprinterdriver ("", &q, &qbuf, 0) ||
997 !rpc_api_pipe_req (cli, PI_SPOOLSS, SPOOLSS_ADDPRINTERDRIVER, &qbuf, &rbuf))
1000 /* Unmarshall response */
1002 if (!spoolss_io_r_addprinterdriver ("", &r, &rbuf, 0))
1005 /* Return output parameters */
1010 prs_mem_free(&qbuf);
1011 prs_mem_free(&rbuf);
1016 /*********************************************************************************
1017 Win32 API - AddPrinter()
1018 ********************************************************************************/
1019 /**********************************************************************
1022 WERROR cli_spoolss_addprinterex (struct cli_state *cli, TALLOC_CTX *mem_ctx,
1023 uint32 level, PRINTER_INFO_CTR*ctr)
1025 prs_struct qbuf, rbuf;
1026 SPOOL_Q_ADDPRINTEREX q;
1027 SPOOL_R_ADDPRINTEREX r;
1028 WERROR result = W_ERROR(ERRgeneral);
1036 slprintf(client, sizeof(fstring)-1, "\\\\%s", cli->desthost);
1038 slprintf(server, sizeof(fstring)-1, "\\\\%s", cli->desthost);
1040 fstrcpy (user, cli->user_name);
1042 /* Initialise input parameters */
1044 prs_init(&qbuf, MAX_PDU_FRAG_LEN, mem_ctx, MARSHALL);
1045 prs_init(&rbuf, 0, mem_ctx, UNMARSHALL);
1047 /* Write the request */
1049 make_spoolss_q_addprinterex (mem_ctx, &q, server, client, user,
1052 /* Marshall data and send request */
1054 if (!spoolss_io_q_addprinterex ("", &q, &qbuf, 0) ||
1055 !rpc_api_pipe_req (cli, PI_SPOOLSS, SPOOLSS_ADDPRINTEREX, &qbuf, &rbuf))
1058 /* Unmarshall response */
1060 if (!spoolss_io_r_addprinterex ("", &r, &rbuf, 0))
1063 /* Return output parameters */
1068 prs_mem_free(&qbuf);
1069 prs_mem_free(&rbuf);
1074 /**********************************************************************
1075 * Delete a Printer Driver from the server (DOES remove
1078 WERROR cli_spoolss_deleteprinterdriverex(struct cli_state *cli,
1079 TALLOC_CTX *mem_ctx, const char *arch,
1080 const char *driver, int version)
1082 prs_struct qbuf, rbuf;
1083 SPOOL_Q_DELETEPRINTERDRIVEREX q;
1084 SPOOL_R_DELETEPRINTERDRIVEREX r;
1085 WERROR result = W_ERROR(ERRgeneral);
1092 /* Initialise input parameters */
1093 prs_init(&qbuf, MAX_PDU_FRAG_LEN, mem_ctx, MARSHALL);
1094 prs_init(&rbuf, 0, mem_ctx, UNMARSHALL);
1096 slprintf(server, sizeof(fstring)-1, "\\\\%s", cli->desthost);
1099 /* Write the request */
1100 make_spoolss_q_deleteprinterdriverex(mem_ctx, &q, server, arch, driver, version);
1102 /* Marshall data and send request */
1104 if (!spoolss_io_q_deleteprinterdriverex ("", &q, &qbuf, 0)
1105 || !rpc_api_pipe_req (cli, PI_SPOOLSS, SPOOLSS_DELETEPRINTERDRIVEREX , &qbuf, &rbuf))
1110 /* Unmarshall response */
1112 if (!spoolss_io_r_deleteprinterdriverex ("", &r, &rbuf, 0))
1115 /* Return output parameters */
1120 prs_mem_free(&qbuf);
1121 prs_mem_free(&rbuf);
1126 /*********************************************************************************
1127 Win32 API - DeltePrinterDriver()
1128 ********************************************************************************/
1129 /**********************************************************************
1130 * Delete a Printer Driver from the server (does not remove
1133 WERROR cli_spoolss_deleteprinterdriver (struct cli_state *cli,
1134 TALLOC_CTX *mem_ctx, const char *arch,
1137 prs_struct qbuf, rbuf;
1138 SPOOL_Q_DELETEPRINTERDRIVER q;
1139 SPOOL_R_DELETEPRINTERDRIVER r;
1140 WERROR result = W_ERROR(ERRgeneral);
1147 /* Initialise input parameters */
1148 prs_init(&qbuf, MAX_PDU_FRAG_LEN, mem_ctx, MARSHALL);
1149 prs_init(&rbuf, 0, mem_ctx, UNMARSHALL);
1151 slprintf(server, sizeof(fstring)-1, "\\\\%s", cli->desthost);
1154 /* Write the request */
1156 make_spoolss_q_deleteprinterdriver(mem_ctx, &q, server, arch, driver);
1158 /* Marshall data and send request */
1160 if (!spoolss_io_q_deleteprinterdriver ("", &q, &qbuf, 0) ||
1161 !rpc_api_pipe_req (cli, PI_SPOOLSS, SPOOLSS_DELETEPRINTERDRIVER , &qbuf, &rbuf))
1164 /* Unmarshall response */
1166 if (!spoolss_io_r_deleteprinterdriver ("", &r, &rbuf, 0))
1169 /* Return output parameters */
1174 prs_mem_free(&qbuf);
1175 prs_mem_free(&rbuf);
1180 /*********************************************************************************
1181 Win32 API - GetPrinterProcessorDirectory()
1182 ********************************************************************************/
1184 WERROR cli_spoolss_getprintprocessordirectory(struct cli_state *cli,
1185 TALLOC_CTX *mem_ctx,
1186 uint32 offered, uint32 *needed,
1187 char *name, char *environment,
1190 prs_struct qbuf, rbuf;
1191 SPOOL_Q_GETPRINTPROCESSORDIRECTORY q;
1192 SPOOL_R_GETPRINTPROCESSORDIRECTORY r;
1194 WERROR result = W_ERROR(ERRgeneral);
1200 /* Initialise parse structures */
1202 prs_init(&qbuf, MAX_PDU_FRAG_LEN, mem_ctx, MARSHALL);
1203 prs_init(&rbuf, 0, mem_ctx, UNMARSHALL);
1205 /* Initialise input parameters */
1207 rpcbuf_init(&buffer, offered, mem_ctx);
1209 make_spoolss_q_getprintprocessordirectory(
1210 &q, name, environment, level, &buffer, offered);
1212 /* Marshall data and send request */
1214 if (!spoolss_io_q_getprintprocessordirectory("", &q, &qbuf, 0) ||
1215 !rpc_api_pipe_req(cli, PI_SPOOLSS, SPOOLSS_GETPRINTPROCESSORDIRECTORY,
1219 /* Unmarshall response */
1221 if (!spoolss_io_r_getprintprocessordirectory("", &r, &rbuf, 0))
1224 /* Return output parameters */
1231 if (W_ERROR_IS_OK(result))
1232 fstrcpy(procdir, "Not implemented!");
1235 prs_mem_free(&qbuf);
1236 prs_mem_free(&rbuf);
1241 /** Add a form to a printer.
1243 * @param cli Pointer to client state structure which is open
1244 * on the SPOOLSS pipe.
1245 * @param mem_ctx Pointer to an initialised talloc context.
1247 * @param handle Policy handle opened with cli_spoolss_open_printer_ex
1248 * or cli_spoolss_addprinterex.
1249 * @param level Form info level to add - should always be 1.
1250 * @param form A pointer to the form to be added.
1254 WERROR cli_spoolss_addform(struct cli_state *cli, TALLOC_CTX *mem_ctx,
1255 POLICY_HND *handle, uint32 level, FORM *form)
1257 prs_struct qbuf, rbuf;
1260 WERROR result = W_ERROR(ERRgeneral);
1265 /* Initialise parse structures */
1267 prs_init(&qbuf, MAX_PDU_FRAG_LEN, mem_ctx, MARSHALL);
1268 prs_init(&rbuf, 0, mem_ctx, UNMARSHALL);
1270 /* Initialise input parameters */
1272 make_spoolss_q_addform(&q, handle, level, form);
1274 /* Marshall data and send request */
1276 if (!spoolss_io_q_addform("", &q, &qbuf, 0) ||
1277 !rpc_api_pipe_req(cli, PI_SPOOLSS, SPOOLSS_ADDFORM, &qbuf, &rbuf))
1280 /* Unmarshall response */
1282 if (!spoolss_io_r_addform("", &r, &rbuf, 0))
1285 /* Return output parameters */
1290 prs_mem_free(&qbuf);
1291 prs_mem_free(&rbuf);
1296 /** Set a form on a printer.
1298 * @param cli Pointer to client state structure which is open
1299 * on the SPOOLSS pipe.
1300 * @param mem_ctx Pointer to an initialised talloc context.
1302 * @param handle Policy handle opened with cli_spoolss_open_printer_ex
1303 * or cli_spoolss_addprinterex.
1304 * @param level Form info level to set - should always be 1.
1305 * @param form A pointer to the form to be set.
1309 WERROR cli_spoolss_setform(struct cli_state *cli, TALLOC_CTX *mem_ctx,
1310 POLICY_HND *handle, uint32 level,
1311 const char *form_name, FORM *form)
1313 prs_struct qbuf, rbuf;
1316 WERROR result = W_ERROR(ERRgeneral);
1321 /* Initialise parse structures */
1323 prs_init(&qbuf, MAX_PDU_FRAG_LEN, mem_ctx, MARSHALL);
1324 prs_init(&rbuf, 0, mem_ctx, UNMARSHALL);
1326 /* Initialise input parameters */
1328 make_spoolss_q_setform(&q, handle, level, form_name, form);
1330 /* Marshall data and send request */
1332 if (!spoolss_io_q_setform("", &q, &qbuf, 0) ||
1333 !rpc_api_pipe_req(cli, PI_SPOOLSS, SPOOLSS_SETFORM, &qbuf, &rbuf))
1336 /* Unmarshall response */
1338 if (!spoolss_io_r_setform("", &r, &rbuf, 0))
1341 /* Return output parameters */
1345 if (!W_ERROR_IS_OK(result))
1351 prs_mem_free(&qbuf);
1352 prs_mem_free(&rbuf);
1357 /** Get a form on a printer.
1359 * @param cli Pointer to client state structure which is open
1360 * on the SPOOLSS pipe.
1361 * @param mem_ctx Pointer to an initialised talloc context.
1363 * @param handle Policy handle opened with cli_spoolss_open_printer_ex
1364 * or cli_spoolss_addprinterex.
1365 * @param formname Name of the form to get
1366 * @param level Form info level to get - should always be 1.
1370 WERROR cli_spoolss_getform(struct cli_state *cli, TALLOC_CTX *mem_ctx,
1371 uint32 offered, uint32 *needed,
1372 POLICY_HND *handle, const char *formname,
1373 uint32 level, FORM_1 *form)
1375 prs_struct qbuf, rbuf;
1378 WERROR result = W_ERROR(ERRgeneral);
1384 /* Initialise parse structures */
1386 rpcbuf_init(&buffer, offered, mem_ctx);
1388 prs_init(&qbuf, MAX_PDU_FRAG_LEN, mem_ctx, MARSHALL);
1389 prs_init(&rbuf, 0, mem_ctx, UNMARSHALL);
1391 /* Initialise input parameters */
1393 make_spoolss_q_getform(&q, handle, formname, level, &buffer, offered);
1395 /* Marshall data and send request */
1397 if (!spoolss_io_q_getform("", &q, &qbuf, 0) ||
1398 !rpc_api_pipe_req(cli, PI_SPOOLSS, SPOOLSS_GETFORM, &qbuf, &rbuf))
1401 /* Unmarshall response */
1403 if (!spoolss_io_r_getform("", &r, &rbuf, 0))
1406 /* Return output parameters */
1413 if (W_ERROR_IS_OK(result)) {
1416 smb_io_form_1("", r.buffer, form, 0);
1419 DEBUG(10, ("cli_spoolss_getform: unknown info level %d", level));
1420 return WERR_UNKNOWN_LEVEL;
1425 prs_mem_free(&qbuf);
1426 prs_mem_free(&rbuf);
1431 /** Delete a form on a printer.
1433 * @param cli Pointer to client state structure which is open
1434 * on the SPOOLSS pipe.
1435 * @param mem_ctx Pointer to an initialised talloc context.
1437 * @param handle Policy handle opened with cli_spoolss_open_printer_ex
1438 * or cli_spoolss_addprinterex.
1439 * @param form The name of the form to delete.
1443 WERROR cli_spoolss_deleteform(struct cli_state *cli, TALLOC_CTX *mem_ctx,
1444 POLICY_HND *handle, const char *form_name)
1446 prs_struct qbuf, rbuf;
1447 SPOOL_Q_DELETEFORM q;
1448 SPOOL_R_DELETEFORM r;
1449 WERROR result = W_ERROR(ERRgeneral);
1454 /* Initialise parse structures */
1456 prs_init(&qbuf, MAX_PDU_FRAG_LEN, mem_ctx, MARSHALL);
1457 prs_init(&rbuf, 0, mem_ctx, UNMARSHALL);
1459 /* Initialise input parameters */
1461 make_spoolss_q_deleteform(&q, handle, form_name);
1463 /* Marshall data and send request */
1465 if (!spoolss_io_q_deleteform("", &q, &qbuf, 0) ||
1466 !rpc_api_pipe_req(cli, PI_SPOOLSS, SPOOLSS_DELETEFORM, &qbuf, &rbuf))
1469 /* Unmarshall response */
1471 if (!spoolss_io_r_deleteform("", &r, &rbuf, 0))
1474 /* Return output parameters */
1479 prs_mem_free(&qbuf);
1480 prs_mem_free(&rbuf);
1485 static void decode_forms_1(TALLOC_CTX *mem_ctx, RPC_BUFFER *buffer,
1486 uint32 num_forms, FORM_1 **forms)
1490 *forms = TALLOC_ARRAY(mem_ctx, FORM_1, num_forms);
1491 prs_set_offset(&buffer->prs,0);
1493 for (i = 0; i < num_forms; i++)
1494 smb_io_form_1("", buffer, &((*forms)[i]), 0);
1499 * @param cli Pointer to client state structure which is open
1500 * on the SPOOLSS pipe.
1501 * @param mem_ctx Pointer to an initialised talloc context.
1503 * @param offered Buffer size offered in the request.
1504 * @param needed Number of bytes needed to complete the request.
1506 * or cli_spoolss_addprinterex.
1507 * @param level Form info level to get - should always be 1.
1508 * @param handle Open policy handle
1512 WERROR cli_spoolss_enumforms(struct cli_state *cli, TALLOC_CTX *mem_ctx,
1513 uint32 offered, uint32 *needed,
1514 POLICY_HND *handle, int level, uint32 *num_forms,
1517 prs_struct qbuf, rbuf;
1518 SPOOL_Q_ENUMFORMS q;
1519 SPOOL_R_ENUMFORMS r;
1520 WERROR result = W_ERROR(ERRgeneral);
1526 /* Initialise parse structures */
1528 rpcbuf_init(&buffer, offered, mem_ctx);
1530 prs_init(&qbuf, MAX_PDU_FRAG_LEN, mem_ctx, MARSHALL);
1531 prs_init(&rbuf, 0, mem_ctx, UNMARSHALL);
1533 /* Initialise input parameters */
1535 make_spoolss_q_enumforms(&q, handle, level, &buffer, offered);
1537 /* Marshall data and send request */
1539 if (!spoolss_io_q_enumforms("", &q, &qbuf, 0) ||
1540 !rpc_api_pipe_req(cli, PI_SPOOLSS, SPOOLSS_ENUMFORMS, &qbuf, &rbuf))
1543 /* Unmarshall response */
1545 if (!spoolss_io_r_enumforms("", &r, &rbuf, 0))
1548 /* Return output parameters */
1556 *num_forms = r.numofforms;
1558 decode_forms_1(mem_ctx, r.buffer, *num_forms, forms);
1561 prs_mem_free(&qbuf);
1562 prs_mem_free(&rbuf);
1567 static void decode_jobs_1(TALLOC_CTX *mem_ctx, RPC_BUFFER *buffer,
1568 uint32 num_jobs, JOB_INFO_1 **jobs)
1572 *jobs = TALLOC_ARRAY(mem_ctx, JOB_INFO_1, num_jobs);
1573 prs_set_offset(&buffer->prs,0);
1575 for (i = 0; i < num_jobs; i++)
1576 smb_io_job_info_1("", buffer, &((*jobs)[i]), 0);
1579 static void decode_jobs_2(TALLOC_CTX *mem_ctx, RPC_BUFFER *buffer,
1580 uint32 num_jobs, JOB_INFO_2 **jobs)
1584 *jobs = TALLOC_ARRAY(mem_ctx, JOB_INFO_2, num_jobs);
1585 prs_set_offset(&buffer->prs,0);
1587 for (i = 0; i < num_jobs; i++)
1588 smb_io_job_info_2("", buffer, &((*jobs)[i]), 0);
1591 /* Enumerate jobs */
1593 WERROR cli_spoolss_enumjobs(struct cli_state *cli, TALLOC_CTX *mem_ctx,
1594 uint32 offered, uint32 *needed,
1595 POLICY_HND *hnd, uint32 level, uint32 firstjob,
1596 uint32 num_jobs, uint32 *returned, JOB_INFO_CTR *ctr)
1598 prs_struct qbuf, rbuf;
1601 WERROR result = W_ERROR(ERRgeneral);
1607 /* Initialise parse structures */
1609 rpcbuf_init(&buffer, offered, mem_ctx);
1611 prs_init(&qbuf, MAX_PDU_FRAG_LEN, mem_ctx, MARSHALL);
1612 prs_init(&rbuf, 0, mem_ctx, UNMARSHALL);
1614 /* Initialise input parameters */
1616 make_spoolss_q_enumjobs(&q, hnd, firstjob, num_jobs, level, &buffer,
1619 /* Marshall data and send request */
1621 if (!spoolss_io_q_enumjobs("", &q, &qbuf, 0) ||
1622 !rpc_api_pipe_req(cli, PI_SPOOLSS, SPOOLSS_ENUMJOBS, &qbuf, &rbuf))
1625 /* Unmarshall response */
1627 if (!spoolss_io_r_enumjobs("", &r, &rbuf, 0))
1630 /* Return output parameters */
1637 if (!W_ERROR_IS_OK(r.status))
1640 *returned = r.returned;
1644 decode_jobs_1(mem_ctx, r.buffer, r.returned,
1645 &ctr->job.job_info_1);
1648 decode_jobs_2(mem_ctx, r.buffer, r.returned,
1649 &ctr->job.job_info_2);
1652 DEBUG(3, ("unsupported info level %d", level));
1657 prs_mem_free(&qbuf);
1658 prs_mem_free(&rbuf);
1665 WERROR cli_spoolss_setjob(struct cli_state *cli, TALLOC_CTX *mem_ctx,
1666 POLICY_HND *hnd, uint32 jobid, uint32 level,
1669 prs_struct qbuf, rbuf;
1672 WERROR result = W_ERROR(ERRgeneral);
1677 /* Initialise parse structures */
1679 prs_init(&qbuf, MAX_PDU_FRAG_LEN, mem_ctx, MARSHALL);
1680 prs_init(&rbuf, 0, mem_ctx, UNMARSHALL);
1682 /* Initialise input parameters */
1684 make_spoolss_q_setjob(&q, hnd, jobid, level, command);
1686 /* Marshall data and send request */
1688 if (!spoolss_io_q_setjob("", &q, &qbuf, 0) ||
1689 !rpc_api_pipe_req(cli, PI_SPOOLSS, SPOOLSS_SETJOB, &qbuf, &rbuf))
1692 /* Unmarshall response */
1694 if (!spoolss_io_r_setjob("", &r, &rbuf, 0))
1697 /* Return output parameters */
1702 prs_mem_free(&qbuf);
1703 prs_mem_free(&rbuf);
1710 WERROR cli_spoolss_getjob(struct cli_state *cli, TALLOC_CTX *mem_ctx,
1711 uint32 offered, uint32 *needed,
1712 POLICY_HND *hnd, uint32 jobid, uint32 level,
1715 prs_struct qbuf, rbuf;
1718 WERROR result = W_ERROR(ERRgeneral);
1724 /* Initialise parse structures */
1726 rpcbuf_init(&buffer, offered, mem_ctx);
1728 prs_init(&qbuf, MAX_PDU_FRAG_LEN, mem_ctx, MARSHALL);
1729 prs_init(&rbuf, 0, mem_ctx, UNMARSHALL);
1731 /* Initialise input parameters */
1733 make_spoolss_q_getjob(&q, hnd, jobid, level, &buffer, offered);
1735 /* Marshall data and send request */
1737 if (!spoolss_io_q_getjob("", &q, &qbuf, 0) ||
1738 !rpc_api_pipe_req(cli, PI_SPOOLSS, SPOOLSS_GETJOB, &qbuf, &rbuf))
1741 /* Unmarshall response */
1743 if (!spoolss_io_r_getjob("", &r, &rbuf, 0))
1746 /* Return output parameters */
1753 if (!W_ERROR_IS_OK(r.status))
1758 decode_jobs_1(mem_ctx, r.buffer, 1, &ctr->job.job_info_1);
1761 decode_jobs_2(mem_ctx, r.buffer, 1, &ctr->job.job_info_2);
1764 DEBUG(3, ("unsupported info level %d", level));
1769 prs_mem_free(&qbuf);
1770 prs_mem_free(&rbuf);
1775 /* Startpageprinter. Sent to notify the spooler when a page is about to be
1776 sent to a printer. */
1778 WERROR cli_spoolss_startpageprinter(struct cli_state *cli, TALLOC_CTX *mem_ctx,
1781 prs_struct qbuf, rbuf;
1782 SPOOL_Q_STARTPAGEPRINTER q;
1783 SPOOL_R_STARTPAGEPRINTER r;
1784 WERROR result = W_ERROR(ERRgeneral);
1789 /* Initialise parse structures */
1791 prs_init(&qbuf, MAX_PDU_FRAG_LEN, mem_ctx, MARSHALL);
1792 prs_init(&rbuf, 0, mem_ctx, UNMARSHALL);
1794 /* Initialise input parameters */
1796 make_spoolss_q_startpageprinter(&q, hnd);
1798 /* Marshall data and send request */
1800 if (!spoolss_io_q_startpageprinter("", &q, &qbuf, 0) ||
1801 !rpc_api_pipe_req(cli, PI_SPOOLSS, SPOOLSS_STARTPAGEPRINTER, &qbuf, &rbuf))
1804 /* Unmarshall response */
1806 if (!spoolss_io_r_startpageprinter("", &r, &rbuf, 0))
1809 /* Return output parameters */
1814 prs_mem_free(&qbuf);
1815 prs_mem_free(&rbuf);
1820 /* Endpageprinter. Sent to notify the spooler when a page has finished
1821 being sent to a printer. */
1823 WERROR cli_spoolss_endpageprinter(struct cli_state *cli, TALLOC_CTX *mem_ctx,
1826 prs_struct qbuf, rbuf;
1827 SPOOL_Q_ENDPAGEPRINTER q;
1828 SPOOL_R_ENDPAGEPRINTER r;
1829 WERROR result = W_ERROR(ERRgeneral);
1834 /* Initialise parse structures */
1836 prs_init(&qbuf, MAX_PDU_FRAG_LEN, mem_ctx, MARSHALL);
1837 prs_init(&rbuf, 0, mem_ctx, UNMARSHALL);
1839 /* Initialise input parameters */
1841 make_spoolss_q_endpageprinter(&q, hnd);
1843 /* Marshall data and send request */
1845 if (!spoolss_io_q_endpageprinter("", &q, &qbuf, 0) ||
1846 !rpc_api_pipe_req(cli, PI_SPOOLSS, SPOOLSS_ENDPAGEPRINTER, &qbuf, &rbuf))
1849 /* Unmarshall response */
1851 if (!spoolss_io_r_endpageprinter("", &r, &rbuf, 0))
1854 /* Return output parameters */
1859 prs_mem_free(&qbuf);
1860 prs_mem_free(&rbuf);
1865 /* Startdocprinter. Sent to notify the spooler that a document is about
1866 to be spooled for printing. */
1868 WERROR cli_spoolss_startdocprinter(struct cli_state *cli, TALLOC_CTX *mem_ctx,
1869 POLICY_HND *hnd, char *docname,
1870 char *outputfile, char *datatype,
1873 prs_struct qbuf, rbuf;
1874 SPOOL_Q_STARTDOCPRINTER q;
1875 SPOOL_R_STARTDOCPRINTER r;
1876 WERROR result = W_ERROR(ERRgeneral);
1882 /* Initialise parse structures */
1884 prs_init(&qbuf, MAX_PDU_FRAG_LEN, mem_ctx, MARSHALL);
1885 prs_init(&rbuf, 0, mem_ctx, UNMARSHALL);
1887 /* Initialise input parameters */
1889 make_spoolss_q_startdocprinter(&q, hnd, level, docname, outputfile,
1892 /* Marshall data and send request */
1894 if (!spoolss_io_q_startdocprinter("", &q, &qbuf, 0) ||
1895 !rpc_api_pipe_req(cli, PI_SPOOLSS, SPOOLSS_STARTDOCPRINTER, &qbuf, &rbuf))
1898 /* Unmarshall response */
1900 if (!spoolss_io_r_startdocprinter("", &r, &rbuf, 0))
1903 /* Return output parameters */
1907 if (W_ERROR_IS_OK(result))
1911 prs_mem_free(&qbuf);
1912 prs_mem_free(&rbuf);
1917 /* Enddocprinter. Sent to notify the spooler that a document has finished
1920 WERROR cli_spoolss_enddocprinter(struct cli_state *cli, TALLOC_CTX *mem_ctx,
1923 prs_struct qbuf, rbuf;
1924 SPOOL_Q_ENDDOCPRINTER q;
1925 SPOOL_R_ENDDOCPRINTER r;
1926 WERROR result = W_ERROR(ERRgeneral);
1931 /* Initialise parse structures */
1933 prs_init(&qbuf, MAX_PDU_FRAG_LEN, mem_ctx, MARSHALL);
1934 prs_init(&rbuf, 0, mem_ctx, UNMARSHALL);
1936 /* Initialise input parameters */
1938 make_spoolss_q_enddocprinter(&q, hnd);
1940 /* Marshall data and send request */
1942 if (!spoolss_io_q_enddocprinter("", &q, &qbuf, 0) ||
1943 !rpc_api_pipe_req(cli, PI_SPOOLSS, SPOOLSS_ENDDOCPRINTER, &qbuf, &rbuf))
1946 /* Unmarshall response */
1948 if (!spoolss_io_r_enddocprinter("", &r, &rbuf, 0))
1951 /* Return output parameters */
1956 prs_mem_free(&qbuf);
1957 prs_mem_free(&rbuf);
1962 /* Get printer data */
1964 WERROR cli_spoolss_getprinterdata(struct cli_state *cli, TALLOC_CTX *mem_ctx,
1965 uint32 offered, uint32 *needed,
1966 POLICY_HND *hnd, const char *valuename,
1967 REGISTRY_VALUE *value)
1969 prs_struct qbuf, rbuf;
1970 SPOOL_Q_GETPRINTERDATA q;
1971 SPOOL_R_GETPRINTERDATA r;
1972 WERROR result = W_ERROR(ERRgeneral);
1977 /* Initialise parse structures */
1979 prs_init(&qbuf, MAX_PDU_FRAG_LEN, mem_ctx, MARSHALL);
1980 prs_init(&rbuf, 0, mem_ctx, UNMARSHALL);
1982 /* Initialise input parameters */
1984 make_spoolss_q_getprinterdata(&q, hnd, valuename, offered);
1986 /* Marshall data and send request */
1988 if (!spoolss_io_q_getprinterdata("", &q, &qbuf, 0) ||
1989 !rpc_api_pipe_req(cli, PI_SPOOLSS, SPOOLSS_GETPRINTERDATA, &qbuf, &rbuf))
1992 /* Unmarshall response */
1994 if (!spoolss_io_r_getprinterdata("", &r, &rbuf, 0))
2002 if (!W_ERROR_IS_OK(r.status))
2005 /* Return output parameters */
2007 value->data_p = TALLOC_MEMDUP(mem_ctx, r.data, r.needed);
2008 value->type = r.type;
2009 value->size = r.size;
2012 prs_mem_free(&qbuf);
2013 prs_mem_free(&rbuf);
2018 WERROR cli_spoolss_getprinterdataex(struct cli_state *cli, TALLOC_CTX *mem_ctx,
2019 uint32 offered, uint32 *needed,
2020 POLICY_HND *hnd, const char *keyname,
2021 const char *valuename,
2022 REGISTRY_VALUE *value)
2024 prs_struct qbuf, rbuf;
2025 SPOOL_Q_GETPRINTERDATAEX q;
2026 SPOOL_R_GETPRINTERDATAEX r;
2027 WERROR result = W_ERROR(ERRgeneral);
2032 /* Initialise parse structures */
2034 prs_init(&qbuf, MAX_PDU_FRAG_LEN, mem_ctx, MARSHALL);
2035 prs_init(&rbuf, 0, mem_ctx, UNMARSHALL);
2037 /* Initialise input parameters */
2039 make_spoolss_q_getprinterdataex(&q, hnd, keyname, valuename, offered);
2041 /* Marshall data and send request */
2043 if (!spoolss_io_q_getprinterdataex("", &q, &qbuf, 0) ||
2044 !rpc_api_pipe_req(cli, PI_SPOOLSS, SPOOLSS_GETPRINTERDATAEX, &qbuf, &rbuf))
2047 /* Unmarshall response */
2049 if (!spoolss_io_r_getprinterdataex("", &r, &rbuf, 0))
2057 if (!W_ERROR_IS_OK(r.status))
2060 /* Return output parameters */
2062 value->data_p = TALLOC_MEMDUP(mem_ctx, r.data, r.needed);
2063 value->type = r.type;
2064 value->size = r.needed;
2067 prs_mem_free(&qbuf);
2068 prs_mem_free(&rbuf);
2073 /* Set printer data */
2075 WERROR cli_spoolss_setprinterdata(struct cli_state *cli, TALLOC_CTX *mem_ctx,
2076 POLICY_HND *hnd, REGISTRY_VALUE *value)
2078 prs_struct qbuf, rbuf;
2079 SPOOL_Q_SETPRINTERDATA q;
2080 SPOOL_R_SETPRINTERDATA r;
2081 WERROR result = W_ERROR(ERRgeneral);
2086 /* Initialise parse structures */
2088 prs_init(&qbuf, MAX_PDU_FRAG_LEN, mem_ctx, MARSHALL);
2089 prs_init(&rbuf, 0, mem_ctx, UNMARSHALL);
2091 /* Initialise input parameters */
2093 make_spoolss_q_setprinterdata(
2094 &q, hnd, value->valuename, value->type, (char *)value->data_p, value->size);
2096 /* Marshall data and send request */
2098 if (!spoolss_io_q_setprinterdata("", &q, &qbuf, 0) ||
2099 !rpc_api_pipe_req(cli, PI_SPOOLSS, SPOOLSS_SETPRINTERDATA, &qbuf, &rbuf))
2102 /* Unmarshall response */
2104 if (!spoolss_io_r_setprinterdata("", &r, &rbuf, 0))
2109 if (!W_ERROR_IS_OK(r.status))
2113 prs_mem_free(&qbuf);
2114 prs_mem_free(&rbuf);
2119 WERROR cli_spoolss_setprinterdataex(struct cli_state *cli, TALLOC_CTX *mem_ctx,
2120 POLICY_HND *hnd, char *keyname,
2121 REGISTRY_VALUE *value)
2123 prs_struct qbuf, rbuf;
2124 SPOOL_Q_SETPRINTERDATAEX q;
2125 SPOOL_R_SETPRINTERDATAEX r;
2126 WERROR result = W_ERROR(ERRgeneral);
2131 /* Initialise parse structures */
2133 prs_init(&qbuf, MAX_PDU_FRAG_LEN, mem_ctx, MARSHALL);
2134 prs_init(&rbuf, 0, mem_ctx, UNMARSHALL);
2136 /* Initialise input parameters */
2138 make_spoolss_q_setprinterdataex(
2139 &q, hnd, keyname, value->valuename, value->type, (char *)value->data_p,
2142 /* Marshall data and send request */
2144 if (!spoolss_io_q_setprinterdataex("", &q, &qbuf, 0) ||
2145 !rpc_api_pipe_req(cli, PI_SPOOLSS, SPOOLSS_SETPRINTERDATAEX, &qbuf, &rbuf))
2148 /* Unmarshall response */
2150 if (!spoolss_io_r_setprinterdataex("", &r, &rbuf, 0))
2155 if (!W_ERROR_IS_OK(r.status))
2159 prs_mem_free(&qbuf);
2160 prs_mem_free(&rbuf);
2165 /* Enum printer data */
2167 WERROR cli_spoolss_enumprinterdata(struct cli_state *cli, TALLOC_CTX *mem_ctx,
2168 POLICY_HND *hnd, uint32 ndx,
2169 uint32 value_offered, uint32 data_offered,
2170 uint32 *value_needed, uint32 *data_needed,
2171 REGISTRY_VALUE *value)
2173 prs_struct qbuf, rbuf;
2174 SPOOL_Q_ENUMPRINTERDATA q;
2175 SPOOL_R_ENUMPRINTERDATA r;
2176 WERROR result = W_ERROR(ERRgeneral);
2181 /* Initialise parse structures */
2183 prs_init(&qbuf, MAX_PDU_FRAG_LEN, mem_ctx, MARSHALL);
2184 prs_init(&rbuf, 0, mem_ctx, UNMARSHALL);
2186 /* Initialise input parameters */
2188 make_spoolss_q_enumprinterdata(&q, hnd, ndx, value_offered, data_offered);
2190 /* Marshall data and send request */
2192 if (!spoolss_io_q_enumprinterdata("", &q, &qbuf, 0) ||
2193 !rpc_api_pipe_req(cli, PI_SPOOLSS, SPOOLSS_ENUMPRINTERDATA, &qbuf, &rbuf))
2196 /* Unmarshall response */
2198 if (!spoolss_io_r_enumprinterdata("", &r, &rbuf, 0))
2203 if (!W_ERROR_IS_OK(r.status))
2209 *value_needed = r.realvaluesize;
2212 *data_needed = r.realdatasize;
2215 rpcstr_pull(value->valuename, r.value, sizeof(value->valuename), -1,
2217 value->data_p = TALLOC_MEMDUP(mem_ctx, r.data, r.realdatasize);
2218 value->type = r.type;
2219 value->size = r.realdatasize;
2223 prs_mem_free(&qbuf);
2224 prs_mem_free(&rbuf);
2229 WERROR cli_spoolss_enumprinterdataex(struct cli_state *cli, TALLOC_CTX *mem_ctx,
2230 uint32 offered, uint32 *needed,
2231 POLICY_HND *hnd, const char *keyname,
2234 prs_struct qbuf, rbuf;
2235 SPOOL_Q_ENUMPRINTERDATAEX q;
2236 SPOOL_R_ENUMPRINTERDATAEX r;
2237 WERROR result = W_ERROR(ERRgeneral);
2243 /* Initialise parse structures */
2245 prs_init(&qbuf, MAX_PDU_FRAG_LEN, mem_ctx, MARSHALL);
2246 prs_init(&rbuf, 0, mem_ctx, UNMARSHALL);
2248 /* Initialise input parameters */
2250 make_spoolss_q_enumprinterdataex(&q, hnd, keyname, offered);
2252 /* Marshall data and send request */
2254 if (!spoolss_io_q_enumprinterdataex("", &q, &qbuf, 0) ||
2255 !rpc_api_pipe_req(cli, PI_SPOOLSS, SPOOLSS_ENUMPRINTERDATAEX, &qbuf, &rbuf))
2258 /* Unmarshall response */
2260 if (!spoolss_io_r_enumprinterdataex("", &r, &rbuf, 0))
2268 if (!W_ERROR_IS_OK(r.status))
2273 regval_ctr_init(ctr);
2275 for (i = 0; i < r.returned; i++) {
2276 PRINTER_ENUM_VALUES *v = &r.ctr.values[i];
2279 rpcstr_pull(name, v->valuename.buffer, sizeof(name), -1,
2281 regval_ctr_addvalue(ctr, name, v->type, (const char *)v->data, v->data_len);
2285 prs_mem_free(&qbuf);
2286 prs_mem_free(&rbuf);
2291 /* Write data to printer */
2293 WERROR cli_spoolss_writeprinter(struct cli_state *cli, TALLOC_CTX *mem_ctx,
2294 POLICY_HND *hnd, uint32 data_size, char *data,
2295 uint32 *num_written)
2297 prs_struct qbuf, rbuf;
2298 SPOOL_Q_WRITEPRINTER q;
2299 SPOOL_R_WRITEPRINTER r;
2300 WERROR result = W_ERROR(ERRgeneral);
2305 /* Initialise parse structures */
2307 prs_init(&qbuf, MAX_PDU_FRAG_LEN, mem_ctx, MARSHALL);
2308 prs_init(&rbuf, 0, mem_ctx, UNMARSHALL);
2310 /* Initialise input parameters */
2312 make_spoolss_q_writeprinter(&q, hnd, data_size, data);
2314 /* Marshall data and send request */
2316 if (!spoolss_io_q_writeprinter("", &q, &qbuf, 0) ||
2317 !rpc_api_pipe_req(cli, PI_SPOOLSS, SPOOLSS_WRITEPRINTER, &qbuf, &rbuf))
2320 /* Unmarshall response */
2322 if (!spoolss_io_r_writeprinter("", &r, &rbuf, 0))
2327 if (!W_ERROR_IS_OK(r.status))
2331 *num_written = r.buffer_written;
2334 prs_mem_free(&qbuf);
2335 prs_mem_free(&rbuf);
2340 /* Delete printer data */
2342 WERROR cli_spoolss_deleteprinterdata(struct cli_state *cli, TALLOC_CTX *mem_ctx,
2343 POLICY_HND *hnd, char *valuename)
2345 prs_struct qbuf, rbuf;
2346 SPOOL_Q_DELETEPRINTERDATA q;
2347 SPOOL_R_DELETEPRINTERDATA r;
2348 WERROR result = W_ERROR(ERRgeneral);
2353 /* Initialise parse structures */
2355 prs_init(&qbuf, MAX_PDU_FRAG_LEN, mem_ctx, MARSHALL);
2356 prs_init(&rbuf, 0, mem_ctx, UNMARSHALL);
2358 /* Initialise input parameters */
2360 make_spoolss_q_deleteprinterdata(&q, hnd, valuename);
2362 /* Marshall data and send request */
2364 if (!spoolss_io_q_deleteprinterdata("", &q, &qbuf, 0) ||
2365 !rpc_api_pipe_req(cli, PI_SPOOLSS, SPOOLSS_DELETEPRINTERDATA, &qbuf, &rbuf))
2368 /* Unmarshall response */
2370 if (!spoolss_io_r_deleteprinterdata("", &r, &rbuf, 0))
2375 if (!W_ERROR_IS_OK(r.status))
2379 prs_mem_free(&qbuf);
2380 prs_mem_free(&rbuf);
2385 WERROR cli_spoolss_deleteprinterdataex(struct cli_state *cli, TALLOC_CTX *mem_ctx,
2386 POLICY_HND *hnd, char *keyname,
2389 prs_struct qbuf, rbuf;
2390 SPOOL_Q_DELETEPRINTERDATAEX q;
2391 SPOOL_R_DELETEPRINTERDATAEX r;
2392 WERROR result = W_ERROR(ERRgeneral);
2397 /* Initialise parse structures */
2399 prs_init(&qbuf, MAX_PDU_FRAG_LEN, mem_ctx, MARSHALL);
2400 prs_init(&rbuf, 0, mem_ctx, UNMARSHALL);
2402 /* Initialise input parameters */
2404 make_spoolss_q_deleteprinterdataex(&q, hnd, keyname, valuename);
2406 /* Marshall data and send request */
2408 if (!spoolss_io_q_deleteprinterdataex("", &q, &qbuf, 0) ||
2409 !rpc_api_pipe_req(cli, PI_SPOOLSS, SPOOLSS_DELETEPRINTERDATAEX, &qbuf, &rbuf))
2412 /* Unmarshall response */
2414 if (!spoolss_io_r_deleteprinterdataex("", &r, &rbuf, 0))
2419 if (!W_ERROR_IS_OK(r.status))
2423 prs_mem_free(&qbuf);
2424 prs_mem_free(&rbuf);
2429 WERROR cli_spoolss_enumprinterkey(struct cli_state *cli, TALLOC_CTX *mem_ctx,
2430 uint32 offered, uint32 *needed,
2431 POLICY_HND *hnd, const char *keyname,
2432 uint16 **keylist, uint32 *len)
2434 prs_struct qbuf, rbuf;
2435 SPOOL_Q_ENUMPRINTERKEY q;
2436 SPOOL_R_ENUMPRINTERKEY r;
2437 WERROR result = W_ERROR(ERRgeneral);
2442 /* Initialise parse structures */
2444 prs_init(&qbuf, MAX_PDU_FRAG_LEN, mem_ctx, MARSHALL);
2445 prs_init(&rbuf, 0, mem_ctx, UNMARSHALL);
2447 /* Initialise input parameters */
2449 make_spoolss_q_enumprinterkey(&q, hnd, keyname, offered);
2451 /* Marshall data and send request */
2453 if (!spoolss_io_q_enumprinterkey("", &q, &qbuf, 0) ||
2454 !rpc_api_pipe_req(cli, PI_SPOOLSS, SPOOLSS_ENUMPRINTERKEY, &qbuf, &rbuf))
2457 /* Unmarshall response */
2459 if (!spoolss_io_r_enumprinterkey("", &r, &rbuf, 0))
2467 if (!W_ERROR_IS_OK(r.status))
2473 *keylist = SMB_MALLOC_ARRAY(uint16, r.keys.buf_len);
2474 memcpy(*keylist, r.keys.buffer, r.keys.buf_len * 2);
2476 *len = r.keys.buf_len * 2;
2480 prs_mem_free(&qbuf);
2481 prs_mem_free(&rbuf);
2486 WERROR cli_spoolss_deleteprinterkey(struct cli_state *cli, TALLOC_CTX *mem_ctx,
2487 POLICY_HND *hnd, char *keyname)
2489 prs_struct qbuf, rbuf;
2490 SPOOL_Q_DELETEPRINTERKEY q;
2491 SPOOL_R_DELETEPRINTERKEY r;
2492 WERROR result = W_ERROR(ERRgeneral);
2497 /* Initialise parse structures */
2499 prs_init(&qbuf, MAX_PDU_FRAG_LEN, mem_ctx, MARSHALL);
2500 prs_init(&rbuf, 0, mem_ctx, UNMARSHALL);
2502 /* Initialise input parameters */
2504 make_spoolss_q_deleteprinterkey(&q, hnd, keyname);
2506 /* Marshall data and send request */
2508 if (!spoolss_io_q_deleteprinterkey("", &q, &qbuf, 0) ||
2509 !rpc_api_pipe_req(cli, PI_SPOOLSS, SPOOLSS_DELETEPRINTERKEY, &qbuf, &rbuf))
2512 /* Unmarshall response */
2514 if (!spoolss_io_r_deleteprinterkey("", &r, &rbuf, 0))
2519 if (!W_ERROR_IS_OK(r.status))
2523 prs_mem_free(&qbuf);
2524 prs_mem_free(&rbuf);