clunky support for calling AddPrinterEx(). The code currently reports
[Samba.git] / source / rpc_parse / parse_spoolss.c
blob033b680e645d26bdc427b6442b8114cf58596d5c
1 /*
2 * Unix SMB/Netbios implementation.
3 * Version 1.9.
4 * RPC Pipe client / server routines
5 * Copyright (C) Andrew Tridgell 1992-2000,
6 * Copyright (C) Luke Kenneth Casson Leighton 1996-2000,
7 * Copyright (C) Jean François Micouleau 1998-2000.
8 * Copyright (C) Gerald Carter 2000
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation; either version 2 of the License, or
13 * (at your option) any later version.
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
20 * You should have received a copy of the GNU General Public License
21 * along with this program; if not, write to the Free Software
22 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
26 #include "includes.h"
28 extern int DEBUGLEVEL;
29 /*******************************************************************
30 return the length of a UNISTR string.
31 ********************************************************************/
32 static uint32 str_len_uni(UNISTR *source)
34 uint32 i=0;
36 if (!source->buffer) return 0;
38 while (source->buffer[i]!=0x0000)
40 i++;
42 return i;
45 /*******************************************************************
46 This should be moved in a more generic lib.
47 ********************************************************************/
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 ********************************************************************/
72 BOOL make_systemtime(SYSTEMTIME *systime, struct tm *unixtime)
74 systime->year=unixtime->tm_year+1900;
75 systime->month=unixtime->tm_mon+1;
76 systime->dayofweek=unixtime->tm_wday;
77 systime->day=unixtime->tm_mday;
78 systime->hour=unixtime->tm_hour;
79 systime->minute=unixtime->tm_min;
80 systime->second=unixtime->tm_sec;
81 systime->milliseconds=0;
83 return True;
86 /*******************************************************************
87 reads or writes an DOC_INFO structure.
88 ********************************************************************/
89 static BOOL smb_io_doc_info_1(char *desc, DOC_INFO_1 *info_1, prs_struct *ps, int depth)
91 if (info_1 == NULL) return False;
93 prs_debug(ps, depth, desc, "smb_io_doc_info_1");
94 depth++;
96 if(!prs_align(ps))
97 return False;
99 if(!prs_uint32("p_docname", ps, depth, &(info_1->p_docname)))
100 return False;
101 if(!prs_uint32("p_outputfile", ps, depth, &(info_1->p_outputfile)))
102 return False;
103 if(!prs_uint32("p_datatype", ps, depth, &(info_1->p_datatype)))
104 return False;
106 if(!smb_io_unistr2("", &(info_1->docname), info_1->p_docname, ps, depth))
107 return False;
108 if(!smb_io_unistr2("", &(info_1->outputfile), info_1->p_outputfile, ps, depth))
109 return False;
110 if(!smb_io_unistr2("", &(info_1->datatype), info_1->p_datatype, ps, depth))
111 return False;
113 return True;
116 /*******************************************************************
117 reads or writes an DOC_INFO structure.
118 ********************************************************************/
119 static BOOL smb_io_doc_info(char *desc, DOC_INFO *info, prs_struct *ps, int depth)
121 uint32 useless_ptr=0;
123 if (info == NULL) return False;
125 prs_debug(ps, depth, desc, "smb_io_doc_info");
126 depth++;
128 if(!prs_align(ps))
129 return False;
131 if(!prs_uint32("switch_value", ps, depth, &(info->switch_value)))
132 return False;
134 if(!prs_uint32("doc_info_X ptr", ps, depth, &(useless_ptr)))
135 return False;
137 switch (info->switch_value)
139 case 1:
140 if(!smb_io_doc_info_1("",&(info->doc_info_1), ps, depth))
141 return False;
142 break;
143 case 2:
145 this is just a placeholder
147 MSDN July 1998 says doc_info_2 is only on
148 Windows 95, and as Win95 doesn't do RPC to print
149 this case is nearly impossible
151 Maybe one day with Windows for dishwasher 2037 ...
154 /* smb_io_doc_info_2("",&(info->doc_info_2), ps, depth); */
155 break;
156 default:
157 DEBUG(0,("Something is obviously wrong somewhere !\n"));
158 break;
161 return True;
164 /*******************************************************************
165 reads or writes an DOC_INFO_CONTAINER structure.
166 ********************************************************************/
167 static BOOL smb_io_doc_info_container(char *desc, DOC_INFO_CONTAINER *cont, prs_struct *ps, int depth)
169 if (cont == NULL) return False;
171 prs_debug(ps, depth, desc, "smb_io_doc_info_container");
172 depth++;
174 if(!prs_align(ps))
175 return False;
177 if(!prs_uint32("level", ps, depth, &cont->level))
178 return False;
180 if(!smb_io_doc_info("",&cont->docinfo, ps, depth))
181 return False;
183 return True;
186 /*******************************************************************
187 reads or writes an NOTIFY OPTION TYPE structure.
188 ********************************************************************/
189 static BOOL smb_io_notify_option_type(char *desc, SPOOL_NOTIFY_OPTION_TYPE *type, prs_struct *ps, int depth)
191 prs_debug(ps, depth, desc, "smb_io_notify_option_type");
192 depth++;
194 if (!prs_align(ps))
195 return False;
197 if(!prs_uint16("type", ps, depth, &type->type))
198 return False;
199 if(!prs_uint16("reserved0", ps, depth, &type->reserved0))
200 return False;
201 if(!prs_uint32("reserved1", ps, depth, &type->reserved1))
202 return False;
203 if(!prs_uint32("reserved2", ps, depth, &type->reserved2))
204 return False;
205 if(!prs_uint32("count", ps, depth, &type->count))
206 return False;
207 if(!prs_uint32("fields_ptr", ps, depth, &type->fields_ptr))
208 return False;
210 return True;
213 /*******************************************************************
214 reads or writes an NOTIFY OPTION TYPE DATA.
215 ********************************************************************/
216 static BOOL smb_io_notify_option_type_data(char *desc, SPOOL_NOTIFY_OPTION_TYPE *type, prs_struct *ps, int depth)
218 int i;
220 prs_debug(ps, depth, desc, "smb_io_notify_option_type_data");
221 depth++;
223 /* if there are no fields just return */
224 if (type->fields_ptr==0)
225 return True;
227 if(!prs_align(ps))
228 return False;
230 if(!prs_uint32("count2", ps, depth, &type->count2))
231 return False;
233 if (type->count2 != type->count)
234 DEBUG(4,("What a mess, count was %x now is %x !\n", type->count, type->count2));
236 /* parse the option type data */
237 for(i=0;i<type->count2;i++)
238 if(!prs_uint16("fields",ps,depth,&type->fields[i]))
239 return False;
240 return True;
243 /*******************************************************************
244 reads or writes an NOTIFY OPTION structure.
245 ********************************************************************/
246 static BOOL smb_io_notify_option_type_ctr(char *desc, SPOOL_NOTIFY_OPTION_TYPE_CTR *ctr , prs_struct *ps, int depth)
248 int i;
250 prs_debug(ps, depth, desc, "smb_io_notify_option_type_ctr");
251 depth++;
253 if(!prs_uint32("count", ps, depth, &ctr->count))
254 return False;
256 /* reading */
257 if (UNMARSHALLING(ps))
258 if((ctr->type=(SPOOL_NOTIFY_OPTION_TYPE *)malloc(ctr->count*sizeof(SPOOL_NOTIFY_OPTION_TYPE))) == NULL)
259 return False;
261 /* the option type struct */
262 for(i=0;i<ctr->count;i++)
263 if(!smb_io_notify_option_type("", &ctr->type[i] , ps, depth))
264 return False;
266 /* the type associated with the option type struct */
267 for(i=0;i<ctr->count;i++)
268 if(!smb_io_notify_option_type_data("", &ctr->type[i] , ps, depth))
269 return False;
271 return True;
274 /*******************************************************************
275 reads or writes an NOTIFY OPTION structure.
276 ********************************************************************/
277 static BOOL smb_io_notify_option(char *desc, SPOOL_NOTIFY_OPTION *option, prs_struct *ps, int depth)
279 prs_debug(ps, depth, desc, "smb_io_notify_option");
280 depth++;
282 if(!prs_uint32("version", ps, depth, &option->version))
283 return False;
284 if(!prs_uint32("flags", ps, depth, &option->flags))
285 return False;
286 if(!prs_uint32("count", ps, depth, &option->count))
287 return False;
288 if(!prs_uint32("option_type_ptr", ps, depth, &option->option_type_ptr))
289 return False;
291 /* marshalling or unmarshalling, that would work */
292 if (option->option_type_ptr!=0) {
293 if(!smb_io_notify_option_type_ctr("", &option->ctr ,ps, depth))
294 return False;
296 else {
297 option->ctr.type=NULL;
298 option->ctr.count=0;
301 return True;
304 /*******************************************************************
305 reads or writes an NOTIFY INFO DATA structure.
306 ********************************************************************/
307 static BOOL smb_io_notify_info_data(char *desc,SPOOL_NOTIFY_INFO_DATA *data, prs_struct *ps, int depth)
309 uint32 useless_ptr=0xADDE0FF0;
311 uint32 how_many_words;
312 BOOL isvalue;
313 uint32 x;
315 prs_debug(ps, depth, desc, "smb_io_notify_info_data");
316 depth++;
318 how_many_words=data->size;
319 if (how_many_words==POINTER) {
320 how_many_words=TWO_VALUE;
323 isvalue=data->enc_type;
325 if(!prs_align(ps))
326 return False;
327 if(!prs_uint16("type", ps, depth, &data->type))
328 return False;
329 if(!prs_uint16("field", ps, depth, &data->field))
330 return False;
331 /*prs_align(ps);*/
333 if(!prs_uint32("how many words", ps, depth, &how_many_words))
334 return False;
335 if(!prs_uint32("id", ps, depth, &data->id))
336 return False;
337 if(!prs_uint32("how many words", ps, depth, &how_many_words))
338 return False;
341 /*prs_align(ps);*/
343 if (isvalue==True) {
344 if(!prs_uint32("value[0]", ps, depth, &data->notify_data.value[0]))
345 return False;
346 if(!prs_uint32("value[1]", ps, depth, &data->notify_data.value[1]))
347 return False;
348 /*prs_align(ps);*/
349 } else {
350 /* it's a string */
351 /* length in ascii including \0 */
352 x=2*(data->notify_data.data.length+1);
353 if(!prs_uint32("string length", ps, depth, &x ))
354 return False;
355 if(!prs_uint32("pointer", ps, depth, &useless_ptr))
356 return False;
357 /*prs_align(ps);*/
360 return True;
363 /*******************************************************************
364 reads or writes an NOTIFY INFO DATA structure.
365 ********************************************************************/
366 BOOL smb_io_notify_info_data_strings(char *desc,SPOOL_NOTIFY_INFO_DATA *data,
367 prs_struct *ps, int depth)
369 uint32 x;
370 BOOL isvalue;
372 prs_debug(ps, depth, desc, "smb_io_notify_info_data_strings");
373 depth++;
375 if(!prs_align(ps))
376 return False;
378 isvalue=data->enc_type;
380 if (isvalue==False) {
381 /* length of string in unicode include \0 */
382 x=data->notify_data.data.length+1;
383 if(!prs_uint32("string length", ps, depth, &x ))
384 return False;
385 if(!prs_uint16s(True,"string",ps,depth,data->notify_data.data.string,x))
386 return False;
388 if(!prs_align(ps))
389 return False;
391 return True;
394 /*******************************************************************
395 reads or writes an NOTIFY INFO structure.
396 ********************************************************************/
397 static BOOL smb_io_notify_info(char *desc, SPOOL_NOTIFY_INFO *info, prs_struct *ps, int depth)
399 int i;
401 prs_debug(ps, depth, desc, "smb_io_notify_info");
402 depth++;
404 if(!prs_align(ps))
405 return False;
407 if(!prs_uint32("count", ps, depth, &info->count))
408 return False;
409 if(!prs_uint32("version", ps, depth, &info->version))
410 return False;
411 if(!prs_uint32("flags", ps, depth, &info->flags))
412 return False;
413 if(!prs_uint32("count", ps, depth, &info->count))
414 return False;
416 for (i=0;i<info->count;i++) {
417 if(!smb_io_notify_info_data(desc, &info->data[i], ps, depth))
418 return False;
421 /* now do the strings at the end of the stream */
422 for (i=0;i<info->count;i++) {
423 if(!smb_io_notify_info_data_strings(desc, &info->data[i], ps, depth))
424 return False;
427 return True;
431 /*******************************************************************
432 ********************************************************************/
433 static BOOL spool_io_user_level_1(char *desc, SPOOL_USER_1 *q_u, prs_struct *ps, int depth)
435 prs_debug(ps, depth, desc, "");
436 depth++;
438 /* reading */
439 if (ps->io)
440 ZERO_STRUCTP(q_u);
442 if (!prs_align(ps))
443 return False;
444 if (!prs_uint32("size", ps, depth, &(q_u->size)))
445 return False;
446 if (!prs_uint32("client_name_ptr", ps, depth, &(q_u->client_name_ptr)))
447 return False;
448 if (!prs_uint32("user_name_ptr", ps, depth, &(q_u->user_name_ptr)))
449 return False;
450 if (!prs_uint32("build", ps, depth, &(q_u->build)))
451 return False;
452 if (!prs_uint32("major", ps, depth, &(q_u->major)))
453 return False;
454 if (!prs_uint32("minor", ps, depth, &(q_u->minor)))
455 return False;
456 if (!prs_uint32("processor", ps, depth, &(q_u->processor)))
457 return False;
459 if (!smb_io_unistr2("", &(q_u->client_name), q_u->client_name_ptr, ps, depth))
460 return False;
461 if (!prs_align(ps))
462 return False;
463 if (!smb_io_unistr2("", &(q_u->user_name), q_u->user_name_ptr, ps, depth))
464 return False;
466 return True;
469 /*******************************************************************
470 ********************************************************************/
471 static BOOL spool_io_user_level(char *desc, SPOOL_USER_CTR *q_u, prs_struct *ps, int depth)
473 if (q_u==NULL)
474 return False;
476 prs_debug(ps, depth, desc, "spool_io_user_level");
477 depth++;
479 if (!prs_align(ps))
480 return False;
481 if (!prs_uint32("level", ps, depth, &q_u->level))
482 return False;
483 if (!prs_uint32("ptr", ps, depth, &q_u->ptr))
484 return False;
486 switch (q_u->level) {
487 case 1:
488 if (!spool_io_user_level_1("", &(q_u->user1), ps, depth))
489 return False;
490 break;
491 default:
492 return False;
495 return True;
498 /*******************************************************************
499 * read or write a DEVICEMODE struct.
500 * on reading allocate memory for the private member
501 ********************************************************************/
502 static BOOL spoolss_io_devmode(char *desc, prs_struct *ps, int depth, DEVICEMODE *devmode)
504 prs_debug(ps, depth, desc, "spoolss_io_devmode");
505 depth++;
507 if (UNMARSHALLING(ps)) {
508 devmode->devicename.buffer = (uint16 *)prs_alloc_mem(ps, 32 * sizeof(uint16) );
509 if (devmode->devicename.buffer == NULL)
510 return False;
513 if (!prs_uint16s(True,"devicename", ps, depth, devmode->devicename.buffer, 32))
514 return False;
515 if (!prs_uint16("specversion", ps, depth, &devmode->specversion))
516 return False;
517 if (!prs_uint16("driverversion", ps, depth, &devmode->driverversion))
518 return False;
519 if (!prs_uint16("size", ps, depth, &devmode->size))
520 return False;
521 if (!prs_uint16("driverextra", ps, depth, &devmode->driverextra))
522 return False;
523 if (!prs_uint32("fields", ps, depth, &devmode->fields))
524 return False;
525 if (!prs_uint16("orientation", ps, depth, &devmode->orientation))
526 return False;
527 if (!prs_uint16("papersize", ps, depth, &devmode->papersize))
528 return False;
529 if (!prs_uint16("paperlength", ps, depth, &devmode->paperlength))
530 return False;
531 if (!prs_uint16("paperwidth", ps, depth, &devmode->paperwidth))
532 return False;
533 if (!prs_uint16("scale", ps, depth, &devmode->scale))
534 return False;
535 if (!prs_uint16("copies", ps, depth, &devmode->copies))
536 return False;
537 if (!prs_uint16("defaultsource", ps, depth, &devmode->defaultsource))
538 return False;
539 if (!prs_uint16("printquality", ps, depth, &devmode->printquality))
540 return False;
541 if (!prs_uint16("color", ps, depth, &devmode->color))
542 return False;
543 if (!prs_uint16("duplex", ps, depth, &devmode->duplex))
544 return False;
545 if (!prs_uint16("yresolution", ps, depth, &devmode->yresolution))
546 return False;
547 if (!prs_uint16("ttoption", ps, depth, &devmode->ttoption))
548 return False;
549 if (!prs_uint16("collate", ps, depth, &devmode->collate))
550 return False;
552 if (UNMARSHALLING(ps)) {
553 devmode->formname.buffer = (uint16 *)prs_alloc_mem(ps, 32 * sizeof(uint16) );
554 if (devmode->formname.buffer == NULL)
555 return False;
558 if (!prs_uint16s(True, "formname", ps, depth, devmode->formname.buffer, 32))
559 return False;
560 if (!prs_uint16("logpixels", ps, depth, &devmode->logpixels))
561 return False;
562 if (!prs_uint32("bitsperpel", ps, depth, &devmode->bitsperpel))
563 return False;
564 if (!prs_uint32("pelswidth", ps, depth, &devmode->pelswidth))
565 return False;
566 if (!prs_uint32("pelsheight", ps, depth, &devmode->pelsheight))
567 return False;
568 if (!prs_uint32("displayflags", ps, depth, &devmode->displayflags))
569 return False;
570 if (!prs_uint32("displayfrequency", ps, depth, &devmode->displayfrequency))
571 return False;
572 if (!prs_uint32("icmmethod", ps, depth, &devmode->icmmethod))
573 return False;
574 if (!prs_uint32("icmintent", ps, depth, &devmode->icmintent))
575 return False;
576 if (!prs_uint32("mediatype", ps, depth, &devmode->mediatype))
577 return False;
578 if (!prs_uint32("dithertype", ps, depth, &devmode->dithertype))
579 return False;
580 if (!prs_uint32("reserved1", ps, depth, &devmode->reserved1))
581 return False;
582 if (!prs_uint32("reserved2", ps, depth, &devmode->reserved2))
583 return False;
584 if (!prs_uint32("panningwidth", ps, depth, &devmode->panningwidth))
585 return False;
586 if (!prs_uint32("panningheight", ps, depth, &devmode->panningheight))
587 return False;
589 if (devmode->driverextra!=0) {
590 if (UNMARSHALLING(ps)) {
591 devmode->private=(uint8 *)malloc(devmode->driverextra*sizeof(uint8));
592 if(devmode->private == NULL)
593 return False;
594 DEBUG(7,("spoolss_io_devmode: allocated memory [%d] for private\n",devmode->driverextra));
597 DEBUG(7,("spoolss_io_devmode: parsing [%d] bytes of private\n",devmode->driverextra));
598 if (!prs_uint8s(True, "private", ps, depth, devmode->private, devmode->driverextra))
599 return False;
602 return True;
605 void free_spoolss_devmode(DEVICEMODE *devmode)
607 if (devmode == NULL)
608 return;
610 safe_free(devmode->private);
611 safe_free(devmode);
614 /*******************************************************************
615 Read or write a DEVICEMODE container
616 ********************************************************************/
617 static BOOL spoolss_io_devmode_cont(char *desc, DEVMODE_CTR *dm_c, prs_struct *ps, int depth)
619 if (dm_c==NULL)
620 return False;
622 prs_debug(ps, depth, desc, "spoolss_io_devmode_cont");
623 depth++;
625 if(!prs_align(ps))
626 return False;
628 if (!prs_uint32("size", ps, depth, &dm_c->size))
629 return False;
631 if (!prs_uint32("devmode_ptr", ps, depth, &dm_c->devmode_ptr))
632 return False;
634 if (dm_c->size==0 || dm_c->devmode_ptr==0) {
635 if (UNMARSHALLING(ps))
636 /* if while reading there is no DEVMODE ... */
637 dm_c->devmode=NULL;
638 return True;
641 /* so we have a DEVICEMODE to follow */
642 if (UNMARSHALLING(ps)) {
643 DEBUG(9,("Allocating memory for spoolss_io_devmode\n"));
644 dm_c->devmode=(DEVICEMODE *)malloc(sizeof(DEVICEMODE));
645 if(dm_c->devmode == NULL)
646 return False;
647 ZERO_STRUCTP(dm_c->devmode);
650 /* this is bad code, shouldn't be there */
651 if (!prs_uint32("size", ps, depth, &dm_c->size))
652 return False;
654 if (!spoolss_io_devmode(desc, ps, depth, dm_c->devmode))
655 return False;
657 return True;
660 /*******************************************************************
661 ********************************************************************/
662 static BOOL spoolss_io_printer_default(char *desc, PRINTER_DEFAULT *pd, prs_struct *ps, int depth)
664 if (pd==NULL)
665 return False;
667 prs_debug(ps, depth, desc, "spoolss_io_printer_default");
668 depth++;
670 if (!prs_uint32("datatype_ptr", ps, depth, &pd->datatype_ptr))
671 return False;
673 if (!smb_io_unistr2("datatype", &(pd->datatype), pd->datatype_ptr, ps,depth))
674 return False;
676 if (!prs_align(ps))
677 return False;
679 if (!spoolss_io_devmode_cont("", &(pd->devmode_cont), ps, depth))
680 return False;
682 if (!prs_uint32("access_required", ps, depth, &pd->access_required))
683 return False;
685 return True;
688 /*******************************************************************
689 * init a structure.
690 ********************************************************************/
691 BOOL make_spoolss_q_open_printer_ex(SPOOL_Q_OPEN_PRINTER_EX *q_u,
692 const fstring printername,
693 const fstring datatype,
694 uint32 access_required,
695 const fstring clientname,
696 const fstring user_name)
698 DEBUG(5,("make_spoolss_q_open_printer_ex\n"));
699 q_u->printername_ptr = (printername!=NULL)?1:0;
700 init_unistr2(&q_u->printername, printername, strlen(printername));
702 q_u->printer_default.datatype_ptr = 0;
704 q_u->printer_default.datatype_ptr = (datatype!=NULL)?1:0;
705 init_unistr2(&q_u->printer_default.datatype, datatype, strlen(datatype));
707 q_u->printer_default.devmode_cont.size=0;
708 q_u->printer_default.devmode_cont.devmode_ptr=0;
709 q_u->printer_default.devmode_cont.devmode=NULL;
710 q_u->printer_default.access_required=access_required;
711 q_u->user_switch=1;
712 q_u->user_ctr.level=1;
713 q_u->user_ctr.ptr=1;
714 q_u->user_ctr.user1.size=strlen(clientname)+strlen(user_name)+8;
715 q_u->user_ctr.user1.client_name_ptr = (clientname!=NULL)?1:0;
716 q_u->user_ctr.user1.user_name_ptr = (user_name!=NULL)?1:0;
717 q_u->user_ctr.user1.build=1381;
718 q_u->user_ctr.user1.major=2;
719 q_u->user_ctr.user1.minor=0;
720 q_u->user_ctr.user1.processor=0;
721 init_unistr2(&q_u->user_ctr.user1.client_name, clientname, strlen(clientname));
722 init_unistr2(&q_u->user_ctr.user1.user_name, user_name, strlen(user_name));
724 return True;
727 /*******************************************************************
728 * init a structure.
729 ********************************************************************/
730 BOOL make_spoolss_q_addprinterex(SPOOL_Q_ADDPRINTEREX *q_u, const char *srv_name,
731 const char* clientname, const char* user_name,
732 uint32 level, PRINTER_INFO_2 *info)
734 DEBUG(5,("make_spoolss_q_addprinterex\n"));
736 q_u->server_name_ptr = (srv_name!=NULL)?1:0;
737 init_unistr2(&q_u->server_name, srv_name, strlen(srv_name));
739 q_u->level = level;
741 q_u->info.level = level;
742 q_u->info.info_ptr = (info!=NULL)?1:0;
743 switch (level)
745 case 2:
746 /* init q_u->info.info2 from *info */
747 if (!make_spool_printer_info_2( &q_u->info.info_2, info))
749 DEBUG(0,("make_spoolss_q_addprinterex: Unable to fill SPOOL_Q_ADDPRINTEREX struct!\n"));
750 return False;
752 break;
753 default :
754 break;
757 q_u->unk0 = q_u->unk1 = q_u->unk2 = q_u->unk3 = 0;
759 q_u->user_switch=1;
761 q_u->user_ctr.level=1;
762 q_u->user_ctr.ptr=1;
763 q_u->user_ctr.user1.size=strlen(clientname)+strlen(user_name)+8;
764 q_u->user_ctr.user1.client_name_ptr = (clientname!=NULL)?1:0;
765 q_u->user_ctr.user1.user_name_ptr = (user_name!=NULL)?1:0;
766 q_u->user_ctr.user1.build=1381;
767 q_u->user_ctr.user1.major=2;
768 q_u->user_ctr.user1.minor=0;
769 q_u->user_ctr.user1.processor=0;
770 init_unistr2(&q_u->user_ctr.user1.client_name, clientname, strlen(clientname));
771 init_unistr2(&q_u->user_ctr.user1.user_name, user_name, strlen(user_name));
773 return True;
775 /*******************************************************************
776 create a SPOOL_PRINTER_INFO_2 stuct from a PRINTER_INFO_2 struct
777 *******************************************************************/
778 BOOL make_spool_printer_info_2(SPOOL_PRINTER_INFO_LEVEL_2 **spool_info2,
779 PRINTER_INFO_2 *info)
782 SPOOL_PRINTER_INFO_LEVEL_2 *inf;
784 /* allocate the necessary memory */
785 inf = (SPOOL_PRINTER_INFO_LEVEL_2*)malloc(sizeof(SPOOL_PRINTER_INFO_LEVEL_2));
786 if (spool_info2 == NULL)
788 DEBUG(0,("make_spool_printer_info_2: Unable to malloc SPOOL_PRINTER_INFO_LEVEL_2 sruct!\n"));
789 return False;
792 ZERO_STRUCTP(inf);
794 inf->servername_ptr = (info->servername.buffer!=NULL)?1:0;
795 inf->printername_ptr = (info->printername.buffer!=NULL)?1:0;
796 inf->sharename_ptr = (info->sharename.buffer!=NULL)?1:0;
797 inf->portname_ptr = (info->portname.buffer!=NULL)?1:0;
798 inf->drivername_ptr = (info->drivername.buffer!=NULL)?1:0;
799 inf->comment_ptr = (info->comment.buffer!=NULL)?1:0;
800 inf->location_ptr = (info->location.buffer!=NULL)?1:0;
801 inf->devmode_ptr = (info->devmode!=NULL)?1:0;
802 inf->sepfile_ptr = (info->sepfile.buffer!=NULL)?1:0;
803 inf->printprocessor_ptr = (info->printprocessor.buffer!=NULL)?1:0;
804 inf->datatype_ptr = (info->datatype.buffer!=NULL)?1:0;
805 inf->parameters_ptr = (info->parameters.buffer!=NULL)?1:0;
806 inf->secdesc_ptr = (info->secdesc!=NULL)?1:0;
807 inf->attributes = info->attributes;
808 inf->priority = info->priority;
809 inf->default_priority = info->defaultpriority;
810 inf->starttime = info->starttime;
811 inf->untiltime = info->untiltime;
812 inf->cjobs = info->cjobs;
813 inf->averageppm = info->averageppm;
814 init_unistr2_from_unistr(&inf->servername, &info->servername);
815 init_unistr2_from_unistr(&inf->printername, &info->printername);
816 init_unistr2_from_unistr(&inf->sharename, &info->sharename);
817 init_unistr2_from_unistr(&inf->portname, &info->portname);
818 init_unistr2_from_unistr(&inf->drivername, &info->drivername);
819 init_unistr2_from_unistr(&inf->comment, &info->comment);
820 init_unistr2_from_unistr(&inf->location, &info->location);
821 init_unistr2_from_unistr(&inf->sepfile, &info->sepfile);
822 init_unistr2_from_unistr(&inf->printprocessor, &info->printprocessor);
823 init_unistr2_from_unistr(&inf->datatype, &info->datatype);
824 init_unistr2_from_unistr(&inf->parameters, &info->parameters);
825 init_unistr2_from_unistr(&inf->datatype, &info->datatype);
826 inf->secdesc = NULL;
828 *spool_info2 = inf;
830 return True;
833 /*******************************************************************
834 * read a structure.
835 * called from spoolss_q_open_printer_ex (srv_spoolss.c)
836 ********************************************************************/
837 BOOL spoolss_io_q_open_printer_ex(char *desc, SPOOL_Q_OPEN_PRINTER_EX *q_u, prs_struct *ps, int depth)
839 if (q_u == NULL)
840 return False;
842 prs_debug(ps, depth, desc, "spoolss_io_q_open_printer_ex");
843 depth++;
845 if (!prs_align(ps))
846 return False;
848 if (!prs_uint32("printername_ptr", ps, depth, &q_u->printername_ptr))
849 return False;
850 if (!smb_io_unistr2("", &q_u->printername, q_u->printername_ptr, ps,depth))
851 return False;
853 if (!prs_align(ps))
854 return False;
856 if (!spoolss_io_printer_default("", &q_u->printer_default, ps, depth))
857 return False;
859 if (!prs_uint32("user_switch", ps, depth, &q_u->user_switch))
860 return False;
861 if (!spool_io_user_level("", &q_u->user_ctr, ps, depth))
862 return False;
864 return True;
867 void free_spoolss_q_open_printer_ex(SPOOL_Q_OPEN_PRINTER_EX *q_u)
869 free_spoolss_devmode(q_u->printer_default.devmode_cont.devmode);
872 /*******************************************************************
873 * write a structure.
874 * called from static spoolss_r_open_printer_ex (srv_spoolss.c)
875 * called from spoolss_open_printer_ex (cli_spoolss.c)
876 ********************************************************************/
877 BOOL spoolss_io_r_open_printer_ex(char *desc, SPOOL_R_OPEN_PRINTER_EX *r_u, prs_struct *ps, int depth)
879 if (r_u == NULL) return False;
881 prs_debug(ps, depth, desc, "spoolss_io_r_open_printer_ex");
882 depth++;
884 if (!prs_align(ps))
885 return False;
887 if (!smb_io_pol_hnd("printer handle",&(r_u->handle),ps,depth))
888 return False;
890 if (!prs_uint32("status code", ps, depth, &(r_u->status)))
891 return False;
893 return True;
896 /*******************************************************************
897 * make a structure.
898 ********************************************************************/
899 BOOL make_spoolss_q_getprinterdata(SPOOL_Q_GETPRINTERDATA *q_u,
900 const POLICY_HND *handle,
901 const UNISTR2 *valuename,
902 uint32 size)
904 if (q_u == NULL) return False;
906 DEBUG(5,("make_spoolss_q_getprinterdata\n"));
908 q_u->handle = *handle;
909 copy_unistr2(&q_u->valuename, valuename);
910 q_u->size = size;
912 return True;
916 /*******************************************************************
917 * read a structure.
918 * called from spoolss_q_getprinterdata (srv_spoolss.c)
919 ********************************************************************/
920 BOOL spoolss_io_q_getprinterdata(char *desc, SPOOL_Q_GETPRINTERDATA *q_u, prs_struct *ps, int depth)
922 if (q_u == NULL) return False;
924 prs_debug(ps, depth, desc, "spoolss_io_q_getprinterdata");
925 depth++;
927 if (!prs_align(ps))
928 return False;
929 if (!smb_io_pol_hnd("printer handle",&(q_u->handle),ps,depth))
930 return False;
931 if (!prs_align(ps))
932 return False;
933 if (!smb_io_unistr2("valuename", &(q_u->valuename),True,ps,depth))
934 return False;
935 if (!prs_align(ps))
936 return False;
937 if (!prs_uint32("size", ps, depth, &(q_u->size)))
938 return False;
940 return True;
943 /*******************************************************************
944 * write a structure.
945 * called from spoolss_r_getprinterdata (srv_spoolss.c)
946 ********************************************************************/
947 BOOL spoolss_io_r_getprinterdata(char *desc, SPOOL_R_GETPRINTERDATA *r_u, prs_struct *ps, int depth)
949 if (r_u == NULL)
950 return False;
952 prs_debug(ps, depth, desc, "spoolss_io_r_getprinterdata");
953 depth++;
955 if (!prs_align(ps))
956 return False;
957 if (!prs_uint32("type", ps, depth, &r_u->type))
958 return False;
959 if (!prs_uint32("size", ps, depth, &r_u->size))
960 return False;
962 if (!prs_uint8s(False,"data", ps, depth, r_u->data, r_u->size))
963 return False;
965 if (!prs_align(ps))
966 return False;
968 if (!prs_uint32("needed", ps, depth, &r_u->needed))
969 return False;
970 if (!prs_uint32("status", ps, depth, &r_u->status))
971 return False;
973 return True;
976 /*******************************************************************
977 * make a structure.
978 ********************************************************************/
979 BOOL make_spoolss_q_closeprinter(SPOOL_Q_CLOSEPRINTER *q_u, POLICY_HND *hnd)
981 if (q_u == NULL) return False;
983 DEBUG(5,("make_spoolss_q_closeprinter\n"));
985 memcpy(&(q_u->handle), hnd, sizeof(q_u->handle));
987 return True;
990 /*******************************************************************
991 * read a structure.
992 * called from static spoolss_q_deleteprinter (srv_spoolss.c)
993 * called from spoolss_deleteprinter (cli_spoolss.c)
994 ********************************************************************/
995 BOOL spoolss_io_q_deleteprinter(char *desc, SPOOL_Q_DELETEPRINTER *q_u, prs_struct *ps, int depth)
997 if (q_u == NULL) return False;
999 prs_debug(ps, depth, desc, "spoolss_io_q_deleteprinter");
1000 depth++;
1002 if (!prs_align(ps))
1003 return False;
1005 if (!smb_io_pol_hnd("printer handle",&q_u->handle,ps,depth))
1006 return False;
1008 return True;
1011 /*******************************************************************
1012 * write a structure.
1013 * called from static spoolss_r_deleteprinter (srv_spoolss.c)
1014 * called from spoolss_deleteprinter (cli_spoolss.c)
1015 ********************************************************************/
1016 BOOL spoolss_io_r_deleteprinter(char *desc, SPOOL_R_DELETEPRINTER *r_u, prs_struct *ps, int depth)
1018 prs_debug(ps, depth, desc, "spoolss_io_r_deleteprinter");
1019 depth++;
1021 if (!prs_align(ps))
1022 return False;
1024 if (!smb_io_pol_hnd("printer handle",&r_u->handle,ps,depth))
1025 return False;
1026 if (!prs_uint32("status", ps, depth, &r_u->status))
1027 return False;
1029 return True;
1033 /*******************************************************************
1034 * read a structure.
1035 * called from static spoolss_q_closeprinter (srv_spoolss.c)
1036 * called from spoolss_closeprinter (cli_spoolss.c)
1037 ********************************************************************/
1038 BOOL spoolss_io_q_closeprinter(char *desc, SPOOL_Q_CLOSEPRINTER *q_u, prs_struct *ps, int depth)
1040 if (q_u == NULL) return False;
1042 prs_debug(ps, depth, desc, "spoolss_io_q_closeprinter");
1043 depth++;
1045 if (!prs_align(ps))
1046 return False;
1048 if (!smb_io_pol_hnd("printer handle",&q_u->handle,ps,depth))
1049 return False;
1051 return True;
1054 /*******************************************************************
1055 * write a structure.
1056 * called from static spoolss_r_closeprinter (srv_spoolss.c)
1057 * called from spoolss_closeprinter (cli_spoolss.c)
1058 ********************************************************************/
1059 BOOL spoolss_io_r_closeprinter(char *desc, SPOOL_R_CLOSEPRINTER *r_u, prs_struct *ps, int depth)
1061 prs_debug(ps, depth, desc, "spoolss_io_r_closeprinter");
1062 depth++;
1064 if (!prs_align(ps))
1065 return False;
1067 if (!smb_io_pol_hnd("printer handle",&r_u->handle,ps,depth))
1068 return False;
1069 if (!prs_uint32("status", ps, depth, &r_u->status))
1070 return False;
1072 return True;
1075 /*******************************************************************
1076 * read a structure.
1077 * called from spoolss_q_startdocprinter (srv_spoolss.c)
1078 ********************************************************************/
1079 BOOL spoolss_io_q_startdocprinter(char *desc, SPOOL_Q_STARTDOCPRINTER *q_u, prs_struct *ps, int depth)
1081 if (q_u == NULL) return False;
1083 prs_debug(ps, depth, desc, "spoolss_io_q_startdocprinter");
1084 depth++;
1086 if(!prs_align(ps))
1087 return False;
1089 if(!smb_io_pol_hnd("printer handle",&(q_u->handle),ps,depth))
1090 return False;
1092 if(!smb_io_doc_info_container("",&(q_u->doc_info_container), ps, depth))
1093 return False;
1095 return True;
1098 /*******************************************************************
1099 * write a structure.
1100 * called from spoolss_r_startdocprinter (srv_spoolss.c)
1101 ********************************************************************/
1102 BOOL spoolss_io_r_startdocprinter(char *desc, SPOOL_R_STARTDOCPRINTER *r_u, prs_struct *ps, int depth)
1104 prs_debug(ps, depth, desc, "spoolss_io_r_startdocprinter");
1105 depth++;
1106 if(!prs_uint32("jobid", ps, depth, &r_u->jobid))
1107 return False;
1108 if(!prs_uint32("status", ps, depth, &r_u->status))
1109 return False;
1111 return True;
1114 /*******************************************************************
1115 * read a structure.
1116 * called from spoolss_q_enddocprinter (srv_spoolss.c)
1117 ********************************************************************/
1118 BOOL spoolss_io_q_enddocprinter(char *desc, SPOOL_Q_ENDDOCPRINTER *q_u, prs_struct *ps, int depth)
1120 if (q_u == NULL) return False;
1122 prs_debug(ps, depth, desc, "spoolss_io_q_enddocprinter");
1123 depth++;
1125 if(!prs_align(ps))
1126 return False;
1128 if(!smb_io_pol_hnd("printer handle",&q_u->handle,ps,depth))
1129 return False;
1131 return True;
1134 /*******************************************************************
1135 * write a structure.
1136 * called from spoolss_r_enddocprinter (srv_spoolss.c)
1137 ********************************************************************/
1138 BOOL spoolss_io_r_enddocprinter(char *desc, SPOOL_R_ENDDOCPRINTER *r_u, prs_struct *ps, int depth)
1140 prs_debug(ps, depth, desc, "spoolss_io_r_enddocprinter");
1141 depth++;
1142 if(!prs_uint32("status", ps, depth, &r_u->status))
1143 return False;
1145 return True;
1148 /*******************************************************************
1149 * read a structure.
1150 * called from spoolss_q_startpageprinter (srv_spoolss.c)
1151 ********************************************************************/
1152 BOOL spoolss_io_q_startpageprinter(char *desc, SPOOL_Q_STARTPAGEPRINTER *q_u, prs_struct *ps, int depth)
1154 if (q_u == NULL) return False;
1156 prs_debug(ps, depth, desc, "spoolss_io_q_startpageprinter");
1157 depth++;
1159 if(!prs_align(ps))
1160 return False;
1162 if(!smb_io_pol_hnd("printer handle",&q_u->handle,ps,depth))
1163 return False;
1165 return True;
1168 /*******************************************************************
1169 * write a structure.
1170 * called from spoolss_r_startpageprinter (srv_spoolss.c)
1171 ********************************************************************/
1172 BOOL spoolss_io_r_startpageprinter(char *desc, SPOOL_R_STARTPAGEPRINTER *r_u, prs_struct *ps, int depth)
1174 prs_debug(ps, depth, desc, "spoolss_io_r_startpageprinter");
1175 depth++;
1176 if(!prs_uint32("status", ps, depth, &r_u->status))
1177 return False;
1179 return True;
1182 /*******************************************************************
1183 * read a structure.
1184 * called from spoolss_q_endpageprinter (srv_spoolss.c)
1185 ********************************************************************/
1186 BOOL spoolss_io_q_endpageprinter(char *desc, SPOOL_Q_ENDPAGEPRINTER *q_u, prs_struct *ps, int depth)
1188 if (q_u == NULL) return False;
1190 prs_debug(ps, depth, desc, "spoolss_io_q_endpageprinter");
1191 depth++;
1193 if(!prs_align(ps))
1194 return False;
1196 if(!smb_io_pol_hnd("printer handle",&q_u->handle,ps,depth))
1197 return False;
1199 return True;
1202 /*******************************************************************
1203 * write a structure.
1204 * called from spoolss_r_endpageprinter (srv_spoolss.c)
1205 ********************************************************************/
1206 BOOL spoolss_io_r_endpageprinter(char *desc, SPOOL_R_ENDPAGEPRINTER *r_u, prs_struct *ps, int depth)
1208 prs_debug(ps, depth, desc, "spoolss_io_r_endpageprinter");
1209 depth++;
1210 if(!prs_uint32("status", ps, depth, &r_u->status))
1211 return False;
1213 return True;
1216 /*******************************************************************
1217 * read a structure.
1218 * called from spoolss_q_writeprinter (srv_spoolss.c)
1219 ********************************************************************/
1220 BOOL spoolss_io_q_writeprinter(char *desc, SPOOL_Q_WRITEPRINTER *q_u, prs_struct *ps, int depth)
1222 if (q_u == NULL) return False;
1224 prs_debug(ps, depth, desc, "spoolss_io_q_writeprinter");
1225 depth++;
1227 if(!prs_align(ps))
1228 return False;
1230 if(!smb_io_pol_hnd("printer handle",&q_u->handle,ps,depth))
1231 return False;
1232 if(!prs_uint32("buffer_size", ps, depth, &q_u->buffer_size))
1233 return False;
1235 if (q_u->buffer_size!=0)
1237 q_u->buffer=(uint8 *)malloc(q_u->buffer_size*sizeof(uint8));
1238 if(q_u->buffer == NULL)
1239 return False;
1240 if(!prs_uint8s(True, "buffer", ps, depth, q_u->buffer, q_u->buffer_size))
1241 return False;
1243 if(!prs_align(ps))
1244 return False;
1245 if(!prs_uint32("buffer_size2", ps, depth, &q_u->buffer_size2))
1246 return False;
1248 return True;
1251 /*******************************************************************
1252 * write a structure.
1253 * called from spoolss_r_writeprinter (srv_spoolss.c)
1254 ********************************************************************/
1255 BOOL spoolss_io_r_writeprinter(char *desc, SPOOL_R_WRITEPRINTER *r_u, prs_struct *ps, int depth)
1257 prs_debug(ps, depth, desc, "spoolss_io_r_writeprinter");
1258 depth++;
1259 if(!prs_uint32("buffer_written", ps, depth, &r_u->buffer_written))
1260 return False;
1261 if(!prs_uint32("status", ps, depth, &r_u->status))
1262 return False;
1264 return True;
1267 /*******************************************************************
1268 * read a structure.
1269 * called from spoolss_q_rffpcnex (srv_spoolss.c)
1270 ********************************************************************/
1271 BOOL spoolss_io_q_rffpcnex(char *desc, SPOOL_Q_RFFPCNEX *q_u, prs_struct *ps, int depth)
1273 prs_debug(ps, depth, desc, "spoolss_io_q_rffpcnex");
1274 depth++;
1276 if(!prs_align(ps))
1277 return False;
1279 if(!smb_io_pol_hnd("printer handle", &q_u->handle, ps, depth))
1280 return False;
1281 if(!prs_uint32("flags", ps, depth, &q_u->flags))
1282 return False;
1283 if(!prs_uint32("options", ps, depth, &q_u->options))
1284 return False;
1285 if(!prs_uint32("localmachine_ptr", ps, depth, &q_u->localmachine_ptr))
1286 return False;
1287 if(!smb_io_unistr2("localmachine", &q_u->localmachine, q_u->localmachine_ptr, ps, depth))
1288 return False;
1290 if(!prs_align(ps))
1291 return False;
1293 if(!prs_uint32("printerlocal", ps, depth, &q_u->printerlocal))
1294 return False;
1296 if(!prs_uint32("option_ptr", ps, depth, &q_u->option_ptr))
1297 return False;
1299 if (q_u->option_ptr!=0) {
1301 if (UNMARSHALLING(ps))
1302 if((q_u->option=(SPOOL_NOTIFY_OPTION *)malloc(sizeof(SPOOL_NOTIFY_OPTION))) == NULL)
1303 return False;
1305 if(!smb_io_notify_option("notify option", q_u->option, ps, depth))
1306 return False;
1309 return True;
1312 /*******************************************************************
1313 * write a structure.
1314 * called from spoolss_r_rffpcnex (srv_spoolss.c)
1315 ********************************************************************/
1316 BOOL spoolss_io_r_rffpcnex(char *desc, SPOOL_R_RFFPCNEX *r_u, prs_struct *ps, int depth)
1318 prs_debug(ps, depth, desc, "spoolss_io_r_rffpcnex");
1319 depth++;
1321 if(!prs_uint32("status", ps, depth, &r_u->status))
1322 return False;
1324 return True;
1327 /*******************************************************************
1328 * read a structure.
1329 * called from spoolss_q_rfnpcnex (srv_spoolss.c)
1330 ********************************************************************/
1331 BOOL spoolss_io_q_rfnpcnex(char *desc, SPOOL_Q_RFNPCNEX *q_u, prs_struct *ps, int depth)
1333 prs_debug(ps, depth, desc, "spoolss_io_q_rfnpcnex");
1334 depth++;
1336 if(!prs_align(ps))
1337 return False;
1339 if(!smb_io_pol_hnd("printer handle",&q_u->handle,ps,depth))
1340 return False;
1342 if(!prs_uint32("change", ps, depth, &q_u->change))
1343 return False;
1345 if(!prs_uint32("option_ptr", ps, depth, &q_u->option_ptr))
1346 return False;
1348 if (q_u->option_ptr!=0) {
1350 if (UNMARSHALLING(ps))
1351 if((q_u->option=(SPOOL_NOTIFY_OPTION *)malloc(sizeof(SPOOL_NOTIFY_OPTION))) == NULL)
1352 return False;
1354 if(!smb_io_notify_option("notify option", q_u->option, ps, depth))
1355 return False;
1358 return True;
1361 /*******************************************************************
1362 * write a structure.
1363 * called from spoolss_r_rfnpcnex (srv_spoolss.c)
1364 ********************************************************************/
1365 BOOL spoolss_io_r_rfnpcnex(char *desc, SPOOL_R_RFNPCNEX *r_u, prs_struct *ps, int depth)
1367 prs_debug(ps, depth, desc, "spoolss_io_r_rfnpcnex");
1368 depth++;
1370 if(!prs_align(ps))
1371 return False;
1373 if (!prs_uint32("info_ptr", ps, depth, &r_u->info_ptr))
1374 return False;
1376 if(!smb_io_notify_info("notify info", &r_u->info ,ps,depth))
1377 return False;
1379 if(!prs_align(ps))
1380 return False;
1381 if(!prs_uint32("status", ps, depth, &r_u->status))
1382 return False;
1384 return True;
1387 /*******************************************************************
1388 * return the length of a uint16 (obvious, but the code is clean)
1389 ********************************************************************/
1390 static uint32 size_of_uint16(uint16 *value)
1392 return (sizeof(*value));
1395 /*******************************************************************
1396 * return the length of a uint32 (obvious, but the code is clean)
1397 ********************************************************************/
1398 static uint32 size_of_uint32(uint32 *value)
1400 return (sizeof(*value));
1402 /*******************************************************************
1403 * return the length of a UNICODE string in number of char, includes:
1404 * - the leading zero
1405 * - the relative pointer size
1406 ********************************************************************/
1407 static uint32 size_of_relative_string(UNISTR *string)
1409 uint32 size=0;
1411 size=str_len_uni(string); /* the string length */
1412 size=size+1; /* add the leading zero */
1413 size=size*2; /* convert in char */
1414 size=size+4; /* add the size of the ptr */
1416 return size;
1419 /*******************************************************************
1420 * return the length of a uint32 (obvious, but the code is clean)
1421 ********************************************************************/
1422 static uint32 size_of_device_mode(DEVICEMODE *devmode)
1424 if (devmode==NULL)
1425 return (4);
1426 else
1427 return (4+devmode->size+devmode->driverextra);
1430 /*******************************************************************
1431 * return the length of a uint32 (obvious, but the code is clean)
1432 ********************************************************************/
1433 static uint32 size_of_systemtime(SYSTEMTIME *systime)
1435 if (systime==NULL)
1436 return (4);
1437 else
1438 return (sizeof(SYSTEMTIME) +4);
1441 /*******************************************************************
1442 * write a UNICODE string.
1443 * used by all the RPC structs passing a buffer
1444 ********************************************************************/
1445 static BOOL spoolss_smb_io_unistr(char *desc, UNISTR *uni, prs_struct *ps, int depth)
1447 if (uni == NULL)
1448 return False;
1450 prs_debug(ps, depth, desc, "spoolss_smb_io_unistr");
1451 depth++;
1452 if (!prs_unistr("unistr", ps, depth, uni))
1453 return False;
1455 return True;
1459 /*******************************************************************
1460 * write a UNICODE string and its relative pointer.
1461 * used by all the RPC structs passing a buffer
1463 * As I'm a nice guy, I'm forcing myself to explain this code.
1464 * MS did a good job in the overall spoolss code except in some
1465 * functions where they are passing the API buffer directly in the
1466 * RPC request/reply. That's to maintain compatiility at the API level.
1467 * They could have done it the good way the first time.
1469 * So what happen is: the strings are written at the buffer's end,
1470 * in the reverse order of the original structure. Some pointers to
1471 * the strings are also in the buffer. Those are relative to the
1472 * buffer's start.
1474 * If you don't understand or want to change that function,
1475 * first get in touch with me: jfm@samba.org
1477 ********************************************************************/
1478 static BOOL new_smb_io_relstr(char *desc, NEW_BUFFER *buffer, int depth, UNISTR *string)
1480 prs_struct *ps=&buffer->prs;
1482 if (MARSHALLING(ps)) {
1483 uint32 struct_offset = prs_offset(ps);
1484 uint32 relative_offset;
1486 buffer->string_at_end -= 2*(str_len_uni(string)+1);
1487 if(!prs_set_offset(ps, buffer->string_at_end))
1488 return False;
1490 /* write the string */
1491 if (!spoolss_smb_io_unistr(desc, string, ps, depth))
1492 return False;
1494 if(!prs_set_offset(ps, struct_offset))
1495 return False;
1497 relative_offset=buffer->string_at_end - buffer->struct_start;
1498 /* write its offset */
1499 if (!prs_uint32("offset", ps, depth, &relative_offset))
1500 return False;
1502 else {
1503 uint32 old_offset;
1505 /* read the offset */
1506 if (!prs_uint32("offset", ps, depth, &(buffer->string_at_end)))
1507 return False;
1509 old_offset = prs_offset(ps);
1510 if(!prs_set_offset(ps, buffer->string_at_end+buffer->struct_start))
1511 return False;
1513 /* read the string */
1514 if (!spoolss_smb_io_unistr(desc, string, ps, depth))
1515 return False;
1517 if(!prs_set_offset(ps, old_offset))
1518 return False;
1520 return True;
1524 /*******************************************************************
1525 * write a array of UNICODE strings and its relative pointer.
1526 * used by 2 RPC structs
1527 ********************************************************************/
1528 static BOOL new_smb_io_relarraystr(char *desc, NEW_BUFFER *buffer, int depth, uint16 **string)
1530 UNISTR chaine;
1532 prs_struct *ps=&buffer->prs;
1534 if (MARSHALLING(ps)) {
1535 uint32 struct_offset = prs_offset(ps);
1536 uint32 relative_offset;
1537 uint16 *p;
1538 uint16 *q;
1539 uint16 zero=0;
1540 p=*string;
1541 q=*string;
1543 /* first write the last 0 */
1544 buffer->string_at_end -= 2;
1545 if(!prs_set_offset(ps, buffer->string_at_end))
1546 return False;
1548 if(!prs_uint16("leading zero", ps, depth, &zero))
1549 return False;
1551 while (p && (*p!=0)) {
1552 while (*q!=0)
1553 q++;
1555 chaine.buffer = malloc((q-p+1)*sizeof(uint16));
1556 if (chaine.buffer == NULL)
1557 return False;
1559 memcpy(chaine.buffer, p, (q-p+1)*sizeof(uint16));
1561 buffer->string_at_end -= (q-p+1)*sizeof(uint16);
1563 if(!prs_set_offset(ps, buffer->string_at_end)) {
1564 free(chaine.buffer);
1565 return False;
1568 /* write the string */
1569 if (!spoolss_smb_io_unistr(desc, &chaine, ps, depth)) {
1570 free(chaine.buffer);
1571 return False;
1573 q++;
1574 p=q;
1576 free(chaine.buffer);
1579 if(!prs_set_offset(ps, struct_offset))
1580 return False;
1582 relative_offset=buffer->string_at_end - buffer->struct_start;
1583 /* write its offset */
1584 if (!prs_uint32("offset", ps, depth, &relative_offset))
1585 return False;
1587 else {
1588 uint32 old_offset;
1589 uint16 *chaine2=NULL;
1590 int l_chaine=0;
1591 int l_chaine2=0;
1593 *string=NULL;
1595 /* read the offset */
1596 if (!prs_uint32("offset", ps, depth, &buffer->string_at_end))
1597 return False;
1599 old_offset = prs_offset(ps);
1600 if(!prs_set_offset(ps, buffer->string_at_end + buffer->struct_start))
1601 return False;
1603 do {
1604 if (!spoolss_smb_io_unistr(desc, &chaine, ps, depth))
1605 return False;
1607 l_chaine=str_len_uni(&chaine);
1608 if((chaine2=(uint16 *)Realloc(chaine2, (l_chaine2+l_chaine+1)*sizeof(uint16))) == NULL)
1609 return False;
1610 memcpy(chaine2+l_chaine2, chaine.buffer, (l_chaine+1)*sizeof(uint16));
1611 l_chaine2+=l_chaine+1;
1613 } while(l_chaine!=0);
1615 *string=chaine2;
1617 if(!prs_set_offset(ps, old_offset))
1618 return False;
1620 return True;
1624 /*******************************************************************
1625 Parse a DEVMODE structure and its relative pointer.
1626 ********************************************************************/
1627 static BOOL new_smb_io_relsecdesc(char *desc, NEW_BUFFER *buffer, int depth,
1628 SEC_DESC **secdesc)
1630 prs_struct *ps= &buffer->prs;
1632 prs_debug(ps, depth, desc, "new_smb_io_relsecdesc");
1633 depth++;
1635 if (MARSHALLING(ps)) {
1636 uint32 struct_offset = prs_offset(ps);
1637 uint32 relative_offset;
1639 if (! *secdesc) {
1640 relative_offset = 0;
1641 if (!prs_uint32("offset", ps, depth, &relative_offset))
1642 return False;
1643 return True;
1646 if (*secdesc != NULL) {
1647 #if 0 /* JRATEST */
1648 if(!prs_set_offset(ps, 0x54))
1649 return False;
1650 #else
1651 buffer->string_at_end -= sec_desc_size(*secdesc);
1653 if(!prs_set_offset(ps, buffer->string_at_end))
1654 return False;
1655 #endif
1656 /* write the secdesc */
1657 if (!sec_io_desc(desc, secdesc, ps, depth))
1658 return False;
1660 if(!prs_set_offset(ps, struct_offset))
1661 return False;
1664 relative_offset=buffer->string_at_end - buffer->struct_start;
1665 /* write its offset */
1666 #if 0 /* JRATEST */
1667 relative_offset = 0x54;
1668 #endif
1670 if (!prs_uint32("offset", ps, depth, &relative_offset))
1671 return False;
1672 } else {
1673 uint32 old_offset;
1675 /* read the offset */
1676 if (!prs_uint32("offset", ps, depth, &buffer->string_at_end))
1677 return False;
1679 old_offset = prs_offset(ps);
1680 if(!prs_set_offset(ps, buffer->string_at_end + buffer->struct_start))
1681 return False;
1683 /* read the sd */
1684 if (!sec_io_desc(desc, secdesc, ps, depth))
1685 return False;
1687 if(!prs_set_offset(ps, old_offset))
1688 return False;
1690 return True;
1693 /*******************************************************************
1694 Parse a DEVMODE structure and its relative pointer.
1695 ********************************************************************/
1696 static BOOL new_smb_io_reldevmode(char *desc, NEW_BUFFER *buffer, int depth, DEVICEMODE **devmode)
1698 prs_struct *ps=&buffer->prs;
1700 prs_debug(ps, depth, desc, "new_smb_io_reldevmode");
1701 depth++;
1703 if (MARSHALLING(ps)) {
1704 uint32 struct_offset = prs_offset(ps);
1705 uint32 relative_offset;
1707 if (*devmode == NULL) {
1708 relative_offset=0;
1709 if (!prs_uint32("offset", ps, depth, &relative_offset))
1710 return False;
1711 DEBUG(8, ("boing, the devmode was NULL\n"));
1713 return True;
1716 buffer->string_at_end -= ((*devmode)->size + (*devmode)->driverextra);
1718 if(!prs_set_offset(ps, buffer->string_at_end))
1719 return False;
1721 /* write the DEVMODE */
1722 if (!spoolss_io_devmode(desc, ps, depth, *devmode))
1723 return False;
1725 if(!prs_set_offset(ps, struct_offset))
1726 return False;
1728 relative_offset=buffer->string_at_end - buffer->struct_start;
1729 /* write its offset */
1730 if (!prs_uint32("offset", ps, depth, &relative_offset))
1731 return False;
1733 else {
1734 uint32 old_offset;
1736 /* read the offset */
1737 if (!prs_uint32("offset", ps, depth, &buffer->string_at_end))
1738 return False;
1740 old_offset = prs_offset(ps);
1741 if(!prs_set_offset(ps, buffer->string_at_end + buffer->struct_start))
1742 return False;
1744 /* read the string */
1745 if((*devmode=(DEVICEMODE *)malloc(sizeof(DEVICEMODE))) == NULL)
1746 return False;
1747 if (!spoolss_io_devmode(desc, ps, depth, *devmode))
1748 return False;
1750 if(!prs_set_offset(ps, old_offset))
1751 return False;
1753 return True;
1757 /*******************************************************************
1758 Parse a PRINTER_INFO_0 structure.
1759 ********************************************************************/
1760 BOOL new_smb_io_printer_info_0(char *desc, NEW_BUFFER *buffer, PRINTER_INFO_0 *info, int depth)
1762 prs_struct *ps=&(buffer->prs);
1764 prs_debug(ps, depth, desc, "smb_io_printer_info_0");
1765 depth++;
1767 buffer->struct_start=prs_offset(ps);
1769 if (!new_smb_io_relstr("printername", buffer, depth, &info->printername))
1770 return False;
1771 if (!new_smb_io_relstr("servername", buffer, depth, &info->servername))
1772 return False;
1774 if(!prs_uint32("cjobs", ps, depth, &info->cjobs))
1775 return False;
1776 if(!prs_uint32("total_jobs", ps, depth, &info->total_jobs))
1777 return False;
1778 if(!prs_uint32("total_bytes", ps, depth, &info->total_bytes))
1779 return False;
1781 if(!prs_uint16("year", ps, depth, &info->year))
1782 return False;
1783 if(!prs_uint16("month", ps, depth, &info->month))
1784 return False;
1785 if(!prs_uint16("dayofweek", ps, depth, &info->dayofweek))
1786 return False;
1787 if(!prs_uint16("day", ps, depth, &info->day))
1788 return False;
1789 if(!prs_uint16("hour", ps, depth, &info->hour))
1790 return False;
1791 if(!prs_uint16("minute", ps, depth, &info->minute))
1792 return False;
1793 if(!prs_uint16("second", ps, depth, &info->second))
1794 return False;
1795 if(!prs_uint16("milliseconds", ps, depth, &info->milliseconds))
1796 return False;
1798 if(!prs_uint32("global_counter", ps, depth, &info->global_counter))
1799 return False;
1800 if(!prs_uint32("total_pages", ps, depth, &info->total_pages))
1801 return False;
1803 if(!prs_uint16("major_version", ps, depth, &info->major_version))
1804 return False;
1805 if(!prs_uint16("build_version", ps, depth, &info->build_version))
1806 return False;
1807 if(!prs_uint32("unknown7", ps, depth, &info->unknown7))
1808 return False;
1809 if(!prs_uint32("unknown8", ps, depth, &info->unknown8))
1810 return False;
1811 if(!prs_uint32("unknown9", ps, depth, &info->unknown9))
1812 return False;
1813 if(!prs_uint32("session_counter", ps, depth, &info->session_counter))
1814 return False;
1815 if(!prs_uint32("unknown11", ps, depth, &info->unknown11))
1816 return False;
1817 if(!prs_uint32("printer_errors", ps, depth, &info->printer_errors))
1818 return False;
1819 if(!prs_uint32("unknown13", ps, depth, &info->unknown13))
1820 return False;
1821 if(!prs_uint32("unknown14", ps, depth, &info->unknown14))
1822 return False;
1823 if(!prs_uint32("unknown15", ps, depth, &info->unknown15))
1824 return False;
1825 if(!prs_uint32("unknown16", ps, depth, &info->unknown16))
1826 return False;
1827 if(!prs_uint32("change_id", ps, depth, &info->change_id))
1828 return False;
1829 if(!prs_uint32("unknown18", ps, depth, &info->unknown18))
1830 return False;
1831 if(!prs_uint32("status" , ps, depth, &info->status))
1832 return False;
1833 if(!prs_uint32("unknown20", ps, depth, &info->unknown20))
1834 return False;
1835 if(!prs_uint32("c_setprinter", ps, depth, &info->c_setprinter))
1836 return False;
1837 if(!prs_uint16("unknown22", ps, depth, &info->unknown22))
1838 return False;
1839 if(!prs_uint16("unknown23", ps, depth, &info->unknown23))
1840 return False;
1841 if(!prs_uint16("unknown24", ps, depth, &info->unknown24))
1842 return False;
1843 if(!prs_uint16("unknown25", ps, depth, &info->unknown25))
1844 return False;
1845 if(!prs_uint16("unknown26", ps, depth, &info->unknown26))
1846 return False;
1847 if(!prs_uint16("unknown27", ps, depth, &info->unknown27))
1848 return False;
1849 if(!prs_uint16("unknown28", ps, depth, &info->unknown28))
1850 return False;
1851 if(!prs_uint16("unknown29", ps, depth, &info->unknown29))
1852 return False;
1854 return True;
1857 /*******************************************************************
1858 Parse a PRINTER_INFO_1 structure.
1859 ********************************************************************/
1860 BOOL new_smb_io_printer_info_1(char *desc, NEW_BUFFER *buffer, PRINTER_INFO_1 *info, int depth)
1862 prs_struct *ps=&buffer->prs;
1864 prs_debug(ps, depth, desc, "new_smb_io_printer_info_1");
1865 depth++;
1867 buffer->struct_start=prs_offset(ps);
1869 if (!prs_uint32("flags", ps, depth, &info->flags))
1870 return False;
1871 if (!new_smb_io_relstr("description", buffer, depth, &info->description))
1872 return False;
1873 if (!new_smb_io_relstr("name", buffer, depth, &info->name))
1874 return False;
1875 if (!new_smb_io_relstr("comment", buffer, depth, &info->comment))
1876 return False;
1878 return True;
1881 /*******************************************************************
1882 Parse a PRINTER_INFO_2 structure.
1883 ********************************************************************/
1884 BOOL new_smb_io_printer_info_2(char *desc, NEW_BUFFER *buffer, PRINTER_INFO_2 *info, int depth)
1886 uint32 sec_offset;
1887 prs_struct *ps=&buffer->prs;
1888 uint32 dummy = 0;
1890 prs_debug(ps, depth, desc, "new_smb_io_printer_info_2");
1891 depth++;
1893 buffer->struct_start=prs_offset(ps);
1895 if (!new_smb_io_relstr("servername", buffer, depth, &info->servername))
1896 return False;
1897 if (!new_smb_io_relstr("printername", buffer, depth, &info->printername))
1898 return False;
1899 if (!new_smb_io_relstr("sharename", buffer, depth, &info->sharename))
1900 return False;
1901 if (!new_smb_io_relstr("portname", buffer, depth, &info->portname))
1902 return False;
1903 if (!new_smb_io_relstr("drivername", buffer, depth, &info->drivername))
1904 return False;
1905 if (!new_smb_io_relstr("comment", buffer, depth, &info->comment))
1906 return False;
1907 if (!new_smb_io_relstr("location", buffer, depth, &info->location))
1908 return False;
1910 /* NT parses the DEVMODE at the end of the struct */
1911 if (!new_smb_io_reldevmode("devmode", buffer, depth, &info->devmode))
1912 return False;
1914 if (!new_smb_io_relstr("sepfile", buffer, depth, &info->sepfile))
1915 return False;
1916 if (!new_smb_io_relstr("printprocessor", buffer, depth, &info->printprocessor))
1917 return False;
1918 if (!new_smb_io_relstr("datatype", buffer, depth, &info->datatype))
1919 return False;
1920 if (!new_smb_io_relstr("parameters", buffer, depth, &info->parameters))
1921 return False;
1923 #if 0 /* JFMTEST */
1924 if (!prs_uint32_pre("secdesc_ptr ", ps, depth, &dummy, &sec_offset))
1925 return False;
1926 #else
1927 if (!new_smb_io_relsecdesc("secdesc", buffer, depth, &info->secdesc))
1928 return False;
1929 #endif
1931 if (!prs_uint32("attributes", ps, depth, &info->attributes))
1932 return False;
1933 if (!prs_uint32("priority", ps, depth, &info->priority))
1934 return False;
1935 if (!prs_uint32("defpriority", ps, depth, &info->defaultpriority))
1936 return False;
1937 if (!prs_uint32("starttime", ps, depth, &info->starttime))
1938 return False;
1939 if (!prs_uint32("untiltime", ps, depth, &info->untiltime))
1940 return False;
1941 if (!prs_uint32("status", ps, depth, &info->status))
1942 return False;
1943 if (!prs_uint32("jobs", ps, depth, &info->cjobs))
1944 return False;
1945 if (!prs_uint32("averageppm", ps, depth, &info->averageppm))
1946 return False;
1948 #if 0 /* JFMTEST */
1949 if (!prs_uint32_post("secdesc_ptr", ps, depth, NULL, sec_offset, info->secdesc ? prs_offset(ps)-buffer->struct_start : 0 ))
1950 return False;
1952 if (!sec_io_desc("secdesc", &info->secdesc, ps, depth))
1953 return False;
1954 #endif
1955 return True;
1958 /*******************************************************************
1959 Parse a PRINTER_INFO_3 structure.
1960 ********************************************************************/
1961 BOOL new_smb_io_printer_info_3(char *desc, NEW_BUFFER *buffer, PRINTER_INFO_3 *info, int depth)
1963 prs_struct *ps=&(buffer->prs);
1965 prs_debug(ps, depth, desc, "new_smb_io_printer_info_3");
1966 depth++;
1968 buffer->struct_start=prs_offset(ps);
1970 if (!prs_uint32("flags", ps, depth, &info->flags))
1971 return False;
1972 if (!sec_io_desc("sec_desc", &info->secdesc, ps, depth))
1973 return False;
1975 return True;
1978 /*******************************************************************
1979 Parse a PORT_INFO_1 structure.
1980 ********************************************************************/
1981 BOOL new_smb_io_port_info_1(char *desc, NEW_BUFFER *buffer, PORT_INFO_1 *info, int depth)
1983 prs_struct *ps=&(buffer->prs);
1985 prs_debug(ps, depth, desc, "new_smb_io_port_info_1");
1986 depth++;
1988 buffer->struct_start=prs_offset(ps);
1990 if (!new_smb_io_relstr("port_name", buffer, depth, &info->port_name))
1991 return False;
1993 return True;
1996 /*******************************************************************
1997 Parse a PORT_INFO_2 structure.
1998 ********************************************************************/
1999 BOOL new_smb_io_port_info_2(char *desc, NEW_BUFFER *buffer, PORT_INFO_2 *info, int depth)
2001 prs_struct *ps=&(buffer->prs);
2003 prs_debug(ps, depth, desc, "new_smb_io_port_info_2");
2004 depth++;
2006 buffer->struct_start=prs_offset(ps);
2008 if (!new_smb_io_relstr("port_name", buffer, depth, &info->port_name))
2009 return False;
2010 if (!new_smb_io_relstr("monitor_name", buffer, depth, &info->monitor_name))
2011 return False;
2012 if (!new_smb_io_relstr("description", buffer, depth, &info->description))
2013 return False;
2014 if (!prs_uint32("port_type", ps, depth, &info->port_type))
2015 return False;
2016 if (!prs_uint32("reserved", ps, depth, &info->reserved))
2017 return False;
2019 return True;
2022 /*******************************************************************
2023 Parse a DRIVER_INFO_1 structure.
2024 ********************************************************************/
2025 BOOL new_smb_io_printer_driver_info_1(char *desc, NEW_BUFFER *buffer, DRIVER_INFO_1 *info, int depth)
2027 prs_struct *ps=&(buffer->prs);
2029 prs_debug(ps, depth, desc, "new_smb_io_printer_driver_info_1");
2030 depth++;
2032 buffer->struct_start=prs_offset(ps);
2034 if (!new_smb_io_relstr("name", buffer, depth, &info->name))
2035 return False;
2037 return True;
2041 /*******************************************************************
2042 Parse a DRIVER_INFO_2 structure.
2043 ********************************************************************/
2044 BOOL new_smb_io_printer_driver_info_2(char *desc, NEW_BUFFER *buffer, DRIVER_INFO_2 *info, int depth)
2046 prs_struct *ps=&(buffer->prs);
2048 prs_debug(ps, depth, desc, "new_smb_io_printer_driver_info_2");
2049 depth++;
2051 buffer->struct_start=prs_offset(ps);
2053 if (!prs_uint32("version", ps, depth, &info->version))
2054 return False;
2055 if (!new_smb_io_relstr("name", buffer, depth, &info->name))
2056 return False;
2057 if (!new_smb_io_relstr("architecture", buffer, depth, &info->architecture))
2058 return False;
2059 if (!new_smb_io_relstr("driverpath", buffer, depth, &info->driverpath))
2060 return False;
2061 if (!new_smb_io_relstr("datafile", buffer, depth, &info->datafile))
2062 return False;
2063 if (!new_smb_io_relstr("configfile", buffer, depth, &info->configfile))
2064 return False;
2066 return True;
2070 /*******************************************************************
2071 Parse a DRIVER_INFO_3 structure.
2072 ********************************************************************/
2073 BOOL new_smb_io_printer_driver_info_3(char *desc, NEW_BUFFER *buffer, DRIVER_INFO_3 *info, int depth)
2075 prs_struct *ps=&(buffer->prs);
2077 prs_debug(ps, depth, desc, "new_smb_io_printer_driver_info_3");
2078 depth++;
2080 buffer->struct_start=prs_offset(ps);
2082 if (!prs_uint32("version", ps, depth, &info->version))
2083 return False;
2084 if (!new_smb_io_relstr("name", buffer, depth, &info->name))
2085 return False;
2086 if (!new_smb_io_relstr("architecture", buffer, depth, &info->architecture))
2087 return False;
2088 if (!new_smb_io_relstr("driverpath", buffer, depth, &info->driverpath))
2089 return False;
2090 if (!new_smb_io_relstr("datafile", buffer, depth, &info->datafile))
2091 return False;
2092 if (!new_smb_io_relstr("configfile", buffer, depth, &info->configfile))
2093 return False;
2094 if (!new_smb_io_relstr("helpfile", buffer, depth, &info->helpfile))
2095 return False;
2097 if (!new_smb_io_relarraystr("dependentfiles", buffer, depth, &info->dependentfiles))
2098 return False;
2100 if (!new_smb_io_relstr("monitorname", buffer, depth, &info->monitorname))
2101 return False;
2102 if (!new_smb_io_relstr("defaultdatatype", buffer, depth, &info->defaultdatatype))
2103 return False;
2105 return True;
2109 /*******************************************************************
2110 Parse a JOB_INFO_1 structure.
2111 ********************************************************************/
2112 BOOL new_smb_io_job_info_1(char *desc, NEW_BUFFER *buffer, JOB_INFO_1 *info, int depth)
2114 prs_struct *ps=&(buffer->prs);
2116 prs_debug(ps, depth, desc, "new_smb_io_job_info_1");
2117 depth++;
2119 buffer->struct_start=prs_offset(ps);
2121 if (!prs_uint32("jobid", ps, depth, &info->jobid))
2122 return False;
2123 if (!new_smb_io_relstr("printername", buffer, depth, &info->printername))
2124 return False;
2125 if (!new_smb_io_relstr("machinename", buffer, depth, &info->machinename))
2126 return False;
2127 if (!new_smb_io_relstr("username", buffer, depth, &info->username))
2128 return False;
2129 if (!new_smb_io_relstr("document", buffer, depth, &info->document))
2130 return False;
2131 if (!new_smb_io_relstr("datatype", buffer, depth, &info->datatype))
2132 return False;
2133 if (!new_smb_io_relstr("text_status", buffer, depth, &info->text_status))
2134 return False;
2135 if (!prs_uint32("status", ps, depth, &info->status))
2136 return False;
2137 if (!prs_uint32("priority", ps, depth, &info->priority))
2138 return False;
2139 if (!prs_uint32("position", ps, depth, &info->position))
2140 return False;
2141 if (!prs_uint32("totalpages", ps, depth, &info->totalpages))
2142 return False;
2143 if (!prs_uint32("pagesprinted", ps, depth, &info->pagesprinted))
2144 return False;
2145 if (!spoolss_io_system_time("submitted", ps, depth, &info->submitted))
2146 return False;
2148 return True;
2151 /*******************************************************************
2152 Parse a JOB_INFO_2 structure.
2153 ********************************************************************/
2154 BOOL new_smb_io_job_info_2(char *desc, NEW_BUFFER *buffer, JOB_INFO_2 *info, int depth)
2156 uint pipo=0;
2157 prs_struct *ps=&(buffer->prs);
2159 prs_debug(ps, depth, desc, "new_smb_io_job_info_2");
2160 depth++;
2162 buffer->struct_start=prs_offset(ps);
2164 if (!prs_uint32("jobid",ps, depth, &info->jobid))
2165 return False;
2166 if (!new_smb_io_relstr("printername", buffer, depth, &info->printername))
2167 return False;
2168 if (!new_smb_io_relstr("machinename", buffer, depth, &info->machinename))
2169 return False;
2170 if (!new_smb_io_relstr("username", buffer, depth, &info->username))
2171 return False;
2172 if (!new_smb_io_relstr("document", buffer, depth, &info->document))
2173 return False;
2174 if (!new_smb_io_relstr("notifyname", buffer, depth, &info->notifyname))
2175 return False;
2176 if (!new_smb_io_relstr("datatype", buffer, depth, &info->datatype))
2177 return False;
2179 if (!new_smb_io_relstr("printprocessor", buffer, depth, &info->printprocessor))
2180 return False;
2181 if (!new_smb_io_relstr("parameters", buffer, depth, &info->parameters))
2182 return False;
2183 if (!new_smb_io_relstr("drivername", buffer, depth, &info->drivername))
2184 return False;
2185 if (!new_smb_io_reldevmode("devmode", buffer, depth, &info->devmode))
2186 return False;
2187 if (!new_smb_io_relstr("text_status", buffer, depth, &info->text_status))
2188 return False;
2190 /* SEC_DESC sec_desc;*/
2191 if (!prs_uint32("Hack! sec desc", ps, depth, &pipo))
2192 return False;
2194 if (!prs_uint32("status",ps, depth, &info->status))
2195 return False;
2196 if (!prs_uint32("priority",ps, depth, &info->priority))
2197 return False;
2198 if (!prs_uint32("position",ps, depth, &info->position))
2199 return False;
2200 if (!prs_uint32("starttime",ps, depth, &info->starttime))
2201 return False;
2202 if (!prs_uint32("untiltime",ps, depth, &info->untiltime))
2203 return False;
2204 if (!prs_uint32("totalpages",ps, depth, &info->totalpages))
2205 return False;
2206 if (!prs_uint32("size",ps, depth, &info->size))
2207 return False;
2208 if (!spoolss_io_system_time("submitted", ps, depth, &info->submitted) )
2209 return False;
2210 if (!prs_uint32("timeelapsed",ps, depth, &info->timeelapsed))
2211 return False;
2212 if (!prs_uint32("pagesprinted",ps, depth, &info->pagesprinted))
2213 return False;
2215 return True;
2218 /*******************************************************************
2219 ********************************************************************/
2220 BOOL new_smb_io_form_1(char *desc, NEW_BUFFER *buffer, FORM_1 *info, int depth)
2222 prs_struct *ps=&(buffer->prs);
2224 prs_debug(ps, depth, desc, "new_smb_io_form_1");
2225 depth++;
2227 buffer->struct_start=prs_offset(ps);
2229 if (!prs_uint32("flag", ps, depth, &info->flag))
2230 return False;
2232 if (!new_smb_io_relstr("name", buffer, depth, &info->name))
2233 return False;
2235 if (!prs_uint32("width", ps, depth, &info->width))
2236 return False;
2237 if (!prs_uint32("length", ps, depth, &info->length))
2238 return False;
2239 if (!prs_uint32("left", ps, depth, &info->left))
2240 return False;
2241 if (!prs_uint32("top", ps, depth, &info->top))
2242 return False;
2243 if (!prs_uint32("right", ps, depth, &info->right))
2244 return False;
2245 if (!prs_uint32("bottom", ps, depth, &info->bottom))
2246 return False;
2248 return True;
2251 /*******************************************************************
2252 Read/write a BUFFER struct.
2253 ********************************************************************/
2254 static BOOL new_spoolss_io_buffer(char *desc, prs_struct *ps, int depth, NEW_BUFFER *buffer)
2256 if (buffer == NULL)
2257 return False;
2259 prs_debug(ps, depth, desc, "new_spoolss_io_buffer");
2260 depth++;
2262 if (!prs_uint32("ptr", ps, depth, &buffer->ptr))
2263 return False;
2265 /* reading */
2266 if (UNMARSHALLING(ps)) {
2267 buffer->size=0;
2268 buffer->string_at_end=0;
2270 if (buffer->ptr==0) {
2271 if (!prs_init(&buffer->prs, 0, 4, prs_get_mem_context(ps), UNMARSHALL))
2272 return False;
2273 return True;
2276 if (!prs_uint32("size", ps, depth, &buffer->size))
2277 return False;
2279 if (!prs_init(&buffer->prs, buffer->size, 4, prs_get_mem_context(ps), UNMARSHALL))
2280 return False;
2282 if (!prs_append_some_prs_data(&buffer->prs, ps, prs_offset(ps), buffer->size))
2283 return False;
2285 if (!prs_set_offset(&buffer->prs, 0))
2286 return False;
2288 if (!prs_set_offset(ps, buffer->size+prs_offset(ps)))
2289 return False;
2291 buffer->string_at_end=buffer->size;
2293 return True;
2295 else {
2296 /* writing */
2297 if (buffer->ptr==0)
2298 return True;
2300 if (!prs_uint32("size", ps, depth, &buffer->size))
2301 return False;
2302 if (!prs_append_some_prs_data(ps, &buffer->prs, 0, buffer->size))
2303 return False;
2305 return True;
2309 /*******************************************************************
2310 move a BUFFER from the query to the reply.
2311 ********************************************************************/
2312 void new_spoolss_move_buffer(NEW_BUFFER *src, NEW_BUFFER **dest)
2314 prs_switch_type(&src->prs, MARSHALL);
2315 if(!prs_set_offset(&src->prs, 0))
2316 return;
2317 prs_force_dynamic(&(src->prs));
2319 *dest=src;
2322 /*******************************************************************
2323 create a BUFFER struct.
2324 ********************************************************************/
2325 BOOL new_spoolss_allocate_buffer(NEW_BUFFER **buffer)
2327 if (buffer==NULL)
2328 return False;
2330 if((*buffer=(NEW_BUFFER *)malloc(sizeof(NEW_BUFFER))) == NULL) {
2331 DEBUG(0,("new_spoolss_allocate_buffer: malloc fail for size %u.\n",
2332 (unsigned int)sizeof(NEW_BUFFER) ));
2333 return False;
2336 (*buffer)->ptr=0x0;
2337 (*buffer)->size=0;
2338 (*buffer)->string_at_end=0;
2339 return True;
2342 /*******************************************************************
2343 Destroy a BUFFER struct.
2344 ********************************************************************/
2345 void new_spoolss_free_buffer(NEW_BUFFER *buffer)
2347 if (buffer==NULL)
2348 return;
2350 prs_mem_free(&buffer->prs);
2351 buffer->ptr=0x0;
2352 buffer->size=0;
2353 buffer->string_at_end=0;
2355 free(buffer);
2358 /*******************************************************************
2359 Get the size of a BUFFER struct.
2360 ********************************************************************/
2361 uint32 new_get_buffer_size(NEW_BUFFER *buffer)
2363 return (buffer->size);
2367 /*******************************************************************
2368 Parse a DRIVER_DIRECTORY_1 structure.
2369 ********************************************************************/
2370 BOOL new_smb_io_driverdir_1(char *desc, NEW_BUFFER *buffer, DRIVER_DIRECTORY_1 *info, int depth)
2372 prs_struct *ps=&(buffer->prs);
2374 prs_debug(ps, depth, desc, "new_smb_io_driverdir_1");
2375 depth++;
2377 buffer->struct_start=prs_offset(ps);
2379 if (!spoolss_smb_io_unistr(desc, &info->name, ps, depth))
2380 return False;
2382 return True;
2385 /*******************************************************************
2386 Parse a PORT_INFO_1 structure.
2387 ********************************************************************/
2388 BOOL new_smb_io_port_1(char *desc, NEW_BUFFER *buffer, PORT_INFO_1 *info, int depth)
2390 prs_struct *ps=&(buffer->prs);
2392 prs_debug(ps, depth, desc, "new_smb_io_port_1");
2393 depth++;
2395 buffer->struct_start=prs_offset(ps);
2397 if(!new_smb_io_relstr("port_name", buffer, depth, &info->port_name))
2398 return False;
2400 return True;
2403 /*******************************************************************
2404 Parse a PORT_INFO_2 structure.
2405 ********************************************************************/
2406 BOOL new_smb_io_port_2(char *desc, NEW_BUFFER *buffer, PORT_INFO_2 *info, int depth)
2408 prs_struct *ps=&(buffer->prs);
2410 prs_debug(ps, depth, desc, "new_smb_io_port_2");
2411 depth++;
2413 buffer->struct_start=prs_offset(ps);
2415 if(!new_smb_io_relstr("port_name", buffer, depth, &info->port_name))
2416 return False;
2417 if(!new_smb_io_relstr("monitor_name", buffer, depth, &info->monitor_name))
2418 return False;
2419 if(!new_smb_io_relstr("description", buffer, depth, &info->description))
2420 return False;
2421 if(!prs_uint32("port_type", ps, depth, &info->port_type))
2422 return False;
2423 if(!prs_uint32("reserved", ps, depth, &info->reserved))
2424 return False;
2426 return True;
2430 /*******************************************************************
2431 ********************************************************************/
2432 BOOL smb_io_printprocessor_info_1(char *desc, NEW_BUFFER *buffer, PRINTPROCESSOR_1 *info, int depth)
2434 prs_struct *ps=&(buffer->prs);
2436 prs_debug(ps, depth, desc, "smb_io_printprocessor_info_1");
2437 depth++;
2439 buffer->struct_start=prs_offset(ps);
2441 if (new_smb_io_relstr("name", buffer, depth, &info->name))
2442 return False;
2444 return True;
2447 /*******************************************************************
2448 ********************************************************************/
2449 BOOL smb_io_printprocdatatype_info_1(char *desc, NEW_BUFFER *buffer, PRINTPROCDATATYPE_1 *info, int depth)
2451 prs_struct *ps=&(buffer->prs);
2453 prs_debug(ps, depth, desc, "smb_io_printprocdatatype_info_1");
2454 depth++;
2456 buffer->struct_start=prs_offset(ps);
2458 if (new_smb_io_relstr("name", buffer, depth, &info->name))
2459 return False;
2461 return True;
2464 /*******************************************************************
2465 ********************************************************************/
2466 BOOL smb_io_printmonitor_info_1(char *desc, NEW_BUFFER *buffer, PRINTMONITOR_1 *info, int depth)
2468 prs_struct *ps=&buffer->prs;
2470 prs_debug(ps, depth, desc, "smb_io_printmonitor_info_1");
2471 depth++;
2473 buffer->struct_start=prs_offset(ps);
2475 if (!new_smb_io_relstr("name", buffer, depth, &info->name))
2476 return False;
2478 return True;
2481 /*******************************************************************
2482 ********************************************************************/
2483 BOOL smb_io_printmonitor_info_2(char *desc, NEW_BUFFER *buffer, PRINTMONITOR_2 *info, int depth)
2485 prs_struct *ps=&(buffer->prs);
2487 prs_debug(ps, depth, desc, "smb_io_printmonitor_info_2");
2488 depth++;
2490 buffer->struct_start=prs_offset(ps);
2492 if (!new_smb_io_relstr("name", buffer, depth, &info->name))
2493 return False;
2494 if (!new_smb_io_relstr("environment", buffer, depth, &info->environment))
2495 return False;
2496 if (!new_smb_io_relstr("dll_name", buffer, depth, &info->dll_name))
2497 return False;
2499 return True;
2502 /*******************************************************************
2503 return the size required by a struct in the stream
2504 ********************************************************************/
2505 uint32 spoolss_size_printer_info_0(PRINTER_INFO_0 *info)
2507 int size=0;
2509 size+=size_of_relative_string( &info->printername );
2510 size+=size_of_relative_string( &info->servername );
2512 size+=size_of_uint32( &info->cjobs);
2513 size+=size_of_uint32( &info->total_jobs);
2514 size+=size_of_uint32( &info->total_bytes);
2516 size+=size_of_uint16( &info->year);
2517 size+=size_of_uint16( &info->month);
2518 size+=size_of_uint16( &info->dayofweek);
2519 size+=size_of_uint16( &info->day);
2520 size+=size_of_uint16( &info->hour);
2521 size+=size_of_uint16( &info->minute);
2522 size+=size_of_uint16( &info->second);
2523 size+=size_of_uint16( &info->milliseconds);
2525 size+=size_of_uint32( &info->global_counter);
2526 size+=size_of_uint32( &info->total_pages);
2528 size+=size_of_uint16( &info->major_version);
2529 size+=size_of_uint16( &info->build_version);
2531 size+=size_of_uint32( &info->unknown7);
2532 size+=size_of_uint32( &info->unknown8);
2533 size+=size_of_uint32( &info->unknown9);
2534 size+=size_of_uint32( &info->session_counter);
2535 size+=size_of_uint32( &info->unknown11);
2536 size+=size_of_uint32( &info->printer_errors);
2537 size+=size_of_uint32( &info->unknown13);
2538 size+=size_of_uint32( &info->unknown14);
2539 size+=size_of_uint32( &info->unknown15);
2540 size+=size_of_uint32( &info->unknown16);
2541 size+=size_of_uint32( &info->change_id);
2542 size+=size_of_uint32( &info->unknown18);
2543 size+=size_of_uint32( &info->status);
2544 size+=size_of_uint32( &info->unknown20);
2545 size+=size_of_uint32( &info->c_setprinter);
2547 size+=size_of_uint16( &info->unknown22);
2548 size+=size_of_uint16( &info->unknown23);
2549 size+=size_of_uint16( &info->unknown24);
2550 size+=size_of_uint16( &info->unknown25);
2551 size+=size_of_uint16( &info->unknown26);
2552 size+=size_of_uint16( &info->unknown27);
2553 size+=size_of_uint16( &info->unknown28);
2554 size+=size_of_uint16( &info->unknown29);
2556 return size;
2559 /*******************************************************************
2560 return the size required by a struct in the stream
2561 ********************************************************************/
2562 uint32 spoolss_size_printer_info_1(PRINTER_INFO_1 *info)
2564 int size=0;
2566 size+=size_of_uint32( &info->flags );
2567 size+=size_of_relative_string( &info->description );
2568 size+=size_of_relative_string( &info->name );
2569 size+=size_of_relative_string( &info->comment );
2571 return size;
2574 /*******************************************************************
2575 return the size required by a struct in the stream
2576 ********************************************************************/
2577 uint32 spoolss_size_printer_info_2(PRINTER_INFO_2 *info)
2579 uint32 size=0;
2581 size += 4;
2582 /* JRA !!!! TESTME - WHAT ABOUT prs_align.... !!! */
2583 size += sec_desc_size( info->secdesc );
2585 size+=size_of_device_mode( info->devmode );
2587 size+=size_of_relative_string( &info->servername );
2588 size+=size_of_relative_string( &info->printername );
2589 size+=size_of_relative_string( &info->sharename );
2590 size+=size_of_relative_string( &info->portname );
2591 size+=size_of_relative_string( &info->drivername );
2592 size+=size_of_relative_string( &info->comment );
2593 size+=size_of_relative_string( &info->location );
2595 size+=size_of_relative_string( &info->sepfile );
2596 size+=size_of_relative_string( &info->printprocessor );
2597 size+=size_of_relative_string( &info->datatype );
2598 size+=size_of_relative_string( &info->parameters );
2600 size+=size_of_uint32( &info->attributes );
2601 size+=size_of_uint32( &info->priority );
2602 size+=size_of_uint32( &info->defaultpriority );
2603 size+=size_of_uint32( &info->starttime );
2604 size+=size_of_uint32( &info->untiltime );
2605 size+=size_of_uint32( &info->status );
2606 size+=size_of_uint32( &info->cjobs );
2607 size+=size_of_uint32( &info->averageppm );
2608 return size;
2611 /*******************************************************************
2612 return the size required by a struct in the stream
2613 ********************************************************************/
2614 uint32 spoolss_size_printer_info_3(PRINTER_INFO_3 *info)
2616 /* The 4 is for the self relative pointer.. */
2617 /* JRA !!!! TESTME - WHAT ABOUT prs_align.... !!! */
2618 return 4 + (uint32)sec_desc_size( info->secdesc );
2621 /*******************************************************************
2622 return the size required by a struct in the stream
2623 ********************************************************************/
2624 uint32 spoolss_size_printer_driver_info_1(DRIVER_INFO_1 *info)
2626 int size=0;
2627 size+=size_of_relative_string( &info->name );
2629 return size;
2632 /*******************************************************************
2633 return the size required by a struct in the stream
2634 ********************************************************************/
2635 uint32 spoolss_size_printer_driver_info_2(DRIVER_INFO_2 *info)
2637 int size=0;
2638 size+=size_of_uint32( &info->version );
2639 size+=size_of_relative_string( &info->name );
2640 size+=size_of_relative_string( &info->architecture );
2641 size+=size_of_relative_string( &info->driverpath );
2642 size+=size_of_relative_string( &info->datafile );
2643 size+=size_of_relative_string( &info->configfile );
2645 return size;
2648 /*******************************************************************
2649 return the size required by a struct in the stream
2650 ********************************************************************/
2651 uint32 spoolss_size_printer_driver_info_3(DRIVER_INFO_3 *info)
2653 int size=0;
2654 uint16 *string;
2655 int i=0;
2657 size+=size_of_uint32( &info->version );
2658 size+=size_of_relative_string( &info->name );
2659 size+=size_of_relative_string( &info->architecture );
2660 size+=size_of_relative_string( &info->driverpath );
2661 size+=size_of_relative_string( &info->datafile );
2662 size+=size_of_relative_string( &info->configfile );
2663 size+=size_of_relative_string( &info->helpfile );
2664 size+=size_of_relative_string( &info->monitorname );
2665 size+=size_of_relative_string( &info->defaultdatatype );
2667 string=info->dependentfiles;
2668 if (string) {
2669 for (i=0; (string[i]!=0x0000) || (string[i+1]!=0x0000); i++);
2672 i=i+2; /* to count all chars including the leading zero */
2673 i=2*i; /* because we need the value in bytes */
2674 i=i+4; /* the offset pointer size */
2676 size+=i;
2678 return size;
2681 /*******************************************************************
2682 return the size required by a struct in the stream
2683 ********************************************************************/
2684 uint32 spoolss_size_job_info_1(JOB_INFO_1 *info)
2686 int size=0;
2687 size+=size_of_uint32( &info->jobid );
2688 size+=size_of_relative_string( &info->printername );
2689 size+=size_of_relative_string( &info->machinename );
2690 size+=size_of_relative_string( &info->username );
2691 size+=size_of_relative_string( &info->document );
2692 size+=size_of_relative_string( &info->datatype );
2693 size+=size_of_relative_string( &info->text_status );
2694 size+=size_of_uint32( &info->status );
2695 size+=size_of_uint32( &info->priority );
2696 size+=size_of_uint32( &info->position );
2697 size+=size_of_uint32( &info->totalpages );
2698 size+=size_of_uint32( &info->pagesprinted );
2699 size+=size_of_systemtime( &info->submitted );
2701 return size;
2704 /*******************************************************************
2705 return the size required by a struct in the stream
2706 ********************************************************************/
2707 uint32 spoolss_size_job_info_2(JOB_INFO_2 *info)
2709 int size=0;
2711 size+=4; /* size of sec desc ptr */
2713 size+=size_of_uint32( &info->jobid );
2714 size+=size_of_relative_string( &info->printername );
2715 size+=size_of_relative_string( &info->machinename );
2716 size+=size_of_relative_string( &info->username );
2717 size+=size_of_relative_string( &info->document );
2718 size+=size_of_relative_string( &info->notifyname );
2719 size+=size_of_relative_string( &info->datatype );
2720 size+=size_of_relative_string( &info->printprocessor );
2721 size+=size_of_relative_string( &info->parameters );
2722 size+=size_of_relative_string( &info->drivername );
2723 size+=size_of_device_mode( info->devmode );
2724 size+=size_of_relative_string( &info->text_status );
2725 /* SEC_DESC sec_desc;*/
2726 size+=size_of_uint32( &info->status );
2727 size+=size_of_uint32( &info->priority );
2728 size+=size_of_uint32( &info->position );
2729 size+=size_of_uint32( &info->starttime );
2730 size+=size_of_uint32( &info->untiltime );
2731 size+=size_of_uint32( &info->totalpages );
2732 size+=size_of_uint32( &info->size );
2733 size+=size_of_systemtime( &info->submitted );
2734 size+=size_of_uint32( &info->timeelapsed );
2735 size+=size_of_uint32( &info->pagesprinted );
2737 return size;
2740 /*******************************************************************
2741 return the size required by a struct in the stream
2742 ********************************************************************/
2743 uint32 spoolss_size_form_1(FORM_1 *info)
2745 int size=0;
2747 size+=size_of_uint32( &info->flag );
2748 size+=size_of_relative_string( &info->name );
2749 size+=size_of_uint32( &info->width );
2750 size+=size_of_uint32( &info->length );
2751 size+=size_of_uint32( &info->left );
2752 size+=size_of_uint32( &info->top );
2753 size+=size_of_uint32( &info->right );
2754 size+=size_of_uint32( &info->bottom );
2756 return size;
2759 /*******************************************************************
2760 return the size required by a struct in the stream
2761 ********************************************************************/
2762 uint32 spoolss_size_port_info_1(PORT_INFO_1 *info)
2764 int size=0;
2766 size+=size_of_relative_string( &info->port_name );
2768 return size;
2771 /*******************************************************************
2772 return the size required by a struct in the stream
2773 ********************************************************************/
2774 uint32 spoolss_size_driverdir_info_1(DRIVER_DIRECTORY_1 *info)
2776 int size=0;
2778 size=str_len_uni(&info->name); /* the string length */
2779 size=size+1; /* add the leading zero */
2780 size=size*2; /* convert in char */
2782 return size;
2785 /*******************************************************************
2786 return the size required by a struct in the stream
2787 ********************************************************************/
2788 uint32 spoolss_size_port_info_2(PORT_INFO_2 *info)
2790 int size=0;
2792 size+=size_of_relative_string( &info->port_name );
2793 size+=size_of_relative_string( &info->monitor_name );
2794 size+=size_of_relative_string( &info->description );
2796 size+=size_of_uint32( &info->port_type );
2797 size+=size_of_uint32( &info->reserved );
2799 return size;
2802 /*******************************************************************
2803 return the size required by a struct in the stream
2804 ********************************************************************/
2805 uint32 spoolss_size_printprocessor_info_1(PRINTPROCESSOR_1 *info)
2807 int size=0;
2808 size+=size_of_relative_string( &info->name );
2810 return size;
2813 /*******************************************************************
2814 return the size required by a struct in the stream
2815 ********************************************************************/
2816 uint32 spoolss_size_printprocdatatype_info_1(PRINTPROCDATATYPE_1 *info)
2818 int size=0;
2819 size+=size_of_relative_string( &info->name );
2821 return size;
2824 /*******************************************************************
2825 return the size required by a struct in the stream
2826 ********************************************************************/
2827 uint32 spoolss_size_printmonitor_info_1(PRINTMONITOR_1 *info)
2829 int size=0;
2830 size+=size_of_relative_string( &info->name );
2832 return size;
2835 /*******************************************************************
2836 return the size required by a struct in the stream
2837 ********************************************************************/
2838 uint32 spoolss_size_printmonitor_info_2(PRINTMONITOR_2 *info)
2840 int size=0;
2841 size+=size_of_relative_string( &info->name);
2842 size+=size_of_relative_string( &info->environment);
2843 size+=size_of_relative_string( &info->dll_name);
2845 return size;
2848 /*******************************************************************
2849 * init a structure.
2850 ********************************************************************/
2851 BOOL make_spoolss_q_getprinterdriver2(SPOOL_Q_GETPRINTERDRIVER2 *q_u,
2852 const POLICY_HND *hnd,
2853 const fstring architecture,
2854 uint32 level, uint32 clientmajor, uint32 clientminor,
2855 NEW_BUFFER *buffer, uint32 offered)
2857 if (q_u == NULL)
2858 return False;
2860 memcpy(&q_u->handle, hnd, sizeof(q_u->handle));
2862 init_buf_unistr2(&q_u->architecture, &q_u->architecture_ptr, architecture);
2864 q_u->level=level;
2865 q_u->clientmajorversion=clientmajor;
2866 q_u->clientminorversion=clientminor;
2868 q_u->buffer=buffer;
2869 q_u->offered=offered;
2871 return True;
2874 /*******************************************************************
2875 * read a structure.
2876 * called from spoolss_getprinterdriver2 (srv_spoolss.c)
2877 ********************************************************************/
2878 BOOL spoolss_io_q_getprinterdriver2(char *desc, SPOOL_Q_GETPRINTERDRIVER2 *q_u, prs_struct *ps, int depth)
2880 prs_debug(ps, depth, desc, "spoolss_io_q_getprinterdriver2");
2881 depth++;
2883 if(!prs_align(ps))
2884 return False;
2886 if(!smb_io_pol_hnd("printer handle", &q_u->handle, ps, depth))
2887 return False;
2888 if(!prs_uint32("architecture_ptr", ps, depth, &q_u->architecture_ptr))
2889 return False;
2890 if(!smb_io_unistr2("architecture", &q_u->architecture, q_u->architecture_ptr, ps, depth))
2891 return False;
2893 if(!prs_align(ps))
2894 return False;
2895 if(!prs_uint32("level", ps, depth, &q_u->level))
2896 return False;
2898 if(!new_spoolss_io_buffer("", ps, depth, q_u->buffer))
2899 return False;
2901 if(!prs_align(ps))
2902 return False;
2904 if(!prs_uint32("offered", ps, depth, &q_u->offered))
2905 return False;
2907 if(!prs_uint32("clientmajorversion", ps, depth, &q_u->clientmajorversion))
2908 return False;
2909 if(!prs_uint32("clientminorversion", ps, depth, &q_u->clientminorversion))
2910 return False;
2912 return True;
2915 /*******************************************************************
2916 * read a structure.
2917 * called from spoolss_getprinterdriver2 (srv_spoolss.c)
2918 ********************************************************************/
2919 BOOL spoolss_io_r_getprinterdriver2(char *desc, SPOOL_R_GETPRINTERDRIVER2 *r_u, prs_struct *ps, int depth)
2921 prs_debug(ps, depth, desc, "spoolss_io_r_getprinterdriver2");
2922 depth++;
2924 if (!prs_align(ps))
2925 return False;
2927 if (!new_spoolss_io_buffer("", ps, depth, r_u->buffer))
2928 return False;
2930 if (!prs_align(ps))
2931 return False;
2932 if (!prs_uint32("needed", ps, depth, &r_u->needed))
2933 return False;
2934 if (!prs_uint32("servermajorversion", ps, depth, &r_u->servermajorversion))
2935 return False;
2936 if (!prs_uint32("serverminorversion", ps, depth, &r_u->serverminorversion))
2937 return False;
2938 if (!prs_uint32("status", ps, depth, &r_u->status))
2939 return False;
2941 return True;
2944 /*******************************************************************
2945 * init a structure.
2946 ********************************************************************/
2947 BOOL make_spoolss_q_enumprinters(SPOOL_Q_ENUMPRINTERS *q_u, uint32 flags,
2948 fstring servername, uint32 level,
2949 NEW_BUFFER *buffer, uint32 offered)
2951 q_u->flags=flags;
2953 q_u->servername_ptr = (servername != NULL) ? 1 : 0;
2954 init_unistr2(&q_u->servername, servername, strlen(servername));
2956 q_u->level=level;
2957 q_u->buffer=buffer;
2958 q_u->offered=offered;
2960 return True;
2963 /*******************************************************************
2964 * init a structure.
2965 ********************************************************************/
2966 BOOL make_spoolss_q_enumports(SPOOL_Q_ENUMPORTS *q_u,
2967 fstring servername, uint32 level,
2968 NEW_BUFFER *buffer, uint32 offered)
2970 q_u->name_ptr = (servername != NULL) ? 1 : 0;
2971 init_buf_unistr2(&q_u->name, &q_u->name_ptr, servername);
2973 q_u->level=level;
2974 q_u->buffer=buffer;
2975 q_u->offered=offered;
2977 return True;
2980 /*******************************************************************
2981 * read a structure.
2982 * called from spoolss_enumprinters (srv_spoolss.c)
2983 ********************************************************************/
2984 BOOL spoolss_io_q_enumprinters(char *desc, SPOOL_Q_ENUMPRINTERS *q_u, prs_struct *ps, int depth)
2986 prs_debug(ps, depth, desc, "spoolss_io_q_enumprinters");
2987 depth++;
2989 if (!prs_align(ps))
2990 return False;
2992 if (!prs_uint32("flags", ps, depth, &q_u->flags))
2993 return False;
2994 if (!prs_uint32("servername_ptr", ps, depth, &q_u->servername_ptr))
2995 return False;
2997 if (!smb_io_unistr2("", &q_u->servername, q_u->servername_ptr, ps, depth))
2998 return False;
3000 if (!prs_align(ps))
3001 return False;
3002 if (!prs_uint32("level", ps, depth, &q_u->level))
3003 return False;
3005 if (!new_spoolss_io_buffer("", ps, depth, q_u->buffer))
3006 return False;
3008 if (!prs_align(ps))
3009 return False;
3010 if (!prs_uint32("offered", ps, depth, &q_u->offered))
3011 return False;
3013 return True;
3016 /*******************************************************************
3017 Parse a SPOOL_R_ENUMPRINTERS structure.
3018 ********************************************************************/
3019 BOOL new_spoolss_io_r_enumprinters(char *desc, SPOOL_R_ENUMPRINTERS *r_u, prs_struct *ps, int depth)
3021 prs_debug(ps, depth, desc, "new_spoolss_io_r_enumprinters");
3022 depth++;
3024 if (!prs_align(ps))
3025 return False;
3027 if (!new_spoolss_io_buffer("", ps, depth, r_u->buffer))
3028 return False;
3030 if (!prs_align(ps))
3031 return False;
3033 if (!prs_uint32("needed", ps, depth, &r_u->needed))
3034 return False;
3036 if (!prs_uint32("returned", ps, depth, &r_u->returned))
3037 return False;
3039 if (!prs_uint32("status", ps, depth, &r_u->status))
3040 return False;
3042 return True;
3045 /*******************************************************************
3046 * write a structure.
3047 * called from spoolss_r_enum_printers (srv_spoolss.c)
3049 ********************************************************************/
3050 BOOL spoolss_io_r_getprinter(char *desc, SPOOL_R_GETPRINTER *r_u, prs_struct *ps, int depth)
3052 prs_debug(ps, depth, desc, "spoolss_io_r_getprinter");
3053 depth++;
3055 if (!prs_align(ps))
3056 return False;
3058 if (!new_spoolss_io_buffer("", ps, depth, r_u->buffer))
3059 return False;
3061 if (!prs_align(ps))
3062 return False;
3064 if (!prs_uint32("needed", ps, depth, &r_u->needed))
3065 return False;
3067 if (!prs_uint32("status", ps, depth, &r_u->status))
3068 return False;
3070 return True;
3073 /*******************************************************************
3074 * read a structure.
3075 * called from spoolss_getprinter (srv_spoolss.c)
3076 ********************************************************************/
3077 BOOL spoolss_io_q_getprinter(char *desc, SPOOL_Q_GETPRINTER *q_u, prs_struct *ps, int depth)
3079 prs_debug(ps, depth, desc, "spoolss_io_q_getprinter");
3080 depth++;
3082 if (!prs_align(ps))
3083 return False;
3085 if(!smb_io_pol_hnd("printer handle", &q_u->handle, ps, depth))
3086 return False;
3087 if (!prs_uint32("level", ps, depth, &q_u->level))
3088 return False;
3090 if (!new_spoolss_io_buffer("", ps, depth, q_u->buffer))
3091 return False;
3093 if (!prs_align(ps))
3094 return False;
3095 if (!prs_uint32("offered", ps, depth, &q_u->offered))
3096 return False;
3098 return True;
3101 /*******************************************************************
3102 * init a structure.
3103 ********************************************************************/
3104 BOOL make_spoolss_q_getprinter(SPOOL_Q_GETPRINTER *q_u, const POLICY_HND *hnd, uint32 level,
3105 NEW_BUFFER *buffer, uint32 offered)
3107 if (q_u == NULL)
3109 return False;
3111 memcpy(&q_u->handle, hnd, sizeof(q_u->handle));
3113 q_u->level=level;
3114 q_u->buffer=buffer;
3115 q_u->offered=offered;
3117 return True;
3120 /*******************************************************************
3121 ********************************************************************/
3122 BOOL spoolss_io_r_setprinter(char *desc, SPOOL_R_SETPRINTER *r_u, prs_struct *ps, int depth)
3124 prs_debug(ps, depth, desc, "spoolss_io_r_setprinter");
3125 depth++;
3127 if(!prs_align(ps))
3128 return False;
3130 if(!prs_uint32("status", ps, depth, &r_u->status))
3131 return False;
3133 return True;
3136 /*******************************************************************
3137 Delete the dynamic parts of a SPOOL_Q_SETPRINTER struct.
3138 ********************************************************************/
3140 void free_spoolss_q_setprinter(SPOOL_Q_SETPRINTER *q_u)
3142 free_spool_printer_info_level(&q_u->info);
3143 free_sec_desc_buf( &q_u->secdesc_ctr );
3144 free_devmode( q_u->devmode_ctr.devmode );
3147 /*******************************************************************
3148 Marshall/unmarshall a SPOOL_Q_SETPRINTER struct.
3149 ********************************************************************/
3151 BOOL spoolss_io_q_setprinter(char *desc, SPOOL_Q_SETPRINTER *q_u, prs_struct *ps, int depth)
3153 uint32 ptr_sec_desc = 0;
3155 prs_debug(ps, depth, desc, "spoolss_io_q_setprinter");
3156 depth++;
3158 if(!prs_align(ps))
3159 return False;
3161 if(!smb_io_pol_hnd("printer handle", &q_u->handle ,ps, depth))
3162 return False;
3163 if(!prs_uint32("level", ps, depth, &q_u->level))
3164 return False;
3166 if(!spool_io_printer_info_level("", &q_u->info, ps, depth))
3167 return False;
3169 if (!spoolss_io_devmode_cont(desc, &q_u->devmode_ctr, ps, depth))
3170 return False;
3172 switch (q_u->level)
3174 case 2:
3176 ptr_sec_desc = q_u->info.info_2->secdesc_ptr;
3177 break;
3179 case 3:
3181 ptr_sec_desc = q_u->info.info_3->secdesc_ptr;
3182 break;
3185 if (ptr_sec_desc)
3187 if (!sec_io_desc_buf(desc, &q_u->secdesc_ctr, ps, depth))
3188 return False;
3191 if(!prs_uint32("command", ps, depth, &q_u->command))
3192 return False;
3194 return True;
3197 /*******************************************************************
3198 ********************************************************************/
3199 BOOL spoolss_io_r_fcpn(char *desc, SPOOL_R_FCPN *r_u, prs_struct *ps, int depth)
3201 prs_debug(ps, depth, desc, "spoolss_io_r_fcpn");
3202 depth++;
3204 if(!prs_align(ps))
3205 return False;
3207 if(!prs_uint32("status", ps, depth, &r_u->status))
3208 return False;
3210 return True;
3213 /*******************************************************************
3214 ********************************************************************/
3215 BOOL spoolss_io_q_fcpn(char *desc, SPOOL_Q_FCPN *q_u, prs_struct *ps, int depth)
3218 prs_debug(ps, depth, desc, "spoolss_io_q_fcpn");
3219 depth++;
3221 if(!prs_align(ps))
3222 return False;
3224 if(!smb_io_pol_hnd("printer handle",&q_u->handle,ps,depth))
3225 return False;
3227 return True;
3231 /*******************************************************************
3232 ********************************************************************/
3233 BOOL spoolss_io_r_addjob(char *desc, SPOOL_R_ADDJOB *r_u, prs_struct *ps, int depth)
3235 prs_debug(ps, depth, desc, "");
3236 depth++;
3238 if(!prs_align(ps))
3239 return False;
3241 if(!prs_uint32("status", ps, depth, &r_u->status))
3242 return False;
3244 return True;
3247 /*******************************************************************
3248 ********************************************************************/
3249 BOOL spoolss_io_q_addjob(char *desc, SPOOL_Q_ADDJOB *q_u, prs_struct *ps, int depth)
3251 prs_debug(ps, depth, desc, "");
3252 depth++;
3254 if(!prs_align(ps))
3255 return False;
3257 if(!smb_io_pol_hnd("printer handle", &q_u->handle, ps, depth))
3258 return False;
3259 if(!prs_uint32("level", ps, depth, &q_u->level))
3260 return False;
3262 if(!new_spoolss_io_buffer("", ps, depth, q_u->buffer))
3263 return False;
3265 if(!prs_align(ps))
3266 return False;
3268 if(!prs_uint32("offered", ps, depth, &q_u->offered))
3269 return False;
3271 return True;
3274 /*******************************************************************
3275 ********************************************************************/
3276 BOOL spoolss_io_r_enumjobs(char *desc, SPOOL_R_ENUMJOBS *r_u, prs_struct *ps, int depth)
3278 prs_debug(ps, depth, desc, "spoolss_io_r_enumjobs");
3279 depth++;
3281 if (!prs_align(ps))
3282 return False;
3284 if (!new_spoolss_io_buffer("", ps, depth, r_u->buffer))
3285 return False;
3287 if (!prs_align(ps))
3288 return False;
3290 if (!prs_uint32("needed", ps, depth, &r_u->needed))
3291 return False;
3293 if (!prs_uint32("returned", ps, depth, &r_u->returned))
3294 return False;
3296 if (!prs_uint32("status", ps, depth, &r_u->status))
3297 return False;
3299 return True;
3303 /*******************************************************************
3304 ********************************************************************/
3305 BOOL make_spoolss_q_enumjobs(SPOOL_Q_ENUMJOBS *q_u, const POLICY_HND *hnd,
3306 uint32 firstjob,
3307 uint32 numofjobs,
3308 uint32 level,
3309 NEW_BUFFER *buffer,
3310 uint32 offered)
3312 if (q_u == NULL)
3314 return False;
3316 memcpy(&q_u->handle, hnd, sizeof(q_u->handle));
3317 q_u->firstjob = firstjob;
3318 q_u->numofjobs = numofjobs;
3319 q_u->level = level;
3320 q_u->buffer= buffer;
3321 q_u->offered = offered;
3322 return True;
3325 /*******************************************************************
3326 ********************************************************************/
3327 BOOL spoolss_io_q_enumjobs(char *desc, SPOOL_Q_ENUMJOBS *q_u, prs_struct *ps, int depth)
3329 prs_debug(ps, depth, desc, "spoolss_io_q_enumjobs");
3330 depth++;
3332 if (!prs_align(ps))
3333 return False;
3335 if (!smb_io_pol_hnd("printer handle",&q_u->handle, ps, depth))
3336 return False;
3338 if (!prs_uint32("firstjob", ps, depth, &q_u->firstjob))
3339 return False;
3340 if (!prs_uint32("numofjobs", ps, depth, &q_u->numofjobs))
3341 return False;
3342 if (!prs_uint32("level", ps, depth, &q_u->level))
3343 return False;
3345 if (!new_spoolss_io_buffer("", ps, depth, q_u->buffer))
3346 return False;
3348 if (!prs_uint32("offered", ps, depth, &q_u->offered))
3349 return False;
3351 return True;
3354 /*******************************************************************
3355 ********************************************************************/
3356 BOOL spoolss_io_r_schedulejob(char *desc, SPOOL_R_SCHEDULEJOB *r_u, prs_struct *ps, int depth)
3358 prs_debug(ps, depth, desc, "spoolss_io_r_schedulejob");
3359 depth++;
3361 if(!prs_align(ps))
3362 return False;
3364 if(!prs_uint32("status", ps, depth, &r_u->status))
3365 return False;
3367 return True;
3370 /*******************************************************************
3371 ********************************************************************/
3372 BOOL spoolss_io_q_schedulejob(char *desc, SPOOL_Q_SCHEDULEJOB *q_u, prs_struct *ps, int depth)
3374 prs_debug(ps, depth, desc, "spoolss_io_q_schedulejob");
3375 depth++;
3377 if(!prs_align(ps))
3378 return False;
3380 if(!smb_io_pol_hnd("printer handle",&q_u->handle,ps,depth))
3381 return False;
3382 if(!prs_uint32("jobid", ps, depth, &q_u->jobid))
3383 return False;
3385 return True;
3388 /*******************************************************************
3389 ********************************************************************/
3390 BOOL spoolss_io_r_setjob(char *desc, SPOOL_R_SETJOB *r_u, prs_struct *ps, int depth)
3392 prs_debug(ps, depth, desc, "spoolss_io_r_setjob");
3393 depth++;
3395 if(!prs_align(ps))
3396 return False;
3398 if(!prs_uint32("status", ps, depth, &r_u->status))
3399 return False;
3401 return True;
3404 /*******************************************************************
3405 ********************************************************************/
3406 BOOL spoolss_io_q_setjob(char *desc, SPOOL_Q_SETJOB *q_u, prs_struct *ps, int depth)
3408 prs_debug(ps, depth, desc, "spoolss_io_q_setjob");
3409 depth++;
3411 if(!prs_align(ps))
3412 return False;
3414 if(!smb_io_pol_hnd("printer handle",&q_u->handle,ps,depth))
3415 return False;
3416 if(!prs_uint32("jobid", ps, depth, &q_u->jobid))
3417 return False;
3419 * level is usually 0. If (level!=0) then I'm in trouble !
3420 * I will try to generate setjob command with level!=0, one day.
3422 if(!prs_uint32("level", ps, depth, &q_u->level))
3423 return False;
3424 if(!prs_uint32("command", ps, depth, &q_u->command))
3425 return False;
3427 return True;
3430 /*******************************************************************
3431 Parse a SPOOL_R_ENUMPRINTERDRIVERS structure.
3432 ********************************************************************/
3433 BOOL new_spoolss_io_r_enumprinterdrivers(char *desc, SPOOL_R_ENUMPRINTERDRIVERS *r_u, prs_struct *ps, int depth)
3435 prs_debug(ps, depth, desc, "new_spoolss_io_r_enumprinterdrivers");
3436 depth++;
3438 if (!prs_align(ps))
3439 return False;
3441 if (!new_spoolss_io_buffer("", ps, depth, r_u->buffer))
3442 return False;
3444 if (!prs_align(ps))
3445 return False;
3447 if (!prs_uint32("needed", ps, depth, &r_u->needed))
3448 return False;
3450 if (!prs_uint32("returned", ps, depth, &r_u->returned))
3451 return False;
3453 if (!prs_uint32("status", ps, depth, &r_u->status))
3454 return False;
3456 return True;
3459 /*******************************************************************
3460 * init a structure.
3461 ********************************************************************/
3462 BOOL make_spoolss_q_enumprinterdrivers(SPOOL_Q_ENUMPRINTERDRIVERS *q_u,
3463 const char *name,
3464 const char *environment,
3465 uint32 level,
3466 NEW_BUFFER *buffer, uint32 offered)
3468 init_buf_unistr2(&q_u->name, &q_u->name_ptr, name);
3469 init_buf_unistr2(&q_u->environment, &q_u->environment_ptr, environment);
3471 q_u->level=level;
3472 q_u->buffer=buffer;
3473 q_u->offered=offered;
3475 return True;
3478 /*******************************************************************
3479 Parse a SPOOL_Q_ENUMPRINTERDRIVERS structure.
3480 ********************************************************************/
3481 BOOL spoolss_io_q_enumprinterdrivers(char *desc, SPOOL_Q_ENUMPRINTERDRIVERS *q_u, prs_struct *ps, int depth)
3484 prs_debug(ps, depth, desc, "spoolss_io_q_enumprinterdrivers");
3485 depth++;
3487 if (!prs_align(ps))
3488 return False;
3490 if (!prs_uint32("name_ptr", ps, depth, &q_u->name_ptr))
3491 return False;
3492 if (!smb_io_unistr2("", &q_u->name, q_u->name_ptr,ps, depth))
3493 return False;
3495 if (!prs_align(ps))
3496 return False;
3497 if (!prs_uint32("environment_ptr", ps, depth, &q_u->environment_ptr))
3498 return False;
3499 if (!smb_io_unistr2("", &q_u->environment, q_u->environment_ptr, ps, depth))
3500 return False;
3502 if (!prs_align(ps))
3503 return False;
3504 if (!prs_uint32("level", ps, depth, &q_u->level))
3505 return False;
3507 if (!new_spoolss_io_buffer("", ps, depth, q_u->buffer))
3508 return False;
3510 if (!prs_align(ps))
3511 return False;
3513 if (!prs_uint32("offered", ps, depth, &q_u->offered))
3514 return False;
3516 return True;
3519 /*******************************************************************
3520 ********************************************************************/
3521 BOOL spoolss_io_q_enumforms(char *desc, SPOOL_Q_ENUMFORMS *q_u, prs_struct *ps, int depth)
3524 prs_debug(ps, depth, desc, "spoolss_io_q_enumforms");
3525 depth++;
3527 if (!prs_align(ps))
3528 return False;
3529 if (!smb_io_pol_hnd("printer handle",&q_u->handle,ps,depth))
3530 return False;
3531 if (!prs_uint32("level", ps, depth, &q_u->level))
3532 return False;
3534 if (!new_spoolss_io_buffer("", ps, depth, q_u->buffer))
3535 return False;
3537 if (!prs_align(ps))
3538 return False;
3539 if (!prs_uint32("offered", ps, depth, &q_u->offered))
3540 return False;
3542 return True;
3545 /*******************************************************************
3546 ********************************************************************/
3547 BOOL new_spoolss_io_r_enumforms(char *desc, SPOOL_R_ENUMFORMS *r_u, prs_struct *ps, int depth)
3549 prs_debug(ps, depth, desc, "new_spoolss_io_r_enumforms");
3550 depth++;
3552 if (!prs_align(ps))
3553 return False;
3555 if (!new_spoolss_io_buffer("", ps, depth, r_u->buffer))
3556 return False;
3558 if (!prs_align(ps))
3559 return False;
3561 if (!prs_uint32("size of buffer needed", ps, depth, &r_u->needed))
3562 return False;
3564 if (!prs_uint32("numofforms", ps, depth, &r_u->numofforms))
3565 return False;
3567 if (!prs_uint32("status", ps, depth, &r_u->status))
3568 return False;
3570 return True;
3574 /*******************************************************************
3575 Parse a SPOOL_R_ENUMPORTS structure.
3576 ********************************************************************/
3577 BOOL new_spoolss_io_r_enumports(char *desc, SPOOL_R_ENUMPORTS *r_u, prs_struct *ps, int depth)
3579 prs_debug(ps, depth, desc, "new_spoolss_io_r_enumports");
3580 depth++;
3582 if (!prs_align(ps))
3583 return False;
3585 if (!new_spoolss_io_buffer("", ps, depth, r_u->buffer))
3586 return False;
3588 if (!prs_align(ps))
3589 return False;
3591 if (!prs_uint32("needed", ps, depth, &r_u->needed))
3592 return False;
3594 if (!prs_uint32("returned", ps, depth, &r_u->returned))
3595 return False;
3597 if (!prs_uint32("status", ps, depth, &r_u->status))
3598 return False;
3600 return True;
3603 /*******************************************************************
3604 ********************************************************************/
3605 BOOL spoolss_io_q_enumports(char *desc, SPOOL_Q_ENUMPORTS *q_u, prs_struct *ps, int depth)
3607 prs_debug(ps, depth, desc, "");
3608 depth++;
3610 if (!prs_align(ps))
3611 return False;
3613 if (!prs_uint32("", ps, depth, &q_u->name_ptr))
3614 return False;
3615 if (!smb_io_unistr2("", &q_u->name,True,ps,depth))
3616 return False;
3618 if (!prs_align(ps))
3619 return False;
3620 if (!prs_uint32("level", ps, depth, &q_u->level))
3621 return False;
3623 if (!new_spoolss_io_buffer("", ps, depth, q_u->buffer))
3624 return False;
3626 if (!prs_align(ps))
3627 return False;
3628 if (!prs_uint32("offered", ps, depth, &q_u->offered))
3629 return False;
3631 return True;
3634 /*******************************************************************
3635 Parse a SPOOL_PRINTER_INFO_LEVEL_1 structure.
3636 ********************************************************************/
3637 BOOL spool_io_printer_info_level_1(char *desc, SPOOL_PRINTER_INFO_LEVEL_1 *il, prs_struct *ps, int depth)
3639 prs_debug(ps, depth, desc, "spool_io_printer_info_level_1");
3640 depth++;
3642 if(!prs_align(ps))
3643 return False;
3645 if(!prs_uint32("flags", ps, depth, &il->flags))
3646 return False;
3647 if(!prs_uint32("description_ptr", ps, depth, &il->description_ptr))
3648 return False;
3649 if(!prs_uint32("name_ptr", ps, depth, &il->name_ptr))
3650 return False;
3651 if(!prs_uint32("comment_ptr", ps, depth, &il->comment_ptr))
3652 return False;
3654 if(!smb_io_unistr2("description", &il->description, il->description_ptr, ps, depth))
3655 return False;
3656 if(!smb_io_unistr2("name", &il->name, il->name_ptr, ps, depth))
3657 return False;
3658 if(!smb_io_unistr2("comment", &il->comment, il->comment_ptr, ps, depth))
3659 return False;
3661 return True;
3664 /*******************************************************************
3665 Parse a SPOOL_PRINTER_INFO_LEVEL_3 structure.
3666 ********************************************************************/
3667 BOOL spool_io_printer_info_level_3(char *desc, SPOOL_PRINTER_INFO_LEVEL_3 *il, prs_struct *ps, int depth)
3669 prs_debug(ps, depth, desc, "spool_io_printer_info_level_3");
3670 depth++;
3672 if(!prs_align(ps))
3673 return False;
3675 if(!prs_uint32("secdesc_ptr", ps, depth, &il->secdesc_ptr))
3676 return False;
3678 return True;
3681 /*******************************************************************
3682 Parse a SPOOL_PRINTER_INFO_LEVEL_2 structure.
3683 ********************************************************************/
3684 BOOL spool_io_printer_info_level_2(char *desc, SPOOL_PRINTER_INFO_LEVEL_2 *il, prs_struct *ps, int depth)
3686 prs_debug(ps, depth, desc, "spool_io_printer_info_level_2");
3687 depth++;
3689 if(!prs_align(ps))
3690 return False;
3692 if(!prs_uint32("servername_ptr", ps, depth, &il->servername_ptr))
3693 return False;
3694 if(!prs_uint32("printername_ptr", ps, depth, &il->printername_ptr))
3695 return False;
3696 if(!prs_uint32("sharename_ptr", ps, depth, &il->sharename_ptr))
3697 return False;
3698 if(!prs_uint32("portname_ptr", ps, depth, &il->portname_ptr))
3699 return False;
3701 if(!prs_uint32("drivername_ptr", ps, depth, &il->drivername_ptr))
3702 return False;
3703 if(!prs_uint32("comment_ptr", ps, depth, &il->comment_ptr))
3704 return False;
3705 if(!prs_uint32("location_ptr", ps, depth, &il->location_ptr))
3706 return False;
3707 if(!prs_uint32("devmode_ptr", ps, depth, &il->devmode_ptr))
3708 return False;
3709 if(!prs_uint32("sepfile_ptr", ps, depth, &il->sepfile_ptr))
3710 return False;
3711 if(!prs_uint32("printprocessor_ptr", ps, depth, &il->printprocessor_ptr))
3712 return False;
3713 if(!prs_uint32("datatype_ptr", ps, depth, &il->datatype_ptr))
3714 return False;
3715 if(!prs_uint32("parameters_ptr", ps, depth, &il->parameters_ptr))
3716 return False;
3717 if(!prs_uint32("secdesc_ptr", ps, depth, &il->secdesc_ptr))
3718 return False;
3720 if(!prs_uint32("attributes", ps, depth, &il->attributes))
3721 return False;
3722 if(!prs_uint32("priority", ps, depth, &il->priority))
3723 return False;
3724 if(!prs_uint32("default_priority", ps, depth, &il->default_priority))
3725 return False;
3726 if(!prs_uint32("starttime", ps, depth, &il->starttime))
3727 return False;
3728 if(!prs_uint32("untiltime", ps, depth, &il->untiltime))
3729 return False;
3730 if(!prs_uint32("status", ps, depth, &il->status))
3731 return False;
3732 if(!prs_uint32("cjobs", ps, depth, &il->cjobs))
3733 return False;
3734 if(!prs_uint32("averageppm", ps, depth, &il->averageppm))
3735 return False;
3737 if(!smb_io_unistr2("servername", &il->servername, il->servername_ptr, ps, depth))
3738 return False;
3739 if(!smb_io_unistr2("printername", &il->printername, il->printername_ptr, ps, depth))
3740 return False;
3741 if(!smb_io_unistr2("sharename", &il->sharename, il->sharename_ptr, ps, depth))
3742 return False;
3743 if(!smb_io_unistr2("portname", &il->portname, il->portname_ptr, ps, depth))
3744 return False;
3745 if(!smb_io_unistr2("drivername", &il->drivername, il->drivername_ptr, ps, depth))
3746 return False;
3747 if(!smb_io_unistr2("comment", &il->comment, il->comment_ptr, ps, depth))
3748 return False;
3749 if(!smb_io_unistr2("location", &il->location, il->location_ptr, ps, depth))
3750 return False;
3751 if(!smb_io_unistr2("sepfile", &il->sepfile, il->sepfile_ptr, ps, depth))
3752 return False;
3753 if(!smb_io_unistr2("printprocessor", &il->printprocessor, il->printprocessor_ptr, ps, depth))
3754 return False;
3755 if(!smb_io_unistr2("datatype", &il->datatype, il->datatype_ptr, ps, depth))
3756 return False;
3757 if(!smb_io_unistr2("parameters", &il->parameters, il->parameters_ptr, ps, depth))
3758 return False;
3760 return True;
3763 /*******************************************************************
3764 ********************************************************************/
3765 BOOL spool_io_printer_info_level(char *desc, SPOOL_PRINTER_INFO_LEVEL *il, prs_struct *ps, int depth)
3767 prs_debug(ps, depth, desc, "spool_io_printer_info_level");
3768 depth++;
3770 if(!prs_align(ps))
3771 return False;
3772 if(!prs_uint32("level", ps, depth, &il->level))
3773 return False;
3774 if(!prs_uint32("info_ptr", ps, depth, &il->info_ptr))
3775 return False;
3777 /* if no struct inside just return */
3778 if (il->info_ptr==0) {
3779 if (UNMARSHALLING(ps)) {
3780 il->info_1=NULL;
3781 il->info_2=NULL;
3783 return True;
3786 switch (il->level) {
3788 * level 0 is used by setprinter when managing the queue
3789 * (hold, stop, start a queue)
3791 case 0:
3792 break;
3793 /* DOCUMENT ME!!! What is level 1 used for? */
3794 case 1:
3796 if (UNMARSHALLING(ps)) {
3797 if ((il->info_1=(SPOOL_PRINTER_INFO_LEVEL_1 *)malloc(sizeof(SPOOL_PRINTER_INFO_LEVEL_1))) == NULL)
3798 return False;
3799 ZERO_STRUCTP(il->info_1);
3801 if (!spool_io_printer_info_level_1("", il->info_1, ps, depth)) {
3802 if (UNMARSHALLING(ps))
3803 safe_free(il->info_1);
3804 return False;
3806 break;
3809 * level 2 is used by addprinter
3810 * and by setprinter when updating printer's info
3812 case 2:
3813 if (UNMARSHALLING(ps)) {
3814 if ((il->info_2=(SPOOL_PRINTER_INFO_LEVEL_2 *)malloc(sizeof(SPOOL_PRINTER_INFO_LEVEL_2))) == NULL)
3815 return False;
3816 ZERO_STRUCTP(il->info_2);
3818 if (!spool_io_printer_info_level_2("", il->info_2, ps, depth)) {
3819 if (UNMARSHALLING(ps))
3820 safe_free(il->info_2);
3821 return False;
3823 break;
3824 /* DOCUMENT ME!!! What is level 3 used for? */
3825 case 3:
3827 if (UNMARSHALLING(ps)) {
3828 if ((il->info_3=(SPOOL_PRINTER_INFO_LEVEL_3 *)malloc(sizeof(SPOOL_PRINTER_INFO_LEVEL_3))) == NULL)
3829 return False;
3830 ZERO_STRUCTP(il->info_3);
3832 if (!spool_io_printer_info_level_3("", il->info_3, ps, depth)) {
3833 if (UNMARSHALLING(ps))
3834 safe_free(il->info_3);
3835 return False;
3837 break;
3841 return True;
3844 /*******************************************************************
3845 ********************************************************************/
3846 BOOL spoolss_io_q_addprinterex(char *desc, SPOOL_Q_ADDPRINTEREX *q_u, prs_struct *ps, int depth)
3848 prs_debug(ps, depth, desc, "spoolss_io_q_addprinterex");
3849 depth++;
3851 if(!prs_align(ps))
3852 return False;
3853 if(!prs_uint32("", ps, depth, &q_u->server_name_ptr))
3854 return False;
3855 if(!smb_io_unistr2("", &q_u->server_name, q_u->server_name_ptr, ps, depth))
3856 return False;
3858 if(!prs_align(ps))
3859 return False;
3861 if(!prs_uint32("info_level", ps, depth, &q_u->level))
3862 return False;
3864 if(!spool_io_printer_info_level("", &q_u->info, ps, depth))
3865 return False;
3867 /* the 4 unknown are all 0 */
3870 * en fait ils sont pas inconnu
3871 * par recoupement avec rpcSetPrinter
3872 * c'est le devicemode
3873 * et le security descriptor.
3876 if(!prs_align(ps))
3877 return False;
3878 if(!prs_uint32("unk0", ps, depth, &q_u->unk0))
3879 return False;
3880 if(!prs_uint32("unk1", ps, depth, &q_u->unk1))
3881 return False;
3882 if(!prs_uint32("unk2", ps, depth, &q_u->unk2))
3883 return False;
3884 if(!prs_uint32("unk3", ps, depth, &q_u->unk3))
3885 return False;
3887 if(!prs_uint32("user_switch", ps, depth, &q_u->user_switch))
3888 return False;
3889 if(!spool_io_user_level("", &q_u->user_ctr, ps, depth))
3890 return False;
3892 return True;
3895 /*******************************************************************
3896 ********************************************************************/
3897 BOOL spoolss_io_r_addprinterex(char *desc, SPOOL_R_ADDPRINTEREX *r_u,
3898 prs_struct *ps, int depth)
3900 prs_debug(ps, depth, desc, "spoolss_io_r_addprinterex");
3901 depth++;
3903 if(!smb_io_pol_hnd("printer handle",&r_u->handle,ps,depth))
3904 return False;
3906 if(!prs_uint32("status", ps, depth, &r_u->status))
3907 return False;
3909 return True;
3912 /*******************************************************************
3913 ********************************************************************/
3914 BOOL spool_io_printer_driver_info_level_3(char *desc, SPOOL_PRINTER_DRIVER_INFO_LEVEL_3 **q_u,
3915 prs_struct *ps, int depth)
3917 SPOOL_PRINTER_DRIVER_INFO_LEVEL_3 *il;
3919 prs_debug(ps, depth, desc, "spool_io_printer_driver_info_level_3");
3920 depth++;
3922 /* reading */
3923 if (UNMARSHALLING(ps)) {
3924 il=(SPOOL_PRINTER_DRIVER_INFO_LEVEL_3 *)malloc(sizeof(SPOOL_PRINTER_DRIVER_INFO_LEVEL_3));
3925 if(il == NULL)
3926 return False;
3927 ZERO_STRUCTP(il);
3928 *q_u=il;
3930 else {
3931 il=*q_u;
3934 if(!prs_align(ps))
3935 return False;
3937 if(!prs_uint32("cversion", ps, depth, &il->cversion))
3938 return False;
3939 if(!prs_uint32("name", ps, depth, &il->name_ptr))
3940 return False;
3941 if(!prs_uint32("environment", ps, depth, &il->environment_ptr))
3942 return False;
3943 if(!prs_uint32("driverpath", ps, depth, &il->driverpath_ptr))
3944 return False;
3945 if(!prs_uint32("datafile", ps, depth, &il->datafile_ptr))
3946 return False;
3947 if(!prs_uint32("configfile", ps, depth, &il->configfile_ptr))
3948 return False;
3949 if(!prs_uint32("helpfile", ps, depth, &il->helpfile_ptr))
3950 return False;
3951 if(!prs_uint32("monitorname", ps, depth, &il->monitorname_ptr))
3952 return False;
3953 if(!prs_uint32("defaultdatatype", ps, depth, &il->defaultdatatype_ptr))
3954 return False;
3955 if(!prs_uint32("dependentfilessize", ps, depth, &il->dependentfilessize))
3956 return False;
3957 if(!prs_uint32("dependentfiles", ps, depth, &il->dependentfiles_ptr))
3958 return False;
3960 if(!prs_align(ps))
3961 return False;
3963 if(!smb_io_unistr2("name", &il->name, il->name_ptr, ps, depth))
3964 return False;
3965 if(!smb_io_unistr2("environment", &il->environment, il->environment_ptr, ps, depth))
3966 return False;
3967 if(!smb_io_unistr2("driverpath", &il->driverpath, il->driverpath_ptr, ps, depth))
3968 return False;
3969 if(!smb_io_unistr2("datafile", &il->datafile, il->datafile_ptr, ps, depth))
3970 return False;
3971 if(!smb_io_unistr2("configfile", &il->configfile, il->configfile_ptr, ps, depth))
3972 return False;
3973 if(!smb_io_unistr2("helpfile", &il->helpfile, il->helpfile_ptr, ps, depth))
3974 return False;
3975 if(!smb_io_unistr2("monitorname", &il->monitorname, il->monitorname_ptr, ps, depth))
3976 return False;
3977 if(!smb_io_unistr2("defaultdatatype", &il->defaultdatatype, il->defaultdatatype_ptr, ps, depth))
3978 return False;
3980 if(!prs_align(ps))
3981 return False;
3983 if (il->dependentfiles_ptr)
3984 smb_io_buffer5("", &il->dependentfiles, ps, depth);
3986 return True;
3989 void free_spool_printer_driver_info_level_3(SPOOL_PRINTER_DRIVER_INFO_LEVEL_3 **q_u)
3991 SPOOL_PRINTER_DRIVER_INFO_LEVEL_3 *il = *q_u;
3993 if (il == NULL)
3994 return;
3996 safe_free(il);
3999 /*******************************************************************
4000 parse a SPOOL_PRINTER_DRIVER_INFO_LEVEL_6 structure
4001 ********************************************************************/
4002 BOOL spool_io_printer_driver_info_level_6(char *desc, SPOOL_PRINTER_DRIVER_INFO_LEVEL_6 **q_u,
4003 prs_struct *ps, int depth)
4005 SPOOL_PRINTER_DRIVER_INFO_LEVEL_6 *il;
4007 prs_debug(ps, depth, desc, "spool_io_printer_driver_info_level_6");
4008 depth++;
4010 /* reading */
4011 if (UNMARSHALLING(ps)) {
4012 il=(SPOOL_PRINTER_DRIVER_INFO_LEVEL_6 *)malloc(sizeof(SPOOL_PRINTER_DRIVER_INFO_LEVEL_6));
4013 if(il == NULL)
4014 return False;
4015 ZERO_STRUCTP(il);
4016 *q_u=il;
4018 else {
4019 il=*q_u;
4022 if(!prs_align(ps))
4023 return False;
4026 /* parse the main elements the packet */
4028 if(!prs_uint32("version", ps, depth, &il->version))
4029 return False;
4030 if(!prs_uint32("name_ptr", ps, depth, &il->name_ptr))
4031 return False;
4032 if(!prs_uint32("environment_ptr", ps, depth, &il->environment_ptr))
4033 return False;
4034 if(!prs_uint32("driverpath_ptr", ps, depth, &il->driverpath_ptr))
4035 return False;
4036 if(!prs_uint32("datafile_ptr", ps, depth, &il->datafile_ptr))
4037 return False;
4038 if(!prs_uint32("configfile_ptr", ps, depth, &il->configfile_ptr))
4039 return False;
4040 if(!prs_uint32("helpfile_ptr", ps, depth, &il->helpfile_ptr))
4041 return False;
4042 if(!prs_uint32("monitorname_ptr", ps, depth, &il->monitorname_ptr))
4043 return False;
4044 if(!prs_uint32("defaultdatatype_ptr", ps, depth, &il->defaultdatatype_ptr))
4045 return False;
4046 if(!prs_uint32("dependentfiles_len", ps, depth, &il->dependentfiles_len))
4047 return False;
4048 if(!prs_uint32("dependentfiles_ptr", ps, depth, &il->dependentfiles_ptr))
4049 return False;
4050 if(!prs_uint32("previousnames_len", ps, depth, &il->previousnames_len))
4051 return False;
4052 if(!prs_uint32("previousnames_ptr", ps, depth, &il->previousnames_ptr))
4053 return False;
4054 if(!smb_io_time("driverdate", &il->driverdate, ps, depth))
4055 return False;
4056 if(!prs_uint32("dummy4", ps, depth, &il->dummy4))
4057 return False;
4058 if(!prs_uint64("driverversion", ps, depth, &il->driverversion))
4059 return False;
4060 if(!prs_uint32("mfgname_ptr", ps, depth, &il->mfgname_ptr))
4061 return False;
4062 if(!prs_uint32("oemurl_ptr", ps, depth, &il->oemurl_ptr))
4063 return False;
4064 if(!prs_uint32("hardwareid_ptr", ps, depth, &il->hardwareid_ptr))
4065 return False;
4066 if(!prs_uint32("provider_ptr", ps, depth, &il->provider_ptr))
4067 return False;
4069 /* parse the structures in the packet */
4071 if(!smb_io_unistr2("name", &il->name, il->name_ptr, ps, depth))
4072 return False;
4073 if(!prs_align(ps))
4074 return False;
4075 if(!smb_io_unistr2("environment", &il->environment, il->environment_ptr, ps, depth))
4076 return False;
4077 if(!prs_align(ps))
4078 return False;
4079 if(!smb_io_unistr2("driverpath", &il->driverpath, il->driverpath_ptr, ps, depth))
4080 return False;
4081 if(!prs_align(ps))
4082 return False;
4083 if(!smb_io_unistr2("datafile", &il->datafile, il->datafile_ptr, ps, depth))
4084 return False;
4085 if(!prs_align(ps))
4086 return False;
4087 if(!smb_io_unistr2("configfile", &il->configfile, il->configfile_ptr, ps, depth))
4088 return False;
4089 if(!prs_align(ps))
4090 return False;
4091 if(!smb_io_unistr2("helpfile", &il->helpfile, il->helpfile_ptr, ps, depth))
4092 return False;
4093 if(!prs_align(ps))
4094 return False;
4095 if(!smb_io_unistr2("monitorname", &il->monitorname, il->monitorname_ptr, ps, depth))
4096 return False;
4097 if(!prs_align(ps))
4098 return False;
4099 if(!smb_io_unistr2("defaultdatatype", &il->defaultdatatype, il->defaultdatatype_ptr, ps, depth))
4100 return False;
4101 if(!prs_align(ps))
4102 return False;
4103 if (il->dependentfiles_ptr) {
4104 if(!smb_io_buffer5("dependentfiles", &il->dependentfiles, ps, depth))
4105 return False;
4106 if(!prs_align(ps))
4107 return False;
4109 if (il->previousnames_ptr) {
4110 if(!smb_io_buffer5("previousnames", &il->previousnames, ps, depth))
4111 return False;
4112 if(!prs_align(ps))
4113 return False;
4115 if(!smb_io_unistr2("mfgname", &il->mfgname, il->mfgname_ptr, ps, depth))
4116 return False;
4117 if(!prs_align(ps))
4118 return False;
4119 if(!smb_io_unistr2("oemurl", &il->oemurl, il->oemurl_ptr, ps, depth))
4120 return False;
4121 if(!prs_align(ps))
4122 return False;
4123 if(!smb_io_unistr2("hardwareid", &il->hardwareid, il->hardwareid_ptr, ps, depth))
4124 return False;
4125 if(!prs_align(ps))
4126 return False;
4127 if(!smb_io_unistr2("provider", &il->provider, il->provider_ptr, ps, depth))
4128 return False;
4130 return True;
4133 void free_spool_printer_driver_info_level_6(SPOOL_PRINTER_DRIVER_INFO_LEVEL_6 **q_u)
4135 SPOOL_PRINTER_DRIVER_INFO_LEVEL_6 *il = *q_u;
4137 if (il == NULL)
4138 return;
4140 safe_free(il);
4144 /*******************************************************************
4145 convert a buffer of UNICODE strings null terminated
4146 the buffer is terminated by a NULL
4148 convert to an dos codepage array (null terminated)
4150 dynamically allocate memory
4152 ********************************************************************/
4153 static BOOL uniarray_2_dosarray(BUFFER5 *buf5, fstring **ar)
4155 fstring f;
4156 int n = 0;
4157 char *src;
4159 if (buf5==NULL) return False;
4161 src = (char *)buf5->buffer;
4162 *ar = NULL;
4164 while (src < ((char *)buf5->buffer) + buf5->buf_len*2) {
4165 unistr_to_dos(f, src, sizeof(f)-1);
4166 src = skip_unibuf(src, 2*buf5->buf_len - PTR_DIFF(src,buf5->buffer));
4167 *ar = (fstring *)Realloc(*ar, sizeof(fstring)*(n+2));
4168 fstrcpy((*ar)[n], f);
4169 n++;
4171 fstrcpy((*ar)[n], "");
4173 return True;
4176 /*******************************************************************
4177 read a UNICODE array with null terminated strings
4178 and null terminated array
4179 and size of array at beginning
4180 ********************************************************************/
4181 BOOL smb_io_unibuffer(char *desc, UNISTR2 *buffer, prs_struct *ps, int depth)
4183 if (buffer==NULL) return False;
4185 buffer->undoc=0;
4186 buffer->uni_str_len=buffer->uni_max_len;
4188 if(!prs_uint32("buffer_size", ps, depth, &buffer->uni_max_len))
4189 return False;
4191 if(!prs_unistr2(True, "buffer ", ps, depth, buffer))
4192 return False;
4194 return True;
4197 /*******************************************************************
4198 ********************************************************************/
4199 BOOL spool_io_printer_driver_info_level(char *desc, SPOOL_PRINTER_DRIVER_INFO_LEVEL *il, prs_struct *ps, int depth)
4201 prs_debug(ps, depth, desc, "spool_io_printer_driver_info_level");
4202 depth++;
4204 if(!prs_align(ps))
4205 return False;
4206 if(!prs_uint32("level", ps, depth, &il->level))
4207 return False;
4208 if(!prs_uint32("ptr", ps, depth, &il->ptr))
4209 return False;
4211 if (il->ptr==0)
4212 return True;
4214 switch (il->level) {
4215 case 3:
4216 if(!spool_io_printer_driver_info_level_3("", &il->info_3, ps, depth))
4217 return False;
4218 break;
4219 case 6:
4220 if(!spool_io_printer_driver_info_level_6("", &il->info_6, ps, depth))
4221 return False;
4222 break;
4223 default:
4224 return False;
4227 return True;
4230 void free_spool_printer_driver_info_level(SPOOL_PRINTER_DRIVER_INFO_LEVEL *il)
4232 if (il->ptr==0)
4233 return;
4235 switch (il->level) {
4236 case 3:
4237 free_spool_printer_driver_info_level_3(&il->info_3);
4238 break;
4239 case 6:
4240 free_spool_printer_driver_info_level_6(&il->info_6);
4241 break;
4245 /*******************************************************************
4246 ********************************************************************/
4247 BOOL spoolss_io_q_addprinterdriver(char *desc, SPOOL_Q_ADDPRINTERDRIVER *q_u, prs_struct *ps, int depth)
4249 prs_debug(ps, depth, desc, "spoolss_io_q_addprinterdriver");
4250 depth++;
4252 if(!prs_align(ps))
4253 return False;
4255 if(!prs_uint32("server_name_ptr", ps, depth, &q_u->server_name_ptr))
4256 return False;
4257 if(!smb_io_unistr2("server_name", &q_u->server_name, q_u->server_name_ptr, ps, depth))
4258 return False;
4260 if(!prs_align(ps))
4261 return False;
4262 if(!prs_uint32("info_level", ps, depth, &q_u->level))
4263 return False;
4265 if(!spool_io_printer_driver_info_level("", &q_u->info, ps, depth))
4266 return False;
4268 return True;
4271 /*******************************************************************
4272 Free the dynamic parts of a printer driver.
4273 ********************************************************************/
4275 void free_spoolss_q_addprinterdriver(SPOOL_Q_ADDPRINTERDRIVER *q_u)
4277 free_spool_printer_driver_info_level(&q_u->info);
4280 /*******************************************************************
4281 ********************************************************************/
4282 BOOL spoolss_io_r_addprinterdriver(char *desc, SPOOL_R_ADDPRINTERDRIVER *q_u, prs_struct *ps, int depth)
4284 prs_debug(ps, depth, desc, "spoolss_io_r_addprinterdriver");
4285 depth++;
4287 if(!prs_uint32("status", ps, depth, &q_u->status))
4288 return False;
4290 return True;
4294 /*******************************************************************
4295 ********************************************************************/
4296 BOOL uni_2_asc_printer_driver_3(SPOOL_PRINTER_DRIVER_INFO_LEVEL_3 *uni,
4297 NT_PRINTER_DRIVER_INFO_LEVEL_3 **asc)
4299 NT_PRINTER_DRIVER_INFO_LEVEL_3 *d;
4301 DEBUG(7,("uni_2_asc_printer_driver_3: Converting from UNICODE to ASCII\n"));
4303 if (*asc==NULL)
4305 *asc=(NT_PRINTER_DRIVER_INFO_LEVEL_3 *)malloc(sizeof(NT_PRINTER_DRIVER_INFO_LEVEL_3));
4306 if(*asc == NULL)
4307 return False;
4308 ZERO_STRUCTP(*asc);
4311 d=*asc;
4313 d->cversion=uni->cversion;
4315 unistr2_to_ascii(d->name, &uni->name, sizeof(d->name)-1);
4316 unistr2_to_ascii(d->environment, &uni->environment, sizeof(d->environment)-1);
4317 unistr2_to_ascii(d->driverpath, &uni->driverpath, sizeof(d->driverpath)-1);
4318 unistr2_to_ascii(d->datafile, &uni->datafile, sizeof(d->datafile)-1);
4319 unistr2_to_ascii(d->configfile, &uni->configfile, sizeof(d->configfile)-1);
4320 unistr2_to_ascii(d->helpfile, &uni->helpfile, sizeof(d->helpfile)-1);
4321 unistr2_to_ascii(d->monitorname, &uni->monitorname, sizeof(d->monitorname)-1);
4322 unistr2_to_ascii(d->defaultdatatype, &uni->defaultdatatype, sizeof(d->defaultdatatype)-1);
4324 DEBUGADD(8,( "version: %d\n", d->cversion));
4325 DEBUGADD(8,( "name: %s\n", d->name));
4326 DEBUGADD(8,( "environment: %s\n", d->environment));
4327 DEBUGADD(8,( "driverpath: %s\n", d->driverpath));
4328 DEBUGADD(8,( "datafile: %s\n", d->datafile));
4329 DEBUGADD(8,( "configfile: %s\n", d->configfile));
4330 DEBUGADD(8,( "helpfile: %s\n", d->helpfile));
4331 DEBUGADD(8,( "monitorname: %s\n", d->monitorname));
4332 DEBUGADD(8,( "defaultdatatype: %s\n", d->defaultdatatype));
4334 uniarray_2_dosarray(&(uni->dependentfiles), &(d->dependentfiles) );
4336 return True;
4339 /*******************************************************************
4340 ********************************************************************/
4341 BOOL uni_2_asc_printer_driver_6(SPOOL_PRINTER_DRIVER_INFO_LEVEL_6 *uni,
4342 NT_PRINTER_DRIVER_INFO_LEVEL_6 **asc)
4344 NT_PRINTER_DRIVER_INFO_LEVEL_6 *d;
4346 DEBUG(7,("uni_2_asc_printer_driver_6: Converting from UNICODE to ASCII\n"));
4348 if (*asc==NULL)
4350 *asc=(NT_PRINTER_DRIVER_INFO_LEVEL_6 *)malloc(sizeof(NT_PRINTER_DRIVER_INFO_LEVEL_6));
4351 if(*asc == NULL)
4352 return False;
4353 ZERO_STRUCTP(*asc);
4356 d=*asc;
4358 d->version=uni->version;
4360 unistr2_to_ascii(d->name, &uni->name, sizeof(d->name)-1);
4361 unistr2_to_ascii(d->environment, &uni->environment, sizeof(d->environment)-1);
4362 unistr2_to_ascii(d->driverpath, &uni->driverpath, sizeof(d->driverpath)-1);
4363 unistr2_to_ascii(d->datafile, &uni->datafile, sizeof(d->datafile)-1);
4364 unistr2_to_ascii(d->configfile, &uni->configfile, sizeof(d->configfile)-1);
4365 unistr2_to_ascii(d->helpfile, &uni->helpfile, sizeof(d->helpfile)-1);
4366 unistr2_to_ascii(d->monitorname, &uni->monitorname, sizeof(d->monitorname)-1);
4367 unistr2_to_ascii(d->defaultdatatype, &uni->defaultdatatype, sizeof(d->defaultdatatype)-1);
4369 DEBUGADD(8,( "version: %d\n", d->version));
4370 DEBUGADD(8,( "name: %s\n", d->name));
4371 DEBUGADD(8,( "environment: %s\n", d->environment));
4372 DEBUGADD(8,( "driverpath: %s\n", d->driverpath));
4373 DEBUGADD(8,( "datafile: %s\n", d->datafile));
4374 DEBUGADD(8,( "configfile: %s\n", d->configfile));
4375 DEBUGADD(8,( "helpfile: %s\n", d->helpfile));
4376 DEBUGADD(8,( "monitorname: %s\n", d->monitorname));
4377 DEBUGADD(8,( "defaultdatatype: %s\n", d->defaultdatatype));
4379 uniarray_2_dosarray(&uni->dependentfiles, &d->dependentfiles );
4380 uniarray_2_dosarray(&uni->previousnames, &d->previousnames );
4382 return True;
4385 BOOL uni_2_asc_printer_info_2(const SPOOL_PRINTER_INFO_LEVEL_2 *uni,
4386 NT_PRINTER_INFO_LEVEL_2 **asc)
4388 NT_PRINTER_INFO_LEVEL_2 *d;
4389 time_t time_unix;
4391 DEBUG(7,("Converting from UNICODE to ASCII\n"));
4392 time_unix=time(NULL);
4394 if (*asc==NULL) {
4395 DEBUGADD(8,("allocating memory\n"));
4397 *asc=(NT_PRINTER_INFO_LEVEL_2 *)malloc(sizeof(NT_PRINTER_INFO_LEVEL_2));
4398 if(*asc == NULL)
4399 return False;
4400 ZERO_STRUCTP(*asc);
4402 /* we allocate memory iff called from
4403 * addprinter(ex) so we can do one time stuff here.
4405 (*asc)->setuptime=time_unix;
4408 DEBUGADD(8,("start converting\n"));
4410 d=*asc;
4412 d->attributes=uni->attributes;
4413 d->priority=uni->priority;
4414 d->default_priority=uni->default_priority;
4415 d->starttime=uni->starttime;
4416 d->untiltime=uni->untiltime;
4417 d->status=uni->status;
4418 d->cjobs=uni->cjobs;
4420 unistr2_to_ascii(d->servername, &uni->servername, sizeof(d->servername)-1);
4421 unistr2_to_ascii(d->printername, &uni->printername, sizeof(d->printername)-1);
4422 unistr2_to_ascii(d->sharename, &uni->sharename, sizeof(d->sharename)-1);
4423 unistr2_to_ascii(d->portname, &uni->portname, sizeof(d->portname)-1);
4424 unistr2_to_ascii(d->drivername, &uni->drivername, sizeof(d->drivername)-1);
4425 unistr2_to_ascii(d->comment, &uni->comment, sizeof(d->comment)-1);
4426 unistr2_to_ascii(d->location, &uni->location, sizeof(d->location)-1);
4427 unistr2_to_ascii(d->sepfile, &uni->sepfile, sizeof(d->sepfile)-1);
4428 unistr2_to_ascii(d->printprocessor, &uni->printprocessor, sizeof(d->printprocessor)-1);
4429 unistr2_to_ascii(d->datatype, &uni->datatype, sizeof(d->datatype)-1);
4430 unistr2_to_ascii(d->parameters, &uni->parameters, sizeof(d->parameters)-1);
4432 return True;
4435 /*******************************************************************
4436 * init a structure.
4437 ********************************************************************/
4438 BOOL make_spoolss_q_getprinterdriverdir(SPOOL_Q_GETPRINTERDRIVERDIR *q_u,
4439 fstring servername, fstring env_name, uint32 level,
4440 NEW_BUFFER *buffer, uint32 offered)
4442 init_buf_unistr2(&q_u->name, &q_u->name_ptr, servername);
4443 init_buf_unistr2(&q_u->environment, &q_u->environment_ptr, env_name);
4445 q_u->level=level;
4446 q_u->buffer=buffer;
4447 q_u->offered=offered;
4449 return True;
4453 /*******************************************************************
4454 Parse a SPOOL_Q_GETPRINTERDRIVERDIR structure.
4455 ********************************************************************/
4456 BOOL spoolss_io_q_getprinterdriverdir(char *desc, SPOOL_Q_GETPRINTERDRIVERDIR *q_u, prs_struct *ps, int depth)
4458 prs_debug(ps, depth, desc, "spoolss_io_q_getprinterdriverdir");
4459 depth++;
4461 if(!prs_align(ps))
4462 return False;
4463 if(!prs_uint32("name_ptr", ps, depth, &q_u->name_ptr))
4464 return False;
4465 if(!smb_io_unistr2("", &q_u->name, q_u->name_ptr, ps, depth))
4466 return False;
4468 if(!prs_align(ps))
4469 return False;
4471 if(!prs_uint32("", ps, depth, &q_u->environment_ptr))
4472 return False;
4473 if(!smb_io_unistr2("", &q_u->environment, q_u->environment_ptr, ps, depth))
4474 return False;
4476 if(!prs_align(ps))
4477 return False;
4479 if(!prs_uint32("level", ps, depth, &q_u->level))
4480 return False;
4482 if(!new_spoolss_io_buffer("", ps, depth, q_u->buffer))
4483 return False;
4485 if(!prs_align(ps))
4486 return False;
4488 if(!prs_uint32("offered", ps, depth, &q_u->offered))
4489 return False;
4491 return True;
4494 /*******************************************************************
4495 Parse a SPOOL_R_GETPRINTERDRIVERDIR structure.
4496 ********************************************************************/
4497 BOOL spoolss_io_r_getprinterdriverdir(char *desc, SPOOL_R_GETPRINTERDRIVERDIR *r_u, prs_struct *ps, int depth)
4499 prs_debug(ps, depth, desc, "spoolss_io_r_getprinterdriverdir");
4500 depth++;
4502 if (!prs_align(ps))
4503 return False;
4505 if (!new_spoolss_io_buffer("", ps, depth, r_u->buffer))
4506 return False;
4508 if (!prs_align(ps))
4509 return False;
4511 if (!prs_uint32("needed", ps, depth, &r_u->needed))
4512 return False;
4514 if (!prs_uint32("status", ps, depth, &r_u->status))
4515 return False;
4517 return True;
4520 /*******************************************************************
4521 ********************************************************************/
4522 BOOL spoolss_io_r_enumprintprocessors(char *desc, SPOOL_R_ENUMPRINTPROCESSORS *r_u, prs_struct *ps, int depth)
4524 prs_debug(ps, depth, desc, "spoolss_io_r_enumprintprocessors");
4525 depth++;
4527 if (!prs_align(ps))
4528 return False;
4530 if (!new_spoolss_io_buffer("", ps, depth, r_u->buffer))
4531 return False;
4533 if (!prs_align(ps))
4534 return False;
4536 if (!prs_uint32("needed", ps, depth, &r_u->needed))
4537 return False;
4539 if (!prs_uint32("returned", ps, depth, &r_u->returned))
4540 return False;
4542 if (!prs_uint32("status", ps, depth, &r_u->status))
4543 return False;
4545 return True;
4548 /*******************************************************************
4549 ********************************************************************/
4550 BOOL spoolss_io_q_enumprintprocessors(char *desc, SPOOL_Q_ENUMPRINTPROCESSORS *q_u, prs_struct *ps, int depth)
4552 prs_debug(ps, depth, desc, "spoolss_io_q_enumprintprocessors");
4553 depth++;
4555 if (!prs_align(ps))
4556 return False;
4558 if (!prs_uint32("name_ptr", ps, depth, &q_u->name_ptr))
4559 return False;
4560 if (!smb_io_unistr2("name", &q_u->name, True, ps, depth))
4561 return False;
4563 if (!prs_align(ps))
4564 return False;
4566 if (!prs_uint32("", ps, depth, &q_u->environment_ptr))
4567 return False;
4568 if (!smb_io_unistr2("", &q_u->environment, q_u->environment_ptr, ps, depth))
4569 return False;
4571 if (!prs_align(ps))
4572 return False;
4574 if (!prs_uint32("level", ps, depth, &q_u->level))
4575 return False;
4577 if(!new_spoolss_io_buffer("", ps, depth, q_u->buffer))
4578 return False;
4580 if (!prs_align(ps))
4581 return False;
4583 if (!prs_uint32("offered", ps, depth, &q_u->offered))
4584 return False;
4586 return True;
4589 /*******************************************************************
4590 ********************************************************************/
4591 BOOL spoolss_io_r_enumprintprocdatatypes(char *desc, SPOOL_R_ENUMPRINTPROCDATATYPES *r_u, prs_struct *ps, int depth)
4593 prs_debug(ps, depth, desc, "spoolss_io_r_enumprintprocdatatypes");
4594 depth++;
4596 if (!prs_align(ps))
4597 return False;
4599 if (!new_spoolss_io_buffer("", ps, depth, r_u->buffer))
4600 return False;
4602 if (!prs_align(ps))
4603 return False;
4605 if (!prs_uint32("needed", ps, depth, &r_u->needed))
4606 return False;
4608 if (!prs_uint32("returned", ps, depth, &r_u->returned))
4609 return False;
4611 if (!prs_uint32("status", ps, depth, &r_u->status))
4612 return False;
4614 return True;
4617 /*******************************************************************
4618 ********************************************************************/
4619 BOOL spoolss_io_q_enumprintprocdatatypes(char *desc, SPOOL_Q_ENUMPRINTPROCDATATYPES *q_u, prs_struct *ps, int depth)
4621 prs_debug(ps, depth, desc, "spoolss_io_q_enumprintprocdatatypes");
4622 depth++;
4624 if (!prs_align(ps))
4625 return False;
4627 if (!prs_uint32("name_ptr", ps, depth, &q_u->name_ptr))
4628 return False;
4629 if (!smb_io_unistr2("name", &q_u->name, True, ps, depth))
4630 return False;
4632 if (!prs_align(ps))
4633 return False;
4635 if (!prs_uint32("processor_ptr", ps, depth, &q_u->processor_ptr))
4636 return False;
4637 if (!smb_io_unistr2("processor", &q_u->processor, q_u->processor_ptr, ps, depth))
4638 return False;
4640 if (!prs_align(ps))
4641 return False;
4643 if (!prs_uint32("level", ps, depth, &q_u->level))
4644 return False;
4646 if(!new_spoolss_io_buffer("buffer", ps, depth, q_u->buffer))
4647 return False;
4649 if (!prs_align(ps))
4650 return False;
4652 if (!prs_uint32("offered", ps, depth, &q_u->offered))
4653 return False;
4655 return True;
4658 /*******************************************************************
4659 Parse a SPOOL_Q_ENUMPRINTMONITORS structure.
4660 ********************************************************************/
4661 BOOL spoolss_io_q_enumprintmonitors(char *desc, SPOOL_Q_ENUMPRINTMONITORS *q_u, prs_struct *ps, int depth)
4663 prs_debug(ps, depth, desc, "spoolss_io_q_enumprintmonitors");
4664 depth++;
4666 if (!prs_align(ps))
4667 return False;
4669 if (!prs_uint32("name_ptr", ps, depth, &q_u->name_ptr))
4670 return False;
4671 if (!smb_io_unistr2("name", &q_u->name, True, ps, depth))
4672 return False;
4674 if (!prs_align(ps))
4675 return False;
4677 if (!prs_uint32("level", ps, depth, &q_u->level))
4678 return False;
4680 if(!new_spoolss_io_buffer("", ps, depth, q_u->buffer))
4681 return False;
4683 if (!prs_align(ps))
4684 return False;
4686 if (!prs_uint32("offered", ps, depth, &q_u->offered))
4687 return False;
4689 return True;
4692 /*******************************************************************
4693 ********************************************************************/
4694 BOOL spoolss_io_r_enumprintmonitors(char *desc, SPOOL_R_ENUMPRINTMONITORS *r_u, prs_struct *ps, int depth)
4696 prs_debug(ps, depth, desc, "spoolss_io_r_enumprintmonitors");
4697 depth++;
4699 if (!prs_align(ps))
4700 return False;
4702 if (!new_spoolss_io_buffer("", ps, depth, r_u->buffer))
4703 return False;
4705 if (!prs_align(ps))
4706 return False;
4708 if (!prs_uint32("needed", ps, depth, &r_u->needed))
4709 return False;
4711 if (!prs_uint32("returned", ps, depth, &r_u->returned))
4712 return False;
4714 if (!prs_uint32("status", ps, depth, &r_u->status))
4715 return False;
4717 return True;
4720 /*******************************************************************
4721 ********************************************************************/
4722 BOOL spoolss_io_r_enumprinterdata(char *desc, SPOOL_R_ENUMPRINTERDATA *r_u, prs_struct *ps, int depth)
4724 prs_debug(ps, depth, desc, "spoolss_io_r_enumprinterdata");
4725 depth++;
4727 if(!prs_align(ps))
4728 return False;
4729 if(!prs_uint32("valuesize", ps, depth, &r_u->valuesize))
4730 return False;
4731 if(!prs_uint16s(False, "value", ps, depth, r_u->value, r_u->valuesize))
4732 return False;
4734 if(!prs_align(ps))
4735 return False;
4737 if(!prs_uint32("realvaluesize", ps, depth, &r_u->realvaluesize))
4738 return False;
4740 if(!prs_uint32("type", ps, depth, &r_u->type))
4741 return False;
4743 if(!prs_uint32("datasize", ps, depth, &r_u->datasize))
4744 return False;
4745 if(!prs_uint8s(False, "data", ps, depth, r_u->data, r_u->datasize))
4746 return False;
4747 if(!prs_align(ps))
4748 return False;
4750 if(!prs_uint32("realdatasize", ps, depth, &r_u->realdatasize))
4751 return False;
4752 if(!prs_uint32("status", ps, depth, &r_u->status))
4753 return False;
4755 return True;
4758 /*******************************************************************
4759 ********************************************************************/
4760 BOOL spoolss_io_q_enumprinterdata(char *desc, SPOOL_Q_ENUMPRINTERDATA *q_u, prs_struct *ps, int depth)
4762 prs_debug(ps, depth, desc, "spoolss_io_q_enumprinterdata");
4763 depth++;
4765 if(!prs_align(ps))
4766 return False;
4767 if(!smb_io_pol_hnd("printer handle",&q_u->handle,ps,depth))
4768 return False;
4769 if(!prs_uint32("index", ps, depth, &q_u->index))
4770 return False;
4771 if(!prs_uint32("valuesize", ps, depth, &q_u->valuesize))
4772 return False;
4773 if(!prs_uint32("datasize", ps, depth, &q_u->datasize))
4774 return False;
4776 return True;
4779 /*******************************************************************
4780 ********************************************************************/
4781 BOOL make_spoolss_q_enumprinterdata(SPOOL_Q_ENUMPRINTERDATA *q_u,
4782 const POLICY_HND *hnd,
4783 uint32 idx, uint32 valuelen, uint32 datalen)
4785 memcpy(&q_u->handle, hnd, sizeof(q_u->handle));
4786 q_u->index=idx;
4787 q_u->valuesize=valuelen;
4788 q_u->datasize=datalen;
4790 return True;
4793 /*******************************************************************
4794 ********************************************************************/
4795 BOOL spoolss_io_q_setprinterdata(char *desc, SPOOL_Q_SETPRINTERDATA *q_u, prs_struct *ps, int depth)
4797 prs_debug(ps, depth, desc, "spoolss_io_q_setprinterdata");
4798 depth++;
4800 if(!prs_align(ps))
4801 return False;
4802 if(!smb_io_pol_hnd("printer handle", &q_u->handle, ps, depth))
4803 return False;
4804 if(!smb_io_unistr2("", &q_u->value, True, ps, depth))
4805 return False;
4807 if(!prs_align(ps))
4808 return False;
4810 if(!prs_uint32("type", ps, depth, &q_u->type))
4811 return False;
4813 if(!prs_uint32("max_len", ps, depth, &q_u->max_len))
4814 return False;
4816 switch (q_u->type)
4818 case 0x1:
4819 case 0x3:
4820 case 0x4:
4821 case 0x7:
4822 q_u->data=(uint8 *)malloc(q_u->max_len * sizeof(uint8));
4823 if(q_u->data == NULL)
4824 return False;
4825 if(!prs_uint8s(False,"data", ps, depth, q_u->data, q_u->max_len))
4826 return False;
4827 if(!prs_align(ps))
4828 return False;
4829 break;
4832 if(!prs_uint32("real_len", ps, depth, &q_u->real_len))
4833 return False;
4835 return True;
4838 void free_spoolss_q_setprinterdata(SPOOL_Q_SETPRINTERDATA *q_u)
4840 safe_free(q_u->data);
4843 /*******************************************************************
4844 ********************************************************************/
4845 BOOL spoolss_io_r_setprinterdata(char *desc, SPOOL_R_SETPRINTERDATA *r_u, prs_struct *ps, int depth)
4847 prs_debug(ps, depth, desc, "spoolss_io_r_setprinterdata");
4848 depth++;
4850 if(!prs_align(ps))
4851 return False;
4852 if(!prs_uint32("status", ps, depth, &r_u->status))
4853 return False;
4855 return True;
4858 /*******************************************************************
4859 ********************************************************************/
4860 BOOL convert_specific_param(NT_PRINTER_PARAM **param, const UNISTR2 *value,
4861 uint32 type, const uint8 *data, uint32 len)
4863 DEBUG(5,("converting a specific param struct\n"));
4865 if (*param == NULL)
4867 *param=(NT_PRINTER_PARAM *)malloc(sizeof(NT_PRINTER_PARAM));
4868 if(*param == NULL)
4869 return False;
4870 ZERO_STRUCTP(*param);
4871 DEBUGADD(6,("Allocated a new PARAM struct\n"));
4873 unistr2_to_ascii((*param)->value, value, sizeof((*param)->value)-1);
4874 (*param)->type = type;
4876 /* le champ data n'est pas NULL termine */
4877 /* on stocke donc la longueur */
4879 (*param)->data_len=len;
4881 (*param)->data=(uint8 *)malloc(len * sizeof(uint8));
4882 if((*param)->data == NULL)
4883 return False;
4885 memcpy((*param)->data, data, len);
4887 DEBUGADD(6,("\tvalue:[%s], len:[%d]\n",(*param)->value, (*param)->data_len));
4889 return True;
4892 /*******************************************************************
4893 ********************************************************************/
4894 static BOOL spoolss_io_addform(char *desc, FORM *f, uint32 ptr, prs_struct *ps, int depth)
4896 prs_debug(ps, depth, desc, "spoolss_io_addform");
4897 depth++;
4898 if(!prs_align(ps))
4899 return False;
4901 if (ptr!=0)
4903 if(!prs_uint32("flags", ps, depth, &f->flags))
4904 return False;
4905 if(!prs_uint32("name_ptr", ps, depth, &f->name_ptr))
4906 return False;
4907 if(!prs_uint32("size_x", ps, depth, &f->size_x))
4908 return False;
4909 if(!prs_uint32("size_y", ps, depth, &f->size_y))
4910 return False;
4911 if(!prs_uint32("left", ps, depth, &f->left))
4912 return False;
4913 if(!prs_uint32("top", ps, depth, &f->top))
4914 return False;
4915 if(!prs_uint32("right", ps, depth, &f->right))
4916 return False;
4917 if(!prs_uint32("bottom", ps, depth, &f->bottom))
4918 return False;
4920 if(!smb_io_unistr2("", &f->name, f->name_ptr, ps, depth))
4921 return False;
4924 return True;
4927 /*******************************************************************
4928 ********************************************************************/
4929 BOOL spoolss_io_q_addform(char *desc, SPOOL_Q_ADDFORM *q_u, prs_struct *ps, int depth)
4931 uint32 useless_ptr=0;
4932 prs_debug(ps, depth, desc, "spoolss_io_q_addform");
4933 depth++;
4935 if(!prs_align(ps))
4936 return False;
4937 if(!smb_io_pol_hnd("printer handle", &q_u->handle, ps, depth))
4938 return False;
4939 if(!prs_uint32("level", ps, depth, &q_u->level))
4940 return False;
4941 if(!prs_uint32("level2", ps, depth, &q_u->level2))
4942 return False;
4944 if (q_u->level==1)
4946 if(!prs_uint32("useless_ptr", ps, depth, &useless_ptr))
4947 return False;
4948 if(!spoolss_io_addform("", &q_u->form, useless_ptr, ps, depth))
4949 return False;
4952 return True;
4955 /*******************************************************************
4956 ********************************************************************/
4957 BOOL spoolss_io_r_addform(char *desc, SPOOL_R_ADDFORM *r_u, prs_struct *ps, int depth)
4959 prs_debug(ps, depth, desc, "spoolss_io_r_addform");
4960 depth++;
4962 if(!prs_align(ps))
4963 return False;
4964 if(!prs_uint32("status", ps, depth, &r_u->status))
4965 return False;
4967 return True;
4970 /*******************************************************************
4971 ********************************************************************/
4972 BOOL spoolss_io_q_setform(char *desc, SPOOL_Q_SETFORM *q_u, prs_struct *ps, int depth)
4974 uint32 useless_ptr=0;
4975 prs_debug(ps, depth, desc, "spoolss_io_q_setform");
4976 depth++;
4978 if(!prs_align(ps))
4979 return False;
4980 if(!smb_io_pol_hnd("printer handle", &q_u->handle, ps, depth))
4981 return False;
4982 if(!smb_io_unistr2("", &q_u->name, True, ps, depth))
4983 return False;
4985 if(!prs_align(ps))
4986 return False;
4988 if(!prs_uint32("level", ps, depth, &q_u->level))
4989 return False;
4990 if(!prs_uint32("level2", ps, depth, &q_u->level2))
4991 return False;
4993 if (q_u->level==1)
4995 if(!prs_uint32("useless_ptr", ps, depth, &useless_ptr))
4996 return False;
4997 if(!spoolss_io_addform("", &q_u->form, useless_ptr, ps, depth))
4998 return False;
5001 return True;
5004 /*******************************************************************
5005 ********************************************************************/
5006 BOOL spoolss_io_r_setform(char *desc, SPOOL_R_SETFORM *r_u, prs_struct *ps, int depth)
5008 prs_debug(ps, depth, desc, "spoolss_io_r_setform");
5009 depth++;
5011 if(!prs_align(ps))
5012 return False;
5013 if(!prs_uint32("status", ps, depth, &r_u->status))
5014 return False;
5016 return True;
5019 /*******************************************************************
5020 Parse a SPOOL_R_GETJOB structure.
5021 ********************************************************************/
5022 BOOL spoolss_io_r_getjob(char *desc, SPOOL_R_GETJOB *r_u, prs_struct *ps, int depth)
5024 prs_debug(ps, depth, desc, "spoolss_io_r_getjob");
5025 depth++;
5027 if (!prs_align(ps))
5028 return False;
5030 if (!new_spoolss_io_buffer("", ps, depth, r_u->buffer))
5031 return False;
5033 if (!prs_align(ps))
5034 return False;
5036 if (!prs_uint32("needed", ps, depth, &r_u->needed))
5037 return False;
5039 if (!prs_uint32("status", ps, depth, &r_u->status))
5040 return False;
5042 return True;
5045 /*******************************************************************
5046 Parse a SPOOL_Q_GETJOB structure.
5047 ********************************************************************/
5048 BOOL spoolss_io_q_getjob(char *desc, SPOOL_Q_GETJOB *q_u, prs_struct *ps, int depth)
5050 prs_debug(ps, depth, desc, "");
5051 depth++;
5053 if(!prs_align(ps))
5054 return False;
5056 if(!smb_io_pol_hnd("printer handle",&q_u->handle,ps,depth))
5057 return False;
5058 if(!prs_uint32("jobid", ps, depth, &q_u->jobid))
5059 return False;
5060 if(!prs_uint32("level", ps, depth, &q_u->level))
5061 return False;
5063 if(!new_spoolss_io_buffer("", ps, depth, q_u->buffer))
5064 return False;
5066 if(!prs_align(ps))
5067 return False;
5069 if(!prs_uint32("offered", ps, depth, &q_u->offered))
5070 return False;
5072 return True;
5075 void free_devmode(DEVICEMODE *devmode)
5077 if (devmode!=NULL) {
5078 safe_free(devmode->private);
5079 safe_free(devmode);
5083 void free_printer_info_1(PRINTER_INFO_1 *printer)
5085 safe_free(printer);
5088 void free_printer_info_2(PRINTER_INFO_2 *printer)
5090 if (printer!=NULL) {
5091 free_devmode(printer->devmode);
5092 printer->devmode = NULL;
5093 if (printer->secdesc != NULL)
5094 free_sec_desc(&printer->secdesc);
5095 safe_free(printer);
5099 void free_printer_info_3(PRINTER_INFO_3 *printer)
5101 if (printer!=NULL) {
5102 if (printer->secdesc != NULL)
5103 free_sec_desc(&printer->secdesc);
5104 safe_free(printer);
5108 void free_spool_printer_info_1(SPOOL_PRINTER_INFO_LEVEL_1 *printer)
5110 safe_free(printer);
5113 void free_spool_printer_info_2(SPOOL_PRINTER_INFO_LEVEL_2 *printer)
5115 if (printer!=NULL) {
5116 if (printer->secdesc != NULL)
5117 free_sec_desc_buf(&printer->secdesc);
5118 safe_free(printer);
5122 void free_spool_printer_info_3(SPOOL_PRINTER_INFO_LEVEL_3 *printer)
5124 safe_free(printer);
5127 void free_spool_printer_info_level(SPOOL_PRINTER_INFO_LEVEL *pil)
5129 if (pil == NULL)
5130 return;
5132 switch (pil->level) {
5133 case 1:
5134 free_spool_printer_info_1(pil->info_1);
5135 break;
5136 case 2:
5137 free_spool_printer_info_2(pil->info_2);
5138 break;
5139 case 3:
5140 free_spool_printer_info_3(pil->info_3);
5141 break;
5142 default:
5143 break;
5147 static PRINTER_INFO_2 *prt2_dup(const PRINTER_INFO_2* from)
5149 PRINTER_INFO_2 *copy = (PRINTER_INFO_2 *)malloc(sizeof(PRINTER_INFO_2));
5150 if (copy != NULL) {
5151 if (from != NULL)
5152 memcpy(copy, from, sizeof(*copy));
5153 else
5154 ZERO_STRUCTP(copy);
5156 return copy;
5159 void free_print2_array(uint32 num_entries, PRINTER_INFO_2 **entries)
5161 void(*fn)(void*) = (void(*)(void*))&free_printer_info_2;
5162 free_void_array(num_entries, (void**)entries, *fn);
5165 PRINTER_INFO_2 *add_print2_to_array(uint32 *len, PRINTER_INFO_2 ***array,
5166 const PRINTER_INFO_2 *prt)
5168 void*(*fn)(const void*) = (void*(*)(const void*))&prt2_dup;
5169 return (PRINTER_INFO_2*)add_copy_to_array(len,
5170 (void***)array, (const void*)prt, *fn, True);
5173 static PRINTER_INFO_1 *prt1_dup(const PRINTER_INFO_1* from)
5175 PRINTER_INFO_1 *copy = (PRINTER_INFO_1 *)malloc(sizeof(PRINTER_INFO_1));
5176 if (copy != NULL) {
5177 if (from != NULL)
5178 memcpy(copy, from, sizeof(*copy));
5179 else
5180 ZERO_STRUCTP(copy);
5182 return copy;
5185 void free_print1_array(uint32 num_entries, PRINTER_INFO_1 **entries)
5187 void(*fn)(void*) = (void(*)(void*))&free;
5188 free_void_array(num_entries, (void**)entries, *fn);
5191 PRINTER_INFO_1 *add_print1_to_array(uint32 *len, PRINTER_INFO_1 ***array,
5192 const PRINTER_INFO_1 *prt)
5194 void*(*fn)(const void*) = (void*(*)(const void*))&prt1_dup;
5195 return (PRINTER_INFO_1*)add_copy_to_array(len,
5196 (void***)array, (const void*)prt, *fn, True);
5199 static JOB_INFO_1 *job1_dup(const JOB_INFO_1* from)
5201 JOB_INFO_1 *copy = (JOB_INFO_1 *)malloc(sizeof(JOB_INFO_1));
5202 if (copy != NULL)
5204 if (from != NULL)
5206 memcpy(copy, from, sizeof(*copy));
5208 else
5210 ZERO_STRUCTP(copy);
5213 return copy;
5216 void free_job1_array(uint32 num_entries, JOB_INFO_1 **entries)
5218 void(*fn)(void*) = (void(*)(void*))&free;
5219 free_void_array(num_entries, (void**)entries, *fn);
5222 JOB_INFO_1 *add_job1_to_array(uint32 *len, JOB_INFO_1 ***array,
5223 const JOB_INFO_1 *job)
5225 void*(*fn)(const void*) = (void*(*)(const void*))&job1_dup;
5226 return (JOB_INFO_1*)add_copy_to_array(len,
5227 (void***)array, (const void*)job, *fn, True);
5230 static JOB_INFO_2 *job2_dup(const JOB_INFO_2* from)
5232 JOB_INFO_2 *copy = (JOB_INFO_2 *)malloc(sizeof(JOB_INFO_2));
5233 if (copy != NULL)
5235 if (from != NULL)
5237 memcpy(copy, from, sizeof(*copy));
5239 else
5241 ZERO_STRUCTP(copy);
5244 return copy;
5247 void free_job_info_2(JOB_INFO_2 *job)
5249 if (job!=NULL)
5251 free_devmode(job->devmode);
5252 free(job);
5256 void free_job2_array(uint32 num_entries, JOB_INFO_2 **entries)
5258 void(*fn)(void*) = (void(*)(void*))&free_job_info_2;
5259 free_void_array(num_entries, (void**)entries, *fn);
5262 JOB_INFO_2 *add_job2_to_array(uint32 *len, JOB_INFO_2 ***array,
5263 const JOB_INFO_2 *job)
5265 void*(*fn)(const void*) = (void*(*)(const void*))&job2_dup;
5266 return (JOB_INFO_2*)add_copy_to_array(len,
5267 (void***)array, (const void*)job, *fn, True);
5270 /*******************************************************************
5271 Parse a SPOOL_Q_REPLYOPENPRINTER structure.
5272 ********************************************************************/
5273 BOOL spoolss_io_q_replyopenprinter(char *desc, SPOOL_Q_REPLYOPENPRINTER *q_u, prs_struct *ps, int depth)
5275 prs_debug(ps, depth, desc, "spoolss_io_q_replyopenprinter");
5276 depth++;
5278 if(!prs_align(ps))
5279 return False;
5281 if(!smb_io_unistr2("", &q_u->string, True, ps, depth))
5282 return False;
5284 if(!prs_align(ps))
5285 return False;
5287 if(!prs_uint32("printer", ps, depth, &q_u->printer))
5288 return False;
5289 if(!prs_uint32("type", ps, depth, &q_u->type))
5290 return False;
5292 if(!new_spoolss_io_buffer("", ps, depth, q_u->buffer))
5293 return False;
5295 return True;
5298 /*******************************************************************
5299 Parse a SPOOL_R_REPLYOPENPRINTER structure.
5300 ********************************************************************/
5301 BOOL spoolss_io_r_replyopenprinter(char *desc, SPOOL_R_REPLYOPENPRINTER *r_u, prs_struct *ps, int depth)
5303 prs_debug(ps, depth, desc, "spoolss_io_r_replyopenprinter");
5304 depth++;
5306 if (!prs_align(ps))
5307 return False;
5309 if(!smb_io_pol_hnd("printer handle",&r_u->handle,ps,depth))
5310 return False;
5312 if (!prs_uint32("status", ps, depth, &r_u->status))
5313 return False;
5315 return True;
5318 /*******************************************************************
5319 Parse a SPOOL_Q_REPLYCLOSEPRINTER structure.
5320 ********************************************************************/
5321 BOOL spoolss_io_q_replycloseprinter(char *desc, SPOOL_Q_REPLYCLOSEPRINTER *q_u, prs_struct *ps, int depth)
5323 prs_debug(ps, depth, desc, "spoolss_io_q_replycloseprinter");
5324 depth++;
5326 if(!prs_align(ps))
5327 return False;
5329 if(!smb_io_pol_hnd("printer handle",&q_u->handle,ps,depth))
5330 return False;
5332 return True;
5335 /*******************************************************************
5336 Parse a SPOOL_R_REPLYCLOSEPRINTER structure.
5337 ********************************************************************/
5338 BOOL spoolss_io_r_replycloseprinter(char *desc, SPOOL_R_REPLYCLOSEPRINTER *r_u, prs_struct *ps, int depth)
5340 prs_debug(ps, depth, desc, "spoolss_io_r_replycloseprinter");
5341 depth++;
5343 if (!prs_align(ps))
5344 return False;
5346 if(!smb_io_pol_hnd("printer handle",&r_u->handle,ps,depth))
5347 return False;
5349 if (!prs_uint32("status", ps, depth, &r_u->status))
5350 return False;
5352 return True;