diff options
author | Andrew Bartlett <abartlet@samba.org> | 2009-03-20 13:22:08 +1100 |
---|---|---|
committer | Andrew Bartlett <abartlet@samba.org> | 2009-03-20 13:22:08 +1100 |
commit | 27c6eca04c4c1bb40ff36f3a08748e2f45770aa8 (patch) | |
tree | f87d3e6ca4958e9b9102ca8ee5fb3e5f0917570e /source3/rpc_parse | |
parent | 1f25b71d199a072f5ee1bdd8786e5c1c157f5888 (diff) | |
parent | 5fe2b28f45289dc5578cdd536600f0d30a14d820 (diff) | |
download | samba-27c6eca04c4c1bb40ff36f3a08748e2f45770aa8.tar.gz samba-27c6eca04c4c1bb40ff36f3a08748e2f45770aa8.tar.bz2 samba-27c6eca04c4c1bb40ff36f3a08748e2f45770aa8.zip |
Merge branch 'master' of ssh://git.samba.org/data/git/samba into wspp-schema
Diffstat (limited to 'source3/rpc_parse')
-rw-r--r-- | source3/rpc_parse/parse_buffer.c | 509 | ||||
-rw-r--r-- | source3/rpc_parse/parse_misc.c | 473 | ||||
-rw-r--r-- | source3/rpc_parse/parse_prs.c | 85 | ||||
-rw-r--r-- | source3/rpc_parse/parse_rpc.c | 10 | ||||
-rw-r--r-- | source3/rpc_parse/parse_spoolss.c | 2440 |
5 files changed, 60 insertions, 3457 deletions
diff --git a/source3/rpc_parse/parse_buffer.c b/source3/rpc_parse/parse_buffer.c deleted file mode 100644 index 99546ef3fb..0000000000 --- a/source3/rpc_parse/parse_buffer.c +++ /dev/null @@ -1,509 +0,0 @@ -/* - * 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 -**********************************************************************/ -bool 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)) - return false; - - buffer->struct_start = prs_offset(&buffer->prs); - return true; -} - -/******************************************************************* - 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, NULL, 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_misc.c b/source3/rpc_parse/parse_misc.c index 38d5b95376..8b4135a1e8 100644 --- a/source3/rpc_parse/parse_misc.c +++ b/source3/rpc_parse/parse_misc.c @@ -59,12 +59,45 @@ bool smb_io_time(const char *desc, NTTIME *nttime, prs_struct *ps, int depth) } /******************************************************************* - Reads or writes an NTTIME structure. ********************************************************************/ -bool smb_io_nttime(const char *desc, prs_struct *ps, int depth, NTTIME *nttime) +bool smb_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) { - return smb_io_time( desc, nttime, ps, depth ); + 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; } /******************************************************************* @@ -153,100 +186,6 @@ void init_unistr(UNISTR *str, const char *buf) } /******************************************************************* -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; -} - -/******************************************************************* -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; -} - -/******************************************************************* -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; - } - } -} - -/******************************************************************* Inits a UNISTR2 structure. ********************************************************************/ @@ -301,343 +240,3 @@ void init_unistr2(UNISTR2 *str, const char *buf, enum unistr2_term_codes flags) if ( num_chars && ((flags == UNI_MAXLEN_TERMINATE) || (flags == UNI_BROKEN_NON_NULL)) ) str->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; -} - -/******************************************************************* - 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); - } -} - -/******************************************************************* -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_prs.c b/source3/rpc_parse/parse_prs.c index bc9202cccc..94732b0a74 100644 --- a/source3/rpc_parse/parse_prs.c +++ b/source3/rpc_parse/parse_prs.c @@ -760,6 +760,30 @@ bool prs_int32(const char *name, prs_struct *ps, int depth, int32 *data32) } /******************************************************************* + 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); + } +} + +/******************************************************************* Stream a NTSTATUS ********************************************************************/ @@ -1025,37 +1049,6 @@ bool prs_uint32s(bool charmode, const char *name, prs_struct *ps, int depth, uin } /****************************************************************** - 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 unicode string, length/buffer specified separately, in uint16 chars. The unicode string is already in little-endian format. ********************************************************************/ @@ -1093,36 +1086,6 @@ bool prs_unistr2(bool charmode, const char *name, prs_struct *ps, int depth, UNI 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. diff --git a/source3/rpc_parse/parse_rpc.c b/source3/rpc_parse/parse_rpc.c index 1477a4c81e..14a4effbf0 100644 --- a/source3/rpc_parse/parse_rpc.c +++ b/source3/rpc_parse/parse_rpc.c @@ -639,13 +639,3 @@ bool smb_io_rpc_auth_schannel_chk(const char *desc, int auth_len, 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_spoolss.c b/source3/rpc_parse/parse_spoolss.c deleted file mode 100644 index 337121d70d..0000000000 --- a/source3/rpc_parse/parse_spoolss.c +++ /dev/null @@ -1,2440 +0,0 @@ -/* - * 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; -} - -/******************************************************************* - * 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; -} - -/******************************************************************* - * 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; -} - -/******************************************************************* - * 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; -} - -/******************************************************************* - * 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; -} - -/******************************************************************* - * 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 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; -} - -/******************************************************************* -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, NULL, 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, NULL, 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_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; -} - -/******************************************************************* - * 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; -} - -/******************************************************************* - * 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; -} - -/******************************************************************* -********************************************************************/ - -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; -} - -/******************************************************************* - 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; -} - -/******************************************************************* - 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; -} - -/******************************************************************* -********************************************************************/ - -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 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; -} - -/******************************************************************* - 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); -} - -/******************************************************************* - * 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 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; -} |