merge from SAMBA_2_2
[Samba.git] / source / rpc_parse / parse_spoolss.c
blobe9f0ca858a9791b4866343f02f24c3159801476c
1 /*
2 * Unix SMB/CIFS implementation.
3 * RPC Pipe client / server routines
4 * Copyright (C) Andrew Tridgell 1992-2000,
5 * Copyright (C) Luke Kenneth Casson Leighton 1996-2000,
6 * Copyright (C) Jean François Micouleau 1998-2000,
7 * Copyright (C) Gerald Carter 2000-2002
8 * Copyright (C) Tim Potter 2001.
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation; either version 2 of the License, or
13 * (at your option) any later version.
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
20 * You should have received a copy of the GNU General Public License
21 * along with this program; if not, write to the Free Software
22 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
25 #include "includes.h"
27 /*******************************************************************
28 return the length of a UNISTR string.
29 ********************************************************************/
31 static uint32 str_len_uni(UNISTR *source)
33 uint32 i=0;
35 if (!source->buffer)
36 return 0;
38 while (source->buffer[i])
39 i++;
41 return i;
44 /*******************************************************************
45 This should be moved in a more generic lib.
46 ********************************************************************/
48 static BOOL spoolss_io_system_time(char *desc, prs_struct *ps, int depth, SYSTEMTIME *systime)
50 if(!prs_uint16("year", ps, depth, &systime->year))
51 return False;
52 if(!prs_uint16("month", ps, depth, &systime->month))
53 return False;
54 if(!prs_uint16("dayofweek", ps, depth, &systime->dayofweek))
55 return False;
56 if(!prs_uint16("day", ps, depth, &systime->day))
57 return False;
58 if(!prs_uint16("hour", ps, depth, &systime->hour))
59 return False;
60 if(!prs_uint16("minute", ps, depth, &systime->minute))
61 return False;
62 if(!prs_uint16("second", ps, depth, &systime->second))
63 return False;
64 if(!prs_uint16("milliseconds", ps, depth, &systime->milliseconds))
65 return False;
67 return True;
70 /*******************************************************************
71 ********************************************************************/
73 BOOL make_systemtime(SYSTEMTIME *systime, struct tm *unixtime)
75 systime->year=unixtime->tm_year+1900;
76 systime->month=unixtime->tm_mon+1;
77 systime->dayofweek=unixtime->tm_wday;
78 systime->day=unixtime->tm_mday;
79 systime->hour=unixtime->tm_hour;
80 systime->minute=unixtime->tm_min;
81 systime->second=unixtime->tm_sec;
82 systime->milliseconds=0;
84 return True;
87 /*******************************************************************
88 reads or writes an DOC_INFO structure.
89 ********************************************************************/
91 static BOOL smb_io_doc_info_1(char *desc, DOC_INFO_1 *info_1, prs_struct *ps, int depth)
93 if (info_1 == NULL) return False;
95 prs_debug(ps, depth, desc, "smb_io_doc_info_1");
96 depth++;
98 if(!prs_align(ps))
99 return False;
101 if(!prs_uint32("p_docname", ps, depth, &info_1->p_docname))
102 return False;
103 if(!prs_uint32("p_outputfile", ps, depth, &info_1->p_outputfile))
104 return False;
105 if(!prs_uint32("p_datatype", ps, depth, &info_1->p_datatype))
106 return False;
108 if(!smb_io_unistr2("", &info_1->docname, info_1->p_docname, ps, depth))
109 return False;
110 if(!smb_io_unistr2("", &info_1->outputfile, info_1->p_outputfile, ps, depth))
111 return False;
112 if(!smb_io_unistr2("", &info_1->datatype, info_1->p_datatype, ps, depth))
113 return False;
115 return True;
118 /*******************************************************************
119 reads or writes an DOC_INFO structure.
120 ********************************************************************/
122 static BOOL smb_io_doc_info(char *desc, DOC_INFO *info, prs_struct *ps, int depth)
124 uint32 useless_ptr=0;
126 if (info == NULL) return False;
128 prs_debug(ps, depth, desc, "smb_io_doc_info");
129 depth++;
131 if(!prs_align(ps))
132 return False;
134 if(!prs_uint32("switch_value", ps, depth, &info->switch_value))
135 return False;
137 if(!prs_uint32("doc_info_X ptr", ps, depth, &useless_ptr))
138 return False;
140 switch (info->switch_value)
142 case 1:
143 if(!smb_io_doc_info_1("",&info->doc_info_1, ps, depth))
144 return False;
145 break;
146 case 2:
148 this is just a placeholder
150 MSDN July 1998 says doc_info_2 is only on
151 Windows 95, and as Win95 doesn't do RPC to print
152 this case is nearly impossible
154 Maybe one day with Windows for dishwasher 2037 ...
157 /* smb_io_doc_info_2("",&info->doc_info_2, ps, depth); */
158 break;
159 default:
160 DEBUG(0,("Something is obviously wrong somewhere !\n"));
161 break;
164 return True;
167 /*******************************************************************
168 reads or writes an DOC_INFO_CONTAINER structure.
169 ********************************************************************/
171 static BOOL smb_io_doc_info_container(char *desc, DOC_INFO_CONTAINER *cont, prs_struct *ps, int depth)
173 if (cont == NULL) return False;
175 prs_debug(ps, depth, desc, "smb_io_doc_info_container");
176 depth++;
178 if(!prs_align(ps))
179 return False;
181 if(!prs_uint32("level", ps, depth, &cont->level))
182 return False;
184 if(!smb_io_doc_info("",&cont->docinfo, ps, depth))
185 return False;
187 return True;
190 /*******************************************************************
191 reads or writes an NOTIFY OPTION TYPE structure.
192 ********************************************************************/
194 /* NOTIFY_OPTION_TYPE and NOTIFY_OPTION_TYPE_DATA are really one
195 structure. The _TYPE structure is really the deferred referrants (i.e
196 the notify fields array) of the _TYPE structure. -tpot */
198 static BOOL smb_io_notify_option_type(char *desc, SPOOL_NOTIFY_OPTION_TYPE *type, prs_struct *ps, int depth)
200 prs_debug(ps, depth, desc, "smb_io_notify_option_type");
201 depth++;
203 if (!prs_align(ps))
204 return False;
206 if(!prs_uint16("type", ps, depth, &type->type))
207 return False;
208 if(!prs_uint16("reserved0", ps, depth, &type->reserved0))
209 return False;
210 if(!prs_uint32("reserved1", ps, depth, &type->reserved1))
211 return False;
212 if(!prs_uint32("reserved2", ps, depth, &type->reserved2))
213 return False;
214 if(!prs_uint32("count", ps, depth, &type->count))
215 return False;
216 if(!prs_uint32("fields_ptr", ps, depth, &type->fields_ptr))
217 return False;
219 return True;
222 /*******************************************************************
223 reads or writes an NOTIFY OPTION TYPE DATA.
224 ********************************************************************/
226 static BOOL smb_io_notify_option_type_data(char *desc, SPOOL_NOTIFY_OPTION_TYPE *type, prs_struct *ps, int depth)
228 int i;
230 prs_debug(ps, depth, desc, "smb_io_notify_option_type_data");
231 depth++;
233 /* if there are no fields just return */
234 if (type->fields_ptr==0)
235 return True;
237 if(!prs_align(ps))
238 return False;
240 if(!prs_uint32("count2", ps, depth, &type->count2))
241 return False;
243 if (type->count2 != type->count)
244 DEBUG(4,("What a mess, count was %x now is %x !\n", type->count, type->count2));
246 /* parse the option type data */
247 for(i=0;i<type->count2;i++)
248 if(!prs_uint16("fields",ps,depth,&type->fields[i]))
249 return False;
250 return True;
253 /*******************************************************************
254 reads or writes an NOTIFY OPTION structure.
255 ********************************************************************/
257 static BOOL smb_io_notify_option_type_ctr(char *desc, SPOOL_NOTIFY_OPTION_TYPE_CTR *ctr , prs_struct *ps, int depth)
259 int i;
261 prs_debug(ps, depth, desc, "smb_io_notify_option_type_ctr");
262 depth++;
264 if(!prs_uint32("count", ps, depth, &ctr->count))
265 return False;
267 /* reading */
268 if (UNMARSHALLING(ps))
269 if((ctr->type=(SPOOL_NOTIFY_OPTION_TYPE *)prs_alloc_mem(ps,ctr->count*sizeof(SPOOL_NOTIFY_OPTION_TYPE))) == NULL)
270 return False;
272 /* the option type struct */
273 for(i=0;i<ctr->count;i++)
274 if(!smb_io_notify_option_type("", &ctr->type[i] , ps, depth))
275 return False;
277 /* the type associated with the option type struct */
278 for(i=0;i<ctr->count;i++)
279 if(!smb_io_notify_option_type_data("", &ctr->type[i] , ps, depth))
280 return False;
282 return True;
285 /*******************************************************************
286 reads or writes an NOTIFY OPTION structure.
287 ********************************************************************/
289 static BOOL smb_io_notify_option(char *desc, SPOOL_NOTIFY_OPTION *option, prs_struct *ps, int depth)
291 prs_debug(ps, depth, desc, "smb_io_notify_option");
292 depth++;
294 if(!prs_uint32("version", ps, depth, &option->version))
295 return False;
296 if(!prs_uint32("flags", ps, depth, &option->flags))
297 return False;
298 if(!prs_uint32("count", ps, depth, &option->count))
299 return False;
300 if(!prs_uint32("option_type_ptr", ps, depth, &option->option_type_ptr))
301 return False;
303 /* marshalling or unmarshalling, that would work */
304 if (option->option_type_ptr!=0) {
305 if(!smb_io_notify_option_type_ctr("", &option->ctr ,ps, depth))
306 return False;
308 else {
309 option->ctr.type=NULL;
310 option->ctr.count=0;
313 return True;
316 /*******************************************************************
317 reads or writes an NOTIFY INFO DATA structure.
318 ********************************************************************/
320 static BOOL smb_io_notify_info_data(char *desc,SPOOL_NOTIFY_INFO_DATA *data, prs_struct *ps, int depth)
322 uint32 useless_ptr=0xADDE0FF0;
324 uint32 how_many_words;
325 BOOL isvalue;
326 uint32 x;
328 prs_debug(ps, depth, desc, "smb_io_notify_info_data");
329 depth++;
331 how_many_words=data->size;
332 if (how_many_words==POINTER) {
333 how_many_words=TWO_VALUE;
336 isvalue=data->enc_type;
338 if(!prs_align(ps))
339 return False;
340 if(!prs_uint16("type", ps, depth, &data->type))
341 return False;
342 if(!prs_uint16("field", ps, depth, &data->field))
343 return False;
344 /*prs_align(ps);*/
346 if(!prs_uint32("how many words", ps, depth, &how_many_words))
347 return False;
348 if(!prs_uint32("id", ps, depth, &data->id))
349 return False;
350 if(!prs_uint32("how many words", ps, depth, &how_many_words))
351 return False;
354 /*prs_align(ps);*/
356 if (isvalue==True) {
357 if(!prs_uint32("value[0]", ps, depth, &data->notify_data.value[0]))
358 return False;
359 if(!prs_uint32("value[1]", ps, depth, &data->notify_data.value[1]))
360 return False;
361 /*prs_align(ps);*/
362 } else {
363 /* it's a string */
364 /* length in ascii including \0 */
365 x=2*(data->notify_data.data.length+1);
366 if(!prs_uint32("string length", ps, depth, &x ))
367 return False;
368 if(!prs_uint32("pointer", ps, depth, &useless_ptr))
369 return False;
370 /*prs_align(ps);*/
373 return True;
376 /*******************************************************************
377 reads or writes an NOTIFY INFO DATA structure.
378 ********************************************************************/
380 BOOL smb_io_notify_info_data_strings(char *desc,SPOOL_NOTIFY_INFO_DATA *data,
381 prs_struct *ps, int depth)
383 uint32 x;
384 BOOL isvalue;
386 prs_debug(ps, depth, desc, "smb_io_notify_info_data_strings");
387 depth++;
389 if(!prs_align(ps))
390 return False;
392 isvalue=data->enc_type;
394 if (isvalue==False) {
395 /* length of string in unicode include \0 */
396 x=data->notify_data.data.length+1;
397 if(!prs_uint32("string length", ps, depth, &x ))
398 return False;
399 if (MARSHALLING(ps)) {
400 /* These are already in little endian format. Don't byte swap. */
401 if (x == 1) {
403 /* No memory allocated for this string
404 therefore following the data.string
405 pointer is a bad idea. Use a pointer to
406 the uint32 length union member to
407 provide a source for a unicode NULL */
409 if(!prs_uint8s(True,"string",ps,depth, (uint8 *)&data->notify_data.data.length,x*2))
410 return False;
411 } else {
412 if(!prs_uint16uni(True,"string",ps,depth,data->notify_data.data.string,x))
413 return False;
415 } else {
417 /* Tallocate memory for string */
419 data->notify_data.data.string = (uint16 *)prs_alloc_mem(ps, x * 2);
420 if (!data->notify_data.data.string)
421 return False;
423 if(!prs_uint16uni(True,"string",ps,depth,data->notify_data.data.string,x))
424 return False;
427 #if 0 /* JERRY */
429 /* Win2k does not seem to put this parse align here */
431 if(!prs_align(ps))
432 return False;
433 #endif
435 return True;
438 /*******************************************************************
439 reads or writes an NOTIFY INFO structure.
440 ********************************************************************/
442 static BOOL smb_io_notify_info(char *desc, SPOOL_NOTIFY_INFO *info, prs_struct *ps, int depth)
444 int i;
446 prs_debug(ps, depth, desc, "smb_io_notify_info");
447 depth++;
449 if(!prs_align(ps))
450 return False;
452 if(!prs_uint32("count", ps, depth, &info->count))
453 return False;
454 if(!prs_uint32("version", ps, depth, &info->version))
455 return False;
456 if(!prs_uint32("flags", ps, depth, &info->flags))
457 return False;
458 if(!prs_uint32("count", ps, depth, &info->count))
459 return False;
461 for (i=0;i<info->count;i++) {
462 if(!smb_io_notify_info_data(desc, &info->data[i], ps, depth))
463 return False;
466 /* now do the strings at the end of the stream */
467 for (i=0;i<info->count;i++) {
468 if(!smb_io_notify_info_data_strings(desc, &info->data[i], ps, depth))
469 return False;
472 return True;
475 /*******************************************************************
476 ********************************************************************/
478 static BOOL spool_io_user_level_1(char *desc, SPOOL_USER_1 *q_u, prs_struct *ps, int depth)
480 prs_debug(ps, depth, desc, "");
481 depth++;
483 /* reading */
484 if (UNMARSHALLING(ps))
485 ZERO_STRUCTP(q_u);
487 if (!prs_align(ps))
488 return False;
489 if (!prs_uint32("size", ps, depth, &q_u->size))
490 return False;
491 if (!prs_uint32("client_name_ptr", ps, depth, &q_u->client_name_ptr))
492 return False;
493 if (!prs_uint32("user_name_ptr", ps, depth, &q_u->user_name_ptr))
494 return False;
495 if (!prs_uint32("build", ps, depth, &q_u->build))
496 return False;
497 if (!prs_uint32("major", ps, depth, &q_u->major))
498 return False;
499 if (!prs_uint32("minor", ps, depth, &q_u->minor))
500 return False;
501 if (!prs_uint32("processor", ps, depth, &q_u->processor))
502 return False;
504 if (!smb_io_unistr2("", &q_u->client_name, q_u->client_name_ptr, ps, depth))
505 return False;
506 if (!prs_align(ps))
507 return False;
508 if (!smb_io_unistr2("", &q_u->user_name, q_u->user_name_ptr, ps, depth))
509 return False;
511 return True;
514 /*******************************************************************
515 ********************************************************************/
517 static BOOL spool_io_user_level(char *desc, SPOOL_USER_CTR *q_u, prs_struct *ps, int depth)
519 if (q_u==NULL)
520 return False;
522 prs_debug(ps, depth, desc, "spool_io_user_level");
523 depth++;
525 if (!prs_align(ps))
526 return False;
527 if (!prs_uint32("level", ps, depth, &q_u->level))
528 return False;
529 if (!prs_uint32("ptr", ps, depth, &q_u->ptr))
530 return False;
532 switch (q_u->level) {
533 case 1:
534 if (!spool_io_user_level_1("", &q_u->user1, ps, depth))
535 return False;
536 break;
537 default:
538 return False;
541 return True;
544 /*******************************************************************
545 * read or write a DEVICEMODE struct.
546 * on reading allocate memory for the private member
547 ********************************************************************/
549 BOOL spoolss_io_devmode(char *desc, prs_struct *ps, int depth, DEVICEMODE *devmode)
551 prs_debug(ps, depth, desc, "spoolss_io_devmode");
552 depth++;
554 if (UNMARSHALLING(ps)) {
555 devmode->devicename.buffer = (uint16 *)prs_alloc_mem(ps, 32 * sizeof(uint16) );
556 if (devmode->devicename.buffer == NULL)
557 return False;
560 if (!prs_uint16uni(True,"devicename", ps, depth, devmode->devicename.buffer, 32))
561 return False;
562 if (!prs_uint16("specversion", ps, depth, &devmode->specversion))
563 return False;
564 if (!prs_uint16("driverversion", ps, depth, &devmode->driverversion))
565 return False;
566 if (!prs_uint16("size", ps, depth, &devmode->size))
567 return False;
568 if (!prs_uint16("driverextra", ps, depth, &devmode->driverextra))
569 return False;
570 if (!prs_uint32("fields", ps, depth, &devmode->fields))
571 return False;
572 if (!prs_uint16("orientation", ps, depth, &devmode->orientation))
573 return False;
574 if (!prs_uint16("papersize", ps, depth, &devmode->papersize))
575 return False;
576 if (!prs_uint16("paperlength", ps, depth, &devmode->paperlength))
577 return False;
578 if (!prs_uint16("paperwidth", ps, depth, &devmode->paperwidth))
579 return False;
580 if (!prs_uint16("scale", ps, depth, &devmode->scale))
581 return False;
582 if (!prs_uint16("copies", ps, depth, &devmode->copies))
583 return False;
584 if (!prs_uint16("defaultsource", ps, depth, &devmode->defaultsource))
585 return False;
586 if (!prs_uint16("printquality", ps, depth, &devmode->printquality))
587 return False;
588 if (!prs_uint16("color", ps, depth, &devmode->color))
589 return False;
590 if (!prs_uint16("duplex", ps, depth, &devmode->duplex))
591 return False;
592 if (!prs_uint16("yresolution", ps, depth, &devmode->yresolution))
593 return False;
594 if (!prs_uint16("ttoption", ps, depth, &devmode->ttoption))
595 return False;
596 if (!prs_uint16("collate", ps, depth, &devmode->collate))
597 return False;
599 if (UNMARSHALLING(ps)) {
600 devmode->formname.buffer = (uint16 *)prs_alloc_mem(ps, 32 * sizeof(uint16) );
601 if (devmode->formname.buffer == NULL)
602 return False;
605 if (!prs_uint16uni(True, "formname", ps, depth, devmode->formname.buffer, 32))
606 return False;
607 if (!prs_uint16("logpixels", ps, depth, &devmode->logpixels))
608 return False;
609 if (!prs_uint32("bitsperpel", ps, depth, &devmode->bitsperpel))
610 return False;
611 if (!prs_uint32("pelswidth", ps, depth, &devmode->pelswidth))
612 return False;
613 if (!prs_uint32("pelsheight", ps, depth, &devmode->pelsheight))
614 return False;
615 if (!prs_uint32("displayflags", ps, depth, &devmode->displayflags))
616 return False;
617 if (!prs_uint32("displayfrequency", ps, depth, &devmode->displayfrequency))
618 return False;
621 * Conditional parsing. Assume that the DeviceMode has been
622 * zero'd by the caller.
624 switch(devmode->specversion) {
626 /* Used by spooler when issuing OpenPrinter() calls. NT 3.5x? */
627 case 0x0320:
628 break;
630 /* See the comments on the DEVMODE in the msdn GDI documentation */
631 case 0x0400:
632 case 0x0401:
633 if (!prs_uint32("icmmethod", ps, depth, &devmode->icmmethod))
634 return False;
635 if (!prs_uint32("icmintent", ps, depth, &devmode->icmintent))
636 return False;
637 if (!prs_uint32("mediatype", ps, depth, &devmode->mediatype))
638 return False;
639 if (!prs_uint32("dithertype", ps, depth, &devmode->dithertype))
640 return False;
641 if (!prs_uint32("reserved1", ps, depth, &devmode->reserved1))
642 return False;
643 if (!prs_uint32("reserved2", ps, depth, &devmode->reserved2))
644 return False;
645 if (!prs_uint32("panningwidth", ps, depth, &devmode->panningwidth))
646 return False;
647 if (!prs_uint32("panningheight", ps, depth, &devmode->panningheight))
648 return False;
649 break;
651 /* log an error if we see something else */
652 default:
653 DEBUG(0,("spoolss_io_devmode: Unknown specversion [0x%x]!\n", devmode->specversion));
654 DEBUG(0,("spoolss_io_devmode: Please report to samba-technical@samba.org\n"));
655 break;
658 if (devmode->driverextra!=0) {
659 if (UNMARSHALLING(ps)) {
660 devmode->private=(uint8 *)prs_alloc_mem(ps, devmode->driverextra*sizeof(uint8));
661 if(devmode->private == NULL)
662 return False;
663 DEBUG(7,("spoolss_io_devmode: allocated memory [%d] for private\n",devmode->driverextra));
666 DEBUG(7,("spoolss_io_devmode: parsing [%d] bytes of private\n",devmode->driverextra));
667 if (!prs_uint8s(False, "private", ps, depth,
668 devmode->private, devmode->driverextra))
669 return False;
672 return True;
675 /*******************************************************************
676 Read or write a DEVICEMODE container
677 ********************************************************************/
679 static BOOL spoolss_io_devmode_cont(char *desc, DEVMODE_CTR *dm_c, prs_struct *ps, int depth)
681 if (dm_c==NULL)
682 return False;
684 prs_debug(ps, depth, desc, "spoolss_io_devmode_cont");
685 depth++;
687 if(!prs_align(ps))
688 return False;
690 if (!prs_uint32("size", ps, depth, &dm_c->size))
691 return False;
693 if (!prs_uint32("devmode_ptr", ps, depth, &dm_c->devmode_ptr))
694 return False;
696 if (dm_c->size==0 || dm_c->devmode_ptr==0) {
697 if (UNMARSHALLING(ps))
698 /* if while reading there is no DEVMODE ... */
699 dm_c->devmode=NULL;
700 return True;
703 /* so we have a DEVICEMODE to follow */
704 if (UNMARSHALLING(ps)) {
705 DEBUG(9,("Allocating memory for spoolss_io_devmode\n"));
706 dm_c->devmode=(DEVICEMODE *)prs_alloc_mem(ps,sizeof(DEVICEMODE));
707 if(dm_c->devmode == NULL)
708 return False;
711 /* this is bad code, shouldn't be there */
712 if (!prs_uint32("size", ps, depth, &dm_c->size))
713 return False;
715 if (!spoolss_io_devmode(desc, ps, depth, dm_c->devmode))
716 return False;
718 return True;
721 /*******************************************************************
722 ********************************************************************/
724 static BOOL spoolss_io_printer_default(char *desc, PRINTER_DEFAULT *pd, prs_struct *ps, int depth)
726 if (pd==NULL)
727 return False;
729 prs_debug(ps, depth, desc, "spoolss_io_printer_default");
730 depth++;
732 if (!prs_uint32("datatype_ptr", ps, depth, &pd->datatype_ptr))
733 return False;
735 if (!smb_io_unistr2("datatype", &pd->datatype, pd->datatype_ptr, ps,depth))
736 return False;
738 if (!prs_align(ps))
739 return False;
741 if (!spoolss_io_devmode_cont("", &pd->devmode_cont, ps, depth))
742 return False;
744 if (!prs_align(ps))
745 return False;
747 if (!prs_uint32("access_required", ps, depth, &pd->access_required))
748 return False;
750 return True;
753 /*******************************************************************
754 * init a structure.
755 ********************************************************************/
757 BOOL make_spoolss_q_open_printer_ex(SPOOL_Q_OPEN_PRINTER_EX *q_u,
758 const fstring printername,
759 const fstring datatype,
760 uint32 access_required,
761 const fstring clientname,
762 const fstring user_name)
764 DEBUG(5,("make_spoolss_q_open_printer_ex\n"));
765 q_u->printername_ptr = (printername!=NULL)?1:0;
766 init_unistr2(&q_u->printername, printername, strlen(printername)+1);
768 q_u->printer_default.datatype_ptr = 0;
770 q_u->printer_default.datatype_ptr = (datatype!=NULL)?1:0;
771 init_unistr2(&q_u->printer_default.datatype, datatype, strlen(datatype));
773 q_u->printer_default.devmode_cont.size=0;
774 q_u->printer_default.devmode_cont.devmode_ptr=0;
775 q_u->printer_default.devmode_cont.devmode=NULL;
776 q_u->printer_default.access_required=access_required;
777 q_u->user_switch=1;
778 q_u->user_ctr.level=1;
779 q_u->user_ctr.ptr=1;
780 q_u->user_ctr.user1.size=strlen(clientname)+strlen(user_name)+10;
781 q_u->user_ctr.user1.client_name_ptr = (clientname!=NULL)?1:0;
782 q_u->user_ctr.user1.user_name_ptr = (user_name!=NULL)?1:0;
783 q_u->user_ctr.user1.build=1381;
784 q_u->user_ctr.user1.major=2;
785 q_u->user_ctr.user1.minor=0;
786 q_u->user_ctr.user1.processor=0;
787 init_unistr2(&q_u->user_ctr.user1.client_name, clientname, strlen(clientname)+1);
788 init_unistr2(&q_u->user_ctr.user1.user_name, user_name, strlen(user_name)+1);
790 return True;
793 /*******************************************************************
794 * init a structure.
795 ********************************************************************/
797 BOOL make_spoolss_q_addprinterex(
798 TALLOC_CTX *mem_ctx,
799 SPOOL_Q_ADDPRINTEREX *q_u,
800 const char *srv_name,
801 const char* clientname,
802 const char* user_name,
803 uint32 level,
804 PRINTER_INFO_CTR *ctr)
806 DEBUG(5,("make_spoolss_q_addprinterex\n"));
808 if (!ctr) return False;
810 ZERO_STRUCTP(q_u);
812 q_u->server_name_ptr = (srv_name!=NULL)?1:0;
813 init_unistr2(&q_u->server_name, srv_name, strlen(srv_name));
815 q_u->level = level;
817 q_u->info.level = level;
818 q_u->info.info_ptr = (ctr->printers_2!=NULL)?1:0;
819 switch (level) {
820 case 2:
821 /* init q_u->info.info2 from *info */
822 if (!make_spoolss_printer_info_2(mem_ctx, &q_u->info.info_2, ctr->printers_2)) {
823 DEBUG(0,("make_spoolss_q_addprinterex: Unable to fill SPOOL_Q_ADDPRINTEREX struct!\n"));
824 return False;
826 break;
827 default :
828 break;
831 q_u->user_switch=1;
833 q_u->user_ctr.level=1;
834 q_u->user_ctr.ptr=1;
835 q_u->user_ctr.user1.client_name_ptr = (clientname!=NULL)?1:0;
836 q_u->user_ctr.user1.user_name_ptr = (user_name!=NULL)?1:0;
837 q_u->user_ctr.user1.build=1381;
838 q_u->user_ctr.user1.major=2;
839 q_u->user_ctr.user1.minor=0;
840 q_u->user_ctr.user1.processor=0;
841 init_unistr2(&q_u->user_ctr.user1.client_name, clientname, strlen(clientname)+1);
842 init_unistr2(&q_u->user_ctr.user1.user_name, user_name, strlen(user_name)+1);
843 q_u->user_ctr.user1.size=q_u->user_ctr.user1.user_name.uni_str_len +
844 q_u->user_ctr.user1.client_name.uni_str_len + 2;
846 return True;
849 /*******************************************************************
850 create a SPOOL_PRINTER_INFO_2 stuct from a PRINTER_INFO_2 struct
851 *******************************************************************/
853 BOOL make_spoolss_printer_info_2(TALLOC_CTX *mem_ctx, SPOOL_PRINTER_INFO_LEVEL_2 **spool_info2,
854 PRINTER_INFO_2 *info)
857 SPOOL_PRINTER_INFO_LEVEL_2 *inf;
859 /* allocate the necessary memory */
860 if (!(inf=(SPOOL_PRINTER_INFO_LEVEL_2*)talloc(mem_ctx, sizeof(SPOOL_PRINTER_INFO_LEVEL_2)))) {
861 DEBUG(0,("make_spoolss_printer_info_2: Unable to allocate SPOOL_PRINTER_INFO_LEVEL_2 sruct!\n"));
862 return False;
865 inf->servername_ptr = (info->servername.buffer!=NULL)?1:0;
866 inf->printername_ptr = (info->printername.buffer!=NULL)?1:0;
867 inf->sharename_ptr = (info->sharename.buffer!=NULL)?1:0;
868 inf->portname_ptr = (info->portname.buffer!=NULL)?1:0;
869 inf->drivername_ptr = (info->drivername.buffer!=NULL)?1:0;
870 inf->comment_ptr = (info->comment.buffer!=NULL)?1:0;
871 inf->location_ptr = (info->location.buffer!=NULL)?1:0;
872 inf->devmode_ptr = (info->devmode!=NULL)?1:0;
873 inf->sepfile_ptr = (info->sepfile.buffer!=NULL)?1:0;
874 inf->printprocessor_ptr = (info->printprocessor.buffer!=NULL)?1:0;
875 inf->datatype_ptr = (info->datatype.buffer!=NULL)?1:0;
876 inf->parameters_ptr = (info->parameters.buffer!=NULL)?1:0;
877 inf->secdesc_ptr = (info->secdesc!=NULL)?1:0;
878 inf->attributes = info->attributes;
879 inf->priority = info->priority;
880 inf->default_priority = info->defaultpriority;
881 inf->starttime = info->starttime;
882 inf->untiltime = info->untiltime;
883 inf->cjobs = info->cjobs;
884 inf->averageppm = info->averageppm;
885 init_unistr2_from_unistr(&inf->servername, &info->servername);
886 init_unistr2_from_unistr(&inf->printername, &info->printername);
887 init_unistr2_from_unistr(&inf->sharename, &info->sharename);
888 init_unistr2_from_unistr(&inf->portname, &info->portname);
889 init_unistr2_from_unistr(&inf->drivername, &info->drivername);
890 init_unistr2_from_unistr(&inf->comment, &info->comment);
891 init_unistr2_from_unistr(&inf->location, &info->location);
892 init_unistr2_from_unistr(&inf->sepfile, &info->sepfile);
893 init_unistr2_from_unistr(&inf->printprocessor, &info->printprocessor);
894 init_unistr2_from_unistr(&inf->datatype, &info->datatype);
895 init_unistr2_from_unistr(&inf->parameters, &info->parameters);
896 init_unistr2_from_unistr(&inf->datatype, &info->datatype);
898 *spool_info2 = inf;
900 return True;
903 /*******************************************************************
904 * read a structure.
905 * called from spoolss_q_open_printer_ex (srv_spoolss.c)
906 ********************************************************************/
908 BOOL spoolss_io_q_open_printer(char *desc, SPOOL_Q_OPEN_PRINTER *q_u, prs_struct *ps, int depth)
910 if (q_u == NULL)
911 return False;
913 prs_debug(ps, depth, desc, "spoolss_io_q_open_printer");
914 depth++;
916 if (!prs_align(ps))
917 return False;
919 if (!prs_uint32("printername_ptr", ps, depth, &q_u->printername_ptr))
920 return False;
921 if (!smb_io_unistr2("", &q_u->printername, q_u->printername_ptr, ps,depth))
922 return False;
924 if (!prs_align(ps))
925 return False;
927 if (!spoolss_io_printer_default("", &q_u->printer_default, ps, depth))
928 return False;
930 return True;
933 /*******************************************************************
934 * write a structure.
935 * called from static spoolss_r_open_printer_ex (srv_spoolss.c)
936 * called from spoolss_open_printer_ex (cli_spoolss.c)
937 ********************************************************************/
939 BOOL spoolss_io_r_open_printer(char *desc, SPOOL_R_OPEN_PRINTER *r_u, prs_struct *ps, int depth)
941 if (r_u == NULL) return False;
943 prs_debug(ps, depth, desc, "spoolss_io_r_open_printer");
944 depth++;
946 if (!prs_align(ps))
947 return False;
949 if (!smb_io_pol_hnd("printer handle",&(r_u->handle),ps,depth))
950 return False;
952 if (!prs_werror("status code", ps, depth, &(r_u->status)))
953 return False;
955 return True;
959 /*******************************************************************
960 * read a structure.
961 * called from spoolss_q_open_printer_ex (srv_spoolss.c)
962 ********************************************************************/
964 BOOL spoolss_io_q_open_printer_ex(char *desc, SPOOL_Q_OPEN_PRINTER_EX *q_u, prs_struct *ps, int depth)
966 if (q_u == NULL)
967 return False;
969 prs_debug(ps, depth, desc, "spoolss_io_q_open_printer_ex");
970 depth++;
972 if (!prs_align(ps))
973 return False;
975 if (!prs_uint32("printername_ptr", ps, depth, &q_u->printername_ptr))
976 return False;
977 if (!smb_io_unistr2("", &q_u->printername, q_u->printername_ptr, ps,depth))
978 return False;
980 if (!prs_align(ps))
981 return False;
983 if (!spoolss_io_printer_default("", &q_u->printer_default, ps, depth))
984 return False;
986 if (!prs_uint32("user_switch", ps, depth, &q_u->user_switch))
987 return False;
988 if (!spool_io_user_level("", &q_u->user_ctr, ps, depth))
989 return False;
991 return True;
994 /*******************************************************************
995 * write a structure.
996 * called from static spoolss_r_open_printer_ex (srv_spoolss.c)
997 * called from spoolss_open_printer_ex (cli_spoolss.c)
998 ********************************************************************/
1000 BOOL spoolss_io_r_open_printer_ex(char *desc, SPOOL_R_OPEN_PRINTER_EX *r_u, prs_struct *ps, int depth)
1002 if (r_u == NULL) return False;
1004 prs_debug(ps, depth, desc, "spoolss_io_r_open_printer_ex");
1005 depth++;
1007 if (!prs_align(ps))
1008 return False;
1010 if (!smb_io_pol_hnd("printer handle",&(r_u->handle),ps,depth))
1011 return False;
1013 if (!prs_werror("status code", ps, depth, &(r_u->status)))
1014 return False;
1016 return True;
1019 /*******************************************************************
1020 * init a structure.
1021 ********************************************************************/
1022 BOOL make_spoolss_q_deleteprinterdriver(
1023 TALLOC_CTX *mem_ctx,
1024 SPOOL_Q_DELETEPRINTERDRIVER *q_u,
1025 const char *server,
1026 const char* arch,
1027 const char* driver
1030 DEBUG(5,("make_spoolss_q_deleteprinterdriver\n"));
1032 q_u->server_ptr = (server!=NULL)?1:0;
1034 /* these must be NULL terminated or else NT4 will
1035 complain about invalid parameters --jerry */
1036 init_unistr2(&q_u->server, server, strlen(server)+1);
1037 init_unistr2(&q_u->arch, arch, strlen(arch)+1);
1038 init_unistr2(&q_u->driver, driver, strlen(driver)+1);
1041 return True;
1045 /*******************************************************************
1046 * make a structure.
1047 ********************************************************************/
1049 BOOL make_spoolss_q_getprinterdata(SPOOL_Q_GETPRINTERDATA *q_u,
1050 const POLICY_HND *handle,
1051 UNISTR2 *valuename, uint32 size)
1053 if (q_u == NULL) return False;
1055 DEBUG(5,("make_spoolss_q_getprinterdata\n"));
1057 q_u->handle = *handle;
1058 copy_unistr2(&q_u->valuename, valuename);
1059 q_u->size = size;
1061 return True;
1064 /*******************************************************************
1065 * read a structure.
1066 * called from spoolss_q_getprinterdata (srv_spoolss.c)
1067 ********************************************************************/
1069 BOOL spoolss_io_q_getprinterdata(char *desc, SPOOL_Q_GETPRINTERDATA *q_u, prs_struct *ps, int depth)
1071 if (q_u == NULL)
1072 return False;
1074 prs_debug(ps, depth, desc, "spoolss_io_q_getprinterdata");
1075 depth++;
1077 if (!prs_align(ps))
1078 return False;
1079 if (!smb_io_pol_hnd("printer handle",&q_u->handle,ps,depth))
1080 return False;
1081 if (!prs_align(ps))
1082 return False;
1083 if (!smb_io_unistr2("valuename", &q_u->valuename,True,ps,depth))
1084 return False;
1085 if (!prs_align(ps))
1086 return False;
1087 if (!prs_uint32("size", ps, depth, &q_u->size))
1088 return False;
1090 return True;
1093 /*******************************************************************
1094 * read a structure.
1095 * called from spoolss_q_deleteprinterdata (srv_spoolss.c)
1096 ********************************************************************/
1098 BOOL spoolss_io_q_deleteprinterdata(char *desc, SPOOL_Q_DELETEPRINTERDATA *q_u, prs_struct *ps, int depth)
1100 if (q_u == NULL)
1101 return False;
1103 prs_debug(ps, depth, desc, "spoolss_io_q_deleteprinterdata");
1104 depth++;
1106 if (!prs_align(ps))
1107 return False;
1108 if (!smb_io_pol_hnd("printer handle",&q_u->handle,ps,depth))
1109 return False;
1110 if (!prs_align(ps))
1111 return False;
1112 if (!smb_io_unistr2("valuename", &q_u->valuename,True,ps,depth))
1113 return False;
1115 return True;
1118 /*******************************************************************
1119 * write a structure.
1120 * called from spoolss_r_deleteprinterdata (srv_spoolss.c)
1121 ********************************************************************/
1123 BOOL spoolss_io_r_deleteprinterdata(char *desc, SPOOL_R_DELETEPRINTERDATA *r_u, prs_struct *ps, int depth)
1125 prs_debug(ps, depth, desc, "spoolss_io_r_deleteprinterdata");
1126 depth++;
1127 if(!prs_werror("status", ps, depth, &r_u->status))
1128 return False;
1130 return True;
1133 /*******************************************************************
1134 * write a structure.
1135 * called from spoolss_r_getprinterdata (srv_spoolss.c)
1136 ********************************************************************/
1138 BOOL spoolss_io_r_getprinterdata(char *desc, SPOOL_R_GETPRINTERDATA *r_u, prs_struct *ps, int depth)
1140 if (r_u == NULL)
1141 return False;
1143 prs_debug(ps, depth, desc, "spoolss_io_r_getprinterdata");
1144 depth++;
1146 if (!prs_align(ps))
1147 return False;
1148 if (!prs_uint32("type", ps, depth, &r_u->type))
1149 return False;
1150 if (!prs_uint32("size", ps, depth, &r_u->size))
1151 return False;
1153 if (!prs_uint8s(False,"data", ps, depth, r_u->data, r_u->size))
1154 return False;
1156 if (!prs_align(ps))
1157 return False;
1159 if (!prs_uint32("needed", ps, depth, &r_u->needed))
1160 return False;
1161 if (!prs_werror("status", ps, depth, &r_u->status))
1162 return False;
1164 return True;
1167 /*******************************************************************
1168 * make a structure.
1169 ********************************************************************/
1171 BOOL make_spoolss_q_closeprinter(SPOOL_Q_CLOSEPRINTER *q_u, POLICY_HND *hnd)
1173 if (q_u == NULL) return False;
1175 DEBUG(5,("make_spoolss_q_closeprinter\n"));
1177 memcpy(&q_u->handle, hnd, sizeof(q_u->handle));
1179 return True;
1182 /*******************************************************************
1183 * read a structure.
1184 * called from static spoolss_q_abortprinter (srv_spoolss.c)
1185 * called from spoolss_abortprinter (cli_spoolss.c)
1186 ********************************************************************/
1188 BOOL spoolss_io_q_abortprinter(char *desc, SPOOL_Q_ABORTPRINTER *q_u, prs_struct *ps, int depth)
1190 if (q_u == NULL) return False;
1192 prs_debug(ps, depth, desc, "spoolss_io_q_abortprinter");
1193 depth++;
1195 if (!prs_align(ps))
1196 return False;
1198 if (!smb_io_pol_hnd("printer handle",&q_u->handle,ps,depth))
1199 return False;
1201 return True;
1204 /*******************************************************************
1205 * write a structure.
1206 * called from spoolss_r_abortprinter (srv_spoolss.c)
1207 ********************************************************************/
1209 BOOL spoolss_io_r_abortprinter(char *desc, SPOOL_R_ABORTPRINTER *r_u, prs_struct *ps, int depth)
1211 prs_debug(ps, depth, desc, "spoolss_io_r_abortprinter");
1212 depth++;
1213 if(!prs_werror("status", ps, depth, &r_u->status))
1214 return False;
1216 return True;
1219 /*******************************************************************
1220 * read a structure.
1221 * called from static spoolss_q_deleteprinter (srv_spoolss.c)
1222 * called from spoolss_deleteprinter (cli_spoolss.c)
1223 ********************************************************************/
1225 BOOL spoolss_io_q_deleteprinter(char *desc, SPOOL_Q_DELETEPRINTER *q_u, prs_struct *ps, int depth)
1227 if (q_u == NULL) return False;
1229 prs_debug(ps, depth, desc, "spoolss_io_q_deleteprinter");
1230 depth++;
1232 if (!prs_align(ps))
1233 return False;
1235 if (!smb_io_pol_hnd("printer handle",&q_u->handle,ps,depth))
1236 return False;
1238 return True;
1241 /*******************************************************************
1242 * write a structure.
1243 * called from static spoolss_r_deleteprinter (srv_spoolss.c)
1244 * called from spoolss_deleteprinter (cli_spoolss.c)
1245 ********************************************************************/
1247 BOOL spoolss_io_r_deleteprinter(char *desc, SPOOL_R_DELETEPRINTER *r_u, prs_struct *ps, int depth)
1249 prs_debug(ps, depth, desc, "spoolss_io_r_deleteprinter");
1250 depth++;
1252 if (!prs_align(ps))
1253 return False;
1255 if (!smb_io_pol_hnd("printer handle",&r_u->handle,ps,depth))
1256 return False;
1257 if (!prs_werror("status", ps, depth, &r_u->status))
1258 return False;
1260 return True;
1264 /*******************************************************************
1265 * read a structure.
1266 * called from api_spoolss_deleteprinterdriver (srv_spoolss.c)
1267 * called from spoolss_deleteprinterdriver (cli_spoolss.c)
1268 ********************************************************************/
1270 BOOL spoolss_io_q_deleteprinterdriver(char *desc, SPOOL_Q_DELETEPRINTERDRIVER *q_u, prs_struct *ps, int depth)
1272 if (q_u == NULL) return False;
1274 prs_debug(ps, depth, desc, "spoolss_io_q_deleteprinterdriver");
1275 depth++;
1277 if (!prs_align(ps))
1278 return False;
1280 if(!prs_uint32("server_ptr", ps, depth, &q_u->server_ptr))
1281 return False;
1282 if(!smb_io_unistr2("server", &q_u->server, q_u->server_ptr, ps, depth))
1283 return False;
1284 if(!smb_io_unistr2("arch", &q_u->arch, True, ps, depth))
1285 return False;
1286 if(!smb_io_unistr2("driver", &q_u->driver, True, ps, depth))
1287 return False;
1290 return True;
1294 /*******************************************************************
1295 * write a structure.
1296 ********************************************************************/
1297 BOOL spoolss_io_r_deleteprinterdriver(char *desc, SPOOL_R_DELETEPRINTERDRIVER *r_u, prs_struct *ps, int depth)
1299 if (r_u == NULL) return False;
1301 prs_debug(ps, depth, desc, "spoolss_io_r_deleteprinterdriver");
1302 depth++;
1304 if (!prs_align(ps))
1305 return False;
1307 if (!prs_werror("status", ps, depth, &r_u->status))
1308 return False;
1310 return True;
1315 /*******************************************************************
1316 * read a structure.
1317 * called from static spoolss_q_closeprinter (srv_spoolss.c)
1318 * called from spoolss_closeprinter (cli_spoolss.c)
1319 ********************************************************************/
1321 BOOL spoolss_io_q_closeprinter(char *desc, SPOOL_Q_CLOSEPRINTER *q_u, prs_struct *ps, int depth)
1323 if (q_u == NULL) return False;
1325 prs_debug(ps, depth, desc, "spoolss_io_q_closeprinter");
1326 depth++;
1328 if (!prs_align(ps))
1329 return False;
1331 if (!smb_io_pol_hnd("printer handle",&q_u->handle,ps,depth))
1332 return False;
1334 return True;
1337 /*******************************************************************
1338 * write a structure.
1339 * called from static spoolss_r_closeprinter (srv_spoolss.c)
1340 * called from spoolss_closeprinter (cli_spoolss.c)
1341 ********************************************************************/
1343 BOOL spoolss_io_r_closeprinter(char *desc, SPOOL_R_CLOSEPRINTER *r_u, prs_struct *ps, int depth)
1345 prs_debug(ps, depth, desc, "spoolss_io_r_closeprinter");
1346 depth++;
1348 if (!prs_align(ps))
1349 return False;
1351 if (!smb_io_pol_hnd("printer handle",&r_u->handle,ps,depth))
1352 return False;
1353 if (!prs_werror("status", ps, depth, &r_u->status))
1354 return False;
1356 return True;
1359 /*******************************************************************
1360 * read a structure.
1361 * called from spoolss_q_startdocprinter (srv_spoolss.c)
1362 ********************************************************************/
1364 BOOL spoolss_io_q_startdocprinter(char *desc, SPOOL_Q_STARTDOCPRINTER *q_u, prs_struct *ps, int depth)
1366 if (q_u == NULL) return False;
1368 prs_debug(ps, depth, desc, "spoolss_io_q_startdocprinter");
1369 depth++;
1371 if(!prs_align(ps))
1372 return False;
1374 if(!smb_io_pol_hnd("printer handle",&q_u->handle,ps,depth))
1375 return False;
1377 if(!smb_io_doc_info_container("",&q_u->doc_info_container, ps, depth))
1378 return False;
1380 return True;
1383 /*******************************************************************
1384 * write a structure.
1385 * called from spoolss_r_startdocprinter (srv_spoolss.c)
1386 ********************************************************************/
1388 BOOL spoolss_io_r_startdocprinter(char *desc, SPOOL_R_STARTDOCPRINTER *r_u, prs_struct *ps, int depth)
1390 prs_debug(ps, depth, desc, "spoolss_io_r_startdocprinter");
1391 depth++;
1392 if(!prs_uint32("jobid", ps, depth, &r_u->jobid))
1393 return False;
1394 if(!prs_werror("status", ps, depth, &r_u->status))
1395 return False;
1397 return True;
1400 /*******************************************************************
1401 * read a structure.
1402 * called from spoolss_q_enddocprinter (srv_spoolss.c)
1403 ********************************************************************/
1405 BOOL spoolss_io_q_enddocprinter(char *desc, SPOOL_Q_ENDDOCPRINTER *q_u, prs_struct *ps, int depth)
1407 if (q_u == NULL) return False;
1409 prs_debug(ps, depth, desc, "spoolss_io_q_enddocprinter");
1410 depth++;
1412 if(!prs_align(ps))
1413 return False;
1415 if(!smb_io_pol_hnd("printer handle",&q_u->handle,ps,depth))
1416 return False;
1418 return True;
1421 /*******************************************************************
1422 * write a structure.
1423 * called from spoolss_r_enddocprinter (srv_spoolss.c)
1424 ********************************************************************/
1426 BOOL spoolss_io_r_enddocprinter(char *desc, SPOOL_R_ENDDOCPRINTER *r_u, prs_struct *ps, int depth)
1428 prs_debug(ps, depth, desc, "spoolss_io_r_enddocprinter");
1429 depth++;
1430 if(!prs_werror("status", ps, depth, &r_u->status))
1431 return False;
1433 return True;
1436 /*******************************************************************
1437 * read a structure.
1438 * called from spoolss_q_startpageprinter (srv_spoolss.c)
1439 ********************************************************************/
1441 BOOL spoolss_io_q_startpageprinter(char *desc, SPOOL_Q_STARTPAGEPRINTER *q_u, prs_struct *ps, int depth)
1443 if (q_u == NULL) return False;
1445 prs_debug(ps, depth, desc, "spoolss_io_q_startpageprinter");
1446 depth++;
1448 if(!prs_align(ps))
1449 return False;
1451 if(!smb_io_pol_hnd("printer handle",&q_u->handle,ps,depth))
1452 return False;
1454 return True;
1457 /*******************************************************************
1458 * write a structure.
1459 * called from spoolss_r_startpageprinter (srv_spoolss.c)
1460 ********************************************************************/
1462 BOOL spoolss_io_r_startpageprinter(char *desc, SPOOL_R_STARTPAGEPRINTER *r_u, prs_struct *ps, int depth)
1464 prs_debug(ps, depth, desc, "spoolss_io_r_startpageprinter");
1465 depth++;
1466 if(!prs_werror("status", ps, depth, &r_u->status))
1467 return False;
1469 return True;
1472 /*******************************************************************
1473 * read a structure.
1474 * called from spoolss_q_endpageprinter (srv_spoolss.c)
1475 ********************************************************************/
1477 BOOL spoolss_io_q_endpageprinter(char *desc, SPOOL_Q_ENDPAGEPRINTER *q_u, prs_struct *ps, int depth)
1479 if (q_u == NULL) return False;
1481 prs_debug(ps, depth, desc, "spoolss_io_q_endpageprinter");
1482 depth++;
1484 if(!prs_align(ps))
1485 return False;
1487 if(!smb_io_pol_hnd("printer handle",&q_u->handle,ps,depth))
1488 return False;
1490 return True;
1493 /*******************************************************************
1494 * write a structure.
1495 * called from spoolss_r_endpageprinter (srv_spoolss.c)
1496 ********************************************************************/
1498 BOOL spoolss_io_r_endpageprinter(char *desc, SPOOL_R_ENDPAGEPRINTER *r_u, prs_struct *ps, int depth)
1500 prs_debug(ps, depth, desc, "spoolss_io_r_endpageprinter");
1501 depth++;
1502 if(!prs_werror("status", ps, depth, &r_u->status))
1503 return False;
1505 return True;
1508 /*******************************************************************
1509 * read a structure.
1510 * called from spoolss_q_writeprinter (srv_spoolss.c)
1511 ********************************************************************/
1513 BOOL spoolss_io_q_writeprinter(char *desc, SPOOL_Q_WRITEPRINTER *q_u, prs_struct *ps, int depth)
1515 if (q_u == NULL) return False;
1517 prs_debug(ps, depth, desc, "spoolss_io_q_writeprinter");
1518 depth++;
1520 if(!prs_align(ps))
1521 return False;
1523 if(!smb_io_pol_hnd("printer handle",&q_u->handle,ps,depth))
1524 return False;
1525 if(!prs_uint32("buffer_size", ps, depth, &q_u->buffer_size))
1526 return False;
1528 if (q_u->buffer_size!=0)
1530 if (UNMARSHALLING(ps))
1531 q_u->buffer=(uint8 *)prs_alloc_mem(ps,q_u->buffer_size*sizeof(uint8));
1532 if(q_u->buffer == NULL)
1533 return False;
1534 if(!prs_uint8s(True, "buffer", ps, depth, q_u->buffer, q_u->buffer_size))
1535 return False;
1537 if(!prs_align(ps))
1538 return False;
1539 if(!prs_uint32("buffer_size2", ps, depth, &q_u->buffer_size2))
1540 return False;
1542 return True;
1545 /*******************************************************************
1546 * write a structure.
1547 * called from spoolss_r_writeprinter (srv_spoolss.c)
1548 ********************************************************************/
1550 BOOL spoolss_io_r_writeprinter(char *desc, SPOOL_R_WRITEPRINTER *r_u, prs_struct *ps, int depth)
1552 prs_debug(ps, depth, desc, "spoolss_io_r_writeprinter");
1553 depth++;
1554 if(!prs_uint32("buffer_written", ps, depth, &r_u->buffer_written))
1555 return False;
1556 if(!prs_werror("status", ps, depth, &r_u->status))
1557 return False;
1559 return True;
1562 /*******************************************************************
1563 * read a structure.
1564 * called from spoolss_q_rffpcnex (srv_spoolss.c)
1565 ********************************************************************/
1567 BOOL spoolss_io_q_rffpcnex(char *desc, SPOOL_Q_RFFPCNEX *q_u, prs_struct *ps, int depth)
1569 prs_debug(ps, depth, desc, "spoolss_io_q_rffpcnex");
1570 depth++;
1572 if(!prs_align(ps))
1573 return False;
1575 if(!smb_io_pol_hnd("printer handle", &q_u->handle, ps, depth))
1576 return False;
1577 if(!prs_uint32("flags", ps, depth, &q_u->flags))
1578 return False;
1579 if(!prs_uint32("options", ps, depth, &q_u->options))
1580 return False;
1581 if(!prs_uint32("localmachine_ptr", ps, depth, &q_u->localmachine_ptr))
1582 return False;
1583 if(!smb_io_unistr2("localmachine", &q_u->localmachine, q_u->localmachine_ptr, ps, depth))
1584 return False;
1586 if(!prs_align(ps))
1587 return False;
1589 if(!prs_uint32("printerlocal", ps, depth, &q_u->printerlocal))
1590 return False;
1592 if(!prs_uint32("option_ptr", ps, depth, &q_u->option_ptr))
1593 return False;
1595 if (q_u->option_ptr!=0) {
1597 if (UNMARSHALLING(ps))
1598 if((q_u->option=(SPOOL_NOTIFY_OPTION *)prs_alloc_mem(ps,sizeof(SPOOL_NOTIFY_OPTION))) == NULL)
1599 return False;
1601 if(!smb_io_notify_option("notify option", q_u->option, ps, depth))
1602 return False;
1605 return True;
1608 /*******************************************************************
1609 * write a structure.
1610 * called from spoolss_r_rffpcnex (srv_spoolss.c)
1611 ********************************************************************/
1613 BOOL spoolss_io_r_rffpcnex(char *desc, SPOOL_R_RFFPCNEX *r_u, prs_struct *ps, int depth)
1615 prs_debug(ps, depth, desc, "spoolss_io_r_rffpcnex");
1616 depth++;
1618 if(!prs_werror("status", ps, depth, &r_u->status))
1619 return False;
1621 return True;
1624 /*******************************************************************
1625 * read a structure.
1626 * called from spoolss_q_rfnpcnex (srv_spoolss.c)
1627 ********************************************************************/
1629 BOOL spoolss_io_q_rfnpcnex(char *desc, SPOOL_Q_RFNPCNEX *q_u, prs_struct *ps, int depth)
1631 prs_debug(ps, depth, desc, "spoolss_io_q_rfnpcnex");
1632 depth++;
1634 if(!prs_align(ps))
1635 return False;
1637 if(!smb_io_pol_hnd("printer handle",&q_u->handle,ps,depth))
1638 return False;
1640 if(!prs_uint32("change", ps, depth, &q_u->change))
1641 return False;
1643 if(!prs_uint32("option_ptr", ps, depth, &q_u->option_ptr))
1644 return False;
1646 if (q_u->option_ptr!=0) {
1648 if (UNMARSHALLING(ps))
1649 if((q_u->option=(SPOOL_NOTIFY_OPTION *)prs_alloc_mem(ps,sizeof(SPOOL_NOTIFY_OPTION))) == NULL)
1650 return False;
1652 if(!smb_io_notify_option("notify option", q_u->option, ps, depth))
1653 return False;
1656 return True;
1659 /*******************************************************************
1660 * write a structure.
1661 * called from spoolss_r_rfnpcnex (srv_spoolss.c)
1662 ********************************************************************/
1664 BOOL spoolss_io_r_rfnpcnex(char *desc, SPOOL_R_RFNPCNEX *r_u, prs_struct *ps, int depth)
1666 prs_debug(ps, depth, desc, "spoolss_io_r_rfnpcnex");
1667 depth++;
1669 if(!prs_align(ps))
1670 return False;
1672 if (!prs_uint32("info_ptr", ps, depth, &r_u->info_ptr))
1673 return False;
1675 if(!smb_io_notify_info("notify info", &r_u->info ,ps,depth))
1676 return False;
1678 if(!prs_align(ps))
1679 return False;
1680 if(!prs_werror("status", ps, depth, &r_u->status))
1681 return False;
1683 return True;
1686 /*******************************************************************
1687 * return the length of a uint16 (obvious, but the code is clean)
1688 ********************************************************************/
1690 static uint32 size_of_uint16(uint16 *value)
1692 return (sizeof(*value));
1695 /*******************************************************************
1696 * return the length of a uint32 (obvious, but the code is clean)
1697 ********************************************************************/
1699 static uint32 size_of_uint32(uint32 *value)
1701 return (sizeof(*value));
1704 /*******************************************************************
1705 * return the length of a NTTIME (obvious, but the code is clean)
1706 ********************************************************************/
1708 static uint32 size_of_nttime(NTTIME *value)
1710 return (sizeof(*value));
1713 /*******************************************************************
1714 * return the length of a UNICODE string in number of char, includes:
1715 * - the leading zero
1716 * - the relative pointer size
1717 ********************************************************************/
1719 static uint32 size_of_relative_string(UNISTR *string)
1721 uint32 size=0;
1723 size=str_len_uni(string); /* the string length */
1724 size=size+1; /* add the trailing zero */
1725 size=size*2; /* convert in char */
1726 size=size+4; /* add the size of the ptr */
1728 #if 0 /* JERRY */
1730 * Do not include alignment as Win2k does not align relative
1731 * strings within a buffer --jerry
1733 /* Ensure size is 4 byte multiple (prs_align is being called...). */
1734 /* size += ((4 - (size & 3)) & 3); */
1735 #endif
1737 return size;
1740 /*******************************************************************
1741 * return the length of a uint32 (obvious, but the code is clean)
1742 ********************************************************************/
1744 static uint32 size_of_device_mode(DEVICEMODE *devmode)
1746 if (devmode==NULL)
1747 return (4);
1748 else
1749 return (4+devmode->size+devmode->driverextra);
1752 /*******************************************************************
1753 * return the length of a uint32 (obvious, but the code is clean)
1754 ********************************************************************/
1756 static uint32 size_of_systemtime(SYSTEMTIME *systime)
1758 if (systime==NULL)
1759 return (4);
1760 else
1761 return (sizeof(SYSTEMTIME) +4);
1764 /*******************************************************************
1765 * write a UNICODE string and its relative pointer.
1766 * used by all the RPC structs passing a buffer
1768 * As I'm a nice guy, I'm forcing myself to explain this code.
1769 * MS did a good job in the overall spoolss code except in some
1770 * functions where they are passing the API buffer directly in the
1771 * RPC request/reply. That's to maintain compatiility at the API level.
1772 * They could have done it the good way the first time.
1774 * So what happen is: the strings are written at the buffer's end,
1775 * in the reverse order of the original structure. Some pointers to
1776 * the strings are also in the buffer. Those are relative to the
1777 * buffer's start.
1779 * If you don't understand or want to change that function,
1780 * first get in touch with me: jfm@samba.org
1782 ********************************************************************/
1784 static BOOL smb_io_relstr(char *desc, NEW_BUFFER *buffer, int depth, UNISTR *string)
1786 prs_struct *ps=&buffer->prs;
1788 if (MARSHALLING(ps)) {
1789 uint32 struct_offset = prs_offset(ps);
1790 uint32 relative_offset;
1792 buffer->string_at_end -= (size_of_relative_string(string) - 4);
1793 if(!prs_set_offset(ps, buffer->string_at_end))
1794 return False;
1795 #if 0 /* JERRY */
1797 * Win2k does not align strings in a buffer
1798 * Tested against WinNT 4.0 SP 6a & 2k SP2 --jerry
1800 if (!prs_align(ps))
1801 return False;
1802 #endif
1803 buffer->string_at_end = prs_offset(ps);
1805 /* write the string */
1806 if (!smb_io_unistr(desc, string, ps, depth))
1807 return False;
1809 if(!prs_set_offset(ps, struct_offset))
1810 return False;
1812 relative_offset=buffer->string_at_end - buffer->struct_start;
1813 /* write its offset */
1814 if (!prs_uint32("offset", ps, depth, &relative_offset))
1815 return False;
1817 else {
1818 uint32 old_offset;
1820 /* read the offset */
1821 if (!prs_uint32("offset", ps, depth, &(buffer->string_at_end)))
1822 return False;
1824 old_offset = prs_offset(ps);
1825 if(!prs_set_offset(ps, buffer->string_at_end+buffer->struct_start))
1826 return False;
1828 /* read the string */
1829 if (!smb_io_unistr(desc, string, ps, depth))
1830 return False;
1832 if(!prs_set_offset(ps, old_offset))
1833 return False;
1835 return True;
1838 /*******************************************************************
1839 * write a array of UNICODE strings and its relative pointer.
1840 * used by 2 RPC structs
1841 ********************************************************************/
1843 static BOOL smb_io_relarraystr(char *desc, NEW_BUFFER *buffer, int depth, uint16 **string)
1845 UNISTR chaine;
1847 prs_struct *ps=&buffer->prs;
1849 if (MARSHALLING(ps)) {
1850 uint32 struct_offset = prs_offset(ps);
1851 uint32 relative_offset;
1852 uint16 *p;
1853 uint16 *q;
1854 uint16 zero=0;
1855 p=*string;
1856 q=*string;
1858 /* first write the last 0 */
1859 buffer->string_at_end -= 2;
1860 if(!prs_set_offset(ps, buffer->string_at_end))
1861 return False;
1863 if(!prs_uint16("leading zero", ps, depth, &zero))
1864 return False;
1866 while (p && (*p!=0)) {
1867 while (*q!=0)
1868 q++;
1870 /* Yes this should be malloc not talloc. Don't change. */
1872 chaine.buffer = malloc((q-p+1)*sizeof(uint16));
1873 if (chaine.buffer == NULL)
1874 return False;
1876 memcpy(chaine.buffer, p, (q-p+1)*sizeof(uint16));
1878 buffer->string_at_end -= (q-p+1)*sizeof(uint16);
1880 if(!prs_set_offset(ps, buffer->string_at_end)) {
1881 SAFE_FREE(chaine.buffer);
1882 return False;
1885 /* write the string */
1886 if (!smb_io_unistr(desc, &chaine, ps, depth)) {
1887 SAFE_FREE(chaine.buffer);
1888 return False;
1890 q++;
1891 p=q;
1893 SAFE_FREE(chaine.buffer);
1896 if(!prs_set_offset(ps, struct_offset))
1897 return False;
1899 relative_offset=buffer->string_at_end - buffer->struct_start;
1900 /* write its offset */
1901 if (!prs_uint32("offset", ps, depth, &relative_offset))
1902 return False;
1904 } else {
1906 /* UNMARSHALLING */
1908 uint32 old_offset;
1909 uint16 *chaine2=NULL;
1910 int l_chaine=0;
1911 int l_chaine2=0;
1912 size_t realloc_size = 0;
1914 *string=NULL;
1916 /* read the offset */
1917 if (!prs_uint32("offset", ps, depth, &buffer->string_at_end))
1918 return False;
1920 old_offset = prs_offset(ps);
1921 if(!prs_set_offset(ps, buffer->string_at_end + buffer->struct_start))
1922 return False;
1924 do {
1925 if (!smb_io_unistr(desc, &chaine, ps, depth))
1926 return False;
1928 l_chaine=str_len_uni(&chaine);
1930 /* we're going to add two more bytes here in case this
1931 is the last string in the array and we need to add
1932 an extra NULL for termination */
1933 if (l_chaine > 0)
1935 uint16 *tc2;
1937 realloc_size = (l_chaine2+l_chaine+2)*sizeof(uint16);
1939 /* Yes this should be realloc - it's freed below. JRA */
1941 if((tc2=(uint16 *)Realloc(chaine2, realloc_size)) == NULL) {
1942 SAFE_FREE(chaine2);
1943 return False;
1945 else chaine2 = tc2;
1946 memcpy(chaine2+l_chaine2, chaine.buffer, (l_chaine+1)*sizeof(uint16));
1947 l_chaine2+=l_chaine+1;
1950 } while(l_chaine!=0);
1952 /* the end should be bould NULL terminated so add
1953 the second one here */
1954 if (chaine2)
1956 chaine2[l_chaine2] = '\0';
1957 *string=(uint16 *)talloc_memdup(prs_get_mem_context(ps),chaine2,realloc_size);
1958 SAFE_FREE(chaine2);
1961 if(!prs_set_offset(ps, old_offset))
1962 return False;
1964 return True;
1967 /*******************************************************************
1968 Parse a DEVMODE structure and its relative pointer.
1969 ********************************************************************/
1971 static BOOL smb_io_relsecdesc(char *desc, NEW_BUFFER *buffer, int depth, SEC_DESC **secdesc)
1973 prs_struct *ps= &buffer->prs;
1975 prs_debug(ps, depth, desc, "smb_io_relsecdesc");
1976 depth++;
1978 if (MARSHALLING(ps)) {
1979 uint32 struct_offset = prs_offset(ps);
1980 uint32 relative_offset;
1982 if (! *secdesc) {
1983 relative_offset = 0;
1984 if (!prs_uint32("offset", ps, depth, &relative_offset))
1985 return False;
1986 return True;
1989 if (*secdesc != NULL) {
1990 buffer->string_at_end -= sec_desc_size(*secdesc);
1992 if(!prs_set_offset(ps, buffer->string_at_end))
1993 return False;
1994 /* write the secdesc */
1995 if (!sec_io_desc(desc, secdesc, ps, depth))
1996 return False;
1998 if(!prs_set_offset(ps, struct_offset))
1999 return False;
2002 relative_offset=buffer->string_at_end - buffer->struct_start;
2003 /* write its offset */
2005 if (!prs_uint32("offset", ps, depth, &relative_offset))
2006 return False;
2007 } else {
2008 uint32 old_offset;
2010 /* read the offset */
2011 if (!prs_uint32("offset", ps, depth, &buffer->string_at_end))
2012 return False;
2014 old_offset = prs_offset(ps);
2015 if(!prs_set_offset(ps, buffer->string_at_end + buffer->struct_start))
2016 return False;
2018 /* read the sd */
2019 if (!sec_io_desc(desc, secdesc, ps, depth))
2020 return False;
2022 if(!prs_set_offset(ps, old_offset))
2023 return False;
2025 return True;
2028 /*******************************************************************
2029 Parse a DEVMODE structure and its relative pointer.
2030 ********************************************************************/
2032 static BOOL smb_io_reldevmode(char *desc, NEW_BUFFER *buffer, int depth, DEVICEMODE **devmode)
2034 prs_struct *ps=&buffer->prs;
2036 prs_debug(ps, depth, desc, "smb_io_reldevmode");
2037 depth++;
2039 if (MARSHALLING(ps)) {
2040 uint32 struct_offset = prs_offset(ps);
2041 uint32 relative_offset;
2043 if (*devmode == NULL) {
2044 relative_offset=0;
2045 if (!prs_uint32("offset", ps, depth, &relative_offset))
2046 return False;
2047 DEBUG(8, ("boing, the devmode was NULL\n"));
2049 return True;
2052 buffer->string_at_end -= ((*devmode)->size + (*devmode)->driverextra);
2054 if(!prs_set_offset(ps, buffer->string_at_end))
2055 return False;
2057 /* write the DEVMODE */
2058 if (!spoolss_io_devmode(desc, ps, depth, *devmode))
2059 return False;
2061 if(!prs_set_offset(ps, struct_offset))
2062 return False;
2064 relative_offset=buffer->string_at_end - buffer->struct_start;
2065 /* write its offset */
2066 if (!prs_uint32("offset", ps, depth, &relative_offset))
2067 return False;
2069 else {
2070 uint32 old_offset;
2072 /* read the offset */
2073 if (!prs_uint32("offset", ps, depth, &buffer->string_at_end))
2074 return False;
2076 old_offset = prs_offset(ps);
2077 if(!prs_set_offset(ps, buffer->string_at_end + buffer->struct_start))
2078 return False;
2080 /* read the string */
2081 if((*devmode=(DEVICEMODE *)prs_alloc_mem(ps,sizeof(DEVICEMODE))) == NULL)
2082 return False;
2083 if (!spoolss_io_devmode(desc, ps, depth, *devmode))
2084 return False;
2086 if(!prs_set_offset(ps, old_offset))
2087 return False;
2089 return True;
2092 /*******************************************************************
2093 Parse a PRINTER_INFO_0 structure.
2094 ********************************************************************/
2096 BOOL smb_io_printer_info_0(char *desc, NEW_BUFFER *buffer, PRINTER_INFO_0 *info, int depth)
2098 prs_struct *ps=&buffer->prs;
2100 prs_debug(ps, depth, desc, "smb_io_printer_info_0");
2101 depth++;
2103 buffer->struct_start=prs_offset(ps);
2105 if (!smb_io_relstr("printername", buffer, depth, &info->printername))
2106 return False;
2107 if (!smb_io_relstr("servername", buffer, depth, &info->servername))
2108 return False;
2110 if(!prs_uint32("cjobs", ps, depth, &info->cjobs))
2111 return False;
2112 if(!prs_uint32("total_jobs", ps, depth, &info->total_jobs))
2113 return False;
2114 if(!prs_uint32("total_bytes", ps, depth, &info->total_bytes))
2115 return False;
2117 if(!prs_uint16("year", ps, depth, &info->year))
2118 return False;
2119 if(!prs_uint16("month", ps, depth, &info->month))
2120 return False;
2121 if(!prs_uint16("dayofweek", ps, depth, &info->dayofweek))
2122 return False;
2123 if(!prs_uint16("day", ps, depth, &info->day))
2124 return False;
2125 if(!prs_uint16("hour", ps, depth, &info->hour))
2126 return False;
2127 if(!prs_uint16("minute", ps, depth, &info->minute))
2128 return False;
2129 if(!prs_uint16("second", ps, depth, &info->second))
2130 return False;
2131 if(!prs_uint16("milliseconds", ps, depth, &info->milliseconds))
2132 return False;
2134 if(!prs_uint32("global_counter", ps, depth, &info->global_counter))
2135 return False;
2136 if(!prs_uint32("total_pages", ps, depth, &info->total_pages))
2137 return False;
2139 if(!prs_uint16("major_version", ps, depth, &info->major_version))
2140 return False;
2141 if(!prs_uint16("build_version", ps, depth, &info->build_version))
2142 return False;
2143 if(!prs_uint32("unknown7", ps, depth, &info->unknown7))
2144 return False;
2145 if(!prs_uint32("unknown8", ps, depth, &info->unknown8))
2146 return False;
2147 if(!prs_uint32("unknown9", ps, depth, &info->unknown9))
2148 return False;
2149 if(!prs_uint32("session_counter", ps, depth, &info->session_counter))
2150 return False;
2151 if(!prs_uint32("unknown11", ps, depth, &info->unknown11))
2152 return False;
2153 if(!prs_uint32("printer_errors", ps, depth, &info->printer_errors))
2154 return False;
2155 if(!prs_uint32("unknown13", ps, depth, &info->unknown13))
2156 return False;
2157 if(!prs_uint32("unknown14", ps, depth, &info->unknown14))
2158 return False;
2159 if(!prs_uint32("unknown15", ps, depth, &info->unknown15))
2160 return False;
2161 if(!prs_uint32("unknown16", ps, depth, &info->unknown16))
2162 return False;
2163 if(!prs_uint32("change_id", ps, depth, &info->change_id))
2164 return False;
2165 if(!prs_uint32("unknown18", ps, depth, &info->unknown18))
2166 return False;
2167 if(!prs_uint32("status" , ps, depth, &info->status))
2168 return False;
2169 if(!prs_uint32("unknown20", ps, depth, &info->unknown20))
2170 return False;
2171 if(!prs_uint32("c_setprinter", ps, depth, &info->c_setprinter))
2172 return False;
2173 if(!prs_uint16("unknown22", ps, depth, &info->unknown22))
2174 return False;
2175 if(!prs_uint16("unknown23", ps, depth, &info->unknown23))
2176 return False;
2177 if(!prs_uint16("unknown24", ps, depth, &info->unknown24))
2178 return False;
2179 if(!prs_uint16("unknown25", ps, depth, &info->unknown25))
2180 return False;
2181 if(!prs_uint16("unknown26", ps, depth, &info->unknown26))
2182 return False;
2183 if(!prs_uint16("unknown27", ps, depth, &info->unknown27))
2184 return False;
2185 if(!prs_uint16("unknown28", ps, depth, &info->unknown28))
2186 return False;
2187 if(!prs_uint16("unknown29", ps, depth, &info->unknown29))
2188 return False;
2190 return True;
2193 /*******************************************************************
2194 Parse a PRINTER_INFO_1 structure.
2195 ********************************************************************/
2197 BOOL smb_io_printer_info_1(char *desc, NEW_BUFFER *buffer, PRINTER_INFO_1 *info, int depth)
2199 prs_struct *ps=&buffer->prs;
2201 prs_debug(ps, depth, desc, "smb_io_printer_info_1");
2202 depth++;
2204 buffer->struct_start=prs_offset(ps);
2206 if (!prs_uint32("flags", ps, depth, &info->flags))
2207 return False;
2208 if (!smb_io_relstr("description", buffer, depth, &info->description))
2209 return False;
2210 if (!smb_io_relstr("name", buffer, depth, &info->name))
2211 return False;
2212 if (!smb_io_relstr("comment", buffer, depth, &info->comment))
2213 return False;
2215 return True;
2218 /*******************************************************************
2219 Parse a PRINTER_INFO_2 structure.
2220 ********************************************************************/
2222 BOOL smb_io_printer_info_2(char *desc, NEW_BUFFER *buffer, PRINTER_INFO_2 *info, int depth)
2224 prs_struct *ps=&buffer->prs;
2226 prs_debug(ps, depth, desc, "smb_io_printer_info_2");
2227 depth++;
2229 buffer->struct_start=prs_offset(ps);
2231 if (!smb_io_relstr("servername", buffer, depth, &info->servername))
2232 return False;
2233 if (!smb_io_relstr("printername", buffer, depth, &info->printername))
2234 return False;
2235 if (!smb_io_relstr("sharename", buffer, depth, &info->sharename))
2236 return False;
2237 if (!smb_io_relstr("portname", buffer, depth, &info->portname))
2238 return False;
2239 if (!smb_io_relstr("drivername", buffer, depth, &info->drivername))
2240 return False;
2241 if (!smb_io_relstr("comment", buffer, depth, &info->comment))
2242 return False;
2243 if (!smb_io_relstr("location", buffer, depth, &info->location))
2244 return False;
2246 /* NT parses the DEVMODE at the end of the struct */
2247 if (!smb_io_reldevmode("devmode", buffer, depth, &info->devmode))
2248 return False;
2250 if (!smb_io_relstr("sepfile", buffer, depth, &info->sepfile))
2251 return False;
2252 if (!smb_io_relstr("printprocessor", buffer, depth, &info->printprocessor))
2253 return False;
2254 if (!smb_io_relstr("datatype", buffer, depth, &info->datatype))
2255 return False;
2256 if (!smb_io_relstr("parameters", buffer, depth, &info->parameters))
2257 return False;
2259 if (!smb_io_relsecdesc("secdesc", buffer, depth, &info->secdesc))
2260 return False;
2262 if (!prs_uint32("attributes", ps, depth, &info->attributes))
2263 return False;
2264 if (!prs_uint32("priority", ps, depth, &info->priority))
2265 return False;
2266 if (!prs_uint32("defpriority", ps, depth, &info->defaultpriority))
2267 return False;
2268 if (!prs_uint32("starttime", ps, depth, &info->starttime))
2269 return False;
2270 if (!prs_uint32("untiltime", ps, depth, &info->untiltime))
2271 return False;
2272 if (!prs_uint32("status", ps, depth, &info->status))
2273 return False;
2274 if (!prs_uint32("jobs", ps, depth, &info->cjobs))
2275 return False;
2276 if (!prs_uint32("averageppm", ps, depth, &info->averageppm))
2277 return False;
2279 #if 0 /* JFMTEST */
2280 if (!prs_uint32_post("secdesc_ptr", ps, depth, NULL, sec_offset, info->secdesc ? prs_offset(ps)-buffer->struct_start : 0 ))
2281 return False;
2283 if (!sec_io_desc("secdesc", &info->secdesc, ps, depth))
2284 return False;
2285 #endif
2286 return True;
2289 /*******************************************************************
2290 Parse a PRINTER_INFO_3 structure.
2291 ********************************************************************/
2293 BOOL smb_io_printer_info_3(char *desc, NEW_BUFFER *buffer, PRINTER_INFO_3 *info, int depth)
2295 prs_struct *ps=&buffer->prs;
2297 prs_debug(ps, depth, desc, "smb_io_printer_info_3");
2298 depth++;
2300 buffer->struct_start=prs_offset(ps);
2302 if (!prs_uint32("flags", ps, depth, &info->flags))
2303 return False;
2304 if (!sec_io_desc("sec_desc", &info->secdesc, ps, depth))
2305 return False;
2307 return True;
2310 /*******************************************************************
2311 Parse a PRINTER_INFO_4 structure.
2312 ********************************************************************/
2314 BOOL smb_io_printer_info_4(char *desc, NEW_BUFFER *buffer, PRINTER_INFO_4 *info, int depth)
2316 prs_struct *ps=&buffer->prs;
2318 prs_debug(ps, depth, desc, "smb_io_printer_info_4");
2319 depth++;
2321 buffer->struct_start=prs_offset(ps);
2323 if (!smb_io_relstr("printername", buffer, depth, &info->printername))
2324 return False;
2325 if (!smb_io_relstr("servername", buffer, depth, &info->servername))
2326 return False;
2327 if (!prs_uint32("attributes", ps, depth, &info->attributes))
2328 return False;
2329 return True;
2332 /*******************************************************************
2333 Parse a PRINTER_INFO_5 structure.
2334 ********************************************************************/
2336 BOOL smb_io_printer_info_5(char *desc, NEW_BUFFER *buffer, PRINTER_INFO_5 *info, int depth)
2338 prs_struct *ps=&buffer->prs;
2340 prs_debug(ps, depth, desc, "smb_io_printer_info_5");
2341 depth++;
2343 buffer->struct_start=prs_offset(ps);
2345 if (!smb_io_relstr("printername", buffer, depth, &info->printername))
2346 return False;
2347 if (!smb_io_relstr("portname", buffer, depth, &info->portname))
2348 return False;
2349 if (!prs_uint32("attributes", ps, depth, &info->attributes))
2350 return False;
2351 if (!prs_uint32("device_not_selected_timeout", ps, depth, &info->device_not_selected_timeout))
2352 return False;
2353 if (!prs_uint32("transmission_retry_timeout", ps, depth, &info->transmission_retry_timeout))
2354 return False;
2355 return True;
2358 /*******************************************************************
2359 Parse a PORT_INFO_1 structure.
2360 ********************************************************************/
2362 BOOL smb_io_port_info_1(char *desc, NEW_BUFFER *buffer, PORT_INFO_1 *info, int depth)
2364 prs_struct *ps=&buffer->prs;
2366 prs_debug(ps, depth, desc, "smb_io_port_info_1");
2367 depth++;
2369 buffer->struct_start=prs_offset(ps);
2371 if (!smb_io_relstr("port_name", buffer, depth, &info->port_name))
2372 return False;
2374 return True;
2377 /*******************************************************************
2378 Parse a PORT_INFO_2 structure.
2379 ********************************************************************/
2381 BOOL smb_io_port_info_2(char *desc, NEW_BUFFER *buffer, PORT_INFO_2 *info, int depth)
2383 prs_struct *ps=&buffer->prs;
2385 prs_debug(ps, depth, desc, "smb_io_port_info_2");
2386 depth++;
2388 buffer->struct_start=prs_offset(ps);
2390 if (!smb_io_relstr("port_name", buffer, depth, &info->port_name))
2391 return False;
2392 if (!smb_io_relstr("monitor_name", buffer, depth, &info->monitor_name))
2393 return False;
2394 if (!smb_io_relstr("description", buffer, depth, &info->description))
2395 return False;
2396 if (!prs_uint32("port_type", ps, depth, &info->port_type))
2397 return False;
2398 if (!prs_uint32("reserved", ps, depth, &info->reserved))
2399 return False;
2401 return True;
2404 /*******************************************************************
2405 Parse a DRIVER_INFO_1 structure.
2406 ********************************************************************/
2408 BOOL smb_io_printer_driver_info_1(char *desc, NEW_BUFFER *buffer, DRIVER_INFO_1 *info, int depth)
2410 prs_struct *ps=&buffer->prs;
2412 prs_debug(ps, depth, desc, "smb_io_printer_driver_info_1");
2413 depth++;
2415 buffer->struct_start=prs_offset(ps);
2417 if (!smb_io_relstr("name", buffer, depth, &info->name))
2418 return False;
2420 return True;
2423 /*******************************************************************
2424 Parse a DRIVER_INFO_2 structure.
2425 ********************************************************************/
2427 BOOL smb_io_printer_driver_info_2(char *desc, NEW_BUFFER *buffer, DRIVER_INFO_2 *info, int depth)
2429 prs_struct *ps=&buffer->prs;
2431 prs_debug(ps, depth, desc, "smb_io_printer_driver_info_2");
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;
2449 return True;
2452 /*******************************************************************
2453 Parse a DRIVER_INFO_3 structure.
2454 ********************************************************************/
2456 BOOL smb_io_printer_driver_info_3(char *desc, NEW_BUFFER *buffer, DRIVER_INFO_3 *info, int depth)
2458 prs_struct *ps=&buffer->prs;
2460 prs_debug(ps, depth, desc, "smb_io_printer_driver_info_3");
2461 depth++;
2463 buffer->struct_start=prs_offset(ps);
2465 if (!prs_uint32("version", ps, depth, &info->version))
2466 return False;
2467 if (!smb_io_relstr("name", buffer, depth, &info->name))
2468 return False;
2469 if (!smb_io_relstr("architecture", buffer, depth, &info->architecture))
2470 return False;
2471 if (!smb_io_relstr("driverpath", buffer, depth, &info->driverpath))
2472 return False;
2473 if (!smb_io_relstr("datafile", buffer, depth, &info->datafile))
2474 return False;
2475 if (!smb_io_relstr("configfile", buffer, depth, &info->configfile))
2476 return False;
2477 if (!smb_io_relstr("helpfile", buffer, depth, &info->helpfile))
2478 return False;
2480 if (!smb_io_relarraystr("dependentfiles", buffer, depth, &info->dependentfiles))
2481 return False;
2483 if (!smb_io_relstr("monitorname", buffer, depth, &info->monitorname))
2484 return False;
2485 if (!smb_io_relstr("defaultdatatype", buffer, depth, &info->defaultdatatype))
2486 return False;
2488 return True;
2491 /*******************************************************************
2492 Parse a DRIVER_INFO_6 structure.
2493 ********************************************************************/
2495 BOOL smb_io_printer_driver_info_6(char *desc, NEW_BUFFER *buffer, DRIVER_INFO_6 *info, int depth)
2497 prs_struct *ps=&buffer->prs;
2499 prs_debug(ps, depth, desc, "smb_io_printer_driver_info_6");
2500 depth++;
2502 buffer->struct_start=prs_offset(ps);
2504 if (!prs_uint32("version", ps, depth, &info->version))
2505 return False;
2506 if (!smb_io_relstr("name", buffer, depth, &info->name))
2507 return False;
2508 if (!smb_io_relstr("architecture", buffer, depth, &info->architecture))
2509 return False;
2510 if (!smb_io_relstr("driverpath", buffer, depth, &info->driverpath))
2511 return False;
2512 if (!smb_io_relstr("datafile", buffer, depth, &info->datafile))
2513 return False;
2514 if (!smb_io_relstr("configfile", buffer, depth, &info->configfile))
2515 return False;
2516 if (!smb_io_relstr("helpfile", buffer, depth, &info->helpfile))
2517 return False;
2519 if (!smb_io_relarraystr("dependentfiles", buffer, depth, &info->dependentfiles))
2520 return False;
2522 if (!smb_io_relstr("monitorname", buffer, depth, &info->monitorname))
2523 return False;
2524 if (!smb_io_relstr("defaultdatatype", buffer, depth, &info->defaultdatatype))
2525 return False;
2527 if (!smb_io_relarraystr("previousdrivernames", buffer, depth, &info->previousdrivernames))
2528 return False;
2530 if (!prs_uint32("date.low", ps, depth, &info->driver_date.low))
2531 return False;
2532 if (!prs_uint32("date.high", ps, depth, &info->driver_date.high))
2533 return False;
2535 if (!prs_uint32("padding", ps, depth, &info->padding))
2536 return False;
2538 if (!prs_uint32("driver_version_low", ps, depth, &info->driver_version_low))
2539 return False;
2541 if (!prs_uint32("driver_version_high", ps, depth, &info->driver_version_high))
2542 return False;
2544 if (!smb_io_relstr("mfgname", buffer, depth, &info->mfgname))
2545 return False;
2546 if (!smb_io_relstr("oem_url", buffer, depth, &info->oem_url))
2547 return False;
2548 if (!smb_io_relstr("hardware_id", buffer, depth, &info->hardware_id))
2549 return False;
2550 if (!smb_io_relstr("provider", buffer, depth, &info->provider))
2551 return False;
2553 return True;
2556 /*******************************************************************
2557 Parse a JOB_INFO_1 structure.
2558 ********************************************************************/
2560 BOOL smb_io_job_info_1(char *desc, NEW_BUFFER *buffer, JOB_INFO_1 *info, int depth)
2562 prs_struct *ps=&buffer->prs;
2564 prs_debug(ps, depth, desc, "smb_io_job_info_1");
2565 depth++;
2567 buffer->struct_start=prs_offset(ps);
2569 if (!prs_uint32("jobid", ps, depth, &info->jobid))
2570 return False;
2571 if (!smb_io_relstr("printername", buffer, depth, &info->printername))
2572 return False;
2573 if (!smb_io_relstr("machinename", buffer, depth, &info->machinename))
2574 return False;
2575 if (!smb_io_relstr("username", buffer, depth, &info->username))
2576 return False;
2577 if (!smb_io_relstr("document", buffer, depth, &info->document))
2578 return False;
2579 if (!smb_io_relstr("datatype", buffer, depth, &info->datatype))
2580 return False;
2581 if (!smb_io_relstr("text_status", buffer, depth, &info->text_status))
2582 return False;
2583 if (!prs_uint32("status", ps, depth, &info->status))
2584 return False;
2585 if (!prs_uint32("priority", ps, depth, &info->priority))
2586 return False;
2587 if (!prs_uint32("position", ps, depth, &info->position))
2588 return False;
2589 if (!prs_uint32("totalpages", ps, depth, &info->totalpages))
2590 return False;
2591 if (!prs_uint32("pagesprinted", ps, depth, &info->pagesprinted))
2592 return False;
2593 if (!spoolss_io_system_time("submitted", ps, depth, &info->submitted))
2594 return False;
2596 return True;
2599 /*******************************************************************
2600 Parse a JOB_INFO_2 structure.
2601 ********************************************************************/
2603 BOOL smb_io_job_info_2(char *desc, NEW_BUFFER *buffer, JOB_INFO_2 *info, int depth)
2605 uint32 pipo=0;
2606 prs_struct *ps=&buffer->prs;
2608 prs_debug(ps, depth, desc, "smb_io_job_info_2");
2609 depth++;
2611 buffer->struct_start=prs_offset(ps);
2613 if (!prs_uint32("jobid",ps, depth, &info->jobid))
2614 return False;
2615 if (!smb_io_relstr("printername", buffer, depth, &info->printername))
2616 return False;
2617 if (!smb_io_relstr("machinename", buffer, depth, &info->machinename))
2618 return False;
2619 if (!smb_io_relstr("username", buffer, depth, &info->username))
2620 return False;
2621 if (!smb_io_relstr("document", buffer, depth, &info->document))
2622 return False;
2623 if (!smb_io_relstr("notifyname", buffer, depth, &info->notifyname))
2624 return False;
2625 if (!smb_io_relstr("datatype", buffer, depth, &info->datatype))
2626 return False;
2628 if (!smb_io_relstr("printprocessor", buffer, depth, &info->printprocessor))
2629 return False;
2630 if (!smb_io_relstr("parameters", buffer, depth, &info->parameters))
2631 return False;
2632 if (!smb_io_relstr("drivername", buffer, depth, &info->drivername))
2633 return False;
2634 if (!smb_io_reldevmode("devmode", buffer, depth, &info->devmode))
2635 return False;
2636 if (!smb_io_relstr("text_status", buffer, depth, &info->text_status))
2637 return False;
2639 /* SEC_DESC sec_desc;*/
2640 if (!prs_uint32("Hack! sec desc", ps, depth, &pipo))
2641 return False;
2643 if (!prs_uint32("status",ps, depth, &info->status))
2644 return False;
2645 if (!prs_uint32("priority",ps, depth, &info->priority))
2646 return False;
2647 if (!prs_uint32("position",ps, depth, &info->position))
2648 return False;
2649 if (!prs_uint32("starttime",ps, depth, &info->starttime))
2650 return False;
2651 if (!prs_uint32("untiltime",ps, depth, &info->untiltime))
2652 return False;
2653 if (!prs_uint32("totalpages",ps, depth, &info->totalpages))
2654 return False;
2655 if (!prs_uint32("size",ps, depth, &info->size))
2656 return False;
2657 if (!spoolss_io_system_time("submitted", ps, depth, &info->submitted) )
2658 return False;
2659 if (!prs_uint32("timeelapsed",ps, depth, &info->timeelapsed))
2660 return False;
2661 if (!prs_uint32("pagesprinted",ps, depth, &info->pagesprinted))
2662 return False;
2664 return True;
2667 /*******************************************************************
2668 ********************************************************************/
2670 BOOL smb_io_form_1(char *desc, NEW_BUFFER *buffer, FORM_1 *info, int depth)
2672 prs_struct *ps=&buffer->prs;
2674 prs_debug(ps, depth, desc, "smb_io_form_1");
2675 depth++;
2677 buffer->struct_start=prs_offset(ps);
2679 if (!prs_uint32("flag", ps, depth, &info->flag))
2680 return False;
2682 if (!smb_io_relstr("name", buffer, depth, &info->name))
2683 return False;
2685 if (!prs_uint32("width", ps, depth, &info->width))
2686 return False;
2687 if (!prs_uint32("length", ps, depth, &info->length))
2688 return False;
2689 if (!prs_uint32("left", ps, depth, &info->left))
2690 return False;
2691 if (!prs_uint32("top", ps, depth, &info->top))
2692 return False;
2693 if (!prs_uint32("right", ps, depth, &info->right))
2694 return False;
2695 if (!prs_uint32("bottom", ps, depth, &info->bottom))
2696 return False;
2698 return True;
2701 /*******************************************************************
2702 Read/write a BUFFER struct.
2703 ********************************************************************/
2705 static BOOL spoolss_io_buffer(char *desc, prs_struct *ps, int depth, NEW_BUFFER **pp_buffer)
2707 NEW_BUFFER *buffer = *pp_buffer;
2709 prs_debug(ps, depth, desc, "spoolss_io_buffer");
2710 depth++;
2712 if (UNMARSHALLING(ps))
2713 buffer = *pp_buffer = (NEW_BUFFER *)prs_alloc_mem(ps, sizeof(NEW_BUFFER));
2715 if (buffer == NULL)
2716 return False;
2718 if (!prs_uint32("ptr", ps, depth, &buffer->ptr))
2719 return False;
2721 /* reading */
2722 if (UNMARSHALLING(ps)) {
2723 buffer->size=0;
2724 buffer->string_at_end=0;
2726 if (buffer->ptr==0) {
2728 * JRA. I'm not sure if the data in here is in big-endian format if
2729 * the client is big-endian. Leave as default (little endian) for now.
2732 if (!prs_init(&buffer->prs, 0, prs_get_mem_context(ps), UNMARSHALL))
2733 return False;
2734 return True;
2737 if (!prs_uint32("size", ps, depth, &buffer->size))
2738 return False;
2741 * JRA. I'm not sure if the data in here is in big-endian format if
2742 * the client is big-endian. Leave as default (little endian) for now.
2745 if (!prs_init(&buffer->prs, buffer->size, prs_get_mem_context(ps), UNMARSHALL))
2746 return False;
2748 if (!prs_append_some_prs_data(&buffer->prs, ps, prs_offset(ps), buffer->size))
2749 return False;
2751 if (!prs_set_offset(&buffer->prs, 0))
2752 return False;
2754 if (!prs_set_offset(ps, buffer->size+prs_offset(ps)))
2755 return False;
2757 buffer->string_at_end=buffer->size;
2759 return True;
2761 else {
2762 BOOL ret = False;
2764 /* writing */
2765 if (buffer->ptr==0) {
2766 /* We have finished with the data in buffer->prs - free it. */
2767 prs_mem_free(&buffer->prs);
2768 return True;
2771 if (!prs_uint32("size", ps, depth, &buffer->size))
2772 goto out;
2774 if (!prs_append_some_prs_data(ps, &buffer->prs, 0, buffer->size))
2775 goto out;
2777 ret = True;
2778 out:
2780 /* We have finished with the data in buffer->prs - free it. */
2781 prs_mem_free(&buffer->prs);
2783 return ret;
2787 /*******************************************************************
2788 move a BUFFER from the query to the reply.
2789 As the data pointers in NEW_BUFFER are malloc'ed, not talloc'ed,
2790 this is ok. This is an OPTIMIZATION and is not strictly neccessary.
2791 Clears the memory to zero also.
2792 ********************************************************************/
2794 void spoolss_move_buffer(NEW_BUFFER *src, NEW_BUFFER **dest)
2796 prs_switch_type(&src->prs, MARSHALL);
2797 if(!prs_set_offset(&src->prs, 0))
2798 return;
2799 prs_force_dynamic(&src->prs);
2800 prs_mem_clear(&src->prs);
2801 *dest=src;
2804 /*******************************************************************
2805 Get the size of a BUFFER struct.
2806 ********************************************************************/
2808 uint32 new_get_buffer_size(NEW_BUFFER *buffer)
2810 return (buffer->size);
2813 /*******************************************************************
2814 Parse a DRIVER_DIRECTORY_1 structure.
2815 ********************************************************************/
2817 BOOL smb_io_driverdir_1(char *desc, NEW_BUFFER *buffer, DRIVER_DIRECTORY_1 *info, int depth)
2819 prs_struct *ps=&buffer->prs;
2821 prs_debug(ps, depth, desc, "smb_io_driverdir_1");
2822 depth++;
2824 buffer->struct_start=prs_offset(ps);
2826 if (!smb_io_unistr(desc, &info->name, ps, depth))
2827 return False;
2829 return True;
2832 /*******************************************************************
2833 Parse a PORT_INFO_1 structure.
2834 ********************************************************************/
2836 BOOL smb_io_port_1(char *desc, NEW_BUFFER *buffer, PORT_INFO_1 *info, int depth)
2838 prs_struct *ps=&buffer->prs;
2840 prs_debug(ps, depth, desc, "smb_io_port_1");
2841 depth++;
2843 buffer->struct_start=prs_offset(ps);
2845 if(!smb_io_relstr("port_name", buffer, depth, &info->port_name))
2846 return False;
2848 return True;
2851 /*******************************************************************
2852 Parse a PORT_INFO_2 structure.
2853 ********************************************************************/
2855 BOOL smb_io_port_2(char *desc, NEW_BUFFER *buffer, PORT_INFO_2 *info, int depth)
2857 prs_struct *ps=&buffer->prs;
2859 prs_debug(ps, depth, desc, "smb_io_port_2");
2860 depth++;
2862 buffer->struct_start=prs_offset(ps);
2864 if(!smb_io_relstr("port_name", buffer, depth, &info->port_name))
2865 return False;
2866 if(!smb_io_relstr("monitor_name", buffer, depth, &info->monitor_name))
2867 return False;
2868 if(!smb_io_relstr("description", buffer, depth, &info->description))
2869 return False;
2870 if(!prs_uint32("port_type", ps, depth, &info->port_type))
2871 return False;
2872 if(!prs_uint32("reserved", ps, depth, &info->reserved))
2873 return False;
2875 return True;
2878 /*******************************************************************
2879 ********************************************************************/
2881 BOOL smb_io_printprocessor_info_1(char *desc, NEW_BUFFER *buffer, PRINTPROCESSOR_1 *info, int depth)
2883 prs_struct *ps=&buffer->prs;
2885 prs_debug(ps, depth, desc, "smb_io_printprocessor_info_1");
2886 depth++;
2888 buffer->struct_start=prs_offset(ps);
2890 if (smb_io_relstr("name", buffer, depth, &info->name))
2891 return False;
2893 return True;
2896 /*******************************************************************
2897 ********************************************************************/
2899 BOOL smb_io_printprocdatatype_info_1(char *desc, NEW_BUFFER *buffer, PRINTPROCDATATYPE_1 *info, int depth)
2901 prs_struct *ps=&buffer->prs;
2903 prs_debug(ps, depth, desc, "smb_io_printprocdatatype_info_1");
2904 depth++;
2906 buffer->struct_start=prs_offset(ps);
2908 if (smb_io_relstr("name", buffer, depth, &info->name))
2909 return False;
2911 return True;
2914 /*******************************************************************
2915 ********************************************************************/
2917 BOOL smb_io_printmonitor_info_1(char *desc, NEW_BUFFER *buffer, PRINTMONITOR_1 *info, int depth)
2919 prs_struct *ps=&buffer->prs;
2921 prs_debug(ps, depth, desc, "smb_io_printmonitor_info_1");
2922 depth++;
2924 buffer->struct_start=prs_offset(ps);
2926 if (!smb_io_relstr("name", buffer, depth, &info->name))
2927 return False;
2929 return True;
2932 /*******************************************************************
2933 ********************************************************************/
2935 BOOL smb_io_printmonitor_info_2(char *desc, NEW_BUFFER *buffer, PRINTMONITOR_2 *info, int depth)
2937 prs_struct *ps=&buffer->prs;
2939 prs_debug(ps, depth, desc, "smb_io_printmonitor_info_2");
2940 depth++;
2942 buffer->struct_start=prs_offset(ps);
2944 if (!smb_io_relstr("name", buffer, depth, &info->name))
2945 return False;
2946 if (!smb_io_relstr("environment", buffer, depth, &info->environment))
2947 return False;
2948 if (!smb_io_relstr("dll_name", buffer, depth, &info->dll_name))
2949 return False;
2951 return True;
2954 /*******************************************************************
2955 return the size required by a struct in the stream
2956 ********************************************************************/
2958 uint32 spoolss_size_printer_info_0(PRINTER_INFO_0 *info)
2960 int size=0;
2962 size+=size_of_relative_string( &info->printername );
2963 size+=size_of_relative_string( &info->servername );
2965 size+=size_of_uint32( &info->cjobs);
2966 size+=size_of_uint32( &info->total_jobs);
2967 size+=size_of_uint32( &info->total_bytes);
2969 size+=size_of_uint16( &info->year);
2970 size+=size_of_uint16( &info->month);
2971 size+=size_of_uint16( &info->dayofweek);
2972 size+=size_of_uint16( &info->day);
2973 size+=size_of_uint16( &info->hour);
2974 size+=size_of_uint16( &info->minute);
2975 size+=size_of_uint16( &info->second);
2976 size+=size_of_uint16( &info->milliseconds);
2978 size+=size_of_uint32( &info->global_counter);
2979 size+=size_of_uint32( &info->total_pages);
2981 size+=size_of_uint16( &info->major_version);
2982 size+=size_of_uint16( &info->build_version);
2984 size+=size_of_uint32( &info->unknown7);
2985 size+=size_of_uint32( &info->unknown8);
2986 size+=size_of_uint32( &info->unknown9);
2987 size+=size_of_uint32( &info->session_counter);
2988 size+=size_of_uint32( &info->unknown11);
2989 size+=size_of_uint32( &info->printer_errors);
2990 size+=size_of_uint32( &info->unknown13);
2991 size+=size_of_uint32( &info->unknown14);
2992 size+=size_of_uint32( &info->unknown15);
2993 size+=size_of_uint32( &info->unknown16);
2994 size+=size_of_uint32( &info->change_id);
2995 size+=size_of_uint32( &info->unknown18);
2996 size+=size_of_uint32( &info->status);
2997 size+=size_of_uint32( &info->unknown20);
2998 size+=size_of_uint32( &info->c_setprinter);
3000 size+=size_of_uint16( &info->unknown22);
3001 size+=size_of_uint16( &info->unknown23);
3002 size+=size_of_uint16( &info->unknown24);
3003 size+=size_of_uint16( &info->unknown25);
3004 size+=size_of_uint16( &info->unknown26);
3005 size+=size_of_uint16( &info->unknown27);
3006 size+=size_of_uint16( &info->unknown28);
3007 size+=size_of_uint16( &info->unknown29);
3009 return size;
3012 /*******************************************************************
3013 return the size required by a struct in the stream
3014 ********************************************************************/
3016 uint32 spoolss_size_printer_info_1(PRINTER_INFO_1 *info)
3018 int size=0;
3020 size+=size_of_uint32( &info->flags );
3021 size+=size_of_relative_string( &info->description );
3022 size+=size_of_relative_string( &info->name );
3023 size+=size_of_relative_string( &info->comment );
3025 return size;
3028 /*******************************************************************
3029 return the size required by a struct in the stream
3030 ********************************************************************/
3032 uint32 spoolss_size_printer_info_2(PRINTER_INFO_2 *info)
3034 uint32 size=0;
3036 size += 4;
3037 /* JRA !!!! TESTME - WHAT ABOUT prs_align.... !!! */
3038 size += sec_desc_size( info->secdesc );
3040 size+=size_of_device_mode( info->devmode );
3042 size+=size_of_relative_string( &info->servername );
3043 size+=size_of_relative_string( &info->printername );
3044 size+=size_of_relative_string( &info->sharename );
3045 size+=size_of_relative_string( &info->portname );
3046 size+=size_of_relative_string( &info->drivername );
3047 size+=size_of_relative_string( &info->comment );
3048 size+=size_of_relative_string( &info->location );
3050 size+=size_of_relative_string( &info->sepfile );
3051 size+=size_of_relative_string( &info->printprocessor );
3052 size+=size_of_relative_string( &info->datatype );
3053 size+=size_of_relative_string( &info->parameters );
3055 size+=size_of_uint32( &info->attributes );
3056 size+=size_of_uint32( &info->priority );
3057 size+=size_of_uint32( &info->defaultpriority );
3058 size+=size_of_uint32( &info->starttime );
3059 size+=size_of_uint32( &info->untiltime );
3060 size+=size_of_uint32( &info->status );
3061 size+=size_of_uint32( &info->cjobs );
3062 size+=size_of_uint32( &info->averageppm );
3063 return size;
3066 /*******************************************************************
3067 return the size required by a struct in the stream
3068 ********************************************************************/
3070 uint32 spoolss_size_printer_info_4(PRINTER_INFO_4 *info)
3072 uint32 size=0;
3074 size+=size_of_relative_string( &info->printername );
3075 size+=size_of_relative_string( &info->servername );
3077 size+=size_of_uint32( &info->attributes );
3078 return size;
3081 /*******************************************************************
3082 return the size required by a struct in the stream
3083 ********************************************************************/
3085 uint32 spoolss_size_printer_info_5(PRINTER_INFO_5 *info)
3087 uint32 size=0;
3089 size+=size_of_relative_string( &info->printername );
3090 size+=size_of_relative_string( &info->portname );
3092 size+=size_of_uint32( &info->attributes );
3093 size+=size_of_uint32( &info->device_not_selected_timeout );
3094 size+=size_of_uint32( &info->transmission_retry_timeout );
3095 return size;
3099 /*******************************************************************
3100 return the size required by a struct in the stream
3101 ********************************************************************/
3103 uint32 spoolss_size_printer_info_3(PRINTER_INFO_3 *info)
3105 /* The 4 is for the self relative pointer.. */
3106 /* JRA !!!! TESTME - WHAT ABOUT prs_align.... !!! */
3107 return 4 + (uint32)sec_desc_size( info->secdesc );
3110 /*******************************************************************
3111 return the size required by a struct in the stream
3112 ********************************************************************/
3114 uint32 spoolss_size_printer_driver_info_1(DRIVER_INFO_1 *info)
3116 int size=0;
3117 size+=size_of_relative_string( &info->name );
3119 return size;
3122 /*******************************************************************
3123 return the size required by a struct in the stream
3124 ********************************************************************/
3126 uint32 spoolss_size_printer_driver_info_2(DRIVER_INFO_2 *info)
3128 int size=0;
3129 size+=size_of_uint32( &info->version );
3130 size+=size_of_relative_string( &info->name );
3131 size+=size_of_relative_string( &info->architecture );
3132 size+=size_of_relative_string( &info->driverpath );
3133 size+=size_of_relative_string( &info->datafile );
3134 size+=size_of_relative_string( &info->configfile );
3136 return size;
3139 /*******************************************************************
3140 return the size required by a string array.
3141 ********************************************************************/
3143 uint32 spoolss_size_string_array(uint16 *string)
3145 uint32 i = 0;
3147 if (string) {
3148 for (i=0; (string[i]!=0x0000) || (string[i+1]!=0x0000); i++);
3150 i=i+2; /* to count all chars including the leading zero */
3151 i=2*i; /* because we need the value in bytes */
3152 i=i+4; /* the offset pointer size */
3154 return i;
3157 /*******************************************************************
3158 return the size required by a struct in the stream
3159 ********************************************************************/
3161 uint32 spoolss_size_printer_driver_info_3(DRIVER_INFO_3 *info)
3163 int size=0;
3165 size+=size_of_uint32( &info->version );
3166 size+=size_of_relative_string( &info->name );
3167 size+=size_of_relative_string( &info->architecture );
3168 size+=size_of_relative_string( &info->driverpath );
3169 size+=size_of_relative_string( &info->datafile );
3170 size+=size_of_relative_string( &info->configfile );
3171 size+=size_of_relative_string( &info->helpfile );
3172 size+=size_of_relative_string( &info->monitorname );
3173 size+=size_of_relative_string( &info->defaultdatatype );
3175 size+=spoolss_size_string_array(info->dependentfiles);
3177 return size;
3180 /*******************************************************************
3181 return the size required by a struct in the stream
3182 ********************************************************************/
3184 uint32 spoolss_size_printer_driver_info_6(DRIVER_INFO_6 *info)
3186 uint32 size=0;
3188 size+=size_of_uint32( &info->version );
3189 size+=size_of_relative_string( &info->name );
3190 size+=size_of_relative_string( &info->architecture );
3191 size+=size_of_relative_string( &info->driverpath );
3192 size+=size_of_relative_string( &info->datafile );
3193 size+=size_of_relative_string( &info->configfile );
3194 size+=size_of_relative_string( &info->helpfile );
3196 size+=spoolss_size_string_array(info->dependentfiles);
3198 size+=size_of_relative_string( &info->monitorname );
3199 size+=size_of_relative_string( &info->defaultdatatype );
3201 size+=spoolss_size_string_array(info->previousdrivernames);
3203 size+=size_of_nttime(&info->driver_date);
3204 size+=size_of_uint32( &info->padding );
3205 size+=size_of_uint32( &info->driver_version_low );
3206 size+=size_of_uint32( &info->driver_version_high );
3207 size+=size_of_relative_string( &info->mfgname );
3208 size+=size_of_relative_string( &info->oem_url );
3209 size+=size_of_relative_string( &info->hardware_id );
3210 size+=size_of_relative_string( &info->provider );
3212 return size;
3215 /*******************************************************************
3216 return the size required by a struct in the stream
3217 ********************************************************************/
3219 uint32 spoolss_size_job_info_1(JOB_INFO_1 *info)
3221 int size=0;
3222 size+=size_of_uint32( &info->jobid );
3223 size+=size_of_relative_string( &info->printername );
3224 size+=size_of_relative_string( &info->machinename );
3225 size+=size_of_relative_string( &info->username );
3226 size+=size_of_relative_string( &info->document );
3227 size+=size_of_relative_string( &info->datatype );
3228 size+=size_of_relative_string( &info->text_status );
3229 size+=size_of_uint32( &info->status );
3230 size+=size_of_uint32( &info->priority );
3231 size+=size_of_uint32( &info->position );
3232 size+=size_of_uint32( &info->totalpages );
3233 size+=size_of_uint32( &info->pagesprinted );
3234 size+=size_of_systemtime( &info->submitted );
3236 return size;
3239 /*******************************************************************
3240 return the size required by a struct in the stream
3241 ********************************************************************/
3243 uint32 spoolss_size_job_info_2(JOB_INFO_2 *info)
3245 int size=0;
3247 size+=4; /* size of sec desc ptr */
3249 size+=size_of_uint32( &info->jobid );
3250 size+=size_of_relative_string( &info->printername );
3251 size+=size_of_relative_string( &info->machinename );
3252 size+=size_of_relative_string( &info->username );
3253 size+=size_of_relative_string( &info->document );
3254 size+=size_of_relative_string( &info->notifyname );
3255 size+=size_of_relative_string( &info->datatype );
3256 size+=size_of_relative_string( &info->printprocessor );
3257 size+=size_of_relative_string( &info->parameters );
3258 size+=size_of_relative_string( &info->drivername );
3259 size+=size_of_device_mode( info->devmode );
3260 size+=size_of_relative_string( &info->text_status );
3261 /* SEC_DESC sec_desc;*/
3262 size+=size_of_uint32( &info->status );
3263 size+=size_of_uint32( &info->priority );
3264 size+=size_of_uint32( &info->position );
3265 size+=size_of_uint32( &info->starttime );
3266 size+=size_of_uint32( &info->untiltime );
3267 size+=size_of_uint32( &info->totalpages );
3268 size+=size_of_uint32( &info->size );
3269 size+=size_of_systemtime( &info->submitted );
3270 size+=size_of_uint32( &info->timeelapsed );
3271 size+=size_of_uint32( &info->pagesprinted );
3273 return size;
3276 /*******************************************************************
3277 return the size required by a struct in the stream
3278 ********************************************************************/
3280 uint32 spoolss_size_form_1(FORM_1 *info)
3282 int size=0;
3284 size+=size_of_uint32( &info->flag );
3285 size+=size_of_relative_string( &info->name );
3286 size+=size_of_uint32( &info->width );
3287 size+=size_of_uint32( &info->length );
3288 size+=size_of_uint32( &info->left );
3289 size+=size_of_uint32( &info->top );
3290 size+=size_of_uint32( &info->right );
3291 size+=size_of_uint32( &info->bottom );
3293 return size;
3296 /*******************************************************************
3297 return the size required by a struct in the stream
3298 ********************************************************************/
3300 uint32 spoolss_size_port_info_1(PORT_INFO_1 *info)
3302 int size=0;
3304 size+=size_of_relative_string( &info->port_name );
3306 return size;
3309 /*******************************************************************
3310 return the size required by a struct in the stream
3311 ********************************************************************/
3313 uint32 spoolss_size_driverdir_info_1(DRIVER_DIRECTORY_1 *info)
3315 int size=0;
3317 size=str_len_uni(&info->name); /* the string length */
3318 size=size+1; /* add the leading zero */
3319 size=size*2; /* convert in char */
3321 return size;
3324 /*******************************************************************
3325 return the size required by a struct in the stream
3326 ********************************************************************/
3328 uint32 spoolss_size_printprocessordirectory_info_1(PRINTPROCESSOR_DIRECTORY_1 *info)
3330 int size=0;
3332 size=str_len_uni(&info->name); /* the string length */
3333 size=size+1; /* add the leading zero */
3334 size=size*2; /* convert in char */
3336 return size;
3339 /*******************************************************************
3340 return the size required by a struct in the stream
3341 ********************************************************************/
3343 uint32 spoolss_size_port_info_2(PORT_INFO_2 *info)
3345 int size=0;
3347 size+=size_of_relative_string( &info->port_name );
3348 size+=size_of_relative_string( &info->monitor_name );
3349 size+=size_of_relative_string( &info->description );
3351 size+=size_of_uint32( &info->port_type );
3352 size+=size_of_uint32( &info->reserved );
3354 return size;
3357 /*******************************************************************
3358 return the size required by a struct in the stream
3359 ********************************************************************/
3361 uint32 spoolss_size_printprocessor_info_1(PRINTPROCESSOR_1 *info)
3363 int size=0;
3364 size+=size_of_relative_string( &info->name );
3366 return size;
3369 /*******************************************************************
3370 return the size required by a struct in the stream
3371 ********************************************************************/
3373 uint32 spoolss_size_printprocdatatype_info_1(PRINTPROCDATATYPE_1 *info)
3375 int size=0;
3376 size+=size_of_relative_string( &info->name );
3378 return size;
3381 /*******************************************************************
3382 return the size required by a struct in the stream
3383 ********************************************************************/
3384 uint32 spoolss_size_printer_enum_values(PRINTER_ENUM_VALUES *p)
3386 uint32 size = 0;
3388 if (!p)
3389 return 0;
3391 /* uint32(offset) + uint32(length) + length) */
3392 size += (size_of_uint32(&p->value_len)*2) + p->value_len;
3393 size += (size_of_uint32(&p->data_len)*2) + p->data_len;
3395 size += size_of_uint32(&p->type);
3397 return size;
3400 /*******************************************************************
3401 return the size required by a struct in the stream
3402 ********************************************************************/
3404 uint32 spoolss_size_printmonitor_info_1(PRINTMONITOR_1 *info)
3406 int size=0;
3407 size+=size_of_relative_string( &info->name );
3409 return size;
3412 /*******************************************************************
3413 return the size required by a struct in the stream
3414 ********************************************************************/
3416 uint32 spoolss_size_printmonitor_info_2(PRINTMONITOR_2 *info)
3418 int size=0;
3419 size+=size_of_relative_string( &info->name);
3420 size+=size_of_relative_string( &info->environment);
3421 size+=size_of_relative_string( &info->dll_name);
3423 return size;
3426 /*******************************************************************
3427 * init a structure.
3428 ********************************************************************/
3430 BOOL make_spoolss_q_getprinterdriver2(SPOOL_Q_GETPRINTERDRIVER2 *q_u,
3431 const POLICY_HND *hnd,
3432 const fstring architecture,
3433 uint32 level, uint32 clientmajor, uint32 clientminor,
3434 NEW_BUFFER *buffer, uint32 offered)
3436 if (q_u == NULL)
3437 return False;
3439 memcpy(&q_u->handle, hnd, sizeof(q_u->handle));
3441 init_buf_unistr2(&q_u->architecture, &q_u->architecture_ptr, architecture);
3443 q_u->level=level;
3444 q_u->clientmajorversion=clientmajor;
3445 q_u->clientminorversion=clientminor;
3447 q_u->buffer=buffer;
3448 q_u->offered=offered;
3450 return True;
3453 /*******************************************************************
3454 * read a structure.
3455 * called from spoolss_getprinterdriver2 (srv_spoolss.c)
3456 ********************************************************************/
3458 BOOL spoolss_io_q_getprinterdriver2(char *desc, SPOOL_Q_GETPRINTERDRIVER2 *q_u, prs_struct *ps, int depth)
3460 prs_debug(ps, depth, desc, "spoolss_io_q_getprinterdriver2");
3461 depth++;
3463 if(!prs_align(ps))
3464 return False;
3466 if(!smb_io_pol_hnd("printer handle", &q_u->handle, ps, depth))
3467 return False;
3468 if(!prs_uint32("architecture_ptr", ps, depth, &q_u->architecture_ptr))
3469 return False;
3470 if(!smb_io_unistr2("architecture", &q_u->architecture, q_u->architecture_ptr, ps, depth))
3471 return False;
3473 if(!prs_align(ps))
3474 return False;
3475 if(!prs_uint32("level", ps, depth, &q_u->level))
3476 return False;
3478 if(!spoolss_io_buffer("", ps, depth, &q_u->buffer))
3479 return False;
3481 if(!prs_align(ps))
3482 return False;
3484 if(!prs_uint32("offered", ps, depth, &q_u->offered))
3485 return False;
3487 if(!prs_uint32("clientmajorversion", ps, depth, &q_u->clientmajorversion))
3488 return False;
3489 if(!prs_uint32("clientminorversion", ps, depth, &q_u->clientminorversion))
3490 return False;
3492 return True;
3495 /*******************************************************************
3496 * read a structure.
3497 * called from spoolss_getprinterdriver2 (srv_spoolss.c)
3498 ********************************************************************/
3500 BOOL spoolss_io_r_getprinterdriver2(char *desc, SPOOL_R_GETPRINTERDRIVER2 *r_u, prs_struct *ps, int depth)
3502 prs_debug(ps, depth, desc, "spoolss_io_r_getprinterdriver2");
3503 depth++;
3505 if (!prs_align(ps))
3506 return False;
3508 if (!spoolss_io_buffer("", ps, depth, &r_u->buffer))
3509 return False;
3511 if (!prs_align(ps))
3512 return False;
3513 if (!prs_uint32("needed", ps, depth, &r_u->needed))
3514 return False;
3515 if (!prs_uint32("servermajorversion", ps, depth, &r_u->servermajorversion))
3516 return False;
3517 if (!prs_uint32("serverminorversion", ps, depth, &r_u->serverminorversion))
3518 return False;
3519 if (!prs_werror("status", ps, depth, &r_u->status))
3520 return False;
3522 return True;
3525 /*******************************************************************
3526 * init a structure.
3527 ********************************************************************/
3529 BOOL make_spoolss_q_enumprinters(
3530 SPOOL_Q_ENUMPRINTERS *q_u,
3531 uint32 flags,
3532 fstring servername,
3533 uint32 level,
3534 NEW_BUFFER *buffer,
3535 uint32 offered
3538 q_u->flags=flags;
3540 q_u->servername_ptr = (servername != NULL) ? 1 : 0;
3541 init_buf_unistr2(&q_u->servername, &q_u->servername_ptr, servername);
3543 q_u->level=level;
3544 q_u->buffer=buffer;
3545 q_u->offered=offered;
3547 return True;
3550 /*******************************************************************
3551 * init a structure.
3552 ********************************************************************/
3554 BOOL make_spoolss_q_enumports(SPOOL_Q_ENUMPORTS *q_u,
3555 fstring servername, uint32 level,
3556 NEW_BUFFER *buffer, uint32 offered)
3558 q_u->name_ptr = (servername != NULL) ? 1 : 0;
3559 init_buf_unistr2(&q_u->name, &q_u->name_ptr, servername);
3561 q_u->level=level;
3562 q_u->buffer=buffer;
3563 q_u->offered=offered;
3565 return True;
3568 /*******************************************************************
3569 * read a structure.
3570 * called from spoolss_enumprinters (srv_spoolss.c)
3571 ********************************************************************/
3573 BOOL spoolss_io_q_enumprinters(char *desc, SPOOL_Q_ENUMPRINTERS *q_u, prs_struct *ps, int depth)
3575 prs_debug(ps, depth, desc, "spoolss_io_q_enumprinters");
3576 depth++;
3578 if (!prs_align(ps))
3579 return False;
3581 if (!prs_uint32("flags", ps, depth, &q_u->flags))
3582 return False;
3583 if (!prs_uint32("servername_ptr", ps, depth, &q_u->servername_ptr))
3584 return False;
3586 if (!smb_io_unistr2("", &q_u->servername, q_u->servername_ptr, ps, depth))
3587 return False;
3589 if (!prs_align(ps))
3590 return False;
3591 if (!prs_uint32("level", ps, depth, &q_u->level))
3592 return False;
3594 if (!spoolss_io_buffer("", ps, depth, &q_u->buffer))
3595 return False;
3597 if (!prs_align(ps))
3598 return False;
3599 if (!prs_uint32("offered", ps, depth, &q_u->offered))
3600 return False;
3602 return True;
3605 /*******************************************************************
3606 Parse a SPOOL_R_ENUMPRINTERS structure.
3607 ********************************************************************/
3609 BOOL spoolss_io_r_enumprinters(char *desc, SPOOL_R_ENUMPRINTERS *r_u, prs_struct *ps, int depth)
3611 prs_debug(ps, depth, desc, "spoolss_io_r_enumprinters");
3612 depth++;
3614 if (!prs_align(ps))
3615 return False;
3617 if (!spoolss_io_buffer("", ps, depth, &r_u->buffer))
3618 return False;
3620 if (!prs_align(ps))
3621 return False;
3623 if (!prs_uint32("needed", ps, depth, &r_u->needed))
3624 return False;
3626 if (!prs_uint32("returned", ps, depth, &r_u->returned))
3627 return False;
3629 if (!prs_werror("status", ps, depth, &r_u->status))
3630 return False;
3632 return True;
3635 /*******************************************************************
3636 * write a structure.
3637 * called from spoolss_r_enum_printers (srv_spoolss.c)
3639 ********************************************************************/
3641 BOOL spoolss_io_r_getprinter(char *desc, SPOOL_R_GETPRINTER *r_u, prs_struct *ps, int depth)
3643 prs_debug(ps, depth, desc, "spoolss_io_r_getprinter");
3644 depth++;
3646 if (!prs_align(ps))
3647 return False;
3649 if (!spoolss_io_buffer("", ps, depth, &r_u->buffer))
3650 return False;
3652 if (!prs_align(ps))
3653 return False;
3655 if (!prs_uint32("needed", ps, depth, &r_u->needed))
3656 return False;
3658 if (!prs_werror("status", ps, depth, &r_u->status))
3659 return False;
3661 return True;
3664 /*******************************************************************
3665 * read a structure.
3666 * called from spoolss_getprinter (srv_spoolss.c)
3667 ********************************************************************/
3669 BOOL spoolss_io_q_getprinter(char *desc, SPOOL_Q_GETPRINTER *q_u, prs_struct *ps, int depth)
3671 prs_debug(ps, depth, desc, "spoolss_io_q_getprinter");
3672 depth++;
3674 if (!prs_align(ps))
3675 return False;
3677 if(!smb_io_pol_hnd("printer handle", &q_u->handle, ps, depth))
3678 return False;
3679 if (!prs_uint32("level", ps, depth, &q_u->level))
3680 return False;
3682 if (!spoolss_io_buffer("", ps, depth, &q_u->buffer))
3683 return False;
3685 if (!prs_align(ps))
3686 return False;
3687 if (!prs_uint32("offered", ps, depth, &q_u->offered))
3688 return False;
3690 return True;
3693 /*******************************************************************
3694 * init a structure.
3695 ********************************************************************/
3697 BOOL make_spoolss_q_getprinter(
3698 TALLOC_CTX *mem_ctx,
3699 SPOOL_Q_GETPRINTER *q_u,
3700 const POLICY_HND *hnd,
3701 uint32 level,
3702 NEW_BUFFER *buffer,
3703 uint32 offered
3706 if (q_u == NULL)
3708 return False;
3710 memcpy(&q_u->handle, hnd, sizeof(q_u->handle));
3712 q_u->level=level;
3713 q_u->buffer=buffer;
3714 q_u->offered=offered;
3716 return True;
3719 /*******************************************************************
3720 * init a structure.
3721 ********************************************************************/
3722 BOOL make_spoolss_q_setprinter(TALLOC_CTX *mem_ctx, SPOOL_Q_SETPRINTER *q_u,
3723 const POLICY_HND *hnd, uint32 level, PRINTER_INFO_CTR *info,
3724 uint32 command)
3726 SEC_DESC *secdesc;
3727 DEVICEMODE *devmode;
3729 if (q_u == NULL)
3730 return False;
3732 memcpy(&q_u->handle, hnd, sizeof(q_u->handle));
3734 q_u->level = level;
3735 q_u->info.level = level;
3736 q_u->info.info_ptr = (info != NULL) ? 1 : 0;
3737 switch (level) {
3739 /* There's no such thing as a setprinter level 1 */
3741 case 2:
3742 secdesc = info->printers_2->secdesc;
3743 devmode = info->printers_2->devmode;
3745 make_spoolss_printer_info_2 (mem_ctx, &q_u->info.info_2, info->printers_2);
3746 #if 1 /* JERRY TEST */
3747 q_u->secdesc_ctr = (SEC_DESC_BUF*)malloc(sizeof(SEC_DESC_BUF));
3748 if (!q_u->secdesc_ctr)
3749 return False;
3750 q_u->secdesc_ctr->ptr = (secdesc != NULL) ? 1: 0;
3751 q_u->secdesc_ctr->max_len = (secdesc) ? sizeof(SEC_DESC) + (2*sizeof(uint32)) : 0;
3752 q_u->secdesc_ctr->len = (secdesc) ? sizeof(SEC_DESC) + (2*sizeof(uint32)) : 0;
3753 q_u->secdesc_ctr->sec = secdesc;
3755 q_u->devmode_ctr.devmode_ptr = (devmode != NULL) ? 1 : 0;
3756 q_u->devmode_ctr.size = (devmode != NULL) ? sizeof(DEVICEMODE) + (3*sizeof(uint32)) : 0;
3757 q_u->devmode_ctr.devmode = devmode;
3758 #else
3759 q_u->secdesc_ctr = NULL;
3761 q_u->devmode_ctr.devmode_ptr = 0;
3762 q_u->devmode_ctr.size = 0;
3763 q_u->devmode_ctr.devmode = NULL;
3764 #endif
3765 break;
3766 default:
3767 DEBUG(0,("make_spoolss_q_setprinter: Unknown info level [%d]\n", level));
3768 break;
3772 q_u->command = command;
3774 return True;
3778 /*******************************************************************
3779 ********************************************************************/
3781 BOOL spoolss_io_r_setprinter(char *desc, SPOOL_R_SETPRINTER *r_u, prs_struct *ps, int depth)
3783 prs_debug(ps, depth, desc, "spoolss_io_r_setprinter");
3784 depth++;
3786 if(!prs_align(ps))
3787 return False;
3789 if(!prs_werror("status", ps, depth, &r_u->status))
3790 return False;
3792 return True;
3795 /*******************************************************************
3796 Marshall/unmarshall a SPOOL_Q_SETPRINTER struct.
3797 ********************************************************************/
3799 BOOL spoolss_io_q_setprinter(char *desc, SPOOL_Q_SETPRINTER *q_u, prs_struct *ps, int depth)
3801 uint32 ptr_sec_desc = 0;
3803 prs_debug(ps, depth, desc, "spoolss_io_q_setprinter");
3804 depth++;
3806 if(!prs_align(ps))
3807 return False;
3809 if(!smb_io_pol_hnd("printer handle", &q_u->handle ,ps, depth))
3810 return False;
3811 if(!prs_uint32("level", ps, depth, &q_u->level))
3812 return False;
3814 if(!spool_io_printer_info_level("", &q_u->info, ps, depth))
3815 return False;
3817 if (!spoolss_io_devmode_cont(desc, &q_u->devmode_ctr, ps, depth))
3818 return False;
3820 if(!prs_align(ps))
3821 return False;
3823 switch (q_u->level)
3825 case 2:
3827 ptr_sec_desc = q_u->info.info_2->secdesc_ptr;
3828 break;
3830 case 3:
3832 ptr_sec_desc = q_u->info.info_3->secdesc_ptr;
3833 break;
3836 if (ptr_sec_desc)
3838 if (!sec_io_desc_buf(desc, &q_u->secdesc_ctr, ps, depth))
3839 return False;
3840 } else {
3841 uint32 dummy = 0;
3843 /* Parse a NULL security descriptor. This should really
3844 happen inside the sec_io_desc_buf() function. */
3846 prs_debug(ps, depth, "", "sec_io_desc_buf");
3847 if (!prs_uint32("size", ps, depth + 1, &dummy))
3848 return False;
3849 if (!prs_uint32("ptr", ps, depth + 1, &dummy)) return
3850 False;
3853 if(!prs_uint32("command", ps, depth, &q_u->command))
3854 return False;
3856 return True;
3859 /*******************************************************************
3860 ********************************************************************/
3862 BOOL spoolss_io_r_fcpn(char *desc, SPOOL_R_FCPN *r_u, prs_struct *ps, int depth)
3864 prs_debug(ps, depth, desc, "spoolss_io_r_fcpn");
3865 depth++;
3867 if(!prs_align(ps))
3868 return False;
3870 if(!prs_werror("status", ps, depth, &r_u->status))
3871 return False;
3873 return True;
3876 /*******************************************************************
3877 ********************************************************************/
3879 BOOL spoolss_io_q_fcpn(char *desc, SPOOL_Q_FCPN *q_u, prs_struct *ps, int depth)
3882 prs_debug(ps, depth, desc, "spoolss_io_q_fcpn");
3883 depth++;
3885 if(!prs_align(ps))
3886 return False;
3888 if(!smb_io_pol_hnd("printer handle",&q_u->handle,ps,depth))
3889 return False;
3891 return True;
3895 /*******************************************************************
3896 ********************************************************************/
3898 BOOL spoolss_io_r_addjob(char *desc, SPOOL_R_ADDJOB *r_u, prs_struct *ps, int depth)
3900 prs_debug(ps, depth, desc, "");
3901 depth++;
3903 if(!prs_align(ps))
3904 return False;
3906 if(!spoolss_io_buffer("", ps, depth, &r_u->buffer))
3907 return False;
3909 if(!prs_align(ps))
3910 return False;
3912 if(!prs_uint32("needed", ps, depth, &r_u->needed))
3913 return False;
3915 if(!prs_werror("status", ps, depth, &r_u->status))
3916 return False;
3918 return True;
3921 /*******************************************************************
3922 ********************************************************************/
3924 BOOL spoolss_io_q_addjob(char *desc, SPOOL_Q_ADDJOB *q_u, prs_struct *ps, int depth)
3926 prs_debug(ps, depth, desc, "");
3927 depth++;
3929 if(!prs_align(ps))
3930 return False;
3932 if(!smb_io_pol_hnd("printer handle", &q_u->handle, ps, depth))
3933 return False;
3934 if(!prs_uint32("level", ps, depth, &q_u->level))
3935 return False;
3937 if(!spoolss_io_buffer("", ps, depth, &q_u->buffer))
3938 return False;
3940 if(!prs_align(ps))
3941 return False;
3943 if(!prs_uint32("offered", ps, depth, &q_u->offered))
3944 return False;
3946 return True;
3949 /*******************************************************************
3950 ********************************************************************/
3952 BOOL spoolss_io_r_enumjobs(char *desc, SPOOL_R_ENUMJOBS *r_u, prs_struct *ps, int depth)
3954 prs_debug(ps, depth, desc, "spoolss_io_r_enumjobs");
3955 depth++;
3957 if (!prs_align(ps))
3958 return False;
3960 if (!spoolss_io_buffer("", ps, depth, &r_u->buffer))
3961 return False;
3963 if (!prs_align(ps))
3964 return False;
3966 if (!prs_uint32("needed", ps, depth, &r_u->needed))
3967 return False;
3969 if (!prs_uint32("returned", ps, depth, &r_u->returned))
3970 return False;
3972 if (!prs_werror("status", ps, depth, &r_u->status))
3973 return False;
3975 return True;
3978 /*******************************************************************
3979 ********************************************************************/
3981 BOOL make_spoolss_q_enumjobs(SPOOL_Q_ENUMJOBS *q_u, const POLICY_HND *hnd,
3982 uint32 firstjob,
3983 uint32 numofjobs,
3984 uint32 level,
3985 NEW_BUFFER *buffer,
3986 uint32 offered)
3988 if (q_u == NULL)
3990 return False;
3992 memcpy(&q_u->handle, hnd, sizeof(q_u->handle));
3993 q_u->firstjob = firstjob;
3994 q_u->numofjobs = numofjobs;
3995 q_u->level = level;
3996 q_u->buffer= buffer;
3997 q_u->offered = offered;
3998 return True;
4001 /*******************************************************************
4002 ********************************************************************/
4004 BOOL spoolss_io_q_enumjobs(char *desc, SPOOL_Q_ENUMJOBS *q_u, prs_struct *ps, int depth)
4006 prs_debug(ps, depth, desc, "spoolss_io_q_enumjobs");
4007 depth++;
4009 if (!prs_align(ps))
4010 return False;
4012 if (!smb_io_pol_hnd("printer handle",&q_u->handle, ps, depth))
4013 return False;
4015 if (!prs_uint32("firstjob", ps, depth, &q_u->firstjob))
4016 return False;
4017 if (!prs_uint32("numofjobs", ps, depth, &q_u->numofjobs))
4018 return False;
4019 if (!prs_uint32("level", ps, depth, &q_u->level))
4020 return False;
4022 if (!spoolss_io_buffer("", ps, depth, &q_u->buffer))
4023 return False;
4025 if(!prs_align(ps))
4026 return False;
4028 if (!prs_uint32("offered", ps, depth, &q_u->offered))
4029 return False;
4031 return True;
4034 /*******************************************************************
4035 ********************************************************************/
4037 BOOL spoolss_io_r_schedulejob(char *desc, SPOOL_R_SCHEDULEJOB *r_u, prs_struct *ps, int depth)
4039 prs_debug(ps, depth, desc, "spoolss_io_r_schedulejob");
4040 depth++;
4042 if(!prs_align(ps))
4043 return False;
4045 if(!prs_werror("status", ps, depth, &r_u->status))
4046 return False;
4048 return True;
4051 /*******************************************************************
4052 ********************************************************************/
4054 BOOL spoolss_io_q_schedulejob(char *desc, SPOOL_Q_SCHEDULEJOB *q_u, prs_struct *ps, int depth)
4056 prs_debug(ps, depth, desc, "spoolss_io_q_schedulejob");
4057 depth++;
4059 if(!prs_align(ps))
4060 return False;
4062 if(!smb_io_pol_hnd("printer handle",&q_u->handle,ps,depth))
4063 return False;
4064 if(!prs_uint32("jobid", ps, depth, &q_u->jobid))
4065 return False;
4067 return True;
4070 /*******************************************************************
4071 ********************************************************************/
4073 BOOL spoolss_io_r_setjob(char *desc, SPOOL_R_SETJOB *r_u, prs_struct *ps, int depth)
4075 prs_debug(ps, depth, desc, "spoolss_io_r_setjob");
4076 depth++;
4078 if(!prs_align(ps))
4079 return False;
4081 if(!prs_werror("status", ps, depth, &r_u->status))
4082 return False;
4084 return True;
4087 /*******************************************************************
4088 ********************************************************************/
4090 BOOL spoolss_io_q_setjob(char *desc, SPOOL_Q_SETJOB *q_u, prs_struct *ps, int depth)
4092 prs_debug(ps, depth, desc, "spoolss_io_q_setjob");
4093 depth++;
4095 if(!prs_align(ps))
4096 return False;
4098 if(!smb_io_pol_hnd("printer handle",&q_u->handle,ps,depth))
4099 return False;
4100 if(!prs_uint32("jobid", ps, depth, &q_u->jobid))
4101 return False;
4103 * level is usually 0. If (level!=0) then I'm in trouble !
4104 * I will try to generate setjob command with level!=0, one day.
4106 if(!prs_uint32("level", ps, depth, &q_u->level))
4107 return False;
4108 if(!prs_uint32("command", ps, depth, &q_u->command))
4109 return False;
4111 return True;
4114 /*******************************************************************
4115 Parse a SPOOL_R_ENUMPRINTERDRIVERS structure.
4116 ********************************************************************/
4118 BOOL spoolss_io_r_enumprinterdrivers(char *desc, SPOOL_R_ENUMPRINTERDRIVERS *r_u, prs_struct *ps, int depth)
4120 prs_debug(ps, depth, desc, "spoolss_io_r_enumprinterdrivers");
4121 depth++;
4123 if (!prs_align(ps))
4124 return False;
4126 if (!spoolss_io_buffer("", ps, depth, &r_u->buffer))
4127 return False;
4129 if (!prs_align(ps))
4130 return False;
4132 if (!prs_uint32("needed", ps, depth, &r_u->needed))
4133 return False;
4135 if (!prs_uint32("returned", ps, depth, &r_u->returned))
4136 return False;
4138 if (!prs_werror("status", ps, depth, &r_u->status))
4139 return False;
4141 return True;
4144 /*******************************************************************
4145 * init a structure.
4146 ********************************************************************/
4148 BOOL make_spoolss_q_enumprinterdrivers(SPOOL_Q_ENUMPRINTERDRIVERS *q_u,
4149 const char *name,
4150 const char *environment,
4151 uint32 level,
4152 NEW_BUFFER *buffer, uint32 offered)
4154 init_buf_unistr2(&q_u->name, &q_u->name_ptr, name);
4155 init_buf_unistr2(&q_u->environment, &q_u->environment_ptr, environment);
4157 q_u->level=level;
4158 q_u->buffer=buffer;
4159 q_u->offered=offered;
4161 return True;
4164 /*******************************************************************
4165 Parse a SPOOL_Q_ENUMPRINTERDRIVERS structure.
4166 ********************************************************************/
4168 BOOL spoolss_io_q_enumprinterdrivers(char *desc, SPOOL_Q_ENUMPRINTERDRIVERS *q_u, prs_struct *ps, int depth)
4171 prs_debug(ps, depth, desc, "spoolss_io_q_enumprinterdrivers");
4172 depth++;
4174 if (!prs_align(ps))
4175 return False;
4177 if (!prs_uint32("name_ptr", ps, depth, &q_u->name_ptr))
4178 return False;
4179 if (!smb_io_unistr2("", &q_u->name, q_u->name_ptr,ps, depth))
4180 return False;
4182 if (!prs_align(ps))
4183 return False;
4184 if (!prs_uint32("environment_ptr", ps, depth, &q_u->environment_ptr))
4185 return False;
4186 if (!smb_io_unistr2("", &q_u->environment, q_u->environment_ptr, ps, depth))
4187 return False;
4189 if (!prs_align(ps))
4190 return False;
4191 if (!prs_uint32("level", ps, depth, &q_u->level))
4192 return False;
4194 if (!spoolss_io_buffer("", ps, depth, &q_u->buffer))
4195 return False;
4197 if (!prs_align(ps))
4198 return False;
4200 if (!prs_uint32("offered", ps, depth, &q_u->offered))
4201 return False;
4203 return True;
4206 /*******************************************************************
4207 ********************************************************************/
4209 BOOL spoolss_io_q_enumforms(char *desc, SPOOL_Q_ENUMFORMS *q_u, prs_struct *ps, int depth)
4212 prs_debug(ps, depth, desc, "spoolss_io_q_enumforms");
4213 depth++;
4215 if (!prs_align(ps))
4216 return False;
4217 if (!smb_io_pol_hnd("printer handle",&q_u->handle,ps,depth))
4218 return False;
4219 if (!prs_uint32("level", ps, depth, &q_u->level))
4220 return False;
4222 if (!spoolss_io_buffer("", ps, depth, &q_u->buffer))
4223 return False;
4225 if (!prs_align(ps))
4226 return False;
4227 if (!prs_uint32("offered", ps, depth, &q_u->offered))
4228 return False;
4230 return True;
4233 /*******************************************************************
4234 ********************************************************************/
4236 BOOL spoolss_io_r_enumforms(char *desc, SPOOL_R_ENUMFORMS *r_u, prs_struct *ps, int depth)
4238 prs_debug(ps, depth, desc, "spoolss_io_r_enumforms");
4239 depth++;
4241 if (!prs_align(ps))
4242 return False;
4244 if (!spoolss_io_buffer("", ps, depth, &r_u->buffer))
4245 return False;
4247 if (!prs_align(ps))
4248 return False;
4250 if (!prs_uint32("size of buffer needed", ps, depth, &r_u->needed))
4251 return False;
4253 if (!prs_uint32("numofforms", ps, depth, &r_u->numofforms))
4254 return False;
4256 if (!prs_werror("status", ps, depth, &r_u->status))
4257 return False;
4259 return True;
4262 /*******************************************************************
4263 ********************************************************************/
4265 BOOL spoolss_io_q_getform(char *desc, SPOOL_Q_GETFORM *q_u, prs_struct *ps, int depth)
4268 prs_debug(ps, depth, desc, "spoolss_io_q_getform");
4269 depth++;
4271 if (!prs_align(ps))
4272 return False;
4273 if (!smb_io_pol_hnd("printer handle",&q_u->handle,ps,depth))
4274 return False;
4275 if (!smb_io_unistr2("", &q_u->formname,True,ps,depth))
4276 return False;
4278 if (!prs_align(ps))
4279 return False;
4281 if (!prs_uint32("level", ps, depth, &q_u->level))
4282 return False;
4284 if (!spoolss_io_buffer("", ps, depth, &q_u->buffer))
4285 return False;
4287 if (!prs_align(ps))
4288 return False;
4289 if (!prs_uint32("offered", ps, depth, &q_u->offered))
4290 return False;
4292 return True;
4295 /*******************************************************************
4296 ********************************************************************/
4298 BOOL spoolss_io_r_getform(char *desc, SPOOL_R_GETFORM *r_u, prs_struct *ps, int depth)
4300 prs_debug(ps, depth, desc, "spoolss_io_r_getform");
4301 depth++;
4303 if (!prs_align(ps))
4304 return False;
4306 if (!spoolss_io_buffer("", ps, depth, &r_u->buffer))
4307 return False;
4309 if (!prs_align(ps))
4310 return False;
4312 if (!prs_uint32("size of buffer needed", ps, depth, &r_u->needed))
4313 return False;
4315 if (!prs_werror("status", ps, depth, &r_u->status))
4316 return False;
4318 return True;
4321 /*******************************************************************
4322 Parse a SPOOL_R_ENUMPORTS structure.
4323 ********************************************************************/
4325 BOOL spoolss_io_r_enumports(char *desc, SPOOL_R_ENUMPORTS *r_u, prs_struct *ps, int depth)
4327 prs_debug(ps, depth, desc, "spoolss_io_r_enumports");
4328 depth++;
4330 if (!prs_align(ps))
4331 return False;
4333 if (!spoolss_io_buffer("", ps, depth, &r_u->buffer))
4334 return False;
4336 if (!prs_align(ps))
4337 return False;
4339 if (!prs_uint32("needed", ps, depth, &r_u->needed))
4340 return False;
4342 if (!prs_uint32("returned", ps, depth, &r_u->returned))
4343 return False;
4345 if (!prs_werror("status", ps, depth, &r_u->status))
4346 return False;
4348 return True;
4351 /*******************************************************************
4352 ********************************************************************/
4354 BOOL spoolss_io_q_enumports(char *desc, SPOOL_Q_ENUMPORTS *q_u, prs_struct *ps, int depth)
4356 prs_debug(ps, depth, desc, "");
4357 depth++;
4359 if (!prs_align(ps))
4360 return False;
4362 if (!prs_uint32("", ps, depth, &q_u->name_ptr))
4363 return False;
4364 if (!smb_io_unistr2("", &q_u->name,True,ps,depth))
4365 return False;
4367 if (!prs_align(ps))
4368 return False;
4369 if (!prs_uint32("level", ps, depth, &q_u->level))
4370 return False;
4372 if (!spoolss_io_buffer("", ps, depth, &q_u->buffer))
4373 return False;
4375 if (!prs_align(ps))
4376 return False;
4377 if (!prs_uint32("offered", ps, depth, &q_u->offered))
4378 return False;
4380 return True;
4383 /*******************************************************************
4384 Parse a SPOOL_PRINTER_INFO_LEVEL_1 structure.
4385 ********************************************************************/
4387 BOOL spool_io_printer_info_level_1(char *desc, SPOOL_PRINTER_INFO_LEVEL_1 *il, prs_struct *ps, int depth)
4389 prs_debug(ps, depth, desc, "spool_io_printer_info_level_1");
4390 depth++;
4392 if(!prs_align(ps))
4393 return False;
4395 if(!prs_uint32("flags", ps, depth, &il->flags))
4396 return False;
4397 if(!prs_uint32("description_ptr", ps, depth, &il->description_ptr))
4398 return False;
4399 if(!prs_uint32("name_ptr", ps, depth, &il->name_ptr))
4400 return False;
4401 if(!prs_uint32("comment_ptr", ps, depth, &il->comment_ptr))
4402 return False;
4404 if(!smb_io_unistr2("description", &il->description, il->description_ptr, ps, depth))
4405 return False;
4406 if(!smb_io_unistr2("name", &il->name, il->name_ptr, ps, depth))
4407 return False;
4408 if(!smb_io_unistr2("comment", &il->comment, il->comment_ptr, ps, depth))
4409 return False;
4411 return True;
4414 /*******************************************************************
4415 Parse a SPOOL_PRINTER_INFO_LEVEL_3 structure.
4416 ********************************************************************/
4418 BOOL spool_io_printer_info_level_3(char *desc, SPOOL_PRINTER_INFO_LEVEL_3 *il, prs_struct *ps, int depth)
4420 prs_debug(ps, depth, desc, "spool_io_printer_info_level_3");
4421 depth++;
4423 if(!prs_align(ps))
4424 return False;
4426 if(!prs_uint32("secdesc_ptr", ps, depth, &il->secdesc_ptr))
4427 return False;
4429 return True;
4432 /*******************************************************************
4433 Parse a SPOOL_PRINTER_INFO_LEVEL_2 structure.
4434 ********************************************************************/
4436 BOOL spool_io_printer_info_level_2(char *desc, SPOOL_PRINTER_INFO_LEVEL_2 *il, prs_struct *ps, int depth)
4438 prs_debug(ps, depth, desc, "spool_io_printer_info_level_2");
4439 depth++;
4441 if(!prs_align(ps))
4442 return False;
4444 if(!prs_uint32("servername_ptr", ps, depth, &il->servername_ptr))
4445 return False;
4446 if(!prs_uint32("printername_ptr", ps, depth, &il->printername_ptr))
4447 return False;
4448 if(!prs_uint32("sharename_ptr", ps, depth, &il->sharename_ptr))
4449 return False;
4450 if(!prs_uint32("portname_ptr", ps, depth, &il->portname_ptr))
4451 return False;
4453 if(!prs_uint32("drivername_ptr", ps, depth, &il->drivername_ptr))
4454 return False;
4455 if(!prs_uint32("comment_ptr", ps, depth, &il->comment_ptr))
4456 return False;
4457 if(!prs_uint32("location_ptr", ps, depth, &il->location_ptr))
4458 return False;
4459 if(!prs_uint32("devmode_ptr", ps, depth, &il->devmode_ptr))
4460 return False;
4461 if(!prs_uint32("sepfile_ptr", ps, depth, &il->sepfile_ptr))
4462 return False;
4463 if(!prs_uint32("printprocessor_ptr", ps, depth, &il->printprocessor_ptr))
4464 return False;
4465 if(!prs_uint32("datatype_ptr", ps, depth, &il->datatype_ptr))
4466 return False;
4467 if(!prs_uint32("parameters_ptr", ps, depth, &il->parameters_ptr))
4468 return False;
4469 if(!prs_uint32("secdesc_ptr", ps, depth, &il->secdesc_ptr))
4470 return False;
4472 if(!prs_uint32("attributes", ps, depth, &il->attributes))
4473 return False;
4474 if(!prs_uint32("priority", ps, depth, &il->priority))
4475 return False;
4476 if(!prs_uint32("default_priority", ps, depth, &il->default_priority))
4477 return False;
4478 if(!prs_uint32("starttime", ps, depth, &il->starttime))
4479 return False;
4480 if(!prs_uint32("untiltime", ps, depth, &il->untiltime))
4481 return False;
4482 if(!prs_uint32("status", ps, depth, &il->status))
4483 return False;
4484 if(!prs_uint32("cjobs", ps, depth, &il->cjobs))
4485 return False;
4486 if(!prs_uint32("averageppm", ps, depth, &il->averageppm))
4487 return False;
4489 if(!smb_io_unistr2("servername", &il->servername, il->servername_ptr, ps, depth))
4490 return False;
4491 if(!smb_io_unistr2("printername", &il->printername, il->printername_ptr, ps, depth))
4492 return False;
4493 if(!smb_io_unistr2("sharename", &il->sharename, il->sharename_ptr, ps, depth))
4494 return False;
4495 if(!smb_io_unistr2("portname", &il->portname, il->portname_ptr, ps, depth))
4496 return False;
4497 if(!smb_io_unistr2("drivername", &il->drivername, il->drivername_ptr, ps, depth))
4498 return False;
4499 if(!smb_io_unistr2("comment", &il->comment, il->comment_ptr, ps, depth))
4500 return False;
4501 if(!smb_io_unistr2("location", &il->location, il->location_ptr, ps, depth))
4502 return False;
4503 if(!smb_io_unistr2("sepfile", &il->sepfile, il->sepfile_ptr, ps, depth))
4504 return False;
4505 if(!smb_io_unistr2("printprocessor", &il->printprocessor, il->printprocessor_ptr, ps, depth))
4506 return False;
4507 if(!smb_io_unistr2("datatype", &il->datatype, il->datatype_ptr, ps, depth))
4508 return False;
4509 if(!smb_io_unistr2("parameters", &il->parameters, il->parameters_ptr, ps, depth))
4510 return False;
4512 return True;
4515 /*******************************************************************
4516 ********************************************************************/
4518 BOOL spool_io_printer_info_level(char *desc, SPOOL_PRINTER_INFO_LEVEL *il, prs_struct *ps, int depth)
4520 prs_debug(ps, depth, desc, "spool_io_printer_info_level");
4521 depth++;
4523 if(!prs_align(ps))
4524 return False;
4525 if(!prs_uint32("level", ps, depth, &il->level))
4526 return False;
4527 if(!prs_uint32("info_ptr", ps, depth, &il->info_ptr))
4528 return False;
4530 /* if no struct inside just return */
4531 if (il->info_ptr==0) {
4532 if (UNMARSHALLING(ps)) {
4533 il->info_1=NULL;
4534 il->info_2=NULL;
4536 return True;
4539 switch (il->level) {
4541 * level 0 is used by setprinter when managing the queue
4542 * (hold, stop, start a queue)
4544 case 0:
4545 break;
4546 /* DOCUMENT ME!!! What is level 1 used for? */
4547 case 1:
4549 if (UNMARSHALLING(ps)) {
4550 if ((il->info_1=(SPOOL_PRINTER_INFO_LEVEL_1 *)prs_alloc_mem(ps,sizeof(SPOOL_PRINTER_INFO_LEVEL_1))) == NULL)
4551 return False;
4553 if (!spool_io_printer_info_level_1("", il->info_1, ps, depth))
4554 return False;
4555 break;
4558 * level 2 is used by addprinter
4559 * and by setprinter when updating printer's info
4561 case 2:
4562 if (UNMARSHALLING(ps)) {
4563 if ((il->info_2=(SPOOL_PRINTER_INFO_LEVEL_2 *)prs_alloc_mem(ps,sizeof(SPOOL_PRINTER_INFO_LEVEL_2))) == NULL)
4564 return False;
4566 if (!spool_io_printer_info_level_2("", il->info_2, ps, depth))
4567 return False;
4568 break;
4569 /* DOCUMENT ME!!! What is level 3 used for? */
4570 case 3:
4572 if (UNMARSHALLING(ps)) {
4573 if ((il->info_3=(SPOOL_PRINTER_INFO_LEVEL_3 *)prs_alloc_mem(ps,sizeof(SPOOL_PRINTER_INFO_LEVEL_3))) == NULL)
4574 return False;
4576 if (!spool_io_printer_info_level_3("", il->info_3, ps, depth))
4577 return False;
4578 break;
4582 return True;
4585 /*******************************************************************
4586 ********************************************************************/
4588 BOOL spoolss_io_q_addprinterex(char *desc, SPOOL_Q_ADDPRINTEREX *q_u, prs_struct *ps, int depth)
4590 uint32 ptr_sec_desc = 0;
4592 prs_debug(ps, depth, desc, "spoolss_io_q_addprinterex");
4593 depth++;
4595 if(!prs_align(ps))
4596 return False;
4597 if(!prs_uint32("", ps, depth, &q_u->server_name_ptr))
4598 return False;
4599 if(!smb_io_unistr2("", &q_u->server_name, q_u->server_name_ptr, ps, depth))
4600 return False;
4602 if(!prs_align(ps))
4603 return False;
4605 if(!prs_uint32("info_level", ps, depth, &q_u->level))
4606 return False;
4608 if(!spool_io_printer_info_level("", &q_u->info, ps, depth))
4609 return False;
4611 if (!spoolss_io_devmode_cont(desc, &q_u->devmode_ctr, ps, depth))
4612 return False;
4614 if(!prs_align(ps))
4615 return False;
4617 switch (q_u->level) {
4618 case 2:
4619 ptr_sec_desc = q_u->info.info_2->secdesc_ptr;
4620 break;
4621 case 3:
4622 ptr_sec_desc = q_u->info.info_3->secdesc_ptr;
4623 break;
4625 if (ptr_sec_desc) {
4626 if (!sec_io_desc_buf(desc, &q_u->secdesc_ctr, ps, depth))
4627 return False;
4628 } else {
4629 uint32 dummy;
4631 /* Parse a NULL security descriptor. This should really
4632 happen inside the sec_io_desc_buf() function. */
4634 prs_debug(ps, depth, "", "sec_io_desc_buf");
4635 if (!prs_uint32("size", ps, depth + 1, &dummy))
4636 return False;
4637 if (!prs_uint32("ptr", ps, depth + 1, &dummy))
4638 return False;
4641 if(!prs_uint32("user_switch", ps, depth, &q_u->user_switch))
4642 return False;
4643 if(!spool_io_user_level("", &q_u->user_ctr, ps, depth))
4644 return False;
4646 return True;
4649 /*******************************************************************
4650 ********************************************************************/
4652 BOOL spoolss_io_r_addprinterex(char *desc, SPOOL_R_ADDPRINTEREX *r_u,
4653 prs_struct *ps, int depth)
4655 prs_debug(ps, depth, desc, "spoolss_io_r_addprinterex");
4656 depth++;
4658 if(!smb_io_pol_hnd("printer handle",&r_u->handle,ps,depth))
4659 return False;
4661 if(!prs_werror("status", ps, depth, &r_u->status))
4662 return False;
4664 return True;
4667 /*******************************************************************
4668 ********************************************************************/
4670 BOOL spool_io_printer_driver_info_level_3(char *desc, SPOOL_PRINTER_DRIVER_INFO_LEVEL_3 **q_u,
4671 prs_struct *ps, int depth)
4673 SPOOL_PRINTER_DRIVER_INFO_LEVEL_3 *il;
4675 prs_debug(ps, depth, desc, "spool_io_printer_driver_info_level_3");
4676 depth++;
4678 /* reading */
4679 if (UNMARSHALLING(ps)) {
4680 il=(SPOOL_PRINTER_DRIVER_INFO_LEVEL_3 *)prs_alloc_mem(ps,sizeof(SPOOL_PRINTER_DRIVER_INFO_LEVEL_3));
4681 if(il == NULL)
4682 return False;
4683 *q_u=il;
4685 else {
4686 il=*q_u;
4689 if(!prs_align(ps))
4690 return False;
4692 if(!prs_uint32("cversion", ps, depth, &il->cversion))
4693 return False;
4694 if(!prs_uint32("name", ps, depth, &il->name_ptr))
4695 return False;
4696 if(!prs_uint32("environment", ps, depth, &il->environment_ptr))
4697 return False;
4698 if(!prs_uint32("driverpath", ps, depth, &il->driverpath_ptr))
4699 return False;
4700 if(!prs_uint32("datafile", ps, depth, &il->datafile_ptr))
4701 return False;
4702 if(!prs_uint32("configfile", ps, depth, &il->configfile_ptr))
4703 return False;
4704 if(!prs_uint32("helpfile", ps, depth, &il->helpfile_ptr))
4705 return False;
4706 if(!prs_uint32("monitorname", ps, depth, &il->monitorname_ptr))
4707 return False;
4708 if(!prs_uint32("defaultdatatype", ps, depth, &il->defaultdatatype_ptr))
4709 return False;
4710 if(!prs_uint32("dependentfilessize", ps, depth, &il->dependentfilessize))
4711 return False;
4712 if(!prs_uint32("dependentfiles", ps, depth, &il->dependentfiles_ptr))
4713 return False;
4715 if(!prs_align(ps))
4716 return False;
4718 if(!smb_io_unistr2("name", &il->name, il->name_ptr, ps, depth))
4719 return False;
4720 if(!smb_io_unistr2("environment", &il->environment, il->environment_ptr, ps, depth))
4721 return False;
4722 if(!smb_io_unistr2("driverpath", &il->driverpath, il->driverpath_ptr, ps, depth))
4723 return False;
4724 if(!smb_io_unistr2("datafile", &il->datafile, il->datafile_ptr, ps, depth))
4725 return False;
4726 if(!smb_io_unistr2("configfile", &il->configfile, il->configfile_ptr, ps, depth))
4727 return False;
4728 if(!smb_io_unistr2("helpfile", &il->helpfile, il->helpfile_ptr, ps, depth))
4729 return False;
4730 if(!smb_io_unistr2("monitorname", &il->monitorname, il->monitorname_ptr, ps, depth))
4731 return False;
4732 if(!smb_io_unistr2("defaultdatatype", &il->defaultdatatype, il->defaultdatatype_ptr, ps, depth))
4733 return False;
4735 if(!prs_align(ps))
4736 return False;
4738 if (il->dependentfiles_ptr)
4739 smb_io_buffer5("", &il->dependentfiles, ps, depth);
4741 return True;
4744 /*******************************************************************
4745 parse a SPOOL_PRINTER_DRIVER_INFO_LEVEL_6 structure
4746 ********************************************************************/
4748 BOOL spool_io_printer_driver_info_level_6(char *desc, SPOOL_PRINTER_DRIVER_INFO_LEVEL_6 **q_u,
4749 prs_struct *ps, int depth)
4751 SPOOL_PRINTER_DRIVER_INFO_LEVEL_6 *il;
4753 prs_debug(ps, depth, desc, "spool_io_printer_driver_info_level_6");
4754 depth++;
4756 /* reading */
4757 if (UNMARSHALLING(ps)) {
4758 il=(SPOOL_PRINTER_DRIVER_INFO_LEVEL_6 *)prs_alloc_mem(ps,sizeof(SPOOL_PRINTER_DRIVER_INFO_LEVEL_6));
4759 if(il == NULL)
4760 return False;
4761 *q_u=il;
4763 else {
4764 il=*q_u;
4767 if(!prs_align(ps))
4768 return False;
4771 /* parse the main elements the packet */
4773 if(!prs_uint32("version", ps, depth, &il->version))
4774 return False;
4776 if(!prs_uint32("name_ptr", ps, depth, &il->name_ptr))
4777 return False;
4779 * If name_ptr is NULL then the next 4 bytes are the name_ptr. A driver
4780 * with a NULL name just isn't a driver For example: "HP LaserJet 4si"
4781 * from W2K CDROM (which uses unidriver). JohnR 010205
4783 if (!il->name_ptr) {
4784 DEBUG(5,("spool_io_printer_driver_info_level_6: name_ptr is NULL! Get next value\n"));
4785 if(!prs_uint32("name_ptr", ps, depth, &il->name_ptr))
4786 return False;
4789 if(!prs_uint32("environment_ptr", ps, depth, &il->environment_ptr))
4790 return False;
4791 if(!prs_uint32("driverpath_ptr", ps, depth, &il->driverpath_ptr))
4792 return False;
4793 if(!prs_uint32("datafile_ptr", ps, depth, &il->datafile_ptr))
4794 return False;
4795 if(!prs_uint32("configfile_ptr", ps, depth, &il->configfile_ptr))
4796 return False;
4797 if(!prs_uint32("helpfile_ptr", ps, depth, &il->helpfile_ptr))
4798 return False;
4799 if(!prs_uint32("monitorname_ptr", ps, depth, &il->monitorname_ptr))
4800 return False;
4801 if(!prs_uint32("defaultdatatype_ptr", ps, depth, &il->defaultdatatype_ptr))
4802 return False;
4803 if(!prs_uint32("dependentfiles_len", ps, depth, &il->dependentfiles_len))
4804 return False;
4805 if(!prs_uint32("dependentfiles_ptr", ps, depth, &il->dependentfiles_ptr))
4806 return False;
4807 if(!prs_uint32("previousnames_len", ps, depth, &il->previousnames_len))
4808 return False;
4809 if(!prs_uint32("previousnames_ptr", ps, depth, &il->previousnames_ptr))
4810 return False;
4811 if(!smb_io_time("driverdate", &il->driverdate, ps, depth))
4812 return False;
4813 if(!prs_uint32("dummy4", ps, depth, &il->dummy4))
4814 return False;
4815 if(!prs_uint64("driverversion", ps, depth, &il->driverversion))
4816 return False;
4817 if(!prs_uint32("mfgname_ptr", ps, depth, &il->mfgname_ptr))
4818 return False;
4819 if(!prs_uint32("oemurl_ptr", ps, depth, &il->oemurl_ptr))
4820 return False;
4821 if(!prs_uint32("hardwareid_ptr", ps, depth, &il->hardwareid_ptr))
4822 return False;
4823 if(!prs_uint32("provider_ptr", ps, depth, &il->provider_ptr))
4824 return False;
4826 /* parse the structures in the packet */
4828 if(!smb_io_unistr2("name", &il->name, il->name_ptr, ps, depth))
4829 return False;
4830 if(!prs_align(ps))
4831 return False;
4833 if(!smb_io_unistr2("environment", &il->environment, il->environment_ptr, ps, depth))
4834 return False;
4835 if(!prs_align(ps))
4836 return False;
4838 if(!smb_io_unistr2("driverpath", &il->driverpath, il->driverpath_ptr, ps, depth))
4839 return False;
4840 if(!prs_align(ps))
4841 return False;
4843 if(!smb_io_unistr2("datafile", &il->datafile, il->datafile_ptr, ps, depth))
4844 return False;
4845 if(!prs_align(ps))
4846 return False;
4848 if(!smb_io_unistr2("configfile", &il->configfile, il->configfile_ptr, ps, depth))
4849 return False;
4850 if(!prs_align(ps))
4851 return False;
4853 if(!smb_io_unistr2("helpfile", &il->helpfile, il->helpfile_ptr, ps, depth))
4854 return False;
4855 if(!prs_align(ps))
4856 return False;
4858 if(!smb_io_unistr2("monitorname", &il->monitorname, il->monitorname_ptr, ps, depth))
4859 return False;
4860 if(!prs_align(ps))
4861 return False;
4863 if(!smb_io_unistr2("defaultdatatype", &il->defaultdatatype, il->defaultdatatype_ptr, ps, depth))
4864 return False;
4865 if(!prs_align(ps))
4866 return False;
4867 if (il->dependentfiles_ptr) {
4868 if(!smb_io_buffer5("dependentfiles", &il->dependentfiles, ps, depth))
4869 return False;
4870 if(!prs_align(ps))
4871 return False;
4873 if (il->previousnames_ptr) {
4874 if(!smb_io_buffer5("previousnames", &il->previousnames, ps, depth))
4875 return False;
4876 if(!prs_align(ps))
4877 return False;
4879 if(!smb_io_unistr2("mfgname", &il->mfgname, il->mfgname_ptr, ps, depth))
4880 return False;
4881 if(!prs_align(ps))
4882 return False;
4883 if(!smb_io_unistr2("oemurl", &il->oemurl, il->oemurl_ptr, ps, depth))
4884 return False;
4885 if(!prs_align(ps))
4886 return False;
4887 if(!smb_io_unistr2("hardwareid", &il->hardwareid, il->hardwareid_ptr, ps, depth))
4888 return False;
4889 if(!prs_align(ps))
4890 return False;
4891 if(!smb_io_unistr2("provider", &il->provider, il->provider_ptr, ps, depth))
4892 return False;
4894 return True;
4897 /*******************************************************************
4898 convert a buffer of UNICODE strings null terminated
4899 the buffer is terminated by a NULL
4901 convert to an dos codepage array (null terminated)
4903 dynamically allocate memory
4905 ********************************************************************/
4906 static BOOL uniarray_2_dosarray(BUFFER5 *buf5, fstring **ar)
4908 fstring f, *tar;
4909 int n = 0;
4910 char *src;
4912 if (buf5==NULL)
4913 return False;
4915 src = (char *)buf5->buffer;
4916 *ar = NULL;
4918 while (src < ((char *)buf5->buffer) + buf5->buf_len*2) {
4919 rpcstr_pull(f, src, sizeof(f)-1, -1, 0);
4920 src = skip_unibuf(src, 2*buf5->buf_len - PTR_DIFF(src,buf5->buffer));
4921 tar = (fstring *)Realloc(*ar, sizeof(fstring)*(n+2));
4922 if (!tar)
4923 return False;
4924 else
4925 *ar = tar;
4926 fstrcpy((*ar)[n], f);
4927 n++;
4929 fstrcpy((*ar)[n], "");
4931 return True;
4937 /*******************************************************************
4938 read a UNICODE array with null terminated strings
4939 and null terminated array
4940 and size of array at beginning
4941 ********************************************************************/
4943 BOOL smb_io_unibuffer(char *desc, UNISTR2 *buffer, prs_struct *ps, int depth)
4945 if (buffer==NULL) return False;
4947 buffer->undoc=0;
4948 buffer->uni_str_len=buffer->uni_max_len;
4950 if(!prs_uint32("buffer_size", ps, depth, &buffer->uni_max_len))
4951 return False;
4953 if(!prs_unistr2(True, "buffer ", ps, depth, buffer))
4954 return False;
4956 return True;
4959 /*******************************************************************
4960 ********************************************************************/
4962 BOOL spool_io_printer_driver_info_level(char *desc, SPOOL_PRINTER_DRIVER_INFO_LEVEL *il, prs_struct *ps, int depth)
4964 prs_debug(ps, depth, desc, "spool_io_printer_driver_info_level");
4965 depth++;
4967 if(!prs_align(ps))
4968 return False;
4969 if(!prs_uint32("level", ps, depth, &il->level))
4970 return False;
4971 if(!prs_uint32("ptr", ps, depth, &il->ptr))
4972 return False;
4974 if (il->ptr==0)
4975 return True;
4977 switch (il->level) {
4978 case 3:
4979 if(!spool_io_printer_driver_info_level_3("", &il->info_3, ps, depth))
4980 return False;
4981 break;
4982 case 6:
4983 if(!spool_io_printer_driver_info_level_6("", &il->info_6, ps, depth))
4984 return False;
4985 break;
4986 default:
4987 return False;
4990 return True;
4993 /*******************************************************************
4994 init a SPOOL_Q_ADDPRINTERDRIVER struct
4995 ******************************************************************/
4997 BOOL make_spoolss_q_addprinterdriver(TALLOC_CTX *mem_ctx,
4998 SPOOL_Q_ADDPRINTERDRIVER *q_u, const char* srv_name,
4999 uint32 level, PRINTER_DRIVER_CTR *info)
5001 DEBUG(5,("make_spoolss_q_addprinterdriver\n"));
5003 q_u->server_name_ptr = (srv_name!=NULL)?1:0;
5004 init_unistr2(&q_u->server_name, srv_name, strlen(srv_name)+1);
5006 q_u->level = level;
5008 q_u->info.level = level;
5009 q_u->info.ptr = (info!=NULL)?1:0;
5010 switch (level)
5012 /* info level 3 is supported by Windows 95/98, WinNT and Win2k */
5013 case 3 :
5014 make_spoolss_driver_info_3(mem_ctx, &q_u->info.info_3, info->info3);
5015 break;
5017 default:
5018 DEBUG(0,("make_spoolss_q_addprinterdriver: Unknown info level [%d]\n", level));
5019 break;
5022 return True;
5025 BOOL make_spoolss_driver_info_3(TALLOC_CTX *mem_ctx,
5026 SPOOL_PRINTER_DRIVER_INFO_LEVEL_3 **spool_drv_info,
5027 DRIVER_INFO_3 *info3)
5029 uint32 len = 0;
5030 uint16 *ptr = info3->dependentfiles;
5031 BOOL done = False;
5032 BOOL null_char = False;
5033 SPOOL_PRINTER_DRIVER_INFO_LEVEL_3 *inf;
5035 if (!(inf=(SPOOL_PRINTER_DRIVER_INFO_LEVEL_3*)talloc_zero(mem_ctx, sizeof(SPOOL_PRINTER_DRIVER_INFO_LEVEL_3))))
5036 return False;
5038 inf->cversion = info3->version;
5039 inf->name_ptr = (info3->name.buffer!=NULL)?1:0;
5040 inf->environment_ptr = (info3->architecture.buffer!=NULL)?1:0;
5041 inf->driverpath_ptr = (info3->driverpath.buffer!=NULL)?1:0;
5042 inf->datafile_ptr = (info3->datafile.buffer!=NULL)?1:0;
5043 inf->configfile_ptr = (info3->configfile.buffer!=NULL)?1:0;
5044 inf->helpfile_ptr = (info3->helpfile.buffer!=NULL)?1:0;
5045 inf->monitorname_ptr = (info3->monitorname.buffer!=NULL)?1:0;
5046 inf->defaultdatatype_ptr = (info3->defaultdatatype.buffer!=NULL)?1:0;
5048 init_unistr2_from_unistr(&inf->name, &info3->name);
5049 init_unistr2_from_unistr(&inf->environment, &info3->architecture);
5050 init_unistr2_from_unistr(&inf->driverpath, &info3->driverpath);
5051 init_unistr2_from_unistr(&inf->datafile, &info3->datafile);
5052 init_unistr2_from_unistr(&inf->configfile, &info3->configfile);
5053 init_unistr2_from_unistr(&inf->helpfile, &info3->helpfile);
5054 init_unistr2_from_unistr(&inf->monitorname, &info3->monitorname);
5055 init_unistr2_from_unistr(&inf->defaultdatatype, &info3->defaultdatatype);
5057 while (!done)
5059 switch (*ptr)
5061 case 0:
5062 /* the null_char BOOL is used to help locate
5063 two '\0's back to back */
5064 if (null_char)
5065 done = True;
5066 else
5067 null_char = True;
5068 break;
5070 default:
5071 null_char = False;
5073 break;
5075 len++;
5076 ptr++;
5078 inf->dependentfiles_ptr = (info3->dependentfiles != NULL) ? 1 : 0;
5079 inf->dependentfilessize = len;
5080 if(!make_spoolss_buffer5(mem_ctx, &inf->dependentfiles, len, info3->dependentfiles))
5082 SAFE_FREE(inf);
5083 return False;
5086 *spool_drv_info = inf;
5088 return True;
5091 /*******************************************************************
5092 make a BUFFER5 struct from a uint16*
5093 ******************************************************************/
5094 BOOL make_spoolss_buffer5(TALLOC_CTX *mem_ctx, BUFFER5 *buf5, uint32 len, uint16 *src)
5097 buf5->buf_len = len;
5098 if((buf5->buffer=(uint16*)talloc_memdup(mem_ctx, src, sizeof(uint16)*len)) == NULL)
5100 DEBUG(0,("make_spoolss_buffer5: Unable to malloc memory for buffer!\n"));
5101 return False;
5104 return True;
5107 /*******************************************************************
5108 fill in the prs_struct for a ADDPRINTERDRIVER request PDU
5109 ********************************************************************/
5111 BOOL spoolss_io_q_addprinterdriver(char *desc, SPOOL_Q_ADDPRINTERDRIVER *q_u, prs_struct *ps, int depth)
5113 prs_debug(ps, depth, desc, "spoolss_io_q_addprinterdriver");
5114 depth++;
5116 if(!prs_align(ps))
5117 return False;
5119 if(!prs_uint32("server_name_ptr", ps, depth, &q_u->server_name_ptr))
5120 return False;
5121 if(!smb_io_unistr2("server_name", &q_u->server_name, q_u->server_name_ptr, ps, depth))
5122 return False;
5124 if(!prs_align(ps))
5125 return False;
5126 if(!prs_uint32("info_level", ps, depth, &q_u->level))
5127 return False;
5129 if(!spool_io_printer_driver_info_level("", &q_u->info, ps, depth))
5130 return False;
5132 return True;
5135 /*******************************************************************
5136 ********************************************************************/
5138 BOOL spoolss_io_r_addprinterdriver(char *desc, SPOOL_R_ADDPRINTERDRIVER *q_u, prs_struct *ps, int depth)
5140 prs_debug(ps, depth, desc, "spoolss_io_r_addprinterdriver");
5141 depth++;
5143 if(!prs_werror("status", ps, depth, &q_u->status))
5144 return False;
5146 return True;
5149 /*******************************************************************
5150 ********************************************************************/
5152 BOOL uni_2_asc_printer_driver_3(SPOOL_PRINTER_DRIVER_INFO_LEVEL_3 *uni,
5153 NT_PRINTER_DRIVER_INFO_LEVEL_3 **asc)
5155 NT_PRINTER_DRIVER_INFO_LEVEL_3 *d;
5157 DEBUG(7,("uni_2_asc_printer_driver_3: Converting from UNICODE to ASCII\n"));
5159 if (*asc==NULL)
5161 *asc=(NT_PRINTER_DRIVER_INFO_LEVEL_3 *)malloc(sizeof(NT_PRINTER_DRIVER_INFO_LEVEL_3));
5162 if(*asc == NULL)
5163 return False;
5164 ZERO_STRUCTP(*asc);
5167 d=*asc;
5169 d->cversion=uni->cversion;
5171 unistr2_to_ascii(d->name, &uni->name, sizeof(d->name)-1);
5172 unistr2_to_ascii(d->environment, &uni->environment, sizeof(d->environment)-1);
5173 unistr2_to_ascii(d->driverpath, &uni->driverpath, sizeof(d->driverpath)-1);
5174 unistr2_to_ascii(d->datafile, &uni->datafile, sizeof(d->datafile)-1);
5175 unistr2_to_ascii(d->configfile, &uni->configfile, sizeof(d->configfile)-1);
5176 unistr2_to_ascii(d->helpfile, &uni->helpfile, sizeof(d->helpfile)-1);
5177 unistr2_to_ascii(d->monitorname, &uni->monitorname, sizeof(d->monitorname)-1);
5178 unistr2_to_ascii(d->defaultdatatype, &uni->defaultdatatype, sizeof(d->defaultdatatype)-1);
5180 DEBUGADD(8,( "version: %d\n", d->cversion));
5181 DEBUGADD(8,( "name: %s\n", d->name));
5182 DEBUGADD(8,( "environment: %s\n", d->environment));
5183 DEBUGADD(8,( "driverpath: %s\n", d->driverpath));
5184 DEBUGADD(8,( "datafile: %s\n", d->datafile));
5185 DEBUGADD(8,( "configfile: %s\n", d->configfile));
5186 DEBUGADD(8,( "helpfile: %s\n", d->helpfile));
5187 DEBUGADD(8,( "monitorname: %s\n", d->monitorname));
5188 DEBUGADD(8,( "defaultdatatype: %s\n", d->defaultdatatype));
5190 if (uniarray_2_dosarray(&uni->dependentfiles, &d->dependentfiles ))
5191 return True;
5193 SAFE_FREE(*asc);
5194 return False;
5197 /*******************************************************************
5198 ********************************************************************/
5199 BOOL uni_2_asc_printer_driver_6(SPOOL_PRINTER_DRIVER_INFO_LEVEL_6 *uni,
5200 NT_PRINTER_DRIVER_INFO_LEVEL_6 **asc)
5202 NT_PRINTER_DRIVER_INFO_LEVEL_6 *d;
5204 DEBUG(7,("uni_2_asc_printer_driver_6: Converting from UNICODE to ASCII\n"));
5206 if (*asc==NULL)
5208 *asc=(NT_PRINTER_DRIVER_INFO_LEVEL_6 *)malloc(sizeof(NT_PRINTER_DRIVER_INFO_LEVEL_6));
5209 if(*asc == NULL)
5210 return False;
5211 ZERO_STRUCTP(*asc);
5214 d=*asc;
5216 d->version=uni->version;
5218 unistr2_to_ascii(d->name, &uni->name, sizeof(d->name)-1);
5219 unistr2_to_ascii(d->environment, &uni->environment, sizeof(d->environment)-1);
5220 unistr2_to_ascii(d->driverpath, &uni->driverpath, sizeof(d->driverpath)-1);
5221 unistr2_to_ascii(d->datafile, &uni->datafile, sizeof(d->datafile)-1);
5222 unistr2_to_ascii(d->configfile, &uni->configfile, sizeof(d->configfile)-1);
5223 unistr2_to_ascii(d->helpfile, &uni->helpfile, sizeof(d->helpfile)-1);
5224 unistr2_to_ascii(d->monitorname, &uni->monitorname, sizeof(d->monitorname)-1);
5225 unistr2_to_ascii(d->defaultdatatype, &uni->defaultdatatype, sizeof(d->defaultdatatype)-1);
5227 DEBUGADD(8,( "version: %d\n", d->version));
5228 DEBUGADD(8,( "name: %s\n", d->name));
5229 DEBUGADD(8,( "environment: %s\n", d->environment));
5230 DEBUGADD(8,( "driverpath: %s\n", d->driverpath));
5231 DEBUGADD(8,( "datafile: %s\n", d->datafile));
5232 DEBUGADD(8,( "configfile: %s\n", d->configfile));
5233 DEBUGADD(8,( "helpfile: %s\n", d->helpfile));
5234 DEBUGADD(8,( "monitorname: %s\n", d->monitorname));
5235 DEBUGADD(8,( "defaultdatatype: %s\n", d->defaultdatatype));
5237 if (!uniarray_2_dosarray(&uni->dependentfiles, &d->dependentfiles ))
5238 goto error;
5239 if (!uniarray_2_dosarray(&uni->previousnames, &d->previousnames ))
5240 goto error;
5242 return True;
5244 error:
5245 SAFE_FREE(*asc);
5246 return False;
5249 BOOL uni_2_asc_printer_info_2(const SPOOL_PRINTER_INFO_LEVEL_2 *uni,
5250 NT_PRINTER_INFO_LEVEL_2 **asc)
5252 NT_PRINTER_INFO_LEVEL_2 *d;
5253 time_t time_unix;
5255 DEBUG(7,("Converting from UNICODE to ASCII\n"));
5256 time_unix=time(NULL);
5258 if (*asc==NULL) {
5259 DEBUGADD(8,("allocating memory\n"));
5261 *asc=(NT_PRINTER_INFO_LEVEL_2 *)malloc(sizeof(NT_PRINTER_INFO_LEVEL_2));
5262 if(*asc == NULL)
5263 return False;
5264 ZERO_STRUCTP(*asc);
5266 /* we allocate memory iff called from
5267 * addprinter(ex) so we can do one time stuff here.
5269 (*asc)->setuptime=time_unix;
5272 DEBUGADD(8,("start converting\n"));
5274 d=*asc;
5276 d->attributes=uni->attributes;
5277 d->priority=uni->priority;
5278 d->default_priority=uni->default_priority;
5279 d->starttime=uni->starttime;
5280 d->untiltime=uni->untiltime;
5281 d->status=uni->status;
5282 d->cjobs=uni->cjobs;
5284 unistr2_to_ascii(d->servername, &uni->servername, sizeof(d->servername)-1);
5285 unistr2_to_ascii(d->printername, &uni->printername, sizeof(d->printername)-1);
5286 unistr2_to_ascii(d->sharename, &uni->sharename, sizeof(d->sharename)-1);
5287 unistr2_to_ascii(d->portname, &uni->portname, sizeof(d->portname)-1);
5288 unistr2_to_ascii(d->drivername, &uni->drivername, sizeof(d->drivername)-1);
5289 unistr2_to_ascii(d->comment, &uni->comment, sizeof(d->comment)-1);
5290 unistr2_to_ascii(d->location, &uni->location, sizeof(d->location)-1);
5291 unistr2_to_ascii(d->sepfile, &uni->sepfile, sizeof(d->sepfile)-1);
5292 unistr2_to_ascii(d->printprocessor, &uni->printprocessor, sizeof(d->printprocessor)-1);
5293 unistr2_to_ascii(d->datatype, &uni->datatype, sizeof(d->datatype)-1);
5294 unistr2_to_ascii(d->parameters, &uni->parameters, sizeof(d->parameters)-1);
5296 return True;
5299 /*******************************************************************
5300 * init a structure.
5301 ********************************************************************/
5303 BOOL make_spoolss_q_getprinterdriverdir(SPOOL_Q_GETPRINTERDRIVERDIR *q_u,
5304 fstring servername, fstring env_name, uint32 level,
5305 NEW_BUFFER *buffer, uint32 offered)
5307 init_buf_unistr2(&q_u->name, &q_u->name_ptr, servername);
5308 init_buf_unistr2(&q_u->environment, &q_u->environment_ptr, env_name);
5310 q_u->level=level;
5311 q_u->buffer=buffer;
5312 q_u->offered=offered;
5314 return True;
5317 /*******************************************************************
5318 Parse a SPOOL_Q_GETPRINTERDRIVERDIR structure.
5319 ********************************************************************/
5321 BOOL spoolss_io_q_getprinterdriverdir(char *desc, SPOOL_Q_GETPRINTERDRIVERDIR *q_u, prs_struct *ps, int depth)
5323 prs_debug(ps, depth, desc, "spoolss_io_q_getprinterdriverdir");
5324 depth++;
5326 if(!prs_align(ps))
5327 return False;
5328 if(!prs_uint32("name_ptr", ps, depth, &q_u->name_ptr))
5329 return False;
5330 if(!smb_io_unistr2("", &q_u->name, q_u->name_ptr, ps, depth))
5331 return False;
5333 if(!prs_align(ps))
5334 return False;
5336 if(!prs_uint32("", ps, depth, &q_u->environment_ptr))
5337 return False;
5338 if(!smb_io_unistr2("", &q_u->environment, q_u->environment_ptr, ps, depth))
5339 return False;
5341 if(!prs_align(ps))
5342 return False;
5344 if(!prs_uint32("level", ps, depth, &q_u->level))
5345 return False;
5347 if(!spoolss_io_buffer("", ps, depth, &q_u->buffer))
5348 return False;
5350 if(!prs_align(ps))
5351 return False;
5353 if(!prs_uint32("offered", ps, depth, &q_u->offered))
5354 return False;
5356 return True;
5359 /*******************************************************************
5360 Parse a SPOOL_R_GETPRINTERDRIVERDIR structure.
5361 ********************************************************************/
5363 BOOL spoolss_io_r_getprinterdriverdir(char *desc, SPOOL_R_GETPRINTERDRIVERDIR *r_u, prs_struct *ps, int depth)
5365 prs_debug(ps, depth, desc, "spoolss_io_r_getprinterdriverdir");
5366 depth++;
5368 if (!prs_align(ps))
5369 return False;
5371 if (!spoolss_io_buffer("", ps, depth, &r_u->buffer))
5372 return False;
5374 if (!prs_align(ps))
5375 return False;
5377 if (!prs_uint32("needed", ps, depth, &r_u->needed))
5378 return False;
5380 if (!prs_werror("status", ps, depth, &r_u->status))
5381 return False;
5383 return True;
5386 /*******************************************************************
5387 ********************************************************************/
5389 BOOL spoolss_io_r_enumprintprocessors(char *desc, SPOOL_R_ENUMPRINTPROCESSORS *r_u, prs_struct *ps, int depth)
5391 prs_debug(ps, depth, desc, "spoolss_io_r_enumprintprocessors");
5392 depth++;
5394 if (!prs_align(ps))
5395 return False;
5397 if (!spoolss_io_buffer("", ps, depth, &r_u->buffer))
5398 return False;
5400 if (!prs_align(ps))
5401 return False;
5403 if (!prs_uint32("needed", ps, depth, &r_u->needed))
5404 return False;
5406 if (!prs_uint32("returned", ps, depth, &r_u->returned))
5407 return False;
5409 if (!prs_werror("status", ps, depth, &r_u->status))
5410 return False;
5412 return True;
5415 /*******************************************************************
5416 ********************************************************************/
5418 BOOL spoolss_io_q_enumprintprocessors(char *desc, SPOOL_Q_ENUMPRINTPROCESSORS *q_u, prs_struct *ps, int depth)
5420 prs_debug(ps, depth, desc, "spoolss_io_q_enumprintprocessors");
5421 depth++;
5423 if (!prs_align(ps))
5424 return False;
5426 if (!prs_uint32("name_ptr", ps, depth, &q_u->name_ptr))
5427 return False;
5428 if (!smb_io_unistr2("name", &q_u->name, True, ps, depth))
5429 return False;
5431 if (!prs_align(ps))
5432 return False;
5434 if (!prs_uint32("", ps, depth, &q_u->environment_ptr))
5435 return False;
5436 if (!smb_io_unistr2("", &q_u->environment, q_u->environment_ptr, ps, depth))
5437 return False;
5439 if (!prs_align(ps))
5440 return False;
5442 if (!prs_uint32("level", ps, depth, &q_u->level))
5443 return False;
5445 if(!spoolss_io_buffer("", ps, depth, &q_u->buffer))
5446 return False;
5448 if (!prs_align(ps))
5449 return False;
5451 if (!prs_uint32("offered", ps, depth, &q_u->offered))
5452 return False;
5454 return True;
5457 /*******************************************************************
5458 ********************************************************************/
5460 BOOL spoolss_io_q_addprintprocessor(char *desc, SPOOL_Q_ADDPRINTPROCESSOR *q_u, prs_struct *ps, int depth)
5462 prs_debug(ps, depth, desc, "spoolss_io_q_addprintprocessor");
5463 depth++;
5465 if (!prs_align(ps))
5466 return False;
5468 if (!prs_uint32("server_ptr", ps, depth, &q_u->server_ptr))
5469 return False;
5470 if (!smb_io_unistr2("server", &q_u->server, q_u->server_ptr, ps, depth))
5471 return False;
5473 if (!prs_align(ps))
5474 return False;
5475 if (!smb_io_unistr2("environment", &q_u->environment, True, ps, depth))
5476 return False;
5478 if (!prs_align(ps))
5479 return False;
5480 if (!smb_io_unistr2("path", &q_u->path, True, ps, depth))
5481 return False;
5483 if (!prs_align(ps))
5484 return False;
5485 if (!smb_io_unistr2("name", &q_u->name, True, ps, depth))
5486 return False;
5488 return True;
5491 /*******************************************************************
5492 ********************************************************************/
5494 BOOL spoolss_io_r_addprintprocessor(char *desc, SPOOL_R_ADDPRINTPROCESSOR *r_u, prs_struct *ps, int depth)
5496 prs_debug(ps, depth, desc, "spoolss_io_r_addprintproicessor");
5497 depth++;
5499 if (!prs_align(ps))
5500 return False;
5502 if (!prs_werror("status", ps, depth, &r_u->status))
5503 return False;
5505 return True;
5508 /*******************************************************************
5509 ********************************************************************/
5511 BOOL spoolss_io_r_enumprintprocdatatypes(char *desc, SPOOL_R_ENUMPRINTPROCDATATYPES *r_u, prs_struct *ps, int depth)
5513 prs_debug(ps, depth, desc, "spoolss_io_r_enumprintprocdatatypes");
5514 depth++;
5516 if (!prs_align(ps))
5517 return False;
5519 if (!spoolss_io_buffer("", ps, depth, &r_u->buffer))
5520 return False;
5522 if (!prs_align(ps))
5523 return False;
5525 if (!prs_uint32("needed", ps, depth, &r_u->needed))
5526 return False;
5528 if (!prs_uint32("returned", ps, depth, &r_u->returned))
5529 return False;
5531 if (!prs_werror("status", ps, depth, &r_u->status))
5532 return False;
5534 return True;
5537 /*******************************************************************
5538 ********************************************************************/
5540 BOOL spoolss_io_q_enumprintprocdatatypes(char *desc, SPOOL_Q_ENUMPRINTPROCDATATYPES *q_u, prs_struct *ps, int depth)
5542 prs_debug(ps, depth, desc, "spoolss_io_q_enumprintprocdatatypes");
5543 depth++;
5545 if (!prs_align(ps))
5546 return False;
5548 if (!prs_uint32("name_ptr", ps, depth, &q_u->name_ptr))
5549 return False;
5550 if (!smb_io_unistr2("name", &q_u->name, True, ps, depth))
5551 return False;
5553 if (!prs_align(ps))
5554 return False;
5556 if (!prs_uint32("processor_ptr", ps, depth, &q_u->processor_ptr))
5557 return False;
5558 if (!smb_io_unistr2("processor", &q_u->processor, q_u->processor_ptr, ps, depth))
5559 return False;
5561 if (!prs_align(ps))
5562 return False;
5564 if (!prs_uint32("level", ps, depth, &q_u->level))
5565 return False;
5567 if(!spoolss_io_buffer("buffer", ps, depth, &q_u->buffer))
5568 return False;
5570 if (!prs_align(ps))
5571 return False;
5573 if (!prs_uint32("offered", ps, depth, &q_u->offered))
5574 return False;
5576 return True;
5579 /*******************************************************************
5580 Parse a SPOOL_Q_ENUMPRINTMONITORS structure.
5581 ********************************************************************/
5583 BOOL spoolss_io_q_enumprintmonitors(char *desc, SPOOL_Q_ENUMPRINTMONITORS *q_u, prs_struct *ps, int depth)
5585 prs_debug(ps, depth, desc, "spoolss_io_q_enumprintmonitors");
5586 depth++;
5588 if (!prs_align(ps))
5589 return False;
5591 if (!prs_uint32("name_ptr", ps, depth, &q_u->name_ptr))
5592 return False;
5593 if (!smb_io_unistr2("name", &q_u->name, True, ps, depth))
5594 return False;
5596 if (!prs_align(ps))
5597 return False;
5599 if (!prs_uint32("level", ps, depth, &q_u->level))
5600 return False;
5602 if(!spoolss_io_buffer("", ps, depth, &q_u->buffer))
5603 return False;
5605 if (!prs_align(ps))
5606 return False;
5608 if (!prs_uint32("offered", ps, depth, &q_u->offered))
5609 return False;
5611 return True;
5614 /*******************************************************************
5615 ********************************************************************/
5617 BOOL spoolss_io_r_enumprintmonitors(char *desc, SPOOL_R_ENUMPRINTMONITORS *r_u, prs_struct *ps, int depth)
5619 prs_debug(ps, depth, desc, "spoolss_io_r_enumprintmonitors");
5620 depth++;
5622 if (!prs_align(ps))
5623 return False;
5625 if (!spoolss_io_buffer("", ps, depth, &r_u->buffer))
5626 return False;
5628 if (!prs_align(ps))
5629 return False;
5631 if (!prs_uint32("needed", ps, depth, &r_u->needed))
5632 return False;
5634 if (!prs_uint32("returned", ps, depth, &r_u->returned))
5635 return False;
5637 if (!prs_werror("status", ps, depth, &r_u->status))
5638 return False;
5640 return True;
5643 /*******************************************************************
5644 ********************************************************************/
5646 BOOL spoolss_io_r_enumprinterdata(char *desc, SPOOL_R_ENUMPRINTERDATA *r_u, prs_struct *ps, int depth)
5648 prs_debug(ps, depth, desc, "spoolss_io_r_enumprinterdata");
5649 depth++;
5651 if(!prs_align(ps))
5652 return False;
5653 if(!prs_uint32("valuesize", ps, depth, &r_u->valuesize))
5654 return False;
5656 if(!prs_uint16uni(False, "value", ps, depth, r_u->value, r_u->valuesize ))
5657 return False;
5659 if(!prs_align(ps))
5660 return False;
5662 if(!prs_uint32("realvaluesize", ps, depth, &r_u->realvaluesize))
5663 return False;
5665 if(!prs_uint32("type", ps, depth, &r_u->type))
5666 return False;
5668 if(!prs_uint32("datasize", ps, depth, &r_u->datasize))
5669 return False;
5670 if(!prs_uint8s(False, "data", ps, depth, r_u->data, r_u->datasize))
5671 return False;
5672 if(!prs_align(ps))
5673 return False;
5675 if(!prs_uint32("realdatasize", ps, depth, &r_u->realdatasize))
5676 return False;
5677 if(!prs_werror("status", ps, depth, &r_u->status))
5678 return False;
5680 return True;
5683 /*******************************************************************
5684 ********************************************************************/
5686 BOOL spoolss_io_q_enumprinterdata(char *desc, SPOOL_Q_ENUMPRINTERDATA *q_u, prs_struct *ps, int depth)
5688 prs_debug(ps, depth, desc, "spoolss_io_q_enumprinterdata");
5689 depth++;
5691 if(!prs_align(ps))
5692 return False;
5693 if(!smb_io_pol_hnd("printer handle",&q_u->handle,ps,depth))
5694 return False;
5695 if(!prs_uint32("index", ps, depth, &q_u->index))
5696 return False;
5697 if(!prs_uint32("valuesize", ps, depth, &q_u->valuesize))
5698 return False;
5699 if(!prs_uint32("datasize", ps, depth, &q_u->datasize))
5700 return False;
5702 return True;
5705 /*******************************************************************
5706 ********************************************************************/
5708 BOOL make_spoolss_q_enumprinterdata(SPOOL_Q_ENUMPRINTERDATA *q_u,
5709 const POLICY_HND *hnd,
5710 uint32 idx, uint32 valuelen, uint32 datalen)
5712 memcpy(&q_u->handle, hnd, sizeof(q_u->handle));
5713 q_u->index=idx;
5714 q_u->valuesize=valuelen;
5715 q_u->datasize=datalen;
5717 return True;
5720 /*******************************************************************
5721 ********************************************************************/
5722 BOOL make_spoolss_q_setprinterdata(SPOOL_Q_SETPRINTERDATA *q_u, TALLOC_CTX *ctx, const POLICY_HND *hnd,
5723 char* value, char* data)
5725 UNISTR2 tmp;
5727 memcpy(&q_u->handle, hnd, sizeof(q_u->handle));
5728 q_u->type = REG_SZ;
5729 init_unistr2(&q_u->value, value, strlen(value)+1);
5731 init_unistr2(&tmp, data, strlen(data)+1);
5732 q_u->max_len = q_u->real_len = tmp.uni_max_len*2;
5733 q_u->data = talloc(ctx, q_u->real_len);
5734 memcpy(q_u->data, tmp.buffer, q_u->real_len);
5736 return True;
5738 /*******************************************************************
5739 ********************************************************************/
5741 BOOL spoolss_io_q_setprinterdata(char *desc, SPOOL_Q_SETPRINTERDATA *q_u, prs_struct *ps, int depth)
5743 prs_debug(ps, depth, desc, "spoolss_io_q_setprinterdata");
5744 depth++;
5746 if(!prs_align(ps))
5747 return False;
5748 if(!smb_io_pol_hnd("printer handle", &q_u->handle, ps, depth))
5749 return False;
5750 if(!smb_io_unistr2("", &q_u->value, True, ps, depth))
5751 return False;
5753 if(!prs_align(ps))
5754 return False;
5756 if(!prs_uint32("type", ps, depth, &q_u->type))
5757 return False;
5759 if(!prs_uint32("max_len", ps, depth, &q_u->max_len))
5760 return False;
5762 switch (q_u->type)
5764 case REG_SZ:
5765 case REG_BINARY:
5766 case REG_DWORD:
5767 case REG_MULTI_SZ:
5768 if (q_u->max_len) {
5769 if (UNMARSHALLING(ps))
5770 q_u->data=(uint8 *)prs_alloc_mem(ps, q_u->max_len * sizeof(uint8));
5771 if(q_u->data == NULL)
5772 return False;
5773 if(!prs_uint8s(False,"data", ps, depth, q_u->data, q_u->max_len))
5774 return False;
5776 if(!prs_align(ps))
5777 return False;
5778 break;
5781 if(!prs_uint32("real_len", ps, depth, &q_u->real_len))
5782 return False;
5784 return True;
5787 /*******************************************************************
5788 ********************************************************************/
5790 BOOL spoolss_io_r_setprinterdata(char *desc, SPOOL_R_SETPRINTERDATA *r_u, prs_struct *ps, int depth)
5792 prs_debug(ps, depth, desc, "spoolss_io_r_setprinterdata");
5793 depth++;
5795 if(!prs_align(ps))
5796 return False;
5797 if(!prs_werror("status", ps, depth, &r_u->status))
5798 return False;
5800 return True;
5803 /*******************************************************************
5804 ********************************************************************/
5805 BOOL spoolss_io_q_resetprinter(char *desc, SPOOL_Q_RESETPRINTER *q_u, prs_struct *ps, int depth)
5807 prs_debug(ps, depth, desc, "spoolss_io_q_resetprinter");
5808 depth++;
5810 if (!prs_align(ps))
5811 return False;
5812 if (!smb_io_pol_hnd("printer handle", &q_u->handle, ps, depth))
5813 return False;
5815 if (!prs_uint32("datatype_ptr", ps, depth, &q_u->datatype_ptr))
5816 return False;
5818 if (q_u->datatype_ptr) {
5819 if (!smb_io_unistr2("datatype", &q_u->datatype, q_u->datatype_ptr?True:False, ps, depth))
5820 return False;
5823 if (!spoolss_io_devmode_cont(desc, &q_u->devmode_ctr, ps, depth))
5824 return False;
5826 return True;
5830 /*******************************************************************
5831 ********************************************************************/
5832 BOOL spoolss_io_r_resetprinter(char *desc, SPOOL_R_RESETPRINTER *r_u, prs_struct *ps, int depth)
5834 prs_debug(ps, depth, desc, "spoolss_io_r_resetprinter");
5835 depth++;
5837 if(!prs_align(ps))
5838 return False;
5839 if(!prs_werror("status", ps, depth, &r_u->status))
5840 return False;
5842 return True;
5845 /*******************************************************************
5846 ********************************************************************/
5847 BOOL convert_specific_param(NT_PRINTER_PARAM **param, const UNISTR2 *value,
5848 uint32 type, const uint8 *data, uint32 len)
5850 DEBUG(5,("converting a specific param struct\n"));
5852 if (*param == NULL)
5854 *param=(NT_PRINTER_PARAM *)malloc(sizeof(NT_PRINTER_PARAM));
5855 if(*param == NULL)
5856 return False;
5857 memset((char *)*param, '\0', sizeof(NT_PRINTER_PARAM));
5858 DEBUGADD(6,("Allocated a new PARAM struct\n"));
5860 unistr2_to_ascii((*param)->value, value, sizeof((*param)->value)-1);
5861 (*param)->type = type;
5863 /* le champ data n'est pas NULL termine */
5864 /* on stocke donc la longueur */
5866 (*param)->data_len=len;
5868 if (len) {
5869 (*param)->data=(uint8 *)malloc(len * sizeof(uint8));
5870 if((*param)->data == NULL)
5871 return False;
5872 memcpy((*param)->data, data, len);
5875 DEBUGADD(6,("\tvalue:[%s], len:[%d]\n",(*param)->value, (*param)->data_len));
5876 dump_data(10, (char *)(*param)->data, (*param)->data_len);
5878 return True;
5881 /*******************************************************************
5882 ********************************************************************/
5884 static BOOL spoolss_io_addform(char *desc, FORM *f, uint32 ptr, prs_struct *ps, int depth)
5886 prs_debug(ps, depth, desc, "spoolss_io_addform");
5887 depth++;
5888 if(!prs_align(ps))
5889 return False;
5891 if (ptr!=0)
5893 if(!prs_uint32("flags", ps, depth, &f->flags))
5894 return False;
5895 if(!prs_uint32("name_ptr", ps, depth, &f->name_ptr))
5896 return False;
5897 if(!prs_uint32("size_x", ps, depth, &f->size_x))
5898 return False;
5899 if(!prs_uint32("size_y", ps, depth, &f->size_y))
5900 return False;
5901 if(!prs_uint32("left", ps, depth, &f->left))
5902 return False;
5903 if(!prs_uint32("top", ps, depth, &f->top))
5904 return False;
5905 if(!prs_uint32("right", ps, depth, &f->right))
5906 return False;
5907 if(!prs_uint32("bottom", ps, depth, &f->bottom))
5908 return False;
5910 if(!smb_io_unistr2("", &f->name, f->name_ptr, ps, depth))
5911 return False;
5914 return True;
5917 /*******************************************************************
5918 ********************************************************************/
5920 BOOL spoolss_io_q_deleteform(char *desc, SPOOL_Q_DELETEFORM *q_u, prs_struct *ps, int depth)
5922 prs_debug(ps, depth, desc, "spoolss_io_q_deleteform");
5923 depth++;
5925 if(!prs_align(ps))
5926 return False;
5927 if(!smb_io_pol_hnd("printer handle", &q_u->handle, ps, depth))
5928 return False;
5929 if(!smb_io_unistr2("form name", &q_u->name, True, ps, depth))
5930 return False;
5932 return True;
5935 /*******************************************************************
5936 ********************************************************************/
5938 BOOL spoolss_io_r_deleteform(char *desc, SPOOL_R_DELETEFORM *r_u, prs_struct *ps, int depth)
5940 prs_debug(ps, depth, desc, "spoolss_io_r_deleteform");
5941 depth++;
5943 if(!prs_align(ps))
5944 return False;
5945 if(!prs_werror("status", ps, depth, &r_u->status))
5946 return False;
5948 return True;
5951 /*******************************************************************
5952 ********************************************************************/
5954 BOOL spoolss_io_q_addform(char *desc, SPOOL_Q_ADDFORM *q_u, prs_struct *ps, int depth)
5956 uint32 useless_ptr=1;
5957 prs_debug(ps, depth, desc, "spoolss_io_q_addform");
5958 depth++;
5960 if(!prs_align(ps))
5961 return False;
5962 if(!smb_io_pol_hnd("printer handle", &q_u->handle, ps, depth))
5963 return False;
5964 if(!prs_uint32("level", ps, depth, &q_u->level))
5965 return False;
5966 if(!prs_uint32("level2", ps, depth, &q_u->level2))
5967 return False;
5969 if (q_u->level==1)
5971 if(!prs_uint32("useless_ptr", ps, depth, &useless_ptr))
5972 return False;
5973 if(!spoolss_io_addform("", &q_u->form, useless_ptr, ps, depth))
5974 return False;
5977 return True;
5980 /*******************************************************************
5981 ********************************************************************/
5983 BOOL spoolss_io_r_addform(char *desc, SPOOL_R_ADDFORM *r_u, prs_struct *ps, int depth)
5985 prs_debug(ps, depth, desc, "spoolss_io_r_addform");
5986 depth++;
5988 if(!prs_align(ps))
5989 return False;
5990 if(!prs_werror("status", ps, depth, &r_u->status))
5991 return False;
5993 return True;
5996 /*******************************************************************
5997 ********************************************************************/
5999 BOOL spoolss_io_q_setform(char *desc, SPOOL_Q_SETFORM *q_u, prs_struct *ps, int depth)
6001 uint32 useless_ptr=1;
6002 prs_debug(ps, depth, desc, "spoolss_io_q_setform");
6003 depth++;
6005 if(!prs_align(ps))
6006 return False;
6007 if(!smb_io_pol_hnd("printer handle", &q_u->handle, ps, depth))
6008 return False;
6009 if(!smb_io_unistr2("", &q_u->name, True, ps, depth))
6010 return False;
6012 if(!prs_align(ps))
6013 return False;
6015 if(!prs_uint32("level", ps, depth, &q_u->level))
6016 return False;
6017 if(!prs_uint32("level2", ps, depth, &q_u->level2))
6018 return False;
6020 if (q_u->level==1)
6022 if(!prs_uint32("useless_ptr", ps, depth, &useless_ptr))
6023 return False;
6024 if(!spoolss_io_addform("", &q_u->form, useless_ptr, ps, depth))
6025 return False;
6028 return True;
6031 /*******************************************************************
6032 ********************************************************************/
6034 BOOL spoolss_io_r_setform(char *desc, SPOOL_R_SETFORM *r_u, prs_struct *ps, int depth)
6036 prs_debug(ps, depth, desc, "spoolss_io_r_setform");
6037 depth++;
6039 if(!prs_align(ps))
6040 return False;
6041 if(!prs_werror("status", ps, depth, &r_u->status))
6042 return False;
6044 return True;
6047 /*******************************************************************
6048 Parse a SPOOL_R_GETJOB structure.
6049 ********************************************************************/
6051 BOOL spoolss_io_r_getjob(char *desc, SPOOL_R_GETJOB *r_u, prs_struct *ps, int depth)
6053 prs_debug(ps, depth, desc, "spoolss_io_r_getjob");
6054 depth++;
6056 if (!prs_align(ps))
6057 return False;
6059 if (!spoolss_io_buffer("", ps, depth, &r_u->buffer))
6060 return False;
6062 if (!prs_align(ps))
6063 return False;
6065 if (!prs_uint32("needed", ps, depth, &r_u->needed))
6066 return False;
6068 if (!prs_werror("status", ps, depth, &r_u->status))
6069 return False;
6071 return True;
6074 /*******************************************************************
6075 Parse a SPOOL_Q_GETJOB structure.
6076 ********************************************************************/
6078 BOOL spoolss_io_q_getjob(char *desc, SPOOL_Q_GETJOB *q_u, prs_struct *ps, int depth)
6080 prs_debug(ps, depth, desc, "");
6081 depth++;
6083 if(!prs_align(ps))
6084 return False;
6086 if(!smb_io_pol_hnd("printer handle",&q_u->handle,ps,depth))
6087 return False;
6088 if(!prs_uint32("jobid", ps, depth, &q_u->jobid))
6089 return False;
6090 if(!prs_uint32("level", ps, depth, &q_u->level))
6091 return False;
6093 if(!spoolss_io_buffer("", ps, depth, &q_u->buffer))
6094 return False;
6096 if(!prs_align(ps))
6097 return False;
6099 if(!prs_uint32("offered", ps, depth, &q_u->offered))
6100 return False;
6102 return True;
6105 void free_devmode(DEVICEMODE *devmode)
6107 if (devmode!=NULL) {
6108 SAFE_FREE(devmode->private);
6109 SAFE_FREE(devmode);
6113 void free_printer_info_1(PRINTER_INFO_1 *printer)
6115 SAFE_FREE(printer);
6118 void free_printer_info_2(PRINTER_INFO_2 *printer)
6120 if (printer!=NULL) {
6121 free_devmode(printer->devmode);
6122 printer->devmode = NULL;
6123 SAFE_FREE(printer);
6127 void free_printer_info_3(PRINTER_INFO_3 *printer)
6129 SAFE_FREE(printer);
6132 void free_printer_info_4(PRINTER_INFO_4 *printer)
6134 SAFE_FREE(printer);
6137 void free_printer_info_5(PRINTER_INFO_5 *printer)
6139 SAFE_FREE(printer);
6142 void free_job_info_2(JOB_INFO_2 *job)
6144 if (job!=NULL)
6145 free_devmode(job->devmode);
6148 /*******************************************************************
6149 * init a structure.
6150 ********************************************************************/
6152 BOOL make_spoolss_q_replyopenprinter(SPOOL_Q_REPLYOPENPRINTER *q_u,
6153 const fstring string, uint32 printer, uint32 type)
6155 if (q_u == NULL)
6156 return False;
6158 init_unistr2(&q_u->string, string, strlen(string)+1);
6160 q_u->printer=printer;
6161 q_u->type=type;
6163 q_u->unknown0=0x0;
6164 q_u->unknown1=0x0;
6166 return True;
6169 /*******************************************************************
6170 Parse a SPOOL_Q_REPLYOPENPRINTER structure.
6171 ********************************************************************/
6173 BOOL spoolss_io_q_replyopenprinter(char *desc, SPOOL_Q_REPLYOPENPRINTER *q_u, prs_struct *ps, int depth)
6175 prs_debug(ps, depth, desc, "spoolss_io_q_replyopenprinter");
6176 depth++;
6178 if(!prs_align(ps))
6179 return False;
6181 if(!smb_io_unistr2("", &q_u->string, True, ps, depth))
6182 return False;
6184 if(!prs_align(ps))
6185 return False;
6187 if(!prs_uint32("printer", ps, depth, &q_u->printer))
6188 return False;
6189 if(!prs_uint32("type", ps, depth, &q_u->type))
6190 return False;
6192 if(!prs_uint32("unknown0", ps, depth, &q_u->unknown0))
6193 return False;
6194 if(!prs_uint32("unknown1", ps, depth, &q_u->unknown1))
6195 return False;
6197 return True;
6200 /*******************************************************************
6201 Parse a SPOOL_R_REPLYOPENPRINTER structure.
6202 ********************************************************************/
6204 BOOL spoolss_io_r_replyopenprinter(char *desc, SPOOL_R_REPLYOPENPRINTER *r_u, prs_struct *ps, int depth)
6206 prs_debug(ps, depth, desc, "spoolss_io_r_replyopenprinter");
6207 depth++;
6209 if (!prs_align(ps))
6210 return False;
6212 if(!smb_io_pol_hnd("printer handle",&r_u->handle,ps,depth))
6213 return False;
6215 if (!prs_werror("status", ps, depth, &r_u->status))
6216 return False;
6218 return True;
6221 /*******************************************************************
6222 * init a structure.
6223 ********************************************************************/
6224 BOOL make_spoolss_q_routerreplyprinter(SPOOL_Q_ROUTERREPLYPRINTER *q_u, POLICY_HND *hnd,
6225 uint32 condition, uint32 change_id)
6228 memcpy(&q_u->handle, hnd, sizeof(q_u->handle));
6230 q_u->condition = condition;
6231 q_u->change_id = change_id;
6233 /* magic values */
6234 q_u->unknown1 = 0x1;
6235 memset(q_u->unknown2, 0x0, 5);
6236 q_u->unknown2[0] = 0x1;
6238 return True;
6241 /*******************************************************************
6242 Parse a SPOOL_Q_ROUTERREPLYPRINTER structure.
6243 ********************************************************************/
6244 BOOL spoolss_io_q_routerreplyprinter (char *desc, SPOOL_Q_ROUTERREPLYPRINTER *q_u, prs_struct *ps, int depth)
6247 prs_debug(ps, depth, desc, "spoolss_io_q_routerreplyprinter");
6248 depth++;
6250 if (!prs_align(ps))
6251 return False;
6253 if(!smb_io_pol_hnd("printer handle",&q_u->handle,ps,depth))
6254 return False;
6256 if (!prs_uint32("condition", ps, depth, &q_u->condition))
6257 return False;
6259 if (!prs_uint32("unknown1", ps, depth, &q_u->unknown1))
6260 return False;
6262 if (!prs_uint32("change_id", ps, depth, &q_u->change_id))
6263 return False;
6265 if (!prs_uint8s(False, "private", ps, depth, q_u->unknown2, 5))
6266 return False;
6268 return True;
6271 /*******************************************************************
6272 Parse a SPOOL_R_ROUTERREPLYPRINTER structure.
6273 ********************************************************************/
6274 BOOL spoolss_io_r_routerreplyprinter (char *desc, SPOOL_R_ROUTERREPLYPRINTER *r_u, prs_struct *ps, int depth)
6276 prs_debug(ps, depth, desc, "spoolss_io_r_routerreplyprinter");
6277 depth++;
6279 if (!prs_align(ps))
6280 return False;
6282 if (!prs_werror("status", ps, depth, &r_u->status))
6283 return False;
6285 return True;
6288 /*******************************************************************
6289 * init a structure.
6290 ********************************************************************/
6292 BOOL make_spoolss_q_reply_closeprinter(SPOOL_Q_REPLYCLOSEPRINTER *q_u, POLICY_HND *hnd)
6294 if (q_u == NULL)
6295 return False;
6297 memcpy(&q_u->handle, hnd, sizeof(q_u->handle));
6299 return True;
6302 /*******************************************************************
6303 Parse a SPOOL_Q_REPLYCLOSEPRINTER structure.
6304 ********************************************************************/
6306 BOOL spoolss_io_q_replycloseprinter(char *desc, SPOOL_Q_REPLYCLOSEPRINTER *q_u, prs_struct *ps, int depth)
6308 prs_debug(ps, depth, desc, "spoolss_io_q_replycloseprinter");
6309 depth++;
6311 if(!prs_align(ps))
6312 return False;
6314 if(!smb_io_pol_hnd("printer handle",&q_u->handle,ps,depth))
6315 return False;
6317 return True;
6320 /*******************************************************************
6321 Parse a SPOOL_R_REPLYCLOSEPRINTER structure.
6322 ********************************************************************/
6324 BOOL spoolss_io_r_replycloseprinter(char *desc, SPOOL_R_REPLYCLOSEPRINTER *r_u, prs_struct *ps, int depth)
6326 prs_debug(ps, depth, desc, "spoolss_io_r_replycloseprinter");
6327 depth++;
6329 if (!prs_align(ps))
6330 return False;
6332 if(!smb_io_pol_hnd("printer handle",&r_u->handle,ps,depth))
6333 return False;
6335 if (!prs_werror("status", ps, depth, &r_u->status))
6336 return False;
6338 return True;
6341 #if 0 /* JERRY - not currently used but could be :-) */
6343 /*******************************************************************
6344 Deep copy a SPOOL_NOTIFY_INFO_DATA structure
6345 ******************************************************************/
6346 static BOOL copy_spool_notify_info_data(SPOOL_NOTIFY_INFO_DATA *dst,
6347 SPOOL_NOTIFY_INFO_DATA *src, int n)
6349 int i;
6351 memcpy(dst, src, sizeof(SPOOL_NOTIFY_INFO_DATA)*n);
6353 for (i=0; i<n; i++) {
6354 int len;
6355 uint16 *s = NULL;
6357 if (src->size != POINTER)
6358 continue;
6359 len = src->notify_data.data.length;
6360 s = malloc(sizeof(uint16)*len);
6361 if (s == NULL) {
6362 DEBUG(0,("copy_spool_notify_info_data: malloc() failed!\n"));
6363 return False;
6366 memcpy(s, src->notify_data.data.string, len*2);
6367 dst->notify_data.data.string = s;
6370 return True;
6373 /*******************************************************************
6374 Deep copy a SPOOL_NOTIFY_INFO structure
6375 ******************************************************************/
6376 static BOOL copy_spool_notify_info(SPOOL_NOTIFY_INFO *dst, SPOOL_NOTIFY_INFO *src)
6378 if (!dst) {
6379 DEBUG(0,("copy_spool_notify_info: NULL destination pointer!\n"));
6380 return False;
6383 dst->version = src->version;
6384 dst->flags = src->flags;
6385 dst->count = src->count;
6387 if (dst->count)
6389 dst->data = malloc(dst->count * sizeof(SPOOL_NOTIFY_INFO_DATA));
6391 DEBUG(10,("copy_spool_notify_info: allocating space for [%d] PRINTER_NOTIFY_INFO_DATA entries\n",
6392 dst->count));
6394 if (dst->data == NULL) {
6395 DEBUG(0,("copy_spool_notify_info: malloc() failed for [%d] entries!\n",
6396 dst->count));
6397 return False;
6400 return (copy_spool_notify_info_data(dst->data, src->data, src->count));
6403 return True;
6405 #endif /* JERRY */
6407 /*******************************************************************
6408 * init a structure.
6409 ********************************************************************/
6411 BOOL make_spoolss_q_reply_rrpcn(SPOOL_Q_REPLY_RRPCN *q_u, POLICY_HND *hnd,
6412 uint32 change_low, uint32 change_high,
6413 SPOOL_NOTIFY_INFO *info)
6415 if (q_u == NULL)
6416 return False;
6418 memcpy(&q_u->handle, hnd, sizeof(q_u->handle));
6420 q_u->change_low=change_low;
6421 q_u->change_high=change_high;
6423 q_u->unknown0=0x0;
6424 q_u->unknown1=0x0;
6426 q_u->info_ptr=0xaddee11e;
6428 q_u->info.version=2;
6430 if (info->count) {
6431 DEBUG(10,("make_spoolss_q_reply_rrpcn: [%d] PRINTER_NOTIFY_INFO_DATA\n",
6432 info->count));
6433 q_u->info.version = info->version;
6434 q_u->info.flags = info->flags;
6435 q_u->info.count = info->count;
6436 /* pointer field - be careful! */
6437 q_u->info.data = info->data;
6439 else {
6440 q_u->info.flags=PRINTER_NOTIFY_INFO_DISCARDED;
6441 q_u->info.count=0;
6444 return True;
6447 /*******************************************************************
6448 Parse a SPOOL_Q_REPLY_RRPCN structure.
6449 ********************************************************************/
6451 BOOL spoolss_io_q_reply_rrpcn(char *desc, SPOOL_Q_REPLY_RRPCN *q_u, prs_struct *ps, int depth)
6453 prs_debug(ps, depth, desc, "spoolss_io_q_reply_rrpcn");
6454 depth++;
6456 if(!prs_align(ps))
6457 return False;
6459 if(!smb_io_pol_hnd("printer handle",&q_u->handle,ps,depth))
6460 return False;
6462 if (!prs_uint32("change_low", ps, depth, &q_u->change_low))
6463 return False;
6465 if (!prs_uint32("change_high", ps, depth, &q_u->change_high))
6466 return False;
6468 if (!prs_uint32("unknown0", ps, depth, &q_u->unknown0))
6469 return False;
6471 if (!prs_uint32("unknown1", ps, depth, &q_u->unknown1))
6472 return False;
6474 if (!prs_uint32("info_ptr", ps, depth, &q_u->info_ptr))
6475 return False;
6477 if(q_u->info_ptr!=0)
6478 if(!smb_io_notify_info(desc, &q_u->info, ps, depth))
6479 return False;
6481 return True;
6484 /*******************************************************************
6485 Parse a SPOOL_R_REPLY_RRPCN structure.
6486 ********************************************************************/
6488 BOOL spoolss_io_r_reply_rrpcn(char *desc, SPOOL_R_REPLY_RRPCN *r_u, prs_struct *ps, int depth)
6490 prs_debug(ps, depth, desc, "spoolss_io_r_reply_rrpcn");
6491 depth++;
6493 if (!prs_align(ps))
6494 return False;
6496 if (!prs_uint32("unknown0", ps, depth, &r_u->unknown0))
6497 return False;
6499 if (!prs_werror("status", ps, depth, &r_u->status))
6500 return False;
6502 return True;
6505 /*******************************************************************
6506 * read a structure.
6507 * called from spoolss_q_getprinterdataex (srv_spoolss.c)
6508 ********************************************************************/
6510 BOOL spoolss_io_q_getprinterdataex(char *desc, SPOOL_Q_GETPRINTERDATAEX *q_u, prs_struct *ps, int depth)
6512 if (q_u == NULL)
6513 return False;
6515 prs_debug(ps, depth, desc, "spoolss_io_q_getprinterdataex");
6516 depth++;
6518 if (!prs_align(ps))
6519 return False;
6520 if (!smb_io_pol_hnd("printer handle",&q_u->handle,ps,depth))
6521 return False;
6522 if (!prs_align(ps))
6523 return False;
6524 if (!smb_io_unistr2("keyname", &q_u->keyname,True,ps,depth))
6525 return False;
6526 if (!prs_align(ps))
6527 return False;
6528 if (!smb_io_unistr2("valuename", &q_u->valuename,True,ps,depth))
6529 return False;
6530 if (!prs_align(ps))
6531 return False;
6532 if (!prs_uint32("size", ps, depth, &q_u->size))
6533 return False;
6535 return True;
6538 /*******************************************************************
6539 * write a structure.
6540 * called from spoolss_r_getprinterdataex (srv_spoolss.c)
6541 ********************************************************************/
6543 BOOL spoolss_io_r_getprinterdataex(char *desc, SPOOL_R_GETPRINTERDATAEX *r_u, prs_struct *ps, int depth)
6545 if (r_u == NULL)
6546 return False;
6548 prs_debug(ps, depth, desc, "spoolss_io_r_getprinterdataex");
6549 depth++;
6551 if (!prs_align(ps))
6552 return False;
6553 if (!prs_uint32("type", ps, depth, &r_u->type))
6554 return False;
6555 if (!prs_uint32("size", ps, depth, &r_u->size))
6556 return False;
6558 if (!prs_uint8s(False,"data", ps, depth, r_u->data, r_u->size))
6559 return False;
6561 if (!prs_align(ps))
6562 return False;
6564 if (!prs_uint32("needed", ps, depth, &r_u->needed))
6565 return False;
6566 if (!prs_werror("status", ps, depth, &r_u->status))
6567 return False;
6569 return True;
6572 /*******************************************************************
6573 * read a structure.
6574 ********************************************************************/
6576 BOOL spoolss_io_q_setprinterdataex(char *desc, SPOOL_Q_SETPRINTERDATAEX *q_u, prs_struct *ps, int depth)
6578 prs_debug(ps, depth, desc, "spoolss_io_q_setprinterdataex");
6579 depth++;
6581 if(!prs_align(ps))
6582 return False;
6583 if(!smb_io_pol_hnd("printer handle", &q_u->handle, ps, depth))
6584 return False;
6585 if(!smb_io_unistr2("", &q_u->key, True, ps, depth))
6586 return False;
6588 if(!prs_align(ps))
6589 return False;
6591 if(!smb_io_unistr2("", &q_u->value, True, ps, depth))
6592 return False;
6594 if(!prs_align(ps))
6595 return False;
6597 if(!prs_uint32("type", ps, depth, &q_u->type))
6598 return False;
6600 if(!prs_uint32("max_len", ps, depth, &q_u->max_len))
6601 return False;
6603 switch (q_u->type)
6605 case 0x1:
6606 case 0x3:
6607 case 0x4:
6608 case 0x7:
6609 if (q_u->max_len) {
6610 if (UNMARSHALLING(ps))
6611 q_u->data=(uint8 *)prs_alloc_mem(ps, q_u->max_len * sizeof(uint8));
6612 if(q_u->data == NULL)
6613 return False;
6614 if(!prs_uint8s(False,"data", ps, depth, q_u->data, q_u->max_len))
6615 return False;
6617 if(!prs_align(ps))
6618 return False;
6619 break;
6622 if(!prs_uint32("real_len", ps, depth, &q_u->real_len))
6623 return False;
6625 return True;
6628 /*******************************************************************
6629 * write a structure.
6630 ********************************************************************/
6632 BOOL spoolss_io_r_setprinterdataex(char *desc, SPOOL_R_SETPRINTERDATAEX *r_u, prs_struct *ps, int depth)
6634 prs_debug(ps, depth, desc, "spoolss_io_r_setprinterdataex");
6635 depth++;
6637 if(!prs_align(ps))
6638 return False;
6639 if(!prs_werror("status", ps, depth, &r_u->status))
6640 return False;
6642 return True;
6646 /*******************************************************************
6647 * read a structure.
6648 ********************************************************************/
6650 BOOL spoolss_io_q_enumprinterkey(char *desc, SPOOL_Q_ENUMPRINTERKEY *q_u, prs_struct *ps, int depth)
6652 prs_debug(ps, depth, desc, "spoolss_io_q_enumprinterkey");
6653 depth++;
6655 if(!prs_align(ps))
6656 return False;
6657 if(!smb_io_pol_hnd("printer handle", &q_u->handle, ps, depth))
6658 return False;
6660 if(!smb_io_unistr2("", &q_u->key, True, ps, depth))
6661 return False;
6663 if(!prs_align(ps))
6664 return False;
6666 if(!prs_uint32("size", ps, depth, &q_u->size))
6667 return False;
6669 return True;
6672 /*******************************************************************
6673 * write a structure.
6674 ********************************************************************/
6676 BOOL spoolss_io_r_enumprinterkey(char *desc, SPOOL_R_ENUMPRINTERKEY *r_u, prs_struct *ps, int depth)
6678 prs_debug(ps, depth, desc, "spoolss_io_r_enumprinterkey");
6679 depth++;
6681 if(!prs_align(ps))
6682 return False;
6684 if (!smb_io_buffer5("", &r_u->keys, ps, depth))
6685 return False;
6687 if(!prs_align(ps))
6688 return False;
6690 if(!prs_uint32("needed", ps, depth, &r_u->needed))
6691 return False;
6693 if(!prs_werror("status", ps, depth, &r_u->status))
6694 return False;
6696 return True;
6700 /*******************************************************************
6701 * read a structure.
6702 ********************************************************************/
6704 BOOL spoolss_io_q_enumprinterdataex(char *desc, SPOOL_Q_ENUMPRINTERDATAEX *q_u, prs_struct *ps, int depth)
6706 prs_debug(ps, depth, desc, "spoolss_io_q_enumprinterdataex");
6707 depth++;
6709 if(!prs_align(ps))
6710 return False;
6711 if(!smb_io_pol_hnd("printer handle", &q_u->handle, ps, depth))
6712 return False;
6714 if(!smb_io_unistr2("", &q_u->key, True, ps, depth))
6715 return False;
6717 if(!prs_align(ps))
6718 return False;
6720 if(!prs_uint32("size", ps, depth, &q_u->size))
6721 return False;
6723 return True;
6726 /*******************************************************************
6727 ********************************************************************/
6728 static BOOL spoolss_io_printer_enum_values_ctr(char *desc, prs_struct *ps,
6729 PRINTER_ENUM_VALUES_CTR *ctr, int depth)
6731 int i;
6732 uint32 valuename_offset,
6733 data_offset,
6734 current_offset;
6735 const uint32 basic_unit = 20; /* size of static portion of enum_values */
6737 prs_debug(ps, depth, desc, "spoolss_io_printer_enum_values_ctr");
6738 depth++;
6740 if (!prs_uint32("size", ps, depth, &ctr->size))
6741 return False;
6743 /* offset data begins at 20 bytes per structure * size_of_array.
6744 Don't forget the uint32 at the beginning */
6746 current_offset = basic_unit * ctr->size_of_array;
6748 /* first loop to write basic enum_value information */
6750 for (i=0; i<ctr->size_of_array; i++)
6752 valuename_offset = current_offset;
6753 if (!prs_uint32("valuename_offset", ps, depth, &valuename_offset))
6754 return False;
6756 if (!prs_uint32("value_len", ps, depth, &ctr->values[i].value_len))
6757 return False;
6759 if (!prs_uint32("type", ps, depth, &ctr->values[i].type))
6760 return False;
6762 data_offset = ctr->values[i].value_len + valuename_offset;
6763 if (!prs_uint32("data_offset", ps, depth, &data_offset))
6764 return False;
6766 if (!prs_uint32("data_len", ps, depth, &ctr->values[i].data_len))
6767 return False;
6769 current_offset = data_offset + ctr->values[i].data_len - basic_unit;
6772 /* loop #2 for writing the dynamically size objects
6773 while viewing conversations between Win2k -> Win2k,
6774 4-byte alignment does not seem to matter here --jerry */
6776 for (i=0; i<ctr->size_of_array; i++)
6779 if (!prs_unistr("valuename", ps, depth, &ctr->values[i].valuename))
6780 return False;
6782 if (!prs_uint8s(False, "data", ps, depth, ctr->values[i].data, ctr->values[i].data_len))
6783 return False;
6788 return True;
6792 /*******************************************************************
6793 * write a structure.
6794 ********************************************************************/
6796 BOOL spoolss_io_r_enumprinterdataex(char *desc, SPOOL_R_ENUMPRINTERDATAEX *r_u, prs_struct *ps, int depth)
6798 prs_debug(ps, depth, desc, "spoolss_io_r_enumprinterdataex");
6799 depth++;
6801 if(!prs_align(ps))
6802 return False;
6804 if (!spoolss_io_printer_enum_values_ctr("", ps, &r_u->ctr, depth ))
6805 return False;
6807 if(!prs_align(ps))
6808 return False;
6810 if(!prs_uint32("needed", ps, depth, &r_u->needed))
6811 return False;
6813 if(!prs_uint32("returned", ps, depth, &r_u->returned))
6814 return False;
6816 if(!prs_werror("status", ps, depth, &r_u->status))
6817 return False;
6819 return True;
6823 /*******************************************************************
6824 * write a structure.
6825 ********************************************************************/
6828 uint32 GetPrintProcessorDirectory(
6829 [in] unistr2 *name,
6830 [in] unistr2 *environment,
6831 [in] uint32 level,
6832 [in,out] NEW_BUFFER buffer,
6833 [in] uint32 offered,
6834 [out] uint32 needed,
6835 [out] uint32 returned
6840 BOOL make_spoolss_q_getprintprocessordirectory(SPOOL_Q_GETPRINTPROCESSORDIRECTORY *q_u, const char *name, char *environment, int level, NEW_BUFFER *buffer, uint32 offered)
6842 DEBUG(5,("make_spoolss_q_getprintprocessordirectory\n"));
6844 init_unistr2(&q_u->name, name, strlen(name)+1);
6845 init_unistr2(&q_u->environment, environment, strlen(environment)+1);
6847 q_u->level = level;
6849 q_u->buffer = buffer;
6850 q_u->offered = offered;
6852 return True;
6855 BOOL spoolss_io_q_getprintprocessordirectory(char *desc, SPOOL_Q_GETPRINTPROCESSORDIRECTORY *q_u, prs_struct *ps, int depth)
6857 uint32 ptr;
6859 prs_debug(ps, depth, desc, "spoolss_io_q_getprintprocessordirectory");
6860 depth++;
6862 if(!prs_align(ps))
6863 return False;
6865 if (!prs_uint32("ptr", ps, depth, &ptr))
6866 return False;
6868 if (ptr) {
6869 if(!smb_io_unistr2("name", &q_u->name, True, ps, depth))
6870 return False;
6873 if (!prs_align(ps))
6874 return False;
6876 if (!prs_uint32("ptr", ps, depth, &ptr))
6877 return False;
6879 if (ptr) {
6880 if(!smb_io_unistr2("environment", &q_u->environment, True,
6881 ps, depth))
6882 return False;
6885 if (!prs_align(ps))
6886 return False;
6888 if(!prs_uint32("level", ps, depth, &q_u->level))
6889 return False;
6891 if(!spoolss_io_buffer("", ps, depth, &q_u->buffer))
6892 return False;
6894 if(!prs_align(ps))
6895 return False;
6897 if(!prs_uint32("offered", ps, depth, &q_u->offered))
6898 return False;
6900 return True;
6903 /*******************************************************************
6904 * write a structure.
6905 ********************************************************************/
6907 BOOL spoolss_io_r_getprintprocessordirectory(char *desc, SPOOL_R_GETPRINTPROCESSORDIRECTORY *r_u, prs_struct *ps, int depth)
6909 prs_debug(ps, depth, desc, "spoolss_io_r_getprintprocessordirectory");
6910 depth++;
6912 if(!prs_align(ps))
6913 return False;
6915 if(!spoolss_io_buffer("", ps, depth, &r_u->buffer))
6916 return False;
6918 if(!prs_align(ps))
6919 return False;
6921 if(!prs_uint32("needed", ps, depth, &r_u->needed))
6922 return False;
6924 if(!prs_werror("status", ps, depth, &r_u->status))
6925 return False;
6927 return True;
6930 BOOL smb_io_printprocessordirectory_1(char *desc, NEW_BUFFER *buffer, PRINTPROCESSOR_DIRECTORY_1 *info, int depth)
6932 prs_struct *ps=&buffer->prs;
6934 prs_debug(ps, depth, desc, "smb_io_printprocessordirectory_1");
6935 depth++;
6937 buffer->struct_start=prs_offset(ps);
6939 if (!smb_io_unistr(desc, &info->name, ps, depth))
6940 return False;
6942 return True;
6945 /*******************************************************************
6946 * init a structure.
6947 ********************************************************************/
6949 BOOL make_spoolss_q_addform(SPOOL_Q_ADDFORM *q_u, POLICY_HND *handle,
6950 int level, FORM *form)
6952 memcpy(&q_u->handle, handle, sizeof(POLICY_HND));
6953 q_u->level = level;
6954 q_u->level2 = level;
6955 memcpy(&q_u->form, form, sizeof(FORM));
6957 return True;
6960 /*******************************************************************
6961 * init a structure.
6962 ********************************************************************/
6964 BOOL make_spoolss_q_setform(SPOOL_Q_SETFORM *q_u, POLICY_HND *handle,
6965 int level, char *form_name, FORM *form)
6967 memcpy(&q_u->handle, handle, sizeof(POLICY_HND));
6968 q_u->level = level;
6969 q_u->level2 = level;
6970 memcpy(&q_u->form, form, sizeof(FORM));
6971 init_unistr2(&q_u->name, form_name, strlen(form_name) + 1);
6973 return True;
6976 /*******************************************************************
6977 * init a structure.
6978 ********************************************************************/
6980 BOOL make_spoolss_q_deleteform(SPOOL_Q_DELETEFORM *q_u, POLICY_HND *handle, char *form)
6982 memcpy(&q_u->handle, handle, sizeof(POLICY_HND));
6983 init_unistr2(&q_u->name, form, strlen(form) + 1);
6984 return True;
6987 /*******************************************************************
6988 * init a structure.
6989 ********************************************************************/
6991 BOOL make_spoolss_q_getform(SPOOL_Q_GETFORM *q_u, POLICY_HND *handle,
6992 char *formname, uint32 level, NEW_BUFFER *buffer,
6993 uint32 offered)
6995 memcpy(&q_u->handle, handle, sizeof(POLICY_HND));
6996 q_u->level = level;
6997 init_unistr2(&q_u->formname, formname, strlen(formname) + 1);
6998 q_u->buffer=buffer;
6999 q_u->offered=offered;
7001 return True;
7004 /*******************************************************************
7005 * init a structure.
7006 ********************************************************************/
7008 BOOL make_spoolss_q_enumforms(SPOOL_Q_ENUMFORMS *q_u, POLICY_HND *handle,
7009 uint32 level, NEW_BUFFER *buffer,
7010 uint32 offered)
7012 memcpy(&q_u->handle, handle, sizeof(POLICY_HND));
7013 q_u->level = level;
7014 q_u->buffer=buffer;
7015 q_u->offered=offered;
7017 return True;