Convert name_mangle() to use talloc
authorVolker Lendecke <vl@samba.org>
Sun, 22 Feb 2009 10:53:50 +0000 (11:53 +0100)
committerVolker Lendecke <vl@samba.org>
Tue, 24 Feb 2009 19:40:46 +0000 (20:40 +0100)
source3/include/proto.h
source3/libsmb/cliconnect.c
source3/libsmb/nmblib.c
source3/utils/smbfilter.c

index 3ca94b9192bfa479643d008c590ac2bbb16c69e7..87dac3e496ea0fc7ee7afd8d0a2a4e879d9a3795 100644 (file)
@@ -3117,7 +3117,7 @@ struct packet_struct *receive_dgram_packet(int fd, int t,
 bool match_mailslot_name(struct packet_struct *p, const char *mailslot_name);
 int matching_len_bits(unsigned char *p1, unsigned char *p2, size_t len);
 void sort_query_replies(char *data, int n, struct in_addr ip);
-int name_mangle( char *In, char *Out, char name_type );
+char *name_mangle(TALLOC_CTX *mem_ctx, char *In, char name_type);
 int name_extract(char *buf,int ofs, fstring name);
 int name_len(char *s1);
 
index dabfc398ced293703dff0bc0f4fd9d85a616b4cd..ad11ee0ed411fe6dabfe57e4df4b514679f845c4 100644 (file)
@@ -1642,6 +1642,7 @@ bool cli_session_request(struct cli_state *cli,
 {
        char *p;
        int len = 4;
+       char *tmp;
 
        /* 445 doesn't have session request */
        if (cli->port == 445)
@@ -1651,14 +1652,30 @@ bool cli_session_request(struct cli_state *cli,
        memcpy(&(cli->called ), called , sizeof(*called ));
 
        /* put in the destination name */
+
+       tmp = name_mangle(talloc_tos(), cli->called.name,
+                         cli->called.name_type);
+       if (tmp == NULL) {
+               return false;
+       }
+
        p = cli->outbuf+len;
-       name_mangle(cli->called .name, p, cli->called .name_type);
-       len += name_len(p);
+       memcpy(p, tmp, name_len(tmp));
+       len += name_len(tmp);
+       TALLOC_FREE(tmp);
 
        /* and my name */
+
+       tmp = name_mangle(talloc_tos(), cli->calling.name,
+                         cli->calling.name_type);
+       if (tmp == NULL) {
+               return false;
+       }
+
        p = cli->outbuf+len;
-       name_mangle(cli->calling.name, p, cli->calling.name_type);
-       len += name_len(p);
+       memcpy(p, tmp, name_len(tmp));
+       len += name_len(tmp);
+       TALLOC_FREE(tmp);
 
        /* send a session request (RFC 1002) */
        /* setup the packet length
index 02b13ae63e9718b968a82634174e192521edef40..5f3eda44fe2960300e2e2e79fc42016b550c3c57 100644 (file)
@@ -1279,12 +1279,19 @@ static int name_interpret(char *in, fstring name)
  Note:  <Out> must be (33 + strlen(scope) + 2) bytes long, at minimum.
 ****************************************************************************/
 
-int name_mangle( char *In, char *Out, char name_type )
+char *name_mangle(TALLOC_CTX *mem_ctx, char *In, char name_type)
 {
        int   i;
        int   len;
        nstring buf;
-       char *p = Out;
+       char *result;
+       char *p;
+
+       result = talloc_array(mem_ctx, char, 33 + strlen(global_scope()) + 2);
+       if (result == NULL) {
+               return NULL;
+       }
+       p = result;
 
        /* Safely copy the input string, In, into buf[]. */
        if (strcmp(In,"*") == 0)
@@ -1321,7 +1328,7 @@ int name_mangle( char *In, char *Out, char name_type )
                                p[0] = len;
                                if( len > 0 )
                                        p[len+1] = 0;
-                               return( name_len(Out) );
+                               return result;
                        case '.':
                                p[0] = len;
                                p   += (len + 1);
@@ -1333,7 +1340,7 @@ int name_mangle( char *In, char *Out, char name_type )
                }
        }
 
-       return( name_len(Out) );
+       return result;
 }
 
 /****************************************************************************
index 1fdea818d6e47ae3a5d4ade03a4bc5c44678bfc9..39a264011eed4cf90acd6d9ac47893f096d30711 100644 (file)
@@ -91,8 +91,15 @@ static void filter_request(char *buf)
                        d_printf("sesion_request: %s -> %s\n",
                                 name1, name2);
                        if (netbiosname) {
-                               /* replace the destination netbios name */
-                               name_mangle(netbiosname, buf+4, 0x20);
+                               char *mangled = name_mangle(
+                                       talloc_tos(), netbiosname, 0x20);
+                               if (mangled != NULL) {
+                                       /* replace the destination netbios
+                                        * name */
+                                       memcpy(buf+4, mangled,
+                                              name_len(mangled));
+                                       TALLOC_FREE(mangled);
+                               }
                        }
                }
                return;