r585: merge of fix for KB828741 -- pw chg -- from 3.0
[Samba.git] / source / rpc_parse / parse_spoolss.c
blob3700b2fded91f7eb78e40d43118308f8c2f21023
1 /*
2 * Unix SMB/CIFS implementation.
3 * RPC Pipe client / server routines
4 * Copyright (C) Andrew Tridgell 1992-2000,
5 * Copyright (C) Luke Kenneth Casson Leighton 1996-2000,
6 * Copyright (C) Jean François Micouleau 1998-2000,
7 * Copyright (C) Gerald Carter 2000-2002,
8 * Copyright (C) Tim Potter 2001-2002.
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation; either version 2 of the License, or
13 * (at your option) any later version.
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
20 * You should have received a copy of the GNU General Public License
21 * along with this program; if not, write to the Free Software
22 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
25 #include "includes.h"
27 /*******************************************************************
28 return the length of a UNISTR string.
29 ********************************************************************/
31 static uint32 str_len_uni(UNISTR *source)
33 uint32 i=0;
35 if (!source->buffer)
36 return 0;
38 while (source->buffer[i])
39 i++;
41 return i;
44 /*******************************************************************
45 This should be moved in a more generic lib.
46 ********************************************************************/
48 static BOOL spoolss_io_system_time(const char *desc, prs_struct *ps, int depth, SYSTEMTIME *systime)
50 if(!prs_uint16("year", ps, depth, &systime->year))
51 return False;
52 if(!prs_uint16("month", ps, depth, &systime->month))
53 return False;
54 if(!prs_uint16("dayofweek", ps, depth, &systime->dayofweek))
55 return False;
56 if(!prs_uint16("day", ps, depth, &systime->day))
57 return False;
58 if(!prs_uint16("hour", ps, depth, &systime->hour))
59 return False;
60 if(!prs_uint16("minute", ps, depth, &systime->minute))
61 return False;
62 if(!prs_uint16("second", ps, depth, &systime->second))
63 return False;
64 if(!prs_uint16("milliseconds", ps, depth, &systime->milliseconds))
65 return False;
67 return True;
70 /*******************************************************************
71 ********************************************************************/
73 BOOL make_systemtime(SYSTEMTIME *systime, struct tm *unixtime)
75 systime->year=unixtime->tm_year+1900;
76 systime->month=unixtime->tm_mon+1;
77 systime->dayofweek=unixtime->tm_wday;
78 systime->day=unixtime->tm_mday;
79 systime->hour=unixtime->tm_hour;
80 systime->minute=unixtime->tm_min;
81 systime->second=unixtime->tm_sec;
82 systime->milliseconds=0;
84 return True;
87 /*******************************************************************
88 reads or writes an DOC_INFO structure.
89 ********************************************************************/
91 static BOOL smb_io_doc_info_1(const char *desc, DOC_INFO_1 *info_1, prs_struct *ps, int depth)
93 if (info_1 == NULL) return False;
95 prs_debug(ps, depth, desc, "smb_io_doc_info_1");
96 depth++;
98 if(!prs_align(ps))
99 return False;
101 if(!prs_uint32("p_docname", ps, depth, &info_1->p_docname))
102 return False;
103 if(!prs_uint32("p_outputfile", ps, depth, &info_1->p_outputfile))
104 return False;
105 if(!prs_uint32("p_datatype", ps, depth, &info_1->p_datatype))
106 return False;
108 if(!smb_io_unistr2("", &info_1->docname, info_1->p_docname, ps, depth))
109 return False;
110 if(!smb_io_unistr2("", &info_1->outputfile, info_1->p_outputfile, ps, depth))
111 return False;
112 if(!smb_io_unistr2("", &info_1->datatype, info_1->p_datatype, ps, depth))
113 return False;
115 return True;
118 /*******************************************************************
119 reads or writes an DOC_INFO structure.
120 ********************************************************************/
122 static BOOL smb_io_doc_info(const char *desc, DOC_INFO *info, prs_struct *ps, int depth)
124 uint32 useless_ptr=0;
126 if (info == NULL) return False;
128 prs_debug(ps, depth, desc, "smb_io_doc_info");
129 depth++;
131 if(!prs_align(ps))
132 return False;
134 if(!prs_uint32("switch_value", ps, depth, &info->switch_value))
135 return False;
137 if(!prs_uint32("doc_info_X ptr", ps, depth, &useless_ptr))
138 return False;
140 switch (info->switch_value)
142 case 1:
143 if(!smb_io_doc_info_1("",&info->doc_info_1, ps, depth))
144 return False;
145 break;
146 case 2:
148 this is just a placeholder
150 MSDN July 1998 says doc_info_2 is only on
151 Windows 95, and as Win95 doesn't do RPC to print
152 this case is nearly impossible
154 Maybe one day with Windows for dishwasher 2037 ...
157 /* smb_io_doc_info_2("",&info->doc_info_2, ps, depth); */
158 break;
159 default:
160 DEBUG(0,("Something is obviously wrong somewhere !\n"));
161 break;
164 return True;
167 /*******************************************************************
168 reads or writes an DOC_INFO_CONTAINER structure.
169 ********************************************************************/
171 static BOOL smb_io_doc_info_container(const char *desc, DOC_INFO_CONTAINER *cont, prs_struct *ps, int depth)
173 if (cont == NULL) return False;
175 prs_debug(ps, depth, desc, "smb_io_doc_info_container");
176 depth++;
178 if(!prs_align(ps))
179 return False;
181 if(!prs_uint32("level", ps, depth, &cont->level))
182 return False;
184 if(!smb_io_doc_info("",&cont->docinfo, ps, depth))
185 return False;
187 return True;
190 /*******************************************************************
191 reads or writes an NOTIFY OPTION TYPE structure.
192 ********************************************************************/
194 /* NOTIFY_OPTION_TYPE and NOTIFY_OPTION_TYPE_DATA are really one
195 structure. The _TYPE structure is really the deferred referrants (i.e
196 the notify fields array) of the _TYPE structure. -tpot */
198 static BOOL smb_io_notify_option_type(const char *desc, SPOOL_NOTIFY_OPTION_TYPE *type, prs_struct *ps, int depth)
200 prs_debug(ps, depth, desc, "smb_io_notify_option_type");
201 depth++;
203 if (!prs_align(ps))
204 return False;
206 if(!prs_uint16("type", ps, depth, &type->type))
207 return False;
208 if(!prs_uint16("reserved0", ps, depth, &type->reserved0))
209 return False;
210 if(!prs_uint32("reserved1", ps, depth, &type->reserved1))
211 return False;
212 if(!prs_uint32("reserved2", ps, depth, &type->reserved2))
213 return False;
214 if(!prs_uint32("count", ps, depth, &type->count))
215 return False;
216 if(!prs_uint32("fields_ptr", ps, depth, &type->fields_ptr))
217 return False;
219 return True;
222 /*******************************************************************
223 reads or writes an NOTIFY OPTION TYPE DATA.
224 ********************************************************************/
226 static BOOL smb_io_notify_option_type_data(const char *desc, SPOOL_NOTIFY_OPTION_TYPE *type, prs_struct *ps, int depth)
228 int i;
230 prs_debug(ps, depth, desc, "smb_io_notify_option_type_data");
231 depth++;
233 /* if there are no fields just return */
234 if (type->fields_ptr==0)
235 return True;
237 if(!prs_align(ps))
238 return False;
240 if(!prs_uint32("count2", ps, depth, &type->count2))
241 return False;
243 if (type->count2 != type->count)
244 DEBUG(4,("What a mess, count was %x now is %x !\n", type->count, type->count2));
246 /* parse the option type data */
247 for(i=0;i<type->count2;i++)
248 if(!prs_uint16("fields",ps,depth,&type->fields[i]))
249 return False;
250 return True;
253 /*******************************************************************
254 reads or writes an NOTIFY OPTION structure.
255 ********************************************************************/
257 static BOOL smb_io_notify_option_type_ctr(const char *desc, SPOOL_NOTIFY_OPTION_TYPE_CTR *ctr , prs_struct *ps, int depth)
259 int i;
261 prs_debug(ps, depth, desc, "smb_io_notify_option_type_ctr");
262 depth++;
264 if(!prs_uint32("count", ps, depth, &ctr->count))
265 return False;
267 /* reading */
268 if (UNMARSHALLING(ps))
269 if((ctr->type=(SPOOL_NOTIFY_OPTION_TYPE *)prs_alloc_mem(ps,ctr->count*sizeof(SPOOL_NOTIFY_OPTION_TYPE))) == NULL)
270 return False;
272 /* the option type struct */
273 for(i=0;i<ctr->count;i++)
274 if(!smb_io_notify_option_type("", &ctr->type[i] , ps, depth))
275 return False;
277 /* the type associated with the option type struct */
278 for(i=0;i<ctr->count;i++)
279 if(!smb_io_notify_option_type_data("", &ctr->type[i] , ps, depth))
280 return False;
282 return True;
285 /*******************************************************************
286 reads or writes an NOTIFY OPTION structure.
287 ********************************************************************/
289 static BOOL smb_io_notify_option(const char *desc, SPOOL_NOTIFY_OPTION *option, prs_struct *ps, int depth)
291 prs_debug(ps, depth, desc, "smb_io_notify_option");
292 depth++;
294 if(!prs_uint32("version", ps, depth, &option->version))
295 return False;
296 if(!prs_uint32("flags", ps, depth, &option->flags))
297 return False;
298 if(!prs_uint32("count", ps, depth, &option->count))
299 return False;
300 if(!prs_uint32("option_type_ptr", ps, depth, &option->option_type_ptr))
301 return False;
303 /* marshalling or unmarshalling, that would work */
304 if (option->option_type_ptr!=0) {
305 if(!smb_io_notify_option_type_ctr("", &option->ctr ,ps, depth))
306 return False;
308 else {
309 option->ctr.type=NULL;
310 option->ctr.count=0;
313 return True;
316 /*******************************************************************
317 reads or writes an NOTIFY INFO DATA structure.
318 ********************************************************************/
320 static BOOL smb_io_notify_info_data(const char *desc,SPOOL_NOTIFY_INFO_DATA *data, prs_struct *ps, int depth)
322 uint32 useless_ptr=0xADDE0FF0;
324 uint32 how_many_words;
325 BOOL isvalue;
326 uint32 x;
328 prs_debug(ps, depth, desc, "smb_io_notify_info_data");
329 depth++;
331 how_many_words=data->size;
332 if (how_many_words==POINTER) {
333 how_many_words=TWO_VALUE;
336 isvalue=data->enc_type;
338 if(!prs_align(ps))
339 return False;
340 if(!prs_uint16("type", ps, depth, &data->type))
341 return False;
342 if(!prs_uint16("field", ps, depth, &data->field))
343 return False;
344 /*prs_align(ps);*/
346 if(!prs_uint32("how many words", ps, depth, &how_many_words))
347 return False;
348 if(!prs_uint32("id", ps, depth, &data->id))
349 return False;
350 if(!prs_uint32("how many words", ps, depth, &how_many_words))
351 return False;
354 /*prs_align(ps);*/
356 if (isvalue==True) {
357 if(!prs_uint32("value[0]", ps, depth, &data->notify_data.value[0]))
358 return False;
359 if(!prs_uint32("value[1]", ps, depth, &data->notify_data.value[1]))
360 return False;
361 /*prs_align(ps);*/
362 } else {
363 /* it's a string */
364 /* length in ascii including \0 */
365 x=2*(data->notify_data.data.length+1);
366 if(!prs_uint32("string length", ps, depth, &x ))
367 return False;
368 if(!prs_uint32("pointer", ps, depth, &useless_ptr))
369 return False;
370 /*prs_align(ps);*/
373 return True;
376 /*******************************************************************
377 reads or writes an NOTIFY INFO DATA structure.
378 ********************************************************************/
380 BOOL smb_io_notify_info_data_strings(const char *desc,SPOOL_NOTIFY_INFO_DATA *data,
381 prs_struct *ps, int depth)
383 uint32 x;
384 BOOL isvalue;
386 prs_debug(ps, depth, desc, "smb_io_notify_info_data_strings");
387 depth++;
389 if(!prs_align(ps))
390 return False;
392 isvalue=data->enc_type;
394 if (isvalue==False) {
395 /* length of string in unicode include \0 */
396 x=data->notify_data.data.length+1;
397 if(!prs_uint32("string length", ps, depth, &x ))
398 return False;
399 if (MARSHALLING(ps)) {
400 /* These are already in little endian format. Don't byte swap. */
401 if (x == 1) {
403 /* No memory allocated for this string
404 therefore following the data.string
405 pointer is a bad idea. Use a pointer to
406 the uint32 length union member to
407 provide a source for a unicode NULL */
409 if(!prs_uint8s(True,"string",ps,depth, (uint8 *)&data->notify_data.data.length,x*2))
410 return False;
411 } else {
412 if(!prs_uint16uni(True,"string",ps,depth,data->notify_data.data.string,x))
413 return False;
415 } else {
417 /* Tallocate memory for string */
419 data->notify_data.data.string = (uint16 *)prs_alloc_mem(ps, x * 2);
420 if (!data->notify_data.data.string)
421 return False;
423 if(!prs_uint16uni(True,"string",ps,depth,data->notify_data.data.string,x))
424 return False;
427 #if 0 /* JERRY */
428 /* Win2k does not seem to put this parse align here */
429 if(!prs_align(ps))
430 return False;
431 #endif
433 return True;
436 /*******************************************************************
437 reads or writes an NOTIFY INFO structure.
438 ********************************************************************/
440 static BOOL smb_io_notify_info(const char *desc, SPOOL_NOTIFY_INFO *info, prs_struct *ps, int depth)
442 int i;
444 prs_debug(ps, depth, desc, "smb_io_notify_info");
445 depth++;
447 if(!prs_align(ps))
448 return False;
450 if(!prs_uint32("count", ps, depth, &info->count))
451 return False;
452 if(!prs_uint32("version", ps, depth, &info->version))
453 return False;
454 if(!prs_uint32("flags", ps, depth, &info->flags))
455 return False;
456 if(!prs_uint32("count", ps, depth, &info->count))
457 return False;
459 for (i=0;i<info->count;i++) {
460 if(!smb_io_notify_info_data(desc, &info->data[i], ps, depth))
461 return False;
464 /* now do the strings at the end of the stream */
465 for (i=0;i<info->count;i++) {
466 if(!smb_io_notify_info_data_strings(desc, &info->data[i], ps, depth))
467 return False;
470 return True;
473 /*******************************************************************
474 ********************************************************************/
476 static BOOL spool_io_user_level_1(const char *desc, SPOOL_USER_1 *q_u, prs_struct *ps, int depth)
478 prs_debug(ps, depth, desc, "");
479 depth++;
481 /* reading */
482 if (UNMARSHALLING(ps))
483 ZERO_STRUCTP(q_u);
485 if (!prs_align(ps))
486 return False;
487 if (!prs_uint32("size", ps, depth, &q_u->size))
488 return False;
489 if (!prs_uint32("client_name_ptr", ps, depth, &q_u->client_name_ptr))
490 return False;
491 if (!prs_uint32("user_name_ptr", ps, depth, &q_u->user_name_ptr))
492 return False;
493 if (!prs_uint32("build", ps, depth, &q_u->build))
494 return False;
495 if (!prs_uint32("major", ps, depth, &q_u->major))
496 return False;
497 if (!prs_uint32("minor", ps, depth, &q_u->minor))
498 return False;
499 if (!prs_uint32("processor", ps, depth, &q_u->processor))
500 return False;
502 if (!smb_io_unistr2("", &q_u->client_name, q_u->client_name_ptr, ps, depth))
503 return False;
504 if (!prs_align(ps))
505 return False;
506 if (!smb_io_unistr2("", &q_u->user_name, q_u->user_name_ptr, ps, depth))
507 return False;
509 return True;
512 /*******************************************************************
513 ********************************************************************/
515 static BOOL spool_io_user_level(const char *desc, SPOOL_USER_CTR *q_u, prs_struct *ps, int depth)
517 if (q_u==NULL)
518 return False;
520 prs_debug(ps, depth, desc, "spool_io_user_level");
521 depth++;
523 if (!prs_align(ps))
524 return False;
525 if (!prs_uint32("level", ps, depth, &q_u->level))
526 return False;
527 if (!prs_uint32("ptr", ps, depth, &q_u->ptr))
528 return False;
530 switch (q_u->level) {
531 case 1:
532 if (!spool_io_user_level_1("", &q_u->user1, ps, depth))
533 return False;
534 break;
535 default:
536 return False;
539 return True;
542 /*******************************************************************
543 * read or write a DEVICEMODE struct.
544 * on reading allocate memory for the private member
545 ********************************************************************/
547 #define DM_NUM_OPTIONAL_FIELDS 8
549 BOOL spoolss_io_devmode(const char *desc, prs_struct *ps, int depth, DEVICEMODE *devmode)
551 uint32 available_space; /* size of the device mode left to parse */
552 /* only important on unmarshalling */
553 int i = 0;
555 struct optional_fields {
556 fstring name;
557 uint32* field;
558 } opt_fields[DM_NUM_OPTIONAL_FIELDS] = {
559 { "icmmethod", NULL },
560 { "icmintent", NULL },
561 { "mediatype", NULL },
562 { "dithertype", NULL },
563 { "reserved1", NULL },
564 { "reserved2", NULL },
565 { "panningwidth", NULL },
566 { "panningheight", NULL }
569 /* assign at run time to keep non-gcc vompilers happy */
571 opt_fields[0].field = &devmode->icmmethod;
572 opt_fields[1].field = &devmode->icmintent;
573 opt_fields[2].field = &devmode->mediatype;
574 opt_fields[3].field = &devmode->dithertype;
575 opt_fields[4].field = &devmode->reserved1;
576 opt_fields[5].field = &devmode->reserved2;
577 opt_fields[6].field = &devmode->panningwidth;
578 opt_fields[7].field = &devmode->panningheight;
581 prs_debug(ps, depth, desc, "spoolss_io_devmode");
582 depth++;
584 if (UNMARSHALLING(ps)) {
585 devmode->devicename.buffer = (uint16 *)prs_alloc_mem(ps, 32 * sizeof(uint16) );
586 if (devmode->devicename.buffer == NULL)
587 return False;
590 if (!prs_uint16uni(True,"devicename", ps, depth, devmode->devicename.buffer, MAXDEVICENAME))
591 return False;
593 if (!prs_uint16("specversion", ps, depth, &devmode->specversion))
594 return False;
596 /* Sanity Check - look for unknown specversions, but don't fail if we see one.
597 Let the size determine that */
599 switch (devmode->specversion) {
600 case 0x0320:
601 case 0x0400:
602 case 0x0401:
603 break;
605 default:
606 DEBUG(0,("spoolss_io_devmode: Unknown specversion in devicemode [0x%x]\n",
607 devmode->specversion));
608 DEBUG(0,("spoolss_io_devmode: please report to samba-technical@samba.org!\n"));
609 break;
613 if (!prs_uint16("driverversion", ps, depth, &devmode->driverversion))
614 return False;
615 if (!prs_uint16("size", ps, depth, &devmode->size))
616 return False;
617 if (!prs_uint16("driverextra", ps, depth, &devmode->driverextra))
618 return False;
619 if (!prs_uint32("fields", ps, depth, &devmode->fields))
620 return False;
621 if (!prs_uint16("orientation", ps, depth, &devmode->orientation))
622 return False;
623 if (!prs_uint16("papersize", ps, depth, &devmode->papersize))
624 return False;
625 if (!prs_uint16("paperlength", ps, depth, &devmode->paperlength))
626 return False;
627 if (!prs_uint16("paperwidth", ps, depth, &devmode->paperwidth))
628 return False;
629 if (!prs_uint16("scale", ps, depth, &devmode->scale))
630 return False;
631 if (!prs_uint16("copies", ps, depth, &devmode->copies))
632 return False;
633 if (!prs_uint16("defaultsource", ps, depth, &devmode->defaultsource))
634 return False;
635 if (!prs_uint16("printquality", ps, depth, &devmode->printquality))
636 return False;
637 if (!prs_uint16("color", ps, depth, &devmode->color))
638 return False;
639 if (!prs_uint16("duplex", ps, depth, &devmode->duplex))
640 return False;
641 if (!prs_uint16("yresolution", ps, depth, &devmode->yresolution))
642 return False;
643 if (!prs_uint16("ttoption", ps, depth, &devmode->ttoption))
644 return False;
645 if (!prs_uint16("collate", ps, depth, &devmode->collate))
646 return False;
648 if (UNMARSHALLING(ps)) {
649 devmode->formname.buffer = (uint16 *)prs_alloc_mem(ps, 32 * sizeof(uint16) );
650 if (devmode->formname.buffer == NULL)
651 return False;
654 if (!prs_uint16uni(True, "formname", ps, depth, devmode->formname.buffer, 32))
655 return False;
656 if (!prs_uint16("logpixels", ps, depth, &devmode->logpixels))
657 return False;
658 if (!prs_uint32("bitsperpel", ps, depth, &devmode->bitsperpel))
659 return False;
660 if (!prs_uint32("pelswidth", ps, depth, &devmode->pelswidth))
661 return False;
662 if (!prs_uint32("pelsheight", ps, depth, &devmode->pelsheight))
663 return False;
664 if (!prs_uint32("displayflags", ps, depth, &devmode->displayflags))
665 return False;
666 if (!prs_uint32("displayfrequency", ps, depth, &devmode->displayfrequency))
667 return False;
669 * every device mode I've ever seen on the wire at least has up
670 * to the displayfrequency field. --jerry (05-09-2002)
673 /* add uint32's + uint16's + two UNICODE strings */
675 available_space = devmode->size - (sizeof(uint32)*6 + sizeof(uint16)*18 + sizeof(uint16)*64);
677 /* Sanity check - we only have uint32's left tp parse */
679 if ( available_space && ((available_space % sizeof(uint32)) != 0) ) {
680 DEBUG(0,("spoolss_io_devmode: available_space [%d] no in multiple of 4 bytes (size = %d)!\n",
681 available_space, devmode->size));
682 DEBUG(0,("spoolss_io_devmode: please report to samba-technical@samba.org!\n"));
683 return False;
687 * Conditional parsing. Assume that the DeviceMode has been
688 * zero'd by the caller.
691 while ((available_space > 0) && (i < DM_NUM_OPTIONAL_FIELDS))
693 DEBUG(10, ("spoolss_io_devmode: [%d] bytes left to parse in devmode\n", available_space));
694 if (!prs_uint32(opt_fields[i].name, ps, depth, opt_fields[i].field))
695 return False;
696 available_space -= sizeof(uint32);
697 i++;
700 /* Sanity Check - we should no available space at this point unless
701 MS changes the device mode structure */
703 if (available_space) {
704 DEBUG(0,("spoolss_io_devmode: I've parsed all I know and there is still stuff left|\n"));
705 DEBUG(0,("spoolss_io_devmode: available_space = [%d], devmode_size = [%d]!\n",
706 available_space, devmode->size));
707 DEBUG(0,("spoolss_io_devmode: please report to samba-technical@samba.org!\n"));
708 return False;
712 if (devmode->driverextra!=0) {
713 if (UNMARSHALLING(ps)) {
714 devmode->private=(uint8 *)prs_alloc_mem(ps, devmode->driverextra*sizeof(uint8));
715 if(devmode->private == NULL)
716 return False;
717 DEBUG(7,("spoolss_io_devmode: allocated memory [%d] for private\n",devmode->driverextra));
720 DEBUG(7,("spoolss_io_devmode: parsing [%d] bytes of private\n",devmode->driverextra));
721 if (!prs_uint8s(False, "private", ps, depth,
722 devmode->private, devmode->driverextra))
723 return False;
726 return True;
729 /*******************************************************************
730 Read or write a DEVICEMODE container
731 ********************************************************************/
733 static BOOL spoolss_io_devmode_cont(const char *desc, DEVMODE_CTR *dm_c, prs_struct *ps, int depth)
735 if (dm_c==NULL)
736 return False;
738 prs_debug(ps, depth, desc, "spoolss_io_devmode_cont");
739 depth++;
741 if(!prs_align(ps))
742 return False;
744 if (!prs_uint32("size", ps, depth, &dm_c->size))
745 return False;
747 if (!prs_uint32("devmode_ptr", ps, depth, &dm_c->devmode_ptr))
748 return False;
750 if (dm_c->size==0 || dm_c->devmode_ptr==0) {
751 if (UNMARSHALLING(ps))
752 /* if while reading there is no DEVMODE ... */
753 dm_c->devmode=NULL;
754 return True;
757 /* so we have a DEVICEMODE to follow */
758 if (UNMARSHALLING(ps)) {
759 DEBUG(9,("Allocating memory for spoolss_io_devmode\n"));
760 dm_c->devmode=(DEVICEMODE *)prs_alloc_mem(ps,sizeof(DEVICEMODE));
761 if(dm_c->devmode == NULL)
762 return False;
765 /* this is bad code, shouldn't be there */
766 if (!prs_uint32("size", ps, depth, &dm_c->size))
767 return False;
769 if (!spoolss_io_devmode(desc, ps, depth, dm_c->devmode))
770 return False;
772 return True;
775 /*******************************************************************
776 ********************************************************************/
778 static BOOL spoolss_io_printer_default(const char *desc, PRINTER_DEFAULT *pd, prs_struct *ps, int depth)
780 if (pd==NULL)
781 return False;
783 prs_debug(ps, depth, desc, "spoolss_io_printer_default");
784 depth++;
786 if (!prs_uint32("datatype_ptr", ps, depth, &pd->datatype_ptr))
787 return False;
789 if (!smb_io_unistr2("datatype", &pd->datatype, pd->datatype_ptr, ps,depth))
790 return False;
792 if (!prs_align(ps))
793 return False;
795 if (!spoolss_io_devmode_cont("", &pd->devmode_cont, ps, depth))
796 return False;
798 if (!prs_align(ps))
799 return False;
801 if (!prs_uint32("access_required", ps, depth, &pd->access_required))
802 return False;
804 return True;
807 /*******************************************************************
808 * init a structure.
809 ********************************************************************/
811 BOOL make_spoolss_q_open_printer_ex(SPOOL_Q_OPEN_PRINTER_EX *q_u,
812 const fstring printername,
813 const fstring datatype,
814 uint32 access_required,
815 const fstring clientname,
816 const fstring user_name)
818 DEBUG(5,("make_spoolss_q_open_printer_ex\n"));
819 q_u->printername_ptr = (printername!=NULL)?1:0;
820 init_unistr2(&q_u->printername, printername, strlen(printername)+1);
822 q_u->printer_default.datatype_ptr = 0;
824 q_u->printer_default.datatype_ptr = (datatype!=NULL)?1:0;
825 init_unistr2(&q_u->printer_default.datatype, datatype, strlen(datatype));
827 q_u->printer_default.devmode_cont.size=0;
828 q_u->printer_default.devmode_cont.devmode_ptr=0;
829 q_u->printer_default.devmode_cont.devmode=NULL;
830 q_u->printer_default.access_required=access_required;
831 q_u->user_switch=1;
832 q_u->user_ctr.level=1;
833 q_u->user_ctr.ptr=1;
834 q_u->user_ctr.user1.size=strlen(clientname)+strlen(user_name)+10;
835 q_u->user_ctr.user1.client_name_ptr = (clientname!=NULL)?1:0;
836 q_u->user_ctr.user1.user_name_ptr = (user_name!=NULL)?1:0;
837 q_u->user_ctr.user1.build=1381;
838 q_u->user_ctr.user1.major=2;
839 q_u->user_ctr.user1.minor=0;
840 q_u->user_ctr.user1.processor=0;
841 init_unistr2(&q_u->user_ctr.user1.client_name, clientname, strlen(clientname)+1);
842 init_unistr2(&q_u->user_ctr.user1.user_name, user_name, strlen(user_name)+1);
844 return True;
847 /*******************************************************************
848 * init a structure.
849 ********************************************************************/
851 BOOL make_spoolss_q_addprinterex(
852 TALLOC_CTX *mem_ctx,
853 SPOOL_Q_ADDPRINTEREX *q_u,
854 const char *srv_name,
855 const char* clientname,
856 const char* user_name,
857 uint32 level,
858 PRINTER_INFO_CTR *ctr)
860 DEBUG(5,("make_spoolss_q_addprinterex\n"));
862 if (!ctr) return False;
864 ZERO_STRUCTP(q_u);
866 q_u->server_name_ptr = (srv_name!=NULL)?1:0;
867 init_unistr2(&q_u->server_name, srv_name, strlen(srv_name));
869 q_u->level = level;
871 q_u->info.level = level;
872 q_u->info.info_ptr = (ctr->printers_2!=NULL)?1:0;
873 switch (level) {
874 case 2:
875 /* init q_u->info.info2 from *info */
876 if (!make_spoolss_printer_info_2(mem_ctx, &q_u->info.info_2, ctr->printers_2)) {
877 DEBUG(0,("make_spoolss_q_addprinterex: Unable to fill SPOOL_Q_ADDPRINTEREX struct!\n"));
878 return False;
880 break;
881 default :
882 break;
885 q_u->user_switch=1;
887 q_u->user_ctr.level=1;
888 q_u->user_ctr.ptr=1;
889 q_u->user_ctr.user1.client_name_ptr = (clientname!=NULL)?1:0;
890 q_u->user_ctr.user1.user_name_ptr = (user_name!=NULL)?1:0;
891 q_u->user_ctr.user1.build=1381;
892 q_u->user_ctr.user1.major=2;
893 q_u->user_ctr.user1.minor=0;
894 q_u->user_ctr.user1.processor=0;
895 init_unistr2(&q_u->user_ctr.user1.client_name, clientname, strlen(clientname)+1);
896 init_unistr2(&q_u->user_ctr.user1.user_name, user_name, strlen(user_name)+1);
897 q_u->user_ctr.user1.size=q_u->user_ctr.user1.user_name.uni_str_len +
898 q_u->user_ctr.user1.client_name.uni_str_len + 2;
900 return True;
903 /*******************************************************************
904 create a SPOOL_PRINTER_INFO_2 stuct from a PRINTER_INFO_2 struct
905 *******************************************************************/
907 BOOL make_spoolss_printer_info_2(TALLOC_CTX *mem_ctx, SPOOL_PRINTER_INFO_LEVEL_2 **spool_info2,
908 PRINTER_INFO_2 *info)
911 SPOOL_PRINTER_INFO_LEVEL_2 *inf;
913 /* allocate the necessary memory */
914 if (!(inf=(SPOOL_PRINTER_INFO_LEVEL_2*)talloc(mem_ctx, sizeof(SPOOL_PRINTER_INFO_LEVEL_2)))) {
915 DEBUG(0,("make_spoolss_printer_info_2: Unable to allocate SPOOL_PRINTER_INFO_LEVEL_2 sruct!\n"));
916 return False;
919 inf->servername_ptr = (info->servername.buffer!=NULL)?1:0;
920 inf->printername_ptr = (info->printername.buffer!=NULL)?1:0;
921 inf->sharename_ptr = (info->sharename.buffer!=NULL)?1:0;
922 inf->portname_ptr = (info->portname.buffer!=NULL)?1:0;
923 inf->drivername_ptr = (info->drivername.buffer!=NULL)?1:0;
924 inf->comment_ptr = (info->comment.buffer!=NULL)?1:0;
925 inf->location_ptr = (info->location.buffer!=NULL)?1:0;
926 inf->devmode_ptr = (info->devmode!=NULL)?1:0;
927 inf->sepfile_ptr = (info->sepfile.buffer!=NULL)?1:0;
928 inf->printprocessor_ptr = (info->printprocessor.buffer!=NULL)?1:0;
929 inf->datatype_ptr = (info->datatype.buffer!=NULL)?1:0;
930 inf->parameters_ptr = (info->parameters.buffer!=NULL)?1:0;
931 inf->secdesc_ptr = (info->secdesc!=NULL)?1:0;
932 inf->attributes = info->attributes;
933 inf->priority = info->priority;
934 inf->default_priority = info->defaultpriority;
935 inf->starttime = info->starttime;
936 inf->untiltime = info->untiltime;
937 inf->cjobs = info->cjobs;
938 inf->averageppm = info->averageppm;
939 init_unistr2_from_unistr(&inf->servername, &info->servername);
940 init_unistr2_from_unistr(&inf->printername, &info->printername);
941 init_unistr2_from_unistr(&inf->sharename, &info->sharename);
942 init_unistr2_from_unistr(&inf->portname, &info->portname);
943 init_unistr2_from_unistr(&inf->drivername, &info->drivername);
944 init_unistr2_from_unistr(&inf->comment, &info->comment);
945 init_unistr2_from_unistr(&inf->location, &info->location);
946 init_unistr2_from_unistr(&inf->sepfile, &info->sepfile);
947 init_unistr2_from_unistr(&inf->printprocessor, &info->printprocessor);
948 init_unistr2_from_unistr(&inf->datatype, &info->datatype);
949 init_unistr2_from_unistr(&inf->parameters, &info->parameters);
950 init_unistr2_from_unistr(&inf->datatype, &info->datatype);
952 *spool_info2 = inf;
954 return True;
958 /*******************************************************************
959 * read a structure.
960 * called from spoolss_q_open_printer_ex (srv_spoolss.c)
961 ********************************************************************/
963 BOOL spoolss_io_q_open_printer(const char *desc, SPOOL_Q_OPEN_PRINTER *q_u, prs_struct *ps, int depth)
965 if (q_u == NULL)
966 return False;
968 prs_debug(ps, depth, desc, "spoolss_io_q_open_printer");
969 depth++;
971 if (!prs_align(ps))
972 return False;
974 if (!prs_uint32("printername_ptr", ps, depth, &q_u->printername_ptr))
975 return False;
976 if (!smb_io_unistr2("", &q_u->printername, q_u->printername_ptr, ps,depth))
977 return False;
979 if (!prs_align(ps))
980 return False;
982 if (!spoolss_io_printer_default("", &q_u->printer_default, ps, depth))
983 return False;
985 return True;
988 /*******************************************************************
989 * write a structure.
990 * called from static spoolss_r_open_printer_ex (srv_spoolss.c)
991 * called from spoolss_open_printer_ex (cli_spoolss.c)
992 ********************************************************************/
994 BOOL spoolss_io_r_open_printer(const char *desc, SPOOL_R_OPEN_PRINTER *r_u, prs_struct *ps, int depth)
996 if (r_u == NULL) return False;
998 prs_debug(ps, depth, desc, "spoolss_io_r_open_printer");
999 depth++;
1001 if (!prs_align(ps))
1002 return False;
1004 if (!smb_io_pol_hnd("printer handle",&(r_u->handle),ps,depth))
1005 return False;
1007 if (!prs_werror("status code", ps, depth, &(r_u->status)))
1008 return False;
1010 return True;
1014 /*******************************************************************
1015 * read a structure.
1016 * called from spoolss_q_open_printer_ex (srv_spoolss.c)
1017 ********************************************************************/
1019 BOOL spoolss_io_q_open_printer_ex(const char *desc, SPOOL_Q_OPEN_PRINTER_EX *q_u, prs_struct *ps, int depth)
1021 if (q_u == NULL)
1022 return False;
1024 prs_debug(ps, depth, desc, "spoolss_io_q_open_printer_ex");
1025 depth++;
1027 if (!prs_align(ps))
1028 return False;
1030 if (!prs_uint32("printername_ptr", ps, depth, &q_u->printername_ptr))
1031 return False;
1032 if (!smb_io_unistr2("", &q_u->printername, q_u->printername_ptr, ps,depth))
1033 return False;
1035 if (!prs_align(ps))
1036 return False;
1038 if (!spoolss_io_printer_default("", &q_u->printer_default, ps, depth))
1039 return False;
1041 if (!prs_uint32("user_switch", ps, depth, &q_u->user_switch))
1042 return False;
1043 if (!spool_io_user_level("", &q_u->user_ctr, ps, depth))
1044 return False;
1046 return True;
1049 /*******************************************************************
1050 * write a structure.
1051 * called from static spoolss_r_open_printer_ex (srv_spoolss.c)
1052 * called from spoolss_open_printer_ex (cli_spoolss.c)
1053 ********************************************************************/
1055 BOOL spoolss_io_r_open_printer_ex(const char *desc, SPOOL_R_OPEN_PRINTER_EX *r_u, prs_struct *ps, int depth)
1057 if (r_u == NULL) return False;
1059 prs_debug(ps, depth, desc, "spoolss_io_r_open_printer_ex");
1060 depth++;
1062 if (!prs_align(ps))
1063 return False;
1065 if (!smb_io_pol_hnd("printer handle",&(r_u->handle),ps,depth))
1066 return False;
1068 if (!prs_werror("status code", ps, depth, &(r_u->status)))
1069 return False;
1071 return True;
1074 /*******************************************************************
1075 * init a structure.
1076 ********************************************************************/
1077 BOOL make_spoolss_q_deleteprinterdriver(
1078 TALLOC_CTX *mem_ctx,
1079 SPOOL_Q_DELETEPRINTERDRIVER *q_u,
1080 const char *server,
1081 const char* arch,
1082 const char* driver
1085 DEBUG(5,("make_spoolss_q_deleteprinterdriver\n"));
1087 q_u->server_ptr = (server!=NULL)?1:0;
1089 /* these must be NULL terminated or else NT4 will
1090 complain about invalid parameters --jerry */
1091 init_unistr2(&q_u->server, server, strlen(server)+1);
1092 init_unistr2(&q_u->arch, arch, strlen(arch)+1);
1093 init_unistr2(&q_u->driver, driver, strlen(driver)+1);
1096 return True;
1100 /*******************************************************************
1101 * make a structure.
1102 ********************************************************************/
1104 BOOL make_spoolss_q_getprinterdata(SPOOL_Q_GETPRINTERDATA *q_u,
1105 const POLICY_HND *handle,
1106 UNISTR2 *valuename, uint32 size)
1108 if (q_u == NULL) return False;
1110 DEBUG(5,("make_spoolss_q_getprinterdata\n"));
1112 q_u->handle = *handle;
1113 copy_unistr2(&q_u->valuename, valuename);
1114 q_u->size = size;
1116 return True;
1119 /*******************************************************************
1120 * read a structure.
1121 * called from spoolss_q_getprinterdata (srv_spoolss.c)
1122 ********************************************************************/
1124 BOOL spoolss_io_q_getprinterdata(const char *desc, SPOOL_Q_GETPRINTERDATA *q_u, prs_struct *ps, int depth)
1126 if (q_u == NULL)
1127 return False;
1129 prs_debug(ps, depth, desc, "spoolss_io_q_getprinterdata");
1130 depth++;
1132 if (!prs_align(ps))
1133 return False;
1134 if (!smb_io_pol_hnd("printer handle",&q_u->handle,ps,depth))
1135 return False;
1136 if (!prs_align(ps))
1137 return False;
1138 if (!smb_io_unistr2("valuename", &q_u->valuename,True,ps,depth))
1139 return False;
1140 if (!prs_align(ps))
1141 return False;
1142 if (!prs_uint32("size", ps, depth, &q_u->size))
1143 return False;
1145 return True;
1148 /*******************************************************************
1149 * read a structure.
1150 * called from spoolss_q_deleteprinterdata (srv_spoolss.c)
1151 ********************************************************************/
1153 BOOL spoolss_io_q_deleteprinterdata(const char *desc, SPOOL_Q_DELETEPRINTERDATA *q_u, prs_struct *ps, int depth)
1155 if (q_u == NULL)
1156 return False;
1158 prs_debug(ps, depth, desc, "spoolss_io_q_deleteprinterdata");
1159 depth++;
1161 if (!prs_align(ps))
1162 return False;
1163 if (!smb_io_pol_hnd("printer handle",&q_u->handle,ps,depth))
1164 return False;
1165 if (!prs_align(ps))
1166 return False;
1167 if (!smb_io_unistr2("valuename", &q_u->valuename,True,ps,depth))
1168 return False;
1170 return True;
1173 /*******************************************************************
1174 * write a structure.
1175 * called from spoolss_r_deleteprinterdata (srv_spoolss.c)
1176 ********************************************************************/
1178 BOOL spoolss_io_r_deleteprinterdata(const char *desc, SPOOL_R_DELETEPRINTERDATA *r_u, prs_struct *ps, int depth)
1180 prs_debug(ps, depth, desc, "spoolss_io_r_deleteprinterdata");
1181 depth++;
1182 if(!prs_werror("status", ps, depth, &r_u->status))
1183 return False;
1185 return True;
1188 /*******************************************************************
1189 * write a structure.
1190 * called from spoolss_r_getprinterdata (srv_spoolss.c)
1191 ********************************************************************/
1193 BOOL spoolss_io_r_getprinterdata(const char *desc, SPOOL_R_GETPRINTERDATA *r_u, prs_struct *ps, int depth)
1195 if (r_u == NULL)
1196 return False;
1198 prs_debug(ps, depth, desc, "spoolss_io_r_getprinterdata");
1199 depth++;
1201 if (!prs_align(ps))
1202 return False;
1203 if (!prs_uint32("type", ps, depth, &r_u->type))
1204 return False;
1205 if (!prs_uint32("size", ps, depth, &r_u->size))
1206 return False;
1208 if (UNMARSHALLING(ps) && r_u->size) {
1209 r_u->data = prs_alloc_mem(ps, r_u->size);
1210 if(!r_u->data)
1211 return False;
1214 if (!prs_uint8s(False,"data", ps, depth, r_u->data, r_u->size))
1215 return False;
1217 if (!prs_align(ps))
1218 return False;
1220 if (!prs_uint32("needed", ps, depth, &r_u->needed))
1221 return False;
1222 if (!prs_werror("status", ps, depth, &r_u->status))
1223 return False;
1225 return True;
1228 /*******************************************************************
1229 * make a structure.
1230 ********************************************************************/
1232 BOOL make_spoolss_q_closeprinter(SPOOL_Q_CLOSEPRINTER *q_u, POLICY_HND *hnd)
1234 if (q_u == NULL) return False;
1236 DEBUG(5,("make_spoolss_q_closeprinter\n"));
1238 memcpy(&q_u->handle, hnd, sizeof(q_u->handle));
1240 return True;
1243 /*******************************************************************
1244 * read a structure.
1245 * called from static spoolss_q_abortprinter (srv_spoolss.c)
1246 * called from spoolss_abortprinter (cli_spoolss.c)
1247 ********************************************************************/
1249 BOOL spoolss_io_q_abortprinter(const char *desc, SPOOL_Q_ABORTPRINTER *q_u, prs_struct *ps, int depth)
1251 if (q_u == NULL) return False;
1253 prs_debug(ps, depth, desc, "spoolss_io_q_abortprinter");
1254 depth++;
1256 if (!prs_align(ps))
1257 return False;
1259 if (!smb_io_pol_hnd("printer handle",&q_u->handle,ps,depth))
1260 return False;
1262 return True;
1265 /*******************************************************************
1266 * write a structure.
1267 * called from spoolss_r_abortprinter (srv_spoolss.c)
1268 ********************************************************************/
1270 BOOL spoolss_io_r_abortprinter(const char *desc, SPOOL_R_ABORTPRINTER *r_u, prs_struct *ps, int depth)
1272 prs_debug(ps, depth, desc, "spoolss_io_r_abortprinter");
1273 depth++;
1274 if(!prs_werror("status", ps, depth, &r_u->status))
1275 return False;
1277 return True;
1280 /*******************************************************************
1281 * read a structure.
1282 * called from static spoolss_q_deleteprinter (srv_spoolss.c)
1283 * called from spoolss_deleteprinter (cli_spoolss.c)
1284 ********************************************************************/
1286 BOOL spoolss_io_q_deleteprinter(const char *desc, SPOOL_Q_DELETEPRINTER *q_u, prs_struct *ps, int depth)
1288 if (q_u == NULL) return False;
1290 prs_debug(ps, depth, desc, "spoolss_io_q_deleteprinter");
1291 depth++;
1293 if (!prs_align(ps))
1294 return False;
1296 if (!smb_io_pol_hnd("printer handle",&q_u->handle,ps,depth))
1297 return False;
1299 return True;
1302 /*******************************************************************
1303 * write a structure.
1304 * called from static spoolss_r_deleteprinter (srv_spoolss.c)
1305 * called from spoolss_deleteprinter (cli_spoolss.c)
1306 ********************************************************************/
1308 BOOL spoolss_io_r_deleteprinter(const char *desc, SPOOL_R_DELETEPRINTER *r_u, prs_struct *ps, int depth)
1310 prs_debug(ps, depth, desc, "spoolss_io_r_deleteprinter");
1311 depth++;
1313 if (!prs_align(ps))
1314 return False;
1316 if (!smb_io_pol_hnd("printer handle",&r_u->handle,ps,depth))
1317 return False;
1318 if (!prs_werror("status", ps, depth, &r_u->status))
1319 return False;
1321 return True;
1325 /*******************************************************************
1326 * read a structure.
1327 * called from api_spoolss_deleteprinterdriver (srv_spoolss.c)
1328 * called from spoolss_deleteprinterdriver (cli_spoolss.c)
1329 ********************************************************************/
1331 BOOL spoolss_io_q_deleteprinterdriver(const char *desc, SPOOL_Q_DELETEPRINTERDRIVER *q_u, prs_struct *ps, int depth)
1333 if (q_u == NULL) return False;
1335 prs_debug(ps, depth, desc, "spoolss_io_q_deleteprinterdriver");
1336 depth++;
1338 if (!prs_align(ps))
1339 return False;
1341 if(!prs_uint32("server_ptr", ps, depth, &q_u->server_ptr))
1342 return False;
1343 if(!smb_io_unistr2("server", &q_u->server, q_u->server_ptr, ps, depth))
1344 return False;
1345 if(!smb_io_unistr2("arch", &q_u->arch, True, ps, depth))
1346 return False;
1347 if(!smb_io_unistr2("driver", &q_u->driver, True, ps, depth))
1348 return False;
1351 return True;
1355 /*******************************************************************
1356 * write a structure.
1357 ********************************************************************/
1358 BOOL spoolss_io_r_deleteprinterdriver(const char *desc, SPOOL_R_DELETEPRINTERDRIVER *r_u, prs_struct *ps, int depth)
1360 if (r_u == NULL) return False;
1362 prs_debug(ps, depth, desc, "spoolss_io_r_deleteprinterdriver");
1363 depth++;
1365 if (!prs_align(ps))
1366 return False;
1368 if (!prs_werror("status", ps, depth, &r_u->status))
1369 return False;
1371 return True;
1376 /*******************************************************************
1377 * read a structure.
1378 * called from static spoolss_q_closeprinter (srv_spoolss.c)
1379 * called from spoolss_closeprinter (cli_spoolss.c)
1380 ********************************************************************/
1382 BOOL spoolss_io_q_closeprinter(const char *desc, SPOOL_Q_CLOSEPRINTER *q_u, prs_struct *ps, int depth)
1384 if (q_u == NULL) return False;
1386 prs_debug(ps, depth, desc, "spoolss_io_q_closeprinter");
1387 depth++;
1389 if (!prs_align(ps))
1390 return False;
1392 if (!smb_io_pol_hnd("printer handle",&q_u->handle,ps,depth))
1393 return False;
1395 return True;
1398 /*******************************************************************
1399 * write a structure.
1400 * called from static spoolss_r_closeprinter (srv_spoolss.c)
1401 * called from spoolss_closeprinter (cli_spoolss.c)
1402 ********************************************************************/
1404 BOOL spoolss_io_r_closeprinter(const char *desc, SPOOL_R_CLOSEPRINTER *r_u, prs_struct *ps, int depth)
1406 prs_debug(ps, depth, desc, "spoolss_io_r_closeprinter");
1407 depth++;
1409 if (!prs_align(ps))
1410 return False;
1412 if (!smb_io_pol_hnd("printer handle",&r_u->handle,ps,depth))
1413 return False;
1414 if (!prs_werror("status", ps, depth, &r_u->status))
1415 return False;
1417 return True;
1420 /*******************************************************************
1421 * read a structure.
1422 * called from spoolss_q_startdocprinter (srv_spoolss.c)
1423 ********************************************************************/
1425 BOOL spoolss_io_q_startdocprinter(const char *desc, SPOOL_Q_STARTDOCPRINTER *q_u, prs_struct *ps, int depth)
1427 if (q_u == NULL) return False;
1429 prs_debug(ps, depth, desc, "spoolss_io_q_startdocprinter");
1430 depth++;
1432 if(!prs_align(ps))
1433 return False;
1435 if(!smb_io_pol_hnd("printer handle",&q_u->handle,ps,depth))
1436 return False;
1438 if(!smb_io_doc_info_container("",&q_u->doc_info_container, ps, depth))
1439 return False;
1441 return True;
1444 /*******************************************************************
1445 * write a structure.
1446 * called from spoolss_r_startdocprinter (srv_spoolss.c)
1447 ********************************************************************/
1449 BOOL spoolss_io_r_startdocprinter(const char *desc, SPOOL_R_STARTDOCPRINTER *r_u, prs_struct *ps, int depth)
1451 prs_debug(ps, depth, desc, "spoolss_io_r_startdocprinter");
1452 depth++;
1453 if(!prs_uint32("jobid", ps, depth, &r_u->jobid))
1454 return False;
1455 if(!prs_werror("status", ps, depth, &r_u->status))
1456 return False;
1458 return True;
1461 /*******************************************************************
1462 * read a structure.
1463 * called from spoolss_q_enddocprinter (srv_spoolss.c)
1464 ********************************************************************/
1466 BOOL spoolss_io_q_enddocprinter(const char *desc, SPOOL_Q_ENDDOCPRINTER *q_u, prs_struct *ps, int depth)
1468 if (q_u == NULL) return False;
1470 prs_debug(ps, depth, desc, "spoolss_io_q_enddocprinter");
1471 depth++;
1473 if(!prs_align(ps))
1474 return False;
1476 if(!smb_io_pol_hnd("printer handle",&q_u->handle,ps,depth))
1477 return False;
1479 return True;
1482 /*******************************************************************
1483 * write a structure.
1484 * called from spoolss_r_enddocprinter (srv_spoolss.c)
1485 ********************************************************************/
1487 BOOL spoolss_io_r_enddocprinter(const char *desc, SPOOL_R_ENDDOCPRINTER *r_u, prs_struct *ps, int depth)
1489 prs_debug(ps, depth, desc, "spoolss_io_r_enddocprinter");
1490 depth++;
1491 if(!prs_werror("status", ps, depth, &r_u->status))
1492 return False;
1494 return True;
1497 /*******************************************************************
1498 * read a structure.
1499 * called from spoolss_q_startpageprinter (srv_spoolss.c)
1500 ********************************************************************/
1502 BOOL spoolss_io_q_startpageprinter(const char *desc, SPOOL_Q_STARTPAGEPRINTER *q_u, prs_struct *ps, int depth)
1504 if (q_u == NULL) return False;
1506 prs_debug(ps, depth, desc, "spoolss_io_q_startpageprinter");
1507 depth++;
1509 if(!prs_align(ps))
1510 return False;
1512 if(!smb_io_pol_hnd("printer handle",&q_u->handle,ps,depth))
1513 return False;
1515 return True;
1518 /*******************************************************************
1519 * write a structure.
1520 * called from spoolss_r_startpageprinter (srv_spoolss.c)
1521 ********************************************************************/
1523 BOOL spoolss_io_r_startpageprinter(const char *desc, SPOOL_R_STARTPAGEPRINTER *r_u, prs_struct *ps, int depth)
1525 prs_debug(ps, depth, desc, "spoolss_io_r_startpageprinter");
1526 depth++;
1527 if(!prs_werror("status", ps, depth, &r_u->status))
1528 return False;
1530 return True;
1533 /*******************************************************************
1534 * read a structure.
1535 * called from spoolss_q_endpageprinter (srv_spoolss.c)
1536 ********************************************************************/
1538 BOOL spoolss_io_q_endpageprinter(const char *desc, SPOOL_Q_ENDPAGEPRINTER *q_u, prs_struct *ps, int depth)
1540 if (q_u == NULL) return False;
1542 prs_debug(ps, depth, desc, "spoolss_io_q_endpageprinter");
1543 depth++;
1545 if(!prs_align(ps))
1546 return False;
1548 if(!smb_io_pol_hnd("printer handle",&q_u->handle,ps,depth))
1549 return False;
1551 return True;
1554 /*******************************************************************
1555 * write a structure.
1556 * called from spoolss_r_endpageprinter (srv_spoolss.c)
1557 ********************************************************************/
1559 BOOL spoolss_io_r_endpageprinter(const char *desc, SPOOL_R_ENDPAGEPRINTER *r_u, prs_struct *ps, int depth)
1561 prs_debug(ps, depth, desc, "spoolss_io_r_endpageprinter");
1562 depth++;
1563 if(!prs_werror("status", ps, depth, &r_u->status))
1564 return False;
1566 return True;
1569 /*******************************************************************
1570 * read a structure.
1571 * called from spoolss_q_writeprinter (srv_spoolss.c)
1572 ********************************************************************/
1574 BOOL spoolss_io_q_writeprinter(const char *desc, SPOOL_Q_WRITEPRINTER *q_u, prs_struct *ps, int depth)
1576 if (q_u == NULL) return False;
1578 prs_debug(ps, depth, desc, "spoolss_io_q_writeprinter");
1579 depth++;
1581 if(!prs_align(ps))
1582 return False;
1584 if(!smb_io_pol_hnd("printer handle",&q_u->handle,ps,depth))
1585 return False;
1586 if(!prs_uint32("buffer_size", ps, depth, &q_u->buffer_size))
1587 return False;
1589 if (q_u->buffer_size!=0)
1591 if (UNMARSHALLING(ps))
1592 q_u->buffer=(uint8 *)prs_alloc_mem(ps,q_u->buffer_size*sizeof(uint8));
1593 if(q_u->buffer == NULL)
1594 return False;
1595 if(!prs_uint8s(True, "buffer", ps, depth, q_u->buffer, q_u->buffer_size))
1596 return False;
1598 if(!prs_align(ps))
1599 return False;
1600 if(!prs_uint32("buffer_size2", ps, depth, &q_u->buffer_size2))
1601 return False;
1603 return True;
1606 /*******************************************************************
1607 * write a structure.
1608 * called from spoolss_r_writeprinter (srv_spoolss.c)
1609 ********************************************************************/
1611 BOOL spoolss_io_r_writeprinter(const char *desc, SPOOL_R_WRITEPRINTER *r_u, prs_struct *ps, int depth)
1613 prs_debug(ps, depth, desc, "spoolss_io_r_writeprinter");
1614 depth++;
1615 if(!prs_uint32("buffer_written", ps, depth, &r_u->buffer_written))
1616 return False;
1617 if(!prs_werror("status", ps, depth, &r_u->status))
1618 return False;
1620 return True;
1623 /*******************************************************************
1624 * read a structure.
1625 * called from spoolss_q_rffpcnex (srv_spoolss.c)
1626 ********************************************************************/
1628 BOOL spoolss_io_q_rffpcnex(const char *desc, SPOOL_Q_RFFPCNEX *q_u, prs_struct *ps, int depth)
1630 prs_debug(ps, depth, desc, "spoolss_io_q_rffpcnex");
1631 depth++;
1633 if(!prs_align(ps))
1634 return False;
1636 if(!smb_io_pol_hnd("printer handle", &q_u->handle, ps, depth))
1637 return False;
1638 if(!prs_uint32("flags", ps, depth, &q_u->flags))
1639 return False;
1640 if(!prs_uint32("options", ps, depth, &q_u->options))
1641 return False;
1642 if(!prs_uint32("localmachine_ptr", ps, depth, &q_u->localmachine_ptr))
1643 return False;
1644 if(!smb_io_unistr2("localmachine", &q_u->localmachine, q_u->localmachine_ptr, ps, depth))
1645 return False;
1647 if(!prs_align(ps))
1648 return False;
1650 if(!prs_uint32("printerlocal", ps, depth, &q_u->printerlocal))
1651 return False;
1653 if(!prs_uint32("option_ptr", ps, depth, &q_u->option_ptr))
1654 return False;
1656 if (q_u->option_ptr!=0) {
1658 if (UNMARSHALLING(ps))
1659 if((q_u->option=(SPOOL_NOTIFY_OPTION *)prs_alloc_mem(ps,sizeof(SPOOL_NOTIFY_OPTION))) == NULL)
1660 return False;
1662 if(!smb_io_notify_option("notify option", q_u->option, ps, depth))
1663 return False;
1666 return True;
1669 /*******************************************************************
1670 * write a structure.
1671 * called from spoolss_r_rffpcnex (srv_spoolss.c)
1672 ********************************************************************/
1674 BOOL spoolss_io_r_rffpcnex(const char *desc, SPOOL_R_RFFPCNEX *r_u, prs_struct *ps, int depth)
1676 prs_debug(ps, depth, desc, "spoolss_io_r_rffpcnex");
1677 depth++;
1679 if(!prs_werror("status", ps, depth, &r_u->status))
1680 return False;
1682 return True;
1685 /*******************************************************************
1686 * read a structure.
1687 * called from spoolss_q_rfnpcnex (srv_spoolss.c)
1688 ********************************************************************/
1690 BOOL spoolss_io_q_rfnpcnex(const char *desc, SPOOL_Q_RFNPCNEX *q_u, prs_struct *ps, int depth)
1692 prs_debug(ps, depth, desc, "spoolss_io_q_rfnpcnex");
1693 depth++;
1695 if(!prs_align(ps))
1696 return False;
1698 if(!smb_io_pol_hnd("printer handle",&q_u->handle,ps,depth))
1699 return False;
1701 if(!prs_uint32("change", ps, depth, &q_u->change))
1702 return False;
1704 if(!prs_uint32("option_ptr", ps, depth, &q_u->option_ptr))
1705 return False;
1707 if (q_u->option_ptr!=0) {
1709 if (UNMARSHALLING(ps))
1710 if((q_u->option=(SPOOL_NOTIFY_OPTION *)prs_alloc_mem(ps,sizeof(SPOOL_NOTIFY_OPTION))) == NULL)
1711 return False;
1713 if(!smb_io_notify_option("notify option", q_u->option, ps, depth))
1714 return False;
1717 return True;
1720 /*******************************************************************
1721 * write a structure.
1722 * called from spoolss_r_rfnpcnex (srv_spoolss.c)
1723 ********************************************************************/
1725 BOOL spoolss_io_r_rfnpcnex(const char *desc, SPOOL_R_RFNPCNEX *r_u, prs_struct *ps, int depth)
1727 prs_debug(ps, depth, desc, "spoolss_io_r_rfnpcnex");
1728 depth++;
1730 if(!prs_align(ps))
1731 return False;
1733 if (!prs_uint32("info_ptr", ps, depth, &r_u->info_ptr))
1734 return False;
1736 if(!smb_io_notify_info("notify info", &r_u->info ,ps,depth))
1737 return False;
1739 if(!prs_align(ps))
1740 return False;
1741 if(!prs_werror("status", ps, depth, &r_u->status))
1742 return False;
1744 return True;
1747 /*******************************************************************
1748 * return the length of a uint16 (obvious, but the code is clean)
1749 ********************************************************************/
1751 static uint32 size_of_uint16(uint16 *value)
1753 return (sizeof(*value));
1756 /*******************************************************************
1757 * return the length of a uint32 (obvious, but the code is clean)
1758 ********************************************************************/
1760 static uint32 size_of_uint32(uint32 *value)
1762 return (sizeof(*value));
1765 /*******************************************************************
1766 * return the length of a NTTIME (obvious, but the code is clean)
1767 ********************************************************************/
1769 static uint32 size_of_nttime(NTTIME *value)
1771 return (sizeof(*value));
1774 /*******************************************************************
1775 * return the length of a UNICODE string in number of char, includes:
1776 * - the leading zero
1777 * - the relative pointer size
1778 ********************************************************************/
1780 static uint32 size_of_relative_string(UNISTR *string)
1782 uint32 size=0;
1784 size=str_len_uni(string); /* the string length */
1785 size=size+1; /* add the trailing zero */
1786 size=size*2; /* convert in char */
1787 size=size+4; /* add the size of the ptr */
1789 #if 0 /* JERRY */
1791 * Do not include alignment as Win2k does not align relative
1792 * strings within a buffer --jerry
1794 /* Ensure size is 4 byte multiple (prs_align is being called...). */
1795 /* size += ((4 - (size & 3)) & 3); */
1796 #endif
1798 return size;
1801 /*******************************************************************
1802 * return the length of a uint32 (obvious, but the code is clean)
1803 ********************************************************************/
1805 static uint32 size_of_device_mode(DEVICEMODE *devmode)
1807 if (devmode==NULL)
1808 return (4);
1809 else
1810 return (4+devmode->size+devmode->driverextra);
1813 /*******************************************************************
1814 * return the length of a uint32 (obvious, but the code is clean)
1815 ********************************************************************/
1817 static uint32 size_of_systemtime(SYSTEMTIME *systime)
1819 if (systime==NULL)
1820 return (4);
1821 else
1822 return (sizeof(SYSTEMTIME) +4);
1825 /*******************************************************************
1826 * write a UNICODE string and its relative pointer.
1827 * used by all the RPC structs passing a buffer
1829 * As I'm a nice guy, I'm forcing myself to explain this code.
1830 * MS did a good job in the overall spoolss code except in some
1831 * functions where they are passing the API buffer directly in the
1832 * RPC request/reply. That's to maintain compatiility at the API level.
1833 * They could have done it the good way the first time.
1835 * So what happen is: the strings are written at the buffer's end,
1836 * in the reverse order of the original structure. Some pointers to
1837 * the strings are also in the buffer. Those are relative to the
1838 * buffer's start.
1840 * If you don't understand or want to change that function,
1841 * first get in touch with me: jfm@samba.org
1843 ********************************************************************/
1845 static BOOL smb_io_relstr(const char *desc, NEW_BUFFER *buffer, int depth, UNISTR *string)
1847 prs_struct *ps=&buffer->prs;
1849 if (MARSHALLING(ps)) {
1850 uint32 struct_offset = prs_offset(ps);
1851 uint32 relative_offset;
1853 buffer->string_at_end -= (size_of_relative_string(string) - 4);
1854 if(!prs_set_offset(ps, buffer->string_at_end))
1855 return False;
1856 #if 0 /* JERRY */
1858 * Win2k does not align strings in a buffer
1859 * Tested against WinNT 4.0 SP 6a & 2k SP2 --jerry
1861 if (!prs_align(ps))
1862 return False;
1863 #endif
1864 buffer->string_at_end = prs_offset(ps);
1866 /* write the string */
1867 if (!smb_io_unistr(desc, string, ps, depth))
1868 return False;
1870 if(!prs_set_offset(ps, struct_offset))
1871 return False;
1873 relative_offset=buffer->string_at_end - buffer->struct_start;
1874 /* write its offset */
1875 if (!prs_uint32("offset", ps, depth, &relative_offset))
1876 return False;
1878 else {
1879 uint32 old_offset;
1881 /* read the offset */
1882 if (!prs_uint32("offset", ps, depth, &(buffer->string_at_end)))
1883 return False;
1885 old_offset = prs_offset(ps);
1886 if(!prs_set_offset(ps, buffer->string_at_end+buffer->struct_start))
1887 return False;
1889 /* read the string */
1890 if (!smb_io_unistr(desc, string, ps, depth))
1891 return False;
1893 if(!prs_set_offset(ps, old_offset))
1894 return False;
1896 return True;
1899 /*******************************************************************
1900 * write a array of UNICODE strings and its relative pointer.
1901 * used by 2 RPC structs
1902 ********************************************************************/
1904 static BOOL smb_io_relarraystr(const char *desc, NEW_BUFFER *buffer, int depth, uint16 **string)
1906 UNISTR chaine;
1908 prs_struct *ps=&buffer->prs;
1910 if (MARSHALLING(ps)) {
1911 uint32 struct_offset = prs_offset(ps);
1912 uint32 relative_offset;
1913 uint16 *p;
1914 uint16 *q;
1915 uint16 zero=0;
1916 p=*string;
1917 q=*string;
1919 /* first write the last 0 */
1920 buffer->string_at_end -= 2;
1921 if(!prs_set_offset(ps, buffer->string_at_end))
1922 return False;
1924 if(!prs_uint16("leading zero", ps, depth, &zero))
1925 return False;
1927 while (p && (*p!=0)) {
1928 while (*q!=0)
1929 q++;
1931 /* Yes this should be malloc not talloc. Don't change. */
1933 chaine.buffer = malloc((q-p+1)*sizeof(uint16));
1934 if (chaine.buffer == NULL)
1935 return False;
1937 memcpy(chaine.buffer, p, (q-p+1)*sizeof(uint16));
1939 buffer->string_at_end -= (q-p+1)*sizeof(uint16);
1941 if(!prs_set_offset(ps, buffer->string_at_end)) {
1942 SAFE_FREE(chaine.buffer);
1943 return False;
1946 /* write the string */
1947 if (!smb_io_unistr(desc, &chaine, ps, depth)) {
1948 SAFE_FREE(chaine.buffer);
1949 return False;
1951 q++;
1952 p=q;
1954 SAFE_FREE(chaine.buffer);
1957 if(!prs_set_offset(ps, struct_offset))
1958 return False;
1960 relative_offset=buffer->string_at_end - buffer->struct_start;
1961 /* write its offset */
1962 if (!prs_uint32("offset", ps, depth, &relative_offset))
1963 return False;
1965 } else {
1967 /* UNMARSHALLING */
1969 uint32 old_offset;
1970 uint16 *chaine2=NULL;
1971 int l_chaine=0;
1972 int l_chaine2=0;
1973 size_t realloc_size = 0;
1975 *string=NULL;
1977 /* read the offset */
1978 if (!prs_uint32("offset", ps, depth, &buffer->string_at_end))
1979 return False;
1981 old_offset = prs_offset(ps);
1982 if(!prs_set_offset(ps, buffer->string_at_end + buffer->struct_start))
1983 return False;
1985 do {
1986 if (!smb_io_unistr(desc, &chaine, ps, depth))
1987 return False;
1989 l_chaine=str_len_uni(&chaine);
1991 /* we're going to add two more bytes here in case this
1992 is the last string in the array and we need to add
1993 an extra NULL for termination */
1994 if (l_chaine > 0)
1996 uint16 *tc2;
1998 realloc_size = (l_chaine2+l_chaine+2)*sizeof(uint16);
2000 /* Yes this should be realloc - it's freed below. JRA */
2002 if((tc2=(uint16 *)Realloc(chaine2, realloc_size)) == NULL) {
2003 SAFE_FREE(chaine2);
2004 return False;
2006 else chaine2 = tc2;
2007 memcpy(chaine2+l_chaine2, chaine.buffer, (l_chaine+1)*sizeof(uint16));
2008 l_chaine2+=l_chaine+1;
2011 } while(l_chaine!=0);
2013 /* the end should be bould NULL terminated so add
2014 the second one here */
2015 if (chaine2)
2017 chaine2[l_chaine2] = '\0';
2018 *string=(uint16 *)talloc_memdup(prs_get_mem_context(ps),chaine2,realloc_size);
2019 SAFE_FREE(chaine2);
2022 if(!prs_set_offset(ps, old_offset))
2023 return False;
2025 return True;
2028 /*******************************************************************
2029 Parse a DEVMODE structure and its relative pointer.
2030 ********************************************************************/
2032 static BOOL smb_io_relsecdesc(const char *desc, NEW_BUFFER *buffer, int depth, SEC_DESC **secdesc)
2034 prs_struct *ps= &buffer->prs;
2036 prs_debug(ps, depth, desc, "smb_io_relsecdesc");
2037 depth++;
2039 if (MARSHALLING(ps)) {
2040 uint32 struct_offset = prs_offset(ps);
2041 uint32 relative_offset;
2043 if (! *secdesc) {
2044 relative_offset = 0;
2045 if (!prs_uint32("offset", ps, depth, &relative_offset))
2046 return False;
2047 return True;
2050 if (*secdesc != NULL) {
2051 buffer->string_at_end -= sec_desc_size(*secdesc);
2053 if(!prs_set_offset(ps, buffer->string_at_end))
2054 return False;
2055 /* write the secdesc */
2056 if (!sec_io_desc(desc, secdesc, ps, depth))
2057 return False;
2059 if(!prs_set_offset(ps, struct_offset))
2060 return False;
2063 relative_offset=buffer->string_at_end - buffer->struct_start;
2064 /* write its offset */
2066 if (!prs_uint32("offset", ps, depth, &relative_offset))
2067 return False;
2068 } else {
2069 uint32 old_offset;
2071 /* read the offset */
2072 if (!prs_uint32("offset", ps, depth, &buffer->string_at_end))
2073 return False;
2075 old_offset = prs_offset(ps);
2076 if(!prs_set_offset(ps, buffer->string_at_end + buffer->struct_start))
2077 return False;
2079 /* read the sd */
2080 if (!sec_io_desc(desc, secdesc, ps, depth))
2081 return False;
2083 if(!prs_set_offset(ps, old_offset))
2084 return False;
2086 return True;
2089 /*******************************************************************
2090 Parse a DEVMODE structure and its relative pointer.
2091 ********************************************************************/
2093 static BOOL smb_io_reldevmode(const char *desc, NEW_BUFFER *buffer, int depth, DEVICEMODE **devmode)
2095 prs_struct *ps=&buffer->prs;
2097 prs_debug(ps, depth, desc, "smb_io_reldevmode");
2098 depth++;
2100 if (MARSHALLING(ps)) {
2101 uint32 struct_offset = prs_offset(ps);
2102 uint32 relative_offset;
2104 if (*devmode == NULL) {
2105 relative_offset=0;
2106 if (!prs_uint32("offset", ps, depth, &relative_offset))
2107 return False;
2108 DEBUG(8, ("boing, the devmode was NULL\n"));
2110 return True;
2113 buffer->string_at_end -= ((*devmode)->size + (*devmode)->driverextra);
2115 if(!prs_set_offset(ps, buffer->string_at_end))
2116 return False;
2118 /* write the DEVMODE */
2119 if (!spoolss_io_devmode(desc, ps, depth, *devmode))
2120 return False;
2122 if(!prs_set_offset(ps, struct_offset))
2123 return False;
2125 relative_offset=buffer->string_at_end - buffer->struct_start;
2126 /* write its offset */
2127 if (!prs_uint32("offset", ps, depth, &relative_offset))
2128 return False;
2130 else {
2131 uint32 old_offset;
2133 /* read the offset */
2134 if (!prs_uint32("offset", ps, depth, &buffer->string_at_end))
2135 return False;
2136 if (buffer->string_at_end == 0) {
2137 *devmode = NULL;
2138 return True;
2141 old_offset = prs_offset(ps);
2142 if(!prs_set_offset(ps, buffer->string_at_end + buffer->struct_start))
2143 return False;
2145 /* read the string */
2146 if((*devmode=(DEVICEMODE *)prs_alloc_mem(ps,sizeof(DEVICEMODE))) == NULL)
2147 return False;
2148 if (!spoolss_io_devmode(desc, ps, depth, *devmode))
2149 return False;
2151 if(!prs_set_offset(ps, old_offset))
2152 return False;
2154 return True;
2157 /*******************************************************************
2158 Parse a PRINTER_INFO_0 structure.
2159 ********************************************************************/
2161 BOOL smb_io_printer_info_0(const char *desc, NEW_BUFFER *buffer, PRINTER_INFO_0 *info, int depth)
2163 prs_struct *ps=&buffer->prs;
2165 prs_debug(ps, depth, desc, "smb_io_printer_info_0");
2166 depth++;
2168 buffer->struct_start=prs_offset(ps);
2170 if (!smb_io_relstr("printername", buffer, depth, &info->printername))
2171 return False;
2172 if (!smb_io_relstr("servername", buffer, depth, &info->servername))
2173 return False;
2175 if(!prs_uint32("cjobs", ps, depth, &info->cjobs))
2176 return False;
2177 if(!prs_uint32("total_jobs", ps, depth, &info->total_jobs))
2178 return False;
2179 if(!prs_uint32("total_bytes", ps, depth, &info->total_bytes))
2180 return False;
2182 if(!prs_uint16("year", ps, depth, &info->year))
2183 return False;
2184 if(!prs_uint16("month", ps, depth, &info->month))
2185 return False;
2186 if(!prs_uint16("dayofweek", ps, depth, &info->dayofweek))
2187 return False;
2188 if(!prs_uint16("day", ps, depth, &info->day))
2189 return False;
2190 if(!prs_uint16("hour", ps, depth, &info->hour))
2191 return False;
2192 if(!prs_uint16("minute", ps, depth, &info->minute))
2193 return False;
2194 if(!prs_uint16("second", ps, depth, &info->second))
2195 return False;
2196 if(!prs_uint16("milliseconds", ps, depth, &info->milliseconds))
2197 return False;
2199 if(!prs_uint32("global_counter", ps, depth, &info->global_counter))
2200 return False;
2201 if(!prs_uint32("total_pages", ps, depth, &info->total_pages))
2202 return False;
2204 if(!prs_uint16("major_version", ps, depth, &info->major_version))
2205 return False;
2206 if(!prs_uint16("build_version", ps, depth, &info->build_version))
2207 return False;
2208 if(!prs_uint32("unknown7", ps, depth, &info->unknown7))
2209 return False;
2210 if(!prs_uint32("unknown8", ps, depth, &info->unknown8))
2211 return False;
2212 if(!prs_uint32("unknown9", ps, depth, &info->unknown9))
2213 return False;
2214 if(!prs_uint32("session_counter", ps, depth, &info->session_counter))
2215 return False;
2216 if(!prs_uint32("unknown11", ps, depth, &info->unknown11))
2217 return False;
2218 if(!prs_uint32("printer_errors", ps, depth, &info->printer_errors))
2219 return False;
2220 if(!prs_uint32("unknown13", ps, depth, &info->unknown13))
2221 return False;
2222 if(!prs_uint32("unknown14", ps, depth, &info->unknown14))
2223 return False;
2224 if(!prs_uint32("unknown15", ps, depth, &info->unknown15))
2225 return False;
2226 if(!prs_uint32("unknown16", ps, depth, &info->unknown16))
2227 return False;
2228 if(!prs_uint32("change_id", ps, depth, &info->change_id))
2229 return False;
2230 if(!prs_uint32("unknown18", ps, depth, &info->unknown18))
2231 return False;
2232 if(!prs_uint32("status" , ps, depth, &info->status))
2233 return False;
2234 if(!prs_uint32("unknown20", ps, depth, &info->unknown20))
2235 return False;
2236 if(!prs_uint32("c_setprinter", ps, depth, &info->c_setprinter))
2237 return False;
2238 if(!prs_uint16("unknown22", ps, depth, &info->unknown22))
2239 return False;
2240 if(!prs_uint16("unknown23", ps, depth, &info->unknown23))
2241 return False;
2242 if(!prs_uint16("unknown24", ps, depth, &info->unknown24))
2243 return False;
2244 if(!prs_uint16("unknown25", ps, depth, &info->unknown25))
2245 return False;
2246 if(!prs_uint16("unknown26", ps, depth, &info->unknown26))
2247 return False;
2248 if(!prs_uint16("unknown27", ps, depth, &info->unknown27))
2249 return False;
2250 if(!prs_uint16("unknown28", ps, depth, &info->unknown28))
2251 return False;
2252 if(!prs_uint16("unknown29", ps, depth, &info->unknown29))
2253 return False;
2255 return True;
2258 /*******************************************************************
2259 Parse a PRINTER_INFO_1 structure.
2260 ********************************************************************/
2262 BOOL smb_io_printer_info_1(const char *desc, NEW_BUFFER *buffer, PRINTER_INFO_1 *info, int depth)
2264 prs_struct *ps=&buffer->prs;
2266 prs_debug(ps, depth, desc, "smb_io_printer_info_1");
2267 depth++;
2269 buffer->struct_start=prs_offset(ps);
2271 if (!prs_uint32("flags", ps, depth, &info->flags))
2272 return False;
2273 if (!smb_io_relstr("description", buffer, depth, &info->description))
2274 return False;
2275 if (!smb_io_relstr("name", buffer, depth, &info->name))
2276 return False;
2277 if (!smb_io_relstr("comment", buffer, depth, &info->comment))
2278 return False;
2280 return True;
2283 /*******************************************************************
2284 Parse a PRINTER_INFO_2 structure.
2285 ********************************************************************/
2287 BOOL smb_io_printer_info_2(const char *desc, NEW_BUFFER *buffer, PRINTER_INFO_2 *info, int depth)
2289 prs_struct *ps=&buffer->prs;
2290 uint32 dm_offset, sd_offset, current_offset;
2291 uint32 dummy_value = 0, has_secdesc = 0;
2293 prs_debug(ps, depth, desc, "smb_io_printer_info_2");
2294 depth++;
2296 buffer->struct_start=prs_offset(ps);
2298 if (!smb_io_relstr("servername", buffer, depth, &info->servername))
2299 return False;
2300 if (!smb_io_relstr("printername", buffer, depth, &info->printername))
2301 return False;
2302 if (!smb_io_relstr("sharename", buffer, depth, &info->sharename))
2303 return False;
2304 if (!smb_io_relstr("portname", buffer, depth, &info->portname))
2305 return False;
2306 if (!smb_io_relstr("drivername", buffer, depth, &info->drivername))
2307 return False;
2308 if (!smb_io_relstr("comment", buffer, depth, &info->comment))
2309 return False;
2310 if (!smb_io_relstr("location", buffer, depth, &info->location))
2311 return False;
2313 /* save current offset and wind forwared by a uint32 */
2314 dm_offset = prs_offset(ps);
2315 if (!prs_uint32("devmode", ps, depth, &dummy_value))
2316 return False;
2318 if (!smb_io_relstr("sepfile", buffer, depth, &info->sepfile))
2319 return False;
2320 if (!smb_io_relstr("printprocessor", buffer, depth, &info->printprocessor))
2321 return False;
2322 if (!smb_io_relstr("datatype", buffer, depth, &info->datatype))
2323 return False;
2324 if (!smb_io_relstr("parameters", buffer, depth, &info->parameters))
2325 return False;
2327 /* save current offset for the sec_desc */
2328 sd_offset = prs_offset(ps);
2329 if (!prs_uint32("sec_desc", ps, depth, &has_secdesc))
2330 return False;
2332 /* save current location so we can pick back up here */
2333 current_offset = prs_offset(ps);
2335 /* parse the devmode */
2336 if (!prs_set_offset(ps, dm_offset))
2337 return False;
2338 if (!smb_io_reldevmode("devmode", buffer, depth, &info->devmode))
2339 return False;
2341 /* parse the sec_desc */
2342 if (has_secdesc) {
2343 if (!prs_set_offset(ps, sd_offset))
2344 return False;
2345 if (!smb_io_relsecdesc("secdesc", buffer, depth, &info->secdesc))
2346 return False;
2349 /* pick up where we left off */
2350 if (!prs_set_offset(ps, current_offset))
2351 return False;
2353 if (!prs_uint32("attributes", ps, depth, &info->attributes))
2354 return False;
2355 if (!prs_uint32("priority", ps, depth, &info->priority))
2356 return False;
2357 if (!prs_uint32("defpriority", ps, depth, &info->defaultpriority))
2358 return False;
2359 if (!prs_uint32("starttime", ps, depth, &info->starttime))
2360 return False;
2361 if (!prs_uint32("untiltime", ps, depth, &info->untiltime))
2362 return False;
2363 if (!prs_uint32("status", ps, depth, &info->status))
2364 return False;
2365 if (!prs_uint32("jobs", ps, depth, &info->cjobs))
2366 return False;
2367 if (!prs_uint32("averageppm", ps, depth, &info->averageppm))
2368 return False;
2370 return True;
2373 /*******************************************************************
2374 Parse a PRINTER_INFO_3 structure.
2375 ********************************************************************/
2377 BOOL smb_io_printer_info_3(const char *desc, NEW_BUFFER *buffer, PRINTER_INFO_3 *info, int depth)
2379 prs_struct *ps=&buffer->prs;
2381 prs_debug(ps, depth, desc, "smb_io_printer_info_3");
2382 depth++;
2384 buffer->struct_start=prs_offset(ps);
2386 if (!prs_uint32("flags", ps, depth, &info->flags))
2387 return False;
2388 if (!sec_io_desc("sec_desc", &info->secdesc, ps, depth))
2389 return False;
2391 return True;
2394 /*******************************************************************
2395 Parse a PRINTER_INFO_4 structure.
2396 ********************************************************************/
2398 BOOL smb_io_printer_info_4(const char *desc, NEW_BUFFER *buffer, PRINTER_INFO_4 *info, int depth)
2400 prs_struct *ps=&buffer->prs;
2402 prs_debug(ps, depth, desc, "smb_io_printer_info_4");
2403 depth++;
2405 buffer->struct_start=prs_offset(ps);
2407 if (!smb_io_relstr("printername", buffer, depth, &info->printername))
2408 return False;
2409 if (!smb_io_relstr("servername", buffer, depth, &info->servername))
2410 return False;
2411 if (!prs_uint32("attributes", ps, depth, &info->attributes))
2412 return False;
2413 return True;
2416 /*******************************************************************
2417 Parse a PRINTER_INFO_5 structure.
2418 ********************************************************************/
2420 BOOL smb_io_printer_info_5(const char *desc, NEW_BUFFER *buffer, PRINTER_INFO_5 *info, int depth)
2422 prs_struct *ps=&buffer->prs;
2424 prs_debug(ps, depth, desc, "smb_io_printer_info_5");
2425 depth++;
2427 buffer->struct_start=prs_offset(ps);
2429 if (!smb_io_relstr("printername", buffer, depth, &info->printername))
2430 return False;
2431 if (!smb_io_relstr("portname", buffer, depth, &info->portname))
2432 return False;
2433 if (!prs_uint32("attributes", ps, depth, &info->attributes))
2434 return False;
2435 if (!prs_uint32("device_not_selected_timeout", ps, depth, &info->device_not_selected_timeout))
2436 return False;
2437 if (!prs_uint32("transmission_retry_timeout", ps, depth, &info->transmission_retry_timeout))
2438 return False;
2439 return True;
2442 /*******************************************************************
2443 Parse a PORT_INFO_1 structure.
2444 ********************************************************************/
2446 BOOL smb_io_port_info_1(const char *desc, NEW_BUFFER *buffer, PORT_INFO_1 *info, int depth)
2448 prs_struct *ps=&buffer->prs;
2450 prs_debug(ps, depth, desc, "smb_io_port_info_1");
2451 depth++;
2453 buffer->struct_start=prs_offset(ps);
2455 if (!smb_io_relstr("port_name", buffer, depth, &info->port_name))
2456 return False;
2458 return True;
2461 /*******************************************************************
2462 Parse a PORT_INFO_2 structure.
2463 ********************************************************************/
2465 BOOL smb_io_port_info_2(const char *desc, NEW_BUFFER *buffer, PORT_INFO_2 *info, int depth)
2467 prs_struct *ps=&buffer->prs;
2469 prs_debug(ps, depth, desc, "smb_io_port_info_2");
2470 depth++;
2472 buffer->struct_start=prs_offset(ps);
2474 if (!smb_io_relstr("port_name", buffer, depth, &info->port_name))
2475 return False;
2476 if (!smb_io_relstr("monitor_name", buffer, depth, &info->monitor_name))
2477 return False;
2478 if (!smb_io_relstr("description", buffer, depth, &info->description))
2479 return False;
2480 if (!prs_uint32("port_type", ps, depth, &info->port_type))
2481 return False;
2482 if (!prs_uint32("reserved", ps, depth, &info->reserved))
2483 return False;
2485 return True;
2488 /*******************************************************************
2489 Parse a DRIVER_INFO_1 structure.
2490 ********************************************************************/
2492 BOOL smb_io_printer_driver_info_1(const char *desc, NEW_BUFFER *buffer, DRIVER_INFO_1 *info, int depth)
2494 prs_struct *ps=&buffer->prs;
2496 prs_debug(ps, depth, desc, "smb_io_printer_driver_info_1");
2497 depth++;
2499 buffer->struct_start=prs_offset(ps);
2501 if (!smb_io_relstr("name", buffer, depth, &info->name))
2502 return False;
2504 return True;
2507 /*******************************************************************
2508 Parse a DRIVER_INFO_2 structure.
2509 ********************************************************************/
2511 BOOL smb_io_printer_driver_info_2(const char *desc, NEW_BUFFER *buffer, DRIVER_INFO_2 *info, int depth)
2513 prs_struct *ps=&buffer->prs;
2515 prs_debug(ps, depth, desc, "smb_io_printer_driver_info_2");
2516 depth++;
2518 buffer->struct_start=prs_offset(ps);
2520 if (!prs_uint32("version", ps, depth, &info->version))
2521 return False;
2522 if (!smb_io_relstr("name", buffer, depth, &info->name))
2523 return False;
2524 if (!smb_io_relstr("architecture", buffer, depth, &info->architecture))
2525 return False;
2526 if (!smb_io_relstr("driverpath", buffer, depth, &info->driverpath))
2527 return False;
2528 if (!smb_io_relstr("datafile", buffer, depth, &info->datafile))
2529 return False;
2530 if (!smb_io_relstr("configfile", buffer, depth, &info->configfile))
2531 return False;
2533 return True;
2536 /*******************************************************************
2537 Parse a DRIVER_INFO_3 structure.
2538 ********************************************************************/
2540 BOOL smb_io_printer_driver_info_3(const char *desc, NEW_BUFFER *buffer, DRIVER_INFO_3 *info, int depth)
2542 prs_struct *ps=&buffer->prs;
2544 prs_debug(ps, depth, desc, "smb_io_printer_driver_info_3");
2545 depth++;
2547 buffer->struct_start=prs_offset(ps);
2549 if (!prs_uint32("version", ps, depth, &info->version))
2550 return False;
2551 if (!smb_io_relstr("name", buffer, depth, &info->name))
2552 return False;
2553 if (!smb_io_relstr("architecture", buffer, depth, &info->architecture))
2554 return False;
2555 if (!smb_io_relstr("driverpath", buffer, depth, &info->driverpath))
2556 return False;
2557 if (!smb_io_relstr("datafile", buffer, depth, &info->datafile))
2558 return False;
2559 if (!smb_io_relstr("configfile", buffer, depth, &info->configfile))
2560 return False;
2561 if (!smb_io_relstr("helpfile", buffer, depth, &info->helpfile))
2562 return False;
2564 if (!smb_io_relarraystr("dependentfiles", buffer, depth, &info->dependentfiles))
2565 return False;
2567 if (!smb_io_relstr("monitorname", buffer, depth, &info->monitorname))
2568 return False;
2569 if (!smb_io_relstr("defaultdatatype", buffer, depth, &info->defaultdatatype))
2570 return False;
2572 return True;
2575 /*******************************************************************
2576 Parse a DRIVER_INFO_6 structure.
2577 ********************************************************************/
2579 BOOL smb_io_printer_driver_info_6(const char *desc, NEW_BUFFER *buffer, DRIVER_INFO_6 *info, int depth)
2581 prs_struct *ps=&buffer->prs;
2583 prs_debug(ps, depth, desc, "smb_io_printer_driver_info_6");
2584 depth++;
2586 buffer->struct_start=prs_offset(ps);
2588 if (!prs_uint32("version", ps, depth, &info->version))
2589 return False;
2590 if (!smb_io_relstr("name", buffer, depth, &info->name))
2591 return False;
2592 if (!smb_io_relstr("architecture", buffer, depth, &info->architecture))
2593 return False;
2594 if (!smb_io_relstr("driverpath", buffer, depth, &info->driverpath))
2595 return False;
2596 if (!smb_io_relstr("datafile", buffer, depth, &info->datafile))
2597 return False;
2598 if (!smb_io_relstr("configfile", buffer, depth, &info->configfile))
2599 return False;
2600 if (!smb_io_relstr("helpfile", buffer, depth, &info->helpfile))
2601 return False;
2603 if (!smb_io_relarraystr("dependentfiles", buffer, depth, &info->dependentfiles))
2604 return False;
2606 if (!smb_io_relstr("monitorname", buffer, depth, &info->monitorname))
2607 return False;
2608 if (!smb_io_relstr("defaultdatatype", buffer, depth, &info->defaultdatatype))
2609 return False;
2611 if (!smb_io_relarraystr("previousdrivernames", buffer, depth, &info->previousdrivernames))
2612 return False;
2614 if (!prs_uint32("date.low", ps, depth, &info->driver_date.low))
2615 return False;
2616 if (!prs_uint32("date.high", ps, depth, &info->driver_date.high))
2617 return False;
2619 if (!prs_uint32("padding", ps, depth, &info->padding))
2620 return False;
2622 if (!prs_uint32("driver_version_low", ps, depth, &info->driver_version_low))
2623 return False;
2625 if (!prs_uint32("driver_version_high", ps, depth, &info->driver_version_high))
2626 return False;
2628 if (!smb_io_relstr("mfgname", buffer, depth, &info->mfgname))
2629 return False;
2630 if (!smb_io_relstr("oem_url", buffer, depth, &info->oem_url))
2631 return False;
2632 if (!smb_io_relstr("hardware_id", buffer, depth, &info->hardware_id))
2633 return False;
2634 if (!smb_io_relstr("provider", buffer, depth, &info->provider))
2635 return False;
2637 return True;
2640 /*******************************************************************
2641 Parse a JOB_INFO_1 structure.
2642 ********************************************************************/
2644 BOOL smb_io_job_info_1(const char *desc, NEW_BUFFER *buffer, JOB_INFO_1 *info, int depth)
2646 prs_struct *ps=&buffer->prs;
2648 prs_debug(ps, depth, desc, "smb_io_job_info_1");
2649 depth++;
2651 buffer->struct_start=prs_offset(ps);
2653 if (!prs_uint32("jobid", ps, depth, &info->jobid))
2654 return False;
2655 if (!smb_io_relstr("printername", buffer, depth, &info->printername))
2656 return False;
2657 if (!smb_io_relstr("machinename", buffer, depth, &info->machinename))
2658 return False;
2659 if (!smb_io_relstr("username", buffer, depth, &info->username))
2660 return False;
2661 if (!smb_io_relstr("document", buffer, depth, &info->document))
2662 return False;
2663 if (!smb_io_relstr("datatype", buffer, depth, &info->datatype))
2664 return False;
2665 if (!smb_io_relstr("text_status", buffer, depth, &info->text_status))
2666 return False;
2667 if (!prs_uint32("status", ps, depth, &info->status))
2668 return False;
2669 if (!prs_uint32("priority", ps, depth, &info->priority))
2670 return False;
2671 if (!prs_uint32("position", ps, depth, &info->position))
2672 return False;
2673 if (!prs_uint32("totalpages", ps, depth, &info->totalpages))
2674 return False;
2675 if (!prs_uint32("pagesprinted", ps, depth, &info->pagesprinted))
2676 return False;
2677 if (!spoolss_io_system_time("submitted", ps, depth, &info->submitted))
2678 return False;
2680 return True;
2683 /*******************************************************************
2684 Parse a JOB_INFO_2 structure.
2685 ********************************************************************/
2687 BOOL smb_io_job_info_2(const char *desc, NEW_BUFFER *buffer, JOB_INFO_2 *info, int depth)
2689 uint32 pipo=0;
2690 prs_struct *ps=&buffer->prs;
2692 prs_debug(ps, depth, desc, "smb_io_job_info_2");
2693 depth++;
2695 buffer->struct_start=prs_offset(ps);
2697 if (!prs_uint32("jobid",ps, depth, &info->jobid))
2698 return False;
2699 if (!smb_io_relstr("printername", buffer, depth, &info->printername))
2700 return False;
2701 if (!smb_io_relstr("machinename", buffer, depth, &info->machinename))
2702 return False;
2703 if (!smb_io_relstr("username", buffer, depth, &info->username))
2704 return False;
2705 if (!smb_io_relstr("document", buffer, depth, &info->document))
2706 return False;
2707 if (!smb_io_relstr("notifyname", buffer, depth, &info->notifyname))
2708 return False;
2709 if (!smb_io_relstr("datatype", buffer, depth, &info->datatype))
2710 return False;
2712 if (!smb_io_relstr("printprocessor", buffer, depth, &info->printprocessor))
2713 return False;
2714 if (!smb_io_relstr("parameters", buffer, depth, &info->parameters))
2715 return False;
2716 if (!smb_io_relstr("drivername", buffer, depth, &info->drivername))
2717 return False;
2718 if (!smb_io_reldevmode("devmode", buffer, depth, &info->devmode))
2719 return False;
2720 if (!smb_io_relstr("text_status", buffer, depth, &info->text_status))
2721 return False;
2723 /* SEC_DESC sec_desc;*/
2724 if (!prs_uint32("Hack! sec desc", ps, depth, &pipo))
2725 return False;
2727 if (!prs_uint32("status",ps, depth, &info->status))
2728 return False;
2729 if (!prs_uint32("priority",ps, depth, &info->priority))
2730 return False;
2731 if (!prs_uint32("position",ps, depth, &info->position))
2732 return False;
2733 if (!prs_uint32("starttime",ps, depth, &info->starttime))
2734 return False;
2735 if (!prs_uint32("untiltime",ps, depth, &info->untiltime))
2736 return False;
2737 if (!prs_uint32("totalpages",ps, depth, &info->totalpages))
2738 return False;
2739 if (!prs_uint32("size",ps, depth, &info->size))
2740 return False;
2741 if (!spoolss_io_system_time("submitted", ps, depth, &info->submitted) )
2742 return False;
2743 if (!prs_uint32("timeelapsed",ps, depth, &info->timeelapsed))
2744 return False;
2745 if (!prs_uint32("pagesprinted",ps, depth, &info->pagesprinted))
2746 return False;
2748 return True;
2751 /*******************************************************************
2752 ********************************************************************/
2754 BOOL smb_io_form_1(const char *desc, NEW_BUFFER *buffer, FORM_1 *info, int depth)
2756 prs_struct *ps=&buffer->prs;
2758 prs_debug(ps, depth, desc, "smb_io_form_1");
2759 depth++;
2761 buffer->struct_start=prs_offset(ps);
2763 if (!prs_uint32("flag", ps, depth, &info->flag))
2764 return False;
2766 if (!smb_io_relstr("name", buffer, depth, &info->name))
2767 return False;
2769 if (!prs_uint32("width", ps, depth, &info->width))
2770 return False;
2771 if (!prs_uint32("length", ps, depth, &info->length))
2772 return False;
2773 if (!prs_uint32("left", ps, depth, &info->left))
2774 return False;
2775 if (!prs_uint32("top", ps, depth, &info->top))
2776 return False;
2777 if (!prs_uint32("right", ps, depth, &info->right))
2778 return False;
2779 if (!prs_uint32("bottom", ps, depth, &info->bottom))
2780 return False;
2782 return True;
2785 /*******************************************************************
2786 Read/write a BUFFER struct.
2787 ********************************************************************/
2789 static BOOL spoolss_io_buffer(const char *desc, prs_struct *ps, int depth, NEW_BUFFER **pp_buffer)
2791 NEW_BUFFER *buffer = *pp_buffer;
2793 prs_debug(ps, depth, desc, "spoolss_io_buffer");
2794 depth++;
2796 if (UNMARSHALLING(ps))
2797 buffer = *pp_buffer = (NEW_BUFFER *)prs_alloc_mem(ps, sizeof(NEW_BUFFER));
2799 if (buffer == NULL)
2800 return False;
2802 if (!prs_uint32("ptr", ps, depth, &buffer->ptr))
2803 return False;
2805 /* reading */
2806 if (UNMARSHALLING(ps)) {
2807 buffer->size=0;
2808 buffer->string_at_end=0;
2810 if (buffer->ptr==0) {
2812 * JRA. I'm not sure if the data in here is in big-endian format if
2813 * the client is big-endian. Leave as default (little endian) for now.
2816 if (!prs_init(&buffer->prs, 0, prs_get_mem_context(ps), UNMARSHALL))
2817 return False;
2818 return True;
2821 if (!prs_uint32("size", ps, depth, &buffer->size))
2822 return False;
2825 * JRA. I'm not sure if the data in here is in big-endian format if
2826 * the client is big-endian. Leave as default (little endian) for now.
2829 if (!prs_init(&buffer->prs, buffer->size, prs_get_mem_context(ps), UNMARSHALL))
2830 return False;
2832 if (!prs_append_some_prs_data(&buffer->prs, ps, prs_offset(ps), buffer->size))
2833 return False;
2835 if (!prs_set_offset(&buffer->prs, 0))
2836 return False;
2838 if (!prs_set_offset(ps, buffer->size+prs_offset(ps)))
2839 return False;
2841 buffer->string_at_end=buffer->size;
2843 return True;
2845 else {
2846 BOOL ret = False;
2848 /* writing */
2849 if (buffer->ptr==0) {
2850 /* We have finished with the data in buffer->prs - free it. */
2851 prs_mem_free(&buffer->prs);
2852 return True;
2855 if (!prs_uint32("size", ps, depth, &buffer->size))
2856 goto out;
2858 if (!prs_append_some_prs_data(ps, &buffer->prs, 0, buffer->size))
2859 goto out;
2861 ret = True;
2862 out:
2864 /* We have finished with the data in buffer->prs - free it. */
2865 prs_mem_free(&buffer->prs);
2867 return ret;
2871 /*******************************************************************
2872 move a BUFFER from the query to the reply.
2873 As the data pointers in NEW_BUFFER are malloc'ed, not talloc'ed,
2874 this is ok. This is an OPTIMIZATION and is not strictly neccessary.
2875 Clears the memory to zero also.
2876 ********************************************************************/
2878 void spoolss_move_buffer(NEW_BUFFER *src, NEW_BUFFER **dest)
2880 prs_switch_type(&src->prs, MARSHALL);
2881 if(!prs_set_offset(&src->prs, 0))
2882 return;
2883 prs_force_dynamic(&src->prs);
2884 prs_mem_clear(&src->prs);
2885 *dest=src;
2888 /*******************************************************************
2889 Get the size of a BUFFER struct.
2890 ********************************************************************/
2892 uint32 new_get_buffer_size(NEW_BUFFER *buffer)
2894 return (buffer->size);
2897 /*******************************************************************
2898 Parse a DRIVER_DIRECTORY_1 structure.
2899 ********************************************************************/
2901 BOOL smb_io_driverdir_1(const char *desc, NEW_BUFFER *buffer, DRIVER_DIRECTORY_1 *info, int depth)
2903 prs_struct *ps=&buffer->prs;
2905 prs_debug(ps, depth, desc, "smb_io_driverdir_1");
2906 depth++;
2908 buffer->struct_start=prs_offset(ps);
2910 if (!smb_io_unistr(desc, &info->name, ps, depth))
2911 return False;
2913 return True;
2916 /*******************************************************************
2917 Parse a PORT_INFO_1 structure.
2918 ********************************************************************/
2920 BOOL smb_io_port_1(const char *desc, NEW_BUFFER *buffer, PORT_INFO_1 *info, int depth)
2922 prs_struct *ps=&buffer->prs;
2924 prs_debug(ps, depth, desc, "smb_io_port_1");
2925 depth++;
2927 buffer->struct_start=prs_offset(ps);
2929 if(!smb_io_relstr("port_name", buffer, depth, &info->port_name))
2930 return False;
2932 return True;
2935 /*******************************************************************
2936 Parse a PORT_INFO_2 structure.
2937 ********************************************************************/
2939 BOOL smb_io_port_2(const char *desc, NEW_BUFFER *buffer, PORT_INFO_2 *info, int depth)
2941 prs_struct *ps=&buffer->prs;
2943 prs_debug(ps, depth, desc, "smb_io_port_2");
2944 depth++;
2946 buffer->struct_start=prs_offset(ps);
2948 if(!smb_io_relstr("port_name", buffer, depth, &info->port_name))
2949 return False;
2950 if(!smb_io_relstr("monitor_name", buffer, depth, &info->monitor_name))
2951 return False;
2952 if(!smb_io_relstr("description", buffer, depth, &info->description))
2953 return False;
2954 if(!prs_uint32("port_type", ps, depth, &info->port_type))
2955 return False;
2956 if(!prs_uint32("reserved", ps, depth, &info->reserved))
2957 return False;
2959 return True;
2962 /*******************************************************************
2963 ********************************************************************/
2965 BOOL smb_io_printprocessor_info_1(const char *desc, NEW_BUFFER *buffer, PRINTPROCESSOR_1 *info, int depth)
2967 prs_struct *ps=&buffer->prs;
2969 prs_debug(ps, depth, desc, "smb_io_printprocessor_info_1");
2970 depth++;
2972 buffer->struct_start=prs_offset(ps);
2974 if (smb_io_relstr("name", buffer, depth, &info->name))
2975 return False;
2977 return True;
2980 /*******************************************************************
2981 ********************************************************************/
2983 BOOL smb_io_printprocdatatype_info_1(const char *desc, NEW_BUFFER *buffer, PRINTPROCDATATYPE_1 *info, int depth)
2985 prs_struct *ps=&buffer->prs;
2987 prs_debug(ps, depth, desc, "smb_io_printprocdatatype_info_1");
2988 depth++;
2990 buffer->struct_start=prs_offset(ps);
2992 if (smb_io_relstr("name", buffer, depth, &info->name))
2993 return False;
2995 return True;
2998 /*******************************************************************
2999 ********************************************************************/
3001 BOOL smb_io_printmonitor_info_1(const char *desc, NEW_BUFFER *buffer, PRINTMONITOR_1 *info, int depth)
3003 prs_struct *ps=&buffer->prs;
3005 prs_debug(ps, depth, desc, "smb_io_printmonitor_info_1");
3006 depth++;
3008 buffer->struct_start=prs_offset(ps);
3010 if (!smb_io_relstr("name", buffer, depth, &info->name))
3011 return False;
3013 return True;
3016 /*******************************************************************
3017 ********************************************************************/
3019 BOOL smb_io_printmonitor_info_2(const char *desc, NEW_BUFFER *buffer, PRINTMONITOR_2 *info, int depth)
3021 prs_struct *ps=&buffer->prs;
3023 prs_debug(ps, depth, desc, "smb_io_printmonitor_info_2");
3024 depth++;
3026 buffer->struct_start=prs_offset(ps);
3028 if (!smb_io_relstr("name", buffer, depth, &info->name))
3029 return False;
3030 if (!smb_io_relstr("environment", buffer, depth, &info->environment))
3031 return False;
3032 if (!smb_io_relstr("dll_name", buffer, depth, &info->dll_name))
3033 return False;
3035 return True;
3038 /*******************************************************************
3039 return the size required by a struct in the stream
3040 ********************************************************************/
3042 uint32 spoolss_size_printer_info_0(PRINTER_INFO_0 *info)
3044 int size=0;
3046 size+=size_of_relative_string( &info->printername );
3047 size+=size_of_relative_string( &info->servername );
3049 size+=size_of_uint32( &info->cjobs);
3050 size+=size_of_uint32( &info->total_jobs);
3051 size+=size_of_uint32( &info->total_bytes);
3053 size+=size_of_uint16( &info->year);
3054 size+=size_of_uint16( &info->month);
3055 size+=size_of_uint16( &info->dayofweek);
3056 size+=size_of_uint16( &info->day);
3057 size+=size_of_uint16( &info->hour);
3058 size+=size_of_uint16( &info->minute);
3059 size+=size_of_uint16( &info->second);
3060 size+=size_of_uint16( &info->milliseconds);
3062 size+=size_of_uint32( &info->global_counter);
3063 size+=size_of_uint32( &info->total_pages);
3065 size+=size_of_uint16( &info->major_version);
3066 size+=size_of_uint16( &info->build_version);
3068 size+=size_of_uint32( &info->unknown7);
3069 size+=size_of_uint32( &info->unknown8);
3070 size+=size_of_uint32( &info->unknown9);
3071 size+=size_of_uint32( &info->session_counter);
3072 size+=size_of_uint32( &info->unknown11);
3073 size+=size_of_uint32( &info->printer_errors);
3074 size+=size_of_uint32( &info->unknown13);
3075 size+=size_of_uint32( &info->unknown14);
3076 size+=size_of_uint32( &info->unknown15);
3077 size+=size_of_uint32( &info->unknown16);
3078 size+=size_of_uint32( &info->change_id);
3079 size+=size_of_uint32( &info->unknown18);
3080 size+=size_of_uint32( &info->status);
3081 size+=size_of_uint32( &info->unknown20);
3082 size+=size_of_uint32( &info->c_setprinter);
3084 size+=size_of_uint16( &info->unknown22);
3085 size+=size_of_uint16( &info->unknown23);
3086 size+=size_of_uint16( &info->unknown24);
3087 size+=size_of_uint16( &info->unknown25);
3088 size+=size_of_uint16( &info->unknown26);
3089 size+=size_of_uint16( &info->unknown27);
3090 size+=size_of_uint16( &info->unknown28);
3091 size+=size_of_uint16( &info->unknown29);
3093 return size;
3096 /*******************************************************************
3097 return the size required by a struct in the stream
3098 ********************************************************************/
3100 uint32 spoolss_size_printer_info_1(PRINTER_INFO_1 *info)
3102 int size=0;
3104 size+=size_of_uint32( &info->flags );
3105 size+=size_of_relative_string( &info->description );
3106 size+=size_of_relative_string( &info->name );
3107 size+=size_of_relative_string( &info->comment );
3109 return size;
3112 /*******************************************************************
3113 return the size required by a struct in the stream
3114 ********************************************************************/
3116 uint32 spoolss_size_printer_info_2(PRINTER_INFO_2 *info)
3118 uint32 size=0;
3120 size += 4;
3122 size += sec_desc_size( info->secdesc );
3124 size+=size_of_device_mode( info->devmode );
3126 size+=size_of_relative_string( &info->servername );
3127 size+=size_of_relative_string( &info->printername );
3128 size+=size_of_relative_string( &info->sharename );
3129 size+=size_of_relative_string( &info->portname );
3130 size+=size_of_relative_string( &info->drivername );
3131 size+=size_of_relative_string( &info->comment );
3132 size+=size_of_relative_string( &info->location );
3134 size+=size_of_relative_string( &info->sepfile );
3135 size+=size_of_relative_string( &info->printprocessor );
3136 size+=size_of_relative_string( &info->datatype );
3137 size+=size_of_relative_string( &info->parameters );
3139 size+=size_of_uint32( &info->attributes );
3140 size+=size_of_uint32( &info->priority );
3141 size+=size_of_uint32( &info->defaultpriority );
3142 size+=size_of_uint32( &info->starttime );
3143 size+=size_of_uint32( &info->untiltime );
3144 size+=size_of_uint32( &info->status );
3145 size+=size_of_uint32( &info->cjobs );
3146 size+=size_of_uint32( &info->averageppm );
3149 * add any adjustments for alignment. This is
3150 * not optimal since we could be calling this
3151 * function from a loop (e.g. enumprinters), but
3152 * it is easier to maintain the calculation here and
3153 * not place the burden on the caller to remember. --jerry
3155 if ((size % 4) != 0)
3156 size += 4 - (size % 4);
3158 return size;
3161 /*******************************************************************
3162 return the size required by a struct in the stream
3163 ********************************************************************/
3165 uint32 spoolss_size_printer_info_4(PRINTER_INFO_4 *info)
3167 uint32 size=0;
3169 size+=size_of_relative_string( &info->printername );
3170 size+=size_of_relative_string( &info->servername );
3172 size+=size_of_uint32( &info->attributes );
3173 return size;
3176 /*******************************************************************
3177 return the size required by a struct in the stream
3178 ********************************************************************/
3180 uint32 spoolss_size_printer_info_5(PRINTER_INFO_5 *info)
3182 uint32 size=0;
3184 size+=size_of_relative_string( &info->printername );
3185 size+=size_of_relative_string( &info->portname );
3187 size+=size_of_uint32( &info->attributes );
3188 size+=size_of_uint32( &info->device_not_selected_timeout );
3189 size+=size_of_uint32( &info->transmission_retry_timeout );
3190 return size;
3194 /*******************************************************************
3195 return the size required by a struct in the stream
3196 ********************************************************************/
3198 uint32 spoolss_size_printer_info_3(PRINTER_INFO_3 *info)
3200 /* The 4 is for the self relative pointer.. */
3201 /* JRA !!!! TESTME - WHAT ABOUT prs_align.... !!! */
3202 return 4 + (uint32)sec_desc_size( info->secdesc );
3205 /*******************************************************************
3206 return the size required by a struct in the stream
3207 ********************************************************************/
3209 uint32 spoolss_size_printer_driver_info_1(DRIVER_INFO_1 *info)
3211 int size=0;
3212 size+=size_of_relative_string( &info->name );
3214 return size;
3217 /*******************************************************************
3218 return the size required by a struct in the stream
3219 ********************************************************************/
3221 uint32 spoolss_size_printer_driver_info_2(DRIVER_INFO_2 *info)
3223 int size=0;
3224 size+=size_of_uint32( &info->version );
3225 size+=size_of_relative_string( &info->name );
3226 size+=size_of_relative_string( &info->architecture );
3227 size+=size_of_relative_string( &info->driverpath );
3228 size+=size_of_relative_string( &info->datafile );
3229 size+=size_of_relative_string( &info->configfile );
3231 return size;
3234 /*******************************************************************
3235 return the size required by a string array.
3236 ********************************************************************/
3238 uint32 spoolss_size_string_array(uint16 *string)
3240 uint32 i = 0;
3242 if (string) {
3243 for (i=0; (string[i]!=0x0000) || (string[i+1]!=0x0000); i++);
3245 i=i+2; /* to count all chars including the leading zero */
3246 i=2*i; /* because we need the value in bytes */
3247 i=i+4; /* the offset pointer size */
3249 return i;
3252 /*******************************************************************
3253 return the size required by a struct in the stream
3254 ********************************************************************/
3256 uint32 spoolss_size_printer_driver_info_3(DRIVER_INFO_3 *info)
3258 int size=0;
3260 size+=size_of_uint32( &info->version );
3261 size+=size_of_relative_string( &info->name );
3262 size+=size_of_relative_string( &info->architecture );
3263 size+=size_of_relative_string( &info->driverpath );
3264 size+=size_of_relative_string( &info->datafile );
3265 size+=size_of_relative_string( &info->configfile );
3266 size+=size_of_relative_string( &info->helpfile );
3267 size+=size_of_relative_string( &info->monitorname );
3268 size+=size_of_relative_string( &info->defaultdatatype );
3270 size+=spoolss_size_string_array(info->dependentfiles);
3272 return size;
3275 /*******************************************************************
3276 return the size required by a struct in the stream
3277 ********************************************************************/
3279 uint32 spoolss_size_printer_driver_info_6(DRIVER_INFO_6 *info)
3281 uint32 size=0;
3283 size+=size_of_uint32( &info->version );
3284 size+=size_of_relative_string( &info->name );
3285 size+=size_of_relative_string( &info->architecture );
3286 size+=size_of_relative_string( &info->driverpath );
3287 size+=size_of_relative_string( &info->datafile );
3288 size+=size_of_relative_string( &info->configfile );
3289 size+=size_of_relative_string( &info->helpfile );
3291 size+=spoolss_size_string_array(info->dependentfiles);
3293 size+=size_of_relative_string( &info->monitorname );
3294 size+=size_of_relative_string( &info->defaultdatatype );
3296 size+=spoolss_size_string_array(info->previousdrivernames);
3298 size+=size_of_nttime(&info->driver_date);
3299 size+=size_of_uint32( &info->padding );
3300 size+=size_of_uint32( &info->driver_version_low );
3301 size+=size_of_uint32( &info->driver_version_high );
3302 size+=size_of_relative_string( &info->mfgname );
3303 size+=size_of_relative_string( &info->oem_url );
3304 size+=size_of_relative_string( &info->hardware_id );
3305 size+=size_of_relative_string( &info->provider );
3307 return size;
3310 /*******************************************************************
3311 return the size required by a struct in the stream
3312 ********************************************************************/
3314 uint32 spoolss_size_job_info_1(JOB_INFO_1 *info)
3316 int size=0;
3317 size+=size_of_uint32( &info->jobid );
3318 size+=size_of_relative_string( &info->printername );
3319 size+=size_of_relative_string( &info->machinename );
3320 size+=size_of_relative_string( &info->username );
3321 size+=size_of_relative_string( &info->document );
3322 size+=size_of_relative_string( &info->datatype );
3323 size+=size_of_relative_string( &info->text_status );
3324 size+=size_of_uint32( &info->status );
3325 size+=size_of_uint32( &info->priority );
3326 size+=size_of_uint32( &info->position );
3327 size+=size_of_uint32( &info->totalpages );
3328 size+=size_of_uint32( &info->pagesprinted );
3329 size+=size_of_systemtime( &info->submitted );
3331 return size;
3334 /*******************************************************************
3335 return the size required by a struct in the stream
3336 ********************************************************************/
3338 uint32 spoolss_size_job_info_2(JOB_INFO_2 *info)
3340 int size=0;
3342 size+=4; /* size of sec desc ptr */
3344 size+=size_of_uint32( &info->jobid );
3345 size+=size_of_relative_string( &info->printername );
3346 size+=size_of_relative_string( &info->machinename );
3347 size+=size_of_relative_string( &info->username );
3348 size+=size_of_relative_string( &info->document );
3349 size+=size_of_relative_string( &info->notifyname );
3350 size+=size_of_relative_string( &info->datatype );
3351 size+=size_of_relative_string( &info->printprocessor );
3352 size+=size_of_relative_string( &info->parameters );
3353 size+=size_of_relative_string( &info->drivername );
3354 size+=size_of_device_mode( info->devmode );
3355 size+=size_of_relative_string( &info->text_status );
3356 /* SEC_DESC sec_desc;*/
3357 size+=size_of_uint32( &info->status );
3358 size+=size_of_uint32( &info->priority );
3359 size+=size_of_uint32( &info->position );
3360 size+=size_of_uint32( &info->starttime );
3361 size+=size_of_uint32( &info->untiltime );
3362 size+=size_of_uint32( &info->totalpages );
3363 size+=size_of_uint32( &info->size );
3364 size+=size_of_systemtime( &info->submitted );
3365 size+=size_of_uint32( &info->timeelapsed );
3366 size+=size_of_uint32( &info->pagesprinted );
3368 return size;
3371 /*******************************************************************
3372 return the size required by a struct in the stream
3373 ********************************************************************/
3375 uint32 spoolss_size_form_1(FORM_1 *info)
3377 int size=0;
3379 size+=size_of_uint32( &info->flag );
3380 size+=size_of_relative_string( &info->name );
3381 size+=size_of_uint32( &info->width );
3382 size+=size_of_uint32( &info->length );
3383 size+=size_of_uint32( &info->left );
3384 size+=size_of_uint32( &info->top );
3385 size+=size_of_uint32( &info->right );
3386 size+=size_of_uint32( &info->bottom );
3388 return size;
3391 /*******************************************************************
3392 return the size required by a struct in the stream
3393 ********************************************************************/
3395 uint32 spoolss_size_port_info_1(PORT_INFO_1 *info)
3397 int size=0;
3399 size+=size_of_relative_string( &info->port_name );
3401 return size;
3404 /*******************************************************************
3405 return the size required by a struct in the stream
3406 ********************************************************************/
3408 uint32 spoolss_size_driverdir_info_1(DRIVER_DIRECTORY_1 *info)
3410 int size=0;
3412 size=str_len_uni(&info->name); /* the string length */
3413 size=size+1; /* add the leading zero */
3414 size=size*2; /* convert in char */
3416 return size;
3419 /*******************************************************************
3420 return the size required by a struct in the stream
3421 ********************************************************************/
3423 uint32 spoolss_size_printprocessordirectory_info_1(PRINTPROCESSOR_DIRECTORY_1 *info)
3425 int size=0;
3427 size=str_len_uni(&info->name); /* the string length */
3428 size=size+1; /* add the leading zero */
3429 size=size*2; /* convert in char */
3431 return size;
3434 /*******************************************************************
3435 return the size required by a struct in the stream
3436 ********************************************************************/
3438 uint32 spoolss_size_port_info_2(PORT_INFO_2 *info)
3440 int size=0;
3442 size+=size_of_relative_string( &info->port_name );
3443 size+=size_of_relative_string( &info->monitor_name );
3444 size+=size_of_relative_string( &info->description );
3446 size+=size_of_uint32( &info->port_type );
3447 size+=size_of_uint32( &info->reserved );
3449 return size;
3452 /*******************************************************************
3453 return the size required by a struct in the stream
3454 ********************************************************************/
3456 uint32 spoolss_size_printprocessor_info_1(PRINTPROCESSOR_1 *info)
3458 int size=0;
3459 size+=size_of_relative_string( &info->name );
3461 return size;
3464 /*******************************************************************
3465 return the size required by a struct in the stream
3466 ********************************************************************/
3468 uint32 spoolss_size_printprocdatatype_info_1(PRINTPROCDATATYPE_1 *info)
3470 int size=0;
3471 size+=size_of_relative_string( &info->name );
3473 return size;
3476 /*******************************************************************
3477 return the size required by a struct in the stream
3478 ********************************************************************/
3479 uint32 spoolss_size_printer_enum_values(PRINTER_ENUM_VALUES *p)
3481 uint32 size = 0;
3483 if (!p)
3484 return 0;
3486 /* uint32(offset) + uint32(length) + length) */
3487 size += (size_of_uint32(&p->value_len)*2) + p->value_len;
3488 size += (size_of_uint32(&p->data_len)*2) + p->data_len + (p->data_len%2) ;
3490 size += size_of_uint32(&p->type);
3492 return size;
3495 /*******************************************************************
3496 return the size required by a struct in the stream
3497 ********************************************************************/
3499 uint32 spoolss_size_printmonitor_info_1(PRINTMONITOR_1 *info)
3501 int size=0;
3502 size+=size_of_relative_string( &info->name );
3504 return size;
3507 /*******************************************************************
3508 return the size required by a struct in the stream
3509 ********************************************************************/
3511 uint32 spoolss_size_printmonitor_info_2(PRINTMONITOR_2 *info)
3513 int size=0;
3514 size+=size_of_relative_string( &info->name);
3515 size+=size_of_relative_string( &info->environment);
3516 size+=size_of_relative_string( &info->dll_name);
3518 return size;
3521 /*******************************************************************
3522 * init a structure.
3523 ********************************************************************/
3525 BOOL make_spoolss_q_getprinterdriver2(SPOOL_Q_GETPRINTERDRIVER2 *q_u,
3526 const POLICY_HND *hnd,
3527 const fstring architecture,
3528 uint32 level, uint32 clientmajor, uint32 clientminor,
3529 NEW_BUFFER *buffer, uint32 offered)
3531 if (q_u == NULL)
3532 return False;
3534 memcpy(&q_u->handle, hnd, sizeof(q_u->handle));
3536 init_buf_unistr2(&q_u->architecture, &q_u->architecture_ptr, architecture);
3538 q_u->level=level;
3539 q_u->clientmajorversion=clientmajor;
3540 q_u->clientminorversion=clientminor;
3542 q_u->buffer=buffer;
3543 q_u->offered=offered;
3545 return True;
3548 /*******************************************************************
3549 * read a structure.
3550 * called from spoolss_getprinterdriver2 (srv_spoolss.c)
3551 ********************************************************************/
3553 BOOL spoolss_io_q_getprinterdriver2(const char *desc, SPOOL_Q_GETPRINTERDRIVER2 *q_u, prs_struct *ps, int depth)
3555 prs_debug(ps, depth, desc, "spoolss_io_q_getprinterdriver2");
3556 depth++;
3558 if(!prs_align(ps))
3559 return False;
3561 if(!smb_io_pol_hnd("printer handle", &q_u->handle, ps, depth))
3562 return False;
3563 if(!prs_uint32("architecture_ptr", ps, depth, &q_u->architecture_ptr))
3564 return False;
3565 if(!smb_io_unistr2("architecture", &q_u->architecture, q_u->architecture_ptr, ps, depth))
3566 return False;
3568 if(!prs_align(ps))
3569 return False;
3570 if(!prs_uint32("level", ps, depth, &q_u->level))
3571 return False;
3573 if(!spoolss_io_buffer("", ps, depth, &q_u->buffer))
3574 return False;
3576 if(!prs_align(ps))
3577 return False;
3579 if(!prs_uint32("offered", ps, depth, &q_u->offered))
3580 return False;
3582 if(!prs_uint32("clientmajorversion", ps, depth, &q_u->clientmajorversion))
3583 return False;
3584 if(!prs_uint32("clientminorversion", ps, depth, &q_u->clientminorversion))
3585 return False;
3587 return True;
3590 /*******************************************************************
3591 * read a structure.
3592 * called from spoolss_getprinterdriver2 (srv_spoolss.c)
3593 ********************************************************************/
3595 BOOL spoolss_io_r_getprinterdriver2(const char *desc, SPOOL_R_GETPRINTERDRIVER2 *r_u, prs_struct *ps, int depth)
3597 prs_debug(ps, depth, desc, "spoolss_io_r_getprinterdriver2");
3598 depth++;
3600 if (!prs_align(ps))
3601 return False;
3603 if (!spoolss_io_buffer("", ps, depth, &r_u->buffer))
3604 return False;
3606 if (!prs_align(ps))
3607 return False;
3608 if (!prs_uint32("needed", ps, depth, &r_u->needed))
3609 return False;
3610 if (!prs_uint32("servermajorversion", ps, depth, &r_u->servermajorversion))
3611 return False;
3612 if (!prs_uint32("serverminorversion", ps, depth, &r_u->serverminorversion))
3613 return False;
3614 if (!prs_werror("status", ps, depth, &r_u->status))
3615 return False;
3617 return True;
3620 /*******************************************************************
3621 * init a structure.
3622 ********************************************************************/
3624 BOOL make_spoolss_q_enumprinters(
3625 SPOOL_Q_ENUMPRINTERS *q_u,
3626 uint32 flags,
3627 fstring servername,
3628 uint32 level,
3629 NEW_BUFFER *buffer,
3630 uint32 offered
3633 q_u->flags=flags;
3635 q_u->servername_ptr = (servername != NULL) ? 1 : 0;
3636 init_buf_unistr2(&q_u->servername, &q_u->servername_ptr, servername);
3638 q_u->level=level;
3639 q_u->buffer=buffer;
3640 q_u->offered=offered;
3642 return True;
3645 /*******************************************************************
3646 * init a structure.
3647 ********************************************************************/
3649 BOOL make_spoolss_q_enumports(SPOOL_Q_ENUMPORTS *q_u,
3650 fstring servername, uint32 level,
3651 NEW_BUFFER *buffer, uint32 offered)
3653 q_u->name_ptr = (servername != NULL) ? 1 : 0;
3654 init_buf_unistr2(&q_u->name, &q_u->name_ptr, servername);
3656 q_u->level=level;
3657 q_u->buffer=buffer;
3658 q_u->offered=offered;
3660 return True;
3663 /*******************************************************************
3664 * read a structure.
3665 * called from spoolss_enumprinters (srv_spoolss.c)
3666 ********************************************************************/
3668 BOOL spoolss_io_q_enumprinters(const char *desc, SPOOL_Q_ENUMPRINTERS *q_u, prs_struct *ps, int depth)
3670 prs_debug(ps, depth, desc, "spoolss_io_q_enumprinters");
3671 depth++;
3673 if (!prs_align(ps))
3674 return False;
3676 if (!prs_uint32("flags", ps, depth, &q_u->flags))
3677 return False;
3678 if (!prs_uint32("servername_ptr", ps, depth, &q_u->servername_ptr))
3679 return False;
3681 if (!smb_io_unistr2("", &q_u->servername, q_u->servername_ptr, ps, depth))
3682 return False;
3684 if (!prs_align(ps))
3685 return False;
3686 if (!prs_uint32("level", ps, depth, &q_u->level))
3687 return False;
3689 if (!spoolss_io_buffer("", ps, depth, &q_u->buffer))
3690 return False;
3692 if (!prs_align(ps))
3693 return False;
3694 if (!prs_uint32("offered", ps, depth, &q_u->offered))
3695 return False;
3697 return True;
3700 /*******************************************************************
3701 Parse a SPOOL_R_ENUMPRINTERS structure.
3702 ********************************************************************/
3704 BOOL spoolss_io_r_enumprinters(const char *desc, SPOOL_R_ENUMPRINTERS *r_u, prs_struct *ps, int depth)
3706 prs_debug(ps, depth, desc, "spoolss_io_r_enumprinters");
3707 depth++;
3709 if (!prs_align(ps))
3710 return False;
3712 if (!spoolss_io_buffer("", ps, depth, &r_u->buffer))
3713 return False;
3715 if (!prs_align(ps))
3716 return False;
3718 if (!prs_uint32("needed", ps, depth, &r_u->needed))
3719 return False;
3721 if (!prs_uint32("returned", ps, depth, &r_u->returned))
3722 return False;
3724 if (!prs_werror("status", ps, depth, &r_u->status))
3725 return False;
3727 return True;
3730 /*******************************************************************
3731 * write a structure.
3732 * called from spoolss_r_enum_printers (srv_spoolss.c)
3734 ********************************************************************/
3736 BOOL spoolss_io_r_getprinter(const char *desc, SPOOL_R_GETPRINTER *r_u, prs_struct *ps, int depth)
3738 prs_debug(ps, depth, desc, "spoolss_io_r_getprinter");
3739 depth++;
3741 if (!prs_align(ps))
3742 return False;
3744 if (!spoolss_io_buffer("", ps, depth, &r_u->buffer))
3745 return False;
3747 if (!prs_align(ps))
3748 return False;
3750 if (!prs_uint32("needed", ps, depth, &r_u->needed))
3751 return False;
3753 if (!prs_werror("status", ps, depth, &r_u->status))
3754 return False;
3756 return True;
3759 /*******************************************************************
3760 * read a structure.
3761 * called from spoolss_getprinter (srv_spoolss.c)
3762 ********************************************************************/
3764 BOOL spoolss_io_q_getprinter(const char *desc, SPOOL_Q_GETPRINTER *q_u, prs_struct *ps, int depth)
3766 prs_debug(ps, depth, desc, "spoolss_io_q_getprinter");
3767 depth++;
3769 if (!prs_align(ps))
3770 return False;
3772 if(!smb_io_pol_hnd("printer handle", &q_u->handle, ps, depth))
3773 return False;
3774 if (!prs_uint32("level", ps, depth, &q_u->level))
3775 return False;
3777 if (!spoolss_io_buffer("", ps, depth, &q_u->buffer))
3778 return False;
3780 if (!prs_align(ps))
3781 return False;
3782 if (!prs_uint32("offered", ps, depth, &q_u->offered))
3783 return False;
3785 return True;
3788 /*******************************************************************
3789 * init a structure.
3790 ********************************************************************/
3792 BOOL make_spoolss_q_getprinter(
3793 TALLOC_CTX *mem_ctx,
3794 SPOOL_Q_GETPRINTER *q_u,
3795 const POLICY_HND *hnd,
3796 uint32 level,
3797 NEW_BUFFER *buffer,
3798 uint32 offered
3801 if (q_u == NULL)
3803 return False;
3805 memcpy(&q_u->handle, hnd, sizeof(q_u->handle));
3807 q_u->level=level;
3808 q_u->buffer=buffer;
3809 q_u->offered=offered;
3811 return True;
3814 /*******************************************************************
3815 * init a structure.
3816 ********************************************************************/
3817 BOOL make_spoolss_q_setprinter(TALLOC_CTX *mem_ctx, SPOOL_Q_SETPRINTER *q_u,
3818 const POLICY_HND *hnd, uint32 level, PRINTER_INFO_CTR *info,
3819 uint32 command)
3821 SEC_DESC *secdesc;
3822 DEVICEMODE *devmode;
3824 if (q_u == NULL)
3825 return False;
3827 memcpy(&q_u->handle, hnd, sizeof(q_u->handle));
3829 q_u->level = level;
3830 q_u->info.level = level;
3831 q_u->info.info_ptr = (info != NULL) ? 1 : 0;
3832 switch (level) {
3834 /* There's no such thing as a setprinter level 1 */
3836 case 2:
3837 secdesc = info->printers_2->secdesc;
3838 devmode = info->printers_2->devmode;
3840 make_spoolss_printer_info_2 (mem_ctx, &q_u->info.info_2, info->printers_2);
3841 #if 1 /* JERRY TEST */
3842 q_u->secdesc_ctr = (SEC_DESC_BUF*)malloc(sizeof(SEC_DESC_BUF));
3843 if (!q_u->secdesc_ctr)
3844 return False;
3845 q_u->secdesc_ctr->ptr = (secdesc != NULL) ? 1: 0;
3846 q_u->secdesc_ctr->max_len = (secdesc) ? sizeof(SEC_DESC) + (2*sizeof(uint32)) : 0;
3847 q_u->secdesc_ctr->len = (secdesc) ? sizeof(SEC_DESC) + (2*sizeof(uint32)) : 0;
3848 q_u->secdesc_ctr->sec = secdesc;
3850 q_u->devmode_ctr.devmode_ptr = (devmode != NULL) ? 1 : 0;
3851 q_u->devmode_ctr.size = (devmode != NULL) ? sizeof(DEVICEMODE) + (3*sizeof(uint32)) : 0;
3852 q_u->devmode_ctr.devmode = devmode;
3853 #else
3854 q_u->secdesc_ctr = NULL;
3856 q_u->devmode_ctr.devmode_ptr = 0;
3857 q_u->devmode_ctr.size = 0;
3858 q_u->devmode_ctr.devmode = NULL;
3859 #endif
3860 break;
3861 default:
3862 DEBUG(0,("make_spoolss_q_setprinter: Unknown info level [%d]\n", level));
3863 break;
3867 q_u->command = command;
3869 return True;
3873 /*******************************************************************
3874 ********************************************************************/
3876 BOOL spoolss_io_r_setprinter(const char *desc, SPOOL_R_SETPRINTER *r_u, prs_struct *ps, int depth)
3878 prs_debug(ps, depth, desc, "spoolss_io_r_setprinter");
3879 depth++;
3881 if(!prs_align(ps))
3882 return False;
3884 if(!prs_werror("status", ps, depth, &r_u->status))
3885 return False;
3887 return True;
3890 /*******************************************************************
3891 Marshall/unmarshall a SPOOL_Q_SETPRINTER struct.
3892 ********************************************************************/
3894 BOOL spoolss_io_q_setprinter(const char *desc, SPOOL_Q_SETPRINTER *q_u, prs_struct *ps, int depth)
3896 uint32 ptr_sec_desc = 0;
3898 prs_debug(ps, depth, desc, "spoolss_io_q_setprinter");
3899 depth++;
3901 if(!prs_align(ps))
3902 return False;
3904 if(!smb_io_pol_hnd("printer handle", &q_u->handle ,ps, depth))
3905 return False;
3906 if(!prs_uint32("level", ps, depth, &q_u->level))
3907 return False;
3909 if(!spool_io_printer_info_level("", &q_u->info, ps, depth))
3910 return False;
3912 if (!spoolss_io_devmode_cont(desc, &q_u->devmode_ctr, ps, depth))
3913 return False;
3915 if(!prs_align(ps))
3916 return False;
3918 switch (q_u->level)
3920 case 2:
3922 ptr_sec_desc = q_u->info.info_2->secdesc_ptr;
3923 break;
3925 case 3:
3927 ptr_sec_desc = q_u->info.info_3->secdesc_ptr;
3928 break;
3931 if (ptr_sec_desc)
3933 if (!sec_io_desc_buf(desc, &q_u->secdesc_ctr, ps, depth))
3934 return False;
3935 } else {
3936 uint32 dummy = 0;
3938 /* Parse a NULL security descriptor. This should really
3939 happen inside the sec_io_desc_buf() function. */
3941 prs_debug(ps, depth, "", "sec_io_desc_buf");
3942 if (!prs_uint32("size", ps, depth + 1, &dummy))
3943 return False;
3944 if (!prs_uint32("ptr", ps, depth + 1, &dummy)) return
3945 False;
3948 if(!prs_uint32("command", ps, depth, &q_u->command))
3949 return False;
3951 return True;
3954 /*******************************************************************
3955 ********************************************************************/
3957 BOOL spoolss_io_r_fcpn(const char *desc, SPOOL_R_FCPN *r_u, prs_struct *ps, int depth)
3959 prs_debug(ps, depth, desc, "spoolss_io_r_fcpn");
3960 depth++;
3962 if(!prs_align(ps))
3963 return False;
3965 if(!prs_werror("status", ps, depth, &r_u->status))
3966 return False;
3968 return True;
3971 /*******************************************************************
3972 ********************************************************************/
3974 BOOL spoolss_io_q_fcpn(const char *desc, SPOOL_Q_FCPN *q_u, prs_struct *ps, int depth)
3977 prs_debug(ps, depth, desc, "spoolss_io_q_fcpn");
3978 depth++;
3980 if(!prs_align(ps))
3981 return False;
3983 if(!smb_io_pol_hnd("printer handle",&q_u->handle,ps,depth))
3984 return False;
3986 return True;
3990 /*******************************************************************
3991 ********************************************************************/
3993 BOOL spoolss_io_r_addjob(const char *desc, SPOOL_R_ADDJOB *r_u, prs_struct *ps, int depth)
3995 prs_debug(ps, depth, desc, "");
3996 depth++;
3998 if(!prs_align(ps))
3999 return False;
4001 if(!spoolss_io_buffer("", ps, depth, &r_u->buffer))
4002 return False;
4004 if(!prs_align(ps))
4005 return False;
4007 if(!prs_uint32("needed", ps, depth, &r_u->needed))
4008 return False;
4010 if(!prs_werror("status", ps, depth, &r_u->status))
4011 return False;
4013 return True;
4016 /*******************************************************************
4017 ********************************************************************/
4019 BOOL spoolss_io_q_addjob(const char *desc, SPOOL_Q_ADDJOB *q_u, prs_struct *ps, int depth)
4021 prs_debug(ps, depth, desc, "");
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;
4029 if(!prs_uint32("level", ps, depth, &q_u->level))
4030 return False;
4032 if(!spoolss_io_buffer("", ps, depth, &q_u->buffer))
4033 return False;
4035 if(!prs_align(ps))
4036 return False;
4038 if(!prs_uint32("offered", ps, depth, &q_u->offered))
4039 return False;
4041 return True;
4044 /*******************************************************************
4045 ********************************************************************/
4047 BOOL spoolss_io_r_enumjobs(const char *desc, SPOOL_R_ENUMJOBS *r_u, prs_struct *ps, int depth)
4049 prs_debug(ps, depth, desc, "spoolss_io_r_enumjobs");
4050 depth++;
4052 if (!prs_align(ps))
4053 return False;
4055 if (!spoolss_io_buffer("", ps, depth, &r_u->buffer))
4056 return False;
4058 if (!prs_align(ps))
4059 return False;
4061 if (!prs_uint32("needed", ps, depth, &r_u->needed))
4062 return False;
4064 if (!prs_uint32("returned", ps, depth, &r_u->returned))
4065 return False;
4067 if (!prs_werror("status", ps, depth, &r_u->status))
4068 return False;
4070 return True;
4073 /*******************************************************************
4074 ********************************************************************/
4076 BOOL make_spoolss_q_enumjobs(SPOOL_Q_ENUMJOBS *q_u, const POLICY_HND *hnd,
4077 uint32 firstjob,
4078 uint32 numofjobs,
4079 uint32 level,
4080 NEW_BUFFER *buffer,
4081 uint32 offered)
4083 if (q_u == NULL)
4085 return False;
4087 memcpy(&q_u->handle, hnd, sizeof(q_u->handle));
4088 q_u->firstjob = firstjob;
4089 q_u->numofjobs = numofjobs;
4090 q_u->level = level;
4091 q_u->buffer= buffer;
4092 q_u->offered = offered;
4093 return True;
4096 /*******************************************************************
4097 ********************************************************************/
4099 BOOL spoolss_io_q_enumjobs(const char *desc, SPOOL_Q_ENUMJOBS *q_u, prs_struct *ps, int depth)
4101 prs_debug(ps, depth, desc, "spoolss_io_q_enumjobs");
4102 depth++;
4104 if (!prs_align(ps))
4105 return False;
4107 if (!smb_io_pol_hnd("printer handle",&q_u->handle, ps, depth))
4108 return False;
4110 if (!prs_uint32("firstjob", ps, depth, &q_u->firstjob))
4111 return False;
4112 if (!prs_uint32("numofjobs", ps, depth, &q_u->numofjobs))
4113 return False;
4114 if (!prs_uint32("level", ps, depth, &q_u->level))
4115 return False;
4117 if (!spoolss_io_buffer("", ps, depth, &q_u->buffer))
4118 return False;
4120 if(!prs_align(ps))
4121 return False;
4123 if (!prs_uint32("offered", ps, depth, &q_u->offered))
4124 return False;
4126 return True;
4129 /*******************************************************************
4130 ********************************************************************/
4132 BOOL spoolss_io_r_schedulejob(const char *desc, SPOOL_R_SCHEDULEJOB *r_u, prs_struct *ps, int depth)
4134 prs_debug(ps, depth, desc, "spoolss_io_r_schedulejob");
4135 depth++;
4137 if(!prs_align(ps))
4138 return False;
4140 if(!prs_werror("status", ps, depth, &r_u->status))
4141 return False;
4143 return True;
4146 /*******************************************************************
4147 ********************************************************************/
4149 BOOL spoolss_io_q_schedulejob(const char *desc, SPOOL_Q_SCHEDULEJOB *q_u, prs_struct *ps, int depth)
4151 prs_debug(ps, depth, desc, "spoolss_io_q_schedulejob");
4152 depth++;
4154 if(!prs_align(ps))
4155 return False;
4157 if(!smb_io_pol_hnd("printer handle",&q_u->handle,ps,depth))
4158 return False;
4159 if(!prs_uint32("jobid", ps, depth, &q_u->jobid))
4160 return False;
4162 return True;
4165 /*******************************************************************
4166 ********************************************************************/
4168 BOOL spoolss_io_r_setjob(const char *desc, SPOOL_R_SETJOB *r_u, prs_struct *ps, int depth)
4170 prs_debug(ps, depth, desc, "spoolss_io_r_setjob");
4171 depth++;
4173 if(!prs_align(ps))
4174 return False;
4176 if(!prs_werror("status", ps, depth, &r_u->status))
4177 return False;
4179 return True;
4182 /*******************************************************************
4183 ********************************************************************/
4185 BOOL spoolss_io_q_setjob(const char *desc, SPOOL_Q_SETJOB *q_u, prs_struct *ps, int depth)
4187 prs_debug(ps, depth, desc, "spoolss_io_q_setjob");
4188 depth++;
4190 if(!prs_align(ps))
4191 return False;
4193 if(!smb_io_pol_hnd("printer handle",&q_u->handle,ps,depth))
4194 return False;
4195 if(!prs_uint32("jobid", ps, depth, &q_u->jobid))
4196 return False;
4198 * level is usually 0. If (level!=0) then I'm in trouble !
4199 * I will try to generate setjob command with level!=0, one day.
4201 if(!prs_uint32("level", ps, depth, &q_u->level))
4202 return False;
4203 if(!prs_uint32("command", ps, depth, &q_u->command))
4204 return False;
4206 return True;
4209 /*******************************************************************
4210 Parse a SPOOL_R_ENUMPRINTERDRIVERS structure.
4211 ********************************************************************/
4213 BOOL spoolss_io_r_enumprinterdrivers(const char *desc, SPOOL_R_ENUMPRINTERDRIVERS *r_u, prs_struct *ps, int depth)
4215 prs_debug(ps, depth, desc, "spoolss_io_r_enumprinterdrivers");
4216 depth++;
4218 if (!prs_align(ps))
4219 return False;
4221 if (!spoolss_io_buffer("", ps, depth, &r_u->buffer))
4222 return False;
4224 if (!prs_align(ps))
4225 return False;
4227 if (!prs_uint32("needed", ps, depth, &r_u->needed))
4228 return False;
4230 if (!prs_uint32("returned", ps, depth, &r_u->returned))
4231 return False;
4233 if (!prs_werror("status", ps, depth, &r_u->status))
4234 return False;
4236 return True;
4239 /*******************************************************************
4240 * init a structure.
4241 ********************************************************************/
4243 BOOL make_spoolss_q_enumprinterdrivers(SPOOL_Q_ENUMPRINTERDRIVERS *q_u,
4244 const char *name,
4245 const char *environment,
4246 uint32 level,
4247 NEW_BUFFER *buffer, uint32 offered)
4249 init_buf_unistr2(&q_u->name, &q_u->name_ptr, name);
4250 init_buf_unistr2(&q_u->environment, &q_u->environment_ptr, environment);
4252 q_u->level=level;
4253 q_u->buffer=buffer;
4254 q_u->offered=offered;
4256 return True;
4259 /*******************************************************************
4260 Parse a SPOOL_Q_ENUMPRINTERDRIVERS structure.
4261 ********************************************************************/
4263 BOOL spoolss_io_q_enumprinterdrivers(const char *desc, SPOOL_Q_ENUMPRINTERDRIVERS *q_u, prs_struct *ps, int depth)
4266 prs_debug(ps, depth, desc, "spoolss_io_q_enumprinterdrivers");
4267 depth++;
4269 if (!prs_align(ps))
4270 return False;
4272 if (!prs_uint32("name_ptr", ps, depth, &q_u->name_ptr))
4273 return False;
4274 if (!smb_io_unistr2("", &q_u->name, q_u->name_ptr,ps, depth))
4275 return False;
4277 if (!prs_align(ps))
4278 return False;
4279 if (!prs_uint32("environment_ptr", ps, depth, &q_u->environment_ptr))
4280 return False;
4281 if (!smb_io_unistr2("", &q_u->environment, q_u->environment_ptr, ps, depth))
4282 return False;
4284 if (!prs_align(ps))
4285 return False;
4286 if (!prs_uint32("level", ps, depth, &q_u->level))
4287 return False;
4289 if (!spoolss_io_buffer("", ps, depth, &q_u->buffer))
4290 return False;
4292 if (!prs_align(ps))
4293 return False;
4295 if (!prs_uint32("offered", ps, depth, &q_u->offered))
4296 return False;
4298 return True;
4301 /*******************************************************************
4302 ********************************************************************/
4304 BOOL spoolss_io_q_enumforms(const char *desc, SPOOL_Q_ENUMFORMS *q_u, prs_struct *ps, int depth)
4307 prs_debug(ps, depth, desc, "spoolss_io_q_enumforms");
4308 depth++;
4310 if (!prs_align(ps))
4311 return False;
4312 if (!smb_io_pol_hnd("printer handle",&q_u->handle,ps,depth))
4313 return False;
4314 if (!prs_uint32("level", ps, depth, &q_u->level))
4315 return False;
4317 if (!spoolss_io_buffer("", ps, depth, &q_u->buffer))
4318 return False;
4320 if (!prs_align(ps))
4321 return False;
4322 if (!prs_uint32("offered", ps, depth, &q_u->offered))
4323 return False;
4325 return True;
4328 /*******************************************************************
4329 ********************************************************************/
4331 BOOL spoolss_io_r_enumforms(const char *desc, SPOOL_R_ENUMFORMS *r_u, prs_struct *ps, int depth)
4333 prs_debug(ps, depth, desc, "spoolss_io_r_enumforms");
4334 depth++;
4336 if (!prs_align(ps))
4337 return False;
4339 if (!spoolss_io_buffer("", ps, depth, &r_u->buffer))
4340 return False;
4342 if (!prs_align(ps))
4343 return False;
4345 if (!prs_uint32("size of buffer needed", ps, depth, &r_u->needed))
4346 return False;
4348 if (!prs_uint32("numofforms", ps, depth, &r_u->numofforms))
4349 return False;
4351 if (!prs_werror("status", ps, depth, &r_u->status))
4352 return False;
4354 return True;
4357 /*******************************************************************
4358 ********************************************************************/
4360 BOOL spoolss_io_q_getform(const char *desc, SPOOL_Q_GETFORM *q_u, prs_struct *ps, int depth)
4363 prs_debug(ps, depth, desc, "spoolss_io_q_getform");
4364 depth++;
4366 if (!prs_align(ps))
4367 return False;
4368 if (!smb_io_pol_hnd("printer handle",&q_u->handle,ps,depth))
4369 return False;
4370 if (!smb_io_unistr2("", &q_u->formname,True,ps,depth))
4371 return False;
4373 if (!prs_align(ps))
4374 return False;
4376 if (!prs_uint32("level", ps, depth, &q_u->level))
4377 return False;
4379 if (!spoolss_io_buffer("", ps, depth, &q_u->buffer))
4380 return False;
4382 if (!prs_align(ps))
4383 return False;
4384 if (!prs_uint32("offered", ps, depth, &q_u->offered))
4385 return False;
4387 return True;
4390 /*******************************************************************
4391 ********************************************************************/
4393 BOOL spoolss_io_r_getform(const char *desc, SPOOL_R_GETFORM *r_u, prs_struct *ps, int depth)
4395 prs_debug(ps, depth, desc, "spoolss_io_r_getform");
4396 depth++;
4398 if (!prs_align(ps))
4399 return False;
4401 if (!spoolss_io_buffer("", ps, depth, &r_u->buffer))
4402 return False;
4404 if (!prs_align(ps))
4405 return False;
4407 if (!prs_uint32("size of buffer needed", ps, depth, &r_u->needed))
4408 return False;
4410 if (!prs_werror("status", ps, depth, &r_u->status))
4411 return False;
4413 return True;
4416 /*******************************************************************
4417 Parse a SPOOL_R_ENUMPORTS structure.
4418 ********************************************************************/
4420 BOOL spoolss_io_r_enumports(const char *desc, SPOOL_R_ENUMPORTS *r_u, prs_struct *ps, int depth)
4422 prs_debug(ps, depth, desc, "spoolss_io_r_enumports");
4423 depth++;
4425 if (!prs_align(ps))
4426 return False;
4428 if (!spoolss_io_buffer("", ps, depth, &r_u->buffer))
4429 return False;
4431 if (!prs_align(ps))
4432 return False;
4434 if (!prs_uint32("needed", ps, depth, &r_u->needed))
4435 return False;
4437 if (!prs_uint32("returned", ps, depth, &r_u->returned))
4438 return False;
4440 if (!prs_werror("status", ps, depth, &r_u->status))
4441 return False;
4443 return True;
4446 /*******************************************************************
4447 ********************************************************************/
4449 BOOL spoolss_io_q_enumports(const char *desc, SPOOL_Q_ENUMPORTS *q_u, prs_struct *ps, int depth)
4451 prs_debug(ps, depth, desc, "");
4452 depth++;
4454 if (!prs_align(ps))
4455 return False;
4457 if (!prs_uint32("", ps, depth, &q_u->name_ptr))
4458 return False;
4459 if (!smb_io_unistr2("", &q_u->name,True,ps,depth))
4460 return False;
4462 if (!prs_align(ps))
4463 return False;
4464 if (!prs_uint32("level", ps, depth, &q_u->level))
4465 return False;
4467 if (!spoolss_io_buffer("", ps, depth, &q_u->buffer))
4468 return False;
4470 if (!prs_align(ps))
4471 return False;
4472 if (!prs_uint32("offered", ps, depth, &q_u->offered))
4473 return False;
4475 return True;
4478 /*******************************************************************
4479 Parse a SPOOL_PRINTER_INFO_LEVEL_1 structure.
4480 ********************************************************************/
4482 BOOL spool_io_printer_info_level_1(const char *desc, SPOOL_PRINTER_INFO_LEVEL_1 *il, prs_struct *ps, int depth)
4484 prs_debug(ps, depth, desc, "spool_io_printer_info_level_1");
4485 depth++;
4487 if(!prs_align(ps))
4488 return False;
4490 if(!prs_uint32("flags", ps, depth, &il->flags))
4491 return False;
4492 if(!prs_uint32("description_ptr", ps, depth, &il->description_ptr))
4493 return False;
4494 if(!prs_uint32("name_ptr", ps, depth, &il->name_ptr))
4495 return False;
4496 if(!prs_uint32("comment_ptr", ps, depth, &il->comment_ptr))
4497 return False;
4499 if(!smb_io_unistr2("description", &il->description, il->description_ptr, ps, depth))
4500 return False;
4501 if(!smb_io_unistr2("name", &il->name, il->name_ptr, ps, depth))
4502 return False;
4503 if(!smb_io_unistr2("comment", &il->comment, il->comment_ptr, ps, depth))
4504 return False;
4506 return True;
4509 /*******************************************************************
4510 Parse a SPOOL_PRINTER_INFO_LEVEL_3 structure.
4511 ********************************************************************/
4513 BOOL spool_io_printer_info_level_3(const char *desc, SPOOL_PRINTER_INFO_LEVEL_3 *il, prs_struct *ps, int depth)
4515 prs_debug(ps, depth, desc, "spool_io_printer_info_level_3");
4516 depth++;
4518 if(!prs_align(ps))
4519 return False;
4521 if(!prs_uint32("secdesc_ptr", ps, depth, &il->secdesc_ptr))
4522 return False;
4524 return True;
4527 /*******************************************************************
4528 Parse a SPOOL_PRINTER_INFO_LEVEL_2 structure.
4529 ********************************************************************/
4531 BOOL spool_io_printer_info_level_2(const char *desc, SPOOL_PRINTER_INFO_LEVEL_2 *il, prs_struct *ps, int depth)
4533 prs_debug(ps, depth, desc, "spool_io_printer_info_level_2");
4534 depth++;
4536 if(!prs_align(ps))
4537 return False;
4539 if(!prs_uint32("servername_ptr", ps, depth, &il->servername_ptr))
4540 return False;
4541 if(!prs_uint32("printername_ptr", ps, depth, &il->printername_ptr))
4542 return False;
4543 if(!prs_uint32("sharename_ptr", ps, depth, &il->sharename_ptr))
4544 return False;
4545 if(!prs_uint32("portname_ptr", ps, depth, &il->portname_ptr))
4546 return False;
4548 if(!prs_uint32("drivername_ptr", ps, depth, &il->drivername_ptr))
4549 return False;
4550 if(!prs_uint32("comment_ptr", ps, depth, &il->comment_ptr))
4551 return False;
4552 if(!prs_uint32("location_ptr", ps, depth, &il->location_ptr))
4553 return False;
4554 if(!prs_uint32("devmode_ptr", ps, depth, &il->devmode_ptr))
4555 return False;
4556 if(!prs_uint32("sepfile_ptr", ps, depth, &il->sepfile_ptr))
4557 return False;
4558 if(!prs_uint32("printprocessor_ptr", ps, depth, &il->printprocessor_ptr))
4559 return False;
4560 if(!prs_uint32("datatype_ptr", ps, depth, &il->datatype_ptr))
4561 return False;
4562 if(!prs_uint32("parameters_ptr", ps, depth, &il->parameters_ptr))
4563 return False;
4564 if(!prs_uint32("secdesc_ptr", ps, depth, &il->secdesc_ptr))
4565 return False;
4567 if(!prs_uint32("attributes", ps, depth, &il->attributes))
4568 return False;
4569 if(!prs_uint32("priority", ps, depth, &il->priority))
4570 return False;
4571 if(!prs_uint32("default_priority", ps, depth, &il->default_priority))
4572 return False;
4573 if(!prs_uint32("starttime", ps, depth, &il->starttime))
4574 return False;
4575 if(!prs_uint32("untiltime", ps, depth, &il->untiltime))
4576 return False;
4577 if(!prs_uint32("status", ps, depth, &il->status))
4578 return False;
4579 if(!prs_uint32("cjobs", ps, depth, &il->cjobs))
4580 return False;
4581 if(!prs_uint32("averageppm", ps, depth, &il->averageppm))
4582 return False;
4584 if(!smb_io_unistr2("servername", &il->servername, il->servername_ptr, ps, depth))
4585 return False;
4586 if(!smb_io_unistr2("printername", &il->printername, il->printername_ptr, ps, depth))
4587 return False;
4588 if(!smb_io_unistr2("sharename", &il->sharename, il->sharename_ptr, ps, depth))
4589 return False;
4590 if(!smb_io_unistr2("portname", &il->portname, il->portname_ptr, ps, depth))
4591 return False;
4592 if(!smb_io_unistr2("drivername", &il->drivername, il->drivername_ptr, ps, depth))
4593 return False;
4594 if(!smb_io_unistr2("comment", &il->comment, il->comment_ptr, ps, depth))
4595 return False;
4596 if(!smb_io_unistr2("location", &il->location, il->location_ptr, ps, depth))
4597 return False;
4598 if(!smb_io_unistr2("sepfile", &il->sepfile, il->sepfile_ptr, ps, depth))
4599 return False;
4600 if(!smb_io_unistr2("printprocessor", &il->printprocessor, il->printprocessor_ptr, ps, depth))
4601 return False;
4602 if(!smb_io_unistr2("datatype", &il->datatype, il->datatype_ptr, ps, depth))
4603 return False;
4604 if(!smb_io_unistr2("parameters", &il->parameters, il->parameters_ptr, ps, depth))
4605 return False;
4607 return True;
4610 /*******************************************************************
4611 ********************************************************************/
4613 BOOL spool_io_printer_info_level(const char *desc, SPOOL_PRINTER_INFO_LEVEL *il, prs_struct *ps, int depth)
4615 prs_debug(ps, depth, desc, "spool_io_printer_info_level");
4616 depth++;
4618 if(!prs_align(ps))
4619 return False;
4620 if(!prs_uint32("level", ps, depth, &il->level))
4621 return False;
4622 if(!prs_uint32("info_ptr", ps, depth, &il->info_ptr))
4623 return False;
4625 /* if no struct inside just return */
4626 if (il->info_ptr==0) {
4627 if (UNMARSHALLING(ps)) {
4628 il->info_1=NULL;
4629 il->info_2=NULL;
4631 return True;
4634 switch (il->level) {
4636 * level 0 is used by setprinter when managing the queue
4637 * (hold, stop, start a queue)
4639 case 0:
4640 break;
4641 /* DOCUMENT ME!!! What is level 1 used for? */
4642 case 1:
4644 if (UNMARSHALLING(ps)) {
4645 if ((il->info_1=(SPOOL_PRINTER_INFO_LEVEL_1 *)prs_alloc_mem(ps,sizeof(SPOOL_PRINTER_INFO_LEVEL_1))) == NULL)
4646 return False;
4648 if (!spool_io_printer_info_level_1("", il->info_1, ps, depth))
4649 return False;
4650 break;
4653 * level 2 is used by addprinter
4654 * and by setprinter when updating printer's info
4656 case 2:
4657 if (UNMARSHALLING(ps)) {
4658 if ((il->info_2=(SPOOL_PRINTER_INFO_LEVEL_2 *)prs_alloc_mem(ps,sizeof(SPOOL_PRINTER_INFO_LEVEL_2))) == NULL)
4659 return False;
4661 if (!spool_io_printer_info_level_2("", il->info_2, ps, depth))
4662 return False;
4663 break;
4664 /* DOCUMENT ME!!! What is level 3 used for? */
4665 case 3:
4667 if (UNMARSHALLING(ps)) {
4668 if ((il->info_3=(SPOOL_PRINTER_INFO_LEVEL_3 *)prs_alloc_mem(ps,sizeof(SPOOL_PRINTER_INFO_LEVEL_3))) == NULL)
4669 return False;
4671 if (!spool_io_printer_info_level_3("", il->info_3, ps, depth))
4672 return False;
4673 break;
4677 return True;
4680 /*******************************************************************
4681 ********************************************************************/
4683 BOOL spoolss_io_q_addprinterex(const char *desc, SPOOL_Q_ADDPRINTEREX *q_u, prs_struct *ps, int depth)
4685 uint32 ptr_sec_desc = 0;
4687 prs_debug(ps, depth, desc, "spoolss_io_q_addprinterex");
4688 depth++;
4690 if(!prs_align(ps))
4691 return False;
4692 if(!prs_uint32("", ps, depth, &q_u->server_name_ptr))
4693 return False;
4694 if(!smb_io_unistr2("", &q_u->server_name, q_u->server_name_ptr, ps, depth))
4695 return False;
4697 if(!prs_align(ps))
4698 return False;
4700 if(!prs_uint32("info_level", ps, depth, &q_u->level))
4701 return False;
4703 if(!spool_io_printer_info_level("", &q_u->info, ps, depth))
4704 return False;
4706 if (!spoolss_io_devmode_cont(desc, &q_u->devmode_ctr, ps, depth))
4707 return False;
4709 if(!prs_align(ps))
4710 return False;
4712 switch (q_u->level) {
4713 case 2:
4714 ptr_sec_desc = q_u->info.info_2->secdesc_ptr;
4715 break;
4716 case 3:
4717 ptr_sec_desc = q_u->info.info_3->secdesc_ptr;
4718 break;
4720 if (ptr_sec_desc) {
4721 if (!sec_io_desc_buf(desc, &q_u->secdesc_ctr, ps, depth))
4722 return False;
4723 } else {
4724 uint32 dummy;
4726 /* Parse a NULL security descriptor. This should really
4727 happen inside the sec_io_desc_buf() function. */
4729 prs_debug(ps, depth, "", "sec_io_desc_buf");
4730 if (!prs_uint32("size", ps, depth + 1, &dummy))
4731 return False;
4732 if (!prs_uint32("ptr", ps, depth + 1, &dummy))
4733 return False;
4736 if(!prs_uint32("user_switch", ps, depth, &q_u->user_switch))
4737 return False;
4738 if(!spool_io_user_level("", &q_u->user_ctr, ps, depth))
4739 return False;
4741 return True;
4744 /*******************************************************************
4745 ********************************************************************/
4747 BOOL spoolss_io_r_addprinterex(const char *desc, SPOOL_R_ADDPRINTEREX *r_u,
4748 prs_struct *ps, int depth)
4750 prs_debug(ps, depth, desc, "spoolss_io_r_addprinterex");
4751 depth++;
4753 if(!smb_io_pol_hnd("printer handle",&r_u->handle,ps,depth))
4754 return False;
4756 if(!prs_werror("status", ps, depth, &r_u->status))
4757 return False;
4759 return True;
4762 /*******************************************************************
4763 ********************************************************************/
4765 BOOL spool_io_printer_driver_info_level_3(const char *desc, SPOOL_PRINTER_DRIVER_INFO_LEVEL_3 **q_u,
4766 prs_struct *ps, int depth)
4768 SPOOL_PRINTER_DRIVER_INFO_LEVEL_3 *il;
4770 prs_debug(ps, depth, desc, "spool_io_printer_driver_info_level_3");
4771 depth++;
4773 /* reading */
4774 if (UNMARSHALLING(ps)) {
4775 il=(SPOOL_PRINTER_DRIVER_INFO_LEVEL_3 *)prs_alloc_mem(ps,sizeof(SPOOL_PRINTER_DRIVER_INFO_LEVEL_3));
4776 if(il == NULL)
4777 return False;
4778 *q_u=il;
4780 else {
4781 il=*q_u;
4784 if(!prs_align(ps))
4785 return False;
4787 if(!prs_uint32("cversion", ps, depth, &il->cversion))
4788 return False;
4789 if(!prs_uint32("name", ps, depth, &il->name_ptr))
4790 return False;
4791 if(!prs_uint32("environment", ps, depth, &il->environment_ptr))
4792 return False;
4793 if(!prs_uint32("driverpath", ps, depth, &il->driverpath_ptr))
4794 return False;
4795 if(!prs_uint32("datafile", ps, depth, &il->datafile_ptr))
4796 return False;
4797 if(!prs_uint32("configfile", ps, depth, &il->configfile_ptr))
4798 return False;
4799 if(!prs_uint32("helpfile", ps, depth, &il->helpfile_ptr))
4800 return False;
4801 if(!prs_uint32("monitorname", ps, depth, &il->monitorname_ptr))
4802 return False;
4803 if(!prs_uint32("defaultdatatype", ps, depth, &il->defaultdatatype_ptr))
4804 return False;
4805 if(!prs_uint32("dependentfilessize", ps, depth, &il->dependentfilessize))
4806 return False;
4807 if(!prs_uint32("dependentfiles", ps, depth, &il->dependentfiles_ptr))
4808 return False;
4810 if(!prs_align(ps))
4811 return False;
4813 if(!smb_io_unistr2("name", &il->name, il->name_ptr, ps, depth))
4814 return False;
4815 if(!smb_io_unistr2("environment", &il->environment, il->environment_ptr, ps, depth))
4816 return False;
4817 if(!smb_io_unistr2("driverpath", &il->driverpath, il->driverpath_ptr, ps, depth))
4818 return False;
4819 if(!smb_io_unistr2("datafile", &il->datafile, il->datafile_ptr, ps, depth))
4820 return False;
4821 if(!smb_io_unistr2("configfile", &il->configfile, il->configfile_ptr, ps, depth))
4822 return False;
4823 if(!smb_io_unistr2("helpfile", &il->helpfile, il->helpfile_ptr, ps, depth))
4824 return False;
4825 if(!smb_io_unistr2("monitorname", &il->monitorname, il->monitorname_ptr, ps, depth))
4826 return False;
4827 if(!smb_io_unistr2("defaultdatatype", &il->defaultdatatype, il->defaultdatatype_ptr, ps, depth))
4828 return False;
4830 if(!prs_align(ps))
4831 return False;
4833 if (il->dependentfiles_ptr)
4834 smb_io_buffer5("", &il->dependentfiles, ps, depth);
4836 return True;
4839 /*******************************************************************
4840 parse a SPOOL_PRINTER_DRIVER_INFO_LEVEL_6 structure
4841 ********************************************************************/
4843 BOOL spool_io_printer_driver_info_level_6(const char *desc, SPOOL_PRINTER_DRIVER_INFO_LEVEL_6 **q_u,
4844 prs_struct *ps, int depth)
4846 SPOOL_PRINTER_DRIVER_INFO_LEVEL_6 *il;
4848 prs_debug(ps, depth, desc, "spool_io_printer_driver_info_level_6");
4849 depth++;
4851 /* reading */
4852 if (UNMARSHALLING(ps)) {
4853 il=(SPOOL_PRINTER_DRIVER_INFO_LEVEL_6 *)prs_alloc_mem(ps,sizeof(SPOOL_PRINTER_DRIVER_INFO_LEVEL_6));
4854 if(il == NULL)
4855 return False;
4856 *q_u=il;
4858 else {
4859 il=*q_u;
4862 if(!prs_align(ps))
4863 return False;
4866 * I know this seems weird, but I have no other explanation.
4867 * This is observed behavior on both NT4 and 2K servers.
4868 * --jerry
4871 if (!prs_align_uint64(ps))
4872 return False;
4874 /* parse the main elements the packet */
4876 if(!prs_uint32("cversion ", ps, depth, &il->version))
4877 return False;
4878 if(!prs_uint32("name ", ps, depth, &il->name_ptr))
4879 return False;
4880 if(!prs_uint32("environment ", ps, depth, &il->environment_ptr))
4881 return False;
4882 if(!prs_uint32("driverpath ", ps, depth, &il->driverpath_ptr))
4883 return False;
4884 if(!prs_uint32("datafile ", ps, depth, &il->datafile_ptr))
4885 return False;
4886 if(!prs_uint32("configfile ", ps, depth, &il->configfile_ptr))
4887 return False;
4888 if(!prs_uint32("helpfile ", ps, depth, &il->helpfile_ptr))
4889 return False;
4890 if(!prs_uint32("monitorname ", ps, depth, &il->monitorname_ptr))
4891 return False;
4892 if(!prs_uint32("defaultdatatype", ps, depth, &il->defaultdatatype_ptr))
4893 return False;
4894 if(!prs_uint32("dependentfiles ", ps, depth, &il->dependentfiles_len))
4895 return False;
4896 if(!prs_uint32("dependentfiles ", ps, depth, &il->dependentfiles_ptr))
4897 return False;
4898 if(!prs_uint32("previousnames ", ps, depth, &il->previousnames_len))
4899 return False;
4900 if(!prs_uint32("previousnames ", ps, depth, &il->previousnames_ptr))
4901 return False;
4902 if(!smb_io_time("driverdate ", &il->driverdate, ps, depth))
4903 return False;
4904 if(!prs_uint32("dummy4 ", ps, depth, &il->dummy4))
4905 return False;
4906 if(!prs_uint64("driverversion ", ps, depth, &il->driverversion))
4907 return False;
4908 if(!prs_uint32("mfgname ", ps, depth, &il->mfgname_ptr))
4909 return False;
4910 if(!prs_uint32("oemurl ", ps, depth, &il->oemurl_ptr))
4911 return False;
4912 if(!prs_uint32("hardwareid ", ps, depth, &il->hardwareid_ptr))
4913 return False;
4914 if(!prs_uint32("provider ", ps, depth, &il->provider_ptr))
4915 return False;
4917 /* parse the structures in the packet */
4919 if(!smb_io_unistr2("name", &il->name, il->name_ptr, ps, depth))
4920 return False;
4921 if(!prs_align(ps))
4922 return False;
4924 if(!smb_io_unistr2("environment", &il->environment, il->environment_ptr, ps, depth))
4925 return False;
4926 if(!prs_align(ps))
4927 return False;
4929 if(!smb_io_unistr2("driverpath", &il->driverpath, il->driverpath_ptr, ps, depth))
4930 return False;
4931 if(!prs_align(ps))
4932 return False;
4934 if(!smb_io_unistr2("datafile", &il->datafile, il->datafile_ptr, ps, depth))
4935 return False;
4936 if(!prs_align(ps))
4937 return False;
4939 if(!smb_io_unistr2("configfile", &il->configfile, il->configfile_ptr, ps, depth))
4940 return False;
4941 if(!prs_align(ps))
4942 return False;
4944 if(!smb_io_unistr2("helpfile", &il->helpfile, il->helpfile_ptr, ps, depth))
4945 return False;
4946 if(!prs_align(ps))
4947 return False;
4949 if(!smb_io_unistr2("monitorname", &il->monitorname, il->monitorname_ptr, ps, depth))
4950 return False;
4951 if(!prs_align(ps))
4952 return False;
4954 if(!smb_io_unistr2("defaultdatatype", &il->defaultdatatype, il->defaultdatatype_ptr, ps, depth))
4955 return False;
4956 if(!prs_align(ps))
4957 return False;
4958 if (il->dependentfiles_ptr) {
4959 if(!smb_io_buffer5("dependentfiles", &il->dependentfiles, ps, depth))
4960 return False;
4961 if(!prs_align(ps))
4962 return False;
4964 if (il->previousnames_ptr) {
4965 if(!smb_io_buffer5("previousnames", &il->previousnames, ps, depth))
4966 return False;
4967 if(!prs_align(ps))
4968 return False;
4970 if(!smb_io_unistr2("mfgname", &il->mfgname, il->mfgname_ptr, ps, depth))
4971 return False;
4972 if(!prs_align(ps))
4973 return False;
4974 if(!smb_io_unistr2("oemurl", &il->oemurl, il->oemurl_ptr, ps, depth))
4975 return False;
4976 if(!prs_align(ps))
4977 return False;
4978 if(!smb_io_unistr2("hardwareid", &il->hardwareid, il->hardwareid_ptr, ps, depth))
4979 return False;
4980 if(!prs_align(ps))
4981 return False;
4982 if(!smb_io_unistr2("provider", &il->provider, il->provider_ptr, ps, depth))
4983 return False;
4985 return True;
4988 /*******************************************************************
4989 convert a buffer of UNICODE strings null terminated
4990 the buffer is terminated by a NULL
4992 convert to an dos codepage array (null terminated)
4994 dynamically allocate memory
4996 ********************************************************************/
4997 static BOOL uniarray_2_dosarray(BUFFER5 *buf5, fstring **ar)
4999 fstring f, *tar;
5000 int n = 0;
5001 char *src;
5003 if (buf5==NULL)
5004 return False;
5006 src = (char *)buf5->buffer;
5007 *ar = NULL;
5009 while (src < ((char *)buf5->buffer) + buf5->buf_len*2) {
5010 unistr_to_dos(f, src, sizeof(f)-1);
5011 src = skip_unibuf(src, 2*buf5->buf_len - PTR_DIFF(src,buf5->buffer));
5012 tar = (fstring *)Realloc(*ar, sizeof(fstring)*(n+2));
5013 if (!tar)
5014 return False;
5015 else
5016 *ar = tar;
5017 fstrcpy((*ar)[n], f);
5018 n++;
5020 fstrcpy((*ar)[n], "");
5022 return True;
5028 /*******************************************************************
5029 read a UNICODE array with null terminated strings
5030 and null terminated array
5031 and size of array at beginning
5032 ********************************************************************/
5034 BOOL smb_io_unibuffer(const char *desc, UNISTR2 *buffer, prs_struct *ps, int depth)
5036 if (buffer==NULL) return False;
5038 buffer->undoc=0;
5039 buffer->uni_str_len=buffer->uni_max_len;
5041 if(!prs_uint32("buffer_size", ps, depth, &buffer->uni_max_len))
5042 return False;
5044 if(!prs_unistr2(True, "buffer ", ps, depth, buffer))
5045 return False;
5047 return True;
5050 /*******************************************************************
5051 ********************************************************************/
5053 BOOL spool_io_printer_driver_info_level(const char *desc, SPOOL_PRINTER_DRIVER_INFO_LEVEL *il, prs_struct *ps, int depth)
5055 prs_debug(ps, depth, desc, "spool_io_printer_driver_info_level");
5056 depth++;
5058 if(!prs_align(ps))
5059 return False;
5060 if(!prs_uint32("level", ps, depth, &il->level))
5061 return False;
5062 if(!prs_uint32("ptr", ps, depth, &il->ptr))
5063 return False;
5065 if (il->ptr==0)
5066 return True;
5068 switch (il->level) {
5069 case 3:
5070 if(!spool_io_printer_driver_info_level_3("", &il->info_3, ps, depth))
5071 return False;
5072 break;
5073 case 6:
5074 if(!spool_io_printer_driver_info_level_6("", &il->info_6, ps, depth))
5075 return False;
5076 break;
5077 default:
5078 return False;
5081 return True;
5084 /*******************************************************************
5085 init a SPOOL_Q_ADDPRINTERDRIVER struct
5086 ******************************************************************/
5088 BOOL make_spoolss_q_addprinterdriver(TALLOC_CTX *mem_ctx,
5089 SPOOL_Q_ADDPRINTERDRIVER *q_u, const char* srv_name,
5090 uint32 level, PRINTER_DRIVER_CTR *info)
5092 DEBUG(5,("make_spoolss_q_addprinterdriver\n"));
5094 q_u->server_name_ptr = (srv_name!=NULL)?1:0;
5095 init_unistr2(&q_u->server_name, srv_name, strlen(srv_name)+1);
5097 q_u->level = level;
5099 q_u->info.level = level;
5100 q_u->info.ptr = (info!=NULL)?1:0;
5101 switch (level)
5103 /* info level 3 is supported by Windows 95/98, WinNT and Win2k */
5104 case 3 :
5105 make_spoolss_driver_info_3(mem_ctx, &q_u->info.info_3, info->info3);
5106 break;
5108 default:
5109 DEBUG(0,("make_spoolss_q_addprinterdriver: Unknown info level [%d]\n", level));
5110 break;
5113 return True;
5116 BOOL make_spoolss_driver_info_3(TALLOC_CTX *mem_ctx,
5117 SPOOL_PRINTER_DRIVER_INFO_LEVEL_3 **spool_drv_info,
5118 DRIVER_INFO_3 *info3)
5120 uint32 len = 0;
5121 uint16 *ptr = info3->dependentfiles;
5122 BOOL done = False;
5123 BOOL null_char = False;
5124 SPOOL_PRINTER_DRIVER_INFO_LEVEL_3 *inf;
5126 if (!(inf=(SPOOL_PRINTER_DRIVER_INFO_LEVEL_3*)talloc_zero(mem_ctx, sizeof(SPOOL_PRINTER_DRIVER_INFO_LEVEL_3))))
5127 return False;
5129 inf->cversion = info3->version;
5130 inf->name_ptr = (info3->name.buffer!=NULL)?1:0;
5131 inf->environment_ptr = (info3->architecture.buffer!=NULL)?1:0;
5132 inf->driverpath_ptr = (info3->driverpath.buffer!=NULL)?1:0;
5133 inf->datafile_ptr = (info3->datafile.buffer!=NULL)?1:0;
5134 inf->configfile_ptr = (info3->configfile.buffer!=NULL)?1:0;
5135 inf->helpfile_ptr = (info3->helpfile.buffer!=NULL)?1:0;
5136 inf->monitorname_ptr = (info3->monitorname.buffer!=NULL)?1:0;
5137 inf->defaultdatatype_ptr = (info3->defaultdatatype.buffer!=NULL)?1:0;
5139 init_unistr2_from_unistr(&inf->name, &info3->name);
5140 init_unistr2_from_unistr(&inf->environment, &info3->architecture);
5141 init_unistr2_from_unistr(&inf->driverpath, &info3->driverpath);
5142 init_unistr2_from_unistr(&inf->datafile, &info3->datafile);
5143 init_unistr2_from_unistr(&inf->configfile, &info3->configfile);
5144 init_unistr2_from_unistr(&inf->helpfile, &info3->helpfile);
5145 init_unistr2_from_unistr(&inf->monitorname, &info3->monitorname);
5146 init_unistr2_from_unistr(&inf->defaultdatatype, &info3->defaultdatatype);
5148 while (!done)
5150 switch (*ptr)
5152 case 0:
5153 /* the null_char BOOL is used to help locate
5154 two '\0's back to back */
5155 if (null_char)
5156 done = True;
5157 else
5158 null_char = True;
5159 break;
5161 default:
5162 null_char = False;
5164 break;
5166 len++;
5167 ptr++;
5169 inf->dependentfiles_ptr = (info3->dependentfiles != NULL) ? 1 : 0;
5170 inf->dependentfilessize = len;
5171 if(!make_spoolss_buffer5(mem_ctx, &inf->dependentfiles, len, info3->dependentfiles))
5173 SAFE_FREE(inf);
5174 return False;
5177 *spool_drv_info = inf;
5179 return True;
5182 /*******************************************************************
5183 make a BUFFER5 struct from a uint16*
5184 ******************************************************************/
5185 BOOL make_spoolss_buffer5(TALLOC_CTX *mem_ctx, BUFFER5 *buf5, uint32 len, uint16 *src)
5188 buf5->buf_len = len;
5189 if((buf5->buffer=(uint16*)talloc_memdup(mem_ctx, src, sizeof(uint16)*len)) == NULL)
5191 DEBUG(0,("make_spoolss_buffer5: Unable to malloc memory for buffer!\n"));
5192 return False;
5195 return True;
5198 /*******************************************************************
5199 fill in the prs_struct for a ADDPRINTERDRIVER request PDU
5200 ********************************************************************/
5202 BOOL spoolss_io_q_addprinterdriver(const char *desc, SPOOL_Q_ADDPRINTERDRIVER *q_u, prs_struct *ps, int depth)
5204 prs_debug(ps, depth, desc, "spoolss_io_q_addprinterdriver");
5205 depth++;
5207 if(!prs_align(ps))
5208 return False;
5210 if(!prs_uint32("server_name_ptr", ps, depth, &q_u->server_name_ptr))
5211 return False;
5212 if(!smb_io_unistr2("server_name", &q_u->server_name, q_u->server_name_ptr, ps, depth))
5213 return False;
5215 if(!prs_align(ps))
5216 return False;
5217 if(!prs_uint32("info_level", ps, depth, &q_u->level))
5218 return False;
5220 if(!spool_io_printer_driver_info_level("", &q_u->info, ps, depth))
5221 return False;
5223 return True;
5226 /*******************************************************************
5227 ********************************************************************/
5229 BOOL spoolss_io_r_addprinterdriver(const char *desc, SPOOL_R_ADDPRINTERDRIVER *q_u, prs_struct *ps, int depth)
5231 prs_debug(ps, depth, desc, "spoolss_io_r_addprinterdriver");
5232 depth++;
5234 if(!prs_werror("status", ps, depth, &q_u->status))
5235 return False;
5237 return True;
5240 /*******************************************************************
5241 ********************************************************************/
5243 BOOL uni_2_asc_printer_driver_3(SPOOL_PRINTER_DRIVER_INFO_LEVEL_3 *uni,
5244 NT_PRINTER_DRIVER_INFO_LEVEL_3 **asc)
5246 NT_PRINTER_DRIVER_INFO_LEVEL_3 *d;
5248 DEBUG(7,("uni_2_asc_printer_driver_3: Converting from UNICODE to ASCII\n"));
5250 if (*asc==NULL)
5252 *asc=(NT_PRINTER_DRIVER_INFO_LEVEL_3 *)malloc(sizeof(NT_PRINTER_DRIVER_INFO_LEVEL_3));
5253 if(*asc == NULL)
5254 return False;
5255 ZERO_STRUCTP(*asc);
5258 d=*asc;
5260 d->cversion=uni->cversion;
5262 unistr2_to_dos(d->name, &uni->name, sizeof(d->name)-1);
5263 unistr2_to_dos(d->environment, &uni->environment, sizeof(d->environment)-1);
5264 unistr2_to_dos(d->driverpath, &uni->driverpath, sizeof(d->driverpath)-1);
5265 unistr2_to_dos(d->datafile, &uni->datafile, sizeof(d->datafile)-1);
5266 unistr2_to_dos(d->configfile, &uni->configfile, sizeof(d->configfile)-1);
5267 unistr2_to_dos(d->helpfile, &uni->helpfile, sizeof(d->helpfile)-1);
5268 unistr2_to_dos(d->monitorname, &uni->monitorname, sizeof(d->monitorname)-1);
5269 unistr2_to_dos(d->defaultdatatype, &uni->defaultdatatype, sizeof(d->defaultdatatype)-1);
5271 DEBUGADD(8,( "version: %d\n", d->cversion));
5272 DEBUGADD(8,( "name: %s\n", d->name));
5273 DEBUGADD(8,( "environment: %s\n", d->environment));
5274 DEBUGADD(8,( "driverpath: %s\n", d->driverpath));
5275 DEBUGADD(8,( "datafile: %s\n", d->datafile));
5276 DEBUGADD(8,( "configfile: %s\n", d->configfile));
5277 DEBUGADD(8,( "helpfile: %s\n", d->helpfile));
5278 DEBUGADD(8,( "monitorname: %s\n", d->monitorname));
5279 DEBUGADD(8,( "defaultdatatype: %s\n", d->defaultdatatype));
5281 if (uniarray_2_dosarray(&uni->dependentfiles, &d->dependentfiles ))
5282 return True;
5284 SAFE_FREE(*asc);
5285 return False;
5288 /*******************************************************************
5289 ********************************************************************/
5290 BOOL uni_2_asc_printer_driver_6(SPOOL_PRINTER_DRIVER_INFO_LEVEL_6 *uni,
5291 NT_PRINTER_DRIVER_INFO_LEVEL_6 **asc)
5293 NT_PRINTER_DRIVER_INFO_LEVEL_6 *d;
5295 DEBUG(7,("uni_2_asc_printer_driver_6: Converting from UNICODE to ASCII\n"));
5297 if (*asc==NULL)
5299 *asc=(NT_PRINTER_DRIVER_INFO_LEVEL_6 *)malloc(sizeof(NT_PRINTER_DRIVER_INFO_LEVEL_6));
5300 if(*asc == NULL)
5301 return False;
5302 ZERO_STRUCTP(*asc);
5305 d=*asc;
5307 d->version=uni->version;
5309 unistr2_to_dos(d->name, &uni->name, sizeof(d->name)-1);
5310 unistr2_to_dos(d->environment, &uni->environment, sizeof(d->environment)-1);
5311 unistr2_to_dos(d->driverpath, &uni->driverpath, sizeof(d->driverpath)-1);
5312 unistr2_to_dos(d->datafile, &uni->datafile, sizeof(d->datafile)-1);
5313 unistr2_to_dos(d->configfile, &uni->configfile, sizeof(d->configfile)-1);
5314 unistr2_to_dos(d->helpfile, &uni->helpfile, sizeof(d->helpfile)-1);
5315 unistr2_to_dos(d->monitorname, &uni->monitorname, sizeof(d->monitorname)-1);
5316 unistr2_to_dos(d->defaultdatatype, &uni->defaultdatatype, sizeof(d->defaultdatatype)-1);
5318 DEBUGADD(8,( "version: %d\n", d->version));
5319 DEBUGADD(8,( "name: %s\n", d->name));
5320 DEBUGADD(8,( "environment: %s\n", d->environment));
5321 DEBUGADD(8,( "driverpath: %s\n", d->driverpath));
5322 DEBUGADD(8,( "datafile: %s\n", d->datafile));
5323 DEBUGADD(8,( "configfile: %s\n", d->configfile));
5324 DEBUGADD(8,( "helpfile: %s\n", d->helpfile));
5325 DEBUGADD(8,( "monitorname: %s\n", d->monitorname));
5326 DEBUGADD(8,( "defaultdatatype: %s\n", d->defaultdatatype));
5328 if (!uniarray_2_dosarray(&uni->dependentfiles, &d->dependentfiles ))
5329 goto error;
5330 if (!uniarray_2_dosarray(&uni->previousnames, &d->previousnames ))
5331 goto error;
5333 return True;
5335 error:
5336 SAFE_FREE(*asc);
5337 return False;
5340 BOOL uni_2_asc_printer_info_2(const SPOOL_PRINTER_INFO_LEVEL_2 *uni,
5341 NT_PRINTER_INFO_LEVEL_2 **asc)
5343 NT_PRINTER_INFO_LEVEL_2 *d;
5344 time_t time_unix;
5346 DEBUG(7,("Converting from UNICODE to ASCII\n"));
5347 time_unix=time(NULL);
5349 if (*asc==NULL) {
5350 DEBUGADD(8,("allocating memory\n"));
5352 *asc=(NT_PRINTER_INFO_LEVEL_2 *)malloc(sizeof(NT_PRINTER_INFO_LEVEL_2));
5353 if(*asc == NULL)
5354 return False;
5355 ZERO_STRUCTP(*asc);
5357 /* we allocate memory iff called from
5358 * addprinter(ex) so we can do one time stuff here.
5360 (*asc)->setuptime=time_unix;
5362 DEBUGADD(8,("start converting\n"));
5364 d=*asc;
5366 d->attributes=uni->attributes;
5367 d->priority=uni->priority;
5368 d->default_priority=uni->default_priority;
5369 d->starttime=uni->starttime;
5370 d->untiltime=uni->untiltime;
5371 d->status=uni->status;
5372 d->cjobs=uni->cjobs;
5374 unistr2_to_dos(d->servername, &uni->servername, sizeof(d->servername)-1);
5375 unistr2_to_dos(d->printername, &uni->printername, sizeof(d->printername)-1);
5376 unistr2_to_dos(d->sharename, &uni->sharename, sizeof(d->sharename)-1);
5377 unistr2_to_dos(d->portname, &uni->portname, sizeof(d->portname)-1);
5378 unistr2_to_dos(d->drivername, &uni->drivername, sizeof(d->drivername)-1);
5379 unistr2_to_dos(d->comment, &uni->comment, sizeof(d->comment)-1);
5380 unistr2_to_dos(d->location, &uni->location, sizeof(d->location)-1);
5381 unistr2_to_dos(d->sepfile, &uni->sepfile, sizeof(d->sepfile)-1);
5382 unistr2_to_dos(d->printprocessor, &uni->printprocessor, sizeof(d->printprocessor)-1);
5383 unistr2_to_dos(d->datatype, &uni->datatype, sizeof(d->datatype)-1);
5384 unistr2_to_dos(d->parameters, &uni->parameters, sizeof(d->parameters)-1);
5386 return True;
5389 /*******************************************************************
5390 * init a structure.
5391 ********************************************************************/
5393 BOOL make_spoolss_q_getprinterdriverdir(SPOOL_Q_GETPRINTERDRIVERDIR *q_u,
5394 fstring servername, fstring env_name, uint32 level,
5395 NEW_BUFFER *buffer, uint32 offered)
5397 init_buf_unistr2(&q_u->name, &q_u->name_ptr, servername);
5398 init_buf_unistr2(&q_u->environment, &q_u->environment_ptr, env_name);
5400 q_u->level=level;
5401 q_u->buffer=buffer;
5402 q_u->offered=offered;
5404 return True;
5407 /*******************************************************************
5408 Parse a SPOOL_Q_GETPRINTERDRIVERDIR structure.
5409 ********************************************************************/
5411 BOOL spoolss_io_q_getprinterdriverdir(const char *desc, SPOOL_Q_GETPRINTERDRIVERDIR *q_u, prs_struct *ps, int depth)
5413 prs_debug(ps, depth, desc, "spoolss_io_q_getprinterdriverdir");
5414 depth++;
5416 if(!prs_align(ps))
5417 return False;
5418 if(!prs_uint32("name_ptr", ps, depth, &q_u->name_ptr))
5419 return False;
5420 if(!smb_io_unistr2("", &q_u->name, q_u->name_ptr, ps, depth))
5421 return False;
5423 if(!prs_align(ps))
5424 return False;
5426 if(!prs_uint32("", ps, depth, &q_u->environment_ptr))
5427 return False;
5428 if(!smb_io_unistr2("", &q_u->environment, q_u->environment_ptr, ps, depth))
5429 return False;
5431 if(!prs_align(ps))
5432 return False;
5434 if(!prs_uint32("level", ps, depth, &q_u->level))
5435 return False;
5437 if(!spoolss_io_buffer("", ps, depth, &q_u->buffer))
5438 return False;
5440 if(!prs_align(ps))
5441 return False;
5443 if(!prs_uint32("offered", ps, depth, &q_u->offered))
5444 return False;
5446 return True;
5449 /*******************************************************************
5450 Parse a SPOOL_R_GETPRINTERDRIVERDIR structure.
5451 ********************************************************************/
5453 BOOL spoolss_io_r_getprinterdriverdir(const char *desc, SPOOL_R_GETPRINTERDRIVERDIR *r_u, prs_struct *ps, int depth)
5455 prs_debug(ps, depth, desc, "spoolss_io_r_getprinterdriverdir");
5456 depth++;
5458 if (!prs_align(ps))
5459 return False;
5461 if (!spoolss_io_buffer("", ps, depth, &r_u->buffer))
5462 return False;
5464 if (!prs_align(ps))
5465 return False;
5467 if (!prs_uint32("needed", ps, depth, &r_u->needed))
5468 return False;
5470 if (!prs_werror("status", ps, depth, &r_u->status))
5471 return False;
5473 return True;
5476 /*******************************************************************
5477 ********************************************************************/
5479 BOOL spoolss_io_r_enumprintprocessors(const char *desc, SPOOL_R_ENUMPRINTPROCESSORS *r_u, prs_struct *ps, int depth)
5481 prs_debug(ps, depth, desc, "spoolss_io_r_enumprintprocessors");
5482 depth++;
5484 if (!prs_align(ps))
5485 return False;
5487 if (!spoolss_io_buffer("", ps, depth, &r_u->buffer))
5488 return False;
5490 if (!prs_align(ps))
5491 return False;
5493 if (!prs_uint32("needed", ps, depth, &r_u->needed))
5494 return False;
5496 if (!prs_uint32("returned", ps, depth, &r_u->returned))
5497 return False;
5499 if (!prs_werror("status", ps, depth, &r_u->status))
5500 return False;
5502 return True;
5505 /*******************************************************************
5506 ********************************************************************/
5508 BOOL spoolss_io_q_enumprintprocessors(const char *desc, SPOOL_Q_ENUMPRINTPROCESSORS *q_u, prs_struct *ps, int depth)
5510 prs_debug(ps, depth, desc, "spoolss_io_q_enumprintprocessors");
5511 depth++;
5513 if (!prs_align(ps))
5514 return False;
5516 if (!prs_uint32("name_ptr", ps, depth, &q_u->name_ptr))
5517 return False;
5518 if (!smb_io_unistr2("name", &q_u->name, True, ps, depth))
5519 return False;
5521 if (!prs_align(ps))
5522 return False;
5524 if (!prs_uint32("", ps, depth, &q_u->environment_ptr))
5525 return False;
5526 if (!smb_io_unistr2("", &q_u->environment, q_u->environment_ptr, ps, depth))
5527 return False;
5529 if (!prs_align(ps))
5530 return False;
5532 if (!prs_uint32("level", ps, depth, &q_u->level))
5533 return False;
5535 if(!spoolss_io_buffer("", ps, depth, &q_u->buffer))
5536 return False;
5538 if (!prs_align(ps))
5539 return False;
5541 if (!prs_uint32("offered", ps, depth, &q_u->offered))
5542 return False;
5544 return True;
5547 /*******************************************************************
5548 ********************************************************************/
5550 BOOL spoolss_io_q_addprintprocessor(const char *desc, SPOOL_Q_ADDPRINTPROCESSOR *q_u, prs_struct *ps, int depth)
5552 prs_debug(ps, depth, desc, "spoolss_io_q_addprintprocessor");
5553 depth++;
5555 if (!prs_align(ps))
5556 return False;
5558 if (!prs_uint32("server_ptr", ps, depth, &q_u->server_ptr))
5559 return False;
5560 if (!smb_io_unistr2("server", &q_u->server, q_u->server_ptr, ps, depth))
5561 return False;
5563 if (!prs_align(ps))
5564 return False;
5565 if (!smb_io_unistr2("environment", &q_u->environment, True, ps, depth))
5566 return False;
5568 if (!prs_align(ps))
5569 return False;
5570 if (!smb_io_unistr2("path", &q_u->path, True, ps, depth))
5571 return False;
5573 if (!prs_align(ps))
5574 return False;
5575 if (!smb_io_unistr2("name", &q_u->name, True, ps, depth))
5576 return False;
5578 return True;
5581 /*******************************************************************
5582 ********************************************************************/
5584 BOOL spoolss_io_r_addprintprocessor(const char *desc, SPOOL_R_ADDPRINTPROCESSOR *r_u, prs_struct *ps, int depth)
5586 prs_debug(ps, depth, desc, "spoolss_io_r_addprintproicessor");
5587 depth++;
5589 if (!prs_align(ps))
5590 return False;
5592 if (!prs_werror("status", ps, depth, &r_u->status))
5593 return False;
5595 return True;
5598 /*******************************************************************
5599 ********************************************************************/
5601 BOOL spoolss_io_r_enumprintprocdatatypes(const char *desc, SPOOL_R_ENUMPRINTPROCDATATYPES *r_u, prs_struct *ps, int depth)
5603 prs_debug(ps, depth, desc, "spoolss_io_r_enumprintprocdatatypes");
5604 depth++;
5606 if (!prs_align(ps))
5607 return False;
5609 if (!spoolss_io_buffer("", ps, depth, &r_u->buffer))
5610 return False;
5612 if (!prs_align(ps))
5613 return False;
5615 if (!prs_uint32("needed", ps, depth, &r_u->needed))
5616 return False;
5618 if (!prs_uint32("returned", ps, depth, &r_u->returned))
5619 return False;
5621 if (!prs_werror("status", ps, depth, &r_u->status))
5622 return False;
5624 return True;
5627 /*******************************************************************
5628 ********************************************************************/
5630 BOOL spoolss_io_q_enumprintprocdatatypes(const char *desc, SPOOL_Q_ENUMPRINTPROCDATATYPES *q_u, prs_struct *ps, int depth)
5632 prs_debug(ps, depth, desc, "spoolss_io_q_enumprintprocdatatypes");
5633 depth++;
5635 if (!prs_align(ps))
5636 return False;
5638 if (!prs_uint32("name_ptr", ps, depth, &q_u->name_ptr))
5639 return False;
5640 if (!smb_io_unistr2("name", &q_u->name, True, ps, depth))
5641 return False;
5643 if (!prs_align(ps))
5644 return False;
5646 if (!prs_uint32("processor_ptr", ps, depth, &q_u->processor_ptr))
5647 return False;
5648 if (!smb_io_unistr2("processor", &q_u->processor, q_u->processor_ptr, ps, depth))
5649 return False;
5651 if (!prs_align(ps))
5652 return False;
5654 if (!prs_uint32("level", ps, depth, &q_u->level))
5655 return False;
5657 if(!spoolss_io_buffer("buffer", ps, depth, &q_u->buffer))
5658 return False;
5660 if (!prs_align(ps))
5661 return False;
5663 if (!prs_uint32("offered", ps, depth, &q_u->offered))
5664 return False;
5666 return True;
5669 /*******************************************************************
5670 Parse a SPOOL_Q_ENUMPRINTMONITORS structure.
5671 ********************************************************************/
5673 BOOL spoolss_io_q_enumprintmonitors(const char *desc, SPOOL_Q_ENUMPRINTMONITORS *q_u, prs_struct *ps, int depth)
5675 prs_debug(ps, depth, desc, "spoolss_io_q_enumprintmonitors");
5676 depth++;
5678 if (!prs_align(ps))
5679 return False;
5681 if (!prs_uint32("name_ptr", ps, depth, &q_u->name_ptr))
5682 return False;
5683 if (!smb_io_unistr2("name", &q_u->name, True, ps, depth))
5684 return False;
5686 if (!prs_align(ps))
5687 return False;
5689 if (!prs_uint32("level", ps, depth, &q_u->level))
5690 return False;
5692 if(!spoolss_io_buffer("", ps, depth, &q_u->buffer))
5693 return False;
5695 if (!prs_align(ps))
5696 return False;
5698 if (!prs_uint32("offered", ps, depth, &q_u->offered))
5699 return False;
5701 return True;
5704 /*******************************************************************
5705 ********************************************************************/
5707 BOOL spoolss_io_r_enumprintmonitors(const char *desc, SPOOL_R_ENUMPRINTMONITORS *r_u, prs_struct *ps, int depth)
5709 prs_debug(ps, depth, desc, "spoolss_io_r_enumprintmonitors");
5710 depth++;
5712 if (!prs_align(ps))
5713 return False;
5715 if (!spoolss_io_buffer("", ps, depth, &r_u->buffer))
5716 return False;
5718 if (!prs_align(ps))
5719 return False;
5721 if (!prs_uint32("needed", ps, depth, &r_u->needed))
5722 return False;
5724 if (!prs_uint32("returned", ps, depth, &r_u->returned))
5725 return False;
5727 if (!prs_werror("status", ps, depth, &r_u->status))
5728 return False;
5730 return True;
5733 /*******************************************************************
5734 ********************************************************************/
5736 BOOL spoolss_io_r_enumprinterdata(const char *desc, SPOOL_R_ENUMPRINTERDATA *r_u, prs_struct *ps, int depth)
5738 prs_debug(ps, depth, desc, "spoolss_io_r_enumprinterdata");
5739 depth++;
5741 if(!prs_align(ps))
5742 return False;
5743 if(!prs_uint32("valuesize", ps, depth, &r_u->valuesize))
5744 return False;
5746 if (UNMARSHALLING(ps) && r_u->valuesize) {
5747 r_u->value = (uint16 *)prs_alloc_mem(ps, r_u->valuesize * 2);
5748 if (!r_u->value) {
5749 DEBUG(0, ("spoolss_io_r_enumprinterdata: out of memory for printerdata value\n"));
5750 return False;
5754 if(!prs_uint16uni(False, "value", ps, depth, r_u->value, r_u->valuesize ))
5755 return False;
5757 if(!prs_align(ps))
5758 return False;
5760 if(!prs_uint32("realvaluesize", ps, depth, &r_u->realvaluesize))
5761 return False;
5763 if(!prs_uint32("type", ps, depth, &r_u->type))
5764 return False;
5766 if(!prs_uint32("datasize", ps, depth, &r_u->datasize))
5767 return False;
5769 if (UNMARSHALLING(ps) && r_u->datasize) {
5770 r_u->data = (uint8 *)prs_alloc_mem(ps, r_u->datasize);
5771 if (!r_u->data) {
5772 DEBUG(0, ("spoolss_io_r_enumprinterdata: out of memory for printerdata data\n"));
5773 return False;
5777 if(!prs_uint8s(False, "data", ps, depth, r_u->data, r_u->datasize))
5778 return False;
5779 if(!prs_align(ps))
5780 return False;
5782 if(!prs_uint32("realdatasize", ps, depth, &r_u->realdatasize))
5783 return False;
5784 if(!prs_werror("status", ps, depth, &r_u->status))
5785 return False;
5787 return True;
5790 /*******************************************************************
5791 ********************************************************************/
5793 BOOL spoolss_io_q_enumprinterdata(const char *desc, SPOOL_Q_ENUMPRINTERDATA *q_u, prs_struct *ps, int depth)
5795 prs_debug(ps, depth, desc, "spoolss_io_q_enumprinterdata");
5796 depth++;
5798 if(!prs_align(ps))
5799 return False;
5800 if(!smb_io_pol_hnd("printer handle",&q_u->handle,ps,depth))
5801 return False;
5802 if(!prs_uint32("index", ps, depth, &q_u->index))
5803 return False;
5804 if(!prs_uint32("valuesize", ps, depth, &q_u->valuesize))
5805 return False;
5806 if(!prs_uint32("datasize", ps, depth, &q_u->datasize))
5807 return False;
5809 return True;
5812 /*******************************************************************
5813 ********************************************************************/
5815 BOOL make_spoolss_q_enumprinterdata(SPOOL_Q_ENUMPRINTERDATA *q_u,
5816 const POLICY_HND *hnd,
5817 uint32 idx, uint32 valuelen, uint32 datalen)
5819 memcpy(&q_u->handle, hnd, sizeof(q_u->handle));
5820 q_u->index=idx;
5821 q_u->valuesize=valuelen;
5822 q_u->datasize=datalen;
5824 return True;
5827 /*******************************************************************
5828 ********************************************************************/
5829 BOOL make_spoolss_q_setprinterdata(SPOOL_Q_SETPRINTERDATA *q_u, TALLOC_CTX *ctx, const POLICY_HND *hnd,
5830 char* value, char* data)
5832 UNISTR2 tmp;
5834 memcpy(&q_u->handle, hnd, sizeof(q_u->handle));
5835 q_u->type = REG_SZ;
5836 init_unistr2(&q_u->value, value, strlen(value)+1);
5838 init_unistr2(&tmp, data, strlen(data)+1);
5839 q_u->max_len = q_u->real_len = tmp.uni_max_len*2;
5840 q_u->data = talloc(ctx, q_u->real_len);
5841 memcpy(q_u->data, tmp.buffer, q_u->real_len);
5843 return True;
5845 /*******************************************************************
5846 ********************************************************************/
5848 BOOL spoolss_io_q_setprinterdata(const char *desc, SPOOL_Q_SETPRINTERDATA *q_u, prs_struct *ps, int depth)
5850 prs_debug(ps, depth, desc, "spoolss_io_q_setprinterdata");
5851 depth++;
5853 if(!prs_align(ps))
5854 return False;
5855 if(!smb_io_pol_hnd("printer handle", &q_u->handle, ps, depth))
5856 return False;
5857 if(!smb_io_unistr2("", &q_u->value, True, ps, depth))
5858 return False;
5860 if(!prs_align(ps))
5861 return False;
5863 if(!prs_uint32("type", ps, depth, &q_u->type))
5864 return False;
5866 if(!prs_uint32("max_len", ps, depth, &q_u->max_len))
5867 return False;
5869 switch (q_u->type)
5871 case REG_SZ:
5872 case REG_BINARY:
5873 case REG_DWORD:
5874 case REG_MULTI_SZ:
5875 if (q_u->max_len) {
5876 if (UNMARSHALLING(ps))
5877 q_u->data=(uint8 *)prs_alloc_mem(ps, q_u->max_len * sizeof(uint8));
5878 if(q_u->data == NULL)
5879 return False;
5880 if(!prs_uint8s(False,"data", ps, depth, q_u->data, q_u->max_len))
5881 return False;
5883 if(!prs_align(ps))
5884 return False;
5885 break;
5888 if(!prs_uint32("real_len", ps, depth, &q_u->real_len))
5889 return False;
5891 return True;
5894 /*******************************************************************
5895 ********************************************************************/
5897 BOOL spoolss_io_r_setprinterdata(const char *desc, SPOOL_R_SETPRINTERDATA *r_u, prs_struct *ps, int depth)
5899 prs_debug(ps, depth, desc, "spoolss_io_r_setprinterdata");
5900 depth++;
5902 if(!prs_align(ps))
5903 return False;
5904 if(!prs_werror("status", ps, depth, &r_u->status))
5905 return False;
5907 return True;
5910 /*******************************************************************
5911 ********************************************************************/
5912 BOOL spoolss_io_q_resetprinter(const char *desc, SPOOL_Q_RESETPRINTER *q_u, prs_struct *ps, int depth)
5914 prs_debug(ps, depth, desc, "spoolss_io_q_resetprinter");
5915 depth++;
5917 if (!prs_align(ps))
5918 return False;
5919 if (!smb_io_pol_hnd("printer handle", &q_u->handle, ps, depth))
5920 return False;
5922 if (!prs_uint32("datatype_ptr", ps, depth, &q_u->datatype_ptr))
5923 return False;
5925 if (q_u->datatype_ptr) {
5926 if (!smb_io_unistr2("datatype", &q_u->datatype, q_u->datatype_ptr?True:False, ps, depth))
5927 return False;
5930 if (!spoolss_io_devmode_cont(desc, &q_u->devmode_ctr, ps, depth))
5931 return False;
5933 return True;
5937 /*******************************************************************
5938 ********************************************************************/
5939 BOOL spoolss_io_r_resetprinter(const char *desc, SPOOL_R_RESETPRINTER *r_u, prs_struct *ps, int depth)
5941 prs_debug(ps, depth, desc, "spoolss_io_r_resetprinter");
5942 depth++;
5944 if(!prs_align(ps))
5945 return False;
5946 if(!prs_werror("status", ps, depth, &r_u->status))
5947 return False;
5949 return True;
5952 /*******************************************************************
5953 ********************************************************************/
5954 BOOL convert_specific_param(NT_PRINTER_PARAM **param, const UNISTR2 *value,
5955 uint32 type, const uint8 *data, uint32 len)
5957 DEBUG(5,("converting a specific param struct\n"));
5959 if (*param == NULL)
5961 *param=(NT_PRINTER_PARAM *)malloc(sizeof(NT_PRINTER_PARAM));
5962 if(*param == NULL)
5963 return False;
5964 memset((char *)*param, '\0', sizeof(NT_PRINTER_PARAM));
5965 DEBUGADD(6,("Allocated a new PARAM struct\n"));
5967 unistr2_to_dos((*param)->value, value, sizeof((*param)->value)-1);
5968 (*param)->type = type;
5970 /* le champ data n'est pas NULL termine */
5971 /* on stocke donc la longueur */
5973 (*param)->data_len=len;
5975 if (len) {
5976 (*param)->data=(uint8 *)malloc(len * sizeof(uint8));
5977 if((*param)->data == NULL)
5978 return False;
5979 memcpy((*param)->data, data, len);
5982 DEBUGADD(6,("\tvalue:[%s], len:[%d]\n",(*param)->value, (*param)->data_len));
5983 dump_data(10, (char *)(*param)->data, (*param)->data_len);
5985 return True;
5988 /*******************************************************************
5989 ********************************************************************/
5991 static BOOL spoolss_io_addform(const char *desc, FORM *f, uint32 ptr, prs_struct *ps, int depth)
5993 prs_debug(ps, depth, desc, "spoolss_io_addform");
5994 depth++;
5995 if(!prs_align(ps))
5996 return False;
5998 if (ptr!=0)
6000 if(!prs_uint32("flags", ps, depth, &f->flags))
6001 return False;
6002 if(!prs_uint32("name_ptr", ps, depth, &f->name_ptr))
6003 return False;
6004 if(!prs_uint32("size_x", ps, depth, &f->size_x))
6005 return False;
6006 if(!prs_uint32("size_y", ps, depth, &f->size_y))
6007 return False;
6008 if(!prs_uint32("left", ps, depth, &f->left))
6009 return False;
6010 if(!prs_uint32("top", ps, depth, &f->top))
6011 return False;
6012 if(!prs_uint32("right", ps, depth, &f->right))
6013 return False;
6014 if(!prs_uint32("bottom", ps, depth, &f->bottom))
6015 return False;
6017 if(!smb_io_unistr2("", &f->name, f->name_ptr, ps, depth))
6018 return False;
6021 return True;
6024 /*******************************************************************
6025 ********************************************************************/
6027 BOOL spoolss_io_q_deleteform(const char *desc, SPOOL_Q_DELETEFORM *q_u, prs_struct *ps, int depth)
6029 prs_debug(ps, depth, desc, "spoolss_io_q_deleteform");
6030 depth++;
6032 if(!prs_align(ps))
6033 return False;
6034 if(!smb_io_pol_hnd("printer handle", &q_u->handle, ps, depth))
6035 return False;
6036 if(!smb_io_unistr2("form name", &q_u->name, True, ps, depth))
6037 return False;
6039 return True;
6042 /*******************************************************************
6043 ********************************************************************/
6045 BOOL spoolss_io_r_deleteform(const char *desc, SPOOL_R_DELETEFORM *r_u, prs_struct *ps, int depth)
6047 prs_debug(ps, depth, desc, "spoolss_io_r_deleteform");
6048 depth++;
6050 if(!prs_align(ps))
6051 return False;
6052 if(!prs_werror("status", ps, depth, &r_u->status))
6053 return False;
6055 return True;
6058 /*******************************************************************
6059 ********************************************************************/
6061 BOOL spoolss_io_q_addform(const char *desc, SPOOL_Q_ADDFORM *q_u, prs_struct *ps, int depth)
6063 uint32 useless_ptr=1;
6064 prs_debug(ps, depth, desc, "spoolss_io_q_addform");
6065 depth++;
6067 if(!prs_align(ps))
6068 return False;
6069 if(!smb_io_pol_hnd("printer handle", &q_u->handle, ps, depth))
6070 return False;
6071 if(!prs_uint32("level", ps, depth, &q_u->level))
6072 return False;
6073 if(!prs_uint32("level2", ps, depth, &q_u->level2))
6074 return False;
6076 if (q_u->level==1)
6078 if(!prs_uint32("useless_ptr", ps, depth, &useless_ptr))
6079 return False;
6080 if(!spoolss_io_addform("", &q_u->form, useless_ptr, ps, depth))
6081 return False;
6084 return True;
6087 /*******************************************************************
6088 ********************************************************************/
6090 BOOL spoolss_io_r_addform(const char *desc, SPOOL_R_ADDFORM *r_u, prs_struct *ps, int depth)
6092 prs_debug(ps, depth, desc, "spoolss_io_r_addform");
6093 depth++;
6095 if(!prs_align(ps))
6096 return False;
6097 if(!prs_werror("status", ps, depth, &r_u->status))
6098 return False;
6100 return True;
6103 /*******************************************************************
6104 ********************************************************************/
6106 BOOL spoolss_io_q_setform(const char *desc, SPOOL_Q_SETFORM *q_u, prs_struct *ps, int depth)
6108 uint32 useless_ptr=1;
6109 prs_debug(ps, depth, desc, "spoolss_io_q_setform");
6110 depth++;
6112 if(!prs_align(ps))
6113 return False;
6114 if(!smb_io_pol_hnd("printer handle", &q_u->handle, ps, depth))
6115 return False;
6116 if(!smb_io_unistr2("", &q_u->name, True, ps, depth))
6117 return False;
6119 if(!prs_align(ps))
6120 return False;
6122 if(!prs_uint32("level", ps, depth, &q_u->level))
6123 return False;
6124 if(!prs_uint32("level2", ps, depth, &q_u->level2))
6125 return False;
6127 if (q_u->level==1)
6129 if(!prs_uint32("useless_ptr", ps, depth, &useless_ptr))
6130 return False;
6131 if(!spoolss_io_addform("", &q_u->form, useless_ptr, ps, depth))
6132 return False;
6135 return True;
6138 /*******************************************************************
6139 ********************************************************************/
6141 BOOL spoolss_io_r_setform(const char *desc, SPOOL_R_SETFORM *r_u, prs_struct *ps, int depth)
6143 prs_debug(ps, depth, desc, "spoolss_io_r_setform");
6144 depth++;
6146 if(!prs_align(ps))
6147 return False;
6148 if(!prs_werror("status", ps, depth, &r_u->status))
6149 return False;
6151 return True;
6154 /*******************************************************************
6155 Parse a SPOOL_R_GETJOB structure.
6156 ********************************************************************/
6158 BOOL spoolss_io_r_getjob(const char *desc, SPOOL_R_GETJOB *r_u, prs_struct *ps, int depth)
6160 prs_debug(ps, depth, desc, "spoolss_io_r_getjob");
6161 depth++;
6163 if (!prs_align(ps))
6164 return False;
6166 if (!spoolss_io_buffer("", ps, depth, &r_u->buffer))
6167 return False;
6169 if (!prs_align(ps))
6170 return False;
6172 if (!prs_uint32("needed", ps, depth, &r_u->needed))
6173 return False;
6175 if (!prs_werror("status", ps, depth, &r_u->status))
6176 return False;
6178 return True;
6181 /*******************************************************************
6182 Parse a SPOOL_Q_GETJOB structure.
6183 ********************************************************************/
6185 BOOL spoolss_io_q_getjob(const char *desc, SPOOL_Q_GETJOB *q_u, prs_struct *ps, int depth)
6187 prs_debug(ps, depth, desc, "");
6188 depth++;
6190 if(!prs_align(ps))
6191 return False;
6193 if(!smb_io_pol_hnd("printer handle",&q_u->handle,ps,depth))
6194 return False;
6195 if(!prs_uint32("jobid", ps, depth, &q_u->jobid))
6196 return False;
6197 if(!prs_uint32("level", ps, depth, &q_u->level))
6198 return False;
6200 if(!spoolss_io_buffer("", ps, depth, &q_u->buffer))
6201 return False;
6203 if(!prs_align(ps))
6204 return False;
6206 if(!prs_uint32("offered", ps, depth, &q_u->offered))
6207 return False;
6209 return True;
6212 void free_devmode(DEVICEMODE *devmode)
6214 if (devmode!=NULL) {
6215 SAFE_FREE(devmode->private);
6216 SAFE_FREE(devmode);
6220 void free_printer_info_1(PRINTER_INFO_1 *printer)
6222 SAFE_FREE(printer);
6225 void free_printer_info_2(PRINTER_INFO_2 *printer)
6227 if (printer!=NULL) {
6228 free_devmode(printer->devmode);
6229 printer->devmode = NULL;
6230 SAFE_FREE(printer);
6234 void free_printer_info_3(PRINTER_INFO_3 *printer)
6236 SAFE_FREE(printer);
6239 void free_printer_info_4(PRINTER_INFO_4 *printer)
6241 SAFE_FREE(printer);
6244 void free_printer_info_5(PRINTER_INFO_5 *printer)
6246 SAFE_FREE(printer);
6249 void free_job_info_2(JOB_INFO_2 *job)
6251 if (job!=NULL)
6252 free_devmode(job->devmode);
6255 /*******************************************************************
6256 * init a structure.
6257 ********************************************************************/
6259 BOOL make_spoolss_q_replyopenprinter(SPOOL_Q_REPLYOPENPRINTER *q_u,
6260 const fstring string, uint32 printer, uint32 type)
6262 if (q_u == NULL)
6263 return False;
6265 init_unistr2(&q_u->string, string, strlen(string)+1);
6267 q_u->printer=printer;
6268 q_u->type=type;
6270 q_u->unknown0=0x0;
6271 q_u->unknown1=0x0;
6273 return True;
6276 /*******************************************************************
6277 Parse a SPOOL_Q_REPLYOPENPRINTER structure.
6278 ********************************************************************/
6280 BOOL spoolss_io_q_replyopenprinter(const char *desc, SPOOL_Q_REPLYOPENPRINTER *q_u, prs_struct *ps, int depth)
6282 prs_debug(ps, depth, desc, "spoolss_io_q_replyopenprinter");
6283 depth++;
6285 if(!prs_align(ps))
6286 return False;
6288 if(!smb_io_unistr2("", &q_u->string, True, ps, depth))
6289 return False;
6291 if(!prs_align(ps))
6292 return False;
6294 if(!prs_uint32("printer", ps, depth, &q_u->printer))
6295 return False;
6296 if(!prs_uint32("type", ps, depth, &q_u->type))
6297 return False;
6299 if(!prs_uint32("unknown0", ps, depth, &q_u->unknown0))
6300 return False;
6301 if(!prs_uint32("unknown1", ps, depth, &q_u->unknown1))
6302 return False;
6304 return True;
6307 /*******************************************************************
6308 Parse a SPOOL_R_REPLYOPENPRINTER structure.
6309 ********************************************************************/
6311 BOOL spoolss_io_r_replyopenprinter(const char *desc, SPOOL_R_REPLYOPENPRINTER *r_u, prs_struct *ps, int depth)
6313 prs_debug(ps, depth, desc, "spoolss_io_r_replyopenprinter");
6314 depth++;
6316 if (!prs_align(ps))
6317 return False;
6319 if(!smb_io_pol_hnd("printer handle",&r_u->handle,ps,depth))
6320 return False;
6322 if (!prs_werror("status", ps, depth, &r_u->status))
6323 return False;
6325 return True;
6328 /*******************************************************************
6329 * init a structure.
6330 ********************************************************************/
6331 BOOL make_spoolss_q_routerreplyprinter(SPOOL_Q_ROUTERREPLYPRINTER *q_u, POLICY_HND *hnd,
6332 uint32 condition, uint32 change_id)
6335 memcpy(&q_u->handle, hnd, sizeof(q_u->handle));
6337 q_u->condition = condition;
6338 q_u->change_id = change_id;
6340 /* magic values */
6341 q_u->unknown1 = 0x1;
6342 memset(q_u->unknown2, 0x0, 5);
6343 q_u->unknown2[0] = 0x1;
6345 return True;
6348 /*******************************************************************
6349 Parse a SPOOL_Q_ROUTERREPLYPRINTER structure.
6350 ********************************************************************/
6351 BOOL spoolss_io_q_routerreplyprinter (const char *desc, SPOOL_Q_ROUTERREPLYPRINTER *q_u, prs_struct *ps, int depth)
6354 prs_debug(ps, depth, desc, "spoolss_io_q_routerreplyprinter");
6355 depth++;
6357 if (!prs_align(ps))
6358 return False;
6360 if(!smb_io_pol_hnd("printer handle",&q_u->handle,ps,depth))
6361 return False;
6363 if (!prs_uint32("condition", ps, depth, &q_u->condition))
6364 return False;
6366 if (!prs_uint32("unknown1", ps, depth, &q_u->unknown1))
6367 return False;
6369 if (!prs_uint32("change_id", ps, depth, &q_u->change_id))
6370 return False;
6372 if (!prs_uint8s(False, "private", ps, depth, q_u->unknown2, 5))
6373 return False;
6375 return True;
6378 /*******************************************************************
6379 Parse a SPOOL_R_ROUTERREPLYPRINTER structure.
6380 ********************************************************************/
6381 BOOL spoolss_io_r_routerreplyprinter (const char *desc, SPOOL_R_ROUTERREPLYPRINTER *r_u, prs_struct *ps, int depth)
6383 prs_debug(ps, depth, desc, "spoolss_io_r_routerreplyprinter");
6384 depth++;
6386 if (!prs_align(ps))
6387 return False;
6389 if (!prs_werror("status", ps, depth, &r_u->status))
6390 return False;
6392 return True;
6395 /*******************************************************************
6396 * init a structure.
6397 ********************************************************************/
6399 BOOL make_spoolss_q_reply_closeprinter(SPOOL_Q_REPLYCLOSEPRINTER *q_u, POLICY_HND *hnd)
6401 if (q_u == NULL)
6402 return False;
6404 memcpy(&q_u->handle, hnd, sizeof(q_u->handle));
6406 return True;
6409 /*******************************************************************
6410 Parse a SPOOL_Q_REPLYCLOSEPRINTER structure.
6411 ********************************************************************/
6413 BOOL spoolss_io_q_replycloseprinter(const char *desc, SPOOL_Q_REPLYCLOSEPRINTER *q_u, prs_struct *ps, int depth)
6415 prs_debug(ps, depth, desc, "spoolss_io_q_replycloseprinter");
6416 depth++;
6418 if(!prs_align(ps))
6419 return False;
6421 if(!smb_io_pol_hnd("printer handle",&q_u->handle,ps,depth))
6422 return False;
6424 return True;
6427 /*******************************************************************
6428 Parse a SPOOL_R_REPLYCLOSEPRINTER structure.
6429 ********************************************************************/
6431 BOOL spoolss_io_r_replycloseprinter(const char *desc, SPOOL_R_REPLYCLOSEPRINTER *r_u, prs_struct *ps, int depth)
6433 prs_debug(ps, depth, desc, "spoolss_io_r_replycloseprinter");
6434 depth++;
6436 if (!prs_align(ps))
6437 return False;
6439 if(!smb_io_pol_hnd("printer handle",&r_u->handle,ps,depth))
6440 return False;
6442 if (!prs_werror("status", ps, depth, &r_u->status))
6443 return False;
6445 return True;
6448 #if 0 /* JERRY - not currently used but could be :-) */
6450 /*******************************************************************
6451 Deep copy a SPOOL_NOTIFY_INFO_DATA structure
6452 ******************************************************************/
6453 static BOOL copy_spool_notify_info_data(SPOOL_NOTIFY_INFO_DATA *dst,
6454 SPOOL_NOTIFY_INFO_DATA *src, int n)
6456 int i;
6458 memcpy(dst, src, sizeof(SPOOL_NOTIFY_INFO_DATA)*n);
6460 for (i=0; i<n; i++) {
6461 int len;
6462 uint16 *s = NULL;
6464 if (src->size != POINTER)
6465 continue;
6466 len = src->notify_data.data.length;
6467 s = malloc(sizeof(uint16)*len);
6468 if (s == NULL) {
6469 DEBUG(0,("copy_spool_notify_info_data: malloc() failed!\n"));
6470 return False;
6473 memcpy(s, src->notify_data.data.string, len*2);
6474 dst->notify_data.data.string = s;
6477 return True;
6480 /*******************************************************************
6481 Deep copy a SPOOL_NOTIFY_INFO structure
6482 ******************************************************************/
6483 static BOOL copy_spool_notify_info(SPOOL_NOTIFY_INFO *dst, SPOOL_NOTIFY_INFO *src)
6485 if (!dst) {
6486 DEBUG(0,("copy_spool_notify_info: NULL destination pointer!\n"));
6487 return False;
6490 dst->version = src->version;
6491 dst->flags = src->flags;
6492 dst->count = src->count;
6494 if (dst->count)
6496 dst->data = malloc(dst->count * sizeof(SPOOL_NOTIFY_INFO_DATA));
6498 DEBUG(10,("copy_spool_notify_info: allocating space for [%d] PRINTER_NOTIFY_INFO_DATA entries\n",
6499 dst->count));
6501 if (dst->data == NULL) {
6502 DEBUG(0,("copy_spool_notify_info: malloc() failed for [%d] entries!\n",
6503 dst->count));
6504 return False;
6507 return (copy_spool_notify_info_data(dst->data, src->data, src->count));
6510 return True;
6512 #endif /* JERRY */
6514 /*******************************************************************
6515 * init a structure.
6516 ********************************************************************/
6518 BOOL make_spoolss_q_reply_rrpcn(SPOOL_Q_REPLY_RRPCN *q_u, POLICY_HND *hnd,
6519 uint32 change_low, uint32 change_high,
6520 SPOOL_NOTIFY_INFO *info)
6522 if (q_u == NULL)
6523 return False;
6525 memcpy(&q_u->handle, hnd, sizeof(q_u->handle));
6527 q_u->change_low=change_low;
6528 q_u->change_high=change_high;
6530 q_u->unknown0=0x0;
6531 q_u->unknown1=0x0;
6533 q_u->info_ptr=0xaddee11e;
6535 q_u->info.version=2;
6537 if (info->count) {
6538 DEBUG(10,("make_spoolss_q_reply_rrpcn: [%d] PRINTER_NOTIFY_INFO_DATA\n",
6539 info->count));
6540 q_u->info.version = info->version;
6541 q_u->info.flags = info->flags;
6542 q_u->info.count = info->count;
6543 /* pointer field - be careful! */
6544 q_u->info.data = info->data;
6546 else {
6547 q_u->info.flags=PRINTER_NOTIFY_INFO_DISCARDED;
6548 q_u->info.count=0;
6551 return True;
6554 /*******************************************************************
6555 Parse a SPOOL_Q_REPLY_RRPCN structure.
6556 ********************************************************************/
6558 BOOL spoolss_io_q_reply_rrpcn(const char *desc, SPOOL_Q_REPLY_RRPCN *q_u, prs_struct *ps, int depth)
6560 prs_debug(ps, depth, desc, "spoolss_io_q_reply_rrpcn");
6561 depth++;
6563 if(!prs_align(ps))
6564 return False;
6566 if(!smb_io_pol_hnd("printer handle",&q_u->handle,ps,depth))
6567 return False;
6569 if (!prs_uint32("change_low", ps, depth, &q_u->change_low))
6570 return False;
6572 if (!prs_uint32("change_high", ps, depth, &q_u->change_high))
6573 return False;
6575 if (!prs_uint32("unknown0", ps, depth, &q_u->unknown0))
6576 return False;
6578 if (!prs_uint32("unknown1", ps, depth, &q_u->unknown1))
6579 return False;
6581 if (!prs_uint32("info_ptr", ps, depth, &q_u->info_ptr))
6582 return False;
6584 if(q_u->info_ptr!=0)
6585 if(!smb_io_notify_info(desc, &q_u->info, ps, depth))
6586 return False;
6588 return True;
6591 /*******************************************************************
6592 Parse a SPOOL_R_REPLY_RRPCN structure.
6593 ********************************************************************/
6595 BOOL spoolss_io_r_reply_rrpcn(const char *desc, SPOOL_R_REPLY_RRPCN *r_u, prs_struct *ps, int depth)
6597 prs_debug(ps, depth, desc, "spoolss_io_r_reply_rrpcn");
6598 depth++;
6600 if (!prs_align(ps))
6601 return False;
6603 if (!prs_uint32("unknown0", ps, depth, &r_u->unknown0))
6604 return False;
6606 if (!prs_werror("status", ps, depth, &r_u->status))
6607 return False;
6609 return True;
6612 /*******************************************************************
6613 * read a structure.
6614 * called from spoolss_q_getprinterdataex (srv_spoolss.c)
6615 ********************************************************************/
6617 BOOL spoolss_io_q_getprinterdataex(const char *desc, SPOOL_Q_GETPRINTERDATAEX *q_u, prs_struct *ps, int depth)
6619 if (q_u == NULL)
6620 return False;
6622 prs_debug(ps, depth, desc, "spoolss_io_q_getprinterdataex");
6623 depth++;
6625 if (!prs_align(ps))
6626 return False;
6627 if (!smb_io_pol_hnd("printer handle",&q_u->handle,ps,depth))
6628 return False;
6629 if (!prs_align(ps))
6630 return False;
6631 if (!smb_io_unistr2("keyname", &q_u->keyname,True,ps,depth))
6632 return False;
6633 if (!prs_align(ps))
6634 return False;
6635 if (!smb_io_unistr2("valuename", &q_u->valuename,True,ps,depth))
6636 return False;
6637 if (!prs_align(ps))
6638 return False;
6639 if (!prs_uint32("size", ps, depth, &q_u->size))
6640 return False;
6642 return True;
6645 /*******************************************************************
6646 * write a structure.
6647 * called from spoolss_r_getprinterdataex (srv_spoolss.c)
6648 ********************************************************************/
6650 BOOL spoolss_io_r_getprinterdataex(const char *desc, SPOOL_R_GETPRINTERDATAEX *r_u, prs_struct *ps, int depth)
6652 if (r_u == NULL)
6653 return False;
6655 prs_debug(ps, depth, desc, "spoolss_io_r_getprinterdataex");
6656 depth++;
6658 if (!prs_align(ps))
6659 return False;
6660 if (!prs_uint32("type", ps, depth, &r_u->type))
6661 return False;
6662 if (!prs_uint32("size", ps, depth, &r_u->size))
6663 return False;
6665 if (UNMARSHALLING(ps) && r_u->size) {
6666 r_u->data = prs_alloc_mem(ps, r_u->size);
6667 if(!r_u->data)
6668 return False;
6671 if (!prs_uint8s(False,"data", ps, depth, r_u->data, r_u->size))
6672 return False;
6674 if (!prs_align(ps))
6675 return False;
6677 if (!prs_uint32("needed", ps, depth, &r_u->needed))
6678 return False;
6679 if (!prs_werror("status", ps, depth, &r_u->status))
6680 return False;
6682 return True;
6685 /*******************************************************************
6686 * read a structure.
6687 ********************************************************************/
6689 BOOL spoolss_io_q_setprinterdataex(const char *desc, SPOOL_Q_SETPRINTERDATAEX *q_u, prs_struct *ps, int depth)
6691 prs_debug(ps, depth, desc, "spoolss_io_q_setprinterdataex");
6692 depth++;
6694 if(!prs_align(ps))
6695 return False;
6696 if(!smb_io_pol_hnd("printer handle", &q_u->handle, ps, depth))
6697 return False;
6698 if(!smb_io_unistr2("", &q_u->key, True, ps, depth))
6699 return False;
6701 if(!prs_align(ps))
6702 return False;
6704 if(!smb_io_unistr2("", &q_u->value, True, ps, depth))
6705 return False;
6707 if(!prs_align(ps))
6708 return False;
6710 if(!prs_uint32("type", ps, depth, &q_u->type))
6711 return False;
6713 if(!prs_uint32("max_len", ps, depth, &q_u->max_len))
6714 return False;
6716 switch (q_u->type)
6718 case 0x1:
6719 case 0x3:
6720 case 0x4:
6721 case 0x7:
6722 if (q_u->max_len) {
6723 if (UNMARSHALLING(ps))
6724 q_u->data=(uint8 *)prs_alloc_mem(ps, q_u->max_len * sizeof(uint8));
6725 if(q_u->data == NULL)
6726 return False;
6727 if(!prs_uint8s(False,"data", ps, depth, q_u->data, q_u->max_len))
6728 return False;
6730 if(!prs_align(ps))
6731 return False;
6732 break;
6735 if(!prs_uint32("real_len", ps, depth, &q_u->real_len))
6736 return False;
6738 return True;
6741 /*******************************************************************
6742 * write a structure.
6743 ********************************************************************/
6745 BOOL spoolss_io_r_setprinterdataex(const char *desc, SPOOL_R_SETPRINTERDATAEX *r_u, prs_struct *ps, int depth)
6747 prs_debug(ps, depth, desc, "spoolss_io_r_setprinterdataex");
6748 depth++;
6750 if(!prs_align(ps))
6751 return False;
6752 if(!prs_werror("status", ps, depth, &r_u->status))
6753 return False;
6755 return True;
6759 /*******************************************************************
6760 * read a structure.
6761 ********************************************************************/
6763 BOOL spoolss_io_q_enumprinterkey(const char *desc, SPOOL_Q_ENUMPRINTERKEY *q_u, prs_struct *ps, int depth)
6765 prs_debug(ps, depth, desc, "spoolss_io_q_enumprinterkey");
6766 depth++;
6768 if(!prs_align(ps))
6769 return False;
6770 if(!smb_io_pol_hnd("printer handle", &q_u->handle, ps, depth))
6771 return False;
6773 if(!smb_io_unistr2("", &q_u->key, True, ps, depth))
6774 return False;
6776 if(!prs_align(ps))
6777 return False;
6779 if(!prs_uint32("size", ps, depth, &q_u->size))
6780 return False;
6782 return True;
6785 /*******************************************************************
6786 * write a structure.
6787 ********************************************************************/
6789 BOOL spoolss_io_r_enumprinterkey(const char *desc, SPOOL_R_ENUMPRINTERKEY *r_u, prs_struct *ps, int depth)
6791 prs_debug(ps, depth, desc, "spoolss_io_r_enumprinterkey");
6792 depth++;
6794 if(!prs_align(ps))
6795 return False;
6797 if (!smb_io_buffer5("", &r_u->keys, ps, depth))
6798 return False;
6800 if(!prs_align(ps))
6801 return False;
6803 if(!prs_uint32("needed", ps, depth, &r_u->needed))
6804 return False;
6806 if(!prs_werror("status", ps, depth, &r_u->status))
6807 return False;
6809 return True;
6813 /*******************************************************************
6814 * read a structure.
6815 ********************************************************************/
6817 BOOL spoolss_io_q_enumprinterdataex(const char *desc, SPOOL_Q_ENUMPRINTERDATAEX *q_u, prs_struct *ps, int depth)
6819 prs_debug(ps, depth, desc, "spoolss_io_q_enumprinterdataex");
6820 depth++;
6822 if(!prs_align(ps))
6823 return False;
6824 if(!smb_io_pol_hnd("printer handle", &q_u->handle, ps, depth))
6825 return False;
6827 if(!smb_io_unistr2("", &q_u->key, True, ps, depth))
6828 return False;
6830 if(!prs_align(ps))
6831 return False;
6833 if(!prs_uint32("size", ps, depth, &q_u->size))
6834 return False;
6836 return True;
6839 /*******************************************************************
6840 ********************************************************************/
6842 static BOOL spoolss_io_printer_enum_values_ctr(const char *desc, prs_struct *ps,
6843 PRINTER_ENUM_VALUES_CTR *ctr, int depth)
6845 int i;
6846 uint32 valuename_offset,
6847 data_offset,
6848 current_offset;
6849 const uint32 basic_unit = 20; /* size of static portion of enum_values */
6851 prs_debug(ps, depth, desc, "spoolss_io_printer_enum_values_ctr");
6852 depth++;
6855 * offset data begins at 20 bytes per structure * size_of_array.
6856 * Don't forget the uint32 at the beginning
6857 * */
6859 current_offset = basic_unit * ctr->size_of_array;
6861 /* first loop to write basic enum_value information */
6863 if (UNMARSHALLING(ps)) {
6864 ctr->values = (PRINTER_ENUM_VALUES *)prs_alloc_mem(
6865 ps, ctr->size_of_array * sizeof(PRINTER_ENUM_VALUES));
6866 if (!ctr->values)
6867 return False;
6870 for (i=0; i<ctr->size_of_array; i++) {
6871 valuename_offset = current_offset;
6872 if (!prs_uint32("valuename_offset", ps, depth, &valuename_offset))
6873 return False;
6875 if (!prs_uint32("value_len", ps, depth, &ctr->values[i].value_len))
6876 return False;
6878 if (!prs_uint32("type", ps, depth, &ctr->values[i].type))
6879 return False;
6881 data_offset = ctr->values[i].value_len + valuename_offset;
6883 if (!prs_uint32("data_offset", ps, depth, &data_offset))
6884 return False;
6886 if (!prs_uint32("data_len", ps, depth, &ctr->values[i].data_len))
6887 return False;
6889 current_offset = data_offset + ctr->values[i].data_len - basic_unit;
6890 /* account for 2 byte alignment */
6891 current_offset += (current_offset % 2);
6895 * loop #2 for writing the dynamically size objects; pay
6896 * attention to 2-byte alignment here....
6899 for (i=0; i<ctr->size_of_array; i++) {
6901 if (!prs_unistr("valuename", ps, depth, &ctr->values[i].valuename))
6902 return False;
6904 if (UNMARSHALLING(ps)) {
6905 ctr->values[i].data = (uint8 *)prs_alloc_mem(
6906 ps, ctr->values[i].data_len);
6907 if (!ctr->values[i].data)
6908 return False;
6911 if (!prs_uint8s(False, "data", ps, depth, ctr->values[i].data, ctr->values[i].data_len))
6912 return False;
6914 if ( !prs_align_uint16(ps) )
6915 return False;
6918 return True;
6921 /*******************************************************************
6922 * write a structure.
6923 ********************************************************************/
6925 BOOL spoolss_io_r_enumprinterdataex(const char *desc, SPOOL_R_ENUMPRINTERDATAEX *r_u, prs_struct *ps, int depth)
6927 uint32 data_offset, end_offset;
6928 prs_debug(ps, depth, desc, "spoolss_io_r_enumprinterdataex");
6929 depth++;
6931 if(!prs_align(ps))
6932 return False;
6934 if (!prs_uint32("size", ps, depth, &r_u->ctr.size))
6935 return False;
6937 data_offset = prs_offset(ps);
6939 if (!prs_set_offset(ps, data_offset + r_u->ctr.size))
6940 return False;
6942 if(!prs_align(ps))
6943 return False;
6945 if(!prs_uint32("needed", ps, depth, &r_u->needed))
6946 return False;
6948 if(!prs_uint32("returned", ps, depth, &r_u->returned))
6949 return False;
6951 if(!prs_werror("status", ps, depth, &r_u->status))
6952 return False;
6954 r_u->ctr.size_of_array = r_u->returned;
6956 end_offset = prs_offset(ps);
6958 if (!prs_set_offset(ps, data_offset))
6959 return False;
6961 if (r_u->ctr.size)
6962 if (!spoolss_io_printer_enum_values_ctr("", ps, &r_u->ctr, depth ))
6963 return False;
6965 if (!prs_set_offset(ps, end_offset))
6966 return False;
6967 return True;
6970 /*******************************************************************
6971 * write a structure.
6972 ********************************************************************/
6975 uint32 GetPrintProcessorDirectory(
6976 [in] unistr2 *name,
6977 [in] unistr2 *environment,
6978 [in] uint32 level,
6979 [in,out] NEW_BUFFER buffer,
6980 [in] uint32 offered,
6981 [out] uint32 needed,
6982 [out] uint32 returned
6987 BOOL make_spoolss_q_getprintprocessordirectory(SPOOL_Q_GETPRINTPROCESSORDIRECTORY *q_u, const char *name, char *environment, int level, NEW_BUFFER *buffer, uint32 offered)
6989 DEBUG(5,("make_spoolss_q_getprintprocessordirectory\n"));
6991 init_unistr2(&q_u->name, name, strlen(name)+1);
6992 init_unistr2(&q_u->environment, environment, strlen(environment)+1);
6994 q_u->level = level;
6996 q_u->buffer = buffer;
6997 q_u->offered = offered;
6999 return True;
7002 BOOL spoolss_io_q_getprintprocessordirectory(const char *desc, SPOOL_Q_GETPRINTPROCESSORDIRECTORY *q_u, prs_struct *ps, int depth)
7004 uint32 ptr;
7006 prs_debug(ps, depth, desc, "spoolss_io_q_getprintprocessordirectory");
7007 depth++;
7009 if(!prs_align(ps))
7010 return False;
7012 if (!prs_uint32("ptr", ps, depth, &ptr))
7013 return False;
7015 if (ptr) {
7016 if(!smb_io_unistr2("name", &q_u->name, True, ps, depth))
7017 return False;
7020 if (!prs_align(ps))
7021 return False;
7023 if (!prs_uint32("ptr", ps, depth, &ptr))
7024 return False;
7026 if (ptr) {
7027 if(!smb_io_unistr2("environment", &q_u->environment, True,
7028 ps, depth))
7029 return False;
7032 if (!prs_align(ps))
7033 return False;
7035 if(!prs_uint32("level", ps, depth, &q_u->level))
7036 return False;
7038 if(!spoolss_io_buffer("", ps, depth, &q_u->buffer))
7039 return False;
7041 if(!prs_align(ps))
7042 return False;
7044 if(!prs_uint32("offered", ps, depth, &q_u->offered))
7045 return False;
7047 return True;
7050 /*******************************************************************
7051 * write a structure.
7052 ********************************************************************/
7054 BOOL spoolss_io_r_getprintprocessordirectory(const char *desc, SPOOL_R_GETPRINTPROCESSORDIRECTORY *r_u, prs_struct *ps, int depth)
7056 prs_debug(ps, depth, desc, "spoolss_io_r_getprintprocessordirectory");
7057 depth++;
7059 if(!prs_align(ps))
7060 return False;
7062 if(!spoolss_io_buffer("", ps, depth, &r_u->buffer))
7063 return False;
7065 if(!prs_align(ps))
7066 return False;
7068 if(!prs_uint32("needed", ps, depth, &r_u->needed))
7069 return False;
7071 if(!prs_werror("status", ps, depth, &r_u->status))
7072 return False;
7074 return True;
7077 BOOL smb_io_printprocessordirectory_1(const char *desc, NEW_BUFFER *buffer, PRINTPROCESSOR_DIRECTORY_1 *info, int depth)
7079 prs_struct *ps=&buffer->prs;
7081 prs_debug(ps, depth, desc, "smb_io_printprocessordirectory_1");
7082 depth++;
7084 buffer->struct_start=prs_offset(ps);
7086 if (!smb_io_unistr(desc, &info->name, ps, depth))
7087 return False;
7089 return True;
7092 /*******************************************************************
7093 * init a structure.
7094 ********************************************************************/
7096 BOOL make_spoolss_q_addform(SPOOL_Q_ADDFORM *q_u, POLICY_HND *handle,
7097 int level, FORM *form)
7099 memcpy(&q_u->handle, handle, sizeof(POLICY_HND));
7100 q_u->level = level;
7101 q_u->level2 = level;
7102 memcpy(&q_u->form, form, sizeof(FORM));
7104 return True;
7107 /*******************************************************************
7108 * init a structure.
7109 ********************************************************************/
7111 BOOL make_spoolss_q_setform(SPOOL_Q_SETFORM *q_u, POLICY_HND *handle,
7112 int level, char *form_name, FORM *form)
7114 memcpy(&q_u->handle, handle, sizeof(POLICY_HND));
7115 q_u->level = level;
7116 q_u->level2 = level;
7117 memcpy(&q_u->form, form, sizeof(FORM));
7118 init_unistr2(&q_u->name, form_name, strlen(form_name) + 1);
7120 return True;
7123 /*******************************************************************
7124 * init a structure.
7125 ********************************************************************/
7127 BOOL make_spoolss_q_deleteform(SPOOL_Q_DELETEFORM *q_u, POLICY_HND *handle, char *form)
7129 memcpy(&q_u->handle, handle, sizeof(POLICY_HND));
7130 init_unistr2(&q_u->name, form, strlen(form) + 1);
7131 return True;
7134 /*******************************************************************
7135 * init a structure.
7136 ********************************************************************/
7138 BOOL make_spoolss_q_getform(SPOOL_Q_GETFORM *q_u, POLICY_HND *handle,
7139 char *formname, uint32 level, NEW_BUFFER *buffer,
7140 uint32 offered)
7142 memcpy(&q_u->handle, handle, sizeof(POLICY_HND));
7143 q_u->level = level;
7144 init_unistr2(&q_u->formname, formname, strlen(formname) + 1);
7145 q_u->buffer=buffer;
7146 q_u->offered=offered;
7148 return True;
7151 /*******************************************************************
7152 * init a structure.
7153 ********************************************************************/
7155 BOOL make_spoolss_q_enumforms(SPOOL_Q_ENUMFORMS *q_u, POLICY_HND *handle,
7156 uint32 level, NEW_BUFFER *buffer,
7157 uint32 offered)
7159 memcpy(&q_u->handle, handle, sizeof(POLICY_HND));
7160 q_u->level = level;
7161 q_u->buffer=buffer;
7162 q_u->offered=offered;
7164 return True;