fa3a16f7e1557fba8545cba194fed6dec75f425c
[samba.git] / source4 / rpc_server / spoolss / dcesrv_spoolss.c
1 /* 
2    Unix SMB/CIFS implementation.
3
4    endpoint server for the spoolss pipe
5
6    Copyright (C) Tim Potter 2004
7    
8    This program is free software; you can redistribute it and/or modify
9    it under the terms of the GNU General Public License as published by
10    the Free Software Foundation; either version 2 of the License, or
11    (at your option) any later version.
12    
13    This program is distributed in the hope that it will be useful,
14    but WITHOUT ANY WARRANTY; without even the implied warranty of
15    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16    GNU General Public License for more details.
17    
18    You should have received a copy of the GNU General Public License
19    along with this program; if not, write to the Free Software
20    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
21 */
22
23 #include "includes.h"
24 #include "rpc_server/dcerpc_server.h"
25 #include "librpc/gen_ndr/ndr_spoolss.h"
26 #include "rpc_server/common/common.h"
27 #include "rpc_server/spoolss/dcesrv_spoolss.h"
28
29 /* 
30   spoolss_EnumPrinters 
31 */
32 static WERROR spoolss_EnumPrinters(struct dcesrv_call_state *dce_call, TALLOC_CTX *mem_ctx,
33                        struct spoolss_EnumPrinters *r)
34 {
35         void *spoolss_ctx;
36         struct ldb_message **msgs;
37         int count;
38         int i;
39         union spoolss_PrinterInfo *info;
40
41         r->out.info = NULL;
42         *r->out.buf_size = 0;
43         r->out.count = 0;
44
45         spoolss_ctx = spoolssdb_connect();
46         W_ERROR_HAVE_NO_MEMORY(spoolss_ctx);
47
48         count = spoolssdb_search(spoolss_ctx, mem_ctx, NULL, &msgs, NULL,
49                                "(&(objectclass=printer))");
50         spoolssdb_close(spoolss_ctx);
51
52         if (count == 0) return WERR_OK;
53         if (count < 0) return WERR_GENERAL_FAILURE;
54
55         info = talloc_array(mem_ctx, union spoolss_PrinterInfo, count);
56         W_ERROR_HAVE_NO_MEMORY(info);
57
58         switch(r->in.level) {
59         case 1:
60                 for (i = 0; i < count; i++) {
61                         info[i].info1.flags             = samdb_result_uint(msgs[i], "flags", 0);
62
63                         info[i].info1.name              = samdb_result_string(msgs[i], "name", "");
64                         W_ERROR_HAVE_NO_MEMORY(info[i].info1.name);
65
66                         info[i].info1.description       = samdb_result_string(msgs[i], "description", "");
67                         W_ERROR_HAVE_NO_MEMORY(info[i].info1.description);
68
69                         info[i].info1.comment           = samdb_result_string(msgs[i], "comment", NULL);
70                 }
71                 return WERR_OK;
72         case 2:
73                 for (i = 0; i < count; i++) {
74                         info[i].info2.servername        = samdb_result_string(msgs[i], "servername", "");
75                         W_ERROR_HAVE_NO_MEMORY(info[i].info2.servername);
76
77                         info[i].info2.printername       = samdb_result_string(msgs[i], "printername", "");
78                         W_ERROR_HAVE_NO_MEMORY(info[i].info2.printername);
79
80                         info[i].info2.sharename         = samdb_result_string(msgs[i], "sharename", "");
81                         W_ERROR_HAVE_NO_MEMORY(info[i].info2.sharename);
82
83                         info[i].info2.portname          = samdb_result_string(msgs[i], "portname", "");
84                         W_ERROR_HAVE_NO_MEMORY(info[i].info2.portname);
85
86                         info[i].info2.drivername        = samdb_result_string(msgs[i], "drivername", "");
87                         W_ERROR_HAVE_NO_MEMORY(info[i].info2.drivername);
88
89                         info[i].info2.comment           = samdb_result_string(msgs[i], "comment", NULL);
90
91                         info[i].info2.location          = samdb_result_string(msgs[i], "location", NULL);
92
93                         info[i].info2.devmode           = NULL;
94
95                         info[i].info2.sepfile           = samdb_result_string(msgs[i], "sepfile", NULL);
96
97                         info[i].info2.printprocessor    = samdb_result_string(msgs[i], "printprocessor", "");
98                         W_ERROR_HAVE_NO_MEMORY(info[i].info2.printprocessor);
99
100                         info[i].info2.datatype          = samdb_result_string(msgs[i], "datatype", "");
101                         W_ERROR_HAVE_NO_MEMORY(info[i].info2.datatype);
102
103                         info[i].info2.parameters        = samdb_result_string(msgs[i], "parameters", NULL);
104
105                         info[i].info2.secdesc           = NULL;
106
107                         info[i].info2.attributes        = samdb_result_uint(msgs[i], "attributes", 0);
108                         info[i].info2.priority          = samdb_result_uint(msgs[i], "priority", 0);
109                         info[i].info2.defaultpriority   = samdb_result_uint(msgs[i], "defaultpriority", 0);
110                         info[i].info2.starttime         = samdb_result_uint(msgs[i], "starttime", 0);
111                         info[i].info2.untiltime         = samdb_result_uint(msgs[i], "untiltime", 0);
112                         info[i].info2.status            = samdb_result_uint(msgs[i], "status", 0);
113                         info[i].info2.cjobs             = samdb_result_uint(msgs[i], "cjobs", 0);
114                         info[i].info2.averageppm        = samdb_result_uint(msgs[i], "averageppm", 0);
115                 }
116                 return WERR_OK;
117         case 4:
118                 for (i = 0; i < count; i++) {
119                         info[i].info4.printername       = samdb_result_string(msgs[i], "printername", "");
120                         W_ERROR_HAVE_NO_MEMORY(info[i].info2.printername);
121
122                         info[i].info4.servername        = samdb_result_string(msgs[i], "servername", "");
123                         W_ERROR_HAVE_NO_MEMORY(info[i].info2.servername);
124
125                         info[i].info4.attributes        = samdb_result_uint(msgs[i], "attributes", 0);
126                 }
127                 return WERR_OK;
128         case 5:
129                 for (i = 0; i < count; i++) {
130                         info[i].info5.printername       = samdb_result_string(msgs[i], "name", "");
131                         W_ERROR_HAVE_NO_MEMORY(info[i].info5.printername);
132
133                         info[i].info5.portname          = samdb_result_string(msgs[i], "port", "");
134                         W_ERROR_HAVE_NO_MEMORY(info[i].info5.portname);
135
136                         info[i].info5.attributes        = samdb_result_uint(msgs[i], "attributes", 0);
137                         info[i].info5.device_not_selected_timeout = samdb_result_uint(msgs[i], "device_not_selected_timeout", 0);
138                         info[i].info5.transmission_retry_timeout  = samdb_result_uint(msgs[i], "transmission_retry_timeout", 0);
139                 }
140                 return WERR_OK;
141         }
142
143         return WERR_UNKNOWN_LEVEL;
144 }
145
146 static WERROR spoolss_OpenPrinterEx(struct dcesrv_call_state *dce_call, TALLOC_CTX *mem_ctx,
147                        struct spoolss_OpenPrinterEx *r);
148 /* 
149   spoolss_OpenPrinter 
150 */
151 static WERROR spoolss_OpenPrinter(struct dcesrv_call_state *dce_call, TALLOC_CTX *mem_ctx,
152                        struct spoolss_OpenPrinter *r)
153 {
154         WERROR status;
155         struct spoolss_OpenPrinterEx *r2;
156
157         r2 = talloc(mem_ctx, struct spoolss_OpenPrinterEx);
158         W_ERROR_HAVE_NO_MEMORY(r2);
159
160         r2->in.printername      = r->in.printername;
161         r2->in.datatype         = r->in.datatype;
162         r2->in.devmode_ctr      = r->in.devmode_ctr;
163         r2->in.access_mask      = r->in.access_mask;
164         r2->in.level            = 1;
165         r2->in.userlevel.level1 = NULL;
166
167         r2->out.handle          = r->out.handle;
168
169         /* TODO: we should take care about async replies here,
170                  if spoolss_OpenPrinterEx() would be async!
171          */
172         status = spoolss_OpenPrinterEx(dce_call, mem_ctx, r2);
173
174         r->out.handle           = r2->out.handle;
175
176         return status;
177 }
178
179
180 /* 
181   spoolss_SetJob 
182 */
183 static WERROR spoolss_SetJob(struct dcesrv_call_state *dce_call, TALLOC_CTX *mem_ctx,
184                        struct spoolss_SetJob *r)
185 {
186         DCESRV_FAULT(DCERPC_FAULT_OP_RNG_ERROR);
187 }
188
189
190 /* 
191   spoolss_GetJob 
192 */
193 static WERROR spoolss_GetJob(struct dcesrv_call_state *dce_call, TALLOC_CTX *mem_ctx,
194                        struct spoolss_GetJob *r)
195 {
196         DCESRV_FAULT(DCERPC_FAULT_OP_RNG_ERROR);
197 }
198
199
200 /* 
201   spoolss_EnumJobs 
202 */
203 static WERROR spoolss_EnumJobs(struct dcesrv_call_state *dce_call, TALLOC_CTX *mem_ctx,
204                        struct spoolss_EnumJobs *r)
205 {
206         DCESRV_FAULT(DCERPC_FAULT_OP_RNG_ERROR);
207 }
208
209
210 /* 
211   spoolss_AddPrinter 
212 */
213 static WERROR spoolss_AddPrinter(struct dcesrv_call_state *dce_call, TALLOC_CTX *mem_ctx,
214                        struct spoolss_AddPrinter *r)
215 {
216         DCESRV_FAULT(DCERPC_FAULT_OP_RNG_ERROR);
217 }
218
219
220 /* 
221   spoolss_DeletePrinter 
222 */
223 static WERROR spoolss_DeletePrinter(struct dcesrv_call_state *dce_call, TALLOC_CTX *mem_ctx,
224                        struct spoolss_DeletePrinter *r)
225 {
226         DCESRV_FAULT(DCERPC_FAULT_OP_RNG_ERROR);
227 }
228
229
230 /* 
231   spoolss_SetPrinter 
232 */
233 static WERROR spoolss_SetPrinter(struct dcesrv_call_state *dce_call, TALLOC_CTX *mem_ctx,
234                        struct spoolss_SetPrinter *r)
235 {
236         DCESRV_FAULT(DCERPC_FAULT_OP_RNG_ERROR);
237 }
238
239
240 /* 
241   spoolss_GetPrinter 
242 */
243 static WERROR spoolss_GetPrinter(struct dcesrv_call_state *dce_call, TALLOC_CTX *mem_ctx,
244                        struct spoolss_GetPrinter *r)
245 {
246         DCESRV_FAULT(DCERPC_FAULT_OP_RNG_ERROR);
247 }
248
249
250 /* 
251   spoolss_AddPrinterDriver 
252 */
253 static WERROR spoolss_AddPrinterDriver(struct dcesrv_call_state *dce_call, TALLOC_CTX *mem_ctx,
254                        struct spoolss_AddPrinterDriver *r)
255 {
256         DCESRV_FAULT(DCERPC_FAULT_OP_RNG_ERROR);
257 }
258
259
260 /* 
261   spoolss_EnumPrinterDrivers 
262 */
263 static WERROR spoolss_EnumPrinterDrivers(struct dcesrv_call_state *dce_call, TALLOC_CTX *mem_ctx,
264                        struct spoolss_EnumPrinterDrivers *r)
265 {
266         DCESRV_FAULT(DCERPC_FAULT_OP_RNG_ERROR);
267 }
268
269
270 /* 
271   spoolss_GetPrinterDriver 
272 */
273 static WERROR spoolss_GetPrinterDriver(struct dcesrv_call_state *dce_call, TALLOC_CTX *mem_ctx,
274                        struct spoolss_GetPrinterDriver *r)
275 {
276         DCESRV_FAULT(DCERPC_FAULT_OP_RNG_ERROR);
277 }
278
279
280 /* 
281   spoolss_GetPrinterDriverDirectory 
282 */
283 static WERROR spoolss_GetPrinterDriverDirectory(struct dcesrv_call_state *dce_call, TALLOC_CTX *mem_ctx,
284                        struct spoolss_GetPrinterDriverDirectory *r)
285 {
286         DCESRV_FAULT(DCERPC_FAULT_OP_RNG_ERROR);
287 }
288
289
290 /* 
291   spoolss_DeletePrinterDriver 
292 */
293 static WERROR spoolss_DeletePrinterDriver(struct dcesrv_call_state *dce_call, TALLOC_CTX *mem_ctx,
294                        struct spoolss_DeletePrinterDriver *r)
295 {
296         DCESRV_FAULT(DCERPC_FAULT_OP_RNG_ERROR);
297 }
298
299
300 /* 
301   spoolss_AddPrintProcessor 
302 */
303 static WERROR spoolss_AddPrintProcessor(struct dcesrv_call_state *dce_call, TALLOC_CTX *mem_ctx,
304                        struct spoolss_AddPrintProcessor *r)
305 {
306         DCESRV_FAULT(DCERPC_FAULT_OP_RNG_ERROR);
307 }
308
309
310 /* 
311   spoolss_EnumPrintProcessors 
312 */
313 static WERROR spoolss_EnumPrintProcessors(struct dcesrv_call_state *dce_call, TALLOC_CTX *mem_ctx,
314                        struct spoolss_EnumPrintProcessors *r)
315 {
316         DCESRV_FAULT(DCERPC_FAULT_OP_RNG_ERROR);
317 }
318
319
320 /* 
321   spoolss_GetPrintProcessorDirectory 
322 */
323 static WERROR spoolss_GetPrintProcessorDirectory(struct dcesrv_call_state *dce_call, TALLOC_CTX *mem_ctx,
324                        struct spoolss_GetPrintProcessorDirectory *r)
325 {
326         DCESRV_FAULT(DCERPC_FAULT_OP_RNG_ERROR);
327 }
328
329
330 /* 
331   spoolss_StartDocPrinter 
332 */
333 static WERROR spoolss_StartDocPrinter(struct dcesrv_call_state *dce_call, TALLOC_CTX *mem_ctx,
334                        struct spoolss_StartDocPrinter *r)
335 {
336         DCESRV_FAULT(DCERPC_FAULT_OP_RNG_ERROR);
337 }
338
339
340 /* 
341   spoolss_StartPagePrinter 
342 */
343 static WERROR spoolss_StartPagePrinter(struct dcesrv_call_state *dce_call, TALLOC_CTX *mem_ctx,
344                        struct spoolss_StartPagePrinter *r)
345 {
346         DCESRV_FAULT(DCERPC_FAULT_OP_RNG_ERROR);
347 }
348
349
350 /* 
351   spoolss_WritePrinter 
352 */
353 static WERROR spoolss_WritePrinter(struct dcesrv_call_state *dce_call, TALLOC_CTX *mem_ctx,
354                        struct spoolss_WritePrinter *r)
355 {
356         DCESRV_FAULT(DCERPC_FAULT_OP_RNG_ERROR);
357 }
358
359
360 /* 
361   spoolss_EndPagePrinter 
362 */
363 static WERROR spoolss_EndPagePrinter(struct dcesrv_call_state *dce_call, TALLOC_CTX *mem_ctx,
364                        struct spoolss_EndPagePrinter *r)
365 {
366         DCESRV_FAULT(DCERPC_FAULT_OP_RNG_ERROR);
367 }
368
369
370 /* 
371   spoolss_AbortPrinter 
372 */
373 static WERROR spoolss_AbortPrinter(struct dcesrv_call_state *dce_call, TALLOC_CTX *mem_ctx,
374                        struct spoolss_AbortPrinter *r)
375 {
376         DCESRV_FAULT(DCERPC_FAULT_OP_RNG_ERROR);
377 }
378
379
380 /* 
381   spoolss_ReadPrinter 
382 */
383 static WERROR spoolss_ReadPrinter(struct dcesrv_call_state *dce_call, TALLOC_CTX *mem_ctx,
384                        struct spoolss_ReadPrinter *r)
385 {
386         DCESRV_FAULT(DCERPC_FAULT_OP_RNG_ERROR);
387 }
388
389
390 /* 
391   spoolss_EndDocPrinter 
392 */
393 static WERROR spoolss_EndDocPrinter(struct dcesrv_call_state *dce_call, TALLOC_CTX *mem_ctx,
394                        struct spoolss_EndDocPrinter *r)
395 {
396         DCESRV_FAULT(DCERPC_FAULT_OP_RNG_ERROR);
397 }
398
399
400 /* 
401   spoolss_AddJob 
402 */
403 static WERROR spoolss_AddJob(struct dcesrv_call_state *dce_call, TALLOC_CTX *mem_ctx,
404                        struct spoolss_AddJob *r)
405 {
406         DCESRV_FAULT(DCERPC_FAULT_OP_RNG_ERROR);
407 }
408
409
410 /* 
411   spoolss_ScheduleJob 
412 */
413 static WERROR spoolss_ScheduleJob(struct dcesrv_call_state *dce_call, TALLOC_CTX *mem_ctx,
414                        struct spoolss_ScheduleJob *r)
415 {
416         DCESRV_FAULT(DCERPC_FAULT_OP_RNG_ERROR);
417 }
418
419
420 /* 
421   spoolss_GetPrinterData 
422 */
423 static WERROR spoolss_GetPrinterData(struct dcesrv_call_state *dce_call, TALLOC_CTX *mem_ctx,
424                        struct spoolss_GetPrinterData *r)
425 {
426         DCESRV_FAULT(DCERPC_FAULT_OP_RNG_ERROR);
427 }
428
429
430 /* 
431   spoolss_SetPrinterData 
432 */
433 static WERROR spoolss_SetPrinterData(struct dcesrv_call_state *dce_call, TALLOC_CTX *mem_ctx,
434                        struct spoolss_SetPrinterData *r)
435 {
436         DCESRV_FAULT(DCERPC_FAULT_OP_RNG_ERROR);
437 }
438
439
440 /* 
441   spoolss_WaitForPrinterChange 
442 */
443 static WERROR spoolss_WaitForPrinterChange(struct dcesrv_call_state *dce_call, TALLOC_CTX *mem_ctx,
444                        struct spoolss_WaitForPrinterChange *r)
445 {
446         DCESRV_FAULT(DCERPC_FAULT_OP_RNG_ERROR);
447 }
448
449
450 /* 
451   spoolss_ClosePrinter 
452 */
453 static WERROR spoolss_ClosePrinter(struct dcesrv_call_state *dce_call, TALLOC_CTX *mem_ctx,
454                        struct spoolss_ClosePrinter *r)
455 {
456         struct dcesrv_handle *h;
457
458         *r->out.handle = *r->in.handle;
459
460         DCESRV_PULL_HANDLE_WERR(h, r->in.handle, DCESRV_HANDLE_ANY);
461
462         talloc_free(h);
463
464         ZERO_STRUCTP(r->out.handle);
465
466         return WERR_OK;
467 }
468
469
470 /* 
471   spoolss_AddForm 
472 */
473 static WERROR spoolss_AddForm(struct dcesrv_call_state *dce_call, TALLOC_CTX *mem_ctx,
474                        struct spoolss_AddForm *r)
475 {
476         DCESRV_FAULT(DCERPC_FAULT_OP_RNG_ERROR);
477 }
478
479
480 /* 
481   spoolss_DeleteForm 
482 */
483 static WERROR spoolss_DeleteForm(struct dcesrv_call_state *dce_call, TALLOC_CTX *mem_ctx,
484                        struct spoolss_DeleteForm *r)
485 {
486         DCESRV_FAULT(DCERPC_FAULT_OP_RNG_ERROR);
487 }
488
489
490 /* 
491   spoolss_GetForm 
492 */
493 static WERROR spoolss_GetForm(struct dcesrv_call_state *dce_call, TALLOC_CTX *mem_ctx,
494                        struct spoolss_GetForm *r)
495 {
496         DCESRV_FAULT(DCERPC_FAULT_OP_RNG_ERROR);
497 }
498
499
500 /* 
501   spoolss_SetForm 
502 */
503 static WERROR spoolss_SetForm(struct dcesrv_call_state *dce_call, TALLOC_CTX *mem_ctx,
504                        struct spoolss_SetForm *r)
505 {
506         DCESRV_FAULT(DCERPC_FAULT_OP_RNG_ERROR);
507 }
508
509
510 /* 
511   spoolss_EnumForms 
512 */
513 static WERROR spoolss_EnumForms(struct dcesrv_call_state *dce_call, TALLOC_CTX *mem_ctx,
514                        struct spoolss_EnumForms *r)
515 {
516         DCESRV_FAULT(DCERPC_FAULT_OP_RNG_ERROR);
517 }
518
519
520 /* 
521   spoolss_EnumPorts 
522 */
523 static WERROR spoolss_EnumPorts(struct dcesrv_call_state *dce_call, TALLOC_CTX *mem_ctx,
524                        struct spoolss_EnumPorts *r)
525 {
526         DCESRV_FAULT(DCERPC_FAULT_OP_RNG_ERROR);
527 }
528
529
530 /* 
531   spoolss_EnumMonitors 
532 */
533 static WERROR spoolss_EnumMonitors(struct dcesrv_call_state *dce_call, TALLOC_CTX *mem_ctx,
534                        struct spoolss_EnumMonitors *r)
535 {
536         DCESRV_FAULT(DCERPC_FAULT_OP_RNG_ERROR);
537 }
538
539
540 /* 
541   spoolss_AddPort 
542 */
543 static WERROR spoolss_AddPort(struct dcesrv_call_state *dce_call, TALLOC_CTX *mem_ctx,
544                        struct spoolss_AddPort *r)
545 {
546         DCESRV_FAULT(DCERPC_FAULT_OP_RNG_ERROR);
547 }
548
549
550 /* 
551   spoolss_ConfigurePort 
552 */
553 static WERROR spoolss_ConfigurePort(struct dcesrv_call_state *dce_call, TALLOC_CTX *mem_ctx,
554                        struct spoolss_ConfigurePort *r)
555 {
556         DCESRV_FAULT(DCERPC_FAULT_OP_RNG_ERROR);
557 }
558
559
560 /* 
561   spoolss_DeletePort 
562 */
563 static WERROR spoolss_DeletePort(struct dcesrv_call_state *dce_call, TALLOC_CTX *mem_ctx,
564                        struct spoolss_DeletePort *r)
565 {
566         DCESRV_FAULT(DCERPC_FAULT_OP_RNG_ERROR);
567 }
568
569
570 /* 
571   spoolss_CreatePrinterIC 
572 */
573 static WERROR spoolss_CreatePrinterIC(struct dcesrv_call_state *dce_call, TALLOC_CTX *mem_ctx,
574                        struct spoolss_CreatePrinterIC *r)
575 {
576         DCESRV_FAULT(DCERPC_FAULT_OP_RNG_ERROR);
577 }
578
579
580 /* 
581   spoolss_PlayGDIScriptOnPrinterIC 
582 */
583 static WERROR spoolss_PlayGDIScriptOnPrinterIC(struct dcesrv_call_state *dce_call, TALLOC_CTX *mem_ctx,
584                        struct spoolss_PlayGDIScriptOnPrinterIC *r)
585 {
586         DCESRV_FAULT(DCERPC_FAULT_OP_RNG_ERROR);
587 }
588
589
590 /* 
591   spoolss_DeletePrinterIC 
592 */
593 static WERROR spoolss_DeletePrinterIC(struct dcesrv_call_state *dce_call, TALLOC_CTX *mem_ctx,
594                        struct spoolss_DeletePrinterIC *r)
595 {
596         DCESRV_FAULT(DCERPC_FAULT_OP_RNG_ERROR);
597 }
598
599
600 /* 
601   spoolss_AddPrinterConnection 
602 */
603 static WERROR spoolss_AddPrinterConnection(struct dcesrv_call_state *dce_call, TALLOC_CTX *mem_ctx,
604                        struct spoolss_AddPrinterConnection *r)
605 {
606         DCESRV_FAULT(DCERPC_FAULT_OP_RNG_ERROR);
607 }
608
609
610 /* 
611   spoolss_DeletePrinterConnection 
612 */
613 static WERROR spoolss_DeletePrinterConnection(struct dcesrv_call_state *dce_call, TALLOC_CTX *mem_ctx,
614                        struct spoolss_DeletePrinterConnection *r)
615 {
616         DCESRV_FAULT(DCERPC_FAULT_OP_RNG_ERROR);
617 }
618
619
620 /* 
621   spoolss_PrinterMessageBox 
622 */
623 static WERROR spoolss_PrinterMessageBox(struct dcesrv_call_state *dce_call, TALLOC_CTX *mem_ctx,
624                        struct spoolss_PrinterMessageBox *r)
625 {
626         DCESRV_FAULT(DCERPC_FAULT_OP_RNG_ERROR);
627 }
628
629
630 /* 
631   spoolss_AddMonitor 
632 */
633 static WERROR spoolss_AddMonitor(struct dcesrv_call_state *dce_call, TALLOC_CTX *mem_ctx,
634                        struct spoolss_AddMonitor *r)
635 {
636         DCESRV_FAULT(DCERPC_FAULT_OP_RNG_ERROR);
637 }
638
639
640 /* 
641   spoolss_DeleteMonitor 
642 */
643 static WERROR spoolss_DeleteMonitor(struct dcesrv_call_state *dce_call, TALLOC_CTX *mem_ctx,
644                        struct spoolss_DeleteMonitor *r)
645 {
646         DCESRV_FAULT(DCERPC_FAULT_OP_RNG_ERROR);
647 }
648
649
650 /* 
651   spoolss_DeletePrintProcessor 
652 */
653 static WERROR spoolss_DeletePrintProcessor(struct dcesrv_call_state *dce_call, TALLOC_CTX *mem_ctx,
654                        struct spoolss_DeletePrintProcessor *r)
655 {
656         DCESRV_FAULT(DCERPC_FAULT_OP_RNG_ERROR);
657 }
658
659
660 /* 
661   spoolss_AddPrintProvidor 
662 */
663 static WERROR spoolss_AddPrintProvidor(struct dcesrv_call_state *dce_call, TALLOC_CTX *mem_ctx,
664                        struct spoolss_AddPrintProvidor *r)
665 {
666         DCESRV_FAULT(DCERPC_FAULT_OP_RNG_ERROR);
667 }
668
669
670 /* 
671   spoolss_DeletePrintProvidor 
672 */
673 static WERROR spoolss_DeletePrintProvidor(struct dcesrv_call_state *dce_call, TALLOC_CTX *mem_ctx,
674                        struct spoolss_DeletePrintProvidor *r)
675 {
676         DCESRV_FAULT(DCERPC_FAULT_OP_RNG_ERROR);
677 }
678
679
680 /* 
681   spoolss_EnumPrintProcDataTypes 
682 */
683 static WERROR spoolss_EnumPrintProcDataTypes(struct dcesrv_call_state *dce_call, TALLOC_CTX *mem_ctx,
684                        struct spoolss_EnumPrintProcDataTypes *r)
685 {
686         DCESRV_FAULT(DCERPC_FAULT_OP_RNG_ERROR);
687 }
688
689
690 /* 
691   spoolss_ResetPrinter 
692 */
693 static WERROR spoolss_ResetPrinter(struct dcesrv_call_state *dce_call, TALLOC_CTX *mem_ctx,
694                        struct spoolss_ResetPrinter *r)
695 {
696         DCESRV_FAULT(DCERPC_FAULT_OP_RNG_ERROR);
697 }
698
699
700 /* 
701   spoolss_GetPrinterDriver2 
702 */
703 static WERROR spoolss_GetPrinterDriver2(struct dcesrv_call_state *dce_call, TALLOC_CTX *mem_ctx,
704                        struct spoolss_GetPrinterDriver2 *r)
705 {
706         DCESRV_FAULT(DCERPC_FAULT_OP_RNG_ERROR);
707 }
708
709
710 /* 
711   spoolss_FindFirstPrinterChangeNotification 
712 */
713 static WERROR spoolss_FindFirstPrinterChangeNotification(struct dcesrv_call_state *dce_call, TALLOC_CTX *mem_ctx,
714                        struct spoolss_FindFirstPrinterChangeNotification *r)
715 {
716         DCESRV_FAULT(DCERPC_FAULT_OP_RNG_ERROR);
717 }
718
719
720 /* 
721   spoolss_FindNextPrinterChangeNotification 
722 */
723 static WERROR spoolss_FindNextPrinterChangeNotification(struct dcesrv_call_state *dce_call, TALLOC_CTX *mem_ctx,
724                        struct spoolss_FindNextPrinterChangeNotification *r)
725 {
726         DCESRV_FAULT(DCERPC_FAULT_OP_RNG_ERROR);
727 }
728
729
730 /* 
731   spoolss_FindClosePrinterNotify 
732 */
733 static WERROR spoolss_FindClosePrinterNotify(struct dcesrv_call_state *dce_call, TALLOC_CTX *mem_ctx,
734                        struct spoolss_FindClosePrinterNotify *r)
735 {
736         DCESRV_FAULT(DCERPC_FAULT_OP_RNG_ERROR);
737 }
738
739
740 /* 
741   spoolss_RouterFindFirstPrinterChangeNotificationOld 
742 */
743 static WERROR spoolss_RouterFindFirstPrinterChangeNotificationOld(struct dcesrv_call_state *dce_call, TALLOC_CTX *mem_ctx,
744                        struct spoolss_RouterFindFirstPrinterChangeNotificationOld *r)
745 {
746         DCESRV_FAULT(DCERPC_FAULT_OP_RNG_ERROR);
747 }
748
749
750 /* 
751   spoolss_ReplyOpenPrinter 
752 */
753 static WERROR spoolss_ReplyOpenPrinter(struct dcesrv_call_state *dce_call, TALLOC_CTX *mem_ctx,
754                        struct spoolss_ReplyOpenPrinter *r)
755 {
756         DCESRV_FAULT(DCERPC_FAULT_OP_RNG_ERROR);
757 }
758
759
760 /* 
761   spoolss_RouterReplyPrinter 
762 */
763 static WERROR spoolss_RouterReplyPrinter(struct dcesrv_call_state *dce_call, TALLOC_CTX *mem_ctx,
764                        struct spoolss_RouterReplyPrinter *r)
765 {
766         DCESRV_FAULT(DCERPC_FAULT_OP_RNG_ERROR);
767 }
768
769
770 /* 
771   spoolss_ReplyClosePrinter 
772 */
773 static WERROR spoolss_ReplyClosePrinter(struct dcesrv_call_state *dce_call, TALLOC_CTX *mem_ctx,
774                        struct spoolss_ReplyClosePrinter *r)
775 {
776         DCESRV_FAULT(DCERPC_FAULT_OP_RNG_ERROR);
777 }
778
779
780 /* 
781   spoolss_AddPortEx 
782 */
783 static WERROR spoolss_AddPortEx(struct dcesrv_call_state *dce_call, TALLOC_CTX *mem_ctx,
784                        struct spoolss_AddPortEx *r)
785 {
786         DCESRV_FAULT(DCERPC_FAULT_OP_RNG_ERROR);
787 }
788
789
790 /* 
791   spoolss_RouterFindFirstPrinterChangeNotification 
792 */
793 static WERROR spoolss_RouterFindFirstPrinterChangeNotification(struct dcesrv_call_state *dce_call, TALLOC_CTX *mem_ctx,
794                        struct spoolss_RouterFindFirstPrinterChangeNotification *r)
795 {
796         DCESRV_FAULT(DCERPC_FAULT_OP_RNG_ERROR);
797 }
798
799
800 /* 
801   spoolss_SpoolerInit 
802 */
803 static WERROR spoolss_SpoolerInit(struct dcesrv_call_state *dce_call, TALLOC_CTX *mem_ctx,
804                        struct spoolss_SpoolerInit *r)
805 {
806         DCESRV_FAULT(DCERPC_FAULT_OP_RNG_ERROR);
807 }
808
809
810 /* 
811   spoolss_ResetPrinterEx 
812 */
813 static WERROR spoolss_ResetPrinterEx(struct dcesrv_call_state *dce_call, TALLOC_CTX *mem_ctx,
814                        struct spoolss_ResetPrinterEx *r)
815 {
816         DCESRV_FAULT(DCERPC_FAULT_OP_RNG_ERROR);
817 }
818
819
820 /* 
821   spoolss_RemoteFindFirstPrinterChangeNotifyEx 
822 */
823 static WERROR spoolss_RemoteFindFirstPrinterChangeNotifyEx(struct dcesrv_call_state *dce_call, TALLOC_CTX *mem_ctx,
824                        struct spoolss_RemoteFindFirstPrinterChangeNotifyEx *r)
825 {
826         DCESRV_FAULT(DCERPC_FAULT_OP_RNG_ERROR);
827 }
828
829
830 /* 
831   spoolss_RouterRefreshPrinterChangeNotification 
832 */
833 static WERROR spoolss_RouterRefreshPrinterChangeNotification(struct dcesrv_call_state *dce_call, TALLOC_CTX *mem_ctx,
834                        struct spoolss_RouterRefreshPrinterChangeNotification *r)
835 {
836         DCESRV_FAULT(DCERPC_FAULT_OP_RNG_ERROR);
837 }
838
839
840 /* 
841   spoolss_RemoteFindNextPrinterChangeNotifyEx 
842 */
843 static WERROR spoolss_RemoteFindNextPrinterChangeNotifyEx(struct dcesrv_call_state *dce_call, TALLOC_CTX *mem_ctx,
844                        struct spoolss_RemoteFindNextPrinterChangeNotifyEx *r)
845 {
846         DCESRV_FAULT(DCERPC_FAULT_OP_RNG_ERROR);
847 }
848
849
850 /* 
851   spoolss_44 
852 */
853 static WERROR spoolss_44(struct dcesrv_call_state *dce_call, TALLOC_CTX *mem_ctx,
854                        struct spoolss_44 *r)
855 {
856         DCESRV_FAULT(DCERPC_FAULT_OP_RNG_ERROR);
857 }
858
859
860 static WERROR spoolss_OpenPrinterEx_server(struct dcesrv_call_state *dce_call, 
861                                            TALLOC_CTX *mem_ctx,
862                                            struct spoolss_OpenPrinterEx *r,
863                                            const char *server_name)
864 {
865         struct spoolss_handle_server *state;
866         struct dcesrv_handle *handle;
867         BOOL ret;
868
869         /* Check printername is our name or our ip address
870          */
871         ret = strequal(server_name, lp_netbios_name());
872         if (!ret) {
873                 /* TODO:
874                 ret = strequal(server_name, ...our_ip...);*/
875                 if (!ret) {
876                         return WERR_INVALID_PRINTER_NAME;
877                 }
878         }
879
880         handle = dcesrv_handle_new(dce_call->context, SPOOLSS_HANDLE_SERVER);
881         W_ERROR_HAVE_NO_MEMORY(handle);
882
883         state = talloc(handle, struct spoolss_handle_server);
884         W_ERROR_HAVE_NO_MEMORY(state);
885
886         handle->data = state;
887
888         state->handle_type      = SPOOLSS_HANDLE_SERVER;
889         state->access_mask      = r->in.access_mask;
890
891         *r->out.handle  = handle->wire_handle;
892
893         return WERR_OK; 
894 }
895
896 static WERROR spoolss_OpenPrinterEx_printer(struct dcesrv_call_state *dce_call, 
897                                             TALLOC_CTX *mem_ctx,
898                                             struct spoolss_OpenPrinterEx *r,
899                                             const char *printer_name)
900 {
901         DEBUG(0, ("looking for printer %s\n", printer_name));
902         
903         return WERR_INVALID_PRINTER_NAME;
904 }
905
906 /* 
907   spoolss_OpenPrinterEx 
908 */
909 static WERROR spoolss_OpenPrinterEx(struct dcesrv_call_state *dce_call, TALLOC_CTX *mem_ctx,
910                        struct spoolss_OpenPrinterEx *r)
911 {
912         const char *p;
913         const char *printer = r->in.printername;
914         ZERO_STRUCTP(r->out.handle);
915
916         /* just "\\" is invalid */
917         if (strequal(r->in.printername, "\\\\")) {
918                 return WERR_INVALID_PRINTER_NAME;
919         }
920
921         if (strncmp(r->in.printername, "\\\\", 2) == 0) {
922                 /* here we know we have "\\" in front not followed
923                  * by '\0', now see if we have another "\" in the string
924                  */
925                 p = strchr_m(r->in.printername + 2, '\\');
926                 if (!p) {
927                         /* there's no other "\", so it's ("\\%s",server)
928                          */
929                         const char *server = r->in.printername + 2;
930                         DEBUG(0,("print server: [%s][%s]\n", r->in.printername, server));
931                         return spoolss_OpenPrinterEx_server(dce_call, mem_ctx, r, server);
932                 }
933                 /* here we know that we have ("\\%s\",server),
934                  * if we have '\0' as next then it's an invalid name
935                  * otherwise the printer_name
936                  */
937                 p++;
938                 if (p[0] == '\0') {
939                         return WERR_INVALID_PRINTER_NAME;
940                 }
941                 printer = p;
942         }
943
944         DEBUG(0,("printer: [%s][%s]\n", r->in.printername, printer));
945         return spoolss_OpenPrinterEx_printer(dce_call, mem_ctx, r, printer);
946 }
947
948
949 /* 
950   spoolss_AddPrinterEx 
951 */
952 static WERROR spoolss_AddPrinterEx(struct dcesrv_call_state *dce_call, TALLOC_CTX *mem_ctx,
953                        struct spoolss_AddPrinterEx *r)
954 {
955         DCESRV_FAULT(DCERPC_FAULT_OP_RNG_ERROR);
956 }
957
958
959 /* 
960   spoolss_47 
961 */
962 static WERROR spoolss_47(struct dcesrv_call_state *dce_call, TALLOC_CTX *mem_ctx,
963                        struct spoolss_47 *r)
964 {
965         DCESRV_FAULT(DCERPC_FAULT_OP_RNG_ERROR);
966 }
967
968
969 /* 
970   spoolss_EnumPrinterData 
971 */
972 static WERROR spoolss_EnumPrinterData(struct dcesrv_call_state *dce_call, TALLOC_CTX *mem_ctx,
973                        struct spoolss_EnumPrinterData *r)
974 {
975         DCESRV_FAULT(DCERPC_FAULT_OP_RNG_ERROR);
976 }
977
978
979 /* 
980   spoolss_DeletePrinterData 
981 */
982 static WERROR spoolss_DeletePrinterData(struct dcesrv_call_state *dce_call, TALLOC_CTX *mem_ctx,
983                        struct spoolss_DeletePrinterData *r)
984 {
985         DCESRV_FAULT(DCERPC_FAULT_OP_RNG_ERROR);
986 }
987
988
989 /* 
990   spoolss_4a 
991 */
992 static WERROR spoolss_4a(struct dcesrv_call_state *dce_call, TALLOC_CTX *mem_ctx,
993                        struct spoolss_4a *r)
994 {
995         DCESRV_FAULT(DCERPC_FAULT_OP_RNG_ERROR);
996 }
997
998
999 /* 
1000   spoolss_4b 
1001 */
1002 static WERROR spoolss_4b(struct dcesrv_call_state *dce_call, TALLOC_CTX *mem_ctx,
1003                        struct spoolss_4b *r)
1004 {
1005         DCESRV_FAULT(DCERPC_FAULT_OP_RNG_ERROR);
1006 }
1007
1008
1009 /* 
1010   spoolss_4c 
1011 */
1012 static WERROR spoolss_4c(struct dcesrv_call_state *dce_call, TALLOC_CTX *mem_ctx,
1013                        struct spoolss_4c *r)
1014 {
1015         DCESRV_FAULT(DCERPC_FAULT_OP_RNG_ERROR);
1016 }
1017
1018
1019 /* 
1020   spoolss_SetPrinterDataEx 
1021 */
1022 static WERROR spoolss_SetPrinterDataEx(struct dcesrv_call_state *dce_call, TALLOC_CTX *mem_ctx,
1023                        struct spoolss_SetPrinterDataEx *r)
1024 {
1025         DCESRV_FAULT(DCERPC_FAULT_OP_RNG_ERROR);
1026 }
1027
1028
1029 /* 
1030   spoolss_GetPrinterDataEx 
1031 */
1032 static WERROR spoolss_GetPrinterDataEx(struct dcesrv_call_state *dce_call, TALLOC_CTX *mem_ctx,
1033                        struct spoolss_GetPrinterDataEx *r)
1034 {
1035         DCESRV_FAULT(DCERPC_FAULT_OP_RNG_ERROR);
1036 }
1037
1038
1039 /* 
1040   spoolss_EnumPrinterDataEx 
1041 */
1042 static WERROR spoolss_EnumPrinterDataEx(struct dcesrv_call_state *dce_call, TALLOC_CTX *mem_ctx,
1043                        struct spoolss_EnumPrinterDataEx *r)
1044 {
1045         DCESRV_FAULT(DCERPC_FAULT_OP_RNG_ERROR);
1046 }
1047
1048
1049 /* 
1050   spoolss_EnumPrinterKey 
1051 */
1052 static WERROR spoolss_EnumPrinterKey(struct dcesrv_call_state *dce_call, TALLOC_CTX *mem_ctx,
1053                        struct spoolss_EnumPrinterKey *r)
1054 {
1055         DCESRV_FAULT(DCERPC_FAULT_OP_RNG_ERROR);
1056 }
1057
1058
1059 /* 
1060   spoolss_DeletePrinterDataEx 
1061 */
1062 static WERROR spoolss_DeletePrinterDataEx(struct dcesrv_call_state *dce_call, TALLOC_CTX *mem_ctx,
1063                        struct spoolss_DeletePrinterDataEx *r)
1064 {
1065         DCESRV_FAULT(DCERPC_FAULT_OP_RNG_ERROR);
1066 }
1067
1068
1069 /* 
1070   spoolss_DeletePrinterKey 
1071 */
1072 static WERROR spoolss_DeletePrinterKey(struct dcesrv_call_state *dce_call, TALLOC_CTX *mem_ctx,
1073                        struct spoolss_DeletePrinterKey *r)
1074 {
1075         DCESRV_FAULT(DCERPC_FAULT_OP_RNG_ERROR);
1076 }
1077
1078
1079 /* 
1080   spoolss_53 
1081 */
1082 static WERROR spoolss_53(struct dcesrv_call_state *dce_call, TALLOC_CTX *mem_ctx,
1083                        struct spoolss_53 *r)
1084 {
1085         DCESRV_FAULT(DCERPC_FAULT_OP_RNG_ERROR);
1086 }
1087
1088
1089 /* 
1090   spoolss_DeletePrinterDriverEx 
1091 */
1092 static WERROR spoolss_DeletePrinterDriverEx(struct dcesrv_call_state *dce_call, TALLOC_CTX *mem_ctx,
1093                        struct spoolss_DeletePrinterDriverEx *r)
1094 {
1095         DCESRV_FAULT(DCERPC_FAULT_OP_RNG_ERROR);
1096 }
1097
1098
1099 /* 
1100   spoolss_55 
1101 */
1102 static WERROR spoolss_55(struct dcesrv_call_state *dce_call, TALLOC_CTX *mem_ctx,
1103                        struct spoolss_55 *r)
1104 {
1105         DCESRV_FAULT(DCERPC_FAULT_OP_RNG_ERROR);
1106 }
1107
1108
1109 /* 
1110   spoolss_56 
1111 */
1112 static WERROR spoolss_56(struct dcesrv_call_state *dce_call, TALLOC_CTX *mem_ctx,
1113                        struct spoolss_56 *r)
1114 {
1115         DCESRV_FAULT(DCERPC_FAULT_OP_RNG_ERROR);
1116 }
1117
1118
1119 /* 
1120   spoolss_57 
1121 */
1122 static WERROR spoolss_57(struct dcesrv_call_state *dce_call, TALLOC_CTX *mem_ctx,
1123                        struct spoolss_57 *r)
1124 {
1125         DCESRV_FAULT(DCERPC_FAULT_OP_RNG_ERROR);
1126 }
1127
1128
1129 /* 
1130   spoolss_58 
1131 */
1132 static WERROR spoolss_58(struct dcesrv_call_state *dce_call, TALLOC_CTX *mem_ctx,
1133                        struct spoolss_58 *r)
1134 {
1135         DCESRV_FAULT(DCERPC_FAULT_OP_RNG_ERROR);
1136 }
1137
1138
1139 /* 
1140   spoolss_AddPrinterDriverEx 
1141 */
1142 static WERROR spoolss_AddPrinterDriverEx(struct dcesrv_call_state *dce_call, TALLOC_CTX *mem_ctx,
1143                        struct spoolss_AddPrinterDriverEx *r)
1144 {
1145         DCESRV_FAULT(DCERPC_FAULT_OP_RNG_ERROR);
1146 }
1147
1148
1149 /* 
1150   spoolss_5a 
1151 */
1152 static WERROR spoolss_5a(struct dcesrv_call_state *dce_call, TALLOC_CTX *mem_ctx,
1153                        struct spoolss_5a *r)
1154 {
1155         DCESRV_FAULT(DCERPC_FAULT_OP_RNG_ERROR);
1156 }
1157
1158
1159 /* 
1160   spoolss_5b 
1161 */
1162 static WERROR spoolss_5b(struct dcesrv_call_state *dce_call, TALLOC_CTX *mem_ctx,
1163                        struct spoolss_5b *r)
1164 {
1165         DCESRV_FAULT(DCERPC_FAULT_OP_RNG_ERROR);
1166 }
1167
1168
1169 /* 
1170   spoolss_5c 
1171 */
1172 static WERROR spoolss_5c(struct dcesrv_call_state *dce_call, TALLOC_CTX *mem_ctx,
1173                        struct spoolss_5c *r)
1174 {
1175         DCESRV_FAULT(DCERPC_FAULT_OP_RNG_ERROR);
1176 }
1177
1178
1179 /* 
1180   spoolss_5d 
1181 */
1182 static WERROR spoolss_5d(struct dcesrv_call_state *dce_call, TALLOC_CTX *mem_ctx,
1183                        struct spoolss_5d *r)
1184 {
1185         DCESRV_FAULT(DCERPC_FAULT_OP_RNG_ERROR);
1186 }
1187
1188
1189 /* 
1190   spoolss_5e 
1191 */
1192 static WERROR spoolss_5e(struct dcesrv_call_state *dce_call, TALLOC_CTX *mem_ctx,
1193                        struct spoolss_5e *r)
1194 {
1195         DCESRV_FAULT(DCERPC_FAULT_OP_RNG_ERROR);
1196 }
1197
1198
1199 /* 
1200   spoolss_5f 
1201 */
1202 static WERROR spoolss_5f(struct dcesrv_call_state *dce_call, TALLOC_CTX *mem_ctx,
1203                        struct spoolss_5f *r)
1204 {
1205         DCESRV_FAULT(DCERPC_FAULT_OP_RNG_ERROR);
1206 }
1207
1208
1209 /* include the generated boilerplate */
1210 #include "librpc/gen_ndr/ndr_spoolss_s.c"