alignment issues in EnumPrinterKey()
[Samba.git] / source / rpc_parse / parse_spoolss.c
blob7e52c6d3636fc665eaf730a26132d64802652b51
1 /*
2 * Unix SMB/Netbios implementation.
3 * Version 1.9.
4 * RPC Pipe client / server routines
5 * Copyright (C) Andrew Tridgell 1992-2000,
6 * Copyright (C) Luke Kenneth Casson Leighton 1996-2000,
7 * Copyright (C) Jean François Micouleau 1998-2000.
8 * Copyright (C) Gerald Carter 2000
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation; either version 2 of the License, or
13 * (at your option) any later version.
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
20 * You should have received a copy of the GNU General Public License
21 * along with this program; if not, write to the Free Software
22 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
25 #include "includes.h"
27 /*******************************************************************
28 return the length of a UNISTR string.
29 ********************************************************************/
31 static uint32 str_len_uni(UNISTR *source)
33 uint32 i=0;
35 if (!source->buffer)
36 return 0;
38 while (source->buffer[i])
39 i++;
41 return i;
44 /*******************************************************************
45 This should be moved in a more generic lib.
46 ********************************************************************/
48 static BOOL spoolss_io_system_time(char *desc, prs_struct *ps, int depth, SYSTEMTIME *systime)
50 if(!prs_uint16("year", ps, depth, &(systime->year)))
51 return False;
52 if(!prs_uint16("month", ps, depth, &(systime->month)))
53 return False;
54 if(!prs_uint16("dayofweek", ps, depth, &(systime->dayofweek)))
55 return False;
56 if(!prs_uint16("day", ps, depth, &(systime->day)))
57 return False;
58 if(!prs_uint16("hour", ps, depth, &(systime->hour)))
59 return False;
60 if(!prs_uint16("minute", ps, depth, &(systime->minute)))
61 return False;
62 if(!prs_uint16("second", ps, depth, &(systime->second)))
63 return False;
64 if(!prs_uint16("milliseconds", ps, depth, &(systime->milliseconds)))
65 return False;
67 return True;
70 /*******************************************************************
71 ********************************************************************/
73 BOOL make_systemtime(SYSTEMTIME *systime, struct tm *unixtime)
75 systime->year=unixtime->tm_year+1900;
76 systime->month=unixtime->tm_mon+1;
77 systime->dayofweek=unixtime->tm_wday;
78 systime->day=unixtime->tm_mday;
79 systime->hour=unixtime->tm_hour;
80 systime->minute=unixtime->tm_min;
81 systime->second=unixtime->tm_sec;
82 systime->milliseconds=0;
84 return True;
87 /*******************************************************************
88 reads or writes an DOC_INFO structure.
89 ********************************************************************/
91 static BOOL smb_io_doc_info_1(char *desc, DOC_INFO_1 *info_1, prs_struct *ps, int depth)
93 if (info_1 == NULL) return False;
95 prs_debug(ps, depth, desc, "smb_io_doc_info_1");
96 depth++;
98 if(!prs_align(ps))
99 return False;
101 if(!prs_uint32("p_docname", ps, depth, &info_1->p_docname))
102 return False;
103 if(!prs_uint32("p_outputfile", ps, depth, &info_1->p_outputfile))
104 return False;
105 if(!prs_uint32("p_datatype", ps, depth, &info_1->p_datatype))
106 return False;
108 if(!smb_io_unistr2("", &info_1->docname, info_1->p_docname, ps, depth))
109 return False;
110 if(!smb_io_unistr2("", &info_1->outputfile, info_1->p_outputfile, ps, depth))
111 return False;
112 if(!smb_io_unistr2("", &info_1->datatype, info_1->p_datatype, ps, depth))
113 return False;
115 return True;
118 /*******************************************************************
119 reads or writes an DOC_INFO structure.
120 ********************************************************************/
122 static BOOL smb_io_doc_info(char *desc, DOC_INFO *info, prs_struct *ps, int depth)
124 uint32 useless_ptr=0;
126 if (info == NULL) return False;
128 prs_debug(ps, depth, desc, "smb_io_doc_info");
129 depth++;
131 if(!prs_align(ps))
132 return False;
134 if(!prs_uint32("switch_value", ps, depth, &info->switch_value))
135 return False;
137 if(!prs_uint32("doc_info_X ptr", ps, depth, &useless_ptr))
138 return False;
140 switch (info->switch_value)
142 case 1:
143 if(!smb_io_doc_info_1("",&info->doc_info_1, ps, depth))
144 return False;
145 break;
146 case 2:
148 this is just a placeholder
150 MSDN July 1998 says doc_info_2 is only on
151 Windows 95, and as Win95 doesn't do RPC to print
152 this case is nearly impossible
154 Maybe one day with Windows for dishwasher 2037 ...
157 /* smb_io_doc_info_2("",&info->doc_info_2, ps, depth); */
158 break;
159 default:
160 DEBUG(0,("Something is obviously wrong somewhere !\n"));
161 break;
164 return True;
167 /*******************************************************************
168 reads or writes an DOC_INFO_CONTAINER structure.
169 ********************************************************************/
171 static BOOL smb_io_doc_info_container(char *desc, DOC_INFO_CONTAINER *cont, prs_struct *ps, int depth)
173 if (cont == NULL) return False;
175 prs_debug(ps, depth, desc, "smb_io_doc_info_container");
176 depth++;
178 if(!prs_align(ps))
179 return False;
181 if(!prs_uint32("level", ps, depth, &cont->level))
182 return False;
184 if(!smb_io_doc_info("",&cont->docinfo, ps, depth))
185 return False;
187 return True;
190 /*******************************************************************
191 reads or writes an NOTIFY OPTION TYPE structure.
192 ********************************************************************/
194 static BOOL smb_io_notify_option_type(char *desc, SPOOL_NOTIFY_OPTION_TYPE *type, prs_struct *ps, int depth)
196 prs_debug(ps, depth, desc, "smb_io_notify_option_type");
197 depth++;
199 if (!prs_align(ps))
200 return False;
202 if(!prs_uint16("type", ps, depth, &type->type))
203 return False;
204 if(!prs_uint16("reserved0", ps, depth, &type->reserved0))
205 return False;
206 if(!prs_uint32("reserved1", ps, depth, &type->reserved1))
207 return False;
208 if(!prs_uint32("reserved2", ps, depth, &type->reserved2))
209 return False;
210 if(!prs_uint32("count", ps, depth, &type->count))
211 return False;
212 if(!prs_uint32("fields_ptr", ps, depth, &type->fields_ptr))
213 return False;
215 return True;
218 /*******************************************************************
219 reads or writes an NOTIFY OPTION TYPE DATA.
220 ********************************************************************/
222 static BOOL smb_io_notify_option_type_data(char *desc, SPOOL_NOTIFY_OPTION_TYPE *type, prs_struct *ps, int depth)
224 int i;
226 prs_debug(ps, depth, desc, "smb_io_notify_option_type_data");
227 depth++;
229 /* if there are no fields just return */
230 if (type->fields_ptr==0)
231 return True;
233 if(!prs_align(ps))
234 return False;
236 if(!prs_uint32("count2", ps, depth, &type->count2))
237 return False;
239 if (type->count2 != type->count)
240 DEBUG(4,("What a mess, count was %x now is %x !\n", type->count, type->count2));
242 /* parse the option type data */
243 for(i=0;i<type->count2;i++)
244 if(!prs_uint16("fields",ps,depth,&type->fields[i]))
245 return False;
246 return True;
249 /*******************************************************************
250 reads or writes an NOTIFY OPTION structure.
251 ********************************************************************/
253 static BOOL smb_io_notify_option_type_ctr(char *desc, SPOOL_NOTIFY_OPTION_TYPE_CTR *ctr , prs_struct *ps, int depth)
255 int i;
257 prs_debug(ps, depth, desc, "smb_io_notify_option_type_ctr");
258 depth++;
260 if(!prs_uint32("count", ps, depth, &ctr->count))
261 return False;
263 /* reading */
264 if (UNMARSHALLING(ps))
265 if((ctr->type=(SPOOL_NOTIFY_OPTION_TYPE *)prs_alloc_mem(ps,ctr->count*sizeof(SPOOL_NOTIFY_OPTION_TYPE))) == NULL)
266 return False;
268 /* the option type struct */
269 for(i=0;i<ctr->count;i++)
270 if(!smb_io_notify_option_type("", &ctr->type[i] , ps, depth))
271 return False;
273 /* the type associated with the option type struct */
274 for(i=0;i<ctr->count;i++)
275 if(!smb_io_notify_option_type_data("", &ctr->type[i] , ps, depth))
276 return False;
278 return True;
281 /*******************************************************************
282 reads or writes an NOTIFY OPTION structure.
283 ********************************************************************/
285 static BOOL smb_io_notify_option(char *desc, SPOOL_NOTIFY_OPTION *option, prs_struct *ps, int depth)
287 prs_debug(ps, depth, desc, "smb_io_notify_option");
288 depth++;
290 if(!prs_uint32("version", ps, depth, &option->version))
291 return False;
292 if(!prs_uint32("flags", ps, depth, &option->flags))
293 return False;
294 if(!prs_uint32("count", ps, depth, &option->count))
295 return False;
296 if(!prs_uint32("option_type_ptr", ps, depth, &option->option_type_ptr))
297 return False;
299 /* marshalling or unmarshalling, that would work */
300 if (option->option_type_ptr!=0) {
301 if(!smb_io_notify_option_type_ctr("", &option->ctr ,ps, depth))
302 return False;
304 else {
305 option->ctr.type=NULL;
306 option->ctr.count=0;
309 return True;
312 /*******************************************************************
313 reads or writes an NOTIFY INFO DATA structure.
314 ********************************************************************/
316 static BOOL smb_io_notify_info_data(char *desc,SPOOL_NOTIFY_INFO_DATA *data, prs_struct *ps, int depth)
318 uint32 useless_ptr=0xADDE0FF0;
320 uint32 how_many_words;
321 BOOL isvalue;
322 uint32 x;
324 prs_debug(ps, depth, desc, "smb_io_notify_info_data");
325 depth++;
327 how_many_words=data->size;
328 if (how_many_words==POINTER) {
329 how_many_words=TWO_VALUE;
332 isvalue=data->enc_type;
334 if(!prs_align(ps))
335 return False;
336 if(!prs_uint16("type", ps, depth, &data->type))
337 return False;
338 if(!prs_uint16("field", ps, depth, &data->field))
339 return False;
340 /*prs_align(ps);*/
342 if(!prs_uint32("how many words", ps, depth, &how_many_words))
343 return False;
344 if(!prs_uint32("id", ps, depth, &data->id))
345 return False;
346 if(!prs_uint32("how many words", ps, depth, &how_many_words))
347 return False;
350 /*prs_align(ps);*/
352 if (isvalue==True) {
353 if(!prs_uint32("value[0]", ps, depth, &data->notify_data.value[0]))
354 return False;
355 if(!prs_uint32("value[1]", ps, depth, &data->notify_data.value[1]))
356 return False;
357 /*prs_align(ps);*/
358 } else {
359 /* it's a string */
360 /* length in ascii including \0 */
361 x=2*(data->notify_data.data.length+1);
362 if(!prs_uint32("string length", ps, depth, &x ))
363 return False;
364 if(!prs_uint32("pointer", ps, depth, &useless_ptr))
365 return False;
366 /*prs_align(ps);*/
369 return True;
372 /*******************************************************************
373 reads or writes an NOTIFY INFO DATA structure.
374 ********************************************************************/
376 BOOL smb_io_notify_info_data_strings(char *desc,SPOOL_NOTIFY_INFO_DATA *data,
377 prs_struct *ps, int depth)
379 uint32 x;
380 BOOL isvalue;
382 prs_debug(ps, depth, desc, "smb_io_notify_info_data_strings");
383 depth++;
385 if(!prs_align(ps))
386 return False;
388 isvalue=data->enc_type;
390 if (isvalue==False) {
391 /* length of string in unicode include \0 */
392 x=data->notify_data.data.length+1;
393 if(!prs_uint32("string length", ps, depth, &x ))
394 return False;
395 if (MARSHALLING(ps)) {
396 /* These are already in little endian format. Don't byte swap. */
397 if (x == 1) {
399 /* No memory allocated for this string
400 therefore following the data.string
401 pointer is a bad idea. Use a pointer to
402 the uint32 length union member to
403 provide a source for a unicode NULL */
405 if(!prs_uint8s(True,"string",ps,depth, (uint8 *)&data->notify_data.data.length,x*2))
406 return False;
407 } else {
408 if(!prs_uint16uni(True,"string",ps,depth,data->notify_data.data.string,x))
409 return False;
411 } else {
413 /* Tallocate memory for string */
415 data->notify_data.data.string = (uint16 *)prs_alloc_mem(ps, x * 2);
416 if (!data->notify_data.data.string)
417 return False;
419 if(!prs_uint16uni(True,"string",ps,depth,data->notify_data.data.string,x))
420 return False;
423 if(!prs_align(ps))
424 return False;
426 return True;
429 /*******************************************************************
430 reads or writes an NOTIFY INFO structure.
431 ********************************************************************/
433 static BOOL smb_io_notify_info(char *desc, SPOOL_NOTIFY_INFO *info, prs_struct *ps, int depth)
435 int i;
437 prs_debug(ps, depth, desc, "smb_io_notify_info");
438 depth++;
440 if(!prs_align(ps))
441 return False;
443 if(!prs_uint32("count", ps, depth, &info->count))
444 return False;
445 if(!prs_uint32("version", ps, depth, &info->version))
446 return False;
447 if(!prs_uint32("flags", ps, depth, &info->flags))
448 return False;
449 if(!prs_uint32("count", ps, depth, &info->count))
450 return False;
452 for (i=0;i<info->count;i++) {
453 if(!smb_io_notify_info_data(desc, &info->data[i], ps, depth))
454 return False;
457 /* now do the strings at the end of the stream */
458 for (i=0;i<info->count;i++) {
459 if(!smb_io_notify_info_data_strings(desc, &info->data[i], ps, depth))
460 return False;
463 return True;
466 /*******************************************************************
467 ********************************************************************/
469 static BOOL spool_io_user_level_1(char *desc, SPOOL_USER_1 *q_u, prs_struct *ps, int depth)
471 prs_debug(ps, depth, desc, "");
472 depth++;
474 /* reading */
475 if (UNMARSHALLING(ps))
476 ZERO_STRUCTP(q_u);
478 if (!prs_align(ps))
479 return False;
480 if (!prs_uint32("size", ps, depth, &q_u->size))
481 return False;
482 if (!prs_uint32("client_name_ptr", ps, depth, &q_u->client_name_ptr))
483 return False;
484 if (!prs_uint32("user_name_ptr", ps, depth, &q_u->user_name_ptr))
485 return False;
486 if (!prs_uint32("build", ps, depth, &q_u->build))
487 return False;
488 if (!prs_uint32("major", ps, depth, &q_u->major))
489 return False;
490 if (!prs_uint32("minor", ps, depth, &q_u->minor))
491 return False;
492 if (!prs_uint32("processor", ps, depth, &q_u->processor))
493 return False;
495 if (!smb_io_unistr2("", &q_u->client_name, q_u->client_name_ptr, ps, depth))
496 return False;
497 if (!prs_align(ps))
498 return False;
499 if (!smb_io_unistr2("", &q_u->user_name, q_u->user_name_ptr, ps, depth))
500 return False;
502 return True;
505 /*******************************************************************
506 ********************************************************************/
508 static BOOL spool_io_user_level(char *desc, SPOOL_USER_CTR *q_u, prs_struct *ps, int depth)
510 if (q_u==NULL)
511 return False;
513 prs_debug(ps, depth, desc, "spool_io_user_level");
514 depth++;
516 if (!prs_align(ps))
517 return False;
518 if (!prs_uint32("level", ps, depth, &q_u->level))
519 return False;
520 if (!prs_uint32("ptr", ps, depth, &q_u->ptr))
521 return False;
523 switch (q_u->level) {
524 case 1:
525 if (!spool_io_user_level_1("", &q_u->user1, ps, depth))
526 return False;
527 break;
528 default:
529 return False;
532 return True;
535 /*******************************************************************
536 * read or write a DEVICEMODE struct.
537 * on reading allocate memory for the private member
538 ********************************************************************/
540 BOOL spoolss_io_devmode(char *desc, prs_struct *ps, int depth, DEVICEMODE *devmode)
542 prs_debug(ps, depth, desc, "spoolss_io_devmode");
543 depth++;
545 if (UNMARSHALLING(ps)) {
546 devmode->devicename.buffer = (uint16 *)prs_alloc_mem(ps, 32 * sizeof(uint16) );
547 if (devmode->devicename.buffer == NULL)
548 return False;
551 if (!prs_uint16uni(True,"devicename", ps, depth, devmode->devicename.buffer, 32))
552 return False;
553 if (!prs_uint16("specversion", ps, depth, &devmode->specversion))
554 return False;
555 if (!prs_uint16("driverversion", ps, depth, &devmode->driverversion))
556 return False;
557 if (!prs_uint16("size", ps, depth, &devmode->size))
558 return False;
559 if (!prs_uint16("driverextra", ps, depth, &devmode->driverextra))
560 return False;
561 if (!prs_uint32("fields", ps, depth, &devmode->fields))
562 return False;
563 if (!prs_uint16("orientation", ps, depth, &devmode->orientation))
564 return False;
565 if (!prs_uint16("papersize", ps, depth, &devmode->papersize))
566 return False;
567 if (!prs_uint16("paperlength", ps, depth, &devmode->paperlength))
568 return False;
569 if (!prs_uint16("paperwidth", ps, depth, &devmode->paperwidth))
570 return False;
571 if (!prs_uint16("scale", ps, depth, &devmode->scale))
572 return False;
573 if (!prs_uint16("copies", ps, depth, &devmode->copies))
574 return False;
575 if (!prs_uint16("defaultsource", ps, depth, &devmode->defaultsource))
576 return False;
577 if (!prs_uint16("printquality", ps, depth, &devmode->printquality))
578 return False;
579 if (!prs_uint16("color", ps, depth, &devmode->color))
580 return False;
581 if (!prs_uint16("duplex", ps, depth, &devmode->duplex))
582 return False;
583 if (!prs_uint16("yresolution", ps, depth, &devmode->yresolution))
584 return False;
585 if (!prs_uint16("ttoption", ps, depth, &devmode->ttoption))
586 return False;
587 if (!prs_uint16("collate", ps, depth, &devmode->collate))
588 return False;
590 if (UNMARSHALLING(ps)) {
591 devmode->formname.buffer = (uint16 *)prs_alloc_mem(ps, 32 * sizeof(uint16) );
592 if (devmode->formname.buffer == NULL)
593 return False;
596 if (!prs_uint16uni(True, "formname", ps, depth, devmode->formname.buffer, 32))
597 return False;
598 if (!prs_uint16("logpixels", ps, depth, &devmode->logpixels))
599 return False;
600 if (!prs_uint32("bitsperpel", ps, depth, &devmode->bitsperpel))
601 return False;
602 if (!prs_uint32("pelswidth", ps, depth, &devmode->pelswidth))
603 return False;
604 if (!prs_uint32("pelsheight", ps, depth, &devmode->pelsheight))
605 return False;
606 if (!prs_uint32("displayflags", ps, depth, &devmode->displayflags))
607 return False;
608 if (!prs_uint32("displayfrequency", ps, depth, &devmode->displayfrequency))
609 return False;
610 if (!prs_uint32("icmmethod", ps, depth, &devmode->icmmethod))
611 return False;
612 if (!prs_uint32("icmintent", ps, depth, &devmode->icmintent))
613 return False;
614 if (!prs_uint32("mediatype", ps, depth, &devmode->mediatype))
615 return False;
616 if (!prs_uint32("dithertype", ps, depth, &devmode->dithertype))
617 return False;
618 if (!prs_uint32("reserved1", ps, depth, &devmode->reserved1))
619 return False;
620 if (!prs_uint32("reserved2", ps, depth, &devmode->reserved2))
621 return False;
622 if (!prs_uint32("panningwidth", ps, depth, &devmode->panningwidth))
623 return False;
624 if (!prs_uint32("panningheight", ps, depth, &devmode->panningheight))
625 return False;
627 if (devmode->driverextra!=0) {
628 if (UNMARSHALLING(ps)) {
629 devmode->private=(uint8 *)prs_alloc_mem(ps, devmode->driverextra*sizeof(uint8));
630 if(devmode->private == NULL)
631 return False;
632 DEBUG(7,("spoolss_io_devmode: allocated memory [%d] for private\n",devmode->driverextra));
635 DEBUG(7,("spoolss_io_devmode: parsing [%d] bytes of private\n",devmode->driverextra));
636 if (!prs_uint8s(False, "private", ps, depth,
637 devmode->private, devmode->driverextra))
638 return False;
641 return True;
644 /*******************************************************************
645 Read or write a DEVICEMODE container
646 ********************************************************************/
648 static BOOL spoolss_io_devmode_cont(char *desc, DEVMODE_CTR *dm_c, prs_struct *ps, int depth)
650 if (dm_c==NULL)
651 return False;
653 prs_debug(ps, depth, desc, "spoolss_io_devmode_cont");
654 depth++;
656 if(!prs_align(ps))
657 return False;
659 if (!prs_uint32("size", ps, depth, &dm_c->size))
660 return False;
662 if (!prs_uint32("devmode_ptr", ps, depth, &dm_c->devmode_ptr))
663 return False;
665 if (dm_c->size==0 || dm_c->devmode_ptr==0) {
666 if (UNMARSHALLING(ps))
667 /* if while reading there is no DEVMODE ... */
668 dm_c->devmode=NULL;
669 return True;
672 /* so we have a DEVICEMODE to follow */
673 if (UNMARSHALLING(ps)) {
674 DEBUG(9,("Allocating memory for spoolss_io_devmode\n"));
675 dm_c->devmode=(DEVICEMODE *)prs_alloc_mem(ps,sizeof(DEVICEMODE));
676 if(dm_c->devmode == NULL)
677 return False;
680 /* this is bad code, shouldn't be there */
681 if (!prs_uint32("size", ps, depth, &dm_c->size))
682 return False;
684 if (!spoolss_io_devmode(desc, ps, depth, dm_c->devmode))
685 return False;
687 return True;
690 /*******************************************************************
691 ********************************************************************/
693 static BOOL spoolss_io_printer_default(char *desc, PRINTER_DEFAULT *pd, prs_struct *ps, int depth)
695 if (pd==NULL)
696 return False;
698 prs_debug(ps, depth, desc, "spoolss_io_printer_default");
699 depth++;
701 if (!prs_uint32("datatype_ptr", ps, depth, &pd->datatype_ptr))
702 return False;
704 if (!smb_io_unistr2("datatype", &pd->datatype, pd->datatype_ptr, ps,depth))
705 return False;
707 if (!prs_align(ps))
708 return False;
710 if (!spoolss_io_devmode_cont("", &pd->devmode_cont, ps, depth))
711 return False;
713 if (!prs_uint32("access_required", ps, depth, &pd->access_required))
714 return False;
716 return True;
719 /*******************************************************************
720 * init a structure.
721 ********************************************************************/
723 BOOL make_spoolss_q_open_printer_ex(SPOOL_Q_OPEN_PRINTER_EX *q_u,
724 const fstring printername,
725 const fstring datatype,
726 uint32 access_required,
727 const fstring clientname,
728 const fstring user_name)
730 DEBUG(5,("make_spoolss_q_open_printer_ex\n"));
731 q_u->printername_ptr = (printername!=NULL)?1:0;
732 init_unistr2(&q_u->printername, printername, strlen(printername)+1);
734 q_u->printer_default.datatype_ptr = 0;
736 q_u->printer_default.datatype_ptr = (datatype!=NULL)?1:0;
737 init_unistr2(&q_u->printer_default.datatype, datatype, strlen(datatype));
739 q_u->printer_default.devmode_cont.size=0;
740 q_u->printer_default.devmode_cont.devmode_ptr=0;
741 q_u->printer_default.devmode_cont.devmode=NULL;
742 q_u->printer_default.access_required=access_required;
743 q_u->user_switch=1;
744 q_u->user_ctr.level=1;
745 q_u->user_ctr.ptr=1;
746 q_u->user_ctr.user1.size=strlen(clientname)+strlen(user_name)+10;
747 q_u->user_ctr.user1.client_name_ptr = (clientname!=NULL)?1:0;
748 q_u->user_ctr.user1.user_name_ptr = (user_name!=NULL)?1:0;
749 q_u->user_ctr.user1.build=1381;
750 q_u->user_ctr.user1.major=2;
751 q_u->user_ctr.user1.minor=0;
752 q_u->user_ctr.user1.processor=0;
753 init_unistr2(&q_u->user_ctr.user1.client_name, clientname, strlen(clientname)+1);
754 init_unistr2(&q_u->user_ctr.user1.user_name, user_name, strlen(user_name)+1);
756 return True;
759 /*******************************************************************
760 * init a structure.
761 ********************************************************************/
762 BOOL make_spoolss_q_addprinterex(
763 TALLOC_CTX *mem_ctx,
764 SPOOL_Q_ADDPRINTEREX *q_u,
765 const char *srv_name,
766 const char* clientname,
767 const char* user_name,
768 uint32 level,
769 PRINTER_INFO_CTR *ctr)
771 DEBUG(5,("make_spoolss_q_addprinterex\n"));
773 if (!ctr) return False;
775 q_u->server_name_ptr = (srv_name!=NULL)?1:0;
776 init_unistr2(&q_u->server_name, srv_name, strlen(srv_name));
778 q_u->level = level;
780 q_u->info.level = level;
781 q_u->info.info_ptr = (ctr->printers_2!=NULL)?1:0;
782 switch (level)
784 case 2:
785 /* init q_u->info.info2 from *info */
786 if (!make_spoolss_printer_info_2(mem_ctx, &q_u->info.info_2, ctr->printers_2))
788 DEBUG(0,("make_spoolss_q_addprinterex: Unable to fill SPOOL_Q_ADDPRINTEREX struct!\n"));
789 return False;
791 break;
792 default :
793 break;
796 q_u->unk0 = q_u->unk1 = q_u->unk2 = q_u->unk3 = 0;
798 q_u->user_switch=1;
800 q_u->user_ctr.level=1;
801 q_u->user_ctr.ptr=1;
802 q_u->user_ctr.user1.client_name_ptr = (clientname!=NULL)?1:0;
803 q_u->user_ctr.user1.user_name_ptr = (user_name!=NULL)?1:0;
804 q_u->user_ctr.user1.build=1381;
805 q_u->user_ctr.user1.major=2;
806 q_u->user_ctr.user1.minor=0;
807 q_u->user_ctr.user1.processor=0;
808 init_unistr2(&q_u->user_ctr.user1.client_name, clientname, strlen(clientname)+1);
809 init_unistr2(&q_u->user_ctr.user1.user_name, user_name, strlen(user_name)+1);
810 q_u->user_ctr.user1.size=q_u->user_ctr.user1.user_name.uni_str_len +
811 q_u->user_ctr.user1.client_name.uni_str_len + 2;
813 return True;
816 /*******************************************************************
817 create a SPOOL_PRINTER_INFO_2 stuct from a PRINTER_INFO_2 struct
818 *******************************************************************/
820 BOOL make_spoolss_printer_info_2(
821 TALLOC_CTX *mem_ctx,
822 SPOOL_PRINTER_INFO_LEVEL_2 **spool_info2,
823 PRINTER_INFO_2 *info
827 SPOOL_PRINTER_INFO_LEVEL_2 *inf;
829 /* allocate the necessary memory */
830 if (!(inf=(SPOOL_PRINTER_INFO_LEVEL_2*)talloc(mem_ctx, sizeof(SPOOL_PRINTER_INFO_LEVEL_2))))
832 DEBUG(0,("make_spoolss_printer_info_2: Unable to allocate SPOOL_PRINTER_INFO_LEVEL_2 sruct!\n"));
833 return False;
836 inf->servername_ptr = (info->servername.buffer!=NULL)?1:0;
837 inf->printername_ptr = (info->printername.buffer!=NULL)?1:0;
838 inf->sharename_ptr = (info->sharename.buffer!=NULL)?1:0;
839 inf->portname_ptr = (info->portname.buffer!=NULL)?1:0;
840 inf->drivername_ptr = (info->drivername.buffer!=NULL)?1:0;
841 inf->comment_ptr = (info->comment.buffer!=NULL)?1:0;
842 inf->location_ptr = (info->location.buffer!=NULL)?1:0;
843 inf->devmode_ptr = (info->devmode!=NULL)?1:0;
844 inf->sepfile_ptr = (info->sepfile.buffer!=NULL)?1:0;
845 inf->printprocessor_ptr = (info->printprocessor.buffer!=NULL)?1:0;
846 inf->datatype_ptr = (info->datatype.buffer!=NULL)?1:0;
847 inf->parameters_ptr = (info->parameters.buffer!=NULL)?1:0;
848 inf->secdesc_ptr = (info->secdesc!=NULL)?1:0;
849 inf->attributes = info->attributes;
850 inf->priority = info->priority;
851 inf->default_priority = info->defaultpriority;
852 inf->starttime = info->starttime;
853 inf->untiltime = info->untiltime;
854 inf->cjobs = info->cjobs;
855 inf->averageppm = info->averageppm;
856 init_unistr2_from_unistr(&inf->servername, &info->servername);
857 init_unistr2_from_unistr(&inf->printername, &info->printername);
858 init_unistr2_from_unistr(&inf->sharename, &info->sharename);
859 init_unistr2_from_unistr(&inf->portname, &info->portname);
860 init_unistr2_from_unistr(&inf->drivername, &info->drivername);
861 init_unistr2_from_unistr(&inf->comment, &info->comment);
862 init_unistr2_from_unistr(&inf->location, &info->location);
863 init_unistr2_from_unistr(&inf->sepfile, &info->sepfile);
864 init_unistr2_from_unistr(&inf->printprocessor, &info->printprocessor);
865 init_unistr2_from_unistr(&inf->datatype, &info->datatype);
866 init_unistr2_from_unistr(&inf->parameters, &info->parameters);
867 init_unistr2_from_unistr(&inf->datatype, &info->datatype);
868 inf->secdesc = inf->secdesc;
870 *spool_info2 = inf;
872 return True;
875 /*******************************************************************
876 * read a structure.
877 * called from spoolss_q_open_printer_ex (srv_spoolss.c)
878 ********************************************************************/
880 BOOL spoolss_io_q_open_printer_ex(char *desc, SPOOL_Q_OPEN_PRINTER_EX *q_u, prs_struct *ps, int depth)
882 if (q_u == NULL)
883 return False;
885 prs_debug(ps, depth, desc, "spoolss_io_q_open_printer_ex");
886 depth++;
888 if (!prs_align(ps))
889 return False;
891 if (!prs_uint32("printername_ptr", ps, depth, &q_u->printername_ptr))
892 return False;
893 if (!smb_io_unistr2("", &q_u->printername, q_u->printername_ptr, ps,depth))
894 return False;
896 if (!prs_align(ps))
897 return False;
899 if (!spoolss_io_printer_default("", &q_u->printer_default, ps, depth))
900 return False;
902 if (!prs_uint32("user_switch", ps, depth, &q_u->user_switch))
903 return False;
904 if (!spool_io_user_level("", &q_u->user_ctr, ps, depth))
905 return False;
907 return True;
910 /*******************************************************************
911 * init a structure.
912 ********************************************************************/
913 BOOL make_spoolss_q_deleteprinterdriver(
914 TALLOC_CTX *mem_ctx,
915 SPOOL_Q_DELETEPRINTERDRIVER *q_u,
916 const char *server,
917 const char* arch,
918 const char* driver
921 DEBUG(5,("make_spoolss_q_deleteprinterdriver\n"));
923 q_u->server_ptr = (server!=NULL)?1:0;
925 /* these must be NULL terminated or else NT4 will
926 complain about invalid parameters --jerry */
927 init_unistr2(&q_u->server, server, strlen(server)+1);
928 init_unistr2(&q_u->arch, arch, strlen(arch)+1);
929 init_unistr2(&q_u->driver, driver, strlen(driver)+1);
932 return True;
935 /*******************************************************************
936 * write a structure.
937 * called from static spoolss_r_open_printer_ex (srv_spoolss.c)
938 * called from spoolss_open_printer_ex (cli_spoolss.c)
939 ********************************************************************/
941 BOOL spoolss_io_r_open_printer_ex(char *desc, SPOOL_R_OPEN_PRINTER_EX *r_u, prs_struct *ps, int depth)
943 if (r_u == NULL) return False;
945 prs_debug(ps, depth, desc, "spoolss_io_r_open_printer_ex");
946 depth++;
948 if (!prs_align(ps))
949 return False;
951 if (!smb_io_pol_hnd("printer handle",&(r_u->handle),ps,depth))
952 return False;
954 if (!prs_werror("status code", ps, depth, &(r_u->status)))
955 return False;
957 return True;
960 /*******************************************************************
961 * make a structure.
962 ********************************************************************/
964 BOOL make_spoolss_q_getprinterdata(SPOOL_Q_GETPRINTERDATA *q_u,
965 const POLICY_HND *handle,
966 UNISTR2 *valuename, uint32 size)
968 if (q_u == NULL) return False;
970 DEBUG(5,("make_spoolss_q_getprinterdata\n"));
972 q_u->handle = *handle;
973 copy_unistr2(&q_u->valuename, valuename);
974 q_u->size = size;
976 return True;
979 /*******************************************************************
980 * read a structure.
981 * called from spoolss_q_getprinterdata (srv_spoolss.c)
982 ********************************************************************/
984 BOOL spoolss_io_q_getprinterdata(char *desc, SPOOL_Q_GETPRINTERDATA *q_u, prs_struct *ps, int depth)
986 if (q_u == NULL)
987 return False;
989 prs_debug(ps, depth, desc, "spoolss_io_q_getprinterdata");
990 depth++;
992 if (!prs_align(ps))
993 return False;
994 if (!smb_io_pol_hnd("printer handle",&q_u->handle,ps,depth))
995 return False;
996 if (!prs_align(ps))
997 return False;
998 if (!smb_io_unistr2("valuename", &q_u->valuename,True,ps,depth))
999 return False;
1000 if (!prs_align(ps))
1001 return False;
1002 if (!prs_uint32("size", ps, depth, &q_u->size))
1003 return False;
1005 return True;
1008 /*******************************************************************
1009 * read a structure.
1010 * called from spoolss_q_deleteprinterdata (srv_spoolss.c)
1011 ********************************************************************/
1013 BOOL spoolss_io_q_deleteprinterdata(char *desc, SPOOL_Q_DELETEPRINTERDATA *q_u, prs_struct *ps, int depth)
1015 if (q_u == NULL)
1016 return False;
1018 prs_debug(ps, depth, desc, "spoolss_io_q_deleteprinterdata");
1019 depth++;
1021 if (!prs_align(ps))
1022 return False;
1023 if (!smb_io_pol_hnd("printer handle",&q_u->handle,ps,depth))
1024 return False;
1025 if (!prs_align(ps))
1026 return False;
1027 if (!smb_io_unistr2("valuename", &q_u->valuename,True,ps,depth))
1028 return False;
1030 return True;
1033 /*******************************************************************
1034 * write a structure.
1035 * called from spoolss_r_deleteprinterdata (srv_spoolss.c)
1036 ********************************************************************/
1038 BOOL spoolss_io_r_deleteprinterdata(char *desc, SPOOL_R_DELETEPRINTERDATA *r_u, prs_struct *ps, int depth)
1040 prs_debug(ps, depth, desc, "spoolss_io_r_deleteprinterdata");
1041 depth++;
1042 if(!prs_werror("status", ps, depth, &r_u->status))
1043 return False;
1045 return True;
1048 /*******************************************************************
1049 * write a structure.
1050 * called from spoolss_r_getprinterdata (srv_spoolss.c)
1051 ********************************************************************/
1053 BOOL spoolss_io_r_getprinterdata(char *desc, SPOOL_R_GETPRINTERDATA *r_u, prs_struct *ps, int depth)
1055 if (r_u == NULL)
1056 return False;
1058 prs_debug(ps, depth, desc, "spoolss_io_r_getprinterdata");
1059 depth++;
1061 if (!prs_align(ps))
1062 return False;
1063 if (!prs_uint32("type", ps, depth, &r_u->type))
1064 return False;
1065 if (!prs_uint32("size", ps, depth, &r_u->size))
1066 return False;
1068 if (!prs_uint8s(False,"data", ps, depth, r_u->data, r_u->size))
1069 return False;
1071 if (!prs_align(ps))
1072 return False;
1074 if (!prs_uint32("needed", ps, depth, &r_u->needed))
1075 return False;
1076 if (!prs_werror("status", ps, depth, &r_u->status))
1077 return False;
1079 return True;
1082 /*******************************************************************
1083 * make a structure.
1084 ********************************************************************/
1086 BOOL make_spoolss_q_closeprinter(SPOOL_Q_CLOSEPRINTER *q_u, POLICY_HND *hnd)
1088 if (q_u == NULL) return False;
1090 DEBUG(5,("make_spoolss_q_closeprinter\n"));
1092 memcpy(&q_u->handle, hnd, sizeof(q_u->handle));
1094 return True;
1097 /*******************************************************************
1098 * read a structure.
1099 * called from static spoolss_q_abortprinter (srv_spoolss.c)
1100 * called from spoolss_abortprinter (cli_spoolss.c)
1101 ********************************************************************/
1103 BOOL spoolss_io_q_abortprinter(char *desc, SPOOL_Q_ABORTPRINTER *q_u, prs_struct *ps, int depth)
1105 if (q_u == NULL) return False;
1107 prs_debug(ps, depth, desc, "spoolss_io_q_abortprinter");
1108 depth++;
1110 if (!prs_align(ps))
1111 return False;
1113 if (!smb_io_pol_hnd("printer handle",&q_u->handle,ps,depth))
1114 return False;
1116 return True;
1119 /*******************************************************************
1120 * write a structure.
1121 * called from spoolss_r_abortprinter (srv_spoolss.c)
1122 ********************************************************************/
1124 BOOL spoolss_io_r_abortprinter(char *desc, SPOOL_R_ABORTPRINTER *r_u, prs_struct *ps, int depth)
1126 prs_debug(ps, depth, desc, "spoolss_io_r_abortprinter");
1127 depth++;
1128 if(!prs_werror("status", ps, depth, &r_u->status))
1129 return False;
1131 return True;
1134 /*******************************************************************
1135 * read a structure.
1136 * called from static spoolss_q_deleteprinter (srv_spoolss.c)
1137 * called from spoolss_deleteprinter (cli_spoolss.c)
1138 ********************************************************************/
1140 BOOL spoolss_io_q_deleteprinter(char *desc, SPOOL_Q_DELETEPRINTER *q_u, prs_struct *ps, int depth)
1142 if (q_u == NULL) return False;
1144 prs_debug(ps, depth, desc, "spoolss_io_q_deleteprinter");
1145 depth++;
1147 if (!prs_align(ps))
1148 return False;
1150 if (!smb_io_pol_hnd("printer handle",&q_u->handle,ps,depth))
1151 return False;
1153 return True;
1156 /*******************************************************************
1157 * write a structure.
1158 * called from static spoolss_r_deleteprinter (srv_spoolss.c)
1159 * called from spoolss_deleteprinter (cli_spoolss.c)
1160 ********************************************************************/
1162 BOOL spoolss_io_r_deleteprinter(char *desc, SPOOL_R_DELETEPRINTER *r_u, prs_struct *ps, int depth)
1164 prs_debug(ps, depth, desc, "spoolss_io_r_deleteprinter");
1165 depth++;
1167 if (!prs_align(ps))
1168 return False;
1170 if (!smb_io_pol_hnd("printer handle",&r_u->handle,ps,depth))
1171 return False;
1172 if (!prs_werror("status", ps, depth, &r_u->status))
1173 return False;
1175 return True;
1179 /*******************************************************************
1180 * read a structure.
1181 * called from api_spoolss_deleteprinterdriver (srv_spoolss.c)
1182 * called from spoolss_deleteprinterdriver (cli_spoolss.c)
1183 ********************************************************************/
1185 BOOL spoolss_io_q_deleteprinterdriver(char *desc, SPOOL_Q_DELETEPRINTERDRIVER *q_u, prs_struct *ps, int depth)
1187 if (q_u == NULL) return False;
1189 prs_debug(ps, depth, desc, "spoolss_io_q_deleteprinterdriver");
1190 depth++;
1192 if (!prs_align(ps))
1193 return False;
1195 if(!prs_uint32("server_ptr", ps, depth, &q_u->server_ptr))
1196 return False;
1197 if(!smb_io_unistr2("server", &q_u->server, q_u->server_ptr, ps, depth))
1198 return False;
1199 if(!smb_io_unistr2("arch", &q_u->arch, True, ps, depth))
1200 return False;
1201 if(!smb_io_unistr2("driver", &q_u->driver, True, ps, depth))
1202 return False;
1205 return True;
1209 /*******************************************************************
1210 * write a structure.
1211 ********************************************************************/
1212 BOOL spoolss_io_r_deleteprinterdriver(char *desc, SPOOL_R_DELETEPRINTERDRIVER *r_u, prs_struct *ps, int depth)
1214 if (r_u == NULL) return False;
1216 prs_debug(ps, depth, desc, "spoolss_io_r_deleteprinterdriver");
1217 depth++;
1219 if (!prs_align(ps))
1220 return False;
1222 if (!prs_werror("status", ps, depth, &r_u->status))
1223 return False;
1225 return True;
1230 /*******************************************************************
1231 * read a structure.
1232 * called from static spoolss_q_closeprinter (srv_spoolss.c)
1233 * called from spoolss_closeprinter (cli_spoolss.c)
1234 ********************************************************************/
1236 BOOL spoolss_io_q_closeprinter(char *desc, SPOOL_Q_CLOSEPRINTER *q_u, prs_struct *ps, int depth)
1238 if (q_u == NULL) return False;
1240 prs_debug(ps, depth, desc, "spoolss_io_q_closeprinter");
1241 depth++;
1243 if (!prs_align(ps))
1244 return False;
1246 if (!smb_io_pol_hnd("printer handle",&q_u->handle,ps,depth))
1247 return False;
1249 return True;
1252 /*******************************************************************
1253 * write a structure.
1254 * called from static spoolss_r_closeprinter (srv_spoolss.c)
1255 * called from spoolss_closeprinter (cli_spoolss.c)
1256 ********************************************************************/
1258 BOOL spoolss_io_r_closeprinter(char *desc, SPOOL_R_CLOSEPRINTER *r_u, prs_struct *ps, int depth)
1260 prs_debug(ps, depth, desc, "spoolss_io_r_closeprinter");
1261 depth++;
1263 if (!prs_align(ps))
1264 return False;
1266 if (!smb_io_pol_hnd("printer handle",&r_u->handle,ps,depth))
1267 return False;
1268 if (!prs_werror("status", ps, depth, &r_u->status))
1269 return False;
1271 return True;
1274 /*******************************************************************
1275 * read a structure.
1276 * called from spoolss_q_startdocprinter (srv_spoolss.c)
1277 ********************************************************************/
1279 BOOL spoolss_io_q_startdocprinter(char *desc, SPOOL_Q_STARTDOCPRINTER *q_u, prs_struct *ps, int depth)
1281 if (q_u == NULL) return False;
1283 prs_debug(ps, depth, desc, "spoolss_io_q_startdocprinter");
1284 depth++;
1286 if(!prs_align(ps))
1287 return False;
1289 if(!smb_io_pol_hnd("printer handle",&q_u->handle,ps,depth))
1290 return False;
1292 if(!smb_io_doc_info_container("",&q_u->doc_info_container, ps, depth))
1293 return False;
1295 return True;
1298 /*******************************************************************
1299 * write a structure.
1300 * called from spoolss_r_startdocprinter (srv_spoolss.c)
1301 ********************************************************************/
1303 BOOL spoolss_io_r_startdocprinter(char *desc, SPOOL_R_STARTDOCPRINTER *r_u, prs_struct *ps, int depth)
1305 prs_debug(ps, depth, desc, "spoolss_io_r_startdocprinter");
1306 depth++;
1307 if(!prs_uint32("jobid", ps, depth, &r_u->jobid))
1308 return False;
1309 if(!prs_werror("status", ps, depth, &r_u->status))
1310 return False;
1312 return True;
1315 /*******************************************************************
1316 * read a structure.
1317 * called from spoolss_q_enddocprinter (srv_spoolss.c)
1318 ********************************************************************/
1320 BOOL spoolss_io_q_enddocprinter(char *desc, SPOOL_Q_ENDDOCPRINTER *q_u, prs_struct *ps, int depth)
1322 if (q_u == NULL) return False;
1324 prs_debug(ps, depth, desc, "spoolss_io_q_enddocprinter");
1325 depth++;
1327 if(!prs_align(ps))
1328 return False;
1330 if(!smb_io_pol_hnd("printer handle",&q_u->handle,ps,depth))
1331 return False;
1333 return True;
1336 /*******************************************************************
1337 * write a structure.
1338 * called from spoolss_r_enddocprinter (srv_spoolss.c)
1339 ********************************************************************/
1341 BOOL spoolss_io_r_enddocprinter(char *desc, SPOOL_R_ENDDOCPRINTER *r_u, prs_struct *ps, int depth)
1343 prs_debug(ps, depth, desc, "spoolss_io_r_enddocprinter");
1344 depth++;
1345 if(!prs_werror("status", ps, depth, &r_u->status))
1346 return False;
1348 return True;
1351 /*******************************************************************
1352 * read a structure.
1353 * called from spoolss_q_startpageprinter (srv_spoolss.c)
1354 ********************************************************************/
1356 BOOL spoolss_io_q_startpageprinter(char *desc, SPOOL_Q_STARTPAGEPRINTER *q_u, prs_struct *ps, int depth)
1358 if (q_u == NULL) return False;
1360 prs_debug(ps, depth, desc, "spoolss_io_q_startpageprinter");
1361 depth++;
1363 if(!prs_align(ps))
1364 return False;
1366 if(!smb_io_pol_hnd("printer handle",&q_u->handle,ps,depth))
1367 return False;
1369 return True;
1372 /*******************************************************************
1373 * write a structure.
1374 * called from spoolss_r_startpageprinter (srv_spoolss.c)
1375 ********************************************************************/
1377 BOOL spoolss_io_r_startpageprinter(char *desc, SPOOL_R_STARTPAGEPRINTER *r_u, prs_struct *ps, int depth)
1379 prs_debug(ps, depth, desc, "spoolss_io_r_startpageprinter");
1380 depth++;
1381 if(!prs_werror("status", ps, depth, &r_u->status))
1382 return False;
1384 return True;
1387 /*******************************************************************
1388 * read a structure.
1389 * called from spoolss_q_endpageprinter (srv_spoolss.c)
1390 ********************************************************************/
1392 BOOL spoolss_io_q_endpageprinter(char *desc, SPOOL_Q_ENDPAGEPRINTER *q_u, prs_struct *ps, int depth)
1394 if (q_u == NULL) return False;
1396 prs_debug(ps, depth, desc, "spoolss_io_q_endpageprinter");
1397 depth++;
1399 if(!prs_align(ps))
1400 return False;
1402 if(!smb_io_pol_hnd("printer handle",&q_u->handle,ps,depth))
1403 return False;
1405 return True;
1408 /*******************************************************************
1409 * write a structure.
1410 * called from spoolss_r_endpageprinter (srv_spoolss.c)
1411 ********************************************************************/
1413 BOOL spoolss_io_r_endpageprinter(char *desc, SPOOL_R_ENDPAGEPRINTER *r_u, prs_struct *ps, int depth)
1415 prs_debug(ps, depth, desc, "spoolss_io_r_endpageprinter");
1416 depth++;
1417 if(!prs_werror("status", ps, depth, &r_u->status))
1418 return False;
1420 return True;
1423 /*******************************************************************
1424 * read a structure.
1425 * called from spoolss_q_writeprinter (srv_spoolss.c)
1426 ********************************************************************/
1428 BOOL spoolss_io_q_writeprinter(char *desc, SPOOL_Q_WRITEPRINTER *q_u, prs_struct *ps, int depth)
1430 if (q_u == NULL) return False;
1432 prs_debug(ps, depth, desc, "spoolss_io_q_writeprinter");
1433 depth++;
1435 if(!prs_align(ps))
1436 return False;
1438 if(!smb_io_pol_hnd("printer handle",&q_u->handle,ps,depth))
1439 return False;
1440 if(!prs_uint32("buffer_size", ps, depth, &q_u->buffer_size))
1441 return False;
1443 if (q_u->buffer_size!=0)
1445 if (UNMARSHALLING(ps))
1446 q_u->buffer=(uint8 *)prs_alloc_mem(ps,q_u->buffer_size*sizeof(uint8));
1447 if(q_u->buffer == NULL)
1448 return False;
1449 if(!prs_uint8s(True, "buffer", ps, depth, q_u->buffer, q_u->buffer_size))
1450 return False;
1452 if(!prs_align(ps))
1453 return False;
1454 if(!prs_uint32("buffer_size2", ps, depth, &q_u->buffer_size2))
1455 return False;
1457 return True;
1460 /*******************************************************************
1461 * write a structure.
1462 * called from spoolss_r_writeprinter (srv_spoolss.c)
1463 ********************************************************************/
1465 BOOL spoolss_io_r_writeprinter(char *desc, SPOOL_R_WRITEPRINTER *r_u, prs_struct *ps, int depth)
1467 prs_debug(ps, depth, desc, "spoolss_io_r_writeprinter");
1468 depth++;
1469 if(!prs_uint32("buffer_written", ps, depth, &r_u->buffer_written))
1470 return False;
1471 if(!prs_werror("status", ps, depth, &r_u->status))
1472 return False;
1474 return True;
1477 /*******************************************************************
1478 * read a structure.
1479 * called from spoolss_q_rffpcnex (srv_spoolss.c)
1480 ********************************************************************/
1482 BOOL spoolss_io_q_rffpcnex(char *desc, SPOOL_Q_RFFPCNEX *q_u, prs_struct *ps, int depth)
1484 prs_debug(ps, depth, desc, "spoolss_io_q_rffpcnex");
1485 depth++;
1487 if(!prs_align(ps))
1488 return False;
1490 if(!smb_io_pol_hnd("printer handle", &q_u->handle, ps, depth))
1491 return False;
1492 if(!prs_uint32("flags", ps, depth, &q_u->flags))
1493 return False;
1494 if(!prs_uint32("options", ps, depth, &q_u->options))
1495 return False;
1496 if(!prs_uint32("localmachine_ptr", ps, depth, &q_u->localmachine_ptr))
1497 return False;
1498 if(!smb_io_unistr2("localmachine", &q_u->localmachine, q_u->localmachine_ptr, ps, depth))
1499 return False;
1501 if(!prs_align(ps))
1502 return False;
1504 if(!prs_uint32("printerlocal", ps, depth, &q_u->printerlocal))
1505 return False;
1507 if(!prs_uint32("option_ptr", ps, depth, &q_u->option_ptr))
1508 return False;
1510 if (q_u->option_ptr!=0) {
1512 if (UNMARSHALLING(ps))
1513 if((q_u->option=(SPOOL_NOTIFY_OPTION *)prs_alloc_mem(ps,sizeof(SPOOL_NOTIFY_OPTION))) == NULL)
1514 return False;
1516 if(!smb_io_notify_option("notify option", q_u->option, ps, depth))
1517 return False;
1520 return True;
1523 /*******************************************************************
1524 * write a structure.
1525 * called from spoolss_r_rffpcnex (srv_spoolss.c)
1526 ********************************************************************/
1528 BOOL spoolss_io_r_rffpcnex(char *desc, SPOOL_R_RFFPCNEX *r_u, prs_struct *ps, int depth)
1530 prs_debug(ps, depth, desc, "spoolss_io_r_rffpcnex");
1531 depth++;
1533 if(!prs_werror("status", ps, depth, &r_u->status))
1534 return False;
1536 return True;
1539 /*******************************************************************
1540 * read a structure.
1541 * called from spoolss_q_rfnpcnex (srv_spoolss.c)
1542 ********************************************************************/
1544 BOOL spoolss_io_q_rfnpcnex(char *desc, SPOOL_Q_RFNPCNEX *q_u, prs_struct *ps, int depth)
1546 prs_debug(ps, depth, desc, "spoolss_io_q_rfnpcnex");
1547 depth++;
1549 if(!prs_align(ps))
1550 return False;
1552 if(!smb_io_pol_hnd("printer handle",&q_u->handle,ps,depth))
1553 return False;
1555 if(!prs_uint32("change", ps, depth, &q_u->change))
1556 return False;
1558 if(!prs_uint32("option_ptr", ps, depth, &q_u->option_ptr))
1559 return False;
1561 if (q_u->option_ptr!=0) {
1563 if (UNMARSHALLING(ps))
1564 if((q_u->option=(SPOOL_NOTIFY_OPTION *)prs_alloc_mem(ps,sizeof(SPOOL_NOTIFY_OPTION))) == NULL)
1565 return False;
1567 if(!smb_io_notify_option("notify option", q_u->option, ps, depth))
1568 return False;
1571 return True;
1574 /*******************************************************************
1575 * write a structure.
1576 * called from spoolss_r_rfnpcnex (srv_spoolss.c)
1577 ********************************************************************/
1579 BOOL spoolss_io_r_rfnpcnex(char *desc, SPOOL_R_RFNPCNEX *r_u, prs_struct *ps, int depth)
1581 prs_debug(ps, depth, desc, "spoolss_io_r_rfnpcnex");
1582 depth++;
1584 if(!prs_align(ps))
1585 return False;
1587 if (!prs_uint32("info_ptr", ps, depth, &r_u->info_ptr))
1588 return False;
1590 if(!smb_io_notify_info("notify info", &r_u->info ,ps,depth))
1591 return False;
1593 if(!prs_align(ps))
1594 return False;
1595 if(!prs_werror("status", ps, depth, &r_u->status))
1596 return False;
1598 return True;
1601 /*******************************************************************
1602 * return the length of a uint16 (obvious, but the code is clean)
1603 ********************************************************************/
1605 static uint32 size_of_uint16(uint16 *value)
1607 return (sizeof(*value));
1610 /*******************************************************************
1611 * return the length of a uint32 (obvious, but the code is clean)
1612 ********************************************************************/
1614 static uint32 size_of_uint32(uint32 *value)
1616 return (sizeof(*value));
1619 /*******************************************************************
1620 * return the length of a NTTIME (obvious, but the code is clean)
1621 ********************************************************************/
1623 static uint32 size_of_nttime(NTTIME *value)
1625 return (sizeof(*value));
1628 /*******************************************************************
1629 * return the length of a UNICODE string in number of char, includes:
1630 * - the leading zero
1631 * - the relative pointer size
1632 ********************************************************************/
1634 static uint32 size_of_relative_string(UNISTR *string)
1636 uint32 size=0;
1638 size=str_len_uni(string); /* the string length */
1639 size=size+1; /* add the leading zero */
1640 size=size*2; /* convert in char */
1641 /* Ensure size is 4 byte multiple (prs_align is being called...). */
1642 size += ((4 - (size & 3)) & 3);
1643 size=size+4; /* add the size of the ptr */
1645 return size;
1648 /*******************************************************************
1649 * return the length of a uint32 (obvious, but the code is clean)
1650 ********************************************************************/
1652 static uint32 size_of_device_mode(DEVICEMODE *devmode)
1654 if (devmode==NULL)
1655 return (4);
1656 else
1657 return (4+devmode->size+devmode->driverextra);
1660 /*******************************************************************
1661 * return the length of a uint32 (obvious, but the code is clean)
1662 ********************************************************************/
1664 static uint32 size_of_systemtime(SYSTEMTIME *systime)
1666 if (systime==NULL)
1667 return (4);
1668 else
1669 return (sizeof(SYSTEMTIME) +4);
1672 /*******************************************************************
1673 * write a UNICODE string.
1674 * used by all the RPC structs passing a buffer
1675 ********************************************************************/
1677 static BOOL spoolss_smb_io_unistr(char *desc, UNISTR *uni, prs_struct *ps, int depth)
1679 if (uni == NULL)
1680 return False;
1682 prs_debug(ps, depth, desc, "spoolss_smb_io_unistr");
1683 depth++;
1685 /* there should be no align here as it can mess up
1686 parsing a NEW_BUFFER->prs */
1687 #if 0 /* JERRY */
1688 if (!prs_align(ps))
1689 return False;
1690 #endif
1692 if (!prs_unistr("unistr", ps, depth, uni))
1693 return False;
1695 return True;
1698 /*******************************************************************
1699 * write a UNICODE string and its relative pointer.
1700 * used by all the RPC structs passing a buffer
1702 * As I'm a nice guy, I'm forcing myself to explain this code.
1703 * MS did a good job in the overall spoolss code except in some
1704 * functions where they are passing the API buffer directly in the
1705 * RPC request/reply. That's to maintain compatiility at the API level.
1706 * They could have done it the good way the first time.
1708 * So what happen is: the strings are written at the buffer's end,
1709 * in the reverse order of the original structure. Some pointers to
1710 * the strings are also in the buffer. Those are relative to the
1711 * buffer's start.
1713 * If you don't understand or want to change that function,
1714 * first get in touch with me: jfm@samba.org
1716 ********************************************************************/
1718 static BOOL smb_io_relstr(char *desc, NEW_BUFFER *buffer, int depth, UNISTR *string)
1720 prs_struct *ps=&buffer->prs;
1722 if (MARSHALLING(ps)) {
1723 uint32 struct_offset = prs_offset(ps);
1724 uint32 relative_offset;
1726 buffer->string_at_end -= (size_of_relative_string(string) - 4);
1727 if(!prs_set_offset(ps, buffer->string_at_end))
1728 return False;
1729 if (!prs_align(ps))
1730 return False;
1731 buffer->string_at_end = prs_offset(ps);
1733 /* write the string */
1734 if (!smb_io_unistr(desc, string, ps, depth))
1735 return False;
1737 if(!prs_set_offset(ps, struct_offset))
1738 return False;
1740 relative_offset=buffer->string_at_end - buffer->struct_start;
1741 /* write its offset */
1742 if (!prs_uint32("offset", ps, depth, &relative_offset))
1743 return False;
1745 else {
1746 uint32 old_offset;
1748 /* read the offset */
1749 if (!prs_uint32("offset", ps, depth, &(buffer->string_at_end)))
1750 return False;
1752 old_offset = prs_offset(ps);
1753 if(!prs_set_offset(ps, buffer->string_at_end+buffer->struct_start))
1754 return False;
1756 /* read the string */
1757 if (!spoolss_smb_io_unistr(desc, string, ps, depth))
1758 return False;
1760 if(!prs_set_offset(ps, old_offset))
1761 return False;
1763 return True;
1766 /*******************************************************************
1767 * write a array of UNICODE strings and its relative pointer.
1768 * used by 2 RPC structs
1769 ********************************************************************/
1771 static BOOL smb_io_relarraystr(char *desc, NEW_BUFFER *buffer, int depth, uint16 **string)
1773 UNISTR chaine;
1775 prs_struct *ps=&buffer->prs;
1777 if (MARSHALLING(ps)) {
1778 uint32 struct_offset = prs_offset(ps);
1779 uint32 relative_offset;
1780 uint16 *p;
1781 uint16 *q;
1782 uint16 zero=0;
1783 p=*string;
1784 q=*string;
1786 /* first write the last 0 */
1787 buffer->string_at_end -= 2;
1788 if(!prs_set_offset(ps, buffer->string_at_end))
1789 return False;
1791 if(!prs_uint16("leading zero", ps, depth, &zero))
1792 return False;
1794 while (p && (*p!=0)) {
1795 while (*q!=0)
1796 q++;
1798 /* Yes this should be malloc not talloc. Don't change. */
1800 chaine.buffer = malloc((q-p+1)*sizeof(uint16));
1801 if (chaine.buffer == NULL)
1802 return False;
1804 memcpy(chaine.buffer, p, (q-p+1)*sizeof(uint16));
1806 buffer->string_at_end -= (q-p+1)*sizeof(uint16);
1808 if(!prs_set_offset(ps, buffer->string_at_end)) {
1809 SAFE_FREE(chaine.buffer);
1810 return False;
1813 /* write the string */
1814 if (!spoolss_smb_io_unistr(desc, &chaine, ps, depth)) {
1815 SAFE_FREE(chaine.buffer);
1816 return False;
1818 q++;
1819 p=q;
1821 SAFE_FREE(chaine.buffer);
1824 if(!prs_set_offset(ps, struct_offset))
1825 return False;
1827 relative_offset=buffer->string_at_end - buffer->struct_start;
1828 /* write its offset */
1829 if (!prs_uint32("offset", ps, depth, &relative_offset))
1830 return False;
1832 } else {
1834 /* UNMARSHALLING */
1836 uint32 old_offset;
1837 uint16 *chaine2=NULL;
1838 int l_chaine=0;
1839 int l_chaine2=0;
1840 size_t realloc_size = 0;
1842 *string=NULL;
1844 /* read the offset */
1845 if (!prs_uint32("offset", ps, depth, &buffer->string_at_end))
1846 return False;
1848 old_offset = prs_offset(ps);
1849 if(!prs_set_offset(ps, buffer->string_at_end + buffer->struct_start))
1850 return False;
1852 do {
1853 if (!spoolss_smb_io_unistr(desc, &chaine, ps, depth))
1854 return False;
1856 l_chaine=str_len_uni(&chaine);
1858 /* we're going to add two more bytes here in case this
1859 is the last string in the array and we need to add
1860 an extra NULL for termination */
1861 if (l_chaine > 0)
1863 uint16 *tc2;
1865 realloc_size = (l_chaine2+l_chaine+2)*sizeof(uint16);
1867 /* Yes this should be realloc - it's freed below. JRA */
1869 if((tc2=(uint16 *)Realloc(chaine2, realloc_size)) == NULL) {
1870 SAFE_FREE(chaine2);
1871 return False;
1873 else chaine2 = tc2;
1874 memcpy(chaine2+l_chaine2, chaine.buffer, (l_chaine+1)*sizeof(uint16));
1875 l_chaine2+=l_chaine+1;
1878 } while(l_chaine!=0);
1880 /* the end should be bould NULL terminated so add
1881 the second one here */
1882 if (chaine2)
1884 chaine2[l_chaine2] = '\0';
1885 *string=(uint16 *)talloc_memdup(prs_get_mem_context(ps),chaine2,realloc_size);
1886 SAFE_FREE(chaine2);
1889 if(!prs_set_offset(ps, old_offset))
1890 return False;
1892 return True;
1895 /*******************************************************************
1896 Parse a DEVMODE structure and its relative pointer.
1897 ********************************************************************/
1899 static BOOL smb_io_relsecdesc(char *desc, NEW_BUFFER *buffer, int depth, SEC_DESC **secdesc)
1901 prs_struct *ps= &buffer->prs;
1903 prs_debug(ps, depth, desc, "smb_io_relsecdesc");
1904 depth++;
1906 if (MARSHALLING(ps)) {
1907 uint32 struct_offset = prs_offset(ps);
1908 uint32 relative_offset;
1910 if (! *secdesc) {
1911 relative_offset = 0;
1912 if (!prs_uint32("offset", ps, depth, &relative_offset))
1913 return False;
1914 return True;
1917 if (*secdesc != NULL) {
1918 buffer->string_at_end -= sec_desc_size(*secdesc);
1920 if(!prs_set_offset(ps, buffer->string_at_end))
1921 return False;
1922 /* write the secdesc */
1923 if (!sec_io_desc(desc, secdesc, ps, depth))
1924 return False;
1926 if(!prs_set_offset(ps, struct_offset))
1927 return False;
1930 relative_offset=buffer->string_at_end - buffer->struct_start;
1931 /* write its offset */
1933 if (!prs_uint32("offset", ps, depth, &relative_offset))
1934 return False;
1935 } else {
1936 uint32 old_offset;
1938 /* read the offset */
1939 if (!prs_uint32("offset", ps, depth, &buffer->string_at_end))
1940 return False;
1942 old_offset = prs_offset(ps);
1943 if(!prs_set_offset(ps, buffer->string_at_end + buffer->struct_start))
1944 return False;
1946 /* read the sd */
1947 if (!sec_io_desc(desc, secdesc, ps, depth))
1948 return False;
1950 if(!prs_set_offset(ps, old_offset))
1951 return False;
1953 return True;
1956 /*******************************************************************
1957 Parse a DEVMODE structure and its relative pointer.
1958 ********************************************************************/
1960 static BOOL smb_io_reldevmode(char *desc, NEW_BUFFER *buffer, int depth, DEVICEMODE **devmode)
1962 prs_struct *ps=&buffer->prs;
1964 prs_debug(ps, depth, desc, "smb_io_reldevmode");
1965 depth++;
1967 if (MARSHALLING(ps)) {
1968 uint32 struct_offset = prs_offset(ps);
1969 uint32 relative_offset;
1971 if (*devmode == NULL) {
1972 relative_offset=0;
1973 if (!prs_uint32("offset", ps, depth, &relative_offset))
1974 return False;
1975 DEBUG(8, ("boing, the devmode was NULL\n"));
1977 return True;
1980 buffer->string_at_end -= ((*devmode)->size + (*devmode)->driverextra);
1982 if(!prs_set_offset(ps, buffer->string_at_end))
1983 return False;
1985 /* write the DEVMODE */
1986 if (!spoolss_io_devmode(desc, ps, depth, *devmode))
1987 return False;
1989 if(!prs_set_offset(ps, struct_offset))
1990 return False;
1992 relative_offset=buffer->string_at_end - buffer->struct_start;
1993 /* write its offset */
1994 if (!prs_uint32("offset", ps, depth, &relative_offset))
1995 return False;
1997 else {
1998 uint32 old_offset;
2000 /* read the offset */
2001 if (!prs_uint32("offset", ps, depth, &buffer->string_at_end))
2002 return False;
2004 old_offset = prs_offset(ps);
2005 if(!prs_set_offset(ps, buffer->string_at_end + buffer->struct_start))
2006 return False;
2008 /* read the string */
2009 if((*devmode=(DEVICEMODE *)prs_alloc_mem(ps,sizeof(DEVICEMODE))) == NULL)
2010 return False;
2011 if (!spoolss_io_devmode(desc, ps, depth, *devmode))
2012 return False;
2014 if(!prs_set_offset(ps, old_offset))
2015 return False;
2017 return True;
2020 /*******************************************************************
2021 Parse a PRINTER_INFO_0 structure.
2022 ********************************************************************/
2024 BOOL smb_io_printer_info_0(char *desc, NEW_BUFFER *buffer, PRINTER_INFO_0 *info, int depth)
2026 prs_struct *ps=&buffer->prs;
2028 prs_debug(ps, depth, desc, "smb_io_printer_info_0");
2029 depth++;
2031 buffer->struct_start=prs_offset(ps);
2033 if (!smb_io_relstr("printername", buffer, depth, &info->printername))
2034 return False;
2035 if (!smb_io_relstr("servername", buffer, depth, &info->servername))
2036 return False;
2038 if(!prs_uint32("cjobs", ps, depth, &info->cjobs))
2039 return False;
2040 if(!prs_uint32("total_jobs", ps, depth, &info->total_jobs))
2041 return False;
2042 if(!prs_uint32("total_bytes", ps, depth, &info->total_bytes))
2043 return False;
2045 if(!prs_uint16("year", ps, depth, &info->year))
2046 return False;
2047 if(!prs_uint16("month", ps, depth, &info->month))
2048 return False;
2049 if(!prs_uint16("dayofweek", ps, depth, &info->dayofweek))
2050 return False;
2051 if(!prs_uint16("day", ps, depth, &info->day))
2052 return False;
2053 if(!prs_uint16("hour", ps, depth, &info->hour))
2054 return False;
2055 if(!prs_uint16("minute", ps, depth, &info->minute))
2056 return False;
2057 if(!prs_uint16("second", ps, depth, &info->second))
2058 return False;
2059 if(!prs_uint16("milliseconds", ps, depth, &info->milliseconds))
2060 return False;
2062 if(!prs_uint32("global_counter", ps, depth, &info->global_counter))
2063 return False;
2064 if(!prs_uint32("total_pages", ps, depth, &info->total_pages))
2065 return False;
2067 if(!prs_uint16("major_version", ps, depth, &info->major_version))
2068 return False;
2069 if(!prs_uint16("build_version", ps, depth, &info->build_version))
2070 return False;
2071 if(!prs_uint32("unknown7", ps, depth, &info->unknown7))
2072 return False;
2073 if(!prs_uint32("unknown8", ps, depth, &info->unknown8))
2074 return False;
2075 if(!prs_uint32("unknown9", ps, depth, &info->unknown9))
2076 return False;
2077 if(!prs_uint32("session_counter", ps, depth, &info->session_counter))
2078 return False;
2079 if(!prs_uint32("unknown11", ps, depth, &info->unknown11))
2080 return False;
2081 if(!prs_uint32("printer_errors", ps, depth, &info->printer_errors))
2082 return False;
2083 if(!prs_uint32("unknown13", ps, depth, &info->unknown13))
2084 return False;
2085 if(!prs_uint32("unknown14", ps, depth, &info->unknown14))
2086 return False;
2087 if(!prs_uint32("unknown15", ps, depth, &info->unknown15))
2088 return False;
2089 if(!prs_uint32("unknown16", ps, depth, &info->unknown16))
2090 return False;
2091 if(!prs_uint32("change_id", ps, depth, &info->change_id))
2092 return False;
2093 if(!prs_uint32("unknown18", ps, depth, &info->unknown18))
2094 return False;
2095 if(!prs_uint32("status" , ps, depth, &info->status))
2096 return False;
2097 if(!prs_uint32("unknown20", ps, depth, &info->unknown20))
2098 return False;
2099 if(!prs_uint32("c_setprinter", ps, depth, &info->c_setprinter))
2100 return False;
2101 if(!prs_uint16("unknown22", ps, depth, &info->unknown22))
2102 return False;
2103 if(!prs_uint16("unknown23", ps, depth, &info->unknown23))
2104 return False;
2105 if(!prs_uint16("unknown24", ps, depth, &info->unknown24))
2106 return False;
2107 if(!prs_uint16("unknown25", ps, depth, &info->unknown25))
2108 return False;
2109 if(!prs_uint16("unknown26", ps, depth, &info->unknown26))
2110 return False;
2111 if(!prs_uint16("unknown27", ps, depth, &info->unknown27))
2112 return False;
2113 if(!prs_uint16("unknown28", ps, depth, &info->unknown28))
2114 return False;
2115 if(!prs_uint16("unknown29", ps, depth, &info->unknown29))
2116 return False;
2118 return True;
2121 /*******************************************************************
2122 Parse a PRINTER_INFO_1 structure.
2123 ********************************************************************/
2125 BOOL smb_io_printer_info_1(char *desc, NEW_BUFFER *buffer, PRINTER_INFO_1 *info, int depth)
2127 prs_struct *ps=&buffer->prs;
2129 prs_debug(ps, depth, desc, "smb_io_printer_info_1");
2130 depth++;
2132 buffer->struct_start=prs_offset(ps);
2134 if (!prs_uint32("flags", ps, depth, &info->flags))
2135 return False;
2136 if (!smb_io_relstr("description", buffer, depth, &info->description))
2137 return False;
2138 if (!smb_io_relstr("name", buffer, depth, &info->name))
2139 return False;
2140 if (!smb_io_relstr("comment", buffer, depth, &info->comment))
2141 return False;
2143 return True;
2146 /*******************************************************************
2147 Parse a PRINTER_INFO_2 structure.
2148 ********************************************************************/
2150 BOOL smb_io_printer_info_2(char *desc, NEW_BUFFER *buffer, PRINTER_INFO_2 *info, int depth)
2152 prs_struct *ps=&buffer->prs;
2154 prs_debug(ps, depth, desc, "smb_io_printer_info_2");
2155 depth++;
2157 buffer->struct_start=prs_offset(ps);
2159 if (!smb_io_relstr("servername", buffer, depth, &info->servername))
2160 return False;
2161 if (!smb_io_relstr("printername", buffer, depth, &info->printername))
2162 return False;
2163 if (!smb_io_relstr("sharename", buffer, depth, &info->sharename))
2164 return False;
2165 if (!smb_io_relstr("portname", buffer, depth, &info->portname))
2166 return False;
2167 if (!smb_io_relstr("drivername", buffer, depth, &info->drivername))
2168 return False;
2169 if (!smb_io_relstr("comment", buffer, depth, &info->comment))
2170 return False;
2171 if (!smb_io_relstr("location", buffer, depth, &info->location))
2172 return False;
2174 /* NT parses the DEVMODE at the end of the struct */
2175 if (!smb_io_reldevmode("devmode", buffer, depth, &info->devmode))
2176 return False;
2178 if (!smb_io_relstr("sepfile", buffer, depth, &info->sepfile))
2179 return False;
2180 if (!smb_io_relstr("printprocessor", buffer, depth, &info->printprocessor))
2181 return False;
2182 if (!smb_io_relstr("datatype", buffer, depth, &info->datatype))
2183 return False;
2184 if (!smb_io_relstr("parameters", buffer, depth, &info->parameters))
2185 return False;
2187 if (!smb_io_relsecdesc("secdesc", buffer, depth, &info->secdesc))
2188 return False;
2190 if (!prs_uint32("attributes", ps, depth, &info->attributes))
2191 return False;
2192 if (!prs_uint32("priority", ps, depth, &info->priority))
2193 return False;
2194 if (!prs_uint32("defpriority", ps, depth, &info->defaultpriority))
2195 return False;
2196 if (!prs_uint32("starttime", ps, depth, &info->starttime))
2197 return False;
2198 if (!prs_uint32("untiltime", ps, depth, &info->untiltime))
2199 return False;
2200 if (!prs_uint32("status", ps, depth, &info->status))
2201 return False;
2202 if (!prs_uint32("jobs", ps, depth, &info->cjobs))
2203 return False;
2204 if (!prs_uint32("averageppm", ps, depth, &info->averageppm))
2205 return False;
2207 #if 0 /* JFMTEST */
2208 if (!prs_uint32_post("secdesc_ptr", ps, depth, NULL, sec_offset, info->secdesc ? prs_offset(ps)-buffer->struct_start : 0 ))
2209 return False;
2211 if (!sec_io_desc("secdesc", &info->secdesc, ps, depth))
2212 return False;
2213 #endif
2214 return True;
2217 /*******************************************************************
2218 Parse a PRINTER_INFO_3 structure.
2219 ********************************************************************/
2221 BOOL smb_io_printer_info_3(char *desc, NEW_BUFFER *buffer, PRINTER_INFO_3 *info, int depth)
2223 prs_struct *ps=&buffer->prs;
2225 prs_debug(ps, depth, desc, "smb_io_printer_info_3");
2226 depth++;
2228 buffer->struct_start=prs_offset(ps);
2230 if (!prs_uint32("flags", ps, depth, &info->flags))
2231 return False;
2232 if (!sec_io_desc("sec_desc", &info->secdesc, ps, depth))
2233 return False;
2235 return True;
2238 /*******************************************************************
2239 Parse a PORT_INFO_1 structure.
2240 ********************************************************************/
2242 BOOL smb_io_port_info_1(char *desc, NEW_BUFFER *buffer, PORT_INFO_1 *info, int depth)
2244 prs_struct *ps=&buffer->prs;
2246 prs_debug(ps, depth, desc, "smb_io_port_info_1");
2247 depth++;
2249 buffer->struct_start=prs_offset(ps);
2251 if (!smb_io_relstr("port_name", buffer, depth, &info->port_name))
2252 return False;
2254 return True;
2257 /*******************************************************************
2258 Parse a PORT_INFO_2 structure.
2259 ********************************************************************/
2261 BOOL smb_io_port_info_2(char *desc, NEW_BUFFER *buffer, PORT_INFO_2 *info, int depth)
2263 prs_struct *ps=&buffer->prs;
2265 prs_debug(ps, depth, desc, "smb_io_port_info_2");
2266 depth++;
2268 buffer->struct_start=prs_offset(ps);
2270 if (!smb_io_relstr("port_name", buffer, depth, &info->port_name))
2271 return False;
2272 if (!smb_io_relstr("monitor_name", buffer, depth, &info->monitor_name))
2273 return False;
2274 if (!smb_io_relstr("description", buffer, depth, &info->description))
2275 return False;
2276 if (!prs_uint32("port_type", ps, depth, &info->port_type))
2277 return False;
2278 if (!prs_uint32("reserved", ps, depth, &info->reserved))
2279 return False;
2281 return True;
2284 /*******************************************************************
2285 Parse a DRIVER_INFO_1 structure.
2286 ********************************************************************/
2288 BOOL smb_io_printer_driver_info_1(char *desc, NEW_BUFFER *buffer, DRIVER_INFO_1 *info, int depth)
2290 prs_struct *ps=&buffer->prs;
2292 prs_debug(ps, depth, desc, "smb_io_printer_driver_info_1");
2293 depth++;
2295 buffer->struct_start=prs_offset(ps);
2297 if (!smb_io_relstr("name", buffer, depth, &info->name))
2298 return False;
2300 return True;
2303 /*******************************************************************
2304 Parse a DRIVER_INFO_2 structure.
2305 ********************************************************************/
2307 BOOL smb_io_printer_driver_info_2(char *desc, NEW_BUFFER *buffer, DRIVER_INFO_2 *info, int depth)
2309 prs_struct *ps=&buffer->prs;
2311 prs_debug(ps, depth, desc, "smb_io_printer_driver_info_2");
2312 depth++;
2314 buffer->struct_start=prs_offset(ps);
2316 if (!prs_uint32("version", ps, depth, &info->version))
2317 return False;
2318 if (!smb_io_relstr("name", buffer, depth, &info->name))
2319 return False;
2320 if (!smb_io_relstr("architecture", buffer, depth, &info->architecture))
2321 return False;
2322 if (!smb_io_relstr("driverpath", buffer, depth, &info->driverpath))
2323 return False;
2324 if (!smb_io_relstr("datafile", buffer, depth, &info->datafile))
2325 return False;
2326 if (!smb_io_relstr("configfile", buffer, depth, &info->configfile))
2327 return False;
2329 return True;
2332 /*******************************************************************
2333 Parse a DRIVER_INFO_3 structure.
2334 ********************************************************************/
2336 BOOL smb_io_printer_driver_info_3(char *desc, NEW_BUFFER *buffer, DRIVER_INFO_3 *info, int depth)
2338 prs_struct *ps=&buffer->prs;
2340 prs_debug(ps, depth, desc, "smb_io_printer_driver_info_3");
2341 depth++;
2343 buffer->struct_start=prs_offset(ps);
2345 if (!prs_uint32("version", ps, depth, &info->version))
2346 return False;
2347 if (!smb_io_relstr("name", buffer, depth, &info->name))
2348 return False;
2349 if (!smb_io_relstr("architecture", buffer, depth, &info->architecture))
2350 return False;
2351 if (!smb_io_relstr("driverpath", buffer, depth, &info->driverpath))
2352 return False;
2353 if (!smb_io_relstr("datafile", buffer, depth, &info->datafile))
2354 return False;
2355 if (!smb_io_relstr("configfile", buffer, depth, &info->configfile))
2356 return False;
2357 if (!smb_io_relstr("helpfile", buffer, depth, &info->helpfile))
2358 return False;
2360 if (!smb_io_relarraystr("dependentfiles", buffer, depth, &info->dependentfiles))
2361 return False;
2363 if (!smb_io_relstr("monitorname", buffer, depth, &info->monitorname))
2364 return False;
2365 if (!smb_io_relstr("defaultdatatype", buffer, depth, &info->defaultdatatype))
2366 return False;
2368 return True;
2371 /*******************************************************************
2372 Parse a DRIVER_INFO_6 structure.
2373 ********************************************************************/
2375 BOOL smb_io_printer_driver_info_6(char *desc, NEW_BUFFER *buffer, DRIVER_INFO_6 *info, int depth)
2377 prs_struct *ps=&buffer->prs;
2379 prs_debug(ps, depth, desc, "smb_io_printer_driver_info_6");
2380 depth++;
2382 buffer->struct_start=prs_offset(ps);
2384 if (!prs_uint32("version", ps, depth, &info->version))
2385 return False;
2386 if (!smb_io_relstr("name", buffer, depth, &info->name))
2387 return False;
2388 if (!smb_io_relstr("architecture", buffer, depth, &info->architecture))
2389 return False;
2390 if (!smb_io_relstr("driverpath", buffer, depth, &info->driverpath))
2391 return False;
2392 if (!smb_io_relstr("datafile", buffer, depth, &info->datafile))
2393 return False;
2394 if (!smb_io_relstr("configfile", buffer, depth, &info->configfile))
2395 return False;
2396 if (!smb_io_relstr("helpfile", buffer, depth, &info->helpfile))
2397 return False;
2399 if (!smb_io_relarraystr("dependentfiles", buffer, depth, &info->dependentfiles))
2400 return False;
2402 if (!smb_io_relstr("monitorname", buffer, depth, &info->monitorname))
2403 return False;
2404 if (!smb_io_relstr("defaultdatatype", buffer, depth, &info->defaultdatatype))
2405 return False;
2407 if (!smb_io_relarraystr("previousdrivernames", buffer, depth, &info->previousdrivernames))
2408 return False;
2410 if (!prs_uint32("date.low", ps, depth, &info->driver_date.low))
2411 return False;
2412 if (!prs_uint32("date.high", ps, depth, &info->driver_date.high))
2413 return False;
2415 if (!prs_uint32("padding", ps, depth, &info->padding))
2416 return False;
2418 if (!prs_uint32("driver_version_low", ps, depth, &info->driver_version_low))
2419 return False;
2421 if (!prs_uint32("driver_version_high", ps, depth, &info->driver_version_high))
2422 return False;
2424 if (!smb_io_relstr("mfgname", buffer, depth, &info->mfgname))
2425 return False;
2426 if (!smb_io_relstr("oem_url", buffer, depth, &info->oem_url))
2427 return False;
2428 if (!smb_io_relstr("hardware_id", buffer, depth, &info->hardware_id))
2429 return False;
2430 if (!smb_io_relstr("provider", buffer, depth, &info->provider))
2431 return False;
2433 return True;
2436 /*******************************************************************
2437 Parse a JOB_INFO_1 structure.
2438 ********************************************************************/
2440 BOOL smb_io_job_info_1(char *desc, NEW_BUFFER *buffer, JOB_INFO_1 *info, int depth)
2442 prs_struct *ps=&buffer->prs;
2444 prs_debug(ps, depth, desc, "smb_io_job_info_1");
2445 depth++;
2447 buffer->struct_start=prs_offset(ps);
2449 if (!prs_uint32("jobid", ps, depth, &info->jobid))
2450 return False;
2451 if (!smb_io_relstr("printername", buffer, depth, &info->printername))
2452 return False;
2453 if (!smb_io_relstr("machinename", buffer, depth, &info->machinename))
2454 return False;
2455 if (!smb_io_relstr("username", buffer, depth, &info->username))
2456 return False;
2457 if (!smb_io_relstr("document", buffer, depth, &info->document))
2458 return False;
2459 if (!smb_io_relstr("datatype", buffer, depth, &info->datatype))
2460 return False;
2461 if (!smb_io_relstr("text_status", buffer, depth, &info->text_status))
2462 return False;
2463 if (!prs_uint32("status", ps, depth, &info->status))
2464 return False;
2465 if (!prs_uint32("priority", ps, depth, &info->priority))
2466 return False;
2467 if (!prs_uint32("position", ps, depth, &info->position))
2468 return False;
2469 if (!prs_uint32("totalpages", ps, depth, &info->totalpages))
2470 return False;
2471 if (!prs_uint32("pagesprinted", ps, depth, &info->pagesprinted))
2472 return False;
2473 if (!spoolss_io_system_time("submitted", ps, depth, &info->submitted))
2474 return False;
2476 return True;
2479 /*******************************************************************
2480 Parse a JOB_INFO_2 structure.
2481 ********************************************************************/
2483 BOOL smb_io_job_info_2(char *desc, NEW_BUFFER *buffer, JOB_INFO_2 *info, int depth)
2485 uint32 pipo=0;
2486 prs_struct *ps=&buffer->prs;
2488 prs_debug(ps, depth, desc, "smb_io_job_info_2");
2489 depth++;
2491 buffer->struct_start=prs_offset(ps);
2493 if (!prs_uint32("jobid",ps, depth, &info->jobid))
2494 return False;
2495 if (!smb_io_relstr("printername", buffer, depth, &info->printername))
2496 return False;
2497 if (!smb_io_relstr("machinename", buffer, depth, &info->machinename))
2498 return False;
2499 if (!smb_io_relstr("username", buffer, depth, &info->username))
2500 return False;
2501 if (!smb_io_relstr("document", buffer, depth, &info->document))
2502 return False;
2503 if (!smb_io_relstr("notifyname", buffer, depth, &info->notifyname))
2504 return False;
2505 if (!smb_io_relstr("datatype", buffer, depth, &info->datatype))
2506 return False;
2508 if (!smb_io_relstr("printprocessor", buffer, depth, &info->printprocessor))
2509 return False;
2510 if (!smb_io_relstr("parameters", buffer, depth, &info->parameters))
2511 return False;
2512 if (!smb_io_relstr("drivername", buffer, depth, &info->drivername))
2513 return False;
2514 if (!smb_io_reldevmode("devmode", buffer, depth, &info->devmode))
2515 return False;
2516 if (!smb_io_relstr("text_status", buffer, depth, &info->text_status))
2517 return False;
2519 /* SEC_DESC sec_desc;*/
2520 if (!prs_uint32("Hack! sec desc", ps, depth, &pipo))
2521 return False;
2523 if (!prs_uint32("status",ps, depth, &info->status))
2524 return False;
2525 if (!prs_uint32("priority",ps, depth, &info->priority))
2526 return False;
2527 if (!prs_uint32("position",ps, depth, &info->position))
2528 return False;
2529 if (!prs_uint32("starttime",ps, depth, &info->starttime))
2530 return False;
2531 if (!prs_uint32("untiltime",ps, depth, &info->untiltime))
2532 return False;
2533 if (!prs_uint32("totalpages",ps, depth, &info->totalpages))
2534 return False;
2535 if (!prs_uint32("size",ps, depth, &info->size))
2536 return False;
2537 if (!spoolss_io_system_time("submitted", ps, depth, &info->submitted) )
2538 return False;
2539 if (!prs_uint32("timeelapsed",ps, depth, &info->timeelapsed))
2540 return False;
2541 if (!prs_uint32("pagesprinted",ps, depth, &info->pagesprinted))
2542 return False;
2544 return True;
2547 /*******************************************************************
2548 ********************************************************************/
2550 BOOL smb_io_form_1(char *desc, NEW_BUFFER *buffer, FORM_1 *info, int depth)
2552 prs_struct *ps=&buffer->prs;
2554 prs_debug(ps, depth, desc, "smb_io_form_1");
2555 depth++;
2557 buffer->struct_start=prs_offset(ps);
2559 if (!prs_uint32("flag", ps, depth, &info->flag))
2560 return False;
2562 if (!smb_io_relstr("name", buffer, depth, &info->name))
2563 return False;
2565 if (!prs_uint32("width", ps, depth, &info->width))
2566 return False;
2567 if (!prs_uint32("length", ps, depth, &info->length))
2568 return False;
2569 if (!prs_uint32("left", ps, depth, &info->left))
2570 return False;
2571 if (!prs_uint32("top", ps, depth, &info->top))
2572 return False;
2573 if (!prs_uint32("right", ps, depth, &info->right))
2574 return False;
2575 if (!prs_uint32("bottom", ps, depth, &info->bottom))
2576 return False;
2578 return True;
2581 /*******************************************************************
2582 Read/write a BUFFER struct.
2583 ********************************************************************/
2585 static BOOL spoolss_io_buffer(char *desc, prs_struct *ps, int depth, NEW_BUFFER **pp_buffer)
2587 NEW_BUFFER *buffer = *pp_buffer;
2589 prs_debug(ps, depth, desc, "spoolss_io_buffer");
2590 depth++;
2592 if (UNMARSHALLING(ps))
2593 buffer = *pp_buffer = (NEW_BUFFER *)prs_alloc_mem(ps, sizeof(NEW_BUFFER));
2595 if (buffer == NULL)
2596 return False;
2598 if (!prs_uint32("ptr", ps, depth, &buffer->ptr))
2599 return False;
2601 /* reading */
2602 if (UNMARSHALLING(ps)) {
2603 buffer->size=0;
2604 buffer->string_at_end=0;
2606 if (buffer->ptr==0) {
2608 * JRA. I'm not sure if the data in here is in big-endian format if
2609 * the client is big-endian. Leave as default (little endian) for now.
2612 if (!prs_init(&buffer->prs, 0, prs_get_mem_context(ps), UNMARSHALL))
2613 return False;
2614 return True;
2617 if (!prs_uint32("size", ps, depth, &buffer->size))
2618 return False;
2621 * JRA. I'm not sure if the data in here is in big-endian format if
2622 * the client is big-endian. Leave as default (little endian) for now.
2625 if (!prs_init(&buffer->prs, buffer->size, prs_get_mem_context(ps), UNMARSHALL))
2626 return False;
2628 if (!prs_append_some_prs_data(&buffer->prs, ps, prs_offset(ps), buffer->size))
2629 return False;
2631 if (!prs_set_offset(&buffer->prs, 0))
2632 return False;
2634 if (!prs_set_offset(ps, buffer->size+prs_offset(ps)))
2635 return False;
2637 buffer->string_at_end=buffer->size;
2639 return True;
2641 else {
2642 BOOL ret = False;
2644 /* writing */
2645 if (buffer->ptr==0) {
2646 /* We have finished with the data in buffer->prs - free it. */
2647 prs_mem_free(&buffer->prs);
2648 return True;
2651 if (!prs_uint32("size", ps, depth, &buffer->size))
2652 goto out;
2654 if (!prs_append_some_prs_data(ps, &buffer->prs, 0, buffer->size))
2655 goto out;
2657 ret = True;
2658 out:
2660 /* We have finished with the data in buffer->prs - free it. */
2661 prs_mem_free(&buffer->prs);
2663 return ret;
2667 /*******************************************************************
2668 move a BUFFER from the query to the reply.
2669 As the data pointers in NEW_BUFFER are malloc'ed, not talloc'ed,
2670 this is ok. This is an OPTIMIZATION and is not strictly neccessary.
2671 ********************************************************************/
2673 void spoolss_move_buffer(NEW_BUFFER *src, NEW_BUFFER **dest)
2675 prs_switch_type(&src->prs, MARSHALL);
2676 if(!prs_set_offset(&src->prs, 0))
2677 return;
2678 prs_force_dynamic(&(src->prs));
2680 *dest=src;
2683 /*******************************************************************
2684 Get the size of a BUFFER struct.
2685 ********************************************************************/
2687 uint32 new_get_buffer_size(NEW_BUFFER *buffer)
2689 return (buffer->size);
2692 /*******************************************************************
2693 Parse a DRIVER_DIRECTORY_1 structure.
2694 ********************************************************************/
2696 BOOL smb_io_driverdir_1(char *desc, NEW_BUFFER *buffer, DRIVER_DIRECTORY_1 *info, int depth)
2698 prs_struct *ps=&buffer->prs;
2700 prs_debug(ps, depth, desc, "smb_io_driverdir_1");
2701 depth++;
2703 buffer->struct_start=prs_offset(ps);
2705 if (!smb_io_unistr(desc, &info->name, ps, depth))
2706 return False;
2708 return True;
2711 /*******************************************************************
2712 Parse a PORT_INFO_1 structure.
2713 ********************************************************************/
2715 BOOL smb_io_port_1(char *desc, NEW_BUFFER *buffer, PORT_INFO_1 *info, int depth)
2717 prs_struct *ps=&buffer->prs;
2719 prs_debug(ps, depth, desc, "smb_io_port_1");
2720 depth++;
2722 buffer->struct_start=prs_offset(ps);
2724 if(!smb_io_relstr("port_name", buffer, depth, &info->port_name))
2725 return False;
2727 return True;
2730 /*******************************************************************
2731 Parse a PORT_INFO_2 structure.
2732 ********************************************************************/
2734 BOOL smb_io_port_2(char *desc, NEW_BUFFER *buffer, PORT_INFO_2 *info, int depth)
2736 prs_struct *ps=&buffer->prs;
2738 prs_debug(ps, depth, desc, "smb_io_port_2");
2739 depth++;
2741 buffer->struct_start=prs_offset(ps);
2743 if(!smb_io_relstr("port_name", buffer, depth, &info->port_name))
2744 return False;
2745 if(!smb_io_relstr("monitor_name", buffer, depth, &info->monitor_name))
2746 return False;
2747 if(!smb_io_relstr("description", buffer, depth, &info->description))
2748 return False;
2749 if(!prs_uint32("port_type", ps, depth, &info->port_type))
2750 return False;
2751 if(!prs_uint32("reserved", ps, depth, &info->reserved))
2752 return False;
2754 return True;
2757 /*******************************************************************
2758 ********************************************************************/
2760 BOOL smb_io_printprocessor_info_1(char *desc, NEW_BUFFER *buffer, PRINTPROCESSOR_1 *info, int depth)
2762 prs_struct *ps=&buffer->prs;
2764 prs_debug(ps, depth, desc, "smb_io_printprocessor_info_1");
2765 depth++;
2767 buffer->struct_start=prs_offset(ps);
2769 if (smb_io_relstr("name", buffer, depth, &info->name))
2770 return False;
2772 return True;
2775 /*******************************************************************
2776 ********************************************************************/
2778 BOOL smb_io_printprocdatatype_info_1(char *desc, NEW_BUFFER *buffer, PRINTPROCDATATYPE_1 *info, int depth)
2780 prs_struct *ps=&buffer->prs;
2782 prs_debug(ps, depth, desc, "smb_io_printprocdatatype_info_1");
2783 depth++;
2785 buffer->struct_start=prs_offset(ps);
2787 if (smb_io_relstr("name", buffer, depth, &info->name))
2788 return False;
2790 return True;
2793 /*******************************************************************
2794 ********************************************************************/
2796 BOOL smb_io_printmonitor_info_1(char *desc, NEW_BUFFER *buffer, PRINTMONITOR_1 *info, int depth)
2798 prs_struct *ps=&buffer->prs;
2800 prs_debug(ps, depth, desc, "smb_io_printmonitor_info_1");
2801 depth++;
2803 buffer->struct_start=prs_offset(ps);
2805 if (!smb_io_relstr("name", buffer, depth, &info->name))
2806 return False;
2808 return True;
2811 /*******************************************************************
2812 ********************************************************************/
2814 BOOL smb_io_printmonitor_info_2(char *desc, NEW_BUFFER *buffer, PRINTMONITOR_2 *info, int depth)
2816 prs_struct *ps=&buffer->prs;
2818 prs_debug(ps, depth, desc, "smb_io_printmonitor_info_2");
2819 depth++;
2821 buffer->struct_start=prs_offset(ps);
2823 if (!smb_io_relstr("name", buffer, depth, &info->name))
2824 return False;
2825 if (!smb_io_relstr("environment", buffer, depth, &info->environment))
2826 return False;
2827 if (!smb_io_relstr("dll_name", buffer, depth, &info->dll_name))
2828 return False;
2830 return True;
2833 /*******************************************************************
2834 return the size required by a struct in the stream
2835 ********************************************************************/
2837 uint32 spoolss_size_printer_info_0(PRINTER_INFO_0 *info)
2839 int size=0;
2841 size+=size_of_relative_string( &info->printername );
2842 size+=size_of_relative_string( &info->servername );
2844 size+=size_of_uint32( &info->cjobs);
2845 size+=size_of_uint32( &info->total_jobs);
2846 size+=size_of_uint32( &info->total_bytes);
2848 size+=size_of_uint16( &info->year);
2849 size+=size_of_uint16( &info->month);
2850 size+=size_of_uint16( &info->dayofweek);
2851 size+=size_of_uint16( &info->day);
2852 size+=size_of_uint16( &info->hour);
2853 size+=size_of_uint16( &info->minute);
2854 size+=size_of_uint16( &info->second);
2855 size+=size_of_uint16( &info->milliseconds);
2857 size+=size_of_uint32( &info->global_counter);
2858 size+=size_of_uint32( &info->total_pages);
2860 size+=size_of_uint16( &info->major_version);
2861 size+=size_of_uint16( &info->build_version);
2863 size+=size_of_uint32( &info->unknown7);
2864 size+=size_of_uint32( &info->unknown8);
2865 size+=size_of_uint32( &info->unknown9);
2866 size+=size_of_uint32( &info->session_counter);
2867 size+=size_of_uint32( &info->unknown11);
2868 size+=size_of_uint32( &info->printer_errors);
2869 size+=size_of_uint32( &info->unknown13);
2870 size+=size_of_uint32( &info->unknown14);
2871 size+=size_of_uint32( &info->unknown15);
2872 size+=size_of_uint32( &info->unknown16);
2873 size+=size_of_uint32( &info->change_id);
2874 size+=size_of_uint32( &info->unknown18);
2875 size+=size_of_uint32( &info->status);
2876 size+=size_of_uint32( &info->unknown20);
2877 size+=size_of_uint32( &info->c_setprinter);
2879 size+=size_of_uint16( &info->unknown22);
2880 size+=size_of_uint16( &info->unknown23);
2881 size+=size_of_uint16( &info->unknown24);
2882 size+=size_of_uint16( &info->unknown25);
2883 size+=size_of_uint16( &info->unknown26);
2884 size+=size_of_uint16( &info->unknown27);
2885 size+=size_of_uint16( &info->unknown28);
2886 size+=size_of_uint16( &info->unknown29);
2888 return size;
2891 /*******************************************************************
2892 return the size required by a struct in the stream
2893 ********************************************************************/
2895 uint32 spoolss_size_printer_info_1(PRINTER_INFO_1 *info)
2897 int size=0;
2899 size+=size_of_uint32( &info->flags );
2900 size+=size_of_relative_string( &info->description );
2901 size+=size_of_relative_string( &info->name );
2902 size+=size_of_relative_string( &info->comment );
2904 return size;
2907 /*******************************************************************
2908 return the size required by a struct in the stream
2909 ********************************************************************/
2911 uint32 spoolss_size_printer_info_2(PRINTER_INFO_2 *info)
2913 uint32 size=0;
2915 size += 4;
2916 /* JRA !!!! TESTME - WHAT ABOUT prs_align.... !!! */
2917 size += sec_desc_size( info->secdesc );
2919 size+=size_of_device_mode( info->devmode );
2921 size+=size_of_relative_string( &info->servername );
2922 size+=size_of_relative_string( &info->printername );
2923 size+=size_of_relative_string( &info->sharename );
2924 size+=size_of_relative_string( &info->portname );
2925 size+=size_of_relative_string( &info->drivername );
2926 size+=size_of_relative_string( &info->comment );
2927 size+=size_of_relative_string( &info->location );
2929 size+=size_of_relative_string( &info->sepfile );
2930 size+=size_of_relative_string( &info->printprocessor );
2931 size+=size_of_relative_string( &info->datatype );
2932 size+=size_of_relative_string( &info->parameters );
2934 size+=size_of_uint32( &info->attributes );
2935 size+=size_of_uint32( &info->priority );
2936 size+=size_of_uint32( &info->defaultpriority );
2937 size+=size_of_uint32( &info->starttime );
2938 size+=size_of_uint32( &info->untiltime );
2939 size+=size_of_uint32( &info->status );
2940 size+=size_of_uint32( &info->cjobs );
2941 size+=size_of_uint32( &info->averageppm );
2942 return size;
2945 /*******************************************************************
2946 return the size required by a struct in the stream
2947 ********************************************************************/
2949 uint32 spoolss_size_printer_info_3(PRINTER_INFO_3 *info)
2951 /* The 4 is for the self relative pointer.. */
2952 /* JRA !!!! TESTME - WHAT ABOUT prs_align.... !!! */
2953 return 4 + (uint32)sec_desc_size( info->secdesc );
2956 /*******************************************************************
2957 return the size required by a struct in the stream
2958 ********************************************************************/
2960 uint32 spoolss_size_printer_driver_info_1(DRIVER_INFO_1 *info)
2962 int size=0;
2963 size+=size_of_relative_string( &info->name );
2965 return size;
2968 /*******************************************************************
2969 return the size required by a struct in the stream
2970 ********************************************************************/
2972 uint32 spoolss_size_printer_driver_info_2(DRIVER_INFO_2 *info)
2974 int size=0;
2975 size+=size_of_uint32( &info->version );
2976 size+=size_of_relative_string( &info->name );
2977 size+=size_of_relative_string( &info->architecture );
2978 size+=size_of_relative_string( &info->driverpath );
2979 size+=size_of_relative_string( &info->datafile );
2980 size+=size_of_relative_string( &info->configfile );
2982 return size;
2985 /*******************************************************************
2986 return the size required by a string array.
2987 ********************************************************************/
2989 uint32 spoolss_size_string_array(uint16 *string)
2991 uint32 i = 0;
2993 if (string) {
2994 for (i=0; (string[i]!=0x0000) || (string[i+1]!=0x0000); i++);
2996 i=i+2; /* to count all chars including the leading zero */
2997 i=2*i; /* because we need the value in bytes */
2998 i=i+4; /* the offset pointer size */
3000 return i;
3003 /*******************************************************************
3004 return the size required by a struct in the stream
3005 ********************************************************************/
3007 uint32 spoolss_size_printer_driver_info_3(DRIVER_INFO_3 *info)
3009 int size=0;
3011 size+=size_of_uint32( &info->version );
3012 size+=size_of_relative_string( &info->name );
3013 size+=size_of_relative_string( &info->architecture );
3014 size+=size_of_relative_string( &info->driverpath );
3015 size+=size_of_relative_string( &info->datafile );
3016 size+=size_of_relative_string( &info->configfile );
3017 size+=size_of_relative_string( &info->helpfile );
3018 size+=size_of_relative_string( &info->monitorname );
3019 size+=size_of_relative_string( &info->defaultdatatype );
3021 size+=spoolss_size_string_array(info->dependentfiles);
3023 return size;
3026 /*******************************************************************
3027 return the size required by a struct in the stream
3028 ********************************************************************/
3030 uint32 spoolss_size_printer_driver_info_6(DRIVER_INFO_6 *info)
3032 uint32 size=0;
3034 size+=size_of_uint32( &info->version );
3035 size+=size_of_relative_string( &info->name );
3036 size+=size_of_relative_string( &info->architecture );
3037 size+=size_of_relative_string( &info->driverpath );
3038 size+=size_of_relative_string( &info->datafile );
3039 size+=size_of_relative_string( &info->configfile );
3040 size+=size_of_relative_string( &info->helpfile );
3042 size+=spoolss_size_string_array(info->dependentfiles);
3044 size+=size_of_relative_string( &info->monitorname );
3045 size+=size_of_relative_string( &info->defaultdatatype );
3047 size+=spoolss_size_string_array(info->previousdrivernames);
3049 size+=size_of_nttime(&info->driver_date);
3050 size+=size_of_uint32( &info->padding );
3051 size+=size_of_uint32( &info->driver_version_low );
3052 size+=size_of_uint32( &info->driver_version_high );
3053 size+=size_of_relative_string( &info->mfgname );
3054 size+=size_of_relative_string( &info->oem_url );
3055 size+=size_of_relative_string( &info->hardware_id );
3056 size+=size_of_relative_string( &info->provider );
3058 return size;
3061 /*******************************************************************
3062 return the size required by a struct in the stream
3063 ********************************************************************/
3065 uint32 spoolss_size_job_info_1(JOB_INFO_1 *info)
3067 int size=0;
3068 size+=size_of_uint32( &info->jobid );
3069 size+=size_of_relative_string( &info->printername );
3070 size+=size_of_relative_string( &info->machinename );
3071 size+=size_of_relative_string( &info->username );
3072 size+=size_of_relative_string( &info->document );
3073 size+=size_of_relative_string( &info->datatype );
3074 size+=size_of_relative_string( &info->text_status );
3075 size+=size_of_uint32( &info->status );
3076 size+=size_of_uint32( &info->priority );
3077 size+=size_of_uint32( &info->position );
3078 size+=size_of_uint32( &info->totalpages );
3079 size+=size_of_uint32( &info->pagesprinted );
3080 size+=size_of_systemtime( &info->submitted );
3082 return size;
3085 /*******************************************************************
3086 return the size required by a struct in the stream
3087 ********************************************************************/
3089 uint32 spoolss_size_job_info_2(JOB_INFO_2 *info)
3091 int size=0;
3093 size+=4; /* size of sec desc ptr */
3095 size+=size_of_uint32( &info->jobid );
3096 size+=size_of_relative_string( &info->printername );
3097 size+=size_of_relative_string( &info->machinename );
3098 size+=size_of_relative_string( &info->username );
3099 size+=size_of_relative_string( &info->document );
3100 size+=size_of_relative_string( &info->notifyname );
3101 size+=size_of_relative_string( &info->datatype );
3102 size+=size_of_relative_string( &info->printprocessor );
3103 size+=size_of_relative_string( &info->parameters );
3104 size+=size_of_relative_string( &info->drivername );
3105 size+=size_of_device_mode( info->devmode );
3106 size+=size_of_relative_string( &info->text_status );
3107 /* SEC_DESC sec_desc;*/
3108 size+=size_of_uint32( &info->status );
3109 size+=size_of_uint32( &info->priority );
3110 size+=size_of_uint32( &info->position );
3111 size+=size_of_uint32( &info->starttime );
3112 size+=size_of_uint32( &info->untiltime );
3113 size+=size_of_uint32( &info->totalpages );
3114 size+=size_of_uint32( &info->size );
3115 size+=size_of_systemtime( &info->submitted );
3116 size+=size_of_uint32( &info->timeelapsed );
3117 size+=size_of_uint32( &info->pagesprinted );
3119 return size;
3122 /*******************************************************************
3123 return the size required by a struct in the stream
3124 ********************************************************************/
3126 uint32 spoolss_size_form_1(FORM_1 *info)
3128 int size=0;
3130 size+=size_of_uint32( &info->flag );
3131 size+=size_of_relative_string( &info->name );
3132 size+=size_of_uint32( &info->width );
3133 size+=size_of_uint32( &info->length );
3134 size+=size_of_uint32( &info->left );
3135 size+=size_of_uint32( &info->top );
3136 size+=size_of_uint32( &info->right );
3137 size+=size_of_uint32( &info->bottom );
3139 return size;
3142 /*******************************************************************
3143 return the size required by a struct in the stream
3144 ********************************************************************/
3146 uint32 spoolss_size_port_info_1(PORT_INFO_1 *info)
3148 int size=0;
3150 size+=size_of_relative_string( &info->port_name );
3152 return size;
3155 /*******************************************************************
3156 return the size required by a struct in the stream
3157 ********************************************************************/
3159 uint32 spoolss_size_driverdir_info_1(DRIVER_DIRECTORY_1 *info)
3161 int size=0;
3163 size=str_len_uni(&info->name); /* the string length */
3164 size=size+1; /* add the leading zero */
3165 size=size*2; /* convert in char */
3167 return size;
3170 /*******************************************************************
3171 return the size required by a struct in the stream
3172 ********************************************************************/
3174 uint32 spoolss_size_port_info_2(PORT_INFO_2 *info)
3176 int size=0;
3178 size+=size_of_relative_string( &info->port_name );
3179 size+=size_of_relative_string( &info->monitor_name );
3180 size+=size_of_relative_string( &info->description );
3182 size+=size_of_uint32( &info->port_type );
3183 size+=size_of_uint32( &info->reserved );
3185 return size;
3188 /*******************************************************************
3189 return the size required by a struct in the stream
3190 ********************************************************************/
3192 uint32 spoolss_size_printprocessor_info_1(PRINTPROCESSOR_1 *info)
3194 int size=0;
3195 size+=size_of_relative_string( &info->name );
3197 return size;
3200 /*******************************************************************
3201 return the size required by a struct in the stream
3202 ********************************************************************/
3204 uint32 spoolss_size_printprocdatatype_info_1(PRINTPROCDATATYPE_1 *info)
3206 int size=0;
3207 size+=size_of_relative_string( &info->name );
3209 return size;
3212 /*******************************************************************
3213 return the size required by a struct in the stream
3214 ********************************************************************/
3215 uint32 spoolss_size_printer_enum_values(PRINTER_ENUM_VALUES *p)
3217 uint32 size = 0;
3219 if (!p)
3220 return 0;
3222 /* uint32(offset) + uint32(length) + length) */
3223 size += (size_of_uint32(&p->value_len)*2) + p->value_len;
3224 size += (size_of_uint32(&p->data_len)*2) + p->data_len;
3226 size += size_of_uint32(&p->type);
3228 return size;
3231 /*******************************************************************
3232 return the size required by a struct in the stream
3233 ********************************************************************/
3235 uint32 spoolss_size_printmonitor_info_1(PRINTMONITOR_1 *info)
3237 int size=0;
3238 size+=size_of_relative_string( &info->name );
3240 return size;
3243 /*******************************************************************
3244 return the size required by a struct in the stream
3245 ********************************************************************/
3247 uint32 spoolss_size_printmonitor_info_2(PRINTMONITOR_2 *info)
3249 int size=0;
3250 size+=size_of_relative_string( &info->name);
3251 size+=size_of_relative_string( &info->environment);
3252 size+=size_of_relative_string( &info->dll_name);
3254 return size;
3257 /*******************************************************************
3258 * init a structure.
3259 ********************************************************************/
3261 BOOL make_spoolss_q_getprinterdriver2(SPOOL_Q_GETPRINTERDRIVER2 *q_u,
3262 const POLICY_HND *hnd,
3263 const fstring architecture,
3264 uint32 level, uint32 clientmajor, uint32 clientminor,
3265 NEW_BUFFER *buffer, uint32 offered)
3267 if (q_u == NULL)
3268 return False;
3270 memcpy(&q_u->handle, hnd, sizeof(q_u->handle));
3272 init_buf_unistr2(&q_u->architecture, &q_u->architecture_ptr, architecture);
3274 q_u->level=level;
3275 q_u->clientmajorversion=clientmajor;
3276 q_u->clientminorversion=clientminor;
3278 q_u->buffer=buffer;
3279 q_u->offered=offered;
3281 return True;
3284 /*******************************************************************
3285 * read a structure.
3286 * called from spoolss_getprinterdriver2 (srv_spoolss.c)
3287 ********************************************************************/
3289 BOOL spoolss_io_q_getprinterdriver2(char *desc, SPOOL_Q_GETPRINTERDRIVER2 *q_u, prs_struct *ps, int depth)
3291 prs_debug(ps, depth, desc, "spoolss_io_q_getprinterdriver2");
3292 depth++;
3294 if(!prs_align(ps))
3295 return False;
3297 if(!smb_io_pol_hnd("printer handle", &q_u->handle, ps, depth))
3298 return False;
3299 if(!prs_uint32("architecture_ptr", ps, depth, &q_u->architecture_ptr))
3300 return False;
3301 if(!smb_io_unistr2("architecture", &q_u->architecture, q_u->architecture_ptr, ps, depth))
3302 return False;
3304 if(!prs_align(ps))
3305 return False;
3306 if(!prs_uint32("level", ps, depth, &q_u->level))
3307 return False;
3309 if(!spoolss_io_buffer("", ps, depth, &q_u->buffer))
3310 return False;
3312 if(!prs_align(ps))
3313 return False;
3315 if(!prs_uint32("offered", ps, depth, &q_u->offered))
3316 return False;
3318 if(!prs_uint32("clientmajorversion", ps, depth, &q_u->clientmajorversion))
3319 return False;
3320 if(!prs_uint32("clientminorversion", ps, depth, &q_u->clientminorversion))
3321 return False;
3323 return True;
3326 /*******************************************************************
3327 * read a structure.
3328 * called from spoolss_getprinterdriver2 (srv_spoolss.c)
3329 ********************************************************************/
3331 BOOL spoolss_io_r_getprinterdriver2(char *desc, SPOOL_R_GETPRINTERDRIVER2 *r_u, prs_struct *ps, int depth)
3333 prs_debug(ps, depth, desc, "spoolss_io_r_getprinterdriver2");
3334 depth++;
3336 if (!prs_align(ps))
3337 return False;
3339 if (!spoolss_io_buffer("", ps, depth, &r_u->buffer))
3340 return False;
3342 if (!prs_align(ps))
3343 return False;
3344 if (!prs_uint32("needed", ps, depth, &r_u->needed))
3345 return False;
3346 if (!prs_uint32("servermajorversion", ps, depth, &r_u->servermajorversion))
3347 return False;
3348 if (!prs_uint32("serverminorversion", ps, depth, &r_u->serverminorversion))
3349 return False;
3350 if (!prs_werror("status", ps, depth, &r_u->status))
3351 return False;
3353 return True;
3356 /*******************************************************************
3357 * init a structure.
3358 ********************************************************************/
3360 BOOL make_spoolss_q_enumprinters(
3361 SPOOL_Q_ENUMPRINTERS *q_u,
3362 uint32 flags,
3363 fstring servername,
3364 uint32 level,
3365 NEW_BUFFER *buffer,
3366 uint32 offered
3369 q_u->flags=flags;
3371 q_u->servername_ptr = (servername != NULL) ? 1 : 0;
3372 init_buf_unistr2(&q_u->servername, &q_u->servername_ptr, servername);
3374 q_u->level=level;
3375 q_u->buffer=buffer;
3376 q_u->offered=offered;
3378 return True;
3381 /*******************************************************************
3382 * init a structure.
3383 ********************************************************************/
3385 BOOL make_spoolss_q_enumports(SPOOL_Q_ENUMPORTS *q_u,
3386 fstring servername, uint32 level,
3387 NEW_BUFFER *buffer, uint32 offered)
3389 q_u->name_ptr = (servername != NULL) ? 1 : 0;
3390 init_buf_unistr2(&q_u->name, &q_u->name_ptr, servername);
3392 q_u->level=level;
3393 q_u->buffer=buffer;
3394 q_u->offered=offered;
3396 return True;
3399 /*******************************************************************
3400 * read a structure.
3401 * called from spoolss_enumprinters (srv_spoolss.c)
3402 ********************************************************************/
3404 BOOL spoolss_io_q_enumprinters(char *desc, SPOOL_Q_ENUMPRINTERS *q_u, prs_struct *ps, int depth)
3406 prs_debug(ps, depth, desc, "spoolss_io_q_enumprinters");
3407 depth++;
3409 if (!prs_align(ps))
3410 return False;
3412 if (!prs_uint32("flags", ps, depth, &q_u->flags))
3413 return False;
3414 if (!prs_uint32("servername_ptr", ps, depth, &q_u->servername_ptr))
3415 return False;
3417 if (!smb_io_unistr2("", &q_u->servername, q_u->servername_ptr, ps, depth))
3418 return False;
3420 if (!prs_align(ps))
3421 return False;
3422 if (!prs_uint32("level", ps, depth, &q_u->level))
3423 return False;
3425 if (!spoolss_io_buffer("", ps, depth, &q_u->buffer))
3426 return False;
3428 if (!prs_align(ps))
3429 return False;
3430 if (!prs_uint32("offered", ps, depth, &q_u->offered))
3431 return False;
3433 return True;
3436 /*******************************************************************
3437 Parse a SPOOL_R_ENUMPRINTERS structure.
3438 ********************************************************************/
3440 BOOL spoolss_io_r_enumprinters(char *desc, SPOOL_R_ENUMPRINTERS *r_u, prs_struct *ps, int depth)
3442 prs_debug(ps, depth, desc, "spoolss_io_r_enumprinters");
3443 depth++;
3445 if (!prs_align(ps))
3446 return False;
3448 if (!spoolss_io_buffer("", ps, depth, &r_u->buffer))
3449 return False;
3451 if (!prs_align(ps))
3452 return False;
3454 if (!prs_uint32("needed", ps, depth, &r_u->needed))
3455 return False;
3457 if (!prs_uint32("returned", ps, depth, &r_u->returned))
3458 return False;
3460 if (!prs_werror("status", ps, depth, &r_u->status))
3461 return False;
3463 return True;
3466 /*******************************************************************
3467 * write a structure.
3468 * called from spoolss_r_enum_printers (srv_spoolss.c)
3470 ********************************************************************/
3472 BOOL spoolss_io_r_getprinter(char *desc, SPOOL_R_GETPRINTER *r_u, prs_struct *ps, int depth)
3474 prs_debug(ps, depth, desc, "spoolss_io_r_getprinter");
3475 depth++;
3477 if (!prs_align(ps))
3478 return False;
3480 if (!spoolss_io_buffer("", ps, depth, &r_u->buffer))
3481 return False;
3483 if (!prs_align(ps))
3484 return False;
3486 if (!prs_uint32("needed", ps, depth, &r_u->needed))
3487 return False;
3489 if (!prs_werror("status", ps, depth, &r_u->status))
3490 return False;
3492 return True;
3495 /*******************************************************************
3496 * read a structure.
3497 * called from spoolss_getprinter (srv_spoolss.c)
3498 ********************************************************************/
3500 BOOL spoolss_io_q_getprinter(char *desc, SPOOL_Q_GETPRINTER *q_u, prs_struct *ps, int depth)
3502 prs_debug(ps, depth, desc, "spoolss_io_q_getprinter");
3503 depth++;
3505 if (!prs_align(ps))
3506 return False;
3508 if(!smb_io_pol_hnd("printer handle", &q_u->handle, ps, depth))
3509 return False;
3510 if (!prs_uint32("level", ps, depth, &q_u->level))
3511 return False;
3513 if (!spoolss_io_buffer("", ps, depth, &q_u->buffer))
3514 return False;
3516 if (!prs_align(ps))
3517 return False;
3518 if (!prs_uint32("offered", ps, depth, &q_u->offered))
3519 return False;
3521 return True;
3524 /*******************************************************************
3525 * init a structure.
3526 ********************************************************************/
3528 BOOL make_spoolss_q_getprinter(
3529 TALLOC_CTX *mem_ctx,
3530 SPOOL_Q_GETPRINTER *q_u,
3531 const POLICY_HND *hnd,
3532 uint32 level,
3533 NEW_BUFFER *buffer,
3534 uint32 offered
3537 if (q_u == NULL)
3539 return False;
3541 memcpy(&q_u->handle, hnd, sizeof(q_u->handle));
3543 q_u->level=level;
3544 q_u->buffer=buffer;
3545 q_u->offered=offered;
3547 return True;
3550 /*******************************************************************
3551 * init a structure.
3552 ********************************************************************/
3553 BOOL make_spoolss_q_setprinter(
3554 TALLOC_CTX *mem_ctx,
3555 SPOOL_Q_SETPRINTER *q_u,
3556 const POLICY_HND *hnd,
3557 uint32 level,
3558 PRINTER_INFO_CTR *info,
3559 uint32 command
3562 SEC_DESC *secdesc;
3563 DEVICEMODE *devmode;
3565 if (q_u == NULL)
3567 return False;
3570 memcpy(&q_u->handle, hnd, sizeof(q_u->handle));
3572 q_u->level = level;
3573 q_u->info.level = level;
3574 q_u->info.info_ptr = (info != NULL) ? 1 : 0;
3575 switch (level)
3577 case 2:
3578 secdesc = info->printers_2->secdesc;
3579 devmode = info->printers_2->devmode;
3581 /* FIXMEE!! HACK ALERT!!! --jerry */
3582 info->printers_2->devmode = NULL;
3583 info->printers_2->secdesc = NULL;
3585 make_spoolss_printer_info_2 (mem_ctx, &q_u->info.info_2, info->printers_2);
3586 #if 0 /* JERRY TEST */
3587 q_u->secdesc_ctr = (SEC_DESC_BUF*)malloc(sizeof(SEC_DESC_BUF));
3588 if (!q_u->secdesc_ctr)
3589 return False;
3590 q_u->secdesc_ctr->ptr = (secdesc != NULL) ? 1: 0;
3591 q_u->secdesc_ctr->max_len = (secdesc) ? sizeof(SEC_DESC) + (2*sizeof(uint32)) : 0;
3592 q_u->secdesc_ctr->len = (secdesc) ? sizeof(SEC_DESC) + (2*sizeof(uint32)) : 0;
3593 q_u->secdesc_ctr->sec = secdesc;
3595 q_u->devmode_ctr.devmode_ptr = (devmode != NULL) ? 1 : 0;
3596 q_u->devmode_ctr.size = sizeof(DEVICEMODE) + (3*sizeof(uint32));
3597 q_u->devmode_ctr.devmode = devmode;
3598 #else
3599 q_u->secdesc_ctr = NULL;
3601 q_u->devmode_ctr.devmode_ptr = 0;
3602 q_u->devmode_ctr.size = 0;
3603 q_u->devmode_ctr.devmode = NULL;
3604 #endif
3605 break;
3606 default:
3607 DEBUG(0,("make_spoolss_q_setprinter: Unknown info level [%d]\n", level));
3608 break;
3612 q_u->command = command;
3614 return True;
3618 /*******************************************************************
3619 ********************************************************************/
3621 BOOL spoolss_io_r_setprinter(char *desc, SPOOL_R_SETPRINTER *r_u, prs_struct *ps, int depth)
3623 prs_debug(ps, depth, desc, "spoolss_io_r_setprinter");
3624 depth++;
3626 if(!prs_align(ps))
3627 return False;
3629 if(!prs_werror("status", ps, depth, &r_u->status))
3630 return False;
3632 return True;
3635 /*******************************************************************
3636 Marshall/unmarshall a SPOOL_Q_SETPRINTER struct.
3637 ********************************************************************/
3639 BOOL spoolss_io_q_setprinter(char *desc, SPOOL_Q_SETPRINTER *q_u, prs_struct *ps, int depth)
3641 uint32 ptr_sec_desc = 0;
3643 prs_debug(ps, depth, desc, "spoolss_io_q_setprinter");
3644 depth++;
3646 if(!prs_align(ps))
3647 return False;
3649 if(!smb_io_pol_hnd("printer handle", &q_u->handle ,ps, depth))
3650 return False;
3651 if(!prs_uint32("level", ps, depth, &q_u->level))
3652 return False;
3654 if(!spool_io_printer_info_level("", &q_u->info, ps, depth))
3655 return False;
3657 if (!spoolss_io_devmode_cont(desc, &q_u->devmode_ctr, ps, depth))
3658 return False;
3660 switch (q_u->level)
3662 case 2:
3664 ptr_sec_desc = q_u->info.info_2->secdesc_ptr;
3665 break;
3667 case 3:
3669 ptr_sec_desc = q_u->info.info_3->secdesc_ptr;
3670 break;
3673 if (ptr_sec_desc)
3675 if (!sec_io_desc_buf(desc, &q_u->secdesc_ctr, ps, depth))
3676 return False;
3677 } else {
3678 uint32 dummy;
3680 /* Parse a NULL security descriptor. This should really
3681 happen inside the sec_io_desc_buf() function. */
3683 prs_debug(ps, depth, "", "sec_io_desc_buf");
3684 if (!prs_uint32("size", ps, depth + 1, &dummy)) return False;
3685 if (!prs_uint32("ptr", ps, depth + 1, &dummy)) return
3686 False;
3689 if(!prs_uint32("command", ps, depth, &q_u->command))
3690 return False;
3692 return True;
3695 /*******************************************************************
3696 ********************************************************************/
3698 BOOL spoolss_io_r_fcpn(char *desc, SPOOL_R_FCPN *r_u, prs_struct *ps, int depth)
3700 prs_debug(ps, depth, desc, "spoolss_io_r_fcpn");
3701 depth++;
3703 if(!prs_align(ps))
3704 return False;
3706 if(!prs_werror("status", ps, depth, &r_u->status))
3707 return False;
3709 return True;
3712 /*******************************************************************
3713 ********************************************************************/
3715 BOOL spoolss_io_q_fcpn(char *desc, SPOOL_Q_FCPN *q_u, prs_struct *ps, int depth)
3718 prs_debug(ps, depth, desc, "spoolss_io_q_fcpn");
3719 depth++;
3721 if(!prs_align(ps))
3722 return False;
3724 if(!smb_io_pol_hnd("printer handle",&q_u->handle,ps,depth))
3725 return False;
3727 return True;
3731 /*******************************************************************
3732 ********************************************************************/
3734 BOOL spoolss_io_r_addjob(char *desc, SPOOL_R_ADDJOB *r_u, prs_struct *ps, int depth)
3736 prs_debug(ps, depth, desc, "");
3737 depth++;
3739 if(!prs_align(ps))
3740 return False;
3742 if(!spoolss_io_buffer("", ps, depth, &r_u->buffer))
3743 return False;
3745 if(!prs_align(ps))
3746 return False;
3748 if(!prs_uint32("needed", ps, depth, &r_u->needed))
3749 return False;
3751 if(!prs_werror("status", ps, depth, &r_u->status))
3752 return False;
3754 return True;
3757 /*******************************************************************
3758 ********************************************************************/
3760 BOOL spoolss_io_q_addjob(char *desc, SPOOL_Q_ADDJOB *q_u, prs_struct *ps, int depth)
3762 prs_debug(ps, depth, desc, "");
3763 depth++;
3765 if(!prs_align(ps))
3766 return False;
3768 if(!smb_io_pol_hnd("printer handle", &q_u->handle, ps, depth))
3769 return False;
3770 if(!prs_uint32("level", ps, depth, &q_u->level))
3771 return False;
3773 if(!spoolss_io_buffer("", ps, depth, &q_u->buffer))
3774 return False;
3776 if(!prs_align(ps))
3777 return False;
3779 if(!prs_uint32("offered", ps, depth, &q_u->offered))
3780 return False;
3782 return True;
3785 /*******************************************************************
3786 ********************************************************************/
3788 BOOL spoolss_io_r_enumjobs(char *desc, SPOOL_R_ENUMJOBS *r_u, prs_struct *ps, int depth)
3790 prs_debug(ps, depth, desc, "spoolss_io_r_enumjobs");
3791 depth++;
3793 if (!prs_align(ps))
3794 return False;
3796 if (!spoolss_io_buffer("", ps, depth, &r_u->buffer))
3797 return False;
3799 if (!prs_align(ps))
3800 return False;
3802 if (!prs_uint32("needed", ps, depth, &r_u->needed))
3803 return False;
3805 if (!prs_uint32("returned", ps, depth, &r_u->returned))
3806 return False;
3808 if (!prs_werror("status", ps, depth, &r_u->status))
3809 return False;
3811 return True;
3814 /*******************************************************************
3815 ********************************************************************/
3817 BOOL make_spoolss_q_enumjobs(SPOOL_Q_ENUMJOBS *q_u, const POLICY_HND *hnd,
3818 uint32 firstjob,
3819 uint32 numofjobs,
3820 uint32 level,
3821 NEW_BUFFER *buffer,
3822 uint32 offered)
3824 if (q_u == NULL)
3826 return False;
3828 memcpy(&q_u->handle, hnd, sizeof(q_u->handle));
3829 q_u->firstjob = firstjob;
3830 q_u->numofjobs = numofjobs;
3831 q_u->level = level;
3832 q_u->buffer= buffer;
3833 q_u->offered = offered;
3834 return True;
3837 /*******************************************************************
3838 ********************************************************************/
3840 BOOL spoolss_io_q_enumjobs(char *desc, SPOOL_Q_ENUMJOBS *q_u, prs_struct *ps, int depth)
3842 prs_debug(ps, depth, desc, "spoolss_io_q_enumjobs");
3843 depth++;
3845 if (!prs_align(ps))
3846 return False;
3848 if (!smb_io_pol_hnd("printer handle",&q_u->handle, ps, depth))
3849 return False;
3851 if (!prs_uint32("firstjob", ps, depth, &q_u->firstjob))
3852 return False;
3853 if (!prs_uint32("numofjobs", ps, depth, &q_u->numofjobs))
3854 return False;
3855 if (!prs_uint32("level", ps, depth, &q_u->level))
3856 return False;
3858 if (!spoolss_io_buffer("", ps, depth, &q_u->buffer))
3859 return False;
3861 if (!prs_uint32("offered", ps, depth, &q_u->offered))
3862 return False;
3864 return True;
3867 /*******************************************************************
3868 ********************************************************************/
3870 BOOL spoolss_io_r_schedulejob(char *desc, SPOOL_R_SCHEDULEJOB *r_u, prs_struct *ps, int depth)
3872 prs_debug(ps, depth, desc, "spoolss_io_r_schedulejob");
3873 depth++;
3875 if(!prs_align(ps))
3876 return False;
3878 if(!prs_werror("status", ps, depth, &r_u->status))
3879 return False;
3881 return True;
3884 /*******************************************************************
3885 ********************************************************************/
3887 BOOL spoolss_io_q_schedulejob(char *desc, SPOOL_Q_SCHEDULEJOB *q_u, prs_struct *ps, int depth)
3889 prs_debug(ps, depth, desc, "spoolss_io_q_schedulejob");
3890 depth++;
3892 if(!prs_align(ps))
3893 return False;
3895 if(!smb_io_pol_hnd("printer handle",&q_u->handle,ps,depth))
3896 return False;
3897 if(!prs_uint32("jobid", ps, depth, &q_u->jobid))
3898 return False;
3900 return True;
3903 /*******************************************************************
3904 ********************************************************************/
3906 BOOL spoolss_io_r_setjob(char *desc, SPOOL_R_SETJOB *r_u, prs_struct *ps, int depth)
3908 prs_debug(ps, depth, desc, "spoolss_io_r_setjob");
3909 depth++;
3911 if(!prs_align(ps))
3912 return False;
3914 if(!prs_werror("status", ps, depth, &r_u->status))
3915 return False;
3917 return True;
3920 /*******************************************************************
3921 ********************************************************************/
3923 BOOL spoolss_io_q_setjob(char *desc, SPOOL_Q_SETJOB *q_u, prs_struct *ps, int depth)
3925 prs_debug(ps, depth, desc, "spoolss_io_q_setjob");
3926 depth++;
3928 if(!prs_align(ps))
3929 return False;
3931 if(!smb_io_pol_hnd("printer handle",&q_u->handle,ps,depth))
3932 return False;
3933 if(!prs_uint32("jobid", ps, depth, &q_u->jobid))
3934 return False;
3936 * level is usually 0. If (level!=0) then I'm in trouble !
3937 * I will try to generate setjob command with level!=0, one day.
3939 if(!prs_uint32("level", ps, depth, &q_u->level))
3940 return False;
3941 if(!prs_uint32("command", ps, depth, &q_u->command))
3942 return False;
3944 return True;
3947 /*******************************************************************
3948 Parse a SPOOL_R_ENUMPRINTERDRIVERS structure.
3949 ********************************************************************/
3951 BOOL spoolss_io_r_enumprinterdrivers(char *desc, SPOOL_R_ENUMPRINTERDRIVERS *r_u, prs_struct *ps, int depth)
3953 prs_debug(ps, depth, desc, "spoolss_io_r_enumprinterdrivers");
3954 depth++;
3956 if (!prs_align(ps))
3957 return False;
3959 if (!spoolss_io_buffer("", ps, depth, &r_u->buffer))
3960 return False;
3962 if (!prs_align(ps))
3963 return False;
3965 if (!prs_uint32("needed", ps, depth, &r_u->needed))
3966 return False;
3968 if (!prs_uint32("returned", ps, depth, &r_u->returned))
3969 return False;
3971 if (!prs_werror("status", ps, depth, &r_u->status))
3972 return False;
3974 return True;
3977 /*******************************************************************
3978 * init a structure.
3979 ********************************************************************/
3981 BOOL make_spoolss_q_enumprinterdrivers(SPOOL_Q_ENUMPRINTERDRIVERS *q_u,
3982 const char *name,
3983 const char *environment,
3984 uint32 level,
3985 NEW_BUFFER *buffer, uint32 offered)
3987 init_buf_unistr2(&q_u->name, &q_u->name_ptr, name);
3988 init_buf_unistr2(&q_u->environment, &q_u->environment_ptr, environment);
3990 q_u->level=level;
3991 q_u->buffer=buffer;
3992 q_u->offered=offered;
3994 return True;
3997 /*******************************************************************
3998 Parse a SPOOL_Q_ENUMPRINTERDRIVERS structure.
3999 ********************************************************************/
4001 BOOL spoolss_io_q_enumprinterdrivers(char *desc, SPOOL_Q_ENUMPRINTERDRIVERS *q_u, prs_struct *ps, int depth)
4004 prs_debug(ps, depth, desc, "spoolss_io_q_enumprinterdrivers");
4005 depth++;
4007 if (!prs_align(ps))
4008 return False;
4010 if (!prs_uint32("name_ptr", ps, depth, &q_u->name_ptr))
4011 return False;
4012 if (!smb_io_unistr2("", &q_u->name, q_u->name_ptr,ps, depth))
4013 return False;
4015 if (!prs_align(ps))
4016 return False;
4017 if (!prs_uint32("environment_ptr", ps, depth, &q_u->environment_ptr))
4018 return False;
4019 if (!smb_io_unistr2("", &q_u->environment, q_u->environment_ptr, ps, depth))
4020 return False;
4022 if (!prs_align(ps))
4023 return False;
4024 if (!prs_uint32("level", ps, depth, &q_u->level))
4025 return False;
4027 if (!spoolss_io_buffer("", ps, depth, &q_u->buffer))
4028 return False;
4030 if (!prs_align(ps))
4031 return False;
4033 if (!prs_uint32("offered", ps, depth, &q_u->offered))
4034 return False;
4036 return True;
4039 /*******************************************************************
4040 ********************************************************************/
4042 BOOL spoolss_io_q_enumforms(char *desc, SPOOL_Q_ENUMFORMS *q_u, prs_struct *ps, int depth)
4045 prs_debug(ps, depth, desc, "spoolss_io_q_enumforms");
4046 depth++;
4048 if (!prs_align(ps))
4049 return False;
4050 if (!smb_io_pol_hnd("printer handle",&q_u->handle,ps,depth))
4051 return False;
4052 if (!prs_uint32("level", ps, depth, &q_u->level))
4053 return False;
4055 if (!spoolss_io_buffer("", ps, depth, &q_u->buffer))
4056 return False;
4058 if (!prs_align(ps))
4059 return False;
4060 if (!prs_uint32("offered", ps, depth, &q_u->offered))
4061 return False;
4063 return True;
4066 /*******************************************************************
4067 ********************************************************************/
4069 BOOL spoolss_io_r_enumforms(char *desc, SPOOL_R_ENUMFORMS *r_u, prs_struct *ps, int depth)
4071 prs_debug(ps, depth, desc, "spoolss_io_r_enumforms");
4072 depth++;
4074 if (!prs_align(ps))
4075 return False;
4077 if (!spoolss_io_buffer("", ps, depth, &r_u->buffer))
4078 return False;
4080 if (!prs_align(ps))
4081 return False;
4083 if (!prs_uint32("size of buffer needed", ps, depth, &r_u->needed))
4084 return False;
4086 if (!prs_uint32("numofforms", ps, depth, &r_u->numofforms))
4087 return False;
4089 if (!prs_werror("status", ps, depth, &r_u->status))
4090 return False;
4092 return True;
4095 /*******************************************************************
4096 ********************************************************************/
4098 BOOL spoolss_io_q_getform(char *desc, SPOOL_Q_GETFORM *q_u, prs_struct *ps, int depth)
4101 prs_debug(ps, depth, desc, "spoolss_io_q_getform");
4102 depth++;
4104 if (!prs_align(ps))
4105 return False;
4106 if (!smb_io_pol_hnd("printer handle",&q_u->handle,ps,depth))
4107 return False;
4108 if (!smb_io_unistr2("", &q_u->formname,True,ps,depth))
4109 return False;
4111 if (!prs_align(ps))
4112 return False;
4114 if (!prs_uint32("level", ps, depth, &q_u->level))
4115 return False;
4117 if (!spoolss_io_buffer("", ps, depth, &q_u->buffer))
4118 return False;
4120 if (!prs_align(ps))
4121 return False;
4122 if (!prs_uint32("offered", ps, depth, &q_u->offered))
4123 return False;
4125 return True;
4128 /*******************************************************************
4129 ********************************************************************/
4131 BOOL spoolss_io_r_getform(char *desc, SPOOL_R_GETFORM *r_u, prs_struct *ps, int depth)
4133 prs_debug(ps, depth, desc, "spoolss_io_r_getform");
4134 depth++;
4136 if (!prs_align(ps))
4137 return False;
4139 if (!spoolss_io_buffer("", ps, depth, &r_u->buffer))
4140 return False;
4142 if (!prs_align(ps))
4143 return False;
4145 if (!prs_uint32("size of buffer needed", ps, depth, &r_u->needed))
4146 return False;
4148 if (!prs_werror("status", ps, depth, &r_u->status))
4149 return False;
4151 return True;
4154 /*******************************************************************
4155 Parse a SPOOL_R_ENUMPORTS structure.
4156 ********************************************************************/
4158 BOOL spoolss_io_r_enumports(char *desc, SPOOL_R_ENUMPORTS *r_u, prs_struct *ps, int depth)
4160 prs_debug(ps, depth, desc, "spoolss_io_r_enumports");
4161 depth++;
4163 if (!prs_align(ps))
4164 return False;
4166 if (!spoolss_io_buffer("", ps, depth, &r_u->buffer))
4167 return False;
4169 if (!prs_align(ps))
4170 return False;
4172 if (!prs_uint32("needed", ps, depth, &r_u->needed))
4173 return False;
4175 if (!prs_uint32("returned", ps, depth, &r_u->returned))
4176 return False;
4178 if (!prs_werror("status", ps, depth, &r_u->status))
4179 return False;
4181 return True;
4184 /*******************************************************************
4185 ********************************************************************/
4187 BOOL spoolss_io_q_enumports(char *desc, SPOOL_Q_ENUMPORTS *q_u, prs_struct *ps, int depth)
4189 prs_debug(ps, depth, desc, "");
4190 depth++;
4192 if (!prs_align(ps))
4193 return False;
4195 if (!prs_uint32("", ps, depth, &q_u->name_ptr))
4196 return False;
4197 if (!smb_io_unistr2("", &q_u->name,True,ps,depth))
4198 return False;
4200 if (!prs_align(ps))
4201 return False;
4202 if (!prs_uint32("level", ps, depth, &q_u->level))
4203 return False;
4205 if (!spoolss_io_buffer("", ps, depth, &q_u->buffer))
4206 return False;
4208 if (!prs_align(ps))
4209 return False;
4210 if (!prs_uint32("offered", ps, depth, &q_u->offered))
4211 return False;
4213 return True;
4216 /*******************************************************************
4217 Parse a SPOOL_PRINTER_INFO_LEVEL_1 structure.
4218 ********************************************************************/
4220 BOOL spool_io_printer_info_level_1(char *desc, SPOOL_PRINTER_INFO_LEVEL_1 *il, prs_struct *ps, int depth)
4222 prs_debug(ps, depth, desc, "spool_io_printer_info_level_1");
4223 depth++;
4225 if(!prs_align(ps))
4226 return False;
4228 if(!prs_uint32("flags", ps, depth, &il->flags))
4229 return False;
4230 if(!prs_uint32("description_ptr", ps, depth, &il->description_ptr))
4231 return False;
4232 if(!prs_uint32("name_ptr", ps, depth, &il->name_ptr))
4233 return False;
4234 if(!prs_uint32("comment_ptr", ps, depth, &il->comment_ptr))
4235 return False;
4237 if(!smb_io_unistr2("description", &il->description, il->description_ptr, ps, depth))
4238 return False;
4239 if(!smb_io_unistr2("name", &il->name, il->name_ptr, ps, depth))
4240 return False;
4241 if(!smb_io_unistr2("comment", &il->comment, il->comment_ptr, ps, depth))
4242 return False;
4244 return True;
4247 /*******************************************************************
4248 Parse a SPOOL_PRINTER_INFO_LEVEL_3 structure.
4249 ********************************************************************/
4251 BOOL spool_io_printer_info_level_3(char *desc, SPOOL_PRINTER_INFO_LEVEL_3 *il, prs_struct *ps, int depth)
4253 prs_debug(ps, depth, desc, "spool_io_printer_info_level_3");
4254 depth++;
4256 if(!prs_align(ps))
4257 return False;
4259 if(!prs_uint32("secdesc_ptr", ps, depth, &il->secdesc_ptr))
4260 return False;
4262 return True;
4265 /*******************************************************************
4266 Parse a SPOOL_PRINTER_INFO_LEVEL_2 structure.
4267 ********************************************************************/
4269 BOOL spool_io_printer_info_level_2(char *desc, SPOOL_PRINTER_INFO_LEVEL_2 *il, prs_struct *ps, int depth)
4271 prs_debug(ps, depth, desc, "spool_io_printer_info_level_2");
4272 depth++;
4274 if(!prs_align(ps))
4275 return False;
4277 if(!prs_uint32("servername_ptr", ps, depth, &il->servername_ptr))
4278 return False;
4279 if(!prs_uint32("printername_ptr", ps, depth, &il->printername_ptr))
4280 return False;
4281 if(!prs_uint32("sharename_ptr", ps, depth, &il->sharename_ptr))
4282 return False;
4283 if(!prs_uint32("portname_ptr", ps, depth, &il->portname_ptr))
4284 return False;
4286 if(!prs_uint32("drivername_ptr", ps, depth, &il->drivername_ptr))
4287 return False;
4288 if(!prs_uint32("comment_ptr", ps, depth, &il->comment_ptr))
4289 return False;
4290 if(!prs_uint32("location_ptr", ps, depth, &il->location_ptr))
4291 return False;
4292 if(!prs_uint32("devmode_ptr", ps, depth, &il->devmode_ptr))
4293 return False;
4294 if(!prs_uint32("sepfile_ptr", ps, depth, &il->sepfile_ptr))
4295 return False;
4296 if(!prs_uint32("printprocessor_ptr", ps, depth, &il->printprocessor_ptr))
4297 return False;
4298 if(!prs_uint32("datatype_ptr", ps, depth, &il->datatype_ptr))
4299 return False;
4300 if(!prs_uint32("parameters_ptr", ps, depth, &il->parameters_ptr))
4301 return False;
4302 if(!prs_uint32("secdesc_ptr", ps, depth, &il->secdesc_ptr))
4303 return False;
4305 if(!prs_uint32("attributes", ps, depth, &il->attributes))
4306 return False;
4307 if(!prs_uint32("priority", ps, depth, &il->priority))
4308 return False;
4309 if(!prs_uint32("default_priority", ps, depth, &il->default_priority))
4310 return False;
4311 if(!prs_uint32("starttime", ps, depth, &il->starttime))
4312 return False;
4313 if(!prs_uint32("untiltime", ps, depth, &il->untiltime))
4314 return False;
4315 if(!prs_werror("status", ps, depth, &il->status))
4316 return False;
4317 if(!prs_uint32("cjobs", ps, depth, &il->cjobs))
4318 return False;
4319 if(!prs_uint32("averageppm", ps, depth, &il->averageppm))
4320 return False;
4322 if(!smb_io_unistr2("servername", &il->servername, il->servername_ptr, ps, depth))
4323 return False;
4324 if(!smb_io_unistr2("printername", &il->printername, il->printername_ptr, ps, depth))
4325 return False;
4326 if(!smb_io_unistr2("sharename", &il->sharename, il->sharename_ptr, ps, depth))
4327 return False;
4328 if(!smb_io_unistr2("portname", &il->portname, il->portname_ptr, ps, depth))
4329 return False;
4330 if(!smb_io_unistr2("drivername", &il->drivername, il->drivername_ptr, ps, depth))
4331 return False;
4332 if(!smb_io_unistr2("comment", &il->comment, il->comment_ptr, ps, depth))
4333 return False;
4334 if(!smb_io_unistr2("location", &il->location, il->location_ptr, ps, depth))
4335 return False;
4336 if(!smb_io_unistr2("sepfile", &il->sepfile, il->sepfile_ptr, ps, depth))
4337 return False;
4338 if(!smb_io_unistr2("printprocessor", &il->printprocessor, il->printprocessor_ptr, ps, depth))
4339 return False;
4340 if(!smb_io_unistr2("datatype", &il->datatype, il->datatype_ptr, ps, depth))
4341 return False;
4342 if(!smb_io_unistr2("parameters", &il->parameters, il->parameters_ptr, ps, depth))
4343 return False;
4345 return True;
4348 /*******************************************************************
4349 ********************************************************************/
4351 BOOL spool_io_printer_info_level(char *desc, SPOOL_PRINTER_INFO_LEVEL *il, prs_struct *ps, int depth)
4353 prs_debug(ps, depth, desc, "spool_io_printer_info_level");
4354 depth++;
4356 if(!prs_align(ps))
4357 return False;
4358 if(!prs_uint32("level", ps, depth, &il->level))
4359 return False;
4360 if(!prs_uint32("info_ptr", ps, depth, &il->info_ptr))
4361 return False;
4363 /* if no struct inside just return */
4364 if (il->info_ptr==0) {
4365 if (UNMARSHALLING(ps)) {
4366 il->info_1=NULL;
4367 il->info_2=NULL;
4369 return True;
4372 switch (il->level) {
4374 * level 0 is used by setprinter when managing the queue
4375 * (hold, stop, start a queue)
4377 case 0:
4378 break;
4379 /* DOCUMENT ME!!! What is level 1 used for? */
4380 case 1:
4382 if (UNMARSHALLING(ps)) {
4383 if ((il->info_1=(SPOOL_PRINTER_INFO_LEVEL_1 *)prs_alloc_mem(ps,sizeof(SPOOL_PRINTER_INFO_LEVEL_1))) == NULL)
4384 return False;
4386 if (!spool_io_printer_info_level_1("", il->info_1, ps, depth))
4387 return False;
4388 break;
4391 * level 2 is used by addprinter
4392 * and by setprinter when updating printer's info
4394 case 2:
4395 if (UNMARSHALLING(ps)) {
4396 if ((il->info_2=(SPOOL_PRINTER_INFO_LEVEL_2 *)prs_alloc_mem(ps,sizeof(SPOOL_PRINTER_INFO_LEVEL_2))) == NULL)
4397 return False;
4399 if (!spool_io_printer_info_level_2("", il->info_2, ps, depth))
4400 return False;
4401 break;
4402 /* DOCUMENT ME!!! What is level 3 used for? */
4403 case 3:
4405 if (UNMARSHALLING(ps)) {
4406 if ((il->info_3=(SPOOL_PRINTER_INFO_LEVEL_3 *)prs_alloc_mem(ps,sizeof(SPOOL_PRINTER_INFO_LEVEL_3))) == NULL)
4407 return False;
4409 if (!spool_io_printer_info_level_3("", il->info_3, ps, depth))
4410 return False;
4411 break;
4415 return True;
4418 /*******************************************************************
4419 ********************************************************************/
4421 BOOL spoolss_io_q_addprinterex(char *desc, SPOOL_Q_ADDPRINTEREX *q_u, prs_struct *ps, int depth)
4423 prs_debug(ps, depth, desc, "spoolss_io_q_addprinterex");
4424 depth++;
4426 if(!prs_align(ps))
4427 return False;
4428 if(!prs_uint32("", ps, depth, &q_u->server_name_ptr))
4429 return False;
4430 if(!smb_io_unistr2("", &q_u->server_name, q_u->server_name_ptr, ps, depth))
4431 return False;
4433 if(!prs_align(ps))
4434 return False;
4436 if(!prs_uint32("info_level", ps, depth, &q_u->level))
4437 return False;
4439 if(!spool_io_printer_info_level("", &q_u->info, ps, depth))
4440 return False;
4442 /* the 4 unknown are all 0 */
4445 * en fait ils sont pas inconnu
4446 * par recoupement avec rpcSetPrinter
4447 * c'est le devicemode
4448 * et le security descriptor.
4451 if(!prs_align(ps))
4452 return False;
4453 if(!prs_uint32("unk0", ps, depth, &q_u->unk0))
4454 return False;
4455 if(!prs_uint32("unk1", ps, depth, &q_u->unk1))
4456 return False;
4457 if(!prs_uint32("unk2", ps, depth, &q_u->unk2))
4458 return False;
4459 if(!prs_uint32("unk3", ps, depth, &q_u->unk3))
4460 return False;
4462 if(!prs_uint32("user_switch", ps, depth, &q_u->user_switch))
4463 return False;
4464 if(!spool_io_user_level("", &q_u->user_ctr, ps, depth))
4465 return False;
4467 return True;
4470 /*******************************************************************
4471 ********************************************************************/
4473 BOOL spoolss_io_r_addprinterex(char *desc, SPOOL_R_ADDPRINTEREX *r_u,
4474 prs_struct *ps, int depth)
4476 prs_debug(ps, depth, desc, "spoolss_io_r_addprinterex");
4477 depth++;
4479 if(!smb_io_pol_hnd("printer handle",&r_u->handle,ps,depth))
4480 return False;
4482 if(!prs_werror("status", ps, depth, &r_u->status))
4483 return False;
4485 return True;
4488 /*******************************************************************
4489 ********************************************************************/
4491 BOOL spool_io_printer_driver_info_level_3(char *desc, SPOOL_PRINTER_DRIVER_INFO_LEVEL_3 **q_u,
4492 prs_struct *ps, int depth)
4494 SPOOL_PRINTER_DRIVER_INFO_LEVEL_3 *il;
4496 prs_debug(ps, depth, desc, "spool_io_printer_driver_info_level_3");
4497 depth++;
4499 /* reading */
4500 if (UNMARSHALLING(ps)) {
4501 il=(SPOOL_PRINTER_DRIVER_INFO_LEVEL_3 *)prs_alloc_mem(ps,sizeof(SPOOL_PRINTER_DRIVER_INFO_LEVEL_3));
4502 if(il == NULL)
4503 return False;
4504 *q_u=il;
4506 else {
4507 il=*q_u;
4510 if(!prs_align(ps))
4511 return False;
4513 if(!prs_uint32("cversion", ps, depth, &il->cversion))
4514 return False;
4515 if(!prs_uint32("name", ps, depth, &il->name_ptr))
4516 return False;
4517 if(!prs_uint32("environment", ps, depth, &il->environment_ptr))
4518 return False;
4519 if(!prs_uint32("driverpath", ps, depth, &il->driverpath_ptr))
4520 return False;
4521 if(!prs_uint32("datafile", ps, depth, &il->datafile_ptr))
4522 return False;
4523 if(!prs_uint32("configfile", ps, depth, &il->configfile_ptr))
4524 return False;
4525 if(!prs_uint32("helpfile", ps, depth, &il->helpfile_ptr))
4526 return False;
4527 if(!prs_uint32("monitorname", ps, depth, &il->monitorname_ptr))
4528 return False;
4529 if(!prs_uint32("defaultdatatype", ps, depth, &il->defaultdatatype_ptr))
4530 return False;
4531 if(!prs_uint32("dependentfilessize", ps, depth, &il->dependentfilessize))
4532 return False;
4533 if(!prs_uint32("dependentfiles", ps, depth, &il->dependentfiles_ptr))
4534 return False;
4536 if(!prs_align(ps))
4537 return False;
4539 if(!smb_io_unistr2("name", &il->name, il->name_ptr, ps, depth))
4540 return False;
4541 if(!smb_io_unistr2("environment", &il->environment, il->environment_ptr, ps, depth))
4542 return False;
4543 if(!smb_io_unistr2("driverpath", &il->driverpath, il->driverpath_ptr, ps, depth))
4544 return False;
4545 if(!smb_io_unistr2("datafile", &il->datafile, il->datafile_ptr, ps, depth))
4546 return False;
4547 if(!smb_io_unistr2("configfile", &il->configfile, il->configfile_ptr, ps, depth))
4548 return False;
4549 if(!smb_io_unistr2("helpfile", &il->helpfile, il->helpfile_ptr, ps, depth))
4550 return False;
4551 if(!smb_io_unistr2("monitorname", &il->monitorname, il->monitorname_ptr, ps, depth))
4552 return False;
4553 if(!smb_io_unistr2("defaultdatatype", &il->defaultdatatype, il->defaultdatatype_ptr, ps, depth))
4554 return False;
4556 if(!prs_align(ps))
4557 return False;
4559 if (il->dependentfiles_ptr)
4560 smb_io_buffer5("", &il->dependentfiles, ps, depth);
4562 return True;
4565 /*******************************************************************
4566 parse a SPOOL_PRINTER_DRIVER_INFO_LEVEL_6 structure
4567 ********************************************************************/
4569 BOOL spool_io_printer_driver_info_level_6(char *desc, SPOOL_PRINTER_DRIVER_INFO_LEVEL_6 **q_u,
4570 prs_struct *ps, int depth)
4572 SPOOL_PRINTER_DRIVER_INFO_LEVEL_6 *il;
4574 prs_debug(ps, depth, desc, "spool_io_printer_driver_info_level_6");
4575 depth++;
4577 /* reading */
4578 if (UNMARSHALLING(ps)) {
4579 il=(SPOOL_PRINTER_DRIVER_INFO_LEVEL_6 *)prs_alloc_mem(ps,sizeof(SPOOL_PRINTER_DRIVER_INFO_LEVEL_6));
4580 if(il == NULL)
4581 return False;
4582 *q_u=il;
4584 else {
4585 il=*q_u;
4588 if(!prs_align(ps))
4589 return False;
4592 /* parse the main elements the packet */
4594 if(!prs_uint32("version", ps, depth, &il->version))
4595 return False;
4597 if(!prs_uint32("name_ptr", ps, depth, &il->name_ptr))
4598 return False;
4600 * If name_ptr is NULL then the next 4 bytes are the name_ptr. A driver
4601 * with a NULL name just isn't a driver For example: "HP LaserJet 4si"
4602 * from W2K CDROM (which uses unidriver). JohnR 010205
4604 if (!il->name_ptr) {
4605 DEBUG(5,("spool_io_printer_driver_info_level_6: name_ptr is NULL! Get next value\n"));
4606 if(!prs_uint32("name_ptr", ps, depth, &il->name_ptr))
4607 return False;
4610 if(!prs_uint32("environment_ptr", ps, depth, &il->environment_ptr))
4611 return False;
4612 if(!prs_uint32("driverpath_ptr", ps, depth, &il->driverpath_ptr))
4613 return False;
4614 if(!prs_uint32("datafile_ptr", ps, depth, &il->datafile_ptr))
4615 return False;
4616 if(!prs_uint32("configfile_ptr", ps, depth, &il->configfile_ptr))
4617 return False;
4618 if(!prs_uint32("helpfile_ptr", ps, depth, &il->helpfile_ptr))
4619 return False;
4620 if(!prs_uint32("monitorname_ptr", ps, depth, &il->monitorname_ptr))
4621 return False;
4622 if(!prs_uint32("defaultdatatype_ptr", ps, depth, &il->defaultdatatype_ptr))
4623 return False;
4624 if(!prs_uint32("dependentfiles_len", ps, depth, &il->dependentfiles_len))
4625 return False;
4626 if(!prs_uint32("dependentfiles_ptr", ps, depth, &il->dependentfiles_ptr))
4627 return False;
4628 if(!prs_uint32("previousnames_len", ps, depth, &il->previousnames_len))
4629 return False;
4630 if(!prs_uint32("previousnames_ptr", ps, depth, &il->previousnames_ptr))
4631 return False;
4632 if(!smb_io_time("driverdate", &il->driverdate, ps, depth))
4633 return False;
4634 if(!prs_uint32("dummy4", ps, depth, &il->dummy4))
4635 return False;
4636 if(!prs_uint64("driverversion", ps, depth, &il->driverversion))
4637 return False;
4638 if(!prs_uint32("mfgname_ptr", ps, depth, &il->mfgname_ptr))
4639 return False;
4640 if(!prs_uint32("oemurl_ptr", ps, depth, &il->oemurl_ptr))
4641 return False;
4642 if(!prs_uint32("hardwareid_ptr", ps, depth, &il->hardwareid_ptr))
4643 return False;
4644 if(!prs_uint32("provider_ptr", ps, depth, &il->provider_ptr))
4645 return False;
4647 /* parse the structures in the packet */
4649 if(!smb_io_unistr2("name", &il->name, il->name_ptr, ps, depth))
4650 return False;
4651 if(!prs_align(ps))
4652 return False;
4654 if(!smb_io_unistr2("environment", &il->environment, il->environment_ptr, ps, depth))
4655 return False;
4656 if(!prs_align(ps))
4657 return False;
4659 if(!smb_io_unistr2("driverpath", &il->driverpath, il->driverpath_ptr, ps, depth))
4660 return False;
4661 if(!prs_align(ps))
4662 return False;
4664 if(!smb_io_unistr2("datafile", &il->datafile, il->datafile_ptr, ps, depth))
4665 return False;
4666 if(!prs_align(ps))
4667 return False;
4669 if(!smb_io_unistr2("configfile", &il->configfile, il->configfile_ptr, ps, depth))
4670 return False;
4671 if(!prs_align(ps))
4672 return False;
4674 if(!smb_io_unistr2("helpfile", &il->helpfile, il->helpfile_ptr, ps, depth))
4675 return False;
4676 if(!prs_align(ps))
4677 return False;
4679 if(!smb_io_unistr2("monitorname", &il->monitorname, il->monitorname_ptr, ps, depth))
4680 return False;
4681 if(!prs_align(ps))
4682 return False;
4684 if(!smb_io_unistr2("defaultdatatype", &il->defaultdatatype, il->defaultdatatype_ptr, ps, depth))
4685 return False;
4686 if(!prs_align(ps))
4687 return False;
4688 if (il->dependentfiles_ptr) {
4689 if(!smb_io_buffer5("dependentfiles", &il->dependentfiles, ps, depth))
4690 return False;
4691 if(!prs_align(ps))
4692 return False;
4694 if (il->previousnames_ptr) {
4695 if(!smb_io_buffer5("previousnames", &il->previousnames, ps, depth))
4696 return False;
4697 if(!prs_align(ps))
4698 return False;
4700 if(!smb_io_unistr2("mfgname", &il->mfgname, il->mfgname_ptr, ps, depth))
4701 return False;
4702 if(!prs_align(ps))
4703 return False;
4704 if(!smb_io_unistr2("oemurl", &il->oemurl, il->oemurl_ptr, ps, depth))
4705 return False;
4706 if(!prs_align(ps))
4707 return False;
4708 if(!smb_io_unistr2("hardwareid", &il->hardwareid, il->hardwareid_ptr, ps, depth))
4709 return False;
4710 if(!prs_align(ps))
4711 return False;
4712 if(!smb_io_unistr2("provider", &il->provider, il->provider_ptr, ps, depth))
4713 return False;
4715 return True;
4718 /*******************************************************************
4719 convert a buffer of UNICODE strings null terminated
4720 the buffer is terminated by a NULL
4722 convert to an dos codepage array (null terminated)
4724 dynamically allocate memory
4726 ********************************************************************/
4727 static BOOL uniarray_2_dosarray(BUFFER5 *buf5, fstring **ar)
4729 fstring f, *tar;
4730 int n = 0;
4731 char *src;
4733 if (buf5==NULL)
4734 return False;
4736 src = (char *)buf5->buffer;
4737 *ar = NULL;
4739 while (src < ((char *)buf5->buffer) + buf5->buf_len*2) {
4740 unistr_to_dos(f, src, sizeof(f)-1);
4741 src = skip_unibuf(src, 2*buf5->buf_len - PTR_DIFF(src,buf5->buffer));
4742 tar = (fstring *)Realloc(*ar, sizeof(fstring)*(n+2));
4743 if (!tar)
4744 return False;
4745 else
4746 *ar = tar;
4747 fstrcpy((*ar)[n], f);
4748 n++;
4750 fstrcpy((*ar)[n], "");
4752 return True;
4758 /*******************************************************************
4759 read a UNICODE array with null terminated strings
4760 and null terminated array
4761 and size of array at beginning
4762 ********************************************************************/
4764 BOOL smb_io_unibuffer(char *desc, UNISTR2 *buffer, prs_struct *ps, int depth)
4766 if (buffer==NULL) return False;
4768 buffer->undoc=0;
4769 buffer->uni_str_len=buffer->uni_max_len;
4771 if(!prs_uint32("buffer_size", ps, depth, &buffer->uni_max_len))
4772 return False;
4774 if(!prs_unistr2(True, "buffer ", ps, depth, buffer))
4775 return False;
4777 return True;
4780 /*******************************************************************
4781 ********************************************************************/
4783 BOOL spool_io_printer_driver_info_level(char *desc, SPOOL_PRINTER_DRIVER_INFO_LEVEL *il, prs_struct *ps, int depth)
4785 prs_debug(ps, depth, desc, "spool_io_printer_driver_info_level");
4786 depth++;
4788 if(!prs_align(ps))
4789 return False;
4790 if(!prs_uint32("level", ps, depth, &il->level))
4791 return False;
4792 if(!prs_uint32("ptr", ps, depth, &il->ptr))
4793 return False;
4795 if (il->ptr==0)
4796 return True;
4798 switch (il->level) {
4799 case 3:
4800 if(!spool_io_printer_driver_info_level_3("", &il->info_3, ps, depth))
4801 return False;
4802 break;
4803 case 6:
4804 if(!spool_io_printer_driver_info_level_6("", &il->info_6, ps, depth))
4805 return False;
4806 break;
4807 default:
4808 return False;
4811 return True;
4814 /*******************************************************************
4815 init a SPOOL_Q_ADDPRINTERDRIVER struct
4816 ******************************************************************/
4818 BOOL make_spoolss_q_addprinterdriver(
4819 TALLOC_CTX *mem_ctx,
4820 SPOOL_Q_ADDPRINTERDRIVER *q_u,
4821 const char* srv_name,
4822 uint32 level,
4823 PRINTER_DRIVER_CTR *info)
4825 DEBUG(5,("make_spoolss_q_addprinterdriver\n"));
4827 q_u->server_name_ptr = (srv_name!=NULL)?1:0;
4828 init_unistr2(&q_u->server_name, srv_name, strlen(srv_name)+1);
4830 q_u->level = level;
4832 q_u->info.level = level;
4833 q_u->info.ptr = (info!=NULL)?1:0;
4834 switch (level)
4836 /* info level 3 is supported by Windows 95/98, WinNT and Win2k */
4837 case 3 :
4838 make_spoolss_driver_info_3(mem_ctx, &q_u->info.info_3, info->info3);
4839 break;
4841 /* info level 6 is supported by WinME and Win2k */
4842 case 6:
4843 /* WRITEME!! will add later --jerry */
4844 break;
4846 default:
4847 DEBUG(0,("make_spoolss_q_addprinterdriver: Unknown info level [%d]\n", level));
4848 break;
4851 return True;
4854 BOOL make_spoolss_driver_info_3(
4855 TALLOC_CTX *mem_ctx,
4856 SPOOL_PRINTER_DRIVER_INFO_LEVEL_3 **spool_drv_info,
4857 DRIVER_INFO_3 *info3
4860 uint32 len = 0;
4861 uint16 *ptr = info3->dependentfiles;
4862 BOOL done = False;
4863 BOOL null_char = False;
4864 SPOOL_PRINTER_DRIVER_INFO_LEVEL_3 *inf;
4866 if (!(inf=(SPOOL_PRINTER_DRIVER_INFO_LEVEL_3*)talloc_zero(mem_ctx, sizeof(SPOOL_PRINTER_DRIVER_INFO_LEVEL_3))))
4867 return False;
4869 inf->cversion = info3->version;
4870 inf->name_ptr = (info3->name.buffer!=NULL)?1:0;
4871 inf->environment_ptr = (info3->architecture.buffer!=NULL)?1:0;
4872 inf->driverpath_ptr = (info3->driverpath.buffer!=NULL)?1:0;
4873 inf->datafile_ptr = (info3->datafile.buffer!=NULL)?1:0;
4874 inf->configfile_ptr = (info3->configfile.buffer!=NULL)?1:0;
4875 inf->helpfile_ptr = (info3->helpfile.buffer!=NULL)?1:0;
4876 inf->monitorname_ptr = (info3->monitorname.buffer!=NULL)?1:0;
4877 inf->defaultdatatype_ptr = (info3->defaultdatatype.buffer!=NULL)?1:0;
4879 init_unistr2_from_unistr(&inf->name, &info3->name);
4880 init_unistr2_from_unistr(&inf->environment, &info3->architecture);
4881 init_unistr2_from_unistr(&inf->driverpath, &info3->driverpath);
4882 init_unistr2_from_unistr(&inf->datafile, &info3->datafile);
4883 init_unistr2_from_unistr(&inf->configfile, &info3->configfile);
4884 init_unistr2_from_unistr(&inf->helpfile, &info3->helpfile);
4885 init_unistr2_from_unistr(&inf->monitorname, &info3->monitorname);
4886 init_unistr2_from_unistr(&inf->defaultdatatype, &info3->defaultdatatype);
4888 while (!done)
4890 switch (*ptr)
4892 case 0:
4893 /* the null_char BOOL is used to help locate
4894 two '\0's back to back */
4895 if (null_char)
4896 done = True;
4897 else
4898 null_char = True;
4899 break;
4901 default:
4902 null_char = False;
4904 break;
4906 len++;
4907 ptr++;
4909 inf->dependentfiles_ptr = (info3->dependentfiles != NULL) ? 1 : 0;
4910 inf->dependentfilessize = len;
4911 if(!make_spoolss_buffer5(mem_ctx, &inf->dependentfiles, len, info3->dependentfiles))
4913 SAFE_FREE(inf);
4914 return False;
4917 *spool_drv_info = inf;
4919 return True;
4922 /*******************************************************************
4923 make a BUFFER5 struct from a uint16*
4924 ******************************************************************/
4925 BOOL make_spoolss_buffer5(TALLOC_CTX *mem_ctx, BUFFER5 *buf5, uint32 len, uint16 *src)
4928 buf5->buf_len = len;
4929 if((buf5->buffer=(uint16*)talloc_memdup(mem_ctx, src, sizeof(uint16)*len)) == NULL)
4931 DEBUG(0,("make_spoolss_buffer5: Unable to malloc memory for buffer!\n"));
4932 return False;
4935 return True;
4938 /*******************************************************************
4939 fill in the prs_struct for a ADDPRINTERDRIVER request PDU
4940 ********************************************************************/
4942 BOOL spoolss_io_q_addprinterdriver(char *desc, SPOOL_Q_ADDPRINTERDRIVER *q_u, prs_struct *ps, int depth)
4944 prs_debug(ps, depth, desc, "spoolss_io_q_addprinterdriver");
4945 depth++;
4947 if(!prs_align(ps))
4948 return False;
4950 if(!prs_uint32("server_name_ptr", ps, depth, &q_u->server_name_ptr))
4951 return False;
4952 if(!smb_io_unistr2("server_name", &q_u->server_name, q_u->server_name_ptr, ps, depth))
4953 return False;
4955 if(!prs_align(ps))
4956 return False;
4957 if(!prs_uint32("info_level", ps, depth, &q_u->level))
4958 return False;
4960 if(!spool_io_printer_driver_info_level("", &q_u->info, ps, depth))
4961 return False;
4963 return True;
4966 /*******************************************************************
4967 ********************************************************************/
4969 BOOL spoolss_io_r_addprinterdriver(char *desc, SPOOL_R_ADDPRINTERDRIVER *q_u, prs_struct *ps, int depth)
4971 prs_debug(ps, depth, desc, "spoolss_io_r_addprinterdriver");
4972 depth++;
4974 if(!prs_werror("status", ps, depth, &q_u->status))
4975 return False;
4977 return True;
4980 /*******************************************************************
4981 ********************************************************************/
4983 BOOL uni_2_asc_printer_driver_3(SPOOL_PRINTER_DRIVER_INFO_LEVEL_3 *uni,
4984 NT_PRINTER_DRIVER_INFO_LEVEL_3 **asc)
4986 NT_PRINTER_DRIVER_INFO_LEVEL_3 *d;
4988 DEBUG(7,("uni_2_asc_printer_driver_3: Converting from UNICODE to ASCII\n"));
4990 if (*asc==NULL)
4992 *asc=(NT_PRINTER_DRIVER_INFO_LEVEL_3 *)malloc(sizeof(NT_PRINTER_DRIVER_INFO_LEVEL_3));
4993 if(*asc == NULL)
4994 return False;
4995 ZERO_STRUCTP(*asc);
4998 d=*asc;
5000 d->cversion=uni->cversion;
5002 unistr2_to_ascii(d->name, &uni->name, sizeof(d->name)-1);
5003 unistr2_to_ascii(d->environment, &uni->environment, sizeof(d->environment)-1);
5004 unistr2_to_ascii(d->driverpath, &uni->driverpath, sizeof(d->driverpath)-1);
5005 unistr2_to_ascii(d->datafile, &uni->datafile, sizeof(d->datafile)-1);
5006 unistr2_to_ascii(d->configfile, &uni->configfile, sizeof(d->configfile)-1);
5007 unistr2_to_ascii(d->helpfile, &uni->helpfile, sizeof(d->helpfile)-1);
5008 unistr2_to_ascii(d->monitorname, &uni->monitorname, sizeof(d->monitorname)-1);
5009 unistr2_to_ascii(d->defaultdatatype, &uni->defaultdatatype, sizeof(d->defaultdatatype)-1);
5011 DEBUGADD(8,( "version: %d\n", d->cversion));
5012 DEBUGADD(8,( "name: %s\n", d->name));
5013 DEBUGADD(8,( "environment: %s\n", d->environment));
5014 DEBUGADD(8,( "driverpath: %s\n", d->driverpath));
5015 DEBUGADD(8,( "datafile: %s\n", d->datafile));
5016 DEBUGADD(8,( "configfile: %s\n", d->configfile));
5017 DEBUGADD(8,( "helpfile: %s\n", d->helpfile));
5018 DEBUGADD(8,( "monitorname: %s\n", d->monitorname));
5019 DEBUGADD(8,( "defaultdatatype: %s\n", d->defaultdatatype));
5021 if (uniarray_2_dosarray(&uni->dependentfiles, &d->dependentfiles ))
5022 return True;
5024 SAFE_FREE(*asc);
5025 return False;
5028 /*******************************************************************
5029 ********************************************************************/
5030 BOOL uni_2_asc_printer_driver_6(SPOOL_PRINTER_DRIVER_INFO_LEVEL_6 *uni,
5031 NT_PRINTER_DRIVER_INFO_LEVEL_6 **asc)
5033 NT_PRINTER_DRIVER_INFO_LEVEL_6 *d;
5035 DEBUG(7,("uni_2_asc_printer_driver_6: Converting from UNICODE to ASCII\n"));
5037 if (*asc==NULL)
5039 *asc=(NT_PRINTER_DRIVER_INFO_LEVEL_6 *)malloc(sizeof(NT_PRINTER_DRIVER_INFO_LEVEL_6));
5040 if(*asc == NULL)
5041 return False;
5042 ZERO_STRUCTP(*asc);
5045 d=*asc;
5047 d->version=uni->version;
5049 unistr2_to_ascii(d->name, &uni->name, sizeof(d->name)-1);
5050 unistr2_to_ascii(d->environment, &uni->environment, sizeof(d->environment)-1);
5051 unistr2_to_ascii(d->driverpath, &uni->driverpath, sizeof(d->driverpath)-1);
5052 unistr2_to_ascii(d->datafile, &uni->datafile, sizeof(d->datafile)-1);
5053 unistr2_to_ascii(d->configfile, &uni->configfile, sizeof(d->configfile)-1);
5054 unistr2_to_ascii(d->helpfile, &uni->helpfile, sizeof(d->helpfile)-1);
5055 unistr2_to_ascii(d->monitorname, &uni->monitorname, sizeof(d->monitorname)-1);
5056 unistr2_to_ascii(d->defaultdatatype, &uni->defaultdatatype, sizeof(d->defaultdatatype)-1);
5058 DEBUGADD(8,( "version: %d\n", d->version));
5059 DEBUGADD(8,( "name: %s\n", d->name));
5060 DEBUGADD(8,( "environment: %s\n", d->environment));
5061 DEBUGADD(8,( "driverpath: %s\n", d->driverpath));
5062 DEBUGADD(8,( "datafile: %s\n", d->datafile));
5063 DEBUGADD(8,( "configfile: %s\n", d->configfile));
5064 DEBUGADD(8,( "helpfile: %s\n", d->helpfile));
5065 DEBUGADD(8,( "monitorname: %s\n", d->monitorname));
5066 DEBUGADD(8,( "defaultdatatype: %s\n", d->defaultdatatype));
5068 if (!uniarray_2_dosarray(&uni->dependentfiles, &d->dependentfiles ))
5069 goto error;
5070 if (!uniarray_2_dosarray(&uni->previousnames, &d->previousnames ))
5071 goto error;
5073 return True;
5075 error:
5076 SAFE_FREE(*asc);
5077 return False;
5080 BOOL uni_2_asc_printer_info_2(const SPOOL_PRINTER_INFO_LEVEL_2 *uni,
5081 NT_PRINTER_INFO_LEVEL_2 **asc)
5083 NT_PRINTER_INFO_LEVEL_2 *d;
5084 time_t time_unix;
5086 DEBUG(7,("Converting from UNICODE to ASCII\n"));
5087 time_unix=time(NULL);
5089 if (*asc==NULL) {
5090 DEBUGADD(8,("allocating memory\n"));
5092 *asc=(NT_PRINTER_INFO_LEVEL_2 *)malloc(sizeof(NT_PRINTER_INFO_LEVEL_2));
5093 if(*asc == NULL)
5094 return False;
5095 ZERO_STRUCTP(*asc);
5097 /* we allocate memory iff called from
5098 * addprinter(ex) so we can do one time stuff here.
5100 (*asc)->setuptime=time_unix;
5103 DEBUGADD(8,("start converting\n"));
5105 d=*asc;
5107 d->attributes=uni->attributes;
5108 d->priority=uni->priority;
5109 d->default_priority=uni->default_priority;
5110 d->starttime=uni->starttime;
5111 d->untiltime=uni->untiltime;
5112 d->status=uni->status;
5113 d->cjobs=uni->cjobs;
5115 unistr2_to_ascii(d->servername, &uni->servername, sizeof(d->servername)-1);
5116 unistr2_to_ascii(d->printername, &uni->printername, sizeof(d->printername)-1);
5117 unistr2_to_ascii(d->sharename, &uni->sharename, sizeof(d->sharename)-1);
5118 unistr2_to_ascii(d->portname, &uni->portname, sizeof(d->portname)-1);
5119 unistr2_to_ascii(d->drivername, &uni->drivername, sizeof(d->drivername)-1);
5120 unistr2_to_ascii(d->comment, &uni->comment, sizeof(d->comment)-1);
5121 unistr2_to_ascii(d->location, &uni->location, sizeof(d->location)-1);
5122 unistr2_to_ascii(d->sepfile, &uni->sepfile, sizeof(d->sepfile)-1);
5123 unistr2_to_ascii(d->printprocessor, &uni->printprocessor, sizeof(d->printprocessor)-1);
5124 unistr2_to_ascii(d->datatype, &uni->datatype, sizeof(d->datatype)-1);
5125 unistr2_to_ascii(d->parameters, &uni->parameters, sizeof(d->parameters)-1);
5127 return True;
5130 /*******************************************************************
5131 * init a structure.
5132 ********************************************************************/
5134 BOOL make_spoolss_q_getprinterdriverdir(SPOOL_Q_GETPRINTERDRIVERDIR *q_u,
5135 fstring servername, fstring env_name, uint32 level,
5136 NEW_BUFFER *buffer, uint32 offered)
5138 init_buf_unistr2(&q_u->name, &q_u->name_ptr, servername);
5139 init_buf_unistr2(&q_u->environment, &q_u->environment_ptr, env_name);
5141 q_u->level=level;
5142 q_u->buffer=buffer;
5143 q_u->offered=offered;
5145 return True;
5148 /*******************************************************************
5149 Parse a SPOOL_Q_GETPRINTERDRIVERDIR structure.
5150 ********************************************************************/
5152 BOOL spoolss_io_q_getprinterdriverdir(char *desc, SPOOL_Q_GETPRINTERDRIVERDIR *q_u, prs_struct *ps, int depth)
5154 prs_debug(ps, depth, desc, "spoolss_io_q_getprinterdriverdir");
5155 depth++;
5157 if(!prs_align(ps))
5158 return False;
5159 if(!prs_uint32("name_ptr", ps, depth, &q_u->name_ptr))
5160 return False;
5161 if(!smb_io_unistr2("", &q_u->name, q_u->name_ptr, ps, depth))
5162 return False;
5164 if(!prs_align(ps))
5165 return False;
5167 if(!prs_uint32("", ps, depth, &q_u->environment_ptr))
5168 return False;
5169 if(!smb_io_unistr2("", &q_u->environment, q_u->environment_ptr, ps, depth))
5170 return False;
5172 if(!prs_align(ps))
5173 return False;
5175 if(!prs_uint32("level", ps, depth, &q_u->level))
5176 return False;
5178 if(!spoolss_io_buffer("", ps, depth, &q_u->buffer))
5179 return False;
5181 if(!prs_align(ps))
5182 return False;
5184 if(!prs_uint32("offered", ps, depth, &q_u->offered))
5185 return False;
5187 return True;
5190 /*******************************************************************
5191 Parse a SPOOL_R_GETPRINTERDRIVERDIR structure.
5192 ********************************************************************/
5194 BOOL spoolss_io_r_getprinterdriverdir(char *desc, SPOOL_R_GETPRINTERDRIVERDIR *r_u, prs_struct *ps, int depth)
5196 prs_debug(ps, depth, desc, "spoolss_io_r_getprinterdriverdir");
5197 depth++;
5199 if (!prs_align(ps))
5200 return False;
5202 if (!spoolss_io_buffer("", ps, depth, &r_u->buffer))
5203 return False;
5205 if (!prs_align(ps))
5206 return False;
5208 if (!prs_uint32("needed", ps, depth, &r_u->needed))
5209 return False;
5211 if (!prs_werror("status", ps, depth, &r_u->status))
5212 return False;
5214 return True;
5217 /*******************************************************************
5218 ********************************************************************/
5220 BOOL spoolss_io_r_enumprintprocessors(char *desc, SPOOL_R_ENUMPRINTPROCESSORS *r_u, prs_struct *ps, int depth)
5222 prs_debug(ps, depth, desc, "spoolss_io_r_enumprintprocessors");
5223 depth++;
5225 if (!prs_align(ps))
5226 return False;
5228 if (!spoolss_io_buffer("", ps, depth, &r_u->buffer))
5229 return False;
5231 if (!prs_align(ps))
5232 return False;
5234 if (!prs_uint32("needed", ps, depth, &r_u->needed))
5235 return False;
5237 if (!prs_uint32("returned", ps, depth, &r_u->returned))
5238 return False;
5240 if (!prs_werror("status", ps, depth, &r_u->status))
5241 return False;
5243 return True;
5246 /*******************************************************************
5247 ********************************************************************/
5249 BOOL spoolss_io_q_enumprintprocessors(char *desc, SPOOL_Q_ENUMPRINTPROCESSORS *q_u, prs_struct *ps, int depth)
5251 prs_debug(ps, depth, desc, "spoolss_io_q_enumprintprocessors");
5252 depth++;
5254 if (!prs_align(ps))
5255 return False;
5257 if (!prs_uint32("name_ptr", ps, depth, &q_u->name_ptr))
5258 return False;
5259 if (!smb_io_unistr2("name", &q_u->name, True, ps, depth))
5260 return False;
5262 if (!prs_align(ps))
5263 return False;
5265 if (!prs_uint32("", ps, depth, &q_u->environment_ptr))
5266 return False;
5267 if (!smb_io_unistr2("", &q_u->environment, q_u->environment_ptr, ps, depth))
5268 return False;
5270 if (!prs_align(ps))
5271 return False;
5273 if (!prs_uint32("level", ps, depth, &q_u->level))
5274 return False;
5276 if(!spoolss_io_buffer("", ps, depth, &q_u->buffer))
5277 return False;
5279 if (!prs_align(ps))
5280 return False;
5282 if (!prs_uint32("offered", ps, depth, &q_u->offered))
5283 return False;
5285 return True;
5288 /*******************************************************************
5289 ********************************************************************/
5291 BOOL spoolss_io_q_addprintprocessor(char *desc, SPOOL_Q_ADDPRINTPROCESSOR *q_u, prs_struct *ps, int depth)
5293 prs_debug(ps, depth, desc, "spoolss_io_q_addprintprocessor");
5294 depth++;
5296 if (!prs_align(ps))
5297 return False;
5299 if (!prs_uint32("server_ptr", ps, depth, &q_u->server_ptr))
5300 return False;
5301 if (!smb_io_unistr2("server", &q_u->server, q_u->server_ptr, ps, depth))
5302 return False;
5304 if (!prs_align(ps))
5305 return False;
5306 if (!smb_io_unistr2("environment", &q_u->environment, True, ps, depth))
5307 return False;
5309 if (!prs_align(ps))
5310 return False;
5311 if (!smb_io_unistr2("path", &q_u->path, True, ps, depth))
5312 return False;
5314 if (!prs_align(ps))
5315 return False;
5316 if (!smb_io_unistr2("name", &q_u->name, True, ps, depth))
5317 return False;
5319 return True;
5322 /*******************************************************************
5323 ********************************************************************/
5325 BOOL spoolss_io_r_addprintprocessor(char *desc, SPOOL_R_ADDPRINTPROCESSOR *r_u, prs_struct *ps, int depth)
5327 prs_debug(ps, depth, desc, "spoolss_io_r_addprintproicessor");
5328 depth++;
5330 if (!prs_align(ps))
5331 return False;
5333 if (!prs_werror("status", ps, depth, &r_u->status))
5334 return False;
5336 return True;
5339 /*******************************************************************
5340 ********************************************************************/
5342 BOOL spoolss_io_r_enumprintprocdatatypes(char *desc, SPOOL_R_ENUMPRINTPROCDATATYPES *r_u, prs_struct *ps, int depth)
5344 prs_debug(ps, depth, desc, "spoolss_io_r_enumprintprocdatatypes");
5345 depth++;
5347 if (!prs_align(ps))
5348 return False;
5350 if (!spoolss_io_buffer("", ps, depth, &r_u->buffer))
5351 return False;
5353 if (!prs_align(ps))
5354 return False;
5356 if (!prs_uint32("needed", ps, depth, &r_u->needed))
5357 return False;
5359 if (!prs_uint32("returned", ps, depth, &r_u->returned))
5360 return False;
5362 if (!prs_werror("status", ps, depth, &r_u->status))
5363 return False;
5365 return True;
5368 /*******************************************************************
5369 ********************************************************************/
5371 BOOL spoolss_io_q_enumprintprocdatatypes(char *desc, SPOOL_Q_ENUMPRINTPROCDATATYPES *q_u, prs_struct *ps, int depth)
5373 prs_debug(ps, depth, desc, "spoolss_io_q_enumprintprocdatatypes");
5374 depth++;
5376 if (!prs_align(ps))
5377 return False;
5379 if (!prs_uint32("name_ptr", ps, depth, &q_u->name_ptr))
5380 return False;
5381 if (!smb_io_unistr2("name", &q_u->name, True, ps, depth))
5382 return False;
5384 if (!prs_align(ps))
5385 return False;
5387 if (!prs_uint32("processor_ptr", ps, depth, &q_u->processor_ptr))
5388 return False;
5389 if (!smb_io_unistr2("processor", &q_u->processor, q_u->processor_ptr, ps, depth))
5390 return False;
5392 if (!prs_align(ps))
5393 return False;
5395 if (!prs_uint32("level", ps, depth, &q_u->level))
5396 return False;
5398 if(!spoolss_io_buffer("buffer", ps, depth, &q_u->buffer))
5399 return False;
5401 if (!prs_align(ps))
5402 return False;
5404 if (!prs_uint32("offered", ps, depth, &q_u->offered))
5405 return False;
5407 return True;
5410 /*******************************************************************
5411 Parse a SPOOL_Q_ENUMPRINTMONITORS structure.
5412 ********************************************************************/
5414 BOOL spoolss_io_q_enumprintmonitors(char *desc, SPOOL_Q_ENUMPRINTMONITORS *q_u, prs_struct *ps, int depth)
5416 prs_debug(ps, depth, desc, "spoolss_io_q_enumprintmonitors");
5417 depth++;
5419 if (!prs_align(ps))
5420 return False;
5422 if (!prs_uint32("name_ptr", ps, depth, &q_u->name_ptr))
5423 return False;
5424 if (!smb_io_unistr2("name", &q_u->name, True, ps, depth))
5425 return False;
5427 if (!prs_align(ps))
5428 return False;
5430 if (!prs_uint32("level", ps, depth, &q_u->level))
5431 return False;
5433 if(!spoolss_io_buffer("", ps, depth, &q_u->buffer))
5434 return False;
5436 if (!prs_align(ps))
5437 return False;
5439 if (!prs_uint32("offered", ps, depth, &q_u->offered))
5440 return False;
5442 return True;
5445 /*******************************************************************
5446 ********************************************************************/
5448 BOOL spoolss_io_r_enumprintmonitors(char *desc, SPOOL_R_ENUMPRINTMONITORS *r_u, prs_struct *ps, int depth)
5450 prs_debug(ps, depth, desc, "spoolss_io_r_enumprintmonitors");
5451 depth++;
5453 if (!prs_align(ps))
5454 return False;
5456 if (!spoolss_io_buffer("", ps, depth, &r_u->buffer))
5457 return False;
5459 if (!prs_align(ps))
5460 return False;
5462 if (!prs_uint32("needed", ps, depth, &r_u->needed))
5463 return False;
5465 if (!prs_uint32("returned", ps, depth, &r_u->returned))
5466 return False;
5468 if (!prs_werror("status", ps, depth, &r_u->status))
5469 return False;
5471 return True;
5474 /*******************************************************************
5475 ********************************************************************/
5477 BOOL spoolss_io_r_enumprinterdata(char *desc, SPOOL_R_ENUMPRINTERDATA *r_u, prs_struct *ps, int depth)
5479 prs_debug(ps, depth, desc, "spoolss_io_r_enumprinterdata");
5480 depth++;
5482 if(!prs_align(ps))
5483 return False;
5484 if(!prs_uint32("valuesize", ps, depth, &r_u->valuesize))
5485 return False;
5487 if(!prs_uint16uni(False, "value", ps, depth, r_u->value, r_u->valuesize ))
5488 return False;
5490 if(!prs_align(ps))
5491 return False;
5493 if(!prs_uint32("realvaluesize", ps, depth, &r_u->realvaluesize))
5494 return False;
5496 if(!prs_uint32("type", ps, depth, &r_u->type))
5497 return False;
5499 if(!prs_uint32("datasize", ps, depth, &r_u->datasize))
5500 return False;
5501 if(!prs_uint8s(False, "data", ps, depth, r_u->data, r_u->datasize))
5502 return False;
5503 if(!prs_align(ps))
5504 return False;
5506 if(!prs_uint32("realdatasize", ps, depth, &r_u->realdatasize))
5507 return False;
5508 if(!prs_werror("status", ps, depth, &r_u->status))
5509 return False;
5511 return True;
5514 /*******************************************************************
5515 ********************************************************************/
5517 BOOL spoolss_io_q_enumprinterdata(char *desc, SPOOL_Q_ENUMPRINTERDATA *q_u, prs_struct *ps, int depth)
5519 prs_debug(ps, depth, desc, "spoolss_io_q_enumprinterdata");
5520 depth++;
5522 if(!prs_align(ps))
5523 return False;
5524 if(!smb_io_pol_hnd("printer handle",&q_u->handle,ps,depth))
5525 return False;
5526 if(!prs_uint32("index", ps, depth, &q_u->index))
5527 return False;
5528 if(!prs_uint32("valuesize", ps, depth, &q_u->valuesize))
5529 return False;
5530 if(!prs_uint32("datasize", ps, depth, &q_u->datasize))
5531 return False;
5533 return True;
5536 /*******************************************************************
5537 ********************************************************************/
5539 BOOL make_spoolss_q_enumprinterdata(SPOOL_Q_ENUMPRINTERDATA *q_u,
5540 const POLICY_HND *hnd,
5541 uint32 idx, uint32 valuelen, uint32 datalen)
5543 memcpy(&q_u->handle, hnd, sizeof(q_u->handle));
5544 q_u->index=idx;
5545 q_u->valuesize=valuelen;
5546 q_u->datasize=datalen;
5548 return True;
5551 /*******************************************************************
5552 ********************************************************************/
5554 BOOL spoolss_io_q_setprinterdata(char *desc, SPOOL_Q_SETPRINTERDATA *q_u, prs_struct *ps, int depth)
5556 prs_debug(ps, depth, desc, "spoolss_io_q_setprinterdata");
5557 depth++;
5559 if(!prs_align(ps))
5560 return False;
5561 if(!smb_io_pol_hnd("printer handle", &q_u->handle, ps, depth))
5562 return False;
5563 if(!smb_io_unistr2("", &q_u->value, True, ps, depth))
5564 return False;
5566 if(!prs_align(ps))
5567 return False;
5569 if(!prs_uint32("type", ps, depth, &q_u->type))
5570 return False;
5572 if(!prs_uint32("max_len", ps, depth, &q_u->max_len))
5573 return False;
5575 switch (q_u->type)
5577 case 0x1:
5578 case 0x3:
5579 case 0x4:
5580 case 0x7:
5581 if (q_u->max_len) {
5582 if (UNMARSHALLING(ps))
5583 q_u->data=(uint8 *)prs_alloc_mem(ps, q_u->max_len * sizeof(uint8));
5584 if(q_u->data == NULL)
5585 return False;
5586 if(!prs_uint8s(False,"data", ps, depth, q_u->data, q_u->max_len))
5587 return False;
5589 if(!prs_align(ps))
5590 return False;
5591 break;
5594 if(!prs_uint32("real_len", ps, depth, &q_u->real_len))
5595 return False;
5597 return True;
5600 /*******************************************************************
5601 ********************************************************************/
5603 BOOL spoolss_io_r_setprinterdata(char *desc, SPOOL_R_SETPRINTERDATA *r_u, prs_struct *ps, int depth)
5605 prs_debug(ps, depth, desc, "spoolss_io_r_setprinterdata");
5606 depth++;
5608 if(!prs_align(ps))
5609 return False;
5610 if(!prs_werror("status", ps, depth, &r_u->status))
5611 return False;
5613 return True;
5616 /*******************************************************************
5617 ********************************************************************/
5619 BOOL convert_specific_param(NT_PRINTER_PARAM **param, const UNISTR2 *value,
5620 uint32 type, const uint8 *data, uint32 len)
5622 DEBUG(5,("converting a specific param struct\n"));
5624 if (*param == NULL)
5626 *param=(NT_PRINTER_PARAM *)malloc(sizeof(NT_PRINTER_PARAM));
5627 if(*param == NULL)
5628 return False;
5629 memset((char *)*param, '\0', sizeof(NT_PRINTER_PARAM));
5630 DEBUGADD(6,("Allocated a new PARAM struct\n"));
5632 unistr2_to_ascii((*param)->value, value, sizeof((*param)->value)-1);
5633 (*param)->type = type;
5635 /* le champ data n'est pas NULL termine */
5636 /* on stocke donc la longueur */
5638 (*param)->data_len=len;
5640 if (len) {
5641 (*param)->data=(uint8 *)malloc(len * sizeof(uint8));
5642 if((*param)->data == NULL)
5643 return False;
5644 memcpy((*param)->data, data, len);
5647 DEBUGADD(6,("\tvalue:[%s], len:[%d]\n",(*param)->value, (*param)->data_len));
5648 dump_data(10, (char *)(*param)->data, (*param)->data_len);
5650 return True;
5653 /*******************************************************************
5654 ********************************************************************/
5656 static BOOL spoolss_io_addform(char *desc, FORM *f, uint32 ptr, prs_struct *ps, int depth)
5658 prs_debug(ps, depth, desc, "spoolss_io_addform");
5659 depth++;
5660 if(!prs_align(ps))
5661 return False;
5663 if (ptr!=0)
5665 if(!prs_uint32("flags", ps, depth, &f->flags))
5666 return False;
5667 if(!prs_uint32("name_ptr", ps, depth, &f->name_ptr))
5668 return False;
5669 if(!prs_uint32("size_x", ps, depth, &f->size_x))
5670 return False;
5671 if(!prs_uint32("size_y", ps, depth, &f->size_y))
5672 return False;
5673 if(!prs_uint32("left", ps, depth, &f->left))
5674 return False;
5675 if(!prs_uint32("top", ps, depth, &f->top))
5676 return False;
5677 if(!prs_uint32("right", ps, depth, &f->right))
5678 return False;
5679 if(!prs_uint32("bottom", ps, depth, &f->bottom))
5680 return False;
5682 if(!smb_io_unistr2("", &f->name, f->name_ptr, ps, depth))
5683 return False;
5686 return True;
5689 /*******************************************************************
5690 ********************************************************************/
5692 BOOL spoolss_io_q_deleteform(char *desc, SPOOL_Q_DELETEFORM *q_u, prs_struct *ps, int depth)
5694 prs_debug(ps, depth, desc, "spoolss_io_q_deleteform");
5695 depth++;
5697 if(!prs_align(ps))
5698 return False;
5699 if(!smb_io_pol_hnd("printer handle", &q_u->handle, ps, depth))
5700 return False;
5701 if(!smb_io_unistr2("form name", &q_u->name, True, ps, depth))
5702 return False;
5704 return True;
5707 /*******************************************************************
5708 ********************************************************************/
5710 BOOL spoolss_io_r_deleteform(char *desc, SPOOL_R_DELETEFORM *r_u, prs_struct *ps, int depth)
5712 prs_debug(ps, depth, desc, "spoolss_io_r_deleteform");
5713 depth++;
5715 if(!prs_align(ps))
5716 return False;
5717 if(!prs_werror("status", ps, depth, &r_u->status))
5718 return False;
5720 return True;
5723 /*******************************************************************
5724 ********************************************************************/
5726 BOOL spoolss_io_q_addform(char *desc, SPOOL_Q_ADDFORM *q_u, prs_struct *ps, int depth)
5728 uint32 useless_ptr=0;
5729 prs_debug(ps, depth, desc, "spoolss_io_q_addform");
5730 depth++;
5732 if(!prs_align(ps))
5733 return False;
5734 if(!smb_io_pol_hnd("printer handle", &q_u->handle, ps, depth))
5735 return False;
5736 if(!prs_uint32("level", ps, depth, &q_u->level))
5737 return False;
5738 if(!prs_uint32("level2", ps, depth, &q_u->level2))
5739 return False;
5741 if (q_u->level==1)
5743 if(!prs_uint32("useless_ptr", ps, depth, &useless_ptr))
5744 return False;
5745 if(!spoolss_io_addform("", &q_u->form, useless_ptr, ps, depth))
5746 return False;
5749 return True;
5752 /*******************************************************************
5753 ********************************************************************/
5755 BOOL spoolss_io_r_addform(char *desc, SPOOL_R_ADDFORM *r_u, prs_struct *ps, int depth)
5757 prs_debug(ps, depth, desc, "spoolss_io_r_addform");
5758 depth++;
5760 if(!prs_align(ps))
5761 return False;
5762 if(!prs_werror("status", ps, depth, &r_u->status))
5763 return False;
5765 return True;
5768 /*******************************************************************
5769 ********************************************************************/
5771 BOOL spoolss_io_q_setform(char *desc, SPOOL_Q_SETFORM *q_u, prs_struct *ps, int depth)
5773 uint32 useless_ptr=0;
5774 prs_debug(ps, depth, desc, "spoolss_io_q_setform");
5775 depth++;
5777 if(!prs_align(ps))
5778 return False;
5779 if(!smb_io_pol_hnd("printer handle", &q_u->handle, ps, depth))
5780 return False;
5781 if(!smb_io_unistr2("", &q_u->name, True, ps, depth))
5782 return False;
5784 if(!prs_align(ps))
5785 return False;
5787 if(!prs_uint32("level", ps, depth, &q_u->level))
5788 return False;
5789 if(!prs_uint32("level2", ps, depth, &q_u->level2))
5790 return False;
5792 if (q_u->level==1)
5794 if(!prs_uint32("useless_ptr", ps, depth, &useless_ptr))
5795 return False;
5796 if(!spoolss_io_addform("", &q_u->form, useless_ptr, ps, depth))
5797 return False;
5800 return True;
5803 /*******************************************************************
5804 ********************************************************************/
5806 BOOL spoolss_io_r_setform(char *desc, SPOOL_R_SETFORM *r_u, prs_struct *ps, int depth)
5808 prs_debug(ps, depth, desc, "spoolss_io_r_setform");
5809 depth++;
5811 if(!prs_align(ps))
5812 return False;
5813 if(!prs_werror("status", ps, depth, &r_u->status))
5814 return False;
5816 return True;
5819 /*******************************************************************
5820 Parse a SPOOL_R_GETJOB structure.
5821 ********************************************************************/
5823 BOOL spoolss_io_r_getjob(char *desc, SPOOL_R_GETJOB *r_u, prs_struct *ps, int depth)
5825 prs_debug(ps, depth, desc, "spoolss_io_r_getjob");
5826 depth++;
5828 if (!prs_align(ps))
5829 return False;
5831 if (!spoolss_io_buffer("", ps, depth, &r_u->buffer))
5832 return False;
5834 if (!prs_align(ps))
5835 return False;
5837 if (!prs_uint32("needed", ps, depth, &r_u->needed))
5838 return False;
5840 if (!prs_werror("status", ps, depth, &r_u->status))
5841 return False;
5843 return True;
5846 /*******************************************************************
5847 Parse a SPOOL_Q_GETJOB structure.
5848 ********************************************************************/
5850 BOOL spoolss_io_q_getjob(char *desc, SPOOL_Q_GETJOB *q_u, prs_struct *ps, int depth)
5852 prs_debug(ps, depth, desc, "");
5853 depth++;
5855 if(!prs_align(ps))
5856 return False;
5858 if(!smb_io_pol_hnd("printer handle",&q_u->handle,ps,depth))
5859 return False;
5860 if(!prs_uint32("jobid", ps, depth, &q_u->jobid))
5861 return False;
5862 if(!prs_uint32("level", ps, depth, &q_u->level))
5863 return False;
5865 if(!spoolss_io_buffer("", ps, depth, &q_u->buffer))
5866 return False;
5868 if(!prs_align(ps))
5869 return False;
5871 if(!prs_uint32("offered", ps, depth, &q_u->offered))
5872 return False;
5874 return True;
5877 void free_devmode(DEVICEMODE *devmode)
5879 if (devmode!=NULL) {
5880 SAFE_FREE(devmode->private);
5881 SAFE_FREE(devmode);
5885 void free_printer_info_1(PRINTER_INFO_1 *printer)
5887 SAFE_FREE(printer);
5890 void free_printer_info_2(PRINTER_INFO_2 *printer)
5892 if (printer!=NULL) {
5893 free_devmode(printer->devmode);
5894 printer->devmode = NULL;
5895 SAFE_FREE(printer);
5899 void free_printer_info_3(PRINTER_INFO_3 *printer)
5901 SAFE_FREE(printer);
5904 void free_job_info_2(JOB_INFO_2 *job)
5906 if (job!=NULL)
5907 free_devmode(job->devmode);
5910 /*******************************************************************
5911 * init a structure.
5912 ********************************************************************/
5914 BOOL make_spoolss_q_replyopenprinter(SPOOL_Q_REPLYOPENPRINTER *q_u,
5915 const fstring string, uint32 printer, uint32 type)
5917 if (q_u == NULL)
5918 return False;
5920 init_unistr2(&q_u->string, string, strlen(string)+1);
5922 q_u->printer=printer;
5923 q_u->type=type;
5925 q_u->unknown0=0x0;
5926 q_u->unknown1=0x0;
5928 return True;
5931 /*******************************************************************
5932 Parse a SPOOL_Q_REPLYOPENPRINTER structure.
5933 ********************************************************************/
5935 BOOL spoolss_io_q_replyopenprinter(char *desc, SPOOL_Q_REPLYOPENPRINTER *q_u, prs_struct *ps, int depth)
5937 prs_debug(ps, depth, desc, "spoolss_io_q_replyopenprinter");
5938 depth++;
5940 if(!prs_align(ps))
5941 return False;
5943 if(!smb_io_unistr2("", &q_u->string, True, ps, depth))
5944 return False;
5946 if(!prs_align(ps))
5947 return False;
5949 if(!prs_uint32("printer", ps, depth, &q_u->printer))
5950 return False;
5951 if(!prs_uint32("type", ps, depth, &q_u->type))
5952 return False;
5954 if(!prs_uint32("unknown0", ps, depth, &q_u->unknown0))
5955 return False;
5956 if(!prs_uint32("unknown1", ps, depth, &q_u->unknown1))
5957 return False;
5959 return True;
5962 /*******************************************************************
5963 Parse a SPOOL_R_REPLYOPENPRINTER structure.
5964 ********************************************************************/
5966 BOOL spoolss_io_r_replyopenprinter(char *desc, SPOOL_R_REPLYOPENPRINTER *r_u, prs_struct *ps, int depth)
5968 prs_debug(ps, depth, desc, "spoolss_io_r_replyopenprinter");
5969 depth++;
5971 if (!prs_align(ps))
5972 return False;
5974 if(!smb_io_pol_hnd("printer handle",&r_u->handle,ps,depth))
5975 return False;
5977 if (!prs_werror("status", ps, depth, &r_u->status))
5978 return False;
5980 return True;
5983 /*******************************************************************
5984 * init a structure.
5985 ********************************************************************/
5987 BOOL make_spoolss_q_reply_closeprinter(SPOOL_Q_REPLYCLOSEPRINTER *q_u, POLICY_HND *hnd)
5989 if (q_u == NULL)
5990 return False;
5992 memcpy(&q_u->handle, hnd, sizeof(q_u->handle));
5994 return True;
5997 /*******************************************************************
5998 Parse a SPOOL_Q_REPLYCLOSEPRINTER structure.
5999 ********************************************************************/
6001 BOOL spoolss_io_q_replycloseprinter(char *desc, SPOOL_Q_REPLYCLOSEPRINTER *q_u, prs_struct *ps, int depth)
6003 prs_debug(ps, depth, desc, "spoolss_io_q_replycloseprinter");
6004 depth++;
6006 if(!prs_align(ps))
6007 return False;
6009 if(!smb_io_pol_hnd("printer handle",&q_u->handle,ps,depth))
6010 return False;
6012 return True;
6015 /*******************************************************************
6016 Parse a SPOOL_R_REPLYCLOSEPRINTER structure.
6017 ********************************************************************/
6019 BOOL spoolss_io_r_replycloseprinter(char *desc, SPOOL_R_REPLYCLOSEPRINTER *r_u, prs_struct *ps, int depth)
6021 prs_debug(ps, depth, desc, "spoolss_io_r_replycloseprinter");
6022 depth++;
6024 if (!prs_align(ps))
6025 return False;
6027 if(!smb_io_pol_hnd("printer handle",&r_u->handle,ps,depth))
6028 return False;
6030 if (!prs_werror("status", ps, depth, &r_u->status))
6031 return False;
6033 return True;
6036 /*******************************************************************
6037 * init a structure.
6038 ********************************************************************/
6040 BOOL make_spoolss_q_reply_rrpcn(SPOOL_Q_REPLY_RRPCN *q_u, POLICY_HND *hnd,
6041 uint32 change_low, uint32 change_high)
6043 if (q_u == NULL)
6044 return False;
6046 memcpy(&q_u->handle, hnd, sizeof(q_u->handle));
6048 q_u->change_low=change_low;
6049 q_u->change_high=change_high;
6051 q_u->unknown0=0x0;
6052 q_u->unknown1=0x0;
6054 q_u->info_ptr=1;
6056 q_u->info.version=2;
6057 q_u->info.flags=PRINTER_NOTIFY_INFO_DISCARDED;
6058 q_u->info.count=0;
6060 return True;
6063 /*******************************************************************
6064 Parse a SPOOL_Q_REPLY_RRPCN structure.
6065 ********************************************************************/
6067 BOOL spoolss_io_q_reply_rrpcn(char *desc, SPOOL_Q_REPLY_RRPCN *q_u, prs_struct *ps, int depth)
6069 prs_debug(ps, depth, desc, "spoolss_io_q_reply_rrpcn");
6070 depth++;
6072 if(!prs_align(ps))
6073 return False;
6075 if(!smb_io_pol_hnd("printer handle",&q_u->handle,ps,depth))
6076 return False;
6078 if (!prs_uint32("change_low", ps, depth, &q_u->change_low))
6079 return False;
6081 if (!prs_uint32("change_high", ps, depth, &q_u->change_high))
6082 return False;
6084 if (!prs_uint32("unknown0", ps, depth, &q_u->unknown0))
6085 return False;
6087 if (!prs_uint32("unknown1", ps, depth, &q_u->unknown1))
6088 return False;
6090 if (!prs_uint32("info_ptr", ps, depth, &q_u->info_ptr))
6091 return False;
6093 if(q_u->info_ptr!=0)
6094 if(!smb_io_notify_info(desc, &q_u->info, ps, depth))
6095 return False;
6097 return True;
6100 /*******************************************************************
6101 Parse a SPOOL_R_REPLY_RRPCN structure.
6102 ********************************************************************/
6104 BOOL spoolss_io_r_reply_rrpcn(char *desc, SPOOL_R_REPLY_RRPCN *r_u, prs_struct *ps, int depth)
6106 prs_debug(ps, depth, desc, "spoolss_io_r_replycloseprinter");
6107 depth++;
6109 if (!prs_align(ps))
6110 return False;
6112 if (!prs_uint32("unknown0", ps, depth, &r_u->unknown0))
6113 return False;
6115 if (!prs_werror("status", ps, depth, &r_u->status))
6116 return False;
6118 return True;
6121 /*******************************************************************
6122 * read a structure.
6123 * called from spoolss_q_getprinterdataex (srv_spoolss.c)
6124 ********************************************************************/
6126 BOOL spoolss_io_q_getprinterdataex(char *desc, SPOOL_Q_GETPRINTERDATAEX *q_u, prs_struct *ps, int depth)
6128 if (q_u == NULL)
6129 return False;
6131 prs_debug(ps, depth, desc, "spoolss_io_q_getprinterdataex");
6132 depth++;
6134 if (!prs_align(ps))
6135 return False;
6136 if (!smb_io_pol_hnd("printer handle",&q_u->handle,ps,depth))
6137 return False;
6138 if (!prs_align(ps))
6139 return False;
6140 if (!smb_io_unistr2("keyname", &q_u->keyname,True,ps,depth))
6141 return False;
6142 if (!prs_align(ps))
6143 return False;
6144 if (!smb_io_unistr2("valuename", &q_u->valuename,True,ps,depth))
6145 return False;
6146 if (!prs_align(ps))
6147 return False;
6148 if (!prs_uint32("size", ps, depth, &q_u->size))
6149 return False;
6151 return True;
6154 /*******************************************************************
6155 * write a structure.
6156 * called from spoolss_r_getprinterdataex (srv_spoolss.c)
6157 ********************************************************************/
6159 BOOL spoolss_io_r_getprinterdataex(char *desc, SPOOL_R_GETPRINTERDATAEX *r_u, prs_struct *ps, int depth)
6161 if (r_u == NULL)
6162 return False;
6164 prs_debug(ps, depth, desc, "spoolss_io_r_getprinterdataex");
6165 depth++;
6167 if (!prs_align(ps))
6168 return False;
6169 if (!prs_uint32("type", ps, depth, &r_u->type))
6170 return False;
6171 if (!prs_uint32("size", ps, depth, &r_u->size))
6172 return False;
6174 if (!prs_uint8s(False,"data", ps, depth, r_u->data, r_u->size))
6175 return False;
6177 if (!prs_align(ps))
6178 return False;
6180 if (!prs_uint32("needed", ps, depth, &r_u->needed))
6181 return False;
6182 if (!prs_werror("status", ps, depth, &r_u->status))
6183 return False;
6185 return True;
6188 /*******************************************************************
6189 * read a structure.
6190 ********************************************************************/
6192 BOOL spoolss_io_q_setprinterdataex(char *desc, SPOOL_Q_SETPRINTERDATAEX *q_u, prs_struct *ps, int depth)
6194 prs_debug(ps, depth, desc, "spoolss_io_q_setprinterdataex");
6195 depth++;
6197 if(!prs_align(ps))
6198 return False;
6199 if(!smb_io_pol_hnd("printer handle", &q_u->handle, ps, depth))
6200 return False;
6201 if(!smb_io_unistr2("", &q_u->key, True, ps, depth))
6202 return False;
6204 if(!prs_align(ps))
6205 return False;
6207 if(!smb_io_unistr2("", &q_u->value, True, ps, depth))
6208 return False;
6210 if(!prs_align(ps))
6211 return False;
6213 if(!prs_uint32("type", ps, depth, &q_u->type))
6214 return False;
6216 if(!prs_uint32("max_len", ps, depth, &q_u->max_len))
6217 return False;
6219 switch (q_u->type)
6221 case 0x1:
6222 case 0x3:
6223 case 0x4:
6224 case 0x7:
6225 if (q_u->max_len) {
6226 if (UNMARSHALLING(ps))
6227 q_u->data=(uint8 *)prs_alloc_mem(ps, q_u->max_len * sizeof(uint8));
6228 if(q_u->data == NULL)
6229 return False;
6230 if(!prs_uint8s(False,"data", ps, depth, q_u->data, q_u->max_len))
6231 return False;
6233 if(!prs_align(ps))
6234 return False;
6235 break;
6238 if(!prs_uint32("real_len", ps, depth, &q_u->real_len))
6239 return False;
6241 return True;
6244 /*******************************************************************
6245 * write a structure.
6246 ********************************************************************/
6248 BOOL spoolss_io_r_setprinterdataex(char *desc, SPOOL_R_SETPRINTERDATAEX *r_u, prs_struct *ps, int depth)
6250 prs_debug(ps, depth, desc, "spoolss_io_r_setprinterdataex");
6251 depth++;
6253 if(!prs_align(ps))
6254 return False;
6255 if(!prs_werror("status", ps, depth, &r_u->status))
6256 return False;
6258 return True;
6262 /*******************************************************************
6263 * read a structure.
6264 ********************************************************************/
6266 BOOL spoolss_io_q_enumprinterkey(char *desc, SPOOL_Q_ENUMPRINTERKEY *q_u, prs_struct *ps, int depth)
6268 prs_debug(ps, depth, desc, "spoolss_io_q_enumprinterkey");
6269 depth++;
6271 if(!prs_align(ps))
6272 return False;
6273 if(!smb_io_pol_hnd("printer handle", &q_u->handle, ps, depth))
6274 return False;
6276 if(!smb_io_unistr2("", &q_u->key, True, ps, depth))
6277 return False;
6279 if(!prs_align(ps))
6280 return False;
6282 if(!prs_uint32("size", ps, depth, &q_u->size))
6283 return False;
6285 return True;
6288 /*******************************************************************
6289 * write a structure.
6290 ********************************************************************/
6292 BOOL spoolss_io_r_enumprinterkey(char *desc, SPOOL_R_ENUMPRINTERKEY *r_u, prs_struct *ps, int depth)
6294 prs_debug(ps, depth, desc, "spoolss_io_r_enumprinterkey");
6295 depth++;
6297 if(!prs_align(ps))
6298 return False;
6300 if (!smb_io_buffer5("", &r_u->keys, ps, depth))
6301 return False;
6303 if(!prs_align(ps))
6304 return False;
6306 if(!prs_uint32("needed", ps, depth, &r_u->needed))
6307 return False;
6309 if(!prs_werror("status", ps, depth, &r_u->status))
6310 return False;
6312 return True;
6316 /*******************************************************************
6317 * read a structure.
6318 ********************************************************************/
6320 BOOL spoolss_io_q_enumprinterdataex(char *desc, SPOOL_Q_ENUMPRINTERDATAEX *q_u, prs_struct *ps, int depth)
6322 prs_debug(ps, depth, desc, "spoolss_io_q_enumprinterdataex");
6323 depth++;
6325 if(!prs_align(ps))
6326 return False;
6327 if(!smb_io_pol_hnd("printer handle", &q_u->handle, ps, depth))
6328 return False;
6330 if(!smb_io_unistr2("", &q_u->key, True, ps, depth))
6331 return False;
6333 if(!prs_align(ps))
6334 return False;
6336 if(!prs_uint32("size", ps, depth, &q_u->size))
6337 return False;
6339 return True;
6342 /*******************************************************************
6343 ********************************************************************/
6344 static BOOL spoolss_io_printer_enum_values_ctr(char *desc, prs_struct *ps,
6345 PRINTER_ENUM_VALUES_CTR *ctr, int depth)
6347 int i;
6348 uint32 valuename_offset,
6349 data_offset,
6350 current_offset;
6352 prs_debug(ps, depth, desc, "spoolss_io_printer_enum_values_ctr");
6353 depth++;
6355 if (!prs_uint32("size", ps, depth, &ctr->size))
6356 return False;
6358 /* offset data begins at 20 bytes per structure * size_of_array.
6359 Don't forget the uint32 at the beginning */
6361 current_offset = 4 + (20*ctr->size_of_array);
6363 /* first loop to write basic enum_value information */
6365 for (i=0; i<ctr->size_of_array; i++)
6367 valuename_offset = current_offset;
6368 if (!prs_uint32("valuename_offset", ps, depth, &valuename_offset))
6369 return False;
6371 if (!prs_uint32("value_len", ps, depth, &ctr->values[i].value_len))
6372 return False;
6374 if (!prs_uint32("type", ps, depth, &ctr->values[i].type))
6375 return False;
6377 data_offset = ctr->values[i].value_len + valuename_offset;
6378 if (!prs_uint32("data_offset", ps, depth, &data_offset))
6379 return False;
6381 if (!prs_uint32("data_len", ps, depth, &ctr->values[i].data_len))
6382 return False;
6384 current_offset = data_offset + ctr->values[i].data_len;
6388 /* loop #2 for writing the dynamically size objects
6389 while viewing oncversations between Win2k -> Win2k,
6390 4-byte alignment does not seem to matter here --jerrty */
6392 for (i=0; i<ctr->size_of_array; i++)
6395 if (!prs_unistr("valuename", ps, depth, &ctr->values[i].valuename))
6396 return False;
6398 if (!prs_uint8s(False, "data", ps, depth, ctr->values[i].data, ctr->values[i].data_len))
6399 return False;
6404 return True;
6408 /*******************************************************************
6409 * write a structure.
6410 ********************************************************************/
6412 BOOL spoolss_io_r_enumprinterdataex(char *desc, SPOOL_R_ENUMPRINTERDATAEX *r_u, prs_struct *ps, int depth)
6414 prs_debug(ps, depth, desc, "spoolss_io_r_enumprinterdataex");
6415 depth++;
6417 if(!prs_align(ps))
6418 return False;
6420 if (!spoolss_io_printer_enum_values_ctr("", ps, &r_u->ctr, depth ))
6421 return False;
6423 if(!prs_align(ps))
6424 return False;
6426 if(!prs_uint32("needed", ps, depth, &r_u->needed))
6427 return False;
6429 if(!prs_uint32("returned", ps, depth, &r_u->returned))
6430 return False;
6432 if(!prs_werror("status", ps, depth, &r_u->status))
6433 return False;
6435 return True;