First commit of the spoolss code to the HEAD branch.
[tprouty/samba.git] / source / 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         spoolss_io_q_closeprinter("", &q_u, data, 0);
111         r_u.status = _spoolss_closeprinter(&q_u.handle);
112         memcpy(&r_u.handle, &q_u.handle, sizeof(r_u.handle));
113         spoolss_io_r_closeprinter("",&r_u,rdata,0);
114 }
115
116 /********************************************************************
117  * api_spoolss_rffpcnex
118  * ReplyFindFirstPrinterChangeNotifyEx
119  ********************************************************************/
120 static BOOL api_spoolss_rffpcnex(uint16 vuid, prs_struct *data, prs_struct *rdata) 
121 {
122         SPOOL_Q_RFFPCNEX q_u;
123         SPOOL_R_RFFPCNEX r_u;
124
125         ZERO_STRUCT(q_u);
126         ZERO_STRUCT(r_u);
127
128         spoolss_io_q_rffpcnex("", &q_u, data, 0);
129
130         r_u.status = _spoolss_rffpcnex(&q_u.handle, q_u.flags,
131                                        q_u.options, &q_u.localmachine,
132                                        q_u.printerlocal, &q_u.option);
133         spoolss_io_r_rffpcnex("",&r_u,rdata,0);
134 }
135
136
137 /********************************************************************
138  * api_spoolss_rfnpcnex
139  * ReplyFindNextPrinterChangeNotifyEx
140  * called from the spoolss dispatcher
141  *
142  ********************************************************************/
143 static BOOL api_spoolss_rfnpcnex(uint16 vuid, prs_struct *data, prs_struct *rdata) 
144 {
145         SPOOL_Q_RFNPCNEX q_u;
146         SPOOL_R_RFNPCNEX r_u;
147
148         ZERO_STRUCT(q_u);
149         ZERO_STRUCT(r_u);
150
151         spoolss_io_q_rfnpcnex("", &q_u, data, 0);
152
153         r_u.status = _spoolss_rfnpcnex(&q_u.handle, q_u.change,
154                                        &q_u.option, &r_u.count, &r_u.info);
155         spoolss_io_r_rfnpcnex("", &r_u, rdata, 0);
156 }
157
158
159 /********************************************************************
160  * api_spoolss_enumprinters
161  * called from the spoolss dispatcher
162  *
163  ********************************************************************/
164 static BOOL api_spoolss_enumprinters(uint16 vuid, prs_struct *data, prs_struct *rdata) 
165 {
166         SPOOL_Q_ENUMPRINTERS q_u;
167         SPOOL_R_ENUMPRINTERS r_u;
168
169         ZERO_STRUCT(q_u);
170         ZERO_STRUCT(r_u);
171
172         spoolss_io_q_enumprinters("", &q_u, data, 0);
173
174         /* lkclXXX DAMN DAMN DAMN!  MICROSOFT @#$%S IT UP, AGAIN, AND WE
175            HAVE TO DEAL WITH IT!  AGH!
176          */
177         r_u.level = q_u.level;
178         r_u.status = _spoolss_enumprinters(
179                                 q_u.flags,
180                                 &q_u.servername,
181                                 q_u.level,
182                                 &q_u.buffer,
183                                 q_u.buf_size,
184                                 &r_u.offered,
185                                 &r_u.needed,
186                                 &r_u.ctr,
187                                 &r_u.returned);
188         
189         memcpy(r_u.servername.buffer,q_u.servername.buffer,
190                2*q_u.servername.uni_str_len);
191         r_u.servername.buffer[q_u.servername.uni_str_len] = 0;
192
193         spoolss_io_free_buffer(&(q_u.buffer));
194         spoolss_io_r_enumprinters("",&r_u,rdata,0);
195 }
196
197
198 /********************************************************************
199  * api_spoolss_getprinter
200  * called from the spoolss dispatcher
201  *
202  ********************************************************************/
203 static BOOL api_spoolss_getprinter(uint16 vuid, prs_struct *data, prs_struct *rdata) 
204 {
205         SPOOL_Q_GETPRINTER q_u;
206         SPOOL_R_GETPRINTER r_u;
207
208         ZERO_STRUCT(q_u);
209         ZERO_STRUCT(r_u);
210
211         spoolss_io_q_getprinter("", &q_u, data, 0);
212
213         r_u.status = _spoolss_getprinter(&q_u.handle, q_u.level,
214                                         &r_u.ctr, &q_u.offered, &r_u.needed);
215
216         memcpy(&r_u.handle, &q_u.handle, sizeof(&r_u.handle));
217         r_u.offered = q_u.offered;
218         r_u.level = q_u.level;
219         safe_free(q_u.buffer);
220
221         spoolss_io_r_getprinter("",&r_u,rdata,0);
222 }
223
224
225 /********************************************************************
226  * api_spoolss_getprinter
227  * called from the spoolss dispatcher
228  *
229  ********************************************************************/
230 static BOOL api_spoolss_getprinterdriver2(uint16 vuid, prs_struct *data, prs_struct *rdata)
231 {
232         SPOOL_Q_GETPRINTERDRIVER2 q_u;
233         SPOOL_R_GETPRINTERDRIVER2 r_u;
234
235         ZERO_STRUCT(q_u);
236         ZERO_STRUCT(r_u);
237         
238         spoolss_io_q_getprinterdriver2("", &q_u, data, 0);
239         
240         r_u.status = _spoolss_getprinterdriver2(&q_u.handle,
241                                 &q_u.architecture, q_u.level,
242                                 &r_u.ctr, &q_u.buf_size,
243                                 &r_u.needed);
244         
245         r_u.offered = q_u.buf_size;
246         r_u.level = q_u.level;
247         spoolss_io_free_buffer(&(q_u.buffer));
248
249         spoolss_io_r_getprinterdriver2("",&r_u,rdata,0);
250 }
251
252 /********************************************************************
253  * api_spoolss_getprinter
254  * called from the spoolss dispatcher
255  *
256  ********************************************************************/
257 static BOOL api_spoolss_startpageprinter(uint16 vuid, prs_struct *data, prs_struct *rdata)
258 {
259         SPOOL_Q_STARTPAGEPRINTER q_u;
260         SPOOL_R_STARTPAGEPRINTER r_u;
261
262         ZERO_STRUCT(q_u);
263         ZERO_STRUCT(r_u);
264         
265         spoolss_io_q_startpageprinter("", &q_u, data, 0);
266         r_u.status = _spoolss_startpageprinter(&q_u.handle);
267         spoolss_io_r_startpageprinter("",&r_u,rdata,0);         
268 }
269
270
271 /********************************************************************
272  * api_spoolss_getprinter
273  * called from the spoolss dispatcher
274  *
275  ********************************************************************/
276 static BOOL api_spoolss_endpageprinter(uint16 vuid, prs_struct *data, prs_struct *rdata)
277 {
278         SPOOL_Q_ENDPAGEPRINTER q_u;
279         SPOOL_R_ENDPAGEPRINTER r_u;
280
281         ZERO_STRUCT(q_u);
282         ZERO_STRUCT(r_u);
283         
284         spoolss_io_q_endpageprinter("", &q_u, data, 0);
285         r_u.status = _spoolss_endpageprinter(&q_u.handle);
286         spoolss_io_r_endpageprinter("",&r_u,rdata,0);           
287 }
288
289 /********************************************************************
290  * api_spoolss_getprinter
291  * called from the spoolss dispatcher
292  *
293  ********************************************************************/
294 static BOOL api_spoolss_startdocprinter(uint16 vuid, prs_struct *data, prs_struct *rdata)
295 {
296         SPOOL_Q_STARTDOCPRINTER q_u;
297         SPOOL_R_STARTDOCPRINTER r_u;
298         
299         ZERO_STRUCT(q_u);
300         ZERO_STRUCT(r_u);
301         
302         spoolss_io_q_startdocprinter("", &q_u, data, 0);
303         r_u.status = _spoolss_startdocprinter(&q_u.handle,
304                                   q_u.doc_info_container.level,
305                                   &q_u.doc_info_container.docinfo,
306                                   &r_u.jobid);
307         spoolss_io_r_startdocprinter("",&r_u,rdata,0);          
308 }
309
310 /********************************************************************
311  * api_spoolss_getprinter
312  * called from the spoolss dispatcher
313  *
314  ********************************************************************/
315 static BOOL api_spoolss_enddocprinter(uint16 vuid, prs_struct *data, prs_struct *rdata)
316 {
317         SPOOL_Q_ENDDOCPRINTER q_u;
318         SPOOL_R_ENDDOCPRINTER r_u;
319
320         ZERO_STRUCT(q_u);
321         ZERO_STRUCT(r_u);
322         
323         spoolss_io_q_enddocprinter("", &q_u, data, 0);
324         r_u.status = _spoolss_enddocprinter(&q_u.handle);
325         spoolss_io_r_enddocprinter("",&r_u,rdata,0);            
326 }
327
328
329 /********************************************************************
330  * api_spoolss_getprinter
331  * called from the spoolss dispatcher
332  *
333  ********************************************************************/
334 static BOOL api_spoolss_writeprinter(uint16 vuid, prs_struct *data, prs_struct *rdata)
335 {
336         SPOOL_Q_WRITEPRINTER q_u;
337         SPOOL_R_WRITEPRINTER r_u;
338
339         ZERO_STRUCT(q_u);
340         ZERO_STRUCT(r_u);
341         
342         spoolss_io_q_writeprinter("", &q_u, data, 0);
343         r_u.status = _spoolss_writeprinter(&q_u.handle,
344                                            q_u.buffer_size,
345                                            q_u.buffer,
346                                            &q_u.buffer_size2);
347         r_u.buffer_written = q_u.buffer_size2;
348         safe_free(q_u.buffer);
349         spoolss_io_r_writeprinter("",&r_u,rdata,0);             
350 }
351
352 /****************************************************************************
353 ****************************************************************************/
354 static BOOL api_spoolss_setprinter(uint16 vuid, prs_struct *data, prs_struct *rdata)
355 {
356         SPOOL_Q_SETPRINTER q_u;
357         SPOOL_R_SETPRINTER r_u;
358
359         ZERO_STRUCT(q_u);
360         ZERO_STRUCT(r_u);
361
362         spoolss_io_q_setprinter("", &q_u, data, 0);
363         DEBUG(0,("api_spoolss_setprinter: typecast sec_des to uint8*!\n"));
364         r_u.status = _spoolss_setprinter(&q_u.handle,
365                                          q_u.level, &q_u.info,
366                                          q_u.devmode,
367                                          q_u.security.size_of_buffer,
368                                          (const uint8*)q_u.security.data,
369                                          q_u.command);
370         spoolss_io_r_setprinter("",&r_u,rdata,0);
371 }
372
373 /****************************************************************************
374 ****************************************************************************/
375 static BOOL api_spoolss_fcpn(uint16 vuid, prs_struct *data, prs_struct *rdata)
376 {
377         SPOOL_Q_FCPN q_u;
378         SPOOL_R_FCPN r_u;
379
380         ZERO_STRUCT(q_u);
381         ZERO_STRUCT(r_u);
382
383         spoolss_io_q_fcpn("", &q_u, data, 0);
384         r_u.status = _spoolss_fcpn(&q_u.handle);
385         spoolss_io_r_fcpn("",&r_u,rdata,0);             
386 }
387
388
389 /****************************************************************************
390 ****************************************************************************/
391 static BOOL api_spoolss_addjob(uint16 vuid, prs_struct *data, prs_struct *rdata)
392 {
393         SPOOL_Q_ADDJOB q_u;
394         SPOOL_R_ADDJOB r_u;
395         
396         ZERO_STRUCT(q_u);
397         ZERO_STRUCT(r_u);
398         
399         spoolss_io_q_addjob("", &q_u, data, 0);
400
401         r_u.status = _spoolss_addjob(&q_u.handle, q_u.level,
402                                      &q_u.buffer, q_u.buf_size);
403         
404         spoolss_io_free_buffer(&(q_u.buffer));
405         spoolss_io_r_addjob("",&r_u,rdata,0);           
406 }
407
408
409 /****************************************************************************
410 ****************************************************************************/
411 static BOOL api_spoolss_enumjobs(uint16 vuid, prs_struct *data, prs_struct *rdata)
412 {
413         SPOOL_Q_ENUMJOBS q_u;
414         SPOOL_R_ENUMJOBS r_u;
415
416         ZERO_STRUCT(q_u);
417         ZERO_STRUCT(r_u);
418         
419         spoolss_io_q_enumjobs("", &q_u, data, 0);
420         r_u.offered = q_u.buf_size;
421         r_u.level = q_u.level;
422         r_u.status = _spoolss_enumjobs(&q_u.handle,
423                                 q_u.firstjob, q_u.numofjobs, q_u.level,
424                                 &r_u.ctr, &r_u.offered, &r_u.numofjobs);
425         spoolss_io_free_buffer(&(q_u.buffer));
426         spoolss_io_r_enumjobs("",&r_u,rdata,0);
427 }
428
429
430 /****************************************************************************
431 ****************************************************************************/
432 static BOOL api_spoolss_schedulejob(uint16 vuid, prs_struct *data, prs_struct *rdata)
433 {
434         SPOOL_Q_SCHEDULEJOB q_u;
435         SPOOL_R_SCHEDULEJOB r_u;
436         
437         ZERO_STRUCT(q_u);
438         ZERO_STRUCT(r_u);
439         
440         spoolss_io_q_schedulejob("", &q_u, data, 0);
441         r_u.status = _spoolss_schedulejob(&q_u.handle, q_u.jobid);
442         spoolss_io_r_schedulejob("",&r_u,rdata,0);              
443 }
444
445 /****************************************************************************
446 ****************************************************************************/
447 static BOOL api_spoolss_setjob(uint16 vuid, prs_struct *data, prs_struct *rdata)
448 {
449         SPOOL_Q_SETJOB q_u;
450         SPOOL_R_SETJOB r_u;
451         
452         ZERO_STRUCT(q_u);
453         ZERO_STRUCT(r_u);
454         
455         spoolss_io_q_setjob("", &q_u, data, 0);
456         r_u.status = _spoolss_setjob(&q_u.handle, q_u.jobid,
457                                 q_u.level, &q_u.ctr, q_u.command);
458         spoolss_io_r_setjob("",&r_u,rdata,0);
459 }
460
461 /****************************************************************************
462 ****************************************************************************/
463
464 static BOOL api_spoolss_enumprinterdrivers(uint16 vuid, prs_struct *data, prs_struct *rdata)
465 {
466         SPOOL_Q_ENUMPRINTERDRIVERS q_u;
467         SPOOL_R_ENUMPRINTERDRIVERS r_u;
468         
469         ZERO_STRUCT(q_u);
470         ZERO_STRUCT(r_u);
471         
472         spoolss_io_q_enumprinterdrivers("", &q_u, data, 0);
473
474         r_u.offered = q_u.buf_size;
475         r_u.level = q_u.level;
476         r_u.status = _spoolss_enumprinterdrivers(&q_u.name,
477                                 &q_u.environment, q_u. level,
478                                 &r_u.ctr, &r_u.offered, &r_u.numofdrivers);
479
480         spoolss_io_free_buffer(&q_u.buffer);
481         spoolss_io_r_enumdrivers("",&r_u,rdata,0);
482         free_spoolss_r_enumdrivers(&r_u);
483 }
484
485
486 /****************************************************************************
487 ****************************************************************************/
488 static BOOL api_spoolss_enumforms(uint16 vuid, prs_struct *data, prs_struct *rdata)
489 {
490         SPOOL_Q_ENUMFORMS q_u;
491         SPOOL_R_ENUMFORMS r_u;
492                 
493         ZERO_STRUCT(q_u);
494         ZERO_STRUCT(r_u);
495
496         DEBUG(5,("spoolss_io_q_enumforms\n"));
497
498         new_spoolss_allocate_buffer(&q_u.buffer);
499
500         if (!spoolss_io_q_enumforms("", &q_u, data, 0))
501                 return False;
502
503         /* that's an [in out] buffer */
504         new_spoolss_move_buffer(q_u.buffer, &r_u.buffer);
505         
506         r_u.status = _new_spoolss_enumforms(&q_u.handle, q_u.level, 
507                                 r_u.buffer, q_u.offered,
508                                 &r_u.needed, &r_u.numofforms);
509
510         if (!new_spoolss_io_r_enumforms("",&r_u,rdata,0)) {
511                 new_spoolss_free_buffer(q_u.buffer);
512                 return False;
513         }
514         
515         new_spoolss_free_buffer(q_u.buffer);
516         
517         return True;
518 }
519
520
521 /****************************************************************************
522 ****************************************************************************/
523 static BOOL api_spoolss_enumports(uint16 vuid, prs_struct *data, prs_struct *rdata)
524 {
525         SPOOL_Q_ENUMPORTS q_u;
526         SPOOL_R_ENUMPORTS r_u;
527         
528         ZERO_STRUCT(q_u);
529         ZERO_STRUCT(r_u);
530         
531         spoolss_io_q_enumports("", &q_u, data, 0);
532
533         r_u.offered = q_u.buf_size;
534         r_u.level = q_u.level;
535         r_u.status = _spoolss_enumports(&q_u.name,
536                                 q_u.level,
537                                 &r_u.ctr,
538                                 &r_u.offered,
539                                 &r_u.numofports);
540         
541         spoolss_io_free_buffer(&(q_u.buffer));
542         spoolss_io_r_enumports("",&r_u,rdata,0);
543         spoolss_free_r_enumports(&r_u);
544 }
545
546
547 /****************************************************************************
548 ****************************************************************************/
549 static BOOL api_spoolss_addprinterex(uint16 vuid, prs_struct *data, prs_struct *rdata)
550 {
551         SPOOL_Q_ADDPRINTEREX q_u;
552         SPOOL_R_ADDPRINTEREX r_u;
553         
554         ZERO_STRUCT(q_u);
555         ZERO_STRUCT(r_u);
556         
557         spoolss_io_q_addprinterex("", &q_u, data, 0);
558         r_u.status = _spoolss_addprinterex(&q_u.server_name,
559                                 q_u.level, &q_u.info,
560                                 q_u.unk0, q_u.unk1, q_u.unk2, q_u.unk3,
561                                 q_u.user_level, &q_u.user,
562                                 &r_u.handle);
563         spoolss_io_r_addprinterex("", &r_u, rdata, 0);
564 }
565
566 /****************************************************************************
567 ****************************************************************************/
568 static BOOL api_spoolss_addprinterdriver(uint16 vuid, prs_struct *data, prs_struct *rdata)
569 {
570         SPOOL_Q_ADDPRINTERDRIVER q_u;
571         SPOOL_R_ADDPRINTERDRIVER r_u;
572         
573         ZERO_STRUCT(q_u);
574         ZERO_STRUCT(r_u);
575         
576         spoolss_io_q_addprinterdriver("", &q_u, data, 0);
577         r_u.status = _spoolss_addprinterdriver(&q_u.server_name,
578                                 q_u.level, &q_u.info);
579         spoolss_io_r_addprinterdriver("", &r_u, rdata, 0);
580 }
581
582 /****************************************************************************
583 ****************************************************************************/
584 static BOOL api_spoolss_getprinterdriverdirectory(uint16 vuid, prs_struct *data, prs_struct *rdata)
585 {
586         SPOOL_Q_GETPRINTERDRIVERDIR q_u;
587         SPOOL_R_GETPRINTERDRIVERDIR r_u;
588         
589         spoolss_io_q_getprinterdriverdir("", &q_u, data, 0);
590         
591         r_u.offered = q_u.buf_size;
592         r_u.level = q_u.level;
593         r_u.status = _spoolss_getprinterdriverdirectory(&q_u.name,
594                                 &q_u.environment,
595                                 q_u.level,
596                                 &r_u.ctr,
597                                 &r_u.offered);
598         spoolss_io_free_buffer(&q_u.buffer);
599         spoolss_io_r_getprinterdriverdir("", &r_u, rdata, 0);
600 }
601
602 /****************************************************************************
603 ****************************************************************************/
604 static BOOL api_spoolss_enumprinterdata(uint16 vuid, prs_struct *data, prs_struct *rdata)
605 {
606         SPOOL_Q_ENUMPRINTERDATA q_u;
607         SPOOL_R_ENUMPRINTERDATA r_u;
608         
609         ZERO_STRUCT(q_u);
610         ZERO_STRUCT(r_u);
611         
612         spoolss_io_q_enumprinterdata("", &q_u, data, 0);
613         r_u.valuesize = q_u.valuesize;
614         r_u.datasize = q_u.datasize;
615
616         r_u.status = _spoolss_enumprinterdata(&q_u.handle,
617                                 q_u.index,/* in */
618                                 &r_u.valuesize,/* in out */
619                                 &r_u.value,/* out */
620                                 &r_u.realvaluesize,/* out */
621                                 &r_u.type,/* out */
622                                 &r_u.datasize,/* in out */
623                                 &r_u.data,/* out */
624                                 &r_u.realdatasize);/* out */
625         spoolss_io_r_enumprinterdata("", &r_u, rdata, 0);
626         safe_free(r_u.data);
627 }
628
629 /****************************************************************************
630 ****************************************************************************/
631 static BOOL api_spoolss_setprinterdata(uint16 vuid, prs_struct *data, prs_struct *rdata)
632 {
633         SPOOL_Q_SETPRINTERDATA q_u;
634         SPOOL_R_SETPRINTERDATA r_u;     
635         
636         ZERO_STRUCT(q_u);
637         ZERO_STRUCT(r_u);
638         
639         spoolss_io_q_setprinterdata("", &q_u, data, 0);
640         r_u.status = _spoolss_setprinterdata(&q_u.handle,
641                                 &q_u.value, q_u.type, q_u.max_len,
642                                 q_u.data, q_u.real_len, q_u.numeric_data);
643         spoolss_io_r_setprinterdata("", &r_u, rdata, 0);
644         safe_free(q_u.data);
645 }
646
647 /****************************************************************************
648 ****************************************************************************/
649 static BOOL api_spoolss_addform(uint16 vuid, prs_struct *data, prs_struct *rdata)
650 {
651         SPOOL_Q_ADDFORM q_u;
652         SPOOL_R_ADDFORM r_u;
653
654         ZERO_STRUCT(q_u);
655         ZERO_STRUCT(r_u);
656         
657         spoolss_io_q_addform("", &q_u, data, 0);
658         r_u.status = _spoolss_addform(&q_u.handle, q_u.level, &q_u.form);
659         spoolss_io_r_addform("", &r_u, rdata, 0);
660 }
661
662 /****************************************************************************
663 ****************************************************************************/
664 static BOOL api_spoolss_setform(uint16 vuid, prs_struct *data, prs_struct *rdata)
665 {
666         SPOOL_Q_SETFORM q_u;
667         SPOOL_R_SETFORM r_u;
668
669         ZERO_STRUCT(q_u);
670         ZERO_STRUCT(r_u);
671         
672         spoolss_io_q_setform("", &q_u, data, 0);
673         r_u.status = _spoolss_setform(&q_u.handle,
674                                       &q_u.name, q_u.level, &q_u.form);
675         spoolss_io_r_setform("", &r_u, rdata, 0);
676 }
677
678 /****************************************************************************
679 ****************************************************************************/
680 static BOOL api_spoolss_enumprintprocessors(uint16 vuid, prs_struct *data, prs_struct *rdata)
681 {
682         SPOOL_Q_ENUMPRINTPROCESSORS q_u;
683         SPOOL_R_ENUMPRINTPROCESSORS r_u;
684
685         ZERO_STRUCT(q_u);
686         ZERO_STRUCT(r_u);
687         
688         spoolss_io_q_enumprintprocessors("", &q_u, data, 0);
689         r_u.offered = q_u.buf_size;
690         r_u.level = q_u.level;
691         r_u.status = _spoolss_enumprintprocessors(&q_u.name,
692                                 &q_u.environment,
693                                 q_u.level,
694                                 &r_u.info_1,
695                                 &r_u.offered,
696                                 &r_u.numofprintprocessors);
697         spoolss_io_free_buffer(&q_u.buffer);
698         spoolss_io_r_enumprintprocessors("", &r_u, rdata, 0);
699         safe_free(r_u.info_1);
700 }
701
702 /****************************************************************************
703 ****************************************************************************/
704 static BOOL api_spoolss_enumprintmonitors(uint16 vuid, prs_struct *data, prs_struct *rdata)
705 {
706         SPOOL_Q_ENUMPRINTMONITORS q_u;
707         SPOOL_R_ENUMPRINTMONITORS r_u;
708
709         ZERO_STRUCT(q_u);
710         ZERO_STRUCT(r_u);
711         
712         spoolss_io_q_enumprintmonitors("", &q_u, data, 0);
713         r_u.offered = q_u.buf_size;
714         r_u.level = q_u.level;
715         r_u.status = _spoolss_enumprintmonitors(&q_u.name,
716                                 q_u.level,
717                                 &r_u.info_1,
718                                 &r_u.offered,
719                                 &r_u.numofprintmonitors);
720         spoolss_io_free_buffer(&q_u.buffer);
721         spoolss_io_r_enumprintmonitors("", &r_u, rdata, 0);
722         safe_free(r_u.info_1);
723 }
724
725 /****************************************************************************
726 ****************************************************************************/
727 static BOOL api_spoolss_getjob(uint16 vuid, prs_struct *data, prs_struct *rdata)
728 {
729         SPOOL_Q_GETJOB q_u;
730         SPOOL_R_GETJOB r_u;
731         
732         spoolss_io_q_getjob("", &q_u, data, 0);
733
734         r_u.offered = q_u.buf_size;
735         r_u.level = q_u.level;
736         r_u.status = _spoolss_getjob(&q_u.handle,
737                                 q_u.jobid,
738                                 q_u.level,
739                                 &r_u.ctr,
740                                 &r_u.offered);
741         spoolss_io_free_buffer(&(q_u.buffer));
742         spoolss_io_r_getjob("",&r_u,rdata,0);
743         free_spoolss_r_getjob(&r_u);
744 }
745
746 /*******************************************************************
747 \pipe\spoolss commands
748 ********************************************************************/
749 struct api_struct api_spoolss_cmds[] = 
750 {
751  {"SPOOLSS_OPENPRINTEREX",             SPOOLSS_OPENPRINTEREX,             api_spoolss_open_printer_ex           },
752  {"SPOOLSS_GETPRINTERDATA",            SPOOLSS_GETPRINTERDATA,            api_spoolss_getprinterdata            },
753  {"SPOOLSS_CLOSEPRINTER",              SPOOLSS_CLOSEPRINTER,              api_spoolss_closeprinter              },
754  {"SPOOLSS_RFFPCNEX",                  SPOOLSS_RFFPCNEX,                  api_spoolss_rffpcnex                  },
755  {"SPOOLSS_RFNPCNEX",                  SPOOLSS_RFNPCNEX,                  api_spoolss_rfnpcnex                  },
756  {"SPOOLSS_ENUMPRINTERS",              SPOOLSS_ENUMPRINTERS,              api_spoolss_enumprinters              },
757  {"SPOOLSS_GETPRINTER",                SPOOLSS_GETPRINTER,                api_spoolss_getprinter                },
758  {"SPOOLSS_GETPRINTERDRIVER2",         SPOOLSS_GETPRINTERDRIVER2,         api_spoolss_getprinterdriver2         }, 
759  {"SPOOLSS_STARTPAGEPRINTER",          SPOOLSS_STARTPAGEPRINTER,          api_spoolss_startpageprinter          },
760  {"SPOOLSS_ENDPAGEPRINTER",            SPOOLSS_ENDPAGEPRINTER,            api_spoolss_endpageprinter            }, 
761  {"SPOOLSS_STARTDOCPRINTER",           SPOOLSS_STARTDOCPRINTER,           api_spoolss_startdocprinter           },
762  {"SPOOLSS_ENDDOCPRINTER",             SPOOLSS_ENDDOCPRINTER,             api_spoolss_enddocprinter             },
763  {"SPOOLSS_WRITEPRINTER",              SPOOLSS_WRITEPRINTER,              api_spoolss_writeprinter              },
764  {"SPOOLSS_SETPRINTER",                SPOOLSS_SETPRINTER,                api_spoolss_setprinter                },
765  {"SPOOLSS_FCPN",                      SPOOLSS_FCPN,                      api_spoolss_fcpn                      },
766  {"SPOOLSS_ADDJOB",                    SPOOLSS_ADDJOB,                    api_spoolss_addjob                    },
767  {"SPOOLSS_ENUMJOBS",                  SPOOLSS_ENUMJOBS,                  api_spoolss_enumjobs                  },
768  {"SPOOLSS_SCHEDULEJOB",               SPOOLSS_SCHEDULEJOB,               api_spoolss_schedulejob               },
769  {"SPOOLSS_SETJOB",                    SPOOLSS_SETJOB,                    api_spoolss_setjob                    },
770  {"SPOOLSS_ENUMFORMS",                 SPOOLSS_ENUMFORMS,                 api_spoolss_enumforms                 },
771  {"SPOOLSS_ENUMPORTS",                 SPOOLSS_ENUMPORTS,                 api_spoolss_enumports                 },
772  {"SPOOLSS_ENUMPRINTERDRIVERS",        SPOOLSS_ENUMPRINTERDRIVERS,        api_spoolss_enumprinterdrivers        },
773  {"SPOOLSS_ADDPRINTEREX",              SPOOLSS_ADDPRINTEREX,              api_spoolss_addprinterex              },
774  {"SPOOLSS_ADDPRINTERDRIVER",          SPOOLSS_ADDPRINTERDRIVER,          api_spoolss_addprinterdriver          },
775  {"SPOOLSS_GETPRINTERDRIVERDIRECTORY", SPOOLSS_GETPRINTERDRIVERDIRECTORY, api_spoolss_getprinterdriverdirectory },
776  {"SPOOLSS_ENUMPRINTERDATA",           SPOOLSS_ENUMPRINTERDATA,           api_spoolss_enumprinterdata           },
777  {"SPOOLSS_SETPRINTERDATA",            SPOOLSS_SETPRINTERDATA,            api_spoolss_setprinterdata            },
778  {"SPOOLSS_ADDFORM",                   SPOOLSS_ADDFORM,                   api_spoolss_addform                   },
779  {"SPOOLSS_SETFORM",                   SPOOLSS_SETFORM,                   api_spoolss_setform                   },
780  {"SPOOLSS_ENUMPRINTPROCESSORS",       SPOOLSS_ENUMPRINTPROCESSORS,       api_spoolss_enumprintprocessors       },
781  {"SPOOLSS_ENUMMONITORS",              SPOOLSS_ENUMMONITORS,              api_spoolss_enumprintmonitors         },
782  {"SPOOLSS_GETJOB",                    SPOOLSS_GETJOB,                    api_spoolss_getjob                    },
783  { NULL,                               0,                                 NULL                                  }
784 };
785
786 /*******************************************************************
787 receives a spoolss pipe and responds.
788 ********************************************************************/
789 BOOL api_spoolss_rpc(pipes_struct *p, prs_struct *data)
790 {
791         return api_rpcTNP(p, "api_spoolss_rpc", api_spoolss_cmds, data);
792 }
793