After talking with Jeremy and JF (and staring at packet traces between
authorGerald Carter <jerry@samba.org>
Fri, 4 Aug 2000 12:42:19 +0000 (12:42 +0000)
committerGerald Carter <jerry@samba.org>
Fri, 4 Aug 2000 12:42:19 +0000 (12:42 +0000)
NT <-> NT), I've come to realize that UNISTR2 strings should be NULL
terminated.

jerry

source/include/rpc_misc.h
source/rpc_parse/parse_misc.c

index 6e585e7a0ef3f16278c66f7270038caf7acd7160..6fb2d63ed48ed62362a42fbaf39f11c2aeba12fd 100644 (file)
@@ -171,7 +171,9 @@ typedef struct unistr2_info
   uint32 uni_max_len;
   uint32 undoc;
   uint32 uni_str_len;
-  /* unicode characters. ***MUST*** be little-endian. **NOT** necessarily null-terminated */
+  /* unicode characters. ***MUST*** be little-endian. 
+     **must** be null-terminated and the uni_str_len should include
+     the NULL character */
   uint16 *buffer;
 
 } UNISTR2;
index 276e66a113da2b9554b5bfe5c5ffeeefcb79a0f7..c0b700c908a0ae71f33d0a985977a7bd9932e78a 100644 (file)
@@ -852,14 +852,14 @@ void init_unistr2(UNISTR2 *str, const char *buf, size_t len)
        str->undoc       = 0;
        str->uni_str_len = (uint32)len;
 
-    if (!parse_misc_talloc)
+       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(parse_misc_talloc, len);
        if (str->buffer == NULL)
                smb_panic("init_unistr2: malloc fail\n");
 
@@ -867,6 +867,56 @@ void init_unistr2(UNISTR2 *str, const char *buf, size_t len)
        dos_struni2((char *)str->buffer, buf, len);
 }
 
+/*******************************************************************
+ Inits a UNISTR2 structure from a UNISTR
+********************************************************************/
+void init_unistr2_from_unistr (UNISTR2 *to, UNISTR *from)
+{
+
+       BOOL found;
+       uint32 i = 0;
+
+       if ((to == NULL) || (from == NULL) || (from->buffer == NULL))
+               return;
+               
+       ZERO_STRUCTP (to);
+
+       /* get the length; UNISTR **are** NULL terminated */
+       found = False;
+       while (!found)
+       {
+               if ((from->buffer)[i]=='\0' && (from->buffer)[(2*i)+1]=='\0')
+                       found = True;
+               else
+                       i++;
+       }
+       i++;
+
+       if (!found)
+       {
+               DEBUG(0,("init_unistr2_from_unistr: non-null terminiated UNISTR!\n"));
+               return;
+       }
+
+       /* set up string lengths. */
+       to->uni_max_len = i;
+       to->undoc       = 0;
+       to->uni_str_len = i;
+
+       if (!parse_misc_talloc)
+               parse_misc_talloc = talloc_init();
+       
+       to->buffer = (uint16 *)talloc(parse_misc_talloc, sizeof(uint16)*(to->uni_str_len));
+       if (to->buffer == NULL)
+               smb_panic("init_unistr2_from_unistr: malloc fail\n");
+
+       for (i=0; i < to->uni_str_len; i++)
+               to->buffer[i] = from->buffer[i];
+               
+       return;
+}
+
+
 /*******************************************************************
  Reads or writes a UNISTR2 structure.
  XXXX NOTE: UNISTR2 structures need NOT be null-terminated.