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