2 Unix SMB/CIFS implementation.
5 Copyright (C) Gerald Carter 2001-2002,
6 Copyright (C) Tim Potter 2000-2002,
7 Copyright (C) Andrew Tridgell 1994-2000,
8 Copyright (C) Luke Kenneth Casson Leighton 1996-2000,
9 Copyright (C) Jean-Francois Micouleau 1999-2000.
11 This program is free software; you can redistribute it and/or modify
12 it under the terms of the GNU General Public License as published by
13 the Free Software Foundation; either version 2 of the License, or
14 (at your option) any later version.
16 This program is distributed in the hope that it will be useful,
17 but WITHOUT ANY WARRANTY; without even the implied warranty of
18 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 GNU General Public License for more details.
21 You should have received a copy of the GNU General Public License
22 along with this program; if not, write to the Free Software
23 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
28 /** @defgroup spoolss SPOOLSS - NT printing routines
34 /**********************************************************************
35 Initialize a new spoolss buff for use by a client rpc
36 **********************************************************************/
37 static void init_buffer(NEW_BUFFER *buffer, uint32 size, TALLOC_CTX *ctx)
39 buffer->ptr = (size != 0);
41 buffer->string_at_end = size;
42 prs_init(&buffer->prs, size, ctx, MARSHALL);
43 buffer->struct_start = prs_offset(&buffer->prs);
46 /*********************************************************************
47 Decode various spoolss rpc's and info levels
48 ********************************************************************/
50 /**********************************************************************
51 **********************************************************************/
52 static void decode_printer_info_0(TALLOC_CTX *mem_ctx, NEW_BUFFER *buffer,
53 uint32 returned, PRINTER_INFO_0 **info)
58 inf=(PRINTER_INFO_0 *)talloc(mem_ctx, returned*sizeof(PRINTER_INFO_0));
60 buffer->prs.data_offset=0;
62 for (i=0; i<returned; i++) {
63 smb_io_printer_info_0("", buffer, &inf[i], 0);
69 /**********************************************************************
70 **********************************************************************/
71 static void decode_printer_info_1(TALLOC_CTX *mem_ctx, NEW_BUFFER *buffer,
72 uint32 returned, PRINTER_INFO_1 **info)
77 inf=(PRINTER_INFO_1 *)talloc(mem_ctx, returned*sizeof(PRINTER_INFO_1));
79 buffer->prs.data_offset=0;
81 for (i=0; i<returned; i++) {
82 smb_io_printer_info_1("", buffer, &inf[i], 0);
88 /**********************************************************************
89 **********************************************************************/
90 static void decode_printer_info_2(TALLOC_CTX *mem_ctx, NEW_BUFFER *buffer,
91 uint32 returned, PRINTER_INFO_2 **info)
96 inf=(PRINTER_INFO_2 *)talloc(mem_ctx, returned*sizeof(PRINTER_INFO_2));
98 buffer->prs.data_offset=0;
100 for (i=0; i<returned; i++) {
101 /* a little initialization as we go */
102 inf[i].secdesc = NULL;
103 smb_io_printer_info_2("", buffer, &inf[i], 0);
109 /**********************************************************************
110 **********************************************************************/
111 static void decode_printer_info_3(TALLOC_CTX *mem_ctx, NEW_BUFFER *buffer,
112 uint32 returned, PRINTER_INFO_3 **info)
117 inf=(PRINTER_INFO_3 *)talloc(mem_ctx, returned*sizeof(PRINTER_INFO_3));
119 buffer->prs.data_offset=0;
121 for (i=0; i<returned; i++) {
122 inf[i].secdesc = NULL;
123 smb_io_printer_info_3("", buffer, &inf[i], 0);
129 /**********************************************************************
130 **********************************************************************/
131 static void decode_port_info_1(TALLOC_CTX *mem_ctx, NEW_BUFFER *buffer,
132 uint32 returned, PORT_INFO_1 **info)
137 inf=(PORT_INFO_1*)talloc(mem_ctx, returned*sizeof(PORT_INFO_1));
139 prs_set_offset(&buffer->prs, 0);
141 for (i=0; i<returned; i++) {
142 smb_io_port_info_1("", buffer, &(inf[i]), 0);
148 /**********************************************************************
149 **********************************************************************/
150 static void decode_port_info_2(TALLOC_CTX *mem_ctx, NEW_BUFFER *buffer,
151 uint32 returned, PORT_INFO_2 **info)
156 inf=(PORT_INFO_2*)talloc(mem_ctx, returned*sizeof(PORT_INFO_2));
158 prs_set_offset(&buffer->prs, 0);
160 for (i=0; i<returned; i++) {
161 smb_io_port_info_2("", buffer, &(inf[i]), 0);
167 /**********************************************************************
168 **********************************************************************/
169 static void decode_printer_driver_1(TALLOC_CTX *mem_ctx, NEW_BUFFER *buffer,
170 uint32 returned, DRIVER_INFO_1 **info)
175 inf=(DRIVER_INFO_1 *)talloc(mem_ctx, returned*sizeof(DRIVER_INFO_1));
177 buffer->prs.data_offset=0;
179 for (i=0; i<returned; i++) {
180 smb_io_printer_driver_info_1("", buffer, &(inf[i]), 0);
186 /**********************************************************************
187 **********************************************************************/
188 static void decode_printer_driver_2(TALLOC_CTX *mem_ctx, NEW_BUFFER *buffer,
189 uint32 returned, DRIVER_INFO_2 **info)
194 inf=(DRIVER_INFO_2 *)talloc(mem_ctx, returned*sizeof(DRIVER_INFO_2));
196 buffer->prs.data_offset=0;
198 for (i=0; i<returned; i++) {
199 smb_io_printer_driver_info_2("", buffer, &(inf[i]), 0);
205 /**********************************************************************
206 **********************************************************************/
207 static void decode_printer_driver_3(TALLOC_CTX *mem_ctx, NEW_BUFFER *buffer,
208 uint32 returned, DRIVER_INFO_3 **info)
213 inf=(DRIVER_INFO_3 *)talloc(mem_ctx, returned*sizeof(DRIVER_INFO_3));
215 buffer->prs.data_offset=0;
217 for (i=0; i<returned; i++) {
218 smb_io_printer_driver_info_3("", buffer, &(inf[i]), 0);
224 /**********************************************************************
225 **********************************************************************/
226 static void decode_printerdriverdir_1 (TALLOC_CTX *mem_ctx, NEW_BUFFER *buffer,
227 uint32 returned, DRIVER_DIRECTORY_1 **info
230 DRIVER_DIRECTORY_1 *inf;
232 inf=(DRIVER_DIRECTORY_1 *)talloc(mem_ctx, sizeof(DRIVER_DIRECTORY_1));
234 prs_set_offset(&buffer->prs, 0);
236 smb_io_driverdir_1("", buffer, inf, 0);
241 /** Return a handle to the specified printer or print server.
243 * @param cli Pointer to client state structure which is open
244 * on the SPOOLSS pipe.
246 * @param mem_ctx Pointer to an initialised talloc context.
248 * @param printername The name of the printer or print server to be
249 * opened in UNC format.
251 * @param datatype Specifies the default data type for the printer.
253 * @param access_required The access rights requested on the printer or
256 * @param station The UNC name of the requesting workstation.
258 * @param username The name of the user requesting the open.
260 * @param pol Returned policy handle.
263 /*********************************************************************************
264 Win32 API - OpenPrinter()
265 ********************************************************************************/
267 WERROR cli_spoolss_open_printer_ex(struct cli_state *cli, TALLOC_CTX *mem_ctx,
268 char *printername, char *datatype, uint32 access_required,
269 char *station, char *username, POLICY_HND *pol)
271 prs_struct qbuf, rbuf;
272 SPOOL_Q_OPEN_PRINTER_EX q;
273 SPOOL_R_OPEN_PRINTER_EX r;
274 WERROR result = W_ERROR(ERRgeneral);
279 /* Initialise parse structures */
281 prs_init(&qbuf, MAX_PDU_FRAG_LEN, mem_ctx, MARSHALL);
282 prs_init(&rbuf, 0, mem_ctx, UNMARSHALL);
284 /* Initialise input parameters */
286 make_spoolss_q_open_printer_ex(&q, printername, datatype,
287 access_required, station, username);
289 /* Marshall data and send request */
291 if (!spoolss_io_q_open_printer_ex("", &q, &qbuf, 0) ||
292 !rpc_api_pipe_req(cli, SPOOLSS_OPENPRINTEREX, &qbuf, &rbuf))
295 /* Unmarshall response */
297 if (!spoolss_io_r_open_printer_ex("", &r, &rbuf, 0))
300 /* Return output parameters */
304 if (W_ERROR_IS_OK(result))
314 /** Close a printer handle
316 * @param cli Pointer to client state structure which is open
317 * on the SPOOLSS pipe.
319 * @param mem_ctx Pointer to an initialised talloc context.
321 * @param pol Policy handle of printer or print server to close.
323 /*********************************************************************************
324 Win32 API - ClosePrinter()
325 ********************************************************************************/
327 WERROR cli_spoolss_close_printer(struct cli_state *cli, TALLOC_CTX *mem_ctx,
330 prs_struct qbuf, rbuf;
331 SPOOL_Q_CLOSEPRINTER q;
332 SPOOL_R_CLOSEPRINTER r;
333 WERROR result = W_ERROR(ERRgeneral);
338 /* Initialise parse structures */
340 prs_init(&qbuf, MAX_PDU_FRAG_LEN, mem_ctx, MARSHALL);
341 prs_init(&rbuf, 0, mem_ctx, UNMARSHALL);
343 /* Initialise input parameters */
345 make_spoolss_q_closeprinter(&q, pol);
347 /* Marshall data and send request */
349 if (!spoolss_io_q_closeprinter("", &q, &qbuf, 0) ||
350 !rpc_api_pipe_req(cli, SPOOLSS_CLOSEPRINTER, &qbuf, &rbuf))
353 /* Unmarshall response */
355 if (!spoolss_io_r_closeprinter("", &r, &rbuf, 0))
358 /* Return output parameters */
362 if (W_ERROR_IS_OK(result))
372 /** Enumerate printers on a print server.
374 * @param cli Pointer to client state structure which is open
375 * on the SPOOLSS pipe.
376 * @param mem_ctx Pointer to an initialised talloc context.
378 * @param offered Buffer size offered in the request.
379 * @param needed Number of bytes needed to complete the request.
382 * @param flags Selected from PRINTER_ENUM_* flags.
383 * @param level Request information level.
385 * @param num_printers Pointer to number of printers returned. May be
387 * @param ctr Return structure for printer information. May
390 /*********************************************************************************
391 Win32 API - EnumPrinters()
392 ********************************************************************************/
394 WERROR cli_spoolss_enum_printers(struct cli_state *cli, TALLOC_CTX *mem_ctx,
395 uint32 offered, uint32 *needed,
396 char *name, uint32 flags, uint32 level,
397 uint32 *num_printers, PRINTER_INFO_CTR *ctr)
399 prs_struct qbuf, rbuf;
400 SPOOL_Q_ENUMPRINTERS q;
401 SPOOL_R_ENUMPRINTERS r;
403 WERROR result = W_ERROR(ERRgeneral);
408 /* Initialise input parameters */
410 init_buffer(&buffer, offered, mem_ctx);
412 prs_init(&qbuf, MAX_PDU_FRAG_LEN, mem_ctx, MARSHALL);
413 prs_init(&rbuf, 0, mem_ctx, UNMARSHALL);
415 make_spoolss_q_enumprinters(&q, flags, name, level, &buffer,
418 /* Marshall data and send request */
420 if (!spoolss_io_q_enumprinters("", &q, &qbuf, 0) ||
421 !rpc_api_pipe_req(cli, SPOOLSS_ENUMPRINTERS, &qbuf, &rbuf))
424 /* Unmarshall response */
426 if (spoolss_io_r_enumprinters("", &r, &rbuf, 0)) {
433 /* Return output parameters */
435 if (!W_ERROR_IS_OK(r.status))
439 *num_printers = r.returned;
446 decode_printer_info_0(mem_ctx, r.buffer, r.returned,
450 decode_printer_info_1(mem_ctx, r.buffer, r.returned,
454 decode_printer_info_2(mem_ctx, r.buffer, r.returned,
458 decode_printer_info_3(mem_ctx, r.buffer, r.returned,
470 /*********************************************************************************
471 Win32 API - EnumPorts()
472 ********************************************************************************/
473 /** Enumerate printer ports on a print server.
475 * @param cli Pointer to client state structure which is open
476 * on the SPOOLSS pipe.
477 * @param mem_ctx Pointer to an initialised talloc context.
479 * @param offered Buffer size offered in the request.
480 * @param needed Number of bytes needed to complete the request.
483 * @param level Requested information level.
485 * @param num_ports Pointer to number of ports returned. May be NULL.
486 * @param ctr Pointer to structure holding port information.
490 WERROR cli_spoolss_enum_ports(struct cli_state *cli, TALLOC_CTX *mem_ctx,
491 uint32 offered, uint32 *needed,
492 uint32 level, int *num_ports, PORT_INFO_CTR *ctr)
494 prs_struct qbuf, rbuf;
498 WERROR result = W_ERROR(ERRgeneral);
504 slprintf (server, sizeof(fstring)-1, "\\\\%s", cli->desthost);
507 /* Initialise input parameters */
509 init_buffer(&buffer, offered, mem_ctx);
511 prs_init(&qbuf, MAX_PDU_FRAG_LEN, mem_ctx, MARSHALL);
512 prs_init(&rbuf, 0, mem_ctx, UNMARSHALL);
514 make_spoolss_q_enumports(&q, server, level, &buffer, offered);
516 /* Marshall data and send request */
518 if (!spoolss_io_q_enumports("", &q, &qbuf, 0) ||
519 !rpc_api_pipe_req(cli, SPOOLSS_ENUMPORTS, &qbuf, &rbuf))
522 /* Unmarshall response */
524 if (spoolss_io_r_enumports("", &r, &rbuf, 0)) {
531 /* Return output parameters */
533 if (!W_ERROR_IS_OK(result))
537 *num_ports = r.returned;
544 decode_port_info_1(mem_ctx, r.buffer, r.returned,
548 decode_port_info_2(mem_ctx, r.buffer, r.returned,
560 /*********************************************************************************
561 Win32 API - GetPrinter()
562 ********************************************************************************/
564 WERROR cli_spoolss_getprinter(struct cli_state *cli, TALLOC_CTX *mem_ctx,
565 uint32 offered, uint32 *needed,
566 POLICY_HND *pol, uint32 level,
567 PRINTER_INFO_CTR *ctr)
569 prs_struct qbuf, rbuf;
570 SPOOL_Q_GETPRINTER q;
571 SPOOL_R_GETPRINTER r;
573 WERROR result = W_ERROR(ERRgeneral);
578 /* Initialise input parameters */
580 init_buffer(&buffer, offered, mem_ctx);
582 prs_init(&qbuf, MAX_PDU_FRAG_LEN, mem_ctx, MARSHALL);
583 prs_init(&rbuf, 0, mem_ctx, UNMARSHALL);
585 make_spoolss_q_getprinter(mem_ctx, &q, pol, level, &buffer, offered);
587 /* Marshall data and send request */
589 if (!spoolss_io_q_getprinter("", &q, &qbuf, 0) ||
590 !rpc_api_pipe_req(cli, SPOOLSS_GETPRINTER, &qbuf, &rbuf))
593 /* Unmarshall response */
595 if (!spoolss_io_r_getprinter("", &r, &rbuf, 0))
601 /* Return output parameters */
605 if (W_ERROR_IS_OK(result)) {
608 decode_printer_info_0(mem_ctx, r.buffer, 1, &ctr->printers_0);
611 decode_printer_info_1(mem_ctx, r.buffer, 1, &ctr->printers_1);
614 decode_printer_info_2(mem_ctx, r.buffer, 1, &ctr->printers_2);
617 decode_printer_info_3(mem_ctx, r.buffer, 1, &ctr->printers_3);
629 /*********************************************************************************
630 Win32 API - SetPrinter()
631 ********************************************************************************/
634 * @param cli Pointer to client state structure which is open
635 * on the SPOOLSS pipe.
636 * @param mem_ctx Pointer to an initialised talloc context.
638 * @param pol Policy handle on printer to set info.
639 * @param level Information level to set.
640 * @param ctr Pointer to structure holding printer information.
641 * @param command Specifies the action performed. See
642 * http://msdn.microsoft.com/library/default.asp?url=/library/en-us/gdi/prntspol_13ua.asp
647 WERROR cli_spoolss_setprinter(struct cli_state *cli, TALLOC_CTX *mem_ctx,
648 POLICY_HND *pol, uint32 level,
649 PRINTER_INFO_CTR *ctr, uint32 command)
651 prs_struct qbuf, rbuf;
652 SPOOL_Q_SETPRINTER q;
653 SPOOL_R_SETPRINTER r;
654 WERROR result = W_ERROR(ERRgeneral);
659 /* Initialise input parameters */
661 prs_init(&qbuf, MAX_PDU_FRAG_LEN, mem_ctx, MARSHALL);
662 prs_init(&rbuf, 0, mem_ctx, UNMARSHALL);
664 make_spoolss_q_setprinter(mem_ctx, &q, pol, level, ctr, command);
666 /* Marshall data and send request */
668 if (!spoolss_io_q_setprinter("", &q, &qbuf, 0) ||
669 !rpc_api_pipe_req(cli, SPOOLSS_SETPRINTER, &qbuf, &rbuf))
672 /* Unmarshall response */
674 if (!spoolss_io_r_setprinter("", &r, &rbuf, 0))
686 /*********************************************************************************
687 Win32 API - GetPrinterDriver()
688 ********************************************************************************/
689 /** Get installed printer drivers for a given printer
691 * @param cli Pointer to client state structure which is open
692 * on the SPOOLSS pipe.
694 * @param mem_ctx Pointer to an initialised talloc context.
696 * @param offered Buffer size offered in the request.
697 * @param needed Number of bytes needed to complete the request.
700 * @param pol Pointer to an open policy handle for the printer
701 * opened with cli_spoolss_open_printer_ex().
702 * @param level Requested information level.
703 * @param env The print environment or archictecture. This is
704 * "Windows NT x86" for NT4.
705 * @param ctr Returned printer driver information.
708 WERROR cli_spoolss_getprinterdriver(struct cli_state *cli,
710 uint32 offered, uint32 *needed,
711 POLICY_HND *pol, uint32 level,
712 char *env, PRINTER_DRIVER_CTR *ctr)
714 prs_struct qbuf, rbuf;
715 SPOOL_Q_GETPRINTERDRIVER2 q;
716 SPOOL_R_GETPRINTERDRIVER2 r;
718 WERROR result = W_ERROR(ERRgeneral);
724 fstrcpy (server, cli->desthost);
727 /* Initialise input parameters */
729 init_buffer(&buffer, offered, mem_ctx);
731 prs_init(&qbuf, MAX_PDU_FRAG_LEN, mem_ctx, MARSHALL);
732 prs_init(&rbuf, 0, mem_ctx, UNMARSHALL);
734 make_spoolss_q_getprinterdriver2(&q, pol, env, level, 2, 2,
737 /* Marshall data and send request */
739 if (!spoolss_io_q_getprinterdriver2 ("", &q, &qbuf, 0) ||
740 !rpc_api_pipe_req (cli, SPOOLSS_GETPRINTERDRIVER2, &qbuf, &rbuf))
743 /* Unmarshall response */
745 if (spoolss_io_r_getprinterdriver2 ("", &r, &rbuf, 0)) {
752 /* Return output parameters */
754 if (!W_ERROR_IS_OK(result))
762 decode_printer_driver_1(mem_ctx, r.buffer, 1, &ctr->info1);
765 decode_printer_driver_2(mem_ctx, r.buffer, 1, &ctr->info2);
768 decode_printer_driver_3(mem_ctx, r.buffer, 1, &ctr->info3);
771 DEBUG(10, ("cli_spoolss_getprinterdriver: unknown info level %d", level));
772 return WERR_UNKNOWN_LEVEL;
782 /*********************************************************************************
783 Win32 API - EnumPrinterDrivers()
784 ********************************************************************************/
785 /**********************************************************************
786 * Get installed printer drivers for a given printer
788 WERROR cli_spoolss_enumprinterdrivers (struct cli_state *cli,
790 uint32 offered, uint32 *needed,
791 uint32 level, char *env,
793 PRINTER_DRIVER_CTR *ctr)
795 prs_struct qbuf, rbuf;
796 SPOOL_Q_ENUMPRINTERDRIVERS q;
797 SPOOL_R_ENUMPRINTERDRIVERS r;
799 WERROR result = W_ERROR(ERRgeneral);
805 slprintf (server, sizeof(fstring)-1, "\\\\%s", cli->desthost);
808 /* Initialise input parameters */
810 init_buffer(&buffer, offered, mem_ctx);
812 prs_init(&qbuf, MAX_PDU_FRAG_LEN, mem_ctx, MARSHALL);
813 prs_init(&rbuf, 0, mem_ctx, UNMARSHALL);
815 /* Write the request */
817 make_spoolss_q_enumprinterdrivers(&q, server, env, level, &buffer,
820 /* Marshall data and send request */
822 if (!spoolss_io_q_enumprinterdrivers ("", &q, &qbuf, 0) ||
823 !rpc_api_pipe_req (cli, SPOOLSS_ENUMPRINTERDRIVERS, &qbuf, &rbuf))
826 /* Unmarshall response */
828 if (!spoolss_io_r_enumprinterdrivers ("", &r, &rbuf, 0))
835 *num_drivers = r.returned;
839 /* Return output parameters */
841 if (W_ERROR_IS_OK(result) && (r.returned != 0)) {
842 *num_drivers = r.returned;
846 decode_printer_driver_1(mem_ctx, r.buffer, r.returned, &ctr->info1);
849 decode_printer_driver_2(mem_ctx, r.buffer, r.returned, &ctr->info2);
852 decode_printer_driver_3(mem_ctx, r.buffer, r.returned, &ctr->info3);
855 DEBUG(10, ("cli_spoolss_enumprinterdrivers: unknown info level %d\n",
857 return WERR_UNKNOWN_LEVEL;
869 /*********************************************************************************
870 Win32 API - GetPrinterDriverDirectory()
871 ********************************************************************************/
872 /**********************************************************************
873 * Get installed printer drivers for a given printer
875 WERROR cli_spoolss_getprinterdriverdir (struct cli_state *cli,
877 uint32 offered, uint32 *needed,
878 uint32 level, char *env,
879 DRIVER_DIRECTORY_CTR *ctr)
881 prs_struct qbuf, rbuf;
882 SPOOL_Q_GETPRINTERDRIVERDIR q;
883 SPOOL_R_GETPRINTERDRIVERDIR r;
885 WERROR result = W_ERROR(ERRgeneral);
891 slprintf (server, sizeof(fstring)-1, "\\\\%s", cli->desthost);
894 /* Initialise input parameters */
896 init_buffer(&buffer, offered, mem_ctx);
898 prs_init(&qbuf, MAX_PDU_FRAG_LEN, mem_ctx, MARSHALL);
899 prs_init(&rbuf, 0, mem_ctx, UNMARSHALL);
901 /* Write the request */
903 make_spoolss_q_getprinterdriverdir(&q, server, env, level, &buffer,
906 /* Marshall data and send request */
908 if (!spoolss_io_q_getprinterdriverdir ("", &q, &qbuf, 0) ||
909 !rpc_api_pipe_req (cli, SPOOLSS_GETPRINTERDRIVERDIRECTORY,
913 /* Unmarshall response */
915 if (spoolss_io_r_getprinterdriverdir ("", &r, &rbuf, 0)) {
920 /* Return output parameters */
924 if (W_ERROR_IS_OK(result)) {
927 decode_printerdriverdir_1(mem_ctx, r.buffer, 1,
940 /*********************************************************************************
941 Win32 API - AddPrinterDriver()
942 ********************************************************************************/
943 /**********************************************************************
944 * Install a printer driver
946 WERROR cli_spoolss_addprinterdriver (struct cli_state *cli,
947 TALLOC_CTX *mem_ctx, uint32 level,
948 PRINTER_DRIVER_CTR *ctr)
950 prs_struct qbuf, rbuf;
951 SPOOL_Q_ADDPRINTERDRIVER q;
952 SPOOL_R_ADDPRINTERDRIVER r;
953 WERROR result = W_ERROR(ERRgeneral);
959 slprintf (server, sizeof(fstring)-1, "\\\\%s", cli->desthost);
962 /* Initialise input parameters */
964 prs_init(&qbuf, MAX_PDU_FRAG_LEN, mem_ctx, MARSHALL);
965 prs_init(&rbuf, 0, mem_ctx, UNMARSHALL);
967 /* Write the request */
969 make_spoolss_q_addprinterdriver (mem_ctx, &q, server, level, ctr);
971 /* Marshall data and send request */
973 if (!spoolss_io_q_addprinterdriver ("", &q, &qbuf, 0) ||
974 !rpc_api_pipe_req (cli, SPOOLSS_ADDPRINTERDRIVER, &qbuf, &rbuf))
977 /* Unmarshall response */
979 if (!spoolss_io_r_addprinterdriver ("", &r, &rbuf, 0))
982 /* Return output parameters */
993 /*********************************************************************************
994 Win32 API - AddPrinter()
995 ********************************************************************************/
996 /**********************************************************************
999 WERROR cli_spoolss_addprinterex (struct cli_state *cli, TALLOC_CTX *mem_ctx,
1000 uint32 level, PRINTER_INFO_CTR*ctr)
1002 prs_struct qbuf, rbuf;
1003 SPOOL_Q_ADDPRINTEREX q;
1004 SPOOL_R_ADDPRINTEREX r;
1005 WERROR result = W_ERROR(ERRgeneral);
1013 slprintf (client, sizeof(fstring)-1, "\\\\%s", cli->desthost);
1015 slprintf (server, sizeof(fstring)-1, "\\\\%s", cli->desthost);
1017 fstrcpy (user, cli->user_name);
1019 /* Initialise input parameters */
1021 prs_init(&qbuf, MAX_PDU_FRAG_LEN, mem_ctx, MARSHALL);
1022 prs_init(&rbuf, 0, mem_ctx, UNMARSHALL);
1024 /* Write the request */
1026 make_spoolss_q_addprinterex (mem_ctx, &q, server, client, user,
1029 /* Marshall data and send request */
1031 if (!spoolss_io_q_addprinterex ("", &q, &qbuf, 0) ||
1032 !rpc_api_pipe_req (cli, SPOOLSS_ADDPRINTEREX, &qbuf, &rbuf))
1035 /* Unmarshall response */
1037 if (!spoolss_io_r_addprinterex ("", &r, &rbuf, 0))
1040 /* Return output parameters */
1045 prs_mem_free(&qbuf);
1046 prs_mem_free(&rbuf);
1051 /*********************************************************************************
1052 Win32 API - DeltePrinterDriver()
1053 ********************************************************************************/
1054 /**********************************************************************
1055 * Delete a Printer Driver from the server (does not remove
1058 WERROR cli_spoolss_deleteprinterdriver (struct cli_state *cli,
1059 TALLOC_CTX *mem_ctx, char *arch,
1062 prs_struct qbuf, rbuf;
1063 SPOOL_Q_DELETEPRINTERDRIVER q;
1064 SPOOL_R_DELETEPRINTERDRIVER r;
1065 WERROR result = W_ERROR(ERRgeneral);
1072 /* Initialise input parameters */
1073 prs_init(&qbuf, MAX_PDU_FRAG_LEN, mem_ctx, MARSHALL);
1074 prs_init(&rbuf, 0, mem_ctx, UNMARSHALL);
1076 slprintf (server, sizeof(fstring)-1, "\\\\%s", cli->desthost);
1079 /* Write the request */
1081 make_spoolss_q_deleteprinterdriver(mem_ctx, &q, server, arch, driver);
1083 /* Marshall data and send request */
1085 if (!spoolss_io_q_deleteprinterdriver ("", &q, &qbuf, 0) ||
1086 !rpc_api_pipe_req (cli,SPOOLSS_DELETEPRINTERDRIVER , &qbuf, &rbuf))
1089 /* Unmarshall response */
1091 if (!spoolss_io_r_deleteprinterdriver ("", &r, &rbuf, 0))
1094 /* Return output parameters */
1099 prs_mem_free(&qbuf);
1100 prs_mem_free(&rbuf);
1105 /*********************************************************************************
1106 Win32 API - GetPrinterProcessorDirectory()
1107 ********************************************************************************/
1109 WERROR cli_spoolss_getprintprocessordirectory(struct cli_state *cli,
1110 TALLOC_CTX *mem_ctx,
1111 uint32 offered, uint32 *needed,
1112 char *name, char *environment,
1115 prs_struct qbuf, rbuf;
1116 SPOOL_Q_GETPRINTPROCESSORDIRECTORY q;
1117 SPOOL_R_GETPRINTPROCESSORDIRECTORY r;
1119 WERROR result = W_ERROR(ERRgeneral);
1125 /* Initialise parse structures */
1127 prs_init(&qbuf, MAX_PDU_FRAG_LEN, mem_ctx, MARSHALL);
1128 prs_init(&rbuf, 0, mem_ctx, UNMARSHALL);
1130 /* Initialise input parameters */
1132 init_buffer(&buffer, offered, mem_ctx);
1134 make_spoolss_q_getprintprocessordirectory(
1135 &q, name, environment, level, &buffer, offered);
1137 /* Marshall data and send request */
1139 if (!spoolss_io_q_getprintprocessordirectory("", &q, &qbuf, 0) ||
1140 !rpc_api_pipe_req(cli, SPOOLSS_GETPRINTPROCESSORDIRECTORY,
1144 /* Unmarshall response */
1146 if (!spoolss_io_r_getprintprocessordirectory("", &r, &rbuf, 0))
1149 /* Return output parameters */
1156 if (W_ERROR_IS_OK(result))
1157 fstrcpy(procdir, "Not implemented!");
1160 prs_mem_free(&qbuf);
1161 prs_mem_free(&rbuf);
1166 /** Add a form to a printer.
1168 * @param cli Pointer to client state structure which is open
1169 * on the SPOOLSS pipe.
1170 * @param mem_ctx Pointer to an initialised talloc context.
1172 * @param handle Policy handle opened with cli_spoolss_open_printer_ex
1173 * or cli_spoolss_addprinterex.
1174 * @param level Form info level to add - should always be 1.
1175 * @param form A pointer to the form to be added.
1179 WERROR cli_spoolss_addform(struct cli_state *cli, TALLOC_CTX *mem_ctx,
1180 POLICY_HND *handle, uint32 level, FORM *form)
1182 prs_struct qbuf, rbuf;
1185 WERROR result = W_ERROR(ERRgeneral);
1190 /* Initialise parse structures */
1192 prs_init(&qbuf, MAX_PDU_FRAG_LEN, mem_ctx, MARSHALL);
1193 prs_init(&rbuf, 0, mem_ctx, UNMARSHALL);
1195 /* Initialise input parameters */
1197 make_spoolss_q_addform(&q, handle, level, form);
1199 /* Marshall data and send request */
1201 if (!spoolss_io_q_addform("", &q, &qbuf, 0) ||
1202 !rpc_api_pipe_req(cli, SPOOLSS_ADDFORM, &qbuf, &rbuf))
1205 /* Unmarshall response */
1207 if (!spoolss_io_r_addform("", &r, &rbuf, 0))
1210 /* Return output parameters */
1215 prs_mem_free(&qbuf);
1216 prs_mem_free(&rbuf);
1221 /** Set a form on a printer.
1223 * @param cli Pointer to client state structure which is open
1224 * on the SPOOLSS pipe.
1225 * @param mem_ctx Pointer to an initialised talloc context.
1227 * @param handle Policy handle opened with cli_spoolss_open_printer_ex
1228 * or cli_spoolss_addprinterex.
1229 * @param level Form info level to set - should always be 1.
1230 * @param form A pointer to the form to be set.
1234 WERROR cli_spoolss_setform(struct cli_state *cli, TALLOC_CTX *mem_ctx,
1235 POLICY_HND *handle, uint32 level, char *form_name,
1238 prs_struct qbuf, rbuf;
1241 WERROR result = W_ERROR(ERRgeneral);
1246 /* Initialise parse structures */
1248 prs_init(&qbuf, MAX_PDU_FRAG_LEN, mem_ctx, MARSHALL);
1249 prs_init(&rbuf, 0, mem_ctx, UNMARSHALL);
1251 /* Initialise input parameters */
1253 make_spoolss_q_setform(&q, handle, level, form_name, form);
1255 /* Marshall data and send request */
1257 if (!spoolss_io_q_setform("", &q, &qbuf, 0) ||
1258 !rpc_api_pipe_req(cli, SPOOLSS_SETFORM, &qbuf, &rbuf))
1261 /* Unmarshall response */
1263 if (!spoolss_io_r_setform("", &r, &rbuf, 0))
1266 /* Return output parameters */
1270 if (!W_ERROR_IS_OK(result))
1276 prs_mem_free(&qbuf);
1277 prs_mem_free(&rbuf);
1282 /** Get a form on a printer.
1284 * @param cli Pointer to client state structure which is open
1285 * on the SPOOLSS pipe.
1286 * @param mem_ctx Pointer to an initialised talloc context.
1288 * @param handle Policy handle opened with cli_spoolss_open_printer_ex
1289 * or cli_spoolss_addprinterex.
1290 * @param formname Name of the form to get
1291 * @param level Form info level to get - should always be 1.
1295 WERROR cli_spoolss_getform(struct cli_state *cli, TALLOC_CTX *mem_ctx,
1296 uint32 offered, uint32 *needed,
1297 POLICY_HND *handle, char *formname, uint32 level,
1300 prs_struct qbuf, rbuf;
1303 WERROR result = W_ERROR(ERRgeneral);
1309 /* Initialise parse structures */
1311 init_buffer(&buffer, offered, mem_ctx);
1313 prs_init(&qbuf, MAX_PDU_FRAG_LEN, mem_ctx, MARSHALL);
1314 prs_init(&rbuf, 0, mem_ctx, UNMARSHALL);
1316 /* Initialise input parameters */
1318 make_spoolss_q_getform(&q, handle, formname, level, &buffer, offered);
1320 /* Marshall data and send request */
1322 if (!spoolss_io_q_getform("", &q, &qbuf, 0) ||
1323 !rpc_api_pipe_req(cli, SPOOLSS_GETFORM, &qbuf, &rbuf))
1326 /* Unmarshall response */
1328 if (!spoolss_io_r_getform("", &r, &rbuf, 0))
1331 /* Return output parameters */
1338 if (W_ERROR_IS_OK(result))
1339 smb_io_form_1("", r.buffer, form, 0);
1342 prs_mem_free(&qbuf);
1343 prs_mem_free(&rbuf);
1348 /** Delete a form on a printer.
1350 * @param cli Pointer to client state structure which is open
1351 * on the SPOOLSS pipe.
1352 * @param mem_ctx Pointer to an initialised talloc context.
1354 * @param handle Policy handle opened with cli_spoolss_open_printer_ex
1355 * or cli_spoolss_addprinterex.
1356 * @param form The name of the form to delete.
1360 WERROR cli_spoolss_deleteform(struct cli_state *cli, TALLOC_CTX *mem_ctx,
1361 POLICY_HND *handle, char *form_name)
1363 prs_struct qbuf, rbuf;
1364 SPOOL_Q_DELETEFORM q;
1365 SPOOL_R_DELETEFORM r;
1366 WERROR result = W_ERROR(ERRgeneral);
1371 /* Initialise parse structures */
1373 prs_init(&qbuf, MAX_PDU_FRAG_LEN, mem_ctx, MARSHALL);
1374 prs_init(&rbuf, 0, mem_ctx, UNMARSHALL);
1376 /* Initialise input parameters */
1378 make_spoolss_q_deleteform(&q, handle, form_name);
1380 /* Marshall data and send request */
1382 if (!spoolss_io_q_deleteform("", &q, &qbuf, 0) ||
1383 !rpc_api_pipe_req(cli, SPOOLSS_DELETEFORM, &qbuf, &rbuf))
1386 /* Unmarshall response */
1388 if (!spoolss_io_r_deleteform("", &r, &rbuf, 0))
1391 /* Return output parameters */
1396 prs_mem_free(&qbuf);
1397 prs_mem_free(&rbuf);
1402 static void decode_forms_1(TALLOC_CTX *mem_ctx, NEW_BUFFER *buffer,
1403 uint32 num_forms, FORM_1 **forms)
1407 *forms = (FORM_1 *)talloc(mem_ctx, num_forms * sizeof(FORM_1));
1408 buffer->prs.data_offset = 0;
1410 for (i = 0; i < num_forms; i++)
1411 smb_io_form_1("", buffer, &((*forms)[i]), 0);
1416 * @param cli Pointer to client state structure which is open
1417 * on the SPOOLSS pipe.
1418 * @param mem_ctx Pointer to an initialised talloc context.
1420 * @param offered Buffer size offered in the request.
1421 * @param needed Number of bytes needed to complete the request.
1423 * or cli_spoolss_addprinterex.
1424 * @param level Form info level to get - should always be 1.
1425 * @param handle Open policy handle
1429 WERROR cli_spoolss_enumforms(struct cli_state *cli, TALLOC_CTX *mem_ctx,
1430 uint32 offered, uint32 *needed,
1431 POLICY_HND *handle, int level, uint32 *num_forms,
1434 prs_struct qbuf, rbuf;
1435 SPOOL_Q_ENUMFORMS q;
1436 SPOOL_R_ENUMFORMS r;
1437 WERROR result = W_ERROR(ERRgeneral);
1443 /* Initialise parse structures */
1445 init_buffer(&buffer, offered, mem_ctx);
1447 prs_init(&qbuf, MAX_PDU_FRAG_LEN, mem_ctx, MARSHALL);
1448 prs_init(&rbuf, 0, mem_ctx, UNMARSHALL);
1450 /* Initialise input parameters */
1452 make_spoolss_q_enumforms(&q, handle, level, &buffer, offered);
1454 /* Marshall data and send request */
1456 if (!spoolss_io_q_enumforms("", &q, &qbuf, 0) ||
1457 !rpc_api_pipe_req(cli, SPOOLSS_ENUMFORMS, &qbuf, &rbuf))
1460 /* Unmarshall response */
1462 if (!spoolss_io_r_enumforms("", &r, &rbuf, 0))
1465 /* Return output parameters */
1473 *num_forms = r.numofforms;
1475 decode_forms_1(mem_ctx, r.buffer, *num_forms, forms);
1478 prs_mem_free(&qbuf);
1479 prs_mem_free(&rbuf);
1484 static void decode_jobs_1(TALLOC_CTX *mem_ctx, NEW_BUFFER *buffer,
1485 uint32 num_jobs, JOB_INFO_1 **jobs)
1489 *jobs = (JOB_INFO_1 *)talloc(mem_ctx, num_jobs * sizeof(JOB_INFO_1));
1490 buffer->prs.data_offset = 0;
1492 for (i = 0; i < num_jobs; i++)
1493 smb_io_job_info_1("", buffer, &((*jobs)[i]), 0);
1496 static void decode_jobs_2(TALLOC_CTX *mem_ctx, NEW_BUFFER *buffer,
1497 uint32 num_jobs, JOB_INFO_2 **jobs)
1501 *jobs = (JOB_INFO_2 *)talloc(mem_ctx, num_jobs * sizeof(JOB_INFO_2));
1502 buffer->prs.data_offset = 0;
1504 for (i = 0; i < num_jobs; i++)
1505 smb_io_job_info_2("", buffer, &((*jobs)[i]), 0);
1508 /* Enumerate jobs */
1510 WERROR cli_spoolss_enumjobs(struct cli_state *cli, TALLOC_CTX *mem_ctx,
1511 uint32 offered, uint32 *needed,
1512 POLICY_HND *hnd, uint32 level, uint32 firstjob,
1513 uint32 num_jobs, uint32 *returned, JOB_INFO_CTR *ctr)
1515 prs_struct qbuf, rbuf;
1518 WERROR result = W_ERROR(ERRgeneral);
1524 /* Initialise parse structures */
1526 init_buffer(&buffer, offered, mem_ctx);
1528 prs_init(&qbuf, MAX_PDU_FRAG_LEN, mem_ctx, MARSHALL);
1529 prs_init(&rbuf, 0, mem_ctx, UNMARSHALL);
1531 /* Initialise input parameters */
1533 make_spoolss_q_enumjobs(&q, hnd, firstjob, num_jobs, level, &buffer,
1536 /* Marshall data and send request */
1538 if (!spoolss_io_q_enumjobs("", &q, &qbuf, 0) ||
1539 !rpc_api_pipe_req(cli, SPOOLSS_ENUMJOBS, &qbuf, &rbuf))
1542 /* Unmarshall response */
1544 if (!spoolss_io_r_enumjobs("", &r, &rbuf, 0))
1547 /* Return output parameters */
1554 if (!W_ERROR_IS_OK(r.status))
1557 *returned = r.returned;
1561 decode_jobs_1(mem_ctx, r.buffer, r.returned,
1562 &ctr->job.job_info_1);
1565 decode_jobs_2(mem_ctx, r.buffer, r.returned,
1566 &ctr->job.job_info_2);
1569 DEBUG(3, ("unsupported info level %d", level));
1574 prs_mem_free(&qbuf);
1575 prs_mem_free(&rbuf);
1582 WERROR cli_spoolss_setjob(struct cli_state *cli, TALLOC_CTX *mem_ctx,
1583 POLICY_HND *hnd, uint32 jobid, uint32 level,
1586 prs_struct qbuf, rbuf;
1589 WERROR result = W_ERROR(ERRgeneral);
1594 /* Initialise parse structures */
1596 prs_init(&qbuf, MAX_PDU_FRAG_LEN, mem_ctx, MARSHALL);
1597 prs_init(&rbuf, 0, mem_ctx, UNMARSHALL);
1599 /* Initialise input parameters */
1601 make_spoolss_q_setjob(&q, hnd, jobid, level, command);
1603 /* Marshall data and send request */
1605 if (!spoolss_io_q_setjob("", &q, &qbuf, 0) ||
1606 !rpc_api_pipe_req(cli, SPOOLSS_SETJOB, &qbuf, &rbuf))
1609 /* Unmarshall response */
1611 if (!spoolss_io_r_setjob("", &r, &rbuf, 0))
1614 /* Return output parameters */
1619 prs_mem_free(&qbuf);
1620 prs_mem_free(&rbuf);
1627 WERROR cli_spoolss_getjob(struct cli_state *cli, TALLOC_CTX *mem_ctx,
1628 uint32 offered, uint32 *needed,
1629 POLICY_HND *hnd, uint32 jobid, uint32 level,
1632 prs_struct qbuf, rbuf;
1635 WERROR result = W_ERROR(ERRgeneral);
1641 /* Initialise parse structures */
1643 init_buffer(&buffer, offered, mem_ctx);
1645 prs_init(&qbuf, MAX_PDU_FRAG_LEN, mem_ctx, MARSHALL);
1646 prs_init(&rbuf, 0, mem_ctx, UNMARSHALL);
1648 /* Initialise input parameters */
1650 make_spoolss_q_getjob(&q, hnd, jobid, level, &buffer, offered);
1652 /* Marshall data and send request */
1654 if (!spoolss_io_q_getjob("", &q, &qbuf, 0) ||
1655 !rpc_api_pipe_req(cli, SPOOLSS_GETJOB, &qbuf, &rbuf))
1658 /* Unmarshall response */
1660 if (!spoolss_io_r_getjob("", &r, &rbuf, 0))
1663 /* Return output parameters */
1670 if (!W_ERROR_IS_OK(r.status))
1675 decode_jobs_1(mem_ctx, r.buffer, 1, &ctr->job.job_info_1);
1678 decode_jobs_2(mem_ctx, r.buffer, 1, &ctr->job.job_info_2);
1681 DEBUG(3, ("unsupported info level %d", level));
1686 prs_mem_free(&qbuf);
1687 prs_mem_free(&rbuf);
1692 /* Startpageprinter. Sent to notify the spooler when a page is about to be
1693 sent to a printer. */
1695 WERROR cli_spoolss_startpageprinter(struct cli_state *cli, TALLOC_CTX *mem_ctx,
1698 prs_struct qbuf, rbuf;
1699 SPOOL_Q_STARTPAGEPRINTER q;
1700 SPOOL_R_STARTPAGEPRINTER r;
1701 WERROR result = W_ERROR(ERRgeneral);
1706 /* Initialise parse structures */
1708 prs_init(&qbuf, MAX_PDU_FRAG_LEN, mem_ctx, MARSHALL);
1709 prs_init(&rbuf, 0, mem_ctx, UNMARSHALL);
1711 /* Initialise input parameters */
1713 make_spoolss_q_startpageprinter(&q, hnd);
1715 /* Marshall data and send request */
1717 if (!spoolss_io_q_startpageprinter("", &q, &qbuf, 0) ||
1718 !rpc_api_pipe_req(cli, SPOOLSS_STARTPAGEPRINTER, &qbuf, &rbuf))
1721 /* Unmarshall response */
1723 if (!spoolss_io_r_startpageprinter("", &r, &rbuf, 0))
1726 /* Return output parameters */
1731 prs_mem_free(&qbuf);
1732 prs_mem_free(&rbuf);
1737 /* Endpageprinter. Sent to notify the spooler when a page has finished
1738 being sent to a printer. */
1740 WERROR cli_spoolss_endpageprinter(struct cli_state *cli, TALLOC_CTX *mem_ctx,
1743 prs_struct qbuf, rbuf;
1744 SPOOL_Q_ENDPAGEPRINTER q;
1745 SPOOL_R_ENDPAGEPRINTER r;
1746 WERROR result = W_ERROR(ERRgeneral);
1751 /* Initialise parse structures */
1753 prs_init(&qbuf, MAX_PDU_FRAG_LEN, mem_ctx, MARSHALL);
1754 prs_init(&rbuf, 0, mem_ctx, UNMARSHALL);
1756 /* Initialise input parameters */
1758 make_spoolss_q_endpageprinter(&q, hnd);
1760 /* Marshall data and send request */
1762 if (!spoolss_io_q_endpageprinter("", &q, &qbuf, 0) ||
1763 !rpc_api_pipe_req(cli, SPOOLSS_ENDPAGEPRINTER, &qbuf, &rbuf))
1766 /* Unmarshall response */
1768 if (!spoolss_io_r_endpageprinter("", &r, &rbuf, 0))
1771 /* Return output parameters */
1776 prs_mem_free(&qbuf);
1777 prs_mem_free(&rbuf);
1782 /* Startdocprinter. Sent to notify the spooler that a document is about
1783 to be spooled for printing. */
1785 WERROR cli_spoolss_startdocprinter(struct cli_state *cli, TALLOC_CTX *mem_ctx,
1786 POLICY_HND *hnd, char *docname,
1787 char *outputfile, char *datatype,
1790 prs_struct qbuf, rbuf;
1791 SPOOL_Q_STARTDOCPRINTER q;
1792 SPOOL_R_STARTDOCPRINTER r;
1793 WERROR result = W_ERROR(ERRgeneral);
1799 /* Initialise parse structures */
1801 prs_init(&qbuf, MAX_PDU_FRAG_LEN, mem_ctx, MARSHALL);
1802 prs_init(&rbuf, 0, mem_ctx, UNMARSHALL);
1804 /* Initialise input parameters */
1806 make_spoolss_q_startdocprinter(&q, hnd, level, docname, outputfile,
1809 /* Marshall data and send request */
1811 if (!spoolss_io_q_startdocprinter("", &q, &qbuf, 0) ||
1812 !rpc_api_pipe_req(cli, SPOOLSS_STARTDOCPRINTER, &qbuf, &rbuf))
1815 /* Unmarshall response */
1817 if (!spoolss_io_r_startdocprinter("", &r, &rbuf, 0))
1820 /* Return output parameters */
1824 if (W_ERROR_IS_OK(result))
1828 prs_mem_free(&qbuf);
1829 prs_mem_free(&rbuf);
1834 /* Enddocprinter. Sent to notify the spooler that a document has finished
1837 WERROR cli_spoolss_enddocprinter(struct cli_state *cli, TALLOC_CTX *mem_ctx,
1840 prs_struct qbuf, rbuf;
1841 SPOOL_Q_ENDDOCPRINTER q;
1842 SPOOL_R_ENDDOCPRINTER r;
1843 WERROR result = W_ERROR(ERRgeneral);
1848 /* Initialise parse structures */
1850 prs_init(&qbuf, MAX_PDU_FRAG_LEN, mem_ctx, MARSHALL);
1851 prs_init(&rbuf, 0, mem_ctx, UNMARSHALL);
1853 /* Initialise input parameters */
1855 make_spoolss_q_enddocprinter(&q, hnd);
1857 /* Marshall data and send request */
1859 if (!spoolss_io_q_enddocprinter("", &q, &qbuf, 0) ||
1860 !rpc_api_pipe_req(cli, SPOOLSS_ENDDOCPRINTER, &qbuf, &rbuf))
1863 /* Unmarshall response */
1865 if (!spoolss_io_r_enddocprinter("", &r, &rbuf, 0))
1868 /* Return output parameters */
1873 prs_mem_free(&qbuf);
1874 prs_mem_free(&rbuf);
1879 /* Get printer data */
1881 WERROR cli_spoolss_getprinterdata(struct cli_state *cli, TALLOC_CTX *mem_ctx,
1882 uint32 offered, uint32 *needed,
1883 POLICY_HND *hnd, char *valuename,
1884 REGISTRY_VALUE *value)
1886 prs_struct qbuf, rbuf;
1887 SPOOL_Q_GETPRINTERDATA q;
1888 SPOOL_R_GETPRINTERDATA r;
1889 WERROR result = W_ERROR(ERRgeneral);
1894 /* Initialise parse structures */
1896 prs_init(&qbuf, MAX_PDU_FRAG_LEN, mem_ctx, MARSHALL);
1897 prs_init(&rbuf, 0, mem_ctx, UNMARSHALL);
1899 /* Initialise input parameters */
1901 make_spoolss_q_getprinterdata(&q, hnd, valuename, offered);
1903 /* Marshall data and send request */
1905 if (!spoolss_io_q_getprinterdata("", &q, &qbuf, 0) ||
1906 !rpc_api_pipe_req(cli, SPOOLSS_GETPRINTERDATA, &qbuf, &rbuf))
1909 /* Unmarshall response */
1911 if (!spoolss_io_r_getprinterdata("", &r, &rbuf, 0))
1919 if (!W_ERROR_IS_OK(r.status))
1922 /* Return output parameters */
1924 value->data_p = talloc_memdup(mem_ctx, r.data, r.needed);
1925 value->type = r.type;
1926 value->size = r.size;
1929 prs_mem_free(&qbuf);
1930 prs_mem_free(&rbuf);
1935 WERROR cli_spoolss_getprinterdataex(struct cli_state *cli, TALLOC_CTX *mem_ctx,
1936 uint32 offered, uint32 *needed,
1937 POLICY_HND *hnd, char *keyname,
1938 char *valuename, REGISTRY_VALUE *value)
1940 prs_struct qbuf, rbuf;
1941 SPOOL_Q_GETPRINTERDATAEX q;
1942 SPOOL_R_GETPRINTERDATAEX r;
1943 WERROR result = W_ERROR(ERRgeneral);
1948 /* Initialise parse structures */
1950 prs_init(&qbuf, MAX_PDU_FRAG_LEN, mem_ctx, MARSHALL);
1951 prs_init(&rbuf, 0, mem_ctx, UNMARSHALL);
1953 /* Initialise input parameters */
1955 make_spoolss_q_getprinterdataex(&q, hnd, keyname, valuename, offered);
1957 /* Marshall data and send request */
1959 if (!spoolss_io_q_getprinterdataex("", &q, &qbuf, 0) ||
1960 !rpc_api_pipe_req(cli, SPOOLSS_GETPRINTERDATAEX, &qbuf, &rbuf))
1963 /* Unmarshall response */
1965 if (!spoolss_io_r_getprinterdataex("", &r, &rbuf, 0))
1973 if (!W_ERROR_IS_OK(r.status))
1976 /* Return output parameters */
1978 value->data_p = talloc_memdup(mem_ctx, r.data, r.needed);
1979 value->type = r.type;
1980 value->size = r.needed;
1983 prs_mem_free(&qbuf);
1984 prs_mem_free(&rbuf);
1989 /* Set printer data */
1991 WERROR cli_spoolss_setprinterdata(struct cli_state *cli, TALLOC_CTX *mem_ctx,
1992 POLICY_HND *hnd, REGISTRY_VALUE *value)
1994 prs_struct qbuf, rbuf;
1995 SPOOL_Q_SETPRINTERDATA q;
1996 SPOOL_R_SETPRINTERDATA r;
1997 WERROR result = W_ERROR(ERRgeneral);
2002 /* Initialise parse structures */
2004 prs_init(&qbuf, MAX_PDU_FRAG_LEN, mem_ctx, MARSHALL);
2005 prs_init(&rbuf, 0, mem_ctx, UNMARSHALL);
2007 /* Initialise input parameters */
2009 make_spoolss_q_setprinterdata(
2010 &q, hnd, value->valuename, value->type, value->data_p, value->size);
2012 /* Marshall data and send request */
2014 if (!spoolss_io_q_setprinterdata("", &q, &qbuf, 0) ||
2015 !rpc_api_pipe_req(cli, SPOOLSS_SETPRINTERDATA, &qbuf, &rbuf))
2018 /* Unmarshall response */
2020 if (!spoolss_io_r_setprinterdata("", &r, &rbuf, 0))
2025 if (!W_ERROR_IS_OK(r.status))
2029 prs_mem_free(&qbuf);
2030 prs_mem_free(&rbuf);
2035 WERROR cli_spoolss_setprinterdataex(struct cli_state *cli, TALLOC_CTX *mem_ctx,
2036 POLICY_HND *hnd, char *keyname,
2037 REGISTRY_VALUE *value)
2039 prs_struct qbuf, rbuf;
2040 SPOOL_Q_SETPRINTERDATAEX q;
2041 SPOOL_R_SETPRINTERDATAEX r;
2042 WERROR result = W_ERROR(ERRgeneral);
2047 /* Initialise parse structures */
2049 prs_init(&qbuf, MAX_PDU_FRAG_LEN, mem_ctx, MARSHALL);
2050 prs_init(&rbuf, 0, mem_ctx, UNMARSHALL);
2052 /* Initialise input parameters */
2054 make_spoolss_q_setprinterdataex(
2055 &q, hnd, keyname, value->valuename, value->type, value->data_p,
2058 /* Marshall data and send request */
2060 if (!spoolss_io_q_setprinterdataex("", &q, &qbuf, 0) ||
2061 !rpc_api_pipe_req(cli, SPOOLSS_SETPRINTERDATAEX, &qbuf, &rbuf))
2064 /* Unmarshall response */
2066 if (!spoolss_io_r_setprinterdataex("", &r, &rbuf, 0))
2071 if (!W_ERROR_IS_OK(r.status))
2075 prs_mem_free(&qbuf);
2076 prs_mem_free(&rbuf);
2081 /* Enum printer data */
2083 WERROR cli_spoolss_enumprinterdata(struct cli_state *cli, TALLOC_CTX *mem_ctx,
2084 POLICY_HND *hnd, uint32 ndx,
2085 uint32 value_offered, uint32 data_offered,
2086 uint32 *value_needed, uint32 *data_needed,
2087 REGISTRY_VALUE *value)
2089 prs_struct qbuf, rbuf;
2090 SPOOL_Q_ENUMPRINTERDATA q;
2091 SPOOL_R_ENUMPRINTERDATA r;
2092 WERROR result = W_ERROR(ERRgeneral);
2097 /* Initialise parse structures */
2099 prs_init(&qbuf, MAX_PDU_FRAG_LEN, mem_ctx, MARSHALL);
2100 prs_init(&rbuf, 0, mem_ctx, UNMARSHALL);
2102 /* Initialise input parameters */
2104 make_spoolss_q_enumprinterdata(&q, hnd, ndx, value_offered, data_offered);
2106 /* Marshall data and send request */
2108 if (!spoolss_io_q_enumprinterdata("", &q, &qbuf, 0) ||
2109 !rpc_api_pipe_req(cli, SPOOLSS_ENUMPRINTERDATA, &qbuf, &rbuf))
2112 /* Unmarshall response */
2114 if (!spoolss_io_r_enumprinterdata("", &r, &rbuf, 0))
2119 if (!W_ERROR_IS_OK(r.status))
2125 *value_needed = r.realvaluesize;
2128 *data_needed = r.realdatasize;
2131 rpcstr_pull(value->valuename, r.value, sizeof(value->valuename), -1,
2133 value->data_p = talloc_memdup(mem_ctx, r.data, r.realdatasize);
2134 value->type = r.type;
2135 value->size = r.realdatasize;
2139 prs_mem_free(&qbuf);
2140 prs_mem_free(&rbuf);
2145 WERROR cli_spoolss_enumprinterdataex(struct cli_state *cli, TALLOC_CTX *mem_ctx,
2146 uint32 offered, uint32 *needed,
2147 POLICY_HND *hnd, char *keyname,
2150 prs_struct qbuf, rbuf;
2151 SPOOL_Q_ENUMPRINTERDATAEX q;
2152 SPOOL_R_ENUMPRINTERDATAEX r;
2153 WERROR result = W_ERROR(ERRgeneral);
2159 /* Initialise parse structures */
2161 prs_init(&qbuf, MAX_PDU_FRAG_LEN, mem_ctx, MARSHALL);
2162 prs_init(&rbuf, 0, mem_ctx, UNMARSHALL);
2164 /* Initialise input parameters */
2166 make_spoolss_q_enumprinterdataex(&q, hnd, keyname, offered);
2168 /* Marshall data and send request */
2170 if (!spoolss_io_q_enumprinterdataex("", &q, &qbuf, 0) ||
2171 !rpc_api_pipe_req(cli, SPOOLSS_ENUMPRINTERDATAEX, &qbuf, &rbuf))
2174 /* Unmarshall response */
2176 if (!spoolss_io_r_enumprinterdataex("", &r, &rbuf, 0))
2184 if (!W_ERROR_IS_OK(r.status))
2190 regval_ctr_init(ctr);
2192 for (i = 0; i < r.returned; i++) {
2193 PRINTER_ENUM_VALUES *v = &r.ctr.values[i];
2196 rpcstr_pull(name, v->valuename.buffer, sizeof(name), -1,
2198 regval_ctr_addvalue(ctr, name, v->type, v->data, v->data_len);
2202 prs_mem_free(&qbuf);
2203 prs_mem_free(&rbuf);
2208 /* Write data to printer */
2210 WERROR cli_spoolss_writeprinter(struct cli_state *cli, TALLOC_CTX *mem_ctx,
2211 POLICY_HND *hnd, uint32 data_size, char *data,
2212 uint32 *num_written)
2214 prs_struct qbuf, rbuf;
2215 SPOOL_Q_WRITEPRINTER q;
2216 SPOOL_R_WRITEPRINTER r;
2217 WERROR result = W_ERROR(ERRgeneral);
2222 /* Initialise parse structures */
2224 prs_init(&qbuf, MAX_PDU_FRAG_LEN, mem_ctx, MARSHALL);
2225 prs_init(&rbuf, 0, mem_ctx, UNMARSHALL);
2227 /* Initialise input parameters */
2229 make_spoolss_q_writeprinter(&q, hnd, data_size, data);
2231 /* Marshall data and send request */
2233 if (!spoolss_io_q_writeprinter("", &q, &qbuf, 0) ||
2234 !rpc_api_pipe_req(cli, SPOOLSS_WRITEPRINTER, &qbuf, &rbuf))
2237 /* Unmarshall response */
2239 if (!spoolss_io_r_writeprinter("", &r, &rbuf, 0))
2244 if (!W_ERROR_IS_OK(r.status))
2248 *num_written = r.buffer_written;
2251 prs_mem_free(&qbuf);
2252 prs_mem_free(&rbuf);
2257 /* Delete printer data */
2259 WERROR cli_spoolss_deleteprinterdata(struct cli_state *cli, TALLOC_CTX *mem_ctx,
2260 POLICY_HND *hnd, char *valuename)
2262 prs_struct qbuf, rbuf;
2263 SPOOL_Q_DELETEPRINTERDATA q;
2264 SPOOL_R_DELETEPRINTERDATA r;
2265 WERROR result = W_ERROR(ERRgeneral);
2270 /* Initialise parse structures */
2272 prs_init(&qbuf, MAX_PDU_FRAG_LEN, mem_ctx, MARSHALL);
2273 prs_init(&rbuf, 0, mem_ctx, UNMARSHALL);
2275 /* Initialise input parameters */
2277 make_spoolss_q_deleteprinterdata(&q, hnd, valuename);
2279 /* Marshall data and send request */
2281 if (!spoolss_io_q_deleteprinterdata("", &q, &qbuf, 0) ||
2282 !rpc_api_pipe_req(cli, SPOOLSS_DELETEPRINTERDATA, &qbuf, &rbuf))
2285 /* Unmarshall response */
2287 if (!spoolss_io_r_deleteprinterdata("", &r, &rbuf, 0))
2292 if (!W_ERROR_IS_OK(r.status))
2296 prs_mem_free(&qbuf);
2297 prs_mem_free(&rbuf);
2302 WERROR cli_spoolss_deleteprinterdataex(struct cli_state *cli, TALLOC_CTX *mem_ctx,
2303 POLICY_HND *hnd, char *keyname,
2306 prs_struct qbuf, rbuf;
2307 SPOOL_Q_DELETEPRINTERDATAEX q;
2308 SPOOL_R_DELETEPRINTERDATAEX r;
2309 WERROR result = W_ERROR(ERRgeneral);
2314 /* Initialise parse structures */
2316 prs_init(&qbuf, MAX_PDU_FRAG_LEN, mem_ctx, MARSHALL);
2317 prs_init(&rbuf, 0, mem_ctx, UNMARSHALL);
2319 /* Initialise input parameters */
2321 make_spoolss_q_deleteprinterdataex(&q, hnd, keyname, valuename);
2323 /* Marshall data and send request */
2325 if (!spoolss_io_q_deleteprinterdataex("", &q, &qbuf, 0) ||
2326 !rpc_api_pipe_req(cli, SPOOLSS_DELETEPRINTERDATAEX, &qbuf, &rbuf))
2329 /* Unmarshall response */
2331 if (!spoolss_io_r_deleteprinterdataex("", &r, &rbuf, 0))
2336 if (!W_ERROR_IS_OK(r.status))
2340 prs_mem_free(&qbuf);
2341 prs_mem_free(&rbuf);