/*
- * Unix SMB/Netbios implementation.
- * Version 1.9.
+ * Unix SMB/CIFS implementation.
* RPC Pipe client / server routines
* Copyright (C) Andrew Tridgell 1992-1997,
* Copyright (C) Luke Kenneth Casson Leighton 1996-1997,
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
-
#include "includes.h"
-extern int DEBUGLEVEL;
+#undef DBGC_CLASS
+#define DBGC_CLASS DBGC_RPC_PARSE
+
+/****************************************************************************
+ A temporary TALLOC context for things like unistrs, that is valid for
+ the life of a complete RPC call.
+****************************************************************************/
-static TALLOC_CTX *parse_misc_talloc = NULL;
+static TALLOC_CTX *current_rpc_talloc = NULL;
-/******************************************************************* a
+TALLOC_CTX *get_current_rpc_talloc(void)
+{
+ return current_rpc_talloc;
+}
+
+void set_current_rpc_talloc( TALLOC_CTX *ctx)
+{
+ current_rpc_talloc = ctx;
+}
+
+static TALLOC_CTX *main_loop_talloc = NULL;
+
+/*******************************************************************
free up temporary memory - called from the main loop
********************************************************************/
-void parse_talloc_free(void)
+void main_loop_talloc_free(void)
{
- if (!parse_misc_talloc)
+ if (!main_loop_talloc)
return;
- talloc_destroy(parse_misc_talloc);
- parse_misc_talloc = NULL;
+ talloc_destroy(main_loop_talloc);
+ main_loop_talloc = NULL;
+}
+
+/*******************************************************************
+ Get a talloc context that is freed in the main loop...
+********************************************************************/
+
+TALLOC_CTX *main_loop_talloc_get(void)
+{
+ if (!main_loop_talloc) {
+ main_loop_talloc = talloc_init("main loop talloc (mainly parse_misc)");
+ if (!main_loop_talloc)
+ smb_panic("main_loop_talloc: malloc fail\n");
+ }
+
+ return main_loop_talloc;
+}
+
+/*******************************************************************
+ Try and get a talloc context. Get the rpc one if possible, else
+ get the main loop one. The main loop one is more dangerous as it
+ goes away between packets, the rpc one will stay around for as long
+ as a current RPC lasts.
+********************************************************************/
+
+TALLOC_CTX *get_talloc_ctx(void)
+{
+ TALLOC_CTX *tc = get_current_rpc_talloc();
+
+ if (tc)
+ return tc;
+ return main_loop_talloc_get();
}
/*******************************************************************
Reads or writes a UTIME type.
********************************************************************/
-static BOOL smb_io_utime(char *desc, UTIME *t, prs_struct *ps, int depth)
+static BOOL smb_io_utime(const char *desc, UTIME *t, prs_struct *ps, int depth)
{
if (t == NULL)
return False;
Reads or writes an NTTIME structure.
********************************************************************/
-BOOL smb_io_time(char *desc, NTTIME *nttime, prs_struct *ps, int depth)
+BOOL smb_io_time(const char *desc, NTTIME *nttime, prs_struct *ps, int depth)
{
if (nttime == NULL)
return False;
Reads or writes a LOOKUP_LEVEL structure.
********************************************************************/
-BOOL smb_io_lookup_level(char *desc, LOOKUP_LEVEL *level, prs_struct *ps, int depth)
+BOOL smb_io_lookup_level(const char *desc, LOOKUP_LEVEL *level, prs_struct *ps, int depth)
{
if (level == NULL)
return False;
Reads or writes an ENUM_HND structure.
********************************************************************/
-BOOL smb_io_enum_hnd(char *desc, ENUM_HND *hnd, prs_struct *ps, int depth)
+BOOL smb_io_enum_hnd(const char *desc, ENUM_HND *hnd, prs_struct *ps, int depth)
{
if (hnd == NULL)
return False;
Reads or writes a DOM_SID structure.
********************************************************************/
-BOOL smb_io_dom_sid(char *desc, DOM_SID *sid, prs_struct *ps, int depth)
+BOOL smb_io_dom_sid(const char *desc, DOM_SID *sid, prs_struct *ps, int depth)
{
int i;
prs_debug(ps, depth, desc, "smb_io_dom_sid");
depth++;
- if(!prs_align(ps))
- return False;
-
if(!prs_uint8 ("sid_rev_num", ps, depth, &sid->sid_rev_num))
return False;
+
if(!prs_uint8 ("num_auths ", ps, depth, &sid->num_auths))
return False;
identauth >= 2^32 can be detected because it will be specified in hex
********************************************************************/
-void init_dom_sid(DOM_SID *sid, char *str_sid)
+void init_dom_sid(DOM_SID *sid, const char *str_sid)
{
pstring domsid;
int identauth;
char *p;
- if (str_sid == NULL)
- {
+ if (str_sid == NULL) {
DEBUG(4,("netlogon domain SID: none\n"));
sid->sid_rev_num = 0;
sid->num_auths = 0;
Inits a DOM_SID2 structure.
********************************************************************/
-void init_dom_sid2(DOM_SID2 *sid2, DOM_SID *sid)
+void init_dom_sid2(DOM_SID2 *sid2, const DOM_SID *sid)
{
sid2->sid = *sid;
sid2->num_auths = sid2->sid.num_auths;
Reads or writes a DOM_SID2 structure.
********************************************************************/
-BOOL smb_io_dom_sid2(char *desc, DOM_SID2 *sid, prs_struct *ps, int depth)
+BOOL smb_io_dom_sid2(const char *desc, DOM_SID2 *sid, prs_struct *ps, int depth)
{
if (sid == NULL)
return False;
Reads or writes a STRHDR structure.
********************************************************************/
-BOOL smb_io_strhdr(char *desc, STRHDR *hdr, prs_struct *ps, int depth)
+BOOL smb_io_strhdr(const char *desc, STRHDR *hdr, prs_struct *ps, int depth)
{
if (hdr == NULL)
return False;
Reads or writes a UNIHDR structure.
********************************************************************/
-BOOL smb_io_unihdr(char *desc, UNIHDR *hdr, prs_struct *ps, int depth)
+BOOL smb_io_unihdr(const char *desc, UNIHDR *hdr, prs_struct *ps, int depth)
{
if (hdr == NULL)
return False;
uint16 should be stored, or gets the size if reading.
********************************************************************/
-BOOL smb_io_hdrbuf_pre(char *desc, BUFHDR *hdr, prs_struct *ps, int depth, uint32 *offset)
+BOOL smb_io_hdrbuf_pre(const char *desc, BUFHDR *hdr, prs_struct *ps, int depth, uint32 *offset)
{
(*offset) = prs_offset(ps);
if (ps->io) {
Does nothing on reading, as that is already handled by ...._pre()
********************************************************************/
-BOOL smb_io_hdrbuf_post(char *desc, BUFHDR *hdr, prs_struct *ps, int depth,
+BOOL smb_io_hdrbuf_post(const char *desc, BUFHDR *hdr, prs_struct *ps, int depth,
uint32 ptr_hdrbuf, uint32 max_len, uint32 len)
{
if (!ps->io) {
Reads or writes a BUFHDR structure.
********************************************************************/
-BOOL smb_io_hdrbuf(char *desc, BUFHDR *hdr, prs_struct *ps, int depth)
+BOOL smb_io_hdrbuf(const char *desc, BUFHDR *hdr, prs_struct *ps, int depth)
{
if (hdr == NULL)
return False;
Reads or writes a UNIHDR2 structure.
********************************************************************/
-BOOL smb_io_unihdr2(char *desc, UNIHDR2 *hdr2, prs_struct *ps, int depth)
+BOOL smb_io_unihdr2(const char *desc, UNIHDR2 *hdr2, prs_struct *ps, int depth)
{
if (hdr2 == NULL)
return False;
len = strlen(buf) + 1;
- if (!parse_misc_talloc)
- parse_misc_talloc = talloc_init();
-
if (len < MAX_UNISTRLEN)
len = MAX_UNISTRLEN;
len *= sizeof(uint16);
- str->buffer = (uint16 *)talloc(parse_misc_talloc, len);
+ str->buffer = (uint16 *)talloc_zero(get_talloc_ctx(), len);
if (str->buffer == NULL)
smb_panic("init_unistr: malloc fail\n");
- /* store the string (null-terminated copy) */
- dos_struni2((char *)str->buffer, buf, len);
+ rpcstr_push(str->buffer, buf, len, STR_TERMINATE);
}
/*******************************************************************
XXXX NOTE: UNISTR structures NEED to be null-terminated.
********************************************************************/
-BOOL smb_io_unistr(char *desc, UNISTR *uni, prs_struct *ps, int depth)
+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_align(ps))
- return False;
if(!prs_unistr("unistr", ps, depth, uni))
return False;
static void create_buffer3(BUFFER3 *str, size_t len)
{
- if (!parse_misc_talloc)
- parse_misc_talloc = talloc_init();
-
if (len < MAX_BUFFERLEN)
len = MAX_BUFFERLEN;
- str->buffer = talloc(parse_misc_talloc, len);
+ str->buffer = talloc_zero(get_talloc_ctx(), len);
if (str->buffer == NULL)
- smb_panic("create_buffer3: malloc fail\n");
+ smb_panic("create_buffer3: talloc fail\n");
}
Inits a BUFFER3 structure.
********************************************************************/
-void init_buffer3_str(BUFFER3 *str, char *buf, int len)
+void init_buffer3_str(BUFFER3 *str, const char *buf, int len)
{
ZERO_STRUCTP(str);
/* set up string lengths. */
str->buf_max_len = len * 2;
- str->buf_len = len * 2;
+ str->buf_len = len * 2;
create_buffer3(str, str->buf_max_len);
- /* store the string (null-terminated 8 bit chars into 16 bit chars) */
- dos_struni2((char *)str->buffer, buf, str->buf_max_len);
+ rpcstr_push(str->buffer, buf, str->buf_max_len, STR_TERMINATE);
+
}
/*******************************************************************
Inits a BUFFER3 structure from a hex string.
********************************************************************/
-void init_buffer3_hex(BUFFER3 *str, char *buf)
+void init_buffer3_hex(BUFFER3 *str, const char *buf)
{
ZERO_STRUCTP(str);
create_buffer3(str, strlen(buf));
the uni_str_len member tells you how much of the buffer is really used.
********************************************************************/
-BOOL smb_io_buffer3(char *desc, BUFFER3 *buf3, prs_struct *ps, int depth)
+BOOL smb_io_buffer3(const char *desc, BUFFER3 *buf3, prs_struct *ps, int depth)
{
if (buf3 == NULL)
return False;
return False;
if (UNMARSHALLING(ps)) {
- buf3->buffer = prs_alloc_mem(ps, buf3->buf_max_len);
+ buf3->buffer = (unsigned char *)prs_alloc_mem(ps, buf3->buf_max_len);
if (buf3->buffer == NULL)
return False;
}
reads or writes a BUFFER5 structure.
the buf_len member tells you how large the buffer is.
********************************************************************/
-BOOL smb_io_buffer5(char *desc, BUFFER5 *buf5, prs_struct *ps, int depth)
+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;
- prs_align(ps);
- prs_uint32("buf_len", ps, depth, &(buf5->buf_len));
+ if(!prs_align(ps))
+ return False;
+ if(!prs_uint32("buf_len", ps, depth, &buf5->buf_len))
+ return False;
- /* reading: alloc the buffer first */
- if ( UNMARSHALLING(ps) ) {
- buf5->buffer=(uint16 *)prs_alloc_mem(ps, sizeof(uint16)*buf5->buf_len );
- if (buf5->buffer == NULL)
+ if(buf5->buf_len) {
+ if(!prs_buffer5(True, "buffer" , ps, depth, buf5))
return False;
}
-
- prs_uint16s(True, "buffer", ps, depth, buf5->buffer, buf5->buf_len);
return True;
}
Inits a BUFFER2 structure.
********************************************************************/
-void init_buffer2(BUFFER2 *str, uint8 *buf, int len)
+void init_buffer2(BUFFER2 *str, const uint8 *buf, size_t len)
{
ZERO_STRUCTP(str);
str->buf_len = buf != NULL ? len : 0;
if (buf != NULL) {
- if (!parse_misc_talloc)
- parse_misc_talloc = talloc_init();
-
if (len < MAX_BUFFERLEN)
len = MAX_BUFFERLEN;
- str->buffer = talloc(parse_misc_talloc, len);
+ str->buffer = talloc_zero(get_talloc_ctx(), len);
if (str->buffer == NULL)
- smb_panic("init_buffer2: malloc fail\n");
+ smb_panic("init_buffer2: talloc fail\n");
memcpy(str->buffer, buf, MIN(str->buf_len, len));
}
}
the uni_str_len member tells you how much of the buffer is really used.
********************************************************************/
-BOOL smb_io_buffer2(char *desc, BUFFER2 *buf2, uint32 buffer, prs_struct *ps, int depth)
+BOOL smb_io_buffer2(const char *desc, BUFFER2 *buf2, uint32 buffer, prs_struct *ps, int depth)
{
if (buf2 == NULL)
return False;
Copies a UNISTR2 structure.
********************************************************************/
-void copy_unistr2(UNISTR2 *str, UNISTR2 *from)
+void copy_unistr2(UNISTR2 *str, const UNISTR2 *from)
{
/* set up string lengths. add one if string is not null-terminated */
if (str->buffer == NULL) {
size_t len = from->uni_max_len * sizeof(uint16);
- if (!parse_misc_talloc)
- parse_misc_talloc = talloc_init();
-
if (len < MAX_UNISTRLEN)
len = MAX_UNISTRLEN;
len *= sizeof(uint16);
- str->buffer = (uint16 *)talloc(parse_misc_talloc, len);
+ str->buffer = (uint16 *)talloc_zero(get_talloc_ctx(), len);
if ((str->buffer == NULL) && (len > 0 ))
{
- smb_panic("copy_unistr2: malloc fail\n");
+ smb_panic("copy_unistr2: talloc fail\n");
return;
}
}
Creates a STRING2 structure.
********************************************************************/
-void init_string2(STRING2 *str, char *buf, int len)
+void init_string2(STRING2 *str, const char *buf, int max_len, int str_len)
{
int alloc_len = 0;
/* set up string lengths. */
- str->str_max_len = len;
+ str->str_max_len = max_len;
str->undoc = 0;
- str->str_str_len = len;
+ str->str_str_len = str_len;
/* store the string */
- if(len != 0) {
- if (!parse_misc_talloc)
- parse_misc_talloc = talloc_init();
-
- if (len < MAX_STRINGLEN)
+ if(str_len != 0) {
+ if (str_len < MAX_STRINGLEN)
alloc_len = MAX_STRINGLEN;
- str->buffer = talloc(parse_misc_talloc, alloc_len);
+ str->buffer = talloc_zero(get_talloc_ctx(), alloc_len);
if (str->buffer == NULL)
smb_panic("init_string2: malloc fail\n");
- memcpy(str->buffer, buf, len);
+ memcpy(str->buffer, buf, str_len);
}
}
the str_max_len member tells you how large the buffer is.
********************************************************************/
-BOOL smb_io_string2(char *desc, STRING2 *str2, uint32 buffer, prs_struct *ps, int depth)
+BOOL smb_io_string2(const char *desc, STRING2 *str2, uint32 buffer, prs_struct *ps, int depth)
{
if (str2 == NULL)
return False;
str->undoc = 0;
str->uni_str_len = (uint32)len;
- if (!parse_misc_talloc)
- parse_misc_talloc = talloc_init();
-
if (len < MAX_UNISTRLEN)
len = MAX_UNISTRLEN;
len *= sizeof(uint16);
- str->buffer = (uint16 *)talloc(parse_misc_talloc, len);
+ str->buffer = (uint16 *)talloc_zero(get_talloc_ctx(), len);
if ((str->buffer == NULL) && (len > 0))
{
smb_panic("init_unistr2: malloc fail\n");
return;
}
- /* store the string (null-terminated 8 bit chars into 16 bit chars) */
- dos_struni2((char *)str->buffer, buf, len);
+ /*
+ * don't move this test above ! The UNISTR2 must be initialized !!!
+ * jfm, 7/7/2001.
+ */
+ if (buf==NULL)
+ return;
+
+ rpcstr_push((char *)str->buffer, buf, len, STR_TERMINATE);
+}
+
+/**
+ * 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 = strlen_w(buf);
+ uint32 max_len = len;
+ uint32 alloc_len;
+
+ ZERO_STRUCTP(str);
+
+ /* set up string lengths. */
+ str->uni_max_len = len;
+ str->undoc = 0;
+ str->uni_str_len = len;
+
+ if (max_len < MAX_UNISTRLEN)
+ max_len = MAX_UNISTRLEN;
+
+ alloc_len = (max_len + 1) * sizeof(uint16);
+
+ str->buffer = (uint16 *)talloc_zero(ctx, alloc_len);
+ if ((str->buffer == NULL) && (alloc_len > 0))
+ {
+ smb_panic("init_unistr2_w: malloc fail\n");
+ return;
+ }
+
+ /*
+ * 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 */
+ strncpy_w(str->buffer, buf, len + 1);
}
/*******************************************************************
Inits a UNISTR2 structure from a UNISTR
********************************************************************/
-void init_unistr2_from_unistr (UNISTR2 *to, UNISTR *from)
+void init_unistr2_from_unistr (UNISTR2 *to, const UNISTR *from)
{
uint32 i;
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->undoc = 0;
to->uni_str_len = i;
- if (!parse_misc_talloc)
- parse_misc_talloc = talloc_init();
-
/* allocate the space and copy the string buffer */
- to->buffer = (uint16 *)talloc(parse_misc_talloc, sizeof(uint16)*(to->uni_str_len));
+ to->buffer = (uint16 *)talloc_zero(get_talloc_ctx(), sizeof(uint16)*(to->uni_str_len));
if (to->buffer == NULL)
smb_panic("init_unistr2_from_unistr: malloc fail\n");
memcpy(to->buffer, from->buffer, to->uni_max_len*sizeof(uint16));
the uni_max_len member tells you how large the buffer is.
********************************************************************/
-BOOL smb_io_unistr2(char *desc, UNISTR2 *uni2, uint32 buffer, prs_struct *ps, int depth)
+BOOL smb_io_unistr2(const char *desc, UNISTR2 *uni2, uint32 buffer, prs_struct *ps, int depth)
{
if (uni2 == NULL)
return False;
return True;
}
+
+/*
+ initialise a UNISTR_ARRAY from a char**
+*/
+BOOL init_unistr2_array(UNISTR2_ARRAY *array,
+ uint32 count, const char **strings)
+{
+ unsigned int i;
+
+ array->count = count;
+ array->ref_id = count?1:0;
+ if (array->count == 0) {
+ return True;
+ }
+
+ array->strings = (UNISTR2_ARRAY_EL *)talloc_zero(get_talloc_ctx(), count * sizeof(UNISTR2_ARRAY_EL));
+ if (!array->strings) {
+ return False;
+ }
+
+ for (i=0;i<count;i++) {
+ init_unistr2(&array->strings[i].string, strings[i], strlen(strings[i]));
+ array->strings[i].size = array->strings[i].string.uni_max_len*2;
+ array->strings[i].length = array->strings[i].size;
+ array->strings[i].ref_id = 1;
+ }
+
+ return True;
+}
+
+/*******************************************************************
+ Reads or writes a UNISTR2_ARRAY structure.
+********************************************************************/
+BOOL smb_io_unistr2_array(const char *desc, UNISTR2_ARRAY *array, prs_struct *ps, int depth)
+{
+ unsigned int i;
+
+ prs_debug(ps, depth, desc, "smb_io_unistr2_array");
+ depth++;
+
+ if(!prs_uint32("ref_id", ps, depth, &array->ref_id))
+ return False;
+
+ if (! array->ref_id) {
+ return True;
+ }
+
+ if(!prs_uint32("count", ps, depth, &array->count))
+ return False;
+
+ if (array->count == 0) {
+ return True;
+ }
+
+ if (UNMARSHALLING(ps)) {
+ array->strings = talloc_zero(get_talloc_ctx(), array->count * sizeof(array->strings[0]));
+ }
+ if (! array->strings) {
+ return False;
+ }
+
+ for (i=0;i<array->count;i++) {
+ if(!prs_uint16("length", ps, depth, &array->strings[i].length))
+ return False;
+ if(!prs_uint16("size", ps, depth, &array->strings[i].size))
+ return False;
+ if(!prs_uint32("ref_id", ps, depth, &array->strings[i].ref_id))
+ return False;
+ }
+
+ for (i=0;i<array->count;i++) {
+ if (! smb_io_unistr2("string", &array->strings[i].string, array->strings[i].ref_id, ps, depth))
+ return False;
+ }
+
+ return True;
+}
+
+
/*******************************************************************
Inits a DOM_RID2 structure.
********************************************************************/
Reads or writes a DOM_RID2 structure.
********************************************************************/
-BOOL smb_io_dom_rid2(char *desc, DOM_RID2 *rid2, prs_struct *ps, int depth)
+BOOL smb_io_dom_rid2(const char *desc, DOM_RID2 *rid2, prs_struct *ps, int depth)
{
if (rid2 == NULL)
return False;
reads or writes a DOM_RID3 structure.
********************************************************************/
-BOOL smb_io_dom_rid3(char *desc, DOM_RID3 *rid3, prs_struct *ps, int depth)
+BOOL smb_io_dom_rid3(const char *desc, DOM_RID3 *rid3, prs_struct *ps, int depth)
{
if (rid3 == NULL)
return False;
Inits a DOM_CLNT_SRV structure.
********************************************************************/
-static void init_clnt_srv(DOM_CLNT_SRV *log, char *logon_srv, char *comp_name)
+static void init_clnt_srv(DOM_CLNT_SRV *log, const char *logon_srv, const char *comp_name)
{
DEBUG(5,("init_clnt_srv: %d\n", __LINE__));
Inits or writes a DOM_CLNT_SRV structure.
********************************************************************/
-static BOOL smb_io_clnt_srv(char *desc, DOM_CLNT_SRV *log, prs_struct *ps, int depth)
+static BOOL smb_io_clnt_srv(const char *desc, DOM_CLNT_SRV *log, prs_struct *ps, int depth)
{
if (log == NULL)
return False;
Inits a DOM_LOG_INFO structure.
********************************************************************/
-void init_log_info(DOM_LOG_INFO *log, char *logon_srv, char *acct_name,
- uint16 sec_chan, char *comp_name)
+void init_log_info(DOM_LOG_INFO *log, const char *logon_srv, const char *acct_name,
+ uint16 sec_chan, const char *comp_name)
{
DEBUG(5,("make_log_info %d\n", __LINE__));
Reads or writes a DOM_LOG_INFO structure.
********************************************************************/
-BOOL smb_io_log_info(char *desc, DOM_LOG_INFO *log, prs_struct *ps, int depth)
+BOOL smb_io_log_info(const char *desc, DOM_LOG_INFO *log, prs_struct *ps, int depth)
{
if (log == NULL)
return False;
Reads or writes a DOM_CHAL structure.
********************************************************************/
-BOOL smb_io_chal(char *desc, DOM_CHAL *chal, prs_struct *ps, int depth)
+BOOL smb_io_chal(const char *desc, DOM_CHAL *chal, prs_struct *ps, int depth)
{
if (chal == NULL)
return False;
prs_debug(ps, depth, desc, "smb_io_chal");
depth++;
-
- if(!prs_align(ps))
- return False;
if(!prs_uint8s (False, "data", ps, depth, chal->data, 8))
return False;
Reads or writes a DOM_CRED structure.
********************************************************************/
-BOOL smb_io_cred(char *desc, DOM_CRED *cred, prs_struct *ps, int depth)
+BOOL smb_io_cred(const char *desc, DOM_CRED *cred, prs_struct *ps, int depth)
{
if (cred == NULL)
return False;
if(!smb_io_chal ("", &cred->challenge, ps, depth))
return False;
+
if(!smb_io_utime("", &cred->timestamp, ps, depth))
return False;
********************************************************************/
void init_clnt_info2(DOM_CLNT_INFO2 *clnt,
- char *logon_srv, char *comp_name,
- DOM_CRED *clnt_cred)
+ const char *logon_srv, const char *comp_name,
+ const DOM_CRED *clnt_cred)
{
DEBUG(5,("make_clnt_info: %d\n", __LINE__));
- init_clnt_srv(&(clnt->login), logon_srv, comp_name);
+ init_clnt_srv(&clnt->login, logon_srv, comp_name);
if (clnt_cred != NULL) {
clnt->ptr_cred = 1;
- memcpy(&(clnt->cred), clnt_cred, sizeof(clnt->cred));
+ memcpy(&clnt->cred, clnt_cred, sizeof(clnt->cred));
} else {
clnt->ptr_cred = 0;
}
Reads or writes a DOM_CLNT_INFO2 structure.
********************************************************************/
-BOOL smb_io_clnt_info2(char *desc, DOM_CLNT_INFO2 *clnt, prs_struct *ps, int depth)
+BOOL smb_io_clnt_info2(const char *desc, DOM_CLNT_INFO2 *clnt, prs_struct *ps, int depth)
{
if (clnt == NULL)
return False;
********************************************************************/
void init_clnt_info(DOM_CLNT_INFO *clnt,
- char *logon_srv, char *acct_name,
- uint16 sec_chan, char *comp_name,
- DOM_CRED *cred)
+ const char *logon_srv, const char *acct_name,
+ uint16 sec_chan, const char *comp_name,
+ const DOM_CRED *cred)
{
DEBUG(5,("make_clnt_info\n"));
Reads or writes a DOM_CLNT_INFO structure.
********************************************************************/
-BOOL smb_io_clnt_info(char *desc, DOM_CLNT_INFO *clnt, prs_struct *ps, int depth)
+BOOL smb_io_clnt_info(const char *desc, DOM_CLNT_INFO *clnt, prs_struct *ps, int depth)
{
if (clnt == NULL)
return False;
Reads or writes a DOM_LOGON_ID structure.
********************************************************************/
-BOOL smb_io_logon_id(char *desc, DOM_LOGON_ID *log, prs_struct *ps, int depth)
+BOOL smb_io_logon_id(const char *desc, DOM_LOGON_ID *log, prs_struct *ps, int depth)
{
if (log == NULL)
return False;
Inits an OWF_INFO structure.
********************************************************************/
-void init_owf_info(OWF_INFO *hash, uint8 data[16])
+void init_owf_info(OWF_INFO *hash, const uint8 data[16])
{
DEBUG(5,("init_owf_info: %d\n", __LINE__));
Reads or writes an OWF_INFO structure.
********************************************************************/
-BOOL smb_io_owf_info(char *desc, OWF_INFO *hash, prs_struct *ps, int depth)
+BOOL smb_io_owf_info(const char *desc, OWF_INFO *hash, prs_struct *ps, int depth)
{
if (hash == NULL)
return False;
Reads or writes a DOM_GID structure.
********************************************************************/
-BOOL smb_io_gid(char *desc, DOM_GID *gid, prs_struct *ps, int depth)
+BOOL smb_io_gid(const char *desc, DOM_GID *gid, prs_struct *ps, int depth)
{
if (gid == NULL)
return False;
Reads or writes an POLICY_HND structure.
********************************************************************/
-BOOL smb_io_pol_hnd(char *desc, POLICY_HND *pol, prs_struct *ps, int depth)
+BOOL smb_io_pol_hnd(const char *desc, POLICY_HND *pol, prs_struct *ps, int depth)
{
if (pol == NULL)
return False;
if(!prs_align(ps))
return False;
-
- if(!prs_uint8s (False, "data", ps, depth, pol->data, POL_HND_SIZE))
- return False;
-
- return True;
-}
-
-/*******************************************************************
- Reads or writes a dom query structure.
-********************************************************************/
-
-static BOOL smb_io_dom_query(char *desc, DOM_QUERY *d_q, prs_struct *ps, int depth)
-{
- if (d_q == NULL)
- return False;
-
- prs_debug(ps, depth, desc, "smb_io_dom_query");
- depth++;
- if(!prs_align(ps))
- return False;
+ if(UNMARSHALLING(ps))
+ ZERO_STRUCTP(pol);
- if(!prs_uint16("uni_dom_max_len", ps, depth, &d_q->uni_dom_max_len)) /* domain name string length * 2 */
+ if (!prs_uint32("data1", ps, depth, &pol->data1))
return False;
- if(!prs_uint16("uni_dom_str_len", ps, depth, &d_q->uni_dom_str_len)) /* domain name string length * 2 */
+ if (!prs_uint32("data2", ps, depth, &pol->data2))
return False;
-
- if(!prs_uint32("buffer_dom_name", ps, depth, &d_q->buffer_dom_name)) /* undocumented domain name string buffer pointer */
+ if (!prs_uint16("data3", ps, depth, &pol->data3))
return False;
- if(!prs_uint32("buffer_dom_sid ", ps, depth, &d_q->buffer_dom_sid)) /* undocumented domain SID string buffer pointer */
+ if (!prs_uint16("data4", ps, depth, &pol->data4))
return False;
-
- if(!smb_io_unistr2("unistr2", &d_q->uni_domain_name, d_q->buffer_dom_name, ps, depth)) /* domain name (unicode string) */
+ if(!prs_uint8s (False, "data5", ps, depth, pol->data5, sizeof(pol->data5)))
return False;
- if(!prs_align(ps))
- return False;
-
- if (d_q->buffer_dom_sid != 0) {
- if(!smb_io_dom_sid2("", &d_q->dom_sid, ps, depth)) /* domain SID */
- return False;
- } else {
- memset((char *)&d_q->dom_sid, '\0', sizeof(d_q->dom_sid));
- }
-
return True;
}
/*******************************************************************
- Reads or writes a dom query structure.
+ Create a UNISTR3.
********************************************************************/
-BOOL smb_io_dom_query_3(char *desc, DOM_QUERY_3 *d_q, prs_struct *ps, int depth)
+void init_unistr3(UNISTR3 *str, const char *buf)
{
- return smb_io_dom_query("", d_q, ps, depth);
-}
+ size_t len;
-/*******************************************************************
- Reads or writes a dom query structure.
-********************************************************************/
+ if (buf == NULL) {
+ str->uni_str_len=0;
+ str->str.buffer = NULL;
+ return;
+ }
-BOOL smb_io_dom_query_5(char *desc, DOM_QUERY_3 *d_q, prs_struct *ps, int depth)
-{
- return smb_io_dom_query("", d_q, ps, depth);
-}
+ len = strlen(buf) + 1;
+ str->uni_str_len=len;
+
+ if (len < MAX_UNISTRLEN)
+ len = MAX_UNISTRLEN;
+
+ len *= sizeof(uint16);
+
+ str->str.buffer = (uint16 *)talloc_zero(get_talloc_ctx(), len);
+ if (str->str.buffer == NULL)
+ smb_panic("init_unistr3: malloc fail\n");
+
+ rpcstr_push((char *)str->str.buffer, buf, len, STR_TERMINATE);
+}
/*******************************************************************
Reads or writes a UNISTR3 structure.
********************************************************************/
-BOOL smb_io_unistr3(char *desc, UNISTR3 *name, prs_struct *ps, int depth)
+BOOL smb_io_unistr3(const char *desc, UNISTR3 *name, prs_struct *ps, int depth)
{
if (name == NULL)
return False;
/*******************************************************************
Stream a uint64_struct
********************************************************************/
-BOOL prs_uint64(char *name, prs_struct *ps, int depth, UINT64_S *data64)
+BOOL prs_uint64(const char *name, prs_struct *ps, int depth, UINT64_S *data64)
{
return prs_uint32(name, ps, depth+1, &data64->low) &&
prs_uint32(name, ps, depth+1, &data64->high);
}
+/*******************************************************************
+reads or writes a BUFHDR2 structure.
+********************************************************************/
+BOOL smb_io_bufhdr2(const char *desc, BUFHDR2 *hdr, prs_struct *ps, int depth)
+{
+ prs_debug(ps, depth, desc, "smb_io_bufhdr2");
+ depth++;
+
+ prs_align(ps);
+ prs_uint32("info_level", ps, depth, &(hdr->info_level));
+ prs_uint32("length ", ps, depth, &(hdr->length ));
+ prs_uint32("buffer ", ps, depth, &(hdr->buffer ));
+
+ return True;
+}
+
+/*******************************************************************
+reads or writes a BUFFER4 structure.
+********************************************************************/
+BOOL smb_io_buffer4(const char *desc, BUFFER4 *buf4, uint32 buffer, prs_struct *ps, int depth)
+{
+ prs_debug(ps, depth, desc, "smb_io_buffer4");
+ depth++;
+
+ prs_align(ps);
+ prs_uint32("buf_len", ps, depth, &(buf4->buf_len));
+
+ if (buf4->buf_len > MAX_BUFFERLEN)
+ {
+ buf4->buf_len = MAX_BUFFERLEN;
+ }
+
+ prs_uint8s(True, "buffer", ps, depth, buf4->buffer, buf4->buf_len);
+ return True;
+}
+
+/*******************************************************************
+creates a UNIHDR structure.
+********************************************************************/
+
+BOOL make_uni_hdr(UNIHDR *hdr, int len)
+{
+ if (hdr == NULL)
+ {
+ return False;
+ }
+ hdr->uni_str_len = 2 * len;
+ hdr->uni_max_len = 2 * len;
+ hdr->buffer = len != 0 ? 1 : 0;
+
+ return True;
+}
+
+/*******************************************************************
+creates a BUFHDR2 structure.
+********************************************************************/
+BOOL make_bufhdr2(BUFHDR2 *hdr, uint32 info_level, uint32 length, uint32 buffer)
+{
+ hdr->info_level = info_level;
+ hdr->length = length;
+ hdr->buffer = buffer;
+
+ return True;
+}