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);
862 /*********************************************************************************
863 Win32 API - GetPrinterDriverDirectory()
864 ********************************************************************************/
865 /**********************************************************************
866 * Get installed printer drivers for a given printer
868 WERROR cli_spoolss_getprinterdriverdir (struct cli_state *cli,
870 uint32 offered, uint32 *needed,
871 uint32 level, char *env,
872 DRIVER_DIRECTORY_CTR *ctr)
874 prs_struct qbuf, rbuf;
875 SPOOL_Q_GETPRINTERDRIVERDIR q;
876 SPOOL_R_GETPRINTERDRIVERDIR r;
878 WERROR result = W_ERROR(ERRgeneral);
884 slprintf (server, sizeof(fstring)-1, "\\\\%s", cli->desthost);
887 /* Initialise input parameters */
889 init_buffer(&buffer, offered, mem_ctx);
891 prs_init(&qbuf, MAX_PDU_FRAG_LEN, mem_ctx, MARSHALL);
892 prs_init(&rbuf, 0, mem_ctx, UNMARSHALL);
894 /* Write the request */
896 make_spoolss_q_getprinterdriverdir(&q, server, env, level, &buffer,
899 /* Marshall data and send request */
901 if (!spoolss_io_q_getprinterdriverdir ("", &q, &qbuf, 0) ||
902 !rpc_api_pipe_req (cli, SPOOLSS_GETPRINTERDRIVERDIRECTORY,
906 /* Unmarshall response */
908 if (spoolss_io_r_getprinterdriverdir ("", &r, &rbuf, 0)) {
913 /* Return output parameters */
917 if (W_ERROR_IS_OK(result)) {
920 decode_printerdriverdir_1(mem_ctx, r.buffer, 1,
933 /*********************************************************************************
934 Win32 API - AddPrinterDriver()
935 ********************************************************************************/
936 /**********************************************************************
937 * Install a printer driver
939 WERROR cli_spoolss_addprinterdriver (struct cli_state *cli,
940 TALLOC_CTX *mem_ctx, uint32 level,
941 PRINTER_DRIVER_CTR *ctr)
943 prs_struct qbuf, rbuf;
944 SPOOL_Q_ADDPRINTERDRIVER q;
945 SPOOL_R_ADDPRINTERDRIVER r;
946 WERROR result = W_ERROR(ERRgeneral);
952 slprintf (server, sizeof(fstring)-1, "\\\\%s", cli->desthost);
955 /* Initialise input parameters */
957 prs_init(&qbuf, MAX_PDU_FRAG_LEN, mem_ctx, MARSHALL);
958 prs_init(&rbuf, 0, mem_ctx, UNMARSHALL);
960 /* Write the request */
962 make_spoolss_q_addprinterdriver (mem_ctx, &q, server, level, ctr);
964 /* Marshall data and send request */
966 if (!spoolss_io_q_addprinterdriver ("", &q, &qbuf, 0) ||
967 !rpc_api_pipe_req (cli, SPOOLSS_ADDPRINTERDRIVER, &qbuf, &rbuf))
970 /* Unmarshall response */
972 if (!spoolss_io_r_addprinterdriver ("", &r, &rbuf, 0))
975 /* Return output parameters */
986 /*********************************************************************************
987 Win32 API - AddPrinter()
988 ********************************************************************************/
989 /**********************************************************************
992 WERROR cli_spoolss_addprinterex (struct cli_state *cli, TALLOC_CTX *mem_ctx,
993 uint32 level, PRINTER_INFO_CTR*ctr)
995 prs_struct qbuf, rbuf;
996 SPOOL_Q_ADDPRINTEREX q;
997 SPOOL_R_ADDPRINTEREX r;
998 WERROR result = W_ERROR(ERRgeneral);
1006 slprintf (client, sizeof(fstring)-1, "\\\\%s", cli->desthost);
1008 slprintf (server, sizeof(fstring)-1, "\\\\%s", cli->desthost);
1010 fstrcpy (user, cli->user_name);
1012 /* Initialise input parameters */
1014 prs_init(&qbuf, MAX_PDU_FRAG_LEN, mem_ctx, MARSHALL);
1015 prs_init(&rbuf, 0, mem_ctx, UNMARSHALL);
1017 /* Write the request */
1019 make_spoolss_q_addprinterex (mem_ctx, &q, server, client, user,
1022 /* Marshall data and send request */
1024 if (!spoolss_io_q_addprinterex ("", &q, &qbuf, 0) ||
1025 !rpc_api_pipe_req (cli, SPOOLSS_ADDPRINTEREX, &qbuf, &rbuf))
1028 /* Unmarshall response */
1030 if (!spoolss_io_r_addprinterex ("", &r, &rbuf, 0))
1033 /* Return output parameters */
1038 prs_mem_free(&qbuf);
1039 prs_mem_free(&rbuf);
1044 /*********************************************************************************
1045 Win32 API - DeltePrinterDriver()
1046 ********************************************************************************/
1047 /**********************************************************************
1048 * Delete a Printer Driver from the server (does not remove
1051 WERROR cli_spoolss_deleteprinterdriver (struct cli_state *cli,
1052 TALLOC_CTX *mem_ctx, char *arch,
1055 prs_struct qbuf, rbuf;
1056 SPOOL_Q_DELETEPRINTERDRIVER q;
1057 SPOOL_R_DELETEPRINTERDRIVER r;
1058 WERROR result = W_ERROR(ERRgeneral);
1065 /* Initialise input parameters */
1066 prs_init(&qbuf, MAX_PDU_FRAG_LEN, mem_ctx, MARSHALL);
1067 prs_init(&rbuf, 0, mem_ctx, UNMARSHALL);
1069 slprintf (server, sizeof(fstring)-1, "\\\\%s", cli->desthost);
1072 /* Write the request */
1074 make_spoolss_q_deleteprinterdriver(mem_ctx, &q, server, arch, driver);
1076 /* Marshall data and send request */
1078 if (!spoolss_io_q_deleteprinterdriver ("", &q, &qbuf, 0) ||
1079 !rpc_api_pipe_req (cli,SPOOLSS_DELETEPRINTERDRIVER , &qbuf, &rbuf))
1082 /* Unmarshall response */
1084 if (!spoolss_io_r_deleteprinterdriver ("", &r, &rbuf, 0))
1087 /* Return output parameters */
1092 prs_mem_free(&qbuf);
1093 prs_mem_free(&rbuf);
1098 /*********************************************************************************
1099 Win32 API - GetPrinterProcessorDirectory()
1100 ********************************************************************************/
1102 WERROR cli_spoolss_getprintprocessordirectory(struct cli_state *cli,
1103 TALLOC_CTX *mem_ctx,
1104 uint32 offered, uint32 *needed,
1105 char *name, char *environment,
1108 prs_struct qbuf, rbuf;
1109 SPOOL_Q_GETPRINTPROCESSORDIRECTORY q;
1110 SPOOL_R_GETPRINTPROCESSORDIRECTORY r;
1112 WERROR result = W_ERROR(ERRgeneral);
1118 /* Initialise parse structures */
1120 prs_init(&qbuf, MAX_PDU_FRAG_LEN, mem_ctx, MARSHALL);
1121 prs_init(&rbuf, 0, mem_ctx, UNMARSHALL);
1123 /* Initialise input parameters */
1125 init_buffer(&buffer, offered, mem_ctx);
1127 make_spoolss_q_getprintprocessordirectory(
1128 &q, name, environment, level, &buffer, offered);
1130 /* Marshall data and send request */
1132 if (!spoolss_io_q_getprintprocessordirectory("", &q, &qbuf, 0) ||
1133 !rpc_api_pipe_req(cli, SPOOLSS_GETPRINTPROCESSORDIRECTORY,
1137 /* Unmarshall response */
1139 if (!spoolss_io_r_getprintprocessordirectory("", &r, &rbuf, 0))
1142 /* Return output parameters */
1149 if (W_ERROR_IS_OK(result))
1150 fstrcpy(procdir, "Not implemented!");
1153 prs_mem_free(&qbuf);
1154 prs_mem_free(&rbuf);
1159 /** Add a form to a printer.
1161 * @param cli Pointer to client state structure which is open
1162 * on the SPOOLSS pipe.
1163 * @param mem_ctx Pointer to an initialised talloc context.
1165 * @param handle Policy handle opened with cli_spoolss_open_printer_ex
1166 * or cli_spoolss_addprinterex.
1167 * @param level Form info level to add - should always be 1.
1168 * @param form A pointer to the form to be added.
1172 WERROR cli_spoolss_addform(struct cli_state *cli, TALLOC_CTX *mem_ctx,
1173 POLICY_HND *handle, uint32 level, FORM *form)
1175 prs_struct qbuf, rbuf;
1178 WERROR result = W_ERROR(ERRgeneral);
1183 /* Initialise parse structures */
1185 prs_init(&qbuf, MAX_PDU_FRAG_LEN, mem_ctx, MARSHALL);
1186 prs_init(&rbuf, 0, mem_ctx, UNMARSHALL);
1188 /* Initialise input parameters */
1190 make_spoolss_q_addform(&q, handle, level, form);
1192 /* Marshall data and send request */
1194 if (!spoolss_io_q_addform("", &q, &qbuf, 0) ||
1195 !rpc_api_pipe_req(cli, SPOOLSS_ADDFORM, &qbuf, &rbuf))
1198 /* Unmarshall response */
1200 if (!spoolss_io_r_addform("", &r, &rbuf, 0))
1203 /* Return output parameters */
1208 prs_mem_free(&qbuf);
1209 prs_mem_free(&rbuf);
1214 /** Set a form on a printer.
1216 * @param cli Pointer to client state structure which is open
1217 * on the SPOOLSS pipe.
1218 * @param mem_ctx Pointer to an initialised talloc context.
1220 * @param handle Policy handle opened with cli_spoolss_open_printer_ex
1221 * or cli_spoolss_addprinterex.
1222 * @param level Form info level to set - should always be 1.
1223 * @param form A pointer to the form to be set.
1227 WERROR cli_spoolss_setform(struct cli_state *cli, TALLOC_CTX *mem_ctx,
1228 POLICY_HND *handle, uint32 level, char *form_name,
1231 prs_struct qbuf, rbuf;
1234 WERROR result = W_ERROR(ERRgeneral);
1239 /* Initialise parse structures */
1241 prs_init(&qbuf, MAX_PDU_FRAG_LEN, mem_ctx, MARSHALL);
1242 prs_init(&rbuf, 0, mem_ctx, UNMARSHALL);
1244 /* Initialise input parameters */
1246 make_spoolss_q_setform(&q, handle, level, form_name, form);
1248 /* Marshall data and send request */
1250 if (!spoolss_io_q_setform("", &q, &qbuf, 0) ||
1251 !rpc_api_pipe_req(cli, SPOOLSS_SETFORM, &qbuf, &rbuf))
1254 /* Unmarshall response */
1256 if (!spoolss_io_r_setform("", &r, &rbuf, 0))
1259 /* Return output parameters */
1263 if (!W_ERROR_IS_OK(result))
1269 prs_mem_free(&qbuf);
1270 prs_mem_free(&rbuf);
1275 /** Get a form on a printer.
1277 * @param cli Pointer to client state structure which is open
1278 * on the SPOOLSS pipe.
1279 * @param mem_ctx Pointer to an initialised talloc context.
1281 * @param handle Policy handle opened with cli_spoolss_open_printer_ex
1282 * or cli_spoolss_addprinterex.
1283 * @param formname Name of the form to get
1284 * @param level Form info level to get - should always be 1.
1288 WERROR cli_spoolss_getform(struct cli_state *cli, TALLOC_CTX *mem_ctx,
1289 uint32 offered, uint32 *needed,
1290 POLICY_HND *handle, char *formname, uint32 level,
1293 prs_struct qbuf, rbuf;
1296 WERROR result = W_ERROR(ERRgeneral);
1302 /* Initialise parse structures */
1304 init_buffer(&buffer, offered, mem_ctx);
1306 prs_init(&qbuf, MAX_PDU_FRAG_LEN, mem_ctx, MARSHALL);
1307 prs_init(&rbuf, 0, mem_ctx, UNMARSHALL);
1309 /* Initialise input parameters */
1311 make_spoolss_q_getform(&q, handle, formname, level, &buffer, offered);
1313 /* Marshall data and send request */
1315 if (!spoolss_io_q_getform("", &q, &qbuf, 0) ||
1316 !rpc_api_pipe_req(cli, SPOOLSS_GETFORM, &qbuf, &rbuf))
1319 /* Unmarshall response */
1321 if (!spoolss_io_r_getform("", &r, &rbuf, 0))
1324 /* Return output parameters */
1331 if (W_ERROR_IS_OK(result))
1332 smb_io_form_1("", r.buffer, form, 0);
1335 prs_mem_free(&qbuf);
1336 prs_mem_free(&rbuf);
1341 /** Delete a form on a printer.
1343 * @param cli Pointer to client state structure which is open
1344 * on the SPOOLSS pipe.
1345 * @param mem_ctx Pointer to an initialised talloc context.
1347 * @param handle Policy handle opened with cli_spoolss_open_printer_ex
1348 * or cli_spoolss_addprinterex.
1349 * @param form The name of the form to delete.
1353 WERROR cli_spoolss_deleteform(struct cli_state *cli, TALLOC_CTX *mem_ctx,
1354 POLICY_HND *handle, char *form_name)
1356 prs_struct qbuf, rbuf;
1357 SPOOL_Q_DELETEFORM q;
1358 SPOOL_R_DELETEFORM r;
1359 WERROR result = W_ERROR(ERRgeneral);
1364 /* Initialise parse structures */
1366 prs_init(&qbuf, MAX_PDU_FRAG_LEN, mem_ctx, MARSHALL);
1367 prs_init(&rbuf, 0, mem_ctx, UNMARSHALL);
1369 /* Initialise input parameters */
1371 make_spoolss_q_deleteform(&q, handle, form_name);
1373 /* Marshall data and send request */
1375 if (!spoolss_io_q_deleteform("", &q, &qbuf, 0) ||
1376 !rpc_api_pipe_req(cli, SPOOLSS_DELETEFORM, &qbuf, &rbuf))
1379 /* Unmarshall response */
1381 if (!spoolss_io_r_deleteform("", &r, &rbuf, 0))
1384 /* Return output parameters */
1389 prs_mem_free(&qbuf);
1390 prs_mem_free(&rbuf);
1395 static void decode_forms_1(TALLOC_CTX *mem_ctx, NEW_BUFFER *buffer,
1396 uint32 num_forms, FORM_1 **forms)
1400 *forms = (FORM_1 *)talloc(mem_ctx, num_forms * sizeof(FORM_1));
1401 buffer->prs.data_offset = 0;
1403 for (i = 0; i < num_forms; i++)
1404 smb_io_form_1("", buffer, &((*forms)[i]), 0);
1409 * @param cli Pointer to client state structure which is open
1410 * on the SPOOLSS pipe.
1411 * @param mem_ctx Pointer to an initialised talloc context.
1413 * @param offered Buffer size offered in the request.
1414 * @param needed Number of bytes needed to complete the request.
1416 * or cli_spoolss_addprinterex.
1417 * @param level Form info level to get - should always be 1.
1418 * @param handle Open policy handle
1422 WERROR cli_spoolss_enumforms(struct cli_state *cli, TALLOC_CTX *mem_ctx,
1423 uint32 offered, uint32 *needed,
1424 POLICY_HND *handle, int level, uint32 *num_forms,
1427 prs_struct qbuf, rbuf;
1428 SPOOL_Q_ENUMFORMS q;
1429 SPOOL_R_ENUMFORMS r;
1430 WERROR result = W_ERROR(ERRgeneral);
1436 /* Initialise parse structures */
1438 init_buffer(&buffer, offered, mem_ctx);
1440 prs_init(&qbuf, MAX_PDU_FRAG_LEN, mem_ctx, MARSHALL);
1441 prs_init(&rbuf, 0, mem_ctx, UNMARSHALL);
1443 /* Initialise input parameters */
1445 make_spoolss_q_enumforms(&q, handle, level, &buffer, offered);
1447 /* Marshall data and send request */
1449 if (!spoolss_io_q_enumforms("", &q, &qbuf, 0) ||
1450 !rpc_api_pipe_req(cli, SPOOLSS_ENUMFORMS, &qbuf, &rbuf))
1453 /* Unmarshall response */
1455 if (!spoolss_io_r_enumforms("", &r, &rbuf, 0))
1458 /* Return output parameters */
1466 *num_forms = r.numofforms;
1468 decode_forms_1(mem_ctx, r.buffer, *num_forms, forms);
1471 prs_mem_free(&qbuf);
1472 prs_mem_free(&rbuf);
1477 static void decode_jobs_1(TALLOC_CTX *mem_ctx, NEW_BUFFER *buffer,
1478 uint32 num_jobs, JOB_INFO_1 **jobs)
1482 *jobs = (JOB_INFO_1 *)talloc(mem_ctx, num_jobs * sizeof(JOB_INFO_1));
1483 buffer->prs.data_offset = 0;
1485 for (i = 0; i < num_jobs; i++)
1486 smb_io_job_info_1("", buffer, &((*jobs)[i]), 0);
1489 static void decode_jobs_2(TALLOC_CTX *mem_ctx, NEW_BUFFER *buffer,
1490 uint32 num_jobs, JOB_INFO_2 **jobs)
1494 *jobs = (JOB_INFO_2 *)talloc(mem_ctx, num_jobs * sizeof(JOB_INFO_2));
1495 buffer->prs.data_offset = 0;
1497 for (i = 0; i < num_jobs; i++)
1498 smb_io_job_info_2("", buffer, &((*jobs)[i]), 0);
1501 /* Enumerate jobs */
1503 WERROR cli_spoolss_enumjobs(struct cli_state *cli, TALLOC_CTX *mem_ctx,
1504 uint32 offered, uint32 *needed,
1505 POLICY_HND *hnd, uint32 level, uint32 firstjob,
1506 uint32 num_jobs, uint32 *returned, JOB_INFO_CTR *ctr)
1508 prs_struct qbuf, rbuf;
1511 WERROR result = W_ERROR(ERRgeneral);
1517 /* Initialise parse structures */
1519 init_buffer(&buffer, offered, mem_ctx);
1521 prs_init(&qbuf, MAX_PDU_FRAG_LEN, mem_ctx, MARSHALL);
1522 prs_init(&rbuf, 0, mem_ctx, UNMARSHALL);
1524 /* Initialise input parameters */
1526 make_spoolss_q_enumjobs(&q, hnd, firstjob, num_jobs, level, &buffer,
1529 /* Marshall data and send request */
1531 if (!spoolss_io_q_enumjobs("", &q, &qbuf, 0) ||
1532 !rpc_api_pipe_req(cli, SPOOLSS_ENUMJOBS, &qbuf, &rbuf))
1535 /* Unmarshall response */
1537 if (!spoolss_io_r_enumjobs("", &r, &rbuf, 0))
1540 /* Return output parameters */
1547 if (!W_ERROR_IS_OK(r.status))
1550 *returned = r.returned;
1554 decode_jobs_1(mem_ctx, r.buffer, r.returned,
1555 &ctr->job.job_info_1);
1558 decode_jobs_2(mem_ctx, r.buffer, r.returned,
1559 &ctr->job.job_info_2);
1562 DEBUG(3, ("unsupported info level %d", level));
1567 prs_mem_free(&qbuf);
1568 prs_mem_free(&rbuf);
1575 WERROR cli_spoolss_setjob(struct cli_state *cli, TALLOC_CTX *mem_ctx,
1576 POLICY_HND *hnd, uint32 jobid, uint32 level,
1579 prs_struct qbuf, rbuf;
1582 WERROR result = W_ERROR(ERRgeneral);
1587 /* Initialise parse structures */
1589 prs_init(&qbuf, MAX_PDU_FRAG_LEN, mem_ctx, MARSHALL);
1590 prs_init(&rbuf, 0, mem_ctx, UNMARSHALL);
1592 /* Initialise input parameters */
1594 make_spoolss_q_setjob(&q, hnd, jobid, level, command);
1596 /* Marshall data and send request */
1598 if (!spoolss_io_q_setjob("", &q, &qbuf, 0) ||
1599 !rpc_api_pipe_req(cli, SPOOLSS_SETJOB, &qbuf, &rbuf))
1602 /* Unmarshall response */
1604 if (!spoolss_io_r_setjob("", &r, &rbuf, 0))
1607 /* Return output parameters */
1612 prs_mem_free(&qbuf);
1613 prs_mem_free(&rbuf);
1620 WERROR cli_spoolss_getjob(struct cli_state *cli, TALLOC_CTX *mem_ctx,
1621 uint32 offered, uint32 *needed,
1622 POLICY_HND *hnd, uint32 jobid, uint32 level,
1625 prs_struct qbuf, rbuf;
1628 WERROR result = W_ERROR(ERRgeneral);
1634 /* Initialise parse structures */
1636 init_buffer(&buffer, offered, mem_ctx);
1638 prs_init(&qbuf, MAX_PDU_FRAG_LEN, mem_ctx, MARSHALL);
1639 prs_init(&rbuf, 0, mem_ctx, UNMARSHALL);
1641 /* Initialise input parameters */
1643 make_spoolss_q_getjob(&q, hnd, jobid, level, &buffer, offered);
1645 /* Marshall data and send request */
1647 if (!spoolss_io_q_getjob("", &q, &qbuf, 0) ||
1648 !rpc_api_pipe_req(cli, SPOOLSS_GETJOB, &qbuf, &rbuf))
1651 /* Unmarshall response */
1653 if (!spoolss_io_r_getjob("", &r, &rbuf, 0))
1656 /* Return output parameters */
1663 if (!W_ERROR_IS_OK(r.status))
1668 decode_jobs_1(mem_ctx, r.buffer, 1, &ctr->job.job_info_1);
1671 decode_jobs_2(mem_ctx, r.buffer, 1, &ctr->job.job_info_2);
1674 DEBUG(3, ("unsupported info level %d", level));
1679 prs_mem_free(&qbuf);
1680 prs_mem_free(&rbuf);
1685 /* Startpageprinter. Sent to notify the spooler when a page is about to be
1686 sent to a printer. */
1688 WERROR cli_spoolss_startpageprinter(struct cli_state *cli, TALLOC_CTX *mem_ctx,
1691 prs_struct qbuf, rbuf;
1692 SPOOL_Q_STARTPAGEPRINTER q;
1693 SPOOL_R_STARTPAGEPRINTER r;
1694 WERROR result = W_ERROR(ERRgeneral);
1699 /* Initialise parse structures */
1701 prs_init(&qbuf, MAX_PDU_FRAG_LEN, mem_ctx, MARSHALL);
1702 prs_init(&rbuf, 0, mem_ctx, UNMARSHALL);
1704 /* Initialise input parameters */
1706 make_spoolss_q_startpageprinter(&q, hnd);
1708 /* Marshall data and send request */
1710 if (!spoolss_io_q_startpageprinter("", &q, &qbuf, 0) ||
1711 !rpc_api_pipe_req(cli, SPOOLSS_STARTPAGEPRINTER, &qbuf, &rbuf))
1714 /* Unmarshall response */
1716 if (!spoolss_io_r_startpageprinter("", &r, &rbuf, 0))
1719 /* Return output parameters */
1724 prs_mem_free(&qbuf);
1725 prs_mem_free(&rbuf);
1730 /* Endpageprinter. Sent to notify the spooler when a page has finished
1731 being sent to a printer. */
1733 WERROR cli_spoolss_endpageprinter(struct cli_state *cli, TALLOC_CTX *mem_ctx,
1736 prs_struct qbuf, rbuf;
1737 SPOOL_Q_ENDPAGEPRINTER q;
1738 SPOOL_R_ENDPAGEPRINTER r;
1739 WERROR result = W_ERROR(ERRgeneral);
1744 /* Initialise parse structures */
1746 prs_init(&qbuf, MAX_PDU_FRAG_LEN, mem_ctx, MARSHALL);
1747 prs_init(&rbuf, 0, mem_ctx, UNMARSHALL);
1749 /* Initialise input parameters */
1751 make_spoolss_q_endpageprinter(&q, hnd);
1753 /* Marshall data and send request */
1755 if (!spoolss_io_q_endpageprinter("", &q, &qbuf, 0) ||
1756 !rpc_api_pipe_req(cli, SPOOLSS_ENDPAGEPRINTER, &qbuf, &rbuf))
1759 /* Unmarshall response */
1761 if (!spoolss_io_r_endpageprinter("", &r, &rbuf, 0))
1764 /* Return output parameters */
1769 prs_mem_free(&qbuf);
1770 prs_mem_free(&rbuf);
1775 /* Startdocprinter. Sent to notify the spooler that a document is about
1776 to be spooled for printing. */
1778 WERROR cli_spoolss_startdocprinter(struct cli_state *cli, TALLOC_CTX *mem_ctx,
1779 POLICY_HND *hnd, char *docname,
1780 char *outputfile, char *datatype,
1783 prs_struct qbuf, rbuf;
1784 SPOOL_Q_STARTDOCPRINTER q;
1785 SPOOL_R_STARTDOCPRINTER r;
1786 WERROR result = W_ERROR(ERRgeneral);
1792 /* Initialise parse structures */
1794 prs_init(&qbuf, MAX_PDU_FRAG_LEN, mem_ctx, MARSHALL);
1795 prs_init(&rbuf, 0, mem_ctx, UNMARSHALL);
1797 /* Initialise input parameters */
1799 make_spoolss_q_startdocprinter(&q, hnd, level, docname, outputfile,
1802 /* Marshall data and send request */
1804 if (!spoolss_io_q_startdocprinter("", &q, &qbuf, 0) ||
1805 !rpc_api_pipe_req(cli, SPOOLSS_STARTDOCPRINTER, &qbuf, &rbuf))
1808 /* Unmarshall response */
1810 if (!spoolss_io_r_startdocprinter("", &r, &rbuf, 0))
1813 /* Return output parameters */
1817 if (W_ERROR_IS_OK(result))
1821 prs_mem_free(&qbuf);
1822 prs_mem_free(&rbuf);
1827 /* Enddocprinter. Sent to notify the spooler that a document has finished
1830 WERROR cli_spoolss_enddocprinter(struct cli_state *cli, TALLOC_CTX *mem_ctx,
1833 prs_struct qbuf, rbuf;
1834 SPOOL_Q_ENDDOCPRINTER q;
1835 SPOOL_R_ENDDOCPRINTER r;
1836 WERROR result = W_ERROR(ERRgeneral);
1841 /* Initialise parse structures */
1843 prs_init(&qbuf, MAX_PDU_FRAG_LEN, mem_ctx, MARSHALL);
1844 prs_init(&rbuf, 0, mem_ctx, UNMARSHALL);
1846 /* Initialise input parameters */
1848 make_spoolss_q_enddocprinter(&q, hnd);
1850 /* Marshall data and send request */
1852 if (!spoolss_io_q_enddocprinter("", &q, &qbuf, 0) ||
1853 !rpc_api_pipe_req(cli, SPOOLSS_ENDDOCPRINTER, &qbuf, &rbuf))
1856 /* Unmarshall response */
1858 if (!spoolss_io_r_enddocprinter("", &r, &rbuf, 0))
1861 /* Return output parameters */
1866 prs_mem_free(&qbuf);
1867 prs_mem_free(&rbuf);
1872 /* Get printer data */
1874 WERROR cli_spoolss_getprinterdata(struct cli_state *cli, TALLOC_CTX *mem_ctx,
1875 uint32 offered, uint32 *needed,
1876 POLICY_HND *hnd, char *valuename,
1877 uint32 *data_type, char **data,
1880 prs_struct qbuf, rbuf;
1881 SPOOL_Q_GETPRINTERDATA q;
1882 SPOOL_R_GETPRINTERDATA r;
1883 WERROR result = W_ERROR(ERRgeneral);
1888 /* Initialise parse structures */
1890 prs_init(&qbuf, MAX_PDU_FRAG_LEN, mem_ctx, MARSHALL);
1891 prs_init(&rbuf, 0, mem_ctx, UNMARSHALL);
1893 /* Initialise input parameters */
1895 make_spoolss_q_getprinterdata(&q, hnd, valuename, offered);
1897 /* Marshall data and send request */
1899 if (!spoolss_io_q_getprinterdata("", &q, &qbuf, 0) ||
1900 !rpc_api_pipe_req(cli, SPOOLSS_GETPRINTERDATA, &qbuf, &rbuf))
1903 /* Unmarshall response */
1905 if (!spoolss_io_r_getprinterdata("", &r, &rbuf, 0))
1913 if (!W_ERROR_IS_OK(r.status))
1916 /* Return output parameters */
1919 *data_type = r.type;
1922 *data = (char *)talloc(mem_ctx, r.needed);
1923 memcpy(*data, r.data, r.needed);
1927 *data_size = r.needed;
1930 prs_mem_free(&qbuf);
1931 prs_mem_free(&rbuf);
1936 WERROR cli_spoolss_getprinterdataex(struct cli_state *cli, TALLOC_CTX *mem_ctx,
1937 uint32 offered, uint32 *needed,
1938 POLICY_HND *hnd, char *keyname,
1939 char *valuename, uint32 *data_type,
1940 char **data, uint32 *data_size)
1942 prs_struct qbuf, rbuf;
1943 SPOOL_Q_GETPRINTERDATAEX q;
1944 SPOOL_R_GETPRINTERDATAEX r;
1945 WERROR result = W_ERROR(ERRgeneral);
1950 /* Initialise parse structures */
1952 prs_init(&qbuf, MAX_PDU_FRAG_LEN, mem_ctx, MARSHALL);
1953 prs_init(&rbuf, 0, mem_ctx, UNMARSHALL);
1955 /* Initialise input parameters */
1957 make_spoolss_q_getprinterdataex(&q, hnd, keyname, valuename, offered);
1959 /* Marshall data and send request */
1961 if (!spoolss_io_q_getprinterdataex("", &q, &qbuf, 0) ||
1962 !rpc_api_pipe_req(cli, SPOOLSS_GETPRINTERDATAEX, &qbuf, &rbuf))
1965 /* Unmarshall response */
1967 if (!spoolss_io_r_getprinterdataex("", &r, &rbuf, 0))
1975 if (!W_ERROR_IS_OK(r.status))
1978 /* Return output parameters */
1981 *data_type = r.type;
1984 *data = (char *)talloc(mem_ctx, r.needed);
1985 memcpy(*data, r.data, r.needed);
1989 *data_size = r.needed;
1992 prs_mem_free(&qbuf);
1993 prs_mem_free(&rbuf);
1998 /* Set printer data */
2000 WERROR cli_spoolss_setprinterdata(struct cli_state *cli, TALLOC_CTX *mem_ctx,
2001 POLICY_HND *hnd, char *value,
2002 uint32 data_type, char *data,
2005 prs_struct qbuf, rbuf;
2006 SPOOL_Q_SETPRINTERDATA q;
2007 SPOOL_R_SETPRINTERDATA r;
2008 WERROR result = W_ERROR(ERRgeneral);
2013 /* Initialise parse structures */
2015 prs_init(&qbuf, MAX_PDU_FRAG_LEN, mem_ctx, MARSHALL);
2016 prs_init(&rbuf, 0, mem_ctx, UNMARSHALL);
2018 /* Initialise input parameters */
2020 make_spoolss_q_setprinterdata(&q, hnd, value, data_type, data, data_size);
2022 /* Marshall data and send request */
2024 if (!spoolss_io_q_setprinterdata("", &q, &qbuf, 0) ||
2025 !rpc_api_pipe_req(cli, SPOOLSS_SETPRINTERDATA, &qbuf, &rbuf))
2028 /* Unmarshall response */
2030 if (!spoolss_io_r_setprinterdata("", &r, &rbuf, 0))
2035 if (!W_ERROR_IS_OK(r.status))
2039 prs_mem_free(&qbuf);
2040 prs_mem_free(&rbuf);
2045 WERROR cli_spoolss_setprinterdataex(struct cli_state *cli, TALLOC_CTX *mem_ctx,
2046 POLICY_HND *hnd, char * key, char *value,
2047 uint32 data_type, char *data,
2050 prs_struct qbuf, rbuf;
2051 SPOOL_Q_SETPRINTERDATAEX q;
2052 SPOOL_R_SETPRINTERDATAEX r;
2053 WERROR result = W_ERROR(ERRgeneral);
2058 /* Initialise parse structures */
2060 prs_init(&qbuf, MAX_PDU_FRAG_LEN, mem_ctx, MARSHALL);
2061 prs_init(&rbuf, 0, mem_ctx, UNMARSHALL);
2063 /* Initialise input parameters */
2065 make_spoolss_q_setprinterdataex(&q, hnd, key, value, data_type, data, data_size);
2067 /* Marshall data and send request */
2069 if (!spoolss_io_q_setprinterdataex("", &q, &qbuf, 0) ||
2070 !rpc_api_pipe_req(cli, SPOOLSS_SETPRINTERDATAEX, &qbuf, &rbuf))
2073 /* Unmarshall response */
2075 if (!spoolss_io_r_setprinterdataex("", &r, &rbuf, 0))
2080 if (!W_ERROR_IS_OK(r.status))
2084 prs_mem_free(&qbuf);
2085 prs_mem_free(&rbuf);
2090 /* Enum printer data */
2092 WERROR cli_spoolss_enumprinterdata(struct cli_state *cli, TALLOC_CTX *mem_ctx,
2093 POLICY_HND *hnd, uint32 ndx,
2094 uint32 value_offered, uint32 data_offered,
2095 uint32 *value_needed, uint32 *data_needed,
2096 char **value, uint32 *data_type, char **data,
2099 prs_struct qbuf, rbuf;
2100 SPOOL_Q_ENUMPRINTERDATA q;
2101 SPOOL_R_ENUMPRINTERDATA r;
2102 WERROR result = W_ERROR(ERRgeneral);
2107 /* Initialise parse structures */
2109 prs_init(&qbuf, MAX_PDU_FRAG_LEN, mem_ctx, MARSHALL);
2110 prs_init(&rbuf, 0, mem_ctx, UNMARSHALL);
2112 /* Initialise input parameters */
2114 make_spoolss_q_enumprinterdata(&q, hnd, ndx, value_offered, data_offered);
2116 /* Marshall data and send request */
2118 if (!spoolss_io_q_enumprinterdata("", &q, &qbuf, 0) ||
2119 !rpc_api_pipe_req(cli, SPOOLSS_ENUMPRINTERDATA, &qbuf, &rbuf))
2122 /* Unmarshall response */
2124 if (!spoolss_io_r_enumprinterdata("", &r, &rbuf, 0))
2129 if (!W_ERROR_IS_OK(r.status))
2135 *value_needed = r.realvaluesize;
2138 *data_needed = r.realdatasize;
2141 *data_type = r.type;
2146 rpcstr_pull(the_value, r.value, sizeof(the_value), -1,
2149 *value = talloc_strdup(mem_ctx, the_value);
2153 *data = talloc_memdup(mem_ctx, r.data, r.realdatasize);
2156 *data_size = r.realdatasize;
2159 prs_mem_free(&qbuf);
2160 prs_mem_free(&rbuf);
2165 WERROR cli_spoolss_enumprinterdataex(struct cli_state *cli, TALLOC_CTX *mem_ctx,
2166 uint32 offered, uint32 *needed,
2167 POLICY_HND *hnd, char *key,
2168 uint32 *returned, PRINTER_ENUM_VALUES **values)
2170 prs_struct qbuf, rbuf;
2171 SPOOL_Q_ENUMPRINTERDATAEX q;
2172 SPOOL_R_ENUMPRINTERDATAEX r;
2173 WERROR result = W_ERROR(ERRgeneral);
2179 /* Initialise parse structures */
2181 prs_init(&qbuf, MAX_PDU_FRAG_LEN, mem_ctx, MARSHALL);
2182 prs_init(&rbuf, 0, mem_ctx, UNMARSHALL);
2184 /* Initialise input parameters */
2186 make_spoolss_q_enumprinterdataex(&q, hnd, key, offered);
2188 /* Marshall data and send request */
2190 if (!spoolss_io_q_enumprinterdataex("", &q, &qbuf, 0) ||
2191 !rpc_api_pipe_req(cli, SPOOLSS_ENUMPRINTERDATAEX, &qbuf, &rbuf))
2194 /* Unmarshall response */
2196 if (!spoolss_io_r_enumprinterdataex("", &r, &rbuf, 0))
2204 if (!W_ERROR_IS_OK(r.status))
2209 *returned = r.returned;
2211 /* Again, we have to deep copy the results on the passed in
2212 tdb context as they will disappear after the prs_free at
2213 the end of this function. */
2215 *values = talloc(mem_ctx, sizeof(PRINTER_ENUM_VALUES) * r.returned);
2217 for (i = 0; i < r.returned; i++) {
2218 PRINTER_ENUM_VALUES *v = &r.ctr.values[i];
2220 (*values)[i].valuename.buffer = talloc(mem_ctx, v->value_len * 2);
2221 unistrcpy((*values)[i].valuename.buffer, v->valuename.buffer);
2222 (*values)[i].type = v->type;
2223 (*values)[i].data = talloc(mem_ctx, v->data_len);
2224 memcpy((*values)[i].data, v->data, v->data_len);
2225 (*values)[i].data_len = v->data_len;
2229 prs_mem_free(&qbuf);
2230 prs_mem_free(&rbuf);
2235 /* Write data to printer */
2237 WERROR cli_spoolss_writeprinter(struct cli_state *cli, TALLOC_CTX *mem_ctx,
2238 POLICY_HND *hnd, uint32 data_size, char *data,
2239 uint32 *num_written)
2241 prs_struct qbuf, rbuf;
2242 SPOOL_Q_WRITEPRINTER q;
2243 SPOOL_R_WRITEPRINTER r;
2244 WERROR result = W_ERROR(ERRgeneral);
2249 /* Initialise parse structures */
2251 prs_init(&qbuf, MAX_PDU_FRAG_LEN, mem_ctx, MARSHALL);
2252 prs_init(&rbuf, 0, mem_ctx, UNMARSHALL);
2254 /* Initialise input parameters */
2256 make_spoolss_q_writeprinter(&q, hnd, data_size, data);
2258 /* Marshall data and send request */
2260 if (!spoolss_io_q_writeprinter("", &q, &qbuf, 0) ||
2261 !rpc_api_pipe_req(cli, SPOOLSS_WRITEPRINTER, &qbuf, &rbuf))
2264 /* Unmarshall response */
2266 if (!spoolss_io_r_writeprinter("", &r, &rbuf, 0))
2271 if (!W_ERROR_IS_OK(r.status))
2275 *num_written = r.buffer_written;
2278 prs_mem_free(&qbuf);
2279 prs_mem_free(&rbuf);
2284 /* Delete printer data */
2286 WERROR cli_spoolss_deleteprinterdata(struct cli_state *cli, TALLOC_CTX *mem_ctx,
2287 POLICY_HND *hnd, char *valuename)
2289 prs_struct qbuf, rbuf;
2290 SPOOL_Q_DELETEPRINTERDATA q;
2291 SPOOL_R_DELETEPRINTERDATA r;
2292 WERROR result = W_ERROR(ERRgeneral);
2297 /* Initialise parse structures */
2299 prs_init(&qbuf, MAX_PDU_FRAG_LEN, mem_ctx, MARSHALL);
2300 prs_init(&rbuf, 0, mem_ctx, UNMARSHALL);
2302 /* Initialise input parameters */
2304 make_spoolss_q_deleteprinterdata(&q, hnd, valuename);
2306 /* Marshall data and send request */
2308 if (!spoolss_io_q_deleteprinterdata("", &q, &qbuf, 0) ||
2309 !rpc_api_pipe_req(cli, SPOOLSS_DELETEPRINTERDATA, &qbuf, &rbuf))
2312 /* Unmarshall response */
2314 if (!spoolss_io_r_deleteprinterdata("", &r, &rbuf, 0))
2319 if (!W_ERROR_IS_OK(r.status))
2323 prs_mem_free(&qbuf);
2324 prs_mem_free(&rbuf);
2329 WERROR cli_spoolss_deleteprinterdataex(struct cli_state *cli, TALLOC_CTX *mem_ctx,
2330 POLICY_HND *hnd, char *key, char *value)
2332 prs_struct qbuf, rbuf;
2333 SPOOL_Q_DELETEPRINTERDATAEX q;
2334 SPOOL_R_DELETEPRINTERDATAEX r;
2335 WERROR result = W_ERROR(ERRgeneral);
2340 /* Initialise parse structures */
2342 prs_init(&qbuf, MAX_PDU_FRAG_LEN, mem_ctx, MARSHALL);
2343 prs_init(&rbuf, 0, mem_ctx, UNMARSHALL);
2345 /* Initialise input parameters */
2347 make_spoolss_q_deleteprinterdataex(&q, hnd, key, value);
2349 /* Marshall data and send request */
2351 if (!spoolss_io_q_deleteprinterdataex("", &q, &qbuf, 0) ||
2352 !rpc_api_pipe_req(cli, SPOOLSS_DELETEPRINTERDATAEX, &qbuf, &rbuf))
2355 /* Unmarshall response */
2357 if (!spoolss_io_r_deleteprinterdataex("", &r, &rbuf, 0))
2362 if (!W_ERROR_IS_OK(r.status))
2366 prs_mem_free(&qbuf);
2367 prs_mem_free(&rbuf);