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