* changed structure of REG_R_ENUM_VALUE structure since the BUFFER2
[bbaumbach/samba-autobuild/.git] / source / rpc_parse / parse_misc.c
index 5160a2778f7d91264fd77080ec8ec6f644f5a41e..01d76981736f5bb9e7c610b3b35b2a21de99c29a 100644 (file)
@@ -1,6 +1,5 @@
 /* 
- *  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,
@@ -23,6 +22,9 @@
 
 #include "includes.h"
 
+#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.
@@ -61,7 +63,7 @@ void main_loop_talloc_free(void)
 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");
     }
@@ -212,9 +214,6 @@ BOOL smb_io_dom_sid(char *desc, DOM_SID *sid, prs_struct *ps, int depth)
        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))
@@ -293,7 +292,7 @@ void init_dom_sid(DOM_SID *sid, char *str_sid)
  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;
@@ -552,8 +551,6 @@ BOOL smb_io_unistr(char *desc, UNISTR *uni, prs_struct *ps, int depth)
        prs_debug(ps, depth, desc, "smb_io_unistr");
        depth++;
 
-       if(!prs_align(ps))
-               return False;
        if(!prs_unistr("unistr", ps, depth, uni))
                return False;
 
@@ -820,23 +817,23 @@ void copy_unistr2(UNISTR2 *str, const UNISTR2 *from)
  Creates a STRING2 structure.
 ********************************************************************/
 
-void init_string2(STRING2 *str, const 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);
   }
 }
 
@@ -917,6 +914,51 @@ void init_unistr2(UNISTR2 *str, const char *buf, size_t len)
        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
 ********************************************************************/
@@ -1155,8 +1197,8 @@ static BOOL smb_io_clnt_srv(char *desc, DOM_CLNT_SRV *log, prs_struct *ps, int d
  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__));