dynamic mem allocation in net_srv_transport_enum() parsing.
authorLuke Leighton <lkcl@samba.org>
Wed, 3 Nov 1999 21:51:29 +0000 (21:51 +0000)
committerLuke Leighton <lkcl@samba.org>
Wed, 3 Nov 1999 21:51:29 +0000 (21:51 +0000)
source/include/proto.h
source/include/rpc_srvsvc.h
source/rpc_parse/parse_srv.c
source/rpcclient/cmd_srvsvc.c

index d6b7abba9567a659c9ef24d05bf5cf192a902a96..3b318b437dcbeb85cd8a914c974e3e0b89afb63b 100644 (file)
@@ -619,6 +619,9 @@ char *uni_strncpy(char *destbuf, const char *srcbuf, int len);
 uint32 buffer2_to_uint32(const BUFFER2 *str);
 void buffer2_to_multistr(char *dest, const BUFFER2 *str, size_t maxlen);
 void buffer4_to_str(char *dest, const BUFFER4 *str, size_t maxlen);
+BOOL copy_unistr2(UNISTR2 *str, const UNISTR2 *from);
+UNISTR2 *unistr2_dup(const UNISTR2 *name);
+void unistr2_free(UNISTR2 *name);
 
 /*The following definitions come from  libsmb/clientgen.c  */
 
@@ -2220,9 +2223,6 @@ BOOL smb_io_buffer5(char *desc, BUFFER5 *buf5, prs_struct *ps, int depth);
 BOOL make_buffer2(BUFFER2 *str, const char *buf, int len);
 BOOL smb_io_buffer2(char *desc,  BUFFER2 *buf2, uint32 buffer, prs_struct *ps, int depth);
 BOOL make_buf_unistr2(UNISTR2 *str, uint32 *ptr, char *buf);
-BOOL copy_unistr2(UNISTR2 *str, const UNISTR2 *from);
-UNISTR2 *unistr2_dup(const UNISTR2 *name);
-void unistr2_free(UNISTR2 *name);
 BOOL make_string2(STRING2 *str, char *buf, int len);
 BOOL smb_io_string2(char *desc,  STRING2 *str2, uint32 buffer, prs_struct *ps, int depth);
 BOOL make_unistr2(UNISTR2 *str, const char *buf, int len);
@@ -3031,6 +3031,8 @@ BOOL make_srv_tprt_info0(TPRT_INFO_0 *tp0,
                                uint32 num_vcs, uint32 trans_addr_len,
                                char *trans_name, char *trans_addr,
                                char *addr_name);
+void free_srv_tprt_info_0(SRV_TPRT_INFO_0 *tp0);
+void free_srv_tprt_ctr(SRV_TPRT_INFO_CTR *ctr);
 BOOL make_srv_q_net_tprt_enum(SRV_Q_NET_TPRT_ENUM *q_n, 
                                char *srv_name, 
                                uint32 tprt_level, SRV_TPRT_INFO_CTR *ctr,
index b875f2a2d6c3644fa63c44d47dd09cf43e1a5de8..0472f6c546e8bc266c2169a92970cf29c5cf234f 100644 (file)
@@ -282,8 +282,8 @@ typedef struct srv_tprt_info_0_info
        uint32 ptr_tprt_info;                        /* Buffer */
        uint32 num_entries_read2;                    /* EntriesRead */
 
-       TPRT_INFO_0     info_0    [MAX_TPRT_ENTRIES]; /* transport entry pointers */
-       TPRT_INFO_0_STR info_0_str[MAX_TPRT_ENTRIES]; /* transport entry strings */
+       TPRT_INFO_0     *info_0; /* transport entry pointers */
+       TPRT_INFO_0_STR *info_0_str; /* transport entry strings */
 
 } SRV_TPRT_INFO_0;
 
index c27f58ac26d316a7e4b3651ffe1ba0da163963a3..c0530f8987910f62bb4041756332969c81a54e8c 100644 (file)
@@ -1207,13 +1207,25 @@ static BOOL srv_io_srv_tprt_info_0(char *desc,  SRV_TPRT_INFO_0 *tp0, prs_struct
        {
                uint32 i;
                uint32 num_entries = tp0->num_entries_read;
-               if (num_entries > MAX_TPRT_ENTRIES)
-               {
-                       num_entries = MAX_TPRT_ENTRIES; /* report this! */
-               }
 
                prs_uint32("num_entries_read2", ps, depth, &(tp0->num_entries_read2));
 
+               if (ps->io)
+               {
+                       /* reading */
+                       tp0->info_0 = (TPRT_INFO_0*)malloc(num_entries *
+                                     sizeof(tp0->info_0[0]));
+
+                       tp0->info_0_str = (TPRT_INFO_0_STR*)malloc(num_entries *
+                                     sizeof(tp0->info_0_str[0]));
+
+                       if (tp0->info_0 == NULL || tp0->info_0_str == NULL)
+                       {
+                               free_srv_tprt_info_0(tp0);
+                               return False;
+                       }
+               }
+
                for (i = 0; i < num_entries; i++)
                {
                        prs_grow(ps);
@@ -1231,9 +1243,32 @@ static BOOL srv_io_srv_tprt_info_0(char *desc,  SRV_TPRT_INFO_0 *tp0, prs_struct
                prs_align(ps);
        }
 
+       if (!ps->io)
+       {
+               /* writing */
+               free_srv_tprt_info_0(tp0);
+       }
+
        return True;
 }
 
+/*******************************************************************
+frees a structure.
+********************************************************************/
+void free_srv_tprt_info_0(SRV_TPRT_INFO_0 *tp0)
+{
+       if (tp0->info_0 != NULL)
+       {
+               free(tp0->info_0);
+               tp0->info_0 = NULL;
+       }
+       if (tp0->info_0_str != NULL)
+       {
+               free(tp0->info_0_str);
+               tp0->info_0_str = NULL;
+       }
+}
+
 /*******************************************************************
 reads or writes a structure.
 ********************************************************************/
@@ -1270,6 +1305,27 @@ static BOOL srv_io_srv_tprt_ctr(char *desc,  SRV_TPRT_INFO_CTR *ctr, prs_struct
        return True;
 }
 
+/*******************************************************************
+reads or writes a structure.
+********************************************************************/
+void free_srv_tprt_ctr(SRV_TPRT_INFO_CTR *ctr)
+{
+       switch (ctr->switch_value)
+       {
+               case 0:
+               {
+                       free_srv_tprt_info_0(&(ctr->tprt.info0));
+                       break;
+               }
+               default:
+               {
+                       DEBUG(5,("no transport info at switch_value %d\n",
+                                ctr->switch_value));
+                       break;
+               }
+       }
+}
+
 /*******************************************************************
 reads or writes a structure.
 ********************************************************************/
index d6f4f336531d3bd17b7dc564c3be1301170e2bf2..b856d2ff5c19a0ad2a7588e0c6c1d2241928ca15 100644 (file)
@@ -161,6 +161,8 @@ void cmd_srv_enum_tprt(struct client_info *info)
        {
                DEBUG(5,("cmd_srv_enum_tprt: query failed\n"));
        }
+
+       free_srv_tprt_ctr(&ctr);
 }
 
 /****************************************************************************