s3-spoolss: remove old spoolss_GetPrintProcessorDirectory.
[jra/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  convencience wrapper around rpccli_spoolss_OpenPrinterEx
30 **********************************************************************/
31
32 WERROR rpccli_spoolss_openprinter_ex(struct rpc_pipe_client *cli,
33                                      TALLOC_CTX *mem_ctx,
34                                      const char *printername,
35                                      uint32_t access_desired,
36                                      struct policy_handle *handle)
37 {
38         NTSTATUS status;
39         WERROR werror;
40         struct spoolss_DevmodeContainer devmode_ctr;
41         union spoolss_UserLevel userlevel;
42         struct spoolss_UserLevel1 level1;
43
44         ZERO_STRUCT(devmode_ctr);
45
46         level1.size     = 28;
47         level1.client   = cli->srv_name_slash;
48         level1.user     = cli->auth->user_name;
49         level1.build    = 1381;
50         level1.major    = 2;
51         level1.minor    = 0;
52         level1.processor = 0;
53
54         userlevel.level1 = &level1;
55
56         status = rpccli_spoolss_OpenPrinterEx(cli, mem_ctx,
57                                               printername,
58                                               NULL,
59                                               devmode_ctr,
60                                               access_desired,
61                                               1, /* level */
62                                               userlevel,
63                                               handle,
64                                               &werror);
65
66         if (!W_ERROR_IS_OK(werror)) {
67                 return werror;
68         }
69
70         if (!NT_STATUS_IS_OK(status)) {
71                 return ntstatus_to_werror(status);
72         }
73
74         return WERR_OK;
75 }
76
77 /*********************************************************************
78  Decode various spoolss rpc's and info levels
79  ********************************************************************/
80
81 /**********************************************************************
82 **********************************************************************/
83
84 static bool decode_printer_info_0(TALLOC_CTX *mem_ctx, RPC_BUFFER *buffer,
85                                 uint32 returned, PRINTER_INFO_0 **info)
86 {
87         uint32 i;
88         PRINTER_INFO_0  *inf;
89
90         if (returned) {
91                 inf=TALLOC_ARRAY(mem_ctx, PRINTER_INFO_0, returned);
92                 if (!inf) {
93                         return False;
94                 }
95                 memset(inf, 0, returned*sizeof(PRINTER_INFO_0));
96         } else {
97                 inf = NULL;
98         }
99
100         prs_set_offset(&buffer->prs,0);
101
102         for (i=0; i<returned; i++) {
103                 if (!smb_io_printer_info_0("", buffer, &inf[i], 0)) {
104                         return False;
105                 }
106         }
107
108         *info=inf;
109         return True;
110 }
111
112 /**********************************************************************
113 **********************************************************************/
114
115 static bool decode_printer_info_1(TALLOC_CTX *mem_ctx, RPC_BUFFER *buffer,
116                                 uint32 returned, PRINTER_INFO_1 **info)
117 {
118         uint32 i;
119         PRINTER_INFO_1  *inf;
120
121         if (returned) {
122                 inf=TALLOC_ARRAY(mem_ctx, PRINTER_INFO_1, returned);
123                 if (!inf) {
124                         return False;
125                 }
126                 memset(inf, 0, returned*sizeof(PRINTER_INFO_1));
127         } else {
128                 inf = NULL;
129         }
130
131         prs_set_offset(&buffer->prs,0);
132
133         for (i=0; i<returned; i++) {
134                 if (!smb_io_printer_info_1("", buffer, &inf[i], 0)) {
135                         return False;
136                 }
137         }
138
139         *info=inf;
140         return True;
141 }
142
143 /**********************************************************************
144 **********************************************************************/
145
146 static bool decode_printer_info_2(TALLOC_CTX *mem_ctx, RPC_BUFFER *buffer, 
147                                 uint32 returned, PRINTER_INFO_2 **info)
148 {
149         uint32 i;
150         PRINTER_INFO_2  *inf;
151
152         if (returned) {
153                 inf=TALLOC_ARRAY(mem_ctx, PRINTER_INFO_2, returned);
154                 if (!inf) {
155                         return False;
156                 }
157                 memset(inf, 0, returned*sizeof(PRINTER_INFO_2));
158         } else {
159                 inf = NULL;
160         }
161
162         prs_set_offset(&buffer->prs,0);
163
164         for (i=0; i<returned; i++) {
165                 /* a little initialization as we go */
166                 inf[i].secdesc = NULL;
167                 if (!smb_io_printer_info_2("", buffer, &inf[i], 0)) {
168                         return False;
169                 }
170         }
171
172         *info=inf;
173         return True;
174 }
175
176 /**********************************************************************
177 **********************************************************************/
178
179 static bool decode_printer_info_3(TALLOC_CTX *mem_ctx, RPC_BUFFER *buffer, 
180                                 uint32 returned, PRINTER_INFO_3 **info)
181 {
182         uint32 i;
183         PRINTER_INFO_3  *inf;
184
185         if (returned) {
186                 inf=TALLOC_ARRAY(mem_ctx, PRINTER_INFO_3, returned);
187                 if (!inf) {
188                         return False;
189                 }
190                 memset(inf, 0, returned*sizeof(PRINTER_INFO_3));
191         } else {
192                 inf = NULL;
193         }
194
195         prs_set_offset(&buffer->prs,0);
196
197         for (i=0; i<returned; i++) {
198                 inf[i].secdesc = NULL;
199                 if (!smb_io_printer_info_3("", buffer, &inf[i], 0)) {
200                         return False;
201                 }
202         }
203
204         *info=inf;
205         return True;
206 }
207
208 /**********************************************************************
209 **********************************************************************/
210
211 static bool decode_printer_info_7(TALLOC_CTX *mem_ctx, RPC_BUFFER *buffer,
212                                 uint32 returned, PRINTER_INFO_7 **info)
213 {
214         uint32 i;
215         PRINTER_INFO_7  *inf;
216
217         if (returned) {
218                 inf=TALLOC_ARRAY(mem_ctx, PRINTER_INFO_7, returned);
219                 if (!inf) {
220                         return False;
221                 }
222                 memset(inf, 0, returned*sizeof(PRINTER_INFO_7));
223         } else {
224                 inf = NULL;
225         }
226
227         prs_set_offset(&buffer->prs,0);
228
229         for (i=0; i<returned; i++) {
230                 if (!smb_io_printer_info_7("", buffer, &inf[i], 0)) {
231                         return False;
232                 }
233         }
234
235         *info=inf;
236         return True;
237 }
238
239
240 /**********************************************************************
241 **********************************************************************/
242
243 static bool decode_port_info_1(TALLOC_CTX *mem_ctx, RPC_BUFFER *buffer, 
244                         uint32 returned, PORT_INFO_1 **info)
245 {
246         uint32 i;
247         PORT_INFO_1 *inf;
248
249         if (returned) {
250                 inf=TALLOC_ARRAY(mem_ctx, PORT_INFO_1, returned);
251                 if (!inf) {
252                         return False;
253                 }
254                 memset(inf, 0, returned*sizeof(PORT_INFO_1));
255         } else {
256                 inf = NULL;
257         }
258
259         prs_set_offset(&buffer->prs, 0);
260
261         for (i=0; i<returned; i++) {
262                 if (!smb_io_port_info_1("", buffer, &(inf[i]), 0)) {
263                         return False;
264                 }
265         }
266
267         *info=inf;
268         return True;
269 }
270
271 /**********************************************************************
272 **********************************************************************/
273
274 static bool decode_port_info_2(TALLOC_CTX *mem_ctx, RPC_BUFFER *buffer, 
275                         uint32 returned, PORT_INFO_2 **info)
276 {
277         uint32 i;
278         PORT_INFO_2 *inf;
279
280         if (returned) {
281                 inf=TALLOC_ARRAY(mem_ctx, PORT_INFO_2, returned);
282                 if (!inf) {
283                         return False;
284                 }
285                 memset(inf, 0, returned*sizeof(PORT_INFO_2));
286         } else {
287                 inf = NULL;
288         }
289
290         prs_set_offset(&buffer->prs, 0);
291
292         for (i=0; i<returned; i++) {
293                 if (!smb_io_port_info_2("", buffer, &(inf[i]), 0)) {
294                         return False;
295                 }
296         }
297
298         *info=inf;
299         return True;
300 }
301
302 /**********************************************************************
303 **********************************************************************/
304
305 static bool decode_printer_driver_1(TALLOC_CTX *mem_ctx, RPC_BUFFER *buffer, 
306                         uint32 returned, DRIVER_INFO_1 **info)
307 {
308         uint32 i;
309         DRIVER_INFO_1 *inf;
310
311         if (returned) {
312                 inf=TALLOC_ARRAY(mem_ctx, DRIVER_INFO_1, returned);
313                 if (!inf) {
314                         return False;
315                 }
316                 memset(inf, 0, returned*sizeof(DRIVER_INFO_1));
317         } else {
318                 inf = NULL;
319         }
320
321         prs_set_offset(&buffer->prs,0);
322
323         for (i=0; i<returned; i++) {
324                 if (!smb_io_printer_driver_info_1("", buffer, &(inf[i]), 0)) {
325                         return False;
326                 }
327         }
328
329         *info=inf;
330         return True;
331 }
332
333 /**********************************************************************
334 **********************************************************************/
335
336 static bool decode_printer_driver_2(TALLOC_CTX *mem_ctx, RPC_BUFFER *buffer, 
337                         uint32 returned, DRIVER_INFO_2 **info)
338 {
339         uint32 i;
340         DRIVER_INFO_2 *inf;
341
342         if (returned) {
343                 inf=TALLOC_ARRAY(mem_ctx, DRIVER_INFO_2, returned);
344                 if (!inf) {
345                         return False;
346                 }
347                 memset(inf, 0, returned*sizeof(DRIVER_INFO_2));
348         } else {
349                 inf = NULL;
350         }
351
352         prs_set_offset(&buffer->prs,0);
353
354         for (i=0; i<returned; i++) {
355                 if (!smb_io_printer_driver_info_2("", buffer, &(inf[i]), 0)) {
356                         return False;
357                 }
358         }
359
360         *info=inf;
361         return True;
362 }
363
364 /**********************************************************************
365 **********************************************************************/
366
367 static bool decode_printer_driver_3(TALLOC_CTX *mem_ctx, RPC_BUFFER *buffer, 
368                         uint32 returned, DRIVER_INFO_3 **info)
369 {
370         uint32 i;
371         DRIVER_INFO_3 *inf;
372
373         if (returned) {
374                 inf=TALLOC_ARRAY(mem_ctx, DRIVER_INFO_3, returned);
375                 if (!inf) {
376                         return False;
377                 }
378                 memset(inf, 0, returned*sizeof(DRIVER_INFO_3));
379         } else {
380                 inf = NULL;
381         }
382
383         prs_set_offset(&buffer->prs,0);
384
385         for (i=0; i<returned; i++) {
386                 if (!smb_io_printer_driver_info_3("", buffer, &(inf[i]), 0)) {
387                         return False;
388                 }
389         }
390
391         *info=inf;
392         return True;
393 }
394
395 /**********************************************************************
396 **********************************************************************/
397
398 static bool decode_jobs_1(TALLOC_CTX *mem_ctx, RPC_BUFFER *buffer, 
399                           uint32 num_jobs, JOB_INFO_1 **jobs)
400 {
401         uint32 i;
402
403         if (num_jobs) {
404                 *jobs = TALLOC_ARRAY(mem_ctx, JOB_INFO_1, num_jobs);
405                 if (*jobs == NULL) {
406                         return False;
407                 }
408         } else {
409                 *jobs = NULL;
410         }
411         prs_set_offset(&buffer->prs,0);
412
413         for (i = 0; i < num_jobs; i++) {
414                 if (!smb_io_job_info_1("", buffer, &((*jobs)[i]), 0)) {
415                         return False;
416                 }
417         }
418
419         return True;
420 }
421
422 /**********************************************************************
423 **********************************************************************/
424
425 static bool decode_jobs_2(TALLOC_CTX *mem_ctx, RPC_BUFFER *buffer, 
426                           uint32 num_jobs, JOB_INFO_2 **jobs)
427 {
428         uint32 i;
429
430         if (num_jobs) {
431                 *jobs = TALLOC_ARRAY(mem_ctx, JOB_INFO_2, num_jobs);
432                 if (*jobs == NULL) {
433                         return False;
434                 }
435         } else {
436                 *jobs = NULL;
437         }
438         prs_set_offset(&buffer->prs,0);
439
440         for (i = 0; i < num_jobs; i++) {
441                 if (!smb_io_job_info_2("", buffer, &((*jobs)[i]), 0)) {
442                         return False;
443                 }
444         }
445
446         return True;
447 }
448
449 /**********************************************************************
450 **********************************************************************/
451
452 static bool decode_forms_1(TALLOC_CTX *mem_ctx, RPC_BUFFER *buffer, 
453                            uint32 num_forms, FORM_1 **forms)
454 {
455         int i;
456
457         if (num_forms) {
458                 *forms = TALLOC_ARRAY(mem_ctx, FORM_1, num_forms);
459                 if (*forms == NULL) {
460                         return False;
461                 }
462         } else {
463                 *forms = NULL;
464         }
465
466         prs_set_offset(&buffer->prs,0);
467
468         for (i = 0; i < num_forms; i++) {
469                 if (!smb_io_form_1("", buffer, &((*forms)[i]), 0)) {
470                         return False;
471                 }
472         }
473
474         return True;
475 }
476
477 /**********************************************************************
478 **********************************************************************/
479
480 WERROR rpccli_spoolss_enum_printers(struct rpc_pipe_client *cli, TALLOC_CTX *mem_ctx,
481                                  char *name, uint32 flags, uint32 level,
482                                  uint32 *num_printers, PRINTER_INFO_CTR *ctr)
483 {
484         prs_struct qbuf, rbuf;
485         SPOOL_Q_ENUMPRINTERS in;
486         SPOOL_R_ENUMPRINTERS out;
487         RPC_BUFFER buffer;
488         uint32 offered;
489
490         ZERO_STRUCT(in);
491         ZERO_STRUCT(out);
492
493         offered = 0;
494         if (!rpcbuf_init(&buffer, offered, mem_ctx))
495                 return WERR_NOMEM;
496         make_spoolss_q_enumprinters( &in, flags, name, level, &buffer, offered );
497
498         CLI_DO_RPC_WERR( cli, mem_ctx, &syntax_spoolss, SPOOLSS_ENUMPRINTERS,
499                     in, out, 
500                     qbuf, rbuf,
501                     spoolss_io_q_enumprinters,
502                     spoolss_io_r_enumprinters, 
503                     WERR_GENERAL_FAILURE );
504                     
505         if ( W_ERROR_EQUAL( out.status, WERR_INSUFFICIENT_BUFFER ) ) {
506                 offered = out.needed;
507                 
508                 ZERO_STRUCT(in);
509                 ZERO_STRUCT(out);
510
511                 if (!rpcbuf_init(&buffer, offered, mem_ctx))
512                         return WERR_NOMEM;
513                 make_spoolss_q_enumprinters( &in, flags, name, level, &buffer, offered );
514
515                 CLI_DO_RPC_WERR( cli, mem_ctx, &syntax_spoolss, SPOOLSS_ENUMPRINTERS,
516                             in, out, 
517                             qbuf, rbuf,
518                             spoolss_io_q_enumprinters,
519                             spoolss_io_r_enumprinters, 
520                             WERR_GENERAL_FAILURE );
521         }
522
523         if ( !W_ERROR_IS_OK(out.status) )
524                 return out.status;
525
526         switch (level) {
527         case 0:
528                 if (!decode_printer_info_0(mem_ctx, out.buffer, out.returned, &ctr->printers_0)) {
529                         return WERR_GENERAL_FAILURE;
530                 }
531                 break;
532         case 1:
533                 if (!decode_printer_info_1(mem_ctx, out.buffer, out.returned, &ctr->printers_1)) {
534                         return WERR_GENERAL_FAILURE;
535                 }
536                 break;
537         case 2:
538                 if (!decode_printer_info_2(mem_ctx, out.buffer, out.returned, &ctr->printers_2)) {
539                         return WERR_GENERAL_FAILURE;
540                 }
541                 break;
542         case 3:
543                 if (!decode_printer_info_3(mem_ctx, out.buffer, out.returned, &ctr->printers_3)) {
544                         return WERR_GENERAL_FAILURE;
545                 }
546                 break;
547         default:
548                 return WERR_UNKNOWN_LEVEL;
549         }                       
550
551         *num_printers = out.returned;
552
553         return out.status;
554 }
555
556 /**********************************************************************
557 **********************************************************************/
558
559 WERROR rpccli_spoolss_enum_ports(struct rpc_pipe_client *cli, TALLOC_CTX *mem_ctx,
560                               uint32 level, uint32 *num_ports, PORT_INFO_CTR *ctr)
561 {
562         prs_struct qbuf, rbuf;
563         SPOOL_Q_ENUMPORTS in;
564         SPOOL_R_ENUMPORTS out;
565         RPC_BUFFER buffer;
566         fstring server;
567         uint32 offered;
568
569         ZERO_STRUCT(in);
570         ZERO_STRUCT(out);
571
572         slprintf(server, sizeof(fstring)-1, "\\\\%s", cli->desthost);
573         strupper_m(server);
574
575         offered = 0;
576         if (!rpcbuf_init(&buffer, offered, mem_ctx))
577                 return WERR_NOMEM;
578         make_spoolss_q_enumports( &in, server, level, &buffer, offered );
579         
580         CLI_DO_RPC_WERR( cli, mem_ctx, &syntax_spoolss, SPOOLSS_ENUMPORTS,
581                     in, out, 
582                     qbuf, rbuf,
583                     spoolss_io_q_enumports,
584                     spoolss_io_r_enumports, 
585                     WERR_GENERAL_FAILURE );
586                         
587         if ( W_ERROR_EQUAL( out.status, WERR_INSUFFICIENT_BUFFER ) ) {
588                 offered = out.needed;
589                 
590                 ZERO_STRUCT(in);
591                 ZERO_STRUCT(out);
592                 
593                 if (!rpcbuf_init(&buffer, offered, mem_ctx))
594                         return WERR_NOMEM;
595                 make_spoolss_q_enumports( &in, server, level, &buffer, offered );
596
597                 CLI_DO_RPC_WERR( cli, mem_ctx, &syntax_spoolss, SPOOLSS_ENUMPORTS,
598                             in, out, 
599                             qbuf, rbuf,
600                             spoolss_io_q_enumports,
601                             spoolss_io_r_enumports, 
602                             WERR_GENERAL_FAILURE );
603         }
604         
605         if ( !W_ERROR_IS_OK(out.status) )
606                 return out.status;
607         
608         switch (level) {
609         case 1:
610                 if (!decode_port_info_1(mem_ctx, out.buffer, out.returned, &ctr->port.info_1)) {
611                         return WERR_GENERAL_FAILURE;
612                 }
613                 break;
614         case 2:
615                 if (!decode_port_info_2(mem_ctx, out.buffer, out.returned, &ctr->port.info_2)) {
616                         return WERR_GENERAL_FAILURE;
617                 }
618                 break;
619         default:
620                 return WERR_UNKNOWN_LEVEL;
621         }
622
623         *num_ports = out.returned;
624
625         return out.status;
626 }
627
628 /**********************************************************************
629 **********************************************************************/
630
631 WERROR rpccli_spoolss_getprinter(struct rpc_pipe_client *cli, TALLOC_CTX *mem_ctx,
632                               POLICY_HND *pol, uint32 level, 
633                               PRINTER_INFO_CTR *ctr)
634 {
635         prs_struct qbuf, rbuf;
636         SPOOL_Q_GETPRINTER in;
637         SPOOL_R_GETPRINTER out;
638         RPC_BUFFER buffer;
639         uint32 offered;
640
641         ZERO_STRUCT(in);
642         ZERO_STRUCT(out);
643
644         /* Initialise input parameters */
645
646         offered = 0;
647         if (!rpcbuf_init(&buffer, offered, mem_ctx))
648                 return WERR_NOMEM;
649         make_spoolss_q_getprinter( mem_ctx, &in, pol, level, &buffer, offered );
650         
651         CLI_DO_RPC_WERR( cli, mem_ctx, &syntax_spoolss, SPOOLSS_GETPRINTER,
652                     in, out, 
653                     qbuf, rbuf,
654                     spoolss_io_q_getprinter,
655                     spoolss_io_r_getprinter, 
656                     WERR_GENERAL_FAILURE );
657
658         if ( W_ERROR_EQUAL( out.status, WERR_INSUFFICIENT_BUFFER ) ) {
659                 offered = out.needed;
660                 
661                 ZERO_STRUCT(in);
662                 ZERO_STRUCT(out);
663                 
664                 if (!rpcbuf_init(&buffer, offered, mem_ctx))
665                         return WERR_NOMEM;
666                 make_spoolss_q_getprinter( mem_ctx, &in, pol, level, &buffer, offered );
667
668                 CLI_DO_RPC_WERR( cli, mem_ctx, &syntax_spoolss, SPOOLSS_GETPRINTER,
669                             in, out, 
670                             qbuf, rbuf,
671                             spoolss_io_q_getprinter,
672                             spoolss_io_r_getprinter, 
673                             WERR_GENERAL_FAILURE );
674         }
675         
676         if ( !W_ERROR_IS_OK(out.status) )
677                 return out.status;
678                 
679         switch (level) {
680         case 0:
681                 if (!decode_printer_info_0(mem_ctx, out.buffer, 1, &ctr->printers_0)) {
682                         return WERR_GENERAL_FAILURE;
683                 }
684                 break;
685         case 1:
686                 if (!decode_printer_info_1(mem_ctx, out.buffer, 1, &ctr->printers_1)) {
687                         return WERR_GENERAL_FAILURE;
688                 }
689                 break;
690         case 2:
691                 if (!decode_printer_info_2(mem_ctx, out.buffer, 1, &ctr->printers_2)) {
692                         return WERR_GENERAL_FAILURE;
693                 }
694                 break;
695         case 3:
696                 if (!decode_printer_info_3(mem_ctx, out.buffer, 1, &ctr->printers_3)) {
697                         return WERR_GENERAL_FAILURE;
698                 }
699                 break;
700         case 7:
701                 if (!decode_printer_info_7(mem_ctx, out.buffer, 1, &ctr->printers_7)) {
702                         return WERR_GENERAL_FAILURE;
703                 }
704                 break;
705         default:
706                 return WERR_UNKNOWN_LEVEL;
707         }
708
709         return out.status;
710 }
711
712 /**********************************************************************
713 **********************************************************************/
714
715 WERROR rpccli_spoolss_setprinter(struct rpc_pipe_client *cli, TALLOC_CTX *mem_ctx,
716                               POLICY_HND *pol, uint32 level, 
717                               PRINTER_INFO_CTR *ctr, uint32 command)
718 {
719         prs_struct qbuf, rbuf;
720         SPOOL_Q_SETPRINTER in;
721         SPOOL_R_SETPRINTER out;
722
723         ZERO_STRUCT(in);
724         ZERO_STRUCT(out);
725
726         make_spoolss_q_setprinter( mem_ctx, &in, pol, level, ctr, command );
727
728         CLI_DO_RPC_WERR( cli, mem_ctx, &syntax_spoolss, SPOOLSS_SETPRINTER,
729                     in, out, 
730                     qbuf, rbuf,
731                     spoolss_io_q_setprinter,
732                     spoolss_io_r_setprinter, 
733                     WERR_GENERAL_FAILURE );
734
735         return out.status;
736 }
737
738 /**********************************************************************
739 **********************************************************************/
740
741 WERROR rpccli_spoolss_getprinterdriver(struct rpc_pipe_client *cli, 
742                                     TALLOC_CTX *mem_ctx, 
743                                     POLICY_HND *pol, uint32 level, 
744                                     const char *env, int version, PRINTER_DRIVER_CTR *ctr)
745 {
746         prs_struct qbuf, rbuf;
747         SPOOL_Q_GETPRINTERDRIVER2 in;
748         SPOOL_R_GETPRINTERDRIVER2 out;
749         RPC_BUFFER buffer;
750         fstring server;
751         uint32 offered;
752
753         ZERO_STRUCT(in);
754         ZERO_STRUCT(out);
755
756         fstrcpy(server, cli->desthost);
757         strupper_m(server);
758
759         offered = 0;
760         if (!rpcbuf_init(&buffer, offered, mem_ctx))
761                 return WERR_NOMEM;
762         make_spoolss_q_getprinterdriver2( &in, pol, env, level, 
763                 version, 2, &buffer, offered);
764
765         CLI_DO_RPC_WERR( cli, mem_ctx, &syntax_spoolss, SPOOLSS_GETPRINTERDRIVER2,
766                     in, out, 
767                     qbuf, rbuf,
768                     spoolss_io_q_getprinterdriver2,
769                     spoolss_io_r_getprinterdriver2, 
770                     WERR_GENERAL_FAILURE );
771                     
772         if ( W_ERROR_EQUAL( out.status, WERR_INSUFFICIENT_BUFFER ) ) {
773                 offered = out.needed;
774                 
775                 ZERO_STRUCT(in);
776                 ZERO_STRUCT(out);
777                 
778                 if (!rpcbuf_init(&buffer, offered, mem_ctx))
779                         return WERR_NOMEM;
780                 make_spoolss_q_getprinterdriver2( &in, pol, env, level, 
781                         version, 2, &buffer, offered);
782
783                 CLI_DO_RPC_WERR( cli, mem_ctx, &syntax_spoolss, SPOOLSS_GETPRINTERDRIVER2,
784                             in, out, 
785                             qbuf, rbuf,
786                             spoolss_io_q_getprinterdriver2,
787                             spoolss_io_r_getprinterdriver2, 
788                             WERR_GENERAL_FAILURE );
789         }
790                 
791         if ( !W_ERROR_IS_OK(out.status) )
792                 return out.status;
793
794         switch (level) {
795         case 1:
796                 if (!decode_printer_driver_1(mem_ctx, out.buffer, 1, &ctr->info1)) {
797                         return WERR_GENERAL_FAILURE;
798                 }
799                 break;
800         case 2:
801                 if (!decode_printer_driver_2(mem_ctx, out.buffer, 1, &ctr->info2)) {
802                         return WERR_GENERAL_FAILURE;
803                 }
804                 break;
805         case 3:
806                 if (!decode_printer_driver_3(mem_ctx, out.buffer, 1, &ctr->info3)) {
807                         return WERR_GENERAL_FAILURE;
808                 }
809                 break;
810         default:
811                 return WERR_UNKNOWN_LEVEL;
812         }
813
814         return out.status;      
815 }
816
817 /**********************************************************************
818 **********************************************************************/
819
820 WERROR rpccli_spoolss_enumprinterdrivers (struct rpc_pipe_client *cli, 
821                                        TALLOC_CTX *mem_ctx,
822                                        uint32 level, const char *env,
823                                        uint32 *num_drivers,
824                                        PRINTER_DRIVER_CTR *ctr)
825 {
826         prs_struct qbuf, rbuf;
827         SPOOL_Q_ENUMPRINTERDRIVERS in;
828         SPOOL_R_ENUMPRINTERDRIVERS out;
829         RPC_BUFFER buffer;
830         fstring server;
831         uint32 offered;
832
833         ZERO_STRUCT(in);
834         ZERO_STRUCT(out);
835
836         slprintf(server, sizeof(fstring)-1, "\\\\%s", cli->desthost);
837         strupper_m(server);
838
839         offered = 0;
840         if (!rpcbuf_init(&buffer, offered, mem_ctx))
841                 return WERR_NOMEM;
842         make_spoolss_q_enumprinterdrivers( &in, server, env, level, 
843                 &buffer, offered);
844         
845         CLI_DO_RPC_WERR( cli, mem_ctx, &syntax_spoolss, SPOOLSS_ENUMPRINTERDRIVERS,
846                     in, out, 
847                     qbuf, rbuf,
848                     spoolss_io_q_enumprinterdrivers,
849                     spoolss_io_r_enumprinterdrivers, 
850                     WERR_GENERAL_FAILURE );
851
852         if ( W_ERROR_EQUAL( out.status, WERR_INSUFFICIENT_BUFFER ) ) {
853                 offered = out.needed;
854                 
855                 ZERO_STRUCT(in);
856                 ZERO_STRUCT(out);
857                 
858                 if (!rpcbuf_init(&buffer, offered, mem_ctx))
859                         return WERR_NOMEM;
860                 make_spoolss_q_enumprinterdrivers( &in, server, env, level, 
861                         &buffer, offered);
862         
863                 CLI_DO_RPC_WERR( cli, mem_ctx, &syntax_spoolss, SPOOLSS_ENUMPRINTERDRIVERS,
864                             in, out, 
865                             qbuf, rbuf,
866                             spoolss_io_q_enumprinterdrivers,
867                             spoolss_io_r_enumprinterdrivers, 
868                             WERR_GENERAL_FAILURE );
869         }
870         
871         *num_drivers = out.returned;
872
873         if ( !W_ERROR_IS_OK(out.status) )
874                 return out.status;
875                 
876         if ( out.returned ) {
877
878                 switch (level) {
879                 case 1:
880                         if (!decode_printer_driver_1(mem_ctx, out.buffer, out.returned, &ctr->info1)) {
881                                 return WERR_GENERAL_FAILURE;
882                         }
883                         break;
884                 case 2:
885                         if (!decode_printer_driver_2(mem_ctx, out.buffer, out.returned, &ctr->info2)) {
886                                 return WERR_GENERAL_FAILURE;
887                         }
888                         break;
889                 case 3:
890                         if (!decode_printer_driver_3(mem_ctx, out.buffer, out.returned, &ctr->info3)) {
891                                 return WERR_GENERAL_FAILURE;
892                         }
893                         break;
894                 default:
895                         return WERR_UNKNOWN_LEVEL;
896                 }
897         }
898
899         return out.status;
900 }
901
902 /**********************************************************************
903 **********************************************************************/
904
905 WERROR rpccli_spoolss_addprinterdriver (struct rpc_pipe_client *cli, 
906                                      TALLOC_CTX *mem_ctx, uint32 level,
907                                      PRINTER_DRIVER_CTR *ctr)
908 {
909         prs_struct qbuf, rbuf;
910         SPOOL_Q_ADDPRINTERDRIVER in;
911         SPOOL_R_ADDPRINTERDRIVER out;
912         fstring server;
913
914         ZERO_STRUCT(in);
915         ZERO_STRUCT(out);
916         
917         slprintf(server, sizeof(fstring)-1, "\\\\%s", cli->desthost);
918         strupper_m(server);
919
920         make_spoolss_q_addprinterdriver( mem_ctx, &in, server, level, ctr );
921
922         CLI_DO_RPC_WERR( cli, mem_ctx, &syntax_spoolss, SPOOLSS_ADDPRINTERDRIVER,
923                     in, out, 
924                     qbuf, rbuf,
925                     spoolss_io_q_addprinterdriver,
926                     spoolss_io_r_addprinterdriver, 
927                     WERR_GENERAL_FAILURE );
928
929         return out.status;                  
930 }
931
932 /**********************************************************************
933 **********************************************************************/
934
935 WERROR rpccli_spoolss_addprinterex (struct rpc_pipe_client *cli, TALLOC_CTX *mem_ctx,
936                                  uint32 level, PRINTER_INFO_CTR*ctr)
937 {
938         prs_struct qbuf, rbuf;
939         SPOOL_Q_ADDPRINTEREX in;
940         SPOOL_R_ADDPRINTEREX out;
941         fstring server, client, user;
942
943         ZERO_STRUCT(in);
944         ZERO_STRUCT(out);
945         
946         slprintf(client, sizeof(fstring)-1, "\\\\%s", global_myname());
947         slprintf(server, sizeof(fstring)-1, "\\\\%s", cli->desthost);
948         
949         strupper_m(client);
950         strupper_m(server);
951
952         fstrcpy  (user, cli->auth->user_name);
953
954         make_spoolss_q_addprinterex( mem_ctx, &in, server, client, 
955                 user, level, ctr);
956
957         CLI_DO_RPC_WERR( cli, mem_ctx, &syntax_spoolss, SPOOLSS_ADDPRINTEREX,
958                     in, out, 
959                     qbuf, rbuf,
960                     spoolss_io_q_addprinterex,
961                     spoolss_io_r_addprinterex, 
962                     WERR_GENERAL_FAILURE );
963
964         return out.status;      
965 }
966
967 /**********************************************************************
968 **********************************************************************/
969
970 WERROR rpccli_spoolss_enumforms(struct rpc_pipe_client *cli, TALLOC_CTX *mem_ctx,
971                              POLICY_HND *handle, int level, uint32 *num_forms,
972                              FORM_1 **forms)
973 {
974         prs_struct qbuf, rbuf;
975         SPOOL_Q_ENUMFORMS in;
976         SPOOL_R_ENUMFORMS out;
977         RPC_BUFFER buffer;
978         uint32 offered;
979
980         ZERO_STRUCT(in);
981         ZERO_STRUCT(out);
982
983         offered = 0;
984         if (!rpcbuf_init(&buffer, offered, mem_ctx))
985                 return WERR_NOMEM;
986         make_spoolss_q_enumforms( &in, handle, level, &buffer, offered );
987
988         CLI_DO_RPC_WERR( cli, mem_ctx, &syntax_spoolss, SPOOLSS_ENUMFORMS,
989                     in, out, 
990                     qbuf, rbuf,
991                     spoolss_io_q_enumforms,
992                     spoolss_io_r_enumforms, 
993                     WERR_GENERAL_FAILURE );
994
995         if ( W_ERROR_EQUAL( out.status, WERR_INSUFFICIENT_BUFFER ) ) {
996                 offered = out.needed;
997                 
998                 ZERO_STRUCT(in);
999                 ZERO_STRUCT(out);
1000
1001                 if (!rpcbuf_init(&buffer, offered, mem_ctx))
1002                         return WERR_NOMEM;
1003                 make_spoolss_q_enumforms( &in, handle, level, &buffer, offered );
1004
1005                 CLI_DO_RPC_WERR( cli, mem_ctx, &syntax_spoolss, SPOOLSS_ENUMFORMS,
1006                             in, out, 
1007                             qbuf, rbuf,
1008                             spoolss_io_q_enumforms,
1009                             spoolss_io_r_enumforms, 
1010                             WERR_GENERAL_FAILURE );
1011         }
1012
1013         if (!W_ERROR_IS_OK(out.status))
1014                 return out.status;
1015
1016         *num_forms = out.numofforms;
1017         
1018         if (!decode_forms_1(mem_ctx, out.buffer, *num_forms, forms)) {
1019                 return WERR_GENERAL_FAILURE;
1020         }
1021
1022         return out.status;
1023 }
1024
1025 /**********************************************************************
1026 **********************************************************************/
1027
1028 WERROR rpccli_spoolss_enumjobs(struct rpc_pipe_client *cli, TALLOC_CTX *mem_ctx,
1029                             POLICY_HND *hnd, uint32 level, uint32 firstjob, 
1030                             uint32 num_jobs, uint32 *returned, JOB_INFO_CTR *ctr)
1031 {
1032         prs_struct qbuf, rbuf;
1033         SPOOL_Q_ENUMJOBS in;
1034         SPOOL_R_ENUMJOBS out;
1035         RPC_BUFFER buffer;
1036         uint32 offered;
1037
1038         ZERO_STRUCT(in);
1039         ZERO_STRUCT(out);
1040
1041         offered = 0;
1042         if (!rpcbuf_init(&buffer, offered, mem_ctx))
1043                 return WERR_NOMEM;
1044         make_spoolss_q_enumjobs( &in, hnd, firstjob, num_jobs, level, 
1045                 &buffer, offered );
1046
1047         CLI_DO_RPC_WERR( cli, mem_ctx, &syntax_spoolss, SPOOLSS_ENUMJOBS,
1048                     in, out, 
1049                     qbuf, rbuf,
1050                     spoolss_io_q_enumjobs,
1051                     spoolss_io_r_enumjobs, 
1052                     WERR_GENERAL_FAILURE );
1053
1054         if ( W_ERROR_EQUAL( out.status, WERR_INSUFFICIENT_BUFFER ) ) {
1055                 offered = out.needed;
1056                 
1057                 ZERO_STRUCT(in);
1058                 ZERO_STRUCT(out);
1059
1060                 if (!rpcbuf_init(&buffer, offered, mem_ctx))
1061                         return WERR_NOMEM;
1062                 make_spoolss_q_enumjobs( &in, hnd, firstjob, num_jobs, level, 
1063                         &buffer, offered );
1064
1065                 CLI_DO_RPC_WERR( cli, mem_ctx, &syntax_spoolss, SPOOLSS_ENUMJOBS,
1066                             in, out, 
1067                             qbuf, rbuf,
1068                             spoolss_io_q_enumjobs,
1069                             spoolss_io_r_enumjobs, 
1070                             WERR_GENERAL_FAILURE );
1071         }
1072
1073         if (!W_ERROR_IS_OK(out.status))
1074                 return out.status;
1075                 
1076         switch(level) {
1077         case 1:
1078                 if (!decode_jobs_1(mem_ctx, out.buffer, out.returned, &ctr->job.job_info_1)) {
1079                         return WERR_GENERAL_FAILURE;
1080                 }
1081                 break;
1082         case 2:
1083                 if (!decode_jobs_2(mem_ctx, out.buffer, out.returned, &ctr->job.job_info_2)) {
1084                         return WERR_GENERAL_FAILURE;
1085                 }
1086                 break;
1087         default:
1088                 DEBUG(3, ("unsupported info level %d", level));
1089                 return WERR_UNKNOWN_LEVEL;
1090         }
1091         
1092         *returned = out.returned;
1093
1094         return out.status;
1095 }
1096
1097 /**********************************************************************
1098 **********************************************************************/
1099
1100 WERROR rpccli_spoolss_getjob(struct rpc_pipe_client *cli, TALLOC_CTX *mem_ctx,
1101                           POLICY_HND *hnd, uint32 jobid, uint32 level,
1102                           JOB_INFO_CTR *ctr)
1103 {
1104         prs_struct qbuf, rbuf;
1105         SPOOL_Q_GETJOB in;
1106         SPOOL_R_GETJOB out;
1107         RPC_BUFFER buffer;
1108         uint32 offered;
1109
1110         ZERO_STRUCT(in);
1111         ZERO_STRUCT(out);
1112
1113         offered = 0;
1114         if (!rpcbuf_init(&buffer, offered, mem_ctx))
1115                 return WERR_NOMEM;
1116         make_spoolss_q_getjob( &in, hnd, jobid, level, &buffer, offered );
1117
1118         CLI_DO_RPC_WERR( cli, mem_ctx, &syntax_spoolss, SPOOLSS_GETJOB,
1119                     in, out, 
1120                     qbuf, rbuf,
1121                     spoolss_io_q_getjob,
1122                     spoolss_io_r_getjob, 
1123                     WERR_GENERAL_FAILURE );
1124
1125         if ( W_ERROR_EQUAL( out.status, WERR_MORE_DATA ) ) {
1126                 offered = out.needed;
1127                 
1128                 ZERO_STRUCT(in);
1129                 ZERO_STRUCT(out);
1130                 
1131                 if (!rpcbuf_init(&buffer, offered, mem_ctx))
1132                         return WERR_NOMEM;
1133                 make_spoolss_q_getjob( &in, hnd, jobid, level, &buffer, offered );
1134
1135                 CLI_DO_RPC_WERR( cli, mem_ctx, &syntax_spoolss, SPOOLSS_GETJOB,
1136                             in, out, 
1137                             qbuf, rbuf,
1138                             spoolss_io_q_getjob,
1139                             spoolss_io_r_getjob, 
1140                             WERR_GENERAL_FAILURE );
1141         }
1142
1143         if (!W_ERROR_IS_OK(out.status))
1144                 return out.status;
1145
1146         switch(level) {
1147         case 1:
1148                 if (!decode_jobs_1(mem_ctx, out.buffer, 1, &ctr->job.job_info_1)) {
1149                         return WERR_GENERAL_FAILURE;
1150                 }
1151                 break;
1152         case 2:
1153                 if (!decode_jobs_2(mem_ctx, out.buffer, 1, &ctr->job.job_info_2)) {
1154                         return WERR_GENERAL_FAILURE;
1155                 }
1156                 break;
1157         default:
1158                 return WERR_UNKNOWN_LEVEL;
1159         }
1160
1161         return out.status;
1162 }
1163
1164 /**********************************************************************
1165 **********************************************************************/
1166
1167 WERROR rpccli_spoolss_getprinterdata(struct rpc_pipe_client *cli, TALLOC_CTX *mem_ctx,
1168                                   POLICY_HND *hnd, const char *valuename, 
1169                                   REGISTRY_VALUE *value)
1170 {
1171         prs_struct qbuf, rbuf;
1172         SPOOL_Q_GETPRINTERDATA in;
1173         SPOOL_R_GETPRINTERDATA out;
1174         uint32 offered;
1175
1176         ZERO_STRUCT(in);
1177         ZERO_STRUCT(out);
1178
1179         offered = 0;
1180         make_spoolss_q_getprinterdata( &in, hnd, valuename, offered );
1181
1182         CLI_DO_RPC_WERR( cli, mem_ctx, &syntax_spoolss, SPOOLSS_GETPRINTERDATA,
1183                     in, out, 
1184                     qbuf, rbuf,
1185                     spoolss_io_q_getprinterdata,
1186                     spoolss_io_r_getprinterdata, 
1187                     WERR_GENERAL_FAILURE );
1188
1189         if ( W_ERROR_EQUAL( out.status, WERR_MORE_DATA ) ) {
1190                 offered = out.needed;
1191                 
1192                 ZERO_STRUCT(in);
1193                 ZERO_STRUCT(out);
1194                 
1195                 make_spoolss_q_getprinterdata( &in, hnd, valuename, offered );
1196
1197                 CLI_DO_RPC_WERR( cli, mem_ctx, &syntax_spoolss, SPOOLSS_GETPRINTERDATA,
1198                             in, out, 
1199                             qbuf, rbuf,
1200                             spoolss_io_q_getprinterdata,
1201                             spoolss_io_r_getprinterdata, 
1202                             WERR_GENERAL_FAILURE );
1203         }
1204
1205         if (!W_ERROR_IS_OK(out.status))
1206                 return out.status;      
1207
1208         /* Return output parameters */
1209
1210         if (out.needed) {
1211                 value->data_p = (uint8 *)TALLOC_MEMDUP(mem_ctx, out.data, out.needed);
1212         } else {
1213                 value->data_p = NULL;
1214         }
1215         value->type = out.type;
1216         value->size = out.size;
1217
1218         return out.status;
1219 }
1220
1221 /**********************************************************************
1222 **********************************************************************/
1223
1224 WERROR rpccli_spoolss_setprinterdata(struct rpc_pipe_client *cli, TALLOC_CTX *mem_ctx,
1225                                   POLICY_HND *hnd, REGISTRY_VALUE *value)
1226 {
1227         prs_struct qbuf, rbuf;
1228         SPOOL_Q_SETPRINTERDATA in;
1229         SPOOL_R_SETPRINTERDATA out;
1230
1231         ZERO_STRUCT(in);
1232         ZERO_STRUCT(out);
1233
1234         make_spoolss_q_setprinterdata( &in, hnd, value->valuename, 
1235                 value->type, (char *)value->data_p, value->size);
1236
1237         CLI_DO_RPC_WERR( cli, mem_ctx, &syntax_spoolss, SPOOLSS_SETPRINTERDATA,
1238                     in, out, 
1239                     qbuf, rbuf,
1240                     spoolss_io_q_setprinterdata,
1241                     spoolss_io_r_setprinterdata, 
1242                     WERR_GENERAL_FAILURE );
1243                     
1244         return out.status;
1245 }
1246
1247 /**********************************************************************
1248 **********************************************************************/
1249
1250 WERROR rpccli_spoolss_enumprinterdata(struct rpc_pipe_client *cli, TALLOC_CTX *mem_ctx,
1251                                    POLICY_HND *hnd, uint32 ndx,
1252                                    uint32 value_offered, uint32 data_offered,
1253                                    uint32 *value_needed, uint32 *data_needed,
1254                                    REGISTRY_VALUE *value)
1255 {
1256         prs_struct qbuf, rbuf;
1257         SPOOL_Q_ENUMPRINTERDATA in;
1258         SPOOL_R_ENUMPRINTERDATA out;
1259
1260         ZERO_STRUCT(in);
1261         ZERO_STRUCT(out);
1262
1263         make_spoolss_q_enumprinterdata( &in, hnd, ndx, value_offered, data_offered );
1264
1265         CLI_DO_RPC_WERR( cli, mem_ctx, &syntax_spoolss, SPOOLSS_ENUMPRINTERDATA,
1266                     in, out, 
1267                     qbuf, rbuf,
1268                     spoolss_io_q_enumprinterdata,
1269                     spoolss_io_r_enumprinterdata, 
1270                     WERR_GENERAL_FAILURE );
1271
1272         if ( value_needed )
1273                 *value_needed = out.realvaluesize;
1274         if ( data_needed )
1275                 *data_needed = out.realdatasize;
1276                 
1277         if (!W_ERROR_IS_OK(out.status))
1278                 return out.status;
1279
1280         if (value) {
1281                 rpcstr_pull(value->valuename, out.value, sizeof(value->valuename), -1,
1282                             STR_TERMINATE);
1283                 if (out.realdatasize) {
1284                         value->data_p = (uint8 *)TALLOC_MEMDUP(mem_ctx, out.data,
1285                                                        out.realdatasize);
1286                 } else {
1287                         value->data_p = NULL;
1288                 }
1289                 value->type = out.type;
1290                 value->size = out.realdatasize;
1291         }
1292         
1293         return out.status;
1294 }
1295
1296 /**********************************************************************
1297 **********************************************************************/
1298
1299 WERROR rpccli_spoolss_enumprinterdataex(struct rpc_pipe_client *cli, TALLOC_CTX *mem_ctx,
1300                                      POLICY_HND *hnd, const char *keyname, 
1301                                      REGVAL_CTR *ctr)
1302 {
1303         prs_struct qbuf, rbuf;
1304         SPOOL_Q_ENUMPRINTERDATAEX in;
1305         SPOOL_R_ENUMPRINTERDATAEX out;
1306         int i;
1307         uint32 offered;
1308
1309         ZERO_STRUCT(in);
1310         ZERO_STRUCT(out);
1311
1312         offered = 0;
1313         make_spoolss_q_enumprinterdataex( &in, hnd, keyname, offered );
1314
1315         CLI_DO_RPC_WERR( cli, mem_ctx, &syntax_spoolss, SPOOLSS_ENUMPRINTERDATAEX,
1316                     in, out, 
1317                     qbuf, rbuf,
1318                     spoolss_io_q_enumprinterdataex,
1319                     spoolss_io_r_enumprinterdataex, 
1320                     WERR_GENERAL_FAILURE );
1321
1322         if ( W_ERROR_EQUAL( out.status, WERR_MORE_DATA ) ) {
1323                 offered = out.needed;
1324                 
1325                 ZERO_STRUCT(in);
1326                 ZERO_STRUCT(out);
1327                 
1328                 make_spoolss_q_enumprinterdataex( &in, hnd, keyname, offered );
1329
1330                 CLI_DO_RPC_WERR( cli, mem_ctx, &syntax_spoolss, SPOOLSS_ENUMPRINTERDATAEX,
1331                             in, out, 
1332                             qbuf, rbuf,
1333                             spoolss_io_q_enumprinterdataex,
1334                             spoolss_io_r_enumprinterdataex, 
1335                             WERR_GENERAL_FAILURE );
1336         }
1337         
1338         if (!W_ERROR_IS_OK(out.status))
1339                 return out.status;
1340
1341         for (i = 0; i < out.returned; i++) {
1342                 PRINTER_ENUM_VALUES *v = &out.ctr.values[i];
1343                 fstring name;
1344
1345                 rpcstr_pull(name, v->valuename.buffer, sizeof(name), -1, 
1346                             STR_TERMINATE);
1347                 regval_ctr_addvalue(ctr, name, v->type, (const char *)v->data, v->data_len);
1348         }
1349
1350         return out.status;
1351 }
1352
1353 /**********************************************************************
1354 **********************************************************************/
1355
1356 WERROR rpccli_spoolss_enumprinterkey(struct rpc_pipe_client *cli, TALLOC_CTX *mem_ctx,
1357                                   POLICY_HND *hnd, const char *keyname,
1358                                   uint16 **keylist, uint32 *len)
1359 {
1360         prs_struct qbuf, rbuf;
1361         SPOOL_Q_ENUMPRINTERKEY in;
1362         SPOOL_R_ENUMPRINTERKEY out;
1363         uint32 offered = 0;
1364
1365         ZERO_STRUCT(in);
1366         ZERO_STRUCT(out);
1367
1368         make_spoolss_q_enumprinterkey( &in, hnd, keyname, offered );
1369
1370         CLI_DO_RPC_WERR( cli, mem_ctx, &syntax_spoolss, SPOOLSS_ENUMPRINTERKEY,
1371                     in, out, 
1372                     qbuf, rbuf,
1373                     spoolss_io_q_enumprinterkey,
1374                     spoolss_io_r_enumprinterkey, 
1375                     WERR_GENERAL_FAILURE );
1376
1377         if ( W_ERROR_EQUAL( out.status, WERR_MORE_DATA ) ) {
1378                 offered = out.needed;
1379                 
1380                 ZERO_STRUCT(in);
1381                 ZERO_STRUCT(out);
1382                 
1383                 make_spoolss_q_enumprinterkey( &in, hnd, keyname, offered );
1384
1385                 CLI_DO_RPC_WERR( cli, mem_ctx, &syntax_spoolss, SPOOLSS_ENUMPRINTERKEY,
1386                             in, out, 
1387                             qbuf, rbuf,
1388                             spoolss_io_q_enumprinterkey,
1389                             spoolss_io_r_enumprinterkey, 
1390                             WERR_GENERAL_FAILURE );
1391         }
1392
1393         if ( !W_ERROR_IS_OK(out.status) )
1394                 return out.status;      
1395         
1396         if (keylist) {
1397                 *keylist = SMB_MALLOC_ARRAY(uint16, out.keys.buf_len);
1398                 if (!*keylist) {
1399                         return WERR_NOMEM;
1400                 }
1401                 memcpy(*keylist, out.keys.buffer, out.keys.buf_len * 2);
1402                 if (len)
1403                         *len = out.keys.buf_len * 2;
1404         }
1405
1406         return out.status;
1407 }
1408
1409 /** @} **/