Convert receive_smb_raw to NTSTATUS
authorVolker Lendecke <vl@samba.org>
Fri, 25 Jan 2008 22:54:22 +0000 (23:54 +0100)
committerVolker Lendecke <vl@samba.org>
Sat, 2 Feb 2008 10:03:23 +0000 (11:03 +0100)
(This used to be commit ba771bd858602452a9e58c3aab1336f2ac8a25ef)

source3/client/client.c
source3/lib/util_sock.c
source3/libsmb/clientgen.c
source3/smbd/oplock_irix.c
source3/utils/smbfilter.c

index c9343104911096214bd140346d2f9bf4c3790afe..1c85a6dafc273e3cefc0ad4713d38faac8f4cadd 100644 (file)
@@ -4422,9 +4422,30 @@ static void readline_callback(void)
           session keepalives and then drop them here.
        */
        if (FD_ISSET(cli->fd,&fds)) {
-               if (receive_smb_raw(cli->fd,cli->inbuf,0,0,&cli->smb_rw_error) == -1) {
-                       DEBUG(0, ("Read from server failed, maybe it closed the "
-                               "connection\n"));
+               NTSTATUS status;
+               size_t len;
+
+               set_smb_read_error(&cli->smb_rw_error, SMB_READ_OK);
+
+               status = receive_smb_raw(cli->fd, cli->inbuf, 0, 0, &len);
+
+               if (!NT_STATUS_IS_OK(status)) {
+                       DEBUG(0, ("Read from server failed, maybe it closed "
+                                 "the connection\n"));
+
+                       if (NT_STATUS_EQUAL(status, NT_STATUS_END_OF_FILE)) {
+                               set_smb_read_error(&cli->smb_rw_error,
+                                                  SMB_READ_EOF);
+                               return;
+                       }
+
+                       if (NT_STATUS_EQUAL(status, NT_STATUS_IO_TIMEOUT)) {
+                               set_smb_read_error(&cli->smb_rw_error,
+                                                  SMB_READ_TIMEOUT);
+                               return;
+                       }
+
+                       set_smb_read_error(&cli->smb_rw_error, SMB_READ_ERROR);
                        return;
                }
                if(CVAL(cli->inbuf,0) != SMBkeepalive) {
index fcea5d8be661b538cbdaa8e6aa7dda400f8282e9..ede2cdae714f2049591e3e599fa2c189dbbe2d6b 100644 (file)
@@ -1196,34 +1196,17 @@ NTSTATUS read_smb_length(int fd, char *inbuf, unsigned int timeout,
  Doesn't check the MAC on signed packets.
 ****************************************************************************/
 
-ssize_t receive_smb_raw(int fd,
-                       char *buffer,
-                       unsigned int timeout,
-                       size_t maxlen,
-                       enum smb_read_errors *pre)
+NTSTATUS receive_smb_raw(int fd, char *buffer, unsigned int timeout,
+                        size_t maxlen, size_t *p_len)
 {
        size_t len;
        NTSTATUS status;
 
-       set_smb_read_error(pre,SMB_READ_OK);
-
        status = read_smb_length_return_keepalive(fd,buffer,timeout,&len);
 
        if (!NT_STATUS_IS_OK(status)) {
                DEBUG(10, ("receive_smb_raw: %s!\n", nt_errstr(status)));
-
-               if (NT_STATUS_EQUAL(status, NT_STATUS_END_OF_FILE)) {
-                       set_smb_read_error(pre, SMB_READ_EOF);
-                       return -1;
-               }
-
-               if (NT_STATUS_EQUAL(status, NT_STATUS_IO_TIMEOUT)) {
-                       set_smb_read_error(pre, SMB_READ_TIMEOUT);
-                       return -1;
-               }
-
-               set_smb_read_error(pre, SMB_READ_ERROR);
-               return -1;
+               return status;
        }
 
        /*
@@ -1235,15 +1218,7 @@ ssize_t receive_smb_raw(int fd,
                DEBUG(0,("Invalid packet length! (%lu bytes).\n",
                                        (unsigned long)len));
                if (len > BUFFER_SIZE + (SAFETY_MARGIN/2)) {
-
-                       /*
-                        * Correct fix. smb_read_error may have already been
-                        * set. Only set it here if not already set. Global
-                        * variables still suck :-). JRA.
-                        */
-
-                       cond_set_smb_read_error(pre,SMB_READ_ERROR);
-                       return -1;
+                       return NT_STATUS_INVALID_PARAMETER;
                }
        }
 
@@ -1252,24 +1227,11 @@ ssize_t receive_smb_raw(int fd,
                        len = MIN(len,maxlen);
                }
 
-               set_smb_read_error(pre, SMB_READ_OK);
-
                status = read_socket_with_timeout(
                        fd, buffer+4, len, len, timeout, &len);
 
                if (!NT_STATUS_IS_OK(status)) {
-                       if (NT_STATUS_EQUAL(status, NT_STATUS_END_OF_FILE)) {
-                               set_smb_read_error(pre, SMB_READ_EOF);
-                               return -1;
-                       }
-
-                       if (NT_STATUS_EQUAL(status, NT_STATUS_IO_TIMEOUT)) {
-                               set_smb_read_error(pre, SMB_READ_TIMEOUT);
-                               return -1;
-                       }
-
-                       set_smb_read_error(pre, SMB_READ_ERROR);
-                       return -1;
+                       return status;
                }
 
                /* not all of samba3 properly checks for packet-termination
@@ -1278,7 +1240,8 @@ ssize_t receive_smb_raw(int fd,
                SSVAL(buffer+4,len, 0);
        }
 
-       return len;
+       *p_len = len;
+       return NT_STATUS_OK;
 }
 
 /****************************************************************************
index 7a7377f1482bc17f1f64852b7c260f534da2ffd4..3b7669f33ef560b292639d3b43b1fad31bd3a826 100644 (file)
@@ -69,15 +69,36 @@ int cli_set_port(struct cli_state *cli, int port)
 
 static ssize_t client_receive_smb(struct cli_state *cli, size_t maxlen)
 {
-       ssize_t len;
+       size_t len;
 
        for(;;) {
-               len = receive_smb_raw(cli->fd, cli->inbuf, cli->timeout,
-                               maxlen, &cli->smb_rw_error);
+               NTSTATUS status;
 
-               if (len < 0) {
+               set_smb_read_error(&cli->smb_rw_error, SMB_READ_OK);
+
+               status = receive_smb_raw(cli->fd, cli->inbuf, cli->timeout,
+                                        maxlen, &len);
+               if (!NT_STATUS_IS_OK(status)) {
                        DEBUG(10,("client_receive_smb failed\n"));
                        show_msg(cli->inbuf);
+
+                       if (NT_STATUS_EQUAL(status, NT_STATUS_END_OF_FILE)) {
+                               set_smb_read_error(&cli->smb_rw_error,
+                                                  SMB_READ_EOF);
+                               return -1;
+                       }
+
+                       if (NT_STATUS_EQUAL(status, NT_STATUS_IO_TIMEOUT)) {
+                               set_smb_read_error(&cli->smb_rw_error,
+                                                  SMB_READ_TIMEOUT);
+                               return -1;
+                       }
+
+                       set_smb_read_error(&cli->smb_rw_error, SMB_READ_ERROR);
+                       return -1;
+               }
+
+               if (len < 0) {
                        return len;
                }
 
index a4ea63bc0aa9825b3cf28f071b4c7455391662bf..788cd04c17d7274988213a464248e2f69124863f 100644 (file)
@@ -121,7 +121,6 @@ static files_struct *irix_oplock_receive_message(fd_set *fds)
                DEBUG(0,("irix_oplock_receive_message: read of kernel "
                         "notification failed. Error was %s.\n",
                         strerror(errno) ));
-               set_smb_read_error(get_srv_read_error(), SMB_READ_ERROR);
                return NULL;
        }
 
@@ -141,7 +140,6 @@ static files_struct *irix_oplock_receive_message(fd_set *fds)
                         */
                        return NULL;
                }
-               set_smb_read_error(get_srv_read_error(), SMB_READ_ERROR);
                return NULL;
        }
 
index 8db969722afd30108258643df70afd2eadfef98a..e128e1ce345c2c1dc55c301eb4e70a5f9829324d 100644 (file)
@@ -169,7 +169,9 @@ 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, 0, 0, &len))) {
                                d_printf("client closed connection\n");
                                exit(0);
                        }
@@ -180,7 +182,9 @@ 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, 0, 0, &len))) {
                                d_printf("server closed connection\n");
                                exit(0);
                        }