s3-spoolss: use pidl for _spoolss_EnumPrinterData.
[Samba.git] / source3 / rpc_server / srv_spoolss.c
blobced4ed53f413dcd3b08a73252d7bf31fbc30e81a
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.
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.
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.
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/>.
25 #include "includes.h"
27 #undef DBGC_CLASS
28 #define DBGC_CLASS DBGC_RPC_SRV
30 /*******************************************************************
31 ********************************************************************/
33 static bool proxy_spoolss_call(pipes_struct *p, uint8_t opnum)
35 struct api_struct *fns;
36 int n_fns;
38 spoolss_get_pipe_fns(&fns, &n_fns);
40 if (opnum >= n_fns) {
41 return false;
44 if (fns[opnum].opnum != opnum) {
45 smb_panic("SPOOLSS function table not sorted");
48 return fns[opnum].fn(p);
51 /********************************************************************
52 * api_spoolss_open_printer_ex (rarely seen - older call)
53 ********************************************************************/
55 static bool api_spoolss_open_printer(pipes_struct *p)
57 return proxy_spoolss_call(p, NDR_SPOOLSS_OPENPRINTER);
60 /********************************************************************
61 * api_spoolss_open_printer_ex
62 ********************************************************************/
64 static bool api_spoolss_open_printer_ex(pipes_struct *p)
66 return proxy_spoolss_call(p, NDR_SPOOLSS_OPENPRINTEREX);
69 /********************************************************************
70 * api_spoolss_getprinterdata
72 * called from the spoolss dispatcher
73 ********************************************************************/
75 static bool api_spoolss_getprinterdata(pipes_struct *p)
77 return proxy_spoolss_call(p, NDR_SPOOLSS_GETPRINTERDATA);
80 /********************************************************************
81 * api_spoolss_deleteprinterdata
83 * called from the spoolss dispatcher
84 ********************************************************************/
86 static bool api_spoolss_deleteprinterdata(pipes_struct *p)
88 return proxy_spoolss_call(p, NDR_SPOOLSS_DELETEPRINTERDATA);
91 /********************************************************************
92 * api_spoolss_closeprinter
94 * called from the spoolss dispatcher
95 ********************************************************************/
97 static bool api_spoolss_closeprinter(pipes_struct *p)
99 return proxy_spoolss_call(p, NDR_SPOOLSS_CLOSEPRINTER);
102 /********************************************************************
103 * api_spoolss_abortprinter
105 * called from the spoolss dispatcher
106 ********************************************************************/
108 static bool api_spoolss_abortprinter(pipes_struct *p)
110 return proxy_spoolss_call(p, NDR_SPOOLSS_ABORTPRINTER);
113 /********************************************************************
114 * api_spoolss_deleteprinter
116 * called from the spoolss dispatcher
117 ********************************************************************/
119 static bool api_spoolss_deleteprinter(pipes_struct *p)
121 return proxy_spoolss_call(p, NDR_SPOOLSS_DELETEPRINTER);
124 /********************************************************************
125 * api_spoolss_deleteprinterdriver
127 * called from the spoolss dispatcher
128 ********************************************************************/
130 static bool api_spoolss_deleteprinterdriver(pipes_struct *p)
132 return proxy_spoolss_call(p, NDR_SPOOLSS_DELETEPRINTERDRIVER);
136 /********************************************************************
137 * api_spoolss_rffpcnex
138 * ReplyFindFirstPrinterChangeNotifyEx
139 ********************************************************************/
141 static bool api_spoolss_rffpcnex(pipes_struct *p)
143 return proxy_spoolss_call(p, NDR_SPOOLSS_REMOTEFINDFIRSTPRINTERCHANGENOTIFYEX);
147 /********************************************************************
148 * api_spoolss_rfnpcnex
149 * ReplyFindNextPrinterChangeNotifyEx
150 * called from the spoolss dispatcher
152 * Note - this is the *ONLY* function that breaks the RPC call
153 * symmetry in all the other calls. We need to do this to fix
154 * the massive memory allocation problem with thousands of jobs...
155 * JRA.
156 ********************************************************************/
158 static bool api_spoolss_rfnpcnex(pipes_struct *p)
160 return proxy_spoolss_call(p, NDR_SPOOLSS_ROUTERREFRESHPRINTERCHANGENOTIFY);
164 /********************************************************************
165 * api_spoolss_enumprinters
166 * called from the spoolss dispatcher
168 ********************************************************************/
170 static bool api_spoolss_enumprinters(pipes_struct *p)
172 return proxy_spoolss_call(p, NDR_SPOOLSS_ENUMPRINTERS);
175 /********************************************************************
176 * api_spoolss_getprinter
177 * called from the spoolss dispatcher
179 ********************************************************************/
181 static bool api_spoolss_getprinter(pipes_struct *p)
183 return proxy_spoolss_call(p, NDR_SPOOLSS_GETPRINTER);
186 /********************************************************************
187 * api_spoolss_getprinter
188 * called from the spoolss dispatcher
190 ********************************************************************/
192 static bool api_spoolss_getprinterdriver2(pipes_struct *p)
194 return proxy_spoolss_call(p, NDR_SPOOLSS_GETPRINTERDRIVER2);
197 /********************************************************************
198 * api_spoolss_getprinter
199 * called from the spoolss dispatcher
201 ********************************************************************/
203 static bool api_spoolss_startpageprinter(pipes_struct *p)
205 return proxy_spoolss_call(p, NDR_SPOOLSS_STARTPAGEPRINTER);
208 /********************************************************************
209 * api_spoolss_getprinter
210 * called from the spoolss dispatcher
212 ********************************************************************/
214 static bool api_spoolss_endpageprinter(pipes_struct *p)
216 return proxy_spoolss_call(p, NDR_SPOOLSS_ENDPAGEPRINTER);
219 /********************************************************************
220 ********************************************************************/
222 static bool api_spoolss_startdocprinter(pipes_struct *p)
224 return proxy_spoolss_call(p, NDR_SPOOLSS_STARTDOCPRINTER);
227 /********************************************************************
228 ********************************************************************/
230 static bool api_spoolss_enddocprinter(pipes_struct *p)
232 return proxy_spoolss_call(p, NDR_SPOOLSS_ENDDOCPRINTER);
235 /********************************************************************
236 ********************************************************************/
238 static bool api_spoolss_writeprinter(pipes_struct *p)
240 return proxy_spoolss_call(p, NDR_SPOOLSS_WRITEPRINTER);
243 /****************************************************************************
245 ****************************************************************************/
247 static bool api_spoolss_setprinter(pipes_struct *p)
249 return proxy_spoolss_call(p, NDR_SPOOLSS_SETPRINTER);
252 /****************************************************************************
253 ****************************************************************************/
255 static bool api_spoolss_fcpn(pipes_struct *p)
257 return proxy_spoolss_call(p, NDR_SPOOLSS_FINDCLOSEPRINTERNOTIFY);
260 /****************************************************************************
261 ****************************************************************************/
263 static bool api_spoolss_addjob(pipes_struct *p)
265 return proxy_spoolss_call(p, NDR_SPOOLSS_ADDJOB);
268 /****************************************************************************
269 ****************************************************************************/
271 static bool api_spoolss_enumjobs(pipes_struct *p)
273 return proxy_spoolss_call(p, NDR_SPOOLSS_ENUMJOBS);
276 /****************************************************************************
277 ****************************************************************************/
279 static bool api_spoolss_schedulejob(pipes_struct *p)
281 return proxy_spoolss_call(p, NDR_SPOOLSS_SCHEDULEJOB);
284 /****************************************************************************
285 ****************************************************************************/
287 static bool api_spoolss_setjob(pipes_struct *p)
289 return proxy_spoolss_call(p, NDR_SPOOLSS_SETJOB);
292 /****************************************************************************
293 ****************************************************************************/
295 static bool api_spoolss_enumprinterdrivers(pipes_struct *p)
297 return proxy_spoolss_call(p, NDR_SPOOLSS_ENUMPRINTERDRIVERS);
300 /****************************************************************************
301 ****************************************************************************/
303 static bool api_spoolss_getform(pipes_struct *p)
305 return proxy_spoolss_call(p, NDR_SPOOLSS_GETFORM);
308 /****************************************************************************
309 ****************************************************************************/
311 static bool api_spoolss_enumforms(pipes_struct *p)
313 return proxy_spoolss_call(p, NDR_SPOOLSS_ENUMFORMS);
316 /****************************************************************************
317 ****************************************************************************/
319 static bool api_spoolss_enumports(pipes_struct *p)
321 return proxy_spoolss_call(p, NDR_SPOOLSS_ENUMPORTS);
324 /****************************************************************************
325 ****************************************************************************/
327 static bool api_spoolss_addprinterex(pipes_struct *p)
329 return proxy_spoolss_call(p, NDR_SPOOLSS_ADDPRINTEREX);
332 /****************************************************************************
333 ****************************************************************************/
335 static bool api_spoolss_addprinterdriver(pipes_struct *p)
337 return proxy_spoolss_call(p, NDR_SPOOLSS_ADDPRINTERDRIVER);
340 /****************************************************************************
341 ****************************************************************************/
343 static bool api_spoolss_getprinterdriverdirectory(pipes_struct *p)
345 return proxy_spoolss_call(p, NDR_SPOOLSS_GETPRINTERDRIVERDIRECTORY);
348 /****************************************************************************
349 ****************************************************************************/
351 static bool api_spoolss_enumprinterdata(pipes_struct *p)
353 return proxy_spoolss_call(p, NDR_SPOOLSS_ENUMPRINTERDATA);
356 /****************************************************************************
357 ****************************************************************************/
359 static bool api_spoolss_setprinterdata(pipes_struct *p)
361 return proxy_spoolss_call(p, NDR_SPOOLSS_SETPRINTERDATA);
364 /****************************************************************************
365 ****************************************************************************/
366 static bool api_spoolss_reset_printer(pipes_struct *p)
368 return proxy_spoolss_call(p, NDR_SPOOLSS_RESETPRINTER);
371 /****************************************************************************
372 ****************************************************************************/
373 static bool api_spoolss_addform(pipes_struct *p)
375 return proxy_spoolss_call(p, NDR_SPOOLSS_ADDFORM);
378 /****************************************************************************
379 ****************************************************************************/
381 static bool api_spoolss_deleteform(pipes_struct *p)
383 return proxy_spoolss_call(p, NDR_SPOOLSS_DELETEFORM);
386 /****************************************************************************
387 ****************************************************************************/
389 static bool api_spoolss_setform(pipes_struct *p)
391 return proxy_spoolss_call(p, NDR_SPOOLSS_SETFORM);
394 /****************************************************************************
395 ****************************************************************************/
397 static bool api_spoolss_enumprintprocessors(pipes_struct *p)
399 return proxy_spoolss_call(p, NDR_SPOOLSS_ENUMPRINTPROCESSORS);
402 /****************************************************************************
403 ****************************************************************************/
405 static bool api_spoolss_addprintprocessor(pipes_struct *p)
407 return proxy_spoolss_call(p, NDR_SPOOLSS_ADDPRINTPROCESSOR);
410 /****************************************************************************
411 ****************************************************************************/
413 static bool api_spoolss_enumprintprocdatatypes(pipes_struct *p)
415 return proxy_spoolss_call(p, NDR_SPOOLSS_ENUMPRINTPROCDATATYPES);
418 /****************************************************************************
419 ****************************************************************************/
421 static bool api_spoolss_enumprintmonitors(pipes_struct *p)
423 return proxy_spoolss_call(p, NDR_SPOOLSS_ENUMMONITORS);
426 /****************************************************************************
427 ****************************************************************************/
429 static bool api_spoolss_getjob(pipes_struct *p)
431 return proxy_spoolss_call(p, NDR_SPOOLSS_GETJOB);
434 /********************************************************************
435 * api_spoolss_getprinterdataex
437 * called from the spoolss dispatcher
438 ********************************************************************/
440 static bool api_spoolss_getprinterdataex(pipes_struct *p)
442 return proxy_spoolss_call(p, NDR_SPOOLSS_GETPRINTERDATAEX);
445 /****************************************************************************
446 ****************************************************************************/
448 static bool api_spoolss_setprinterdataex(pipes_struct *p)
450 return proxy_spoolss_call(p, NDR_SPOOLSS_SETPRINTERDATAEX);
454 /****************************************************************************
455 ****************************************************************************/
457 static bool api_spoolss_enumprinterkey(pipes_struct *p)
459 SPOOL_Q_ENUMPRINTERKEY q_u;
460 SPOOL_R_ENUMPRINTERKEY r_u;
461 prs_struct *data = &p->in_data.data;
462 prs_struct *rdata = &p->out_data.rdata;
464 ZERO_STRUCT(q_u);
465 ZERO_STRUCT(r_u);
467 if(!spoolss_io_q_enumprinterkey("", &q_u, data, 0)) {
468 DEBUG(0,("spoolss_io_q_setprinterkey: unable to unmarshall SPOOL_Q_ENUMPRINTERKEY.\n"));
469 return False;
472 r_u.status = _spoolss_enumprinterkey(p, &q_u, &r_u);
474 if(!spoolss_io_r_enumprinterkey("", &r_u, rdata, 0)) {
475 DEBUG(0,("spoolss_io_r_enumprinterkey: unable to marshall SPOOL_R_ENUMPRINTERKEY.\n"));
476 return False;
479 return True;
482 /****************************************************************************
483 ****************************************************************************/
485 static bool api_spoolss_enumprinterdataex(pipes_struct *p)
487 SPOOL_Q_ENUMPRINTERDATAEX q_u;
488 SPOOL_R_ENUMPRINTERDATAEX r_u;
489 prs_struct *data = &p->in_data.data;
490 prs_struct *rdata = &p->out_data.rdata;
492 ZERO_STRUCT(q_u);
493 ZERO_STRUCT(r_u);
495 if(!spoolss_io_q_enumprinterdataex("", &q_u, data, 0)) {
496 DEBUG(0,("spoolss_io_q_enumprinterdataex: unable to unmarshall SPOOL_Q_ENUMPRINTERDATAEX.\n"));
497 return False;
500 r_u.status = _spoolss_enumprinterdataex(p, &q_u, &r_u);
502 if(!spoolss_io_r_enumprinterdataex("", &r_u, rdata, 0)) {
503 DEBUG(0,("spoolss_io_r_enumprinterdataex: unable to marshall SPOOL_R_ENUMPRINTERDATAEX.\n"));
504 return False;
507 return True;
510 /****************************************************************************
511 ****************************************************************************/
513 static bool api_spoolss_getprintprocessordirectory(pipes_struct *p)
515 return proxy_spoolss_call(p, NDR_SPOOLSS_GETPRINTPROCESSORDIRECTORY);
518 /****************************************************************************
519 ****************************************************************************/
521 static bool api_spoolss_deleteprinterdataex(pipes_struct *p)
523 return proxy_spoolss_call(p, NDR_SPOOLSS_DELETEPRINTERDATAEX);
526 /****************************************************************************
527 ****************************************************************************/
529 static bool api_spoolss_deleteprinterkey(pipes_struct *p)
531 return proxy_spoolss_call(p, NDR_SPOOLSS_DELETEPRINTERKEY);
534 /****************************************************************************
535 ****************************************************************************/
537 static bool api_spoolss_addprinterdriverex(pipes_struct *p)
539 return proxy_spoolss_call(p, NDR_SPOOLSS_ADDPRINTERDRIVEREX);
542 /****************************************************************************
543 ****************************************************************************/
545 static bool api_spoolss_deleteprinterdriverex(pipes_struct *p)
547 return proxy_spoolss_call(p, NDR_SPOOLSS_DELETEPRINTERDRIVEREX);
550 /****************************************************************************
551 ****************************************************************************/
553 static bool api_spoolss_xcvdataport(pipes_struct *p)
555 return proxy_spoolss_call(p, NDR_SPOOLSS_XCVDATA);
558 /*******************************************************************
559 \pipe\spoolss commands
560 ********************************************************************/
562 struct api_struct api_spoolss_cmds[] =
564 {"SPOOLSS_OPENPRINTER", SPOOLSS_OPENPRINTER, api_spoolss_open_printer },
565 {"SPOOLSS_OPENPRINTEREX", SPOOLSS_OPENPRINTEREX, api_spoolss_open_printer_ex },
566 {"SPOOLSS_GETPRINTERDATA", SPOOLSS_GETPRINTERDATA, api_spoolss_getprinterdata },
567 {"SPOOLSS_CLOSEPRINTER", SPOOLSS_CLOSEPRINTER, api_spoolss_closeprinter },
568 {"SPOOLSS_DELETEPRINTER", SPOOLSS_DELETEPRINTER, api_spoolss_deleteprinter },
569 {"SPOOLSS_ABORTPRINTER", SPOOLSS_ABORTPRINTER, api_spoolss_abortprinter },
570 {"SPOOLSS_RFFPCNEX", SPOOLSS_RFFPCNEX, api_spoolss_rffpcnex },
571 {"SPOOLSS_RFNPCNEX", SPOOLSS_RFNPCNEX, api_spoolss_rfnpcnex },
572 {"SPOOLSS_ENUMPRINTERS", SPOOLSS_ENUMPRINTERS, api_spoolss_enumprinters },
573 {"SPOOLSS_GETPRINTER", SPOOLSS_GETPRINTER, api_spoolss_getprinter },
574 {"SPOOLSS_GETPRINTERDRIVER2", SPOOLSS_GETPRINTERDRIVER2, api_spoolss_getprinterdriver2 },
575 {"SPOOLSS_STARTPAGEPRINTER", SPOOLSS_STARTPAGEPRINTER, api_spoolss_startpageprinter },
576 {"SPOOLSS_ENDPAGEPRINTER", SPOOLSS_ENDPAGEPRINTER, api_spoolss_endpageprinter },
577 {"SPOOLSS_STARTDOCPRINTER", SPOOLSS_STARTDOCPRINTER, api_spoolss_startdocprinter },
578 {"SPOOLSS_ENDDOCPRINTER", SPOOLSS_ENDDOCPRINTER, api_spoolss_enddocprinter },
579 {"SPOOLSS_WRITEPRINTER", SPOOLSS_WRITEPRINTER, api_spoolss_writeprinter },
580 {"SPOOLSS_SETPRINTER", SPOOLSS_SETPRINTER, api_spoolss_setprinter },
581 {"SPOOLSS_FCPN", SPOOLSS_FCPN, api_spoolss_fcpn },
582 {"SPOOLSS_ADDJOB", SPOOLSS_ADDJOB, api_spoolss_addjob },
583 {"SPOOLSS_ENUMJOBS", SPOOLSS_ENUMJOBS, api_spoolss_enumjobs },
584 {"SPOOLSS_SCHEDULEJOB", SPOOLSS_SCHEDULEJOB, api_spoolss_schedulejob },
585 {"SPOOLSS_SETJOB", SPOOLSS_SETJOB, api_spoolss_setjob },
586 {"SPOOLSS_ENUMFORMS", SPOOLSS_ENUMFORMS, api_spoolss_enumforms },
587 {"SPOOLSS_ENUMPORTS", SPOOLSS_ENUMPORTS, api_spoolss_enumports },
588 {"SPOOLSS_ENUMPRINTERDRIVERS", SPOOLSS_ENUMPRINTERDRIVERS, api_spoolss_enumprinterdrivers },
589 {"SPOOLSS_ADDPRINTEREX", SPOOLSS_ADDPRINTEREX, api_spoolss_addprinterex },
590 {"SPOOLSS_ADDPRINTERDRIVER", SPOOLSS_ADDPRINTERDRIVER, api_spoolss_addprinterdriver },
591 {"SPOOLSS_DELETEPRINTERDRIVER", SPOOLSS_DELETEPRINTERDRIVER, api_spoolss_deleteprinterdriver },
592 {"SPOOLSS_GETPRINTERDRIVERDIRECTORY", SPOOLSS_GETPRINTERDRIVERDIRECTORY, api_spoolss_getprinterdriverdirectory },
593 {"SPOOLSS_ENUMPRINTERDATA", SPOOLSS_ENUMPRINTERDATA, api_spoolss_enumprinterdata },
594 {"SPOOLSS_SETPRINTERDATA", SPOOLSS_SETPRINTERDATA, api_spoolss_setprinterdata },
595 {"SPOOLSS_RESETPRINTER", SPOOLSS_RESETPRINTER, api_spoolss_reset_printer },
596 {"SPOOLSS_DELETEPRINTERDATA", SPOOLSS_DELETEPRINTERDATA, api_spoolss_deleteprinterdata },
597 {"SPOOLSS_ADDFORM", SPOOLSS_ADDFORM, api_spoolss_addform },
598 {"SPOOLSS_DELETEFORM", SPOOLSS_DELETEFORM, api_spoolss_deleteform },
599 {"SPOOLSS_GETFORM", SPOOLSS_GETFORM, api_spoolss_getform },
600 {"SPOOLSS_SETFORM", SPOOLSS_SETFORM, api_spoolss_setform },
601 {"SPOOLSS_ADDPRINTPROCESSOR", SPOOLSS_ADDPRINTPROCESSOR, api_spoolss_addprintprocessor },
602 {"SPOOLSS_ENUMPRINTPROCESSORS", SPOOLSS_ENUMPRINTPROCESSORS, api_spoolss_enumprintprocessors },
603 {"SPOOLSS_ENUMMONITORS", SPOOLSS_ENUMMONITORS, api_spoolss_enumprintmonitors },
604 {"SPOOLSS_GETJOB", SPOOLSS_GETJOB, api_spoolss_getjob },
605 {"SPOOLSS_ENUMPRINTPROCDATATYPES", SPOOLSS_ENUMPRINTPROCDATATYPES, api_spoolss_enumprintprocdatatypes },
606 {"SPOOLSS_GETPRINTERDATAEX", SPOOLSS_GETPRINTERDATAEX, api_spoolss_getprinterdataex },
607 {"SPOOLSS_SETPRINTERDATAEX", SPOOLSS_SETPRINTERDATAEX, api_spoolss_setprinterdataex },
608 {"SPOOLSS_DELETEPRINTERDATAEX", SPOOLSS_DELETEPRINTERDATAEX, api_spoolss_deleteprinterdataex },
609 {"SPOOLSS_ENUMPRINTERDATAEX", SPOOLSS_ENUMPRINTERDATAEX, api_spoolss_enumprinterdataex },
610 {"SPOOLSS_ENUMPRINTERKEY", SPOOLSS_ENUMPRINTERKEY, api_spoolss_enumprinterkey },
611 {"SPOOLSS_DELETEPRINTERKEY", SPOOLSS_DELETEPRINTERKEY, api_spoolss_deleteprinterkey },
612 {"SPOOLSS_GETPRINTPROCESSORDIRECTORY",SPOOLSS_GETPRINTPROCESSORDIRECTORY,api_spoolss_getprintprocessordirectory},
613 {"SPOOLSS_ADDPRINTERDRIVEREX", SPOOLSS_ADDPRINTERDRIVEREX, api_spoolss_addprinterdriverex },
614 {"SPOOLSS_DELETEPRINTERDRIVEREX", SPOOLSS_DELETEPRINTERDRIVEREX, api_spoolss_deleteprinterdriverex },
615 {"SPOOLSS_XCVDATAPORT", SPOOLSS_XCVDATAPORT, api_spoolss_xcvdataport },
618 void spoolss2_get_pipe_fns( struct api_struct **fns, int *n_fns )
620 *fns = api_spoolss_cmds;
621 *n_fns = sizeof(api_spoolss_cmds) / sizeof(struct api_struct);
624 NTSTATUS rpc_spoolss2_init(void)
626 return rpc_srv_register(
627 SMB_RPC_INTERFACE_VERSION, "spoolss", "spoolss",
628 &ndr_table_spoolss,
629 api_spoolss_cmds,
630 sizeof(api_spoolss_cmds) / sizeof(struct api_struct));