merging spoolss code between branches. SPOOLSS_RESETPRINTER
[Samba.git] / source / rpc_parse / parse_spoolss.c
blobecd2c7e12c57faed7c54790234e50585eaf87960
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,
9 * Copyright (C) Tim Potter 2001.
11 * This program is free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License as published by
13 * the Free Software Foundation; either version 2 of the License, or
14 * (at your option) any later version.
16 * This program is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU General Public License for more details.
21 * You should have received a copy of the GNU General Public License
22 * along with this program; if not, write to the Free Software
23 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
26 #include "includes.h"
28 /*******************************************************************
29 return the length of a UNISTR string.
30 ********************************************************************/
32 static uint32 str_len_uni(UNISTR *source)
34 uint32 i=0;
36 if (!source->buffer)
37 return 0;
39 while (source->buffer[i])
40 i++;
42 return i;
45 /*******************************************************************
46 This should be moved in a more generic lib.
47 ********************************************************************/
49 static BOOL spoolss_io_system_time(char *desc, prs_struct *ps, int depth, SYSTEMTIME *systime)
51 if(!prs_uint16("year", ps, depth, &systime->year))
52 return False;
53 if(!prs_uint16("month", ps, depth, &systime->month))
54 return False;
55 if(!prs_uint16("dayofweek", ps, depth, &systime->dayofweek))
56 return False;
57 if(!prs_uint16("day", ps, depth, &systime->day))
58 return False;
59 if(!prs_uint16("hour", ps, depth, &systime->hour))
60 return False;
61 if(!prs_uint16("minute", ps, depth, &systime->minute))
62 return False;
63 if(!prs_uint16("second", ps, depth, &systime->second))
64 return False;
65 if(!prs_uint16("milliseconds", ps, depth, &systime->milliseconds))
66 return False;
68 return True;
71 /*******************************************************************
72 ********************************************************************/
74 BOOL make_systemtime(SYSTEMTIME *systime, struct tm *unixtime)
76 systime->year=unixtime->tm_year+1900;
77 systime->month=unixtime->tm_mon+1;
78 systime->dayofweek=unixtime->tm_wday;
79 systime->day=unixtime->tm_mday;
80 systime->hour=unixtime->tm_hour;
81 systime->minute=unixtime->tm_min;
82 systime->second=unixtime->tm_sec;
83 systime->milliseconds=0;
85 return True;
88 /*******************************************************************
89 reads or writes an DOC_INFO structure.
90 ********************************************************************/
92 static BOOL smb_io_doc_info_1(char *desc, DOC_INFO_1 *info_1, prs_struct *ps, int depth)
94 if (info_1 == NULL) return False;
96 prs_debug(ps, depth, desc, "smb_io_doc_info_1");
97 depth++;
99 if(!prs_align(ps))
100 return False;
102 if(!prs_uint32("p_docname", ps, depth, &info_1->p_docname))
103 return False;
104 if(!prs_uint32("p_outputfile", ps, depth, &info_1->p_outputfile))
105 return False;
106 if(!prs_uint32("p_datatype", ps, depth, &info_1->p_datatype))
107 return False;
109 if(!smb_io_unistr2("", &info_1->docname, info_1->p_docname, ps, depth))
110 return False;
111 if(!smb_io_unistr2("", &info_1->outputfile, info_1->p_outputfile, ps, depth))
112 return False;
113 if(!smb_io_unistr2("", &info_1->datatype, info_1->p_datatype, ps, depth))
114 return False;
116 return True;
119 /*******************************************************************
120 reads or writes an DOC_INFO structure.
121 ********************************************************************/
123 static BOOL smb_io_doc_info(char *desc, DOC_INFO *info, prs_struct *ps, int depth)
125 uint32 useless_ptr=0;
127 if (info == NULL) return False;
129 prs_debug(ps, depth, desc, "smb_io_doc_info");
130 depth++;
132 if(!prs_align(ps))
133 return False;
135 if(!prs_uint32("switch_value", ps, depth, &info->switch_value))
136 return False;
138 if(!prs_uint32("doc_info_X ptr", ps, depth, &useless_ptr))
139 return False;
141 switch (info->switch_value)
143 case 1:
144 if(!smb_io_doc_info_1("",&info->doc_info_1, ps, depth))
145 return False;
146 break;
147 case 2:
149 this is just a placeholder
151 MSDN July 1998 says doc_info_2 is only on
152 Windows 95, and as Win95 doesn't do RPC to print
153 this case is nearly impossible
155 Maybe one day with Windows for dishwasher 2037 ...
158 /* smb_io_doc_info_2("",&info->doc_info_2, ps, depth); */
159 break;
160 default:
161 DEBUG(0,("Something is obviously wrong somewhere !\n"));
162 break;
165 return True;
168 /*******************************************************************
169 reads or writes an DOC_INFO_CONTAINER structure.
170 ********************************************************************/
172 static BOOL smb_io_doc_info_container(char *desc, DOC_INFO_CONTAINER *cont, prs_struct *ps, int depth)
174 if (cont == NULL) return False;
176 prs_debug(ps, depth, desc, "smb_io_doc_info_container");
177 depth++;
179 if(!prs_align(ps))
180 return False;
182 if(!prs_uint32("level", ps, depth, &cont->level))
183 return False;
185 if(!smb_io_doc_info("",&cont->docinfo, ps, depth))
186 return False;
188 return True;
191 /*******************************************************************
192 reads or writes an NOTIFY OPTION TYPE structure.
193 ********************************************************************/
195 /* NOTIFY_OPTION_TYPE and NOTIFY_OPTION_TYPE_DATA are really one
196 structure. The _TYPE structure is really the deferred referrants (i.e
197 the notify fields array) of the _TYPE structure. -tpot */
199 static BOOL smb_io_notify_option_type(char *desc, SPOOL_NOTIFY_OPTION_TYPE *type, prs_struct *ps, int depth)
201 prs_debug(ps, depth, desc, "smb_io_notify_option_type");
202 depth++;
204 if (!prs_align(ps))
205 return False;
207 if(!prs_uint16("type", ps, depth, &type->type))
208 return False;
209 if(!prs_uint16("reserved0", ps, depth, &type->reserved0))
210 return False;
211 if(!prs_uint32("reserved1", ps, depth, &type->reserved1))
212 return False;
213 if(!prs_uint32("reserved2", ps, depth, &type->reserved2))
214 return False;
215 if(!prs_uint32("count", ps, depth, &type->count))
216 return False;
217 if(!prs_uint32("fields_ptr", ps, depth, &type->fields_ptr))
218 return False;
220 return True;
223 /*******************************************************************
224 reads or writes an NOTIFY OPTION TYPE DATA.
225 ********************************************************************/
227 static BOOL smb_io_notify_option_type_data(char *desc, SPOOL_NOTIFY_OPTION_TYPE *type, prs_struct *ps, int depth)
229 int i;
231 prs_debug(ps, depth, desc, "smb_io_notify_option_type_data");
232 depth++;
234 /* if there are no fields just return */
235 if (type->fields_ptr==0)
236 return True;
238 if(!prs_align(ps))
239 return False;
241 if(!prs_uint32("count2", ps, depth, &type->count2))
242 return False;
244 if (type->count2 != type->count)
245 DEBUG(4,("What a mess, count was %x now is %x !\n", type->count, type->count2));
247 /* parse the option type data */
248 for(i=0;i<type->count2;i++)
249 if(!prs_uint16("fields",ps,depth,&type->fields[i]))
250 return False;
251 return True;
254 /*******************************************************************
255 reads or writes an NOTIFY OPTION structure.
256 ********************************************************************/
258 static BOOL smb_io_notify_option_type_ctr(char *desc, SPOOL_NOTIFY_OPTION_TYPE_CTR *ctr , prs_struct *ps, int depth)
260 int i;
262 prs_debug(ps, depth, desc, "smb_io_notify_option_type_ctr");
263 depth++;
265 if(!prs_uint32("count", ps, depth, &ctr->count))
266 return False;
268 /* reading */
269 if (UNMARSHALLING(ps))
270 if((ctr->type=(SPOOL_NOTIFY_OPTION_TYPE *)prs_alloc_mem(ps,ctr->count*sizeof(SPOOL_NOTIFY_OPTION_TYPE))) == NULL)
271 return False;
273 /* the option type struct */
274 for(i=0;i<ctr->count;i++)
275 if(!smb_io_notify_option_type("", &ctr->type[i] , ps, depth))
276 return False;
278 /* the type associated with the option type struct */
279 for(i=0;i<ctr->count;i++)
280 if(!smb_io_notify_option_type_data("", &ctr->type[i] , ps, depth))
281 return False;
283 return True;
286 /*******************************************************************
287 reads or writes an NOTIFY OPTION structure.
288 ********************************************************************/
290 static BOOL smb_io_notify_option(char *desc, SPOOL_NOTIFY_OPTION *option, prs_struct *ps, int depth)
292 prs_debug(ps, depth, desc, "smb_io_notify_option");
293 depth++;
295 if(!prs_uint32("version", ps, depth, &option->version))
296 return False;
297 if(!prs_uint32("flags", ps, depth, &option->flags))
298 return False;
299 if(!prs_uint32("count", ps, depth, &option->count))
300 return False;
301 if(!prs_uint32("option_type_ptr", ps, depth, &option->option_type_ptr))
302 return False;
304 /* marshalling or unmarshalling, that would work */
305 if (option->option_type_ptr!=0) {
306 if(!smb_io_notify_option_type_ctr("", &option->ctr ,ps, depth))
307 return False;
309 else {
310 option->ctr.type=NULL;
311 option->ctr.count=0;
314 return True;
317 /*******************************************************************
318 reads or writes an NOTIFY INFO DATA structure.
319 ********************************************************************/
321 static BOOL smb_io_notify_info_data(char *desc,SPOOL_NOTIFY_INFO_DATA *data, prs_struct *ps, int depth)
323 uint32 useless_ptr=0xADDE0FF0;
325 uint32 how_many_words;
326 BOOL isvalue;
327 uint32 x;
329 prs_debug(ps, depth, desc, "smb_io_notify_info_data");
330 depth++;
332 how_many_words=data->size;
333 if (how_many_words==POINTER) {
334 how_many_words=TWO_VALUE;
337 isvalue=data->enc_type;
339 if(!prs_align(ps))
340 return False;
341 if(!prs_uint16("type", ps, depth, &data->type))
342 return False;
343 if(!prs_uint16("field", ps, depth, &data->field))
344 return False;
345 /*prs_align(ps);*/
347 if(!prs_uint32("how many words", ps, depth, &how_many_words))
348 return False;
349 if(!prs_uint32("id", ps, depth, &data->id))
350 return False;
351 if(!prs_uint32("how many words", ps, depth, &how_many_words))
352 return False;
355 /*prs_align(ps);*/
357 if (isvalue==True) {
358 if(!prs_uint32("value[0]", ps, depth, &data->notify_data.value[0]))
359 return False;
360 if(!prs_uint32("value[1]", ps, depth, &data->notify_data.value[1]))
361 return False;
362 /*prs_align(ps);*/
363 } else {
364 /* it's a string */
365 /* length in ascii including \0 */
366 x=2*(data->notify_data.data.length+1);
367 if(!prs_uint32("string length", ps, depth, &x ))
368 return False;
369 if(!prs_uint32("pointer", ps, depth, &useless_ptr))
370 return False;
371 /*prs_align(ps);*/
374 return True;
377 /*******************************************************************
378 reads or writes an NOTIFY INFO DATA structure.
379 ********************************************************************/
381 BOOL smb_io_notify_info_data_strings(char *desc,SPOOL_NOTIFY_INFO_DATA *data,
382 prs_struct *ps, int depth)
384 uint32 x;
385 BOOL isvalue;
387 prs_debug(ps, depth, desc, "smb_io_notify_info_data_strings");
388 depth++;
390 if(!prs_align(ps))
391 return False;
393 isvalue=data->enc_type;
395 if (isvalue==False) {
396 /* length of string in unicode include \0 */
397 x=data->notify_data.data.length+1;
398 if(!prs_uint32("string length", ps, depth, &x ))
399 return False;
400 if (MARSHALLING(ps)) {
401 /* These are already in little endian format. Don't byte swap. */
402 if (x == 1) {
404 /* No memory allocated for this string
405 therefore following the data.string
406 pointer is a bad idea. Use a pointer to
407 the uint32 length union member to
408 provide a source for a unicode NULL */
410 if(!prs_uint8s(True,"string",ps,depth, (uint8 *)&data->notify_data.data.length,x*2))
411 return False;
412 } else {
413 if(!prs_uint16uni(True,"string",ps,depth,data->notify_data.data.string,x))
414 return False;
416 } else {
418 /* Tallocate memory for string */
420 data->notify_data.data.string = (uint16 *)prs_alloc_mem(ps, x * 2);
421 if (!data->notify_data.data.string)
422 return False;
424 if(!prs_uint16uni(True,"string",ps,depth,data->notify_data.data.string,x))
425 return False;
428 #if 0 /* JERRY */
430 /* Win2k does not seem to put this parse align here */
432 if(!prs_align(ps))
433 return False;
434 #endif
436 return True;
439 /*******************************************************************
440 reads or writes an NOTIFY INFO structure.
441 ********************************************************************/
443 static BOOL smb_io_notify_info(char *desc, SPOOL_NOTIFY_INFO *info, prs_struct *ps, int depth)
445 int i;
447 prs_debug(ps, depth, desc, "smb_io_notify_info");
448 depth++;
450 if(!prs_align(ps))
451 return False;
453 if(!prs_uint32("count", ps, depth, &info->count))
454 return False;
455 if(!prs_uint32("version", ps, depth, &info->version))
456 return False;
457 if(!prs_uint32("flags", ps, depth, &info->flags))
458 return False;
459 if(!prs_uint32("count", ps, depth, &info->count))
460 return False;
462 for (i=0;i<info->count;i++) {
463 if(!smb_io_notify_info_data(desc, &info->data[i], ps, depth))
464 return False;
467 /* now do the strings at the end of the stream */
468 for (i=0;i<info->count;i++) {
469 if(!smb_io_notify_info_data_strings(desc, &info->data[i], ps, depth))
470 return False;
473 return True;
476 /*******************************************************************
477 ********************************************************************/
479 static BOOL spool_io_user_level_1(char *desc, SPOOL_USER_1 *q_u, prs_struct *ps, int depth)
481 prs_debug(ps, depth, desc, "");
482 depth++;
484 /* reading */
485 if (UNMARSHALLING(ps))
486 ZERO_STRUCTP(q_u);
488 if (!prs_align(ps))
489 return False;
490 if (!prs_uint32("size", ps, depth, &q_u->size))
491 return False;
492 if (!prs_uint32("client_name_ptr", ps, depth, &q_u->client_name_ptr))
493 return False;
494 if (!prs_uint32("user_name_ptr", ps, depth, &q_u->user_name_ptr))
495 return False;
496 if (!prs_uint32("build", ps, depth, &q_u->build))
497 return False;
498 if (!prs_uint32("major", ps, depth, &q_u->major))
499 return False;
500 if (!prs_uint32("minor", ps, depth, &q_u->minor))
501 return False;
502 if (!prs_uint32("processor", ps, depth, &q_u->processor))
503 return False;
505 if (!smb_io_unistr2("", &q_u->client_name, q_u->client_name_ptr, ps, depth))
506 return False;
507 if (!prs_align(ps))
508 return False;
509 if (!smb_io_unistr2("", &q_u->user_name, q_u->user_name_ptr, ps, depth))
510 return False;
512 return True;
515 /*******************************************************************
516 ********************************************************************/
518 static BOOL spool_io_user_level(char *desc, SPOOL_USER_CTR *q_u, prs_struct *ps, int depth)
520 if (q_u==NULL)
521 return False;
523 prs_debug(ps, depth, desc, "spool_io_user_level");
524 depth++;
526 if (!prs_align(ps))
527 return False;
528 if (!prs_uint32("level", ps, depth, &q_u->level))
529 return False;
530 if (!prs_uint32("ptr", ps, depth, &q_u->ptr))
531 return False;
533 switch (q_u->level) {
534 case 1:
535 if (!spool_io_user_level_1("", &q_u->user1, ps, depth))
536 return False;
537 break;
538 default:
539 return False;
542 return True;
545 /*******************************************************************
546 * read or write a DEVICEMODE struct.
547 * on reading allocate memory for the private member
548 ********************************************************************/
550 BOOL spoolss_io_devmode(char *desc, prs_struct *ps, int depth, DEVICEMODE *devmode)
552 prs_debug(ps, depth, desc, "spoolss_io_devmode");
553 depth++;
555 if (UNMARSHALLING(ps)) {
556 devmode->devicename.buffer = (uint16 *)prs_alloc_mem(ps, 32 * sizeof(uint16) );
557 if (devmode->devicename.buffer == NULL)
558 return False;
561 if (!prs_uint16uni(True,"devicename", ps, depth, devmode->devicename.buffer, 32))
562 return False;
563 if (!prs_uint16("specversion", ps, depth, &devmode->specversion))
564 return False;
565 if (!prs_uint16("driverversion", ps, depth, &devmode->driverversion))
566 return False;
567 if (!prs_uint16("size", ps, depth, &devmode->size))
568 return False;
569 if (!prs_uint16("driverextra", ps, depth, &devmode->driverextra))
570 return False;
571 if (!prs_uint32("fields", ps, depth, &devmode->fields))
572 return False;
573 if (!prs_uint16("orientation", ps, depth, &devmode->orientation))
574 return False;
575 if (!prs_uint16("papersize", ps, depth, &devmode->papersize))
576 return False;
577 if (!prs_uint16("paperlength", ps, depth, &devmode->paperlength))
578 return False;
579 if (!prs_uint16("paperwidth", ps, depth, &devmode->paperwidth))
580 return False;
581 if (!prs_uint16("scale", ps, depth, &devmode->scale))
582 return False;
583 if (!prs_uint16("copies", ps, depth, &devmode->copies))
584 return False;
585 if (!prs_uint16("defaultsource", ps, depth, &devmode->defaultsource))
586 return False;
587 if (!prs_uint16("printquality", ps, depth, &devmode->printquality))
588 return False;
589 if (!prs_uint16("color", ps, depth, &devmode->color))
590 return False;
591 if (!prs_uint16("duplex", ps, depth, &devmode->duplex))
592 return False;
593 if (!prs_uint16("yresolution", ps, depth, &devmode->yresolution))
594 return False;
595 if (!prs_uint16("ttoption", ps, depth, &devmode->ttoption))
596 return False;
597 if (!prs_uint16("collate", ps, depth, &devmode->collate))
598 return False;
600 if (UNMARSHALLING(ps)) {
601 devmode->formname.buffer = (uint16 *)prs_alloc_mem(ps, 32 * sizeof(uint16) );
602 if (devmode->formname.buffer == NULL)
603 return False;
606 if (!prs_uint16uni(True, "formname", ps, depth, devmode->formname.buffer, 32))
607 return False;
608 if (!prs_uint16("logpixels", ps, depth, &devmode->logpixels))
609 return False;
610 if (!prs_uint32("bitsperpel", ps, depth, &devmode->bitsperpel))
611 return False;
612 if (!prs_uint32("pelswidth", ps, depth, &devmode->pelswidth))
613 return False;
614 if (!prs_uint32("pelsheight", ps, depth, &devmode->pelsheight))
615 return False;
616 if (!prs_uint32("displayflags", ps, depth, &devmode->displayflags))
617 return False;
618 if (!prs_uint32("displayfrequency", ps, depth, &devmode->displayfrequency))
619 return False;
620 if (!prs_uint32("icmmethod", ps, depth, &devmode->icmmethod))
621 return False;
622 if (!prs_uint32("icmintent", ps, depth, &devmode->icmintent))
623 return False;
624 if (!prs_uint32("mediatype", ps, depth, &devmode->mediatype))
625 return False;
626 if (!prs_uint32("dithertype", ps, depth, &devmode->dithertype))
627 return False;
628 if (!prs_uint32("reserved1", ps, depth, &devmode->reserved1))
629 return False;
630 if (!prs_uint32("reserved2", ps, depth, &devmode->reserved2))
631 return False;
632 if (!prs_uint32("panningwidth", ps, depth, &devmode->panningwidth))
633 return False;
634 if (!prs_uint32("panningheight", ps, depth, &devmode->panningheight))
635 return False;
637 if (devmode->driverextra!=0) {
638 if (UNMARSHALLING(ps)) {
639 devmode->private=(uint8 *)prs_alloc_mem(ps, devmode->driverextra*sizeof(uint8));
640 if(devmode->private == NULL)
641 return False;
642 DEBUG(7,("spoolss_io_devmode: allocated memory [%d] for private\n",devmode->driverextra));
645 DEBUG(7,("spoolss_io_devmode: parsing [%d] bytes of private\n",devmode->driverextra));
646 if (!prs_uint8s(False, "private", ps, depth,
647 devmode->private, devmode->driverextra))
648 return False;
651 return True;
654 /*******************************************************************
655 Read or write a DEVICEMODE container
656 ********************************************************************/
658 static BOOL spoolss_io_devmode_cont(char *desc, DEVMODE_CTR *dm_c, prs_struct *ps, int depth)
660 if (dm_c==NULL)
661 return False;
663 prs_debug(ps, depth, desc, "spoolss_io_devmode_cont");
664 depth++;
666 if(!prs_align(ps))
667 return False;
669 if (!prs_uint32("size", ps, depth, &dm_c->size))
670 return False;
672 if (!prs_uint32("devmode_ptr", ps, depth, &dm_c->devmode_ptr))
673 return False;
675 if (dm_c->size==0 || dm_c->devmode_ptr==0) {
676 if (UNMARSHALLING(ps))
677 /* if while reading there is no DEVMODE ... */
678 dm_c->devmode=NULL;
679 return True;
682 /* so we have a DEVICEMODE to follow */
683 if (UNMARSHALLING(ps)) {
684 DEBUG(9,("Allocating memory for spoolss_io_devmode\n"));
685 dm_c->devmode=(DEVICEMODE *)prs_alloc_mem(ps,sizeof(DEVICEMODE));
686 if(dm_c->devmode == NULL)
687 return False;
690 /* this is bad code, shouldn't be there */
691 if (!prs_uint32("size", ps, depth, &dm_c->size))
692 return False;
694 if (!spoolss_io_devmode(desc, ps, depth, dm_c->devmode))
695 return False;
697 return True;
700 /*******************************************************************
701 ********************************************************************/
703 static BOOL spoolss_io_printer_default(char *desc, PRINTER_DEFAULT *pd, prs_struct *ps, int depth)
705 if (pd==NULL)
706 return False;
708 prs_debug(ps, depth, desc, "spoolss_io_printer_default");
709 depth++;
711 if (!prs_uint32("datatype_ptr", ps, depth, &pd->datatype_ptr))
712 return False;
714 if (!smb_io_unistr2("datatype", &pd->datatype, pd->datatype_ptr, ps,depth))
715 return False;
717 if (!prs_align(ps))
718 return False;
720 if (!spoolss_io_devmode_cont("", &pd->devmode_cont, ps, depth))
721 return False;
723 if (!prs_uint32("access_required", ps, depth, &pd->access_required))
724 return False;
726 return True;
729 /*******************************************************************
730 * init a structure.
731 ********************************************************************/
733 BOOL make_spoolss_q_open_printer_ex(SPOOL_Q_OPEN_PRINTER_EX *q_u,
734 const fstring printername,
735 const fstring datatype,
736 uint32 access_required,
737 const fstring clientname,
738 const fstring user_name)
740 DEBUG(5,("make_spoolss_q_open_printer_ex\n"));
741 q_u->printername_ptr = (printername!=NULL)?1:0;
742 init_unistr2(&q_u->printername, printername, strlen(printername)+1);
744 q_u->printer_default.datatype_ptr = 0;
746 q_u->printer_default.datatype_ptr = (datatype!=NULL)?1:0;
747 init_unistr2(&q_u->printer_default.datatype, datatype, strlen(datatype));
749 q_u->printer_default.devmode_cont.size=0;
750 q_u->printer_default.devmode_cont.devmode_ptr=0;
751 q_u->printer_default.devmode_cont.devmode=NULL;
752 q_u->printer_default.access_required=access_required;
753 q_u->user_switch=1;
754 q_u->user_ctr.level=1;
755 q_u->user_ctr.ptr=1;
756 q_u->user_ctr.user1.size=strlen(clientname)+strlen(user_name)+10;
757 q_u->user_ctr.user1.client_name_ptr = (clientname!=NULL)?1:0;
758 q_u->user_ctr.user1.user_name_ptr = (user_name!=NULL)?1:0;
759 q_u->user_ctr.user1.build=1381;
760 q_u->user_ctr.user1.major=2;
761 q_u->user_ctr.user1.minor=0;
762 q_u->user_ctr.user1.processor=0;
763 init_unistr2(&q_u->user_ctr.user1.client_name, clientname, strlen(clientname)+1);
764 init_unistr2(&q_u->user_ctr.user1.user_name, user_name, strlen(user_name)+1);
766 return True;
769 /*******************************************************************
770 * init a structure.
771 ********************************************************************/
773 BOOL make_spoolss_q_addprinterex(
774 TALLOC_CTX *mem_ctx,
775 SPOOL_Q_ADDPRINTEREX *q_u,
776 const char *srv_name,
777 const char* clientname,
778 const char* user_name,
779 uint32 level,
780 PRINTER_INFO_CTR *ctr)
782 DEBUG(5,("make_spoolss_q_addprinterex\n"));
784 if (!ctr) return False;
786 ZERO_STRUCTP(q_u);
788 q_u->server_name_ptr = (srv_name!=NULL)?1:0;
789 init_unistr2(&q_u->server_name, srv_name, strlen(srv_name));
791 q_u->level = level;
793 q_u->info.level = level;
794 q_u->info.info_ptr = (ctr->printers_2!=NULL)?1:0;
795 switch (level) {
796 case 2:
797 /* init q_u->info.info2 from *info */
798 if (!make_spoolss_printer_info_2(mem_ctx, &q_u->info.info_2, ctr->printers_2)) {
799 DEBUG(0,("make_spoolss_q_addprinterex: Unable to fill SPOOL_Q_ADDPRINTEREX struct!\n"));
800 return False;
802 break;
803 default :
804 break;
807 q_u->user_switch=1;
809 q_u->user_ctr.level=1;
810 q_u->user_ctr.ptr=1;
811 q_u->user_ctr.user1.client_name_ptr = (clientname!=NULL)?1:0;
812 q_u->user_ctr.user1.user_name_ptr = (user_name!=NULL)?1:0;
813 q_u->user_ctr.user1.build=1381;
814 q_u->user_ctr.user1.major=2;
815 q_u->user_ctr.user1.minor=0;
816 q_u->user_ctr.user1.processor=0;
817 init_unistr2(&q_u->user_ctr.user1.client_name, clientname, strlen(clientname)+1);
818 init_unistr2(&q_u->user_ctr.user1.user_name, user_name, strlen(user_name)+1);
819 q_u->user_ctr.user1.size=q_u->user_ctr.user1.user_name.uni_str_len +
820 q_u->user_ctr.user1.client_name.uni_str_len + 2;
822 return True;
825 /*******************************************************************
826 create a SPOOL_PRINTER_INFO_2 stuct from a PRINTER_INFO_2 struct
827 *******************************************************************/
829 BOOL make_spoolss_printer_info_2(TALLOC_CTX *mem_ctx, SPOOL_PRINTER_INFO_LEVEL_2 **spool_info2,
830 PRINTER_INFO_2 *info)
833 SPOOL_PRINTER_INFO_LEVEL_2 *inf;
835 /* allocate the necessary memory */
836 if (!(inf=(SPOOL_PRINTER_INFO_LEVEL_2*)talloc(mem_ctx, sizeof(SPOOL_PRINTER_INFO_LEVEL_2)))) {
837 DEBUG(0,("make_spoolss_printer_info_2: Unable to allocate SPOOL_PRINTER_INFO_LEVEL_2 sruct!\n"));
838 return False;
841 inf->servername_ptr = (info->servername.buffer!=NULL)?1:0;
842 inf->printername_ptr = (info->printername.buffer!=NULL)?1:0;
843 inf->sharename_ptr = (info->sharename.buffer!=NULL)?1:0;
844 inf->portname_ptr = (info->portname.buffer!=NULL)?1:0;
845 inf->drivername_ptr = (info->drivername.buffer!=NULL)?1:0;
846 inf->comment_ptr = (info->comment.buffer!=NULL)?1:0;
847 inf->location_ptr = (info->location.buffer!=NULL)?1:0;
848 inf->devmode_ptr = (info->devmode!=NULL)?1:0;
849 inf->sepfile_ptr = (info->sepfile.buffer!=NULL)?1:0;
850 inf->printprocessor_ptr = (info->printprocessor.buffer!=NULL)?1:0;
851 inf->datatype_ptr = (info->datatype.buffer!=NULL)?1:0;
852 inf->parameters_ptr = (info->parameters.buffer!=NULL)?1:0;
853 inf->secdesc_ptr = (info->secdesc!=NULL)?1:0;
854 inf->attributes = info->attributes;
855 inf->priority = info->priority;
856 inf->default_priority = info->defaultpriority;
857 inf->starttime = info->starttime;
858 inf->untiltime = info->untiltime;
859 inf->cjobs = info->cjobs;
860 inf->averageppm = info->averageppm;
861 init_unistr2_from_unistr(&inf->servername, &info->servername);
862 init_unistr2_from_unistr(&inf->printername, &info->printername);
863 init_unistr2_from_unistr(&inf->sharename, &info->sharename);
864 init_unistr2_from_unistr(&inf->portname, &info->portname);
865 init_unistr2_from_unistr(&inf->drivername, &info->drivername);
866 init_unistr2_from_unistr(&inf->comment, &info->comment);
867 init_unistr2_from_unistr(&inf->location, &info->location);
868 init_unistr2_from_unistr(&inf->sepfile, &info->sepfile);
869 init_unistr2_from_unistr(&inf->printprocessor, &info->printprocessor);
870 init_unistr2_from_unistr(&inf->datatype, &info->datatype);
871 init_unistr2_from_unistr(&inf->parameters, &info->parameters);
872 init_unistr2_from_unistr(&inf->datatype, &info->datatype);
874 *spool_info2 = inf;
876 return True;
879 /*******************************************************************
880 * read a structure.
881 * called from spoolss_q_open_printer_ex (srv_spoolss.c)
882 ********************************************************************/
884 BOOL spoolss_io_q_open_printer_ex(char *desc, SPOOL_Q_OPEN_PRINTER_EX *q_u, prs_struct *ps, int depth)
886 if (q_u == NULL)
887 return False;
889 prs_debug(ps, depth, desc, "spoolss_io_q_open_printer_ex");
890 depth++;
892 if (!prs_align(ps))
893 return False;
895 if (!prs_uint32("printername_ptr", ps, depth, &q_u->printername_ptr))
896 return False;
897 if (!smb_io_unistr2("", &q_u->printername, q_u->printername_ptr, ps,depth))
898 return False;
900 if (!prs_align(ps))
901 return False;
903 if (!spoolss_io_printer_default("", &q_u->printer_default, ps, depth))
904 return False;
906 if (!prs_uint32("user_switch", ps, depth, &q_u->user_switch))
907 return False;
908 if (!spool_io_user_level("", &q_u->user_ctr, ps, depth))
909 return False;
911 return True;
914 /*******************************************************************
915 * init a structure.
916 ********************************************************************/
917 BOOL make_spoolss_q_deleteprinterdriver(
918 TALLOC_CTX *mem_ctx,
919 SPOOL_Q_DELETEPRINTERDRIVER *q_u,
920 const char *server,
921 const char* arch,
922 const char* driver
925 DEBUG(5,("make_spoolss_q_deleteprinterdriver\n"));
927 q_u->server_ptr = (server!=NULL)?1:0;
929 /* these must be NULL terminated or else NT4 will
930 complain about invalid parameters --jerry */
931 init_unistr2(&q_u->server, server, strlen(server)+1);
932 init_unistr2(&q_u->arch, arch, strlen(arch)+1);
933 init_unistr2(&q_u->driver, driver, strlen(driver)+1);
936 return True;
939 /*******************************************************************
940 * write a structure.
941 * called from static spoolss_r_open_printer_ex (srv_spoolss.c)
942 * called from spoolss_open_printer_ex (cli_spoolss.c)
943 ********************************************************************/
945 BOOL spoolss_io_r_open_printer_ex(char *desc, SPOOL_R_OPEN_PRINTER_EX *r_u, prs_struct *ps, int depth)
947 if (r_u == NULL) return False;
949 prs_debug(ps, depth, desc, "spoolss_io_r_open_printer_ex");
950 depth++;
952 if (!prs_align(ps))
953 return False;
955 if (!smb_io_pol_hnd("printer handle",&(r_u->handle),ps,depth))
956 return False;
958 if (!prs_werror("status code", ps, depth, &(r_u->status)))
959 return False;
961 return True;
964 /*******************************************************************
965 * make a structure.
966 ********************************************************************/
968 BOOL make_spoolss_q_getprinterdata(SPOOL_Q_GETPRINTERDATA *q_u,
969 const POLICY_HND *handle,
970 UNISTR2 *valuename, uint32 size)
972 if (q_u == NULL) return False;
974 DEBUG(5,("make_spoolss_q_getprinterdata\n"));
976 q_u->handle = *handle;
977 copy_unistr2(&q_u->valuename, valuename);
978 q_u->size = size;
980 return True;
983 /*******************************************************************
984 * read a structure.
985 * called from spoolss_q_getprinterdata (srv_spoolss.c)
986 ********************************************************************/
988 BOOL spoolss_io_q_getprinterdata(char *desc, SPOOL_Q_GETPRINTERDATA *q_u, prs_struct *ps, int depth)
990 if (q_u == NULL)
991 return False;
993 prs_debug(ps, depth, desc, "spoolss_io_q_getprinterdata");
994 depth++;
996 if (!prs_align(ps))
997 return False;
998 if (!smb_io_pol_hnd("printer handle",&q_u->handle,ps,depth))
999 return False;
1000 if (!prs_align(ps))
1001 return False;
1002 if (!smb_io_unistr2("valuename", &q_u->valuename,True,ps,depth))
1003 return False;
1004 if (!prs_align(ps))
1005 return False;
1006 if (!prs_uint32("size", ps, depth, &q_u->size))
1007 return False;
1009 return True;
1012 /*******************************************************************
1013 * read a structure.
1014 * called from spoolss_q_deleteprinterdata (srv_spoolss.c)
1015 ********************************************************************/
1017 BOOL spoolss_io_q_deleteprinterdata(char *desc, SPOOL_Q_DELETEPRINTERDATA *q_u, prs_struct *ps, int depth)
1019 if (q_u == NULL)
1020 return False;
1022 prs_debug(ps, depth, desc, "spoolss_io_q_deleteprinterdata");
1023 depth++;
1025 if (!prs_align(ps))
1026 return False;
1027 if (!smb_io_pol_hnd("printer handle",&q_u->handle,ps,depth))
1028 return False;
1029 if (!prs_align(ps))
1030 return False;
1031 if (!smb_io_unistr2("valuename", &q_u->valuename,True,ps,depth))
1032 return False;
1034 return True;
1037 /*******************************************************************
1038 * write a structure.
1039 * called from spoolss_r_deleteprinterdata (srv_spoolss.c)
1040 ********************************************************************/
1042 BOOL spoolss_io_r_deleteprinterdata(char *desc, SPOOL_R_DELETEPRINTERDATA *r_u, prs_struct *ps, int depth)
1044 prs_debug(ps, depth, desc, "spoolss_io_r_deleteprinterdata");
1045 depth++;
1046 if(!prs_werror("status", ps, depth, &r_u->status))
1047 return False;
1049 return True;
1052 /*******************************************************************
1053 * write a structure.
1054 * called from spoolss_r_getprinterdata (srv_spoolss.c)
1055 ********************************************************************/
1057 BOOL spoolss_io_r_getprinterdata(char *desc, SPOOL_R_GETPRINTERDATA *r_u, prs_struct *ps, int depth)
1059 if (r_u == NULL)
1060 return False;
1062 prs_debug(ps, depth, desc, "spoolss_io_r_getprinterdata");
1063 depth++;
1065 if (!prs_align(ps))
1066 return False;
1067 if (!prs_uint32("type", ps, depth, &r_u->type))
1068 return False;
1069 if (!prs_uint32("size", ps, depth, &r_u->size))
1070 return False;
1072 if (!prs_uint8s(False,"data", ps, depth, r_u->data, r_u->size))
1073 return False;
1075 if (!prs_align(ps))
1076 return False;
1078 if (!prs_uint32("needed", ps, depth, &r_u->needed))
1079 return False;
1080 if (!prs_werror("status", ps, depth, &r_u->status))
1081 return False;
1083 return True;
1086 /*******************************************************************
1087 * make a structure.
1088 ********************************************************************/
1090 BOOL make_spoolss_q_closeprinter(SPOOL_Q_CLOSEPRINTER *q_u, POLICY_HND *hnd)
1092 if (q_u == NULL) return False;
1094 DEBUG(5,("make_spoolss_q_closeprinter\n"));
1096 memcpy(&q_u->handle, hnd, sizeof(q_u->handle));
1098 return True;
1101 /*******************************************************************
1102 * read a structure.
1103 * called from static spoolss_q_abortprinter (srv_spoolss.c)
1104 * called from spoolss_abortprinter (cli_spoolss.c)
1105 ********************************************************************/
1107 BOOL spoolss_io_q_abortprinter(char *desc, SPOOL_Q_ABORTPRINTER *q_u, prs_struct *ps, int depth)
1109 if (q_u == NULL) return False;
1111 prs_debug(ps, depth, desc, "spoolss_io_q_abortprinter");
1112 depth++;
1114 if (!prs_align(ps))
1115 return False;
1117 if (!smb_io_pol_hnd("printer handle",&q_u->handle,ps,depth))
1118 return False;
1120 return True;
1123 /*******************************************************************
1124 * write a structure.
1125 * called from spoolss_r_abortprinter (srv_spoolss.c)
1126 ********************************************************************/
1128 BOOL spoolss_io_r_abortprinter(char *desc, SPOOL_R_ABORTPRINTER *r_u, prs_struct *ps, int depth)
1130 prs_debug(ps, depth, desc, "spoolss_io_r_abortprinter");
1131 depth++;
1132 if(!prs_werror("status", ps, depth, &r_u->status))
1133 return False;
1135 return True;
1138 /*******************************************************************
1139 * read a structure.
1140 * called from static spoolss_q_deleteprinter (srv_spoolss.c)
1141 * called from spoolss_deleteprinter (cli_spoolss.c)
1142 ********************************************************************/
1144 BOOL spoolss_io_q_deleteprinter(char *desc, SPOOL_Q_DELETEPRINTER *q_u, prs_struct *ps, int depth)
1146 if (q_u == NULL) return False;
1148 prs_debug(ps, depth, desc, "spoolss_io_q_deleteprinter");
1149 depth++;
1151 if (!prs_align(ps))
1152 return False;
1154 if (!smb_io_pol_hnd("printer handle",&q_u->handle,ps,depth))
1155 return False;
1157 return True;
1160 /*******************************************************************
1161 * write a structure.
1162 * called from static spoolss_r_deleteprinter (srv_spoolss.c)
1163 * called from spoolss_deleteprinter (cli_spoolss.c)
1164 ********************************************************************/
1166 BOOL spoolss_io_r_deleteprinter(char *desc, SPOOL_R_DELETEPRINTER *r_u, prs_struct *ps, int depth)
1168 prs_debug(ps, depth, desc, "spoolss_io_r_deleteprinter");
1169 depth++;
1171 if (!prs_align(ps))
1172 return False;
1174 if (!smb_io_pol_hnd("printer handle",&r_u->handle,ps,depth))
1175 return False;
1176 if (!prs_werror("status", ps, depth, &r_u->status))
1177 return False;
1179 return True;
1183 /*******************************************************************
1184 * read a structure.
1185 * called from api_spoolss_deleteprinterdriver (srv_spoolss.c)
1186 * called from spoolss_deleteprinterdriver (cli_spoolss.c)
1187 ********************************************************************/
1189 BOOL spoolss_io_q_deleteprinterdriver(char *desc, SPOOL_Q_DELETEPRINTERDRIVER *q_u, prs_struct *ps, int depth)
1191 if (q_u == NULL) return False;
1193 prs_debug(ps, depth, desc, "spoolss_io_q_deleteprinterdriver");
1194 depth++;
1196 if (!prs_align(ps))
1197 return False;
1199 if(!prs_uint32("server_ptr", ps, depth, &q_u->server_ptr))
1200 return False;
1201 if(!smb_io_unistr2("server", &q_u->server, q_u->server_ptr, ps, depth))
1202 return False;
1203 if(!smb_io_unistr2("arch", &q_u->arch, True, ps, depth))
1204 return False;
1205 if(!smb_io_unistr2("driver", &q_u->driver, True, ps, depth))
1206 return False;
1209 return True;
1213 /*******************************************************************
1214 * write a structure.
1215 ********************************************************************/
1216 BOOL spoolss_io_r_deleteprinterdriver(char *desc, SPOOL_R_DELETEPRINTERDRIVER *r_u, prs_struct *ps, int depth)
1218 if (r_u == NULL) return False;
1220 prs_debug(ps, depth, desc, "spoolss_io_r_deleteprinterdriver");
1221 depth++;
1223 if (!prs_align(ps))
1224 return False;
1226 if (!prs_werror("status", ps, depth, &r_u->status))
1227 return False;
1229 return True;
1234 /*******************************************************************
1235 * read a structure.
1236 * called from static spoolss_q_closeprinter (srv_spoolss.c)
1237 * called from spoolss_closeprinter (cli_spoolss.c)
1238 ********************************************************************/
1240 BOOL spoolss_io_q_closeprinter(char *desc, SPOOL_Q_CLOSEPRINTER *q_u, prs_struct *ps, int depth)
1242 if (q_u == NULL) return False;
1244 prs_debug(ps, depth, desc, "spoolss_io_q_closeprinter");
1245 depth++;
1247 if (!prs_align(ps))
1248 return False;
1250 if (!smb_io_pol_hnd("printer handle",&q_u->handle,ps,depth))
1251 return False;
1253 return True;
1256 /*******************************************************************
1257 * write a structure.
1258 * called from static spoolss_r_closeprinter (srv_spoolss.c)
1259 * called from spoolss_closeprinter (cli_spoolss.c)
1260 ********************************************************************/
1262 BOOL spoolss_io_r_closeprinter(char *desc, SPOOL_R_CLOSEPRINTER *r_u, prs_struct *ps, int depth)
1264 prs_debug(ps, depth, desc, "spoolss_io_r_closeprinter");
1265 depth++;
1267 if (!prs_align(ps))
1268 return False;
1270 if (!smb_io_pol_hnd("printer handle",&r_u->handle,ps,depth))
1271 return False;
1272 if (!prs_werror("status", ps, depth, &r_u->status))
1273 return False;
1275 return True;
1278 /*******************************************************************
1279 * read a structure.
1280 * called from spoolss_q_startdocprinter (srv_spoolss.c)
1281 ********************************************************************/
1283 BOOL spoolss_io_q_startdocprinter(char *desc, SPOOL_Q_STARTDOCPRINTER *q_u, prs_struct *ps, int depth)
1285 if (q_u == NULL) return False;
1287 prs_debug(ps, depth, desc, "spoolss_io_q_startdocprinter");
1288 depth++;
1290 if(!prs_align(ps))
1291 return False;
1293 if(!smb_io_pol_hnd("printer handle",&q_u->handle,ps,depth))
1294 return False;
1296 if(!smb_io_doc_info_container("",&q_u->doc_info_container, ps, depth))
1297 return False;
1299 return True;
1302 /*******************************************************************
1303 * write a structure.
1304 * called from spoolss_r_startdocprinter (srv_spoolss.c)
1305 ********************************************************************/
1307 BOOL spoolss_io_r_startdocprinter(char *desc, SPOOL_R_STARTDOCPRINTER *r_u, prs_struct *ps, int depth)
1309 prs_debug(ps, depth, desc, "spoolss_io_r_startdocprinter");
1310 depth++;
1311 if(!prs_uint32("jobid", ps, depth, &r_u->jobid))
1312 return False;
1313 if(!prs_werror("status", ps, depth, &r_u->status))
1314 return False;
1316 return True;
1319 /*******************************************************************
1320 * read a structure.
1321 * called from spoolss_q_enddocprinter (srv_spoolss.c)
1322 ********************************************************************/
1324 BOOL spoolss_io_q_enddocprinter(char *desc, SPOOL_Q_ENDDOCPRINTER *q_u, prs_struct *ps, int depth)
1326 if (q_u == NULL) return False;
1328 prs_debug(ps, depth, desc, "spoolss_io_q_enddocprinter");
1329 depth++;
1331 if(!prs_align(ps))
1332 return False;
1334 if(!smb_io_pol_hnd("printer handle",&q_u->handle,ps,depth))
1335 return False;
1337 return True;
1340 /*******************************************************************
1341 * write a structure.
1342 * called from spoolss_r_enddocprinter (srv_spoolss.c)
1343 ********************************************************************/
1345 BOOL spoolss_io_r_enddocprinter(char *desc, SPOOL_R_ENDDOCPRINTER *r_u, prs_struct *ps, int depth)
1347 prs_debug(ps, depth, desc, "spoolss_io_r_enddocprinter");
1348 depth++;
1349 if(!prs_werror("status", ps, depth, &r_u->status))
1350 return False;
1352 return True;
1355 /*******************************************************************
1356 * read a structure.
1357 * called from spoolss_q_startpageprinter (srv_spoolss.c)
1358 ********************************************************************/
1360 BOOL spoolss_io_q_startpageprinter(char *desc, SPOOL_Q_STARTPAGEPRINTER *q_u, prs_struct *ps, int depth)
1362 if (q_u == NULL) return False;
1364 prs_debug(ps, depth, desc, "spoolss_io_q_startpageprinter");
1365 depth++;
1367 if(!prs_align(ps))
1368 return False;
1370 if(!smb_io_pol_hnd("printer handle",&q_u->handle,ps,depth))
1371 return False;
1373 return True;
1376 /*******************************************************************
1377 * write a structure.
1378 * called from spoolss_r_startpageprinter (srv_spoolss.c)
1379 ********************************************************************/
1381 BOOL spoolss_io_r_startpageprinter(char *desc, SPOOL_R_STARTPAGEPRINTER *r_u, prs_struct *ps, int depth)
1383 prs_debug(ps, depth, desc, "spoolss_io_r_startpageprinter");
1384 depth++;
1385 if(!prs_werror("status", ps, depth, &r_u->status))
1386 return False;
1388 return True;
1391 /*******************************************************************
1392 * read a structure.
1393 * called from spoolss_q_endpageprinter (srv_spoolss.c)
1394 ********************************************************************/
1396 BOOL spoolss_io_q_endpageprinter(char *desc, SPOOL_Q_ENDPAGEPRINTER *q_u, prs_struct *ps, int depth)
1398 if (q_u == NULL) return False;
1400 prs_debug(ps, depth, desc, "spoolss_io_q_endpageprinter");
1401 depth++;
1403 if(!prs_align(ps))
1404 return False;
1406 if(!smb_io_pol_hnd("printer handle",&q_u->handle,ps,depth))
1407 return False;
1409 return True;
1412 /*******************************************************************
1413 * write a structure.
1414 * called from spoolss_r_endpageprinter (srv_spoolss.c)
1415 ********************************************************************/
1417 BOOL spoolss_io_r_endpageprinter(char *desc, SPOOL_R_ENDPAGEPRINTER *r_u, prs_struct *ps, int depth)
1419 prs_debug(ps, depth, desc, "spoolss_io_r_endpageprinter");
1420 depth++;
1421 if(!prs_werror("status", ps, depth, &r_u->status))
1422 return False;
1424 return True;
1427 /*******************************************************************
1428 * read a structure.
1429 * called from spoolss_q_writeprinter (srv_spoolss.c)
1430 ********************************************************************/
1432 BOOL spoolss_io_q_writeprinter(char *desc, SPOOL_Q_WRITEPRINTER *q_u, prs_struct *ps, int depth)
1434 if (q_u == NULL) return False;
1436 prs_debug(ps, depth, desc, "spoolss_io_q_writeprinter");
1437 depth++;
1439 if(!prs_align(ps))
1440 return False;
1442 if(!smb_io_pol_hnd("printer handle",&q_u->handle,ps,depth))
1443 return False;
1444 if(!prs_uint32("buffer_size", ps, depth, &q_u->buffer_size))
1445 return False;
1447 if (q_u->buffer_size!=0)
1449 if (UNMARSHALLING(ps))
1450 q_u->buffer=(uint8 *)prs_alloc_mem(ps,q_u->buffer_size*sizeof(uint8));
1451 if(q_u->buffer == NULL)
1452 return False;
1453 if(!prs_uint8s(True, "buffer", ps, depth, q_u->buffer, q_u->buffer_size))
1454 return False;
1456 if(!prs_align(ps))
1457 return False;
1458 if(!prs_uint32("buffer_size2", ps, depth, &q_u->buffer_size2))
1459 return False;
1461 return True;
1464 /*******************************************************************
1465 * write a structure.
1466 * called from spoolss_r_writeprinter (srv_spoolss.c)
1467 ********************************************************************/
1469 BOOL spoolss_io_r_writeprinter(char *desc, SPOOL_R_WRITEPRINTER *r_u, prs_struct *ps, int depth)
1471 prs_debug(ps, depth, desc, "spoolss_io_r_writeprinter");
1472 depth++;
1473 if(!prs_uint32("buffer_written", ps, depth, &r_u->buffer_written))
1474 return False;
1475 if(!prs_werror("status", ps, depth, &r_u->status))
1476 return False;
1478 return True;
1481 /*******************************************************************
1482 * read a structure.
1483 * called from spoolss_q_rffpcnex (srv_spoolss.c)
1484 ********************************************************************/
1486 BOOL spoolss_io_q_rffpcnex(char *desc, SPOOL_Q_RFFPCNEX *q_u, prs_struct *ps, int depth)
1488 prs_debug(ps, depth, desc, "spoolss_io_q_rffpcnex");
1489 depth++;
1491 if(!prs_align(ps))
1492 return False;
1494 if(!smb_io_pol_hnd("printer handle", &q_u->handle, ps, depth))
1495 return False;
1496 if(!prs_uint32("flags", ps, depth, &q_u->flags))
1497 return False;
1498 if(!prs_uint32("options", ps, depth, &q_u->options))
1499 return False;
1500 if(!prs_uint32("localmachine_ptr", ps, depth, &q_u->localmachine_ptr))
1501 return False;
1502 if(!smb_io_unistr2("localmachine", &q_u->localmachine, q_u->localmachine_ptr, ps, depth))
1503 return False;
1505 if(!prs_align(ps))
1506 return False;
1508 if(!prs_uint32("printerlocal", ps, depth, &q_u->printerlocal))
1509 return False;
1511 if(!prs_uint32("option_ptr", ps, depth, &q_u->option_ptr))
1512 return False;
1514 if (q_u->option_ptr!=0) {
1516 if (UNMARSHALLING(ps))
1517 if((q_u->option=(SPOOL_NOTIFY_OPTION *)prs_alloc_mem(ps,sizeof(SPOOL_NOTIFY_OPTION))) == NULL)
1518 return False;
1520 if(!smb_io_notify_option("notify option", q_u->option, ps, depth))
1521 return False;
1524 return True;
1527 /*******************************************************************
1528 * write a structure.
1529 * called from spoolss_r_rffpcnex (srv_spoolss.c)
1530 ********************************************************************/
1532 BOOL spoolss_io_r_rffpcnex(char *desc, SPOOL_R_RFFPCNEX *r_u, prs_struct *ps, int depth)
1534 prs_debug(ps, depth, desc, "spoolss_io_r_rffpcnex");
1535 depth++;
1537 if(!prs_werror("status", ps, depth, &r_u->status))
1538 return False;
1540 return True;
1543 /*******************************************************************
1544 * read a structure.
1545 * called from spoolss_q_rfnpcnex (srv_spoolss.c)
1546 ********************************************************************/
1548 BOOL spoolss_io_q_rfnpcnex(char *desc, SPOOL_Q_RFNPCNEX *q_u, prs_struct *ps, int depth)
1550 prs_debug(ps, depth, desc, "spoolss_io_q_rfnpcnex");
1551 depth++;
1553 if(!prs_align(ps))
1554 return False;
1556 if(!smb_io_pol_hnd("printer handle",&q_u->handle,ps,depth))
1557 return False;
1559 if(!prs_uint32("change", ps, depth, &q_u->change))
1560 return False;
1562 if(!prs_uint32("option_ptr", ps, depth, &q_u->option_ptr))
1563 return False;
1565 if (q_u->option_ptr!=0) {
1567 if (UNMARSHALLING(ps))
1568 if((q_u->option=(SPOOL_NOTIFY_OPTION *)prs_alloc_mem(ps,sizeof(SPOOL_NOTIFY_OPTION))) == NULL)
1569 return False;
1571 if(!smb_io_notify_option("notify option", q_u->option, ps, depth))
1572 return False;
1575 return True;
1578 /*******************************************************************
1579 * write a structure.
1580 * called from spoolss_r_rfnpcnex (srv_spoolss.c)
1581 ********************************************************************/
1583 BOOL spoolss_io_r_rfnpcnex(char *desc, SPOOL_R_RFNPCNEX *r_u, prs_struct *ps, int depth)
1585 prs_debug(ps, depth, desc, "spoolss_io_r_rfnpcnex");
1586 depth++;
1588 if(!prs_align(ps))
1589 return False;
1591 if (!prs_uint32("info_ptr", ps, depth, &r_u->info_ptr))
1592 return False;
1594 if(!smb_io_notify_info("notify info", &r_u->info ,ps,depth))
1595 return False;
1597 if(!prs_align(ps))
1598 return False;
1599 if(!prs_werror("status", ps, depth, &r_u->status))
1600 return False;
1602 return True;
1605 /*******************************************************************
1606 * return the length of a uint16 (obvious, but the code is clean)
1607 ********************************************************************/
1609 static uint32 size_of_uint16(uint16 *value)
1611 return (sizeof(*value));
1614 /*******************************************************************
1615 * return the length of a uint32 (obvious, but the code is clean)
1616 ********************************************************************/
1618 static uint32 size_of_uint32(uint32 *value)
1620 return (sizeof(*value));
1623 /*******************************************************************
1624 * return the length of a NTTIME (obvious, but the code is clean)
1625 ********************************************************************/
1627 static uint32 size_of_nttime(NTTIME *value)
1629 return (sizeof(*value));
1632 /*******************************************************************
1633 * return the length of a UNICODE string in number of char, includes:
1634 * - the leading zero
1635 * - the relative pointer size
1636 ********************************************************************/
1638 static uint32 size_of_relative_string(UNISTR *string)
1640 uint32 size=0;
1642 size=str_len_uni(string); /* the string length */
1643 size=size+1; /* add the leading zero */
1644 size=size*2; /* convert in char */
1645 /* Ensure size is 4 byte multiple (prs_align is being called...). */
1646 size += ((4 - (size & 3)) & 3);
1647 size=size+4; /* add the size of the ptr */
1649 return size;
1652 /*******************************************************************
1653 * return the length of a uint32 (obvious, but the code is clean)
1654 ********************************************************************/
1656 static uint32 size_of_device_mode(DEVICEMODE *devmode)
1658 if (devmode==NULL)
1659 return (4);
1660 else
1661 return (4+devmode->size+devmode->driverextra);
1664 /*******************************************************************
1665 * return the length of a uint32 (obvious, but the code is clean)
1666 ********************************************************************/
1668 static uint32 size_of_systemtime(SYSTEMTIME *systime)
1670 if (systime==NULL)
1671 return (4);
1672 else
1673 return (sizeof(SYSTEMTIME) +4);
1676 /*******************************************************************
1677 * write a UNICODE string.
1678 * used by all the RPC structs passing a buffer
1679 ********************************************************************/
1681 static BOOL spoolss_smb_io_unistr(char *desc, UNISTR *uni, prs_struct *ps, int depth)
1683 if (uni == NULL)
1684 return False;
1686 prs_debug(ps, depth, desc, "spoolss_smb_io_unistr");
1687 depth++;
1689 /* there should be no align here as it can mess up
1690 parsing a NEW_BUFFER->prs */
1691 #if 0 /* JERRY */
1692 if (!prs_align(ps))
1693 return False;
1694 #endif
1696 if (!prs_unistr("unistr", ps, depth, uni))
1697 return False;
1699 return True;
1702 /*******************************************************************
1703 * write a UNICODE string and its relative pointer.
1704 * used by all the RPC structs passing a buffer
1706 * As I'm a nice guy, I'm forcing myself to explain this code.
1707 * MS did a good job in the overall spoolss code except in some
1708 * functions where they are passing the API buffer directly in the
1709 * RPC request/reply. That's to maintain compatiility at the API level.
1710 * They could have done it the good way the first time.
1712 * So what happen is: the strings are written at the buffer's end,
1713 * in the reverse order of the original structure. Some pointers to
1714 * the strings are also in the buffer. Those are relative to the
1715 * buffer's start.
1717 * If you don't understand or want to change that function,
1718 * first get in touch with me: jfm@samba.org
1720 ********************************************************************/
1722 static BOOL smb_io_relstr(char *desc, NEW_BUFFER *buffer, int depth, UNISTR *string)
1724 prs_struct *ps=&buffer->prs;
1726 if (MARSHALLING(ps)) {
1727 uint32 struct_offset = prs_offset(ps);
1728 uint32 relative_offset;
1730 buffer->string_at_end -= (size_of_relative_string(string) - 4);
1731 if(!prs_set_offset(ps, buffer->string_at_end))
1732 return False;
1733 if (!prs_align(ps))
1734 return False;
1735 buffer->string_at_end = prs_offset(ps);
1737 /* write the string */
1738 if (!smb_io_unistr(desc, string, ps, depth))
1739 return False;
1741 if(!prs_set_offset(ps, struct_offset))
1742 return False;
1744 relative_offset=buffer->string_at_end - buffer->struct_start;
1745 /* write its offset */
1746 if (!prs_uint32("offset", ps, depth, &relative_offset))
1747 return False;
1749 else {
1750 uint32 old_offset;
1752 /* read the offset */
1753 if (!prs_uint32("offset", ps, depth, &(buffer->string_at_end)))
1754 return False;
1756 old_offset = prs_offset(ps);
1757 if(!prs_set_offset(ps, buffer->string_at_end+buffer->struct_start))
1758 return False;
1760 /* read the string */
1761 if (!spoolss_smb_io_unistr(desc, string, ps, depth))
1762 return False;
1764 if(!prs_set_offset(ps, old_offset))
1765 return False;
1767 return True;
1770 /*******************************************************************
1771 * write a array of UNICODE strings and its relative pointer.
1772 * used by 2 RPC structs
1773 ********************************************************************/
1775 static BOOL smb_io_relarraystr(char *desc, NEW_BUFFER *buffer, int depth, uint16 **string)
1777 UNISTR chaine;
1779 prs_struct *ps=&buffer->prs;
1781 if (MARSHALLING(ps)) {
1782 uint32 struct_offset = prs_offset(ps);
1783 uint32 relative_offset;
1784 uint16 *p;
1785 uint16 *q;
1786 uint16 zero=0;
1787 p=*string;
1788 q=*string;
1790 /* first write the last 0 */
1791 buffer->string_at_end -= 2;
1792 if(!prs_set_offset(ps, buffer->string_at_end))
1793 return False;
1795 if(!prs_uint16("leading zero", ps, depth, &zero))
1796 return False;
1798 while (p && (*p!=0)) {
1799 while (*q!=0)
1800 q++;
1802 /* Yes this should be malloc not talloc. Don't change. */
1804 chaine.buffer = malloc((q-p+1)*sizeof(uint16));
1805 if (chaine.buffer == NULL)
1806 return False;
1808 memcpy(chaine.buffer, p, (q-p+1)*sizeof(uint16));
1810 buffer->string_at_end -= (q-p+1)*sizeof(uint16);
1812 if(!prs_set_offset(ps, buffer->string_at_end)) {
1813 SAFE_FREE(chaine.buffer);
1814 return False;
1817 /* write the string */
1818 if (!spoolss_smb_io_unistr(desc, &chaine, ps, depth)) {
1819 SAFE_FREE(chaine.buffer);
1820 return False;
1822 q++;
1823 p=q;
1825 SAFE_FREE(chaine.buffer);
1828 if(!prs_set_offset(ps, struct_offset))
1829 return False;
1831 relative_offset=buffer->string_at_end - buffer->struct_start;
1832 /* write its offset */
1833 if (!prs_uint32("offset", ps, depth, &relative_offset))
1834 return False;
1836 } else {
1838 /* UNMARSHALLING */
1840 uint32 old_offset;
1841 uint16 *chaine2=NULL;
1842 int l_chaine=0;
1843 int l_chaine2=0;
1844 size_t realloc_size = 0;
1846 *string=NULL;
1848 /* read the offset */
1849 if (!prs_uint32("offset", ps, depth, &buffer->string_at_end))
1850 return False;
1852 old_offset = prs_offset(ps);
1853 if(!prs_set_offset(ps, buffer->string_at_end + buffer->struct_start))
1854 return False;
1856 do {
1857 if (!spoolss_smb_io_unistr(desc, &chaine, ps, depth))
1858 return False;
1860 l_chaine=str_len_uni(&chaine);
1862 /* we're going to add two more bytes here in case this
1863 is the last string in the array and we need to add
1864 an extra NULL for termination */
1865 if (l_chaine > 0)
1867 uint16 *tc2;
1869 realloc_size = (l_chaine2+l_chaine+2)*sizeof(uint16);
1871 /* Yes this should be realloc - it's freed below. JRA */
1873 if((tc2=(uint16 *)Realloc(chaine2, realloc_size)) == NULL) {
1874 SAFE_FREE(chaine2);
1875 return False;
1877 else chaine2 = tc2;
1878 memcpy(chaine2+l_chaine2, chaine.buffer, (l_chaine+1)*sizeof(uint16));
1879 l_chaine2+=l_chaine+1;
1882 } while(l_chaine!=0);
1884 /* the end should be bould NULL terminated so add
1885 the second one here */
1886 if (chaine2)
1888 chaine2[l_chaine2] = '\0';
1889 *string=(uint16 *)talloc_memdup(prs_get_mem_context(ps),chaine2,realloc_size);
1890 SAFE_FREE(chaine2);
1893 if(!prs_set_offset(ps, old_offset))
1894 return False;
1896 return True;
1899 /*******************************************************************
1900 Parse a DEVMODE structure and its relative pointer.
1901 ********************************************************************/
1903 static BOOL smb_io_relsecdesc(char *desc, NEW_BUFFER *buffer, int depth, SEC_DESC **secdesc)
1905 prs_struct *ps= &buffer->prs;
1907 prs_debug(ps, depth, desc, "smb_io_relsecdesc");
1908 depth++;
1910 if (MARSHALLING(ps)) {
1911 uint32 struct_offset = prs_offset(ps);
1912 uint32 relative_offset;
1914 if (! *secdesc) {
1915 relative_offset = 0;
1916 if (!prs_uint32("offset", ps, depth, &relative_offset))
1917 return False;
1918 return True;
1921 if (*secdesc != NULL) {
1922 buffer->string_at_end -= sec_desc_size(*secdesc);
1924 if(!prs_set_offset(ps, buffer->string_at_end))
1925 return False;
1926 /* write the secdesc */
1927 if (!sec_io_desc(desc, secdesc, ps, depth))
1928 return False;
1930 if(!prs_set_offset(ps, struct_offset))
1931 return False;
1934 relative_offset=buffer->string_at_end - buffer->struct_start;
1935 /* write its offset */
1937 if (!prs_uint32("offset", ps, depth, &relative_offset))
1938 return False;
1939 } else {
1940 uint32 old_offset;
1942 /* read the offset */
1943 if (!prs_uint32("offset", ps, depth, &buffer->string_at_end))
1944 return False;
1946 old_offset = prs_offset(ps);
1947 if(!prs_set_offset(ps, buffer->string_at_end + buffer->struct_start))
1948 return False;
1950 /* read the sd */
1951 if (!sec_io_desc(desc, secdesc, ps, depth))
1952 return False;
1954 if(!prs_set_offset(ps, old_offset))
1955 return False;
1957 return True;
1960 /*******************************************************************
1961 Parse a DEVMODE structure and its relative pointer.
1962 ********************************************************************/
1964 static BOOL smb_io_reldevmode(char *desc, NEW_BUFFER *buffer, int depth, DEVICEMODE **devmode)
1966 prs_struct *ps=&buffer->prs;
1968 prs_debug(ps, depth, desc, "smb_io_reldevmode");
1969 depth++;
1971 if (MARSHALLING(ps)) {
1972 uint32 struct_offset = prs_offset(ps);
1973 uint32 relative_offset;
1975 if (*devmode == NULL) {
1976 relative_offset=0;
1977 if (!prs_uint32("offset", ps, depth, &relative_offset))
1978 return False;
1979 DEBUG(8, ("boing, the devmode was NULL\n"));
1981 return True;
1984 buffer->string_at_end -= ((*devmode)->size + (*devmode)->driverextra);
1986 if(!prs_set_offset(ps, buffer->string_at_end))
1987 return False;
1989 /* write the DEVMODE */
1990 if (!spoolss_io_devmode(desc, ps, depth, *devmode))
1991 return False;
1993 if(!prs_set_offset(ps, struct_offset))
1994 return False;
1996 relative_offset=buffer->string_at_end - buffer->struct_start;
1997 /* write its offset */
1998 if (!prs_uint32("offset", ps, depth, &relative_offset))
1999 return False;
2001 else {
2002 uint32 old_offset;
2004 /* read the offset */
2005 if (!prs_uint32("offset", ps, depth, &buffer->string_at_end))
2006 return False;
2008 old_offset = prs_offset(ps);
2009 if(!prs_set_offset(ps, buffer->string_at_end + buffer->struct_start))
2010 return False;
2012 /* read the string */
2013 if((*devmode=(DEVICEMODE *)prs_alloc_mem(ps,sizeof(DEVICEMODE))) == NULL)
2014 return False;
2015 if (!spoolss_io_devmode(desc, ps, depth, *devmode))
2016 return False;
2018 if(!prs_set_offset(ps, old_offset))
2019 return False;
2021 return True;
2024 /*******************************************************************
2025 Parse a PRINTER_INFO_0 structure.
2026 ********************************************************************/
2028 BOOL smb_io_printer_info_0(char *desc, NEW_BUFFER *buffer, PRINTER_INFO_0 *info, int depth)
2030 prs_struct *ps=&buffer->prs;
2032 prs_debug(ps, depth, desc, "smb_io_printer_info_0");
2033 depth++;
2035 buffer->struct_start=prs_offset(ps);
2037 if (!smb_io_relstr("printername", buffer, depth, &info->printername))
2038 return False;
2039 if (!smb_io_relstr("servername", buffer, depth, &info->servername))
2040 return False;
2042 if(!prs_uint32("cjobs", ps, depth, &info->cjobs))
2043 return False;
2044 if(!prs_uint32("total_jobs", ps, depth, &info->total_jobs))
2045 return False;
2046 if(!prs_uint32("total_bytes", ps, depth, &info->total_bytes))
2047 return False;
2049 if(!prs_uint16("year", ps, depth, &info->year))
2050 return False;
2051 if(!prs_uint16("month", ps, depth, &info->month))
2052 return False;
2053 if(!prs_uint16("dayofweek", ps, depth, &info->dayofweek))
2054 return False;
2055 if(!prs_uint16("day", ps, depth, &info->day))
2056 return False;
2057 if(!prs_uint16("hour", ps, depth, &info->hour))
2058 return False;
2059 if(!prs_uint16("minute", ps, depth, &info->minute))
2060 return False;
2061 if(!prs_uint16("second", ps, depth, &info->second))
2062 return False;
2063 if(!prs_uint16("milliseconds", ps, depth, &info->milliseconds))
2064 return False;
2066 if(!prs_uint32("global_counter", ps, depth, &info->global_counter))
2067 return False;
2068 if(!prs_uint32("total_pages", ps, depth, &info->total_pages))
2069 return False;
2071 if(!prs_uint16("major_version", ps, depth, &info->major_version))
2072 return False;
2073 if(!prs_uint16("build_version", ps, depth, &info->build_version))
2074 return False;
2075 if(!prs_uint32("unknown7", ps, depth, &info->unknown7))
2076 return False;
2077 if(!prs_uint32("unknown8", ps, depth, &info->unknown8))
2078 return False;
2079 if(!prs_uint32("unknown9", ps, depth, &info->unknown9))
2080 return False;
2081 if(!prs_uint32("session_counter", ps, depth, &info->session_counter))
2082 return False;
2083 if(!prs_uint32("unknown11", ps, depth, &info->unknown11))
2084 return False;
2085 if(!prs_uint32("printer_errors", ps, depth, &info->printer_errors))
2086 return False;
2087 if(!prs_uint32("unknown13", ps, depth, &info->unknown13))
2088 return False;
2089 if(!prs_uint32("unknown14", ps, depth, &info->unknown14))
2090 return False;
2091 if(!prs_uint32("unknown15", ps, depth, &info->unknown15))
2092 return False;
2093 if(!prs_uint32("unknown16", ps, depth, &info->unknown16))
2094 return False;
2095 if(!prs_uint32("change_id", ps, depth, &info->change_id))
2096 return False;
2097 if(!prs_uint32("unknown18", ps, depth, &info->unknown18))
2098 return False;
2099 if(!prs_uint32("status" , ps, depth, &info->status))
2100 return False;
2101 if(!prs_uint32("unknown20", ps, depth, &info->unknown20))
2102 return False;
2103 if(!prs_uint32("c_setprinter", ps, depth, &info->c_setprinter))
2104 return False;
2105 if(!prs_uint16("unknown22", ps, depth, &info->unknown22))
2106 return False;
2107 if(!prs_uint16("unknown23", ps, depth, &info->unknown23))
2108 return False;
2109 if(!prs_uint16("unknown24", ps, depth, &info->unknown24))
2110 return False;
2111 if(!prs_uint16("unknown25", ps, depth, &info->unknown25))
2112 return False;
2113 if(!prs_uint16("unknown26", ps, depth, &info->unknown26))
2114 return False;
2115 if(!prs_uint16("unknown27", ps, depth, &info->unknown27))
2116 return False;
2117 if(!prs_uint16("unknown28", ps, depth, &info->unknown28))
2118 return False;
2119 if(!prs_uint16("unknown29", ps, depth, &info->unknown29))
2120 return False;
2122 return True;
2125 /*******************************************************************
2126 Parse a PRINTER_INFO_1 structure.
2127 ********************************************************************/
2129 BOOL smb_io_printer_info_1(char *desc, NEW_BUFFER *buffer, PRINTER_INFO_1 *info, int depth)
2131 prs_struct *ps=&buffer->prs;
2133 prs_debug(ps, depth, desc, "smb_io_printer_info_1");
2134 depth++;
2136 buffer->struct_start=prs_offset(ps);
2138 if (!prs_uint32("flags", ps, depth, &info->flags))
2139 return False;
2140 if (!smb_io_relstr("description", buffer, depth, &info->description))
2141 return False;
2142 if (!smb_io_relstr("name", buffer, depth, &info->name))
2143 return False;
2144 if (!smb_io_relstr("comment", buffer, depth, &info->comment))
2145 return False;
2147 return True;
2150 /*******************************************************************
2151 Parse a PRINTER_INFO_2 structure.
2152 ********************************************************************/
2154 BOOL smb_io_printer_info_2(char *desc, NEW_BUFFER *buffer, PRINTER_INFO_2 *info, int depth)
2156 prs_struct *ps=&buffer->prs;
2158 prs_debug(ps, depth, desc, "smb_io_printer_info_2");
2159 depth++;
2161 buffer->struct_start=prs_offset(ps);
2163 if (!smb_io_relstr("servername", buffer, depth, &info->servername))
2164 return False;
2165 if (!smb_io_relstr("printername", buffer, depth, &info->printername))
2166 return False;
2167 if (!smb_io_relstr("sharename", buffer, depth, &info->sharename))
2168 return False;
2169 if (!smb_io_relstr("portname", buffer, depth, &info->portname))
2170 return False;
2171 if (!smb_io_relstr("drivername", buffer, depth, &info->drivername))
2172 return False;
2173 if (!smb_io_relstr("comment", buffer, depth, &info->comment))
2174 return False;
2175 if (!smb_io_relstr("location", buffer, depth, &info->location))
2176 return False;
2178 /* NT parses the DEVMODE at the end of the struct */
2179 if (!smb_io_reldevmode("devmode", buffer, depth, &info->devmode))
2180 return False;
2182 if (!smb_io_relstr("sepfile", buffer, depth, &info->sepfile))
2183 return False;
2184 if (!smb_io_relstr("printprocessor", buffer, depth, &info->printprocessor))
2185 return False;
2186 if (!smb_io_relstr("datatype", buffer, depth, &info->datatype))
2187 return False;
2188 if (!smb_io_relstr("parameters", buffer, depth, &info->parameters))
2189 return False;
2191 if (!smb_io_relsecdesc("secdesc", buffer, depth, &info->secdesc))
2192 return False;
2194 if (!prs_uint32("attributes", ps, depth, &info->attributes))
2195 return False;
2196 if (!prs_uint32("priority", ps, depth, &info->priority))
2197 return False;
2198 if (!prs_uint32("defpriority", ps, depth, &info->defaultpriority))
2199 return False;
2200 if (!prs_uint32("starttime", ps, depth, &info->starttime))
2201 return False;
2202 if (!prs_uint32("untiltime", ps, depth, &info->untiltime))
2203 return False;
2204 if (!prs_uint32("status", ps, depth, &info->status))
2205 return False;
2206 if (!prs_uint32("jobs", ps, depth, &info->cjobs))
2207 return False;
2208 if (!prs_uint32("averageppm", ps, depth, &info->averageppm))
2209 return False;
2211 #if 0 /* JFMTEST */
2212 if (!prs_uint32_post("secdesc_ptr", ps, depth, NULL, sec_offset, info->secdesc ? prs_offset(ps)-buffer->struct_start : 0 ))
2213 return False;
2215 if (!sec_io_desc("secdesc", &info->secdesc, ps, depth))
2216 return False;
2217 #endif
2218 return True;
2221 /*******************************************************************
2222 Parse a PRINTER_INFO_3 structure.
2223 ********************************************************************/
2225 BOOL smb_io_printer_info_3(char *desc, NEW_BUFFER *buffer, PRINTER_INFO_3 *info, int depth)
2227 prs_struct *ps=&buffer->prs;
2229 prs_debug(ps, depth, desc, "smb_io_printer_info_3");
2230 depth++;
2232 buffer->struct_start=prs_offset(ps);
2234 if (!prs_uint32("flags", ps, depth, &info->flags))
2235 return False;
2236 if (!sec_io_desc("sec_desc", &info->secdesc, ps, depth))
2237 return False;
2239 return True;
2242 /*******************************************************************
2243 Parse a PRINTER_INFO_4 structure.
2244 ********************************************************************/
2246 BOOL smb_io_printer_info_4(char *desc, NEW_BUFFER *buffer, PRINTER_INFO_4 *info, int depth)
2248 prs_struct *ps=&buffer->prs;
2250 prs_debug(ps, depth, desc, "smb_io_printer_info_4");
2251 depth++;
2253 buffer->struct_start=prs_offset(ps);
2255 if (!smb_io_relstr("printername", buffer, depth, &info->printername))
2256 return False;
2257 if (!smb_io_relstr("servername", buffer, depth, &info->servername))
2258 return False;
2259 if (!prs_uint32("attributes", ps, depth, &info->attributes))
2260 return False;
2261 return True;
2264 /*******************************************************************
2265 Parse a PRINTER_INFO_5 structure.
2266 ********************************************************************/
2268 BOOL smb_io_printer_info_5(char *desc, NEW_BUFFER *buffer, PRINTER_INFO_5 *info, int depth)
2270 prs_struct *ps=&buffer->prs;
2272 prs_debug(ps, depth, desc, "smb_io_printer_info_5");
2273 depth++;
2275 buffer->struct_start=prs_offset(ps);
2277 if (!smb_io_relstr("printername", buffer, depth, &info->printername))
2278 return False;
2279 if (!smb_io_relstr("portname", buffer, depth, &info->portname))
2280 return False;
2281 if (!prs_uint32("attributes", ps, depth, &info->attributes))
2282 return False;
2283 if (!prs_uint32("device_not_selected_timeout", ps, depth, &info->device_not_selected_timeout))
2284 return False;
2285 if (!prs_uint32("transmission_retry_timeout", ps, depth, &info->transmission_retry_timeout))
2286 return False;
2287 return True;
2290 /*******************************************************************
2291 Parse a PORT_INFO_1 structure.
2292 ********************************************************************/
2294 BOOL smb_io_port_info_1(char *desc, NEW_BUFFER *buffer, PORT_INFO_1 *info, int depth)
2296 prs_struct *ps=&buffer->prs;
2298 prs_debug(ps, depth, desc, "smb_io_port_info_1");
2299 depth++;
2301 buffer->struct_start=prs_offset(ps);
2303 if (!smb_io_relstr("port_name", buffer, depth, &info->port_name))
2304 return False;
2306 return True;
2309 /*******************************************************************
2310 Parse a PORT_INFO_2 structure.
2311 ********************************************************************/
2313 BOOL smb_io_port_info_2(char *desc, NEW_BUFFER *buffer, PORT_INFO_2 *info, int depth)
2315 prs_struct *ps=&buffer->prs;
2317 prs_debug(ps, depth, desc, "smb_io_port_info_2");
2318 depth++;
2320 buffer->struct_start=prs_offset(ps);
2322 if (!smb_io_relstr("port_name", buffer, depth, &info->port_name))
2323 return False;
2324 if (!smb_io_relstr("monitor_name", buffer, depth, &info->monitor_name))
2325 return False;
2326 if (!smb_io_relstr("description", buffer, depth, &info->description))
2327 return False;
2328 if (!prs_uint32("port_type", ps, depth, &info->port_type))
2329 return False;
2330 if (!prs_uint32("reserved", ps, depth, &info->reserved))
2331 return False;
2333 return True;
2336 /*******************************************************************
2337 Parse a DRIVER_INFO_1 structure.
2338 ********************************************************************/
2340 BOOL smb_io_printer_driver_info_1(char *desc, NEW_BUFFER *buffer, DRIVER_INFO_1 *info, int depth)
2342 prs_struct *ps=&buffer->prs;
2344 prs_debug(ps, depth, desc, "smb_io_printer_driver_info_1");
2345 depth++;
2347 buffer->struct_start=prs_offset(ps);
2349 if (!smb_io_relstr("name", buffer, depth, &info->name))
2350 return False;
2352 return True;
2355 /*******************************************************************
2356 Parse a DRIVER_INFO_2 structure.
2357 ********************************************************************/
2359 BOOL smb_io_printer_driver_info_2(char *desc, NEW_BUFFER *buffer, DRIVER_INFO_2 *info, int depth)
2361 prs_struct *ps=&buffer->prs;
2363 prs_debug(ps, depth, desc, "smb_io_printer_driver_info_2");
2364 depth++;
2366 buffer->struct_start=prs_offset(ps);
2368 if (!prs_uint32("version", ps, depth, &info->version))
2369 return False;
2370 if (!smb_io_relstr("name", buffer, depth, &info->name))
2371 return False;
2372 if (!smb_io_relstr("architecture", buffer, depth, &info->architecture))
2373 return False;
2374 if (!smb_io_relstr("driverpath", buffer, depth, &info->driverpath))
2375 return False;
2376 if (!smb_io_relstr("datafile", buffer, depth, &info->datafile))
2377 return False;
2378 if (!smb_io_relstr("configfile", buffer, depth, &info->configfile))
2379 return False;
2381 return True;
2384 /*******************************************************************
2385 Parse a DRIVER_INFO_3 structure.
2386 ********************************************************************/
2388 BOOL smb_io_printer_driver_info_3(char *desc, NEW_BUFFER *buffer, DRIVER_INFO_3 *info, int depth)
2390 prs_struct *ps=&buffer->prs;
2392 prs_debug(ps, depth, desc, "smb_io_printer_driver_info_3");
2393 depth++;
2395 buffer->struct_start=prs_offset(ps);
2397 if (!prs_uint32("version", ps, depth, &info->version))
2398 return False;
2399 if (!smb_io_relstr("name", buffer, depth, &info->name))
2400 return False;
2401 if (!smb_io_relstr("architecture", buffer, depth, &info->architecture))
2402 return False;
2403 if (!smb_io_relstr("driverpath", buffer, depth, &info->driverpath))
2404 return False;
2405 if (!smb_io_relstr("datafile", buffer, depth, &info->datafile))
2406 return False;
2407 if (!smb_io_relstr("configfile", buffer, depth, &info->configfile))
2408 return False;
2409 if (!smb_io_relstr("helpfile", buffer, depth, &info->helpfile))
2410 return False;
2412 if (!smb_io_relarraystr("dependentfiles", buffer, depth, &info->dependentfiles))
2413 return False;
2415 if (!smb_io_relstr("monitorname", buffer, depth, &info->monitorname))
2416 return False;
2417 if (!smb_io_relstr("defaultdatatype", buffer, depth, &info->defaultdatatype))
2418 return False;
2420 return True;
2423 /*******************************************************************
2424 Parse a DRIVER_INFO_6 structure.
2425 ********************************************************************/
2427 BOOL smb_io_printer_driver_info_6(char *desc, NEW_BUFFER *buffer, DRIVER_INFO_6 *info, int depth)
2429 prs_struct *ps=&buffer->prs;
2431 prs_debug(ps, depth, desc, "smb_io_printer_driver_info_6");
2432 depth++;
2434 buffer->struct_start=prs_offset(ps);
2436 if (!prs_uint32("version", ps, depth, &info->version))
2437 return False;
2438 if (!smb_io_relstr("name", buffer, depth, &info->name))
2439 return False;
2440 if (!smb_io_relstr("architecture", buffer, depth, &info->architecture))
2441 return False;
2442 if (!smb_io_relstr("driverpath", buffer, depth, &info->driverpath))
2443 return False;
2444 if (!smb_io_relstr("datafile", buffer, depth, &info->datafile))
2445 return False;
2446 if (!smb_io_relstr("configfile", buffer, depth, &info->configfile))
2447 return False;
2448 if (!smb_io_relstr("helpfile", buffer, depth, &info->helpfile))
2449 return False;
2451 if (!smb_io_relarraystr("dependentfiles", buffer, depth, &info->dependentfiles))
2452 return False;
2454 if (!smb_io_relstr("monitorname", buffer, depth, &info->monitorname))
2455 return False;
2456 if (!smb_io_relstr("defaultdatatype", buffer, depth, &info->defaultdatatype))
2457 return False;
2459 if (!smb_io_relarraystr("previousdrivernames", buffer, depth, &info->previousdrivernames))
2460 return False;
2462 if (!prs_uint32("date.low", ps, depth, &info->driver_date.low))
2463 return False;
2464 if (!prs_uint32("date.high", ps, depth, &info->driver_date.high))
2465 return False;
2467 if (!prs_uint32("padding", ps, depth, &info->padding))
2468 return False;
2470 if (!prs_uint32("driver_version_low", ps, depth, &info->driver_version_low))
2471 return False;
2473 if (!prs_uint32("driver_version_high", ps, depth, &info->driver_version_high))
2474 return False;
2476 if (!smb_io_relstr("mfgname", buffer, depth, &info->mfgname))
2477 return False;
2478 if (!smb_io_relstr("oem_url", buffer, depth, &info->oem_url))
2479 return False;
2480 if (!smb_io_relstr("hardware_id", buffer, depth, &info->hardware_id))
2481 return False;
2482 if (!smb_io_relstr("provider", buffer, depth, &info->provider))
2483 return False;
2485 return True;
2488 /*******************************************************************
2489 Parse a JOB_INFO_1 structure.
2490 ********************************************************************/
2492 BOOL smb_io_job_info_1(char *desc, NEW_BUFFER *buffer, JOB_INFO_1 *info, int depth)
2494 prs_struct *ps=&buffer->prs;
2496 prs_debug(ps, depth, desc, "smb_io_job_info_1");
2497 depth++;
2499 buffer->struct_start=prs_offset(ps);
2501 if (!prs_uint32("jobid", ps, depth, &info->jobid))
2502 return False;
2503 if (!smb_io_relstr("printername", buffer, depth, &info->printername))
2504 return False;
2505 if (!smb_io_relstr("machinename", buffer, depth, &info->machinename))
2506 return False;
2507 if (!smb_io_relstr("username", buffer, depth, &info->username))
2508 return False;
2509 if (!smb_io_relstr("document", buffer, depth, &info->document))
2510 return False;
2511 if (!smb_io_relstr("datatype", buffer, depth, &info->datatype))
2512 return False;
2513 if (!smb_io_relstr("text_status", buffer, depth, &info->text_status))
2514 return False;
2515 if (!prs_uint32("status", ps, depth, &info->status))
2516 return False;
2517 if (!prs_uint32("priority", ps, depth, &info->priority))
2518 return False;
2519 if (!prs_uint32("position", ps, depth, &info->position))
2520 return False;
2521 if (!prs_uint32("totalpages", ps, depth, &info->totalpages))
2522 return False;
2523 if (!prs_uint32("pagesprinted", ps, depth, &info->pagesprinted))
2524 return False;
2525 if (!spoolss_io_system_time("submitted", ps, depth, &info->submitted))
2526 return False;
2528 return True;
2531 /*******************************************************************
2532 Parse a JOB_INFO_2 structure.
2533 ********************************************************************/
2535 BOOL smb_io_job_info_2(char *desc, NEW_BUFFER *buffer, JOB_INFO_2 *info, int depth)
2537 uint32 pipo=0;
2538 prs_struct *ps=&buffer->prs;
2540 prs_debug(ps, depth, desc, "smb_io_job_info_2");
2541 depth++;
2543 buffer->struct_start=prs_offset(ps);
2545 if (!prs_uint32("jobid",ps, depth, &info->jobid))
2546 return False;
2547 if (!smb_io_relstr("printername", buffer, depth, &info->printername))
2548 return False;
2549 if (!smb_io_relstr("machinename", buffer, depth, &info->machinename))
2550 return False;
2551 if (!smb_io_relstr("username", buffer, depth, &info->username))
2552 return False;
2553 if (!smb_io_relstr("document", buffer, depth, &info->document))
2554 return False;
2555 if (!smb_io_relstr("notifyname", buffer, depth, &info->notifyname))
2556 return False;
2557 if (!smb_io_relstr("datatype", buffer, depth, &info->datatype))
2558 return False;
2560 if (!smb_io_relstr("printprocessor", buffer, depth, &info->printprocessor))
2561 return False;
2562 if (!smb_io_relstr("parameters", buffer, depth, &info->parameters))
2563 return False;
2564 if (!smb_io_relstr("drivername", buffer, depth, &info->drivername))
2565 return False;
2566 if (!smb_io_reldevmode("devmode", buffer, depth, &info->devmode))
2567 return False;
2568 if (!smb_io_relstr("text_status", buffer, depth, &info->text_status))
2569 return False;
2571 /* SEC_DESC sec_desc;*/
2572 if (!prs_uint32("Hack! sec desc", ps, depth, &pipo))
2573 return False;
2575 if (!prs_uint32("status",ps, depth, &info->status))
2576 return False;
2577 if (!prs_uint32("priority",ps, depth, &info->priority))
2578 return False;
2579 if (!prs_uint32("position",ps, depth, &info->position))
2580 return False;
2581 if (!prs_uint32("starttime",ps, depth, &info->starttime))
2582 return False;
2583 if (!prs_uint32("untiltime",ps, depth, &info->untiltime))
2584 return False;
2585 if (!prs_uint32("totalpages",ps, depth, &info->totalpages))
2586 return False;
2587 if (!prs_uint32("size",ps, depth, &info->size))
2588 return False;
2589 if (!spoolss_io_system_time("submitted", ps, depth, &info->submitted) )
2590 return False;
2591 if (!prs_uint32("timeelapsed",ps, depth, &info->timeelapsed))
2592 return False;
2593 if (!prs_uint32("pagesprinted",ps, depth, &info->pagesprinted))
2594 return False;
2596 return True;
2599 /*******************************************************************
2600 ********************************************************************/
2602 BOOL smb_io_form_1(char *desc, NEW_BUFFER *buffer, FORM_1 *info, int depth)
2604 prs_struct *ps=&buffer->prs;
2606 prs_debug(ps, depth, desc, "smb_io_form_1");
2607 depth++;
2609 buffer->struct_start=prs_offset(ps);
2611 if (!prs_uint32("flag", ps, depth, &info->flag))
2612 return False;
2614 if (!smb_io_relstr("name", buffer, depth, &info->name))
2615 return False;
2617 if (!prs_uint32("width", ps, depth, &info->width))
2618 return False;
2619 if (!prs_uint32("length", ps, depth, &info->length))
2620 return False;
2621 if (!prs_uint32("left", ps, depth, &info->left))
2622 return False;
2623 if (!prs_uint32("top", ps, depth, &info->top))
2624 return False;
2625 if (!prs_uint32("right", ps, depth, &info->right))
2626 return False;
2627 if (!prs_uint32("bottom", ps, depth, &info->bottom))
2628 return False;
2630 return True;
2633 /*******************************************************************
2634 Read/write a BUFFER struct.
2635 ********************************************************************/
2637 static BOOL spoolss_io_buffer(char *desc, prs_struct *ps, int depth, NEW_BUFFER **pp_buffer)
2639 NEW_BUFFER *buffer = *pp_buffer;
2641 prs_debug(ps, depth, desc, "spoolss_io_buffer");
2642 depth++;
2644 if (UNMARSHALLING(ps))
2645 buffer = *pp_buffer = (NEW_BUFFER *)prs_alloc_mem(ps, sizeof(NEW_BUFFER));
2647 if (buffer == NULL)
2648 return False;
2650 if (!prs_uint32("ptr", ps, depth, &buffer->ptr))
2651 return False;
2653 /* reading */
2654 if (UNMARSHALLING(ps)) {
2655 buffer->size=0;
2656 buffer->string_at_end=0;
2658 if (buffer->ptr==0) {
2660 * JRA. I'm not sure if the data in here is in big-endian format if
2661 * the client is big-endian. Leave as default (little endian) for now.
2664 if (!prs_init(&buffer->prs, 0, prs_get_mem_context(ps), UNMARSHALL))
2665 return False;
2666 return True;
2669 if (!prs_uint32("size", ps, depth, &buffer->size))
2670 return False;
2673 * JRA. I'm not sure if the data in here is in big-endian format if
2674 * the client is big-endian. Leave as default (little endian) for now.
2677 if (!prs_init(&buffer->prs, buffer->size, prs_get_mem_context(ps), UNMARSHALL))
2678 return False;
2680 if (!prs_append_some_prs_data(&buffer->prs, ps, prs_offset(ps), buffer->size))
2681 return False;
2683 if (!prs_set_offset(&buffer->prs, 0))
2684 return False;
2686 if (!prs_set_offset(ps, buffer->size+prs_offset(ps)))
2687 return False;
2689 buffer->string_at_end=buffer->size;
2691 return True;
2693 else {
2694 BOOL ret = False;
2696 /* writing */
2697 if (buffer->ptr==0) {
2698 /* We have finished with the data in buffer->prs - free it. */
2699 prs_mem_free(&buffer->prs);
2700 return True;
2703 if (!prs_uint32("size", ps, depth, &buffer->size))
2704 goto out;
2706 if (!prs_append_some_prs_data(ps, &buffer->prs, 0, buffer->size))
2707 goto out;
2709 ret = True;
2710 out:
2712 /* We have finished with the data in buffer->prs - free it. */
2713 prs_mem_free(&buffer->prs);
2715 return ret;
2719 /*******************************************************************
2720 move a BUFFER from the query to the reply.
2721 As the data pointers in NEW_BUFFER are malloc'ed, not talloc'ed,
2722 this is ok. This is an OPTIMIZATION and is not strictly neccessary.
2723 Clears the memory to zero also.
2724 ********************************************************************/
2726 void spoolss_move_buffer(NEW_BUFFER *src, NEW_BUFFER **dest)
2728 prs_switch_type(&src->prs, MARSHALL);
2729 if(!prs_set_offset(&src->prs, 0))
2730 return;
2731 prs_force_dynamic(&src->prs);
2732 prs_mem_clear(&src->prs);
2733 *dest=src;
2736 /*******************************************************************
2737 Get the size of a BUFFER struct.
2738 ********************************************************************/
2740 uint32 new_get_buffer_size(NEW_BUFFER *buffer)
2742 return (buffer->size);
2745 /*******************************************************************
2746 Parse a DRIVER_DIRECTORY_1 structure.
2747 ********************************************************************/
2749 BOOL smb_io_driverdir_1(char *desc, NEW_BUFFER *buffer, DRIVER_DIRECTORY_1 *info, int depth)
2751 prs_struct *ps=&buffer->prs;
2753 prs_debug(ps, depth, desc, "smb_io_driverdir_1");
2754 depth++;
2756 buffer->struct_start=prs_offset(ps);
2758 if (!smb_io_unistr(desc, &info->name, ps, depth))
2759 return False;
2761 return True;
2764 /*******************************************************************
2765 Parse a PORT_INFO_1 structure.
2766 ********************************************************************/
2768 BOOL smb_io_port_1(char *desc, NEW_BUFFER *buffer, PORT_INFO_1 *info, int depth)
2770 prs_struct *ps=&buffer->prs;
2772 prs_debug(ps, depth, desc, "smb_io_port_1");
2773 depth++;
2775 buffer->struct_start=prs_offset(ps);
2777 if(!smb_io_relstr("port_name", buffer, depth, &info->port_name))
2778 return False;
2780 return True;
2783 /*******************************************************************
2784 Parse a PORT_INFO_2 structure.
2785 ********************************************************************/
2787 BOOL smb_io_port_2(char *desc, NEW_BUFFER *buffer, PORT_INFO_2 *info, int depth)
2789 prs_struct *ps=&buffer->prs;
2791 prs_debug(ps, depth, desc, "smb_io_port_2");
2792 depth++;
2794 buffer->struct_start=prs_offset(ps);
2796 if(!smb_io_relstr("port_name", buffer, depth, &info->port_name))
2797 return False;
2798 if(!smb_io_relstr("monitor_name", buffer, depth, &info->monitor_name))
2799 return False;
2800 if(!smb_io_relstr("description", buffer, depth, &info->description))
2801 return False;
2802 if(!prs_uint32("port_type", ps, depth, &info->port_type))
2803 return False;
2804 if(!prs_uint32("reserved", ps, depth, &info->reserved))
2805 return False;
2807 return True;
2810 /*******************************************************************
2811 ********************************************************************/
2813 BOOL smb_io_printprocessor_info_1(char *desc, NEW_BUFFER *buffer, PRINTPROCESSOR_1 *info, int depth)
2815 prs_struct *ps=&buffer->prs;
2817 prs_debug(ps, depth, desc, "smb_io_printprocessor_info_1");
2818 depth++;
2820 buffer->struct_start=prs_offset(ps);
2822 if (smb_io_relstr("name", buffer, depth, &info->name))
2823 return False;
2825 return True;
2828 /*******************************************************************
2829 ********************************************************************/
2831 BOOL smb_io_printprocdatatype_info_1(char *desc, NEW_BUFFER *buffer, PRINTPROCDATATYPE_1 *info, int depth)
2833 prs_struct *ps=&buffer->prs;
2835 prs_debug(ps, depth, desc, "smb_io_printprocdatatype_info_1");
2836 depth++;
2838 buffer->struct_start=prs_offset(ps);
2840 if (smb_io_relstr("name", buffer, depth, &info->name))
2841 return False;
2843 return True;
2846 /*******************************************************************
2847 ********************************************************************/
2849 BOOL smb_io_printmonitor_info_1(char *desc, NEW_BUFFER *buffer, PRINTMONITOR_1 *info, int depth)
2851 prs_struct *ps=&buffer->prs;
2853 prs_debug(ps, depth, desc, "smb_io_printmonitor_info_1");
2854 depth++;
2856 buffer->struct_start=prs_offset(ps);
2858 if (!smb_io_relstr("name", buffer, depth, &info->name))
2859 return False;
2861 return True;
2864 /*******************************************************************
2865 ********************************************************************/
2867 BOOL smb_io_printmonitor_info_2(char *desc, NEW_BUFFER *buffer, PRINTMONITOR_2 *info, int depth)
2869 prs_struct *ps=&buffer->prs;
2871 prs_debug(ps, depth, desc, "smb_io_printmonitor_info_2");
2872 depth++;
2874 buffer->struct_start=prs_offset(ps);
2876 if (!smb_io_relstr("name", buffer, depth, &info->name))
2877 return False;
2878 if (!smb_io_relstr("environment", buffer, depth, &info->environment))
2879 return False;
2880 if (!smb_io_relstr("dll_name", buffer, depth, &info->dll_name))
2881 return False;
2883 return True;
2886 /*******************************************************************
2887 return the size required by a struct in the stream
2888 ********************************************************************/
2890 uint32 spoolss_size_printer_info_0(PRINTER_INFO_0 *info)
2892 int size=0;
2894 size+=size_of_relative_string( &info->printername );
2895 size+=size_of_relative_string( &info->servername );
2897 size+=size_of_uint32( &info->cjobs);
2898 size+=size_of_uint32( &info->total_jobs);
2899 size+=size_of_uint32( &info->total_bytes);
2901 size+=size_of_uint16( &info->year);
2902 size+=size_of_uint16( &info->month);
2903 size+=size_of_uint16( &info->dayofweek);
2904 size+=size_of_uint16( &info->day);
2905 size+=size_of_uint16( &info->hour);
2906 size+=size_of_uint16( &info->minute);
2907 size+=size_of_uint16( &info->second);
2908 size+=size_of_uint16( &info->milliseconds);
2910 size+=size_of_uint32( &info->global_counter);
2911 size+=size_of_uint32( &info->total_pages);
2913 size+=size_of_uint16( &info->major_version);
2914 size+=size_of_uint16( &info->build_version);
2916 size+=size_of_uint32( &info->unknown7);
2917 size+=size_of_uint32( &info->unknown8);
2918 size+=size_of_uint32( &info->unknown9);
2919 size+=size_of_uint32( &info->session_counter);
2920 size+=size_of_uint32( &info->unknown11);
2921 size+=size_of_uint32( &info->printer_errors);
2922 size+=size_of_uint32( &info->unknown13);
2923 size+=size_of_uint32( &info->unknown14);
2924 size+=size_of_uint32( &info->unknown15);
2925 size+=size_of_uint32( &info->unknown16);
2926 size+=size_of_uint32( &info->change_id);
2927 size+=size_of_uint32( &info->unknown18);
2928 size+=size_of_uint32( &info->status);
2929 size+=size_of_uint32( &info->unknown20);
2930 size+=size_of_uint32( &info->c_setprinter);
2932 size+=size_of_uint16( &info->unknown22);
2933 size+=size_of_uint16( &info->unknown23);
2934 size+=size_of_uint16( &info->unknown24);
2935 size+=size_of_uint16( &info->unknown25);
2936 size+=size_of_uint16( &info->unknown26);
2937 size+=size_of_uint16( &info->unknown27);
2938 size+=size_of_uint16( &info->unknown28);
2939 size+=size_of_uint16( &info->unknown29);
2941 return size;
2944 /*******************************************************************
2945 return the size required by a struct in the stream
2946 ********************************************************************/
2948 uint32 spoolss_size_printer_info_1(PRINTER_INFO_1 *info)
2950 int size=0;
2952 size+=size_of_uint32( &info->flags );
2953 size+=size_of_relative_string( &info->description );
2954 size+=size_of_relative_string( &info->name );
2955 size+=size_of_relative_string( &info->comment );
2957 return size;
2960 /*******************************************************************
2961 return the size required by a struct in the stream
2962 ********************************************************************/
2964 uint32 spoolss_size_printer_info_2(PRINTER_INFO_2 *info)
2966 uint32 size=0;
2968 size += 4;
2969 /* JRA !!!! TESTME - WHAT ABOUT prs_align.... !!! */
2970 size += sec_desc_size( info->secdesc );
2972 size+=size_of_device_mode( info->devmode );
2974 size+=size_of_relative_string( &info->servername );
2975 size+=size_of_relative_string( &info->printername );
2976 size+=size_of_relative_string( &info->sharename );
2977 size+=size_of_relative_string( &info->portname );
2978 size+=size_of_relative_string( &info->drivername );
2979 size+=size_of_relative_string( &info->comment );
2980 size+=size_of_relative_string( &info->location );
2982 size+=size_of_relative_string( &info->sepfile );
2983 size+=size_of_relative_string( &info->printprocessor );
2984 size+=size_of_relative_string( &info->datatype );
2985 size+=size_of_relative_string( &info->parameters );
2987 size+=size_of_uint32( &info->attributes );
2988 size+=size_of_uint32( &info->priority );
2989 size+=size_of_uint32( &info->defaultpriority );
2990 size+=size_of_uint32( &info->starttime );
2991 size+=size_of_uint32( &info->untiltime );
2992 size+=size_of_uint32( &info->status );
2993 size+=size_of_uint32( &info->cjobs );
2994 size+=size_of_uint32( &info->averageppm );
2995 return size;
2998 /*******************************************************************
2999 return the size required by a struct in the stream
3000 ********************************************************************/
3002 uint32 spoolss_size_printer_info_4(PRINTER_INFO_4 *info)
3004 uint32 size=0;
3006 size+=size_of_relative_string( &info->printername );
3007 size+=size_of_relative_string( &info->servername );
3009 size+=size_of_uint32( &info->attributes );
3010 return size;
3013 /*******************************************************************
3014 return the size required by a struct in the stream
3015 ********************************************************************/
3017 uint32 spoolss_size_printer_info_5(PRINTER_INFO_5 *info)
3019 uint32 size=0;
3021 size+=size_of_relative_string( &info->printername );
3022 size+=size_of_relative_string( &info->portname );
3024 size+=size_of_uint32( &info->attributes );
3025 size+=size_of_uint32( &info->device_not_selected_timeout );
3026 size+=size_of_uint32( &info->transmission_retry_timeout );
3027 return size;
3031 /*******************************************************************
3032 return the size required by a struct in the stream
3033 ********************************************************************/
3035 uint32 spoolss_size_printer_info_3(PRINTER_INFO_3 *info)
3037 /* The 4 is for the self relative pointer.. */
3038 /* JRA !!!! TESTME - WHAT ABOUT prs_align.... !!! */
3039 return 4 + (uint32)sec_desc_size( info->secdesc );
3042 /*******************************************************************
3043 return the size required by a struct in the stream
3044 ********************************************************************/
3046 uint32 spoolss_size_printer_driver_info_1(DRIVER_INFO_1 *info)
3048 int size=0;
3049 size+=size_of_relative_string( &info->name );
3051 return size;
3054 /*******************************************************************
3055 return the size required by a struct in the stream
3056 ********************************************************************/
3058 uint32 spoolss_size_printer_driver_info_2(DRIVER_INFO_2 *info)
3060 int size=0;
3061 size+=size_of_uint32( &info->version );
3062 size+=size_of_relative_string( &info->name );
3063 size+=size_of_relative_string( &info->architecture );
3064 size+=size_of_relative_string( &info->driverpath );
3065 size+=size_of_relative_string( &info->datafile );
3066 size+=size_of_relative_string( &info->configfile );
3068 return size;
3071 /*******************************************************************
3072 return the size required by a string array.
3073 ********************************************************************/
3075 uint32 spoolss_size_string_array(uint16 *string)
3077 uint32 i = 0;
3079 if (string) {
3080 for (i=0; (string[i]!=0x0000) || (string[i+1]!=0x0000); i++);
3082 i=i+2; /* to count all chars including the leading zero */
3083 i=2*i; /* because we need the value in bytes */
3084 i=i+4; /* the offset pointer size */
3086 return i;
3089 /*******************************************************************
3090 return the size required by a struct in the stream
3091 ********************************************************************/
3093 uint32 spoolss_size_printer_driver_info_3(DRIVER_INFO_3 *info)
3095 int size=0;
3097 size+=size_of_uint32( &info->version );
3098 size+=size_of_relative_string( &info->name );
3099 size+=size_of_relative_string( &info->architecture );
3100 size+=size_of_relative_string( &info->driverpath );
3101 size+=size_of_relative_string( &info->datafile );
3102 size+=size_of_relative_string( &info->configfile );
3103 size+=size_of_relative_string( &info->helpfile );
3104 size+=size_of_relative_string( &info->monitorname );
3105 size+=size_of_relative_string( &info->defaultdatatype );
3107 size+=spoolss_size_string_array(info->dependentfiles);
3109 return size;
3112 /*******************************************************************
3113 return the size required by a struct in the stream
3114 ********************************************************************/
3116 uint32 spoolss_size_printer_driver_info_6(DRIVER_INFO_6 *info)
3118 uint32 size=0;
3120 size+=size_of_uint32( &info->version );
3121 size+=size_of_relative_string( &info->name );
3122 size+=size_of_relative_string( &info->architecture );
3123 size+=size_of_relative_string( &info->driverpath );
3124 size+=size_of_relative_string( &info->datafile );
3125 size+=size_of_relative_string( &info->configfile );
3126 size+=size_of_relative_string( &info->helpfile );
3128 size+=spoolss_size_string_array(info->dependentfiles);
3130 size+=size_of_relative_string( &info->monitorname );
3131 size+=size_of_relative_string( &info->defaultdatatype );
3133 size+=spoolss_size_string_array(info->previousdrivernames);
3135 size+=size_of_nttime(&info->driver_date);
3136 size+=size_of_uint32( &info->padding );
3137 size+=size_of_uint32( &info->driver_version_low );
3138 size+=size_of_uint32( &info->driver_version_high );
3139 size+=size_of_relative_string( &info->mfgname );
3140 size+=size_of_relative_string( &info->oem_url );
3141 size+=size_of_relative_string( &info->hardware_id );
3142 size+=size_of_relative_string( &info->provider );
3144 return size;
3147 /*******************************************************************
3148 return the size required by a struct in the stream
3149 ********************************************************************/
3151 uint32 spoolss_size_job_info_1(JOB_INFO_1 *info)
3153 int size=0;
3154 size+=size_of_uint32( &info->jobid );
3155 size+=size_of_relative_string( &info->printername );
3156 size+=size_of_relative_string( &info->machinename );
3157 size+=size_of_relative_string( &info->username );
3158 size+=size_of_relative_string( &info->document );
3159 size+=size_of_relative_string( &info->datatype );
3160 size+=size_of_relative_string( &info->text_status );
3161 size+=size_of_uint32( &info->status );
3162 size+=size_of_uint32( &info->priority );
3163 size+=size_of_uint32( &info->position );
3164 size+=size_of_uint32( &info->totalpages );
3165 size+=size_of_uint32( &info->pagesprinted );
3166 size+=size_of_systemtime( &info->submitted );
3168 return size;
3171 /*******************************************************************
3172 return the size required by a struct in the stream
3173 ********************************************************************/
3175 uint32 spoolss_size_job_info_2(JOB_INFO_2 *info)
3177 int size=0;
3179 size+=4; /* size of sec desc ptr */
3181 size+=size_of_uint32( &info->jobid );
3182 size+=size_of_relative_string( &info->printername );
3183 size+=size_of_relative_string( &info->machinename );
3184 size+=size_of_relative_string( &info->username );
3185 size+=size_of_relative_string( &info->document );
3186 size+=size_of_relative_string( &info->notifyname );
3187 size+=size_of_relative_string( &info->datatype );
3188 size+=size_of_relative_string( &info->printprocessor );
3189 size+=size_of_relative_string( &info->parameters );
3190 size+=size_of_relative_string( &info->drivername );
3191 size+=size_of_device_mode( info->devmode );
3192 size+=size_of_relative_string( &info->text_status );
3193 /* SEC_DESC sec_desc;*/
3194 size+=size_of_uint32( &info->status );
3195 size+=size_of_uint32( &info->priority );
3196 size+=size_of_uint32( &info->position );
3197 size+=size_of_uint32( &info->starttime );
3198 size+=size_of_uint32( &info->untiltime );
3199 size+=size_of_uint32( &info->totalpages );
3200 size+=size_of_uint32( &info->size );
3201 size+=size_of_systemtime( &info->submitted );
3202 size+=size_of_uint32( &info->timeelapsed );
3203 size+=size_of_uint32( &info->pagesprinted );
3205 return size;
3208 /*******************************************************************
3209 return the size required by a struct in the stream
3210 ********************************************************************/
3212 uint32 spoolss_size_form_1(FORM_1 *info)
3214 int size=0;
3216 size+=size_of_uint32( &info->flag );
3217 size+=size_of_relative_string( &info->name );
3218 size+=size_of_uint32( &info->width );
3219 size+=size_of_uint32( &info->length );
3220 size+=size_of_uint32( &info->left );
3221 size+=size_of_uint32( &info->top );
3222 size+=size_of_uint32( &info->right );
3223 size+=size_of_uint32( &info->bottom );
3225 return size;
3228 /*******************************************************************
3229 return the size required by a struct in the stream
3230 ********************************************************************/
3232 uint32 spoolss_size_port_info_1(PORT_INFO_1 *info)
3234 int size=0;
3236 size+=size_of_relative_string( &info->port_name );
3238 return size;
3241 /*******************************************************************
3242 return the size required by a struct in the stream
3243 ********************************************************************/
3245 uint32 spoolss_size_driverdir_info_1(DRIVER_DIRECTORY_1 *info)
3247 int size=0;
3249 size=str_len_uni(&info->name); /* the string length */
3250 size=size+1; /* add the leading zero */
3251 size=size*2; /* convert in char */
3253 return size;
3256 /*******************************************************************
3257 return the size required by a struct in the stream
3258 ********************************************************************/
3260 uint32 spoolss_size_printprocessordirectory_info_1(PRINTPROCESSOR_DIRECTORY_1 *info)
3262 int size=0;
3264 size=str_len_uni(&info->name); /* the string length */
3265 size=size+1; /* add the leading zero */
3266 size=size*2; /* convert in char */
3268 return size;
3271 /*******************************************************************
3272 return the size required by a struct in the stream
3273 ********************************************************************/
3275 uint32 spoolss_size_port_info_2(PORT_INFO_2 *info)
3277 int size=0;
3279 size+=size_of_relative_string( &info->port_name );
3280 size+=size_of_relative_string( &info->monitor_name );
3281 size+=size_of_relative_string( &info->description );
3283 size+=size_of_uint32( &info->port_type );
3284 size+=size_of_uint32( &info->reserved );
3286 return size;
3289 /*******************************************************************
3290 return the size required by a struct in the stream
3291 ********************************************************************/
3293 uint32 spoolss_size_printprocessor_info_1(PRINTPROCESSOR_1 *info)
3295 int size=0;
3296 size+=size_of_relative_string( &info->name );
3298 return size;
3301 /*******************************************************************
3302 return the size required by a struct in the stream
3303 ********************************************************************/
3305 uint32 spoolss_size_printprocdatatype_info_1(PRINTPROCDATATYPE_1 *info)
3307 int size=0;
3308 size+=size_of_relative_string( &info->name );
3310 return size;
3313 /*******************************************************************
3314 return the size required by a struct in the stream
3315 ********************************************************************/
3316 uint32 spoolss_size_printer_enum_values(PRINTER_ENUM_VALUES *p)
3318 uint32 size = 0;
3320 if (!p)
3321 return 0;
3323 /* uint32(offset) + uint32(length) + length) */
3324 size += (size_of_uint32(&p->value_len)*2) + p->value_len;
3325 size += (size_of_uint32(&p->data_len)*2) + p->data_len;
3327 size += size_of_uint32(&p->type);
3329 return size;
3332 /*******************************************************************
3333 return the size required by a struct in the stream
3334 ********************************************************************/
3336 uint32 spoolss_size_printmonitor_info_1(PRINTMONITOR_1 *info)
3338 int size=0;
3339 size+=size_of_relative_string( &info->name );
3341 return size;
3344 /*******************************************************************
3345 return the size required by a struct in the stream
3346 ********************************************************************/
3348 uint32 spoolss_size_printmonitor_info_2(PRINTMONITOR_2 *info)
3350 int size=0;
3351 size+=size_of_relative_string( &info->name);
3352 size+=size_of_relative_string( &info->environment);
3353 size+=size_of_relative_string( &info->dll_name);
3355 return size;
3358 /*******************************************************************
3359 * init a structure.
3360 ********************************************************************/
3362 BOOL make_spoolss_q_getprinterdriver2(SPOOL_Q_GETPRINTERDRIVER2 *q_u,
3363 const POLICY_HND *hnd,
3364 const fstring architecture,
3365 uint32 level, uint32 clientmajor, uint32 clientminor,
3366 NEW_BUFFER *buffer, uint32 offered)
3368 if (q_u == NULL)
3369 return False;
3371 memcpy(&q_u->handle, hnd, sizeof(q_u->handle));
3373 init_buf_unistr2(&q_u->architecture, &q_u->architecture_ptr, architecture);
3375 q_u->level=level;
3376 q_u->clientmajorversion=clientmajor;
3377 q_u->clientminorversion=clientminor;
3379 q_u->buffer=buffer;
3380 q_u->offered=offered;
3382 return True;
3385 /*******************************************************************
3386 * read a structure.
3387 * called from spoolss_getprinterdriver2 (srv_spoolss.c)
3388 ********************************************************************/
3390 BOOL spoolss_io_q_getprinterdriver2(char *desc, SPOOL_Q_GETPRINTERDRIVER2 *q_u, prs_struct *ps, int depth)
3392 prs_debug(ps, depth, desc, "spoolss_io_q_getprinterdriver2");
3393 depth++;
3395 if(!prs_align(ps))
3396 return False;
3398 if(!smb_io_pol_hnd("printer handle", &q_u->handle, ps, depth))
3399 return False;
3400 if(!prs_uint32("architecture_ptr", ps, depth, &q_u->architecture_ptr))
3401 return False;
3402 if(!smb_io_unistr2("architecture", &q_u->architecture, q_u->architecture_ptr, ps, depth))
3403 return False;
3405 if(!prs_align(ps))
3406 return False;
3407 if(!prs_uint32("level", ps, depth, &q_u->level))
3408 return False;
3410 if(!spoolss_io_buffer("", ps, depth, &q_u->buffer))
3411 return False;
3413 if(!prs_align(ps))
3414 return False;
3416 if(!prs_uint32("offered", ps, depth, &q_u->offered))
3417 return False;
3419 if(!prs_uint32("clientmajorversion", ps, depth, &q_u->clientmajorversion))
3420 return False;
3421 if(!prs_uint32("clientminorversion", ps, depth, &q_u->clientminorversion))
3422 return False;
3424 return True;
3427 /*******************************************************************
3428 * read a structure.
3429 * called from spoolss_getprinterdriver2 (srv_spoolss.c)
3430 ********************************************************************/
3432 BOOL spoolss_io_r_getprinterdriver2(char *desc, SPOOL_R_GETPRINTERDRIVER2 *r_u, prs_struct *ps, int depth)
3434 prs_debug(ps, depth, desc, "spoolss_io_r_getprinterdriver2");
3435 depth++;
3437 if (!prs_align(ps))
3438 return False;
3440 if (!spoolss_io_buffer("", ps, depth, &r_u->buffer))
3441 return False;
3443 if (!prs_align(ps))
3444 return False;
3445 if (!prs_uint32("needed", ps, depth, &r_u->needed))
3446 return False;
3447 if (!prs_uint32("servermajorversion", ps, depth, &r_u->servermajorversion))
3448 return False;
3449 if (!prs_uint32("serverminorversion", ps, depth, &r_u->serverminorversion))
3450 return False;
3451 if (!prs_werror("status", ps, depth, &r_u->status))
3452 return False;
3454 return True;
3457 /*******************************************************************
3458 * init a structure.
3459 ********************************************************************/
3461 BOOL make_spoolss_q_enumprinters(
3462 SPOOL_Q_ENUMPRINTERS *q_u,
3463 uint32 flags,
3464 fstring servername,
3465 uint32 level,
3466 NEW_BUFFER *buffer,
3467 uint32 offered
3470 q_u->flags=flags;
3472 q_u->servername_ptr = (servername != NULL) ? 1 : 0;
3473 init_buf_unistr2(&q_u->servername, &q_u->servername_ptr, servername);
3475 q_u->level=level;
3476 q_u->buffer=buffer;
3477 q_u->offered=offered;
3479 return True;
3482 /*******************************************************************
3483 * init a structure.
3484 ********************************************************************/
3486 BOOL make_spoolss_q_enumports(SPOOL_Q_ENUMPORTS *q_u,
3487 fstring servername, uint32 level,
3488 NEW_BUFFER *buffer, uint32 offered)
3490 q_u->name_ptr = (servername != NULL) ? 1 : 0;
3491 init_buf_unistr2(&q_u->name, &q_u->name_ptr, servername);
3493 q_u->level=level;
3494 q_u->buffer=buffer;
3495 q_u->offered=offered;
3497 return True;
3500 /*******************************************************************
3501 * read a structure.
3502 * called from spoolss_enumprinters (srv_spoolss.c)
3503 ********************************************************************/
3505 BOOL spoolss_io_q_enumprinters(char *desc, SPOOL_Q_ENUMPRINTERS *q_u, prs_struct *ps, int depth)
3507 prs_debug(ps, depth, desc, "spoolss_io_q_enumprinters");
3508 depth++;
3510 if (!prs_align(ps))
3511 return False;
3513 if (!prs_uint32("flags", ps, depth, &q_u->flags))
3514 return False;
3515 if (!prs_uint32("servername_ptr", ps, depth, &q_u->servername_ptr))
3516 return False;
3518 if (!smb_io_unistr2("", &q_u->servername, q_u->servername_ptr, ps, depth))
3519 return False;
3521 if (!prs_align(ps))
3522 return False;
3523 if (!prs_uint32("level", ps, depth, &q_u->level))
3524 return False;
3526 if (!spoolss_io_buffer("", ps, depth, &q_u->buffer))
3527 return False;
3529 if (!prs_align(ps))
3530 return False;
3531 if (!prs_uint32("offered", ps, depth, &q_u->offered))
3532 return False;
3534 return True;
3537 /*******************************************************************
3538 Parse a SPOOL_R_ENUMPRINTERS structure.
3539 ********************************************************************/
3541 BOOL spoolss_io_r_enumprinters(char *desc, SPOOL_R_ENUMPRINTERS *r_u, prs_struct *ps, int depth)
3543 prs_debug(ps, depth, desc, "spoolss_io_r_enumprinters");
3544 depth++;
3546 if (!prs_align(ps))
3547 return False;
3549 if (!spoolss_io_buffer("", ps, depth, &r_u->buffer))
3550 return False;
3552 if (!prs_align(ps))
3553 return False;
3555 if (!prs_uint32("needed", ps, depth, &r_u->needed))
3556 return False;
3558 if (!prs_uint32("returned", ps, depth, &r_u->returned))
3559 return False;
3561 if (!prs_werror("status", ps, depth, &r_u->status))
3562 return False;
3564 return True;
3567 /*******************************************************************
3568 * write a structure.
3569 * called from spoolss_r_enum_printers (srv_spoolss.c)
3571 ********************************************************************/
3573 BOOL spoolss_io_r_getprinter(char *desc, SPOOL_R_GETPRINTER *r_u, prs_struct *ps, int depth)
3575 prs_debug(ps, depth, desc, "spoolss_io_r_getprinter");
3576 depth++;
3578 if (!prs_align(ps))
3579 return False;
3581 if (!spoolss_io_buffer("", ps, depth, &r_u->buffer))
3582 return False;
3584 if (!prs_align(ps))
3585 return False;
3587 if (!prs_uint32("needed", ps, depth, &r_u->needed))
3588 return False;
3590 if (!prs_werror("status", ps, depth, &r_u->status))
3591 return False;
3593 return True;
3596 /*******************************************************************
3597 * read a structure.
3598 * called from spoolss_getprinter (srv_spoolss.c)
3599 ********************************************************************/
3601 BOOL spoolss_io_q_getprinter(char *desc, SPOOL_Q_GETPRINTER *q_u, prs_struct *ps, int depth)
3603 prs_debug(ps, depth, desc, "spoolss_io_q_getprinter");
3604 depth++;
3606 if (!prs_align(ps))
3607 return False;
3609 if(!smb_io_pol_hnd("printer handle", &q_u->handle, ps, depth))
3610 return False;
3611 if (!prs_uint32("level", ps, depth, &q_u->level))
3612 return False;
3614 if (!spoolss_io_buffer("", ps, depth, &q_u->buffer))
3615 return False;
3617 if (!prs_align(ps))
3618 return False;
3619 if (!prs_uint32("offered", ps, depth, &q_u->offered))
3620 return False;
3622 return True;
3625 /*******************************************************************
3626 * init a structure.
3627 ********************************************************************/
3629 BOOL make_spoolss_q_getprinter(
3630 TALLOC_CTX *mem_ctx,
3631 SPOOL_Q_GETPRINTER *q_u,
3632 const POLICY_HND *hnd,
3633 uint32 level,
3634 NEW_BUFFER *buffer,
3635 uint32 offered
3638 if (q_u == NULL)
3640 return False;
3642 memcpy(&q_u->handle, hnd, sizeof(q_u->handle));
3644 q_u->level=level;
3645 q_u->buffer=buffer;
3646 q_u->offered=offered;
3648 return True;
3651 /*******************************************************************
3652 * init a structure.
3653 ********************************************************************/
3654 BOOL make_spoolss_q_setprinter(TALLOC_CTX *mem_ctx, SPOOL_Q_SETPRINTER *q_u,
3655 const POLICY_HND *hnd, uint32 level, PRINTER_INFO_CTR *info,
3656 uint32 command)
3658 SEC_DESC *secdesc;
3659 DEVICEMODE *devmode;
3661 if (q_u == NULL)
3662 return False;
3664 memcpy(&q_u->handle, hnd, sizeof(q_u->handle));
3666 q_u->level = level;
3667 q_u->info.level = level;
3668 q_u->info.info_ptr = (info != NULL) ? 1 : 0;
3669 switch (level) {
3670 case 2:
3671 secdesc = info->printers_2->secdesc;
3672 devmode = info->printers_2->devmode;
3674 make_spoolss_printer_info_2 (mem_ctx, &q_u->info.info_2, info->printers_2);
3675 #if 1 /* JERRY TEST */
3676 q_u->secdesc_ctr = (SEC_DESC_BUF*)malloc(sizeof(SEC_DESC_BUF));
3677 if (!q_u->secdesc_ctr)
3678 return False;
3679 q_u->secdesc_ctr->ptr = (secdesc != NULL) ? 1: 0;
3680 q_u->secdesc_ctr->max_len = (secdesc) ? sizeof(SEC_DESC) + (2*sizeof(uint32)) : 0;
3681 q_u->secdesc_ctr->len = (secdesc) ? sizeof(SEC_DESC) + (2*sizeof(uint32)) : 0;
3682 q_u->secdesc_ctr->sec = secdesc;
3684 q_u->devmode_ctr.devmode_ptr = (devmode != NULL) ? 1 : 0;
3685 q_u->devmode_ctr.size = (devmode != NULL) ? sizeof(DEVICEMODE) + (3*sizeof(uint32)) : 0;
3686 q_u->devmode_ctr.devmode = devmode;
3687 #else
3688 q_u->secdesc_ctr = NULL;
3690 q_u->devmode_ctr.devmode_ptr = 0;
3691 q_u->devmode_ctr.size = 0;
3692 q_u->devmode_ctr.devmode = NULL;
3693 #endif
3694 break;
3695 default:
3696 DEBUG(0,("make_spoolss_q_setprinter: Unknown info level [%d]\n", level));
3697 break;
3701 q_u->command = command;
3703 return True;
3707 /*******************************************************************
3708 ********************************************************************/
3710 BOOL spoolss_io_r_setprinter(char *desc, SPOOL_R_SETPRINTER *r_u, prs_struct *ps, int depth)
3712 prs_debug(ps, depth, desc, "spoolss_io_r_setprinter");
3713 depth++;
3715 if(!prs_align(ps))
3716 return False;
3718 if(!prs_werror("status", ps, depth, &r_u->status))
3719 return False;
3721 return True;
3724 /*******************************************************************
3725 Marshall/unmarshall a SPOOL_Q_SETPRINTER struct.
3726 ********************************************************************/
3728 BOOL spoolss_io_q_setprinter(char *desc, SPOOL_Q_SETPRINTER *q_u, prs_struct *ps, int depth)
3730 uint32 ptr_sec_desc = 0;
3732 prs_debug(ps, depth, desc, "spoolss_io_q_setprinter");
3733 depth++;
3735 if(!prs_align(ps))
3736 return False;
3738 if(!smb_io_pol_hnd("printer handle", &q_u->handle ,ps, depth))
3739 return False;
3740 if(!prs_uint32("level", ps, depth, &q_u->level))
3741 return False;
3743 if(!spool_io_printer_info_level("", &q_u->info, ps, depth))
3744 return False;
3746 if (!spoolss_io_devmode_cont(desc, &q_u->devmode_ctr, ps, depth))
3747 return False;
3749 switch (q_u->level)
3751 case 2:
3753 ptr_sec_desc = q_u->info.info_2->secdesc_ptr;
3754 break;
3756 case 3:
3758 ptr_sec_desc = q_u->info.info_3->secdesc_ptr;
3759 break;
3762 if (ptr_sec_desc)
3764 if (!sec_io_desc_buf(desc, &q_u->secdesc_ctr, ps, depth))
3765 return False;
3766 } else {
3767 uint32 dummy = 0;
3769 /* Parse a NULL security descriptor. This should really
3770 happen inside the sec_io_desc_buf() function. */
3772 prs_debug(ps, depth, "", "sec_io_desc_buf");
3773 if (!prs_uint32("size", ps, depth + 1, &dummy))
3774 return False;
3775 if (!prs_uint32("ptr", ps, depth + 1, &dummy)) return
3776 False;
3779 if(!prs_uint32("command", ps, depth, &q_u->command))
3780 return False;
3782 return True;
3785 /*******************************************************************
3786 ********************************************************************/
3788 BOOL spoolss_io_r_fcpn(char *desc, SPOOL_R_FCPN *r_u, prs_struct *ps, int depth)
3790 prs_debug(ps, depth, desc, "spoolss_io_r_fcpn");
3791 depth++;
3793 if(!prs_align(ps))
3794 return False;
3796 if(!prs_werror("status", ps, depth, &r_u->status))
3797 return False;
3799 return True;
3802 /*******************************************************************
3803 ********************************************************************/
3805 BOOL spoolss_io_q_fcpn(char *desc, SPOOL_Q_FCPN *q_u, prs_struct *ps, int depth)
3808 prs_debug(ps, depth, desc, "spoolss_io_q_fcpn");
3809 depth++;
3811 if(!prs_align(ps))
3812 return False;
3814 if(!smb_io_pol_hnd("printer handle",&q_u->handle,ps,depth))
3815 return False;
3817 return True;
3821 /*******************************************************************
3822 ********************************************************************/
3824 BOOL spoolss_io_r_addjob(char *desc, SPOOL_R_ADDJOB *r_u, prs_struct *ps, int depth)
3826 prs_debug(ps, depth, desc, "");
3827 depth++;
3829 if(!prs_align(ps))
3830 return False;
3832 if(!spoolss_io_buffer("", ps, depth, &r_u->buffer))
3833 return False;
3835 if(!prs_align(ps))
3836 return False;
3838 if(!prs_uint32("needed", ps, depth, &r_u->needed))
3839 return False;
3841 if(!prs_werror("status", ps, depth, &r_u->status))
3842 return False;
3844 return True;
3847 /*******************************************************************
3848 ********************************************************************/
3850 BOOL spoolss_io_q_addjob(char *desc, SPOOL_Q_ADDJOB *q_u, prs_struct *ps, int depth)
3852 prs_debug(ps, depth, desc, "");
3853 depth++;
3855 if(!prs_align(ps))
3856 return False;
3858 if(!smb_io_pol_hnd("printer handle", &q_u->handle, ps, depth))
3859 return False;
3860 if(!prs_uint32("level", ps, depth, &q_u->level))
3861 return False;
3863 if(!spoolss_io_buffer("", ps, depth, &q_u->buffer))
3864 return False;
3866 if(!prs_align(ps))
3867 return False;
3869 if(!prs_uint32("offered", ps, depth, &q_u->offered))
3870 return False;
3872 return True;
3875 /*******************************************************************
3876 ********************************************************************/
3878 BOOL spoolss_io_r_enumjobs(char *desc, SPOOL_R_ENUMJOBS *r_u, prs_struct *ps, int depth)
3880 prs_debug(ps, depth, desc, "spoolss_io_r_enumjobs");
3881 depth++;
3883 if (!prs_align(ps))
3884 return False;
3886 if (!spoolss_io_buffer("", ps, depth, &r_u->buffer))
3887 return False;
3889 if (!prs_align(ps))
3890 return False;
3892 if (!prs_uint32("needed", ps, depth, &r_u->needed))
3893 return False;
3895 if (!prs_uint32("returned", ps, depth, &r_u->returned))
3896 return False;
3898 if (!prs_werror("status", ps, depth, &r_u->status))
3899 return False;
3901 return True;
3904 /*******************************************************************
3905 ********************************************************************/
3907 BOOL make_spoolss_q_enumjobs(SPOOL_Q_ENUMJOBS *q_u, const POLICY_HND *hnd,
3908 uint32 firstjob,
3909 uint32 numofjobs,
3910 uint32 level,
3911 NEW_BUFFER *buffer,
3912 uint32 offered)
3914 if (q_u == NULL)
3916 return False;
3918 memcpy(&q_u->handle, hnd, sizeof(q_u->handle));
3919 q_u->firstjob = firstjob;
3920 q_u->numofjobs = numofjobs;
3921 q_u->level = level;
3922 q_u->buffer= buffer;
3923 q_u->offered = offered;
3924 return True;
3927 /*******************************************************************
3928 ********************************************************************/
3930 BOOL spoolss_io_q_enumjobs(char *desc, SPOOL_Q_ENUMJOBS *q_u, prs_struct *ps, int depth)
3932 prs_debug(ps, depth, desc, "spoolss_io_q_enumjobs");
3933 depth++;
3935 if (!prs_align(ps))
3936 return False;
3938 if (!smb_io_pol_hnd("printer handle",&q_u->handle, ps, depth))
3939 return False;
3941 if (!prs_uint32("firstjob", ps, depth, &q_u->firstjob))
3942 return False;
3943 if (!prs_uint32("numofjobs", ps, depth, &q_u->numofjobs))
3944 return False;
3945 if (!prs_uint32("level", ps, depth, &q_u->level))
3946 return False;
3948 if (!spoolss_io_buffer("", ps, depth, &q_u->buffer))
3949 return False;
3951 if (!prs_uint32("offered", ps, depth, &q_u->offered))
3952 return False;
3954 return True;
3957 /*******************************************************************
3958 ********************************************************************/
3960 BOOL spoolss_io_r_schedulejob(char *desc, SPOOL_R_SCHEDULEJOB *r_u, prs_struct *ps, int depth)
3962 prs_debug(ps, depth, desc, "spoolss_io_r_schedulejob");
3963 depth++;
3965 if(!prs_align(ps))
3966 return False;
3968 if(!prs_werror("status", ps, depth, &r_u->status))
3969 return False;
3971 return True;
3974 /*******************************************************************
3975 ********************************************************************/
3977 BOOL spoolss_io_q_schedulejob(char *desc, SPOOL_Q_SCHEDULEJOB *q_u, prs_struct *ps, int depth)
3979 prs_debug(ps, depth, desc, "spoolss_io_q_schedulejob");
3980 depth++;
3982 if(!prs_align(ps))
3983 return False;
3985 if(!smb_io_pol_hnd("printer handle",&q_u->handle,ps,depth))
3986 return False;
3987 if(!prs_uint32("jobid", ps, depth, &q_u->jobid))
3988 return False;
3990 return True;
3993 /*******************************************************************
3994 ********************************************************************/
3996 BOOL spoolss_io_r_setjob(char *desc, SPOOL_R_SETJOB *r_u, prs_struct *ps, int depth)
3998 prs_debug(ps, depth, desc, "spoolss_io_r_setjob");
3999 depth++;
4001 if(!prs_align(ps))
4002 return False;
4004 if(!prs_werror("status", ps, depth, &r_u->status))
4005 return False;
4007 return True;
4010 /*******************************************************************
4011 ********************************************************************/
4013 BOOL spoolss_io_q_setjob(char *desc, SPOOL_Q_SETJOB *q_u, prs_struct *ps, int depth)
4015 prs_debug(ps, depth, desc, "spoolss_io_q_setjob");
4016 depth++;
4018 if(!prs_align(ps))
4019 return False;
4021 if(!smb_io_pol_hnd("printer handle",&q_u->handle,ps,depth))
4022 return False;
4023 if(!prs_uint32("jobid", ps, depth, &q_u->jobid))
4024 return False;
4026 * level is usually 0. If (level!=0) then I'm in trouble !
4027 * I will try to generate setjob command with level!=0, one day.
4029 if(!prs_uint32("level", ps, depth, &q_u->level))
4030 return False;
4031 if(!prs_uint32("command", ps, depth, &q_u->command))
4032 return False;
4034 return True;
4037 /*******************************************************************
4038 Parse a SPOOL_R_ENUMPRINTERDRIVERS structure.
4039 ********************************************************************/
4041 BOOL spoolss_io_r_enumprinterdrivers(char *desc, SPOOL_R_ENUMPRINTERDRIVERS *r_u, prs_struct *ps, int depth)
4043 prs_debug(ps, depth, desc, "spoolss_io_r_enumprinterdrivers");
4044 depth++;
4046 if (!prs_align(ps))
4047 return False;
4049 if (!spoolss_io_buffer("", ps, depth, &r_u->buffer))
4050 return False;
4052 if (!prs_align(ps))
4053 return False;
4055 if (!prs_uint32("needed", ps, depth, &r_u->needed))
4056 return False;
4058 if (!prs_uint32("returned", ps, depth, &r_u->returned))
4059 return False;
4061 if (!prs_werror("status", ps, depth, &r_u->status))
4062 return False;
4064 return True;
4067 /*******************************************************************
4068 * init a structure.
4069 ********************************************************************/
4071 BOOL make_spoolss_q_enumprinterdrivers(SPOOL_Q_ENUMPRINTERDRIVERS *q_u,
4072 const char *name,
4073 const char *environment,
4074 uint32 level,
4075 NEW_BUFFER *buffer, uint32 offered)
4077 init_buf_unistr2(&q_u->name, &q_u->name_ptr, name);
4078 init_buf_unistr2(&q_u->environment, &q_u->environment_ptr, environment);
4080 q_u->level=level;
4081 q_u->buffer=buffer;
4082 q_u->offered=offered;
4084 return True;
4087 /*******************************************************************
4088 Parse a SPOOL_Q_ENUMPRINTERDRIVERS structure.
4089 ********************************************************************/
4091 BOOL spoolss_io_q_enumprinterdrivers(char *desc, SPOOL_Q_ENUMPRINTERDRIVERS *q_u, prs_struct *ps, int depth)
4094 prs_debug(ps, depth, desc, "spoolss_io_q_enumprinterdrivers");
4095 depth++;
4097 if (!prs_align(ps))
4098 return False;
4100 if (!prs_uint32("name_ptr", ps, depth, &q_u->name_ptr))
4101 return False;
4102 if (!smb_io_unistr2("", &q_u->name, q_u->name_ptr,ps, depth))
4103 return False;
4105 if (!prs_align(ps))
4106 return False;
4107 if (!prs_uint32("environment_ptr", ps, depth, &q_u->environment_ptr))
4108 return False;
4109 if (!smb_io_unistr2("", &q_u->environment, q_u->environment_ptr, ps, depth))
4110 return False;
4112 if (!prs_align(ps))
4113 return False;
4114 if (!prs_uint32("level", ps, depth, &q_u->level))
4115 return False;
4117 if (!spoolss_io_buffer("", ps, depth, &q_u->buffer))
4118 return False;
4120 if (!prs_align(ps))
4121 return False;
4123 if (!prs_uint32("offered", ps, depth, &q_u->offered))
4124 return False;
4126 return True;
4129 /*******************************************************************
4130 ********************************************************************/
4132 BOOL spoolss_io_q_enumforms(char *desc, SPOOL_Q_ENUMFORMS *q_u, prs_struct *ps, int depth)
4135 prs_debug(ps, depth, desc, "spoolss_io_q_enumforms");
4136 depth++;
4138 if (!prs_align(ps))
4139 return False;
4140 if (!smb_io_pol_hnd("printer handle",&q_u->handle,ps,depth))
4141 return False;
4142 if (!prs_uint32("level", ps, depth, &q_u->level))
4143 return False;
4145 if (!spoolss_io_buffer("", ps, depth, &q_u->buffer))
4146 return False;
4148 if (!prs_align(ps))
4149 return False;
4150 if (!prs_uint32("offered", ps, depth, &q_u->offered))
4151 return False;
4153 return True;
4156 /*******************************************************************
4157 ********************************************************************/
4159 BOOL spoolss_io_r_enumforms(char *desc, SPOOL_R_ENUMFORMS *r_u, prs_struct *ps, int depth)
4161 prs_debug(ps, depth, desc, "spoolss_io_r_enumforms");
4162 depth++;
4164 if (!prs_align(ps))
4165 return False;
4167 if (!spoolss_io_buffer("", ps, depth, &r_u->buffer))
4168 return False;
4170 if (!prs_align(ps))
4171 return False;
4173 if (!prs_uint32("size of buffer needed", ps, depth, &r_u->needed))
4174 return False;
4176 if (!prs_uint32("numofforms", ps, depth, &r_u->numofforms))
4177 return False;
4179 if (!prs_werror("status", ps, depth, &r_u->status))
4180 return False;
4182 return True;
4185 /*******************************************************************
4186 ********************************************************************/
4188 BOOL spoolss_io_q_getform(char *desc, SPOOL_Q_GETFORM *q_u, prs_struct *ps, int depth)
4191 prs_debug(ps, depth, desc, "spoolss_io_q_getform");
4192 depth++;
4194 if (!prs_align(ps))
4195 return False;
4196 if (!smb_io_pol_hnd("printer handle",&q_u->handle,ps,depth))
4197 return False;
4198 if (!smb_io_unistr2("", &q_u->formname,True,ps,depth))
4199 return False;
4201 if (!prs_align(ps))
4202 return False;
4204 if (!prs_uint32("level", ps, depth, &q_u->level))
4205 return False;
4207 if (!spoolss_io_buffer("", ps, depth, &q_u->buffer))
4208 return False;
4210 if (!prs_align(ps))
4211 return False;
4212 if (!prs_uint32("offered", ps, depth, &q_u->offered))
4213 return False;
4215 return True;
4218 /*******************************************************************
4219 ********************************************************************/
4221 BOOL spoolss_io_r_getform(char *desc, SPOOL_R_GETFORM *r_u, prs_struct *ps, int depth)
4223 prs_debug(ps, depth, desc, "spoolss_io_r_getform");
4224 depth++;
4226 if (!prs_align(ps))
4227 return False;
4229 if (!spoolss_io_buffer("", ps, depth, &r_u->buffer))
4230 return False;
4232 if (!prs_align(ps))
4233 return False;
4235 if (!prs_uint32("size of buffer needed", ps, depth, &r_u->needed))
4236 return False;
4238 if (!prs_werror("status", ps, depth, &r_u->status))
4239 return False;
4241 return True;
4244 /*******************************************************************
4245 Parse a SPOOL_R_ENUMPORTS structure.
4246 ********************************************************************/
4248 BOOL spoolss_io_r_enumports(char *desc, SPOOL_R_ENUMPORTS *r_u, prs_struct *ps, int depth)
4250 prs_debug(ps, depth, desc, "spoolss_io_r_enumports");
4251 depth++;
4253 if (!prs_align(ps))
4254 return False;
4256 if (!spoolss_io_buffer("", ps, depth, &r_u->buffer))
4257 return False;
4259 if (!prs_align(ps))
4260 return False;
4262 if (!prs_uint32("needed", ps, depth, &r_u->needed))
4263 return False;
4265 if (!prs_uint32("returned", ps, depth, &r_u->returned))
4266 return False;
4268 if (!prs_werror("status", ps, depth, &r_u->status))
4269 return False;
4271 return True;
4274 /*******************************************************************
4275 ********************************************************************/
4277 BOOL spoolss_io_q_enumports(char *desc, SPOOL_Q_ENUMPORTS *q_u, prs_struct *ps, int depth)
4279 prs_debug(ps, depth, desc, "");
4280 depth++;
4282 if (!prs_align(ps))
4283 return False;
4285 if (!prs_uint32("", ps, depth, &q_u->name_ptr))
4286 return False;
4287 if (!smb_io_unistr2("", &q_u->name,True,ps,depth))
4288 return False;
4290 if (!prs_align(ps))
4291 return False;
4292 if (!prs_uint32("level", ps, depth, &q_u->level))
4293 return False;
4295 if (!spoolss_io_buffer("", ps, depth, &q_u->buffer))
4296 return False;
4298 if (!prs_align(ps))
4299 return False;
4300 if (!prs_uint32("offered", ps, depth, &q_u->offered))
4301 return False;
4303 return True;
4306 /*******************************************************************
4307 Parse a SPOOL_PRINTER_INFO_LEVEL_1 structure.
4308 ********************************************************************/
4310 BOOL spool_io_printer_info_level_1(char *desc, SPOOL_PRINTER_INFO_LEVEL_1 *il, prs_struct *ps, int depth)
4312 prs_debug(ps, depth, desc, "spool_io_printer_info_level_1");
4313 depth++;
4315 if(!prs_align(ps))
4316 return False;
4318 if(!prs_uint32("flags", ps, depth, &il->flags))
4319 return False;
4320 if(!prs_uint32("description_ptr", ps, depth, &il->description_ptr))
4321 return False;
4322 if(!prs_uint32("name_ptr", ps, depth, &il->name_ptr))
4323 return False;
4324 if(!prs_uint32("comment_ptr", ps, depth, &il->comment_ptr))
4325 return False;
4327 if(!smb_io_unistr2("description", &il->description, il->description_ptr, ps, depth))
4328 return False;
4329 if(!smb_io_unistr2("name", &il->name, il->name_ptr, ps, depth))
4330 return False;
4331 if(!smb_io_unistr2("comment", &il->comment, il->comment_ptr, ps, depth))
4332 return False;
4334 return True;
4337 /*******************************************************************
4338 Parse a SPOOL_PRINTER_INFO_LEVEL_3 structure.
4339 ********************************************************************/
4341 BOOL spool_io_printer_info_level_3(char *desc, SPOOL_PRINTER_INFO_LEVEL_3 *il, prs_struct *ps, int depth)
4343 prs_debug(ps, depth, desc, "spool_io_printer_info_level_3");
4344 depth++;
4346 if(!prs_align(ps))
4347 return False;
4349 if(!prs_uint32("secdesc_ptr", ps, depth, &il->secdesc_ptr))
4350 return False;
4352 return True;
4355 /*******************************************************************
4356 Parse a SPOOL_PRINTER_INFO_LEVEL_2 structure.
4357 ********************************************************************/
4359 BOOL spool_io_printer_info_level_2(char *desc, SPOOL_PRINTER_INFO_LEVEL_2 *il, prs_struct *ps, int depth)
4361 prs_debug(ps, depth, desc, "spool_io_printer_info_level_2");
4362 depth++;
4364 if(!prs_align(ps))
4365 return False;
4367 if(!prs_uint32("servername_ptr", ps, depth, &il->servername_ptr))
4368 return False;
4369 if(!prs_uint32("printername_ptr", ps, depth, &il->printername_ptr))
4370 return False;
4371 if(!prs_uint32("sharename_ptr", ps, depth, &il->sharename_ptr))
4372 return False;
4373 if(!prs_uint32("portname_ptr", ps, depth, &il->portname_ptr))
4374 return False;
4376 if(!prs_uint32("drivername_ptr", ps, depth, &il->drivername_ptr))
4377 return False;
4378 if(!prs_uint32("comment_ptr", ps, depth, &il->comment_ptr))
4379 return False;
4380 if(!prs_uint32("location_ptr", ps, depth, &il->location_ptr))
4381 return False;
4382 if(!prs_uint32("devmode_ptr", ps, depth, &il->devmode_ptr))
4383 return False;
4384 if(!prs_uint32("sepfile_ptr", ps, depth, &il->sepfile_ptr))
4385 return False;
4386 if(!prs_uint32("printprocessor_ptr", ps, depth, &il->printprocessor_ptr))
4387 return False;
4388 if(!prs_uint32("datatype_ptr", ps, depth, &il->datatype_ptr))
4389 return False;
4390 if(!prs_uint32("parameters_ptr", ps, depth, &il->parameters_ptr))
4391 return False;
4392 if(!prs_uint32("secdesc_ptr", ps, depth, &il->secdesc_ptr))
4393 return False;
4395 if(!prs_uint32("attributes", ps, depth, &il->attributes))
4396 return False;
4397 if(!prs_uint32("priority", ps, depth, &il->priority))
4398 return False;
4399 if(!prs_uint32("default_priority", ps, depth, &il->default_priority))
4400 return False;
4401 if(!prs_uint32("starttime", ps, depth, &il->starttime))
4402 return False;
4403 if(!prs_uint32("untiltime", ps, depth, &il->untiltime))
4404 return False;
4405 if(!prs_uint32("status", ps, depth, &il->status))
4406 return False;
4407 if(!prs_uint32("cjobs", ps, depth, &il->cjobs))
4408 return False;
4409 if(!prs_uint32("averageppm", ps, depth, &il->averageppm))
4410 return False;
4412 if(!smb_io_unistr2("servername", &il->servername, il->servername_ptr, ps, depth))
4413 return False;
4414 if(!smb_io_unistr2("printername", &il->printername, il->printername_ptr, ps, depth))
4415 return False;
4416 if(!smb_io_unistr2("sharename", &il->sharename, il->sharename_ptr, ps, depth))
4417 return False;
4418 if(!smb_io_unistr2("portname", &il->portname, il->portname_ptr, ps, depth))
4419 return False;
4420 if(!smb_io_unistr2("drivername", &il->drivername, il->drivername_ptr, ps, depth))
4421 return False;
4422 if(!smb_io_unistr2("comment", &il->comment, il->comment_ptr, ps, depth))
4423 return False;
4424 if(!smb_io_unistr2("location", &il->location, il->location_ptr, ps, depth))
4425 return False;
4426 if(!smb_io_unistr2("sepfile", &il->sepfile, il->sepfile_ptr, ps, depth))
4427 return False;
4428 if(!smb_io_unistr2("printprocessor", &il->printprocessor, il->printprocessor_ptr, ps, depth))
4429 return False;
4430 if(!smb_io_unistr2("datatype", &il->datatype, il->datatype_ptr, ps, depth))
4431 return False;
4432 if(!smb_io_unistr2("parameters", &il->parameters, il->parameters_ptr, ps, depth))
4433 return False;
4435 return True;
4438 /*******************************************************************
4439 ********************************************************************/
4441 BOOL spool_io_printer_info_level(char *desc, SPOOL_PRINTER_INFO_LEVEL *il, prs_struct *ps, int depth)
4443 prs_debug(ps, depth, desc, "spool_io_printer_info_level");
4444 depth++;
4446 if(!prs_align(ps))
4447 return False;
4448 if(!prs_uint32("level", ps, depth, &il->level))
4449 return False;
4450 if(!prs_uint32("info_ptr", ps, depth, &il->info_ptr))
4451 return False;
4453 /* if no struct inside just return */
4454 if (il->info_ptr==0) {
4455 if (UNMARSHALLING(ps)) {
4456 il->info_1=NULL;
4457 il->info_2=NULL;
4459 return True;
4462 switch (il->level) {
4464 * level 0 is used by setprinter when managing the queue
4465 * (hold, stop, start a queue)
4467 case 0:
4468 break;
4469 /* DOCUMENT ME!!! What is level 1 used for? */
4470 case 1:
4472 if (UNMARSHALLING(ps)) {
4473 if ((il->info_1=(SPOOL_PRINTER_INFO_LEVEL_1 *)prs_alloc_mem(ps,sizeof(SPOOL_PRINTER_INFO_LEVEL_1))) == NULL)
4474 return False;
4476 if (!spool_io_printer_info_level_1("", il->info_1, ps, depth))
4477 return False;
4478 break;
4481 * level 2 is used by addprinter
4482 * and by setprinter when updating printer's info
4484 case 2:
4485 if (UNMARSHALLING(ps)) {
4486 if ((il->info_2=(SPOOL_PRINTER_INFO_LEVEL_2 *)prs_alloc_mem(ps,sizeof(SPOOL_PRINTER_INFO_LEVEL_2))) == NULL)
4487 return False;
4489 if (!spool_io_printer_info_level_2("", il->info_2, ps, depth))
4490 return False;
4491 break;
4492 /* DOCUMENT ME!!! What is level 3 used for? */
4493 case 3:
4495 if (UNMARSHALLING(ps)) {
4496 if ((il->info_3=(SPOOL_PRINTER_INFO_LEVEL_3 *)prs_alloc_mem(ps,sizeof(SPOOL_PRINTER_INFO_LEVEL_3))) == NULL)
4497 return False;
4499 if (!spool_io_printer_info_level_3("", il->info_3, ps, depth))
4500 return False;
4501 break;
4505 return True;
4508 /*******************************************************************
4509 ********************************************************************/
4511 BOOL spoolss_io_q_addprinterex(char *desc, SPOOL_Q_ADDPRINTEREX *q_u, prs_struct *ps, int depth)
4513 uint32 ptr_sec_desc = 0;
4515 prs_debug(ps, depth, desc, "spoolss_io_q_addprinterex");
4516 depth++;
4518 if(!prs_align(ps))
4519 return False;
4520 if(!prs_uint32("", ps, depth, &q_u->server_name_ptr))
4521 return False;
4522 if(!smb_io_unistr2("", &q_u->server_name, q_u->server_name_ptr, ps, depth))
4523 return False;
4525 if(!prs_align(ps))
4526 return False;
4528 if(!prs_uint32("info_level", ps, depth, &q_u->level))
4529 return False;
4531 if(!spool_io_printer_info_level("", &q_u->info, ps, depth))
4532 return False;
4534 if (!spoolss_io_devmode_cont(desc, &q_u->devmode_ctr, ps, depth))
4535 return False;
4537 switch (q_u->level) {
4538 case 2:
4539 ptr_sec_desc = q_u->info.info_2->secdesc_ptr;
4540 break;
4541 case 3:
4542 ptr_sec_desc = q_u->info.info_3->secdesc_ptr;
4543 break;
4545 if (ptr_sec_desc) {
4546 if (!sec_io_desc_buf(desc, &q_u->secdesc_ctr, ps, depth))
4547 return False;
4548 } else {
4549 uint32 dummy;
4551 /* Parse a NULL security descriptor. This should really
4552 happen inside the sec_io_desc_buf() function. */
4554 prs_debug(ps, depth, "", "sec_io_desc_buf");
4555 if (!prs_uint32("size", ps, depth + 1, &dummy))
4556 return False;
4557 if (!prs_uint32("ptr", ps, depth + 1, &dummy))
4558 return False;
4561 if(!prs_uint32("user_switch", ps, depth, &q_u->user_switch))
4562 return False;
4563 if(!spool_io_user_level("", &q_u->user_ctr, ps, depth))
4564 return False;
4566 return True;
4569 /*******************************************************************
4570 ********************************************************************/
4572 BOOL spoolss_io_r_addprinterex(char *desc, SPOOL_R_ADDPRINTEREX *r_u,
4573 prs_struct *ps, int depth)
4575 prs_debug(ps, depth, desc, "spoolss_io_r_addprinterex");
4576 depth++;
4578 if(!smb_io_pol_hnd("printer handle",&r_u->handle,ps,depth))
4579 return False;
4581 if(!prs_werror("status", ps, depth, &r_u->status))
4582 return False;
4584 return True;
4587 /*******************************************************************
4588 ********************************************************************/
4590 BOOL spool_io_printer_driver_info_level_3(char *desc, SPOOL_PRINTER_DRIVER_INFO_LEVEL_3 **q_u,
4591 prs_struct *ps, int depth)
4593 SPOOL_PRINTER_DRIVER_INFO_LEVEL_3 *il;
4595 prs_debug(ps, depth, desc, "spool_io_printer_driver_info_level_3");
4596 depth++;
4598 /* reading */
4599 if (UNMARSHALLING(ps)) {
4600 il=(SPOOL_PRINTER_DRIVER_INFO_LEVEL_3 *)prs_alloc_mem(ps,sizeof(SPOOL_PRINTER_DRIVER_INFO_LEVEL_3));
4601 if(il == NULL)
4602 return False;
4603 *q_u=il;
4605 else {
4606 il=*q_u;
4609 if(!prs_align(ps))
4610 return False;
4612 if(!prs_uint32("cversion", ps, depth, &il->cversion))
4613 return False;
4614 if(!prs_uint32("name", ps, depth, &il->name_ptr))
4615 return False;
4616 if(!prs_uint32("environment", ps, depth, &il->environment_ptr))
4617 return False;
4618 if(!prs_uint32("driverpath", ps, depth, &il->driverpath_ptr))
4619 return False;
4620 if(!prs_uint32("datafile", ps, depth, &il->datafile_ptr))
4621 return False;
4622 if(!prs_uint32("configfile", ps, depth, &il->configfile_ptr))
4623 return False;
4624 if(!prs_uint32("helpfile", ps, depth, &il->helpfile_ptr))
4625 return False;
4626 if(!prs_uint32("monitorname", ps, depth, &il->monitorname_ptr))
4627 return False;
4628 if(!prs_uint32("defaultdatatype", ps, depth, &il->defaultdatatype_ptr))
4629 return False;
4630 if(!prs_uint32("dependentfilessize", ps, depth, &il->dependentfilessize))
4631 return False;
4632 if(!prs_uint32("dependentfiles", ps, depth, &il->dependentfiles_ptr))
4633 return False;
4635 if(!prs_align(ps))
4636 return False;
4638 if(!smb_io_unistr2("name", &il->name, il->name_ptr, ps, depth))
4639 return False;
4640 if(!smb_io_unistr2("environment", &il->environment, il->environment_ptr, ps, depth))
4641 return False;
4642 if(!smb_io_unistr2("driverpath", &il->driverpath, il->driverpath_ptr, ps, depth))
4643 return False;
4644 if(!smb_io_unistr2("datafile", &il->datafile, il->datafile_ptr, ps, depth))
4645 return False;
4646 if(!smb_io_unistr2("configfile", &il->configfile, il->configfile_ptr, ps, depth))
4647 return False;
4648 if(!smb_io_unistr2("helpfile", &il->helpfile, il->helpfile_ptr, ps, depth))
4649 return False;
4650 if(!smb_io_unistr2("monitorname", &il->monitorname, il->monitorname_ptr, ps, depth))
4651 return False;
4652 if(!smb_io_unistr2("defaultdatatype", &il->defaultdatatype, il->defaultdatatype_ptr, ps, depth))
4653 return False;
4655 if(!prs_align(ps))
4656 return False;
4658 if (il->dependentfiles_ptr)
4659 smb_io_buffer5("", &il->dependentfiles, ps, depth);
4661 return True;
4664 /*******************************************************************
4665 parse a SPOOL_PRINTER_DRIVER_INFO_LEVEL_6 structure
4666 ********************************************************************/
4668 BOOL spool_io_printer_driver_info_level_6(char *desc, SPOOL_PRINTER_DRIVER_INFO_LEVEL_6 **q_u,
4669 prs_struct *ps, int depth)
4671 SPOOL_PRINTER_DRIVER_INFO_LEVEL_6 *il;
4673 prs_debug(ps, depth, desc, "spool_io_printer_driver_info_level_6");
4674 depth++;
4676 /* reading */
4677 if (UNMARSHALLING(ps)) {
4678 il=(SPOOL_PRINTER_DRIVER_INFO_LEVEL_6 *)prs_alloc_mem(ps,sizeof(SPOOL_PRINTER_DRIVER_INFO_LEVEL_6));
4679 if(il == NULL)
4680 return False;
4681 *q_u=il;
4683 else {
4684 il=*q_u;
4687 if(!prs_align(ps))
4688 return False;
4691 /* parse the main elements the packet */
4693 if(!prs_uint32("version", ps, depth, &il->version))
4694 return False;
4696 if(!prs_uint32("name_ptr", ps, depth, &il->name_ptr))
4697 return False;
4699 * If name_ptr is NULL then the next 4 bytes are the name_ptr. A driver
4700 * with a NULL name just isn't a driver For example: "HP LaserJet 4si"
4701 * from W2K CDROM (which uses unidriver). JohnR 010205
4703 if (!il->name_ptr) {
4704 DEBUG(5,("spool_io_printer_driver_info_level_6: name_ptr is NULL! Get next value\n"));
4705 if(!prs_uint32("name_ptr", ps, depth, &il->name_ptr))
4706 return False;
4709 if(!prs_uint32("environment_ptr", ps, depth, &il->environment_ptr))
4710 return False;
4711 if(!prs_uint32("driverpath_ptr", ps, depth, &il->driverpath_ptr))
4712 return False;
4713 if(!prs_uint32("datafile_ptr", ps, depth, &il->datafile_ptr))
4714 return False;
4715 if(!prs_uint32("configfile_ptr", ps, depth, &il->configfile_ptr))
4716 return False;
4717 if(!prs_uint32("helpfile_ptr", ps, depth, &il->helpfile_ptr))
4718 return False;
4719 if(!prs_uint32("monitorname_ptr", ps, depth, &il->monitorname_ptr))
4720 return False;
4721 if(!prs_uint32("defaultdatatype_ptr", ps, depth, &il->defaultdatatype_ptr))
4722 return False;
4723 if(!prs_uint32("dependentfiles_len", ps, depth, &il->dependentfiles_len))
4724 return False;
4725 if(!prs_uint32("dependentfiles_ptr", ps, depth, &il->dependentfiles_ptr))
4726 return False;
4727 if(!prs_uint32("previousnames_len", ps, depth, &il->previousnames_len))
4728 return False;
4729 if(!prs_uint32("previousnames_ptr", ps, depth, &il->previousnames_ptr))
4730 return False;
4731 if(!smb_io_time("driverdate", &il->driverdate, ps, depth))
4732 return False;
4733 if(!prs_uint32("dummy4", ps, depth, &il->dummy4))
4734 return False;
4735 if(!prs_uint64("driverversion", ps, depth, &il->driverversion))
4736 return False;
4737 if(!prs_uint32("mfgname_ptr", ps, depth, &il->mfgname_ptr))
4738 return False;
4739 if(!prs_uint32("oemurl_ptr", ps, depth, &il->oemurl_ptr))
4740 return False;
4741 if(!prs_uint32("hardwareid_ptr", ps, depth, &il->hardwareid_ptr))
4742 return False;
4743 if(!prs_uint32("provider_ptr", ps, depth, &il->provider_ptr))
4744 return False;
4746 /* parse the structures in the packet */
4748 if(!smb_io_unistr2("name", &il->name, il->name_ptr, ps, depth))
4749 return False;
4750 if(!prs_align(ps))
4751 return False;
4753 if(!smb_io_unistr2("environment", &il->environment, il->environment_ptr, ps, depth))
4754 return False;
4755 if(!prs_align(ps))
4756 return False;
4758 if(!smb_io_unistr2("driverpath", &il->driverpath, il->driverpath_ptr, ps, depth))
4759 return False;
4760 if(!prs_align(ps))
4761 return False;
4763 if(!smb_io_unistr2("datafile", &il->datafile, il->datafile_ptr, ps, depth))
4764 return False;
4765 if(!prs_align(ps))
4766 return False;
4768 if(!smb_io_unistr2("configfile", &il->configfile, il->configfile_ptr, ps, depth))
4769 return False;
4770 if(!prs_align(ps))
4771 return False;
4773 if(!smb_io_unistr2("helpfile", &il->helpfile, il->helpfile_ptr, ps, depth))
4774 return False;
4775 if(!prs_align(ps))
4776 return False;
4778 if(!smb_io_unistr2("monitorname", &il->monitorname, il->monitorname_ptr, ps, depth))
4779 return False;
4780 if(!prs_align(ps))
4781 return False;
4783 if(!smb_io_unistr2("defaultdatatype", &il->defaultdatatype, il->defaultdatatype_ptr, ps, depth))
4784 return False;
4785 if(!prs_align(ps))
4786 return False;
4787 if (il->dependentfiles_ptr) {
4788 if(!smb_io_buffer5("dependentfiles", &il->dependentfiles, ps, depth))
4789 return False;
4790 if(!prs_align(ps))
4791 return False;
4793 if (il->previousnames_ptr) {
4794 if(!smb_io_buffer5("previousnames", &il->previousnames, ps, depth))
4795 return False;
4796 if(!prs_align(ps))
4797 return False;
4799 if(!smb_io_unistr2("mfgname", &il->mfgname, il->mfgname_ptr, ps, depth))
4800 return False;
4801 if(!prs_align(ps))
4802 return False;
4803 if(!smb_io_unistr2("oemurl", &il->oemurl, il->oemurl_ptr, ps, depth))
4804 return False;
4805 if(!prs_align(ps))
4806 return False;
4807 if(!smb_io_unistr2("hardwareid", &il->hardwareid, il->hardwareid_ptr, ps, depth))
4808 return False;
4809 if(!prs_align(ps))
4810 return False;
4811 if(!smb_io_unistr2("provider", &il->provider, il->provider_ptr, ps, depth))
4812 return False;
4814 return True;
4817 /*******************************************************************
4818 convert a buffer of UNICODE strings null terminated
4819 the buffer is terminated by a NULL
4821 convert to an dos codepage array (null terminated)
4823 dynamically allocate memory
4825 ********************************************************************/
4826 static BOOL uniarray_2_dosarray(BUFFER5 *buf5, fstring **ar)
4828 fstring f, *tar;
4829 int n = 0;
4830 char *src;
4832 if (buf5==NULL)
4833 return False;
4835 src = (char *)buf5->buffer;
4836 *ar = NULL;
4838 while (src < ((char *)buf5->buffer) + buf5->buf_len*2) {
4839 unistr_to_dos(f, src, sizeof(f)-1);
4840 src = skip_unibuf(src, 2*buf5->buf_len - PTR_DIFF(src,buf5->buffer));
4841 tar = (fstring *)Realloc(*ar, sizeof(fstring)*(n+2));
4842 if (!tar)
4843 return False;
4844 else
4845 *ar = tar;
4846 fstrcpy((*ar)[n], f);
4847 n++;
4849 fstrcpy((*ar)[n], "");
4851 return True;
4857 /*******************************************************************
4858 read a UNICODE array with null terminated strings
4859 and null terminated array
4860 and size of array at beginning
4861 ********************************************************************/
4863 BOOL smb_io_unibuffer(char *desc, UNISTR2 *buffer, prs_struct *ps, int depth)
4865 if (buffer==NULL) return False;
4867 buffer->undoc=0;
4868 buffer->uni_str_len=buffer->uni_max_len;
4870 if(!prs_uint32("buffer_size", ps, depth, &buffer->uni_max_len))
4871 return False;
4873 if(!prs_unistr2(True, "buffer ", ps, depth, buffer))
4874 return False;
4876 return True;
4879 /*******************************************************************
4880 ********************************************************************/
4882 BOOL spool_io_printer_driver_info_level(char *desc, SPOOL_PRINTER_DRIVER_INFO_LEVEL *il, prs_struct *ps, int depth)
4884 prs_debug(ps, depth, desc, "spool_io_printer_driver_info_level");
4885 depth++;
4887 if(!prs_align(ps))
4888 return False;
4889 if(!prs_uint32("level", ps, depth, &il->level))
4890 return False;
4891 if(!prs_uint32("ptr", ps, depth, &il->ptr))
4892 return False;
4894 if (il->ptr==0)
4895 return True;
4897 switch (il->level) {
4898 case 3:
4899 if(!spool_io_printer_driver_info_level_3("", &il->info_3, ps, depth))
4900 return False;
4901 break;
4902 case 6:
4903 if(!spool_io_printer_driver_info_level_6("", &il->info_6, ps, depth))
4904 return False;
4905 break;
4906 default:
4907 return False;
4910 return True;
4913 /*******************************************************************
4914 init a SPOOL_Q_ADDPRINTERDRIVER struct
4915 ******************************************************************/
4917 BOOL make_spoolss_q_addprinterdriver(
4918 TALLOC_CTX *mem_ctx,
4919 SPOOL_Q_ADDPRINTERDRIVER *q_u,
4920 const char* srv_name,
4921 uint32 level,
4922 PRINTER_DRIVER_CTR *info)
4924 DEBUG(5,("make_spoolss_q_addprinterdriver\n"));
4926 q_u->server_name_ptr = (srv_name!=NULL)?1:0;
4927 init_unistr2(&q_u->server_name, srv_name, strlen(srv_name)+1);
4929 q_u->level = level;
4931 q_u->info.level = level;
4932 q_u->info.ptr = (info!=NULL)?1:0;
4933 switch (level)
4935 /* info level 3 is supported by Windows 95/98, WinNT and Win2k */
4936 case 3 :
4937 make_spoolss_driver_info_3(mem_ctx, &q_u->info.info_3, info->info3);
4938 break;
4940 /* info level 6 is supported by WinME and Win2k */
4941 case 6:
4942 /* WRITEME!! will add later --jerry */
4943 break;
4945 default:
4946 DEBUG(0,("make_spoolss_q_addprinterdriver: Unknown info level [%d]\n", level));
4947 break;
4950 return True;
4953 BOOL make_spoolss_driver_info_3(
4954 TALLOC_CTX *mem_ctx,
4955 SPOOL_PRINTER_DRIVER_INFO_LEVEL_3 **spool_drv_info,
4956 DRIVER_INFO_3 *info3
4959 uint32 len = 0;
4960 uint16 *ptr = info3->dependentfiles;
4961 BOOL done = False;
4962 BOOL null_char = False;
4963 SPOOL_PRINTER_DRIVER_INFO_LEVEL_3 *inf;
4965 if (!(inf=(SPOOL_PRINTER_DRIVER_INFO_LEVEL_3*)talloc_zero(mem_ctx, sizeof(SPOOL_PRINTER_DRIVER_INFO_LEVEL_3))))
4966 return False;
4968 inf->cversion = info3->version;
4969 inf->name_ptr = (info3->name.buffer!=NULL)?1:0;
4970 inf->environment_ptr = (info3->architecture.buffer!=NULL)?1:0;
4971 inf->driverpath_ptr = (info3->driverpath.buffer!=NULL)?1:0;
4972 inf->datafile_ptr = (info3->datafile.buffer!=NULL)?1:0;
4973 inf->configfile_ptr = (info3->configfile.buffer!=NULL)?1:0;
4974 inf->helpfile_ptr = (info3->helpfile.buffer!=NULL)?1:0;
4975 inf->monitorname_ptr = (info3->monitorname.buffer!=NULL)?1:0;
4976 inf->defaultdatatype_ptr = (info3->defaultdatatype.buffer!=NULL)?1:0;
4978 init_unistr2_from_unistr(&inf->name, &info3->name);
4979 init_unistr2_from_unistr(&inf->environment, &info3->architecture);
4980 init_unistr2_from_unistr(&inf->driverpath, &info3->driverpath);
4981 init_unistr2_from_unistr(&inf->datafile, &info3->datafile);
4982 init_unistr2_from_unistr(&inf->configfile, &info3->configfile);
4983 init_unistr2_from_unistr(&inf->helpfile, &info3->helpfile);
4984 init_unistr2_from_unistr(&inf->monitorname, &info3->monitorname);
4985 init_unistr2_from_unistr(&inf->defaultdatatype, &info3->defaultdatatype);
4987 while (!done)
4989 switch (*ptr)
4991 case 0:
4992 /* the null_char BOOL is used to help locate
4993 two '\0's back to back */
4994 if (null_char)
4995 done = True;
4996 else
4997 null_char = True;
4998 break;
5000 default:
5001 null_char = False;
5003 break;
5005 len++;
5006 ptr++;
5008 inf->dependentfiles_ptr = (info3->dependentfiles != NULL) ? 1 : 0;
5009 inf->dependentfilessize = len;
5010 if(!make_spoolss_buffer5(mem_ctx, &inf->dependentfiles, len, info3->dependentfiles))
5012 SAFE_FREE(inf);
5013 return False;
5016 *spool_drv_info = inf;
5018 return True;
5021 /*******************************************************************
5022 make a BUFFER5 struct from a uint16*
5023 ******************************************************************/
5024 BOOL make_spoolss_buffer5(TALLOC_CTX *mem_ctx, BUFFER5 *buf5, uint32 len, uint16 *src)
5027 buf5->buf_len = len;
5028 if((buf5->buffer=(uint16*)talloc_memdup(mem_ctx, src, sizeof(uint16)*len)) == NULL)
5030 DEBUG(0,("make_spoolss_buffer5: Unable to malloc memory for buffer!\n"));
5031 return False;
5034 return True;
5037 /*******************************************************************
5038 fill in the prs_struct for a ADDPRINTERDRIVER request PDU
5039 ********************************************************************/
5041 BOOL spoolss_io_q_addprinterdriver(char *desc, SPOOL_Q_ADDPRINTERDRIVER *q_u, prs_struct *ps, int depth)
5043 prs_debug(ps, depth, desc, "spoolss_io_q_addprinterdriver");
5044 depth++;
5046 if(!prs_align(ps))
5047 return False;
5049 if(!prs_uint32("server_name_ptr", ps, depth, &q_u->server_name_ptr))
5050 return False;
5051 if(!smb_io_unistr2("server_name", &q_u->server_name, q_u->server_name_ptr, ps, depth))
5052 return False;
5054 if(!prs_align(ps))
5055 return False;
5056 if(!prs_uint32("info_level", ps, depth, &q_u->level))
5057 return False;
5059 if(!spool_io_printer_driver_info_level("", &q_u->info, ps, depth))
5060 return False;
5062 return True;
5065 /*******************************************************************
5066 ********************************************************************/
5068 BOOL spoolss_io_r_addprinterdriver(char *desc, SPOOL_R_ADDPRINTERDRIVER *q_u, prs_struct *ps, int depth)
5070 prs_debug(ps, depth, desc, "spoolss_io_r_addprinterdriver");
5071 depth++;
5073 if(!prs_werror("status", ps, depth, &q_u->status))
5074 return False;
5076 return True;
5079 /*******************************************************************
5080 ********************************************************************/
5082 BOOL uni_2_asc_printer_driver_3(SPOOL_PRINTER_DRIVER_INFO_LEVEL_3 *uni,
5083 NT_PRINTER_DRIVER_INFO_LEVEL_3 **asc)
5085 NT_PRINTER_DRIVER_INFO_LEVEL_3 *d;
5087 DEBUG(7,("uni_2_asc_printer_driver_3: Converting from UNICODE to ASCII\n"));
5089 if (*asc==NULL)
5091 *asc=(NT_PRINTER_DRIVER_INFO_LEVEL_3 *)malloc(sizeof(NT_PRINTER_DRIVER_INFO_LEVEL_3));
5092 if(*asc == NULL)
5093 return False;
5094 ZERO_STRUCTP(*asc);
5097 d=*asc;
5099 d->cversion=uni->cversion;
5101 unistr2_to_ascii(d->name, &uni->name, sizeof(d->name)-1);
5102 unistr2_to_ascii(d->environment, &uni->environment, sizeof(d->environment)-1);
5103 unistr2_to_ascii(d->driverpath, &uni->driverpath, sizeof(d->driverpath)-1);
5104 unistr2_to_ascii(d->datafile, &uni->datafile, sizeof(d->datafile)-1);
5105 unistr2_to_ascii(d->configfile, &uni->configfile, sizeof(d->configfile)-1);
5106 unistr2_to_ascii(d->helpfile, &uni->helpfile, sizeof(d->helpfile)-1);
5107 unistr2_to_ascii(d->monitorname, &uni->monitorname, sizeof(d->monitorname)-1);
5108 unistr2_to_ascii(d->defaultdatatype, &uni->defaultdatatype, sizeof(d->defaultdatatype)-1);
5110 DEBUGADD(8,( "version: %d\n", d->cversion));
5111 DEBUGADD(8,( "name: %s\n", d->name));
5112 DEBUGADD(8,( "environment: %s\n", d->environment));
5113 DEBUGADD(8,( "driverpath: %s\n", d->driverpath));
5114 DEBUGADD(8,( "datafile: %s\n", d->datafile));
5115 DEBUGADD(8,( "configfile: %s\n", d->configfile));
5116 DEBUGADD(8,( "helpfile: %s\n", d->helpfile));
5117 DEBUGADD(8,( "monitorname: %s\n", d->monitorname));
5118 DEBUGADD(8,( "defaultdatatype: %s\n", d->defaultdatatype));
5120 if (uniarray_2_dosarray(&uni->dependentfiles, &d->dependentfiles ))
5121 return True;
5123 SAFE_FREE(*asc);
5124 return False;
5127 /*******************************************************************
5128 ********************************************************************/
5129 BOOL uni_2_asc_printer_driver_6(SPOOL_PRINTER_DRIVER_INFO_LEVEL_6 *uni,
5130 NT_PRINTER_DRIVER_INFO_LEVEL_6 **asc)
5132 NT_PRINTER_DRIVER_INFO_LEVEL_6 *d;
5134 DEBUG(7,("uni_2_asc_printer_driver_6: Converting from UNICODE to ASCII\n"));
5136 if (*asc==NULL)
5138 *asc=(NT_PRINTER_DRIVER_INFO_LEVEL_6 *)malloc(sizeof(NT_PRINTER_DRIVER_INFO_LEVEL_6));
5139 if(*asc == NULL)
5140 return False;
5141 ZERO_STRUCTP(*asc);
5144 d=*asc;
5146 d->version=uni->version;
5148 unistr2_to_ascii(d->name, &uni->name, sizeof(d->name)-1);
5149 unistr2_to_ascii(d->environment, &uni->environment, sizeof(d->environment)-1);
5150 unistr2_to_ascii(d->driverpath, &uni->driverpath, sizeof(d->driverpath)-1);
5151 unistr2_to_ascii(d->datafile, &uni->datafile, sizeof(d->datafile)-1);
5152 unistr2_to_ascii(d->configfile, &uni->configfile, sizeof(d->configfile)-1);
5153 unistr2_to_ascii(d->helpfile, &uni->helpfile, sizeof(d->helpfile)-1);
5154 unistr2_to_ascii(d->monitorname, &uni->monitorname, sizeof(d->monitorname)-1);
5155 unistr2_to_ascii(d->defaultdatatype, &uni->defaultdatatype, sizeof(d->defaultdatatype)-1);
5157 DEBUGADD(8,( "version: %d\n", d->version));
5158 DEBUGADD(8,( "name: %s\n", d->name));
5159 DEBUGADD(8,( "environment: %s\n", d->environment));
5160 DEBUGADD(8,( "driverpath: %s\n", d->driverpath));
5161 DEBUGADD(8,( "datafile: %s\n", d->datafile));
5162 DEBUGADD(8,( "configfile: %s\n", d->configfile));
5163 DEBUGADD(8,( "helpfile: %s\n", d->helpfile));
5164 DEBUGADD(8,( "monitorname: %s\n", d->monitorname));
5165 DEBUGADD(8,( "defaultdatatype: %s\n", d->defaultdatatype));
5167 if (!uniarray_2_dosarray(&uni->dependentfiles, &d->dependentfiles ))
5168 goto error;
5169 if (!uniarray_2_dosarray(&uni->previousnames, &d->previousnames ))
5170 goto error;
5172 return True;
5174 error:
5175 SAFE_FREE(*asc);
5176 return False;
5179 BOOL uni_2_asc_printer_info_2(const SPOOL_PRINTER_INFO_LEVEL_2 *uni,
5180 NT_PRINTER_INFO_LEVEL_2 **asc)
5182 NT_PRINTER_INFO_LEVEL_2 *d;
5183 time_t time_unix;
5185 DEBUG(7,("Converting from UNICODE to ASCII\n"));
5186 time_unix=time(NULL);
5188 if (*asc==NULL) {
5189 DEBUGADD(8,("allocating memory\n"));
5191 *asc=(NT_PRINTER_INFO_LEVEL_2 *)malloc(sizeof(NT_PRINTER_INFO_LEVEL_2));
5192 if(*asc == NULL)
5193 return False;
5194 ZERO_STRUCTP(*asc);
5196 /* we allocate memory iff called from
5197 * addprinter(ex) so we can do one time stuff here.
5199 (*asc)->setuptime=time_unix;
5201 DEBUGADD(8,("start converting\n"));
5203 d=*asc;
5205 d->attributes=uni->attributes;
5206 d->priority=uni->priority;
5207 d->default_priority=uni->default_priority;
5208 d->starttime=uni->starttime;
5209 d->untiltime=uni->untiltime;
5210 d->status=uni->status;
5211 d->cjobs=uni->cjobs;
5213 unistr2_to_ascii(d->servername, &uni->servername, sizeof(d->servername)-1);
5214 unistr2_to_ascii(d->printername, &uni->printername, sizeof(d->printername)-1);
5215 unistr2_to_ascii(d->sharename, &uni->sharename, sizeof(d->sharename)-1);
5216 unistr2_to_ascii(d->portname, &uni->portname, sizeof(d->portname)-1);
5217 unistr2_to_ascii(d->drivername, &uni->drivername, sizeof(d->drivername)-1);
5218 unistr2_to_ascii(d->comment, &uni->comment, sizeof(d->comment)-1);
5219 unistr2_to_ascii(d->location, &uni->location, sizeof(d->location)-1);
5220 unistr2_to_ascii(d->sepfile, &uni->sepfile, sizeof(d->sepfile)-1);
5221 unistr2_to_ascii(d->printprocessor, &uni->printprocessor, sizeof(d->printprocessor)-1);
5222 unistr2_to_ascii(d->datatype, &uni->datatype, sizeof(d->datatype)-1);
5223 unistr2_to_ascii(d->parameters, &uni->parameters, sizeof(d->parameters)-1);
5225 return True;
5228 /*******************************************************************
5229 * init a structure.
5230 ********************************************************************/
5232 BOOL make_spoolss_q_getprinterdriverdir(SPOOL_Q_GETPRINTERDRIVERDIR *q_u,
5233 fstring servername, fstring env_name, uint32 level,
5234 NEW_BUFFER *buffer, uint32 offered)
5236 init_buf_unistr2(&q_u->name, &q_u->name_ptr, servername);
5237 init_buf_unistr2(&q_u->environment, &q_u->environment_ptr, env_name);
5239 q_u->level=level;
5240 q_u->buffer=buffer;
5241 q_u->offered=offered;
5243 return True;
5246 /*******************************************************************
5247 Parse a SPOOL_Q_GETPRINTERDRIVERDIR structure.
5248 ********************************************************************/
5250 BOOL spoolss_io_q_getprinterdriverdir(char *desc, SPOOL_Q_GETPRINTERDRIVERDIR *q_u, prs_struct *ps, int depth)
5252 prs_debug(ps, depth, desc, "spoolss_io_q_getprinterdriverdir");
5253 depth++;
5255 if(!prs_align(ps))
5256 return False;
5257 if(!prs_uint32("name_ptr", ps, depth, &q_u->name_ptr))
5258 return False;
5259 if(!smb_io_unistr2("", &q_u->name, q_u->name_ptr, 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 Parse a SPOOL_R_GETPRINTERDRIVERDIR structure.
5290 ********************************************************************/
5292 BOOL spoolss_io_r_getprinterdriverdir(char *desc, SPOOL_R_GETPRINTERDRIVERDIR *r_u, prs_struct *ps, int depth)
5294 prs_debug(ps, depth, desc, "spoolss_io_r_getprinterdriverdir");
5295 depth++;
5297 if (!prs_align(ps))
5298 return False;
5300 if (!spoolss_io_buffer("", ps, depth, &r_u->buffer))
5301 return False;
5303 if (!prs_align(ps))
5304 return False;
5306 if (!prs_uint32("needed", ps, depth, &r_u->needed))
5307 return False;
5309 if (!prs_werror("status", ps, depth, &r_u->status))
5310 return False;
5312 return True;
5315 /*******************************************************************
5316 ********************************************************************/
5318 BOOL spoolss_io_r_enumprintprocessors(char *desc, SPOOL_R_ENUMPRINTPROCESSORS *r_u, prs_struct *ps, int depth)
5320 prs_debug(ps, depth, desc, "spoolss_io_r_enumprintprocessors");
5321 depth++;
5323 if (!prs_align(ps))
5324 return False;
5326 if (!spoolss_io_buffer("", ps, depth, &r_u->buffer))
5327 return False;
5329 if (!prs_align(ps))
5330 return False;
5332 if (!prs_uint32("needed", ps, depth, &r_u->needed))
5333 return False;
5335 if (!prs_uint32("returned", ps, depth, &r_u->returned))
5336 return False;
5338 if (!prs_werror("status", ps, depth, &r_u->status))
5339 return False;
5341 return True;
5344 /*******************************************************************
5345 ********************************************************************/
5347 BOOL spoolss_io_q_enumprintprocessors(char *desc, SPOOL_Q_ENUMPRINTPROCESSORS *q_u, prs_struct *ps, int depth)
5349 prs_debug(ps, depth, desc, "spoolss_io_q_enumprintprocessors");
5350 depth++;
5352 if (!prs_align(ps))
5353 return False;
5355 if (!prs_uint32("name_ptr", ps, depth, &q_u->name_ptr))
5356 return False;
5357 if (!smb_io_unistr2("name", &q_u->name, True, ps, depth))
5358 return False;
5360 if (!prs_align(ps))
5361 return False;
5363 if (!prs_uint32("", ps, depth, &q_u->environment_ptr))
5364 return False;
5365 if (!smb_io_unistr2("", &q_u->environment, q_u->environment_ptr, ps, depth))
5366 return False;
5368 if (!prs_align(ps))
5369 return False;
5371 if (!prs_uint32("level", ps, depth, &q_u->level))
5372 return False;
5374 if(!spoolss_io_buffer("", ps, depth, &q_u->buffer))
5375 return False;
5377 if (!prs_align(ps))
5378 return False;
5380 if (!prs_uint32("offered", ps, depth, &q_u->offered))
5381 return False;
5383 return True;
5386 /*******************************************************************
5387 ********************************************************************/
5389 BOOL spoolss_io_q_addprintprocessor(char *desc, SPOOL_Q_ADDPRINTPROCESSOR *q_u, prs_struct *ps, int depth)
5391 prs_debug(ps, depth, desc, "spoolss_io_q_addprintprocessor");
5392 depth++;
5394 if (!prs_align(ps))
5395 return False;
5397 if (!prs_uint32("server_ptr", ps, depth, &q_u->server_ptr))
5398 return False;
5399 if (!smb_io_unistr2("server", &q_u->server, q_u->server_ptr, ps, depth))
5400 return False;
5402 if (!prs_align(ps))
5403 return False;
5404 if (!smb_io_unistr2("environment", &q_u->environment, True, ps, depth))
5405 return False;
5407 if (!prs_align(ps))
5408 return False;
5409 if (!smb_io_unistr2("path", &q_u->path, True, ps, depth))
5410 return False;
5412 if (!prs_align(ps))
5413 return False;
5414 if (!smb_io_unistr2("name", &q_u->name, True, ps, depth))
5415 return False;
5417 return True;
5420 /*******************************************************************
5421 ********************************************************************/
5423 BOOL spoolss_io_r_addprintprocessor(char *desc, SPOOL_R_ADDPRINTPROCESSOR *r_u, prs_struct *ps, int depth)
5425 prs_debug(ps, depth, desc, "spoolss_io_r_addprintproicessor");
5426 depth++;
5428 if (!prs_align(ps))
5429 return False;
5431 if (!prs_werror("status", ps, depth, &r_u->status))
5432 return False;
5434 return True;
5437 /*******************************************************************
5438 ********************************************************************/
5440 BOOL spoolss_io_r_enumprintprocdatatypes(char *desc, SPOOL_R_ENUMPRINTPROCDATATYPES *r_u, prs_struct *ps, int depth)
5442 prs_debug(ps, depth, desc, "spoolss_io_r_enumprintprocdatatypes");
5443 depth++;
5445 if (!prs_align(ps))
5446 return False;
5448 if (!spoolss_io_buffer("", ps, depth, &r_u->buffer))
5449 return False;
5451 if (!prs_align(ps))
5452 return False;
5454 if (!prs_uint32("needed", ps, depth, &r_u->needed))
5455 return False;
5457 if (!prs_uint32("returned", ps, depth, &r_u->returned))
5458 return False;
5460 if (!prs_werror("status", ps, depth, &r_u->status))
5461 return False;
5463 return True;
5466 /*******************************************************************
5467 ********************************************************************/
5469 BOOL spoolss_io_q_enumprintprocdatatypes(char *desc, SPOOL_Q_ENUMPRINTPROCDATATYPES *q_u, prs_struct *ps, int depth)
5471 prs_debug(ps, depth, desc, "spoolss_io_q_enumprintprocdatatypes");
5472 depth++;
5474 if (!prs_align(ps))
5475 return False;
5477 if (!prs_uint32("name_ptr", ps, depth, &q_u->name_ptr))
5478 return False;
5479 if (!smb_io_unistr2("name", &q_u->name, True, ps, depth))
5480 return False;
5482 if (!prs_align(ps))
5483 return False;
5485 if (!prs_uint32("processor_ptr", ps, depth, &q_u->processor_ptr))
5486 return False;
5487 if (!smb_io_unistr2("processor", &q_u->processor, q_u->processor_ptr, ps, depth))
5488 return False;
5490 if (!prs_align(ps))
5491 return False;
5493 if (!prs_uint32("level", ps, depth, &q_u->level))
5494 return False;
5496 if(!spoolss_io_buffer("buffer", ps, depth, &q_u->buffer))
5497 return False;
5499 if (!prs_align(ps))
5500 return False;
5502 if (!prs_uint32("offered", ps, depth, &q_u->offered))
5503 return False;
5505 return True;
5508 /*******************************************************************
5509 Parse a SPOOL_Q_ENUMPRINTMONITORS structure.
5510 ********************************************************************/
5512 BOOL spoolss_io_q_enumprintmonitors(char *desc, SPOOL_Q_ENUMPRINTMONITORS *q_u, prs_struct *ps, int depth)
5514 prs_debug(ps, depth, desc, "spoolss_io_q_enumprintmonitors");
5515 depth++;
5517 if (!prs_align(ps))
5518 return False;
5520 if (!prs_uint32("name_ptr", ps, depth, &q_u->name_ptr))
5521 return False;
5522 if (!smb_io_unistr2("name", &q_u->name, True, ps, depth))
5523 return False;
5525 if (!prs_align(ps))
5526 return False;
5528 if (!prs_uint32("level", ps, depth, &q_u->level))
5529 return False;
5531 if(!spoolss_io_buffer("", ps, depth, &q_u->buffer))
5532 return False;
5534 if (!prs_align(ps))
5535 return False;
5537 if (!prs_uint32("offered", ps, depth, &q_u->offered))
5538 return False;
5540 return True;
5543 /*******************************************************************
5544 ********************************************************************/
5546 BOOL spoolss_io_r_enumprintmonitors(char *desc, SPOOL_R_ENUMPRINTMONITORS *r_u, prs_struct *ps, int depth)
5548 prs_debug(ps, depth, desc, "spoolss_io_r_enumprintmonitors");
5549 depth++;
5551 if (!prs_align(ps))
5552 return False;
5554 if (!spoolss_io_buffer("", ps, depth, &r_u->buffer))
5555 return False;
5557 if (!prs_align(ps))
5558 return False;
5560 if (!prs_uint32("needed", ps, depth, &r_u->needed))
5561 return False;
5563 if (!prs_uint32("returned", ps, depth, &r_u->returned))
5564 return False;
5566 if (!prs_werror("status", ps, depth, &r_u->status))
5567 return False;
5569 return True;
5572 /*******************************************************************
5573 ********************************************************************/
5575 BOOL spoolss_io_r_enumprinterdata(char *desc, SPOOL_R_ENUMPRINTERDATA *r_u, prs_struct *ps, int depth)
5577 prs_debug(ps, depth, desc, "spoolss_io_r_enumprinterdata");
5578 depth++;
5580 if(!prs_align(ps))
5581 return False;
5582 if(!prs_uint32("valuesize", ps, depth, &r_u->valuesize))
5583 return False;
5585 if(!prs_uint16uni(False, "value", ps, depth, r_u->value, r_u->valuesize ))
5586 return False;
5588 if(!prs_align(ps))
5589 return False;
5591 if(!prs_uint32("realvaluesize", ps, depth, &r_u->realvaluesize))
5592 return False;
5594 if(!prs_uint32("type", ps, depth, &r_u->type))
5595 return False;
5597 if(!prs_uint32("datasize", ps, depth, &r_u->datasize))
5598 return False;
5599 if(!prs_uint8s(False, "data", ps, depth, r_u->data, r_u->datasize))
5600 return False;
5601 if(!prs_align(ps))
5602 return False;
5604 if(!prs_uint32("realdatasize", ps, depth, &r_u->realdatasize))
5605 return False;
5606 if(!prs_werror("status", ps, depth, &r_u->status))
5607 return False;
5609 return True;
5612 /*******************************************************************
5613 ********************************************************************/
5615 BOOL spoolss_io_q_enumprinterdata(char *desc, SPOOL_Q_ENUMPRINTERDATA *q_u, prs_struct *ps, int depth)
5617 prs_debug(ps, depth, desc, "spoolss_io_q_enumprinterdata");
5618 depth++;
5620 if(!prs_align(ps))
5621 return False;
5622 if(!smb_io_pol_hnd("printer handle",&q_u->handle,ps,depth))
5623 return False;
5624 if(!prs_uint32("index", ps, depth, &q_u->index))
5625 return False;
5626 if(!prs_uint32("valuesize", ps, depth, &q_u->valuesize))
5627 return False;
5628 if(!prs_uint32("datasize", ps, depth, &q_u->datasize))
5629 return False;
5631 return True;
5634 /*******************************************************************
5635 ********************************************************************/
5637 BOOL make_spoolss_q_enumprinterdata(SPOOL_Q_ENUMPRINTERDATA *q_u,
5638 const POLICY_HND *hnd,
5639 uint32 idx, uint32 valuelen, uint32 datalen)
5641 memcpy(&q_u->handle, hnd, sizeof(q_u->handle));
5642 q_u->index=idx;
5643 q_u->valuesize=valuelen;
5644 q_u->datasize=datalen;
5646 return True;
5649 /*******************************************************************
5650 ********************************************************************/
5651 BOOL make_spoolss_q_setprinterdata(SPOOL_Q_SETPRINTERDATA *q_u, TALLOC_CTX *ctx, const POLICY_HND *hnd,
5652 char* value, char* data)
5654 UNISTR2 tmp;
5656 memcpy(&q_u->handle, hnd, sizeof(q_u->handle));
5657 q_u->type = REG_SZ;
5658 init_unistr2(&q_u->value, value, strlen(value)+1);
5660 init_unistr2(&tmp, data, strlen(data)+1);
5661 q_u->max_len = q_u->real_len = tmp.uni_max_len*2;
5662 q_u->data = talloc(ctx, q_u->real_len);
5663 memcpy(q_u->data, tmp.buffer, q_u->real_len);
5665 return True;
5667 /*******************************************************************
5668 ********************************************************************/
5670 BOOL spoolss_io_q_setprinterdata(char *desc, SPOOL_Q_SETPRINTERDATA *q_u, prs_struct *ps, int depth)
5672 prs_debug(ps, depth, desc, "spoolss_io_q_setprinterdata");
5673 depth++;
5675 if(!prs_align(ps))
5676 return False;
5677 if(!smb_io_pol_hnd("printer handle", &q_u->handle, ps, depth))
5678 return False;
5679 if(!smb_io_unistr2("", &q_u->value, True, ps, depth))
5680 return False;
5682 if(!prs_align(ps))
5683 return False;
5685 if(!prs_uint32("type", ps, depth, &q_u->type))
5686 return False;
5688 if(!prs_uint32("max_len", ps, depth, &q_u->max_len))
5689 return False;
5691 switch (q_u->type)
5693 case REG_SZ:
5694 case REG_BINARY:
5695 case REG_DWORD:
5696 case REG_MULTI_SZ:
5697 if (q_u->max_len) {
5698 if (UNMARSHALLING(ps))
5699 q_u->data=(uint8 *)prs_alloc_mem(ps, q_u->max_len * sizeof(uint8));
5700 if(q_u->data == NULL)
5701 return False;
5702 if(!prs_uint8s(False,"data", ps, depth, q_u->data, q_u->max_len))
5703 return False;
5705 if(!prs_align(ps))
5706 return False;
5707 break;
5710 if(!prs_uint32("real_len", ps, depth, &q_u->real_len))
5711 return False;
5713 return True;
5716 /*******************************************************************
5717 ********************************************************************/
5719 BOOL spoolss_io_r_setprinterdata(char *desc, SPOOL_R_SETPRINTERDATA *r_u, prs_struct *ps, int depth)
5721 prs_debug(ps, depth, desc, "spoolss_io_r_setprinterdata");
5722 depth++;
5724 if(!prs_align(ps))
5725 return False;
5726 if(!prs_werror("status", ps, depth, &r_u->status))
5727 return False;
5729 return True;
5732 /*******************************************************************
5733 ********************************************************************/
5734 BOOL spoolss_io_q_resetprinter(char *desc, SPOOL_Q_RESETPRINTER *q_u, prs_struct *ps, int depth)
5736 prs_debug(ps, depth, desc, "spoolss_io_q_resetprinter");
5737 depth++;
5739 if (!prs_align(ps))
5740 return False;
5741 if (!smb_io_pol_hnd("printer handle", &q_u->handle, ps, depth))
5742 return False;
5744 if (!prs_uint32("unknown1", ps, depth, &q_u->unknown1))
5745 return False;
5747 if (!spoolss_io_devmode_cont(desc, &q_u->devmode_ctr, ps, depth))
5748 return False;
5750 return True;
5754 /*******************************************************************
5755 ********************************************************************/
5756 BOOL spoolss_io_r_resetprinter(char *desc, SPOOL_R_RESETPRINTER *r_u, prs_struct *ps, int depth)
5758 prs_debug(ps, depth, desc, "spoolss_io_r_resetprinter");
5759 depth++;
5761 if(!prs_align(ps))
5762 return False;
5763 if(!prs_werror("status", ps, depth, &r_u->status))
5764 return False;
5766 return True;
5769 /*******************************************************************
5770 ********************************************************************/
5771 BOOL convert_specific_param(NT_PRINTER_PARAM **param, const UNISTR2 *value,
5772 uint32 type, const uint8 *data, uint32 len)
5774 DEBUG(5,("converting a specific param struct\n"));
5776 if (*param == NULL)
5778 *param=(NT_PRINTER_PARAM *)malloc(sizeof(NT_PRINTER_PARAM));
5779 if(*param == NULL)
5780 return False;
5781 memset((char *)*param, '\0', sizeof(NT_PRINTER_PARAM));
5782 DEBUGADD(6,("Allocated a new PARAM struct\n"));
5784 unistr2_to_ascii((*param)->value, value, sizeof((*param)->value)-1);
5785 (*param)->type = type;
5787 /* le champ data n'est pas NULL termine */
5788 /* on stocke donc la longueur */
5790 (*param)->data_len=len;
5792 if (len) {
5793 (*param)->data=(uint8 *)malloc(len * sizeof(uint8));
5794 if((*param)->data == NULL)
5795 return False;
5796 memcpy((*param)->data, data, len);
5799 DEBUGADD(6,("\tvalue:[%s], len:[%d]\n",(*param)->value, (*param)->data_len));
5800 dump_data(10, (char *)(*param)->data, (*param)->data_len);
5802 return True;
5805 /*******************************************************************
5806 ********************************************************************/
5808 static BOOL spoolss_io_addform(char *desc, FORM *f, uint32 ptr, prs_struct *ps, int depth)
5810 prs_debug(ps, depth, desc, "spoolss_io_addform");
5811 depth++;
5812 if(!prs_align(ps))
5813 return False;
5815 if (ptr!=0)
5817 if(!prs_uint32("flags", ps, depth, &f->flags))
5818 return False;
5819 if(!prs_uint32("name_ptr", ps, depth, &f->name_ptr))
5820 return False;
5821 if(!prs_uint32("size_x", ps, depth, &f->size_x))
5822 return False;
5823 if(!prs_uint32("size_y", ps, depth, &f->size_y))
5824 return False;
5825 if(!prs_uint32("left", ps, depth, &f->left))
5826 return False;
5827 if(!prs_uint32("top", ps, depth, &f->top))
5828 return False;
5829 if(!prs_uint32("right", ps, depth, &f->right))
5830 return False;
5831 if(!prs_uint32("bottom", ps, depth, &f->bottom))
5832 return False;
5834 if(!smb_io_unistr2("", &f->name, f->name_ptr, ps, depth))
5835 return False;
5838 return True;
5841 /*******************************************************************
5842 ********************************************************************/
5844 BOOL spoolss_io_q_deleteform(char *desc, SPOOL_Q_DELETEFORM *q_u, prs_struct *ps, int depth)
5846 prs_debug(ps, depth, desc, "spoolss_io_q_deleteform");
5847 depth++;
5849 if(!prs_align(ps))
5850 return False;
5851 if(!smb_io_pol_hnd("printer handle", &q_u->handle, ps, depth))
5852 return False;
5853 if(!smb_io_unistr2("form name", &q_u->name, True, ps, depth))
5854 return False;
5856 return True;
5859 /*******************************************************************
5860 ********************************************************************/
5862 BOOL spoolss_io_r_deleteform(char *desc, SPOOL_R_DELETEFORM *r_u, prs_struct *ps, int depth)
5864 prs_debug(ps, depth, desc, "spoolss_io_r_deleteform");
5865 depth++;
5867 if(!prs_align(ps))
5868 return False;
5869 if(!prs_werror("status", ps, depth, &r_u->status))
5870 return False;
5872 return True;
5875 /*******************************************************************
5876 ********************************************************************/
5878 BOOL spoolss_io_q_addform(char *desc, SPOOL_Q_ADDFORM *q_u, prs_struct *ps, int depth)
5880 uint32 useless_ptr=0;
5881 prs_debug(ps, depth, desc, "spoolss_io_q_addform");
5882 depth++;
5884 if(!prs_align(ps))
5885 return False;
5886 if(!smb_io_pol_hnd("printer handle", &q_u->handle, ps, depth))
5887 return False;
5888 if(!prs_uint32("level", ps, depth, &q_u->level))
5889 return False;
5890 if(!prs_uint32("level2", ps, depth, &q_u->level2))
5891 return False;
5893 if (q_u->level==1)
5895 if(!prs_uint32("useless_ptr", ps, depth, &useless_ptr))
5896 return False;
5897 if(!spoolss_io_addform("", &q_u->form, useless_ptr, ps, depth))
5898 return False;
5901 return True;
5904 /*******************************************************************
5905 ********************************************************************/
5907 BOOL spoolss_io_r_addform(char *desc, SPOOL_R_ADDFORM *r_u, prs_struct *ps, int depth)
5909 prs_debug(ps, depth, desc, "spoolss_io_r_addform");
5910 depth++;
5912 if(!prs_align(ps))
5913 return False;
5914 if(!prs_werror("status", ps, depth, &r_u->status))
5915 return False;
5917 return True;
5920 /*******************************************************************
5921 ********************************************************************/
5923 BOOL spoolss_io_q_setform(char *desc, SPOOL_Q_SETFORM *q_u, prs_struct *ps, int depth)
5925 uint32 useless_ptr=0;
5926 prs_debug(ps, depth, desc, "spoolss_io_q_setform");
5927 depth++;
5929 if(!prs_align(ps))
5930 return False;
5931 if(!smb_io_pol_hnd("printer handle", &q_u->handle, ps, depth))
5932 return False;
5933 if(!smb_io_unistr2("", &q_u->name, True, ps, depth))
5934 return False;
5936 if(!prs_align(ps))
5937 return False;
5939 if(!prs_uint32("level", ps, depth, &q_u->level))
5940 return False;
5941 if(!prs_uint32("level2", ps, depth, &q_u->level2))
5942 return False;
5944 if (q_u->level==1)
5946 if(!prs_uint32("useless_ptr", ps, depth, &useless_ptr))
5947 return False;
5948 if(!spoolss_io_addform("", &q_u->form, useless_ptr, ps, depth))
5949 return False;
5952 return True;
5955 /*******************************************************************
5956 ********************************************************************/
5958 BOOL spoolss_io_r_setform(char *desc, SPOOL_R_SETFORM *r_u, prs_struct *ps, int depth)
5960 prs_debug(ps, depth, desc, "spoolss_io_r_setform");
5961 depth++;
5963 if(!prs_align(ps))
5964 return False;
5965 if(!prs_werror("status", ps, depth, &r_u->status))
5966 return False;
5968 return True;
5971 /*******************************************************************
5972 Parse a SPOOL_R_GETJOB structure.
5973 ********************************************************************/
5975 BOOL spoolss_io_r_getjob(char *desc, SPOOL_R_GETJOB *r_u, prs_struct *ps, int depth)
5977 prs_debug(ps, depth, desc, "spoolss_io_r_getjob");
5978 depth++;
5980 if (!prs_align(ps))
5981 return False;
5983 if (!spoolss_io_buffer("", ps, depth, &r_u->buffer))
5984 return False;
5986 if (!prs_align(ps))
5987 return False;
5989 if (!prs_uint32("needed", ps, depth, &r_u->needed))
5990 return False;
5992 if (!prs_werror("status", ps, depth, &r_u->status))
5993 return False;
5995 return True;
5998 /*******************************************************************
5999 Parse a SPOOL_Q_GETJOB structure.
6000 ********************************************************************/
6002 BOOL spoolss_io_q_getjob(char *desc, SPOOL_Q_GETJOB *q_u, prs_struct *ps, int depth)
6004 prs_debug(ps, depth, desc, "");
6005 depth++;
6007 if(!prs_align(ps))
6008 return False;
6010 if(!smb_io_pol_hnd("printer handle",&q_u->handle,ps,depth))
6011 return False;
6012 if(!prs_uint32("jobid", ps, depth, &q_u->jobid))
6013 return False;
6014 if(!prs_uint32("level", ps, depth, &q_u->level))
6015 return False;
6017 if(!spoolss_io_buffer("", ps, depth, &q_u->buffer))
6018 return False;
6020 if(!prs_align(ps))
6021 return False;
6023 if(!prs_uint32("offered", ps, depth, &q_u->offered))
6024 return False;
6026 return True;
6029 void free_devmode(DEVICEMODE *devmode)
6031 if (devmode!=NULL) {
6032 SAFE_FREE(devmode->private);
6033 SAFE_FREE(devmode);
6037 void free_printer_info_1(PRINTER_INFO_1 *printer)
6039 SAFE_FREE(printer);
6042 void free_printer_info_2(PRINTER_INFO_2 *printer)
6044 if (printer!=NULL) {
6045 free_devmode(printer->devmode);
6046 printer->devmode = NULL;
6047 SAFE_FREE(printer);
6051 void free_printer_info_3(PRINTER_INFO_3 *printer)
6053 SAFE_FREE(printer);
6056 void free_printer_info_4(PRINTER_INFO_4 *printer)
6058 SAFE_FREE(printer);
6061 void free_printer_info_5(PRINTER_INFO_5 *printer)
6063 SAFE_FREE(printer);
6066 void free_job_info_2(JOB_INFO_2 *job)
6068 if (job!=NULL)
6069 free_devmode(job->devmode);
6072 /*******************************************************************
6073 * init a structure.
6074 ********************************************************************/
6076 BOOL make_spoolss_q_replyopenprinter(SPOOL_Q_REPLYOPENPRINTER *q_u,
6077 const fstring string, uint32 printer, uint32 type)
6079 if (q_u == NULL)
6080 return False;
6082 init_unistr2(&q_u->string, string, strlen(string)+1);
6084 q_u->printer=printer;
6085 q_u->type=type;
6087 q_u->unknown0=0x0;
6088 q_u->unknown1=0x0;
6090 return True;
6093 /*******************************************************************
6094 Parse a SPOOL_Q_REPLYOPENPRINTER structure.
6095 ********************************************************************/
6097 BOOL spoolss_io_q_replyopenprinter(char *desc, SPOOL_Q_REPLYOPENPRINTER *q_u, prs_struct *ps, int depth)
6099 prs_debug(ps, depth, desc, "spoolss_io_q_replyopenprinter");
6100 depth++;
6102 if(!prs_align(ps))
6103 return False;
6105 if(!smb_io_unistr2("", &q_u->string, True, ps, depth))
6106 return False;
6108 if(!prs_align(ps))
6109 return False;
6111 if(!prs_uint32("printer", ps, depth, &q_u->printer))
6112 return False;
6113 if(!prs_uint32("type", ps, depth, &q_u->type))
6114 return False;
6116 if(!prs_uint32("unknown0", ps, depth, &q_u->unknown0))
6117 return False;
6118 if(!prs_uint32("unknown1", ps, depth, &q_u->unknown1))
6119 return False;
6121 return True;
6124 /*******************************************************************
6125 Parse a SPOOL_R_REPLYOPENPRINTER structure.
6126 ********************************************************************/
6128 BOOL spoolss_io_r_replyopenprinter(char *desc, SPOOL_R_REPLYOPENPRINTER *r_u, prs_struct *ps, int depth)
6130 prs_debug(ps, depth, desc, "spoolss_io_r_replyopenprinter");
6131 depth++;
6133 if (!prs_align(ps))
6134 return False;
6136 if(!smb_io_pol_hnd("printer handle",&r_u->handle,ps,depth))
6137 return False;
6139 if (!prs_werror("status", ps, depth, &r_u->status))
6140 return False;
6142 return True;
6145 /*******************************************************************
6146 * init a structure.
6147 ********************************************************************/
6148 BOOL make_spoolss_q_routerreplyprinter(SPOOL_Q_ROUTERREPLYPRINTER *q_u, POLICY_HND *hnd,
6149 uint32 condition, uint32 change_id)
6152 memcpy(&q_u->handle, hnd, sizeof(q_u->handle));
6154 q_u->condition = condition;
6155 q_u->change_id = change_id;
6157 /* magic values */
6158 q_u->unknown1 = 0x1;
6159 memset(q_u->unknown2, 0x0, 5);
6160 q_u->unknown2[0] = 0x1;
6162 return True;
6165 /*******************************************************************
6166 Parse a SPOOL_Q_ROUTERREPLYPRINTER structure.
6167 ********************************************************************/
6168 BOOL spoolss_io_q_routerreplyprinter (char *desc, SPOOL_Q_ROUTERREPLYPRINTER *q_u, prs_struct *ps, int depth)
6171 prs_debug(ps, depth, desc, "spoolss_io_q_routerreplyprinter");
6172 depth++;
6174 if (!prs_align(ps))
6175 return False;
6177 if(!smb_io_pol_hnd("printer handle",&q_u->handle,ps,depth))
6178 return False;
6180 if (!prs_uint32("condition", ps, depth, &q_u->condition))
6181 return False;
6183 if (!prs_uint32("unknown1", ps, depth, &q_u->unknown1))
6184 return False;
6186 if (!prs_uint32("change_id", ps, depth, &q_u->change_id))
6187 return False;
6189 if (!prs_uint8s(False, "private", ps, depth, q_u->unknown2, 5))
6190 return False;
6192 return True;
6195 /*******************************************************************
6196 Parse a SPOOL_R_ROUTERREPLYPRINTER structure.
6197 ********************************************************************/
6198 BOOL spoolss_io_r_routerreplyprinter (char *desc, SPOOL_R_ROUTERREPLYPRINTER *r_u, prs_struct *ps, int depth)
6200 prs_debug(ps, depth, desc, "spoolss_io_r_routerreplyprinter");
6201 depth++;
6203 if (!prs_align(ps))
6204 return False;
6206 if (!prs_werror("status", ps, depth, &r_u->status))
6207 return False;
6209 return True;
6212 /*******************************************************************
6213 * init a structure.
6214 ********************************************************************/
6216 BOOL make_spoolss_q_reply_closeprinter(SPOOL_Q_REPLYCLOSEPRINTER *q_u, POLICY_HND *hnd)
6218 if (q_u == NULL)
6219 return False;
6221 memcpy(&q_u->handle, hnd, sizeof(q_u->handle));
6223 return True;
6226 /*******************************************************************
6227 Parse a SPOOL_Q_REPLYCLOSEPRINTER structure.
6228 ********************************************************************/
6230 BOOL spoolss_io_q_replycloseprinter(char *desc, SPOOL_Q_REPLYCLOSEPRINTER *q_u, prs_struct *ps, int depth)
6232 prs_debug(ps, depth, desc, "spoolss_io_q_replycloseprinter");
6233 depth++;
6235 if(!prs_align(ps))
6236 return False;
6238 if(!smb_io_pol_hnd("printer handle",&q_u->handle,ps,depth))
6239 return False;
6241 return True;
6244 /*******************************************************************
6245 Parse a SPOOL_R_REPLYCLOSEPRINTER structure.
6246 ********************************************************************/
6248 BOOL spoolss_io_r_replycloseprinter(char *desc, SPOOL_R_REPLYCLOSEPRINTER *r_u, prs_struct *ps, int depth)
6250 prs_debug(ps, depth, desc, "spoolss_io_r_replycloseprinter");
6251 depth++;
6253 if (!prs_align(ps))
6254 return False;
6256 if(!smb_io_pol_hnd("printer handle",&r_u->handle,ps,depth))
6257 return False;
6259 if (!prs_werror("status", ps, depth, &r_u->status))
6260 return False;
6262 return True;
6265 #if 0 /* JERRY - not currently used but could be :-) */
6267 /*******************************************************************
6268 Deep copy a SPOOL_NOTIFY_INFO_DATA structure
6269 ******************************************************************/
6270 static BOOL copy_spool_notify_info_data(SPOOL_NOTIFY_INFO_DATA *dst,
6271 SPOOL_NOTIFY_INFO_DATA *src, int n)
6273 int i;
6275 memcpy(dst, src, sizeof(SPOOL_NOTIFY_INFO_DATA)*n);
6277 for (i=0; i<n; i++) {
6278 int len;
6279 uint16 *s = NULL;
6281 if (src->size != POINTER)
6282 continue;
6283 len = src->notify_data.data.length;
6284 s = malloc(sizeof(uint16)*len);
6285 if (s == NULL) {
6286 DEBUG(0,("copy_spool_notify_info_data: malloc() failed!\n"));
6287 return False;
6290 memcpy(s, src->notify_data.data.string, len*2);
6291 dst->notify_data.data.string = s;
6294 return True;
6297 /*******************************************************************
6298 Deep copy a SPOOL_NOTIFY_INFO structure
6299 ******************************************************************/
6300 static BOOL copy_spool_notify_info(SPOOL_NOTIFY_INFO *dst, SPOOL_NOTIFY_INFO *src)
6302 if (!dst) {
6303 DEBUG(0,("copy_spool_notify_info: NULL destination pointer!\n"));
6304 return False;
6307 dst->version = src->version;
6308 dst->flags = src->flags;
6309 dst->count = src->count;
6311 if (dst->count)
6313 dst->data = malloc(dst->count * sizeof(SPOOL_NOTIFY_INFO_DATA));
6315 DEBUG(10,("copy_spool_notify_info: allocating space for [%d] PRINTER_NOTIFY_INFO_DATA entries\n",
6316 dst->count));
6318 if (dst->data == NULL) {
6319 DEBUG(0,("copy_spool_notify_info: malloc() failed for [%d] entries!\n",
6320 dst->count));
6321 return False;
6324 return (copy_spool_notify_info_data(dst->data, src->data, src->count));
6327 return True;
6329 #endif /* JERRY */
6331 /*******************************************************************
6332 * init a structure.
6333 ********************************************************************/
6335 BOOL make_spoolss_q_reply_rrpcn(SPOOL_Q_REPLY_RRPCN *q_u, POLICY_HND *hnd,
6336 uint32 change_low, uint32 change_high,
6337 SPOOL_NOTIFY_INFO *info)
6339 if (q_u == NULL)
6340 return False;
6342 memcpy(&q_u->handle, hnd, sizeof(q_u->handle));
6344 q_u->change_low=change_low;
6345 q_u->change_high=change_high;
6347 q_u->unknown0=0x0;
6348 q_u->unknown1=0x0;
6350 q_u->info_ptr=0xaddee11e;
6352 q_u->info.version=2;
6354 if (info->count) {
6355 DEBUG(10,("make_spoolss_q_reply_rrpcn: [%d] PRINTER_NOTIFY_INFO_DATA\n",
6356 info->count));
6357 q_u->info.version = info->version;
6358 q_u->info.flags = info->flags;
6359 q_u->info.count = info->count;
6360 /* pointer field - be careful! */
6361 q_u->info.data = info->data;
6363 else {
6364 q_u->info.flags=PRINTER_NOTIFY_INFO_DISCARDED;
6365 q_u->info.count=0;
6368 return True;
6371 /*******************************************************************
6372 Parse a SPOOL_Q_REPLY_RRPCN structure.
6373 ********************************************************************/
6375 BOOL spoolss_io_q_reply_rrpcn(char *desc, SPOOL_Q_REPLY_RRPCN *q_u, prs_struct *ps, int depth)
6377 prs_debug(ps, depth, desc, "spoolss_io_q_reply_rrpcn");
6378 depth++;
6380 if(!prs_align(ps))
6381 return False;
6383 if(!smb_io_pol_hnd("printer handle",&q_u->handle,ps,depth))
6384 return False;
6386 if (!prs_uint32("change_low", ps, depth, &q_u->change_low))
6387 return False;
6389 if (!prs_uint32("change_high", ps, depth, &q_u->change_high))
6390 return False;
6392 if (!prs_uint32("unknown0", ps, depth, &q_u->unknown0))
6393 return False;
6395 if (!prs_uint32("unknown1", ps, depth, &q_u->unknown1))
6396 return False;
6398 if (!prs_uint32("info_ptr", ps, depth, &q_u->info_ptr))
6399 return False;
6401 if(q_u->info_ptr!=0)
6402 if(!smb_io_notify_info(desc, &q_u->info, ps, depth))
6403 return False;
6405 return True;
6408 /*******************************************************************
6409 Parse a SPOOL_R_REPLY_RRPCN structure.
6410 ********************************************************************/
6412 BOOL spoolss_io_r_reply_rrpcn(char *desc, SPOOL_R_REPLY_RRPCN *r_u, prs_struct *ps, int depth)
6414 prs_debug(ps, depth, desc, "spoolss_io_r_reply_rrpcn");
6415 depth++;
6417 if (!prs_align(ps))
6418 return False;
6420 if (!prs_uint32("unknown0", ps, depth, &r_u->unknown0))
6421 return False;
6423 if (!prs_werror("status", ps, depth, &r_u->status))
6424 return False;
6426 return True;
6429 /*******************************************************************
6430 * read a structure.
6431 * called from spoolss_q_getprinterdataex (srv_spoolss.c)
6432 ********************************************************************/
6434 BOOL spoolss_io_q_getprinterdataex(char *desc, SPOOL_Q_GETPRINTERDATAEX *q_u, prs_struct *ps, int depth)
6436 if (q_u == NULL)
6437 return False;
6439 prs_debug(ps, depth, desc, "spoolss_io_q_getprinterdataex");
6440 depth++;
6442 if (!prs_align(ps))
6443 return False;
6444 if (!smb_io_pol_hnd("printer handle",&q_u->handle,ps,depth))
6445 return False;
6446 if (!prs_align(ps))
6447 return False;
6448 if (!smb_io_unistr2("keyname", &q_u->keyname,True,ps,depth))
6449 return False;
6450 if (!prs_align(ps))
6451 return False;
6452 if (!smb_io_unistr2("valuename", &q_u->valuename,True,ps,depth))
6453 return False;
6454 if (!prs_align(ps))
6455 return False;
6456 if (!prs_uint32("size", ps, depth, &q_u->size))
6457 return False;
6459 return True;
6462 /*******************************************************************
6463 * write a structure.
6464 * called from spoolss_r_getprinterdataex (srv_spoolss.c)
6465 ********************************************************************/
6467 BOOL spoolss_io_r_getprinterdataex(char *desc, SPOOL_R_GETPRINTERDATAEX *r_u, prs_struct *ps, int depth)
6469 if (r_u == NULL)
6470 return False;
6472 prs_debug(ps, depth, desc, "spoolss_io_r_getprinterdataex");
6473 depth++;
6475 if (!prs_align(ps))
6476 return False;
6477 if (!prs_uint32("type", ps, depth, &r_u->type))
6478 return False;
6479 if (!prs_uint32("size", ps, depth, &r_u->size))
6480 return False;
6482 if (!prs_uint8s(False,"data", ps, depth, r_u->data, r_u->size))
6483 return False;
6485 if (!prs_align(ps))
6486 return False;
6488 if (!prs_uint32("needed", ps, depth, &r_u->needed))
6489 return False;
6490 if (!prs_werror("status", ps, depth, &r_u->status))
6491 return False;
6493 return True;
6496 /*******************************************************************
6497 * read a structure.
6498 ********************************************************************/
6500 BOOL spoolss_io_q_setprinterdataex(char *desc, SPOOL_Q_SETPRINTERDATAEX *q_u, prs_struct *ps, int depth)
6502 prs_debug(ps, depth, desc, "spoolss_io_q_setprinterdataex");
6503 depth++;
6505 if(!prs_align(ps))
6506 return False;
6507 if(!smb_io_pol_hnd("printer handle", &q_u->handle, ps, depth))
6508 return False;
6509 if(!smb_io_unistr2("", &q_u->key, True, ps, depth))
6510 return False;
6512 if(!prs_align(ps))
6513 return False;
6515 if(!smb_io_unistr2("", &q_u->value, True, ps, depth))
6516 return False;
6518 if(!prs_align(ps))
6519 return False;
6521 if(!prs_uint32("type", ps, depth, &q_u->type))
6522 return False;
6524 if(!prs_uint32("max_len", ps, depth, &q_u->max_len))
6525 return False;
6527 switch (q_u->type)
6529 case 0x1:
6530 case 0x3:
6531 case 0x4:
6532 case 0x7:
6533 if (q_u->max_len) {
6534 if (UNMARSHALLING(ps))
6535 q_u->data=(uint8 *)prs_alloc_mem(ps, q_u->max_len * sizeof(uint8));
6536 if(q_u->data == NULL)
6537 return False;
6538 if(!prs_uint8s(False,"data", ps, depth, q_u->data, q_u->max_len))
6539 return False;
6541 if(!prs_align(ps))
6542 return False;
6543 break;
6546 if(!prs_uint32("real_len", ps, depth, &q_u->real_len))
6547 return False;
6549 return True;
6552 /*******************************************************************
6553 * write a structure.
6554 ********************************************************************/
6556 BOOL spoolss_io_r_setprinterdataex(char *desc, SPOOL_R_SETPRINTERDATAEX *r_u, prs_struct *ps, int depth)
6558 prs_debug(ps, depth, desc, "spoolss_io_r_setprinterdataex");
6559 depth++;
6561 if(!prs_align(ps))
6562 return False;
6563 if(!prs_werror("status", ps, depth, &r_u->status))
6564 return False;
6566 return True;
6570 /*******************************************************************
6571 * read a structure.
6572 ********************************************************************/
6574 BOOL spoolss_io_q_enumprinterkey(char *desc, SPOOL_Q_ENUMPRINTERKEY *q_u, prs_struct *ps, int depth)
6576 prs_debug(ps, depth, desc, "spoolss_io_q_enumprinterkey");
6577 depth++;
6579 if(!prs_align(ps))
6580 return False;
6581 if(!smb_io_pol_hnd("printer handle", &q_u->handle, ps, depth))
6582 return False;
6584 if(!smb_io_unistr2("", &q_u->key, True, ps, depth))
6585 return False;
6587 if(!prs_align(ps))
6588 return False;
6590 if(!prs_uint32("size", ps, depth, &q_u->size))
6591 return False;
6593 return True;
6596 /*******************************************************************
6597 * write a structure.
6598 ********************************************************************/
6600 BOOL spoolss_io_r_enumprinterkey(char *desc, SPOOL_R_ENUMPRINTERKEY *r_u, prs_struct *ps, int depth)
6602 prs_debug(ps, depth, desc, "spoolss_io_r_enumprinterkey");
6603 depth++;
6605 if(!prs_align(ps))
6606 return False;
6608 if (!smb_io_buffer5("", &r_u->keys, ps, depth))
6609 return False;
6611 if(!prs_align(ps))
6612 return False;
6614 if(!prs_uint32("needed", ps, depth, &r_u->needed))
6615 return False;
6617 if(!prs_werror("status", ps, depth, &r_u->status))
6618 return False;
6620 return True;
6624 /*******************************************************************
6625 * read a structure.
6626 ********************************************************************/
6628 BOOL spoolss_io_q_enumprinterdataex(char *desc, SPOOL_Q_ENUMPRINTERDATAEX *q_u, prs_struct *ps, int depth)
6630 prs_debug(ps, depth, desc, "spoolss_io_q_enumprinterdataex");
6631 depth++;
6633 if(!prs_align(ps))
6634 return False;
6635 if(!smb_io_pol_hnd("printer handle", &q_u->handle, ps, depth))
6636 return False;
6638 if(!smb_io_unistr2("", &q_u->key, True, ps, depth))
6639 return False;
6641 if(!prs_align(ps))
6642 return False;
6644 if(!prs_uint32("size", ps, depth, &q_u->size))
6645 return False;
6647 return True;
6650 /*******************************************************************
6651 ********************************************************************/
6652 static BOOL spoolss_io_printer_enum_values_ctr(char *desc, prs_struct *ps,
6653 PRINTER_ENUM_VALUES_CTR *ctr, int depth)
6655 int i;
6656 uint32 valuename_offset,
6657 data_offset,
6658 current_offset;
6659 const uint32 basic_unit = 20; /* size of static portion of enum_values */
6661 prs_debug(ps, depth, desc, "spoolss_io_printer_enum_values_ctr");
6662 depth++;
6664 if (!prs_uint32("size", ps, depth, &ctr->size))
6665 return False;
6667 /* offset data begins at 20 bytes per structure * size_of_array.
6668 Don't forget the uint32 at the beginning */
6670 current_offset = basic_unit * ctr->size_of_array;
6672 /* first loop to write basic enum_value information */
6674 for (i=0; i<ctr->size_of_array; i++)
6676 valuename_offset = current_offset;
6677 if (!prs_uint32("valuename_offset", ps, depth, &valuename_offset))
6678 return False;
6680 if (!prs_uint32("value_len", ps, depth, &ctr->values[i].value_len))
6681 return False;
6683 if (!prs_uint32("type", ps, depth, &ctr->values[i].type))
6684 return False;
6686 data_offset = ctr->values[i].value_len + valuename_offset;
6687 if (!prs_uint32("data_offset", ps, depth, &data_offset))
6688 return False;
6690 if (!prs_uint32("data_len", ps, depth, &ctr->values[i].data_len))
6691 return False;
6693 current_offset = data_offset + ctr->values[i].data_len - basic_unit;
6696 /* loop #2 for writing the dynamically size objects
6697 while viewing conversations between Win2k -> Win2k,
6698 4-byte alignment does not seem to matter here --jerry */
6700 for (i=0; i<ctr->size_of_array; i++)
6703 if (!prs_unistr("valuename", ps, depth, &ctr->values[i].valuename))
6704 return False;
6706 if (!prs_uint8s(False, "data", ps, depth, ctr->values[i].data, ctr->values[i].data_len))
6707 return False;
6712 return True;
6716 /*******************************************************************
6717 * write a structure.
6718 ********************************************************************/
6720 BOOL spoolss_io_r_enumprinterdataex(char *desc, SPOOL_R_ENUMPRINTERDATAEX *r_u, prs_struct *ps, int depth)
6722 prs_debug(ps, depth, desc, "spoolss_io_r_enumprinterdataex");
6723 depth++;
6725 if(!prs_align(ps))
6726 return False;
6728 if (!spoolss_io_printer_enum_values_ctr("", ps, &r_u->ctr, depth ))
6729 return False;
6731 if(!prs_align(ps))
6732 return False;
6734 if(!prs_uint32("needed", ps, depth, &r_u->needed))
6735 return False;
6737 if(!prs_uint32("returned", ps, depth, &r_u->returned))
6738 return False;
6740 if(!prs_werror("status", ps, depth, &r_u->status))
6741 return False;
6743 return True;
6747 /*******************************************************************
6748 * write a structure.
6749 ********************************************************************/
6752 uint32 GetPrintProcessorDirectory(
6753 [in] unistr2 *name,
6754 [in] unistr2 *environment,
6755 [in] uint32 level,
6756 [in,out] NEW_BUFFER buffer,
6757 [in] uint32 offered,
6758 [out] uint32 needed,
6759 [out] uint32 returned
6764 BOOL make_spoolss_q_getprintprocessordirectory(SPOOL_Q_GETPRINTPROCESSORDIRECTORY *q_u, const char *name, char *environment, int level, NEW_BUFFER *buffer, uint32 offered)
6766 DEBUG(5,("make_spoolss_q_getprintprocessordirectory\n"));
6768 init_unistr2(&q_u->name, name, strlen(name)+1);
6769 init_unistr2(&q_u->environment, environment, strlen(environment)+1);
6771 q_u->level = level;
6773 q_u->buffer = buffer;
6774 q_u->offered = offered;
6776 return True;
6779 BOOL spoolss_io_q_getprintprocessordirectory(char *desc, SPOOL_Q_GETPRINTPROCESSORDIRECTORY *q_u, prs_struct *ps, int depth)
6781 uint32 ptr;
6783 prs_debug(ps, depth, desc, "spoolss_io_q_getprintprocessordirectory");
6784 depth++;
6786 if(!prs_align(ps))
6787 return False;
6789 if (!prs_uint32("ptr", ps, depth, &ptr))
6790 return False;
6792 if (ptr) {
6793 if(!smb_io_unistr2("name", &q_u->name, True, ps, depth))
6794 return False;
6797 if (!prs_align(ps))
6798 return False;
6800 if (!prs_uint32("ptr", ps, depth, &ptr))
6801 return False;
6803 if (ptr) {
6804 if(!smb_io_unistr2("environment", &q_u->environment, True,
6805 ps, depth))
6806 return False;
6809 if (!prs_align(ps))
6810 return False;
6812 if(!prs_uint32("level", ps, depth, &q_u->level))
6813 return False;
6815 if(!spoolss_io_buffer("", ps, depth, &q_u->buffer))
6816 return False;
6818 if(!prs_align(ps))
6819 return False;
6821 if(!prs_uint32("offered", ps, depth, &q_u->offered))
6822 return False;
6824 return True;
6827 /*******************************************************************
6828 * write a structure.
6829 ********************************************************************/
6831 BOOL spoolss_io_r_getprintprocessordirectory(char *desc, SPOOL_R_GETPRINTPROCESSORDIRECTORY *r_u, prs_struct *ps, int depth)
6833 prs_debug(ps, depth, desc, "spoolss_io_r_getprintprocessordirectory");
6834 depth++;
6836 if(!prs_align(ps))
6837 return False;
6839 if(!spoolss_io_buffer("", ps, depth, &r_u->buffer))
6840 return False;
6842 if(!prs_align(ps))
6843 return False;
6845 if(!prs_uint32("needed", ps, depth, &r_u->needed))
6846 return False;
6848 if(!prs_werror("status", ps, depth, &r_u->status))
6849 return False;
6851 return True;
6854 BOOL smb_io_printprocessordirectory_1(char *desc, NEW_BUFFER *buffer, PRINTPROCESSOR_DIRECTORY_1 *info, int depth)
6856 prs_struct *ps=&buffer->prs;
6858 prs_debug(ps, depth, desc, "smb_io_printprocessordirectory_1");
6859 depth++;
6861 buffer->struct_start=prs_offset(ps);
6863 if (!smb_io_unistr(desc, &info->name, ps, depth))
6864 return False;
6866 return True;