this is a big global fix for the ptr = Realloc(ptr, size) bug.
[ira/wip.git] / source / rpc_parse / parse_spoolss.c
index bd33b634f8848de418a56d52a236d1a92f378b9c..dd2c4a541abddebbe513ea74dbe9dfb9d0ecb438 100644 (file)
@@ -5,6 +5,7 @@
  *  Copyright (C) Andrew Tridgell              1992-2000,
  *  Copyright (C) Luke Kenneth Casson Leighton 1996-2000,
  *  Copyright (C) Jean François Micouleau      1998-2000.
+ *  Copyright (C) Gerald Carter                2000
  *
  *  This program is free software; you can redistribute it and/or modify
  *  it under the terms of the GNU General Public License as published by
  *  Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  */
 
-
 #include "includes.h"
 
 extern int DEBUGLEVEL;
+
 /*******************************************************************
 return the length of a UNISTR string.
 ********************************************************************/  
+
 static uint32 str_len_uni(UNISTR *source)
 {
        uint32 i=0;
 
-       if (!source->buffer) return 0;
+       if (!source->buffer)
+               return 0;
+
+       while (source->buffer[i])
+               i++;
 
-       while (source->buffer[i]!=0x0000)
-       {
-        i++;
-       }
        return i;
 }
 
 /*******************************************************************
 This should be moved in a more generic lib.
 ********************************************************************/  
+
 static BOOL spoolss_io_system_time(char *desc, prs_struct *ps, int depth, SYSTEMTIME *systime)
 {
        if(!prs_uint16("year", ps, depth, &(systime->year)))
@@ -68,6 +71,7 @@ static BOOL spoolss_io_system_time(char *desc, prs_struct *ps, int depth, SYSTEM
 
 /*******************************************************************
 ********************************************************************/  
+
 BOOL make_systemtime(SYSTEMTIME *systime, struct tm *unixtime)
 {
        systime->year=unixtime->tm_year+1900;
@@ -85,6 +89,7 @@ BOOL make_systemtime(SYSTEMTIME *systime, struct tm *unixtime)
 /*******************************************************************
 reads or writes an DOC_INFO structure.
 ********************************************************************/  
+
 static BOOL smb_io_doc_info_1(char *desc, DOC_INFO_1 *info_1, prs_struct *ps, int depth)
 {
        if (info_1 == NULL) return False;
@@ -95,18 +100,18 @@ static BOOL smb_io_doc_info_1(char *desc, DOC_INFO_1 *info_1, prs_struct *ps, in
        if(!prs_align(ps))
                return False;
        
-       if(!prs_uint32("p_docname",    ps, depth, &(info_1->p_docname)))
+       if(!prs_uint32("p_docname",    ps, depth, &info_1->p_docname))
                return False;
-       if(!prs_uint32("p_outputfile", ps, depth, &(info_1->p_outputfile)))
+       if(!prs_uint32("p_outputfile", ps, depth, &info_1->p_outputfile))
                return False;
-       if(!prs_uint32("p_datatype",   ps, depth, &(info_1->p_datatype)))
+       if(!prs_uint32("p_datatype",   ps, depth, &info_1->p_datatype))
                return False;
 
-       if(!smb_io_unistr2("", &(info_1->docname),    info_1->p_docname,    ps, depth))
+       if(!smb_io_unistr2("", &info_1->docname,    info_1->p_docname,    ps, depth))
                return False;
-       if(!smb_io_unistr2("", &(info_1->outputfile), info_1->p_outputfile, ps, depth))
+       if(!smb_io_unistr2("", &info_1->outputfile, info_1->p_outputfile, ps, depth))
                return False;
-       if(!smb_io_unistr2("", &(info_1->datatype),   info_1->p_datatype,   ps, depth))
+       if(!smb_io_unistr2("", &info_1->datatype,   info_1->p_datatype,   ps, depth))
                return False;
 
        return True;
@@ -115,6 +120,7 @@ static BOOL smb_io_doc_info_1(char *desc, DOC_INFO_1 *info_1, prs_struct *ps, in
 /*******************************************************************
 reads or writes an DOC_INFO structure.
 ********************************************************************/  
+
 static BOOL smb_io_doc_info(char *desc, DOC_INFO *info, prs_struct *ps, int depth)
 {
        uint32 useless_ptr=0;
@@ -127,16 +133,16 @@ static BOOL smb_io_doc_info(char *desc, DOC_INFO *info, prs_struct *ps, int dept
        if(!prs_align(ps))
                return False;
         
-       if(!prs_uint32("switch_value", ps, depth, &(info->switch_value)))
+       if(!prs_uint32("switch_value", ps, depth, &info->switch_value))
                return False;
        
-       if(!prs_uint32("doc_info_X ptr", ps, depth, &(useless_ptr)))
+       if(!prs_uint32("doc_info_X ptr", ps, depth, &useless_ptr))
                return False;
 
        switch (info->switch_value)
        {
                case 1: 
-                       if(!smb_io_doc_info_1("",&(info->doc_info_1), ps, depth))
+                       if(!smb_io_doc_info_1("",&info->doc_info_1, ps, depth))
                                return False;
                        break;
                case 2:
@@ -150,7 +156,7 @@ static BOOL smb_io_doc_info(char *desc, DOC_INFO *info, prs_struct *ps, int dept
                          Maybe one day with Windows for dishwasher 2037 ...
                          
                        */
-                       /* smb_io_doc_info_2("",&(info->doc_info_2), ps, depth); */
+                       /* smb_io_doc_info_2("",&info->doc_info_2, ps, depth); */
                        break;
                default:
                        DEBUG(0,("Something is obviously wrong somewhere !\n"));
@@ -163,6 +169,7 @@ static BOOL smb_io_doc_info(char *desc, DOC_INFO *info, prs_struct *ps, int dept
 /*******************************************************************
 reads or writes an DOC_INFO_CONTAINER structure.
 ********************************************************************/  
+
 static BOOL smb_io_doc_info_container(char *desc, DOC_INFO_CONTAINER *cont, prs_struct *ps, int depth)
 {
        if (cont == NULL) return False;
@@ -185,6 +192,7 @@ static BOOL smb_io_doc_info_container(char *desc, DOC_INFO_CONTAINER *cont, prs_
 /*******************************************************************
 reads or writes an NOTIFY OPTION TYPE structure.
 ********************************************************************/  
+
 static BOOL smb_io_notify_option_type(char *desc, SPOOL_NOTIFY_OPTION_TYPE *type, prs_struct *ps, int depth)
 {
        prs_debug(ps, depth, desc, "smb_io_notify_option_type");
@@ -212,6 +220,7 @@ static BOOL smb_io_notify_option_type(char *desc, SPOOL_NOTIFY_OPTION_TYPE *type
 /*******************************************************************
 reads or writes an NOTIFY OPTION TYPE DATA.
 ********************************************************************/  
+
 static BOOL smb_io_notify_option_type_data(char *desc, SPOOL_NOTIFY_OPTION_TYPE *type, prs_struct *ps, int depth)
 {
        int i;
@@ -242,6 +251,7 @@ static BOOL smb_io_notify_option_type_data(char *desc, SPOOL_NOTIFY_OPTION_TYPE
 /*******************************************************************
 reads or writes an NOTIFY OPTION structure.
 ********************************************************************/  
+
 static BOOL smb_io_notify_option_type_ctr(char *desc, SPOOL_NOTIFY_OPTION_TYPE_CTR *ctr , prs_struct *ps, int depth)
 {              
        int i;
@@ -254,7 +264,7 @@ static BOOL smb_io_notify_option_type_ctr(char *desc, SPOOL_NOTIFY_OPTION_TYPE_C
 
        /* reading */
        if (UNMARSHALLING(ps))
-               if((ctr->type=(SPOOL_NOTIFY_OPTION_TYPE *)malloc(ctr->count*sizeof(SPOOL_NOTIFY_OPTION_TYPE))) == NULL)
+               if((ctr->type=(SPOOL_NOTIFY_OPTION_TYPE *)prs_alloc_mem(ps,ctr->count*sizeof(SPOOL_NOTIFY_OPTION_TYPE))) == NULL)
                        return False;
                
        /* the option type struct */
@@ -273,6 +283,7 @@ static BOOL smb_io_notify_option_type_ctr(char *desc, SPOOL_NOTIFY_OPTION_TYPE_C
 /*******************************************************************
 reads or writes an NOTIFY OPTION structure.
 ********************************************************************/  
+
 static BOOL smb_io_notify_option(char *desc, SPOOL_NOTIFY_OPTION *option, prs_struct *ps, int depth)
 {
        prs_debug(ps, depth, desc, "smb_io_notify_option");
@@ -303,6 +314,7 @@ static BOOL smb_io_notify_option(char *desc, SPOOL_NOTIFY_OPTION *option, prs_st
 /*******************************************************************
 reads or writes an NOTIFY INFO DATA structure.
 ********************************************************************/  
+
 static BOOL smb_io_notify_info_data(char *desc,SPOOL_NOTIFY_INFO_DATA *data, prs_struct *ps, int depth)
 {
        uint32 useless_ptr=0xADDE0FF0;
@@ -362,6 +374,7 @@ static BOOL smb_io_notify_info_data(char *desc,SPOOL_NOTIFY_INFO_DATA *data, prs
 /*******************************************************************
 reads or writes an NOTIFY INFO DATA structure.
 ********************************************************************/  
+
 BOOL smb_io_notify_info_data_strings(char *desc,SPOOL_NOTIFY_INFO_DATA *data,
                                      prs_struct *ps, int depth)
 {
@@ -381,8 +394,33 @@ BOOL smb_io_notify_info_data_strings(char *desc,SPOOL_NOTIFY_INFO_DATA *data,
                x=data->notify_data.data.length+1;
                if(!prs_uint32("string length", ps, depth, &x ))
                        return False;
-               if(!prs_uint16s(True,"string",ps,depth,data->notify_data.data.string,x))
-                       return False;
+               if (MARSHALLING(ps)) {
+                       /* These are already in little endian format. Don't byte swap. */
+                       if (x == 1) {
+
+                               /* No memory allocated for this string
+                                  therefore following the data.string
+                                  pointer is a bad idea.  Use a pointer to
+                                  the uint32 length union member to
+                                  provide a source for a unicode NULL */
+
+                               if(!prs_uint8s(True,"string",ps,depth, (uint8 *)&data->notify_data.data.length,x*2)) 
+                                       return False;
+                       } else {
+                               if(!prs_uint16uni(True,"string",ps,depth,data->notify_data.data.string,x))
+                                       return False;
+                       }
+               } else {
+
+                       /* Tallocate memory for string */
+
+                       data->notify_data.data.string = (uint16 *)prs_alloc_mem(ps, x * 2);
+                       if (!data->notify_data.data.string) 
+                               return False;
+
+                       if(!prs_uint16uni(True,"string",ps,depth,data->notify_data.data.string,x))
+                               return False;
+               }
        }
        if(!prs_align(ps))
                return False;
@@ -393,6 +431,7 @@ BOOL smb_io_notify_info_data_strings(char *desc,SPOOL_NOTIFY_INFO_DATA *data,
 /*******************************************************************
 reads or writes an NOTIFY INFO structure.
 ********************************************************************/  
+
 static BOOL smb_io_notify_info(char *desc, SPOOL_NOTIFY_INFO *info, prs_struct *ps, int depth)
 {
        int i;
@@ -426,40 +465,40 @@ static BOOL smb_io_notify_info(char *desc, SPOOL_NOTIFY_INFO *info, prs_struct *
        return True;
 }
 
-
 /*******************************************************************
 ********************************************************************/  
+
 static BOOL spool_io_user_level_1(char *desc, SPOOL_USER_1 *q_u, prs_struct *ps, int depth)
 {
        prs_debug(ps, depth, desc, "");
        depth++;
 
        /* reading */
-       if (ps->io)
+       if (UNMARSHALLING(ps))
                ZERO_STRUCTP(q_u);
 
        if (!prs_align(ps))
                return False;
-       if (!prs_uint32("size", ps, depth, &(q_u->size)))
+       if (!prs_uint32("size", ps, depth, &q_u->size))
                return False;
-       if (!prs_uint32("client_name_ptr", ps, depth, &(q_u->client_name_ptr)))
+       if (!prs_uint32("client_name_ptr", ps, depth, &q_u->client_name_ptr))
                return False;
-       if (!prs_uint32("user_name_ptr", ps, depth, &(q_u->user_name_ptr)))
+       if (!prs_uint32("user_name_ptr", ps, depth, &q_u->user_name_ptr))
                return False;
-       if (!prs_uint32("build", ps, depth, &(q_u->build)))
+       if (!prs_uint32("build", ps, depth, &q_u->build))
                return False;
-       if (!prs_uint32("major", ps, depth, &(q_u->major)))
+       if (!prs_uint32("major", ps, depth, &q_u->major))
                return False;
-       if (!prs_uint32("minor", ps, depth, &(q_u->minor)))
+       if (!prs_uint32("minor", ps, depth, &q_u->minor))
                return False;
-       if (!prs_uint32("processor", ps, depth, &(q_u->processor)))
+       if (!prs_uint32("processor", ps, depth, &q_u->processor))
                return False;
 
-       if (!smb_io_unistr2("", &(q_u->client_name), q_u->client_name_ptr, ps, depth))
+       if (!smb_io_unistr2("", &q_u->client_name, q_u->client_name_ptr, ps, depth))
                return False;
        if (!prs_align(ps))
                return False;
-       if (!smb_io_unistr2("", &(q_u->user_name),   q_u->user_name_ptr,   ps, depth))
+       if (!smb_io_unistr2("", &q_u->user_name,   q_u->user_name_ptr,   ps, depth))
                return False;
 
        return True;
@@ -467,6 +506,7 @@ static BOOL spool_io_user_level_1(char *desc, SPOOL_USER_1 *q_u, prs_struct *ps,
 
 /*******************************************************************
 ********************************************************************/  
+
 static BOOL spool_io_user_level(char *desc, SPOOL_USER_CTR *q_u, prs_struct *ps, int depth)
 {
        if (q_u==NULL)
@@ -484,7 +524,7 @@ static BOOL spool_io_user_level(char *desc, SPOOL_USER_CTR *q_u, prs_struct *ps,
        
        switch (q_u->level) {   
        case 1:
-               if (!spool_io_user_level_1("", &(q_u->user1), ps, depth))
+               if (!spool_io_user_level_1("", &q_u->user1, ps, depth))
                        return False;
                break;
        default:
@@ -498,7 +538,8 @@ static BOOL spool_io_user_level(char *desc, SPOOL_USER_CTR *q_u, prs_struct *ps,
  * read or write a DEVICEMODE struct.
  * on reading allocate memory for the private member
  ********************************************************************/
-static BOOL spoolss_io_devmode(char *desc, prs_struct *ps, int depth, DEVICEMODE *devmode)
+
+BOOL spoolss_io_devmode(char *desc, prs_struct *ps, int depth, DEVICEMODE *devmode)
 {
        prs_debug(ps, depth, desc, "spoolss_io_devmode");
        depth++;
@@ -509,7 +550,7 @@ static BOOL spoolss_io_devmode(char *desc, prs_struct *ps, int depth, DEVICEMODE
                        return False;
        }
 
-       if (!prs_uint16s(True,"devicename", ps, depth, devmode->devicename.buffer, 32))
+       if (!prs_uint16uni(True,"devicename", ps, depth, devmode->devicename.buffer, 32))
                return False;
        if (!prs_uint16("specversion",      ps, depth, &devmode->specversion))
                return False;
@@ -554,7 +595,7 @@ static BOOL spoolss_io_devmode(char *desc, prs_struct *ps, int depth, DEVICEMODE
                        return False;
        }
 
-       if (!prs_uint16s(True, "formname",  ps, depth, devmode->formname.buffer, 32))
+       if (!prs_uint16uni(True, "formname",  ps, depth, devmode->formname.buffer, 32))
                return False;
        if (!prs_uint16("logpixels",        ps, depth, &devmode->logpixels))
                return False;
@@ -587,7 +628,7 @@ static BOOL spoolss_io_devmode(char *desc, prs_struct *ps, int depth, DEVICEMODE
 
        if (devmode->driverextra!=0) {
                if (UNMARSHALLING(ps)) {
-                       devmode->private=(uint8 *)malloc(devmode->driverextra*sizeof(uint8));
+                       devmode->private=(uint8 *)prs_alloc_mem(ps, devmode->driverextra*sizeof(uint8));
                        if(devmode->private == NULL)
                                return False;
                        DEBUG(7,("spoolss_io_devmode: allocated memory [%d] for private\n",devmode->driverextra)); 
@@ -601,18 +642,10 @@ static BOOL spoolss_io_devmode(char *desc, prs_struct *ps, int depth, DEVICEMODE
        return True;
 }
 
-void free_spoolss_devmode(DEVICEMODE *devmode)
-{
-       if (devmode == NULL)
-               return;
-
-       safe_free(devmode->private);
-       safe_free(devmode);
-}
-
 /*******************************************************************
  Read or write a DEVICEMODE container
 ********************************************************************/  
+
 static BOOL spoolss_io_devmode_cont(char *desc, DEVMODE_CTR *dm_c, prs_struct *ps, int depth)
 {
        if (dm_c==NULL)
@@ -640,10 +673,9 @@ static BOOL spoolss_io_devmode_cont(char *desc, DEVMODE_CTR *dm_c, prs_struct *p
        /* so we have a DEVICEMODE to follow */         
        if (UNMARSHALLING(ps)) {
                DEBUG(9,("Allocating memory for spoolss_io_devmode\n"));
-               dm_c->devmode=(DEVICEMODE *)malloc(sizeof(DEVICEMODE));
+               dm_c->devmode=(DEVICEMODE *)prs_alloc_mem(ps,sizeof(DEVICEMODE));
                if(dm_c->devmode == NULL)
                        return False;
-               ZERO_STRUCTP(dm_c->devmode);
        }
        
        /* this is bad code, shouldn't be there */
@@ -658,6 +690,7 @@ static BOOL spoolss_io_devmode_cont(char *desc, DEVMODE_CTR *dm_c, prs_struct *p
 
 /*******************************************************************
 ********************************************************************/  
+
 static BOOL spoolss_io_printer_default(char *desc, PRINTER_DEFAULT *pd, prs_struct *ps, int depth)
 {
        if (pd==NULL)
@@ -669,13 +702,13 @@ static BOOL spoolss_io_printer_default(char *desc, PRINTER_DEFAULT *pd, prs_stru
        if (!prs_uint32("datatype_ptr", ps, depth, &pd->datatype_ptr))
                return False;
 
-       if (!smb_io_unistr2("datatype", &(pd->datatype), pd->datatype_ptr, ps,depth))
+       if (!smb_io_unistr2("datatype", &pd->datatype, pd->datatype_ptr, ps,depth))
                return False;
        
        if (!prs_align(ps))
                return False;
 
-       if (!spoolss_io_devmode_cont("", &(pd->devmode_cont), ps, depth))
+       if (!spoolss_io_devmode_cont("", &pd->devmode_cont, ps, depth))
                return False;
 
        if (!prs_uint32("access_required", ps, depth, &pd->access_required))
@@ -687,6 +720,7 @@ static BOOL spoolss_io_printer_default(char *desc, PRINTER_DEFAULT *pd, prs_stru
 /*******************************************************************
  * init a structure.
  ********************************************************************/
+
 BOOL make_spoolss_q_open_printer_ex(SPOOL_Q_OPEN_PRINTER_EX *q_u,
                const fstring printername, 
                const fstring datatype, 
@@ -696,7 +730,7 @@ BOOL make_spoolss_q_open_printer_ex(SPOOL_Q_OPEN_PRINTER_EX *q_u,
 {
        DEBUG(5,("make_spoolss_q_open_printer_ex\n"));
        q_u->printername_ptr = (printername!=NULL)?1:0;
-       init_unistr2(&q_u->printername, printername, strlen(printername));
+       init_unistr2(&q_u->printername, printername, strlen(printername)+1);
 
        q_u->printer_default.datatype_ptr = 0;
 /*
@@ -710,16 +744,132 @@ BOOL make_spoolss_q_open_printer_ex(SPOOL_Q_OPEN_PRINTER_EX *q_u,
        q_u->user_switch=1;
        q_u->user_ctr.level=1;
        q_u->user_ctr.ptr=1;
-       q_u->user_ctr.user1.size=strlen(clientname)+strlen(user_name)+8;
+       q_u->user_ctr.user1.size=strlen(clientname)+strlen(user_name)+10;
+       q_u->user_ctr.user1.client_name_ptr = (clientname!=NULL)?1:0;
+       q_u->user_ctr.user1.user_name_ptr = (user_name!=NULL)?1:0;
+       q_u->user_ctr.user1.build=1381;
+       q_u->user_ctr.user1.major=2;
+       q_u->user_ctr.user1.minor=0;
+       q_u->user_ctr.user1.processor=0;
+       init_unistr2(&q_u->user_ctr.user1.client_name, clientname, strlen(clientname)+1);
+       init_unistr2(&q_u->user_ctr.user1.user_name, user_name, strlen(user_name)+1);
+       
+       return True;
+}
+
+/*******************************************************************
+ * init a structure.
+ ********************************************************************/
+BOOL make_spoolss_q_addprinterex(
+       TALLOC_CTX *mem_ctx,
+       SPOOL_Q_ADDPRINTEREX *q_u, 
+       const char *srv_name,
+       const char* clientname, 
+       const char* user_name,
+       uint32 level, 
+       PRINTER_INFO_CTR *ctr)
+{
+       DEBUG(5,("make_spoolss_q_addprinterex\n"));
+       
+       if (!ctr) return False;
+
+       q_u->server_name_ptr = (srv_name!=NULL)?1:0;
+       init_unistr2(&q_u->server_name, srv_name, strlen(srv_name));
+
+       q_u->level = level;
+       
+       q_u->info.level = level;
+       q_u->info.info_ptr = (ctr->printers_2!=NULL)?1:0;
+       switch (level)
+       {
+               case 2:
+                       /* init q_u->info.info2 from *info */
+                       if (!make_spoolss_printer_info_2(mem_ctx, &q_u->info.info_2, ctr->printers_2))
+                       {
+                               DEBUG(0,("make_spoolss_q_addprinterex: Unable to fill SPOOL_Q_ADDPRINTEREX struct!\n"));
+                               return False;
+                       }
+                       break;
+               default :
+                       break;
+       }
+
+       q_u->unk0 = q_u->unk1 = q_u->unk2 = q_u->unk3 = 0;
+
+       q_u->user_switch=1;
+
+       q_u->user_ctr.level=1;
+       q_u->user_ctr.ptr=1;
        q_u->user_ctr.user1.client_name_ptr = (clientname!=NULL)?1:0;
        q_u->user_ctr.user1.user_name_ptr = (user_name!=NULL)?1:0;
        q_u->user_ctr.user1.build=1381;
        q_u->user_ctr.user1.major=2;
        q_u->user_ctr.user1.minor=0;
        q_u->user_ctr.user1.processor=0;
-       init_unistr2(&q_u->user_ctr.user1.client_name, clientname, strlen(clientname));
-       init_unistr2(&q_u->user_ctr.user1.user_name, user_name, strlen(user_name));
+       init_unistr2(&q_u->user_ctr.user1.client_name, clientname, strlen(clientname)+1);
+       init_unistr2(&q_u->user_ctr.user1.user_name, user_name, strlen(user_name)+1);
+       q_u->user_ctr.user1.size=q_u->user_ctr.user1.user_name.uni_str_len +
+                                q_u->user_ctr.user1.client_name.uni_str_len + 2;
+       
+       return True;
+}
+       
+/*******************************************************************
+create a SPOOL_PRINTER_INFO_2 stuct from a PRINTER_INFO_2 struct
+*******************************************************************/
+
+BOOL make_spoolss_printer_info_2(
+       TALLOC_CTX *mem_ctx,
+       SPOOL_PRINTER_INFO_LEVEL_2 **spool_info2, 
+       PRINTER_INFO_2 *info
+)
+{
+
+       SPOOL_PRINTER_INFO_LEVEL_2 *inf;
+
+       /* allocate the necessary memory */
+       if (!(inf=(SPOOL_PRINTER_INFO_LEVEL_2*)talloc(mem_ctx, sizeof(SPOOL_PRINTER_INFO_LEVEL_2))))
+       {
+               DEBUG(0,("make_spoolss_printer_info_2: Unable to allocate SPOOL_PRINTER_INFO_LEVEL_2 sruct!\n"));
+               return False;
+       }
        
+       inf->servername_ptr     = (info->servername.buffer!=NULL)?1:0;
+       inf->printername_ptr    = (info->printername.buffer!=NULL)?1:0;
+       inf->sharename_ptr      = (info->sharename.buffer!=NULL)?1:0;
+       inf->portname_ptr       = (info->portname.buffer!=NULL)?1:0;
+       inf->drivername_ptr     = (info->drivername.buffer!=NULL)?1:0;
+       inf->comment_ptr        = (info->comment.buffer!=NULL)?1:0;
+       inf->location_ptr       = (info->location.buffer!=NULL)?1:0;
+       inf->devmode_ptr        = (info->devmode!=NULL)?1:0;
+       inf->sepfile_ptr        = (info->sepfile.buffer!=NULL)?1:0;
+       inf->printprocessor_ptr = (info->printprocessor.buffer!=NULL)?1:0;
+       inf->datatype_ptr       = (info->datatype.buffer!=NULL)?1:0;
+       inf->parameters_ptr     = (info->parameters.buffer!=NULL)?1:0;
+       inf->secdesc_ptr        = (info->secdesc!=NULL)?1:0;
+       inf->attributes         = info->attributes;
+       inf->priority           = info->priority;
+       inf->default_priority   = info->defaultpriority;
+       inf->starttime          = info->starttime;
+       inf->untiltime          = info->untiltime;
+       inf->cjobs              = info->cjobs;
+       inf->averageppm = info->averageppm;
+       init_unistr2_from_unistr(&inf->servername,      &info->servername);
+       init_unistr2_from_unistr(&inf->printername,     &info->printername);
+       init_unistr2_from_unistr(&inf->sharename,       &info->sharename);
+       init_unistr2_from_unistr(&inf->portname,        &info->portname);
+       init_unistr2_from_unistr(&inf->drivername,      &info->drivername);
+       init_unistr2_from_unistr(&inf->comment,         &info->comment);
+       init_unistr2_from_unistr(&inf->location,        &info->location);
+       init_unistr2_from_unistr(&inf->sepfile,         &info->sepfile);
+       init_unistr2_from_unistr(&inf->printprocessor,  &info->printprocessor);
+       init_unistr2_from_unistr(&inf->datatype,        &info->datatype);
+       init_unistr2_from_unistr(&inf->parameters,      &info->parameters);
+       init_unistr2_from_unistr(&inf->datatype,        &info->datatype);
+       inf->secdesc            = inf->secdesc;
+
+       *spool_info2 = inf;
+
        return True;
 }
 
@@ -727,6 +877,7 @@ BOOL make_spoolss_q_open_printer_ex(SPOOL_Q_OPEN_PRINTER_EX *q_u,
  * read a structure.
  * called from spoolss_q_open_printer_ex (srv_spoolss.c)
  ********************************************************************/
+
 BOOL spoolss_io_q_open_printer_ex(char *desc, SPOOL_Q_OPEN_PRINTER_EX *q_u, prs_struct *ps, int depth)
 {
        if (q_u == NULL)
@@ -757,9 +908,29 @@ BOOL spoolss_io_q_open_printer_ex(char *desc, SPOOL_Q_OPEN_PRINTER_EX *q_u, prs_
        return True;
 }
 
-void free_spoolss_q_open_printer_ex(SPOOL_Q_OPEN_PRINTER_EX *q_u)
-{
-       free_spoolss_devmode(q_u->printer_default.devmode_cont.devmode);
+/*******************************************************************
+ * init a structure.
+ ********************************************************************/
+BOOL make_spoolss_q_deleteprinterdriver(
+       TALLOC_CTX *mem_ctx,
+       SPOOL_Q_DELETEPRINTERDRIVER *q_u, 
+       const char *server,
+       const char* arch, 
+       const char* driver 
+)
+{
+       DEBUG(5,("make_spoolss_q_deleteprinterdriver\n"));
+       
+       q_u->server_ptr = (server!=NULL)?1:0;
+
+       /* these must be NULL terminated or else NT4 will
+          complain about invalid parameters --jerry */
+       init_unistr2(&q_u->server, server, strlen(server)+1);
+       init_unistr2(&q_u->arch, arch, strlen(arch)+1);
+       init_unistr2(&q_u->driver, driver, strlen(driver)+1);
+
+       
+       return True;
 }
 
 /*******************************************************************
@@ -767,6 +938,7 @@ void free_spoolss_q_open_printer_ex(SPOOL_Q_OPEN_PRINTER_EX *q_u)
  * called from static spoolss_r_open_printer_ex (srv_spoolss.c)
  * called from spoolss_open_printer_ex (cli_spoolss.c)
  ********************************************************************/
+
 BOOL spoolss_io_r_open_printer_ex(char *desc, SPOOL_R_OPEN_PRINTER_EX *r_u, prs_struct *ps, int depth)
 {
        if (r_u == NULL) return False;
@@ -789,10 +961,10 @@ BOOL spoolss_io_r_open_printer_ex(char *desc, SPOOL_R_OPEN_PRINTER_EX *r_u, prs_
 /*******************************************************************
  * make a structure.
  ********************************************************************/
+
 BOOL make_spoolss_q_getprinterdata(SPOOL_Q_GETPRINTERDATA *q_u,
                                 const POLICY_HND *handle,
-                                const UNISTR2 *valuename,
-                                uint32 size)
+                                UNISTR2 *valuename, uint32 size)
 {
         if (q_u == NULL) return False;
 
@@ -805,29 +977,70 @@ BOOL make_spoolss_q_getprinterdata(SPOOL_Q_GETPRINTERDATA *q_u,
         return True;
 }
 
-
 /*******************************************************************
  * read a structure.
  * called from spoolss_q_getprinterdata (srv_spoolss.c)
  ********************************************************************/
+
 BOOL spoolss_io_q_getprinterdata(char *desc, SPOOL_Q_GETPRINTERDATA *q_u, prs_struct *ps, int depth)
 {
-       if (q_u == NULL) return False;
+       if (q_u == NULL)
+               return False;
 
        prs_debug(ps, depth, desc, "spoolss_io_q_getprinterdata");
        depth++;
 
        if (!prs_align(ps))
                return False;
-       if (!smb_io_pol_hnd("printer handle",&(q_u->handle),ps,depth))
+       if (!smb_io_pol_hnd("printer handle",&q_u->handle,ps,depth))
+               return False;
+       if (!prs_align(ps))
+               return False;
+       if (!smb_io_unistr2("valuename", &q_u->valuename,True,ps,depth))
+               return False;
+       if (!prs_align(ps))
+               return False;
+       if (!prs_uint32("size", ps, depth, &q_u->size))
+               return False;
+
+       return True;
+}
+
+/*******************************************************************
+ * read a structure.
+ * called from spoolss_q_deleteprinterdata (srv_spoolss.c)
+ ********************************************************************/
+
+BOOL spoolss_io_q_deleteprinterdata(char *desc, SPOOL_Q_DELETEPRINTERDATA *q_u, prs_struct *ps, int depth)
+{
+       if (q_u == NULL)
                return False;
+
+       prs_debug(ps, depth, desc, "spoolss_io_q_deleteprinterdata");
+       depth++;
+
        if (!prs_align(ps))
                return False;
-       if (!smb_io_unistr2("valuename", &(q_u->valuename),True,ps,depth))
+       if (!smb_io_pol_hnd("printer handle",&q_u->handle,ps,depth))
                return False;
        if (!prs_align(ps))
                return False;
-       if (!prs_uint32("size", ps, depth, &(q_u->size)))
+       if (!smb_io_unistr2("valuename", &q_u->valuename,True,ps,depth))
+               return False;
+
+       return True;
+}
+
+/*******************************************************************
+ * write a structure.
+ * called from spoolss_r_deleteprinterdata (srv_spoolss.c)
+ ********************************************************************/
+
+BOOL spoolss_io_r_deleteprinterdata(char *desc, SPOOL_R_DELETEPRINTERDATA *r_u, prs_struct *ps, int depth)
+{
+       prs_debug(ps, depth, desc, "spoolss_io_r_deleteprinterdata");
+       depth++;
+       if(!prs_uint32("status", ps, depth, &r_u->status))
                return False;
 
        return True;
@@ -837,6 +1050,7 @@ BOOL spoolss_io_q_getprinterdata(char *desc, SPOOL_Q_GETPRINTERDATA *q_u, prs_st
  * write a structure.
  * called from spoolss_r_getprinterdata (srv_spoolss.c)
  ********************************************************************/
+
 BOOL spoolss_io_r_getprinterdata(char *desc, SPOOL_R_GETPRINTERDATA *r_u, prs_struct *ps, int depth)
 {
        if (r_u == NULL)
@@ -869,13 +1083,51 @@ BOOL spoolss_io_r_getprinterdata(char *desc, SPOOL_R_GETPRINTERDATA *r_u, prs_st
 /*******************************************************************
  * make a structure.
  ********************************************************************/
+
 BOOL make_spoolss_q_closeprinter(SPOOL_Q_CLOSEPRINTER *q_u, POLICY_HND *hnd)
 {
        if (q_u == NULL) return False;
 
        DEBUG(5,("make_spoolss_q_closeprinter\n"));
 
-       memcpy(&(q_u->handle), hnd, sizeof(q_u->handle));
+       memcpy(&q_u->handle, hnd, sizeof(q_u->handle));
+
+       return True;
+}
+
+/*******************************************************************
+ * read a structure.
+ * called from static spoolss_q_abortprinter (srv_spoolss.c)
+ * called from spoolss_abortprinter (cli_spoolss.c)
+ ********************************************************************/
+
+BOOL spoolss_io_q_abortprinter(char *desc, SPOOL_Q_ABORTPRINTER *q_u, prs_struct *ps, int depth)
+{
+       if (q_u == NULL) return False;
+
+       prs_debug(ps, depth, desc, "spoolss_io_q_abortprinter");
+       depth++;
+
+       if (!prs_align(ps))
+               return False;
+
+       if (!smb_io_pol_hnd("printer handle",&q_u->handle,ps,depth))
+               return False;
+
+       return True;
+}
+
+/*******************************************************************
+ * write a structure.
+ * called from spoolss_r_abortprinter (srv_spoolss.c)
+ ********************************************************************/
+
+BOOL spoolss_io_r_abortprinter(char *desc, SPOOL_R_ABORTPRINTER *r_u, prs_struct *ps, int depth)
+{
+       prs_debug(ps, depth, desc, "spoolss_io_r_abortprinter");
+       depth++;
+       if(!prs_uint32("status", ps, depth, &r_u->status))
+               return False;
 
        return True;
 }
@@ -885,6 +1137,7 @@ BOOL make_spoolss_q_closeprinter(SPOOL_Q_CLOSEPRINTER *q_u, POLICY_HND *hnd)
  * called from static spoolss_q_deleteprinter (srv_spoolss.c)
  * called from spoolss_deleteprinter (cli_spoolss.c)
  ********************************************************************/
+
 BOOL spoolss_io_q_deleteprinter(char *desc, SPOOL_Q_DELETEPRINTER *q_u, prs_struct *ps, int depth)
 {
        if (q_u == NULL) return False;
@@ -906,6 +1159,7 @@ BOOL spoolss_io_q_deleteprinter(char *desc, SPOOL_Q_DELETEPRINTER *q_u, prs_stru
  * called from static spoolss_r_deleteprinter (srv_spoolss.c)
  * called from spoolss_deleteprinter (cli_spoolss.c)
  ********************************************************************/
+
 BOOL spoolss_io_r_deleteprinter(char *desc, SPOOL_R_DELETEPRINTER *r_u, prs_struct *ps, int depth)
 {
        prs_debug(ps, depth, desc, "spoolss_io_r_deleteprinter");
@@ -923,11 +1177,63 @@ BOOL spoolss_io_r_deleteprinter(char *desc, SPOOL_R_DELETEPRINTER *r_u, prs_stru
 }
 
 
+/*******************************************************************
+ * read a structure.
+ * called from api_spoolss_deleteprinterdriver (srv_spoolss.c)
+ * called from spoolss_deleteprinterdriver (cli_spoolss.c)
+ ********************************************************************/
+
+BOOL spoolss_io_q_deleteprinterdriver(char *desc, SPOOL_Q_DELETEPRINTERDRIVER *q_u, prs_struct *ps, int depth)
+{
+       if (q_u == NULL) return False;
+
+       prs_debug(ps, depth, desc, "spoolss_io_q_deleteprinterdriver");
+       depth++;
+
+       if (!prs_align(ps))
+               return False;
+
+       if(!prs_uint32("server_ptr", ps, depth, &q_u->server_ptr))
+               return False;           
+       if(!smb_io_unistr2("server", &q_u->server, q_u->server_ptr, ps, depth))
+               return False;
+       if(!smb_io_unistr2("arch", &q_u->arch, True, ps, depth))
+               return False;
+       if(!smb_io_unistr2("driver", &q_u->driver, True, ps, depth))
+               return False;
+
+
+       return True;
+}
+
+
+/*******************************************************************
+ * write a structure.
+ ********************************************************************/
+BOOL spoolss_io_r_deleteprinterdriver(char *desc, SPOOL_R_DELETEPRINTERDRIVER *r_u, prs_struct *ps, int depth)
+{
+       if (r_u == NULL) return False;
+
+       prs_debug(ps, depth, desc, "spoolss_io_r_deleteprinterdriver");
+       depth++;
+
+       if (!prs_align(ps))
+               return False;
+
+       if (!prs_uint32("status", ps, depth, &r_u->status))
+               return False;
+
+       return True;
+}
+
+
+
 /*******************************************************************
  * read a structure.
  * called from static spoolss_q_closeprinter (srv_spoolss.c)
  * called from spoolss_closeprinter (cli_spoolss.c)
  ********************************************************************/
+
 BOOL spoolss_io_q_closeprinter(char *desc, SPOOL_Q_CLOSEPRINTER *q_u, prs_struct *ps, int depth)
 {
        if (q_u == NULL) return False;
@@ -949,6 +1255,7 @@ BOOL spoolss_io_q_closeprinter(char *desc, SPOOL_Q_CLOSEPRINTER *q_u, prs_struct
  * called from static spoolss_r_closeprinter (srv_spoolss.c)
  * called from spoolss_closeprinter (cli_spoolss.c)
  ********************************************************************/
+
 BOOL spoolss_io_r_closeprinter(char *desc, SPOOL_R_CLOSEPRINTER *r_u, prs_struct *ps, int depth)
 {
        prs_debug(ps, depth, desc, "spoolss_io_r_closeprinter");
@@ -969,6 +1276,7 @@ BOOL spoolss_io_r_closeprinter(char *desc, SPOOL_R_CLOSEPRINTER *r_u, prs_struct
  * read a structure.
  * called from spoolss_q_startdocprinter (srv_spoolss.c)
  ********************************************************************/
+
 BOOL spoolss_io_q_startdocprinter(char *desc, SPOOL_Q_STARTDOCPRINTER *q_u, prs_struct *ps, int depth)
 {
        if (q_u == NULL) return False;
@@ -979,10 +1287,10 @@ BOOL spoolss_io_q_startdocprinter(char *desc, SPOOL_Q_STARTDOCPRINTER *q_u, prs_
        if(!prs_align(ps))
                return False;
 
-       if(!smb_io_pol_hnd("printer handle",&(q_u->handle),ps,depth))
+       if(!smb_io_pol_hnd("printer handle",&q_u->handle,ps,depth))
                return False;
        
-       if(!smb_io_doc_info_container("",&(q_u->doc_info_container), ps, depth))
+       if(!smb_io_doc_info_container("",&q_u->doc_info_container, ps, depth))
                return False;
 
        return True;
@@ -992,6 +1300,7 @@ BOOL spoolss_io_q_startdocprinter(char *desc, SPOOL_Q_STARTDOCPRINTER *q_u, prs_
  * write a structure.
  * called from spoolss_r_startdocprinter (srv_spoolss.c)
  ********************************************************************/
+
 BOOL spoolss_io_r_startdocprinter(char *desc, SPOOL_R_STARTDOCPRINTER *r_u, prs_struct *ps, int depth)
 {
        prs_debug(ps, depth, desc, "spoolss_io_r_startdocprinter");
@@ -1008,6 +1317,7 @@ BOOL spoolss_io_r_startdocprinter(char *desc, SPOOL_R_STARTDOCPRINTER *r_u, prs_
  * read a structure.
  * called from spoolss_q_enddocprinter (srv_spoolss.c)
  ********************************************************************/
+
 BOOL spoolss_io_q_enddocprinter(char *desc, SPOOL_Q_ENDDOCPRINTER *q_u, prs_struct *ps, int depth)
 {
        if (q_u == NULL) return False;
@@ -1028,6 +1338,7 @@ BOOL spoolss_io_q_enddocprinter(char *desc, SPOOL_Q_ENDDOCPRINTER *q_u, prs_stru
  * write a structure.
  * called from spoolss_r_enddocprinter (srv_spoolss.c)
  ********************************************************************/
+
 BOOL spoolss_io_r_enddocprinter(char *desc, SPOOL_R_ENDDOCPRINTER *r_u, prs_struct *ps, int depth)
 {
        prs_debug(ps, depth, desc, "spoolss_io_r_enddocprinter");
@@ -1042,6 +1353,7 @@ BOOL spoolss_io_r_enddocprinter(char *desc, SPOOL_R_ENDDOCPRINTER *r_u, prs_stru
  * read a structure.
  * called from spoolss_q_startpageprinter (srv_spoolss.c)
  ********************************************************************/
+
 BOOL spoolss_io_q_startpageprinter(char *desc, SPOOL_Q_STARTPAGEPRINTER *q_u, prs_struct *ps, int depth)
 {
        if (q_u == NULL) return False;
@@ -1062,6 +1374,7 @@ BOOL spoolss_io_q_startpageprinter(char *desc, SPOOL_Q_STARTPAGEPRINTER *q_u, pr
  * write a structure.
  * called from spoolss_r_startpageprinter (srv_spoolss.c)
  ********************************************************************/
+
 BOOL spoolss_io_r_startpageprinter(char *desc, SPOOL_R_STARTPAGEPRINTER *r_u, prs_struct *ps, int depth)
 {
        prs_debug(ps, depth, desc, "spoolss_io_r_startpageprinter");
@@ -1076,6 +1389,7 @@ BOOL spoolss_io_r_startpageprinter(char *desc, SPOOL_R_STARTPAGEPRINTER *r_u, pr
  * read a structure.
  * called from spoolss_q_endpageprinter (srv_spoolss.c)
  ********************************************************************/
+
 BOOL spoolss_io_q_endpageprinter(char *desc, SPOOL_Q_ENDPAGEPRINTER *q_u, prs_struct *ps, int depth)
 {
        if (q_u == NULL) return False;
@@ -1096,6 +1410,7 @@ BOOL spoolss_io_q_endpageprinter(char *desc, SPOOL_Q_ENDPAGEPRINTER *q_u, prs_st
  * write a structure.
  * called from spoolss_r_endpageprinter (srv_spoolss.c)
  ********************************************************************/
+
 BOOL spoolss_io_r_endpageprinter(char *desc, SPOOL_R_ENDPAGEPRINTER *r_u, prs_struct *ps, int depth)
 {
        prs_debug(ps, depth, desc, "spoolss_io_r_endpageprinter");
@@ -1110,6 +1425,7 @@ BOOL spoolss_io_r_endpageprinter(char *desc, SPOOL_R_ENDPAGEPRINTER *r_u, prs_st
  * read a structure.
  * called from spoolss_q_writeprinter (srv_spoolss.c)
  ********************************************************************/
+
 BOOL spoolss_io_q_writeprinter(char *desc, SPOOL_Q_WRITEPRINTER *q_u, prs_struct *ps, int depth)
 {
        if (q_u == NULL) return False;
@@ -1127,7 +1443,8 @@ BOOL spoolss_io_q_writeprinter(char *desc, SPOOL_Q_WRITEPRINTER *q_u, prs_struct
        
        if (q_u->buffer_size!=0)
        {
-               q_u->buffer=(uint8 *)malloc(q_u->buffer_size*sizeof(uint8));
+               if (UNMARSHALLING(ps))
+                       q_u->buffer=(uint8 *)prs_alloc_mem(ps,q_u->buffer_size*sizeof(uint8));
                if(q_u->buffer == NULL)
                        return False;   
                if(!prs_uint8s(True, "buffer", ps, depth, q_u->buffer, q_u->buffer_size))
@@ -1145,6 +1462,7 @@ BOOL spoolss_io_q_writeprinter(char *desc, SPOOL_Q_WRITEPRINTER *q_u, prs_struct
  * write a structure.
  * called from spoolss_r_writeprinter (srv_spoolss.c)
  ********************************************************************/
+
 BOOL spoolss_io_r_writeprinter(char *desc, SPOOL_R_WRITEPRINTER *r_u, prs_struct *ps, int depth)
 {
        prs_debug(ps, depth, desc, "spoolss_io_r_writeprinter");
@@ -1161,6 +1479,7 @@ BOOL spoolss_io_r_writeprinter(char *desc, SPOOL_R_WRITEPRINTER *r_u, prs_struct
  * read a structure.
  * called from spoolss_q_rffpcnex (srv_spoolss.c)
  ********************************************************************/
+
 BOOL spoolss_io_q_rffpcnex(char *desc, SPOOL_Q_RFFPCNEX *q_u, prs_struct *ps, int depth)
 {
        prs_debug(ps, depth, desc, "spoolss_io_q_rffpcnex");
@@ -1192,7 +1511,7 @@ BOOL spoolss_io_q_rffpcnex(char *desc, SPOOL_Q_RFFPCNEX *q_u, prs_struct *ps, in
        if (q_u->option_ptr!=0) {
        
                if (UNMARSHALLING(ps))
-                       if((q_u->option=(SPOOL_NOTIFY_OPTION *)malloc(sizeof(SPOOL_NOTIFY_OPTION))) == NULL)
+                       if((q_u->option=(SPOOL_NOTIFY_OPTION *)prs_alloc_mem(ps,sizeof(SPOOL_NOTIFY_OPTION))) == NULL)
                                return False;
        
                if(!smb_io_notify_option("notify option", q_u->option, ps, depth))
@@ -1206,6 +1525,7 @@ BOOL spoolss_io_q_rffpcnex(char *desc, SPOOL_Q_RFFPCNEX *q_u, prs_struct *ps, in
  * write a structure.
  * called from spoolss_r_rffpcnex (srv_spoolss.c)
  ********************************************************************/
+
 BOOL spoolss_io_r_rffpcnex(char *desc, SPOOL_R_RFFPCNEX *r_u, prs_struct *ps, int depth)
 {
        prs_debug(ps, depth, desc, "spoolss_io_r_rffpcnex");
@@ -1221,6 +1541,7 @@ BOOL spoolss_io_r_rffpcnex(char *desc, SPOOL_R_RFFPCNEX *r_u, prs_struct *ps, in
  * read a structure.
  * called from spoolss_q_rfnpcnex (srv_spoolss.c)
  ********************************************************************/
+
 BOOL spoolss_io_q_rfnpcnex(char *desc, SPOOL_Q_RFNPCNEX *q_u, prs_struct *ps, int depth)
 {
        prs_debug(ps, depth, desc, "spoolss_io_q_rfnpcnex");
@@ -1241,7 +1562,7 @@ BOOL spoolss_io_q_rfnpcnex(char *desc, SPOOL_Q_RFNPCNEX *q_u, prs_struct *ps, in
        if (q_u->option_ptr!=0) {
        
                if (UNMARSHALLING(ps))
-                       if((q_u->option=(SPOOL_NOTIFY_OPTION *)malloc(sizeof(SPOOL_NOTIFY_OPTION))) == NULL)
+                       if((q_u->option=(SPOOL_NOTIFY_OPTION *)prs_alloc_mem(ps,sizeof(SPOOL_NOTIFY_OPTION))) == NULL)
                                return False;
        
                if(!smb_io_notify_option("notify option", q_u->option, ps, depth))
@@ -1255,6 +1576,7 @@ BOOL spoolss_io_q_rfnpcnex(char *desc, SPOOL_Q_RFNPCNEX *q_u, prs_struct *ps, in
  * write a structure.
  * called from spoolss_r_rfnpcnex (srv_spoolss.c)
  ********************************************************************/
+
 BOOL spoolss_io_r_rfnpcnex(char *desc, SPOOL_R_RFNPCNEX *r_u, prs_struct *ps, int depth)
 {
        prs_debug(ps, depth, desc, "spoolss_io_r_rfnpcnex");
@@ -1280,6 +1602,7 @@ BOOL spoolss_io_r_rfnpcnex(char *desc, SPOOL_R_RFNPCNEX *r_u, prs_struct *ps, in
 /*******************************************************************
  * return the length of a uint16 (obvious, but the code is clean)
  ********************************************************************/
+
 static uint32 size_of_uint16(uint16 *value)
 {
        return (sizeof(*value));
@@ -1288,15 +1611,27 @@ static uint32 size_of_uint16(uint16 *value)
 /*******************************************************************
  * return the length of a uint32 (obvious, but the code is clean)
  ********************************************************************/
+
 static uint32 size_of_uint32(uint32 *value)
 {
        return (sizeof(*value));
 }
+
+/*******************************************************************
+ * return the length of a NTTIME (obvious, but the code is clean)
+ ********************************************************************/
+
+static uint32 size_of_nttime(NTTIME *value)
+{
+       return (sizeof(*value));
+}
+
 /*******************************************************************
  * return the length of a UNICODE string in number of char, includes:
  * - the leading zero
  * - the relative pointer size
  ********************************************************************/
+
 static uint32 size_of_relative_string(UNISTR *string)
 {
        uint32 size=0;
@@ -1304,6 +1639,8 @@ static uint32 size_of_relative_string(UNISTR *string)
        size=str_len_uni(string);       /* the string length       */
        size=size+1;                    /* add the leading zero    */
        size=size*2;                    /* convert in char         */
+       /* Ensure size is 4 byte multiple (prs_align is being called...). */
+       size += ((4 - (size & 3)) & 3);
        size=size+4;                    /* add the size of the ptr */   
 
        return size;
@@ -1312,6 +1649,7 @@ static uint32 size_of_relative_string(UNISTR *string)
 /*******************************************************************
  * return the length of a uint32 (obvious, but the code is clean)
  ********************************************************************/
+
 static uint32 size_of_device_mode(DEVICEMODE *devmode)
 {
        if (devmode==NULL)
@@ -1323,6 +1661,7 @@ static uint32 size_of_device_mode(DEVICEMODE *devmode)
 /*******************************************************************
  * return the length of a uint32 (obvious, but the code is clean)
  ********************************************************************/
+
 static uint32 size_of_systemtime(SYSTEMTIME *systime)
 {
        if (systime==NULL)
@@ -1335,6 +1674,7 @@ static uint32 size_of_systemtime(SYSTEMTIME *systime)
  * write a UNICODE string.
  * used by all the RPC structs passing a buffer
  ********************************************************************/
+
 static BOOL spoolss_smb_io_unistr(char *desc, UNISTR *uni, prs_struct *ps, int depth)
 {
        if (uni == NULL)
@@ -1342,13 +1682,20 @@ static BOOL spoolss_smb_io_unistr(char *desc, UNISTR *uni, prs_struct *ps, int d
 
        prs_debug(ps, depth, desc, "spoolss_smb_io_unistr");
        depth++;
+       
+       /* there should be no align here as it can mess up
+          parsing a NEW_BUFFER->prs */
+#if 0  /* JERRY */
+       if (!prs_align(ps))
+               return False;
+#endif
+               
        if (!prs_unistr("unistr", ps, depth, uni))
                return False;
 
        return True;
 }
 
-
 /*******************************************************************
  * write a UNICODE string and its relative pointer.
  * used by all the RPC structs passing a buffer
@@ -1368,7 +1715,8 @@ static BOOL spoolss_smb_io_unistr(char *desc, UNISTR *uni, prs_struct *ps, int d
  * first get in touch with me: jfm@samba.org
  *
  ********************************************************************/
-static BOOL new_smb_io_relstr(char *desc, NEW_BUFFER *buffer, int depth, UNISTR *string)
+
+static BOOL smb_io_relstr(char *desc, NEW_BUFFER *buffer, int depth, UNISTR *string)
 {
        prs_struct *ps=&buffer->prs;
        
@@ -1376,12 +1724,15 @@ static BOOL new_smb_io_relstr(char *desc, NEW_BUFFER *buffer, int depth, UNISTR
                uint32 struct_offset = prs_offset(ps);
                uint32 relative_offset;
                
-               buffer->string_at_end -= 2*(str_len_uni(string)+1);
+               buffer->string_at_end -= (size_of_relative_string(string) - 4);
                if(!prs_set_offset(ps, buffer->string_at_end))
                        return False;
+               if (!prs_align(ps))
+                       return False;
+               buffer->string_at_end = prs_offset(ps);
                
                /* write the string */
-               if (!spoolss_smb_io_unistr(desc, string, ps, depth))
+               if (!smb_io_unistr(desc, string, ps, depth))
                        return False;
 
                if(!prs_set_offset(ps, struct_offset))
@@ -1413,12 +1764,12 @@ static BOOL new_smb_io_relstr(char *desc, NEW_BUFFER *buffer, int depth, UNISTR
        return True;
 }
 
-
 /*******************************************************************
  * write a array of UNICODE strings and its relative pointer.
  * used by 2 RPC structs
  ********************************************************************/
-static BOOL new_smb_io_relarraystr(char *desc, NEW_BUFFER *buffer, int depth, uint16 **string)
+
+static BOOL smb_io_relarraystr(char *desc, NEW_BUFFER *buffer, int depth, uint16 **string)
 {
        UNISTR chaine;
        
@@ -1445,6 +1796,8 @@ static BOOL new_smb_io_relarraystr(char *desc, NEW_BUFFER *buffer, int depth, ui
                        while (*q!=0)
                                q++;
 
+                       /* Yes this should be malloc not talloc. Don't change. */
+
                        chaine.buffer = malloc((q-p+1)*sizeof(uint16));
                        if (chaine.buffer == NULL)
                                return False;
@@ -1476,13 +1829,17 @@ static BOOL new_smb_io_relarraystr(char *desc, NEW_BUFFER *buffer, int depth, ui
                /* write its offset */
                if (!prs_uint32("offset", ps, depth, &relative_offset))
                        return False;
-       }
-       else {
+
+       } else {
+
+               /* UNMARSHALLING */
+
                uint32 old_offset;
                uint16 *chaine2=NULL;
                int l_chaine=0;
                int l_chaine2=0;
-               
+               size_t realloc_size = 0;
+
                *string=NULL;
                                
                /* read the offset */
@@ -1498,14 +1855,37 @@ static BOOL new_smb_io_relarraystr(char *desc, NEW_BUFFER *buffer, int depth, ui
                                return False;
                        
                        l_chaine=str_len_uni(&chaine);
-                       if((chaine2=(uint16 *)Realloc(chaine2, (l_chaine2+l_chaine+1)*sizeof(uint16))) == NULL)
-                               return False;
-                       memcpy(chaine2+l_chaine2, chaine.buffer, (l_chaine+1)*sizeof(uint16));
-                       l_chaine2+=l_chaine+1;
+                       
+                       /* we're going to add two more bytes here in case this
+                          is the last string in the array and we need to add 
+                          an extra NULL for termination */
+                       if (l_chaine > 0)
+                       {
+                               uint16 *tc2;
+                       
+                               realloc_size = (l_chaine2+l_chaine+2)*sizeof(uint16);
+
+                               /* Yes this should be realloc - it's freed below. JRA */
+
+                               if((tc2=(uint16 *)Realloc(chaine2, realloc_size)) == NULL) {
+                                       if (chaine2) free(chaine2);
+                                       return False;
+                               }
+                               else chaine2 = tc2;
+                               memcpy(chaine2+l_chaine2, chaine.buffer, (l_chaine+1)*sizeof(uint16));
+                               l_chaine2+=l_chaine+1;
+                       }
                
                } while(l_chaine!=0);
                
-               *string=chaine2;
+               /* the end should be bould NULL terminated so add 
+                  the second one here */
+               if (chaine2)
+               {
+                       chaine2[l_chaine2] = '\0';
+                       *string=(uint16 *)talloc_memdup(prs_get_mem_context(ps),chaine2,realloc_size);
+                       free(chaine2);
+               }
 
                if(!prs_set_offset(ps, old_offset))
                        return False;
@@ -1513,16 +1893,15 @@ static BOOL new_smb_io_relarraystr(char *desc, NEW_BUFFER *buffer, int depth, ui
        return True;
 }
 
-
 /*******************************************************************
  Parse a DEVMODE structure and its relative pointer.
 ********************************************************************/
-static BOOL new_smb_io_relsecdesc(char *desc, NEW_BUFFER *buffer, int depth,
-               SEC_DESC **secdesc)
+
+static BOOL smb_io_relsecdesc(char *desc, NEW_BUFFER *buffer, int depth, SEC_DESC **secdesc)
 {
        prs_struct *ps= &buffer->prs;
 
-       prs_debug(ps, depth, desc, "new_smb_io_relsecdesc");
+       prs_debug(ps, depth, desc, "smb_io_relsecdesc");
        depth++;
 
        if (MARSHALLING(ps)) {
@@ -1537,15 +1916,10 @@ static BOOL new_smb_io_relsecdesc(char *desc, NEW_BUFFER *buffer, int depth,
                }
                
                if (*secdesc != NULL) {
-#if 0 /* JRATEST */
-                       if(!prs_set_offset(ps, 0x54))
-                               return False;
-#else
                        buffer->string_at_end -= sec_desc_size(*secdesc);
 
                        if(!prs_set_offset(ps, buffer->string_at_end))
                                return False;
-#endif
                        /* write the secdesc */
                        if (!sec_io_desc(desc, secdesc, ps, depth))
                                return False;
@@ -1556,9 +1930,6 @@ static BOOL new_smb_io_relsecdesc(char *desc, NEW_BUFFER *buffer, int depth,
 
                relative_offset=buffer->string_at_end - buffer->struct_start;
                /* write its offset */
-#if 0 /* JRATEST */
-               relative_offset = 0x54;
-#endif
 
                if (!prs_uint32("offset", ps, depth, &relative_offset))
                        return False;
@@ -1586,11 +1957,12 @@ static BOOL new_smb_io_relsecdesc(char *desc, NEW_BUFFER *buffer, int depth,
 /*******************************************************************
  Parse a DEVMODE structure and its relative pointer.
 ********************************************************************/
-static BOOL new_smb_io_reldevmode(char *desc, NEW_BUFFER *buffer, int depth, DEVICEMODE **devmode)
+
+static BOOL smb_io_reldevmode(char *desc, NEW_BUFFER *buffer, int depth, DEVICEMODE **devmode)
 {
        prs_struct *ps=&buffer->prs;
 
-       prs_debug(ps, depth, desc, "new_smb_io_reldevmode");
+       prs_debug(ps, depth, desc, "smb_io_reldevmode");
        depth++;
 
        if (MARSHALLING(ps)) {
@@ -1635,7 +2007,7 @@ static BOOL new_smb_io_reldevmode(char *desc, NEW_BUFFER *buffer, int depth, DEV
                        return False;
 
                /* read the string */
-               if((*devmode=(DEVICEMODE *)malloc(sizeof(DEVICEMODE))) == NULL)
+               if((*devmode=(DEVICEMODE *)prs_alloc_mem(ps,sizeof(DEVICEMODE))) == NULL)
                        return False;
                if (!spoolss_io_devmode(desc, ps, depth, *devmode))
                        return False;
@@ -1646,22 +2018,22 @@ static BOOL new_smb_io_reldevmode(char *desc, NEW_BUFFER *buffer, int depth, DEV
        return True;
 }
 
-
 /*******************************************************************
  Parse a PRINTER_INFO_0 structure.
 ********************************************************************/  
-BOOL new_smb_io_printer_info_0(char *desc, NEW_BUFFER *buffer, PRINTER_INFO_0 *info, int depth)
+
+BOOL smb_io_printer_info_0(char *desc, NEW_BUFFER *buffer, PRINTER_INFO_0 *info, int depth)
 {
-       prs_struct *ps=&(buffer->prs);
+       prs_struct *ps=&buffer->prs;
 
        prs_debug(ps, depth, desc, "smb_io_printer_info_0");
        depth++;        
        
        buffer->struct_start=prs_offset(ps);
 
-       if (!new_smb_io_relstr("printername", buffer, depth, &info->printername))
+       if (!smb_io_relstr("printername", buffer, depth, &info->printername))
                return False;
-       if (!new_smb_io_relstr("servername", buffer, depth, &info->servername))
+       if (!smb_io_relstr("servername", buffer, depth, &info->servername))
                return False;
        
        if(!prs_uint32("cjobs", ps, depth, &info->cjobs))
@@ -1750,22 +2122,23 @@ BOOL new_smb_io_printer_info_0(char *desc, NEW_BUFFER *buffer, PRINTER_INFO_0 *i
 /*******************************************************************
  Parse a PRINTER_INFO_1 structure.
 ********************************************************************/  
-BOOL new_smb_io_printer_info_1(char *desc, NEW_BUFFER *buffer, PRINTER_INFO_1 *info, int depth)
+
+BOOL smb_io_printer_info_1(char *desc, NEW_BUFFER *buffer, PRINTER_INFO_1 *info, int depth)
 {
        prs_struct *ps=&buffer->prs;
 
-       prs_debug(ps, depth, desc, "new_smb_io_printer_info_1");
+       prs_debug(ps, depth, desc, "smb_io_printer_info_1");
        depth++;        
        
        buffer->struct_start=prs_offset(ps);
 
        if (!prs_uint32("flags", ps, depth, &info->flags))
                return False;
-       if (!new_smb_io_relstr("description", buffer, depth, &info->description))
+       if (!smb_io_relstr("description", buffer, depth, &info->description))
                return False;
-       if (!new_smb_io_relstr("name", buffer, depth, &info->name))
+       if (!smb_io_relstr("name", buffer, depth, &info->name))
                return False;
-       if (!new_smb_io_relstr("comment", buffer, depth, &info->comment))
+       if (!smb_io_relstr("comment", buffer, depth, &info->comment))
                return False;   
 
        return True;
@@ -1774,52 +2147,46 @@ BOOL new_smb_io_printer_info_1(char *desc, NEW_BUFFER *buffer, PRINTER_INFO_1 *i
 /*******************************************************************
  Parse a PRINTER_INFO_2 structure.
 ********************************************************************/  
-BOOL new_smb_io_printer_info_2(char *desc, NEW_BUFFER *buffer, PRINTER_INFO_2 *info, int depth)
+
+BOOL smb_io_printer_info_2(char *desc, NEW_BUFFER *buffer, PRINTER_INFO_2 *info, int depth)
 {
-       uint32 sec_offset;
        prs_struct *ps=&buffer->prs;
-       uint32 dummy = 0;
 
-       prs_debug(ps, depth, desc, "new_smb_io_printer_info_2");
+       prs_debug(ps, depth, desc, "smb_io_printer_info_2");
        depth++;        
        
        buffer->struct_start=prs_offset(ps);
        
-       if (!new_smb_io_relstr("servername", buffer, depth, &info->servername))
+       if (!smb_io_relstr("servername", buffer, depth, &info->servername))
                return False;
-       if (!new_smb_io_relstr("printername", buffer, depth, &info->printername))
+       if (!smb_io_relstr("printername", buffer, depth, &info->printername))
                return False;
-       if (!new_smb_io_relstr("sharename", buffer, depth, &info->sharename))
+       if (!smb_io_relstr("sharename", buffer, depth, &info->sharename))
                return False;
-       if (!new_smb_io_relstr("portname", buffer, depth, &info->portname))
+       if (!smb_io_relstr("portname", buffer, depth, &info->portname))
                return False;
-       if (!new_smb_io_relstr("drivername", buffer, depth, &info->drivername))
+       if (!smb_io_relstr("drivername", buffer, depth, &info->drivername))
                return False;
-       if (!new_smb_io_relstr("comment", buffer, depth, &info->comment))
+       if (!smb_io_relstr("comment", buffer, depth, &info->comment))
                return False;
-       if (!new_smb_io_relstr("location", buffer, depth, &info->location))
+       if (!smb_io_relstr("location", buffer, depth, &info->location))
                return False;
 
        /* NT parses the DEVMODE at the end of the struct */
-       if (!new_smb_io_reldevmode("devmode", buffer, depth, &info->devmode))
+       if (!smb_io_reldevmode("devmode", buffer, depth, &info->devmode))
                return False;
        
-       if (!new_smb_io_relstr("sepfile", buffer, depth, &info->sepfile))
+       if (!smb_io_relstr("sepfile", buffer, depth, &info->sepfile))
                return False;
-       if (!new_smb_io_relstr("printprocessor", buffer, depth, &info->printprocessor))
+       if (!smb_io_relstr("printprocessor", buffer, depth, &info->printprocessor))
                return False;
-       if (!new_smb_io_relstr("datatype", buffer, depth, &info->datatype))
+       if (!smb_io_relstr("datatype", buffer, depth, &info->datatype))
                return False;
-       if (!new_smb_io_relstr("parameters", buffer, depth, &info->parameters))
+       if (!smb_io_relstr("parameters", buffer, depth, &info->parameters))
                return False;
 
-#if 0 /* JFMTEST */
-       if (!prs_uint32_pre("secdesc_ptr ", ps, depth, &dummy, &sec_offset))
+       if (!smb_io_relsecdesc("secdesc", buffer, depth, &info->secdesc))
                return False;
-#else
-       if (!new_smb_io_relsecdesc("secdesc", buffer, depth, &info->secdesc))
-               return False;
-#endif
 
        if (!prs_uint32("attributes", ps, depth, &info->attributes))
                return False;
@@ -1851,11 +2218,12 @@ BOOL new_smb_io_printer_info_2(char *desc, NEW_BUFFER *buffer, PRINTER_INFO_2 *i
 /*******************************************************************
  Parse a PRINTER_INFO_3 structure.
 ********************************************************************/  
-BOOL new_smb_io_printer_info_3(char *desc, NEW_BUFFER *buffer, PRINTER_INFO_3 *info, int depth)
+
+BOOL smb_io_printer_info_3(char *desc, NEW_BUFFER *buffer, PRINTER_INFO_3 *info, int depth)
 {
-       prs_struct *ps=&(buffer->prs);
+       prs_struct *ps=&buffer->prs;
 
-       prs_debug(ps, depth, desc, "new_smb_io_printer_info_3");
+       prs_debug(ps, depth, desc, "smb_io_printer_info_3");
        depth++;        
        
        buffer->struct_start=prs_offset(ps);
@@ -1871,16 +2239,17 @@ BOOL new_smb_io_printer_info_3(char *desc, NEW_BUFFER *buffer, PRINTER_INFO_3 *i
 /*******************************************************************
  Parse a PORT_INFO_1 structure.
 ********************************************************************/  
-BOOL new_smb_io_port_info_1(char *desc, NEW_BUFFER *buffer, PORT_INFO_1 *info, int depth)
+
+BOOL smb_io_port_info_1(char *desc, NEW_BUFFER *buffer, PORT_INFO_1 *info, int depth)
 {
-       prs_struct *ps=&(buffer->prs);
+       prs_struct *ps=&buffer->prs;
 
-       prs_debug(ps, depth, desc, "new_smb_io_port_info_1");
+       prs_debug(ps, depth, desc, "smb_io_port_info_1");
        depth++;        
        
        buffer->struct_start=prs_offset(ps);
        
-       if (!new_smb_io_relstr("port_name", buffer, depth, &info->port_name))
+       if (!smb_io_relstr("port_name", buffer, depth, &info->port_name))
                return False;
 
        return True;
@@ -1889,20 +2258,21 @@ BOOL new_smb_io_port_info_1(char *desc, NEW_BUFFER *buffer, PORT_INFO_1 *info, i
 /*******************************************************************
  Parse a PORT_INFO_2 structure.
 ********************************************************************/  
-BOOL new_smb_io_port_info_2(char *desc, NEW_BUFFER *buffer, PORT_INFO_2 *info, int depth)
+
+BOOL smb_io_port_info_2(char *desc, NEW_BUFFER *buffer, PORT_INFO_2 *info, int depth)
 {
-       prs_struct *ps=&(buffer->prs);
+       prs_struct *ps=&buffer->prs;
 
-       prs_debug(ps, depth, desc, "new_smb_io_port_info_2");
+       prs_debug(ps, depth, desc, "smb_io_port_info_2");
        depth++;        
        
        buffer->struct_start=prs_offset(ps);
        
-       if (!new_smb_io_relstr("port_name", buffer, depth, &info->port_name))
+       if (!smb_io_relstr("port_name", buffer, depth, &info->port_name))
                return False;
-       if (!new_smb_io_relstr("monitor_name", buffer, depth, &info->monitor_name))
+       if (!smb_io_relstr("monitor_name", buffer, depth, &info->monitor_name))
                return False;
-       if (!new_smb_io_relstr("description", buffer, depth, &info->description))
+       if (!smb_io_relstr("description", buffer, depth, &info->description))
                return False;
        if (!prs_uint32("port_type", ps, depth, &info->port_type))
                return False;
@@ -1915,115 +2285,181 @@ BOOL new_smb_io_port_info_2(char *desc, NEW_BUFFER *buffer, PORT_INFO_2 *info, i
 /*******************************************************************
  Parse a DRIVER_INFO_1 structure.
 ********************************************************************/
-BOOL new_smb_io_printer_driver_info_1(char *desc, NEW_BUFFER *buffer, DRIVER_INFO_1 *info, int depth) 
+
+BOOL smb_io_printer_driver_info_1(char *desc, NEW_BUFFER *buffer, DRIVER_INFO_1 *info, int depth) 
 {
-       prs_struct *ps=&(buffer->prs);
+       prs_struct *ps=&buffer->prs;
 
-       prs_debug(ps, depth, desc, "new_smb_io_printer_driver_info_1");
+       prs_debug(ps, depth, desc, "smb_io_printer_driver_info_1");
        depth++;        
        
        buffer->struct_start=prs_offset(ps);
 
-       if (!new_smb_io_relstr("name", buffer, depth, &info->name))
+       if (!smb_io_relstr("name", buffer, depth, &info->name))
                return False;
 
        return True;
 }
 
-
 /*******************************************************************
  Parse a DRIVER_INFO_2 structure.
 ********************************************************************/
-BOOL new_smb_io_printer_driver_info_2(char *desc, NEW_BUFFER *buffer, DRIVER_INFO_2 *info, int depth) 
+
+BOOL smb_io_printer_driver_info_2(char *desc, NEW_BUFFER *buffer, DRIVER_INFO_2 *info, int depth) 
 {
-       prs_struct *ps=&(buffer->prs);
+       prs_struct *ps=&buffer->prs;
 
-       prs_debug(ps, depth, desc, "new_smb_io_printer_driver_info_2");
+       prs_debug(ps, depth, desc, "smb_io_printer_driver_info_2");
        depth++;        
        
        buffer->struct_start=prs_offset(ps);
 
        if (!prs_uint32("version", ps, depth, &info->version))
                return False;
-       if (!new_smb_io_relstr("name", buffer, depth, &info->name))
+       if (!smb_io_relstr("name", buffer, depth, &info->name))
                return False;
-       if (!new_smb_io_relstr("architecture", buffer, depth, &info->architecture))
+       if (!smb_io_relstr("architecture", buffer, depth, &info->architecture))
                return False;
-       if (!new_smb_io_relstr("driverpath", buffer, depth, &info->driverpath))
+       if (!smb_io_relstr("driverpath", buffer, depth, &info->driverpath))
                return False;
-       if (!new_smb_io_relstr("datafile", buffer, depth, &info->datafile))
+       if (!smb_io_relstr("datafile", buffer, depth, &info->datafile))
                return False;
-       if (!new_smb_io_relstr("configfile", buffer, depth, &info->configfile))
+       if (!smb_io_relstr("configfile", buffer, depth, &info->configfile))
                return False;
 
        return True;
 }
 
-
 /*******************************************************************
  Parse a DRIVER_INFO_3 structure.
 ********************************************************************/
-BOOL new_smb_io_printer_driver_info_3(char *desc, NEW_BUFFER *buffer, DRIVER_INFO_3 *info, int depth)
+
+BOOL smb_io_printer_driver_info_3(char *desc, NEW_BUFFER *buffer, DRIVER_INFO_3 *info, int depth)
 {
-       prs_struct *ps=&(buffer->prs);
+       prs_struct *ps=&buffer->prs;
 
-       prs_debug(ps, depth, desc, "new_smb_io_printer_driver_info_3");
+       prs_debug(ps, depth, desc, "smb_io_printer_driver_info_3");
        depth++;        
        
        buffer->struct_start=prs_offset(ps);
 
        if (!prs_uint32("version", ps, depth, &info->version))
                return False;
-       if (!new_smb_io_relstr("name", buffer, depth, &info->name))
+       if (!smb_io_relstr("name", buffer, depth, &info->name))
                return False;
-       if (!new_smb_io_relstr("architecture", buffer, depth, &info->architecture))
+       if (!smb_io_relstr("architecture", buffer, depth, &info->architecture))
                return False;
-       if (!new_smb_io_relstr("driverpath", buffer, depth, &info->driverpath))
+       if (!smb_io_relstr("driverpath", buffer, depth, &info->driverpath))
                return False;
-       if (!new_smb_io_relstr("datafile", buffer, depth, &info->datafile))
+       if (!smb_io_relstr("datafile", buffer, depth, &info->datafile))
                return False;
-       if (!new_smb_io_relstr("configfile", buffer, depth, &info->configfile))
+       if (!smb_io_relstr("configfile", buffer, depth, &info->configfile))
                return False;
-       if (!new_smb_io_relstr("helpfile", buffer, depth, &info->helpfile))
+       if (!smb_io_relstr("helpfile", buffer, depth, &info->helpfile))
                return False;
 
-       if (!new_smb_io_relarraystr("dependentfiles", buffer, depth, &info->dependentfiles))
+       if (!smb_io_relarraystr("dependentfiles", buffer, depth, &info->dependentfiles))
                return False;
 
-       if (!new_smb_io_relstr("monitorname", buffer, depth, &info->monitorname))
+       if (!smb_io_relstr("monitorname", buffer, depth, &info->monitorname))
                return False;
-       if (!new_smb_io_relstr("defaultdatatype", buffer, depth, &info->defaultdatatype))
+       if (!smb_io_relstr("defaultdatatype", buffer, depth, &info->defaultdatatype))
                return False;
 
        return True;
 }
 
+/*******************************************************************
+ Parse a DRIVER_INFO_6 structure.
+********************************************************************/
+
+BOOL smb_io_printer_driver_info_6(char *desc, NEW_BUFFER *buffer, DRIVER_INFO_6 *info, int depth)
+{
+       prs_struct *ps=&buffer->prs;
+
+       prs_debug(ps, depth, desc, "smb_io_printer_driver_info_6");
+       depth++;        
+       
+       buffer->struct_start=prs_offset(ps);
+
+       if (!prs_uint32("version", ps, depth, &info->version))
+               return False;
+       if (!smb_io_relstr("name", buffer, depth, &info->name))
+               return False;
+       if (!smb_io_relstr("architecture", buffer, depth, &info->architecture))
+               return False;
+       if (!smb_io_relstr("driverpath", buffer, depth, &info->driverpath))
+               return False;
+       if (!smb_io_relstr("datafile", buffer, depth, &info->datafile))
+               return False;
+       if (!smb_io_relstr("configfile", buffer, depth, &info->configfile))
+               return False;
+       if (!smb_io_relstr("helpfile", buffer, depth, &info->helpfile))
+               return False;
+
+       if (!smb_io_relarraystr("dependentfiles", buffer, depth, &info->dependentfiles))
+               return False;
+
+       if (!smb_io_relstr("monitorname", buffer, depth, &info->monitorname))
+               return False;
+       if (!smb_io_relstr("defaultdatatype", buffer, depth, &info->defaultdatatype))
+               return False;
+
+       if (!smb_io_relarraystr("previousdrivernames", buffer, depth, &info->previousdrivernames))
+               return False;
+
+       if (!prs_uint32("date.low", ps, depth, &info->driver_date.low))
+               return False;
+       if (!prs_uint32("date.high", ps, depth, &info->driver_date.high))
+               return False;
+
+       if (!prs_uint32("padding", ps, depth, &info->padding))
+               return False;
+
+       if (!prs_uint32("driver_version_low", ps, depth, &info->driver_version_low))
+               return False;
+
+       if (!prs_uint32("driver_version_high", ps, depth, &info->driver_version_high))
+               return False;
+
+       if (!smb_io_relstr("mfgname", buffer, depth, &info->mfgname))
+               return False;
+       if (!smb_io_relstr("oem_url", buffer, depth, &info->oem_url))
+               return False;
+       if (!smb_io_relstr("hardware_id", buffer, depth, &info->hardware_id))
+               return False;
+       if (!smb_io_relstr("provider", buffer, depth, &info->provider))
+               return False;
+       
+       return True;
+}
 
 /*******************************************************************
  Parse a JOB_INFO_1 structure.
 ********************************************************************/  
-BOOL new_smb_io_job_info_1(char *desc, NEW_BUFFER *buffer, JOB_INFO_1 *info, int depth)
+
+BOOL smb_io_job_info_1(char *desc, NEW_BUFFER *buffer, JOB_INFO_1 *info, int depth)
 {
-       prs_struct *ps=&(buffer->prs);
+       prs_struct *ps=&buffer->prs;
 
-       prs_debug(ps, depth, desc, "new_smb_io_job_info_1");
+       prs_debug(ps, depth, desc, "smb_io_job_info_1");
        depth++;        
        
        buffer->struct_start=prs_offset(ps);
 
        if (!prs_uint32("jobid", ps, depth, &info->jobid))
                return False;
-       if (!new_smb_io_relstr("printername", buffer, depth, &info->printername))
+       if (!smb_io_relstr("printername", buffer, depth, &info->printername))
                return False;
-       if (!new_smb_io_relstr("machinename", buffer, depth, &info->machinename))
+       if (!smb_io_relstr("machinename", buffer, depth, &info->machinename))
                return False;
-       if (!new_smb_io_relstr("username", buffer, depth, &info->username))
+       if (!smb_io_relstr("username", buffer, depth, &info->username))
                return False;
-       if (!new_smb_io_relstr("document", buffer, depth, &info->document))
+       if (!smb_io_relstr("document", buffer, depth, &info->document))
                return False;
-       if (!new_smb_io_relstr("datatype", buffer, depth, &info->datatype))
+       if (!smb_io_relstr("datatype", buffer, depth, &info->datatype))
                return False;
-       if (!new_smb_io_relstr("text_status", buffer, depth, &info->text_status))
+       if (!smb_io_relstr("text_status", buffer, depth, &info->text_status))
                return False;
        if (!prs_uint32("status", ps, depth, &info->status))
                return False;
@@ -2044,40 +2480,41 @@ BOOL new_smb_io_job_info_1(char *desc, NEW_BUFFER *buffer, JOB_INFO_1 *info, int
 /*******************************************************************
  Parse a JOB_INFO_2 structure.
 ********************************************************************/  
-BOOL new_smb_io_job_info_2(char *desc, NEW_BUFFER *buffer, JOB_INFO_2 *info, int depth)
+
+BOOL smb_io_job_info_2(char *desc, NEW_BUFFER *buffer, JOB_INFO_2 *info, int depth)
 {      
-       uint pipo=0;
-       prs_struct *ps=&(buffer->prs);
+       uint32 pipo=0;
+       prs_struct *ps=&buffer->prs;
        
-       prs_debug(ps, depth, desc, "new_smb_io_job_info_2");
+       prs_debug(ps, depth, desc, "smb_io_job_info_2");
        depth++;        
 
        buffer->struct_start=prs_offset(ps);
        
        if (!prs_uint32("jobid",ps, depth, &info->jobid))
                return False;
-       if (!new_smb_io_relstr("printername", buffer, depth, &info->printername))
+       if (!smb_io_relstr("printername", buffer, depth, &info->printername))
                return False;
-       if (!new_smb_io_relstr("machinename", buffer, depth, &info->machinename))
+       if (!smb_io_relstr("machinename", buffer, depth, &info->machinename))
                return False;
-       if (!new_smb_io_relstr("username", buffer, depth, &info->username))
+       if (!smb_io_relstr("username", buffer, depth, &info->username))
                return False;
-       if (!new_smb_io_relstr("document", buffer, depth, &info->document))
+       if (!smb_io_relstr("document", buffer, depth, &info->document))
                return False;
-       if (!new_smb_io_relstr("notifyname", buffer, depth, &info->notifyname))
+       if (!smb_io_relstr("notifyname", buffer, depth, &info->notifyname))
                return False;
-       if (!new_smb_io_relstr("datatype", buffer, depth, &info->datatype))
+       if (!smb_io_relstr("datatype", buffer, depth, &info->datatype))
                return False;
 
-       if (!new_smb_io_relstr("printprocessor", buffer, depth, &info->printprocessor))
+       if (!smb_io_relstr("printprocessor", buffer, depth, &info->printprocessor))
                return False;
-       if (!new_smb_io_relstr("parameters", buffer, depth, &info->parameters))
+       if (!smb_io_relstr("parameters", buffer, depth, &info->parameters))
                return False;
-       if (!new_smb_io_relstr("drivername", buffer, depth, &info->drivername))
+       if (!smb_io_relstr("drivername", buffer, depth, &info->drivername))
                return False;
-       if (!new_smb_io_reldevmode("devmode", buffer, depth, &info->devmode))
+       if (!smb_io_reldevmode("devmode", buffer, depth, &info->devmode))
                return False;
-       if (!new_smb_io_relstr("text_status", buffer, depth, &info->text_status))
+       if (!smb_io_relstr("text_status", buffer, depth, &info->text_status))
                return False;
 
 /*     SEC_DESC sec_desc;*/
@@ -2110,11 +2547,12 @@ BOOL new_smb_io_job_info_2(char *desc, NEW_BUFFER *buffer, JOB_INFO_2 *info, int
 
 /*******************************************************************
 ********************************************************************/  
-BOOL new_smb_io_form_1(char *desc, NEW_BUFFER *buffer, FORM_1 *info, int depth)
+
+BOOL smb_io_form_1(char *desc, NEW_BUFFER *buffer, FORM_1 *info, int depth)
 {
-       prs_struct *ps=&(buffer->prs);
+       prs_struct *ps=&buffer->prs;
        
-       prs_debug(ps, depth, desc, "new_smb_io_form_1");
+       prs_debug(ps, depth, desc, "smb_io_form_1");
        depth++;
                
        buffer->struct_start=prs_offset(ps);
@@ -2122,7 +2560,7 @@ BOOL new_smb_io_form_1(char *desc, NEW_BUFFER *buffer, FORM_1 *info, int depth)
        if (!prs_uint32("flag", ps, depth, &info->flag))
                return False;
                
-       if (!new_smb_io_relstr("name", buffer, depth, &info->name))
+       if (!smb_io_relstr("name", buffer, depth, &info->name))
                return False;
 
        if (!prs_uint32("width", ps, depth, &info->width))
@@ -2144,14 +2582,20 @@ BOOL new_smb_io_form_1(char *desc, NEW_BUFFER *buffer, FORM_1 *info, int depth)
 /*******************************************************************
  Read/write a BUFFER struct.
 ********************************************************************/  
-static BOOL new_spoolss_io_buffer(char *desc, prs_struct *ps, int depth, NEW_BUFFER *buffer)
+
+static BOOL spoolss_io_buffer(char *desc, prs_struct *ps, int depth, NEW_BUFFER **pp_buffer)
 {
-       if (buffer == NULL)
-               return False;
+       NEW_BUFFER *buffer = *pp_buffer;
 
-       prs_debug(ps, depth, desc, "new_spoolss_io_buffer");
+       prs_debug(ps, depth, desc, "spoolss_io_buffer");
        depth++;
        
+       if (UNMARSHALLING(ps))
+               buffer = *pp_buffer = (NEW_BUFFER *)prs_alloc_mem(ps, sizeof(NEW_BUFFER));
+
+       if (buffer == NULL)
+               return False;
+
        if (!prs_uint32("ptr", ps, depth, &buffer->ptr))
                return False;
        
@@ -2161,7 +2605,12 @@ static BOOL new_spoolss_io_buffer(char *desc, prs_struct *ps, int depth, NEW_BUF
                buffer->string_at_end=0;
                
                if (buffer->ptr==0) {
-                       if (!prs_init(&buffer->prs, 0, 4, prs_get_mem_context(ps), UNMARSHALL))
+                       /*
+                        * JRA. I'm not sure if the data in here is in big-endian format if
+                        * the client is big-endian. Leave as default (little endian) for now.
+                        */
+
+                       if (!prs_init(&buffer->prs, 0, prs_get_mem_context(ps), UNMARSHALL))
                                return False;
                        return True;
                }
@@ -2169,7 +2618,12 @@ static BOOL new_spoolss_io_buffer(char *desc, prs_struct *ps, int depth, NEW_BUF
                if (!prs_uint32("size", ps, depth, &buffer->size))
                        return False;
                                        
-               if (!prs_init(&buffer->prs, buffer->size, 4, prs_get_mem_context(ps), UNMARSHALL))
+               /*
+                * JRA. I'm not sure if the data in here is in big-endian format if
+                * the client is big-endian. Leave as default (little endian) for now.
+                */
+
+               if (!prs_init(&buffer->prs, buffer->size, prs_get_mem_context(ps), UNMARSHALL))
                        return False;
 
                if (!prs_append_some_prs_data(&buffer->prs, ps, prs_offset(ps), buffer->size))
@@ -2186,23 +2640,38 @@ static BOOL new_spoolss_io_buffer(char *desc, prs_struct *ps, int depth, NEW_BUF
                return True;
        }
        else {
+               BOOL ret = False;
+
                /* writing */
-               if (buffer->ptr==0)
+               if (buffer->ptr==0) {
+                       /* We have finished with the data in buffer->prs - free it. */
+                       prs_mem_free(&buffer->prs);
                        return True;
-               
+               }
+       
                if (!prs_uint32("size", ps, depth, &buffer->size))
-                       return False;
+                       goto out;
+
                if (!prs_append_some_prs_data(ps, &buffer->prs, 0, buffer->size))
-                       return False;
+                       goto out;
 
-               return True;
+               ret = True;
+       out:
+
+               /* We have finished with the data in buffer->prs - free it. */
+               prs_mem_free(&buffer->prs);
+
+               return ret;
        }
 }
 
 /*******************************************************************
  move a BUFFER from the query to the reply.
+ As the data pointers in NEW_BUFFER are malloc'ed, not talloc'ed,
+ this is ok. This is an OPTIMIZATION and is not strictly neccessary.
 ********************************************************************/  
-void new_spoolss_move_buffer(NEW_BUFFER *src, NEW_BUFFER **dest)
+
+void spoolss_move_buffer(NEW_BUFFER *src, NEW_BUFFER **dest)
 {
        prs_switch_type(&src->prs, MARSHALL);
        if(!prs_set_offset(&src->prs, 0))
@@ -2212,64 +2681,29 @@ void new_spoolss_move_buffer(NEW_BUFFER *src, NEW_BUFFER **dest)
        *dest=src;
 }
 
-/*******************************************************************
- create a BUFFER struct.
-********************************************************************/  
-BOOL new_spoolss_allocate_buffer(NEW_BUFFER **buffer)
-{
-       if (buffer==NULL)
-               return False;
-               
-       if((*buffer=(NEW_BUFFER *)malloc(sizeof(NEW_BUFFER))) == NULL) {
-               DEBUG(0,("new_spoolss_allocate_buffer: malloc fail for size %u.\n",
-                               (unsigned int)sizeof(NEW_BUFFER) ));
-               return False;
-       }
-       
-       (*buffer)->ptr=0x0;
-       (*buffer)->size=0;
-       (*buffer)->string_at_end=0;     
-       return True;
-}
-
-/*******************************************************************
- Destroy a BUFFER struct.
-********************************************************************/  
-void new_spoolss_free_buffer(NEW_BUFFER *buffer)
-{
-       if (buffer==NULL)
-               return;
-               
-       prs_mem_free(&buffer->prs);
-       buffer->ptr=0x0;
-       buffer->size=0;
-       buffer->string_at_end=0;
-       
-       free(buffer);
-}
-
 /*******************************************************************
  Get the size of a BUFFER struct.
 ********************************************************************/  
+
 uint32 new_get_buffer_size(NEW_BUFFER *buffer)
 {
        return (buffer->size);
 }
 
-
 /*******************************************************************
  Parse a DRIVER_DIRECTORY_1 structure.
 ********************************************************************/  
-BOOL new_smb_io_driverdir_1(char *desc, NEW_BUFFER *buffer, DRIVER_DIRECTORY_1 *info, int depth)
+
+BOOL smb_io_driverdir_1(char *desc, NEW_BUFFER *buffer, DRIVER_DIRECTORY_1 *info, int depth)
 {
-       prs_struct *ps=&(buffer->prs);
+       prs_struct *ps=&buffer->prs;
 
-       prs_debug(ps, depth, desc, "new_smb_io_driverdir_1");
+       prs_debug(ps, depth, desc, "smb_io_driverdir_1");
        depth++;
 
        buffer->struct_start=prs_offset(ps);
 
-       if (!spoolss_smb_io_unistr(desc, &info->name, ps, depth))
+       if (!smb_io_unistr(desc, &info->name, ps, depth))
                return False;
 
        return True;
@@ -2278,16 +2712,17 @@ BOOL new_smb_io_driverdir_1(char *desc, NEW_BUFFER *buffer, DRIVER_DIRECTORY_1 *
 /*******************************************************************
  Parse a PORT_INFO_1 structure.
 ********************************************************************/  
-BOOL new_smb_io_port_1(char *desc, NEW_BUFFER *buffer, PORT_INFO_1 *info, int depth)
+
+BOOL smb_io_port_1(char *desc, NEW_BUFFER *buffer, PORT_INFO_1 *info, int depth)
 {
-       prs_struct *ps=&(buffer->prs);
+       prs_struct *ps=&buffer->prs;
 
-       prs_debug(ps, depth, desc, "new_smb_io_port_1");
+       prs_debug(ps, depth, desc, "smb_io_port_1");
        depth++;
 
        buffer->struct_start=prs_offset(ps);
 
-       if(!new_smb_io_relstr("port_name", buffer, depth, &info->port_name))
+       if(!smb_io_relstr("port_name", buffer, depth, &info->port_name))
                return False;
 
        return True;
@@ -2296,20 +2731,21 @@ BOOL new_smb_io_port_1(char *desc, NEW_BUFFER *buffer, PORT_INFO_1 *info, int de
 /*******************************************************************
  Parse a PORT_INFO_2 structure.
 ********************************************************************/  
-BOOL new_smb_io_port_2(char *desc, NEW_BUFFER *buffer, PORT_INFO_2 *info, int depth)
+
+BOOL smb_io_port_2(char *desc, NEW_BUFFER *buffer, PORT_INFO_2 *info, int depth)
 {
-       prs_struct *ps=&(buffer->prs);
+       prs_struct *ps=&buffer->prs;
 
-       prs_debug(ps, depth, desc, "new_smb_io_port_2");
+       prs_debug(ps, depth, desc, "smb_io_port_2");
        depth++;
 
        buffer->struct_start=prs_offset(ps);
 
-       if(!new_smb_io_relstr("port_name", buffer, depth, &info->port_name))
+       if(!smb_io_relstr("port_name", buffer, depth, &info->port_name))
                return False;
-       if(!new_smb_io_relstr("monitor_name", buffer, depth, &info->monitor_name))
+       if(!smb_io_relstr("monitor_name", buffer, depth, &info->monitor_name))
                return False;
-       if(!new_smb_io_relstr("description", buffer, depth, &info->description))
+       if(!smb_io_relstr("description", buffer, depth, &info->description))
                return False;
        if(!prs_uint32("port_type", ps, depth, &info->port_type))
                return False;
@@ -2319,19 +2755,19 @@ BOOL new_smb_io_port_2(char *desc, NEW_BUFFER *buffer, PORT_INFO_2 *info, int de
        return True;
 }
 
-
 /*******************************************************************
 ********************************************************************/  
+
 BOOL smb_io_printprocessor_info_1(char *desc, NEW_BUFFER *buffer, PRINTPROCESSOR_1 *info, int depth)
 {
-       prs_struct *ps=&(buffer->prs);
+       prs_struct *ps=&buffer->prs;
 
        prs_debug(ps, depth, desc, "smb_io_printprocessor_info_1");
        depth++;        
 
        buffer->struct_start=prs_offset(ps);
        
-       if (new_smb_io_relstr("name", buffer, depth, &info->name))
+       if (smb_io_relstr("name", buffer, depth, &info->name))
                return False;
 
        return True;
@@ -2339,16 +2775,17 @@ BOOL smb_io_printprocessor_info_1(char *desc, NEW_BUFFER *buffer, PRINTPROCESSOR
 
 /*******************************************************************
 ********************************************************************/  
+
 BOOL smb_io_printprocdatatype_info_1(char *desc, NEW_BUFFER *buffer, PRINTPROCDATATYPE_1 *info, int depth)
 {
-       prs_struct *ps=&(buffer->prs);
+       prs_struct *ps=&buffer->prs;
 
        prs_debug(ps, depth, desc, "smb_io_printprocdatatype_info_1");
        depth++;        
 
        buffer->struct_start=prs_offset(ps);
        
-       if (new_smb_io_relstr("name", buffer, depth, &info->name))
+       if (smb_io_relstr("name", buffer, depth, &info->name))
                return False;
 
        return True;
@@ -2356,6 +2793,7 @@ BOOL smb_io_printprocdatatype_info_1(char *desc, NEW_BUFFER *buffer, PRINTPROCDA
 
 /*******************************************************************
 ********************************************************************/  
+
 BOOL smb_io_printmonitor_info_1(char *desc, NEW_BUFFER *buffer, PRINTMONITOR_1 *info, int depth)
 {
        prs_struct *ps=&buffer->prs;
@@ -2365,7 +2803,7 @@ BOOL smb_io_printmonitor_info_1(char *desc, NEW_BUFFER *buffer, PRINTMONITOR_1 *
 
        buffer->struct_start=prs_offset(ps);
 
-       if (!new_smb_io_relstr("name", buffer, depth, &info->name))
+       if (!smb_io_relstr("name", buffer, depth, &info->name))
                return False;
 
        return True;
@@ -2373,20 +2811,21 @@ BOOL smb_io_printmonitor_info_1(char *desc, NEW_BUFFER *buffer, PRINTMONITOR_1 *
 
 /*******************************************************************
 ********************************************************************/  
+
 BOOL smb_io_printmonitor_info_2(char *desc, NEW_BUFFER *buffer, PRINTMONITOR_2 *info, int depth)
 {
-       prs_struct *ps=&(buffer->prs);
+       prs_struct *ps=&buffer->prs;
 
        prs_debug(ps, depth, desc, "smb_io_printmonitor_info_2");
        depth++;        
 
        buffer->struct_start=prs_offset(ps);
 
-       if (!new_smb_io_relstr("name", buffer, depth, &info->name))
+       if (!smb_io_relstr("name", buffer, depth, &info->name))
                return False;
-       if (!new_smb_io_relstr("environment", buffer, depth, &info->environment))
+       if (!smb_io_relstr("environment", buffer, depth, &info->environment))
                return False;
-       if (!new_smb_io_relstr("dll_name", buffer, depth, &info->dll_name))
+       if (!smb_io_relstr("dll_name", buffer, depth, &info->dll_name))
                return False;
 
        return True;
@@ -2395,6 +2834,7 @@ BOOL smb_io_printmonitor_info_2(char *desc, NEW_BUFFER *buffer, PRINTMONITOR_2 *
 /*******************************************************************
 return the size required by a struct in the stream
 ********************************************************************/  
+
 uint32 spoolss_size_printer_info_0(PRINTER_INFO_0 *info)
 {
        int size=0;
@@ -2452,6 +2892,7 @@ uint32 spoolss_size_printer_info_0(PRINTER_INFO_0 *info)
 /*******************************************************************
 return the size required by a struct in the stream
 ********************************************************************/  
+
 uint32 spoolss_size_printer_info_1(PRINTER_INFO_1 *info)
 {
        int size=0;
@@ -2467,6 +2908,7 @@ uint32 spoolss_size_printer_info_1(PRINTER_INFO_1 *info)
 /*******************************************************************
 return the size required by a struct in the stream
 ********************************************************************/
+
 uint32 spoolss_size_printer_info_2(PRINTER_INFO_2 *info)
 {
        uint32 size=0;
@@ -2504,6 +2946,7 @@ uint32 spoolss_size_printer_info_2(PRINTER_INFO_2 *info)
 /*******************************************************************
 return the size required by a struct in the stream
 ********************************************************************/
+
 uint32 spoolss_size_printer_info_3(PRINTER_INFO_3 *info)
 {
        /* The 4 is for the self relative pointer.. */
@@ -2514,6 +2957,7 @@ uint32 spoolss_size_printer_info_3(PRINTER_INFO_3 *info)
 /*******************************************************************
 return the size required by a struct in the stream
 ********************************************************************/
+
 uint32 spoolss_size_printer_driver_info_1(DRIVER_INFO_1 *info)
 {
        int size=0;
@@ -2525,6 +2969,7 @@ uint32 spoolss_size_printer_driver_info_1(DRIVER_INFO_1 *info)
 /*******************************************************************
 return the size required by a struct in the stream
 ********************************************************************/
+
 uint32 spoolss_size_printer_driver_info_2(DRIVER_INFO_2 *info)
 {
        int size=0;
@@ -2538,14 +2983,31 @@ uint32 spoolss_size_printer_driver_info_2(DRIVER_INFO_2 *info)
        return size;
 }
 
+/*******************************************************************
+return the size required by a string array.
+********************************************************************/
+
+uint32 spoolss_size_string_array(uint16 *string)
+{
+       uint32 i = 0;
+
+       if (string) {
+               for (i=0; (string[i]!=0x0000) || (string[i+1]!=0x0000); i++);
+       }
+       i=i+2; /* to count all chars including the leading zero */
+       i=2*i; /* because we need the value in bytes */
+       i=i+4; /* the offset pointer size */
+
+       return i;
+}
+
 /*******************************************************************
 return the size required by a struct in the stream
 ********************************************************************/
+
 uint32 spoolss_size_printer_driver_info_3(DRIVER_INFO_3 *info)
 {
        int size=0;
-       uint16 *string;
-       int i=0;
 
        size+=size_of_uint32( &info->version ); 
        size+=size_of_relative_string( &info->name );
@@ -2557,16 +3019,42 @@ uint32 spoolss_size_printer_driver_info_3(DRIVER_INFO_3 *info)
        size+=size_of_relative_string( &info->monitorname );
        size+=size_of_relative_string( &info->defaultdatatype );
        
-       string=info->dependentfiles;
-       if (string) {
-               for (i=0; (string[i]!=0x0000) || (string[i+1]!=0x0000); i++);
-       }
+       size+=spoolss_size_string_array(info->dependentfiles);
 
-       i=i+2; /* to count all chars including the leading zero */
-       i=2*i; /* because we need the value in bytes */
-       i=i+4; /* the offset pointer size */
+       return size;
+}
+
+/*******************************************************************
+return the size required by a struct in the stream
+********************************************************************/
+
+uint32 spoolss_size_printer_driver_info_6(DRIVER_INFO_6 *info)
+{
+       uint32 size=0;
+
+       size+=size_of_uint32( &info->version ); 
+       size+=size_of_relative_string( &info->name );
+       size+=size_of_relative_string( &info->architecture );
+       size+=size_of_relative_string( &info->driverpath );
+       size+=size_of_relative_string( &info->datafile );
+       size+=size_of_relative_string( &info->configfile );
+       size+=size_of_relative_string( &info->helpfile );
+
+       size+=spoolss_size_string_array(info->dependentfiles);
+
+       size+=size_of_relative_string( &info->monitorname );
+       size+=size_of_relative_string( &info->defaultdatatype );
+       
+       size+=spoolss_size_string_array(info->previousdrivernames);
 
-       size+=i;
+       size+=size_of_nttime(&info->driver_date);
+       size+=size_of_uint32( &info->padding ); 
+       size+=size_of_uint32( &info->driver_version_low );      
+       size+=size_of_uint32( &info->driver_version_high );     
+       size+=size_of_relative_string( &info->mfgname );
+       size+=size_of_relative_string( &info->oem_url );
+       size+=size_of_relative_string( &info->hardware_id );
+       size+=size_of_relative_string( &info->provider );
 
        return size;
 }
@@ -2574,6 +3062,7 @@ uint32 spoolss_size_printer_driver_info_3(DRIVER_INFO_3 *info)
 /*******************************************************************
 return the size required by a struct in the stream
 ********************************************************************/  
+
 uint32 spoolss_size_job_info_1(JOB_INFO_1 *info)
 {
        int size=0;
@@ -2597,6 +3086,7 @@ uint32 spoolss_size_job_info_1(JOB_INFO_1 *info)
 /*******************************************************************
 return the size required by a struct in the stream
 ********************************************************************/  
+
 uint32 spoolss_size_job_info_2(JOB_INFO_2 *info)
 {
        int size=0;
@@ -2633,6 +3123,7 @@ uint32 spoolss_size_job_info_2(JOB_INFO_2 *info)
 /*******************************************************************
 return the size required by a struct in the stream
 ********************************************************************/
+
 uint32 spoolss_size_form_1(FORM_1 *info)
 {
        int size=0;
@@ -2652,6 +3143,7 @@ uint32 spoolss_size_form_1(FORM_1 *info)
 /*******************************************************************
 return the size required by a struct in the stream
 ********************************************************************/  
+
 uint32 spoolss_size_port_info_1(PORT_INFO_1 *info)
 {
        int size=0;
@@ -2664,6 +3156,7 @@ uint32 spoolss_size_port_info_1(PORT_INFO_1 *info)
 /*******************************************************************
 return the size required by a struct in the stream
 ********************************************************************/  
+
 uint32 spoolss_size_driverdir_info_1(DRIVER_DIRECTORY_1 *info)
 {
        int size=0;
@@ -2678,6 +3171,7 @@ uint32 spoolss_size_driverdir_info_1(DRIVER_DIRECTORY_1 *info)
 /*******************************************************************
 return the size required by a struct in the stream
 ********************************************************************/  
+
 uint32 spoolss_size_port_info_2(PORT_INFO_2 *info)
 {
        int size=0;
@@ -2695,6 +3189,7 @@ uint32 spoolss_size_port_info_2(PORT_INFO_2 *info)
 /*******************************************************************
 return the size required by a struct in the stream
 ********************************************************************/  
+
 uint32 spoolss_size_printprocessor_info_1(PRINTPROCESSOR_1 *info)
 {
        int size=0;
@@ -2706,6 +3201,7 @@ uint32 spoolss_size_printprocessor_info_1(PRINTPROCESSOR_1 *info)
 /*******************************************************************
 return the size required by a struct in the stream
 ********************************************************************/  
+
 uint32 spoolss_size_printprocdatatype_info_1(PRINTPROCDATATYPE_1 *info)
 {
        int size=0;
@@ -2717,6 +3213,7 @@ uint32 spoolss_size_printprocdatatype_info_1(PRINTPROCDATATYPE_1 *info)
 /*******************************************************************
 return the size required by a struct in the stream
 ********************************************************************/  
+
 uint32 spoolss_size_printmonitor_info_1(PRINTMONITOR_1 *info)
 {
        int size=0;
@@ -2728,6 +3225,7 @@ uint32 spoolss_size_printmonitor_info_1(PRINTMONITOR_1 *info)
 /*******************************************************************
 return the size required by a struct in the stream
 ********************************************************************/  
+
 uint32 spoolss_size_printmonitor_info_2(PRINTMONITOR_2 *info)
 {
        int size=0;
@@ -2741,6 +3239,7 @@ uint32 spoolss_size_printmonitor_info_2(PRINTMONITOR_2 *info)
 /*******************************************************************
  * init a structure.
  ********************************************************************/
+
 BOOL make_spoolss_q_getprinterdriver2(SPOOL_Q_GETPRINTERDRIVER2 *q_u, 
                               const POLICY_HND *hnd,
                               const fstring architecture,
@@ -2768,6 +3267,7 @@ BOOL make_spoolss_q_getprinterdriver2(SPOOL_Q_GETPRINTERDRIVER2 *q_u,
  * read a structure.
  * called from spoolss_getprinterdriver2 (srv_spoolss.c)
  ********************************************************************/
+
 BOOL spoolss_io_q_getprinterdriver2(char *desc, SPOOL_Q_GETPRINTERDRIVER2 *q_u, prs_struct *ps, int depth)
 {
        prs_debug(ps, depth, desc, "spoolss_io_q_getprinterdriver2");
@@ -2785,10 +3285,10 @@ BOOL spoolss_io_q_getprinterdriver2(char *desc, SPOOL_Q_GETPRINTERDRIVER2 *q_u,
        
        if(!prs_align(ps))
                return False;
-               if(!prs_uint32("level", ps, depth, &q_u->level))
+       if(!prs_uint32("level", ps, depth, &q_u->level))
                return False;
                
-       if(!new_spoolss_io_buffer("", ps, depth, q_u->buffer))
+       if(!spoolss_io_buffer("", ps, depth, &q_u->buffer))
                return False;
 
        if(!prs_align(ps))
@@ -2809,6 +3309,7 @@ BOOL spoolss_io_q_getprinterdriver2(char *desc, SPOOL_Q_GETPRINTERDRIVER2 *q_u,
  * read a structure.
  * called from spoolss_getprinterdriver2 (srv_spoolss.c)
  ********************************************************************/
+
 BOOL spoolss_io_r_getprinterdriver2(char *desc, SPOOL_R_GETPRINTERDRIVER2 *r_u, prs_struct *ps, int depth)
 {
        prs_debug(ps, depth, desc, "spoolss_io_r_getprinterdriver2");
@@ -2817,7 +3318,7 @@ BOOL spoolss_io_r_getprinterdriver2(char *desc, SPOOL_R_GETPRINTERDRIVER2 *r_u,
        if (!prs_align(ps))
                return False;
                
-       if (!new_spoolss_io_buffer("", ps, depth, r_u->buffer))
+       if (!spoolss_io_buffer("", ps, depth, &r_u->buffer))
                return False;
 
        if (!prs_align(ps))
@@ -2837,14 +3338,20 @@ BOOL spoolss_io_r_getprinterdriver2(char *desc, SPOOL_R_GETPRINTERDRIVER2 *r_u,
 /*******************************************************************
  * init a structure.
  ********************************************************************/
-BOOL make_spoolss_q_enumprinters(SPOOL_Q_ENUMPRINTERS *q_u, uint32 flags, 
-                               fstring servername, uint32 level, 
-                               NEW_BUFFER *buffer, uint32 offered)
+
+BOOL make_spoolss_q_enumprinters(
+       SPOOL_Q_ENUMPRINTERS *q_u, 
+       uint32 flags, 
+       fstring servername, 
+       uint32 level, 
+       NEW_BUFFER *buffer, 
+       uint32 offered
+)
 {
        q_u->flags=flags;
        
        q_u->servername_ptr = (servername != NULL) ? 1 : 0;
-       init_unistr2(&q_u->servername, servername, strlen(servername));
+       init_buf_unistr2(&q_u->servername, &q_u->servername_ptr, servername);
 
        q_u->level=level;
        q_u->buffer=buffer;
@@ -2856,6 +3363,7 @@ BOOL make_spoolss_q_enumprinters(SPOOL_Q_ENUMPRINTERS *q_u, uint32 flags,
 /*******************************************************************
  * init a structure.
  ********************************************************************/
+
 BOOL make_spoolss_q_enumports(SPOOL_Q_ENUMPORTS *q_u, 
                                fstring servername, uint32 level, 
                                NEW_BUFFER *buffer, uint32 offered)
@@ -2874,6 +3382,7 @@ BOOL make_spoolss_q_enumports(SPOOL_Q_ENUMPORTS *q_u,
  * read a structure.
  * called from spoolss_enumprinters (srv_spoolss.c)
  ********************************************************************/
+
 BOOL spoolss_io_q_enumprinters(char *desc, SPOOL_Q_ENUMPRINTERS *q_u, prs_struct *ps, int depth)
 {
        prs_debug(ps, depth, desc, "spoolss_io_q_enumprinters");
@@ -2895,7 +3404,7 @@ BOOL spoolss_io_q_enumprinters(char *desc, SPOOL_Q_ENUMPRINTERS *q_u, prs_struct
        if (!prs_uint32("level", ps, depth, &q_u->level))
                return False;
 
-       if (!new_spoolss_io_buffer("", ps, depth, q_u->buffer))
+       if (!spoolss_io_buffer("", ps, depth, &q_u->buffer))
                return False;
 
        if (!prs_align(ps))
@@ -2909,15 +3418,16 @@ BOOL spoolss_io_q_enumprinters(char *desc, SPOOL_Q_ENUMPRINTERS *q_u, prs_struct
 /*******************************************************************
  Parse a SPOOL_R_ENUMPRINTERS structure.
  ********************************************************************/
-BOOL new_spoolss_io_r_enumprinters(char *desc, SPOOL_R_ENUMPRINTERS *r_u, prs_struct *ps, int depth)
+
+BOOL spoolss_io_r_enumprinters(char *desc, SPOOL_R_ENUMPRINTERS *r_u, prs_struct *ps, int depth)
 {
-       prs_debug(ps, depth, desc, "new_spoolss_io_r_enumprinters");
+       prs_debug(ps, depth, desc, "spoolss_io_r_enumprinters");
        depth++;
 
        if (!prs_align(ps))
                return False;
                
-       if (!new_spoolss_io_buffer("", ps, depth, r_u->buffer))
+       if (!spoolss_io_buffer("", ps, depth, &r_u->buffer))
                return False;
 
        if (!prs_align(ps))
@@ -2940,6 +3450,7 @@ BOOL new_spoolss_io_r_enumprinters(char *desc, SPOOL_R_ENUMPRINTERS *r_u, prs_st
  * called from spoolss_r_enum_printers (srv_spoolss.c)
  *
  ********************************************************************/
+
 BOOL spoolss_io_r_getprinter(char *desc, SPOOL_R_GETPRINTER *r_u, prs_struct *ps, int depth)
 {      
        prs_debug(ps, depth, desc, "spoolss_io_r_getprinter");
@@ -2948,7 +3459,7 @@ BOOL spoolss_io_r_getprinter(char *desc, SPOOL_R_GETPRINTER *r_u, prs_struct *ps
        if (!prs_align(ps))
                return False;
                
-       if (!new_spoolss_io_buffer("", ps, depth, r_u->buffer))
+       if (!spoolss_io_buffer("", ps, depth, &r_u->buffer))
                return False;
 
        if (!prs_align(ps))
@@ -2967,6 +3478,7 @@ BOOL spoolss_io_r_getprinter(char *desc, SPOOL_R_GETPRINTER *r_u, prs_struct *ps
  * read a structure.
  * called from spoolss_getprinter (srv_spoolss.c)
  ********************************************************************/
+
 BOOL spoolss_io_q_getprinter(char *desc, SPOOL_Q_GETPRINTER *q_u, prs_struct *ps, int depth)
 {
        prs_debug(ps, depth, desc, "spoolss_io_q_getprinter");
@@ -2980,7 +3492,7 @@ BOOL spoolss_io_q_getprinter(char *desc, SPOOL_Q_GETPRINTER *q_u, prs_struct *ps
        if (!prs_uint32("level", ps, depth, &q_u->level))
                return False;
 
-       if (!new_spoolss_io_buffer("", ps, depth, q_u->buffer))
+       if (!spoolss_io_buffer("", ps, depth, &q_u->buffer))
                return False;
 
        if (!prs_align(ps))
@@ -2994,8 +3506,15 @@ BOOL spoolss_io_q_getprinter(char *desc, SPOOL_Q_GETPRINTER *q_u, prs_struct *ps
 /*******************************************************************
  * init a structure.
  ********************************************************************/
-BOOL make_spoolss_q_getprinter(SPOOL_Q_GETPRINTER *q_u, const POLICY_HND *hnd, uint32 level, 
-                               NEW_BUFFER *buffer, uint32 offered)
+
+BOOL make_spoolss_q_getprinter(
+       TALLOC_CTX *mem_ctx,
+       SPOOL_Q_GETPRINTER *q_u, 
+       const POLICY_HND *hnd, 
+       uint32 level, 
+       NEW_BUFFER *buffer, 
+       uint32 offered
+)
 {
        if (q_u == NULL)
        {
@@ -3011,34 +3530,92 @@ BOOL make_spoolss_q_getprinter(SPOOL_Q_GETPRINTER *q_u, const POLICY_HND *hnd, u
 }
 
 /*******************************************************************
-********************************************************************/  
-BOOL spoolss_io_r_setprinter(char *desc, SPOOL_R_SETPRINTER *r_u, prs_struct *ps, int depth)
-{              
-       prs_debug(ps, depth, desc, "spoolss_io_r_setprinter");
-       depth++;
+ * init a structure.
+ ********************************************************************/
+BOOL make_spoolss_q_setprinter(
+       TALLOC_CTX *mem_ctx,
+       SPOOL_Q_SETPRINTER *q_u, 
+       const POLICY_HND *hnd, 
+       uint32 level, 
+       PRINTER_INFO_CTR *info, 
+       uint32 command
+)
+{
+       SEC_DESC *secdesc;
+       DEVICEMODE *devmode;
 
-       if(!prs_align(ps))
+       if (q_u == NULL)
+       {
                return False;
+       }
        
-       if(!prs_uint32("status", ps, depth, &r_u->status))
-               return False;
-
-       return True;
-}
-
-/*******************************************************************
- Delete the dynamic parts of a SPOOL_Q_SETPRINTER struct.
-********************************************************************/  
-
-void free_spoolss_q_setprinter(SPOOL_Q_SETPRINTER *q_u)
-{
-       free_spool_printer_info_level(&q_u->info);
-       free_sec_desc_buf( &q_u->secdesc_ctr );
-       free_devmode( q_u->devmode_ctr.devmode );
-}
+       memcpy(&q_u->handle, hnd, sizeof(q_u->handle));
 
-/*******************************************************************
- Marshall/unmarshall a SPOOL_Q_SETPRINTER struct.
+       q_u->level = level;
+       q_u->info.level = level;
+       q_u->info.info_ptr = (info != NULL) ? 1 : 0;
+       switch (level)
+       {
+       case 2:
+               secdesc = info->printers_2->secdesc;
+               devmode = info->printers_2->devmode;
+               
+               /* FIXMEE!!  HACK ALERT!!!  --jerry */
+               info->printers_2->devmode = NULL;
+               info->printers_2->secdesc = NULL;
+               
+               make_spoolss_printer_info_2 (mem_ctx, &q_u->info.info_2, info->printers_2);
+#if 0  /* JERRY TEST */
+               q_u->secdesc_ctr = (SEC_DESC_BUF*)malloc(sizeof(SEC_DESC_BUF));
+               if (!q_u->secdesc_ctr)
+                       return False;
+               q_u->secdesc_ctr->ptr = (secdesc != NULL) ? 1: 0;
+               q_u->secdesc_ctr->max_len = (secdesc) ? sizeof(SEC_DESC) + (2*sizeof(uint32)) : 0;
+               q_u->secdesc_ctr->len = (secdesc) ? sizeof(SEC_DESC) + (2*sizeof(uint32)) : 0;
+               q_u->secdesc_ctr->sec = secdesc;
+
+               q_u->devmode_ctr.devmode_ptr = (devmode != NULL) ? 1 : 0;
+               q_u->devmode_ctr.size = sizeof(DEVICEMODE) + (3*sizeof(uint32));
+               q_u->devmode_ctr.devmode = devmode;
+#else
+               q_u->secdesc_ctr = NULL;
+       
+               q_u->devmode_ctr.devmode_ptr = 0;
+               q_u->devmode_ctr.size = 0;
+               q_u->devmode_ctr.devmode = NULL;
+#endif
+               break;
+       default: 
+               DEBUG(0,("make_spoolss_q_setprinter: Unknown info level [%d]\n", level));
+                       break;
+       }
+
+       
+       q_u->command = command;
+
+       return True;
+}
+
+
+/*******************************************************************
+********************************************************************/  
+
+BOOL spoolss_io_r_setprinter(char *desc, SPOOL_R_SETPRINTER *r_u, prs_struct *ps, int depth)
+{              
+       prs_debug(ps, depth, desc, "spoolss_io_r_setprinter");
+       depth++;
+
+       if(!prs_align(ps))
+               return False;
+       
+       if(!prs_uint32("status", ps, depth, &r_u->status))
+               return False;
+
+       return True;
+}
+
+/*******************************************************************
+ Marshall/unmarshall a SPOOL_Q_SETPRINTER struct.
 ********************************************************************/  
 
 BOOL spoolss_io_q_setprinter(char *desc, SPOOL_Q_SETPRINTER *q_u, prs_struct *ps, int depth)
@@ -3079,6 +3656,16 @@ BOOL spoolss_io_q_setprinter(char *desc, SPOOL_Q_SETPRINTER *q_u, prs_struct *ps
        {
                if (!sec_io_desc_buf(desc, &q_u->secdesc_ctr, ps, depth))
                        return False;
+       } else {
+               uint32 dummy;
+
+               /* Parse a NULL security descriptor.  This should really
+                  happen inside the sec_io_desc_buf() function. */
+
+               prs_debug(ps, depth, "", "sec_io_desc_buf");
+               if (!prs_uint32("size", ps, depth + 1, &dummy)) return False;
+               if (!prs_uint32("ptr", ps, depth + 1, &dummy)) return
+                                                                      False;
        }
        
        if(!prs_uint32("command", ps, depth, &q_u->command))
@@ -3089,6 +3676,7 @@ BOOL spoolss_io_q_setprinter(char *desc, SPOOL_Q_SETPRINTER *q_u, prs_struct *ps
 
 /*******************************************************************
 ********************************************************************/  
+
 BOOL spoolss_io_r_fcpn(char *desc, SPOOL_R_FCPN *r_u, prs_struct *ps, int depth)
 {              
        prs_debug(ps, depth, desc, "spoolss_io_r_fcpn");
@@ -3105,6 +3693,7 @@ BOOL spoolss_io_r_fcpn(char *desc, SPOOL_R_FCPN *r_u, prs_struct *ps, int depth)
 
 /*******************************************************************
 ********************************************************************/  
+
 BOOL spoolss_io_q_fcpn(char *desc, SPOOL_Q_FCPN *q_u, prs_struct *ps, int depth)
 {
 
@@ -3123,6 +3712,7 @@ BOOL spoolss_io_q_fcpn(char *desc, SPOOL_Q_FCPN *q_u, prs_struct *ps, int depth)
 
 /*******************************************************************
 ********************************************************************/  
+
 BOOL spoolss_io_r_addjob(char *desc, SPOOL_R_ADDJOB *r_u, prs_struct *ps, int depth)
 {              
        prs_debug(ps, depth, desc, "");
@@ -3131,6 +3721,15 @@ BOOL spoolss_io_r_addjob(char *desc, SPOOL_R_ADDJOB *r_u, prs_struct *ps, int de
        if(!prs_align(ps))
                return False;
        
+       if(!spoolss_io_buffer("", ps, depth, &r_u->buffer))
+               return False;
+
+       if(!prs_align(ps))
+               return False;
+       
+       if(!prs_uint32("needed", ps, depth, &r_u->needed))
+               return False;
+
        if(!prs_uint32("status", ps, depth, &r_u->status))
                return False;
 
@@ -3139,6 +3738,7 @@ BOOL spoolss_io_r_addjob(char *desc, SPOOL_R_ADDJOB *r_u, prs_struct *ps, int de
 
 /*******************************************************************
 ********************************************************************/  
+
 BOOL spoolss_io_q_addjob(char *desc, SPOOL_Q_ADDJOB *q_u, prs_struct *ps, int depth)
 {
        prs_debug(ps, depth, desc, "");
@@ -3152,7 +3752,7 @@ BOOL spoolss_io_q_addjob(char *desc, SPOOL_Q_ADDJOB *q_u, prs_struct *ps, int de
        if(!prs_uint32("level", ps, depth, &q_u->level))
                return False;
        
-       if(!new_spoolss_io_buffer("", ps, depth, q_u->buffer))
+       if(!spoolss_io_buffer("", ps, depth, &q_u->buffer))
                return False;
 
        if(!prs_align(ps))
@@ -3166,6 +3766,7 @@ BOOL spoolss_io_q_addjob(char *desc, SPOOL_Q_ADDJOB *q_u, prs_struct *ps, int de
 
 /*******************************************************************
 ********************************************************************/  
+
 BOOL spoolss_io_r_enumjobs(char *desc, SPOOL_R_ENUMJOBS *r_u, prs_struct *ps, int depth)
 {              
        prs_debug(ps, depth, desc, "spoolss_io_r_enumjobs");
@@ -3174,7 +3775,7 @@ BOOL spoolss_io_r_enumjobs(char *desc, SPOOL_R_ENUMJOBS *r_u, prs_struct *ps, in
        if (!prs_align(ps))
                return False;
                
-       if (!new_spoolss_io_buffer("", ps, depth, r_u->buffer))
+       if (!spoolss_io_buffer("", ps, depth, &r_u->buffer))
                return False;
 
        if (!prs_align(ps))
@@ -3192,9 +3793,9 @@ BOOL spoolss_io_r_enumjobs(char *desc, SPOOL_R_ENUMJOBS *r_u, prs_struct *ps, in
        return True;            
 }
 
-
 /*******************************************************************
 ********************************************************************/  
+
 BOOL make_spoolss_q_enumjobs(SPOOL_Q_ENUMJOBS *q_u, const POLICY_HND *hnd,
                                uint32 firstjob,
                                uint32 numofjobs,
@@ -3217,6 +3818,7 @@ BOOL make_spoolss_q_enumjobs(SPOOL_Q_ENUMJOBS *q_u, const POLICY_HND *hnd,
 
 /*******************************************************************
 ********************************************************************/  
+
 BOOL spoolss_io_q_enumjobs(char *desc, SPOOL_Q_ENUMJOBS *q_u, prs_struct *ps, int depth)
 {
        prs_debug(ps, depth, desc, "spoolss_io_q_enumjobs");
@@ -3235,7 +3837,7 @@ BOOL spoolss_io_q_enumjobs(char *desc, SPOOL_Q_ENUMJOBS *q_u, prs_struct *ps, in
        if (!prs_uint32("level", ps, depth, &q_u->level))
                return False;
 
-       if (!new_spoolss_io_buffer("", ps, depth, q_u->buffer))
+       if (!spoolss_io_buffer("", ps, depth, &q_u->buffer))
                return False;   
 
        if (!prs_uint32("offered", ps, depth, &q_u->offered))
@@ -3246,6 +3848,7 @@ BOOL spoolss_io_q_enumjobs(char *desc, SPOOL_Q_ENUMJOBS *q_u, prs_struct *ps, in
 
 /*******************************************************************
 ********************************************************************/  
+
 BOOL spoolss_io_r_schedulejob(char *desc, SPOOL_R_SCHEDULEJOB *r_u, prs_struct *ps, int depth)
 {              
        prs_debug(ps, depth, desc, "spoolss_io_r_schedulejob");
@@ -3262,6 +3865,7 @@ BOOL spoolss_io_r_schedulejob(char *desc, SPOOL_R_SCHEDULEJOB *r_u, prs_struct *
 
 /*******************************************************************
 ********************************************************************/  
+
 BOOL spoolss_io_q_schedulejob(char *desc, SPOOL_Q_SCHEDULEJOB *q_u, prs_struct *ps, int depth)
 {
        prs_debug(ps, depth, desc, "spoolss_io_q_schedulejob");
@@ -3280,6 +3884,7 @@ BOOL spoolss_io_q_schedulejob(char *desc, SPOOL_Q_SCHEDULEJOB *q_u, prs_struct *
 
 /*******************************************************************
 ********************************************************************/  
+
 BOOL spoolss_io_r_setjob(char *desc, SPOOL_R_SETJOB *r_u, prs_struct *ps, int depth)
 {              
        prs_debug(ps, depth, desc, "spoolss_io_r_setjob");
@@ -3296,6 +3901,7 @@ BOOL spoolss_io_r_setjob(char *desc, SPOOL_R_SETJOB *r_u, prs_struct *ps, int de
 
 /*******************************************************************
 ********************************************************************/  
+
 BOOL spoolss_io_q_setjob(char *desc, SPOOL_Q_SETJOB *q_u, prs_struct *ps, int depth)
 {
        prs_debug(ps, depth, desc, "spoolss_io_q_setjob");
@@ -3323,15 +3929,16 @@ BOOL spoolss_io_q_setjob(char *desc, SPOOL_Q_SETJOB *q_u, prs_struct *ps, int de
 /*******************************************************************
  Parse a SPOOL_R_ENUMPRINTERDRIVERS structure.
 ********************************************************************/  
-BOOL new_spoolss_io_r_enumprinterdrivers(char *desc, SPOOL_R_ENUMPRINTERDRIVERS *r_u, prs_struct *ps, int depth)
+
+BOOL spoolss_io_r_enumprinterdrivers(char *desc, SPOOL_R_ENUMPRINTERDRIVERS *r_u, prs_struct *ps, int depth)
 {
-       prs_debug(ps, depth, desc, "new_spoolss_io_r_enumprinterdrivers");
+       prs_debug(ps, depth, desc, "spoolss_io_r_enumprinterdrivers");
        depth++;
 
        if (!prs_align(ps))
                return False;
                
-       if (!new_spoolss_io_buffer("", ps, depth, r_u->buffer))
+       if (!spoolss_io_buffer("", ps, depth, &r_u->buffer))
                return False;
 
        if (!prs_align(ps))
@@ -3352,6 +3959,7 @@ BOOL new_spoolss_io_r_enumprinterdrivers(char *desc, SPOOL_R_ENUMPRINTERDRIVERS
 /*******************************************************************
  * init a structure.
  ********************************************************************/
+
 BOOL make_spoolss_q_enumprinterdrivers(SPOOL_Q_ENUMPRINTERDRIVERS *q_u,
                                 const char *name,
                                 const char *environment,
@@ -3371,6 +3979,7 @@ BOOL make_spoolss_q_enumprinterdrivers(SPOOL_Q_ENUMPRINTERDRIVERS *q_u,
 /*******************************************************************
  Parse a SPOOL_Q_ENUMPRINTERDRIVERS structure.
 ********************************************************************/  
+
 BOOL spoolss_io_q_enumprinterdrivers(char *desc, SPOOL_Q_ENUMPRINTERDRIVERS *q_u, prs_struct *ps, int depth)
 {
 
@@ -3397,7 +4006,7 @@ BOOL spoolss_io_q_enumprinterdrivers(char *desc, SPOOL_Q_ENUMPRINTERDRIVERS *q_u
        if (!prs_uint32("level", ps, depth, &q_u->level))
                return False;
                
-       if (!new_spoolss_io_buffer("", ps, depth, q_u->buffer))
+       if (!spoolss_io_buffer("", ps, depth, &q_u->buffer))
                return False;
 
        if (!prs_align(ps))
@@ -3411,6 +4020,7 @@ BOOL spoolss_io_q_enumprinterdrivers(char *desc, SPOOL_Q_ENUMPRINTERDRIVERS *q_u
 
 /*******************************************************************
 ********************************************************************/  
+
 BOOL spoolss_io_q_enumforms(char *desc, SPOOL_Q_ENUMFORMS *q_u, prs_struct *ps, int depth)
 {
 
@@ -3424,7 +4034,7 @@ BOOL spoolss_io_q_enumforms(char *desc, SPOOL_Q_ENUMFORMS *q_u, prs_struct *ps,
        if (!prs_uint32("level", ps, depth, &q_u->level))
                return False;   
        
-       if (!new_spoolss_io_buffer("", ps, depth, q_u->buffer))
+       if (!spoolss_io_buffer("", ps, depth, &q_u->buffer))
                return False;
 
        if (!prs_align(ps))
@@ -3437,15 +4047,16 @@ BOOL spoolss_io_q_enumforms(char *desc, SPOOL_Q_ENUMFORMS *q_u, prs_struct *ps,
 
 /*******************************************************************
 ********************************************************************/  
-BOOL new_spoolss_io_r_enumforms(char *desc, SPOOL_R_ENUMFORMS *r_u, prs_struct *ps, int depth)
+
+BOOL spoolss_io_r_enumforms(char *desc, SPOOL_R_ENUMFORMS *r_u, prs_struct *ps, int depth)
 {
-       prs_debug(ps, depth, desc, "new_spoolss_io_r_enumforms");
+       prs_debug(ps, depth, desc, "spoolss_io_r_enumforms");
        depth++;
 
        if (!prs_align(ps))
                return False;
                
-       if (!new_spoolss_io_buffer("", ps, depth, r_u->buffer))
+       if (!spoolss_io_buffer("", ps, depth, &r_u->buffer))
                return False;
 
        if (!prs_align(ps))
@@ -3461,21 +4072,80 @@ BOOL new_spoolss_io_r_enumforms(char *desc, SPOOL_R_ENUMFORMS *r_u, prs_struct *
                return False;
 
        return True;
+}
+
+/*******************************************************************
+********************************************************************/  
+
+BOOL spoolss_io_q_getform(char *desc, SPOOL_Q_GETFORM *q_u, prs_struct *ps, int depth)
+{
+
+       prs_debug(ps, depth, desc, "spoolss_io_q_getform");
+       depth++;
+
+       if (!prs_align(ps))
+               return False;                   
+       if (!smb_io_pol_hnd("printer handle",&q_u->handle,ps,depth))
+               return False;           
+       if (!smb_io_unistr2("", &q_u->formname,True,ps,depth))
+               return False;
+
+       if (!prs_align(ps))
+               return False;
+
+       if (!prs_uint32("level", ps, depth, &q_u->level))
+               return False;   
+       
+       if (!spoolss_io_buffer("", ps, depth, &q_u->buffer))
+               return False;
+
+       if (!prs_align(ps))
+               return False;
+       if (!prs_uint32("offered", ps, depth, &q_u->offered))
+               return False;
+
+       return True;
+}
+
+/*******************************************************************
+********************************************************************/  
+
+BOOL spoolss_io_r_getform(char *desc, SPOOL_R_GETFORM *r_u, prs_struct *ps, int depth)
+{
+       prs_debug(ps, depth, desc, "spoolss_io_r_getform");
+       depth++;
+
+       if (!prs_align(ps))
+               return False;
+               
+       if (!spoolss_io_buffer("", ps, depth, &r_u->buffer))
+               return False;
+
+       if (!prs_align(ps))
+               return False;
+               
+       if (!prs_uint32("size of buffer needed", ps, depth, &r_u->needed))
+               return False;
                
+       if (!prs_uint32("status", ps, depth, &r_u->status))
+               return False;
+
+       return True;
 }
 
 /*******************************************************************
  Parse a SPOOL_R_ENUMPORTS structure.
 ********************************************************************/  
-BOOL new_spoolss_io_r_enumports(char *desc, SPOOL_R_ENUMPORTS *r_u, prs_struct *ps, int depth)
+
+BOOL spoolss_io_r_enumports(char *desc, SPOOL_R_ENUMPORTS *r_u, prs_struct *ps, int depth)
 {
-       prs_debug(ps, depth, desc, "new_spoolss_io_r_enumports");
+       prs_debug(ps, depth, desc, "spoolss_io_r_enumports");
        depth++;
 
        if (!prs_align(ps))
                return False;
                
-       if (!new_spoolss_io_buffer("", ps, depth, r_u->buffer))
+       if (!spoolss_io_buffer("", ps, depth, &r_u->buffer))
                return False;
 
        if (!prs_align(ps))
@@ -3495,6 +4165,7 @@ BOOL new_spoolss_io_r_enumports(char *desc, SPOOL_R_ENUMPORTS *r_u, prs_struct *
 
 /*******************************************************************
 ********************************************************************/  
+
 BOOL spoolss_io_q_enumports(char *desc, SPOOL_Q_ENUMPORTS *q_u, prs_struct *ps, int depth)
 {
        prs_debug(ps, depth, desc, "");
@@ -3513,7 +4184,7 @@ BOOL spoolss_io_q_enumports(char *desc, SPOOL_Q_ENUMPORTS *q_u, prs_struct *ps,
        if (!prs_uint32("level", ps, depth, &q_u->level))
                return False;
                
-       if (!new_spoolss_io_buffer("", ps, depth, q_u->buffer))
+       if (!spoolss_io_buffer("", ps, depth, &q_u->buffer))
                return False;
 
        if (!prs_align(ps))
@@ -3527,6 +4198,7 @@ BOOL spoolss_io_q_enumports(char *desc, SPOOL_Q_ENUMPORTS *q_u, prs_struct *ps,
 /*******************************************************************
  Parse a SPOOL_PRINTER_INFO_LEVEL_1 structure.
 ********************************************************************/  
+
 BOOL spool_io_printer_info_level_1(char *desc, SPOOL_PRINTER_INFO_LEVEL_1 *il, prs_struct *ps, int depth)
 {      
        prs_debug(ps, depth, desc, "spool_io_printer_info_level_1");
@@ -3557,6 +4229,7 @@ BOOL spool_io_printer_info_level_1(char *desc, SPOOL_PRINTER_INFO_LEVEL_1 *il, p
 /*******************************************************************
  Parse a SPOOL_PRINTER_INFO_LEVEL_3 structure.
 ********************************************************************/  
+
 BOOL spool_io_printer_info_level_3(char *desc, SPOOL_PRINTER_INFO_LEVEL_3 *il, prs_struct *ps, int depth)
 {      
        prs_debug(ps, depth, desc, "spool_io_printer_info_level_3");
@@ -3574,6 +4247,7 @@ BOOL spool_io_printer_info_level_3(char *desc, SPOOL_PRINTER_INFO_LEVEL_3 *il, p
 /*******************************************************************
  Parse a SPOOL_PRINTER_INFO_LEVEL_2 structure.
 ********************************************************************/  
+
 BOOL spool_io_printer_info_level_2(char *desc, SPOOL_PRINTER_INFO_LEVEL_2 *il, prs_struct *ps, int depth)
 {      
        prs_debug(ps, depth, desc, "spool_io_printer_info_level_2");
@@ -3655,6 +4329,7 @@ BOOL spool_io_printer_info_level_2(char *desc, SPOOL_PRINTER_INFO_LEVEL_2 *il, p
 
 /*******************************************************************
 ********************************************************************/  
+
 BOOL spool_io_printer_info_level(char *desc, SPOOL_PRINTER_INFO_LEVEL *il, prs_struct *ps, int depth)
 {
        prs_debug(ps, depth, desc, "spool_io_printer_info_level");
@@ -3687,15 +4362,11 @@ BOOL spool_io_printer_info_level(char *desc, SPOOL_PRINTER_INFO_LEVEL *il, prs_s
                case 1:
                {
                        if (UNMARSHALLING(ps)) {
-                               if ((il->info_1=(SPOOL_PRINTER_INFO_LEVEL_1 *)malloc(sizeof(SPOOL_PRINTER_INFO_LEVEL_1))) == NULL)
+                               if ((il->info_1=(SPOOL_PRINTER_INFO_LEVEL_1 *)prs_alloc_mem(ps,sizeof(SPOOL_PRINTER_INFO_LEVEL_1))) == NULL)
                                        return False;
-                               ZERO_STRUCTP(il->info_1);
                        }
-                       if (!spool_io_printer_info_level_1("", il->info_1, ps, depth)) {
-                               if (UNMARSHALLING(ps))
-                                       safe_free(il->info_1);
+                       if (!spool_io_printer_info_level_1("", il->info_1, ps, depth))
                                return False;
-                       }
                        break;          
                }
                /* 
@@ -3704,29 +4375,21 @@ BOOL spool_io_printer_info_level(char *desc, SPOOL_PRINTER_INFO_LEVEL *il, prs_s
                 */     
                case 2:
                        if (UNMARSHALLING(ps)) {
-                               if ((il->info_2=(SPOOL_PRINTER_INFO_LEVEL_2 *)malloc(sizeof(SPOOL_PRINTER_INFO_LEVEL_2))) == NULL)
+                               if ((il->info_2=(SPOOL_PRINTER_INFO_LEVEL_2 *)prs_alloc_mem(ps,sizeof(SPOOL_PRINTER_INFO_LEVEL_2))) == NULL)
                                        return False;
-                               ZERO_STRUCTP(il->info_2);
                        }
-                       if (!spool_io_printer_info_level_2("", il->info_2, ps, depth)) {
-                               if (UNMARSHALLING(ps))
-                                       safe_free(il->info_2);
+                       if (!spool_io_printer_info_level_2("", il->info_2, ps, depth))
                                return False;
-                       }
                        break;          
                /* DOCUMENT ME!!! What is level 3 used for? */
                case 3:
                {
                        if (UNMARSHALLING(ps)) {
-                               if ((il->info_3=(SPOOL_PRINTER_INFO_LEVEL_3 *)malloc(sizeof(SPOOL_PRINTER_INFO_LEVEL_3))) == NULL)
+                               if ((il->info_3=(SPOOL_PRINTER_INFO_LEVEL_3 *)prs_alloc_mem(ps,sizeof(SPOOL_PRINTER_INFO_LEVEL_3))) == NULL)
                                        return False;
-                               ZERO_STRUCTP(il->info_3);
                        }
-                       if (!spool_io_printer_info_level_3("", il->info_3, ps, depth)) {
-                               if (UNMARSHALLING(ps))
-                                       safe_free(il->info_3);
+                       if (!spool_io_printer_info_level_3("", il->info_3, ps, depth))
                                return False;
-                       }
                        break;          
                }
        }
@@ -3736,17 +4399,12 @@ BOOL spool_io_printer_info_level(char *desc, SPOOL_PRINTER_INFO_LEVEL *il, prs_s
 
 /*******************************************************************
 ********************************************************************/  
+
 BOOL spoolss_io_q_addprinterex(char *desc, SPOOL_Q_ADDPRINTEREX *q_u, prs_struct *ps, int depth)
 {
        prs_debug(ps, depth, desc, "spoolss_io_q_addprinterex");
        depth++;
 
-       /*
-        * I think that's one of the few well written functions.
-        * the sub-structures are correctly parsed and analysed
-        * the info level are handled in a nice way.
-        */
-
        if(!prs_align(ps))
                return False;
        if(!prs_uint32("", ps, depth, &q_u->server_name_ptr))
@@ -3772,6 +4430,8 @@ BOOL spoolss_io_q_addprinterex(char *desc, SPOOL_Q_ADDPRINTEREX *q_u, prs_struct
         * et le security descriptor.
         */
        
+       if(!prs_align(ps))
+               return False;
        if(!prs_uint32("unk0", ps, depth, &q_u->unk0))
                return False;
        if(!prs_uint32("unk1", ps, depth, &q_u->unk1))
@@ -3789,10 +4449,11 @@ BOOL spoolss_io_q_addprinterex(char *desc, SPOOL_Q_ADDPRINTEREX *q_u, prs_struct
        return True;
 }
 
-
 /*******************************************************************
 ********************************************************************/  
-BOOL spoolss_io_r_addprinterex(char *desc, SPOOL_R_ADDPRINTEREX *r_u, prs_struct *ps, int depth)
+
+BOOL spoolss_io_r_addprinterex(char *desc, SPOOL_R_ADDPRINTEREX *r_u, 
+                              prs_struct *ps, int depth)
 {
        prs_debug(ps, depth, desc, "spoolss_io_r_addprinterex");
        depth++;
@@ -3808,6 +4469,7 @@ BOOL spoolss_io_r_addprinterex(char *desc, SPOOL_R_ADDPRINTEREX *r_u, prs_struct
 
 /*******************************************************************
 ********************************************************************/  
+
 BOOL spool_io_printer_driver_info_level_3(char *desc, SPOOL_PRINTER_DRIVER_INFO_LEVEL_3 **q_u, 
                                           prs_struct *ps, int depth)
 {      
@@ -3818,10 +4480,9 @@ BOOL spool_io_printer_driver_info_level_3(char *desc, SPOOL_PRINTER_DRIVER_INFO_
                
        /* reading */
        if (UNMARSHALLING(ps)) {
-               il=(SPOOL_PRINTER_DRIVER_INFO_LEVEL_3 *)malloc(sizeof(SPOOL_PRINTER_DRIVER_INFO_LEVEL_3));
+               il=(SPOOL_PRINTER_DRIVER_INFO_LEVEL_3 *)prs_alloc_mem(ps,sizeof(SPOOL_PRINTER_DRIVER_INFO_LEVEL_3));
                if(il == NULL)
                        return False;
-               ZERO_STRUCTP(il);
                *q_u=il;
        }
        else {
@@ -3883,19 +4544,10 @@ BOOL spool_io_printer_driver_info_level_3(char *desc, SPOOL_PRINTER_DRIVER_INFO_
        return True;
 }
 
-void free_spool_printer_driver_info_level_3(SPOOL_PRINTER_DRIVER_INFO_LEVEL_3 **q_u)
-{
-       SPOOL_PRINTER_DRIVER_INFO_LEVEL_3 *il = *q_u;
-
-       if (il == NULL)
-               return;
-
-       safe_free(il);
-}
-
 /*******************************************************************
 parse a SPOOL_PRINTER_DRIVER_INFO_LEVEL_6 structure
 ********************************************************************/  
+
 BOOL spool_io_printer_driver_info_level_6(char *desc, SPOOL_PRINTER_DRIVER_INFO_LEVEL_6 **q_u, 
                                           prs_struct *ps, int depth)
 {      
@@ -3906,10 +4558,9 @@ BOOL spool_io_printer_driver_info_level_6(char *desc, SPOOL_PRINTER_DRIVER_INFO_
                
        /* reading */
        if (UNMARSHALLING(ps)) {
-               il=(SPOOL_PRINTER_DRIVER_INFO_LEVEL_6 *)malloc(sizeof(SPOOL_PRINTER_DRIVER_INFO_LEVEL_6));
+               il=(SPOOL_PRINTER_DRIVER_INFO_LEVEL_6 *)prs_alloc_mem(ps,sizeof(SPOOL_PRINTER_DRIVER_INFO_LEVEL_6));
                if(il == NULL)
                        return False;
-               ZERO_STRUCTP(il);
                *q_u=il;
        }
        else {
@@ -3924,8 +4575,20 @@ BOOL spool_io_printer_driver_info_level_6(char *desc, SPOOL_PRINTER_DRIVER_INFO_
 
        if(!prs_uint32("version", ps, depth, &il->version))
                return False;
+
        if(!prs_uint32("name_ptr", ps, depth, &il->name_ptr))
-               return False;
+               return False;   
+       /*
+        * If name_ptr is NULL then the next 4 bytes are the name_ptr. A driver 
+        * with a NULL name just isn't a driver For example: "HP LaserJet 4si"
+        * from W2K CDROM (which uses unidriver). JohnR 010205
+        */
+       if (!il->name_ptr) {
+               DEBUG(5,("spool_io_printer_driver_info_level_6: name_ptr is NULL! Get next value\n"));
+               if(!prs_uint32("name_ptr", ps, depth, &il->name_ptr))
+                       return False;   
+       }
+       
        if(!prs_uint32("environment_ptr", ps, depth, &il->environment_ptr))
                return False;
        if(!prs_uint32("driverpath_ptr", ps, depth, &il->driverpath_ptr))
@@ -3969,30 +4632,37 @@ BOOL spool_io_printer_driver_info_level_6(char *desc, SPOOL_PRINTER_DRIVER_INFO_
                return False;
        if(!prs_align(ps))
                return False;
+
        if(!smb_io_unistr2("environment", &il->environment, il->environment_ptr, ps, depth))
                return False;
        if(!prs_align(ps))
                return False;
+
        if(!smb_io_unistr2("driverpath", &il->driverpath, il->driverpath_ptr, ps, depth))
                return False;
        if(!prs_align(ps))
                return False;
+
        if(!smb_io_unistr2("datafile", &il->datafile, il->datafile_ptr, ps, depth))
                return False;
        if(!prs_align(ps))
                return False;
+
        if(!smb_io_unistr2("configfile", &il->configfile, il->configfile_ptr, ps, depth))
                return False;
        if(!prs_align(ps))
                return False;
+
        if(!smb_io_unistr2("helpfile", &il->helpfile, il->helpfile_ptr, ps, depth))
                return False;
        if(!prs_align(ps))
                return False;
+
        if(!smb_io_unistr2("monitorname", &il->monitorname, il->monitorname_ptr, ps, depth))
                return False;
        if(!prs_align(ps))
                return False;
+
        if(!smb_io_unistr2("defaultdatatype", &il->defaultdatatype, il->defaultdatatype_ptr, ps, depth))
                return False;
        if(!prs_align(ps))
@@ -4027,17 +4697,6 @@ BOOL spool_io_printer_driver_info_level_6(char *desc, SPOOL_PRINTER_DRIVER_INFO_
        return True;
 }
 
-void free_spool_printer_driver_info_level_6(SPOOL_PRINTER_DRIVER_INFO_LEVEL_6 **q_u)
-{
-       SPOOL_PRINTER_DRIVER_INFO_LEVEL_6 *il = *q_u;
-
-       if (il == NULL)
-               return;
-
-       safe_free(il);
-}
-
-
 /*******************************************************************
  convert a buffer of UNICODE strings null terminated
  the buffer is terminated by a NULL
@@ -4049,7 +4708,7 @@ void free_spool_printer_driver_info_level_6(SPOOL_PRINTER_DRIVER_INFO_LEVEL_6 **
 ********************************************************************/  
 static BOOL uniarray_2_dosarray(BUFFER5 *buf5, fstring **ar)
 {
-       fstring f;
+       fstring f, *tar;
        int n = 0;
        char *src;
 
@@ -4059,9 +4718,11 @@ static BOOL uniarray_2_dosarray(BUFFER5 *buf5, fstring **ar)
        *ar = NULL;
 
        while (src < ((char *)buf5->buffer) + buf5->buf_len*2) {
-               unistr_to_dos(f, src, sizeof(f)-1);
+               rpcstr_pull(f, src, sizeof(f)-1, -1, 0);
                src = skip_unibuf(src, 2*buf5->buf_len - PTR_DIFF(src,buf5->buffer));
-               *ar = (fstring *)Realloc(*ar, sizeof(fstring)*(n+2));
+               tar = (fstring *)Realloc(*ar, sizeof(fstring)*(n+2));
+               if (!tar) return False;
+               else *ar = tar;
                fstrcpy((*ar)[n], f);
                n++;
        }
@@ -4075,6 +4736,7 @@ static BOOL uniarray_2_dosarray(BUFFER5 *buf5, fstring **ar)
  and null terminated array 
  and size of array at beginning
 ********************************************************************/  
+
 BOOL smb_io_unibuffer(char *desc, UNISTR2 *buffer, prs_struct *ps, int depth)
 {
        if (buffer==NULL) return False;
@@ -4093,6 +4755,7 @@ BOOL smb_io_unibuffer(char *desc, UNISTR2 *buffer, prs_struct *ps, int depth)
 
 /*******************************************************************
 ********************************************************************/  
+
 BOOL spool_io_printer_driver_info_level(char *desc, SPOOL_PRINTER_DRIVER_INFO_LEVEL *il, prs_struct *ps, int depth)
 {
        prs_debug(ps, depth, desc, "spool_io_printer_driver_info_level");
@@ -4124,23 +4787,140 @@ BOOL spool_io_printer_driver_info_level(char *desc, SPOOL_PRINTER_DRIVER_INFO_LE
        return True;
 }
 
-void free_spool_printer_driver_info_level(SPOOL_PRINTER_DRIVER_INFO_LEVEL *il)
+/*******************************************************************
+ init a SPOOL_Q_ADDPRINTERDRIVER struct
+ ******************************************************************/
+
+BOOL make_spoolss_q_addprinterdriver(
+       TALLOC_CTX *mem_ctx,
+       SPOOL_Q_ADDPRINTERDRIVER *q_u, 
+       const char* srv_name, 
+       uint32 level, 
+       PRINTER_DRIVER_CTR *info)
 {
-       if (il->ptr==0)
-               return;
+       DEBUG(5,("make_spoolss_q_addprinterdriver\n"));
+       
+       q_u->server_name_ptr = (srv_name!=NULL)?1:0;
+       init_unistr2(&q_u->server_name, srv_name, strlen(srv_name)+1);
+       
+       q_u->level = level;
+       
+       q_u->info.level = level;
+       q_u->info.ptr = (info!=NULL)?1:0;
+       switch (level)
+       {
+       /* info level 3 is supported by Windows 95/98, WinNT and Win2k */
+       case 3 :
+               make_spoolss_driver_info_3(mem_ctx, &q_u->info.info_3, info->info3);
+               break;
+               
+       /* info level 6 is supported by WinME and Win2k */
+       case 6:
+               /* WRITEME!!  will add later  --jerry */
+               break;
+               
+       default:
+               DEBUG(0,("make_spoolss_q_addprinterdriver: Unknown info level [%d]\n", level));
+               break;
+       }
+       
+       return True;
+}
 
-       switch (il->level) {
-               case 3:
-                       free_spool_printer_driver_info_level_3(&il->info_3);
-                       break;
-               case 6:
-                       free_spool_printer_driver_info_level_6(&il->info_6);
-                       break;
+BOOL make_spoolss_driver_info_3(
+       TALLOC_CTX *mem_ctx,
+       SPOOL_PRINTER_DRIVER_INFO_LEVEL_3 **spool_drv_info,
+       DRIVER_INFO_3 *info3
+)
+{
+       uint32          len = 0;
+       uint16          *ptr = info3->dependentfiles;
+       BOOL            done = False;
+       BOOL            null_char = False;
+       SPOOL_PRINTER_DRIVER_INFO_LEVEL_3 *inf;
+
+       if (!(inf=(SPOOL_PRINTER_DRIVER_INFO_LEVEL_3*)talloc_zero(mem_ctx, sizeof(SPOOL_PRINTER_DRIVER_INFO_LEVEL_3))))
+               return False;
+       
+       inf->cversion   = info3->version;
+       inf->name_ptr   = (info3->name.buffer!=NULL)?1:0;
+       inf->environment_ptr    = (info3->architecture.buffer!=NULL)?1:0;
+       inf->driverpath_ptr     = (info3->driverpath.buffer!=NULL)?1:0;
+       inf->datafile_ptr       = (info3->datafile.buffer!=NULL)?1:0;
+       inf->configfile_ptr     = (info3->configfile.buffer!=NULL)?1:0;
+       inf->helpfile_ptr       = (info3->helpfile.buffer!=NULL)?1:0;
+       inf->monitorname_ptr    = (info3->monitorname.buffer!=NULL)?1:0;
+       inf->defaultdatatype_ptr        = (info3->defaultdatatype.buffer!=NULL)?1:0;
+
+       init_unistr2_from_unistr(&inf->name, &info3->name);
+       init_unistr2_from_unistr(&inf->environment, &info3->architecture);
+       init_unistr2_from_unistr(&inf->driverpath, &info3->driverpath);
+       init_unistr2_from_unistr(&inf->datafile, &info3->datafile);
+       init_unistr2_from_unistr(&inf->configfile, &info3->configfile);
+       init_unistr2_from_unistr(&inf->helpfile, &info3->helpfile);
+       init_unistr2_from_unistr(&inf->monitorname, &info3->monitorname);
+       init_unistr2_from_unistr(&inf->defaultdatatype, &info3->defaultdatatype);
+
+       while (!done)
+       {
+               switch (*ptr)
+               {
+                       case 0:
+                               /* the null_char BOOL is used to help locate
+                                  two '\0's back to back */
+                               if (null_char)
+                                       done = True;
+                               else
+                                       null_char = True;
+                               break;
+                                       
+                       default:
+                               null_char = False;
+                               ;;
+                               break;                          
+               }
+               len++;
+               ptr++;
+       }
+       inf->dependentfiles_ptr = (info3->dependentfiles != NULL) ? 1 : 0;
+       inf->dependentfilessize = len;
+       if(!make_spoolss_buffer5(mem_ctx, &inf->dependentfiles, len, info3->dependentfiles))
+       {
+               safe_free (inf);
+               return False;
        }
+       
+       *spool_drv_info = inf;
+       
+       return True;
 }
 
 /*******************************************************************
-********************************************************************/  
+ make a BUFFER5 struct from a uint16*
+ ******************************************************************/
+
+BOOL make_spoolss_buffer5(
+       TALLOC_CTX *mem_ctx,
+       BUFFER5 *buf5, 
+       uint32 len, 
+       uint16 *src
+)
+{
+
+       buf5->buf_len = len;
+       if((buf5->buffer=(uint16*)talloc_memdup(mem_ctx, src, sizeof(uint16)*len)) == NULL)
+       {
+               DEBUG(0,("make_spoolss_buffer5: Unable to malloc memory for buffer!\n"));
+               return False;
+       }
+       
+       return True;
+}
+
+/*******************************************************************
+ fill in the prs_struct for a ADDPRINTERDRIVER request PDU
+ ********************************************************************/  
+
 BOOL spoolss_io_q_addprinterdriver(char *desc, SPOOL_Q_ADDPRINTERDRIVER *q_u, prs_struct *ps, int depth)
 {
        prs_debug(ps, depth, desc, "spoolss_io_q_addprinterdriver");
@@ -4166,16 +4946,8 @@ BOOL spoolss_io_q_addprinterdriver(char *desc, SPOOL_Q_ADDPRINTERDRIVER *q_u, pr
 }
 
 /*******************************************************************
- Free the dynamic parts of a printer driver.
 ********************************************************************/  
 
-void free_spoolss_q_addprinterdriver(SPOOL_Q_ADDPRINTERDRIVER *q_u)
-{
-       free_spool_printer_driver_info_level(&q_u->info);
-}
-
-/*******************************************************************
-********************************************************************/  
 BOOL spoolss_io_r_addprinterdriver(char *desc, SPOOL_R_ADDPRINTERDRIVER *q_u, prs_struct *ps, int depth)
 {
        prs_debug(ps, depth, desc, "spoolss_io_r_addprinterdriver");
@@ -4187,9 +4959,9 @@ BOOL spoolss_io_r_addprinterdriver(char *desc, SPOOL_R_ADDPRINTERDRIVER *q_u, pr
        return True;
 }
 
-
 /*******************************************************************
 ********************************************************************/  
+
 BOOL uni_2_asc_printer_driver_3(SPOOL_PRINTER_DRIVER_INFO_LEVEL_3 *uni,
                                 NT_PRINTER_DRIVER_INFO_LEVEL_3 **asc)
 {
@@ -4228,9 +5000,11 @@ BOOL uni_2_asc_printer_driver_3(SPOOL_PRINTER_DRIVER_INFO_LEVEL_3 *uni,
        DEBUGADD(8,( "monitorname:     %s\n", d->monitorname));
        DEBUGADD(8,( "defaultdatatype: %s\n", d->defaultdatatype));
 
-       uniarray_2_dosarray(&(uni->dependentfiles), &(d->dependentfiles) );
-
-       return True;
+       if (uniarray_2_dosarray(&uni->dependentfiles, &d->dependentfiles ))
+               return True;
+       
+       free(*asc);
+       return False;
 }
 
 /*******************************************************************
@@ -4273,10 +5047,16 @@ BOOL uni_2_asc_printer_driver_6(SPOOL_PRINTER_DRIVER_INFO_LEVEL_6 *uni,
        DEBUGADD(8,( "monitorname:     %s\n", d->monitorname));
        DEBUGADD(8,( "defaultdatatype: %s\n", d->defaultdatatype));
 
-       uniarray_2_dosarray(&uni->dependentfiles, &d->dependentfiles );
-       uniarray_2_dosarray(&uni->previousnames, &d->previousnames );
-
+       if (!uniarray_2_dosarray(&uni->dependentfiles, &d->dependentfiles ))
+               goto error;
+       if (!uniarray_2_dosarray(&uni->previousnames, &d->previousnames ))
+               goto error;
+       
        return True;
+       
+error:
+       free(*asc);
+       return False;
 }
 
 BOOL uni_2_asc_printer_info_2(const SPOOL_PRINTER_INFO_LEVEL_2 *uni,
@@ -4332,6 +5112,7 @@ BOOL uni_2_asc_printer_info_2(const SPOOL_PRINTER_INFO_LEVEL_2 *uni,
 /*******************************************************************
  * init a structure.
  ********************************************************************/
+
 BOOL make_spoolss_q_getprinterdriverdir(SPOOL_Q_GETPRINTERDRIVERDIR *q_u,
                                 fstring servername, fstring env_name, uint32 level,
                                 NEW_BUFFER *buffer, uint32 offered)
@@ -4339,17 +5120,17 @@ BOOL make_spoolss_q_getprinterdriverdir(SPOOL_Q_GETPRINTERDRIVERDIR *q_u,
        init_buf_unistr2(&q_u->name, &q_u->name_ptr, servername);
        init_buf_unistr2(&q_u->environment, &q_u->environment_ptr, env_name);
 
-        q_u->level=level;
-        q_u->buffer=buffer;
-        q_u->offered=offered;
+       q_u->level=level;
+       q_u->buffer=buffer;
+       q_u->offered=offered;
 
-        return True;
+       return True;
 }
 
-
 /*******************************************************************
  Parse a SPOOL_Q_GETPRINTERDRIVERDIR structure.
 ********************************************************************/  
+
 BOOL spoolss_io_q_getprinterdriverdir(char *desc, SPOOL_Q_GETPRINTERDRIVERDIR *q_u, prs_struct *ps, int depth)
 {
        prs_debug(ps, depth, desc, "spoolss_io_q_getprinterdriverdir");
@@ -4376,7 +5157,7 @@ BOOL spoolss_io_q_getprinterdriverdir(char *desc, SPOOL_Q_GETPRINTERDRIVERDIR *q
        if(!prs_uint32("level", ps, depth, &q_u->level))
                return False;
                
-       if(!new_spoolss_io_buffer("", ps, depth, q_u->buffer))
+       if(!spoolss_io_buffer("", ps, depth, &q_u->buffer))
                return False;
                
        if(!prs_align(ps))
@@ -4391,6 +5172,7 @@ BOOL spoolss_io_q_getprinterdriverdir(char *desc, SPOOL_Q_GETPRINTERDRIVERDIR *q
 /*******************************************************************
  Parse a SPOOL_R_GETPRINTERDRIVERDIR structure.
 ********************************************************************/  
+
 BOOL spoolss_io_r_getprinterdriverdir(char *desc, SPOOL_R_GETPRINTERDRIVERDIR *r_u, prs_struct *ps, int depth)
 {              
        prs_debug(ps, depth, desc, "spoolss_io_r_getprinterdriverdir");
@@ -4399,7 +5181,7 @@ BOOL spoolss_io_r_getprinterdriverdir(char *desc, SPOOL_R_GETPRINTERDRIVERDIR *r
        if (!prs_align(ps))
                return False;
                
-       if (!new_spoolss_io_buffer("", ps, depth, r_u->buffer))
+       if (!spoolss_io_buffer("", ps, depth, &r_u->buffer))
                return False;
 
        if (!prs_align(ps))
@@ -4416,6 +5198,7 @@ BOOL spoolss_io_r_getprinterdriverdir(char *desc, SPOOL_R_GETPRINTERDRIVERDIR *r
 
 /*******************************************************************
 ********************************************************************/  
+
 BOOL spoolss_io_r_enumprintprocessors(char *desc, SPOOL_R_ENUMPRINTPROCESSORS *r_u, prs_struct *ps, int depth)
 {              
        prs_debug(ps, depth, desc, "spoolss_io_r_enumprintprocessors");
@@ -4424,7 +5207,7 @@ BOOL spoolss_io_r_enumprintprocessors(char *desc, SPOOL_R_ENUMPRINTPROCESSORS *r
        if (!prs_align(ps))
                return False;
                
-       if (!new_spoolss_io_buffer("", ps, depth, r_u->buffer))
+       if (!spoolss_io_buffer("", ps, depth, &r_u->buffer))
                return False;
 
        if (!prs_align(ps))
@@ -4444,6 +5227,7 @@ BOOL spoolss_io_r_enumprintprocessors(char *desc, SPOOL_R_ENUMPRINTPROCESSORS *r
 
 /*******************************************************************
 ********************************************************************/  
+
 BOOL spoolss_io_q_enumprintprocessors(char *desc, SPOOL_Q_ENUMPRINTPROCESSORS *q_u, prs_struct *ps, int depth)
 {
        prs_debug(ps, depth, desc, "spoolss_io_q_enumprintprocessors");
@@ -4471,7 +5255,7 @@ BOOL spoolss_io_q_enumprintprocessors(char *desc, SPOOL_Q_ENUMPRINTPROCESSORS *q
        if (!prs_uint32("level", ps, depth, &q_u->level))
                return False;
                
-       if(!new_spoolss_io_buffer("", ps, depth, q_u->buffer))
+       if(!spoolss_io_buffer("", ps, depth, &q_u->buffer))
                return False;
 
        if (!prs_align(ps))
@@ -4485,6 +5269,58 @@ BOOL spoolss_io_q_enumprintprocessors(char *desc, SPOOL_Q_ENUMPRINTPROCESSORS *q
 
 /*******************************************************************
 ********************************************************************/  
+
+BOOL spoolss_io_q_addprintprocessor(char *desc, SPOOL_Q_ADDPRINTPROCESSOR *q_u, prs_struct *ps, int depth)
+{
+       prs_debug(ps, depth, desc, "spoolss_io_q_addprintprocessor");
+       depth++;
+
+       if (!prs_align(ps))
+               return False;
+               
+       if (!prs_uint32("server_ptr", ps, depth, &q_u->server_ptr))
+               return False;
+       if (!smb_io_unistr2("server", &q_u->server, q_u->server_ptr, ps, depth))
+               return False;
+               
+       if (!prs_align(ps))
+               return False;
+       if (!smb_io_unistr2("environment", &q_u->environment, True, ps, depth))
+               return False;
+               
+       if (!prs_align(ps))
+               return False;
+       if (!smb_io_unistr2("path", &q_u->path, True, ps, depth))
+               return False;
+
+       if (!prs_align(ps))
+               return False;
+       if (!smb_io_unistr2("name", &q_u->name, True, ps, depth))
+               return False;
+
+       return True;
+}
+
+/*******************************************************************
+********************************************************************/  
+
+BOOL spoolss_io_r_addprintprocessor(char *desc, SPOOL_R_ADDPRINTPROCESSOR *r_u, prs_struct *ps, int depth)
+{              
+       prs_debug(ps, depth, desc, "spoolss_io_r_addprintproicessor");
+       depth++;
+
+       if (!prs_align(ps))
+               return False;
+               
+       if (!prs_uint32("status", ps, depth, &r_u->status))
+               return False;
+
+       return True;            
+}
+
+/*******************************************************************
+********************************************************************/  
+
 BOOL spoolss_io_r_enumprintprocdatatypes(char *desc, SPOOL_R_ENUMPRINTPROCDATATYPES *r_u, prs_struct *ps, int depth)
 {              
        prs_debug(ps, depth, desc, "spoolss_io_r_enumprintprocdatatypes");
@@ -4493,7 +5329,7 @@ BOOL spoolss_io_r_enumprintprocdatatypes(char *desc, SPOOL_R_ENUMPRINTPROCDATATY
        if (!prs_align(ps))
                return False;
                
-       if (!new_spoolss_io_buffer("", ps, depth, r_u->buffer))
+       if (!spoolss_io_buffer("", ps, depth, &r_u->buffer))
                return False;
 
        if (!prs_align(ps))
@@ -4513,6 +5349,7 @@ BOOL spoolss_io_r_enumprintprocdatatypes(char *desc, SPOOL_R_ENUMPRINTPROCDATATY
 
 /*******************************************************************
 ********************************************************************/  
+
 BOOL spoolss_io_q_enumprintprocdatatypes(char *desc, SPOOL_Q_ENUMPRINTPROCDATATYPES *q_u, prs_struct *ps, int depth)
 {
        prs_debug(ps, depth, desc, "spoolss_io_q_enumprintprocdatatypes");
@@ -4540,7 +5377,7 @@ BOOL spoolss_io_q_enumprintprocdatatypes(char *desc, SPOOL_Q_ENUMPRINTPROCDATATY
        if (!prs_uint32("level", ps, depth, &q_u->level))
                return False;
                
-       if(!new_spoolss_io_buffer("buffer", ps, depth, q_u->buffer))
+       if(!spoolss_io_buffer("buffer", ps, depth, &q_u->buffer))
                return False;
 
        if (!prs_align(ps))
@@ -4555,6 +5392,7 @@ BOOL spoolss_io_q_enumprintprocdatatypes(char *desc, SPOOL_Q_ENUMPRINTPROCDATATY
 /*******************************************************************
  Parse a SPOOL_Q_ENUMPRINTMONITORS structure.
 ********************************************************************/  
+
 BOOL spoolss_io_q_enumprintmonitors(char *desc, SPOOL_Q_ENUMPRINTMONITORS *q_u, prs_struct *ps, int depth)
 {
        prs_debug(ps, depth, desc, "spoolss_io_q_enumprintmonitors");
@@ -4574,7 +5412,7 @@ BOOL spoolss_io_q_enumprintmonitors(char *desc, SPOOL_Q_ENUMPRINTMONITORS *q_u,
        if (!prs_uint32("level", ps, depth, &q_u->level))
                return False;
                
-       if(!new_spoolss_io_buffer("", ps, depth, q_u->buffer))
+       if(!spoolss_io_buffer("", ps, depth, &q_u->buffer))
                return False;
 
        if (!prs_align(ps))
@@ -4588,6 +5426,7 @@ BOOL spoolss_io_q_enumprintmonitors(char *desc, SPOOL_Q_ENUMPRINTMONITORS *q_u,
 
 /*******************************************************************
 ********************************************************************/  
+
 BOOL spoolss_io_r_enumprintmonitors(char *desc, SPOOL_R_ENUMPRINTMONITORS *r_u, prs_struct *ps, int depth)
 {              
        prs_debug(ps, depth, desc, "spoolss_io_r_enumprintmonitors");
@@ -4596,7 +5435,7 @@ BOOL spoolss_io_r_enumprintmonitors(char *desc, SPOOL_R_ENUMPRINTMONITORS *r_u,
        if (!prs_align(ps))
                return False;
                
-       if (!new_spoolss_io_buffer("", ps, depth, r_u->buffer))
+       if (!spoolss_io_buffer("", ps, depth, &r_u->buffer))
                return False;
 
        if (!prs_align(ps))
@@ -4616,6 +5455,7 @@ BOOL spoolss_io_r_enumprintmonitors(char *desc, SPOOL_R_ENUMPRINTMONITORS *r_u,
 
 /*******************************************************************
 ********************************************************************/  
+
 BOOL spoolss_io_r_enumprinterdata(char *desc, SPOOL_R_ENUMPRINTERDATA *r_u, prs_struct *ps, int depth)
 {      
        prs_debug(ps, depth, desc, "spoolss_io_r_enumprinterdata");
@@ -4625,7 +5465,8 @@ BOOL spoolss_io_r_enumprinterdata(char *desc, SPOOL_R_ENUMPRINTERDATA *r_u, prs_
                return False;
        if(!prs_uint32("valuesize", ps, depth, &r_u->valuesize))
                return False;
-       if(!prs_uint16s(False, "value", ps, depth, r_u->value, r_u->valuesize))
+
+       if(!prs_uint16uni(False, "value", ps, depth, r_u->value, r_u->valuesize ))
                return False;
 
        if(!prs_align(ps))
@@ -4654,6 +5495,7 @@ BOOL spoolss_io_r_enumprinterdata(char *desc, SPOOL_R_ENUMPRINTERDATA *r_u, prs_
 
 /*******************************************************************
 ********************************************************************/  
+
 BOOL spoolss_io_q_enumprinterdata(char *desc, SPOOL_Q_ENUMPRINTERDATA *q_u, prs_struct *ps, int depth)
 {
        prs_debug(ps, depth, desc, "spoolss_io_q_enumprinterdata");
@@ -4675,6 +5517,7 @@ BOOL spoolss_io_q_enumprinterdata(char *desc, SPOOL_Q_ENUMPRINTERDATA *q_u, prs_
 
 /*******************************************************************
 ********************************************************************/  
+
 BOOL make_spoolss_q_enumprinterdata(SPOOL_Q_ENUMPRINTERDATA *q_u,
                const POLICY_HND *hnd,
                uint32 idx, uint32 valuelen, uint32 datalen)
@@ -4689,6 +5532,7 @@ BOOL make_spoolss_q_enumprinterdata(SPOOL_Q_ENUMPRINTERDATA *q_u,
 
 /*******************************************************************
 ********************************************************************/  
+
 BOOL spoolss_io_q_setprinterdata(char *desc, SPOOL_Q_SETPRINTERDATA *q_u, prs_struct *ps, int depth)
 {
        prs_debug(ps, depth, desc, "spoolss_io_q_setprinterdata");
@@ -4716,11 +5560,14 @@ BOOL spoolss_io_q_setprinterdata(char *desc, SPOOL_Q_SETPRINTERDATA *q_u, prs_st
                case 0x3:
                case 0x4:
                case 0x7:
-                       q_u->data=(uint8 *)malloc(q_u->max_len * sizeof(uint8));
-                       if(q_u->data == NULL)
-                               return False;
-                       if(!prs_uint8s(False,"data", ps, depth, q_u->data, q_u->max_len))
-                               return False;
+            if (q_u->max_len) {
+                if (UNMARSHALLING(ps))
+                               q_u->data=(uint8 *)prs_alloc_mem(ps, q_u->max_len * sizeof(uint8));
+                       if(q_u->data == NULL)
+                               return False;
+                       if(!prs_uint8s(False,"data", ps, depth, q_u->data, q_u->max_len))
+                               return False;
+            }
                        if(!prs_align(ps))
                                return False;
                        break;
@@ -4732,13 +5579,9 @@ BOOL spoolss_io_q_setprinterdata(char *desc, SPOOL_Q_SETPRINTERDATA *q_u, prs_st
        return True;
 }
 
-void free_spoolss_q_setprinterdata(SPOOL_Q_SETPRINTERDATA *q_u)
-{
-       safe_free(q_u->data);
-}
-
 /*******************************************************************
 ********************************************************************/  
+
 BOOL spoolss_io_r_setprinterdata(char *desc, SPOOL_R_SETPRINTERDATA *r_u, prs_struct *ps, int depth)
 {
        prs_debug(ps, depth, desc, "spoolss_io_r_setprinterdata");
@@ -4754,6 +5597,7 @@ BOOL spoolss_io_r_setprinterdata(char *desc, SPOOL_R_SETPRINTERDATA *r_u, prs_st
 
 /*******************************************************************
 ********************************************************************/  
+
 BOOL convert_specific_param(NT_PRINTER_PARAM **param, const UNISTR2 *value,
                                uint32 type, const uint8 *data, uint32 len)
 {
@@ -4764,7 +5608,7 @@ BOOL convert_specific_param(NT_PRINTER_PARAM **param, const UNISTR2 *value,
                *param=(NT_PRINTER_PARAM *)malloc(sizeof(NT_PRINTER_PARAM));
                if(*param == NULL)
                        return False;
-               ZERO_STRUCTP(*param);
+               memset((char *)*param, '\0', sizeof(NT_PRINTER_PARAM));
                DEBUGADD(6,("Allocated a new PARAM struct\n"));
        }
        unistr2_to_ascii((*param)->value, value, sizeof((*param)->value)-1);
@@ -4775,19 +5619,22 @@ BOOL convert_specific_param(NT_PRINTER_PARAM **param, const UNISTR2 *value,
        
        (*param)->data_len=len;
        
-       (*param)->data=(uint8 *)malloc(len * sizeof(uint8));
-       if((*param)->data == NULL)
-               return False;
-                       
-       memcpy((*param)->data, data, len);
+       if (len) {
+               (*param)->data=(uint8 *)malloc(len * sizeof(uint8));
+               if((*param)->data == NULL)
+                       return False;
+               memcpy((*param)->data, data, len);
+       }
                
        DEBUGADD(6,("\tvalue:[%s], len:[%d]\n",(*param)->value, (*param)->data_len));
+       dump_data(10, (char *)(*param)->data, (*param)->data_len);
 
        return True;
 }
 
 /*******************************************************************
 ********************************************************************/  
+
 static BOOL spoolss_io_addform(char *desc, FORM *f, uint32 ptr, prs_struct *ps, int depth)
 {
        prs_debug(ps, depth, desc, "spoolss_io_addform");
@@ -4823,6 +5670,41 @@ static BOOL spoolss_io_addform(char *desc, FORM *f, uint32 ptr, prs_struct *ps,
 
 /*******************************************************************
 ********************************************************************/  
+
+BOOL spoolss_io_q_deleteform(char *desc, SPOOL_Q_DELETEFORM *q_u, prs_struct *ps, int depth)
+{
+       prs_debug(ps, depth, desc, "spoolss_io_q_deleteform");
+       depth++;
+
+       if(!prs_align(ps))
+               return False;
+       if(!smb_io_pol_hnd("printer handle", &q_u->handle, ps, depth))
+               return False;
+       if(!smb_io_unistr2("form name", &q_u->name, True, ps, depth))
+               return False;
+
+       return True;
+}
+
+/*******************************************************************
+********************************************************************/  
+
+BOOL spoolss_io_r_deleteform(char *desc, SPOOL_R_DELETEFORM *r_u, prs_struct *ps, int depth)
+{
+       prs_debug(ps, depth, desc, "spoolss_io_r_deleteform");
+       depth++;
+
+       if(!prs_align(ps))
+               return False;
+       if(!prs_uint32("status",        ps, depth, &r_u->status))
+               return False;
+
+       return True;
+}
+
+/*******************************************************************
+********************************************************************/  
+
 BOOL spoolss_io_q_addform(char *desc, SPOOL_Q_ADDFORM *q_u, prs_struct *ps, int depth)
 {
        uint32 useless_ptr=0;
@@ -4851,6 +5733,7 @@ BOOL spoolss_io_q_addform(char *desc, SPOOL_Q_ADDFORM *q_u, prs_struct *ps, int
 
 /*******************************************************************
 ********************************************************************/  
+
 BOOL spoolss_io_r_addform(char *desc, SPOOL_R_ADDFORM *r_u, prs_struct *ps, int depth)
 {
        prs_debug(ps, depth, desc, "spoolss_io_r_addform");
@@ -4866,6 +5749,7 @@ BOOL spoolss_io_r_addform(char *desc, SPOOL_R_ADDFORM *r_u, prs_struct *ps, int
 
 /*******************************************************************
 ********************************************************************/  
+
 BOOL spoolss_io_q_setform(char *desc, SPOOL_Q_SETFORM *q_u, prs_struct *ps, int depth)
 {
        uint32 useless_ptr=0;
@@ -4900,6 +5784,7 @@ BOOL spoolss_io_q_setform(char *desc, SPOOL_Q_SETFORM *q_u, prs_struct *ps, int
 
 /*******************************************************************
 ********************************************************************/  
+
 BOOL spoolss_io_r_setform(char *desc, SPOOL_R_SETFORM *r_u, prs_struct *ps, int depth)
 {
        prs_debug(ps, depth, desc, "spoolss_io_r_setform");
@@ -4916,6 +5801,7 @@ BOOL spoolss_io_r_setform(char *desc, SPOOL_R_SETFORM *r_u, prs_struct *ps, int
 /*******************************************************************
  Parse a SPOOL_R_GETJOB structure.
 ********************************************************************/  
+
 BOOL spoolss_io_r_getjob(char *desc, SPOOL_R_GETJOB *r_u, prs_struct *ps, int depth)
 {              
        prs_debug(ps, depth, desc, "spoolss_io_r_getjob");
@@ -4924,7 +5810,7 @@ BOOL spoolss_io_r_getjob(char *desc, SPOOL_R_GETJOB *r_u, prs_struct *ps, int de
        if (!prs_align(ps))
                return False;
                
-       if (!new_spoolss_io_buffer("", ps, depth, r_u->buffer))
+       if (!spoolss_io_buffer("", ps, depth, &r_u->buffer))
                return False;
 
        if (!prs_align(ps))
@@ -4942,6 +5828,7 @@ BOOL spoolss_io_r_getjob(char *desc, SPOOL_R_GETJOB *r_u, prs_struct *ps, int de
 /*******************************************************************
  Parse a SPOOL_Q_GETJOB structure.
 ********************************************************************/  
+
 BOOL spoolss_io_q_getjob(char *desc, SPOOL_Q_GETJOB *q_u, prs_struct *ps, int depth)
 {
        prs_debug(ps, depth, desc, "");
@@ -4957,7 +5844,7 @@ BOOL spoolss_io_q_getjob(char *desc, SPOOL_Q_GETJOB *q_u, prs_struct *ps, int de
        if(!prs_uint32("level", ps, depth, &q_u->level))
                return False;
        
-       if(!new_spoolss_io_buffer("", ps, depth, q_u->buffer))
+       if(!spoolss_io_buffer("", ps, depth, &q_u->buffer))
                return False;
 
        if(!prs_align(ps))
@@ -4987,8 +5874,6 @@ void free_printer_info_2(PRINTER_INFO_2 *printer)
        if (printer!=NULL) {
                free_devmode(printer->devmode);
                printer->devmode = NULL;
-               if (printer->secdesc != NULL)
-                       free_sec_desc(&printer->secdesc);
                safe_free(printer);
        }
 }
@@ -4996,177 +5881,41 @@ void free_printer_info_2(PRINTER_INFO_2 *printer)
 void free_printer_info_3(PRINTER_INFO_3 *printer)
 {
        if (printer!=NULL) {
-               if (printer->secdesc != NULL)
-                       free_sec_desc(&printer->secdesc);
                safe_free(printer);
        }
 }
 
-void free_spool_printer_info_1(SPOOL_PRINTER_INFO_LEVEL_1 *printer)
-{
-       safe_free(printer);
-}
-
-void free_spool_printer_info_2(SPOOL_PRINTER_INFO_LEVEL_2 *printer)
-{
-       if (printer!=NULL) {
-               if (printer->secdesc != NULL)
-                       free_sec_desc_buf(&printer->secdesc);
-               safe_free(printer);
-       }
-}
-
-void free_spool_printer_info_3(SPOOL_PRINTER_INFO_LEVEL_3 *printer)
-{
-       safe_free(printer);
-}
-
-void free_spool_printer_info_level(SPOOL_PRINTER_INFO_LEVEL *pil)
-{
-       if (pil == NULL)
-               return;
-
-       switch (pil->level) {
-               case 1:
-                       free_spool_printer_info_1(pil->info_1);
-                       break;
-               case 2:
-                       free_spool_printer_info_2(pil->info_2);
-                       break;
-               case 3:
-                       free_spool_printer_info_3(pil->info_3);
-                       break;
-               default:
-                       break;
-       }
-}
-
-static PRINTER_INFO_2 *prt2_dup(const PRINTER_INFO_2* from)
-{
-       PRINTER_INFO_2 *copy = (PRINTER_INFO_2 *)malloc(sizeof(PRINTER_INFO_2));
-       if (copy != NULL) {
-               if (from != NULL)
-                       memcpy(copy, from, sizeof(*copy));
-               else
-                       ZERO_STRUCTP(copy);
-       }
-       return copy;
-}
-
-void free_print2_array(uint32 num_entries, PRINTER_INFO_2 **entries)
-{
-       void(*fn)(void*) = (void(*)(void*))&free_printer_info_2;
-       free_void_array(num_entries, (void**)entries, *fn);
-}
-
-PRINTER_INFO_2 *add_print2_to_array(uint32 *len, PRINTER_INFO_2 ***array,
-                               const PRINTER_INFO_2 *prt)
-{
-       void*(*fn)(const void*) = (void*(*)(const void*))&prt2_dup;
-       return (PRINTER_INFO_2*)add_copy_to_array(len,
-                  (void***)array, (const void*)prt, *fn, True);
-}
-
-static PRINTER_INFO_1 *prt1_dup(const PRINTER_INFO_1* from)
-{
-       PRINTER_INFO_1 *copy = (PRINTER_INFO_1 *)malloc(sizeof(PRINTER_INFO_1));
-       if (copy != NULL) {
-               if (from != NULL)
-                       memcpy(copy, from, sizeof(*copy));
-               else
-                       ZERO_STRUCTP(copy);
-       }
-       return copy;
-}
-
-void free_print1_array(uint32 num_entries, PRINTER_INFO_1 **entries)
+void free_job_info_2(JOB_INFO_2 *job)
 {
-       void(*fn)(void*) = (void(*)(void*))&free;
-       free_void_array(num_entries, (void**)entries, *fn);
+    if (job!=NULL)
+        free_devmode(job->devmode);
 }
 
-PRINTER_INFO_1 *add_print1_to_array(uint32 *len, PRINTER_INFO_1 ***array,
-                               const PRINTER_INFO_1 *prt)
-{
-       void*(*fn)(const void*) = (void*(*)(const void*))&prt1_dup;
-       return (PRINTER_INFO_1*)add_copy_to_array(len,
-                          (void***)array, (const void*)prt, *fn, True);
-}
+/*******************************************************************
+ * init a structure.
+ ********************************************************************/
 
-static JOB_INFO_1 *job1_dup(const JOB_INFO_1* from)
-{
-       JOB_INFO_1 *copy = (JOB_INFO_1 *)malloc(sizeof(JOB_INFO_1));
-       if (copy != NULL)
-       {
-               if (from != NULL)
-               {
-                       memcpy(copy, from, sizeof(*copy));
-               }
-               else
-               {
-                       ZERO_STRUCTP(copy);
-               }
-       }
-       return copy;
-}
+BOOL make_spoolss_q_replyopenprinter(SPOOL_Q_REPLYOPENPRINTER *q_u, 
+                              const fstring string, uint32 printer, uint32 type)
+{      
+       if (q_u == NULL)
+               return False;
 
-void free_job1_array(uint32 num_entries, JOB_INFO_1 **entries)
-{
-       void(*fn)(void*) = (void(*)(void*))&free;
-       free_void_array(num_entries, (void**)entries, *fn);
-}
+       init_unistr2(&q_u->string, string, strlen(string)+1);
 
-JOB_INFO_1 *add_job1_to_array(uint32 *len, JOB_INFO_1 ***array,
-                               const JOB_INFO_1 *job)
-{
-       void*(*fn)(const void*) = (void*(*)(const void*))&job1_dup;
-       return (JOB_INFO_1*)add_copy_to_array(len,
-                          (void***)array, (const void*)job, *fn, True);
-}
+       q_u->printer=printer;
+       q_u->type=type;
 
-static JOB_INFO_2 *job2_dup(const JOB_INFO_2* from)
-{
-       JOB_INFO_2 *copy = (JOB_INFO_2 *)malloc(sizeof(JOB_INFO_2));
-       if (copy != NULL)
-       {
-               if (from != NULL)
-               {
-                       memcpy(copy, from, sizeof(*copy));
-               }
-               else
-               {
-                       ZERO_STRUCTP(copy);
-               }
-       }
-       return copy;
-}
-
-void free_job_info_2(JOB_INFO_2 *job)
-{
-       if (job!=NULL)
-       {
-               free_devmode(job->devmode);
-               free(job);
-       }
-}
-
-void free_job2_array(uint32 num_entries, JOB_INFO_2 **entries)
-{
-       void(*fn)(void*) = (void(*)(void*))&free_job_info_2;
-       free_void_array(num_entries, (void**)entries, *fn);
-}
+       q_u->unknown0=0x0;
+       q_u->unknown1=0x0;
 
-JOB_INFO_2 *add_job2_to_array(uint32 *len, JOB_INFO_2 ***array,
-                               const JOB_INFO_2 *job)
-{
-       void*(*fn)(const void*) = (void*(*)(const void*))&job2_dup;
-       return (JOB_INFO_2*)add_copy_to_array(len,
-                          (void***)array, (const void*)job, *fn, True);
+       return True;
 }
 
 /*******************************************************************
  Parse a SPOOL_Q_REPLYOPENPRINTER structure.
 ********************************************************************/  
+
 BOOL spoolss_io_q_replyopenprinter(char *desc, SPOOL_Q_REPLYOPENPRINTER *q_u, prs_struct *ps, int depth)
 {
        prs_debug(ps, depth, desc, "spoolss_io_q_replyopenprinter");
@@ -5186,7 +5935,9 @@ BOOL spoolss_io_q_replyopenprinter(char *desc, SPOOL_Q_REPLYOPENPRINTER *q_u, pr
        if(!prs_uint32("type", ps, depth, &q_u->type))
                return False;
        
-       if(!new_spoolss_io_buffer("", ps, depth, q_u->buffer))
+       if(!prs_uint32("unknown0", ps, depth, &q_u->unknown0))
+               return False;
+       if(!prs_uint32("unknown1", ps, depth, &q_u->unknown1))
                return False;
 
        return True;
@@ -5195,6 +5946,7 @@ BOOL spoolss_io_q_replyopenprinter(char *desc, SPOOL_Q_REPLYOPENPRINTER *q_u, pr
 /*******************************************************************
  Parse a SPOOL_R_REPLYOPENPRINTER structure.
 ********************************************************************/  
+
 BOOL spoolss_io_r_replyopenprinter(char *desc, SPOOL_R_REPLYOPENPRINTER *r_u, prs_struct *ps, int depth)
 {              
        prs_debug(ps, depth, desc, "spoolss_io_r_replyopenprinter");
@@ -5212,9 +5964,24 @@ BOOL spoolss_io_r_replyopenprinter(char *desc, SPOOL_R_REPLYOPENPRINTER *r_u, pr
        return True;            
 }
 
+/*******************************************************************
+ * init a structure.
+ ********************************************************************/
+
+BOOL make_spoolss_q_reply_closeprinter(SPOOL_Q_REPLYCLOSEPRINTER *q_u, POLICY_HND *hnd)
+{      
+       if (q_u == NULL)
+               return False;
+
+       memcpy(&q_u->handle, hnd, sizeof(q_u->handle));
+
+       return True;
+}
+
 /*******************************************************************
  Parse a SPOOL_Q_REPLYCLOSEPRINTER structure.
 ********************************************************************/  
+
 BOOL spoolss_io_q_replycloseprinter(char *desc, SPOOL_Q_REPLYCLOSEPRINTER *q_u, prs_struct *ps, int depth)
 {
        prs_debug(ps, depth, desc, "spoolss_io_q_replycloseprinter");
@@ -5232,6 +5999,7 @@ BOOL spoolss_io_q_replycloseprinter(char *desc, SPOOL_Q_REPLYCLOSEPRINTER *q_u,
 /*******************************************************************
  Parse a SPOOL_R_REPLYCLOSEPRINTER structure.
 ********************************************************************/  
+
 BOOL spoolss_io_r_replycloseprinter(char *desc, SPOOL_R_REPLYCLOSEPRINTER *r_u, prs_struct *ps, int depth)
 {              
        prs_debug(ps, depth, desc, "spoolss_io_r_replycloseprinter");
@@ -5248,3 +6016,88 @@ BOOL spoolss_io_r_replycloseprinter(char *desc, SPOOL_R_REPLYCLOSEPRINTER *r_u,
 
        return True;            
 }
+
+/*******************************************************************
+ * init a structure.
+ ********************************************************************/
+
+BOOL make_spoolss_q_reply_rrpcn(SPOOL_Q_REPLY_RRPCN *q_u, POLICY_HND *hnd,
+                               uint32 change_low, uint32 change_high)
+{      
+       if (q_u == NULL)
+               return False;
+
+       memcpy(&q_u->handle, hnd, sizeof(q_u->handle));
+
+       q_u->change_low=change_low;
+       q_u->change_high=change_high;
+
+       q_u->unknown0=0x0;
+       q_u->unknown1=0x0;
+
+       q_u->info_ptr=1;
+
+       q_u->info.version=2;
+       q_u->info.flags=PRINTER_NOTIFY_INFO_DISCARDED;
+       q_u->info.count=0;
+
+       return True;
+}
+
+/*******************************************************************
+ Parse a SPOOL_Q_REPLY_RRPCN structure.
+********************************************************************/  
+
+BOOL spoolss_io_q_reply_rrpcn(char *desc, SPOOL_Q_REPLY_RRPCN *q_u, prs_struct *ps, int depth)
+{
+       prs_debug(ps, depth, desc, "spoolss_io_q_reply_rrpcn");
+       depth++;
+
+       if(!prs_align(ps))
+               return False;
+
+       if(!smb_io_pol_hnd("printer handle",&q_u->handle,ps,depth))
+               return False;
+
+       if (!prs_uint32("change_low", ps, depth, &q_u->change_low))
+               return False;
+
+       if (!prs_uint32("change_high", ps, depth, &q_u->change_high))
+               return False;
+
+       if (!prs_uint32("unknown0", ps, depth, &q_u->unknown0))
+               return False;
+
+       if (!prs_uint32("unknown1", ps, depth, &q_u->unknown1))
+               return False;
+
+       if (!prs_uint32("info_ptr", ps, depth, &q_u->info_ptr))
+               return False;
+
+       if(q_u->info_ptr!=0)
+               if(!smb_io_notify_info(desc, &q_u->info, ps, depth))
+                       return False;
+               
+       return True;
+}
+
+/*******************************************************************
+ Parse a SPOOL_R_REPLY_RRPCN structure.
+********************************************************************/  
+
+BOOL spoolss_io_r_reply_rrpcn(char *desc, SPOOL_R_REPLY_RRPCN *r_u, prs_struct *ps, int depth)
+{              
+       prs_debug(ps, depth, desc, "spoolss_io_r_replycloseprinter");
+       depth++;
+
+       if (!prs_align(ps))
+               return False;
+
+       if (!prs_uint32("unknown0", ps, depth, &r_u->unknown0))
+               return False;
+
+       if (!prs_uint32("status", ps, depth, &r_u->status))
+               return False;
+
+       return True;            
+}