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