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