diff options
Diffstat (limited to 'source3/rpc_parse')
-rw-r--r-- | source3/rpc_parse/parse_buffer.c | 508 | ||||
-rw-r--r-- | source3/rpc_parse/parse_eventlog.c | 193 | ||||
-rw-r--r-- | source3/rpc_parse/parse_misc.c | 1834 | ||||
-rw-r--r-- | source3/rpc_parse/parse_ntsvcs.c | 147 | ||||
-rw-r--r-- | source3/rpc_parse/parse_prs.c | 1868 | ||||
-rw-r--r-- | source3/rpc_parse/parse_rpc.c | 651 | ||||
-rw-r--r-- | source3/rpc_parse/parse_sec.c | 436 | ||||
-rw-r--r-- | source3/rpc_parse/parse_spoolss.c | 7726 | ||||
-rw-r--r-- | source3/rpc_parse/parse_svcctl.c | 535 |
9 files changed, 13898 insertions, 0 deletions
diff --git a/source3/rpc_parse/parse_buffer.c b/source3/rpc_parse/parse_buffer.c new file mode 100644 index 0000000000..63a73c4b7c --- /dev/null +++ b/source3/rpc_parse/parse_buffer.c @@ -0,0 +1,508 @@ +/* + * Unix SMB/CIFS implementation. + * RPC Pipe client / server routines + * + * 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-2005, + * Copyright (C) Tim Potter 2001-2002. + * + * 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 + * the Free Software Foundation; either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, see <http://www.gnu.org/licenses/>. + */ + +#include "includes.h" + +#undef DBGC_CLASS +#define DBGC_CLASS DBGC_RPC_PARSE + +/********************************************************************** + Initialize a new spoolss buff for use by a client rpc +**********************************************************************/ +void rpcbuf_init(RPC_BUFFER *buffer, uint32 size, TALLOC_CTX *ctx) +{ + buffer->size = size; + buffer->string_at_end = size; + if (prs_init(&buffer->prs, size, ctx, MARSHALL)) + buffer->struct_start = prs_offset(&buffer->prs); + else + buffer->struct_start = 0; +} + +/******************************************************************* + Read/write a RPC_BUFFER struct. +********************************************************************/ + +bool prs_rpcbuffer(const char *desc, prs_struct *ps, int depth, RPC_BUFFER *buffer) +{ + prs_debug(ps, depth, desc, "prs_rpcbuffer"); + depth++; + + /* reading */ + if (UNMARSHALLING(ps)) { + buffer->size=0; + buffer->string_at_end=0; + + if (!prs_uint32("size", ps, depth, &buffer->size)) + return False; + + /* + * 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)) + return False; + + if (!prs_set_offset(&buffer->prs, 0)) + return False; + + if (!prs_set_offset(ps, buffer->size+prs_offset(ps))) + return False; + + buffer->string_at_end=buffer->size; + + return True; + } + else { + bool ret = False; + + if (!prs_uint32("size", ps, depth, &buffer->size)) + goto out; + + if (!prs_append_some_prs_data(ps, &buffer->prs, 0, buffer->size)) + goto out; + + ret = True; + out: + + /* We have finished with the data in buffer->prs - free it. */ + prs_mem_free(&buffer->prs); + + return ret; + } +} + +/******************************************************************* + Read/write an RPC_BUFFER* struct.(allocate memory if unmarshalling) +********************************************************************/ + +bool prs_rpcbuffer_p(const char *desc, prs_struct *ps, int depth, RPC_BUFFER **buffer) +{ + uint32 data_p; + + /* caputure the pointer value to stream */ + + data_p = *buffer ? 0xf000baaa : 0; + + if ( !prs_uint32("ptr", ps, depth, &data_p )) + return False; + + /* we're done if there is no data */ + + if ( !data_p ) + return True; + + if ( UNMARSHALLING(ps) ) { + if ( !(*buffer = PRS_ALLOC_MEM(ps, RPC_BUFFER, 1)) ) + return False; + } else { + /* Marshalling case. - coverity paranoia - should already be ok if data_p != 0 */ + if (!*buffer) { + return True; + } + } + + return prs_rpcbuffer( desc, ps, depth, *buffer); +} + +/**************************************************************************** + Allocate more memory for a RPC_BUFFER. +****************************************************************************/ + +bool rpcbuf_alloc_size(RPC_BUFFER *buffer, uint32 buffer_size) +{ + prs_struct *ps; + uint32 extra_space; + uint32 old_offset; + + /* if we don't need anything. don't do anything */ + + if ( buffer_size == 0x0 ) + return True; + + if (!buffer) { + return False; + } + + ps= &buffer->prs; + + /* damn, I'm doing the reverse operation of prs_grow() :) */ + if (buffer_size < prs_data_size(ps)) + extra_space=0; + else + extra_space = buffer_size - prs_data_size(ps); + + /* + * save the offset and move to the end of the buffer + * prs_grow() checks the extra_space against the offset + */ + old_offset=prs_offset(ps); + prs_set_offset(ps, prs_data_size(ps)); + + if (!prs_grow(ps, extra_space)) + return False; + + prs_set_offset(ps, old_offset); + + buffer->string_at_end=prs_data_size(ps); + + return True; +} + +/******************************************************************* + move a BUFFER from the query to the reply. + As the data pointers in RPC_BUFFER are malloc'ed, not talloc'ed, + this is ok. This is an OPTIMIZATION and is not strictly neccessary. + Clears the memory to zero also. +********************************************************************/ + +void rpcbuf_move(RPC_BUFFER *src, RPC_BUFFER **dest) +{ + if ( !src ) { + *dest = NULL; + return; + } + + prs_switch_type( &src->prs, MARSHALL ); + + if ( !prs_set_offset(&src->prs, 0) ) + return; + + prs_force_dynamic( &src->prs ); + prs_mem_clear( &src->prs ); + + *dest = src; +} + +/******************************************************************* + Get the size of a BUFFER struct. +********************************************************************/ + +uint32 rpcbuf_get_size(RPC_BUFFER *buffer) +{ + return (buffer->size); +} + + +/******************************************************************* + * write a UNICODE string and its relative pointer. + * used by all the RPC structs passing a buffer + * + * As I'm a nice guy, I'm forcing myself to explain this code. + * MS did a good job in the overall spoolss code except in some + * functions where they are passing the API buffer directly in the + * RPC request/reply. That's to maintain compatiility at the API level. + * They could have done it the good way the first time. + * + * So what happen is: the strings are written at the buffer's end, + * in the reverse order of the original structure. Some pointers to + * the strings are also in the buffer. Those are relative to the + * buffer's start. + * + * If you don't understand or want to change that function, + * first get in touch with me: jfm@samba.org + * + ********************************************************************/ + +bool smb_io_relstr(const char *desc, RPC_BUFFER *buffer, int depth, UNISTR *string) +{ + prs_struct *ps=&buffer->prs; + + if (MARSHALLING(ps)) { + uint32 struct_offset = prs_offset(ps); + uint32 relative_offset; + + buffer->string_at_end -= (size_of_relative_string(string) - 4); + if(!prs_set_offset(ps, buffer->string_at_end)) + return False; +#if 0 /* JERRY */ + /* + * Win2k does not align strings in a buffer + * Tested against WinNT 4.0 SP 6a & 2k SP2 --jerry + */ + if (!prs_align(ps)) + return False; +#endif + buffer->string_at_end = prs_offset(ps); + + /* write the string */ + if (!smb_io_unistr(desc, string, ps, depth)) + return False; + + if(!prs_set_offset(ps, struct_offset)) + return False; + + relative_offset=buffer->string_at_end - buffer->struct_start; + /* write its offset */ + if (!prs_uint32("offset", ps, depth, &relative_offset)) + return False; + } + else { + uint32 old_offset; + + /* read the offset */ + if (!prs_uint32("offset", ps, depth, &(buffer->string_at_end))) + return False; + + if (buffer->string_at_end == 0) + return True; + + old_offset = prs_offset(ps); + if(!prs_set_offset(ps, buffer->string_at_end+buffer->struct_start)) + return False; + + /* read the string */ + if (!smb_io_unistr(desc, string, ps, depth)) + return False; + + if(!prs_set_offset(ps, old_offset)) + return False; + } + return True; +} + +/******************************************************************* + * write a array of UNICODE strings and its relative pointer. + * used by 2 RPC structs + ********************************************************************/ + +bool smb_io_relarraystr(const char *desc, RPC_BUFFER *buffer, int depth, uint16 **string) +{ + UNISTR chaine; + + prs_struct *ps=&buffer->prs; + + if (MARSHALLING(ps)) { + uint32 struct_offset = prs_offset(ps); + uint32 relative_offset; + uint16 *p; + uint16 *q; + uint16 zero=0; + p=*string; + q=*string; + + /* first write the last 0 */ + buffer->string_at_end -= 2; + if(!prs_set_offset(ps, buffer->string_at_end)) + return False; + + if(!prs_uint16("leading zero", ps, depth, &zero)) + return False; + + while (p && (*p!=0)) { + while (*q!=0) + q++; + + /* Yes this should be malloc not talloc. Don't change. */ + + chaine.buffer = (uint16 *) + SMB_MALLOC((q-p+1)*sizeof(uint16)); + if (chaine.buffer == NULL) + return False; + + memcpy(chaine.buffer, p, (q-p+1)*sizeof(uint16)); + + buffer->string_at_end -= (q-p+1)*sizeof(uint16); + + if(!prs_set_offset(ps, buffer->string_at_end)) { + SAFE_FREE(chaine.buffer); + return False; + } + + /* write the string */ + if (!smb_io_unistr(desc, &chaine, ps, depth)) { + SAFE_FREE(chaine.buffer); + return False; + } + q++; + p=q; + + SAFE_FREE(chaine.buffer); + } + + if(!prs_set_offset(ps, struct_offset)) + return False; + + relative_offset=buffer->string_at_end - buffer->struct_start; + /* write its offset */ + if (!prs_uint32("offset", ps, depth, &relative_offset)) + return False; + + } 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 */ + if (!prs_uint32("offset", ps, depth, &buffer->string_at_end)) + return False; + + old_offset = prs_offset(ps); + if(!prs_set_offset(ps, buffer->string_at_end + buffer->struct_start)) + return False; + + do { + if (!smb_io_unistr(desc, &chaine, ps, depth)) { + SAFE_FREE(chaine2); + return False; + } + + l_chaine=str_len_uni(&chaine); + + /* 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) { + realloc_size = (l_chaine2+l_chaine+2)*sizeof(uint16); + + /* Yes this should be realloc - it's freed below. JRA */ + + if((chaine2=(uint16 *)SMB_REALLOC(chaine2, realloc_size)) == NULL) { + return False; + } + memcpy(chaine2+l_chaine2, chaine.buffer, (l_chaine+1)*sizeof(uint16)); + l_chaine2+=l_chaine+1; + } + + } while(l_chaine!=0); + + /* 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); + SAFE_FREE(chaine2); + if (!*string) { + return False; + } + } + + if(!prs_set_offset(ps, old_offset)) + return False; + } + return True; +} + +/******************************************************************* + Parse a DEVMODE structure and its relative pointer. +********************************************************************/ + +bool smb_io_relsecdesc(const char *desc, RPC_BUFFER *buffer, int depth, SEC_DESC **secdesc) +{ + prs_struct *ps= &buffer->prs; + + prs_debug(ps, depth, desc, "smb_io_relsecdesc"); + depth++; + + if (MARSHALLING(ps)) { + uint32 struct_offset = prs_offset(ps); + uint32 relative_offset; + + if (! *secdesc) { + relative_offset = 0; + if (!prs_uint32("offset", ps, depth, &relative_offset)) + return False; + return True; + } + + if (*secdesc != NULL) { + buffer->string_at_end -= ndr_size_security_descriptor(*secdesc, 0); + + if(!prs_set_offset(ps, buffer->string_at_end)) + return False; + /* write the secdesc */ + if (!sec_io_desc(desc, secdesc, ps, depth)) + return False; + + if(!prs_set_offset(ps, struct_offset)) + return False; + } + + relative_offset=buffer->string_at_end - buffer->struct_start; + /* write its offset */ + + if (!prs_uint32("offset", ps, depth, &relative_offset)) + return False; + } else { + uint32 old_offset; + + /* read the offset */ + if (!prs_uint32("offset", ps, depth, &buffer->string_at_end)) + return False; + + old_offset = prs_offset(ps); + if(!prs_set_offset(ps, buffer->string_at_end + buffer->struct_start)) + return False; + + /* read the sd */ + if (!sec_io_desc(desc, secdesc, ps, depth)) + return False; + + if(!prs_set_offset(ps, old_offset)) + return False; + } + return True; +} + + + +/******************************************************************* + * return the length of a UNICODE string in number of char, includes: + * - the leading zero + * - the relative pointer size + ********************************************************************/ + +uint32 size_of_relative_string(UNISTR *string) +{ + uint32 size=0; + + size=str_len_uni(string); /* the string length */ + size=size+1; /* add the trailing zero */ + size=size*2; /* convert in char */ + size=size+4; /* add the size of the ptr */ + +#if 0 /* JERRY */ + /* + * Do not include alignment as Win2k does not align relative + * strings within a buffer --jerry + */ + /* Ensure size is 4 byte multiple (prs_align is being called...). */ + /* size += ((4 - (size & 3)) & 3); */ +#endif + + return size; +} + diff --git a/source3/rpc_parse/parse_eventlog.c b/source3/rpc_parse/parse_eventlog.c new file mode 100644 index 0000000000..2ff217eb9e --- /dev/null +++ b/source3/rpc_parse/parse_eventlog.c @@ -0,0 +1,193 @@ +/* + * Unix SMB/CIFS implementation. + * RPC Pipe client / server routines + * Copyright (C) Marcin Krzysztof Porwit 2005. + * + * 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 + * the Free Software Foundation; either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, see <http://www.gnu.org/licenses/>. + */ + +#include "includes.h" + +#undef DBGC_CLASS +#define DBGC_CLASS DBGC_RPC_PARSE + +/******************************************************************** +********************************************************************/ + +bool eventlog_io_q_read_eventlog(const char *desc, EVENTLOG_Q_READ_EVENTLOG *q_u, + prs_struct *ps, int depth) +{ + if(q_u == NULL) + return False; + + prs_debug(ps, depth, desc, "eventlog_io_q_read_eventlog"); + depth++; + + if(!(prs_align(ps))) + return False; + + if(!(smb_io_pol_hnd("log handle", &(q_u->handle), ps, depth))) + return False; + + if(!(prs_uint32("read flags", ps, depth, &(q_u->flags)))) + return False; + + if(!(prs_uint32("read offset", ps, depth, &(q_u->offset)))) + return False; + + if(!(prs_uint32("read buf size", ps, depth, &(q_u->max_read_size)))) + return False; + + return True; +} +/** Structure of response seems to be: + DWORD num_bytes_in_resp -- MUST be the same as q_u->max_read_size + for i=0..n + EVENTLOGRECORD record + DWORD sent_size -- sum of EVENTLOGRECORD lengths if records returned, 0 otherwise + DWORD real_size -- 0 if records returned, otherwise length of next record to be returned + WERROR status */ +bool eventlog_io_r_read_eventlog(const char *desc, + EVENTLOG_Q_READ_EVENTLOG *q_u, + EVENTLOG_R_READ_EVENTLOG *r_u, + prs_struct *ps, + int depth) +{ + Eventlog_entry *entry; + uint32 record_written = 0; + uint32 record_total = 0; + + if(r_u == NULL) + return False; + + prs_debug(ps, depth, desc, "eventlog_io_r_read_eventlog"); + depth++; + + /* First, see if we've read more logs than we can output */ + + if(r_u->num_bytes_in_resp > q_u->max_read_size) { + entry = r_u->entry; + + /* remove the size of the last entry from the list */ + + while(entry->next != NULL) + entry = entry->next; + + r_u->num_bytes_in_resp -= entry->record.length; + + /* do not output the last log entry */ + + r_u->num_records--; + } + + entry = r_u->entry; + record_total = r_u->num_records; + + if(r_u->num_bytes_in_resp != 0) + r_u->sent_size = r_u->num_bytes_in_resp; + else + r_u->real_size = r_u->bytes_in_next_record; + + if(!(prs_align(ps))) + return False; + if(!(prs_uint32("bytes in resp", ps, depth, &(q_u->max_read_size)))) + return False; + + while(entry != NULL && record_written < record_total) + { + DEBUG(11, ("eventlog_io_r_read_eventlog: writing record [%d] out of [%d].\n", record_written, record_total)); + + /* Encode the actual eventlog record record */ + + if(!(prs_uint32("length", ps, depth, &(entry->record.length)))) + return False; + if(!(prs_uint32("reserved", ps, depth, &(entry->record.reserved1)))) + return False; + if(!(prs_uint32("record number", ps, depth, &(entry->record.record_number)))) + return False; + if(!(prs_uint32("time generated", ps, depth, &(entry->record.time_generated)))) + return False; + if(!(prs_uint32("time written", ps, depth, &(entry->record.time_written)))) + return False; + if(!(prs_uint32("event id", ps, depth, &(entry->record.event_id)))) + return False; + if(!(prs_uint16("event type", ps, depth, &(entry->record.event_type)))) + return False; + if(!(prs_uint16("num strings", ps, depth, &(entry->record.num_strings)))) + return False; + if(!(prs_uint16("event category", ps, depth, &(entry->record.event_category)))) + return False; + if(!(prs_uint16("reserved2", ps, depth, &(entry->record.reserved2)))) + return False; + if(!(prs_uint32("closing record", ps, depth, &(entry->record.closing_record_number)))) + return False; + if(!(prs_uint32("string offset", ps, depth, &(entry->record.string_offset)))) + return False; + if(!(prs_uint32("user sid length", ps, depth, &(entry->record.user_sid_length)))) + return False; + if(!(prs_uint32("user sid offset", ps, depth, &(entry->record.user_sid_offset)))) + return False; + if(!(prs_uint32("data length", ps, depth, &(entry->record.data_length)))) + return False; + if(!(prs_uint32("data offset", ps, depth, &(entry->record.data_offset)))) + return False; + if(!(prs_align(ps))) + return False; + + /* Now encoding data */ + + if(!(prs_uint8s(False, "buffer", ps, depth, entry->data, + entry->record.length - sizeof(Eventlog_record) - sizeof(entry->record.length)))) + { + return False; + } + + if(!(prs_align(ps))) + return False; + if(!(prs_uint32("length 2", ps, depth, &(entry->record.length)))) + return False; + + entry = entry->next; + record_written++; + + } /* end of encoding EVENTLOGRECORD */ + + /* Now pad with whitespace until the end of the response buffer */ + + if (q_u->max_read_size - r_u->num_bytes_in_resp) { + if (!r_u->end_of_entries_padding) { + return False; + } + + if(!(prs_uint8s(False, "end of entries padding", ps, + depth, r_u->end_of_entries_padding, + (q_u->max_read_size - r_u->num_bytes_in_resp)))) { + free(r_u->end_of_entries_padding); + return False; + } + + free(r_u->end_of_entries_padding); + } + + /* We had better be DWORD aligned here */ + + if(!(prs_uint32("sent size", ps, depth, &(r_u->sent_size)))) + return False; + if(!(prs_uint32("real size", ps, depth, &(r_u->real_size)))) + return False; + if(!(prs_ntstatus("status code", ps, depth, &r_u->status))) + return False; + + return True; +} diff --git a/source3/rpc_parse/parse_misc.c b/source3/rpc_parse/parse_misc.c new file mode 100644 index 0000000000..cf989c8b5e --- /dev/null +++ b/source3/rpc_parse/parse_misc.c @@ -0,0 +1,1834 @@ +/* + * Unix SMB/CIFS implementation. + * RPC Pipe client / server routines + * Copyright (C) Andrew Tridgell 1992-1997, + * Copyright (C) Luke Kenneth Casson Leighton 1996-1997, + * Copyright (C) Paul Ashton 1997. + * Copyright (C) Gerald (Jerry) Carter 2005 + * + * 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 + * the Free Software Foundation; either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, see <http://www.gnu.org/licenses/>. + */ + +#include "includes.h" + +#undef DBGC_CLASS +#define DBGC_CLASS DBGC_RPC_PARSE + +/******************************************************************* + Reads or writes a UTIME type. +********************************************************************/ + +static bool smb_io_utime(const char *desc, UTIME *t, prs_struct *ps, int depth) +{ + if (t == NULL) + return False; + + prs_debug(ps, depth, desc, "smb_io_utime"); + depth++; + + if(!prs_align(ps)) + return False; + + if(!prs_uint32 ("time", ps, depth, &t->time)) + return False; + + return True; +} + +/******************************************************************* + Reads or writes an NTTIME structure. +********************************************************************/ + +bool smb_io_time(const char *desc, NTTIME *nttime, prs_struct *ps, int depth) +{ + uint32 low, high; + if (nttime == NULL) + return False; + + prs_debug(ps, depth, desc, "smb_io_time"); + depth++; + + if(!prs_align(ps)) + return False; + + if (MARSHALLING(ps)) { + low = *nttime & 0xFFFFFFFF; + high = *nttime >> 32; + } + + if(!prs_uint32("low ", ps, depth, &low)) /* low part */ + return False; + if(!prs_uint32("high", ps, depth, &high)) /* high part */ + return False; + + if (UNMARSHALLING(ps)) { + *nttime = (((uint64_t)high << 32) + low); + } + + return True; +} + +/******************************************************************* + Reads or writes an NTTIME structure. +********************************************************************/ + +bool smb_io_nttime(const char *desc, prs_struct *ps, int depth, NTTIME *nttime) +{ + return smb_io_time( desc, nttime, ps, depth ); +} + +/******************************************************************* + Gets an enumeration handle from an ENUM_HND structure. +********************************************************************/ + +uint32 get_enum_hnd(ENUM_HND *enh) +{ + return (enh && enh->ptr_hnd != 0) ? enh->handle : 0; +} + +/******************************************************************* + Inits an ENUM_HND structure. +********************************************************************/ + +void init_enum_hnd(ENUM_HND *enh, uint32 hnd) +{ + DEBUG(5,("smb_io_enum_hnd\n")); + + enh->ptr_hnd = (hnd != 0) ? 1 : 0; + enh->handle = hnd; +} + +/******************************************************************* + Reads or writes an ENUM_HND structure. +********************************************************************/ + +bool smb_io_enum_hnd(const char *desc, ENUM_HND *hnd, prs_struct *ps, int depth) +{ + if (hnd == NULL) + return False; + + prs_debug(ps, depth, desc, "smb_io_enum_hnd"); + depth++; + + if(!prs_align(ps)) + return False; + + if(!prs_uint32("ptr_hnd", ps, depth, &hnd->ptr_hnd)) /* pointer */ + return False; + + if (hnd->ptr_hnd != 0) { + if(!prs_uint32("handle ", ps, depth, &hnd->handle )) /* enum handle */ + return False; + } + + return True; +} + +/******************************************************************* + Reads or writes a DOM_SID structure. +********************************************************************/ + +bool smb_io_dom_sid(const char *desc, DOM_SID *sid, prs_struct *ps, int depth) +{ + int i; + + if (sid == NULL) + return False; + + prs_debug(ps, depth, desc, "smb_io_dom_sid"); + depth++; + + if(!prs_uint8 ("sid_rev_num", ps, depth, &sid->sid_rev_num)) + return False; + + if(!prs_uint8 ("num_auths ", ps, depth, &sid->num_auths)) + return False; + + for (i = 0; i < 6; i++) + { + fstring tmp; + slprintf(tmp, sizeof(tmp) - 1, "id_auth[%d] ", i); + if(!prs_uint8 (tmp, ps, depth, &sid->id_auth[i])) + return False; + } + + /* oops! XXXX should really issue a warning here... */ + if (sid->num_auths > MAXSUBAUTHS) + sid->num_auths = MAXSUBAUTHS; + + if(!prs_uint32s(False, "sub_auths ", ps, depth, sid->sub_auths, sid->num_auths)) + return False; + + return True; +} + +/******************************************************************* + Inits a DOM_SID2 structure. +********************************************************************/ + +void init_dom_sid2(DOM_SID2 *sid2, const DOM_SID *sid) +{ + sid2->sid = *sid; + sid2->num_auths = sid2->sid.num_auths; +} + +/******************************************************************* + Reads or writes a DOM_SID2 structure. +********************************************************************/ + +bool smb_io_dom_sid2_p(const char *desc, prs_struct *ps, int depth, DOM_SID2 **sid2) +{ + uint32 data_p; + + /* caputure the pointer value to stream */ + + data_p = *sid2 ? 0xf000baaa : 0; + + if ( !prs_uint32("dom_sid2_p", ps, depth, &data_p )) + return False; + + /* we're done if there is no data */ + + if ( !data_p ) + return True; + + if (UNMARSHALLING(ps)) { + if ( !(*sid2 = PRS_ALLOC_MEM(ps, DOM_SID2, 1)) ) + return False; + } + + return True; +} +/******************************************************************* + Reads or writes a DOM_SID2 structure. +********************************************************************/ + +bool smb_io_dom_sid2(const char *desc, DOM_SID2 *sid, prs_struct *ps, int depth) +{ + if (sid == NULL) + return False; + + prs_debug(ps, depth, desc, "smb_io_dom_sid2"); + depth++; + + if(!prs_align(ps)) + return False; + + if(!prs_uint32("num_auths", ps, depth, &sid->num_auths)) + return False; + + if(!smb_io_dom_sid("sid", &sid->sid, ps, depth)) + return False; + + return True; +} + +/******************************************************************* + Reads or writes a struct GUID +********************************************************************/ + +bool smb_io_uuid(const char *desc, struct GUID *uuid, + prs_struct *ps, int depth) +{ + if (uuid == NULL) + return False; + + prs_debug(ps, depth, desc, "smb_io_uuid"); + depth++; + + if(!prs_uint32 ("data ", ps, depth, &uuid->time_low)) + return False; + if(!prs_uint16 ("data ", ps, depth, &uuid->time_mid)) + return False; + if(!prs_uint16 ("data ", ps, depth, &uuid->time_hi_and_version)) + return False; + + if(!prs_uint8s (False, "data ", ps, depth, uuid->clock_seq, sizeof(uuid->clock_seq))) + return False; + if(!prs_uint8s (False, "data ", ps, depth, uuid->node, sizeof(uuid->node))) + return False; + + return True; +} + +/******************************************************************* +creates a STRHDR structure. +********************************************************************/ + +void init_str_hdr(STRHDR *hdr, int max_len, int len, uint32 buffer) +{ + hdr->str_max_len = max_len; + hdr->str_str_len = len; + hdr->buffer = buffer; +} + +/******************************************************************* + Reads or writes a STRHDR structure. +********************************************************************/ + +bool smb_io_strhdr(const char *desc, STRHDR *hdr, prs_struct *ps, int depth) +{ + if (hdr == NULL) + return False; + + prs_debug(ps, depth, desc, "smb_io_strhdr"); + depth++; + + if(!prs_align(ps)) + return False; + + if(!prs_uint16("str_str_len", ps, depth, &hdr->str_str_len)) + return False; + if(!prs_uint16("str_max_len", ps, depth, &hdr->str_max_len)) + return False; + if(!prs_uint32("buffer ", ps, depth, &hdr->buffer)) + return False; + + return True; +} + +/******************************************************************* + Inits a UNIHDR structure. +********************************************************************/ + +void init_uni_hdr(UNIHDR *hdr, UNISTR2 *str2) +{ + hdr->uni_str_len = 2 * (str2->uni_str_len); + hdr->uni_max_len = 2 * (str2->uni_max_len); + hdr->buffer = (str2->uni_str_len != 0) ? 1 : 0; +} + +/******************************************************************* + Reads or writes a UNIHDR structure. +********************************************************************/ + +bool smb_io_unihdr(const char *desc, UNIHDR *hdr, prs_struct *ps, int depth) +{ + if (hdr == NULL) + return False; + + prs_debug(ps, depth, desc, "smb_io_unihdr"); + depth++; + + if(!prs_align(ps)) + return False; + + if(!prs_uint16("uni_str_len", ps, depth, &hdr->uni_str_len)) + return False; + if(!prs_uint16("uni_max_len", ps, depth, &hdr->uni_max_len)) + return False; + if(!prs_uint32("buffer ", ps, depth, &hdr->buffer)) + return False; + + return True; +} + +/******************************************************************* + Inits a BUFHDR structure. +********************************************************************/ + +void init_buf_hdr(BUFHDR *hdr, int max_len, int len) +{ + hdr->buf_max_len = max_len; + hdr->buf_len = len; +} + +/******************************************************************* + prs_uint16 wrapper. Call this and it sets up a pointer to where the + uint16 should be stored, or gets the size if reading. + ********************************************************************/ + +bool smb_io_hdrbuf_pre(const char *desc, BUFHDR *hdr, prs_struct *ps, int depth, uint32 *offset) +{ + (*offset) = prs_offset(ps); + if (ps->io) { + + /* reading. */ + + if(!smb_io_hdrbuf(desc, hdr, ps, depth)) + return False; + + } else { + + /* writing. */ + + if(!prs_set_offset(ps, prs_offset(ps) + (sizeof(uint32) * 2))) + return False; + } + + return True; +} + +/******************************************************************* + smb_io_hdrbuf wrapper. Call this and it retrospectively stores the size. + Does nothing on reading, as that is already handled by ...._pre() + ********************************************************************/ + +bool smb_io_hdrbuf_post(const char *desc, BUFHDR *hdr, prs_struct *ps, int depth, + uint32 ptr_hdrbuf, uint32 max_len, uint32 len) +{ + if (!ps->io) { + /* writing: go back and do a retrospective job. i hate this */ + + uint32 old_offset = prs_offset(ps); + + init_buf_hdr(hdr, max_len, len); + if(!prs_set_offset(ps, ptr_hdrbuf)) + return False; + if(!smb_io_hdrbuf(desc, hdr, ps, depth)) + return False; + + if(!prs_set_offset(ps, old_offset)) + return False; + } + + return True; +} + +/******************************************************************* + Reads or writes a BUFHDR structure. +********************************************************************/ + +bool smb_io_hdrbuf(const char *desc, BUFHDR *hdr, prs_struct *ps, int depth) +{ + if (hdr == NULL) + return False; + + prs_debug(ps, depth, desc, "smb_io_hdrbuf"); + depth++; + + if(!prs_align(ps)) + return False; + + if(!prs_uint32("buf_max_len", ps, depth, &hdr->buf_max_len)) + return False; + if(!prs_uint32("buf_len ", ps, depth, &hdr->buf_len)) + return False; + + return True; +} + +/******************************************************************* + Inits a UNISTR structure. +********************************************************************/ + +void init_unistr(UNISTR *str, const char *buf) +{ + size_t len; + + if (buf == NULL) { + str->buffer = NULL; + return; + } + + len = rpcstr_push_talloc(talloc_tos(), &str->buffer, buf); + if (len == (size_t)-1) { + str->buffer = NULL; + } +} + +/******************************************************************* +reads or writes a UNISTR structure. +XXXX NOTE: UNISTR structures NEED to be null-terminated. +********************************************************************/ + +bool smb_io_unistr(const char *desc, UNISTR *uni, prs_struct *ps, int depth) +{ + if (uni == NULL) + return False; + + prs_debug(ps, depth, desc, "smb_io_unistr"); + depth++; + + if(!prs_unistr("unistr", ps, depth, uni)) + return False; + + return True; +} + +/******************************************************************* + Allocate the RPC_DATA_BLOB memory. +********************************************************************/ + +static void create_rpc_blob(RPC_DATA_BLOB *str, size_t len) +{ + if (len) { + str->buffer = (uint8 *)TALLOC_ZERO(talloc_tos(), len); + if (str->buffer == NULL) + smb_panic("create_rpc_blob: talloc fail"); + str->buf_len = len; + } else { + str->buffer = NULL; + str->buf_len = 0; + } +} + +/******************************************************************* + Inits a RPC_DATA_BLOB structure from a uint32 +********************************************************************/ + +void init_rpc_blob_uint32(RPC_DATA_BLOB *str, uint32 val) +{ + ZERO_STRUCTP(str); + + /* set up string lengths. */ + create_rpc_blob(str, sizeof(uint32)); + SIVAL(str->buffer, 0, val); +} + +/******************************************************************* + Inits a RPC_DATA_BLOB structure. +********************************************************************/ + +void init_rpc_blob_str(RPC_DATA_BLOB *str, const char *buf, int len) +{ + ZERO_STRUCTP(str); + + /* set up string lengths. */ + if (len) { + create_rpc_blob(str, len*2); + rpcstr_push(str->buffer, buf, (size_t)str->buf_len, STR_TERMINATE); + } +} + +/******************************************************************* + Inits a RPC_DATA_BLOB structure from a hex string. +********************************************************************/ + +void init_rpc_blob_hex(RPC_DATA_BLOB *str, const char *buf) +{ + ZERO_STRUCTP(str); + if (buf && *buf) { + size_t len = strlen(buf); + create_rpc_blob(str, len); + str->buf_len = strhex_to_str((char *)str->buffer, str->buf_len, + buf, len); + } +} + +/******************************************************************* + Inits a RPC_DATA_BLOB structure. +********************************************************************/ + +void init_rpc_blob_bytes(RPC_DATA_BLOB *str, uint8 *buf, size_t len) +{ + ZERO_STRUCTP(str); + + /* max buffer size (allocated size) */ + if (buf != NULL && len) { + create_rpc_blob(str, len); + memcpy(str->buffer, buf, len); + } + str->buf_len = len; +} + +/******************************************************************* +reads or writes a BUFFER5 structure. +the buf_len member tells you how large the buffer is. +********************************************************************/ +bool smb_io_buffer5(const char *desc, BUFFER5 *buf5, prs_struct *ps, int depth) +{ + prs_debug(ps, depth, desc, "smb_io_buffer5"); + depth++; + + if (buf5 == NULL) return False; + + if(!prs_align(ps)) + return False; + if(!prs_uint32("buf_len", ps, depth, &buf5->buf_len)) + return False; + + if(buf5->buf_len) { + if(!prs_buffer5(True, "buffer" , ps, depth, buf5)) + return False; + } + + return True; +} + +/******************************************************************* + Inits a REGVAL_BUFFER structure. +********************************************************************/ + +void init_regval_buffer(REGVAL_BUFFER *str, const uint8 *buf, size_t len) +{ + ZERO_STRUCTP(str); + + /* max buffer size (allocated size) */ + str->buf_max_len = len; + str->offset = 0; + str->buf_len = buf != NULL ? len : 0; + + if (buf != NULL) { + SMB_ASSERT(str->buf_max_len >= str->buf_len); + str->buffer = (uint16 *)TALLOC_ZERO(talloc_tos(), + str->buf_max_len); + if (str->buffer == NULL) + smb_panic("init_regval_buffer: talloc fail"); + memcpy(str->buffer, buf, str->buf_len); + } +} + +/******************************************************************* + Reads or writes a REGVAL_BUFFER structure. + the uni_max_len member tells you how large the buffer is. + the uni_str_len member tells you how much of the buffer is really used. +********************************************************************/ + +bool smb_io_regval_buffer(const char *desc, prs_struct *ps, int depth, REGVAL_BUFFER *buf2) +{ + + prs_debug(ps, depth, desc, "smb_io_regval_buffer"); + depth++; + + if(!prs_align(ps)) + return False; + + if(!prs_uint32("buf_max_len", ps, depth, &buf2->buf_max_len)) + return False; + if(!prs_uint32("offset ", ps, depth, &buf2->offset)) + return False; + if(!prs_uint32("buf_len ", ps, depth, &buf2->buf_len)) + return False; + + /* buffer advanced by indicated length of string + NOT by searching for null-termination */ + + if(!prs_regval_buffer(True, "buffer ", ps, depth, buf2)) + return False; + + return True; +} + +/******************************************************************* +creates a UNISTR2 structure: sets up the buffer, too +********************************************************************/ + +void init_buf_unistr2(UNISTR2 *str, uint32 *ptr, const char *buf) +{ + if (buf != NULL) { + *ptr = 1; + init_unistr2(str, buf, UNI_STR_TERMINATE); + } else { + *ptr = 0; + init_unistr2(str, NULL, UNI_FLAGS_NONE); + + } +} + +/******************************************************************* + Copies a UNISTR2 structure. +********************************************************************/ + +void copy_unistr2(UNISTR2 *str, const UNISTR2 *from) +{ + if (from->buffer == NULL) { + ZERO_STRUCTP(str); + return; + } + + SMB_ASSERT(from->uni_max_len >= from->uni_str_len); + + str->uni_max_len = from->uni_max_len; + str->offset = from->offset; + str->uni_str_len = from->uni_str_len; + + /* the string buffer is allocated to the maximum size + (the the length of the source string) to prevent + reallocation of memory. */ + if (str->buffer == NULL) { + if (str->uni_max_len) { + str->buffer = (uint16 *)TALLOC_ZERO_ARRAY(talloc_tos(), uint16, str->uni_max_len); + if ((str->buffer == NULL)) { + smb_panic("copy_unistr2: talloc fail"); + return; + } + /* copy the string */ + memcpy(str->buffer, from->buffer, str->uni_max_len*sizeof(uint16)); + } else { + str->buffer = NULL; + } + } +} + +/******************************************************************* + Creates a STRING2 structure. +********************************************************************/ + +void init_string2(STRING2 *str, const char *buf, size_t max_len, size_t str_len) +{ + /* set up string lengths. */ + SMB_ASSERT(max_len >= str_len); + + /* Ensure buf is valid if str_len was set. Coverity check. */ + if (str_len && !buf) { + return; + } + + str->str_max_len = max_len; + str->offset = 0; + str->str_str_len = str_len; + + /* store the string */ + if(str_len != 0) { + str->buffer = (uint8 *)TALLOC_ZERO(talloc_tos(), + str->str_max_len); + if (str->buffer == NULL) + smb_panic("init_string2: malloc fail"); + memcpy(str->buffer, buf, str_len); + } +} + +/******************************************************************* + Reads or writes a STRING2 structure. + XXXX NOTE: STRING2 structures need NOT be null-terminated. + the str_str_len member tells you how long the string is; + the str_max_len member tells you how large the buffer is. +********************************************************************/ + +bool smb_io_string2(const char *desc, STRING2 *str2, uint32 buffer, prs_struct *ps, int depth) +{ + if (str2 == NULL) + return False; + + if (buffer) { + + prs_debug(ps, depth, desc, "smb_io_string2"); + depth++; + + if(!prs_align(ps)) + return False; + + if(!prs_uint32("str_max_len", ps, depth, &str2->str_max_len)) + return False; + if(!prs_uint32("offset ", ps, depth, &str2->offset)) + return False; + if(!prs_uint32("str_str_len", ps, depth, &str2->str_str_len)) + return False; + + /* buffer advanced by indicated length of string + NOT by searching for null-termination */ + if(!prs_string2(True, "buffer ", ps, depth, str2)) + return False; + + } else { + + prs_debug(ps, depth, desc, "smb_io_string2 - NULL"); + depth++; + memset((char *)str2, '\0', sizeof(*str2)); + + } + + return True; +} + +/******************************************************************* + Inits a UNISTR2 structure. +********************************************************************/ + +void init_unistr2(UNISTR2 *str, const char *buf, enum unistr2_term_codes flags) +{ + size_t len = 0; + uint32 num_chars = 0; + + if (buf) { + /* We always null terminate the copy. */ + len = strlen(buf) + 1; + if ( flags == UNI_STR_DBLTERMINATE ) + len++; + } + + if (buf == NULL || len == 0) { + /* no buffer -- nothing to do */ + str->uni_max_len = 0; + str->offset = 0; + str->uni_str_len = 0; + + return; + } + + + str->buffer = TALLOC_ZERO_ARRAY(talloc_tos(), uint16, len); + if (str->buffer == NULL) { + smb_panic("init_unistr2: malloc fail"); + return; + } + + /* Ensure len is the length in *bytes* */ + len *= sizeof(uint16); + + /* + * The UNISTR2 must be initialized !!! + * jfm, 7/7/2001. + */ + if (buf) { + rpcstr_push((char *)str->buffer, buf, len, STR_TERMINATE); + num_chars = strlen_w(str->buffer); + if (flags == UNI_STR_TERMINATE || flags == UNI_MAXLEN_TERMINATE) { + num_chars++; + } + if ( flags == UNI_STR_DBLTERMINATE ) + num_chars += 2; + } + + str->uni_max_len = num_chars; + str->offset = 0; + str->uni_str_len = num_chars; + if ( num_chars && ((flags == UNI_MAXLEN_TERMINATE) || (flags == UNI_BROKEN_NON_NULL)) ) + str->uni_max_len++; +} + +/******************************************************************* + Inits a UNISTR4 structure. +********************************************************************/ + +void init_unistr4(UNISTR4 *uni4, const char *buf, enum unistr2_term_codes flags) +{ + uni4->string = TALLOC_P( talloc_tos(), UNISTR2 ); + if (!uni4->string) { + smb_panic("init_unistr4: talloc fail"); + return; + } + init_unistr2( uni4->string, buf, flags ); + + uni4->length = 2 * (uni4->string->uni_str_len); + uni4->size = 2 * (uni4->string->uni_max_len); +} + +void init_unistr4_w( TALLOC_CTX *ctx, UNISTR4 *uni4, const smb_ucs2_t *buf ) +{ + uni4->string = TALLOC_P( ctx, UNISTR2 ); + if (!uni4->string) { + smb_panic("init_unistr4_w: talloc fail"); + return; + } + init_unistr2_w( ctx, uni4->string, buf ); + + uni4->length = 2 * (uni4->string->uni_str_len); + uni4->size = 2 * (uni4->string->uni_max_len); +} + +/** + * Inits a UNISTR2 structure. + * @param ctx talloc context to allocate string on + * @param str pointer to string to create + * @param buf UCS2 null-terminated buffer to init from +*/ + +void init_unistr2_w(TALLOC_CTX *ctx, UNISTR2 *str, const smb_ucs2_t *buf) +{ + uint32 len = buf ? strlen_w(buf) : 0; + + ZERO_STRUCTP(str); + + /* set up string lengths. */ + str->uni_max_len = len; + str->offset = 0; + str->uni_str_len = len; + + if (len + 1) { + str->buffer = TALLOC_ZERO_ARRAY(ctx, uint16, len + 1); + if (str->buffer == NULL) { + smb_panic("init_unistr2_w: talloc fail"); + return; + } + } else { + str->buffer = NULL; + } + + /* + * don't move this test above ! The UNISTR2 must be initialized !!! + * jfm, 7/7/2001. + */ + if (buf==NULL) + return; + + /* Yes, this is a strncpy( foo, bar, strlen(bar)) - but as + long as the buffer above is talloc()ed correctly then this + is the correct thing to do */ + if (len+1) { + strncpy_w(str->buffer, buf, len + 1); + } +} + +/******************************************************************* + Inits a UNISTR2 structure from a UNISTR +********************************************************************/ + +void init_unistr2_from_unistr(TALLOC_CTX *ctx, UNISTR2 *to, const UNISTR *from) +{ + uint32 i; + + /* the destination UNISTR2 should never be NULL. + if it is it is a programming error */ + + /* if the source UNISTR is NULL, then zero out + the destination string and return */ + ZERO_STRUCTP (to); + if ((from == NULL) || (from->buffer == NULL)) + return; + + /* get the length; UNISTR must be NULL terminated */ + i = 0; + while ((from->buffer)[i]!='\0') + i++; + i++; /* one more to catch the terminating NULL */ + /* is this necessary -- jerry? I need to think */ + + /* set up string lengths; uni_max_len is set to i+1 + because we need to account for the final NULL termination */ + to->uni_max_len = i; + to->offset = 0; + to->uni_str_len = i; + + /* allocate the space and copy the string buffer */ + if (i) { + to->buffer = TALLOC_ZERO_ARRAY(ctx, uint16, i); + if (to->buffer == NULL) + smb_panic("init_unistr2_from_unistr: talloc fail"); + memcpy(to->buffer, from->buffer, i*sizeof(uint16)); + } else { + to->buffer = NULL; + } + return; +} + +/******************************************************************* + Inits a UNISTR2 structure from a DATA_BLOB. + The length of the data_blob must count the bytes of the buffer. + Copies the blob data. +********************************************************************/ + +void init_unistr2_from_datablob(UNISTR2 *str, DATA_BLOB *blob) +{ + /* Allocs the unistring */ + init_unistr2(str, NULL, UNI_FLAGS_NONE); + + /* Sets the values */ + str->uni_str_len = blob->length / sizeof(uint16); + str->uni_max_len = str->uni_str_len; + str->offset = 0; + if (blob->length) { + str->buffer = (uint16 *) memdup(blob->data, blob->length); + } else { + str->buffer = NULL; + } + if ((str->buffer == NULL) && (blob->length > 0)) { + smb_panic("init_unistr2_from_datablob: malloc fail"); + } +} + +/******************************************************************* + UNISTR2* are a little different in that the pointer and the UNISTR2 + are not necessarily read/written back to back. So we break it up + into 2 separate functions. + See SPOOL_USER_1 in include/rpc_spoolss.h for an example. +********************************************************************/ + +bool prs_io_unistr2_p(const char *desc, prs_struct *ps, int depth, UNISTR2 **uni2) +{ + uint32 data_p; + + /* caputure the pointer value to stream */ + + data_p = *uni2 ? 0xf000baaa : 0; + + if ( !prs_uint32("ptr", ps, depth, &data_p )) + return False; + + /* we're done if there is no data */ + + if ( !data_p ) + return True; + + if (UNMARSHALLING(ps)) { + if ( !(*uni2 = PRS_ALLOC_MEM(ps, UNISTR2, 1)) ) + return False; + } + + return True; +} + +/******************************************************************* + now read/write the actual UNISTR2. Memory for the UNISTR2 (but + not UNISTR2.buffer) has been allocated previously by prs_unistr2_p() +********************************************************************/ + +bool prs_io_unistr2(const char *desc, prs_struct *ps, int depth, UNISTR2 *uni2 ) +{ + /* just return true if there is no pointer to deal with. + the memory must have been previously allocated on unmarshalling + by prs_unistr2_p() */ + + if ( !uni2 ) + return True; + + /* just pass off to smb_io_unstr2() passing the uni2 address as + the pointer (like you would expect) */ + + return smb_io_unistr2( desc, uni2, uni2 ? 1 : 0, ps, depth ); +} + +/******************************************************************* + Reads or writes a UNISTR2 structure. + XXXX NOTE: UNISTR2 structures need NOT be null-terminated. + the uni_str_len member tells you how long the string is; + the uni_max_len member tells you how large the buffer is. +********************************************************************/ + +bool smb_io_unistr2(const char *desc, UNISTR2 *uni2, uint32 buffer, prs_struct *ps, int depth) +{ + if (uni2 == NULL) + return False; + + if (buffer) { + + prs_debug(ps, depth, desc, "smb_io_unistr2"); + depth++; + + if(!prs_align(ps)) + return False; + + if(!prs_uint32("uni_max_len", ps, depth, &uni2->uni_max_len)) + return False; + if(!prs_uint32("offset ", ps, depth, &uni2->offset)) + return False; + if(!prs_uint32("uni_str_len", ps, depth, &uni2->uni_str_len)) + return False; + + /* buffer advanced by indicated length of string + NOT by searching for null-termination */ + if(!prs_unistr2(True, "buffer ", ps, depth, uni2)) + return False; + + } else { + + prs_debug(ps, depth, desc, "smb_io_unistr2 - NULL"); + depth++; + memset((char *)uni2, '\0', sizeof(*uni2)); + + } + + return True; +} + +/******************************************************************* + now read/write UNISTR4 +********************************************************************/ + +bool prs_unistr4(const char *desc, prs_struct *ps, int depth, UNISTR4 *uni4) +{ + void *ptr; + prs_debug(ps, depth, desc, "prs_unistr4"); + depth++; + + if ( !prs_uint16("length", ps, depth, &uni4->length )) + return False; + if ( !prs_uint16("size", ps, depth, &uni4->size )) + return False; + + ptr = uni4->string; + + if ( !prs_pointer( desc, ps, depth, &ptr, sizeof(UNISTR2), (PRS_POINTER_CAST)prs_io_unistr2 ) ) + return False; + + uni4->string = (UNISTR2 *)ptr; + + return True; +} + +/******************************************************************* + now read/write UNISTR4 header +********************************************************************/ + +bool prs_unistr4_hdr(const char *desc, prs_struct *ps, int depth, UNISTR4 *uni4) +{ + prs_debug(ps, depth, desc, "prs_unistr4_hdr"); + depth++; + + if ( !prs_uint16("length", ps, depth, &uni4->length) ) + return False; + if ( !prs_uint16("size", ps, depth, &uni4->size) ) + return False; + if ( !prs_io_unistr2_p(desc, ps, depth, &uni4->string) ) + return False; + + return True; +} + +/******************************************************************* + now read/write UNISTR4 string +********************************************************************/ + +bool prs_unistr4_str(const char *desc, prs_struct *ps, int depth, UNISTR4 *uni4) +{ + prs_debug(ps, depth, desc, "prs_unistr4_str"); + depth++; + + if ( !prs_io_unistr2(desc, ps, depth, uni4->string) ) + return False; + + return True; +} + +/******************************************************************* + Reads or writes a UNISTR4_ARRAY structure. +********************************************************************/ + +bool prs_unistr4_array(const char *desc, prs_struct *ps, int depth, UNISTR4_ARRAY *array ) +{ + unsigned int i; + + prs_debug(ps, depth, desc, "prs_unistr4_array"); + depth++; + + if(!prs_uint32("count", ps, depth, &array->count)) + return False; + + if (UNMARSHALLING(ps)) { + if (array->count) { + if ( !(array->strings = TALLOC_ZERO_ARRAY( talloc_tos(), UNISTR4, array->count)) ) + return False; + } else { + array->strings = NULL; + } + } + + /* write the headers and then the actual string buffer */ + + for ( i=0; i<array->count; i++ ) { + if ( !prs_unistr4_hdr( "string", ps, depth, &array->strings[i]) ) + return False; + } + + for (i=0;i<array->count;i++) { + if ( !prs_unistr4_str("string", ps, depth, &array->strings[i]) ) + return False; + } + + return True; +} + +/******************************************************************** + initialise a UNISTR_ARRAY from a char** +********************************************************************/ + +bool init_unistr4_array( UNISTR4_ARRAY *array, uint32 count, const char **strings ) +{ + unsigned int i; + + array->count = count; + + /* allocate memory for the array of UNISTR4 objects */ + + if (array->count) { + if ( !(array->strings = TALLOC_ZERO_ARRAY(talloc_tos(), UNISTR4, count )) ) + return False; + } else { + array->strings = NULL; + } + + for ( i=0; i<count; i++ ) + init_unistr4( &array->strings[i], strings[i], UNI_STR_TERMINATE ); + + return True; +} + +/******************************************************************* + Inits a DOM_RID structure. +********************************************************************/ + +void init_dom_rid(DOM_RID *prid, uint32 rid, uint16 type, uint32 idx) +{ + prid->type = type; + prid->rid = rid; + prid->rid_idx = idx; +} + +/******************************************************************* + Reads or writes a DOM_RID structure. +********************************************************************/ + +bool smb_io_dom_rid(const char *desc, DOM_RID *rid, prs_struct *ps, int depth) +{ + if (rid == NULL) + return False; + + prs_debug(ps, depth, desc, "smb_io_dom_rid"); + depth++; + + if(!prs_align(ps)) + return False; + + if(!prs_uint16("type ", ps, depth, &rid->type)) + return False; + if(!prs_align(ps)) + return False; + if(!prs_uint32("rid ", ps, depth, &rid->rid)) + return False; + if(!prs_uint32("rid_idx", ps, depth, &rid->rid_idx)) + return False; + + return True; +} + +/******************************************************************* + Reads or writes a DOM_RID2 structure. +********************************************************************/ + +bool smb_io_dom_rid2(const char *desc, DOM_RID2 *rid, prs_struct *ps, int depth) +{ + if (rid == NULL) + return False; + + prs_debug(ps, depth, desc, "smb_io_dom_rid2"); + depth++; + + if(!prs_align(ps)) + return False; + + if(!prs_uint16("type ", ps, depth, &rid->type)) + return False; + if(!prs_align(ps)) + return False; + if(!prs_uint32("rid ", ps, depth, &rid->rid)) + return False; + if(!prs_uint32("rid_idx", ps, depth, &rid->rid_idx)) + return False; + if(!prs_uint32("unknown", ps, depth, &rid->unknown)) + return False; + + return True; +} + + +/******************************************************************* +creates a DOM_RID3 structure. +********************************************************************/ + +void init_dom_rid3(DOM_RID3 *rid3, uint32 rid, uint8 type) +{ + rid3->rid = rid; + rid3->type1 = type; + rid3->ptr_type = 0x1; /* non-zero, basically. */ + rid3->type2 = 0x1; + rid3->unk = type; +} + +/******************************************************************* +reads or writes a DOM_RID3 structure. +********************************************************************/ + +bool smb_io_dom_rid3(const char *desc, DOM_RID3 *rid3, prs_struct *ps, int depth) +{ + if (rid3 == NULL) + return False; + + prs_debug(ps, depth, desc, "smb_io_dom_rid3"); + depth++; + + if(!prs_align(ps)) + return False; + + if(!prs_uint32("rid ", ps, depth, &rid3->rid)) + return False; + if(!prs_uint32("type1 ", ps, depth, &rid3->type1)) + return False; + if(!prs_uint32("ptr_type", ps, depth, &rid3->ptr_type)) + return False; + if(!prs_uint32("type2 ", ps, depth, &rid3->type2)) + return False; + if(!prs_uint32("unk ", ps, depth, &rid3->unk)) + return False; + + return True; +} + +/******************************************************************* + Inits a DOM_RID4 structure. +********************************************************************/ + +void init_dom_rid4(DOM_RID4 *rid4, uint16 unknown, uint16 attr, uint32 rid) +{ + rid4->unknown = unknown; + rid4->attr = attr; + rid4->rid = rid; +} + +/******************************************************************* + Inits a DOM_CLNT_SRV structure. +********************************************************************/ + +void init_clnt_srv(DOM_CLNT_SRV *logcln, const char *logon_srv, + const char *comp_name) +{ + DEBUG(5,("init_clnt_srv: %d\n", __LINE__)); + + if (logon_srv != NULL) { + logcln->undoc_buffer = 1; + init_unistr2(&logcln->uni_logon_srv, logon_srv, UNI_STR_TERMINATE); + } else { + logcln->undoc_buffer = 0; + } + + if (comp_name != NULL) { + logcln->undoc_buffer2 = 1; + init_unistr2(&logcln->uni_comp_name, comp_name, UNI_STR_TERMINATE); + } else { + logcln->undoc_buffer2 = 0; + } +} + +/******************************************************************* + Inits or writes a DOM_CLNT_SRV structure. +********************************************************************/ + +bool smb_io_clnt_srv(const char *desc, DOM_CLNT_SRV *logcln, prs_struct *ps, int depth) +{ + if (logcln == NULL) + return False; + + prs_debug(ps, depth, desc, "smb_io_clnt_srv"); + depth++; + + if(!prs_align(ps)) + return False; + + if(!prs_uint32("undoc_buffer ", ps, depth, &logcln->undoc_buffer)) + return False; + + if (logcln->undoc_buffer != 0) { + if(!smb_io_unistr2("unistr2", &logcln->uni_logon_srv, logcln->undoc_buffer, ps, depth)) + return False; + } + + if(!prs_align(ps)) + return False; + + if(!prs_uint32("undoc_buffer2", ps, depth, &logcln->undoc_buffer2)) + return False; + + if (logcln->undoc_buffer2 != 0) { + if(!smb_io_unistr2("unistr2", &logcln->uni_comp_name, logcln->undoc_buffer2, ps, depth)) + return False; + } + + return True; +} + +/******************************************************************* + Inits a DOM_LOG_INFO structure. +********************************************************************/ + +void init_log_info(DOM_LOG_INFO *loginfo, const char *logon_srv, const char *acct_name, + uint16 sec_chan, const char *comp_name) +{ + DEBUG(5,("make_log_info %d\n", __LINE__)); + + loginfo->undoc_buffer = 1; + + init_unistr2(&loginfo->uni_logon_srv, logon_srv, UNI_STR_TERMINATE); + init_unistr2(&loginfo->uni_acct_name, acct_name, UNI_STR_TERMINATE); + + loginfo->sec_chan = sec_chan; + + init_unistr2(&loginfo->uni_comp_name, comp_name, UNI_STR_TERMINATE); +} + +/******************************************************************* + Reads or writes a DOM_LOG_INFO structure. +********************************************************************/ + +bool smb_io_log_info(const char *desc, DOM_LOG_INFO *loginfo, prs_struct *ps, int depth) +{ + if (loginfo == NULL) + return False; + + prs_debug(ps, depth, desc, "smb_io_log_info"); + depth++; + + if(!prs_align(ps)) + return False; + + if(!prs_uint32("undoc_buffer", ps, depth, &loginfo->undoc_buffer)) + return False; + + if(!smb_io_unistr2("unistr2", &loginfo->uni_logon_srv, True, ps, depth)) + return False; + if(!smb_io_unistr2("unistr2", &loginfo->uni_acct_name, True, ps, depth)) + return False; + + if(!prs_uint16("sec_chan", ps, depth, &loginfo->sec_chan)) + return False; + + if(!smb_io_unistr2("unistr2", &loginfo->uni_comp_name, True, ps, depth)) + return False; + + return True; +} + +/******************************************************************* + Reads or writes a DOM_CHAL structure. +********************************************************************/ + +bool smb_io_chal(const char *desc, DOM_CHAL *chal, prs_struct *ps, int depth) +{ + if (chal == NULL) + return False; + + prs_debug(ps, depth, desc, "smb_io_chal"); + depth++; + + if(!prs_uint8s (False, "data", ps, depth, chal->data, 8)) + return False; + + return True; +} + +/******************************************************************* + Reads or writes a DOM_CRED structure. +********************************************************************/ + +bool smb_io_cred(const char *desc, DOM_CRED *cred, prs_struct *ps, int depth) +{ + if (cred == NULL) + return False; + + prs_debug(ps, depth, desc, "smb_io_cred"); + depth++; + + if(!prs_align(ps)) + return False; + + if(!smb_io_chal ("", &cred->challenge, ps, depth)) + return False; + + if(!smb_io_utime("", &cred->timestamp, ps, depth)) + return False; + + return True; +} + +/******************************************************************* + Inits a DOM_CLNT_INFO2 structure. +********************************************************************/ + +void init_clnt_info2(DOM_CLNT_INFO2 *clnt, + const char *logon_srv, const char *comp_name, + const DOM_CRED *clnt_cred) +{ + DEBUG(5,("make_clnt_info: %d\n", __LINE__)); + + init_clnt_srv(&clnt->login, logon_srv, comp_name); + + if (clnt_cred != NULL) { + clnt->ptr_cred = 1; + memcpy(&clnt->cred, clnt_cred, sizeof(clnt->cred)); + } else { + clnt->ptr_cred = 0; + } +} + +/******************************************************************* + Reads or writes a DOM_CLNT_INFO2 structure. +********************************************************************/ + +bool smb_io_clnt_info2(const char *desc, DOM_CLNT_INFO2 *clnt, prs_struct *ps, int depth) +{ + if (clnt == NULL) + return False; + + prs_debug(ps, depth, desc, "smb_io_clnt_info2"); + depth++; + + if(!prs_align(ps)) + return False; + + if(!smb_io_clnt_srv("", &clnt->login, ps, depth)) + return False; + + if(!prs_align(ps)) + return False; + + if(!prs_uint32("ptr_cred", ps, depth, &clnt->ptr_cred)) + return False; + if(!smb_io_cred("", &clnt->cred, ps, depth)) + return False; + + return True; +} + +/******************************************************************* + Inits a DOM_CLNT_INFO structure. +********************************************************************/ + +void init_clnt_info(DOM_CLNT_INFO *clnt, + const char *logon_srv, const char *acct_name, + uint16 sec_chan, const char *comp_name, + const DOM_CRED *cred) +{ + DEBUG(5,("make_clnt_info\n")); + + init_log_info(&clnt->login, logon_srv, acct_name, sec_chan, comp_name); + memcpy(&clnt->cred, cred, sizeof(clnt->cred)); +} + +/******************************************************************* + Reads or writes a DOM_CLNT_INFO structure. +********************************************************************/ + +bool smb_io_clnt_info(const char *desc, DOM_CLNT_INFO *clnt, prs_struct *ps, int depth) +{ + if (clnt == NULL) + return False; + + prs_debug(ps, depth, desc, "smb_io_clnt_info"); + depth++; + + if(!prs_align(ps)) + return False; + + if(!smb_io_log_info("", &clnt->login, ps, depth)) + return False; + if(!smb_io_cred("", &clnt->cred, ps, depth)) + return False; + + return True; +} + +/******************************************************************* + Inits a DOM_LOGON_ID structure. +********************************************************************/ + +void init_logon_id(DOM_LOGON_ID *logonid, uint32 log_id_low, uint32 log_id_high) +{ + DEBUG(5,("make_logon_id: %d\n", __LINE__)); + + logonid->low = log_id_low; + logonid->high = log_id_high; +} + +/******************************************************************* + Reads or writes a DOM_LOGON_ID structure. +********************************************************************/ + +bool smb_io_logon_id(const char *desc, DOM_LOGON_ID *logonid, prs_struct *ps, int depth) +{ + if (logonid == NULL) + return False; + + prs_debug(ps, depth, desc, "smb_io_logon_id"); + depth++; + + if(!prs_align(ps)) + return False; + + if(!prs_uint32("low ", ps, depth, &logonid->low )) + return False; + if(!prs_uint32("high", ps, depth, &logonid->high)) + return False; + + return True; +} + +/******************************************************************* + Inits an OWF_INFO structure. +********************************************************************/ + +void init_owf_info(OWF_INFO *hash, const uint8 data[16]) +{ + DEBUG(5,("init_owf_info: %d\n", __LINE__)); + + if (data != NULL) + memcpy(hash->data, data, sizeof(hash->data)); + else + memset((char *)hash->data, '\0', sizeof(hash->data)); +} + +/******************************************************************* + Reads or writes an OWF_INFO structure. +********************************************************************/ + +bool smb_io_owf_info(const char *desc, OWF_INFO *hash, prs_struct *ps, int depth) +{ + if (hash == NULL) + return False; + + prs_debug(ps, depth, desc, "smb_io_owf_info"); + depth++; + + if(!prs_align(ps)) + return False; + + if(!prs_uint8s (False, "data", ps, depth, hash->data, 16)) + return False; + + return True; +} + +/******************************************************************* + Reads or writes a DOM_GID structure. +********************************************************************/ + +bool smb_io_gid(const char *desc, DOM_GID *gid, prs_struct *ps, int depth) +{ + if (gid == NULL) + return False; + + prs_debug(ps, depth, desc, "smb_io_gid"); + depth++; + + if(!prs_align(ps)) + return False; + + if(!prs_uint32("g_rid", ps, depth, &gid->g_rid)) + return False; + if(!prs_uint32("attr ", ps, depth, &gid->attr)) + return False; + + return True; +} + +/******************************************************************* + Reads or writes an POLICY_HND structure. +********************************************************************/ + +bool smb_io_pol_hnd(const char *desc, POLICY_HND *pol, prs_struct *ps, int depth) +{ + if (pol == NULL) + return False; + + prs_debug(ps, depth, desc, "smb_io_pol_hnd"); + depth++; + + if(!prs_align(ps)) + return False; + + if(UNMARSHALLING(ps)) + ZERO_STRUCTP(pol); + + if (!prs_uint32("handle_type", ps, depth, &pol->handle_type)) + return False; + if (!smb_io_uuid("uuid", (struct GUID*)&pol->uuid, ps, depth)) + return False; + + return True; +} + +/******************************************************************* + Create a UNISTR3. +********************************************************************/ + +void init_unistr3(UNISTR3 *str, const char *buf) +{ + if (buf == NULL) { + str->uni_str_len=0; + str->str.buffer = NULL; + return; + } + + str->uni_str_len = strlen(buf) + 1; + + if (str->uni_str_len) { + str->str.buffer = TALLOC_ZERO_ARRAY(talloc_tos(), uint16, str->uni_str_len); + if (str->str.buffer == NULL) + smb_panic("init_unistr3: malloc fail"); + + rpcstr_push((char *)str->str.buffer, buf, str->uni_str_len * sizeof(uint16), STR_TERMINATE); + } else { + str->str.buffer = NULL; + } +} + +/******************************************************************* + Reads or writes a UNISTR3 structure. +********************************************************************/ + +bool smb_io_unistr3(const char *desc, UNISTR3 *name, prs_struct *ps, int depth) +{ + if (name == NULL) + return False; + + prs_debug(ps, depth, desc, "smb_io_unistr3"); + depth++; + + if(!prs_align(ps)) + return False; + + if(!prs_uint32("uni_str_len", ps, depth, &name->uni_str_len)) + return False; + + /* we're done if there is no string */ + + if ( name->uni_str_len == 0 ) + return True; + + /* don't know if len is specified by uni_str_len member... */ + /* assume unicode string is unicode-null-terminated, instead */ + + if(!prs_unistr3(True, "unistr", name, ps, depth)) + return False; + + return True; +} + +/******************************************************************* + Stream a uint64_struct + ********************************************************************/ +bool prs_uint64(const char *name, prs_struct *ps, int depth, uint64 *data64) +{ + if (UNMARSHALLING(ps)) { + uint32 high, low; + + if (!prs_uint32(name, ps, depth+1, &low)) + return False; + + if (!prs_uint32(name, ps, depth+1, &high)) + return False; + + *data64 = ((uint64_t)high << 32) + low; + + return True; + } else { + uint32 high = (*data64) >> 32, low = (*data64) & 0xFFFFFFFF; + return prs_uint32(name, ps, depth+1, &low) && + prs_uint32(name, ps, depth+1, &high); + } +} + +/******************************************************************* +reads or writes a BUFHDR2 structure. +********************************************************************/ +bool smb_io_bufhdr2(const char *desc, BUFHDR2 *hdr, prs_struct *ps, int depth) +{ + prs_debug(ps, depth, desc, "smb_io_bufhdr2"); + depth++; + + if (!prs_align(ps)) + return False; + if (!prs_uint32("info_level", ps, depth, &(hdr->info_level))) + return False; + if (!prs_uint32("length ", ps, depth, &(hdr->length ))) + return False; + if (!prs_uint32("buffer ", ps, depth, &(hdr->buffer ))) + return False; + + return True; +} + +/******************************************************************* +reads or writes a BUFHDR4 structure. +********************************************************************/ +bool smb_io_bufhdr4(const char *desc, BUFHDR4 *hdr, prs_struct *ps, int depth) +{ + prs_debug(ps, depth, desc, "smb_io_bufhdr4"); + depth++; + + if (!prs_align(ps)) + return False; + if (!prs_uint32("size", ps, depth, &hdr->size)) + return False; + if (!prs_uint32("buffer", ps, depth, &hdr->buffer)) + return False; + + return True; +} + +/******************************************************************* +reads or writes a RPC_DATA_BLOB structure. +********************************************************************/ + +bool smb_io_rpc_blob(const char *desc, RPC_DATA_BLOB *blob, prs_struct *ps, int depth) +{ + prs_debug(ps, depth, desc, "smb_io_rpc_blob"); + depth++; + + if (!prs_align(ps)) + return False; + if ( !prs_uint32("buf_len", ps, depth, &blob->buf_len) ) + return False; + + if ( blob->buf_len == 0 ) + return True; + + if (UNMARSHALLING(ps)) { + blob->buffer = PRS_ALLOC_MEM(ps, uint8, blob->buf_len); + if (!blob->buffer) { + return False; + } + } + + if ( !prs_uint8s(True, "buffer", ps, depth, blob->buffer, blob->buf_len) ) + return False; + + return True; +} + +/******************************************************************* +creates a UNIHDR structure. +********************************************************************/ + +bool make_uni_hdr(UNIHDR *hdr, int len) +{ + if (hdr == NULL) + { + return False; + } + hdr->uni_str_len = 2 * len; + hdr->uni_max_len = 2 * len; + hdr->buffer = len != 0 ? 1 : 0; + + return True; +} + +/******************************************************************* +creates a BUFHDR2 structure. +********************************************************************/ +bool make_bufhdr2(BUFHDR2 *hdr, uint32 info_level, uint32 length, uint32 buffer) +{ + hdr->info_level = info_level; + hdr->length = length; + hdr->buffer = buffer; + + return True; +} + +/******************************************************************* +return the length of a UNISTR string. +********************************************************************/ + +uint32 str_len_uni(UNISTR *source) +{ + uint32 i=0; + + if (!source->buffer) + return 0; + + while (source->buffer[i]) + i++; + + return i; +} + +/******************************************************************* + Verifies policy handle +********************************************************************/ + +bool policy_handle_is_valid(const POLICY_HND *hnd) +{ + POLICY_HND zero_pol; + + ZERO_STRUCT(zero_pol); + return ((memcmp(&zero_pol, hnd, sizeof(POLICY_HND)) == 0) ? false : true ); +} diff --git a/source3/rpc_parse/parse_ntsvcs.c b/source3/rpc_parse/parse_ntsvcs.c new file mode 100644 index 0000000000..2b15a45506 --- /dev/null +++ b/source3/rpc_parse/parse_ntsvcs.c @@ -0,0 +1,147 @@ +/* + * Unix SMB/CIFS implementation. + * RPC Pipe client / server routines + * Copyright (C) Gerald (Jerry) Carter 2005. + * + * 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 + * the Free Software Foundation; either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, see <http://www.gnu.org/licenses/>. + */ + +#include "includes.h" + +#undef DBGC_CLASS +#define DBGC_CLASS DBGC_RPC_PARSE + +/******************************************************************* +********************************************************************/ + +bool ntsvcs_io_q_get_device_list(const char *desc, NTSVCS_Q_GET_DEVICE_LIST *q_u, prs_struct *ps, int depth) +{ + if (q_u == NULL) + return False; + + prs_debug(ps, depth, desc, "ntsvcs_io_q_get_device_list"); + depth++; + + if(!prs_align(ps)) + return False; + + if ( !prs_pointer("devicename", ps, depth, (void*)&q_u->devicename, sizeof(UNISTR2), (PRS_POINTER_CAST)prs_io_unistr2) ) + return False; + if( !prs_align(ps) ) + return False; + + if ( !prs_uint32("buffer_size", ps, depth, &q_u->buffer_size) ) + return False; + if ( !prs_uint32("flags", ps, depth, &q_u->flags) ) + return False; + + return True; + +} + +/******************************************************************* +********************************************************************/ + +bool ntsvcs_io_r_get_device_list(const char *desc, NTSVCS_R_GET_DEVICE_LIST *r_u, prs_struct *ps, int depth) +{ + if ( !r_u ) + return False; + + prs_debug(ps, depth, desc, "ntsvcs_io_r_get_device_list_size"); + depth++; + + if(!prs_align(ps)) + return False; + + if ( !prs_io_unistr2("devicepath", ps, depth, &r_u->devicepath) ) + return False; + if(!prs_align(ps)) + return False; + + if(!prs_uint32("needed", ps, depth, &r_u->needed)) + return False; + + if(!prs_werror("status", ps, depth, &r_u->status)) + return False; + + return True; +} + +/******************************************************************* +********************************************************************/ + +bool ntsvcs_io_q_get_device_reg_property(const char *desc, NTSVCS_Q_GET_DEVICE_REG_PROPERTY *q_u, prs_struct *ps, int depth) +{ + if (q_u == NULL) + return False; + + prs_debug(ps, depth, desc, "ntsvcs_io_q_get_device_reg_property"); + depth++; + + if(!prs_align(ps)) + return False; + + if ( !prs_io_unistr2("devicepath", ps, depth, &q_u->devicepath) ) + return False; + if( !prs_align(ps) ) + return False; + + if ( !prs_uint32("property", ps, depth, &q_u->property) ) + return False; + if ( !prs_uint32("unknown2", ps, depth, &q_u->unknown2) ) + return False; + if ( !prs_uint32("buffer_size1", ps, depth, &q_u->buffer_size1) ) + return False; + if ( !prs_uint32("buffer_size2", ps, depth, &q_u->buffer_size2) ) + return False; + if ( !prs_uint32("unknown5", ps, depth, &q_u->unknown5) ) + return False; + + return True; + +} + +/******************************************************************* +********************************************************************/ + +bool ntsvcs_io_r_get_device_reg_property(const char *desc, NTSVCS_R_GET_DEVICE_REG_PROPERTY *r_u, prs_struct *ps, int depth) +{ + if ( !r_u ) + return False; + + prs_debug(ps, depth, desc, "ntsvcs_io_r_get_device_reg_property"); + depth++; + + if ( !prs_align(ps) ) + return False; + + if ( !prs_uint32("unknown1", ps, depth, &r_u->unknown1) ) + return False; + + if ( !smb_io_regval_buffer("value", ps, depth, &r_u->value) ) + return False; + if ( !prs_align(ps) ) + return False; + + if ( !prs_uint32("size", ps, depth, &r_u->size) ) + return False; + + if ( !prs_uint32("needed", ps, depth, &r_u->needed) ) + return False; + + if(!prs_werror("status", ps, depth, &r_u->status)) + return False; + + return True; +} diff --git a/source3/rpc_parse/parse_prs.c b/source3/rpc_parse/parse_prs.c new file mode 100644 index 0000000000..5eb6c31ee6 --- /dev/null +++ b/source3/rpc_parse/parse_prs.c @@ -0,0 +1,1868 @@ +/* + Unix SMB/CIFS implementation. + Samba memory buffer functions + Copyright (C) Andrew Tridgell 1992-1997 + Copyright (C) Luke Kenneth Casson Leighton 1996-1997 + Copyright (C) Jeremy Allison 1999 + Copyright (C) Andrew Bartlett 2003. + + 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 + the Free Software Foundation; either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see <http://www.gnu.org/licenses/>. +*/ + +#include "includes.h" + +#undef DBGC_CLASS +#define DBGC_CLASS DBGC_RPC_PARSE + +/** + * Dump a prs to a file: from the current location through to the end. + **/ +void prs_dump(const char *name, int v, prs_struct *ps) +{ + prs_dump_region(name, v, ps, ps->data_offset, ps->buffer_size); +} + +/** + * Dump from the start of the prs to the current location. + **/ +void prs_dump_before(const char *name, int v, prs_struct *ps) +{ + prs_dump_region(name, v, ps, 0, ps->data_offset); +} + +/** + * Dump everything from the start of the prs up to the current location. + **/ +void prs_dump_region(const char *name, int v, prs_struct *ps, + int from_off, int to_off) +{ + int fd, i; + char *fname = NULL; + ssize_t sz; + if (DEBUGLEVEL < 50) return; + for (i=1;i<100;i++) { + if (v != -1) { + if (asprintf(&fname,"/tmp/%s_%d.%d.prs", name, v, i) < 0) { + return; + } + } else { + if (asprintf(&fname,"/tmp/%s.%d.prs", name, i) < 0) { + return; + } + } + fd = open(fname, O_WRONLY|O_CREAT|O_EXCL, 0644); + if (fd != -1 || errno != EEXIST) break; + } + if (fd != -1) { + sz = write(fd, ps->data_p + from_off, to_off - from_off); + i = close(fd); + if ( (sz != to_off-from_off) || (i != 0) ) { + DEBUG(0,("Error writing/closing %s: %ld!=%ld %d\n", fname, (unsigned long)sz, (unsigned long)to_off-from_off, i )); + } else { + DEBUG(0,("created %s\n", fname)); + } + } + SAFE_FREE(fname); +} + +/******************************************************************* + Debug output for parsing info + + XXXX side-effect of this function is to increase the debug depth XXXX. + +********************************************************************/ + +void prs_debug(prs_struct *ps, int depth, const char *desc, const char *fn_name) +{ + DEBUG(5+depth, ("%s%06x %s %s\n", tab_depth(5+depth,depth), ps->data_offset, fn_name, desc)); +} + +/** + * Initialise an expandable parse structure. + * + * @param size Initial buffer size. If >0, a new buffer will be + * created with malloc(). + * + * @return False if allocation fails, otherwise True. + **/ + +bool prs_init(prs_struct *ps, uint32 size, TALLOC_CTX *ctx, bool io) +{ + ZERO_STRUCTP(ps); + ps->io = io; + ps->bigendian_data = RPC_LITTLE_ENDIAN; + ps->align = RPC_PARSE_ALIGN; + ps->is_dynamic = False; + ps->data_offset = 0; + ps->buffer_size = 0; + ps->data_p = NULL; + ps->mem_ctx = ctx; + + if (size != 0) { + ps->buffer_size = size; + if((ps->data_p = (char *)SMB_MALLOC((size_t)size)) == NULL) { + DEBUG(0,("prs_init: malloc fail for %u bytes.\n", (unsigned int)size)); + return False; + } + memset(ps->data_p, '\0', (size_t)size); + ps->is_dynamic = True; /* We own this memory. */ + } else if (MARSHALLING(ps)) { + /* If size is zero and we're marshalling we should allocate memory on demand. */ + ps->is_dynamic = True; + } + + return True; +} + +/******************************************************************* + Delete the memory in a parse structure - if we own it. + + NOTE: Contrary to the somewhat confusing naming, this function is not + intended for freeing memory allocated by prs_alloc_mem(). That memory + is attached to the talloc context given by ps->mem_ctx. + ********************************************************************/ + +void prs_mem_free(prs_struct *ps) +{ + if(ps->is_dynamic) + SAFE_FREE(ps->data_p); + ps->is_dynamic = False; + ps->buffer_size = 0; + ps->data_offset = 0; +} + +/******************************************************************* + Clear the memory in a parse structure. + ********************************************************************/ + +void prs_mem_clear(prs_struct *ps) +{ + if (ps->buffer_size) + memset(ps->data_p, '\0', (size_t)ps->buffer_size); +} + +/******************************************************************* + Allocate memory when unmarshalling... Always zero clears. + ********************************************************************/ + +#if defined(PARANOID_MALLOC_CHECKER) +char *prs_alloc_mem_(prs_struct *ps, size_t size, unsigned int count) +#else +char *prs_alloc_mem(prs_struct *ps, size_t size, unsigned int count) +#endif +{ + char *ret = NULL; + + if (size && count) { + /* We can't call the type-safe version here. */ + ret = (char *)_talloc_zero_array(ps->mem_ctx, size, count, + "parse_prs"); + } + return ret; +} + +/******************************************************************* + Return the current talloc context we're using. + ********************************************************************/ + +TALLOC_CTX *prs_get_mem_context(prs_struct *ps) +{ + return ps->mem_ctx; +} + +/******************************************************************* + Hand some already allocated memory to a prs_struct. + ********************************************************************/ + +void prs_give_memory(prs_struct *ps, char *buf, uint32 size, bool is_dynamic) +{ + ps->is_dynamic = is_dynamic; + ps->data_p = buf; + ps->buffer_size = size; +} + +/******************************************************************* + Take some memory back from a prs_struct. + ********************************************************************/ + +char *prs_take_memory(prs_struct *ps, uint32 *psize) +{ + char *ret = ps->data_p; + if(psize) + *psize = ps->buffer_size; + ps->is_dynamic = False; + prs_mem_free(ps); + return ret; +} + +/******************************************************************* + Set a prs_struct to exactly a given size. Will grow or tuncate if neccessary. + ********************************************************************/ + +bool prs_set_buffer_size(prs_struct *ps, uint32 newsize) +{ + if (newsize > ps->buffer_size) + return prs_force_grow(ps, newsize - ps->buffer_size); + + if (newsize < ps->buffer_size) { + ps->buffer_size = newsize; + + /* newsize == 0 acts as a free and set pointer to NULL */ + if (newsize == 0) { + SAFE_FREE(ps->data_p); + } else { + ps->data_p = (char *)SMB_REALLOC(ps->data_p, newsize); + + if (ps->data_p == NULL) { + DEBUG(0,("prs_set_buffer_size: Realloc failure for size %u.\n", + (unsigned int)newsize)); + DEBUG(0,("prs_set_buffer_size: Reason %s\n",strerror(errno))); + return False; + } + } + } + + return True; +} + +/******************************************************************* + Attempt, if needed, to grow a data buffer. + Also depends on the data stream mode (io). + ********************************************************************/ + +bool prs_grow(prs_struct *ps, uint32 extra_space) +{ + uint32 new_size; + + ps->grow_size = MAX(ps->grow_size, ps->data_offset + extra_space); + + if(ps->data_offset + extra_space <= ps->buffer_size) + return True; + + /* + * We cannot grow the buffer if we're not reading + * into the prs_struct, or if we don't own the memory. + */ + + if(UNMARSHALLING(ps) || !ps->is_dynamic) { + DEBUG(0,("prs_grow: Buffer overflow - unable to expand buffer by %u bytes.\n", + (unsigned int)extra_space)); + return False; + } + + /* + * Decide how much extra space we really need. + */ + + extra_space -= (ps->buffer_size - ps->data_offset); + if(ps->buffer_size == 0) { + /* + * Ensure we have at least a PDU's length, or extra_space, whichever + * is greater. + */ + + new_size = MAX(RPC_MAX_PDU_FRAG_LEN,extra_space); + + if((ps->data_p = (char *)SMB_MALLOC(new_size)) == NULL) { + DEBUG(0,("prs_grow: Malloc failure for size %u.\n", (unsigned int)new_size)); + return False; + } + memset(ps->data_p, '\0', (size_t)new_size ); + } else { + /* + * If the current buffer size is bigger than the space needed, just + * double it, else add extra_space. + */ + new_size = MAX(ps->buffer_size*2, ps->buffer_size + extra_space); + + if ((ps->data_p = (char *)SMB_REALLOC(ps->data_p, new_size)) == NULL) { + DEBUG(0,("prs_grow: Realloc failure for size %u.\n", + (unsigned int)new_size)); + return False; + } + + memset(&ps->data_p[ps->buffer_size], '\0', (size_t)(new_size - ps->buffer_size)); + } + ps->buffer_size = new_size; + + return True; +} + +/******************************************************************* + Attempt to force a data buffer to grow by len bytes. + This is only used when appending more data onto a prs_struct + when reading an rpc reply, before unmarshalling it. + ********************************************************************/ + +bool prs_force_grow(prs_struct *ps, uint32 extra_space) +{ + uint32 new_size = ps->buffer_size + extra_space; + + if(!UNMARSHALLING(ps) || !ps->is_dynamic) { + DEBUG(0,("prs_force_grow: Buffer overflow - unable to expand buffer by %u bytes.\n", + (unsigned int)extra_space)); + return False; + } + + if((ps->data_p = (char *)SMB_REALLOC(ps->data_p, new_size)) == NULL) { + DEBUG(0,("prs_force_grow: Realloc failure for size %u.\n", + (unsigned int)new_size)); + return False; + } + + memset(&ps->data_p[ps->buffer_size], '\0', (size_t)(new_size - ps->buffer_size)); + + ps->buffer_size = new_size; + + return True; +} + +/******************************************************************* + Get the data pointer (external interface). +********************************************************************/ + +char *prs_data_p(prs_struct *ps) +{ + return ps->data_p; +} + +/******************************************************************* + Get the current data size (external interface). + ********************************************************************/ + +uint32 prs_data_size(prs_struct *ps) +{ + return ps->buffer_size; +} + +/******************************************************************* + Fetch the current offset (external interface). + ********************************************************************/ + +uint32 prs_offset(prs_struct *ps) +{ + return ps->data_offset; +} + +/******************************************************************* + Set the current offset (external interface). + ********************************************************************/ + +bool prs_set_offset(prs_struct *ps, uint32 offset) +{ + if(offset <= ps->data_offset) { + ps->data_offset = offset; + return True; + } + + if(!prs_grow(ps, offset - ps->data_offset)) + return False; + + ps->data_offset = offset; + return True; +} + +/******************************************************************* + Append the data from one parse_struct into another. + ********************************************************************/ + +bool prs_append_prs_data(prs_struct *dst, prs_struct *src) +{ + if (prs_offset(src) == 0) + return True; + + if(!prs_grow(dst, prs_offset(src))) + return False; + + memcpy(&dst->data_p[dst->data_offset], src->data_p, (size_t)prs_offset(src)); + dst->data_offset += prs_offset(src); + + return True; +} + +/******************************************************************* + Append some data from one parse_struct into another. + ********************************************************************/ + +bool prs_append_some_data(prs_struct *dst, void *src_base, uint32_t start, + uint32_t len) +{ + if (len == 0) { + return true; + } + + if(!prs_grow(dst, len)) { + return false; + } + + memcpy(&dst->data_p[dst->data_offset], ((char *)src_base) + start, (size_t)len); + dst->data_offset += len; + return true; +} + +bool prs_append_some_prs_data(prs_struct *dst, prs_struct *src, int32 start, + uint32 len) +{ + return prs_append_some_data(dst, src->data_p, start, len); +} + +/******************************************************************* + Append the data from a buffer into a parse_struct. + ********************************************************************/ + +bool prs_copy_data_in(prs_struct *dst, const char *src, uint32 len) +{ + if (len == 0) + return True; + + if(!prs_grow(dst, len)) + return False; + + memcpy(&dst->data_p[dst->data_offset], src, (size_t)len); + dst->data_offset += len; + + return True; +} + +/******************************************************************* + Copy some data from a parse_struct into a buffer. + ********************************************************************/ + +bool prs_copy_data_out(char *dst, prs_struct *src, uint32 len) +{ + if (len == 0) + return True; + + if(!prs_mem_get(src, len)) + return False; + + memcpy(dst, &src->data_p[src->data_offset], (size_t)len); + src->data_offset += len; + + return True; +} + +/******************************************************************* + Copy all the data from a parse_struct into a buffer. + ********************************************************************/ + +bool prs_copy_all_data_out(char *dst, prs_struct *src) +{ + uint32 len = prs_offset(src); + + if (!len) + return True; + + prs_set_offset(src, 0); + return prs_copy_data_out(dst, src, len); +} + +/******************************************************************* + Set the data as X-endian (external interface). + ********************************************************************/ + +void prs_set_endian_data(prs_struct *ps, bool endian) +{ + ps->bigendian_data = endian; +} + +/******************************************************************* + Align a the data_len to a multiple of align bytes - filling with + zeros. + ********************************************************************/ + +bool prs_align(prs_struct *ps) +{ + uint32 mod = ps->data_offset & (ps->align-1); + + if (ps->align != 0 && mod != 0) { + uint32 extra_space = (ps->align - mod); + if(!prs_grow(ps, extra_space)) + return False; + memset(&ps->data_p[ps->data_offset], '\0', (size_t)extra_space); + ps->data_offset += extra_space; + } + + return True; +} + +/****************************************************************** + Align on a 2 byte boundary + *****************************************************************/ + +bool prs_align_uint16(prs_struct *ps) +{ + bool ret; + uint8 old_align = ps->align; + + ps->align = 2; + ret = prs_align(ps); + ps->align = old_align; + + return ret; +} + +/****************************************************************** + Align on a 8 byte boundary + *****************************************************************/ + +bool prs_align_uint64(prs_struct *ps) +{ + bool ret; + uint8 old_align = ps->align; + + ps->align = 8; + ret = prs_align(ps); + ps->align = old_align; + + return ret; +} + +/****************************************************************** + Align on a specific byte boundary + *****************************************************************/ + +bool prs_align_custom(prs_struct *ps, uint8 boundary) +{ + bool ret; + uint8 old_align = ps->align; + + ps->align = boundary; + ret = prs_align(ps); + ps->align = old_align; + + return ret; +} + + + +/******************************************************************* + Align only if required (for the unistr2 string mainly) + ********************************************************************/ + +bool prs_align_needed(prs_struct *ps, uint32 needed) +{ + if (needed==0) + return True; + else + return prs_align(ps); +} + +/******************************************************************* + Ensure we can read/write to a given offset. + ********************************************************************/ + +char *prs_mem_get(prs_struct *ps, uint32 extra_size) +{ + if(UNMARSHALLING(ps)) { + /* + * If reading, ensure that we can read the requested size item. + */ + if (ps->data_offset + extra_size > ps->buffer_size) { + DEBUG(0,("prs_mem_get: reading data of size %u would overrun " + "buffer by %u bytes.\n", + (unsigned int)extra_size, + (unsigned int)(ps->data_offset + extra_size - ps->buffer_size) )); + return NULL; + } + } else { + /* + * Writing - grow the buffer if needed. + */ + if(!prs_grow(ps, extra_size)) + return NULL; + } + return &ps->data_p[ps->data_offset]; +} + +/******************************************************************* + Change the struct type. + ********************************************************************/ + +void prs_switch_type(prs_struct *ps, bool io) +{ + if ((ps->io ^ io) == True) + ps->io=io; +} + +/******************************************************************* + Force a prs_struct to be dynamic even when it's size is 0. + ********************************************************************/ + +void prs_force_dynamic(prs_struct *ps) +{ + ps->is_dynamic=True; +} + +/******************************************************************* + Associate a session key with a parse struct. + ********************************************************************/ + +void prs_set_session_key(prs_struct *ps, const char sess_key[16]) +{ + ps->sess_key = sess_key; +} + +/******************************************************************* + Stream a uint8. + ********************************************************************/ + +bool prs_uint8(const char *name, prs_struct *ps, int depth, uint8 *data8) +{ + char *q = prs_mem_get(ps, 1); + if (q == NULL) + return False; + + if (UNMARSHALLING(ps)) + *data8 = CVAL(q,0); + else + SCVAL(q,0,*data8); + + DEBUG(5,("%s%04x %s: %02x\n", tab_depth(5,depth), ps->data_offset, name, *data8)); + + ps->data_offset += 1; + + return True; +} + +/******************************************************************* + Stream a uint16* (allocate memory if unmarshalling) + ********************************************************************/ + +bool prs_pointer( const char *name, prs_struct *ps, int depth, + void *dta, size_t data_size, + bool (*prs_fn)(const char*, prs_struct*, int, void*) ) +{ + void ** data = (void **)dta; + uint32 data_p; + + /* output f000baaa to stream if the pointer is non-zero. */ + + data_p = *data ? 0xf000baaa : 0; + + if ( !prs_uint32("ptr", ps, depth, &data_p )) + return False; + + /* we're done if there is no data */ + + if ( !data_p ) + return True; + + if (UNMARSHALLING(ps)) { + if (data_size) { + if ( !(*data = PRS_ALLOC_MEM(ps, char, data_size)) ) + return False; + } else { + *data = NULL; + } + } + + return prs_fn(name, ps, depth, *data); +} + + +/******************************************************************* + Stream a uint16. + ********************************************************************/ + +bool prs_uint16(const char *name, prs_struct *ps, int depth, uint16 *data16) +{ + char *q = prs_mem_get(ps, sizeof(uint16)); + if (q == NULL) + return False; + + if (UNMARSHALLING(ps)) { + if (ps->bigendian_data) + *data16 = RSVAL(q,0); + else + *data16 = SVAL(q,0); + } else { + if (ps->bigendian_data) + RSSVAL(q,0,*data16); + else + SSVAL(q,0,*data16); + } + + DEBUG(5,("%s%04x %s: %04x\n", tab_depth(5,depth), ps->data_offset, name, *data16)); + + ps->data_offset += sizeof(uint16); + + return True; +} + +/******************************************************************* + Stream a uint32. + ********************************************************************/ + +bool prs_uint32(const char *name, prs_struct *ps, int depth, uint32 *data32) +{ + char *q = prs_mem_get(ps, sizeof(uint32)); + if (q == NULL) + return False; + + if (UNMARSHALLING(ps)) { + if (ps->bigendian_data) + *data32 = RIVAL(q,0); + else + *data32 = IVAL(q,0); + } else { + if (ps->bigendian_data) + RSIVAL(q,0,*data32); + else + SIVAL(q,0,*data32); + } + + DEBUG(5,("%s%04x %s: %08x\n", tab_depth(5,depth), ps->data_offset, name, *data32)); + + ps->data_offset += sizeof(uint32); + + return True; +} + +/******************************************************************* + Stream an int32. + ********************************************************************/ + +bool prs_int32(const char *name, prs_struct *ps, int depth, int32 *data32) +{ + char *q = prs_mem_get(ps, sizeof(int32)); + if (q == NULL) + return False; + + if (UNMARSHALLING(ps)) { + if (ps->bigendian_data) + *data32 = RIVALS(q,0); + else + *data32 = IVALS(q,0); + } else { + if (ps->bigendian_data) + RSIVALS(q,0,*data32); + else + SIVALS(q,0,*data32); + } + + DEBUG(5,("%s%04x %s: %08x\n", tab_depth(5,depth), ps->data_offset, name, *data32)); + + ps->data_offset += sizeof(int32); + + return True; +} + +/******************************************************************* + Stream a NTSTATUS + ********************************************************************/ + +bool prs_ntstatus(const char *name, prs_struct *ps, int depth, NTSTATUS *status) +{ + char *q = prs_mem_get(ps, sizeof(uint32)); + if (q == NULL) + return False; + + if (UNMARSHALLING(ps)) { + if (ps->bigendian_data) + *status = NT_STATUS(RIVAL(q,0)); + else + *status = NT_STATUS(IVAL(q,0)); + } else { + if (ps->bigendian_data) + RSIVAL(q,0,NT_STATUS_V(*status)); + else + SIVAL(q,0,NT_STATUS_V(*status)); + } + + DEBUG(5,("%s%04x %s: %s\n", tab_depth(5,depth), ps->data_offset, name, + nt_errstr(*status))); + + ps->data_offset += sizeof(uint32); + + return True; +} + +/******************************************************************* + Stream a DCE error code + ********************************************************************/ + +bool prs_dcerpc_status(const char *name, prs_struct *ps, int depth, NTSTATUS *status) +{ + char *q = prs_mem_get(ps, sizeof(uint32)); + if (q == NULL) + return False; + + if (UNMARSHALLING(ps)) { + if (ps->bigendian_data) + *status = NT_STATUS(RIVAL(q,0)); + else + *status = NT_STATUS(IVAL(q,0)); + } else { + if (ps->bigendian_data) + RSIVAL(q,0,NT_STATUS_V(*status)); + else + SIVAL(q,0,NT_STATUS_V(*status)); + } + + DEBUG(5,("%s%04x %s: %s\n", tab_depth(5,depth), ps->data_offset, name, + dcerpc_errstr(NT_STATUS_V(*status)))); + + ps->data_offset += sizeof(uint32); + + return True; +} + + +/******************************************************************* + Stream a WERROR + ********************************************************************/ + +bool prs_werror(const char *name, prs_struct *ps, int depth, WERROR *status) +{ + char *q = prs_mem_get(ps, sizeof(uint32)); + if (q == NULL) + return False; + + if (UNMARSHALLING(ps)) { + if (ps->bigendian_data) + *status = W_ERROR(RIVAL(q,0)); + else + *status = W_ERROR(IVAL(q,0)); + } else { + if (ps->bigendian_data) + RSIVAL(q,0,W_ERROR_V(*status)); + else + SIVAL(q,0,W_ERROR_V(*status)); + } + + DEBUG(5,("%s%04x %s: %s\n", tab_depth(5,depth), ps->data_offset, name, + dos_errstr(*status))); + + ps->data_offset += sizeof(uint32); + + return True; +} + + +/****************************************************************** + Stream an array of uint8s. Length is number of uint8s. + ********************************************************************/ + +bool prs_uint8s(bool charmode, const char *name, prs_struct *ps, int depth, uint8 *data8s, int len) +{ + int i; + char *q = prs_mem_get(ps, len); + if (q == NULL) + return False; + + if (UNMARSHALLING(ps)) { + for (i = 0; i < len; i++) + data8s[i] = CVAL(q,i); + } else { + for (i = 0; i < len; i++) + SCVAL(q, i, data8s[i]); + } + + DEBUG(5,("%s%04x %s: ", tab_depth(5,depth), ps->data_offset ,name)); + if (charmode) + print_asc(5, (unsigned char*)data8s, len); + else { + for (i = 0; i < len; i++) + DEBUG(5,("%02x ", data8s[i])); + } + DEBUG(5,("\n")); + + ps->data_offset += len; + + return True; +} + +/****************************************************************** + Stream an array of uint16s. Length is number of uint16s. + ********************************************************************/ + +bool prs_uint16s(bool charmode, const char *name, prs_struct *ps, int depth, uint16 *data16s, int len) +{ + int i; + char *q = prs_mem_get(ps, len * sizeof(uint16)); + if (q == NULL) + return False; + + if (UNMARSHALLING(ps)) { + if (ps->bigendian_data) { + for (i = 0; i < len; i++) + data16s[i] = RSVAL(q, 2*i); + } else { + for (i = 0; i < len; i++) + data16s[i] = SVAL(q, 2*i); + } + } else { + if (ps->bigendian_data) { + for (i = 0; i < len; i++) + RSSVAL(q, 2*i, data16s[i]); + } else { + for (i = 0; i < len; i++) + SSVAL(q, 2*i, data16s[i]); + } + } + + DEBUG(5,("%s%04x %s: ", tab_depth(5,depth), ps->data_offset, name)); + if (charmode) + print_asc(5, (unsigned char*)data16s, 2*len); + else { + for (i = 0; i < len; i++) + DEBUG(5,("%04x ", data16s[i])); + } + DEBUG(5,("\n")); + + ps->data_offset += (len * sizeof(uint16)); + + return True; +} + +/****************************************************************** + Start using a function for streaming unicode chars. If unmarshalling, + output must be little-endian, if marshalling, input must be little-endian. + ********************************************************************/ + +static void dbg_rw_punival(bool charmode, const char *name, int depth, prs_struct *ps, + char *in_buf, char *out_buf, int len) +{ + int i; + + if (UNMARSHALLING(ps)) { + if (ps->bigendian_data) { + for (i = 0; i < len; i++) + SSVAL(out_buf,2*i,RSVAL(in_buf, 2*i)); + } else { + for (i = 0; i < len; i++) + SSVAL(out_buf, 2*i, SVAL(in_buf, 2*i)); + } + } else { + if (ps->bigendian_data) { + for (i = 0; i < len; i++) + RSSVAL(in_buf, 2*i, SVAL(out_buf,2*i)); + } else { + for (i = 0; i < len; i++) + SSVAL(in_buf, 2*i, SVAL(out_buf,2*i)); + } + } + + DEBUG(5,("%s%04x %s: ", tab_depth(5,depth), ps->data_offset, name)); + if (charmode) + print_asc(5, (unsigned char*)out_buf, 2*len); + else { + for (i = 0; i < len; i++) + DEBUG(5,("%04x ", out_buf[i])); + } + DEBUG(5,("\n")); +} + +/****************************************************************** + Stream a unistr. Always little endian. + ********************************************************************/ + +bool prs_uint16uni(bool charmode, const char *name, prs_struct *ps, int depth, uint16 *data16s, int len) +{ + char *q = prs_mem_get(ps, len * sizeof(uint16)); + if (q == NULL) + return False; + + dbg_rw_punival(charmode, name, depth, ps, q, (char *)data16s, len); + ps->data_offset += (len * sizeof(uint16)); + + return True; +} + +/****************************************************************** + Stream an array of uint32s. Length is number of uint32s. + ********************************************************************/ + +bool prs_uint32s(bool charmode, const char *name, prs_struct *ps, int depth, uint32 *data32s, int len) +{ + int i; + char *q = prs_mem_get(ps, len * sizeof(uint32)); + if (q == NULL) + return False; + + if (UNMARSHALLING(ps)) { + if (ps->bigendian_data) { + for (i = 0; i < len; i++) + data32s[i] = RIVAL(q, 4*i); + } else { + for (i = 0; i < len; i++) + data32s[i] = IVAL(q, 4*i); + } + } else { + if (ps->bigendian_data) { + for (i = 0; i < len; i++) + RSIVAL(q, 4*i, data32s[i]); + } else { + for (i = 0; i < len; i++) + SIVAL(q, 4*i, data32s[i]); + } + } + + DEBUG(5,("%s%04x %s: ", tab_depth(5,depth), ps->data_offset, name)); + if (charmode) + print_asc(5, (unsigned char*)data32s, 4*len); + else { + for (i = 0; i < len; i++) + DEBUG(5,("%08x ", data32s[i])); + } + DEBUG(5,("\n")); + + ps->data_offset += (len * sizeof(uint32)); + + return True; +} + +/****************************************************************** + Stream an array of unicode string, length/buffer specified separately, + in uint16 chars. The unicode string is already in little-endian format. + ********************************************************************/ + +bool prs_buffer5(bool charmode, const char *name, prs_struct *ps, int depth, BUFFER5 *str) +{ + char *p; + char *q = prs_mem_get(ps, str->buf_len * sizeof(uint16)); + if (q == NULL) + return False; + + /* If the string is empty, we don't have anything to stream */ + if (str->buf_len==0) + return True; + + if (UNMARSHALLING(ps)) { + str->buffer = PRS_ALLOC_MEM(ps,uint16,str->buf_len); + if (str->buffer == NULL) + return False; + } + + p = (char *)str->buffer; + + dbg_rw_punival(charmode, name, depth, ps, q, p, str->buf_len); + + ps->data_offset += (str->buf_len * sizeof(uint16)); + + return True; +} + +/****************************************************************** + Stream a "not" unicode string, length/buffer specified separately, + in byte chars. String is in little-endian format. + ********************************************************************/ + +bool prs_regval_buffer(bool charmode, const char *name, prs_struct *ps, int depth, REGVAL_BUFFER *buf) +{ + char *p; + char *q = prs_mem_get(ps, buf->buf_len); + if (q == NULL) + return False; + + if (UNMARSHALLING(ps)) { + if (buf->buf_len > buf->buf_max_len) { + return False; + } + if ( buf->buf_max_len ) { + buf->buffer = PRS_ALLOC_MEM(ps, uint16, buf->buf_max_len); + if ( buf->buffer == NULL ) + return False; + } else { + buf->buffer = NULL; + } + } + + p = (char *)buf->buffer; + + dbg_rw_punival(charmode, name, depth, ps, q, p, buf->buf_len/2); + ps->data_offset += buf->buf_len; + + return True; +} + +/****************************************************************** + Stream a string, length/buffer specified separately, + in uint8 chars. + ********************************************************************/ + +bool prs_string2(bool charmode, const char *name, prs_struct *ps, int depth, STRING2 *str) +{ + unsigned int i; + char *q = prs_mem_get(ps, str->str_str_len); + if (q == NULL) + return False; + + if (UNMARSHALLING(ps)) { + if (str->str_str_len > str->str_max_len) { + return False; + } + if (str->str_max_len) { + str->buffer = PRS_ALLOC_MEM(ps,unsigned char, str->str_max_len); + if (str->buffer == NULL) + return False; + } else { + str->buffer = NULL; + /* Return early to ensure Coverity isn't confused. */ + DEBUG(5,("%s%04x %s: \n", tab_depth(5,depth), ps->data_offset, name)); + return True; + } + } + + if (UNMARSHALLING(ps)) { + for (i = 0; i < str->str_str_len; i++) + str->buffer[i] = CVAL(q,i); + } else { + for (i = 0; i < str->str_str_len; i++) + SCVAL(q, i, str->buffer[i]); + } + + DEBUG(5,("%s%04x %s: ", tab_depth(5,depth), ps->data_offset, name)); + if (charmode) + print_asc(5, (unsigned char*)str->buffer, str->str_str_len); + else { + for (i = 0; i < str->str_str_len; i++) + DEBUG(5,("%02x ", str->buffer[i])); + } + DEBUG(5,("\n")); + + ps->data_offset += str->str_str_len; + + return True; +} + +/****************************************************************** + Stream a unicode string, length/buffer specified separately, + in uint16 chars. The unicode string is already in little-endian format. + ********************************************************************/ + +bool prs_unistr2(bool charmode, const char *name, prs_struct *ps, int depth, UNISTR2 *str) +{ + char *p; + char *q = prs_mem_get(ps, str->uni_str_len * sizeof(uint16)); + if (q == NULL) + return False; + + /* If the string is empty, we don't have anything to stream */ + if (str->uni_str_len==0) + return True; + + if (UNMARSHALLING(ps)) { + if (str->uni_str_len > str->uni_max_len) { + return False; + } + if (str->uni_max_len) { + str->buffer = PRS_ALLOC_MEM(ps,uint16,str->uni_max_len); + if (str->buffer == NULL) + return False; + } else { + str->buffer = NULL; + } + } + + p = (char *)str->buffer; + + dbg_rw_punival(charmode, name, depth, ps, q, p, str->uni_str_len); + + ps->data_offset += (str->uni_str_len * sizeof(uint16)); + + return True; +} + +/****************************************************************** + Stream a unicode string, length/buffer specified separately, + in uint16 chars. The unicode string is already in little-endian format. + ********************************************************************/ + +bool prs_unistr3(bool charmode, const char *name, UNISTR3 *str, prs_struct *ps, int depth) +{ + char *p; + char *q = prs_mem_get(ps, str->uni_str_len * sizeof(uint16)); + if (q == NULL) + return False; + + if (UNMARSHALLING(ps)) { + if (str->uni_str_len) { + str->str.buffer = PRS_ALLOC_MEM(ps,uint16,str->uni_str_len); + if (str->str.buffer == NULL) + return False; + } else { + str->str.buffer = NULL; + } + } + + p = (char *)str->str.buffer; + + dbg_rw_punival(charmode, name, depth, ps, q, p, str->uni_str_len); + ps->data_offset += (str->uni_str_len * sizeof(uint16)); + + return True; +} + +/******************************************************************* + Stream a unicode null-terminated string. As the string is already + in little-endian format then do it as a stream of bytes. + ********************************************************************/ + +bool prs_unistr(const char *name, prs_struct *ps, int depth, UNISTR *str) +{ + unsigned int len = 0; + unsigned char *p = (unsigned char *)str->buffer; + uint8 *start; + char *q; + uint32 max_len; + uint16* ptr; + + if (MARSHALLING(ps)) { + + for(len = 0; str->buffer[len] != 0; len++) + ; + + q = prs_mem_get(ps, (len+1)*2); + if (q == NULL) + return False; + + start = (uint8*)q; + + for(len = 0; str->buffer[len] != 0; len++) { + if(ps->bigendian_data) { + /* swap bytes - p is little endian, q is big endian. */ + q[0] = (char)p[1]; + q[1] = (char)p[0]; + p += 2; + q += 2; + } + else + { + q[0] = (char)p[0]; + q[1] = (char)p[1]; + p += 2; + q += 2; + } + } + + /* + * even if the string is 'empty' (only an \0 char) + * at this point the leading \0 hasn't been parsed. + * so parse it now + */ + + q[0] = 0; + q[1] = 0; + q += 2; + + len++; + + DEBUG(5,("%s%04x %s: ", tab_depth(5,depth), ps->data_offset, name)); + print_asc(5, (unsigned char*)start, 2*len); + DEBUG(5, ("\n")); + } + else { /* unmarshalling */ + + uint32 alloc_len = 0; + q = ps->data_p + prs_offset(ps); + + /* + * Work out how much space we need and talloc it. + */ + max_len = (ps->buffer_size - ps->data_offset)/sizeof(uint16); + + /* the test of the value of *ptr helps to catch the circumstance + where we have an emtpty (non-existent) string in the buffer */ + for ( ptr = (uint16 *)q; *ptr++ && (alloc_len <= max_len); alloc_len++) + /* do nothing */ + ; + + if (alloc_len < max_len) + alloc_len += 1; + + /* should we allocate anything at all? */ + str->buffer = PRS_ALLOC_MEM(ps,uint16,alloc_len); + if ((str->buffer == NULL) && (alloc_len > 0)) + return False; + + p = (unsigned char *)str->buffer; + + len = 0; + /* the (len < alloc_len) test is to prevent us from overwriting + memory that is not ours...if we get that far, we have a non-null + terminated string in the buffer and have messed up somewhere */ + while ((len < alloc_len) && (*(uint16 *)q != 0)) { + if(ps->bigendian_data) + { + /* swap bytes - q is big endian, p is little endian. */ + p[0] = (unsigned char)q[1]; + p[1] = (unsigned char)q[0]; + p += 2; + q += 2; + } else { + + p[0] = (unsigned char)q[0]; + p[1] = (unsigned char)q[1]; + p += 2; + q += 2; + } + + len++; + } + if (len < alloc_len) { + /* NULL terminate the UNISTR */ + str->buffer[len++] = '\0'; + } + + DEBUG(5,("%s%04x %s: ", tab_depth(5,depth), ps->data_offset, name)); + print_asc(5, (unsigned char*)str->buffer, 2*len); + DEBUG(5, ("\n")); + } + + /* set the offset in the prs_struct; 'len' points to the + terminiating NULL in the UNISTR so we need to go one more + uint16 */ + ps->data_offset += (len)*2; + + return True; +} + + +/******************************************************************* + Stream a null-terminated string. len is strlen, and therefore does + not include the null-termination character. + ********************************************************************/ + +bool prs_string(const char *name, prs_struct *ps, int depth, char *str, int max_buf_size) +{ + char *q; + int i; + int len; + + if (UNMARSHALLING(ps)) + len = strlen(&ps->data_p[ps->data_offset]); + else + len = strlen(str); + + len = MIN(len, (max_buf_size-1)); + + q = prs_mem_get(ps, len+1); + if (q == NULL) + return False; + + for(i = 0; i < len; i++) { + if (UNMARSHALLING(ps)) + str[i] = q[i]; + else + q[i] = str[i]; + } + + /* The terminating null. */ + str[i] = '\0'; + + if (MARSHALLING(ps)) { + q[i] = '\0'; + } + + ps->data_offset += len+1; + + dump_data(5+depth, (uint8 *)q, len); + + return True; +} + +bool prs_string_alloc(const char *name, prs_struct *ps, int depth, const char **str) +{ + size_t len; + char *tmp_str; + + if (UNMARSHALLING(ps)) { + len = strlen(&ps->data_p[ps->data_offset]); + } else { + len = strlen(*str); + } + + tmp_str = PRS_ALLOC_MEM(ps, char, len+1); + + if (tmp_str == NULL) { + return False; + } + + if (MARSHALLING(ps)) { + strncpy(tmp_str, *str, len); + } + + if (!prs_string(name, ps, depth, tmp_str, len+1)) { + return False; + } + + *str = tmp_str; + return True; +} + +/******************************************************************* + prs_uint16 wrapper. Call this and it sets up a pointer to where the + uint16 should be stored, or gets the size if reading. + ********************************************************************/ + +bool prs_uint16_pre(const char *name, prs_struct *ps, int depth, uint16 *data16, uint32 *offset) +{ + *offset = ps->data_offset; + if (UNMARSHALLING(ps)) { + /* reading. */ + return prs_uint16(name, ps, depth, data16); + } else { + char *q = prs_mem_get(ps, sizeof(uint16)); + if(q ==NULL) + return False; + ps->data_offset += sizeof(uint16); + } + return True; +} + +/******************************************************************* + prs_uint16 wrapper. call this and it retrospectively stores the size. + does nothing on reading, as that is already handled by ...._pre() + ********************************************************************/ + +bool prs_uint16_post(const char *name, prs_struct *ps, int depth, uint16 *data16, + uint32 ptr_uint16, uint32 start_offset) +{ + if (MARSHALLING(ps)) { + /* + * Writing - temporarily move the offset pointer. + */ + uint16 data_size = ps->data_offset - start_offset; + uint32 old_offset = ps->data_offset; + + ps->data_offset = ptr_uint16; + if(!prs_uint16(name, ps, depth, &data_size)) { + ps->data_offset = old_offset; + return False; + } + ps->data_offset = old_offset; + } else { + ps->data_offset = start_offset + (uint32)(*data16); + } + return True; +} + +/******************************************************************* + prs_uint32 wrapper. Call this and it sets up a pointer to where the + uint32 should be stored, or gets the size if reading. + ********************************************************************/ + +bool prs_uint32_pre(const char *name, prs_struct *ps, int depth, uint32 *data32, uint32 *offset) +{ + *offset = ps->data_offset; + if (UNMARSHALLING(ps) && (data32 != NULL)) { + /* reading. */ + return prs_uint32(name, ps, depth, data32); + } else { + ps->data_offset += sizeof(uint32); + } + return True; +} + +/******************************************************************* + prs_uint32 wrapper. call this and it retrospectively stores the size. + does nothing on reading, as that is already handled by ...._pre() + ********************************************************************/ + +bool prs_uint32_post(const char *name, prs_struct *ps, int depth, uint32 *data32, + uint32 ptr_uint32, uint32 data_size) +{ + if (MARSHALLING(ps)) { + /* + * Writing - temporarily move the offset pointer. + */ + uint32 old_offset = ps->data_offset; + ps->data_offset = ptr_uint32; + if(!prs_uint32(name, ps, depth, &data_size)) { + ps->data_offset = old_offset; + return False; + } + ps->data_offset = old_offset; + } + return True; +} + +/* useful function to store a structure in rpc wire format */ +int tdb_prs_store(TDB_CONTEXT *tdb, TDB_DATA kbuf, prs_struct *ps) +{ + TDB_DATA dbuf; + dbuf.dptr = (uint8 *)ps->data_p; + dbuf.dsize = prs_offset(ps); + return tdb_trans_store(tdb, kbuf, dbuf, TDB_REPLACE); +} + +/* useful function to fetch a structure into rpc wire format */ +int tdb_prs_fetch(TDB_CONTEXT *tdb, TDB_DATA kbuf, prs_struct *ps, TALLOC_CTX *mem_ctx) +{ + TDB_DATA dbuf; + + prs_init_empty(ps, mem_ctx, UNMARSHALL); + + dbuf = tdb_fetch(tdb, kbuf); + if (!dbuf.dptr) + return -1; + + prs_give_memory(ps, (char *)dbuf.dptr, dbuf.dsize, True); + + return 0; +} + +/******************************************************************* + hash a stream. + ********************************************************************/ + +bool prs_hash1(prs_struct *ps, uint32 offset, int len) +{ + char *q; + + q = ps->data_p; + q = &q[offset]; + +#ifdef DEBUG_PASSWORD + DEBUG(100, ("prs_hash1\n")); + dump_data(100, (uint8 *)ps->sess_key, 16); + dump_data(100, (uint8 *)q, len); +#endif + SamOEMhash((uchar *) q, (const unsigned char *)ps->sess_key, len); + +#ifdef DEBUG_PASSWORD + dump_data(100, (uint8 *)q, len); +#endif + + return True; +} + +/******************************************************************* + Create a digest over the entire packet (including the data), and + MD5 it with the session key. + ********************************************************************/ + +static void schannel_digest(struct schannel_auth_struct *a, + enum pipe_auth_level auth_level, + RPC_AUTH_SCHANNEL_CHK * verf, + char *data, size_t data_len, + uchar digest_final[16]) +{ + uchar whole_packet_digest[16]; + uchar zeros[4]; + struct MD5Context ctx3; + + ZERO_STRUCT(zeros); + + /* verfiy the signature on the packet by MD5 over various bits */ + MD5Init(&ctx3); + /* use our sequence number, which ensures the packet is not + out of order */ + MD5Update(&ctx3, zeros, sizeof(zeros)); + MD5Update(&ctx3, verf->sig, sizeof(verf->sig)); + if (auth_level == PIPE_AUTH_LEVEL_PRIVACY) { + MD5Update(&ctx3, verf->confounder, sizeof(verf->confounder)); + } + MD5Update(&ctx3, (const unsigned char *)data, data_len); + MD5Final(whole_packet_digest, &ctx3); + dump_data_pw("whole_packet_digest:\n", whole_packet_digest, sizeof(whole_packet_digest)); + + /* MD5 this result and the session key, to prove that + only a valid client could had produced this */ + hmac_md5(a->sess_key, whole_packet_digest, sizeof(whole_packet_digest), digest_final); +} + +/******************************************************************* + Calculate the key with which to encode the data payload + ********************************************************************/ + +static void schannel_get_sealing_key(struct schannel_auth_struct *a, + RPC_AUTH_SCHANNEL_CHK *verf, + uchar sealing_key[16]) +{ + uchar zeros[4]; + uchar digest2[16]; + uchar sess_kf0[16]; + int i; + + ZERO_STRUCT(zeros); + + for (i = 0; i < sizeof(sess_kf0); i++) { + sess_kf0[i] = a->sess_key[i] ^ 0xf0; + } + + dump_data_pw("sess_kf0:\n", sess_kf0, sizeof(sess_kf0)); + + /* MD5 of sess_kf0 and 4 zero bytes */ + hmac_md5(sess_kf0, zeros, 0x4, digest2); + dump_data_pw("digest2:\n", digest2, sizeof(digest2)); + + /* MD5 of the above result, plus 8 bytes of sequence number */ + hmac_md5(digest2, verf->seq_num, sizeof(verf->seq_num), sealing_key); + dump_data_pw("sealing_key:\n", sealing_key, 16); +} + +/******************************************************************* + Encode or Decode the sequence number (which is symmetric) + ********************************************************************/ + +static void schannel_deal_with_seq_num(struct schannel_auth_struct *a, + RPC_AUTH_SCHANNEL_CHK *verf) +{ + uchar zeros[4]; + uchar sequence_key[16]; + uchar digest1[16]; + + ZERO_STRUCT(zeros); + + hmac_md5(a->sess_key, zeros, sizeof(zeros), digest1); + dump_data_pw("(sequence key) digest1:\n", digest1, sizeof(digest1)); + + hmac_md5(digest1, verf->packet_digest, 8, sequence_key); + + dump_data_pw("sequence_key:\n", sequence_key, sizeof(sequence_key)); + + dump_data_pw("seq_num (before):\n", verf->seq_num, sizeof(verf->seq_num)); + SamOEMhash(verf->seq_num, sequence_key, 8); + dump_data_pw("seq_num (after):\n", verf->seq_num, sizeof(verf->seq_num)); +} + +/******************************************************************* +creates an RPC_AUTH_SCHANNEL_CHK structure. +********************************************************************/ + +static bool init_rpc_auth_schannel_chk(RPC_AUTH_SCHANNEL_CHK * chk, + const uchar sig[8], + const uchar packet_digest[8], + const uchar seq_num[8], const uchar confounder[8]) +{ + if (chk == NULL) + return False; + + memcpy(chk->sig, sig, sizeof(chk->sig)); + memcpy(chk->packet_digest, packet_digest, sizeof(chk->packet_digest)); + memcpy(chk->seq_num, seq_num, sizeof(chk->seq_num)); + memcpy(chk->confounder, confounder, sizeof(chk->confounder)); + + return True; +} + +/******************************************************************* + Encode a blob of data using the schannel alogrithm, also produceing + a checksum over the original data. We currently only support + signing and sealing togeather - the signing-only code is close, but not + quite compatible with what MS does. + ********************************************************************/ + +void schannel_encode(struct schannel_auth_struct *a, enum pipe_auth_level auth_level, + enum schannel_direction direction, + RPC_AUTH_SCHANNEL_CHK * verf, + char *data, size_t data_len) +{ + uchar digest_final[16]; + uchar confounder[8]; + uchar seq_num[8]; + static const uchar nullbytes[8] = { 0, }; + + static const uchar schannel_seal_sig[8] = SCHANNEL_SEAL_SIGNATURE; + static const uchar schannel_sign_sig[8] = SCHANNEL_SIGN_SIGNATURE; + const uchar *schannel_sig = NULL; + + DEBUG(10,("SCHANNEL: schannel_encode seq_num=%d data_len=%lu\n", a->seq_num, (unsigned long)data_len)); + + if (auth_level == PIPE_AUTH_LEVEL_PRIVACY) { + schannel_sig = schannel_seal_sig; + } else { + schannel_sig = schannel_sign_sig; + } + + /* fill the 'confounder' with random data */ + generate_random_buffer(confounder, sizeof(confounder)); + + dump_data_pw("a->sess_key:\n", a->sess_key, sizeof(a->sess_key)); + + RSIVAL(seq_num, 0, a->seq_num); + + switch (direction) { + case SENDER_IS_INITIATOR: + SIVAL(seq_num, 4, 0x80); + break; + case SENDER_IS_ACCEPTOR: + SIVAL(seq_num, 4, 0x0); + break; + } + + dump_data_pw("verf->seq_num:\n", seq_num, sizeof(verf->seq_num)); + + init_rpc_auth_schannel_chk(verf, schannel_sig, nullbytes, + seq_num, confounder); + + /* produce a digest of the packet to prove it's legit (before we seal it) */ + schannel_digest(a, auth_level, verf, data, data_len, digest_final); + memcpy(verf->packet_digest, digest_final, sizeof(verf->packet_digest)); + + if (auth_level == PIPE_AUTH_LEVEL_PRIVACY) { + uchar sealing_key[16]; + + /* get the key to encode the data with */ + schannel_get_sealing_key(a, verf, sealing_key); + + /* encode the verification data */ + dump_data_pw("verf->confounder:\n", verf->confounder, sizeof(verf->confounder)); + SamOEMhash(verf->confounder, sealing_key, 8); + + dump_data_pw("verf->confounder_enc:\n", verf->confounder, sizeof(verf->confounder)); + + /* encode the packet payload */ + dump_data_pw("data:\n", (const unsigned char *)data, data_len); + SamOEMhash((unsigned char *)data, sealing_key, data_len); + dump_data_pw("data_enc:\n", (const unsigned char *)data, data_len); + } + + /* encode the sequence number (key based on packet digest) */ + /* needs to be done after the sealing, as the original version + is used in the sealing stuff... */ + schannel_deal_with_seq_num(a, verf); + + return; +} + +/******************************************************************* + Decode a blob of data using the schannel alogrithm, also verifiying + a checksum over the original data. We currently can verify signed messages, + as well as decode sealed messages + ********************************************************************/ + +bool schannel_decode(struct schannel_auth_struct *a, enum pipe_auth_level auth_level, + enum schannel_direction direction, + RPC_AUTH_SCHANNEL_CHK * verf, char *data, size_t data_len) +{ + uchar digest_final[16]; + + static const uchar schannel_seal_sig[8] = SCHANNEL_SEAL_SIGNATURE; + static const uchar schannel_sign_sig[8] = SCHANNEL_SIGN_SIGNATURE; + const uchar *schannel_sig = NULL; + + uchar seq_num[8]; + + DEBUG(10,("SCHANNEL: schannel_decode seq_num=%d data_len=%lu\n", a->seq_num, (unsigned long)data_len)); + + if (auth_level == PIPE_AUTH_LEVEL_PRIVACY) { + schannel_sig = schannel_seal_sig; + } else { + schannel_sig = schannel_sign_sig; + } + + /* Create the expected sequence number for comparison */ + RSIVAL(seq_num, 0, a->seq_num); + + switch (direction) { + case SENDER_IS_INITIATOR: + SIVAL(seq_num, 4, 0x80); + break; + case SENDER_IS_ACCEPTOR: + SIVAL(seq_num, 4, 0x0); + break; + } + + DEBUG(10,("SCHANNEL: schannel_decode seq_num=%d data_len=%lu\n", a->seq_num, (unsigned long)data_len)); + dump_data_pw("a->sess_key:\n", a->sess_key, sizeof(a->sess_key)); + + dump_data_pw("seq_num:\n", seq_num, sizeof(seq_num)); + + /* extract the sequence number (key based on supplied packet digest) */ + /* needs to be done before the sealing, as the original version + is used in the sealing stuff... */ + schannel_deal_with_seq_num(a, verf); + + if (memcmp(verf->seq_num, seq_num, sizeof(seq_num))) { + /* don't even bother with the below if the sequence number is out */ + /* The sequence number is MD5'ed with a key based on the whole-packet + digest, as supplied by the client. We check that it's a valid + checksum after the decode, below + */ + DEBUG(2, ("schannel_decode: FAILED: packet sequence number:\n")); + dump_data(2, verf->seq_num, sizeof(verf->seq_num)); + DEBUG(2, ("should be:\n")); + dump_data(2, seq_num, sizeof(seq_num)); + + return False; + } + + if (memcmp(verf->sig, schannel_sig, sizeof(verf->sig))) { + /* Validate that the other end sent the expected header */ + DEBUG(2, ("schannel_decode: FAILED: packet header:\n")); + dump_data(2, verf->sig, sizeof(verf->sig)); + DEBUG(2, ("should be:\n")); + dump_data(2, schannel_sig, sizeof(schannel_sig)); + return False; + } + + if (auth_level == PIPE_AUTH_LEVEL_PRIVACY) { + uchar sealing_key[16]; + + /* get the key to extract the data with */ + schannel_get_sealing_key(a, verf, sealing_key); + + /* extract the verification data */ + dump_data_pw("verf->confounder:\n", verf->confounder, + sizeof(verf->confounder)); + SamOEMhash(verf->confounder, sealing_key, 8); + + dump_data_pw("verf->confounder_dec:\n", verf->confounder, + sizeof(verf->confounder)); + + /* extract the packet payload */ + dump_data_pw("data :\n", (const unsigned char *)data, data_len); + SamOEMhash((unsigned char *)data, sealing_key, data_len); + dump_data_pw("datadec:\n", (const unsigned char *)data, data_len); + } + + /* digest includes 'data' after unsealing */ + schannel_digest(a, auth_level, verf, data, data_len, digest_final); + + dump_data_pw("Calculated digest:\n", digest_final, + sizeof(digest_final)); + dump_data_pw("verf->packet_digest:\n", verf->packet_digest, + sizeof(verf->packet_digest)); + + /* compare - if the client got the same result as us, then + it must know the session key */ + return (memcmp(digest_final, verf->packet_digest, + sizeof(verf->packet_digest)) == 0); +} + +/******************************************************************* +creates a new prs_struct containing a DATA_BLOB +********************************************************************/ +bool prs_init_data_blob(prs_struct *prs, DATA_BLOB *blob, TALLOC_CTX *mem_ctx) +{ + if (!prs_init( prs, RPC_MAX_PDU_FRAG_LEN, mem_ctx, MARSHALL )) + return False; + + + if (!prs_copy_data_in(prs, (char *)blob->data, blob->length)) + return False; + + return True; +} + +/******************************************************************* +return the contents of a prs_struct in a DATA_BLOB +********************************************************************/ +bool prs_data_blob(prs_struct *prs, DATA_BLOB *blob, TALLOC_CTX *mem_ctx) +{ + blob->length = prs_data_size(prs); + blob->data = (uint8 *)TALLOC_ZERO_SIZE(mem_ctx, blob->length); + + /* set the pointer at the end of the buffer */ + prs_set_offset( prs, prs_data_size(prs) ); + + if (!prs_copy_all_data_out((char *)blob->data, prs)) + return False; + + return True; +} diff --git a/source3/rpc_parse/parse_rpc.c b/source3/rpc_parse/parse_rpc.c new file mode 100644 index 0000000000..1477a4c81e --- /dev/null +++ b/source3/rpc_parse/parse_rpc.c @@ -0,0 +1,651 @@ +/* + * Unix SMB/CIFS implementation. + * RPC Pipe client / server routines + * Copyright (C) Andrew Tridgell 1992-1997, + * Copyright (C) Luke Kenneth Casson Leighton 1996-1997, + * Copyright (C) Paul Ashton 1997. + * Copyright (C) Jeremy Allison 1999. + * + * 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 + * the Free Software Foundation; either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, see <http://www.gnu.org/licenses/>. + */ + +#include "includes.h" + +#undef DBGC_CLASS +#define DBGC_CLASS DBGC_RPC_PARSE + +/******************************************************************* + Inits an RPC_HDR structure. +********************************************************************/ + +void init_rpc_hdr(RPC_HDR *hdr, enum RPC_PKT_TYPE pkt_type, uint8 flags, + uint32 call_id, int data_len, int auth_len) +{ + hdr->major = 5; /* RPC version 5 */ + hdr->minor = 0; /* minor version 0 */ + hdr->pkt_type = pkt_type; /* RPC packet type */ + hdr->flags = flags; /* dce/rpc flags */ + hdr->pack_type[0] = 0x10; /* little-endian data representation */ + hdr->pack_type[1] = 0; /* packed data representation */ + hdr->pack_type[2] = 0; /* packed data representation */ + hdr->pack_type[3] = 0; /* packed data representation */ + hdr->frag_len = data_len; /* fragment length, fill in later */ + hdr->auth_len = auth_len; /* authentication length */ + hdr->call_id = call_id; /* call identifier - match incoming RPC */ +} + +/******************************************************************* + Reads or writes an RPC_HDR structure. +********************************************************************/ + +bool smb_io_rpc_hdr(const char *desc, RPC_HDR *rpc, prs_struct *ps, int depth) +{ + if (rpc == NULL) + return False; + + prs_debug(ps, depth, desc, "smb_io_rpc_hdr"); + depth++; + + if(!prs_uint8 ("major ", ps, depth, &rpc->major)) + return False; + + if(!prs_uint8 ("minor ", ps, depth, &rpc->minor)) + return False; + if(!prs_uint8 ("pkt_type ", ps, depth, &rpc->pkt_type)) + return False; + if(!prs_uint8 ("flags ", ps, depth, &rpc->flags)) + return False; + + /* We always marshall in little endian format. */ + if (MARSHALLING(ps)) + rpc->pack_type[0] = 0x10; + + if(!prs_uint8("pack_type0", ps, depth, &rpc->pack_type[0])) + return False; + if(!prs_uint8("pack_type1", ps, depth, &rpc->pack_type[1])) + return False; + if(!prs_uint8("pack_type2", ps, depth, &rpc->pack_type[2])) + return False; + if(!prs_uint8("pack_type3", ps, depth, &rpc->pack_type[3])) + return False; + + /* + * If reading and pack_type[0] == 0 then the data is in big-endian + * format. Set the flag in the prs_struct to specify reverse-endainness. + */ + + if (UNMARSHALLING(ps) && rpc->pack_type[0] == 0) { + DEBUG(10,("smb_io_rpc_hdr: PDU data format is big-endian. Setting flag.\n")); + prs_set_endian_data(ps, RPC_BIG_ENDIAN); + } + + if(!prs_uint16("frag_len ", ps, depth, &rpc->frag_len)) + return False; + if(!prs_uint16("auth_len ", ps, depth, &rpc->auth_len)) + return False; + if(!prs_uint32("call_id ", ps, depth, &rpc->call_id)) + return False; + return True; +} + +/******************************************************************* + Reads or writes an RPC_IFACE structure. +********************************************************************/ + +static bool smb_io_rpc_iface(const char *desc, RPC_IFACE *ifc, prs_struct *ps, int depth) +{ + if (ifc == NULL) + return False; + + prs_debug(ps, depth, desc, "smb_io_rpc_iface"); + depth++; + + if (!prs_align(ps)) + return False; + + if (!smb_io_uuid( "uuid", &ifc->uuid, ps, depth)) + return False; + + if(!prs_uint32 ("version", ps, depth, &ifc->if_version)) + return False; + + return True; +} + +/******************************************************************* + Inits an RPC_ADDR_STR structure. +********************************************************************/ + +static void init_rpc_addr_str(RPC_ADDR_STR *str, const char *name) +{ + str->len = strlen(name) + 1; + fstrcpy(str->str, name); +} + +/******************************************************************* + Reads or writes an RPC_ADDR_STR structure. +********************************************************************/ + +static bool smb_io_rpc_addr_str(const char *desc, RPC_ADDR_STR *str, prs_struct *ps, int depth) +{ + if (str == NULL) + return False; + + prs_debug(ps, depth, desc, "smb_io_rpc_addr_str"); + depth++; + if(!prs_align(ps)) + return False; + + if(!prs_uint16 ( "len", ps, depth, &str->len)) + return False; + if(!prs_uint8s (True, "str", ps, depth, (uchar*)str->str, MIN(str->len, sizeof(str->str)) )) + return False; + return True; +} + +/******************************************************************* + Inits an RPC_HDR_BBA structure. +********************************************************************/ + +static void init_rpc_hdr_bba(RPC_HDR_BBA *bba, uint16 max_tsize, uint16 max_rsize, uint32 assoc_gid) +{ + bba->max_tsize = max_tsize; /* maximum transmission fragment size (0x1630) */ + bba->max_rsize = max_rsize; /* max receive fragment size (0x1630) */ + bba->assoc_gid = assoc_gid; /* associated group id (0x0) */ +} + +/******************************************************************* + Reads or writes an RPC_HDR_BBA structure. +********************************************************************/ + +static bool smb_io_rpc_hdr_bba(const char *desc, RPC_HDR_BBA *rpc, prs_struct *ps, int depth) +{ + if (rpc == NULL) + return False; + + prs_debug(ps, depth, desc, "smb_io_rpc_hdr_bba"); + depth++; + + if(!prs_uint16("max_tsize", ps, depth, &rpc->max_tsize)) + return False; + if(!prs_uint16("max_rsize", ps, depth, &rpc->max_rsize)) + return False; + if(!prs_uint32("assoc_gid", ps, depth, &rpc->assoc_gid)) + return False; + return True; +} + +/******************************************************************* + Inits an RPC_CONTEXT structure. + Note the transfer pointer must remain valid until this is marshalled. +********************************************************************/ + +void init_rpc_context(RPC_CONTEXT *rpc_ctx, uint16 context_id, + const RPC_IFACE *abstract, const RPC_IFACE *transfer) +{ + rpc_ctx->context_id = context_id ; /* presentation context identifier (0x0) */ + rpc_ctx->num_transfer_syntaxes = 1 ; /* the number of syntaxes (has always been 1?)(0x1) */ + + /* num and vers. of interface client is using */ + rpc_ctx->abstract = *abstract; + + /* vers. of interface to use for replies */ + rpc_ctx->transfer = CONST_DISCARD(RPC_IFACE *, transfer); +} + +/******************************************************************* + Inits an RPC_HDR_RB structure. + Note the context pointer must remain valid until this is marshalled. +********************************************************************/ + +void init_rpc_hdr_rb(RPC_HDR_RB *rpc, + uint16 max_tsize, uint16 max_rsize, uint32 assoc_gid, + RPC_CONTEXT *context) +{ + init_rpc_hdr_bba(&rpc->bba, max_tsize, max_rsize, assoc_gid); + + rpc->num_contexts = 1; + rpc->rpc_context = context; +} + +/******************************************************************* + Reads or writes an RPC_CONTEXT structure. +********************************************************************/ + +bool smb_io_rpc_context(const char *desc, RPC_CONTEXT *rpc_ctx, prs_struct *ps, int depth) +{ + int i; + + if (rpc_ctx == NULL) + return False; + + if(!prs_align(ps)) + return False; + if(!prs_uint16("context_id ", ps, depth, &rpc_ctx->context_id )) + return False; + if(!prs_uint8 ("num_transfer_syntaxes", ps, depth, &rpc_ctx->num_transfer_syntaxes)) + return False; + + /* num_transfer_syntaxes must not be zero. */ + if (rpc_ctx->num_transfer_syntaxes == 0) + return False; + + if(!smb_io_rpc_iface("", &rpc_ctx->abstract, ps, depth)) + return False; + + if (UNMARSHALLING(ps)) { + if (!(rpc_ctx->transfer = PRS_ALLOC_MEM(ps, RPC_IFACE, rpc_ctx->num_transfer_syntaxes))) { + return False; + } + } + + for (i = 0; i < rpc_ctx->num_transfer_syntaxes; i++ ) { + if (!smb_io_rpc_iface("", &rpc_ctx->transfer[i], ps, depth)) + return False; + } + return True; +} + +/******************************************************************* + Reads or writes an RPC_HDR_RB structure. +********************************************************************/ + +bool smb_io_rpc_hdr_rb(const char *desc, RPC_HDR_RB *rpc, prs_struct *ps, int depth) +{ + int i; + + if (rpc == NULL) + return False; + + prs_debug(ps, depth, desc, "smb_io_rpc_hdr_rb"); + depth++; + + if(!smb_io_rpc_hdr_bba("", &rpc->bba, ps, depth)) + return False; + + if(!prs_uint8("num_contexts", ps, depth, &rpc->num_contexts)) + return False; + + /* 3 pad bytes following - will be mopped up by the prs_align in smb_io_rpc_context(). */ + + /* num_contexts must not be zero. */ + if (rpc->num_contexts == 0) + return False; + + if (UNMARSHALLING(ps)) { + if (!(rpc->rpc_context = PRS_ALLOC_MEM(ps, RPC_CONTEXT, rpc->num_contexts))) { + return False; + } + } + + for (i = 0; i < rpc->num_contexts; i++ ) { + if (!smb_io_rpc_context("", &rpc->rpc_context[i], ps, depth)) + return False; + } + + return True; +} + +/******************************************************************* + Inits an RPC_RESULTS structure. + + lkclXXXX only one reason at the moment! +********************************************************************/ + +static void init_rpc_results(RPC_RESULTS *res, + uint8 num_results, uint16 result, uint16 reason) +{ + res->num_results = num_results; /* the number of results (0x01) */ + res->result = result ; /* result (0x00 = accept) */ + res->reason = reason ; /* reason (0x00 = no reason specified) */ +} + +/******************************************************************* + Reads or writes an RPC_RESULTS structure. + + lkclXXXX only one reason at the moment! +********************************************************************/ + +static bool smb_io_rpc_results(const char *desc, RPC_RESULTS *res, prs_struct *ps, int depth) +{ + if (res == NULL) + return False; + + prs_debug(ps, depth, desc, "smb_io_rpc_results"); + depth++; + + if(!prs_align(ps)) + return False; + + if(!prs_uint8 ("num_results", ps, depth, &res->num_results)) + return False; + + if(!prs_align(ps)) + return False; + + if(!prs_uint16("result ", ps, depth, &res->result)) + return False; + if(!prs_uint16("reason ", ps, depth, &res->reason)) + return False; + return True; +} + +/******************************************************************* + Init an RPC_HDR_BA structure. + + lkclXXXX only one reason at the moment! + +********************************************************************/ + +void init_rpc_hdr_ba(RPC_HDR_BA *rpc, + uint16 max_tsize, uint16 max_rsize, uint32 assoc_gid, + const char *pipe_addr, + uint8 num_results, uint16 result, uint16 reason, + RPC_IFACE *transfer) +{ + init_rpc_hdr_bba (&rpc->bba, max_tsize, max_rsize, assoc_gid); + init_rpc_addr_str(&rpc->addr, pipe_addr); + init_rpc_results (&rpc->res, num_results, result, reason); + + /* the transfer syntax from the request */ + memcpy(&rpc->transfer, transfer, sizeof(rpc->transfer)); +} + +/******************************************************************* + Reads or writes an RPC_HDR_BA structure. +********************************************************************/ + +bool smb_io_rpc_hdr_ba(const char *desc, RPC_HDR_BA *rpc, prs_struct *ps, int depth) +{ + if (rpc == NULL) + return False; + + prs_debug(ps, depth, desc, "smb_io_rpc_hdr_ba"); + depth++; + + if(!smb_io_rpc_hdr_bba("", &rpc->bba, ps, depth)) + return False; + if(!smb_io_rpc_addr_str("", &rpc->addr, ps, depth)) + return False; + if(!smb_io_rpc_results("", &rpc->res, ps, depth)) + return False; + if(!smb_io_rpc_iface("", &rpc->transfer, ps, depth)) + return False; + return True; +} + +/******************************************************************* + Init an RPC_HDR_REQ structure. +********************************************************************/ + +void init_rpc_hdr_req(RPC_HDR_REQ *hdr, uint32 alloc_hint, uint16 opnum) +{ + hdr->alloc_hint = alloc_hint; /* allocation hint */ + hdr->context_id = 0; /* presentation context identifier */ + hdr->opnum = opnum; /* opnum */ +} + +/******************************************************************* + Reads or writes an RPC_HDR_REQ structure. +********************************************************************/ + +bool smb_io_rpc_hdr_req(const char *desc, RPC_HDR_REQ *rpc, prs_struct *ps, int depth) +{ + if (rpc == NULL) + return False; + + prs_debug(ps, depth, desc, "smb_io_rpc_hdr_req"); + depth++; + + if(!prs_uint32("alloc_hint", ps, depth, &rpc->alloc_hint)) + return False; + if(!prs_uint16("context_id", ps, depth, &rpc->context_id)) + return False; + if(!prs_uint16("opnum ", ps, depth, &rpc->opnum)) + return False; + return True; +} + +/******************************************************************* + Reads or writes an RPC_HDR_RESP structure. +********************************************************************/ + +bool smb_io_rpc_hdr_resp(const char *desc, RPC_HDR_RESP *rpc, prs_struct *ps, int depth) +{ + if (rpc == NULL) + return False; + + prs_debug(ps, depth, desc, "smb_io_rpc_hdr_resp"); + depth++; + + if(!prs_uint32("alloc_hint", ps, depth, &rpc->alloc_hint)) + return False; + if(!prs_uint16("context_id", ps, depth, &rpc->context_id)) + return False; + if(!prs_uint8 ("cancel_ct ", ps, depth, &rpc->cancel_count)) + return False; + if(!prs_uint8 ("reserved ", ps, depth, &rpc->reserved)) + return False; + return True; +} + +/******************************************************************* + Reads or writes an RPC_HDR_FAULT structure. +********************************************************************/ + +bool smb_io_rpc_hdr_fault(const char *desc, RPC_HDR_FAULT *rpc, prs_struct *ps, int depth) +{ + if (rpc == NULL) + return False; + + prs_debug(ps, depth, desc, "smb_io_rpc_hdr_fault"); + depth++; + + if(!prs_dcerpc_status("status ", ps, depth, &rpc->status)) + return False; + if(!prs_uint32("reserved", ps, depth, &rpc->reserved)) + return False; + + return True; +} + +/******************************************************************* + Inits an RPC_HDR_AUTH structure. +********************************************************************/ + +void init_rpc_hdr_auth(RPC_HDR_AUTH *rai, + uint8 auth_type, uint8 auth_level, + uint8 auth_pad_len, + uint32 auth_context_id) +{ + rai->auth_type = auth_type; + rai->auth_level = auth_level; + rai->auth_pad_len = auth_pad_len; + rai->auth_reserved = 0; + rai->auth_context_id = auth_context_id; +} + +/******************************************************************* + Reads or writes an RPC_HDR_AUTH structure. +********************************************************************/ + +bool smb_io_rpc_hdr_auth(const char *desc, RPC_HDR_AUTH *rai, prs_struct *ps, int depth) +{ + if (rai == NULL) + return False; + + prs_debug(ps, depth, desc, "smb_io_rpc_hdr_auth"); + depth++; + + if(!prs_align(ps)) + return False; + + if(!prs_uint8 ("auth_type ", ps, depth, &rai->auth_type)) + return False; + if(!prs_uint8 ("auth_level ", ps, depth, &rai->auth_level)) + return False; + if(!prs_uint8 ("auth_pad_len ", ps, depth, &rai->auth_pad_len)) + return False; + if(!prs_uint8 ("auth_reserved", ps, depth, &rai->auth_reserved)) + return False; + if(!prs_uint32("auth_context_id", ps, depth, &rai->auth_context_id)) + return False; + + return True; +} + +/******************************************************************* + Checks an RPC_AUTH_VERIFIER structure. +********************************************************************/ + +bool rpc_auth_verifier_chk(RPC_AUTH_VERIFIER *rav, + const char *signature, uint32 msg_type) +{ + return (strequal(rav->signature, signature) && rav->msg_type == msg_type); +} + +/******************************************************************* + Inits an RPC_AUTH_VERIFIER structure. +********************************************************************/ + +void init_rpc_auth_verifier(RPC_AUTH_VERIFIER *rav, + const char *signature, uint32 msg_type) +{ + fstrcpy(rav->signature, signature); /* "NTLMSSP" */ + rav->msg_type = msg_type; /* NTLMSSP_MESSAGE_TYPE */ +} + +/******************************************************************* + Reads or writes an RPC_AUTH_VERIFIER structure. +********************************************************************/ + +bool smb_io_rpc_auth_verifier(const char *desc, RPC_AUTH_VERIFIER *rav, prs_struct *ps, int depth) +{ + if (rav == NULL) + return False; + + prs_debug(ps, depth, desc, "smb_io_rpc_auth_verifier"); + depth++; + + /* "NTLMSSP" */ + if(!prs_string("signature", ps, depth, rav->signature, + sizeof(rav->signature))) + return False; + if(!prs_uint32("msg_type ", ps, depth, &rav->msg_type)) /* NTLMSSP_MESSAGE_TYPE */ + return False; + + return True; +} + +/******************************************************************* + This parses an RPC_AUTH_VERIFIER for schannel. I think +********************************************************************/ + +bool smb_io_rpc_schannel_verifier(const char *desc, RPC_AUTH_VERIFIER *rav, prs_struct *ps, int depth) +{ + if (rav == NULL) + return False; + + prs_debug(ps, depth, desc, "smb_io_rpc_schannel_verifier"); + depth++; + + if(!prs_string("signature", ps, depth, rav->signature, sizeof(rav->signature))) + return False; + if(!prs_uint32("msg_type ", ps, depth, &rav->msg_type)) + return False; + + return True; +} + +/******************************************************************* +creates an RPC_AUTH_SCHANNEL_NEG structure. +********************************************************************/ + +void init_rpc_auth_schannel_neg(RPC_AUTH_SCHANNEL_NEG *neg, + const char *domain, const char *myname) +{ + neg->type1 = 0; + neg->type2 = 0x3; + fstrcpy(neg->domain, domain); + fstrcpy(neg->myname, myname); +} + +/******************************************************************* + Reads or writes an RPC_AUTH_SCHANNEL_NEG structure. +********************************************************************/ + +bool smb_io_rpc_auth_schannel_neg(const char *desc, RPC_AUTH_SCHANNEL_NEG *neg, + prs_struct *ps, int depth) +{ + if (neg == NULL) + return False; + + prs_debug(ps, depth, desc, "smb_io_rpc_auth_schannel_neg"); + depth++; + + if(!prs_align(ps)) + return False; + + if(!prs_uint32("type1", ps, depth, &neg->type1)) + return False; + if(!prs_uint32("type2", ps, depth, &neg->type2)) + return False; + if(!prs_string("domain ", ps, depth, neg->domain, sizeof(neg->domain))) + return False; + if(!prs_string("myname ", ps, depth, neg->myname, sizeof(neg->myname))) + return False; + + return True; +} + +/******************************************************************* +reads or writes an RPC_AUTH_SCHANNEL_CHK structure. +********************************************************************/ + +bool smb_io_rpc_auth_schannel_chk(const char *desc, int auth_len, + RPC_AUTH_SCHANNEL_CHK * chk, + prs_struct *ps, int depth) +{ + if (chk == NULL) + return False; + + prs_debug(ps, depth, desc, "smb_io_rpc_auth_schannel_chk"); + depth++; + + if ( !prs_uint8s(False, "sig ", ps, depth, chk->sig, sizeof(chk->sig)) ) + return False; + + if ( !prs_uint8s(False, "seq_num", ps, depth, chk->seq_num, sizeof(chk->seq_num)) ) + return False; + + if ( !prs_uint8s(False, "packet_digest", ps, depth, chk->packet_digest, sizeof(chk->packet_digest)) ) + return False; + + if ( auth_len == RPC_AUTH_SCHANNEL_SIGN_OR_SEAL_CHK_LEN ) { + if ( !prs_uint8s(False, "confounder", ps, depth, chk->confounder, sizeof(chk->confounder)) ) + return False; + } + + return True; +} + +const struct ndr_syntax_id syntax_spoolss = { + { + 0x12345678, 0x1234, 0xabcd, + { 0xef, 0x00 }, + { 0x01, 0x23, + 0x45, 0x67, 0x89, 0xab } + }, 0x01 +}; + diff --git a/source3/rpc_parse/parse_sec.c b/source3/rpc_parse/parse_sec.c new file mode 100644 index 0000000000..c71b31086a --- /dev/null +++ b/source3/rpc_parse/parse_sec.c @@ -0,0 +1,436 @@ +/* + * Unix SMB/Netbios implementation. + * Version 1.9. + * RPC Pipe client / server routines + * Copyright (C) Andrew Tridgell 1992-1998, + * Copyright (C) Jeremy R. Allison 1995-2005. + * Copyright (C) Luke Kenneth Casson Leighton 1996-1998, + * Copyright (C) Paul Ashton 1997-1998. + * + * 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 + * the Free Software Foundation; either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, see <http://www.gnu.org/licenses/>. + */ + +#include "includes.h" + +#undef DBGC_CLASS +#define DBGC_CLASS DBGC_RPC_PARSE + +/******************************************************************* + Reads or writes a SEC_ACE structure. +********************************************************************/ + +static bool sec_io_ace(const char *desc, SEC_ACE *psa, prs_struct *ps, + int depth) +{ + uint32 old_offset; + uint32 offset_ace_size; + uint8 type; + + if (psa == NULL) + return False; + + prs_debug(ps, depth, desc, "sec_io_ace"); + depth++; + + old_offset = prs_offset(ps); + + if (MARSHALLING(ps)) { + type = (uint8)psa->type; + } + + if(!prs_uint8("type ", ps, depth, &type)) + return False; + + if (UNMARSHALLING(ps)) { + psa->type = (enum security_ace_type)type; + } + + if(!prs_uint8("flags", ps, depth, &psa->flags)) + return False; + + if(!prs_uint16_pre("size ", ps, depth, &psa->size, &offset_ace_size)) + return False; + + if(!prs_uint32("access_mask", ps, depth, &psa->access_mask)) + return False; + + /* check whether object access is present */ + if (!sec_ace_object(psa->type)) { + if (!smb_io_dom_sid("trustee ", &psa->trustee , ps, depth)) + return False; + } else { + if (!prs_uint32("obj_flags", ps, depth, &psa->object.object.flags)) + return False; + + if (psa->object.object.flags & SEC_ACE_OBJECT_PRESENT) + if (!smb_io_uuid("obj_guid", &psa->object.object.type.type, ps,depth)) + return False; + + if (psa->object.object.flags & SEC_ACE_OBJECT_INHERITED_PRESENT) + if (!smb_io_uuid("inh_guid", &psa->object.object.inherited_type.inherited_type, ps,depth)) + return False; + + if(!smb_io_dom_sid("trustee ", &psa->trustee , ps, depth)) + return False; + } + + /* Theorectically an ACE can have a size greater than the + sum of its components. When marshalling, pad with extra null bytes up to the + correct size. */ + + if (MARSHALLING(ps) && (psa->size > prs_offset(ps) - old_offset)) { + uint32 extra_len = psa->size - (prs_offset(ps) - old_offset); + uint32 i; + uint8 c = 0; + + for (i = 0; i < extra_len; i++) { + if (!prs_uint8("ace extra space", ps, depth, &c)) + return False; + } + } + + if(!prs_uint16_post("size ", ps, depth, &psa->size, offset_ace_size, old_offset)) + return False; + + return True; +} + +/******************************************************************* + Reads or writes a SEC_ACL structure. + + First of the xx_io_xx functions that allocates its data structures + for you as it reads them. +********************************************************************/ + +static bool sec_io_acl(const char *desc, SEC_ACL **ppsa, prs_struct *ps, + int depth) +{ + unsigned int i; + uint32 old_offset; + uint32 offset_acl_size; + SEC_ACL *psa; + uint16 revision; + + /* + * Note that the size is always a multiple of 4 bytes due to the + * nature of the data structure. Therefore the prs_align() calls + * have been removed as they through us off when doing two-layer + * marshalling such as in the printing code (RPC_BUFFER). --jerry + */ + + if (ppsa == NULL) + return False; + + psa = *ppsa; + + if(UNMARSHALLING(ps) && psa == NULL) { + /* + * This is a read and we must allocate the stuct to read into. + */ + if((psa = PRS_ALLOC_MEM(ps, SEC_ACL, 1)) == NULL) + return False; + *ppsa = psa; + } + + prs_debug(ps, depth, desc, "sec_io_acl"); + depth++; + + old_offset = prs_offset(ps); + + if (MARSHALLING(ps)) { + revision = (uint16)psa->revision; + } + + if(!prs_uint16("revision", ps, depth, &revision)) + return False; + + if (UNMARSHALLING(ps)) { + psa->revision = (enum security_acl_revision)revision; + } + + if(!prs_uint16_pre("size ", ps, depth, &psa->size, &offset_acl_size)) + return False; + + if(!prs_uint32("num_aces ", ps, depth, &psa->num_aces)) + return False; + + if (UNMARSHALLING(ps)) { + if (psa->num_aces) { + if((psa->aces = PRS_ALLOC_MEM(ps, SEC_ACE, psa->num_aces)) == NULL) + return False; + } else { + psa->aces = NULL; + } + } + + for (i = 0; i < psa->num_aces; i++) { + fstring tmp; + slprintf(tmp, sizeof(tmp)-1, "ace_list[%02d]: ", i); + if(!sec_io_ace(tmp, &psa->aces[i], ps, depth)) + return False; + } + + /* Theorectically an ACL can have a size greater than the + sum of its components. When marshalling, pad with extra null bytes up to the + correct size. */ + + if (MARSHALLING(ps) && (psa->size > prs_offset(ps) - old_offset)) { + uint32 extra_len = psa->size - (prs_offset(ps) - old_offset); + uint8 c = 0; + + for (i = 0; i < extra_len; i++) { + if (!prs_uint8("acl extra space", ps, depth, &c)) + return False; + } + } + + if(!prs_uint16_post("size ", ps, depth, &psa->size, offset_acl_size, old_offset)) + return False; + + return True; +} + +/******************************************************************* + Reads or writes a SEC_DESC structure. + If reading and the *ppsd = NULL, allocates the structure. +********************************************************************/ + +bool sec_io_desc(const char *desc, SEC_DESC **ppsd, prs_struct *ps, int depth) +{ + uint32 old_offset; + uint32 max_offset = 0; /* after we're done, move offset to end */ + uint32 tmp_offset = 0; + uint32 off_sacl, off_dacl, off_owner_sid, off_grp_sid; + uint16 revision; + + SEC_DESC *psd; + + if (ppsd == NULL) + return False; + + psd = *ppsd; + + if (psd == NULL) { + if(UNMARSHALLING(ps)) { + if((psd = PRS_ALLOC_MEM(ps,SEC_DESC,1)) == NULL) + return False; + *ppsd = psd; + } else { + /* Marshalling - just ignore. */ + return True; + } + } + + prs_debug(ps, depth, desc, "sec_io_desc"); + depth++; + + /* start of security descriptor stored for back-calc offset purposes */ + old_offset = prs_offset(ps); + + if (MARSHALLING(ps)) { + revision = (uint16)psd->revision; + } + + if(!prs_uint16("revision", ps, depth, &revision)) + return False; + + if (UNMARSHALLING(ps)) { + psd->revision = (enum security_descriptor_revision)revision; + } + + if(!prs_uint16("type ", ps, depth, &psd->type)) + return False; + + if (MARSHALLING(ps)) { + uint32 offset = SEC_DESC_HEADER_SIZE; + + /* + * Work out the offsets here, as we write it out. + */ + + if (psd->sacl != NULL) { + off_sacl = offset; + offset += psd->sacl->size; + } else { + off_sacl = 0; + } + + if (psd->dacl != NULL) { + off_dacl = offset; + offset += psd->dacl->size; + } else { + off_dacl = 0; + } + + if (psd->owner_sid != NULL) { + off_owner_sid = offset; + offset += ndr_size_dom_sid(psd->owner_sid, 0); + } else { + off_owner_sid = 0; + } + + if (psd->group_sid != NULL) { + off_grp_sid = offset; + offset += ndr_size_dom_sid(psd->group_sid, 0); + } else { + off_grp_sid = 0; + } + } + + if(!prs_uint32("off_owner_sid", ps, depth, &off_owner_sid)) + return False; + + if(!prs_uint32("off_grp_sid ", ps, depth, &off_grp_sid)) + return False; + + if(!prs_uint32("off_sacl ", ps, depth, &off_sacl)) + return False; + + if(!prs_uint32("off_dacl ", ps, depth, &off_dacl)) + return False; + + max_offset = MAX(max_offset, prs_offset(ps)); + + if (off_owner_sid != 0) { + + tmp_offset = prs_offset(ps); + if(!prs_set_offset(ps, old_offset + off_owner_sid)) + return False; + + if (UNMARSHALLING(ps)) { + /* reading */ + if((psd->owner_sid = PRS_ALLOC_MEM(ps,DOM_SID,1)) == NULL) + return False; + } + + if(!smb_io_dom_sid("owner_sid ", psd->owner_sid , ps, depth)) + return False; + + max_offset = MAX(max_offset, prs_offset(ps)); + + if (!prs_set_offset(ps,tmp_offset)) + return False; + } + + if (psd->group_sid != 0) { + + tmp_offset = prs_offset(ps); + if(!prs_set_offset(ps, old_offset + off_grp_sid)) + return False; + + if (UNMARSHALLING(ps)) { + /* reading */ + if((psd->group_sid = PRS_ALLOC_MEM(ps,DOM_SID,1)) == NULL) + return False; + } + + if(!smb_io_dom_sid("grp_sid", psd->group_sid, ps, depth)) + return False; + + max_offset = MAX(max_offset, prs_offset(ps)); + + if (!prs_set_offset(ps,tmp_offset)) + return False; + } + + if ((psd->type & SEC_DESC_SACL_PRESENT) && off_sacl) { + tmp_offset = prs_offset(ps); + if(!prs_set_offset(ps, old_offset + off_sacl)) + return False; + if(!sec_io_acl("sacl", &psd->sacl, ps, depth)) + return False; + max_offset = MAX(max_offset, prs_offset(ps)); + if (!prs_set_offset(ps,tmp_offset)) + return False; + } + + if ((psd->type & SEC_DESC_DACL_PRESENT) && off_dacl != 0) { + tmp_offset = prs_offset(ps); + if(!prs_set_offset(ps, old_offset + off_dacl)) + return False; + if(!sec_io_acl("dacl", &psd->dacl, ps, depth)) + return False; + max_offset = MAX(max_offset, prs_offset(ps)); + if (!prs_set_offset(ps,tmp_offset)) + return False; + } + + if(!prs_set_offset(ps, max_offset)) + return False; + + return True; +} + +/******************************************************************* + Reads or writes a SEC_DESC_BUF structure. +********************************************************************/ + +bool sec_io_desc_buf(const char *desc, SEC_DESC_BUF **ppsdb, prs_struct *ps, int depth) +{ + uint32 off_len; + uint32 off_max_len; + uint32 old_offset; + uint32 size; + uint32 len; + SEC_DESC_BUF *psdb; + uint32 ptr; + + if (ppsdb == NULL) + return False; + + psdb = *ppsdb; + + if (UNMARSHALLING(ps) && psdb == NULL) { + if((psdb = PRS_ALLOC_MEM(ps,SEC_DESC_BUF,1)) == NULL) + return False; + *ppsdb = psdb; + } + + prs_debug(ps, depth, desc, "sec_io_desc_buf"); + depth++; + + if(!prs_align(ps)) + return False; + + if(!prs_uint32_pre("max_len", ps, depth, &psdb->sd_size, &off_max_len)) + return False; + + ptr = 1; + if(!prs_uint32 ("ptr ", ps, depth, &ptr)) + return False; + + len = ndr_size_security_descriptor(psdb->sd, 0); + if(!prs_uint32_pre("len ", ps, depth, &len, &off_len)) + return False; + + old_offset = prs_offset(ps); + + /* reading, length is non-zero; writing, descriptor is non-NULL */ + if ((UNMARSHALLING(ps) && psdb->sd_size != 0) || (MARSHALLING(ps) && psdb->sd != NULL)) { + if(!sec_io_desc("sec ", &psdb->sd, ps, depth)) + return False; + } + + if(!prs_align(ps)) + return False; + + size = prs_offset(ps) - old_offset; + if(!prs_uint32_post("max_len", ps, depth, &psdb->sd_size, off_max_len, size == 0 ? psdb->sd_size : size)) + return False; + + if(!prs_uint32_post("len ", ps, depth, &len, off_len, size)) + return False; + + return True; +} diff --git a/source3/rpc_parse/parse_spoolss.c b/source3/rpc_parse/parse_spoolss.c new file mode 100644 index 0000000000..78a80a019b --- /dev/null +++ b/source3/rpc_parse/parse_spoolss.c @@ -0,0 +1,7726 @@ +/* + * Unix SMB/CIFS implementation. + * RPC Pipe client / server routines + * 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-2002, + * Copyright (C) Tim Potter 2001-2002. + * + * 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 + * the Free Software Foundation; either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, see <http://www.gnu.org/licenses/>. + */ + +#include "includes.h" + +#undef DBGC_CLASS +#define DBGC_CLASS DBGC_RPC_PARSE + + +/******************************************************************* +This should be moved in a more generic lib. +********************************************************************/ + +bool spoolss_io_system_time(const char *desc, prs_struct *ps, int depth, SYSTEMTIME *systime) +{ + if(!prs_uint16("year", ps, depth, &systime->year)) + return False; + if(!prs_uint16("month", ps, depth, &systime->month)) + return False; + if(!prs_uint16("dayofweek", ps, depth, &systime->dayofweek)) + return False; + if(!prs_uint16("day", ps, depth, &systime->day)) + return False; + if(!prs_uint16("hour", ps, depth, &systime->hour)) + return False; + if(!prs_uint16("minute", ps, depth, &systime->minute)) + return False; + if(!prs_uint16("second", ps, depth, &systime->second)) + return False; + if(!prs_uint16("milliseconds", ps, depth, &systime->milliseconds)) + return False; + + return True; +} + +/******************************************************************* +********************************************************************/ + +bool make_systemtime(SYSTEMTIME *systime, struct tm *unixtime) +{ + systime->year=unixtime->tm_year+1900; + systime->month=unixtime->tm_mon+1; + systime->dayofweek=unixtime->tm_wday; + systime->day=unixtime->tm_mday; + systime->hour=unixtime->tm_hour; + systime->minute=unixtime->tm_min; + systime->second=unixtime->tm_sec; + systime->milliseconds=0; + + return True; +} + +/******************************************************************* +reads or writes an DOC_INFO structure. +********************************************************************/ + +static bool smb_io_doc_info_1(const char *desc, DOC_INFO_1 *info_1, prs_struct *ps, int depth) +{ + if (info_1 == NULL) return False; + + prs_debug(ps, depth, desc, "smb_io_doc_info_1"); + depth++; + + if(!prs_align(ps)) + return False; + + if(!prs_uint32("p_docname", ps, depth, &info_1->p_docname)) + return False; + if(!prs_uint32("p_outputfile", ps, depth, &info_1->p_outputfile)) + return False; + 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)) + return False; + 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)) + return False; + + return True; +} + +/******************************************************************* +reads or writes an DOC_INFO structure. +********************************************************************/ + +static bool smb_io_doc_info(const char *desc, DOC_INFO *info, prs_struct *ps, int depth) +{ + uint32 useless_ptr=0; + + if (info == NULL) return False; + + prs_debug(ps, depth, desc, "smb_io_doc_info"); + depth++; + + if(!prs_align(ps)) + return False; + + if(!prs_uint32("switch_value", ps, depth, &info->switch_value)) + return False; + + 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)) + return False; + break; + case 2: + /* + this is just a placeholder + + MSDN July 1998 says doc_info_2 is only on + Windows 95, and as Win95 doesn't do RPC to print + this case is nearly impossible + + Maybe one day with Windows for dishwasher 2037 ... + + */ + /* smb_io_doc_info_2("",&info->doc_info_2, ps, depth); */ + break; + default: + DEBUG(0,("Something is obviously wrong somewhere !\n")); + break; + } + + return True; +} + +/******************************************************************* +reads or writes an DOC_INFO_CONTAINER structure. +********************************************************************/ + +static bool smb_io_doc_info_container(const char *desc, DOC_INFO_CONTAINER *cont, prs_struct *ps, int depth) +{ + if (cont == NULL) return False; + + prs_debug(ps, depth, desc, "smb_io_doc_info_container"); + depth++; + + if(!prs_align(ps)) + return False; + + if(!prs_uint32("level", ps, depth, &cont->level)) + return False; + + if(!smb_io_doc_info("",&cont->docinfo, ps, depth)) + return False; + + return True; +} + +/******************************************************************* +reads or writes an NOTIFY OPTION TYPE structure. +********************************************************************/ + +/* NOTIFY_OPTION_TYPE and NOTIFY_OPTION_TYPE_DATA are really one + structure. The _TYPE structure is really the deferred referrants (i.e + the notify fields array) of the _TYPE structure. -tpot */ + +static bool smb_io_notify_option_type(const char *desc, SPOOL_NOTIFY_OPTION_TYPE *type, prs_struct *ps, int depth) +{ + prs_debug(ps, depth, desc, "smb_io_notify_option_type"); + depth++; + + if (!prs_align(ps)) + return False; + + if(!prs_uint16("type", ps, depth, &type->type)) + return False; + if(!prs_uint16("reserved0", ps, depth, &type->reserved0)) + return False; + if(!prs_uint32("reserved1", ps, depth, &type->reserved1)) + return False; + if(!prs_uint32("reserved2", ps, depth, &type->reserved2)) + return False; + if(!prs_uint32("count", ps, depth, &type->count)) + return False; + if(!prs_uint32("fields_ptr", ps, depth, &type->fields_ptr)) + return False; + + return True; +} + +/******************************************************************* +reads or writes an NOTIFY OPTION TYPE DATA. +********************************************************************/ + +static bool smb_io_notify_option_type_data(const char *desc, SPOOL_NOTIFY_OPTION_TYPE *type, prs_struct *ps, int depth) +{ + int i; + + prs_debug(ps, depth, desc, "smb_io_notify_option_type_data"); + depth++; + + /* if there are no fields just return */ + if (type->fields_ptr==0) + return True; + + if(!prs_align(ps)) + return False; + + if(!prs_uint32("count2", ps, depth, &type->count2)) + return False; + + if (type->count2 != type->count) + DEBUG(4,("What a mess, count was %x now is %x !\n", type->count, type->count2)); + + if (type->count2 > MAX_NOTIFY_TYPE_FOR_NOW) { + return False; + } + + /* parse the option type data */ + for(i=0;i<type->count2;i++) + if(!prs_uint16("fields",ps,depth,&type->fields[i])) + return False; + return True; +} + +/******************************************************************* +reads or writes an NOTIFY OPTION structure. +********************************************************************/ + +static bool smb_io_notify_option_type_ctr(const char *desc, SPOOL_NOTIFY_OPTION_TYPE_CTR *ctr , prs_struct *ps, int depth) +{ + int i; + + prs_debug(ps, depth, desc, "smb_io_notify_option_type_ctr"); + depth++; + + if(!prs_uint32("count", ps, depth, &ctr->count)) + return False; + + /* reading */ + if (UNMARSHALLING(ps) && ctr->count) + if((ctr->type=PRS_ALLOC_MEM(ps,SPOOL_NOTIFY_OPTION_TYPE,ctr->count)) == NULL) + return False; + + /* the option type struct */ + for(i=0;i<ctr->count;i++) + if(!smb_io_notify_option_type("", &ctr->type[i] , ps, depth)) + return False; + + /* the type associated with the option type struct */ + for(i=0;i<ctr->count;i++) + if(!smb_io_notify_option_type_data("", &ctr->type[i] , ps, depth)) + return False; + + return True; +} + +/******************************************************************* +reads or writes an NOTIFY OPTION structure. +********************************************************************/ + +static bool smb_io_notify_option(const char *desc, SPOOL_NOTIFY_OPTION *option, prs_struct *ps, int depth) +{ + prs_debug(ps, depth, desc, "smb_io_notify_option"); + depth++; + + if(!prs_uint32("version", ps, depth, &option->version)) + return False; + if(!prs_uint32("flags", ps, depth, &option->flags)) + return False; + if(!prs_uint32("count", ps, depth, &option->count)) + return False; + if(!prs_uint32("option_type_ptr", ps, depth, &option->option_type_ptr)) + return False; + + /* marshalling or unmarshalling, that would work */ + if (option->option_type_ptr!=0) { + if(!smb_io_notify_option_type_ctr("", &option->ctr ,ps, depth)) + return False; + } + else { + option->ctr.type=NULL; + option->ctr.count=0; + } + + return True; +} + +/******************************************************************* +reads or writes an NOTIFY INFO DATA structure. +********************************************************************/ + +static bool smb_io_notify_info_data(const char *desc,SPOOL_NOTIFY_INFO_DATA *data, prs_struct *ps, int depth) +{ + uint32 useless_ptr=0x0FF0ADDE; + + prs_debug(ps, depth, desc, "smb_io_notify_info_data"); + depth++; + + if(!prs_align(ps)) + return False; + if(!prs_uint16("type", ps, depth, &data->type)) + return False; + if(!prs_uint16("field", ps, depth, &data->field)) + return False; + + if(!prs_uint32("how many words", ps, depth, &data->size)) + return False; + if(!prs_uint32("id", ps, depth, &data->id)) + return False; + if(!prs_uint32("how many words", ps, depth, &data->size)) + return False; + + switch (data->enc_type) { + + /* One and two value data has two uint32 values */ + + case NOTIFY_ONE_VALUE: + case NOTIFY_TWO_VALUE: + + if(!prs_uint32("value[0]", ps, depth, &data->notify_data.value[0])) + return False; + if(!prs_uint32("value[1]", ps, depth, &data->notify_data.value[1])) + return False; + break; + + /* Pointers and strings have a string length and a + pointer. For a string the length is expressed as + the number of uint16 characters plus a trailing + \0\0. */ + + case NOTIFY_POINTER: + + if(!prs_uint32("string length", ps, depth, &data->notify_data.data.length )) + return False; + if(!prs_uint32("pointer", ps, depth, &useless_ptr)) + return False; + + break; + + case NOTIFY_STRING: + + if(!prs_uint32("string length", ps, depth, &data->notify_data.data.length)) + return False; + + if(!prs_uint32("pointer", ps, depth, &useless_ptr)) + return False; + + break; + + case NOTIFY_SECDESC: + if( !prs_uint32( "sd size", ps, depth, &data->notify_data.sd.size ) ) + return False; + if( !prs_uint32( "pointer", ps, depth, &useless_ptr ) ) + return False; + + break; + + default: + DEBUG(3, ("invalid enc_type %d for smb_io_notify_info_data\n", + data->enc_type)); + break; + } + + return True; +} + +/******************************************************************* +reads or writes an NOTIFY INFO DATA structure. +********************************************************************/ + +bool smb_io_notify_info_data_strings(const char *desc,SPOOL_NOTIFY_INFO_DATA *data, + prs_struct *ps, int depth) +{ + prs_debug(ps, depth, desc, "smb_io_notify_info_data_strings"); + depth++; + + if(!prs_align(ps)) + return False; + + switch(data->enc_type) { + + /* No data for values */ + + case NOTIFY_ONE_VALUE: + case NOTIFY_TWO_VALUE: + + break; + + /* Strings start with a length in uint16s */ + + case NOTIFY_STRING: + + if (MARSHALLING(ps)) + data->notify_data.data.length /= 2; + + if(!prs_uint32("string length", ps, depth, &data->notify_data.data.length)) + return False; + + if (UNMARSHALLING(ps) && data->notify_data.data.length) { + data->notify_data.data.string = PRS_ALLOC_MEM(ps, uint16, + data->notify_data.data.length); + + if (!data->notify_data.data.string) + return False; + } + + if (!prs_uint16uni(True, "string", ps, depth, data->notify_data.data.string, + data->notify_data.data.length)) + return False; + + if (MARSHALLING(ps)) + data->notify_data.data.length *= 2; + + break; + + case NOTIFY_POINTER: + + if (UNMARSHALLING(ps) && data->notify_data.data.length) { + data->notify_data.data.string = PRS_ALLOC_MEM(ps, uint16, + data->notify_data.data.length); + + if (!data->notify_data.data.string) + return False; + } + + if(!prs_uint8s(True,"buffer",ps,depth,(uint8*)data->notify_data.data.string,data->notify_data.data.length)) + return False; + + break; + + case NOTIFY_SECDESC: + if( !prs_uint32("secdesc size ", ps, depth, &data->notify_data.sd.size ) ) + return False; + if ( !sec_io_desc( "sec_desc", &data->notify_data.sd.desc, ps, depth ) ) + return False; + break; + + default: + DEBUG(3, ("invalid enc_type %d for smb_io_notify_info_data_strings\n", + data->enc_type)); + break; + } + +#if 0 + if (isvalue==False) { + + /* length of string in unicode include \0 */ + x=data->notify_data.data.length+1; + + if (data->field != 16) + if(!prs_uint32("string length", ps, depth, &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 (data->field == 16) + x /= 2; + + if(!prs_uint16uni(True,"string",ps,depth,data->notify_data.data.string,x)) + return False; + } + } else { + + /* Tallocate memory for string */ + + if (x) { + data->notify_data.data.string = PRS_ALLOC_MEM(ps, uint16, x * 2); + if (!data->notify_data.data.string) + return False; + } else { + data->notify_data.data.string = NULL; + } + + if(!prs_uint16uni(True,"string",ps,depth,data->notify_data.data.string,x)) + return False; + } + } + +#endif + +#if 0 /* JERRY */ + /* Win2k does not seem to put this parse align here */ + if(!prs_align(ps)) + return False; +#endif + + return True; +} + +/******************************************************************* +reads or writes an NOTIFY INFO structure. +********************************************************************/ + +static bool smb_io_notify_info(const char *desc, SPOOL_NOTIFY_INFO *info, prs_struct *ps, int depth) +{ + int i; + + prs_debug(ps, depth, desc, "smb_io_notify_info"); + depth++; + + if(!prs_align(ps)) + return False; + + if(!prs_uint32("count", ps, depth, &info->count)) + return False; + if(!prs_uint32("version", ps, depth, &info->version)) + return False; + if(!prs_uint32("flags", ps, depth, &info->flags)) + return False; + if(!prs_uint32("count", ps, depth, &info->count)) + return False; + + for (i=0;i<info->count;i++) { + if(!smb_io_notify_info_data(desc, &info->data[i], ps, depth)) + return False; + } + + /* now do the strings at the end of the stream */ + for (i=0;i<info->count;i++) { + if(!smb_io_notify_info_data_strings(desc, &info->data[i], ps, depth)) + return False; + } + + return True; +} + +/******************************************************************* +********************************************************************/ + +bool spool_io_user_level_1( const char *desc, prs_struct *ps, int depth, SPOOL_USER_1 *q_u ) +{ + prs_debug(ps, depth, desc, ""); + depth++; + + if (!prs_align(ps)) + return False; + + if (!prs_uint32("size", ps, depth, &q_u->size)) + return False; + + if (!prs_io_unistr2_p("", ps, depth, &q_u->client_name)) + return False; + if (!prs_io_unistr2_p("", ps, depth, &q_u->user_name)) + return False; + + if (!prs_uint32("build", ps, depth, &q_u->build)) + return False; + if (!prs_uint32("major", ps, depth, &q_u->major)) + return False; + if (!prs_uint32("minor", ps, depth, &q_u->minor)) + return False; + if (!prs_uint32("processor", ps, depth, &q_u->processor)) + return False; + + if (!prs_io_unistr2("", ps, depth, q_u->client_name)) + return False; + if (!prs_align(ps)) + return False; + + if (!prs_io_unistr2("", ps, depth, q_u->user_name)) + return False; + + return True; +} + +/******************************************************************* +********************************************************************/ + +static bool spool_io_user_level(const char *desc, SPOOL_USER_CTR *q_u, prs_struct *ps, int depth) +{ + if (q_u==NULL) + return False; + + prs_debug(ps, depth, desc, "spool_io_user_level"); + depth++; + + if (!prs_align(ps)) + return False; + + if (!prs_uint32("level", ps, depth, &q_u->level)) + return False; + + switch ( q_u->level ) + { + case 1: + if ( !prs_pointer( "" , ps, depth, (void*)&q_u->user.user1, + sizeof(SPOOL_USER_1), (PRS_POINTER_CAST)spool_io_user_level_1 )) + { + return False; + } + break; + default: + return False; + } + + return True; +} + +/******************************************************************* + * read or write a DEVICEMODE struct. + * on reading allocate memory for the private member + ********************************************************************/ + +#define DM_NUM_OPTIONAL_FIELDS 8 + +bool spoolss_io_devmode(const char *desc, prs_struct *ps, int depth, DEVICEMODE *devmode) +{ + int available_space; /* size of the device mode left to parse */ + /* only important on unmarshalling */ + int i = 0; + uint16 *unistr_buffer; + int j; + + struct optional_fields { + fstring name; + uint32* field; + } opt_fields[DM_NUM_OPTIONAL_FIELDS] = { + { "icmmethod", NULL }, + { "icmintent", NULL }, + { "mediatype", NULL }, + { "dithertype", NULL }, + { "reserved1", NULL }, + { "reserved2", NULL }, + { "panningwidth", NULL }, + { "panningheight", NULL } + }; + + /* assign at run time to keep non-gcc compilers happy */ + + opt_fields[0].field = &devmode->icmmethod; + opt_fields[1].field = &devmode->icmintent; + opt_fields[2].field = &devmode->mediatype; + opt_fields[3].field = &devmode->dithertype; + opt_fields[4].field = &devmode->reserved1; + opt_fields[5].field = &devmode->reserved2; + opt_fields[6].field = &devmode->panningwidth; + opt_fields[7].field = &devmode->panningheight; + + + prs_debug(ps, depth, desc, "spoolss_io_devmode"); + depth++; + + if (UNMARSHALLING(ps)) { + devmode->devicename.buffer = PRS_ALLOC_MEM(ps, uint16, MAXDEVICENAME); + if (devmode->devicename.buffer == NULL) + return False; + unistr_buffer = devmode->devicename.buffer; + } + else { + /* devicename is a static sized string but the buffer we set is not */ + unistr_buffer = PRS_ALLOC_MEM(ps, uint16, MAXDEVICENAME); + memset( unistr_buffer, 0x0, MAXDEVICENAME ); + for ( j=0; devmode->devicename.buffer[j]; j++ ) + unistr_buffer[j] = devmode->devicename.buffer[j]; + } + + if (!prs_uint16uni(True,"devicename", ps, depth, unistr_buffer, MAXDEVICENAME)) + return False; + + if (!prs_uint16("specversion", ps, depth, &devmode->specversion)) + return False; + + if (!prs_uint16("driverversion", ps, depth, &devmode->driverversion)) + return False; + if (!prs_uint16("size", ps, depth, &devmode->size)) + return False; + if (!prs_uint16("driverextra", ps, depth, &devmode->driverextra)) + return False; + if (!prs_uint32("fields", ps, depth, &devmode->fields)) + return False; + if (!prs_uint16("orientation", ps, depth, &devmode->orientation)) + return False; + if (!prs_uint16("papersize", ps, depth, &devmode->papersize)) + return False; + if (!prs_uint16("paperlength", ps, depth, &devmode->paperlength)) + return False; + if (!prs_uint16("paperwidth", ps, depth, &devmode->paperwidth)) + return False; + if (!prs_uint16("scale", ps, depth, &devmode->scale)) + return False; + if (!prs_uint16("copies", ps, depth, &devmode->copies)) + return False; + if (!prs_uint16("defaultsource", ps, depth, &devmode->defaultsource)) + return False; + if (!prs_uint16("printquality", ps, depth, &devmode->printquality)) + return False; + if (!prs_uint16("color", ps, depth, &devmode->color)) + return False; + if (!prs_uint16("duplex", ps, depth, &devmode->duplex)) + return False; + if (!prs_uint16("yresolution", ps, depth, &devmode->yresolution)) + return False; + if (!prs_uint16("ttoption", ps, depth, &devmode->ttoption)) + return False; + if (!prs_uint16("collate", ps, depth, &devmode->collate)) + return False; + + if (UNMARSHALLING(ps)) { + devmode->formname.buffer = PRS_ALLOC_MEM(ps, uint16, MAXDEVICENAME); + if (devmode->formname.buffer == NULL) + return False; + unistr_buffer = devmode->formname.buffer; + } + else { + /* devicename is a static sized string but the buffer we set is not */ + unistr_buffer = PRS_ALLOC_MEM(ps, uint16, MAXDEVICENAME); + memset( unistr_buffer, 0x0, MAXDEVICENAME ); + for ( j=0; devmode->formname.buffer[j]; j++ ) + unistr_buffer[j] = devmode->formname.buffer[j]; + } + + if (!prs_uint16uni(True, "formname", ps, depth, unistr_buffer, MAXDEVICENAME)) + return False; + if (!prs_uint16("logpixels", ps, depth, &devmode->logpixels)) + return False; + if (!prs_uint32("bitsperpel", ps, depth, &devmode->bitsperpel)) + return False; + if (!prs_uint32("pelswidth", ps, depth, &devmode->pelswidth)) + return False; + if (!prs_uint32("pelsheight", ps, depth, &devmode->pelsheight)) + return False; + if (!prs_uint32("displayflags", ps, depth, &devmode->displayflags)) + return False; + if (!prs_uint32("displayfrequency", ps, depth, &devmode->displayfrequency)) + return False; + /* + * every device mode I've ever seen on the wire at least has up + * to the displayfrequency field. --jerry (05-09-2002) + */ + + /* add uint32's + uint16's + two UNICODE strings */ + + available_space = devmode->size - (sizeof(uint32)*6 + sizeof(uint16)*18 + sizeof(uint16)*64); + + /* Sanity check - we only have uint32's left tp parse */ + + if ( available_space && ((available_space % sizeof(uint32)) != 0) ) { + DEBUG(0,("spoolss_io_devmode: available_space [%d] no in multiple of 4 bytes (size = %d)!\n", + available_space, devmode->size)); + DEBUG(0,("spoolss_io_devmode: please report to samba-technical@samba.org!\n")); + return False; + } + + /* + * Conditional parsing. Assume that the DeviceMode has been + * zero'd by the caller. + */ + + while ((available_space > 0) && (i < DM_NUM_OPTIONAL_FIELDS)) + { + DEBUG(11, ("spoolss_io_devmode: [%d] bytes left to parse in devmode\n", available_space)); + if (!prs_uint32(opt_fields[i].name, ps, depth, opt_fields[i].field)) + return False; + available_space -= sizeof(uint32); + i++; + } + + /* Sanity Check - we should no available space at this point unless + MS changes the device mode structure */ + + if (available_space) { + DEBUG(0,("spoolss_io_devmode: I've parsed all I know and there is still stuff left|\n")); + DEBUG(0,("spoolss_io_devmode: available_space = [%d], devmode_size = [%d]!\n", + available_space, devmode->size)); + DEBUG(0,("spoolss_io_devmode: please report to samba-technical@samba.org!\n")); + return False; + } + + + if (devmode->driverextra!=0) { + if (UNMARSHALLING(ps)) { + devmode->dev_private=PRS_ALLOC_MEM(ps, uint8, devmode->driverextra); + if(devmode->dev_private == NULL) + return False; + DEBUG(7,("spoolss_io_devmode: allocated memory [%d] for dev_private\n",devmode->driverextra)); + } + + DEBUG(7,("spoolss_io_devmode: parsing [%d] bytes of dev_private\n",devmode->driverextra)); + if (!prs_uint8s(False, "dev_private", ps, depth, + devmode->dev_private, devmode->driverextra)) + return False; + } + + return True; +} + +/******************************************************************* + Read or write a DEVICEMODE container +********************************************************************/ + +static bool spoolss_io_devmode_cont(const char *desc, DEVMODE_CTR *dm_c, prs_struct *ps, int depth) +{ + if (dm_c==NULL) + return False; + + prs_debug(ps, depth, desc, "spoolss_io_devmode_cont"); + depth++; + + if(!prs_align(ps)) + return False; + + if (!prs_uint32("size", ps, depth, &dm_c->size)) + return False; + + if (!prs_uint32("devmode_ptr", ps, depth, &dm_c->devmode_ptr)) + return False; + + if (dm_c->size==0 || dm_c->devmode_ptr==0) { + if (UNMARSHALLING(ps)) + /* if while reading there is no DEVMODE ... */ + dm_c->devmode=NULL; + return True; + } + + /* so we have a DEVICEMODE to follow */ + if (UNMARSHALLING(ps)) { + DEBUG(9,("Allocating memory for spoolss_io_devmode\n")); + dm_c->devmode=PRS_ALLOC_MEM(ps,DEVICEMODE,1); + if(dm_c->devmode == NULL) + return False; + } + + /* this is bad code, shouldn't be there */ + if (!prs_uint32("size", ps, depth, &dm_c->size)) + return False; + + if (!spoolss_io_devmode(desc, ps, depth, dm_c->devmode)) + return False; + + return True; +} + +/******************************************************************* +********************************************************************/ + +static bool spoolss_io_printer_default(const char *desc, PRINTER_DEFAULT *pd, prs_struct *ps, int depth) +{ + if (pd==NULL) + return False; + + prs_debug(ps, depth, desc, "spoolss_io_printer_default"); + depth++; + + if (!prs_uint32("datatype_ptr", ps, depth, &pd->datatype_ptr)) + return False; + + 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)) + return False; + + if (!prs_align(ps)) + return False; + + if (!prs_uint32("access_required", ps, depth, &pd->access_required)) + return False; + + return True; +} + +/******************************************************************* + * init a structure. + ********************************************************************/ + +bool make_spoolss_q_open_printer_ex(SPOOL_Q_OPEN_PRINTER_EX *q_u, + const fstring printername, + const fstring datatype, + uint32 access_required, + const fstring clientname, + const fstring user_name) +{ + DEBUG(5,("make_spoolss_q_open_printer_ex\n")); + + q_u->printername = TALLOC_P( talloc_tos(), UNISTR2 ); + if (!q_u->printername) { + return False; + } + init_unistr2(q_u->printername, printername, UNI_STR_TERMINATE); + + q_u->printer_default.datatype_ptr = 0; + + q_u->printer_default.devmode_cont.size=0; + q_u->printer_default.devmode_cont.devmode_ptr=0; + q_u->printer_default.devmode_cont.devmode=NULL; + q_u->printer_default.access_required=access_required; + + q_u->user_switch = 1; + + q_u->user_ctr.level = 1; + q_u->user_ctr.user.user1 = TALLOC_P( talloc_tos(), SPOOL_USER_1 ); + if (!q_u->user_ctr.user.user1) { + return False; + } + q_u->user_ctr.user.user1->size = strlen(clientname) + strlen(user_name) + 10; + q_u->user_ctr.user.user1->build = 1381; + q_u->user_ctr.user.user1->major = 2; + q_u->user_ctr.user.user1->minor = 0; + q_u->user_ctr.user.user1->processor = 0; + + q_u->user_ctr.user.user1->client_name = TALLOC_P( talloc_tos(), UNISTR2 ); + if (!q_u->user_ctr.user.user1->client_name) { + return False; + } + q_u->user_ctr.user.user1->user_name = TALLOC_P( talloc_tos(), UNISTR2 ); + if (!q_u->user_ctr.user.user1->user_name) { + return False; + } + + init_unistr2(q_u->user_ctr.user.user1->client_name, clientname, UNI_STR_TERMINATE); + init_unistr2(q_u->user_ctr.user.user1->user_name, user_name, UNI_STR_TERMINATE); + + 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 || !ctr->printers_2) + return False; + + ZERO_STRUCTP(q_u); + + q_u->server_name = TALLOC_P( mem_ctx, UNISTR2 ); + if (!q_u->server_name) { + return False; + } + init_unistr2(q_u->server_name, srv_name, UNI_FLAGS_NONE); + + 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->user_switch=1; + + q_u->user_ctr.level = 1; + q_u->user_ctr.user.user1 = TALLOC_P( talloc_tos(), SPOOL_USER_1 ); + if (!q_u->user_ctr.user.user1) { + return False; + } + q_u->user_ctr.user.user1->build = 1381; + q_u->user_ctr.user.user1->major = 2; + q_u->user_ctr.user.user1->minor = 0; + q_u->user_ctr.user.user1->processor = 0; + + q_u->user_ctr.user.user1->client_name = TALLOC_P( mem_ctx, UNISTR2 ); + if (!q_u->user_ctr.user.user1->client_name) { + return False; + } + q_u->user_ctr.user.user1->user_name = TALLOC_P( mem_ctx, UNISTR2 ); + if (!q_u->user_ctr.user.user1->user_name) { + return False; + } + init_unistr2(q_u->user_ctr.user.user1->client_name, clientname, UNI_STR_TERMINATE); + init_unistr2(q_u->user_ctr.user.user1->user_name, user_name, UNI_STR_TERMINATE); + + q_u->user_ctr.user.user1->size = q_u->user_ctr.user.user1->user_name->uni_str_len + + q_u->user_ctr.user.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 *ctx, SPOOL_PRINTER_INFO_LEVEL_2 **spool_info2, + PRINTER_INFO_2 *info) +{ + + SPOOL_PRINTER_INFO_LEVEL_2 *inf; + + /* allocate the necessary memory */ + if (!(inf=TALLOC_P(ctx, 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, &inf->servername, &info->servername); + init_unistr2_from_unistr(inf, &inf->printername, &info->printername); + init_unistr2_from_unistr(inf, &inf->sharename, &info->sharename); + init_unistr2_from_unistr(inf, &inf->portname, &info->portname); + init_unistr2_from_unistr(inf, &inf->drivername, &info->drivername); + init_unistr2_from_unistr(inf, &inf->comment, &info->comment); + init_unistr2_from_unistr(inf, &inf->location, &info->location); + init_unistr2_from_unistr(inf, &inf->sepfile, &info->sepfile); + init_unistr2_from_unistr(inf, &inf->printprocessor, &info->printprocessor); + init_unistr2_from_unistr(inf, &inf->datatype, &info->datatype); + init_unistr2_from_unistr(inf, &inf->parameters, &info->parameters); + init_unistr2_from_unistr(inf, &inf->datatype, &info->datatype); + + *spool_info2 = inf; + + return True; +} + +/******************************************************************* +create a SPOOL_PRINTER_INFO_3 struct from a PRINTER_INFO_3 struct +*******************************************************************/ + +bool make_spoolss_printer_info_3(TALLOC_CTX *mem_ctx, SPOOL_PRINTER_INFO_LEVEL_3 **spool_info3, + PRINTER_INFO_3 *info) +{ + + SPOOL_PRINTER_INFO_LEVEL_3 *inf; + + /* allocate the necessary memory */ + if (!(inf=TALLOC_P(mem_ctx, SPOOL_PRINTER_INFO_LEVEL_3))) { + DEBUG(0,("make_spoolss_printer_info_3: Unable to allocate SPOOL_PRINTER_INFO_LEVEL_3 sruct!\n")); + return False; + } + + inf->secdesc_ptr = (info->secdesc!=NULL)?1:0; + + *spool_info3 = inf; + + return True; +} + +/******************************************************************* +create a SPOOL_PRINTER_INFO_7 struct from a PRINTER_INFO_7 struct +*******************************************************************/ + +bool make_spoolss_printer_info_7(TALLOC_CTX *mem_ctx, SPOOL_PRINTER_INFO_LEVEL_7 **spool_info7, + PRINTER_INFO_7 *info) +{ + + SPOOL_PRINTER_INFO_LEVEL_7 *inf; + + /* allocate the necessary memory */ + if (!(inf=TALLOC_P(mem_ctx, SPOOL_PRINTER_INFO_LEVEL_7))) { + DEBUG(0,("make_spoolss_printer_info_7: Unable to allocate SPOOL_PRINTER_INFO_LEVEL_7 struct!\n")); + return False; + } + + inf->guid_ptr = (info->guid.buffer!=NULL)?1:0; + inf->action = info->action; + init_unistr2_from_unistr(inf, &inf->guid, &info->guid); + + *spool_info7 = inf; + + return True; +} + + +/******************************************************************* + * read a structure. + * called from spoolss_q_open_printer_ex (srv_spoolss.c) + ********************************************************************/ + +bool spoolss_io_q_open_printer(const char *desc, SPOOL_Q_OPEN_PRINTER *q_u, prs_struct *ps, int depth) +{ + if (q_u == NULL) + return False; + + prs_debug(ps, depth, desc, "spoolss_io_q_open_printer"); + depth++; + + if (!prs_align(ps)) + return False; + + if (!prs_io_unistr2_p("ptr", ps, depth, &q_u->printername)) + return False; + if (!prs_io_unistr2("printername", ps, depth, q_u->printername)) + return False; + + if (!prs_align(ps)) + return False; + + if (!spoolss_io_printer_default("", &q_u->printer_default, ps, depth)) + return False; + + return True; +} + +/******************************************************************* + * write a structure. + * 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(const char *desc, SPOOL_R_OPEN_PRINTER *r_u, prs_struct *ps, int depth) +{ + if (r_u == NULL) return False; + + prs_debug(ps, depth, desc, "spoolss_io_r_open_printer"); + depth++; + + if (!prs_align(ps)) + return False; + + if (!smb_io_pol_hnd("printer handle",&(r_u->handle),ps,depth)) + return False; + + if (!prs_werror("status", ps, depth, &(r_u->status))) + return False; + + return True; +} + + +/******************************************************************* + * read a structure. + * called from spoolss_q_open_printer_ex (srv_spoolss.c) + ********************************************************************/ + +bool spoolss_io_q_open_printer_ex(const char *desc, SPOOL_Q_OPEN_PRINTER_EX *q_u, prs_struct *ps, int depth) +{ + if (q_u == NULL) + return False; + + prs_debug(ps, depth, desc, "spoolss_io_q_open_printer_ex"); + depth++; + + if (!prs_align(ps)) + return False; + + if (!prs_io_unistr2_p("ptr", ps, depth, &q_u->printername)) + return False; + if (!prs_io_unistr2("printername", ps, depth, q_u->printername)) + return False; + + if (!prs_align(ps)) + return False; + + if (!spoolss_io_printer_default("", &q_u->printer_default, ps, depth)) + return False; + + if (!prs_uint32("user_switch", ps, depth, &q_u->user_switch)) + return False; + if (!spool_io_user_level("", &q_u->user_ctr, ps, depth)) + return False; + + return True; +} + +/******************************************************************* + * write a structure. + * 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(const char *desc, SPOOL_R_OPEN_PRINTER_EX *r_u, prs_struct *ps, int depth) +{ + if (r_u == NULL) return False; + + prs_debug(ps, depth, desc, "spoolss_io_r_open_printer_ex"); + depth++; + + if (!prs_align(ps)) + return False; + + if (!smb_io_pol_hnd("printer handle",&(r_u->handle),ps,depth)) + return False; + + if (!prs_werror("status", ps, depth, &(r_u->status))) + return False; + + return True; +} + +/******************************************************************* + * init a structure. + ********************************************************************/ +bool make_spoolss_q_deleteprinterdriverex( TALLOC_CTX *mem_ctx, + SPOOL_Q_DELETEPRINTERDRIVEREX *q_u, + const char *server, + const char* arch, + const char* driver, + int version) +{ + DEBUG(5,("make_spoolss_q_deleteprinterdriverex\n")); + + q_u->server_ptr = (server!=NULL)?1:0; + q_u->delete_flags = DPD_DELETE_UNUSED_FILES; + + /* these must be NULL terminated or else NT4 will + complain about invalid parameters --jerry */ + init_unistr2(&q_u->server, server, UNI_STR_TERMINATE); + init_unistr2(&q_u->arch, arch, UNI_STR_TERMINATE); + init_unistr2(&q_u->driver, driver, UNI_STR_TERMINATE); + + if (version >= 0) { + q_u->delete_flags |= DPD_DELETE_SPECIFIC_VERSION; + q_u->version = version; + } + + return True; +} + + +/******************************************************************* + * 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, UNI_STR_TERMINATE); + init_unistr2(&q_u->arch, arch, UNI_STR_TERMINATE); + init_unistr2(&q_u->driver, driver, UNI_STR_TERMINATE); + + return True; +} + +/******************************************************************* + * make a structure. + ********************************************************************/ + +bool make_spoolss_q_getprinterdata(SPOOL_Q_GETPRINTERDATA *q_u, + const POLICY_HND *handle, + const char *valuename, uint32 size) +{ + if (q_u == NULL) return False; + + DEBUG(5,("make_spoolss_q_getprinterdata\n")); + + q_u->handle = *handle; + init_unistr2(&q_u->valuename, valuename, UNI_STR_TERMINATE); + q_u->size = size; + + return True; +} + +/******************************************************************* + * make a structure. + ********************************************************************/ + +bool make_spoolss_q_getprinterdataex(SPOOL_Q_GETPRINTERDATAEX *q_u, + const POLICY_HND *handle, + const char *keyname, + const char *valuename, uint32 size) +{ + if (q_u == NULL) return False; + + DEBUG(5,("make_spoolss_q_getprinterdataex\n")); + + q_u->handle = *handle; + init_unistr2(&q_u->valuename, valuename, UNI_STR_TERMINATE); + init_unistr2(&q_u->keyname, keyname, UNI_STR_TERMINATE); + q_u->size = size; + + return True; +} + +/******************************************************************* + * read a structure. + * called from spoolss_q_getprinterdata (srv_spoolss.c) + ********************************************************************/ + +bool spoolss_io_q_getprinterdata(const char *desc, SPOOL_Q_GETPRINTERDATA *q_u, prs_struct *ps, int depth) +{ + 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)) + 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(const 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_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; + + return True; +} + +/******************************************************************* + * write a structure. + * called from spoolss_r_deleteprinterdata (srv_spoolss.c) + ********************************************************************/ + +bool spoolss_io_r_deleteprinterdata(const char *desc, SPOOL_R_DELETEPRINTERDATA *r_u, prs_struct *ps, int depth) +{ + prs_debug(ps, depth, desc, "spoolss_io_r_deleteprinterdata"); + depth++; + if(!prs_werror("status", ps, depth, &r_u->status)) + return False; + + return True; +} + +/******************************************************************* + * read a structure. + * called from spoolss_q_deleteprinterdataex (srv_spoolss.c) + ********************************************************************/ + +bool spoolss_io_q_deleteprinterdataex(const char *desc, SPOOL_Q_DELETEPRINTERDATAEX *q_u, prs_struct *ps, int depth) +{ + if (q_u == NULL) + return False; + + prs_debug(ps, depth, desc, "spoolss_io_q_deleteprinterdataex"); + 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("keyname ", &q_u->keyname, True, ps, depth)) + return False; + if (!smb_io_unistr2("valuename", &q_u->valuename, True, ps, depth)) + return False; + + return True; +} + +/******************************************************************* + * write a structure. + * called from spoolss_r_deleteprinterdataex (srv_spoolss.c) + ********************************************************************/ + +bool spoolss_io_r_deleteprinterdataex(const char *desc, SPOOL_R_DELETEPRINTERDATAEX *r_u, prs_struct *ps, int depth) +{ + prs_debug(ps, depth, desc, "spoolss_io_r_deleteprinterdataex"); + depth++; + + if(!prs_werror("status", ps, depth, &r_u->status)) + return False; + + return True; +} + +/******************************************************************* + * write a structure. + * called from spoolss_r_getprinterdata (srv_spoolss.c) + ********************************************************************/ + +bool spoolss_io_r_getprinterdata(const char *desc, SPOOL_R_GETPRINTERDATA *r_u, prs_struct *ps, int depth) +{ + if (r_u == NULL) + return False; + + prs_debug(ps, depth, desc, "spoolss_io_r_getprinterdata"); + depth++; + + if (!prs_align(ps)) + return False; + if (!prs_uint32("type", ps, depth, &r_u->type)) + return False; + if (!prs_uint32("size", ps, depth, &r_u->size)) + return False; + + if (UNMARSHALLING(ps) && r_u->size) { + r_u->data = PRS_ALLOC_MEM(ps, unsigned char, r_u->size); + if(!r_u->data) + return False; + } + + if (!prs_uint8s( False, "data", ps, depth, r_u->data, r_u->size )) + return False; + + if (!prs_align(ps)) + return False; + + if (!prs_uint32("needed", ps, depth, &r_u->needed)) + return False; + if (!prs_werror("status", ps, depth, &r_u->status)) + return False; + + return True; +} + +/******************************************************************* + * 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)); + + 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(const 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(const char *desc, SPOOL_R_ABORTPRINTER *r_u, prs_struct *ps, int depth) +{ + prs_debug(ps, depth, desc, "spoolss_io_r_abortprinter"); + depth++; + if(!prs_werror("status", ps, depth, &r_u->status)) + return False; + + return True; +} + +/******************************************************************* + * read a structure. + * called from static spoolss_q_deleteprinter (srv_spoolss.c) + * called from spoolss_deleteprinter (cli_spoolss.c) + ********************************************************************/ + +bool spoolss_io_q_deleteprinter(const char *desc, SPOOL_Q_DELETEPRINTER *q_u, prs_struct *ps, int depth) +{ + if (q_u == NULL) return False; + + prs_debug(ps, depth, desc, "spoolss_io_q_deleteprinter"); + 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 static spoolss_r_deleteprinter (srv_spoolss.c) + * called from spoolss_deleteprinter (cli_spoolss.c) + ********************************************************************/ + +bool spoolss_io_r_deleteprinter(const char *desc, SPOOL_R_DELETEPRINTER *r_u, prs_struct *ps, int depth) +{ + prs_debug(ps, depth, desc, "spoolss_io_r_deleteprinter"); + depth++; + + if (!prs_align(ps)) + return False; + + if (!smb_io_pol_hnd("printer handle",&r_u->handle,ps,depth)) + return False; + if (!prs_werror("status", ps, depth, &r_u->status)) + return False; + + return True; +} + + +/******************************************************************* + * read a structure. + * called from api_spoolss_deleteprinterdriver (srv_spoolss.c) + * called from spoolss_deleteprinterdriver (cli_spoolss.c) + ********************************************************************/ + +bool spoolss_io_q_deleteprinterdriver(const 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(const 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_werror("status", ps, depth, &r_u->status)) + return False; + + return True; +} + + +/******************************************************************* + * read a structure. + * called from api_spoolss_deleteprinterdriver (srv_spoolss.c) + * called from spoolss_deleteprinterdriver (cli_spoolss.c) + ********************************************************************/ + +bool spoolss_io_q_deleteprinterdriverex(const char *desc, SPOOL_Q_DELETEPRINTERDRIVEREX *q_u, prs_struct *ps, int depth) +{ + if (q_u == NULL) return False; + + prs_debug(ps, depth, desc, "spoolss_io_q_deleteprinterdriverex"); + 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; + + if (!prs_align(ps)) + return False; + + if(!prs_uint32("delete_flags ", ps, depth, &q_u->delete_flags)) + return False; + if(!prs_uint32("version ", ps, depth, &q_u->version)) + return False; + + + return True; +} + + +/******************************************************************* + * write a structure. + ********************************************************************/ +bool spoolss_io_r_deleteprinterdriverex(const char *desc, SPOOL_R_DELETEPRINTERDRIVEREX *r_u, prs_struct *ps, int depth) +{ + if (r_u == NULL) return False; + + prs_debug(ps, depth, desc, "spoolss_io_r_deleteprinterdriverex"); + depth++; + + if (!prs_align(ps)) + return False; + + if (!prs_werror("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(const char *desc, SPOOL_Q_CLOSEPRINTER *q_u, prs_struct *ps, int depth) +{ + if (q_u == NULL) return False; + + prs_debug(ps, depth, desc, "spoolss_io_q_closeprinter"); + 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 static spoolss_r_closeprinter (srv_spoolss.c) + * called from spoolss_closeprinter (cli_spoolss.c) + ********************************************************************/ + +bool spoolss_io_r_closeprinter(const char *desc, SPOOL_R_CLOSEPRINTER *r_u, prs_struct *ps, int depth) +{ + prs_debug(ps, depth, desc, "spoolss_io_r_closeprinter"); + depth++; + + if (!prs_align(ps)) + return False; + + if (!smb_io_pol_hnd("printer handle",&r_u->handle,ps,depth)) + return False; + if (!prs_werror("status", ps, depth, &r_u->status)) + return False; + + return True; +} + +/******************************************************************* + * read a structure. + * called from spoolss_q_startdocprinter (srv_spoolss.c) + ********************************************************************/ + +bool spoolss_io_q_startdocprinter(const char *desc, SPOOL_Q_STARTDOCPRINTER *q_u, prs_struct *ps, int depth) +{ + if (q_u == NULL) return False; + + prs_debug(ps, depth, desc, "spoolss_io_q_startdocprinter"); + depth++; + + if(!prs_align(ps)) + return False; + + 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)) + return False; + + return True; +} + +/******************************************************************* + * write a structure. + * called from spoolss_r_startdocprinter (srv_spoolss.c) + ********************************************************************/ + +bool spoolss_io_r_startdocprinter(const char *desc, SPOOL_R_STARTDOCPRINTER *r_u, prs_struct *ps, int depth) +{ + prs_debug(ps, depth, desc, "spoolss_io_r_startdocprinter"); + depth++; + if(!prs_uint32("jobid", ps, depth, &r_u->jobid)) + return False; + if(!prs_werror("status", ps, depth, &r_u->status)) + return False; + + return True; +} + +/******************************************************************* + * read a structure. + * called from spoolss_q_enddocprinter (srv_spoolss.c) + ********************************************************************/ + +bool spoolss_io_q_enddocprinter(const char *desc, SPOOL_Q_ENDDOCPRINTER *q_u, prs_struct *ps, int depth) +{ + if (q_u == NULL) return False; + + prs_debug(ps, depth, desc, "spoolss_io_q_enddocprinter"); + 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_enddocprinter (srv_spoolss.c) + ********************************************************************/ + +bool spoolss_io_r_enddocprinter(const char *desc, SPOOL_R_ENDDOCPRINTER *r_u, prs_struct *ps, int depth) +{ + prs_debug(ps, depth, desc, "spoolss_io_r_enddocprinter"); + depth++; + if(!prs_werror("status", ps, depth, &r_u->status)) + return False; + + return True; +} + +/******************************************************************* + * read a structure. + * called from spoolss_q_startpageprinter (srv_spoolss.c) + ********************************************************************/ + +bool spoolss_io_q_startpageprinter(const char *desc, SPOOL_Q_STARTPAGEPRINTER *q_u, prs_struct *ps, int depth) +{ + if (q_u == NULL) return False; + + prs_debug(ps, depth, desc, "spoolss_io_q_startpageprinter"); + 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_startpageprinter (srv_spoolss.c) + ********************************************************************/ + +bool spoolss_io_r_startpageprinter(const char *desc, SPOOL_R_STARTPAGEPRINTER *r_u, prs_struct *ps, int depth) +{ + prs_debug(ps, depth, desc, "spoolss_io_r_startpageprinter"); + depth++; + if(!prs_werror("status", ps, depth, &r_u->status)) + return False; + + return True; +} + +/******************************************************************* + * read a structure. + * called from spoolss_q_endpageprinter (srv_spoolss.c) + ********************************************************************/ + +bool spoolss_io_q_endpageprinter(const char *desc, SPOOL_Q_ENDPAGEPRINTER *q_u, prs_struct *ps, int depth) +{ + if (q_u == NULL) return False; + + prs_debug(ps, depth, desc, "spoolss_io_q_endpageprinter"); + 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_endpageprinter (srv_spoolss.c) + ********************************************************************/ + +bool spoolss_io_r_endpageprinter(const char *desc, SPOOL_R_ENDPAGEPRINTER *r_u, prs_struct *ps, int depth) +{ + prs_debug(ps, depth, desc, "spoolss_io_r_endpageprinter"); + depth++; + if(!prs_werror("status", ps, depth, &r_u->status)) + return False; + + return True; +} + +/******************************************************************* + * read a structure. + * called from spoolss_q_writeprinter (srv_spoolss.c) + ********************************************************************/ + +bool spoolss_io_q_writeprinter(const char *desc, SPOOL_Q_WRITEPRINTER *q_u, prs_struct *ps, int depth) +{ + if (q_u == NULL) return False; + + prs_debug(ps, depth, desc, "spoolss_io_q_writeprinter"); + depth++; + + if(!prs_align(ps)) + return False; + + if(!smb_io_pol_hnd("printer handle",&q_u->handle,ps,depth)) + return False; + if(!prs_uint32("buffer_size", ps, depth, &q_u->buffer_size)) + return False; + + if (q_u->buffer_size!=0) + { + if (UNMARSHALLING(ps)) + q_u->buffer=PRS_ALLOC_MEM(ps, uint8, q_u->buffer_size); + if(q_u->buffer == NULL) + return False; + if(!prs_uint8s(True, "buffer", ps, depth, q_u->buffer, q_u->buffer_size)) + return False; + } + if(!prs_align(ps)) + return False; + if(!prs_uint32("buffer_size2", ps, depth, &q_u->buffer_size2)) + return False; + + return True; +} + +/******************************************************************* + * write a structure. + * called from spoolss_r_writeprinter (srv_spoolss.c) + ********************************************************************/ + +bool spoolss_io_r_writeprinter(const char *desc, SPOOL_R_WRITEPRINTER *r_u, prs_struct *ps, int depth) +{ + prs_debug(ps, depth, desc, "spoolss_io_r_writeprinter"); + depth++; + if(!prs_uint32("buffer_written", ps, depth, &r_u->buffer_written)) + return False; + if(!prs_werror("status", ps, depth, &r_u->status)) + return False; + + return True; +} + +/******************************************************************* + * read a structure. + * called from spoolss_q_rffpcnex (srv_spoolss.c) + ********************************************************************/ + +bool spoolss_io_q_rffpcnex(const char *desc, SPOOL_Q_RFFPCNEX *q_u, prs_struct *ps, int depth) +{ + prs_debug(ps, depth, desc, "spoolss_io_q_rffpcnex"); + depth++; + + if(!prs_align(ps)) + return False; + + if(!smb_io_pol_hnd("printer handle", &q_u->handle, ps, depth)) + return False; + if(!prs_uint32("flags", ps, depth, &q_u->flags)) + return False; + if(!prs_uint32("options", ps, depth, &q_u->options)) + return False; + if(!prs_uint32("localmachine_ptr", ps, depth, &q_u->localmachine_ptr)) + return False; + if(!smb_io_unistr2("localmachine", &q_u->localmachine, q_u->localmachine_ptr, ps, depth)) + return False; + + if(!prs_align(ps)) + return False; + + if(!prs_uint32("printerlocal", ps, depth, &q_u->printerlocal)) + return False; + + if(!prs_uint32("option_ptr", ps, depth, &q_u->option_ptr)) + return False; + + if (q_u->option_ptr!=0) { + + if (UNMARSHALLING(ps)) + if((q_u->option=PRS_ALLOC_MEM(ps,SPOOL_NOTIFY_OPTION,1)) == NULL) + return False; + + if(!smb_io_notify_option("notify option", q_u->option, ps, depth)) + return False; + } + + return True; +} + +/******************************************************************* + * write a structure. + * called from spoolss_r_rffpcnex (srv_spoolss.c) + ********************************************************************/ + +bool spoolss_io_r_rffpcnex(const char *desc, SPOOL_R_RFFPCNEX *r_u, prs_struct *ps, int depth) +{ + prs_debug(ps, depth, desc, "spoolss_io_r_rffpcnex"); + depth++; + + if(!prs_werror("status", ps, depth, &r_u->status)) + return False; + + return True; +} + +/******************************************************************* + * read a structure. + * called from spoolss_q_rfnpcnex (srv_spoolss.c) + ********************************************************************/ + +bool spoolss_io_q_rfnpcnex(const char *desc, SPOOL_Q_RFNPCNEX *q_u, prs_struct *ps, int depth) +{ + prs_debug(ps, depth, desc, "spoolss_io_q_rfnpcnex"); + 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", ps, depth, &q_u->change)) + return False; + + if(!prs_uint32("option_ptr", ps, depth, &q_u->option_ptr)) + return False; + + if (q_u->option_ptr!=0) { + + if (UNMARSHALLING(ps)) + if((q_u->option=PRS_ALLOC_MEM(ps,SPOOL_NOTIFY_OPTION,1)) == NULL) + return False; + + if(!smb_io_notify_option("notify option", q_u->option, ps, depth)) + return False; + } + + return True; +} + +/******************************************************************* + * write a structure. + * called from spoolss_r_rfnpcnex (srv_spoolss.c) + ********************************************************************/ + +bool spoolss_io_r_rfnpcnex(const char *desc, SPOOL_R_RFNPCNEX *r_u, prs_struct *ps, int depth) +{ + prs_debug(ps, depth, desc, "spoolss_io_r_rfnpcnex"); + depth++; + + if(!prs_align(ps)) + return False; + + if (!prs_uint32("info_ptr", ps, depth, &r_u->info_ptr)) + return False; + + if(!smb_io_notify_info("notify info", &r_u->info ,ps,depth)) + return False; + + if(!prs_align(ps)) + return False; + if(!prs_werror("status", ps, depth, &r_u->status)) + return False; + + return True; +} + +/******************************************************************* + * return the length of a uint16 (obvious, but the code is clean) + ********************************************************************/ + +static uint32 size_of_uint16(uint16 *value) +{ + return (sizeof(*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 uint32 (obvious, but the code is clean) + ********************************************************************/ + +static uint32 size_of_device_mode(DEVICEMODE *devmode) +{ + if (devmode==NULL) + return (4); + else + return (4+devmode->size+devmode->driverextra); +} + +/******************************************************************* + * return the length of a uint32 (obvious, but the code is clean) + ********************************************************************/ + +static uint32 size_of_systemtime(SYSTEMTIME *systime) +{ + if (systime==NULL) + return (4); + else + return (sizeof(SYSTEMTIME) +4); +} + +/******************************************************************* + Parse a DEVMODE structure and its relative pointer. +********************************************************************/ + +static bool smb_io_reldevmode(const char *desc, RPC_BUFFER *buffer, int depth, DEVICEMODE **devmode) +{ + prs_struct *ps=&buffer->prs; + + prs_debug(ps, depth, desc, "smb_io_reldevmode"); + depth++; + + if (MARSHALLING(ps)) { + uint32 struct_offset = prs_offset(ps); + uint32 relative_offset; + + if (*devmode == NULL) { + relative_offset=0; + if (!prs_uint32("offset", ps, depth, &relative_offset)) + return False; + DEBUG(8, ("boing, the devmode was NULL\n")); + + return True; + } + + buffer->string_at_end -= ((*devmode)->size + (*devmode)->driverextra); + + /* mz: we have to align the device mode for VISTA */ + if (buffer->string_at_end % 4) { + buffer->string_at_end += 4 - (buffer->string_at_end % 4); + } + + if(!prs_set_offset(ps, buffer->string_at_end)) + return False; + + /* write the DEVMODE */ + if (!spoolss_io_devmode(desc, ps, depth, *devmode)) + return False; + + if(!prs_set_offset(ps, struct_offset)) + return False; + + relative_offset=buffer->string_at_end - buffer->struct_start; + /* write its offset */ + if (!prs_uint32("offset", ps, depth, &relative_offset)) + return False; + } + else { + uint32 old_offset; + + /* read the offset */ + if (!prs_uint32("offset", ps, depth, &buffer->string_at_end)) + return False; + if (buffer->string_at_end == 0) { + *devmode = NULL; + return True; + } + + old_offset = prs_offset(ps); + if(!prs_set_offset(ps, buffer->string_at_end + buffer->struct_start)) + return False; + + /* read the string */ + if((*devmode=PRS_ALLOC_MEM(ps,DEVICEMODE,1)) == NULL) + return False; + if (!spoolss_io_devmode(desc, ps, depth, *devmode)) + return False; + + if(!prs_set_offset(ps, old_offset)) + return False; + } + return True; +} + +/******************************************************************* + Parse a PRINTER_INFO_0 structure. +********************************************************************/ + +bool smb_io_printer_info_0(const char *desc, RPC_BUFFER *buffer, PRINTER_INFO_0 *info, int depth) +{ + prs_struct *ps=&buffer->prs; + + prs_debug(ps, depth, desc, "smb_io_printer_info_0"); + depth++; + + buffer->struct_start=prs_offset(ps); + + if (!smb_io_relstr("printername", buffer, depth, &info->printername)) + return False; + if (!smb_io_relstr("servername", buffer, depth, &info->servername)) + return False; + + if(!prs_uint32("cjobs", ps, depth, &info->cjobs)) + return False; + if(!prs_uint32("total_jobs", ps, depth, &info->total_jobs)) + return False; + if(!prs_uint32("total_bytes", ps, depth, &info->total_bytes)) + return False; + + if(!prs_uint16("year", ps, depth, &info->year)) + return False; + if(!prs_uint16("month", ps, depth, &info->month)) + return False; + if(!prs_uint16("dayofweek", ps, depth, &info->dayofweek)) + return False; + if(!prs_uint16("day", ps, depth, &info->day)) + return False; + if(!prs_uint16("hour", ps, depth, &info->hour)) + return False; + if(!prs_uint16("minute", ps, depth, &info->minute)) + return False; + if(!prs_uint16("second", ps, depth, &info->second)) + return False; + if(!prs_uint16("milliseconds", ps, depth, &info->milliseconds)) + return False; + + if(!prs_uint32("global_counter", ps, depth, &info->global_counter)) + return False; + if(!prs_uint32("total_pages", ps, depth, &info->total_pages)) + return False; + + if(!prs_uint16("major_version", ps, depth, &info->major_version)) + return False; + if(!prs_uint16("build_version", ps, depth, &info->build_version)) + return False; + if(!prs_uint32("unknown7", ps, depth, &info->unknown7)) + return False; + if(!prs_uint32("unknown8", ps, depth, &info->unknown8)) + return False; + if(!prs_uint32("unknown9", ps, depth, &info->unknown9)) + return False; + if(!prs_uint32("session_counter", ps, depth, &info->session_counter)) + return False; + if(!prs_uint32("unknown11", ps, depth, &info->unknown11)) + return False; + if(!prs_uint32("printer_errors", ps, depth, &info->printer_errors)) + return False; + if(!prs_uint32("unknown13", ps, depth, &info->unknown13)) + return False; + if(!prs_uint32("unknown14", ps, depth, &info->unknown14)) + return False; + if(!prs_uint32("unknown15", ps, depth, &info->unknown15)) + return False; + if(!prs_uint32("unknown16", ps, depth, &info->unknown16)) + return False; + if(!prs_uint32("change_id", ps, depth, &info->change_id)) + return False; + if(!prs_uint32("unknown18", ps, depth, &info->unknown18)) + return False; + if(!prs_uint32("status" , ps, depth, &info->status)) + return False; + if(!prs_uint32("unknown20", ps, depth, &info->unknown20)) + return False; + if(!prs_uint32("c_setprinter", ps, depth, &info->c_setprinter)) + return False; + if(!prs_uint16("unknown22", ps, depth, &info->unknown22)) + return False; + if(!prs_uint16("unknown23", ps, depth, &info->unknown23)) + return False; + if(!prs_uint16("unknown24", ps, depth, &info->unknown24)) + return False; + if(!prs_uint16("unknown25", ps, depth, &info->unknown25)) + return False; + if(!prs_uint16("unknown26", ps, depth, &info->unknown26)) + return False; + if(!prs_uint16("unknown27", ps, depth, &info->unknown27)) + return False; + if(!prs_uint16("unknown28", ps, depth, &info->unknown28)) + return False; + if(!prs_uint16("unknown29", ps, depth, &info->unknown29)) + return False; + + return True; +} + +/******************************************************************* + Parse a PRINTER_INFO_1 structure. +********************************************************************/ + +bool smb_io_printer_info_1(const char *desc, RPC_BUFFER *buffer, PRINTER_INFO_1 *info, int depth) +{ + prs_struct *ps=&buffer->prs; + + 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 (!smb_io_relstr("description", buffer, depth, &info->description)) + return False; + if (!smb_io_relstr("name", buffer, depth, &info->name)) + return False; + if (!smb_io_relstr("comment", buffer, depth, &info->comment)) + return False; + + return True; +} + +/******************************************************************* + Parse a PRINTER_INFO_2 structure. +********************************************************************/ + +bool smb_io_printer_info_2(const char *desc, RPC_BUFFER *buffer, PRINTER_INFO_2 *info, int depth) +{ + prs_struct *ps=&buffer->prs; + uint32 dm_offset, sd_offset, current_offset; + uint32 dummy_value = 0, has_secdesc = 0; + + prs_debug(ps, depth, desc, "smb_io_printer_info_2"); + depth++; + + buffer->struct_start=prs_offset(ps); + + if (!smb_io_relstr("servername", buffer, depth, &info->servername)) + return False; + if (!smb_io_relstr("printername", buffer, depth, &info->printername)) + return False; + if (!smb_io_relstr("sharename", buffer, depth, &info->sharename)) + return False; + if (!smb_io_relstr("portname", buffer, depth, &info->portname)) + return False; + if (!smb_io_relstr("drivername", buffer, depth, &info->drivername)) + return False; + if (!smb_io_relstr("comment", buffer, depth, &info->comment)) + return False; + if (!smb_io_relstr("location", buffer, depth, &info->location)) + return False; + + /* save current offset and wind forwared by a uint32 */ + dm_offset = prs_offset(ps); + if (!prs_uint32("devmode", ps, depth, &dummy_value)) + return False; + + if (!smb_io_relstr("sepfile", buffer, depth, &info->sepfile)) + return False; + if (!smb_io_relstr("printprocessor", buffer, depth, &info->printprocessor)) + return False; + if (!smb_io_relstr("datatype", buffer, depth, &info->datatype)) + return False; + if (!smb_io_relstr("parameters", buffer, depth, &info->parameters)) + return False; + + /* save current offset for the sec_desc */ + sd_offset = prs_offset(ps); + if (!prs_uint32("sec_desc", ps, depth, &has_secdesc)) + return False; + + + /* save current location so we can pick back up here */ + current_offset = prs_offset(ps); + + /* parse the devmode */ + if (!prs_set_offset(ps, dm_offset)) + return False; + if (!smb_io_reldevmode("devmode", buffer, depth, &info->devmode)) + return False; + + /* parse the sec_desc */ + if (info->secdesc) { + if (!prs_set_offset(ps, sd_offset)) + return False; + if (!smb_io_relsecdesc("secdesc", buffer, depth, &info->secdesc)) + return False; + } + + /* pick up where we left off */ + if (!prs_set_offset(ps, current_offset)) + return False; + + if (!prs_uint32("attributes", ps, depth, &info->attributes)) + return False; + if (!prs_uint32("priority", ps, depth, &info->priority)) + return False; + if (!prs_uint32("defpriority", ps, depth, &info->defaultpriority)) + return False; + if (!prs_uint32("starttime", ps, depth, &info->starttime)) + return False; + if (!prs_uint32("untiltime", ps, depth, &info->untiltime)) + return False; + if (!prs_uint32("status", ps, depth, &info->status)) + return False; + if (!prs_uint32("jobs", ps, depth, &info->cjobs)) + return False; + if (!prs_uint32("averageppm", ps, depth, &info->averageppm)) + return False; + + return True; +} + +/******************************************************************* + Parse a PRINTER_INFO_3 structure. +********************************************************************/ + +bool smb_io_printer_info_3(const char *desc, RPC_BUFFER *buffer, PRINTER_INFO_3 *info, int depth) +{ + uint32 offset = 0; + prs_struct *ps=&buffer->prs; + + prs_debug(ps, depth, desc, "smb_io_printer_info_3"); + depth++; + + buffer->struct_start=prs_offset(ps); + + if (MARSHALLING(ps)) { + /* Ensure the SD is 8 byte aligned in the buffer. */ + uint32 start = prs_offset(ps); /* Remember the start position. */ + uint32 off_val = 0; + + /* Write a dummy value. */ + if (!prs_uint32("offset", ps, depth, &off_val)) + return False; + + /* 8 byte align. */ + if (!prs_align_uint64(ps)) + return False; + + /* Remember where we must seek back to write the SD. */ + offset = prs_offset(ps); + + /* Calculate the real offset for the SD. */ + + off_val = offset - start; + + /* Seek back to where we store the SD offset & store. */ + prs_set_offset(ps, start); + if (!prs_uint32("offset", ps, depth, &off_val)) + return False; + + /* Return to after the 8 byte align. */ + prs_set_offset(ps, offset); + + } else { + if (!prs_uint32("offset", ps, depth, &offset)) + return False; + /* Seek within the buffer. */ + if (!prs_set_offset(ps, offset)) + return False; + } + if (!sec_io_desc("sec_desc", &info->secdesc, ps, depth)) + return False; + + return True; +} + +/******************************************************************* + Parse a PRINTER_INFO_4 structure. +********************************************************************/ + +bool smb_io_printer_info_4(const char *desc, RPC_BUFFER *buffer, PRINTER_INFO_4 *info, int depth) +{ + prs_struct *ps=&buffer->prs; + + prs_debug(ps, depth, desc, "smb_io_printer_info_4"); + depth++; + + buffer->struct_start=prs_offset(ps); + + if (!smb_io_relstr("printername", buffer, depth, &info->printername)) + return False; + if (!smb_io_relstr("servername", buffer, depth, &info->servername)) + return False; + if (!prs_uint32("attributes", ps, depth, &info->attributes)) + return False; + return True; +} + +/******************************************************************* + Parse a PRINTER_INFO_5 structure. +********************************************************************/ + +bool smb_io_printer_info_5(const char *desc, RPC_BUFFER *buffer, PRINTER_INFO_5 *info, int depth) +{ + prs_struct *ps=&buffer->prs; + + prs_debug(ps, depth, desc, "smb_io_printer_info_5"); + depth++; + + buffer->struct_start=prs_offset(ps); + + if (!smb_io_relstr("printername", buffer, depth, &info->printername)) + return False; + if (!smb_io_relstr("portname", buffer, depth, &info->portname)) + return False; + if (!prs_uint32("attributes", ps, depth, &info->attributes)) + return False; + if (!prs_uint32("device_not_selected_timeout", ps, depth, &info->device_not_selected_timeout)) + return False; + if (!prs_uint32("transmission_retry_timeout", ps, depth, &info->transmission_retry_timeout)) + return False; + return True; +} + +/******************************************************************* + Parse a PRINTER_INFO_6 structure. +********************************************************************/ + +bool smb_io_printer_info_6(const char *desc, RPC_BUFFER *buffer, + PRINTER_INFO_6 *info, int depth) +{ + prs_struct *ps=&buffer->prs; + + prs_debug(ps, depth, desc, "smb_io_printer_info_6"); + depth++; + + if (!prs_uint32("status", ps, depth, &info->status)) + return False; + + return True; +} + +/******************************************************************* + Parse a PRINTER_INFO_7 structure. +********************************************************************/ + +bool smb_io_printer_info_7(const char *desc, RPC_BUFFER *buffer, PRINTER_INFO_7 *info, int depth) +{ + prs_struct *ps=&buffer->prs; + + prs_debug(ps, depth, desc, "smb_io_printer_info_7"); + depth++; + + buffer->struct_start=prs_offset(ps); + + if (!smb_io_relstr("guid", buffer, depth, &info->guid)) + return False; + if (!prs_uint32("action", ps, depth, &info->action)) + return False; + return True; +} + +/******************************************************************* + Parse a PORT_INFO_1 structure. +********************************************************************/ + +bool smb_io_port_info_1(const char *desc, RPC_BUFFER *buffer, PORT_INFO_1 *info, int depth) +{ + prs_struct *ps=&buffer->prs; + + prs_debug(ps, depth, desc, "smb_io_port_info_1"); + depth++; + + buffer->struct_start=prs_offset(ps); + + if (!smb_io_relstr("port_name", buffer, depth, &info->port_name)) + return False; + + return True; +} + +/******************************************************************* + Parse a PORT_INFO_2 structure. +********************************************************************/ + +bool smb_io_port_info_2(const char *desc, RPC_BUFFER *buffer, PORT_INFO_2 *info, int depth) +{ + prs_struct *ps=&buffer->prs; + + prs_debug(ps, depth, desc, "smb_io_port_info_2"); + depth++; + + buffer->struct_start=prs_offset(ps); + + if (!smb_io_relstr("port_name", buffer, depth, &info->port_name)) + return False; + if (!smb_io_relstr("monitor_name", buffer, depth, &info->monitor_name)) + return False; + if (!smb_io_relstr("description", buffer, depth, &info->description)) + return False; + if (!prs_uint32("port_type", ps, depth, &info->port_type)) + return False; + if (!prs_uint32("reserved", ps, depth, &info->reserved)) + return False; + + return True; +} + +/******************************************************************* + Parse a DRIVER_INFO_1 structure. +********************************************************************/ + +bool smb_io_printer_driver_info_1(const char *desc, RPC_BUFFER *buffer, DRIVER_INFO_1 *info, int depth) +{ + prs_struct *ps=&buffer->prs; + + prs_debug(ps, depth, desc, "smb_io_printer_driver_info_1"); + depth++; + + buffer->struct_start=prs_offset(ps); + + if (!smb_io_relstr("name", buffer, depth, &info->name)) + return False; + + return True; +} + +/******************************************************************* + Parse a DRIVER_INFO_2 structure. +********************************************************************/ + +bool smb_io_printer_driver_info_2(const char *desc, RPC_BUFFER *buffer, DRIVER_INFO_2 *info, int depth) +{ + prs_struct *ps=&buffer->prs; + + 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 (!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; + + return True; +} + +/******************************************************************* + Parse a DRIVER_INFO_3 structure. +********************************************************************/ + +bool smb_io_printer_driver_info_3(const char *desc, RPC_BUFFER *buffer, DRIVER_INFO_3 *info, int depth) +{ + prs_struct *ps=&buffer->prs; + + 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 (!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; + + return True; +} + +/******************************************************************* + Parse a DRIVER_INFO_6 structure. +********************************************************************/ + +bool smb_io_printer_driver_info_6(const char *desc, RPC_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_uint64("date", ps, depth, &info->driver_date)) + 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 smb_io_job_info_1(const char *desc, RPC_BUFFER *buffer, JOB_INFO_1 *info, int depth) +{ + prs_struct *ps=&buffer->prs; + + 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 (!smb_io_relstr("printername", buffer, depth, &info->printername)) + return False; + if (!smb_io_relstr("machinename", buffer, depth, &info->machinename)) + return False; + if (!smb_io_relstr("username", buffer, depth, &info->username)) + return False; + if (!smb_io_relstr("document", buffer, depth, &info->document)) + return False; + if (!smb_io_relstr("datatype", buffer, depth, &info->datatype)) + return False; + if (!smb_io_relstr("text_status", buffer, depth, &info->text_status)) + return False; + if (!prs_uint32("status", ps, depth, &info->status)) + return False; + if (!prs_uint32("priority", ps, depth, &info->priority)) + return False; + if (!prs_uint32("position", ps, depth, &info->position)) + return False; + if (!prs_uint32("totalpages", ps, depth, &info->totalpages)) + return False; + if (!prs_uint32("pagesprinted", ps, depth, &info->pagesprinted)) + return False; + if (!spoolss_io_system_time("submitted", ps, depth, &info->submitted)) + return False; + + return True; +} + +/******************************************************************* + Parse a JOB_INFO_2 structure. +********************************************************************/ + +bool smb_io_job_info_2(const char *desc, RPC_BUFFER *buffer, JOB_INFO_2 *info, int depth) +{ + uint32 pipo=0; + prs_struct *ps=&buffer->prs; + + 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 (!smb_io_relstr("printername", buffer, depth, &info->printername)) + return False; + if (!smb_io_relstr("machinename", buffer, depth, &info->machinename)) + return False; + if (!smb_io_relstr("username", buffer, depth, &info->username)) + return False; + if (!smb_io_relstr("document", buffer, depth, &info->document)) + return False; + if (!smb_io_relstr("notifyname", buffer, depth, &info->notifyname)) + return False; + if (!smb_io_relstr("datatype", buffer, depth, &info->datatype)) + return False; + + if (!smb_io_relstr("printprocessor", buffer, depth, &info->printprocessor)) + return False; + if (!smb_io_relstr("parameters", buffer, depth, &info->parameters)) + return False; + if (!smb_io_relstr("drivername", buffer, depth, &info->drivername)) + return False; + if (!smb_io_reldevmode("devmode", buffer, depth, &info->devmode)) + return False; + if (!smb_io_relstr("text_status", buffer, depth, &info->text_status)) + return False; + +/* SEC_DESC sec_desc;*/ + if (!prs_uint32("Hack! sec desc", ps, depth, &pipo)) + return False; + + if (!prs_uint32("status",ps, depth, &info->status)) + return False; + if (!prs_uint32("priority",ps, depth, &info->priority)) + return False; + if (!prs_uint32("position",ps, depth, &info->position)) + return False; + if (!prs_uint32("starttime",ps, depth, &info->starttime)) + return False; + if (!prs_uint32("untiltime",ps, depth, &info->untiltime)) + return False; + if (!prs_uint32("totalpages",ps, depth, &info->totalpages)) + return False; + if (!prs_uint32("size",ps, depth, &info->size)) + return False; + if (!spoolss_io_system_time("submitted", ps, depth, &info->submitted) ) + return False; + if (!prs_uint32("timeelapsed",ps, depth, &info->timeelapsed)) + return False; + if (!prs_uint32("pagesprinted",ps, depth, &info->pagesprinted)) + return False; + + return True; +} + +/******************************************************************* +********************************************************************/ + +bool smb_io_form_1(const char *desc, RPC_BUFFER *buffer, FORM_1 *info, int depth) +{ + prs_struct *ps=&buffer->prs; + + prs_debug(ps, depth, desc, "smb_io_form_1"); + depth++; + + buffer->struct_start=prs_offset(ps); + + if (!prs_uint32("flag", ps, depth, &info->flag)) + return False; + + if (!smb_io_relstr("name", buffer, depth, &info->name)) + return False; + + if (!prs_uint32("width", ps, depth, &info->width)) + return False; + if (!prs_uint32("length", ps, depth, &info->length)) + return False; + if (!prs_uint32("left", ps, depth, &info->left)) + return False; + if (!prs_uint32("top", ps, depth, &info->top)) + return False; + if (!prs_uint32("right", ps, depth, &info->right)) + return False; + if (!prs_uint32("bottom", ps, depth, &info->bottom)) + return False; + + return True; +} + + + +/******************************************************************* + Parse a DRIVER_DIRECTORY_1 structure. +********************************************************************/ + +bool smb_io_driverdir_1(const char *desc, RPC_BUFFER *buffer, DRIVER_DIRECTORY_1 *info, int depth) +{ + prs_struct *ps=&buffer->prs; + + prs_debug(ps, depth, desc, "smb_io_driverdir_1"); + depth++; + + buffer->struct_start=prs_offset(ps); + + if (!smb_io_unistr(desc, &info->name, ps, depth)) + return False; + + return True; +} + +/******************************************************************* + Parse a PORT_INFO_1 structure. +********************************************************************/ + +bool smb_io_port_1(const char *desc, RPC_BUFFER *buffer, PORT_INFO_1 *info, int depth) +{ + prs_struct *ps=&buffer->prs; + + prs_debug(ps, depth, desc, "smb_io_port_1"); + depth++; + + buffer->struct_start=prs_offset(ps); + + if(!smb_io_relstr("port_name", buffer, depth, &info->port_name)) + return False; + + return True; +} + +/******************************************************************* + Parse a PORT_INFO_2 structure. +********************************************************************/ + +bool smb_io_port_2(const char *desc, RPC_BUFFER *buffer, PORT_INFO_2 *info, int depth) +{ + prs_struct *ps=&buffer->prs; + + prs_debug(ps, depth, desc, "smb_io_port_2"); + depth++; + + buffer->struct_start=prs_offset(ps); + + if(!smb_io_relstr("port_name", buffer, depth, &info->port_name)) + return False; + if(!smb_io_relstr("monitor_name", buffer, depth, &info->monitor_name)) + return False; + if(!smb_io_relstr("description", buffer, depth, &info->description)) + return False; + if(!prs_uint32("port_type", ps, depth, &info->port_type)) + return False; + if(!prs_uint32("reserved", ps, depth, &info->reserved)) + return False; + + return True; +} + +/******************************************************************* +********************************************************************/ + +bool smb_io_printprocessor_info_1(const char *desc, RPC_BUFFER *buffer, PRINTPROCESSOR_1 *info, int depth) +{ + prs_struct *ps=&buffer->prs; + + prs_debug(ps, depth, desc, "smb_io_printprocessor_info_1"); + depth++; + + buffer->struct_start=prs_offset(ps); + + if (smb_io_relstr("name", buffer, depth, &info->name)) + return False; + + return True; +} + +/******************************************************************* +********************************************************************/ + +bool smb_io_printprocdatatype_info_1(const char *desc, RPC_BUFFER *buffer, PRINTPROCDATATYPE_1 *info, int depth) +{ + prs_struct *ps=&buffer->prs; + + prs_debug(ps, depth, desc, "smb_io_printprocdatatype_info_1"); + depth++; + + buffer->struct_start=prs_offset(ps); + + if (smb_io_relstr("name", buffer, depth, &info->name)) + return False; + + return True; +} + +/******************************************************************* +********************************************************************/ + +bool smb_io_printmonitor_info_1(const char *desc, RPC_BUFFER *buffer, PRINTMONITOR_1 *info, int depth) +{ + prs_struct *ps=&buffer->prs; + + prs_debug(ps, depth, desc, "smb_io_printmonitor_info_1"); + depth++; + + buffer->struct_start=prs_offset(ps); + + if (!smb_io_relstr("name", buffer, depth, &info->name)) + return False; + + return True; +} + +/******************************************************************* +********************************************************************/ + +bool smb_io_printmonitor_info_2(const char *desc, RPC_BUFFER *buffer, PRINTMONITOR_2 *info, int depth) +{ + prs_struct *ps=&buffer->prs; + + prs_debug(ps, depth, desc, "smb_io_printmonitor_info_2"); + depth++; + + buffer->struct_start=prs_offset(ps); + + if (!smb_io_relstr("name", buffer, depth, &info->name)) + return False; + if (!smb_io_relstr("environment", buffer, depth, &info->environment)) + return False; + if (!smb_io_relstr("dll_name", buffer, depth, &info->dll_name)) + return False; + + return True; +} + +/******************************************************************* +return the size required by a struct in the stream +********************************************************************/ + +uint32 spoolss_size_printer_info_0(PRINTER_INFO_0 *info) +{ + int size=0; + + size+=size_of_relative_string( &info->printername ); + size+=size_of_relative_string( &info->servername ); + + size+=size_of_uint32( &info->cjobs); + size+=size_of_uint32( &info->total_jobs); + size+=size_of_uint32( &info->total_bytes); + + size+=size_of_uint16( &info->year); + size+=size_of_uint16( &info->month); + size+=size_of_uint16( &info->dayofweek); + size+=size_of_uint16( &info->day); + size+=size_of_uint16( &info->hour); + size+=size_of_uint16( &info->minute); + size+=size_of_uint16( &info->second); + size+=size_of_uint16( &info->milliseconds); + + size+=size_of_uint32( &info->global_counter); + size+=size_of_uint32( &info->total_pages); + + size+=size_of_uint16( &info->major_version); + size+=size_of_uint16( &info->build_version); + + size+=size_of_uint32( &info->unknown7); + size+=size_of_uint32( &info->unknown8); + size+=size_of_uint32( &info->unknown9); + size+=size_of_uint32( &info->session_counter); + size+=size_of_uint32( &info->unknown11); + size+=size_of_uint32( &info->printer_errors); + size+=size_of_uint32( &info->unknown13); + size+=size_of_uint32( &info->unknown14); + size+=size_of_uint32( &info->unknown15); + size+=size_of_uint32( &info->unknown16); + size+=size_of_uint32( &info->change_id); + size+=size_of_uint32( &info->unknown18); + size+=size_of_uint32( &info->status); + size+=size_of_uint32( &info->unknown20); + size+=size_of_uint32( &info->c_setprinter); + + size+=size_of_uint16( &info->unknown22); + size+=size_of_uint16( &info->unknown23); + size+=size_of_uint16( &info->unknown24); + size+=size_of_uint16( &info->unknown25); + size+=size_of_uint16( &info->unknown26); + size+=size_of_uint16( &info->unknown27); + size+=size_of_uint16( &info->unknown28); + size+=size_of_uint16( &info->unknown29); + + return size; +} + +/******************************************************************* +return the size required by a struct in the stream +********************************************************************/ + +uint32 spoolss_size_printer_info_1(PRINTER_INFO_1 *info) +{ + int size=0; + + size+=size_of_uint32( &info->flags ); + size+=size_of_relative_string( &info->description ); + size+=size_of_relative_string( &info->name ); + size+=size_of_relative_string( &info->comment ); + + return size; +} + +/******************************************************************* +return the size required by a struct in the stream +********************************************************************/ + +uint32 spoolss_size_printer_info_2(PRINTER_INFO_2 *info) +{ + uint32 size=0; + + size += 4; + + size += ndr_size_security_descriptor( info->secdesc, 0 ); + + size+=size_of_device_mode( info->devmode ); + + size+=size_of_relative_string( &info->servername ); + size+=size_of_relative_string( &info->printername ); + size+=size_of_relative_string( &info->sharename ); + size+=size_of_relative_string( &info->portname ); + size+=size_of_relative_string( &info->drivername ); + size+=size_of_relative_string( &info->comment ); + size+=size_of_relative_string( &info->location ); + + size+=size_of_relative_string( &info->sepfile ); + size+=size_of_relative_string( &info->printprocessor ); + size+=size_of_relative_string( &info->datatype ); + size+=size_of_relative_string( &info->parameters ); + + size+=size_of_uint32( &info->attributes ); + size+=size_of_uint32( &info->priority ); + size+=size_of_uint32( &info->defaultpriority ); + size+=size_of_uint32( &info->starttime ); + size+=size_of_uint32( &info->untiltime ); + size+=size_of_uint32( &info->status ); + size+=size_of_uint32( &info->cjobs ); + size+=size_of_uint32( &info->averageppm ); + + /* + * add any adjustments for alignment. This is + * not optimal since we could be calling this + * function from a loop (e.g. enumprinters), but + * it is easier to maintain the calculation here and + * not place the burden on the caller to remember. --jerry + */ + if ((size % 4) != 0) + size += 4 - (size % 4); + + return size; +} + +/******************************************************************* +return the size required by a struct in the stream +********************************************************************/ + +uint32 spoolss_size_printer_info_4(PRINTER_INFO_4 *info) +{ + uint32 size=0; + + size+=size_of_relative_string( &info->printername ); + size+=size_of_relative_string( &info->servername ); + + size+=size_of_uint32( &info->attributes ); + return size; +} + +/******************************************************************* +return the size required by a struct in the stream +********************************************************************/ + +uint32 spoolss_size_printer_info_5(PRINTER_INFO_5 *info) +{ + uint32 size=0; + + size+=size_of_relative_string( &info->printername ); + size+=size_of_relative_string( &info->portname ); + + size+=size_of_uint32( &info->attributes ); + size+=size_of_uint32( &info->device_not_selected_timeout ); + size+=size_of_uint32( &info->transmission_retry_timeout ); + return size; +} + +/******************************************************************* +return the size required by a struct in the stream +********************************************************************/ + +uint32 spoolss_size_printer_info_6(PRINTER_INFO_6 *info) +{ + return sizeof(uint32); +} + +/******************************************************************* +return the size required by a struct in the stream +********************************************************************/ + +uint32 spoolss_size_printer_info_3(PRINTER_INFO_3 *info) +{ + /* The 8 is for the self relative pointer - 8 byte aligned.. */ + return 8 + (uint32)ndr_size_security_descriptor( info->secdesc, 0 ); +} + +/******************************************************************* +return the size required by a struct in the stream +********************************************************************/ + +uint32 spoolss_size_printer_info_7(PRINTER_INFO_7 *info) +{ + uint32 size=0; + + size+=size_of_relative_string( &info->guid ); + size+=size_of_uint32( &info->action ); + return size; +} + +/******************************************************************* +return the size required by a struct in the stream +********************************************************************/ + +uint32 spoolss_size_printer_driver_info_1(DRIVER_INFO_1 *info) +{ + int size=0; + size+=size_of_relative_string( &info->name ); + + return size; +} + +/******************************************************************* +return the size required by a struct in the stream +********************************************************************/ + +uint32 spoolss_size_printer_driver_info_2(DRIVER_INFO_2 *info) +{ + int 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 ); + + 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; + + 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+=size_of_relative_string( &info->monitorname ); + size+=size_of_relative_string( &info->defaultdatatype ); + + size+=spoolss_size_string_array(info->dependentfiles); + + 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+=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; +} + +/******************************************************************* +return the size required by a struct in the stream +********************************************************************/ + +uint32 spoolss_size_job_info_1(JOB_INFO_1 *info) +{ + int size=0; + size+=size_of_uint32( &info->jobid ); + size+=size_of_relative_string( &info->printername ); + size+=size_of_relative_string( &info->machinename ); + size+=size_of_relative_string( &info->username ); + size+=size_of_relative_string( &info->document ); + size+=size_of_relative_string( &info->datatype ); + size+=size_of_relative_string( &info->text_status ); + size+=size_of_uint32( &info->status ); + size+=size_of_uint32( &info->priority ); + size+=size_of_uint32( &info->position ); + size+=size_of_uint32( &info->totalpages ); + size+=size_of_uint32( &info->pagesprinted ); + size+=size_of_systemtime( &info->submitted ); + + return size; +} + +/******************************************************************* +return the size required by a struct in the stream +********************************************************************/ + +uint32 spoolss_size_job_info_2(JOB_INFO_2 *info) +{ + int size=0; + + size+=4; /* size of sec desc ptr */ + + size+=size_of_uint32( &info->jobid ); + size+=size_of_relative_string( &info->printername ); + size+=size_of_relative_string( &info->machinename ); + size+=size_of_relative_string( &info->username ); + size+=size_of_relative_string( &info->document ); + size+=size_of_relative_string( &info->notifyname ); + size+=size_of_relative_string( &info->datatype ); + size+=size_of_relative_string( &info->printprocessor ); + size+=size_of_relative_string( &info->parameters ); + size+=size_of_relative_string( &info->drivername ); + size+=size_of_device_mode( info->devmode ); + size+=size_of_relative_string( &info->text_status ); +/* SEC_DESC sec_desc;*/ + size+=size_of_uint32( &info->status ); + size+=size_of_uint32( &info->priority ); + size+=size_of_uint32( &info->position ); + size+=size_of_uint32( &info->starttime ); + size+=size_of_uint32( &info->untiltime ); + size+=size_of_uint32( &info->totalpages ); + size+=size_of_uint32( &info->size ); + size+=size_of_systemtime( &info->submitted ); + size+=size_of_uint32( &info->timeelapsed ); + size+=size_of_uint32( &info->pagesprinted ); + + return size; +} + +/******************************************************************* +return the size required by a struct in the stream +********************************************************************/ + +uint32 spoolss_size_form_1(FORM_1 *info) +{ + int size=0; + + size+=size_of_uint32( &info->flag ); + size+=size_of_relative_string( &info->name ); + size+=size_of_uint32( &info->width ); + size+=size_of_uint32( &info->length ); + size+=size_of_uint32( &info->left ); + size+=size_of_uint32( &info->top ); + size+=size_of_uint32( &info->right ); + size+=size_of_uint32( &info->bottom ); + + return size; +} + +/******************************************************************* +return the size required by a struct in the stream +********************************************************************/ + +uint32 spoolss_size_port_info_1(PORT_INFO_1 *info) +{ + int size=0; + + size+=size_of_relative_string( &info->port_name ); + + return size; +} + +/******************************************************************* +return the size required by a struct in the stream +********************************************************************/ + +uint32 spoolss_size_driverdir_info_1(DRIVER_DIRECTORY_1 *info) +{ + int size=0; + + size=str_len_uni(&info->name); /* the string length */ + size=size+1; /* add the leading zero */ + size=size*2; /* convert in char */ + + return size; +} + +/******************************************************************* +return the size required by a struct in the stream +********************************************************************/ + +uint32 spoolss_size_printprocessordirectory_info_1(PRINTPROCESSOR_DIRECTORY_1 *info) +{ + int size=0; + + size=str_len_uni(&info->name); /* the string length */ + size=size+1; /* add the leading zero */ + size=size*2; /* convert in char */ + + return size; +} + +/******************************************************************* +return the size required by a struct in the stream +********************************************************************/ + +uint32 spoolss_size_port_info_2(PORT_INFO_2 *info) +{ + int size=0; + + size+=size_of_relative_string( &info->port_name ); + size+=size_of_relative_string( &info->monitor_name ); + size+=size_of_relative_string( &info->description ); + + size+=size_of_uint32( &info->port_type ); + size+=size_of_uint32( &info->reserved ); + + return size; +} + +/******************************************************************* +return the size required by a struct in the stream +********************************************************************/ + +uint32 spoolss_size_printprocessor_info_1(PRINTPROCESSOR_1 *info) +{ + int size=0; + size+=size_of_relative_string( &info->name ); + + return size; +} + +/******************************************************************* +return the size required by a struct in the stream +********************************************************************/ + +uint32 spoolss_size_printprocdatatype_info_1(PRINTPROCDATATYPE_1 *info) +{ + int size=0; + size+=size_of_relative_string( &info->name ); + + return size; +} + +/******************************************************************* +return the size required by a struct in the stream +********************************************************************/ +uint32 spoolss_size_printer_enum_values(PRINTER_ENUM_VALUES *p) +{ + uint32 size = 0; + + if (!p) + return 0; + + /* uint32(offset) + uint32(length) + length) */ + size += (size_of_uint32(&p->value_len)*2) + p->value_len; + size += (size_of_uint32(&p->data_len)*2) + p->data_len + (p->data_len%2) ; + + size += size_of_uint32(&p->type); + + return size; +} + +/******************************************************************* +return the size required by a struct in the stream +********************************************************************/ + +uint32 spoolss_size_printmonitor_info_1(PRINTMONITOR_1 *info) +{ + int size=0; + size+=size_of_relative_string( &info->name ); + + return size; +} + +/******************************************************************* +return the size required by a struct in the stream +********************************************************************/ + +uint32 spoolss_size_printmonitor_info_2(PRINTMONITOR_2 *info) +{ + int size=0; + size+=size_of_relative_string( &info->name); + size+=size_of_relative_string( &info->environment); + size+=size_of_relative_string( &info->dll_name); + + return size; +} + +/******************************************************************* + * init a structure. + ********************************************************************/ + +bool make_spoolss_q_getprinterdriver2(SPOOL_Q_GETPRINTERDRIVER2 *q_u, + const POLICY_HND *hnd, + const fstring architecture, + uint32 level, uint32 clientmajor, uint32 clientminor, + RPC_BUFFER *buffer, uint32 offered) +{ + if (q_u == NULL) + return False; + + memcpy(&q_u->handle, hnd, sizeof(q_u->handle)); + + init_buf_unistr2(&q_u->architecture, &q_u->architecture_ptr, architecture); + + q_u->level=level; + q_u->clientmajorversion=clientmajor; + q_u->clientminorversion=clientminor; + + q_u->buffer=buffer; + q_u->offered=offered; + + return True; +} + +/******************************************************************* + * read a structure. + * called from spoolss_getprinterdriver2 (srv_spoolss.c) + ********************************************************************/ + +bool spoolss_io_q_getprinterdriver2(const char *desc, SPOOL_Q_GETPRINTERDRIVER2 *q_u, prs_struct *ps, int depth) +{ + prs_debug(ps, depth, desc, "spoolss_io_q_getprinterdriver2"); + depth++; + + if(!prs_align(ps)) + return False; + + if(!smb_io_pol_hnd("printer handle", &q_u->handle, ps, depth)) + return False; + if(!prs_uint32("architecture_ptr", ps, depth, &q_u->architecture_ptr)) + return False; + if(!smb_io_unistr2("architecture", &q_u->architecture, q_u->architecture_ptr, ps, depth)) + return False; + + if(!prs_align(ps)) + return False; + if(!prs_uint32("level", ps, depth, &q_u->level)) + return False; + + if(!prs_rpcbuffer_p("", ps, depth, &q_u->buffer)) + return False; + + if(!prs_align(ps)) + return False; + + if(!prs_uint32("offered", ps, depth, &q_u->offered)) + return False; + + if(!prs_uint32("clientmajorversion", ps, depth, &q_u->clientmajorversion)) + return False; + if(!prs_uint32("clientminorversion", ps, depth, &q_u->clientminorversion)) + return False; + + return True; +} + +/******************************************************************* + * read a structure. + * called from spoolss_getprinterdriver2 (srv_spoolss.c) + ********************************************************************/ + +bool spoolss_io_r_getprinterdriver2(const char *desc, SPOOL_R_GETPRINTERDRIVER2 *r_u, prs_struct *ps, int depth) +{ + prs_debug(ps, depth, desc, "spoolss_io_r_getprinterdriver2"); + depth++; + + if (!prs_align(ps)) + return False; + + if (!prs_rpcbuffer_p("", 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("servermajorversion", ps, depth, &r_u->servermajorversion)) + return False; + if (!prs_uint32("serverminorversion", ps, depth, &r_u->serverminorversion)) + return False; + if (!prs_werror("status", ps, depth, &r_u->status)) + return False; + + return True; +} + +/******************************************************************* + * init a structure. + ********************************************************************/ + +bool make_spoolss_q_enumprinters( + SPOOL_Q_ENUMPRINTERS *q_u, + uint32 flags, + char *servername, + uint32 level, + RPC_BUFFER *buffer, + uint32 offered +) +{ + q_u->flags=flags; + + q_u->servername_ptr = (servername != NULL) ? 1 : 0; + init_buf_unistr2(&q_u->servername, &q_u->servername_ptr, servername); + + q_u->level=level; + q_u->buffer=buffer; + q_u->offered=offered; + + return True; +} + +/******************************************************************* + * init a structure. + ********************************************************************/ + +bool make_spoolss_q_enumports(SPOOL_Q_ENUMPORTS *q_u, + fstring servername, uint32 level, + RPC_BUFFER *buffer, uint32 offered) +{ + q_u->name_ptr = (servername != NULL) ? 1 : 0; + init_buf_unistr2(&q_u->name, &q_u->name_ptr, servername); + + q_u->level=level; + q_u->buffer=buffer; + q_u->offered=offered; + + return True; +} + +/******************************************************************* + * read a structure. + * called from spoolss_enumprinters (srv_spoolss.c) + ********************************************************************/ + +bool spoolss_io_q_enumprinters(const char *desc, SPOOL_Q_ENUMPRINTERS *q_u, prs_struct *ps, int depth) +{ + prs_debug(ps, depth, desc, "spoolss_io_q_enumprinters"); + depth++; + + if (!prs_align(ps)) + return False; + + if (!prs_uint32("flags", ps, depth, &q_u->flags)) + return False; + if (!prs_uint32("servername_ptr", ps, depth, &q_u->servername_ptr)) + return False; + + if (!smb_io_unistr2("", &q_u->servername, q_u->servername_ptr, ps, depth)) + return False; + + if (!prs_align(ps)) + return False; + if (!prs_uint32("level", ps, depth, &q_u->level)) + return False; + + if (!prs_rpcbuffer_p("", 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; +} + +/******************************************************************* + Parse a SPOOL_R_ENUMPRINTERS structure. + ********************************************************************/ + +bool spoolss_io_r_enumprinters(const char *desc, SPOOL_R_ENUMPRINTERS *r_u, prs_struct *ps, int depth) +{ + prs_debug(ps, depth, desc, "spoolss_io_r_enumprinters"); + depth++; + + if (!prs_align(ps)) + return False; + + if (!prs_rpcbuffer_p("", 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("returned", ps, depth, &r_u->returned)) + return False; + + if (!prs_werror("status", ps, depth, &r_u->status)) + return False; + + return True; +} + +/******************************************************************* + * write a structure. + * called from spoolss_r_enum_printers (srv_spoolss.c) + * + ********************************************************************/ + +bool spoolss_io_r_getprinter(const char *desc, SPOOL_R_GETPRINTER *r_u, prs_struct *ps, int depth) +{ + prs_debug(ps, depth, desc, "spoolss_io_r_getprinter"); + depth++; + + if (!prs_align(ps)) + return False; + + if (!prs_rpcbuffer_p("", 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_werror("status", ps, depth, &r_u->status)) + return False; + + return True; +} + +/******************************************************************* + * read a structure. + * called from spoolss_getprinter (srv_spoolss.c) + ********************************************************************/ + +bool spoolss_io_q_getprinter(const char *desc, SPOOL_Q_GETPRINTER *q_u, prs_struct *ps, int depth) +{ + prs_debug(ps, depth, desc, "spoolss_io_q_getprinter"); + depth++; + + if (!prs_align(ps)) + return False; + + if(!smb_io_pol_hnd("printer handle", &q_u->handle, ps, depth)) + return False; + if (!prs_uint32("level", ps, depth, &q_u->level)) + return False; + + if (!prs_rpcbuffer_p("", 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; +} + +/******************************************************************* + * init a structure. + ********************************************************************/ + +bool make_spoolss_q_getprinter( + TALLOC_CTX *mem_ctx, + SPOOL_Q_GETPRINTER *q_u, + const POLICY_HND *hnd, + uint32 level, + RPC_BUFFER *buffer, + uint32 offered +) +{ + if (q_u == NULL) + { + return False; + } + memcpy(&q_u->handle, hnd, sizeof(q_u->handle)); + + q_u->level=level; + q_u->buffer=buffer; + q_u->offered=offered; + + return True; +} + +/******************************************************************* + * 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 (!q_u || !info) + return False; + + memcpy(&q_u->handle, hnd, sizeof(q_u->handle)); + + q_u->level = level; + q_u->info.level = level; + q_u->info.info_ptr = 1; /* Info is != NULL, see above */ + switch (level) { + + /* There's no such thing as a setprinter level 1 */ + + case 2: + secdesc = info->printers_2->secdesc; + devmode = info->printers_2->devmode; + + make_spoolss_printer_info_2 (mem_ctx, &q_u->info.info_2, info->printers_2); +#if 1 /* JERRY TEST */ + q_u->secdesc_ctr = SMB_MALLOC_P(SEC_DESC_BUF); + if (!q_u->secdesc_ctr) + return False; + q_u->secdesc_ctr->sd = secdesc; + q_u->secdesc_ctr->sd_size = (secdesc) ? sizeof(SEC_DESC) + (2*sizeof(uint32)) : 0; + + q_u->devmode_ctr.devmode_ptr = (devmode != NULL) ? 1 : 0; + q_u->devmode_ctr.size = (devmode != NULL) ? sizeof(DEVICEMODE) + (3*sizeof(uint32)) : 0; + 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; + case 3: + secdesc = info->printers_3->secdesc; + + make_spoolss_printer_info_3 (mem_ctx, &q_u->info.info_3, info->printers_3); + + q_u->secdesc_ctr = SMB_MALLOC_P(SEC_DESC_BUF); + if (!q_u->secdesc_ctr) + return False; + q_u->secdesc_ctr->sd_size = (secdesc) ? sizeof(SEC_DESC) + (2*sizeof(uint32)) : 0; + q_u->secdesc_ctr->sd = secdesc; + + break; + case 7: + make_spoolss_printer_info_7 (mem_ctx, &q_u->info.info_7, info->printers_7); + 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(const 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_werror("status", ps, depth, &r_u->status)) + return False; + + return True; +} + +/******************************************************************* + Marshall/unmarshall a SPOOL_Q_SETPRINTER struct. +********************************************************************/ + +bool spoolss_io_q_setprinter(const char *desc, SPOOL_Q_SETPRINTER *q_u, prs_struct *ps, int depth) +{ + uint32 ptr_sec_desc = 0; + + prs_debug(ps, depth, desc, "spoolss_io_q_setprinter"); + depth++; + + if(!prs_align(ps)) + return False; + + if(!smb_io_pol_hnd("printer handle", &q_u->handle ,ps, depth)) + return False; + if(!prs_uint32("level", ps, depth, &q_u->level)) + return False; + + /* check for supported levels and structures we know about */ + + switch ( q_u->level ) { + case 0: + case 2: + case 3: + case 7: + /* supported levels */ + break; + default: + DEBUG(0,("spoolss_io_q_setprinter: unsupported printer info level [%d]\n", + q_u->level)); + return True; + } + + + if(!spool_io_printer_info_level("", &q_u->info, ps, depth)) + return False; + + if (!spoolss_io_devmode_cont(desc, &q_u->devmode_ctr, ps, depth)) + return False; + + if(!prs_align(ps)) + return False; + + switch (q_u->level) + { + case 2: + { + ptr_sec_desc = q_u->info.info_2->secdesc_ptr; + break; + } + case 3: + { + /* FIXME ! Our parsing here is wrong I think, + * but for a level3 it makes no sense for + * ptr_sec_desc to be NULL. JRA. Based on + * a Vista sniff from Martin Zielinski <mz@seh.de>. + */ + if (UNMARSHALLING(ps)) { + ptr_sec_desc = 1; + } else { + ptr_sec_desc = q_u->info.info_3->secdesc_ptr; + } + break; + } + } + if (ptr_sec_desc) + { + if (!sec_io_desc_buf(desc, &q_u->secdesc_ctr, ps, depth)) + return False; + } else { + uint32 dummy = 0; + + /* 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)) + return False; + + return True; +} + +/******************************************************************* +********************************************************************/ + +bool spoolss_io_r_fcpn(const char *desc, SPOOL_R_FCPN *r_u, prs_struct *ps, int depth) +{ + prs_debug(ps, depth, desc, "spoolss_io_r_fcpn"); + depth++; + + if(!prs_align(ps)) + return False; + + if(!prs_werror("status", ps, depth, &r_u->status)) + return False; + + return True; +} + +/******************************************************************* +********************************************************************/ + +bool spoolss_io_q_fcpn(const char *desc, SPOOL_Q_FCPN *q_u, prs_struct *ps, int depth) +{ + + prs_debug(ps, depth, desc, "spoolss_io_q_fcpn"); + depth++; + + if(!prs_align(ps)) + return False; + + if(!smb_io_pol_hnd("printer handle",&q_u->handle,ps,depth)) + return False; + + return True; +} + + +/******************************************************************* +********************************************************************/ + +bool spoolss_io_r_addjob(const char *desc, SPOOL_R_ADDJOB *r_u, prs_struct *ps, int depth) +{ + prs_debug(ps, depth, desc, ""); + depth++; + + if(!prs_align(ps)) + return False; + + if(!prs_rpcbuffer_p("", 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_werror("status", ps, depth, &r_u->status)) + return False; + + return True; +} + +/******************************************************************* +********************************************************************/ + +bool spoolss_io_q_addjob(const char *desc, SPOOL_Q_ADDJOB *q_u, prs_struct *ps, int depth) +{ + prs_debug(ps, depth, desc, ""); + depth++; + + if(!prs_align(ps)) + return False; + + if(!smb_io_pol_hnd("printer handle", &q_u->handle, ps, depth)) + return False; + if(!prs_uint32("level", ps, depth, &q_u->level)) + return False; + + if(!prs_rpcbuffer_p("", 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_enumjobs(const char *desc, SPOOL_R_ENUMJOBS *r_u, prs_struct *ps, int depth) +{ + prs_debug(ps, depth, desc, "spoolss_io_r_enumjobs"); + depth++; + + if (!prs_align(ps)) + return False; + + if (!prs_rpcbuffer_p("", 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("returned", ps, depth, &r_u->returned)) + return False; + + if (!prs_werror("status", ps, depth, &r_u->status)) + return False; + + return True; +} + +/******************************************************************* +********************************************************************/ + +bool make_spoolss_q_enumjobs(SPOOL_Q_ENUMJOBS *q_u, const POLICY_HND *hnd, + uint32 firstjob, + uint32 numofjobs, + uint32 level, + RPC_BUFFER *buffer, + uint32 offered) +{ + if (q_u == NULL) + { + return False; + } + memcpy(&q_u->handle, hnd, sizeof(q_u->handle)); + q_u->firstjob = firstjob; + q_u->numofjobs = numofjobs; + q_u->level = level; + q_u->buffer= buffer; + q_u->offered = offered; + return True; +} + +/******************************************************************* +********************************************************************/ + +bool spoolss_io_q_enumjobs(const char *desc, SPOOL_Q_ENUMJOBS *q_u, prs_struct *ps, int depth) +{ + prs_debug(ps, depth, desc, "spoolss_io_q_enumjobs"); + depth++; + + if (!prs_align(ps)) + return False; + + if (!smb_io_pol_hnd("printer handle",&q_u->handle, ps, depth)) + return False; + + if (!prs_uint32("firstjob", ps, depth, &q_u->firstjob)) + return False; + if (!prs_uint32("numofjobs", ps, depth, &q_u->numofjobs)) + return False; + if (!prs_uint32("level", ps, depth, &q_u->level)) + return False; + + if (!prs_rpcbuffer_p("", 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_schedulejob(const char *desc, SPOOL_R_SCHEDULEJOB *r_u, prs_struct *ps, int depth) +{ + prs_debug(ps, depth, desc, "spoolss_io_r_schedulejob"); + depth++; + + if(!prs_align(ps)) + return False; + + if(!prs_werror("status", ps, depth, &r_u->status)) + return False; + + return True; +} + +/******************************************************************* +********************************************************************/ + +bool spoolss_io_q_schedulejob(const char *desc, SPOOL_Q_SCHEDULEJOB *q_u, prs_struct *ps, int depth) +{ + prs_debug(ps, depth, desc, "spoolss_io_q_schedulejob"); + depth++; + + if(!prs_align(ps)) + return False; + + if(!smb_io_pol_hnd("printer handle",&q_u->handle,ps,depth)) + return False; + if(!prs_uint32("jobid", ps, depth, &q_u->jobid)) + return False; + + return True; +} + +/******************************************************************* +********************************************************************/ + +bool spoolss_io_r_setjob(const char *desc, SPOOL_R_SETJOB *r_u, prs_struct *ps, int depth) +{ + prs_debug(ps, depth, desc, "spoolss_io_r_setjob"); + depth++; + + if(!prs_align(ps)) + return False; + + if(!prs_werror("status", ps, depth, &r_u->status)) + return False; + + return True; +} + +/******************************************************************* +********************************************************************/ + +bool spoolss_io_q_setjob(const char *desc, SPOOL_Q_SETJOB *q_u, prs_struct *ps, int depth) +{ + prs_debug(ps, depth, desc, "spoolss_io_q_setjob"); + depth++; + + if(!prs_align(ps)) + return False; + + if(!smb_io_pol_hnd("printer handle",&q_u->handle,ps,depth)) + return False; + if(!prs_uint32("jobid", ps, depth, &q_u->jobid)) + return False; + /* + * level is usually 0. If (level!=0) then I'm in trouble ! + * I will try to generate setjob command with level!=0, one day. + */ + if(!prs_uint32("level", ps, depth, &q_u->level)) + return False; + if(!prs_uint32("command", ps, depth, &q_u->command)) + return False; + + return True; +} + +/******************************************************************* + Parse a SPOOL_R_ENUMPRINTERDRIVERS structure. +********************************************************************/ + +bool spoolss_io_r_enumprinterdrivers(const char *desc, SPOOL_R_ENUMPRINTERDRIVERS *r_u, prs_struct *ps, int depth) +{ + prs_debug(ps, depth, desc, "spoolss_io_r_enumprinterdrivers"); + depth++; + + if (!prs_align(ps)) + return False; + + if (!prs_rpcbuffer_p("", 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("returned", ps, depth, &r_u->returned)) + return False; + + if (!prs_werror("status", ps, depth, &r_u->status)) + return False; + + return True; +} + +/******************************************************************* + * init a structure. + ********************************************************************/ + +bool make_spoolss_q_enumprinterdrivers(SPOOL_Q_ENUMPRINTERDRIVERS *q_u, + const char *name, + const char *environment, + uint32 level, + RPC_BUFFER *buffer, uint32 offered) +{ + init_buf_unistr2(&q_u->name, &q_u->name_ptr, name); + init_buf_unistr2(&q_u->environment, &q_u->environment_ptr, environment); + + q_u->level=level; + q_u->buffer=buffer; + q_u->offered=offered; + + return True; +} + +/******************************************************************* + Parse a SPOOL_Q_ENUMPRINTERDRIVERS structure. +********************************************************************/ + +bool spoolss_io_q_enumprinterdrivers(const char *desc, SPOOL_Q_ENUMPRINTERDRIVERS *q_u, prs_struct *ps, int depth) +{ + + prs_debug(ps, depth, desc, "spoolss_io_q_enumprinterdrivers"); + depth++; + + if (!prs_align(ps)) + return False; + + if (!prs_uint32("name_ptr", ps, depth, &q_u->name_ptr)) + return False; + if (!smb_io_unistr2("", &q_u->name, q_u->name_ptr,ps, depth)) + return False; + + if (!prs_align(ps)) + return False; + if (!prs_uint32("environment_ptr", ps, depth, &q_u->environment_ptr)) + return False; + if (!smb_io_unistr2("", &q_u->environment, q_u->environment_ptr, ps, depth)) + return False; + + if (!prs_align(ps)) + return False; + if (!prs_uint32("level", ps, depth, &q_u->level)) + return False; + + if (!prs_rpcbuffer_p("", 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_q_enumforms(const char *desc, SPOOL_Q_ENUMFORMS *q_u, prs_struct *ps, int depth) +{ + + prs_debug(ps, depth, desc, "spoolss_io_q_enumforms"); + depth++; + + if (!prs_align(ps)) + return False; + if (!smb_io_pol_hnd("printer handle",&q_u->handle,ps,depth)) + return False; + if (!prs_uint32("level", ps, depth, &q_u->level)) + return False; + + if (!prs_rpcbuffer_p("", 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_enumforms(const char *desc, SPOOL_R_ENUMFORMS *r_u, prs_struct *ps, int depth) +{ + prs_debug(ps, depth, desc, "spoolss_io_r_enumforms"); + depth++; + + if (!prs_align(ps)) + return False; + + if (!prs_rpcbuffer_p("", 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("numofforms", ps, depth, &r_u->numofforms)) + return False; + + if (!prs_werror("status", ps, depth, &r_u->status)) + return False; + + return True; +} + +/******************************************************************* +********************************************************************/ + +bool spoolss_io_q_getform(const 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 (!prs_rpcbuffer_p("", 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(const 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 (!prs_rpcbuffer_p("", 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_werror("status", ps, depth, &r_u->status)) + return False; + + return True; +} + +/******************************************************************* + Parse a SPOOL_R_ENUMPORTS structure. +********************************************************************/ + +bool spoolss_io_r_enumports(const char *desc, SPOOL_R_ENUMPORTS *r_u, prs_struct *ps, int depth) +{ + prs_debug(ps, depth, desc, "spoolss_io_r_enumports"); + depth++; + + if (!prs_align(ps)) + return False; + + if (!prs_rpcbuffer_p("", 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("returned", ps, depth, &r_u->returned)) + return False; + + if (!prs_werror("status", ps, depth, &r_u->status)) + return False; + + return True; +} + +/******************************************************************* +********************************************************************/ + +bool spoolss_io_q_enumports(const char *desc, SPOOL_Q_ENUMPORTS *q_u, prs_struct *ps, int depth) +{ + prs_debug(ps, depth, desc, ""); + depth++; + + if (!prs_align(ps)) + return False; + + if (!prs_uint32("", ps, depth, &q_u->name_ptr)) + return False; + if (!smb_io_unistr2("", &q_u->name,True,ps,depth)) + return False; + + if (!prs_align(ps)) + return False; + if (!prs_uint32("level", ps, depth, &q_u->level)) + return False; + + if (!prs_rpcbuffer_p("", 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; +} + +/******************************************************************* + Parse a SPOOL_PRINTER_INFO_LEVEL_1 structure. +********************************************************************/ + +bool spool_io_printer_info_level_1(const char *desc, SPOOL_PRINTER_INFO_LEVEL_1 *il, prs_struct *ps, int depth) +{ + prs_debug(ps, depth, desc, "spool_io_printer_info_level_1"); + depth++; + + if(!prs_align(ps)) + return False; + + if(!prs_uint32("flags", ps, depth, &il->flags)) + return False; + if(!prs_uint32("description_ptr", ps, depth, &il->description_ptr)) + return False; + if(!prs_uint32("name_ptr", ps, depth, &il->name_ptr)) + return False; + if(!prs_uint32("comment_ptr", ps, depth, &il->comment_ptr)) + return False; + + if(!smb_io_unistr2("description", &il->description, il->description_ptr, ps, depth)) + return False; + if(!smb_io_unistr2("name", &il->name, il->name_ptr, ps, depth)) + return False; + if(!smb_io_unistr2("comment", &il->comment, il->comment_ptr, ps, depth)) + return False; + + return True; +} + +/******************************************************************* + Parse a SPOOL_PRINTER_INFO_LEVEL_3 structure. +********************************************************************/ + +bool spool_io_printer_info_level_3(const char *desc, SPOOL_PRINTER_INFO_LEVEL_3 *il, prs_struct *ps, int depth) +{ + prs_debug(ps, depth, desc, "spool_io_printer_info_level_3"); + depth++; + + if(!prs_align(ps)) + return False; + + if(!prs_uint32("secdesc_ptr", ps, depth, &il->secdesc_ptr)) + return False; + + return True; +} + +/******************************************************************* + Parse a SPOOL_PRINTER_INFO_LEVEL_2 structure. +********************************************************************/ + +bool spool_io_printer_info_level_2(const char *desc, SPOOL_PRINTER_INFO_LEVEL_2 *il, prs_struct *ps, int depth) +{ + prs_debug(ps, depth, desc, "spool_io_printer_info_level_2"); + depth++; + + if(!prs_align(ps)) + return False; + + if(!prs_uint32("servername_ptr", ps, depth, &il->servername_ptr)) + return False; + if(!prs_uint32("printername_ptr", ps, depth, &il->printername_ptr)) + return False; + if(!prs_uint32("sharename_ptr", ps, depth, &il->sharename_ptr)) + return False; + if(!prs_uint32("portname_ptr", ps, depth, &il->portname_ptr)) + return False; + + if(!prs_uint32("drivername_ptr", ps, depth, &il->drivername_ptr)) + return False; + if(!prs_uint32("comment_ptr", ps, depth, &il->comment_ptr)) + return False; + if(!prs_uint32("location_ptr", ps, depth, &il->location_ptr)) + return False; + if(!prs_uint32("devmode_ptr", ps, depth, &il->devmode_ptr)) + return False; + if(!prs_uint32("sepfile_ptr", ps, depth, &il->sepfile_ptr)) + return False; + if(!prs_uint32("printprocessor_ptr", ps, depth, &il->printprocessor_ptr)) + return False; + if(!prs_uint32("datatype_ptr", ps, depth, &il->datatype_ptr)) + return False; + if(!prs_uint32("parameters_ptr", ps, depth, &il->parameters_ptr)) + return False; + if(!prs_uint32("secdesc_ptr", ps, depth, &il->secdesc_ptr)) + return False; + + if(!prs_uint32("attributes", ps, depth, &il->attributes)) + return False; + if(!prs_uint32("priority", ps, depth, &il->priority)) + return False; + if(!prs_uint32("default_priority", ps, depth, &il->default_priority)) + return False; + if(!prs_uint32("starttime", ps, depth, &il->starttime)) + return False; + if(!prs_uint32("untiltime", ps, depth, &il->untiltime)) + return False; + if(!prs_uint32("status", ps, depth, &il->status)) + return False; + if(!prs_uint32("cjobs", ps, depth, &il->cjobs)) + return False; + if(!prs_uint32("averageppm", ps, depth, &il->averageppm)) + return False; + + if(!smb_io_unistr2("servername", &il->servername, il->servername_ptr, ps, depth)) + return False; + if(!smb_io_unistr2("printername", &il->printername, il->printername_ptr, ps, depth)) + return False; + if(!smb_io_unistr2("sharename", &il->sharename, il->sharename_ptr, ps, depth)) + return False; + if(!smb_io_unistr2("portname", &il->portname, il->portname_ptr, ps, depth)) + return False; + if(!smb_io_unistr2("drivername", &il->drivername, il->drivername_ptr, ps, depth)) + return False; + if(!smb_io_unistr2("comment", &il->comment, il->comment_ptr, ps, depth)) + return False; + if(!smb_io_unistr2("location", &il->location, il->location_ptr, ps, depth)) + return False; + if(!smb_io_unistr2("sepfile", &il->sepfile, il->sepfile_ptr, ps, depth)) + return False; + if(!smb_io_unistr2("printprocessor", &il->printprocessor, il->printprocessor_ptr, ps, depth)) + return False; + if(!smb_io_unistr2("datatype", &il->datatype, il->datatype_ptr, ps, depth)) + return False; + if(!smb_io_unistr2("parameters", &il->parameters, il->parameters_ptr, ps, depth)) + return False; + + return True; +} + +bool spool_io_printer_info_level_7(const char *desc, SPOOL_PRINTER_INFO_LEVEL_7 *il, prs_struct *ps, int depth) +{ + prs_debug(ps, depth, desc, "spool_io_printer_info_level_7"); + depth++; + + if(!prs_align(ps)) + return False; + + if(!prs_uint32("guid_ptr", ps, depth, &il->guid_ptr)) + return False; + if(!prs_uint32("action", ps, depth, &il->action)) + return False; + + if(!smb_io_unistr2("servername", &il->guid, il->guid_ptr, ps, depth)) + return False; + return True; +} + +/******************************************************************* +********************************************************************/ + +bool spool_io_printer_info_level(const char *desc, SPOOL_PRINTER_INFO_LEVEL *il, prs_struct *ps, int depth) +{ + prs_debug(ps, depth, desc, "spool_io_printer_info_level"); + depth++; + + if(!prs_align(ps)) + return False; + if(!prs_uint32("level", ps, depth, &il->level)) + return False; + if(!prs_uint32("info_ptr", ps, depth, &il->info_ptr)) + return False; + + /* if no struct inside just return */ + if (il->info_ptr==0) { + if (UNMARSHALLING(ps)) { + il->info_1=NULL; + il->info_2=NULL; + } + return True; + } + + switch (il->level) { + /* + * level 0 is used by setprinter when managing the queue + * (hold, stop, start a queue) + */ + case 0: + break; + /* DOCUMENT ME!!! What is level 1 used for? */ + case 1: + { + if (UNMARSHALLING(ps)) { + if ((il->info_1=PRS_ALLOC_MEM(ps,SPOOL_PRINTER_INFO_LEVEL_1,1)) == NULL) + return False; + } + if (!spool_io_printer_info_level_1("", il->info_1, ps, depth)) + return False; + break; + } + /* + * level 2 is used by addprinter + * and by setprinter when updating printer's info + */ + case 2: + if (UNMARSHALLING(ps)) { + if ((il->info_2=PRS_ALLOC_MEM(ps,SPOOL_PRINTER_INFO_LEVEL_2,1)) == NULL) + return False; + } + 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=PRS_ALLOC_MEM(ps,SPOOL_PRINTER_INFO_LEVEL_3,1)) == NULL) + return False; + } + if (!spool_io_printer_info_level_3("", il->info_3, ps, depth)) + return False; + break; + } + case 7: + if (UNMARSHALLING(ps)) + if ((il->info_7=PRS_ALLOC_MEM(ps,SPOOL_PRINTER_INFO_LEVEL_7,1)) == NULL) + return False; + if (!spool_io_printer_info_level_7("", il->info_7, ps, depth)) + return False; + break; + } + + return True; +} + +/******************************************************************* +********************************************************************/ + +bool spoolss_io_q_addprinterex(const char *desc, SPOOL_Q_ADDPRINTEREX *q_u, prs_struct *ps, int depth) +{ + uint32 ptr_sec_desc = 0; + + prs_debug(ps, depth, desc, "spoolss_io_q_addprinterex"); + depth++; + + if(!prs_align(ps)) + return False; + + if (!prs_io_unistr2_p("ptr", ps, depth, &q_u->server_name)) + return False; + if (!prs_io_unistr2("servername", ps, depth, q_u->server_name)) + return False; + + if(!prs_align(ps)) + return False; + + if(!prs_uint32("info_level", ps, depth, &q_u->level)) + return False; + + if(!spool_io_printer_info_level("", &q_u->info, ps, depth)) + return False; + + if (!spoolss_io_devmode_cont(desc, &q_u->devmode_ctr, ps, depth)) + return False; + + if(!prs_align(ps)) + return False; + + switch (q_u->level) { + case 2: + ptr_sec_desc = q_u->info.info_2->secdesc_ptr; + break; + case 3: + ptr_sec_desc = q_u->info.info_3->secdesc_ptr; + break; + } + if (ptr_sec_desc) { + if (!sec_io_desc_buf(desc, &q_u->secdesc_ctr, ps, depth)) + return False; + } else { + uint32 dummy = 0; + + /* 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("user_switch", ps, depth, &q_u->user_switch)) + return False; + if(!spool_io_user_level("", &q_u->user_ctr, ps, depth)) + return False; + + return True; +} + +/******************************************************************* +********************************************************************/ + +bool spoolss_io_r_addprinterex(const char *desc, SPOOL_R_ADDPRINTEREX *r_u, + prs_struct *ps, int depth) +{ + prs_debug(ps, depth, desc, "spoolss_io_r_addprinterex"); + depth++; + + if(!smb_io_pol_hnd("printer handle",&r_u->handle,ps,depth)) + return False; + + if(!prs_werror("status", ps, depth, &r_u->status)) + return False; + + return True; +} + +/******************************************************************* +********************************************************************/ + +bool spool_io_printer_driver_info_level_3(const char *desc, SPOOL_PRINTER_DRIVER_INFO_LEVEL_3 **q_u, + prs_struct *ps, int depth) +{ + SPOOL_PRINTER_DRIVER_INFO_LEVEL_3 *il; + + prs_debug(ps, depth, desc, "spool_io_printer_driver_info_level_3"); + depth++; + + /* reading */ + if (UNMARSHALLING(ps)) { + il=PRS_ALLOC_MEM(ps,SPOOL_PRINTER_DRIVER_INFO_LEVEL_3,1); + if(il == NULL) + return False; + *q_u=il; + } + else { + il=*q_u; + } + + if(!prs_align(ps)) + return False; + + if(!prs_uint32("cversion", ps, depth, &il->cversion)) + return False; + if(!prs_uint32("name", ps, depth, &il->name_ptr)) + return False; + if(!prs_uint32("environment", ps, depth, &il->environment_ptr)) + return False; + if(!prs_uint32("driverpath", ps, depth, &il->driverpath_ptr)) + return False; + if(!prs_uint32("datafile", ps, depth, &il->datafile_ptr)) + return False; + if(!prs_uint32("configfile", ps, depth, &il->configfile_ptr)) + return False; + if(!prs_uint32("helpfile", ps, depth, &il->helpfile_ptr)) + return False; + if(!prs_uint32("monitorname", ps, depth, &il->monitorname_ptr)) + return False; + if(!prs_uint32("defaultdatatype", ps, depth, &il->defaultdatatype_ptr)) + return False; + if(!prs_uint32("dependentfilessize", ps, depth, &il->dependentfilessize)) + return False; + if(!prs_uint32("dependentfiles", ps, depth, &il->dependentfiles_ptr)) + return False; + + if(!prs_align(ps)) + return False; + + if(!smb_io_unistr2("name", &il->name, il->name_ptr, ps, depth)) + return False; + if(!smb_io_unistr2("environment", &il->environment, il->environment_ptr, ps, depth)) + return False; + if(!smb_io_unistr2("driverpath", &il->driverpath, il->driverpath_ptr, ps, depth)) + return False; + if(!smb_io_unistr2("datafile", &il->datafile, il->datafile_ptr, ps, depth)) + return False; + if(!smb_io_unistr2("configfile", &il->configfile, il->configfile_ptr, ps, depth)) + return False; + if(!smb_io_unistr2("helpfile", &il->helpfile, il->helpfile_ptr, ps, depth)) + return False; + if(!smb_io_unistr2("monitorname", &il->monitorname, il->monitorname_ptr, ps, depth)) + return False; + if(!smb_io_unistr2("defaultdatatype", &il->defaultdatatype, il->defaultdatatype_ptr, ps, depth)) + return False; + + if(!prs_align(ps)) + return False; + + if (il->dependentfiles_ptr) + smb_io_buffer5("", &il->dependentfiles, ps, depth); + + return True; +} + +/******************************************************************* +parse a SPOOL_PRINTER_DRIVER_INFO_LEVEL_6 structure +********************************************************************/ + +bool spool_io_printer_driver_info_level_6(const char *desc, SPOOL_PRINTER_DRIVER_INFO_LEVEL_6 **q_u, + prs_struct *ps, int depth) +{ + SPOOL_PRINTER_DRIVER_INFO_LEVEL_6 *il; + + prs_debug(ps, depth, desc, "spool_io_printer_driver_info_level_6"); + depth++; + + /* reading */ + if (UNMARSHALLING(ps)) { + il=PRS_ALLOC_MEM(ps,SPOOL_PRINTER_DRIVER_INFO_LEVEL_6,1); + if(il == NULL) + return False; + *q_u=il; + } + else { + il=*q_u; + } + + if(!prs_align(ps)) + return False; + + /* + * I know this seems weird, but I have no other explanation. + * This is observed behavior on both NT4 and 2K servers. + * --jerry + */ + + if (!prs_align_uint64(ps)) + return False; + + /* parse the main elements the packet */ + + if(!prs_uint32("cversion ", ps, depth, &il->version)) + return False; + if(!prs_uint32("name ", ps, depth, &il->name_ptr)) + return False; + if(!prs_uint32("environment ", ps, depth, &il->environment_ptr)) + return False; + if(!prs_uint32("driverpath ", ps, depth, &il->driverpath_ptr)) + return False; + if(!prs_uint32("datafile ", ps, depth, &il->datafile_ptr)) + return False; + if(!prs_uint32("configfile ", ps, depth, &il->configfile_ptr)) + return False; + if(!prs_uint32("helpfile ", ps, depth, &il->helpfile_ptr)) + return False; + if(!prs_uint32("monitorname ", ps, depth, &il->monitorname_ptr)) + return False; + if(!prs_uint32("defaultdatatype", ps, depth, &il->defaultdatatype_ptr)) + return False; + if(!prs_uint32("dependentfiles ", ps, depth, &il->dependentfiles_len)) + return False; + if(!prs_uint32("dependentfiles ", ps, depth, &il->dependentfiles_ptr)) + return False; + if(!prs_uint32("previousnames ", ps, depth, &il->previousnames_len)) + return False; + if(!prs_uint32("previousnames ", ps, depth, &il->previousnames_ptr)) + return False; + if(!smb_io_time("driverdate ", &il->driverdate, ps, depth)) + return False; + if(!prs_uint32("dummy4 ", ps, depth, &il->dummy4)) + return False; + if(!prs_uint64("driverversion ", ps, depth, &il->driverversion)) + return False; + if(!prs_uint32("mfgname ", ps, depth, &il->mfgname_ptr)) + return False; + if(!prs_uint32("oemurl ", ps, depth, &il->oemurl_ptr)) + return False; + if(!prs_uint32("hardwareid ", ps, depth, &il->hardwareid_ptr)) + return False; + if(!prs_uint32("provider ", ps, depth, &il->provider_ptr)) + return False; + + /* parse the structures in the packet */ + + if(!smb_io_unistr2("name", &il->name, il->name_ptr, ps, depth)) + 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)) + return False; + if (il->dependentfiles_ptr) { + if(!smb_io_buffer5("dependentfiles", &il->dependentfiles, ps, depth)) + return False; + if(!prs_align(ps)) + return False; + } + if (il->previousnames_ptr) { + if(!smb_io_buffer5("previousnames", &il->previousnames, ps, depth)) + return False; + if(!prs_align(ps)) + return False; + } + if(!smb_io_unistr2("mfgname", &il->mfgname, il->mfgname_ptr, ps, depth)) + return False; + if(!prs_align(ps)) + return False; + if(!smb_io_unistr2("oemurl", &il->oemurl, il->oemurl_ptr, ps, depth)) + return False; + if(!prs_align(ps)) + return False; + if(!smb_io_unistr2("hardwareid", &il->hardwareid, il->hardwareid_ptr, ps, depth)) + return False; + if(!prs_align(ps)) + return False; + if(!smb_io_unistr2("provider", &il->provider, il->provider_ptr, ps, depth)) + return False; + + return True; +} + +/******************************************************************* + convert a buffer of UNICODE strings null terminated + the buffer is terminated by a NULL + + convert to an dos codepage array (null terminated) + + dynamically allocate memory + +********************************************************************/ + +static bool uniarray_2_dosarray(BUFFER5 *buf5, fstring **ar) +{ + fstring f; + int n = 0; + char *src; + + if (buf5==NULL) + return False; + + src = (char *)buf5->buffer; + *ar = SMB_MALLOC_ARRAY(fstring, 1); + if (!*ar) { + return False; + } + + while (src < ((char *)buf5->buffer) + buf5->buf_len*2) { + rpcstr_pull(f, src, sizeof(f)-1, -1, STR_TERMINATE); + src = skip_unibuf(src, 2*buf5->buf_len - PTR_DIFF(src,buf5->buffer)); + *ar = SMB_REALLOC_ARRAY(*ar, fstring, n+2); + if (!*ar) { + return False; + } + fstrcpy((*ar)[n], f); + n++; + } + + fstrcpy((*ar)[n], ""); + + return True; +} + +/******************************************************************* + read a UNICODE array with null terminated strings + and null terminated array + and size of array at beginning +********************************************************************/ + +bool smb_io_unibuffer(const char *desc, UNISTR2 *buffer, prs_struct *ps, int depth) +{ + if (buffer==NULL) return False; + + buffer->offset=0; + buffer->uni_str_len=buffer->uni_max_len; + + if(!prs_uint32("buffer_size", ps, depth, &buffer->uni_max_len)) + return False; + + if(!prs_unistr2(True, "buffer ", ps, depth, buffer)) + return False; + + return True; +} + +/******************************************************************* +********************************************************************/ + +bool spool_io_printer_driver_info_level(const char *desc, SPOOL_PRINTER_DRIVER_INFO_LEVEL *il, prs_struct *ps, int depth) +{ + prs_debug(ps, depth, desc, "spool_io_printer_driver_info_level"); + depth++; + + if(!prs_align(ps)) + return False; + if(!prs_uint32("level", ps, depth, &il->level)) + return False; + if(!prs_uint32("ptr", ps, depth, &il->ptr)) + return False; + + if (il->ptr==0) + return True; + + switch (il->level) { + case 3: + if(!spool_io_printer_driver_info_level_3("", &il->info_3, ps, depth)) + return False; + break; + case 6: + if(!spool_io_printer_driver_info_level_6("", &il->info_6, ps, depth)) + return False; + break; + default: + return False; + } + + return True; +} + +/******************************************************************* + 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) +{ + DEBUG(5,("make_spoolss_q_addprinterdriver\n")); + + if (!srv_name || !info) { + return False; + } + + q_u->server_name_ptr = 1; /* srv_name is != NULL, see above */ + init_unistr2(&q_u->server_name, srv_name, UNI_STR_TERMINATE); + + q_u->level = level; + + q_u->info.level = level; + q_u->info.ptr = 1; /* Info is != NULL, see above */ + 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; + + default: + DEBUG(0,("make_spoolss_q_addprinterdriver: Unknown info level [%d]\n", level)); + break; + } + + return True; +} + +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; + SPOOL_PRINTER_DRIVER_INFO_LEVEL_3 *inf; + + if (!(inf=TALLOC_ZERO_P(mem_ctx, 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, &inf->name, &info3->name); + init_unistr2_from_unistr(inf, &inf->environment, &info3->architecture); + init_unistr2_from_unistr(inf, &inf->driverpath, &info3->driverpath); + init_unistr2_from_unistr(inf, &inf->datafile, &info3->datafile); + init_unistr2_from_unistr(inf, &inf->configfile, &info3->configfile); + init_unistr2_from_unistr(inf, &inf->helpfile, &info3->helpfile); + init_unistr2_from_unistr(inf, &inf->monitorname, &info3->monitorname); + init_unistr2_from_unistr(inf, &inf->defaultdatatype, &info3->defaultdatatype); + + if (info3->dependentfiles) { + bool done = False; + bool null_char = False; + uint16 *ptr = info3->dependentfiles; + + 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 = (info3->dependentfiles != NULL) ? len : 0; + 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 (src) { + if (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; + } + } else { + buf5->buffer = NULL; + } + } else { + buf5->buffer=NULL; + } + + return True; +} + +/******************************************************************* + fill in the prs_struct for a ADDPRINTERDRIVER request PDU + ********************************************************************/ + +bool spoolss_io_q_addprinterdriver(const char *desc, SPOOL_Q_ADDPRINTERDRIVER *q_u, prs_struct *ps, int depth) +{ + prs_debug(ps, depth, desc, "spoolss_io_q_addprinterdriver"); + depth++; + + if(!prs_align(ps)) + return False; + + if(!prs_uint32("server_name_ptr", ps, depth, &q_u->server_name_ptr)) + return False; + if(!smb_io_unistr2("server_name", &q_u->server_name, q_u->server_name_ptr, ps, depth)) + return False; + + if(!prs_align(ps)) + return False; + if(!prs_uint32("info_level", ps, depth, &q_u->level)) + return False; + + if(!spool_io_printer_driver_info_level("", &q_u->info, ps, depth)) + return False; + + return True; +} + +/******************************************************************* +********************************************************************/ + +bool spoolss_io_r_addprinterdriver(const char *desc, SPOOL_R_ADDPRINTERDRIVER *q_u, prs_struct *ps, int depth) +{ + prs_debug(ps, depth, desc, "spoolss_io_r_addprinterdriver"); + depth++; + + if(!prs_werror("status", ps, depth, &q_u->status)) + return False; + + return True; +} + +/******************************************************************* + fill in the prs_struct for a ADDPRINTERDRIVER request PDU + ********************************************************************/ + +bool spoolss_io_q_addprinterdriverex(const char *desc, SPOOL_Q_ADDPRINTERDRIVEREX *q_u, prs_struct *ps, int depth) +{ + prs_debug(ps, depth, desc, "spoolss_io_q_addprinterdriverex"); + depth++; + + if(!prs_align(ps)) + return False; + + if(!prs_uint32("server_name_ptr", ps, depth, &q_u->server_name_ptr)) + return False; + if(!smb_io_unistr2("server_name", &q_u->server_name, q_u->server_name_ptr, ps, depth)) + return False; + + if(!prs_align(ps)) + return False; + if(!prs_uint32("info_level", ps, depth, &q_u->level)) + return False; + + if(!spool_io_printer_driver_info_level("", &q_u->info, ps, depth)) + return False; + + if(!prs_align(ps)) + return False; + if(!prs_uint32("copy flags", ps, depth, &q_u->copy_flags)) + return False; + + return True; +} + +/******************************************************************* +********************************************************************/ + +bool spoolss_io_r_addprinterdriverex(const char *desc, SPOOL_R_ADDPRINTERDRIVEREX *q_u, prs_struct *ps, int depth) +{ + prs_debug(ps, depth, desc, "spoolss_io_r_addprinterdriverex"); + depth++; + + if(!prs_werror("status", ps, depth, &q_u->status)) + return False; + + return True; +} + +/******************************************************************* +********************************************************************/ + +bool uni_2_asc_printer_driver_3(SPOOL_PRINTER_DRIVER_INFO_LEVEL_3 *uni, + NT_PRINTER_DRIVER_INFO_LEVEL_3 **asc) +{ + NT_PRINTER_DRIVER_INFO_LEVEL_3 *d; + + DEBUG(7,("uni_2_asc_printer_driver_3: Converting from UNICODE to ASCII\n")); + + if (*asc==NULL) + { + *asc=SMB_MALLOC_P(NT_PRINTER_DRIVER_INFO_LEVEL_3); + if(*asc == NULL) + return False; + ZERO_STRUCTP(*asc); + } + + d=*asc; + + d->cversion=uni->cversion; + + unistr2_to_ascii(d->name, &uni->name, sizeof(d->name)); + unistr2_to_ascii(d->environment, &uni->environment, sizeof(d->environment)); + unistr2_to_ascii(d->driverpath, &uni->driverpath, sizeof(d->driverpath)); + unistr2_to_ascii(d->datafile, &uni->datafile, sizeof(d->datafile)); + unistr2_to_ascii(d->configfile, &uni->configfile, sizeof(d->configfile)); + unistr2_to_ascii(d->helpfile, &uni->helpfile, sizeof(d->helpfile)); + unistr2_to_ascii(d->monitorname, &uni->monitorname, sizeof(d->monitorname)); + unistr2_to_ascii(d->defaultdatatype, &uni->defaultdatatype, sizeof(d->defaultdatatype)); + + DEBUGADD(8,( "version: %d\n", d->cversion)); + DEBUGADD(8,( "name: %s\n", d->name)); + DEBUGADD(8,( "environment: %s\n", d->environment)); + DEBUGADD(8,( "driverpath: %s\n", d->driverpath)); + DEBUGADD(8,( "datafile: %s\n", d->datafile)); + DEBUGADD(8,( "configfile: %s\n", d->configfile)); + DEBUGADD(8,( "helpfile: %s\n", d->helpfile)); + DEBUGADD(8,( "monitorname: %s\n", d->monitorname)); + DEBUGADD(8,( "defaultdatatype: %s\n", d->defaultdatatype)); + + if (uniarray_2_dosarray(&uni->dependentfiles, &d->dependentfiles )) + return True; + + SAFE_FREE(*asc); + return False; +} + +/******************************************************************* +********************************************************************/ +bool uni_2_asc_printer_driver_6(SPOOL_PRINTER_DRIVER_INFO_LEVEL_6 *uni, + NT_PRINTER_DRIVER_INFO_LEVEL_6 **asc) +{ + NT_PRINTER_DRIVER_INFO_LEVEL_6 *d; + + DEBUG(7,("uni_2_asc_printer_driver_6: Converting from UNICODE to ASCII\n")); + + if (*asc==NULL) + { + *asc=SMB_MALLOC_P(NT_PRINTER_DRIVER_INFO_LEVEL_6); + if(*asc == NULL) + return False; + ZERO_STRUCTP(*asc); + } + + d=*asc; + + d->version=uni->version; + + unistr2_to_ascii(d->name, &uni->name, sizeof(d->name)); + unistr2_to_ascii(d->environment, &uni->environment, sizeof(d->environment)); + unistr2_to_ascii(d->driverpath, &uni->driverpath, sizeof(d->driverpath)); + unistr2_to_ascii(d->datafile, &uni->datafile, sizeof(d->datafile)); + unistr2_to_ascii(d->configfile, &uni->configfile, sizeof(d->configfile)); + unistr2_to_ascii(d->helpfile, &uni->helpfile, sizeof(d->helpfile)); + unistr2_to_ascii(d->monitorname, &uni->monitorname, sizeof(d->monitorname)); + unistr2_to_ascii(d->defaultdatatype, &uni->defaultdatatype, sizeof(d->defaultdatatype)); + + DEBUGADD(8,( "version: %d\n", d->version)); + DEBUGADD(8,( "name: %s\n", d->name)); + DEBUGADD(8,( "environment: %s\n", d->environment)); + DEBUGADD(8,( "driverpath: %s\n", d->driverpath)); + DEBUGADD(8,( "datafile: %s\n", d->datafile)); + DEBUGADD(8,( "configfile: %s\n", d->configfile)); + DEBUGADD(8,( "helpfile: %s\n", d->helpfile)); + DEBUGADD(8,( "monitorname: %s\n", d->monitorname)); + DEBUGADD(8,( "defaultdatatype: %s\n", d->defaultdatatype)); + + if (!uniarray_2_dosarray(&uni->dependentfiles, &d->dependentfiles )) + goto error; + if (!uniarray_2_dosarray(&uni->previousnames, &d->previousnames )) + goto error; + + return True; + +error: + SAFE_FREE(*asc); + return False; +} + +bool uni_2_asc_printer_info_2(const SPOOL_PRINTER_INFO_LEVEL_2 *uni, + NT_PRINTER_INFO_LEVEL_2 *d) +{ + DEBUG(7,("Converting from UNICODE to ASCII\n")); + + d->attributes=uni->attributes; + d->priority=uni->priority; + d->default_priority=uni->default_priority; + d->starttime=uni->starttime; + d->untiltime=uni->untiltime; + d->status=uni->status; + d->cjobs=uni->cjobs; + + unistr2_to_ascii(d->servername, &uni->servername, sizeof(d->servername)); + unistr2_to_ascii(d->printername, &uni->printername, sizeof(d->printername)); + unistr2_to_ascii(d->sharename, &uni->sharename, sizeof(d->sharename)); + unistr2_to_ascii(d->portname, &uni->portname, sizeof(d->portname)); + unistr2_to_ascii(d->drivername, &uni->drivername, sizeof(d->drivername)); + unistr2_to_ascii(d->comment, &uni->comment, sizeof(d->comment)); + unistr2_to_ascii(d->location, &uni->location, sizeof(d->location)); + unistr2_to_ascii(d->sepfile, &uni->sepfile, sizeof(d->sepfile)); + unistr2_to_ascii(d->printprocessor, &uni->printprocessor, sizeof(d->printprocessor)); + unistr2_to_ascii(d->datatype, &uni->datatype, sizeof(d->datatype)); + unistr2_to_ascii(d->parameters, &uni->parameters, sizeof(d->parameters)); + + return True; +} + +/******************************************************************* + * init a structure. + ********************************************************************/ + +bool make_spoolss_q_getprinterdriverdir(SPOOL_Q_GETPRINTERDRIVERDIR *q_u, + fstring servername, fstring env_name, uint32 level, + RPC_BUFFER *buffer, uint32 offered) +{ + 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; + + return True; +} + +/******************************************************************* + Parse a SPOOL_Q_GETPRINTERDRIVERDIR structure. +********************************************************************/ + +bool spoolss_io_q_getprinterdriverdir(const char *desc, SPOOL_Q_GETPRINTERDRIVERDIR *q_u, prs_struct *ps, int depth) +{ + prs_debug(ps, depth, desc, "spoolss_io_q_getprinterdriverdir"); + depth++; + + if(!prs_align(ps)) + return False; + if(!prs_uint32("name_ptr", ps, depth, &q_u->name_ptr)) + return False; + if(!smb_io_unistr2("", &q_u->name, q_u->name_ptr, ps, depth)) + return False; + + if(!prs_align(ps)) + return False; + + if(!prs_uint32("", ps, depth, &q_u->environment_ptr)) + return False; + if(!smb_io_unistr2("", &q_u->environment, q_u->environment_ptr, ps, depth)) + return False; + + if(!prs_align(ps)) + return False; + + if(!prs_uint32("level", ps, depth, &q_u->level)) + return False; + + if(!prs_rpcbuffer_p("", 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; +} + +/******************************************************************* + Parse a SPOOL_R_GETPRINTERDRIVERDIR structure. +********************************************************************/ + +bool spoolss_io_r_getprinterdriverdir(const char *desc, SPOOL_R_GETPRINTERDRIVERDIR *r_u, prs_struct *ps, int depth) +{ + prs_debug(ps, depth, desc, "spoolss_io_r_getprinterdriverdir"); + depth++; + + if (!prs_align(ps)) + return False; + + if (!prs_rpcbuffer_p("", 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_werror("status", ps, depth, &r_u->status)) + return False; + + return True; +} + +/******************************************************************* +********************************************************************/ + +bool spoolss_io_r_enumprintprocessors(const char *desc, SPOOL_R_ENUMPRINTPROCESSORS *r_u, prs_struct *ps, int depth) +{ + prs_debug(ps, depth, desc, "spoolss_io_r_enumprintprocessors"); + depth++; + + if (!prs_align(ps)) + return False; + + if (!prs_rpcbuffer_p("", 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("returned", ps, depth, &r_u->returned)) + return False; + + if (!prs_werror("status", ps, depth, &r_u->status)) + return False; + + return True; +} + +/******************************************************************* +********************************************************************/ + +bool spoolss_io_q_enumprintprocessors(const char *desc, SPOOL_Q_ENUMPRINTPROCESSORS *q_u, prs_struct *ps, int depth) +{ + prs_debug(ps, depth, desc, "spoolss_io_q_enumprintprocessors"); + depth++; + + if (!prs_align(ps)) + return False; + + if (!prs_uint32("name_ptr", ps, depth, &q_u->name_ptr)) + return False; + if (!smb_io_unistr2("name", &q_u->name, True, ps, depth)) + return False; + + if (!prs_align(ps)) + return False; + + if (!prs_uint32("", ps, depth, &q_u->environment_ptr)) + return False; + if (!smb_io_unistr2("", &q_u->environment, q_u->environment_ptr, ps, depth)) + return False; + + if (!prs_align(ps)) + return False; + + if (!prs_uint32("level", ps, depth, &q_u->level)) + return False; + + if(!prs_rpcbuffer_p("", 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_q_addprintprocessor(const 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(const 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_werror("status", ps, depth, &r_u->status)) + return False; + + return True; +} + +/******************************************************************* +********************************************************************/ + +bool spoolss_io_r_enumprintprocdatatypes(const char *desc, SPOOL_R_ENUMPRINTPROCDATATYPES *r_u, prs_struct *ps, int depth) +{ + prs_debug(ps, depth, desc, "spoolss_io_r_enumprintprocdatatypes"); + depth++; + + if (!prs_align(ps)) + return False; + + if (!prs_rpcbuffer_p("", 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("returned", ps, depth, &r_u->returned)) + return False; + + if (!prs_werror("status", ps, depth, &r_u->status)) + return False; + + return True; +} + +/******************************************************************* +********************************************************************/ + +bool spoolss_io_q_enumprintprocdatatypes(const char *desc, SPOOL_Q_ENUMPRINTPROCDATATYPES *q_u, prs_struct *ps, int depth) +{ + prs_debug(ps, depth, desc, "spoolss_io_q_enumprintprocdatatypes"); + depth++; + + if (!prs_align(ps)) + return False; + + if (!prs_uint32("name_ptr", ps, depth, &q_u->name_ptr)) + return False; + if (!smb_io_unistr2("name", &q_u->name, True, ps, depth)) + return False; + + if (!prs_align(ps)) + return False; + + if (!prs_uint32("processor_ptr", ps, depth, &q_u->processor_ptr)) + return False; + if (!smb_io_unistr2("processor", &q_u->processor, q_u->processor_ptr, ps, depth)) + return False; + + if (!prs_align(ps)) + return False; + + if (!prs_uint32("level", ps, depth, &q_u->level)) + return False; + + if(!prs_rpcbuffer_p("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; +} + +/******************************************************************* + Parse a SPOOL_Q_ENUMPRINTMONITORS structure. +********************************************************************/ + +bool spoolss_io_q_enumprintmonitors(const char *desc, SPOOL_Q_ENUMPRINTMONITORS *q_u, prs_struct *ps, int depth) +{ + prs_debug(ps, depth, desc, "spoolss_io_q_enumprintmonitors"); + depth++; + + if (!prs_align(ps)) + return False; + + if (!prs_uint32("name_ptr", ps, depth, &q_u->name_ptr)) + return False; + if (!smb_io_unistr2("name", &q_u->name, True, ps, depth)) + return False; + + if (!prs_align(ps)) + return False; + + if (!prs_uint32("level", ps, depth, &q_u->level)) + return False; + + if(!prs_rpcbuffer_p("", 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_enumprintmonitors(const char *desc, SPOOL_R_ENUMPRINTMONITORS *r_u, prs_struct *ps, int depth) +{ + prs_debug(ps, depth, desc, "spoolss_io_r_enumprintmonitors"); + depth++; + + if (!prs_align(ps)) + return False; + + if (!prs_rpcbuffer_p("", 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("returned", ps, depth, &r_u->returned)) + return False; + + if (!prs_werror("status", ps, depth, &r_u->status)) + return False; + + return True; +} + +/******************************************************************* +********************************************************************/ + +bool spoolss_io_r_enumprinterdata(const char *desc, SPOOL_R_ENUMPRINTERDATA *r_u, prs_struct *ps, int depth) +{ + prs_debug(ps, depth, desc, "spoolss_io_r_enumprinterdata"); + depth++; + + if(!prs_align(ps)) + return False; + if(!prs_uint32("valuesize", ps, depth, &r_u->valuesize)) + return False; + + if (UNMARSHALLING(ps) && r_u->valuesize) { + r_u->value = PRS_ALLOC_MEM(ps, uint16, r_u->valuesize); + if (!r_u->value) { + DEBUG(0, ("spoolss_io_r_enumprinterdata: out of memory for printerdata value\n")); + return False; + } + } + + if(!prs_uint16uni(False, "value", ps, depth, r_u->value, r_u->valuesize )) + return False; + + if(!prs_align(ps)) + return False; + + if(!prs_uint32("realvaluesize", ps, depth, &r_u->realvaluesize)) + return False; + + if(!prs_uint32("type", ps, depth, &r_u->type)) + return False; + + if(!prs_uint32("datasize", ps, depth, &r_u->datasize)) + return False; + + if (UNMARSHALLING(ps) && r_u->datasize) { + r_u->data = PRS_ALLOC_MEM(ps, uint8, r_u->datasize); + if (!r_u->data) { + DEBUG(0, ("spoolss_io_r_enumprinterdata: out of memory for printerdata data\n")); + return False; + } + } + + if(!prs_uint8s(False, "data", ps, depth, r_u->data, r_u->datasize)) + return False; + if(!prs_align(ps)) + return False; + + if(!prs_uint32("realdatasize", ps, depth, &r_u->realdatasize)) + return False; + if(!prs_werror("status", ps, depth, &r_u->status)) + return False; + + return True; +} + +/******************************************************************* +********************************************************************/ + +bool spoolss_io_q_enumprinterdata(const char *desc, SPOOL_Q_ENUMPRINTERDATA *q_u, prs_struct *ps, int depth) +{ + prs_debug(ps, depth, desc, "spoolss_io_q_enumprinterdata"); + depth++; + + if(!prs_align(ps)) + return False; + if(!smb_io_pol_hnd("printer handle",&q_u->handle,ps,depth)) + return False; + if(!prs_uint32("index", ps, depth, &q_u->index)) + return False; + if(!prs_uint32("valuesize", ps, depth, &q_u->valuesize)) + return False; + if(!prs_uint32("datasize", ps, depth, &q_u->datasize)) + return False; + + return True; +} + +/******************************************************************* +********************************************************************/ + +bool make_spoolss_q_enumprinterdata(SPOOL_Q_ENUMPRINTERDATA *q_u, + const POLICY_HND *hnd, + uint32 idx, uint32 valuelen, uint32 datalen) +{ + memcpy(&q_u->handle, hnd, sizeof(q_u->handle)); + q_u->index=idx; + q_u->valuesize=valuelen; + q_u->datasize=datalen; + + return True; +} + +/******************************************************************* +********************************************************************/ + +bool make_spoolss_q_enumprinterdataex(SPOOL_Q_ENUMPRINTERDATAEX *q_u, + const POLICY_HND *hnd, const char *key, + uint32 size) +{ + memcpy(&q_u->handle, hnd, sizeof(q_u->handle)); + init_unistr2(&q_u->key, key, UNI_STR_TERMINATE); + q_u->size = size; + + return True; +} + +/******************************************************************* +********************************************************************/ +bool make_spoolss_q_setprinterdata(SPOOL_Q_SETPRINTERDATA *q_u, const POLICY_HND *hnd, + char* value, uint32 data_type, char* data, uint32 data_size) +{ + memcpy(&q_u->handle, hnd, sizeof(q_u->handle)); + q_u->type = data_type; + init_unistr2(&q_u->value, value, UNI_STR_TERMINATE); + + q_u->max_len = q_u->real_len = data_size; + q_u->data = (unsigned char *)data; + + return True; +} + +/******************************************************************* +********************************************************************/ +bool make_spoolss_q_setprinterdataex(SPOOL_Q_SETPRINTERDATAEX *q_u, const POLICY_HND *hnd, + char *key, char* value, uint32 data_type, char* data, + uint32 data_size) +{ + memcpy(&q_u->handle, hnd, sizeof(q_u->handle)); + q_u->type = data_type; + init_unistr2(&q_u->value, value, UNI_STR_TERMINATE); + init_unistr2(&q_u->key, key, UNI_STR_TERMINATE); + + q_u->max_len = q_u->real_len = data_size; + q_u->data = (unsigned char *)data; + + return True; +} + +/******************************************************************* +********************************************************************/ + +bool spoolss_io_q_setprinterdata(const char *desc, SPOOL_Q_SETPRINTERDATA *q_u, prs_struct *ps, int depth) +{ + prs_debug(ps, depth, desc, "spoolss_io_q_setprinterdata"); + 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->value, True, ps, depth)) + return False; + + if(!prs_align(ps)) + return False; + + if(!prs_uint32("type", ps, depth, &q_u->type)) + return False; + + if(!prs_uint32("max_len", ps, depth, &q_u->max_len)) + return False; + + switch (q_u->type) + { + case REG_SZ: + case REG_BINARY: + case REG_DWORD: + case REG_MULTI_SZ: + if (q_u->max_len) { + if (UNMARSHALLING(ps)) + q_u->data=PRS_ALLOC_MEM(ps, uint8, q_u->max_len); + 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; + } + + if(!prs_uint32("real_len", ps, depth, &q_u->real_len)) + return False; + + return True; +} + +/******************************************************************* +********************************************************************/ + +bool spoolss_io_r_setprinterdata(const char *desc, SPOOL_R_SETPRINTERDATA *r_u, prs_struct *ps, int depth) +{ + prs_debug(ps, depth, desc, "spoolss_io_r_setprinterdata"); + depth++; + + if(!prs_align(ps)) + return False; + if(!prs_werror("status", ps, depth, &r_u->status)) + return False; + + return True; +} + +/******************************************************************* +********************************************************************/ +bool spoolss_io_q_resetprinter(const char *desc, SPOOL_Q_RESETPRINTER *q_u, prs_struct *ps, int depth) +{ + prs_debug(ps, depth, desc, "spoolss_io_q_resetprinter"); + depth++; + + if (!prs_align(ps)) + return False; + if (!smb_io_pol_hnd("printer handle", &q_u->handle, ps, depth)) + return False; + + if (!prs_uint32("datatype_ptr", ps, depth, &q_u->datatype_ptr)) + return False; + + if (q_u->datatype_ptr) { + if (!smb_io_unistr2("datatype", &q_u->datatype, q_u->datatype_ptr?True:False, ps, depth)) + return False; + } + + if (!spoolss_io_devmode_cont(desc, &q_u->devmode_ctr, ps, depth)) + return False; + + return True; +} + + +/******************************************************************* +********************************************************************/ +bool spoolss_io_r_resetprinter(const char *desc, SPOOL_R_RESETPRINTER *r_u, prs_struct *ps, int depth) +{ + prs_debug(ps, depth, desc, "spoolss_io_r_resetprinter"); + depth++; + + if(!prs_align(ps)) + return False; + if(!prs_werror("status", ps, depth, &r_u->status)) + return False; + + return True; +} + +/******************************************************************* +********************************************************************/ + +static bool spoolss_io_addform(const char *desc, FORM *f, uint32 ptr, prs_struct *ps, int depth) +{ + prs_debug(ps, depth, desc, "spoolss_io_addform"); + depth++; + if(!prs_align(ps)) + return False; + + if (ptr!=0) + { + if(!prs_uint32("flags", ps, depth, &f->flags)) + return False; + if(!prs_uint32("name_ptr", ps, depth, &f->name_ptr)) + return False; + if(!prs_uint32("size_x", ps, depth, &f->size_x)) + return False; + if(!prs_uint32("size_y", ps, depth, &f->size_y)) + return False; + if(!prs_uint32("left", ps, depth, &f->left)) + return False; + if(!prs_uint32("top", ps, depth, &f->top)) + return False; + if(!prs_uint32("right", ps, depth, &f->right)) + return False; + if(!prs_uint32("bottom", ps, depth, &f->bottom)) + return False; + + if(!smb_io_unistr2("", &f->name, f->name_ptr, ps, depth)) + return False; + } + + return True; +} + +/******************************************************************* +********************************************************************/ + +bool spoolss_io_q_deleteform(const 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(const 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_werror("status", ps, depth, &r_u->status)) + return False; + + return True; +} + +/******************************************************************* +********************************************************************/ + +bool spoolss_io_q_addform(const char *desc, SPOOL_Q_ADDFORM *q_u, prs_struct *ps, int depth) +{ + uint32 useless_ptr=1; + prs_debug(ps, depth, desc, "spoolss_io_q_addform"); + depth++; + + if(!prs_align(ps)) + return False; + if(!smb_io_pol_hnd("printer handle", &q_u->handle, ps, depth)) + return False; + if(!prs_uint32("level", ps, depth, &q_u->level)) + return False; + if(!prs_uint32("level2", ps, depth, &q_u->level2)) + return False; + + if (q_u->level==1) + { + if(!prs_uint32("useless_ptr", ps, depth, &useless_ptr)) + return False; + if(!spoolss_io_addform("", &q_u->form, useless_ptr, ps, depth)) + return False; + } + + return True; +} + +/******************************************************************* +********************************************************************/ + +bool spoolss_io_r_addform(const char *desc, SPOOL_R_ADDFORM *r_u, prs_struct *ps, int depth) +{ + prs_debug(ps, depth, desc, "spoolss_io_r_addform"); + depth++; + + if(!prs_align(ps)) + return False; + if(!prs_werror("status", ps, depth, &r_u->status)) + return False; + + return True; +} + +/******************************************************************* +********************************************************************/ + +bool spoolss_io_q_setform(const char *desc, SPOOL_Q_SETFORM *q_u, prs_struct *ps, int depth) +{ + uint32 useless_ptr=1; + prs_debug(ps, depth, desc, "spoolss_io_q_setform"); + 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->name, True, ps, depth)) + return False; + + if(!prs_align(ps)) + return False; + + if(!prs_uint32("level", ps, depth, &q_u->level)) + return False; + if(!prs_uint32("level2", ps, depth, &q_u->level2)) + return False; + + if (q_u->level==1) + { + if(!prs_uint32("useless_ptr", ps, depth, &useless_ptr)) + return False; + if(!spoolss_io_addform("", &q_u->form, useless_ptr, ps, depth)) + return False; + } + + return True; +} + +/******************************************************************* +********************************************************************/ + +bool spoolss_io_r_setform(const char *desc, SPOOL_R_SETFORM *r_u, prs_struct *ps, int depth) +{ + prs_debug(ps, depth, desc, "spoolss_io_r_setform"); + depth++; + + if(!prs_align(ps)) + return False; + if(!prs_werror("status", ps, depth, &r_u->status)) + return False; + + return True; +} + +/******************************************************************* + Parse a SPOOL_R_GETJOB structure. +********************************************************************/ + +bool spoolss_io_r_getjob(const char *desc, SPOOL_R_GETJOB *r_u, prs_struct *ps, int depth) +{ + prs_debug(ps, depth, desc, "spoolss_io_r_getjob"); + depth++; + + if (!prs_align(ps)) + return False; + + if (!prs_rpcbuffer_p("", 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_werror("status", ps, depth, &r_u->status)) + return False; + + return True; +} + +/******************************************************************* + Parse a SPOOL_Q_GETJOB structure. +********************************************************************/ + +bool spoolss_io_q_getjob(const char *desc, SPOOL_Q_GETJOB *q_u, prs_struct *ps, int depth) +{ + prs_debug(ps, depth, desc, ""); + depth++; + + if(!prs_align(ps)) + return False; + + if(!smb_io_pol_hnd("printer handle",&q_u->handle,ps,depth)) + return False; + if(!prs_uint32("jobid", ps, depth, &q_u->jobid)) + return False; + if(!prs_uint32("level", ps, depth, &q_u->level)) + return False; + + if(!prs_rpcbuffer_p("", 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; +} + +void free_devmode(DEVICEMODE *devmode) +{ + if (devmode!=NULL) { + SAFE_FREE(devmode->dev_private); + SAFE_FREE(devmode); + } +} + +void free_printer_info_1(PRINTER_INFO_1 *printer) +{ + SAFE_FREE(printer); +} + +void free_printer_info_2(PRINTER_INFO_2 *printer) +{ + if (printer!=NULL) { + free_devmode(printer->devmode); + printer->devmode = NULL; + SAFE_FREE(printer); + } +} + +void free_printer_info_3(PRINTER_INFO_3 *printer) +{ + SAFE_FREE(printer); +} + +void free_printer_info_4(PRINTER_INFO_4 *printer) +{ + SAFE_FREE(printer); +} + +void free_printer_info_5(PRINTER_INFO_5 *printer) +{ + SAFE_FREE(printer); +} + +void free_printer_info_6(PRINTER_INFO_6 *printer) +{ + SAFE_FREE(printer); +} + +void free_printer_info_7(PRINTER_INFO_7 *printer) +{ + SAFE_FREE(printer); +} + +void free_job_info_2(JOB_INFO_2 *job) +{ + if (job!=NULL) + free_devmode(job->devmode); +} + +/******************************************************************* + * init a structure. + ********************************************************************/ + +bool make_spoolss_q_replyopenprinter(SPOOL_Q_REPLYOPENPRINTER *q_u, + const fstring string, uint32 printer, uint32 type) +{ + if (q_u == NULL) + return False; + + init_unistr2(&q_u->string, string, UNI_STR_TERMINATE); + + q_u->printer=printer; + q_u->type=type; + + q_u->unknown0=0x0; + q_u->unknown1=0x0; + + return True; +} + +/******************************************************************* + Parse a SPOOL_Q_REPLYOPENPRINTER structure. +********************************************************************/ + +bool spoolss_io_q_replyopenprinter(const char *desc, SPOOL_Q_REPLYOPENPRINTER *q_u, prs_struct *ps, int depth) +{ + prs_debug(ps, depth, desc, "spoolss_io_q_replyopenprinter"); + depth++; + + if(!prs_align(ps)) + return False; + + if(!smb_io_unistr2("", &q_u->string, True, ps, depth)) + return False; + + if(!prs_align(ps)) + return False; + + if(!prs_uint32("printer", ps, depth, &q_u->printer)) + return False; + if(!prs_uint32("type", ps, depth, &q_u->type)) + return False; + + if(!prs_uint32("unknown0", ps, depth, &q_u->unknown0)) + return False; + if(!prs_uint32("unknown1", ps, depth, &q_u->unknown1)) + return False; + + return True; +} + +/******************************************************************* + Parse a SPOOL_R_REPLYOPENPRINTER structure. +********************************************************************/ + +bool spoolss_io_r_replyopenprinter(const char *desc, SPOOL_R_REPLYOPENPRINTER *r_u, prs_struct *ps, int depth) +{ + prs_debug(ps, depth, desc, "spoolss_io_r_replyopenprinter"); + depth++; + + if (!prs_align(ps)) + return False; + + if(!smb_io_pol_hnd("printer handle",&r_u->handle,ps,depth)) + return False; + + if (!prs_werror("status", ps, depth, &r_u->status)) + return False; + + return True; +} + +/******************************************************************* + * init a structure. + ********************************************************************/ +bool make_spoolss_q_routerreplyprinter(SPOOL_Q_ROUTERREPLYPRINTER *q_u, POLICY_HND *hnd, + uint32 condition, uint32 change_id) +{ + + memcpy(&q_u->handle, hnd, sizeof(q_u->handle)); + + q_u->condition = condition; + q_u->change_id = change_id; + + /* magic values */ + q_u->unknown1 = 0x1; + memset(q_u->unknown2, 0x0, 5); + q_u->unknown2[0] = 0x1; + + return True; +} + +/******************************************************************* + Parse a SPOOL_Q_ROUTERREPLYPRINTER structure. +********************************************************************/ +bool spoolss_io_q_routerreplyprinter (const char *desc, SPOOL_Q_ROUTERREPLYPRINTER *q_u, prs_struct *ps, int depth) +{ + + prs_debug(ps, depth, desc, "spoolss_io_q_routerreplyprinter"); + depth++; + + if (!prs_align(ps)) + return False; + + if(!smb_io_pol_hnd("printer handle",&q_u->handle,ps,depth)) + return False; + + if (!prs_uint32("condition", ps, depth, &q_u->condition)) + return False; + + if (!prs_uint32("unknown1", ps, depth, &q_u->unknown1)) + return False; + + if (!prs_uint32("change_id", ps, depth, &q_u->change_id)) + return False; + + if (!prs_uint8s(False, "dev_private", ps, depth, q_u->unknown2, 5)) + return False; + + return True; +} + +/******************************************************************* + Parse a SPOOL_R_ROUTERREPLYPRINTER structure. +********************************************************************/ +bool spoolss_io_r_routerreplyprinter (const char *desc, SPOOL_R_ROUTERREPLYPRINTER *r_u, prs_struct *ps, int depth) +{ + prs_debug(ps, depth, desc, "spoolss_io_r_routerreplyprinter"); + depth++; + + if (!prs_align(ps)) + return False; + + if (!prs_werror("status", ps, depth, &r_u->status)) + return False; + + 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(const char *desc, SPOOL_Q_REPLYCLOSEPRINTER *q_u, prs_struct *ps, int depth) +{ + prs_debug(ps, depth, desc, "spoolss_io_q_replycloseprinter"); + depth++; + + if(!prs_align(ps)) + return False; + + if(!smb_io_pol_hnd("printer handle",&q_u->handle,ps,depth)) + return False; + + return True; +} + +/******************************************************************* + Parse a SPOOL_R_REPLYCLOSEPRINTER structure. +********************************************************************/ + +bool spoolss_io_r_replycloseprinter(const char *desc, SPOOL_R_REPLYCLOSEPRINTER *r_u, prs_struct *ps, int depth) +{ + prs_debug(ps, depth, desc, "spoolss_io_r_replycloseprinter"); + depth++; + + if (!prs_align(ps)) + return False; + + if(!smb_io_pol_hnd("printer handle",&r_u->handle,ps,depth)) + return False; + + if (!prs_werror("status", ps, depth, &r_u->status)) + return False; + + return True; +} + +#if 0 /* JERRY - not currently used but could be :-) */ + +/******************************************************************* + Deep copy a SPOOL_NOTIFY_INFO_DATA structure + ******************************************************************/ +static bool copy_spool_notify_info_data(SPOOL_NOTIFY_INFO_DATA *dst, + SPOOL_NOTIFY_INFO_DATA *src, int n) +{ + int i; + + memcpy(dst, src, sizeof(SPOOL_NOTIFY_INFO_DATA)*n); + + for (i=0; i<n; i++) { + int len; + uint16 *s = NULL; + + if (src->size != POINTER) + continue; + len = src->notify_data.data.length; + s = SMB_MALLOC_ARRAY(uint16, len); + if (s == NULL) { + DEBUG(0,("copy_spool_notify_info_data: malloc() failed!\n")); + return False; + } + + memcpy(s, src->notify_data.data.string, len*2); + dst->notify_data.data.string = s; + } + + return True; +} + +/******************************************************************* + Deep copy a SPOOL_NOTIFY_INFO structure + ******************************************************************/ +static bool copy_spool_notify_info(SPOOL_NOTIFY_INFO *dst, SPOOL_NOTIFY_INFO *src) +{ + if (!dst) { + DEBUG(0,("copy_spool_notify_info: NULL destination pointer!\n")); + return False; + } + + dst->version = src->version; + dst->flags = src->flags; + dst->count = src->count; + + if (dst->count) + { + dst->data = SMB_MALLOC_ARRAY(SPOOL_NOTIFY_INFO_DATA, dst->count); + + DEBUG(10,("copy_spool_notify_info: allocating space for [%d] PRINTER_NOTIFY_INFO_DATA entries\n", + dst->count)); + + if (dst->data == NULL) { + DEBUG(0,("copy_spool_notify_info: malloc() failed for [%d] entries!\n", + dst->count)); + return False; + } + + return (copy_spool_notify_info_data(dst->data, src->data, src->count)); + } + + return True; +} +#endif /* JERRY */ + +/******************************************************************* + * init a structure. + ********************************************************************/ + +bool make_spoolss_q_reply_rrpcn(SPOOL_Q_REPLY_RRPCN *q_u, POLICY_HND *hnd, + uint32 change_low, uint32 change_high, + SPOOL_NOTIFY_INFO *info) +{ + 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=0x0FF0ADDE; + + q_u->info.version=2; + + if (info->count) { + DEBUG(10,("make_spoolss_q_reply_rrpcn: [%d] PRINTER_NOTIFY_INFO_DATA\n", + info->count)); + q_u->info.version = info->version; + q_u->info.flags = info->flags; + q_u->info.count = info->count; + /* pointer field - be careful! */ + q_u->info.data = info->data; + } + else { + 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(const 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(const char *desc, SPOOL_R_REPLY_RRPCN *r_u, prs_struct *ps, int depth) +{ + prs_debug(ps, depth, desc, "spoolss_io_r_reply_rrpcn"); + depth++; + + if (!prs_align(ps)) + return False; + + if (!prs_uint32("unknown0", ps, depth, &r_u->unknown0)) + return False; + + if (!prs_werror("status", ps, depth, &r_u->status)) + return False; + + return True; +} + +/******************************************************************* + * read a structure. + * called from spoolss_q_getprinterdataex (srv_spoolss.c) + ********************************************************************/ + +bool spoolss_io_q_getprinterdataex(const char *desc, SPOOL_Q_GETPRINTERDATAEX *q_u, prs_struct *ps, int depth) +{ + if (q_u == NULL) + return False; + + prs_debug(ps, depth, desc, "spoolss_io_q_getprinterdataex"); + depth++; + + if (!prs_align(ps)) + return False; + if (!smb_io_pol_hnd("printer handle",&q_u->handle,ps,depth)) + return False; + if (!prs_align(ps)) + return False; + if (!smb_io_unistr2("keyname", &q_u->keyname,True,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; +} + +/******************************************************************* + * write a structure. + * called from spoolss_r_getprinterdataex (srv_spoolss.c) + ********************************************************************/ + +bool spoolss_io_r_getprinterdataex(const char *desc, SPOOL_R_GETPRINTERDATAEX *r_u, prs_struct *ps, int depth) +{ + if (r_u == NULL) + return False; + + prs_debug(ps, depth, desc, "spoolss_io_r_getprinterdataex"); + depth++; + + if (!prs_align(ps)) + return False; + if (!prs_uint32("type", ps, depth, &r_u->type)) + return False; + if (!prs_uint32("size", ps, depth, &r_u->size)) + return False; + + if (UNMARSHALLING(ps) && r_u->size) { + r_u->data = PRS_ALLOC_MEM(ps, unsigned char, r_u->size); + if(!r_u->data) + return False; + } + + if (!prs_uint8s(False,"data", ps, depth, r_u->data, r_u->size)) + return False; + + if (!prs_align(ps)) + return False; + + if (!prs_uint32("needed", ps, depth, &r_u->needed)) + return False; + if (!prs_werror("status", ps, depth, &r_u->status)) + return False; + + return True; +} + +/******************************************************************* + * read a structure. + ********************************************************************/ + +bool spoolss_io_q_setprinterdataex(const char *desc, SPOOL_Q_SETPRINTERDATAEX *q_u, prs_struct *ps, int depth) +{ + prs_debug(ps, depth, desc, "spoolss_io_q_setprinterdataex"); + 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->key, True, ps, depth)) + return False; + + if(!prs_align(ps)) + return False; + + if(!smb_io_unistr2("", &q_u->value, True, ps, depth)) + return False; + + if(!prs_align(ps)) + return False; + + if(!prs_uint32("type", ps, depth, &q_u->type)) + return False; + + if(!prs_uint32("max_len", ps, depth, &q_u->max_len)) + return False; + + switch (q_u->type) + { + case 0x1: + case 0x3: + case 0x4: + case 0x7: + if (q_u->max_len) { + if (UNMARSHALLING(ps)) + q_u->data=PRS_ALLOC_MEM(ps, uint8, q_u->max_len); + 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; + } + + if(!prs_uint32("real_len", ps, depth, &q_u->real_len)) + return False; + + return True; +} + +/******************************************************************* + * write a structure. + ********************************************************************/ + +bool spoolss_io_r_setprinterdataex(const char *desc, SPOOL_R_SETPRINTERDATAEX *r_u, prs_struct *ps, int depth) +{ + prs_debug(ps, depth, desc, "spoolss_io_r_setprinterdataex"); + depth++; + + if(!prs_align(ps)) + return False; + if(!prs_werror("status", ps, depth, &r_u->status)) + return False; + + return True; +} + +/******************************************************************* + * read a structure. + ********************************************************************/ +bool make_spoolss_q_enumprinterkey(SPOOL_Q_ENUMPRINTERKEY *q_u, + POLICY_HND *hnd, const char *key, + uint32 size) +{ + DEBUG(5,("make_spoolss_q_enumprinterkey\n")); + + memcpy(&q_u->handle, hnd, sizeof(q_u->handle)); + init_unistr2(&q_u->key, key, UNI_STR_TERMINATE); + q_u->size = size; + + return True; +} + +/******************************************************************* + * read a structure. + ********************************************************************/ + +bool spoolss_io_q_enumprinterkey(const char *desc, SPOOL_Q_ENUMPRINTERKEY *q_u, prs_struct *ps, int depth) +{ + prs_debug(ps, depth, desc, "spoolss_io_q_enumprinterkey"); + 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->key, True, ps, depth)) + return False; + + if(!prs_align(ps)) + return False; + + if(!prs_uint32("size", ps, depth, &q_u->size)) + return False; + + return True; +} + +/******************************************************************* + * write a structure. + ********************************************************************/ + +bool spoolss_io_r_enumprinterkey(const char *desc, SPOOL_R_ENUMPRINTERKEY *r_u, prs_struct *ps, int depth) +{ + prs_debug(ps, depth, desc, "spoolss_io_r_enumprinterkey"); + depth++; + + if(!prs_align(ps)) + return False; + + if (!smb_io_buffer5("", &r_u->keys, ps, depth)) + return False; + + if(!prs_align(ps)) + return False; + + if(!prs_uint32("needed", ps, depth, &r_u->needed)) + return False; + + if(!prs_werror("status", ps, depth, &r_u->status)) + return False; + + return True; +} + +/******************************************************************* + * read a structure. + ********************************************************************/ + +bool make_spoolss_q_deleteprinterkey(SPOOL_Q_DELETEPRINTERKEY *q_u, + POLICY_HND *hnd, char *keyname) +{ + DEBUG(5,("make_spoolss_q_deleteprinterkey\n")); + + memcpy(&q_u->handle, hnd, sizeof(q_u->handle)); + init_unistr2(&q_u->keyname, keyname, UNI_STR_TERMINATE); + + return True; +} + +/******************************************************************* + * read a structure. + ********************************************************************/ + +bool spoolss_io_q_deleteprinterkey(const char *desc, SPOOL_Q_DELETEPRINTERKEY *q_u, prs_struct *ps, int depth) +{ + prs_debug(ps, depth, desc, "spoolss_io_q_deleteprinterkey"); + 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->keyname, True, ps, depth)) + return False; + + return True; +} + +/******************************************************************* + * write a structure. + ********************************************************************/ + +bool spoolss_io_r_deleteprinterkey(const char *desc, SPOOL_R_DELETEPRINTERKEY *r_u, prs_struct *ps, int depth) +{ + prs_debug(ps, depth, desc, "spoolss_io_r_deleteprinterkey"); + depth++; + + if(!prs_align(ps)) + return False; + + if(!prs_werror("status", ps, depth, &r_u->status)) + return False; + + return True; +} + + +/******************************************************************* + * read a structure. + ********************************************************************/ + +bool spoolss_io_q_enumprinterdataex(const char *desc, SPOOL_Q_ENUMPRINTERDATAEX *q_u, prs_struct *ps, int depth) +{ + prs_debug(ps, depth, desc, "spoolss_io_q_enumprinterdataex"); + 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->key, True, ps, depth)) + return False; + + if(!prs_align(ps)) + return False; + + if(!prs_uint32("size", ps, depth, &q_u->size)) + return False; + + return True; +} + +/******************************************************************* +********************************************************************/ + +static bool spoolss_io_printer_enum_values_ctr(const char *desc, prs_struct *ps, + PRINTER_ENUM_VALUES_CTR *ctr, int depth) +{ + int i; + uint32 valuename_offset, + data_offset, + current_offset; + const uint32 basic_unit = 20; /* size of static portion of enum_values */ + + prs_debug(ps, depth, desc, "spoolss_io_printer_enum_values_ctr"); + depth++; + + /* + * offset data begins at 20 bytes per structure * size_of_array. + * Don't forget the uint32 at the beginning + * */ + + current_offset = basic_unit * ctr->size_of_array; + + /* first loop to write basic enum_value information */ + + if (UNMARSHALLING(ps) && ctr->size_of_array) { + ctr->values = PRS_ALLOC_MEM(ps, PRINTER_ENUM_VALUES, ctr->size_of_array); + if (!ctr->values) + return False; + } + + for (i=0; i<ctr->size_of_array; i++) { + uint32 base_offset, return_offset; + + base_offset = prs_offset(ps); + + valuename_offset = current_offset; + if (!prs_uint32("valuename_offset", ps, depth, &valuename_offset)) + return False; + + /* Read or write the value. */ + + return_offset = prs_offset(ps); + + if (!prs_set_offset(ps, base_offset + valuename_offset)) { + return False; + } + + if (!prs_unistr("valuename", ps, depth, &ctr->values[i].valuename)) + return False; + + /* And go back. */ + if (!prs_set_offset(ps, return_offset)) + return False; + + if (!prs_uint32("value_len", ps, depth, &ctr->values[i].value_len)) + return False; + + if (!prs_uint32("type", ps, depth, &ctr->values[i].type)) + return False; + + data_offset = ctr->values[i].value_len + valuename_offset; + + if (!prs_uint32("data_offset", ps, depth, &data_offset)) + return False; + + if (!prs_uint32("data_len", ps, depth, &ctr->values[i].data_len)) + return False; + + /* Read or write the data. */ + + return_offset = prs_offset(ps); + + if (!prs_set_offset(ps, base_offset + data_offset)) { + return False; + } + + if ( ctr->values[i].data_len ) { + if ( UNMARSHALLING(ps) ) { + ctr->values[i].data = PRS_ALLOC_MEM(ps, uint8, ctr->values[i].data_len); + if (!ctr->values[i].data) + return False; + } + if (!prs_uint8s(False, "data", ps, depth, ctr->values[i].data, ctr->values[i].data_len)) + return False; + } + + current_offset = data_offset + ctr->values[i].data_len - basic_unit; + /* account for 2 byte alignment */ + current_offset += (current_offset % 2); + + /* Remember how far we got. */ + data_offset = prs_offset(ps); + + /* And go back. */ + if (!prs_set_offset(ps, return_offset)) + return False; + + } + + /* Go to the last data offset we got to. */ + + if (!prs_set_offset(ps, data_offset)) + return False; + + /* And ensure we're 2 byte aligned. */ + + if ( !prs_align_uint16(ps) ) + return False; + + return True; +} + +/******************************************************************* + * write a structure. + ********************************************************************/ + +bool spoolss_io_r_enumprinterdataex(const char *desc, SPOOL_R_ENUMPRINTERDATAEX *r_u, prs_struct *ps, int depth) +{ + uint32 data_offset, end_offset; + prs_debug(ps, depth, desc, "spoolss_io_r_enumprinterdataex"); + depth++; + + if(!prs_align(ps)) + return False; + + if (!prs_uint32("size", ps, depth, &r_u->ctr.size)) + return False; + + data_offset = prs_offset(ps); + + if (!prs_set_offset(ps, data_offset + r_u->ctr.size)) + return False; + + if(!prs_align(ps)) + return False; + + if(!prs_uint32("needed", ps, depth, &r_u->needed)) + return False; + + if(!prs_uint32("returned", ps, depth, &r_u->returned)) + return False; + + if(!prs_werror("status", ps, depth, &r_u->status)) + return False; + + r_u->ctr.size_of_array = r_u->returned; + + end_offset = prs_offset(ps); + + if (!prs_set_offset(ps, data_offset)) + return False; + + if (r_u->ctr.size) + if (!spoolss_io_printer_enum_values_ctr("", ps, &r_u->ctr, depth )) + return False; + + if (!prs_set_offset(ps, end_offset)) + return False; + return True; +} + +/******************************************************************* + * write a structure. + ********************************************************************/ + +/* + uint32 GetPrintProcessorDirectory( + [in] unistr2 *name, + [in] unistr2 *environment, + [in] uint32 level, + [in,out] RPC_BUFFER buffer, + [in] uint32 offered, + [out] uint32 needed, + [out] uint32 returned + ); + +*/ + +bool make_spoolss_q_getprintprocessordirectory(SPOOL_Q_GETPRINTPROCESSORDIRECTORY *q_u, const char *name, char *environment, int level, RPC_BUFFER *buffer, uint32 offered) +{ + DEBUG(5,("make_spoolss_q_getprintprocessordirectory\n")); + + init_unistr2(&q_u->name, name, UNI_STR_TERMINATE); + init_unistr2(&q_u->environment, environment, UNI_STR_TERMINATE); + + q_u->level = level; + + q_u->buffer = buffer; + q_u->offered = offered; + + return True; +} + +bool spoolss_io_q_getprintprocessordirectory(const char *desc, SPOOL_Q_GETPRINTPROCESSORDIRECTORY *q_u, prs_struct *ps, int depth) +{ + uint32 ptr = 0; + + prs_debug(ps, depth, desc, "spoolss_io_q_getprintprocessordirectory"); + depth++; + + if(!prs_align(ps)) + return False; + + if (!prs_uint32("ptr", ps, depth, &ptr)) + return False; + + if (ptr) { + if(!smb_io_unistr2("name", &q_u->name, True, ps, depth)) + return False; + } + + if (!prs_align(ps)) + return False; + + if (!prs_uint32("ptr", ps, depth, &ptr)) + return False; + + if (ptr) { + if(!smb_io_unistr2("environment", &q_u->environment, True, + ps, depth)) + return False; + } + + if (!prs_align(ps)) + return False; + + if(!prs_uint32("level", ps, depth, &q_u->level)) + return False; + + if(!prs_rpcbuffer_p("", 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; +} + +/******************************************************************* + * write a structure. + ********************************************************************/ + +bool spoolss_io_r_getprintprocessordirectory(const char *desc, SPOOL_R_GETPRINTPROCESSORDIRECTORY *r_u, prs_struct *ps, int depth) +{ + prs_debug(ps, depth, desc, "spoolss_io_r_getprintprocessordirectory"); + depth++; + + if(!prs_align(ps)) + return False; + + if(!prs_rpcbuffer_p("", 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_werror("status", ps, depth, &r_u->status)) + return False; + + return True; +} + +bool smb_io_printprocessordirectory_1(const char *desc, RPC_BUFFER *buffer, PRINTPROCESSOR_DIRECTORY_1 *info, int depth) +{ + prs_struct *ps=&buffer->prs; + + prs_debug(ps, depth, desc, "smb_io_printprocessordirectory_1"); + depth++; + + buffer->struct_start=prs_offset(ps); + + if (!smb_io_unistr(desc, &info->name, ps, depth)) + return False; + + return True; +} + +/******************************************************************* + * init a structure. + ********************************************************************/ + +bool make_spoolss_q_addform(SPOOL_Q_ADDFORM *q_u, POLICY_HND *handle, + int level, FORM *form) +{ + memcpy(&q_u->handle, handle, sizeof(POLICY_HND)); + q_u->level = level; + q_u->level2 = level; + memcpy(&q_u->form, form, sizeof(FORM)); + + return True; +} + +/******************************************************************* + * init a structure. + ********************************************************************/ + +bool make_spoolss_q_setform(SPOOL_Q_SETFORM *q_u, POLICY_HND *handle, + int level, const char *form_name, FORM *form) +{ + memcpy(&q_u->handle, handle, sizeof(POLICY_HND)); + q_u->level = level; + q_u->level2 = level; + memcpy(&q_u->form, form, sizeof(FORM)); + init_unistr2(&q_u->name, form_name, UNI_STR_TERMINATE); + + return True; +} + +/******************************************************************* + * init a structure. + ********************************************************************/ + +bool make_spoolss_q_deleteform(SPOOL_Q_DELETEFORM *q_u, POLICY_HND *handle, + const char *form) +{ + memcpy(&q_u->handle, handle, sizeof(POLICY_HND)); + init_unistr2(&q_u->name, form, UNI_STR_TERMINATE); + return True; +} + +/******************************************************************* + * init a structure. + ********************************************************************/ + +bool make_spoolss_q_getform(SPOOL_Q_GETFORM *q_u, POLICY_HND *handle, + const char *formname, uint32 level, + RPC_BUFFER *buffer, uint32 offered) +{ + memcpy(&q_u->handle, handle, sizeof(POLICY_HND)); + q_u->level = level; + init_unistr2(&q_u->formname, formname, UNI_STR_TERMINATE); + q_u->buffer=buffer; + q_u->offered=offered; + + return True; +} + +/******************************************************************* + * init a structure. + ********************************************************************/ + +bool make_spoolss_q_enumforms(SPOOL_Q_ENUMFORMS *q_u, POLICY_HND *handle, + uint32 level, RPC_BUFFER *buffer, + uint32 offered) +{ + memcpy(&q_u->handle, handle, sizeof(POLICY_HND)); + q_u->level = level; + q_u->buffer=buffer; + q_u->offered=offered; + + return True; +} + +/******************************************************************* + * init a structure. + ********************************************************************/ + +bool make_spoolss_q_setjob(SPOOL_Q_SETJOB *q_u, POLICY_HND *handle, + uint32 jobid, uint32 level, uint32 command) +{ + memcpy(&q_u->handle, handle, sizeof(POLICY_HND)); + q_u->jobid = jobid; + q_u->level = level; + + /* Hmm - the SPOOL_Q_SETJOB structure has a JOB_INFO ctr in it but + the server side code has it marked as unused. */ + + q_u->command = command; + + return True; +} + +/******************************************************************* + * init a structure. + ********************************************************************/ + +bool make_spoolss_q_getjob(SPOOL_Q_GETJOB *q_u, POLICY_HND *handle, + uint32 jobid, uint32 level, RPC_BUFFER *buffer, + uint32 offered) +{ + memcpy(&q_u->handle, handle, sizeof(POLICY_HND)); + q_u->jobid = jobid; + q_u->level = level; + q_u->buffer = buffer; + q_u->offered = offered; + + return True; +} + +/******************************************************************* + * init a structure. + ********************************************************************/ + +bool make_spoolss_q_startpageprinter(SPOOL_Q_STARTPAGEPRINTER *q_u, + POLICY_HND *handle) +{ + memcpy(&q_u->handle, handle, sizeof(POLICY_HND)); + + return True; +} + +/******************************************************************* + * init a structure. + ********************************************************************/ + +bool make_spoolss_q_endpageprinter(SPOOL_Q_ENDPAGEPRINTER *q_u, + POLICY_HND *handle) +{ + memcpy(&q_u->handle, handle, sizeof(POLICY_HND)); + + return True; +} + +/******************************************************************* + * init a structure. + ********************************************************************/ + +bool make_spoolss_q_startdocprinter(SPOOL_Q_STARTDOCPRINTER *q_u, + POLICY_HND *handle, uint32 level, + char *docname, char *outputfile, + char *datatype) +{ + DOC_INFO_CONTAINER *ctr = &q_u->doc_info_container; + + memcpy(&q_u->handle, handle, sizeof(POLICY_HND)); + + ctr->level = level; + + switch (level) { + case 1: + ctr->docinfo.switch_value = level; + + ctr->docinfo.doc_info_1.p_docname = docname ? 1 : 0; + ctr->docinfo.doc_info_1.p_outputfile = outputfile ? 1 : 0; + ctr->docinfo.doc_info_1.p_datatype = datatype ? 1 : 0; + + init_unistr2(&ctr->docinfo.doc_info_1.docname, docname, UNI_STR_TERMINATE); + init_unistr2(&ctr->docinfo.doc_info_1.outputfile, outputfile, UNI_STR_TERMINATE); + init_unistr2(&ctr->docinfo.doc_info_1.datatype, datatype, UNI_STR_TERMINATE); + + break; + case 2: + /* DOC_INFO_2 is only used by Windows 9x and since it + doesn't do printing over RPC we don't have to worry + about it. */ + default: + DEBUG(3, ("unsupported info level %d\n", level)); + return False; + } + + return True; +} + +/******************************************************************* + * init a structure. + ********************************************************************/ + +bool make_spoolss_q_enddocprinter(SPOOL_Q_ENDDOCPRINTER *q_u, + POLICY_HND *handle) +{ + memcpy(&q_u->handle, handle, sizeof(POLICY_HND)); + + return True; +} + +/******************************************************************* + * init a structure. + ********************************************************************/ + +bool make_spoolss_q_writeprinter(SPOOL_Q_WRITEPRINTER *q_u, + POLICY_HND *handle, uint32 data_size, + char *data) +{ + memcpy(&q_u->handle, handle, sizeof(POLICY_HND)); + q_u->buffer_size = q_u->buffer_size2 = data_size; + q_u->buffer = (unsigned char *)data; + return True; +} + +/******************************************************************* + * init a structure. + ********************************************************************/ + +bool make_spoolss_q_deleteprinterdata(SPOOL_Q_DELETEPRINTERDATA *q_u, + POLICY_HND *handle, char *valuename) +{ + memcpy(&q_u->handle, handle, sizeof(POLICY_HND)); + init_unistr2(&q_u->valuename, valuename, UNI_STR_TERMINATE); + + return True; +} + +/******************************************************************* + * init a structure. + ********************************************************************/ + +bool make_spoolss_q_deleteprinterdataex(SPOOL_Q_DELETEPRINTERDATAEX *q_u, + POLICY_HND *handle, char *key, + char *value) +{ + memcpy(&q_u->handle, handle, sizeof(POLICY_HND)); + init_unistr2(&q_u->valuename, value, UNI_STR_TERMINATE); + init_unistr2(&q_u->keyname, key, UNI_STR_TERMINATE); + + return True; +} + +/******************************************************************* + * init a structure. + ********************************************************************/ + +bool make_spoolss_q_rffpcnex(SPOOL_Q_RFFPCNEX *q_u, POLICY_HND *handle, + uint32 flags, uint32 options, const char *localmachine, + uint32 printerlocal, SPOOL_NOTIFY_OPTION *option) +{ + memcpy(&q_u->handle, handle, sizeof(POLICY_HND)); + + q_u->flags = flags; + q_u->options = options; + + q_u->localmachine_ptr = 1; + + init_unistr2(&q_u->localmachine, localmachine, UNI_STR_TERMINATE); + + q_u->printerlocal = printerlocal; + + if (option) + q_u->option_ptr = 1; + + q_u->option = option; + + return True; +} + + +/******************************************************************* + ********************************************************************/ + +bool spoolss_io_q_xcvdataport(const char *desc, SPOOL_Q_XCVDATAPORT *q_u, prs_struct *ps, int depth) +{ + prs_debug(ps, depth, desc, "spoolss_io_q_xcvdataport"); + 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->dataname, True, ps, depth)) + return False; + + if (!prs_align(ps)) + return False; + + if(!prs_rpcbuffer("", ps, depth, &q_u->indata)) + return False; + + if (!prs_align(ps)) + return False; + + if (!prs_uint32("indata_len", ps, depth, &q_u->indata_len)) + return False; + if (!prs_uint32("offered", ps, depth, &q_u->offered)) + return False; + if (!prs_uint32("unknown", ps, depth, &q_u->unknown)) + return False; + + return True; +} + +/******************************************************************* + ********************************************************************/ + +bool spoolss_io_r_xcvdataport(const char *desc, SPOOL_R_XCVDATAPORT *r_u, prs_struct *ps, int depth) +{ + prs_debug(ps, depth, desc, "spoolss_io_r_xcvdataport"); + depth++; + + if(!prs_align(ps)) + return False; + if(!prs_rpcbuffer("", ps, depth, &r_u->outdata)) + return False; + + if (!prs_align(ps)) + return False; + + if (!prs_uint32("needed", ps, depth, &r_u->needed)) + return False; + if (!prs_uint32("unknown", ps, depth, &r_u->unknown)) + return False; + + if(!prs_werror("status", ps, depth, &r_u->status)) + return False; + + return True; +} + +/******************************************************************* + ********************************************************************/ + +bool make_monitorui_buf( RPC_BUFFER *buf, const char *dllname ) +{ + UNISTR string; + + if ( !buf ) + return False; + + init_unistr( &string, dllname ); + + if ( !prs_unistr( "ui_dll", &buf->prs, 0, &string ) ) + return False; + + return True; +} + +/******************************************************************* + ********************************************************************/ + +#define PORT_DATA_1_PAD 540 + +static bool smb_io_port_data_1( const char *desc, RPC_BUFFER *buf, int depth, SPOOL_PORT_DATA_1 *p1 ) +{ + prs_struct *ps = &buf->prs; + uint8 padding[PORT_DATA_1_PAD]; + + prs_debug(ps, depth, desc, "smb_io_port_data_1"); + depth++; + + if(!prs_align(ps)) + return False; + + if( !prs_uint16s(True, "portname", ps, depth, p1->portname, MAX_PORTNAME)) + return False; + + if (!prs_uint32("version", ps, depth, &p1->version)) + return False; + if (!prs_uint32("protocol", ps, depth, &p1->protocol)) + return False; + if (!prs_uint32("size", ps, depth, &p1->size)) + return False; + if (!prs_uint32("reserved", ps, depth, &p1->reserved)) + return False; + + if( !prs_uint16s(True, "hostaddress", ps, depth, p1->hostaddress, MAX_NETWORK_NAME)) + return False; + if( !prs_uint16s(True, "snmpcommunity", ps, depth, p1->snmpcommunity, MAX_SNMP_COMM_NAME)) + return False; + + if (!prs_uint32("dblspool", ps, depth, &p1->dblspool)) + return False; + + if( !prs_uint16s(True, "queue", ps, depth, p1->queue, MAX_QUEUE_NAME)) + return False; + if( !prs_uint16s(True, "ipaddress", ps, depth, p1->ipaddress, MAX_IPADDR_STRING)) + return False; + + if( !prs_uint8s(False, "", ps, depth, padding, PORT_DATA_1_PAD)) + return False; + + if (!prs_uint32("port", ps, depth, &p1->port)) + return False; + if (!prs_uint32("snmpenabled", ps, depth, &p1->snmpenabled)) + return False; + if (!prs_uint32("snmpdevindex", ps, depth, &p1->snmpdevindex)) + return False; + + return True; +} + +/******************************************************************* + ********************************************************************/ + +bool convert_port_data_1( NT_PORT_DATA_1 *port1, RPC_BUFFER *buf ) +{ + SPOOL_PORT_DATA_1 spdata_1; + + ZERO_STRUCT( spdata_1 ); + + if ( !smb_io_port_data_1( "port_data_1", buf, 0, &spdata_1 ) ) + return False; + + rpcstr_pull(port1->name, spdata_1.portname, sizeof(port1->name), -1, 0); + rpcstr_pull(port1->queue, spdata_1.queue, sizeof(port1->queue), -1, 0); + rpcstr_pull(port1->hostaddr, spdata_1.hostaddress, sizeof(port1->hostaddr), -1, 0); + + port1->port = spdata_1.port; + + switch ( spdata_1.protocol ) { + case 1: + port1->protocol = PORT_PROTOCOL_DIRECT; + break; + case 2: + port1->protocol = PORT_PROTOCOL_LPR; + break; + default: + DEBUG(3,("convert_port_data_1: unknown protocol [%d]!\n", + spdata_1.protocol)); + return False; + } + + return True; +} diff --git a/source3/rpc_parse/parse_svcctl.c b/source3/rpc_parse/parse_svcctl.c new file mode 100644 index 0000000000..c5d93864ba --- /dev/null +++ b/source3/rpc_parse/parse_svcctl.c @@ -0,0 +1,535 @@ +/* + * Unix SMB/CIFS implementation. + * RPC Pipe client / server routines + * Copyright (C) Gerald (Jerry) Carter 2005. + * + * 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 + * the Free Software Foundation; either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, see <http://www.gnu.org/licenses/>. + */ + +#include "includes.h" + +#undef DBGC_CLASS +#define DBGC_CLASS DBGC_RPC_PARSE + +/******************************************************************* +********************************************************************/ + +static bool svcctl_io_service_status( const char *desc, SERVICE_STATUS *status, prs_struct *ps, int depth ) +{ + + prs_debug(ps, depth, desc, "svcctl_io_service_status"); + depth++; + + if(!prs_uint32("type", ps, depth, &status->type)) + return False; + + if(!prs_uint32("state", ps, depth, &status->state)) + return False; + + if(!prs_uint32("controls_accepted", ps, depth, &status->controls_accepted)) + return False; + + if(!prs_werror("win32_exit_code", ps, depth, &status->win32_exit_code)) + return False; + + if(!prs_uint32("service_exit_code", ps, depth, &status->service_exit_code)) + return False; + + if(!prs_uint32("check_point", ps, depth, &status->check_point)) + return False; + + if(!prs_uint32("wait_hint", ps, depth, &status->wait_hint)) + return False; + + return True; +} + +/******************************************************************* +********************************************************************/ + +static bool svcctl_io_service_config( const char *desc, SERVICE_CONFIG *config, prs_struct *ps, int depth ) +{ + + prs_debug(ps, depth, desc, "svcctl_io_service_config"); + depth++; + + if(!prs_uint32("service_type", ps, depth, &config->service_type)) + return False; + if(!prs_uint32("start_type", ps, depth, &config->start_type)) + return False; + if(!prs_uint32("error_control", ps, depth, &config->error_control)) + return False; + + if (!prs_io_unistr2_p("", ps, depth, &config->executablepath)) + return False; + if (!prs_io_unistr2_p("", ps, depth, &config->loadordergroup)) + return False; + + if(!prs_uint32("tag_id", ps, depth, &config->tag_id)) + return False; + + if (!prs_io_unistr2_p("", ps, depth, &config->dependencies)) + return False; + if (!prs_io_unistr2_p("", ps, depth, &config->startname)) + return False; + if (!prs_io_unistr2_p("", ps, depth, &config->displayname)) + return False; + + if (!prs_io_unistr2("", ps, depth, config->executablepath)) + return False; + if (!prs_io_unistr2("", ps, depth, config->loadordergroup)) + return False; + if (!prs_io_unistr2("", ps, depth, config->dependencies)) + return False; + if (!prs_io_unistr2("", ps, depth, config->startname)) + return False; + if (!prs_io_unistr2("", ps, depth, config->displayname)) + return False; + + return True; +} + +/******************************************************************* +********************************************************************/ + +bool svcctl_io_enum_services_status( const char *desc, ENUM_SERVICES_STATUS *enum_status, RPC_BUFFER *buffer, int depth ) +{ + prs_struct *ps=&buffer->prs; + + prs_debug(ps, depth, desc, "svcctl_io_enum_services_status"); + depth++; + + if ( !smb_io_relstr("servicename", buffer, depth, &enum_status->servicename) ) + return False; + if ( !smb_io_relstr("displayname", buffer, depth, &enum_status->displayname) ) + return False; + + if ( !svcctl_io_service_status("svc_status", &enum_status->status, ps, depth) ) + return False; + + return True; +} + +/******************************************************************* +********************************************************************/ + +bool svcctl_io_service_status_process( const char *desc, SERVICE_STATUS_PROCESS *status, RPC_BUFFER *buffer, int depth ) +{ + prs_struct *ps=&buffer->prs; + + prs_debug(ps, depth, desc, "svcctl_io_service_status_process"); + depth++; + + if ( !svcctl_io_service_status("status", &status->status, ps, depth) ) + return False; + if(!prs_align(ps)) + return False; + + if(!prs_uint32("process_id", ps, depth, &status->process_id)) + return False; + if(!prs_uint32("service_flags", ps, depth, &status->service_flags)) + return False; + + return True; +} + +/******************************************************************* +********************************************************************/ + +uint32 svcctl_sizeof_enum_services_status( ENUM_SERVICES_STATUS *status ) +{ + uint32 size = 0; + + size += size_of_relative_string( &status->servicename ); + size += size_of_relative_string( &status->displayname ); + size += sizeof(SERVICE_STATUS); + + return size; +} + +/******************************************************************** +********************************************************************/ + +static uint32 sizeof_unistr2( UNISTR2 *string ) +{ + uint32 size = 0; + + if ( !string ) + return 0; + + size = sizeof(uint32) * 3; /* length fields */ + size += 2 * string->uni_max_len; /* string data */ + size += size % 4; /* alignment */ + + return size; +} + +/******************************************************************** +********************************************************************/ + +uint32 svcctl_sizeof_service_config( SERVICE_CONFIG *config ) +{ + uint32 size = 0; + + size = sizeof(uint32) * 4; /* static uint32 fields */ + + /* now add the UNISTR2 + pointer sizes */ + + size += sizeof(uint32) * sizeof_unistr2(config->executablepath); + size += sizeof(uint32) * sizeof_unistr2(config->loadordergroup); + size += sizeof(uint32) * sizeof_unistr2(config->dependencies); + size += sizeof(uint32) * sizeof_unistr2(config->startname); + size += sizeof(uint32) * sizeof_unistr2(config->displayname); + + return size; +} + +/******************************************************************* +********************************************************************/ + +bool svcctl_io_q_enum_services_status(const char *desc, SVCCTL_Q_ENUM_SERVICES_STATUS *q_u, prs_struct *ps, int depth) +{ + if (q_u == NULL) + return False; + + prs_debug(ps, depth, desc, "svcctl_io_q_enum_services_status"); + depth++; + + if(!prs_align(ps)) + return False; + + if(!smb_io_pol_hnd("scm_pol", &q_u->handle, ps, depth)) + return False; + + if(!prs_uint32("type", ps, depth, &q_u->type)) + return False; + if(!prs_uint32("state", ps, depth, &q_u->state)) + return False; + if(!prs_uint32("buffer_size", ps, depth, &q_u->buffer_size)) + return False; + + if(!prs_pointer("resume", ps, depth, (void*)&q_u->resume, sizeof(uint32), (PRS_POINTER_CAST)prs_uint32)) + return False; + + return True; +} + +/******************************************************************* +********************************************************************/ + +bool svcctl_io_r_enum_services_status(const char *desc, SVCCTL_R_ENUM_SERVICES_STATUS *r_u, prs_struct *ps, int depth) +{ + if (r_u == NULL) + return False; + + prs_debug(ps, depth, desc, "svcctl_io_r_enum_services_status"); + depth++; + + if(!prs_align(ps)) + return False; + + if (!prs_rpcbuffer("", 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("returned", ps, depth, &r_u->returned)) + return False; + + if(!prs_pointer("resume", ps, depth, (void*)&r_u->resume, sizeof(uint32), (PRS_POINTER_CAST)prs_uint32)) + return False; + + if(!prs_werror("status", ps, depth, &r_u->status)) + return False; + + return True; +} + +/******************************************************************* +********************************************************************/ + +bool svcctl_io_q_query_service_config(const char *desc, SVCCTL_Q_QUERY_SERVICE_CONFIG *q_u, prs_struct *ps, int depth) +{ + if (q_u == NULL) + return False; + + prs_debug(ps, depth, desc, "svcctl_io_q_query_service_config"); + depth++; + + if(!prs_align(ps)) + return False; + + if(!smb_io_pol_hnd("service_pol", &q_u->handle, ps, depth)) + return False; + + if(!prs_uint32("buffer_size", ps, depth, &q_u->buffer_size)) + return False; + + return True; +} + +/******************************************************************* +********************************************************************/ + +bool svcctl_io_r_query_service_config(const char *desc, SVCCTL_R_QUERY_SERVICE_CONFIG *r_u, prs_struct *ps, int depth) +{ + if (r_u == NULL) + return False; + + prs_debug(ps, depth, desc, "svcctl_io_r_query_service_config"); + depth++; + + + if(!prs_align(ps)) + return False; + + if(!svcctl_io_service_config("config", &r_u->config, ps, depth)) + return False; + + if(!prs_uint32("needed", ps, depth, &r_u->needed)) + return False; + + if(!prs_werror("status", ps, depth, &r_u->status)) + return False; + + + return True; +} + +/******************************************************************* +********************************************************************/ + +bool svcctl_io_q_query_service_config2(const char *desc, SVCCTL_Q_QUERY_SERVICE_CONFIG2 *q_u, prs_struct *ps, int depth) +{ + if (q_u == NULL) + return False; + + prs_debug(ps, depth, desc, "svcctl_io_q_query_service_config2"); + depth++; + + if(!prs_align(ps)) + return False; + + if(!smb_io_pol_hnd("service_pol", &q_u->handle, ps, depth)) + return False; + + if(!prs_uint32("level", ps, depth, &q_u->level)) + return False; + + if(!prs_uint32("buffer_size", ps, depth, &q_u->buffer_size)) + return False; + + return True; +} + + +/******************************************************************* +********************************************************************/ + +void init_service_description_buffer(SERVICE_DESCRIPTION *desc, const char *service_desc ) +{ + desc->unknown = 0x04; /* always 0x0000 0004 (no idea what this is) */ + init_unistr( &desc->description, service_desc ); +} + +/******************************************************************* +********************************************************************/ + +bool svcctl_io_service_description( const char *desc, SERVICE_DESCRIPTION *description, RPC_BUFFER *buffer, int depth ) +{ + prs_struct *ps = &buffer->prs; + + prs_debug(ps, depth, desc, "svcctl_io_service_description"); + depth++; + + if ( !prs_uint32("unknown", ps, depth, &description->unknown) ) + return False; + if ( !prs_unistr("description", ps, depth, &description->description) ) + return False; + + return True; +} + +/******************************************************************* +********************************************************************/ + +uint32 svcctl_sizeof_service_description( SERVICE_DESCRIPTION *desc ) +{ + if ( !desc ) + return 0; + + /* make sure to include the terminating NULL */ + return ( sizeof(uint32) + (2*(str_len_uni(&desc->description)+1)) ); +} + +/******************************************************************* +********************************************************************/ + +static bool svcctl_io_action( const char *desc, SC_ACTION *action, prs_struct *ps, int depth ) +{ + + prs_debug(ps, depth, desc, "svcctl_io_action"); + depth++; + + if ( !prs_uint32("type", ps, depth, &action->type) ) + return False; + if ( !prs_uint32("delay", ps, depth, &action->delay) ) + return False; + + return True; +} + +/******************************************************************* +********************************************************************/ + +bool svcctl_io_service_fa( const char *desc, SERVICE_FAILURE_ACTIONS *fa, RPC_BUFFER *buffer, int depth ) +{ + prs_struct *ps = &buffer->prs; + int i; + + prs_debug(ps, depth, desc, "svcctl_io_service_description"); + depth++; + + if ( !prs_uint32("reset_period", ps, depth, &fa->reset_period) ) + return False; + + if ( !prs_pointer( desc, ps, depth, (void*)&fa->rebootmsg, sizeof(UNISTR2), (PRS_POINTER_CAST)prs_io_unistr2 ) ) + return False; + if ( !prs_pointer( desc, ps, depth, (void*)&fa->command, sizeof(UNISTR2), (PRS_POINTER_CAST)prs_io_unistr2 ) ) + return False; + + if ( !prs_uint32("num_actions", ps, depth, &fa->num_actions) ) + return False; + + if ( UNMARSHALLING(ps)) { + if (fa->num_actions) { + if ( !(fa->actions = TALLOC_ARRAY( talloc_tos(), SC_ACTION, fa->num_actions )) ) { + DEBUG(0,("svcctl_io_service_fa: talloc() failure!\n")); + return False; + } + } else { + fa->actions = NULL; + } + } + + for ( i=0; i<fa->num_actions; i++ ) { + if ( !svcctl_io_action( "actions", &fa->actions[i], ps, depth ) ) + return False; + } + + return True; +} + +/******************************************************************* +********************************************************************/ + +uint32 svcctl_sizeof_service_fa( SERVICE_FAILURE_ACTIONS *fa) +{ + uint32 size = 0; + + if ( !fa ) + return 0; + + size = sizeof(uint32) * 2; + size += sizeof_unistr2( fa->rebootmsg ); + size += sizeof_unistr2( fa->command ); + size += sizeof(SC_ACTION) * fa->num_actions; + + return size; +} + +/******************************************************************* +********************************************************************/ + +bool svcctl_io_r_query_service_config2(const char *desc, SVCCTL_R_QUERY_SERVICE_CONFIG2 *r_u, prs_struct *ps, int depth) +{ + if ( !r_u ) + return False; + + prs_debug(ps, depth, desc, "svcctl_io_r_query_service_config2"); + depth++; + + if ( !prs_align(ps) ) + return False; + + if (!prs_rpcbuffer("", 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_werror("status", ps, depth, &r_u->status)) + return False; + + return True; +} + + +/******************************************************************* +********************************************************************/ + +bool svcctl_io_q_query_service_status_ex(const char *desc, SVCCTL_Q_QUERY_SERVICE_STATUSEX *q_u, prs_struct *ps, int depth) +{ + if (q_u == NULL) + return False; + + prs_debug(ps, depth, desc, "svcctl_io_q_query_service_status_ex"); + depth++; + + if(!prs_align(ps)) + return False; + + if(!smb_io_pol_hnd("service_pol", &q_u->handle, ps, depth)) + return False; + + if(!prs_uint32("level", ps, depth, &q_u->level)) + return False; + + if(!prs_uint32("buffer_size", ps, depth, &q_u->buffer_size)) + return False; + + return True; + +} + +/******************************************************************* +********************************************************************/ + +bool svcctl_io_r_query_service_status_ex(const char *desc, SVCCTL_R_QUERY_SERVICE_STATUSEX *r_u, prs_struct *ps, int depth) +{ + if ( !r_u ) + return False; + + prs_debug(ps, depth, desc, "svcctl_io_r_query_service_status_ex"); + depth++; + + if (!prs_rpcbuffer("", 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_werror("status", ps, depth, &r_u->status)) + return False; + + return True; +} |