rewrote enumprinterdata. still a bug in it but reproducing it hard and
[kai/samba.git] / source3 / rpc_server / srv_spoolss.c
1 /* 
2  *  Unix SMB/Netbios implementation.
3  *  Version 1.9.
4  *  RPC Pipe client / server routines
5  *  Copyright (C) Andrew Tridgell              1992-2000,
6  *  Copyright (C) Luke Kenneth Casson Leighton 1996-2000,
7  *  Copyright (C) Jean François Micouleau      1998-2000.
8  *  
9  *  This program is free software; you can redistribute it and/or modify
10  *  it under the terms of the GNU General Public License as published by
11  *  the Free Software Foundation; either version 2 of the License, or
12  *  (at your option) any later version.
13  *  
14  *  This program is distributed in the hope that it will be useful,
15  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
16  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17  *  GNU General Public License for more details.
18  *  
19  *  You should have received a copy of the GNU General Public License
20  *  along with this program; if not, write to the Free Software
21  *  Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
22  */
23
24 #include "includes.h"
25 #include "nterr.h"
26
27 extern int DEBUGLEVEL;
28
29 /********************************************************************
30  * api_spoolss_open_printer_ex
31  ********************************************************************/
32 static BOOL api_spoolss_open_printer_ex(uint16 vuid, prs_struct *data, prs_struct *rdata)
33 {
34         SPOOL_Q_OPEN_PRINTER_EX q_u;
35         SPOOL_R_OPEN_PRINTER_EX r_u;
36         UNISTR2 *printername = NULL;
37
38         ZERO_STRUCT(q_u);
39         ZERO_STRUCT(r_u);
40
41         if (!spoolss_io_q_open_printer_ex("", &q_u, data, 0)) {
42                 DEBUG(0,("spoolss_io_q_open_printer_ex: unable to unmarshall SPOOL_Q_OPEN_PRINTER_EX.\n"));
43                 return False;
44         }
45
46         if (q_u.printername_ptr != 0)
47                 printername = &q_u.printername;
48
49         r_u.status = _spoolss_open_printer_ex( printername,
50                                                &q_u.printer_default,
51                                                q_u.user_switch, q_u.user_ctr,
52                                                &r_u.handle);
53
54         if (!spoolss_io_r_open_printer_ex("",&r_u,rdata,0)){
55                 DEBUG(0,("spoolss_io_r_open_printer_ex: unable to marshall SPOOL_R_OPEN_PRINTER_EX.\n"));
56                 return False;
57         }
58
59         return True;
60 }
61
62 /********************************************************************
63  * api_spoolss_getprinterdata
64  *
65  * called from the spoolss dispatcher
66  ********************************************************************/
67 static BOOL api_spoolss_getprinterdata(uint16 vuid, prs_struct *data, prs_struct *rdata) 
68 {
69         SPOOL_Q_GETPRINTERDATA q_u;
70         SPOOL_R_GETPRINTERDATA r_u;
71
72         ZERO_STRUCT(q_u);
73         ZERO_STRUCT(r_u);
74
75         /* read the stream and fill the struct */
76         if (!spoolss_io_q_getprinterdata("", &q_u, data, 0)) {
77                 DEBUG(0,("spoolss_io_q_getprinterdata: unable to unmarshall SPOOL_Q_GETPRINTERDATA.\n"));
78                 return False;
79         }
80         
81         r_u.status = _spoolss_getprinterdata( &q_u.handle, &q_u.valuename,
82                                               q_u.size, &r_u.type, &r_u.size,
83                                               &r_u.data, &r_u.needed);
84
85         if (!spoolss_io_r_getprinterdata("", &r_u, rdata, 0)) {
86                 DEBUG(0,("spoolss_io_r_getprinterdata: unable to marshall SPOOL_R_GETPRINTERDATA.\n"));
87                 return False;
88         }
89
90         safe_free(r_u.data);
91
92         return True;
93 }
94
95 /********************************************************************
96  * api_spoolss_closeprinter
97  *
98  * called from the spoolss dispatcher
99  ********************************************************************/
100 static BOOL api_spoolss_closeprinter(uint16 vuid, prs_struct *data, prs_struct *rdata) 
101 {
102         SPOOL_Q_CLOSEPRINTER q_u;
103         SPOOL_R_CLOSEPRINTER r_u;
104
105         ZERO_STRUCT(q_u);
106         ZERO_STRUCT(r_u);
107
108         if (!spoolss_io_q_closeprinter("", &q_u, data, 0)) {
109                 DEBUG(0,("spoolss_io_q_closeprinter: unable to unmarshall SPOOL_Q_CLOSEPRINTER.\n"));
110                 return False;
111         }
112
113         r_u.status = _spoolss_closeprinter(&q_u.handle);
114         memcpy(&r_u.handle, &q_u.handle, sizeof(r_u.handle));
115
116         if (!spoolss_io_r_closeprinter("",&r_u,rdata,0)) {
117                 DEBUG(0,("spoolss_io_r_closeprinter: unable to marshall SPOOL_R_CLOSEPRINTER.\n"));
118                 return False;
119         }
120
121         return True;
122 }
123
124 /********************************************************************
125  * api_spoolss_rffpcnex
126  * ReplyFindFirstPrinterChangeNotifyEx
127  ********************************************************************/
128 static BOOL api_spoolss_rffpcnex(uint16 vuid, prs_struct *data, prs_struct *rdata) 
129 {
130         SPOOL_Q_RFFPCNEX q_u;
131         SPOOL_R_RFFPCNEX r_u;
132
133         ZERO_STRUCT(q_u);
134         ZERO_STRUCT(r_u);
135
136         if (!spoolss_io_q_rffpcnex("", &q_u, data, 0)) {
137                 DEBUG(0,("spoolss_io_q_rffpcnex: unable to unmarshall SPOOL_Q_RFFPCNEX.\n"));
138                 return False;
139         }
140
141         r_u.status = _spoolss_rffpcnex(&q_u.handle, q_u.flags,
142                                        q_u.options, &q_u.localmachine,
143                                        q_u.printerlocal, q_u.option);
144
145         if (!spoolss_io_r_rffpcnex("", &r_u, rdata, 0)) {
146                 DEBUG(0,("spoolss_io_r_rffpcnex: unable to marshall SPOOL_R_RFFPCNEX.\n"));
147                 return False;
148         }
149
150         return True;
151 }
152
153
154 /********************************************************************
155  * api_spoolss_rfnpcnex
156  * ReplyFindNextPrinterChangeNotifyEx
157  * called from the spoolss dispatcher
158  *
159  ********************************************************************/
160 static BOOL api_spoolss_rfnpcnex(uint16 vuid, prs_struct *data, prs_struct *rdata) 
161 {
162         SPOOL_Q_RFNPCNEX q_u;
163         SPOOL_R_RFNPCNEX r_u;
164
165         ZERO_STRUCT(q_u);
166         ZERO_STRUCT(r_u);
167
168         if (!spoolss_io_q_rfnpcnex("", &q_u, data, 0)) {
169                 DEBUG(0,("spoolss_io_q_rfnpcnex: unable to unmarshall SPOOL_Q_RFNPCNEX.\n"));
170                 return False;
171         }
172
173         r_u.status = _spoolss_rfnpcnex(&q_u.handle, q_u.change,
174                                        q_u.option, &r_u.info);
175
176         /* we always have a NOTIFY_INFO struct */
177         r_u.info_ptr=0x1;
178
179         if (!spoolss_io_r_rfnpcnex("", &r_u, rdata, 0)) {
180                 DEBUG(0,("spoolss_io_r_rfnpcnex: unable to marshall SPOOL_R_RFNPCNEX.\n"));
181                 return False;
182         }
183
184         safe_free(r_u.info.data);
185
186         return True;
187 }
188
189
190 /********************************************************************
191  * api_spoolss_enumprinters
192  * called from the spoolss dispatcher
193  *
194  ********************************************************************/
195 static BOOL api_spoolss_enumprinters(uint16 vuid, prs_struct *data, prs_struct *rdata) 
196 {
197         SPOOL_Q_ENUMPRINTERS q_u;
198         SPOOL_R_ENUMPRINTERS r_u;
199
200         ZERO_STRUCT(q_u);
201         ZERO_STRUCT(r_u);
202
203         new_spoolss_allocate_buffer(&q_u.buffer);
204
205         if (!spoolss_io_q_enumprinters("", &q_u, data, 0)) {
206                 DEBUG(0,("spoolss_io_q_enumprinters: unable to unmarshall SPOOL_Q_ENUMPRINTERS.\n"));
207                 return False;
208         }
209
210         /* that's an [in out] buffer */
211         new_spoolss_move_buffer(q_u.buffer, &r_u.buffer);
212
213         r_u.status = _spoolss_enumprinters( q_u.flags, &q_u.servername, q_u.level,
214                                             r_u.buffer, q_u.offered,
215                                             &r_u.needed, &r_u.returned);
216
217         if (!new_spoolss_io_r_enumprinters("", &r_u, rdata, 0)) {
218                 DEBUG(0,("new_spoolss_io_r_enumprinters: unable to marshall SPOOL_R_ENUMPRINTERS.\n"));
219                 new_spoolss_free_buffer(q_u.buffer);
220                 return False;
221         }
222
223         new_spoolss_free_buffer(q_u.buffer);
224
225         return True;
226 }
227
228 /********************************************************************
229  * api_spoolss_getprinter
230  * called from the spoolss dispatcher
231  *
232  ********************************************************************/
233 static BOOL api_spoolss_getprinter(uint16 vuid, prs_struct *data, prs_struct *rdata) 
234 {
235         SPOOL_Q_GETPRINTER q_u;
236         SPOOL_R_GETPRINTER r_u;
237
238         ZERO_STRUCT(q_u);
239         ZERO_STRUCT(r_u);
240
241         new_spoolss_allocate_buffer(&q_u.buffer);
242
243         if(!spoolss_io_q_getprinter("", &q_u, data, 0)) {
244                 DEBUG(0,("spoolss_io_q_getprinter: unable to unmarshall SPOOL_Q_GETPRINTER.\n"));
245                 return False;
246         }
247
248         /* that's an [in out] buffer */
249         new_spoolss_move_buffer(q_u.buffer, &r_u.buffer);
250
251         r_u.status = _spoolss_getprinter(&q_u.handle, q_u.level,
252                                          r_u.buffer, q_u.offered, 
253                                          &r_u.needed);
254
255         if(!spoolss_io_r_getprinter("",&r_u,rdata,0)) {
256                 DEBUG(0,("spoolss_io_r_getprinter: unable to marshall SPOOL_R_GETPRINTER.\n"));
257                 new_spoolss_free_buffer(q_u.buffer);
258                 return False;
259         }
260
261         new_spoolss_free_buffer(q_u.buffer);
262         return True;
263 }
264
265
266 /********************************************************************
267  * api_spoolss_getprinter
268  * called from the spoolss dispatcher
269  *
270  ********************************************************************/
271 static BOOL api_spoolss_getprinterdriver2(uint16 vuid, prs_struct *data, prs_struct *rdata)
272 {
273         SPOOL_Q_GETPRINTERDRIVER2 q_u;
274         SPOOL_R_GETPRINTERDRIVER2 r_u;
275
276         ZERO_STRUCT(q_u);
277         ZERO_STRUCT(r_u);
278
279         new_spoolss_allocate_buffer(&q_u.buffer);
280
281         if(!spoolss_io_q_getprinterdriver2("", &q_u, data, 0)) {
282                 DEBUG(0,("spoolss_io_q_getprinterdriver2: unable to unmarshall SPOOL_Q_GETPRINTERDRIVER2.\n"));
283                 return False;
284         }
285
286         /* that's an [in out] buffer */
287         new_spoolss_move_buffer(q_u.buffer, &r_u.buffer);
288
289         r_u.status = _spoolss_getprinterdriver2(&q_u.handle, &q_u.architecture, q_u.level, q_u.unknown,
290                                                 r_u.buffer, q_u.offered,
291                                                 &r_u.needed, &r_u.unknown0, &r_u.unknown1);
292         
293         if(!spoolss_io_r_getprinterdriver2("",&r_u,rdata,0)) {
294                 DEBUG(0,("spoolss_io_r_getprinterdriver2: unable to marshall SPOOL_R_GETPRINTERDRIVER2.\n"));
295                 new_spoolss_free_buffer(q_u.buffer);
296                 return False;
297         }
298         
299         new_spoolss_free_buffer(q_u.buffer);
300         return True;
301 }
302
303 /********************************************************************
304  * api_spoolss_getprinter
305  * called from the spoolss dispatcher
306  *
307  ********************************************************************/
308 static BOOL api_spoolss_startpageprinter(uint16 vuid, prs_struct *data, prs_struct *rdata)
309 {
310         SPOOL_Q_STARTPAGEPRINTER q_u;
311         SPOOL_R_STARTPAGEPRINTER r_u;
312
313         ZERO_STRUCT(q_u);
314         ZERO_STRUCT(r_u);
315
316         if(!spoolss_io_q_startpageprinter("", &q_u, data, 0)) {
317                 DEBUG(0,("spoolss_io_q_startpageprinter: unable to unmarshall SPOOL_Q_STARTPAGEPRINTER.\n"));
318                 return False;
319         }
320
321         r_u.status = _spoolss_startpageprinter(&q_u.handle);
322
323         if(!spoolss_io_r_startpageprinter("",&r_u,rdata,0)) {
324                 DEBUG(0,("spoolss_io_r_startpageprinter: unable to marshall SPOOL_R_STARTPAGEPRINTER.\n"));
325                 return False;
326         }
327
328         return True;
329 }
330
331
332 /********************************************************************
333  * api_spoolss_getprinter
334  * called from the spoolss dispatcher
335  *
336  ********************************************************************/
337 static BOOL api_spoolss_endpageprinter(uint16 vuid, prs_struct *data, prs_struct *rdata)
338 {
339         SPOOL_Q_ENDPAGEPRINTER q_u;
340         SPOOL_R_ENDPAGEPRINTER r_u;
341
342         ZERO_STRUCT(q_u);
343         ZERO_STRUCT(r_u);
344
345         if(!spoolss_io_q_endpageprinter("", &q_u, data, 0)) {
346                 DEBUG(0,("spoolss_io_q_endpageprinter: unable to unmarshall SPOOL_Q_ENDPAGEPRINTER.\n"));
347                 return False;
348         }
349
350         r_u.status = _spoolss_endpageprinter(&q_u.handle);
351
352         if(!spoolss_io_r_endpageprinter("",&r_u,rdata,0)) {
353                 DEBUG(0,("spoolss_io_r_endpageprinter: unable to marshall SPOOL_R_ENDPAGEPRINTER.\n"));
354                 return False;
355         }
356
357         return True;
358 }
359
360 /********************************************************************
361 ********************************************************************/
362 static BOOL api_spoolss_startdocprinter(uint16 vuid, prs_struct *data, prs_struct *rdata)
363 {
364         SPOOL_Q_STARTDOCPRINTER q_u;
365         SPOOL_R_STARTDOCPRINTER r_u;
366
367         ZERO_STRUCT(q_u);
368         ZERO_STRUCT(r_u);
369
370         if(!spoolss_io_q_startdocprinter("", &q_u, data, 0)) {
371                 DEBUG(0,("spoolss_io_q_startdocprinter: unable to unmarshall SPOOL_Q_STARTDOCPRINTER.\n"));
372                 return False;
373         }
374
375         r_u.status = _spoolss_startdocprinter(&q_u.handle,
376                                   q_u.doc_info_container.level,
377                                   &q_u.doc_info_container.docinfo,
378                                   &r_u.jobid);
379
380         if(!spoolss_io_r_startdocprinter("",&r_u,rdata,0)) {
381                 DEBUG(0,("spoolss_io_r_startdocprinter: unable to marshall SPOOL_R_STARTDOCPRINTER.\n"));
382                 return False;
383         }
384
385         return True;
386 }
387
388
389 /********************************************************************
390 ********************************************************************/
391 static BOOL api_spoolss_enddocprinter(uint16 vuid, prs_struct *data, prs_struct *rdata)
392 {
393         SPOOL_Q_ENDDOCPRINTER q_u;
394         SPOOL_R_ENDDOCPRINTER r_u;
395
396         ZERO_STRUCT(q_u);
397         ZERO_STRUCT(r_u);
398
399         if(!spoolss_io_q_enddocprinter("", &q_u, data, 0)) {
400                 DEBUG(0,("spoolss_io_q_enddocprinter: unable to unmarshall SPOOL_Q_ENDDOCPRINTER.\n"));
401                 return False;
402         }
403
404         r_u.status = _spoolss_enddocprinter(&q_u.handle);
405
406         if(!spoolss_io_r_enddocprinter("",&r_u,rdata,0)) {
407                 DEBUG(0,("spoolss_io_r_enddocprinter: unable to marshall SPOOL_R_ENDDOCPRINTER.\n"));
408                 return False;
409         }
410
411         return True;            
412 }
413
414
415 /********************************************************************
416 ********************************************************************/
417 static BOOL api_spoolss_writeprinter(uint16 vuid, prs_struct *data, prs_struct *rdata)
418 {
419         SPOOL_Q_WRITEPRINTER q_u;
420         SPOOL_R_WRITEPRINTER r_u;
421
422         ZERO_STRUCT(q_u);
423         ZERO_STRUCT(r_u);
424
425         if(!spoolss_io_q_writeprinter("", &q_u, data, 0)) {
426                 DEBUG(0,("spoolss_io_q_writeprinter: unable to unmarshall SPOOL_Q_WRITEPRINTER.\n"));
427                 return False;
428         }
429
430         r_u.status = _spoolss_writeprinter(&q_u.handle,
431                                            q_u.buffer_size,
432                                            q_u.buffer,
433                                            &q_u.buffer_size2);
434         r_u.buffer_written = q_u.buffer_size2;
435         safe_free(q_u.buffer);
436
437         if(!spoolss_io_r_writeprinter("",&r_u,rdata,0)) {
438                 DEBUG(0,("spoolss_io_r_writeprinter: unable to marshall SPOOL_R_WRITEPRINTER.\n"));
439                 return False;
440         }
441
442         return True;
443 }
444
445 /****************************************************************************
446
447 ****************************************************************************/
448 static BOOL api_spoolss_setprinter(uint16 vuid, prs_struct *data, prs_struct *rdata)
449 {
450         SPOOL_Q_SETPRINTER q_u;
451         SPOOL_R_SETPRINTER r_u;
452
453         ZERO_STRUCT(q_u);
454         ZERO_STRUCT(r_u);
455
456         if(!spoolss_io_q_setprinter("", &q_u, data, 0)) {
457                 DEBUG(0,("spoolss_io_q_setprinter: unable to unmarshall SPOOL_Q_SETPRINTER.\n"));
458                 return False;
459         }
460         
461         r_u.status = _spoolss_setprinter(&q_u.handle, q_u.level, &q_u.info,
462                                          q_u.devmode_ctr, q_u.command);
463         
464         /* now, we can free the memory */
465         if (q_u.info.level==2 && q_u.info.info_ptr!=0)
466                 safe_free(q_u.info.info_2);
467                 
468         if (q_u.devmode_ctr.devmode_ptr!=0)
469                 safe_free(q_u.devmode_ctr.devmode);
470         
471         if(!spoolss_io_r_setprinter("",&r_u,rdata,0)) {
472                 DEBUG(0,("spoolss_io_r_setprinter: unable to marshall SPOOL_R_SETPRINTER.\n"));
473                 return False;
474         }
475
476         return True;
477 }
478
479 /****************************************************************************
480 ****************************************************************************/
481 static BOOL api_spoolss_fcpn(uint16 vuid, prs_struct *data, prs_struct *rdata)
482 {
483         SPOOL_Q_FCPN q_u;
484         SPOOL_R_FCPN r_u;
485
486         ZERO_STRUCT(q_u);
487         ZERO_STRUCT(r_u);
488
489         if(!spoolss_io_q_fcpn("", &q_u, data, 0)) {
490                 DEBUG(0,("spoolss_io_q_fcpn: unable to unmarshall SPOOL_Q_FCPN.\n"));
491                 return False;
492         }
493
494         r_u.status = _spoolss_fcpn(&q_u.handle);
495
496         if(!spoolss_io_r_fcpn("",&r_u,rdata,0)) {
497                 DEBUG(0,("spoolss_io_r_fcpn: unable to marshall SPOOL_R_FCPN.\n"));
498                 return False;
499         }
500
501         return True;
502 }
503
504
505 /****************************************************************************
506 ****************************************************************************/
507 static BOOL api_spoolss_addjob(uint16 vuid, prs_struct *data, prs_struct *rdata)
508 {
509         SPOOL_Q_ADDJOB q_u;
510         SPOOL_R_ADDJOB r_u;
511
512         ZERO_STRUCT(q_u);
513         ZERO_STRUCT(r_u);
514
515         new_spoolss_allocate_buffer(&q_u.buffer);
516
517         if(!spoolss_io_q_addjob("", &q_u, data, 0)) {
518                 DEBUG(0,("spoolss_io_q_addjob: unable to unmarshall SPOOL_Q_ADDJOB.\n"));
519                 return False;
520         }
521
522         /* that's only an [in] buffer ! */
523
524         r_u.status = _spoolss_addjob(&q_u.handle, q_u.level,
525                                      q_u.buffer, q_u.offered);
526                 
527         if(!spoolss_io_r_addjob("",&r_u,rdata,0)) {
528                 DEBUG(0,("spoolss_io_r_addjob: unable to marshall SPOOL_R_ADDJOB.\n"));
529                 new_spoolss_free_buffer(q_u.buffer);
530                 return False;
531         }
532
533         new_spoolss_free_buffer(q_u.buffer);
534
535         return True;            
536 }
537
538
539 /****************************************************************************
540 ****************************************************************************/
541 static BOOL api_spoolss_enumjobs(uint16 vuid, prs_struct *data, prs_struct *rdata)
542 {
543         SPOOL_Q_ENUMJOBS q_u;
544         SPOOL_R_ENUMJOBS r_u;
545
546         ZERO_STRUCT(q_u);
547         ZERO_STRUCT(r_u);
548
549         new_spoolss_allocate_buffer(&q_u.buffer);
550
551         if (!spoolss_io_q_enumjobs("", &q_u, data, 0)) {
552                 DEBUG(0,("spoolss_io_q_enumjobs: unable to unmarshall SPOOL_Q_ENUMJOBS.\n"));
553                 return False;
554         }
555
556         /* that's an [in out] buffer */
557         new_spoolss_move_buffer(q_u.buffer, &r_u.buffer);
558
559         r_u.status = _spoolss_enumjobs(&q_u.handle, q_u.firstjob, q_u.numofjobs, q_u.level,
560                                         r_u.buffer, q_u.offered,
561                                         &r_u.needed, &r_u.returned);
562
563         if (!spoolss_io_r_enumjobs("",&r_u,rdata,0)) {
564                 DEBUG(0,("spoolss_io_r_enumjobs: unable to marshall SPOOL_R_ENUMJOBS.\n"));
565                 new_spoolss_free_buffer(q_u.buffer);
566                 return False;
567         }
568
569         new_spoolss_free_buffer(q_u.buffer);
570
571         return True;
572 }
573
574
575 /****************************************************************************
576 ****************************************************************************/
577 static BOOL api_spoolss_schedulejob(uint16 vuid, prs_struct *data, prs_struct *rdata)
578 {
579         SPOOL_Q_SCHEDULEJOB q_u;
580         SPOOL_R_SCHEDULEJOB r_u;
581
582         ZERO_STRUCT(q_u);
583         ZERO_STRUCT(r_u);
584
585         if(!spoolss_io_q_schedulejob("", &q_u, data, 0)) {
586                 DEBUG(0,("spoolss_io_q_schedulejob: unable to unmarshall SPOOL_Q_SCHEDULEJOB.\n"));
587                 return False;
588         }
589
590         r_u.status = _spoolss_schedulejob(&q_u.handle, q_u.jobid);
591
592         if(!spoolss_io_r_schedulejob("",&r_u,rdata,0)) {
593                 DEBUG(0,("spoolss_io_r_schedulejob: unable to marshall SPOOL_R_SCHEDULEJOB.\n"));
594                 return False;
595         }
596
597         return True;
598 }
599
600 /****************************************************************************
601 ****************************************************************************/
602 static BOOL api_spoolss_setjob(uint16 vuid, prs_struct *data, prs_struct *rdata)
603 {
604         SPOOL_Q_SETJOB q_u;
605         SPOOL_R_SETJOB r_u;
606
607         ZERO_STRUCT(q_u);
608         ZERO_STRUCT(r_u);
609
610         if(!spoolss_io_q_setjob("", &q_u, data, 0)) {
611                 DEBUG(0,("spoolss_io_q_setjob: unable to unmarshall SPOOL_Q_SETJOB.\n"));
612                 return False;
613         }
614
615         r_u.status = _spoolss_setjob(&q_u.handle, q_u.jobid,
616                                 q_u.level, &q_u.ctr, q_u.command);
617
618         if(!spoolss_io_r_setjob("",&r_u,rdata,0)) {
619                 DEBUG(0,("spoolss_io_r_setjob: unable to marshall SPOOL_R_SETJOB.\n"));
620                 return False;
621         }
622
623         return True;
624 }
625
626 /****************************************************************************
627 ****************************************************************************/
628
629 static BOOL api_spoolss_enumprinterdrivers(uint16 vuid, prs_struct *data, prs_struct *rdata)
630 {
631         SPOOL_Q_ENUMPRINTERDRIVERS q_u;
632         SPOOL_R_ENUMPRINTERDRIVERS r_u;
633
634         ZERO_STRUCT(q_u);
635         ZERO_STRUCT(r_u);
636
637         new_spoolss_allocate_buffer(&q_u.buffer);
638
639         if (!spoolss_io_q_enumprinterdrivers("", &q_u, data, 0)) {
640                 DEBUG(0,("spoolss_io_q_enumprinterdrivers: unable to unmarshall SPOOL_Q_ENUMPRINTERDRIVERS.\n"));
641                 return False;
642         }
643
644         /* that's an [in out] buffer */
645         new_spoolss_move_buffer(q_u.buffer, &r_u.buffer);
646
647         r_u.status = _spoolss_enumprinterdrivers(&q_u.name, &q_u.environment, q_u.level,
648                                                  r_u.buffer, q_u.offered,
649                                                  &r_u.needed, &r_u.returned);
650
651         if (!new_spoolss_io_r_enumprinterdrivers("",&r_u,rdata,0)) {
652                 DEBUG(0,("new_spoolss_io_r_enumprinterdrivers: unable to marshall SPOOL_R_ENUMPRINTERDRIVERS.\n"));
653                 new_spoolss_free_buffer(q_u.buffer);
654                 return False;
655         }
656
657         new_spoolss_free_buffer(q_u.buffer);
658
659         return True;
660 }
661
662
663 /****************************************************************************
664 ****************************************************************************/
665 static BOOL api_spoolss_enumforms(uint16 vuid, prs_struct *data, prs_struct *rdata)
666 {
667         SPOOL_Q_ENUMFORMS q_u;
668         SPOOL_R_ENUMFORMS r_u;
669
670         ZERO_STRUCT(q_u);
671         ZERO_STRUCT(r_u);
672
673         new_spoolss_allocate_buffer(&q_u.buffer);
674
675         if (!spoolss_io_q_enumforms("", &q_u, data, 0)) {
676                 DEBUG(0,("spoolss_io_q_enumforms: unable to unmarshall SPOOL_Q_ENUMFORMS.\n"));
677                 return False;
678         }
679
680         /* that's an [in out] buffer */
681         new_spoolss_move_buffer(q_u.buffer, &r_u.buffer);
682
683         r_u.status = _new_spoolss_enumforms(&q_u.handle, q_u.level, 
684                                 r_u.buffer, q_u.offered,
685                                 &r_u.needed, &r_u.numofforms);
686
687         if (!new_spoolss_io_r_enumforms("",&r_u,rdata,0)) {
688                 DEBUG(0,("new_spoolss_io_r_enumforms: unable to marshall SPOOL_R_ENUMFORMS.\n"));
689                 new_spoolss_free_buffer(q_u.buffer);
690                 return False;
691         }
692
693         new_spoolss_free_buffer(q_u.buffer);
694
695         return True;
696 }
697
698
699 /****************************************************************************
700 ****************************************************************************/
701 static BOOL api_spoolss_enumports(uint16 vuid, prs_struct *data, prs_struct *rdata)
702 {
703         SPOOL_Q_ENUMPORTS q_u;
704         SPOOL_R_ENUMPORTS r_u;
705
706         ZERO_STRUCT(q_u);
707         ZERO_STRUCT(r_u);
708
709         new_spoolss_allocate_buffer(&q_u.buffer);
710
711         if(!spoolss_io_q_enumports("", &q_u, data, 0)) {
712                 DEBUG(0,("spoolss_io_q_enumports: unable to unmarshall SPOOL_Q_ENUMPORTS.\n"));
713                 return False;
714         }
715
716         /* that's an [in out] buffer */
717         new_spoolss_move_buffer(q_u.buffer, &r_u.buffer);
718
719         r_u.status = _spoolss_enumports(&q_u.name, q_u.level,
720                                         r_u.buffer, q_u.offered,
721                                         &r_u.needed, &r_u.returned);
722
723         if (!new_spoolss_io_r_enumports("",&r_u,rdata,0)) {
724                 DEBUG(0,("new_spoolss_io_r_enumports: unable to marshall SPOOL_R_ENUMPORTS.\n"));
725                 new_spoolss_free_buffer(q_u.buffer);
726                 return False;
727         }
728
729         new_spoolss_free_buffer(q_u.buffer);
730
731         return True;
732 }
733
734
735 /****************************************************************************
736 ****************************************************************************/
737 static BOOL api_spoolss_addprinterex(uint16 vuid, prs_struct *data, prs_struct *rdata)
738 {
739         SPOOL_Q_ADDPRINTEREX q_u;
740         SPOOL_R_ADDPRINTEREX r_u;
741         
742         ZERO_STRUCT(q_u);
743         ZERO_STRUCT(r_u);
744         
745         if(!spoolss_io_q_addprinterex("", &q_u, data, 0)) {
746                 DEBUG(0,("spoolss_io_q_addprinterex: unable to unmarshall SPOOL_Q_ADDPRINTEREX.\n"));
747                 return False;
748         }
749         
750         r_u.status = _spoolss_addprinterex(&q_u.server_name,
751                                 q_u.level, &q_u.info,
752                                 q_u.unk0, q_u.unk1, q_u.unk2, q_u.unk3,
753                                 q_u.user_switch, &q_u.user_ctr,
754                                 &r_u.handle);
755                                 
756         if(!spoolss_io_r_addprinterex("", &r_u, rdata, 0)) {
757                 DEBUG(0,("spoolss_io_r_addprinterex: unable to marshall SPOOL_R_ADDPRINTEREX.\n"));
758                 return False;
759         }
760         
761         return True;
762 }
763
764 /****************************************************************************
765 ****************************************************************************/
766 static BOOL api_spoolss_addprinterdriver(uint16 vuid, prs_struct *data, prs_struct *rdata)
767 {
768         SPOOL_Q_ADDPRINTERDRIVER q_u;
769         SPOOL_R_ADDPRINTERDRIVER r_u;
770         
771         ZERO_STRUCT(q_u);
772         ZERO_STRUCT(r_u);
773         
774         if(!spoolss_io_q_addprinterdriver("", &q_u, data, 0)) {
775                 DEBUG(0,("spoolss_io_q_addprinterdriver: unable to unmarshall SPOOL_Q_ADDPRINTERDRIVER.\n"));
776                 return False;
777         }
778         
779         r_u.status = _spoolss_addprinterdriver(&q_u.server_name, q_u.level, &q_u.info);
780                                 
781         if(!spoolss_io_r_addprinterdriver("", &r_u, rdata, 0)) {
782                 DEBUG(0,("spoolss_io_r_addprinterdriver: unable to marshall SPOOL_R_ADDPRINTERDRIVER.\n"));
783                 return False;
784         }
785         
786         return True;
787 }
788
789 /****************************************************************************
790 ****************************************************************************/
791 static BOOL api_spoolss_getprinterdriverdirectory(uint16 vuid, prs_struct *data, prs_struct *rdata)
792 {
793         SPOOL_Q_GETPRINTERDRIVERDIR q_u;
794         SPOOL_R_GETPRINTERDRIVERDIR r_u;
795
796         ZERO_STRUCT(q_u);
797         ZERO_STRUCT(r_u);
798
799         new_spoolss_allocate_buffer(&q_u.buffer);
800
801         if(!spoolss_io_q_getprinterdriverdir("", &q_u, data, 0)) {
802                 DEBUG(0,("spoolss_io_q_getprinterdriverdir: unable to unmarshall SPOOL_Q_GETPRINTERDRIVERDIR.\n"));
803                 return False;
804         }
805
806         /* that's an [in out] buffer */
807         new_spoolss_move_buffer(q_u.buffer, &r_u.buffer);
808
809         r_u.status = _spoolss_getprinterdriverdirectory(&q_u.name, &q_u.environment, q_u.level,
810                                                         r_u.buffer, q_u.offered,
811                                                         &r_u.needed);
812
813         if(!spoolss_io_r_getprinterdriverdir("", &r_u, rdata, 0)) {
814                 DEBUG(0,("spoolss_io_r_getprinterdriverdir: unable to marshall SPOOL_R_GETPRINTERDRIVERDIR.\n"));
815                 new_spoolss_free_buffer(q_u.buffer);
816                 return False;
817         }
818
819         new_spoolss_free_buffer(q_u.buffer);
820
821         return True;
822 }
823
824 /****************************************************************************
825 ****************************************************************************/
826 static BOOL api_spoolss_enumprinterdata(uint16 vuid, prs_struct *data, prs_struct *rdata)
827 {
828         SPOOL_Q_ENUMPRINTERDATA q_u;
829         SPOOL_R_ENUMPRINTERDATA r_u;
830         
831         ZERO_STRUCT(q_u);
832         ZERO_STRUCT(r_u);
833         
834         if(!spoolss_io_q_enumprinterdata("", &q_u, data, 0)) {
835                 DEBUG(0,("spoolss_io_q_enumprinterdata: unable to unmarshall SPOOL_Q_ENUMPRINTERDATA.\n"));
836                 return False;
837         }
838         
839         r_u.status = _spoolss_enumprinterdata(&q_u.handle, q_u.index, q_u.valuesize, q_u.datasize,
840                                                 &r_u.valuesize, &r_u.value, &r_u.realvaluesize,
841                                                 &r_u.type,
842                                                 &r_u.datasize, &r_u.data, &r_u.realdatasize);
843                                 
844         if(!spoolss_io_r_enumprinterdata("", &r_u, rdata, 0)) {
845                 DEBUG(0,("spoolss_io_r_enumprinterdata: unable to marshall SPOOL_R_ENUMPRINTERDATA.\n"));
846                 safe_free(r_u.value);
847                 safe_free(r_u.data);
848                 return False;
849         }
850
851         safe_free(r_u.value);
852         safe_free(r_u.data);
853
854         return True;
855 }
856
857 /****************************************************************************
858 ****************************************************************************/
859 static BOOL api_spoolss_setprinterdata(uint16 vuid, prs_struct *data, prs_struct *rdata)
860 {
861         SPOOL_Q_SETPRINTERDATA q_u;
862         SPOOL_R_SETPRINTERDATA r_u;     
863         
864         ZERO_STRUCT(q_u);
865         ZERO_STRUCT(r_u);
866         
867         if(!spoolss_io_q_setprinterdata("", &q_u, data, 0)) {
868                 DEBUG(0,("spoolss_io_q_setprinterdata: unable to unmarshall SPOOL_Q_SETPRINTERDATA.\n"));
869                 return False;
870         }
871         
872         r_u.status = _spoolss_setprinterdata(&q_u.handle,
873                                 &q_u.value, q_u.type, q_u.max_len,
874                                 q_u.data, q_u.real_len, q_u.numeric_data);
875                                 
876         if(!spoolss_io_r_setprinterdata("", &r_u, rdata, 0)) {
877                 DEBUG(0,("spoolss_io_r_setprinterdata: unable to marshall SPOOL_R_SETPRINTERDATA.\n"));
878                 return False;
879         }
880
881         return True;
882 }
883
884 /****************************************************************************
885 ****************************************************************************/
886 static BOOL api_spoolss_addform(uint16 vuid, prs_struct *data, prs_struct *rdata)
887 {
888         SPOOL_Q_ADDFORM q_u;
889         SPOOL_R_ADDFORM r_u;
890
891         ZERO_STRUCT(q_u);
892         ZERO_STRUCT(r_u);
893         
894         if(!spoolss_io_q_addform("", &q_u, data, 0)) {
895                 DEBUG(0,("spoolss_io_q_addform: unable to unmarshall SPOOL_Q_ADDFORM.\n"));
896                 return False;
897         }
898         
899         r_u.status = _spoolss_addform(&q_u.handle, q_u.level, &q_u.form);
900         
901         if(!spoolss_io_r_addform("", &r_u, rdata, 0)) {
902                 DEBUG(0,("spoolss_io_r_addform: unable to marshall SPOOL_R_ADDFORM.\n"));
903                 return False;
904         }
905
906         return True;
907 }
908
909 /****************************************************************************
910 ****************************************************************************/
911 static BOOL api_spoolss_setform(uint16 vuid, prs_struct *data, prs_struct *rdata)
912 {
913         SPOOL_Q_SETFORM q_u;
914         SPOOL_R_SETFORM r_u;
915
916         ZERO_STRUCT(q_u);
917         ZERO_STRUCT(r_u);
918         
919         if(!spoolss_io_q_setform("", &q_u, data, 0)) {
920                 DEBUG(0,("spoolss_io_q_setform: unable to unmarshall SPOOL_Q_SETFORM.\n"));
921                 return False;
922         }
923         
924         r_u.status = _spoolss_setform(&q_u.handle, &q_u.name, q_u.level, &q_u.form);
925                                       
926         if(!spoolss_io_r_setform("", &r_u, rdata, 0)) {
927                 DEBUG(0,("spoolss_io_r_setform: unable to marshall SPOOL_R_SETFORM.\n"));
928                 return False;
929         }
930
931         return True;
932 }
933
934 /****************************************************************************
935 ****************************************************************************/
936 static BOOL api_spoolss_enumprintprocessors(uint16 vuid, prs_struct *data, prs_struct *rdata)
937 {
938         SPOOL_Q_ENUMPRINTPROCESSORS q_u;
939         SPOOL_R_ENUMPRINTPROCESSORS r_u;
940
941         ZERO_STRUCT(q_u);
942         ZERO_STRUCT(r_u);
943         
944         new_spoolss_allocate_buffer(&q_u.buffer);
945
946         if(!spoolss_io_q_enumprintprocessors("", &q_u, data, 0)) {
947                 DEBUG(0,("spoolss_io_q_enumprintprocessors: unable to unmarshall SPOOL_Q_ENUMPRINTPROCESSORS.\n"));
948                 return False;
949         }
950         
951         /* that's an [in out] buffer */
952         new_spoolss_move_buffer(q_u.buffer, &r_u.buffer);
953         
954         r_u.status = _spoolss_enumprintprocessors(&q_u.name, &q_u.environment, q_u.level,
955                                                   r_u.buffer, q_u.offered,
956                                                   &r_u.needed, &r_u.returned);
957
958         if(!spoolss_io_r_enumprintprocessors("", &r_u, rdata, 0)) {
959                 DEBUG(0,("spoolss_io_r_enumprintprocessors: unable to marshall SPOOL_R_ENUMPRINTPROCESSORS.\n"));
960                 new_spoolss_free_buffer(q_u.buffer);
961                 return False;
962         }
963         
964         new_spoolss_free_buffer(q_u.buffer);
965         
966         return True;
967 }
968
969 /****************************************************************************
970 ****************************************************************************/
971 static BOOL api_spoolss_enumprintmonitors(uint16 vuid, prs_struct *data, prs_struct *rdata)
972 {
973         SPOOL_Q_ENUMPRINTMONITORS q_u;
974         SPOOL_R_ENUMPRINTMONITORS r_u;
975
976         ZERO_STRUCT(q_u);
977         ZERO_STRUCT(r_u);
978         
979         new_spoolss_allocate_buffer(&q_u.buffer);
980
981         if (!spoolss_io_q_enumprintmonitors("", &q_u, data, 0)) {
982                 DEBUG(0,("spoolss_io_q_enumprintmonitors: unable to unmarshall SPOOL_Q_ENUMPRINTMONITORS.\n"));
983                 return False;
984         }
985                 
986         /* that's an [in out] buffer */
987         new_spoolss_move_buffer(q_u.buffer, &r_u.buffer);
988
989         r_u.status = _spoolss_enumprintmonitors(&q_u.name, q_u.level,
990                                                 r_u.buffer, q_u.offered,
991                                                 &r_u.needed, &r_u.returned);
992
993         if (!spoolss_io_r_enumprintmonitors("", &r_u, rdata, 0)) {
994                 DEBUG(0,("spoolss_io_r_enumprintmonitors: unable to marshall SPOOL_R_ENUMPRINTMONITORS.\n"));
995                 new_spoolss_free_buffer(q_u.buffer);
996                 return False;
997         }
998         
999         new_spoolss_free_buffer(q_u.buffer);
1000         
1001         return True;
1002 }
1003
1004 /****************************************************************************
1005 ****************************************************************************/
1006 static BOOL api_spoolss_getjob(uint16 vuid, prs_struct *data, prs_struct *rdata)
1007 {
1008         SPOOL_Q_GETJOB q_u;
1009         SPOOL_R_GETJOB r_u;
1010         
1011         new_spoolss_allocate_buffer(&q_u.buffer);
1012
1013         if(!spoolss_io_q_getjob("", &q_u, data, 0)) {
1014                 DEBUG(0,("spoolss_io_q_getjob: unable to unmarshall SPOOL_Q_GETJOB.\n"));
1015                 return False;
1016         }
1017
1018         /* that's an [in out] buffer */
1019         new_spoolss_move_buffer(q_u.buffer, &r_u.buffer);
1020
1021         r_u.status = _spoolss_getjob(&q_u.handle, q_u.jobid, q_u.level,
1022                                         r_u.buffer, q_u.offered,
1023                                         &r_u.needed);
1024         
1025         if(!spoolss_io_r_getjob("",&r_u,rdata,0)) {
1026                 DEBUG(0,("spoolss_io_r_getjob: unable to marshall SPOOL_R_GETJOB.\n"));
1027                 new_spoolss_free_buffer(q_u.buffer);
1028                 return False;
1029         }
1030                 
1031         new_spoolss_free_buffer(q_u.buffer);
1032         return True;
1033 }
1034
1035 /*******************************************************************
1036 \pipe\spoolss commands
1037 ********************************************************************/
1038 struct api_struct api_spoolss_cmds[] = 
1039 {
1040  {"SPOOLSS_OPENPRINTEREX",             SPOOLSS_OPENPRINTEREX,             api_spoolss_open_printer_ex           },
1041  {"SPOOLSS_GETPRINTERDATA",            SPOOLSS_GETPRINTERDATA,            api_spoolss_getprinterdata            },
1042  {"SPOOLSS_CLOSEPRINTER",              SPOOLSS_CLOSEPRINTER,              api_spoolss_closeprinter              },
1043  {"SPOOLSS_RFFPCNEX",                  SPOOLSS_RFFPCNEX,                  api_spoolss_rffpcnex                  },
1044  {"SPOOLSS_RFNPCNEX",                  SPOOLSS_RFNPCNEX,                  api_spoolss_rfnpcnex                  },
1045  {"SPOOLSS_ENUMPRINTERS",              SPOOLSS_ENUMPRINTERS,              api_spoolss_enumprinters              },
1046  {"SPOOLSS_GETPRINTER",                SPOOLSS_GETPRINTER,                api_spoolss_getprinter                },
1047  {"SPOOLSS_GETPRINTERDRIVER2",         SPOOLSS_GETPRINTERDRIVER2,         api_spoolss_getprinterdriver2         }, 
1048  {"SPOOLSS_STARTPAGEPRINTER",          SPOOLSS_STARTPAGEPRINTER,          api_spoolss_startpageprinter          },
1049  {"SPOOLSS_ENDPAGEPRINTER",            SPOOLSS_ENDPAGEPRINTER,            api_spoolss_endpageprinter            }, 
1050  {"SPOOLSS_STARTDOCPRINTER",           SPOOLSS_STARTDOCPRINTER,           api_spoolss_startdocprinter           },
1051  {"SPOOLSS_ENDDOCPRINTER",             SPOOLSS_ENDDOCPRINTER,             api_spoolss_enddocprinter             },
1052  {"SPOOLSS_WRITEPRINTER",              SPOOLSS_WRITEPRINTER,              api_spoolss_writeprinter              },
1053  {"SPOOLSS_SETPRINTER",                SPOOLSS_SETPRINTER,                api_spoolss_setprinter                },
1054  {"SPOOLSS_FCPN",                      SPOOLSS_FCPN,                      api_spoolss_fcpn                      },
1055  {"SPOOLSS_ADDJOB",                    SPOOLSS_ADDJOB,                    api_spoolss_addjob                    },
1056  {"SPOOLSS_ENUMJOBS",                  SPOOLSS_ENUMJOBS,                  api_spoolss_enumjobs                  },
1057  {"SPOOLSS_SCHEDULEJOB",               SPOOLSS_SCHEDULEJOB,               api_spoolss_schedulejob               },
1058  {"SPOOLSS_SETJOB",                    SPOOLSS_SETJOB,                    api_spoolss_setjob                    },
1059  {"SPOOLSS_ENUMFORMS",                 SPOOLSS_ENUMFORMS,                 api_spoolss_enumforms                 },
1060  {"SPOOLSS_ENUMPORTS",                 SPOOLSS_ENUMPORTS,                 api_spoolss_enumports                 },
1061  {"SPOOLSS_ENUMPRINTERDRIVERS",        SPOOLSS_ENUMPRINTERDRIVERS,        api_spoolss_enumprinterdrivers        },
1062  {"SPOOLSS_ADDPRINTEREX",              SPOOLSS_ADDPRINTEREX,              api_spoolss_addprinterex              },
1063  {"SPOOLSS_ADDPRINTERDRIVER",          SPOOLSS_ADDPRINTERDRIVER,          api_spoolss_addprinterdriver          },
1064  {"SPOOLSS_GETPRINTERDRIVERDIRECTORY", SPOOLSS_GETPRINTERDRIVERDIRECTORY, api_spoolss_getprinterdriverdirectory },
1065  {"SPOOLSS_ENUMPRINTERDATA",           SPOOLSS_ENUMPRINTERDATA,           api_spoolss_enumprinterdata           },
1066  {"SPOOLSS_SETPRINTERDATA",            SPOOLSS_SETPRINTERDATA,            api_spoolss_setprinterdata            },
1067  {"SPOOLSS_ADDFORM",                   SPOOLSS_ADDFORM,                   api_spoolss_addform                   },
1068  {"SPOOLSS_SETFORM",                   SPOOLSS_SETFORM,                   api_spoolss_setform                   },
1069  {"SPOOLSS_ENUMPRINTPROCESSORS",       SPOOLSS_ENUMPRINTPROCESSORS,       api_spoolss_enumprintprocessors       },
1070  {"SPOOLSS_ENUMMONITORS",              SPOOLSS_ENUMMONITORS,              api_spoolss_enumprintmonitors         },
1071  {"SPOOLSS_GETJOB",                    SPOOLSS_GETJOB,                    api_spoolss_getjob                    },
1072  { NULL,                               0,                                 NULL                                  }
1073 };
1074
1075 /*******************************************************************
1076 receives a spoolss pipe and responds.
1077 ********************************************************************/
1078 BOOL api_spoolss_rpc(pipes_struct *p, prs_struct *data)
1079 {
1080         return api_rpcTNP(p, "api_spoolss_rpc", api_spoolss_cmds, data);
1081 }
1082