specversion / device mode fix from APP_HEAD
[Samba.git] / source / rpc_parse / parse_spoolss.c
blobaac1624b713bb8dd1d9d50b4270bf6c66af81238
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 * Copyright (C) Gerald Carter 2000-2002
9 * Copyright (C) Tim Potter 2001.
11 * This program is free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License as published by
13 * the Free Software Foundation; either version 2 of the License, or
14 * (at your option) any later version.
16 * This program is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU General Public License for more details.
21 * You should have received a copy of the GNU General Public License
22 * along with this program; if not, write to the Free Software
23 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
26 #include "includes.h"
28 /*******************************************************************
29 return the length of a UNISTR string.
30 ********************************************************************/
32 static uint32 str_len_uni(UNISTR *source)
34 uint32 i=0;
36 if (!source->buffer)
37 return 0;
39 while (source->buffer[i])
40 i++;
42 return i;
45 /*******************************************************************
46 This should be moved in a more generic lib.
47 ********************************************************************/
49 static BOOL spoolss_io_system_time(char *desc, prs_struct *ps, int depth, SYSTEMTIME *systime)
51 if(!prs_uint16("year", ps, depth, &systime->year))
52 return False;
53 if(!prs_uint16("month", ps, depth, &systime->month))
54 return False;
55 if(!prs_uint16("dayofweek", ps, depth, &systime->dayofweek))
56 return False;
57 if(!prs_uint16("day", ps, depth, &systime->day))
58 return False;
59 if(!prs_uint16("hour", ps, depth, &systime->hour))
60 return False;
61 if(!prs_uint16("minute", ps, depth, &systime->minute))
62 return False;
63 if(!prs_uint16("second", ps, depth, &systime->second))
64 return False;
65 if(!prs_uint16("milliseconds", ps, depth, &systime->milliseconds))
66 return False;
68 return True;
71 /*******************************************************************
72 ********************************************************************/
74 BOOL make_systemtime(SYSTEMTIME *systime, struct tm *unixtime)
76 systime->year=unixtime->tm_year+1900;
77 systime->month=unixtime->tm_mon+1;
78 systime->dayofweek=unixtime->tm_wday;
79 systime->day=unixtime->tm_mday;
80 systime->hour=unixtime->tm_hour;
81 systime->minute=unixtime->tm_min;
82 systime->second=unixtime->tm_sec;
83 systime->milliseconds=0;
85 return True;
88 /*******************************************************************
89 reads or writes an DOC_INFO structure.
90 ********************************************************************/
92 static BOOL smb_io_doc_info_1(char *desc, DOC_INFO_1 *info_1, prs_struct *ps, int depth)
94 if (info_1 == NULL) return False;
96 prs_debug(ps, depth, desc, "smb_io_doc_info_1");
97 depth++;
99 if(!prs_align(ps))
100 return False;
102 if(!prs_uint32("p_docname", ps, depth, &info_1->p_docname))
103 return False;
104 if(!prs_uint32("p_outputfile", ps, depth, &info_1->p_outputfile))
105 return False;
106 if(!prs_uint32("p_datatype", ps, depth, &info_1->p_datatype))
107 return False;
109 if(!smb_io_unistr2("", &info_1->docname, info_1->p_docname, ps, depth))
110 return False;
111 if(!smb_io_unistr2("", &info_1->outputfile, info_1->p_outputfile, ps, depth))
112 return False;
113 if(!smb_io_unistr2("", &info_1->datatype, info_1->p_datatype, ps, depth))
114 return False;
116 return True;
119 /*******************************************************************
120 reads or writes an DOC_INFO structure.
121 ********************************************************************/
123 static BOOL smb_io_doc_info(char *desc, DOC_INFO *info, prs_struct *ps, int depth)
125 uint32 useless_ptr=0;
127 if (info == NULL) return False;
129 prs_debug(ps, depth, desc, "smb_io_doc_info");
130 depth++;
132 if(!prs_align(ps))
133 return False;
135 if(!prs_uint32("switch_value", ps, depth, &info->switch_value))
136 return False;
138 if(!prs_uint32("doc_info_X ptr", ps, depth, &useless_ptr))
139 return False;
141 switch (info->switch_value)
143 case 1:
144 if(!smb_io_doc_info_1("",&info->doc_info_1, ps, depth))
145 return False;
146 break;
147 case 2:
149 this is just a placeholder
151 MSDN July 1998 says doc_info_2 is only on
152 Windows 95, and as Win95 doesn't do RPC to print
153 this case is nearly impossible
155 Maybe one day with Windows for dishwasher 2037 ...
158 /* smb_io_doc_info_2("",&info->doc_info_2, ps, depth); */
159 break;
160 default:
161 DEBUG(0,("Something is obviously wrong somewhere !\n"));
162 break;
165 return True;
168 /*******************************************************************
169 reads or writes an DOC_INFO_CONTAINER structure.
170 ********************************************************************/
172 static BOOL smb_io_doc_info_container(char *desc, DOC_INFO_CONTAINER *cont, prs_struct *ps, int depth)
174 if (cont == NULL) return False;
176 prs_debug(ps, depth, desc, "smb_io_doc_info_container");
177 depth++;
179 if(!prs_align(ps))
180 return False;
182 if(!prs_uint32("level", ps, depth, &cont->level))
183 return False;
185 if(!smb_io_doc_info("",&cont->docinfo, ps, depth))
186 return False;
188 return True;
191 /*******************************************************************
192 reads or writes an NOTIFY OPTION TYPE structure.
193 ********************************************************************/
195 /* NOTIFY_OPTION_TYPE and NOTIFY_OPTION_TYPE_DATA are really one
196 structure. The _TYPE structure is really the deferred referrants (i.e
197 the notify fields array) of the _TYPE structure. -tpot */
199 static BOOL smb_io_notify_option_type(char *desc, SPOOL_NOTIFY_OPTION_TYPE *type, prs_struct *ps, int depth)
201 prs_debug(ps, depth, desc, "smb_io_notify_option_type");
202 depth++;
204 if (!prs_align(ps))
205 return False;
207 if(!prs_uint16("type", ps, depth, &type->type))
208 return False;
209 if(!prs_uint16("reserved0", ps, depth, &type->reserved0))
210 return False;
211 if(!prs_uint32("reserved1", ps, depth, &type->reserved1))
212 return False;
213 if(!prs_uint32("reserved2", ps, depth, &type->reserved2))
214 return False;
215 if(!prs_uint32("count", ps, depth, &type->count))
216 return False;
217 if(!prs_uint32("fields_ptr", ps, depth, &type->fields_ptr))
218 return False;
220 return True;
223 /*******************************************************************
224 reads or writes an NOTIFY OPTION TYPE DATA.
225 ********************************************************************/
227 static BOOL smb_io_notify_option_type_data(char *desc, SPOOL_NOTIFY_OPTION_TYPE *type, prs_struct *ps, int depth)
229 int i;
231 prs_debug(ps, depth, desc, "smb_io_notify_option_type_data");
232 depth++;
234 /* if there are no fields just return */
235 if (type->fields_ptr==0)
236 return True;
238 if(!prs_align(ps))
239 return False;
241 if(!prs_uint32("count2", ps, depth, &type->count2))
242 return False;
244 if (type->count2 != type->count)
245 DEBUG(4,("What a mess, count was %x now is %x !\n", type->count, type->count2));
247 /* parse the option type data */
248 for(i=0;i<type->count2;i++)
249 if(!prs_uint16("fields",ps,depth,&type->fields[i]))
250 return False;
251 return True;
254 /*******************************************************************
255 reads or writes an NOTIFY OPTION structure.
256 ********************************************************************/
258 static BOOL smb_io_notify_option_type_ctr(char *desc, SPOOL_NOTIFY_OPTION_TYPE_CTR *ctr , prs_struct *ps, int depth)
260 int i;
262 prs_debug(ps, depth, desc, "smb_io_notify_option_type_ctr");
263 depth++;
265 if(!prs_uint32("count", ps, depth, &ctr->count))
266 return False;
268 /* reading */
269 if (UNMARSHALLING(ps))
270 if((ctr->type=(SPOOL_NOTIFY_OPTION_TYPE *)prs_alloc_mem(ps,ctr->count*sizeof(SPOOL_NOTIFY_OPTION_TYPE))) == NULL)
271 return False;
273 /* the option type struct */
274 for(i=0;i<ctr->count;i++)
275 if(!smb_io_notify_option_type("", &ctr->type[i] , ps, depth))
276 return False;
278 /* the type associated with the option type struct */
279 for(i=0;i<ctr->count;i++)
280 if(!smb_io_notify_option_type_data("", &ctr->type[i] , ps, depth))
281 return False;
283 return True;
286 /*******************************************************************
287 reads or writes an NOTIFY OPTION structure.
288 ********************************************************************/
290 static BOOL smb_io_notify_option(char *desc, SPOOL_NOTIFY_OPTION *option, prs_struct *ps, int depth)
292 prs_debug(ps, depth, desc, "smb_io_notify_option");
293 depth++;
295 if(!prs_uint32("version", ps, depth, &option->version))
296 return False;
297 if(!prs_uint32("flags", ps, depth, &option->flags))
298 return False;
299 if(!prs_uint32("count", ps, depth, &option->count))
300 return False;
301 if(!prs_uint32("option_type_ptr", ps, depth, &option->option_type_ptr))
302 return False;
304 /* marshalling or unmarshalling, that would work */
305 if (option->option_type_ptr!=0) {
306 if(!smb_io_notify_option_type_ctr("", &option->ctr ,ps, depth))
307 return False;
309 else {
310 option->ctr.type=NULL;
311 option->ctr.count=0;
314 return True;
317 /*******************************************************************
318 reads or writes an NOTIFY INFO DATA structure.
319 ********************************************************************/
321 static BOOL smb_io_notify_info_data(char *desc,SPOOL_NOTIFY_INFO_DATA *data, prs_struct *ps, int depth)
323 uint32 useless_ptr=0xADDE0FF0;
325 uint32 how_many_words;
326 BOOL isvalue;
327 uint32 x;
329 prs_debug(ps, depth, desc, "smb_io_notify_info_data");
330 depth++;
332 how_many_words=data->size;
333 if (how_many_words==POINTER) {
334 how_many_words=TWO_VALUE;
337 isvalue=data->enc_type;
339 if(!prs_align(ps))
340 return False;
341 if(!prs_uint16("type", ps, depth, &data->type))
342 return False;
343 if(!prs_uint16("field", ps, depth, &data->field))
344 return False;
345 /*prs_align(ps);*/
347 if(!prs_uint32("how many words", ps, depth, &how_many_words))
348 return False;
349 if(!prs_uint32("id", ps, depth, &data->id))
350 return False;
351 if(!prs_uint32("how many words", ps, depth, &how_many_words))
352 return False;
355 /*prs_align(ps);*/
357 if (isvalue==True) {
358 if(!prs_uint32("value[0]", ps, depth, &data->notify_data.value[0]))
359 return False;
360 if(!prs_uint32("value[1]", ps, depth, &data->notify_data.value[1]))
361 return False;
362 /*prs_align(ps);*/
363 } else {
364 /* it's a string */
365 /* length in ascii including \0 */
366 x=2*(data->notify_data.data.length+1);
367 if(!prs_uint32("string length", ps, depth, &x ))
368 return False;
369 if(!prs_uint32("pointer", ps, depth, &useless_ptr))
370 return False;
371 /*prs_align(ps);*/
374 return True;
377 /*******************************************************************
378 reads or writes an NOTIFY INFO DATA structure.
379 ********************************************************************/
381 BOOL smb_io_notify_info_data_strings(char *desc,SPOOL_NOTIFY_INFO_DATA *data,
382 prs_struct *ps, int depth)
384 uint32 x;
385 BOOL isvalue;
387 prs_debug(ps, depth, desc, "smb_io_notify_info_data_strings");
388 depth++;
390 if(!prs_align(ps))
391 return False;
393 isvalue=data->enc_type;
395 if (isvalue==False) {
396 /* length of string in unicode include \0 */
397 x=data->notify_data.data.length+1;
398 if(!prs_uint32("string length", ps, depth, &x ))
399 return False;
400 if (MARSHALLING(ps)) {
401 /* These are already in little endian format. Don't byte swap. */
402 if (x == 1) {
404 /* No memory allocated for this string
405 therefore following the data.string
406 pointer is a bad idea. Use a pointer to
407 the uint32 length union member to
408 provide a source for a unicode NULL */
410 if(!prs_uint8s(True,"string",ps,depth, (uint8 *)&data->notify_data.data.length,x*2))
411 return False;
412 } else {
413 if(!prs_uint16uni(True,"string",ps,depth,data->notify_data.data.string,x))
414 return False;
416 } else {
418 /* Tallocate memory for string */
420 data->notify_data.data.string = (uint16 *)prs_alloc_mem(ps, x * 2);
421 if (!data->notify_data.data.string)
422 return False;
424 if(!prs_uint16uni(True,"string",ps,depth,data->notify_data.data.string,x))
425 return False;
428 #if 0 /* JERRY */
430 /* Win2k does not seem to put this parse align here */
432 if(!prs_align(ps))
433 return False;
434 #endif
436 return True;
439 /*******************************************************************
440 reads or writes an NOTIFY INFO structure.
441 ********************************************************************/
443 static BOOL smb_io_notify_info(char *desc, SPOOL_NOTIFY_INFO *info, prs_struct *ps, int depth)
445 int i;
447 prs_debug(ps, depth, desc, "smb_io_notify_info");
448 depth++;
450 if(!prs_align(ps))
451 return False;
453 if(!prs_uint32("count", ps, depth, &info->count))
454 return False;
455 if(!prs_uint32("version", ps, depth, &info->version))
456 return False;
457 if(!prs_uint32("flags", ps, depth, &info->flags))
458 return False;
459 if(!prs_uint32("count", ps, depth, &info->count))
460 return False;
462 for (i=0;i<info->count;i++) {
463 if(!smb_io_notify_info_data(desc, &info->data[i], ps, depth))
464 return False;
467 /* now do the strings at the end of the stream */
468 for (i=0;i<info->count;i++) {
469 if(!smb_io_notify_info_data_strings(desc, &info->data[i], ps, depth))
470 return False;
473 return True;
476 /*******************************************************************
477 ********************************************************************/
479 static BOOL spool_io_user_level_1(char *desc, SPOOL_USER_1 *q_u, prs_struct *ps, int depth)
481 prs_debug(ps, depth, desc, "");
482 depth++;
484 /* reading */
485 if (UNMARSHALLING(ps))
486 ZERO_STRUCTP(q_u);
488 if (!prs_align(ps))
489 return False;
490 if (!prs_uint32("size", ps, depth, &q_u->size))
491 return False;
492 if (!prs_uint32("client_name_ptr", ps, depth, &q_u->client_name_ptr))
493 return False;
494 if (!prs_uint32("user_name_ptr", ps, depth, &q_u->user_name_ptr))
495 return False;
496 if (!prs_uint32("build", ps, depth, &q_u->build))
497 return False;
498 if (!prs_uint32("major", ps, depth, &q_u->major))
499 return False;
500 if (!prs_uint32("minor", ps, depth, &q_u->minor))
501 return False;
502 if (!prs_uint32("processor", ps, depth, &q_u->processor))
503 return False;
505 if (!smb_io_unistr2("", &q_u->client_name, q_u->client_name_ptr, ps, depth))
506 return False;
507 if (!prs_align(ps))
508 return False;
509 if (!smb_io_unistr2("", &q_u->user_name, q_u->user_name_ptr, ps, depth))
510 return False;
512 return True;
515 /*******************************************************************
516 ********************************************************************/
518 static BOOL spool_io_user_level(char *desc, SPOOL_USER_CTR *q_u, prs_struct *ps, int depth)
520 if (q_u==NULL)
521 return False;
523 prs_debug(ps, depth, desc, "spool_io_user_level");
524 depth++;
526 if (!prs_align(ps))
527 return False;
528 if (!prs_uint32("level", ps, depth, &q_u->level))
529 return False;
530 if (!prs_uint32("ptr", ps, depth, &q_u->ptr))
531 return False;
533 switch (q_u->level) {
534 case 1:
535 if (!spool_io_user_level_1("", &q_u->user1, ps, depth))
536 return False;
537 break;
538 default:
539 return False;
542 return True;
545 /*******************************************************************
546 * read or write a DEVICEMODE struct.
547 * on reading allocate memory for the private member
548 ********************************************************************/
550 BOOL spoolss_io_devmode(char *desc, prs_struct *ps, int depth, DEVICEMODE *devmode)
552 prs_debug(ps, depth, desc, "spoolss_io_devmode");
553 depth++;
555 if (UNMARSHALLING(ps)) {
556 devmode->devicename.buffer = (uint16 *)prs_alloc_mem(ps, 32 * sizeof(uint16) );
557 if (devmode->devicename.buffer == NULL)
558 return False;
561 if (!prs_uint16uni(True,"devicename", ps, depth, devmode->devicename.buffer, 32))
562 return False;
563 if (!prs_uint16("specversion", ps, depth, &devmode->specversion))
564 return False;
565 if (!prs_uint16("driverversion", ps, depth, &devmode->driverversion))
566 return False;
567 if (!prs_uint16("size", ps, depth, &devmode->size))
568 return False;
569 if (!prs_uint16("driverextra", ps, depth, &devmode->driverextra))
570 return False;
571 if (!prs_uint32("fields", ps, depth, &devmode->fields))
572 return False;
573 if (!prs_uint16("orientation", ps, depth, &devmode->orientation))
574 return False;
575 if (!prs_uint16("papersize", ps, depth, &devmode->papersize))
576 return False;
577 if (!prs_uint16("paperlength", ps, depth, &devmode->paperlength))
578 return False;
579 if (!prs_uint16("paperwidth", ps, depth, &devmode->paperwidth))
580 return False;
581 if (!prs_uint16("scale", ps, depth, &devmode->scale))
582 return False;
583 if (!prs_uint16("copies", ps, depth, &devmode->copies))
584 return False;
585 if (!prs_uint16("defaultsource", ps, depth, &devmode->defaultsource))
586 return False;
587 if (!prs_uint16("printquality", ps, depth, &devmode->printquality))
588 return False;
589 if (!prs_uint16("color", ps, depth, &devmode->color))
590 return False;
591 if (!prs_uint16("duplex", ps, depth, &devmode->duplex))
592 return False;
593 if (!prs_uint16("yresolution", ps, depth, &devmode->yresolution))
594 return False;
595 if (!prs_uint16("ttoption", ps, depth, &devmode->ttoption))
596 return False;
597 if (!prs_uint16("collate", ps, depth, &devmode->collate))
598 return False;
600 if (UNMARSHALLING(ps)) {
601 devmode->formname.buffer = (uint16 *)prs_alloc_mem(ps, 32 * sizeof(uint16) );
602 if (devmode->formname.buffer == NULL)
603 return False;
606 if (!prs_uint16uni(True, "formname", ps, depth, devmode->formname.buffer, 32))
607 return False;
608 if (!prs_uint16("logpixels", ps, depth, &devmode->logpixels))
609 return False;
610 if (!prs_uint32("bitsperpel", ps, depth, &devmode->bitsperpel))
611 return False;
612 if (!prs_uint32("pelswidth", ps, depth, &devmode->pelswidth))
613 return False;
614 if (!prs_uint32("pelsheight", ps, depth, &devmode->pelsheight))
615 return False;
616 if (!prs_uint32("displayflags", ps, depth, &devmode->displayflags))
617 return False;
618 if (!prs_uint32("displayfrequency", ps, depth, &devmode->displayfrequency))
619 return False;
622 * Conditional parsing. Assume that the DeviceMode has been
623 * zero'd by the caller.
625 switch(devmode->specversion) {
627 /* Used by spooler when issuing OpenPrinter() calls. NT 3.5x? */
628 case 0x0320:
629 break;
631 /* See the comments on the DEVMODE in the msdn GDI documentation */
632 case 0x0400:
633 case 0x0401:
634 if (!prs_uint32("icmmethod", ps, depth, &devmode->icmmethod))
635 return False;
636 if (!prs_uint32("icmintent", ps, depth, &devmode->icmintent))
637 return False;
638 if (!prs_uint32("mediatype", ps, depth, &devmode->mediatype))
639 return False;
640 if (!prs_uint32("dithertype", ps, depth, &devmode->dithertype))
641 return False;
642 if (!prs_uint32("reserved1", ps, depth, &devmode->reserved1))
643 return False;
644 if (!prs_uint32("reserved2", ps, depth, &devmode->reserved2))
645 return False;
646 if (!prs_uint32("panningwidth", ps, depth, &devmode->panningwidth))
647 return False;
648 if (!prs_uint32("panningheight", ps, depth, &devmode->panningheight))
649 return False;
650 break;
652 /* log an error if we see something else */
653 default:
654 DEBUG(0,("spoolss_io_devmode: Unknown specversion [0x%x]!\n", devmode->specversion));
655 DEBUG(0,("spoolss_io_devmode: Please report to samba-technical@samba.org\n"));
656 break;
659 if (devmode->driverextra!=0) {
660 if (UNMARSHALLING(ps)) {
661 devmode->private=(uint8 *)prs_alloc_mem(ps, devmode->driverextra*sizeof(uint8));
662 if(devmode->private == NULL)
663 return False;
664 DEBUG(7,("spoolss_io_devmode: allocated memory [%d] for private\n",devmode->driverextra));
667 DEBUG(7,("spoolss_io_devmode: parsing [%d] bytes of private\n",devmode->driverextra));
668 if (!prs_uint8s(False, "private", ps, depth,
669 devmode->private, devmode->driverextra))
670 return False;
673 return True;
676 /*******************************************************************
677 Read or write a DEVICEMODE container
678 ********************************************************************/
680 static BOOL spoolss_io_devmode_cont(char *desc, DEVMODE_CTR *dm_c, prs_struct *ps, int depth)
682 if (dm_c==NULL)
683 return False;
685 prs_debug(ps, depth, desc, "spoolss_io_devmode_cont");
686 depth++;
688 if(!prs_align(ps))
689 return False;
691 if (!prs_uint32("size", ps, depth, &dm_c->size))
692 return False;
694 if (!prs_uint32("devmode_ptr", ps, depth, &dm_c->devmode_ptr))
695 return False;
697 if (dm_c->size==0 || dm_c->devmode_ptr==0) {
698 if (UNMARSHALLING(ps))
699 /* if while reading there is no DEVMODE ... */
700 dm_c->devmode=NULL;
701 return True;
704 /* so we have a DEVICEMODE to follow */
705 if (UNMARSHALLING(ps)) {
706 DEBUG(9,("Allocating memory for spoolss_io_devmode\n"));
707 dm_c->devmode=(DEVICEMODE *)prs_alloc_mem(ps,sizeof(DEVICEMODE));
708 if(dm_c->devmode == NULL)
709 return False;
712 /* this is bad code, shouldn't be there */
713 if (!prs_uint32("size", ps, depth, &dm_c->size))
714 return False;
716 if (!spoolss_io_devmode(desc, ps, depth, dm_c->devmode))
717 return False;
719 return True;
722 /*******************************************************************
723 ********************************************************************/
725 static BOOL spoolss_io_printer_default(char *desc, PRINTER_DEFAULT *pd, prs_struct *ps, int depth)
727 if (pd==NULL)
728 return False;
730 prs_debug(ps, depth, desc, "spoolss_io_printer_default");
731 depth++;
733 if (!prs_uint32("datatype_ptr", ps, depth, &pd->datatype_ptr))
734 return False;
736 if (!smb_io_unistr2("datatype", &pd->datatype, pd->datatype_ptr, ps,depth))
737 return False;
739 if (!prs_align(ps))
740 return False;
742 if (!spoolss_io_devmode_cont("", &pd->devmode_cont, ps, depth))
743 return False;
745 if (!prs_align(ps))
746 return False;
748 if (!prs_uint32("access_required", ps, depth, &pd->access_required))
749 return False;
751 return True;
754 /*******************************************************************
755 * init a structure.
756 ********************************************************************/
758 BOOL make_spoolss_q_open_printer_ex(SPOOL_Q_OPEN_PRINTER_EX *q_u,
759 const fstring printername,
760 const fstring datatype,
761 uint32 access_required,
762 const fstring clientname,
763 const fstring user_name)
765 DEBUG(5,("make_spoolss_q_open_printer_ex\n"));
766 q_u->printername_ptr = (printername!=NULL)?1:0;
767 init_unistr2(&q_u->printername, printername, strlen(printername)+1);
769 q_u->printer_default.datatype_ptr = 0;
771 q_u->printer_default.datatype_ptr = (datatype!=NULL)?1:0;
772 init_unistr2(&q_u->printer_default.datatype, datatype, strlen(datatype));
774 q_u->printer_default.devmode_cont.size=0;
775 q_u->printer_default.devmode_cont.devmode_ptr=0;
776 q_u->printer_default.devmode_cont.devmode=NULL;
777 q_u->printer_default.access_required=access_required;
778 q_u->user_switch=1;
779 q_u->user_ctr.level=1;
780 q_u->user_ctr.ptr=1;
781 q_u->user_ctr.user1.size=strlen(clientname)+strlen(user_name)+10;
782 q_u->user_ctr.user1.client_name_ptr = (clientname!=NULL)?1:0;
783 q_u->user_ctr.user1.user_name_ptr = (user_name!=NULL)?1:0;
784 q_u->user_ctr.user1.build=1381;
785 q_u->user_ctr.user1.major=2;
786 q_u->user_ctr.user1.minor=0;
787 q_u->user_ctr.user1.processor=0;
788 init_unistr2(&q_u->user_ctr.user1.client_name, clientname, strlen(clientname)+1);
789 init_unistr2(&q_u->user_ctr.user1.user_name, user_name, strlen(user_name)+1);
791 return True;
794 /*******************************************************************
795 * init a structure.
796 ********************************************************************/
798 BOOL make_spoolss_q_addprinterex(
799 TALLOC_CTX *mem_ctx,
800 SPOOL_Q_ADDPRINTEREX *q_u,
801 const char *srv_name,
802 const char* clientname,
803 const char* user_name,
804 uint32 level,
805 PRINTER_INFO_CTR *ctr)
807 DEBUG(5,("make_spoolss_q_addprinterex\n"));
809 if (!ctr) return False;
811 ZERO_STRUCTP(q_u);
813 q_u->server_name_ptr = (srv_name!=NULL)?1:0;
814 init_unistr2(&q_u->server_name, srv_name, strlen(srv_name));
816 q_u->level = level;
818 q_u->info.level = level;
819 q_u->info.info_ptr = (ctr->printers_2!=NULL)?1:0;
820 switch (level) {
821 case 2:
822 /* init q_u->info.info2 from *info */
823 if (!make_spoolss_printer_info_2(mem_ctx, &q_u->info.info_2, ctr->printers_2)) {
824 DEBUG(0,("make_spoolss_q_addprinterex: Unable to fill SPOOL_Q_ADDPRINTEREX struct!\n"));
825 return False;
827 break;
828 default :
829 break;
832 q_u->user_switch=1;
834 q_u->user_ctr.level=1;
835 q_u->user_ctr.ptr=1;
836 q_u->user_ctr.user1.client_name_ptr = (clientname!=NULL)?1:0;
837 q_u->user_ctr.user1.user_name_ptr = (user_name!=NULL)?1:0;
838 q_u->user_ctr.user1.build=1381;
839 q_u->user_ctr.user1.major=2;
840 q_u->user_ctr.user1.minor=0;
841 q_u->user_ctr.user1.processor=0;
842 init_unistr2(&q_u->user_ctr.user1.client_name, clientname, strlen(clientname)+1);
843 init_unistr2(&q_u->user_ctr.user1.user_name, user_name, strlen(user_name)+1);
844 q_u->user_ctr.user1.size=q_u->user_ctr.user1.user_name.uni_str_len +
845 q_u->user_ctr.user1.client_name.uni_str_len + 2;
847 return True;
850 /*******************************************************************
851 create a SPOOL_PRINTER_INFO_2 stuct from a PRINTER_INFO_2 struct
852 *******************************************************************/
854 BOOL make_spoolss_printer_info_2(TALLOC_CTX *mem_ctx, SPOOL_PRINTER_INFO_LEVEL_2 **spool_info2,
855 PRINTER_INFO_2 *info)
858 SPOOL_PRINTER_INFO_LEVEL_2 *inf;
860 /* allocate the necessary memory */
861 if (!(inf=(SPOOL_PRINTER_INFO_LEVEL_2*)talloc(mem_ctx, sizeof(SPOOL_PRINTER_INFO_LEVEL_2)))) {
862 DEBUG(0,("make_spoolss_printer_info_2: Unable to allocate SPOOL_PRINTER_INFO_LEVEL_2 sruct!\n"));
863 return False;
866 inf->servername_ptr = (info->servername.buffer!=NULL)?1:0;
867 inf->printername_ptr = (info->printername.buffer!=NULL)?1:0;
868 inf->sharename_ptr = (info->sharename.buffer!=NULL)?1:0;
869 inf->portname_ptr = (info->portname.buffer!=NULL)?1:0;
870 inf->drivername_ptr = (info->drivername.buffer!=NULL)?1:0;
871 inf->comment_ptr = (info->comment.buffer!=NULL)?1:0;
872 inf->location_ptr = (info->location.buffer!=NULL)?1:0;
873 inf->devmode_ptr = (info->devmode!=NULL)?1:0;
874 inf->sepfile_ptr = (info->sepfile.buffer!=NULL)?1:0;
875 inf->printprocessor_ptr = (info->printprocessor.buffer!=NULL)?1:0;
876 inf->datatype_ptr = (info->datatype.buffer!=NULL)?1:0;
877 inf->parameters_ptr = (info->parameters.buffer!=NULL)?1:0;
878 inf->secdesc_ptr = (info->secdesc!=NULL)?1:0;
879 inf->attributes = info->attributes;
880 inf->priority = info->priority;
881 inf->default_priority = info->defaultpriority;
882 inf->starttime = info->starttime;
883 inf->untiltime = info->untiltime;
884 inf->cjobs = info->cjobs;
885 inf->averageppm = info->averageppm;
886 init_unistr2_from_unistr(&inf->servername, &info->servername);
887 init_unistr2_from_unistr(&inf->printername, &info->printername);
888 init_unistr2_from_unistr(&inf->sharename, &info->sharename);
889 init_unistr2_from_unistr(&inf->portname, &info->portname);
890 init_unistr2_from_unistr(&inf->drivername, &info->drivername);
891 init_unistr2_from_unistr(&inf->comment, &info->comment);
892 init_unistr2_from_unistr(&inf->location, &info->location);
893 init_unistr2_from_unistr(&inf->sepfile, &info->sepfile);
894 init_unistr2_from_unistr(&inf->printprocessor, &info->printprocessor);
895 init_unistr2_from_unistr(&inf->datatype, &info->datatype);
896 init_unistr2_from_unistr(&inf->parameters, &info->parameters);
897 init_unistr2_from_unistr(&inf->datatype, &info->datatype);
899 *spool_info2 = inf;
901 return True;
905 /*******************************************************************
906 * read a structure.
907 * called from spoolss_q_open_printer_ex (srv_spoolss.c)
908 ********************************************************************/
910 BOOL spoolss_io_q_open_printer(char *desc, SPOOL_Q_OPEN_PRINTER *q_u, prs_struct *ps, int depth)
912 if (q_u == NULL)
913 return False;
915 prs_debug(ps, depth, desc, "spoolss_io_q_open_printer");
916 depth++;
918 if (!prs_align(ps))
919 return False;
921 if (!prs_uint32("printername_ptr", ps, depth, &q_u->printername_ptr))
922 return False;
923 if (!smb_io_unistr2("", &q_u->printername, q_u->printername_ptr, ps,depth))
924 return False;
926 if (!prs_align(ps))
927 return False;
929 if (!spoolss_io_printer_default("", &q_u->printer_default, ps, depth))
930 return False;
932 return True;
935 /*******************************************************************
936 * write a structure.
937 * called from static spoolss_r_open_printer_ex (srv_spoolss.c)
938 * called from spoolss_open_printer_ex (cli_spoolss.c)
939 ********************************************************************/
941 BOOL spoolss_io_r_open_printer(char *desc, SPOOL_R_OPEN_PRINTER *r_u, prs_struct *ps, int depth)
943 if (r_u == NULL) return False;
945 prs_debug(ps, depth, desc, "spoolss_io_r_open_printer");
946 depth++;
948 if (!prs_align(ps))
949 return False;
951 if (!smb_io_pol_hnd("printer handle",&(r_u->handle),ps,depth))
952 return False;
954 if (!prs_werror("status code", ps, depth, &(r_u->status)))
955 return False;
957 return True;
961 /*******************************************************************
962 * read a structure.
963 * called from spoolss_q_open_printer_ex (srv_spoolss.c)
964 ********************************************************************/
966 BOOL spoolss_io_q_open_printer_ex(char *desc, SPOOL_Q_OPEN_PRINTER_EX *q_u, prs_struct *ps, int depth)
968 if (q_u == NULL)
969 return False;
971 prs_debug(ps, depth, desc, "spoolss_io_q_open_printer_ex");
972 depth++;
974 if (!prs_align(ps))
975 return False;
977 if (!prs_uint32("printername_ptr", ps, depth, &q_u->printername_ptr))
978 return False;
979 if (!smb_io_unistr2("", &q_u->printername, q_u->printername_ptr, ps,depth))
980 return False;
982 if (!prs_align(ps))
983 return False;
985 if (!spoolss_io_printer_default("", &q_u->printer_default, ps, depth))
986 return False;
988 if (!prs_uint32("user_switch", ps, depth, &q_u->user_switch))
989 return False;
990 if (!spool_io_user_level("", &q_u->user_ctr, ps, depth))
991 return False;
993 return True;
996 /*******************************************************************
997 * write a structure.
998 * called from static spoolss_r_open_printer_ex (srv_spoolss.c)
999 * called from spoolss_open_printer_ex (cli_spoolss.c)
1000 ********************************************************************/
1002 BOOL spoolss_io_r_open_printer_ex(char *desc, SPOOL_R_OPEN_PRINTER_EX *r_u, prs_struct *ps, int depth)
1004 if (r_u == NULL) return False;
1006 prs_debug(ps, depth, desc, "spoolss_io_r_open_printer_ex");
1007 depth++;
1009 if (!prs_align(ps))
1010 return False;
1012 if (!smb_io_pol_hnd("printer handle",&(r_u->handle),ps,depth))
1013 return False;
1015 if (!prs_werror("status code", ps, depth, &(r_u->status)))
1016 return False;
1018 return True;
1021 /*******************************************************************
1022 * init a structure.
1023 ********************************************************************/
1024 BOOL make_spoolss_q_deleteprinterdriver(
1025 TALLOC_CTX *mem_ctx,
1026 SPOOL_Q_DELETEPRINTERDRIVER *q_u,
1027 const char *server,
1028 const char* arch,
1029 const char* driver
1032 DEBUG(5,("make_spoolss_q_deleteprinterdriver\n"));
1034 q_u->server_ptr = (server!=NULL)?1:0;
1036 /* these must be NULL terminated or else NT4 will
1037 complain about invalid parameters --jerry */
1038 init_unistr2(&q_u->server, server, strlen(server)+1);
1039 init_unistr2(&q_u->arch, arch, strlen(arch)+1);
1040 init_unistr2(&q_u->driver, driver, strlen(driver)+1);
1043 return True;
1047 /*******************************************************************
1048 * make a structure.
1049 ********************************************************************/
1051 BOOL make_spoolss_q_getprinterdata(SPOOL_Q_GETPRINTERDATA *q_u,
1052 const POLICY_HND *handle,
1053 UNISTR2 *valuename, uint32 size)
1055 if (q_u == NULL) return False;
1057 DEBUG(5,("make_spoolss_q_getprinterdata\n"));
1059 q_u->handle = *handle;
1060 copy_unistr2(&q_u->valuename, valuename);
1061 q_u->size = size;
1063 return True;
1066 /*******************************************************************
1067 * read a structure.
1068 * called from spoolss_q_getprinterdata (srv_spoolss.c)
1069 ********************************************************************/
1071 BOOL spoolss_io_q_getprinterdata(char *desc, SPOOL_Q_GETPRINTERDATA *q_u, prs_struct *ps, int depth)
1073 if (q_u == NULL)
1074 return False;
1076 prs_debug(ps, depth, desc, "spoolss_io_q_getprinterdata");
1077 depth++;
1079 if (!prs_align(ps))
1080 return False;
1081 if (!smb_io_pol_hnd("printer handle",&q_u->handle,ps,depth))
1082 return False;
1083 if (!prs_align(ps))
1084 return False;
1085 if (!smb_io_unistr2("valuename", &q_u->valuename,True,ps,depth))
1086 return False;
1087 if (!prs_align(ps))
1088 return False;
1089 if (!prs_uint32("size", ps, depth, &q_u->size))
1090 return False;
1092 return True;
1095 /*******************************************************************
1096 * read a structure.
1097 * called from spoolss_q_deleteprinterdata (srv_spoolss.c)
1098 ********************************************************************/
1100 BOOL spoolss_io_q_deleteprinterdata(char *desc, SPOOL_Q_DELETEPRINTERDATA *q_u, prs_struct *ps, int depth)
1102 if (q_u == NULL)
1103 return False;
1105 prs_debug(ps, depth, desc, "spoolss_io_q_deleteprinterdata");
1106 depth++;
1108 if (!prs_align(ps))
1109 return False;
1110 if (!smb_io_pol_hnd("printer handle",&q_u->handle,ps,depth))
1111 return False;
1112 if (!prs_align(ps))
1113 return False;
1114 if (!smb_io_unistr2("valuename", &q_u->valuename,True,ps,depth))
1115 return False;
1117 return True;
1120 /*******************************************************************
1121 * write a structure.
1122 * called from spoolss_r_deleteprinterdata (srv_spoolss.c)
1123 ********************************************************************/
1125 BOOL spoolss_io_r_deleteprinterdata(char *desc, SPOOL_R_DELETEPRINTERDATA *r_u, prs_struct *ps, int depth)
1127 prs_debug(ps, depth, desc, "spoolss_io_r_deleteprinterdata");
1128 depth++;
1129 if(!prs_werror("status", ps, depth, &r_u->status))
1130 return False;
1132 return True;
1135 /*******************************************************************
1136 * write a structure.
1137 * called from spoolss_r_getprinterdata (srv_spoolss.c)
1138 ********************************************************************/
1140 BOOL spoolss_io_r_getprinterdata(char *desc, SPOOL_R_GETPRINTERDATA *r_u, prs_struct *ps, int depth)
1142 if (r_u == NULL)
1143 return False;
1145 prs_debug(ps, depth, desc, "spoolss_io_r_getprinterdata");
1146 depth++;
1148 if (!prs_align(ps))
1149 return False;
1150 if (!prs_uint32("type", ps, depth, &r_u->type))
1151 return False;
1152 if (!prs_uint32("size", ps, depth, &r_u->size))
1153 return False;
1155 if (!prs_uint8s(False,"data", ps, depth, r_u->data, r_u->size))
1156 return False;
1158 if (!prs_align(ps))
1159 return False;
1161 if (!prs_uint32("needed", ps, depth, &r_u->needed))
1162 return False;
1163 if (!prs_werror("status", ps, depth, &r_u->status))
1164 return False;
1166 return True;
1169 /*******************************************************************
1170 * make a structure.
1171 ********************************************************************/
1173 BOOL make_spoolss_q_closeprinter(SPOOL_Q_CLOSEPRINTER *q_u, POLICY_HND *hnd)
1175 if (q_u == NULL) return False;
1177 DEBUG(5,("make_spoolss_q_closeprinter\n"));
1179 memcpy(&q_u->handle, hnd, sizeof(q_u->handle));
1181 return True;
1184 /*******************************************************************
1185 * read a structure.
1186 * called from static spoolss_q_abortprinter (srv_spoolss.c)
1187 * called from spoolss_abortprinter (cli_spoolss.c)
1188 ********************************************************************/
1190 BOOL spoolss_io_q_abortprinter(char *desc, SPOOL_Q_ABORTPRINTER *q_u, prs_struct *ps, int depth)
1192 if (q_u == NULL) return False;
1194 prs_debug(ps, depth, desc, "spoolss_io_q_abortprinter");
1195 depth++;
1197 if (!prs_align(ps))
1198 return False;
1200 if (!smb_io_pol_hnd("printer handle",&q_u->handle,ps,depth))
1201 return False;
1203 return True;
1206 /*******************************************************************
1207 * write a structure.
1208 * called from spoolss_r_abortprinter (srv_spoolss.c)
1209 ********************************************************************/
1211 BOOL spoolss_io_r_abortprinter(char *desc, SPOOL_R_ABORTPRINTER *r_u, prs_struct *ps, int depth)
1213 prs_debug(ps, depth, desc, "spoolss_io_r_abortprinter");
1214 depth++;
1215 if(!prs_werror("status", ps, depth, &r_u->status))
1216 return False;
1218 return True;
1221 /*******************************************************************
1222 * read a structure.
1223 * called from static spoolss_q_deleteprinter (srv_spoolss.c)
1224 * called from spoolss_deleteprinter (cli_spoolss.c)
1225 ********************************************************************/
1227 BOOL spoolss_io_q_deleteprinter(char *desc, SPOOL_Q_DELETEPRINTER *q_u, prs_struct *ps, int depth)
1229 if (q_u == NULL) return False;
1231 prs_debug(ps, depth, desc, "spoolss_io_q_deleteprinter");
1232 depth++;
1234 if (!prs_align(ps))
1235 return False;
1237 if (!smb_io_pol_hnd("printer handle",&q_u->handle,ps,depth))
1238 return False;
1240 return True;
1243 /*******************************************************************
1244 * write a structure.
1245 * called from static spoolss_r_deleteprinter (srv_spoolss.c)
1246 * called from spoolss_deleteprinter (cli_spoolss.c)
1247 ********************************************************************/
1249 BOOL spoolss_io_r_deleteprinter(char *desc, SPOOL_R_DELETEPRINTER *r_u, prs_struct *ps, int depth)
1251 prs_debug(ps, depth, desc, "spoolss_io_r_deleteprinter");
1252 depth++;
1254 if (!prs_align(ps))
1255 return False;
1257 if (!smb_io_pol_hnd("printer handle",&r_u->handle,ps,depth))
1258 return False;
1259 if (!prs_werror("status", ps, depth, &r_u->status))
1260 return False;
1262 return True;
1266 /*******************************************************************
1267 * read a structure.
1268 * called from api_spoolss_deleteprinterdriver (srv_spoolss.c)
1269 * called from spoolss_deleteprinterdriver (cli_spoolss.c)
1270 ********************************************************************/
1272 BOOL spoolss_io_q_deleteprinterdriver(char *desc, SPOOL_Q_DELETEPRINTERDRIVER *q_u, prs_struct *ps, int depth)
1274 if (q_u == NULL) return False;
1276 prs_debug(ps, depth, desc, "spoolss_io_q_deleteprinterdriver");
1277 depth++;
1279 if (!prs_align(ps))
1280 return False;
1282 if(!prs_uint32("server_ptr", ps, depth, &q_u->server_ptr))
1283 return False;
1284 if(!smb_io_unistr2("server", &q_u->server, q_u->server_ptr, ps, depth))
1285 return False;
1286 if(!smb_io_unistr2("arch", &q_u->arch, True, ps, depth))
1287 return False;
1288 if(!smb_io_unistr2("driver", &q_u->driver, True, ps, depth))
1289 return False;
1292 return True;
1296 /*******************************************************************
1297 * write a structure.
1298 ********************************************************************/
1299 BOOL spoolss_io_r_deleteprinterdriver(char *desc, SPOOL_R_DELETEPRINTERDRIVER *r_u, prs_struct *ps, int depth)
1301 if (r_u == NULL) return False;
1303 prs_debug(ps, depth, desc, "spoolss_io_r_deleteprinterdriver");
1304 depth++;
1306 if (!prs_align(ps))
1307 return False;
1309 if (!prs_werror("status", ps, depth, &r_u->status))
1310 return False;
1312 return True;
1317 /*******************************************************************
1318 * read a structure.
1319 * called from static spoolss_q_closeprinter (srv_spoolss.c)
1320 * called from spoolss_closeprinter (cli_spoolss.c)
1321 ********************************************************************/
1323 BOOL spoolss_io_q_closeprinter(char *desc, SPOOL_Q_CLOSEPRINTER *q_u, prs_struct *ps, int depth)
1325 if (q_u == NULL) return False;
1327 prs_debug(ps, depth, desc, "spoolss_io_q_closeprinter");
1328 depth++;
1330 if (!prs_align(ps))
1331 return False;
1333 if (!smb_io_pol_hnd("printer handle",&q_u->handle,ps,depth))
1334 return False;
1336 return True;
1339 /*******************************************************************
1340 * write a structure.
1341 * called from static spoolss_r_closeprinter (srv_spoolss.c)
1342 * called from spoolss_closeprinter (cli_spoolss.c)
1343 ********************************************************************/
1345 BOOL spoolss_io_r_closeprinter(char *desc, SPOOL_R_CLOSEPRINTER *r_u, prs_struct *ps, int depth)
1347 prs_debug(ps, depth, desc, "spoolss_io_r_closeprinter");
1348 depth++;
1350 if (!prs_align(ps))
1351 return False;
1353 if (!smb_io_pol_hnd("printer handle",&r_u->handle,ps,depth))
1354 return False;
1355 if (!prs_werror("status", ps, depth, &r_u->status))
1356 return False;
1358 return True;
1361 /*******************************************************************
1362 * read a structure.
1363 * called from spoolss_q_startdocprinter (srv_spoolss.c)
1364 ********************************************************************/
1366 BOOL spoolss_io_q_startdocprinter(char *desc, SPOOL_Q_STARTDOCPRINTER *q_u, prs_struct *ps, int depth)
1368 if (q_u == NULL) return False;
1370 prs_debug(ps, depth, desc, "spoolss_io_q_startdocprinter");
1371 depth++;
1373 if(!prs_align(ps))
1374 return False;
1376 if(!smb_io_pol_hnd("printer handle",&q_u->handle,ps,depth))
1377 return False;
1379 if(!smb_io_doc_info_container("",&q_u->doc_info_container, ps, depth))
1380 return False;
1382 return True;
1385 /*******************************************************************
1386 * write a structure.
1387 * called from spoolss_r_startdocprinter (srv_spoolss.c)
1388 ********************************************************************/
1390 BOOL spoolss_io_r_startdocprinter(char *desc, SPOOL_R_STARTDOCPRINTER *r_u, prs_struct *ps, int depth)
1392 prs_debug(ps, depth, desc, "spoolss_io_r_startdocprinter");
1393 depth++;
1394 if(!prs_uint32("jobid", ps, depth, &r_u->jobid))
1395 return False;
1396 if(!prs_werror("status", ps, depth, &r_u->status))
1397 return False;
1399 return True;
1402 /*******************************************************************
1403 * read a structure.
1404 * called from spoolss_q_enddocprinter (srv_spoolss.c)
1405 ********************************************************************/
1407 BOOL spoolss_io_q_enddocprinter(char *desc, SPOOL_Q_ENDDOCPRINTER *q_u, prs_struct *ps, int depth)
1409 if (q_u == NULL) return False;
1411 prs_debug(ps, depth, desc, "spoolss_io_q_enddocprinter");
1412 depth++;
1414 if(!prs_align(ps))
1415 return False;
1417 if(!smb_io_pol_hnd("printer handle",&q_u->handle,ps,depth))
1418 return False;
1420 return True;
1423 /*******************************************************************
1424 * write a structure.
1425 * called from spoolss_r_enddocprinter (srv_spoolss.c)
1426 ********************************************************************/
1428 BOOL spoolss_io_r_enddocprinter(char *desc, SPOOL_R_ENDDOCPRINTER *r_u, prs_struct *ps, int depth)
1430 prs_debug(ps, depth, desc, "spoolss_io_r_enddocprinter");
1431 depth++;
1432 if(!prs_werror("status", ps, depth, &r_u->status))
1433 return False;
1435 return True;
1438 /*******************************************************************
1439 * read a structure.
1440 * called from spoolss_q_startpageprinter (srv_spoolss.c)
1441 ********************************************************************/
1443 BOOL spoolss_io_q_startpageprinter(char *desc, SPOOL_Q_STARTPAGEPRINTER *q_u, prs_struct *ps, int depth)
1445 if (q_u == NULL) return False;
1447 prs_debug(ps, depth, desc, "spoolss_io_q_startpageprinter");
1448 depth++;
1450 if(!prs_align(ps))
1451 return False;
1453 if(!smb_io_pol_hnd("printer handle",&q_u->handle,ps,depth))
1454 return False;
1456 return True;
1459 /*******************************************************************
1460 * write a structure.
1461 * called from spoolss_r_startpageprinter (srv_spoolss.c)
1462 ********************************************************************/
1464 BOOL spoolss_io_r_startpageprinter(char *desc, SPOOL_R_STARTPAGEPRINTER *r_u, prs_struct *ps, int depth)
1466 prs_debug(ps, depth, desc, "spoolss_io_r_startpageprinter");
1467 depth++;
1468 if(!prs_werror("status", ps, depth, &r_u->status))
1469 return False;
1471 return True;
1474 /*******************************************************************
1475 * read a structure.
1476 * called from spoolss_q_endpageprinter (srv_spoolss.c)
1477 ********************************************************************/
1479 BOOL spoolss_io_q_endpageprinter(char *desc, SPOOL_Q_ENDPAGEPRINTER *q_u, prs_struct *ps, int depth)
1481 if (q_u == NULL) return False;
1483 prs_debug(ps, depth, desc, "spoolss_io_q_endpageprinter");
1484 depth++;
1486 if(!prs_align(ps))
1487 return False;
1489 if(!smb_io_pol_hnd("printer handle",&q_u->handle,ps,depth))
1490 return False;
1492 return True;
1495 /*******************************************************************
1496 * write a structure.
1497 * called from spoolss_r_endpageprinter (srv_spoolss.c)
1498 ********************************************************************/
1500 BOOL spoolss_io_r_endpageprinter(char *desc, SPOOL_R_ENDPAGEPRINTER *r_u, prs_struct *ps, int depth)
1502 prs_debug(ps, depth, desc, "spoolss_io_r_endpageprinter");
1503 depth++;
1504 if(!prs_werror("status", ps, depth, &r_u->status))
1505 return False;
1507 return True;
1510 /*******************************************************************
1511 * read a structure.
1512 * called from spoolss_q_writeprinter (srv_spoolss.c)
1513 ********************************************************************/
1515 BOOL spoolss_io_q_writeprinter(char *desc, SPOOL_Q_WRITEPRINTER *q_u, prs_struct *ps, int depth)
1517 if (q_u == NULL) return False;
1519 prs_debug(ps, depth, desc, "spoolss_io_q_writeprinter");
1520 depth++;
1522 if(!prs_align(ps))
1523 return False;
1525 if(!smb_io_pol_hnd("printer handle",&q_u->handle,ps,depth))
1526 return False;
1527 if(!prs_uint32("buffer_size", ps, depth, &q_u->buffer_size))
1528 return False;
1530 if (q_u->buffer_size!=0)
1532 if (UNMARSHALLING(ps))
1533 q_u->buffer=(uint8 *)prs_alloc_mem(ps,q_u->buffer_size*sizeof(uint8));
1534 if(q_u->buffer == NULL)
1535 return False;
1536 if(!prs_uint8s(True, "buffer", ps, depth, q_u->buffer, q_u->buffer_size))
1537 return False;
1539 if(!prs_align(ps))
1540 return False;
1541 if(!prs_uint32("buffer_size2", ps, depth, &q_u->buffer_size2))
1542 return False;
1544 return True;
1547 /*******************************************************************
1548 * write a structure.
1549 * called from spoolss_r_writeprinter (srv_spoolss.c)
1550 ********************************************************************/
1552 BOOL spoolss_io_r_writeprinter(char *desc, SPOOL_R_WRITEPRINTER *r_u, prs_struct *ps, int depth)
1554 prs_debug(ps, depth, desc, "spoolss_io_r_writeprinter");
1555 depth++;
1556 if(!prs_uint32("buffer_written", ps, depth, &r_u->buffer_written))
1557 return False;
1558 if(!prs_werror("status", ps, depth, &r_u->status))
1559 return False;
1561 return True;
1564 /*******************************************************************
1565 * read a structure.
1566 * called from spoolss_q_rffpcnex (srv_spoolss.c)
1567 ********************************************************************/
1569 BOOL spoolss_io_q_rffpcnex(char *desc, SPOOL_Q_RFFPCNEX *q_u, prs_struct *ps, int depth)
1571 prs_debug(ps, depth, desc, "spoolss_io_q_rffpcnex");
1572 depth++;
1574 if(!prs_align(ps))
1575 return False;
1577 if(!smb_io_pol_hnd("printer handle", &q_u->handle, ps, depth))
1578 return False;
1579 if(!prs_uint32("flags", ps, depth, &q_u->flags))
1580 return False;
1581 if(!prs_uint32("options", ps, depth, &q_u->options))
1582 return False;
1583 if(!prs_uint32("localmachine_ptr", ps, depth, &q_u->localmachine_ptr))
1584 return False;
1585 if(!smb_io_unistr2("localmachine", &q_u->localmachine, q_u->localmachine_ptr, ps, depth))
1586 return False;
1588 if(!prs_align(ps))
1589 return False;
1591 if(!prs_uint32("printerlocal", ps, depth, &q_u->printerlocal))
1592 return False;
1594 if(!prs_uint32("option_ptr", ps, depth, &q_u->option_ptr))
1595 return False;
1597 if (q_u->option_ptr!=0) {
1599 if (UNMARSHALLING(ps))
1600 if((q_u->option=(SPOOL_NOTIFY_OPTION *)prs_alloc_mem(ps,sizeof(SPOOL_NOTIFY_OPTION))) == NULL)
1601 return False;
1603 if(!smb_io_notify_option("notify option", q_u->option, ps, depth))
1604 return False;
1607 return True;
1610 /*******************************************************************
1611 * write a structure.
1612 * called from spoolss_r_rffpcnex (srv_spoolss.c)
1613 ********************************************************************/
1615 BOOL spoolss_io_r_rffpcnex(char *desc, SPOOL_R_RFFPCNEX *r_u, prs_struct *ps, int depth)
1617 prs_debug(ps, depth, desc, "spoolss_io_r_rffpcnex");
1618 depth++;
1620 if(!prs_werror("status", ps, depth, &r_u->status))
1621 return False;
1623 return True;
1626 /*******************************************************************
1627 * read a structure.
1628 * called from spoolss_q_rfnpcnex (srv_spoolss.c)
1629 ********************************************************************/
1631 BOOL spoolss_io_q_rfnpcnex(char *desc, SPOOL_Q_RFNPCNEX *q_u, prs_struct *ps, int depth)
1633 prs_debug(ps, depth, desc, "spoolss_io_q_rfnpcnex");
1634 depth++;
1636 if(!prs_align(ps))
1637 return False;
1639 if(!smb_io_pol_hnd("printer handle",&q_u->handle,ps,depth))
1640 return False;
1642 if(!prs_uint32("change", ps, depth, &q_u->change))
1643 return False;
1645 if(!prs_uint32("option_ptr", ps, depth, &q_u->option_ptr))
1646 return False;
1648 if (q_u->option_ptr!=0) {
1650 if (UNMARSHALLING(ps))
1651 if((q_u->option=(SPOOL_NOTIFY_OPTION *)prs_alloc_mem(ps,sizeof(SPOOL_NOTIFY_OPTION))) == NULL)
1652 return False;
1654 if(!smb_io_notify_option("notify option", q_u->option, ps, depth))
1655 return False;
1658 return True;
1661 /*******************************************************************
1662 * write a structure.
1663 * called from spoolss_r_rfnpcnex (srv_spoolss.c)
1664 ********************************************************************/
1666 BOOL spoolss_io_r_rfnpcnex(char *desc, SPOOL_R_RFNPCNEX *r_u, prs_struct *ps, int depth)
1668 prs_debug(ps, depth, desc, "spoolss_io_r_rfnpcnex");
1669 depth++;
1671 if(!prs_align(ps))
1672 return False;
1674 if (!prs_uint32("info_ptr", ps, depth, &r_u->info_ptr))
1675 return False;
1677 if(!smb_io_notify_info("notify info", &r_u->info ,ps,depth))
1678 return False;
1680 if(!prs_align(ps))
1681 return False;
1682 if(!prs_werror("status", ps, depth, &r_u->status))
1683 return False;
1685 return True;
1688 /*******************************************************************
1689 * return the length of a uint16 (obvious, but the code is clean)
1690 ********************************************************************/
1692 static uint32 size_of_uint16(uint16 *value)
1694 return (sizeof(*value));
1697 /*******************************************************************
1698 * return the length of a uint32 (obvious, but the code is clean)
1699 ********************************************************************/
1701 static uint32 size_of_uint32(uint32 *value)
1703 return (sizeof(*value));
1706 /*******************************************************************
1707 * return the length of a NTTIME (obvious, but the code is clean)
1708 ********************************************************************/
1710 static uint32 size_of_nttime(NTTIME *value)
1712 return (sizeof(*value));
1715 /*******************************************************************
1716 * return the length of a UNICODE string in number of char, includes:
1717 * - the leading zero
1718 * - the relative pointer size
1719 ********************************************************************/
1721 static uint32 size_of_relative_string(UNISTR *string)
1723 uint32 size=0;
1725 size=str_len_uni(string); /* the string length */
1726 size=size+1; /* add the leading zero */
1727 size=size*2; /* convert in char */
1728 /* Ensure size is 4 byte multiple (prs_align is being called...). */
1729 size += ((4 - (size & 3)) & 3);
1730 size=size+4; /* add the size of the ptr */
1732 return size;
1735 /*******************************************************************
1736 * return the length of a uint32 (obvious, but the code is clean)
1737 ********************************************************************/
1739 static uint32 size_of_device_mode(DEVICEMODE *devmode)
1741 if (devmode==NULL)
1742 return (4);
1743 else
1744 return (4+devmode->size+devmode->driverextra);
1747 /*******************************************************************
1748 * return the length of a uint32 (obvious, but the code is clean)
1749 ********************************************************************/
1751 static uint32 size_of_systemtime(SYSTEMTIME *systime)
1753 if (systime==NULL)
1754 return (4);
1755 else
1756 return (sizeof(SYSTEMTIME) +4);
1759 /*******************************************************************
1760 * write a UNICODE string.
1761 * used by all the RPC structs passing a buffer
1762 ********************************************************************/
1764 static BOOL spoolss_smb_io_unistr(char *desc, UNISTR *uni, prs_struct *ps, int depth)
1766 if (uni == NULL)
1767 return False;
1769 prs_debug(ps, depth, desc, "spoolss_smb_io_unistr");
1770 depth++;
1772 /* there should be no align here as it can mess up
1773 parsing a NEW_BUFFER->prs */
1774 #if 0 /* JERRY */
1775 if (!prs_align(ps))
1776 return False;
1777 #endif
1779 if (!prs_unistr("unistr", ps, depth, uni))
1780 return False;
1782 return True;
1785 /*******************************************************************
1786 * write a UNICODE string and its relative pointer.
1787 * used by all the RPC structs passing a buffer
1789 * As I'm a nice guy, I'm forcing myself to explain this code.
1790 * MS did a good job in the overall spoolss code except in some
1791 * functions where they are passing the API buffer directly in the
1792 * RPC request/reply. That's to maintain compatiility at the API level.
1793 * They could have done it the good way the first time.
1795 * So what happen is: the strings are written at the buffer's end,
1796 * in the reverse order of the original structure. Some pointers to
1797 * the strings are also in the buffer. Those are relative to the
1798 * buffer's start.
1800 * If you don't understand or want to change that function,
1801 * first get in touch with me: jfm@samba.org
1803 ********************************************************************/
1805 static BOOL smb_io_relstr(char *desc, NEW_BUFFER *buffer, int depth, UNISTR *string)
1807 prs_struct *ps=&buffer->prs;
1809 if (MARSHALLING(ps)) {
1810 uint32 struct_offset = prs_offset(ps);
1811 uint32 relative_offset;
1813 buffer->string_at_end -= (size_of_relative_string(string) - 4);
1814 if(!prs_set_offset(ps, buffer->string_at_end))
1815 return False;
1816 if (!prs_align(ps))
1817 return False;
1818 buffer->string_at_end = prs_offset(ps);
1820 /* write the string */
1821 if (!smb_io_unistr(desc, string, ps, depth))
1822 return False;
1824 if(!prs_set_offset(ps, struct_offset))
1825 return False;
1827 relative_offset=buffer->string_at_end - buffer->struct_start;
1828 /* write its offset */
1829 if (!prs_uint32("offset", ps, depth, &relative_offset))
1830 return False;
1832 else {
1833 uint32 old_offset;
1835 /* read the offset */
1836 if (!prs_uint32("offset", ps, depth, &(buffer->string_at_end)))
1837 return False;
1839 old_offset = prs_offset(ps);
1840 if(!prs_set_offset(ps, buffer->string_at_end+buffer->struct_start))
1841 return False;
1843 /* read the string */
1844 if (!spoolss_smb_io_unistr(desc, string, ps, depth))
1845 return False;
1847 if(!prs_set_offset(ps, old_offset))
1848 return False;
1850 return True;
1853 /*******************************************************************
1854 * write a array of UNICODE strings and its relative pointer.
1855 * used by 2 RPC structs
1856 ********************************************************************/
1858 static BOOL smb_io_relarraystr(char *desc, NEW_BUFFER *buffer, int depth, uint16 **string)
1860 UNISTR chaine;
1862 prs_struct *ps=&buffer->prs;
1864 if (MARSHALLING(ps)) {
1865 uint32 struct_offset = prs_offset(ps);
1866 uint32 relative_offset;
1867 uint16 *p;
1868 uint16 *q;
1869 uint16 zero=0;
1870 p=*string;
1871 q=*string;
1873 /* first write the last 0 */
1874 buffer->string_at_end -= 2;
1875 if(!prs_set_offset(ps, buffer->string_at_end))
1876 return False;
1878 if(!prs_uint16("leading zero", ps, depth, &zero))
1879 return False;
1881 while (p && (*p!=0)) {
1882 while (*q!=0)
1883 q++;
1885 /* Yes this should be malloc not talloc. Don't change. */
1887 chaine.buffer = malloc((q-p+1)*sizeof(uint16));
1888 if (chaine.buffer == NULL)
1889 return False;
1891 memcpy(chaine.buffer, p, (q-p+1)*sizeof(uint16));
1893 buffer->string_at_end -= (q-p+1)*sizeof(uint16);
1895 if(!prs_set_offset(ps, buffer->string_at_end)) {
1896 SAFE_FREE(chaine.buffer);
1897 return False;
1900 /* write the string */
1901 if (!spoolss_smb_io_unistr(desc, &chaine, ps, depth)) {
1902 SAFE_FREE(chaine.buffer);
1903 return False;
1905 q++;
1906 p=q;
1908 SAFE_FREE(chaine.buffer);
1911 if(!prs_set_offset(ps, struct_offset))
1912 return False;
1914 relative_offset=buffer->string_at_end - buffer->struct_start;
1915 /* write its offset */
1916 if (!prs_uint32("offset", ps, depth, &relative_offset))
1917 return False;
1919 } else {
1921 /* UNMARSHALLING */
1923 uint32 old_offset;
1924 uint16 *chaine2=NULL;
1925 int l_chaine=0;
1926 int l_chaine2=0;
1927 size_t realloc_size = 0;
1929 *string=NULL;
1931 /* read the offset */
1932 if (!prs_uint32("offset", ps, depth, &buffer->string_at_end))
1933 return False;
1935 old_offset = prs_offset(ps);
1936 if(!prs_set_offset(ps, buffer->string_at_end + buffer->struct_start))
1937 return False;
1939 do {
1940 if (!spoolss_smb_io_unistr(desc, &chaine, ps, depth))
1941 return False;
1943 l_chaine=str_len_uni(&chaine);
1945 /* we're going to add two more bytes here in case this
1946 is the last string in the array and we need to add
1947 an extra NULL for termination */
1948 if (l_chaine > 0)
1950 uint16 *tc2;
1952 realloc_size = (l_chaine2+l_chaine+2)*sizeof(uint16);
1954 /* Yes this should be realloc - it's freed below. JRA */
1956 if((tc2=(uint16 *)Realloc(chaine2, realloc_size)) == NULL) {
1957 SAFE_FREE(chaine2);
1958 return False;
1960 else chaine2 = tc2;
1961 memcpy(chaine2+l_chaine2, chaine.buffer, (l_chaine+1)*sizeof(uint16));
1962 l_chaine2+=l_chaine+1;
1965 } while(l_chaine!=0);
1967 /* the end should be bould NULL terminated so add
1968 the second one here */
1969 if (chaine2)
1971 chaine2[l_chaine2] = '\0';
1972 *string=(uint16 *)talloc_memdup(prs_get_mem_context(ps),chaine2,realloc_size);
1973 SAFE_FREE(chaine2);
1976 if(!prs_set_offset(ps, old_offset))
1977 return False;
1979 return True;
1982 /*******************************************************************
1983 Parse a DEVMODE structure and its relative pointer.
1984 ********************************************************************/
1986 static BOOL smb_io_relsecdesc(char *desc, NEW_BUFFER *buffer, int depth, SEC_DESC **secdesc)
1988 prs_struct *ps= &buffer->prs;
1990 prs_debug(ps, depth, desc, "smb_io_relsecdesc");
1991 depth++;
1993 if (MARSHALLING(ps)) {
1994 uint32 struct_offset = prs_offset(ps);
1995 uint32 relative_offset;
1997 if (! *secdesc) {
1998 relative_offset = 0;
1999 if (!prs_uint32("offset", ps, depth, &relative_offset))
2000 return False;
2001 return True;
2004 if (*secdesc != NULL) {
2005 buffer->string_at_end -= sec_desc_size(*secdesc);
2007 if(!prs_set_offset(ps, buffer->string_at_end))
2008 return False;
2009 /* write the secdesc */
2010 if (!sec_io_desc(desc, secdesc, ps, depth))
2011 return False;
2013 if(!prs_set_offset(ps, struct_offset))
2014 return False;
2017 relative_offset=buffer->string_at_end - buffer->struct_start;
2018 /* write its offset */
2020 if (!prs_uint32("offset", ps, depth, &relative_offset))
2021 return False;
2022 } else {
2023 uint32 old_offset;
2025 /* read the offset */
2026 if (!prs_uint32("offset", ps, depth, &buffer->string_at_end))
2027 return False;
2029 old_offset = prs_offset(ps);
2030 if(!prs_set_offset(ps, buffer->string_at_end + buffer->struct_start))
2031 return False;
2033 /* read the sd */
2034 if (!sec_io_desc(desc, secdesc, ps, depth))
2035 return False;
2037 if(!prs_set_offset(ps, old_offset))
2038 return False;
2040 return True;
2043 /*******************************************************************
2044 Parse a DEVMODE structure and its relative pointer.
2045 ********************************************************************/
2047 static BOOL smb_io_reldevmode(char *desc, NEW_BUFFER *buffer, int depth, DEVICEMODE **devmode)
2049 prs_struct *ps=&buffer->prs;
2051 prs_debug(ps, depth, desc, "smb_io_reldevmode");
2052 depth++;
2054 if (MARSHALLING(ps)) {
2055 uint32 struct_offset = prs_offset(ps);
2056 uint32 relative_offset;
2058 if (*devmode == NULL) {
2059 relative_offset=0;
2060 if (!prs_uint32("offset", ps, depth, &relative_offset))
2061 return False;
2062 DEBUG(8, ("boing, the devmode was NULL\n"));
2064 return True;
2067 buffer->string_at_end -= ((*devmode)->size + (*devmode)->driverextra);
2069 if(!prs_set_offset(ps, buffer->string_at_end))
2070 return False;
2072 /* write the DEVMODE */
2073 if (!spoolss_io_devmode(desc, ps, depth, *devmode))
2074 return False;
2076 if(!prs_set_offset(ps, struct_offset))
2077 return False;
2079 relative_offset=buffer->string_at_end - buffer->struct_start;
2080 /* write its offset */
2081 if (!prs_uint32("offset", ps, depth, &relative_offset))
2082 return False;
2084 else {
2085 uint32 old_offset;
2087 /* read the offset */
2088 if (!prs_uint32("offset", ps, depth, &buffer->string_at_end))
2089 return False;
2091 old_offset = prs_offset(ps);
2092 if(!prs_set_offset(ps, buffer->string_at_end + buffer->struct_start))
2093 return False;
2095 /* read the string */
2096 if((*devmode=(DEVICEMODE *)prs_alloc_mem(ps,sizeof(DEVICEMODE))) == NULL)
2097 return False;
2098 if (!spoolss_io_devmode(desc, ps, depth, *devmode))
2099 return False;
2101 if(!prs_set_offset(ps, old_offset))
2102 return False;
2104 return True;
2107 /*******************************************************************
2108 Parse a PRINTER_INFO_0 structure.
2109 ********************************************************************/
2111 BOOL smb_io_printer_info_0(char *desc, NEW_BUFFER *buffer, PRINTER_INFO_0 *info, int depth)
2113 prs_struct *ps=&buffer->prs;
2115 prs_debug(ps, depth, desc, "smb_io_printer_info_0");
2116 depth++;
2118 buffer->struct_start=prs_offset(ps);
2120 if (!smb_io_relstr("printername", buffer, depth, &info->printername))
2121 return False;
2122 if (!smb_io_relstr("servername", buffer, depth, &info->servername))
2123 return False;
2125 if(!prs_uint32("cjobs", ps, depth, &info->cjobs))
2126 return False;
2127 if(!prs_uint32("total_jobs", ps, depth, &info->total_jobs))
2128 return False;
2129 if(!prs_uint32("total_bytes", ps, depth, &info->total_bytes))
2130 return False;
2132 if(!prs_uint16("year", ps, depth, &info->year))
2133 return False;
2134 if(!prs_uint16("month", ps, depth, &info->month))
2135 return False;
2136 if(!prs_uint16("dayofweek", ps, depth, &info->dayofweek))
2137 return False;
2138 if(!prs_uint16("day", ps, depth, &info->day))
2139 return False;
2140 if(!prs_uint16("hour", ps, depth, &info->hour))
2141 return False;
2142 if(!prs_uint16("minute", ps, depth, &info->minute))
2143 return False;
2144 if(!prs_uint16("second", ps, depth, &info->second))
2145 return False;
2146 if(!prs_uint16("milliseconds", ps, depth, &info->milliseconds))
2147 return False;
2149 if(!prs_uint32("global_counter", ps, depth, &info->global_counter))
2150 return False;
2151 if(!prs_uint32("total_pages", ps, depth, &info->total_pages))
2152 return False;
2154 if(!prs_uint16("major_version", ps, depth, &info->major_version))
2155 return False;
2156 if(!prs_uint16("build_version", ps, depth, &info->build_version))
2157 return False;
2158 if(!prs_uint32("unknown7", ps, depth, &info->unknown7))
2159 return False;
2160 if(!prs_uint32("unknown8", ps, depth, &info->unknown8))
2161 return False;
2162 if(!prs_uint32("unknown9", ps, depth, &info->unknown9))
2163 return False;
2164 if(!prs_uint32("session_counter", ps, depth, &info->session_counter))
2165 return False;
2166 if(!prs_uint32("unknown11", ps, depth, &info->unknown11))
2167 return False;
2168 if(!prs_uint32("printer_errors", ps, depth, &info->printer_errors))
2169 return False;
2170 if(!prs_uint32("unknown13", ps, depth, &info->unknown13))
2171 return False;
2172 if(!prs_uint32("unknown14", ps, depth, &info->unknown14))
2173 return False;
2174 if(!prs_uint32("unknown15", ps, depth, &info->unknown15))
2175 return False;
2176 if(!prs_uint32("unknown16", ps, depth, &info->unknown16))
2177 return False;
2178 if(!prs_uint32("change_id", ps, depth, &info->change_id))
2179 return False;
2180 if(!prs_uint32("unknown18", ps, depth, &info->unknown18))
2181 return False;
2182 if(!prs_uint32("status" , ps, depth, &info->status))
2183 return False;
2184 if(!prs_uint32("unknown20", ps, depth, &info->unknown20))
2185 return False;
2186 if(!prs_uint32("c_setprinter", ps, depth, &info->c_setprinter))
2187 return False;
2188 if(!prs_uint16("unknown22", ps, depth, &info->unknown22))
2189 return False;
2190 if(!prs_uint16("unknown23", ps, depth, &info->unknown23))
2191 return False;
2192 if(!prs_uint16("unknown24", ps, depth, &info->unknown24))
2193 return False;
2194 if(!prs_uint16("unknown25", ps, depth, &info->unknown25))
2195 return False;
2196 if(!prs_uint16("unknown26", ps, depth, &info->unknown26))
2197 return False;
2198 if(!prs_uint16("unknown27", ps, depth, &info->unknown27))
2199 return False;
2200 if(!prs_uint16("unknown28", ps, depth, &info->unknown28))
2201 return False;
2202 if(!prs_uint16("unknown29", ps, depth, &info->unknown29))
2203 return False;
2205 return True;
2208 /*******************************************************************
2209 Parse a PRINTER_INFO_1 structure.
2210 ********************************************************************/
2212 BOOL smb_io_printer_info_1(char *desc, NEW_BUFFER *buffer, PRINTER_INFO_1 *info, int depth)
2214 prs_struct *ps=&buffer->prs;
2216 prs_debug(ps, depth, desc, "smb_io_printer_info_1");
2217 depth++;
2219 buffer->struct_start=prs_offset(ps);
2221 if (!prs_uint32("flags", ps, depth, &info->flags))
2222 return False;
2223 if (!smb_io_relstr("description", buffer, depth, &info->description))
2224 return False;
2225 if (!smb_io_relstr("name", buffer, depth, &info->name))
2226 return False;
2227 if (!smb_io_relstr("comment", buffer, depth, &info->comment))
2228 return False;
2230 return True;
2233 /*******************************************************************
2234 Parse a PRINTER_INFO_2 structure.
2235 ********************************************************************/
2237 BOOL smb_io_printer_info_2(char *desc, NEW_BUFFER *buffer, PRINTER_INFO_2 *info, int depth)
2239 prs_struct *ps=&buffer->prs;
2241 prs_debug(ps, depth, desc, "smb_io_printer_info_2");
2242 depth++;
2244 buffer->struct_start=prs_offset(ps);
2246 if (!smb_io_relstr("servername", buffer, depth, &info->servername))
2247 return False;
2248 if (!smb_io_relstr("printername", buffer, depth, &info->printername))
2249 return False;
2250 if (!smb_io_relstr("sharename", buffer, depth, &info->sharename))
2251 return False;
2252 if (!smb_io_relstr("portname", buffer, depth, &info->portname))
2253 return False;
2254 if (!smb_io_relstr("drivername", buffer, depth, &info->drivername))
2255 return False;
2256 if (!smb_io_relstr("comment", buffer, depth, &info->comment))
2257 return False;
2258 if (!smb_io_relstr("location", buffer, depth, &info->location))
2259 return False;
2261 /* NT parses the DEVMODE at the end of the struct */
2262 if (!smb_io_reldevmode("devmode", buffer, depth, &info->devmode))
2263 return False;
2265 if (!smb_io_relstr("sepfile", buffer, depth, &info->sepfile))
2266 return False;
2267 if (!smb_io_relstr("printprocessor", buffer, depth, &info->printprocessor))
2268 return False;
2269 if (!smb_io_relstr("datatype", buffer, depth, &info->datatype))
2270 return False;
2271 if (!smb_io_relstr("parameters", buffer, depth, &info->parameters))
2272 return False;
2274 if (!smb_io_relsecdesc("secdesc", buffer, depth, &info->secdesc))
2275 return False;
2277 if (!prs_uint32("attributes", ps, depth, &info->attributes))
2278 return False;
2279 if (!prs_uint32("priority", ps, depth, &info->priority))
2280 return False;
2281 if (!prs_uint32("defpriority", ps, depth, &info->defaultpriority))
2282 return False;
2283 if (!prs_uint32("starttime", ps, depth, &info->starttime))
2284 return False;
2285 if (!prs_uint32("untiltime", ps, depth, &info->untiltime))
2286 return False;
2287 if (!prs_uint32("status", ps, depth, &info->status))
2288 return False;
2289 if (!prs_uint32("jobs", ps, depth, &info->cjobs))
2290 return False;
2291 if (!prs_uint32("averageppm", ps, depth, &info->averageppm))
2292 return False;
2294 #if 0 /* JFMTEST */
2295 if (!prs_uint32_post("secdesc_ptr", ps, depth, NULL, sec_offset, info->secdesc ? prs_offset(ps)-buffer->struct_start : 0 ))
2296 return False;
2298 if (!sec_io_desc("secdesc", &info->secdesc, ps, depth))
2299 return False;
2300 #endif
2301 return True;
2304 /*******************************************************************
2305 Parse a PRINTER_INFO_3 structure.
2306 ********************************************************************/
2308 BOOL smb_io_printer_info_3(char *desc, NEW_BUFFER *buffer, PRINTER_INFO_3 *info, int depth)
2310 prs_struct *ps=&buffer->prs;
2312 prs_debug(ps, depth, desc, "smb_io_printer_info_3");
2313 depth++;
2315 buffer->struct_start=prs_offset(ps);
2317 if (!prs_uint32("flags", ps, depth, &info->flags))
2318 return False;
2319 if (!sec_io_desc("sec_desc", &info->secdesc, ps, depth))
2320 return False;
2322 return True;
2325 /*******************************************************************
2326 Parse a PRINTER_INFO_4 structure.
2327 ********************************************************************/
2329 BOOL smb_io_printer_info_4(char *desc, NEW_BUFFER *buffer, PRINTER_INFO_4 *info, int depth)
2331 prs_struct *ps=&buffer->prs;
2333 prs_debug(ps, depth, desc, "smb_io_printer_info_4");
2334 depth++;
2336 buffer->struct_start=prs_offset(ps);
2338 if (!smb_io_relstr("printername", buffer, depth, &info->printername))
2339 return False;
2340 if (!smb_io_relstr("servername", buffer, depth, &info->servername))
2341 return False;
2342 if (!prs_uint32("attributes", ps, depth, &info->attributes))
2343 return False;
2344 return True;
2347 /*******************************************************************
2348 Parse a PRINTER_INFO_5 structure.
2349 ********************************************************************/
2351 BOOL smb_io_printer_info_5(char *desc, NEW_BUFFER *buffer, PRINTER_INFO_5 *info, int depth)
2353 prs_struct *ps=&buffer->prs;
2355 prs_debug(ps, depth, desc, "smb_io_printer_info_5");
2356 depth++;
2358 buffer->struct_start=prs_offset(ps);
2360 if (!smb_io_relstr("printername", buffer, depth, &info->printername))
2361 return False;
2362 if (!smb_io_relstr("portname", buffer, depth, &info->portname))
2363 return False;
2364 if (!prs_uint32("attributes", ps, depth, &info->attributes))
2365 return False;
2366 if (!prs_uint32("device_not_selected_timeout", ps, depth, &info->device_not_selected_timeout))
2367 return False;
2368 if (!prs_uint32("transmission_retry_timeout", ps, depth, &info->transmission_retry_timeout))
2369 return False;
2370 return True;
2373 /*******************************************************************
2374 Parse a PORT_INFO_1 structure.
2375 ********************************************************************/
2377 BOOL smb_io_port_info_1(char *desc, NEW_BUFFER *buffer, PORT_INFO_1 *info, int depth)
2379 prs_struct *ps=&buffer->prs;
2381 prs_debug(ps, depth, desc, "smb_io_port_info_1");
2382 depth++;
2384 buffer->struct_start=prs_offset(ps);
2386 if (!smb_io_relstr("port_name", buffer, depth, &info->port_name))
2387 return False;
2389 return True;
2392 /*******************************************************************
2393 Parse a PORT_INFO_2 structure.
2394 ********************************************************************/
2396 BOOL smb_io_port_info_2(char *desc, NEW_BUFFER *buffer, PORT_INFO_2 *info, int depth)
2398 prs_struct *ps=&buffer->prs;
2400 prs_debug(ps, depth, desc, "smb_io_port_info_2");
2401 depth++;
2403 buffer->struct_start=prs_offset(ps);
2405 if (!smb_io_relstr("port_name", buffer, depth, &info->port_name))
2406 return False;
2407 if (!smb_io_relstr("monitor_name", buffer, depth, &info->monitor_name))
2408 return False;
2409 if (!smb_io_relstr("description", buffer, depth, &info->description))
2410 return False;
2411 if (!prs_uint32("port_type", ps, depth, &info->port_type))
2412 return False;
2413 if (!prs_uint32("reserved", ps, depth, &info->reserved))
2414 return False;
2416 return True;
2419 /*******************************************************************
2420 Parse a DRIVER_INFO_1 structure.
2421 ********************************************************************/
2423 BOOL smb_io_printer_driver_info_1(char *desc, NEW_BUFFER *buffer, DRIVER_INFO_1 *info, int depth)
2425 prs_struct *ps=&buffer->prs;
2427 prs_debug(ps, depth, desc, "smb_io_printer_driver_info_1");
2428 depth++;
2430 buffer->struct_start=prs_offset(ps);
2432 if (!smb_io_relstr("name", buffer, depth, &info->name))
2433 return False;
2435 return True;
2438 /*******************************************************************
2439 Parse a DRIVER_INFO_2 structure.
2440 ********************************************************************/
2442 BOOL smb_io_printer_driver_info_2(char *desc, NEW_BUFFER *buffer, DRIVER_INFO_2 *info, int depth)
2444 prs_struct *ps=&buffer->prs;
2446 prs_debug(ps, depth, desc, "smb_io_printer_driver_info_2");
2447 depth++;
2449 buffer->struct_start=prs_offset(ps);
2451 if (!prs_uint32("version", ps, depth, &info->version))
2452 return False;
2453 if (!smb_io_relstr("name", buffer, depth, &info->name))
2454 return False;
2455 if (!smb_io_relstr("architecture", buffer, depth, &info->architecture))
2456 return False;
2457 if (!smb_io_relstr("driverpath", buffer, depth, &info->driverpath))
2458 return False;
2459 if (!smb_io_relstr("datafile", buffer, depth, &info->datafile))
2460 return False;
2461 if (!smb_io_relstr("configfile", buffer, depth, &info->configfile))
2462 return False;
2464 return True;
2467 /*******************************************************************
2468 Parse a DRIVER_INFO_3 structure.
2469 ********************************************************************/
2471 BOOL smb_io_printer_driver_info_3(char *desc, NEW_BUFFER *buffer, DRIVER_INFO_3 *info, int depth)
2473 prs_struct *ps=&buffer->prs;
2475 prs_debug(ps, depth, desc, "smb_io_printer_driver_info_3");
2476 depth++;
2478 buffer->struct_start=prs_offset(ps);
2480 if (!prs_uint32("version", ps, depth, &info->version))
2481 return False;
2482 if (!smb_io_relstr("name", buffer, depth, &info->name))
2483 return False;
2484 if (!smb_io_relstr("architecture", buffer, depth, &info->architecture))
2485 return False;
2486 if (!smb_io_relstr("driverpath", buffer, depth, &info->driverpath))
2487 return False;
2488 if (!smb_io_relstr("datafile", buffer, depth, &info->datafile))
2489 return False;
2490 if (!smb_io_relstr("configfile", buffer, depth, &info->configfile))
2491 return False;
2492 if (!smb_io_relstr("helpfile", buffer, depth, &info->helpfile))
2493 return False;
2495 if (!smb_io_relarraystr("dependentfiles", buffer, depth, &info->dependentfiles))
2496 return False;
2498 if (!smb_io_relstr("monitorname", buffer, depth, &info->monitorname))
2499 return False;
2500 if (!smb_io_relstr("defaultdatatype", buffer, depth, &info->defaultdatatype))
2501 return False;
2503 return True;
2506 /*******************************************************************
2507 Parse a DRIVER_INFO_6 structure.
2508 ********************************************************************/
2510 BOOL smb_io_printer_driver_info_6(char *desc, NEW_BUFFER *buffer, DRIVER_INFO_6 *info, int depth)
2512 prs_struct *ps=&buffer->prs;
2514 prs_debug(ps, depth, desc, "smb_io_printer_driver_info_6");
2515 depth++;
2517 buffer->struct_start=prs_offset(ps);
2519 if (!prs_uint32("version", ps, depth, &info->version))
2520 return False;
2521 if (!smb_io_relstr("name", buffer, depth, &info->name))
2522 return False;
2523 if (!smb_io_relstr("architecture", buffer, depth, &info->architecture))
2524 return False;
2525 if (!smb_io_relstr("driverpath", buffer, depth, &info->driverpath))
2526 return False;
2527 if (!smb_io_relstr("datafile", buffer, depth, &info->datafile))
2528 return False;
2529 if (!smb_io_relstr("configfile", buffer, depth, &info->configfile))
2530 return False;
2531 if (!smb_io_relstr("helpfile", buffer, depth, &info->helpfile))
2532 return False;
2534 if (!smb_io_relarraystr("dependentfiles", buffer, depth, &info->dependentfiles))
2535 return False;
2537 if (!smb_io_relstr("monitorname", buffer, depth, &info->monitorname))
2538 return False;
2539 if (!smb_io_relstr("defaultdatatype", buffer, depth, &info->defaultdatatype))
2540 return False;
2542 if (!smb_io_relarraystr("previousdrivernames", buffer, depth, &info->previousdrivernames))
2543 return False;
2545 if (!prs_uint32("date.low", ps, depth, &info->driver_date.low))
2546 return False;
2547 if (!prs_uint32("date.high", ps, depth, &info->driver_date.high))
2548 return False;
2550 if (!prs_uint32("padding", ps, depth, &info->padding))
2551 return False;
2553 if (!prs_uint32("driver_version_low", ps, depth, &info->driver_version_low))
2554 return False;
2556 if (!prs_uint32("driver_version_high", ps, depth, &info->driver_version_high))
2557 return False;
2559 if (!smb_io_relstr("mfgname", buffer, depth, &info->mfgname))
2560 return False;
2561 if (!smb_io_relstr("oem_url", buffer, depth, &info->oem_url))
2562 return False;
2563 if (!smb_io_relstr("hardware_id", buffer, depth, &info->hardware_id))
2564 return False;
2565 if (!smb_io_relstr("provider", buffer, depth, &info->provider))
2566 return False;
2568 return True;
2571 /*******************************************************************
2572 Parse a JOB_INFO_1 structure.
2573 ********************************************************************/
2575 BOOL smb_io_job_info_1(char *desc, NEW_BUFFER *buffer, JOB_INFO_1 *info, int depth)
2577 prs_struct *ps=&buffer->prs;
2579 prs_debug(ps, depth, desc, "smb_io_job_info_1");
2580 depth++;
2582 buffer->struct_start=prs_offset(ps);
2584 if (!prs_uint32("jobid", ps, depth, &info->jobid))
2585 return False;
2586 if (!smb_io_relstr("printername", buffer, depth, &info->printername))
2587 return False;
2588 if (!smb_io_relstr("machinename", buffer, depth, &info->machinename))
2589 return False;
2590 if (!smb_io_relstr("username", buffer, depth, &info->username))
2591 return False;
2592 if (!smb_io_relstr("document", buffer, depth, &info->document))
2593 return False;
2594 if (!smb_io_relstr("datatype", buffer, depth, &info->datatype))
2595 return False;
2596 if (!smb_io_relstr("text_status", buffer, depth, &info->text_status))
2597 return False;
2598 if (!prs_uint32("status", ps, depth, &info->status))
2599 return False;
2600 if (!prs_uint32("priority", ps, depth, &info->priority))
2601 return False;
2602 if (!prs_uint32("position", ps, depth, &info->position))
2603 return False;
2604 if (!prs_uint32("totalpages", ps, depth, &info->totalpages))
2605 return False;
2606 if (!prs_uint32("pagesprinted", ps, depth, &info->pagesprinted))
2607 return False;
2608 if (!spoolss_io_system_time("submitted", ps, depth, &info->submitted))
2609 return False;
2611 return True;
2614 /*******************************************************************
2615 Parse a JOB_INFO_2 structure.
2616 ********************************************************************/
2618 BOOL smb_io_job_info_2(char *desc, NEW_BUFFER *buffer, JOB_INFO_2 *info, int depth)
2620 uint32 pipo=0;
2621 prs_struct *ps=&buffer->prs;
2623 prs_debug(ps, depth, desc, "smb_io_job_info_2");
2624 depth++;
2626 buffer->struct_start=prs_offset(ps);
2628 if (!prs_uint32("jobid",ps, depth, &info->jobid))
2629 return False;
2630 if (!smb_io_relstr("printername", buffer, depth, &info->printername))
2631 return False;
2632 if (!smb_io_relstr("machinename", buffer, depth, &info->machinename))
2633 return False;
2634 if (!smb_io_relstr("username", buffer, depth, &info->username))
2635 return False;
2636 if (!smb_io_relstr("document", buffer, depth, &info->document))
2637 return False;
2638 if (!smb_io_relstr("notifyname", buffer, depth, &info->notifyname))
2639 return False;
2640 if (!smb_io_relstr("datatype", buffer, depth, &info->datatype))
2641 return False;
2643 if (!smb_io_relstr("printprocessor", buffer, depth, &info->printprocessor))
2644 return False;
2645 if (!smb_io_relstr("parameters", buffer, depth, &info->parameters))
2646 return False;
2647 if (!smb_io_relstr("drivername", buffer, depth, &info->drivername))
2648 return False;
2649 if (!smb_io_reldevmode("devmode", buffer, depth, &info->devmode))
2650 return False;
2651 if (!smb_io_relstr("text_status", buffer, depth, &info->text_status))
2652 return False;
2654 /* SEC_DESC sec_desc;*/
2655 if (!prs_uint32("Hack! sec desc", ps, depth, &pipo))
2656 return False;
2658 if (!prs_uint32("status",ps, depth, &info->status))
2659 return False;
2660 if (!prs_uint32("priority",ps, depth, &info->priority))
2661 return False;
2662 if (!prs_uint32("position",ps, depth, &info->position))
2663 return False;
2664 if (!prs_uint32("starttime",ps, depth, &info->starttime))
2665 return False;
2666 if (!prs_uint32("untiltime",ps, depth, &info->untiltime))
2667 return False;
2668 if (!prs_uint32("totalpages",ps, depth, &info->totalpages))
2669 return False;
2670 if (!prs_uint32("size",ps, depth, &info->size))
2671 return False;
2672 if (!spoolss_io_system_time("submitted", ps, depth, &info->submitted) )
2673 return False;
2674 if (!prs_uint32("timeelapsed",ps, depth, &info->timeelapsed))
2675 return False;
2676 if (!prs_uint32("pagesprinted",ps, depth, &info->pagesprinted))
2677 return False;
2679 return True;
2682 /*******************************************************************
2683 ********************************************************************/
2685 BOOL smb_io_form_1(char *desc, NEW_BUFFER *buffer, FORM_1 *info, int depth)
2687 prs_struct *ps=&buffer->prs;
2689 prs_debug(ps, depth, desc, "smb_io_form_1");
2690 depth++;
2692 buffer->struct_start=prs_offset(ps);
2694 if (!prs_uint32("flag", ps, depth, &info->flag))
2695 return False;
2697 if (!smb_io_relstr("name", buffer, depth, &info->name))
2698 return False;
2700 if (!prs_uint32("width", ps, depth, &info->width))
2701 return False;
2702 if (!prs_uint32("length", ps, depth, &info->length))
2703 return False;
2704 if (!prs_uint32("left", ps, depth, &info->left))
2705 return False;
2706 if (!prs_uint32("top", ps, depth, &info->top))
2707 return False;
2708 if (!prs_uint32("right", ps, depth, &info->right))
2709 return False;
2710 if (!prs_uint32("bottom", ps, depth, &info->bottom))
2711 return False;
2713 return True;
2716 /*******************************************************************
2717 Read/write a BUFFER struct.
2718 ********************************************************************/
2720 static BOOL spoolss_io_buffer(char *desc, prs_struct *ps, int depth, NEW_BUFFER **pp_buffer)
2722 NEW_BUFFER *buffer = *pp_buffer;
2724 prs_debug(ps, depth, desc, "spoolss_io_buffer");
2725 depth++;
2727 if (UNMARSHALLING(ps))
2728 buffer = *pp_buffer = (NEW_BUFFER *)prs_alloc_mem(ps, sizeof(NEW_BUFFER));
2730 if (buffer == NULL)
2731 return False;
2733 if (!prs_uint32("ptr", ps, depth, &buffer->ptr))
2734 return False;
2736 /* reading */
2737 if (UNMARSHALLING(ps)) {
2738 buffer->size=0;
2739 buffer->string_at_end=0;
2741 if (buffer->ptr==0) {
2743 * JRA. I'm not sure if the data in here is in big-endian format if
2744 * the client is big-endian. Leave as default (little endian) for now.
2747 if (!prs_init(&buffer->prs, 0, prs_get_mem_context(ps), UNMARSHALL))
2748 return False;
2749 return True;
2752 if (!prs_uint32("size", ps, depth, &buffer->size))
2753 return False;
2756 * JRA. I'm not sure if the data in here is in big-endian format if
2757 * the client is big-endian. Leave as default (little endian) for now.
2760 if (!prs_init(&buffer->prs, buffer->size, prs_get_mem_context(ps), UNMARSHALL))
2761 return False;
2763 if (!prs_append_some_prs_data(&buffer->prs, ps, prs_offset(ps), buffer->size))
2764 return False;
2766 if (!prs_set_offset(&buffer->prs, 0))
2767 return False;
2769 if (!prs_set_offset(ps, buffer->size+prs_offset(ps)))
2770 return False;
2772 buffer->string_at_end=buffer->size;
2774 return True;
2776 else {
2777 BOOL ret = False;
2779 /* writing */
2780 if (buffer->ptr==0) {
2781 /* We have finished with the data in buffer->prs - free it. */
2782 prs_mem_free(&buffer->prs);
2783 return True;
2786 if (!prs_uint32("size", ps, depth, &buffer->size))
2787 goto out;
2789 if (!prs_append_some_prs_data(ps, &buffer->prs, 0, buffer->size))
2790 goto out;
2792 ret = True;
2793 out:
2795 /* We have finished with the data in buffer->prs - free it. */
2796 prs_mem_free(&buffer->prs);
2798 return ret;
2802 /*******************************************************************
2803 move a BUFFER from the query to the reply.
2804 As the data pointers in NEW_BUFFER are malloc'ed, not talloc'ed,
2805 this is ok. This is an OPTIMIZATION and is not strictly neccessary.
2806 Clears the memory to zero also.
2807 ********************************************************************/
2809 void spoolss_move_buffer(NEW_BUFFER *src, NEW_BUFFER **dest)
2811 prs_switch_type(&src->prs, MARSHALL);
2812 if(!prs_set_offset(&src->prs, 0))
2813 return;
2814 prs_force_dynamic(&src->prs);
2815 prs_mem_clear(&src->prs);
2816 *dest=src;
2819 /*******************************************************************
2820 Get the size of a BUFFER struct.
2821 ********************************************************************/
2823 uint32 new_get_buffer_size(NEW_BUFFER *buffer)
2825 return (buffer->size);
2828 /*******************************************************************
2829 Parse a DRIVER_DIRECTORY_1 structure.
2830 ********************************************************************/
2832 BOOL smb_io_driverdir_1(char *desc, NEW_BUFFER *buffer, DRIVER_DIRECTORY_1 *info, int depth)
2834 prs_struct *ps=&buffer->prs;
2836 prs_debug(ps, depth, desc, "smb_io_driverdir_1");
2837 depth++;
2839 buffer->struct_start=prs_offset(ps);
2841 if (!smb_io_unistr(desc, &info->name, ps, depth))
2842 return False;
2844 return True;
2847 /*******************************************************************
2848 Parse a PORT_INFO_1 structure.
2849 ********************************************************************/
2851 BOOL smb_io_port_1(char *desc, NEW_BUFFER *buffer, PORT_INFO_1 *info, int depth)
2853 prs_struct *ps=&buffer->prs;
2855 prs_debug(ps, depth, desc, "smb_io_port_1");
2856 depth++;
2858 buffer->struct_start=prs_offset(ps);
2860 if(!smb_io_relstr("port_name", buffer, depth, &info->port_name))
2861 return False;
2863 return True;
2866 /*******************************************************************
2867 Parse a PORT_INFO_2 structure.
2868 ********************************************************************/
2870 BOOL smb_io_port_2(char *desc, NEW_BUFFER *buffer, PORT_INFO_2 *info, int depth)
2872 prs_struct *ps=&buffer->prs;
2874 prs_debug(ps, depth, desc, "smb_io_port_2");
2875 depth++;
2877 buffer->struct_start=prs_offset(ps);
2879 if(!smb_io_relstr("port_name", buffer, depth, &info->port_name))
2880 return False;
2881 if(!smb_io_relstr("monitor_name", buffer, depth, &info->monitor_name))
2882 return False;
2883 if(!smb_io_relstr("description", buffer, depth, &info->description))
2884 return False;
2885 if(!prs_uint32("port_type", ps, depth, &info->port_type))
2886 return False;
2887 if(!prs_uint32("reserved", ps, depth, &info->reserved))
2888 return False;
2890 return True;
2893 /*******************************************************************
2894 ********************************************************************/
2896 BOOL smb_io_printprocessor_info_1(char *desc, NEW_BUFFER *buffer, PRINTPROCESSOR_1 *info, int depth)
2898 prs_struct *ps=&buffer->prs;
2900 prs_debug(ps, depth, desc, "smb_io_printprocessor_info_1");
2901 depth++;
2903 buffer->struct_start=prs_offset(ps);
2905 if (smb_io_relstr("name", buffer, depth, &info->name))
2906 return False;
2908 return True;
2911 /*******************************************************************
2912 ********************************************************************/
2914 BOOL smb_io_printprocdatatype_info_1(char *desc, NEW_BUFFER *buffer, PRINTPROCDATATYPE_1 *info, int depth)
2916 prs_struct *ps=&buffer->prs;
2918 prs_debug(ps, depth, desc, "smb_io_printprocdatatype_info_1");
2919 depth++;
2921 buffer->struct_start=prs_offset(ps);
2923 if (smb_io_relstr("name", buffer, depth, &info->name))
2924 return False;
2926 return True;
2929 /*******************************************************************
2930 ********************************************************************/
2932 BOOL smb_io_printmonitor_info_1(char *desc, NEW_BUFFER *buffer, PRINTMONITOR_1 *info, int depth)
2934 prs_struct *ps=&buffer->prs;
2936 prs_debug(ps, depth, desc, "smb_io_printmonitor_info_1");
2937 depth++;
2939 buffer->struct_start=prs_offset(ps);
2941 if (!smb_io_relstr("name", buffer, depth, &info->name))
2942 return False;
2944 return True;
2947 /*******************************************************************
2948 ********************************************************************/
2950 BOOL smb_io_printmonitor_info_2(char *desc, NEW_BUFFER *buffer, PRINTMONITOR_2 *info, int depth)
2952 prs_struct *ps=&buffer->prs;
2954 prs_debug(ps, depth, desc, "smb_io_printmonitor_info_2");
2955 depth++;
2957 buffer->struct_start=prs_offset(ps);
2959 if (!smb_io_relstr("name", buffer, depth, &info->name))
2960 return False;
2961 if (!smb_io_relstr("environment", buffer, depth, &info->environment))
2962 return False;
2963 if (!smb_io_relstr("dll_name", buffer, depth, &info->dll_name))
2964 return False;
2966 return True;
2969 /*******************************************************************
2970 return the size required by a struct in the stream
2971 ********************************************************************/
2973 uint32 spoolss_size_printer_info_0(PRINTER_INFO_0 *info)
2975 int size=0;
2977 size+=size_of_relative_string( &info->printername );
2978 size+=size_of_relative_string( &info->servername );
2980 size+=size_of_uint32( &info->cjobs);
2981 size+=size_of_uint32( &info->total_jobs);
2982 size+=size_of_uint32( &info->total_bytes);
2984 size+=size_of_uint16( &info->year);
2985 size+=size_of_uint16( &info->month);
2986 size+=size_of_uint16( &info->dayofweek);
2987 size+=size_of_uint16( &info->day);
2988 size+=size_of_uint16( &info->hour);
2989 size+=size_of_uint16( &info->minute);
2990 size+=size_of_uint16( &info->second);
2991 size+=size_of_uint16( &info->milliseconds);
2993 size+=size_of_uint32( &info->global_counter);
2994 size+=size_of_uint32( &info->total_pages);
2996 size+=size_of_uint16( &info->major_version);
2997 size+=size_of_uint16( &info->build_version);
2999 size+=size_of_uint32( &info->unknown7);
3000 size+=size_of_uint32( &info->unknown8);
3001 size+=size_of_uint32( &info->unknown9);
3002 size+=size_of_uint32( &info->session_counter);
3003 size+=size_of_uint32( &info->unknown11);
3004 size+=size_of_uint32( &info->printer_errors);
3005 size+=size_of_uint32( &info->unknown13);
3006 size+=size_of_uint32( &info->unknown14);
3007 size+=size_of_uint32( &info->unknown15);
3008 size+=size_of_uint32( &info->unknown16);
3009 size+=size_of_uint32( &info->change_id);
3010 size+=size_of_uint32( &info->unknown18);
3011 size+=size_of_uint32( &info->status);
3012 size+=size_of_uint32( &info->unknown20);
3013 size+=size_of_uint32( &info->c_setprinter);
3015 size+=size_of_uint16( &info->unknown22);
3016 size+=size_of_uint16( &info->unknown23);
3017 size+=size_of_uint16( &info->unknown24);
3018 size+=size_of_uint16( &info->unknown25);
3019 size+=size_of_uint16( &info->unknown26);
3020 size+=size_of_uint16( &info->unknown27);
3021 size+=size_of_uint16( &info->unknown28);
3022 size+=size_of_uint16( &info->unknown29);
3024 return size;
3027 /*******************************************************************
3028 return the size required by a struct in the stream
3029 ********************************************************************/
3031 uint32 spoolss_size_printer_info_1(PRINTER_INFO_1 *info)
3033 int size=0;
3035 size+=size_of_uint32( &info->flags );
3036 size+=size_of_relative_string( &info->description );
3037 size+=size_of_relative_string( &info->name );
3038 size+=size_of_relative_string( &info->comment );
3040 return size;
3043 /*******************************************************************
3044 return the size required by a struct in the stream
3045 ********************************************************************/
3047 uint32 spoolss_size_printer_info_2(PRINTER_INFO_2 *info)
3049 uint32 size=0;
3051 size += 4;
3052 /* JRA !!!! TESTME - WHAT ABOUT prs_align.... !!! */
3053 size += sec_desc_size( info->secdesc );
3055 size+=size_of_device_mode( info->devmode );
3057 size+=size_of_relative_string( &info->servername );
3058 size+=size_of_relative_string( &info->printername );
3059 size+=size_of_relative_string( &info->sharename );
3060 size+=size_of_relative_string( &info->portname );
3061 size+=size_of_relative_string( &info->drivername );
3062 size+=size_of_relative_string( &info->comment );
3063 size+=size_of_relative_string( &info->location );
3065 size+=size_of_relative_string( &info->sepfile );
3066 size+=size_of_relative_string( &info->printprocessor );
3067 size+=size_of_relative_string( &info->datatype );
3068 size+=size_of_relative_string( &info->parameters );
3070 size+=size_of_uint32( &info->attributes );
3071 size+=size_of_uint32( &info->priority );
3072 size+=size_of_uint32( &info->defaultpriority );
3073 size+=size_of_uint32( &info->starttime );
3074 size+=size_of_uint32( &info->untiltime );
3075 size+=size_of_uint32( &info->status );
3076 size+=size_of_uint32( &info->cjobs );
3077 size+=size_of_uint32( &info->averageppm );
3078 return size;
3081 /*******************************************************************
3082 return the size required by a struct in the stream
3083 ********************************************************************/
3085 uint32 spoolss_size_printer_info_4(PRINTER_INFO_4 *info)
3087 uint32 size=0;
3089 size+=size_of_relative_string( &info->printername );
3090 size+=size_of_relative_string( &info->servername );
3092 size+=size_of_uint32( &info->attributes );
3093 return size;
3096 /*******************************************************************
3097 return the size required by a struct in the stream
3098 ********************************************************************/
3100 uint32 spoolss_size_printer_info_5(PRINTER_INFO_5 *info)
3102 uint32 size=0;
3104 size+=size_of_relative_string( &info->printername );
3105 size+=size_of_relative_string( &info->portname );
3107 size+=size_of_uint32( &info->attributes );
3108 size+=size_of_uint32( &info->device_not_selected_timeout );
3109 size+=size_of_uint32( &info->transmission_retry_timeout );
3110 return size;
3114 /*******************************************************************
3115 return the size required by a struct in the stream
3116 ********************************************************************/
3118 uint32 spoolss_size_printer_info_3(PRINTER_INFO_3 *info)
3120 /* The 4 is for the self relative pointer.. */
3121 /* JRA !!!! TESTME - WHAT ABOUT prs_align.... !!! */
3122 return 4 + (uint32)sec_desc_size( info->secdesc );
3125 /*******************************************************************
3126 return the size required by a struct in the stream
3127 ********************************************************************/
3129 uint32 spoolss_size_printer_driver_info_1(DRIVER_INFO_1 *info)
3131 int size=0;
3132 size+=size_of_relative_string( &info->name );
3134 return size;
3137 /*******************************************************************
3138 return the size required by a struct in the stream
3139 ********************************************************************/
3141 uint32 spoolss_size_printer_driver_info_2(DRIVER_INFO_2 *info)
3143 int size=0;
3144 size+=size_of_uint32( &info->version );
3145 size+=size_of_relative_string( &info->name );
3146 size+=size_of_relative_string( &info->architecture );
3147 size+=size_of_relative_string( &info->driverpath );
3148 size+=size_of_relative_string( &info->datafile );
3149 size+=size_of_relative_string( &info->configfile );
3151 return size;
3154 /*******************************************************************
3155 return the size required by a string array.
3156 ********************************************************************/
3158 uint32 spoolss_size_string_array(uint16 *string)
3160 uint32 i = 0;
3162 if (string) {
3163 for (i=0; (string[i]!=0x0000) || (string[i+1]!=0x0000); i++);
3165 i=i+2; /* to count all chars including the leading zero */
3166 i=2*i; /* because we need the value in bytes */
3167 i=i+4; /* the offset pointer size */
3169 return i;
3172 /*******************************************************************
3173 return the size required by a struct in the stream
3174 ********************************************************************/
3176 uint32 spoolss_size_printer_driver_info_3(DRIVER_INFO_3 *info)
3178 int size=0;
3180 size+=size_of_uint32( &info->version );
3181 size+=size_of_relative_string( &info->name );
3182 size+=size_of_relative_string( &info->architecture );
3183 size+=size_of_relative_string( &info->driverpath );
3184 size+=size_of_relative_string( &info->datafile );
3185 size+=size_of_relative_string( &info->configfile );
3186 size+=size_of_relative_string( &info->helpfile );
3187 size+=size_of_relative_string( &info->monitorname );
3188 size+=size_of_relative_string( &info->defaultdatatype );
3190 size+=spoolss_size_string_array(info->dependentfiles);
3192 return size;
3195 /*******************************************************************
3196 return the size required by a struct in the stream
3197 ********************************************************************/
3199 uint32 spoolss_size_printer_driver_info_6(DRIVER_INFO_6 *info)
3201 uint32 size=0;
3203 size+=size_of_uint32( &info->version );
3204 size+=size_of_relative_string( &info->name );
3205 size+=size_of_relative_string( &info->architecture );
3206 size+=size_of_relative_string( &info->driverpath );
3207 size+=size_of_relative_string( &info->datafile );
3208 size+=size_of_relative_string( &info->configfile );
3209 size+=size_of_relative_string( &info->helpfile );
3211 size+=spoolss_size_string_array(info->dependentfiles);
3213 size+=size_of_relative_string( &info->monitorname );
3214 size+=size_of_relative_string( &info->defaultdatatype );
3216 size+=spoolss_size_string_array(info->previousdrivernames);
3218 size+=size_of_nttime(&info->driver_date);
3219 size+=size_of_uint32( &info->padding );
3220 size+=size_of_uint32( &info->driver_version_low );
3221 size+=size_of_uint32( &info->driver_version_high );
3222 size+=size_of_relative_string( &info->mfgname );
3223 size+=size_of_relative_string( &info->oem_url );
3224 size+=size_of_relative_string( &info->hardware_id );
3225 size+=size_of_relative_string( &info->provider );
3227 return size;
3230 /*******************************************************************
3231 return the size required by a struct in the stream
3232 ********************************************************************/
3234 uint32 spoolss_size_job_info_1(JOB_INFO_1 *info)
3236 int size=0;
3237 size+=size_of_uint32( &info->jobid );
3238 size+=size_of_relative_string( &info->printername );
3239 size+=size_of_relative_string( &info->machinename );
3240 size+=size_of_relative_string( &info->username );
3241 size+=size_of_relative_string( &info->document );
3242 size+=size_of_relative_string( &info->datatype );
3243 size+=size_of_relative_string( &info->text_status );
3244 size+=size_of_uint32( &info->status );
3245 size+=size_of_uint32( &info->priority );
3246 size+=size_of_uint32( &info->position );
3247 size+=size_of_uint32( &info->totalpages );
3248 size+=size_of_uint32( &info->pagesprinted );
3249 size+=size_of_systemtime( &info->submitted );
3251 return size;
3254 /*******************************************************************
3255 return the size required by a struct in the stream
3256 ********************************************************************/
3258 uint32 spoolss_size_job_info_2(JOB_INFO_2 *info)
3260 int size=0;
3262 size+=4; /* size of sec desc ptr */
3264 size+=size_of_uint32( &info->jobid );
3265 size+=size_of_relative_string( &info->printername );
3266 size+=size_of_relative_string( &info->machinename );
3267 size+=size_of_relative_string( &info->username );
3268 size+=size_of_relative_string( &info->document );
3269 size+=size_of_relative_string( &info->notifyname );
3270 size+=size_of_relative_string( &info->datatype );
3271 size+=size_of_relative_string( &info->printprocessor );
3272 size+=size_of_relative_string( &info->parameters );
3273 size+=size_of_relative_string( &info->drivername );
3274 size+=size_of_device_mode( info->devmode );
3275 size+=size_of_relative_string( &info->text_status );
3276 /* SEC_DESC sec_desc;*/
3277 size+=size_of_uint32( &info->status );
3278 size+=size_of_uint32( &info->priority );
3279 size+=size_of_uint32( &info->position );
3280 size+=size_of_uint32( &info->starttime );
3281 size+=size_of_uint32( &info->untiltime );
3282 size+=size_of_uint32( &info->totalpages );
3283 size+=size_of_uint32( &info->size );
3284 size+=size_of_systemtime( &info->submitted );
3285 size+=size_of_uint32( &info->timeelapsed );
3286 size+=size_of_uint32( &info->pagesprinted );
3288 return size;
3291 /*******************************************************************
3292 return the size required by a struct in the stream
3293 ********************************************************************/
3295 uint32 spoolss_size_form_1(FORM_1 *info)
3297 int size=0;
3299 size+=size_of_uint32( &info->flag );
3300 size+=size_of_relative_string( &info->name );
3301 size+=size_of_uint32( &info->width );
3302 size+=size_of_uint32( &info->length );
3303 size+=size_of_uint32( &info->left );
3304 size+=size_of_uint32( &info->top );
3305 size+=size_of_uint32( &info->right );
3306 size+=size_of_uint32( &info->bottom );
3308 return size;
3311 /*******************************************************************
3312 return the size required by a struct in the stream
3313 ********************************************************************/
3315 uint32 spoolss_size_port_info_1(PORT_INFO_1 *info)
3317 int size=0;
3319 size+=size_of_relative_string( &info->port_name );
3321 return size;
3324 /*******************************************************************
3325 return the size required by a struct in the stream
3326 ********************************************************************/
3328 uint32 spoolss_size_driverdir_info_1(DRIVER_DIRECTORY_1 *info)
3330 int size=0;
3332 size=str_len_uni(&info->name); /* the string length */
3333 size=size+1; /* add the leading zero */
3334 size=size*2; /* convert in char */
3336 return size;
3339 /*******************************************************************
3340 return the size required by a struct in the stream
3341 ********************************************************************/
3343 uint32 spoolss_size_printprocessordirectory_info_1(PRINTPROCESSOR_DIRECTORY_1 *info)
3345 int size=0;
3347 size=str_len_uni(&info->name); /* the string length */
3348 size=size+1; /* add the leading zero */
3349 size=size*2; /* convert in char */
3351 return size;
3354 /*******************************************************************
3355 return the size required by a struct in the stream
3356 ********************************************************************/
3358 uint32 spoolss_size_port_info_2(PORT_INFO_2 *info)
3360 int size=0;
3362 size+=size_of_relative_string( &info->port_name );
3363 size+=size_of_relative_string( &info->monitor_name );
3364 size+=size_of_relative_string( &info->description );
3366 size+=size_of_uint32( &info->port_type );
3367 size+=size_of_uint32( &info->reserved );
3369 return size;
3372 /*******************************************************************
3373 return the size required by a struct in the stream
3374 ********************************************************************/
3376 uint32 spoolss_size_printprocessor_info_1(PRINTPROCESSOR_1 *info)
3378 int size=0;
3379 size+=size_of_relative_string( &info->name );
3381 return size;
3384 /*******************************************************************
3385 return the size required by a struct in the stream
3386 ********************************************************************/
3388 uint32 spoolss_size_printprocdatatype_info_1(PRINTPROCDATATYPE_1 *info)
3390 int size=0;
3391 size+=size_of_relative_string( &info->name );
3393 return size;
3396 /*******************************************************************
3397 return the size required by a struct in the stream
3398 ********************************************************************/
3399 uint32 spoolss_size_printer_enum_values(PRINTER_ENUM_VALUES *p)
3401 uint32 size = 0;
3403 if (!p)
3404 return 0;
3406 /* uint32(offset) + uint32(length) + length) */
3407 size += (size_of_uint32(&p->value_len)*2) + p->value_len;
3408 size += (size_of_uint32(&p->data_len)*2) + p->data_len;
3410 size += size_of_uint32(&p->type);
3412 return size;
3415 /*******************************************************************
3416 return the size required by a struct in the stream
3417 ********************************************************************/
3419 uint32 spoolss_size_printmonitor_info_1(PRINTMONITOR_1 *info)
3421 int size=0;
3422 size+=size_of_relative_string( &info->name );
3424 return size;
3427 /*******************************************************************
3428 return the size required by a struct in the stream
3429 ********************************************************************/
3431 uint32 spoolss_size_printmonitor_info_2(PRINTMONITOR_2 *info)
3433 int size=0;
3434 size+=size_of_relative_string( &info->name);
3435 size+=size_of_relative_string( &info->environment);
3436 size+=size_of_relative_string( &info->dll_name);
3438 return size;
3441 /*******************************************************************
3442 * init a structure.
3443 ********************************************************************/
3445 BOOL make_spoolss_q_getprinterdriver2(SPOOL_Q_GETPRINTERDRIVER2 *q_u,
3446 const POLICY_HND *hnd,
3447 const fstring architecture,
3448 uint32 level, uint32 clientmajor, uint32 clientminor,
3449 NEW_BUFFER *buffer, uint32 offered)
3451 if (q_u == NULL)
3452 return False;
3454 memcpy(&q_u->handle, hnd, sizeof(q_u->handle));
3456 init_buf_unistr2(&q_u->architecture, &q_u->architecture_ptr, architecture);
3458 q_u->level=level;
3459 q_u->clientmajorversion=clientmajor;
3460 q_u->clientminorversion=clientminor;
3462 q_u->buffer=buffer;
3463 q_u->offered=offered;
3465 return True;
3468 /*******************************************************************
3469 * read a structure.
3470 * called from spoolss_getprinterdriver2 (srv_spoolss.c)
3471 ********************************************************************/
3473 BOOL spoolss_io_q_getprinterdriver2(char *desc, SPOOL_Q_GETPRINTERDRIVER2 *q_u, prs_struct *ps, int depth)
3475 prs_debug(ps, depth, desc, "spoolss_io_q_getprinterdriver2");
3476 depth++;
3478 if(!prs_align(ps))
3479 return False;
3481 if(!smb_io_pol_hnd("printer handle", &q_u->handle, ps, depth))
3482 return False;
3483 if(!prs_uint32("architecture_ptr", ps, depth, &q_u->architecture_ptr))
3484 return False;
3485 if(!smb_io_unistr2("architecture", &q_u->architecture, q_u->architecture_ptr, ps, depth))
3486 return False;
3488 if(!prs_align(ps))
3489 return False;
3490 if(!prs_uint32("level", ps, depth, &q_u->level))
3491 return False;
3493 if(!spoolss_io_buffer("", ps, depth, &q_u->buffer))
3494 return False;
3496 if(!prs_align(ps))
3497 return False;
3499 if(!prs_uint32("offered", ps, depth, &q_u->offered))
3500 return False;
3502 if(!prs_uint32("clientmajorversion", ps, depth, &q_u->clientmajorversion))
3503 return False;
3504 if(!prs_uint32("clientminorversion", ps, depth, &q_u->clientminorversion))
3505 return False;
3507 return True;
3510 /*******************************************************************
3511 * read a structure.
3512 * called from spoolss_getprinterdriver2 (srv_spoolss.c)
3513 ********************************************************************/
3515 BOOL spoolss_io_r_getprinterdriver2(char *desc, SPOOL_R_GETPRINTERDRIVER2 *r_u, prs_struct *ps, int depth)
3517 prs_debug(ps, depth, desc, "spoolss_io_r_getprinterdriver2");
3518 depth++;
3520 if (!prs_align(ps))
3521 return False;
3523 if (!spoolss_io_buffer("", ps, depth, &r_u->buffer))
3524 return False;
3526 if (!prs_align(ps))
3527 return False;
3528 if (!prs_uint32("needed", ps, depth, &r_u->needed))
3529 return False;
3530 if (!prs_uint32("servermajorversion", ps, depth, &r_u->servermajorversion))
3531 return False;
3532 if (!prs_uint32("serverminorversion", ps, depth, &r_u->serverminorversion))
3533 return False;
3534 if (!prs_werror("status", ps, depth, &r_u->status))
3535 return False;
3537 return True;
3540 /*******************************************************************
3541 * init a structure.
3542 ********************************************************************/
3544 BOOL make_spoolss_q_enumprinters(
3545 SPOOL_Q_ENUMPRINTERS *q_u,
3546 uint32 flags,
3547 fstring servername,
3548 uint32 level,
3549 NEW_BUFFER *buffer,
3550 uint32 offered
3553 q_u->flags=flags;
3555 q_u->servername_ptr = (servername != NULL) ? 1 : 0;
3556 init_buf_unistr2(&q_u->servername, &q_u->servername_ptr, servername);
3558 q_u->level=level;
3559 q_u->buffer=buffer;
3560 q_u->offered=offered;
3562 return True;
3565 /*******************************************************************
3566 * init a structure.
3567 ********************************************************************/
3569 BOOL make_spoolss_q_enumports(SPOOL_Q_ENUMPORTS *q_u,
3570 fstring servername, uint32 level,
3571 NEW_BUFFER *buffer, uint32 offered)
3573 q_u->name_ptr = (servername != NULL) ? 1 : 0;
3574 init_buf_unistr2(&q_u->name, &q_u->name_ptr, servername);
3576 q_u->level=level;
3577 q_u->buffer=buffer;
3578 q_u->offered=offered;
3580 return True;
3583 /*******************************************************************
3584 * read a structure.
3585 * called from spoolss_enumprinters (srv_spoolss.c)
3586 ********************************************************************/
3588 BOOL spoolss_io_q_enumprinters(char *desc, SPOOL_Q_ENUMPRINTERS *q_u, prs_struct *ps, int depth)
3590 prs_debug(ps, depth, desc, "spoolss_io_q_enumprinters");
3591 depth++;
3593 if (!prs_align(ps))
3594 return False;
3596 if (!prs_uint32("flags", ps, depth, &q_u->flags))
3597 return False;
3598 if (!prs_uint32("servername_ptr", ps, depth, &q_u->servername_ptr))
3599 return False;
3601 if (!smb_io_unistr2("", &q_u->servername, q_u->servername_ptr, ps, depth))
3602 return False;
3604 if (!prs_align(ps))
3605 return False;
3606 if (!prs_uint32("level", ps, depth, &q_u->level))
3607 return False;
3609 if (!spoolss_io_buffer("", ps, depth, &q_u->buffer))
3610 return False;
3612 if (!prs_align(ps))
3613 return False;
3614 if (!prs_uint32("offered", ps, depth, &q_u->offered))
3615 return False;
3617 return True;
3620 /*******************************************************************
3621 Parse a SPOOL_R_ENUMPRINTERS structure.
3622 ********************************************************************/
3624 BOOL spoolss_io_r_enumprinters(char *desc, SPOOL_R_ENUMPRINTERS *r_u, prs_struct *ps, int depth)
3626 prs_debug(ps, depth, desc, "spoolss_io_r_enumprinters");
3627 depth++;
3629 if (!prs_align(ps))
3630 return False;
3632 if (!spoolss_io_buffer("", ps, depth, &r_u->buffer))
3633 return False;
3635 if (!prs_align(ps))
3636 return False;
3638 if (!prs_uint32("needed", ps, depth, &r_u->needed))
3639 return False;
3641 if (!prs_uint32("returned", ps, depth, &r_u->returned))
3642 return False;
3644 if (!prs_werror("status", ps, depth, &r_u->status))
3645 return False;
3647 return True;
3650 /*******************************************************************
3651 * write a structure.
3652 * called from spoolss_r_enum_printers (srv_spoolss.c)
3654 ********************************************************************/
3656 BOOL spoolss_io_r_getprinter(char *desc, SPOOL_R_GETPRINTER *r_u, prs_struct *ps, int depth)
3658 prs_debug(ps, depth, desc, "spoolss_io_r_getprinter");
3659 depth++;
3661 if (!prs_align(ps))
3662 return False;
3664 if (!spoolss_io_buffer("", ps, depth, &r_u->buffer))
3665 return False;
3667 if (!prs_align(ps))
3668 return False;
3670 if (!prs_uint32("needed", ps, depth, &r_u->needed))
3671 return False;
3673 if (!prs_werror("status", ps, depth, &r_u->status))
3674 return False;
3676 return True;
3679 /*******************************************************************
3680 * read a structure.
3681 * called from spoolss_getprinter (srv_spoolss.c)
3682 ********************************************************************/
3684 BOOL spoolss_io_q_getprinter(char *desc, SPOOL_Q_GETPRINTER *q_u, prs_struct *ps, int depth)
3686 prs_debug(ps, depth, desc, "spoolss_io_q_getprinter");
3687 depth++;
3689 if (!prs_align(ps))
3690 return False;
3692 if(!smb_io_pol_hnd("printer handle", &q_u->handle, ps, depth))
3693 return False;
3694 if (!prs_uint32("level", ps, depth, &q_u->level))
3695 return False;
3697 if (!spoolss_io_buffer("", ps, depth, &q_u->buffer))
3698 return False;
3700 if (!prs_align(ps))
3701 return False;
3702 if (!prs_uint32("offered", ps, depth, &q_u->offered))
3703 return False;
3705 return True;
3708 /*******************************************************************
3709 * init a structure.
3710 ********************************************************************/
3712 BOOL make_spoolss_q_getprinter(
3713 TALLOC_CTX *mem_ctx,
3714 SPOOL_Q_GETPRINTER *q_u,
3715 const POLICY_HND *hnd,
3716 uint32 level,
3717 NEW_BUFFER *buffer,
3718 uint32 offered
3721 if (q_u == NULL)
3723 return False;
3725 memcpy(&q_u->handle, hnd, sizeof(q_u->handle));
3727 q_u->level=level;
3728 q_u->buffer=buffer;
3729 q_u->offered=offered;
3731 return True;
3734 /*******************************************************************
3735 * init a structure.
3736 ********************************************************************/
3737 BOOL make_spoolss_q_setprinter(TALLOC_CTX *mem_ctx, SPOOL_Q_SETPRINTER *q_u,
3738 const POLICY_HND *hnd, uint32 level, PRINTER_INFO_CTR *info,
3739 uint32 command)
3741 SEC_DESC *secdesc;
3742 DEVICEMODE *devmode;
3744 if (q_u == NULL)
3745 return False;
3747 memcpy(&q_u->handle, hnd, sizeof(q_u->handle));
3749 q_u->level = level;
3750 q_u->info.level = level;
3751 q_u->info.info_ptr = (info != NULL) ? 1 : 0;
3752 switch (level) {
3754 /* There's no such thing as a setprinter level 1 */
3756 case 2:
3757 secdesc = info->printers_2->secdesc;
3758 devmode = info->printers_2->devmode;
3760 make_spoolss_printer_info_2 (mem_ctx, &q_u->info.info_2, info->printers_2);
3761 #if 1 /* JERRY TEST */
3762 q_u->secdesc_ctr = (SEC_DESC_BUF*)malloc(sizeof(SEC_DESC_BUF));
3763 if (!q_u->secdesc_ctr)
3764 return False;
3765 q_u->secdesc_ctr->ptr = (secdesc != NULL) ? 1: 0;
3766 q_u->secdesc_ctr->max_len = (secdesc) ? sizeof(SEC_DESC) + (2*sizeof(uint32)) : 0;
3767 q_u->secdesc_ctr->len = (secdesc) ? sizeof(SEC_DESC) + (2*sizeof(uint32)) : 0;
3768 q_u->secdesc_ctr->sec = secdesc;
3770 q_u->devmode_ctr.devmode_ptr = (devmode != NULL) ? 1 : 0;
3771 q_u->devmode_ctr.size = (devmode != NULL) ? sizeof(DEVICEMODE) + (3*sizeof(uint32)) : 0;
3772 q_u->devmode_ctr.devmode = devmode;
3773 #else
3774 q_u->secdesc_ctr = NULL;
3776 q_u->devmode_ctr.devmode_ptr = 0;
3777 q_u->devmode_ctr.size = 0;
3778 q_u->devmode_ctr.devmode = NULL;
3779 #endif
3780 break;
3781 default:
3782 DEBUG(0,("make_spoolss_q_setprinter: Unknown info level [%d]\n", level));
3783 break;
3787 q_u->command = command;
3789 return True;
3793 /*******************************************************************
3794 ********************************************************************/
3796 BOOL spoolss_io_r_setprinter(char *desc, SPOOL_R_SETPRINTER *r_u, prs_struct *ps, int depth)
3798 prs_debug(ps, depth, desc, "spoolss_io_r_setprinter");
3799 depth++;
3801 if(!prs_align(ps))
3802 return False;
3804 if(!prs_werror("status", ps, depth, &r_u->status))
3805 return False;
3807 return True;
3810 /*******************************************************************
3811 Marshall/unmarshall a SPOOL_Q_SETPRINTER struct.
3812 ********************************************************************/
3814 BOOL spoolss_io_q_setprinter(char *desc, SPOOL_Q_SETPRINTER *q_u, prs_struct *ps, int depth)
3816 uint32 ptr_sec_desc = 0;
3818 prs_debug(ps, depth, desc, "spoolss_io_q_setprinter");
3819 depth++;
3821 if(!prs_align(ps))
3822 return False;
3824 if(!smb_io_pol_hnd("printer handle", &q_u->handle ,ps, depth))
3825 return False;
3826 if(!prs_uint32("level", ps, depth, &q_u->level))
3827 return False;
3829 if(!spool_io_printer_info_level("", &q_u->info, ps, depth))
3830 return False;
3832 if (!spoolss_io_devmode_cont(desc, &q_u->devmode_ctr, ps, depth))
3833 return False;
3835 if(!prs_align(ps))
3836 return False;
3838 switch (q_u->level)
3840 case 2:
3842 ptr_sec_desc = q_u->info.info_2->secdesc_ptr;
3843 break;
3845 case 3:
3847 ptr_sec_desc = q_u->info.info_3->secdesc_ptr;
3848 break;
3851 if (ptr_sec_desc)
3853 if (!sec_io_desc_buf(desc, &q_u->secdesc_ctr, ps, depth))
3854 return False;
3855 } else {
3856 uint32 dummy = 0;
3858 /* Parse a NULL security descriptor. This should really
3859 happen inside the sec_io_desc_buf() function. */
3861 prs_debug(ps, depth, "", "sec_io_desc_buf");
3862 if (!prs_uint32("size", ps, depth + 1, &dummy))
3863 return False;
3864 if (!prs_uint32("ptr", ps, depth + 1, &dummy)) return
3865 False;
3868 if(!prs_uint32("command", ps, depth, &q_u->command))
3869 return False;
3871 return True;
3874 /*******************************************************************
3875 ********************************************************************/
3877 BOOL spoolss_io_r_fcpn(char *desc, SPOOL_R_FCPN *r_u, prs_struct *ps, int depth)
3879 prs_debug(ps, depth, desc, "spoolss_io_r_fcpn");
3880 depth++;
3882 if(!prs_align(ps))
3883 return False;
3885 if(!prs_werror("status", ps, depth, &r_u->status))
3886 return False;
3888 return True;
3891 /*******************************************************************
3892 ********************************************************************/
3894 BOOL spoolss_io_q_fcpn(char *desc, SPOOL_Q_FCPN *q_u, prs_struct *ps, int depth)
3897 prs_debug(ps, depth, desc, "spoolss_io_q_fcpn");
3898 depth++;
3900 if(!prs_align(ps))
3901 return False;
3903 if(!smb_io_pol_hnd("printer handle",&q_u->handle,ps,depth))
3904 return False;
3906 return True;
3910 /*******************************************************************
3911 ********************************************************************/
3913 BOOL spoolss_io_r_addjob(char *desc, SPOOL_R_ADDJOB *r_u, prs_struct *ps, int depth)
3915 prs_debug(ps, depth, desc, "");
3916 depth++;
3918 if(!prs_align(ps))
3919 return False;
3921 if(!spoolss_io_buffer("", ps, depth, &r_u->buffer))
3922 return False;
3924 if(!prs_align(ps))
3925 return False;
3927 if(!prs_uint32("needed", ps, depth, &r_u->needed))
3928 return False;
3930 if(!prs_werror("status", ps, depth, &r_u->status))
3931 return False;
3933 return True;
3936 /*******************************************************************
3937 ********************************************************************/
3939 BOOL spoolss_io_q_addjob(char *desc, SPOOL_Q_ADDJOB *q_u, prs_struct *ps, int depth)
3941 prs_debug(ps, depth, desc, "");
3942 depth++;
3944 if(!prs_align(ps))
3945 return False;
3947 if(!smb_io_pol_hnd("printer handle", &q_u->handle, ps, depth))
3948 return False;
3949 if(!prs_uint32("level", ps, depth, &q_u->level))
3950 return False;
3952 if(!spoolss_io_buffer("", ps, depth, &q_u->buffer))
3953 return False;
3955 if(!prs_align(ps))
3956 return False;
3958 if(!prs_uint32("offered", ps, depth, &q_u->offered))
3959 return False;
3961 return True;
3964 /*******************************************************************
3965 ********************************************************************/
3967 BOOL spoolss_io_r_enumjobs(char *desc, SPOOL_R_ENUMJOBS *r_u, prs_struct *ps, int depth)
3969 prs_debug(ps, depth, desc, "spoolss_io_r_enumjobs");
3970 depth++;
3972 if (!prs_align(ps))
3973 return False;
3975 if (!spoolss_io_buffer("", ps, depth, &r_u->buffer))
3976 return False;
3978 if (!prs_align(ps))
3979 return False;
3981 if (!prs_uint32("needed", ps, depth, &r_u->needed))
3982 return False;
3984 if (!prs_uint32("returned", ps, depth, &r_u->returned))
3985 return False;
3987 if (!prs_werror("status", ps, depth, &r_u->status))
3988 return False;
3990 return True;
3993 /*******************************************************************
3994 ********************************************************************/
3996 BOOL make_spoolss_q_enumjobs(SPOOL_Q_ENUMJOBS *q_u, const POLICY_HND *hnd,
3997 uint32 firstjob,
3998 uint32 numofjobs,
3999 uint32 level,
4000 NEW_BUFFER *buffer,
4001 uint32 offered)
4003 if (q_u == NULL)
4005 return False;
4007 memcpy(&q_u->handle, hnd, sizeof(q_u->handle));
4008 q_u->firstjob = firstjob;
4009 q_u->numofjobs = numofjobs;
4010 q_u->level = level;
4011 q_u->buffer= buffer;
4012 q_u->offered = offered;
4013 return True;
4016 /*******************************************************************
4017 ********************************************************************/
4019 BOOL spoolss_io_q_enumjobs(char *desc, SPOOL_Q_ENUMJOBS *q_u, prs_struct *ps, int depth)
4021 prs_debug(ps, depth, desc, "spoolss_io_q_enumjobs");
4022 depth++;
4024 if (!prs_align(ps))
4025 return False;
4027 if (!smb_io_pol_hnd("printer handle",&q_u->handle, ps, depth))
4028 return False;
4030 if (!prs_uint32("firstjob", ps, depth, &q_u->firstjob))
4031 return False;
4032 if (!prs_uint32("numofjobs", ps, depth, &q_u->numofjobs))
4033 return False;
4034 if (!prs_uint32("level", ps, depth, &q_u->level))
4035 return False;
4037 if (!spoolss_io_buffer("", ps, depth, &q_u->buffer))
4038 return False;
4040 if(!prs_align(ps))
4041 return False;
4043 if (!prs_uint32("offered", ps, depth, &q_u->offered))
4044 return False;
4046 return True;
4049 /*******************************************************************
4050 ********************************************************************/
4052 BOOL spoolss_io_r_schedulejob(char *desc, SPOOL_R_SCHEDULEJOB *r_u, prs_struct *ps, int depth)
4054 prs_debug(ps, depth, desc, "spoolss_io_r_schedulejob");
4055 depth++;
4057 if(!prs_align(ps))
4058 return False;
4060 if(!prs_werror("status", ps, depth, &r_u->status))
4061 return False;
4063 return True;
4066 /*******************************************************************
4067 ********************************************************************/
4069 BOOL spoolss_io_q_schedulejob(char *desc, SPOOL_Q_SCHEDULEJOB *q_u, prs_struct *ps, int depth)
4071 prs_debug(ps, depth, desc, "spoolss_io_q_schedulejob");
4072 depth++;
4074 if(!prs_align(ps))
4075 return False;
4077 if(!smb_io_pol_hnd("printer handle",&q_u->handle,ps,depth))
4078 return False;
4079 if(!prs_uint32("jobid", ps, depth, &q_u->jobid))
4080 return False;
4082 return True;
4085 /*******************************************************************
4086 ********************************************************************/
4088 BOOL spoolss_io_r_setjob(char *desc, SPOOL_R_SETJOB *r_u, prs_struct *ps, int depth)
4090 prs_debug(ps, depth, desc, "spoolss_io_r_setjob");
4091 depth++;
4093 if(!prs_align(ps))
4094 return False;
4096 if(!prs_werror("status", ps, depth, &r_u->status))
4097 return False;
4099 return True;
4102 /*******************************************************************
4103 ********************************************************************/
4105 BOOL spoolss_io_q_setjob(char *desc, SPOOL_Q_SETJOB *q_u, prs_struct *ps, int depth)
4107 prs_debug(ps, depth, desc, "spoolss_io_q_setjob");
4108 depth++;
4110 if(!prs_align(ps))
4111 return False;
4113 if(!smb_io_pol_hnd("printer handle",&q_u->handle,ps,depth))
4114 return False;
4115 if(!prs_uint32("jobid", ps, depth, &q_u->jobid))
4116 return False;
4118 * level is usually 0. If (level!=0) then I'm in trouble !
4119 * I will try to generate setjob command with level!=0, one day.
4121 if(!prs_uint32("level", ps, depth, &q_u->level))
4122 return False;
4123 if(!prs_uint32("command", ps, depth, &q_u->command))
4124 return False;
4126 return True;
4129 /*******************************************************************
4130 Parse a SPOOL_R_ENUMPRINTERDRIVERS structure.
4131 ********************************************************************/
4133 BOOL spoolss_io_r_enumprinterdrivers(char *desc, SPOOL_R_ENUMPRINTERDRIVERS *r_u, prs_struct *ps, int depth)
4135 prs_debug(ps, depth, desc, "spoolss_io_r_enumprinterdrivers");
4136 depth++;
4138 if (!prs_align(ps))
4139 return False;
4141 if (!spoolss_io_buffer("", ps, depth, &r_u->buffer))
4142 return False;
4144 if (!prs_align(ps))
4145 return False;
4147 if (!prs_uint32("needed", ps, depth, &r_u->needed))
4148 return False;
4150 if (!prs_uint32("returned", ps, depth, &r_u->returned))
4151 return False;
4153 if (!prs_werror("status", ps, depth, &r_u->status))
4154 return False;
4156 return True;
4159 /*******************************************************************
4160 * init a structure.
4161 ********************************************************************/
4163 BOOL make_spoolss_q_enumprinterdrivers(SPOOL_Q_ENUMPRINTERDRIVERS *q_u,
4164 const char *name,
4165 const char *environment,
4166 uint32 level,
4167 NEW_BUFFER *buffer, uint32 offered)
4169 init_buf_unistr2(&q_u->name, &q_u->name_ptr, name);
4170 init_buf_unistr2(&q_u->environment, &q_u->environment_ptr, environment);
4172 q_u->level=level;
4173 q_u->buffer=buffer;
4174 q_u->offered=offered;
4176 return True;
4179 /*******************************************************************
4180 Parse a SPOOL_Q_ENUMPRINTERDRIVERS structure.
4181 ********************************************************************/
4183 BOOL spoolss_io_q_enumprinterdrivers(char *desc, SPOOL_Q_ENUMPRINTERDRIVERS *q_u, prs_struct *ps, int depth)
4186 prs_debug(ps, depth, desc, "spoolss_io_q_enumprinterdrivers");
4187 depth++;
4189 if (!prs_align(ps))
4190 return False;
4192 if (!prs_uint32("name_ptr", ps, depth, &q_u->name_ptr))
4193 return False;
4194 if (!smb_io_unistr2("", &q_u->name, q_u->name_ptr,ps, depth))
4195 return False;
4197 if (!prs_align(ps))
4198 return False;
4199 if (!prs_uint32("environment_ptr", ps, depth, &q_u->environment_ptr))
4200 return False;
4201 if (!smb_io_unistr2("", &q_u->environment, q_u->environment_ptr, ps, depth))
4202 return False;
4204 if (!prs_align(ps))
4205 return False;
4206 if (!prs_uint32("level", ps, depth, &q_u->level))
4207 return False;
4209 if (!spoolss_io_buffer("", ps, depth, &q_u->buffer))
4210 return False;
4212 if (!prs_align(ps))
4213 return False;
4215 if (!prs_uint32("offered", ps, depth, &q_u->offered))
4216 return False;
4218 return True;
4221 /*******************************************************************
4222 ********************************************************************/
4224 BOOL spoolss_io_q_enumforms(char *desc, SPOOL_Q_ENUMFORMS *q_u, prs_struct *ps, int depth)
4227 prs_debug(ps, depth, desc, "spoolss_io_q_enumforms");
4228 depth++;
4230 if (!prs_align(ps))
4231 return False;
4232 if (!smb_io_pol_hnd("printer handle",&q_u->handle,ps,depth))
4233 return False;
4234 if (!prs_uint32("level", ps, depth, &q_u->level))
4235 return False;
4237 if (!spoolss_io_buffer("", ps, depth, &q_u->buffer))
4238 return False;
4240 if (!prs_align(ps))
4241 return False;
4242 if (!prs_uint32("offered", ps, depth, &q_u->offered))
4243 return False;
4245 return True;
4248 /*******************************************************************
4249 ********************************************************************/
4251 BOOL spoolss_io_r_enumforms(char *desc, SPOOL_R_ENUMFORMS *r_u, prs_struct *ps, int depth)
4253 prs_debug(ps, depth, desc, "spoolss_io_r_enumforms");
4254 depth++;
4256 if (!prs_align(ps))
4257 return False;
4259 if (!spoolss_io_buffer("", ps, depth, &r_u->buffer))
4260 return False;
4262 if (!prs_align(ps))
4263 return False;
4265 if (!prs_uint32("size of buffer needed", ps, depth, &r_u->needed))
4266 return False;
4268 if (!prs_uint32("numofforms", ps, depth, &r_u->numofforms))
4269 return False;
4271 if (!prs_werror("status", ps, depth, &r_u->status))
4272 return False;
4274 return True;
4277 /*******************************************************************
4278 ********************************************************************/
4280 BOOL spoolss_io_q_getform(char *desc, SPOOL_Q_GETFORM *q_u, prs_struct *ps, int depth)
4283 prs_debug(ps, depth, desc, "spoolss_io_q_getform");
4284 depth++;
4286 if (!prs_align(ps))
4287 return False;
4288 if (!smb_io_pol_hnd("printer handle",&q_u->handle,ps,depth))
4289 return False;
4290 if (!smb_io_unistr2("", &q_u->formname,True,ps,depth))
4291 return False;
4293 if (!prs_align(ps))
4294 return False;
4296 if (!prs_uint32("level", ps, depth, &q_u->level))
4297 return False;
4299 if (!spoolss_io_buffer("", ps, depth, &q_u->buffer))
4300 return False;
4302 if (!prs_align(ps))
4303 return False;
4304 if (!prs_uint32("offered", ps, depth, &q_u->offered))
4305 return False;
4307 return True;
4310 /*******************************************************************
4311 ********************************************************************/
4313 BOOL spoolss_io_r_getform(char *desc, SPOOL_R_GETFORM *r_u, prs_struct *ps, int depth)
4315 prs_debug(ps, depth, desc, "spoolss_io_r_getform");
4316 depth++;
4318 if (!prs_align(ps))
4319 return False;
4321 if (!spoolss_io_buffer("", ps, depth, &r_u->buffer))
4322 return False;
4324 if (!prs_align(ps))
4325 return False;
4327 if (!prs_uint32("size of buffer needed", ps, depth, &r_u->needed))
4328 return False;
4330 if (!prs_werror("status", ps, depth, &r_u->status))
4331 return False;
4333 return True;
4336 /*******************************************************************
4337 Parse a SPOOL_R_ENUMPORTS structure.
4338 ********************************************************************/
4340 BOOL spoolss_io_r_enumports(char *desc, SPOOL_R_ENUMPORTS *r_u, prs_struct *ps, int depth)
4342 prs_debug(ps, depth, desc, "spoolss_io_r_enumports");
4343 depth++;
4345 if (!prs_align(ps))
4346 return False;
4348 if (!spoolss_io_buffer("", ps, depth, &r_u->buffer))
4349 return False;
4351 if (!prs_align(ps))
4352 return False;
4354 if (!prs_uint32("needed", ps, depth, &r_u->needed))
4355 return False;
4357 if (!prs_uint32("returned", ps, depth, &r_u->returned))
4358 return False;
4360 if (!prs_werror("status", ps, depth, &r_u->status))
4361 return False;
4363 return True;
4366 /*******************************************************************
4367 ********************************************************************/
4369 BOOL spoolss_io_q_enumports(char *desc, SPOOL_Q_ENUMPORTS *q_u, prs_struct *ps, int depth)
4371 prs_debug(ps, depth, desc, "");
4372 depth++;
4374 if (!prs_align(ps))
4375 return False;
4377 if (!prs_uint32("", ps, depth, &q_u->name_ptr))
4378 return False;
4379 if (!smb_io_unistr2("", &q_u->name,True,ps,depth))
4380 return False;
4382 if (!prs_align(ps))
4383 return False;
4384 if (!prs_uint32("level", ps, depth, &q_u->level))
4385 return False;
4387 if (!spoolss_io_buffer("", ps, depth, &q_u->buffer))
4388 return False;
4390 if (!prs_align(ps))
4391 return False;
4392 if (!prs_uint32("offered", ps, depth, &q_u->offered))
4393 return False;
4395 return True;
4398 /*******************************************************************
4399 Parse a SPOOL_PRINTER_INFO_LEVEL_1 structure.
4400 ********************************************************************/
4402 BOOL spool_io_printer_info_level_1(char *desc, SPOOL_PRINTER_INFO_LEVEL_1 *il, prs_struct *ps, int depth)
4404 prs_debug(ps, depth, desc, "spool_io_printer_info_level_1");
4405 depth++;
4407 if(!prs_align(ps))
4408 return False;
4410 if(!prs_uint32("flags", ps, depth, &il->flags))
4411 return False;
4412 if(!prs_uint32("description_ptr", ps, depth, &il->description_ptr))
4413 return False;
4414 if(!prs_uint32("name_ptr", ps, depth, &il->name_ptr))
4415 return False;
4416 if(!prs_uint32("comment_ptr", ps, depth, &il->comment_ptr))
4417 return False;
4419 if(!smb_io_unistr2("description", &il->description, il->description_ptr, ps, depth))
4420 return False;
4421 if(!smb_io_unistr2("name", &il->name, il->name_ptr, ps, depth))
4422 return False;
4423 if(!smb_io_unistr2("comment", &il->comment, il->comment_ptr, ps, depth))
4424 return False;
4426 return True;
4429 /*******************************************************************
4430 Parse a SPOOL_PRINTER_INFO_LEVEL_3 structure.
4431 ********************************************************************/
4433 BOOL spool_io_printer_info_level_3(char *desc, SPOOL_PRINTER_INFO_LEVEL_3 *il, prs_struct *ps, int depth)
4435 prs_debug(ps, depth, desc, "spool_io_printer_info_level_3");
4436 depth++;
4438 if(!prs_align(ps))
4439 return False;
4441 if(!prs_uint32("secdesc_ptr", ps, depth, &il->secdesc_ptr))
4442 return False;
4444 return True;
4447 /*******************************************************************
4448 Parse a SPOOL_PRINTER_INFO_LEVEL_2 structure.
4449 ********************************************************************/
4451 BOOL spool_io_printer_info_level_2(char *desc, SPOOL_PRINTER_INFO_LEVEL_2 *il, prs_struct *ps, int depth)
4453 prs_debug(ps, depth, desc, "spool_io_printer_info_level_2");
4454 depth++;
4456 if(!prs_align(ps))
4457 return False;
4459 if(!prs_uint32("servername_ptr", ps, depth, &il->servername_ptr))
4460 return False;
4461 if(!prs_uint32("printername_ptr", ps, depth, &il->printername_ptr))
4462 return False;
4463 if(!prs_uint32("sharename_ptr", ps, depth, &il->sharename_ptr))
4464 return False;
4465 if(!prs_uint32("portname_ptr", ps, depth, &il->portname_ptr))
4466 return False;
4468 if(!prs_uint32("drivername_ptr", ps, depth, &il->drivername_ptr))
4469 return False;
4470 if(!prs_uint32("comment_ptr", ps, depth, &il->comment_ptr))
4471 return False;
4472 if(!prs_uint32("location_ptr", ps, depth, &il->location_ptr))
4473 return False;
4474 if(!prs_uint32("devmode_ptr", ps, depth, &il->devmode_ptr))
4475 return False;
4476 if(!prs_uint32("sepfile_ptr", ps, depth, &il->sepfile_ptr))
4477 return False;
4478 if(!prs_uint32("printprocessor_ptr", ps, depth, &il->printprocessor_ptr))
4479 return False;
4480 if(!prs_uint32("datatype_ptr", ps, depth, &il->datatype_ptr))
4481 return False;
4482 if(!prs_uint32("parameters_ptr", ps, depth, &il->parameters_ptr))
4483 return False;
4484 if(!prs_uint32("secdesc_ptr", ps, depth, &il->secdesc_ptr))
4485 return False;
4487 if(!prs_uint32("attributes", ps, depth, &il->attributes))
4488 return False;
4489 if(!prs_uint32("priority", ps, depth, &il->priority))
4490 return False;
4491 if(!prs_uint32("default_priority", ps, depth, &il->default_priority))
4492 return False;
4493 if(!prs_uint32("starttime", ps, depth, &il->starttime))
4494 return False;
4495 if(!prs_uint32("untiltime", ps, depth, &il->untiltime))
4496 return False;
4497 if(!prs_uint32("status", ps, depth, &il->status))
4498 return False;
4499 if(!prs_uint32("cjobs", ps, depth, &il->cjobs))
4500 return False;
4501 if(!prs_uint32("averageppm", ps, depth, &il->averageppm))
4502 return False;
4504 if(!smb_io_unistr2("servername", &il->servername, il->servername_ptr, ps, depth))
4505 return False;
4506 if(!smb_io_unistr2("printername", &il->printername, il->printername_ptr, ps, depth))
4507 return False;
4508 if(!smb_io_unistr2("sharename", &il->sharename, il->sharename_ptr, ps, depth))
4509 return False;
4510 if(!smb_io_unistr2("portname", &il->portname, il->portname_ptr, ps, depth))
4511 return False;
4512 if(!smb_io_unistr2("drivername", &il->drivername, il->drivername_ptr, ps, depth))
4513 return False;
4514 if(!smb_io_unistr2("comment", &il->comment, il->comment_ptr, ps, depth))
4515 return False;
4516 if(!smb_io_unistr2("location", &il->location, il->location_ptr, ps, depth))
4517 return False;
4518 if(!smb_io_unistr2("sepfile", &il->sepfile, il->sepfile_ptr, ps, depth))
4519 return False;
4520 if(!smb_io_unistr2("printprocessor", &il->printprocessor, il->printprocessor_ptr, ps, depth))
4521 return False;
4522 if(!smb_io_unistr2("datatype", &il->datatype, il->datatype_ptr, ps, depth))
4523 return False;
4524 if(!smb_io_unistr2("parameters", &il->parameters, il->parameters_ptr, ps, depth))
4525 return False;
4527 return True;
4530 /*******************************************************************
4531 ********************************************************************/
4533 BOOL spool_io_printer_info_level(char *desc, SPOOL_PRINTER_INFO_LEVEL *il, prs_struct *ps, int depth)
4535 prs_debug(ps, depth, desc, "spool_io_printer_info_level");
4536 depth++;
4538 if(!prs_align(ps))
4539 return False;
4540 if(!prs_uint32("level", ps, depth, &il->level))
4541 return False;
4542 if(!prs_uint32("info_ptr", ps, depth, &il->info_ptr))
4543 return False;
4545 /* if no struct inside just return */
4546 if (il->info_ptr==0) {
4547 if (UNMARSHALLING(ps)) {
4548 il->info_1=NULL;
4549 il->info_2=NULL;
4551 return True;
4554 switch (il->level) {
4556 * level 0 is used by setprinter when managing the queue
4557 * (hold, stop, start a queue)
4559 case 0:
4560 break;
4561 /* DOCUMENT ME!!! What is level 1 used for? */
4562 case 1:
4564 if (UNMARSHALLING(ps)) {
4565 if ((il->info_1=(SPOOL_PRINTER_INFO_LEVEL_1 *)prs_alloc_mem(ps,sizeof(SPOOL_PRINTER_INFO_LEVEL_1))) == NULL)
4566 return False;
4568 if (!spool_io_printer_info_level_1("", il->info_1, ps, depth))
4569 return False;
4570 break;
4573 * level 2 is used by addprinter
4574 * and by setprinter when updating printer's info
4576 case 2:
4577 if (UNMARSHALLING(ps)) {
4578 if ((il->info_2=(SPOOL_PRINTER_INFO_LEVEL_2 *)prs_alloc_mem(ps,sizeof(SPOOL_PRINTER_INFO_LEVEL_2))) == NULL)
4579 return False;
4581 if (!spool_io_printer_info_level_2("", il->info_2, ps, depth))
4582 return False;
4583 break;
4584 /* DOCUMENT ME!!! What is level 3 used for? */
4585 case 3:
4587 if (UNMARSHALLING(ps)) {
4588 if ((il->info_3=(SPOOL_PRINTER_INFO_LEVEL_3 *)prs_alloc_mem(ps,sizeof(SPOOL_PRINTER_INFO_LEVEL_3))) == NULL)
4589 return False;
4591 if (!spool_io_printer_info_level_3("", il->info_3, ps, depth))
4592 return False;
4593 break;
4597 return True;
4600 /*******************************************************************
4601 ********************************************************************/
4603 BOOL spoolss_io_q_addprinterex(char *desc, SPOOL_Q_ADDPRINTEREX *q_u, prs_struct *ps, int depth)
4605 uint32 ptr_sec_desc = 0;
4607 prs_debug(ps, depth, desc, "spoolss_io_q_addprinterex");
4608 depth++;
4610 if(!prs_align(ps))
4611 return False;
4612 if(!prs_uint32("", ps, depth, &q_u->server_name_ptr))
4613 return False;
4614 if(!smb_io_unistr2("", &q_u->server_name, q_u->server_name_ptr, ps, depth))
4615 return False;
4617 if(!prs_align(ps))
4618 return False;
4620 if(!prs_uint32("info_level", ps, depth, &q_u->level))
4621 return False;
4623 if(!spool_io_printer_info_level("", &q_u->info, ps, depth))
4624 return False;
4626 if (!spoolss_io_devmode_cont(desc, &q_u->devmode_ctr, ps, depth))
4627 return False;
4629 if(!prs_align(ps))
4630 return False;
4632 switch (q_u->level) {
4633 case 2:
4634 ptr_sec_desc = q_u->info.info_2->secdesc_ptr;
4635 break;
4636 case 3:
4637 ptr_sec_desc = q_u->info.info_3->secdesc_ptr;
4638 break;
4640 if (ptr_sec_desc) {
4641 if (!sec_io_desc_buf(desc, &q_u->secdesc_ctr, ps, depth))
4642 return False;
4643 } else {
4644 uint32 dummy;
4646 /* Parse a NULL security descriptor. This should really
4647 happen inside the sec_io_desc_buf() function. */
4649 prs_debug(ps, depth, "", "sec_io_desc_buf");
4650 if (!prs_uint32("size", ps, depth + 1, &dummy))
4651 return False;
4652 if (!prs_uint32("ptr", ps, depth + 1, &dummy))
4653 return False;
4656 if(!prs_uint32("user_switch", ps, depth, &q_u->user_switch))
4657 return False;
4658 if(!spool_io_user_level("", &q_u->user_ctr, ps, depth))
4659 return False;
4661 return True;
4664 /*******************************************************************
4665 ********************************************************************/
4667 BOOL spoolss_io_r_addprinterex(char *desc, SPOOL_R_ADDPRINTEREX *r_u,
4668 prs_struct *ps, int depth)
4670 prs_debug(ps, depth, desc, "spoolss_io_r_addprinterex");
4671 depth++;
4673 if(!smb_io_pol_hnd("printer handle",&r_u->handle,ps,depth))
4674 return False;
4676 if(!prs_werror("status", ps, depth, &r_u->status))
4677 return False;
4679 return True;
4682 /*******************************************************************
4683 ********************************************************************/
4685 BOOL spool_io_printer_driver_info_level_3(char *desc, SPOOL_PRINTER_DRIVER_INFO_LEVEL_3 **q_u,
4686 prs_struct *ps, int depth)
4688 SPOOL_PRINTER_DRIVER_INFO_LEVEL_3 *il;
4690 prs_debug(ps, depth, desc, "spool_io_printer_driver_info_level_3");
4691 depth++;
4693 /* reading */
4694 if (UNMARSHALLING(ps)) {
4695 il=(SPOOL_PRINTER_DRIVER_INFO_LEVEL_3 *)prs_alloc_mem(ps,sizeof(SPOOL_PRINTER_DRIVER_INFO_LEVEL_3));
4696 if(il == NULL)
4697 return False;
4698 *q_u=il;
4700 else {
4701 il=*q_u;
4704 if(!prs_align(ps))
4705 return False;
4707 if(!prs_uint32("cversion", ps, depth, &il->cversion))
4708 return False;
4709 if(!prs_uint32("name", ps, depth, &il->name_ptr))
4710 return False;
4711 if(!prs_uint32("environment", ps, depth, &il->environment_ptr))
4712 return False;
4713 if(!prs_uint32("driverpath", ps, depth, &il->driverpath_ptr))
4714 return False;
4715 if(!prs_uint32("datafile", ps, depth, &il->datafile_ptr))
4716 return False;
4717 if(!prs_uint32("configfile", ps, depth, &il->configfile_ptr))
4718 return False;
4719 if(!prs_uint32("helpfile", ps, depth, &il->helpfile_ptr))
4720 return False;
4721 if(!prs_uint32("monitorname", ps, depth, &il->monitorname_ptr))
4722 return False;
4723 if(!prs_uint32("defaultdatatype", ps, depth, &il->defaultdatatype_ptr))
4724 return False;
4725 if(!prs_uint32("dependentfilessize", ps, depth, &il->dependentfilessize))
4726 return False;
4727 if(!prs_uint32("dependentfiles", ps, depth, &il->dependentfiles_ptr))
4728 return False;
4730 if(!prs_align(ps))
4731 return False;
4733 if(!smb_io_unistr2("name", &il->name, il->name_ptr, ps, depth))
4734 return False;
4735 if(!smb_io_unistr2("environment", &il->environment, il->environment_ptr, ps, depth))
4736 return False;
4737 if(!smb_io_unistr2("driverpath", &il->driverpath, il->driverpath_ptr, ps, depth))
4738 return False;
4739 if(!smb_io_unistr2("datafile", &il->datafile, il->datafile_ptr, ps, depth))
4740 return False;
4741 if(!smb_io_unistr2("configfile", &il->configfile, il->configfile_ptr, ps, depth))
4742 return False;
4743 if(!smb_io_unistr2("helpfile", &il->helpfile, il->helpfile_ptr, ps, depth))
4744 return False;
4745 if(!smb_io_unistr2("monitorname", &il->monitorname, il->monitorname_ptr, ps, depth))
4746 return False;
4747 if(!smb_io_unistr2("defaultdatatype", &il->defaultdatatype, il->defaultdatatype_ptr, ps, depth))
4748 return False;
4750 if(!prs_align(ps))
4751 return False;
4753 if (il->dependentfiles_ptr)
4754 smb_io_buffer5("", &il->dependentfiles, ps, depth);
4756 return True;
4759 /*******************************************************************
4760 parse a SPOOL_PRINTER_DRIVER_INFO_LEVEL_6 structure
4761 ********************************************************************/
4763 BOOL spool_io_printer_driver_info_level_6(char *desc, SPOOL_PRINTER_DRIVER_INFO_LEVEL_6 **q_u,
4764 prs_struct *ps, int depth)
4766 SPOOL_PRINTER_DRIVER_INFO_LEVEL_6 *il;
4768 prs_debug(ps, depth, desc, "spool_io_printer_driver_info_level_6");
4769 depth++;
4771 /* reading */
4772 if (UNMARSHALLING(ps)) {
4773 il=(SPOOL_PRINTER_DRIVER_INFO_LEVEL_6 *)prs_alloc_mem(ps,sizeof(SPOOL_PRINTER_DRIVER_INFO_LEVEL_6));
4774 if(il == NULL)
4775 return False;
4776 *q_u=il;
4778 else {
4779 il=*q_u;
4782 if(!prs_align(ps))
4783 return False;
4786 /* parse the main elements the packet */
4788 if(!prs_uint32("version", ps, depth, &il->version))
4789 return False;
4791 if(!prs_uint32("name_ptr", ps, depth, &il->name_ptr))
4792 return False;
4794 * If name_ptr is NULL then the next 4 bytes are the name_ptr. A driver
4795 * with a NULL name just isn't a driver For example: "HP LaserJet 4si"
4796 * from W2K CDROM (which uses unidriver). JohnR 010205
4798 if (!il->name_ptr) {
4799 DEBUG(5,("spool_io_printer_driver_info_level_6: name_ptr is NULL! Get next value\n"));
4800 if(!prs_uint32("name_ptr", ps, depth, &il->name_ptr))
4801 return False;
4804 if(!prs_uint32("environment_ptr", ps, depth, &il->environment_ptr))
4805 return False;
4806 if(!prs_uint32("driverpath_ptr", ps, depth, &il->driverpath_ptr))
4807 return False;
4808 if(!prs_uint32("datafile_ptr", ps, depth, &il->datafile_ptr))
4809 return False;
4810 if(!prs_uint32("configfile_ptr", ps, depth, &il->configfile_ptr))
4811 return False;
4812 if(!prs_uint32("helpfile_ptr", ps, depth, &il->helpfile_ptr))
4813 return False;
4814 if(!prs_uint32("monitorname_ptr", ps, depth, &il->monitorname_ptr))
4815 return False;
4816 if(!prs_uint32("defaultdatatype_ptr", ps, depth, &il->defaultdatatype_ptr))
4817 return False;
4818 if(!prs_uint32("dependentfiles_len", ps, depth, &il->dependentfiles_len))
4819 return False;
4820 if(!prs_uint32("dependentfiles_ptr", ps, depth, &il->dependentfiles_ptr))
4821 return False;
4822 if(!prs_uint32("previousnames_len", ps, depth, &il->previousnames_len))
4823 return False;
4824 if(!prs_uint32("previousnames_ptr", ps, depth, &il->previousnames_ptr))
4825 return False;
4826 if(!smb_io_time("driverdate", &il->driverdate, ps, depth))
4827 return False;
4828 if(!prs_uint32("dummy4", ps, depth, &il->dummy4))
4829 return False;
4830 if(!prs_uint64("driverversion", ps, depth, &il->driverversion))
4831 return False;
4832 if(!prs_uint32("mfgname_ptr", ps, depth, &il->mfgname_ptr))
4833 return False;
4834 if(!prs_uint32("oemurl_ptr", ps, depth, &il->oemurl_ptr))
4835 return False;
4836 if(!prs_uint32("hardwareid_ptr", ps, depth, &il->hardwareid_ptr))
4837 return False;
4838 if(!prs_uint32("provider_ptr", ps, depth, &il->provider_ptr))
4839 return False;
4841 /* parse the structures in the packet */
4843 if(!smb_io_unistr2("name", &il->name, il->name_ptr, ps, depth))
4844 return False;
4845 if(!prs_align(ps))
4846 return False;
4848 if(!smb_io_unistr2("environment", &il->environment, il->environment_ptr, ps, depth))
4849 return False;
4850 if(!prs_align(ps))
4851 return False;
4853 if(!smb_io_unistr2("driverpath", &il->driverpath, il->driverpath_ptr, ps, depth))
4854 return False;
4855 if(!prs_align(ps))
4856 return False;
4858 if(!smb_io_unistr2("datafile", &il->datafile, il->datafile_ptr, ps, depth))
4859 return False;
4860 if(!prs_align(ps))
4861 return False;
4863 if(!smb_io_unistr2("configfile", &il->configfile, il->configfile_ptr, ps, depth))
4864 return False;
4865 if(!prs_align(ps))
4866 return False;
4868 if(!smb_io_unistr2("helpfile", &il->helpfile, il->helpfile_ptr, ps, depth))
4869 return False;
4870 if(!prs_align(ps))
4871 return False;
4873 if(!smb_io_unistr2("monitorname", &il->monitorname, il->monitorname_ptr, ps, depth))
4874 return False;
4875 if(!prs_align(ps))
4876 return False;
4878 if(!smb_io_unistr2("defaultdatatype", &il->defaultdatatype, il->defaultdatatype_ptr, ps, depth))
4879 return False;
4880 if(!prs_align(ps))
4881 return False;
4882 if (il->dependentfiles_ptr) {
4883 if(!smb_io_buffer5("dependentfiles", &il->dependentfiles, ps, depth))
4884 return False;
4885 if(!prs_align(ps))
4886 return False;
4888 if (il->previousnames_ptr) {
4889 if(!smb_io_buffer5("previousnames", &il->previousnames, ps, depth))
4890 return False;
4891 if(!prs_align(ps))
4892 return False;
4894 if(!smb_io_unistr2("mfgname", &il->mfgname, il->mfgname_ptr, ps, depth))
4895 return False;
4896 if(!prs_align(ps))
4897 return False;
4898 if(!smb_io_unistr2("oemurl", &il->oemurl, il->oemurl_ptr, ps, depth))
4899 return False;
4900 if(!prs_align(ps))
4901 return False;
4902 if(!smb_io_unistr2("hardwareid", &il->hardwareid, il->hardwareid_ptr, ps, depth))
4903 return False;
4904 if(!prs_align(ps))
4905 return False;
4906 if(!smb_io_unistr2("provider", &il->provider, il->provider_ptr, ps, depth))
4907 return False;
4909 return True;
4912 /*******************************************************************
4913 convert a buffer of UNICODE strings null terminated
4914 the buffer is terminated by a NULL
4916 convert to an dos codepage array (null terminated)
4918 dynamically allocate memory
4920 ********************************************************************/
4921 static BOOL uniarray_2_dosarray(BUFFER5 *buf5, fstring **ar)
4923 fstring f, *tar;
4924 int n = 0;
4925 char *src;
4927 if (buf5==NULL)
4928 return False;
4930 src = (char *)buf5->buffer;
4931 *ar = NULL;
4933 while (src < ((char *)buf5->buffer) + buf5->buf_len*2) {
4934 unistr_to_dos(f, src, sizeof(f)-1);
4935 src = skip_unibuf(src, 2*buf5->buf_len - PTR_DIFF(src,buf5->buffer));
4936 tar = (fstring *)Realloc(*ar, sizeof(fstring)*(n+2));
4937 if (!tar)
4938 return False;
4939 else
4940 *ar = tar;
4941 fstrcpy((*ar)[n], f);
4942 n++;
4944 fstrcpy((*ar)[n], "");
4946 return True;
4952 /*******************************************************************
4953 read a UNICODE array with null terminated strings
4954 and null terminated array
4955 and size of array at beginning
4956 ********************************************************************/
4958 BOOL smb_io_unibuffer(char *desc, UNISTR2 *buffer, prs_struct *ps, int depth)
4960 if (buffer==NULL) return False;
4962 buffer->undoc=0;
4963 buffer->uni_str_len=buffer->uni_max_len;
4965 if(!prs_uint32("buffer_size", ps, depth, &buffer->uni_max_len))
4966 return False;
4968 if(!prs_unistr2(True, "buffer ", ps, depth, buffer))
4969 return False;
4971 return True;
4974 /*******************************************************************
4975 ********************************************************************/
4977 BOOL spool_io_printer_driver_info_level(char *desc, SPOOL_PRINTER_DRIVER_INFO_LEVEL *il, prs_struct *ps, int depth)
4979 prs_debug(ps, depth, desc, "spool_io_printer_driver_info_level");
4980 depth++;
4982 if(!prs_align(ps))
4983 return False;
4984 if(!prs_uint32("level", ps, depth, &il->level))
4985 return False;
4986 if(!prs_uint32("ptr", ps, depth, &il->ptr))
4987 return False;
4989 if (il->ptr==0)
4990 return True;
4992 switch (il->level) {
4993 case 3:
4994 if(!spool_io_printer_driver_info_level_3("", &il->info_3, ps, depth))
4995 return False;
4996 break;
4997 case 6:
4998 if(!spool_io_printer_driver_info_level_6("", &il->info_6, ps, depth))
4999 return False;
5000 break;
5001 default:
5002 return False;
5005 return True;
5008 /*******************************************************************
5009 init a SPOOL_Q_ADDPRINTERDRIVER struct
5010 ******************************************************************/
5012 BOOL make_spoolss_q_addprinterdriver(TALLOC_CTX *mem_ctx,
5013 SPOOL_Q_ADDPRINTERDRIVER *q_u, const char* srv_name,
5014 uint32 level, PRINTER_DRIVER_CTR *info)
5016 DEBUG(5,("make_spoolss_q_addprinterdriver\n"));
5018 q_u->server_name_ptr = (srv_name!=NULL)?1:0;
5019 init_unistr2(&q_u->server_name, srv_name, strlen(srv_name)+1);
5021 q_u->level = level;
5023 q_u->info.level = level;
5024 q_u->info.ptr = (info!=NULL)?1:0;
5025 switch (level)
5027 /* info level 3 is supported by Windows 95/98, WinNT and Win2k */
5028 case 3 :
5029 make_spoolss_driver_info_3(mem_ctx, &q_u->info.info_3, info->info3);
5030 break;
5032 /* info level 6 is supported by WinME and Win2k */
5033 case 6:
5034 /* WRITEME!! will add later --jerry */
5035 break;
5037 default:
5038 DEBUG(0,("make_spoolss_q_addprinterdriver: Unknown info level [%d]\n", level));
5039 break;
5042 return True;
5045 BOOL make_spoolss_driver_info_3(TALLOC_CTX *mem_ctx,
5046 SPOOL_PRINTER_DRIVER_INFO_LEVEL_3 **spool_drv_info,
5047 DRIVER_INFO_3 *info3)
5049 uint32 len = 0;
5050 uint16 *ptr = info3->dependentfiles;
5051 BOOL done = False;
5052 BOOL null_char = False;
5053 SPOOL_PRINTER_DRIVER_INFO_LEVEL_3 *inf;
5055 if (!(inf=(SPOOL_PRINTER_DRIVER_INFO_LEVEL_3*)talloc_zero(mem_ctx, sizeof(SPOOL_PRINTER_DRIVER_INFO_LEVEL_3))))
5056 return False;
5058 inf->cversion = info3->version;
5059 inf->name_ptr = (info3->name.buffer!=NULL)?1:0;
5060 inf->environment_ptr = (info3->architecture.buffer!=NULL)?1:0;
5061 inf->driverpath_ptr = (info3->driverpath.buffer!=NULL)?1:0;
5062 inf->datafile_ptr = (info3->datafile.buffer!=NULL)?1:0;
5063 inf->configfile_ptr = (info3->configfile.buffer!=NULL)?1:0;
5064 inf->helpfile_ptr = (info3->helpfile.buffer!=NULL)?1:0;
5065 inf->monitorname_ptr = (info3->monitorname.buffer!=NULL)?1:0;
5066 inf->defaultdatatype_ptr = (info3->defaultdatatype.buffer!=NULL)?1:0;
5068 init_unistr2_from_unistr(&inf->name, &info3->name);
5069 init_unistr2_from_unistr(&inf->environment, &info3->architecture);
5070 init_unistr2_from_unistr(&inf->driverpath, &info3->driverpath);
5071 init_unistr2_from_unistr(&inf->datafile, &info3->datafile);
5072 init_unistr2_from_unistr(&inf->configfile, &info3->configfile);
5073 init_unistr2_from_unistr(&inf->helpfile, &info3->helpfile);
5074 init_unistr2_from_unistr(&inf->monitorname, &info3->monitorname);
5075 init_unistr2_from_unistr(&inf->defaultdatatype, &info3->defaultdatatype);
5077 while (!done)
5079 switch (*ptr)
5081 case 0:
5082 /* the null_char BOOL is used to help locate
5083 two '\0's back to back */
5084 if (null_char)
5085 done = True;
5086 else
5087 null_char = True;
5088 break;
5090 default:
5091 null_char = False;
5093 break;
5095 len++;
5096 ptr++;
5098 inf->dependentfiles_ptr = (info3->dependentfiles != NULL) ? 1 : 0;
5099 inf->dependentfilessize = len;
5100 if(!make_spoolss_buffer5(mem_ctx, &inf->dependentfiles, len, info3->dependentfiles))
5102 SAFE_FREE(inf);
5103 return False;
5106 *spool_drv_info = inf;
5108 return True;
5111 /*******************************************************************
5112 make a BUFFER5 struct from a uint16*
5113 ******************************************************************/
5114 BOOL make_spoolss_buffer5(TALLOC_CTX *mem_ctx, BUFFER5 *buf5, uint32 len, uint16 *src)
5117 buf5->buf_len = len;
5118 if((buf5->buffer=(uint16*)talloc_memdup(mem_ctx, src, sizeof(uint16)*len)) == NULL)
5120 DEBUG(0,("make_spoolss_buffer5: Unable to malloc memory for buffer!\n"));
5121 return False;
5124 return True;
5127 /*******************************************************************
5128 fill in the prs_struct for a ADDPRINTERDRIVER request PDU
5129 ********************************************************************/
5131 BOOL spoolss_io_q_addprinterdriver(char *desc, SPOOL_Q_ADDPRINTERDRIVER *q_u, prs_struct *ps, int depth)
5133 prs_debug(ps, depth, desc, "spoolss_io_q_addprinterdriver");
5134 depth++;
5136 if(!prs_align(ps))
5137 return False;
5139 if(!prs_uint32("server_name_ptr", ps, depth, &q_u->server_name_ptr))
5140 return False;
5141 if(!smb_io_unistr2("server_name", &q_u->server_name, q_u->server_name_ptr, ps, depth))
5142 return False;
5144 if(!prs_align(ps))
5145 return False;
5146 if(!prs_uint32("info_level", ps, depth, &q_u->level))
5147 return False;
5149 if(!spool_io_printer_driver_info_level("", &q_u->info, ps, depth))
5150 return False;
5152 return True;
5155 /*******************************************************************
5156 ********************************************************************/
5158 BOOL spoolss_io_r_addprinterdriver(char *desc, SPOOL_R_ADDPRINTERDRIVER *q_u, prs_struct *ps, int depth)
5160 prs_debug(ps, depth, desc, "spoolss_io_r_addprinterdriver");
5161 depth++;
5163 if(!prs_werror("status", ps, depth, &q_u->status))
5164 return False;
5166 return True;
5169 /*******************************************************************
5170 ********************************************************************/
5172 BOOL uni_2_asc_printer_driver_3(SPOOL_PRINTER_DRIVER_INFO_LEVEL_3 *uni,
5173 NT_PRINTER_DRIVER_INFO_LEVEL_3 **asc)
5175 NT_PRINTER_DRIVER_INFO_LEVEL_3 *d;
5177 DEBUG(7,("uni_2_asc_printer_driver_3: Converting from UNICODE to ASCII\n"));
5179 if (*asc==NULL)
5181 *asc=(NT_PRINTER_DRIVER_INFO_LEVEL_3 *)malloc(sizeof(NT_PRINTER_DRIVER_INFO_LEVEL_3));
5182 if(*asc == NULL)
5183 return False;
5184 ZERO_STRUCTP(*asc);
5187 d=*asc;
5189 d->cversion=uni->cversion;
5191 unistr2_to_ascii(d->name, &uni->name, sizeof(d->name)-1);
5192 unistr2_to_ascii(d->environment, &uni->environment, sizeof(d->environment)-1);
5193 unistr2_to_ascii(d->driverpath, &uni->driverpath, sizeof(d->driverpath)-1);
5194 unistr2_to_ascii(d->datafile, &uni->datafile, sizeof(d->datafile)-1);
5195 unistr2_to_ascii(d->configfile, &uni->configfile, sizeof(d->configfile)-1);
5196 unistr2_to_ascii(d->helpfile, &uni->helpfile, sizeof(d->helpfile)-1);
5197 unistr2_to_ascii(d->monitorname, &uni->monitorname, sizeof(d->monitorname)-1);
5198 unistr2_to_ascii(d->defaultdatatype, &uni->defaultdatatype, sizeof(d->defaultdatatype)-1);
5200 DEBUGADD(8,( "version: %d\n", d->cversion));
5201 DEBUGADD(8,( "name: %s\n", d->name));
5202 DEBUGADD(8,( "environment: %s\n", d->environment));
5203 DEBUGADD(8,( "driverpath: %s\n", d->driverpath));
5204 DEBUGADD(8,( "datafile: %s\n", d->datafile));
5205 DEBUGADD(8,( "configfile: %s\n", d->configfile));
5206 DEBUGADD(8,( "helpfile: %s\n", d->helpfile));
5207 DEBUGADD(8,( "monitorname: %s\n", d->monitorname));
5208 DEBUGADD(8,( "defaultdatatype: %s\n", d->defaultdatatype));
5210 if (uniarray_2_dosarray(&uni->dependentfiles, &d->dependentfiles ))
5211 return True;
5213 SAFE_FREE(*asc);
5214 return False;
5217 /*******************************************************************
5218 ********************************************************************/
5219 BOOL uni_2_asc_printer_driver_6(SPOOL_PRINTER_DRIVER_INFO_LEVEL_6 *uni,
5220 NT_PRINTER_DRIVER_INFO_LEVEL_6 **asc)
5222 NT_PRINTER_DRIVER_INFO_LEVEL_6 *d;
5224 DEBUG(7,("uni_2_asc_printer_driver_6: Converting from UNICODE to ASCII\n"));
5226 if (*asc==NULL)
5228 *asc=(NT_PRINTER_DRIVER_INFO_LEVEL_6 *)malloc(sizeof(NT_PRINTER_DRIVER_INFO_LEVEL_6));
5229 if(*asc == NULL)
5230 return False;
5231 ZERO_STRUCTP(*asc);
5234 d=*asc;
5236 d->version=uni->version;
5238 unistr2_to_ascii(d->name, &uni->name, sizeof(d->name)-1);
5239 unistr2_to_ascii(d->environment, &uni->environment, sizeof(d->environment)-1);
5240 unistr2_to_ascii(d->driverpath, &uni->driverpath, sizeof(d->driverpath)-1);
5241 unistr2_to_ascii(d->datafile, &uni->datafile, sizeof(d->datafile)-1);
5242 unistr2_to_ascii(d->configfile, &uni->configfile, sizeof(d->configfile)-1);
5243 unistr2_to_ascii(d->helpfile, &uni->helpfile, sizeof(d->helpfile)-1);
5244 unistr2_to_ascii(d->monitorname, &uni->monitorname, sizeof(d->monitorname)-1);
5245 unistr2_to_ascii(d->defaultdatatype, &uni->defaultdatatype, sizeof(d->defaultdatatype)-1);
5247 DEBUGADD(8,( "version: %d\n", d->version));
5248 DEBUGADD(8,( "name: %s\n", d->name));
5249 DEBUGADD(8,( "environment: %s\n", d->environment));
5250 DEBUGADD(8,( "driverpath: %s\n", d->driverpath));
5251 DEBUGADD(8,( "datafile: %s\n", d->datafile));
5252 DEBUGADD(8,( "configfile: %s\n", d->configfile));
5253 DEBUGADD(8,( "helpfile: %s\n", d->helpfile));
5254 DEBUGADD(8,( "monitorname: %s\n", d->monitorname));
5255 DEBUGADD(8,( "defaultdatatype: %s\n", d->defaultdatatype));
5257 if (!uniarray_2_dosarray(&uni->dependentfiles, &d->dependentfiles ))
5258 goto error;
5259 if (!uniarray_2_dosarray(&uni->previousnames, &d->previousnames ))
5260 goto error;
5262 return True;
5264 error:
5265 SAFE_FREE(*asc);
5266 return False;
5269 BOOL uni_2_asc_printer_info_2(const SPOOL_PRINTER_INFO_LEVEL_2 *uni,
5270 NT_PRINTER_INFO_LEVEL_2 **asc)
5272 NT_PRINTER_INFO_LEVEL_2 *d;
5273 time_t time_unix;
5275 DEBUG(7,("Converting from UNICODE to ASCII\n"));
5276 time_unix=time(NULL);
5278 if (*asc==NULL) {
5279 DEBUGADD(8,("allocating memory\n"));
5281 *asc=(NT_PRINTER_INFO_LEVEL_2 *)malloc(sizeof(NT_PRINTER_INFO_LEVEL_2));
5282 if(*asc == NULL)
5283 return False;
5284 ZERO_STRUCTP(*asc);
5286 /* we allocate memory iff called from
5287 * addprinter(ex) so we can do one time stuff here.
5289 (*asc)->setuptime=time_unix;
5291 DEBUGADD(8,("start converting\n"));
5293 d=*asc;
5295 d->attributes=uni->attributes;
5296 d->priority=uni->priority;
5297 d->default_priority=uni->default_priority;
5298 d->starttime=uni->starttime;
5299 d->untiltime=uni->untiltime;
5300 d->status=uni->status;
5301 d->cjobs=uni->cjobs;
5303 unistr2_to_ascii(d->servername, &uni->servername, sizeof(d->servername)-1);
5304 unistr2_to_ascii(d->printername, &uni->printername, sizeof(d->printername)-1);
5305 unistr2_to_ascii(d->sharename, &uni->sharename, sizeof(d->sharename)-1);
5306 unistr2_to_ascii(d->portname, &uni->portname, sizeof(d->portname)-1);
5307 unistr2_to_ascii(d->drivername, &uni->drivername, sizeof(d->drivername)-1);
5308 unistr2_to_ascii(d->comment, &uni->comment, sizeof(d->comment)-1);
5309 unistr2_to_ascii(d->location, &uni->location, sizeof(d->location)-1);
5310 unistr2_to_ascii(d->sepfile, &uni->sepfile, sizeof(d->sepfile)-1);
5311 unistr2_to_ascii(d->printprocessor, &uni->printprocessor, sizeof(d->printprocessor)-1);
5312 unistr2_to_ascii(d->datatype, &uni->datatype, sizeof(d->datatype)-1);
5313 unistr2_to_ascii(d->parameters, &uni->parameters, sizeof(d->parameters)-1);
5315 return True;
5318 /*******************************************************************
5319 * init a structure.
5320 ********************************************************************/
5322 BOOL make_spoolss_q_getprinterdriverdir(SPOOL_Q_GETPRINTERDRIVERDIR *q_u,
5323 fstring servername, fstring env_name, uint32 level,
5324 NEW_BUFFER *buffer, uint32 offered)
5326 init_buf_unistr2(&q_u->name, &q_u->name_ptr, servername);
5327 init_buf_unistr2(&q_u->environment, &q_u->environment_ptr, env_name);
5329 q_u->level=level;
5330 q_u->buffer=buffer;
5331 q_u->offered=offered;
5333 return True;
5336 /*******************************************************************
5337 Parse a SPOOL_Q_GETPRINTERDRIVERDIR structure.
5338 ********************************************************************/
5340 BOOL spoolss_io_q_getprinterdriverdir(char *desc, SPOOL_Q_GETPRINTERDRIVERDIR *q_u, prs_struct *ps, int depth)
5342 prs_debug(ps, depth, desc, "spoolss_io_q_getprinterdriverdir");
5343 depth++;
5345 if(!prs_align(ps))
5346 return False;
5347 if(!prs_uint32("name_ptr", ps, depth, &q_u->name_ptr))
5348 return False;
5349 if(!smb_io_unistr2("", &q_u->name, q_u->name_ptr, ps, depth))
5350 return False;
5352 if(!prs_align(ps))
5353 return False;
5355 if(!prs_uint32("", ps, depth, &q_u->environment_ptr))
5356 return False;
5357 if(!smb_io_unistr2("", &q_u->environment, q_u->environment_ptr, ps, depth))
5358 return False;
5360 if(!prs_align(ps))
5361 return False;
5363 if(!prs_uint32("level", ps, depth, &q_u->level))
5364 return False;
5366 if(!spoolss_io_buffer("", ps, depth, &q_u->buffer))
5367 return False;
5369 if(!prs_align(ps))
5370 return False;
5372 if(!prs_uint32("offered", ps, depth, &q_u->offered))
5373 return False;
5375 return True;
5378 /*******************************************************************
5379 Parse a SPOOL_R_GETPRINTERDRIVERDIR structure.
5380 ********************************************************************/
5382 BOOL spoolss_io_r_getprinterdriverdir(char *desc, SPOOL_R_GETPRINTERDRIVERDIR *r_u, prs_struct *ps, int depth)
5384 prs_debug(ps, depth, desc, "spoolss_io_r_getprinterdriverdir");
5385 depth++;
5387 if (!prs_align(ps))
5388 return False;
5390 if (!spoolss_io_buffer("", ps, depth, &r_u->buffer))
5391 return False;
5393 if (!prs_align(ps))
5394 return False;
5396 if (!prs_uint32("needed", ps, depth, &r_u->needed))
5397 return False;
5399 if (!prs_werror("status", ps, depth, &r_u->status))
5400 return False;
5402 return True;
5405 /*******************************************************************
5406 ********************************************************************/
5408 BOOL spoolss_io_r_enumprintprocessors(char *desc, SPOOL_R_ENUMPRINTPROCESSORS *r_u, prs_struct *ps, int depth)
5410 prs_debug(ps, depth, desc, "spoolss_io_r_enumprintprocessors");
5411 depth++;
5413 if (!prs_align(ps))
5414 return False;
5416 if (!spoolss_io_buffer("", ps, depth, &r_u->buffer))
5417 return False;
5419 if (!prs_align(ps))
5420 return False;
5422 if (!prs_uint32("needed", ps, depth, &r_u->needed))
5423 return False;
5425 if (!prs_uint32("returned", ps, depth, &r_u->returned))
5426 return False;
5428 if (!prs_werror("status", ps, depth, &r_u->status))
5429 return False;
5431 return True;
5434 /*******************************************************************
5435 ********************************************************************/
5437 BOOL spoolss_io_q_enumprintprocessors(char *desc, SPOOL_Q_ENUMPRINTPROCESSORS *q_u, prs_struct *ps, int depth)
5439 prs_debug(ps, depth, desc, "spoolss_io_q_enumprintprocessors");
5440 depth++;
5442 if (!prs_align(ps))
5443 return False;
5445 if (!prs_uint32("name_ptr", ps, depth, &q_u->name_ptr))
5446 return False;
5447 if (!smb_io_unistr2("name", &q_u->name, True, ps, depth))
5448 return False;
5450 if (!prs_align(ps))
5451 return False;
5453 if (!prs_uint32("", ps, depth, &q_u->environment_ptr))
5454 return False;
5455 if (!smb_io_unistr2("", &q_u->environment, q_u->environment_ptr, ps, depth))
5456 return False;
5458 if (!prs_align(ps))
5459 return False;
5461 if (!prs_uint32("level", ps, depth, &q_u->level))
5462 return False;
5464 if(!spoolss_io_buffer("", ps, depth, &q_u->buffer))
5465 return False;
5467 if (!prs_align(ps))
5468 return False;
5470 if (!prs_uint32("offered", ps, depth, &q_u->offered))
5471 return False;
5473 return True;
5476 /*******************************************************************
5477 ********************************************************************/
5479 BOOL spoolss_io_q_addprintprocessor(char *desc, SPOOL_Q_ADDPRINTPROCESSOR *q_u, prs_struct *ps, int depth)
5481 prs_debug(ps, depth, desc, "spoolss_io_q_addprintprocessor");
5482 depth++;
5484 if (!prs_align(ps))
5485 return False;
5487 if (!prs_uint32("server_ptr", ps, depth, &q_u->server_ptr))
5488 return False;
5489 if (!smb_io_unistr2("server", &q_u->server, q_u->server_ptr, ps, depth))
5490 return False;
5492 if (!prs_align(ps))
5493 return False;
5494 if (!smb_io_unistr2("environment", &q_u->environment, True, ps, depth))
5495 return False;
5497 if (!prs_align(ps))
5498 return False;
5499 if (!smb_io_unistr2("path", &q_u->path, True, ps, depth))
5500 return False;
5502 if (!prs_align(ps))
5503 return False;
5504 if (!smb_io_unistr2("name", &q_u->name, True, ps, depth))
5505 return False;
5507 return True;
5510 /*******************************************************************
5511 ********************************************************************/
5513 BOOL spoolss_io_r_addprintprocessor(char *desc, SPOOL_R_ADDPRINTPROCESSOR *r_u, prs_struct *ps, int depth)
5515 prs_debug(ps, depth, desc, "spoolss_io_r_addprintproicessor");
5516 depth++;
5518 if (!prs_align(ps))
5519 return False;
5521 if (!prs_werror("status", ps, depth, &r_u->status))
5522 return False;
5524 return True;
5527 /*******************************************************************
5528 ********************************************************************/
5530 BOOL spoolss_io_r_enumprintprocdatatypes(char *desc, SPOOL_R_ENUMPRINTPROCDATATYPES *r_u, prs_struct *ps, int depth)
5532 prs_debug(ps, depth, desc, "spoolss_io_r_enumprintprocdatatypes");
5533 depth++;
5535 if (!prs_align(ps))
5536 return False;
5538 if (!spoolss_io_buffer("", ps, depth, &r_u->buffer))
5539 return False;
5541 if (!prs_align(ps))
5542 return False;
5544 if (!prs_uint32("needed", ps, depth, &r_u->needed))
5545 return False;
5547 if (!prs_uint32("returned", ps, depth, &r_u->returned))
5548 return False;
5550 if (!prs_werror("status", ps, depth, &r_u->status))
5551 return False;
5553 return True;
5556 /*******************************************************************
5557 ********************************************************************/
5559 BOOL spoolss_io_q_enumprintprocdatatypes(char *desc, SPOOL_Q_ENUMPRINTPROCDATATYPES *q_u, prs_struct *ps, int depth)
5561 prs_debug(ps, depth, desc, "spoolss_io_q_enumprintprocdatatypes");
5562 depth++;
5564 if (!prs_align(ps))
5565 return False;
5567 if (!prs_uint32("name_ptr", ps, depth, &q_u->name_ptr))
5568 return False;
5569 if (!smb_io_unistr2("name", &q_u->name, True, ps, depth))
5570 return False;
5572 if (!prs_align(ps))
5573 return False;
5575 if (!prs_uint32("processor_ptr", ps, depth, &q_u->processor_ptr))
5576 return False;
5577 if (!smb_io_unistr2("processor", &q_u->processor, q_u->processor_ptr, ps, depth))
5578 return False;
5580 if (!prs_align(ps))
5581 return False;
5583 if (!prs_uint32("level", ps, depth, &q_u->level))
5584 return False;
5586 if(!spoolss_io_buffer("buffer", ps, depth, &q_u->buffer))
5587 return False;
5589 if (!prs_align(ps))
5590 return False;
5592 if (!prs_uint32("offered", ps, depth, &q_u->offered))
5593 return False;
5595 return True;
5598 /*******************************************************************
5599 Parse a SPOOL_Q_ENUMPRINTMONITORS structure.
5600 ********************************************************************/
5602 BOOL spoolss_io_q_enumprintmonitors(char *desc, SPOOL_Q_ENUMPRINTMONITORS *q_u, prs_struct *ps, int depth)
5604 prs_debug(ps, depth, desc, "spoolss_io_q_enumprintmonitors");
5605 depth++;
5607 if (!prs_align(ps))
5608 return False;
5610 if (!prs_uint32("name_ptr", ps, depth, &q_u->name_ptr))
5611 return False;
5612 if (!smb_io_unistr2("name", &q_u->name, True, ps, depth))
5613 return False;
5615 if (!prs_align(ps))
5616 return False;
5618 if (!prs_uint32("level", ps, depth, &q_u->level))
5619 return False;
5621 if(!spoolss_io_buffer("", ps, depth, &q_u->buffer))
5622 return False;
5624 if (!prs_align(ps))
5625 return False;
5627 if (!prs_uint32("offered", ps, depth, &q_u->offered))
5628 return False;
5630 return True;
5633 /*******************************************************************
5634 ********************************************************************/
5636 BOOL spoolss_io_r_enumprintmonitors(char *desc, SPOOL_R_ENUMPRINTMONITORS *r_u, prs_struct *ps, int depth)
5638 prs_debug(ps, depth, desc, "spoolss_io_r_enumprintmonitors");
5639 depth++;
5641 if (!prs_align(ps))
5642 return False;
5644 if (!spoolss_io_buffer("", ps, depth, &r_u->buffer))
5645 return False;
5647 if (!prs_align(ps))
5648 return False;
5650 if (!prs_uint32("needed", ps, depth, &r_u->needed))
5651 return False;
5653 if (!prs_uint32("returned", ps, depth, &r_u->returned))
5654 return False;
5656 if (!prs_werror("status", ps, depth, &r_u->status))
5657 return False;
5659 return True;
5662 /*******************************************************************
5663 ********************************************************************/
5665 BOOL spoolss_io_r_enumprinterdata(char *desc, SPOOL_R_ENUMPRINTERDATA *r_u, prs_struct *ps, int depth)
5667 prs_debug(ps, depth, desc, "spoolss_io_r_enumprinterdata");
5668 depth++;
5670 if(!prs_align(ps))
5671 return False;
5672 if(!prs_uint32("valuesize", ps, depth, &r_u->valuesize))
5673 return False;
5675 if(!prs_uint16uni(False, "value", ps, depth, r_u->value, r_u->valuesize ))
5676 return False;
5678 if(!prs_align(ps))
5679 return False;
5681 if(!prs_uint32("realvaluesize", ps, depth, &r_u->realvaluesize))
5682 return False;
5684 if(!prs_uint32("type", ps, depth, &r_u->type))
5685 return False;
5687 if(!prs_uint32("datasize", ps, depth, &r_u->datasize))
5688 return False;
5689 if(!prs_uint8s(False, "data", ps, depth, r_u->data, r_u->datasize))
5690 return False;
5691 if(!prs_align(ps))
5692 return False;
5694 if(!prs_uint32("realdatasize", ps, depth, &r_u->realdatasize))
5695 return False;
5696 if(!prs_werror("status", ps, depth, &r_u->status))
5697 return False;
5699 return True;
5702 /*******************************************************************
5703 ********************************************************************/
5705 BOOL spoolss_io_q_enumprinterdata(char *desc, SPOOL_Q_ENUMPRINTERDATA *q_u, prs_struct *ps, int depth)
5707 prs_debug(ps, depth, desc, "spoolss_io_q_enumprinterdata");
5708 depth++;
5710 if(!prs_align(ps))
5711 return False;
5712 if(!smb_io_pol_hnd("printer handle",&q_u->handle,ps,depth))
5713 return False;
5714 if(!prs_uint32("index", ps, depth, &q_u->index))
5715 return False;
5716 if(!prs_uint32("valuesize", ps, depth, &q_u->valuesize))
5717 return False;
5718 if(!prs_uint32("datasize", ps, depth, &q_u->datasize))
5719 return False;
5721 return True;
5724 /*******************************************************************
5725 ********************************************************************/
5727 BOOL make_spoolss_q_enumprinterdata(SPOOL_Q_ENUMPRINTERDATA *q_u,
5728 const POLICY_HND *hnd,
5729 uint32 idx, uint32 valuelen, uint32 datalen)
5731 memcpy(&q_u->handle, hnd, sizeof(q_u->handle));
5732 q_u->index=idx;
5733 q_u->valuesize=valuelen;
5734 q_u->datasize=datalen;
5736 return True;
5739 /*******************************************************************
5740 ********************************************************************/
5741 BOOL make_spoolss_q_setprinterdata(SPOOL_Q_SETPRINTERDATA *q_u, TALLOC_CTX *ctx, const POLICY_HND *hnd,
5742 char* value, char* data)
5744 UNISTR2 tmp;
5746 memcpy(&q_u->handle, hnd, sizeof(q_u->handle));
5747 q_u->type = REG_SZ;
5748 init_unistr2(&q_u->value, value, strlen(value)+1);
5750 init_unistr2(&tmp, data, strlen(data)+1);
5751 q_u->max_len = q_u->real_len = tmp.uni_max_len*2;
5752 q_u->data = talloc(ctx, q_u->real_len);
5753 memcpy(q_u->data, tmp.buffer, q_u->real_len);
5755 return True;
5757 /*******************************************************************
5758 ********************************************************************/
5760 BOOL spoolss_io_q_setprinterdata(char *desc, SPOOL_Q_SETPRINTERDATA *q_u, prs_struct *ps, int depth)
5762 prs_debug(ps, depth, desc, "spoolss_io_q_setprinterdata");
5763 depth++;
5765 if(!prs_align(ps))
5766 return False;
5767 if(!smb_io_pol_hnd("printer handle", &q_u->handle, ps, depth))
5768 return False;
5769 if(!smb_io_unistr2("", &q_u->value, True, ps, depth))
5770 return False;
5772 if(!prs_align(ps))
5773 return False;
5775 if(!prs_uint32("type", ps, depth, &q_u->type))
5776 return False;
5778 if(!prs_uint32("max_len", ps, depth, &q_u->max_len))
5779 return False;
5781 switch (q_u->type)
5783 case REG_SZ:
5784 case REG_BINARY:
5785 case REG_DWORD:
5786 case REG_MULTI_SZ:
5787 if (q_u->max_len) {
5788 if (UNMARSHALLING(ps))
5789 q_u->data=(uint8 *)prs_alloc_mem(ps, q_u->max_len * sizeof(uint8));
5790 if(q_u->data == NULL)
5791 return False;
5792 if(!prs_uint8s(False,"data", ps, depth, q_u->data, q_u->max_len))
5793 return False;
5795 if(!prs_align(ps))
5796 return False;
5797 break;
5800 if(!prs_uint32("real_len", ps, depth, &q_u->real_len))
5801 return False;
5803 return True;
5806 /*******************************************************************
5807 ********************************************************************/
5809 BOOL spoolss_io_r_setprinterdata(char *desc, SPOOL_R_SETPRINTERDATA *r_u, prs_struct *ps, int depth)
5811 prs_debug(ps, depth, desc, "spoolss_io_r_setprinterdata");
5812 depth++;
5814 if(!prs_align(ps))
5815 return False;
5816 if(!prs_werror("status", ps, depth, &r_u->status))
5817 return False;
5819 return True;
5822 /*******************************************************************
5823 ********************************************************************/
5824 BOOL spoolss_io_q_resetprinter(char *desc, SPOOL_Q_RESETPRINTER *q_u, prs_struct *ps, int depth)
5826 prs_debug(ps, depth, desc, "spoolss_io_q_resetprinter");
5827 depth++;
5829 if (!prs_align(ps))
5830 return False;
5831 if (!smb_io_pol_hnd("printer handle", &q_u->handle, ps, depth))
5832 return False;
5834 if (!prs_uint32("datatype_ptr", ps, depth, &q_u->datatype_ptr))
5835 return False;
5837 if (q_u->datatype_ptr) {
5838 if (!smb_io_unistr2("datatype", &q_u->datatype, q_u->datatype_ptr?True:False, ps, depth))
5839 return False;
5842 if (!spoolss_io_devmode_cont(desc, &q_u->devmode_ctr, ps, depth))
5843 return False;
5845 return True;
5849 /*******************************************************************
5850 ********************************************************************/
5851 BOOL spoolss_io_r_resetprinter(char *desc, SPOOL_R_RESETPRINTER *r_u, prs_struct *ps, int depth)
5853 prs_debug(ps, depth, desc, "spoolss_io_r_resetprinter");
5854 depth++;
5856 if(!prs_align(ps))
5857 return False;
5858 if(!prs_werror("status", ps, depth, &r_u->status))
5859 return False;
5861 return True;
5864 /*******************************************************************
5865 ********************************************************************/
5866 BOOL convert_specific_param(NT_PRINTER_PARAM **param, const UNISTR2 *value,
5867 uint32 type, const uint8 *data, uint32 len)
5869 DEBUG(5,("converting a specific param struct\n"));
5871 if (*param == NULL)
5873 *param=(NT_PRINTER_PARAM *)malloc(sizeof(NT_PRINTER_PARAM));
5874 if(*param == NULL)
5875 return False;
5876 memset((char *)*param, '\0', sizeof(NT_PRINTER_PARAM));
5877 DEBUGADD(6,("Allocated a new PARAM struct\n"));
5879 unistr2_to_ascii((*param)->value, value, sizeof((*param)->value)-1);
5880 (*param)->type = type;
5882 /* le champ data n'est pas NULL termine */
5883 /* on stocke donc la longueur */
5885 (*param)->data_len=len;
5887 if (len) {
5888 (*param)->data=(uint8 *)malloc(len * sizeof(uint8));
5889 if((*param)->data == NULL)
5890 return False;
5891 memcpy((*param)->data, data, len);
5894 DEBUGADD(6,("\tvalue:[%s], len:[%d]\n",(*param)->value, (*param)->data_len));
5895 dump_data(10, (char *)(*param)->data, (*param)->data_len);
5897 return True;
5900 /*******************************************************************
5901 ********************************************************************/
5903 static BOOL spoolss_io_addform(char *desc, FORM *f, uint32 ptr, prs_struct *ps, int depth)
5905 prs_debug(ps, depth, desc, "spoolss_io_addform");
5906 depth++;
5907 if(!prs_align(ps))
5908 return False;
5910 if (ptr!=0)
5912 if(!prs_uint32("flags", ps, depth, &f->flags))
5913 return False;
5914 if(!prs_uint32("name_ptr", ps, depth, &f->name_ptr))
5915 return False;
5916 if(!prs_uint32("size_x", ps, depth, &f->size_x))
5917 return False;
5918 if(!prs_uint32("size_y", ps, depth, &f->size_y))
5919 return False;
5920 if(!prs_uint32("left", ps, depth, &f->left))
5921 return False;
5922 if(!prs_uint32("top", ps, depth, &f->top))
5923 return False;
5924 if(!prs_uint32("right", ps, depth, &f->right))
5925 return False;
5926 if(!prs_uint32("bottom", ps, depth, &f->bottom))
5927 return False;
5929 if(!smb_io_unistr2("", &f->name, f->name_ptr, ps, depth))
5930 return False;
5933 return True;
5936 /*******************************************************************
5937 ********************************************************************/
5939 BOOL spoolss_io_q_deleteform(char *desc, SPOOL_Q_DELETEFORM *q_u, prs_struct *ps, int depth)
5941 prs_debug(ps, depth, desc, "spoolss_io_q_deleteform");
5942 depth++;
5944 if(!prs_align(ps))
5945 return False;
5946 if(!smb_io_pol_hnd("printer handle", &q_u->handle, ps, depth))
5947 return False;
5948 if(!smb_io_unistr2("form name", &q_u->name, True, ps, depth))
5949 return False;
5951 return True;
5954 /*******************************************************************
5955 ********************************************************************/
5957 BOOL spoolss_io_r_deleteform(char *desc, SPOOL_R_DELETEFORM *r_u, prs_struct *ps, int depth)
5959 prs_debug(ps, depth, desc, "spoolss_io_r_deleteform");
5960 depth++;
5962 if(!prs_align(ps))
5963 return False;
5964 if(!prs_werror("status", ps, depth, &r_u->status))
5965 return False;
5967 return True;
5970 /*******************************************************************
5971 ********************************************************************/
5973 BOOL spoolss_io_q_addform(char *desc, SPOOL_Q_ADDFORM *q_u, prs_struct *ps, int depth)
5975 uint32 useless_ptr=1;
5976 prs_debug(ps, depth, desc, "spoolss_io_q_addform");
5977 depth++;
5979 if(!prs_align(ps))
5980 return False;
5981 if(!smb_io_pol_hnd("printer handle", &q_u->handle, ps, depth))
5982 return False;
5983 if(!prs_uint32("level", ps, depth, &q_u->level))
5984 return False;
5985 if(!prs_uint32("level2", ps, depth, &q_u->level2))
5986 return False;
5988 if (q_u->level==1)
5990 if(!prs_uint32("useless_ptr", ps, depth, &useless_ptr))
5991 return False;
5992 if(!spoolss_io_addform("", &q_u->form, useless_ptr, ps, depth))
5993 return False;
5996 return True;
5999 /*******************************************************************
6000 ********************************************************************/
6002 BOOL spoolss_io_r_addform(char *desc, SPOOL_R_ADDFORM *r_u, prs_struct *ps, int depth)
6004 prs_debug(ps, depth, desc, "spoolss_io_r_addform");
6005 depth++;
6007 if(!prs_align(ps))
6008 return False;
6009 if(!prs_werror("status", ps, depth, &r_u->status))
6010 return False;
6012 return True;
6015 /*******************************************************************
6016 ********************************************************************/
6018 BOOL spoolss_io_q_setform(char *desc, SPOOL_Q_SETFORM *q_u, prs_struct *ps, int depth)
6020 uint32 useless_ptr=1;
6021 prs_debug(ps, depth, desc, "spoolss_io_q_setform");
6022 depth++;
6024 if(!prs_align(ps))
6025 return False;
6026 if(!smb_io_pol_hnd("printer handle", &q_u->handle, ps, depth))
6027 return False;
6028 if(!smb_io_unistr2("", &q_u->name, True, ps, depth))
6029 return False;
6031 if(!prs_align(ps))
6032 return False;
6034 if(!prs_uint32("level", ps, depth, &q_u->level))
6035 return False;
6036 if(!prs_uint32("level2", ps, depth, &q_u->level2))
6037 return False;
6039 if (q_u->level==1)
6041 if(!prs_uint32("useless_ptr", ps, depth, &useless_ptr))
6042 return False;
6043 if(!spoolss_io_addform("", &q_u->form, useless_ptr, ps, depth))
6044 return False;
6047 return True;
6050 /*******************************************************************
6051 ********************************************************************/
6053 BOOL spoolss_io_r_setform(char *desc, SPOOL_R_SETFORM *r_u, prs_struct *ps, int depth)
6055 prs_debug(ps, depth, desc, "spoolss_io_r_setform");
6056 depth++;
6058 if(!prs_align(ps))
6059 return False;
6060 if(!prs_werror("status", ps, depth, &r_u->status))
6061 return False;
6063 return True;
6066 /*******************************************************************
6067 Parse a SPOOL_R_GETJOB structure.
6068 ********************************************************************/
6070 BOOL spoolss_io_r_getjob(char *desc, SPOOL_R_GETJOB *r_u, prs_struct *ps, int depth)
6072 prs_debug(ps, depth, desc, "spoolss_io_r_getjob");
6073 depth++;
6075 if (!prs_align(ps))
6076 return False;
6078 if (!spoolss_io_buffer("", ps, depth, &r_u->buffer))
6079 return False;
6081 if (!prs_align(ps))
6082 return False;
6084 if (!prs_uint32("needed", ps, depth, &r_u->needed))
6085 return False;
6087 if (!prs_werror("status", ps, depth, &r_u->status))
6088 return False;
6090 return True;
6093 /*******************************************************************
6094 Parse a SPOOL_Q_GETJOB structure.
6095 ********************************************************************/
6097 BOOL spoolss_io_q_getjob(char *desc, SPOOL_Q_GETJOB *q_u, prs_struct *ps, int depth)
6099 prs_debug(ps, depth, desc, "");
6100 depth++;
6102 if(!prs_align(ps))
6103 return False;
6105 if(!smb_io_pol_hnd("printer handle",&q_u->handle,ps,depth))
6106 return False;
6107 if(!prs_uint32("jobid", ps, depth, &q_u->jobid))
6108 return False;
6109 if(!prs_uint32("level", ps, depth, &q_u->level))
6110 return False;
6112 if(!spoolss_io_buffer("", ps, depth, &q_u->buffer))
6113 return False;
6115 if(!prs_align(ps))
6116 return False;
6118 if(!prs_uint32("offered", ps, depth, &q_u->offered))
6119 return False;
6121 return True;
6124 void free_devmode(DEVICEMODE *devmode)
6126 if (devmode!=NULL) {
6127 SAFE_FREE(devmode->private);
6128 SAFE_FREE(devmode);
6132 void free_printer_info_1(PRINTER_INFO_1 *printer)
6134 SAFE_FREE(printer);
6137 void free_printer_info_2(PRINTER_INFO_2 *printer)
6139 if (printer!=NULL) {
6140 free_devmode(printer->devmode);
6141 printer->devmode = NULL;
6142 SAFE_FREE(printer);
6146 void free_printer_info_3(PRINTER_INFO_3 *printer)
6148 SAFE_FREE(printer);
6151 void free_printer_info_4(PRINTER_INFO_4 *printer)
6153 SAFE_FREE(printer);
6156 void free_printer_info_5(PRINTER_INFO_5 *printer)
6158 SAFE_FREE(printer);
6161 void free_job_info_2(JOB_INFO_2 *job)
6163 if (job!=NULL)
6164 free_devmode(job->devmode);
6167 /*******************************************************************
6168 * init a structure.
6169 ********************************************************************/
6171 BOOL make_spoolss_q_replyopenprinter(SPOOL_Q_REPLYOPENPRINTER *q_u,
6172 const fstring string, uint32 printer, uint32 type)
6174 if (q_u == NULL)
6175 return False;
6177 init_unistr2(&q_u->string, string, strlen(string)+1);
6179 q_u->printer=printer;
6180 q_u->type=type;
6182 q_u->unknown0=0x0;
6183 q_u->unknown1=0x0;
6185 return True;
6188 /*******************************************************************
6189 Parse a SPOOL_Q_REPLYOPENPRINTER structure.
6190 ********************************************************************/
6192 BOOL spoolss_io_q_replyopenprinter(char *desc, SPOOL_Q_REPLYOPENPRINTER *q_u, prs_struct *ps, int depth)
6194 prs_debug(ps, depth, desc, "spoolss_io_q_replyopenprinter");
6195 depth++;
6197 if(!prs_align(ps))
6198 return False;
6200 if(!smb_io_unistr2("", &q_u->string, True, ps, depth))
6201 return False;
6203 if(!prs_align(ps))
6204 return False;
6206 if(!prs_uint32("printer", ps, depth, &q_u->printer))
6207 return False;
6208 if(!prs_uint32("type", ps, depth, &q_u->type))
6209 return False;
6211 if(!prs_uint32("unknown0", ps, depth, &q_u->unknown0))
6212 return False;
6213 if(!prs_uint32("unknown1", ps, depth, &q_u->unknown1))
6214 return False;
6216 return True;
6219 /*******************************************************************
6220 Parse a SPOOL_R_REPLYOPENPRINTER structure.
6221 ********************************************************************/
6223 BOOL spoolss_io_r_replyopenprinter(char *desc, SPOOL_R_REPLYOPENPRINTER *r_u, prs_struct *ps, int depth)
6225 prs_debug(ps, depth, desc, "spoolss_io_r_replyopenprinter");
6226 depth++;
6228 if (!prs_align(ps))
6229 return False;
6231 if(!smb_io_pol_hnd("printer handle",&r_u->handle,ps,depth))
6232 return False;
6234 if (!prs_werror("status", ps, depth, &r_u->status))
6235 return False;
6237 return True;
6240 /*******************************************************************
6241 * init a structure.
6242 ********************************************************************/
6243 BOOL make_spoolss_q_routerreplyprinter(SPOOL_Q_ROUTERREPLYPRINTER *q_u, POLICY_HND *hnd,
6244 uint32 condition, uint32 change_id)
6247 memcpy(&q_u->handle, hnd, sizeof(q_u->handle));
6249 q_u->condition = condition;
6250 q_u->change_id = change_id;
6252 /* magic values */
6253 q_u->unknown1 = 0x1;
6254 memset(q_u->unknown2, 0x0, 5);
6255 q_u->unknown2[0] = 0x1;
6257 return True;
6260 /*******************************************************************
6261 Parse a SPOOL_Q_ROUTERREPLYPRINTER structure.
6262 ********************************************************************/
6263 BOOL spoolss_io_q_routerreplyprinter (char *desc, SPOOL_Q_ROUTERREPLYPRINTER *q_u, prs_struct *ps, int depth)
6266 prs_debug(ps, depth, desc, "spoolss_io_q_routerreplyprinter");
6267 depth++;
6269 if (!prs_align(ps))
6270 return False;
6272 if(!smb_io_pol_hnd("printer handle",&q_u->handle,ps,depth))
6273 return False;
6275 if (!prs_uint32("condition", ps, depth, &q_u->condition))
6276 return False;
6278 if (!prs_uint32("unknown1", ps, depth, &q_u->unknown1))
6279 return False;
6281 if (!prs_uint32("change_id", ps, depth, &q_u->change_id))
6282 return False;
6284 if (!prs_uint8s(False, "private", ps, depth, q_u->unknown2, 5))
6285 return False;
6287 return True;
6290 /*******************************************************************
6291 Parse a SPOOL_R_ROUTERREPLYPRINTER structure.
6292 ********************************************************************/
6293 BOOL spoolss_io_r_routerreplyprinter (char *desc, SPOOL_R_ROUTERREPLYPRINTER *r_u, prs_struct *ps, int depth)
6295 prs_debug(ps, depth, desc, "spoolss_io_r_routerreplyprinter");
6296 depth++;
6298 if (!prs_align(ps))
6299 return False;
6301 if (!prs_werror("status", ps, depth, &r_u->status))
6302 return False;
6304 return True;
6307 /*******************************************************************
6308 * init a structure.
6309 ********************************************************************/
6311 BOOL make_spoolss_q_reply_closeprinter(SPOOL_Q_REPLYCLOSEPRINTER *q_u, POLICY_HND *hnd)
6313 if (q_u == NULL)
6314 return False;
6316 memcpy(&q_u->handle, hnd, sizeof(q_u->handle));
6318 return True;
6321 /*******************************************************************
6322 Parse a SPOOL_Q_REPLYCLOSEPRINTER structure.
6323 ********************************************************************/
6325 BOOL spoolss_io_q_replycloseprinter(char *desc, SPOOL_Q_REPLYCLOSEPRINTER *q_u, prs_struct *ps, int depth)
6327 prs_debug(ps, depth, desc, "spoolss_io_q_replycloseprinter");
6328 depth++;
6330 if(!prs_align(ps))
6331 return False;
6333 if(!smb_io_pol_hnd("printer handle",&q_u->handle,ps,depth))
6334 return False;
6336 return True;
6339 /*******************************************************************
6340 Parse a SPOOL_R_REPLYCLOSEPRINTER structure.
6341 ********************************************************************/
6343 BOOL spoolss_io_r_replycloseprinter(char *desc, SPOOL_R_REPLYCLOSEPRINTER *r_u, prs_struct *ps, int depth)
6345 prs_debug(ps, depth, desc, "spoolss_io_r_replycloseprinter");
6346 depth++;
6348 if (!prs_align(ps))
6349 return False;
6351 if(!smb_io_pol_hnd("printer handle",&r_u->handle,ps,depth))
6352 return False;
6354 if (!prs_werror("status", ps, depth, &r_u->status))
6355 return False;
6357 return True;
6360 #if 0 /* JERRY - not currently used but could be :-) */
6362 /*******************************************************************
6363 Deep copy a SPOOL_NOTIFY_INFO_DATA structure
6364 ******************************************************************/
6365 static BOOL copy_spool_notify_info_data(SPOOL_NOTIFY_INFO_DATA *dst,
6366 SPOOL_NOTIFY_INFO_DATA *src, int n)
6368 int i;
6370 memcpy(dst, src, sizeof(SPOOL_NOTIFY_INFO_DATA)*n);
6372 for (i=0; i<n; i++) {
6373 int len;
6374 uint16 *s = NULL;
6376 if (src->size != POINTER)
6377 continue;
6378 len = src->notify_data.data.length;
6379 s = malloc(sizeof(uint16)*len);
6380 if (s == NULL) {
6381 DEBUG(0,("copy_spool_notify_info_data: malloc() failed!\n"));
6382 return False;
6385 memcpy(s, src->notify_data.data.string, len*2);
6386 dst->notify_data.data.string = s;
6389 return True;
6392 /*******************************************************************
6393 Deep copy a SPOOL_NOTIFY_INFO structure
6394 ******************************************************************/
6395 static BOOL copy_spool_notify_info(SPOOL_NOTIFY_INFO *dst, SPOOL_NOTIFY_INFO *src)
6397 if (!dst) {
6398 DEBUG(0,("copy_spool_notify_info: NULL destination pointer!\n"));
6399 return False;
6402 dst->version = src->version;
6403 dst->flags = src->flags;
6404 dst->count = src->count;
6406 if (dst->count)
6408 dst->data = malloc(dst->count * sizeof(SPOOL_NOTIFY_INFO_DATA));
6410 DEBUG(10,("copy_spool_notify_info: allocating space for [%d] PRINTER_NOTIFY_INFO_DATA entries\n",
6411 dst->count));
6413 if (dst->data == NULL) {
6414 DEBUG(0,("copy_spool_notify_info: malloc() failed for [%d] entries!\n",
6415 dst->count));
6416 return False;
6419 return (copy_spool_notify_info_data(dst->data, src->data, src->count));
6422 return True;
6424 #endif /* JERRY */
6426 /*******************************************************************
6427 * init a structure.
6428 ********************************************************************/
6430 BOOL make_spoolss_q_reply_rrpcn(SPOOL_Q_REPLY_RRPCN *q_u, POLICY_HND *hnd,
6431 uint32 change_low, uint32 change_high,
6432 SPOOL_NOTIFY_INFO *info)
6434 if (q_u == NULL)
6435 return False;
6437 memcpy(&q_u->handle, hnd, sizeof(q_u->handle));
6439 q_u->change_low=change_low;
6440 q_u->change_high=change_high;
6442 q_u->unknown0=0x0;
6443 q_u->unknown1=0x0;
6445 q_u->info_ptr=0xaddee11e;
6447 q_u->info.version=2;
6449 if (info->count) {
6450 DEBUG(10,("make_spoolss_q_reply_rrpcn: [%d] PRINTER_NOTIFY_INFO_DATA\n",
6451 info->count));
6452 q_u->info.version = info->version;
6453 q_u->info.flags = info->flags;
6454 q_u->info.count = info->count;
6455 /* pointer field - be careful! */
6456 q_u->info.data = info->data;
6458 else {
6459 q_u->info.flags=PRINTER_NOTIFY_INFO_DISCARDED;
6460 q_u->info.count=0;
6463 return True;
6466 /*******************************************************************
6467 Parse a SPOOL_Q_REPLY_RRPCN structure.
6468 ********************************************************************/
6470 BOOL spoolss_io_q_reply_rrpcn(char *desc, SPOOL_Q_REPLY_RRPCN *q_u, prs_struct *ps, int depth)
6472 prs_debug(ps, depth, desc, "spoolss_io_q_reply_rrpcn");
6473 depth++;
6475 if(!prs_align(ps))
6476 return False;
6478 if(!smb_io_pol_hnd("printer handle",&q_u->handle,ps,depth))
6479 return False;
6481 if (!prs_uint32("change_low", ps, depth, &q_u->change_low))
6482 return False;
6484 if (!prs_uint32("change_high", ps, depth, &q_u->change_high))
6485 return False;
6487 if (!prs_uint32("unknown0", ps, depth, &q_u->unknown0))
6488 return False;
6490 if (!prs_uint32("unknown1", ps, depth, &q_u->unknown1))
6491 return False;
6493 if (!prs_uint32("info_ptr", ps, depth, &q_u->info_ptr))
6494 return False;
6496 if(q_u->info_ptr!=0)
6497 if(!smb_io_notify_info(desc, &q_u->info, ps, depth))
6498 return False;
6500 return True;
6503 /*******************************************************************
6504 Parse a SPOOL_R_REPLY_RRPCN structure.
6505 ********************************************************************/
6507 BOOL spoolss_io_r_reply_rrpcn(char *desc, SPOOL_R_REPLY_RRPCN *r_u, prs_struct *ps, int depth)
6509 prs_debug(ps, depth, desc, "spoolss_io_r_reply_rrpcn");
6510 depth++;
6512 if (!prs_align(ps))
6513 return False;
6515 if (!prs_uint32("unknown0", ps, depth, &r_u->unknown0))
6516 return False;
6518 if (!prs_werror("status", ps, depth, &r_u->status))
6519 return False;
6521 return True;
6524 /*******************************************************************
6525 * read a structure.
6526 * called from spoolss_q_getprinterdataex (srv_spoolss.c)
6527 ********************************************************************/
6529 BOOL spoolss_io_q_getprinterdataex(char *desc, SPOOL_Q_GETPRINTERDATAEX *q_u, prs_struct *ps, int depth)
6531 if (q_u == NULL)
6532 return False;
6534 prs_debug(ps, depth, desc, "spoolss_io_q_getprinterdataex");
6535 depth++;
6537 if (!prs_align(ps))
6538 return False;
6539 if (!smb_io_pol_hnd("printer handle",&q_u->handle,ps,depth))
6540 return False;
6541 if (!prs_align(ps))
6542 return False;
6543 if (!smb_io_unistr2("keyname", &q_u->keyname,True,ps,depth))
6544 return False;
6545 if (!prs_align(ps))
6546 return False;
6547 if (!smb_io_unistr2("valuename", &q_u->valuename,True,ps,depth))
6548 return False;
6549 if (!prs_align(ps))
6550 return False;
6551 if (!prs_uint32("size", ps, depth, &q_u->size))
6552 return False;
6554 return True;
6557 /*******************************************************************
6558 * write a structure.
6559 * called from spoolss_r_getprinterdataex (srv_spoolss.c)
6560 ********************************************************************/
6562 BOOL spoolss_io_r_getprinterdataex(char *desc, SPOOL_R_GETPRINTERDATAEX *r_u, prs_struct *ps, int depth)
6564 if (r_u == NULL)
6565 return False;
6567 prs_debug(ps, depth, desc, "spoolss_io_r_getprinterdataex");
6568 depth++;
6570 if (!prs_align(ps))
6571 return False;
6572 if (!prs_uint32("type", ps, depth, &r_u->type))
6573 return False;
6574 if (!prs_uint32("size", ps, depth, &r_u->size))
6575 return False;
6577 if (!prs_uint8s(False,"data", ps, depth, r_u->data, r_u->size))
6578 return False;
6580 if (!prs_align(ps))
6581 return False;
6583 if (!prs_uint32("needed", ps, depth, &r_u->needed))
6584 return False;
6585 if (!prs_werror("status", ps, depth, &r_u->status))
6586 return False;
6588 return True;
6591 /*******************************************************************
6592 * read a structure.
6593 ********************************************************************/
6595 BOOL spoolss_io_q_setprinterdataex(char *desc, SPOOL_Q_SETPRINTERDATAEX *q_u, prs_struct *ps, int depth)
6597 prs_debug(ps, depth, desc, "spoolss_io_q_setprinterdataex");
6598 depth++;
6600 if(!prs_align(ps))
6601 return False;
6602 if(!smb_io_pol_hnd("printer handle", &q_u->handle, ps, depth))
6603 return False;
6604 if(!smb_io_unistr2("", &q_u->key, True, ps, depth))
6605 return False;
6607 if(!prs_align(ps))
6608 return False;
6610 if(!smb_io_unistr2("", &q_u->value, True, ps, depth))
6611 return False;
6613 if(!prs_align(ps))
6614 return False;
6616 if(!prs_uint32("type", ps, depth, &q_u->type))
6617 return False;
6619 if(!prs_uint32("max_len", ps, depth, &q_u->max_len))
6620 return False;
6622 switch (q_u->type)
6624 case 0x1:
6625 case 0x3:
6626 case 0x4:
6627 case 0x7:
6628 if (q_u->max_len) {
6629 if (UNMARSHALLING(ps))
6630 q_u->data=(uint8 *)prs_alloc_mem(ps, q_u->max_len * sizeof(uint8));
6631 if(q_u->data == NULL)
6632 return False;
6633 if(!prs_uint8s(False,"data", ps, depth, q_u->data, q_u->max_len))
6634 return False;
6636 if(!prs_align(ps))
6637 return False;
6638 break;
6641 if(!prs_uint32("real_len", ps, depth, &q_u->real_len))
6642 return False;
6644 return True;
6647 /*******************************************************************
6648 * write a structure.
6649 ********************************************************************/
6651 BOOL spoolss_io_r_setprinterdataex(char *desc, SPOOL_R_SETPRINTERDATAEX *r_u, prs_struct *ps, int depth)
6653 prs_debug(ps, depth, desc, "spoolss_io_r_setprinterdataex");
6654 depth++;
6656 if(!prs_align(ps))
6657 return False;
6658 if(!prs_werror("status", ps, depth, &r_u->status))
6659 return False;
6661 return True;
6665 /*******************************************************************
6666 * read a structure.
6667 ********************************************************************/
6669 BOOL spoolss_io_q_enumprinterkey(char *desc, SPOOL_Q_ENUMPRINTERKEY *q_u, prs_struct *ps, int depth)
6671 prs_debug(ps, depth, desc, "spoolss_io_q_enumprinterkey");
6672 depth++;
6674 if(!prs_align(ps))
6675 return False;
6676 if(!smb_io_pol_hnd("printer handle", &q_u->handle, ps, depth))
6677 return False;
6679 if(!smb_io_unistr2("", &q_u->key, True, ps, depth))
6680 return False;
6682 if(!prs_align(ps))
6683 return False;
6685 if(!prs_uint32("size", ps, depth, &q_u->size))
6686 return False;
6688 return True;
6691 /*******************************************************************
6692 * write a structure.
6693 ********************************************************************/
6695 BOOL spoolss_io_r_enumprinterkey(char *desc, SPOOL_R_ENUMPRINTERKEY *r_u, prs_struct *ps, int depth)
6697 prs_debug(ps, depth, desc, "spoolss_io_r_enumprinterkey");
6698 depth++;
6700 if(!prs_align(ps))
6701 return False;
6703 if (!smb_io_buffer5("", &r_u->keys, ps, depth))
6704 return False;
6706 if(!prs_align(ps))
6707 return False;
6709 if(!prs_uint32("needed", ps, depth, &r_u->needed))
6710 return False;
6712 if(!prs_werror("status", ps, depth, &r_u->status))
6713 return False;
6715 return True;
6719 /*******************************************************************
6720 * read a structure.
6721 ********************************************************************/
6723 BOOL spoolss_io_q_enumprinterdataex(char *desc, SPOOL_Q_ENUMPRINTERDATAEX *q_u, prs_struct *ps, int depth)
6725 prs_debug(ps, depth, desc, "spoolss_io_q_enumprinterdataex");
6726 depth++;
6728 if(!prs_align(ps))
6729 return False;
6730 if(!smb_io_pol_hnd("printer handle", &q_u->handle, ps, depth))
6731 return False;
6733 if(!smb_io_unistr2("", &q_u->key, True, ps, depth))
6734 return False;
6736 if(!prs_align(ps))
6737 return False;
6739 if(!prs_uint32("size", ps, depth, &q_u->size))
6740 return False;
6742 return True;
6745 /*******************************************************************
6746 ********************************************************************/
6747 static BOOL spoolss_io_printer_enum_values_ctr(char *desc, prs_struct *ps,
6748 PRINTER_ENUM_VALUES_CTR *ctr, int depth)
6750 int i;
6751 uint32 valuename_offset,
6752 data_offset,
6753 current_offset;
6754 const uint32 basic_unit = 20; /* size of static portion of enum_values */
6756 prs_debug(ps, depth, desc, "spoolss_io_printer_enum_values_ctr");
6757 depth++;
6759 if (!prs_uint32("size", ps, depth, &ctr->size))
6760 return False;
6762 /* offset data begins at 20 bytes per structure * size_of_array.
6763 Don't forget the uint32 at the beginning */
6765 current_offset = basic_unit * ctr->size_of_array;
6767 /* first loop to write basic enum_value information */
6769 for (i=0; i<ctr->size_of_array; i++)
6771 valuename_offset = current_offset;
6772 if (!prs_uint32("valuename_offset", ps, depth, &valuename_offset))
6773 return False;
6775 if (!prs_uint32("value_len", ps, depth, &ctr->values[i].value_len))
6776 return False;
6778 if (!prs_uint32("type", ps, depth, &ctr->values[i].type))
6779 return False;
6781 data_offset = ctr->values[i].value_len + valuename_offset;
6782 if (!prs_uint32("data_offset", ps, depth, &data_offset))
6783 return False;
6785 if (!prs_uint32("data_len", ps, depth, &ctr->values[i].data_len))
6786 return False;
6788 current_offset = data_offset + ctr->values[i].data_len - basic_unit;
6791 /* loop #2 for writing the dynamically size objects
6792 while viewing conversations between Win2k -> Win2k,
6793 4-byte alignment does not seem to matter here --jerry */
6795 for (i=0; i<ctr->size_of_array; i++)
6798 if (!prs_unistr("valuename", ps, depth, &ctr->values[i].valuename))
6799 return False;
6801 if (!prs_uint8s(False, "data", ps, depth, ctr->values[i].data, ctr->values[i].data_len))
6802 return False;
6807 return True;
6811 /*******************************************************************
6812 * write a structure.
6813 ********************************************************************/
6815 BOOL spoolss_io_r_enumprinterdataex(char *desc, SPOOL_R_ENUMPRINTERDATAEX *r_u, prs_struct *ps, int depth)
6817 prs_debug(ps, depth, desc, "spoolss_io_r_enumprinterdataex");
6818 depth++;
6820 if(!prs_align(ps))
6821 return False;
6823 if (!spoolss_io_printer_enum_values_ctr("", ps, &r_u->ctr, depth ))
6824 return False;
6826 if(!prs_align(ps))
6827 return False;
6829 if(!prs_uint32("needed", ps, depth, &r_u->needed))
6830 return False;
6832 if(!prs_uint32("returned", ps, depth, &r_u->returned))
6833 return False;
6835 if(!prs_werror("status", ps, depth, &r_u->status))
6836 return False;
6838 return True;
6842 /*******************************************************************
6843 * write a structure.
6844 ********************************************************************/
6847 uint32 GetPrintProcessorDirectory(
6848 [in] unistr2 *name,
6849 [in] unistr2 *environment,
6850 [in] uint32 level,
6851 [in,out] NEW_BUFFER buffer,
6852 [in] uint32 offered,
6853 [out] uint32 needed,
6854 [out] uint32 returned
6859 BOOL make_spoolss_q_getprintprocessordirectory(SPOOL_Q_GETPRINTPROCESSORDIRECTORY *q_u, const char *name, char *environment, int level, NEW_BUFFER *buffer, uint32 offered)
6861 DEBUG(5,("make_spoolss_q_getprintprocessordirectory\n"));
6863 init_unistr2(&q_u->name, name, strlen(name)+1);
6864 init_unistr2(&q_u->environment, environment, strlen(environment)+1);
6866 q_u->level = level;
6868 q_u->buffer = buffer;
6869 q_u->offered = offered;
6871 return True;
6874 BOOL spoolss_io_q_getprintprocessordirectory(char *desc, SPOOL_Q_GETPRINTPROCESSORDIRECTORY *q_u, prs_struct *ps, int depth)
6876 uint32 ptr;
6878 prs_debug(ps, depth, desc, "spoolss_io_q_getprintprocessordirectory");
6879 depth++;
6881 if(!prs_align(ps))
6882 return False;
6884 if (!prs_uint32("ptr", ps, depth, &ptr))
6885 return False;
6887 if (ptr) {
6888 if(!smb_io_unistr2("name", &q_u->name, True, ps, depth))
6889 return False;
6892 if (!prs_align(ps))
6893 return False;
6895 if (!prs_uint32("ptr", ps, depth, &ptr))
6896 return False;
6898 if (ptr) {
6899 if(!smb_io_unistr2("environment", &q_u->environment, True,
6900 ps, depth))
6901 return False;
6904 if (!prs_align(ps))
6905 return False;
6907 if(!prs_uint32("level", ps, depth, &q_u->level))
6908 return False;
6910 if(!spoolss_io_buffer("", ps, depth, &q_u->buffer))
6911 return False;
6913 if(!prs_align(ps))
6914 return False;
6916 if(!prs_uint32("offered", ps, depth, &q_u->offered))
6917 return False;
6919 return True;
6922 /*******************************************************************
6923 * write a structure.
6924 ********************************************************************/
6926 BOOL spoolss_io_r_getprintprocessordirectory(char *desc, SPOOL_R_GETPRINTPROCESSORDIRECTORY *r_u, prs_struct *ps, int depth)
6928 prs_debug(ps, depth, desc, "spoolss_io_r_getprintprocessordirectory");
6929 depth++;
6931 if(!prs_align(ps))
6932 return False;
6934 if(!spoolss_io_buffer("", ps, depth, &r_u->buffer))
6935 return False;
6937 if(!prs_align(ps))
6938 return False;
6940 if(!prs_uint32("needed", ps, depth, &r_u->needed))
6941 return False;
6943 if(!prs_werror("status", ps, depth, &r_u->status))
6944 return False;
6946 return True;
6949 BOOL smb_io_printprocessordirectory_1(char *desc, NEW_BUFFER *buffer, PRINTPROCESSOR_DIRECTORY_1 *info, int depth)
6951 prs_struct *ps=&buffer->prs;
6953 prs_debug(ps, depth, desc, "smb_io_printprocessordirectory_1");
6954 depth++;
6956 buffer->struct_start=prs_offset(ps);
6958 if (!smb_io_unistr(desc, &info->name, ps, depth))
6959 return False;
6961 return True;
6964 /*******************************************************************
6965 * init a structure.
6966 ********************************************************************/
6968 BOOL make_spoolss_q_addform(SPOOL_Q_ADDFORM *q_u, POLICY_HND *handle,
6969 int level, FORM *form)
6971 memcpy(&q_u->handle, handle, sizeof(POLICY_HND));
6972 q_u->level = level;
6973 q_u->level2 = level;
6974 memcpy(&q_u->form, form, sizeof(FORM));
6976 return True;
6979 /*******************************************************************
6980 * init a structure.
6981 ********************************************************************/
6983 BOOL make_spoolss_q_setform(SPOOL_Q_SETFORM *q_u, POLICY_HND *handle,
6984 int level, char *form_name, FORM *form)
6986 memcpy(&q_u->handle, handle, sizeof(POLICY_HND));
6987 q_u->level = level;
6988 q_u->level2 = level;
6989 memcpy(&q_u->form, form, sizeof(FORM));
6990 init_unistr2(&q_u->name, form_name, strlen(form_name) + 1);
6992 return True;
6995 /*******************************************************************
6996 * init a structure.
6997 ********************************************************************/
6999 BOOL make_spoolss_q_deleteform(SPOOL_Q_DELETEFORM *q_u, POLICY_HND *handle, char *form)
7001 memcpy(&q_u->handle, handle, sizeof(POLICY_HND));
7002 init_unistr2(&q_u->name, form, strlen(form) + 1);
7003 return True;
7006 /*******************************************************************
7007 * init a structure.
7008 ********************************************************************/
7010 BOOL make_spoolss_q_getform(SPOOL_Q_GETFORM *q_u, POLICY_HND *handle,
7011 char *formname, uint32 level, NEW_BUFFER *buffer,
7012 uint32 offered)
7014 memcpy(&q_u->handle, handle, sizeof(POLICY_HND));
7015 q_u->level = level;
7016 init_unistr2(&q_u->formname, formname, strlen(formname) + 1);
7017 q_u->buffer=buffer;
7018 q_u->offered=offered;
7020 return True;
7023 /*******************************************************************
7024 * init a structure.
7025 ********************************************************************/
7027 BOOL make_spoolss_q_enumforms(SPOOL_Q_ENUMFORMS *q_u, POLICY_HND *handle,
7028 uint32 level, NEW_BUFFER *buffer,
7029 uint32 offered)
7031 memcpy(&q_u->handle, handle, sizeof(POLICY_HND));
7032 q_u->level = level;
7033 q_u->buffer=buffer;
7034 q_u->offered=offered;
7036 return True;