s3: Lift smbd_server_fd() from read_fd_with_timeout()
authorVolker Lendecke <vl@samba.org>
Sun, 15 Aug 2010 13:23:47 +0000 (15:23 +0200)
committerVolker Lendecke <vl@samba.org>
Tue, 17 Aug 2010 20:44:03 +0000 (22:44 +0200)
source3/lib/util_sock.c
source3/rpc_server/srv_samr_chgpasswd.c
source3/smbd/process.c

index 5a658bcad3570f276c2e0d4d54ebf1b0e129ef1c..b61a3f703e81a2a65037cd8b4a0548d9ea25a7d0 100644 (file)
@@ -442,7 +442,6 @@ NTSTATUS read_fd_with_timeout(int fd, char *buf,
        ssize_t readret;
        size_t nread = 0;
        struct timeval timeout;
-       char addr[INET6_ADDRSTRLEN];
        int save_errno;
 
        /* just checking .... */
@@ -465,19 +464,6 @@ NTSTATUS read_fd_with_timeout(int fd, char *buf,
                        }
 
                        if (readret == -1) {
-                               save_errno = errno;
-                               if (fd == smbd_server_fd()) {
-                                       /* Try and give an error message
-                                        * saying what client failed. */
-                                       DEBUG(0,("read_fd_with_timeout: "
-                                               "client %s read error = %s.\n",
-                                               get_peer_addr(fd,addr,sizeof(addr)),
-                                               strerror(save_errno) ));
-                               } else {
-                                       DEBUG(0,("read_fd_with_timeout: "
-                                               "read error = %s.\n",
-                                               strerror(save_errno) ));
-                               }
                                return map_nt_error_from_unix(save_errno);
                        }
                        nread += readret;
@@ -503,20 +489,6 @@ NTSTATUS read_fd_with_timeout(int fd, char *buf,
 
                /* Check if error */
                if (selrtn == -1) {
-                       save_errno = errno;
-                       /* something is wrong. Maybe the socket is dead? */
-                       if (fd == smbd_server_fd()) {
-                               /* Try and give an error message saying
-                                * what client failed. */
-                               DEBUG(0,("read_fd_with_timeout: timeout "
-                               "read for client %s. select error = %s.\n",
-                               get_peer_addr(fd,addr,sizeof(addr)),
-                               strerror(save_errno) ));
-                       } else {
-                               DEBUG(0,("read_fd_with_timeout: timeout "
-                               "read. select error = %s.\n",
-                               strerror(save_errno) ));
-                       }
                        return map_nt_error_from_unix(save_errno);
                }
 
@@ -537,20 +509,6 @@ NTSTATUS read_fd_with_timeout(int fd, char *buf,
                }
 
                if (readret == -1) {
-                       save_errno = errno;
-                       /* the descriptor is probably dead */
-                       if (fd == smbd_server_fd()) {
-                               /* Try and give an error message
-                                * saying what client failed. */
-                               DEBUG(0,("read_fd_with_timeout: timeout "
-                                       "read to client %s. read error = %s.\n",
-                                       get_peer_addr(fd,addr,sizeof(addr)),
-                                       strerror(save_errno) ));
-                       } else {
-                               DEBUG(0,("read_fd_with_timeout: timeout "
-                                       "read. read error = %s.\n",
-                                       strerror(save_errno) ));
-                       }
                        return map_nt_error_from_unix(errno);
                }
 
@@ -573,7 +531,25 @@ NTSTATUS read_fd_with_timeout(int fd, char *buf,
 
 NTSTATUS read_data(int fd, char *buffer, size_t N)
 {
-       return read_fd_with_timeout(fd, buffer, N, N, 0, NULL);
+       NTSTATUS status;
+
+       status = read_fd_with_timeout(fd, buffer, N, N, 0, NULL);
+       if (NT_STATUS_IS_OK(status)) {
+               return status;
+       }
+       if (fd == smbd_server_fd()) {
+               char addr[INET6_ADDRSTRLEN];
+               /* Try and give an error message
+                * saying what client failed. */
+               DEBUG(0, ("read_fd_with_timeout failed for "
+                         "client %s read error = %s.\n",
+                         get_peer_addr(fd,addr,sizeof(addr)),
+                         nt_errstr(status)));
+       } else {
+               DEBUG(0, ("read_fd_with_timeout failed, read error = %s.\n",
+                         nt_errstr(status)));
+       }
+       return status;
 }
 
 /****************************************************************************
@@ -694,6 +670,18 @@ NTSTATUS read_smb_length_return_keepalive(int fd, char *inbuf,
        status = read_fd_with_timeout(fd, inbuf, 4, 4, timeout, NULL);
 
        if (!NT_STATUS_IS_OK(status)) {
+               if (fd == smbd_server_fd()) {
+                       char addr[INET6_ADDRSTRLEN];
+                       /* Try and give an error message
+                        * saying what client failed. */
+                       DEBUG(0, ("read_fd_with_timeout failed for "
+                                 "client %s read error = %s.\n",
+                                 get_peer_addr(fd,addr,sizeof(addr)),
+                                 nt_errstr(status)));
+               } else {
+                       DEBUG(0, ("read_fd_with_timeout failed, read error = "
+                                 "%s.\n", nt_errstr(status)));
+               }
                return status;
        }
 
@@ -776,6 +764,19 @@ NTSTATUS receive_smb_raw(int fd, char *buffer, size_t buflen, unsigned int timeo
                        fd, buffer+4, len, len, timeout, &len);
 
                if (!NT_STATUS_IS_OK(status)) {
+                       if (fd == smbd_server_fd()) {
+                               char addr[INET6_ADDRSTRLEN];
+                               /* Try and give an error message
+                                * saying what client failed. */
+                               DEBUG(0, ("read_fd_with_timeout failed for "
+                                         "client %s read error = %s.\n",
+                                         get_peer_addr(fd,addr,sizeof(addr)),
+                                         nt_errstr(status)));
+                       } else {
+                               DEBUG(0, ("read_fd_with_timeout failed, "
+                                         "read error = %s.\n",
+                                         nt_errstr(status)));
+                       }
                        return status;
                }
 
index 2e76e55dfa447ee95caedda906a90c0b7e77cc40..525f8382c6bda00607c16fbc332417ef314e8d50 100644 (file)
@@ -269,6 +269,8 @@ static int expect(int master, char *issue, char *expected)
                                timeout, &len);
 
                        if (!NT_STATUS_IS_OK(status)) {
+                               DEBUG(2, ("expect: read error %s\n",
+                                         nt_errstr(status)));
                                break;
                        }
                        nread += len;
index c44d86a6b863b5cce6a489d82f738a90c98bb242..8c781c8955f1e4a604d37a4b787e92400cceb875 100644 (file)
@@ -206,11 +206,21 @@ static bool valid_packet_size(size_t len)
 static NTSTATUS read_packet_remainder(int fd, char *buffer,
                                      unsigned int timeout, ssize_t len)
 {
+       NTSTATUS status;
+
        if (len <= 0) {
                return NT_STATUS_OK;
        }
 
-       return read_fd_with_timeout(fd, buffer, len, len, timeout, NULL);
+       status = read_fd_with_timeout(fd, buffer, len, len, timeout, NULL);
+       if (!NT_STATUS_IS_OK(status)) {
+               char addr[INET6_ADDRSTRLEN];
+               DEBUG(0, ("read_fd_with_timeout failed for client %s read "
+                         "error = %s.\n",
+                         get_peer_addr(fd, addr, sizeof(addr)),
+                         nt_errstr(status)));
+       }
+       return status;
 }
 
 /****************************************************************************
@@ -251,6 +261,11 @@ static NTSTATUS receive_smb_raw_talloc_partial_read(TALLOC_CTX *mem_ctx,
                timeout, NULL);
 
        if (!NT_STATUS_IS_OK(status)) {
+               char addr[INET6_ADDRSTRLEN];
+               DEBUG(0, ("read_fd_with_timeout failed for client %s read "
+                         "error = %s.\n",
+                         get_peer_addr(fd, addr, sizeof(addr)),
+                         nt_errstr(status)));
                return status;
        }