0590c7a248715eb8d9e35a9dc62de5c4a7b14a02
[tprouty/samba.git] / source3 / rpc_client / cli_spoolss.c
1 /*
2    Unix SMB/CIFS implementation.
3    RPC pipe client
4
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.
10
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 3 of the License, or
14    (at your option) any later version.
15
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.
20
21    You should have received a copy of the GNU General Public License
22    along with this program.  If not, see <http://www.gnu.org/licenses/>.
23 */
24
25 #include "includes.h"
26 #include "rpc_client.h"
27
28 /*********************************************************************
29  Decode various spoolss rpc's and info levels
30  ********************************************************************/
31
32 /**********************************************************************
33 **********************************************************************/
34
35 static bool decode_printer_info_0(TALLOC_CTX *mem_ctx, RPC_BUFFER *buffer,
36                                 uint32 returned, PRINTER_INFO_0 **info)
37 {
38         uint32 i;
39         PRINTER_INFO_0  *inf;
40
41         if (returned) {
42                 inf=TALLOC_ARRAY(mem_ctx, PRINTER_INFO_0, returned);
43                 if (!inf) {
44                         return False;
45                 }
46                 memset(inf, 0, returned*sizeof(PRINTER_INFO_0));
47         } else {
48                 inf = NULL;
49         }
50
51         prs_set_offset(&buffer->prs,0);
52
53         for (i=0; i<returned; i++) {
54                 if (!smb_io_printer_info_0("", buffer, &inf[i], 0)) {
55                         return False;
56                 }
57         }
58
59         *info=inf;
60         return True;
61 }
62
63 /**********************************************************************
64 **********************************************************************/
65
66 static bool decode_printer_info_1(TALLOC_CTX *mem_ctx, RPC_BUFFER *buffer,
67                                 uint32 returned, PRINTER_INFO_1 **info)
68 {
69         uint32 i;
70         PRINTER_INFO_1  *inf;
71
72         if (returned) {
73                 inf=TALLOC_ARRAY(mem_ctx, PRINTER_INFO_1, returned);
74                 if (!inf) {
75                         return False;
76                 }
77                 memset(inf, 0, returned*sizeof(PRINTER_INFO_1));
78         } else {
79                 inf = NULL;
80         }
81
82         prs_set_offset(&buffer->prs,0);
83
84         for (i=0; i<returned; i++) {
85                 if (!smb_io_printer_info_1("", buffer, &inf[i], 0)) {
86                         return False;
87                 }
88         }
89
90         *info=inf;
91         return True;
92 }
93
94 /**********************************************************************
95 **********************************************************************/
96
97 static bool decode_printer_info_2(TALLOC_CTX *mem_ctx, RPC_BUFFER *buffer, 
98                                 uint32 returned, PRINTER_INFO_2 **info)
99 {
100         uint32 i;
101         PRINTER_INFO_2  *inf;
102
103         if (returned) {
104                 inf=TALLOC_ARRAY(mem_ctx, PRINTER_INFO_2, returned);
105                 if (!inf) {
106                         return False;
107                 }
108                 memset(inf, 0, returned*sizeof(PRINTER_INFO_2));
109         } else {
110                 inf = NULL;
111         }
112
113         prs_set_offset(&buffer->prs,0);
114
115         for (i=0; i<returned; i++) {
116                 /* a little initialization as we go */
117                 inf[i].secdesc = NULL;
118                 if (!smb_io_printer_info_2("", buffer, &inf[i], 0)) {
119                         return False;
120                 }
121         }
122
123         *info=inf;
124         return True;
125 }
126
127 /**********************************************************************
128 **********************************************************************/
129
130 static bool decode_printer_info_3(TALLOC_CTX *mem_ctx, RPC_BUFFER *buffer, 
131                                 uint32 returned, PRINTER_INFO_3 **info)
132 {
133         uint32 i;
134         PRINTER_INFO_3  *inf;
135
136         if (returned) {
137                 inf=TALLOC_ARRAY(mem_ctx, PRINTER_INFO_3, returned);
138                 if (!inf) {
139                         return False;
140                 }
141                 memset(inf, 0, returned*sizeof(PRINTER_INFO_3));
142         } else {
143                 inf = NULL;
144         }
145
146         prs_set_offset(&buffer->prs,0);
147
148         for (i=0; i<returned; i++) {
149                 inf[i].secdesc = NULL;
150                 if (!smb_io_printer_info_3("", buffer, &inf[i], 0)) {
151                         return False;
152                 }
153         }
154
155         *info=inf;
156         return True;
157 }
158
159 /**********************************************************************
160 **********************************************************************/
161
162 static bool decode_printer_info_7(TALLOC_CTX *mem_ctx, RPC_BUFFER *buffer,
163                                 uint32 returned, PRINTER_INFO_7 **info)
164 {
165         uint32 i;
166         PRINTER_INFO_7  *inf;
167
168         if (returned) {
169                 inf=TALLOC_ARRAY(mem_ctx, PRINTER_INFO_7, returned);
170                 if (!inf) {
171                         return False;
172                 }
173                 memset(inf, 0, returned*sizeof(PRINTER_INFO_7));
174         } else {
175                 inf = NULL;
176         }
177
178         prs_set_offset(&buffer->prs,0);
179
180         for (i=0; i<returned; i++) {
181                 if (!smb_io_printer_info_7("", buffer, &inf[i], 0)) {
182                         return False;
183                 }
184         }
185
186         *info=inf;
187         return True;
188 }
189
190
191 /**********************************************************************
192 **********************************************************************/
193
194 static bool decode_port_info_1(TALLOC_CTX *mem_ctx, RPC_BUFFER *buffer, 
195                         uint32 returned, PORT_INFO_1 **info)
196 {
197         uint32 i;
198         PORT_INFO_1 *inf;
199
200         if (returned) {
201                 inf=TALLOC_ARRAY(mem_ctx, PORT_INFO_1, returned);
202                 if (!inf) {
203                         return False;
204                 }
205                 memset(inf, 0, returned*sizeof(PORT_INFO_1));
206         } else {
207                 inf = NULL;
208         }
209
210         prs_set_offset(&buffer->prs, 0);
211
212         for (i=0; i<returned; i++) {
213                 if (!smb_io_port_info_1("", buffer, &(inf[i]), 0)) {
214                         return False;
215                 }
216         }
217
218         *info=inf;
219         return True;
220 }
221
222 /**********************************************************************
223 **********************************************************************/
224
225 static bool decode_port_info_2(TALLOC_CTX *mem_ctx, RPC_BUFFER *buffer, 
226                         uint32 returned, PORT_INFO_2 **info)
227 {
228         uint32 i;
229         PORT_INFO_2 *inf;
230
231         if (returned) {
232                 inf=TALLOC_ARRAY(mem_ctx, PORT_INFO_2, returned);
233                 if (!inf) {
234                         return False;
235                 }
236                 memset(inf, 0, returned*sizeof(PORT_INFO_2));
237         } else {
238                 inf = NULL;
239         }
240
241         prs_set_offset(&buffer->prs, 0);
242
243         for (i=0; i<returned; i++) {
244                 if (!smb_io_port_info_2("", buffer, &(inf[i]), 0)) {
245                         return False;
246                 }
247         }
248
249         *info=inf;
250         return True;
251 }
252
253 /**********************************************************************
254 **********************************************************************/
255
256 static bool decode_printer_driver_1(TALLOC_CTX *mem_ctx, RPC_BUFFER *buffer, 
257                         uint32 returned, DRIVER_INFO_1 **info)
258 {
259         uint32 i;
260         DRIVER_INFO_1 *inf;
261
262         if (returned) {
263                 inf=TALLOC_ARRAY(mem_ctx, DRIVER_INFO_1, returned);
264                 if (!inf) {
265                         return False;
266                 }
267                 memset(inf, 0, returned*sizeof(DRIVER_INFO_1));
268         } else {
269                 inf = NULL;
270         }
271
272         prs_set_offset(&buffer->prs,0);
273
274         for (i=0; i<returned; i++) {
275                 if (!smb_io_printer_driver_info_1("", buffer, &(inf[i]), 0)) {
276                         return False;
277                 }
278         }
279
280         *info=inf;
281         return True;
282 }
283
284 /**********************************************************************
285 **********************************************************************/
286
287 static bool decode_printer_driver_2(TALLOC_CTX *mem_ctx, RPC_BUFFER *buffer, 
288                         uint32 returned, DRIVER_INFO_2 **info)
289 {
290         uint32 i;
291         DRIVER_INFO_2 *inf;
292
293         if (returned) {
294                 inf=TALLOC_ARRAY(mem_ctx, DRIVER_INFO_2, returned);
295                 if (!inf) {
296                         return False;
297                 }
298                 memset(inf, 0, returned*sizeof(DRIVER_INFO_2));
299         } else {
300                 inf = NULL;
301         }
302
303         prs_set_offset(&buffer->prs,0);
304
305         for (i=0; i<returned; i++) {
306                 if (!smb_io_printer_driver_info_2("", buffer, &(inf[i]), 0)) {
307                         return False;
308                 }
309         }
310
311         *info=inf;
312         return True;
313 }
314
315 /**********************************************************************
316 **********************************************************************/
317
318 static bool decode_printer_driver_3(TALLOC_CTX *mem_ctx, RPC_BUFFER *buffer, 
319                         uint32 returned, DRIVER_INFO_3 **info)
320 {
321         uint32 i;
322         DRIVER_INFO_3 *inf;
323
324         if (returned) {
325                 inf=TALLOC_ARRAY(mem_ctx, DRIVER_INFO_3, returned);
326                 if (!inf) {
327                         return False;
328                 }
329                 memset(inf, 0, returned*sizeof(DRIVER_INFO_3));
330         } else {
331                 inf = NULL;
332         }
333
334         prs_set_offset(&buffer->prs,0);
335
336         for (i=0; i<returned; i++) {
337                 if (!smb_io_printer_driver_info_3("", buffer, &(inf[i]), 0)) {
338                         return False;
339                 }
340         }
341
342         *info=inf;
343         return True;
344 }
345
346 /**********************************************************************
347 **********************************************************************/
348
349 static bool decode_printerdriverdir_1 (TALLOC_CTX *mem_ctx, RPC_BUFFER *buffer,
350                         uint32 returned, DRIVER_DIRECTORY_1 **info
351 )
352 {
353         DRIVER_DIRECTORY_1 *inf;
354  
355         inf=TALLOC_P(mem_ctx, DRIVER_DIRECTORY_1);
356         if (!inf) {
357                 return False;
358         }
359         memset(inf, 0, sizeof(DRIVER_DIRECTORY_1));
360
361         prs_set_offset(&buffer->prs, 0);
362
363         if (!smb_io_driverdir_1("", buffer, inf, 0)) {
364                 return False;
365         }
366  
367         *info=inf;
368         return True;
369 }
370
371 /**********************************************************************
372 **********************************************************************/
373
374 static bool decode_jobs_1(TALLOC_CTX *mem_ctx, RPC_BUFFER *buffer, 
375                           uint32 num_jobs, JOB_INFO_1 **jobs)
376 {
377         uint32 i;
378
379         if (num_jobs) {
380                 *jobs = TALLOC_ARRAY(mem_ctx, JOB_INFO_1, num_jobs);
381                 if (*jobs == NULL) {
382                         return False;
383                 }
384         } else {
385                 *jobs = NULL;
386         }
387         prs_set_offset(&buffer->prs,0);
388
389         for (i = 0; i < num_jobs; i++) {
390                 if (!smb_io_job_info_1("", buffer, &((*jobs)[i]), 0)) {
391                         return False;
392                 }
393         }
394
395         return True;
396 }
397
398 /**********************************************************************
399 **********************************************************************/
400
401 static bool decode_jobs_2(TALLOC_CTX *mem_ctx, RPC_BUFFER *buffer, 
402                           uint32 num_jobs, JOB_INFO_2 **jobs)
403 {
404         uint32 i;
405
406         if (num_jobs) {
407                 *jobs = TALLOC_ARRAY(mem_ctx, JOB_INFO_2, num_jobs);
408                 if (*jobs == NULL) {
409                         return False;
410                 }
411         } else {
412                 *jobs = NULL;
413         }
414         prs_set_offset(&buffer->prs,0);
415
416         for (i = 0; i < num_jobs; i++) {
417                 if (!smb_io_job_info_2("", buffer, &((*jobs)[i]), 0)) {
418                         return False;
419                 }
420         }
421
422         return True;
423 }
424
425 /**********************************************************************
426 **********************************************************************/
427
428 static bool decode_forms_1(TALLOC_CTX *mem_ctx, RPC_BUFFER *buffer, 
429                            uint32 num_forms, FORM_1 **forms)
430 {
431         int i;
432
433         if (num_forms) {
434                 *forms = TALLOC_ARRAY(mem_ctx, FORM_1, num_forms);
435                 if (*forms == NULL) {
436                         return False;
437                 }
438         } else {
439                 *forms = NULL;
440         }
441
442         prs_set_offset(&buffer->prs,0);
443
444         for (i = 0; i < num_forms; i++) {
445                 if (!smb_io_form_1("", buffer, &((*forms)[i]), 0)) {
446                         return False;
447                 }
448         }
449
450         return True;
451 }
452
453 /**********************************************************************
454 **********************************************************************/
455
456 WERROR rpccli_spoolss_open_printer_ex(struct rpc_pipe_client *cli, TALLOC_CTX *mem_ctx,
457                                 const char *printername, const char *datatype, uint32 access_required,
458                                 const char *station, const char *username, POLICY_HND *pol)
459 {
460         prs_struct qbuf, rbuf;
461         SPOOL_Q_OPEN_PRINTER_EX in;
462         SPOOL_R_OPEN_PRINTER_EX out;
463
464         ZERO_STRUCT(in);
465         ZERO_STRUCT(out);
466
467         make_spoolss_q_open_printer_ex( &in, printername, datatype,
468                 access_required, station, username );
469
470         CLI_DO_RPC_WERR( cli, mem_ctx, &syntax_spoolss, SPOOLSS_OPENPRINTEREX,
471                     in, out, 
472                     qbuf, rbuf,
473                     spoolss_io_q_open_printer_ex,
474                     spoolss_io_r_open_printer_ex, 
475                     WERR_GENERAL_FAILURE );
476
477         memcpy( pol, &out.handle, sizeof(POLICY_HND) );
478         
479         return out.status;
480 }
481
482 /**********************************************************************
483 **********************************************************************/
484
485 WERROR rpccli_spoolss_enum_printers(struct rpc_pipe_client *cli, TALLOC_CTX *mem_ctx,
486                                  char *name, uint32 flags, uint32 level,
487                                  uint32 *num_printers, PRINTER_INFO_CTR *ctr)
488 {
489         prs_struct qbuf, rbuf;
490         SPOOL_Q_ENUMPRINTERS in;
491         SPOOL_R_ENUMPRINTERS out;
492         RPC_BUFFER buffer;
493         uint32 offered;
494
495         ZERO_STRUCT(in);
496         ZERO_STRUCT(out);
497
498         offered = 0;
499         if (!rpcbuf_init(&buffer, offered, mem_ctx))
500                 return WERR_NOMEM;
501         make_spoolss_q_enumprinters( &in, flags, name, level, &buffer, offered );
502
503         CLI_DO_RPC_WERR( cli, mem_ctx, &syntax_spoolss, SPOOLSS_ENUMPRINTERS,
504                     in, out, 
505                     qbuf, rbuf,
506                     spoolss_io_q_enumprinters,
507                     spoolss_io_r_enumprinters, 
508                     WERR_GENERAL_FAILURE );
509                     
510         if ( W_ERROR_EQUAL( out.status, WERR_INSUFFICIENT_BUFFER ) ) {
511                 offered = out.needed;
512                 
513                 ZERO_STRUCT(in);
514                 ZERO_STRUCT(out);
515
516                 if (!rpcbuf_init(&buffer, offered, mem_ctx))
517                         return WERR_NOMEM;
518                 make_spoolss_q_enumprinters( &in, flags, name, level, &buffer, offered );
519
520                 CLI_DO_RPC_WERR( cli, mem_ctx, &syntax_spoolss, SPOOLSS_ENUMPRINTERS,
521                             in, out, 
522                             qbuf, rbuf,
523                             spoolss_io_q_enumprinters,
524                             spoolss_io_r_enumprinters, 
525                             WERR_GENERAL_FAILURE );
526         }
527
528         if ( !W_ERROR_IS_OK(out.status) )
529                 return out.status;
530
531         switch (level) {
532         case 0:
533                 if (!decode_printer_info_0(mem_ctx, out.buffer, out.returned, &ctr->printers_0)) {
534                         return WERR_GENERAL_FAILURE;
535                 }
536                 break;
537         case 1:
538                 if (!decode_printer_info_1(mem_ctx, out.buffer, out.returned, &ctr->printers_1)) {
539                         return WERR_GENERAL_FAILURE;
540                 }
541                 break;
542         case 2:
543                 if (!decode_printer_info_2(mem_ctx, out.buffer, out.returned, &ctr->printers_2)) {
544                         return WERR_GENERAL_FAILURE;
545                 }
546                 break;
547         case 3:
548                 if (!decode_printer_info_3(mem_ctx, out.buffer, out.returned, &ctr->printers_3)) {
549                         return WERR_GENERAL_FAILURE;
550                 }
551                 break;
552         default:
553                 return WERR_UNKNOWN_LEVEL;
554         }                       
555
556         *num_printers = out.returned;
557
558         return out.status;
559 }
560
561 /**********************************************************************
562 **********************************************************************/
563
564 WERROR rpccli_spoolss_enum_ports(struct rpc_pipe_client *cli, TALLOC_CTX *mem_ctx,
565                               uint32 level, uint32 *num_ports, PORT_INFO_CTR *ctr)
566 {
567         prs_struct qbuf, rbuf;
568         SPOOL_Q_ENUMPORTS in;
569         SPOOL_R_ENUMPORTS out;
570         RPC_BUFFER buffer;
571         fstring server;
572         uint32 offered;
573
574         ZERO_STRUCT(in);
575         ZERO_STRUCT(out);
576
577         slprintf(server, sizeof(fstring)-1, "\\\\%s", cli->desthost);
578         strupper_m(server);
579
580         offered = 0;
581         if (!rpcbuf_init(&buffer, offered, mem_ctx))
582                 return WERR_NOMEM;
583         make_spoolss_q_enumports( &in, server, level, &buffer, offered );
584         
585         CLI_DO_RPC_WERR( cli, mem_ctx, &syntax_spoolss, SPOOLSS_ENUMPORTS,
586                     in, out, 
587                     qbuf, rbuf,
588                     spoolss_io_q_enumports,
589                     spoolss_io_r_enumports, 
590                     WERR_GENERAL_FAILURE );
591                         
592         if ( W_ERROR_EQUAL( out.status, WERR_INSUFFICIENT_BUFFER ) ) {
593                 offered = out.needed;
594                 
595                 ZERO_STRUCT(in);
596                 ZERO_STRUCT(out);
597                 
598                 if (!rpcbuf_init(&buffer, offered, mem_ctx))
599                         return WERR_NOMEM;
600                 make_spoolss_q_enumports( &in, server, level, &buffer, offered );
601
602                 CLI_DO_RPC_WERR( cli, mem_ctx, &syntax_spoolss, SPOOLSS_ENUMPORTS,
603                             in, out, 
604                             qbuf, rbuf,
605                             spoolss_io_q_enumports,
606                             spoolss_io_r_enumports, 
607                             WERR_GENERAL_FAILURE );
608         }
609         
610         if ( !W_ERROR_IS_OK(out.status) )
611                 return out.status;
612         
613         switch (level) {
614         case 1:
615                 if (!decode_port_info_1(mem_ctx, out.buffer, out.returned, &ctr->port.info_1)) {
616                         return WERR_GENERAL_FAILURE;
617                 }
618                 break;
619         case 2:
620                 if (!decode_port_info_2(mem_ctx, out.buffer, out.returned, &ctr->port.info_2)) {
621                         return WERR_GENERAL_FAILURE;
622                 }
623                 break;
624         default:
625                 return WERR_UNKNOWN_LEVEL;
626         }
627
628         *num_ports = out.returned;
629
630         return out.status;
631 }
632
633 /**********************************************************************
634 **********************************************************************/
635
636 WERROR rpccli_spoolss_getprinter(struct rpc_pipe_client *cli, TALLOC_CTX *mem_ctx,
637                               POLICY_HND *pol, uint32 level, 
638                               PRINTER_INFO_CTR *ctr)
639 {
640         prs_struct qbuf, rbuf;
641         SPOOL_Q_GETPRINTER in;
642         SPOOL_R_GETPRINTER out;
643         RPC_BUFFER buffer;
644         uint32 offered;
645
646         ZERO_STRUCT(in);
647         ZERO_STRUCT(out);
648
649         /* Initialise input parameters */
650
651         offered = 0;
652         if (!rpcbuf_init(&buffer, offered, mem_ctx))
653                 return WERR_NOMEM;
654         make_spoolss_q_getprinter( mem_ctx, &in, pol, level, &buffer, offered );
655         
656         CLI_DO_RPC_WERR( cli, mem_ctx, &syntax_spoolss, SPOOLSS_GETPRINTER,
657                     in, out, 
658                     qbuf, rbuf,
659                     spoolss_io_q_getprinter,
660                     spoolss_io_r_getprinter, 
661                     WERR_GENERAL_FAILURE );
662
663         if ( W_ERROR_EQUAL( out.status, WERR_INSUFFICIENT_BUFFER ) ) {
664                 offered = out.needed;
665                 
666                 ZERO_STRUCT(in);
667                 ZERO_STRUCT(out);
668                 
669                 if (!rpcbuf_init(&buffer, offered, mem_ctx))
670                         return WERR_NOMEM;
671                 make_spoolss_q_getprinter( mem_ctx, &in, pol, level, &buffer, offered );
672
673                 CLI_DO_RPC_WERR( cli, mem_ctx, &syntax_spoolss, SPOOLSS_GETPRINTER,
674                             in, out, 
675                             qbuf, rbuf,
676                             spoolss_io_q_getprinter,
677                             spoolss_io_r_getprinter, 
678                             WERR_GENERAL_FAILURE );
679         }
680         
681         if ( !W_ERROR_IS_OK(out.status) )
682                 return out.status;
683                 
684         switch (level) {
685         case 0:
686                 if (!decode_printer_info_0(mem_ctx, out.buffer, 1, &ctr->printers_0)) {
687                         return WERR_GENERAL_FAILURE;
688                 }
689                 break;
690         case 1:
691                 if (!decode_printer_info_1(mem_ctx, out.buffer, 1, &ctr->printers_1)) {
692                         return WERR_GENERAL_FAILURE;
693                 }
694                 break;
695         case 2:
696                 if (!decode_printer_info_2(mem_ctx, out.buffer, 1, &ctr->printers_2)) {
697                         return WERR_GENERAL_FAILURE;
698                 }
699                 break;
700         case 3:
701                 if (!decode_printer_info_3(mem_ctx, out.buffer, 1, &ctr->printers_3)) {
702                         return WERR_GENERAL_FAILURE;
703                 }
704                 break;
705         case 7:
706                 if (!decode_printer_info_7(mem_ctx, out.buffer, 1, &ctr->printers_7)) {
707                         return WERR_GENERAL_FAILURE;
708                 }
709                 break;
710         default:
711                 return WERR_UNKNOWN_LEVEL;
712         }
713
714         return out.status;
715 }
716
717 /**********************************************************************
718 **********************************************************************/
719
720 WERROR rpccli_spoolss_setprinter(struct rpc_pipe_client *cli, TALLOC_CTX *mem_ctx,
721                               POLICY_HND *pol, uint32 level, 
722                               PRINTER_INFO_CTR *ctr, uint32 command)
723 {
724         prs_struct qbuf, rbuf;
725         SPOOL_Q_SETPRINTER in;
726         SPOOL_R_SETPRINTER out;
727
728         ZERO_STRUCT(in);
729         ZERO_STRUCT(out);
730
731         make_spoolss_q_setprinter( mem_ctx, &in, pol, level, ctr, command );
732
733         CLI_DO_RPC_WERR( cli, mem_ctx, &syntax_spoolss, SPOOLSS_SETPRINTER,
734                     in, out, 
735                     qbuf, rbuf,
736                     spoolss_io_q_setprinter,
737                     spoolss_io_r_setprinter, 
738                     WERR_GENERAL_FAILURE );
739
740         return out.status;
741 }
742
743 /**********************************************************************
744 **********************************************************************/
745
746 WERROR rpccli_spoolss_getprinterdriver(struct rpc_pipe_client *cli, 
747                                     TALLOC_CTX *mem_ctx, 
748                                     POLICY_HND *pol, uint32 level, 
749                                     const char *env, int version, PRINTER_DRIVER_CTR *ctr)
750 {
751         prs_struct qbuf, rbuf;
752         SPOOL_Q_GETPRINTERDRIVER2 in;
753         SPOOL_R_GETPRINTERDRIVER2 out;
754         RPC_BUFFER buffer;
755         fstring server;
756         uint32 offered;
757
758         ZERO_STRUCT(in);
759         ZERO_STRUCT(out);
760
761         fstrcpy(server, cli->desthost);
762         strupper_m(server);
763
764         offered = 0;
765         if (!rpcbuf_init(&buffer, offered, mem_ctx))
766                 return WERR_NOMEM;
767         make_spoolss_q_getprinterdriver2( &in, pol, env, level, 
768                 version, 2, &buffer, offered);
769
770         CLI_DO_RPC_WERR( cli, mem_ctx, &syntax_spoolss, SPOOLSS_GETPRINTERDRIVER2,
771                     in, out, 
772                     qbuf, rbuf,
773                     spoolss_io_q_getprinterdriver2,
774                     spoolss_io_r_getprinterdriver2, 
775                     WERR_GENERAL_FAILURE );
776                     
777         if ( W_ERROR_EQUAL( out.status, WERR_INSUFFICIENT_BUFFER ) ) {
778                 offered = out.needed;
779                 
780                 ZERO_STRUCT(in);
781                 ZERO_STRUCT(out);
782                 
783                 if (!rpcbuf_init(&buffer, offered, mem_ctx))
784                         return WERR_NOMEM;
785                 make_spoolss_q_getprinterdriver2( &in, pol, env, level, 
786                         version, 2, &buffer, offered);
787
788                 CLI_DO_RPC_WERR( cli, mem_ctx, &syntax_spoolss, SPOOLSS_GETPRINTERDRIVER2,
789                             in, out, 
790                             qbuf, rbuf,
791                             spoolss_io_q_getprinterdriver2,
792                             spoolss_io_r_getprinterdriver2, 
793                             WERR_GENERAL_FAILURE );
794         }
795                 
796         if ( !W_ERROR_IS_OK(out.status) )
797                 return out.status;
798
799         switch (level) {
800         case 1:
801                 if (!decode_printer_driver_1(mem_ctx, out.buffer, 1, &ctr->info1)) {
802                         return WERR_GENERAL_FAILURE;
803                 }
804                 break;
805         case 2:
806                 if (!decode_printer_driver_2(mem_ctx, out.buffer, 1, &ctr->info2)) {
807                         return WERR_GENERAL_FAILURE;
808                 }
809                 break;
810         case 3:
811                 if (!decode_printer_driver_3(mem_ctx, out.buffer, 1, &ctr->info3)) {
812                         return WERR_GENERAL_FAILURE;
813                 }
814                 break;
815         default:
816                 return WERR_UNKNOWN_LEVEL;
817         }
818
819         return out.status;      
820 }
821
822 /**********************************************************************
823 **********************************************************************/
824
825 WERROR rpccli_spoolss_enumprinterdrivers (struct rpc_pipe_client *cli, 
826                                        TALLOC_CTX *mem_ctx,
827                                        uint32 level, const char *env,
828                                        uint32 *num_drivers,
829                                        PRINTER_DRIVER_CTR *ctr)
830 {
831         prs_struct qbuf, rbuf;
832         SPOOL_Q_ENUMPRINTERDRIVERS in;
833         SPOOL_R_ENUMPRINTERDRIVERS out;
834         RPC_BUFFER buffer;
835         fstring server;
836         uint32 offered;
837
838         ZERO_STRUCT(in);
839         ZERO_STRUCT(out);
840
841         slprintf(server, sizeof(fstring)-1, "\\\\%s", cli->desthost);
842         strupper_m(server);
843
844         offered = 0;
845         if (!rpcbuf_init(&buffer, offered, mem_ctx))
846                 return WERR_NOMEM;
847         make_spoolss_q_enumprinterdrivers( &in, server, env, level, 
848                 &buffer, offered);
849         
850         CLI_DO_RPC_WERR( cli, mem_ctx, &syntax_spoolss, SPOOLSS_ENUMPRINTERDRIVERS,
851                     in, out, 
852                     qbuf, rbuf,
853                     spoolss_io_q_enumprinterdrivers,
854                     spoolss_io_r_enumprinterdrivers, 
855                     WERR_GENERAL_FAILURE );
856
857         if ( W_ERROR_EQUAL( out.status, WERR_INSUFFICIENT_BUFFER ) ) {
858                 offered = out.needed;
859                 
860                 ZERO_STRUCT(in);
861                 ZERO_STRUCT(out);
862                 
863                 if (!rpcbuf_init(&buffer, offered, mem_ctx))
864                         return WERR_NOMEM;
865                 make_spoolss_q_enumprinterdrivers( &in, server, env, level, 
866                         &buffer, offered);
867         
868                 CLI_DO_RPC_WERR( cli, mem_ctx, &syntax_spoolss, SPOOLSS_ENUMPRINTERDRIVERS,
869                             in, out, 
870                             qbuf, rbuf,
871                             spoolss_io_q_enumprinterdrivers,
872                             spoolss_io_r_enumprinterdrivers, 
873                             WERR_GENERAL_FAILURE );
874         }
875         
876         *num_drivers = out.returned;
877
878         if ( !W_ERROR_IS_OK(out.status) )
879                 return out.status;
880                 
881         if ( out.returned ) {
882
883                 switch (level) {
884                 case 1:
885                         if (!decode_printer_driver_1(mem_ctx, out.buffer, out.returned, &ctr->info1)) {
886                                 return WERR_GENERAL_FAILURE;
887                         }
888                         break;
889                 case 2:
890                         if (!decode_printer_driver_2(mem_ctx, out.buffer, out.returned, &ctr->info2)) {
891                                 return WERR_GENERAL_FAILURE;
892                         }
893                         break;
894                 case 3:
895                         if (!decode_printer_driver_3(mem_ctx, out.buffer, out.returned, &ctr->info3)) {
896                                 return WERR_GENERAL_FAILURE;
897                         }
898                         break;
899                 default:
900                         return WERR_UNKNOWN_LEVEL;
901                 }
902         }
903
904         return out.status;
905 }
906
907
908 /**********************************************************************
909 **********************************************************************/
910
911 WERROR rpccli_spoolss_getprinterdriverdir (struct rpc_pipe_client *cli, 
912                                         TALLOC_CTX *mem_ctx,
913                                         uint32 level, char *env,
914                                         DRIVER_DIRECTORY_CTR *ctr)
915 {
916         prs_struct qbuf, rbuf;
917         SPOOL_Q_GETPRINTERDRIVERDIR in;
918         SPOOL_R_GETPRINTERDRIVERDIR out;
919         RPC_BUFFER buffer;
920         fstring server;
921         uint32 offered;
922
923         ZERO_STRUCT(in);
924         ZERO_STRUCT(out);
925
926         slprintf(server, sizeof(fstring)-1, "\\\\%s", cli->desthost);
927         strupper_m(server);
928
929         offered = 0;
930         if (!rpcbuf_init(&buffer, offered, mem_ctx))
931                 return WERR_NOMEM;
932         make_spoolss_q_getprinterdriverdir( &in, server, env, level, 
933                 &buffer, offered );
934
935         CLI_DO_RPC_WERR( cli, mem_ctx, &syntax_spoolss, SPOOLSS_GETPRINTERDRIVERDIRECTORY,
936                     in, out, 
937                     qbuf, rbuf,
938                     spoolss_io_q_getprinterdriverdir,
939                     spoolss_io_r_getprinterdriverdir, 
940                     WERR_GENERAL_FAILURE );
941                     
942         if ( W_ERROR_EQUAL( out.status, WERR_INSUFFICIENT_BUFFER ) ) {
943                 offered = out.needed;
944                 
945                 ZERO_STRUCT(in);
946                 ZERO_STRUCT(out);
947                 
948                 if (!rpcbuf_init(&buffer, offered, mem_ctx))
949                         return WERR_NOMEM;
950                 make_spoolss_q_getprinterdriverdir( &in, server, env, level, 
951                         &buffer, offered );
952
953                 CLI_DO_RPC_WERR( cli, mem_ctx, &syntax_spoolss, SPOOLSS_GETPRINTERDRIVERDIRECTORY,
954                             in, out, 
955                             qbuf, rbuf,
956                             spoolss_io_q_getprinterdriverdir,
957                             spoolss_io_r_getprinterdriverdir, 
958                             WERR_GENERAL_FAILURE );
959         }
960         
961         if (!W_ERROR_IS_OK(out.status))
962                 return out.status;
963                 
964         if (!decode_printerdriverdir_1(mem_ctx, out.buffer, 1, &ctr->info1)) {
965                 return WERR_GENERAL_FAILURE;
966         }
967
968         return out.status;
969 }
970
971 /**********************************************************************
972 **********************************************************************/
973
974 WERROR rpccli_spoolss_addprinterdriver (struct rpc_pipe_client *cli, 
975                                      TALLOC_CTX *mem_ctx, uint32 level,
976                                      PRINTER_DRIVER_CTR *ctr)
977 {
978         prs_struct qbuf, rbuf;
979         SPOOL_Q_ADDPRINTERDRIVER in;
980         SPOOL_R_ADDPRINTERDRIVER out;
981         fstring server;
982
983         ZERO_STRUCT(in);
984         ZERO_STRUCT(out);
985         
986         slprintf(server, sizeof(fstring)-1, "\\\\%s", cli->desthost);
987         strupper_m(server);
988
989         make_spoolss_q_addprinterdriver( mem_ctx, &in, server, level, ctr );
990
991         CLI_DO_RPC_WERR( cli, mem_ctx, &syntax_spoolss, SPOOLSS_ADDPRINTERDRIVER,
992                     in, out, 
993                     qbuf, rbuf,
994                     spoolss_io_q_addprinterdriver,
995                     spoolss_io_r_addprinterdriver, 
996                     WERR_GENERAL_FAILURE );
997
998         return out.status;                  
999 }
1000
1001 /**********************************************************************
1002 **********************************************************************/
1003
1004 WERROR rpccli_spoolss_addprinterex (struct rpc_pipe_client *cli, TALLOC_CTX *mem_ctx,
1005                                  uint32 level, PRINTER_INFO_CTR*ctr)
1006 {
1007         prs_struct qbuf, rbuf;
1008         SPOOL_Q_ADDPRINTEREX in;
1009         SPOOL_R_ADDPRINTEREX out;
1010         fstring server, client, user;
1011
1012         ZERO_STRUCT(in);
1013         ZERO_STRUCT(out);
1014         
1015         slprintf(client, sizeof(fstring)-1, "\\\\%s", global_myname());
1016         slprintf(server, sizeof(fstring)-1, "\\\\%s", cli->desthost);
1017         
1018         strupper_m(client);
1019         strupper_m(server);
1020
1021         fstrcpy  (user, cli->auth->user_name);
1022
1023         make_spoolss_q_addprinterex( mem_ctx, &in, server, client, 
1024                 user, level, ctr);
1025
1026         CLI_DO_RPC_WERR( cli, mem_ctx, &syntax_spoolss, SPOOLSS_ADDPRINTEREX,
1027                     in, out, 
1028                     qbuf, rbuf,
1029                     spoolss_io_q_addprinterex,
1030                     spoolss_io_r_addprinterex, 
1031                     WERR_GENERAL_FAILURE );
1032
1033         return out.status;      
1034 }
1035
1036 /**********************************************************************
1037 **********************************************************************/
1038
1039 WERROR rpccli_spoolss_deleteprinterdriverex(struct rpc_pipe_client *cli, 
1040                                          TALLOC_CTX *mem_ctx, const char *arch,
1041                                          const char *driver, int version)
1042 {
1043         prs_struct qbuf, rbuf;
1044         SPOOL_Q_DELETEPRINTERDRIVEREX in;
1045         SPOOL_R_DELETEPRINTERDRIVEREX out;
1046         fstring server;
1047
1048         ZERO_STRUCT(in);
1049         ZERO_STRUCT(out);
1050
1051         slprintf(server, sizeof(fstring)-1, "\\\\%s", cli->desthost);
1052         strupper_m(server);
1053
1054         make_spoolss_q_deleteprinterdriverex( mem_ctx, &in, server, arch, driver, version );
1055
1056         CLI_DO_RPC_WERR( cli, mem_ctx, &syntax_spoolss, SPOOLSS_DELETEPRINTERDRIVEREX,
1057                     in, out, 
1058                     qbuf, rbuf,
1059                     spoolss_io_q_deleteprinterdriverex,
1060                     spoolss_io_r_deleteprinterdriverex, 
1061                     WERR_GENERAL_FAILURE );
1062                     
1063         return out.status;      
1064 }
1065
1066 /**********************************************************************
1067 **********************************************************************/
1068
1069 WERROR rpccli_spoolss_deleteprinterdriver (struct rpc_pipe_client *cli, 
1070                                         TALLOC_CTX *mem_ctx, const char *arch,
1071                                         const char *driver)
1072 {
1073         prs_struct qbuf, rbuf;
1074         SPOOL_Q_DELETEPRINTERDRIVER in;
1075         SPOOL_R_DELETEPRINTERDRIVER out;
1076         fstring server;
1077
1078         ZERO_STRUCT(in);
1079         ZERO_STRUCT(out);
1080
1081         slprintf(server, sizeof(fstring)-1, "\\\\%s", cli->desthost);
1082         strupper_m(server);
1083
1084         make_spoolss_q_deleteprinterdriver( mem_ctx, &in, server, arch, driver );
1085
1086         CLI_DO_RPC_WERR( cli, mem_ctx, &syntax_spoolss, SPOOLSS_DELETEPRINTERDRIVER,
1087                     in, out, 
1088                     qbuf, rbuf,
1089                     spoolss_io_q_deleteprinterdriver,
1090                     spoolss_io_r_deleteprinterdriver, 
1091                     WERR_GENERAL_FAILURE );
1092                     
1093         return out.status;      
1094 }
1095
1096 /**********************************************************************
1097 **********************************************************************/
1098
1099 WERROR rpccli_spoolss_getprintprocessordirectory(struct rpc_pipe_client *cli,
1100                                               TALLOC_CTX *mem_ctx,
1101                                               char *name, char *environment,
1102                                               fstring procdir)
1103 {
1104         prs_struct qbuf, rbuf;
1105         SPOOL_Q_GETPRINTPROCESSORDIRECTORY in;
1106         SPOOL_R_GETPRINTPROCESSORDIRECTORY out;
1107         int level = 1;
1108         RPC_BUFFER buffer;
1109         uint32 offered;
1110
1111         ZERO_STRUCT(in);
1112         ZERO_STRUCT(out);
1113
1114         offered = 0;
1115         if (!rpcbuf_init(&buffer, offered, mem_ctx))
1116                 return WERR_NOMEM;
1117         make_spoolss_q_getprintprocessordirectory( &in, name, 
1118                 environment, level, &buffer, offered );
1119
1120         CLI_DO_RPC_WERR( cli, mem_ctx, &syntax_spoolss, SPOOLSS_GETPRINTPROCESSORDIRECTORY,
1121                     in, out, 
1122                     qbuf, rbuf,
1123                     spoolss_io_q_getprintprocessordirectory,
1124                     spoolss_io_r_getprintprocessordirectory, 
1125                     WERR_GENERAL_FAILURE );
1126                     
1127         if ( W_ERROR_EQUAL( out.status, WERR_INSUFFICIENT_BUFFER ) ) {
1128                 offered = out.needed;
1129                 
1130                 ZERO_STRUCT(in);
1131                 ZERO_STRUCT(out);
1132                 
1133                 if (!rpcbuf_init(&buffer, offered, mem_ctx))
1134                         return WERR_NOMEM;
1135                 make_spoolss_q_getprintprocessordirectory( &in, name, 
1136                         environment, level, &buffer, offered );
1137
1138                 CLI_DO_RPC_WERR( cli, mem_ctx, &syntax_spoolss, SPOOLSS_GETPRINTPROCESSORDIRECTORY,
1139                             in, out, 
1140                             qbuf, rbuf,
1141                             spoolss_io_q_getprintprocessordirectory,
1142                             spoolss_io_r_getprintprocessordirectory, 
1143                             WERR_GENERAL_FAILURE );
1144         }
1145         
1146         if ( !W_ERROR_IS_OK(out.status) )
1147                 return out.status;
1148         
1149         fstrcpy(procdir, "Not implemented!");
1150         
1151         return out.status;
1152 }
1153
1154 /**********************************************************************
1155 **********************************************************************/
1156
1157 WERROR rpccli_spoolss_addform(struct rpc_pipe_client *cli, TALLOC_CTX *mem_ctx,
1158                            POLICY_HND *handle, uint32 level, FORM *form)
1159 {
1160         prs_struct qbuf, rbuf;
1161         SPOOL_Q_ADDFORM in;
1162         SPOOL_R_ADDFORM out;
1163
1164         ZERO_STRUCT(in);
1165         ZERO_STRUCT(out);
1166
1167         make_spoolss_q_addform( &in, handle, level, form );
1168         
1169         CLI_DO_RPC_WERR( cli, mem_ctx, &syntax_spoolss, SPOOLSS_ADDFORM,
1170                     in, out, 
1171                     qbuf, rbuf,
1172                     spoolss_io_q_addform,
1173                     spoolss_io_r_addform, 
1174                     WERR_GENERAL_FAILURE );
1175
1176         return out.status;
1177 }
1178
1179 /**********************************************************************
1180 **********************************************************************/
1181
1182 WERROR rpccli_spoolss_setform(struct rpc_pipe_client *cli, TALLOC_CTX *mem_ctx,
1183                            POLICY_HND *handle, uint32 level, 
1184                            const char *form_name, FORM *form)
1185 {
1186         prs_struct qbuf, rbuf;
1187         SPOOL_Q_SETFORM in;
1188         SPOOL_R_SETFORM out;
1189
1190         ZERO_STRUCT(in);
1191         ZERO_STRUCT(out);
1192
1193         make_spoolss_q_setform( &in, handle, level, form_name, form );
1194         
1195         CLI_DO_RPC_WERR( cli, mem_ctx, &syntax_spoolss, SPOOLSS_SETFORM,
1196                     in, out, 
1197                     qbuf, rbuf,
1198                     spoolss_io_q_setform,
1199                     spoolss_io_r_setform, 
1200                     WERR_GENERAL_FAILURE );
1201
1202         return out.status;
1203 }
1204
1205 /**********************************************************************
1206 **********************************************************************/
1207
1208 WERROR rpccli_spoolss_getform(struct rpc_pipe_client *cli, TALLOC_CTX *mem_ctx,
1209                            POLICY_HND *handle, const char *formname, 
1210                            uint32 level, FORM_1 *form)
1211 {
1212         prs_struct qbuf, rbuf;
1213         SPOOL_Q_GETFORM in;
1214         SPOOL_R_GETFORM out;
1215         RPC_BUFFER buffer;
1216         uint32 offered;
1217
1218         ZERO_STRUCT(in);
1219         ZERO_STRUCT(out);
1220
1221         offered = 0;
1222         if (!rpcbuf_init(&buffer, offered, mem_ctx))
1223                 return WERR_NOMEM;
1224         make_spoolss_q_getform( &in, handle, formname, level, &buffer, offered );
1225         
1226         CLI_DO_RPC_WERR( cli, mem_ctx, &syntax_spoolss, SPOOLSS_GETFORM,
1227                     in, out, 
1228                     qbuf, rbuf,
1229                     spoolss_io_q_getform,
1230                     spoolss_io_r_getform, 
1231                     WERR_GENERAL_FAILURE );
1232                     
1233         if ( W_ERROR_EQUAL( out.status, WERR_INSUFFICIENT_BUFFER ) ) {
1234                 offered = out.needed;
1235                 
1236                 ZERO_STRUCT(in);
1237                 ZERO_STRUCT(out);
1238                 
1239                 if (!rpcbuf_init(&buffer, offered, mem_ctx))
1240                         return WERR_NOMEM;
1241                 make_spoolss_q_getform( &in, handle, formname, level, &buffer, offered );
1242         
1243                 CLI_DO_RPC_WERR( cli, mem_ctx, &syntax_spoolss, SPOOLSS_GETFORM,
1244                             in, out, 
1245                             qbuf, rbuf,
1246                             spoolss_io_q_getform,
1247                             spoolss_io_r_getform, 
1248                             WERR_GENERAL_FAILURE );
1249         }
1250         
1251         if (!W_ERROR_IS_OK(out.status))
1252                 return out.status;
1253
1254         if (!smb_io_form_1("", out.buffer, form, 0)) {
1255                 return WERR_GENERAL_FAILURE;
1256         }
1257
1258         return out.status;
1259 }
1260
1261 /**********************************************************************
1262 **********************************************************************/
1263
1264 WERROR rpccli_spoolss_deleteform(struct rpc_pipe_client *cli, TALLOC_CTX *mem_ctx,
1265                               POLICY_HND *handle, const char *form_name)
1266 {
1267         prs_struct qbuf, rbuf;
1268         SPOOL_Q_DELETEFORM in;
1269         SPOOL_R_DELETEFORM out;
1270
1271         ZERO_STRUCT(in);
1272         ZERO_STRUCT(out);
1273
1274         make_spoolss_q_deleteform( &in, handle, form_name );
1275         
1276         CLI_DO_RPC_WERR( cli, mem_ctx, &syntax_spoolss, SPOOLSS_DELETEFORM,
1277                     in, out, 
1278                     qbuf, rbuf,
1279                     spoolss_io_q_deleteform,
1280                     spoolss_io_r_deleteform, 
1281                     WERR_GENERAL_FAILURE );
1282                     
1283         return out.status;
1284 }
1285
1286 /**********************************************************************
1287 **********************************************************************/
1288
1289 WERROR rpccli_spoolss_enumforms(struct rpc_pipe_client *cli, TALLOC_CTX *mem_ctx,
1290                              POLICY_HND *handle, int level, uint32 *num_forms,
1291                              FORM_1 **forms)
1292 {
1293         prs_struct qbuf, rbuf;
1294         SPOOL_Q_ENUMFORMS in;
1295         SPOOL_R_ENUMFORMS out;
1296         RPC_BUFFER buffer;
1297         uint32 offered;
1298
1299         ZERO_STRUCT(in);
1300         ZERO_STRUCT(out);
1301
1302         offered = 0;
1303         if (!rpcbuf_init(&buffer, offered, mem_ctx))
1304                 return WERR_NOMEM;
1305         make_spoolss_q_enumforms( &in, handle, level, &buffer, offered );
1306
1307         CLI_DO_RPC_WERR( cli, mem_ctx, &syntax_spoolss, SPOOLSS_ENUMFORMS,
1308                     in, out, 
1309                     qbuf, rbuf,
1310                     spoolss_io_q_enumforms,
1311                     spoolss_io_r_enumforms, 
1312                     WERR_GENERAL_FAILURE );
1313
1314         if ( W_ERROR_EQUAL( out.status, WERR_INSUFFICIENT_BUFFER ) ) {
1315                 offered = out.needed;
1316                 
1317                 ZERO_STRUCT(in);
1318                 ZERO_STRUCT(out);
1319
1320                 if (!rpcbuf_init(&buffer, offered, mem_ctx))
1321                         return WERR_NOMEM;
1322                 make_spoolss_q_enumforms( &in, handle, level, &buffer, offered );
1323
1324                 CLI_DO_RPC_WERR( cli, mem_ctx, &syntax_spoolss, SPOOLSS_ENUMFORMS,
1325                             in, out, 
1326                             qbuf, rbuf,
1327                             spoolss_io_q_enumforms,
1328                             spoolss_io_r_enumforms, 
1329                             WERR_GENERAL_FAILURE );
1330         }
1331
1332         if (!W_ERROR_IS_OK(out.status))
1333                 return out.status;
1334
1335         *num_forms = out.numofforms;
1336         
1337         if (!decode_forms_1(mem_ctx, out.buffer, *num_forms, forms)) {
1338                 return WERR_GENERAL_FAILURE;
1339         }
1340
1341         return out.status;
1342 }
1343
1344 /**********************************************************************
1345 **********************************************************************/
1346
1347 WERROR rpccli_spoolss_enumjobs(struct rpc_pipe_client *cli, TALLOC_CTX *mem_ctx,
1348                             POLICY_HND *hnd, uint32 level, uint32 firstjob, 
1349                             uint32 num_jobs, uint32 *returned, JOB_INFO_CTR *ctr)
1350 {
1351         prs_struct qbuf, rbuf;
1352         SPOOL_Q_ENUMJOBS in;
1353         SPOOL_R_ENUMJOBS out;
1354         RPC_BUFFER buffer;
1355         uint32 offered;
1356
1357         ZERO_STRUCT(in);
1358         ZERO_STRUCT(out);
1359
1360         offered = 0;
1361         if (!rpcbuf_init(&buffer, offered, mem_ctx))
1362                 return WERR_NOMEM;
1363         make_spoolss_q_enumjobs( &in, hnd, firstjob, num_jobs, level, 
1364                 &buffer, offered );
1365
1366         CLI_DO_RPC_WERR( cli, mem_ctx, &syntax_spoolss, SPOOLSS_ENUMJOBS,
1367                     in, out, 
1368                     qbuf, rbuf,
1369                     spoolss_io_q_enumjobs,
1370                     spoolss_io_r_enumjobs, 
1371                     WERR_GENERAL_FAILURE );
1372
1373         if ( W_ERROR_EQUAL( out.status, WERR_INSUFFICIENT_BUFFER ) ) {
1374                 offered = out.needed;
1375                 
1376                 ZERO_STRUCT(in);
1377                 ZERO_STRUCT(out);
1378
1379                 if (!rpcbuf_init(&buffer, offered, mem_ctx))
1380                         return WERR_NOMEM;
1381                 make_spoolss_q_enumjobs( &in, hnd, firstjob, num_jobs, level, 
1382                         &buffer, offered );
1383
1384                 CLI_DO_RPC_WERR( cli, mem_ctx, &syntax_spoolss, SPOOLSS_ENUMJOBS,
1385                             in, out, 
1386                             qbuf, rbuf,
1387                             spoolss_io_q_enumjobs,
1388                             spoolss_io_r_enumjobs, 
1389                             WERR_GENERAL_FAILURE );
1390         }
1391
1392         if (!W_ERROR_IS_OK(out.status))
1393                 return out.status;
1394                 
1395         switch(level) {
1396         case 1:
1397                 if (!decode_jobs_1(mem_ctx, out.buffer, out.returned, &ctr->job.job_info_1)) {
1398                         return WERR_GENERAL_FAILURE;
1399                 }
1400                 break;
1401         case 2:
1402                 if (!decode_jobs_2(mem_ctx, out.buffer, out.returned, &ctr->job.job_info_2)) {
1403                         return WERR_GENERAL_FAILURE;
1404                 }
1405                 break;
1406         default:
1407                 DEBUG(3, ("unsupported info level %d", level));
1408                 return WERR_UNKNOWN_LEVEL;
1409         }
1410         
1411         *returned = out.returned;
1412
1413         return out.status;
1414 }
1415
1416 /**********************************************************************
1417 **********************************************************************/
1418
1419 WERROR rpccli_spoolss_setjob(struct rpc_pipe_client *cli, TALLOC_CTX *mem_ctx,
1420                           POLICY_HND *hnd, uint32 jobid, uint32 level, 
1421                           uint32 command)
1422 {
1423         prs_struct qbuf, rbuf;
1424         SPOOL_Q_SETJOB in;
1425         SPOOL_R_SETJOB out;
1426
1427         ZERO_STRUCT(in);
1428         ZERO_STRUCT(out);
1429
1430         make_spoolss_q_setjob( &in, hnd, jobid, level, command );
1431
1432         CLI_DO_RPC_WERR( cli, mem_ctx, &syntax_spoolss, SPOOLSS_SETJOB,
1433                     in, out, 
1434                     qbuf, rbuf,
1435                     spoolss_io_q_setjob,
1436                     spoolss_io_r_setjob, 
1437                     WERR_GENERAL_FAILURE );
1438                     
1439         return out.status;
1440 }
1441
1442 /**********************************************************************
1443 **********************************************************************/
1444
1445 WERROR rpccli_spoolss_getjob(struct rpc_pipe_client *cli, TALLOC_CTX *mem_ctx,
1446                           POLICY_HND *hnd, uint32 jobid, uint32 level,
1447                           JOB_INFO_CTR *ctr)
1448 {
1449         prs_struct qbuf, rbuf;
1450         SPOOL_Q_GETJOB in;
1451         SPOOL_R_GETJOB out;
1452         RPC_BUFFER buffer;
1453         uint32 offered;
1454
1455         ZERO_STRUCT(in);
1456         ZERO_STRUCT(out);
1457
1458         offered = 0;
1459         if (!rpcbuf_init(&buffer, offered, mem_ctx))
1460                 return WERR_NOMEM;
1461         make_spoolss_q_getjob( &in, hnd, jobid, level, &buffer, offered );
1462
1463         CLI_DO_RPC_WERR( cli, mem_ctx, &syntax_spoolss, SPOOLSS_GETJOB,
1464                     in, out, 
1465                     qbuf, rbuf,
1466                     spoolss_io_q_getjob,
1467                     spoolss_io_r_getjob, 
1468                     WERR_GENERAL_FAILURE );
1469
1470         if ( W_ERROR_EQUAL( out.status, WERR_MORE_DATA ) ) {
1471                 offered = out.needed;
1472                 
1473                 ZERO_STRUCT(in);
1474                 ZERO_STRUCT(out);
1475                 
1476                 if (!rpcbuf_init(&buffer, offered, mem_ctx))
1477                         return WERR_NOMEM;
1478                 make_spoolss_q_getjob( &in, hnd, jobid, level, &buffer, offered );
1479
1480                 CLI_DO_RPC_WERR( cli, mem_ctx, &syntax_spoolss, SPOOLSS_GETJOB,
1481                             in, out, 
1482                             qbuf, rbuf,
1483                             spoolss_io_q_getjob,
1484                             spoolss_io_r_getjob, 
1485                             WERR_GENERAL_FAILURE );
1486         }
1487
1488         if (!W_ERROR_IS_OK(out.status))
1489                 return out.status;
1490
1491         switch(level) {
1492         case 1:
1493                 if (!decode_jobs_1(mem_ctx, out.buffer, 1, &ctr->job.job_info_1)) {
1494                         return WERR_GENERAL_FAILURE;
1495                 }
1496                 break;
1497         case 2:
1498                 if (!decode_jobs_2(mem_ctx, out.buffer, 1, &ctr->job.job_info_2)) {
1499                         return WERR_GENERAL_FAILURE;
1500                 }
1501                 break;
1502         default:
1503                 return WERR_UNKNOWN_LEVEL;
1504         }
1505
1506         return out.status;
1507 }
1508
1509 /**********************************************************************
1510 **********************************************************************/
1511
1512 WERROR rpccli_spoolss_endpageprinter(struct rpc_pipe_client *cli, TALLOC_CTX *mem_ctx,
1513                                   POLICY_HND *hnd)
1514 {
1515         prs_struct qbuf, rbuf;
1516         SPOOL_Q_ENDPAGEPRINTER in;
1517         SPOOL_R_ENDPAGEPRINTER out;
1518
1519         ZERO_STRUCT(in);
1520         ZERO_STRUCT(out);
1521
1522         make_spoolss_q_endpageprinter( &in, hnd );
1523
1524         CLI_DO_RPC_WERR( cli, mem_ctx, &syntax_spoolss, SPOOLSS_ENDPAGEPRINTER,
1525                     in, out, 
1526                     qbuf, rbuf,
1527                     spoolss_io_q_endpageprinter,
1528                     spoolss_io_r_endpageprinter, 
1529                     WERR_GENERAL_FAILURE );
1530                     
1531         return out.status;
1532 }
1533
1534 /**********************************************************************
1535 **********************************************************************/
1536
1537 WERROR rpccli_spoolss_startdocprinter(struct rpc_pipe_client *cli, TALLOC_CTX *mem_ctx,
1538                                    POLICY_HND *hnd, char *docname, 
1539                                    char *outputfile, char *datatype, 
1540                                    uint32 *jobid)
1541 {
1542         prs_struct qbuf, rbuf;
1543         SPOOL_Q_STARTDOCPRINTER in;
1544         SPOOL_R_STARTDOCPRINTER out;
1545         uint32 level = 1;
1546
1547         ZERO_STRUCT(in);
1548         ZERO_STRUCT(out);
1549
1550         make_spoolss_q_startdocprinter( &in, hnd, level, docname, 
1551                 outputfile, datatype );
1552
1553         CLI_DO_RPC_WERR( cli, mem_ctx, &syntax_spoolss, SPOOLSS_STARTDOCPRINTER,
1554                     in, out, 
1555                     qbuf, rbuf,
1556                     spoolss_io_q_startdocprinter,
1557                     spoolss_io_r_startdocprinter, 
1558                     WERR_GENERAL_FAILURE );
1559
1560         *jobid = out.jobid;
1561
1562         return out.status;
1563 }
1564
1565 /**********************************************************************
1566 **********************************************************************/
1567
1568 WERROR rpccli_spoolss_enddocprinter(struct rpc_pipe_client *cli, TALLOC_CTX *mem_ctx,
1569                                   POLICY_HND *hnd)
1570 {
1571         prs_struct qbuf, rbuf;
1572         SPOOL_Q_ENDDOCPRINTER in;
1573         SPOOL_R_ENDDOCPRINTER out;
1574
1575         ZERO_STRUCT(in);
1576         ZERO_STRUCT(out);
1577
1578         make_spoolss_q_enddocprinter( &in, hnd );
1579
1580         CLI_DO_RPC_WERR( cli, mem_ctx, &syntax_spoolss, SPOOLSS_ENDDOCPRINTER,
1581                     in, out, 
1582                     qbuf, rbuf,
1583                     spoolss_io_q_enddocprinter,
1584                     spoolss_io_r_enddocprinter, 
1585                     WERR_GENERAL_FAILURE );
1586                     
1587         return out.status;
1588 }
1589
1590 /**********************************************************************
1591 **********************************************************************/
1592
1593 WERROR rpccli_spoolss_getprinterdata(struct rpc_pipe_client *cli, TALLOC_CTX *mem_ctx,
1594                                   POLICY_HND *hnd, const char *valuename, 
1595                                   REGISTRY_VALUE *value)
1596 {
1597         prs_struct qbuf, rbuf;
1598         SPOOL_Q_GETPRINTERDATA in;
1599         SPOOL_R_GETPRINTERDATA out;
1600         uint32 offered;
1601
1602         ZERO_STRUCT(in);
1603         ZERO_STRUCT(out);
1604
1605         offered = 0;
1606         make_spoolss_q_getprinterdata( &in, hnd, valuename, offered );
1607
1608         CLI_DO_RPC_WERR( cli, mem_ctx, &syntax_spoolss, SPOOLSS_GETPRINTERDATA,
1609                     in, out, 
1610                     qbuf, rbuf,
1611                     spoolss_io_q_getprinterdata,
1612                     spoolss_io_r_getprinterdata, 
1613                     WERR_GENERAL_FAILURE );
1614
1615         if ( W_ERROR_EQUAL( out.status, WERR_MORE_DATA ) ) {
1616                 offered = out.needed;
1617                 
1618                 ZERO_STRUCT(in);
1619                 ZERO_STRUCT(out);
1620                 
1621                 make_spoolss_q_getprinterdata( &in, hnd, valuename, offered );
1622
1623                 CLI_DO_RPC_WERR( cli, mem_ctx, &syntax_spoolss, SPOOLSS_GETPRINTERDATA,
1624                             in, out, 
1625                             qbuf, rbuf,
1626                             spoolss_io_q_getprinterdata,
1627                             spoolss_io_r_getprinterdata, 
1628                             WERR_GENERAL_FAILURE );
1629         }
1630
1631         if (!W_ERROR_IS_OK(out.status))
1632                 return out.status;      
1633
1634         /* Return output parameters */
1635
1636         if (out.needed) {
1637                 value->data_p = (uint8 *)TALLOC_MEMDUP(mem_ctx, out.data, out.needed);
1638         } else {
1639                 value->data_p = NULL;
1640         }
1641         value->type = out.type;
1642         value->size = out.size;
1643
1644         return out.status;
1645 }
1646
1647 /**********************************************************************
1648 **********************************************************************/
1649
1650 WERROR rpccli_spoolss_getprinterdataex(struct rpc_pipe_client *cli, TALLOC_CTX *mem_ctx,
1651                                     POLICY_HND *hnd, const char *keyname, 
1652                                     const char *valuename, 
1653                                     REGISTRY_VALUE *value)
1654 {
1655         prs_struct qbuf, rbuf;
1656         SPOOL_Q_GETPRINTERDATAEX in;
1657         SPOOL_R_GETPRINTERDATAEX out;
1658         uint32 offered = 0;
1659
1660         ZERO_STRUCT(in);
1661         ZERO_STRUCT(out);
1662
1663         make_spoolss_q_getprinterdataex( &in, hnd, keyname, valuename, offered );
1664
1665         CLI_DO_RPC_WERR( cli, mem_ctx, &syntax_spoolss, SPOOLSS_GETPRINTERDATAEX,
1666                     in, out, 
1667                     qbuf, rbuf,
1668                     spoolss_io_q_getprinterdataex,
1669                     spoolss_io_r_getprinterdataex, 
1670                     WERR_GENERAL_FAILURE );
1671
1672         if ( W_ERROR_EQUAL( out.status, WERR_MORE_DATA ) ) {
1673                 offered = out.needed;
1674                 
1675                 ZERO_STRUCT(in);
1676                 ZERO_STRUCT(out);
1677                 
1678                 make_spoolss_q_getprinterdataex( &in, hnd, keyname, valuename, offered );
1679
1680                 CLI_DO_RPC_WERR( cli, mem_ctx, &syntax_spoolss, SPOOLSS_GETPRINTERDATAEX,
1681                             in, out, 
1682                             qbuf, rbuf,
1683                             spoolss_io_q_getprinterdataex,
1684                             spoolss_io_r_getprinterdataex, 
1685                             WERR_GENERAL_FAILURE );
1686         }
1687
1688         if (!W_ERROR_IS_OK(out.status))
1689                 return out.status;      
1690
1691         /* Return output parameters */
1692
1693         if (out.needed) {
1694                 value->data_p = (uint8 *)TALLOC_MEMDUP(mem_ctx, out.data, out.needed);
1695         } else {
1696                 value->data_p = NULL;
1697         }
1698         value->type = out.type;
1699         value->size = out.needed;
1700         
1701         return out.status;
1702 }
1703
1704 /**********************************************************************
1705 **********************************************************************/
1706
1707 WERROR rpccli_spoolss_setprinterdata(struct rpc_pipe_client *cli, TALLOC_CTX *mem_ctx,
1708                                   POLICY_HND *hnd, REGISTRY_VALUE *value)
1709 {
1710         prs_struct qbuf, rbuf;
1711         SPOOL_Q_SETPRINTERDATA in;
1712         SPOOL_R_SETPRINTERDATA out;
1713
1714         ZERO_STRUCT(in);
1715         ZERO_STRUCT(out);
1716
1717         make_spoolss_q_setprinterdata( &in, hnd, value->valuename, 
1718                 value->type, (char *)value->data_p, value->size);
1719
1720         CLI_DO_RPC_WERR( cli, mem_ctx, &syntax_spoolss, SPOOLSS_SETPRINTERDATA,
1721                     in, out, 
1722                     qbuf, rbuf,
1723                     spoolss_io_q_setprinterdata,
1724                     spoolss_io_r_setprinterdata, 
1725                     WERR_GENERAL_FAILURE );
1726                     
1727         return out.status;
1728 }
1729
1730 /**********************************************************************
1731 **********************************************************************/
1732
1733 WERROR rpccli_spoolss_setprinterdataex(struct rpc_pipe_client *cli, TALLOC_CTX *mem_ctx,
1734                                     POLICY_HND *hnd, char *keyname, 
1735                                     REGISTRY_VALUE *value)
1736 {
1737         prs_struct qbuf, rbuf;
1738         SPOOL_Q_SETPRINTERDATAEX in;
1739         SPOOL_R_SETPRINTERDATAEX out;
1740         
1741         ZERO_STRUCT(in);
1742         ZERO_STRUCT(out);
1743
1744         make_spoolss_q_setprinterdataex( &in, hnd, keyname, value->valuename, 
1745                 value->type, (char *)value->data_p, value->size);
1746
1747         CLI_DO_RPC_WERR( cli, mem_ctx, &syntax_spoolss, SPOOLSS_SETPRINTERDATAEX,
1748                     in, out, 
1749                     qbuf, rbuf,
1750                     spoolss_io_q_setprinterdataex,
1751                     spoolss_io_r_setprinterdataex, 
1752                     WERR_GENERAL_FAILURE );
1753
1754         return out.status;
1755 }
1756
1757 /**********************************************************************
1758 **********************************************************************/
1759
1760 WERROR rpccli_spoolss_enumprinterdata(struct rpc_pipe_client *cli, TALLOC_CTX *mem_ctx,
1761                                    POLICY_HND *hnd, uint32 ndx,
1762                                    uint32 value_offered, uint32 data_offered,
1763                                    uint32 *value_needed, uint32 *data_needed,
1764                                    REGISTRY_VALUE *value)
1765 {
1766         prs_struct qbuf, rbuf;
1767         SPOOL_Q_ENUMPRINTERDATA in;
1768         SPOOL_R_ENUMPRINTERDATA out;
1769
1770         ZERO_STRUCT(in);
1771         ZERO_STRUCT(out);
1772
1773         make_spoolss_q_enumprinterdata( &in, hnd, ndx, value_offered, data_offered );
1774
1775         CLI_DO_RPC_WERR( cli, mem_ctx, &syntax_spoolss, SPOOLSS_ENUMPRINTERDATA,
1776                     in, out, 
1777                     qbuf, rbuf,
1778                     spoolss_io_q_enumprinterdata,
1779                     spoolss_io_r_enumprinterdata, 
1780                     WERR_GENERAL_FAILURE );
1781
1782         if ( value_needed )
1783                 *value_needed = out.realvaluesize;
1784         if ( data_needed )
1785                 *data_needed = out.realdatasize;
1786                 
1787         if (!W_ERROR_IS_OK(out.status))
1788                 return out.status;
1789
1790         if (value) {
1791                 rpcstr_pull(value->valuename, out.value, sizeof(value->valuename), -1,
1792                             STR_TERMINATE);
1793                 if (out.realdatasize) {
1794                         value->data_p = (uint8 *)TALLOC_MEMDUP(mem_ctx, out.data,
1795                                                        out.realdatasize);
1796                 } else {
1797                         value->data_p = NULL;
1798                 }
1799                 value->type = out.type;
1800                 value->size = out.realdatasize;
1801         }
1802         
1803         return out.status;
1804 }
1805
1806 /**********************************************************************
1807 **********************************************************************/
1808
1809 WERROR rpccli_spoolss_enumprinterdataex(struct rpc_pipe_client *cli, TALLOC_CTX *mem_ctx,
1810                                      POLICY_HND *hnd, const char *keyname, 
1811                                      REGVAL_CTR *ctr)
1812 {
1813         prs_struct qbuf, rbuf;
1814         SPOOL_Q_ENUMPRINTERDATAEX in;
1815         SPOOL_R_ENUMPRINTERDATAEX out;
1816         int i;
1817         uint32 offered;
1818
1819         ZERO_STRUCT(in);
1820         ZERO_STRUCT(out);
1821
1822         offered = 0;
1823         make_spoolss_q_enumprinterdataex( &in, hnd, keyname, offered );
1824
1825         CLI_DO_RPC_WERR( cli, mem_ctx, &syntax_spoolss, SPOOLSS_ENUMPRINTERDATAEX,
1826                     in, out, 
1827                     qbuf, rbuf,
1828                     spoolss_io_q_enumprinterdataex,
1829                     spoolss_io_r_enumprinterdataex, 
1830                     WERR_GENERAL_FAILURE );
1831
1832         if ( W_ERROR_EQUAL( out.status, WERR_MORE_DATA ) ) {
1833                 offered = out.needed;
1834                 
1835                 ZERO_STRUCT(in);
1836                 ZERO_STRUCT(out);
1837                 
1838                 make_spoolss_q_enumprinterdataex( &in, hnd, keyname, offered );
1839
1840                 CLI_DO_RPC_WERR( cli, mem_ctx, &syntax_spoolss, SPOOLSS_ENUMPRINTERDATAEX,
1841                             in, out, 
1842                             qbuf, rbuf,
1843                             spoolss_io_q_enumprinterdataex,
1844                             spoolss_io_r_enumprinterdataex, 
1845                             WERR_GENERAL_FAILURE );
1846         }
1847         
1848         if (!W_ERROR_IS_OK(out.status))
1849                 return out.status;
1850
1851         for (i = 0; i < out.returned; i++) {
1852                 PRINTER_ENUM_VALUES *v = &out.ctr.values[i];
1853                 fstring name;
1854
1855                 rpcstr_pull(name, v->valuename.buffer, sizeof(name), -1, 
1856                             STR_TERMINATE);
1857                 regval_ctr_addvalue(ctr, name, v->type, (const char *)v->data, v->data_len);
1858         }
1859
1860         return out.status;
1861 }
1862
1863 /**********************************************************************
1864 **********************************************************************/
1865
1866 WERROR rpccli_spoolss_writeprinter(struct rpc_pipe_client *cli, TALLOC_CTX *mem_ctx,
1867                                 POLICY_HND *hnd, uint32 data_size, char *data,
1868                                 uint32 *num_written)
1869 {
1870         prs_struct qbuf, rbuf;
1871         SPOOL_Q_WRITEPRINTER in;
1872         SPOOL_R_WRITEPRINTER out;
1873
1874         ZERO_STRUCT(in);
1875         ZERO_STRUCT(out);
1876
1877         make_spoolss_q_writeprinter( &in, hnd, data_size, data );
1878
1879         CLI_DO_RPC_WERR( cli, mem_ctx, &syntax_spoolss, SPOOLSS_WRITEPRINTER,
1880                     in, out, 
1881                     qbuf, rbuf,
1882                     spoolss_io_q_writeprinter,
1883                     spoolss_io_r_writeprinter, 
1884                     WERR_GENERAL_FAILURE );
1885                     
1886         if (num_written)
1887                 *num_written = out.buffer_written;
1888                 
1889         return out.status;
1890 }
1891
1892 /**********************************************************************
1893 **********************************************************************/
1894
1895 WERROR rpccli_spoolss_deleteprinterdata(struct rpc_pipe_client *cli, TALLOC_CTX *mem_ctx,
1896                                      POLICY_HND *hnd, char *valuename)
1897 {
1898         prs_struct qbuf, rbuf;
1899         SPOOL_Q_DELETEPRINTERDATA in;
1900         SPOOL_R_DELETEPRINTERDATA out;
1901
1902         ZERO_STRUCT(in);
1903         ZERO_STRUCT(out);
1904
1905         make_spoolss_q_deleteprinterdata( &in, hnd, valuename );
1906
1907         CLI_DO_RPC_WERR( cli, mem_ctx, &syntax_spoolss, SPOOLSS_DELETEPRINTERDATA,
1908                     in, out, 
1909                     qbuf, rbuf,
1910                     spoolss_io_q_deleteprinterdata,
1911                     spoolss_io_r_deleteprinterdata, 
1912                     WERR_GENERAL_FAILURE );
1913
1914         return out.status;
1915 }
1916
1917 /**********************************************************************
1918 **********************************************************************/
1919
1920 WERROR rpccli_spoolss_deleteprinterdataex(struct rpc_pipe_client *cli, TALLOC_CTX *mem_ctx,
1921                                        POLICY_HND *hnd, char *keyname, 
1922                                        char *valuename)
1923 {
1924         prs_struct qbuf, rbuf;
1925         SPOOL_Q_DELETEPRINTERDATAEX in;
1926         SPOOL_R_DELETEPRINTERDATAEX out;
1927
1928         ZERO_STRUCT(in);
1929         ZERO_STRUCT(out);
1930
1931         make_spoolss_q_deleteprinterdataex( &in, hnd, keyname, valuename );
1932
1933         CLI_DO_RPC_WERR( cli, mem_ctx, &syntax_spoolss, SPOOLSS_DELETEPRINTERDATAEX,
1934                     in, out, 
1935                     qbuf, rbuf,
1936                     spoolss_io_q_deleteprinterdataex,
1937                     spoolss_io_r_deleteprinterdataex, 
1938                     WERR_GENERAL_FAILURE );
1939
1940         return out.status;
1941 }
1942
1943 /**********************************************************************
1944 **********************************************************************/
1945
1946 WERROR rpccli_spoolss_enumprinterkey(struct rpc_pipe_client *cli, TALLOC_CTX *mem_ctx,
1947                                   POLICY_HND *hnd, const char *keyname,
1948                                   uint16 **keylist, uint32 *len)
1949 {
1950         prs_struct qbuf, rbuf;
1951         SPOOL_Q_ENUMPRINTERKEY in;
1952         SPOOL_R_ENUMPRINTERKEY out;
1953         uint32 offered = 0;
1954
1955         ZERO_STRUCT(in);
1956         ZERO_STRUCT(out);
1957
1958         make_spoolss_q_enumprinterkey( &in, hnd, keyname, offered );
1959
1960         CLI_DO_RPC_WERR( cli, mem_ctx, &syntax_spoolss, SPOOLSS_ENUMPRINTERKEY,
1961                     in, out, 
1962                     qbuf, rbuf,
1963                     spoolss_io_q_enumprinterkey,
1964                     spoolss_io_r_enumprinterkey, 
1965                     WERR_GENERAL_FAILURE );
1966
1967         if ( W_ERROR_EQUAL( out.status, WERR_MORE_DATA ) ) {
1968                 offered = out.needed;
1969                 
1970                 ZERO_STRUCT(in);
1971                 ZERO_STRUCT(out);
1972                 
1973                 make_spoolss_q_enumprinterkey( &in, hnd, keyname, offered );
1974
1975                 CLI_DO_RPC_WERR( cli, mem_ctx, &syntax_spoolss, SPOOLSS_ENUMPRINTERKEY,
1976                             in, out, 
1977                             qbuf, rbuf,
1978                             spoolss_io_q_enumprinterkey,
1979                             spoolss_io_r_enumprinterkey, 
1980                             WERR_GENERAL_FAILURE );
1981         }
1982
1983         if ( !W_ERROR_IS_OK(out.status) )
1984                 return out.status;      
1985         
1986         if (keylist) {
1987                 *keylist = SMB_MALLOC_ARRAY(uint16, out.keys.buf_len);
1988                 if (!*keylist) {
1989                         return WERR_NOMEM;
1990                 }
1991                 memcpy(*keylist, out.keys.buffer, out.keys.buf_len * 2);
1992                 if (len)
1993                         *len = out.keys.buf_len * 2;
1994         }
1995
1996         return out.status;
1997 }
1998
1999 /**********************************************************************
2000 **********************************************************************/
2001
2002 WERROR rpccli_spoolss_deleteprinterkey(struct rpc_pipe_client *cli, TALLOC_CTX *mem_ctx,
2003                                     POLICY_HND *hnd, char *keyname)
2004 {
2005         prs_struct qbuf, rbuf;
2006         SPOOL_Q_DELETEPRINTERKEY in;
2007         SPOOL_R_DELETEPRINTERKEY out;
2008
2009         ZERO_STRUCT(in);
2010         ZERO_STRUCT(out);
2011
2012         make_spoolss_q_deleteprinterkey( &in, hnd, keyname );
2013
2014         CLI_DO_RPC_WERR( cli, mem_ctx, &syntax_spoolss, SPOOLSS_DELETEPRINTERKEY,
2015                     in, out, 
2016                     qbuf, rbuf,
2017                     spoolss_io_q_deleteprinterkey,
2018                     spoolss_io_r_deleteprinterkey, 
2019                     WERR_GENERAL_FAILURE );
2020                     
2021         return out.status;
2022 }
2023
2024 /** @} **/