6c2d6b49785866df7a266b311af16273858b85af
[samba.git] / source3 / rpc_parse / parse_spoolss.c
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.
9  *
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.
14  *  
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.
19  *  
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.
23  */
24
25 #include "includes.h"
26
27 #undef DBGC_CLASS
28 #define DBGC_CLASS DBGC_RPC_PARSE
29
30
31 /*******************************************************************
32 This should be moved in a more generic lib.
33 ********************************************************************/  
34
35 BOOL spoolss_io_system_time(const char *desc, prs_struct *ps, int depth, SYSTEMTIME *systime)
36 {
37         if(!prs_uint16("year", ps, depth, &systime->year))
38                 return False;
39         if(!prs_uint16("month", ps, depth, &systime->month))
40                 return False;
41         if(!prs_uint16("dayofweek", ps, depth, &systime->dayofweek))
42                 return False;
43         if(!prs_uint16("day", ps, depth, &systime->day))
44                 return False;
45         if(!prs_uint16("hour", ps, depth, &systime->hour))
46                 return False;
47         if(!prs_uint16("minute", ps, depth, &systime->minute))
48                 return False;
49         if(!prs_uint16("second", ps, depth, &systime->second))
50                 return False;
51         if(!prs_uint16("milliseconds", ps, depth, &systime->milliseconds))
52                 return False;
53
54         return True;
55 }
56
57 /*******************************************************************
58 ********************************************************************/  
59
60 BOOL make_systemtime(SYSTEMTIME *systime, struct tm *unixtime)
61 {
62         systime->year=unixtime->tm_year+1900;
63         systime->month=unixtime->tm_mon+1;
64         systime->dayofweek=unixtime->tm_wday;
65         systime->day=unixtime->tm_mday;
66         systime->hour=unixtime->tm_hour;
67         systime->minute=unixtime->tm_min;
68         systime->second=unixtime->tm_sec;
69         systime->milliseconds=0;
70
71         return True;
72 }
73
74 /*******************************************************************
75 reads or writes an DOC_INFO structure.
76 ********************************************************************/  
77
78 static BOOL smb_io_doc_info_1(const char *desc, DOC_INFO_1 *info_1, prs_struct *ps, int depth)
79 {
80         if (info_1 == NULL) return False;
81
82         prs_debug(ps, depth, desc, "smb_io_doc_info_1");
83         depth++;
84  
85         if(!prs_align(ps))
86                 return False;
87         
88         if(!prs_uint32("p_docname",    ps, depth, &info_1->p_docname))
89                 return False;
90         if(!prs_uint32("p_outputfile", ps, depth, &info_1->p_outputfile))
91                 return False;
92         if(!prs_uint32("p_datatype",   ps, depth, &info_1->p_datatype))
93                 return False;
94
95         if(!smb_io_unistr2("", &info_1->docname,    info_1->p_docname,    ps, depth))
96                 return False;
97         if(!smb_io_unistr2("", &info_1->outputfile, info_1->p_outputfile, ps, depth))
98                 return False;
99         if(!smb_io_unistr2("", &info_1->datatype,   info_1->p_datatype,   ps, depth))
100                 return False;
101
102         return True;
103 }
104
105 /*******************************************************************
106 reads or writes an DOC_INFO structure.
107 ********************************************************************/  
108
109 static BOOL smb_io_doc_info(const char *desc, DOC_INFO *info, prs_struct *ps, int depth)
110 {
111         uint32 useless_ptr=0;
112         
113         if (info == NULL) return False;
114
115         prs_debug(ps, depth, desc, "smb_io_doc_info");
116         depth++;
117  
118         if(!prs_align(ps))
119                 return False;
120         
121         if(!prs_uint32("switch_value", ps, depth, &info->switch_value))
122                 return False;
123         
124         if(!prs_uint32("doc_info_X ptr", ps, depth, &useless_ptr))
125                 return False;
126
127         switch (info->switch_value)
128         {
129                 case 1: 
130                         if(!smb_io_doc_info_1("",&info->doc_info_1, ps, depth))
131                                 return False;
132                         break;
133                 case 2:
134                         /*
135                           this is just a placeholder
136                           
137                           MSDN July 1998 says doc_info_2 is only on
138                           Windows 95, and as Win95 doesn't do RPC to print
139                           this case is nearly impossible
140                           
141                           Maybe one day with Windows for dishwasher 2037 ...
142                           
143                         */
144                         /* smb_io_doc_info_2("",&info->doc_info_2, ps, depth); */
145                         break;
146                 default:
147                         DEBUG(0,("Something is obviously wrong somewhere !\n"));
148                         break;
149         }
150
151         return True;
152 }
153
154 /*******************************************************************
155 reads or writes an DOC_INFO_CONTAINER structure.
156 ********************************************************************/  
157
158 static BOOL smb_io_doc_info_container(const char *desc, DOC_INFO_CONTAINER *cont, prs_struct *ps, int depth)
159 {
160         if (cont == NULL) return False;
161
162         prs_debug(ps, depth, desc, "smb_io_doc_info_container");
163         depth++;
164  
165         if(!prs_align(ps))
166                 return False;
167         
168         if(!prs_uint32("level", ps, depth, &cont->level))
169                 return False;
170         
171         if(!smb_io_doc_info("",&cont->docinfo, ps, depth))
172                 return False;
173
174         return True;
175 }
176
177 /*******************************************************************
178 reads or writes an NOTIFY OPTION TYPE structure.
179 ********************************************************************/  
180
181 /* NOTIFY_OPTION_TYPE and NOTIFY_OPTION_TYPE_DATA are really one
182    structure.  The _TYPE structure is really the deferred referrants (i.e
183    the notify fields array) of the _TYPE structure. -tpot */
184
185 static BOOL smb_io_notify_option_type(const char *desc, SPOOL_NOTIFY_OPTION_TYPE *type, prs_struct *ps, int depth)
186 {
187         prs_debug(ps, depth, desc, "smb_io_notify_option_type");
188         depth++;
189  
190         if (!prs_align(ps))
191                 return False;
192
193         if(!prs_uint16("type", ps, depth, &type->type))
194                 return False;
195         if(!prs_uint16("reserved0", ps, depth, &type->reserved0))
196                 return False;
197         if(!prs_uint32("reserved1", ps, depth, &type->reserved1))
198                 return False;
199         if(!prs_uint32("reserved2", ps, depth, &type->reserved2))
200                 return False;
201         if(!prs_uint32("count", ps, depth, &type->count))
202                 return False;
203         if(!prs_uint32("fields_ptr", ps, depth, &type->fields_ptr))
204                 return False;
205
206         return True;
207 }
208
209 /*******************************************************************
210 reads or writes an NOTIFY OPTION TYPE DATA.
211 ********************************************************************/  
212
213 static BOOL smb_io_notify_option_type_data(const char *desc, SPOOL_NOTIFY_OPTION_TYPE *type, prs_struct *ps, int depth)
214 {
215         int i;
216
217         prs_debug(ps, depth, desc, "smb_io_notify_option_type_data");
218         depth++;
219  
220         /* if there are no fields just return */
221         if (type->fields_ptr==0)
222                 return True;
223
224         if(!prs_align(ps))
225                 return False;
226
227         if(!prs_uint32("count2", ps, depth, &type->count2))
228                 return False;
229         
230         if (type->count2 != type->count)
231                 DEBUG(4,("What a mess, count was %x now is %x !\n", type->count, type->count2));
232
233         /* parse the option type data */
234         for(i=0;i<type->count2;i++)
235                 if(!prs_uint16("fields",ps,depth,&type->fields[i]))
236                         return False;
237         return True;
238 }
239
240 /*******************************************************************
241 reads or writes an NOTIFY OPTION structure.
242 ********************************************************************/  
243
244 static BOOL smb_io_notify_option_type_ctr(const char *desc, SPOOL_NOTIFY_OPTION_TYPE_CTR *ctr , prs_struct *ps, int depth)
245 {               
246         int i;
247         
248         prs_debug(ps, depth, desc, "smb_io_notify_option_type_ctr");
249         depth++;
250  
251         if(!prs_uint32("count", ps, depth, &ctr->count))
252                 return False;
253
254         /* reading */
255         if (UNMARSHALLING(ps))
256                 if((ctr->type=PRS_ALLOC_MEM(ps,SPOOL_NOTIFY_OPTION_TYPE,ctr->count)) == NULL)
257                         return False;
258                 
259         /* the option type struct */
260         for(i=0;i<ctr->count;i++)
261                 if(!smb_io_notify_option_type("", &ctr->type[i] , ps, depth))
262                         return False;
263
264         /* the type associated with the option type struct */
265         for(i=0;i<ctr->count;i++)
266                 if(!smb_io_notify_option_type_data("", &ctr->type[i] , ps, depth))
267                         return False;
268         
269         return True;
270 }
271
272 /*******************************************************************
273 reads or writes an NOTIFY OPTION structure.
274 ********************************************************************/  
275
276 static BOOL smb_io_notify_option(const char *desc, SPOOL_NOTIFY_OPTION *option, prs_struct *ps, int depth)
277 {
278         prs_debug(ps, depth, desc, "smb_io_notify_option");
279         depth++;
280         
281         if(!prs_uint32("version", ps, depth, &option->version))
282                 return False;
283         if(!prs_uint32("flags", ps, depth, &option->flags))
284                 return False;
285         if(!prs_uint32("count", ps, depth, &option->count))
286                 return False;
287         if(!prs_uint32("option_type_ptr", ps, depth, &option->option_type_ptr))
288                 return False;
289         
290         /* marshalling or unmarshalling, that would work */     
291         if (option->option_type_ptr!=0) {
292                 if(!smb_io_notify_option_type_ctr("", &option->ctr ,ps, depth))
293                         return False;
294         }
295         else {
296                 option->ctr.type=NULL;
297                 option->ctr.count=0;
298         }
299         
300         return True;
301 }
302
303 /*******************************************************************
304 reads or writes an NOTIFY INFO DATA structure.
305 ********************************************************************/  
306
307 static BOOL smb_io_notify_info_data(const char *desc,SPOOL_NOTIFY_INFO_DATA *data, prs_struct *ps, int depth)
308 {
309         uint32 useless_ptr=0x0FF0ADDE;
310
311         prs_debug(ps, depth, desc, "smb_io_notify_info_data");
312         depth++;
313
314         if(!prs_align(ps))
315                 return False;
316         if(!prs_uint16("type",           ps, depth, &data->type))
317                 return False;
318         if(!prs_uint16("field",          ps, depth, &data->field))
319                 return False;
320
321         if(!prs_uint32("how many words", ps, depth, &data->size))
322                 return False;
323         if(!prs_uint32("id",             ps, depth, &data->id))
324                 return False;
325         if(!prs_uint32("how many words", ps, depth, &data->size))
326                 return False;
327
328         switch (data->enc_type) {
329
330                 /* One and two value data has two uint32 values */
331
332         case NOTIFY_ONE_VALUE:
333         case NOTIFY_TWO_VALUE:
334
335                 if(!prs_uint32("value[0]", ps, depth, &data->notify_data.value[0]))
336                         return False;
337                 if(!prs_uint32("value[1]", ps, depth, &data->notify_data.value[1]))
338                         return False;
339                 break;
340
341                 /* Pointers and strings have a string length and a
342                    pointer.  For a string the length is expressed as
343                    the number of uint16 characters plus a trailing
344                    \0\0. */
345
346         case NOTIFY_POINTER:
347
348                 if(!prs_uint32("string length", ps, depth, &data->notify_data.data.length ))
349                         return False;
350                 if(!prs_uint32("pointer", ps, depth, &useless_ptr))
351                         return False;
352
353                 break;
354
355         case NOTIFY_STRING:
356
357                 if(!prs_uint32("string length", ps, depth, &data->notify_data.data.length))
358                         return False;
359
360                 if(!prs_uint32("pointer", ps, depth, &useless_ptr))
361                         return False;
362
363                 break;
364
365         case NOTIFY_SECDESC:
366                 if( !prs_uint32( "sd size", ps, depth, &data->notify_data.sd.size ) )
367                         return False;
368                 if( !prs_uint32( "pointer", ps, depth, &useless_ptr ) )
369                         return False;
370                 
371                 break;
372
373         default:
374                 DEBUG(3, ("invalid enc_type %d for smb_io_notify_info_data\n",
375                           data->enc_type));
376                 break;
377         }
378
379         return True;
380 }
381
382 /*******************************************************************
383 reads or writes an NOTIFY INFO DATA structure.
384 ********************************************************************/  
385
386 BOOL smb_io_notify_info_data_strings(const char *desc,SPOOL_NOTIFY_INFO_DATA *data,
387                                      prs_struct *ps, int depth)
388 {
389         prs_debug(ps, depth, desc, "smb_io_notify_info_data_strings");
390         depth++;
391         
392         if(!prs_align(ps))
393                 return False;
394
395         switch(data->enc_type) {
396
397                 /* No data for values */
398
399         case NOTIFY_ONE_VALUE:
400         case NOTIFY_TWO_VALUE:
401
402                 break;
403
404                 /* Strings start with a length in uint16s */
405
406         case NOTIFY_STRING:
407
408                 if (MARSHALLING(ps))
409                         data->notify_data.data.length /= 2;
410
411                 if(!prs_uint32("string length", ps, depth, &data->notify_data.data.length))
412                         return False;
413
414                 if (UNMARSHALLING(ps)) {
415                         data->notify_data.data.string = PRS_ALLOC_MEM(ps, uint16,
416                                                                 data->notify_data.data.length);
417
418                         if (!data->notify_data.data.string) 
419                                 return False;
420                 }
421
422                 if (!prs_uint16uni(True, "string", ps, depth, data->notify_data.data.string,
423                                    data->notify_data.data.length))
424                         return False;
425
426                 if (MARSHALLING(ps))
427                         data->notify_data.data.length *= 2;
428
429                 break;
430
431         case NOTIFY_POINTER:
432
433                 if (UNMARSHALLING(ps)) {
434                         data->notify_data.data.string = PRS_ALLOC_MEM(ps, uint16,
435                                                                 data->notify_data.data.length);
436
437                         if (!data->notify_data.data.string) 
438                                 return False;
439                 }
440
441                 if(!prs_uint8s(True,"buffer",ps,depth,(uint8*)data->notify_data.data.string,data->notify_data.data.length))
442                         return False;
443
444                 break;
445
446         case NOTIFY_SECDESC:    
447                 if( !prs_uint32("secdesc size ", ps, depth, &data->notify_data.sd.size ) )
448                         return False;
449                 if ( !sec_io_desc( "sec_desc", &data->notify_data.sd.desc, ps, depth ) )
450                         return False;
451                 break;
452
453         default:
454                 DEBUG(3, ("invalid enc_type %d for smb_io_notify_info_data_strings\n",
455                           data->enc_type));
456                 break;
457         }
458
459 #if 0
460         if (isvalue==False) {
461
462                 /* length of string in unicode include \0 */
463                 x=data->notify_data.data.length+1;
464
465                 if (data->field != 16)
466                 if(!prs_uint32("string length", ps, depth, &x ))
467                         return False;
468
469                 if (MARSHALLING(ps)) {
470                         /* These are already in little endian format. Don't byte swap. */
471                         if (x == 1) {
472
473                                 /* No memory allocated for this string
474                                    therefore following the data.string
475                                    pointer is a bad idea.  Use a pointer to
476                                    the uint32 length union member to
477                                    provide a source for a unicode NULL */
478
479                                 if(!prs_uint8s(True,"string",ps,depth, (uint8 *)&data->notify_data.data.length,x*2)) 
480                                         return False;
481                         } else {
482
483                                 if (data->field == 16)
484                                         x /= 2;
485
486                                 if(!prs_uint16uni(True,"string",ps,depth,data->notify_data.data.string,x))
487                                         return False;
488                         }
489                 } else {
490
491                         /* Tallocate memory for string */
492
493                         data->notify_data.data.string = PRS_ALLOC_MEM(ps, uint16, x * 2);
494                         if (!data->notify_data.data.string) 
495                                 return False;
496
497                         if(!prs_uint16uni(True,"string",ps,depth,data->notify_data.data.string,x))
498                                 return False;
499                 }
500         }
501
502 #endif
503
504 #if 0   /* JERRY */
505         /* Win2k does not seem to put this parse align here */
506         if(!prs_align(ps))
507                 return False;
508 #endif
509
510         return True;
511 }
512
513 /*******************************************************************
514 reads or writes an NOTIFY INFO structure.
515 ********************************************************************/  
516
517 static BOOL smb_io_notify_info(const char *desc, SPOOL_NOTIFY_INFO *info, prs_struct *ps, int depth)
518 {
519         int i;
520
521         prs_debug(ps, depth, desc, "smb_io_notify_info");
522         depth++;
523  
524         if(!prs_align(ps))
525                 return False;
526
527         if(!prs_uint32("count", ps, depth, &info->count))
528                 return False;
529         if(!prs_uint32("version", ps, depth, &info->version))
530                 return False;
531         if(!prs_uint32("flags", ps, depth, &info->flags))
532                 return False;
533         if(!prs_uint32("count", ps, depth, &info->count))
534                 return False;
535
536         for (i=0;i<info->count;i++) {
537                 if(!smb_io_notify_info_data(desc, &info->data[i], ps, depth))
538                         return False;
539         }
540
541         /* now do the strings at the end of the stream */       
542         for (i=0;i<info->count;i++) {
543                 if(!smb_io_notify_info_data_strings(desc, &info->data[i], ps, depth))
544                         return False;
545         }
546
547         return True;
548 }
549
550 /*******************************************************************
551 ********************************************************************/  
552
553 BOOL spool_io_user_level_1( const char *desc, prs_struct *ps, int depth, SPOOL_USER_1 *q_u )
554 {
555         prs_debug(ps, depth, desc, "");
556         depth++;
557
558         if (!prs_align(ps))
559                 return False;
560
561         if (!prs_uint32("size", ps, depth, &q_u->size))
562                 return False;
563
564         if (!prs_io_unistr2_p("", ps, depth, &q_u->client_name))
565                 return False;
566         if (!prs_io_unistr2_p("", ps, depth, &q_u->user_name))
567                 return False;
568
569         if (!prs_uint32("build", ps, depth, &q_u->build))
570                 return False;
571         if (!prs_uint32("major", ps, depth, &q_u->major))
572                 return False;
573         if (!prs_uint32("minor", ps, depth, &q_u->minor))
574                 return False;
575         if (!prs_uint32("processor", ps, depth, &q_u->processor))
576                 return False;
577
578         if (!prs_io_unistr2("", ps, depth, q_u->client_name))
579                 return False;
580         if (!prs_align(ps))
581                 return False;
582
583         if (!prs_io_unistr2("", ps, depth, q_u->user_name))
584                 return False;
585
586         return True;
587 }
588
589 /*******************************************************************
590 ********************************************************************/  
591
592 static BOOL spool_io_user_level(const char *desc, SPOOL_USER_CTR *q_u, prs_struct *ps, int depth)
593 {
594         if (q_u==NULL)
595                 return False;
596
597         prs_debug(ps, depth, desc, "spool_io_user_level");
598         depth++;
599
600         if (!prs_align(ps))
601                 return False;
602
603         if (!prs_uint32("level", ps, depth, &q_u->level))
604                 return False;
605         
606         switch ( q_u->level ) 
607         {       
608                 case 1:
609                         if ( !prs_pointer( "" , ps, depth, (void**)&q_u->user.user1, 
610                                 sizeof(SPOOL_USER_1), (PRS_POINTER_CAST)spool_io_user_level_1 )) 
611                         {
612                                 return False;
613                         }
614                         break;
615                 default:
616                         return False;   
617         }       
618
619         return True;
620 }
621
622 /*******************************************************************
623  * read or write a DEVICEMODE struct.
624  * on reading allocate memory for the private member
625  ********************************************************************/
626
627 #define DM_NUM_OPTIONAL_FIELDS          8
628
629 BOOL spoolss_io_devmode(const char *desc, prs_struct *ps, int depth, DEVICEMODE *devmode)
630 {
631         int available_space;            /* size of the device mode left to parse */
632                                         /* only important on unmarshalling       */
633         int i = 0;
634                                         
635         struct optional_fields {
636                 fstring         name;
637                 uint32*         field;
638         } opt_fields[DM_NUM_OPTIONAL_FIELDS] = {
639                 { "icmmethod",          NULL },
640                 { "icmintent",          NULL },
641                 { "mediatype",          NULL },
642                 { "dithertype",         NULL },
643                 { "reserved1",          NULL },
644                 { "reserved2",          NULL },
645                 { "panningwidth",       NULL },
646                 { "panningheight",      NULL }
647         };
648
649         /* assign at run time to keep non-gcc compilers happy */
650
651         opt_fields[0].field = &devmode->icmmethod;
652         opt_fields[1].field = &devmode->icmintent;
653         opt_fields[2].field = &devmode->mediatype;
654         opt_fields[3].field = &devmode->dithertype;
655         opt_fields[4].field = &devmode->reserved1;
656         opt_fields[5].field = &devmode->reserved2;
657         opt_fields[6].field = &devmode->panningwidth;
658         opt_fields[7].field = &devmode->panningheight;
659                 
660         
661         prs_debug(ps, depth, desc, "spoolss_io_devmode");
662         depth++;
663
664         if (UNMARSHALLING(ps)) {
665                 devmode->devicename.buffer = PRS_ALLOC_MEM(ps, uint16, 32);
666                 if (devmode->devicename.buffer == NULL)
667                         return False;
668         }
669
670         if (!prs_uint16uni(True,"devicename", ps, depth, devmode->devicename.buffer, MAXDEVICENAME))
671                 return False;
672         
673         if (!prs_uint16("specversion",      ps, depth, &devmode->specversion))
674                 return False;
675                 
676         if (!prs_uint16("driverversion",    ps, depth, &devmode->driverversion))
677                 return False;
678         if (!prs_uint16("size",             ps, depth, &devmode->size))
679                 return False;
680         if (!prs_uint16("driverextra",      ps, depth, &devmode->driverextra))
681                 return False;
682         if (!prs_uint32("fields",           ps, depth, &devmode->fields))
683                 return False;
684         if (!prs_uint16("orientation",      ps, depth, &devmode->orientation))
685                 return False;
686         if (!prs_uint16("papersize",        ps, depth, &devmode->papersize))
687                 return False;
688         if (!prs_uint16("paperlength",      ps, depth, &devmode->paperlength))
689                 return False;
690         if (!prs_uint16("paperwidth",       ps, depth, &devmode->paperwidth))
691                 return False;
692         if (!prs_uint16("scale",            ps, depth, &devmode->scale))
693                 return False;
694         if (!prs_uint16("copies",           ps, depth, &devmode->copies))
695                 return False;
696         if (!prs_uint16("defaultsource",    ps, depth, &devmode->defaultsource))
697                 return False;
698         if (!prs_uint16("printquality",     ps, depth, &devmode->printquality))
699                 return False;
700         if (!prs_uint16("color",            ps, depth, &devmode->color))
701                 return False;
702         if (!prs_uint16("duplex",           ps, depth, &devmode->duplex))
703                 return False;
704         if (!prs_uint16("yresolution",      ps, depth, &devmode->yresolution))
705                 return False;
706         if (!prs_uint16("ttoption",         ps, depth, &devmode->ttoption))
707                 return False;
708         if (!prs_uint16("collate",          ps, depth, &devmode->collate))
709                 return False;
710
711         if (UNMARSHALLING(ps)) {
712                 devmode->formname.buffer = PRS_ALLOC_MEM(ps, uint16, 32);
713                 if (devmode->formname.buffer == NULL)
714                         return False;
715         }
716
717         if (!prs_uint16uni(True, "formname",  ps, depth, devmode->formname.buffer, 32))
718                 return False;
719         if (!prs_uint16("logpixels",        ps, depth, &devmode->logpixels))
720                 return False;
721         if (!prs_uint32("bitsperpel",       ps, depth, &devmode->bitsperpel))
722                 return False;
723         if (!prs_uint32("pelswidth",        ps, depth, &devmode->pelswidth))
724                 return False;
725         if (!prs_uint32("pelsheight",       ps, depth, &devmode->pelsheight))
726                 return False;
727         if (!prs_uint32("displayflags",     ps, depth, &devmode->displayflags))
728                 return False;
729         if (!prs_uint32("displayfrequency", ps, depth, &devmode->displayfrequency))
730                 return False;
731         /* 
732          * every device mode I've ever seen on the wire at least has up 
733          * to the displayfrequency field.   --jerry (05-09-2002)
734          */
735          
736         /* add uint32's + uint16's + two UNICODE strings */
737          
738         available_space = devmode->size - (sizeof(uint32)*6 + sizeof(uint16)*18 + sizeof(uint16)*64);
739         
740         /* Sanity check - we only have uint32's left tp parse */
741         
742         if ( available_space && ((available_space % sizeof(uint32)) != 0) ) {
743                 DEBUG(0,("spoolss_io_devmode: available_space [%d] no in multiple of 4 bytes (size = %d)!\n",
744                         available_space, devmode->size));
745                 DEBUG(0,("spoolss_io_devmode: please report to samba-technical@samba.org!\n"));
746                 return False;
747         }
748
749         /* 
750          * Conditional parsing.  Assume that the DeviceMode has been 
751          * zero'd by the caller. 
752          */
753         
754         while ((available_space > 0)  && (i < DM_NUM_OPTIONAL_FIELDS))
755         {
756                 DEBUG(11, ("spoolss_io_devmode: [%d] bytes left to parse in devmode\n", available_space));
757                 if (!prs_uint32(opt_fields[i].name, ps, depth, opt_fields[i].field))
758                         return False;
759                 available_space -= sizeof(uint32);
760                 i++;
761         }        
762         
763         /* Sanity Check - we should no available space at this point unless 
764            MS changes the device mode structure */
765                 
766         if (available_space) {
767                 DEBUG(0,("spoolss_io_devmode: I've parsed all I know and there is still stuff left|\n"));
768                 DEBUG(0,("spoolss_io_devmode: available_space = [%d], devmode_size = [%d]!\n",
769                         available_space, devmode->size));
770                 DEBUG(0,("spoolss_io_devmode: please report to samba-technical@samba.org!\n"));
771                 return False;
772         }
773
774
775         if (devmode->driverextra!=0) {
776                 if (UNMARSHALLING(ps)) {
777                         devmode->private=PRS_ALLOC_MEM(ps, uint8, devmode->driverextra);
778                         if(devmode->private == NULL)
779                                 return False;
780                         DEBUG(7,("spoolss_io_devmode: allocated memory [%d] for private\n",devmode->driverextra)); 
781                 }
782                         
783                 DEBUG(7,("spoolss_io_devmode: parsing [%d] bytes of private\n",devmode->driverextra));
784                 if (!prs_uint8s(False, "private",  ps, depth,
785                                 devmode->private, devmode->driverextra))
786                         return False;
787         }
788
789         return True;
790 }
791
792 /*******************************************************************
793  Read or write a DEVICEMODE container
794 ********************************************************************/  
795
796 static BOOL spoolss_io_devmode_cont(const char *desc, DEVMODE_CTR *dm_c, prs_struct *ps, int depth)
797 {
798         if (dm_c==NULL)
799                 return False;
800
801         prs_debug(ps, depth, desc, "spoolss_io_devmode_cont");
802         depth++;
803
804         if(!prs_align(ps))
805                 return False;
806         
807         if (!prs_uint32("size", ps, depth, &dm_c->size))
808                 return False;
809
810         if (!prs_uint32("devmode_ptr", ps, depth, &dm_c->devmode_ptr))
811                 return False;
812
813         if (dm_c->size==0 || dm_c->devmode_ptr==0) {
814                 if (UNMARSHALLING(ps))
815                         /* if while reading there is no DEVMODE ... */
816                         dm_c->devmode=NULL;
817                 return True;
818         }
819         
820         /* so we have a DEVICEMODE to follow */         
821         if (UNMARSHALLING(ps)) {
822                 DEBUG(9,("Allocating memory for spoolss_io_devmode\n"));
823                 dm_c->devmode=PRS_ALLOC_MEM(ps,DEVICEMODE,1);
824                 if(dm_c->devmode == NULL)
825                         return False;
826         }
827         
828         /* this is bad code, shouldn't be there */
829         if (!prs_uint32("size", ps, depth, &dm_c->size))
830                 return False;
831                 
832         if (!spoolss_io_devmode(desc, ps, depth, dm_c->devmode))
833                 return False;
834
835         return True;
836 }
837
838 /*******************************************************************
839 ********************************************************************/  
840
841 static BOOL spoolss_io_printer_default(const char *desc, PRINTER_DEFAULT *pd, prs_struct *ps, int depth)
842 {
843         if (pd==NULL)
844                 return False;
845
846         prs_debug(ps, depth, desc, "spoolss_io_printer_default");
847         depth++;
848
849         if (!prs_uint32("datatype_ptr", ps, depth, &pd->datatype_ptr))
850                 return False;
851
852         if (!smb_io_unistr2("datatype", &pd->datatype, pd->datatype_ptr, ps,depth))
853                 return False;
854         
855         if (!prs_align(ps))
856                 return False;
857
858         if (!spoolss_io_devmode_cont("", &pd->devmode_cont, ps, depth))
859                 return False;
860
861         if (!prs_align(ps))
862                 return False;
863
864         if (!prs_uint32("access_required", ps, depth, &pd->access_required))
865                 return False;
866
867         return True;
868 }
869
870 /*******************************************************************
871  * init a structure.
872  ********************************************************************/
873
874 BOOL make_spoolss_q_open_printer_ex(SPOOL_Q_OPEN_PRINTER_EX *q_u,
875                 const fstring printername, 
876                 const fstring datatype, 
877                 uint32 access_required,
878                 const fstring clientname,
879                 const fstring user_name)
880 {
881         DEBUG(5,("make_spoolss_q_open_printer_ex\n"));
882
883         q_u->printername = TALLOC_P( get_talloc_ctx(), UNISTR2 );
884         init_unistr2(q_u->printername, printername, UNI_STR_TERMINATE);
885
886         q_u->printer_default.datatype_ptr = 0;
887
888         q_u->printer_default.devmode_cont.size=0;
889         q_u->printer_default.devmode_cont.devmode_ptr=0;
890         q_u->printer_default.devmode_cont.devmode=NULL;
891         q_u->printer_default.access_required=access_required;
892
893         q_u->user_switch = 1;
894         
895         q_u->user_ctr.level                 = 1;
896         q_u->user_ctr.user.user1            = TALLOC_P( get_talloc_ctx(), SPOOL_USER_1 );
897         q_u->user_ctr.user.user1->size      = strlen(clientname) + strlen(user_name) + 10;
898         q_u->user_ctr.user.user1->build     = 1381;
899         q_u->user_ctr.user.user1->major     = 2;
900         q_u->user_ctr.user.user1->minor     = 0;
901         q_u->user_ctr.user.user1->processor = 0;
902
903         q_u->user_ctr.user.user1->client_name = TALLOC_P( get_talloc_ctx(), UNISTR2 );
904         q_u->user_ctr.user.user1->user_name   = TALLOC_P( get_talloc_ctx(), UNISTR2 );
905
906         init_unistr2(q_u->user_ctr.user.user1->client_name, clientname, UNI_STR_TERMINATE);
907         init_unistr2(q_u->user_ctr.user.user1->user_name, user_name, UNI_STR_TERMINATE);
908         
909         return True;
910 }
911
912 /*******************************************************************
913  * init a structure.
914  ********************************************************************/
915
916 BOOL make_spoolss_q_addprinterex( TALLOC_CTX *mem_ctx, SPOOL_Q_ADDPRINTEREX *q_u, 
917         const char *srv_name, const char* clientname, const char* user_name,
918         uint32 level, PRINTER_INFO_CTR *ctr)
919 {
920         DEBUG(5,("make_spoolss_q_addprinterex\n"));
921         
922         if (!ctr) 
923                 return False;
924
925         ZERO_STRUCTP(q_u);
926
927         q_u->server_name = TALLOC_P( mem_ctx, UNISTR2 );
928         init_unistr2(q_u->server_name, srv_name, UNI_FLAGS_NONE);
929
930         q_u->level = level;
931         
932         q_u->info.level = level;
933         q_u->info.info_ptr = (ctr->printers_2!=NULL)?1:0;
934         switch (level) {
935                 case 2:
936                         /* init q_u->info.info2 from *info */
937                         if (!make_spoolss_printer_info_2(mem_ctx, &q_u->info.info_2, ctr->printers_2)) {
938                                 DEBUG(0,("make_spoolss_q_addprinterex: Unable to fill SPOOL_Q_ADDPRINTEREX struct!\n"));
939                                 return False;
940                         }
941                         break;
942                 default :
943                         break;
944         }
945
946         q_u->user_switch=1;
947
948         q_u->user_ctr.level                = 1;
949         q_u->user_ctr.user.user1->build     = 1381;
950         q_u->user_ctr.user.user1->major     = 2; 
951         q_u->user_ctr.user.user1->minor     = 0;
952         q_u->user_ctr.user.user1->processor = 0;
953
954         q_u->user_ctr.user.user1->client_name = TALLOC_P( mem_ctx, UNISTR2 );
955         q_u->user_ctr.user.user1->user_name   = TALLOC_P( mem_ctx, UNISTR2 );
956
957         init_unistr2(q_u->user_ctr.user.user1->client_name, clientname, UNI_STR_TERMINATE);
958         init_unistr2(q_u->user_ctr.user.user1->user_name, user_name, UNI_STR_TERMINATE);
959
960         q_u->user_ctr.user.user1->size = q_u->user_ctr.user.user1->user_name->uni_str_len +
961                                    q_u->user_ctr.user.user1->client_name->uni_str_len + 2;
962         
963         return True;
964 }
965         
966 /*******************************************************************
967 create a SPOOL_PRINTER_INFO_2 stuct from a PRINTER_INFO_2 struct
968 *******************************************************************/
969
970 BOOL make_spoolss_printer_info_2(TALLOC_CTX *mem_ctx, SPOOL_PRINTER_INFO_LEVEL_2 **spool_info2, 
971                                 PRINTER_INFO_2 *info)
972 {
973
974         SPOOL_PRINTER_INFO_LEVEL_2 *inf;
975
976         /* allocate the necessary memory */
977         if (!(inf=TALLOC_P(mem_ctx, SPOOL_PRINTER_INFO_LEVEL_2))) {
978                 DEBUG(0,("make_spoolss_printer_info_2: Unable to allocate SPOOL_PRINTER_INFO_LEVEL_2 sruct!\n"));
979                 return False;
980         }
981         
982         inf->servername_ptr     = (info->servername.buffer!=NULL)?1:0;
983         inf->printername_ptr    = (info->printername.buffer!=NULL)?1:0;
984         inf->sharename_ptr      = (info->sharename.buffer!=NULL)?1:0;
985         inf->portname_ptr       = (info->portname.buffer!=NULL)?1:0;
986         inf->drivername_ptr     = (info->drivername.buffer!=NULL)?1:0;
987         inf->comment_ptr        = (info->comment.buffer!=NULL)?1:0;
988         inf->location_ptr       = (info->location.buffer!=NULL)?1:0;
989         inf->devmode_ptr        = (info->devmode!=NULL)?1:0;
990         inf->sepfile_ptr        = (info->sepfile.buffer!=NULL)?1:0;
991         inf->printprocessor_ptr = (info->printprocessor.buffer!=NULL)?1:0;
992         inf->datatype_ptr       = (info->datatype.buffer!=NULL)?1:0;
993         inf->parameters_ptr     = (info->parameters.buffer!=NULL)?1:0;
994         inf->secdesc_ptr        = (info->secdesc!=NULL)?1:0;
995         inf->attributes         = info->attributes;
996         inf->priority           = info->priority;
997         inf->default_priority   = info->defaultpriority;
998         inf->starttime          = info->starttime;
999         inf->untiltime          = info->untiltime;
1000         inf->cjobs              = info->cjobs;
1001         inf->averageppm = info->averageppm;
1002         init_unistr2_from_unistr(&inf->servername,      &info->servername);
1003         init_unistr2_from_unistr(&inf->printername,     &info->printername);
1004         init_unistr2_from_unistr(&inf->sharename,       &info->sharename);
1005         init_unistr2_from_unistr(&inf->portname,        &info->portname);
1006         init_unistr2_from_unistr(&inf->drivername,      &info->drivername);
1007         init_unistr2_from_unistr(&inf->comment,         &info->comment);
1008         init_unistr2_from_unistr(&inf->location,        &info->location);
1009         init_unistr2_from_unistr(&inf->sepfile,         &info->sepfile);
1010         init_unistr2_from_unistr(&inf->printprocessor,  &info->printprocessor);
1011         init_unistr2_from_unistr(&inf->datatype,        &info->datatype);
1012         init_unistr2_from_unistr(&inf->parameters,      &info->parameters);
1013         init_unistr2_from_unistr(&inf->datatype,        &info->datatype);
1014
1015         *spool_info2 = inf;
1016
1017         return True;
1018 }
1019
1020 /*******************************************************************
1021 create a SPOOL_PRINTER_INFO_3 struct from a PRINTER_INFO_3 struct
1022 *******************************************************************/
1023
1024 BOOL make_spoolss_printer_info_3(TALLOC_CTX *mem_ctx, SPOOL_PRINTER_INFO_LEVEL_3 **spool_info3, 
1025                                 PRINTER_INFO_3 *info)
1026 {
1027
1028         SPOOL_PRINTER_INFO_LEVEL_3 *inf;
1029
1030         /* allocate the necessary memory */
1031         if (!(inf=TALLOC_P(mem_ctx, SPOOL_PRINTER_INFO_LEVEL_3))) {
1032                 DEBUG(0,("make_spoolss_printer_info_3: Unable to allocate SPOOL_PRINTER_INFO_LEVEL_3 sruct!\n"));
1033                 return False;
1034         }
1035         
1036         inf->secdesc_ptr        = (info->secdesc!=NULL)?1:0;
1037
1038         *spool_info3 = inf;
1039
1040         return True;
1041 }
1042
1043 /*******************************************************************
1044 create a SPOOL_PRINTER_INFO_7 struct from a PRINTER_INFO_7 struct
1045 *******************************************************************/
1046
1047 BOOL make_spoolss_printer_info_7(TALLOC_CTX *mem_ctx, SPOOL_PRINTER_INFO_LEVEL_7 **spool_info7, 
1048                                 PRINTER_INFO_7 *info)
1049 {
1050
1051         SPOOL_PRINTER_INFO_LEVEL_7 *inf;
1052
1053         /* allocate the necessary memory */
1054         if (!(inf=TALLOC_P(mem_ctx, SPOOL_PRINTER_INFO_LEVEL_7))) {
1055                 DEBUG(0,("make_spoolss_printer_info_7: Unable to allocate SPOOL_PRINTER_INFO_LEVEL_7 struct!\n"));
1056                 return False;
1057         }
1058
1059         inf->guid_ptr           = (info->guid.buffer!=NULL)?1:0;
1060         inf->action             = info->action;
1061         init_unistr2_from_unistr(&inf->guid,            &info->guid);
1062
1063         *spool_info7 = inf;
1064
1065         return True;
1066 }
1067
1068
1069 /*******************************************************************
1070  * read a structure.
1071  * called from spoolss_q_open_printer_ex (srv_spoolss.c)
1072  ********************************************************************/
1073
1074 BOOL spoolss_io_q_open_printer(const char *desc, SPOOL_Q_OPEN_PRINTER *q_u, prs_struct *ps, int depth)
1075 {
1076         if (q_u == NULL)
1077                 return False;
1078
1079         prs_debug(ps, depth, desc, "spoolss_io_q_open_printer");
1080         depth++;
1081
1082         if (!prs_align(ps))
1083                 return False;
1084
1085         if (!prs_io_unistr2_p("ptr", ps, depth, &q_u->printername))
1086                 return False;
1087         if (!prs_io_unistr2("printername", ps, depth, q_u->printername))
1088                 return False;
1089         
1090         if (!prs_align(ps))
1091                 return False;
1092
1093         if (!spoolss_io_printer_default("", &q_u->printer_default, ps, depth))
1094                 return False;
1095                 
1096         return True;
1097 }
1098
1099 /*******************************************************************
1100  * write a structure.
1101  * called from static spoolss_r_open_printer_ex (srv_spoolss.c)
1102  * called from spoolss_open_printer_ex (cli_spoolss.c)
1103  ********************************************************************/
1104
1105 BOOL spoolss_io_r_open_printer(const char *desc, SPOOL_R_OPEN_PRINTER *r_u, prs_struct *ps, int depth)
1106 {
1107         if (r_u == NULL) return False;
1108
1109         prs_debug(ps, depth, desc, "spoolss_io_r_open_printer");
1110         depth++;
1111         
1112         if (!prs_align(ps))
1113                 return False;
1114
1115         if (!smb_io_pol_hnd("printer handle",&(r_u->handle),ps,depth))
1116                 return False;   
1117
1118         if (!prs_werror("status code", ps, depth, &(r_u->status)))
1119                 return False;
1120                 
1121         return True;
1122 }
1123
1124
1125 /*******************************************************************
1126  * read a structure.
1127  * called from spoolss_q_open_printer_ex (srv_spoolss.c)
1128  ********************************************************************/
1129
1130 BOOL spoolss_io_q_open_printer_ex(const char *desc, SPOOL_Q_OPEN_PRINTER_EX *q_u, prs_struct *ps, int depth)
1131 {
1132         if (q_u == NULL)
1133                 return False;
1134
1135         prs_debug(ps, depth, desc, "spoolss_io_q_open_printer_ex");
1136         depth++;
1137
1138         if (!prs_align(ps))
1139                 return False;
1140
1141         if (!prs_io_unistr2_p("ptr", ps, depth, &q_u->printername))
1142                 return False;
1143         if (!prs_io_unistr2("printername", ps, depth, q_u->printername))
1144                 return False;
1145         
1146         if (!prs_align(ps))
1147                 return False;
1148
1149         if (!spoolss_io_printer_default("", &q_u->printer_default, ps, depth))
1150                 return False;
1151
1152         if (!prs_uint32("user_switch", ps, depth, &q_u->user_switch))
1153                 return False;   
1154         if (!spool_io_user_level("", &q_u->user_ctr, ps, depth))
1155                 return False;
1156         
1157         return True;
1158 }
1159
1160 /*******************************************************************
1161  * write a structure.
1162  * called from static spoolss_r_open_printer_ex (srv_spoolss.c)
1163  * called from spoolss_open_printer_ex (cli_spoolss.c)
1164  ********************************************************************/
1165
1166 BOOL spoolss_io_r_open_printer_ex(const char *desc, SPOOL_R_OPEN_PRINTER_EX *r_u, prs_struct *ps, int depth)
1167 {
1168         if (r_u == NULL) return False;
1169
1170         prs_debug(ps, depth, desc, "spoolss_io_r_open_printer_ex");
1171         depth++;
1172         
1173         if (!prs_align(ps))
1174                 return False;
1175
1176         if (!smb_io_pol_hnd("printer handle",&(r_u->handle),ps,depth))
1177                 return False;
1178
1179         if (!prs_werror("status code", ps, depth, &(r_u->status)))
1180                 return False;
1181
1182         return True;
1183 }
1184
1185 /*******************************************************************
1186  * init a structure.
1187  ********************************************************************/
1188 BOOL make_spoolss_q_deleteprinterdriverex( TALLOC_CTX *mem_ctx,
1189                                            SPOOL_Q_DELETEPRINTERDRIVEREX *q_u, 
1190                                            const char *server,
1191                                            const char* arch, 
1192                                            const char* driver,
1193                                            int version)
1194 {
1195         DEBUG(5,("make_spoolss_q_deleteprinterdriverex\n"));
1196  
1197         q_u->server_ptr = (server!=NULL)?1:0;
1198         q_u->delete_flags = DPD_DELETE_UNUSED_FILES;
1199  
1200         /* these must be NULL terminated or else NT4 will
1201            complain about invalid parameters --jerry */
1202         init_unistr2(&q_u->server, server, UNI_STR_TERMINATE);
1203         init_unistr2(&q_u->arch, arch, UNI_STR_TERMINATE);
1204         init_unistr2(&q_u->driver, driver, UNI_STR_TERMINATE);
1205
1206         if (version >= 0) { 
1207                 q_u->delete_flags |= DPD_DELETE_SPECIFIC_VERSION;
1208                 q_u->version = version;
1209         }
1210
1211         return True;
1212 }
1213
1214
1215 /*******************************************************************
1216  * init a structure.
1217  ********************************************************************/
1218 BOOL make_spoolss_q_deleteprinterdriver(
1219         TALLOC_CTX *mem_ctx,
1220         SPOOL_Q_DELETEPRINTERDRIVER *q_u, 
1221         const char *server,
1222         const char* arch, 
1223         const char* driver 
1224 )
1225 {
1226         DEBUG(5,("make_spoolss_q_deleteprinterdriver\n"));
1227         
1228         q_u->server_ptr = (server!=NULL)?1:0;
1229
1230         /* these must be NULL terminated or else NT4 will
1231            complain about invalid parameters --jerry */
1232         init_unistr2(&q_u->server, server, UNI_STR_TERMINATE);
1233         init_unistr2(&q_u->arch, arch, UNI_STR_TERMINATE);
1234         init_unistr2(&q_u->driver, driver, UNI_STR_TERMINATE);
1235         
1236         return True;
1237 }
1238
1239 /*******************************************************************
1240  * make a structure.
1241  ********************************************************************/
1242
1243 BOOL make_spoolss_q_getprinterdata(SPOOL_Q_GETPRINTERDATA *q_u,
1244                                    const POLICY_HND *handle,
1245                                    const char *valuename, uint32 size)
1246 {
1247         if (q_u == NULL) return False;
1248
1249         DEBUG(5,("make_spoolss_q_getprinterdata\n"));
1250
1251         q_u->handle = *handle;
1252         init_unistr2(&q_u->valuename, valuename, UNI_STR_TERMINATE);
1253         q_u->size = size;
1254
1255         return True;
1256 }
1257
1258 /*******************************************************************
1259  * make a structure.
1260  ********************************************************************/
1261
1262 BOOL make_spoolss_q_getprinterdataex(SPOOL_Q_GETPRINTERDATAEX *q_u,
1263                                      const POLICY_HND *handle,
1264                                      const char *keyname, 
1265                                      const char *valuename, uint32 size)
1266 {
1267         if (q_u == NULL) return False;
1268
1269         DEBUG(5,("make_spoolss_q_getprinterdataex\n"));
1270
1271         q_u->handle = *handle;
1272         init_unistr2(&q_u->valuename, valuename, UNI_STR_TERMINATE);
1273         init_unistr2(&q_u->keyname, keyname, UNI_STR_TERMINATE);
1274         q_u->size = size;
1275
1276         return True;
1277 }
1278
1279 /*******************************************************************
1280  * read a structure.
1281  * called from spoolss_q_getprinterdata (srv_spoolss.c)
1282  ********************************************************************/
1283
1284 BOOL spoolss_io_q_getprinterdata(const char *desc, SPOOL_Q_GETPRINTERDATA *q_u, prs_struct *ps, int depth)
1285 {
1286         if (q_u == NULL)
1287                 return False;
1288
1289         prs_debug(ps, depth, desc, "spoolss_io_q_getprinterdata");
1290         depth++;
1291
1292         if (!prs_align(ps))
1293                 return False;
1294         if (!smb_io_pol_hnd("printer handle",&q_u->handle,ps,depth))
1295                 return False;
1296         if (!prs_align(ps))
1297                 return False;
1298         if (!smb_io_unistr2("valuename", &q_u->valuename,True,ps,depth))
1299                 return False;
1300         if (!prs_align(ps))
1301                 return False;
1302         if (!prs_uint32("size", ps, depth, &q_u->size))
1303                 return False;
1304
1305         return True;
1306 }
1307
1308 /*******************************************************************
1309  * read a structure.
1310  * called from spoolss_q_deleteprinterdata (srv_spoolss.c)
1311  ********************************************************************/
1312
1313 BOOL spoolss_io_q_deleteprinterdata(const char *desc, SPOOL_Q_DELETEPRINTERDATA *q_u, prs_struct *ps, int depth)
1314 {
1315         if (q_u == NULL)
1316                 return False;
1317
1318         prs_debug(ps, depth, desc, "spoolss_io_q_deleteprinterdata");
1319         depth++;
1320
1321         if (!prs_align(ps))
1322                 return False;
1323         if (!smb_io_pol_hnd("printer handle",&q_u->handle,ps,depth))
1324                 return False;
1325         if (!prs_align(ps))
1326                 return False;
1327         if (!smb_io_unistr2("valuename", &q_u->valuename,True,ps,depth))
1328                 return False;
1329
1330         return True;
1331 }
1332
1333 /*******************************************************************
1334  * write a structure.
1335  * called from spoolss_r_deleteprinterdata (srv_spoolss.c)
1336  ********************************************************************/
1337
1338 BOOL spoolss_io_r_deleteprinterdata(const char *desc, SPOOL_R_DELETEPRINTERDATA *r_u, prs_struct *ps, int depth)
1339 {
1340         prs_debug(ps, depth, desc, "spoolss_io_r_deleteprinterdata");
1341         depth++;
1342         if(!prs_werror("status", ps, depth, &r_u->status))
1343                 return False;
1344
1345         return True;
1346 }
1347
1348 /*******************************************************************
1349  * read a structure.
1350  * called from spoolss_q_deleteprinterdataex (srv_spoolss.c)
1351  ********************************************************************/
1352
1353 BOOL spoolss_io_q_deleteprinterdataex(const char *desc, SPOOL_Q_DELETEPRINTERDATAEX *q_u, prs_struct *ps, int depth)
1354 {
1355         if (q_u == NULL)
1356                 return False;
1357
1358         prs_debug(ps, depth, desc, "spoolss_io_q_deleteprinterdataex");
1359         depth++;
1360
1361         if (!prs_align(ps))
1362                 return False;
1363         if (!smb_io_pol_hnd("printer handle", &q_u->handle, ps, depth))
1364                 return False;
1365         
1366         if (!smb_io_unistr2("keyname  ", &q_u->keyname, True, ps, depth))
1367                 return False;
1368         if (!smb_io_unistr2("valuename", &q_u->valuename, True, ps, depth))
1369                 return False;
1370
1371         return True;
1372 }
1373
1374 /*******************************************************************
1375  * write a structure.
1376  * called from spoolss_r_deleteprinterdataex (srv_spoolss.c)
1377  ********************************************************************/
1378
1379 BOOL spoolss_io_r_deleteprinterdataex(const char *desc, SPOOL_R_DELETEPRINTERDATAEX *r_u, prs_struct *ps, int depth)
1380 {
1381         prs_debug(ps, depth, desc, "spoolss_io_r_deleteprinterdataex");
1382         depth++;
1383         
1384         if(!prs_werror("status", ps, depth, &r_u->status))
1385                 return False;
1386
1387         return True;
1388 }
1389
1390 /*******************************************************************
1391  * write a structure.
1392  * called from spoolss_r_getprinterdata (srv_spoolss.c)
1393  ********************************************************************/
1394
1395 BOOL spoolss_io_r_getprinterdata(const char *desc, SPOOL_R_GETPRINTERDATA *r_u, prs_struct *ps, int depth)
1396 {
1397         if (r_u == NULL)
1398                 return False;
1399
1400         prs_debug(ps, depth, desc, "spoolss_io_r_getprinterdata");
1401         depth++;
1402
1403         if (!prs_align(ps))
1404                 return False;
1405         if (!prs_uint32("type", ps, depth, &r_u->type))
1406                 return False;
1407         if (!prs_uint32("size", ps, depth, &r_u->size))
1408                 return False;
1409         
1410         if (UNMARSHALLING(ps) && r_u->size) {
1411                 r_u->data = PRS_ALLOC_MEM(ps, unsigned char, r_u->size);
1412                 if(!r_u->data)
1413                         return False;
1414         }
1415
1416         if (!prs_uint8s( False, "data", ps, depth, r_u->data, r_u->size ))
1417                 return False;
1418                 
1419         if (!prs_align(ps))
1420                 return False;
1421         
1422         if (!prs_uint32("needed", ps, depth, &r_u->needed))
1423                 return False;
1424         if (!prs_werror("status", ps, depth, &r_u->status))
1425                 return False;
1426                 
1427         return True;
1428 }
1429
1430 /*******************************************************************
1431  * make a structure.
1432  ********************************************************************/
1433
1434 BOOL make_spoolss_q_closeprinter(SPOOL_Q_CLOSEPRINTER *q_u, POLICY_HND *hnd)
1435 {
1436         if (q_u == NULL) return False;
1437
1438         DEBUG(5,("make_spoolss_q_closeprinter\n"));
1439
1440         memcpy(&q_u->handle, hnd, sizeof(q_u->handle));
1441
1442         return True;
1443 }
1444
1445 /*******************************************************************
1446  * read a structure.
1447  * called from static spoolss_q_abortprinter (srv_spoolss.c)
1448  * called from spoolss_abortprinter (cli_spoolss.c)
1449  ********************************************************************/
1450
1451 BOOL spoolss_io_q_abortprinter(const char *desc, SPOOL_Q_ABORTPRINTER *q_u, prs_struct *ps, int depth)
1452 {
1453         if (q_u == NULL) return False;
1454
1455         prs_debug(ps, depth, desc, "spoolss_io_q_abortprinter");
1456         depth++;
1457
1458         if (!prs_align(ps))
1459                 return False;
1460
1461         if (!smb_io_pol_hnd("printer handle",&q_u->handle,ps,depth))
1462                 return False;
1463
1464         return True;
1465 }
1466
1467 /*******************************************************************
1468  * write a structure.
1469  * called from spoolss_r_abortprinter (srv_spoolss.c)
1470  ********************************************************************/
1471
1472 BOOL spoolss_io_r_abortprinter(const char *desc, SPOOL_R_ABORTPRINTER *r_u, prs_struct *ps, int depth)
1473 {
1474         prs_debug(ps, depth, desc, "spoolss_io_r_abortprinter");
1475         depth++;
1476         if(!prs_werror("status", ps, depth, &r_u->status))
1477                 return False;
1478
1479         return True;
1480 }
1481
1482 /*******************************************************************
1483  * read a structure.
1484  * called from static spoolss_q_deleteprinter (srv_spoolss.c)
1485  * called from spoolss_deleteprinter (cli_spoolss.c)
1486  ********************************************************************/
1487
1488 BOOL spoolss_io_q_deleteprinter(const char *desc, SPOOL_Q_DELETEPRINTER *q_u, prs_struct *ps, int depth)
1489 {
1490         if (q_u == NULL) return False;
1491
1492         prs_debug(ps, depth, desc, "spoolss_io_q_deleteprinter");
1493         depth++;
1494
1495         if (!prs_align(ps))
1496                 return False;
1497
1498         if (!smb_io_pol_hnd("printer handle",&q_u->handle,ps,depth))
1499                 return False;
1500
1501         return True;
1502 }
1503
1504 /*******************************************************************
1505  * write a structure.
1506  * called from static spoolss_r_deleteprinter (srv_spoolss.c)
1507  * called from spoolss_deleteprinter (cli_spoolss.c)
1508  ********************************************************************/
1509
1510 BOOL spoolss_io_r_deleteprinter(const char *desc, SPOOL_R_DELETEPRINTER *r_u, prs_struct *ps, int depth)
1511 {
1512         prs_debug(ps, depth, desc, "spoolss_io_r_deleteprinter");
1513         depth++;
1514         
1515         if (!prs_align(ps))
1516                 return False;
1517
1518         if (!smb_io_pol_hnd("printer handle",&r_u->handle,ps,depth))
1519                 return False;
1520         if (!prs_werror("status", ps, depth, &r_u->status))
1521                 return False;
1522         
1523         return True;
1524 }
1525
1526
1527 /*******************************************************************
1528  * read a structure.
1529  * called from api_spoolss_deleteprinterdriver (srv_spoolss.c)
1530  * called from spoolss_deleteprinterdriver (cli_spoolss.c)
1531  ********************************************************************/
1532
1533 BOOL spoolss_io_q_deleteprinterdriver(const char *desc, SPOOL_Q_DELETEPRINTERDRIVER *q_u, prs_struct *ps, int depth)
1534 {
1535         if (q_u == NULL) return False;
1536
1537         prs_debug(ps, depth, desc, "spoolss_io_q_deleteprinterdriver");
1538         depth++;
1539
1540         if (!prs_align(ps))
1541                 return False;
1542
1543         if(!prs_uint32("server_ptr", ps, depth, &q_u->server_ptr))
1544                 return False;           
1545         if(!smb_io_unistr2("server", &q_u->server, q_u->server_ptr, ps, depth))
1546                 return False;
1547         if(!smb_io_unistr2("arch", &q_u->arch, True, ps, depth))
1548                 return False;
1549         if(!smb_io_unistr2("driver", &q_u->driver, True, ps, depth))
1550                 return False;
1551
1552
1553         return True;
1554 }
1555
1556
1557 /*******************************************************************
1558  * write a structure.
1559  ********************************************************************/
1560 BOOL spoolss_io_r_deleteprinterdriver(const char *desc, SPOOL_R_DELETEPRINTERDRIVER *r_u, prs_struct *ps, int depth)
1561 {
1562         if (r_u == NULL) return False;
1563
1564         prs_debug(ps, depth, desc, "spoolss_io_r_deleteprinterdriver");
1565         depth++;
1566
1567         if (!prs_align(ps))
1568                 return False;
1569
1570         if (!prs_werror("status", ps, depth, &r_u->status))
1571                 return False;
1572
1573         return True;
1574 }
1575
1576
1577 /*******************************************************************
1578  * read a structure.
1579  * called from api_spoolss_deleteprinterdriver (srv_spoolss.c)
1580  * called from spoolss_deleteprinterdriver (cli_spoolss.c)
1581  ********************************************************************/
1582
1583 BOOL spoolss_io_q_deleteprinterdriverex(const char *desc, SPOOL_Q_DELETEPRINTERDRIVEREX *q_u, prs_struct *ps, int depth)
1584 {
1585         if (q_u == NULL) return False;
1586
1587         prs_debug(ps, depth, desc, "spoolss_io_q_deleteprinterdriverex");
1588         depth++;
1589
1590         if (!prs_align(ps))
1591                 return False;
1592
1593         if(!prs_uint32("server_ptr", ps, depth, &q_u->server_ptr))
1594                 return False;           
1595         if(!smb_io_unistr2("server", &q_u->server, q_u->server_ptr, ps, depth))
1596                 return False;
1597         if(!smb_io_unistr2("arch", &q_u->arch, True, ps, depth))
1598                 return False;
1599         if(!smb_io_unistr2("driver", &q_u->driver, True, ps, depth))
1600                 return False;
1601
1602         if (!prs_align(ps))
1603                 return False;
1604
1605         if(!prs_uint32("delete_flags ", ps, depth, &q_u->delete_flags))
1606                 return False;           
1607         if(!prs_uint32("version      ", ps, depth, &q_u->version))
1608                 return False;           
1609
1610
1611         return True;
1612 }
1613
1614
1615 /*******************************************************************
1616  * write a structure.
1617  ********************************************************************/
1618 BOOL spoolss_io_r_deleteprinterdriverex(const char *desc, SPOOL_R_DELETEPRINTERDRIVEREX *r_u, prs_struct *ps, int depth)
1619 {
1620         if (r_u == NULL) return False;
1621
1622         prs_debug(ps, depth, desc, "spoolss_io_r_deleteprinterdriverex");
1623         depth++;
1624
1625         if (!prs_align(ps))
1626                 return False;
1627
1628         if (!prs_werror("status", ps, depth, &r_u->status))
1629                 return False;
1630
1631         return True;
1632 }
1633
1634
1635
1636 /*******************************************************************
1637  * read a structure.
1638  * called from static spoolss_q_closeprinter (srv_spoolss.c)
1639  * called from spoolss_closeprinter (cli_spoolss.c)
1640  ********************************************************************/
1641
1642 BOOL spoolss_io_q_closeprinter(const char *desc, SPOOL_Q_CLOSEPRINTER *q_u, prs_struct *ps, int depth)
1643 {
1644         if (q_u == NULL) return False;
1645
1646         prs_debug(ps, depth, desc, "spoolss_io_q_closeprinter");
1647         depth++;
1648
1649         if (!prs_align(ps))
1650                 return False;
1651
1652         if (!smb_io_pol_hnd("printer handle",&q_u->handle,ps,depth))
1653                 return False;
1654
1655         return True;
1656 }
1657
1658 /*******************************************************************
1659  * write a structure.
1660  * called from static spoolss_r_closeprinter (srv_spoolss.c)
1661  * called from spoolss_closeprinter (cli_spoolss.c)
1662  ********************************************************************/
1663
1664 BOOL spoolss_io_r_closeprinter(const char *desc, SPOOL_R_CLOSEPRINTER *r_u, prs_struct *ps, int depth)
1665 {
1666         prs_debug(ps, depth, desc, "spoolss_io_r_closeprinter");
1667         depth++;
1668         
1669         if (!prs_align(ps))
1670                 return False;
1671
1672         if (!smb_io_pol_hnd("printer handle",&r_u->handle,ps,depth))
1673                 return False;
1674         if (!prs_werror("status", ps, depth, &r_u->status))
1675                 return False;
1676         
1677         return True;
1678 }
1679
1680 /*******************************************************************
1681  * read a structure.
1682  * called from spoolss_q_startdocprinter (srv_spoolss.c)
1683  ********************************************************************/
1684
1685 BOOL spoolss_io_q_startdocprinter(const char *desc, SPOOL_Q_STARTDOCPRINTER *q_u, prs_struct *ps, int depth)
1686 {
1687         if (q_u == NULL) return False;
1688
1689         prs_debug(ps, depth, desc, "spoolss_io_q_startdocprinter");
1690         depth++;
1691
1692         if(!prs_align(ps))
1693                 return False;
1694
1695         if(!smb_io_pol_hnd("printer handle",&q_u->handle,ps,depth))
1696                 return False;
1697         
1698         if(!smb_io_doc_info_container("",&q_u->doc_info_container, ps, depth))
1699                 return False;
1700
1701         return True;
1702 }
1703
1704 /*******************************************************************
1705  * write a structure.
1706  * called from spoolss_r_startdocprinter (srv_spoolss.c)
1707  ********************************************************************/
1708
1709 BOOL spoolss_io_r_startdocprinter(const char *desc, SPOOL_R_STARTDOCPRINTER *r_u, prs_struct *ps, int depth)
1710 {
1711         prs_debug(ps, depth, desc, "spoolss_io_r_startdocprinter");
1712         depth++;
1713         if(!prs_uint32("jobid", ps, depth, &r_u->jobid))
1714                 return False;
1715         if(!prs_werror("status", ps, depth, &r_u->status))
1716                 return False;
1717
1718         return True;
1719 }
1720
1721 /*******************************************************************
1722  * read a structure.
1723  * called from spoolss_q_enddocprinter (srv_spoolss.c)
1724  ********************************************************************/
1725
1726 BOOL spoolss_io_q_enddocprinter(const char *desc, SPOOL_Q_ENDDOCPRINTER *q_u, prs_struct *ps, int depth)
1727 {
1728         if (q_u == NULL) return False;
1729
1730         prs_debug(ps, depth, desc, "spoolss_io_q_enddocprinter");
1731         depth++;
1732
1733         if(!prs_align(ps))
1734                 return False;
1735
1736         if(!smb_io_pol_hnd("printer handle",&q_u->handle,ps,depth))
1737                 return False;
1738
1739         return True;
1740 }
1741
1742 /*******************************************************************
1743  * write a structure.
1744  * called from spoolss_r_enddocprinter (srv_spoolss.c)
1745  ********************************************************************/
1746
1747 BOOL spoolss_io_r_enddocprinter(const char *desc, SPOOL_R_ENDDOCPRINTER *r_u, prs_struct *ps, int depth)
1748 {
1749         prs_debug(ps, depth, desc, "spoolss_io_r_enddocprinter");
1750         depth++;
1751         if(!prs_werror("status", ps, depth, &r_u->status))
1752                 return False;
1753
1754         return True;
1755 }
1756
1757 /*******************************************************************
1758  * read a structure.
1759  * called from spoolss_q_startpageprinter (srv_spoolss.c)
1760  ********************************************************************/
1761
1762 BOOL spoolss_io_q_startpageprinter(const char *desc, SPOOL_Q_STARTPAGEPRINTER *q_u, prs_struct *ps, int depth)
1763 {
1764         if (q_u == NULL) return False;
1765
1766         prs_debug(ps, depth, desc, "spoolss_io_q_startpageprinter");
1767         depth++;
1768
1769         if(!prs_align(ps))
1770                 return False;
1771
1772         if(!smb_io_pol_hnd("printer handle",&q_u->handle,ps,depth))
1773                 return False;
1774
1775         return True;
1776 }
1777
1778 /*******************************************************************
1779  * write a structure.
1780  * called from spoolss_r_startpageprinter (srv_spoolss.c)
1781  ********************************************************************/
1782
1783 BOOL spoolss_io_r_startpageprinter(const char *desc, SPOOL_R_STARTPAGEPRINTER *r_u, prs_struct *ps, int depth)
1784 {
1785         prs_debug(ps, depth, desc, "spoolss_io_r_startpageprinter");
1786         depth++;
1787         if(!prs_werror("status", ps, depth, &r_u->status))
1788                 return False;
1789
1790         return True;
1791 }
1792
1793 /*******************************************************************
1794  * read a structure.
1795  * called from spoolss_q_endpageprinter (srv_spoolss.c)
1796  ********************************************************************/
1797
1798 BOOL spoolss_io_q_endpageprinter(const char *desc, SPOOL_Q_ENDPAGEPRINTER *q_u, prs_struct *ps, int depth)
1799 {
1800         if (q_u == NULL) return False;
1801
1802         prs_debug(ps, depth, desc, "spoolss_io_q_endpageprinter");
1803         depth++;
1804
1805         if(!prs_align(ps))
1806                 return False;
1807
1808         if(!smb_io_pol_hnd("printer handle",&q_u->handle,ps,depth))
1809                 return False;
1810
1811         return True;
1812 }
1813
1814 /*******************************************************************
1815  * write a structure.
1816  * called from spoolss_r_endpageprinter (srv_spoolss.c)
1817  ********************************************************************/
1818
1819 BOOL spoolss_io_r_endpageprinter(const char *desc, SPOOL_R_ENDPAGEPRINTER *r_u, prs_struct *ps, int depth)
1820 {
1821         prs_debug(ps, depth, desc, "spoolss_io_r_endpageprinter");
1822         depth++;
1823         if(!prs_werror("status", ps, depth, &r_u->status))
1824                 return False;
1825
1826         return True;
1827 }
1828
1829 /*******************************************************************
1830  * read a structure.
1831  * called from spoolss_q_writeprinter (srv_spoolss.c)
1832  ********************************************************************/
1833
1834 BOOL spoolss_io_q_writeprinter(const char *desc, SPOOL_Q_WRITEPRINTER *q_u, prs_struct *ps, int depth)
1835 {
1836         if (q_u == NULL) return False;
1837
1838         prs_debug(ps, depth, desc, "spoolss_io_q_writeprinter");
1839         depth++;
1840
1841         if(!prs_align(ps))
1842                 return False;
1843
1844         if(!smb_io_pol_hnd("printer handle",&q_u->handle,ps,depth))
1845                 return False;
1846         if(!prs_uint32("buffer_size", ps, depth, &q_u->buffer_size))
1847                 return False;
1848         
1849         if (q_u->buffer_size!=0)
1850         {
1851                 if (UNMARSHALLING(ps))
1852                         q_u->buffer=PRS_ALLOC_MEM(ps, uint8, q_u->buffer_size);
1853                 if(q_u->buffer == NULL)
1854                         return False;   
1855                 if(!prs_uint8s(True, "buffer", ps, depth, q_u->buffer, q_u->buffer_size))
1856                         return False;
1857         }
1858         if(!prs_align(ps))
1859                 return False;
1860         if(!prs_uint32("buffer_size2", ps, depth, &q_u->buffer_size2))
1861                 return False;
1862
1863         return True;
1864 }
1865
1866 /*******************************************************************
1867  * write a structure.
1868  * called from spoolss_r_writeprinter (srv_spoolss.c)
1869  ********************************************************************/
1870
1871 BOOL spoolss_io_r_writeprinter(const char *desc, SPOOL_R_WRITEPRINTER *r_u, prs_struct *ps, int depth)
1872 {
1873         prs_debug(ps, depth, desc, "spoolss_io_r_writeprinter");
1874         depth++;
1875         if(!prs_uint32("buffer_written", ps, depth, &r_u->buffer_written))
1876                 return False;
1877         if(!prs_werror("status", ps, depth, &r_u->status))
1878                 return False;
1879
1880         return True;
1881 }
1882
1883 /*******************************************************************
1884  * read a structure.
1885  * called from spoolss_q_rffpcnex (srv_spoolss.c)
1886  ********************************************************************/
1887
1888 BOOL spoolss_io_q_rffpcnex(const char *desc, SPOOL_Q_RFFPCNEX *q_u, prs_struct *ps, int depth)
1889 {
1890         prs_debug(ps, depth, desc, "spoolss_io_q_rffpcnex");
1891         depth++;
1892
1893         if(!prs_align(ps))
1894                 return False;
1895
1896         if(!smb_io_pol_hnd("printer handle", &q_u->handle, ps, depth))
1897                 return False;
1898         if(!prs_uint32("flags", ps, depth, &q_u->flags))
1899                 return False;
1900         if(!prs_uint32("options", ps, depth, &q_u->options))
1901                 return False;
1902         if(!prs_uint32("localmachine_ptr", ps, depth, &q_u->localmachine_ptr))
1903                 return False;
1904         if(!smb_io_unistr2("localmachine", &q_u->localmachine, q_u->localmachine_ptr, ps, depth))
1905                 return False;
1906
1907         if(!prs_align(ps))
1908                 return False;
1909                 
1910         if(!prs_uint32("printerlocal", ps, depth, &q_u->printerlocal))
1911                 return False;
1912
1913         if(!prs_uint32("option_ptr", ps, depth, &q_u->option_ptr))
1914                 return False;
1915         
1916         if (q_u->option_ptr!=0) {
1917         
1918                 if (UNMARSHALLING(ps))
1919                         if((q_u->option=PRS_ALLOC_MEM(ps,SPOOL_NOTIFY_OPTION,1)) == NULL)
1920                                 return False;
1921         
1922                 if(!smb_io_notify_option("notify option", q_u->option, ps, depth))
1923                         return False;
1924         }
1925         
1926         return True;
1927 }
1928
1929 /*******************************************************************
1930  * write a structure.
1931  * called from spoolss_r_rffpcnex (srv_spoolss.c)
1932  ********************************************************************/
1933
1934 BOOL spoolss_io_r_rffpcnex(const char *desc, SPOOL_R_RFFPCNEX *r_u, prs_struct *ps, int depth)
1935 {
1936         prs_debug(ps, depth, desc, "spoolss_io_r_rffpcnex");
1937         depth++;
1938
1939         if(!prs_werror("status", ps, depth, &r_u->status))
1940                 return False;
1941
1942         return True;
1943 }
1944
1945 /*******************************************************************
1946  * read a structure.
1947  * called from spoolss_q_rfnpcnex (srv_spoolss.c)
1948  ********************************************************************/
1949
1950 BOOL spoolss_io_q_rfnpcnex(const char *desc, SPOOL_Q_RFNPCNEX *q_u, prs_struct *ps, int depth)
1951 {
1952         prs_debug(ps, depth, desc, "spoolss_io_q_rfnpcnex");
1953         depth++;
1954
1955         if(!prs_align(ps))
1956                 return False;
1957
1958         if(!smb_io_pol_hnd("printer handle",&q_u->handle,ps,depth))
1959                 return False;
1960
1961         if(!prs_uint32("change", ps, depth, &q_u->change))
1962                 return False;
1963         
1964         if(!prs_uint32("option_ptr", ps, depth, &q_u->option_ptr))
1965                 return False;
1966         
1967         if (q_u->option_ptr!=0) {
1968         
1969                 if (UNMARSHALLING(ps))
1970                         if((q_u->option=PRS_ALLOC_MEM(ps,SPOOL_NOTIFY_OPTION,1)) == NULL)
1971                                 return False;
1972         
1973                 if(!smb_io_notify_option("notify option", q_u->option, ps, depth))
1974                         return False;
1975         }
1976
1977         return True;
1978 }
1979
1980 /*******************************************************************
1981  * write a structure.
1982  * called from spoolss_r_rfnpcnex (srv_spoolss.c)
1983  ********************************************************************/
1984
1985 BOOL spoolss_io_r_rfnpcnex(const char *desc, SPOOL_R_RFNPCNEX *r_u, prs_struct *ps, int depth)
1986 {
1987         prs_debug(ps, depth, desc, "spoolss_io_r_rfnpcnex");
1988         depth++;
1989
1990         if(!prs_align(ps))
1991                 return False;
1992                 
1993         if (!prs_uint32("info_ptr", ps, depth, &r_u->info_ptr))
1994                 return False;
1995
1996         if(!smb_io_notify_info("notify info", &r_u->info ,ps,depth))
1997                 return False;
1998         
1999         if(!prs_align(ps))
2000                 return False;
2001         if(!prs_werror("status", ps, depth, &r_u->status))
2002                 return False;
2003
2004         return True;
2005 }
2006
2007 /*******************************************************************
2008  * return the length of a uint16 (obvious, but the code is clean)
2009  ********************************************************************/
2010
2011 static uint32 size_of_uint16(uint16 *value)
2012 {
2013         return (sizeof(*value));
2014 }
2015
2016 /*******************************************************************
2017  * return the length of a uint32 (obvious, but the code is clean)
2018  ********************************************************************/
2019
2020 static uint32 size_of_uint32(uint32 *value)
2021 {
2022         return (sizeof(*value));
2023 }
2024
2025 /*******************************************************************
2026  * return the length of a NTTIME (obvious, but the code is clean)
2027  ********************************************************************/
2028
2029 static uint32 size_of_nttime(NTTIME *value)
2030 {
2031         return (sizeof(*value));
2032 }
2033
2034 /*******************************************************************
2035  * return the length of a uint32 (obvious, but the code is clean)
2036  ********************************************************************/
2037
2038 static uint32 size_of_device_mode(DEVICEMODE *devmode)
2039 {
2040         if (devmode==NULL)
2041                 return (4);
2042         else 
2043                 return (4+devmode->size+devmode->driverextra);
2044 }
2045
2046 /*******************************************************************
2047  * return the length of a uint32 (obvious, but the code is clean)
2048  ********************************************************************/
2049
2050 static uint32 size_of_systemtime(SYSTEMTIME *systime)
2051 {
2052         if (systime==NULL)
2053                 return (4);
2054         else 
2055                 return (sizeof(SYSTEMTIME) +4);
2056 }
2057
2058 /*******************************************************************
2059  Parse a DEVMODE structure and its relative pointer.
2060 ********************************************************************/
2061
2062 static BOOL smb_io_reldevmode(const char *desc, RPC_BUFFER *buffer, int depth, DEVICEMODE **devmode)
2063 {
2064         prs_struct *ps=&buffer->prs;
2065
2066         prs_debug(ps, depth, desc, "smb_io_reldevmode");
2067         depth++;
2068
2069         if (MARSHALLING(ps)) {
2070                 uint32 struct_offset = prs_offset(ps);
2071                 uint32 relative_offset;
2072                 
2073                 if (*devmode == NULL) {
2074                         relative_offset=0;
2075                         if (!prs_uint32("offset", ps, depth, &relative_offset))
2076                                 return False;
2077                         DEBUG(8, ("boing, the devmode was NULL\n"));
2078                         
2079                         return True;
2080                 }
2081                 
2082                 buffer->string_at_end -= ((*devmode)->size + (*devmode)->driverextra);
2083                 
2084                 if(!prs_set_offset(ps, buffer->string_at_end))
2085                         return False;
2086                 
2087                 /* write the DEVMODE */
2088                 if (!spoolss_io_devmode(desc, ps, depth, *devmode))
2089                         return False;
2090
2091                 if(!prs_set_offset(ps, struct_offset))
2092                         return False;
2093                 
2094                 relative_offset=buffer->string_at_end - buffer->struct_start;
2095                 /* write its offset */
2096                 if (!prs_uint32("offset", ps, depth, &relative_offset))
2097                         return False;
2098         }
2099         else {
2100                 uint32 old_offset;
2101                 
2102                 /* read the offset */
2103                 if (!prs_uint32("offset", ps, depth, &buffer->string_at_end))
2104                         return False;
2105                 if (buffer->string_at_end == 0) {
2106                         *devmode = NULL;
2107                         return True;
2108                 }
2109
2110                 old_offset = prs_offset(ps);
2111                 if(!prs_set_offset(ps, buffer->string_at_end + buffer->struct_start))
2112                         return False;
2113
2114                 /* read the string */
2115                 if((*devmode=PRS_ALLOC_MEM(ps,DEVICEMODE,1)) == NULL)
2116                         return False;
2117                 if (!spoolss_io_devmode(desc, ps, depth, *devmode))
2118                         return False;
2119
2120                 if(!prs_set_offset(ps, old_offset))
2121                         return False;
2122         }
2123         return True;
2124 }
2125
2126 /*******************************************************************
2127  Parse a PRINTER_INFO_0 structure.
2128 ********************************************************************/  
2129
2130 BOOL smb_io_printer_info_0(const char *desc, RPC_BUFFER *buffer, PRINTER_INFO_0 *info, int depth)
2131 {
2132         prs_struct *ps=&buffer->prs;
2133
2134         prs_debug(ps, depth, desc, "smb_io_printer_info_0");
2135         depth++;        
2136         
2137         buffer->struct_start=prs_offset(ps);
2138
2139         if (!smb_io_relstr("printername", buffer, depth, &info->printername))
2140                 return False;
2141         if (!smb_io_relstr("servername", buffer, depth, &info->servername))
2142                 return False;
2143         
2144         if(!prs_uint32("cjobs", ps, depth, &info->cjobs))
2145                 return False;
2146         if(!prs_uint32("total_jobs", ps, depth, &info->total_jobs))
2147                 return False;
2148         if(!prs_uint32("total_bytes", ps, depth, &info->total_bytes))
2149                 return False;
2150
2151         if(!prs_uint16("year", ps, depth, &info->year))
2152                 return False;
2153         if(!prs_uint16("month", ps, depth, &info->month))
2154                 return False;
2155         if(!prs_uint16("dayofweek", ps, depth, &info->dayofweek))
2156                 return False;
2157         if(!prs_uint16("day", ps, depth, &info->day))
2158                 return False;
2159         if(!prs_uint16("hour", ps, depth, &info->hour))
2160                 return False;
2161         if(!prs_uint16("minute", ps, depth, &info->minute))
2162                 return False;
2163         if(!prs_uint16("second", ps, depth, &info->second))
2164                 return False;
2165         if(!prs_uint16("milliseconds", ps, depth, &info->milliseconds))
2166                 return False;
2167
2168         if(!prs_uint32("global_counter", ps, depth, &info->global_counter))
2169                 return False;
2170         if(!prs_uint32("total_pages", ps, depth, &info->total_pages))
2171                 return False;
2172
2173         if(!prs_uint16("major_version", ps, depth, &info->major_version))
2174                 return False;
2175         if(!prs_uint16("build_version", ps, depth, &info->build_version))
2176                 return False;
2177         if(!prs_uint32("unknown7", ps, depth, &info->unknown7))
2178                 return False;
2179         if(!prs_uint32("unknown8", ps, depth, &info->unknown8))
2180                 return False;
2181         if(!prs_uint32("unknown9", ps, depth, &info->unknown9))
2182                 return False;
2183         if(!prs_uint32("session_counter", ps, depth, &info->session_counter))
2184                 return False;
2185         if(!prs_uint32("unknown11", ps, depth, &info->unknown11))
2186                 return False;
2187         if(!prs_uint32("printer_errors", ps, depth, &info->printer_errors))
2188                 return False;
2189         if(!prs_uint32("unknown13", ps, depth, &info->unknown13))
2190                 return False;
2191         if(!prs_uint32("unknown14", ps, depth, &info->unknown14))
2192                 return False;
2193         if(!prs_uint32("unknown15", ps, depth, &info->unknown15))
2194                 return False;
2195         if(!prs_uint32("unknown16", ps, depth, &info->unknown16))
2196                 return False;
2197         if(!prs_uint32("change_id", ps, depth, &info->change_id))
2198                 return False;
2199         if(!prs_uint32("unknown18", ps, depth, &info->unknown18))
2200                 return False;
2201         if(!prs_uint32("status"   , ps, depth, &info->status))
2202                 return False;
2203         if(!prs_uint32("unknown20", ps, depth, &info->unknown20))
2204                 return False;
2205         if(!prs_uint32("c_setprinter", ps, depth, &info->c_setprinter))
2206                 return False;
2207         if(!prs_uint16("unknown22", ps, depth, &info->unknown22))
2208                 return False;
2209         if(!prs_uint16("unknown23", ps, depth, &info->unknown23))
2210                 return False;
2211         if(!prs_uint16("unknown24", ps, depth, &info->unknown24))
2212                 return False;
2213         if(!prs_uint16("unknown25", ps, depth, &info->unknown25))
2214                 return False;
2215         if(!prs_uint16("unknown26", ps, depth, &info->unknown26))
2216                 return False;
2217         if(!prs_uint16("unknown27", ps, depth, &info->unknown27))
2218                 return False;
2219         if(!prs_uint16("unknown28", ps, depth, &info->unknown28))
2220                 return False;
2221         if(!prs_uint16("unknown29", ps, depth, &info->unknown29))
2222                 return False;
2223
2224         return True;
2225 }
2226
2227 /*******************************************************************
2228  Parse a PRINTER_INFO_1 structure.
2229 ********************************************************************/  
2230
2231 BOOL smb_io_printer_info_1(const char *desc, RPC_BUFFER *buffer, PRINTER_INFO_1 *info, int depth)
2232 {
2233         prs_struct *ps=&buffer->prs;
2234
2235         prs_debug(ps, depth, desc, "smb_io_printer_info_1");
2236         depth++;        
2237         
2238         buffer->struct_start=prs_offset(ps);
2239
2240         if (!prs_uint32("flags", ps, depth, &info->flags))
2241                 return False;
2242         if (!smb_io_relstr("description", buffer, depth, &info->description))
2243                 return False;
2244         if (!smb_io_relstr("name", buffer, depth, &info->name))
2245                 return False;
2246         if (!smb_io_relstr("comment", buffer, depth, &info->comment))
2247                 return False;   
2248
2249         return True;
2250 }
2251
2252 /*******************************************************************
2253  Parse a PRINTER_INFO_2 structure.
2254 ********************************************************************/  
2255
2256 BOOL smb_io_printer_info_2(const char *desc, RPC_BUFFER *buffer, PRINTER_INFO_2 *info, int depth)
2257 {
2258         prs_struct *ps=&buffer->prs;
2259         uint32 dm_offset, sd_offset, current_offset;
2260         uint32 dummy_value = 0, has_secdesc = 0;
2261
2262         prs_debug(ps, depth, desc, "smb_io_printer_info_2");
2263         depth++;        
2264         
2265         buffer->struct_start=prs_offset(ps);
2266         
2267         if (!smb_io_relstr("servername", buffer, depth, &info->servername))
2268                 return False;
2269         if (!smb_io_relstr("printername", buffer, depth, &info->printername))
2270                 return False;
2271         if (!smb_io_relstr("sharename", buffer, depth, &info->sharename))
2272                 return False;
2273         if (!smb_io_relstr("portname", buffer, depth, &info->portname))
2274                 return False;
2275         if (!smb_io_relstr("drivername", buffer, depth, &info->drivername))
2276                 return False;
2277         if (!smb_io_relstr("comment", buffer, depth, &info->comment))
2278                 return False;
2279         if (!smb_io_relstr("location", buffer, depth, &info->location))
2280                 return False;
2281
2282         /* save current offset and wind forwared by a uint32 */
2283         dm_offset = prs_offset(ps);
2284         if (!prs_uint32("devmode", ps, depth, &dummy_value))
2285                 return False;
2286         
2287         if (!smb_io_relstr("sepfile", buffer, depth, &info->sepfile))
2288                 return False;
2289         if (!smb_io_relstr("printprocessor", buffer, depth, &info->printprocessor))
2290                 return False;
2291         if (!smb_io_relstr("datatype", buffer, depth, &info->datatype))
2292                 return False;
2293         if (!smb_io_relstr("parameters", buffer, depth, &info->parameters))
2294                 return False;
2295
2296         /* save current offset for the sec_desc */
2297         sd_offset = prs_offset(ps);
2298         if (!prs_uint32("sec_desc", ps, depth, &has_secdesc))
2299                 return False;
2300
2301         
2302         /* save current location so we can pick back up here */
2303         current_offset = prs_offset(ps);
2304         
2305         /* parse the devmode */
2306         if (!prs_set_offset(ps, dm_offset))
2307                 return False;
2308         if (!smb_io_reldevmode("devmode", buffer, depth, &info->devmode))
2309                 return False;
2310         
2311         /* parse the sec_desc */
2312         if (info->secdesc) {
2313                 if (!prs_set_offset(ps, sd_offset))
2314                         return False;
2315                 if (!smb_io_relsecdesc("secdesc", buffer, depth, &info->secdesc))
2316                         return False;
2317         }
2318
2319         /* pick up where we left off */
2320         if (!prs_set_offset(ps, current_offset))
2321                 return False;
2322
2323         if (!prs_uint32("attributes", ps, depth, &info->attributes))
2324                 return False;
2325         if (!prs_uint32("priority", ps, depth, &info->priority))
2326                 return False;
2327         if (!prs_uint32("defpriority", ps, depth, &info->defaultpriority))
2328                 return False;
2329         if (!prs_uint32("starttime", ps, depth, &info->starttime))
2330                 return False;
2331         if (!prs_uint32("untiltime", ps, depth, &info->untiltime))
2332                 return False;
2333         if (!prs_uint32("status", ps, depth, &info->status))
2334                 return False;
2335         if (!prs_uint32("jobs", ps, depth, &info->cjobs))
2336                 return False;
2337         if (!prs_uint32("averageppm", ps, depth, &info->averageppm))
2338                 return False;
2339
2340         return True;
2341 }
2342
2343 /*******************************************************************
2344  Parse a PRINTER_INFO_3 structure.
2345 ********************************************************************/  
2346
2347 BOOL smb_io_printer_info_3(const char *desc, RPC_BUFFER *buffer, PRINTER_INFO_3 *info, int depth)
2348 {
2349         prs_struct *ps=&buffer->prs;
2350
2351         prs_debug(ps, depth, desc, "smb_io_printer_info_3");
2352         depth++;        
2353         
2354         buffer->struct_start=prs_offset(ps);
2355         
2356         if (!prs_uint32("flags", ps, depth, &info->flags))
2357                 return False;
2358         if (!sec_io_desc("sec_desc", &info->secdesc, ps, depth))
2359                 return False;
2360
2361         return True;
2362 }
2363
2364 /*******************************************************************
2365  Parse a PRINTER_INFO_4 structure.
2366 ********************************************************************/  
2367
2368 BOOL smb_io_printer_info_4(const char *desc, RPC_BUFFER *buffer, PRINTER_INFO_4 *info, int depth)
2369 {
2370         prs_struct *ps=&buffer->prs;
2371
2372         prs_debug(ps, depth, desc, "smb_io_printer_info_4");
2373         depth++;        
2374         
2375         buffer->struct_start=prs_offset(ps);
2376         
2377         if (!smb_io_relstr("printername", buffer, depth, &info->printername))
2378                 return False;
2379         if (!smb_io_relstr("servername", buffer, depth, &info->servername))
2380                 return False;
2381         if (!prs_uint32("attributes", ps, depth, &info->attributes))
2382                 return False;
2383         return True;
2384 }
2385
2386 /*******************************************************************
2387  Parse a PRINTER_INFO_5 structure.
2388 ********************************************************************/  
2389
2390 BOOL smb_io_printer_info_5(const char *desc, RPC_BUFFER *buffer, PRINTER_INFO_5 *info, int depth)
2391 {
2392         prs_struct *ps=&buffer->prs;
2393
2394         prs_debug(ps, depth, desc, "smb_io_printer_info_5");
2395         depth++;        
2396         
2397         buffer->struct_start=prs_offset(ps);
2398         
2399         if (!smb_io_relstr("printername", buffer, depth, &info->printername))
2400                 return False;
2401         if (!smb_io_relstr("portname", buffer, depth, &info->portname))
2402                 return False;
2403         if (!prs_uint32("attributes", ps, depth, &info->attributes))
2404                 return False;
2405         if (!prs_uint32("device_not_selected_timeout", ps, depth, &info->device_not_selected_timeout))
2406                 return False;
2407         if (!prs_uint32("transmission_retry_timeout", ps, depth, &info->transmission_retry_timeout))
2408                 return False;
2409         return True;
2410 }
2411
2412 /*******************************************************************
2413  Parse a PRINTER_INFO_7 structure.
2414 ********************************************************************/  
2415
2416 BOOL smb_io_printer_info_7(const char *desc, RPC_BUFFER *buffer, PRINTER_INFO_7 *info, int depth)
2417 {
2418         prs_struct *ps=&buffer->prs;
2419
2420         prs_debug(ps, depth, desc, "smb_io_printer_info_7");
2421         depth++;        
2422         
2423         buffer->struct_start=prs_offset(ps);
2424         
2425         if (!smb_io_relstr("guid", buffer, depth, &info->guid))
2426                 return False;
2427         if (!prs_uint32("action", ps, depth, &info->action))
2428                 return False;
2429         return True;
2430 }
2431
2432 /*******************************************************************
2433  Parse a PORT_INFO_1 structure.
2434 ********************************************************************/  
2435
2436 BOOL smb_io_port_info_1(const char *desc, RPC_BUFFER *buffer, PORT_INFO_1 *info, int depth)
2437 {
2438         prs_struct *ps=&buffer->prs;
2439
2440         prs_debug(ps, depth, desc, "smb_io_port_info_1");
2441         depth++;        
2442         
2443         buffer->struct_start=prs_offset(ps);
2444         
2445         if (!smb_io_relstr("port_name", buffer, depth, &info->port_name))
2446                 return False;
2447
2448         return True;
2449 }
2450
2451 /*******************************************************************
2452  Parse a PORT_INFO_2 structure.
2453 ********************************************************************/  
2454
2455 BOOL smb_io_port_info_2(const char *desc, RPC_BUFFER *buffer, PORT_INFO_2 *info, int depth)
2456 {
2457         prs_struct *ps=&buffer->prs;
2458
2459         prs_debug(ps, depth, desc, "smb_io_port_info_2");
2460         depth++;        
2461         
2462         buffer->struct_start=prs_offset(ps);
2463         
2464         if (!smb_io_relstr("port_name", buffer, depth, &info->port_name))
2465                 return False;
2466         if (!smb_io_relstr("monitor_name", buffer, depth, &info->monitor_name))
2467                 return False;
2468         if (!smb_io_relstr("description", buffer, depth, &info->description))
2469                 return False;
2470         if (!prs_uint32("port_type", ps, depth, &info->port_type))
2471                 return False;
2472         if (!prs_uint32("reserved", ps, depth, &info->reserved))
2473                 return False;
2474
2475         return True;
2476 }
2477
2478 /*******************************************************************
2479  Parse a DRIVER_INFO_1 structure.
2480 ********************************************************************/
2481
2482 BOOL smb_io_printer_driver_info_1(const char *desc, RPC_BUFFER *buffer, DRIVER_INFO_1 *info, int depth) 
2483 {
2484         prs_struct *ps=&buffer->prs;
2485
2486         prs_debug(ps, depth, desc, "smb_io_printer_driver_info_1");
2487         depth++;        
2488         
2489         buffer->struct_start=prs_offset(ps);
2490
2491         if (!smb_io_relstr("name", buffer, depth, &info->name))
2492                 return False;
2493
2494         return True;
2495 }
2496
2497 /*******************************************************************
2498  Parse a DRIVER_INFO_2 structure.
2499 ********************************************************************/
2500
2501 BOOL smb_io_printer_driver_info_2(const char *desc, RPC_BUFFER *buffer, DRIVER_INFO_2 *info, int depth) 
2502 {
2503         prs_struct *ps=&buffer->prs;
2504
2505         prs_debug(ps, depth, desc, "smb_io_printer_driver_info_2");
2506         depth++;        
2507         
2508         buffer->struct_start=prs_offset(ps);
2509
2510         if (!prs_uint32("version", ps, depth, &info->version))
2511                 return False;
2512         if (!smb_io_relstr("name", buffer, depth, &info->name))
2513                 return False;
2514         if (!smb_io_relstr("architecture", buffer, depth, &info->architecture))
2515                 return False;
2516         if (!smb_io_relstr("driverpath", buffer, depth, &info->driverpath))
2517                 return False;
2518         if (!smb_io_relstr("datafile", buffer, depth, &info->datafile))
2519                 return False;
2520         if (!smb_io_relstr("configfile", buffer, depth, &info->configfile))
2521                 return False;
2522
2523         return True;
2524 }
2525
2526 /*******************************************************************
2527  Parse a DRIVER_INFO_3 structure.
2528 ********************************************************************/
2529
2530 BOOL smb_io_printer_driver_info_3(const char *desc, RPC_BUFFER *buffer, DRIVER_INFO_3 *info, int depth)
2531 {
2532         prs_struct *ps=&buffer->prs;
2533
2534         prs_debug(ps, depth, desc, "smb_io_printer_driver_info_3");
2535         depth++;        
2536         
2537         buffer->struct_start=prs_offset(ps);
2538
2539         if (!prs_uint32("version", ps, depth, &info->version))
2540                 return False;
2541         if (!smb_io_relstr("name", buffer, depth, &info->name))
2542                 return False;
2543         if (!smb_io_relstr("architecture", buffer, depth, &info->architecture))
2544                 return False;
2545         if (!smb_io_relstr("driverpath", buffer, depth, &info->driverpath))
2546                 return False;
2547         if (!smb_io_relstr("datafile", buffer, depth, &info->datafile))
2548                 return False;
2549         if (!smb_io_relstr("configfile", buffer, depth, &info->configfile))
2550                 return False;
2551         if (!smb_io_relstr("helpfile", buffer, depth, &info->helpfile))
2552                 return False;
2553
2554         if (!smb_io_relarraystr("dependentfiles", buffer, depth, &info->dependentfiles))
2555                 return False;
2556
2557         if (!smb_io_relstr("monitorname", buffer, depth, &info->monitorname))
2558                 return False;
2559         if (!smb_io_relstr("defaultdatatype", buffer, depth, &info->defaultdatatype))
2560                 return False;
2561
2562         return True;
2563 }
2564
2565 /*******************************************************************
2566  Parse a DRIVER_INFO_6 structure.
2567 ********************************************************************/
2568
2569 BOOL smb_io_printer_driver_info_6(const char *desc, RPC_BUFFER *buffer, DRIVER_INFO_6 *info, int depth)
2570 {
2571         prs_struct *ps=&buffer->prs;
2572
2573         prs_debug(ps, depth, desc, "smb_io_printer_driver_info_6");
2574         depth++;        
2575         
2576         buffer->struct_start=prs_offset(ps);
2577
2578         if (!prs_uint32("version", ps, depth, &info->version))
2579                 return False;
2580         if (!smb_io_relstr("name", buffer, depth, &info->name))
2581                 return False;
2582         if (!smb_io_relstr("architecture", buffer, depth, &info->architecture))
2583                 return False;
2584         if (!smb_io_relstr("driverpath", buffer, depth, &info->driverpath))
2585                 return False;
2586         if (!smb_io_relstr("datafile", buffer, depth, &info->datafile))
2587                 return False;
2588         if (!smb_io_relstr("configfile", buffer, depth, &info->configfile))
2589                 return False;
2590         if (!smb_io_relstr("helpfile", buffer, depth, &info->helpfile))
2591                 return False;
2592
2593         if (!smb_io_relarraystr("dependentfiles", buffer, depth, &info->dependentfiles))
2594                 return False;
2595
2596         if (!smb_io_relstr("monitorname", buffer, depth, &info->monitorname))
2597                 return False;
2598         if (!smb_io_relstr("defaultdatatype", buffer, depth, &info->defaultdatatype))
2599                 return False;
2600
2601         if (!smb_io_relarraystr("previousdrivernames", buffer, depth, &info->previousdrivernames))
2602                 return False;
2603
2604         if (!prs_uint32("date.low", ps, depth, &info->driver_date.low))
2605                 return False;
2606         if (!prs_uint32("date.high", ps, depth, &info->driver_date.high))
2607                 return False;
2608
2609         if (!prs_uint32("padding", ps, depth, &info->padding))
2610                 return False;
2611
2612         if (!prs_uint32("driver_version_low", ps, depth, &info->driver_version_low))
2613                 return False;
2614
2615         if (!prs_uint32("driver_version_high", ps, depth, &info->driver_version_high))
2616                 return False;
2617
2618         if (!smb_io_relstr("mfgname", buffer, depth, &info->mfgname))
2619                 return False;
2620         if (!smb_io_relstr("oem_url", buffer, depth, &info->oem_url))
2621                 return False;
2622         if (!smb_io_relstr("hardware_id", buffer, depth, &info->hardware_id))
2623                 return False;
2624         if (!smb_io_relstr("provider", buffer, depth, &info->provider))
2625                 return False;
2626         
2627         return True;
2628 }
2629
2630 /*******************************************************************
2631  Parse a JOB_INFO_1 structure.
2632 ********************************************************************/  
2633
2634 BOOL smb_io_job_info_1(const char *desc, RPC_BUFFER *buffer, JOB_INFO_1 *info, int depth)
2635 {
2636         prs_struct *ps=&buffer->prs;
2637
2638         prs_debug(ps, depth, desc, "smb_io_job_info_1");
2639         depth++;        
2640         
2641         buffer->struct_start=prs_offset(ps);
2642
2643         if (!prs_uint32("jobid", ps, depth, &info->jobid))
2644                 return False;
2645         if (!smb_io_relstr("printername", buffer, depth, &info->printername))
2646                 return False;
2647         if (!smb_io_relstr("machinename", buffer, depth, &info->machinename))
2648                 return False;
2649         if (!smb_io_relstr("username", buffer, depth, &info->username))
2650                 return False;
2651         if (!smb_io_relstr("document", buffer, depth, &info->document))
2652                 return False;
2653         if (!smb_io_relstr("datatype", buffer, depth, &info->datatype))
2654                 return False;
2655         if (!smb_io_relstr("text_status", buffer, depth, &info->text_status))
2656                 return False;
2657         if (!prs_uint32("status", ps, depth, &info->status))
2658                 return False;
2659         if (!prs_uint32("priority", ps, depth, &info->priority))
2660                 return False;
2661         if (!prs_uint32("position", ps, depth, &info->position))
2662                 return False;
2663         if (!prs_uint32("totalpages", ps, depth, &info->totalpages))
2664                 return False;
2665         if (!prs_uint32("pagesprinted", ps, depth, &info->pagesprinted))
2666                 return False;
2667         if (!spoolss_io_system_time("submitted", ps, depth, &info->submitted))
2668                 return False;
2669
2670         return True;
2671 }
2672
2673 /*******************************************************************
2674  Parse a JOB_INFO_2 structure.
2675 ********************************************************************/  
2676
2677 BOOL smb_io_job_info_2(const char *desc, RPC_BUFFER *buffer, JOB_INFO_2 *info, int depth)
2678 {       
2679         uint32 pipo=0;
2680         prs_struct *ps=&buffer->prs;
2681         
2682         prs_debug(ps, depth, desc, "smb_io_job_info_2");
2683         depth++;        
2684
2685         buffer->struct_start=prs_offset(ps);
2686         
2687         if (!prs_uint32("jobid",ps, depth, &info->jobid))
2688                 return False;
2689         if (!smb_io_relstr("printername", buffer, depth, &info->printername))
2690                 return False;
2691         if (!smb_io_relstr("machinename", buffer, depth, &info->machinename))
2692                 return False;
2693         if (!smb_io_relstr("username", buffer, depth, &info->username))
2694                 return False;
2695         if (!smb_io_relstr("document", buffer, depth, &info->document))
2696                 return False;
2697         if (!smb_io_relstr("notifyname", buffer, depth, &info->notifyname))
2698                 return False;
2699         if (!smb_io_relstr("datatype", buffer, depth, &info->datatype))
2700                 return False;
2701
2702         if (!smb_io_relstr("printprocessor", buffer, depth, &info->printprocessor))
2703                 return False;
2704         if (!smb_io_relstr("parameters", buffer, depth, &info->parameters))
2705                 return False;
2706         if (!smb_io_relstr("drivername", buffer, depth, &info->drivername))
2707                 return False;
2708         if (!smb_io_reldevmode("devmode", buffer, depth, &info->devmode))
2709                 return False;
2710         if (!smb_io_relstr("text_status", buffer, depth, &info->text_status))
2711                 return False;
2712
2713 /*      SEC_DESC sec_desc;*/
2714         if (!prs_uint32("Hack! sec desc", ps, depth, &pipo))
2715                 return False;
2716
2717         if (!prs_uint32("status",ps, depth, &info->status))
2718                 return False;
2719         if (!prs_uint32("priority",ps, depth, &info->priority))
2720                 return False;
2721         if (!prs_uint32("position",ps, depth, &info->position)) 
2722                 return False;
2723         if (!prs_uint32("starttime",ps, depth, &info->starttime))
2724                 return False;
2725         if (!prs_uint32("untiltime",ps, depth, &info->untiltime))       
2726                 return False;
2727         if (!prs_uint32("totalpages",ps, depth, &info->totalpages))
2728                 return False;
2729         if (!prs_uint32("size",ps, depth, &info->size))
2730                 return False;
2731         if (!spoolss_io_system_time("submitted", ps, depth, &info->submitted) )
2732                 return False;
2733         if (!prs_uint32("timeelapsed",ps, depth, &info->timeelapsed))
2734                 return False;
2735         if (!prs_uint32("pagesprinted",ps, depth, &info->pagesprinted))
2736                 return False;
2737
2738         return True;
2739 }
2740
2741 /*******************************************************************
2742 ********************************************************************/  
2743
2744 BOOL smb_io_form_1(const char *desc, RPC_BUFFER *buffer, FORM_1 *info, int depth)
2745 {
2746         prs_struct *ps=&buffer->prs;
2747         
2748         prs_debug(ps, depth, desc, "smb_io_form_1");
2749         depth++;
2750                 
2751         buffer->struct_start=prs_offset(ps);
2752         
2753         if (!prs_uint32("flag", ps, depth, &info->flag))
2754                 return False;
2755                 
2756         if (!smb_io_relstr("name", buffer, depth, &info->name))
2757                 return False;
2758
2759         if (!prs_uint32("width", ps, depth, &info->width))
2760                 return False;
2761         if (!prs_uint32("length", ps, depth, &info->length))
2762                 return False;
2763         if (!prs_uint32("left", ps, depth, &info->left))
2764                 return False;
2765         if (!prs_uint32("top", ps, depth, &info->top))
2766                 return False;
2767         if (!prs_uint32("right", ps, depth, &info->right))
2768                 return False;
2769         if (!prs_uint32("bottom", ps, depth, &info->bottom))
2770                 return False;
2771
2772         return True;
2773 }
2774
2775
2776
2777 /*******************************************************************
2778  Parse a DRIVER_DIRECTORY_1 structure.
2779 ********************************************************************/  
2780
2781 BOOL smb_io_driverdir_1(const char *desc, RPC_BUFFER *buffer, DRIVER_DIRECTORY_1 *info, int depth)
2782 {
2783         prs_struct *ps=&buffer->prs;
2784
2785         prs_debug(ps, depth, desc, "smb_io_driverdir_1");
2786         depth++;
2787
2788         buffer->struct_start=prs_offset(ps);
2789
2790         if (!smb_io_unistr(desc, &info->name, ps, depth))
2791                 return False;
2792
2793         return True;
2794 }
2795
2796 /*******************************************************************
2797  Parse a PORT_INFO_1 structure.
2798 ********************************************************************/  
2799
2800 BOOL smb_io_port_1(const char *desc, RPC_BUFFER *buffer, PORT_INFO_1 *info, int depth)
2801 {
2802         prs_struct *ps=&buffer->prs;
2803
2804         prs_debug(ps, depth, desc, "smb_io_port_1");
2805         depth++;
2806
2807         buffer->struct_start=prs_offset(ps);
2808
2809         if(!smb_io_relstr("port_name", buffer, depth, &info->port_name))
2810                 return False;
2811
2812         return True;
2813 }
2814
2815 /*******************************************************************
2816  Parse a PORT_INFO_2 structure.
2817 ********************************************************************/  
2818
2819 BOOL smb_io_port_2(const char *desc, RPC_BUFFER *buffer, PORT_INFO_2 *info, int depth)
2820 {
2821         prs_struct *ps=&buffer->prs;
2822
2823         prs_debug(ps, depth, desc, "smb_io_port_2");
2824         depth++;
2825
2826         buffer->struct_start=prs_offset(ps);
2827
2828         if(!smb_io_relstr("port_name", buffer, depth, &info->port_name))
2829                 return False;
2830         if(!smb_io_relstr("monitor_name", buffer, depth, &info->monitor_name))
2831                 return False;
2832         if(!smb_io_relstr("description", buffer, depth, &info->description))
2833                 return False;
2834         if(!prs_uint32("port_type", ps, depth, &info->port_type))
2835                 return False;
2836         if(!prs_uint32("reserved", ps, depth, &info->reserved))
2837                 return False;
2838
2839         return True;
2840 }
2841
2842 /*******************************************************************
2843 ********************************************************************/  
2844
2845 BOOL smb_io_printprocessor_info_1(const char *desc, RPC_BUFFER *buffer, PRINTPROCESSOR_1 *info, int depth)
2846 {
2847         prs_struct *ps=&buffer->prs;
2848
2849         prs_debug(ps, depth, desc, "smb_io_printprocessor_info_1");
2850         depth++;        
2851
2852         buffer->struct_start=prs_offset(ps);
2853         
2854         if (smb_io_relstr("name", buffer, depth, &info->name))
2855                 return False;
2856
2857         return True;
2858 }
2859
2860 /*******************************************************************
2861 ********************************************************************/  
2862
2863 BOOL smb_io_printprocdatatype_info_1(const char *desc, RPC_BUFFER *buffer, PRINTPROCDATATYPE_1 *info, int depth)
2864 {
2865         prs_struct *ps=&buffer->prs;
2866
2867         prs_debug(ps, depth, desc, "smb_io_printprocdatatype_info_1");
2868         depth++;        
2869
2870         buffer->struct_start=prs_offset(ps);
2871         
2872         if (smb_io_relstr("name", buffer, depth, &info->name))
2873                 return False;
2874
2875         return True;
2876 }
2877
2878 /*******************************************************************
2879 ********************************************************************/  
2880
2881 BOOL smb_io_printmonitor_info_1(const char *desc, RPC_BUFFER *buffer, PRINTMONITOR_1 *info, int depth)
2882 {
2883         prs_struct *ps=&buffer->prs;
2884
2885         prs_debug(ps, depth, desc, "smb_io_printmonitor_info_1");
2886         depth++;        
2887
2888         buffer->struct_start=prs_offset(ps);
2889
2890         if (!smb_io_relstr("name", buffer, depth, &info->name))
2891                 return False;
2892
2893         return True;
2894 }
2895
2896 /*******************************************************************
2897 ********************************************************************/  
2898
2899 BOOL smb_io_printmonitor_info_2(const char *desc, RPC_BUFFER *buffer, PRINTMONITOR_2 *info, int depth)
2900 {
2901         prs_struct *ps=&buffer->prs;
2902
2903         prs_debug(ps, depth, desc, "smb_io_printmonitor_info_2");
2904         depth++;        
2905
2906         buffer->struct_start=prs_offset(ps);
2907
2908         if (!smb_io_relstr("name", buffer, depth, &info->name))
2909                 return False;
2910         if (!smb_io_relstr("environment", buffer, depth, &info->environment))
2911                 return False;
2912         if (!smb_io_relstr("dll_name", buffer, depth, &info->dll_name))
2913                 return False;
2914
2915         return True;
2916 }
2917
2918 /*******************************************************************
2919 return the size required by a struct in the stream
2920 ********************************************************************/  
2921
2922 uint32 spoolss_size_printer_info_0(PRINTER_INFO_0 *info)
2923 {
2924         int size=0;
2925         
2926         size+=size_of_relative_string( &info->printername );
2927         size+=size_of_relative_string( &info->servername );
2928
2929         size+=size_of_uint32( &info->cjobs);
2930         size+=size_of_uint32( &info->total_jobs);
2931         size+=size_of_uint32( &info->total_bytes);
2932
2933         size+=size_of_uint16( &info->year);
2934         size+=size_of_uint16( &info->month);
2935         size+=size_of_uint16( &info->dayofweek);
2936         size+=size_of_uint16( &info->day);
2937         size+=size_of_uint16( &info->hour);
2938         size+=size_of_uint16( &info->minute);
2939         size+=size_of_uint16( &info->second);
2940         size+=size_of_uint16( &info->milliseconds);
2941
2942         size+=size_of_uint32( &info->global_counter);
2943         size+=size_of_uint32( &info->total_pages);
2944
2945         size+=size_of_uint16( &info->major_version);
2946         size+=size_of_uint16( &info->build_version);
2947
2948         size+=size_of_uint32( &info->unknown7);
2949         size+=size_of_uint32( &info->unknown8);
2950         size+=size_of_uint32( &info->unknown9);
2951         size+=size_of_uint32( &info->session_counter);
2952         size+=size_of_uint32( &info->unknown11);
2953         size+=size_of_uint32( &info->printer_errors);
2954         size+=size_of_uint32( &info->unknown13);
2955         size+=size_of_uint32( &info->unknown14);
2956         size+=size_of_uint32( &info->unknown15);
2957         size+=size_of_uint32( &info->unknown16);
2958         size+=size_of_uint32( &info->change_id);
2959         size+=size_of_uint32( &info->unknown18);
2960         size+=size_of_uint32( &info->status);
2961         size+=size_of_uint32( &info->unknown20);
2962         size+=size_of_uint32( &info->c_setprinter);
2963         
2964         size+=size_of_uint16( &info->unknown22);
2965         size+=size_of_uint16( &info->unknown23);
2966         size+=size_of_uint16( &info->unknown24);
2967         size+=size_of_uint16( &info->unknown25);
2968         size+=size_of_uint16( &info->unknown26);
2969         size+=size_of_uint16( &info->unknown27);
2970         size+=size_of_uint16( &info->unknown28);
2971         size+=size_of_uint16( &info->unknown29);
2972         
2973         return size;
2974 }
2975
2976 /*******************************************************************
2977 return the size required by a struct in the stream
2978 ********************************************************************/  
2979
2980 uint32 spoolss_size_printer_info_1(PRINTER_INFO_1 *info)
2981 {
2982         int size=0;
2983                 
2984         size+=size_of_uint32( &info->flags );   
2985         size+=size_of_relative_string( &info->description );
2986         size+=size_of_relative_string( &info->name );
2987         size+=size_of_relative_string( &info->comment );
2988
2989         return size;
2990 }
2991
2992 /*******************************************************************
2993 return the size required by a struct in the stream
2994 ********************************************************************/
2995
2996 uint32 spoolss_size_printer_info_2(PRINTER_INFO_2 *info)
2997 {
2998         uint32 size=0;
2999                 
3000         size += 4;
3001         
3002         size += sec_desc_size( info->secdesc );
3003
3004         size+=size_of_device_mode( info->devmode );
3005         
3006         size+=size_of_relative_string( &info->servername );
3007         size+=size_of_relative_string( &info->printername );
3008         size+=size_of_relative_string( &info->sharename );
3009         size+=size_of_relative_string( &info->portname );
3010         size+=size_of_relative_string( &info->drivername );
3011         size+=size_of_relative_string( &info->comment );
3012         size+=size_of_relative_string( &info->location );
3013         
3014         size+=size_of_relative_string( &info->sepfile );
3015         size+=size_of_relative_string( &info->printprocessor );
3016         size+=size_of_relative_string( &info->datatype );
3017         size+=size_of_relative_string( &info->parameters );
3018
3019         size+=size_of_uint32( &info->attributes );
3020         size+=size_of_uint32( &info->priority );
3021         size+=size_of_uint32( &info->defaultpriority );
3022         size+=size_of_uint32( &info->starttime );
3023         size+=size_of_uint32( &info->untiltime );
3024         size+=size_of_uint32( &info->status );
3025         size+=size_of_uint32( &info->cjobs );
3026         size+=size_of_uint32( &info->averageppm );      
3027                 
3028         /* 
3029          * add any adjustments for alignment.  This is
3030          * not optimal since we could be calling this
3031          * function from a loop (e.g. enumprinters), but 
3032          * it is easier to maintain the calculation here and
3033          * not place the burden on the caller to remember.   --jerry
3034          */
3035         if ((size % 4) != 0)
3036                 size += 4 - (size % 4);
3037         
3038         return size;
3039 }
3040
3041 /*******************************************************************
3042 return the size required by a struct in the stream
3043 ********************************************************************/
3044
3045 uint32 spoolss_size_printer_info_4(PRINTER_INFO_4 *info)
3046 {
3047         uint32 size=0;
3048                 
3049         size+=size_of_relative_string( &info->printername );
3050         size+=size_of_relative_string( &info->servername );
3051
3052         size+=size_of_uint32( &info->attributes );
3053         return size;
3054 }
3055
3056 /*******************************************************************
3057 return the size required by a struct in the stream
3058 ********************************************************************/
3059
3060 uint32 spoolss_size_printer_info_5(PRINTER_INFO_5 *info)
3061 {
3062         uint32 size=0;
3063                 
3064         size+=size_of_relative_string( &info->printername );
3065         size+=size_of_relative_string( &info->portname );
3066
3067         size+=size_of_uint32( &info->attributes );
3068         size+=size_of_uint32( &info->device_not_selected_timeout );
3069         size+=size_of_uint32( &info->transmission_retry_timeout );
3070         return size;
3071 }
3072
3073
3074 /*******************************************************************
3075 return the size required by a struct in the stream
3076 ********************************************************************/
3077
3078 uint32 spoolss_size_printer_info_3(PRINTER_INFO_3 *info)
3079 {
3080         /* The 4 is for the self relative pointer.. */
3081         /* JRA !!!! TESTME - WHAT ABOUT prs_align.... !!! */
3082         return 4 + (uint32)sec_desc_size( info->secdesc );
3083 }
3084
3085 /*******************************************************************
3086 return the size required by a struct in the stream
3087 ********************************************************************/
3088
3089 uint32 spoolss_size_printer_info_7(PRINTER_INFO_7 *info)
3090 {
3091         uint32 size=0;
3092                 
3093         size+=size_of_relative_string( &info->guid );
3094         size+=size_of_uint32( &info->action );
3095         return size;
3096 }
3097
3098 /*******************************************************************
3099 return the size required by a struct in the stream
3100 ********************************************************************/
3101
3102 uint32 spoolss_size_printer_driver_info_1(DRIVER_INFO_1 *info)
3103 {
3104         int size=0;
3105         size+=size_of_relative_string( &info->name );
3106
3107         return size;
3108 }
3109
3110 /*******************************************************************
3111 return the size required by a struct in the stream
3112 ********************************************************************/
3113
3114 uint32 spoolss_size_printer_driver_info_2(DRIVER_INFO_2 *info)
3115 {
3116         int size=0;
3117         size+=size_of_uint32( &info->version ); 
3118         size+=size_of_relative_string( &info->name );
3119         size+=size_of_relative_string( &info->architecture );
3120         size+=size_of_relative_string( &info->driverpath );
3121         size+=size_of_relative_string( &info->datafile );
3122         size+=size_of_relative_string( &info->configfile );
3123
3124         return size;
3125 }
3126
3127 /*******************************************************************
3128 return the size required by a string array.
3129 ********************************************************************/
3130
3131 uint32 spoolss_size_string_array(uint16 *string)
3132 {
3133         uint32 i = 0;
3134
3135         if (string) {
3136                 for (i=0; (string[i]!=0x0000) || (string[i+1]!=0x0000); i++);
3137         }
3138         i=i+2; /* to count all chars including the leading zero */
3139         i=2*i; /* because we need the value in bytes */
3140         i=i+4; /* the offset pointer size */
3141
3142         return i;
3143 }
3144
3145 /*******************************************************************
3146 return the size required by a struct in the stream
3147 ********************************************************************/
3148
3149 uint32 spoolss_size_printer_driver_info_3(DRIVER_INFO_3 *info)
3150 {
3151         int size=0;
3152
3153         size+=size_of_uint32( &info->version ); 
3154         size+=size_of_relative_string( &info->name );
3155         size+=size_of_relative_string( &info->architecture );
3156         size+=size_of_relative_string( &info->driverpath );
3157         size+=size_of_relative_string( &info->datafile );
3158         size+=size_of_relative_string( &info->configfile );
3159         size+=size_of_relative_string( &info->helpfile );
3160         size+=size_of_relative_string( &info->monitorname );
3161         size+=size_of_relative_string( &info->defaultdatatype );
3162         
3163         size+=spoolss_size_string_array(info->dependentfiles);
3164
3165         return size;
3166 }
3167
3168 /*******************************************************************
3169 return the size required by a struct in the stream
3170 ********************************************************************/
3171
3172 uint32 spoolss_size_printer_driver_info_6(DRIVER_INFO_6 *info)
3173 {
3174         uint32 size=0;
3175
3176         size+=size_of_uint32( &info->version ); 
3177         size+=size_of_relative_string( &info->name );
3178         size+=size_of_relative_string( &info->architecture );
3179         size+=size_of_relative_string( &info->driverpath );
3180         size+=size_of_relative_string( &info->datafile );
3181         size+=size_of_relative_string( &info->configfile );
3182         size+=size_of_relative_string( &info->helpfile );
3183
3184         size+=spoolss_size_string_array(info->dependentfiles);
3185
3186         size+=size_of_relative_string( &info->monitorname );
3187         size+=size_of_relative_string( &info->defaultdatatype );
3188         
3189         size+=spoolss_size_string_array(info->previousdrivernames);
3190
3191         size+=size_of_nttime(&info->driver_date);
3192         size+=size_of_uint32( &info->padding ); 
3193         size+=size_of_uint32( &info->driver_version_low );      
3194         size+=size_of_uint32( &info->driver_version_high );     
3195         size+=size_of_relative_string( &info->mfgname );
3196         size+=size_of_relative_string( &info->oem_url );
3197         size+=size_of_relative_string( &info->hardware_id );
3198         size+=size_of_relative_string( &info->provider );
3199
3200         return size;
3201 }
3202
3203 /*******************************************************************
3204 return the size required by a struct in the stream
3205 ********************************************************************/  
3206
3207 uint32 spoolss_size_job_info_1(JOB_INFO_1 *info)
3208 {
3209         int size=0;
3210         size+=size_of_uint32( &info->jobid );
3211         size+=size_of_relative_string( &info->printername );
3212         size+=size_of_relative_string( &info->machinename );
3213         size+=size_of_relative_string( &info->username );
3214         size+=size_of_relative_string( &info->document );
3215         size+=size_of_relative_string( &info->datatype );
3216         size+=size_of_relative_string( &info->text_status );
3217         size+=size_of_uint32( &info->status );
3218         size+=size_of_uint32( &info->priority );
3219         size+=size_of_uint32( &info->position );
3220         size+=size_of_uint32( &info->totalpages );
3221         size+=size_of_uint32( &info->pagesprinted );
3222         size+=size_of_systemtime( &info->submitted );
3223
3224         return size;
3225 }
3226
3227 /*******************************************************************
3228 return the size required by a struct in the stream
3229 ********************************************************************/  
3230
3231 uint32 spoolss_size_job_info_2(JOB_INFO_2 *info)
3232 {
3233         int size=0;
3234
3235         size+=4; /* size of sec desc ptr */
3236
3237         size+=size_of_uint32( &info->jobid );
3238         size+=size_of_relative_string( &info->printername );
3239         size+=size_of_relative_string( &info->machinename );
3240         size+=size_of_relative_string( &info->username );
3241         size+=size_of_relative_string( &info->document );
3242         size+=size_of_relative_string( &info->notifyname );
3243         size+=size_of_relative_string( &info->datatype );
3244         size+=size_of_relative_string( &info->printprocessor );
3245         size+=size_of_relative_string( &info->parameters );
3246         size+=size_of_relative_string( &info->drivername );
3247         size+=size_of_device_mode( info->devmode );
3248         size+=size_of_relative_string( &info->text_status );
3249 /*      SEC_DESC sec_desc;*/
3250         size+=size_of_uint32( &info->status );
3251         size+=size_of_uint32( &info->priority );
3252         size+=size_of_uint32( &info->position );
3253         size+=size_of_uint32( &info->starttime );
3254         size+=size_of_uint32( &info->untiltime );
3255         size+=size_of_uint32( &info->totalpages );
3256         size+=size_of_uint32( &info->size );
3257         size+=size_of_systemtime( &info->submitted );
3258         size+=size_of_uint32( &info->timeelapsed );
3259         size+=size_of_uint32( &info->pagesprinted );
3260
3261         return size;
3262 }
3263
3264 /*******************************************************************
3265 return the size required by a struct in the stream
3266 ********************************************************************/
3267
3268 uint32 spoolss_size_form_1(FORM_1 *info)
3269 {
3270         int size=0;
3271
3272         size+=size_of_uint32( &info->flag );
3273         size+=size_of_relative_string( &info->name );
3274         size+=size_of_uint32( &info->width );
3275         size+=size_of_uint32( &info->length );
3276         size+=size_of_uint32( &info->left );
3277         size+=size_of_uint32( &info->top );
3278         size+=size_of_uint32( &info->right );
3279         size+=size_of_uint32( &info->bottom );
3280
3281         return size;
3282 }
3283
3284 /*******************************************************************
3285 return the size required by a struct in the stream
3286 ********************************************************************/  
3287
3288 uint32 spoolss_size_port_info_1(PORT_INFO_1 *info)
3289 {
3290         int size=0;
3291
3292         size+=size_of_relative_string( &info->port_name );
3293
3294         return size;
3295 }
3296
3297 /*******************************************************************
3298 return the size required by a struct in the stream
3299 ********************************************************************/  
3300
3301 uint32 spoolss_size_driverdir_info_1(DRIVER_DIRECTORY_1 *info)
3302 {
3303         int size=0;
3304
3305         size=str_len_uni(&info->name);  /* the string length       */
3306         size=size+1;                    /* add the leading zero    */
3307         size=size*2;                    /* convert in char         */
3308
3309         return size;
3310 }
3311
3312 /*******************************************************************
3313 return the size required by a struct in the stream
3314 ********************************************************************/  
3315
3316 uint32 spoolss_size_printprocessordirectory_info_1(PRINTPROCESSOR_DIRECTORY_1 *info)
3317 {
3318         int size=0;
3319
3320         size=str_len_uni(&info->name);  /* the string length       */
3321         size=size+1;                    /* add the leading zero    */
3322         size=size*2;                    /* convert in char         */
3323
3324         return size;
3325 }
3326
3327 /*******************************************************************
3328 return the size required by a struct in the stream
3329 ********************************************************************/  
3330
3331 uint32 spoolss_size_port_info_2(PORT_INFO_2 *info)
3332 {
3333         int size=0;
3334
3335         size+=size_of_relative_string( &info->port_name );
3336         size+=size_of_relative_string( &info->monitor_name );
3337         size+=size_of_relative_string( &info->description );
3338
3339         size+=size_of_uint32( &info->port_type );
3340         size+=size_of_uint32( &info->reserved );
3341
3342         return size;
3343 }
3344
3345 /*******************************************************************
3346 return the size required by a struct in the stream
3347 ********************************************************************/  
3348
3349 uint32 spoolss_size_printprocessor_info_1(PRINTPROCESSOR_1 *info)
3350 {
3351         int size=0;
3352         size+=size_of_relative_string( &info->name );
3353
3354         return size;
3355 }
3356
3357 /*******************************************************************
3358 return the size required by a struct in the stream
3359 ********************************************************************/  
3360
3361 uint32 spoolss_size_printprocdatatype_info_1(PRINTPROCDATATYPE_1 *info)
3362 {
3363         int size=0;
3364         size+=size_of_relative_string( &info->name );
3365
3366         return size;
3367 }
3368
3369 /*******************************************************************
3370 return the size required by a struct in the stream
3371 ********************************************************************/  
3372 uint32 spoolss_size_printer_enum_values(PRINTER_ENUM_VALUES *p)
3373 {
3374         uint32  size = 0; 
3375         
3376         if (!p)
3377                 return 0;
3378         
3379         /* uint32(offset) + uint32(length) + length) */
3380         size += (size_of_uint32(&p->value_len)*2) + p->value_len;
3381         size += (size_of_uint32(&p->data_len)*2) + p->data_len + (p->data_len%2) ;
3382         
3383         size += size_of_uint32(&p->type);
3384                        
3385         return size;
3386 }
3387
3388 /*******************************************************************
3389 return the size required by a struct in the stream
3390 ********************************************************************/  
3391
3392 uint32 spoolss_size_printmonitor_info_1(PRINTMONITOR_1 *info)
3393 {
3394         int size=0;
3395         size+=size_of_relative_string( &info->name );
3396
3397         return size;
3398 }
3399
3400 /*******************************************************************
3401 return the size required by a struct in the stream
3402 ********************************************************************/  
3403
3404 uint32 spoolss_size_printmonitor_info_2(PRINTMONITOR_2 *info)
3405 {
3406         int size=0;
3407         size+=size_of_relative_string( &info->name);
3408         size+=size_of_relative_string( &info->environment);
3409         size+=size_of_relative_string( &info->dll_name);
3410
3411         return size;
3412 }
3413
3414 /*******************************************************************
3415  * init a structure.
3416  ********************************************************************/
3417
3418 BOOL make_spoolss_q_getprinterdriver2(SPOOL_Q_GETPRINTERDRIVER2 *q_u, 
3419                                const POLICY_HND *hnd,
3420                                const fstring architecture,
3421                                uint32 level, uint32 clientmajor, uint32 clientminor,
3422                                RPC_BUFFER *buffer, uint32 offered)
3423 {      
3424         if (q_u == NULL)
3425                 return False;
3426
3427         memcpy(&q_u->handle, hnd, sizeof(q_u->handle));
3428
3429         init_buf_unistr2(&q_u->architecture, &q_u->architecture_ptr, architecture);
3430
3431         q_u->level=level;
3432         q_u->clientmajorversion=clientmajor;
3433         q_u->clientminorversion=clientminor;
3434
3435         q_u->buffer=buffer;
3436         q_u->offered=offered;
3437
3438         return True;
3439 }
3440
3441 /*******************************************************************
3442  * read a structure.
3443  * called from spoolss_getprinterdriver2 (srv_spoolss.c)
3444  ********************************************************************/
3445
3446 BOOL spoolss_io_q_getprinterdriver2(const char *desc, SPOOL_Q_GETPRINTERDRIVER2 *q_u, prs_struct *ps, int depth)
3447 {
3448         prs_debug(ps, depth, desc, "spoolss_io_q_getprinterdriver2");
3449         depth++;
3450
3451         if(!prs_align(ps))
3452                 return False;
3453         
3454         if(!smb_io_pol_hnd("printer handle", &q_u->handle, ps, depth))
3455                 return False;
3456         if(!prs_uint32("architecture_ptr", ps, depth, &q_u->architecture_ptr))
3457                 return False;
3458         if(!smb_io_unistr2("architecture", &q_u->architecture, q_u->architecture_ptr, ps, depth))
3459                 return False;
3460         
3461         if(!prs_align(ps))
3462                 return False;
3463         if(!prs_uint32("level", ps, depth, &q_u->level))
3464                 return False;
3465                 
3466         if(!prs_rpcbuffer_p("", ps, depth, &q_u->buffer))
3467                 return False;
3468
3469         if(!prs_align(ps))
3470                 return False;
3471
3472         if(!prs_uint32("offered", ps, depth, &q_u->offered))
3473                 return False;
3474                 
3475         if(!prs_uint32("clientmajorversion", ps, depth, &q_u->clientmajorversion))
3476                 return False;
3477         if(!prs_uint32("clientminorversion", ps, depth, &q_u->clientminorversion))
3478                 return False;
3479
3480         return True;
3481 }
3482
3483 /*******************************************************************
3484  * read a structure.
3485  * called from spoolss_getprinterdriver2 (srv_spoolss.c)
3486  ********************************************************************/
3487
3488 BOOL spoolss_io_r_getprinterdriver2(const char *desc, SPOOL_R_GETPRINTERDRIVER2 *r_u, prs_struct *ps, int depth)
3489 {
3490         prs_debug(ps, depth, desc, "spoolss_io_r_getprinterdriver2");
3491         depth++;
3492
3493         if (!prs_align(ps))
3494                 return False;
3495                 
3496         if (!prs_rpcbuffer_p("", ps, depth, &r_u->buffer))
3497                 return False;
3498
3499         if (!prs_align(ps))
3500                 return False;
3501         if (!prs_uint32("needed", ps, depth, &r_u->needed))
3502                 return False;
3503         if (!prs_uint32("servermajorversion", ps, depth, &r_u->servermajorversion))
3504                 return False;
3505         if (!prs_uint32("serverminorversion", ps, depth, &r_u->serverminorversion))
3506                 return False;           
3507         if (!prs_werror("status", ps, depth, &r_u->status))
3508                 return False;
3509
3510         return True;            
3511 }
3512
3513 /*******************************************************************
3514  * init a structure.
3515  ********************************************************************/
3516
3517 BOOL make_spoolss_q_enumprinters(
3518         SPOOL_Q_ENUMPRINTERS *q_u, 
3519         uint32 flags, 
3520         char *servername, 
3521         uint32 level, 
3522         RPC_BUFFER *buffer, 
3523         uint32 offered
3524 )
3525 {
3526         q_u->flags=flags;
3527         
3528         q_u->servername_ptr = (servername != NULL) ? 1 : 0;
3529         init_buf_unistr2(&q_u->servername, &q_u->servername_ptr, servername);
3530
3531         q_u->level=level;
3532         q_u->buffer=buffer;
3533         q_u->offered=offered;
3534
3535         return True;
3536 }
3537
3538 /*******************************************************************
3539  * init a structure.
3540  ********************************************************************/
3541
3542 BOOL make_spoolss_q_enumports(SPOOL_Q_ENUMPORTS *q_u, 
3543                                 fstring servername, uint32 level, 
3544                                 RPC_BUFFER *buffer, uint32 offered)
3545 {
3546         q_u->name_ptr = (servername != NULL) ? 1 : 0;
3547         init_buf_unistr2(&q_u->name, &q_u->name_ptr, servername);
3548
3549         q_u->level=level;
3550         q_u->buffer=buffer;
3551         q_u->offered=offered;
3552
3553         return True;
3554 }
3555
3556 /*******************************************************************
3557  * read a structure.
3558  * called from spoolss_enumprinters (srv_spoolss.c)
3559  ********************************************************************/
3560
3561 BOOL spoolss_io_q_enumprinters(const char *desc, SPOOL_Q_ENUMPRINTERS *q_u, prs_struct *ps, int depth)
3562 {
3563         prs_debug(ps, depth, desc, "spoolss_io_q_enumprinters");
3564         depth++;
3565
3566         if (!prs_align(ps))
3567                 return False;
3568
3569         if (!prs_uint32("flags", ps, depth, &q_u->flags))
3570                 return False;
3571         if (!prs_uint32("servername_ptr", ps, depth, &q_u->servername_ptr))
3572                 return False;
3573
3574         if (!smb_io_unistr2("", &q_u->servername, q_u->servername_ptr, ps, depth))
3575                 return False;
3576                 
3577         if (!prs_align(ps))
3578                 return False;
3579         if (!prs_uint32("level", ps, depth, &q_u->level))
3580                 return False;
3581
3582         if (!prs_rpcbuffer_p("", ps, depth, &q_u->buffer))
3583                 return False;
3584
3585         if (!prs_align(ps))
3586                 return False;
3587         if (!prs_uint32("offered", ps, depth, &q_u->offered))
3588                 return False;
3589
3590         return True;
3591 }
3592
3593 /*******************************************************************
3594  Parse a SPOOL_R_ENUMPRINTERS structure.
3595  ********************************************************************/
3596
3597 BOOL spoolss_io_r_enumprinters(const char *desc, SPOOL_R_ENUMPRINTERS *r_u, prs_struct *ps, int depth)
3598 {
3599         prs_debug(ps, depth, desc, "spoolss_io_r_enumprinters");
3600         depth++;
3601
3602         if (!prs_align(ps))
3603                 return False;
3604                 
3605         if (!prs_rpcbuffer_p("", ps, depth, &r_u->buffer))
3606                 return False;
3607
3608         if (!prs_align(ps))
3609                 return False;
3610                 
3611         if (!prs_uint32("needed", ps, depth, &r_u->needed))
3612                 return False;
3613                 
3614         if (!prs_uint32("returned", ps, depth, &r_u->returned))
3615                 return False;
3616                 
3617         if (!prs_werror("status", ps, depth, &r_u->status))
3618                 return False;
3619
3620         return True;            
3621 }
3622
3623 /*******************************************************************
3624  * write a structure.
3625  * called from spoolss_r_enum_printers (srv_spoolss.c)
3626  *
3627  ********************************************************************/
3628
3629 BOOL spoolss_io_r_getprinter(const char *desc, SPOOL_R_GETPRINTER *r_u, prs_struct *ps, int depth)
3630 {       
3631         prs_debug(ps, depth, desc, "spoolss_io_r_getprinter");
3632         depth++;
3633
3634         if (!prs_align(ps))
3635                 return False;
3636                 
3637         if (!prs_rpcbuffer_p("", ps, depth, &r_u->buffer))
3638                 return False;
3639
3640         if (!prs_align(ps))
3641                 return False;
3642
3643         if (!prs_uint32("needed", ps, depth, &r_u->needed))
3644                 return False;
3645                 
3646         if (!prs_werror("status", ps, depth, &r_u->status))
3647                 return False;
3648
3649         return True;            
3650 }
3651
3652 /*******************************************************************
3653  * read a structure.
3654  * called from spoolss_getprinter (srv_spoolss.c)
3655  ********************************************************************/
3656
3657 BOOL spoolss_io_q_getprinter(const char *desc, SPOOL_Q_GETPRINTER *q_u, prs_struct *ps, int depth)
3658 {
3659         prs_debug(ps, depth, desc, "spoolss_io_q_getprinter");
3660         depth++;
3661
3662         if (!prs_align(ps))
3663                 return False;
3664
3665         if(!smb_io_pol_hnd("printer handle", &q_u->handle, ps, depth))
3666                 return False;
3667         if (!prs_uint32("level", ps, depth, &q_u->level))
3668                 return False;
3669
3670         if (!prs_rpcbuffer_p("", ps, depth, &q_u->buffer))
3671                 return False;
3672
3673         if (!prs_align(ps))
3674                 return False;
3675         if (!prs_uint32("offered", ps, depth, &q_u->offered))
3676                 return False;
3677
3678         return True;
3679 }
3680
3681 /*******************************************************************
3682  * init a structure.
3683  ********************************************************************/
3684
3685 BOOL make_spoolss_q_getprinter(
3686         TALLOC_CTX *mem_ctx,
3687         SPOOL_Q_GETPRINTER *q_u, 
3688         const POLICY_HND *hnd, 
3689         uint32 level, 
3690         RPC_BUFFER *buffer, 
3691         uint32 offered
3692 )
3693 {
3694         if (q_u == NULL)
3695         {
3696                 return False;
3697         }
3698         memcpy(&q_u->handle, hnd, sizeof(q_u->handle));
3699
3700         q_u->level=level;
3701         q_u->buffer=buffer;
3702         q_u->offered=offered;
3703
3704         return True;
3705 }
3706
3707 /*******************************************************************
3708  * init a structure.
3709  ********************************************************************/
3710 BOOL make_spoolss_q_setprinter(TALLOC_CTX *mem_ctx, SPOOL_Q_SETPRINTER *q_u, 
3711                                 const POLICY_HND *hnd, uint32 level, PRINTER_INFO_CTR *info, 
3712                                 uint32 command)
3713 {
3714         SEC_DESC *secdesc;
3715         DEVICEMODE *devmode;
3716
3717         if (q_u == NULL)
3718                 return False;
3719         
3720         memcpy(&q_u->handle, hnd, sizeof(q_u->handle));
3721
3722         q_u->level = level;
3723         q_u->info.level = level;
3724         q_u->info.info_ptr = (info != NULL) ? 1 : 0;
3725         switch (level) {
3726
3727           /* There's no such thing as a setprinter level 1 */
3728
3729         case 2:
3730                 secdesc = info->printers_2->secdesc;
3731                 devmode = info->printers_2->devmode;
3732                 
3733                 make_spoolss_printer_info_2 (mem_ctx, &q_u->info.info_2, info->printers_2);
3734 #if 1   /* JERRY TEST */
3735                 q_u->secdesc_ctr = SMB_MALLOC_P(SEC_DESC_BUF);
3736                 if (!q_u->secdesc_ctr)
3737                         return False;
3738                 q_u->secdesc_ctr->ptr = (secdesc != NULL) ? 1: 0;
3739                 q_u->secdesc_ctr->max_len = (secdesc) ? sizeof(SEC_DESC) + (2*sizeof(uint32)) : 0;
3740                 q_u->secdesc_ctr->len = (secdesc) ? sizeof(SEC_DESC) + (2*sizeof(uint32)) : 0;
3741                 q_u->secdesc_ctr->sec = secdesc;
3742
3743                 q_u->devmode_ctr.devmode_ptr = (devmode != NULL) ? 1 : 0;
3744                 q_u->devmode_ctr.size = (devmode != NULL) ? sizeof(DEVICEMODE) + (3*sizeof(uint32)) : 0;
3745                 q_u->devmode_ctr.devmode = devmode;
3746 #else
3747                 q_u->secdesc_ctr = NULL;
3748         
3749                 q_u->devmode_ctr.devmode_ptr = 0;
3750                 q_u->devmode_ctr.size = 0;
3751                 q_u->devmode_ctr.devmode = NULL;
3752 #endif
3753                 break;
3754         case 3:
3755                 secdesc = info->printers_3->secdesc;
3756                 
3757                 make_spoolss_printer_info_3 (mem_ctx, &q_u->info.info_3, info->printers_3);
3758                 
3759                 q_u->secdesc_ctr = SMB_MALLOC_P(SEC_DESC_BUF);
3760                 if (!q_u->secdesc_ctr)
3761                         return False;
3762                 q_u->secdesc_ctr->ptr = (secdesc != NULL) ? 1: 0;
3763                 q_u->secdesc_ctr->max_len = (secdesc) ? sizeof(SEC_DESC) + (2*sizeof(uint32)) : 0;
3764                 q_u->secdesc_ctr->len = (secdesc) ? sizeof(SEC_DESC) + (2*sizeof(uint32)) : 0;
3765                 q_u->secdesc_ctr->sec = secdesc;
3766
3767                 break;
3768         case 7:
3769                 make_spoolss_printer_info_7 (mem_ctx, &q_u->info.info_7, info->printers_7);
3770                 break;
3771
3772         default: 
3773                 DEBUG(0,("make_spoolss_q_setprinter: Unknown info level [%d]\n", level));
3774                         break;
3775         }
3776
3777         
3778         q_u->command = command;
3779
3780         return True;
3781 }
3782
3783
3784 /*******************************************************************
3785 ********************************************************************/  
3786
3787 BOOL spoolss_io_r_setprinter(const char *desc, SPOOL_R_SETPRINTER *r_u, prs_struct *ps, int depth)
3788 {               
3789         prs_debug(ps, depth, desc, "spoolss_io_r_setprinter");
3790         depth++;
3791
3792         if(!prs_align(ps))
3793                 return False;
3794         
3795         if(!prs_werror("status", ps, depth, &r_u->status))
3796                 return False;
3797
3798         return True;
3799 }
3800
3801 /*******************************************************************
3802  Marshall/unmarshall a SPOOL_Q_SETPRINTER struct.
3803 ********************************************************************/  
3804
3805 BOOL spoolss_io_q_setprinter(const char *desc, SPOOL_Q_SETPRINTER *q_u, prs_struct *ps, int depth)
3806 {
3807         uint32 ptr_sec_desc = 0;
3808
3809         prs_debug(ps, depth, desc, "spoolss_io_q_setprinter");
3810         depth++;
3811
3812         if(!prs_align(ps))
3813                 return False;
3814
3815         if(!smb_io_pol_hnd("printer handle", &q_u->handle ,ps, depth))
3816                 return False;
3817         if(!prs_uint32("level", ps, depth, &q_u->level))
3818                 return False;
3819
3820         if(!spool_io_printer_info_level("", &q_u->info, ps, depth))
3821                 return False;
3822
3823         if (!spoolss_io_devmode_cont(desc, &q_u->devmode_ctr, ps, depth))
3824                 return False;
3825         
3826         if(!prs_align(ps))
3827                 return False;
3828
3829         switch (q_u->level)
3830         {
3831                 case 2:
3832                 {
3833                         ptr_sec_desc = q_u->info.info_2->secdesc_ptr;
3834                         break;
3835                 }
3836                 case 3:
3837                 {
3838                         ptr_sec_desc = q_u->info.info_3->secdesc_ptr;
3839                         break;
3840                 }
3841         }
3842         if (ptr_sec_desc)
3843         {
3844                 if (!sec_io_desc_buf(desc, &q_u->secdesc_ctr, ps, depth))
3845                         return False;
3846         } else {
3847                 uint32 dummy = 0;
3848
3849                 /* Parse a NULL security descriptor.  This should really
3850                    happen inside the sec_io_desc_buf() function. */
3851
3852                 prs_debug(ps, depth, "", "sec_io_desc_buf");
3853                 if (!prs_uint32("size", ps, depth + 1, &dummy))
3854                         return False;
3855                 if (!prs_uint32("ptr", ps, depth + 1, &dummy)) return
3856                                                                        False;
3857         }
3858         
3859         if(!prs_uint32("command", ps, depth, &q_u->command))
3860                 return False;
3861
3862         return True;
3863 }
3864
3865 /*******************************************************************
3866 ********************************************************************/  
3867
3868 BOOL spoolss_io_r_fcpn(const char *desc, SPOOL_R_FCPN *r_u, prs_struct *ps, int depth)
3869 {               
3870         prs_debug(ps, depth, desc, "spoolss_io_r_fcpn");
3871         depth++;
3872
3873         if(!prs_align(ps))
3874                 return False;
3875         
3876         if(!prs_werror("status", ps, depth, &r_u->status))
3877                 return False;
3878
3879         return True;
3880 }
3881
3882 /*******************************************************************
3883 ********************************************************************/  
3884
3885 BOOL spoolss_io_q_fcpn(const char *desc, SPOOL_Q_FCPN *q_u, prs_struct *ps, int depth)
3886 {
3887
3888         prs_debug(ps, depth, desc, "spoolss_io_q_fcpn");
3889         depth++;
3890
3891         if(!prs_align(ps))
3892                 return False;
3893
3894         if(!smb_io_pol_hnd("printer handle",&q_u->handle,ps,depth))
3895                 return False;
3896
3897         return True;
3898 }
3899
3900
3901 /*******************************************************************
3902 ********************************************************************/  
3903
3904 BOOL spoolss_io_r_addjob(const char *desc, SPOOL_R_ADDJOB *r_u, prs_struct *ps, int depth)
3905 {               
3906         prs_debug(ps, depth, desc, "");
3907         depth++;
3908
3909         if(!prs_align(ps))
3910                 return False;
3911         
3912         if(!prs_rpcbuffer_p("", ps, depth, &r_u->buffer))
3913                 return False;
3914
3915         if(!prs_align(ps))
3916                 return False;
3917         
3918         if(!prs_uint32("needed", ps, depth, &r_u->needed))
3919                 return False;
3920
3921         if(!prs_werror("status", ps, depth, &r_u->status))
3922                 return False;
3923
3924         return True;
3925 }
3926
3927 /*******************************************************************
3928 ********************************************************************/  
3929
3930 BOOL spoolss_io_q_addjob(const char *desc, SPOOL_Q_ADDJOB *q_u, prs_struct *ps, int depth)
3931 {
3932         prs_debug(ps, depth, desc, "");
3933         depth++;
3934
3935         if(!prs_align(ps))
3936                 return False;
3937
3938         if(!smb_io_pol_hnd("printer handle", &q_u->handle, ps, depth))
3939                 return False;
3940         if(!prs_uint32("level", ps, depth, &q_u->level))
3941                 return False;
3942         
3943         if(!prs_rpcbuffer_p("", ps, depth, &q_u->buffer))
3944                 return False;
3945
3946         if(!prs_align(ps))
3947                 return False;
3948         
3949         if(!prs_uint32("offered", ps, depth, &q_u->offered))
3950                 return False;
3951
3952         return True;
3953 }
3954
3955 /*******************************************************************
3956 ********************************************************************/  
3957
3958 BOOL spoolss_io_r_enumjobs(const char *desc, SPOOL_R_ENUMJOBS *r_u, prs_struct *ps, int depth)
3959 {               
3960         prs_debug(ps, depth, desc, "spoolss_io_r_enumjobs");
3961         depth++;
3962
3963         if (!prs_align(ps))
3964                 return False;
3965                 
3966         if (!prs_rpcbuffer_p("", ps, depth, &r_u->buffer))
3967                 return False;
3968
3969         if (!prs_align(ps))
3970                 return False;
3971                 
3972         if (!prs_uint32("needed", ps, depth, &r_u->needed))
3973                 return False;
3974                 
3975         if (!prs_uint32("returned", ps, depth, &r_u->returned))
3976                 return False;
3977                 
3978         if (!prs_werror("status", ps, depth, &r_u->status))
3979                 return False;
3980
3981         return True;            
3982 }
3983
3984 /*******************************************************************
3985 ********************************************************************/  
3986
3987 BOOL make_spoolss_q_enumjobs(SPOOL_Q_ENUMJOBS *q_u, const POLICY_HND *hnd,
3988                                 uint32 firstjob,
3989                                 uint32 numofjobs,
3990                                 uint32 level,
3991                                 RPC_BUFFER *buffer,
3992                                 uint32 offered)
3993 {
3994         if (q_u == NULL)
3995         {
3996                 return False;
3997         }
3998         memcpy(&q_u->handle, hnd, sizeof(q_u->handle));
3999         q_u->firstjob = firstjob;
4000         q_u->numofjobs = numofjobs;
4001         q_u->level = level;
4002         q_u->buffer= buffer;
4003         q_u->offered = offered;
4004         return True;
4005 }
4006
4007 /*******************************************************************
4008 ********************************************************************/  
4009
4010 BOOL spoolss_io_q_enumjobs(const char *desc, SPOOL_Q_ENUMJOBS *q_u, prs_struct *ps, int depth)
4011 {
4012         prs_debug(ps, depth, desc, "spoolss_io_q_enumjobs");
4013         depth++;
4014
4015         if (!prs_align(ps))
4016                 return False;
4017
4018         if (!smb_io_pol_hnd("printer handle",&q_u->handle, ps, depth))
4019                 return False;
4020                 
4021         if (!prs_uint32("firstjob", ps, depth, &q_u->firstjob))
4022                 return False;
4023         if (!prs_uint32("numofjobs", ps, depth, &q_u->numofjobs))
4024                 return False;
4025         if (!prs_uint32("level", ps, depth, &q_u->level))
4026                 return False;
4027
4028         if (!prs_rpcbuffer_p("", ps, depth, &q_u->buffer))
4029                 return False;   
4030
4031         if(!prs_align(ps))
4032                 return False;
4033
4034         if (!prs_uint32("offered", ps, depth, &q_u->offered))
4035                 return False;
4036
4037         return True;
4038 }
4039
4040 /*******************************************************************
4041 ********************************************************************/  
4042
4043 BOOL spoolss_io_r_schedulejob(const char *desc, SPOOL_R_SCHEDULEJOB *r_u, prs_struct *ps, int depth)
4044 {               
4045         prs_debug(ps, depth, desc, "spoolss_io_r_schedulejob");
4046         depth++;
4047
4048         if(!prs_align(ps))
4049                 return False;
4050         
4051         if(!prs_werror("status", ps, depth, &r_u->status))
4052                 return False;
4053
4054         return True;
4055 }
4056
4057 /*******************************************************************
4058 ********************************************************************/  
4059
4060 BOOL spoolss_io_q_schedulejob(const char *desc, SPOOL_Q_SCHEDULEJOB *q_u, prs_struct *ps, int depth)
4061 {
4062         prs_debug(ps, depth, desc, "spoolss_io_q_schedulejob");
4063         depth++;
4064
4065         if(!prs_align(ps))
4066                 return False;
4067
4068         if(!smb_io_pol_hnd("printer handle",&q_u->handle,ps,depth))
4069                 return False;
4070         if(!prs_uint32("jobid", ps, depth, &q_u->jobid))
4071                 return False;
4072
4073         return True;
4074 }
4075
4076 /*******************************************************************
4077 ********************************************************************/  
4078
4079 BOOL spoolss_io_r_setjob(const char *desc, SPOOL_R_SETJOB *r_u, prs_struct *ps, int depth)
4080 {               
4081         prs_debug(ps, depth, desc, "spoolss_io_r_setjob");
4082         depth++;
4083
4084         if(!prs_align(ps))
4085                 return False;
4086         
4087         if(!prs_werror("status", ps, depth, &r_u->status))
4088                 return False;
4089
4090         return True;
4091 }
4092
4093 /*******************************************************************
4094 ********************************************************************/  
4095
4096 BOOL spoolss_io_q_setjob(const char *desc, SPOOL_Q_SETJOB *q_u, prs_struct *ps, int depth)
4097 {
4098         prs_debug(ps, depth, desc, "spoolss_io_q_setjob");
4099         depth++;
4100
4101         if(!prs_align(ps))
4102                 return False;
4103
4104         if(!smb_io_pol_hnd("printer handle",&q_u->handle,ps,depth))
4105                 return False;
4106         if(!prs_uint32("jobid", ps, depth, &q_u->jobid))
4107                 return False;
4108         /* 
4109          * level is usually 0. If (level!=0) then I'm in trouble !
4110          * I will try to generate setjob command with level!=0, one day.
4111          */
4112         if(!prs_uint32("level", ps, depth, &q_u->level))
4113                 return False;
4114         if(!prs_uint32("command", ps, depth, &q_u->command))
4115                 return False;
4116
4117         return True;
4118 }
4119
4120 /*******************************************************************
4121  Parse a SPOOL_R_ENUMPRINTERDRIVERS structure.
4122 ********************************************************************/  
4123
4124 BOOL spoolss_io_r_enumprinterdrivers(const char *desc, SPOOL_R_ENUMPRINTERDRIVERS *r_u, prs_struct *ps, int depth)
4125 {
4126         prs_debug(ps, depth, desc, "spoolss_io_r_enumprinterdrivers");
4127         depth++;
4128
4129         if (!prs_align(ps))
4130                 return False;
4131                 
4132         if (!prs_rpcbuffer_p("", ps, depth, &r_u->buffer))
4133                 return False;
4134
4135         if (!prs_align(ps))
4136                 return False;
4137                 
4138         if (!prs_uint32("needed", ps, depth, &r_u->needed))
4139                 return False;
4140                 
4141         if (!prs_uint32("returned", ps, depth, &r_u->returned))
4142                 return False;
4143                 
4144         if (!prs_werror("status", ps, depth, &r_u->status))
4145                 return False;
4146
4147         return True;            
4148 }
4149
4150 /*******************************************************************
4151  * init a structure.
4152  ********************************************************************/
4153
4154 BOOL make_spoolss_q_enumprinterdrivers(SPOOL_Q_ENUMPRINTERDRIVERS *q_u,
4155                                 const char *name,
4156                                 const char *environment,
4157                                 uint32 level,
4158                                 RPC_BUFFER *buffer, uint32 offered)
4159 {
4160         init_buf_unistr2(&q_u->name, &q_u->name_ptr, name);
4161         init_buf_unistr2(&q_u->environment, &q_u->environment_ptr, environment);
4162
4163         q_u->level=level;
4164         q_u->buffer=buffer;
4165         q_u->offered=offered;
4166
4167         return True;
4168 }
4169
4170 /*******************************************************************
4171  Parse a SPOOL_Q_ENUMPRINTERDRIVERS structure.
4172 ********************************************************************/  
4173
4174 BOOL spoolss_io_q_enumprinterdrivers(const char *desc, SPOOL_Q_ENUMPRINTERDRIVERS *q_u, prs_struct *ps, int depth)
4175 {
4176
4177         prs_debug(ps, depth, desc, "spoolss_io_q_enumprinterdrivers");
4178         depth++;
4179
4180         if (!prs_align(ps))
4181                 return False;
4182                 
4183         if (!prs_uint32("name_ptr", ps, depth, &q_u->name_ptr))
4184                 return False;
4185         if (!smb_io_unistr2("", &q_u->name, q_u->name_ptr,ps, depth))
4186                 return False;
4187                 
4188         if (!prs_align(ps))
4189                 return False;
4190         if (!prs_uint32("environment_ptr", ps, depth, &q_u->environment_ptr))
4191                 return False;
4192         if (!smb_io_unistr2("", &q_u->environment, q_u->environment_ptr, ps, depth))
4193                 return False;
4194                 
4195         if (!prs_align(ps))
4196                 return False;
4197         if (!prs_uint32("level", ps, depth, &q_u->level))
4198                 return False;
4199                 
4200         if (!prs_rpcbuffer_p("", ps, depth, &q_u->buffer))
4201                 return False;
4202
4203         if (!prs_align(ps))
4204                 return False;
4205                 
4206         if (!prs_uint32("offered", ps, depth, &q_u->offered))
4207                 return False;
4208
4209         return True;
4210 }
4211
4212 /*******************************************************************
4213 ********************************************************************/  
4214
4215 BOOL spoolss_io_q_enumforms(const char *desc, SPOOL_Q_ENUMFORMS *q_u, prs_struct *ps, int depth)
4216 {
4217
4218         prs_debug(ps, depth, desc, "spoolss_io_q_enumforms");
4219         depth++;
4220
4221         if (!prs_align(ps))
4222                 return False;                   
4223         if (!smb_io_pol_hnd("printer handle",&q_u->handle,ps,depth))
4224                 return False;           
4225         if (!prs_uint32("level", ps, depth, &q_u->level))
4226                 return False;   
4227         
4228         if (!prs_rpcbuffer_p("", ps, depth, &q_u->buffer))
4229                 return False;
4230
4231         if (!prs_align(ps))
4232                 return False;
4233         if (!prs_uint32("offered", ps, depth, &q_u->offered))
4234                 return False;
4235
4236         return True;
4237 }
4238
4239 /*******************************************************************
4240 ********************************************************************/  
4241
4242 BOOL spoolss_io_r_enumforms(const char *desc, SPOOL_R_ENUMFORMS *r_u, prs_struct *ps, int depth)
4243 {
4244         prs_debug(ps, depth, desc, "spoolss_io_r_enumforms");
4245         depth++;
4246
4247         if (!prs_align(ps))
4248                 return False;
4249                 
4250         if (!prs_rpcbuffer_p("", ps, depth, &r_u->buffer))
4251                 return False;
4252
4253         if (!prs_align(ps))
4254                 return False;
4255                 
4256         if (!prs_uint32("size of buffer needed", ps, depth, &r_u->needed))
4257                 return False;
4258                 
4259         if (!prs_uint32("numofforms", ps, depth, &r_u->numofforms))
4260                 return False;
4261                 
4262         if (!prs_werror("status", ps, depth, &r_u->status))
4263                 return False;
4264
4265         return True;
4266 }
4267
4268 /*******************************************************************
4269 ********************************************************************/  
4270
4271 BOOL spoolss_io_q_getform(const char *desc, SPOOL_Q_GETFORM *q_u, prs_struct *ps, int depth)
4272 {
4273
4274         prs_debug(ps, depth, desc, "spoolss_io_q_getform");
4275         depth++;
4276
4277         if (!prs_align(ps))
4278                 return False;                   
4279         if (!smb_io_pol_hnd("printer handle",&q_u->handle,ps,depth))
4280                 return False;           
4281         if (!smb_io_unistr2("", &q_u->formname,True,ps,depth))
4282                 return False;
4283
4284         if (!prs_align(ps))
4285                 return False;
4286
4287         if (!prs_uint32("level", ps, depth, &q_u->level))
4288                 return False;   
4289         
4290         if (!prs_rpcbuffer_p("", ps, depth, &q_u->buffer))
4291                 return False;
4292
4293         if (!prs_align(ps))
4294                 return False;
4295         if (!prs_uint32("offered", ps, depth, &q_u->offered))
4296                 return False;
4297
4298         return True;
4299 }
4300
4301 /*******************************************************************
4302 ********************************************************************/  
4303
4304 BOOL spoolss_io_r_getform(const char *desc, SPOOL_R_GETFORM *r_u, prs_struct *ps, int depth)
4305 {
4306         prs_debug(ps, depth, desc, "spoolss_io_r_getform");
4307         depth++;
4308
4309         if (!prs_align(ps))
4310                 return False;
4311                 
4312         if (!prs_rpcbuffer_p("", ps, depth, &r_u->buffer))
4313                 return False;
4314
4315         if (!prs_align(ps))
4316                 return False;
4317                 
4318         if (!prs_uint32("size of buffer needed", ps, depth, &r_u->needed))
4319                 return False;
4320                 
4321         if (!prs_werror("status", ps, depth, &r_u->status))
4322                 return False;
4323
4324         return True;
4325 }
4326
4327 /*******************************************************************
4328  Parse a SPOOL_R_ENUMPORTS structure.
4329 ********************************************************************/  
4330
4331 BOOL spoolss_io_r_enumports(const char *desc, SPOOL_R_ENUMPORTS *r_u, prs_struct *ps, int depth)
4332 {
4333         prs_debug(ps, depth, desc, "spoolss_io_r_enumports");
4334         depth++;
4335
4336         if (!prs_align(ps))
4337                 return False;
4338                 
4339         if (!prs_rpcbuffer_p("", ps, depth, &r_u->buffer))
4340                 return False;
4341
4342         if (!prs_align(ps))
4343                 return False;
4344                 
4345         if (!prs_uint32("needed", ps, depth, &r_u->needed))
4346                 return False;
4347                 
4348         if (!prs_uint32("returned", ps, depth, &r_u->returned))
4349                 return False;
4350                 
4351         if (!prs_werror("status", ps, depth, &r_u->status))
4352                 return False;
4353
4354         return True;            
4355 }
4356
4357 /*******************************************************************
4358 ********************************************************************/  
4359
4360 BOOL spoolss_io_q_enumports(const char *desc, SPOOL_Q_ENUMPORTS *q_u, prs_struct *ps, int depth)
4361 {
4362         prs_debug(ps, depth, desc, "");
4363         depth++;
4364
4365         if (!prs_align(ps))
4366                 return False;
4367
4368         if (!prs_uint32("", ps, depth, &q_u->name_ptr))
4369                 return False;
4370         if (!smb_io_unistr2("", &q_u->name,True,ps,depth))
4371                 return False;
4372
4373         if (!prs_align(ps))
4374                 return False;
4375         if (!prs_uint32("level", ps, depth, &q_u->level))
4376                 return False;
4377                 
4378         if (!prs_rpcbuffer_p("", ps, depth, &q_u->buffer))
4379                 return False;
4380
4381         if (!prs_align(ps))
4382                 return False;
4383         if (!prs_uint32("offered", ps, depth, &q_u->offered))
4384                 return False;
4385
4386         return True;
4387 }
4388
4389 /*******************************************************************
4390  Parse a SPOOL_PRINTER_INFO_LEVEL_1 structure.
4391 ********************************************************************/  
4392
4393 BOOL spool_io_printer_info_level_1(const char *desc, SPOOL_PRINTER_INFO_LEVEL_1 *il, prs_struct *ps, int depth)
4394 {       
4395         prs_debug(ps, depth, desc, "spool_io_printer_info_level_1");
4396         depth++;
4397                 
4398         if(!prs_align(ps))
4399                 return False;
4400
4401         if(!prs_uint32("flags", ps, depth, &il->flags))
4402                 return False;
4403         if(!prs_uint32("description_ptr", ps, depth, &il->description_ptr))
4404                 return False;
4405         if(!prs_uint32("name_ptr", ps, depth, &il->name_ptr))
4406                 return False;
4407         if(!prs_uint32("comment_ptr", ps, depth, &il->comment_ptr))
4408                 return False;
4409                 
4410         if(!smb_io_unistr2("description", &il->description, il->description_ptr, ps, depth))
4411                 return False;
4412         if(!smb_io_unistr2("name", &il->name, il->name_ptr, ps, depth))
4413                 return False;
4414         if(!smb_io_unistr2("comment", &il->comment, il->comment_ptr, ps, depth))
4415                 return False;
4416
4417         return True;
4418 }
4419
4420 /*******************************************************************
4421  Parse a SPOOL_PRINTER_INFO_LEVEL_3 structure.
4422 ********************************************************************/  
4423
4424 BOOL spool_io_printer_info_level_3(const char *desc, SPOOL_PRINTER_INFO_LEVEL_3 *il, prs_struct *ps, int depth)
4425 {       
4426         prs_debug(ps, depth, desc, "spool_io_printer_info_level_3");
4427         depth++;
4428                 
4429         if(!prs_align(ps))
4430                 return False;
4431
4432         if(!prs_uint32("secdesc_ptr", ps, depth, &il->secdesc_ptr))
4433                 return False;
4434
4435         return True;
4436 }
4437
4438 /*******************************************************************
4439  Parse a SPOOL_PRINTER_INFO_LEVEL_2 structure.
4440 ********************************************************************/  
4441
4442 BOOL spool_io_printer_info_level_2(const char *desc, SPOOL_PRINTER_INFO_LEVEL_2 *il, prs_struct *ps, int depth)
4443 {       
4444         prs_debug(ps, depth, desc, "spool_io_printer_info_level_2");
4445         depth++;
4446                 
4447         if(!prs_align(ps))
4448                 return False;
4449
4450         if(!prs_uint32("servername_ptr", ps, depth, &il->servername_ptr))
4451                 return False;
4452         if(!prs_uint32("printername_ptr", ps, depth, &il->printername_ptr))
4453                 return False;
4454         if(!prs_uint32("sharename_ptr", ps, depth, &il->sharename_ptr))
4455                 return False;
4456         if(!prs_uint32("portname_ptr", ps, depth, &il->portname_ptr))
4457                 return False;
4458
4459         if(!prs_uint32("drivername_ptr", ps, depth, &il->drivername_ptr))
4460                 return False;
4461         if(!prs_uint32("comment_ptr", ps, depth, &il->comment_ptr))
4462                 return False;
4463         if(!prs_uint32("location_ptr", ps, depth, &il->location_ptr))
4464                 return False;
4465         if(!prs_uint32("devmode_ptr", ps, depth, &il->devmode_ptr))
4466                 return False;
4467         if(!prs_uint32("sepfile_ptr", ps, depth, &il->sepfile_ptr))
4468                 return False;
4469         if(!prs_uint32("printprocessor_ptr", ps, depth, &il->printprocessor_ptr))
4470                 return False;
4471         if(!prs_uint32("datatype_ptr", ps, depth, &il->datatype_ptr))
4472                 return False;
4473         if(!prs_uint32("parameters_ptr", ps, depth, &il->parameters_ptr))
4474                 return False;
4475         if(!prs_uint32("secdesc_ptr", ps, depth, &il->secdesc_ptr))
4476                 return False;
4477
4478         if(!prs_uint32("attributes", ps, depth, &il->attributes))
4479                 return False;
4480         if(!prs_uint32("priority", ps, depth, &il->priority))
4481                 return False;
4482         if(!prs_uint32("default_priority", ps, depth, &il->default_priority))
4483                 return False;
4484         if(!prs_uint32("starttime", ps, depth, &il->starttime))
4485                 return False;
4486         if(!prs_uint32("untiltime", ps, depth, &il->untiltime))
4487                 return False;
4488         if(!prs_uint32("status", ps, depth, &il->status))
4489                 return False;
4490         if(!prs_uint32("cjobs", ps, depth, &il->cjobs))
4491                 return False;
4492         if(!prs_uint32("averageppm", ps, depth, &il->averageppm))
4493                 return False;
4494
4495         if(!smb_io_unistr2("servername", &il->servername, il->servername_ptr, ps, depth))
4496                 return False;
4497         if(!smb_io_unistr2("printername", &il->printername, il->printername_ptr, ps, depth))
4498                 return False;
4499         if(!smb_io_unistr2("sharename", &il->sharename, il->sharename_ptr, ps, depth))
4500                 return False;
4501         if(!smb_io_unistr2("portname", &il->portname, il->portname_ptr, ps, depth))
4502                 return False;
4503         if(!smb_io_unistr2("drivername", &il->drivername, il->drivername_ptr, ps, depth))
4504                 return False;
4505         if(!smb_io_unistr2("comment", &il->comment, il->comment_ptr, ps, depth))
4506                 return False;
4507         if(!smb_io_unistr2("location", &il->location, il->location_ptr, ps, depth))
4508                 return False;
4509         if(!smb_io_unistr2("sepfile", &il->sepfile, il->sepfile_ptr, ps, depth))
4510                 return False;
4511         if(!smb_io_unistr2("printprocessor", &il->printprocessor, il->printprocessor_ptr, ps, depth))
4512                 return False;
4513         if(!smb_io_unistr2("datatype", &il->datatype, il->datatype_ptr, ps, depth))
4514                 return False;
4515         if(!smb_io_unistr2("parameters", &il->parameters, il->parameters_ptr, ps, depth))
4516                 return False;
4517
4518         return True;
4519 }
4520
4521 BOOL spool_io_printer_info_level_7(const char *desc, SPOOL_PRINTER_INFO_LEVEL_7 *il, prs_struct *ps, int depth)
4522 {       
4523         prs_debug(ps, depth, desc, "spool_io_printer_info_level_7");
4524         depth++;
4525                 
4526         if(!prs_align(ps))
4527                 return False;
4528
4529         if(!prs_uint32("guid_ptr", ps, depth, &il->guid_ptr))
4530                 return False;
4531         if(!prs_uint32("action", ps, depth, &il->action))
4532                 return False;
4533
4534         if(!smb_io_unistr2("servername", &il->guid, il->guid_ptr, ps, depth))
4535                 return False;
4536         return True;
4537 }
4538
4539 /*******************************************************************
4540 ********************************************************************/  
4541
4542 BOOL spool_io_printer_info_level(const char *desc, SPOOL_PRINTER_INFO_LEVEL *il, prs_struct *ps, int depth)
4543 {
4544         prs_debug(ps, depth, desc, "spool_io_printer_info_level");
4545         depth++;
4546
4547         if(!prs_align(ps))
4548                 return False;
4549         if(!prs_uint32("level", ps, depth, &il->level))
4550                 return False;
4551         if(!prs_uint32("info_ptr", ps, depth, &il->info_ptr))
4552                 return False;
4553         
4554         /* if no struct inside just return */
4555         if (il->info_ptr==0) {
4556                 if (UNMARSHALLING(ps)) {
4557                         il->info_1=NULL;
4558                         il->info_2=NULL;
4559                 }
4560                 return True;
4561         }
4562                         
4563         switch (il->level) {
4564                 /*
4565                  * level 0 is used by setprinter when managing the queue
4566                  * (hold, stop, start a queue)
4567                  */
4568                 case 0:
4569                         break;
4570                 /* DOCUMENT ME!!! What is level 1 used for? */
4571                 case 1:
4572                 {
4573                         if (UNMARSHALLING(ps)) {
4574                                 if ((il->info_1=PRS_ALLOC_MEM(ps,SPOOL_PRINTER_INFO_LEVEL_1,1)) == NULL)
4575                                         return False;
4576                         }
4577                         if (!spool_io_printer_info_level_1("", il->info_1, ps, depth))
4578                                 return False;
4579                         break;          
4580                 }
4581                 /* 
4582                  * level 2 is used by addprinter
4583                  * and by setprinter when updating printer's info
4584                  */     
4585                 case 2:
4586                         if (UNMARSHALLING(ps)) {
4587                                 if ((il->info_2=PRS_ALLOC_MEM(ps,SPOOL_PRINTER_INFO_LEVEL_2,1)) == NULL)
4588                                         return False;
4589                         }
4590                         if (!spool_io_printer_info_level_2("", il->info_2, ps, depth))
4591                                 return False;
4592                         break;          
4593                 /* DOCUMENT ME!!! What is level 3 used for? */
4594                 case 3:
4595                 {
4596                         if (UNMARSHALLING(ps)) {
4597                                 if ((il->info_3=PRS_ALLOC_MEM(ps,SPOOL_PRINTER_INFO_LEVEL_3,1)) == NULL)
4598                                         return False;
4599                         }
4600                         if (!spool_io_printer_info_level_3("", il->info_3, ps, depth))
4601                                 return False;
4602                         break;          
4603                 }
4604                 case 7:
4605                         if (UNMARSHALLING(ps))
4606                                 if ((il->info_7=PRS_ALLOC_MEM(ps,SPOOL_PRINTER_INFO_LEVEL_7,1)) == NULL)
4607                                         return False;
4608                         if (!spool_io_printer_info_level_7("", il->info_7, ps, depth))
4609                                 return False;
4610                         break;
4611         }
4612
4613         return True;
4614 }
4615
4616 /*******************************************************************
4617 ********************************************************************/  
4618
4619 BOOL spoolss_io_q_addprinterex(const char *desc, SPOOL_Q_ADDPRINTEREX *q_u, prs_struct *ps, int depth)
4620 {
4621         uint32 ptr_sec_desc = 0;
4622
4623         prs_debug(ps, depth, desc, "spoolss_io_q_addprinterex");
4624         depth++;
4625
4626         if(!prs_align(ps))
4627                 return False;
4628
4629         if (!prs_io_unistr2_p("ptr", ps, depth, &q_u->server_name))
4630                 return False;
4631         if (!prs_io_unistr2("servername", ps, depth, q_u->server_name))
4632                 return False;
4633
4634         if(!prs_align(ps))
4635                 return False;
4636
4637         if(!prs_uint32("info_level", ps, depth, &q_u->level))
4638                 return False;
4639         
4640         if(!spool_io_printer_info_level("", &q_u->info, ps, depth))
4641                 return False;
4642         
4643         if (!spoolss_io_devmode_cont(desc, &q_u->devmode_ctr, ps, depth))
4644                 return False;
4645
4646         if(!prs_align(ps))
4647                 return False;
4648
4649         switch (q_u->level) {
4650                 case 2:
4651                         ptr_sec_desc = q_u->info.info_2->secdesc_ptr;
4652                         break;
4653                 case 3:
4654                         ptr_sec_desc = q_u->info.info_3->secdesc_ptr;
4655                         break;
4656         }
4657         if (ptr_sec_desc) {
4658                 if (!sec_io_desc_buf(desc, &q_u->secdesc_ctr, ps, depth))
4659                         return False;
4660         } else {
4661                 uint32 dummy;
4662
4663                 /* Parse a NULL security descriptor.  This should really
4664                         happen inside the sec_io_desc_buf() function. */
4665
4666                 prs_debug(ps, depth, "", "sec_io_desc_buf");
4667                 if (!prs_uint32("size", ps, depth + 1, &dummy))
4668                         return False;
4669                 if (!prs_uint32("ptr", ps, depth + 1, &dummy))
4670                         return False;
4671         }
4672
4673         if(!prs_uint32("user_switch", ps, depth, &q_u->user_switch))
4674                 return False;
4675         if(!spool_io_user_level("", &q_u->user_ctr, ps, depth))
4676                 return False;
4677
4678         return True;
4679 }
4680
4681 /*******************************************************************
4682 ********************************************************************/  
4683
4684 BOOL spoolss_io_r_addprinterex(const char *desc, SPOOL_R_ADDPRINTEREX *r_u, 
4685                                prs_struct *ps, int depth)
4686 {
4687         prs_debug(ps, depth, desc, "spoolss_io_r_addprinterex");
4688         depth++;
4689         
4690         if(!smb_io_pol_hnd("printer handle",&r_u->handle,ps,depth))
4691                 return False;
4692
4693         if(!prs_werror("status", ps, depth, &r_u->status))
4694                 return False;
4695
4696         return True;
4697 }
4698
4699 /*******************************************************************
4700 ********************************************************************/  
4701
4702 BOOL spool_io_printer_driver_info_level_3(const char *desc, SPOOL_PRINTER_DRIVER_INFO_LEVEL_3 **q_u, 
4703                                           prs_struct *ps, int depth)
4704 {       
4705         SPOOL_PRINTER_DRIVER_INFO_LEVEL_3 *il;
4706         
4707         prs_debug(ps, depth, desc, "spool_io_printer_driver_info_level_3");
4708         depth++;
4709                 
4710         /* reading */
4711         if (UNMARSHALLING(ps)) {
4712                 il=PRS_ALLOC_MEM(ps,SPOOL_PRINTER_DRIVER_INFO_LEVEL_3,1);
4713                 if(il == NULL)
4714                         return False;
4715                 *q_u=il;
4716         }
4717         else {
4718                 il=*q_u;
4719         }
4720         
4721         if(!prs_align(ps))
4722                 return False;
4723
4724         if(!prs_uint32("cversion", ps, depth, &il->cversion))
4725                 return False;
4726         if(!prs_uint32("name", ps, depth, &il->name_ptr))
4727                 return False;
4728         if(!prs_uint32("environment", ps, depth, &il->environment_ptr))
4729                 return False;
4730         if(!prs_uint32("driverpath", ps, depth, &il->driverpath_ptr))
4731                 return False;
4732         if(!prs_uint32("datafile", ps, depth, &il->datafile_ptr))
4733                 return False;
4734         if(!prs_uint32("configfile", ps, depth, &il->configfile_ptr))
4735                 return False;
4736         if(!prs_uint32("helpfile", ps, depth, &il->helpfile_ptr))
4737                 return False;
4738         if(!prs_uint32("monitorname", ps, depth, &il->monitorname_ptr))
4739                 return False;
4740         if(!prs_uint32("defaultdatatype", ps, depth, &il->defaultdatatype_ptr))
4741                 return False;
4742         if(!prs_uint32("dependentfilessize", ps, depth, &il->dependentfilessize))
4743                 return False;
4744         if(!prs_uint32("dependentfiles", ps, depth, &il->dependentfiles_ptr))
4745                 return False;
4746
4747         if(!prs_align(ps))
4748                 return False;
4749         
4750         if(!smb_io_unistr2("name", &il->name, il->name_ptr, ps, depth))
4751                 return False;
4752         if(!smb_io_unistr2("environment", &il->environment, il->environment_ptr, ps, depth))
4753                 return False;
4754         if(!smb_io_unistr2("driverpath", &il->driverpath, il->driverpath_ptr, ps, depth))
4755                 return False;
4756         if(!smb_io_unistr2("datafile", &il->datafile, il->datafile_ptr, ps, depth))
4757                 return False;
4758         if(!smb_io_unistr2("configfile", &il->configfile, il->configfile_ptr, ps, depth))
4759                 return False;
4760         if(!smb_io_unistr2("helpfile", &il->helpfile, il->helpfile_ptr, ps, depth))
4761                 return False;
4762         if(!smb_io_unistr2("monitorname", &il->monitorname, il->monitorname_ptr, ps, depth))
4763                 return False;
4764         if(!smb_io_unistr2("defaultdatatype", &il->defaultdatatype, il->defaultdatatype_ptr, ps, depth))
4765                 return False;
4766
4767         if(!prs_align(ps))
4768                 return False;
4769                 
4770         if (il->dependentfiles_ptr)
4771                 smb_io_buffer5("", &il->dependentfiles, ps, depth);
4772
4773         return True;
4774 }
4775
4776 /*******************************************************************
4777 parse a SPOOL_PRINTER_DRIVER_INFO_LEVEL_6 structure
4778 ********************************************************************/  
4779
4780 BOOL spool_io_printer_driver_info_level_6(const char *desc, SPOOL_PRINTER_DRIVER_INFO_LEVEL_6 **q_u, 
4781                                           prs_struct *ps, int depth)
4782 {       
4783         SPOOL_PRINTER_DRIVER_INFO_LEVEL_6 *il;
4784         
4785         prs_debug(ps, depth, desc, "spool_io_printer_driver_info_level_6");
4786         depth++;
4787                 
4788         /* reading */
4789         if (UNMARSHALLING(ps)) {
4790                 il=PRS_ALLOC_MEM(ps,SPOOL_PRINTER_DRIVER_INFO_LEVEL_6,1);
4791                 if(il == NULL)
4792                         return False;
4793                 *q_u=il;
4794         }
4795         else {
4796                 il=*q_u;
4797         }
4798         
4799         if(!prs_align(ps))
4800                 return False;
4801
4802         /* 
4803          * I know this seems weird, but I have no other explanation.
4804          * This is observed behavior on both NT4 and 2K servers.
4805          * --jerry
4806          */
4807          
4808         if (!prs_align_uint64(ps))
4809                 return False;
4810
4811         /* parse the main elements the packet */
4812
4813         if(!prs_uint32("cversion       ", ps, depth, &il->version))
4814                 return False;
4815         if(!prs_uint32("name           ", ps, depth, &il->name_ptr))
4816                 return False;
4817         if(!prs_uint32("environment    ", ps, depth, &il->environment_ptr))
4818                 return False;
4819         if(!prs_uint32("driverpath     ", ps, depth, &il->driverpath_ptr))
4820                 return False;
4821         if(!prs_uint32("datafile       ", ps, depth, &il->datafile_ptr))
4822                 return False;
4823         if(!prs_uint32("configfile     ", ps, depth, &il->configfile_ptr))
4824                 return False;
4825         if(!prs_uint32("helpfile       ", ps, depth, &il->helpfile_ptr))
4826                 return False;
4827         if(!prs_uint32("monitorname    ", ps, depth, &il->monitorname_ptr))
4828                 return False;
4829         if(!prs_uint32("defaultdatatype", ps, depth, &il->defaultdatatype_ptr))
4830                 return False;
4831         if(!prs_uint32("dependentfiles ", ps, depth, &il->dependentfiles_len))
4832                 return False;
4833         if(!prs_uint32("dependentfiles ", ps, depth, &il->dependentfiles_ptr))
4834                 return False;
4835         if(!prs_uint32("previousnames  ", ps, depth, &il->previousnames_len))
4836                 return False;
4837         if(!prs_uint32("previousnames  ", ps, depth, &il->previousnames_ptr))
4838                 return False;
4839         if(!smb_io_time("driverdate    ", &il->driverdate, ps, depth))
4840                 return False;
4841         if(!prs_uint32("dummy4         ", ps, depth, &il->dummy4))
4842                 return False;
4843         if(!prs_uint64("driverversion  ", ps, depth, &il->driverversion))
4844                 return False;
4845         if(!prs_uint32("mfgname        ", ps, depth, &il->mfgname_ptr))
4846                 return False;
4847         if(!prs_uint32("oemurl         ", ps, depth, &il->oemurl_ptr))
4848                 return False;
4849         if(!prs_uint32("hardwareid     ", ps, depth, &il->hardwareid_ptr))
4850                 return False;
4851         if(!prs_uint32("provider       ", ps, depth, &il->provider_ptr))
4852                 return False;
4853
4854         /* parse the structures in the packet */
4855
4856         if(!smb_io_unistr2("name", &il->name, il->name_ptr, ps, depth))
4857                 return False;
4858         if(!prs_align(ps))
4859                 return False;
4860
4861         if(!smb_io_unistr2("environment", &il->environment, il->environment_ptr, ps, depth))
4862                 return False;
4863         if(!prs_align(ps))
4864                 return False;
4865
4866         if(!smb_io_unistr2("driverpath", &il->driverpath, il->driverpath_ptr, ps, depth))
4867                 return False;
4868         if(!prs_align(ps))
4869                 return False;
4870
4871         if(!smb_io_unistr2("datafile", &il->datafile, il->datafile_ptr, ps, depth))
4872                 return False;
4873         if(!prs_align(ps))
4874                 return False;
4875
4876         if(!smb_io_unistr2("configfile", &il->configfile, il->configfile_ptr, ps, depth))
4877                 return False;
4878         if(!prs_align(ps))
4879                 return False;
4880
4881         if(!smb_io_unistr2("helpfile", &il->helpfile, il->helpfile_ptr, ps, depth))
4882                 return False;
4883         if(!prs_align(ps))
4884                 return False;
4885
4886         if(!smb_io_unistr2("monitorname", &il->monitorname, il->monitorname_ptr, ps, depth))
4887                 return False;
4888         if(!prs_align(ps))
4889                 return False;
4890
4891         if(!smb_io_unistr2("defaultdatatype", &il->defaultdatatype, il->defaultdatatype_ptr, ps, depth))
4892                 return False;
4893         if(!prs_align(ps))
4894                 return False;
4895         if (il->dependentfiles_ptr) {
4896                 if(!smb_io_buffer5("dependentfiles", &il->dependentfiles, ps, depth))
4897                         return False;
4898                 if(!prs_align(ps))
4899                         return False;
4900         }
4901         if (il->previousnames_ptr) {
4902                 if(!smb_io_buffer5("previousnames", &il->previousnames, ps, depth))
4903                         return False;
4904                 if(!prs_align(ps))
4905                         return False;
4906         }
4907         if(!smb_io_unistr2("mfgname", &il->mfgname, il->mfgname_ptr, ps, depth))
4908                 return False;
4909         if(!prs_align(ps))
4910                 return False;
4911         if(!smb_io_unistr2("oemurl", &il->oemurl, il->oemurl_ptr, ps, depth))
4912                 return False;
4913         if(!prs_align(ps))
4914                 return False;
4915         if(!smb_io_unistr2("hardwareid", &il->hardwareid, il->hardwareid_ptr, ps, depth))
4916                 return False;
4917         if(!prs_align(ps))
4918                 return False;
4919         if(!smb_io_unistr2("provider", &il->provider, il->provider_ptr, ps, depth))
4920                 return False;
4921
4922         return True;
4923 }
4924
4925 /*******************************************************************
4926  convert a buffer of UNICODE strings null terminated
4927  the buffer is terminated by a NULL
4928  
4929  convert to an dos codepage array (null terminated)
4930  
4931  dynamically allocate memory
4932  
4933 ********************************************************************/  
4934 static BOOL uniarray_2_dosarray(BUFFER5 *buf5, fstring **ar)
4935 {
4936         fstring f, *tar;
4937         int n = 0;
4938         char *src;
4939
4940         if (buf5==NULL)
4941                 return False;
4942
4943         src = (char *)buf5->buffer;
4944         *ar = NULL;
4945
4946         while (src < ((char *)buf5->buffer) + buf5->buf_len*2) {
4947                 rpcstr_pull(f, src, sizeof(f)-1, -1, STR_TERMINATE);
4948                 src = skip_unibuf(src, 2*buf5->buf_len - PTR_DIFF(src,buf5->buffer));
4949                 tar = SMB_REALLOC_ARRAY(*ar, fstring, n+2);
4950                 if (!tar)
4951                         return False;
4952                 else
4953                         *ar = tar;
4954                 fstrcpy((*ar)[n], f);
4955                 n++;
4956         }
4957         fstrcpy((*ar)[n], "");
4958  
4959         return True;
4960 }
4961
4962
4963
4964
4965 /*******************************************************************
4966  read a UNICODE array with null terminated strings 
4967  and null terminated array 
4968  and size of array at beginning
4969 ********************************************************************/  
4970
4971 BOOL smb_io_unibuffer(const char *desc, UNISTR2 *buffer, prs_struct *ps, int depth)
4972 {
4973         if (buffer==NULL) return False;
4974
4975         buffer->offset=0;
4976         buffer->uni_str_len=buffer->uni_max_len;
4977         
4978         if(!prs_uint32("buffer_size", ps, depth, &buffer->uni_max_len))
4979                 return False;
4980
4981         if(!prs_unistr2(True, "buffer     ", ps, depth, buffer))
4982                 return False;
4983
4984         return True;
4985 }
4986
4987 /*******************************************************************
4988 ********************************************************************/  
4989
4990 BOOL spool_io_printer_driver_info_level(const char *desc, SPOOL_PRINTER_DRIVER_INFO_LEVEL *il, prs_struct *ps, int depth)
4991 {
4992         prs_debug(ps, depth, desc, "spool_io_printer_driver_info_level");
4993         depth++;
4994
4995         if(!prs_align(ps))
4996                 return False;
4997         if(!prs_uint32("level", ps, depth, &il->level))
4998                 return False;
4999         if(!prs_uint32("ptr", ps, depth, &il->ptr))
5000                 return False;
5001
5002         if (il->ptr==0)
5003                 return True;
5004                 
5005         switch (il->level) {
5006                 case 3:
5007                         if(!spool_io_printer_driver_info_level_3("", &il->info_3, ps, depth))
5008                                 return False;
5009                         break;          
5010                 case 6:
5011                         if(!spool_io_printer_driver_info_level_6("", &il->info_6, ps, depth))
5012                                 return False;
5013                         break;          
5014         default:
5015                 return False;
5016         }
5017
5018         return True;
5019 }
5020
5021 /*******************************************************************
5022  init a SPOOL_Q_ADDPRINTERDRIVER struct
5023  ******************************************************************/
5024
5025 BOOL make_spoolss_q_addprinterdriver(TALLOC_CTX *mem_ctx,
5026                                 SPOOL_Q_ADDPRINTERDRIVER *q_u, const char* srv_name, 
5027                                 uint32 level, PRINTER_DRIVER_CTR *info)
5028 {
5029         DEBUG(5,("make_spoolss_q_addprinterdriver\n"));
5030         
5031         q_u->server_name_ptr = (srv_name!=NULL)?1:0;
5032         init_unistr2(&q_u->server_name, srv_name, UNI_STR_TERMINATE);
5033         
5034         q_u->level = level;
5035         
5036         q_u->info.level = level;
5037         q_u->info.ptr = (info!=NULL)?1:0;
5038         switch (level)
5039         {
5040         /* info level 3 is supported by Windows 95/98, WinNT and Win2k */
5041         case 3 :
5042                 make_spoolss_driver_info_3(mem_ctx, &q_u->info.info_3, info->info3);
5043                 break;
5044                 
5045         default:
5046                 DEBUG(0,("make_spoolss_q_addprinterdriver: Unknown info level [%d]\n", level));
5047                 break;
5048         }
5049         
5050         return True;
5051 }
5052
5053 BOOL make_spoolss_driver_info_3(TALLOC_CTX *mem_ctx, 
5054         SPOOL_PRINTER_DRIVER_INFO_LEVEL_3 **spool_drv_info,
5055                                 DRIVER_INFO_3 *info3)
5056 {
5057         uint32          len = 0;
5058         uint16          *ptr = info3->dependentfiles;
5059         BOOL            done = False;
5060         BOOL            null_char = False;
5061         SPOOL_PRINTER_DRIVER_INFO_LEVEL_3 *inf;
5062
5063         if (!(inf=TALLOC_ZERO_P(mem_ctx, SPOOL_PRINTER_DRIVER_INFO_LEVEL_3)))
5064                 return False;
5065         
5066         inf->cversion   = info3->version;
5067         inf->name_ptr   = (info3->name.buffer!=NULL)?1:0;
5068         inf->environment_ptr    = (info3->architecture.buffer!=NULL)?1:0;
5069         inf->driverpath_ptr     = (info3->driverpath.buffer!=NULL)?1:0;
5070         inf->datafile_ptr       = (info3->datafile.buffer!=NULL)?1:0;
5071         inf->configfile_ptr     = (info3->configfile.buffer!=NULL)?1:0;
5072         inf->helpfile_ptr       = (info3->helpfile.buffer!=NULL)?1:0;
5073         inf->monitorname_ptr    = (info3->monitorname.buffer!=NULL)?1:0;
5074         inf->defaultdatatype_ptr        = (info3->defaultdatatype.buffer!=NULL)?1:0;
5075
5076         init_unistr2_from_unistr(&inf->name, &info3->name);
5077         init_unistr2_from_unistr(&inf->environment, &info3->architecture);
5078         init_unistr2_from_unistr(&inf->driverpath, &info3->driverpath);
5079         init_unistr2_from_unistr(&inf->datafile, &info3->datafile);
5080         init_unistr2_from_unistr(&inf->configfile, &info3->configfile);
5081         init_unistr2_from_unistr(&inf->helpfile, &info3->helpfile);
5082         init_unistr2_from_unistr(&inf->monitorname, &info3->monitorname);
5083         init_unistr2_from_unistr(&inf->defaultdatatype, &info3->defaultdatatype);
5084
5085         while (!done)
5086         {
5087                 switch (*ptr)
5088                 {
5089                         case 0:
5090                                 /* the null_char BOOL is used to help locate
5091                                    two '\0's back to back */
5092                                 if (null_char)
5093                                         done = True;
5094                                 else
5095                                         null_char = True;
5096                                 break;
5097                                         
5098                         default:
5099                                 null_char = False;
5100                                 ;;
5101                                 break;                          
5102                 }
5103                 len++;
5104                 ptr++;
5105         }
5106         inf->dependentfiles_ptr = (info3->dependentfiles != NULL) ? 1 : 0;
5107         inf->dependentfilessize = len;
5108         if(!make_spoolss_buffer5(mem_ctx, &inf->dependentfiles, len, info3->dependentfiles))
5109         {
5110                 SAFE_FREE(inf);
5111                 return False;
5112         }
5113         
5114         *spool_drv_info = inf;
5115         
5116         return True;
5117 }
5118
5119 /*******************************************************************
5120  make a BUFFER5 struct from a uint16*
5121  ******************************************************************/
5122 BOOL make_spoolss_buffer5(TALLOC_CTX *mem_ctx, BUFFER5 *buf5, uint32 len, uint16 *src)
5123 {
5124
5125         buf5->buf_len = len;
5126         if((buf5->buffer=(uint16*)TALLOC_MEMDUP(mem_ctx, src, sizeof(uint16)*len)) == NULL) {
5127                 DEBUG(0,("make_spoolss_buffer5: Unable to malloc memory for buffer!\n"));
5128                 return False;
5129         }
5130         
5131         return True;
5132 }
5133
5134 /*******************************************************************
5135  fill in the prs_struct for a ADDPRINTERDRIVER request PDU
5136  ********************************************************************/  
5137
5138 BOOL spoolss_io_q_addprinterdriver(const char *desc, SPOOL_Q_ADDPRINTERDRIVER *q_u, prs_struct *ps, int depth)
5139 {
5140         prs_debug(ps, depth, desc, "spoolss_io_q_addprinterdriver");
5141         depth++;
5142
5143         if(!prs_align(ps))
5144                 return False;
5145
5146         if(!prs_uint32("server_name_ptr", ps, depth, &q_u->server_name_ptr))
5147                 return False;
5148         if(!smb_io_unistr2("server_name", &q_u->server_name, q_u->server_name_ptr, ps, depth))
5149                 return False;
5150                 
5151         if(!prs_align(ps))
5152                 return False;
5153         if(!prs_uint32("info_level", ps, depth, &q_u->level))
5154                 return False;
5155
5156         if(!spool_io_printer_driver_info_level("", &q_u->info, ps, depth))
5157                 return False;
5158
5159         return True;
5160 }
5161
5162 /*******************************************************************
5163 ********************************************************************/  
5164
5165 BOOL spoolss_io_r_addprinterdriver(const char *desc, SPOOL_R_ADDPRINTERDRIVER *q_u, prs_struct *ps, int depth)
5166 {
5167         prs_debug(ps, depth, desc, "spoolss_io_r_addprinterdriver");
5168         depth++;
5169
5170         if(!prs_werror("status", ps, depth, &q_u->status))
5171                 return False;
5172
5173         return True;
5174 }
5175
5176 /*******************************************************************
5177  fill in the prs_struct for a ADDPRINTERDRIVER request PDU
5178  ********************************************************************/  
5179
5180 BOOL spoolss_io_q_addprinterdriverex(const char *desc, SPOOL_Q_ADDPRINTERDRIVEREX *q_u, prs_struct *ps, int depth)
5181 {
5182         prs_debug(ps, depth, desc, "spoolss_io_q_addprinterdriverex");
5183         depth++;
5184
5185         if(!prs_align(ps))
5186                 return False;
5187
5188         if(!prs_uint32("server_name_ptr", ps, depth, &q_u->server_name_ptr))
5189                 return False;
5190         if(!smb_io_unistr2("server_name", &q_u->server_name, q_u->server_name_ptr, ps, depth))
5191                 return False;
5192                 
5193         if(!prs_align(ps))
5194                 return False;
5195         if(!prs_uint32("info_level", ps, depth, &q_u->level))
5196                 return False;
5197
5198         if(!spool_io_printer_driver_info_level("", &q_u->info, ps, depth))
5199                 return False;
5200
5201         if(!prs_align(ps))
5202                 return False;
5203         if(!prs_uint32("copy flags", ps, depth, &q_u->copy_flags))
5204                 return False;
5205                 
5206         return True;
5207 }
5208
5209 /*******************************************************************
5210 ********************************************************************/  
5211
5212 BOOL spoolss_io_r_addprinterdriverex(const char *desc, SPOOL_R_ADDPRINTERDRIVEREX *q_u, prs_struct *ps, int depth)
5213 {
5214         prs_debug(ps, depth, desc, "spoolss_io_r_addprinterdriverex");
5215         depth++;
5216
5217         if(!prs_werror("status", ps, depth, &q_u->status))
5218                 return False;
5219
5220         return True;
5221 }
5222
5223 /*******************************************************************
5224 ********************************************************************/  
5225
5226 BOOL uni_2_asc_printer_driver_3(SPOOL_PRINTER_DRIVER_INFO_LEVEL_3 *uni,
5227                                 NT_PRINTER_DRIVER_INFO_LEVEL_3 **asc)
5228 {
5229         NT_PRINTER_DRIVER_INFO_LEVEL_3 *d;
5230         
5231         DEBUG(7,("uni_2_asc_printer_driver_3: Converting from UNICODE to ASCII\n"));
5232         
5233         if (*asc==NULL)
5234         {
5235                 *asc=SMB_MALLOC_P(NT_PRINTER_DRIVER_INFO_LEVEL_3);
5236                 if(*asc == NULL)
5237                         return False;
5238                 ZERO_STRUCTP(*asc);
5239         }       
5240
5241         d=*asc;
5242
5243         d->cversion=uni->cversion;
5244
5245         unistr2_to_ascii(d->name,            &uni->name,            sizeof(d->name)-1);
5246         unistr2_to_ascii(d->environment,     &uni->environment,     sizeof(d->environment)-1);
5247         unistr2_to_ascii(d->driverpath,      &uni->driverpath,      sizeof(d->driverpath)-1);
5248         unistr2_to_ascii(d->datafile,        &uni->datafile,        sizeof(d->datafile)-1);
5249         unistr2_to_ascii(d->configfile,      &uni->configfile,      sizeof(d->configfile)-1);
5250         unistr2_to_ascii(d->helpfile,        &uni->helpfile,        sizeof(d->helpfile)-1);
5251         unistr2_to_ascii(d->monitorname,     &uni->monitorname,     sizeof(d->monitorname)-1);
5252         unistr2_to_ascii(d->defaultdatatype, &uni->defaultdatatype, sizeof(d->defaultdatatype)-1);
5253
5254         DEBUGADD(8,( "version:         %d\n", d->cversion));
5255         DEBUGADD(8,( "name:            %s\n", d->name));
5256         DEBUGADD(8,( "environment:     %s\n", d->environment));
5257         DEBUGADD(8,( "driverpath:      %s\n", d->driverpath));
5258         DEBUGADD(8,( "datafile:        %s\n", d->datafile));
5259         DEBUGADD(8,( "configfile:      %s\n", d->configfile));
5260         DEBUGADD(8,( "helpfile:        %s\n", d->helpfile));
5261         DEBUGADD(8,( "monitorname:     %s\n", d->monitorname));
5262         DEBUGADD(8,( "defaultdatatype: %s\n", d->defaultdatatype));
5263
5264         if (uniarray_2_dosarray(&uni->dependentfiles, &d->dependentfiles ))
5265                 return True;
5266         
5267         SAFE_FREE(*asc);
5268         return False;
5269 }
5270
5271 /*******************************************************************
5272 ********************************************************************/  
5273 BOOL uni_2_asc_printer_driver_6(SPOOL_PRINTER_DRIVER_INFO_LEVEL_6 *uni,
5274                                 NT_PRINTER_DRIVER_INFO_LEVEL_6 **asc)
5275 {
5276         NT_PRINTER_DRIVER_INFO_LEVEL_6 *d;
5277         
5278         DEBUG(7,("uni_2_asc_printer_driver_6: Converting from UNICODE to ASCII\n"));
5279         
5280         if (*asc==NULL)
5281         {
5282                 *asc=SMB_MALLOC_P(NT_PRINTER_DRIVER_INFO_LEVEL_6);
5283                 if(*asc == NULL)
5284                         return False;
5285                 ZERO_STRUCTP(*asc);
5286         }       
5287
5288         d=*asc;
5289
5290         d->version=uni->version;
5291
5292         unistr2_to_ascii(d->name,            &uni->name,            sizeof(d->name)-1);
5293         unistr2_to_ascii(d->environment,     &uni->environment,     sizeof(d->environment)-1);
5294         unistr2_to_ascii(d->driverpath,      &uni->driverpath,      sizeof(d->driverpath)-1);
5295         unistr2_to_ascii(d->datafile,        &uni->datafile,        sizeof(d->datafile)-1);
5296         unistr2_to_ascii(d->configfile,      &uni->configfile,      sizeof(d->configfile)-1);
5297         unistr2_to_ascii(d->helpfile,        &uni->helpfile,        sizeof(d->helpfile)-1);
5298         unistr2_to_ascii(d->monitorname,     &uni->monitorname,     sizeof(d->monitorname)-1);
5299         unistr2_to_ascii(d->defaultdatatype, &uni->defaultdatatype, sizeof(d->defaultdatatype)-1);
5300
5301         DEBUGADD(8,( "version:         %d\n", d->version));
5302         DEBUGADD(8,( "name:            %s\n", d->name));
5303         DEBUGADD(8,( "environment:     %s\n", d->environment));
5304         DEBUGADD(8,( "driverpath:      %s\n", d->driverpath));
5305         DEBUGADD(8,( "datafile:        %s\n", d->datafile));
5306         DEBUGADD(8,( "configfile:      %s\n", d->configfile));
5307         DEBUGADD(8,( "helpfile:        %s\n", d->helpfile));
5308         DEBUGADD(8,( "monitorname:     %s\n", d->monitorname));
5309         DEBUGADD(8,( "defaultdatatype: %s\n", d->defaultdatatype));
5310
5311         if (!uniarray_2_dosarray(&uni->dependentfiles, &d->dependentfiles ))
5312                 goto error;
5313         if (!uniarray_2_dosarray(&uni->previousnames, &d->previousnames ))
5314                 goto error;
5315         
5316         return True;
5317         
5318 error:
5319         SAFE_FREE(*asc);
5320         return False;
5321 }
5322
5323 BOOL uni_2_asc_printer_info_2(const SPOOL_PRINTER_INFO_LEVEL_2 *uni,
5324                               NT_PRINTER_INFO_LEVEL_2  **asc)
5325 {
5326         NT_PRINTER_INFO_LEVEL_2 *d;
5327         time_t time_unix;
5328         
5329         DEBUG(7,("Converting from UNICODE to ASCII\n"));
5330         time_unix=time(NULL);
5331         
5332         if (*asc==NULL) {
5333                 DEBUGADD(8,("allocating memory\n"));
5334
5335                 *asc=SMB_MALLOC_P(NT_PRINTER_INFO_LEVEL_2);
5336                 if(*asc == NULL)
5337                         return False;
5338                 ZERO_STRUCTP(*asc);
5339                 
5340                 /* we allocate memory iff called from 
5341                  * addprinter(ex) so we can do one time stuff here.
5342                  */
5343                 (*asc)->setuptime=time_unix;
5344
5345         }       
5346         DEBUGADD(8,("start converting\n"));
5347
5348         d=*asc;
5349                 
5350         d->attributes=uni->attributes;
5351         d->priority=uni->priority;
5352         d->default_priority=uni->default_priority;
5353         d->starttime=uni->starttime;
5354         d->untiltime=uni->untiltime;
5355         d->status=uni->status;
5356         d->cjobs=uni->cjobs;
5357         
5358         unistr2_to_ascii(d->servername, &uni->servername, sizeof(d->servername)-1);
5359         unistr2_to_ascii(d->printername, &uni->printername, sizeof(d->printername)-1);
5360         unistr2_to_ascii(d->sharename, &uni->sharename, sizeof(d->sharename)-1);
5361         unistr2_to_ascii(d->portname, &uni->portname, sizeof(d->portname)-1);
5362         unistr2_to_ascii(d->drivername, &uni->drivername, sizeof(d->drivername)-1);
5363         unistr2_to_ascii(d->comment, &uni->comment, sizeof(d->comment)-1);
5364         unistr2_to_ascii(d->location, &uni->location, sizeof(d->location)-1);
5365         unistr2_to_ascii(d->sepfile, &uni->sepfile, sizeof(d->sepfile)-1);
5366         unistr2_to_ascii(d->printprocessor, &uni->printprocessor, sizeof(d->printprocessor)-1);
5367         unistr2_to_ascii(d->datatype, &uni->datatype, sizeof(d->datatype)-1);
5368         unistr2_to_ascii(d->parameters, &uni->parameters, sizeof(d->parameters)-1);
5369
5370         return True;
5371 }
5372
5373 /*******************************************************************
5374  * init a structure.
5375  ********************************************************************/
5376
5377 BOOL make_spoolss_q_getprinterdriverdir(SPOOL_Q_GETPRINTERDRIVERDIR *q_u,
5378                                 fstring servername, fstring env_name, uint32 level,
5379                                 RPC_BUFFER *buffer, uint32 offered)
5380 {
5381         init_buf_unistr2(&q_u->name, &q_u->name_ptr, servername);
5382         init_buf_unistr2(&q_u->environment, &q_u->environment_ptr, env_name);
5383
5384         q_u->level=level;
5385         q_u->buffer=buffer;
5386         q_u->offered=offered;
5387
5388         return True;
5389 }
5390
5391 /*******************************************************************
5392  Parse a SPOOL_Q_GETPRINTERDRIVERDIR structure.
5393 ********************************************************************/  
5394
5395 BOOL spoolss_io_q_getprinterdriverdir(const char *desc, SPOOL_Q_GETPRINTERDRIVERDIR *q_u, prs_struct *ps, int depth)
5396 {
5397         prs_debug(ps, depth, desc, "spoolss_io_q_getprinterdriverdir");
5398         depth++;
5399
5400         if(!prs_align(ps))
5401                 return False;
5402         if(!prs_uint32("name_ptr", ps, depth, &q_u->name_ptr))
5403                 return False;
5404         if(!smb_io_unistr2("", &q_u->name, q_u->name_ptr, ps, depth))
5405                 return False;
5406
5407         if(!prs_align(ps))
5408                 return False;
5409                 
5410         if(!prs_uint32("", ps, depth, &q_u->environment_ptr))
5411                 return False;
5412         if(!smb_io_unistr2("", &q_u->environment, q_u->environment_ptr, ps, depth))
5413                 return False;
5414                 
5415         if(!prs_align(ps))
5416                 return False;
5417
5418         if(!prs_uint32("level", ps, depth, &q_u->level))
5419                 return False;
5420                 
5421         if(!prs_rpcbuffer_p("", ps, depth, &q_u->buffer))
5422                 return False;
5423                 
5424         if(!prs_align(ps))
5425                 return False;
5426                 
5427         if(!prs_uint32("offered", ps, depth, &q_u->offered))
5428                 return False;
5429
5430         return True;
5431 }
5432
5433 /*******************************************************************
5434  Parse a SPOOL_R_GETPRINTERDRIVERDIR structure.
5435 ********************************************************************/  
5436
5437 BOOL spoolss_io_r_getprinterdriverdir(const char *desc, SPOOL_R_GETPRINTERDRIVERDIR *r_u, prs_struct *ps, int depth)
5438 {               
5439         prs_debug(ps, depth, desc, "spoolss_io_r_getprinterdriverdir");
5440         depth++;
5441
5442         if (!prs_align(ps))
5443                 return False;
5444                 
5445         if (!prs_rpcbuffer_p("", ps, depth, &r_u->buffer))
5446                 return False;
5447
5448         if (!prs_align(ps))
5449                 return False;
5450                 
5451         if (!prs_uint32("needed", ps, depth, &r_u->needed))
5452                 return False;
5453                 
5454         if (!prs_werror("status", ps, depth, &r_u->status))
5455                 return False;
5456
5457         return True;            
5458 }
5459
5460 /*******************************************************************
5461 ********************************************************************/  
5462
5463 BOOL spoolss_io_r_enumprintprocessors(const char *desc, SPOOL_R_ENUMPRINTPROCESSORS *r_u, prs_struct *ps, int depth)
5464 {               
5465         prs_debug(ps, depth, desc, "spoolss_io_r_enumprintprocessors");
5466         depth++;
5467
5468         if (!prs_align(ps))
5469                 return False;
5470                 
5471         if (!prs_rpcbuffer_p("", ps, depth, &r_u->buffer))
5472                 return False;
5473
5474         if (!prs_align(ps))
5475                 return False;
5476                 
5477         if (!prs_uint32("needed", ps, depth, &r_u->needed))
5478                 return False;
5479                 
5480         if (!prs_uint32("returned", ps, depth, &r_u->returned))
5481                 return False;
5482                 
5483         if (!prs_werror("status", ps, depth, &r_u->status))
5484                 return False;
5485
5486         return True;            
5487 }
5488
5489 /*******************************************************************
5490 ********************************************************************/  
5491
5492 BOOL spoolss_io_q_enumprintprocessors(const char *desc, SPOOL_Q_ENUMPRINTPROCESSORS *q_u, prs_struct *ps, int depth)
5493 {
5494         prs_debug(ps, depth, desc, "spoolss_io_q_enumprintprocessors");
5495         depth++;
5496
5497         if (!prs_align(ps))
5498                 return False;
5499                 
5500         if (!prs_uint32("name_ptr", ps, depth, &q_u->name_ptr))
5501                 return False;
5502         if (!smb_io_unistr2("name", &q_u->name, True, ps, depth))
5503                 return False;
5504                 
5505         if (!prs_align(ps))
5506                 return False;
5507                 
5508         if (!prs_uint32("", ps, depth, &q_u->environment_ptr))
5509                 return False;
5510         if (!smb_io_unistr2("", &q_u->environment, q_u->environment_ptr, ps, depth))
5511                 return False;
5512         
5513         if (!prs_align(ps))
5514                 return False;
5515                 
5516         if (!prs_uint32("level", ps, depth, &q_u->level))
5517                 return False;
5518                 
5519         if(!prs_rpcbuffer_p("", ps, depth, &q_u->buffer))
5520                 return False;
5521
5522         if (!prs_align(ps))
5523                 return False;
5524
5525         if (!prs_uint32("offered", ps, depth, &q_u->offered))
5526                 return False;
5527
5528         return True;
5529 }
5530
5531 /*******************************************************************
5532 ********************************************************************/  
5533
5534 BOOL spoolss_io_q_addprintprocessor(const char *desc, SPOOL_Q_ADDPRINTPROCESSOR *q_u, prs_struct *ps, int depth)
5535 {
5536         prs_debug(ps, depth, desc, "spoolss_io_q_addprintprocessor");
5537         depth++;
5538
5539         if (!prs_align(ps))
5540                 return False;
5541                 
5542         if (!prs_uint32("server_ptr", ps, depth, &q_u->server_ptr))
5543                 return False;
5544         if (!smb_io_unistr2("server", &q_u->server, q_u->server_ptr, ps, depth))
5545                 return False;
5546                 
5547         if (!prs_align(ps))
5548                 return False;
5549         if (!smb_io_unistr2("environment", &q_u->environment, True, ps, depth))
5550                 return False;
5551                 
5552         if (!prs_align(ps))
5553                 return False;
5554         if (!smb_io_unistr2("path", &q_u->path, True, ps, depth))
5555                 return False;
5556
5557         if (!prs_align(ps))
5558                 return False;
5559         if (!smb_io_unistr2("name", &q_u->name, True, ps, depth))
5560                 return False;
5561
5562         return True;
5563 }
5564
5565 /*******************************************************************
5566 ********************************************************************/  
5567
5568 BOOL spoolss_io_r_addprintprocessor(const char *desc, SPOOL_R_ADDPRINTPROCESSOR *r_u, prs_struct *ps, int depth)
5569 {               
5570         prs_debug(ps, depth, desc, "spoolss_io_r_addprintproicessor");
5571         depth++;
5572
5573         if (!prs_align(ps))
5574                 return False;
5575                 
5576         if (!prs_werror("status", ps, depth, &r_u->status))
5577                 return False;
5578
5579         return True;            
5580 }
5581
5582 /*******************************************************************
5583 ********************************************************************/  
5584
5585 BOOL spoolss_io_r_enumprintprocdatatypes(const char *desc, SPOOL_R_ENUMPRINTPROCDATATYPES *r_u, prs_struct *ps, int depth)
5586 {               
5587         prs_debug(ps, depth, desc, "spoolss_io_r_enumprintprocdatatypes");
5588         depth++;
5589
5590         if (!prs_align(ps))
5591                 return False;
5592                 
5593         if (!prs_rpcbuffer_p("", ps, depth, &r_u->buffer))
5594                 return False;
5595
5596         if (!prs_align(ps))
5597                 return False;
5598                 
5599         if (!prs_uint32("needed", ps, depth, &r_u->needed))
5600                 return False;
5601                 
5602         if (!prs_uint32("returned", ps, depth, &r_u->returned))
5603                 return False;
5604                 
5605         if (!prs_werror("status", ps, depth, &r_u->status))
5606                 return False;
5607
5608         return True;            
5609 }
5610
5611 /*******************************************************************
5612 ********************************************************************/  
5613
5614 BOOL spoolss_io_q_enumprintprocdatatypes(const char *desc, SPOOL_Q_ENUMPRINTPROCDATATYPES *q_u, prs_struct *ps, int depth)
5615 {
5616         prs_debug(ps, depth, desc, "spoolss_io_q_enumprintprocdatatypes");
5617         depth++;
5618
5619         if (!prs_align(ps))
5620                 return False;
5621                 
5622         if (!prs_uint32("name_ptr", ps, depth, &q_u->name_ptr))
5623                 return False;
5624         if (!smb_io_unistr2("name", &q_u->name, True, ps, depth))
5625                 return False;
5626                 
5627         if (!prs_align(ps))
5628                 return False;
5629                 
5630         if (!prs_uint32("processor_ptr", ps, depth, &q_u->processor_ptr))
5631                 return False;
5632         if (!smb_io_unistr2("processor", &q_u->processor, q_u->processor_ptr, ps, depth))
5633                 return False;
5634         
5635         if (!prs_align(ps))
5636                 return False;
5637                 
5638         if (!prs_uint32("level", ps, depth, &q_u->level))
5639                 return False;
5640                 
5641         if(!prs_rpcbuffer_p("buffer", ps, depth, &q_u->buffer))
5642                 return False;
5643
5644         if (!prs_align(ps))
5645                 return False;
5646
5647         if (!prs_uint32("offered", ps, depth, &q_u->offered))
5648                 return False;
5649
5650         return True;
5651 }
5652
5653 /*******************************************************************
5654  Parse a SPOOL_Q_ENUMPRINTMONITORS structure.
5655 ********************************************************************/  
5656
5657 BOOL spoolss_io_q_enumprintmonitors(const char *desc, SPOOL_Q_ENUMPRINTMONITORS *q_u, prs_struct *ps, int depth)
5658 {
5659         prs_debug(ps, depth, desc, "spoolss_io_q_enumprintmonitors");
5660         depth++;
5661
5662         if (!prs_align(ps))
5663                 return False;
5664                 
5665         if (!prs_uint32("name_ptr", ps, depth, &q_u->name_ptr))
5666                 return False;
5667         if (!smb_io_unistr2("name", &q_u->name, True, ps, depth))
5668                 return False;
5669                 
5670         if (!prs_align(ps))
5671                 return False;
5672                                 
5673         if (!prs_uint32("level", ps, depth, &q_u->level))
5674                 return False;
5675                 
5676         if(!prs_rpcbuffer_p("", ps, depth, &q_u->buffer))
5677                 return False;
5678
5679         if (!prs_align(ps))
5680                 return False;
5681
5682         if (!prs_uint32("offered", ps, depth, &q_u->offered))
5683                 return False;
5684
5685         return True;
5686 }
5687
5688 /*******************************************************************
5689 ********************************************************************/  
5690
5691 BOOL spoolss_io_r_enumprintmonitors(const char *desc, SPOOL_R_ENUMPRINTMONITORS *r_u, prs_struct *ps, int depth)
5692 {               
5693         prs_debug(ps, depth, desc, "spoolss_io_r_enumprintmonitors");
5694         depth++;
5695
5696         if (!prs_align(ps))
5697                 return False;
5698                 
5699         if (!prs_rpcbuffer_p("", ps, depth, &r_u->buffer))
5700                 return False;
5701
5702         if (!prs_align(ps))
5703                 return False;
5704                 
5705         if (!prs_uint32("needed", ps, depth, &r_u->needed))
5706                 return False;
5707                 
5708         if (!prs_uint32("returned", ps, depth, &r_u->returned))
5709                 return False;
5710                 
5711         if (!prs_werror("status", ps, depth, &r_u->status))
5712                 return False;
5713
5714         return True;            
5715 }
5716
5717 /*******************************************************************
5718 ********************************************************************/  
5719
5720 BOOL spoolss_io_r_enumprinterdata(const char *desc, SPOOL_R_ENUMPRINTERDATA *r_u, prs_struct *ps, int depth)
5721 {       
5722         prs_debug(ps, depth, desc, "spoolss_io_r_enumprinterdata");
5723         depth++;
5724
5725         if(!prs_align(ps))
5726                 return False;
5727         if(!prs_uint32("valuesize", ps, depth, &r_u->valuesize))
5728                 return False;
5729
5730         if (UNMARSHALLING(ps) && r_u->valuesize) {
5731                 r_u->value = PRS_ALLOC_MEM(ps, uint16, r_u->valuesize);
5732                 if (!r_u->value) {
5733                         DEBUG(0, ("spoolss_io_r_enumprinterdata: out of memory for printerdata value\n"));
5734                         return False;
5735                 }
5736         }
5737
5738         if(!prs_uint16uni(False, "value", ps, depth, r_u->value, r_u->valuesize ))
5739                 return False;
5740
5741         if(!prs_align(ps))
5742                 return False;
5743
5744         if(!prs_uint32("realvaluesize", ps, depth, &r_u->realvaluesize))
5745                 return False;
5746
5747         if(!prs_uint32("type", ps, depth, &r_u->type))
5748                 return False;
5749
5750         if(!prs_uint32("datasize", ps, depth, &r_u->datasize))
5751                 return False;
5752
5753         if (UNMARSHALLING(ps) && r_u->datasize) {
5754                 r_u->data = PRS_ALLOC_MEM(ps, uint8, r_u->datasize);
5755                 if (!r_u->data) {
5756                         DEBUG(0, ("spoolss_io_r_enumprinterdata: out of memory for printerdata data\n"));
5757                         return False;
5758                 }
5759         }
5760
5761         if(!prs_uint8s(False, "data", ps, depth, r_u->data, r_u->datasize))
5762                 return False;
5763         if(!prs_align(ps))
5764                 return False;
5765
5766         if(!prs_uint32("realdatasize", ps, depth, &r_u->realdatasize))
5767                 return False;
5768         if(!prs_werror("status", ps, depth, &r_u->status))
5769                 return False;
5770
5771         return True;
5772 }
5773
5774 /*******************************************************************
5775 ********************************************************************/  
5776
5777 BOOL spoolss_io_q_enumprinterdata(const char *desc, SPOOL_Q_ENUMPRINTERDATA *q_u, prs_struct *ps, int depth)
5778 {
5779         prs_debug(ps, depth, desc, "spoolss_io_q_enumprinterdata");
5780         depth++;
5781
5782         if(!prs_align(ps))
5783                 return False;
5784         if(!smb_io_pol_hnd("printer handle",&q_u->handle,ps,depth))
5785                 return False;
5786         if(!prs_uint32("index", ps, depth, &q_u->index))
5787                 return False;
5788         if(!prs_uint32("valuesize", ps, depth, &q_u->valuesize))
5789                 return False;
5790         if(!prs_uint32("datasize", ps, depth, &q_u->datasize))
5791                 return False;
5792
5793         return True;
5794 }
5795
5796 /*******************************************************************
5797 ********************************************************************/  
5798
5799 BOOL make_spoolss_q_enumprinterdata(SPOOL_Q_ENUMPRINTERDATA *q_u,
5800                 const POLICY_HND *hnd,
5801                 uint32 idx, uint32 valuelen, uint32 datalen)
5802 {
5803         memcpy(&q_u->handle, hnd, sizeof(q_u->handle));
5804         q_u->index=idx;
5805         q_u->valuesize=valuelen;
5806         q_u->datasize=datalen;
5807
5808         return True;
5809 }
5810
5811 /*******************************************************************
5812 ********************************************************************/  
5813
5814 BOOL make_spoolss_q_enumprinterdataex(SPOOL_Q_ENUMPRINTERDATAEX *q_u,
5815                                       const POLICY_HND *hnd, const char *key,
5816                                       uint32 size)
5817 {
5818         memcpy(&q_u->handle, hnd, sizeof(q_u->handle));
5819         init_unistr2(&q_u->key, key, UNI_STR_TERMINATE);
5820         q_u->size = size;
5821
5822         return True;
5823 }
5824
5825 /*******************************************************************
5826 ********************************************************************/  
5827 BOOL make_spoolss_q_setprinterdata(SPOOL_Q_SETPRINTERDATA *q_u, const POLICY_HND *hnd,
5828                                    char* value, uint32 data_type, char* data, uint32 data_size)
5829 {
5830         memcpy(&q_u->handle, hnd, sizeof(q_u->handle));
5831         q_u->type = data_type;
5832         init_unistr2(&q_u->value, value, UNI_STR_TERMINATE);
5833
5834         q_u->max_len = q_u->real_len = data_size;
5835         q_u->data = (unsigned char *)data;
5836         
5837         return True;
5838 }
5839
5840 /*******************************************************************
5841 ********************************************************************/  
5842 BOOL make_spoolss_q_setprinterdataex(SPOOL_Q_SETPRINTERDATAEX *q_u, const POLICY_HND *hnd,
5843                                      char *key, char* value, uint32 data_type, char* data, 
5844                                      uint32 data_size)
5845 {
5846         memcpy(&q_u->handle, hnd, sizeof(q_u->handle));
5847         q_u->type = data_type;
5848         init_unistr2(&q_u->value, value, UNI_STR_TERMINATE);
5849         init_unistr2(&q_u->key, key, UNI_STR_TERMINATE);
5850
5851         q_u->max_len = q_u->real_len = data_size;
5852         q_u->data = (unsigned char *)data;
5853         
5854         return True;
5855 }
5856
5857 /*******************************************************************
5858 ********************************************************************/  
5859
5860 BOOL spoolss_io_q_setprinterdata(const char *desc, SPOOL_Q_SETPRINTERDATA *q_u, prs_struct *ps, int depth)
5861 {
5862         prs_debug(ps, depth, desc, "spoolss_io_q_setprinterdata");
5863         depth++;
5864
5865         if(!prs_align(ps))
5866                 return False;
5867         if(!smb_io_pol_hnd("printer handle", &q_u->handle, ps, depth))
5868                 return False;
5869         if(!smb_io_unistr2("", &q_u->value, True, ps, depth))
5870                 return False;
5871
5872         if(!prs_align(ps))
5873                 return False;
5874
5875         if(!prs_uint32("type", ps, depth, &q_u->type))
5876                 return False;
5877
5878         if(!prs_uint32("max_len", ps, depth, &q_u->max_len))
5879                 return False;
5880
5881         switch (q_u->type)
5882         {
5883                 case REG_SZ:
5884                 case REG_BINARY:
5885                 case REG_DWORD:
5886                 case REG_MULTI_SZ:
5887             if (q_u->max_len) {
5888                 if (UNMARSHALLING(ps))
5889                                 q_u->data=PRS_ALLOC_MEM(ps, uint8, q_u->max_len);
5890                         if(q_u->data == NULL)
5891                                 return False;
5892                         if(!prs_uint8s(False,"data", ps, depth, q_u->data, q_u->max_len))
5893                                 return False;
5894             }
5895                         if(!prs_align(ps))
5896                                 return False;
5897                         break;
5898         }       
5899         
5900         if(!prs_uint32("real_len", ps, depth, &q_u->real_len))
5901                 return False;
5902
5903         return True;
5904 }
5905
5906 /*******************************************************************
5907 ********************************************************************/  
5908
5909 BOOL spoolss_io_r_setprinterdata(const char *desc, SPOOL_R_SETPRINTERDATA *r_u, prs_struct *ps, int depth)
5910 {
5911         prs_debug(ps, depth, desc, "spoolss_io_r_setprinterdata");
5912         depth++;
5913
5914         if(!prs_align(ps))
5915                 return False;
5916         if(!prs_werror("status",     ps, depth, &r_u->status))
5917                 return False;
5918
5919         return True;
5920 }
5921
5922 /*******************************************************************
5923 ********************************************************************/  
5924 BOOL spoolss_io_q_resetprinter(const char *desc, SPOOL_Q_RESETPRINTER *q_u, prs_struct *ps, int depth)
5925 {
5926         prs_debug(ps, depth, desc, "spoolss_io_q_resetprinter");
5927         depth++;
5928
5929         if (!prs_align(ps))
5930                 return False;
5931         if (!smb_io_pol_hnd("printer handle", &q_u->handle, ps, depth))
5932                 return False;
5933
5934         if (!prs_uint32("datatype_ptr", ps, depth, &q_u->datatype_ptr))
5935                 return False;
5936                 
5937         if (q_u->datatype_ptr) {
5938                 if (!smb_io_unistr2("datatype", &q_u->datatype, q_u->datatype_ptr?True:False, ps, depth))
5939                 return False;
5940         }
5941
5942         if (!spoolss_io_devmode_cont(desc, &q_u->devmode_ctr, ps, depth))
5943                 return False;
5944
5945         return True;
5946 }
5947
5948
5949 /*******************************************************************
5950 ********************************************************************/  
5951 BOOL spoolss_io_r_resetprinter(const char *desc, SPOOL_R_RESETPRINTER *r_u, prs_struct *ps, int depth)
5952 {
5953         prs_debug(ps, depth, desc, "spoolss_io_r_resetprinter");
5954         depth++;
5955
5956         if(!prs_align(ps))
5957                 return False;
5958         if(!prs_werror("status",     ps, depth, &r_u->status))
5959                 return False;
5960
5961         return True;
5962 }
5963
5964 /*******************************************************************
5965 ********************************************************************/  
5966
5967 static BOOL spoolss_io_addform(const char *desc, FORM *f, uint32 ptr, prs_struct *ps, int depth)
5968 {
5969         prs_debug(ps, depth, desc, "spoolss_io_addform");
5970         depth++;
5971         if(!prs_align(ps))
5972                 return False;
5973
5974         if (ptr!=0)
5975         {
5976                 if(!prs_uint32("flags",    ps, depth, &f->flags))
5977                         return False;
5978                 if(!prs_uint32("name_ptr", ps, depth, &f->name_ptr))
5979                         return False;
5980                 if(!prs_uint32("size_x",   ps, depth, &f->size_x))
5981                         return False;
5982                 if(!prs_uint32("size_y",   ps, depth, &f->size_y))
5983                         return False;
5984                 if(!prs_uint32("left",     ps, depth, &f->left))
5985                         return False;
5986                 if(!prs_uint32("top",      ps, depth, &f->top))
5987                         return False;
5988                 if(!prs_uint32("right",    ps, depth, &f->right))
5989                         return False;
5990                 if(!prs_uint32("bottom",   ps, depth, &f->bottom))
5991                         return False;
5992
5993                 if(!smb_io_unistr2("", &f->name, f->name_ptr, ps, depth))
5994                         return False;
5995         }
5996
5997         return True;
5998 }
5999
6000 /*******************************************************************
6001 ********************************************************************/  
6002
6003 BOOL spoolss_io_q_deleteform(const char *desc, SPOOL_Q_DELETEFORM *q_u, prs_struct *ps, int depth)
6004 {
6005         prs_debug(ps, depth, desc, "spoolss_io_q_deleteform");
6006         depth++;
6007
6008         if(!prs_align(ps))
6009                 return False;
6010         if(!smb_io_pol_hnd("printer handle", &q_u->handle, ps, depth))
6011                 return False;
6012         if(!smb_io_unistr2("form name", &q_u->name, True, ps, depth))
6013                 return False;
6014
6015         return True;
6016 }
6017
6018 /*******************************************************************
6019 ********************************************************************/  
6020
6021 BOOL spoolss_io_r_deleteform(const char *desc, SPOOL_R_DELETEFORM *r_u, prs_struct *ps, int depth)
6022 {
6023         prs_debug(ps, depth, desc, "spoolss_io_r_deleteform");
6024         depth++;
6025
6026         if(!prs_align(ps))
6027                 return False;
6028         if(!prs_werror("status",        ps, depth, &r_u->status))
6029                 return False;
6030
6031         return True;
6032 }
6033
6034 /*******************************************************************
6035 ********************************************************************/  
6036
6037 BOOL spoolss_io_q_addform(const char *desc, SPOOL_Q_ADDFORM *q_u, prs_struct *ps, int depth)
6038 {
6039         uint32 useless_ptr=1;
6040         prs_debug(ps, depth, desc, "spoolss_io_q_addform");
6041         depth++;
6042
6043         if(!prs_align(ps))
6044                 return False;
6045         if(!smb_io_pol_hnd("printer handle", &q_u->handle, ps, depth))
6046                 return False;
6047         if(!prs_uint32("level",  ps, depth, &q_u->level))
6048                 return False;
6049         if(!prs_uint32("level2", ps, depth, &q_u->level2))
6050                 return False;
6051
6052         if (q_u->level==1)
6053         {
6054                 if(!prs_uint32("useless_ptr", ps, depth, &useless_ptr))
6055                         return False;
6056                 if(!spoolss_io_addform("", &q_u->form, useless_ptr, ps, depth))
6057                         return False;
6058         }
6059
6060         return True;
6061 }
6062
6063 /*******************************************************************
6064 ********************************************************************/  
6065
6066 BOOL spoolss_io_r_addform(const char *desc, SPOOL_R_ADDFORM *r_u, prs_struct *ps, int depth)
6067 {
6068         prs_debug(ps, depth, desc, "spoolss_io_r_addform");
6069         depth++;
6070
6071         if(!prs_align(ps))
6072                 return False;
6073         if(!prs_werror("status",        ps, depth, &r_u->status))
6074                 return False;
6075
6076         return True;
6077 }
6078
6079 /*******************************************************************
6080 ********************************************************************/  
6081
6082 BOOL spoolss_io_q_setform(const char *desc, SPOOL_Q_SETFORM *q_u, prs_struct *ps, int depth)
6083 {
6084         uint32 useless_ptr=1;
6085         prs_debug(ps, depth, desc, "spoolss_io_q_setform");
6086         depth++;
6087
6088         if(!prs_align(ps))
6089                 return False;
6090         if(!smb_io_pol_hnd("printer handle", &q_u->handle, ps, depth))
6091                 return False;
6092         if(!smb_io_unistr2("", &q_u->name, True, ps, depth))
6093                 return False;
6094               
6095         if(!prs_align(ps))
6096                 return False;
6097         
6098         if(!prs_uint32("level",  ps, depth, &q_u->level))
6099                 return False;
6100         if(!prs_uint32("level2", ps, depth, &q_u->level2))
6101                 return False;
6102
6103         if (q_u->level==1)
6104         {
6105                 if(!prs_uint32("useless_ptr", ps, depth, &useless_ptr))
6106                         return False;
6107                 if(!spoolss_io_addform("", &q_u->form, useless_ptr, ps, depth))
6108                         return False;
6109         }
6110
6111         return True;
6112 }
6113
6114 /*******************************************************************
6115 ********************************************************************/  
6116
6117 BOOL spoolss_io_r_setform(const char *desc, SPOOL_R_SETFORM *r_u, prs_struct *ps, int depth)
6118 {
6119         prs_debug(ps, depth, desc, "spoolss_io_r_setform");
6120         depth++;
6121
6122         if(!prs_align(ps))
6123                 return False;
6124         if(!prs_werror("status",        ps, depth, &r_u->status))
6125                 return False;
6126
6127         return True;
6128 }
6129
6130 /*******************************************************************
6131  Parse a SPOOL_R_GETJOB structure.
6132 ********************************************************************/  
6133
6134 BOOL spoolss_io_r_getjob(const char *desc, SPOOL_R_GETJOB *r_u, prs_struct *ps, int depth)
6135 {               
6136         prs_debug(ps, depth, desc, "spoolss_io_r_getjob");
6137         depth++;
6138
6139         if (!prs_align(ps))
6140                 return False;
6141                 
6142         if (!prs_rpcbuffer_p("", ps, depth, &r_u->buffer))
6143                 return False;
6144
6145         if (!prs_align(ps))
6146                 return False;
6147                 
6148         if (!prs_uint32("needed", ps, depth, &r_u->needed))
6149                 return False;
6150                 
6151         if (!prs_werror("status", ps, depth, &r_u->status))
6152                 return False;
6153
6154         return True;            
6155 }
6156
6157 /*******************************************************************
6158  Parse a SPOOL_Q_GETJOB structure.
6159 ********************************************************************/  
6160
6161 BOOL spoolss_io_q_getjob(const char *desc, SPOOL_Q_GETJOB *q_u, prs_struct *ps, int depth)
6162 {
6163         prs_debug(ps, depth, desc, "");
6164         depth++;
6165
6166         if(!prs_align(ps))
6167                 return False;
6168
6169         if(!smb_io_pol_hnd("printer handle",&q_u->handle,ps,depth))
6170                 return False;
6171         if(!prs_uint32("jobid", ps, depth, &q_u->jobid))
6172                 return False;
6173         if(!prs_uint32("level", ps, depth, &q_u->level))
6174                 return False;
6175         
6176         if(!prs_rpcbuffer_p("", ps, depth, &q_u->buffer))
6177                 return False;
6178
6179         if(!prs_align(ps))
6180                 return False;
6181         
6182         if(!prs_uint32("offered", ps, depth, &q_u->offered))
6183                 return False;
6184
6185         return True;
6186 }
6187
6188 void free_devmode(DEVICEMODE *devmode)
6189 {
6190         if (devmode!=NULL) {
6191                 SAFE_FREE(devmode->private);
6192                 SAFE_FREE(devmode);
6193         }
6194 }
6195
6196 void free_printer_info_1(PRINTER_INFO_1 *printer)
6197 {
6198         SAFE_FREE(printer);
6199 }
6200
6201 void free_printer_info_2(PRINTER_INFO_2 *printer)
6202 {
6203         if (printer!=NULL) {
6204                 free_devmode(printer->devmode);
6205                 printer->devmode = NULL;
6206                 SAFE_FREE(printer);
6207         }
6208 }
6209
6210 void free_printer_info_3(PRINTER_INFO_3 *printer)
6211 {
6212         SAFE_FREE(printer);
6213 }
6214
6215 void free_printer_info_4(PRINTER_INFO_4 *printer)
6216 {
6217         SAFE_FREE(printer);
6218 }
6219
6220 void free_printer_info_5(PRINTER_INFO_5 *printer)
6221 {
6222         SAFE_FREE(printer);
6223 }
6224
6225 void free_printer_info_7(PRINTER_INFO_7 *printer)
6226 {
6227         SAFE_FREE(printer);
6228 }
6229
6230 void free_job_info_2(JOB_INFO_2 *job)
6231 {
6232     if (job!=NULL)
6233         free_devmode(job->devmode);
6234 }
6235
6236 /*******************************************************************
6237  * init a structure.
6238  ********************************************************************/
6239
6240 BOOL make_spoolss_q_replyopenprinter(SPOOL_Q_REPLYOPENPRINTER *q_u, 
6241                                const fstring string, uint32 printer, uint32 type)
6242 {      
6243         if (q_u == NULL)
6244                 return False;
6245
6246         init_unistr2(&q_u->string, string, UNI_STR_TERMINATE);
6247
6248         q_u->printer=printer;
6249         q_u->type=type;
6250
6251         q_u->unknown0=0x0;
6252         q_u->unknown1=0x0;
6253
6254         return True;
6255 }
6256
6257 /*******************************************************************
6258  Parse a SPOOL_Q_REPLYOPENPRINTER structure.
6259 ********************************************************************/  
6260
6261 BOOL spoolss_io_q_replyopenprinter(const char *desc, SPOOL_Q_REPLYOPENPRINTER *q_u, prs_struct *ps, int depth)
6262 {
6263         prs_debug(ps, depth, desc, "spoolss_io_q_replyopenprinter");
6264         depth++;
6265
6266         if(!prs_align(ps))
6267                 return False;
6268
6269         if(!smb_io_unistr2("", &q_u->string, True, ps, depth))
6270                 return False;
6271
6272         if(!prs_align(ps))
6273                 return False;
6274
6275         if(!prs_uint32("printer", ps, depth, &q_u->printer))
6276                 return False;
6277         if(!prs_uint32("type", ps, depth, &q_u->type))
6278                 return False;
6279         
6280         if(!prs_uint32("unknown0", ps, depth, &q_u->unknown0))
6281                 return False;
6282         if(!prs_uint32("unknown1", ps, depth, &q_u->unknown1))
6283                 return False;
6284
6285         return True;
6286 }
6287
6288 /*******************************************************************
6289  Parse a SPOOL_R_REPLYOPENPRINTER structure.
6290 ********************************************************************/  
6291
6292 BOOL spoolss_io_r_replyopenprinter(const char *desc, SPOOL_R_REPLYOPENPRINTER *r_u, prs_struct *ps, int depth)
6293 {               
6294         prs_debug(ps, depth, desc, "spoolss_io_r_replyopenprinter");
6295         depth++;
6296
6297         if (!prs_align(ps))
6298                 return False;
6299
6300         if(!smb_io_pol_hnd("printer handle",&r_u->handle,ps,depth))
6301                 return False;
6302
6303         if (!prs_werror("status", ps, depth, &r_u->status))
6304                 return False;
6305
6306         return True;            
6307 }
6308
6309 /*******************************************************************
6310  * init a structure.
6311  ********************************************************************/
6312 BOOL make_spoolss_q_routerreplyprinter(SPOOL_Q_ROUTERREPLYPRINTER *q_u, POLICY_HND *hnd, 
6313                                         uint32 condition, uint32 change_id)
6314 {
6315
6316         memcpy(&q_u->handle, hnd, sizeof(q_u->handle));
6317
6318         q_u->condition = condition;
6319         q_u->change_id = change_id;
6320
6321         /* magic values */
6322         q_u->unknown1 = 0x1;
6323         memset(q_u->unknown2, 0x0, 5);
6324         q_u->unknown2[0] = 0x1;
6325
6326         return True;
6327 }
6328
6329 /*******************************************************************
6330  Parse a SPOOL_Q_ROUTERREPLYPRINTER structure.
6331 ********************************************************************/
6332 BOOL spoolss_io_q_routerreplyprinter (const char *desc, SPOOL_Q_ROUTERREPLYPRINTER *q_u, prs_struct *ps, int depth)
6333 {
6334
6335         prs_debug(ps, depth, desc, "spoolss_io_q_routerreplyprinter");
6336         depth++;
6337
6338         if (!prs_align(ps))
6339                 return False;
6340
6341         if(!smb_io_pol_hnd("printer handle",&q_u->handle,ps,depth))
6342                 return False;
6343
6344         if (!prs_uint32("condition", ps, depth, &q_u->condition))
6345                 return False;
6346
6347         if (!prs_uint32("unknown1", ps, depth, &q_u->unknown1))
6348                 return False;
6349
6350         if (!prs_uint32("change_id", ps, depth, &q_u->change_id))
6351                 return False;
6352
6353         if (!prs_uint8s(False, "private",  ps, depth, q_u->unknown2, 5))
6354                 return False;
6355
6356         return True;
6357 }
6358
6359 /*******************************************************************
6360  Parse a SPOOL_R_ROUTERREPLYPRINTER structure.
6361 ********************************************************************/
6362 BOOL spoolss_io_r_routerreplyprinter (const char *desc, SPOOL_R_ROUTERREPLYPRINTER *r_u, prs_struct *ps, int depth)
6363 {
6364         prs_debug(ps, depth, desc, "spoolss_io_r_routerreplyprinter");
6365         depth++;
6366
6367         if (!prs_align(ps))
6368                 return False;
6369
6370         if (!prs_werror("status", ps, depth, &r_u->status))
6371                 return False;
6372
6373         return True;
6374 }
6375
6376 /*******************************************************************
6377  * init a structure.
6378  ********************************************************************/
6379
6380 BOOL make_spoolss_q_reply_closeprinter(SPOOL_Q_REPLYCLOSEPRINTER *q_u, POLICY_HND *hnd)
6381 {      
6382         if (q_u == NULL)
6383                 return False;
6384
6385         memcpy(&q_u->handle, hnd, sizeof(q_u->handle));
6386
6387         return True;
6388 }
6389
6390 /*******************************************************************
6391  Parse a SPOOL_Q_REPLYCLOSEPRINTER structure.
6392 ********************************************************************/  
6393
6394 BOOL spoolss_io_q_replycloseprinter(const char *desc, SPOOL_Q_REPLYCLOSEPRINTER *q_u, prs_struct *ps, int depth)
6395 {
6396         prs_debug(ps, depth, desc, "spoolss_io_q_replycloseprinter");
6397         depth++;
6398
6399         if(!prs_align(ps))
6400                 return False;
6401
6402         if(!smb_io_pol_hnd("printer handle",&q_u->handle,ps,depth))
6403                 return False;
6404
6405         return True;
6406 }
6407
6408 /*******************************************************************
6409  Parse a SPOOL_R_REPLYCLOSEPRINTER structure.
6410 ********************************************************************/  
6411
6412 BOOL spoolss_io_r_replycloseprinter(const char *desc, SPOOL_R_REPLYCLOSEPRINTER *r_u, prs_struct *ps, int depth)
6413 {               
6414         prs_debug(ps, depth, desc, "spoolss_io_r_replycloseprinter");
6415         depth++;
6416
6417         if (!prs_align(ps))
6418                 return False;
6419
6420         if(!smb_io_pol_hnd("printer handle",&r_u->handle,ps,depth))
6421                 return False;
6422
6423         if (!prs_werror("status", ps, depth, &r_u->status))
6424                 return False;
6425
6426         return True;            
6427 }
6428
6429 #if 0   /* JERRY - not currently used but could be :-) */
6430
6431 /*******************************************************************
6432  Deep copy a SPOOL_NOTIFY_INFO_DATA structure
6433  ******************************************************************/
6434 static BOOL copy_spool_notify_info_data(SPOOL_NOTIFY_INFO_DATA *dst, 
6435                                 SPOOL_NOTIFY_INFO_DATA *src, int n)
6436 {
6437         int i;
6438
6439         memcpy(dst, src, sizeof(SPOOL_NOTIFY_INFO_DATA)*n);
6440         
6441         for (i=0; i<n; i++) {
6442                 int len;
6443                 uint16 *s = NULL;
6444                 
6445                 if (src->size != POINTER) 
6446                         continue;
6447                 len = src->notify_data.data.length;
6448                 s = SMB_MALLOC_ARRAY(uint16, len);
6449                 if (s == NULL) {
6450                         DEBUG(0,("copy_spool_notify_info_data: malloc() failed!\n"));
6451                         return False;
6452                 }
6453                 
6454                 memcpy(s, src->notify_data.data.string, len*2);
6455                 dst->notify_data.data.string = s;
6456         }
6457         
6458         return True;
6459 }
6460
6461 /*******************************************************************
6462  Deep copy a SPOOL_NOTIFY_INFO structure
6463  ******************************************************************/
6464 static BOOL copy_spool_notify_info(SPOOL_NOTIFY_INFO *dst, SPOOL_NOTIFY_INFO *src)
6465 {
6466         if (!dst) {
6467                 DEBUG(0,("copy_spool_notify_info: NULL destination pointer!\n"));
6468                 return False;
6469         }
6470                 
6471         dst->version = src->version;
6472         dst->flags   = src->flags;
6473         dst->count   = src->count;
6474         
6475         if (dst->count) 
6476         {
6477                 dst->data = SMB_MALLOC_ARRAY(SPOOL_NOTIFY_INFO_DATA, dst->count);
6478                 
6479                 DEBUG(10,("copy_spool_notify_info: allocating space for [%d] PRINTER_NOTIFY_INFO_DATA entries\n",
6480                         dst->count));
6481
6482                 if (dst->data == NULL) {
6483                         DEBUG(0,("copy_spool_notify_info: malloc() failed for [%d] entries!\n", 
6484                                 dst->count));
6485                         return False;
6486                 }
6487                 
6488                 return (copy_spool_notify_info_data(dst->data, src->data, src->count));
6489         }
6490         
6491         return True;
6492 }
6493 #endif  /* JERRY */
6494
6495 /*******************************************************************
6496  * init a structure.
6497  ********************************************************************/
6498
6499 BOOL make_spoolss_q_reply_rrpcn(SPOOL_Q_REPLY_RRPCN *q_u, POLICY_HND *hnd,
6500                                 uint32 change_low, uint32 change_high,
6501                                 SPOOL_NOTIFY_INFO *info)
6502 {      
6503         if (q_u == NULL)
6504                 return False;
6505
6506         memcpy(&q_u->handle, hnd, sizeof(q_u->handle));
6507
6508         q_u->change_low=change_low;
6509         q_u->change_high=change_high;
6510
6511         q_u->unknown0=0x0;
6512         q_u->unknown1=0x0;
6513
6514         q_u->info_ptr=0x0FF0ADDE;
6515
6516         q_u->info.version=2;
6517         
6518         if (info->count) {
6519                 DEBUG(10,("make_spoolss_q_reply_rrpcn: [%d] PRINTER_NOTIFY_INFO_DATA\n",
6520                         info->count));
6521                 q_u->info.version = info->version;
6522                 q_u->info.flags   = info->flags;
6523                 q_u->info.count   = info->count;
6524                 /* pointer field - be careful! */
6525                 q_u->info.data    = info->data;
6526         }
6527         else  {
6528         q_u->info.flags=PRINTER_NOTIFY_INFO_DISCARDED;
6529         q_u->info.count=0;
6530         }
6531
6532         return True;
6533 }
6534
6535 /*******************************************************************
6536  Parse a SPOOL_Q_REPLY_RRPCN structure.
6537 ********************************************************************/  
6538
6539 BOOL spoolss_io_q_reply_rrpcn(const char *desc, SPOOL_Q_REPLY_RRPCN *q_u, prs_struct *ps, int depth)
6540 {
6541         prs_debug(ps, depth, desc, "spoolss_io_q_reply_rrpcn");
6542         depth++;
6543
6544         if(!prs_align(ps))
6545                 return False;
6546
6547         if(!smb_io_pol_hnd("printer handle",&q_u->handle,ps,depth))
6548                 return False;
6549
6550         if (!prs_uint32("change_low", ps, depth, &q_u->change_low))
6551                 return False;
6552
6553         if (!prs_uint32("change_high", ps, depth, &q_u->change_high))
6554                 return False;
6555
6556         if (!prs_uint32("unknown0", ps, depth, &q_u->unknown0))
6557                 return False;
6558
6559         if (!prs_uint32("unknown1", ps, depth, &q_u->unknown1))
6560                 return False;
6561
6562         if (!prs_uint32("info_ptr", ps, depth, &q_u->info_ptr))
6563                 return False;
6564
6565         if(q_u->info_ptr!=0)
6566                 if(!smb_io_notify_info(desc, &q_u->info, ps, depth))
6567                         return False;
6568                 
6569         return True;
6570 }
6571
6572 /*******************************************************************
6573  Parse a SPOOL_R_REPLY_RRPCN structure.
6574 ********************************************************************/  
6575
6576 BOOL spoolss_io_r_reply_rrpcn(const char *desc, SPOOL_R_REPLY_RRPCN *r_u, prs_struct *ps, int depth)
6577 {               
6578         prs_debug(ps, depth, desc, "spoolss_io_r_reply_rrpcn");
6579         depth++;
6580
6581         if (!prs_align(ps))
6582                 return False;
6583
6584         if (!prs_uint32("unknown0", ps, depth, &r_u->unknown0))
6585                 return False;
6586
6587         if (!prs_werror("status", ps, depth, &r_u->status))
6588                 return False;
6589
6590         return True;            
6591 }
6592
6593 /*******************************************************************
6594  * read a structure.
6595  * called from spoolss_q_getprinterdataex (srv_spoolss.c)
6596  ********************************************************************/
6597
6598 BOOL spoolss_io_q_getprinterdataex(const char *desc, SPOOL_Q_GETPRINTERDATAEX *q_u, prs_struct *ps, int depth)
6599 {
6600         if (q_u == NULL)
6601                 return False;
6602
6603         prs_debug(ps, depth, desc, "spoolss_io_q_getprinterdataex");
6604         depth++;
6605
6606         if (!prs_align(ps))
6607                 return False;
6608         if (!smb_io_pol_hnd("printer handle",&q_u->handle,ps,depth))
6609                 return False;
6610         if (!prs_align(ps))
6611                 return False;
6612         if (!smb_io_unistr2("keyname", &q_u->keyname,True,ps,depth))
6613                 return False;
6614         if (!prs_align(ps))
6615                 return False;
6616         if (!smb_io_unistr2("valuename", &q_u->valuename,True,ps,depth))
6617                 return False;
6618         if (!prs_align(ps))
6619                 return False;
6620         if (!prs_uint32("size", ps, depth, &q_u->size))
6621                 return False;
6622
6623         return True;
6624 }
6625
6626 /*******************************************************************
6627  * write a structure.
6628  * called from spoolss_r_getprinterdataex (srv_spoolss.c)
6629  ********************************************************************/
6630
6631 BOOL spoolss_io_r_getprinterdataex(const char *desc, SPOOL_R_GETPRINTERDATAEX *r_u, prs_struct *ps, int depth)
6632 {
6633         if (r_u == NULL)
6634                 return False;
6635
6636         prs_debug(ps, depth, desc, "spoolss_io_r_getprinterdataex");
6637         depth++;
6638
6639         if (!prs_align(ps))
6640                 return False;
6641         if (!prs_uint32("type", ps, depth, &r_u->type))
6642                 return False;
6643         if (!prs_uint32("size", ps, depth, &r_u->size))
6644                 return False;
6645         
6646         if (UNMARSHALLING(ps) && r_u->size) {
6647                 r_u->data = PRS_ALLOC_MEM(ps, unsigned char, r_u->size);
6648                 if(!r_u->data)
6649                         return False;
6650         }
6651
6652         if (!prs_uint8s(False,"data", ps, depth, r_u->data, r_u->size))
6653                 return False;
6654                 
6655         if (!prs_align(ps))
6656                 return False;
6657         
6658         if (!prs_uint32("needed", ps, depth, &r_u->needed))
6659                 return False;
6660         if (!prs_werror("status", ps, depth, &r_u->status))
6661                 return False;
6662                 
6663         return True;
6664 }
6665
6666 /*******************************************************************
6667  * read a structure.
6668  ********************************************************************/  
6669
6670 BOOL spoolss_io_q_setprinterdataex(const char *desc, SPOOL_Q_SETPRINTERDATAEX *q_u, prs_struct *ps, int depth)
6671 {
6672         prs_debug(ps, depth, desc, "spoolss_io_q_setprinterdataex");
6673         depth++;
6674
6675         if(!prs_align(ps))
6676                 return False;
6677         if(!smb_io_pol_hnd("printer handle", &q_u->handle, ps, depth))
6678                 return False;
6679         if(!smb_io_unistr2("", &q_u->key, True, ps, depth))
6680                 return False;
6681
6682         if(!prs_align(ps))
6683                 return False;
6684
6685         if(!smb_io_unistr2("", &q_u->value, True, ps, depth))
6686                 return False;
6687
6688         if(!prs_align(ps))
6689                 return False;
6690
6691         if(!prs_uint32("type", ps, depth, &q_u->type))
6692                 return False;
6693
6694         if(!prs_uint32("max_len", ps, depth, &q_u->max_len))
6695                 return False;
6696
6697         switch (q_u->type)
6698         {
6699                 case 0x1:
6700                 case 0x3:
6701                 case 0x4:
6702                 case 0x7:
6703                         if (q_u->max_len) {
6704                                 if (UNMARSHALLING(ps))
6705                                         q_u->data=PRS_ALLOC_MEM(ps, uint8, q_u->max_len);
6706                                 if(q_u->data == NULL)
6707                                         return False;
6708                                 if(!prs_uint8s(False,"data", ps, depth, q_u->data, q_u->max_len))
6709                                         return False;
6710                         }
6711                         if(!prs_align(ps))
6712                                 return False;
6713                         break;
6714         }       
6715         
6716         if(!prs_uint32("real_len", ps, depth, &q_u->real_len))
6717                 return False;
6718
6719         return True;
6720 }
6721
6722 /*******************************************************************
6723  * write a structure.
6724  ********************************************************************/  
6725
6726 BOOL spoolss_io_r_setprinterdataex(const char *desc, SPOOL_R_SETPRINTERDATAEX *r_u, prs_struct *ps, int depth)
6727 {
6728         prs_debug(ps, depth, desc, "spoolss_io_r_setprinterdataex");
6729         depth++;
6730
6731         if(!prs_align(ps))
6732                 return False;
6733         if(!prs_werror("status",     ps, depth, &r_u->status))
6734                 return False;
6735
6736         return True;
6737 }
6738
6739 /*******************************************************************
6740  * read a structure.
6741  ********************************************************************/  
6742 BOOL make_spoolss_q_enumprinterkey(SPOOL_Q_ENUMPRINTERKEY *q_u, 
6743                                    POLICY_HND *hnd, const char *key, 
6744                                    uint32 size)
6745 {
6746         DEBUG(5,("make_spoolss_q_enumprinterkey\n"));
6747
6748         memcpy(&q_u->handle, hnd, sizeof(q_u->handle));
6749         init_unistr2(&q_u->key, key, UNI_STR_TERMINATE);
6750         q_u->size = size;
6751
6752         return True;
6753 }
6754
6755 /*******************************************************************
6756  * read a structure.
6757  ********************************************************************/  
6758
6759 BOOL spoolss_io_q_enumprinterkey(const char *desc, SPOOL_Q_ENUMPRINTERKEY *q_u, prs_struct *ps, int depth)
6760 {
6761         prs_debug(ps, depth, desc, "spoolss_io_q_enumprinterkey");
6762         depth++;
6763
6764         if(!prs_align(ps))
6765                 return False;
6766         if(!smb_io_pol_hnd("printer handle", &q_u->handle, ps, depth))
6767                 return False;
6768                 
6769         if(!smb_io_unistr2("", &q_u->key, True, ps, depth))
6770                 return False;
6771
6772         if(!prs_align(ps))
6773                 return False;
6774         
6775         if(!prs_uint32("size", ps, depth, &q_u->size))
6776                 return False;
6777
6778         return True;
6779 }
6780
6781 /*******************************************************************
6782  * write a structure.
6783  ********************************************************************/  
6784
6785 BOOL spoolss_io_r_enumprinterkey(const char *desc, SPOOL_R_ENUMPRINTERKEY *r_u, prs_struct *ps, int depth)
6786 {
6787         prs_debug(ps, depth, desc, "spoolss_io_r_enumprinterkey");
6788         depth++;
6789
6790         if(!prs_align(ps))
6791                 return False;
6792
6793         if (!smb_io_buffer5("", &r_u->keys, ps, depth))
6794                 return False;
6795         
6796         if(!prs_align(ps))
6797                 return False;
6798
6799         if(!prs_uint32("needed",     ps, depth, &r_u->needed))
6800                 return False;
6801
6802         if(!prs_werror("status",     ps, depth, &r_u->status))
6803                 return False;
6804
6805         return True;
6806 }
6807
6808 /*******************************************************************
6809  * read a structure.
6810  ********************************************************************/  
6811
6812 BOOL make_spoolss_q_deleteprinterkey(SPOOL_Q_DELETEPRINTERKEY *q_u, 
6813                                      POLICY_HND *hnd, char *keyname)
6814 {
6815         DEBUG(5,("make_spoolss_q_deleteprinterkey\n"));
6816
6817         memcpy(&q_u->handle, hnd, sizeof(q_u->handle));
6818         init_unistr2(&q_u->keyname, keyname, UNI_STR_TERMINATE);
6819
6820         return True;
6821 }
6822
6823 /*******************************************************************
6824  * read a structure.
6825  ********************************************************************/  
6826
6827 BOOL spoolss_io_q_deleteprinterkey(const char *desc, SPOOL_Q_DELETEPRINTERKEY *q_u, prs_struct *ps, int depth)
6828 {
6829         prs_debug(ps, depth, desc, "spoolss_io_q_deleteprinterkey");
6830         depth++;
6831
6832         if(!prs_align(ps))
6833                 return False;
6834         if(!smb_io_pol_hnd("printer handle", &q_u->handle, ps, depth))
6835                 return False;
6836                 
6837         if(!smb_io_unistr2("", &q_u->keyname, True, ps, depth))
6838                 return False;
6839
6840         return True;
6841 }
6842
6843 /*******************************************************************
6844  * write a structure.
6845  ********************************************************************/  
6846
6847 BOOL spoolss_io_r_deleteprinterkey(const char *desc, SPOOL_R_DELETEPRINTERKEY *r_u, prs_struct *ps, int depth)
6848 {
6849         prs_debug(ps, depth, desc, "spoolss_io_r_deleteprinterkey");
6850         depth++;
6851
6852         if(!prs_align(ps))
6853                 return False;
6854                 
6855         if(!prs_werror("status",     ps, depth, &r_u->status))
6856                 return False;
6857
6858         return True;
6859 }
6860
6861
6862 /*******************************************************************
6863  * read a structure.
6864  ********************************************************************/  
6865
6866 BOOL spoolss_io_q_enumprinterdataex(const char *desc, SPOOL_Q_ENUMPRINTERDATAEX *q_u, prs_struct *ps, int depth)
6867 {
6868         prs_debug(ps, depth, desc, "spoolss_io_q_enumprinterdataex");
6869         depth++;
6870
6871         if(!prs_align(ps))
6872                 return False;
6873         if(!smb_io_pol_hnd("printer handle", &q_u->handle, ps, depth))
6874                 return False;
6875                 
6876         if(!smb_io_unistr2("", &q_u->key, True, ps, depth))
6877                 return False;
6878
6879         if(!prs_align(ps))
6880                 return False;
6881         
6882         if(!prs_uint32("size", ps, depth, &q_u->size))
6883                 return False;
6884
6885         return True;
6886 }
6887
6888 /*******************************************************************
6889 ********************************************************************/  
6890
6891 static BOOL spoolss_io_printer_enum_values_ctr(const char *desc, prs_struct *ps, 
6892                                 PRINTER_ENUM_VALUES_CTR *ctr, int depth)
6893 {
6894         int     i;
6895         uint32  valuename_offset,
6896                 data_offset,
6897                 current_offset;
6898         const uint32 basic_unit = 20; /* size of static portion of enum_values */
6899         
6900         prs_debug(ps, depth, desc, "spoolss_io_printer_enum_values_ctr");
6901         depth++;        
6902         
6903         /* 
6904          * offset data begins at 20 bytes per structure * size_of_array.
6905          * Don't forget the uint32 at the beginning 
6906          * */
6907         
6908         current_offset = basic_unit * ctr->size_of_array;
6909         
6910         /* first loop to write basic enum_value information */
6911         
6912         if (UNMARSHALLING(ps)) {
6913                 ctr->values = PRS_ALLOC_MEM(ps, PRINTER_ENUM_VALUES, ctr->size_of_array);
6914                 if (!ctr->values)
6915                         return False;
6916         }
6917
6918         for (i=0; i<ctr->size_of_array; i++) {
6919                 valuename_offset = current_offset;
6920                 if (!prs_uint32("valuename_offset", ps, depth, &valuename_offset))
6921                         return False;
6922
6923                 if (!prs_uint32("value_len", ps, depth, &ctr->values[i].value_len))
6924                         return False;
6925         
6926                 if (!prs_uint32("type", ps, depth, &ctr->values[i].type))
6927                         return False;
6928         
6929                 data_offset = ctr->values[i].value_len + valuename_offset;
6930                 
6931                 if (!prs_uint32("data_offset", ps, depth, &data_offset))
6932                         return False;
6933
6934                 if (!prs_uint32("data_len", ps, depth, &ctr->values[i].data_len))
6935                         return False;
6936                         
6937                 current_offset  = data_offset + ctr->values[i].data_len - basic_unit;
6938                 /* account for 2 byte alignment */
6939                 current_offset += (current_offset % 2);
6940         }
6941
6942         /* 
6943          * loop #2 for writing the dynamically size objects; pay 
6944          * attention to 2-byte alignment here....
6945          */
6946         
6947         for (i=0; i<ctr->size_of_array; i++) {
6948         
6949                 if (!prs_unistr("valuename", ps, depth, &ctr->values[i].valuename))
6950                         return False;
6951                 
6952                 if ( ctr->values[i].data_len ) {
6953                         if ( UNMARSHALLING(ps) ) {
6954                                 ctr->values[i].data = PRS_ALLOC_MEM(ps, uint8, ctr->values[i].data_len);
6955                                 if (!ctr->values[i].data)
6956                                         return False;
6957                         }
6958                         if (!prs_uint8s(False, "data", ps, depth, ctr->values[i].data, ctr->values[i].data_len))
6959                                 return False;
6960                 }
6961                         
6962                 if ( !prs_align_uint16(ps) )
6963                         return False;
6964         }
6965
6966         return True;    
6967 }
6968
6969 /*******************************************************************
6970  * write a structure.
6971  ********************************************************************/  
6972
6973 BOOL spoolss_io_r_enumprinterdataex(const char *desc, SPOOL_R_ENUMPRINTERDATAEX *r_u, prs_struct *ps, int depth)
6974 {
6975         uint32 data_offset, end_offset;
6976         prs_debug(ps, depth, desc, "spoolss_io_r_enumprinterdataex");
6977         depth++;
6978
6979         if(!prs_align(ps))
6980                 return False;
6981
6982         if (!prs_uint32("size", ps, depth, &r_u->ctr.size))
6983                 return False;
6984
6985         data_offset = prs_offset(ps);
6986
6987         if (!prs_set_offset(ps, data_offset + r_u->ctr.size))
6988                 return False;
6989
6990         if(!prs_align(ps))
6991                 return False;
6992
6993         if(!prs_uint32("needed",     ps, depth, &r_u->needed))
6994                 return False;
6995
6996         if(!prs_uint32("returned",   ps, depth, &r_u->returned))
6997                 return False;
6998
6999         if(!prs_werror("status",     ps, depth, &r_u->status))
7000                 return False;
7001
7002         r_u->ctr.size_of_array = r_u->returned;
7003
7004         end_offset = prs_offset(ps);
7005
7006         if (!prs_set_offset(ps, data_offset))
7007                 return False;
7008
7009         if (r_u->ctr.size)
7010                 if (!spoolss_io_printer_enum_values_ctr("", ps, &r_u->ctr, depth ))
7011                         return False;
7012
7013         if (!prs_set_offset(ps, end_offset))
7014                 return False;
7015         return True;
7016 }
7017
7018 /*******************************************************************
7019  * write a structure.
7020  ********************************************************************/  
7021
7022 /* 
7023    uint32 GetPrintProcessorDirectory(
7024        [in] unistr2 *name,
7025        [in] unistr2 *environment,
7026        [in] uint32 level,
7027        [in,out] RPC_BUFFER buffer,
7028        [in] uint32 offered,
7029        [out] uint32 needed,
7030        [out] uint32 returned
7031    );
7032
7033 */
7034
7035 BOOL make_spoolss_q_getprintprocessordirectory(SPOOL_Q_GETPRINTPROCESSORDIRECTORY *q_u, const char *name, char *environment, int level, RPC_BUFFER *buffer, uint32 offered)
7036 {
7037         DEBUG(5,("make_spoolss_q_getprintprocessordirectory\n"));
7038
7039         init_unistr2(&q_u->name, name, UNI_STR_TERMINATE);
7040         init_unistr2(&q_u->environment, environment, UNI_STR_TERMINATE);
7041
7042         q_u->level = level;
7043
7044         q_u->buffer = buffer;
7045         q_u->offered = offered;
7046
7047         return True;
7048 }
7049
7050 BOOL spoolss_io_q_getprintprocessordirectory(const char *desc, SPOOL_Q_GETPRINTPROCESSORDIRECTORY *q_u, prs_struct *ps, int depth)
7051 {
7052         uint32 ptr;
7053
7054         prs_debug(ps, depth, desc, "spoolss_io_q_getprintprocessordirectory");
7055         depth++;
7056
7057         if(!prs_align(ps))
7058                 return False;   
7059
7060         if (!prs_uint32("ptr", ps, depth, &ptr)) 
7061                 return False;
7062
7063         if (ptr) {
7064                 if(!smb_io_unistr2("name", &q_u->name, True, ps, depth))
7065                         return False;
7066         }
7067
7068         if (!prs_align(ps))
7069                 return False;
7070
7071         if (!prs_uint32("ptr", ps, depth, &ptr))
7072                 return False;
7073
7074         if (ptr) {
7075                 if(!smb_io_unistr2("environment", &q_u->environment, True, 
7076                                    ps, depth))
7077                         return False;
7078         }
7079
7080         if (!prs_align(ps))
7081                 return False;
7082
7083         if(!prs_uint32("level",   ps, depth, &q_u->level))
7084                 return False;
7085
7086         if(!prs_rpcbuffer_p("", ps, depth, &q_u->buffer))
7087                 return False;
7088         
7089         if(!prs_align(ps))
7090                 return False;
7091
7092         if(!prs_uint32("offered", ps, depth, &q_u->offered))
7093                 return False;
7094
7095         return True;
7096 }
7097
7098 /*******************************************************************
7099  * write a structure.
7100  ********************************************************************/  
7101
7102 BOOL spoolss_io_r_getprintprocessordirectory(const char *desc, SPOOL_R_GETPRINTPROCESSORDIRECTORY *r_u, prs_struct *ps, int depth)
7103 {
7104         prs_debug(ps, depth, desc, "spoolss_io_r_getprintprocessordirectory");
7105         depth++;
7106
7107         if(!prs_align(ps))
7108                 return False;
7109
7110         if(!prs_rpcbuffer_p("", ps, depth, &r_u->buffer))
7111                 return False;
7112         
7113         if(!prs_align(ps))
7114                 return False;
7115
7116         if(!prs_uint32("needed",     ps, depth, &r_u->needed))
7117                 return False;
7118                 
7119         if(!prs_werror("status",     ps, depth, &r_u->status))
7120                 return False;
7121
7122         return True;
7123 }
7124
7125 BOOL smb_io_printprocessordirectory_1(const char *desc, RPC_BUFFER *buffer, PRINTPROCESSOR_DIRECTORY_1 *info, int depth)
7126 {
7127         prs_struct *ps=&buffer->prs;
7128
7129         prs_debug(ps, depth, desc, "smb_io_printprocessordirectory_1");
7130         depth++;
7131
7132         buffer->struct_start=prs_offset(ps);
7133
7134         if (!smb_io_unistr(desc, &info->name, ps, depth))
7135                 return False;
7136
7137         return True;
7138 }
7139
7140 /*******************************************************************
7141  * init a structure.
7142  ********************************************************************/
7143
7144 BOOL make_spoolss_q_addform(SPOOL_Q_ADDFORM *q_u, POLICY_HND *handle, 
7145                             int level, FORM *form)
7146 {
7147         memcpy(&q_u->handle, handle, sizeof(POLICY_HND));
7148         q_u->level = level;
7149         q_u->level2 = level;
7150         memcpy(&q_u->form, form, sizeof(FORM));
7151
7152         return True;
7153 }
7154
7155 /*******************************************************************
7156  * init a structure.
7157  ********************************************************************/
7158
7159 BOOL make_spoolss_q_setform(SPOOL_Q_SETFORM *q_u, POLICY_HND *handle, 
7160                             int level, const char *form_name, FORM *form)
7161 {
7162         memcpy(&q_u->handle, handle, sizeof(POLICY_HND));
7163         q_u->level = level;
7164         q_u->level2 = level;
7165         memcpy(&q_u->form, form, sizeof(FORM));
7166         init_unistr2(&q_u->name, form_name, UNI_STR_TERMINATE);
7167
7168         return True;
7169 }
7170
7171 /*******************************************************************
7172  * init a structure.
7173  ********************************************************************/
7174
7175 BOOL make_spoolss_q_deleteform(SPOOL_Q_DELETEFORM *q_u, POLICY_HND *handle, 
7176                                const char *form)
7177 {
7178         memcpy(&q_u->handle, handle, sizeof(POLICY_HND));
7179         init_unistr2(&q_u->name, form, UNI_STR_TERMINATE);
7180         return True;
7181 }
7182
7183 /*******************************************************************
7184  * init a structure.
7185  ********************************************************************/
7186
7187 BOOL make_spoolss_q_getform(SPOOL_Q_GETFORM *q_u, POLICY_HND *handle, 
7188                             const char *formname, uint32 level, 
7189                             RPC_BUFFER *buffer, uint32 offered)
7190 {
7191         memcpy(&q_u->handle, handle, sizeof(POLICY_HND));
7192         q_u->level = level;
7193         init_unistr2(&q_u->formname, formname, UNI_STR_TERMINATE);
7194         q_u->buffer=buffer;
7195         q_u->offered=offered;
7196
7197         return True;
7198 }
7199
7200 /*******************************************************************
7201  * init a structure.
7202  ********************************************************************/
7203
7204 BOOL make_spoolss_q_enumforms(SPOOL_Q_ENUMFORMS *q_u, POLICY_HND *handle, 
7205                               uint32 level, RPC_BUFFER *buffer,
7206                               uint32 offered)
7207 {
7208         memcpy(&q_u->handle, handle, sizeof(POLICY_HND));
7209         q_u->level = level;
7210         q_u->buffer=buffer;
7211         q_u->offered=offered;
7212
7213         return True;
7214 }
7215
7216 /*******************************************************************
7217  * init a structure.
7218  ********************************************************************/
7219
7220 BOOL make_spoolss_q_setjob(SPOOL_Q_SETJOB *q_u, POLICY_HND *handle, 
7221                            uint32 jobid, uint32 level, uint32 command)
7222 {
7223         memcpy(&q_u->handle, handle, sizeof(POLICY_HND));
7224         q_u->jobid = jobid;
7225         q_u->level = level;
7226
7227         /* Hmm - the SPOOL_Q_SETJOB structure has a JOB_INFO ctr in it but
7228            the server side code has it marked as unused. */
7229
7230         q_u->command = command;
7231
7232         return True;
7233 }
7234
7235 /*******************************************************************
7236  * init a structure.
7237  ********************************************************************/
7238
7239 BOOL make_spoolss_q_getjob(SPOOL_Q_GETJOB *q_u, POLICY_HND *handle, 
7240                            uint32 jobid, uint32 level, RPC_BUFFER *buffer,
7241                            uint32 offered)
7242 {
7243         memcpy(&q_u->handle, handle, sizeof(POLICY_HND));
7244         q_u->jobid = jobid;
7245         q_u->level = level;
7246         q_u->buffer = buffer;
7247         q_u->offered = offered;
7248
7249         return True;
7250 }
7251
7252 /*******************************************************************
7253  * init a structure.
7254  ********************************************************************/
7255
7256 BOOL make_spoolss_q_startpageprinter(SPOOL_Q_STARTPAGEPRINTER *q_u, 
7257                                      POLICY_HND *handle)
7258 {
7259         memcpy(&q_u->handle, handle, sizeof(POLICY_HND));
7260
7261         return True;
7262 }
7263
7264 /*******************************************************************
7265  * init a structure.
7266  ********************************************************************/
7267
7268 BOOL make_spoolss_q_endpageprinter(SPOOL_Q_ENDPAGEPRINTER *q_u, 
7269                                    POLICY_HND *handle)
7270 {
7271         memcpy(&q_u->handle, handle, sizeof(POLICY_HND));
7272
7273         return True;
7274 }
7275
7276 /*******************************************************************
7277  * init a structure.
7278  ********************************************************************/
7279
7280 BOOL make_spoolss_q_startdocprinter(SPOOL_Q_STARTDOCPRINTER *q_u, 
7281                                     POLICY_HND *handle, uint32 level,
7282                                     char *docname, char *outputfile,
7283                                     char *datatype)
7284 {
7285         DOC_INFO_CONTAINER *ctr = &q_u->doc_info_container;
7286
7287         memcpy(&q_u->handle, handle, sizeof(POLICY_HND));
7288
7289         ctr->level = level;
7290
7291         switch (level) {
7292         case 1:
7293                 ctr->docinfo.switch_value = level;
7294
7295                 ctr->docinfo.doc_info_1.p_docname = docname ? 1 : 0;
7296                 ctr->docinfo.doc_info_1.p_outputfile = outputfile ? 1 : 0;
7297                 ctr->docinfo.doc_info_1.p_datatype = datatype ? 1 : 0;
7298
7299                 init_unistr2(&ctr->docinfo.doc_info_1.docname, docname, UNI_STR_TERMINATE);
7300                 init_unistr2(&ctr->docinfo.doc_info_1.outputfile, outputfile, UNI_STR_TERMINATE);
7301                 init_unistr2(&ctr->docinfo.doc_info_1.datatype, datatype, UNI_STR_TERMINATE);
7302
7303                 break;
7304         case 2:
7305                 /* DOC_INFO_2 is only used by Windows 9x and since it
7306                    doesn't do printing over RPC we don't have to worry
7307                    about it. */
7308         default:
7309                 DEBUG(3, ("unsupported info level %d\n", level));
7310                 return False;
7311         }
7312
7313         return True;
7314 }
7315
7316 /*******************************************************************
7317  * init a structure.
7318  ********************************************************************/
7319
7320 BOOL make_spoolss_q_enddocprinter(SPOOL_Q_ENDDOCPRINTER *q_u, 
7321                                   POLICY_HND *handle)
7322 {
7323         memcpy(&q_u->handle, handle, sizeof(POLICY_HND));
7324
7325         return True;
7326 }
7327
7328 /*******************************************************************
7329  * init a structure.
7330  ********************************************************************/
7331
7332 BOOL make_spoolss_q_writeprinter(SPOOL_Q_WRITEPRINTER *q_u, 
7333                                  POLICY_HND *handle, uint32 data_size,
7334                                  char *data)
7335 {
7336         memcpy(&q_u->handle, handle, sizeof(POLICY_HND));
7337         q_u->buffer_size = q_u->buffer_size2 = data_size;
7338         q_u->buffer = (unsigned char *)data;
7339         return True;
7340 }
7341
7342 /*******************************************************************
7343  * init a structure.
7344  ********************************************************************/
7345
7346 BOOL make_spoolss_q_deleteprinterdata(SPOOL_Q_DELETEPRINTERDATA *q_u, 
7347                                  POLICY_HND *handle, char *valuename)
7348 {
7349         memcpy(&q_u->handle, handle, sizeof(POLICY_HND));
7350         init_unistr2(&q_u->valuename, valuename, UNI_STR_TERMINATE);
7351
7352         return True;
7353 }
7354
7355 /*******************************************************************
7356  * init a structure.
7357  ********************************************************************/
7358
7359 BOOL make_spoolss_q_deleteprinterdataex(SPOOL_Q_DELETEPRINTERDATAEX *q_u, 
7360                                         POLICY_HND *handle, char *key,
7361                                         char *value)
7362 {
7363         memcpy(&q_u->handle, handle, sizeof(POLICY_HND));
7364         init_unistr2(&q_u->valuename, value, UNI_STR_TERMINATE);
7365         init_unistr2(&q_u->keyname, key, UNI_STR_TERMINATE);
7366
7367         return True;
7368 }
7369
7370 /*******************************************************************
7371  * init a structure.
7372  ********************************************************************/
7373
7374 BOOL make_spoolss_q_rffpcnex(SPOOL_Q_RFFPCNEX *q_u, POLICY_HND *handle,
7375                              uint32 flags, uint32 options, const char *localmachine,
7376                              uint32 printerlocal, SPOOL_NOTIFY_OPTION *option)
7377 {
7378         memcpy(&q_u->handle, handle, sizeof(POLICY_HND));
7379
7380         q_u->flags = flags;
7381         q_u->options = options;
7382
7383         q_u->localmachine_ptr = 1;
7384
7385         init_unistr2(&q_u->localmachine, localmachine, UNI_STR_TERMINATE);
7386
7387         q_u->printerlocal = printerlocal;
7388
7389         if (option)
7390                 q_u->option_ptr = 1;
7391
7392         q_u->option = option;
7393
7394         return True;
7395 }