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);
779 /*********************************************************************************
780 Win32 API - EnumPrinterDrivers()
781 ********************************************************************************/
782 /**********************************************************************
783 * Get installed printer drivers for a given printer
785 WERROR cli_spoolss_enumprinterdrivers (struct cli_state *cli,
787 uint32 offered, uint32 *needed,
788 uint32 level, char *env,
790 PRINTER_DRIVER_CTR *ctr)
792 prs_struct qbuf, rbuf;
793 SPOOL_Q_ENUMPRINTERDRIVERS q;
794 SPOOL_R_ENUMPRINTERDRIVERS r;
796 WERROR result = W_ERROR(ERRgeneral);
802 slprintf (server, sizeof(fstring)-1, "\\\\%s", cli->desthost);
805 /* Initialise input parameters */
807 init_buffer(&buffer, offered, mem_ctx);
809 prs_init(&qbuf, MAX_PDU_FRAG_LEN, mem_ctx, MARSHALL);
810 prs_init(&rbuf, 0, mem_ctx, UNMARSHALL);
812 /* Write the request */
814 make_spoolss_q_enumprinterdrivers(&q, server, env, level, &buffer,
817 /* Marshall data and send request */
819 if (!spoolss_io_q_enumprinterdrivers ("", &q, &qbuf, 0) ||
820 !rpc_api_pipe_req (cli, SPOOLSS_ENUMPRINTERDRIVERS, &qbuf, &rbuf))
823 /* Unmarshall response */
825 if (!spoolss_io_r_enumprinterdrivers ("", &r, &rbuf, 0))
832 *num_drivers = r.returned;
836 /* Return output parameters */
838 if (W_ERROR_IS_OK(result) && (r.returned != 0)) {
839 *num_drivers = r.returned;
843 decode_printer_driver_1(mem_ctx, r.buffer, r.returned, &ctr->info1);
846 decode_printer_driver_2(mem_ctx, r.buffer, r.returned, &ctr->info2);
849 decode_printer_driver_3(mem_ctx, r.buffer, r.returned, &ctr->info3);
852 DEBUG(10, ("cli_spoolss_enumprinterdrivers: unknown info level %d\n",
854 return WERR_UNKNOWN_LEVEL;
866 /*********************************************************************************
867 Win32 API - GetPrinterDriverDirectory()
868 ********************************************************************************/
869 /**********************************************************************
870 * Get installed printer drivers for a given printer
872 WERROR cli_spoolss_getprinterdriverdir (struct cli_state *cli,
874 uint32 offered, uint32 *needed,
875 uint32 level, char *env,
876 DRIVER_DIRECTORY_CTR *ctr)
878 prs_struct qbuf, rbuf;
879 SPOOL_Q_GETPRINTERDRIVERDIR q;
880 SPOOL_R_GETPRINTERDRIVERDIR r;
882 WERROR result = W_ERROR(ERRgeneral);
888 slprintf (server, sizeof(fstring)-1, "\\\\%s", cli->desthost);
891 /* Initialise input parameters */
893 init_buffer(&buffer, offered, mem_ctx);
895 prs_init(&qbuf, MAX_PDU_FRAG_LEN, mem_ctx, MARSHALL);
896 prs_init(&rbuf, 0, mem_ctx, UNMARSHALL);
898 /* Write the request */
900 make_spoolss_q_getprinterdriverdir(&q, server, env, level, &buffer,
903 /* Marshall data and send request */
905 if (!spoolss_io_q_getprinterdriverdir ("", &q, &qbuf, 0) ||
906 !rpc_api_pipe_req (cli, SPOOLSS_GETPRINTERDRIVERDIRECTORY,
910 /* Unmarshall response */
912 if (spoolss_io_r_getprinterdriverdir ("", &r, &rbuf, 0)) {
917 /* Return output parameters */
921 if (W_ERROR_IS_OK(result)) {
924 decode_printerdriverdir_1(mem_ctx, r.buffer, 1,
937 /*********************************************************************************
938 Win32 API - AddPrinterDriver()
939 ********************************************************************************/
940 /**********************************************************************
941 * Install a printer driver
943 WERROR cli_spoolss_addprinterdriver (struct cli_state *cli,
944 TALLOC_CTX *mem_ctx, uint32 level,
945 PRINTER_DRIVER_CTR *ctr)
947 prs_struct qbuf, rbuf;
948 SPOOL_Q_ADDPRINTERDRIVER q;
949 SPOOL_R_ADDPRINTERDRIVER r;
950 WERROR result = W_ERROR(ERRgeneral);
956 slprintf (server, sizeof(fstring)-1, "\\\\%s", cli->desthost);
959 /* Initialise input parameters */
961 prs_init(&qbuf, MAX_PDU_FRAG_LEN, mem_ctx, MARSHALL);
962 prs_init(&rbuf, 0, mem_ctx, UNMARSHALL);
964 /* Write the request */
966 make_spoolss_q_addprinterdriver (mem_ctx, &q, server, level, ctr);
968 /* Marshall data and send request */
970 if (!spoolss_io_q_addprinterdriver ("", &q, &qbuf, 0) ||
971 !rpc_api_pipe_req (cli, SPOOLSS_ADDPRINTERDRIVER, &qbuf, &rbuf))
974 /* Unmarshall response */
976 if (!spoolss_io_r_addprinterdriver ("", &r, &rbuf, 0))
979 /* Return output parameters */
990 /*********************************************************************************
991 Win32 API - AddPrinter()
992 ********************************************************************************/
993 /**********************************************************************
996 WERROR cli_spoolss_addprinterex (struct cli_state *cli, TALLOC_CTX *mem_ctx,
997 uint32 level, PRINTER_INFO_CTR*ctr)
999 prs_struct qbuf, rbuf;
1000 SPOOL_Q_ADDPRINTEREX q;
1001 SPOOL_R_ADDPRINTEREX r;
1002 WERROR result = W_ERROR(ERRgeneral);
1010 slprintf (client, sizeof(fstring)-1, "\\\\%s", cli->desthost);
1012 slprintf (server, sizeof(fstring)-1, "\\\\%s", cli->desthost);
1014 fstrcpy (user, cli->user_name);
1016 /* Initialise input parameters */
1018 prs_init(&qbuf, MAX_PDU_FRAG_LEN, mem_ctx, MARSHALL);
1019 prs_init(&rbuf, 0, mem_ctx, UNMARSHALL);
1021 /* Write the request */
1023 make_spoolss_q_addprinterex (mem_ctx, &q, server, client, user,
1026 /* Marshall data and send request */
1028 if (!spoolss_io_q_addprinterex ("", &q, &qbuf, 0) ||
1029 !rpc_api_pipe_req (cli, SPOOLSS_ADDPRINTEREX, &qbuf, &rbuf))
1032 /* Unmarshall response */
1034 if (!spoolss_io_r_addprinterex ("", &r, &rbuf, 0))
1037 /* Return output parameters */
1042 prs_mem_free(&qbuf);
1043 prs_mem_free(&rbuf);
1048 /*********************************************************************************
1049 Win32 API - DeltePrinterDriver()
1050 ********************************************************************************/
1051 /**********************************************************************
1052 * Delete a Printer Driver from the server (does not remove
1055 WERROR cli_spoolss_deleteprinterdriver (struct cli_state *cli,
1056 TALLOC_CTX *mem_ctx, char *arch,
1059 prs_struct qbuf, rbuf;
1060 SPOOL_Q_DELETEPRINTERDRIVER q;
1061 SPOOL_R_DELETEPRINTERDRIVER r;
1062 WERROR result = W_ERROR(ERRgeneral);
1069 /* Initialise input parameters */
1070 prs_init(&qbuf, MAX_PDU_FRAG_LEN, mem_ctx, MARSHALL);
1071 prs_init(&rbuf, 0, mem_ctx, UNMARSHALL);
1073 slprintf (server, sizeof(fstring)-1, "\\\\%s", cli->desthost);
1076 /* Write the request */
1078 make_spoolss_q_deleteprinterdriver(mem_ctx, &q, server, arch, driver);
1080 /* Marshall data and send request */
1082 if (!spoolss_io_q_deleteprinterdriver ("", &q, &qbuf, 0) ||
1083 !rpc_api_pipe_req (cli,SPOOLSS_DELETEPRINTERDRIVER , &qbuf, &rbuf))
1086 /* Unmarshall response */
1088 if (!spoolss_io_r_deleteprinterdriver ("", &r, &rbuf, 0))
1091 /* Return output parameters */
1096 prs_mem_free(&qbuf);
1097 prs_mem_free(&rbuf);
1102 /*********************************************************************************
1103 Win32 API - GetPrinterProcessorDirectory()
1104 ********************************************************************************/
1106 WERROR cli_spoolss_getprintprocessordirectory(struct cli_state *cli,
1107 TALLOC_CTX *mem_ctx,
1108 uint32 offered, uint32 *needed,
1109 char *name, char *environment,
1112 prs_struct qbuf, rbuf;
1113 SPOOL_Q_GETPRINTPROCESSORDIRECTORY q;
1114 SPOOL_R_GETPRINTPROCESSORDIRECTORY r;
1116 WERROR result = W_ERROR(ERRgeneral);
1122 /* Initialise parse structures */
1124 prs_init(&qbuf, MAX_PDU_FRAG_LEN, mem_ctx, MARSHALL);
1125 prs_init(&rbuf, 0, mem_ctx, UNMARSHALL);
1127 /* Initialise input parameters */
1129 init_buffer(&buffer, offered, mem_ctx);
1131 make_spoolss_q_getprintprocessordirectory(
1132 &q, name, environment, level, &buffer, offered);
1134 /* Marshall data and send request */
1136 if (!spoolss_io_q_getprintprocessordirectory("", &q, &qbuf, 0) ||
1137 !rpc_api_pipe_req(cli, SPOOLSS_GETPRINTPROCESSORDIRECTORY,
1141 /* Unmarshall response */
1143 if (!spoolss_io_r_getprintprocessordirectory("", &r, &rbuf, 0))
1146 /* Return output parameters */
1153 if (W_ERROR_IS_OK(result))
1154 fstrcpy(procdir, "Not implemented!");
1157 prs_mem_free(&qbuf);
1158 prs_mem_free(&rbuf);
1163 /** Add a form to a printer.
1165 * @param cli Pointer to client state structure which is open
1166 * on the SPOOLSS pipe.
1167 * @param mem_ctx Pointer to an initialised talloc context.
1169 * @param handle Policy handle opened with cli_spoolss_open_printer_ex
1170 * or cli_spoolss_addprinterex.
1171 * @param level Form info level to add - should always be 1.
1172 * @param form A pointer to the form to be added.
1176 WERROR cli_spoolss_addform(struct cli_state *cli, TALLOC_CTX *mem_ctx,
1177 POLICY_HND *handle, uint32 level, FORM *form)
1179 prs_struct qbuf, rbuf;
1182 WERROR result = W_ERROR(ERRgeneral);
1187 /* Initialise parse structures */
1189 prs_init(&qbuf, MAX_PDU_FRAG_LEN, mem_ctx, MARSHALL);
1190 prs_init(&rbuf, 0, mem_ctx, UNMARSHALL);
1192 /* Initialise input parameters */
1194 make_spoolss_q_addform(&q, handle, level, form);
1196 /* Marshall data and send request */
1198 if (!spoolss_io_q_addform("", &q, &qbuf, 0) ||
1199 !rpc_api_pipe_req(cli, SPOOLSS_ADDFORM, &qbuf, &rbuf))
1202 /* Unmarshall response */
1204 if (!spoolss_io_r_addform("", &r, &rbuf, 0))
1207 /* Return output parameters */
1212 prs_mem_free(&qbuf);
1213 prs_mem_free(&rbuf);
1218 /** Set a form on a printer.
1220 * @param cli Pointer to client state structure which is open
1221 * on the SPOOLSS pipe.
1222 * @param mem_ctx Pointer to an initialised talloc context.
1224 * @param handle Policy handle opened with cli_spoolss_open_printer_ex
1225 * or cli_spoolss_addprinterex.
1226 * @param level Form info level to set - should always be 1.
1227 * @param form A pointer to the form to be set.
1231 WERROR cli_spoolss_setform(struct cli_state *cli, TALLOC_CTX *mem_ctx,
1232 POLICY_HND *handle, uint32 level, char *form_name,
1235 prs_struct qbuf, rbuf;
1238 WERROR result = W_ERROR(ERRgeneral);
1243 /* Initialise parse structures */
1245 prs_init(&qbuf, MAX_PDU_FRAG_LEN, mem_ctx, MARSHALL);
1246 prs_init(&rbuf, 0, mem_ctx, UNMARSHALL);
1248 /* Initialise input parameters */
1250 make_spoolss_q_setform(&q, handle, level, form_name, form);
1252 /* Marshall data and send request */
1254 if (!spoolss_io_q_setform("", &q, &qbuf, 0) ||
1255 !rpc_api_pipe_req(cli, SPOOLSS_SETFORM, &qbuf, &rbuf))
1258 /* Unmarshall response */
1260 if (!spoolss_io_r_setform("", &r, &rbuf, 0))
1263 /* Return output parameters */
1267 if (!W_ERROR_IS_OK(result))
1273 prs_mem_free(&qbuf);
1274 prs_mem_free(&rbuf);
1279 /** Get a form on a printer.
1281 * @param cli Pointer to client state structure which is open
1282 * on the SPOOLSS pipe.
1283 * @param mem_ctx Pointer to an initialised talloc context.
1285 * @param handle Policy handle opened with cli_spoolss_open_printer_ex
1286 * or cli_spoolss_addprinterex.
1287 * @param formname Name of the form to get
1288 * @param level Form info level to get - should always be 1.
1292 WERROR cli_spoolss_getform(struct cli_state *cli, TALLOC_CTX *mem_ctx,
1293 uint32 offered, uint32 *needed,
1294 POLICY_HND *handle, char *formname, uint32 level,
1297 prs_struct qbuf, rbuf;
1300 WERROR result = W_ERROR(ERRgeneral);
1306 /* Initialise parse structures */
1308 init_buffer(&buffer, offered, mem_ctx);
1310 prs_init(&qbuf, MAX_PDU_FRAG_LEN, mem_ctx, MARSHALL);
1311 prs_init(&rbuf, 0, mem_ctx, UNMARSHALL);
1313 /* Initialise input parameters */
1315 make_spoolss_q_getform(&q, handle, formname, level, &buffer, offered);
1317 /* Marshall data and send request */
1319 if (!spoolss_io_q_getform("", &q, &qbuf, 0) ||
1320 !rpc_api_pipe_req(cli, SPOOLSS_GETFORM, &qbuf, &rbuf))
1323 /* Unmarshall response */
1325 if (!spoolss_io_r_getform("", &r, &rbuf, 0))
1328 /* Return output parameters */
1335 if (W_ERROR_IS_OK(result))
1336 smb_io_form_1("", r.buffer, form, 0);
1339 prs_mem_free(&qbuf);
1340 prs_mem_free(&rbuf);
1345 /** Delete a form on a printer.
1347 * @param cli Pointer to client state structure which is open
1348 * on the SPOOLSS pipe.
1349 * @param mem_ctx Pointer to an initialised talloc context.
1351 * @param handle Policy handle opened with cli_spoolss_open_printer_ex
1352 * or cli_spoolss_addprinterex.
1353 * @param form The name of the form to delete.
1357 WERROR cli_spoolss_deleteform(struct cli_state *cli, TALLOC_CTX *mem_ctx,
1358 POLICY_HND *handle, char *form_name)
1360 prs_struct qbuf, rbuf;
1361 SPOOL_Q_DELETEFORM q;
1362 SPOOL_R_DELETEFORM r;
1363 WERROR result = W_ERROR(ERRgeneral);
1368 /* Initialise parse structures */
1370 prs_init(&qbuf, MAX_PDU_FRAG_LEN, mem_ctx, MARSHALL);
1371 prs_init(&rbuf, 0, mem_ctx, UNMARSHALL);
1373 /* Initialise input parameters */
1375 make_spoolss_q_deleteform(&q, handle, form_name);
1377 /* Marshall data and send request */
1379 if (!spoolss_io_q_deleteform("", &q, &qbuf, 0) ||
1380 !rpc_api_pipe_req(cli, SPOOLSS_DELETEFORM, &qbuf, &rbuf))
1383 /* Unmarshall response */
1385 if (!spoolss_io_r_deleteform("", &r, &rbuf, 0))
1388 /* Return output parameters */
1393 prs_mem_free(&qbuf);
1394 prs_mem_free(&rbuf);
1399 static void decode_forms_1(TALLOC_CTX *mem_ctx, NEW_BUFFER *buffer,
1400 uint32 num_forms, FORM_1 **forms)
1404 *forms = (FORM_1 *)talloc(mem_ctx, num_forms * sizeof(FORM_1));
1405 buffer->prs.data_offset = 0;
1407 for (i = 0; i < num_forms; i++)
1408 smb_io_form_1("", buffer, &((*forms)[i]), 0);
1413 * @param cli Pointer to client state structure which is open
1414 * on the SPOOLSS pipe.
1415 * @param mem_ctx Pointer to an initialised talloc context.
1417 * @param offered Buffer size offered in the request.
1418 * @param needed Number of bytes needed to complete the request.
1420 * or cli_spoolss_addprinterex.
1421 * @param level Form info level to get - should always be 1.
1422 * @param handle Open policy handle
1426 WERROR cli_spoolss_enumforms(struct cli_state *cli, TALLOC_CTX *mem_ctx,
1427 uint32 offered, uint32 *needed,
1428 POLICY_HND *handle, int level, uint32 *num_forms,
1431 prs_struct qbuf, rbuf;
1432 SPOOL_Q_ENUMFORMS q;
1433 SPOOL_R_ENUMFORMS r;
1434 WERROR result = W_ERROR(ERRgeneral);
1440 /* Initialise parse structures */
1442 init_buffer(&buffer, offered, mem_ctx);
1444 prs_init(&qbuf, MAX_PDU_FRAG_LEN, mem_ctx, MARSHALL);
1445 prs_init(&rbuf, 0, mem_ctx, UNMARSHALL);
1447 /* Initialise input parameters */
1449 make_spoolss_q_enumforms(&q, handle, level, &buffer, offered);
1451 /* Marshall data and send request */
1453 if (!spoolss_io_q_enumforms("", &q, &qbuf, 0) ||
1454 !rpc_api_pipe_req(cli, SPOOLSS_ENUMFORMS, &qbuf, &rbuf))
1457 /* Unmarshall response */
1459 if (!spoolss_io_r_enumforms("", &r, &rbuf, 0))
1462 /* Return output parameters */
1470 *num_forms = r.numofforms;
1472 decode_forms_1(mem_ctx, r.buffer, *num_forms, forms);
1475 prs_mem_free(&qbuf);
1476 prs_mem_free(&rbuf);
1481 static void decode_jobs_1(TALLOC_CTX *mem_ctx, NEW_BUFFER *buffer,
1482 uint32 num_jobs, JOB_INFO_1 **jobs)
1486 *jobs = (JOB_INFO_1 *)talloc(mem_ctx, num_jobs * sizeof(JOB_INFO_1));
1487 buffer->prs.data_offset = 0;
1489 for (i = 0; i < num_jobs; i++)
1490 smb_io_job_info_1("", buffer, &((*jobs)[i]), 0);
1493 static void decode_jobs_2(TALLOC_CTX *mem_ctx, NEW_BUFFER *buffer,
1494 uint32 num_jobs, JOB_INFO_2 **jobs)
1498 *jobs = (JOB_INFO_2 *)talloc(mem_ctx, num_jobs * sizeof(JOB_INFO_2));
1499 buffer->prs.data_offset = 0;
1501 for (i = 0; i < num_jobs; i++)
1502 smb_io_job_info_2("", buffer, &((*jobs)[i]), 0);
1505 /* Enumerate jobs */
1507 WERROR cli_spoolss_enumjobs(struct cli_state *cli, TALLOC_CTX *mem_ctx,
1508 uint32 offered, uint32 *needed,
1509 POLICY_HND *hnd, uint32 level, uint32 firstjob,
1510 uint32 num_jobs, uint32 *returned, JOB_INFO_CTR *ctr)
1512 prs_struct qbuf, rbuf;
1515 WERROR result = W_ERROR(ERRgeneral);
1521 /* Initialise parse structures */
1523 init_buffer(&buffer, offered, mem_ctx);
1525 prs_init(&qbuf, MAX_PDU_FRAG_LEN, mem_ctx, MARSHALL);
1526 prs_init(&rbuf, 0, mem_ctx, UNMARSHALL);
1528 /* Initialise input parameters */
1530 make_spoolss_q_enumjobs(&q, hnd, firstjob, num_jobs, level, &buffer,
1533 /* Marshall data and send request */
1535 if (!spoolss_io_q_enumjobs("", &q, &qbuf, 0) ||
1536 !rpc_api_pipe_req(cli, SPOOLSS_ENUMJOBS, &qbuf, &rbuf))
1539 /* Unmarshall response */
1541 if (!spoolss_io_r_enumjobs("", &r, &rbuf, 0))
1544 /* Return output parameters */
1551 if (!W_ERROR_IS_OK(r.status))
1554 *returned = r.returned;
1558 decode_jobs_1(mem_ctx, r.buffer, r.returned,
1559 &ctr->job.job_info_1);
1562 decode_jobs_2(mem_ctx, r.buffer, r.returned,
1563 &ctr->job.job_info_2);
1566 DEBUG(3, ("unsupported info level %d", level));
1571 prs_mem_free(&qbuf);
1572 prs_mem_free(&rbuf);
1579 WERROR cli_spoolss_setjob(struct cli_state *cli, TALLOC_CTX *mem_ctx,
1580 POLICY_HND *hnd, uint32 jobid, uint32 level,
1583 prs_struct qbuf, rbuf;
1586 WERROR result = W_ERROR(ERRgeneral);
1591 /* Initialise parse structures */
1593 prs_init(&qbuf, MAX_PDU_FRAG_LEN, mem_ctx, MARSHALL);
1594 prs_init(&rbuf, 0, mem_ctx, UNMARSHALL);
1596 /* Initialise input parameters */
1598 make_spoolss_q_setjob(&q, hnd, jobid, level, command);
1600 /* Marshall data and send request */
1602 if (!spoolss_io_q_setjob("", &q, &qbuf, 0) ||
1603 !rpc_api_pipe_req(cli, SPOOLSS_SETJOB, &qbuf, &rbuf))
1606 /* Unmarshall response */
1608 if (!spoolss_io_r_setjob("", &r, &rbuf, 0))
1611 /* Return output parameters */
1616 prs_mem_free(&qbuf);
1617 prs_mem_free(&rbuf);
1624 WERROR cli_spoolss_getjob(struct cli_state *cli, TALLOC_CTX *mem_ctx,
1625 uint32 offered, uint32 *needed,
1626 POLICY_HND *hnd, uint32 jobid, uint32 level,
1629 prs_struct qbuf, rbuf;
1632 WERROR result = W_ERROR(ERRgeneral);
1638 /* Initialise parse structures */
1640 init_buffer(&buffer, offered, mem_ctx);
1642 prs_init(&qbuf, MAX_PDU_FRAG_LEN, mem_ctx, MARSHALL);
1643 prs_init(&rbuf, 0, mem_ctx, UNMARSHALL);
1645 /* Initialise input parameters */
1647 make_spoolss_q_getjob(&q, hnd, jobid, level, &buffer, offered);
1649 /* Marshall data and send request */
1651 if (!spoolss_io_q_getjob("", &q, &qbuf, 0) ||
1652 !rpc_api_pipe_req(cli, SPOOLSS_GETJOB, &qbuf, &rbuf))
1655 /* Unmarshall response */
1657 if (!spoolss_io_r_getjob("", &r, &rbuf, 0))
1660 /* Return output parameters */
1667 if (!W_ERROR_IS_OK(r.status))
1672 decode_jobs_1(mem_ctx, r.buffer, 1, &ctr->job.job_info_1);
1675 decode_jobs_2(mem_ctx, r.buffer, 1, &ctr->job.job_info_2);
1678 DEBUG(3, ("unsupported info level %d", level));
1683 prs_mem_free(&qbuf);
1684 prs_mem_free(&rbuf);
1689 /* Startpageprinter. Sent to notify the spooler when a page is about to be
1690 sent to a printer. */
1692 WERROR cli_spoolss_startpageprinter(struct cli_state *cli, TALLOC_CTX *mem_ctx,
1695 prs_struct qbuf, rbuf;
1696 SPOOL_Q_STARTPAGEPRINTER q;
1697 SPOOL_R_STARTPAGEPRINTER r;
1698 WERROR result = W_ERROR(ERRgeneral);
1703 /* Initialise parse structures */
1705 prs_init(&qbuf, MAX_PDU_FRAG_LEN, mem_ctx, MARSHALL);
1706 prs_init(&rbuf, 0, mem_ctx, UNMARSHALL);
1708 /* Initialise input parameters */
1710 make_spoolss_q_startpageprinter(&q, hnd);
1712 /* Marshall data and send request */
1714 if (!spoolss_io_q_startpageprinter("", &q, &qbuf, 0) ||
1715 !rpc_api_pipe_req(cli, SPOOLSS_STARTPAGEPRINTER, &qbuf, &rbuf))
1718 /* Unmarshall response */
1720 if (!spoolss_io_r_startpageprinter("", &r, &rbuf, 0))
1723 /* Return output parameters */
1728 prs_mem_free(&qbuf);
1729 prs_mem_free(&rbuf);
1734 /* Endpageprinter. Sent to notify the spooler when a page has finished
1735 being sent to a printer. */
1737 WERROR cli_spoolss_endpageprinter(struct cli_state *cli, TALLOC_CTX *mem_ctx,
1740 prs_struct qbuf, rbuf;
1741 SPOOL_Q_ENDPAGEPRINTER q;
1742 SPOOL_R_ENDPAGEPRINTER r;
1743 WERROR result = W_ERROR(ERRgeneral);
1748 /* Initialise parse structures */
1750 prs_init(&qbuf, MAX_PDU_FRAG_LEN, mem_ctx, MARSHALL);
1751 prs_init(&rbuf, 0, mem_ctx, UNMARSHALL);
1753 /* Initialise input parameters */
1755 make_spoolss_q_endpageprinter(&q, hnd);
1757 /* Marshall data and send request */
1759 if (!spoolss_io_q_endpageprinter("", &q, &qbuf, 0) ||
1760 !rpc_api_pipe_req(cli, SPOOLSS_ENDPAGEPRINTER, &qbuf, &rbuf))
1763 /* Unmarshall response */
1765 if (!spoolss_io_r_endpageprinter("", &r, &rbuf, 0))
1768 /* Return output parameters */
1773 prs_mem_free(&qbuf);
1774 prs_mem_free(&rbuf);
1779 /* Startdocprinter. Sent to notify the spooler that a document is about
1780 to be spooled for printing. */
1782 WERROR cli_spoolss_startdocprinter(struct cli_state *cli, TALLOC_CTX *mem_ctx,
1783 POLICY_HND *hnd, char *docname,
1784 char *outputfile, char *datatype,
1787 prs_struct qbuf, rbuf;
1788 SPOOL_Q_STARTDOCPRINTER q;
1789 SPOOL_R_STARTDOCPRINTER r;
1790 WERROR result = W_ERROR(ERRgeneral);
1796 /* Initialise parse structures */
1798 prs_init(&qbuf, MAX_PDU_FRAG_LEN, mem_ctx, MARSHALL);
1799 prs_init(&rbuf, 0, mem_ctx, UNMARSHALL);
1801 /* Initialise input parameters */
1803 make_spoolss_q_startdocprinter(&q, hnd, level, docname, outputfile,
1806 /* Marshall data and send request */
1808 if (!spoolss_io_q_startdocprinter("", &q, &qbuf, 0) ||
1809 !rpc_api_pipe_req(cli, SPOOLSS_STARTDOCPRINTER, &qbuf, &rbuf))
1812 /* Unmarshall response */
1814 if (!spoolss_io_r_startdocprinter("", &r, &rbuf, 0))
1817 /* Return output parameters */
1821 if (W_ERROR_IS_OK(result))
1825 prs_mem_free(&qbuf);
1826 prs_mem_free(&rbuf);
1831 /* Enddocprinter. Sent to notify the spooler that a document has finished
1834 WERROR cli_spoolss_enddocprinter(struct cli_state *cli, TALLOC_CTX *mem_ctx,
1837 prs_struct qbuf, rbuf;
1838 SPOOL_Q_ENDDOCPRINTER q;
1839 SPOOL_R_ENDDOCPRINTER r;
1840 WERROR result = W_ERROR(ERRgeneral);
1845 /* Initialise parse structures */
1847 prs_init(&qbuf, MAX_PDU_FRAG_LEN, mem_ctx, MARSHALL);
1848 prs_init(&rbuf, 0, mem_ctx, UNMARSHALL);
1850 /* Initialise input parameters */
1852 make_spoolss_q_enddocprinter(&q, hnd);
1854 /* Marshall data and send request */
1856 if (!spoolss_io_q_enddocprinter("", &q, &qbuf, 0) ||
1857 !rpc_api_pipe_req(cli, SPOOLSS_ENDDOCPRINTER, &qbuf, &rbuf))
1860 /* Unmarshall response */
1862 if (!spoolss_io_r_enddocprinter("", &r, &rbuf, 0))
1865 /* Return output parameters */
1870 prs_mem_free(&qbuf);
1871 prs_mem_free(&rbuf);
1876 /* Get printer data */
1878 WERROR cli_spoolss_getprinterdata(struct cli_state *cli, TALLOC_CTX *mem_ctx,
1879 uint32 offered, uint32 *needed,
1880 POLICY_HND *hnd, char *valuename,
1881 REGISTRY_VALUE *value)
1883 prs_struct qbuf, rbuf;
1884 SPOOL_Q_GETPRINTERDATA q;
1885 SPOOL_R_GETPRINTERDATA r;
1886 WERROR result = W_ERROR(ERRgeneral);
1891 /* Initialise parse structures */
1893 prs_init(&qbuf, MAX_PDU_FRAG_LEN, mem_ctx, MARSHALL);
1894 prs_init(&rbuf, 0, mem_ctx, UNMARSHALL);
1896 /* Initialise input parameters */
1898 make_spoolss_q_getprinterdata(&q, hnd, valuename, offered);
1900 /* Marshall data and send request */
1902 if (!spoolss_io_q_getprinterdata("", &q, &qbuf, 0) ||
1903 !rpc_api_pipe_req(cli, SPOOLSS_GETPRINTERDATA, &qbuf, &rbuf))
1906 /* Unmarshall response */
1908 if (!spoolss_io_r_getprinterdata("", &r, &rbuf, 0))
1916 if (!W_ERROR_IS_OK(r.status))
1919 /* Return output parameters */
1921 value->data_p = talloc_memdup(mem_ctx, r.data, r.needed);
1922 value->type = r.type;
1923 value->size = r.size;
1926 prs_mem_free(&qbuf);
1927 prs_mem_free(&rbuf);
1932 WERROR cli_spoolss_getprinterdataex(struct cli_state *cli, TALLOC_CTX *mem_ctx,
1933 uint32 offered, uint32 *needed,
1934 POLICY_HND *hnd, char *keyname,
1935 char *valuename, REGISTRY_VALUE *value)
1937 prs_struct qbuf, rbuf;
1938 SPOOL_Q_GETPRINTERDATAEX q;
1939 SPOOL_R_GETPRINTERDATAEX r;
1940 WERROR result = W_ERROR(ERRgeneral);
1945 /* Initialise parse structures */
1947 prs_init(&qbuf, MAX_PDU_FRAG_LEN, mem_ctx, MARSHALL);
1948 prs_init(&rbuf, 0, mem_ctx, UNMARSHALL);
1950 /* Initialise input parameters */
1952 make_spoolss_q_getprinterdataex(&q, hnd, keyname, valuename, offered);
1954 /* Marshall data and send request */
1956 if (!spoolss_io_q_getprinterdataex("", &q, &qbuf, 0) ||
1957 !rpc_api_pipe_req(cli, SPOOLSS_GETPRINTERDATAEX, &qbuf, &rbuf))
1960 /* Unmarshall response */
1962 if (!spoolss_io_r_getprinterdataex("", &r, &rbuf, 0))
1970 if (!W_ERROR_IS_OK(r.status))
1973 /* Return output parameters */
1975 value->data_p = talloc_memdup(mem_ctx, r.data, r.needed);
1976 value->type = r.type;
1977 value->size = r.needed;
1980 prs_mem_free(&qbuf);
1981 prs_mem_free(&rbuf);
1986 /* Set printer data */
1988 WERROR cli_spoolss_setprinterdata(struct cli_state *cli, TALLOC_CTX *mem_ctx,
1989 POLICY_HND *hnd, REGISTRY_VALUE *value)
1991 prs_struct qbuf, rbuf;
1992 SPOOL_Q_SETPRINTERDATA q;
1993 SPOOL_R_SETPRINTERDATA r;
1994 WERROR result = W_ERROR(ERRgeneral);
1999 /* Initialise parse structures */
2001 prs_init(&qbuf, MAX_PDU_FRAG_LEN, mem_ctx, MARSHALL);
2002 prs_init(&rbuf, 0, mem_ctx, UNMARSHALL);
2004 /* Initialise input parameters */
2006 make_spoolss_q_setprinterdata(
2007 &q, hnd, value->valuename, value->type, value->data_p, value->size);
2009 /* Marshall data and send request */
2011 if (!spoolss_io_q_setprinterdata("", &q, &qbuf, 0) ||
2012 !rpc_api_pipe_req(cli, SPOOLSS_SETPRINTERDATA, &qbuf, &rbuf))
2015 /* Unmarshall response */
2017 if (!spoolss_io_r_setprinterdata("", &r, &rbuf, 0))
2022 if (!W_ERROR_IS_OK(r.status))
2026 prs_mem_free(&qbuf);
2027 prs_mem_free(&rbuf);
2032 WERROR cli_spoolss_setprinterdataex(struct cli_state *cli, TALLOC_CTX *mem_ctx,
2033 POLICY_HND *hnd, char *keyname,
2034 REGISTRY_VALUE *value)
2036 prs_struct qbuf, rbuf;
2037 SPOOL_Q_SETPRINTERDATAEX q;
2038 SPOOL_R_SETPRINTERDATAEX r;
2039 WERROR result = W_ERROR(ERRgeneral);
2044 /* Initialise parse structures */
2046 prs_init(&qbuf, MAX_PDU_FRAG_LEN, mem_ctx, MARSHALL);
2047 prs_init(&rbuf, 0, mem_ctx, UNMARSHALL);
2049 /* Initialise input parameters */
2051 make_spoolss_q_setprinterdataex(
2052 &q, hnd, keyname, value->valuename, value->type, value->data_p,
2055 /* Marshall data and send request */
2057 if (!spoolss_io_q_setprinterdataex("", &q, &qbuf, 0) ||
2058 !rpc_api_pipe_req(cli, SPOOLSS_SETPRINTERDATAEX, &qbuf, &rbuf))
2061 /* Unmarshall response */
2063 if (!spoolss_io_r_setprinterdataex("", &r, &rbuf, 0))
2068 if (!W_ERROR_IS_OK(r.status))
2072 prs_mem_free(&qbuf);
2073 prs_mem_free(&rbuf);
2078 /* Enum printer data */
2080 WERROR cli_spoolss_enumprinterdata(struct cli_state *cli, TALLOC_CTX *mem_ctx,
2081 POLICY_HND *hnd, uint32 ndx,
2082 uint32 value_offered, uint32 data_offered,
2083 uint32 *value_needed, uint32 *data_needed,
2084 REGISTRY_VALUE *value)
2086 prs_struct qbuf, rbuf;
2087 SPOOL_Q_ENUMPRINTERDATA q;
2088 SPOOL_R_ENUMPRINTERDATA r;
2089 WERROR result = W_ERROR(ERRgeneral);
2094 /* Initialise parse structures */
2096 prs_init(&qbuf, MAX_PDU_FRAG_LEN, mem_ctx, MARSHALL);
2097 prs_init(&rbuf, 0, mem_ctx, UNMARSHALL);
2099 /* Initialise input parameters */
2101 make_spoolss_q_enumprinterdata(&q, hnd, ndx, value_offered, data_offered);
2103 /* Marshall data and send request */
2105 if (!spoolss_io_q_enumprinterdata("", &q, &qbuf, 0) ||
2106 !rpc_api_pipe_req(cli, SPOOLSS_ENUMPRINTERDATA, &qbuf, &rbuf))
2109 /* Unmarshall response */
2111 if (!spoolss_io_r_enumprinterdata("", &r, &rbuf, 0))
2116 if (!W_ERROR_IS_OK(r.status))
2122 *value_needed = r.realvaluesize;
2125 *data_needed = r.realdatasize;
2128 rpcstr_pull(value->valuename, r.value, sizeof(value->valuename), -1,
2130 value->data_p = talloc_memdup(mem_ctx, r.data, r.realdatasize);
2131 value->type = r.type;
2132 value->size = r.realdatasize;
2136 prs_mem_free(&qbuf);
2137 prs_mem_free(&rbuf);
2142 WERROR cli_spoolss_enumprinterdataex(struct cli_state *cli, TALLOC_CTX *mem_ctx,
2143 uint32 offered, uint32 *needed,
2144 POLICY_HND *hnd, char *keyname,
2147 prs_struct qbuf, rbuf;
2148 SPOOL_Q_ENUMPRINTERDATAEX q;
2149 SPOOL_R_ENUMPRINTERDATAEX r;
2150 WERROR result = W_ERROR(ERRgeneral);
2156 /* Initialise parse structures */
2158 prs_init(&qbuf, MAX_PDU_FRAG_LEN, mem_ctx, MARSHALL);
2159 prs_init(&rbuf, 0, mem_ctx, UNMARSHALL);
2161 /* Initialise input parameters */
2163 make_spoolss_q_enumprinterdataex(&q, hnd, keyname, offered);
2165 /* Marshall data and send request */
2167 if (!spoolss_io_q_enumprinterdataex("", &q, &qbuf, 0) ||
2168 !rpc_api_pipe_req(cli, SPOOLSS_ENUMPRINTERDATAEX, &qbuf, &rbuf))
2171 /* Unmarshall response */
2173 if (!spoolss_io_r_enumprinterdataex("", &r, &rbuf, 0))
2181 if (!W_ERROR_IS_OK(r.status))
2187 regval_ctr_init(ctr);
2189 for (i = 0; i < r.returned; i++) {
2190 PRINTER_ENUM_VALUES *v = &r.ctr.values[i];
2193 rpcstr_pull(name, v->valuename.buffer, sizeof(name), -1,
2195 regval_ctr_addvalue(ctr, name, v->type, v->data, v->data_len);
2199 prs_mem_free(&qbuf);
2200 prs_mem_free(&rbuf);
2205 /* Write data to printer */
2207 WERROR cli_spoolss_writeprinter(struct cli_state *cli, TALLOC_CTX *mem_ctx,
2208 POLICY_HND *hnd, uint32 data_size, char *data,
2209 uint32 *num_written)
2211 prs_struct qbuf, rbuf;
2212 SPOOL_Q_WRITEPRINTER q;
2213 SPOOL_R_WRITEPRINTER r;
2214 WERROR result = W_ERROR(ERRgeneral);
2219 /* Initialise parse structures */
2221 prs_init(&qbuf, MAX_PDU_FRAG_LEN, mem_ctx, MARSHALL);
2222 prs_init(&rbuf, 0, mem_ctx, UNMARSHALL);
2224 /* Initialise input parameters */
2226 make_spoolss_q_writeprinter(&q, hnd, data_size, data);
2228 /* Marshall data and send request */
2230 if (!spoolss_io_q_writeprinter("", &q, &qbuf, 0) ||
2231 !rpc_api_pipe_req(cli, SPOOLSS_WRITEPRINTER, &qbuf, &rbuf))
2234 /* Unmarshall response */
2236 if (!spoolss_io_r_writeprinter("", &r, &rbuf, 0))
2241 if (!W_ERROR_IS_OK(r.status))
2245 *num_written = r.buffer_written;
2248 prs_mem_free(&qbuf);
2249 prs_mem_free(&rbuf);
2254 /* Delete printer data */
2256 WERROR cli_spoolss_deleteprinterdata(struct cli_state *cli, TALLOC_CTX *mem_ctx,
2257 POLICY_HND *hnd, char *valuename)
2259 prs_struct qbuf, rbuf;
2260 SPOOL_Q_DELETEPRINTERDATA q;
2261 SPOOL_R_DELETEPRINTERDATA r;
2262 WERROR result = W_ERROR(ERRgeneral);
2267 /* Initialise parse structures */
2269 prs_init(&qbuf, MAX_PDU_FRAG_LEN, mem_ctx, MARSHALL);
2270 prs_init(&rbuf, 0, mem_ctx, UNMARSHALL);
2272 /* Initialise input parameters */
2274 make_spoolss_q_deleteprinterdata(&q, hnd, valuename);
2276 /* Marshall data and send request */
2278 if (!spoolss_io_q_deleteprinterdata("", &q, &qbuf, 0) ||
2279 !rpc_api_pipe_req(cli, SPOOLSS_DELETEPRINTERDATA, &qbuf, &rbuf))
2282 /* Unmarshall response */
2284 if (!spoolss_io_r_deleteprinterdata("", &r, &rbuf, 0))
2289 if (!W_ERROR_IS_OK(r.status))
2293 prs_mem_free(&qbuf);
2294 prs_mem_free(&rbuf);
2299 WERROR cli_spoolss_deleteprinterdataex(struct cli_state *cli, TALLOC_CTX *mem_ctx,
2300 POLICY_HND *hnd, char *keyname,
2303 prs_struct qbuf, rbuf;
2304 SPOOL_Q_DELETEPRINTERDATAEX q;
2305 SPOOL_R_DELETEPRINTERDATAEX r;
2306 WERROR result = W_ERROR(ERRgeneral);
2311 /* Initialise parse structures */
2313 prs_init(&qbuf, MAX_PDU_FRAG_LEN, mem_ctx, MARSHALL);
2314 prs_init(&rbuf, 0, mem_ctx, UNMARSHALL);
2316 /* Initialise input parameters */
2318 make_spoolss_q_deleteprinterdataex(&q, hnd, keyname, valuename);
2320 /* Marshall data and send request */
2322 if (!spoolss_io_q_deleteprinterdataex("", &q, &qbuf, 0) ||
2323 !rpc_api_pipe_req(cli, SPOOLSS_DELETEPRINTERDATAEX, &qbuf, &rbuf))
2326 /* Unmarshall response */
2328 if (!spoolss_io_r_deleteprinterdataex("", &r, &rbuf, 0))
2333 if (!W_ERROR_IS_OK(r.status))
2337 prs_mem_free(&qbuf);
2338 prs_mem_free(&rbuf);