r5805: merging spoolss parsing changes from trunk and cleaning up resulting segvs
[Samba/gbeck.git] / source / rpc_client / cli_spoolss.c
blobac2d5bd31e6ff067345119ce7d9ce6f1bcebfec0
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 Decode various spoolss rpc's and info levels
36 ********************************************************************/
38 /**********************************************************************
39 **********************************************************************/
40 static void decode_printer_info_0(TALLOC_CTX *mem_ctx, RPC_BUFFER *buffer,
41 uint32 returned, PRINTER_INFO_0 **info)
43 uint32 i;
44 PRINTER_INFO_0 *inf;
46 inf=TALLOC_ARRAY(mem_ctx, PRINTER_INFO_0, returned);
47 memset(inf, 0, returned*sizeof(PRINTER_INFO_0));
49 prs_set_offset(&buffer->prs,0);
51 for (i=0; i<returned; i++) {
52 smb_io_printer_info_0("", buffer, &inf[i], 0);
55 *info=inf;
58 /**********************************************************************
59 **********************************************************************/
60 static void decode_printer_info_1(TALLOC_CTX *mem_ctx, RPC_BUFFER *buffer,
61 uint32 returned, PRINTER_INFO_1 **info)
63 uint32 i;
64 PRINTER_INFO_1 *inf;
66 inf=TALLOC_ARRAY(mem_ctx, PRINTER_INFO_1, returned);
67 memset(inf, 0, returned*sizeof(PRINTER_INFO_1));
69 prs_set_offset(&buffer->prs,0);
71 for (i=0; i<returned; i++) {
72 smb_io_printer_info_1("", buffer, &inf[i], 0);
75 *info=inf;
78 /**********************************************************************
79 **********************************************************************/
80 static void decode_printer_info_2(TALLOC_CTX *mem_ctx, RPC_BUFFER *buffer,
81 uint32 returned, PRINTER_INFO_2 **info)
83 uint32 i;
84 PRINTER_INFO_2 *inf;
86 inf=TALLOC_ARRAY(mem_ctx, PRINTER_INFO_2, returned);
87 memset(inf, 0, returned*sizeof(PRINTER_INFO_2));
89 prs_set_offset(&buffer->prs,0);
91 for (i=0; i<returned; i++) {
92 /* a little initialization as we go */
93 inf[i].secdesc = NULL;
94 smb_io_printer_info_2("", buffer, &inf[i], 0);
97 *info=inf;
100 /**********************************************************************
101 **********************************************************************/
102 static void decode_printer_info_3(TALLOC_CTX *mem_ctx, RPC_BUFFER *buffer,
103 uint32 returned, PRINTER_INFO_3 **info)
105 uint32 i;
106 PRINTER_INFO_3 *inf;
108 inf=TALLOC_ARRAY(mem_ctx, PRINTER_INFO_3, returned);
109 memset(inf, 0, returned*sizeof(PRINTER_INFO_3));
111 prs_set_offset(&buffer->prs,0);
113 for (i=0; i<returned; i++) {
114 inf[i].secdesc = NULL;
115 smb_io_printer_info_3("", buffer, &inf[i], 0);
118 *info=inf;
121 /**********************************************************************
122 **********************************************************************/
123 static void decode_printer_info_7(TALLOC_CTX *mem_ctx, RPC_BUFFER *buffer,
124 uint32 returned, PRINTER_INFO_7 **info)
126 uint32 i;
127 PRINTER_INFO_7 *inf;
129 inf=TALLOC_ARRAY(mem_ctx, PRINTER_INFO_7, returned);
130 memset(inf, 0, returned*sizeof(PRINTER_INFO_7));
132 prs_set_offset(&buffer->prs,0);
134 for (i=0; i<returned; i++) {
135 smb_io_printer_info_7("", buffer, &inf[i], 0);
138 *info=inf;
142 /**********************************************************************
143 **********************************************************************/
144 static void decode_port_info_1(TALLOC_CTX *mem_ctx, RPC_BUFFER *buffer,
145 uint32 returned, PORT_INFO_1 **info)
147 uint32 i;
148 PORT_INFO_1 *inf;
150 inf=TALLOC_ARRAY(mem_ctx, PORT_INFO_1, returned);
151 memset(inf, 0, returned*sizeof(PORT_INFO_1));
153 prs_set_offset(&buffer->prs, 0);
155 for (i=0; i<returned; i++) {
156 smb_io_port_info_1("", buffer, &(inf[i]), 0);
159 *info=inf;
162 /**********************************************************************
163 **********************************************************************/
164 static void decode_port_info_2(TALLOC_CTX *mem_ctx, RPC_BUFFER *buffer,
165 uint32 returned, PORT_INFO_2 **info)
167 uint32 i;
168 PORT_INFO_2 *inf;
170 inf=TALLOC_ARRAY(mem_ctx, PORT_INFO_2, returned);
171 memset(inf, 0, returned*sizeof(PORT_INFO_2));
173 prs_set_offset(&buffer->prs, 0);
175 for (i=0; i<returned; i++) {
176 smb_io_port_info_2("", buffer, &(inf[i]), 0);
179 *info=inf;
182 /**********************************************************************
183 **********************************************************************/
184 static void decode_printer_driver_1(TALLOC_CTX *mem_ctx, RPC_BUFFER *buffer,
185 uint32 returned, DRIVER_INFO_1 **info)
187 uint32 i;
188 DRIVER_INFO_1 *inf;
190 inf=TALLOC_ARRAY(mem_ctx, DRIVER_INFO_1, returned);
191 memset(inf, 0, returned*sizeof(DRIVER_INFO_1));
193 prs_set_offset(&buffer->prs,0);
195 for (i=0; i<returned; i++) {
196 smb_io_printer_driver_info_1("", buffer, &(inf[i]), 0);
199 *info=inf;
202 /**********************************************************************
203 **********************************************************************/
204 static void decode_printer_driver_2(TALLOC_CTX *mem_ctx, RPC_BUFFER *buffer,
205 uint32 returned, DRIVER_INFO_2 **info)
207 uint32 i;
208 DRIVER_INFO_2 *inf;
210 inf=TALLOC_ARRAY(mem_ctx, DRIVER_INFO_2, returned);
211 memset(inf, 0, returned*sizeof(DRIVER_INFO_2));
213 prs_set_offset(&buffer->prs,0);
215 for (i=0; i<returned; i++) {
216 smb_io_printer_driver_info_2("", buffer, &(inf[i]), 0);
219 *info=inf;
222 /**********************************************************************
223 **********************************************************************/
224 static void decode_printer_driver_3(TALLOC_CTX *mem_ctx, RPC_BUFFER *buffer,
225 uint32 returned, DRIVER_INFO_3 **info)
227 uint32 i;
228 DRIVER_INFO_3 *inf;
230 inf=TALLOC_ARRAY(mem_ctx, DRIVER_INFO_3, returned);
231 memset(inf, 0, returned*sizeof(DRIVER_INFO_3));
233 prs_set_offset(&buffer->prs,0);
235 for (i=0; i<returned; i++) {
236 smb_io_printer_driver_info_3("", buffer, &(inf[i]), 0);
239 *info=inf;
242 /**********************************************************************
243 **********************************************************************/
244 static void decode_printerdriverdir_1 (TALLOC_CTX *mem_ctx, RPC_BUFFER *buffer,
245 uint32 returned, DRIVER_DIRECTORY_1 **info
248 DRIVER_DIRECTORY_1 *inf;
250 inf=TALLOC_P(mem_ctx, DRIVER_DIRECTORY_1);
251 memset(inf, 0, sizeof(DRIVER_DIRECTORY_1));
253 prs_set_offset(&buffer->prs, 0);
255 smb_io_driverdir_1("", buffer, inf, 0);
257 *info=inf;
260 /** Return a handle to the specified printer or print server.
262 * @param cli Pointer to client state structure which is open
263 * on the SPOOLSS pipe.
265 * @param mem_ctx Pointer to an initialised talloc context.
267 * @param printername The name of the printer or print server to be
268 * opened in UNC format.
270 * @param datatype Specifies the default data type for the printer.
272 * @param access_required The access rights requested on the printer or
273 * print server.
275 * @param station The UNC name of the requesting workstation.
277 * @param username The name of the user requesting the open.
279 * @param pol Returned policy handle.
282 /*********************************************************************************
283 Win32 API - OpenPrinter()
284 ********************************************************************************/
286 WERROR cli_spoolss_open_printer_ex(struct cli_state *cli, TALLOC_CTX *mem_ctx,
287 const char *printername, const char *datatype, uint32 access_required,
288 const char *station, const char *username, POLICY_HND *pol)
290 prs_struct qbuf, rbuf;
291 SPOOL_Q_OPEN_PRINTER_EX q;
292 SPOOL_R_OPEN_PRINTER_EX r;
293 WERROR result = W_ERROR(ERRgeneral);
295 ZERO_STRUCT(q);
296 ZERO_STRUCT(r);
298 /* Initialise parse structures */
300 prs_init(&qbuf, MAX_PDU_FRAG_LEN, mem_ctx, MARSHALL);
301 prs_init(&rbuf, 0, mem_ctx, UNMARSHALL);
303 /* Initialise input parameters */
305 make_spoolss_q_open_printer_ex(&q, printername, datatype,
306 access_required, station, username);
308 /* Marshall data and send request */
310 if (!spoolss_io_q_open_printer_ex("", &q, &qbuf, 0) ||
311 !rpc_api_pipe_req(cli, PI_SPOOLSS, SPOOLSS_OPENPRINTEREX, &qbuf, &rbuf))
312 goto done;
314 /* Unmarshall response */
316 if (!spoolss_io_r_open_printer_ex("", &r, &rbuf, 0))
317 goto done;
319 /* Return output parameters */
321 result = r.status;
323 if (W_ERROR_IS_OK(result))
324 *pol = r.handle;
326 done:
327 prs_mem_free(&qbuf);
328 prs_mem_free(&rbuf);
330 return result;
333 /** Close a printer handle
335 * @param cli Pointer to client state structure which is open
336 * on the SPOOLSS pipe.
338 * @param mem_ctx Pointer to an initialised talloc context.
340 * @param pol Policy handle of printer or print server to close.
342 /*********************************************************************************
343 Win32 API - ClosePrinter()
344 ********************************************************************************/
346 WERROR cli_spoolss_close_printer(struct cli_state *cli, TALLOC_CTX *mem_ctx,
347 POLICY_HND *pol)
349 prs_struct qbuf, rbuf;
350 SPOOL_Q_CLOSEPRINTER q;
351 SPOOL_R_CLOSEPRINTER r;
352 WERROR result = W_ERROR(ERRgeneral);
354 ZERO_STRUCT(q);
355 ZERO_STRUCT(r);
357 /* Initialise parse structures */
359 prs_init(&qbuf, MAX_PDU_FRAG_LEN, mem_ctx, MARSHALL);
360 prs_init(&rbuf, 0, mem_ctx, UNMARSHALL);
362 /* Initialise input parameters */
364 make_spoolss_q_closeprinter(&q, pol);
366 /* Marshall data and send request */
368 if (!spoolss_io_q_closeprinter("", &q, &qbuf, 0) ||
369 !rpc_api_pipe_req(cli, PI_SPOOLSS, SPOOLSS_CLOSEPRINTER, &qbuf, &rbuf))
370 goto done;
372 /* Unmarshall response */
374 if (!spoolss_io_r_closeprinter("", &r, &rbuf, 0))
375 goto done;
377 /* Return output parameters */
379 result = r.status;
381 if (W_ERROR_IS_OK(result))
382 *pol = r.handle;
384 done:
385 prs_mem_free(&qbuf);
386 prs_mem_free(&rbuf);
388 return result;
391 /** Enumerate printers on a print server.
393 * @param cli Pointer to client state structure which is open
394 * on the SPOOLSS pipe.
395 * @param mem_ctx Pointer to an initialised talloc context.
397 * @param offered Buffer size offered in the request.
398 * @param needed Number of bytes needed to complete the request.
399 * may be NULL.
401 * @param flags Selected from PRINTER_ENUM_* flags.
402 * @param level Request information level.
404 * @param num_printers Pointer to number of printers returned. May be
405 * NULL.
406 * @param ctr Return structure for printer information. May
407 * be NULL.
409 /*********************************************************************************
410 Win32 API - EnumPrinters()
411 ********************************************************************************/
413 WERROR cli_spoolss_enum_printers(struct cli_state *cli, TALLOC_CTX *mem_ctx,
414 uint32 offered, uint32 *needed,
415 char *name, uint32 flags, uint32 level,
416 uint32 *num_printers, PRINTER_INFO_CTR *ctr)
418 prs_struct qbuf, rbuf;
419 SPOOL_Q_ENUMPRINTERS q;
420 SPOOL_R_ENUMPRINTERS r;
421 RPC_BUFFER buffer;
422 WERROR result = W_ERROR(ERRgeneral);
424 ZERO_STRUCT(q);
425 ZERO_STRUCT(r);
427 /* Initialise input parameters */
429 rpcbuf_init(&buffer, offered, mem_ctx);
431 prs_init(&qbuf, MAX_PDU_FRAG_LEN, mem_ctx, MARSHALL);
432 prs_init(&rbuf, 0, mem_ctx, UNMARSHALL);
434 make_spoolss_q_enumprinters(&q, flags, name, level, &buffer,
435 offered);
437 /* Marshall data and send request */
439 if (!spoolss_io_q_enumprinters("", &q, &qbuf, 0) ||
440 !rpc_api_pipe_req(cli, PI_SPOOLSS, SPOOLSS_ENUMPRINTERS, &qbuf, &rbuf))
441 goto done;
443 /* Unmarshall response */
445 if (spoolss_io_r_enumprinters("", &r, &rbuf, 0)) {
446 if (needed)
447 *needed = r.needed;
450 result = r.status;
452 /* Return output parameters */
454 if (!W_ERROR_IS_OK(r.status))
455 goto done;
457 if (num_printers)
458 *num_printers = r.returned;
460 if (!ctr)
461 goto done;
463 switch (level) {
464 case 0:
465 decode_printer_info_0(mem_ctx, r.buffer, r.returned,
466 &ctr->printers_0);
467 break;
468 case 1:
469 decode_printer_info_1(mem_ctx, r.buffer, r.returned,
470 &ctr->printers_1);
471 break;
472 case 2:
473 decode_printer_info_2(mem_ctx, r.buffer, r.returned,
474 &ctr->printers_2);
475 break;
476 case 3:
477 decode_printer_info_3(mem_ctx, r.buffer, r.returned,
478 &ctr->printers_3);
479 break;
482 done:
483 prs_mem_free(&qbuf);
484 prs_mem_free(&rbuf);
486 return result;
489 /*********************************************************************************
490 Win32 API - EnumPorts()
491 ********************************************************************************/
492 /** Enumerate printer ports on a print server.
494 * @param cli Pointer to client state structure which is open
495 * on the SPOOLSS pipe.
496 * @param mem_ctx Pointer to an initialised talloc context.
498 * @param offered Buffer size offered in the request.
499 * @param needed Number of bytes needed to complete the request.
500 * May be NULL.
502 * @param level Requested information level.
504 * @param num_ports Pointer to number of ports returned. May be NULL.
505 * @param ctr Pointer to structure holding port information.
506 * May be NULL.
509 WERROR cli_spoolss_enum_ports(struct cli_state *cli, TALLOC_CTX *mem_ctx,
510 uint32 offered, uint32 *needed,
511 uint32 level, uint32 *num_ports, PORT_INFO_CTR *ctr)
513 prs_struct qbuf, rbuf;
514 SPOOL_Q_ENUMPORTS q;
515 SPOOL_R_ENUMPORTS r;
516 RPC_BUFFER buffer;
517 WERROR result = W_ERROR(ERRgeneral);
518 fstring server;
520 ZERO_STRUCT(q);
521 ZERO_STRUCT(r);
523 slprintf(server, sizeof(fstring)-1, "\\\\%s", cli->desthost);
524 strupper_m(server);
526 /* Initialise input parameters */
528 rpcbuf_init(&buffer, offered, mem_ctx);
530 prs_init(&qbuf, MAX_PDU_FRAG_LEN, mem_ctx, MARSHALL);
531 prs_init(&rbuf, 0, mem_ctx, UNMARSHALL);
533 make_spoolss_q_enumports(&q, server, level, &buffer, offered);
535 /* Marshall data and send request */
537 if (!spoolss_io_q_enumports("", &q, &qbuf, 0) ||
538 !rpc_api_pipe_req(cli, PI_SPOOLSS, SPOOLSS_ENUMPORTS, &qbuf, &rbuf))
539 goto done;
541 /* Unmarshall response */
543 if (spoolss_io_r_enumports("", &r, &rbuf, 0)) {
544 if (needed)
545 *needed = r.needed;
548 result = r.status;
550 /* Return output parameters */
552 if (!W_ERROR_IS_OK(result))
553 goto done;
555 if (num_ports)
556 *num_ports = r.returned;
558 if (!ctr)
559 goto done;
561 switch (level) {
562 case 1:
563 decode_port_info_1(mem_ctx, r.buffer, r.returned,
564 &ctr->port.info_1);
565 break;
566 case 2:
567 decode_port_info_2(mem_ctx, r.buffer, r.returned,
568 &ctr->port.info_2);
569 break;
572 done:
573 prs_mem_free(&qbuf);
574 prs_mem_free(&rbuf);
576 return result;
579 /*********************************************************************************
580 Win32 API - GetPrinter()
581 ********************************************************************************/
583 WERROR cli_spoolss_getprinter(struct cli_state *cli, TALLOC_CTX *mem_ctx,
584 uint32 offered, uint32 *needed,
585 POLICY_HND *pol, uint32 level,
586 PRINTER_INFO_CTR *ctr)
588 prs_struct qbuf, rbuf;
589 SPOOL_Q_GETPRINTER q;
590 SPOOL_R_GETPRINTER r;
591 RPC_BUFFER buffer;
592 WERROR result = W_ERROR(ERRgeneral);
594 ZERO_STRUCT(q);
595 ZERO_STRUCT(r);
597 /* Initialise input parameters */
599 rpcbuf_init(&buffer, offered, mem_ctx);
601 prs_init(&qbuf, MAX_PDU_FRAG_LEN, mem_ctx, MARSHALL);
602 prs_init(&rbuf, 0, mem_ctx, UNMARSHALL);
604 make_spoolss_q_getprinter(mem_ctx, &q, pol, level, &buffer, offered);
606 /* Marshall data and send request */
608 if (!spoolss_io_q_getprinter("", &q, &qbuf, 0) ||
609 !rpc_api_pipe_req(cli, PI_SPOOLSS, SPOOLSS_GETPRINTER, &qbuf, &rbuf))
610 goto done;
612 /* Unmarshall response */
614 if (!spoolss_io_r_getprinter("", &r, &rbuf, 0))
615 goto done;
617 if (needed)
618 *needed = r.needed;
620 /* Return output parameters */
622 result = r.status;
624 if (W_ERROR_IS_OK(result)) {
625 switch (level) {
626 case 0:
627 decode_printer_info_0(mem_ctx, r.buffer, 1, &ctr->printers_0);
628 break;
629 case 1:
630 decode_printer_info_1(mem_ctx, r.buffer, 1, &ctr->printers_1);
631 break;
632 case 2:
633 decode_printer_info_2(mem_ctx, r.buffer, 1, &ctr->printers_2);
634 break;
635 case 3:
636 decode_printer_info_3(mem_ctx, r.buffer, 1, &ctr->printers_3);
637 break;
638 case 7:
639 decode_printer_info_7(mem_ctx, r.buffer, 1, &ctr->printers_7);
640 break;
644 done:
645 prs_mem_free(&qbuf);
646 prs_mem_free(&rbuf);
648 return result;
651 /*********************************************************************************
652 Win32 API - SetPrinter()
653 ********************************************************************************/
654 /** Set printer info
656 * @param cli Pointer to client state structure which is open
657 * on the SPOOLSS pipe.
658 * @param mem_ctx Pointer to an initialised talloc context.
660 * @param pol Policy handle on printer to set info.
661 * @param level Information level to set.
662 * @param ctr Pointer to structure holding printer information.
663 * @param command Specifies the action performed. See
664 * http://msdn.microsoft.com/library/default.asp?url=/library/en-us/gdi/prntspol_13ua.asp
665 * for details.
669 WERROR cli_spoolss_setprinter(struct cli_state *cli, TALLOC_CTX *mem_ctx,
670 POLICY_HND *pol, uint32 level,
671 PRINTER_INFO_CTR *ctr, uint32 command)
673 prs_struct qbuf, rbuf;
674 SPOOL_Q_SETPRINTER q;
675 SPOOL_R_SETPRINTER r;
676 WERROR result = W_ERROR(ERRgeneral);
678 ZERO_STRUCT(q);
679 ZERO_STRUCT(r);
681 /* Initialise input parameters */
683 prs_init(&qbuf, MAX_PDU_FRAG_LEN, mem_ctx, MARSHALL);
684 prs_init(&rbuf, 0, mem_ctx, UNMARSHALL);
686 if (!make_spoolss_q_setprinter(mem_ctx, &q, pol, level, ctr, command))
687 goto done;
689 /* Marshall data and send request */
691 if (!spoolss_io_q_setprinter("", &q, &qbuf, 0) ||
692 !rpc_api_pipe_req(cli, PI_SPOOLSS, SPOOLSS_SETPRINTER, &qbuf, &rbuf))
693 goto done;
695 /* Unmarshall response */
697 if (!spoolss_io_r_setprinter("", &r, &rbuf, 0))
698 goto done;
700 result = r.status;
702 done:
703 prs_mem_free(&qbuf);
704 prs_mem_free(&rbuf);
706 return result;
709 /*********************************************************************************
710 Win32 API - GetPrinterDriver()
711 ********************************************************************************/
712 /** Get installed printer drivers for a given printer
714 * @param cli Pointer to client state structure which is open
715 * on the SPOOLSS pipe.
717 * @param mem_ctx Pointer to an initialised talloc context.
719 * @param offered Buffer size offered in the request.
720 * @param needed Number of bytes needed to complete the request.
721 * may be NULL.
723 * @param pol Pointer to an open policy handle for the printer
724 * opened with cli_spoolss_open_printer_ex().
725 * @param level Requested information level.
726 * @param env The print environment or archictecture. This is
727 * "Windows NT x86" for NT4.
728 * @param ctr Returned printer driver information.
731 WERROR cli_spoolss_getprinterdriver(struct cli_state *cli,
732 TALLOC_CTX *mem_ctx,
733 uint32 offered, uint32 *needed,
734 POLICY_HND *pol, uint32 level,
735 const char *env, int version, PRINTER_DRIVER_CTR *ctr)
737 prs_struct qbuf, rbuf;
738 SPOOL_Q_GETPRINTERDRIVER2 q;
739 SPOOL_R_GETPRINTERDRIVER2 r;
740 RPC_BUFFER buffer;
741 WERROR result = W_ERROR(ERRgeneral);
742 fstring server;
744 ZERO_STRUCT(q);
745 ZERO_STRUCT(r);
747 fstrcpy(server, cli->desthost);
748 strupper_m(server);
750 /* Initialise input parameters */
752 rpcbuf_init(&buffer, offered, mem_ctx);
754 prs_init(&qbuf, MAX_PDU_FRAG_LEN, mem_ctx, MARSHALL);
755 prs_init(&rbuf, 0, mem_ctx, UNMARSHALL);
757 make_spoolss_q_getprinterdriver2(&q, pol, env, level, version, 2,
758 &buffer, offered);
760 /* Marshall data and send request */
762 if (!spoolss_io_q_getprinterdriver2 ("", &q, &qbuf, 0) ||
763 !rpc_api_pipe_req (cli, PI_SPOOLSS, SPOOLSS_GETPRINTERDRIVER2, &qbuf, &rbuf))
764 goto done;
766 /* Unmarshall response */
768 if (spoolss_io_r_getprinterdriver2 ("", &r, &rbuf, 0)) {
769 if (needed)
770 *needed = r.needed;
773 result = r.status;
775 /* Return output parameters */
777 if (!W_ERROR_IS_OK(result))
778 goto done;
780 if (!ctr)
781 goto done;
783 switch (level) {
784 case 1:
785 decode_printer_driver_1(mem_ctx, r.buffer, 1, &ctr->info1);
786 break;
787 case 2:
788 decode_printer_driver_2(mem_ctx, r.buffer, 1, &ctr->info2);
789 break;
790 case 3:
791 decode_printer_driver_3(mem_ctx, r.buffer, 1, &ctr->info3);
792 break;
793 default:
794 DEBUG(10, ("cli_spoolss_getprinterdriver: unknown info level %d", level));
795 return WERR_UNKNOWN_LEVEL;
798 done:
799 prs_mem_free(&qbuf);
800 prs_mem_free(&rbuf);
802 return result;
805 /*********************************************************************************
806 Win32 API - EnumPrinterDrivers()
807 ********************************************************************************/
808 /**********************************************************************
809 * Get installed printer drivers for a given printer
811 WERROR cli_spoolss_enumprinterdrivers (struct cli_state *cli,
812 TALLOC_CTX *mem_ctx,
813 uint32 offered, uint32 *needed,
814 uint32 level, const char *env,
815 uint32 *num_drivers,
816 PRINTER_DRIVER_CTR *ctr)
818 prs_struct qbuf, rbuf;
819 SPOOL_Q_ENUMPRINTERDRIVERS q;
820 SPOOL_R_ENUMPRINTERDRIVERS r;
821 RPC_BUFFER buffer;
822 WERROR result = W_ERROR(ERRgeneral);
823 fstring server;
825 ZERO_STRUCT(q);
826 ZERO_STRUCT(r);
828 slprintf(server, sizeof(fstring)-1, "\\\\%s", cli->desthost);
829 strupper_m(server);
831 /* Initialise input parameters */
833 rpcbuf_init(&buffer, offered, mem_ctx);
835 prs_init(&qbuf, MAX_PDU_FRAG_LEN, mem_ctx, MARSHALL);
836 prs_init(&rbuf, 0, mem_ctx, UNMARSHALL);
838 /* Write the request */
840 make_spoolss_q_enumprinterdrivers(&q, server, env, level, &buffer,
841 offered);
843 /* Marshall data and send request */
845 if (!spoolss_io_q_enumprinterdrivers ("", &q, &qbuf, 0) ||
846 !rpc_api_pipe_req (cli, PI_SPOOLSS, SPOOLSS_ENUMPRINTERDRIVERS, &qbuf, &rbuf))
847 goto done;
849 /* Unmarshall response */
851 if (!spoolss_io_r_enumprinterdrivers ("", &r, &rbuf, 0))
852 goto done;
854 if (needed)
855 *needed = r.needed;
857 if (num_drivers)
858 *num_drivers = r.returned;
860 result = r.status;
862 /* Return output parameters */
864 if (W_ERROR_IS_OK(result) && (r.returned != 0)) {
865 *num_drivers = r.returned;
867 switch (level) {
868 case 1:
869 decode_printer_driver_1(mem_ctx, r.buffer, r.returned, &ctr->info1);
870 break;
871 case 2:
872 decode_printer_driver_2(mem_ctx, r.buffer, r.returned, &ctr->info2);
873 break;
874 case 3:
875 decode_printer_driver_3(mem_ctx, r.buffer, r.returned, &ctr->info3);
876 break;
877 default:
878 DEBUG(10, ("cli_spoolss_enumprinterdrivers: unknown info level %d\n",
879 level));
880 return WERR_UNKNOWN_LEVEL;
884 done:
885 prs_mem_free(&qbuf);
886 prs_mem_free(&rbuf);
888 return result;
892 /*********************************************************************************
893 Win32 API - GetPrinterDriverDirectory()
894 ********************************************************************************/
895 /**********************************************************************
896 * Get installed printer drivers for a given printer
898 WERROR cli_spoolss_getprinterdriverdir (struct cli_state *cli,
899 TALLOC_CTX *mem_ctx,
900 uint32 offered, uint32 *needed,
901 uint32 level, char *env,
902 DRIVER_DIRECTORY_CTR *ctr)
904 prs_struct qbuf, rbuf;
905 SPOOL_Q_GETPRINTERDRIVERDIR q;
906 SPOOL_R_GETPRINTERDRIVERDIR r;
907 RPC_BUFFER buffer;
908 WERROR result = W_ERROR(ERRgeneral);
909 fstring server;
911 ZERO_STRUCT(q);
912 ZERO_STRUCT(r);
914 slprintf(server, sizeof(fstring)-1, "\\\\%s", cli->desthost);
915 strupper_m(server);
917 /* Initialise input parameters */
919 rpcbuf_init(&buffer, offered, mem_ctx);
921 prs_init(&qbuf, MAX_PDU_FRAG_LEN, mem_ctx, MARSHALL);
922 prs_init(&rbuf, 0, mem_ctx, UNMARSHALL);
924 /* Write the request */
926 make_spoolss_q_getprinterdriverdir(&q, server, env, level, &buffer,
927 offered);
929 /* Marshall data and send request */
931 if (!spoolss_io_q_getprinterdriverdir ("", &q, &qbuf, 0) ||
932 !rpc_api_pipe_req (cli, PI_SPOOLSS, SPOOLSS_GETPRINTERDRIVERDIRECTORY,
933 &qbuf, &rbuf))
934 goto done;
936 /* Unmarshall response */
938 if (spoolss_io_r_getprinterdriverdir ("", &r, &rbuf, 0)) {
939 if (needed)
940 *needed = r.needed;
943 /* Return output parameters */
945 result = r.status;
947 if (W_ERROR_IS_OK(result)) {
948 switch (level) {
949 case 1:
950 decode_printerdriverdir_1(mem_ctx, r.buffer, 1,
951 &ctr->info1);
952 break;
956 done:
957 prs_mem_free(&qbuf);
958 prs_mem_free(&rbuf);
960 return result;
963 /*********************************************************************************
964 Win32 API - AddPrinterDriver()
965 ********************************************************************************/
966 /**********************************************************************
967 * Install a printer driver
969 WERROR cli_spoolss_addprinterdriver (struct cli_state *cli,
970 TALLOC_CTX *mem_ctx, uint32 level,
971 PRINTER_DRIVER_CTR *ctr)
973 prs_struct qbuf, rbuf;
974 SPOOL_Q_ADDPRINTERDRIVER q;
975 SPOOL_R_ADDPRINTERDRIVER r;
976 WERROR result = W_ERROR(ERRgeneral);
977 fstring server;
979 ZERO_STRUCT(q);
980 ZERO_STRUCT(r);
982 slprintf(server, sizeof(fstring)-1, "\\\\%s", cli->desthost);
983 strupper_m(server);
985 /* Initialise input parameters */
987 prs_init(&qbuf, MAX_PDU_FRAG_LEN, mem_ctx, MARSHALL);
988 prs_init(&rbuf, 0, mem_ctx, UNMARSHALL);
990 /* Write the request */
992 make_spoolss_q_addprinterdriver (mem_ctx, &q, server, level, ctr);
994 /* Marshall data and send request */
996 if (!spoolss_io_q_addprinterdriver ("", &q, &qbuf, 0) ||
997 !rpc_api_pipe_req (cli, PI_SPOOLSS, SPOOLSS_ADDPRINTERDRIVER, &qbuf, &rbuf))
998 goto done;
1000 /* Unmarshall response */
1002 if (!spoolss_io_r_addprinterdriver ("", &r, &rbuf, 0))
1003 goto done;
1005 /* Return output parameters */
1007 result = r.status;
1009 done:
1010 prs_mem_free(&qbuf);
1011 prs_mem_free(&rbuf);
1013 return result;
1016 /*********************************************************************************
1017 Win32 API - AddPrinter()
1018 ********************************************************************************/
1019 /**********************************************************************
1020 * Install a printer
1022 WERROR cli_spoolss_addprinterex (struct cli_state *cli, TALLOC_CTX *mem_ctx,
1023 uint32 level, PRINTER_INFO_CTR*ctr)
1025 prs_struct qbuf, rbuf;
1026 SPOOL_Q_ADDPRINTEREX q;
1027 SPOOL_R_ADDPRINTEREX r;
1028 WERROR result = W_ERROR(ERRgeneral);
1029 fstring server,
1030 client,
1031 user;
1033 ZERO_STRUCT(q);
1034 ZERO_STRUCT(r);
1036 slprintf(client, sizeof(fstring)-1, "\\\\%s", cli->desthost);
1037 strupper_m(client);
1038 slprintf(server, sizeof(fstring)-1, "\\\\%s", cli->desthost);
1039 strupper_m(server);
1040 fstrcpy (user, cli->user_name);
1042 /* Initialise input parameters */
1044 prs_init(&qbuf, MAX_PDU_FRAG_LEN, mem_ctx, MARSHALL);
1045 prs_init(&rbuf, 0, mem_ctx, UNMARSHALL);
1047 /* Write the request */
1049 make_spoolss_q_addprinterex (mem_ctx, &q, server, client, user,
1050 level, ctr);
1052 /* Marshall data and send request */
1054 if (!spoolss_io_q_addprinterex ("", &q, &qbuf, 0) ||
1055 !rpc_api_pipe_req (cli, PI_SPOOLSS, SPOOLSS_ADDPRINTEREX, &qbuf, &rbuf))
1056 goto done;
1058 /* Unmarshall response */
1060 if (!spoolss_io_r_addprinterex ("", &r, &rbuf, 0))
1061 goto done;
1063 /* Return output parameters */
1065 result = r.status;
1067 done:
1068 prs_mem_free(&qbuf);
1069 prs_mem_free(&rbuf);
1071 return result;
1074 /**********************************************************************
1075 * Delete a Printer Driver from the server (DOES remove
1076 * the driver files)
1078 WERROR cli_spoolss_deleteprinterdriverex(struct cli_state *cli,
1079 TALLOC_CTX *mem_ctx, const char *arch,
1080 const char *driver, uint32 version)
1082 prs_struct qbuf, rbuf;
1083 SPOOL_Q_DELETEPRINTERDRIVEREX q;
1084 SPOOL_R_DELETEPRINTERDRIVEREX r;
1085 WERROR result = W_ERROR(ERRgeneral);
1086 fstring server;
1088 ZERO_STRUCT(q);
1089 ZERO_STRUCT(r);
1092 /* Initialise input parameters */
1093 prs_init(&qbuf, MAX_PDU_FRAG_LEN, mem_ctx, MARSHALL);
1094 prs_init(&rbuf, 0, mem_ctx, UNMARSHALL);
1096 slprintf(server, sizeof(fstring)-1, "\\\\%s", cli->desthost);
1097 strupper_m(server);
1099 /* Write the request */
1100 make_spoolss_q_deleteprinterdriverex(mem_ctx, &q, server, arch, driver, version);
1102 /* Marshall data and send request */
1104 if (!spoolss_io_q_deleteprinterdriverex ("", &q, &qbuf, 0)
1105 || !rpc_api_pipe_req (cli, PI_SPOOLSS, SPOOLSS_DELETEPRINTERDRIVEREX , &qbuf, &rbuf))
1107 goto done;
1110 /* Unmarshall response */
1112 if (!spoolss_io_r_deleteprinterdriverex ("", &r, &rbuf, 0))
1113 goto done;
1115 /* Return output parameters */
1117 result = r.status;
1119 done:
1120 prs_mem_free(&qbuf);
1121 prs_mem_free(&rbuf);
1123 return result;
1126 /*********************************************************************************
1127 Win32 API - DeltePrinterDriver()
1128 ********************************************************************************/
1129 /**********************************************************************
1130 * Delete a Printer Driver from the server (does not remove
1131 * the driver files
1133 WERROR cli_spoolss_deleteprinterdriver (struct cli_state *cli,
1134 TALLOC_CTX *mem_ctx, const char *arch,
1135 const char *driver)
1137 prs_struct qbuf, rbuf;
1138 SPOOL_Q_DELETEPRINTERDRIVER q;
1139 SPOOL_R_DELETEPRINTERDRIVER r;
1140 WERROR result = W_ERROR(ERRgeneral);
1141 fstring server;
1143 ZERO_STRUCT(q);
1144 ZERO_STRUCT(r);
1147 /* Initialise input parameters */
1148 prs_init(&qbuf, MAX_PDU_FRAG_LEN, mem_ctx, MARSHALL);
1149 prs_init(&rbuf, 0, mem_ctx, UNMARSHALL);
1151 slprintf(server, sizeof(fstring)-1, "\\\\%s", cli->desthost);
1152 strupper_m(server);
1154 /* Write the request */
1156 make_spoolss_q_deleteprinterdriver(mem_ctx, &q, server, arch, driver);
1158 /* Marshall data and send request */
1160 if (!spoolss_io_q_deleteprinterdriver ("", &q, &qbuf, 0) ||
1161 !rpc_api_pipe_req (cli, PI_SPOOLSS, SPOOLSS_DELETEPRINTERDRIVER , &qbuf, &rbuf))
1162 goto done;
1164 /* Unmarshall response */
1166 if (!spoolss_io_r_deleteprinterdriver ("", &r, &rbuf, 0))
1167 goto done;
1169 /* Return output parameters */
1171 result = r.status;
1173 done:
1174 prs_mem_free(&qbuf);
1175 prs_mem_free(&rbuf);
1177 return result;
1180 /*********************************************************************************
1181 Win32 API - GetPrinterProcessorDirectory()
1182 ********************************************************************************/
1184 WERROR cli_spoolss_getprintprocessordirectory(struct cli_state *cli,
1185 TALLOC_CTX *mem_ctx,
1186 uint32 offered, uint32 *needed,
1187 char *name, char *environment,
1188 fstring procdir)
1190 prs_struct qbuf, rbuf;
1191 SPOOL_Q_GETPRINTPROCESSORDIRECTORY q;
1192 SPOOL_R_GETPRINTPROCESSORDIRECTORY r;
1193 int level = 1;
1194 WERROR result = W_ERROR(ERRgeneral);
1195 RPC_BUFFER buffer;
1197 ZERO_STRUCT(q);
1198 ZERO_STRUCT(r);
1200 /* Initialise parse structures */
1202 prs_init(&qbuf, MAX_PDU_FRAG_LEN, mem_ctx, MARSHALL);
1203 prs_init(&rbuf, 0, mem_ctx, UNMARSHALL);
1205 /* Initialise input parameters */
1207 rpcbuf_init(&buffer, offered, mem_ctx);
1209 make_spoolss_q_getprintprocessordirectory(
1210 &q, name, environment, level, &buffer, offered);
1212 /* Marshall data and send request */
1214 if (!spoolss_io_q_getprintprocessordirectory("", &q, &qbuf, 0) ||
1215 !rpc_api_pipe_req(cli, PI_SPOOLSS, SPOOLSS_GETPRINTPROCESSORDIRECTORY,
1216 &qbuf, &rbuf))
1217 goto done;
1219 /* Unmarshall response */
1221 if (!spoolss_io_r_getprintprocessordirectory("", &r, &rbuf, 0))
1222 goto done;
1224 /* Return output parameters */
1226 result = r.status;
1228 if (needed)
1229 *needed = r.needed;
1231 if (W_ERROR_IS_OK(result))
1232 fstrcpy(procdir, "Not implemented!");
1234 done:
1235 prs_mem_free(&qbuf);
1236 prs_mem_free(&rbuf);
1238 return result;
1241 /** Add a form to a printer.
1243 * @param cli Pointer to client state structure which is open
1244 * on the SPOOLSS pipe.
1245 * @param mem_ctx Pointer to an initialised talloc context.
1247 * @param handle Policy handle opened with cli_spoolss_open_printer_ex
1248 * or cli_spoolss_addprinterex.
1249 * @param level Form info level to add - should always be 1.
1250 * @param form A pointer to the form to be added.
1254 WERROR cli_spoolss_addform(struct cli_state *cli, TALLOC_CTX *mem_ctx,
1255 POLICY_HND *handle, uint32 level, FORM *form)
1257 prs_struct qbuf, rbuf;
1258 SPOOL_Q_ADDFORM q;
1259 SPOOL_R_ADDFORM r;
1260 WERROR result = W_ERROR(ERRgeneral);
1262 ZERO_STRUCT(q);
1263 ZERO_STRUCT(r);
1265 /* Initialise parse structures */
1267 prs_init(&qbuf, MAX_PDU_FRAG_LEN, mem_ctx, MARSHALL);
1268 prs_init(&rbuf, 0, mem_ctx, UNMARSHALL);
1270 /* Initialise input parameters */
1272 make_spoolss_q_addform(&q, handle, level, form);
1274 /* Marshall data and send request */
1276 if (!spoolss_io_q_addform("", &q, &qbuf, 0) ||
1277 !rpc_api_pipe_req(cli, PI_SPOOLSS, SPOOLSS_ADDFORM, &qbuf, &rbuf))
1278 goto done;
1280 /* Unmarshall response */
1282 if (!spoolss_io_r_addform("", &r, &rbuf, 0))
1283 goto done;
1285 /* Return output parameters */
1287 result = r.status;
1289 done:
1290 prs_mem_free(&qbuf);
1291 prs_mem_free(&rbuf);
1293 return result;
1296 /** Set a form on a printer.
1298 * @param cli Pointer to client state structure which is open
1299 * on the SPOOLSS pipe.
1300 * @param mem_ctx Pointer to an initialised talloc context.
1302 * @param handle Policy handle opened with cli_spoolss_open_printer_ex
1303 * or cli_spoolss_addprinterex.
1304 * @param level Form info level to set - should always be 1.
1305 * @param form A pointer to the form to be set.
1309 WERROR cli_spoolss_setform(struct cli_state *cli, TALLOC_CTX *mem_ctx,
1310 POLICY_HND *handle, uint32 level,
1311 const char *form_name, FORM *form)
1313 prs_struct qbuf, rbuf;
1314 SPOOL_Q_SETFORM q;
1315 SPOOL_R_SETFORM r;
1316 WERROR result = W_ERROR(ERRgeneral);
1318 ZERO_STRUCT(q);
1319 ZERO_STRUCT(r);
1321 /* Initialise parse structures */
1323 prs_init(&qbuf, MAX_PDU_FRAG_LEN, mem_ctx, MARSHALL);
1324 prs_init(&rbuf, 0, mem_ctx, UNMARSHALL);
1326 /* Initialise input parameters */
1328 make_spoolss_q_setform(&q, handle, level, form_name, form);
1330 /* Marshall data and send request */
1332 if (!spoolss_io_q_setform("", &q, &qbuf, 0) ||
1333 !rpc_api_pipe_req(cli, PI_SPOOLSS, SPOOLSS_SETFORM, &qbuf, &rbuf))
1334 goto done;
1336 /* Unmarshall response */
1338 if (!spoolss_io_r_setform("", &r, &rbuf, 0))
1339 goto done;
1341 /* Return output parameters */
1343 result = r.status;
1345 if (!W_ERROR_IS_OK(result))
1346 goto done;
1350 done:
1351 prs_mem_free(&qbuf);
1352 prs_mem_free(&rbuf);
1354 return result;
1357 /** Get a form on a printer.
1359 * @param cli Pointer to client state structure which is open
1360 * on the SPOOLSS pipe.
1361 * @param mem_ctx Pointer to an initialised talloc context.
1363 * @param handle Policy handle opened with cli_spoolss_open_printer_ex
1364 * or cli_spoolss_addprinterex.
1365 * @param formname Name of the form to get
1366 * @param level Form info level to get - should always be 1.
1370 WERROR cli_spoolss_getform(struct cli_state *cli, TALLOC_CTX *mem_ctx,
1371 uint32 offered, uint32 *needed,
1372 POLICY_HND *handle, const char *formname,
1373 uint32 level, FORM_1 *form)
1375 prs_struct qbuf, rbuf;
1376 SPOOL_Q_GETFORM q;
1377 SPOOL_R_GETFORM r;
1378 WERROR result = W_ERROR(ERRgeneral);
1379 RPC_BUFFER buffer;
1381 ZERO_STRUCT(q);
1382 ZERO_STRUCT(r);
1384 /* Initialise parse structures */
1386 rpcbuf_init(&buffer, offered, mem_ctx);
1388 prs_init(&qbuf, MAX_PDU_FRAG_LEN, mem_ctx, MARSHALL);
1389 prs_init(&rbuf, 0, mem_ctx, UNMARSHALL);
1391 /* Initialise input parameters */
1393 make_spoolss_q_getform(&q, handle, formname, level, &buffer, offered);
1395 /* Marshall data and send request */
1397 if (!spoolss_io_q_getform("", &q, &qbuf, 0) ||
1398 !rpc_api_pipe_req(cli, PI_SPOOLSS, SPOOLSS_GETFORM, &qbuf, &rbuf))
1399 goto done;
1401 /* Unmarshall response */
1403 if (!spoolss_io_r_getform("", &r, &rbuf, 0))
1404 goto done;
1406 /* Return output parameters */
1408 result = r.status;
1410 if (needed)
1411 *needed = r.needed;
1413 if (W_ERROR_IS_OK(result)) {
1414 switch(level) {
1415 case 1:
1416 smb_io_form_1("", r.buffer, form, 0);
1417 break;
1418 default:
1419 DEBUG(10, ("cli_spoolss_getform: unknown info level %d", level));
1420 return WERR_UNKNOWN_LEVEL;
1424 done:
1425 prs_mem_free(&qbuf);
1426 prs_mem_free(&rbuf);
1428 return result;
1431 /** Delete a form on a printer.
1433 * @param cli Pointer to client state structure which is open
1434 * on the SPOOLSS pipe.
1435 * @param mem_ctx Pointer to an initialised talloc context.
1437 * @param handle Policy handle opened with cli_spoolss_open_printer_ex
1438 * or cli_spoolss_addprinterex.
1439 * @param form The name of the form to delete.
1443 WERROR cli_spoolss_deleteform(struct cli_state *cli, TALLOC_CTX *mem_ctx,
1444 POLICY_HND *handle, const char *form_name)
1446 prs_struct qbuf, rbuf;
1447 SPOOL_Q_DELETEFORM q;
1448 SPOOL_R_DELETEFORM r;
1449 WERROR result = W_ERROR(ERRgeneral);
1451 ZERO_STRUCT(q);
1452 ZERO_STRUCT(r);
1454 /* Initialise parse structures */
1456 prs_init(&qbuf, MAX_PDU_FRAG_LEN, mem_ctx, MARSHALL);
1457 prs_init(&rbuf, 0, mem_ctx, UNMARSHALL);
1459 /* Initialise input parameters */
1461 make_spoolss_q_deleteform(&q, handle, form_name);
1463 /* Marshall data and send request */
1465 if (!spoolss_io_q_deleteform("", &q, &qbuf, 0) ||
1466 !rpc_api_pipe_req(cli, PI_SPOOLSS, SPOOLSS_DELETEFORM, &qbuf, &rbuf))
1467 goto done;
1469 /* Unmarshall response */
1471 if (!spoolss_io_r_deleteform("", &r, &rbuf, 0))
1472 goto done;
1474 /* Return output parameters */
1476 result = r.status;
1478 done:
1479 prs_mem_free(&qbuf);
1480 prs_mem_free(&rbuf);
1482 return result;
1485 static void decode_forms_1(TALLOC_CTX *mem_ctx, RPC_BUFFER *buffer,
1486 uint32 num_forms, FORM_1 **forms)
1488 int i;
1490 *forms = TALLOC_ARRAY(mem_ctx, FORM_1, num_forms);
1491 prs_set_offset(&buffer->prs,0);
1493 for (i = 0; i < num_forms; i++)
1494 smb_io_form_1("", buffer, &((*forms)[i]), 0);
1497 /** Enumerate forms
1499 * @param cli Pointer to client state structure which is open
1500 * on the SPOOLSS pipe.
1501 * @param mem_ctx Pointer to an initialised talloc context.
1503 * @param offered Buffer size offered in the request.
1504 * @param needed Number of bytes needed to complete the request.
1505 * may be NULL.
1506 * or cli_spoolss_addprinterex.
1507 * @param level Form info level to get - should always be 1.
1508 * @param handle Open policy handle
1512 WERROR cli_spoolss_enumforms(struct cli_state *cli, TALLOC_CTX *mem_ctx,
1513 uint32 offered, uint32 *needed,
1514 POLICY_HND *handle, int level, uint32 *num_forms,
1515 FORM_1 **forms)
1517 prs_struct qbuf, rbuf;
1518 SPOOL_Q_ENUMFORMS q;
1519 SPOOL_R_ENUMFORMS r;
1520 WERROR result = W_ERROR(ERRgeneral);
1521 RPC_BUFFER buffer;
1523 ZERO_STRUCT(q);
1524 ZERO_STRUCT(r);
1526 /* Initialise parse structures */
1528 rpcbuf_init(&buffer, offered, mem_ctx);
1530 prs_init(&qbuf, MAX_PDU_FRAG_LEN, mem_ctx, MARSHALL);
1531 prs_init(&rbuf, 0, mem_ctx, UNMARSHALL);
1533 /* Initialise input parameters */
1535 make_spoolss_q_enumforms(&q, handle, level, &buffer, offered);
1537 /* Marshall data and send request */
1539 if (!spoolss_io_q_enumforms("", &q, &qbuf, 0) ||
1540 !rpc_api_pipe_req(cli, PI_SPOOLSS, SPOOLSS_ENUMFORMS, &qbuf, &rbuf))
1541 goto done;
1543 /* Unmarshall response */
1545 if (!spoolss_io_r_enumforms("", &r, &rbuf, 0))
1546 goto done;
1548 /* Return output parameters */
1550 result = r.status;
1552 if (needed)
1553 *needed = r.needed;
1555 if (num_forms)
1556 *num_forms = r.numofforms;
1558 decode_forms_1(mem_ctx, r.buffer, *num_forms, forms);
1560 done:
1561 prs_mem_free(&qbuf);
1562 prs_mem_free(&rbuf);
1564 return result;
1567 static void decode_jobs_1(TALLOC_CTX *mem_ctx, RPC_BUFFER *buffer,
1568 uint32 num_jobs, JOB_INFO_1 **jobs)
1570 uint32 i;
1572 *jobs = TALLOC_ARRAY(mem_ctx, JOB_INFO_1, num_jobs);
1573 prs_set_offset(&buffer->prs,0);
1575 for (i = 0; i < num_jobs; i++)
1576 smb_io_job_info_1("", buffer, &((*jobs)[i]), 0);
1579 static void decode_jobs_2(TALLOC_CTX *mem_ctx, RPC_BUFFER *buffer,
1580 uint32 num_jobs, JOB_INFO_2 **jobs)
1582 uint32 i;
1584 *jobs = TALLOC_ARRAY(mem_ctx, JOB_INFO_2, num_jobs);
1585 prs_set_offset(&buffer->prs,0);
1587 for (i = 0; i < num_jobs; i++)
1588 smb_io_job_info_2("", buffer, &((*jobs)[i]), 0);
1591 /* Enumerate jobs */
1593 WERROR cli_spoolss_enumjobs(struct cli_state *cli, TALLOC_CTX *mem_ctx,
1594 uint32 offered, uint32 *needed,
1595 POLICY_HND *hnd, uint32 level, uint32 firstjob,
1596 uint32 num_jobs, uint32 *returned, JOB_INFO_CTR *ctr)
1598 prs_struct qbuf, rbuf;
1599 SPOOL_Q_ENUMJOBS q;
1600 SPOOL_R_ENUMJOBS r;
1601 WERROR result = W_ERROR(ERRgeneral);
1602 RPC_BUFFER buffer;
1604 ZERO_STRUCT(q);
1605 ZERO_STRUCT(r);
1607 /* Initialise parse structures */
1609 rpcbuf_init(&buffer, offered, mem_ctx);
1611 prs_init(&qbuf, MAX_PDU_FRAG_LEN, mem_ctx, MARSHALL);
1612 prs_init(&rbuf, 0, mem_ctx, UNMARSHALL);
1614 /* Initialise input parameters */
1616 make_spoolss_q_enumjobs(&q, hnd, firstjob, num_jobs, level, &buffer,
1617 offered);
1619 /* Marshall data and send request */
1621 if (!spoolss_io_q_enumjobs("", &q, &qbuf, 0) ||
1622 !rpc_api_pipe_req(cli, PI_SPOOLSS, SPOOLSS_ENUMJOBS, &qbuf, &rbuf))
1623 goto done;
1625 /* Unmarshall response */
1627 if (!spoolss_io_r_enumjobs("", &r, &rbuf, 0))
1628 goto done;
1630 /* Return output parameters */
1632 result = r.status;
1634 if (needed)
1635 *needed = r.needed;
1637 if (!W_ERROR_IS_OK(r.status))
1638 goto done;
1640 *returned = r.returned;
1642 switch(level) {
1643 case 1:
1644 decode_jobs_1(mem_ctx, r.buffer, r.returned,
1645 &ctr->job.job_info_1);
1646 break;
1647 case 2:
1648 decode_jobs_2(mem_ctx, r.buffer, r.returned,
1649 &ctr->job.job_info_2);
1650 break;
1651 default:
1652 DEBUG(3, ("unsupported info level %d", level));
1653 break;
1656 done:
1657 prs_mem_free(&qbuf);
1658 prs_mem_free(&rbuf);
1660 return result;
1663 /* Set job */
1665 WERROR cli_spoolss_setjob(struct cli_state *cli, TALLOC_CTX *mem_ctx,
1666 POLICY_HND *hnd, uint32 jobid, uint32 level,
1667 uint32 command)
1669 prs_struct qbuf, rbuf;
1670 SPOOL_Q_SETJOB q;
1671 SPOOL_R_SETJOB r;
1672 WERROR result = W_ERROR(ERRgeneral);
1674 ZERO_STRUCT(q);
1675 ZERO_STRUCT(r);
1677 /* Initialise parse structures */
1679 prs_init(&qbuf, MAX_PDU_FRAG_LEN, mem_ctx, MARSHALL);
1680 prs_init(&rbuf, 0, mem_ctx, UNMARSHALL);
1682 /* Initialise input parameters */
1684 make_spoolss_q_setjob(&q, hnd, jobid, level, command);
1686 /* Marshall data and send request */
1688 if (!spoolss_io_q_setjob("", &q, &qbuf, 0) ||
1689 !rpc_api_pipe_req(cli, PI_SPOOLSS, SPOOLSS_SETJOB, &qbuf, &rbuf))
1690 goto done;
1692 /* Unmarshall response */
1694 if (!spoolss_io_r_setjob("", &r, &rbuf, 0))
1695 goto done;
1697 /* Return output parameters */
1699 result = r.status;
1701 done:
1702 prs_mem_free(&qbuf);
1703 prs_mem_free(&rbuf);
1705 return result;
1708 /* Get job */
1710 WERROR cli_spoolss_getjob(struct cli_state *cli, TALLOC_CTX *mem_ctx,
1711 uint32 offered, uint32 *needed,
1712 POLICY_HND *hnd, uint32 jobid, uint32 level,
1713 JOB_INFO_CTR *ctr)
1715 prs_struct qbuf, rbuf;
1716 SPOOL_Q_GETJOB q;
1717 SPOOL_R_GETJOB r;
1718 WERROR result = W_ERROR(ERRgeneral);
1719 RPC_BUFFER buffer;
1721 ZERO_STRUCT(q);
1722 ZERO_STRUCT(r);
1724 /* Initialise parse structures */
1726 rpcbuf_init(&buffer, offered, mem_ctx);
1728 prs_init(&qbuf, MAX_PDU_FRAG_LEN, mem_ctx, MARSHALL);
1729 prs_init(&rbuf, 0, mem_ctx, UNMARSHALL);
1731 /* Initialise input parameters */
1733 make_spoolss_q_getjob(&q, hnd, jobid, level, &buffer, offered);
1735 /* Marshall data and send request */
1737 if (!spoolss_io_q_getjob("", &q, &qbuf, 0) ||
1738 !rpc_api_pipe_req(cli, PI_SPOOLSS, SPOOLSS_GETJOB, &qbuf, &rbuf))
1739 goto done;
1741 /* Unmarshall response */
1743 if (!spoolss_io_r_getjob("", &r, &rbuf, 0))
1744 goto done;
1746 /* Return output parameters */
1748 result = r.status;
1750 if (needed)
1751 *needed = r.needed;
1753 if (!W_ERROR_IS_OK(r.status))
1754 goto done;
1756 switch(level) {
1757 case 1:
1758 decode_jobs_1(mem_ctx, r.buffer, 1, &ctr->job.job_info_1);
1759 break;
1760 case 2:
1761 decode_jobs_2(mem_ctx, r.buffer, 1, &ctr->job.job_info_2);
1762 break;
1763 default:
1764 DEBUG(3, ("unsupported info level %d", level));
1765 break;
1768 done:
1769 prs_mem_free(&qbuf);
1770 prs_mem_free(&rbuf);
1772 return result;
1775 /* Startpageprinter. Sent to notify the spooler when a page is about to be
1776 sent to a printer. */
1778 WERROR cli_spoolss_startpageprinter(struct cli_state *cli, TALLOC_CTX *mem_ctx,
1779 POLICY_HND *hnd)
1781 prs_struct qbuf, rbuf;
1782 SPOOL_Q_STARTPAGEPRINTER q;
1783 SPOOL_R_STARTPAGEPRINTER r;
1784 WERROR result = W_ERROR(ERRgeneral);
1786 ZERO_STRUCT(q);
1787 ZERO_STRUCT(r);
1789 /* Initialise parse structures */
1791 prs_init(&qbuf, MAX_PDU_FRAG_LEN, mem_ctx, MARSHALL);
1792 prs_init(&rbuf, 0, mem_ctx, UNMARSHALL);
1794 /* Initialise input parameters */
1796 make_spoolss_q_startpageprinter(&q, hnd);
1798 /* Marshall data and send request */
1800 if (!spoolss_io_q_startpageprinter("", &q, &qbuf, 0) ||
1801 !rpc_api_pipe_req(cli, PI_SPOOLSS, SPOOLSS_STARTPAGEPRINTER, &qbuf, &rbuf))
1802 goto done;
1804 /* Unmarshall response */
1806 if (!spoolss_io_r_startpageprinter("", &r, &rbuf, 0))
1807 goto done;
1809 /* Return output parameters */
1811 result = r.status;
1813 done:
1814 prs_mem_free(&qbuf);
1815 prs_mem_free(&rbuf);
1817 return result;
1820 /* Endpageprinter. Sent to notify the spooler when a page has finished
1821 being sent to a printer. */
1823 WERROR cli_spoolss_endpageprinter(struct cli_state *cli, TALLOC_CTX *mem_ctx,
1824 POLICY_HND *hnd)
1826 prs_struct qbuf, rbuf;
1827 SPOOL_Q_ENDPAGEPRINTER q;
1828 SPOOL_R_ENDPAGEPRINTER r;
1829 WERROR result = W_ERROR(ERRgeneral);
1831 ZERO_STRUCT(q);
1832 ZERO_STRUCT(r);
1834 /* Initialise parse structures */
1836 prs_init(&qbuf, MAX_PDU_FRAG_LEN, mem_ctx, MARSHALL);
1837 prs_init(&rbuf, 0, mem_ctx, UNMARSHALL);
1839 /* Initialise input parameters */
1841 make_spoolss_q_endpageprinter(&q, hnd);
1843 /* Marshall data and send request */
1845 if (!spoolss_io_q_endpageprinter("", &q, &qbuf, 0) ||
1846 !rpc_api_pipe_req(cli, PI_SPOOLSS, SPOOLSS_ENDPAGEPRINTER, &qbuf, &rbuf))
1847 goto done;
1849 /* Unmarshall response */
1851 if (!spoolss_io_r_endpageprinter("", &r, &rbuf, 0))
1852 goto done;
1854 /* Return output parameters */
1856 result = r.status;
1858 done:
1859 prs_mem_free(&qbuf);
1860 prs_mem_free(&rbuf);
1862 return result;
1865 /* Startdocprinter. Sent to notify the spooler that a document is about
1866 to be spooled for printing. */
1868 WERROR cli_spoolss_startdocprinter(struct cli_state *cli, TALLOC_CTX *mem_ctx,
1869 POLICY_HND *hnd, char *docname,
1870 char *outputfile, char *datatype,
1871 uint32 *jobid)
1873 prs_struct qbuf, rbuf;
1874 SPOOL_Q_STARTDOCPRINTER q;
1875 SPOOL_R_STARTDOCPRINTER r;
1876 WERROR result = W_ERROR(ERRgeneral);
1877 uint32 level = 1;
1879 ZERO_STRUCT(q);
1880 ZERO_STRUCT(r);
1882 /* Initialise parse structures */
1884 prs_init(&qbuf, MAX_PDU_FRAG_LEN, mem_ctx, MARSHALL);
1885 prs_init(&rbuf, 0, mem_ctx, UNMARSHALL);
1887 /* Initialise input parameters */
1889 make_spoolss_q_startdocprinter(&q, hnd, level, docname, outputfile,
1890 datatype);
1892 /* Marshall data and send request */
1894 if (!spoolss_io_q_startdocprinter("", &q, &qbuf, 0) ||
1895 !rpc_api_pipe_req(cli, PI_SPOOLSS, SPOOLSS_STARTDOCPRINTER, &qbuf, &rbuf))
1896 goto done;
1898 /* Unmarshall response */
1900 if (!spoolss_io_r_startdocprinter("", &r, &rbuf, 0))
1901 goto done;
1903 /* Return output parameters */
1905 result = r.status;
1907 if (W_ERROR_IS_OK(result))
1908 *jobid = r.jobid;
1910 done:
1911 prs_mem_free(&qbuf);
1912 prs_mem_free(&rbuf);
1914 return result;
1917 /* Enddocprinter. Sent to notify the spooler that a document has finished
1918 being spooled. */
1920 WERROR cli_spoolss_enddocprinter(struct cli_state *cli, TALLOC_CTX *mem_ctx,
1921 POLICY_HND *hnd)
1923 prs_struct qbuf, rbuf;
1924 SPOOL_Q_ENDDOCPRINTER q;
1925 SPOOL_R_ENDDOCPRINTER r;
1926 WERROR result = W_ERROR(ERRgeneral);
1928 ZERO_STRUCT(q);
1929 ZERO_STRUCT(r);
1931 /* Initialise parse structures */
1933 prs_init(&qbuf, MAX_PDU_FRAG_LEN, mem_ctx, MARSHALL);
1934 prs_init(&rbuf, 0, mem_ctx, UNMARSHALL);
1936 /* Initialise input parameters */
1938 make_spoolss_q_enddocprinter(&q, hnd);
1940 /* Marshall data and send request */
1942 if (!spoolss_io_q_enddocprinter("", &q, &qbuf, 0) ||
1943 !rpc_api_pipe_req(cli, PI_SPOOLSS, SPOOLSS_ENDDOCPRINTER, &qbuf, &rbuf))
1944 goto done;
1946 /* Unmarshall response */
1948 if (!spoolss_io_r_enddocprinter("", &r, &rbuf, 0))
1949 goto done;
1951 /* Return output parameters */
1953 result = r.status;
1955 done:
1956 prs_mem_free(&qbuf);
1957 prs_mem_free(&rbuf);
1959 return result;
1962 /* Get printer data */
1964 WERROR cli_spoolss_getprinterdata(struct cli_state *cli, TALLOC_CTX *mem_ctx,
1965 uint32 offered, uint32 *needed,
1966 POLICY_HND *hnd, const char *valuename,
1967 REGISTRY_VALUE *value)
1969 prs_struct qbuf, rbuf;
1970 SPOOL_Q_GETPRINTERDATA q;
1971 SPOOL_R_GETPRINTERDATA r;
1972 WERROR result = W_ERROR(ERRgeneral);
1974 ZERO_STRUCT(q);
1975 ZERO_STRUCT(r);
1977 /* Initialise parse structures */
1979 prs_init(&qbuf, MAX_PDU_FRAG_LEN, mem_ctx, MARSHALL);
1980 prs_init(&rbuf, 0, mem_ctx, UNMARSHALL);
1982 /* Initialise input parameters */
1984 make_spoolss_q_getprinterdata(&q, hnd, valuename, offered);
1986 /* Marshall data and send request */
1988 if (!spoolss_io_q_getprinterdata("", &q, &qbuf, 0) ||
1989 !rpc_api_pipe_req(cli, PI_SPOOLSS, SPOOLSS_GETPRINTERDATA, &qbuf, &rbuf))
1990 goto done;
1992 /* Unmarshall response */
1994 if (!spoolss_io_r_getprinterdata("", &r, &rbuf, 0))
1995 goto done;
1997 result = r.status;
1999 if (needed)
2000 *needed = r.needed;
2002 if (!W_ERROR_IS_OK(r.status))
2003 goto done;
2005 /* Return output parameters */
2007 value->data_p = TALLOC_MEMDUP(mem_ctx, r.data, r.needed);
2008 value->type = r.type;
2009 value->size = r.size;
2011 done:
2012 prs_mem_free(&qbuf);
2013 prs_mem_free(&rbuf);
2015 return result;
2018 WERROR cli_spoolss_getprinterdataex(struct cli_state *cli, TALLOC_CTX *mem_ctx,
2019 uint32 offered, uint32 *needed,
2020 POLICY_HND *hnd, const char *keyname,
2021 const char *valuename,
2022 REGISTRY_VALUE *value)
2024 prs_struct qbuf, rbuf;
2025 SPOOL_Q_GETPRINTERDATAEX q;
2026 SPOOL_R_GETPRINTERDATAEX r;
2027 WERROR result = W_ERROR(ERRgeneral);
2029 ZERO_STRUCT(q);
2030 ZERO_STRUCT(r);
2032 /* Initialise parse structures */
2034 prs_init(&qbuf, MAX_PDU_FRAG_LEN, mem_ctx, MARSHALL);
2035 prs_init(&rbuf, 0, mem_ctx, UNMARSHALL);
2037 /* Initialise input parameters */
2039 make_spoolss_q_getprinterdataex(&q, hnd, keyname, valuename, offered);
2041 /* Marshall data and send request */
2043 if (!spoolss_io_q_getprinterdataex("", &q, &qbuf, 0) ||
2044 !rpc_api_pipe_req(cli, PI_SPOOLSS, SPOOLSS_GETPRINTERDATAEX, &qbuf, &rbuf))
2045 goto done;
2047 /* Unmarshall response */
2049 if (!spoolss_io_r_getprinterdataex("", &r, &rbuf, 0))
2050 goto done;
2052 result = r.status;
2054 if (needed)
2055 *needed = r.needed;
2057 if (!W_ERROR_IS_OK(r.status))
2058 goto done;
2060 /* Return output parameters */
2062 value->data_p = TALLOC_MEMDUP(mem_ctx, r.data, r.needed);
2063 value->type = r.type;
2064 value->size = r.needed;
2066 done:
2067 prs_mem_free(&qbuf);
2068 prs_mem_free(&rbuf);
2070 return result;
2073 /* Set printer data */
2075 WERROR cli_spoolss_setprinterdata(struct cli_state *cli, TALLOC_CTX *mem_ctx,
2076 POLICY_HND *hnd, REGISTRY_VALUE *value)
2078 prs_struct qbuf, rbuf;
2079 SPOOL_Q_SETPRINTERDATA q;
2080 SPOOL_R_SETPRINTERDATA r;
2081 WERROR result = W_ERROR(ERRgeneral);
2083 ZERO_STRUCT(q);
2084 ZERO_STRUCT(r);
2086 /* Initialise parse structures */
2088 prs_init(&qbuf, MAX_PDU_FRAG_LEN, mem_ctx, MARSHALL);
2089 prs_init(&rbuf, 0, mem_ctx, UNMARSHALL);
2091 /* Initialise input parameters */
2093 make_spoolss_q_setprinterdata(
2094 &q, hnd, value->valuename, value->type, (char *)value->data_p, value->size);
2096 /* Marshall data and send request */
2098 if (!spoolss_io_q_setprinterdata("", &q, &qbuf, 0) ||
2099 !rpc_api_pipe_req(cli, PI_SPOOLSS, SPOOLSS_SETPRINTERDATA, &qbuf, &rbuf))
2100 goto done;
2102 /* Unmarshall response */
2104 if (!spoolss_io_r_setprinterdata("", &r, &rbuf, 0))
2105 goto done;
2107 result = r.status;
2109 if (!W_ERROR_IS_OK(r.status))
2110 goto done;
2112 done:
2113 prs_mem_free(&qbuf);
2114 prs_mem_free(&rbuf);
2116 return result;
2119 WERROR cli_spoolss_setprinterdataex(struct cli_state *cli, TALLOC_CTX *mem_ctx,
2120 POLICY_HND *hnd, char *keyname,
2121 REGISTRY_VALUE *value)
2123 prs_struct qbuf, rbuf;
2124 SPOOL_Q_SETPRINTERDATAEX q;
2125 SPOOL_R_SETPRINTERDATAEX r;
2126 WERROR result = W_ERROR(ERRgeneral);
2128 ZERO_STRUCT(q);
2129 ZERO_STRUCT(r);
2131 /* Initialise parse structures */
2133 prs_init(&qbuf, MAX_PDU_FRAG_LEN, mem_ctx, MARSHALL);
2134 prs_init(&rbuf, 0, mem_ctx, UNMARSHALL);
2136 /* Initialise input parameters */
2138 make_spoolss_q_setprinterdataex(
2139 &q, hnd, keyname, value->valuename, value->type, (char *)value->data_p,
2140 value->size);
2142 /* Marshall data and send request */
2144 if (!spoolss_io_q_setprinterdataex("", &q, &qbuf, 0) ||
2145 !rpc_api_pipe_req(cli, PI_SPOOLSS, SPOOLSS_SETPRINTERDATAEX, &qbuf, &rbuf))
2146 goto done;
2148 /* Unmarshall response */
2150 if (!spoolss_io_r_setprinterdataex("", &r, &rbuf, 0))
2151 goto done;
2153 result = r.status;
2155 if (!W_ERROR_IS_OK(r.status))
2156 goto done;
2158 done:
2159 prs_mem_free(&qbuf);
2160 prs_mem_free(&rbuf);
2162 return result;
2165 /* Enum printer data */
2167 WERROR cli_spoolss_enumprinterdata(struct cli_state *cli, TALLOC_CTX *mem_ctx,
2168 POLICY_HND *hnd, uint32 ndx,
2169 uint32 value_offered, uint32 data_offered,
2170 uint32 *value_needed, uint32 *data_needed,
2171 REGISTRY_VALUE *value)
2173 prs_struct qbuf, rbuf;
2174 SPOOL_Q_ENUMPRINTERDATA q;
2175 SPOOL_R_ENUMPRINTERDATA r;
2176 WERROR result = W_ERROR(ERRgeneral);
2178 ZERO_STRUCT(q);
2179 ZERO_STRUCT(r);
2181 /* Initialise parse structures */
2183 prs_init(&qbuf, MAX_PDU_FRAG_LEN, mem_ctx, MARSHALL);
2184 prs_init(&rbuf, 0, mem_ctx, UNMARSHALL);
2186 /* Initialise input parameters */
2188 make_spoolss_q_enumprinterdata(&q, hnd, ndx, value_offered, data_offered);
2190 /* Marshall data and send request */
2192 if (!spoolss_io_q_enumprinterdata("", &q, &qbuf, 0) ||
2193 !rpc_api_pipe_req(cli, PI_SPOOLSS, SPOOLSS_ENUMPRINTERDATA, &qbuf, &rbuf))
2194 goto done;
2196 /* Unmarshall response */
2198 if (!spoolss_io_r_enumprinterdata("", &r, &rbuf, 0))
2199 goto done;
2201 result = r.status;
2203 if (!W_ERROR_IS_OK(r.status))
2204 goto done;
2206 /* Return data */
2208 if (value_needed)
2209 *value_needed = r.realvaluesize;
2211 if (data_needed)
2212 *data_needed = r.realdatasize;
2214 if (value) {
2215 rpcstr_pull(value->valuename, r.value, sizeof(value->valuename), -1,
2216 STR_TERMINATE);
2217 value->data_p = TALLOC_MEMDUP(mem_ctx, r.data, r.realdatasize);
2218 value->type = r.type;
2219 value->size = r.realdatasize;
2222 done:
2223 prs_mem_free(&qbuf);
2224 prs_mem_free(&rbuf);
2226 return result;
2229 WERROR cli_spoolss_enumprinterdataex(struct cli_state *cli, TALLOC_CTX *mem_ctx,
2230 uint32 offered, uint32 *needed,
2231 POLICY_HND *hnd, const char *keyname,
2232 REGVAL_CTR *ctr)
2234 prs_struct qbuf, rbuf;
2235 SPOOL_Q_ENUMPRINTERDATAEX q;
2236 SPOOL_R_ENUMPRINTERDATAEX r;
2237 WERROR result = W_ERROR(ERRgeneral);
2238 int i;
2240 ZERO_STRUCT(q);
2241 ZERO_STRUCT(r);
2243 /* Initialise parse structures */
2245 prs_init(&qbuf, MAX_PDU_FRAG_LEN, mem_ctx, MARSHALL);
2246 prs_init(&rbuf, 0, mem_ctx, UNMARSHALL);
2248 /* Initialise input parameters */
2250 make_spoolss_q_enumprinterdataex(&q, hnd, keyname, offered);
2252 /* Marshall data and send request */
2254 if (!spoolss_io_q_enumprinterdataex("", &q, &qbuf, 0) ||
2255 !rpc_api_pipe_req(cli, PI_SPOOLSS, SPOOLSS_ENUMPRINTERDATAEX, &qbuf, &rbuf))
2256 goto done;
2258 /* Unmarshall response */
2260 if (!spoolss_io_r_enumprinterdataex("", &r, &rbuf, 0))
2261 goto done;
2263 result = r.status;
2265 if (needed)
2266 *needed = r.needed;
2268 if (!W_ERROR_IS_OK(r.status))
2269 goto done;
2271 /* Return data */
2273 ZERO_STRUCTP(ctr);
2274 regval_ctr_init(ctr);
2276 for (i = 0; i < r.returned; i++) {
2277 PRINTER_ENUM_VALUES *v = &r.ctr.values[i];
2278 fstring name;
2280 rpcstr_pull(name, v->valuename.buffer, sizeof(name), -1,
2281 STR_TERMINATE);
2282 regval_ctr_addvalue(ctr, name, v->type, (const char *)v->data, v->data_len);
2285 done:
2286 prs_mem_free(&qbuf);
2287 prs_mem_free(&rbuf);
2289 return result;
2292 /* Write data to printer */
2294 WERROR cli_spoolss_writeprinter(struct cli_state *cli, TALLOC_CTX *mem_ctx,
2295 POLICY_HND *hnd, uint32 data_size, char *data,
2296 uint32 *num_written)
2298 prs_struct qbuf, rbuf;
2299 SPOOL_Q_WRITEPRINTER q;
2300 SPOOL_R_WRITEPRINTER r;
2301 WERROR result = W_ERROR(ERRgeneral);
2303 ZERO_STRUCT(q);
2304 ZERO_STRUCT(r);
2306 /* Initialise parse structures */
2308 prs_init(&qbuf, MAX_PDU_FRAG_LEN, mem_ctx, MARSHALL);
2309 prs_init(&rbuf, 0, mem_ctx, UNMARSHALL);
2311 /* Initialise input parameters */
2313 make_spoolss_q_writeprinter(&q, hnd, data_size, data);
2315 /* Marshall data and send request */
2317 if (!spoolss_io_q_writeprinter("", &q, &qbuf, 0) ||
2318 !rpc_api_pipe_req(cli, PI_SPOOLSS, SPOOLSS_WRITEPRINTER, &qbuf, &rbuf))
2319 goto done;
2321 /* Unmarshall response */
2323 if (!spoolss_io_r_writeprinter("", &r, &rbuf, 0))
2324 goto done;
2326 result = r.status;
2328 if (!W_ERROR_IS_OK(r.status))
2329 goto done;
2331 if (num_written)
2332 *num_written = r.buffer_written;
2334 done:
2335 prs_mem_free(&qbuf);
2336 prs_mem_free(&rbuf);
2338 return result;
2341 /* Delete printer data */
2343 WERROR cli_spoolss_deleteprinterdata(struct cli_state *cli, TALLOC_CTX *mem_ctx,
2344 POLICY_HND *hnd, char *valuename)
2346 prs_struct qbuf, rbuf;
2347 SPOOL_Q_DELETEPRINTERDATA q;
2348 SPOOL_R_DELETEPRINTERDATA r;
2349 WERROR result = W_ERROR(ERRgeneral);
2351 ZERO_STRUCT(q);
2352 ZERO_STRUCT(r);
2354 /* Initialise parse structures */
2356 prs_init(&qbuf, MAX_PDU_FRAG_LEN, mem_ctx, MARSHALL);
2357 prs_init(&rbuf, 0, mem_ctx, UNMARSHALL);
2359 /* Initialise input parameters */
2361 make_spoolss_q_deleteprinterdata(&q, hnd, valuename);
2363 /* Marshall data and send request */
2365 if (!spoolss_io_q_deleteprinterdata("", &q, &qbuf, 0) ||
2366 !rpc_api_pipe_req(cli, PI_SPOOLSS, SPOOLSS_DELETEPRINTERDATA, &qbuf, &rbuf))
2367 goto done;
2369 /* Unmarshall response */
2371 if (!spoolss_io_r_deleteprinterdata("", &r, &rbuf, 0))
2372 goto done;
2374 result = r.status;
2376 if (!W_ERROR_IS_OK(r.status))
2377 goto done;
2379 done:
2380 prs_mem_free(&qbuf);
2381 prs_mem_free(&rbuf);
2383 return result;
2386 WERROR cli_spoolss_deleteprinterdataex(struct cli_state *cli, TALLOC_CTX *mem_ctx,
2387 POLICY_HND *hnd, char *keyname,
2388 char *valuename)
2390 prs_struct qbuf, rbuf;
2391 SPOOL_Q_DELETEPRINTERDATAEX q;
2392 SPOOL_R_DELETEPRINTERDATAEX r;
2393 WERROR result = W_ERROR(ERRgeneral);
2395 ZERO_STRUCT(q);
2396 ZERO_STRUCT(r);
2398 /* Initialise parse structures */
2400 prs_init(&qbuf, MAX_PDU_FRAG_LEN, mem_ctx, MARSHALL);
2401 prs_init(&rbuf, 0, mem_ctx, UNMARSHALL);
2403 /* Initialise input parameters */
2405 make_spoolss_q_deleteprinterdataex(&q, hnd, keyname, valuename);
2407 /* Marshall data and send request */
2409 if (!spoolss_io_q_deleteprinterdataex("", &q, &qbuf, 0) ||
2410 !rpc_api_pipe_req(cli, PI_SPOOLSS, SPOOLSS_DELETEPRINTERDATAEX, &qbuf, &rbuf))
2411 goto done;
2413 /* Unmarshall response */
2415 if (!spoolss_io_r_deleteprinterdataex("", &r, &rbuf, 0))
2416 goto done;
2418 result = r.status;
2420 if (!W_ERROR_IS_OK(r.status))
2421 goto done;
2423 done:
2424 prs_mem_free(&qbuf);
2425 prs_mem_free(&rbuf);
2427 return result;
2430 WERROR cli_spoolss_enumprinterkey(struct cli_state *cli, TALLOC_CTX *mem_ctx,
2431 uint32 offered, uint32 *needed,
2432 POLICY_HND *hnd, const char *keyname,
2433 uint16 **keylist, uint32 *len)
2435 prs_struct qbuf, rbuf;
2436 SPOOL_Q_ENUMPRINTERKEY q;
2437 SPOOL_R_ENUMPRINTERKEY r;
2438 WERROR result = W_ERROR(ERRgeneral);
2440 ZERO_STRUCT(q);
2441 ZERO_STRUCT(r);
2443 /* Initialise parse structures */
2445 prs_init(&qbuf, MAX_PDU_FRAG_LEN, mem_ctx, MARSHALL);
2446 prs_init(&rbuf, 0, mem_ctx, UNMARSHALL);
2448 /* Initialise input parameters */
2450 make_spoolss_q_enumprinterkey(&q, hnd, keyname, offered);
2452 /* Marshall data and send request */
2454 if (!spoolss_io_q_enumprinterkey("", &q, &qbuf, 0) ||
2455 !rpc_api_pipe_req(cli, PI_SPOOLSS, SPOOLSS_ENUMPRINTERKEY, &qbuf, &rbuf))
2456 goto done;
2458 /* Unmarshall response */
2460 if (!spoolss_io_r_enumprinterkey("", &r, &rbuf, 0))
2461 goto done;
2463 result = r.status;
2465 if (needed)
2466 *needed = r.needed;
2468 if (!W_ERROR_IS_OK(r.status))
2469 goto done;
2471 /* Copy results */
2473 if (keylist) {
2474 *keylist = SMB_MALLOC_ARRAY(uint16, r.keys.buf_len);
2475 memcpy(*keylist, r.keys.buffer, r.keys.buf_len * 2);
2476 if (len)
2477 *len = r.keys.buf_len * 2;
2480 done:
2481 prs_mem_free(&qbuf);
2482 prs_mem_free(&rbuf);
2484 return result;
2487 WERROR cli_spoolss_deleteprinterkey(struct cli_state *cli, TALLOC_CTX *mem_ctx,
2488 POLICY_HND *hnd, char *keyname)
2490 prs_struct qbuf, rbuf;
2491 SPOOL_Q_DELETEPRINTERKEY q;
2492 SPOOL_R_DELETEPRINTERKEY r;
2493 WERROR result = W_ERROR(ERRgeneral);
2495 ZERO_STRUCT(q);
2496 ZERO_STRUCT(r);
2498 /* Initialise parse structures */
2500 prs_init(&qbuf, MAX_PDU_FRAG_LEN, mem_ctx, MARSHALL);
2501 prs_init(&rbuf, 0, mem_ctx, UNMARSHALL);
2503 /* Initialise input parameters */
2505 make_spoolss_q_deleteprinterkey(&q, hnd, keyname);
2507 /* Marshall data and send request */
2509 if (!spoolss_io_q_deleteprinterkey("", &q, &qbuf, 0) ||
2510 !rpc_api_pipe_req(cli, PI_SPOOLSS, SPOOLSS_DELETEPRINTERKEY, &qbuf, &rbuf))
2511 goto done;
2513 /* Unmarshall response */
2515 if (!spoolss_io_r_deleteprinterkey("", &r, &rbuf, 0))
2516 goto done;
2518 result = r.status;
2520 if (!W_ERROR_IS_OK(r.status))
2521 goto done;
2523 done:
2524 prs_mem_free(&qbuf);
2525 prs_mem_free(&rbuf);
2527 return result;
2530 /** @} **/