/*
- * 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,
* Copyright (C) Paul Ashton 1997.
- * Copyright (C) Andrew Bartlett 2001.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
-
#include "includes.h"
-extern int DEBUGLEVEL;
+#undef DBGC_CLASS
+#define DBGC_CLASS DBGC_RPC_PARSE
/****************************************************************************
A temporary TALLOC context for things like unistrs, that is valid for
TALLOC_CTX *main_loop_talloc_get(void)
{
if (!main_loop_talloc) {
- main_loop_talloc = talloc_init();
+ main_loop_talloc = talloc_init_named("main loop talloc (mainly parse_misc)");
if (!main_loop_talloc)
smb_panic("main_loop_talloc: malloc fail\n");
}
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))
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;
prs_debug(ps, depth, desc, "smb_io_unistr");
depth++;
- if(!prs_align(ps))
- return False;
if(!prs_unistr("unistr", ps, depth, uni))
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 */
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 (len < MAX_STRINGLEN)
+ if(str_len != 0) {
+ if (str_len < MAX_STRINGLEN)
alloc_len = MAX_STRINGLEN;
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);
}
}
rpcstr_push((char *)str->buffer, buf, len, STR_TERMINATE);
}
-/*******************************************************************
- Inits a UNIHDR and UNISTR2 structure at one time.
-********************************************************************/
+/**
+ * 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_and_hdr(UNISTR2 *str, UNIHDR *hdr, const char *buf )
+void init_unistr2_w(TALLOC_CTX *ctx, UNISTR2 *str, const smb_ucs2_t *buf)
{
- size_t convbuf_len_bytes, len_bytes;
- int len;
-
- uint16 *conversion_buffer;
-
- if (buf == NULL) {
- str->buffer = NULL;
- hdr->uni_str_len = 0;
- hdr->uni_max_len = 0;
- hdr->buffer = 0;
- return;
- }
+ uint32 len = strlen_w(buf);
+ uint32 max_len = len;
+ uint32 alloc_len;
- convbuf_len_bytes = (sizeof(uint16)*(strlen(buf) + 1));
- /* Our strings cannot expand from internal to unicode by more
- than a factor of 2 */
-
- conversion_buffer = malloc(convbuf_len_bytes);
- if (conversion_buffer == NULL)
- smb_panic("init_unistr: malloc fail\n");
+ ZERO_STRUCTP(str);
- /* Check this */
+ /* set up string lengths. */
+ str->uni_max_len = len;
+ str->undoc = 0;
+ str->uni_str_len = len;
- len_bytes = rpcstr_push(conversion_buffer, buf, convbuf_len_bytes, STR_TERMINATE);
+ if (max_len < MAX_UNISTRLEN)
+ max_len = MAX_UNISTRLEN;
- len = len_bytes/sizeof(uint16);
+ alloc_len = (max_len + 1) * sizeof(uint16);
- if (len > MAX_UNISTRLEN) {
- len = MAX_UNISTRLEN;
+ str->buffer = (uint16 *)talloc_zero(ctx, alloc_len);
+ if ((str->buffer == NULL) && (alloc_len > 0))
+ {
+ smb_panic("init_unistr2_w: malloc fail\n");
+ return;
}
-
- str->buffer = (uint16 *)talloc_zero(get_talloc_ctx(), len*sizeof(uint16));
- if (str->buffer == NULL)
- smb_panic("init_unistr: talloc fail\n");
-
- hdr->uni_str_len = len;
- hdr->uni_max_len = len;
-
- hdr->buffer = 1;
-
- str->uni_str_len = len;
- str->uni_max_len = len;
- memcpy(str->buffer, conversion_buffer, len*sizeof(uint16));
-
- free(conversion_buffer);
+
+ /*
+ * 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 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__));
if(!smb_io_chal ("", &cred->challenge, ps, depth))
return False;
+
if(!smb_io_utime("", &cred->timestamp, ps, depth))
return False;
prs_uint32(name, ps, depth+1, &data64->high);
}
+/*******************************************************************
+reads or writes a BUFHDR2 structure.
+********************************************************************/
+BOOL smb_io_bufhdr2(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(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;
+}