sync'ing up for 3.0alpha20 release
[Samba/gbeck.git] / source3 / rpc_client / cli_spoolss.c
blobca24d95e33628bdeaf6511c96d7aeea17ece24b2
1 /*
2 Unix SMB/CIFS implementation.
3 RPC pipe client
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.
26 #include "includes.h"
28 /** @defgroup spoolss SPOOLSS - NT printing routines
29 * @ingroup rpc_client
31 * @{
32 **/
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);
40 buffer->size = size;
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)
55 uint32 i;
56 PRINTER_INFO_0 *inf;
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);
66 *info=inf;
69 /**********************************************************************
70 **********************************************************************/
71 static void decode_printer_info_1(TALLOC_CTX *mem_ctx, NEW_BUFFER *buffer,
72 uint32 returned, PRINTER_INFO_1 **info)
74 uint32 i;
75 PRINTER_INFO_1 *inf;
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);
85 *info=inf;
88 /**********************************************************************
89 **********************************************************************/
90 static void decode_printer_info_2(TALLOC_CTX *mem_ctx, NEW_BUFFER *buffer,
91 uint32 returned, PRINTER_INFO_2 **info)
93 uint32 i;
94 PRINTER_INFO_2 *inf;
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);
106 *info=inf;
109 /**********************************************************************
110 **********************************************************************/
111 static void decode_printer_info_3(TALLOC_CTX *mem_ctx, NEW_BUFFER *buffer,
112 uint32 returned, PRINTER_INFO_3 **info)
114 uint32 i;
115 PRINTER_INFO_3 *inf;
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);
126 *info=inf;
129 /**********************************************************************
130 **********************************************************************/
131 static void decode_port_info_1(TALLOC_CTX *mem_ctx, NEW_BUFFER *buffer,
132 uint32 returned, PORT_INFO_1 **info)
134 uint32 i;
135 PORT_INFO_1 *inf;
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);
145 *info=inf;
148 /**********************************************************************
149 **********************************************************************/
150 static void decode_port_info_2(TALLOC_CTX *mem_ctx, NEW_BUFFER *buffer,
151 uint32 returned, PORT_INFO_2 **info)
153 uint32 i;
154 PORT_INFO_2 *inf;
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);
164 *info=inf;
167 /**********************************************************************
168 **********************************************************************/
169 static void decode_printer_driver_1(TALLOC_CTX *mem_ctx, NEW_BUFFER *buffer,
170 uint32 returned, DRIVER_INFO_1 **info)
172 uint32 i;
173 DRIVER_INFO_1 *inf;
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);
183 *info=inf;
186 /**********************************************************************
187 **********************************************************************/
188 static void decode_printer_driver_2(TALLOC_CTX *mem_ctx, NEW_BUFFER *buffer,
189 uint32 returned, DRIVER_INFO_2 **info)
191 uint32 i;
192 DRIVER_INFO_2 *inf;
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);
202 *info=inf;
205 /**********************************************************************
206 **********************************************************************/
207 static void decode_printer_driver_3(TALLOC_CTX *mem_ctx, NEW_BUFFER *buffer,
208 uint32 returned, DRIVER_INFO_3 **info)
210 uint32 i;
211 DRIVER_INFO_3 *inf;
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);
221 *info=inf;
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);
238 *info=inf;
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
254 * print server.
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);
276 ZERO_STRUCT(q);
277 ZERO_STRUCT(r);
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))
293 goto done;
295 /* Unmarshall response */
297 if (!spoolss_io_r_open_printer_ex("", &r, &rbuf, 0))
298 goto done;
300 /* Return output parameters */
302 result = r.status;
304 if (W_ERROR_IS_OK(result))
305 *pol = r.handle;
307 done:
308 prs_mem_free(&qbuf);
309 prs_mem_free(&rbuf);
311 return 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,
328 POLICY_HND *pol)
330 prs_struct qbuf, rbuf;
331 SPOOL_Q_CLOSEPRINTER q;
332 SPOOL_R_CLOSEPRINTER r;
333 WERROR result = W_ERROR(ERRgeneral);
335 ZERO_STRUCT(q);
336 ZERO_STRUCT(r);
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))
351 goto done;
353 /* Unmarshall response */
355 if (!spoolss_io_r_closeprinter("", &r, &rbuf, 0))
356 goto done;
358 /* Return output parameters */
360 result = r.status;
362 if (W_ERROR_IS_OK(result))
363 *pol = r.handle;
365 done:
366 prs_mem_free(&qbuf);
367 prs_mem_free(&rbuf);
369 return 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.
380 * may be NULL.
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
386 * NULL.
387 * @param ctr Return structure for printer information. May
388 * be NULL.
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;
402 NEW_BUFFER buffer;
403 WERROR result = W_ERROR(ERRgeneral);
405 ZERO_STRUCT(q);
406 ZERO_STRUCT(r);
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,
416 offered);
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))
422 goto done;
424 /* Unmarshall response */
426 if (spoolss_io_r_enumprinters("", &r, &rbuf, 0)) {
427 if (needed)
428 *needed = r.needed;
431 result = r.status;
433 /* Return output parameters */
435 if (!W_ERROR_IS_OK(r.status))
436 goto done;
438 if (num_printers)
439 *num_printers = r.returned;
441 if (!ctr)
442 goto done;
444 switch (level) {
445 case 0:
446 decode_printer_info_0(mem_ctx, r.buffer, r.returned,
447 &ctr->printers_0);
448 break;
449 case 1:
450 decode_printer_info_1(mem_ctx, r.buffer, r.returned,
451 &ctr->printers_1);
452 break;
453 case 2:
454 decode_printer_info_2(mem_ctx, r.buffer, r.returned,
455 &ctr->printers_2);
456 break;
457 case 3:
458 decode_printer_info_3(mem_ctx, r.buffer, r.returned,
459 &ctr->printers_3);
460 break;
463 done:
464 prs_mem_free(&qbuf);
465 prs_mem_free(&rbuf);
467 return result;
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.
481 * May be NULL.
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.
487 * May be NULL.
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;
495 SPOOL_Q_ENUMPORTS q;
496 SPOOL_R_ENUMPORTS r;
497 NEW_BUFFER buffer;
498 WERROR result = W_ERROR(ERRgeneral);
499 fstring server;
501 ZERO_STRUCT(q);
502 ZERO_STRUCT(r);
504 slprintf (server, sizeof(fstring)-1, "\\\\%s", cli->desthost);
505 strupper (server);
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))
520 goto done;
522 /* Unmarshall response */
524 if (spoolss_io_r_enumports("", &r, &rbuf, 0)) {
525 if (needed)
526 *needed = r.needed;
529 result = r.status;
531 /* Return output parameters */
533 if (!W_ERROR_IS_OK(result))
534 goto done;
536 if (num_ports)
537 *num_ports = r.returned;
539 if (!ctr)
540 goto done;
542 switch (level) {
543 case 1:
544 decode_port_info_1(mem_ctx, r.buffer, r.returned,
545 &ctr->port.info_1);
546 break;
547 case 2:
548 decode_port_info_2(mem_ctx, r.buffer, r.returned,
549 &ctr->port.info_2);
550 break;
553 done:
554 prs_mem_free(&qbuf);
555 prs_mem_free(&rbuf);
557 return result;
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;
572 NEW_BUFFER buffer;
573 WERROR result = W_ERROR(ERRgeneral);
575 ZERO_STRUCT(q);
576 ZERO_STRUCT(r);
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))
591 goto done;
593 /* Unmarshall response */
595 if (!spoolss_io_r_getprinter("", &r, &rbuf, 0))
596 goto done;
598 if (needed)
599 *needed = r.needed;
601 /* Return output parameters */
603 result = r.status;
605 if (W_ERROR_IS_OK(result)) {
606 switch (level) {
607 case 0:
608 decode_printer_info_0(mem_ctx, r.buffer, 1, &ctr->printers_0);
609 break;
610 case 1:
611 decode_printer_info_1(mem_ctx, r.buffer, 1, &ctr->printers_1);
612 break;
613 case 2:
614 decode_printer_info_2(mem_ctx, r.buffer, 1, &ctr->printers_2);
615 break;
616 case 3:
617 decode_printer_info_3(mem_ctx, r.buffer, 1, &ctr->printers_3);
618 break;
622 done:
623 prs_mem_free(&qbuf);
624 prs_mem_free(&rbuf);
626 return result;
629 /*********************************************************************************
630 Win32 API - SetPrinter()
631 ********************************************************************************/
632 /** Set printer info
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
643 * for details.
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);
656 ZERO_STRUCT(q);
657 ZERO_STRUCT(r);
659 /* Initialise input parameters */
661 prs_init(&qbuf, MAX_PDU_FRAG_LEN, mem_ctx, MARSHALL);
662 prs_init(&rbuf, 0, mem_ctx, UNMARSHALL);
664 if (!make_spoolss_q_setprinter(mem_ctx, &q, pol, level, ctr, command))
665 goto done;
667 /* Marshall data and send request */
669 if (!spoolss_io_q_setprinter("", &q, &qbuf, 0) ||
670 !rpc_api_pipe_req(cli, SPOOLSS_SETPRINTER, &qbuf, &rbuf))
671 goto done;
673 /* Unmarshall response */
675 if (!spoolss_io_r_setprinter("", &r, &rbuf, 0))
676 goto done;
678 result = r.status;
680 done:
681 prs_mem_free(&qbuf);
682 prs_mem_free(&rbuf);
684 return result;
687 /*********************************************************************************
688 Win32 API - GetPrinterDriver()
689 ********************************************************************************/
690 /** Get installed printer drivers for a given printer
692 * @param cli Pointer to client state structure which is open
693 * on the SPOOLSS pipe.
695 * @param mem_ctx Pointer to an initialised talloc context.
697 * @param offered Buffer size offered in the request.
698 * @param needed Number of bytes needed to complete the request.
699 * may be NULL.
701 * @param pol Pointer to an open policy handle for the printer
702 * opened with cli_spoolss_open_printer_ex().
703 * @param level Requested information level.
704 * @param env The print environment or archictecture. This is
705 * "Windows NT x86" for NT4.
706 * @param ctr Returned printer driver information.
709 WERROR cli_spoolss_getprinterdriver(struct cli_state *cli,
710 TALLOC_CTX *mem_ctx,
711 uint32 offered, uint32 *needed,
712 POLICY_HND *pol, uint32 level,
713 char *env, PRINTER_DRIVER_CTR *ctr)
715 prs_struct qbuf, rbuf;
716 SPOOL_Q_GETPRINTERDRIVER2 q;
717 SPOOL_R_GETPRINTERDRIVER2 r;
718 NEW_BUFFER buffer;
719 WERROR result = W_ERROR(ERRgeneral);
720 fstring server;
722 ZERO_STRUCT(q);
723 ZERO_STRUCT(r);
725 fstrcpy (server, cli->desthost);
726 strupper (server);
728 /* Initialise input parameters */
730 init_buffer(&buffer, offered, mem_ctx);
732 prs_init(&qbuf, MAX_PDU_FRAG_LEN, mem_ctx, MARSHALL);
733 prs_init(&rbuf, 0, mem_ctx, UNMARSHALL);
735 make_spoolss_q_getprinterdriver2(&q, pol, env, level, 2, 2,
736 &buffer, offered);
738 /* Marshall data and send request */
740 if (!spoolss_io_q_getprinterdriver2 ("", &q, &qbuf, 0) ||
741 !rpc_api_pipe_req (cli, SPOOLSS_GETPRINTERDRIVER2, &qbuf, &rbuf))
742 goto done;
744 /* Unmarshall response */
746 if (spoolss_io_r_getprinterdriver2 ("", &r, &rbuf, 0)) {
747 if (needed)
748 *needed = r.needed;
751 result = r.status;
753 /* Return output parameters */
755 if (!W_ERROR_IS_OK(result))
756 goto done;
758 if (!ctr)
759 goto done;
761 switch (level) {
762 case 1:
763 decode_printer_driver_1(mem_ctx, r.buffer, 1, &ctr->info1);
764 break;
765 case 2:
766 decode_printer_driver_2(mem_ctx, r.buffer, 1, &ctr->info2);
767 break;
768 case 3:
769 decode_printer_driver_3(mem_ctx, r.buffer, 1, &ctr->info3);
770 break;
771 default:
772 DEBUG(10, ("cli_spoolss_getprinterdriver: unknown info level %d", level));
773 return WERR_UNKNOWN_LEVEL;
776 done:
777 prs_mem_free(&qbuf);
778 prs_mem_free(&rbuf);
780 return result;
783 /*********************************************************************************
784 Win32 API - EnumPrinterDrivers()
785 ********************************************************************************/
786 /**********************************************************************
787 * Get installed printer drivers for a given printer
789 WERROR cli_spoolss_enumprinterdrivers (struct cli_state *cli,
790 TALLOC_CTX *mem_ctx,
791 uint32 offered, uint32 *needed,
792 uint32 level, char *env,
793 uint32 *num_drivers,
794 PRINTER_DRIVER_CTR *ctr)
796 prs_struct qbuf, rbuf;
797 SPOOL_Q_ENUMPRINTERDRIVERS q;
798 SPOOL_R_ENUMPRINTERDRIVERS r;
799 NEW_BUFFER buffer;
800 WERROR result = W_ERROR(ERRgeneral);
801 fstring server;
803 ZERO_STRUCT(q);
804 ZERO_STRUCT(r);
806 slprintf (server, sizeof(fstring)-1, "\\\\%s", cli->desthost);
807 strupper (server);
809 /* Initialise input parameters */
811 init_buffer(&buffer, offered, mem_ctx);
813 prs_init(&qbuf, MAX_PDU_FRAG_LEN, mem_ctx, MARSHALL);
814 prs_init(&rbuf, 0, mem_ctx, UNMARSHALL);
816 /* Write the request */
818 make_spoolss_q_enumprinterdrivers(&q, server, env, level, &buffer,
819 offered);
821 /* Marshall data and send request */
823 if (!spoolss_io_q_enumprinterdrivers ("", &q, &qbuf, 0) ||
824 !rpc_api_pipe_req (cli, SPOOLSS_ENUMPRINTERDRIVERS, &qbuf, &rbuf))
825 goto done;
827 /* Unmarshall response */
829 if (!spoolss_io_r_enumprinterdrivers ("", &r, &rbuf, 0))
830 goto done;
832 if (needed)
833 *needed = r.needed;
835 if (num_drivers)
836 *num_drivers = r.returned;
838 result = r.status;
840 /* Return output parameters */
842 if (W_ERROR_IS_OK(result) && (r.returned != 0)) {
843 *num_drivers = r.returned;
845 switch (level) {
846 case 1:
847 decode_printer_driver_1(mem_ctx, r.buffer, r.returned, &ctr->info1);
848 break;
849 case 2:
850 decode_printer_driver_2(mem_ctx, r.buffer, r.returned, &ctr->info2);
851 break;
852 case 3:
853 decode_printer_driver_3(mem_ctx, r.buffer, r.returned, &ctr->info3);
854 break;
855 default:
856 DEBUG(10, ("cli_spoolss_enumprinterdrivers: unknown info level %d\n",
857 level));
858 return WERR_UNKNOWN_LEVEL;
862 done:
863 prs_mem_free(&qbuf);
864 prs_mem_free(&rbuf);
866 return result;
870 /*********************************************************************************
871 Win32 API - GetPrinterDriverDirectory()
872 ********************************************************************************/
873 /**********************************************************************
874 * Get installed printer drivers for a given printer
876 WERROR cli_spoolss_getprinterdriverdir (struct cli_state *cli,
877 TALLOC_CTX *mem_ctx,
878 uint32 offered, uint32 *needed,
879 uint32 level, char *env,
880 DRIVER_DIRECTORY_CTR *ctr)
882 prs_struct qbuf, rbuf;
883 SPOOL_Q_GETPRINTERDRIVERDIR q;
884 SPOOL_R_GETPRINTERDRIVERDIR r;
885 NEW_BUFFER buffer;
886 WERROR result = W_ERROR(ERRgeneral);
887 fstring server;
889 ZERO_STRUCT(q);
890 ZERO_STRUCT(r);
892 slprintf (server, sizeof(fstring)-1, "\\\\%s", cli->desthost);
893 strupper (server);
895 /* Initialise input parameters */
897 init_buffer(&buffer, offered, mem_ctx);
899 prs_init(&qbuf, MAX_PDU_FRAG_LEN, mem_ctx, MARSHALL);
900 prs_init(&rbuf, 0, mem_ctx, UNMARSHALL);
902 /* Write the request */
904 make_spoolss_q_getprinterdriverdir(&q, server, env, level, &buffer,
905 offered);
907 /* Marshall data and send request */
909 if (!spoolss_io_q_getprinterdriverdir ("", &q, &qbuf, 0) ||
910 !rpc_api_pipe_req (cli, SPOOLSS_GETPRINTERDRIVERDIRECTORY,
911 &qbuf, &rbuf))
912 goto done;
914 /* Unmarshall response */
916 if (spoolss_io_r_getprinterdriverdir ("", &r, &rbuf, 0)) {
917 if (needed)
918 *needed = r.needed;
921 /* Return output parameters */
923 result = r.status;
925 if (W_ERROR_IS_OK(result)) {
926 switch (level) {
927 case 1:
928 decode_printerdriverdir_1(mem_ctx, r.buffer, 1,
929 &ctr->info1);
930 break;
934 done:
935 prs_mem_free(&qbuf);
936 prs_mem_free(&rbuf);
938 return result;
941 /*********************************************************************************
942 Win32 API - AddPrinterDriver()
943 ********************************************************************************/
944 /**********************************************************************
945 * Install a printer driver
947 WERROR cli_spoolss_addprinterdriver (struct cli_state *cli,
948 TALLOC_CTX *mem_ctx, uint32 level,
949 PRINTER_DRIVER_CTR *ctr)
951 prs_struct qbuf, rbuf;
952 SPOOL_Q_ADDPRINTERDRIVER q;
953 SPOOL_R_ADDPRINTERDRIVER r;
954 WERROR result = W_ERROR(ERRgeneral);
955 fstring server;
957 ZERO_STRUCT(q);
958 ZERO_STRUCT(r);
960 slprintf (server, sizeof(fstring)-1, "\\\\%s", cli->desthost);
961 strupper (server);
963 /* Initialise input parameters */
965 prs_init(&qbuf, MAX_PDU_FRAG_LEN, mem_ctx, MARSHALL);
966 prs_init(&rbuf, 0, mem_ctx, UNMARSHALL);
968 /* Write the request */
970 make_spoolss_q_addprinterdriver (mem_ctx, &q, server, level, ctr);
972 /* Marshall data and send request */
974 if (!spoolss_io_q_addprinterdriver ("", &q, &qbuf, 0) ||
975 !rpc_api_pipe_req (cli, SPOOLSS_ADDPRINTERDRIVER, &qbuf, &rbuf))
976 goto done;
978 /* Unmarshall response */
980 if (!spoolss_io_r_addprinterdriver ("", &r, &rbuf, 0))
981 goto done;
983 /* Return output parameters */
985 result = r.status;
987 done:
988 prs_mem_free(&qbuf);
989 prs_mem_free(&rbuf);
991 return result;
994 /*********************************************************************************
995 Win32 API - AddPrinter()
996 ********************************************************************************/
997 /**********************************************************************
998 * Install a printer
1000 WERROR cli_spoolss_addprinterex (struct cli_state *cli, TALLOC_CTX *mem_ctx,
1001 uint32 level, PRINTER_INFO_CTR*ctr)
1003 prs_struct qbuf, rbuf;
1004 SPOOL_Q_ADDPRINTEREX q;
1005 SPOOL_R_ADDPRINTEREX r;
1006 WERROR result = W_ERROR(ERRgeneral);
1007 fstring server,
1008 client,
1009 user;
1011 ZERO_STRUCT(q);
1012 ZERO_STRUCT(r);
1014 slprintf (client, sizeof(fstring)-1, "\\\\%s", cli->desthost);
1015 strupper (client);
1016 slprintf (server, sizeof(fstring)-1, "\\\\%s", cli->desthost);
1017 strupper (server);
1018 fstrcpy (user, cli->user_name);
1020 /* Initialise input parameters */
1022 prs_init(&qbuf, MAX_PDU_FRAG_LEN, mem_ctx, MARSHALL);
1023 prs_init(&rbuf, 0, mem_ctx, UNMARSHALL);
1025 /* Write the request */
1027 make_spoolss_q_addprinterex (mem_ctx, &q, server, client, user,
1028 level, ctr);
1030 /* Marshall data and send request */
1032 if (!spoolss_io_q_addprinterex ("", &q, &qbuf, 0) ||
1033 !rpc_api_pipe_req (cli, SPOOLSS_ADDPRINTEREX, &qbuf, &rbuf))
1034 goto done;
1036 /* Unmarshall response */
1038 if (!spoolss_io_r_addprinterex ("", &r, &rbuf, 0))
1039 goto done;
1041 /* Return output parameters */
1043 result = r.status;
1045 done:
1046 prs_mem_free(&qbuf);
1047 prs_mem_free(&rbuf);
1049 return result;
1052 /*********************************************************************************
1053 Win32 API - DeltePrinterDriver()
1054 ********************************************************************************/
1055 /**********************************************************************
1056 * Delete a Printer Driver from the server (does not remove
1057 * the driver files
1059 WERROR cli_spoolss_deleteprinterdriver (struct cli_state *cli,
1060 TALLOC_CTX *mem_ctx, char *arch,
1061 char *driver)
1063 prs_struct qbuf, rbuf;
1064 SPOOL_Q_DELETEPRINTERDRIVER q;
1065 SPOOL_R_DELETEPRINTERDRIVER r;
1066 WERROR result = W_ERROR(ERRgeneral);
1067 fstring server;
1069 ZERO_STRUCT(q);
1070 ZERO_STRUCT(r);
1073 /* Initialise input parameters */
1074 prs_init(&qbuf, MAX_PDU_FRAG_LEN, mem_ctx, MARSHALL);
1075 prs_init(&rbuf, 0, mem_ctx, UNMARSHALL);
1077 slprintf (server, sizeof(fstring)-1, "\\\\%s", cli->desthost);
1078 strupper (server);
1080 /* Write the request */
1082 make_spoolss_q_deleteprinterdriver(mem_ctx, &q, server, arch, driver);
1084 /* Marshall data and send request */
1086 if (!spoolss_io_q_deleteprinterdriver ("", &q, &qbuf, 0) ||
1087 !rpc_api_pipe_req (cli,SPOOLSS_DELETEPRINTERDRIVER , &qbuf, &rbuf))
1088 goto done;
1090 /* Unmarshall response */
1092 if (!spoolss_io_r_deleteprinterdriver ("", &r, &rbuf, 0))
1093 goto done;
1095 /* Return output parameters */
1097 result = r.status;
1099 done:
1100 prs_mem_free(&qbuf);
1101 prs_mem_free(&rbuf);
1103 return result;
1106 /*********************************************************************************
1107 Win32 API - GetPrinterProcessorDirectory()
1108 ********************************************************************************/
1110 WERROR cli_spoolss_getprintprocessordirectory(struct cli_state *cli,
1111 TALLOC_CTX *mem_ctx,
1112 uint32 offered, uint32 *needed,
1113 char *name, char *environment,
1114 fstring procdir)
1116 prs_struct qbuf, rbuf;
1117 SPOOL_Q_GETPRINTPROCESSORDIRECTORY q;
1118 SPOOL_R_GETPRINTPROCESSORDIRECTORY r;
1119 int level = 1;
1120 WERROR result = W_ERROR(ERRgeneral);
1121 NEW_BUFFER buffer;
1123 ZERO_STRUCT(q);
1124 ZERO_STRUCT(r);
1126 /* Initialise parse structures */
1128 prs_init(&qbuf, MAX_PDU_FRAG_LEN, mem_ctx, MARSHALL);
1129 prs_init(&rbuf, 0, mem_ctx, UNMARSHALL);
1131 /* Initialise input parameters */
1133 init_buffer(&buffer, offered, mem_ctx);
1135 make_spoolss_q_getprintprocessordirectory(
1136 &q, name, environment, level, &buffer, offered);
1138 /* Marshall data and send request */
1140 if (!spoolss_io_q_getprintprocessordirectory("", &q, &qbuf, 0) ||
1141 !rpc_api_pipe_req(cli, SPOOLSS_GETPRINTPROCESSORDIRECTORY,
1142 &qbuf, &rbuf))
1143 goto done;
1145 /* Unmarshall response */
1147 if (!spoolss_io_r_getprintprocessordirectory("", &r, &rbuf, 0))
1148 goto done;
1150 /* Return output parameters */
1152 result = r.status;
1154 if (needed)
1155 *needed = r.needed;
1157 if (W_ERROR_IS_OK(result))
1158 fstrcpy(procdir, "Not implemented!");
1160 done:
1161 prs_mem_free(&qbuf);
1162 prs_mem_free(&rbuf);
1164 return result;
1167 /** Add a form to a printer.
1169 * @param cli Pointer to client state structure which is open
1170 * on the SPOOLSS pipe.
1171 * @param mem_ctx Pointer to an initialised talloc context.
1173 * @param handle Policy handle opened with cli_spoolss_open_printer_ex
1174 * or cli_spoolss_addprinterex.
1175 * @param level Form info level to add - should always be 1.
1176 * @param form A pointer to the form to be added.
1180 WERROR cli_spoolss_addform(struct cli_state *cli, TALLOC_CTX *mem_ctx,
1181 POLICY_HND *handle, uint32 level, FORM *form)
1183 prs_struct qbuf, rbuf;
1184 SPOOL_Q_ADDFORM q;
1185 SPOOL_R_ADDFORM r;
1186 WERROR result = W_ERROR(ERRgeneral);
1188 ZERO_STRUCT(q);
1189 ZERO_STRUCT(r);
1191 /* Initialise parse structures */
1193 prs_init(&qbuf, MAX_PDU_FRAG_LEN, mem_ctx, MARSHALL);
1194 prs_init(&rbuf, 0, mem_ctx, UNMARSHALL);
1196 /* Initialise input parameters */
1198 make_spoolss_q_addform(&q, handle, level, form);
1200 /* Marshall data and send request */
1202 if (!spoolss_io_q_addform("", &q, &qbuf, 0) ||
1203 !rpc_api_pipe_req(cli, SPOOLSS_ADDFORM, &qbuf, &rbuf))
1204 goto done;
1206 /* Unmarshall response */
1208 if (!spoolss_io_r_addform("", &r, &rbuf, 0))
1209 goto done;
1211 /* Return output parameters */
1213 result = r.status;
1215 done:
1216 prs_mem_free(&qbuf);
1217 prs_mem_free(&rbuf);
1219 return result;
1222 /** Set a form on a printer.
1224 * @param cli Pointer to client state structure which is open
1225 * on the SPOOLSS pipe.
1226 * @param mem_ctx Pointer to an initialised talloc context.
1228 * @param handle Policy handle opened with cli_spoolss_open_printer_ex
1229 * or cli_spoolss_addprinterex.
1230 * @param level Form info level to set - should always be 1.
1231 * @param form A pointer to the form to be set.
1235 WERROR cli_spoolss_setform(struct cli_state *cli, TALLOC_CTX *mem_ctx,
1236 POLICY_HND *handle, uint32 level, char *form_name,
1237 FORM *form)
1239 prs_struct qbuf, rbuf;
1240 SPOOL_Q_SETFORM q;
1241 SPOOL_R_SETFORM r;
1242 WERROR result = W_ERROR(ERRgeneral);
1244 ZERO_STRUCT(q);
1245 ZERO_STRUCT(r);
1247 /* Initialise parse structures */
1249 prs_init(&qbuf, MAX_PDU_FRAG_LEN, mem_ctx, MARSHALL);
1250 prs_init(&rbuf, 0, mem_ctx, UNMARSHALL);
1252 /* Initialise input parameters */
1254 make_spoolss_q_setform(&q, handle, level, form_name, form);
1256 /* Marshall data and send request */
1258 if (!spoolss_io_q_setform("", &q, &qbuf, 0) ||
1259 !rpc_api_pipe_req(cli, SPOOLSS_SETFORM, &qbuf, &rbuf))
1260 goto done;
1262 /* Unmarshall response */
1264 if (!spoolss_io_r_setform("", &r, &rbuf, 0))
1265 goto done;
1267 /* Return output parameters */
1269 result = r.status;
1271 if (!W_ERROR_IS_OK(result))
1272 goto done;
1276 done:
1277 prs_mem_free(&qbuf);
1278 prs_mem_free(&rbuf);
1280 return result;
1283 /** Get a form on a printer.
1285 * @param cli Pointer to client state structure which is open
1286 * on the SPOOLSS pipe.
1287 * @param mem_ctx Pointer to an initialised talloc context.
1289 * @param handle Policy handle opened with cli_spoolss_open_printer_ex
1290 * or cli_spoolss_addprinterex.
1291 * @param formname Name of the form to get
1292 * @param level Form info level to get - should always be 1.
1296 WERROR cli_spoolss_getform(struct cli_state *cli, TALLOC_CTX *mem_ctx,
1297 uint32 offered, uint32 *needed,
1298 POLICY_HND *handle, char *formname, uint32 level,
1299 FORM_1 *form)
1301 prs_struct qbuf, rbuf;
1302 SPOOL_Q_GETFORM q;
1303 SPOOL_R_GETFORM r;
1304 WERROR result = W_ERROR(ERRgeneral);
1305 NEW_BUFFER buffer;
1307 ZERO_STRUCT(q);
1308 ZERO_STRUCT(r);
1310 /* Initialise parse structures */
1312 init_buffer(&buffer, offered, mem_ctx);
1314 prs_init(&qbuf, MAX_PDU_FRAG_LEN, mem_ctx, MARSHALL);
1315 prs_init(&rbuf, 0, mem_ctx, UNMARSHALL);
1317 /* Initialise input parameters */
1319 make_spoolss_q_getform(&q, handle, formname, level, &buffer, offered);
1321 /* Marshall data and send request */
1323 if (!spoolss_io_q_getform("", &q, &qbuf, 0) ||
1324 !rpc_api_pipe_req(cli, SPOOLSS_GETFORM, &qbuf, &rbuf))
1325 goto done;
1327 /* Unmarshall response */
1329 if (!spoolss_io_r_getform("", &r, &rbuf, 0))
1330 goto done;
1332 /* Return output parameters */
1334 result = r.status;
1336 if (needed)
1337 *needed = r.needed;
1339 if (W_ERROR_IS_OK(result)) {
1340 switch(level) {
1341 case 1:
1342 smb_io_form_1("", r.buffer, form, 0);
1343 break;
1344 default:
1345 DEBUG(10, ("cli_spoolss_getform: unknown info level %d", level));
1346 return WERR_UNKNOWN_LEVEL;
1350 done:
1351 prs_mem_free(&qbuf);
1352 prs_mem_free(&rbuf);
1354 return result;
1357 /** Delete a form on a printer.
1359 * @param cli Pointer to client state structure which is open
1360 * on the SPOOLSS pipe.
1361 * @param mem_ctx Pointer to an initialised talloc context.
1363 * @param handle Policy handle opened with cli_spoolss_open_printer_ex
1364 * or cli_spoolss_addprinterex.
1365 * @param form The name of the form to delete.
1369 WERROR cli_spoolss_deleteform(struct cli_state *cli, TALLOC_CTX *mem_ctx,
1370 POLICY_HND *handle, char *form_name)
1372 prs_struct qbuf, rbuf;
1373 SPOOL_Q_DELETEFORM q;
1374 SPOOL_R_DELETEFORM r;
1375 WERROR result = W_ERROR(ERRgeneral);
1377 ZERO_STRUCT(q);
1378 ZERO_STRUCT(r);
1380 /* Initialise parse structures */
1382 prs_init(&qbuf, MAX_PDU_FRAG_LEN, mem_ctx, MARSHALL);
1383 prs_init(&rbuf, 0, mem_ctx, UNMARSHALL);
1385 /* Initialise input parameters */
1387 make_spoolss_q_deleteform(&q, handle, form_name);
1389 /* Marshall data and send request */
1391 if (!spoolss_io_q_deleteform("", &q, &qbuf, 0) ||
1392 !rpc_api_pipe_req(cli, SPOOLSS_DELETEFORM, &qbuf, &rbuf))
1393 goto done;
1395 /* Unmarshall response */
1397 if (!spoolss_io_r_deleteform("", &r, &rbuf, 0))
1398 goto done;
1400 /* Return output parameters */
1402 result = r.status;
1404 done:
1405 prs_mem_free(&qbuf);
1406 prs_mem_free(&rbuf);
1408 return result;
1411 static void decode_forms_1(TALLOC_CTX *mem_ctx, NEW_BUFFER *buffer,
1412 uint32 num_forms, FORM_1 **forms)
1414 int i;
1416 *forms = (FORM_1 *)talloc(mem_ctx, num_forms * sizeof(FORM_1));
1417 buffer->prs.data_offset = 0;
1419 for (i = 0; i < num_forms; i++)
1420 smb_io_form_1("", buffer, &((*forms)[i]), 0);
1423 /** Enumerate forms
1425 * @param cli Pointer to client state structure which is open
1426 * on the SPOOLSS pipe.
1427 * @param mem_ctx Pointer to an initialised talloc context.
1429 * @param offered Buffer size offered in the request.
1430 * @param needed Number of bytes needed to complete the request.
1431 * may be NULL.
1432 * or cli_spoolss_addprinterex.
1433 * @param level Form info level to get - should always be 1.
1434 * @param handle Open policy handle
1438 WERROR cli_spoolss_enumforms(struct cli_state *cli, TALLOC_CTX *mem_ctx,
1439 uint32 offered, uint32 *needed,
1440 POLICY_HND *handle, int level, uint32 *num_forms,
1441 FORM_1 **forms)
1443 prs_struct qbuf, rbuf;
1444 SPOOL_Q_ENUMFORMS q;
1445 SPOOL_R_ENUMFORMS r;
1446 WERROR result = W_ERROR(ERRgeneral);
1447 NEW_BUFFER buffer;
1449 ZERO_STRUCT(q);
1450 ZERO_STRUCT(r);
1452 /* Initialise parse structures */
1454 init_buffer(&buffer, offered, mem_ctx);
1456 prs_init(&qbuf, MAX_PDU_FRAG_LEN, mem_ctx, MARSHALL);
1457 prs_init(&rbuf, 0, mem_ctx, UNMARSHALL);
1459 /* Initialise input parameters */
1461 make_spoolss_q_enumforms(&q, handle, level, &buffer, offered);
1463 /* Marshall data and send request */
1465 if (!spoolss_io_q_enumforms("", &q, &qbuf, 0) ||
1466 !rpc_api_pipe_req(cli, SPOOLSS_ENUMFORMS, &qbuf, &rbuf))
1467 goto done;
1469 /* Unmarshall response */
1471 if (!spoolss_io_r_enumforms("", &r, &rbuf, 0))
1472 goto done;
1474 /* Return output parameters */
1476 result = r.status;
1478 if (needed)
1479 *needed = r.needed;
1481 if (num_forms)
1482 *num_forms = r.numofforms;
1484 decode_forms_1(mem_ctx, r.buffer, *num_forms, forms);
1486 done:
1487 prs_mem_free(&qbuf);
1488 prs_mem_free(&rbuf);
1490 return result;
1493 static void decode_jobs_1(TALLOC_CTX *mem_ctx, NEW_BUFFER *buffer,
1494 uint32 num_jobs, JOB_INFO_1 **jobs)
1496 uint32 i;
1498 *jobs = (JOB_INFO_1 *)talloc(mem_ctx, num_jobs * sizeof(JOB_INFO_1));
1499 buffer->prs.data_offset = 0;
1501 for (i = 0; i < num_jobs; i++)
1502 smb_io_job_info_1("", buffer, &((*jobs)[i]), 0);
1505 static void decode_jobs_2(TALLOC_CTX *mem_ctx, NEW_BUFFER *buffer,
1506 uint32 num_jobs, JOB_INFO_2 **jobs)
1508 uint32 i;
1510 *jobs = (JOB_INFO_2 *)talloc(mem_ctx, num_jobs * sizeof(JOB_INFO_2));
1511 buffer->prs.data_offset = 0;
1513 for (i = 0; i < num_jobs; i++)
1514 smb_io_job_info_2("", buffer, &((*jobs)[i]), 0);
1517 /* Enumerate jobs */
1519 WERROR cli_spoolss_enumjobs(struct cli_state *cli, TALLOC_CTX *mem_ctx,
1520 uint32 offered, uint32 *needed,
1521 POLICY_HND *hnd, uint32 level, uint32 firstjob,
1522 uint32 num_jobs, uint32 *returned, JOB_INFO_CTR *ctr)
1524 prs_struct qbuf, rbuf;
1525 SPOOL_Q_ENUMJOBS q;
1526 SPOOL_R_ENUMJOBS r;
1527 WERROR result = W_ERROR(ERRgeneral);
1528 NEW_BUFFER buffer;
1530 ZERO_STRUCT(q);
1531 ZERO_STRUCT(r);
1533 /* Initialise parse structures */
1535 init_buffer(&buffer, offered, mem_ctx);
1537 prs_init(&qbuf, MAX_PDU_FRAG_LEN, mem_ctx, MARSHALL);
1538 prs_init(&rbuf, 0, mem_ctx, UNMARSHALL);
1540 /* Initialise input parameters */
1542 make_spoolss_q_enumjobs(&q, hnd, firstjob, num_jobs, level, &buffer,
1543 offered);
1545 /* Marshall data and send request */
1547 if (!spoolss_io_q_enumjobs("", &q, &qbuf, 0) ||
1548 !rpc_api_pipe_req(cli, SPOOLSS_ENUMJOBS, &qbuf, &rbuf))
1549 goto done;
1551 /* Unmarshall response */
1553 if (!spoolss_io_r_enumjobs("", &r, &rbuf, 0))
1554 goto done;
1556 /* Return output parameters */
1558 result = r.status;
1560 if (needed)
1561 *needed = r.needed;
1563 if (!W_ERROR_IS_OK(r.status))
1564 goto done;
1566 *returned = r.returned;
1568 switch(level) {
1569 case 1:
1570 decode_jobs_1(mem_ctx, r.buffer, r.returned,
1571 &ctr->job.job_info_1);
1572 break;
1573 case 2:
1574 decode_jobs_2(mem_ctx, r.buffer, r.returned,
1575 &ctr->job.job_info_2);
1576 break;
1577 default:
1578 DEBUG(3, ("unsupported info level %d", level));
1579 break;
1582 done:
1583 prs_mem_free(&qbuf);
1584 prs_mem_free(&rbuf);
1586 return result;
1589 /* Set job */
1591 WERROR cli_spoolss_setjob(struct cli_state *cli, TALLOC_CTX *mem_ctx,
1592 POLICY_HND *hnd, uint32 jobid, uint32 level,
1593 uint32 command)
1595 prs_struct qbuf, rbuf;
1596 SPOOL_Q_SETJOB q;
1597 SPOOL_R_SETJOB r;
1598 WERROR result = W_ERROR(ERRgeneral);
1600 ZERO_STRUCT(q);
1601 ZERO_STRUCT(r);
1603 /* Initialise parse structures */
1605 prs_init(&qbuf, MAX_PDU_FRAG_LEN, mem_ctx, MARSHALL);
1606 prs_init(&rbuf, 0, mem_ctx, UNMARSHALL);
1608 /* Initialise input parameters */
1610 make_spoolss_q_setjob(&q, hnd, jobid, level, command);
1612 /* Marshall data and send request */
1614 if (!spoolss_io_q_setjob("", &q, &qbuf, 0) ||
1615 !rpc_api_pipe_req(cli, SPOOLSS_SETJOB, &qbuf, &rbuf))
1616 goto done;
1618 /* Unmarshall response */
1620 if (!spoolss_io_r_setjob("", &r, &rbuf, 0))
1621 goto done;
1623 /* Return output parameters */
1625 result = r.status;
1627 done:
1628 prs_mem_free(&qbuf);
1629 prs_mem_free(&rbuf);
1631 return result;
1634 /* Get job */
1636 WERROR cli_spoolss_getjob(struct cli_state *cli, TALLOC_CTX *mem_ctx,
1637 uint32 offered, uint32 *needed,
1638 POLICY_HND *hnd, uint32 jobid, uint32 level,
1639 JOB_INFO_CTR *ctr)
1641 prs_struct qbuf, rbuf;
1642 SPOOL_Q_GETJOB q;
1643 SPOOL_R_GETJOB r;
1644 WERROR result = W_ERROR(ERRgeneral);
1645 NEW_BUFFER buffer;
1647 ZERO_STRUCT(q);
1648 ZERO_STRUCT(r);
1650 /* Initialise parse structures */
1652 init_buffer(&buffer, offered, mem_ctx);
1654 prs_init(&qbuf, MAX_PDU_FRAG_LEN, mem_ctx, MARSHALL);
1655 prs_init(&rbuf, 0, mem_ctx, UNMARSHALL);
1657 /* Initialise input parameters */
1659 make_spoolss_q_getjob(&q, hnd, jobid, level, &buffer, offered);
1661 /* Marshall data and send request */
1663 if (!spoolss_io_q_getjob("", &q, &qbuf, 0) ||
1664 !rpc_api_pipe_req(cli, SPOOLSS_GETJOB, &qbuf, &rbuf))
1665 goto done;
1667 /* Unmarshall response */
1669 if (!spoolss_io_r_getjob("", &r, &rbuf, 0))
1670 goto done;
1672 /* Return output parameters */
1674 result = r.status;
1676 if (needed)
1677 *needed = r.needed;
1679 if (!W_ERROR_IS_OK(r.status))
1680 goto done;
1682 switch(level) {
1683 case 1:
1684 decode_jobs_1(mem_ctx, r.buffer, 1, &ctr->job.job_info_1);
1685 break;
1686 case 2:
1687 decode_jobs_2(mem_ctx, r.buffer, 1, &ctr->job.job_info_2);
1688 break;
1689 default:
1690 DEBUG(3, ("unsupported info level %d", level));
1691 break;
1694 done:
1695 prs_mem_free(&qbuf);
1696 prs_mem_free(&rbuf);
1698 return result;
1701 /* Startpageprinter. Sent to notify the spooler when a page is about to be
1702 sent to a printer. */
1704 WERROR cli_spoolss_startpageprinter(struct cli_state *cli, TALLOC_CTX *mem_ctx,
1705 POLICY_HND *hnd)
1707 prs_struct qbuf, rbuf;
1708 SPOOL_Q_STARTPAGEPRINTER q;
1709 SPOOL_R_STARTPAGEPRINTER r;
1710 WERROR result = W_ERROR(ERRgeneral);
1712 ZERO_STRUCT(q);
1713 ZERO_STRUCT(r);
1715 /* Initialise parse structures */
1717 prs_init(&qbuf, MAX_PDU_FRAG_LEN, mem_ctx, MARSHALL);
1718 prs_init(&rbuf, 0, mem_ctx, UNMARSHALL);
1720 /* Initialise input parameters */
1722 make_spoolss_q_startpageprinter(&q, hnd);
1724 /* Marshall data and send request */
1726 if (!spoolss_io_q_startpageprinter("", &q, &qbuf, 0) ||
1727 !rpc_api_pipe_req(cli, SPOOLSS_STARTPAGEPRINTER, &qbuf, &rbuf))
1728 goto done;
1730 /* Unmarshall response */
1732 if (!spoolss_io_r_startpageprinter("", &r, &rbuf, 0))
1733 goto done;
1735 /* Return output parameters */
1737 result = r.status;
1739 done:
1740 prs_mem_free(&qbuf);
1741 prs_mem_free(&rbuf);
1743 return result;
1746 /* Endpageprinter. Sent to notify the spooler when a page has finished
1747 being sent to a printer. */
1749 WERROR cli_spoolss_endpageprinter(struct cli_state *cli, TALLOC_CTX *mem_ctx,
1750 POLICY_HND *hnd)
1752 prs_struct qbuf, rbuf;
1753 SPOOL_Q_ENDPAGEPRINTER q;
1754 SPOOL_R_ENDPAGEPRINTER r;
1755 WERROR result = W_ERROR(ERRgeneral);
1757 ZERO_STRUCT(q);
1758 ZERO_STRUCT(r);
1760 /* Initialise parse structures */
1762 prs_init(&qbuf, MAX_PDU_FRAG_LEN, mem_ctx, MARSHALL);
1763 prs_init(&rbuf, 0, mem_ctx, UNMARSHALL);
1765 /* Initialise input parameters */
1767 make_spoolss_q_endpageprinter(&q, hnd);
1769 /* Marshall data and send request */
1771 if (!spoolss_io_q_endpageprinter("", &q, &qbuf, 0) ||
1772 !rpc_api_pipe_req(cli, SPOOLSS_ENDPAGEPRINTER, &qbuf, &rbuf))
1773 goto done;
1775 /* Unmarshall response */
1777 if (!spoolss_io_r_endpageprinter("", &r, &rbuf, 0))
1778 goto done;
1780 /* Return output parameters */
1782 result = r.status;
1784 done:
1785 prs_mem_free(&qbuf);
1786 prs_mem_free(&rbuf);
1788 return result;
1791 /* Startdocprinter. Sent to notify the spooler that a document is about
1792 to be spooled for printing. */
1794 WERROR cli_spoolss_startdocprinter(struct cli_state *cli, TALLOC_CTX *mem_ctx,
1795 POLICY_HND *hnd, char *docname,
1796 char *outputfile, char *datatype,
1797 uint32 *jobid)
1799 prs_struct qbuf, rbuf;
1800 SPOOL_Q_STARTDOCPRINTER q;
1801 SPOOL_R_STARTDOCPRINTER r;
1802 WERROR result = W_ERROR(ERRgeneral);
1803 uint32 level = 1;
1805 ZERO_STRUCT(q);
1806 ZERO_STRUCT(r);
1808 /* Initialise parse structures */
1810 prs_init(&qbuf, MAX_PDU_FRAG_LEN, mem_ctx, MARSHALL);
1811 prs_init(&rbuf, 0, mem_ctx, UNMARSHALL);
1813 /* Initialise input parameters */
1815 make_spoolss_q_startdocprinter(&q, hnd, level, docname, outputfile,
1816 datatype);
1818 /* Marshall data and send request */
1820 if (!spoolss_io_q_startdocprinter("", &q, &qbuf, 0) ||
1821 !rpc_api_pipe_req(cli, SPOOLSS_STARTDOCPRINTER, &qbuf, &rbuf))
1822 goto done;
1824 /* Unmarshall response */
1826 if (!spoolss_io_r_startdocprinter("", &r, &rbuf, 0))
1827 goto done;
1829 /* Return output parameters */
1831 result = r.status;
1833 if (W_ERROR_IS_OK(result))
1834 *jobid = r.jobid;
1836 done:
1837 prs_mem_free(&qbuf);
1838 prs_mem_free(&rbuf);
1840 return result;
1843 /* Enddocprinter. Sent to notify the spooler that a document has finished
1844 being spooled. */
1846 WERROR cli_spoolss_enddocprinter(struct cli_state *cli, TALLOC_CTX *mem_ctx,
1847 POLICY_HND *hnd)
1849 prs_struct qbuf, rbuf;
1850 SPOOL_Q_ENDDOCPRINTER q;
1851 SPOOL_R_ENDDOCPRINTER r;
1852 WERROR result = W_ERROR(ERRgeneral);
1854 ZERO_STRUCT(q);
1855 ZERO_STRUCT(r);
1857 /* Initialise parse structures */
1859 prs_init(&qbuf, MAX_PDU_FRAG_LEN, mem_ctx, MARSHALL);
1860 prs_init(&rbuf, 0, mem_ctx, UNMARSHALL);
1862 /* Initialise input parameters */
1864 make_spoolss_q_enddocprinter(&q, hnd);
1866 /* Marshall data and send request */
1868 if (!spoolss_io_q_enddocprinter("", &q, &qbuf, 0) ||
1869 !rpc_api_pipe_req(cli, SPOOLSS_ENDDOCPRINTER, &qbuf, &rbuf))
1870 goto done;
1872 /* Unmarshall response */
1874 if (!spoolss_io_r_enddocprinter("", &r, &rbuf, 0))
1875 goto done;
1877 /* Return output parameters */
1879 result = r.status;
1881 done:
1882 prs_mem_free(&qbuf);
1883 prs_mem_free(&rbuf);
1885 return result;
1888 /* Get printer data */
1890 WERROR cli_spoolss_getprinterdata(struct cli_state *cli, TALLOC_CTX *mem_ctx,
1891 uint32 offered, uint32 *needed,
1892 POLICY_HND *hnd, char *valuename,
1893 REGISTRY_VALUE *value)
1895 prs_struct qbuf, rbuf;
1896 SPOOL_Q_GETPRINTERDATA q;
1897 SPOOL_R_GETPRINTERDATA r;
1898 WERROR result = W_ERROR(ERRgeneral);
1900 ZERO_STRUCT(q);
1901 ZERO_STRUCT(r);
1903 /* Initialise parse structures */
1905 prs_init(&qbuf, MAX_PDU_FRAG_LEN, mem_ctx, MARSHALL);
1906 prs_init(&rbuf, 0, mem_ctx, UNMARSHALL);
1908 /* Initialise input parameters */
1910 make_spoolss_q_getprinterdata(&q, hnd, valuename, offered);
1912 /* Marshall data and send request */
1914 if (!spoolss_io_q_getprinterdata("", &q, &qbuf, 0) ||
1915 !rpc_api_pipe_req(cli, SPOOLSS_GETPRINTERDATA, &qbuf, &rbuf))
1916 goto done;
1918 /* Unmarshall response */
1920 if (!spoolss_io_r_getprinterdata("", &r, &rbuf, 0))
1921 goto done;
1923 result = r.status;
1925 if (needed)
1926 *needed = r.needed;
1928 if (!W_ERROR_IS_OK(r.status))
1929 goto done;
1931 /* Return output parameters */
1933 value->data_p = talloc_memdup(mem_ctx, r.data, r.needed);
1934 value->type = r.type;
1935 value->size = r.size;
1937 done:
1938 prs_mem_free(&qbuf);
1939 prs_mem_free(&rbuf);
1941 return result;
1944 WERROR cli_spoolss_getprinterdataex(struct cli_state *cli, TALLOC_CTX *mem_ctx,
1945 uint32 offered, uint32 *needed,
1946 POLICY_HND *hnd, char *keyname,
1947 char *valuename, REGISTRY_VALUE *value)
1949 prs_struct qbuf, rbuf;
1950 SPOOL_Q_GETPRINTERDATAEX q;
1951 SPOOL_R_GETPRINTERDATAEX r;
1952 WERROR result = W_ERROR(ERRgeneral);
1954 ZERO_STRUCT(q);
1955 ZERO_STRUCT(r);
1957 /* Initialise parse structures */
1959 prs_init(&qbuf, MAX_PDU_FRAG_LEN, mem_ctx, MARSHALL);
1960 prs_init(&rbuf, 0, mem_ctx, UNMARSHALL);
1962 /* Initialise input parameters */
1964 make_spoolss_q_getprinterdataex(&q, hnd, keyname, valuename, offered);
1966 /* Marshall data and send request */
1968 if (!spoolss_io_q_getprinterdataex("", &q, &qbuf, 0) ||
1969 !rpc_api_pipe_req(cli, SPOOLSS_GETPRINTERDATAEX, &qbuf, &rbuf))
1970 goto done;
1972 /* Unmarshall response */
1974 if (!spoolss_io_r_getprinterdataex("", &r, &rbuf, 0))
1975 goto done;
1977 result = r.status;
1979 if (needed)
1980 *needed = r.needed;
1982 if (!W_ERROR_IS_OK(r.status))
1983 goto done;
1985 /* Return output parameters */
1987 value->data_p = talloc_memdup(mem_ctx, r.data, r.needed);
1988 value->type = r.type;
1989 value->size = r.needed;
1991 done:
1992 prs_mem_free(&qbuf);
1993 prs_mem_free(&rbuf);
1995 return result;
1998 /* Set printer data */
2000 WERROR cli_spoolss_setprinterdata(struct cli_state *cli, TALLOC_CTX *mem_ctx,
2001 POLICY_HND *hnd, REGISTRY_VALUE *value)
2003 prs_struct qbuf, rbuf;
2004 SPOOL_Q_SETPRINTERDATA q;
2005 SPOOL_R_SETPRINTERDATA r;
2006 WERROR result = W_ERROR(ERRgeneral);
2008 ZERO_STRUCT(q);
2009 ZERO_STRUCT(r);
2011 /* Initialise parse structures */
2013 prs_init(&qbuf, MAX_PDU_FRAG_LEN, mem_ctx, MARSHALL);
2014 prs_init(&rbuf, 0, mem_ctx, UNMARSHALL);
2016 /* Initialise input parameters */
2018 make_spoolss_q_setprinterdata(
2019 &q, hnd, value->valuename, value->type, value->data_p, value->size);
2021 /* Marshall data and send request */
2023 if (!spoolss_io_q_setprinterdata("", &q, &qbuf, 0) ||
2024 !rpc_api_pipe_req(cli, SPOOLSS_SETPRINTERDATA, &qbuf, &rbuf))
2025 goto done;
2027 /* Unmarshall response */
2029 if (!spoolss_io_r_setprinterdata("", &r, &rbuf, 0))
2030 goto done;
2032 result = r.status;
2034 if (!W_ERROR_IS_OK(r.status))
2035 goto done;
2037 done:
2038 prs_mem_free(&qbuf);
2039 prs_mem_free(&rbuf);
2041 return result;
2044 WERROR cli_spoolss_setprinterdataex(struct cli_state *cli, TALLOC_CTX *mem_ctx,
2045 POLICY_HND *hnd, char *keyname,
2046 REGISTRY_VALUE *value)
2048 prs_struct qbuf, rbuf;
2049 SPOOL_Q_SETPRINTERDATAEX q;
2050 SPOOL_R_SETPRINTERDATAEX r;
2051 WERROR result = W_ERROR(ERRgeneral);
2053 ZERO_STRUCT(q);
2054 ZERO_STRUCT(r);
2056 /* Initialise parse structures */
2058 prs_init(&qbuf, MAX_PDU_FRAG_LEN, mem_ctx, MARSHALL);
2059 prs_init(&rbuf, 0, mem_ctx, UNMARSHALL);
2061 /* Initialise input parameters */
2063 make_spoolss_q_setprinterdataex(
2064 &q, hnd, keyname, value->valuename, value->type, value->data_p,
2065 value->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))
2071 goto done;
2073 /* Unmarshall response */
2075 if (!spoolss_io_r_setprinterdataex("", &r, &rbuf, 0))
2076 goto done;
2078 result = r.status;
2080 if (!W_ERROR_IS_OK(r.status))
2081 goto done;
2083 done:
2084 prs_mem_free(&qbuf);
2085 prs_mem_free(&rbuf);
2087 return result;
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 REGISTRY_VALUE *value)
2098 prs_struct qbuf, rbuf;
2099 SPOOL_Q_ENUMPRINTERDATA q;
2100 SPOOL_R_ENUMPRINTERDATA r;
2101 WERROR result = W_ERROR(ERRgeneral);
2103 ZERO_STRUCT(q);
2104 ZERO_STRUCT(r);
2106 /* Initialise parse structures */
2108 prs_init(&qbuf, MAX_PDU_FRAG_LEN, mem_ctx, MARSHALL);
2109 prs_init(&rbuf, 0, mem_ctx, UNMARSHALL);
2111 /* Initialise input parameters */
2113 make_spoolss_q_enumprinterdata(&q, hnd, ndx, value_offered, data_offered);
2115 /* Marshall data and send request */
2117 if (!spoolss_io_q_enumprinterdata("", &q, &qbuf, 0) ||
2118 !rpc_api_pipe_req(cli, SPOOLSS_ENUMPRINTERDATA, &qbuf, &rbuf))
2119 goto done;
2121 /* Unmarshall response */
2123 if (!spoolss_io_r_enumprinterdata("", &r, &rbuf, 0))
2124 goto done;
2126 result = r.status;
2128 if (!W_ERROR_IS_OK(r.status))
2129 goto done;
2131 /* Return data */
2133 if (value_needed)
2134 *value_needed = r.realvaluesize;
2136 if (data_needed)
2137 *data_needed = r.realdatasize;
2139 if (value) {
2140 rpcstr_pull(value->valuename, r.value, sizeof(value->valuename), -1,
2141 STR_TERMINATE);
2142 value->data_p = talloc_memdup(mem_ctx, r.data, r.realdatasize);
2143 value->type = r.type;
2144 value->size = r.realdatasize;
2147 done:
2148 prs_mem_free(&qbuf);
2149 prs_mem_free(&rbuf);
2151 return result;
2154 WERROR cli_spoolss_enumprinterdataex(struct cli_state *cli, TALLOC_CTX *mem_ctx,
2155 uint32 offered, uint32 *needed,
2156 POLICY_HND *hnd, char *keyname,
2157 REGVAL_CTR *ctr)
2159 prs_struct qbuf, rbuf;
2160 SPOOL_Q_ENUMPRINTERDATAEX q;
2161 SPOOL_R_ENUMPRINTERDATAEX r;
2162 WERROR result = W_ERROR(ERRgeneral);
2163 int i;
2165 ZERO_STRUCT(q);
2166 ZERO_STRUCT(r);
2168 /* Initialise parse structures */
2170 prs_init(&qbuf, MAX_PDU_FRAG_LEN, mem_ctx, MARSHALL);
2171 prs_init(&rbuf, 0, mem_ctx, UNMARSHALL);
2173 /* Initialise input parameters */
2175 make_spoolss_q_enumprinterdataex(&q, hnd, keyname, offered);
2177 /* Marshall data and send request */
2179 if (!spoolss_io_q_enumprinterdataex("", &q, &qbuf, 0) ||
2180 !rpc_api_pipe_req(cli, SPOOLSS_ENUMPRINTERDATAEX, &qbuf, &rbuf))
2181 goto done;
2183 /* Unmarshall response */
2185 if (!spoolss_io_r_enumprinterdataex("", &r, &rbuf, 0))
2186 goto done;
2188 result = r.status;
2190 if (needed)
2191 *needed = r.needed;
2193 if (!W_ERROR_IS_OK(r.status))
2194 goto done;
2196 /* Return data */
2198 ZERO_STRUCTP(ctr);
2199 regval_ctr_init(ctr);
2201 for (i = 0; i < r.returned; i++) {
2202 PRINTER_ENUM_VALUES *v = &r.ctr.values[i];
2203 fstring name;
2205 rpcstr_pull(name, v->valuename.buffer, sizeof(name), -1,
2206 STR_TERMINATE);
2207 regval_ctr_addvalue(ctr, name, v->type, v->data, v->data_len);
2210 done:
2211 prs_mem_free(&qbuf);
2212 prs_mem_free(&rbuf);
2214 return result;
2217 /* Write data to printer */
2219 WERROR cli_spoolss_writeprinter(struct cli_state *cli, TALLOC_CTX *mem_ctx,
2220 POLICY_HND *hnd, uint32 data_size, char *data,
2221 uint32 *num_written)
2223 prs_struct qbuf, rbuf;
2224 SPOOL_Q_WRITEPRINTER q;
2225 SPOOL_R_WRITEPRINTER r;
2226 WERROR result = W_ERROR(ERRgeneral);
2228 ZERO_STRUCT(q);
2229 ZERO_STRUCT(r);
2231 /* Initialise parse structures */
2233 prs_init(&qbuf, MAX_PDU_FRAG_LEN, mem_ctx, MARSHALL);
2234 prs_init(&rbuf, 0, mem_ctx, UNMARSHALL);
2236 /* Initialise input parameters */
2238 make_spoolss_q_writeprinter(&q, hnd, data_size, data);
2240 /* Marshall data and send request */
2242 if (!spoolss_io_q_writeprinter("", &q, &qbuf, 0) ||
2243 !rpc_api_pipe_req(cli, SPOOLSS_WRITEPRINTER, &qbuf, &rbuf))
2244 goto done;
2246 /* Unmarshall response */
2248 if (!spoolss_io_r_writeprinter("", &r, &rbuf, 0))
2249 goto done;
2251 result = r.status;
2253 if (!W_ERROR_IS_OK(r.status))
2254 goto done;
2256 if (num_written)
2257 *num_written = r.buffer_written;
2259 done:
2260 prs_mem_free(&qbuf);
2261 prs_mem_free(&rbuf);
2263 return result;
2266 /* Delete printer data */
2268 WERROR cli_spoolss_deleteprinterdata(struct cli_state *cli, TALLOC_CTX *mem_ctx,
2269 POLICY_HND *hnd, char *valuename)
2271 prs_struct qbuf, rbuf;
2272 SPOOL_Q_DELETEPRINTERDATA q;
2273 SPOOL_R_DELETEPRINTERDATA r;
2274 WERROR result = W_ERROR(ERRgeneral);
2276 ZERO_STRUCT(q);
2277 ZERO_STRUCT(r);
2279 /* Initialise parse structures */
2281 prs_init(&qbuf, MAX_PDU_FRAG_LEN, mem_ctx, MARSHALL);
2282 prs_init(&rbuf, 0, mem_ctx, UNMARSHALL);
2284 /* Initialise input parameters */
2286 make_spoolss_q_deleteprinterdata(&q, hnd, valuename);
2288 /* Marshall data and send request */
2290 if (!spoolss_io_q_deleteprinterdata("", &q, &qbuf, 0) ||
2291 !rpc_api_pipe_req(cli, SPOOLSS_DELETEPRINTERDATA, &qbuf, &rbuf))
2292 goto done;
2294 /* Unmarshall response */
2296 if (!spoolss_io_r_deleteprinterdata("", &r, &rbuf, 0))
2297 goto done;
2299 result = r.status;
2301 if (!W_ERROR_IS_OK(r.status))
2302 goto done;
2304 done:
2305 prs_mem_free(&qbuf);
2306 prs_mem_free(&rbuf);
2308 return result;
2311 WERROR cli_spoolss_deleteprinterdataex(struct cli_state *cli, TALLOC_CTX *mem_ctx,
2312 POLICY_HND *hnd, char *keyname,
2313 char *valuename)
2315 prs_struct qbuf, rbuf;
2316 SPOOL_Q_DELETEPRINTERDATAEX q;
2317 SPOOL_R_DELETEPRINTERDATAEX r;
2318 WERROR result = W_ERROR(ERRgeneral);
2320 ZERO_STRUCT(q);
2321 ZERO_STRUCT(r);
2323 /* Initialise parse structures */
2325 prs_init(&qbuf, MAX_PDU_FRAG_LEN, mem_ctx, MARSHALL);
2326 prs_init(&rbuf, 0, mem_ctx, UNMARSHALL);
2328 /* Initialise input parameters */
2330 make_spoolss_q_deleteprinterdataex(&q, hnd, keyname, valuename);
2332 /* Marshall data and send request */
2334 if (!spoolss_io_q_deleteprinterdataex("", &q, &qbuf, 0) ||
2335 !rpc_api_pipe_req(cli, SPOOLSS_DELETEPRINTERDATAEX, &qbuf, &rbuf))
2336 goto done;
2338 /* Unmarshall response */
2340 if (!spoolss_io_r_deleteprinterdataex("", &r, &rbuf, 0))
2341 goto done;
2343 result = r.status;
2345 if (!W_ERROR_IS_OK(r.status))
2346 goto done;
2348 done:
2349 prs_mem_free(&qbuf);
2350 prs_mem_free(&rbuf);
2352 return result;
2355 /** @} **/