Make 3.0.x in sync with 3.2 here.
[Samba.git] / source / rpc_client / cli_spoolss.c
blob76a5e0b8ad48423960e689bb4bdf6e67dc0b6dcd
1 /*
2 Unix SMB/CIFS implementation.
3 RPC pipe client
5 Copyright (C) Gerald Carter 2001-2005,
6 Copyright (C) Tim Potter 2000-2002,
7 Copyright (C) Andrew Tridgell 1994-2000,
8 Copyright (C) Jean-Francois Micouleau 1999-2000.
9 Copyright (C) Jeremy Allison 2005.
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"
27 #include "rpc_client.h"
29 /*********************************************************************
30 Decode various spoolss rpc's and info levels
31 ********************************************************************/
33 /**********************************************************************
34 **********************************************************************/
36 static BOOL decode_printer_info_0(TALLOC_CTX *mem_ctx, RPC_BUFFER *buffer,
37 uint32 returned, PRINTER_INFO_0 **info)
39 uint32 i;
40 PRINTER_INFO_0 *inf;
42 if (returned) {
43 inf=TALLOC_ARRAY(mem_ctx, PRINTER_INFO_0, returned);
44 if (!inf) {
45 return False;
47 memset(inf, 0, returned*sizeof(PRINTER_INFO_0));
48 } else {
49 inf = NULL;
52 prs_set_offset(&buffer->prs,0);
54 for (i=0; i<returned; i++) {
55 if (!smb_io_printer_info_0("", buffer, &inf[i], 0)) {
56 return False;
60 *info=inf;
61 return True;
64 /**********************************************************************
65 **********************************************************************/
67 static BOOL decode_printer_info_1(TALLOC_CTX *mem_ctx, RPC_BUFFER *buffer,
68 uint32 returned, PRINTER_INFO_1 **info)
70 uint32 i;
71 PRINTER_INFO_1 *inf;
73 if (returned) {
74 inf=TALLOC_ARRAY(mem_ctx, PRINTER_INFO_1, returned);
75 if (!inf) {
76 return False;
78 memset(inf, 0, returned*sizeof(PRINTER_INFO_1));
79 } else {
80 inf = NULL;
83 prs_set_offset(&buffer->prs,0);
85 for (i=0; i<returned; i++) {
86 if (!smb_io_printer_info_1("", buffer, &inf[i], 0)) {
87 return False;
91 *info=inf;
92 return True;
95 /**********************************************************************
96 **********************************************************************/
98 static BOOL decode_printer_info_2(TALLOC_CTX *mem_ctx, RPC_BUFFER *buffer,
99 uint32 returned, PRINTER_INFO_2 **info)
101 uint32 i;
102 PRINTER_INFO_2 *inf;
104 if (returned) {
105 inf=TALLOC_ARRAY(mem_ctx, PRINTER_INFO_2, returned);
106 if (!inf) {
107 return False;
109 memset(inf, 0, returned*sizeof(PRINTER_INFO_2));
110 } else {
111 inf = NULL;
114 prs_set_offset(&buffer->prs,0);
116 for (i=0; i<returned; i++) {
117 /* a little initialization as we go */
118 inf[i].secdesc = NULL;
119 if (!smb_io_printer_info_2("", buffer, &inf[i], 0)) {
120 return False;
124 *info=inf;
125 return True;
128 /**********************************************************************
129 **********************************************************************/
131 static BOOL decode_printer_info_3(TALLOC_CTX *mem_ctx, RPC_BUFFER *buffer,
132 uint32 returned, PRINTER_INFO_3 **info)
134 uint32 i;
135 PRINTER_INFO_3 *inf;
137 if (returned) {
138 inf=TALLOC_ARRAY(mem_ctx, PRINTER_INFO_3, returned);
139 if (!inf) {
140 return False;
142 memset(inf, 0, returned*sizeof(PRINTER_INFO_3));
143 } else {
144 inf = NULL;
147 prs_set_offset(&buffer->prs,0);
149 for (i=0; i<returned; i++) {
150 inf[i].secdesc = NULL;
151 if (!smb_io_printer_info_3("", buffer, &inf[i], 0)) {
152 return False;
156 *info=inf;
157 return True;
160 /**********************************************************************
161 **********************************************************************/
163 static BOOL decode_printer_info_7(TALLOC_CTX *mem_ctx, RPC_BUFFER *buffer,
164 uint32 returned, PRINTER_INFO_7 **info)
166 uint32 i;
167 PRINTER_INFO_7 *inf;
169 if (returned) {
170 inf=TALLOC_ARRAY(mem_ctx, PRINTER_INFO_7, returned);
171 if (!inf) {
172 return False;
174 memset(inf, 0, returned*sizeof(PRINTER_INFO_7));
175 } else {
176 inf = NULL;
179 prs_set_offset(&buffer->prs,0);
181 for (i=0; i<returned; i++) {
182 if (!smb_io_printer_info_7("", buffer, &inf[i], 0)) {
183 return False;
187 *info=inf;
188 return True;
192 /**********************************************************************
193 **********************************************************************/
195 static BOOL decode_port_info_1(TALLOC_CTX *mem_ctx, RPC_BUFFER *buffer,
196 uint32 returned, PORT_INFO_1 **info)
198 uint32 i;
199 PORT_INFO_1 *inf;
201 if (returned) {
202 inf=TALLOC_ARRAY(mem_ctx, PORT_INFO_1, returned);
203 if (!inf) {
204 return False;
206 memset(inf, 0, returned*sizeof(PORT_INFO_1));
207 } else {
208 inf = NULL;
211 prs_set_offset(&buffer->prs, 0);
213 for (i=0; i<returned; i++) {
214 if (!smb_io_port_info_1("", buffer, &(inf[i]), 0)) {
215 return False;
219 *info=inf;
220 return True;
223 /**********************************************************************
224 **********************************************************************/
226 static BOOL decode_port_info_2(TALLOC_CTX *mem_ctx, RPC_BUFFER *buffer,
227 uint32 returned, PORT_INFO_2 **info)
229 uint32 i;
230 PORT_INFO_2 *inf;
232 if (returned) {
233 inf=TALLOC_ARRAY(mem_ctx, PORT_INFO_2, returned);
234 if (!inf) {
235 return False;
237 memset(inf, 0, returned*sizeof(PORT_INFO_2));
238 } else {
239 inf = NULL;
242 prs_set_offset(&buffer->prs, 0);
244 for (i=0; i<returned; i++) {
245 if (!smb_io_port_info_2("", buffer, &(inf[i]), 0)) {
246 return False;
250 *info=inf;
251 return True;
254 /**********************************************************************
255 **********************************************************************/
257 static BOOL decode_printer_driver_1(TALLOC_CTX *mem_ctx, RPC_BUFFER *buffer,
258 uint32 returned, DRIVER_INFO_1 **info)
260 uint32 i;
261 DRIVER_INFO_1 *inf;
263 if (returned) {
264 inf=TALLOC_ARRAY(mem_ctx, DRIVER_INFO_1, returned);
265 if (!inf) {
266 return False;
268 memset(inf, 0, returned*sizeof(DRIVER_INFO_1));
269 } else {
270 inf = NULL;
273 prs_set_offset(&buffer->prs,0);
275 for (i=0; i<returned; i++) {
276 if (!smb_io_printer_driver_info_1("", buffer, &(inf[i]), 0)) {
277 return False;
281 *info=inf;
282 return True;
285 /**********************************************************************
286 **********************************************************************/
288 static BOOL decode_printer_driver_2(TALLOC_CTX *mem_ctx, RPC_BUFFER *buffer,
289 uint32 returned, DRIVER_INFO_2 **info)
291 uint32 i;
292 DRIVER_INFO_2 *inf;
294 if (returned) {
295 inf=TALLOC_ARRAY(mem_ctx, DRIVER_INFO_2, returned);
296 if (!inf) {
297 return False;
299 memset(inf, 0, returned*sizeof(DRIVER_INFO_2));
300 } else {
301 inf = NULL;
304 prs_set_offset(&buffer->prs,0);
306 for (i=0; i<returned; i++) {
307 if (!smb_io_printer_driver_info_2("", buffer, &(inf[i]), 0)) {
308 return False;
312 *info=inf;
313 return True;
316 /**********************************************************************
317 **********************************************************************/
319 static BOOL decode_printer_driver_3(TALLOC_CTX *mem_ctx, RPC_BUFFER *buffer,
320 uint32 returned, DRIVER_INFO_3 **info)
322 uint32 i;
323 DRIVER_INFO_3 *inf;
325 if (returned) {
326 inf=TALLOC_ARRAY(mem_ctx, DRIVER_INFO_3, returned);
327 if (!inf) {
328 return False;
330 memset(inf, 0, returned*sizeof(DRIVER_INFO_3));
331 } else {
332 inf = NULL;
335 prs_set_offset(&buffer->prs,0);
337 for (i=0; i<returned; i++) {
338 if (!smb_io_printer_driver_info_3("", buffer, &(inf[i]), 0)) {
339 return False;
343 *info=inf;
344 return True;
347 /**********************************************************************
348 **********************************************************************/
350 static BOOL decode_printerdriverdir_1 (TALLOC_CTX *mem_ctx, RPC_BUFFER *buffer,
351 uint32 returned, DRIVER_DIRECTORY_1 **info
354 DRIVER_DIRECTORY_1 *inf;
356 inf=TALLOC_P(mem_ctx, DRIVER_DIRECTORY_1);
357 if (!inf) {
358 return False;
360 memset(inf, 0, sizeof(DRIVER_DIRECTORY_1));
362 prs_set_offset(&buffer->prs, 0);
364 if (!smb_io_driverdir_1("", buffer, inf, 0)) {
365 return False;
368 *info=inf;
369 return True;
372 /**********************************************************************
373 **********************************************************************/
375 static BOOL decode_jobs_1(TALLOC_CTX *mem_ctx, RPC_BUFFER *buffer,
376 uint32 num_jobs, JOB_INFO_1 **jobs)
378 uint32 i;
380 if (num_jobs) {
381 *jobs = TALLOC_ARRAY(mem_ctx, JOB_INFO_1, num_jobs);
382 if (*jobs == NULL) {
383 return False;
385 } else {
386 *jobs = NULL;
388 prs_set_offset(&buffer->prs,0);
390 for (i = 0; i < num_jobs; i++) {
391 if (!smb_io_job_info_1("", buffer, &((*jobs)[i]), 0)) {
392 return False;
396 return True;
399 /**********************************************************************
400 **********************************************************************/
402 static BOOL decode_jobs_2(TALLOC_CTX *mem_ctx, RPC_BUFFER *buffer,
403 uint32 num_jobs, JOB_INFO_2 **jobs)
405 uint32 i;
407 if (num_jobs) {
408 *jobs = TALLOC_ARRAY(mem_ctx, JOB_INFO_2, num_jobs);
409 if (*jobs == NULL) {
410 return False;
412 } else {
413 *jobs = NULL;
415 prs_set_offset(&buffer->prs,0);
417 for (i = 0; i < num_jobs; i++) {
418 if (!smb_io_job_info_2("", buffer, &((*jobs)[i]), 0)) {
419 return False;
423 return True;
426 /**********************************************************************
427 **********************************************************************/
429 static BOOL decode_forms_1(TALLOC_CTX *mem_ctx, RPC_BUFFER *buffer,
430 uint32 num_forms, FORM_1 **forms)
432 int i;
434 if (num_forms) {
435 *forms = TALLOC_ARRAY(mem_ctx, FORM_1, num_forms);
436 if (*forms == NULL) {
437 return False;
439 } else {
440 *forms = NULL;
443 prs_set_offset(&buffer->prs,0);
445 for (i = 0; i < num_forms; i++) {
446 if (!smb_io_form_1("", buffer, &((*forms)[i]), 0)) {
447 return False;
451 return True;
454 /**********************************************************************
455 **********************************************************************/
457 WERROR rpccli_spoolss_open_printer_ex(struct rpc_pipe_client *cli, TALLOC_CTX *mem_ctx,
458 const char *printername, const char *datatype, uint32 access_required,
459 const char *station, const char *username, POLICY_HND *pol)
461 prs_struct qbuf, rbuf;
462 SPOOL_Q_OPEN_PRINTER_EX in;
463 SPOOL_R_OPEN_PRINTER_EX out;
465 ZERO_STRUCT(in);
466 ZERO_STRUCT(out);
468 make_spoolss_q_open_printer_ex( &in, printername, datatype,
469 access_required, station, username );
471 CLI_DO_RPC_WERR( cli, mem_ctx, PI_SPOOLSS, SPOOLSS_OPENPRINTEREX,
472 in, out,
473 qbuf, rbuf,
474 spoolss_io_q_open_printer_ex,
475 spoolss_io_r_open_printer_ex,
476 WERR_GENERAL_FAILURE );
478 memcpy( pol, &out.handle, sizeof(POLICY_HND) );
480 return out.status;
483 /**********************************************************************
484 **********************************************************************/
486 WERROR rpccli_spoolss_close_printer(struct rpc_pipe_client *cli, TALLOC_CTX *mem_ctx,
487 POLICY_HND *pol)
489 prs_struct qbuf, rbuf;
490 SPOOL_Q_CLOSEPRINTER in;
491 SPOOL_R_CLOSEPRINTER out;
493 ZERO_STRUCT(in);
494 ZERO_STRUCT(out);
496 make_spoolss_q_closeprinter( &in, pol );
498 CLI_DO_RPC_WERR( cli, mem_ctx, PI_SPOOLSS, SPOOLSS_CLOSEPRINTER,
499 in, out,
500 qbuf, rbuf,
501 spoolss_io_q_closeprinter,
502 spoolss_io_r_closeprinter,
503 WERR_GENERAL_FAILURE );
505 return out.status;
508 /**********************************************************************
509 **********************************************************************/
511 WERROR rpccli_spoolss_enum_printers(struct rpc_pipe_client *cli, TALLOC_CTX *mem_ctx,
512 char *name, uint32 flags, uint32 level,
513 uint32 *num_printers, PRINTER_INFO_CTR *ctr)
515 prs_struct qbuf, rbuf;
516 SPOOL_Q_ENUMPRINTERS in;
517 SPOOL_R_ENUMPRINTERS out;
518 RPC_BUFFER buffer;
519 uint32 offered;
521 ZERO_STRUCT(in);
522 ZERO_STRUCT(out);
524 offered = 0;
525 rpcbuf_init(&buffer, offered, mem_ctx);
526 make_spoolss_q_enumprinters( &in, flags, name, level, &buffer, offered );
528 CLI_DO_RPC_WERR( cli, mem_ctx, PI_SPOOLSS, SPOOLSS_ENUMPRINTERS,
529 in, out,
530 qbuf, rbuf,
531 spoolss_io_q_enumprinters,
532 spoolss_io_r_enumprinters,
533 WERR_GENERAL_FAILURE );
535 if ( W_ERROR_EQUAL( out.status, WERR_INSUFFICIENT_BUFFER ) ) {
536 offered = out.needed;
538 ZERO_STRUCT(in);
539 ZERO_STRUCT(out);
541 rpcbuf_init(&buffer, offered, mem_ctx);
542 make_spoolss_q_enumprinters( &in, flags, name, level, &buffer, offered );
544 CLI_DO_RPC_WERR( cli, mem_ctx, PI_SPOOLSS, SPOOLSS_ENUMPRINTERS,
545 in, out,
546 qbuf, rbuf,
547 spoolss_io_q_enumprinters,
548 spoolss_io_r_enumprinters,
549 WERR_GENERAL_FAILURE );
552 if ( !W_ERROR_IS_OK(out.status) )
553 return out.status;
555 switch (level) {
556 case 0:
557 if (!decode_printer_info_0(mem_ctx, out.buffer, out.returned, &ctr->printers_0)) {
558 return WERR_GENERAL_FAILURE;
560 break;
561 case 1:
562 if (!decode_printer_info_1(mem_ctx, out.buffer, out.returned, &ctr->printers_1)) {
563 return WERR_GENERAL_FAILURE;
565 break;
566 case 2:
567 if (!decode_printer_info_2(mem_ctx, out.buffer, out.returned, &ctr->printers_2)) {
568 return WERR_GENERAL_FAILURE;
570 break;
571 case 3:
572 if (!decode_printer_info_3(mem_ctx, out.buffer, out.returned, &ctr->printers_3)) {
573 return WERR_GENERAL_FAILURE;
575 break;
576 default:
577 return WERR_UNKNOWN_LEVEL;
580 *num_printers = out.returned;
582 return out.status;
585 /**********************************************************************
586 **********************************************************************/
588 WERROR rpccli_spoolss_enum_ports(struct rpc_pipe_client *cli, TALLOC_CTX *mem_ctx,
589 uint32 level, uint32 *num_ports, PORT_INFO_CTR *ctr)
591 prs_struct qbuf, rbuf;
592 SPOOL_Q_ENUMPORTS in;
593 SPOOL_R_ENUMPORTS out;
594 RPC_BUFFER buffer;
595 fstring server;
596 uint32 offered;
598 ZERO_STRUCT(in);
599 ZERO_STRUCT(out);
601 slprintf(server, sizeof(fstring)-1, "\\\\%s", cli->cli->desthost);
602 strupper_m(server);
604 offered = 0;
605 rpcbuf_init(&buffer, offered, mem_ctx);
606 make_spoolss_q_enumports( &in, server, level, &buffer, offered );
608 CLI_DO_RPC_WERR( cli, mem_ctx, PI_SPOOLSS, SPOOLSS_ENUMPORTS,
609 in, out,
610 qbuf, rbuf,
611 spoolss_io_q_enumports,
612 spoolss_io_r_enumports,
613 WERR_GENERAL_FAILURE );
615 if ( W_ERROR_EQUAL( out.status, WERR_INSUFFICIENT_BUFFER ) ) {
616 offered = out.needed;
618 ZERO_STRUCT(in);
619 ZERO_STRUCT(out);
621 rpcbuf_init(&buffer, offered, mem_ctx);
622 make_spoolss_q_enumports( &in, server, level, &buffer, offered );
624 CLI_DO_RPC_WERR( cli, mem_ctx, PI_SPOOLSS, SPOOLSS_ENUMPORTS,
625 in, out,
626 qbuf, rbuf,
627 spoolss_io_q_enumports,
628 spoolss_io_r_enumports,
629 WERR_GENERAL_FAILURE );
632 if ( !W_ERROR_IS_OK(out.status) )
633 return out.status;
635 switch (level) {
636 case 1:
637 if (!decode_port_info_1(mem_ctx, out.buffer, out.returned, &ctr->port.info_1)) {
638 return WERR_GENERAL_FAILURE;
640 break;
641 case 2:
642 if (!decode_port_info_2(mem_ctx, out.buffer, out.returned, &ctr->port.info_2)) {
643 return WERR_GENERAL_FAILURE;
645 break;
646 default:
647 return WERR_UNKNOWN_LEVEL;
650 *num_ports = out.returned;
652 return out.status;
655 /**********************************************************************
656 **********************************************************************/
658 WERROR rpccli_spoolss_getprinter(struct rpc_pipe_client *cli, TALLOC_CTX *mem_ctx,
659 POLICY_HND *pol, uint32 level,
660 PRINTER_INFO_CTR *ctr)
662 prs_struct qbuf, rbuf;
663 SPOOL_Q_GETPRINTER in;
664 SPOOL_R_GETPRINTER out;
665 RPC_BUFFER buffer;
666 uint32 offered;
668 ZERO_STRUCT(in);
669 ZERO_STRUCT(out);
671 /* Initialise input parameters */
673 offered = 0;
674 rpcbuf_init(&buffer, offered, mem_ctx);
675 make_spoolss_q_getprinter( mem_ctx, &in, pol, level, &buffer, offered );
677 CLI_DO_RPC_WERR( cli, mem_ctx, PI_SPOOLSS, SPOOLSS_GETPRINTER,
678 in, out,
679 qbuf, rbuf,
680 spoolss_io_q_getprinter,
681 spoolss_io_r_getprinter,
682 WERR_GENERAL_FAILURE );
684 if ( W_ERROR_EQUAL( out.status, WERR_INSUFFICIENT_BUFFER ) ) {
685 offered = out.needed;
687 ZERO_STRUCT(in);
688 ZERO_STRUCT(out);
690 rpcbuf_init(&buffer, offered, mem_ctx);
691 make_spoolss_q_getprinter( mem_ctx, &in, pol, level, &buffer, offered );
693 CLI_DO_RPC_WERR( cli, mem_ctx, PI_SPOOLSS, SPOOLSS_GETPRINTER,
694 in, out,
695 qbuf, rbuf,
696 spoolss_io_q_getprinter,
697 spoolss_io_r_getprinter,
698 WERR_GENERAL_FAILURE );
701 if ( !W_ERROR_IS_OK(out.status) )
702 return out.status;
704 switch (level) {
705 case 0:
706 if (!decode_printer_info_0(mem_ctx, out.buffer, 1, &ctr->printers_0)) {
707 return WERR_GENERAL_FAILURE;
709 break;
710 case 1:
711 if (!decode_printer_info_1(mem_ctx, out.buffer, 1, &ctr->printers_1)) {
712 return WERR_GENERAL_FAILURE;
714 break;
715 case 2:
716 if (!decode_printer_info_2(mem_ctx, out.buffer, 1, &ctr->printers_2)) {
717 return WERR_GENERAL_FAILURE;
719 break;
720 case 3:
721 if (!decode_printer_info_3(mem_ctx, out.buffer, 1, &ctr->printers_3)) {
722 return WERR_GENERAL_FAILURE;
724 break;
725 case 7:
726 if (!decode_printer_info_7(mem_ctx, out.buffer, 1, &ctr->printers_7)) {
727 return WERR_GENERAL_FAILURE;
729 break;
730 default:
731 return WERR_UNKNOWN_LEVEL;
734 return out.status;
737 /**********************************************************************
738 **********************************************************************/
740 WERROR rpccli_spoolss_setprinter(struct rpc_pipe_client *cli, TALLOC_CTX *mem_ctx,
741 POLICY_HND *pol, uint32 level,
742 PRINTER_INFO_CTR *ctr, uint32 command)
744 prs_struct qbuf, rbuf;
745 SPOOL_Q_SETPRINTER in;
746 SPOOL_R_SETPRINTER out;
748 ZERO_STRUCT(in);
749 ZERO_STRUCT(out);
751 make_spoolss_q_setprinter( mem_ctx, &in, pol, level, ctr, command );
753 CLI_DO_RPC_WERR( cli, mem_ctx, PI_SPOOLSS, SPOOLSS_SETPRINTER,
754 in, out,
755 qbuf, rbuf,
756 spoolss_io_q_setprinter,
757 spoolss_io_r_setprinter,
758 WERR_GENERAL_FAILURE );
760 return out.status;
763 /**********************************************************************
764 **********************************************************************/
766 WERROR rpccli_spoolss_getprinterdriver(struct rpc_pipe_client *cli,
767 TALLOC_CTX *mem_ctx,
768 POLICY_HND *pol, uint32 level,
769 const char *env, int version, PRINTER_DRIVER_CTR *ctr)
771 prs_struct qbuf, rbuf;
772 SPOOL_Q_GETPRINTERDRIVER2 in;
773 SPOOL_R_GETPRINTERDRIVER2 out;
774 RPC_BUFFER buffer;
775 fstring server;
776 uint32 offered;
778 ZERO_STRUCT(in);
779 ZERO_STRUCT(out);
781 fstrcpy(server, cli->cli->desthost);
782 strupper_m(server);
784 offered = 0;
785 rpcbuf_init(&buffer, offered, mem_ctx);
786 make_spoolss_q_getprinterdriver2( &in, pol, env, level,
787 version, 2, &buffer, offered);
789 CLI_DO_RPC_WERR( cli, mem_ctx, PI_SPOOLSS, SPOOLSS_GETPRINTERDRIVER2,
790 in, out,
791 qbuf, rbuf,
792 spoolss_io_q_getprinterdriver2,
793 spoolss_io_r_getprinterdriver2,
794 WERR_GENERAL_FAILURE );
796 if ( W_ERROR_EQUAL( out.status, WERR_INSUFFICIENT_BUFFER ) ) {
797 offered = out.needed;
799 ZERO_STRUCT(in);
800 ZERO_STRUCT(out);
802 rpcbuf_init(&buffer, offered, mem_ctx);
803 make_spoolss_q_getprinterdriver2( &in, pol, env, level,
804 version, 2, &buffer, offered);
806 CLI_DO_RPC_WERR( cli, mem_ctx, PI_SPOOLSS, SPOOLSS_GETPRINTERDRIVER2,
807 in, out,
808 qbuf, rbuf,
809 spoolss_io_q_getprinterdriver2,
810 spoolss_io_r_getprinterdriver2,
811 WERR_GENERAL_FAILURE );
814 if ( !W_ERROR_IS_OK(out.status) )
815 return out.status;
817 switch (level) {
818 case 1:
819 if (!decode_printer_driver_1(mem_ctx, out.buffer, 1, &ctr->info1)) {
820 return WERR_GENERAL_FAILURE;
822 break;
823 case 2:
824 if (!decode_printer_driver_2(mem_ctx, out.buffer, 1, &ctr->info2)) {
825 return WERR_GENERAL_FAILURE;
827 break;
828 case 3:
829 if (!decode_printer_driver_3(mem_ctx, out.buffer, 1, &ctr->info3)) {
830 return WERR_GENERAL_FAILURE;
832 break;
833 default:
834 return WERR_UNKNOWN_LEVEL;
837 return out.status;
840 /**********************************************************************
841 **********************************************************************/
843 WERROR rpccli_spoolss_enumprinterdrivers (struct rpc_pipe_client *cli,
844 TALLOC_CTX *mem_ctx,
845 uint32 level, const char *env,
846 uint32 *num_drivers,
847 PRINTER_DRIVER_CTR *ctr)
849 prs_struct qbuf, rbuf;
850 SPOOL_Q_ENUMPRINTERDRIVERS in;
851 SPOOL_R_ENUMPRINTERDRIVERS out;
852 RPC_BUFFER buffer;
853 fstring server;
854 uint32 offered;
856 ZERO_STRUCT(in);
857 ZERO_STRUCT(out);
859 slprintf(server, sizeof(fstring)-1, "\\\\%s", cli->cli->desthost);
860 strupper_m(server);
862 offered = 0;
863 rpcbuf_init(&buffer, offered, mem_ctx);
864 make_spoolss_q_enumprinterdrivers( &in, server, env, level,
865 &buffer, offered);
867 CLI_DO_RPC_WERR( cli, mem_ctx, PI_SPOOLSS, SPOOLSS_ENUMPRINTERDRIVERS,
868 in, out,
869 qbuf, rbuf,
870 spoolss_io_q_enumprinterdrivers,
871 spoolss_io_r_enumprinterdrivers,
872 WERR_GENERAL_FAILURE );
874 if ( W_ERROR_EQUAL( out.status, WERR_INSUFFICIENT_BUFFER ) ) {
875 offered = out.needed;
877 ZERO_STRUCT(in);
878 ZERO_STRUCT(out);
880 rpcbuf_init(&buffer, offered, mem_ctx);
881 make_spoolss_q_enumprinterdrivers( &in, server, env, level,
882 &buffer, offered);
884 CLI_DO_RPC_WERR( cli, mem_ctx, PI_SPOOLSS, SPOOLSS_ENUMPRINTERDRIVERS,
885 in, out,
886 qbuf, rbuf,
887 spoolss_io_q_enumprinterdrivers,
888 spoolss_io_r_enumprinterdrivers,
889 WERR_GENERAL_FAILURE );
892 *num_drivers = out.returned;
894 if ( !W_ERROR_IS_OK(out.status) )
895 return out.status;
897 if ( out.returned ) {
899 switch (level) {
900 case 1:
901 if (!decode_printer_driver_1(mem_ctx, out.buffer, out.returned, &ctr->info1)) {
902 return WERR_GENERAL_FAILURE;
904 break;
905 case 2:
906 if (!decode_printer_driver_2(mem_ctx, out.buffer, out.returned, &ctr->info2)) {
907 return WERR_GENERAL_FAILURE;
909 break;
910 case 3:
911 if (!decode_printer_driver_3(mem_ctx, out.buffer, out.returned, &ctr->info3)) {
912 return WERR_GENERAL_FAILURE;
914 break;
915 default:
916 return WERR_UNKNOWN_LEVEL;
920 return out.status;
924 /**********************************************************************
925 **********************************************************************/
927 WERROR rpccli_spoolss_getprinterdriverdir (struct rpc_pipe_client *cli,
928 TALLOC_CTX *mem_ctx,
929 uint32 level, char *env,
930 DRIVER_DIRECTORY_CTR *ctr)
932 prs_struct qbuf, rbuf;
933 SPOOL_Q_GETPRINTERDRIVERDIR in;
934 SPOOL_R_GETPRINTERDRIVERDIR out;
935 RPC_BUFFER buffer;
936 fstring server;
937 uint32 offered;
939 ZERO_STRUCT(in);
940 ZERO_STRUCT(out);
942 slprintf(server, sizeof(fstring)-1, "\\\\%s", cli->cli->desthost);
943 strupper_m(server);
945 offered = 0;
946 rpcbuf_init(&buffer, offered, mem_ctx);
947 make_spoolss_q_getprinterdriverdir( &in, server, env, level,
948 &buffer, offered );
950 CLI_DO_RPC_WERR( cli, mem_ctx, PI_SPOOLSS, SPOOLSS_GETPRINTERDRIVERDIRECTORY,
951 in, out,
952 qbuf, rbuf,
953 spoolss_io_q_getprinterdriverdir,
954 spoolss_io_r_getprinterdriverdir,
955 WERR_GENERAL_FAILURE );
957 if ( W_ERROR_EQUAL( out.status, WERR_INSUFFICIENT_BUFFER ) ) {
958 offered = out.needed;
960 ZERO_STRUCT(in);
961 ZERO_STRUCT(out);
963 rpcbuf_init(&buffer, offered, mem_ctx);
964 make_spoolss_q_getprinterdriverdir( &in, server, env, level,
965 &buffer, offered );
967 CLI_DO_RPC_WERR( cli, mem_ctx, PI_SPOOLSS, SPOOLSS_GETPRINTERDRIVERDIRECTORY,
968 in, out,
969 qbuf, rbuf,
970 spoolss_io_q_getprinterdriverdir,
971 spoolss_io_r_getprinterdriverdir,
972 WERR_GENERAL_FAILURE );
975 if (!W_ERROR_IS_OK(out.status))
976 return out.status;
978 if (!decode_printerdriverdir_1(mem_ctx, out.buffer, 1, &ctr->info1)) {
979 return WERR_GENERAL_FAILURE;
982 return out.status;
985 /**********************************************************************
986 **********************************************************************/
988 WERROR rpccli_spoolss_addprinterdriver (struct rpc_pipe_client *cli,
989 TALLOC_CTX *mem_ctx, uint32 level,
990 PRINTER_DRIVER_CTR *ctr)
992 prs_struct qbuf, rbuf;
993 SPOOL_Q_ADDPRINTERDRIVER in;
994 SPOOL_R_ADDPRINTERDRIVER out;
995 fstring server;
997 ZERO_STRUCT(in);
998 ZERO_STRUCT(out);
1000 slprintf(server, sizeof(fstring)-1, "\\\\%s", cli->cli->desthost);
1001 strupper_m(server);
1003 make_spoolss_q_addprinterdriver( mem_ctx, &in, server, level, ctr );
1005 CLI_DO_RPC_WERR( cli, mem_ctx, PI_SPOOLSS, SPOOLSS_ADDPRINTERDRIVER,
1006 in, out,
1007 qbuf, rbuf,
1008 spoolss_io_q_addprinterdriver,
1009 spoolss_io_r_addprinterdriver,
1010 WERR_GENERAL_FAILURE );
1012 return out.status;
1015 /**********************************************************************
1016 **********************************************************************/
1018 WERROR rpccli_spoolss_addprinterex (struct rpc_pipe_client *cli, TALLOC_CTX *mem_ctx,
1019 uint32 level, PRINTER_INFO_CTR*ctr)
1021 prs_struct qbuf, rbuf;
1022 SPOOL_Q_ADDPRINTEREX in;
1023 SPOOL_R_ADDPRINTEREX out;
1024 fstring server, client, user;
1026 ZERO_STRUCT(in);
1027 ZERO_STRUCT(out);
1029 slprintf(client, sizeof(fstring)-1, "\\\\%s", global_myname());
1030 slprintf(server, sizeof(fstring)-1, "\\\\%s", cli->cli->desthost);
1032 strupper_m(client);
1033 strupper_m(server);
1035 fstrcpy (user, cli->user_name);
1037 make_spoolss_q_addprinterex( mem_ctx, &in, server, client,
1038 user, level, ctr);
1040 CLI_DO_RPC_WERR( cli, mem_ctx, PI_SPOOLSS, SPOOLSS_ADDPRINTEREX,
1041 in, out,
1042 qbuf, rbuf,
1043 spoolss_io_q_addprinterex,
1044 spoolss_io_r_addprinterex,
1045 WERR_GENERAL_FAILURE );
1047 return out.status;
1050 /**********************************************************************
1051 **********************************************************************/
1053 WERROR rpccli_spoolss_deleteprinterdriverex(struct rpc_pipe_client *cli,
1054 TALLOC_CTX *mem_ctx, const char *arch,
1055 const char *driver, int version)
1057 prs_struct qbuf, rbuf;
1058 SPOOL_Q_DELETEPRINTERDRIVEREX in;
1059 SPOOL_R_DELETEPRINTERDRIVEREX out;
1060 fstring server;
1062 ZERO_STRUCT(in);
1063 ZERO_STRUCT(out);
1065 slprintf(server, sizeof(fstring)-1, "\\\\%s", cli->cli->desthost);
1066 strupper_m(server);
1068 make_spoolss_q_deleteprinterdriverex( mem_ctx, &in, server, arch, driver, version );
1070 CLI_DO_RPC_WERR( cli, mem_ctx, PI_SPOOLSS, SPOOLSS_DELETEPRINTERDRIVEREX,
1071 in, out,
1072 qbuf, rbuf,
1073 spoolss_io_q_deleteprinterdriverex,
1074 spoolss_io_r_deleteprinterdriverex,
1075 WERR_GENERAL_FAILURE );
1077 return out.status;
1080 /**********************************************************************
1081 **********************************************************************/
1083 WERROR rpccli_spoolss_deleteprinterdriver (struct rpc_pipe_client *cli,
1084 TALLOC_CTX *mem_ctx, const char *arch,
1085 const char *driver)
1087 prs_struct qbuf, rbuf;
1088 SPOOL_Q_DELETEPRINTERDRIVER in;
1089 SPOOL_R_DELETEPRINTERDRIVER out;
1090 fstring server;
1092 ZERO_STRUCT(in);
1093 ZERO_STRUCT(out);
1095 slprintf(server, sizeof(fstring)-1, "\\\\%s", cli->cli->desthost);
1096 strupper_m(server);
1098 make_spoolss_q_deleteprinterdriver( mem_ctx, &in, server, arch, driver );
1100 CLI_DO_RPC_WERR( cli, mem_ctx, PI_SPOOLSS, SPOOLSS_DELETEPRINTERDRIVER,
1101 in, out,
1102 qbuf, rbuf,
1103 spoolss_io_q_deleteprinterdriver,
1104 spoolss_io_r_deleteprinterdriver,
1105 WERR_GENERAL_FAILURE );
1107 return out.status;
1110 /**********************************************************************
1111 **********************************************************************/
1113 WERROR rpccli_spoolss_getprintprocessordirectory(struct rpc_pipe_client *cli,
1114 TALLOC_CTX *mem_ctx,
1115 char *name, char *environment,
1116 fstring procdir)
1118 prs_struct qbuf, rbuf;
1119 SPOOL_Q_GETPRINTPROCESSORDIRECTORY in;
1120 SPOOL_R_GETPRINTPROCESSORDIRECTORY out;
1121 int level = 1;
1122 RPC_BUFFER buffer;
1123 uint32 offered;
1125 ZERO_STRUCT(in);
1126 ZERO_STRUCT(out);
1128 offered = 0;
1129 rpcbuf_init(&buffer, offered, mem_ctx);
1130 make_spoolss_q_getprintprocessordirectory( &in, name,
1131 environment, level, &buffer, offered );
1133 CLI_DO_RPC_WERR( cli, mem_ctx, PI_SPOOLSS, SPOOLSS_GETPRINTPROCESSORDIRECTORY,
1134 in, out,
1135 qbuf, rbuf,
1136 spoolss_io_q_getprintprocessordirectory,
1137 spoolss_io_r_getprintprocessordirectory,
1138 WERR_GENERAL_FAILURE );
1140 if ( W_ERROR_EQUAL( out.status, WERR_INSUFFICIENT_BUFFER ) ) {
1141 offered = out.needed;
1143 ZERO_STRUCT(in);
1144 ZERO_STRUCT(out);
1146 rpcbuf_init(&buffer, offered, mem_ctx);
1147 make_spoolss_q_getprintprocessordirectory( &in, name,
1148 environment, level, &buffer, offered );
1150 CLI_DO_RPC_WERR( cli, mem_ctx, PI_SPOOLSS, SPOOLSS_GETPRINTPROCESSORDIRECTORY,
1151 in, out,
1152 qbuf, rbuf,
1153 spoolss_io_q_getprintprocessordirectory,
1154 spoolss_io_r_getprintprocessordirectory,
1155 WERR_GENERAL_FAILURE );
1158 if ( !W_ERROR_IS_OK(out.status) )
1159 return out.status;
1161 fstrcpy(procdir, "Not implemented!");
1163 return out.status;
1166 /**********************************************************************
1167 **********************************************************************/
1169 WERROR rpccli_spoolss_addform(struct rpc_pipe_client *cli, TALLOC_CTX *mem_ctx,
1170 POLICY_HND *handle, uint32 level, FORM *form)
1172 prs_struct qbuf, rbuf;
1173 SPOOL_Q_ADDFORM in;
1174 SPOOL_R_ADDFORM out;
1176 ZERO_STRUCT(in);
1177 ZERO_STRUCT(out);
1179 make_spoolss_q_addform( &in, handle, level, form );
1181 CLI_DO_RPC_WERR( cli, mem_ctx, PI_SPOOLSS, SPOOLSS_ADDFORM,
1182 in, out,
1183 qbuf, rbuf,
1184 spoolss_io_q_addform,
1185 spoolss_io_r_addform,
1186 WERR_GENERAL_FAILURE );
1188 return out.status;
1191 /**********************************************************************
1192 **********************************************************************/
1194 WERROR rpccli_spoolss_setform(struct rpc_pipe_client *cli, TALLOC_CTX *mem_ctx,
1195 POLICY_HND *handle, uint32 level,
1196 const char *form_name, FORM *form)
1198 prs_struct qbuf, rbuf;
1199 SPOOL_Q_SETFORM in;
1200 SPOOL_R_SETFORM out;
1202 ZERO_STRUCT(in);
1203 ZERO_STRUCT(out);
1205 make_spoolss_q_setform( &in, handle, level, form_name, form );
1207 CLI_DO_RPC_WERR( cli, mem_ctx, PI_SPOOLSS, SPOOLSS_SETFORM,
1208 in, out,
1209 qbuf, rbuf,
1210 spoolss_io_q_setform,
1211 spoolss_io_r_setform,
1212 WERR_GENERAL_FAILURE );
1214 return out.status;
1217 /**********************************************************************
1218 **********************************************************************/
1220 WERROR rpccli_spoolss_getform(struct rpc_pipe_client *cli, TALLOC_CTX *mem_ctx,
1221 POLICY_HND *handle, const char *formname,
1222 uint32 level, FORM_1 *form)
1224 prs_struct qbuf, rbuf;
1225 SPOOL_Q_GETFORM in;
1226 SPOOL_R_GETFORM out;
1227 RPC_BUFFER buffer;
1228 uint32 offered;
1230 ZERO_STRUCT(in);
1231 ZERO_STRUCT(out);
1233 offered = 0;
1234 rpcbuf_init(&buffer, offered, mem_ctx);
1235 make_spoolss_q_getform( &in, handle, formname, level, &buffer, offered );
1237 CLI_DO_RPC_WERR( cli, mem_ctx, PI_SPOOLSS, SPOOLSS_GETFORM,
1238 in, out,
1239 qbuf, rbuf,
1240 spoolss_io_q_getform,
1241 spoolss_io_r_getform,
1242 WERR_GENERAL_FAILURE );
1244 if ( W_ERROR_EQUAL( out.status, WERR_INSUFFICIENT_BUFFER ) ) {
1245 offered = out.needed;
1247 ZERO_STRUCT(in);
1248 ZERO_STRUCT(out);
1250 rpcbuf_init(&buffer, offered, mem_ctx);
1251 make_spoolss_q_getform( &in, handle, formname, level, &buffer, offered );
1253 CLI_DO_RPC_WERR( cli, mem_ctx, PI_SPOOLSS, SPOOLSS_GETFORM,
1254 in, out,
1255 qbuf, rbuf,
1256 spoolss_io_q_getform,
1257 spoolss_io_r_getform,
1258 WERR_GENERAL_FAILURE );
1261 if (!W_ERROR_IS_OK(out.status))
1262 return out.status;
1264 if (!smb_io_form_1("", out.buffer, form, 0)) {
1265 return WERR_GENERAL_FAILURE;
1268 return out.status;
1271 /**********************************************************************
1272 **********************************************************************/
1274 WERROR rpccli_spoolss_deleteform(struct rpc_pipe_client *cli, TALLOC_CTX *mem_ctx,
1275 POLICY_HND *handle, const char *form_name)
1277 prs_struct qbuf, rbuf;
1278 SPOOL_Q_DELETEFORM in;
1279 SPOOL_R_DELETEFORM out;
1281 ZERO_STRUCT(in);
1282 ZERO_STRUCT(out);
1284 make_spoolss_q_deleteform( &in, handle, form_name );
1286 CLI_DO_RPC_WERR( cli, mem_ctx, PI_SPOOLSS, SPOOLSS_DELETEFORM,
1287 in, out,
1288 qbuf, rbuf,
1289 spoolss_io_q_deleteform,
1290 spoolss_io_r_deleteform,
1291 WERR_GENERAL_FAILURE );
1293 return out.status;
1296 /**********************************************************************
1297 **********************************************************************/
1299 WERROR rpccli_spoolss_enumforms(struct rpc_pipe_client *cli, TALLOC_CTX *mem_ctx,
1300 POLICY_HND *handle, int level, uint32 *num_forms,
1301 FORM_1 **forms)
1303 prs_struct qbuf, rbuf;
1304 SPOOL_Q_ENUMFORMS in;
1305 SPOOL_R_ENUMFORMS out;
1306 RPC_BUFFER buffer;
1307 uint32 offered;
1309 ZERO_STRUCT(in);
1310 ZERO_STRUCT(out);
1312 offered = 0;
1313 rpcbuf_init(&buffer, offered, mem_ctx);
1314 make_spoolss_q_enumforms( &in, handle, level, &buffer, offered );
1316 CLI_DO_RPC_WERR( cli, mem_ctx, PI_SPOOLSS, SPOOLSS_ENUMFORMS,
1317 in, out,
1318 qbuf, rbuf,
1319 spoolss_io_q_enumforms,
1320 spoolss_io_r_enumforms,
1321 WERR_GENERAL_FAILURE );
1323 if ( W_ERROR_EQUAL( out.status, WERR_INSUFFICIENT_BUFFER ) ) {
1324 offered = out.needed;
1326 ZERO_STRUCT(in);
1327 ZERO_STRUCT(out);
1329 rpcbuf_init(&buffer, offered, mem_ctx);
1330 make_spoolss_q_enumforms( &in, handle, level, &buffer, offered );
1332 CLI_DO_RPC_WERR( cli, mem_ctx, PI_SPOOLSS, SPOOLSS_ENUMFORMS,
1333 in, out,
1334 qbuf, rbuf,
1335 spoolss_io_q_enumforms,
1336 spoolss_io_r_enumforms,
1337 WERR_GENERAL_FAILURE );
1340 if (!W_ERROR_IS_OK(out.status))
1341 return out.status;
1343 *num_forms = out.numofforms;
1345 if (!decode_forms_1(mem_ctx, out.buffer, *num_forms, forms)) {
1346 return WERR_GENERAL_FAILURE;
1349 return out.status;
1352 /**********************************************************************
1353 **********************************************************************/
1355 WERROR rpccli_spoolss_enumjobs(struct rpc_pipe_client *cli, TALLOC_CTX *mem_ctx,
1356 POLICY_HND *hnd, uint32 level, uint32 firstjob,
1357 uint32 num_jobs, uint32 *returned, JOB_INFO_CTR *ctr)
1359 prs_struct qbuf, rbuf;
1360 SPOOL_Q_ENUMJOBS in;
1361 SPOOL_R_ENUMJOBS out;
1362 RPC_BUFFER buffer;
1363 uint32 offered;
1365 ZERO_STRUCT(in);
1366 ZERO_STRUCT(out);
1368 offered = 0;
1369 rpcbuf_init(&buffer, offered, mem_ctx);
1370 make_spoolss_q_enumjobs( &in, hnd, firstjob, num_jobs, level,
1371 &buffer, offered );
1373 CLI_DO_RPC_WERR( cli, mem_ctx, PI_SPOOLSS, SPOOLSS_ENUMJOBS,
1374 in, out,
1375 qbuf, rbuf,
1376 spoolss_io_q_enumjobs,
1377 spoolss_io_r_enumjobs,
1378 WERR_GENERAL_FAILURE );
1380 if ( W_ERROR_EQUAL( out.status, WERR_INSUFFICIENT_BUFFER ) ) {
1381 offered = out.needed;
1383 ZERO_STRUCT(in);
1384 ZERO_STRUCT(out);
1386 rpcbuf_init(&buffer, offered, mem_ctx);
1387 make_spoolss_q_enumjobs( &in, hnd, firstjob, num_jobs, level,
1388 &buffer, offered );
1390 CLI_DO_RPC_WERR( cli, mem_ctx, PI_SPOOLSS, SPOOLSS_ENUMJOBS,
1391 in, out,
1392 qbuf, rbuf,
1393 spoolss_io_q_enumjobs,
1394 spoolss_io_r_enumjobs,
1395 WERR_GENERAL_FAILURE );
1398 if (!W_ERROR_IS_OK(out.status))
1399 return out.status;
1401 switch(level) {
1402 case 1:
1403 if (!decode_jobs_1(mem_ctx, out.buffer, out.returned, &ctr->job.job_info_1)) {
1404 return WERR_GENERAL_FAILURE;
1406 break;
1407 case 2:
1408 if (!decode_jobs_2(mem_ctx, out.buffer, out.returned, &ctr->job.job_info_2)) {
1409 return WERR_GENERAL_FAILURE;
1411 break;
1412 default:
1413 DEBUG(3, ("unsupported info level %d", level));
1414 return WERR_UNKNOWN_LEVEL;
1417 *returned = out.returned;
1419 return out.status;
1422 /**********************************************************************
1423 **********************************************************************/
1425 WERROR rpccli_spoolss_setjob(struct rpc_pipe_client *cli, TALLOC_CTX *mem_ctx,
1426 POLICY_HND *hnd, uint32 jobid, uint32 level,
1427 uint32 command)
1429 prs_struct qbuf, rbuf;
1430 SPOOL_Q_SETJOB in;
1431 SPOOL_R_SETJOB out;
1433 ZERO_STRUCT(in);
1434 ZERO_STRUCT(out);
1436 make_spoolss_q_setjob( &in, hnd, jobid, level, command );
1438 CLI_DO_RPC_WERR( cli, mem_ctx, PI_SPOOLSS, SPOOLSS_SETJOB,
1439 in, out,
1440 qbuf, rbuf,
1441 spoolss_io_q_setjob,
1442 spoolss_io_r_setjob,
1443 WERR_GENERAL_FAILURE );
1445 return out.status;
1448 /**********************************************************************
1449 **********************************************************************/
1451 WERROR rpccli_spoolss_getjob(struct rpc_pipe_client *cli, TALLOC_CTX *mem_ctx,
1452 POLICY_HND *hnd, uint32 jobid, uint32 level,
1453 JOB_INFO_CTR *ctr)
1455 prs_struct qbuf, rbuf;
1456 SPOOL_Q_GETJOB in;
1457 SPOOL_R_GETJOB out;
1458 RPC_BUFFER buffer;
1459 uint32 offered;
1461 ZERO_STRUCT(in);
1462 ZERO_STRUCT(out);
1464 offered = 0;
1465 rpcbuf_init(&buffer, offered, mem_ctx);
1466 make_spoolss_q_getjob( &in, hnd, jobid, level, &buffer, offered );
1468 CLI_DO_RPC_WERR( cli, mem_ctx, PI_SPOOLSS, SPOOLSS_GETJOB,
1469 in, out,
1470 qbuf, rbuf,
1471 spoolss_io_q_getjob,
1472 spoolss_io_r_getjob,
1473 WERR_GENERAL_FAILURE );
1475 if ( W_ERROR_EQUAL( out.status, WERR_MORE_DATA ) ) {
1476 offered = out.needed;
1478 ZERO_STRUCT(in);
1479 ZERO_STRUCT(out);
1481 rpcbuf_init(&buffer, offered, mem_ctx);
1482 make_spoolss_q_getjob( &in, hnd, jobid, level, &buffer, offered );
1484 CLI_DO_RPC_WERR( cli, mem_ctx, PI_SPOOLSS, SPOOLSS_GETJOB,
1485 in, out,
1486 qbuf, rbuf,
1487 spoolss_io_q_getjob,
1488 spoolss_io_r_getjob,
1489 WERR_GENERAL_FAILURE );
1492 if (!W_ERROR_IS_OK(out.status))
1493 return out.status;
1495 switch(level) {
1496 case 1:
1497 if (!decode_jobs_1(mem_ctx, out.buffer, 1, &ctr->job.job_info_1)) {
1498 return WERR_GENERAL_FAILURE;
1500 break;
1501 case 2:
1502 if (!decode_jobs_2(mem_ctx, out.buffer, 1, &ctr->job.job_info_2)) {
1503 return WERR_GENERAL_FAILURE;
1505 break;
1506 default:
1507 return WERR_UNKNOWN_LEVEL;
1510 return out.status;
1513 /**********************************************************************
1514 **********************************************************************/
1516 WERROR rpccli_spoolss_startpageprinter(struct rpc_pipe_client *cli, TALLOC_CTX *mem_ctx,
1517 POLICY_HND *hnd)
1519 prs_struct qbuf, rbuf;
1520 SPOOL_Q_STARTPAGEPRINTER in;
1521 SPOOL_R_STARTPAGEPRINTER out;
1523 ZERO_STRUCT(in);
1524 ZERO_STRUCT(out);
1526 make_spoolss_q_startpageprinter( &in, hnd );
1528 CLI_DO_RPC_WERR( cli, mem_ctx, PI_SPOOLSS, SPOOLSS_STARTPAGEPRINTER,
1529 in, out,
1530 qbuf, rbuf,
1531 spoolss_io_q_startpageprinter,
1532 spoolss_io_r_startpageprinter,
1533 WERR_GENERAL_FAILURE );
1535 return out.status;
1538 /**********************************************************************
1539 **********************************************************************/
1541 WERROR rpccli_spoolss_endpageprinter(struct rpc_pipe_client *cli, TALLOC_CTX *mem_ctx,
1542 POLICY_HND *hnd)
1544 prs_struct qbuf, rbuf;
1545 SPOOL_Q_ENDPAGEPRINTER in;
1546 SPOOL_R_ENDPAGEPRINTER out;
1548 ZERO_STRUCT(in);
1549 ZERO_STRUCT(out);
1551 make_spoolss_q_endpageprinter( &in, hnd );
1553 CLI_DO_RPC_WERR( cli, mem_ctx, PI_SPOOLSS, SPOOLSS_ENDPAGEPRINTER,
1554 in, out,
1555 qbuf, rbuf,
1556 spoolss_io_q_endpageprinter,
1557 spoolss_io_r_endpageprinter,
1558 WERR_GENERAL_FAILURE );
1560 return out.status;
1563 /**********************************************************************
1564 **********************************************************************/
1566 WERROR rpccli_spoolss_startdocprinter(struct rpc_pipe_client *cli, TALLOC_CTX *mem_ctx,
1567 POLICY_HND *hnd, char *docname,
1568 char *outputfile, char *datatype,
1569 uint32 *jobid)
1571 prs_struct qbuf, rbuf;
1572 SPOOL_Q_STARTDOCPRINTER in;
1573 SPOOL_R_STARTDOCPRINTER out;
1574 uint32 level = 1;
1576 ZERO_STRUCT(in);
1577 ZERO_STRUCT(out);
1579 make_spoolss_q_startdocprinter( &in, hnd, level, docname,
1580 outputfile, datatype );
1582 CLI_DO_RPC_WERR( cli, mem_ctx, PI_SPOOLSS, SPOOLSS_STARTDOCPRINTER,
1583 in, out,
1584 qbuf, rbuf,
1585 spoolss_io_q_startdocprinter,
1586 spoolss_io_r_startdocprinter,
1587 WERR_GENERAL_FAILURE );
1589 *jobid = out.jobid;
1591 return out.status;
1594 /**********************************************************************
1595 **********************************************************************/
1597 WERROR rpccli_spoolss_enddocprinter(struct rpc_pipe_client *cli, TALLOC_CTX *mem_ctx,
1598 POLICY_HND *hnd)
1600 prs_struct qbuf, rbuf;
1601 SPOOL_Q_ENDDOCPRINTER in;
1602 SPOOL_R_ENDDOCPRINTER out;
1604 ZERO_STRUCT(in);
1605 ZERO_STRUCT(out);
1607 make_spoolss_q_enddocprinter( &in, hnd );
1609 CLI_DO_RPC_WERR( cli, mem_ctx, PI_SPOOLSS, SPOOLSS_ENDDOCPRINTER,
1610 in, out,
1611 qbuf, rbuf,
1612 spoolss_io_q_enddocprinter,
1613 spoolss_io_r_enddocprinter,
1614 WERR_GENERAL_FAILURE );
1616 return out.status;
1619 /**********************************************************************
1620 **********************************************************************/
1622 WERROR rpccli_spoolss_getprinterdata(struct rpc_pipe_client *cli, TALLOC_CTX *mem_ctx,
1623 POLICY_HND *hnd, const char *valuename,
1624 REGISTRY_VALUE *value)
1626 prs_struct qbuf, rbuf;
1627 SPOOL_Q_GETPRINTERDATA in;
1628 SPOOL_R_GETPRINTERDATA out;
1629 uint32 offered;
1631 ZERO_STRUCT(in);
1632 ZERO_STRUCT(out);
1634 offered = 0;
1635 make_spoolss_q_getprinterdata( &in, hnd, valuename, offered );
1637 CLI_DO_RPC_WERR( cli, mem_ctx, PI_SPOOLSS, SPOOLSS_GETPRINTERDATA,
1638 in, out,
1639 qbuf, rbuf,
1640 spoolss_io_q_getprinterdata,
1641 spoolss_io_r_getprinterdata,
1642 WERR_GENERAL_FAILURE );
1644 if ( W_ERROR_EQUAL( out.status, WERR_MORE_DATA ) ) {
1645 offered = out.needed;
1647 ZERO_STRUCT(in);
1648 ZERO_STRUCT(out);
1650 make_spoolss_q_getprinterdata( &in, hnd, valuename, offered );
1652 CLI_DO_RPC_WERR( cli, mem_ctx, PI_SPOOLSS, SPOOLSS_GETPRINTERDATA,
1653 in, out,
1654 qbuf, rbuf,
1655 spoolss_io_q_getprinterdata,
1656 spoolss_io_r_getprinterdata,
1657 WERR_GENERAL_FAILURE );
1660 if (!W_ERROR_IS_OK(out.status))
1661 return out.status;
1663 /* Return output parameters */
1665 if (out.needed) {
1666 value->data_p = (uint8 *)TALLOC_MEMDUP(mem_ctx, out.data, out.needed);
1667 } else {
1668 value->data_p = NULL;
1670 value->type = out.type;
1671 value->size = out.size;
1673 return out.status;
1676 /**********************************************************************
1677 **********************************************************************/
1679 WERROR rpccli_spoolss_getprinterdataex(struct rpc_pipe_client *cli, TALLOC_CTX *mem_ctx,
1680 POLICY_HND *hnd, const char *keyname,
1681 const char *valuename,
1682 REGISTRY_VALUE *value)
1684 prs_struct qbuf, rbuf;
1685 SPOOL_Q_GETPRINTERDATAEX in;
1686 SPOOL_R_GETPRINTERDATAEX out;
1687 uint32 offered = 0;
1689 ZERO_STRUCT(in);
1690 ZERO_STRUCT(out);
1692 make_spoolss_q_getprinterdataex( &in, hnd, keyname, valuename, offered );
1694 CLI_DO_RPC_WERR( cli, mem_ctx, PI_SPOOLSS, SPOOLSS_GETPRINTERDATAEX,
1695 in, out,
1696 qbuf, rbuf,
1697 spoolss_io_q_getprinterdataex,
1698 spoolss_io_r_getprinterdataex,
1699 WERR_GENERAL_FAILURE );
1701 if ( W_ERROR_EQUAL( out.status, WERR_MORE_DATA ) ) {
1702 offered = out.needed;
1704 ZERO_STRUCT(in);
1705 ZERO_STRUCT(out);
1707 make_spoolss_q_getprinterdataex( &in, hnd, keyname, valuename, offered );
1709 CLI_DO_RPC_WERR( cli, mem_ctx, PI_SPOOLSS, SPOOLSS_GETPRINTERDATAEX,
1710 in, out,
1711 qbuf, rbuf,
1712 spoolss_io_q_getprinterdataex,
1713 spoolss_io_r_getprinterdataex,
1714 WERR_GENERAL_FAILURE );
1717 if (!W_ERROR_IS_OK(out.status))
1718 return out.status;
1720 /* Return output parameters */
1722 if (out.needed) {
1723 value->data_p = (uint8 *)TALLOC_MEMDUP(mem_ctx, out.data, out.needed);
1724 } else {
1725 value->data_p = NULL;
1727 value->type = out.type;
1728 value->size = out.needed;
1730 return out.status;
1733 /**********************************************************************
1734 **********************************************************************/
1736 WERROR rpccli_spoolss_setprinterdata(struct rpc_pipe_client *cli, TALLOC_CTX *mem_ctx,
1737 POLICY_HND *hnd, REGISTRY_VALUE *value)
1739 prs_struct qbuf, rbuf;
1740 SPOOL_Q_SETPRINTERDATA in;
1741 SPOOL_R_SETPRINTERDATA out;
1743 ZERO_STRUCT(in);
1744 ZERO_STRUCT(out);
1746 make_spoolss_q_setprinterdata( &in, hnd, value->valuename,
1747 value->type, (char *)value->data_p, value->size);
1749 CLI_DO_RPC_WERR( cli, mem_ctx, PI_SPOOLSS, SPOOLSS_SETPRINTERDATA,
1750 in, out,
1751 qbuf, rbuf,
1752 spoolss_io_q_setprinterdata,
1753 spoolss_io_r_setprinterdata,
1754 WERR_GENERAL_FAILURE );
1756 return out.status;
1759 /**********************************************************************
1760 **********************************************************************/
1762 WERROR rpccli_spoolss_setprinterdataex(struct rpc_pipe_client *cli, TALLOC_CTX *mem_ctx,
1763 POLICY_HND *hnd, char *keyname,
1764 REGISTRY_VALUE *value)
1766 prs_struct qbuf, rbuf;
1767 SPOOL_Q_SETPRINTERDATAEX in;
1768 SPOOL_R_SETPRINTERDATAEX out;
1770 ZERO_STRUCT(in);
1771 ZERO_STRUCT(out);
1773 make_spoolss_q_setprinterdataex( &in, hnd, keyname, value->valuename,
1774 value->type, (char *)value->data_p, value->size);
1776 CLI_DO_RPC_WERR( cli, mem_ctx, PI_SPOOLSS, SPOOLSS_SETPRINTERDATAEX,
1777 in, out,
1778 qbuf, rbuf,
1779 spoolss_io_q_setprinterdataex,
1780 spoolss_io_r_setprinterdataex,
1781 WERR_GENERAL_FAILURE );
1783 return out.status;
1786 /**********************************************************************
1787 **********************************************************************/
1789 WERROR rpccli_spoolss_enumprinterdata(struct rpc_pipe_client *cli, TALLOC_CTX *mem_ctx,
1790 POLICY_HND *hnd, uint32 ndx,
1791 uint32 value_offered, uint32 data_offered,
1792 uint32 *value_needed, uint32 *data_needed,
1793 REGISTRY_VALUE *value)
1795 prs_struct qbuf, rbuf;
1796 SPOOL_Q_ENUMPRINTERDATA in;
1797 SPOOL_R_ENUMPRINTERDATA out;
1799 ZERO_STRUCT(in);
1800 ZERO_STRUCT(out);
1802 make_spoolss_q_enumprinterdata( &in, hnd, ndx, value_offered, data_offered );
1804 CLI_DO_RPC_WERR( cli, mem_ctx, PI_SPOOLSS, SPOOLSS_ENUMPRINTERDATA,
1805 in, out,
1806 qbuf, rbuf,
1807 spoolss_io_q_enumprinterdata,
1808 spoolss_io_r_enumprinterdata,
1809 WERR_GENERAL_FAILURE );
1811 if ( value_needed )
1812 *value_needed = out.realvaluesize;
1813 if ( data_needed )
1814 *data_needed = out.realdatasize;
1816 if (!W_ERROR_IS_OK(out.status))
1817 return out.status;
1819 if (value) {
1820 rpcstr_pull(value->valuename, out.value, sizeof(value->valuename), -1,
1821 STR_TERMINATE);
1822 if (out.realdatasize) {
1823 value->data_p = (uint8 *)TALLOC_MEMDUP(mem_ctx, out.data,
1824 out.realdatasize);
1825 } else {
1826 value->data_p = NULL;
1828 value->type = out.type;
1829 value->size = out.realdatasize;
1832 return out.status;
1835 /**********************************************************************
1836 **********************************************************************/
1838 WERROR rpccli_spoolss_enumprinterdataex(struct rpc_pipe_client *cli, TALLOC_CTX *mem_ctx,
1839 POLICY_HND *hnd, const char *keyname,
1840 REGVAL_CTR *ctr)
1842 prs_struct qbuf, rbuf;
1843 SPOOL_Q_ENUMPRINTERDATAEX in;
1844 SPOOL_R_ENUMPRINTERDATAEX out;
1845 int i;
1846 uint32 offered;
1848 ZERO_STRUCT(in);
1849 ZERO_STRUCT(out);
1851 offered = 0;
1852 make_spoolss_q_enumprinterdataex( &in, hnd, keyname, offered );
1854 CLI_DO_RPC_WERR( cli, mem_ctx, PI_SPOOLSS, SPOOLSS_ENUMPRINTERDATAEX,
1855 in, out,
1856 qbuf, rbuf,
1857 spoolss_io_q_enumprinterdataex,
1858 spoolss_io_r_enumprinterdataex,
1859 WERR_GENERAL_FAILURE );
1861 if ( W_ERROR_EQUAL( out.status, WERR_MORE_DATA ) ) {
1862 offered = out.needed;
1864 ZERO_STRUCT(in);
1865 ZERO_STRUCT(out);
1867 make_spoolss_q_enumprinterdataex( &in, hnd, keyname, offered );
1869 CLI_DO_RPC_WERR( cli, mem_ctx, PI_SPOOLSS, SPOOLSS_ENUMPRINTERDATAEX,
1870 in, out,
1871 qbuf, rbuf,
1872 spoolss_io_q_enumprinterdataex,
1873 spoolss_io_r_enumprinterdataex,
1874 WERR_GENERAL_FAILURE );
1877 if (!W_ERROR_IS_OK(out.status))
1878 return out.status;
1880 for (i = 0; i < out.returned; i++) {
1881 PRINTER_ENUM_VALUES *v = &out.ctr.values[i];
1882 fstring name;
1884 rpcstr_pull(name, v->valuename.buffer, sizeof(name), -1,
1885 STR_TERMINATE);
1886 regval_ctr_addvalue(ctr, name, v->type, (const char *)v->data, v->data_len);
1889 return out.status;
1892 /**********************************************************************
1893 **********************************************************************/
1895 WERROR rpccli_spoolss_writeprinter(struct rpc_pipe_client *cli, TALLOC_CTX *mem_ctx,
1896 POLICY_HND *hnd, uint32 data_size, char *data,
1897 uint32 *num_written)
1899 prs_struct qbuf, rbuf;
1900 SPOOL_Q_WRITEPRINTER in;
1901 SPOOL_R_WRITEPRINTER out;
1903 ZERO_STRUCT(in);
1904 ZERO_STRUCT(out);
1906 make_spoolss_q_writeprinter( &in, hnd, data_size, data );
1908 CLI_DO_RPC_WERR( cli, mem_ctx, PI_SPOOLSS, SPOOLSS_WRITEPRINTER,
1909 in, out,
1910 qbuf, rbuf,
1911 spoolss_io_q_writeprinter,
1912 spoolss_io_r_writeprinter,
1913 WERR_GENERAL_FAILURE );
1915 if (num_written)
1916 *num_written = out.buffer_written;
1918 return out.status;
1921 /**********************************************************************
1922 **********************************************************************/
1924 WERROR rpccli_spoolss_deleteprinterdata(struct rpc_pipe_client *cli, TALLOC_CTX *mem_ctx,
1925 POLICY_HND *hnd, char *valuename)
1927 prs_struct qbuf, rbuf;
1928 SPOOL_Q_DELETEPRINTERDATA in;
1929 SPOOL_R_DELETEPRINTERDATA out;
1931 ZERO_STRUCT(in);
1932 ZERO_STRUCT(out);
1934 make_spoolss_q_deleteprinterdata( &in, hnd, valuename );
1936 CLI_DO_RPC_WERR( cli, mem_ctx, PI_SPOOLSS, SPOOLSS_DELETEPRINTERDATA,
1937 in, out,
1938 qbuf, rbuf,
1939 spoolss_io_q_deleteprinterdata,
1940 spoolss_io_r_deleteprinterdata,
1941 WERR_GENERAL_FAILURE );
1943 return out.status;
1946 /**********************************************************************
1947 **********************************************************************/
1949 WERROR rpccli_spoolss_deleteprinterdataex(struct rpc_pipe_client *cli, TALLOC_CTX *mem_ctx,
1950 POLICY_HND *hnd, char *keyname,
1951 char *valuename)
1953 prs_struct qbuf, rbuf;
1954 SPOOL_Q_DELETEPRINTERDATAEX in;
1955 SPOOL_R_DELETEPRINTERDATAEX out;
1957 ZERO_STRUCT(in);
1958 ZERO_STRUCT(out);
1960 make_spoolss_q_deleteprinterdataex( &in, hnd, keyname, valuename );
1962 CLI_DO_RPC_WERR( cli, mem_ctx, PI_SPOOLSS, SPOOLSS_DELETEPRINTERDATAEX,
1963 in, out,
1964 qbuf, rbuf,
1965 spoolss_io_q_deleteprinterdataex,
1966 spoolss_io_r_deleteprinterdataex,
1967 WERR_GENERAL_FAILURE );
1969 return out.status;
1972 /**********************************************************************
1973 **********************************************************************/
1975 WERROR rpccli_spoolss_enumprinterkey(struct rpc_pipe_client *cli, TALLOC_CTX *mem_ctx,
1976 POLICY_HND *hnd, const char *keyname,
1977 uint16 **keylist, uint32 *len)
1979 prs_struct qbuf, rbuf;
1980 SPOOL_Q_ENUMPRINTERKEY in;
1981 SPOOL_R_ENUMPRINTERKEY out;
1982 uint32 offered = 0;
1984 ZERO_STRUCT(in);
1985 ZERO_STRUCT(out);
1987 make_spoolss_q_enumprinterkey( &in, hnd, keyname, offered );
1989 CLI_DO_RPC_WERR( cli, mem_ctx, PI_SPOOLSS, SPOOLSS_ENUMPRINTERKEY,
1990 in, out,
1991 qbuf, rbuf,
1992 spoolss_io_q_enumprinterkey,
1993 spoolss_io_r_enumprinterkey,
1994 WERR_GENERAL_FAILURE );
1996 if ( W_ERROR_EQUAL( out.status, WERR_MORE_DATA ) ) {
1997 offered = out.needed;
1999 ZERO_STRUCT(in);
2000 ZERO_STRUCT(out);
2002 make_spoolss_q_enumprinterkey( &in, hnd, keyname, offered );
2004 CLI_DO_RPC_WERR( cli, mem_ctx, PI_SPOOLSS, SPOOLSS_ENUMPRINTERKEY,
2005 in, out,
2006 qbuf, rbuf,
2007 spoolss_io_q_enumprinterkey,
2008 spoolss_io_r_enumprinterkey,
2009 WERR_GENERAL_FAILURE );
2012 if ( !W_ERROR_IS_OK(out.status) )
2013 return out.status;
2015 if (keylist) {
2016 *keylist = SMB_MALLOC_ARRAY(uint16, out.keys.buf_len);
2017 if (!*keylist) {
2018 return WERR_NOMEM;
2020 memcpy(*keylist, out.keys.buffer, out.keys.buf_len * 2);
2021 if (len)
2022 *len = out.keys.buf_len * 2;
2025 return out.status;
2028 /**********************************************************************
2029 **********************************************************************/
2031 WERROR rpccli_spoolss_deleteprinterkey(struct rpc_pipe_client *cli, TALLOC_CTX *mem_ctx,
2032 POLICY_HND *hnd, char *keyname)
2034 prs_struct qbuf, rbuf;
2035 SPOOL_Q_DELETEPRINTERKEY in;
2036 SPOOL_R_DELETEPRINTERKEY out;
2038 ZERO_STRUCT(in);
2039 ZERO_STRUCT(out);
2041 make_spoolss_q_deleteprinterkey( &in, hnd, keyname );
2043 CLI_DO_RPC_WERR( cli, mem_ctx, PI_SPOOLSS, SPOOLSS_DELETEPRINTERKEY,
2044 in, out,
2045 qbuf, rbuf,
2046 spoolss_io_q_deleteprinterkey,
2047 spoolss_io_r_deleteprinterkey,
2048 WERR_GENERAL_FAILURE );
2050 return out.status;
2053 /** @} **/