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