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