s3-spoolss: remove old _spoolss_WritePrinter.
[ira/wip.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_enumforms(struct rpc_pipe_client *cli, TALLOC_CTX *mem_ctx,
1265                              POLICY_HND *handle, int level, uint32 *num_forms,
1266                              FORM_1 **forms)
1267 {
1268         prs_struct qbuf, rbuf;
1269         SPOOL_Q_ENUMFORMS in;
1270         SPOOL_R_ENUMFORMS out;
1271         RPC_BUFFER buffer;
1272         uint32 offered;
1273
1274         ZERO_STRUCT(in);
1275         ZERO_STRUCT(out);
1276
1277         offered = 0;
1278         if (!rpcbuf_init(&buffer, offered, mem_ctx))
1279                 return WERR_NOMEM;
1280         make_spoolss_q_enumforms( &in, handle, level, &buffer, offered );
1281
1282         CLI_DO_RPC_WERR( cli, mem_ctx, &syntax_spoolss, SPOOLSS_ENUMFORMS,
1283                     in, out, 
1284                     qbuf, rbuf,
1285                     spoolss_io_q_enumforms,
1286                     spoolss_io_r_enumforms, 
1287                     WERR_GENERAL_FAILURE );
1288
1289         if ( W_ERROR_EQUAL( out.status, WERR_INSUFFICIENT_BUFFER ) ) {
1290                 offered = out.needed;
1291                 
1292                 ZERO_STRUCT(in);
1293                 ZERO_STRUCT(out);
1294
1295                 if (!rpcbuf_init(&buffer, offered, mem_ctx))
1296                         return WERR_NOMEM;
1297                 make_spoolss_q_enumforms( &in, handle, level, &buffer, offered );
1298
1299                 CLI_DO_RPC_WERR( cli, mem_ctx, &syntax_spoolss, SPOOLSS_ENUMFORMS,
1300                             in, out, 
1301                             qbuf, rbuf,
1302                             spoolss_io_q_enumforms,
1303                             spoolss_io_r_enumforms, 
1304                             WERR_GENERAL_FAILURE );
1305         }
1306
1307         if (!W_ERROR_IS_OK(out.status))
1308                 return out.status;
1309
1310         *num_forms = out.numofforms;
1311         
1312         if (!decode_forms_1(mem_ctx, out.buffer, *num_forms, forms)) {
1313                 return WERR_GENERAL_FAILURE;
1314         }
1315
1316         return out.status;
1317 }
1318
1319 /**********************************************************************
1320 **********************************************************************/
1321
1322 WERROR rpccli_spoolss_enumjobs(struct rpc_pipe_client *cli, TALLOC_CTX *mem_ctx,
1323                             POLICY_HND *hnd, uint32 level, uint32 firstjob, 
1324                             uint32 num_jobs, uint32 *returned, JOB_INFO_CTR *ctr)
1325 {
1326         prs_struct qbuf, rbuf;
1327         SPOOL_Q_ENUMJOBS in;
1328         SPOOL_R_ENUMJOBS out;
1329         RPC_BUFFER buffer;
1330         uint32 offered;
1331
1332         ZERO_STRUCT(in);
1333         ZERO_STRUCT(out);
1334
1335         offered = 0;
1336         if (!rpcbuf_init(&buffer, offered, mem_ctx))
1337                 return WERR_NOMEM;
1338         make_spoolss_q_enumjobs( &in, hnd, firstjob, num_jobs, level, 
1339                 &buffer, offered );
1340
1341         CLI_DO_RPC_WERR( cli, mem_ctx, &syntax_spoolss, SPOOLSS_ENUMJOBS,
1342                     in, out, 
1343                     qbuf, rbuf,
1344                     spoolss_io_q_enumjobs,
1345                     spoolss_io_r_enumjobs, 
1346                     WERR_GENERAL_FAILURE );
1347
1348         if ( W_ERROR_EQUAL( out.status, WERR_INSUFFICIENT_BUFFER ) ) {
1349                 offered = out.needed;
1350                 
1351                 ZERO_STRUCT(in);
1352                 ZERO_STRUCT(out);
1353
1354                 if (!rpcbuf_init(&buffer, offered, mem_ctx))
1355                         return WERR_NOMEM;
1356                 make_spoolss_q_enumjobs( &in, hnd, firstjob, num_jobs, level, 
1357                         &buffer, offered );
1358
1359                 CLI_DO_RPC_WERR( cli, mem_ctx, &syntax_spoolss, SPOOLSS_ENUMJOBS,
1360                             in, out, 
1361                             qbuf, rbuf,
1362                             spoolss_io_q_enumjobs,
1363                             spoolss_io_r_enumjobs, 
1364                             WERR_GENERAL_FAILURE );
1365         }
1366
1367         if (!W_ERROR_IS_OK(out.status))
1368                 return out.status;
1369                 
1370         switch(level) {
1371         case 1:
1372                 if (!decode_jobs_1(mem_ctx, out.buffer, out.returned, &ctr->job.job_info_1)) {
1373                         return WERR_GENERAL_FAILURE;
1374                 }
1375                 break;
1376         case 2:
1377                 if (!decode_jobs_2(mem_ctx, out.buffer, out.returned, &ctr->job.job_info_2)) {
1378                         return WERR_GENERAL_FAILURE;
1379                 }
1380                 break;
1381         default:
1382                 DEBUG(3, ("unsupported info level %d", level));
1383                 return WERR_UNKNOWN_LEVEL;
1384         }
1385         
1386         *returned = out.returned;
1387
1388         return out.status;
1389 }
1390
1391 /**********************************************************************
1392 **********************************************************************/
1393
1394 WERROR rpccli_spoolss_setjob(struct rpc_pipe_client *cli, TALLOC_CTX *mem_ctx,
1395                           POLICY_HND *hnd, uint32 jobid, uint32 level, 
1396                           uint32 command)
1397 {
1398         prs_struct qbuf, rbuf;
1399         SPOOL_Q_SETJOB in;
1400         SPOOL_R_SETJOB out;
1401
1402         ZERO_STRUCT(in);
1403         ZERO_STRUCT(out);
1404
1405         make_spoolss_q_setjob( &in, hnd, jobid, level, command );
1406
1407         CLI_DO_RPC_WERR( cli, mem_ctx, &syntax_spoolss, SPOOLSS_SETJOB,
1408                     in, out, 
1409                     qbuf, rbuf,
1410                     spoolss_io_q_setjob,
1411                     spoolss_io_r_setjob, 
1412                     WERR_GENERAL_FAILURE );
1413                     
1414         return out.status;
1415 }
1416
1417 /**********************************************************************
1418 **********************************************************************/
1419
1420 WERROR rpccli_spoolss_getjob(struct rpc_pipe_client *cli, TALLOC_CTX *mem_ctx,
1421                           POLICY_HND *hnd, uint32 jobid, uint32 level,
1422                           JOB_INFO_CTR *ctr)
1423 {
1424         prs_struct qbuf, rbuf;
1425         SPOOL_Q_GETJOB in;
1426         SPOOL_R_GETJOB out;
1427         RPC_BUFFER buffer;
1428         uint32 offered;
1429
1430         ZERO_STRUCT(in);
1431         ZERO_STRUCT(out);
1432
1433         offered = 0;
1434         if (!rpcbuf_init(&buffer, offered, mem_ctx))
1435                 return WERR_NOMEM;
1436         make_spoolss_q_getjob( &in, hnd, jobid, level, &buffer, offered );
1437
1438         CLI_DO_RPC_WERR( cli, mem_ctx, &syntax_spoolss, SPOOLSS_GETJOB,
1439                     in, out, 
1440                     qbuf, rbuf,
1441                     spoolss_io_q_getjob,
1442                     spoolss_io_r_getjob, 
1443                     WERR_GENERAL_FAILURE );
1444
1445         if ( W_ERROR_EQUAL( out.status, WERR_MORE_DATA ) ) {
1446                 offered = out.needed;
1447                 
1448                 ZERO_STRUCT(in);
1449                 ZERO_STRUCT(out);
1450                 
1451                 if (!rpcbuf_init(&buffer, offered, mem_ctx))
1452                         return WERR_NOMEM;
1453                 make_spoolss_q_getjob( &in, hnd, jobid, level, &buffer, offered );
1454
1455                 CLI_DO_RPC_WERR( cli, mem_ctx, &syntax_spoolss, SPOOLSS_GETJOB,
1456                             in, out, 
1457                             qbuf, rbuf,
1458                             spoolss_io_q_getjob,
1459                             spoolss_io_r_getjob, 
1460                             WERR_GENERAL_FAILURE );
1461         }
1462
1463         if (!W_ERROR_IS_OK(out.status))
1464                 return out.status;
1465
1466         switch(level) {
1467         case 1:
1468                 if (!decode_jobs_1(mem_ctx, out.buffer, 1, &ctr->job.job_info_1)) {
1469                         return WERR_GENERAL_FAILURE;
1470                 }
1471                 break;
1472         case 2:
1473                 if (!decode_jobs_2(mem_ctx, out.buffer, 1, &ctr->job.job_info_2)) {
1474                         return WERR_GENERAL_FAILURE;
1475                 }
1476                 break;
1477         default:
1478                 return WERR_UNKNOWN_LEVEL;
1479         }
1480
1481         return out.status;
1482 }
1483
1484 /**********************************************************************
1485 **********************************************************************/
1486
1487 WERROR rpccli_spoolss_startdocprinter(struct rpc_pipe_client *cli, TALLOC_CTX *mem_ctx,
1488                                    POLICY_HND *hnd, char *docname, 
1489                                    char *outputfile, char *datatype, 
1490                                    uint32 *jobid)
1491 {
1492         prs_struct qbuf, rbuf;
1493         SPOOL_Q_STARTDOCPRINTER in;
1494         SPOOL_R_STARTDOCPRINTER out;
1495         uint32 level = 1;
1496
1497         ZERO_STRUCT(in);
1498         ZERO_STRUCT(out);
1499
1500         make_spoolss_q_startdocprinter( &in, hnd, level, docname, 
1501                 outputfile, datatype );
1502
1503         CLI_DO_RPC_WERR( cli, mem_ctx, &syntax_spoolss, SPOOLSS_STARTDOCPRINTER,
1504                     in, out, 
1505                     qbuf, rbuf,
1506                     spoolss_io_q_startdocprinter,
1507                     spoolss_io_r_startdocprinter, 
1508                     WERR_GENERAL_FAILURE );
1509
1510         *jobid = out.jobid;
1511
1512         return out.status;
1513 }
1514
1515 /**********************************************************************
1516 **********************************************************************/
1517
1518 WERROR rpccli_spoolss_getprinterdata(struct rpc_pipe_client *cli, TALLOC_CTX *mem_ctx,
1519                                   POLICY_HND *hnd, const char *valuename, 
1520                                   REGISTRY_VALUE *value)
1521 {
1522         prs_struct qbuf, rbuf;
1523         SPOOL_Q_GETPRINTERDATA in;
1524         SPOOL_R_GETPRINTERDATA out;
1525         uint32 offered;
1526
1527         ZERO_STRUCT(in);
1528         ZERO_STRUCT(out);
1529
1530         offered = 0;
1531         make_spoolss_q_getprinterdata( &in, hnd, valuename, offered );
1532
1533         CLI_DO_RPC_WERR( cli, mem_ctx, &syntax_spoolss, SPOOLSS_GETPRINTERDATA,
1534                     in, out, 
1535                     qbuf, rbuf,
1536                     spoolss_io_q_getprinterdata,
1537                     spoolss_io_r_getprinterdata, 
1538                     WERR_GENERAL_FAILURE );
1539
1540         if ( W_ERROR_EQUAL( out.status, WERR_MORE_DATA ) ) {
1541                 offered = out.needed;
1542                 
1543                 ZERO_STRUCT(in);
1544                 ZERO_STRUCT(out);
1545                 
1546                 make_spoolss_q_getprinterdata( &in, hnd, valuename, offered );
1547
1548                 CLI_DO_RPC_WERR( cli, mem_ctx, &syntax_spoolss, SPOOLSS_GETPRINTERDATA,
1549                             in, out, 
1550                             qbuf, rbuf,
1551                             spoolss_io_q_getprinterdata,
1552                             spoolss_io_r_getprinterdata, 
1553                             WERR_GENERAL_FAILURE );
1554         }
1555
1556         if (!W_ERROR_IS_OK(out.status))
1557                 return out.status;      
1558
1559         /* Return output parameters */
1560
1561         if (out.needed) {
1562                 value->data_p = (uint8 *)TALLOC_MEMDUP(mem_ctx, out.data, out.needed);
1563         } else {
1564                 value->data_p = NULL;
1565         }
1566         value->type = out.type;
1567         value->size = out.size;
1568
1569         return out.status;
1570 }
1571
1572 /**********************************************************************
1573 **********************************************************************/
1574
1575 WERROR rpccli_spoolss_getprinterdataex(struct rpc_pipe_client *cli, TALLOC_CTX *mem_ctx,
1576                                     POLICY_HND *hnd, const char *keyname, 
1577                                     const char *valuename, 
1578                                     REGISTRY_VALUE *value)
1579 {
1580         prs_struct qbuf, rbuf;
1581         SPOOL_Q_GETPRINTERDATAEX in;
1582         SPOOL_R_GETPRINTERDATAEX out;
1583         uint32 offered = 0;
1584
1585         ZERO_STRUCT(in);
1586         ZERO_STRUCT(out);
1587
1588         make_spoolss_q_getprinterdataex( &in, hnd, keyname, valuename, offered );
1589
1590         CLI_DO_RPC_WERR( cli, mem_ctx, &syntax_spoolss, SPOOLSS_GETPRINTERDATAEX,
1591                     in, out, 
1592                     qbuf, rbuf,
1593                     spoolss_io_q_getprinterdataex,
1594                     spoolss_io_r_getprinterdataex, 
1595                     WERR_GENERAL_FAILURE );
1596
1597         if ( W_ERROR_EQUAL( out.status, WERR_MORE_DATA ) ) {
1598                 offered = out.needed;
1599                 
1600                 ZERO_STRUCT(in);
1601                 ZERO_STRUCT(out);
1602                 
1603                 make_spoolss_q_getprinterdataex( &in, hnd, keyname, valuename, offered );
1604
1605                 CLI_DO_RPC_WERR( cli, mem_ctx, &syntax_spoolss, SPOOLSS_GETPRINTERDATAEX,
1606                             in, out, 
1607                             qbuf, rbuf,
1608                             spoolss_io_q_getprinterdataex,
1609                             spoolss_io_r_getprinterdataex, 
1610                             WERR_GENERAL_FAILURE );
1611         }
1612
1613         if (!W_ERROR_IS_OK(out.status))
1614                 return out.status;      
1615
1616         /* Return output parameters */
1617
1618         if (out.needed) {
1619                 value->data_p = (uint8 *)TALLOC_MEMDUP(mem_ctx, out.data, out.needed);
1620         } else {
1621                 value->data_p = NULL;
1622         }
1623         value->type = out.type;
1624         value->size = out.needed;
1625         
1626         return out.status;
1627 }
1628
1629 /**********************************************************************
1630 **********************************************************************/
1631
1632 WERROR rpccli_spoolss_setprinterdata(struct rpc_pipe_client *cli, TALLOC_CTX *mem_ctx,
1633                                   POLICY_HND *hnd, REGISTRY_VALUE *value)
1634 {
1635         prs_struct qbuf, rbuf;
1636         SPOOL_Q_SETPRINTERDATA in;
1637         SPOOL_R_SETPRINTERDATA out;
1638
1639         ZERO_STRUCT(in);
1640         ZERO_STRUCT(out);
1641
1642         make_spoolss_q_setprinterdata( &in, hnd, value->valuename, 
1643                 value->type, (char *)value->data_p, value->size);
1644
1645         CLI_DO_RPC_WERR( cli, mem_ctx, &syntax_spoolss, SPOOLSS_SETPRINTERDATA,
1646                     in, out, 
1647                     qbuf, rbuf,
1648                     spoolss_io_q_setprinterdata,
1649                     spoolss_io_r_setprinterdata, 
1650                     WERR_GENERAL_FAILURE );
1651                     
1652         return out.status;
1653 }
1654
1655 /**********************************************************************
1656 **********************************************************************/
1657
1658 WERROR rpccli_spoolss_setprinterdataex(struct rpc_pipe_client *cli, TALLOC_CTX *mem_ctx,
1659                                     POLICY_HND *hnd, char *keyname, 
1660                                     REGISTRY_VALUE *value)
1661 {
1662         prs_struct qbuf, rbuf;
1663         SPOOL_Q_SETPRINTERDATAEX in;
1664         SPOOL_R_SETPRINTERDATAEX out;
1665         
1666         ZERO_STRUCT(in);
1667         ZERO_STRUCT(out);
1668
1669         make_spoolss_q_setprinterdataex( &in, hnd, keyname, value->valuename, 
1670                 value->type, (char *)value->data_p, value->size);
1671
1672         CLI_DO_RPC_WERR( cli, mem_ctx, &syntax_spoolss, SPOOLSS_SETPRINTERDATAEX,
1673                     in, out, 
1674                     qbuf, rbuf,
1675                     spoolss_io_q_setprinterdataex,
1676                     spoolss_io_r_setprinterdataex, 
1677                     WERR_GENERAL_FAILURE );
1678
1679         return out.status;
1680 }
1681
1682 /**********************************************************************
1683 **********************************************************************/
1684
1685 WERROR rpccli_spoolss_enumprinterdata(struct rpc_pipe_client *cli, TALLOC_CTX *mem_ctx,
1686                                    POLICY_HND *hnd, uint32 ndx,
1687                                    uint32 value_offered, uint32 data_offered,
1688                                    uint32 *value_needed, uint32 *data_needed,
1689                                    REGISTRY_VALUE *value)
1690 {
1691         prs_struct qbuf, rbuf;
1692         SPOOL_Q_ENUMPRINTERDATA in;
1693         SPOOL_R_ENUMPRINTERDATA out;
1694
1695         ZERO_STRUCT(in);
1696         ZERO_STRUCT(out);
1697
1698         make_spoolss_q_enumprinterdata( &in, hnd, ndx, value_offered, data_offered );
1699
1700         CLI_DO_RPC_WERR( cli, mem_ctx, &syntax_spoolss, SPOOLSS_ENUMPRINTERDATA,
1701                     in, out, 
1702                     qbuf, rbuf,
1703                     spoolss_io_q_enumprinterdata,
1704                     spoolss_io_r_enumprinterdata, 
1705                     WERR_GENERAL_FAILURE );
1706
1707         if ( value_needed )
1708                 *value_needed = out.realvaluesize;
1709         if ( data_needed )
1710                 *data_needed = out.realdatasize;
1711                 
1712         if (!W_ERROR_IS_OK(out.status))
1713                 return out.status;
1714
1715         if (value) {
1716                 rpcstr_pull(value->valuename, out.value, sizeof(value->valuename), -1,
1717                             STR_TERMINATE);
1718                 if (out.realdatasize) {
1719                         value->data_p = (uint8 *)TALLOC_MEMDUP(mem_ctx, out.data,
1720                                                        out.realdatasize);
1721                 } else {
1722                         value->data_p = NULL;
1723                 }
1724                 value->type = out.type;
1725                 value->size = out.realdatasize;
1726         }
1727         
1728         return out.status;
1729 }
1730
1731 /**********************************************************************
1732 **********************************************************************/
1733
1734 WERROR rpccli_spoolss_enumprinterdataex(struct rpc_pipe_client *cli, TALLOC_CTX *mem_ctx,
1735                                      POLICY_HND *hnd, const char *keyname, 
1736                                      REGVAL_CTR *ctr)
1737 {
1738         prs_struct qbuf, rbuf;
1739         SPOOL_Q_ENUMPRINTERDATAEX in;
1740         SPOOL_R_ENUMPRINTERDATAEX out;
1741         int i;
1742         uint32 offered;
1743
1744         ZERO_STRUCT(in);
1745         ZERO_STRUCT(out);
1746
1747         offered = 0;
1748         make_spoolss_q_enumprinterdataex( &in, hnd, keyname, offered );
1749
1750         CLI_DO_RPC_WERR( cli, mem_ctx, &syntax_spoolss, SPOOLSS_ENUMPRINTERDATAEX,
1751                     in, out, 
1752                     qbuf, rbuf,
1753                     spoolss_io_q_enumprinterdataex,
1754                     spoolss_io_r_enumprinterdataex, 
1755                     WERR_GENERAL_FAILURE );
1756
1757         if ( W_ERROR_EQUAL( out.status, WERR_MORE_DATA ) ) {
1758                 offered = out.needed;
1759                 
1760                 ZERO_STRUCT(in);
1761                 ZERO_STRUCT(out);
1762                 
1763                 make_spoolss_q_enumprinterdataex( &in, hnd, keyname, offered );
1764
1765                 CLI_DO_RPC_WERR( cli, mem_ctx, &syntax_spoolss, SPOOLSS_ENUMPRINTERDATAEX,
1766                             in, out, 
1767                             qbuf, rbuf,
1768                             spoolss_io_q_enumprinterdataex,
1769                             spoolss_io_r_enumprinterdataex, 
1770                             WERR_GENERAL_FAILURE );
1771         }
1772         
1773         if (!W_ERROR_IS_OK(out.status))
1774                 return out.status;
1775
1776         for (i = 0; i < out.returned; i++) {
1777                 PRINTER_ENUM_VALUES *v = &out.ctr.values[i];
1778                 fstring name;
1779
1780                 rpcstr_pull(name, v->valuename.buffer, sizeof(name), -1, 
1781                             STR_TERMINATE);
1782                 regval_ctr_addvalue(ctr, name, v->type, (const char *)v->data, v->data_len);
1783         }
1784
1785         return out.status;
1786 }
1787
1788 /**********************************************************************
1789 **********************************************************************/
1790
1791 WERROR rpccli_spoolss_deleteprinterdata(struct rpc_pipe_client *cli, TALLOC_CTX *mem_ctx,
1792                                      POLICY_HND *hnd, char *valuename)
1793 {
1794         prs_struct qbuf, rbuf;
1795         SPOOL_Q_DELETEPRINTERDATA in;
1796         SPOOL_R_DELETEPRINTERDATA out;
1797
1798         ZERO_STRUCT(in);
1799         ZERO_STRUCT(out);
1800
1801         make_spoolss_q_deleteprinterdata( &in, hnd, valuename );
1802
1803         CLI_DO_RPC_WERR( cli, mem_ctx, &syntax_spoolss, SPOOLSS_DELETEPRINTERDATA,
1804                     in, out, 
1805                     qbuf, rbuf,
1806                     spoolss_io_q_deleteprinterdata,
1807                     spoolss_io_r_deleteprinterdata, 
1808                     WERR_GENERAL_FAILURE );
1809
1810         return out.status;
1811 }
1812
1813 /**********************************************************************
1814 **********************************************************************/
1815
1816 WERROR rpccli_spoolss_deleteprinterdataex(struct rpc_pipe_client *cli, TALLOC_CTX *mem_ctx,
1817                                        POLICY_HND *hnd, char *keyname, 
1818                                        char *valuename)
1819 {
1820         prs_struct qbuf, rbuf;
1821         SPOOL_Q_DELETEPRINTERDATAEX in;
1822         SPOOL_R_DELETEPRINTERDATAEX out;
1823
1824         ZERO_STRUCT(in);
1825         ZERO_STRUCT(out);
1826
1827         make_spoolss_q_deleteprinterdataex( &in, hnd, keyname, valuename );
1828
1829         CLI_DO_RPC_WERR( cli, mem_ctx, &syntax_spoolss, SPOOLSS_DELETEPRINTERDATAEX,
1830                     in, out, 
1831                     qbuf, rbuf,
1832                     spoolss_io_q_deleteprinterdataex,
1833                     spoolss_io_r_deleteprinterdataex, 
1834                     WERR_GENERAL_FAILURE );
1835
1836         return out.status;
1837 }
1838
1839 /**********************************************************************
1840 **********************************************************************/
1841
1842 WERROR rpccli_spoolss_enumprinterkey(struct rpc_pipe_client *cli, TALLOC_CTX *mem_ctx,
1843                                   POLICY_HND *hnd, const char *keyname,
1844                                   uint16 **keylist, uint32 *len)
1845 {
1846         prs_struct qbuf, rbuf;
1847         SPOOL_Q_ENUMPRINTERKEY in;
1848         SPOOL_R_ENUMPRINTERKEY out;
1849         uint32 offered = 0;
1850
1851         ZERO_STRUCT(in);
1852         ZERO_STRUCT(out);
1853
1854         make_spoolss_q_enumprinterkey( &in, hnd, keyname, offered );
1855
1856         CLI_DO_RPC_WERR( cli, mem_ctx, &syntax_spoolss, SPOOLSS_ENUMPRINTERKEY,
1857                     in, out, 
1858                     qbuf, rbuf,
1859                     spoolss_io_q_enumprinterkey,
1860                     spoolss_io_r_enumprinterkey, 
1861                     WERR_GENERAL_FAILURE );
1862
1863         if ( W_ERROR_EQUAL( out.status, WERR_MORE_DATA ) ) {
1864                 offered = out.needed;
1865                 
1866                 ZERO_STRUCT(in);
1867                 ZERO_STRUCT(out);
1868                 
1869                 make_spoolss_q_enumprinterkey( &in, hnd, keyname, offered );
1870
1871                 CLI_DO_RPC_WERR( cli, mem_ctx, &syntax_spoolss, SPOOLSS_ENUMPRINTERKEY,
1872                             in, out, 
1873                             qbuf, rbuf,
1874                             spoolss_io_q_enumprinterkey,
1875                             spoolss_io_r_enumprinterkey, 
1876                             WERR_GENERAL_FAILURE );
1877         }
1878
1879         if ( !W_ERROR_IS_OK(out.status) )
1880                 return out.status;      
1881         
1882         if (keylist) {
1883                 *keylist = SMB_MALLOC_ARRAY(uint16, out.keys.buf_len);
1884                 if (!*keylist) {
1885                         return WERR_NOMEM;
1886                 }
1887                 memcpy(*keylist, out.keys.buffer, out.keys.buf_len * 2);
1888                 if (len)
1889                         *len = out.keys.buf_len * 2;
1890         }
1891
1892         return out.status;
1893 }
1894
1895 /**********************************************************************
1896 **********************************************************************/
1897
1898 WERROR rpccli_spoolss_deleteprinterkey(struct rpc_pipe_client *cli, TALLOC_CTX *mem_ctx,
1899                                     POLICY_HND *hnd, char *keyname)
1900 {
1901         prs_struct qbuf, rbuf;
1902         SPOOL_Q_DELETEPRINTERKEY in;
1903         SPOOL_R_DELETEPRINTERKEY out;
1904
1905         ZERO_STRUCT(in);
1906         ZERO_STRUCT(out);
1907
1908         make_spoolss_q_deleteprinterkey( &in, hnd, keyname );
1909
1910         CLI_DO_RPC_WERR( cli, mem_ctx, &syntax_spoolss, SPOOLSS_DELETEPRINTERKEY,
1911                     in, out, 
1912                     qbuf, rbuf,
1913                     spoolss_io_q_deleteprinterkey,
1914                     spoolss_io_r_deleteprinterkey, 
1915                     WERR_GENERAL_FAILURE );
1916                     
1917         return out.status;
1918 }
1919
1920 /** @} **/