s3-spoolss: use pidl for _spoolss_GetPrinterDriverDirectory.
[ira/wip.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         return proxy_spoolss_call(p, NDR_SPOOLSS_OPENPRINTER);
58 }
59
60 /********************************************************************
61  * api_spoolss_open_printer_ex
62  ********************************************************************/
63
64 static bool api_spoolss_open_printer_ex(pipes_struct *p)
65 {
66         return proxy_spoolss_call(p, NDR_SPOOLSS_OPENPRINTEREX);
67 }
68
69 /********************************************************************
70  * api_spoolss_getprinterdata
71  *
72  * called from the spoolss dispatcher
73  ********************************************************************/
74
75 static bool api_spoolss_getprinterdata(pipes_struct *p)
76 {
77         SPOOL_Q_GETPRINTERDATA q_u;
78         SPOOL_R_GETPRINTERDATA r_u;
79         prs_struct *data = &p->in_data.data;
80         prs_struct *rdata = &p->out_data.rdata;
81
82         ZERO_STRUCT(q_u);
83         ZERO_STRUCT(r_u);
84
85         /* read the stream and fill the struct */
86         if (!spoolss_io_q_getprinterdata("", &q_u, data, 0)) {
87                 DEBUG(0,("spoolss_io_q_getprinterdata: unable to unmarshall SPOOL_Q_GETPRINTERDATA.\n"));
88                 return False;
89         }
90         
91         r_u.status = _spoolss_getprinterdata( p, &q_u, &r_u);
92
93         if (!spoolss_io_r_getprinterdata("", &r_u, rdata, 0)) {
94                 DEBUG(0,("spoolss_io_r_getprinterdata: unable to marshall SPOOL_R_GETPRINTERDATA.\n"));
95                 return False;
96         }
97
98         return True;
99 }
100
101 /********************************************************************
102  * api_spoolss_deleteprinterdata
103  *
104  * called from the spoolss dispatcher
105  ********************************************************************/
106
107 static bool api_spoolss_deleteprinterdata(pipes_struct *p)
108 {
109         return proxy_spoolss_call(p, NDR_SPOOLSS_DELETEPRINTERDATA);
110 }
111
112 /********************************************************************
113  * api_spoolss_closeprinter
114  *
115  * called from the spoolss dispatcher
116  ********************************************************************/
117
118 static bool api_spoolss_closeprinter(pipes_struct *p)
119 {
120         return proxy_spoolss_call(p, NDR_SPOOLSS_CLOSEPRINTER);
121 }
122
123 /********************************************************************
124  * api_spoolss_abortprinter
125  *
126  * called from the spoolss dispatcher
127  ********************************************************************/
128
129 static bool api_spoolss_abortprinter(pipes_struct *p)
130 {
131         return proxy_spoolss_call(p, NDR_SPOOLSS_ABORTPRINTER);
132 }
133
134 /********************************************************************
135  * api_spoolss_deleteprinter
136  *
137  * called from the spoolss dispatcher
138  ********************************************************************/
139
140 static bool api_spoolss_deleteprinter(pipes_struct *p)
141 {
142         return proxy_spoolss_call(p, NDR_SPOOLSS_DELETEPRINTER);
143 }
144
145 /********************************************************************
146  * api_spoolss_deleteprinterdriver
147  *
148  * called from the spoolss dispatcher
149  ********************************************************************/
150
151 static bool api_spoolss_deleteprinterdriver(pipes_struct *p)
152 {
153         return proxy_spoolss_call(p, NDR_SPOOLSS_DELETEPRINTERDRIVER);
154 }
155
156
157 /********************************************************************
158  * api_spoolss_rffpcnex
159  * ReplyFindFirstPrinterChangeNotifyEx
160  ********************************************************************/
161
162 static bool api_spoolss_rffpcnex(pipes_struct *p)
163 {
164         SPOOL_Q_RFFPCNEX q_u;
165         SPOOL_R_RFFPCNEX r_u;
166         prs_struct *data = &p->in_data.data;
167         prs_struct *rdata = &p->out_data.rdata;
168
169         ZERO_STRUCT(q_u);
170         ZERO_STRUCT(r_u);
171
172         if (!spoolss_io_q_rffpcnex("", &q_u, data, 0)) {
173                 DEBUG(0,("spoolss_io_q_rffpcnex: unable to unmarshall SPOOL_Q_RFFPCNEX.\n"));
174                 return False;
175         }
176
177         r_u.status = _spoolss_rffpcnex(p, &q_u, &r_u);
178
179         if (!spoolss_io_r_rffpcnex("", &r_u, rdata, 0)) {
180                 DEBUG(0,("spoolss_io_r_rffpcnex: unable to marshall SPOOL_R_RFFPCNEX.\n"));
181                 return False;
182         }
183
184         return True;
185 }
186
187
188 /********************************************************************
189  * api_spoolss_rfnpcnex
190  * ReplyFindNextPrinterChangeNotifyEx
191  * called from the spoolss dispatcher
192
193  * Note - this is the *ONLY* function that breaks the RPC call
194  * symmetry in all the other calls. We need to do this to fix
195  * the massive memory allocation problem with thousands of jobs...
196  * JRA.
197  ********************************************************************/
198
199 static bool api_spoolss_rfnpcnex(pipes_struct *p)
200 {
201         SPOOL_Q_RFNPCNEX q_u;
202         SPOOL_R_RFNPCNEX r_u;
203         prs_struct *data = &p->in_data.data;
204         prs_struct *rdata = &p->out_data.rdata;
205
206         ZERO_STRUCT(q_u);
207         ZERO_STRUCT(r_u);
208
209         if (!spoolss_io_q_rfnpcnex("", &q_u, data, 0)) {
210                 DEBUG(0,("spoolss_io_q_rfnpcnex: unable to unmarshall SPOOL_Q_RFNPCNEX.\n"));
211                 return False;
212         }
213
214         r_u.status = _spoolss_rfnpcnex(p, &q_u, &r_u);
215
216         if (!spoolss_io_r_rfnpcnex("", &r_u, rdata, 0)) {
217                 SAFE_FREE(r_u.info.data);
218                 DEBUG(0,("spoolss_io_r_rfnpcnex: unable to marshall SPOOL_R_RFNPCNEX.\n"));
219                 return False;
220         }
221
222         SAFE_FREE(r_u.info.data);
223
224         return True;
225 }
226
227
228 /********************************************************************
229  * api_spoolss_enumprinters
230  * called from the spoolss dispatcher
231  *
232  ********************************************************************/
233
234 static bool api_spoolss_enumprinters(pipes_struct *p)
235 {
236         SPOOL_Q_ENUMPRINTERS q_u;
237         SPOOL_R_ENUMPRINTERS r_u;
238         prs_struct *data = &p->in_data.data;
239         prs_struct *rdata = &p->out_data.rdata;
240
241         ZERO_STRUCT(q_u);
242         ZERO_STRUCT(r_u);
243
244         if (!spoolss_io_q_enumprinters("", &q_u, data, 0)) {
245                 DEBUG(0,("spoolss_io_q_enumprinters: unable to unmarshall SPOOL_Q_ENUMPRINTERS.\n"));
246                 return False;
247         }
248
249         r_u.status = _spoolss_enumprinters( p, &q_u, &r_u);
250
251         if (!spoolss_io_r_enumprinters("", &r_u, rdata, 0)) {
252                 DEBUG(0,("spoolss_io_r_enumprinters: unable to marshall SPOOL_R_ENUMPRINTERS.\n"));
253                 return False;
254         }
255
256         return True;
257 }
258
259 /********************************************************************
260  * api_spoolss_getprinter
261  * called from the spoolss dispatcher
262  *
263  ********************************************************************/
264
265 static bool api_spoolss_getprinter(pipes_struct *p)
266 {
267         SPOOL_Q_GETPRINTER q_u;
268         SPOOL_R_GETPRINTER r_u;
269         prs_struct *data = &p->in_data.data;
270         prs_struct *rdata = &p->out_data.rdata;
271
272         ZERO_STRUCT(q_u);
273         ZERO_STRUCT(r_u);
274
275         if(!spoolss_io_q_getprinter("", &q_u, data, 0)) {
276                 DEBUG(0,("spoolss_io_q_getprinter: unable to unmarshall SPOOL_Q_GETPRINTER.\n"));
277                 return False;
278         }
279
280         r_u.status = _spoolss_getprinter(p, &q_u, &r_u);
281
282         if(!spoolss_io_r_getprinter("",&r_u,rdata,0)) {
283                 DEBUG(0,("spoolss_io_r_getprinter: unable to marshall SPOOL_R_GETPRINTER.\n"));
284                 return False;
285         }
286
287         return True;
288 }
289
290 /********************************************************************
291  * api_spoolss_getprinter
292  * called from the spoolss dispatcher
293  *
294  ********************************************************************/
295
296 static bool api_spoolss_getprinterdriver2(pipes_struct *p)
297 {
298         SPOOL_Q_GETPRINTERDRIVER2 q_u;
299         SPOOL_R_GETPRINTERDRIVER2 r_u;
300         prs_struct *data = &p->in_data.data;
301         prs_struct *rdata = &p->out_data.rdata;
302
303         ZERO_STRUCT(q_u);
304         ZERO_STRUCT(r_u);
305
306         if(!spoolss_io_q_getprinterdriver2("", &q_u, data, 0)) {
307                 DEBUG(0,("spoolss_io_q_getprinterdriver2: unable to unmarshall SPOOL_Q_GETPRINTERDRIVER2.\n"));
308                 return False;
309         }
310
311         r_u.status = _spoolss_getprinterdriver2(p, &q_u, &r_u);
312         
313         if(!spoolss_io_r_getprinterdriver2("",&r_u,rdata,0)) {
314                 DEBUG(0,("spoolss_io_r_getprinterdriver2: unable to marshall SPOOL_R_GETPRINTERDRIVER2.\n"));
315                 return False;
316         }
317         
318         return True;
319 }
320
321 /********************************************************************
322  * api_spoolss_getprinter
323  * called from the spoolss dispatcher
324  *
325  ********************************************************************/
326
327 static bool api_spoolss_startpageprinter(pipes_struct *p)
328 {
329         return proxy_spoolss_call(p, NDR_SPOOLSS_STARTPAGEPRINTER);
330 }
331
332 /********************************************************************
333  * api_spoolss_getprinter
334  * called from the spoolss dispatcher
335  *
336  ********************************************************************/
337
338 static bool api_spoolss_endpageprinter(pipes_struct *p)
339 {
340         return proxy_spoolss_call(p, NDR_SPOOLSS_ENDPAGEPRINTER);
341 }
342
343 /********************************************************************
344 ********************************************************************/
345
346 static bool api_spoolss_startdocprinter(pipes_struct *p)
347 {
348         return proxy_spoolss_call(p, NDR_SPOOLSS_STARTDOCPRINTER);
349 }
350
351 /********************************************************************
352 ********************************************************************/
353
354 static bool api_spoolss_enddocprinter(pipes_struct *p)
355 {
356         return proxy_spoolss_call(p, NDR_SPOOLSS_ENDDOCPRINTER);
357 }
358
359 /********************************************************************
360 ********************************************************************/
361
362 static bool api_spoolss_writeprinter(pipes_struct *p)
363 {
364         return proxy_spoolss_call(p, NDR_SPOOLSS_WRITEPRINTER);
365 }
366
367 /****************************************************************************
368
369 ****************************************************************************/
370
371 static bool api_spoolss_setprinter(pipes_struct *p)
372 {
373         return proxy_spoolss_call(p, NDR_SPOOLSS_SETPRINTER);
374 }
375
376 /****************************************************************************
377 ****************************************************************************/
378
379 static bool api_spoolss_fcpn(pipes_struct *p)
380 {
381         return proxy_spoolss_call(p, NDR_SPOOLSS_FINDCLOSEPRINTERNOTIFY);
382 }
383
384 /****************************************************************************
385 ****************************************************************************/
386
387 static bool api_spoolss_addjob(pipes_struct *p)
388 {
389         return proxy_spoolss_call(p, NDR_SPOOLSS_ADDJOB);
390 }
391
392 /****************************************************************************
393 ****************************************************************************/
394
395 static bool api_spoolss_enumjobs(pipes_struct *p)
396 {
397         SPOOL_Q_ENUMJOBS q_u;
398         SPOOL_R_ENUMJOBS r_u;
399         prs_struct *data = &p->in_data.data;
400         prs_struct *rdata = &p->out_data.rdata;
401
402         ZERO_STRUCT(q_u);
403         ZERO_STRUCT(r_u);
404
405         if (!spoolss_io_q_enumjobs("", &q_u, data, 0)) {
406                 DEBUG(0,("spoolss_io_q_enumjobs: unable to unmarshall SPOOL_Q_ENUMJOBS.\n"));
407                 return False;
408         }
409
410         r_u.status = _spoolss_enumjobs(p, &q_u, &r_u);
411
412         if (!spoolss_io_r_enumjobs("",&r_u,rdata,0)) {
413                 DEBUG(0,("spoolss_io_r_enumjobs: unable to marshall SPOOL_R_ENUMJOBS.\n"));
414                 return False;
415         }
416
417         return True;
418 }
419
420 /****************************************************************************
421 ****************************************************************************/
422
423 static bool api_spoolss_schedulejob(pipes_struct *p)
424 {
425         return proxy_spoolss_call(p, NDR_SPOOLSS_SCHEDULEJOB);
426 }
427
428 /****************************************************************************
429 ****************************************************************************/
430
431 static bool api_spoolss_setjob(pipes_struct *p)
432 {
433         return proxy_spoolss_call(p, NDR_SPOOLSS_SETJOB);
434 }
435
436 /****************************************************************************
437 ****************************************************************************/
438
439 static bool api_spoolss_enumprinterdrivers(pipes_struct *p)
440 {
441         SPOOL_Q_ENUMPRINTERDRIVERS q_u;
442         SPOOL_R_ENUMPRINTERDRIVERS 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_enumprinterdrivers("", &q_u, data, 0)) {
450                 DEBUG(0,("spoolss_io_q_enumprinterdrivers: unable to unmarshall SPOOL_Q_ENUMPRINTERDRIVERS.\n"));
451                 return False;
452         }
453
454         r_u.status = _spoolss_enumprinterdrivers(p, &q_u, &r_u);
455
456         if (!spoolss_io_r_enumprinterdrivers("",&r_u,rdata,0)) {
457                 DEBUG(0,("spoolss_io_r_enumprinterdrivers: unable to marshall SPOOL_R_ENUMPRINTERDRIVERS.\n"));
458                 return False;
459         }
460
461         return True;
462 }
463
464 /****************************************************************************
465 ****************************************************************************/
466
467 static bool api_spoolss_getform(pipes_struct *p)
468 {
469         return proxy_spoolss_call(p, NDR_SPOOLSS_GETFORM);
470 }
471
472 /****************************************************************************
473 ****************************************************************************/
474
475 static bool api_spoolss_enumforms(pipes_struct *p)
476 {
477         SPOOL_Q_ENUMFORMS q_u;
478         SPOOL_R_ENUMFORMS r_u;
479         prs_struct *data = &p->in_data.data;
480         prs_struct *rdata = &p->out_data.rdata;
481
482         ZERO_STRUCT(q_u);
483         ZERO_STRUCT(r_u);
484
485         if (!spoolss_io_q_enumforms("", &q_u, data, 0)) {
486                 DEBUG(0,("spoolss_io_q_enumforms: unable to unmarshall SPOOL_Q_ENUMFORMS.\n"));
487                 return False;
488         }
489
490         r_u.status = _spoolss_enumforms(p, &q_u, &r_u);
491
492         if (!spoolss_io_r_enumforms("",&r_u,rdata,0)) {
493                 DEBUG(0,("spoolss_io_r_enumforms: unable to marshall SPOOL_R_ENUMFORMS.\n"));
494                 return False;
495         }
496
497         return True;
498 }
499
500 /****************************************************************************
501 ****************************************************************************/
502
503 static bool api_spoolss_enumports(pipes_struct *p)
504 {
505         SPOOL_Q_ENUMPORTS q_u;
506         SPOOL_R_ENUMPORTS r_u;
507         prs_struct *data = &p->in_data.data;
508         prs_struct *rdata = &p->out_data.rdata;
509
510         ZERO_STRUCT(q_u);
511         ZERO_STRUCT(r_u);
512
513         if(!spoolss_io_q_enumports("", &q_u, data, 0)) {
514                 DEBUG(0,("spoolss_io_q_enumports: unable to unmarshall SPOOL_Q_ENUMPORTS.\n"));
515                 return False;
516         }
517
518         r_u.status = _spoolss_enumports(p, &q_u, &r_u);
519
520         if (!spoolss_io_r_enumports("",&r_u,rdata,0)) {
521                 DEBUG(0,("spoolss_io_r_enumports: unable to marshall SPOOL_R_ENUMPORTS.\n"));
522                 return False;
523         }
524
525         return True;
526 }
527
528 /****************************************************************************
529 ****************************************************************************/
530
531 static bool api_spoolss_addprinterex(pipes_struct *p)
532 {
533         return proxy_spoolss_call(p, NDR_SPOOLSS_ADDPRINTEREX);
534 }
535
536 /****************************************************************************
537 ****************************************************************************/
538
539 static bool api_spoolss_addprinterdriver(pipes_struct *p)
540 {
541         SPOOL_Q_ADDPRINTERDRIVER q_u;
542         SPOOL_R_ADDPRINTERDRIVER r_u;
543         prs_struct *data = &p->in_data.data;
544         prs_struct *rdata = &p->out_data.rdata;
545         
546         ZERO_STRUCT(q_u);
547         ZERO_STRUCT(r_u);
548         
549         if(!spoolss_io_q_addprinterdriver("", &q_u, data, 0)) {
550                 if (q_u.level != 3 && q_u.level != 6) {
551                         /* Clever hack from Martin Zielinski <mz@seh.de>
552                          * to allow downgrade from level 8 (Vista).
553                          */
554                         DEBUG(3,("api_spoolss_addprinterdriver: unknown SPOOL_Q_ADDPRINTERDRIVER level %u.\n",
555                                 (unsigned int)q_u.level ));
556                         setup_fault_pdu(p, NT_STATUS(DCERPC_FAULT_INVALID_TAG));
557                         return True;
558                 }
559                 DEBUG(0,("spoolss_io_q_addprinterdriver: unable to unmarshall SPOOL_Q_ADDPRINTERDRIVER.\n"));
560                 return False;
561         }
562         
563         r_u.status = _spoolss_addprinterdriver(p, &q_u, &r_u);
564                                 
565         if(!spoolss_io_r_addprinterdriver("", &r_u, rdata, 0)) {
566                 DEBUG(0,("spoolss_io_r_addprinterdriver: unable to marshall SPOOL_R_ADDPRINTERDRIVER.\n"));
567                 return False;
568         }
569         
570         return True;
571 }
572
573 /****************************************************************************
574 ****************************************************************************/
575
576 static bool api_spoolss_getprinterdriverdirectory(pipes_struct *p)
577 {
578         return proxy_spoolss_call(p, NDR_SPOOLSS_GETPRINTERDRIVERDIRECTORY);
579 }
580
581 /****************************************************************************
582 ****************************************************************************/
583
584 static bool api_spoolss_enumprinterdata(pipes_struct *p)
585 {
586         SPOOL_Q_ENUMPRINTERDATA q_u;
587         SPOOL_R_ENUMPRINTERDATA r_u;
588         prs_struct *data = &p->in_data.data;
589         prs_struct *rdata = &p->out_data.rdata;
590         
591         ZERO_STRUCT(q_u);
592         ZERO_STRUCT(r_u);
593         
594         if(!spoolss_io_q_enumprinterdata("", &q_u, data, 0)) {
595                 DEBUG(0,("spoolss_io_q_enumprinterdata: unable to unmarshall SPOOL_Q_ENUMPRINTERDATA.\n"));
596                 return False;
597         }
598         
599         r_u.status = _spoolss_enumprinterdata(p, &q_u, &r_u);
600                                 
601         if(!spoolss_io_r_enumprinterdata("", &r_u, rdata, 0)) {
602                 DEBUG(0,("spoolss_io_r_enumprinterdata: unable to marshall SPOOL_R_ENUMPRINTERDATA.\n"));
603                 return False;
604         }
605
606         return True;
607 }
608
609 /****************************************************************************
610 ****************************************************************************/
611
612 static bool api_spoolss_setprinterdata(pipes_struct *p)
613 {
614         SPOOL_Q_SETPRINTERDATA q_u;
615         SPOOL_R_SETPRINTERDATA r_u;
616         prs_struct *data = &p->in_data.data;
617         prs_struct *rdata = &p->out_data.rdata;
618         
619         ZERO_STRUCT(q_u);
620         ZERO_STRUCT(r_u);
621         
622         if(!spoolss_io_q_setprinterdata("", &q_u, data, 0)) {
623                 DEBUG(0,("spoolss_io_q_setprinterdata: unable to unmarshall SPOOL_Q_SETPRINTERDATA.\n"));
624                 return False;
625         }
626         
627         r_u.status = _spoolss_setprinterdata(p, &q_u, &r_u);
628                                 
629         if(!spoolss_io_r_setprinterdata("", &r_u, rdata, 0)) {
630                 DEBUG(0,("spoolss_io_r_setprinterdata: unable to marshall SPOOL_R_SETPRINTERDATA.\n"));
631                 return False;
632         }
633
634         return True;
635 }
636
637 /****************************************************************************
638 ****************************************************************************/
639 static bool api_spoolss_reset_printer(pipes_struct *p)
640 {
641         return proxy_spoolss_call(p, NDR_SPOOLSS_RESETPRINTER);
642 }
643
644 /****************************************************************************
645 ****************************************************************************/
646 static bool api_spoolss_addform(pipes_struct *p)
647 {
648         return proxy_spoolss_call(p, NDR_SPOOLSS_ADDFORM);
649 }
650
651 /****************************************************************************
652 ****************************************************************************/
653
654 static bool api_spoolss_deleteform(pipes_struct *p)
655 {
656         return proxy_spoolss_call(p, NDR_SPOOLSS_DELETEFORM);
657 }
658
659 /****************************************************************************
660 ****************************************************************************/
661
662 static bool api_spoolss_setform(pipes_struct *p)
663 {
664         return proxy_spoolss_call(p, NDR_SPOOLSS_SETFORM);
665 }
666
667 /****************************************************************************
668 ****************************************************************************/
669
670 static bool api_spoolss_enumprintprocessors(pipes_struct *p)
671 {
672         SPOOL_Q_ENUMPRINTPROCESSORS q_u;
673         SPOOL_R_ENUMPRINTPROCESSORS 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_enumprintprocessors("", &q_u, data, 0)) {
681                 DEBUG(0,("spoolss_io_q_enumprintprocessors: unable to unmarshall SPOOL_Q_ENUMPRINTPROCESSORS.\n"));
682                 return False;
683         }
684         
685         r_u.status = _spoolss_enumprintprocessors(p, &q_u, &r_u);
686
687         if(!spoolss_io_r_enumprintprocessors("", &r_u, rdata, 0)) {
688                 DEBUG(0,("spoolss_io_r_enumprintprocessors: unable to marshall SPOOL_R_ENUMPRINTPROCESSORS.\n"));
689                 return False;
690         }
691         
692         return True;
693 }
694
695 /****************************************************************************
696 ****************************************************************************/
697
698 static bool api_spoolss_addprintprocessor(pipes_struct *p)
699 {
700         return proxy_spoolss_call(p, NDR_SPOOLSS_ADDPRINTPROCESSOR);
701 }
702
703 /****************************************************************************
704 ****************************************************************************/
705
706 static bool api_spoolss_enumprintprocdatatypes(pipes_struct *p)
707 {
708         SPOOL_Q_ENUMPRINTPROCDATATYPES q_u;
709         SPOOL_R_ENUMPRINTPROCDATATYPES r_u;
710         prs_struct *data = &p->in_data.data;
711         prs_struct *rdata = &p->out_data.rdata;
712
713         ZERO_STRUCT(q_u);
714         ZERO_STRUCT(r_u);
715         
716         if(!spoolss_io_q_enumprintprocdatatypes("", &q_u, data, 0)) {
717                 DEBUG(0,("spoolss_io_q_enumprintprocdatatypes: unable to unmarshall SPOOL_Q_ENUMPRINTPROCDATATYPES.\n"));
718                 return False;
719         }
720         
721         r_u.status = _spoolss_enumprintprocdatatypes(p, &q_u, &r_u);
722
723         if(!spoolss_io_r_enumprintprocdatatypes("", &r_u, rdata, 0)) {
724                 DEBUG(0,("spoolss_io_r_enumprintprocdatatypes: unable to marshall SPOOL_R_ENUMPRINTPROCDATATYPES.\n"));
725                 return False;
726         }
727         
728         return True;
729 }
730
731 /****************************************************************************
732 ****************************************************************************/
733
734 static bool api_spoolss_enumprintmonitors(pipes_struct *p)
735 {
736         SPOOL_Q_ENUMPRINTMONITORS q_u;
737         SPOOL_R_ENUMPRINTMONITORS r_u;
738         prs_struct *data = &p->in_data.data;
739         prs_struct *rdata = &p->out_data.rdata;
740
741         ZERO_STRUCT(q_u);
742         ZERO_STRUCT(r_u);
743         
744         if (!spoolss_io_q_enumprintmonitors("", &q_u, data, 0)) {
745                 DEBUG(0,("spoolss_io_q_enumprintmonitors: unable to unmarshall SPOOL_Q_ENUMPRINTMONITORS.\n"));
746                 return False;
747         }
748                 
749         r_u.status = _spoolss_enumprintmonitors(p, &q_u, &r_u);
750
751         if (!spoolss_io_r_enumprintmonitors("", &r_u, rdata, 0)) {
752                 DEBUG(0,("spoolss_io_r_enumprintmonitors: unable to marshall SPOOL_R_ENUMPRINTMONITORS.\n"));
753                 return False;
754         }
755         
756         return True;
757 }
758
759 /****************************************************************************
760 ****************************************************************************/
761
762 static bool api_spoolss_getjob(pipes_struct *p)
763 {
764         SPOOL_Q_GETJOB q_u;
765         SPOOL_R_GETJOB r_u;
766         prs_struct *data = &p->in_data.data;
767         prs_struct *rdata = &p->out_data.rdata;
768         
769         ZERO_STRUCT(q_u);
770         ZERO_STRUCT(r_u);
771         
772         if(!spoolss_io_q_getjob("", &q_u, data, 0)) {
773                 DEBUG(0,("spoolss_io_q_getjob: unable to unmarshall SPOOL_Q_GETJOB.\n"));
774                 return False;
775         }
776
777         r_u.status = _spoolss_getjob(p, &q_u, &r_u);
778         
779         if(!spoolss_io_r_getjob("",&r_u,rdata,0)) {
780                 DEBUG(0,("spoolss_io_r_getjob: unable to marshall SPOOL_R_GETJOB.\n"));
781                 return False;
782         }
783                 
784         return True;
785 }
786
787 /********************************************************************
788  * api_spoolss_getprinterdataex
789  *
790  * called from the spoolss dispatcher
791  ********************************************************************/
792
793 static bool api_spoolss_getprinterdataex(pipes_struct *p)
794 {
795         return proxy_spoolss_call(p, NDR_SPOOLSS_GETPRINTERDATAEX);
796 }
797
798 /****************************************************************************
799 ****************************************************************************/
800
801 static bool api_spoolss_setprinterdataex(pipes_struct *p)
802 {
803         return proxy_spoolss_call(p, NDR_SPOOLSS_SETPRINTERDATAEX);
804 }
805
806
807 /****************************************************************************
808 ****************************************************************************/
809
810 static bool api_spoolss_enumprinterkey(pipes_struct *p)
811 {
812         SPOOL_Q_ENUMPRINTERKEY q_u;
813         SPOOL_R_ENUMPRINTERKEY 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_enumprinterkey("", &q_u, data, 0)) {
821                 DEBUG(0,("spoolss_io_q_setprinterkey: unable to unmarshall SPOOL_Q_ENUMPRINTERKEY.\n"));
822                 return False;
823         }
824         
825         r_u.status = _spoolss_enumprinterkey(p, &q_u, &r_u);
826                                 
827         if(!spoolss_io_r_enumprinterkey("", &r_u, rdata, 0)) {
828                 DEBUG(0,("spoolss_io_r_enumprinterkey: unable to marshall SPOOL_R_ENUMPRINTERKEY.\n"));
829                 return False;
830         }
831
832         return True;
833 }
834
835 /****************************************************************************
836 ****************************************************************************/
837
838 static bool api_spoolss_enumprinterdataex(pipes_struct *p)
839 {
840         SPOOL_Q_ENUMPRINTERDATAEX q_u;
841         SPOOL_R_ENUMPRINTERDATAEX 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_enumprinterdataex("", &q_u, data, 0)) {
849                 DEBUG(0,("spoolss_io_q_enumprinterdataex: unable to unmarshall SPOOL_Q_ENUMPRINTERDATAEX.\n"));
850                 return False;
851         }
852         
853         r_u.status = _spoolss_enumprinterdataex(p, &q_u, &r_u);
854                                 
855         if(!spoolss_io_r_enumprinterdataex("", &r_u, rdata, 0)) {
856                 DEBUG(0,("spoolss_io_r_enumprinterdataex: unable to marshall SPOOL_R_ENUMPRINTERDATAEX.\n"));
857                 return False;
858         }
859
860         return True;
861 }
862
863 /****************************************************************************
864 ****************************************************************************/
865
866 static bool api_spoolss_getprintprocessordirectory(pipes_struct *p)
867 {
868         SPOOL_Q_GETPRINTPROCESSORDIRECTORY q_u;
869         SPOOL_R_GETPRINTPROCESSORDIRECTORY 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_getprintprocessordirectory("", &q_u, data, 0)) {
877                 DEBUG(0,("spoolss_io_q_getprintprocessordirectory: unable to unmarshall SPOOL_Q_GETPRINTPROCESSORDIRECTORY.\n"));
878                 return False;
879         }
880         
881         r_u.status = _spoolss_getprintprocessordirectory(p, &q_u, &r_u);
882                                 
883         if(!spoolss_io_r_getprintprocessordirectory("", &r_u, rdata, 0)) {
884                 DEBUG(0,("spoolss_io_r_getprintprocessordirectory: unable to marshall SPOOL_R_GETPRINTPROCESSORDIRECTORY.\n"));
885                 return False;
886         }
887         
888         return True;
889 }
890
891 /****************************************************************************
892 ****************************************************************************/
893
894 static bool api_spoolss_deleteprinterdataex(pipes_struct *p)
895 {
896         return proxy_spoolss_call(p, NDR_SPOOLSS_DELETEPRINTERDATAEX);
897 }
898
899 /****************************************************************************
900 ****************************************************************************/
901
902 static bool api_spoolss_deleteprinterkey(pipes_struct *p)
903 {
904         return proxy_spoolss_call(p, NDR_SPOOLSS_DELETEPRINTERKEY);
905 }
906
907 /****************************************************************************
908 ****************************************************************************/
909
910 static bool api_spoolss_addprinterdriverex(pipes_struct *p)
911 {
912         SPOOL_Q_ADDPRINTERDRIVEREX q_u;
913         SPOOL_R_ADDPRINTERDRIVEREX r_u;
914         prs_struct *data = &p->in_data.data;
915         prs_struct *rdata = &p->out_data.rdata;
916         
917         ZERO_STRUCT(q_u);
918         ZERO_STRUCT(r_u);
919         
920         if(!spoolss_io_q_addprinterdriverex("", &q_u, data, 0)) {
921                 if (q_u.level != 3 && q_u.level != 6) {
922                         /* Clever hack from Martin Zielinski <mz@seh.de>
923                          * to allow downgrade from level 8 (Vista).
924                          */
925                         DEBUG(3,("api_spoolss_addprinterdriverex: unknown SPOOL_Q_ADDPRINTERDRIVEREX level %u.\n",
926                                 (unsigned int)q_u.level ));
927                         setup_fault_pdu(p, NT_STATUS(DCERPC_FAULT_INVALID_TAG));
928                         return True;
929                 }
930                 DEBUG(0,("spoolss_io_q_addprinterdriverex: unable to unmarshall SPOOL_Q_ADDPRINTERDRIVEREX.\n"));
931                 return False;
932         }
933         
934         r_u.status = _spoolss_addprinterdriverex(p, &q_u, &r_u);
935                                 
936         if(!spoolss_io_r_addprinterdriverex("", &r_u, rdata, 0)) {
937                 DEBUG(0,("spoolss_io_r_addprinterdriverex: unable to marshall SPOOL_R_ADDPRINTERDRIVEREX.\n"));
938                 return False;
939         }
940         
941         return True;
942 }
943
944 /****************************************************************************
945 ****************************************************************************/
946
947 static bool api_spoolss_deleteprinterdriverex(pipes_struct *p)
948 {
949         return proxy_spoolss_call(p, NDR_SPOOLSS_DELETEPRINTERDRIVEREX);
950 }
951
952 /****************************************************************************
953 ****************************************************************************/
954
955 static bool api_spoolss_xcvdataport(pipes_struct *p)
956 {
957         return proxy_spoolss_call(p, NDR_SPOOLSS_XCVDATA);
958 }
959
960 /*******************************************************************
961 \pipe\spoolss commands
962 ********************************************************************/
963
964   struct api_struct api_spoolss_cmds[] = 
965     {
966  {"SPOOLSS_OPENPRINTER",               SPOOLSS_OPENPRINTER,               api_spoolss_open_printer              },
967  {"SPOOLSS_OPENPRINTEREX",             SPOOLSS_OPENPRINTEREX,             api_spoolss_open_printer_ex           },
968  {"SPOOLSS_GETPRINTERDATA",            SPOOLSS_GETPRINTERDATA,            api_spoolss_getprinterdata            },
969  {"SPOOLSS_CLOSEPRINTER",              SPOOLSS_CLOSEPRINTER,              api_spoolss_closeprinter              },
970  {"SPOOLSS_DELETEPRINTER",             SPOOLSS_DELETEPRINTER,             api_spoolss_deleteprinter             },
971  {"SPOOLSS_ABORTPRINTER",              SPOOLSS_ABORTPRINTER,              api_spoolss_abortprinter              },
972  {"SPOOLSS_RFFPCNEX",                  SPOOLSS_RFFPCNEX,                  api_spoolss_rffpcnex                  },
973  {"SPOOLSS_RFNPCNEX",                  SPOOLSS_RFNPCNEX,                  api_spoolss_rfnpcnex                  },
974  {"SPOOLSS_ENUMPRINTERS",              SPOOLSS_ENUMPRINTERS,              api_spoolss_enumprinters              },
975  {"SPOOLSS_GETPRINTER",                SPOOLSS_GETPRINTER,                api_spoolss_getprinter                },
976  {"SPOOLSS_GETPRINTERDRIVER2",         SPOOLSS_GETPRINTERDRIVER2,         api_spoolss_getprinterdriver2         }, 
977  {"SPOOLSS_STARTPAGEPRINTER",          SPOOLSS_STARTPAGEPRINTER,          api_spoolss_startpageprinter          },
978  {"SPOOLSS_ENDPAGEPRINTER",            SPOOLSS_ENDPAGEPRINTER,            api_spoolss_endpageprinter            }, 
979  {"SPOOLSS_STARTDOCPRINTER",           SPOOLSS_STARTDOCPRINTER,           api_spoolss_startdocprinter           },
980  {"SPOOLSS_ENDDOCPRINTER",             SPOOLSS_ENDDOCPRINTER,             api_spoolss_enddocprinter             },
981  {"SPOOLSS_WRITEPRINTER",              SPOOLSS_WRITEPRINTER,              api_spoolss_writeprinter              },
982  {"SPOOLSS_SETPRINTER",                SPOOLSS_SETPRINTER,                api_spoolss_setprinter                },
983  {"SPOOLSS_FCPN",                      SPOOLSS_FCPN,                      api_spoolss_fcpn                      },
984  {"SPOOLSS_ADDJOB",                    SPOOLSS_ADDJOB,                    api_spoolss_addjob                    },
985  {"SPOOLSS_ENUMJOBS",                  SPOOLSS_ENUMJOBS,                  api_spoolss_enumjobs                  },
986  {"SPOOLSS_SCHEDULEJOB",               SPOOLSS_SCHEDULEJOB,               api_spoolss_schedulejob               },
987  {"SPOOLSS_SETJOB",                    SPOOLSS_SETJOB,                    api_spoolss_setjob                    },
988  {"SPOOLSS_ENUMFORMS",                 SPOOLSS_ENUMFORMS,                 api_spoolss_enumforms                 },
989  {"SPOOLSS_ENUMPORTS",                 SPOOLSS_ENUMPORTS,                 api_spoolss_enumports                 },
990  {"SPOOLSS_ENUMPRINTERDRIVERS",        SPOOLSS_ENUMPRINTERDRIVERS,        api_spoolss_enumprinterdrivers        },
991  {"SPOOLSS_ADDPRINTEREX",              SPOOLSS_ADDPRINTEREX,              api_spoolss_addprinterex              },
992  {"SPOOLSS_ADDPRINTERDRIVER",          SPOOLSS_ADDPRINTERDRIVER,          api_spoolss_addprinterdriver          },
993  {"SPOOLSS_DELETEPRINTERDRIVER",       SPOOLSS_DELETEPRINTERDRIVER,       api_spoolss_deleteprinterdriver       },
994  {"SPOOLSS_GETPRINTERDRIVERDIRECTORY", SPOOLSS_GETPRINTERDRIVERDIRECTORY, api_spoolss_getprinterdriverdirectory },
995  {"SPOOLSS_ENUMPRINTERDATA",           SPOOLSS_ENUMPRINTERDATA,           api_spoolss_enumprinterdata           },
996  {"SPOOLSS_SETPRINTERDATA",            SPOOLSS_SETPRINTERDATA,            api_spoolss_setprinterdata            },
997  {"SPOOLSS_RESETPRINTER",              SPOOLSS_RESETPRINTER,              api_spoolss_reset_printer             },
998  {"SPOOLSS_DELETEPRINTERDATA",         SPOOLSS_DELETEPRINTERDATA,         api_spoolss_deleteprinterdata         },
999  {"SPOOLSS_ADDFORM",                   SPOOLSS_ADDFORM,                   api_spoolss_addform                   },
1000  {"SPOOLSS_DELETEFORM",                SPOOLSS_DELETEFORM,                api_spoolss_deleteform                },
1001  {"SPOOLSS_GETFORM",                   SPOOLSS_GETFORM,                   api_spoolss_getform                   },
1002  {"SPOOLSS_SETFORM",                   SPOOLSS_SETFORM,                   api_spoolss_setform                   },
1003  {"SPOOLSS_ADDPRINTPROCESSOR",         SPOOLSS_ADDPRINTPROCESSOR,         api_spoolss_addprintprocessor         },
1004  {"SPOOLSS_ENUMPRINTPROCESSORS",       SPOOLSS_ENUMPRINTPROCESSORS,       api_spoolss_enumprintprocessors       },
1005  {"SPOOLSS_ENUMMONITORS",              SPOOLSS_ENUMMONITORS,              api_spoolss_enumprintmonitors         },
1006  {"SPOOLSS_GETJOB",                    SPOOLSS_GETJOB,                    api_spoolss_getjob                    },
1007  {"SPOOLSS_ENUMPRINTPROCDATATYPES",    SPOOLSS_ENUMPRINTPROCDATATYPES,    api_spoolss_enumprintprocdatatypes    },
1008  {"SPOOLSS_GETPRINTERDATAEX",          SPOOLSS_GETPRINTERDATAEX,          api_spoolss_getprinterdataex          },
1009  {"SPOOLSS_SETPRINTERDATAEX",          SPOOLSS_SETPRINTERDATAEX,          api_spoolss_setprinterdataex          },
1010  {"SPOOLSS_DELETEPRINTERDATAEX",       SPOOLSS_DELETEPRINTERDATAEX,       api_spoolss_deleteprinterdataex       },
1011  {"SPOOLSS_ENUMPRINTERDATAEX",         SPOOLSS_ENUMPRINTERDATAEX,         api_spoolss_enumprinterdataex         },
1012  {"SPOOLSS_ENUMPRINTERKEY",            SPOOLSS_ENUMPRINTERKEY,            api_spoolss_enumprinterkey            },
1013  {"SPOOLSS_DELETEPRINTERKEY",          SPOOLSS_DELETEPRINTERKEY,          api_spoolss_deleteprinterkey          },
1014  {"SPOOLSS_GETPRINTPROCESSORDIRECTORY",SPOOLSS_GETPRINTPROCESSORDIRECTORY,api_spoolss_getprintprocessordirectory},
1015  {"SPOOLSS_ADDPRINTERDRIVEREX",        SPOOLSS_ADDPRINTERDRIVEREX,        api_spoolss_addprinterdriverex        },
1016  {"SPOOLSS_DELETEPRINTERDRIVEREX",     SPOOLSS_DELETEPRINTERDRIVEREX,     api_spoolss_deleteprinterdriverex     },
1017  {"SPOOLSS_XCVDATAPORT",               SPOOLSS_XCVDATAPORT,               api_spoolss_xcvdataport               },
1018 };
1019
1020 void spoolss2_get_pipe_fns( struct api_struct **fns, int *n_fns )
1021 {
1022         *fns = api_spoolss_cmds;
1023         *n_fns = sizeof(api_spoolss_cmds) / sizeof(struct api_struct);
1024 }
1025
1026 NTSTATUS rpc_spoolss2_init(void)
1027 {
1028         return rpc_srv_register(
1029                 SMB_RPC_INTERFACE_VERSION, "spoolss", "spoolss",
1030                 &ndr_table_spoolss,
1031                 api_spoolss_cmds,
1032                 sizeof(api_spoolss_cmds) / sizeof(struct api_struct));
1033 }