Added prefer_ipv4 bool parameter to resolve_name().
[ira/wip.git] / source3 / utils / smbfilter.c
index 8db969722afd30108258643df70afd2eadfef98a..83de0c4c37482662075a2007074bde51fdbee893 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;
@@ -141,10 +148,11 @@ static bool send_smb(int fd, char *buffer)
 
 static void filter_child(int c, struct sockaddr_storage *dest_ss)
 {
-       int s;
+       NTSTATUS status;
+       int s = -1;
 
        /* we have a connection from a new client, now connect to the server */
-       s = open_socket_out(SOCK_STREAM, dest_ss, 445, LONG_CONNECT_TIMEOUT);
+       status = open_socket_out(dest_ss, 445, LONG_CONNECT_TIMEOUT, &s);
 
        if (s == -1) {
                char addr[INET6_ADDRSTRLEN];
@@ -169,7 +177,10 @@ static void filter_child(int c, struct sockaddr_storage *dest_ss)
                if (num <= 0) continue;
                
                if (c != -1 && FD_ISSET(c, &fds)) {
-                       if (!receive_smb_raw(c, packet, 0, 0, NULL)) {
+                       size_t len;
+                       if (!NT_STATUS_IS_OK(receive_smb_raw(
+                                                       c, packet, sizeof(packet),
+                                                       0, 0, &len))) {
                                d_printf("client closed connection\n");
                                exit(0);
                        }
@@ -180,7 +191,10 @@ static void filter_child(int c, struct sockaddr_storage *dest_ss)
                        }                       
                }
                if (s != -1 && FD_ISSET(s, &fds)) {
-                       if (!receive_smb_raw(s, packet, 0, 0, NULL)) {
+                       size_t len;
+                       if (!NT_STATUS_IS_OK(receive_smb_raw(
+                                                       s, packet, sizeof(packet),
+                                                       0, 0, &len))) {
                                d_printf("server closed connection\n");
                                exit(0);
                        }
@@ -206,7 +220,7 @@ static void start_filter(char *desthost)
 
        /* start listening on port 445 locally */
 
-       zero_addr(&my_ss);
+       zero_sockaddr(&my_ss);
        s = open_socket_in(SOCK_STREAM, 445, 0, &my_ss, True);
        
        if (s == -1) {
@@ -218,7 +232,7 @@ static void start_filter(char *desthost)
                d_printf("listen failed\n");
        }
 
-       if (!resolve_name(desthost, &dest_ss, 0x20)) {
+       if (!resolve_name(desthost, &dest_ss, 0x20, false)) {
                d_printf("Unable to resolve host %s\n", desthost);
                exit(1);
        }