svn commit: samba r9626 - in branches/SOC/SAMBA_3_0/source/libmsrpc: .

skel at samba.org skel at samba.org
Thu Aug 25 23:29:54 GMT 2005


Author: skel
Date: 2005-08-25 23:29:54 +0000 (Thu, 25 Aug 2005)
New Revision: 9626

WebSVN: http://websvn.samba.org/cgi-bin/viewcvs.cgi?view=rev&root=samba&rev=9626

Log:
added support to retrieve REG_MULTI_SZ values

setting and retrieving REG_MULTI_SZ values is done 'properly' using rpcstr_push() and rpcstr_pull()


Modified:
   branches/SOC/SAMBA_3_0/source/libmsrpc/libmsrpc_internal.c


Changeset:
Modified: branches/SOC/SAMBA_3_0/source/libmsrpc/libmsrpc_internal.c
===================================================================
--- branches/SOC/SAMBA_3_0/source/libmsrpc/libmsrpc_internal.c	2005-08-25 23:05:41 UTC (rev 9625)
+++ branches/SOC/SAMBA_3_0/source/libmsrpc/libmsrpc_internal.c	2005-08-25 23:29:54 UTC (rev 9626)
@@ -71,8 +71,9 @@
 
 RPC_DATA_BLOB *cac_MakeRpcDataBlob(TALLOC_CTX *mem_ctx, uint32 data_type, REG_VALUE_DATA data) {
    RPC_DATA_BLOB *blob = NULL;
-   int i, j;
+   int i;
    uint32 size = 0;
+   uint32 len  = 0;
    uint8 *multi = NULL;
    uint32 multi_idx = 0;
 
@@ -110,34 +111,25 @@
             size += strlen(data.reg_multi_sz.strings[i]) + 1;
          }
 
-         /*have to add an additional '\0'*/
-/*         size++;
-
-         blob->buf_len = size;
-         blob->buffer = talloc_size(mem_ctx, sizeof(uint8) * size);
-
-         if(blob->buffer) {
-            memcpy(blob->buffer, data.reg_multi_sz.strings, size);
-            blob->buffer[size - 1] = '\0';
-         }
-*/
          /**need a whole bunch of unicode strings in a row (seperated by null characters), with an extra null-character on the end*/
 
-         /*this is a hack.. but it works*/
          multi = TALLOC_ZERO_ARRAY(mem_ctx, uint8, (size + 1)*2); /*size +1 for the extra null character*/
          if(!multi) {
             errno = ENOMEM;
             break;
          }
          
+         /*do it using rpcstr_push()*/
+         multi_idx = 0;
          for(i = 0; i < data.reg_multi_sz.num_strings; i++) {
-            for(j = 0; j <= strlen(data.reg_multi_sz.strings[i]); j++) {
-               multi[multi_idx] = data.reg_multi_sz.strings[i][j];
+            len = strlen(data.reg_multi_sz.strings[i]) + 1;
 
-               multi_idx += 2;
-            }
-         }
+            rpcstr_push((multi + multi_idx), data.reg_multi_sz.strings[i], len * 2, STR_TERMINATE);
 
+            /* x2 becuase it is a uint8 buffer*/
+            multi_idx += len * 2;
+         }
+            
          /*now initialize the buffer as binary data*/
          init_rpc_blob_bytes(blob, multi, (size + 1)*2);
 
@@ -188,8 +180,15 @@
 REG_VALUE_DATA *cac_MakeRegValueData(TALLOC_CTX *mem_ctx, uint32 data_type, REGVAL_BUFFER buf) {
    REG_VALUE_DATA *data;
 
-   uint32 size          = 0;
+   uint32 i;
 
+   /*all of the following used for MULTI_SZ data*/
+   uint32 size       = 0;
+   uint32 len        = 0;
+   uint32 multi_idx  = 0;
+   uint32 num_strings= 0;
+   char **strings    = NULL;
+
    data = talloc(mem_ctx, REG_VALUE_DATA);
    if(!data) {
       errno = ENOMEM;
@@ -242,11 +241,7 @@
       case REG_MULTI_SZ:
          size = buf.buf_len;
 
-         /*FIXME: make this do something useful*/
-#if 0
-         /*find out how many strings there are*/
-         i = 0;
-         
+         /*find out how many strings there are. size is # of bytes and we want to work uint16*/
          for(i = 0; i < (size/2 - 1); i++) {
             if(buf.buffer[i] == 0x0000)
                num_strings++;
@@ -255,7 +250,9 @@
             if(buf.buffer[i] == 0x0000 && buf.buffer[i + 1] == 0x0000)
                break;
          }
-
+         
+         printf("cac_RegMakeValueData: num_strings => %d, buf_len = %d\n", num_strings, buf.buf_len);
+         
          strings = talloc_array(mem_ctx, char *, num_strings);
          if(!strings) {
             errno = ENOMEM;
@@ -267,29 +264,27 @@
             break;
 
          for(i = 0; i < num_strings; i++) {
-            /*first we have to find out how long this string is*/
-            cur_size = 0;
-            while(buf_idx + cur_size < sizebuf.buffer[bytes_used + cur_size] != 0x0000)
-               cur_size++;
+            /*find out how many characters are in this string*/
+            len = 0;
+            /*make sure we don't go past the end of the buffer and keep looping until we have a uni \0*/
+            while( multi_idx + len < size/2 && buf.buffer[multi_idx + len] != 0x0000)
+               len++;
 
-            strings[i] = cac_unistr_to_str(mem_ctx, (buf.buffer + buf_idx), (size - bytes_used));
+            /*stay aware of the \0\0*/
+            len++;
 
-            if(!strings[i]) {
-               talloc_free(strings);
-               strings = NULL;
-               break;
-            }
-            
-            /*buf_idx is here to keep things more readable, keeps track of where we are in the buffer*/
-            buf_idx    = strlen(strings[i]) + 1;
-            /*need to keep track of what's left in the buffer. buffer is 2 bytes for letter, string is 1 byte per letter, hence multiply by 2*/
-            bytes_used = 2 * buf_idx;
-         }
+            strings[i] = TALLOC_ZERO_ARRAY(mem_ctx, char, len);
 
+            /*pull out the unicode string*/
+            rpcstr_pull(strings[i], (buf.buffer + multi_idx) , len, -1, STR_TERMINATE);
 
+            /*keep track of where we are in the bigger array*/
+            multi_idx += len;
+         }
+
          data->reg_multi_sz.num_strings = num_strings;
          data->reg_multi_sz.strings     = strings;
-#endif
+
          break;
 
       default:



More information about the samba-cvs mailing list