r3684: syncing up some changes for 3.0.9
[Samba.git] / source / rpc_parse / parse_spoolss.c
blob6362dcf0f1d92675f59252db7c9a84ac2cec46f2
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 #undef DBGC_CLASS
28 #define DBGC_CLASS DBGC_RPC_PARSE
30 /*******************************************************************
31 return the length of a UNISTR string.
32 ********************************************************************/
34 static uint32 str_len_uni(UNISTR *source)
36 uint32 i=0;
38 if (!source->buffer)
39 return 0;
41 while (source->buffer[i])
42 i++;
44 return i;
47 /*******************************************************************
48 This should be moved in a more generic lib.
49 ********************************************************************/
51 BOOL spoolss_io_system_time(const char *desc, prs_struct *ps, int depth, SYSTEMTIME *systime)
53 if(!prs_uint16("year", ps, depth, &systime->year))
54 return False;
55 if(!prs_uint16("month", ps, depth, &systime->month))
56 return False;
57 if(!prs_uint16("dayofweek", ps, depth, &systime->dayofweek))
58 return False;
59 if(!prs_uint16("day", ps, depth, &systime->day))
60 return False;
61 if(!prs_uint16("hour", ps, depth, &systime->hour))
62 return False;
63 if(!prs_uint16("minute", ps, depth, &systime->minute))
64 return False;
65 if(!prs_uint16("second", ps, depth, &systime->second))
66 return False;
67 if(!prs_uint16("milliseconds", ps, depth, &systime->milliseconds))
68 return False;
70 return True;
73 /*******************************************************************
74 ********************************************************************/
76 BOOL make_systemtime(SYSTEMTIME *systime, struct tm *unixtime)
78 systime->year=unixtime->tm_year+1900;
79 systime->month=unixtime->tm_mon+1;
80 systime->dayofweek=unixtime->tm_wday;
81 systime->day=unixtime->tm_mday;
82 systime->hour=unixtime->tm_hour;
83 systime->minute=unixtime->tm_min;
84 systime->second=unixtime->tm_sec;
85 systime->milliseconds=0;
87 return True;
90 /*******************************************************************
91 reads or writes an DOC_INFO structure.
92 ********************************************************************/
94 static BOOL smb_io_doc_info_1(const char *desc, DOC_INFO_1 *info_1, prs_struct *ps, int depth)
96 if (info_1 == NULL) return False;
98 prs_debug(ps, depth, desc, "smb_io_doc_info_1");
99 depth++;
101 if(!prs_align(ps))
102 return False;
104 if(!prs_uint32("p_docname", ps, depth, &info_1->p_docname))
105 return False;
106 if(!prs_uint32("p_outputfile", ps, depth, &info_1->p_outputfile))
107 return False;
108 if(!prs_uint32("p_datatype", ps, depth, &info_1->p_datatype))
109 return False;
111 if(!smb_io_unistr2("", &info_1->docname, info_1->p_docname, ps, depth))
112 return False;
113 if(!smb_io_unistr2("", &info_1->outputfile, info_1->p_outputfile, ps, depth))
114 return False;
115 if(!smb_io_unistr2("", &info_1->datatype, info_1->p_datatype, ps, depth))
116 return False;
118 return True;
121 /*******************************************************************
122 reads or writes an DOC_INFO structure.
123 ********************************************************************/
125 static BOOL smb_io_doc_info(const char *desc, DOC_INFO *info, prs_struct *ps, int depth)
127 uint32 useless_ptr=0;
129 if (info == NULL) return False;
131 prs_debug(ps, depth, desc, "smb_io_doc_info");
132 depth++;
134 if(!prs_align(ps))
135 return False;
137 if(!prs_uint32("switch_value", ps, depth, &info->switch_value))
138 return False;
140 if(!prs_uint32("doc_info_X ptr", ps, depth, &useless_ptr))
141 return False;
143 switch (info->switch_value)
145 case 1:
146 if(!smb_io_doc_info_1("",&info->doc_info_1, ps, depth))
147 return False;
148 break;
149 case 2:
151 this is just a placeholder
153 MSDN July 1998 says doc_info_2 is only on
154 Windows 95, and as Win95 doesn't do RPC to print
155 this case is nearly impossible
157 Maybe one day with Windows for dishwasher 2037 ...
160 /* smb_io_doc_info_2("",&info->doc_info_2, ps, depth); */
161 break;
162 default:
163 DEBUG(0,("Something is obviously wrong somewhere !\n"));
164 break;
167 return True;
170 /*******************************************************************
171 reads or writes an DOC_INFO_CONTAINER structure.
172 ********************************************************************/
174 static BOOL smb_io_doc_info_container(const char *desc, DOC_INFO_CONTAINER *cont, prs_struct *ps, int depth)
176 if (cont == NULL) return False;
178 prs_debug(ps, depth, desc, "smb_io_doc_info_container");
179 depth++;
181 if(!prs_align(ps))
182 return False;
184 if(!prs_uint32("level", ps, depth, &cont->level))
185 return False;
187 if(!smb_io_doc_info("",&cont->docinfo, ps, depth))
188 return False;
190 return True;
193 /*******************************************************************
194 reads or writes an NOTIFY OPTION TYPE structure.
195 ********************************************************************/
197 /* NOTIFY_OPTION_TYPE and NOTIFY_OPTION_TYPE_DATA are really one
198 structure. The _TYPE structure is really the deferred referrants (i.e
199 the notify fields array) of the _TYPE structure. -tpot */
201 static BOOL smb_io_notify_option_type(const char *desc, SPOOL_NOTIFY_OPTION_TYPE *type, prs_struct *ps, int depth)
203 prs_debug(ps, depth, desc, "smb_io_notify_option_type");
204 depth++;
206 if (!prs_align(ps))
207 return False;
209 if(!prs_uint16("type", ps, depth, &type->type))
210 return False;
211 if(!prs_uint16("reserved0", ps, depth, &type->reserved0))
212 return False;
213 if(!prs_uint32("reserved1", ps, depth, &type->reserved1))
214 return False;
215 if(!prs_uint32("reserved2", ps, depth, &type->reserved2))
216 return False;
217 if(!prs_uint32("count", ps, depth, &type->count))
218 return False;
219 if(!prs_uint32("fields_ptr", ps, depth, &type->fields_ptr))
220 return False;
222 return True;
225 /*******************************************************************
226 reads or writes an NOTIFY OPTION TYPE DATA.
227 ********************************************************************/
229 static BOOL smb_io_notify_option_type_data(const char *desc, SPOOL_NOTIFY_OPTION_TYPE *type, prs_struct *ps, int depth)
231 int i;
233 prs_debug(ps, depth, desc, "smb_io_notify_option_type_data");
234 depth++;
236 /* if there are no fields just return */
237 if (type->fields_ptr==0)
238 return True;
240 if(!prs_align(ps))
241 return False;
243 if(!prs_uint32("count2", ps, depth, &type->count2))
244 return False;
246 if (type->count2 != type->count)
247 DEBUG(4,("What a mess, count was %x now is %x !\n", type->count, type->count2));
249 /* parse the option type data */
250 for(i=0;i<type->count2;i++)
251 if(!prs_uint16("fields",ps,depth,&type->fields[i]))
252 return False;
253 return True;
256 /*******************************************************************
257 reads or writes an NOTIFY OPTION structure.
258 ********************************************************************/
260 static BOOL smb_io_notify_option_type_ctr(const char *desc, SPOOL_NOTIFY_OPTION_TYPE_CTR *ctr , prs_struct *ps, int depth)
262 int i;
264 prs_debug(ps, depth, desc, "smb_io_notify_option_type_ctr");
265 depth++;
267 if(!prs_uint32("count", ps, depth, &ctr->count))
268 return False;
270 /* reading */
271 if (UNMARSHALLING(ps))
272 if((ctr->type=(SPOOL_NOTIFY_OPTION_TYPE *)prs_alloc_mem(ps,ctr->count*sizeof(SPOOL_NOTIFY_OPTION_TYPE))) == NULL)
273 return False;
275 /* the option type struct */
276 for(i=0;i<ctr->count;i++)
277 if(!smb_io_notify_option_type("", &ctr->type[i] , ps, depth))
278 return False;
280 /* the type associated with the option type struct */
281 for(i=0;i<ctr->count;i++)
282 if(!smb_io_notify_option_type_data("", &ctr->type[i] , ps, depth))
283 return False;
285 return True;
288 /*******************************************************************
289 reads or writes an NOTIFY OPTION structure.
290 ********************************************************************/
292 static BOOL smb_io_notify_option(const char *desc, SPOOL_NOTIFY_OPTION *option, prs_struct *ps, int depth)
294 prs_debug(ps, depth, desc, "smb_io_notify_option");
295 depth++;
297 if(!prs_uint32("version", ps, depth, &option->version))
298 return False;
299 if(!prs_uint32("flags", ps, depth, &option->flags))
300 return False;
301 if(!prs_uint32("count", ps, depth, &option->count))
302 return False;
303 if(!prs_uint32("option_type_ptr", ps, depth, &option->option_type_ptr))
304 return False;
306 /* marshalling or unmarshalling, that would work */
307 if (option->option_type_ptr!=0) {
308 if(!smb_io_notify_option_type_ctr("", &option->ctr ,ps, depth))
309 return False;
311 else {
312 option->ctr.type=NULL;
313 option->ctr.count=0;
316 return True;
319 /*******************************************************************
320 reads or writes an NOTIFY INFO DATA structure.
321 ********************************************************************/
323 static BOOL smb_io_notify_info_data(const char *desc,SPOOL_NOTIFY_INFO_DATA *data, prs_struct *ps, int depth)
325 uint32 useless_ptr=0x0FF0ADDE;
327 prs_debug(ps, depth, desc, "smb_io_notify_info_data");
328 depth++;
330 if(!prs_align(ps))
331 return False;
332 if(!prs_uint16("type", ps, depth, &data->type))
333 return False;
334 if(!prs_uint16("field", ps, depth, &data->field))
335 return False;
337 if(!prs_uint32("how many words", ps, depth, &data->size))
338 return False;
339 if(!prs_uint32("id", ps, depth, &data->id))
340 return False;
341 if(!prs_uint32("how many words", ps, depth, &data->size))
342 return False;
344 switch (data->enc_type) {
346 /* One and two value data has two uint32 values */
348 case NOTIFY_ONE_VALUE:
349 case NOTIFY_TWO_VALUE:
351 if(!prs_uint32("value[0]", ps, depth, &data->notify_data.value[0]))
352 return False;
353 if(!prs_uint32("value[1]", ps, depth, &data->notify_data.value[1]))
354 return False;
355 break;
357 /* Pointers and strings have a string length and a
358 pointer. For a string the length is expressed as
359 the number of uint16 characters plus a trailing
360 \0\0. */
362 case NOTIFY_POINTER:
364 if(!prs_uint32("string length", ps, depth, &data->notify_data.data.length ))
365 return False;
366 if(!prs_uint32("pointer", ps, depth, &useless_ptr))
367 return False;
369 break;
371 case NOTIFY_STRING:
373 if(!prs_uint32("string length", ps, depth, &data->notify_data.data.length))
374 return False;
376 if(!prs_uint32("pointer", ps, depth, &useless_ptr))
377 return False;
379 break;
381 case NOTIFY_SECDESC:
382 if( !prs_uint32( "sd size", ps, depth, &data->notify_data.sd.size ) )
383 return False;
384 if( !prs_uint32( "pointer", ps, depth, &useless_ptr ) )
385 return False;
387 break;
389 default:
390 DEBUG(3, ("invalid enc_type %d for smb_io_notify_info_data\n",
391 data->enc_type));
392 break;
395 return True;
398 /*******************************************************************
399 reads or writes an NOTIFY INFO DATA structure.
400 ********************************************************************/
402 BOOL smb_io_notify_info_data_strings(const char *desc,SPOOL_NOTIFY_INFO_DATA *data,
403 prs_struct *ps, int depth)
405 prs_debug(ps, depth, desc, "smb_io_notify_info_data_strings");
406 depth++;
408 if(!prs_align(ps))
409 return False;
411 switch(data->enc_type) {
413 /* No data for values */
415 case NOTIFY_ONE_VALUE:
416 case NOTIFY_TWO_VALUE:
418 break;
420 /* Strings start with a length in uint16s */
422 case NOTIFY_STRING:
424 if (UNMARSHALLING(ps)) {
425 data->notify_data.data.string =
426 (uint16 *)prs_alloc_mem(ps, data->notify_data.data.length);
428 if (!data->notify_data.data.string)
429 return False;
432 if (MARSHALLING(ps))
433 data->notify_data.data.length /= 2;
435 if(!prs_uint32("string length", ps, depth, &data->notify_data.data.length))
436 return False;
438 if (!prs_uint16uni(True, "string", ps, depth, data->notify_data.data.string,
439 data->notify_data.data.length))
440 return False;
442 if (MARSHALLING(ps))
443 data->notify_data.data.length *= 2;
445 break;
447 case NOTIFY_POINTER:
449 if (UNMARSHALLING(ps)) {
450 data->notify_data.data.string =
451 (uint16 *)prs_alloc_mem(ps, data->notify_data.data.length);
453 if (!data->notify_data.data.string)
454 return False;
457 if(!prs_uint8s(True,"buffer",ps,depth,(uint8*)data->notify_data.data.string,data->notify_data.data.length))
458 return False;
460 break;
462 case NOTIFY_SECDESC:
463 if( !prs_uint32("secdesc size ", ps, depth, &data->notify_data.sd.size ) )
464 return False;
465 if ( !sec_io_desc( "sec_desc", &data->notify_data.sd.desc, ps, depth ) )
466 return False;
467 break;
469 default:
470 DEBUG(3, ("invalid enc_type %d for smb_io_notify_info_data_strings\n",
471 data->enc_type));
472 break;
475 #if 0
476 if (isvalue==False) {
478 /* length of string in unicode include \0 */
479 x=data->notify_data.data.length+1;
481 if (data->field != 16)
482 if(!prs_uint32("string length", ps, depth, &x ))
483 return False;
485 if (MARSHALLING(ps)) {
486 /* These are already in little endian format. Don't byte swap. */
487 if (x == 1) {
489 /* No memory allocated for this string
490 therefore following the data.string
491 pointer is a bad idea. Use a pointer to
492 the uint32 length union member to
493 provide a source for a unicode NULL */
495 if(!prs_uint8s(True,"string",ps,depth, (uint8 *)&data->notify_data.data.length,x*2))
496 return False;
497 } else {
499 if (data->field == 16)
500 x /= 2;
502 if(!prs_uint16uni(True,"string",ps,depth,data->notify_data.data.string,x))
503 return False;
505 } else {
507 /* Tallocate memory for string */
509 data->notify_data.data.string = (uint16 *)prs_alloc_mem(ps, x * 2);
510 if (!data->notify_data.data.string)
511 return False;
513 if(!prs_uint16uni(True,"string",ps,depth,data->notify_data.data.string,x))
514 return False;
518 #endif
520 #if 0 /* JERRY */
521 /* Win2k does not seem to put this parse align here */
522 if(!prs_align(ps))
523 return False;
524 #endif
526 return True;
529 /*******************************************************************
530 reads or writes an NOTIFY INFO structure.
531 ********************************************************************/
533 static BOOL smb_io_notify_info(const char *desc, SPOOL_NOTIFY_INFO *info, prs_struct *ps, int depth)
535 int i;
537 prs_debug(ps, depth, desc, "smb_io_notify_info");
538 depth++;
540 if(!prs_align(ps))
541 return False;
543 if(!prs_uint32("count", ps, depth, &info->count))
544 return False;
545 if(!prs_uint32("version", ps, depth, &info->version))
546 return False;
547 if(!prs_uint32("flags", ps, depth, &info->flags))
548 return False;
549 if(!prs_uint32("count", ps, depth, &info->count))
550 return False;
552 for (i=0;i<info->count;i++) {
553 if(!smb_io_notify_info_data(desc, &info->data[i], ps, depth))
554 return False;
557 /* now do the strings at the end of the stream */
558 for (i=0;i<info->count;i++) {
559 if(!smb_io_notify_info_data_strings(desc, &info->data[i], ps, depth))
560 return False;
563 return True;
566 /*******************************************************************
567 ********************************************************************/
569 static BOOL spool_io_user_level_1(const char *desc, SPOOL_USER_1 *q_u, prs_struct *ps, int depth)
571 prs_debug(ps, depth, desc, "");
572 depth++;
574 /* reading */
575 if (UNMARSHALLING(ps))
576 ZERO_STRUCTP(q_u);
578 if (!prs_align(ps))
579 return False;
580 if (!prs_uint32("size", ps, depth, &q_u->size))
581 return False;
582 if (!prs_uint32("client_name_ptr", ps, depth, &q_u->client_name_ptr))
583 return False;
584 if (!prs_uint32("user_name_ptr", ps, depth, &q_u->user_name_ptr))
585 return False;
586 if (!prs_uint32("build", ps, depth, &q_u->build))
587 return False;
588 if (!prs_uint32("major", ps, depth, &q_u->major))
589 return False;
590 if (!prs_uint32("minor", ps, depth, &q_u->minor))
591 return False;
592 if (!prs_uint32("processor", ps, depth, &q_u->processor))
593 return False;
595 if (!smb_io_unistr2("", &q_u->client_name, q_u->client_name_ptr, ps, depth))
596 return False;
597 if (!prs_align(ps))
598 return False;
599 if (!smb_io_unistr2("", &q_u->user_name, q_u->user_name_ptr, ps, depth))
600 return False;
602 return True;
605 /*******************************************************************
606 ********************************************************************/
608 static BOOL spool_io_user_level(const char *desc, SPOOL_USER_CTR *q_u, prs_struct *ps, int depth)
610 if (q_u==NULL)
611 return False;
613 prs_debug(ps, depth, desc, "spool_io_user_level");
614 depth++;
616 if (!prs_align(ps))
617 return False;
619 /* From looking at many captures in ethereal, it looks like
620 the level and ptr fields should be transposed. -tpot */
622 if (!prs_uint32("level", ps, depth, &q_u->level))
623 return False;
624 if (!prs_uint32("ptr", ps, depth, &q_u->ptr))
625 return False;
627 switch (q_u->level) {
628 case 1:
629 if (!spool_io_user_level_1("", &q_u->user1, ps, depth))
630 return False;
631 break;
632 default:
633 return False;
636 return True;
639 /*******************************************************************
640 * read or write a DEVICEMODE struct.
641 * on reading allocate memory for the private member
642 ********************************************************************/
644 #define DM_NUM_OPTIONAL_FIELDS 8
646 BOOL spoolss_io_devmode(const char *desc, prs_struct *ps, int depth, DEVICEMODE *devmode)
648 int available_space; /* size of the device mode left to parse */
649 /* only important on unmarshalling */
650 int i = 0;
652 struct optional_fields {
653 fstring name;
654 uint32* field;
655 } opt_fields[DM_NUM_OPTIONAL_FIELDS] = {
656 { "icmmethod", NULL },
657 { "icmintent", NULL },
658 { "mediatype", NULL },
659 { "dithertype", NULL },
660 { "reserved1", NULL },
661 { "reserved2", NULL },
662 { "panningwidth", NULL },
663 { "panningheight", NULL }
666 /* assign at run time to keep non-gcc compilers happy */
668 opt_fields[0].field = &devmode->icmmethod;
669 opt_fields[1].field = &devmode->icmintent;
670 opt_fields[2].field = &devmode->mediatype;
671 opt_fields[3].field = &devmode->dithertype;
672 opt_fields[4].field = &devmode->reserved1;
673 opt_fields[5].field = &devmode->reserved2;
674 opt_fields[6].field = &devmode->panningwidth;
675 opt_fields[7].field = &devmode->panningheight;
678 prs_debug(ps, depth, desc, "spoolss_io_devmode");
679 depth++;
681 if (UNMARSHALLING(ps)) {
682 devmode->devicename.buffer = (uint16 *)prs_alloc_mem(ps, 32 * sizeof(uint16) );
683 if (devmode->devicename.buffer == NULL)
684 return False;
687 if (!prs_uint16uni(True,"devicename", ps, depth, devmode->devicename.buffer, MAXDEVICENAME))
688 return False;
690 if (!prs_uint16("specversion", ps, depth, &devmode->specversion))
691 return False;
693 /* Sanity Check - look for unknown specversions, but don't fail if we see one.
694 Let the size determine that */
696 switch (devmode->specversion) {
697 /* list of observed spec version's */
698 case 0x0320:
699 case 0x0400:
700 case 0x0401:
701 case 0x040d:
702 break;
704 default:
705 DEBUG(0,("spoolss_io_devmode: Unknown specversion in devicemode [0x%x]\n",
706 devmode->specversion));
707 DEBUG(0,("spoolss_io_devmode: please report to samba-technical@samba.org!\n"));
708 break;
712 if (!prs_uint16("driverversion", ps, depth, &devmode->driverversion))
713 return False;
714 if (!prs_uint16("size", ps, depth, &devmode->size))
715 return False;
716 if (!prs_uint16("driverextra", ps, depth, &devmode->driverextra))
717 return False;
718 if (!prs_uint32("fields", ps, depth, &devmode->fields))
719 return False;
720 if (!prs_uint16("orientation", ps, depth, &devmode->orientation))
721 return False;
722 if (!prs_uint16("papersize", ps, depth, &devmode->papersize))
723 return False;
724 if (!prs_uint16("paperlength", ps, depth, &devmode->paperlength))
725 return False;
726 if (!prs_uint16("paperwidth", ps, depth, &devmode->paperwidth))
727 return False;
728 if (!prs_uint16("scale", ps, depth, &devmode->scale))
729 return False;
730 if (!prs_uint16("copies", ps, depth, &devmode->copies))
731 return False;
732 if (!prs_uint16("defaultsource", ps, depth, &devmode->defaultsource))
733 return False;
734 if (!prs_uint16("printquality", ps, depth, &devmode->printquality))
735 return False;
736 if (!prs_uint16("color", ps, depth, &devmode->color))
737 return False;
738 if (!prs_uint16("duplex", ps, depth, &devmode->duplex))
739 return False;
740 if (!prs_uint16("yresolution", ps, depth, &devmode->yresolution))
741 return False;
742 if (!prs_uint16("ttoption", ps, depth, &devmode->ttoption))
743 return False;
744 if (!prs_uint16("collate", ps, depth, &devmode->collate))
745 return False;
747 if (UNMARSHALLING(ps)) {
748 devmode->formname.buffer = (uint16 *)prs_alloc_mem(ps, 32 * sizeof(uint16) );
749 if (devmode->formname.buffer == NULL)
750 return False;
753 if (!prs_uint16uni(True, "formname", ps, depth, devmode->formname.buffer, 32))
754 return False;
755 if (!prs_uint16("logpixels", ps, depth, &devmode->logpixels))
756 return False;
757 if (!prs_uint32("bitsperpel", ps, depth, &devmode->bitsperpel))
758 return False;
759 if (!prs_uint32("pelswidth", ps, depth, &devmode->pelswidth))
760 return False;
761 if (!prs_uint32("pelsheight", ps, depth, &devmode->pelsheight))
762 return False;
763 if (!prs_uint32("displayflags", ps, depth, &devmode->displayflags))
764 return False;
765 if (!prs_uint32("displayfrequency", ps, depth, &devmode->displayfrequency))
766 return False;
768 * every device mode I've ever seen on the wire at least has up
769 * to the displayfrequency field. --jerry (05-09-2002)
772 /* add uint32's + uint16's + two UNICODE strings */
774 available_space = devmode->size - (sizeof(uint32)*6 + sizeof(uint16)*18 + sizeof(uint16)*64);
776 /* Sanity check - we only have uint32's left tp parse */
778 if ( available_space && ((available_space % sizeof(uint32)) != 0) ) {
779 DEBUG(0,("spoolss_io_devmode: available_space [%d] no in multiple of 4 bytes (size = %d)!\n",
780 available_space, devmode->size));
781 DEBUG(0,("spoolss_io_devmode: please report to samba-technical@samba.org!\n"));
782 return False;
786 * Conditional parsing. Assume that the DeviceMode has been
787 * zero'd by the caller.
790 while ((available_space > 0) && (i < DM_NUM_OPTIONAL_FIELDS))
792 DEBUG(11, ("spoolss_io_devmode: [%d] bytes left to parse in devmode\n", available_space));
793 if (!prs_uint32(opt_fields[i].name, ps, depth, opt_fields[i].field))
794 return False;
795 available_space -= sizeof(uint32);
796 i++;
799 /* Sanity Check - we should no available space at this point unless
800 MS changes the device mode structure */
802 if (available_space) {
803 DEBUG(0,("spoolss_io_devmode: I've parsed all I know and there is still stuff left|\n"));
804 DEBUG(0,("spoolss_io_devmode: available_space = [%d], devmode_size = [%d]!\n",
805 available_space, devmode->size));
806 DEBUG(0,("spoolss_io_devmode: please report to samba-technical@samba.org!\n"));
807 return False;
811 if (devmode->driverextra!=0) {
812 if (UNMARSHALLING(ps)) {
813 devmode->private=(uint8 *)prs_alloc_mem(ps, devmode->driverextra*sizeof(uint8));
814 if(devmode->private == NULL)
815 return False;
816 DEBUG(7,("spoolss_io_devmode: allocated memory [%d] for private\n",devmode->driverextra));
819 DEBUG(7,("spoolss_io_devmode: parsing [%d] bytes of private\n",devmode->driverextra));
820 if (!prs_uint8s(False, "private", ps, depth,
821 devmode->private, devmode->driverextra))
822 return False;
825 return True;
828 /*******************************************************************
829 Read or write a DEVICEMODE container
830 ********************************************************************/
832 static BOOL spoolss_io_devmode_cont(const char *desc, DEVMODE_CTR *dm_c, prs_struct *ps, int depth)
834 if (dm_c==NULL)
835 return False;
837 prs_debug(ps, depth, desc, "spoolss_io_devmode_cont");
838 depth++;
840 if(!prs_align(ps))
841 return False;
843 if (!prs_uint32("size", ps, depth, &dm_c->size))
844 return False;
846 if (!prs_uint32("devmode_ptr", ps, depth, &dm_c->devmode_ptr))
847 return False;
849 if (dm_c->size==0 || dm_c->devmode_ptr==0) {
850 if (UNMARSHALLING(ps))
851 /* if while reading there is no DEVMODE ... */
852 dm_c->devmode=NULL;
853 return True;
856 /* so we have a DEVICEMODE to follow */
857 if (UNMARSHALLING(ps)) {
858 DEBUG(9,("Allocating memory for spoolss_io_devmode\n"));
859 dm_c->devmode=(DEVICEMODE *)prs_alloc_mem(ps,sizeof(DEVICEMODE));
860 if(dm_c->devmode == NULL)
861 return False;
864 /* this is bad code, shouldn't be there */
865 if (!prs_uint32("size", ps, depth, &dm_c->size))
866 return False;
868 if (!spoolss_io_devmode(desc, ps, depth, dm_c->devmode))
869 return False;
871 return True;
874 /*******************************************************************
875 ********************************************************************/
877 static BOOL spoolss_io_printer_default(const char *desc, PRINTER_DEFAULT *pd, prs_struct *ps, int depth)
879 if (pd==NULL)
880 return False;
882 prs_debug(ps, depth, desc, "spoolss_io_printer_default");
883 depth++;
885 if (!prs_uint32("datatype_ptr", ps, depth, &pd->datatype_ptr))
886 return False;
888 if (!smb_io_unistr2("datatype", &pd->datatype, pd->datatype_ptr, ps,depth))
889 return False;
891 if (!prs_align(ps))
892 return False;
894 if (!spoolss_io_devmode_cont("", &pd->devmode_cont, ps, depth))
895 return False;
897 if (!prs_align(ps))
898 return False;
900 if (!prs_uint32("access_required", ps, depth, &pd->access_required))
901 return False;
903 return True;
906 /*******************************************************************
907 * init a structure.
908 ********************************************************************/
910 BOOL make_spoolss_q_open_printer_ex(SPOOL_Q_OPEN_PRINTER_EX *q_u,
911 const fstring printername,
912 const fstring datatype,
913 uint32 access_required,
914 const fstring clientname,
915 const fstring user_name)
917 DEBUG(5,("make_spoolss_q_open_printer_ex\n"));
918 q_u->printername_ptr = (printername!=NULL)?1:0;
919 init_unistr2(&q_u->printername, printername, UNI_STR_TERMINATE);
921 q_u->printer_default.datatype_ptr = 0;
923 q_u->printer_default.datatype_ptr = (datatype!=NULL)?1:0;
924 init_unistr2(&q_u->printer_default.datatype, datatype, UNI_FLAGS_NONE);
926 q_u->printer_default.devmode_cont.size=0;
927 q_u->printer_default.devmode_cont.devmode_ptr=0;
928 q_u->printer_default.devmode_cont.devmode=NULL;
929 q_u->printer_default.access_required=access_required;
930 q_u->user_switch=1;
931 q_u->user_ctr.level=1;
932 q_u->user_ctr.ptr=1;
933 q_u->user_ctr.user1.size=strlen(clientname)+strlen(user_name)+10;
934 q_u->user_ctr.user1.client_name_ptr = (clientname!=NULL)?1:0;
935 q_u->user_ctr.user1.user_name_ptr = (user_name!=NULL)?1:0;
936 q_u->user_ctr.user1.build=1381;
937 q_u->user_ctr.user1.major=2;
938 q_u->user_ctr.user1.minor=0;
939 q_u->user_ctr.user1.processor=0;
940 init_unistr2(&q_u->user_ctr.user1.client_name, clientname, UNI_STR_TERMINATE);
941 init_unistr2(&q_u->user_ctr.user1.user_name, user_name, UNI_STR_TERMINATE);
943 return True;
946 /*******************************************************************
947 * init a structure.
948 ********************************************************************/
950 BOOL make_spoolss_q_addprinterex(
951 TALLOC_CTX *mem_ctx,
952 SPOOL_Q_ADDPRINTEREX *q_u,
953 const char *srv_name,
954 const char* clientname,
955 const char* user_name,
956 uint32 level,
957 PRINTER_INFO_CTR *ctr)
959 DEBUG(5,("make_spoolss_q_addprinterex\n"));
961 if (!ctr) return False;
963 ZERO_STRUCTP(q_u);
965 q_u->server_name_ptr = (srv_name!=NULL)?1:0;
966 init_unistr2(&q_u->server_name, srv_name, UNI_FLAGS_NONE);
968 q_u->level = level;
970 q_u->info.level = level;
971 q_u->info.info_ptr = (ctr->printers_2!=NULL)?1:0;
972 switch (level) {
973 case 2:
974 /* init q_u->info.info2 from *info */
975 if (!make_spoolss_printer_info_2(mem_ctx, &q_u->info.info_2, ctr->printers_2)) {
976 DEBUG(0,("make_spoolss_q_addprinterex: Unable to fill SPOOL_Q_ADDPRINTEREX struct!\n"));
977 return False;
979 break;
980 default :
981 break;
984 q_u->user_switch=1;
986 q_u->user_ctr.level=1;
987 q_u->user_ctr.ptr=1;
988 q_u->user_ctr.user1.client_name_ptr = (clientname!=NULL)?1:0;
989 q_u->user_ctr.user1.user_name_ptr = (user_name!=NULL)?1:0;
990 q_u->user_ctr.user1.build=1381;
991 q_u->user_ctr.user1.major=2;
992 q_u->user_ctr.user1.minor=0;
993 q_u->user_ctr.user1.processor=0;
994 init_unistr2(&q_u->user_ctr.user1.client_name, clientname, UNI_STR_TERMINATE);
995 init_unistr2(&q_u->user_ctr.user1.user_name, user_name, UNI_STR_TERMINATE);
996 q_u->user_ctr.user1.size=q_u->user_ctr.user1.user_name.uni_str_len +
997 q_u->user_ctr.user1.client_name.uni_str_len + 2;
999 return True;
1002 /*******************************************************************
1003 create a SPOOL_PRINTER_INFO_2 stuct from a PRINTER_INFO_2 struct
1004 *******************************************************************/
1006 BOOL make_spoolss_printer_info_2(TALLOC_CTX *mem_ctx, SPOOL_PRINTER_INFO_LEVEL_2 **spool_info2,
1007 PRINTER_INFO_2 *info)
1010 SPOOL_PRINTER_INFO_LEVEL_2 *inf;
1012 /* allocate the necessary memory */
1013 if (!(inf=(SPOOL_PRINTER_INFO_LEVEL_2*)talloc(mem_ctx, sizeof(SPOOL_PRINTER_INFO_LEVEL_2)))) {
1014 DEBUG(0,("make_spoolss_printer_info_2: Unable to allocate SPOOL_PRINTER_INFO_LEVEL_2 sruct!\n"));
1015 return False;
1018 inf->servername_ptr = (info->servername.buffer!=NULL)?1:0;
1019 inf->printername_ptr = (info->printername.buffer!=NULL)?1:0;
1020 inf->sharename_ptr = (info->sharename.buffer!=NULL)?1:0;
1021 inf->portname_ptr = (info->portname.buffer!=NULL)?1:0;
1022 inf->drivername_ptr = (info->drivername.buffer!=NULL)?1:0;
1023 inf->comment_ptr = (info->comment.buffer!=NULL)?1:0;
1024 inf->location_ptr = (info->location.buffer!=NULL)?1:0;
1025 inf->devmode_ptr = (info->devmode!=NULL)?1:0;
1026 inf->sepfile_ptr = (info->sepfile.buffer!=NULL)?1:0;
1027 inf->printprocessor_ptr = (info->printprocessor.buffer!=NULL)?1:0;
1028 inf->datatype_ptr = (info->datatype.buffer!=NULL)?1:0;
1029 inf->parameters_ptr = (info->parameters.buffer!=NULL)?1:0;
1030 inf->secdesc_ptr = (info->secdesc!=NULL)?1:0;
1031 inf->attributes = info->attributes;
1032 inf->priority = info->priority;
1033 inf->default_priority = info->defaultpriority;
1034 inf->starttime = info->starttime;
1035 inf->untiltime = info->untiltime;
1036 inf->cjobs = info->cjobs;
1037 inf->averageppm = info->averageppm;
1038 init_unistr2_from_unistr(&inf->servername, &info->servername);
1039 init_unistr2_from_unistr(&inf->printername, &info->printername);
1040 init_unistr2_from_unistr(&inf->sharename, &info->sharename);
1041 init_unistr2_from_unistr(&inf->portname, &info->portname);
1042 init_unistr2_from_unistr(&inf->drivername, &info->drivername);
1043 init_unistr2_from_unistr(&inf->comment, &info->comment);
1044 init_unistr2_from_unistr(&inf->location, &info->location);
1045 init_unistr2_from_unistr(&inf->sepfile, &info->sepfile);
1046 init_unistr2_from_unistr(&inf->printprocessor, &info->printprocessor);
1047 init_unistr2_from_unistr(&inf->datatype, &info->datatype);
1048 init_unistr2_from_unistr(&inf->parameters, &info->parameters);
1049 init_unistr2_from_unistr(&inf->datatype, &info->datatype);
1051 *spool_info2 = inf;
1053 return True;
1056 /*******************************************************************
1057 create a SPOOL_PRINTER_INFO_3 struct from a PRINTER_INFO_3 struct
1058 *******************************************************************/
1060 BOOL make_spoolss_printer_info_3(TALLOC_CTX *mem_ctx, SPOOL_PRINTER_INFO_LEVEL_3 **spool_info3,
1061 PRINTER_INFO_3 *info)
1064 SPOOL_PRINTER_INFO_LEVEL_3 *inf;
1066 /* allocate the necessary memory */
1067 if (!(inf=(SPOOL_PRINTER_INFO_LEVEL_3*)talloc(mem_ctx, sizeof(SPOOL_PRINTER_INFO_LEVEL_3)))) {
1068 DEBUG(0,("make_spoolss_printer_info_3: Unable to allocate SPOOL_PRINTER_INFO_LEVEL_3 sruct!\n"));
1069 return False;
1072 inf->secdesc_ptr = (info->secdesc!=NULL)?1:0;
1074 *spool_info3 = inf;
1076 return True;
1079 /*******************************************************************
1080 create a SPOOL_PRINTER_INFO_7 struct from a PRINTER_INFO_7 struct
1081 *******************************************************************/
1083 BOOL make_spoolss_printer_info_7(TALLOC_CTX *mem_ctx, SPOOL_PRINTER_INFO_LEVEL_7 **spool_info7,
1084 PRINTER_INFO_7 *info)
1087 SPOOL_PRINTER_INFO_LEVEL_7 *inf;
1089 /* allocate the necessary memory */
1090 if (!(inf=(SPOOL_PRINTER_INFO_LEVEL_7*)talloc(mem_ctx, sizeof(SPOOL_PRINTER_INFO_LEVEL_7)))) {
1091 DEBUG(0,("make_spoolss_printer_info_7: Unable to allocate SPOOL_PRINTER_INFO_LEVEL_7 struct!\n"));
1092 return False;
1095 inf->guid_ptr = (info->guid.buffer!=NULL)?1:0;
1096 inf->action = info->action;
1097 init_unistr2_from_unistr(&inf->guid, &info->guid);
1099 *spool_info7 = inf;
1101 return True;
1105 /*******************************************************************
1106 * read a structure.
1107 * called from spoolss_q_open_printer_ex (srv_spoolss.c)
1108 ********************************************************************/
1110 BOOL spoolss_io_q_open_printer(const char *desc, SPOOL_Q_OPEN_PRINTER *q_u, prs_struct *ps, int depth)
1112 if (q_u == NULL)
1113 return False;
1115 prs_debug(ps, depth, desc, "spoolss_io_q_open_printer");
1116 depth++;
1118 if (!prs_align(ps))
1119 return False;
1121 if (!prs_uint32("printername_ptr", ps, depth, &q_u->printername_ptr))
1122 return False;
1123 if (!smb_io_unistr2("", &q_u->printername, q_u->printername_ptr, ps,depth))
1124 return False;
1126 if (!prs_align(ps))
1127 return False;
1129 if (!spoolss_io_printer_default("", &q_u->printer_default, ps, depth))
1130 return False;
1132 return True;
1135 /*******************************************************************
1136 * write a structure.
1137 * called from static spoolss_r_open_printer_ex (srv_spoolss.c)
1138 * called from spoolss_open_printer_ex (cli_spoolss.c)
1139 ********************************************************************/
1141 BOOL spoolss_io_r_open_printer(const char *desc, SPOOL_R_OPEN_PRINTER *r_u, prs_struct *ps, int depth)
1143 if (r_u == NULL) return False;
1145 prs_debug(ps, depth, desc, "spoolss_io_r_open_printer");
1146 depth++;
1148 if (!prs_align(ps))
1149 return False;
1151 if (!smb_io_pol_hnd("printer handle",&(r_u->handle),ps,depth))
1152 return False;
1154 if (!prs_werror("status code", ps, depth, &(r_u->status)))
1155 return False;
1157 return True;
1161 /*******************************************************************
1162 * read a structure.
1163 * called from spoolss_q_open_printer_ex (srv_spoolss.c)
1164 ********************************************************************/
1166 BOOL spoolss_io_q_open_printer_ex(const char *desc, SPOOL_Q_OPEN_PRINTER_EX *q_u, prs_struct *ps, int depth)
1168 if (q_u == NULL)
1169 return False;
1171 prs_debug(ps, depth, desc, "spoolss_io_q_open_printer_ex");
1172 depth++;
1174 if (!prs_align(ps))
1175 return False;
1177 if (!prs_uint32("printername_ptr", ps, depth, &q_u->printername_ptr))
1178 return False;
1179 if (!smb_io_unistr2("", &q_u->printername, q_u->printername_ptr, ps,depth))
1180 return False;
1182 if (!prs_align(ps))
1183 return False;
1185 if (!spoolss_io_printer_default("", &q_u->printer_default, ps, depth))
1186 return False;
1188 if (!prs_uint32("user_switch", ps, depth, &q_u->user_switch))
1189 return False;
1190 if (!spool_io_user_level("", &q_u->user_ctr, ps, depth))
1191 return False;
1193 return True;
1196 /*******************************************************************
1197 * write a structure.
1198 * called from static spoolss_r_open_printer_ex (srv_spoolss.c)
1199 * called from spoolss_open_printer_ex (cli_spoolss.c)
1200 ********************************************************************/
1202 BOOL spoolss_io_r_open_printer_ex(const char *desc, SPOOL_R_OPEN_PRINTER_EX *r_u, prs_struct *ps, int depth)
1204 if (r_u == NULL) return False;
1206 prs_debug(ps, depth, desc, "spoolss_io_r_open_printer_ex");
1207 depth++;
1209 if (!prs_align(ps))
1210 return False;
1212 if (!smb_io_pol_hnd("printer handle",&(r_u->handle),ps,depth))
1213 return False;
1215 if (!prs_werror("status code", ps, depth, &(r_u->status)))
1216 return False;
1218 return True;
1221 /*******************************************************************
1222 * init a structure.
1223 ********************************************************************/
1224 BOOL make_spoolss_q_deleteprinterdriverex( TALLOC_CTX *mem_ctx,
1225 SPOOL_Q_DELETEPRINTERDRIVEREX *q_u,
1226 const char *server,
1227 const char* arch,
1228 const char* driver,
1229 uint32 version)
1231 DEBUG(5,("make_spoolss_q_deleteprinterdriverex\n"));
1233 q_u->server_ptr = (server!=NULL)?1:0;
1234 q_u->delete_flags = DPD_DELETE_UNUSED_FILES;
1236 /* these must be NULL terminated or else NT4 will
1237 complain about invalid parameters --jerry */
1238 init_unistr2(&q_u->server, server, UNI_STR_TERMINATE);
1239 init_unistr2(&q_u->arch, arch, UNI_STR_TERMINATE);
1240 init_unistr2(&q_u->driver, driver, UNI_STR_TERMINATE);
1242 if (version >= 0) {
1243 q_u->delete_flags |= DPD_DELETE_SPECIFIC_VERSION;
1244 q_u->version = version;
1247 return True;
1251 /*******************************************************************
1252 * init a structure.
1253 ********************************************************************/
1254 BOOL make_spoolss_q_deleteprinterdriver(
1255 TALLOC_CTX *mem_ctx,
1256 SPOOL_Q_DELETEPRINTERDRIVER *q_u,
1257 const char *server,
1258 const char* arch,
1259 const char* driver
1262 DEBUG(5,("make_spoolss_q_deleteprinterdriver\n"));
1264 q_u->server_ptr = (server!=NULL)?1:0;
1266 /* these must be NULL terminated or else NT4 will
1267 complain about invalid parameters --jerry */
1268 init_unistr2(&q_u->server, server, UNI_STR_TERMINATE);
1269 init_unistr2(&q_u->arch, arch, UNI_STR_TERMINATE);
1270 init_unistr2(&q_u->driver, driver, UNI_STR_TERMINATE);
1272 return True;
1275 /*******************************************************************
1276 * make a structure.
1277 ********************************************************************/
1279 BOOL make_spoolss_q_getprinterdata(SPOOL_Q_GETPRINTERDATA *q_u,
1280 const POLICY_HND *handle,
1281 const char *valuename, uint32 size)
1283 if (q_u == NULL) return False;
1285 DEBUG(5,("make_spoolss_q_getprinterdata\n"));
1287 q_u->handle = *handle;
1288 init_unistr2(&q_u->valuename, valuename, UNI_STR_TERMINATE);
1289 q_u->size = size;
1291 return True;
1294 /*******************************************************************
1295 * make a structure.
1296 ********************************************************************/
1298 BOOL make_spoolss_q_getprinterdataex(SPOOL_Q_GETPRINTERDATAEX *q_u,
1299 const POLICY_HND *handle,
1300 const char *keyname,
1301 const char *valuename, uint32 size)
1303 if (q_u == NULL) return False;
1305 DEBUG(5,("make_spoolss_q_getprinterdataex\n"));
1307 q_u->handle = *handle;
1308 init_unistr2(&q_u->valuename, valuename, UNI_STR_TERMINATE);
1309 init_unistr2(&q_u->keyname, keyname, UNI_STR_TERMINATE);
1310 q_u->size = size;
1312 return True;
1315 /*******************************************************************
1316 * read a structure.
1317 * called from spoolss_q_getprinterdata (srv_spoolss.c)
1318 ********************************************************************/
1320 BOOL spoolss_io_q_getprinterdata(const char *desc, SPOOL_Q_GETPRINTERDATA *q_u, prs_struct *ps, int depth)
1322 if (q_u == NULL)
1323 return False;
1325 prs_debug(ps, depth, desc, "spoolss_io_q_getprinterdata");
1326 depth++;
1328 if (!prs_align(ps))
1329 return False;
1330 if (!smb_io_pol_hnd("printer handle",&q_u->handle,ps,depth))
1331 return False;
1332 if (!prs_align(ps))
1333 return False;
1334 if (!smb_io_unistr2("valuename", &q_u->valuename,True,ps,depth))
1335 return False;
1336 if (!prs_align(ps))
1337 return False;
1338 if (!prs_uint32("size", ps, depth, &q_u->size))
1339 return False;
1341 return True;
1344 /*******************************************************************
1345 * read a structure.
1346 * called from spoolss_q_deleteprinterdata (srv_spoolss.c)
1347 ********************************************************************/
1349 BOOL spoolss_io_q_deleteprinterdata(const char *desc, SPOOL_Q_DELETEPRINTERDATA *q_u, prs_struct *ps, int depth)
1351 if (q_u == NULL)
1352 return False;
1354 prs_debug(ps, depth, desc, "spoolss_io_q_deleteprinterdata");
1355 depth++;
1357 if (!prs_align(ps))
1358 return False;
1359 if (!smb_io_pol_hnd("printer handle",&q_u->handle,ps,depth))
1360 return False;
1361 if (!prs_align(ps))
1362 return False;
1363 if (!smb_io_unistr2("valuename", &q_u->valuename,True,ps,depth))
1364 return False;
1366 return True;
1369 /*******************************************************************
1370 * write a structure.
1371 * called from spoolss_r_deleteprinterdata (srv_spoolss.c)
1372 ********************************************************************/
1374 BOOL spoolss_io_r_deleteprinterdata(const char *desc, SPOOL_R_DELETEPRINTERDATA *r_u, prs_struct *ps, int depth)
1376 prs_debug(ps, depth, desc, "spoolss_io_r_deleteprinterdata");
1377 depth++;
1378 if(!prs_werror("status", ps, depth, &r_u->status))
1379 return False;
1381 return True;
1384 /*******************************************************************
1385 * read a structure.
1386 * called from spoolss_q_deleteprinterdataex (srv_spoolss.c)
1387 ********************************************************************/
1389 BOOL spoolss_io_q_deleteprinterdataex(const char *desc, SPOOL_Q_DELETEPRINTERDATAEX *q_u, prs_struct *ps, int depth)
1391 if (q_u == NULL)
1392 return False;
1394 prs_debug(ps, depth, desc, "spoolss_io_q_deleteprinterdataex");
1395 depth++;
1397 if (!prs_align(ps))
1398 return False;
1399 if (!smb_io_pol_hnd("printer handle", &q_u->handle, ps, depth))
1400 return False;
1402 if (!smb_io_unistr2("keyname ", &q_u->keyname, True, ps, depth))
1403 return False;
1404 if (!smb_io_unistr2("valuename", &q_u->valuename, True, ps, depth))
1405 return False;
1407 return True;
1410 /*******************************************************************
1411 * write a structure.
1412 * called from spoolss_r_deleteprinterdataex (srv_spoolss.c)
1413 ********************************************************************/
1415 BOOL spoolss_io_r_deleteprinterdataex(const char *desc, SPOOL_R_DELETEPRINTERDATAEX *r_u, prs_struct *ps, int depth)
1417 prs_debug(ps, depth, desc, "spoolss_io_r_deleteprinterdataex");
1418 depth++;
1420 if(!prs_werror("status", ps, depth, &r_u->status))
1421 return False;
1423 return True;
1426 /*******************************************************************
1427 * write a structure.
1428 * called from spoolss_r_getprinterdata (srv_spoolss.c)
1429 ********************************************************************/
1431 BOOL spoolss_io_r_getprinterdata(const char *desc, SPOOL_R_GETPRINTERDATA *r_u, prs_struct *ps, int depth)
1433 if (r_u == NULL)
1434 return False;
1436 prs_debug(ps, depth, desc, "spoolss_io_r_getprinterdata");
1437 depth++;
1439 if (!prs_align(ps))
1440 return False;
1441 if (!prs_uint32("type", ps, depth, &r_u->type))
1442 return False;
1443 if (!prs_uint32("size", ps, depth, &r_u->size))
1444 return False;
1446 if (UNMARSHALLING(ps) && r_u->size) {
1447 r_u->data = (unsigned char *)prs_alloc_mem(ps, r_u->size);
1448 if(!r_u->data)
1449 return False;
1452 if (!prs_uint8s( False, "data", ps, depth, r_u->data, r_u->size ))
1453 return False;
1455 if (!prs_align(ps))
1456 return False;
1458 if (!prs_uint32("needed", ps, depth, &r_u->needed))
1459 return False;
1460 if (!prs_werror("status", ps, depth, &r_u->status))
1461 return False;
1463 return True;
1466 /*******************************************************************
1467 * make a structure.
1468 ********************************************************************/
1470 BOOL make_spoolss_q_closeprinter(SPOOL_Q_CLOSEPRINTER *q_u, POLICY_HND *hnd)
1472 if (q_u == NULL) return False;
1474 DEBUG(5,("make_spoolss_q_closeprinter\n"));
1476 memcpy(&q_u->handle, hnd, sizeof(q_u->handle));
1478 return True;
1481 /*******************************************************************
1482 * read a structure.
1483 * called from static spoolss_q_abortprinter (srv_spoolss.c)
1484 * called from spoolss_abortprinter (cli_spoolss.c)
1485 ********************************************************************/
1487 BOOL spoolss_io_q_abortprinter(const char *desc, SPOOL_Q_ABORTPRINTER *q_u, prs_struct *ps, int depth)
1489 if (q_u == NULL) return False;
1491 prs_debug(ps, depth, desc, "spoolss_io_q_abortprinter");
1492 depth++;
1494 if (!prs_align(ps))
1495 return False;
1497 if (!smb_io_pol_hnd("printer handle",&q_u->handle,ps,depth))
1498 return False;
1500 return True;
1503 /*******************************************************************
1504 * write a structure.
1505 * called from spoolss_r_abortprinter (srv_spoolss.c)
1506 ********************************************************************/
1508 BOOL spoolss_io_r_abortprinter(const char *desc, SPOOL_R_ABORTPRINTER *r_u, prs_struct *ps, int depth)
1510 prs_debug(ps, depth, desc, "spoolss_io_r_abortprinter");
1511 depth++;
1512 if(!prs_werror("status", ps, depth, &r_u->status))
1513 return False;
1515 return True;
1518 /*******************************************************************
1519 * read a structure.
1520 * called from static spoolss_q_deleteprinter (srv_spoolss.c)
1521 * called from spoolss_deleteprinter (cli_spoolss.c)
1522 ********************************************************************/
1524 BOOL spoolss_io_q_deleteprinter(const char *desc, SPOOL_Q_DELETEPRINTER *q_u, prs_struct *ps, int depth)
1526 if (q_u == NULL) return False;
1528 prs_debug(ps, depth, desc, "spoolss_io_q_deleteprinter");
1529 depth++;
1531 if (!prs_align(ps))
1532 return False;
1534 if (!smb_io_pol_hnd("printer handle",&q_u->handle,ps,depth))
1535 return False;
1537 return True;
1540 /*******************************************************************
1541 * write a structure.
1542 * called from static spoolss_r_deleteprinter (srv_spoolss.c)
1543 * called from spoolss_deleteprinter (cli_spoolss.c)
1544 ********************************************************************/
1546 BOOL spoolss_io_r_deleteprinter(const char *desc, SPOOL_R_DELETEPRINTER *r_u, prs_struct *ps, int depth)
1548 prs_debug(ps, depth, desc, "spoolss_io_r_deleteprinter");
1549 depth++;
1551 if (!prs_align(ps))
1552 return False;
1554 if (!smb_io_pol_hnd("printer handle",&r_u->handle,ps,depth))
1555 return False;
1556 if (!prs_werror("status", ps, depth, &r_u->status))
1557 return False;
1559 return True;
1563 /*******************************************************************
1564 * read a structure.
1565 * called from api_spoolss_deleteprinterdriver (srv_spoolss.c)
1566 * called from spoolss_deleteprinterdriver (cli_spoolss.c)
1567 ********************************************************************/
1569 BOOL spoolss_io_q_deleteprinterdriver(const char *desc, SPOOL_Q_DELETEPRINTERDRIVER *q_u, prs_struct *ps, int depth)
1571 if (q_u == NULL) return False;
1573 prs_debug(ps, depth, desc, "spoolss_io_q_deleteprinterdriver");
1574 depth++;
1576 if (!prs_align(ps))
1577 return False;
1579 if(!prs_uint32("server_ptr", ps, depth, &q_u->server_ptr))
1580 return False;
1581 if(!smb_io_unistr2("server", &q_u->server, q_u->server_ptr, ps, depth))
1582 return False;
1583 if(!smb_io_unistr2("arch", &q_u->arch, True, ps, depth))
1584 return False;
1585 if(!smb_io_unistr2("driver", &q_u->driver, True, ps, depth))
1586 return False;
1589 return True;
1593 /*******************************************************************
1594 * write a structure.
1595 ********************************************************************/
1596 BOOL spoolss_io_r_deleteprinterdriver(const char *desc, SPOOL_R_DELETEPRINTERDRIVER *r_u, prs_struct *ps, int depth)
1598 if (r_u == NULL) return False;
1600 prs_debug(ps, depth, desc, "spoolss_io_r_deleteprinterdriver");
1601 depth++;
1603 if (!prs_align(ps))
1604 return False;
1606 if (!prs_werror("status", ps, depth, &r_u->status))
1607 return False;
1609 return True;
1613 /*******************************************************************
1614 * read a structure.
1615 * called from api_spoolss_deleteprinterdriver (srv_spoolss.c)
1616 * called from spoolss_deleteprinterdriver (cli_spoolss.c)
1617 ********************************************************************/
1619 BOOL spoolss_io_q_deleteprinterdriverex(const char *desc, SPOOL_Q_DELETEPRINTERDRIVEREX *q_u, prs_struct *ps, int depth)
1621 if (q_u == NULL) return False;
1623 prs_debug(ps, depth, desc, "spoolss_io_q_deleteprinterdriverex");
1624 depth++;
1626 if (!prs_align(ps))
1627 return False;
1629 if(!prs_uint32("server_ptr", ps, depth, &q_u->server_ptr))
1630 return False;
1631 if(!smb_io_unistr2("server", &q_u->server, q_u->server_ptr, ps, depth))
1632 return False;
1633 if(!smb_io_unistr2("arch", &q_u->arch, True, ps, depth))
1634 return False;
1635 if(!smb_io_unistr2("driver", &q_u->driver, True, ps, depth))
1636 return False;
1638 if (!prs_align(ps))
1639 return False;
1641 if(!prs_uint32("delete_flags ", ps, depth, &q_u->delete_flags))
1642 return False;
1643 if(!prs_uint32("version ", ps, depth, &q_u->version))
1644 return False;
1647 return True;
1651 /*******************************************************************
1652 * write a structure.
1653 ********************************************************************/
1654 BOOL spoolss_io_r_deleteprinterdriverex(const char *desc, SPOOL_R_DELETEPRINTERDRIVEREX *r_u, prs_struct *ps, int depth)
1656 if (r_u == NULL) return False;
1658 prs_debug(ps, depth, desc, "spoolss_io_r_deleteprinterdriverex");
1659 depth++;
1661 if (!prs_align(ps))
1662 return False;
1664 if (!prs_werror("status", ps, depth, &r_u->status))
1665 return False;
1667 return True;
1672 /*******************************************************************
1673 * read a structure.
1674 * called from static spoolss_q_closeprinter (srv_spoolss.c)
1675 * called from spoolss_closeprinter (cli_spoolss.c)
1676 ********************************************************************/
1678 BOOL spoolss_io_q_closeprinter(const char *desc, SPOOL_Q_CLOSEPRINTER *q_u, prs_struct *ps, int depth)
1680 if (q_u == NULL) return False;
1682 prs_debug(ps, depth, desc, "spoolss_io_q_closeprinter");
1683 depth++;
1685 if (!prs_align(ps))
1686 return False;
1688 if (!smb_io_pol_hnd("printer handle",&q_u->handle,ps,depth))
1689 return False;
1691 return True;
1694 /*******************************************************************
1695 * write a structure.
1696 * called from static spoolss_r_closeprinter (srv_spoolss.c)
1697 * called from spoolss_closeprinter (cli_spoolss.c)
1698 ********************************************************************/
1700 BOOL spoolss_io_r_closeprinter(const char *desc, SPOOL_R_CLOSEPRINTER *r_u, prs_struct *ps, int depth)
1702 prs_debug(ps, depth, desc, "spoolss_io_r_closeprinter");
1703 depth++;
1705 if (!prs_align(ps))
1706 return False;
1708 if (!smb_io_pol_hnd("printer handle",&r_u->handle,ps,depth))
1709 return False;
1710 if (!prs_werror("status", ps, depth, &r_u->status))
1711 return False;
1713 return True;
1716 /*******************************************************************
1717 * read a structure.
1718 * called from spoolss_q_startdocprinter (srv_spoolss.c)
1719 ********************************************************************/
1721 BOOL spoolss_io_q_startdocprinter(const char *desc, SPOOL_Q_STARTDOCPRINTER *q_u, prs_struct *ps, int depth)
1723 if (q_u == NULL) return False;
1725 prs_debug(ps, depth, desc, "spoolss_io_q_startdocprinter");
1726 depth++;
1728 if(!prs_align(ps))
1729 return False;
1731 if(!smb_io_pol_hnd("printer handle",&q_u->handle,ps,depth))
1732 return False;
1734 if(!smb_io_doc_info_container("",&q_u->doc_info_container, ps, depth))
1735 return False;
1737 return True;
1740 /*******************************************************************
1741 * write a structure.
1742 * called from spoolss_r_startdocprinter (srv_spoolss.c)
1743 ********************************************************************/
1745 BOOL spoolss_io_r_startdocprinter(const char *desc, SPOOL_R_STARTDOCPRINTER *r_u, prs_struct *ps, int depth)
1747 prs_debug(ps, depth, desc, "spoolss_io_r_startdocprinter");
1748 depth++;
1749 if(!prs_uint32("jobid", ps, depth, &r_u->jobid))
1750 return False;
1751 if(!prs_werror("status", ps, depth, &r_u->status))
1752 return False;
1754 return True;
1757 /*******************************************************************
1758 * read a structure.
1759 * called from spoolss_q_enddocprinter (srv_spoolss.c)
1760 ********************************************************************/
1762 BOOL spoolss_io_q_enddocprinter(const char *desc, SPOOL_Q_ENDDOCPRINTER *q_u, prs_struct *ps, int depth)
1764 if (q_u == NULL) return False;
1766 prs_debug(ps, depth, desc, "spoolss_io_q_enddocprinter");
1767 depth++;
1769 if(!prs_align(ps))
1770 return False;
1772 if(!smb_io_pol_hnd("printer handle",&q_u->handle,ps,depth))
1773 return False;
1775 return True;
1778 /*******************************************************************
1779 * write a structure.
1780 * called from spoolss_r_enddocprinter (srv_spoolss.c)
1781 ********************************************************************/
1783 BOOL spoolss_io_r_enddocprinter(const char *desc, SPOOL_R_ENDDOCPRINTER *r_u, prs_struct *ps, int depth)
1785 prs_debug(ps, depth, desc, "spoolss_io_r_enddocprinter");
1786 depth++;
1787 if(!prs_werror("status", ps, depth, &r_u->status))
1788 return False;
1790 return True;
1793 /*******************************************************************
1794 * read a structure.
1795 * called from spoolss_q_startpageprinter (srv_spoolss.c)
1796 ********************************************************************/
1798 BOOL spoolss_io_q_startpageprinter(const char *desc, SPOOL_Q_STARTPAGEPRINTER *q_u, prs_struct *ps, int depth)
1800 if (q_u == NULL) return False;
1802 prs_debug(ps, depth, desc, "spoolss_io_q_startpageprinter");
1803 depth++;
1805 if(!prs_align(ps))
1806 return False;
1808 if(!smb_io_pol_hnd("printer handle",&q_u->handle,ps,depth))
1809 return False;
1811 return True;
1814 /*******************************************************************
1815 * write a structure.
1816 * called from spoolss_r_startpageprinter (srv_spoolss.c)
1817 ********************************************************************/
1819 BOOL spoolss_io_r_startpageprinter(const char *desc, SPOOL_R_STARTPAGEPRINTER *r_u, prs_struct *ps, int depth)
1821 prs_debug(ps, depth, desc, "spoolss_io_r_startpageprinter");
1822 depth++;
1823 if(!prs_werror("status", ps, depth, &r_u->status))
1824 return False;
1826 return True;
1829 /*******************************************************************
1830 * read a structure.
1831 * called from spoolss_q_endpageprinter (srv_spoolss.c)
1832 ********************************************************************/
1834 BOOL spoolss_io_q_endpageprinter(const char *desc, SPOOL_Q_ENDPAGEPRINTER *q_u, prs_struct *ps, int depth)
1836 if (q_u == NULL) return False;
1838 prs_debug(ps, depth, desc, "spoolss_io_q_endpageprinter");
1839 depth++;
1841 if(!prs_align(ps))
1842 return False;
1844 if(!smb_io_pol_hnd("printer handle",&q_u->handle,ps,depth))
1845 return False;
1847 return True;
1850 /*******************************************************************
1851 * write a structure.
1852 * called from spoolss_r_endpageprinter (srv_spoolss.c)
1853 ********************************************************************/
1855 BOOL spoolss_io_r_endpageprinter(const char *desc, SPOOL_R_ENDPAGEPRINTER *r_u, prs_struct *ps, int depth)
1857 prs_debug(ps, depth, desc, "spoolss_io_r_endpageprinter");
1858 depth++;
1859 if(!prs_werror("status", ps, depth, &r_u->status))
1860 return False;
1862 return True;
1865 /*******************************************************************
1866 * read a structure.
1867 * called from spoolss_q_writeprinter (srv_spoolss.c)
1868 ********************************************************************/
1870 BOOL spoolss_io_q_writeprinter(const char *desc, SPOOL_Q_WRITEPRINTER *q_u, prs_struct *ps, int depth)
1872 if (q_u == NULL) return False;
1874 prs_debug(ps, depth, desc, "spoolss_io_q_writeprinter");
1875 depth++;
1877 if(!prs_align(ps))
1878 return False;
1880 if(!smb_io_pol_hnd("printer handle",&q_u->handle,ps,depth))
1881 return False;
1882 if(!prs_uint32("buffer_size", ps, depth, &q_u->buffer_size))
1883 return False;
1885 if (q_u->buffer_size!=0)
1887 if (UNMARSHALLING(ps))
1888 q_u->buffer=(uint8 *)prs_alloc_mem(ps,q_u->buffer_size*sizeof(uint8));
1889 if(q_u->buffer == NULL)
1890 return False;
1891 if(!prs_uint8s(True, "buffer", ps, depth, q_u->buffer, q_u->buffer_size))
1892 return False;
1894 if(!prs_align(ps))
1895 return False;
1896 if(!prs_uint32("buffer_size2", ps, depth, &q_u->buffer_size2))
1897 return False;
1899 return True;
1902 /*******************************************************************
1903 * write a structure.
1904 * called from spoolss_r_writeprinter (srv_spoolss.c)
1905 ********************************************************************/
1907 BOOL spoolss_io_r_writeprinter(const char *desc, SPOOL_R_WRITEPRINTER *r_u, prs_struct *ps, int depth)
1909 prs_debug(ps, depth, desc, "spoolss_io_r_writeprinter");
1910 depth++;
1911 if(!prs_uint32("buffer_written", ps, depth, &r_u->buffer_written))
1912 return False;
1913 if(!prs_werror("status", ps, depth, &r_u->status))
1914 return False;
1916 return True;
1919 /*******************************************************************
1920 * read a structure.
1921 * called from spoolss_q_rffpcnex (srv_spoolss.c)
1922 ********************************************************************/
1924 BOOL spoolss_io_q_rffpcnex(const char *desc, SPOOL_Q_RFFPCNEX *q_u, prs_struct *ps, int depth)
1926 prs_debug(ps, depth, desc, "spoolss_io_q_rffpcnex");
1927 depth++;
1929 if(!prs_align(ps))
1930 return False;
1932 if(!smb_io_pol_hnd("printer handle", &q_u->handle, ps, depth))
1933 return False;
1934 if(!prs_uint32("flags", ps, depth, &q_u->flags))
1935 return False;
1936 if(!prs_uint32("options", ps, depth, &q_u->options))
1937 return False;
1938 if(!prs_uint32("localmachine_ptr", ps, depth, &q_u->localmachine_ptr))
1939 return False;
1940 if(!smb_io_unistr2("localmachine", &q_u->localmachine, q_u->localmachine_ptr, ps, depth))
1941 return False;
1943 if(!prs_align(ps))
1944 return False;
1946 if(!prs_uint32("printerlocal", ps, depth, &q_u->printerlocal))
1947 return False;
1949 if(!prs_uint32("option_ptr", ps, depth, &q_u->option_ptr))
1950 return False;
1952 if (q_u->option_ptr!=0) {
1954 if (UNMARSHALLING(ps))
1955 if((q_u->option=(SPOOL_NOTIFY_OPTION *)prs_alloc_mem(ps,sizeof(SPOOL_NOTIFY_OPTION))) == NULL)
1956 return False;
1958 if(!smb_io_notify_option("notify option", q_u->option, ps, depth))
1959 return False;
1962 return True;
1965 /*******************************************************************
1966 * write a structure.
1967 * called from spoolss_r_rffpcnex (srv_spoolss.c)
1968 ********************************************************************/
1970 BOOL spoolss_io_r_rffpcnex(const char *desc, SPOOL_R_RFFPCNEX *r_u, prs_struct *ps, int depth)
1972 prs_debug(ps, depth, desc, "spoolss_io_r_rffpcnex");
1973 depth++;
1975 if(!prs_werror("status", ps, depth, &r_u->status))
1976 return False;
1978 return True;
1981 /*******************************************************************
1982 * read a structure.
1983 * called from spoolss_q_rfnpcnex (srv_spoolss.c)
1984 ********************************************************************/
1986 BOOL spoolss_io_q_rfnpcnex(const char *desc, SPOOL_Q_RFNPCNEX *q_u, prs_struct *ps, int depth)
1988 prs_debug(ps, depth, desc, "spoolss_io_q_rfnpcnex");
1989 depth++;
1991 if(!prs_align(ps))
1992 return False;
1994 if(!smb_io_pol_hnd("printer handle",&q_u->handle,ps,depth))
1995 return False;
1997 if(!prs_uint32("change", ps, depth, &q_u->change))
1998 return False;
2000 if(!prs_uint32("option_ptr", ps, depth, &q_u->option_ptr))
2001 return False;
2003 if (q_u->option_ptr!=0) {
2005 if (UNMARSHALLING(ps))
2006 if((q_u->option=(SPOOL_NOTIFY_OPTION *)prs_alloc_mem(ps,sizeof(SPOOL_NOTIFY_OPTION))) == NULL)
2007 return False;
2009 if(!smb_io_notify_option("notify option", q_u->option, ps, depth))
2010 return False;
2013 return True;
2016 /*******************************************************************
2017 * write a structure.
2018 * called from spoolss_r_rfnpcnex (srv_spoolss.c)
2019 ********************************************************************/
2021 BOOL spoolss_io_r_rfnpcnex(const char *desc, SPOOL_R_RFNPCNEX *r_u, prs_struct *ps, int depth)
2023 prs_debug(ps, depth, desc, "spoolss_io_r_rfnpcnex");
2024 depth++;
2026 if(!prs_align(ps))
2027 return False;
2029 if (!prs_uint32("info_ptr", ps, depth, &r_u->info_ptr))
2030 return False;
2032 if(!smb_io_notify_info("notify info", &r_u->info ,ps,depth))
2033 return False;
2035 if(!prs_align(ps))
2036 return False;
2037 if(!prs_werror("status", ps, depth, &r_u->status))
2038 return False;
2040 return True;
2043 /*******************************************************************
2044 * return the length of a uint16 (obvious, but the code is clean)
2045 ********************************************************************/
2047 static uint32 size_of_uint16(uint16 *value)
2049 return (sizeof(*value));
2052 /*******************************************************************
2053 * return the length of a uint32 (obvious, but the code is clean)
2054 ********************************************************************/
2056 static uint32 size_of_uint32(uint32 *value)
2058 return (sizeof(*value));
2061 /*******************************************************************
2062 * return the length of a NTTIME (obvious, but the code is clean)
2063 ********************************************************************/
2065 static uint32 size_of_nttime(NTTIME *value)
2067 return (sizeof(*value));
2070 /*******************************************************************
2071 * return the length of a UNICODE string in number of char, includes:
2072 * - the leading zero
2073 * - the relative pointer size
2074 ********************************************************************/
2076 static uint32 size_of_relative_string(UNISTR *string)
2078 uint32 size=0;
2080 size=str_len_uni(string); /* the string length */
2081 size=size+1; /* add the trailing zero */
2082 size=size*2; /* convert in char */
2083 size=size+4; /* add the size of the ptr */
2085 #if 0 /* JERRY */
2087 * Do not include alignment as Win2k does not align relative
2088 * strings within a buffer --jerry
2090 /* Ensure size is 4 byte multiple (prs_align is being called...). */
2091 /* size += ((4 - (size & 3)) & 3); */
2092 #endif
2094 return size;
2097 /*******************************************************************
2098 * return the length of a uint32 (obvious, but the code is clean)
2099 ********************************************************************/
2101 static uint32 size_of_device_mode(DEVICEMODE *devmode)
2103 if (devmode==NULL)
2104 return (4);
2105 else
2106 return (4+devmode->size+devmode->driverextra);
2109 /*******************************************************************
2110 * return the length of a uint32 (obvious, but the code is clean)
2111 ********************************************************************/
2113 static uint32 size_of_systemtime(SYSTEMTIME *systime)
2115 if (systime==NULL)
2116 return (4);
2117 else
2118 return (sizeof(SYSTEMTIME) +4);
2121 /*******************************************************************
2122 * write a UNICODE string and its relative pointer.
2123 * used by all the RPC structs passing a buffer
2125 * As I'm a nice guy, I'm forcing myself to explain this code.
2126 * MS did a good job in the overall spoolss code except in some
2127 * functions where they are passing the API buffer directly in the
2128 * RPC request/reply. That's to maintain compatiility at the API level.
2129 * They could have done it the good way the first time.
2131 * So what happen is: the strings are written at the buffer's end,
2132 * in the reverse order of the original structure. Some pointers to
2133 * the strings are also in the buffer. Those are relative to the
2134 * buffer's start.
2136 * If you don't understand or want to change that function,
2137 * first get in touch with me: jfm@samba.org
2139 ********************************************************************/
2141 static BOOL smb_io_relstr(const char *desc, NEW_BUFFER *buffer, int depth, UNISTR *string)
2143 prs_struct *ps=&buffer->prs;
2145 if (MARSHALLING(ps)) {
2146 uint32 struct_offset = prs_offset(ps);
2147 uint32 relative_offset;
2149 buffer->string_at_end -= (size_of_relative_string(string) - 4);
2150 if(!prs_set_offset(ps, buffer->string_at_end))
2151 return False;
2152 #if 0 /* JERRY */
2154 * Win2k does not align strings in a buffer
2155 * Tested against WinNT 4.0 SP 6a & 2k SP2 --jerry
2157 if (!prs_align(ps))
2158 return False;
2159 #endif
2160 buffer->string_at_end = prs_offset(ps);
2162 /* write the string */
2163 if (!smb_io_unistr(desc, string, ps, depth))
2164 return False;
2166 if(!prs_set_offset(ps, struct_offset))
2167 return False;
2169 relative_offset=buffer->string_at_end - buffer->struct_start;
2170 /* write its offset */
2171 if (!prs_uint32("offset", ps, depth, &relative_offset))
2172 return False;
2174 else {
2175 uint32 old_offset;
2177 /* read the offset */
2178 if (!prs_uint32("offset", ps, depth, &(buffer->string_at_end)))
2179 return False;
2181 if (buffer->string_at_end == 0)
2182 return True;
2184 old_offset = prs_offset(ps);
2185 if(!prs_set_offset(ps, buffer->string_at_end+buffer->struct_start))
2186 return False;
2188 /* read the string */
2189 if (!smb_io_unistr(desc, string, ps, depth))
2190 return False;
2192 if(!prs_set_offset(ps, old_offset))
2193 return False;
2195 return True;
2198 /*******************************************************************
2199 * write a array of UNICODE strings and its relative pointer.
2200 * used by 2 RPC structs
2201 ********************************************************************/
2203 static BOOL smb_io_relarraystr(const char *desc, NEW_BUFFER *buffer, int depth, uint16 **string)
2205 UNISTR chaine;
2207 prs_struct *ps=&buffer->prs;
2209 if (MARSHALLING(ps)) {
2210 uint32 struct_offset = prs_offset(ps);
2211 uint32 relative_offset;
2212 uint16 *p;
2213 uint16 *q;
2214 uint16 zero=0;
2215 p=*string;
2216 q=*string;
2218 /* first write the last 0 */
2219 buffer->string_at_end -= 2;
2220 if(!prs_set_offset(ps, buffer->string_at_end))
2221 return False;
2223 if(!prs_uint16("leading zero", ps, depth, &zero))
2224 return False;
2226 while (p && (*p!=0)) {
2227 while (*q!=0)
2228 q++;
2230 /* Yes this should be malloc not talloc. Don't change. */
2232 chaine.buffer = malloc((q-p+1)*sizeof(uint16));
2233 if (chaine.buffer == NULL)
2234 return False;
2236 memcpy(chaine.buffer, p, (q-p+1)*sizeof(uint16));
2238 buffer->string_at_end -= (q-p+1)*sizeof(uint16);
2240 if(!prs_set_offset(ps, buffer->string_at_end)) {
2241 SAFE_FREE(chaine.buffer);
2242 return False;
2245 /* write the string */
2246 if (!smb_io_unistr(desc, &chaine, ps, depth)) {
2247 SAFE_FREE(chaine.buffer);
2248 return False;
2250 q++;
2251 p=q;
2253 SAFE_FREE(chaine.buffer);
2256 if(!prs_set_offset(ps, struct_offset))
2257 return False;
2259 relative_offset=buffer->string_at_end - buffer->struct_start;
2260 /* write its offset */
2261 if (!prs_uint32("offset", ps, depth, &relative_offset))
2262 return False;
2264 } else {
2266 /* UNMARSHALLING */
2268 uint32 old_offset;
2269 uint16 *chaine2=NULL;
2270 int l_chaine=0;
2271 int l_chaine2=0;
2272 size_t realloc_size = 0;
2274 *string=NULL;
2276 /* read the offset */
2277 if (!prs_uint32("offset", ps, depth, &buffer->string_at_end))
2278 return False;
2280 old_offset = prs_offset(ps);
2281 if(!prs_set_offset(ps, buffer->string_at_end + buffer->struct_start))
2282 return False;
2284 do {
2285 if (!smb_io_unistr(desc, &chaine, ps, depth))
2286 return False;
2288 l_chaine=str_len_uni(&chaine);
2290 /* we're going to add two more bytes here in case this
2291 is the last string in the array and we need to add
2292 an extra NULL for termination */
2293 if (l_chaine > 0)
2295 uint16 *tc2;
2297 realloc_size = (l_chaine2+l_chaine+2)*sizeof(uint16);
2299 /* Yes this should be realloc - it's freed below. JRA */
2301 if((tc2=(uint16 *)Realloc(chaine2, realloc_size)) == NULL) {
2302 SAFE_FREE(chaine2);
2303 return False;
2305 else chaine2 = tc2;
2306 memcpy(chaine2+l_chaine2, chaine.buffer, (l_chaine+1)*sizeof(uint16));
2307 l_chaine2+=l_chaine+1;
2310 } while(l_chaine!=0);
2312 /* the end should be bould NULL terminated so add
2313 the second one here */
2314 if (chaine2)
2316 chaine2[l_chaine2] = '\0';
2317 *string=(uint16 *)talloc_memdup(prs_get_mem_context(ps),chaine2,realloc_size);
2318 SAFE_FREE(chaine2);
2321 if(!prs_set_offset(ps, old_offset))
2322 return False;
2324 return True;
2327 /*******************************************************************
2328 Parse a DEVMODE structure and its relative pointer.
2329 ********************************************************************/
2331 static BOOL smb_io_relsecdesc(const char *desc, NEW_BUFFER *buffer, int depth, SEC_DESC **secdesc)
2333 prs_struct *ps= &buffer->prs;
2335 prs_debug(ps, depth, desc, "smb_io_relsecdesc");
2336 depth++;
2338 if (MARSHALLING(ps)) {
2339 uint32 struct_offset = prs_offset(ps);
2340 uint32 relative_offset;
2342 if (! *secdesc) {
2343 relative_offset = 0;
2344 if (!prs_uint32("offset", ps, depth, &relative_offset))
2345 return False;
2346 return True;
2349 if (*secdesc != NULL) {
2350 buffer->string_at_end -= sec_desc_size(*secdesc);
2352 if(!prs_set_offset(ps, buffer->string_at_end))
2353 return False;
2354 /* write the secdesc */
2355 if (!sec_io_desc(desc, secdesc, ps, depth))
2356 return False;
2358 if(!prs_set_offset(ps, struct_offset))
2359 return False;
2362 relative_offset=buffer->string_at_end - buffer->struct_start;
2363 /* write its offset */
2365 if (!prs_uint32("offset", ps, depth, &relative_offset))
2366 return False;
2367 } else {
2368 uint32 old_offset;
2370 /* read the offset */
2371 if (!prs_uint32("offset", ps, depth, &buffer->string_at_end))
2372 return False;
2374 old_offset = prs_offset(ps);
2375 if(!prs_set_offset(ps, buffer->string_at_end + buffer->struct_start))
2376 return False;
2378 /* read the sd */
2379 if (!sec_io_desc(desc, secdesc, ps, depth))
2380 return False;
2382 if(!prs_set_offset(ps, old_offset))
2383 return False;
2385 return True;
2388 /*******************************************************************
2389 Parse a DEVMODE structure and its relative pointer.
2390 ********************************************************************/
2392 static BOOL smb_io_reldevmode(const char *desc, NEW_BUFFER *buffer, int depth, DEVICEMODE **devmode)
2394 prs_struct *ps=&buffer->prs;
2396 prs_debug(ps, depth, desc, "smb_io_reldevmode");
2397 depth++;
2399 if (MARSHALLING(ps)) {
2400 uint32 struct_offset = prs_offset(ps);
2401 uint32 relative_offset;
2403 if (*devmode == NULL) {
2404 relative_offset=0;
2405 if (!prs_uint32("offset", ps, depth, &relative_offset))
2406 return False;
2407 DEBUG(8, ("boing, the devmode was NULL\n"));
2409 return True;
2412 buffer->string_at_end -= ((*devmode)->size + (*devmode)->driverextra);
2414 if(!prs_set_offset(ps, buffer->string_at_end))
2415 return False;
2417 /* write the DEVMODE */
2418 if (!spoolss_io_devmode(desc, ps, depth, *devmode))
2419 return False;
2421 if(!prs_set_offset(ps, struct_offset))
2422 return False;
2424 relative_offset=buffer->string_at_end - buffer->struct_start;
2425 /* write its offset */
2426 if (!prs_uint32("offset", ps, depth, &relative_offset))
2427 return False;
2429 else {
2430 uint32 old_offset;
2432 /* read the offset */
2433 if (!prs_uint32("offset", ps, depth, &buffer->string_at_end))
2434 return False;
2435 if (buffer->string_at_end == 0) {
2436 *devmode = NULL;
2437 return True;
2440 old_offset = prs_offset(ps);
2441 if(!prs_set_offset(ps, buffer->string_at_end + buffer->struct_start))
2442 return False;
2444 /* read the string */
2445 if((*devmode=(DEVICEMODE *)prs_alloc_mem(ps,sizeof(DEVICEMODE))) == NULL)
2446 return False;
2447 if (!spoolss_io_devmode(desc, ps, depth, *devmode))
2448 return False;
2450 if(!prs_set_offset(ps, old_offset))
2451 return False;
2453 return True;
2456 /*******************************************************************
2457 Parse a PRINTER_INFO_0 structure.
2458 ********************************************************************/
2460 BOOL smb_io_printer_info_0(const char *desc, NEW_BUFFER *buffer, PRINTER_INFO_0 *info, int depth)
2462 prs_struct *ps=&buffer->prs;
2464 prs_debug(ps, depth, desc, "smb_io_printer_info_0");
2465 depth++;
2467 buffer->struct_start=prs_offset(ps);
2469 if (!smb_io_relstr("printername", buffer, depth, &info->printername))
2470 return False;
2471 if (!smb_io_relstr("servername", buffer, depth, &info->servername))
2472 return False;
2474 if(!prs_uint32("cjobs", ps, depth, &info->cjobs))
2475 return False;
2476 if(!prs_uint32("total_jobs", ps, depth, &info->total_jobs))
2477 return False;
2478 if(!prs_uint32("total_bytes", ps, depth, &info->total_bytes))
2479 return False;
2481 if(!prs_uint16("year", ps, depth, &info->year))
2482 return False;
2483 if(!prs_uint16("month", ps, depth, &info->month))
2484 return False;
2485 if(!prs_uint16("dayofweek", ps, depth, &info->dayofweek))
2486 return False;
2487 if(!prs_uint16("day", ps, depth, &info->day))
2488 return False;
2489 if(!prs_uint16("hour", ps, depth, &info->hour))
2490 return False;
2491 if(!prs_uint16("minute", ps, depth, &info->minute))
2492 return False;
2493 if(!prs_uint16("second", ps, depth, &info->second))
2494 return False;
2495 if(!prs_uint16("milliseconds", ps, depth, &info->milliseconds))
2496 return False;
2498 if(!prs_uint32("global_counter", ps, depth, &info->global_counter))
2499 return False;
2500 if(!prs_uint32("total_pages", ps, depth, &info->total_pages))
2501 return False;
2503 if(!prs_uint16("major_version", ps, depth, &info->major_version))
2504 return False;
2505 if(!prs_uint16("build_version", ps, depth, &info->build_version))
2506 return False;
2507 if(!prs_uint32("unknown7", ps, depth, &info->unknown7))
2508 return False;
2509 if(!prs_uint32("unknown8", ps, depth, &info->unknown8))
2510 return False;
2511 if(!prs_uint32("unknown9", ps, depth, &info->unknown9))
2512 return False;
2513 if(!prs_uint32("session_counter", ps, depth, &info->session_counter))
2514 return False;
2515 if(!prs_uint32("unknown11", ps, depth, &info->unknown11))
2516 return False;
2517 if(!prs_uint32("printer_errors", ps, depth, &info->printer_errors))
2518 return False;
2519 if(!prs_uint32("unknown13", ps, depth, &info->unknown13))
2520 return False;
2521 if(!prs_uint32("unknown14", ps, depth, &info->unknown14))
2522 return False;
2523 if(!prs_uint32("unknown15", ps, depth, &info->unknown15))
2524 return False;
2525 if(!prs_uint32("unknown16", ps, depth, &info->unknown16))
2526 return False;
2527 if(!prs_uint32("change_id", ps, depth, &info->change_id))
2528 return False;
2529 if(!prs_uint32("unknown18", ps, depth, &info->unknown18))
2530 return False;
2531 if(!prs_uint32("status" , ps, depth, &info->status))
2532 return False;
2533 if(!prs_uint32("unknown20", ps, depth, &info->unknown20))
2534 return False;
2535 if(!prs_uint32("c_setprinter", ps, depth, &info->c_setprinter))
2536 return False;
2537 if(!prs_uint16("unknown22", ps, depth, &info->unknown22))
2538 return False;
2539 if(!prs_uint16("unknown23", ps, depth, &info->unknown23))
2540 return False;
2541 if(!prs_uint16("unknown24", ps, depth, &info->unknown24))
2542 return False;
2543 if(!prs_uint16("unknown25", ps, depth, &info->unknown25))
2544 return False;
2545 if(!prs_uint16("unknown26", ps, depth, &info->unknown26))
2546 return False;
2547 if(!prs_uint16("unknown27", ps, depth, &info->unknown27))
2548 return False;
2549 if(!prs_uint16("unknown28", ps, depth, &info->unknown28))
2550 return False;
2551 if(!prs_uint16("unknown29", ps, depth, &info->unknown29))
2552 return False;
2554 return True;
2557 /*******************************************************************
2558 Parse a PRINTER_INFO_1 structure.
2559 ********************************************************************/
2561 BOOL smb_io_printer_info_1(const char *desc, NEW_BUFFER *buffer, PRINTER_INFO_1 *info, int depth)
2563 prs_struct *ps=&buffer->prs;
2565 prs_debug(ps, depth, desc, "smb_io_printer_info_1");
2566 depth++;
2568 buffer->struct_start=prs_offset(ps);
2570 if (!prs_uint32("flags", ps, depth, &info->flags))
2571 return False;
2572 if (!smb_io_relstr("description", buffer, depth, &info->description))
2573 return False;
2574 if (!smb_io_relstr("name", buffer, depth, &info->name))
2575 return False;
2576 if (!smb_io_relstr("comment", buffer, depth, &info->comment))
2577 return False;
2579 return True;
2582 /*******************************************************************
2583 Parse a PRINTER_INFO_2 structure.
2584 ********************************************************************/
2586 BOOL smb_io_printer_info_2(const char *desc, NEW_BUFFER *buffer, PRINTER_INFO_2 *info, int depth)
2588 prs_struct *ps=&buffer->prs;
2589 uint32 dm_offset, sd_offset, current_offset;
2590 uint32 dummy_value = 0, has_secdesc = 0;
2592 prs_debug(ps, depth, desc, "smb_io_printer_info_2");
2593 depth++;
2595 buffer->struct_start=prs_offset(ps);
2597 if (!smb_io_relstr("servername", buffer, depth, &info->servername))
2598 return False;
2599 if (!smb_io_relstr("printername", buffer, depth, &info->printername))
2600 return False;
2601 if (!smb_io_relstr("sharename", buffer, depth, &info->sharename))
2602 return False;
2603 if (!smb_io_relstr("portname", buffer, depth, &info->portname))
2604 return False;
2605 if (!smb_io_relstr("drivername", buffer, depth, &info->drivername))
2606 return False;
2607 if (!smb_io_relstr("comment", buffer, depth, &info->comment))
2608 return False;
2609 if (!smb_io_relstr("location", buffer, depth, &info->location))
2610 return False;
2612 /* save current offset and wind forwared by a uint32 */
2613 dm_offset = prs_offset(ps);
2614 if (!prs_uint32("devmode", ps, depth, &dummy_value))
2615 return False;
2617 if (!smb_io_relstr("sepfile", buffer, depth, &info->sepfile))
2618 return False;
2619 if (!smb_io_relstr("printprocessor", buffer, depth, &info->printprocessor))
2620 return False;
2621 if (!smb_io_relstr("datatype", buffer, depth, &info->datatype))
2622 return False;
2623 if (!smb_io_relstr("parameters", buffer, depth, &info->parameters))
2624 return False;
2626 /* save current offset for the sec_desc */
2627 sd_offset = prs_offset(ps);
2628 if (!prs_uint32("sec_desc", ps, depth, &has_secdesc))
2629 return False;
2632 /* save current location so we can pick back up here */
2633 current_offset = prs_offset(ps);
2635 /* parse the devmode */
2636 if (!prs_set_offset(ps, dm_offset))
2637 return False;
2638 if (!smb_io_reldevmode("devmode", buffer, depth, &info->devmode))
2639 return False;
2641 /* parse the sec_desc */
2642 if (info->secdesc) {
2643 if (!prs_set_offset(ps, sd_offset))
2644 return False;
2645 if (!smb_io_relsecdesc("secdesc", buffer, depth, &info->secdesc))
2646 return False;
2649 /* pick up where we left off */
2650 if (!prs_set_offset(ps, current_offset))
2651 return False;
2653 if (!prs_uint32("attributes", ps, depth, &info->attributes))
2654 return False;
2655 if (!prs_uint32("priority", ps, depth, &info->priority))
2656 return False;
2657 if (!prs_uint32("defpriority", ps, depth, &info->defaultpriority))
2658 return False;
2659 if (!prs_uint32("starttime", ps, depth, &info->starttime))
2660 return False;
2661 if (!prs_uint32("untiltime", ps, depth, &info->untiltime))
2662 return False;
2663 if (!prs_uint32("status", ps, depth, &info->status))
2664 return False;
2665 if (!prs_uint32("jobs", ps, depth, &info->cjobs))
2666 return False;
2667 if (!prs_uint32("averageppm", ps, depth, &info->averageppm))
2668 return False;
2670 return True;
2673 /*******************************************************************
2674 Parse a PRINTER_INFO_3 structure.
2675 ********************************************************************/
2677 BOOL smb_io_printer_info_3(const char *desc, NEW_BUFFER *buffer, PRINTER_INFO_3 *info, int depth)
2679 prs_struct *ps=&buffer->prs;
2681 prs_debug(ps, depth, desc, "smb_io_printer_info_3");
2682 depth++;
2684 buffer->struct_start=prs_offset(ps);
2686 if (!prs_uint32("flags", ps, depth, &info->flags))
2687 return False;
2688 if (!sec_io_desc("sec_desc", &info->secdesc, ps, depth))
2689 return False;
2691 return True;
2694 /*******************************************************************
2695 Parse a PRINTER_INFO_4 structure.
2696 ********************************************************************/
2698 BOOL smb_io_printer_info_4(const char *desc, NEW_BUFFER *buffer, PRINTER_INFO_4 *info, int depth)
2700 prs_struct *ps=&buffer->prs;
2702 prs_debug(ps, depth, desc, "smb_io_printer_info_4");
2703 depth++;
2705 buffer->struct_start=prs_offset(ps);
2707 if (!smb_io_relstr("printername", buffer, depth, &info->printername))
2708 return False;
2709 if (!smb_io_relstr("servername", buffer, depth, &info->servername))
2710 return False;
2711 if (!prs_uint32("attributes", ps, depth, &info->attributes))
2712 return False;
2713 return True;
2716 /*******************************************************************
2717 Parse a PRINTER_INFO_5 structure.
2718 ********************************************************************/
2720 BOOL smb_io_printer_info_5(const char *desc, NEW_BUFFER *buffer, PRINTER_INFO_5 *info, int depth)
2722 prs_struct *ps=&buffer->prs;
2724 prs_debug(ps, depth, desc, "smb_io_printer_info_5");
2725 depth++;
2727 buffer->struct_start=prs_offset(ps);
2729 if (!smb_io_relstr("printername", buffer, depth, &info->printername))
2730 return False;
2731 if (!smb_io_relstr("portname", buffer, depth, &info->portname))
2732 return False;
2733 if (!prs_uint32("attributes", ps, depth, &info->attributes))
2734 return False;
2735 if (!prs_uint32("device_not_selected_timeout", ps, depth, &info->device_not_selected_timeout))
2736 return False;
2737 if (!prs_uint32("transmission_retry_timeout", ps, depth, &info->transmission_retry_timeout))
2738 return False;
2739 return True;
2742 /*******************************************************************
2743 Parse a PRINTER_INFO_7 structure.
2744 ********************************************************************/
2746 BOOL smb_io_printer_info_7(const char *desc, NEW_BUFFER *buffer, PRINTER_INFO_7 *info, int depth)
2748 prs_struct *ps=&buffer->prs;
2750 prs_debug(ps, depth, desc, "smb_io_printer_info_7");
2751 depth++;
2753 buffer->struct_start=prs_offset(ps);
2755 if (!smb_io_relstr("guid", buffer, depth, &info->guid))
2756 return False;
2757 if (!prs_uint32("action", ps, depth, &info->action))
2758 return False;
2759 return True;
2762 /*******************************************************************
2763 Parse a PORT_INFO_1 structure.
2764 ********************************************************************/
2766 BOOL smb_io_port_info_1(const char *desc, NEW_BUFFER *buffer, PORT_INFO_1 *info, int depth)
2768 prs_struct *ps=&buffer->prs;
2770 prs_debug(ps, depth, desc, "smb_io_port_info_1");
2771 depth++;
2773 buffer->struct_start=prs_offset(ps);
2775 if (!smb_io_relstr("port_name", buffer, depth, &info->port_name))
2776 return False;
2778 return True;
2781 /*******************************************************************
2782 Parse a PORT_INFO_2 structure.
2783 ********************************************************************/
2785 BOOL smb_io_port_info_2(const char *desc, NEW_BUFFER *buffer, PORT_INFO_2 *info, int depth)
2787 prs_struct *ps=&buffer->prs;
2789 prs_debug(ps, depth, desc, "smb_io_port_info_2");
2790 depth++;
2792 buffer->struct_start=prs_offset(ps);
2794 if (!smb_io_relstr("port_name", buffer, depth, &info->port_name))
2795 return False;
2796 if (!smb_io_relstr("monitor_name", buffer, depth, &info->monitor_name))
2797 return False;
2798 if (!smb_io_relstr("description", buffer, depth, &info->description))
2799 return False;
2800 if (!prs_uint32("port_type", ps, depth, &info->port_type))
2801 return False;
2802 if (!prs_uint32("reserved", ps, depth, &info->reserved))
2803 return False;
2805 return True;
2808 /*******************************************************************
2809 Parse a DRIVER_INFO_1 structure.
2810 ********************************************************************/
2812 BOOL smb_io_printer_driver_info_1(const char *desc, NEW_BUFFER *buffer, DRIVER_INFO_1 *info, int depth)
2814 prs_struct *ps=&buffer->prs;
2816 prs_debug(ps, depth, desc, "smb_io_printer_driver_info_1");
2817 depth++;
2819 buffer->struct_start=prs_offset(ps);
2821 if (!smb_io_relstr("name", buffer, depth, &info->name))
2822 return False;
2824 return True;
2827 /*******************************************************************
2828 Parse a DRIVER_INFO_2 structure.
2829 ********************************************************************/
2831 BOOL smb_io_printer_driver_info_2(const char *desc, NEW_BUFFER *buffer, DRIVER_INFO_2 *info, int depth)
2833 prs_struct *ps=&buffer->prs;
2835 prs_debug(ps, depth, desc, "smb_io_printer_driver_info_2");
2836 depth++;
2838 buffer->struct_start=prs_offset(ps);
2840 if (!prs_uint32("version", ps, depth, &info->version))
2841 return False;
2842 if (!smb_io_relstr("name", buffer, depth, &info->name))
2843 return False;
2844 if (!smb_io_relstr("architecture", buffer, depth, &info->architecture))
2845 return False;
2846 if (!smb_io_relstr("driverpath", buffer, depth, &info->driverpath))
2847 return False;
2848 if (!smb_io_relstr("datafile", buffer, depth, &info->datafile))
2849 return False;
2850 if (!smb_io_relstr("configfile", buffer, depth, &info->configfile))
2851 return False;
2853 return True;
2856 /*******************************************************************
2857 Parse a DRIVER_INFO_3 structure.
2858 ********************************************************************/
2860 BOOL smb_io_printer_driver_info_3(const char *desc, NEW_BUFFER *buffer, DRIVER_INFO_3 *info, int depth)
2862 prs_struct *ps=&buffer->prs;
2864 prs_debug(ps, depth, desc, "smb_io_printer_driver_info_3");
2865 depth++;
2867 buffer->struct_start=prs_offset(ps);
2869 if (!prs_uint32("version", ps, depth, &info->version))
2870 return False;
2871 if (!smb_io_relstr("name", buffer, depth, &info->name))
2872 return False;
2873 if (!smb_io_relstr("architecture", buffer, depth, &info->architecture))
2874 return False;
2875 if (!smb_io_relstr("driverpath", buffer, depth, &info->driverpath))
2876 return False;
2877 if (!smb_io_relstr("datafile", buffer, depth, &info->datafile))
2878 return False;
2879 if (!smb_io_relstr("configfile", buffer, depth, &info->configfile))
2880 return False;
2881 if (!smb_io_relstr("helpfile", buffer, depth, &info->helpfile))
2882 return False;
2884 if (!smb_io_relarraystr("dependentfiles", buffer, depth, &info->dependentfiles))
2885 return False;
2887 if (!smb_io_relstr("monitorname", buffer, depth, &info->monitorname))
2888 return False;
2889 if (!smb_io_relstr("defaultdatatype", buffer, depth, &info->defaultdatatype))
2890 return False;
2892 return True;
2895 /*******************************************************************
2896 Parse a DRIVER_INFO_6 structure.
2897 ********************************************************************/
2899 BOOL smb_io_printer_driver_info_6(const char *desc, NEW_BUFFER *buffer, DRIVER_INFO_6 *info, int depth)
2901 prs_struct *ps=&buffer->prs;
2903 prs_debug(ps, depth, desc, "smb_io_printer_driver_info_6");
2904 depth++;
2906 buffer->struct_start=prs_offset(ps);
2908 if (!prs_uint32("version", ps, depth, &info->version))
2909 return False;
2910 if (!smb_io_relstr("name", buffer, depth, &info->name))
2911 return False;
2912 if (!smb_io_relstr("architecture", buffer, depth, &info->architecture))
2913 return False;
2914 if (!smb_io_relstr("driverpath", buffer, depth, &info->driverpath))
2915 return False;
2916 if (!smb_io_relstr("datafile", buffer, depth, &info->datafile))
2917 return False;
2918 if (!smb_io_relstr("configfile", buffer, depth, &info->configfile))
2919 return False;
2920 if (!smb_io_relstr("helpfile", buffer, depth, &info->helpfile))
2921 return False;
2923 if (!smb_io_relarraystr("dependentfiles", buffer, depth, &info->dependentfiles))
2924 return False;
2926 if (!smb_io_relstr("monitorname", buffer, depth, &info->monitorname))
2927 return False;
2928 if (!smb_io_relstr("defaultdatatype", buffer, depth, &info->defaultdatatype))
2929 return False;
2931 if (!smb_io_relarraystr("previousdrivernames", buffer, depth, &info->previousdrivernames))
2932 return False;
2934 if (!prs_uint32("date.low", ps, depth, &info->driver_date.low))
2935 return False;
2936 if (!prs_uint32("date.high", ps, depth, &info->driver_date.high))
2937 return False;
2939 if (!prs_uint32("padding", ps, depth, &info->padding))
2940 return False;
2942 if (!prs_uint32("driver_version_low", ps, depth, &info->driver_version_low))
2943 return False;
2945 if (!prs_uint32("driver_version_high", ps, depth, &info->driver_version_high))
2946 return False;
2948 if (!smb_io_relstr("mfgname", buffer, depth, &info->mfgname))
2949 return False;
2950 if (!smb_io_relstr("oem_url", buffer, depth, &info->oem_url))
2951 return False;
2952 if (!smb_io_relstr("hardware_id", buffer, depth, &info->hardware_id))
2953 return False;
2954 if (!smb_io_relstr("provider", buffer, depth, &info->provider))
2955 return False;
2957 return True;
2960 /*******************************************************************
2961 Parse a JOB_INFO_1 structure.
2962 ********************************************************************/
2964 BOOL smb_io_job_info_1(const char *desc, NEW_BUFFER *buffer, JOB_INFO_1 *info, int depth)
2966 prs_struct *ps=&buffer->prs;
2968 prs_debug(ps, depth, desc, "smb_io_job_info_1");
2969 depth++;
2971 buffer->struct_start=prs_offset(ps);
2973 if (!prs_uint32("jobid", ps, depth, &info->jobid))
2974 return False;
2975 if (!smb_io_relstr("printername", buffer, depth, &info->printername))
2976 return False;
2977 if (!smb_io_relstr("machinename", buffer, depth, &info->machinename))
2978 return False;
2979 if (!smb_io_relstr("username", buffer, depth, &info->username))
2980 return False;
2981 if (!smb_io_relstr("document", buffer, depth, &info->document))
2982 return False;
2983 if (!smb_io_relstr("datatype", buffer, depth, &info->datatype))
2984 return False;
2985 if (!smb_io_relstr("text_status", buffer, depth, &info->text_status))
2986 return False;
2987 if (!prs_uint32("status", ps, depth, &info->status))
2988 return False;
2989 if (!prs_uint32("priority", ps, depth, &info->priority))
2990 return False;
2991 if (!prs_uint32("position", ps, depth, &info->position))
2992 return False;
2993 if (!prs_uint32("totalpages", ps, depth, &info->totalpages))
2994 return False;
2995 if (!prs_uint32("pagesprinted", ps, depth, &info->pagesprinted))
2996 return False;
2997 if (!spoolss_io_system_time("submitted", ps, depth, &info->submitted))
2998 return False;
3000 return True;
3003 /*******************************************************************
3004 Parse a JOB_INFO_2 structure.
3005 ********************************************************************/
3007 BOOL smb_io_job_info_2(const char *desc, NEW_BUFFER *buffer, JOB_INFO_2 *info, int depth)
3009 uint32 pipo=0;
3010 prs_struct *ps=&buffer->prs;
3012 prs_debug(ps, depth, desc, "smb_io_job_info_2");
3013 depth++;
3015 buffer->struct_start=prs_offset(ps);
3017 if (!prs_uint32("jobid",ps, depth, &info->jobid))
3018 return False;
3019 if (!smb_io_relstr("printername", buffer, depth, &info->printername))
3020 return False;
3021 if (!smb_io_relstr("machinename", buffer, depth, &info->machinename))
3022 return False;
3023 if (!smb_io_relstr("username", buffer, depth, &info->username))
3024 return False;
3025 if (!smb_io_relstr("document", buffer, depth, &info->document))
3026 return False;
3027 if (!smb_io_relstr("notifyname", buffer, depth, &info->notifyname))
3028 return False;
3029 if (!smb_io_relstr("datatype", buffer, depth, &info->datatype))
3030 return False;
3032 if (!smb_io_relstr("printprocessor", buffer, depth, &info->printprocessor))
3033 return False;
3034 if (!smb_io_relstr("parameters", buffer, depth, &info->parameters))
3035 return False;
3036 if (!smb_io_relstr("drivername", buffer, depth, &info->drivername))
3037 return False;
3038 if (!smb_io_reldevmode("devmode", buffer, depth, &info->devmode))
3039 return False;
3040 if (!smb_io_relstr("text_status", buffer, depth, &info->text_status))
3041 return False;
3043 /* SEC_DESC sec_desc;*/
3044 if (!prs_uint32("Hack! sec desc", ps, depth, &pipo))
3045 return False;
3047 if (!prs_uint32("status",ps, depth, &info->status))
3048 return False;
3049 if (!prs_uint32("priority",ps, depth, &info->priority))
3050 return False;
3051 if (!prs_uint32("position",ps, depth, &info->position))
3052 return False;
3053 if (!prs_uint32("starttime",ps, depth, &info->starttime))
3054 return False;
3055 if (!prs_uint32("untiltime",ps, depth, &info->untiltime))
3056 return False;
3057 if (!prs_uint32("totalpages",ps, depth, &info->totalpages))
3058 return False;
3059 if (!prs_uint32("size",ps, depth, &info->size))
3060 return False;
3061 if (!spoolss_io_system_time("submitted", ps, depth, &info->submitted) )
3062 return False;
3063 if (!prs_uint32("timeelapsed",ps, depth, &info->timeelapsed))
3064 return False;
3065 if (!prs_uint32("pagesprinted",ps, depth, &info->pagesprinted))
3066 return False;
3068 return True;
3071 /*******************************************************************
3072 ********************************************************************/
3074 BOOL smb_io_form_1(const char *desc, NEW_BUFFER *buffer, FORM_1 *info, int depth)
3076 prs_struct *ps=&buffer->prs;
3078 prs_debug(ps, depth, desc, "smb_io_form_1");
3079 depth++;
3081 buffer->struct_start=prs_offset(ps);
3083 if (!prs_uint32("flag", ps, depth, &info->flag))
3084 return False;
3086 if (!smb_io_relstr("name", buffer, depth, &info->name))
3087 return False;
3089 if (!prs_uint32("width", ps, depth, &info->width))
3090 return False;
3091 if (!prs_uint32("length", ps, depth, &info->length))
3092 return False;
3093 if (!prs_uint32("left", ps, depth, &info->left))
3094 return False;
3095 if (!prs_uint32("top", ps, depth, &info->top))
3096 return False;
3097 if (!prs_uint32("right", ps, depth, &info->right))
3098 return False;
3099 if (!prs_uint32("bottom", ps, depth, &info->bottom))
3100 return False;
3102 return True;
3105 /*******************************************************************
3106 Read/write a BUFFER struct.
3107 ********************************************************************/
3109 static BOOL spoolss_io_buffer(const char *desc, prs_struct *ps, int depth, NEW_BUFFER **pp_buffer)
3111 NEW_BUFFER *buffer = *pp_buffer;
3113 prs_debug(ps, depth, desc, "spoolss_io_buffer");
3114 depth++;
3116 if (UNMARSHALLING(ps))
3117 buffer = *pp_buffer = (NEW_BUFFER *)prs_alloc_mem(ps, sizeof(NEW_BUFFER));
3119 if (buffer == NULL)
3120 return False;
3122 if (!prs_uint32("ptr", ps, depth, &buffer->ptr))
3123 return False;
3125 /* reading */
3126 if (UNMARSHALLING(ps)) {
3127 buffer->size=0;
3128 buffer->string_at_end=0;
3130 if (buffer->ptr==0) {
3132 * JRA. I'm not sure if the data in here is in big-endian format if
3133 * the client is big-endian. Leave as default (little endian) for now.
3136 if (!prs_init(&buffer->prs, 0, prs_get_mem_context(ps), UNMARSHALL))
3137 return False;
3138 return True;
3141 if (!prs_uint32("size", ps, depth, &buffer->size))
3142 return False;
3145 * JRA. I'm not sure if the data in here is in big-endian format if
3146 * the client is big-endian. Leave as default (little endian) for now.
3149 if (!prs_init(&buffer->prs, buffer->size, prs_get_mem_context(ps), UNMARSHALL))
3150 return False;
3152 if (!prs_append_some_prs_data(&buffer->prs, ps, prs_offset(ps), buffer->size))
3153 return False;
3155 if (!prs_set_offset(&buffer->prs, 0))
3156 return False;
3158 if (!prs_set_offset(ps, buffer->size+prs_offset(ps)))
3159 return False;
3161 buffer->string_at_end=buffer->size;
3163 return True;
3165 else {
3166 BOOL ret = False;
3168 /* writing */
3169 if (buffer->ptr==0) {
3170 /* We have finished with the data in buffer->prs - free it. */
3171 prs_mem_free(&buffer->prs);
3172 return True;
3175 if (!prs_uint32("size", ps, depth, &buffer->size))
3176 goto out;
3178 if (!prs_append_some_prs_data(ps, &buffer->prs, 0, buffer->size))
3179 goto out;
3181 ret = True;
3182 out:
3184 /* We have finished with the data in buffer->prs - free it. */
3185 prs_mem_free(&buffer->prs);
3187 return ret;
3191 /*******************************************************************
3192 move a BUFFER from the query to the reply.
3193 As the data pointers in NEW_BUFFER are malloc'ed, not talloc'ed,
3194 this is ok. This is an OPTIMIZATION and is not strictly neccessary.
3195 Clears the memory to zero also.
3196 ********************************************************************/
3198 void spoolss_move_buffer(NEW_BUFFER *src, NEW_BUFFER **dest)
3200 prs_switch_type(&src->prs, MARSHALL);
3201 if(!prs_set_offset(&src->prs, 0))
3202 return;
3203 prs_force_dynamic(&src->prs);
3204 prs_mem_clear(&src->prs);
3205 *dest=src;
3208 /*******************************************************************
3209 Get the size of a BUFFER struct.
3210 ********************************************************************/
3212 uint32 new_get_buffer_size(NEW_BUFFER *buffer)
3214 return (buffer->size);
3217 /*******************************************************************
3218 Parse a DRIVER_DIRECTORY_1 structure.
3219 ********************************************************************/
3221 BOOL smb_io_driverdir_1(const char *desc, NEW_BUFFER *buffer, DRIVER_DIRECTORY_1 *info, int depth)
3223 prs_struct *ps=&buffer->prs;
3225 prs_debug(ps, depth, desc, "smb_io_driverdir_1");
3226 depth++;
3228 buffer->struct_start=prs_offset(ps);
3230 if (!smb_io_unistr(desc, &info->name, ps, depth))
3231 return False;
3233 return True;
3236 /*******************************************************************
3237 Parse a PORT_INFO_1 structure.
3238 ********************************************************************/
3240 BOOL smb_io_port_1(const char *desc, NEW_BUFFER *buffer, PORT_INFO_1 *info, int depth)
3242 prs_struct *ps=&buffer->prs;
3244 prs_debug(ps, depth, desc, "smb_io_port_1");
3245 depth++;
3247 buffer->struct_start=prs_offset(ps);
3249 if(!smb_io_relstr("port_name", buffer, depth, &info->port_name))
3250 return False;
3252 return True;
3255 /*******************************************************************
3256 Parse a PORT_INFO_2 structure.
3257 ********************************************************************/
3259 BOOL smb_io_port_2(const char *desc, NEW_BUFFER *buffer, PORT_INFO_2 *info, int depth)
3261 prs_struct *ps=&buffer->prs;
3263 prs_debug(ps, depth, desc, "smb_io_port_2");
3264 depth++;
3266 buffer->struct_start=prs_offset(ps);
3268 if(!smb_io_relstr("port_name", buffer, depth, &info->port_name))
3269 return False;
3270 if(!smb_io_relstr("monitor_name", buffer, depth, &info->monitor_name))
3271 return False;
3272 if(!smb_io_relstr("description", buffer, depth, &info->description))
3273 return False;
3274 if(!prs_uint32("port_type", ps, depth, &info->port_type))
3275 return False;
3276 if(!prs_uint32("reserved", ps, depth, &info->reserved))
3277 return False;
3279 return True;
3282 /*******************************************************************
3283 ********************************************************************/
3285 BOOL smb_io_printprocessor_info_1(const char *desc, NEW_BUFFER *buffer, PRINTPROCESSOR_1 *info, int depth)
3287 prs_struct *ps=&buffer->prs;
3289 prs_debug(ps, depth, desc, "smb_io_printprocessor_info_1");
3290 depth++;
3292 buffer->struct_start=prs_offset(ps);
3294 if (smb_io_relstr("name", buffer, depth, &info->name))
3295 return False;
3297 return True;
3300 /*******************************************************************
3301 ********************************************************************/
3303 BOOL smb_io_printprocdatatype_info_1(const char *desc, NEW_BUFFER *buffer, PRINTPROCDATATYPE_1 *info, int depth)
3305 prs_struct *ps=&buffer->prs;
3307 prs_debug(ps, depth, desc, "smb_io_printprocdatatype_info_1");
3308 depth++;
3310 buffer->struct_start=prs_offset(ps);
3312 if (smb_io_relstr("name", buffer, depth, &info->name))
3313 return False;
3315 return True;
3318 /*******************************************************************
3319 ********************************************************************/
3321 BOOL smb_io_printmonitor_info_1(const char *desc, NEW_BUFFER *buffer, PRINTMONITOR_1 *info, int depth)
3323 prs_struct *ps=&buffer->prs;
3325 prs_debug(ps, depth, desc, "smb_io_printmonitor_info_1");
3326 depth++;
3328 buffer->struct_start=prs_offset(ps);
3330 if (!smb_io_relstr("name", buffer, depth, &info->name))
3331 return False;
3333 return True;
3336 /*******************************************************************
3337 ********************************************************************/
3339 BOOL smb_io_printmonitor_info_2(const char *desc, NEW_BUFFER *buffer, PRINTMONITOR_2 *info, int depth)
3341 prs_struct *ps=&buffer->prs;
3343 prs_debug(ps, depth, desc, "smb_io_printmonitor_info_2");
3344 depth++;
3346 buffer->struct_start=prs_offset(ps);
3348 if (!smb_io_relstr("name", buffer, depth, &info->name))
3349 return False;
3350 if (!smb_io_relstr("environment", buffer, depth, &info->environment))
3351 return False;
3352 if (!smb_io_relstr("dll_name", buffer, depth, &info->dll_name))
3353 return False;
3355 return True;
3358 /*******************************************************************
3359 return the size required by a struct in the stream
3360 ********************************************************************/
3362 uint32 spoolss_size_printer_info_0(PRINTER_INFO_0 *info)
3364 int size=0;
3366 size+=size_of_relative_string( &info->printername );
3367 size+=size_of_relative_string( &info->servername );
3369 size+=size_of_uint32( &info->cjobs);
3370 size+=size_of_uint32( &info->total_jobs);
3371 size+=size_of_uint32( &info->total_bytes);
3373 size+=size_of_uint16( &info->year);
3374 size+=size_of_uint16( &info->month);
3375 size+=size_of_uint16( &info->dayofweek);
3376 size+=size_of_uint16( &info->day);
3377 size+=size_of_uint16( &info->hour);
3378 size+=size_of_uint16( &info->minute);
3379 size+=size_of_uint16( &info->second);
3380 size+=size_of_uint16( &info->milliseconds);
3382 size+=size_of_uint32( &info->global_counter);
3383 size+=size_of_uint32( &info->total_pages);
3385 size+=size_of_uint16( &info->major_version);
3386 size+=size_of_uint16( &info->build_version);
3388 size+=size_of_uint32( &info->unknown7);
3389 size+=size_of_uint32( &info->unknown8);
3390 size+=size_of_uint32( &info->unknown9);
3391 size+=size_of_uint32( &info->session_counter);
3392 size+=size_of_uint32( &info->unknown11);
3393 size+=size_of_uint32( &info->printer_errors);
3394 size+=size_of_uint32( &info->unknown13);
3395 size+=size_of_uint32( &info->unknown14);
3396 size+=size_of_uint32( &info->unknown15);
3397 size+=size_of_uint32( &info->unknown16);
3398 size+=size_of_uint32( &info->change_id);
3399 size+=size_of_uint32( &info->unknown18);
3400 size+=size_of_uint32( &info->status);
3401 size+=size_of_uint32( &info->unknown20);
3402 size+=size_of_uint32( &info->c_setprinter);
3404 size+=size_of_uint16( &info->unknown22);
3405 size+=size_of_uint16( &info->unknown23);
3406 size+=size_of_uint16( &info->unknown24);
3407 size+=size_of_uint16( &info->unknown25);
3408 size+=size_of_uint16( &info->unknown26);
3409 size+=size_of_uint16( &info->unknown27);
3410 size+=size_of_uint16( &info->unknown28);
3411 size+=size_of_uint16( &info->unknown29);
3413 return size;
3416 /*******************************************************************
3417 return the size required by a struct in the stream
3418 ********************************************************************/
3420 uint32 spoolss_size_printer_info_1(PRINTER_INFO_1 *info)
3422 int size=0;
3424 size+=size_of_uint32( &info->flags );
3425 size+=size_of_relative_string( &info->description );
3426 size+=size_of_relative_string( &info->name );
3427 size+=size_of_relative_string( &info->comment );
3429 return size;
3432 /*******************************************************************
3433 return the size required by a struct in the stream
3434 ********************************************************************/
3436 uint32 spoolss_size_printer_info_2(PRINTER_INFO_2 *info)
3438 uint32 size=0;
3440 size += 4;
3442 size += sec_desc_size( info->secdesc );
3444 size+=size_of_device_mode( info->devmode );
3446 size+=size_of_relative_string( &info->servername );
3447 size+=size_of_relative_string( &info->printername );
3448 size+=size_of_relative_string( &info->sharename );
3449 size+=size_of_relative_string( &info->portname );
3450 size+=size_of_relative_string( &info->drivername );
3451 size+=size_of_relative_string( &info->comment );
3452 size+=size_of_relative_string( &info->location );
3454 size+=size_of_relative_string( &info->sepfile );
3455 size+=size_of_relative_string( &info->printprocessor );
3456 size+=size_of_relative_string( &info->datatype );
3457 size+=size_of_relative_string( &info->parameters );
3459 size+=size_of_uint32( &info->attributes );
3460 size+=size_of_uint32( &info->priority );
3461 size+=size_of_uint32( &info->defaultpriority );
3462 size+=size_of_uint32( &info->starttime );
3463 size+=size_of_uint32( &info->untiltime );
3464 size+=size_of_uint32( &info->status );
3465 size+=size_of_uint32( &info->cjobs );
3466 size+=size_of_uint32( &info->averageppm );
3469 * add any adjustments for alignment. This is
3470 * not optimal since we could be calling this
3471 * function from a loop (e.g. enumprinters), but
3472 * it is easier to maintain the calculation here and
3473 * not place the burden on the caller to remember. --jerry
3475 if ((size % 4) != 0)
3476 size += 4 - (size % 4);
3478 return size;
3481 /*******************************************************************
3482 return the size required by a struct in the stream
3483 ********************************************************************/
3485 uint32 spoolss_size_printer_info_4(PRINTER_INFO_4 *info)
3487 uint32 size=0;
3489 size+=size_of_relative_string( &info->printername );
3490 size+=size_of_relative_string( &info->servername );
3492 size+=size_of_uint32( &info->attributes );
3493 return size;
3496 /*******************************************************************
3497 return the size required by a struct in the stream
3498 ********************************************************************/
3500 uint32 spoolss_size_printer_info_5(PRINTER_INFO_5 *info)
3502 uint32 size=0;
3504 size+=size_of_relative_string( &info->printername );
3505 size+=size_of_relative_string( &info->portname );
3507 size+=size_of_uint32( &info->attributes );
3508 size+=size_of_uint32( &info->device_not_selected_timeout );
3509 size+=size_of_uint32( &info->transmission_retry_timeout );
3510 return size;
3514 /*******************************************************************
3515 return the size required by a struct in the stream
3516 ********************************************************************/
3518 uint32 spoolss_size_printer_info_3(PRINTER_INFO_3 *info)
3520 /* The 4 is for the self relative pointer.. */
3521 /* JRA !!!! TESTME - WHAT ABOUT prs_align.... !!! */
3522 return 4 + (uint32)sec_desc_size( info->secdesc );
3525 /*******************************************************************
3526 return the size required by a struct in the stream
3527 ********************************************************************/
3529 uint32 spoolss_size_printer_info_7(PRINTER_INFO_7 *info)
3531 uint32 size=0;
3533 size+=size_of_relative_string( &info->guid );
3534 size+=size_of_uint32( &info->action );
3535 return size;
3538 /*******************************************************************
3539 return the size required by a struct in the stream
3540 ********************************************************************/
3542 uint32 spoolss_size_printer_driver_info_1(DRIVER_INFO_1 *info)
3544 int size=0;
3545 size+=size_of_relative_string( &info->name );
3547 return size;
3550 /*******************************************************************
3551 return the size required by a struct in the stream
3552 ********************************************************************/
3554 uint32 spoolss_size_printer_driver_info_2(DRIVER_INFO_2 *info)
3556 int size=0;
3557 size+=size_of_uint32( &info->version );
3558 size+=size_of_relative_string( &info->name );
3559 size+=size_of_relative_string( &info->architecture );
3560 size+=size_of_relative_string( &info->driverpath );
3561 size+=size_of_relative_string( &info->datafile );
3562 size+=size_of_relative_string( &info->configfile );
3564 return size;
3567 /*******************************************************************
3568 return the size required by a string array.
3569 ********************************************************************/
3571 uint32 spoolss_size_string_array(uint16 *string)
3573 uint32 i = 0;
3575 if (string) {
3576 for (i=0; (string[i]!=0x0000) || (string[i+1]!=0x0000); i++);
3578 i=i+2; /* to count all chars including the leading zero */
3579 i=2*i; /* because we need the value in bytes */
3580 i=i+4; /* the offset pointer size */
3582 return i;
3585 /*******************************************************************
3586 return the size required by a struct in the stream
3587 ********************************************************************/
3589 uint32 spoolss_size_printer_driver_info_3(DRIVER_INFO_3 *info)
3591 int size=0;
3593 size+=size_of_uint32( &info->version );
3594 size+=size_of_relative_string( &info->name );
3595 size+=size_of_relative_string( &info->architecture );
3596 size+=size_of_relative_string( &info->driverpath );
3597 size+=size_of_relative_string( &info->datafile );
3598 size+=size_of_relative_string( &info->configfile );
3599 size+=size_of_relative_string( &info->helpfile );
3600 size+=size_of_relative_string( &info->monitorname );
3601 size+=size_of_relative_string( &info->defaultdatatype );
3603 size+=spoolss_size_string_array(info->dependentfiles);
3605 return size;
3608 /*******************************************************************
3609 return the size required by a struct in the stream
3610 ********************************************************************/
3612 uint32 spoolss_size_printer_driver_info_6(DRIVER_INFO_6 *info)
3614 uint32 size=0;
3616 size+=size_of_uint32( &info->version );
3617 size+=size_of_relative_string( &info->name );
3618 size+=size_of_relative_string( &info->architecture );
3619 size+=size_of_relative_string( &info->driverpath );
3620 size+=size_of_relative_string( &info->datafile );
3621 size+=size_of_relative_string( &info->configfile );
3622 size+=size_of_relative_string( &info->helpfile );
3624 size+=spoolss_size_string_array(info->dependentfiles);
3626 size+=size_of_relative_string( &info->monitorname );
3627 size+=size_of_relative_string( &info->defaultdatatype );
3629 size+=spoolss_size_string_array(info->previousdrivernames);
3631 size+=size_of_nttime(&info->driver_date);
3632 size+=size_of_uint32( &info->padding );
3633 size+=size_of_uint32( &info->driver_version_low );
3634 size+=size_of_uint32( &info->driver_version_high );
3635 size+=size_of_relative_string( &info->mfgname );
3636 size+=size_of_relative_string( &info->oem_url );
3637 size+=size_of_relative_string( &info->hardware_id );
3638 size+=size_of_relative_string( &info->provider );
3640 return size;
3643 /*******************************************************************
3644 return the size required by a struct in the stream
3645 ********************************************************************/
3647 uint32 spoolss_size_job_info_1(JOB_INFO_1 *info)
3649 int size=0;
3650 size+=size_of_uint32( &info->jobid );
3651 size+=size_of_relative_string( &info->printername );
3652 size+=size_of_relative_string( &info->machinename );
3653 size+=size_of_relative_string( &info->username );
3654 size+=size_of_relative_string( &info->document );
3655 size+=size_of_relative_string( &info->datatype );
3656 size+=size_of_relative_string( &info->text_status );
3657 size+=size_of_uint32( &info->status );
3658 size+=size_of_uint32( &info->priority );
3659 size+=size_of_uint32( &info->position );
3660 size+=size_of_uint32( &info->totalpages );
3661 size+=size_of_uint32( &info->pagesprinted );
3662 size+=size_of_systemtime( &info->submitted );
3664 return size;
3667 /*******************************************************************
3668 return the size required by a struct in the stream
3669 ********************************************************************/
3671 uint32 spoolss_size_job_info_2(JOB_INFO_2 *info)
3673 int size=0;
3675 size+=4; /* size of sec desc ptr */
3677 size+=size_of_uint32( &info->jobid );
3678 size+=size_of_relative_string( &info->printername );
3679 size+=size_of_relative_string( &info->machinename );
3680 size+=size_of_relative_string( &info->username );
3681 size+=size_of_relative_string( &info->document );
3682 size+=size_of_relative_string( &info->notifyname );
3683 size+=size_of_relative_string( &info->datatype );
3684 size+=size_of_relative_string( &info->printprocessor );
3685 size+=size_of_relative_string( &info->parameters );
3686 size+=size_of_relative_string( &info->drivername );
3687 size+=size_of_device_mode( info->devmode );
3688 size+=size_of_relative_string( &info->text_status );
3689 /* SEC_DESC sec_desc;*/
3690 size+=size_of_uint32( &info->status );
3691 size+=size_of_uint32( &info->priority );
3692 size+=size_of_uint32( &info->position );
3693 size+=size_of_uint32( &info->starttime );
3694 size+=size_of_uint32( &info->untiltime );
3695 size+=size_of_uint32( &info->totalpages );
3696 size+=size_of_uint32( &info->size );
3697 size+=size_of_systemtime( &info->submitted );
3698 size+=size_of_uint32( &info->timeelapsed );
3699 size+=size_of_uint32( &info->pagesprinted );
3701 return size;
3704 /*******************************************************************
3705 return the size required by a struct in the stream
3706 ********************************************************************/
3708 uint32 spoolss_size_form_1(FORM_1 *info)
3710 int size=0;
3712 size+=size_of_uint32( &info->flag );
3713 size+=size_of_relative_string( &info->name );
3714 size+=size_of_uint32( &info->width );
3715 size+=size_of_uint32( &info->length );
3716 size+=size_of_uint32( &info->left );
3717 size+=size_of_uint32( &info->top );
3718 size+=size_of_uint32( &info->right );
3719 size+=size_of_uint32( &info->bottom );
3721 return size;
3724 /*******************************************************************
3725 return the size required by a struct in the stream
3726 ********************************************************************/
3728 uint32 spoolss_size_port_info_1(PORT_INFO_1 *info)
3730 int size=0;
3732 size+=size_of_relative_string( &info->port_name );
3734 return size;
3737 /*******************************************************************
3738 return the size required by a struct in the stream
3739 ********************************************************************/
3741 uint32 spoolss_size_driverdir_info_1(DRIVER_DIRECTORY_1 *info)
3743 int size=0;
3745 size=str_len_uni(&info->name); /* the string length */
3746 size=size+1; /* add the leading zero */
3747 size=size*2; /* convert in char */
3749 return size;
3752 /*******************************************************************
3753 return the size required by a struct in the stream
3754 ********************************************************************/
3756 uint32 spoolss_size_printprocessordirectory_info_1(PRINTPROCESSOR_DIRECTORY_1 *info)
3758 int size=0;
3760 size=str_len_uni(&info->name); /* the string length */
3761 size=size+1; /* add the leading zero */
3762 size=size*2; /* convert in char */
3764 return size;
3767 /*******************************************************************
3768 return the size required by a struct in the stream
3769 ********************************************************************/
3771 uint32 spoolss_size_port_info_2(PORT_INFO_2 *info)
3773 int size=0;
3775 size+=size_of_relative_string( &info->port_name );
3776 size+=size_of_relative_string( &info->monitor_name );
3777 size+=size_of_relative_string( &info->description );
3779 size+=size_of_uint32( &info->port_type );
3780 size+=size_of_uint32( &info->reserved );
3782 return size;
3785 /*******************************************************************
3786 return the size required by a struct in the stream
3787 ********************************************************************/
3789 uint32 spoolss_size_printprocessor_info_1(PRINTPROCESSOR_1 *info)
3791 int size=0;
3792 size+=size_of_relative_string( &info->name );
3794 return size;
3797 /*******************************************************************
3798 return the size required by a struct in the stream
3799 ********************************************************************/
3801 uint32 spoolss_size_printprocdatatype_info_1(PRINTPROCDATATYPE_1 *info)
3803 int size=0;
3804 size+=size_of_relative_string( &info->name );
3806 return size;
3809 /*******************************************************************
3810 return the size required by a struct in the stream
3811 ********************************************************************/
3812 uint32 spoolss_size_printer_enum_values(PRINTER_ENUM_VALUES *p)
3814 uint32 size = 0;
3816 if (!p)
3817 return 0;
3819 /* uint32(offset) + uint32(length) + length) */
3820 size += (size_of_uint32(&p->value_len)*2) + p->value_len;
3821 size += (size_of_uint32(&p->data_len)*2) + p->data_len + (p->data_len%2) ;
3823 size += size_of_uint32(&p->type);
3825 return size;
3828 /*******************************************************************
3829 return the size required by a struct in the stream
3830 ********************************************************************/
3832 uint32 spoolss_size_printmonitor_info_1(PRINTMONITOR_1 *info)
3834 int size=0;
3835 size+=size_of_relative_string( &info->name );
3837 return size;
3840 /*******************************************************************
3841 return the size required by a struct in the stream
3842 ********************************************************************/
3844 uint32 spoolss_size_printmonitor_info_2(PRINTMONITOR_2 *info)
3846 int size=0;
3847 size+=size_of_relative_string( &info->name);
3848 size+=size_of_relative_string( &info->environment);
3849 size+=size_of_relative_string( &info->dll_name);
3851 return size;
3854 /*******************************************************************
3855 * init a structure.
3856 ********************************************************************/
3858 BOOL make_spoolss_q_getprinterdriver2(SPOOL_Q_GETPRINTERDRIVER2 *q_u,
3859 const POLICY_HND *hnd,
3860 const fstring architecture,
3861 uint32 level, uint32 clientmajor, uint32 clientminor,
3862 NEW_BUFFER *buffer, uint32 offered)
3864 if (q_u == NULL)
3865 return False;
3867 memcpy(&q_u->handle, hnd, sizeof(q_u->handle));
3869 init_buf_unistr2(&q_u->architecture, &q_u->architecture_ptr, architecture);
3871 q_u->level=level;
3872 q_u->clientmajorversion=clientmajor;
3873 q_u->clientminorversion=clientminor;
3875 q_u->buffer=buffer;
3876 q_u->offered=offered;
3878 return True;
3881 /*******************************************************************
3882 * read a structure.
3883 * called from spoolss_getprinterdriver2 (srv_spoolss.c)
3884 ********************************************************************/
3886 BOOL spoolss_io_q_getprinterdriver2(const char *desc, SPOOL_Q_GETPRINTERDRIVER2 *q_u, prs_struct *ps, int depth)
3888 prs_debug(ps, depth, desc, "spoolss_io_q_getprinterdriver2");
3889 depth++;
3891 if(!prs_align(ps))
3892 return False;
3894 if(!smb_io_pol_hnd("printer handle", &q_u->handle, ps, depth))
3895 return False;
3896 if(!prs_uint32("architecture_ptr", ps, depth, &q_u->architecture_ptr))
3897 return False;
3898 if(!smb_io_unistr2("architecture", &q_u->architecture, q_u->architecture_ptr, ps, depth))
3899 return False;
3901 if(!prs_align(ps))
3902 return False;
3903 if(!prs_uint32("level", ps, depth, &q_u->level))
3904 return False;
3906 if(!spoolss_io_buffer("", ps, depth, &q_u->buffer))
3907 return False;
3909 if(!prs_align(ps))
3910 return False;
3912 if(!prs_uint32("offered", ps, depth, &q_u->offered))
3913 return False;
3915 if(!prs_uint32("clientmajorversion", ps, depth, &q_u->clientmajorversion))
3916 return False;
3917 if(!prs_uint32("clientminorversion", ps, depth, &q_u->clientminorversion))
3918 return False;
3920 return True;
3923 /*******************************************************************
3924 * read a structure.
3925 * called from spoolss_getprinterdriver2 (srv_spoolss.c)
3926 ********************************************************************/
3928 BOOL spoolss_io_r_getprinterdriver2(const char *desc, SPOOL_R_GETPRINTERDRIVER2 *r_u, prs_struct *ps, int depth)
3930 prs_debug(ps, depth, desc, "spoolss_io_r_getprinterdriver2");
3931 depth++;
3933 if (!prs_align(ps))
3934 return False;
3936 if (!spoolss_io_buffer("", ps, depth, &r_u->buffer))
3937 return False;
3939 if (!prs_align(ps))
3940 return False;
3941 if (!prs_uint32("needed", ps, depth, &r_u->needed))
3942 return False;
3943 if (!prs_uint32("servermajorversion", ps, depth, &r_u->servermajorversion))
3944 return False;
3945 if (!prs_uint32("serverminorversion", ps, depth, &r_u->serverminorversion))
3946 return False;
3947 if (!prs_werror("status", ps, depth, &r_u->status))
3948 return False;
3950 return True;
3953 /*******************************************************************
3954 * init a structure.
3955 ********************************************************************/
3957 BOOL make_spoolss_q_enumprinters(
3958 SPOOL_Q_ENUMPRINTERS *q_u,
3959 uint32 flags,
3960 char *servername,
3961 uint32 level,
3962 NEW_BUFFER *buffer,
3963 uint32 offered
3966 q_u->flags=flags;
3968 q_u->servername_ptr = (servername != NULL) ? 1 : 0;
3969 init_buf_unistr2(&q_u->servername, &q_u->servername_ptr, servername);
3971 q_u->level=level;
3972 q_u->buffer=buffer;
3973 q_u->offered=offered;
3975 return True;
3978 /*******************************************************************
3979 * init a structure.
3980 ********************************************************************/
3982 BOOL make_spoolss_q_enumports(SPOOL_Q_ENUMPORTS *q_u,
3983 fstring servername, uint32 level,
3984 NEW_BUFFER *buffer, uint32 offered)
3986 q_u->name_ptr = (servername != NULL) ? 1 : 0;
3987 init_buf_unistr2(&q_u->name, &q_u->name_ptr, servername);
3989 q_u->level=level;
3990 q_u->buffer=buffer;
3991 q_u->offered=offered;
3993 return True;
3996 /*******************************************************************
3997 * read a structure.
3998 * called from spoolss_enumprinters (srv_spoolss.c)
3999 ********************************************************************/
4001 BOOL spoolss_io_q_enumprinters(const char *desc, SPOOL_Q_ENUMPRINTERS *q_u, prs_struct *ps, int depth)
4003 prs_debug(ps, depth, desc, "spoolss_io_q_enumprinters");
4004 depth++;
4006 if (!prs_align(ps))
4007 return False;
4009 if (!prs_uint32("flags", ps, depth, &q_u->flags))
4010 return False;
4011 if (!prs_uint32("servername_ptr", ps, depth, &q_u->servername_ptr))
4012 return False;
4014 if (!smb_io_unistr2("", &q_u->servername, q_u->servername_ptr, ps, depth))
4015 return False;
4017 if (!prs_align(ps))
4018 return False;
4019 if (!prs_uint32("level", ps, depth, &q_u->level))
4020 return False;
4022 if (!spoolss_io_buffer("", ps, depth, &q_u->buffer))
4023 return False;
4025 if (!prs_align(ps))
4026 return False;
4027 if (!prs_uint32("offered", ps, depth, &q_u->offered))
4028 return False;
4030 return True;
4033 /*******************************************************************
4034 Parse a SPOOL_R_ENUMPRINTERS structure.
4035 ********************************************************************/
4037 BOOL spoolss_io_r_enumprinters(const char *desc, SPOOL_R_ENUMPRINTERS *r_u, prs_struct *ps, int depth)
4039 prs_debug(ps, depth, desc, "spoolss_io_r_enumprinters");
4040 depth++;
4042 if (!prs_align(ps))
4043 return False;
4045 if (!spoolss_io_buffer("", ps, depth, &r_u->buffer))
4046 return False;
4048 if (!prs_align(ps))
4049 return False;
4051 if (!prs_uint32("needed", ps, depth, &r_u->needed))
4052 return False;
4054 if (!prs_uint32("returned", ps, depth, &r_u->returned))
4055 return False;
4057 if (!prs_werror("status", ps, depth, &r_u->status))
4058 return False;
4060 return True;
4063 /*******************************************************************
4064 * write a structure.
4065 * called from spoolss_r_enum_printers (srv_spoolss.c)
4067 ********************************************************************/
4069 BOOL spoolss_io_r_getprinter(const char *desc, SPOOL_R_GETPRINTER *r_u, prs_struct *ps, int depth)
4071 prs_debug(ps, depth, desc, "spoolss_io_r_getprinter");
4072 depth++;
4074 if (!prs_align(ps))
4075 return False;
4077 if (!spoolss_io_buffer("", ps, depth, &r_u->buffer))
4078 return False;
4080 if (!prs_align(ps))
4081 return False;
4083 if (!prs_uint32("needed", ps, depth, &r_u->needed))
4084 return False;
4086 if (!prs_werror("status", ps, depth, &r_u->status))
4087 return False;
4089 return True;
4092 /*******************************************************************
4093 * read a structure.
4094 * called from spoolss_getprinter (srv_spoolss.c)
4095 ********************************************************************/
4097 BOOL spoolss_io_q_getprinter(const char *desc, SPOOL_Q_GETPRINTER *q_u, prs_struct *ps, int depth)
4099 prs_debug(ps, depth, desc, "spoolss_io_q_getprinter");
4100 depth++;
4102 if (!prs_align(ps))
4103 return False;
4105 if(!smb_io_pol_hnd("printer handle", &q_u->handle, ps, depth))
4106 return False;
4107 if (!prs_uint32("level", ps, depth, &q_u->level))
4108 return False;
4110 if (!spoolss_io_buffer("", ps, depth, &q_u->buffer))
4111 return False;
4113 if (!prs_align(ps))
4114 return False;
4115 if (!prs_uint32("offered", ps, depth, &q_u->offered))
4116 return False;
4118 return True;
4121 /*******************************************************************
4122 * init a structure.
4123 ********************************************************************/
4125 BOOL make_spoolss_q_getprinter(
4126 TALLOC_CTX *mem_ctx,
4127 SPOOL_Q_GETPRINTER *q_u,
4128 const POLICY_HND *hnd,
4129 uint32 level,
4130 NEW_BUFFER *buffer,
4131 uint32 offered
4134 if (q_u == NULL)
4136 return False;
4138 memcpy(&q_u->handle, hnd, sizeof(q_u->handle));
4140 q_u->level=level;
4141 q_u->buffer=buffer;
4142 q_u->offered=offered;
4144 return True;
4147 /*******************************************************************
4148 * init a structure.
4149 ********************************************************************/
4150 BOOL make_spoolss_q_setprinter(TALLOC_CTX *mem_ctx, SPOOL_Q_SETPRINTER *q_u,
4151 const POLICY_HND *hnd, uint32 level, PRINTER_INFO_CTR *info,
4152 uint32 command)
4154 SEC_DESC *secdesc;
4155 DEVICEMODE *devmode;
4157 if (q_u == NULL)
4158 return False;
4160 memcpy(&q_u->handle, hnd, sizeof(q_u->handle));
4162 q_u->level = level;
4163 q_u->info.level = level;
4164 q_u->info.info_ptr = (info != NULL) ? 1 : 0;
4165 switch (level) {
4167 /* There's no such thing as a setprinter level 1 */
4169 case 2:
4170 secdesc = info->printers_2->secdesc;
4171 devmode = info->printers_2->devmode;
4173 make_spoolss_printer_info_2 (mem_ctx, &q_u->info.info_2, info->printers_2);
4174 #if 1 /* JERRY TEST */
4175 q_u->secdesc_ctr = (SEC_DESC_BUF*)malloc(sizeof(SEC_DESC_BUF));
4176 if (!q_u->secdesc_ctr)
4177 return False;
4178 q_u->secdesc_ctr->ptr = (secdesc != NULL) ? 1: 0;
4179 q_u->secdesc_ctr->max_len = (secdesc) ? sizeof(SEC_DESC) + (2*sizeof(uint32)) : 0;
4180 q_u->secdesc_ctr->len = (secdesc) ? sizeof(SEC_DESC) + (2*sizeof(uint32)) : 0;
4181 q_u->secdesc_ctr->sec = secdesc;
4183 q_u->devmode_ctr.devmode_ptr = (devmode != NULL) ? 1 : 0;
4184 q_u->devmode_ctr.size = (devmode != NULL) ? sizeof(DEVICEMODE) + (3*sizeof(uint32)) : 0;
4185 q_u->devmode_ctr.devmode = devmode;
4186 #else
4187 q_u->secdesc_ctr = NULL;
4189 q_u->devmode_ctr.devmode_ptr = 0;
4190 q_u->devmode_ctr.size = 0;
4191 q_u->devmode_ctr.devmode = NULL;
4192 #endif
4193 break;
4194 case 3:
4195 secdesc = info->printers_3->secdesc;
4197 make_spoolss_printer_info_3 (mem_ctx, &q_u->info.info_3, info->printers_3);
4199 q_u->secdesc_ctr = (SEC_DESC_BUF*)malloc(sizeof(SEC_DESC_BUF));
4200 if (!q_u->secdesc_ctr)
4201 return False;
4202 q_u->secdesc_ctr->ptr = (secdesc != NULL) ? 1: 0;
4203 q_u->secdesc_ctr->max_len = (secdesc) ? sizeof(SEC_DESC) + (2*sizeof(uint32)) : 0;
4204 q_u->secdesc_ctr->len = (secdesc) ? sizeof(SEC_DESC) + (2*sizeof(uint32)) : 0;
4205 q_u->secdesc_ctr->sec = secdesc;
4207 break;
4208 case 7:
4209 make_spoolss_printer_info_7 (mem_ctx, &q_u->info.info_7, info->printers_7);
4210 break;
4212 default:
4213 DEBUG(0,("make_spoolss_q_setprinter: Unknown info level [%d]\n", level));
4214 break;
4218 q_u->command = command;
4220 return True;
4224 /*******************************************************************
4225 ********************************************************************/
4227 BOOL spoolss_io_r_setprinter(const char *desc, SPOOL_R_SETPRINTER *r_u, prs_struct *ps, int depth)
4229 prs_debug(ps, depth, desc, "spoolss_io_r_setprinter");
4230 depth++;
4232 if(!prs_align(ps))
4233 return False;
4235 if(!prs_werror("status", ps, depth, &r_u->status))
4236 return False;
4238 return True;
4241 /*******************************************************************
4242 Marshall/unmarshall a SPOOL_Q_SETPRINTER struct.
4243 ********************************************************************/
4245 BOOL spoolss_io_q_setprinter(const char *desc, SPOOL_Q_SETPRINTER *q_u, prs_struct *ps, int depth)
4247 uint32 ptr_sec_desc = 0;
4249 prs_debug(ps, depth, desc, "spoolss_io_q_setprinter");
4250 depth++;
4252 if(!prs_align(ps))
4253 return False;
4255 if(!smb_io_pol_hnd("printer handle", &q_u->handle ,ps, depth))
4256 return False;
4257 if(!prs_uint32("level", ps, depth, &q_u->level))
4258 return False;
4260 if(!spool_io_printer_info_level("", &q_u->info, ps, depth))
4261 return False;
4263 if (!spoolss_io_devmode_cont(desc, &q_u->devmode_ctr, ps, depth))
4264 return False;
4266 if(!prs_align(ps))
4267 return False;
4269 switch (q_u->level)
4271 case 2:
4273 ptr_sec_desc = q_u->info.info_2->secdesc_ptr;
4274 break;
4276 case 3:
4278 ptr_sec_desc = q_u->info.info_3->secdesc_ptr;
4279 break;
4282 if (ptr_sec_desc)
4284 if (!sec_io_desc_buf(desc, &q_u->secdesc_ctr, ps, depth))
4285 return False;
4286 } else {
4287 uint32 dummy = 0;
4289 /* Parse a NULL security descriptor. This should really
4290 happen inside the sec_io_desc_buf() function. */
4292 prs_debug(ps, depth, "", "sec_io_desc_buf");
4293 if (!prs_uint32("size", ps, depth + 1, &dummy))
4294 return False;
4295 if (!prs_uint32("ptr", ps, depth + 1, &dummy)) return
4296 False;
4299 if(!prs_uint32("command", ps, depth, &q_u->command))
4300 return False;
4302 return True;
4305 /*******************************************************************
4306 ********************************************************************/
4308 BOOL spoolss_io_r_fcpn(const char *desc, SPOOL_R_FCPN *r_u, prs_struct *ps, int depth)
4310 prs_debug(ps, depth, desc, "spoolss_io_r_fcpn");
4311 depth++;
4313 if(!prs_align(ps))
4314 return False;
4316 if(!prs_werror("status", ps, depth, &r_u->status))
4317 return False;
4319 return True;
4322 /*******************************************************************
4323 ********************************************************************/
4325 BOOL spoolss_io_q_fcpn(const char *desc, SPOOL_Q_FCPN *q_u, prs_struct *ps, int depth)
4328 prs_debug(ps, depth, desc, "spoolss_io_q_fcpn");
4329 depth++;
4331 if(!prs_align(ps))
4332 return False;
4334 if(!smb_io_pol_hnd("printer handle",&q_u->handle,ps,depth))
4335 return False;
4337 return True;
4341 /*******************************************************************
4342 ********************************************************************/
4344 BOOL spoolss_io_r_addjob(const char *desc, SPOOL_R_ADDJOB *r_u, prs_struct *ps, int depth)
4346 prs_debug(ps, depth, desc, "");
4347 depth++;
4349 if(!prs_align(ps))
4350 return False;
4352 if(!spoolss_io_buffer("", ps, depth, &r_u->buffer))
4353 return False;
4355 if(!prs_align(ps))
4356 return False;
4358 if(!prs_uint32("needed", ps, depth, &r_u->needed))
4359 return False;
4361 if(!prs_werror("status", ps, depth, &r_u->status))
4362 return False;
4364 return True;
4367 /*******************************************************************
4368 ********************************************************************/
4370 BOOL spoolss_io_q_addjob(const char *desc, SPOOL_Q_ADDJOB *q_u, prs_struct *ps, int depth)
4372 prs_debug(ps, depth, desc, "");
4373 depth++;
4375 if(!prs_align(ps))
4376 return False;
4378 if(!smb_io_pol_hnd("printer handle", &q_u->handle, ps, depth))
4379 return False;
4380 if(!prs_uint32("level", ps, depth, &q_u->level))
4381 return False;
4383 if(!spoolss_io_buffer("", ps, depth, &q_u->buffer))
4384 return False;
4386 if(!prs_align(ps))
4387 return False;
4389 if(!prs_uint32("offered", ps, depth, &q_u->offered))
4390 return False;
4392 return True;
4395 /*******************************************************************
4396 ********************************************************************/
4398 BOOL spoolss_io_r_enumjobs(const char *desc, SPOOL_R_ENUMJOBS *r_u, prs_struct *ps, int depth)
4400 prs_debug(ps, depth, desc, "spoolss_io_r_enumjobs");
4401 depth++;
4403 if (!prs_align(ps))
4404 return False;
4406 if (!spoolss_io_buffer("", ps, depth, &r_u->buffer))
4407 return False;
4409 if (!prs_align(ps))
4410 return False;
4412 if (!prs_uint32("needed", ps, depth, &r_u->needed))
4413 return False;
4415 if (!prs_uint32("returned", ps, depth, &r_u->returned))
4416 return False;
4418 if (!prs_werror("status", ps, depth, &r_u->status))
4419 return False;
4421 return True;
4424 /*******************************************************************
4425 ********************************************************************/
4427 BOOL make_spoolss_q_enumjobs(SPOOL_Q_ENUMJOBS *q_u, const POLICY_HND *hnd,
4428 uint32 firstjob,
4429 uint32 numofjobs,
4430 uint32 level,
4431 NEW_BUFFER *buffer,
4432 uint32 offered)
4434 if (q_u == NULL)
4436 return False;
4438 memcpy(&q_u->handle, hnd, sizeof(q_u->handle));
4439 q_u->firstjob = firstjob;
4440 q_u->numofjobs = numofjobs;
4441 q_u->level = level;
4442 q_u->buffer= buffer;
4443 q_u->offered = offered;
4444 return True;
4447 /*******************************************************************
4448 ********************************************************************/
4450 BOOL spoolss_io_q_enumjobs(const char *desc, SPOOL_Q_ENUMJOBS *q_u, prs_struct *ps, int depth)
4452 prs_debug(ps, depth, desc, "spoolss_io_q_enumjobs");
4453 depth++;
4455 if (!prs_align(ps))
4456 return False;
4458 if (!smb_io_pol_hnd("printer handle",&q_u->handle, ps, depth))
4459 return False;
4461 if (!prs_uint32("firstjob", ps, depth, &q_u->firstjob))
4462 return False;
4463 if (!prs_uint32("numofjobs", ps, depth, &q_u->numofjobs))
4464 return False;
4465 if (!prs_uint32("level", ps, depth, &q_u->level))
4466 return False;
4468 if (!spoolss_io_buffer("", ps, depth, &q_u->buffer))
4469 return False;
4471 if(!prs_align(ps))
4472 return False;
4474 if (!prs_uint32("offered", ps, depth, &q_u->offered))
4475 return False;
4477 return True;
4480 /*******************************************************************
4481 ********************************************************************/
4483 BOOL spoolss_io_r_schedulejob(const char *desc, SPOOL_R_SCHEDULEJOB *r_u, prs_struct *ps, int depth)
4485 prs_debug(ps, depth, desc, "spoolss_io_r_schedulejob");
4486 depth++;
4488 if(!prs_align(ps))
4489 return False;
4491 if(!prs_werror("status", ps, depth, &r_u->status))
4492 return False;
4494 return True;
4497 /*******************************************************************
4498 ********************************************************************/
4500 BOOL spoolss_io_q_schedulejob(const char *desc, SPOOL_Q_SCHEDULEJOB *q_u, prs_struct *ps, int depth)
4502 prs_debug(ps, depth, desc, "spoolss_io_q_schedulejob");
4503 depth++;
4505 if(!prs_align(ps))
4506 return False;
4508 if(!smb_io_pol_hnd("printer handle",&q_u->handle,ps,depth))
4509 return False;
4510 if(!prs_uint32("jobid", ps, depth, &q_u->jobid))
4511 return False;
4513 return True;
4516 /*******************************************************************
4517 ********************************************************************/
4519 BOOL spoolss_io_r_setjob(const char *desc, SPOOL_R_SETJOB *r_u, prs_struct *ps, int depth)
4521 prs_debug(ps, depth, desc, "spoolss_io_r_setjob");
4522 depth++;
4524 if(!prs_align(ps))
4525 return False;
4527 if(!prs_werror("status", ps, depth, &r_u->status))
4528 return False;
4530 return True;
4533 /*******************************************************************
4534 ********************************************************************/
4536 BOOL spoolss_io_q_setjob(const char *desc, SPOOL_Q_SETJOB *q_u, prs_struct *ps, int depth)
4538 prs_debug(ps, depth, desc, "spoolss_io_q_setjob");
4539 depth++;
4541 if(!prs_align(ps))
4542 return False;
4544 if(!smb_io_pol_hnd("printer handle",&q_u->handle,ps,depth))
4545 return False;
4546 if(!prs_uint32("jobid", ps, depth, &q_u->jobid))
4547 return False;
4549 * level is usually 0. If (level!=0) then I'm in trouble !
4550 * I will try to generate setjob command with level!=0, one day.
4552 if(!prs_uint32("level", ps, depth, &q_u->level))
4553 return False;
4554 if(!prs_uint32("command", ps, depth, &q_u->command))
4555 return False;
4557 return True;
4560 /*******************************************************************
4561 Parse a SPOOL_R_ENUMPRINTERDRIVERS structure.
4562 ********************************************************************/
4564 BOOL spoolss_io_r_enumprinterdrivers(const char *desc, SPOOL_R_ENUMPRINTERDRIVERS *r_u, prs_struct *ps, int depth)
4566 prs_debug(ps, depth, desc, "spoolss_io_r_enumprinterdrivers");
4567 depth++;
4569 if (!prs_align(ps))
4570 return False;
4572 if (!spoolss_io_buffer("", ps, depth, &r_u->buffer))
4573 return False;
4575 if (!prs_align(ps))
4576 return False;
4578 if (!prs_uint32("needed", ps, depth, &r_u->needed))
4579 return False;
4581 if (!prs_uint32("returned", ps, depth, &r_u->returned))
4582 return False;
4584 if (!prs_werror("status", ps, depth, &r_u->status))
4585 return False;
4587 return True;
4590 /*******************************************************************
4591 * init a structure.
4592 ********************************************************************/
4594 BOOL make_spoolss_q_enumprinterdrivers(SPOOL_Q_ENUMPRINTERDRIVERS *q_u,
4595 const char *name,
4596 const char *environment,
4597 uint32 level,
4598 NEW_BUFFER *buffer, uint32 offered)
4600 init_buf_unistr2(&q_u->name, &q_u->name_ptr, name);
4601 init_buf_unistr2(&q_u->environment, &q_u->environment_ptr, environment);
4603 q_u->level=level;
4604 q_u->buffer=buffer;
4605 q_u->offered=offered;
4607 return True;
4610 /*******************************************************************
4611 Parse a SPOOL_Q_ENUMPRINTERDRIVERS structure.
4612 ********************************************************************/
4614 BOOL spoolss_io_q_enumprinterdrivers(const char *desc, SPOOL_Q_ENUMPRINTERDRIVERS *q_u, prs_struct *ps, int depth)
4617 prs_debug(ps, depth, desc, "spoolss_io_q_enumprinterdrivers");
4618 depth++;
4620 if (!prs_align(ps))
4621 return False;
4623 if (!prs_uint32("name_ptr", ps, depth, &q_u->name_ptr))
4624 return False;
4625 if (!smb_io_unistr2("", &q_u->name, q_u->name_ptr,ps, depth))
4626 return False;
4628 if (!prs_align(ps))
4629 return False;
4630 if (!prs_uint32("environment_ptr", ps, depth, &q_u->environment_ptr))
4631 return False;
4632 if (!smb_io_unistr2("", &q_u->environment, q_u->environment_ptr, ps, depth))
4633 return False;
4635 if (!prs_align(ps))
4636 return False;
4637 if (!prs_uint32("level", ps, depth, &q_u->level))
4638 return False;
4640 if (!spoolss_io_buffer("", ps, depth, &q_u->buffer))
4641 return False;
4643 if (!prs_align(ps))
4644 return False;
4646 if (!prs_uint32("offered", ps, depth, &q_u->offered))
4647 return False;
4649 return True;
4652 /*******************************************************************
4653 ********************************************************************/
4655 BOOL spoolss_io_q_enumforms(const char *desc, SPOOL_Q_ENUMFORMS *q_u, prs_struct *ps, int depth)
4658 prs_debug(ps, depth, desc, "spoolss_io_q_enumforms");
4659 depth++;
4661 if (!prs_align(ps))
4662 return False;
4663 if (!smb_io_pol_hnd("printer handle",&q_u->handle,ps,depth))
4664 return False;
4665 if (!prs_uint32("level", ps, depth, &q_u->level))
4666 return False;
4668 if (!spoolss_io_buffer("", ps, depth, &q_u->buffer))
4669 return False;
4671 if (!prs_align(ps))
4672 return False;
4673 if (!prs_uint32("offered", ps, depth, &q_u->offered))
4674 return False;
4676 return True;
4679 /*******************************************************************
4680 ********************************************************************/
4682 BOOL spoolss_io_r_enumforms(const char *desc, SPOOL_R_ENUMFORMS *r_u, prs_struct *ps, int depth)
4684 prs_debug(ps, depth, desc, "spoolss_io_r_enumforms");
4685 depth++;
4687 if (!prs_align(ps))
4688 return False;
4690 if (!spoolss_io_buffer("", ps, depth, &r_u->buffer))
4691 return False;
4693 if (!prs_align(ps))
4694 return False;
4696 if (!prs_uint32("size of buffer needed", ps, depth, &r_u->needed))
4697 return False;
4699 if (!prs_uint32("numofforms", ps, depth, &r_u->numofforms))
4700 return False;
4702 if (!prs_werror("status", ps, depth, &r_u->status))
4703 return False;
4705 return True;
4708 /*******************************************************************
4709 ********************************************************************/
4711 BOOL spoolss_io_q_getform(const char *desc, SPOOL_Q_GETFORM *q_u, prs_struct *ps, int depth)
4714 prs_debug(ps, depth, desc, "spoolss_io_q_getform");
4715 depth++;
4717 if (!prs_align(ps))
4718 return False;
4719 if (!smb_io_pol_hnd("printer handle",&q_u->handle,ps,depth))
4720 return False;
4721 if (!smb_io_unistr2("", &q_u->formname,True,ps,depth))
4722 return False;
4724 if (!prs_align(ps))
4725 return False;
4727 if (!prs_uint32("level", ps, depth, &q_u->level))
4728 return False;
4730 if (!spoolss_io_buffer("", ps, depth, &q_u->buffer))
4731 return False;
4733 if (!prs_align(ps))
4734 return False;
4735 if (!prs_uint32("offered", ps, depth, &q_u->offered))
4736 return False;
4738 return True;
4741 /*******************************************************************
4742 ********************************************************************/
4744 BOOL spoolss_io_r_getform(const char *desc, SPOOL_R_GETFORM *r_u, prs_struct *ps, int depth)
4746 prs_debug(ps, depth, desc, "spoolss_io_r_getform");
4747 depth++;
4749 if (!prs_align(ps))
4750 return False;
4752 if (!spoolss_io_buffer("", ps, depth, &r_u->buffer))
4753 return False;
4755 if (!prs_align(ps))
4756 return False;
4758 if (!prs_uint32("size of buffer needed", ps, depth, &r_u->needed))
4759 return False;
4761 if (!prs_werror("status", ps, depth, &r_u->status))
4762 return False;
4764 return True;
4767 /*******************************************************************
4768 Parse a SPOOL_R_ENUMPORTS structure.
4769 ********************************************************************/
4771 BOOL spoolss_io_r_enumports(const char *desc, SPOOL_R_ENUMPORTS *r_u, prs_struct *ps, int depth)
4773 prs_debug(ps, depth, desc, "spoolss_io_r_enumports");
4774 depth++;
4776 if (!prs_align(ps))
4777 return False;
4779 if (!spoolss_io_buffer("", ps, depth, &r_u->buffer))
4780 return False;
4782 if (!prs_align(ps))
4783 return False;
4785 if (!prs_uint32("needed", ps, depth, &r_u->needed))
4786 return False;
4788 if (!prs_uint32("returned", ps, depth, &r_u->returned))
4789 return False;
4791 if (!prs_werror("status", ps, depth, &r_u->status))
4792 return False;
4794 return True;
4797 /*******************************************************************
4798 ********************************************************************/
4800 BOOL spoolss_io_q_enumports(const char *desc, SPOOL_Q_ENUMPORTS *q_u, prs_struct *ps, int depth)
4802 prs_debug(ps, depth, desc, "");
4803 depth++;
4805 if (!prs_align(ps))
4806 return False;
4808 if (!prs_uint32("", ps, depth, &q_u->name_ptr))
4809 return False;
4810 if (!smb_io_unistr2("", &q_u->name,True,ps,depth))
4811 return False;
4813 if (!prs_align(ps))
4814 return False;
4815 if (!prs_uint32("level", ps, depth, &q_u->level))
4816 return False;
4818 if (!spoolss_io_buffer("", ps, depth, &q_u->buffer))
4819 return False;
4821 if (!prs_align(ps))
4822 return False;
4823 if (!prs_uint32("offered", ps, depth, &q_u->offered))
4824 return False;
4826 return True;
4829 /*******************************************************************
4830 Parse a SPOOL_PRINTER_INFO_LEVEL_1 structure.
4831 ********************************************************************/
4833 BOOL spool_io_printer_info_level_1(const char *desc, SPOOL_PRINTER_INFO_LEVEL_1 *il, prs_struct *ps, int depth)
4835 prs_debug(ps, depth, desc, "spool_io_printer_info_level_1");
4836 depth++;
4838 if(!prs_align(ps))
4839 return False;
4841 if(!prs_uint32("flags", ps, depth, &il->flags))
4842 return False;
4843 if(!prs_uint32("description_ptr", ps, depth, &il->description_ptr))
4844 return False;
4845 if(!prs_uint32("name_ptr", ps, depth, &il->name_ptr))
4846 return False;
4847 if(!prs_uint32("comment_ptr", ps, depth, &il->comment_ptr))
4848 return False;
4850 if(!smb_io_unistr2("description", &il->description, il->description_ptr, ps, depth))
4851 return False;
4852 if(!smb_io_unistr2("name", &il->name, il->name_ptr, ps, depth))
4853 return False;
4854 if(!smb_io_unistr2("comment", &il->comment, il->comment_ptr, ps, depth))
4855 return False;
4857 return True;
4860 /*******************************************************************
4861 Parse a SPOOL_PRINTER_INFO_LEVEL_3 structure.
4862 ********************************************************************/
4864 BOOL spool_io_printer_info_level_3(const char *desc, SPOOL_PRINTER_INFO_LEVEL_3 *il, prs_struct *ps, int depth)
4866 prs_debug(ps, depth, desc, "spool_io_printer_info_level_3");
4867 depth++;
4869 if(!prs_align(ps))
4870 return False;
4872 if(!prs_uint32("secdesc_ptr", ps, depth, &il->secdesc_ptr))
4873 return False;
4875 return True;
4878 /*******************************************************************
4879 Parse a SPOOL_PRINTER_INFO_LEVEL_2 structure.
4880 ********************************************************************/
4882 BOOL spool_io_printer_info_level_2(const char *desc, SPOOL_PRINTER_INFO_LEVEL_2 *il, prs_struct *ps, int depth)
4884 prs_debug(ps, depth, desc, "spool_io_printer_info_level_2");
4885 depth++;
4887 if(!prs_align(ps))
4888 return False;
4890 if(!prs_uint32("servername_ptr", ps, depth, &il->servername_ptr))
4891 return False;
4892 if(!prs_uint32("printername_ptr", ps, depth, &il->printername_ptr))
4893 return False;
4894 if(!prs_uint32("sharename_ptr", ps, depth, &il->sharename_ptr))
4895 return False;
4896 if(!prs_uint32("portname_ptr", ps, depth, &il->portname_ptr))
4897 return False;
4899 if(!prs_uint32("drivername_ptr", ps, depth, &il->drivername_ptr))
4900 return False;
4901 if(!prs_uint32("comment_ptr", ps, depth, &il->comment_ptr))
4902 return False;
4903 if(!prs_uint32("location_ptr", ps, depth, &il->location_ptr))
4904 return False;
4905 if(!prs_uint32("devmode_ptr", ps, depth, &il->devmode_ptr))
4906 return False;
4907 if(!prs_uint32("sepfile_ptr", ps, depth, &il->sepfile_ptr))
4908 return False;
4909 if(!prs_uint32("printprocessor_ptr", ps, depth, &il->printprocessor_ptr))
4910 return False;
4911 if(!prs_uint32("datatype_ptr", ps, depth, &il->datatype_ptr))
4912 return False;
4913 if(!prs_uint32("parameters_ptr", ps, depth, &il->parameters_ptr))
4914 return False;
4915 if(!prs_uint32("secdesc_ptr", ps, depth, &il->secdesc_ptr))
4916 return False;
4918 if(!prs_uint32("attributes", ps, depth, &il->attributes))
4919 return False;
4920 if(!prs_uint32("priority", ps, depth, &il->priority))
4921 return False;
4922 if(!prs_uint32("default_priority", ps, depth, &il->default_priority))
4923 return False;
4924 if(!prs_uint32("starttime", ps, depth, &il->starttime))
4925 return False;
4926 if(!prs_uint32("untiltime", ps, depth, &il->untiltime))
4927 return False;
4928 if(!prs_uint32("status", ps, depth, &il->status))
4929 return False;
4930 if(!prs_uint32("cjobs", ps, depth, &il->cjobs))
4931 return False;
4932 if(!prs_uint32("averageppm", ps, depth, &il->averageppm))
4933 return False;
4935 if(!smb_io_unistr2("servername", &il->servername, il->servername_ptr, ps, depth))
4936 return False;
4937 if(!smb_io_unistr2("printername", &il->printername, il->printername_ptr, ps, depth))
4938 return False;
4939 if(!smb_io_unistr2("sharename", &il->sharename, il->sharename_ptr, ps, depth))
4940 return False;
4941 if(!smb_io_unistr2("portname", &il->portname, il->portname_ptr, ps, depth))
4942 return False;
4943 if(!smb_io_unistr2("drivername", &il->drivername, il->drivername_ptr, ps, depth))
4944 return False;
4945 if(!smb_io_unistr2("comment", &il->comment, il->comment_ptr, ps, depth))
4946 return False;
4947 if(!smb_io_unistr2("location", &il->location, il->location_ptr, ps, depth))
4948 return False;
4949 if(!smb_io_unistr2("sepfile", &il->sepfile, il->sepfile_ptr, ps, depth))
4950 return False;
4951 if(!smb_io_unistr2("printprocessor", &il->printprocessor, il->printprocessor_ptr, ps, depth))
4952 return False;
4953 if(!smb_io_unistr2("datatype", &il->datatype, il->datatype_ptr, ps, depth))
4954 return False;
4955 if(!smb_io_unistr2("parameters", &il->parameters, il->parameters_ptr, ps, depth))
4956 return False;
4958 return True;
4961 BOOL spool_io_printer_info_level_7(const char *desc, SPOOL_PRINTER_INFO_LEVEL_7 *il, prs_struct *ps, int depth)
4963 prs_debug(ps, depth, desc, "spool_io_printer_info_level_7");
4964 depth++;
4966 if(!prs_align(ps))
4967 return False;
4969 if(!prs_uint32("guid_ptr", ps, depth, &il->guid_ptr))
4970 return False;
4971 if(!prs_uint32("action", ps, depth, &il->action))
4972 return False;
4974 if(!smb_io_unistr2("servername", &il->guid, il->guid_ptr, ps, depth))
4975 return False;
4976 return True;
4979 /*******************************************************************
4980 ********************************************************************/
4982 BOOL spool_io_printer_info_level(const char *desc, SPOOL_PRINTER_INFO_LEVEL *il, prs_struct *ps, int depth)
4984 prs_debug(ps, depth, desc, "spool_io_printer_info_level");
4985 depth++;
4987 if(!prs_align(ps))
4988 return False;
4989 if(!prs_uint32("level", ps, depth, &il->level))
4990 return False;
4991 if(!prs_uint32("info_ptr", ps, depth, &il->info_ptr))
4992 return False;
4994 /* if no struct inside just return */
4995 if (il->info_ptr==0) {
4996 if (UNMARSHALLING(ps)) {
4997 il->info_1=NULL;
4998 il->info_2=NULL;
5000 return True;
5003 switch (il->level) {
5005 * level 0 is used by setprinter when managing the queue
5006 * (hold, stop, start a queue)
5008 case 0:
5009 break;
5010 /* DOCUMENT ME!!! What is level 1 used for? */
5011 case 1:
5013 if (UNMARSHALLING(ps)) {
5014 if ((il->info_1=(SPOOL_PRINTER_INFO_LEVEL_1 *)prs_alloc_mem(ps,sizeof(SPOOL_PRINTER_INFO_LEVEL_1))) == NULL)
5015 return False;
5017 if (!spool_io_printer_info_level_1("", il->info_1, ps, depth))
5018 return False;
5019 break;
5022 * level 2 is used by addprinter
5023 * and by setprinter when updating printer's info
5025 case 2:
5026 if (UNMARSHALLING(ps)) {
5027 if ((il->info_2=(SPOOL_PRINTER_INFO_LEVEL_2 *)prs_alloc_mem(ps,sizeof(SPOOL_PRINTER_INFO_LEVEL_2))) == NULL)
5028 return False;
5030 if (!spool_io_printer_info_level_2("", il->info_2, ps, depth))
5031 return False;
5032 break;
5033 /* DOCUMENT ME!!! What is level 3 used for? */
5034 case 3:
5036 if (UNMARSHALLING(ps)) {
5037 if ((il->info_3=(SPOOL_PRINTER_INFO_LEVEL_3 *)prs_alloc_mem(ps,sizeof(SPOOL_PRINTER_INFO_LEVEL_3))) == NULL)
5038 return False;
5040 if (!spool_io_printer_info_level_3("", il->info_3, ps, depth))
5041 return False;
5042 break;
5044 case 7:
5045 if (UNMARSHALLING(ps))
5046 if ((il->info_7=(SPOOL_PRINTER_INFO_LEVEL_7 *)prs_alloc_mem(ps,sizeof(SPOOL_PRINTER_INFO_LEVEL_7))) == NULL)
5047 return False;
5048 if (!spool_io_printer_info_level_7("", il->info_7, ps, depth))
5049 return False;
5050 break;
5053 return True;
5056 /*******************************************************************
5057 ********************************************************************/
5059 BOOL spoolss_io_q_addprinterex(const char *desc, SPOOL_Q_ADDPRINTEREX *q_u, prs_struct *ps, int depth)
5061 uint32 ptr_sec_desc = 0;
5063 prs_debug(ps, depth, desc, "spoolss_io_q_addprinterex");
5064 depth++;
5066 if(!prs_align(ps))
5067 return False;
5068 if(!prs_uint32("", ps, depth, &q_u->server_name_ptr))
5069 return False;
5070 if(!smb_io_unistr2("", &q_u->server_name, q_u->server_name_ptr, ps, depth))
5071 return False;
5073 if(!prs_align(ps))
5074 return False;
5076 if(!prs_uint32("info_level", ps, depth, &q_u->level))
5077 return False;
5079 if(!spool_io_printer_info_level("", &q_u->info, ps, depth))
5080 return False;
5082 if (!spoolss_io_devmode_cont(desc, &q_u->devmode_ctr, ps, depth))
5083 return False;
5085 if(!prs_align(ps))
5086 return False;
5088 switch (q_u->level) {
5089 case 2:
5090 ptr_sec_desc = q_u->info.info_2->secdesc_ptr;
5091 break;
5092 case 3:
5093 ptr_sec_desc = q_u->info.info_3->secdesc_ptr;
5094 break;
5096 if (ptr_sec_desc) {
5097 if (!sec_io_desc_buf(desc, &q_u->secdesc_ctr, ps, depth))
5098 return False;
5099 } else {
5100 uint32 dummy;
5102 /* Parse a NULL security descriptor. This should really
5103 happen inside the sec_io_desc_buf() function. */
5105 prs_debug(ps, depth, "", "sec_io_desc_buf");
5106 if (!prs_uint32("size", ps, depth + 1, &dummy))
5107 return False;
5108 if (!prs_uint32("ptr", ps, depth + 1, &dummy))
5109 return False;
5112 if(!prs_uint32("user_switch", ps, depth, &q_u->user_switch))
5113 return False;
5114 if(!spool_io_user_level("", &q_u->user_ctr, ps, depth))
5115 return False;
5117 return True;
5120 /*******************************************************************
5121 ********************************************************************/
5123 BOOL spoolss_io_r_addprinterex(const char *desc, SPOOL_R_ADDPRINTEREX *r_u,
5124 prs_struct *ps, int depth)
5126 prs_debug(ps, depth, desc, "spoolss_io_r_addprinterex");
5127 depth++;
5129 if(!smb_io_pol_hnd("printer handle",&r_u->handle,ps,depth))
5130 return False;
5132 if(!prs_werror("status", ps, depth, &r_u->status))
5133 return False;
5135 return True;
5138 /*******************************************************************
5139 ********************************************************************/
5141 BOOL spool_io_printer_driver_info_level_3(const char *desc, SPOOL_PRINTER_DRIVER_INFO_LEVEL_3 **q_u,
5142 prs_struct *ps, int depth)
5144 SPOOL_PRINTER_DRIVER_INFO_LEVEL_3 *il;
5146 prs_debug(ps, depth, desc, "spool_io_printer_driver_info_level_3");
5147 depth++;
5149 /* reading */
5150 if (UNMARSHALLING(ps)) {
5151 il=(SPOOL_PRINTER_DRIVER_INFO_LEVEL_3 *)prs_alloc_mem(ps,sizeof(SPOOL_PRINTER_DRIVER_INFO_LEVEL_3));
5152 if(il == NULL)
5153 return False;
5154 *q_u=il;
5156 else {
5157 il=*q_u;
5160 if(!prs_align(ps))
5161 return False;
5163 if(!prs_uint32("cversion", ps, depth, &il->cversion))
5164 return False;
5165 if(!prs_uint32("name", ps, depth, &il->name_ptr))
5166 return False;
5167 if(!prs_uint32("environment", ps, depth, &il->environment_ptr))
5168 return False;
5169 if(!prs_uint32("driverpath", ps, depth, &il->driverpath_ptr))
5170 return False;
5171 if(!prs_uint32("datafile", ps, depth, &il->datafile_ptr))
5172 return False;
5173 if(!prs_uint32("configfile", ps, depth, &il->configfile_ptr))
5174 return False;
5175 if(!prs_uint32("helpfile", ps, depth, &il->helpfile_ptr))
5176 return False;
5177 if(!prs_uint32("monitorname", ps, depth, &il->monitorname_ptr))
5178 return False;
5179 if(!prs_uint32("defaultdatatype", ps, depth, &il->defaultdatatype_ptr))
5180 return False;
5181 if(!prs_uint32("dependentfilessize", ps, depth, &il->dependentfilessize))
5182 return False;
5183 if(!prs_uint32("dependentfiles", ps, depth, &il->dependentfiles_ptr))
5184 return False;
5186 if(!prs_align(ps))
5187 return False;
5189 if(!smb_io_unistr2("name", &il->name, il->name_ptr, ps, depth))
5190 return False;
5191 if(!smb_io_unistr2("environment", &il->environment, il->environment_ptr, ps, depth))
5192 return False;
5193 if(!smb_io_unistr2("driverpath", &il->driverpath, il->driverpath_ptr, ps, depth))
5194 return False;
5195 if(!smb_io_unistr2("datafile", &il->datafile, il->datafile_ptr, ps, depth))
5196 return False;
5197 if(!smb_io_unistr2("configfile", &il->configfile, il->configfile_ptr, ps, depth))
5198 return False;
5199 if(!smb_io_unistr2("helpfile", &il->helpfile, il->helpfile_ptr, ps, depth))
5200 return False;
5201 if(!smb_io_unistr2("monitorname", &il->monitorname, il->monitorname_ptr, ps, depth))
5202 return False;
5203 if(!smb_io_unistr2("defaultdatatype", &il->defaultdatatype, il->defaultdatatype_ptr, ps, depth))
5204 return False;
5206 if(!prs_align(ps))
5207 return False;
5209 if (il->dependentfiles_ptr)
5210 smb_io_buffer5("", &il->dependentfiles, ps, depth);
5212 return True;
5215 /*******************************************************************
5216 parse a SPOOL_PRINTER_DRIVER_INFO_LEVEL_6 structure
5217 ********************************************************************/
5219 BOOL spool_io_printer_driver_info_level_6(const char *desc, SPOOL_PRINTER_DRIVER_INFO_LEVEL_6 **q_u,
5220 prs_struct *ps, int depth)
5222 SPOOL_PRINTER_DRIVER_INFO_LEVEL_6 *il;
5224 prs_debug(ps, depth, desc, "spool_io_printer_driver_info_level_6");
5225 depth++;
5227 /* reading */
5228 if (UNMARSHALLING(ps)) {
5229 il=(SPOOL_PRINTER_DRIVER_INFO_LEVEL_6 *)prs_alloc_mem(ps,sizeof(SPOOL_PRINTER_DRIVER_INFO_LEVEL_6));
5230 if(il == NULL)
5231 return False;
5232 *q_u=il;
5234 else {
5235 il=*q_u;
5238 if(!prs_align(ps))
5239 return False;
5242 * I know this seems weird, but I have no other explanation.
5243 * This is observed behavior on both NT4 and 2K servers.
5244 * --jerry
5247 if (!prs_align_uint64(ps))
5248 return False;
5250 /* parse the main elements the packet */
5252 if(!prs_uint32("cversion ", ps, depth, &il->version))
5253 return False;
5254 if(!prs_uint32("name ", ps, depth, &il->name_ptr))
5255 return False;
5256 if(!prs_uint32("environment ", ps, depth, &il->environment_ptr))
5257 return False;
5258 if(!prs_uint32("driverpath ", ps, depth, &il->driverpath_ptr))
5259 return False;
5260 if(!prs_uint32("datafile ", ps, depth, &il->datafile_ptr))
5261 return False;
5262 if(!prs_uint32("configfile ", ps, depth, &il->configfile_ptr))
5263 return False;
5264 if(!prs_uint32("helpfile ", ps, depth, &il->helpfile_ptr))
5265 return False;
5266 if(!prs_uint32("monitorname ", ps, depth, &il->monitorname_ptr))
5267 return False;
5268 if(!prs_uint32("defaultdatatype", ps, depth, &il->defaultdatatype_ptr))
5269 return False;
5270 if(!prs_uint32("dependentfiles ", ps, depth, &il->dependentfiles_len))
5271 return False;
5272 if(!prs_uint32("dependentfiles ", ps, depth, &il->dependentfiles_ptr))
5273 return False;
5274 if(!prs_uint32("previousnames ", ps, depth, &il->previousnames_len))
5275 return False;
5276 if(!prs_uint32("previousnames ", ps, depth, &il->previousnames_ptr))
5277 return False;
5278 if(!smb_io_time("driverdate ", &il->driverdate, ps, depth))
5279 return False;
5280 if(!prs_uint32("dummy4 ", ps, depth, &il->dummy4))
5281 return False;
5282 if(!prs_uint64("driverversion ", ps, depth, &il->driverversion))
5283 return False;
5284 if(!prs_uint32("mfgname ", ps, depth, &il->mfgname_ptr))
5285 return False;
5286 if(!prs_uint32("oemurl ", ps, depth, &il->oemurl_ptr))
5287 return False;
5288 if(!prs_uint32("hardwareid ", ps, depth, &il->hardwareid_ptr))
5289 return False;
5290 if(!prs_uint32("provider ", ps, depth, &il->provider_ptr))
5291 return False;
5293 /* parse the structures in the packet */
5295 if(!smb_io_unistr2("name", &il->name, il->name_ptr, ps, depth))
5296 return False;
5297 if(!prs_align(ps))
5298 return False;
5300 if(!smb_io_unistr2("environment", &il->environment, il->environment_ptr, ps, depth))
5301 return False;
5302 if(!prs_align(ps))
5303 return False;
5305 if(!smb_io_unistr2("driverpath", &il->driverpath, il->driverpath_ptr, ps, depth))
5306 return False;
5307 if(!prs_align(ps))
5308 return False;
5310 if(!smb_io_unistr2("datafile", &il->datafile, il->datafile_ptr, ps, depth))
5311 return False;
5312 if(!prs_align(ps))
5313 return False;
5315 if(!smb_io_unistr2("configfile", &il->configfile, il->configfile_ptr, ps, depth))
5316 return False;
5317 if(!prs_align(ps))
5318 return False;
5320 if(!smb_io_unistr2("helpfile", &il->helpfile, il->helpfile_ptr, ps, depth))
5321 return False;
5322 if(!prs_align(ps))
5323 return False;
5325 if(!smb_io_unistr2("monitorname", &il->monitorname, il->monitorname_ptr, ps, depth))
5326 return False;
5327 if(!prs_align(ps))
5328 return False;
5330 if(!smb_io_unistr2("defaultdatatype", &il->defaultdatatype, il->defaultdatatype_ptr, ps, depth))
5331 return False;
5332 if(!prs_align(ps))
5333 return False;
5334 if (il->dependentfiles_ptr) {
5335 if(!smb_io_buffer5("dependentfiles", &il->dependentfiles, ps, depth))
5336 return False;
5337 if(!prs_align(ps))
5338 return False;
5340 if (il->previousnames_ptr) {
5341 if(!smb_io_buffer5("previousnames", &il->previousnames, ps, depth))
5342 return False;
5343 if(!prs_align(ps))
5344 return False;
5346 if(!smb_io_unistr2("mfgname", &il->mfgname, il->mfgname_ptr, ps, depth))
5347 return False;
5348 if(!prs_align(ps))
5349 return False;
5350 if(!smb_io_unistr2("oemurl", &il->oemurl, il->oemurl_ptr, ps, depth))
5351 return False;
5352 if(!prs_align(ps))
5353 return False;
5354 if(!smb_io_unistr2("hardwareid", &il->hardwareid, il->hardwareid_ptr, ps, depth))
5355 return False;
5356 if(!prs_align(ps))
5357 return False;
5358 if(!smb_io_unistr2("provider", &il->provider, il->provider_ptr, ps, depth))
5359 return False;
5361 return True;
5364 /*******************************************************************
5365 convert a buffer of UNICODE strings null terminated
5366 the buffer is terminated by a NULL
5368 convert to an dos codepage array (null terminated)
5370 dynamically allocate memory
5372 ********************************************************************/
5373 static BOOL uniarray_2_dosarray(BUFFER5 *buf5, fstring **ar)
5375 fstring f, *tar;
5376 int n = 0;
5377 char *src;
5379 if (buf5==NULL)
5380 return False;
5382 src = (char *)buf5->buffer;
5383 *ar = NULL;
5385 while (src < ((char *)buf5->buffer) + buf5->buf_len*2) {
5386 rpcstr_pull(f, src, sizeof(f)-1, -1, STR_TERMINATE);
5387 src = skip_unibuf(src, 2*buf5->buf_len - PTR_DIFF(src,buf5->buffer));
5388 tar = (fstring *)Realloc(*ar, sizeof(fstring)*(n+2));
5389 if (!tar)
5390 return False;
5391 else
5392 *ar = tar;
5393 fstrcpy((*ar)[n], f);
5394 n++;
5396 fstrcpy((*ar)[n], "");
5398 return True;
5404 /*******************************************************************
5405 read a UNICODE array with null terminated strings
5406 and null terminated array
5407 and size of array at beginning
5408 ********************************************************************/
5410 BOOL smb_io_unibuffer(const char *desc, UNISTR2 *buffer, prs_struct *ps, int depth)
5412 if (buffer==NULL) return False;
5414 buffer->offset=0;
5415 buffer->uni_str_len=buffer->uni_max_len;
5417 if(!prs_uint32("buffer_size", ps, depth, &buffer->uni_max_len))
5418 return False;
5420 if(!prs_unistr2(True, "buffer ", ps, depth, buffer))
5421 return False;
5423 return True;
5426 /*******************************************************************
5427 ********************************************************************/
5429 BOOL spool_io_printer_driver_info_level(const char *desc, SPOOL_PRINTER_DRIVER_INFO_LEVEL *il, prs_struct *ps, int depth)
5431 prs_debug(ps, depth, desc, "spool_io_printer_driver_info_level");
5432 depth++;
5434 if(!prs_align(ps))
5435 return False;
5436 if(!prs_uint32("level", ps, depth, &il->level))
5437 return False;
5438 if(!prs_uint32("ptr", ps, depth, &il->ptr))
5439 return False;
5441 if (il->ptr==0)
5442 return True;
5444 switch (il->level) {
5445 case 3:
5446 if(!spool_io_printer_driver_info_level_3("", &il->info_3, ps, depth))
5447 return False;
5448 break;
5449 case 6:
5450 if(!spool_io_printer_driver_info_level_6("", &il->info_6, ps, depth))
5451 return False;
5452 break;
5453 default:
5454 return False;
5457 return True;
5460 /*******************************************************************
5461 init a SPOOL_Q_ADDPRINTERDRIVER struct
5462 ******************************************************************/
5464 BOOL make_spoolss_q_addprinterdriver(TALLOC_CTX *mem_ctx,
5465 SPOOL_Q_ADDPRINTERDRIVER *q_u, const char* srv_name,
5466 uint32 level, PRINTER_DRIVER_CTR *info)
5468 DEBUG(5,("make_spoolss_q_addprinterdriver\n"));
5470 q_u->server_name_ptr = (srv_name!=NULL)?1:0;
5471 init_unistr2(&q_u->server_name, srv_name, UNI_STR_TERMINATE);
5473 q_u->level = level;
5475 q_u->info.level = level;
5476 q_u->info.ptr = (info!=NULL)?1:0;
5477 switch (level)
5479 /* info level 3 is supported by Windows 95/98, WinNT and Win2k */
5480 case 3 :
5481 make_spoolss_driver_info_3(mem_ctx, &q_u->info.info_3, info->info3);
5482 break;
5484 default:
5485 DEBUG(0,("make_spoolss_q_addprinterdriver: Unknown info level [%d]\n", level));
5486 break;
5489 return True;
5492 BOOL make_spoolss_driver_info_3(TALLOC_CTX *mem_ctx,
5493 SPOOL_PRINTER_DRIVER_INFO_LEVEL_3 **spool_drv_info,
5494 DRIVER_INFO_3 *info3)
5496 uint32 len = 0;
5497 uint16 *ptr = info3->dependentfiles;
5498 BOOL done = False;
5499 BOOL null_char = False;
5500 SPOOL_PRINTER_DRIVER_INFO_LEVEL_3 *inf;
5502 if (!(inf=(SPOOL_PRINTER_DRIVER_INFO_LEVEL_3*)talloc_zero(mem_ctx, sizeof(SPOOL_PRINTER_DRIVER_INFO_LEVEL_3))))
5503 return False;
5505 inf->cversion = info3->version;
5506 inf->name_ptr = (info3->name.buffer!=NULL)?1:0;
5507 inf->environment_ptr = (info3->architecture.buffer!=NULL)?1:0;
5508 inf->driverpath_ptr = (info3->driverpath.buffer!=NULL)?1:0;
5509 inf->datafile_ptr = (info3->datafile.buffer!=NULL)?1:0;
5510 inf->configfile_ptr = (info3->configfile.buffer!=NULL)?1:0;
5511 inf->helpfile_ptr = (info3->helpfile.buffer!=NULL)?1:0;
5512 inf->monitorname_ptr = (info3->monitorname.buffer!=NULL)?1:0;
5513 inf->defaultdatatype_ptr = (info3->defaultdatatype.buffer!=NULL)?1:0;
5515 init_unistr2_from_unistr(&inf->name, &info3->name);
5516 init_unistr2_from_unistr(&inf->environment, &info3->architecture);
5517 init_unistr2_from_unistr(&inf->driverpath, &info3->driverpath);
5518 init_unistr2_from_unistr(&inf->datafile, &info3->datafile);
5519 init_unistr2_from_unistr(&inf->configfile, &info3->configfile);
5520 init_unistr2_from_unistr(&inf->helpfile, &info3->helpfile);
5521 init_unistr2_from_unistr(&inf->monitorname, &info3->monitorname);
5522 init_unistr2_from_unistr(&inf->defaultdatatype, &info3->defaultdatatype);
5524 while (!done)
5526 switch (*ptr)
5528 case 0:
5529 /* the null_char BOOL is used to help locate
5530 two '\0's back to back */
5531 if (null_char)
5532 done = True;
5533 else
5534 null_char = True;
5535 break;
5537 default:
5538 null_char = False;
5540 break;
5542 len++;
5543 ptr++;
5545 inf->dependentfiles_ptr = (info3->dependentfiles != NULL) ? 1 : 0;
5546 inf->dependentfilessize = len;
5547 if(!make_spoolss_buffer5(mem_ctx, &inf->dependentfiles, len, info3->dependentfiles))
5549 SAFE_FREE(inf);
5550 return False;
5553 *spool_drv_info = inf;
5555 return True;
5558 /*******************************************************************
5559 make a BUFFER5 struct from a uint16*
5560 ******************************************************************/
5561 BOOL make_spoolss_buffer5(TALLOC_CTX *mem_ctx, BUFFER5 *buf5, uint32 len, uint16 *src)
5564 buf5->buf_len = len;
5565 if((buf5->buffer=(uint16*)talloc_memdup(mem_ctx, src, sizeof(uint16)*len)) == NULL)
5567 DEBUG(0,("make_spoolss_buffer5: Unable to malloc memory for buffer!\n"));
5568 return False;
5571 return True;
5574 /*******************************************************************
5575 fill in the prs_struct for a ADDPRINTERDRIVER request PDU
5576 ********************************************************************/
5578 BOOL spoolss_io_q_addprinterdriver(const char *desc, SPOOL_Q_ADDPRINTERDRIVER *q_u, prs_struct *ps, int depth)
5580 prs_debug(ps, depth, desc, "spoolss_io_q_addprinterdriver");
5581 depth++;
5583 if(!prs_align(ps))
5584 return False;
5586 if(!prs_uint32("server_name_ptr", ps, depth, &q_u->server_name_ptr))
5587 return False;
5588 if(!smb_io_unistr2("server_name", &q_u->server_name, q_u->server_name_ptr, ps, depth))
5589 return False;
5591 if(!prs_align(ps))
5592 return False;
5593 if(!prs_uint32("info_level", ps, depth, &q_u->level))
5594 return False;
5596 if(!spool_io_printer_driver_info_level("", &q_u->info, ps, depth))
5597 return False;
5599 return True;
5602 /*******************************************************************
5603 ********************************************************************/
5605 BOOL spoolss_io_r_addprinterdriver(const char *desc, SPOOL_R_ADDPRINTERDRIVER *q_u, prs_struct *ps, int depth)
5607 prs_debug(ps, depth, desc, "spoolss_io_r_addprinterdriver");
5608 depth++;
5610 if(!prs_werror("status", ps, depth, &q_u->status))
5611 return False;
5613 return True;
5616 /*******************************************************************
5617 fill in the prs_struct for a ADDPRINTERDRIVER request PDU
5618 ********************************************************************/
5620 BOOL spoolss_io_q_addprinterdriverex(const char *desc, SPOOL_Q_ADDPRINTERDRIVEREX *q_u, prs_struct *ps, int depth)
5622 prs_debug(ps, depth, desc, "spoolss_io_q_addprinterdriverex");
5623 depth++;
5625 if(!prs_align(ps))
5626 return False;
5628 if(!prs_uint32("server_name_ptr", ps, depth, &q_u->server_name_ptr))
5629 return False;
5630 if(!smb_io_unistr2("server_name", &q_u->server_name, q_u->server_name_ptr, ps, depth))
5631 return False;
5633 if(!prs_align(ps))
5634 return False;
5635 if(!prs_uint32("info_level", ps, depth, &q_u->level))
5636 return False;
5638 if(!spool_io_printer_driver_info_level("", &q_u->info, ps, depth))
5639 return False;
5641 if(!prs_align(ps))
5642 return False;
5643 if(!prs_uint32("copy flags", ps, depth, &q_u->copy_flags))
5644 return False;
5646 return True;
5649 /*******************************************************************
5650 ********************************************************************/
5652 BOOL spoolss_io_r_addprinterdriverex(const char *desc, SPOOL_R_ADDPRINTERDRIVEREX *q_u, prs_struct *ps, int depth)
5654 prs_debug(ps, depth, desc, "spoolss_io_r_addprinterdriverex");
5655 depth++;
5657 if(!prs_werror("status", ps, depth, &q_u->status))
5658 return False;
5660 return True;
5663 /*******************************************************************
5664 ********************************************************************/
5666 BOOL uni_2_asc_printer_driver_3(SPOOL_PRINTER_DRIVER_INFO_LEVEL_3 *uni,
5667 NT_PRINTER_DRIVER_INFO_LEVEL_3 **asc)
5669 NT_PRINTER_DRIVER_INFO_LEVEL_3 *d;
5671 DEBUG(7,("uni_2_asc_printer_driver_3: Converting from UNICODE to ASCII\n"));
5673 if (*asc==NULL)
5675 *asc=(NT_PRINTER_DRIVER_INFO_LEVEL_3 *)malloc(sizeof(NT_PRINTER_DRIVER_INFO_LEVEL_3));
5676 if(*asc == NULL)
5677 return False;
5678 ZERO_STRUCTP(*asc);
5681 d=*asc;
5683 d->cversion=uni->cversion;
5685 unistr2_to_ascii(d->name, &uni->name, sizeof(d->name)-1);
5686 unistr2_to_ascii(d->environment, &uni->environment, sizeof(d->environment)-1);
5687 unistr2_to_ascii(d->driverpath, &uni->driverpath, sizeof(d->driverpath)-1);
5688 unistr2_to_ascii(d->datafile, &uni->datafile, sizeof(d->datafile)-1);
5689 unistr2_to_ascii(d->configfile, &uni->configfile, sizeof(d->configfile)-1);
5690 unistr2_to_ascii(d->helpfile, &uni->helpfile, sizeof(d->helpfile)-1);
5691 unistr2_to_ascii(d->monitorname, &uni->monitorname, sizeof(d->monitorname)-1);
5692 unistr2_to_ascii(d->defaultdatatype, &uni->defaultdatatype, sizeof(d->defaultdatatype)-1);
5694 DEBUGADD(8,( "version: %d\n", d->cversion));
5695 DEBUGADD(8,( "name: %s\n", d->name));
5696 DEBUGADD(8,( "environment: %s\n", d->environment));
5697 DEBUGADD(8,( "driverpath: %s\n", d->driverpath));
5698 DEBUGADD(8,( "datafile: %s\n", d->datafile));
5699 DEBUGADD(8,( "configfile: %s\n", d->configfile));
5700 DEBUGADD(8,( "helpfile: %s\n", d->helpfile));
5701 DEBUGADD(8,( "monitorname: %s\n", d->monitorname));
5702 DEBUGADD(8,( "defaultdatatype: %s\n", d->defaultdatatype));
5704 if (uniarray_2_dosarray(&uni->dependentfiles, &d->dependentfiles ))
5705 return True;
5707 SAFE_FREE(*asc);
5708 return False;
5711 /*******************************************************************
5712 ********************************************************************/
5713 BOOL uni_2_asc_printer_driver_6(SPOOL_PRINTER_DRIVER_INFO_LEVEL_6 *uni,
5714 NT_PRINTER_DRIVER_INFO_LEVEL_6 **asc)
5716 NT_PRINTER_DRIVER_INFO_LEVEL_6 *d;
5718 DEBUG(7,("uni_2_asc_printer_driver_6: Converting from UNICODE to ASCII\n"));
5720 if (*asc==NULL)
5722 *asc=(NT_PRINTER_DRIVER_INFO_LEVEL_6 *)malloc(sizeof(NT_PRINTER_DRIVER_INFO_LEVEL_6));
5723 if(*asc == NULL)
5724 return False;
5725 ZERO_STRUCTP(*asc);
5728 d=*asc;
5730 d->version=uni->version;
5732 unistr2_to_ascii(d->name, &uni->name, sizeof(d->name)-1);
5733 unistr2_to_ascii(d->environment, &uni->environment, sizeof(d->environment)-1);
5734 unistr2_to_ascii(d->driverpath, &uni->driverpath, sizeof(d->driverpath)-1);
5735 unistr2_to_ascii(d->datafile, &uni->datafile, sizeof(d->datafile)-1);
5736 unistr2_to_ascii(d->configfile, &uni->configfile, sizeof(d->configfile)-1);
5737 unistr2_to_ascii(d->helpfile, &uni->helpfile, sizeof(d->helpfile)-1);
5738 unistr2_to_ascii(d->monitorname, &uni->monitorname, sizeof(d->monitorname)-1);
5739 unistr2_to_ascii(d->defaultdatatype, &uni->defaultdatatype, sizeof(d->defaultdatatype)-1);
5741 DEBUGADD(8,( "version: %d\n", d->version));
5742 DEBUGADD(8,( "name: %s\n", d->name));
5743 DEBUGADD(8,( "environment: %s\n", d->environment));
5744 DEBUGADD(8,( "driverpath: %s\n", d->driverpath));
5745 DEBUGADD(8,( "datafile: %s\n", d->datafile));
5746 DEBUGADD(8,( "configfile: %s\n", d->configfile));
5747 DEBUGADD(8,( "helpfile: %s\n", d->helpfile));
5748 DEBUGADD(8,( "monitorname: %s\n", d->monitorname));
5749 DEBUGADD(8,( "defaultdatatype: %s\n", d->defaultdatatype));
5751 if (!uniarray_2_dosarray(&uni->dependentfiles, &d->dependentfiles ))
5752 goto error;
5753 if (!uniarray_2_dosarray(&uni->previousnames, &d->previousnames ))
5754 goto error;
5756 return True;
5758 error:
5759 SAFE_FREE(*asc);
5760 return False;
5763 BOOL uni_2_asc_printer_info_2(const SPOOL_PRINTER_INFO_LEVEL_2 *uni,
5764 NT_PRINTER_INFO_LEVEL_2 **asc)
5766 NT_PRINTER_INFO_LEVEL_2 *d;
5767 time_t time_unix;
5769 DEBUG(7,("Converting from UNICODE to ASCII\n"));
5770 time_unix=time(NULL);
5772 if (*asc==NULL) {
5773 DEBUGADD(8,("allocating memory\n"));
5775 *asc=(NT_PRINTER_INFO_LEVEL_2 *)malloc(sizeof(NT_PRINTER_INFO_LEVEL_2));
5776 if(*asc == NULL)
5777 return False;
5778 ZERO_STRUCTP(*asc);
5780 /* we allocate memory iff called from
5781 * addprinter(ex) so we can do one time stuff here.
5783 (*asc)->setuptime=time_unix;
5786 DEBUGADD(8,("start converting\n"));
5788 d=*asc;
5790 d->attributes=uni->attributes;
5791 d->priority=uni->priority;
5792 d->default_priority=uni->default_priority;
5793 d->starttime=uni->starttime;
5794 d->untiltime=uni->untiltime;
5795 d->status=uni->status;
5796 d->cjobs=uni->cjobs;
5798 unistr2_to_ascii(d->servername, &uni->servername, sizeof(d->servername)-1);
5799 unistr2_to_ascii(d->printername, &uni->printername, sizeof(d->printername)-1);
5800 unistr2_to_ascii(d->sharename, &uni->sharename, sizeof(d->sharename)-1);
5801 unistr2_to_ascii(d->portname, &uni->portname, sizeof(d->portname)-1);
5802 unistr2_to_ascii(d->drivername, &uni->drivername, sizeof(d->drivername)-1);
5803 unistr2_to_ascii(d->comment, &uni->comment, sizeof(d->comment)-1);
5804 unistr2_to_ascii(d->location, &uni->location, sizeof(d->location)-1);
5805 unistr2_to_ascii(d->sepfile, &uni->sepfile, sizeof(d->sepfile)-1);
5806 unistr2_to_ascii(d->printprocessor, &uni->printprocessor, sizeof(d->printprocessor)-1);
5807 unistr2_to_ascii(d->datatype, &uni->datatype, sizeof(d->datatype)-1);
5808 unistr2_to_ascii(d->parameters, &uni->parameters, sizeof(d->parameters)-1);
5810 return True;
5813 /*******************************************************************
5814 * init a structure.
5815 ********************************************************************/
5817 BOOL make_spoolss_q_getprinterdriverdir(SPOOL_Q_GETPRINTERDRIVERDIR *q_u,
5818 fstring servername, fstring env_name, uint32 level,
5819 NEW_BUFFER *buffer, uint32 offered)
5821 init_buf_unistr2(&q_u->name, &q_u->name_ptr, servername);
5822 init_buf_unistr2(&q_u->environment, &q_u->environment_ptr, env_name);
5824 q_u->level=level;
5825 q_u->buffer=buffer;
5826 q_u->offered=offered;
5828 return True;
5831 /*******************************************************************
5832 Parse a SPOOL_Q_GETPRINTERDRIVERDIR structure.
5833 ********************************************************************/
5835 BOOL spoolss_io_q_getprinterdriverdir(const char *desc, SPOOL_Q_GETPRINTERDRIVERDIR *q_u, prs_struct *ps, int depth)
5837 prs_debug(ps, depth, desc, "spoolss_io_q_getprinterdriverdir");
5838 depth++;
5840 if(!prs_align(ps))
5841 return False;
5842 if(!prs_uint32("name_ptr", ps, depth, &q_u->name_ptr))
5843 return False;
5844 if(!smb_io_unistr2("", &q_u->name, q_u->name_ptr, ps, depth))
5845 return False;
5847 if(!prs_align(ps))
5848 return False;
5850 if(!prs_uint32("", ps, depth, &q_u->environment_ptr))
5851 return False;
5852 if(!smb_io_unistr2("", &q_u->environment, q_u->environment_ptr, ps, depth))
5853 return False;
5855 if(!prs_align(ps))
5856 return False;
5858 if(!prs_uint32("level", ps, depth, &q_u->level))
5859 return False;
5861 if(!spoolss_io_buffer("", ps, depth, &q_u->buffer))
5862 return False;
5864 if(!prs_align(ps))
5865 return False;
5867 if(!prs_uint32("offered", ps, depth, &q_u->offered))
5868 return False;
5870 return True;
5873 /*******************************************************************
5874 Parse a SPOOL_R_GETPRINTERDRIVERDIR structure.
5875 ********************************************************************/
5877 BOOL spoolss_io_r_getprinterdriverdir(const char *desc, SPOOL_R_GETPRINTERDRIVERDIR *r_u, prs_struct *ps, int depth)
5879 prs_debug(ps, depth, desc, "spoolss_io_r_getprinterdriverdir");
5880 depth++;
5882 if (!prs_align(ps))
5883 return False;
5885 if (!spoolss_io_buffer("", ps, depth, &r_u->buffer))
5886 return False;
5888 if (!prs_align(ps))
5889 return False;
5891 if (!prs_uint32("needed", ps, depth, &r_u->needed))
5892 return False;
5894 if (!prs_werror("status", ps, depth, &r_u->status))
5895 return False;
5897 return True;
5900 /*******************************************************************
5901 ********************************************************************/
5903 BOOL spoolss_io_r_enumprintprocessors(const char *desc, SPOOL_R_ENUMPRINTPROCESSORS *r_u, prs_struct *ps, int depth)
5905 prs_debug(ps, depth, desc, "spoolss_io_r_enumprintprocessors");
5906 depth++;
5908 if (!prs_align(ps))
5909 return False;
5911 if (!spoolss_io_buffer("", ps, depth, &r_u->buffer))
5912 return False;
5914 if (!prs_align(ps))
5915 return False;
5917 if (!prs_uint32("needed", ps, depth, &r_u->needed))
5918 return False;
5920 if (!prs_uint32("returned", ps, depth, &r_u->returned))
5921 return False;
5923 if (!prs_werror("status", ps, depth, &r_u->status))
5924 return False;
5926 return True;
5929 /*******************************************************************
5930 ********************************************************************/
5932 BOOL spoolss_io_q_enumprintprocessors(const char *desc, SPOOL_Q_ENUMPRINTPROCESSORS *q_u, prs_struct *ps, int depth)
5934 prs_debug(ps, depth, desc, "spoolss_io_q_enumprintprocessors");
5935 depth++;
5937 if (!prs_align(ps))
5938 return False;
5940 if (!prs_uint32("name_ptr", ps, depth, &q_u->name_ptr))
5941 return False;
5942 if (!smb_io_unistr2("name", &q_u->name, True, ps, depth))
5943 return False;
5945 if (!prs_align(ps))
5946 return False;
5948 if (!prs_uint32("", ps, depth, &q_u->environment_ptr))
5949 return False;
5950 if (!smb_io_unistr2("", &q_u->environment, q_u->environment_ptr, ps, depth))
5951 return False;
5953 if (!prs_align(ps))
5954 return False;
5956 if (!prs_uint32("level", ps, depth, &q_u->level))
5957 return False;
5959 if(!spoolss_io_buffer("", ps, depth, &q_u->buffer))
5960 return False;
5962 if (!prs_align(ps))
5963 return False;
5965 if (!prs_uint32("offered", ps, depth, &q_u->offered))
5966 return False;
5968 return True;
5971 /*******************************************************************
5972 ********************************************************************/
5974 BOOL spoolss_io_q_addprintprocessor(const char *desc, SPOOL_Q_ADDPRINTPROCESSOR *q_u, prs_struct *ps, int depth)
5976 prs_debug(ps, depth, desc, "spoolss_io_q_addprintprocessor");
5977 depth++;
5979 if (!prs_align(ps))
5980 return False;
5982 if (!prs_uint32("server_ptr", ps, depth, &q_u->server_ptr))
5983 return False;
5984 if (!smb_io_unistr2("server", &q_u->server, q_u->server_ptr, ps, depth))
5985 return False;
5987 if (!prs_align(ps))
5988 return False;
5989 if (!smb_io_unistr2("environment", &q_u->environment, True, ps, depth))
5990 return False;
5992 if (!prs_align(ps))
5993 return False;
5994 if (!smb_io_unistr2("path", &q_u->path, True, ps, depth))
5995 return False;
5997 if (!prs_align(ps))
5998 return False;
5999 if (!smb_io_unistr2("name", &q_u->name, True, ps, depth))
6000 return False;
6002 return True;
6005 /*******************************************************************
6006 ********************************************************************/
6008 BOOL spoolss_io_r_addprintprocessor(const char *desc, SPOOL_R_ADDPRINTPROCESSOR *r_u, prs_struct *ps, int depth)
6010 prs_debug(ps, depth, desc, "spoolss_io_r_addprintproicessor");
6011 depth++;
6013 if (!prs_align(ps))
6014 return False;
6016 if (!prs_werror("status", ps, depth, &r_u->status))
6017 return False;
6019 return True;
6022 /*******************************************************************
6023 ********************************************************************/
6025 BOOL spoolss_io_r_enumprintprocdatatypes(const char *desc, SPOOL_R_ENUMPRINTPROCDATATYPES *r_u, prs_struct *ps, int depth)
6027 prs_debug(ps, depth, desc, "spoolss_io_r_enumprintprocdatatypes");
6028 depth++;
6030 if (!prs_align(ps))
6031 return False;
6033 if (!spoolss_io_buffer("", ps, depth, &r_u->buffer))
6034 return False;
6036 if (!prs_align(ps))
6037 return False;
6039 if (!prs_uint32("needed", ps, depth, &r_u->needed))
6040 return False;
6042 if (!prs_uint32("returned", ps, depth, &r_u->returned))
6043 return False;
6045 if (!prs_werror("status", ps, depth, &r_u->status))
6046 return False;
6048 return True;
6051 /*******************************************************************
6052 ********************************************************************/
6054 BOOL spoolss_io_q_enumprintprocdatatypes(const char *desc, SPOOL_Q_ENUMPRINTPROCDATATYPES *q_u, prs_struct *ps, int depth)
6056 prs_debug(ps, depth, desc, "spoolss_io_q_enumprintprocdatatypes");
6057 depth++;
6059 if (!prs_align(ps))
6060 return False;
6062 if (!prs_uint32("name_ptr", ps, depth, &q_u->name_ptr))
6063 return False;
6064 if (!smb_io_unistr2("name", &q_u->name, True, ps, depth))
6065 return False;
6067 if (!prs_align(ps))
6068 return False;
6070 if (!prs_uint32("processor_ptr", ps, depth, &q_u->processor_ptr))
6071 return False;
6072 if (!smb_io_unistr2("processor", &q_u->processor, q_u->processor_ptr, ps, depth))
6073 return False;
6075 if (!prs_align(ps))
6076 return False;
6078 if (!prs_uint32("level", ps, depth, &q_u->level))
6079 return False;
6081 if(!spoolss_io_buffer("buffer", ps, depth, &q_u->buffer))
6082 return False;
6084 if (!prs_align(ps))
6085 return False;
6087 if (!prs_uint32("offered", ps, depth, &q_u->offered))
6088 return False;
6090 return True;
6093 /*******************************************************************
6094 Parse a SPOOL_Q_ENUMPRINTMONITORS structure.
6095 ********************************************************************/
6097 BOOL spoolss_io_q_enumprintmonitors(const char *desc, SPOOL_Q_ENUMPRINTMONITORS *q_u, prs_struct *ps, int depth)
6099 prs_debug(ps, depth, desc, "spoolss_io_q_enumprintmonitors");
6100 depth++;
6102 if (!prs_align(ps))
6103 return False;
6105 if (!prs_uint32("name_ptr", ps, depth, &q_u->name_ptr))
6106 return False;
6107 if (!smb_io_unistr2("name", &q_u->name, True, ps, depth))
6108 return False;
6110 if (!prs_align(ps))
6111 return False;
6113 if (!prs_uint32("level", ps, depth, &q_u->level))
6114 return False;
6116 if(!spoolss_io_buffer("", ps, depth, &q_u->buffer))
6117 return False;
6119 if (!prs_align(ps))
6120 return False;
6122 if (!prs_uint32("offered", ps, depth, &q_u->offered))
6123 return False;
6125 return True;
6128 /*******************************************************************
6129 ********************************************************************/
6131 BOOL spoolss_io_r_enumprintmonitors(const char *desc, SPOOL_R_ENUMPRINTMONITORS *r_u, prs_struct *ps, int depth)
6133 prs_debug(ps, depth, desc, "spoolss_io_r_enumprintmonitors");
6134 depth++;
6136 if (!prs_align(ps))
6137 return False;
6139 if (!spoolss_io_buffer("", ps, depth, &r_u->buffer))
6140 return False;
6142 if (!prs_align(ps))
6143 return False;
6145 if (!prs_uint32("needed", ps, depth, &r_u->needed))
6146 return False;
6148 if (!prs_uint32("returned", ps, depth, &r_u->returned))
6149 return False;
6151 if (!prs_werror("status", ps, depth, &r_u->status))
6152 return False;
6154 return True;
6157 /*******************************************************************
6158 ********************************************************************/
6160 BOOL spoolss_io_r_enumprinterdata(const char *desc, SPOOL_R_ENUMPRINTERDATA *r_u, prs_struct *ps, int depth)
6162 prs_debug(ps, depth, desc, "spoolss_io_r_enumprinterdata");
6163 depth++;
6165 if(!prs_align(ps))
6166 return False;
6167 if(!prs_uint32("valuesize", ps, depth, &r_u->valuesize))
6168 return False;
6170 if (UNMARSHALLING(ps) && r_u->valuesize) {
6171 r_u->value = (uint16 *)prs_alloc_mem(ps, r_u->valuesize * 2);
6172 if (!r_u->value) {
6173 DEBUG(0, ("spoolss_io_r_enumprinterdata: out of memory for printerdata value\n"));
6174 return False;
6178 if(!prs_uint16uni(False, "value", ps, depth, r_u->value, r_u->valuesize ))
6179 return False;
6181 if(!prs_align(ps))
6182 return False;
6184 if(!prs_uint32("realvaluesize", ps, depth, &r_u->realvaluesize))
6185 return False;
6187 if(!prs_uint32("type", ps, depth, &r_u->type))
6188 return False;
6190 if(!prs_uint32("datasize", ps, depth, &r_u->datasize))
6191 return False;
6193 if (UNMARSHALLING(ps) && r_u->datasize) {
6194 r_u->data = (uint8 *)prs_alloc_mem(ps, r_u->datasize);
6195 if (!r_u->data) {
6196 DEBUG(0, ("spoolss_io_r_enumprinterdata: out of memory for printerdata data\n"));
6197 return False;
6201 if(!prs_uint8s(False, "data", ps, depth, r_u->data, r_u->datasize))
6202 return False;
6203 if(!prs_align(ps))
6204 return False;
6206 if(!prs_uint32("realdatasize", ps, depth, &r_u->realdatasize))
6207 return False;
6208 if(!prs_werror("status", ps, depth, &r_u->status))
6209 return False;
6211 return True;
6214 /*******************************************************************
6215 ********************************************************************/
6217 BOOL spoolss_io_q_enumprinterdata(const char *desc, SPOOL_Q_ENUMPRINTERDATA *q_u, prs_struct *ps, int depth)
6219 prs_debug(ps, depth, desc, "spoolss_io_q_enumprinterdata");
6220 depth++;
6222 if(!prs_align(ps))
6223 return False;
6224 if(!smb_io_pol_hnd("printer handle",&q_u->handle,ps,depth))
6225 return False;
6226 if(!prs_uint32("index", ps, depth, &q_u->index))
6227 return False;
6228 if(!prs_uint32("valuesize", ps, depth, &q_u->valuesize))
6229 return False;
6230 if(!prs_uint32("datasize", ps, depth, &q_u->datasize))
6231 return False;
6233 return True;
6236 /*******************************************************************
6237 ********************************************************************/
6239 BOOL make_spoolss_q_enumprinterdata(SPOOL_Q_ENUMPRINTERDATA *q_u,
6240 const POLICY_HND *hnd,
6241 uint32 idx, uint32 valuelen, uint32 datalen)
6243 memcpy(&q_u->handle, hnd, sizeof(q_u->handle));
6244 q_u->index=idx;
6245 q_u->valuesize=valuelen;
6246 q_u->datasize=datalen;
6248 return True;
6251 /*******************************************************************
6252 ********************************************************************/
6254 BOOL make_spoolss_q_enumprinterdataex(SPOOL_Q_ENUMPRINTERDATAEX *q_u,
6255 const POLICY_HND *hnd, const char *key,
6256 uint32 size)
6258 memcpy(&q_u->handle, hnd, sizeof(q_u->handle));
6259 init_unistr2(&q_u->key, key, UNI_STR_TERMINATE);
6260 q_u->size = size;
6262 return True;
6265 /*******************************************************************
6266 ********************************************************************/
6267 BOOL make_spoolss_q_setprinterdata(SPOOL_Q_SETPRINTERDATA *q_u, const POLICY_HND *hnd,
6268 char* value, uint32 data_type, char* data, uint32 data_size)
6270 memcpy(&q_u->handle, hnd, sizeof(q_u->handle));
6271 q_u->type = data_type;
6272 init_unistr2(&q_u->value, value, UNI_STR_TERMINATE);
6274 q_u->max_len = q_u->real_len = data_size;
6275 q_u->data = (unsigned char *)data;
6277 return True;
6280 /*******************************************************************
6281 ********************************************************************/
6282 BOOL make_spoolss_q_setprinterdataex(SPOOL_Q_SETPRINTERDATAEX *q_u, const POLICY_HND *hnd,
6283 char *key, char* value, uint32 data_type, char* data,
6284 uint32 data_size)
6286 memcpy(&q_u->handle, hnd, sizeof(q_u->handle));
6287 q_u->type = data_type;
6288 init_unistr2(&q_u->value, value, UNI_STR_TERMINATE);
6289 init_unistr2(&q_u->key, key, UNI_STR_TERMINATE);
6291 q_u->max_len = q_u->real_len = data_size;
6292 q_u->data = (unsigned char *)data;
6294 return True;
6297 /*******************************************************************
6298 ********************************************************************/
6300 BOOL spoolss_io_q_setprinterdata(const char *desc, SPOOL_Q_SETPRINTERDATA *q_u, prs_struct *ps, int depth)
6302 prs_debug(ps, depth, desc, "spoolss_io_q_setprinterdata");
6303 depth++;
6305 if(!prs_align(ps))
6306 return False;
6307 if(!smb_io_pol_hnd("printer handle", &q_u->handle, ps, depth))
6308 return False;
6309 if(!smb_io_unistr2("", &q_u->value, True, ps, depth))
6310 return False;
6312 if(!prs_align(ps))
6313 return False;
6315 if(!prs_uint32("type", ps, depth, &q_u->type))
6316 return False;
6318 if(!prs_uint32("max_len", ps, depth, &q_u->max_len))
6319 return False;
6321 switch (q_u->type)
6323 case REG_SZ:
6324 case REG_BINARY:
6325 case REG_DWORD:
6326 case REG_MULTI_SZ:
6327 if (q_u->max_len) {
6328 if (UNMARSHALLING(ps))
6329 q_u->data=(uint8 *)prs_alloc_mem(ps, q_u->max_len * sizeof(uint8));
6330 if(q_u->data == NULL)
6331 return False;
6332 if(!prs_uint8s(False,"data", ps, depth, q_u->data, q_u->max_len))
6333 return False;
6335 if(!prs_align(ps))
6336 return False;
6337 break;
6340 if(!prs_uint32("real_len", ps, depth, &q_u->real_len))
6341 return False;
6343 return True;
6346 /*******************************************************************
6347 ********************************************************************/
6349 BOOL spoolss_io_r_setprinterdata(const char *desc, SPOOL_R_SETPRINTERDATA *r_u, prs_struct *ps, int depth)
6351 prs_debug(ps, depth, desc, "spoolss_io_r_setprinterdata");
6352 depth++;
6354 if(!prs_align(ps))
6355 return False;
6356 if(!prs_werror("status", ps, depth, &r_u->status))
6357 return False;
6359 return True;
6362 /*******************************************************************
6363 ********************************************************************/
6364 BOOL spoolss_io_q_resetprinter(const char *desc, SPOOL_Q_RESETPRINTER *q_u, prs_struct *ps, int depth)
6366 prs_debug(ps, depth, desc, "spoolss_io_q_resetprinter");
6367 depth++;
6369 if (!prs_align(ps))
6370 return False;
6371 if (!smb_io_pol_hnd("printer handle", &q_u->handle, ps, depth))
6372 return False;
6374 if (!prs_uint32("datatype_ptr", ps, depth, &q_u->datatype_ptr))
6375 return False;
6377 if (q_u->datatype_ptr) {
6378 if (!smb_io_unistr2("datatype", &q_u->datatype, q_u->datatype_ptr?True:False, ps, depth))
6379 return False;
6382 if (!spoolss_io_devmode_cont(desc, &q_u->devmode_ctr, ps, depth))
6383 return False;
6385 return True;
6389 /*******************************************************************
6390 ********************************************************************/
6391 BOOL spoolss_io_r_resetprinter(const char *desc, SPOOL_R_RESETPRINTER *r_u, prs_struct *ps, int depth)
6393 prs_debug(ps, depth, desc, "spoolss_io_r_resetprinter");
6394 depth++;
6396 if(!prs_align(ps))
6397 return False;
6398 if(!prs_werror("status", ps, depth, &r_u->status))
6399 return False;
6401 return True;
6404 /*******************************************************************
6405 ********************************************************************/
6407 static BOOL spoolss_io_addform(const char *desc, FORM *f, uint32 ptr, prs_struct *ps, int depth)
6409 prs_debug(ps, depth, desc, "spoolss_io_addform");
6410 depth++;
6411 if(!prs_align(ps))
6412 return False;
6414 if (ptr!=0)
6416 if(!prs_uint32("flags", ps, depth, &f->flags))
6417 return False;
6418 if(!prs_uint32("name_ptr", ps, depth, &f->name_ptr))
6419 return False;
6420 if(!prs_uint32("size_x", ps, depth, &f->size_x))
6421 return False;
6422 if(!prs_uint32("size_y", ps, depth, &f->size_y))
6423 return False;
6424 if(!prs_uint32("left", ps, depth, &f->left))
6425 return False;
6426 if(!prs_uint32("top", ps, depth, &f->top))
6427 return False;
6428 if(!prs_uint32("right", ps, depth, &f->right))
6429 return False;
6430 if(!prs_uint32("bottom", ps, depth, &f->bottom))
6431 return False;
6433 if(!smb_io_unistr2("", &f->name, f->name_ptr, ps, depth))
6434 return False;
6437 return True;
6440 /*******************************************************************
6441 ********************************************************************/
6443 BOOL spoolss_io_q_deleteform(const char *desc, SPOOL_Q_DELETEFORM *q_u, prs_struct *ps, int depth)
6445 prs_debug(ps, depth, desc, "spoolss_io_q_deleteform");
6446 depth++;
6448 if(!prs_align(ps))
6449 return False;
6450 if(!smb_io_pol_hnd("printer handle", &q_u->handle, ps, depth))
6451 return False;
6452 if(!smb_io_unistr2("form name", &q_u->name, True, ps, depth))
6453 return False;
6455 return True;
6458 /*******************************************************************
6459 ********************************************************************/
6461 BOOL spoolss_io_r_deleteform(const char *desc, SPOOL_R_DELETEFORM *r_u, prs_struct *ps, int depth)
6463 prs_debug(ps, depth, desc, "spoolss_io_r_deleteform");
6464 depth++;
6466 if(!prs_align(ps))
6467 return False;
6468 if(!prs_werror("status", ps, depth, &r_u->status))
6469 return False;
6471 return True;
6474 /*******************************************************************
6475 ********************************************************************/
6477 BOOL spoolss_io_q_addform(const char *desc, SPOOL_Q_ADDFORM *q_u, prs_struct *ps, int depth)
6479 uint32 useless_ptr=1;
6480 prs_debug(ps, depth, desc, "spoolss_io_q_addform");
6481 depth++;
6483 if(!prs_align(ps))
6484 return False;
6485 if(!smb_io_pol_hnd("printer handle", &q_u->handle, ps, depth))
6486 return False;
6487 if(!prs_uint32("level", ps, depth, &q_u->level))
6488 return False;
6489 if(!prs_uint32("level2", ps, depth, &q_u->level2))
6490 return False;
6492 if (q_u->level==1)
6494 if(!prs_uint32("useless_ptr", ps, depth, &useless_ptr))
6495 return False;
6496 if(!spoolss_io_addform("", &q_u->form, useless_ptr, ps, depth))
6497 return False;
6500 return True;
6503 /*******************************************************************
6504 ********************************************************************/
6506 BOOL spoolss_io_r_addform(const char *desc, SPOOL_R_ADDFORM *r_u, prs_struct *ps, int depth)
6508 prs_debug(ps, depth, desc, "spoolss_io_r_addform");
6509 depth++;
6511 if(!prs_align(ps))
6512 return False;
6513 if(!prs_werror("status", ps, depth, &r_u->status))
6514 return False;
6516 return True;
6519 /*******************************************************************
6520 ********************************************************************/
6522 BOOL spoolss_io_q_setform(const char *desc, SPOOL_Q_SETFORM *q_u, prs_struct *ps, int depth)
6524 uint32 useless_ptr=1;
6525 prs_debug(ps, depth, desc, "spoolss_io_q_setform");
6526 depth++;
6528 if(!prs_align(ps))
6529 return False;
6530 if(!smb_io_pol_hnd("printer handle", &q_u->handle, ps, depth))
6531 return False;
6532 if(!smb_io_unistr2("", &q_u->name, True, ps, depth))
6533 return False;
6535 if(!prs_align(ps))
6536 return False;
6538 if(!prs_uint32("level", ps, depth, &q_u->level))
6539 return False;
6540 if(!prs_uint32("level2", ps, depth, &q_u->level2))
6541 return False;
6543 if (q_u->level==1)
6545 if(!prs_uint32("useless_ptr", ps, depth, &useless_ptr))
6546 return False;
6547 if(!spoolss_io_addform("", &q_u->form, useless_ptr, ps, depth))
6548 return False;
6551 return True;
6554 /*******************************************************************
6555 ********************************************************************/
6557 BOOL spoolss_io_r_setform(const char *desc, SPOOL_R_SETFORM *r_u, prs_struct *ps, int depth)
6559 prs_debug(ps, depth, desc, "spoolss_io_r_setform");
6560 depth++;
6562 if(!prs_align(ps))
6563 return False;
6564 if(!prs_werror("status", ps, depth, &r_u->status))
6565 return False;
6567 return True;
6570 /*******************************************************************
6571 Parse a SPOOL_R_GETJOB structure.
6572 ********************************************************************/
6574 BOOL spoolss_io_r_getjob(const char *desc, SPOOL_R_GETJOB *r_u, prs_struct *ps, int depth)
6576 prs_debug(ps, depth, desc, "spoolss_io_r_getjob");
6577 depth++;
6579 if (!prs_align(ps))
6580 return False;
6582 if (!spoolss_io_buffer("", ps, depth, &r_u->buffer))
6583 return False;
6585 if (!prs_align(ps))
6586 return False;
6588 if (!prs_uint32("needed", ps, depth, &r_u->needed))
6589 return False;
6591 if (!prs_werror("status", ps, depth, &r_u->status))
6592 return False;
6594 return True;
6597 /*******************************************************************
6598 Parse a SPOOL_Q_GETJOB structure.
6599 ********************************************************************/
6601 BOOL spoolss_io_q_getjob(const char *desc, SPOOL_Q_GETJOB *q_u, prs_struct *ps, int depth)
6603 prs_debug(ps, depth, desc, "");
6604 depth++;
6606 if(!prs_align(ps))
6607 return False;
6609 if(!smb_io_pol_hnd("printer handle",&q_u->handle,ps,depth))
6610 return False;
6611 if(!prs_uint32("jobid", ps, depth, &q_u->jobid))
6612 return False;
6613 if(!prs_uint32("level", ps, depth, &q_u->level))
6614 return False;
6616 if(!spoolss_io_buffer("", ps, depth, &q_u->buffer))
6617 return False;
6619 if(!prs_align(ps))
6620 return False;
6622 if(!prs_uint32("offered", ps, depth, &q_u->offered))
6623 return False;
6625 return True;
6628 void free_devmode(DEVICEMODE *devmode)
6630 if (devmode!=NULL) {
6631 SAFE_FREE(devmode->private);
6632 SAFE_FREE(devmode);
6636 void free_printer_info_1(PRINTER_INFO_1 *printer)
6638 SAFE_FREE(printer);
6641 void free_printer_info_2(PRINTER_INFO_2 *printer)
6643 if (printer!=NULL) {
6644 free_devmode(printer->devmode);
6645 printer->devmode = NULL;
6646 SAFE_FREE(printer);
6650 void free_printer_info_3(PRINTER_INFO_3 *printer)
6652 SAFE_FREE(printer);
6655 void free_printer_info_4(PRINTER_INFO_4 *printer)
6657 SAFE_FREE(printer);
6660 void free_printer_info_5(PRINTER_INFO_5 *printer)
6662 SAFE_FREE(printer);
6665 void free_printer_info_7(PRINTER_INFO_7 *printer)
6667 SAFE_FREE(printer);
6670 void free_job_info_2(JOB_INFO_2 *job)
6672 if (job!=NULL)
6673 free_devmode(job->devmode);
6676 /*******************************************************************
6677 * init a structure.
6678 ********************************************************************/
6680 BOOL make_spoolss_q_replyopenprinter(SPOOL_Q_REPLYOPENPRINTER *q_u,
6681 const fstring string, uint32 printer, uint32 type)
6683 if (q_u == NULL)
6684 return False;
6686 init_unistr2(&q_u->string, string, UNI_STR_TERMINATE);
6688 q_u->printer=printer;
6689 q_u->type=type;
6691 q_u->unknown0=0x0;
6692 q_u->unknown1=0x0;
6694 return True;
6697 /*******************************************************************
6698 Parse a SPOOL_Q_REPLYOPENPRINTER structure.
6699 ********************************************************************/
6701 BOOL spoolss_io_q_replyopenprinter(const char *desc, SPOOL_Q_REPLYOPENPRINTER *q_u, prs_struct *ps, int depth)
6703 prs_debug(ps, depth, desc, "spoolss_io_q_replyopenprinter");
6704 depth++;
6706 if(!prs_align(ps))
6707 return False;
6709 if(!smb_io_unistr2("", &q_u->string, True, ps, depth))
6710 return False;
6712 if(!prs_align(ps))
6713 return False;
6715 if(!prs_uint32("printer", ps, depth, &q_u->printer))
6716 return False;
6717 if(!prs_uint32("type", ps, depth, &q_u->type))
6718 return False;
6720 if(!prs_uint32("unknown0", ps, depth, &q_u->unknown0))
6721 return False;
6722 if(!prs_uint32("unknown1", ps, depth, &q_u->unknown1))
6723 return False;
6725 return True;
6728 /*******************************************************************
6729 Parse a SPOOL_R_REPLYOPENPRINTER structure.
6730 ********************************************************************/
6732 BOOL spoolss_io_r_replyopenprinter(const char *desc, SPOOL_R_REPLYOPENPRINTER *r_u, prs_struct *ps, int depth)
6734 prs_debug(ps, depth, desc, "spoolss_io_r_replyopenprinter");
6735 depth++;
6737 if (!prs_align(ps))
6738 return False;
6740 if(!smb_io_pol_hnd("printer handle",&r_u->handle,ps,depth))
6741 return False;
6743 if (!prs_werror("status", ps, depth, &r_u->status))
6744 return False;
6746 return True;
6749 /*******************************************************************
6750 * init a structure.
6751 ********************************************************************/
6752 BOOL make_spoolss_q_routerreplyprinter(SPOOL_Q_ROUTERREPLYPRINTER *q_u, POLICY_HND *hnd,
6753 uint32 condition, uint32 change_id)
6756 memcpy(&q_u->handle, hnd, sizeof(q_u->handle));
6758 q_u->condition = condition;
6759 q_u->change_id = change_id;
6761 /* magic values */
6762 q_u->unknown1 = 0x1;
6763 memset(q_u->unknown2, 0x0, 5);
6764 q_u->unknown2[0] = 0x1;
6766 return True;
6769 /*******************************************************************
6770 Parse a SPOOL_Q_ROUTERREPLYPRINTER structure.
6771 ********************************************************************/
6772 BOOL spoolss_io_q_routerreplyprinter (const char *desc, SPOOL_Q_ROUTERREPLYPRINTER *q_u, prs_struct *ps, int depth)
6775 prs_debug(ps, depth, desc, "spoolss_io_q_routerreplyprinter");
6776 depth++;
6778 if (!prs_align(ps))
6779 return False;
6781 if(!smb_io_pol_hnd("printer handle",&q_u->handle,ps,depth))
6782 return False;
6784 if (!prs_uint32("condition", ps, depth, &q_u->condition))
6785 return False;
6787 if (!prs_uint32("unknown1", ps, depth, &q_u->unknown1))
6788 return False;
6790 if (!prs_uint32("change_id", ps, depth, &q_u->change_id))
6791 return False;
6793 if (!prs_uint8s(False, "private", ps, depth, q_u->unknown2, 5))
6794 return False;
6796 return True;
6799 /*******************************************************************
6800 Parse a SPOOL_R_ROUTERREPLYPRINTER structure.
6801 ********************************************************************/
6802 BOOL spoolss_io_r_routerreplyprinter (const char *desc, SPOOL_R_ROUTERREPLYPRINTER *r_u, prs_struct *ps, int depth)
6804 prs_debug(ps, depth, desc, "spoolss_io_r_routerreplyprinter");
6805 depth++;
6807 if (!prs_align(ps))
6808 return False;
6810 if (!prs_werror("status", ps, depth, &r_u->status))
6811 return False;
6813 return True;
6816 /*******************************************************************
6817 * init a structure.
6818 ********************************************************************/
6820 BOOL make_spoolss_q_reply_closeprinter(SPOOL_Q_REPLYCLOSEPRINTER *q_u, POLICY_HND *hnd)
6822 if (q_u == NULL)
6823 return False;
6825 memcpy(&q_u->handle, hnd, sizeof(q_u->handle));
6827 return True;
6830 /*******************************************************************
6831 Parse a SPOOL_Q_REPLYCLOSEPRINTER structure.
6832 ********************************************************************/
6834 BOOL spoolss_io_q_replycloseprinter(const char *desc, SPOOL_Q_REPLYCLOSEPRINTER *q_u, prs_struct *ps, int depth)
6836 prs_debug(ps, depth, desc, "spoolss_io_q_replycloseprinter");
6837 depth++;
6839 if(!prs_align(ps))
6840 return False;
6842 if(!smb_io_pol_hnd("printer handle",&q_u->handle,ps,depth))
6843 return False;
6845 return True;
6848 /*******************************************************************
6849 Parse a SPOOL_R_REPLYCLOSEPRINTER structure.
6850 ********************************************************************/
6852 BOOL spoolss_io_r_replycloseprinter(const char *desc, SPOOL_R_REPLYCLOSEPRINTER *r_u, prs_struct *ps, int depth)
6854 prs_debug(ps, depth, desc, "spoolss_io_r_replycloseprinter");
6855 depth++;
6857 if (!prs_align(ps))
6858 return False;
6860 if(!smb_io_pol_hnd("printer handle",&r_u->handle,ps,depth))
6861 return False;
6863 if (!prs_werror("status", ps, depth, &r_u->status))
6864 return False;
6866 return True;
6869 #if 0 /* JERRY - not currently used but could be :-) */
6871 /*******************************************************************
6872 Deep copy a SPOOL_NOTIFY_INFO_DATA structure
6873 ******************************************************************/
6874 static BOOL copy_spool_notify_info_data(SPOOL_NOTIFY_INFO_DATA *dst,
6875 SPOOL_NOTIFY_INFO_DATA *src, int n)
6877 int i;
6879 memcpy(dst, src, sizeof(SPOOL_NOTIFY_INFO_DATA)*n);
6881 for (i=0; i<n; i++) {
6882 int len;
6883 uint16 *s = NULL;
6885 if (src->size != POINTER)
6886 continue;
6887 len = src->notify_data.data.length;
6888 s = malloc(sizeof(uint16)*len);
6889 if (s == NULL) {
6890 DEBUG(0,("copy_spool_notify_info_data: malloc() failed!\n"));
6891 return False;
6894 memcpy(s, src->notify_data.data.string, len*2);
6895 dst->notify_data.data.string = s;
6898 return True;
6901 /*******************************************************************
6902 Deep copy a SPOOL_NOTIFY_INFO structure
6903 ******************************************************************/
6904 static BOOL copy_spool_notify_info(SPOOL_NOTIFY_INFO *dst, SPOOL_NOTIFY_INFO *src)
6906 if (!dst) {
6907 DEBUG(0,("copy_spool_notify_info: NULL destination pointer!\n"));
6908 return False;
6911 dst->version = src->version;
6912 dst->flags = src->flags;
6913 dst->count = src->count;
6915 if (dst->count)
6917 dst->data = malloc(dst->count * sizeof(SPOOL_NOTIFY_INFO_DATA));
6919 DEBUG(10,("copy_spool_notify_info: allocating space for [%d] PRINTER_NOTIFY_INFO_DATA entries\n",
6920 dst->count));
6922 if (dst->data == NULL) {
6923 DEBUG(0,("copy_spool_notify_info: malloc() failed for [%d] entries!\n",
6924 dst->count));
6925 return False;
6928 return (copy_spool_notify_info_data(dst->data, src->data, src->count));
6931 return True;
6933 #endif /* JERRY */
6935 /*******************************************************************
6936 * init a structure.
6937 ********************************************************************/
6939 BOOL make_spoolss_q_reply_rrpcn(SPOOL_Q_REPLY_RRPCN *q_u, POLICY_HND *hnd,
6940 uint32 change_low, uint32 change_high,
6941 SPOOL_NOTIFY_INFO *info)
6943 if (q_u == NULL)
6944 return False;
6946 memcpy(&q_u->handle, hnd, sizeof(q_u->handle));
6948 q_u->change_low=change_low;
6949 q_u->change_high=change_high;
6951 q_u->unknown0=0x0;
6952 q_u->unknown1=0x0;
6954 q_u->info_ptr=0x0FF0ADDE;
6956 q_u->info.version=2;
6958 if (info->count) {
6959 DEBUG(10,("make_spoolss_q_reply_rrpcn: [%d] PRINTER_NOTIFY_INFO_DATA\n",
6960 info->count));
6961 q_u->info.version = info->version;
6962 q_u->info.flags = info->flags;
6963 q_u->info.count = info->count;
6964 /* pointer field - be careful! */
6965 q_u->info.data = info->data;
6967 else {
6968 q_u->info.flags=PRINTER_NOTIFY_INFO_DISCARDED;
6969 q_u->info.count=0;
6972 return True;
6975 /*******************************************************************
6976 Parse a SPOOL_Q_REPLY_RRPCN structure.
6977 ********************************************************************/
6979 BOOL spoolss_io_q_reply_rrpcn(const char *desc, SPOOL_Q_REPLY_RRPCN *q_u, prs_struct *ps, int depth)
6981 prs_debug(ps, depth, desc, "spoolss_io_q_reply_rrpcn");
6982 depth++;
6984 if(!prs_align(ps))
6985 return False;
6987 if(!smb_io_pol_hnd("printer handle",&q_u->handle,ps,depth))
6988 return False;
6990 if (!prs_uint32("change_low", ps, depth, &q_u->change_low))
6991 return False;
6993 if (!prs_uint32("change_high", ps, depth, &q_u->change_high))
6994 return False;
6996 if (!prs_uint32("unknown0", ps, depth, &q_u->unknown0))
6997 return False;
6999 if (!prs_uint32("unknown1", ps, depth, &q_u->unknown1))
7000 return False;
7002 if (!prs_uint32("info_ptr", ps, depth, &q_u->info_ptr))
7003 return False;
7005 if(q_u->info_ptr!=0)
7006 if(!smb_io_notify_info(desc, &q_u->info, ps, depth))
7007 return False;
7009 return True;
7012 /*******************************************************************
7013 Parse a SPOOL_R_REPLY_RRPCN structure.
7014 ********************************************************************/
7016 BOOL spoolss_io_r_reply_rrpcn(const char *desc, SPOOL_R_REPLY_RRPCN *r_u, prs_struct *ps, int depth)
7018 prs_debug(ps, depth, desc, "spoolss_io_r_reply_rrpcn");
7019 depth++;
7021 if (!prs_align(ps))
7022 return False;
7024 if (!prs_uint32("unknown0", ps, depth, &r_u->unknown0))
7025 return False;
7027 if (!prs_werror("status", ps, depth, &r_u->status))
7028 return False;
7030 return True;
7033 /*******************************************************************
7034 * read a structure.
7035 * called from spoolss_q_getprinterdataex (srv_spoolss.c)
7036 ********************************************************************/
7038 BOOL spoolss_io_q_getprinterdataex(const char *desc, SPOOL_Q_GETPRINTERDATAEX *q_u, prs_struct *ps, int depth)
7040 if (q_u == NULL)
7041 return False;
7043 prs_debug(ps, depth, desc, "spoolss_io_q_getprinterdataex");
7044 depth++;
7046 if (!prs_align(ps))
7047 return False;
7048 if (!smb_io_pol_hnd("printer handle",&q_u->handle,ps,depth))
7049 return False;
7050 if (!prs_align(ps))
7051 return False;
7052 if (!smb_io_unistr2("keyname", &q_u->keyname,True,ps,depth))
7053 return False;
7054 if (!prs_align(ps))
7055 return False;
7056 if (!smb_io_unistr2("valuename", &q_u->valuename,True,ps,depth))
7057 return False;
7058 if (!prs_align(ps))
7059 return False;
7060 if (!prs_uint32("size", ps, depth, &q_u->size))
7061 return False;
7063 return True;
7066 /*******************************************************************
7067 * write a structure.
7068 * called from spoolss_r_getprinterdataex (srv_spoolss.c)
7069 ********************************************************************/
7071 BOOL spoolss_io_r_getprinterdataex(const char *desc, SPOOL_R_GETPRINTERDATAEX *r_u, prs_struct *ps, int depth)
7073 if (r_u == NULL)
7074 return False;
7076 prs_debug(ps, depth, desc, "spoolss_io_r_getprinterdataex");
7077 depth++;
7079 if (!prs_align(ps))
7080 return False;
7081 if (!prs_uint32("type", ps, depth, &r_u->type))
7082 return False;
7083 if (!prs_uint32("size", ps, depth, &r_u->size))
7084 return False;
7086 if (UNMARSHALLING(ps) && r_u->size) {
7087 r_u->data = (unsigned char *)prs_alloc_mem(ps, r_u->size);
7088 if(!r_u->data)
7089 return False;
7092 if (!prs_uint8s(False,"data", ps, depth, r_u->data, r_u->size))
7093 return False;
7095 if (!prs_align(ps))
7096 return False;
7098 if (!prs_uint32("needed", ps, depth, &r_u->needed))
7099 return False;
7100 if (!prs_werror("status", ps, depth, &r_u->status))
7101 return False;
7103 return True;
7106 /*******************************************************************
7107 * read a structure.
7108 ********************************************************************/
7110 BOOL spoolss_io_q_setprinterdataex(const char *desc, SPOOL_Q_SETPRINTERDATAEX *q_u, prs_struct *ps, int depth)
7112 prs_debug(ps, depth, desc, "spoolss_io_q_setprinterdataex");
7113 depth++;
7115 if(!prs_align(ps))
7116 return False;
7117 if(!smb_io_pol_hnd("printer handle", &q_u->handle, ps, depth))
7118 return False;
7119 if(!smb_io_unistr2("", &q_u->key, True, ps, depth))
7120 return False;
7122 if(!prs_align(ps))
7123 return False;
7125 if(!smb_io_unistr2("", &q_u->value, True, ps, depth))
7126 return False;
7128 if(!prs_align(ps))
7129 return False;
7131 if(!prs_uint32("type", ps, depth, &q_u->type))
7132 return False;
7134 if(!prs_uint32("max_len", ps, depth, &q_u->max_len))
7135 return False;
7137 switch (q_u->type)
7139 case 0x1:
7140 case 0x3:
7141 case 0x4:
7142 case 0x7:
7143 if (q_u->max_len) {
7144 if (UNMARSHALLING(ps))
7145 q_u->data=(uint8 *)prs_alloc_mem(ps, q_u->max_len * sizeof(uint8));
7146 if(q_u->data == NULL)
7147 return False;
7148 if(!prs_uint8s(False,"data", ps, depth, q_u->data, q_u->max_len))
7149 return False;
7151 if(!prs_align(ps))
7152 return False;
7153 break;
7156 if(!prs_uint32("real_len", ps, depth, &q_u->real_len))
7157 return False;
7159 return True;
7162 /*******************************************************************
7163 * write a structure.
7164 ********************************************************************/
7166 BOOL spoolss_io_r_setprinterdataex(const char *desc, SPOOL_R_SETPRINTERDATAEX *r_u, prs_struct *ps, int depth)
7168 prs_debug(ps, depth, desc, "spoolss_io_r_setprinterdataex");
7169 depth++;
7171 if(!prs_align(ps))
7172 return False;
7173 if(!prs_werror("status", ps, depth, &r_u->status))
7174 return False;
7176 return True;
7179 /*******************************************************************
7180 * read a structure.
7181 ********************************************************************/
7182 BOOL make_spoolss_q_enumprinterkey(SPOOL_Q_ENUMPRINTERKEY *q_u,
7183 POLICY_HND *hnd, const char *key,
7184 uint32 size)
7186 DEBUG(5,("make_spoolss_q_enumprinterkey\n"));
7188 memcpy(&q_u->handle, hnd, sizeof(q_u->handle));
7189 init_unistr2(&q_u->key, key, UNI_STR_TERMINATE);
7190 q_u->size = size;
7192 return True;
7195 /*******************************************************************
7196 * read a structure.
7197 ********************************************************************/
7199 BOOL spoolss_io_q_enumprinterkey(const char *desc, SPOOL_Q_ENUMPRINTERKEY *q_u, prs_struct *ps, int depth)
7201 prs_debug(ps, depth, desc, "spoolss_io_q_enumprinterkey");
7202 depth++;
7204 if(!prs_align(ps))
7205 return False;
7206 if(!smb_io_pol_hnd("printer handle", &q_u->handle, ps, depth))
7207 return False;
7209 if(!smb_io_unistr2("", &q_u->key, True, ps, depth))
7210 return False;
7212 if(!prs_align(ps))
7213 return False;
7215 if(!prs_uint32("size", ps, depth, &q_u->size))
7216 return False;
7218 return True;
7221 /*******************************************************************
7222 * write a structure.
7223 ********************************************************************/
7225 BOOL spoolss_io_r_enumprinterkey(const char *desc, SPOOL_R_ENUMPRINTERKEY *r_u, prs_struct *ps, int depth)
7227 prs_debug(ps, depth, desc, "spoolss_io_r_enumprinterkey");
7228 depth++;
7230 if(!prs_align(ps))
7231 return False;
7233 if (!smb_io_buffer5("", &r_u->keys, ps, depth))
7234 return False;
7236 if(!prs_align(ps))
7237 return False;
7239 if(!prs_uint32("needed", ps, depth, &r_u->needed))
7240 return False;
7242 if(!prs_werror("status", ps, depth, &r_u->status))
7243 return False;
7245 return True;
7248 /*******************************************************************
7249 * read a structure.
7250 ********************************************************************/
7252 BOOL make_spoolss_q_deleteprinterkey(SPOOL_Q_DELETEPRINTERKEY *q_u,
7253 POLICY_HND *hnd, char *keyname)
7255 DEBUG(5,("make_spoolss_q_deleteprinterkey\n"));
7257 memcpy(&q_u->handle, hnd, sizeof(q_u->handle));
7258 init_unistr2(&q_u->keyname, keyname, UNI_STR_TERMINATE);
7260 return True;
7263 /*******************************************************************
7264 * read a structure.
7265 ********************************************************************/
7267 BOOL spoolss_io_q_deleteprinterkey(const char *desc, SPOOL_Q_DELETEPRINTERKEY *q_u, prs_struct *ps, int depth)
7269 prs_debug(ps, depth, desc, "spoolss_io_q_deleteprinterkey");
7270 depth++;
7272 if(!prs_align(ps))
7273 return False;
7274 if(!smb_io_pol_hnd("printer handle", &q_u->handle, ps, depth))
7275 return False;
7277 if(!smb_io_unistr2("", &q_u->keyname, True, ps, depth))
7278 return False;
7280 return True;
7283 /*******************************************************************
7284 * write a structure.
7285 ********************************************************************/
7287 BOOL spoolss_io_r_deleteprinterkey(const char *desc, SPOOL_R_DELETEPRINTERKEY *r_u, prs_struct *ps, int depth)
7289 prs_debug(ps, depth, desc, "spoolss_io_r_deleteprinterkey");
7290 depth++;
7292 if(!prs_align(ps))
7293 return False;
7295 if(!prs_werror("status", ps, depth, &r_u->status))
7296 return False;
7298 return True;
7302 /*******************************************************************
7303 * read a structure.
7304 ********************************************************************/
7306 BOOL spoolss_io_q_enumprinterdataex(const char *desc, SPOOL_Q_ENUMPRINTERDATAEX *q_u, prs_struct *ps, int depth)
7308 prs_debug(ps, depth, desc, "spoolss_io_q_enumprinterdataex");
7309 depth++;
7311 if(!prs_align(ps))
7312 return False;
7313 if(!smb_io_pol_hnd("printer handle", &q_u->handle, ps, depth))
7314 return False;
7316 if(!smb_io_unistr2("", &q_u->key, True, ps, depth))
7317 return False;
7319 if(!prs_align(ps))
7320 return False;
7322 if(!prs_uint32("size", ps, depth, &q_u->size))
7323 return False;
7325 return True;
7328 /*******************************************************************
7329 ********************************************************************/
7331 static BOOL spoolss_io_printer_enum_values_ctr(const char *desc, prs_struct *ps,
7332 PRINTER_ENUM_VALUES_CTR *ctr, int depth)
7334 int i;
7335 uint32 valuename_offset,
7336 data_offset,
7337 current_offset;
7338 const uint32 basic_unit = 20; /* size of static portion of enum_values */
7340 prs_debug(ps, depth, desc, "spoolss_io_printer_enum_values_ctr");
7341 depth++;
7344 * offset data begins at 20 bytes per structure * size_of_array.
7345 * Don't forget the uint32 at the beginning
7346 * */
7348 current_offset = basic_unit * ctr->size_of_array;
7350 /* first loop to write basic enum_value information */
7352 if (UNMARSHALLING(ps)) {
7353 ctr->values = (PRINTER_ENUM_VALUES *)prs_alloc_mem(
7354 ps, ctr->size_of_array * sizeof(PRINTER_ENUM_VALUES));
7355 if (!ctr->values)
7356 return False;
7359 for (i=0; i<ctr->size_of_array; i++) {
7360 valuename_offset = current_offset;
7361 if (!prs_uint32("valuename_offset", ps, depth, &valuename_offset))
7362 return False;
7364 if (!prs_uint32("value_len", ps, depth, &ctr->values[i].value_len))
7365 return False;
7367 if (!prs_uint32("type", ps, depth, &ctr->values[i].type))
7368 return False;
7370 data_offset = ctr->values[i].value_len + valuename_offset;
7372 if (!prs_uint32("data_offset", ps, depth, &data_offset))
7373 return False;
7375 if (!prs_uint32("data_len", ps, depth, &ctr->values[i].data_len))
7376 return False;
7378 current_offset = data_offset + ctr->values[i].data_len - basic_unit;
7379 /* account for 2 byte alignment */
7380 current_offset += (current_offset % 2);
7384 * loop #2 for writing the dynamically size objects; pay
7385 * attention to 2-byte alignment here....
7388 for (i=0; i<ctr->size_of_array; i++) {
7390 if (!prs_unistr("valuename", ps, depth, &ctr->values[i].valuename))
7391 return False;
7393 if ( ctr->values[i].data_len ) {
7394 if ( UNMARSHALLING(ps) ) {
7395 ctr->values[i].data = (uint8 *)prs_alloc_mem(
7396 ps, ctr->values[i].data_len);
7397 if (!ctr->values[i].data)
7398 return False;
7400 if (!prs_uint8s(False, "data", ps, depth, ctr->values[i].data, ctr->values[i].data_len))
7401 return False;
7404 if ( !prs_align_uint16(ps) )
7405 return False;
7408 return True;
7411 /*******************************************************************
7412 * write a structure.
7413 ********************************************************************/
7415 BOOL spoolss_io_r_enumprinterdataex(const char *desc, SPOOL_R_ENUMPRINTERDATAEX *r_u, prs_struct *ps, int depth)
7417 uint32 data_offset, end_offset;
7418 prs_debug(ps, depth, desc, "spoolss_io_r_enumprinterdataex");
7419 depth++;
7421 if(!prs_align(ps))
7422 return False;
7424 if (!prs_uint32("size", ps, depth, &r_u->ctr.size))
7425 return False;
7427 data_offset = prs_offset(ps);
7429 if (!prs_set_offset(ps, data_offset + r_u->ctr.size))
7430 return False;
7432 if(!prs_align(ps))
7433 return False;
7435 if(!prs_uint32("needed", ps, depth, &r_u->needed))
7436 return False;
7438 if(!prs_uint32("returned", ps, depth, &r_u->returned))
7439 return False;
7441 if(!prs_werror("status", ps, depth, &r_u->status))
7442 return False;
7444 r_u->ctr.size_of_array = r_u->returned;
7446 end_offset = prs_offset(ps);
7448 if (!prs_set_offset(ps, data_offset))
7449 return False;
7451 if (r_u->ctr.size)
7452 if (!spoolss_io_printer_enum_values_ctr("", ps, &r_u->ctr, depth ))
7453 return False;
7455 if (!prs_set_offset(ps, end_offset))
7456 return False;
7457 return True;
7460 /*******************************************************************
7461 * write a structure.
7462 ********************************************************************/
7465 uint32 GetPrintProcessorDirectory(
7466 [in] unistr2 *name,
7467 [in] unistr2 *environment,
7468 [in] uint32 level,
7469 [in,out] NEW_BUFFER buffer,
7470 [in] uint32 offered,
7471 [out] uint32 needed,
7472 [out] uint32 returned
7477 BOOL make_spoolss_q_getprintprocessordirectory(SPOOL_Q_GETPRINTPROCESSORDIRECTORY *q_u, const char *name, char *environment, int level, NEW_BUFFER *buffer, uint32 offered)
7479 DEBUG(5,("make_spoolss_q_getprintprocessordirectory\n"));
7481 init_unistr2(&q_u->name, name, UNI_STR_TERMINATE);
7482 init_unistr2(&q_u->environment, environment, UNI_STR_TERMINATE);
7484 q_u->level = level;
7486 q_u->buffer = buffer;
7487 q_u->offered = offered;
7489 return True;
7492 BOOL spoolss_io_q_getprintprocessordirectory(const char *desc, SPOOL_Q_GETPRINTPROCESSORDIRECTORY *q_u, prs_struct *ps, int depth)
7494 uint32 ptr;
7496 prs_debug(ps, depth, desc, "spoolss_io_q_getprintprocessordirectory");
7497 depth++;
7499 if(!prs_align(ps))
7500 return False;
7502 if (!prs_uint32("ptr", ps, depth, &ptr))
7503 return False;
7505 if (ptr) {
7506 if(!smb_io_unistr2("name", &q_u->name, True, ps, depth))
7507 return False;
7510 if (!prs_align(ps))
7511 return False;
7513 if (!prs_uint32("ptr", ps, depth, &ptr))
7514 return False;
7516 if (ptr) {
7517 if(!smb_io_unistr2("environment", &q_u->environment, True,
7518 ps, depth))
7519 return False;
7522 if (!prs_align(ps))
7523 return False;
7525 if(!prs_uint32("level", ps, depth, &q_u->level))
7526 return False;
7528 if(!spoolss_io_buffer("", ps, depth, &q_u->buffer))
7529 return False;
7531 if(!prs_align(ps))
7532 return False;
7534 if(!prs_uint32("offered", ps, depth, &q_u->offered))
7535 return False;
7537 return True;
7540 /*******************************************************************
7541 * write a structure.
7542 ********************************************************************/
7544 BOOL spoolss_io_r_getprintprocessordirectory(const char *desc, SPOOL_R_GETPRINTPROCESSORDIRECTORY *r_u, prs_struct *ps, int depth)
7546 prs_debug(ps, depth, desc, "spoolss_io_r_getprintprocessordirectory");
7547 depth++;
7549 if(!prs_align(ps))
7550 return False;
7552 if(!spoolss_io_buffer("", ps, depth, &r_u->buffer))
7553 return False;
7555 if(!prs_align(ps))
7556 return False;
7558 if(!prs_uint32("needed", ps, depth, &r_u->needed))
7559 return False;
7561 if(!prs_werror("status", ps, depth, &r_u->status))
7562 return False;
7564 return True;
7567 BOOL smb_io_printprocessordirectory_1(const char *desc, NEW_BUFFER *buffer, PRINTPROCESSOR_DIRECTORY_1 *info, int depth)
7569 prs_struct *ps=&buffer->prs;
7571 prs_debug(ps, depth, desc, "smb_io_printprocessordirectory_1");
7572 depth++;
7574 buffer->struct_start=prs_offset(ps);
7576 if (!smb_io_unistr(desc, &info->name, ps, depth))
7577 return False;
7579 return True;
7582 /*******************************************************************
7583 * init a structure.
7584 ********************************************************************/
7586 BOOL make_spoolss_q_addform(SPOOL_Q_ADDFORM *q_u, POLICY_HND *handle,
7587 int level, FORM *form)
7589 memcpy(&q_u->handle, handle, sizeof(POLICY_HND));
7590 q_u->level = level;
7591 q_u->level2 = level;
7592 memcpy(&q_u->form, form, sizeof(FORM));
7594 return True;
7597 /*******************************************************************
7598 * init a structure.
7599 ********************************************************************/
7601 BOOL make_spoolss_q_setform(SPOOL_Q_SETFORM *q_u, POLICY_HND *handle,
7602 int level, const char *form_name, FORM *form)
7604 memcpy(&q_u->handle, handle, sizeof(POLICY_HND));
7605 q_u->level = level;
7606 q_u->level2 = level;
7607 memcpy(&q_u->form, form, sizeof(FORM));
7608 init_unistr2(&q_u->name, form_name, UNI_STR_TERMINATE);
7610 return True;
7613 /*******************************************************************
7614 * init a structure.
7615 ********************************************************************/
7617 BOOL make_spoolss_q_deleteform(SPOOL_Q_DELETEFORM *q_u, POLICY_HND *handle,
7618 const char *form)
7620 memcpy(&q_u->handle, handle, sizeof(POLICY_HND));
7621 init_unistr2(&q_u->name, form, UNI_STR_TERMINATE);
7622 return True;
7625 /*******************************************************************
7626 * init a structure.
7627 ********************************************************************/
7629 BOOL make_spoolss_q_getform(SPOOL_Q_GETFORM *q_u, POLICY_HND *handle,
7630 const char *formname, uint32 level,
7631 NEW_BUFFER *buffer, uint32 offered)
7633 memcpy(&q_u->handle, handle, sizeof(POLICY_HND));
7634 q_u->level = level;
7635 init_unistr2(&q_u->formname, formname, UNI_STR_TERMINATE);
7636 q_u->buffer=buffer;
7637 q_u->offered=offered;
7639 return True;
7642 /*******************************************************************
7643 * init a structure.
7644 ********************************************************************/
7646 BOOL make_spoolss_q_enumforms(SPOOL_Q_ENUMFORMS *q_u, POLICY_HND *handle,
7647 uint32 level, NEW_BUFFER *buffer,
7648 uint32 offered)
7650 memcpy(&q_u->handle, handle, sizeof(POLICY_HND));
7651 q_u->level = level;
7652 q_u->buffer=buffer;
7653 q_u->offered=offered;
7655 return True;
7658 /*******************************************************************
7659 * init a structure.
7660 ********************************************************************/
7662 BOOL make_spoolss_q_setjob(SPOOL_Q_SETJOB *q_u, POLICY_HND *handle,
7663 uint32 jobid, uint32 level, uint32 command)
7665 memcpy(&q_u->handle, handle, sizeof(POLICY_HND));
7666 q_u->jobid = jobid;
7667 q_u->level = level;
7669 /* Hmm - the SPOOL_Q_SETJOB structure has a JOB_INFO ctr in it but
7670 the server side code has it marked as unused. */
7672 q_u->command = command;
7674 return True;
7677 /*******************************************************************
7678 * init a structure.
7679 ********************************************************************/
7681 BOOL make_spoolss_q_getjob(SPOOL_Q_GETJOB *q_u, POLICY_HND *handle,
7682 uint32 jobid, uint32 level, NEW_BUFFER *buffer,
7683 uint32 offered)
7685 memcpy(&q_u->handle, handle, sizeof(POLICY_HND));
7686 q_u->jobid = jobid;
7687 q_u->level = level;
7688 q_u->buffer = buffer;
7689 q_u->offered = offered;
7691 return True;
7694 /*******************************************************************
7695 * init a structure.
7696 ********************************************************************/
7698 BOOL make_spoolss_q_startpageprinter(SPOOL_Q_STARTPAGEPRINTER *q_u,
7699 POLICY_HND *handle)
7701 memcpy(&q_u->handle, handle, sizeof(POLICY_HND));
7703 return True;
7706 /*******************************************************************
7707 * init a structure.
7708 ********************************************************************/
7710 BOOL make_spoolss_q_endpageprinter(SPOOL_Q_ENDPAGEPRINTER *q_u,
7711 POLICY_HND *handle)
7713 memcpy(&q_u->handle, handle, sizeof(POLICY_HND));
7715 return True;
7718 /*******************************************************************
7719 * init a structure.
7720 ********************************************************************/
7722 BOOL make_spoolss_q_startdocprinter(SPOOL_Q_STARTDOCPRINTER *q_u,
7723 POLICY_HND *handle, uint32 level,
7724 char *docname, char *outputfile,
7725 char *datatype)
7727 DOC_INFO_CONTAINER *ctr = &q_u->doc_info_container;
7729 memcpy(&q_u->handle, handle, sizeof(POLICY_HND));
7731 ctr->level = level;
7733 switch (level) {
7734 case 1:
7735 ctr->docinfo.switch_value = level;
7737 ctr->docinfo.doc_info_1.p_docname = docname ? 1 : 0;
7738 ctr->docinfo.doc_info_1.p_outputfile = outputfile ? 1 : 0;
7739 ctr->docinfo.doc_info_1.p_datatype = datatype ? 1 : 0;
7741 init_unistr2(&ctr->docinfo.doc_info_1.docname, docname, UNI_STR_TERMINATE);
7742 init_unistr2(&ctr->docinfo.doc_info_1.outputfile, outputfile, UNI_STR_TERMINATE);
7743 init_unistr2(&ctr->docinfo.doc_info_1.datatype, datatype, UNI_STR_TERMINATE);
7745 break;
7746 case 2:
7747 /* DOC_INFO_2 is only used by Windows 9x and since it
7748 doesn't do printing over RPC we don't have to worry
7749 about it. */
7750 default:
7751 DEBUG(3, ("unsupported info level %d\n", level));
7752 return False;
7755 return True;
7758 /*******************************************************************
7759 * init a structure.
7760 ********************************************************************/
7762 BOOL make_spoolss_q_enddocprinter(SPOOL_Q_ENDDOCPRINTER *q_u,
7763 POLICY_HND *handle)
7765 memcpy(&q_u->handle, handle, sizeof(POLICY_HND));
7767 return True;
7770 /*******************************************************************
7771 * init a structure.
7772 ********************************************************************/
7774 BOOL make_spoolss_q_writeprinter(SPOOL_Q_WRITEPRINTER *q_u,
7775 POLICY_HND *handle, uint32 data_size,
7776 char *data)
7778 memcpy(&q_u->handle, handle, sizeof(POLICY_HND));
7779 q_u->buffer_size = q_u->buffer_size2 = data_size;
7780 q_u->buffer = (unsigned char *)data;
7781 return True;
7784 /*******************************************************************
7785 * init a structure.
7786 ********************************************************************/
7788 BOOL make_spoolss_q_deleteprinterdata(SPOOL_Q_DELETEPRINTERDATA *q_u,
7789 POLICY_HND *handle, char *valuename)
7791 memcpy(&q_u->handle, handle, sizeof(POLICY_HND));
7792 init_unistr2(&q_u->valuename, valuename, UNI_STR_TERMINATE);
7794 return True;
7797 /*******************************************************************
7798 * init a structure.
7799 ********************************************************************/
7801 BOOL make_spoolss_q_deleteprinterdataex(SPOOL_Q_DELETEPRINTERDATAEX *q_u,
7802 POLICY_HND *handle, char *key,
7803 char *value)
7805 memcpy(&q_u->handle, handle, sizeof(POLICY_HND));
7806 init_unistr2(&q_u->valuename, value, UNI_STR_TERMINATE);
7807 init_unistr2(&q_u->keyname, key, UNI_STR_TERMINATE);
7809 return True;
7812 /*******************************************************************
7813 * init a structure.
7814 ********************************************************************/
7816 BOOL make_spoolss_q_rffpcnex(SPOOL_Q_RFFPCNEX *q_u, POLICY_HND *handle,
7817 uint32 flags, uint32 options, const char *localmachine,
7818 uint32 printerlocal, SPOOL_NOTIFY_OPTION *option)
7820 memcpy(&q_u->handle, handle, sizeof(POLICY_HND));
7822 q_u->flags = flags;
7823 q_u->options = options;
7825 q_u->localmachine_ptr = 1;
7827 init_unistr2(&q_u->localmachine, localmachine, UNI_STR_TERMINATE);
7829 q_u->printerlocal = printerlocal;
7831 if (option)
7832 q_u->option_ptr = 1;
7834 q_u->option = option;
7836 return True;