s3-spoolss: use pidl for _spoolss_EndPagePrinter.
[tprouty/samba.git] / source3 / rpc_server / srv_spoolss.c
1 /* 
2  *  Unix SMB/CIFS implementation.
3  *  RPC Pipe client / server routines
4  *  Copyright (C) Andrew Tridgell              1992-2000,
5  *  Copyright (C) Luke Kenneth Casson Leighton 1996-2000,
6  *  Copyright (C) Jean François Micouleau      1998-2000,
7  *  Copyright (C) Jeremy Allison                    2001,
8  *  Copyright (C) Gerald Carter                2001-2002,
9  *  Copyright (C) Jim McDonough <jmcd@us.ibm.com>   2003.
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
27 #undef DBGC_CLASS
28 #define DBGC_CLASS DBGC_RPC_SRV
29
30 /*******************************************************************
31  ********************************************************************/
32
33 static bool proxy_spoolss_call(pipes_struct *p, uint8_t opnum)
34 {
35         struct api_struct *fns;
36         int n_fns;
37
38         spoolss_get_pipe_fns(&fns, &n_fns);
39
40         if (opnum >= n_fns) {
41                 return false;
42         }
43
44         if (fns[opnum].opnum != opnum) {
45                 smb_panic("SPOOLSS function table not sorted");
46         }
47
48         return fns[opnum].fn(p);
49 }
50
51 /********************************************************************
52  * api_spoolss_open_printer_ex (rarely seen - older call)
53  ********************************************************************/
54
55 static bool api_spoolss_open_printer(pipes_struct *p)
56 {
57         SPOOL_Q_OPEN_PRINTER q_u;
58         SPOOL_R_OPEN_PRINTER r_u;
59         prs_struct *data = &p->in_data.data;
60         prs_struct *rdata = &p->out_data.rdata;
61
62         ZERO_STRUCT(q_u);
63         ZERO_STRUCT(r_u);
64
65         if (!spoolss_io_q_open_printer("", &q_u, data, 0)) {
66                 DEBUG(0,("spoolss_io_q_open_printer: unable to unmarshall SPOOL_Q_OPEN_PRINTER.\n"));
67                 return False;
68         }
69
70         r_u.status = _spoolss_open_printer( p, &q_u, &r_u);
71         
72         if (!spoolss_io_r_open_printer("",&r_u,rdata,0)){
73                 DEBUG(0,("spoolss_io_r_open_printer: unable to marshall SPOOL_R_OPEN_PRINTER.\n"));
74                 return False;
75         }
76
77         return True;
78 }
79
80
81 /********************************************************************
82  * api_spoolss_open_printer_ex
83  ********************************************************************/
84
85 static bool api_spoolss_open_printer_ex(pipes_struct *p)
86 {
87         SPOOL_Q_OPEN_PRINTER_EX q_u;
88         SPOOL_R_OPEN_PRINTER_EX r_u;
89         prs_struct *data = &p->in_data.data;
90         prs_struct *rdata = &p->out_data.rdata;
91
92         ZERO_STRUCT(q_u);
93         ZERO_STRUCT(r_u);
94
95         if (!spoolss_io_q_open_printer_ex("", &q_u, data, 0)) {
96                 DEBUG(0,("spoolss_io_q_open_printer_ex: unable to unmarshall SPOOL_Q_OPEN_PRINTER_EX.\n"));
97                 return False;
98         }
99
100         r_u.status = _spoolss_open_printer_ex( p, &q_u, &r_u);
101
102         if (!spoolss_io_r_open_printer_ex("",&r_u,rdata,0)){
103                 DEBUG(0,("spoolss_io_r_open_printer_ex: unable to marshall SPOOL_R_OPEN_PRINTER_EX.\n"));
104                 return False;
105         }
106
107         return True;
108 }
109
110 /********************************************************************
111  * api_spoolss_getprinterdata
112  *
113  * called from the spoolss dispatcher
114  ********************************************************************/
115
116 static bool api_spoolss_getprinterdata(pipes_struct *p)
117 {
118         SPOOL_Q_GETPRINTERDATA q_u;
119         SPOOL_R_GETPRINTERDATA r_u;
120         prs_struct *data = &p->in_data.data;
121         prs_struct *rdata = &p->out_data.rdata;
122
123         ZERO_STRUCT(q_u);
124         ZERO_STRUCT(r_u);
125
126         /* read the stream and fill the struct */
127         if (!spoolss_io_q_getprinterdata("", &q_u, data, 0)) {
128                 DEBUG(0,("spoolss_io_q_getprinterdata: unable to unmarshall SPOOL_Q_GETPRINTERDATA.\n"));
129                 return False;
130         }
131         
132         r_u.status = _spoolss_getprinterdata( p, &q_u, &r_u);
133
134         if (!spoolss_io_r_getprinterdata("", &r_u, rdata, 0)) {
135                 DEBUG(0,("spoolss_io_r_getprinterdata: unable to marshall SPOOL_R_GETPRINTERDATA.\n"));
136                 return False;
137         }
138
139         return True;
140 }
141
142 /********************************************************************
143  * api_spoolss_deleteprinterdata
144  *
145  * called from the spoolss dispatcher
146  ********************************************************************/
147
148 static bool api_spoolss_deleteprinterdata(pipes_struct *p)
149 {
150         SPOOL_Q_DELETEPRINTERDATA q_u;
151         SPOOL_R_DELETEPRINTERDATA r_u;
152         prs_struct *data = &p->in_data.data;
153         prs_struct *rdata = &p->out_data.rdata;
154
155         ZERO_STRUCT(q_u);
156         ZERO_STRUCT(r_u);
157
158         /* read the stream and fill the struct */
159         if (!spoolss_io_q_deleteprinterdata("", &q_u, data, 0)) {
160                 DEBUG(0,("spoolss_io_q_deleteprinterdata: unable to unmarshall SPOOL_Q_DELETEPRINTERDATA.\n"));
161                 return False;
162         }
163         
164         r_u.status = _spoolss_deleteprinterdata( p, &q_u, &r_u );
165
166         if (!spoolss_io_r_deleteprinterdata("", &r_u, rdata, 0)) {
167                 DEBUG(0,("spoolss_io_r_deleteprinterdata: unable to marshall SPOOL_R_DELETEPRINTERDATA.\n"));
168                 return False;
169         }
170
171         return True;
172 }
173
174 /********************************************************************
175  * api_spoolss_closeprinter
176  *
177  * called from the spoolss dispatcher
178  ********************************************************************/
179
180 static bool api_spoolss_closeprinter(pipes_struct *p)
181 {
182         return proxy_spoolss_call(p, NDR_SPOOLSS_CLOSEPRINTER);
183 }
184
185 /********************************************************************
186  * api_spoolss_abortprinter
187  *
188  * called from the spoolss dispatcher
189  ********************************************************************/
190
191 static bool api_spoolss_abortprinter(pipes_struct *p)
192 {
193         SPOOL_Q_ABORTPRINTER q_u;
194         SPOOL_R_ABORTPRINTER r_u;
195         prs_struct *data = &p->in_data.data;
196         prs_struct *rdata = &p->out_data.rdata;
197
198         ZERO_STRUCT(q_u);
199         ZERO_STRUCT(r_u);
200
201         if (!spoolss_io_q_abortprinter("", &q_u, data, 0)) {
202                 DEBUG(0,("spoolss_io_q_abortprinter: unable to unmarshall SPOOL_Q_ABORTPRINTER.\n"));
203                 return False;
204         }
205
206         r_u.status = _spoolss_abortprinter(p, &q_u, &r_u);
207
208         if (!spoolss_io_r_abortprinter("",&r_u,rdata,0)) {
209                 DEBUG(0,("spoolss_io_r_abortprinter: unable to marshall SPOOL_R_ABORTPRINTER.\n"));
210                 return False;
211         }
212
213         return True;
214 }
215
216 /********************************************************************
217  * api_spoolss_deleteprinter
218  *
219  * called from the spoolss dispatcher
220  ********************************************************************/
221
222 static bool api_spoolss_deleteprinter(pipes_struct *p)
223 {
224         return proxy_spoolss_call(p, NDR_SPOOLSS_DELETEPRINTER);
225 }
226
227 /********************************************************************
228  * api_spoolss_deleteprinterdriver
229  *
230  * called from the spoolss dispatcher
231  ********************************************************************/
232
233 static bool api_spoolss_deleteprinterdriver(pipes_struct *p)
234 {
235         SPOOL_Q_DELETEPRINTERDRIVER q_u;
236         SPOOL_R_DELETEPRINTERDRIVER r_u;
237         prs_struct *data = &p->in_data.data;
238         prs_struct *rdata = &p->out_data.rdata;
239
240         ZERO_STRUCT(q_u);
241         ZERO_STRUCT(r_u);
242
243         if (!spoolss_io_q_deleteprinterdriver("", &q_u, data, 0)) {
244                 DEBUG(0,("spoolss_io_q_deleteprinterdriver: unable to unmarshall SPOOL_Q_DELETEPRINTERDRIVER.\n"));
245                 return False;
246         }
247
248         r_u.status = _spoolss_deleteprinterdriver(p, &q_u, &r_u);
249
250         if (!spoolss_io_r_deleteprinterdriver("",&r_u,rdata,0)) {
251                 DEBUG(0,("spoolss_io_r_deleteprinter: unable to marshall SPOOL_R_DELETEPRINTER.\n"));
252                 return False;
253         }
254
255         return True;
256 }
257
258
259 /********************************************************************
260  * api_spoolss_rffpcnex
261  * ReplyFindFirstPrinterChangeNotifyEx
262  ********************************************************************/
263
264 static bool api_spoolss_rffpcnex(pipes_struct *p)
265 {
266         SPOOL_Q_RFFPCNEX q_u;
267         SPOOL_R_RFFPCNEX r_u;
268         prs_struct *data = &p->in_data.data;
269         prs_struct *rdata = &p->out_data.rdata;
270
271         ZERO_STRUCT(q_u);
272         ZERO_STRUCT(r_u);
273
274         if (!spoolss_io_q_rffpcnex("", &q_u, data, 0)) {
275                 DEBUG(0,("spoolss_io_q_rffpcnex: unable to unmarshall SPOOL_Q_RFFPCNEX.\n"));
276                 return False;
277         }
278
279         r_u.status = _spoolss_rffpcnex(p, &q_u, &r_u);
280
281         if (!spoolss_io_r_rffpcnex("", &r_u, rdata, 0)) {
282                 DEBUG(0,("spoolss_io_r_rffpcnex: unable to marshall SPOOL_R_RFFPCNEX.\n"));
283                 return False;
284         }
285
286         return True;
287 }
288
289
290 /********************************************************************
291  * api_spoolss_rfnpcnex
292  * ReplyFindNextPrinterChangeNotifyEx
293  * called from the spoolss dispatcher
294
295  * Note - this is the *ONLY* function that breaks the RPC call
296  * symmetry in all the other calls. We need to do this to fix
297  * the massive memory allocation problem with thousands of jobs...
298  * JRA.
299  ********************************************************************/
300
301 static bool api_spoolss_rfnpcnex(pipes_struct *p)
302 {
303         SPOOL_Q_RFNPCNEX q_u;
304         SPOOL_R_RFNPCNEX r_u;
305         prs_struct *data = &p->in_data.data;
306         prs_struct *rdata = &p->out_data.rdata;
307
308         ZERO_STRUCT(q_u);
309         ZERO_STRUCT(r_u);
310
311         if (!spoolss_io_q_rfnpcnex("", &q_u, data, 0)) {
312                 DEBUG(0,("spoolss_io_q_rfnpcnex: unable to unmarshall SPOOL_Q_RFNPCNEX.\n"));
313                 return False;
314         }
315
316         r_u.status = _spoolss_rfnpcnex(p, &q_u, &r_u);
317
318         if (!spoolss_io_r_rfnpcnex("", &r_u, rdata, 0)) {
319                 SAFE_FREE(r_u.info.data);
320                 DEBUG(0,("spoolss_io_r_rfnpcnex: unable to marshall SPOOL_R_RFNPCNEX.\n"));
321                 return False;
322         }
323
324         SAFE_FREE(r_u.info.data);
325
326         return True;
327 }
328
329
330 /********************************************************************
331  * api_spoolss_enumprinters
332  * called from the spoolss dispatcher
333  *
334  ********************************************************************/
335
336 static bool api_spoolss_enumprinters(pipes_struct *p)
337 {
338         SPOOL_Q_ENUMPRINTERS q_u;
339         SPOOL_R_ENUMPRINTERS r_u;
340         prs_struct *data = &p->in_data.data;
341         prs_struct *rdata = &p->out_data.rdata;
342
343         ZERO_STRUCT(q_u);
344         ZERO_STRUCT(r_u);
345
346         if (!spoolss_io_q_enumprinters("", &q_u, data, 0)) {
347                 DEBUG(0,("spoolss_io_q_enumprinters: unable to unmarshall SPOOL_Q_ENUMPRINTERS.\n"));
348                 return False;
349         }
350
351         r_u.status = _spoolss_enumprinters( p, &q_u, &r_u);
352
353         if (!spoolss_io_r_enumprinters("", &r_u, rdata, 0)) {
354                 DEBUG(0,("spoolss_io_r_enumprinters: unable to marshall SPOOL_R_ENUMPRINTERS.\n"));
355                 return False;
356         }
357
358         return True;
359 }
360
361 /********************************************************************
362  * api_spoolss_getprinter
363  * called from the spoolss dispatcher
364  *
365  ********************************************************************/
366
367 static bool api_spoolss_getprinter(pipes_struct *p)
368 {
369         SPOOL_Q_GETPRINTER q_u;
370         SPOOL_R_GETPRINTER r_u;
371         prs_struct *data = &p->in_data.data;
372         prs_struct *rdata = &p->out_data.rdata;
373
374         ZERO_STRUCT(q_u);
375         ZERO_STRUCT(r_u);
376
377         if(!spoolss_io_q_getprinter("", &q_u, data, 0)) {
378                 DEBUG(0,("spoolss_io_q_getprinter: unable to unmarshall SPOOL_Q_GETPRINTER.\n"));
379                 return False;
380         }
381
382         r_u.status = _spoolss_getprinter(p, &q_u, &r_u);
383
384         if(!spoolss_io_r_getprinter("",&r_u,rdata,0)) {
385                 DEBUG(0,("spoolss_io_r_getprinter: unable to marshall SPOOL_R_GETPRINTER.\n"));
386                 return False;
387         }
388
389         return True;
390 }
391
392 /********************************************************************
393  * api_spoolss_getprinter
394  * called from the spoolss dispatcher
395  *
396  ********************************************************************/
397
398 static bool api_spoolss_getprinterdriver2(pipes_struct *p)
399 {
400         SPOOL_Q_GETPRINTERDRIVER2 q_u;
401         SPOOL_R_GETPRINTERDRIVER2 r_u;
402         prs_struct *data = &p->in_data.data;
403         prs_struct *rdata = &p->out_data.rdata;
404
405         ZERO_STRUCT(q_u);
406         ZERO_STRUCT(r_u);
407
408         if(!spoolss_io_q_getprinterdriver2("", &q_u, data, 0)) {
409                 DEBUG(0,("spoolss_io_q_getprinterdriver2: unable to unmarshall SPOOL_Q_GETPRINTERDRIVER2.\n"));
410                 return False;
411         }
412
413         r_u.status = _spoolss_getprinterdriver2(p, &q_u, &r_u);
414         
415         if(!spoolss_io_r_getprinterdriver2("",&r_u,rdata,0)) {
416                 DEBUG(0,("spoolss_io_r_getprinterdriver2: unable to marshall SPOOL_R_GETPRINTERDRIVER2.\n"));
417                 return False;
418         }
419         
420         return True;
421 }
422
423 /********************************************************************
424  * api_spoolss_getprinter
425  * called from the spoolss dispatcher
426  *
427  ********************************************************************/
428
429 static bool api_spoolss_startpageprinter(pipes_struct *p)
430 {
431         return proxy_spoolss_call(p, NDR_SPOOLSS_STARTPAGEPRINTER);
432 }
433
434 /********************************************************************
435  * api_spoolss_getprinter
436  * called from the spoolss dispatcher
437  *
438  ********************************************************************/
439
440 static bool api_spoolss_endpageprinter(pipes_struct *p)
441 {
442         return proxy_spoolss_call(p, NDR_SPOOLSS_ENDPAGEPRINTER);
443 }
444
445 /********************************************************************
446 ********************************************************************/
447
448 static bool api_spoolss_startdocprinter(pipes_struct *p)
449 {
450         SPOOL_Q_STARTDOCPRINTER q_u;
451         SPOOL_R_STARTDOCPRINTER r_u;
452         prs_struct *data = &p->in_data.data;
453         prs_struct *rdata = &p->out_data.rdata;
454
455         ZERO_STRUCT(q_u);
456         ZERO_STRUCT(r_u);
457
458         if(!spoolss_io_q_startdocprinter("", &q_u, data, 0)) {
459                 DEBUG(0,("spoolss_io_q_startdocprinter: unable to unmarshall SPOOL_Q_STARTDOCPRINTER.\n"));
460                 return False;
461         }
462
463         r_u.status = _spoolss_startdocprinter(p, &q_u, &r_u);
464
465         if(!spoolss_io_r_startdocprinter("",&r_u,rdata,0)) {
466                 DEBUG(0,("spoolss_io_r_startdocprinter: unable to marshall SPOOL_R_STARTDOCPRINTER.\n"));
467                 return False;
468         }
469
470         return True;
471 }
472
473 /********************************************************************
474 ********************************************************************/
475
476 static bool api_spoolss_enddocprinter(pipes_struct *p)
477 {
478         SPOOL_Q_ENDDOCPRINTER q_u;
479         SPOOL_R_ENDDOCPRINTER r_u;
480         prs_struct *data = &p->in_data.data;
481         prs_struct *rdata = &p->out_data.rdata;
482
483         ZERO_STRUCT(q_u);
484         ZERO_STRUCT(r_u);
485
486         if(!spoolss_io_q_enddocprinter("", &q_u, data, 0)) {
487                 DEBUG(0,("spoolss_io_q_enddocprinter: unable to unmarshall SPOOL_Q_ENDDOCPRINTER.\n"));
488                 return False;
489         }
490
491         r_u.status = _spoolss_enddocprinter(p, &q_u, &r_u);
492
493         if(!spoolss_io_r_enddocprinter("",&r_u,rdata,0)) {
494                 DEBUG(0,("spoolss_io_r_enddocprinter: unable to marshall SPOOL_R_ENDDOCPRINTER.\n"));
495                 return False;
496         }
497
498         return True;            
499 }
500
501 /********************************************************************
502 ********************************************************************/
503
504 static bool api_spoolss_writeprinter(pipes_struct *p)
505 {
506         SPOOL_Q_WRITEPRINTER q_u;
507         SPOOL_R_WRITEPRINTER r_u;
508         prs_struct *data = &p->in_data.data;
509         prs_struct *rdata = &p->out_data.rdata;
510
511         ZERO_STRUCT(q_u);
512         ZERO_STRUCT(r_u);
513
514         if(!spoolss_io_q_writeprinter("", &q_u, data, 0)) {
515                 DEBUG(0,("spoolss_io_q_writeprinter: unable to unmarshall SPOOL_Q_WRITEPRINTER.\n"));
516                 return False;
517         }
518
519         r_u.status = _spoolss_writeprinter(p, &q_u, &r_u);
520
521         if(!spoolss_io_r_writeprinter("",&r_u,rdata,0)) {
522                 DEBUG(0,("spoolss_io_r_writeprinter: unable to marshall SPOOL_R_WRITEPRINTER.\n"));
523                 return False;
524         }
525
526         return True;
527 }
528
529 /****************************************************************************
530
531 ****************************************************************************/
532
533 static bool api_spoolss_setprinter(pipes_struct *p)
534 {
535         SPOOL_Q_SETPRINTER q_u;
536         SPOOL_R_SETPRINTER r_u;
537         prs_struct *data = &p->in_data.data;
538         prs_struct *rdata = &p->out_data.rdata;
539
540         ZERO_STRUCT(q_u);
541         ZERO_STRUCT(r_u);
542
543         if(!spoolss_io_q_setprinter("", &q_u, data, 0)) {
544                 DEBUG(0,("spoolss_io_q_setprinter: unable to unmarshall SPOOL_Q_SETPRINTER.\n"));
545                 return False;
546         }
547         
548         r_u.status = _spoolss_setprinter(p, &q_u, &r_u);
549         
550         if(!spoolss_io_r_setprinter("",&r_u,rdata,0)) {
551                 DEBUG(0,("spoolss_io_r_setprinter: unable to marshall SPOOL_R_SETPRINTER.\n"));
552                 return False;
553         }
554
555         return True;
556 }
557
558 /****************************************************************************
559 ****************************************************************************/
560
561 static bool api_spoolss_fcpn(pipes_struct *p)
562 {
563         SPOOL_Q_FCPN q_u;
564         SPOOL_R_FCPN r_u;
565         prs_struct *data = &p->in_data.data;
566         prs_struct *rdata = &p->out_data.rdata;
567
568         ZERO_STRUCT(q_u);
569         ZERO_STRUCT(r_u);
570
571         if(!spoolss_io_q_fcpn("", &q_u, data, 0)) {
572                 DEBUG(0,("spoolss_io_q_fcpn: unable to unmarshall SPOOL_Q_FCPN.\n"));
573                 return False;
574         }
575
576         r_u.status = _spoolss_fcpn(p, &q_u, &r_u);
577
578         if(!spoolss_io_r_fcpn("",&r_u,rdata,0)) {
579                 DEBUG(0,("spoolss_io_r_fcpn: unable to marshall SPOOL_R_FCPN.\n"));
580                 return False;
581         }
582
583         return True;
584 }
585
586 /****************************************************************************
587 ****************************************************************************/
588
589 static bool api_spoolss_addjob(pipes_struct *p)
590 {
591         SPOOL_Q_ADDJOB q_u;
592         SPOOL_R_ADDJOB r_u;
593         prs_struct *data = &p->in_data.data;
594         prs_struct *rdata = &p->out_data.rdata;
595
596         ZERO_STRUCT(q_u);
597         ZERO_STRUCT(r_u);
598
599         if(!spoolss_io_q_addjob("", &q_u, data, 0)) {
600                 DEBUG(0,("spoolss_io_q_addjob: unable to unmarshall SPOOL_Q_ADDJOB.\n"));
601                 return False;
602         }
603
604         r_u.status = _spoolss_addjob(p, &q_u, &r_u);
605                 
606         if(!spoolss_io_r_addjob("",&r_u,rdata,0)) {
607                 DEBUG(0,("spoolss_io_r_addjob: unable to marshall SPOOL_R_ADDJOB.\n"));
608                 return False;
609         }
610
611         return True;            
612 }
613
614 /****************************************************************************
615 ****************************************************************************/
616
617 static bool api_spoolss_enumjobs(pipes_struct *p)
618 {
619         SPOOL_Q_ENUMJOBS q_u;
620         SPOOL_R_ENUMJOBS r_u;
621         prs_struct *data = &p->in_data.data;
622         prs_struct *rdata = &p->out_data.rdata;
623
624         ZERO_STRUCT(q_u);
625         ZERO_STRUCT(r_u);
626
627         if (!spoolss_io_q_enumjobs("", &q_u, data, 0)) {
628                 DEBUG(0,("spoolss_io_q_enumjobs: unable to unmarshall SPOOL_Q_ENUMJOBS.\n"));
629                 return False;
630         }
631
632         r_u.status = _spoolss_enumjobs(p, &q_u, &r_u);
633
634         if (!spoolss_io_r_enumjobs("",&r_u,rdata,0)) {
635                 DEBUG(0,("spoolss_io_r_enumjobs: unable to marshall SPOOL_R_ENUMJOBS.\n"));
636                 return False;
637         }
638
639         return True;
640 }
641
642 /****************************************************************************
643 ****************************************************************************/
644
645 static bool api_spoolss_schedulejob(pipes_struct *p)
646 {
647         SPOOL_Q_SCHEDULEJOB q_u;
648         SPOOL_R_SCHEDULEJOB r_u;
649         prs_struct *data = &p->in_data.data;
650         prs_struct *rdata = &p->out_data.rdata;
651
652         ZERO_STRUCT(q_u);
653         ZERO_STRUCT(r_u);
654
655         if(!spoolss_io_q_schedulejob("", &q_u, data, 0)) {
656                 DEBUG(0,("spoolss_io_q_schedulejob: unable to unmarshall SPOOL_Q_SCHEDULEJOB.\n"));
657                 return False;
658         }
659
660         r_u.status = _spoolss_schedulejob(p, &q_u, &r_u);
661
662         if(!spoolss_io_r_schedulejob("",&r_u,rdata,0)) {
663                 DEBUG(0,("spoolss_io_r_schedulejob: unable to marshall SPOOL_R_SCHEDULEJOB.\n"));
664                 return False;
665         }
666
667         return True;
668 }
669
670 /****************************************************************************
671 ****************************************************************************/
672
673 static bool api_spoolss_setjob(pipes_struct *p)
674 {
675         SPOOL_Q_SETJOB q_u;
676         SPOOL_R_SETJOB r_u;
677         prs_struct *data = &p->in_data.data;
678         prs_struct *rdata = &p->out_data.rdata;
679
680         ZERO_STRUCT(q_u);
681         ZERO_STRUCT(r_u);
682
683         if(!spoolss_io_q_setjob("", &q_u, data, 0)) {
684                 DEBUG(0,("spoolss_io_q_setjob: unable to unmarshall SPOOL_Q_SETJOB.\n"));
685                 return False;
686         }
687
688         r_u.status = _spoolss_setjob(p, &q_u, &r_u);
689
690         if(!spoolss_io_r_setjob("",&r_u,rdata,0)) {
691                 DEBUG(0,("spoolss_io_r_setjob: unable to marshall SPOOL_R_SETJOB.\n"));
692                 return False;
693         }
694
695         return True;
696 }
697
698 /****************************************************************************
699 ****************************************************************************/
700
701 static bool api_spoolss_enumprinterdrivers(pipes_struct *p)
702 {
703         SPOOL_Q_ENUMPRINTERDRIVERS q_u;
704         SPOOL_R_ENUMPRINTERDRIVERS r_u;
705         prs_struct *data = &p->in_data.data;
706         prs_struct *rdata = &p->out_data.rdata;
707
708         ZERO_STRUCT(q_u);
709         ZERO_STRUCT(r_u);
710
711         if (!spoolss_io_q_enumprinterdrivers("", &q_u, data, 0)) {
712                 DEBUG(0,("spoolss_io_q_enumprinterdrivers: unable to unmarshall SPOOL_Q_ENUMPRINTERDRIVERS.\n"));
713                 return False;
714         }
715
716         r_u.status = _spoolss_enumprinterdrivers(p, &q_u, &r_u);
717
718         if (!spoolss_io_r_enumprinterdrivers("",&r_u,rdata,0)) {
719                 DEBUG(0,("spoolss_io_r_enumprinterdrivers: unable to marshall SPOOL_R_ENUMPRINTERDRIVERS.\n"));
720                 return False;
721         }
722
723         return True;
724 }
725
726 /****************************************************************************
727 ****************************************************************************/
728
729 static bool api_spoolss_getform(pipes_struct *p)
730 {
731         SPOOL_Q_GETFORM q_u;
732         SPOOL_R_GETFORM r_u;
733         prs_struct *data = &p->in_data.data;
734         prs_struct *rdata = &p->out_data.rdata;
735
736         ZERO_STRUCT(q_u);
737         ZERO_STRUCT(r_u);
738
739         if (!spoolss_io_q_getform("", &q_u, data, 0)) {
740                 DEBUG(0,("spoolss_io_q_getform: unable to unmarshall SPOOL_Q_GETFORM.\n"));
741                 return False;
742         }
743
744         r_u.status = _spoolss_getform(p, &q_u, &r_u);
745
746         if (!spoolss_io_r_getform("",&r_u,rdata,0)) {
747                 DEBUG(0,("spoolss_io_r_getform: unable to marshall SPOOL_R_GETFORM.\n"));
748                 return False;
749         }
750
751         return True;
752 }
753
754 /****************************************************************************
755 ****************************************************************************/
756
757 static bool api_spoolss_enumforms(pipes_struct *p)
758 {
759         SPOOL_Q_ENUMFORMS q_u;
760         SPOOL_R_ENUMFORMS r_u;
761         prs_struct *data = &p->in_data.data;
762         prs_struct *rdata = &p->out_data.rdata;
763
764         ZERO_STRUCT(q_u);
765         ZERO_STRUCT(r_u);
766
767         if (!spoolss_io_q_enumforms("", &q_u, data, 0)) {
768                 DEBUG(0,("spoolss_io_q_enumforms: unable to unmarshall SPOOL_Q_ENUMFORMS.\n"));
769                 return False;
770         }
771
772         r_u.status = _spoolss_enumforms(p, &q_u, &r_u);
773
774         if (!spoolss_io_r_enumforms("",&r_u,rdata,0)) {
775                 DEBUG(0,("spoolss_io_r_enumforms: unable to marshall SPOOL_R_ENUMFORMS.\n"));
776                 return False;
777         }
778
779         return True;
780 }
781
782 /****************************************************************************
783 ****************************************************************************/
784
785 static bool api_spoolss_enumports(pipes_struct *p)
786 {
787         SPOOL_Q_ENUMPORTS q_u;
788         SPOOL_R_ENUMPORTS r_u;
789         prs_struct *data = &p->in_data.data;
790         prs_struct *rdata = &p->out_data.rdata;
791
792         ZERO_STRUCT(q_u);
793         ZERO_STRUCT(r_u);
794
795         if(!spoolss_io_q_enumports("", &q_u, data, 0)) {
796                 DEBUG(0,("spoolss_io_q_enumports: unable to unmarshall SPOOL_Q_ENUMPORTS.\n"));
797                 return False;
798         }
799
800         r_u.status = _spoolss_enumports(p, &q_u, &r_u);
801
802         if (!spoolss_io_r_enumports("",&r_u,rdata,0)) {
803                 DEBUG(0,("spoolss_io_r_enumports: unable to marshall SPOOL_R_ENUMPORTS.\n"));
804                 return False;
805         }
806
807         return True;
808 }
809
810 /****************************************************************************
811 ****************************************************************************/
812
813 static bool api_spoolss_addprinterex(pipes_struct *p)
814 {
815         SPOOL_Q_ADDPRINTEREX q_u;
816         SPOOL_R_ADDPRINTEREX r_u;
817         prs_struct *data = &p->in_data.data;
818         prs_struct *rdata = &p->out_data.rdata;
819         
820         ZERO_STRUCT(q_u);
821         ZERO_STRUCT(r_u);
822         
823         if(!spoolss_io_q_addprinterex("", &q_u, data, 0)) {
824                 DEBUG(0,("spoolss_io_q_addprinterex: unable to unmarshall SPOOL_Q_ADDPRINTEREX.\n"));
825                 return False;
826         }
827         
828         r_u.status = _spoolss_addprinterex(p, &q_u, &r_u);
829                                 
830         if(!spoolss_io_r_addprinterex("", &r_u, rdata, 0)) {
831                 DEBUG(0,("spoolss_io_r_addprinterex: unable to marshall SPOOL_R_ADDPRINTEREX.\n"));
832                 return False;
833         }
834         
835         return True;
836 }
837
838 /****************************************************************************
839 ****************************************************************************/
840
841 static bool api_spoolss_addprinterdriver(pipes_struct *p)
842 {
843         SPOOL_Q_ADDPRINTERDRIVER q_u;
844         SPOOL_R_ADDPRINTERDRIVER r_u;
845         prs_struct *data = &p->in_data.data;
846         prs_struct *rdata = &p->out_data.rdata;
847         
848         ZERO_STRUCT(q_u);
849         ZERO_STRUCT(r_u);
850         
851         if(!spoolss_io_q_addprinterdriver("", &q_u, data, 0)) {
852                 if (q_u.level != 3 && q_u.level != 6) {
853                         /* Clever hack from Martin Zielinski <mz@seh.de>
854                          * to allow downgrade from level 8 (Vista).
855                          */
856                         DEBUG(3,("api_spoolss_addprinterdriver: unknown SPOOL_Q_ADDPRINTERDRIVER level %u.\n",
857                                 (unsigned int)q_u.level ));
858                         setup_fault_pdu(p, NT_STATUS(DCERPC_FAULT_INVALID_TAG));
859                         return True;
860                 }
861                 DEBUG(0,("spoolss_io_q_addprinterdriver: unable to unmarshall SPOOL_Q_ADDPRINTERDRIVER.\n"));
862                 return False;
863         }
864         
865         r_u.status = _spoolss_addprinterdriver(p, &q_u, &r_u);
866                                 
867         if(!spoolss_io_r_addprinterdriver("", &r_u, rdata, 0)) {
868                 DEBUG(0,("spoolss_io_r_addprinterdriver: unable to marshall SPOOL_R_ADDPRINTERDRIVER.\n"));
869                 return False;
870         }
871         
872         return True;
873 }
874
875 /****************************************************************************
876 ****************************************************************************/
877
878 static bool api_spoolss_getprinterdriverdirectory(pipes_struct *p)
879 {
880         SPOOL_Q_GETPRINTERDRIVERDIR q_u;
881         SPOOL_R_GETPRINTERDRIVERDIR r_u;
882         prs_struct *data = &p->in_data.data;
883         prs_struct *rdata = &p->out_data.rdata;
884
885         ZERO_STRUCT(q_u);
886         ZERO_STRUCT(r_u);
887
888         if(!spoolss_io_q_getprinterdriverdir("", &q_u, data, 0)) {
889                 DEBUG(0,("spoolss_io_q_getprinterdriverdir: unable to unmarshall SPOOL_Q_GETPRINTERDRIVERDIR.\n"));
890                 return False;
891         }
892
893         r_u.status = _spoolss_getprinterdriverdirectory(p, &q_u, &r_u);
894
895         if(!spoolss_io_r_getprinterdriverdir("", &r_u, rdata, 0)) {
896                 DEBUG(0,("spoolss_io_r_getprinterdriverdir: unable to marshall SPOOL_R_GETPRINTERDRIVERDIR.\n"));
897                 return False;
898         }
899
900         return True;
901 }
902
903 /****************************************************************************
904 ****************************************************************************/
905
906 static bool api_spoolss_enumprinterdata(pipes_struct *p)
907 {
908         SPOOL_Q_ENUMPRINTERDATA q_u;
909         SPOOL_R_ENUMPRINTERDATA r_u;
910         prs_struct *data = &p->in_data.data;
911         prs_struct *rdata = &p->out_data.rdata;
912         
913         ZERO_STRUCT(q_u);
914         ZERO_STRUCT(r_u);
915         
916         if(!spoolss_io_q_enumprinterdata("", &q_u, data, 0)) {
917                 DEBUG(0,("spoolss_io_q_enumprinterdata: unable to unmarshall SPOOL_Q_ENUMPRINTERDATA.\n"));
918                 return False;
919         }
920         
921         r_u.status = _spoolss_enumprinterdata(p, &q_u, &r_u);
922                                 
923         if(!spoolss_io_r_enumprinterdata("", &r_u, rdata, 0)) {
924                 DEBUG(0,("spoolss_io_r_enumprinterdata: unable to marshall SPOOL_R_ENUMPRINTERDATA.\n"));
925                 return False;
926         }
927
928         return True;
929 }
930
931 /****************************************************************************
932 ****************************************************************************/
933
934 static bool api_spoolss_setprinterdata(pipes_struct *p)
935 {
936         SPOOL_Q_SETPRINTERDATA q_u;
937         SPOOL_R_SETPRINTERDATA r_u;
938         prs_struct *data = &p->in_data.data;
939         prs_struct *rdata = &p->out_data.rdata;
940         
941         ZERO_STRUCT(q_u);
942         ZERO_STRUCT(r_u);
943         
944         if(!spoolss_io_q_setprinterdata("", &q_u, data, 0)) {
945                 DEBUG(0,("spoolss_io_q_setprinterdata: unable to unmarshall SPOOL_Q_SETPRINTERDATA.\n"));
946                 return False;
947         }
948         
949         r_u.status = _spoolss_setprinterdata(p, &q_u, &r_u);
950                                 
951         if(!spoolss_io_r_setprinterdata("", &r_u, rdata, 0)) {
952                 DEBUG(0,("spoolss_io_r_setprinterdata: unable to marshall SPOOL_R_SETPRINTERDATA.\n"));
953                 return False;
954         }
955
956         return True;
957 }
958
959 /****************************************************************************
960 ****************************************************************************/
961 static bool api_spoolss_reset_printer(pipes_struct *p)
962 {
963         SPOOL_Q_RESETPRINTER q_u;
964         SPOOL_R_RESETPRINTER r_u;
965         prs_struct *data = &p->in_data.data;
966         prs_struct *rdata = &p->out_data.rdata;
967
968         ZERO_STRUCT(q_u);
969         ZERO_STRUCT(r_u);
970
971         if(!spoolss_io_q_resetprinter("", &q_u, data, 0)) {
972                 DEBUG(0,("spoolss_io_q_setprinterdata: unable to unmarshall SPOOL_Q_SETPRINTERDATA.\n"));
973                 return False;
974         }
975         
976         r_u.status = _spoolss_resetprinter(p, &q_u, &r_u);
977
978         if(!spoolss_io_r_resetprinter("", &r_u, rdata, 0)) {
979                 DEBUG(0,("spoolss_io_r_setprinterdata: unable to marshall SPOOL_R_RESETPRINTER.\n"));
980                 return False;
981         }
982
983         return True;
984 }
985
986 /****************************************************************************
987 ****************************************************************************/
988 static bool api_spoolss_addform(pipes_struct *p)
989 {
990         SPOOL_Q_ADDFORM q_u;
991         SPOOL_R_ADDFORM r_u;
992         prs_struct *data = &p->in_data.data;
993         prs_struct *rdata = &p->out_data.rdata;
994
995         ZERO_STRUCT(q_u);
996         ZERO_STRUCT(r_u);
997         
998         if(!spoolss_io_q_addform("", &q_u, data, 0)) {
999                 DEBUG(0,("spoolss_io_q_addform: unable to unmarshall SPOOL_Q_ADDFORM.\n"));
1000                 return False;
1001         }
1002         
1003         r_u.status = _spoolss_addform(p, &q_u, &r_u);
1004         
1005         if(!spoolss_io_r_addform("", &r_u, rdata, 0)) {
1006                 DEBUG(0,("spoolss_io_r_addform: unable to marshall SPOOL_R_ADDFORM.\n"));
1007                 return False;
1008         }
1009
1010         return True;
1011 }
1012
1013 /****************************************************************************
1014 ****************************************************************************/
1015
1016 static bool api_spoolss_deleteform(pipes_struct *p)
1017 {
1018         SPOOL_Q_DELETEFORM q_u;
1019         SPOOL_R_DELETEFORM r_u;
1020         prs_struct *data = &p->in_data.data;
1021         prs_struct *rdata = &p->out_data.rdata;
1022
1023         ZERO_STRUCT(q_u);
1024         ZERO_STRUCT(r_u);
1025         
1026         if(!spoolss_io_q_deleteform("", &q_u, data, 0)) {
1027                 DEBUG(0,("spoolss_io_q_deleteform: unable to unmarshall SPOOL_Q_DELETEFORM.\n"));
1028                 return False;
1029         }
1030         
1031         r_u.status = _spoolss_deleteform(p, &q_u, &r_u);
1032         
1033         if(!spoolss_io_r_deleteform("", &r_u, rdata, 0)) {
1034                 DEBUG(0,("spoolss_io_r_deleteform: unable to marshall SPOOL_R_DELETEFORM.\n"));
1035                 return False;
1036         }
1037
1038         return True;
1039 }
1040
1041 /****************************************************************************
1042 ****************************************************************************/
1043
1044 static bool api_spoolss_setform(pipes_struct *p)
1045 {
1046         SPOOL_Q_SETFORM q_u;
1047         SPOOL_R_SETFORM r_u;
1048         prs_struct *data = &p->in_data.data;
1049         prs_struct *rdata = &p->out_data.rdata;
1050
1051         ZERO_STRUCT(q_u);
1052         ZERO_STRUCT(r_u);
1053         
1054         if(!spoolss_io_q_setform("", &q_u, data, 0)) {
1055                 DEBUG(0,("spoolss_io_q_setform: unable to unmarshall SPOOL_Q_SETFORM.\n"));
1056                 return False;
1057         }
1058         
1059         r_u.status = _spoolss_setform(p, &q_u, &r_u);
1060                                       
1061         if(!spoolss_io_r_setform("", &r_u, rdata, 0)) {
1062                 DEBUG(0,("spoolss_io_r_setform: unable to marshall SPOOL_R_SETFORM.\n"));
1063                 return False;
1064         }
1065
1066         return True;
1067 }
1068
1069 /****************************************************************************
1070 ****************************************************************************/
1071
1072 static bool api_spoolss_enumprintprocessors(pipes_struct *p)
1073 {
1074         SPOOL_Q_ENUMPRINTPROCESSORS q_u;
1075         SPOOL_R_ENUMPRINTPROCESSORS r_u;
1076         prs_struct *data = &p->in_data.data;
1077         prs_struct *rdata = &p->out_data.rdata;
1078
1079         ZERO_STRUCT(q_u);
1080         ZERO_STRUCT(r_u);
1081         
1082         if(!spoolss_io_q_enumprintprocessors("", &q_u, data, 0)) {
1083                 DEBUG(0,("spoolss_io_q_enumprintprocessors: unable to unmarshall SPOOL_Q_ENUMPRINTPROCESSORS.\n"));
1084                 return False;
1085         }
1086         
1087         r_u.status = _spoolss_enumprintprocessors(p, &q_u, &r_u);
1088
1089         if(!spoolss_io_r_enumprintprocessors("", &r_u, rdata, 0)) {
1090                 DEBUG(0,("spoolss_io_r_enumprintprocessors: unable to marshall SPOOL_R_ENUMPRINTPROCESSORS.\n"));
1091                 return False;
1092         }
1093         
1094         return True;
1095 }
1096
1097 /****************************************************************************
1098 ****************************************************************************/
1099
1100 static bool api_spoolss_addprintprocessor(pipes_struct *p)
1101 {
1102         SPOOL_Q_ADDPRINTPROCESSOR q_u;
1103         SPOOL_R_ADDPRINTPROCESSOR r_u;
1104         prs_struct *data = &p->in_data.data;
1105         prs_struct *rdata = &p->out_data.rdata;
1106
1107         ZERO_STRUCT(q_u);
1108         ZERO_STRUCT(r_u);
1109         
1110         if(!spoolss_io_q_addprintprocessor("", &q_u, data, 0)) {
1111                 DEBUG(0,("spoolss_io_q_addprintprocessor: unable to unmarshall SPOOL_Q_ADDPRINTPROCESSOR.\n"));
1112                 return False;
1113         }
1114         
1115         /* for now, just indicate success and ignore the add.  We'll
1116            automatically set the winprint processor for printer
1117            entries later.  Used to debug the LexMark Optra S 1855 PCL
1118            driver --jerry */
1119         r_u.status = WERR_OK;
1120
1121         if(!spoolss_io_r_addprintprocessor("", &r_u, rdata, 0)) {
1122                 DEBUG(0,("spoolss_io_r_addprintprocessor: unable to marshall SPOOL_R_ADDPRINTPROCESSOR.\n"));
1123                 return False;
1124         }
1125         
1126         return True;
1127 }
1128
1129 /****************************************************************************
1130 ****************************************************************************/
1131
1132 static bool api_spoolss_enumprintprocdatatypes(pipes_struct *p)
1133 {
1134         SPOOL_Q_ENUMPRINTPROCDATATYPES q_u;
1135         SPOOL_R_ENUMPRINTPROCDATATYPES r_u;
1136         prs_struct *data = &p->in_data.data;
1137         prs_struct *rdata = &p->out_data.rdata;
1138
1139         ZERO_STRUCT(q_u);
1140         ZERO_STRUCT(r_u);
1141         
1142         if(!spoolss_io_q_enumprintprocdatatypes("", &q_u, data, 0)) {
1143                 DEBUG(0,("spoolss_io_q_enumprintprocdatatypes: unable to unmarshall SPOOL_Q_ENUMPRINTPROCDATATYPES.\n"));
1144                 return False;
1145         }
1146         
1147         r_u.status = _spoolss_enumprintprocdatatypes(p, &q_u, &r_u);
1148
1149         if(!spoolss_io_r_enumprintprocdatatypes("", &r_u, rdata, 0)) {
1150                 DEBUG(0,("spoolss_io_r_enumprintprocdatatypes: unable to marshall SPOOL_R_ENUMPRINTPROCDATATYPES.\n"));
1151                 return False;
1152         }
1153         
1154         return True;
1155 }
1156
1157 /****************************************************************************
1158 ****************************************************************************/
1159
1160 static bool api_spoolss_enumprintmonitors(pipes_struct *p)
1161 {
1162         SPOOL_Q_ENUMPRINTMONITORS q_u;
1163         SPOOL_R_ENUMPRINTMONITORS r_u;
1164         prs_struct *data = &p->in_data.data;
1165         prs_struct *rdata = &p->out_data.rdata;
1166
1167         ZERO_STRUCT(q_u);
1168         ZERO_STRUCT(r_u);
1169         
1170         if (!spoolss_io_q_enumprintmonitors("", &q_u, data, 0)) {
1171                 DEBUG(0,("spoolss_io_q_enumprintmonitors: unable to unmarshall SPOOL_Q_ENUMPRINTMONITORS.\n"));
1172                 return False;
1173         }
1174                 
1175         r_u.status = _spoolss_enumprintmonitors(p, &q_u, &r_u);
1176
1177         if (!spoolss_io_r_enumprintmonitors("", &r_u, rdata, 0)) {
1178                 DEBUG(0,("spoolss_io_r_enumprintmonitors: unable to marshall SPOOL_R_ENUMPRINTMONITORS.\n"));
1179                 return False;
1180         }
1181         
1182         return True;
1183 }
1184
1185 /****************************************************************************
1186 ****************************************************************************/
1187
1188 static bool api_spoolss_getjob(pipes_struct *p)
1189 {
1190         SPOOL_Q_GETJOB q_u;
1191         SPOOL_R_GETJOB r_u;
1192         prs_struct *data = &p->in_data.data;
1193         prs_struct *rdata = &p->out_data.rdata;
1194         
1195         ZERO_STRUCT(q_u);
1196         ZERO_STRUCT(r_u);
1197         
1198         if(!spoolss_io_q_getjob("", &q_u, data, 0)) {
1199                 DEBUG(0,("spoolss_io_q_getjob: unable to unmarshall SPOOL_Q_GETJOB.\n"));
1200                 return False;
1201         }
1202
1203         r_u.status = _spoolss_getjob(p, &q_u, &r_u);
1204         
1205         if(!spoolss_io_r_getjob("",&r_u,rdata,0)) {
1206                 DEBUG(0,("spoolss_io_r_getjob: unable to marshall SPOOL_R_GETJOB.\n"));
1207                 return False;
1208         }
1209                 
1210         return True;
1211 }
1212
1213 /********************************************************************
1214  * api_spoolss_getprinterdataex
1215  *
1216  * called from the spoolss dispatcher
1217  ********************************************************************/
1218
1219 static bool api_spoolss_getprinterdataex(pipes_struct *p)
1220 {
1221         SPOOL_Q_GETPRINTERDATAEX q_u;
1222         SPOOL_R_GETPRINTERDATAEX r_u;
1223         prs_struct *data = &p->in_data.data;
1224         prs_struct *rdata = &p->out_data.rdata;
1225
1226         ZERO_STRUCT(q_u);
1227         ZERO_STRUCT(r_u);
1228
1229         /* read the stream and fill the struct */
1230         if (!spoolss_io_q_getprinterdataex("", &q_u, data, 0)) {
1231                 DEBUG(0,("spoolss_io_q_getprinterdataex: unable to unmarshall SPOOL_Q_GETPRINTERDATAEX.\n"));
1232                 return False;
1233         }
1234         
1235         r_u.status = _spoolss_getprinterdataex( p, &q_u, &r_u);
1236
1237         if (!spoolss_io_r_getprinterdataex("", &r_u, rdata, 0)) {
1238                 DEBUG(0,("spoolss_io_r_getprinterdataex: unable to marshall SPOOL_R_GETPRINTERDATAEX.\n"));
1239                 return False;
1240         }
1241
1242         return True;
1243 }
1244
1245 /****************************************************************************
1246 ****************************************************************************/
1247
1248 static bool api_spoolss_setprinterdataex(pipes_struct *p)
1249 {
1250         SPOOL_Q_SETPRINTERDATAEX q_u;
1251         SPOOL_R_SETPRINTERDATAEX r_u;
1252         prs_struct *data = &p->in_data.data;
1253         prs_struct *rdata = &p->out_data.rdata;
1254         
1255         ZERO_STRUCT(q_u);
1256         ZERO_STRUCT(r_u);
1257         
1258         if(!spoolss_io_q_setprinterdataex("", &q_u, data, 0)) {
1259                 DEBUG(0,("spoolss_io_q_setprinterdataex: unable to unmarshall SPOOL_Q_SETPRINTERDATAEX.\n"));
1260                 return False;
1261         }
1262         
1263         r_u.status = _spoolss_setprinterdataex(p, &q_u, &r_u);
1264                                 
1265         if(!spoolss_io_r_setprinterdataex("", &r_u, rdata, 0)) {
1266                 DEBUG(0,("spoolss_io_r_setprinterdataex: unable to marshall SPOOL_R_SETPRINTERDATAEX.\n"));
1267                 return False;
1268         }
1269
1270         return True;
1271 }
1272
1273
1274 /****************************************************************************
1275 ****************************************************************************/
1276
1277 static bool api_spoolss_enumprinterkey(pipes_struct *p)
1278 {
1279         SPOOL_Q_ENUMPRINTERKEY q_u;
1280         SPOOL_R_ENUMPRINTERKEY r_u;
1281         prs_struct *data = &p->in_data.data;
1282         prs_struct *rdata = &p->out_data.rdata;
1283         
1284         ZERO_STRUCT(q_u);
1285         ZERO_STRUCT(r_u);
1286         
1287         if(!spoolss_io_q_enumprinterkey("", &q_u, data, 0)) {
1288                 DEBUG(0,("spoolss_io_q_setprinterkey: unable to unmarshall SPOOL_Q_ENUMPRINTERKEY.\n"));
1289                 return False;
1290         }
1291         
1292         r_u.status = _spoolss_enumprinterkey(p, &q_u, &r_u);
1293                                 
1294         if(!spoolss_io_r_enumprinterkey("", &r_u, rdata, 0)) {
1295                 DEBUG(0,("spoolss_io_r_enumprinterkey: unable to marshall SPOOL_R_ENUMPRINTERKEY.\n"));
1296                 return False;
1297         }
1298
1299         return True;
1300 }
1301
1302 /****************************************************************************
1303 ****************************************************************************/
1304
1305 static bool api_spoolss_enumprinterdataex(pipes_struct *p)
1306 {
1307         SPOOL_Q_ENUMPRINTERDATAEX q_u;
1308         SPOOL_R_ENUMPRINTERDATAEX r_u;
1309         prs_struct *data = &p->in_data.data;
1310         prs_struct *rdata = &p->out_data.rdata;
1311         
1312         ZERO_STRUCT(q_u);
1313         ZERO_STRUCT(r_u);
1314         
1315         if(!spoolss_io_q_enumprinterdataex("", &q_u, data, 0)) {
1316                 DEBUG(0,("spoolss_io_q_enumprinterdataex: unable to unmarshall SPOOL_Q_ENUMPRINTERDATAEX.\n"));
1317                 return False;
1318         }
1319         
1320         r_u.status = _spoolss_enumprinterdataex(p, &q_u, &r_u);
1321                                 
1322         if(!spoolss_io_r_enumprinterdataex("", &r_u, rdata, 0)) {
1323                 DEBUG(0,("spoolss_io_r_enumprinterdataex: unable to marshall SPOOL_R_ENUMPRINTERDATAEX.\n"));
1324                 return False;
1325         }
1326
1327         return True;
1328 }
1329
1330 /****************************************************************************
1331 ****************************************************************************/
1332
1333 static bool api_spoolss_getprintprocessordirectory(pipes_struct *p)
1334 {
1335         SPOOL_Q_GETPRINTPROCESSORDIRECTORY q_u;
1336         SPOOL_R_GETPRINTPROCESSORDIRECTORY r_u;
1337         prs_struct *data = &p->in_data.data;
1338         prs_struct *rdata = &p->out_data.rdata;
1339         
1340         ZERO_STRUCT(q_u);
1341         ZERO_STRUCT(r_u);
1342         
1343         if(!spoolss_io_q_getprintprocessordirectory("", &q_u, data, 0)) {
1344                 DEBUG(0,("spoolss_io_q_getprintprocessordirectory: unable to unmarshall SPOOL_Q_GETPRINTPROCESSORDIRECTORY.\n"));
1345                 return False;
1346         }
1347         
1348         r_u.status = _spoolss_getprintprocessordirectory(p, &q_u, &r_u);
1349                                 
1350         if(!spoolss_io_r_getprintprocessordirectory("", &r_u, rdata, 0)) {
1351                 DEBUG(0,("spoolss_io_r_getprintprocessordirectory: unable to marshall SPOOL_R_GETPRINTPROCESSORDIRECTORY.\n"));
1352                 return False;
1353         }
1354         
1355         return True;
1356 }
1357
1358 /****************************************************************************
1359 ****************************************************************************/
1360
1361 static bool api_spoolss_deleteprinterdataex(pipes_struct *p)
1362 {
1363         SPOOL_Q_DELETEPRINTERDATAEX q_u;
1364         SPOOL_R_DELETEPRINTERDATAEX r_u;
1365         prs_struct *data = &p->in_data.data;
1366         prs_struct *rdata = &p->out_data.rdata;
1367         
1368         ZERO_STRUCT(q_u);
1369         ZERO_STRUCT(r_u);
1370         
1371         if(!spoolss_io_q_deleteprinterdataex("", &q_u, data, 0)) {
1372                 DEBUG(0,("spoolss_io_q_deleteprinterdataex: unable to unmarshall SPOOL_Q_DELETEPRINTERDATAEX.\n"));
1373                 return False;
1374         }
1375         
1376         r_u.status = _spoolss_deleteprinterdataex(p, &q_u, &r_u);
1377                                 
1378         if(!spoolss_io_r_deleteprinterdataex("", &r_u, rdata, 0)) {
1379                 DEBUG(0,("spoolss_io_r_deleteprinterdataex: unable to marshall SPOOL_R_DELETEPRINTERDATAEX.\n"));
1380                 return False;
1381         }
1382         
1383         return True;
1384 }
1385
1386 /****************************************************************************
1387 ****************************************************************************/
1388
1389 static bool api_spoolss_deleteprinterkey(pipes_struct *p)
1390 {
1391         SPOOL_Q_DELETEPRINTERKEY q_u;
1392         SPOOL_R_DELETEPRINTERKEY r_u;
1393         prs_struct *data = &p->in_data.data;
1394         prs_struct *rdata = &p->out_data.rdata;
1395         
1396         ZERO_STRUCT(q_u);
1397         ZERO_STRUCT(r_u);
1398         
1399         if(!spoolss_io_q_deleteprinterkey("", &q_u, data, 0)) {
1400                 DEBUG(0,("spoolss_io_q_deleteprinterkey: unable to unmarshall SPOOL_Q_DELETEPRINTERKEY.\n"));
1401                 return False;
1402         }
1403         
1404         r_u.status = _spoolss_deleteprinterkey(p, &q_u, &r_u);
1405                                 
1406         if(!spoolss_io_r_deleteprinterkey("", &r_u, rdata, 0)) {
1407                 DEBUG(0,("spoolss_io_r_deleteprinterkey: unable to marshall SPOOL_R_DELETEPRINTERKEY.\n"));
1408                 return False;
1409         }
1410         
1411         return True;
1412 }
1413
1414 /****************************************************************************
1415 ****************************************************************************/
1416
1417 static bool api_spoolss_addprinterdriverex(pipes_struct *p)
1418 {
1419         SPOOL_Q_ADDPRINTERDRIVEREX q_u;
1420         SPOOL_R_ADDPRINTERDRIVEREX r_u;
1421         prs_struct *data = &p->in_data.data;
1422         prs_struct *rdata = &p->out_data.rdata;
1423         
1424         ZERO_STRUCT(q_u);
1425         ZERO_STRUCT(r_u);
1426         
1427         if(!spoolss_io_q_addprinterdriverex("", &q_u, data, 0)) {
1428                 if (q_u.level != 3 && q_u.level != 6) {
1429                         /* Clever hack from Martin Zielinski <mz@seh.de>
1430                          * to allow downgrade from level 8 (Vista).
1431                          */
1432                         DEBUG(3,("api_spoolss_addprinterdriverex: unknown SPOOL_Q_ADDPRINTERDRIVEREX level %u.\n",
1433                                 (unsigned int)q_u.level ));
1434                         setup_fault_pdu(p, NT_STATUS(DCERPC_FAULT_INVALID_TAG));
1435                         return True;
1436                 }
1437                 DEBUG(0,("spoolss_io_q_addprinterdriverex: unable to unmarshall SPOOL_Q_ADDPRINTERDRIVEREX.\n"));
1438                 return False;
1439         }
1440         
1441         r_u.status = _spoolss_addprinterdriverex(p, &q_u, &r_u);
1442                                 
1443         if(!spoolss_io_r_addprinterdriverex("", &r_u, rdata, 0)) {
1444                 DEBUG(0,("spoolss_io_r_addprinterdriverex: unable to marshall SPOOL_R_ADDPRINTERDRIVEREX.\n"));
1445                 return False;
1446         }
1447         
1448         return True;
1449 }
1450
1451 /****************************************************************************
1452 ****************************************************************************/
1453
1454 static bool api_spoolss_deleteprinterdriverex(pipes_struct *p)
1455 {
1456         SPOOL_Q_DELETEPRINTERDRIVEREX q_u;
1457         SPOOL_R_DELETEPRINTERDRIVEREX r_u;
1458         prs_struct *data = &p->in_data.data;
1459         prs_struct *rdata = &p->out_data.rdata;
1460         
1461         ZERO_STRUCT(q_u);
1462         ZERO_STRUCT(r_u);
1463         
1464         if(!spoolss_io_q_deleteprinterdriverex("", &q_u, data, 0)) {
1465                 DEBUG(0,("spoolss_io_q_deleteprinterdriverex: unable to unmarshall SPOOL_Q_DELETEPRINTERDRIVEREX.\n"));
1466                 return False;
1467         }
1468         
1469         r_u.status = _spoolss_deleteprinterdriverex(p, &q_u, &r_u);
1470                                 
1471         if(!spoolss_io_r_deleteprinterdriverex("", &r_u, rdata, 0)) {
1472                 DEBUG(0,("spoolss_io_r_deleteprinterdriverex: unable to marshall SPOOL_R_DELETEPRINTERDRIVEREX.\n"));
1473                 return False;
1474         }
1475         
1476         return True;
1477 }
1478
1479 /****************************************************************************
1480 ****************************************************************************/
1481
1482 static bool api_spoolss_xcvdataport(pipes_struct *p)
1483 {
1484         SPOOL_Q_XCVDATAPORT q_u;
1485         SPOOL_R_XCVDATAPORT r_u;
1486         prs_struct *data = &p->in_data.data;
1487         prs_struct *rdata = &p->out_data.rdata;
1488         
1489         ZERO_STRUCT(q_u);
1490         ZERO_STRUCT(r_u);
1491         
1492         if(!spoolss_io_q_xcvdataport("", &q_u, data, 0)) {
1493                 DEBUG(0,("spoolss_io_q_replyopenprinter: unable to unmarshall SPOOL_Q_XCVDATAPORT.\n"));
1494                 return False;
1495         }
1496         
1497         r_u.status = _spoolss_xcvdataport(p, &q_u, &r_u);
1498                                 
1499         if(!spoolss_io_r_xcvdataport("", &r_u, rdata, 0)) {
1500                 DEBUG(0,("spoolss_io_r_replyopenprinter: unable to marshall SPOOL_R_XCVDATAPORT.\n"));
1501                 return False;
1502         }
1503         
1504         return True;
1505 }
1506
1507 /*******************************************************************
1508 \pipe\spoolss commands
1509 ********************************************************************/
1510
1511   struct api_struct api_spoolss_cmds[] = 
1512     {
1513  {"SPOOLSS_OPENPRINTER",               SPOOLSS_OPENPRINTER,               api_spoolss_open_printer              },
1514  {"SPOOLSS_OPENPRINTEREX",             SPOOLSS_OPENPRINTEREX,             api_spoolss_open_printer_ex           },
1515  {"SPOOLSS_GETPRINTERDATA",            SPOOLSS_GETPRINTERDATA,            api_spoolss_getprinterdata            },
1516  {"SPOOLSS_CLOSEPRINTER",              SPOOLSS_CLOSEPRINTER,              api_spoolss_closeprinter              },
1517  {"SPOOLSS_DELETEPRINTER",             SPOOLSS_DELETEPRINTER,             api_spoolss_deleteprinter             },
1518  {"SPOOLSS_ABORTPRINTER",              SPOOLSS_ABORTPRINTER,              api_spoolss_abortprinter              },
1519  {"SPOOLSS_RFFPCNEX",                  SPOOLSS_RFFPCNEX,                  api_spoolss_rffpcnex                  },
1520  {"SPOOLSS_RFNPCNEX",                  SPOOLSS_RFNPCNEX,                  api_spoolss_rfnpcnex                  },
1521  {"SPOOLSS_ENUMPRINTERS",              SPOOLSS_ENUMPRINTERS,              api_spoolss_enumprinters              },
1522  {"SPOOLSS_GETPRINTER",                SPOOLSS_GETPRINTER,                api_spoolss_getprinter                },
1523  {"SPOOLSS_GETPRINTERDRIVER2",         SPOOLSS_GETPRINTERDRIVER2,         api_spoolss_getprinterdriver2         }, 
1524  {"SPOOLSS_STARTPAGEPRINTER",          SPOOLSS_STARTPAGEPRINTER,          api_spoolss_startpageprinter          },
1525  {"SPOOLSS_ENDPAGEPRINTER",            SPOOLSS_ENDPAGEPRINTER,            api_spoolss_endpageprinter            }, 
1526  {"SPOOLSS_STARTDOCPRINTER",           SPOOLSS_STARTDOCPRINTER,           api_spoolss_startdocprinter           },
1527  {"SPOOLSS_ENDDOCPRINTER",             SPOOLSS_ENDDOCPRINTER,             api_spoolss_enddocprinter             },
1528  {"SPOOLSS_WRITEPRINTER",              SPOOLSS_WRITEPRINTER,              api_spoolss_writeprinter              },
1529  {"SPOOLSS_SETPRINTER",                SPOOLSS_SETPRINTER,                api_spoolss_setprinter                },
1530  {"SPOOLSS_FCPN",                      SPOOLSS_FCPN,                      api_spoolss_fcpn                      },
1531  {"SPOOLSS_ADDJOB",                    SPOOLSS_ADDJOB,                    api_spoolss_addjob                    },
1532  {"SPOOLSS_ENUMJOBS",                  SPOOLSS_ENUMJOBS,                  api_spoolss_enumjobs                  },
1533  {"SPOOLSS_SCHEDULEJOB",               SPOOLSS_SCHEDULEJOB,               api_spoolss_schedulejob               },
1534  {"SPOOLSS_SETJOB",                    SPOOLSS_SETJOB,                    api_spoolss_setjob                    },
1535  {"SPOOLSS_ENUMFORMS",                 SPOOLSS_ENUMFORMS,                 api_spoolss_enumforms                 },
1536  {"SPOOLSS_ENUMPORTS",                 SPOOLSS_ENUMPORTS,                 api_spoolss_enumports                 },
1537  {"SPOOLSS_ENUMPRINTERDRIVERS",        SPOOLSS_ENUMPRINTERDRIVERS,        api_spoolss_enumprinterdrivers        },
1538  {"SPOOLSS_ADDPRINTEREX",              SPOOLSS_ADDPRINTEREX,              api_spoolss_addprinterex              },
1539  {"SPOOLSS_ADDPRINTERDRIVER",          SPOOLSS_ADDPRINTERDRIVER,          api_spoolss_addprinterdriver          },
1540  {"SPOOLSS_DELETEPRINTERDRIVER",       SPOOLSS_DELETEPRINTERDRIVER,       api_spoolss_deleteprinterdriver       },
1541  {"SPOOLSS_GETPRINTERDRIVERDIRECTORY", SPOOLSS_GETPRINTERDRIVERDIRECTORY, api_spoolss_getprinterdriverdirectory },
1542  {"SPOOLSS_ENUMPRINTERDATA",           SPOOLSS_ENUMPRINTERDATA,           api_spoolss_enumprinterdata           },
1543  {"SPOOLSS_SETPRINTERDATA",            SPOOLSS_SETPRINTERDATA,            api_spoolss_setprinterdata            },
1544  {"SPOOLSS_RESETPRINTER",              SPOOLSS_RESETPRINTER,              api_spoolss_reset_printer             },
1545  {"SPOOLSS_DELETEPRINTERDATA",         SPOOLSS_DELETEPRINTERDATA,         api_spoolss_deleteprinterdata         },
1546  {"SPOOLSS_ADDFORM",                   SPOOLSS_ADDFORM,                   api_spoolss_addform                   },
1547  {"SPOOLSS_DELETEFORM",                SPOOLSS_DELETEFORM,                api_spoolss_deleteform                },
1548  {"SPOOLSS_GETFORM",                   SPOOLSS_GETFORM,                   api_spoolss_getform                   },
1549  {"SPOOLSS_SETFORM",                   SPOOLSS_SETFORM,                   api_spoolss_setform                   },
1550  {"SPOOLSS_ADDPRINTPROCESSOR",         SPOOLSS_ADDPRINTPROCESSOR,         api_spoolss_addprintprocessor         },
1551  {"SPOOLSS_ENUMPRINTPROCESSORS",       SPOOLSS_ENUMPRINTPROCESSORS,       api_spoolss_enumprintprocessors       },
1552  {"SPOOLSS_ENUMMONITORS",              SPOOLSS_ENUMMONITORS,              api_spoolss_enumprintmonitors         },
1553  {"SPOOLSS_GETJOB",                    SPOOLSS_GETJOB,                    api_spoolss_getjob                    },
1554  {"SPOOLSS_ENUMPRINTPROCDATATYPES",    SPOOLSS_ENUMPRINTPROCDATATYPES,    api_spoolss_enumprintprocdatatypes    },
1555  {"SPOOLSS_GETPRINTERDATAEX",          SPOOLSS_GETPRINTERDATAEX,          api_spoolss_getprinterdataex          },
1556  {"SPOOLSS_SETPRINTERDATAEX",          SPOOLSS_SETPRINTERDATAEX,          api_spoolss_setprinterdataex          },
1557  {"SPOOLSS_DELETEPRINTERDATAEX",       SPOOLSS_DELETEPRINTERDATAEX,       api_spoolss_deleteprinterdataex       },
1558  {"SPOOLSS_ENUMPRINTERDATAEX",         SPOOLSS_ENUMPRINTERDATAEX,         api_spoolss_enumprinterdataex         },
1559  {"SPOOLSS_ENUMPRINTERKEY",            SPOOLSS_ENUMPRINTERKEY,            api_spoolss_enumprinterkey            },
1560  {"SPOOLSS_DELETEPRINTERKEY",          SPOOLSS_DELETEPRINTERKEY,          api_spoolss_deleteprinterkey          },
1561  {"SPOOLSS_GETPRINTPROCESSORDIRECTORY",SPOOLSS_GETPRINTPROCESSORDIRECTORY,api_spoolss_getprintprocessordirectory},
1562  {"SPOOLSS_ADDPRINTERDRIVEREX",        SPOOLSS_ADDPRINTERDRIVEREX,        api_spoolss_addprinterdriverex        },
1563  {"SPOOLSS_DELETEPRINTERDRIVEREX",     SPOOLSS_DELETEPRINTERDRIVEREX,     api_spoolss_deleteprinterdriverex     },
1564  {"SPOOLSS_XCVDATAPORT",               SPOOLSS_XCVDATAPORT,               api_spoolss_xcvdataport               },
1565 };
1566
1567 void spoolss2_get_pipe_fns( struct api_struct **fns, int *n_fns )
1568 {
1569         *fns = api_spoolss_cmds;
1570         *n_fns = sizeof(api_spoolss_cmds) / sizeof(struct api_struct);
1571 }
1572
1573 NTSTATUS rpc_spoolss2_init(void)
1574 {
1575         return rpc_srv_register(
1576                 SMB_RPC_INTERFACE_VERSION, "spoolss", "spoolss",
1577                 &ndr_table_spoolss,
1578                 api_spoolss_cmds,
1579                 sizeof(api_spoolss_cmds) / sizeof(struct api_struct));
1580 }