diff options
author | Jeremy Allison <jra@samba.org> | 2007-11-03 15:12:42 -0700 |
---|---|---|
committer | Jeremy Allison <jra@samba.org> | 2007-11-03 15:12:42 -0700 |
commit | 73d407968002587eadd0ff13eb413ddf07c78771 (patch) | |
tree | e1656e24e0298ee3b9097c1904618955535233e4 /source3 | |
parent | 705ba0d5b5156075d841ce120cea967f665f52d6 (diff) | |
download | samba-73d407968002587eadd0ff13eb413ddf07c78771.tar.gz samba-73d407968002587eadd0ff13eb413ddf07c78771.tar.bz2 samba-73d407968002587eadd0ff13eb413ddf07c78771.zip |
Remove the smb_read_error global variable and replace
it with accessor functions. "One global or pstring a day...." :-).
Jeremy.
(This used to be commit d50d14c300abc83b7015718ec48acc8b3227a273)
Diffstat (limited to 'source3')
-rw-r--r-- | source3/include/client.h | 3 | ||||
-rw-r--r-- | source3/include/smb.h | 15 | ||||
-rw-r--r-- | source3/lib/util_sock.c | 59 | ||||
-rw-r--r-- | source3/libsmb/cliconnect.c | 2 | ||||
-rw-r--r-- | source3/libsmb/clientgen.c | 21 | ||||
-rw-r--r-- | source3/libsmb/clierror.c | 20 | ||||
-rw-r--r-- | source3/smbd/nttrans.c | 1 | ||||
-rw-r--r-- | source3/smbd/oplock.c | 1 | ||||
-rw-r--r-- | source3/smbd/oplock_irix.c | 5 | ||||
-rw-r--r-- | source3/smbd/process.c | 51 | ||||
-rw-r--r-- | source3/smbd/trans2.c | 1 |
11 files changed, 91 insertions, 88 deletions
diff --git a/source3/include/client.h b/source3/include/client.h index e38017fe7b..d8c35780a4 100644 --- a/source3/include/client.h +++ b/source3/include/client.h @@ -82,7 +82,8 @@ struct rpc_pipe_client { struct cli_state { int port; int fd; - int smb_rw_error; /* Copy of last read or write error. */ + /* Copy of last read or write error. */ + enum smb_read_errors smb_rw_error; uint16 cnum; uint16 pid; uint16 mid; diff --git a/source3/include/smb.h b/source3/include/smb.h index 303f7606d3..be339f2e38 100644 --- a/source3/include/smb.h +++ b/source3/include/smb.h @@ -72,12 +72,15 @@ #include "debug.h" /* this defines the error codes that receive_smb can put in smb_read_error */ -#define READ_TIMEOUT 1 -#define READ_EOF 2 -#define READ_ERROR 3 -#define WRITE_ERROR 4 /* This error code can go into the client smb_rw_error. */ -#define READ_BAD_SIG 5 -#define DO_NOT_DO_TDIS 6 /* cli_close_connection() check for this when smbfs wants to keep tree connected */ +enum smb_read_errors { + SMB_READ_OK = 0, + SMB_READ_TIMEOUT, + SMB_READ_EOF, + SMB_READ_ERROR, + SMB_WRITE_ERROR, /* This error code can go into the client smb_rw_error. */ + SMB_READ_BAD_SIG, + SMB_DO_NOT_DO_TDIS /* cli_close_connection() check for this when smbfs wants to keep tree connected */ +}; #define DIR_STRUCT_SIZE 43 diff --git a/source3/lib/util_sock.c b/source3/lib/util_sock.c index 4a73f92bd8..ea33de8077 100644 --- a/source3/lib/util_sock.c +++ b/source3/lib/util_sock.c @@ -673,7 +673,28 @@ int client_socket_port(void) return get_socket_port(client_fd); } -int smb_read_error = 0; +/**************************************************************************** + Accessor functions to make thread-safe code easier later... +****************************************************************************/ + +static enum smb_read_errors smb_read_error = SMB_READ_OK; + +enum smb_read_errors get_smb_read_error(void) +{ + return smb_read_error; +} + +void set_smb_read_error(enum smb_read_errors newerr) +{ + smb_read_error = newerr; +} + +void cond_set_smb_read_error(enum smb_read_errors newerr) +{ + if (smb_read_error == SMB_READ_OK) { + smb_read_error = newerr; + } +} /**************************************************************************** Determine if a file descriptor is in fact a socket. @@ -897,7 +918,7 @@ ssize_t read_socket_with_timeout(int fd, if (maxcnt <= 0) return(0); - smb_read_error = 0; + set_smb_read_error(SMB_READ_OK); /* Blocking read */ if (time_out == 0) { @@ -911,7 +932,7 @@ ssize_t read_socket_with_timeout(int fd, if (readret == 0) { DEBUG(5,("read_socket_with_timeout: " "blocking read. EOF from client.\n")); - smb_read_error = READ_EOF; + set_smb_read_error(SMB_READ_EOF); return -1; } @@ -928,7 +949,7 @@ ssize_t read_socket_with_timeout(int fd, "read error = %s.\n", strerror(errno) )); } - smb_read_error = READ_ERROR; + set_smb_read_error(SMB_READ_ERROR); return -1; } nread += readret; @@ -966,7 +987,7 @@ ssize_t read_socket_with_timeout(int fd, "read. select error = %s.\n", strerror(errno) )); } - smb_read_error = READ_ERROR; + set_smb_read_error(SMB_READ_ERROR); return -1; } @@ -974,7 +995,7 @@ ssize_t read_socket_with_timeout(int fd, if (selrtn == 0) { DEBUG(10,("read_socket_with_timeout: timeout read. " "select timed out.\n")); - smb_read_error = READ_TIMEOUT; + set_smb_read_error(SMB_READ_TIMEOUT); return -1; } @@ -984,7 +1005,7 @@ ssize_t read_socket_with_timeout(int fd, /* we got EOF on the file descriptor */ DEBUG(5,("read_socket_with_timeout: timeout read. " "EOF from client.\n")); - smb_read_error = READ_EOF; + set_smb_read_error(SMB_READ_EOF); return -1; } @@ -1001,7 +1022,7 @@ ssize_t read_socket_with_timeout(int fd, "read. read error = %s.\n", strerror(errno) )); } - smb_read_error = READ_ERROR; + set_smb_read_error(SMB_READ_ERROR); return -1; } @@ -1021,7 +1042,7 @@ ssize_t read_data(int fd,char *buffer,size_t N) ssize_t ret; size_t total=0; - smb_read_error = 0; + set_smb_read_error(SMB_READ_OK); while (total < N) { ret = sys_read(fd,buffer + total,N - total); @@ -1030,7 +1051,7 @@ ssize_t read_data(int fd,char *buffer,size_t N) DEBUG(10,("read_data: read of %d returned 0. " "Error = %s\n", (int)(N - total), strerror(errno) )); - smb_read_error = READ_EOF; + set_smb_read_error(SMB_READ_EOF); return 0; } @@ -1049,7 +1070,7 @@ ssize_t read_data(int fd,char *buffer,size_t N) (int)(N - total), strerror(errno) )); } - smb_read_error = READ_ERROR; + set_smb_read_error(SMB_READ_ERROR); return -1; } total += ret; @@ -1191,7 +1212,7 @@ ssize_t receive_smb_raw(int fd, { ssize_t len,ret; - smb_read_error = 0; + set_smb_read_error(SMB_READ_OK); len = read_smb_length_return_keepalive(fd,buffer,timeout); if (len < 0) { @@ -1203,8 +1224,7 @@ ssize_t receive_smb_raw(int fd, * variables still suck :-). JRA. */ - if (smb_read_error == 0) - smb_read_error = READ_ERROR; + cond_set_smb_read_error(SMB_READ_ERROR); return -1; } @@ -1224,8 +1244,7 @@ ssize_t receive_smb_raw(int fd, * variables still suck :-). JRA. */ - if (smb_read_error == 0) - smb_read_error = READ_ERROR; + cond_set_smb_read_error(SMB_READ_ERROR); return -1; } } @@ -1246,9 +1265,7 @@ ssize_t receive_smb_raw(int fd, } if (ret != len) { - if (smb_read_error == 0) { - smb_read_error = READ_ERROR; - } + cond_set_smb_read_error(SMB_READ_ERROR); return -1; } @@ -1276,8 +1293,8 @@ bool receive_smb(int fd, char *buffer, unsigned int timeout) if (!srv_check_sign_mac(buffer, true)) { DEBUG(0, ("receive_smb: SMB Signature verification " "failed on incoming packet!\n")); - if (smb_read_error == 0) { - smb_read_error = READ_BAD_SIG; + if (get_smb_read_error() == 0) { + smb_read_error = SMB_READ_BAD_SIG; } return false; } diff --git a/source3/libsmb/cliconnect.c b/source3/libsmb/cliconnect.c index 448bfd7663..b86939a897 100644 --- a/source3/libsmb/cliconnect.c +++ b/source3/libsmb/cliconnect.c @@ -699,7 +699,7 @@ static NTSTATUS cli_session_setup_ntlmssp(struct cli_state *cli, const char *use nt_status = cli_nt_error(cli); if (cli_is_error(cli) && NT_STATUS_IS_OK(nt_status)) { - if (cli->smb_rw_error == READ_BAD_SIG) { + if (cli->smb_rw_error == SMB_READ_BAD_SIG) { nt_status = NT_STATUS_ACCESS_DENIED; } else { nt_status = NT_STATUS_UNSUCCESSFUL; diff --git a/source3/libsmb/clientgen.c b/source3/libsmb/clientgen.c index 19210dd069..0a8ff4e552 100644 --- a/source3/libsmb/clientgen.c +++ b/source3/libsmb/clientgen.c @@ -20,8 +20,6 @@ #include "includes.h" -extern int smb_read_error; - /**************************************************************************** Change the timeout (in milliseconds). ****************************************************************************/ @@ -112,7 +110,7 @@ bool cli_receive_smb(struct cli_state *cli) /* If the server is not responding, note that now */ if (len < 0) { DEBUG(0, ("Receiving SMB: Server stopped responding\n")); - cli->smb_rw_error = smb_read_error; + cli->smb_rw_error = get_smb_read_error(); close(cli->fd); cli->fd = -1; return False; @@ -135,12 +133,12 @@ bool cli_receive_smb(struct cli_state *cli) * Reflected signature on login error. * Set bad sig but don't close fd. */ - cli->smb_rw_error = READ_BAD_SIG; + cli->smb_rw_error = SMB_READ_BAD_SIG; return True; } DEBUG(0, ("SMB Signature verification failed on incoming packet!\n")); - cli->smb_rw_error = READ_BAD_SIG; + cli->smb_rw_error = SMB_READ_BAD_SIG; close(cli->fd); cli->fd = -1; return False; @@ -242,7 +240,8 @@ bool cli_receive_smb_readX_header(struct cli_state *cli) read_err: - cli->smb_rw_error = smb_read_error = READ_ERROR; + set_smb_read_error(SMB_READ_ERROR); + cli->smb_rw_error = SMB_READ_ERROR; close(cli->fd); cli->fd = -1; return False; @@ -286,7 +285,7 @@ bool cli_send_smb(struct cli_state *cli) if (ret <= 0) { close(cli->fd); cli->fd = -1; - cli->smb_rw_error = WRITE_ERROR; + cli->smb_rw_error = SMB_WRITE_ERROR; DEBUG(0,("Error writing %d bytes to client. %d (%s)\n", (int)len,(int)ret, strerror(errno) )); return False; @@ -328,7 +327,7 @@ bool cli_send_smb_direct_writeX(struct cli_state *cli, if (ret <= 0) { close(cli->fd); cli->fd = -1; - cli->smb_rw_error = WRITE_ERROR; + cli->smb_rw_error = SMB_WRITE_ERROR; DEBUG(0,("Error writing %d bytes to client. %d (%s)\n", (int)len,(int)ret, strerror(errno) )); return false; @@ -343,7 +342,7 @@ bool cli_send_smb_direct_writeX(struct cli_state *cli, if (ret <= 0) { close(cli->fd); cli->fd = -1; - cli->smb_rw_error = WRITE_ERROR; + cli->smb_rw_error = SMB_WRITE_ERROR; DEBUG(0,("Error writing %d extradata " "bytes to client. %d (%s)\n", (int)extradata,(int)ret, strerror(errno) )); @@ -590,11 +589,11 @@ void cli_shutdown(struct cli_state *cli) * later. This tree disconnect forces the peer to clean up, since the * connection will be going away. * - * Also, do not do tree disconnect when cli->smb_rw_error is DO_NOT_DO_TDIS + * Also, do not do tree disconnect when cli->smb_rw_error is SMB_DO_NOT_DO_TDIS * the only user for this so far is smbmount which passes opened connection * down to kernel's smbfs module. */ - if ( (cli->cnum != (uint16)-1) && (cli->smb_rw_error != DO_NOT_DO_TDIS ) ) { + if ( (cli->cnum != (uint16)-1) && (cli->smb_rw_error != SMB_DO_NOT_DO_TDIS ) ) { cli_tdis(cli); } diff --git a/source3/libsmb/clierror.c b/source3/libsmb/clierror.c index 4ab1c237dc..1c35bcf146 100644 --- a/source3/libsmb/clierror.c +++ b/source3/libsmb/clierror.c @@ -72,17 +72,17 @@ static const char *cli_smb_errstr(struct cli_state *cli) static NTSTATUS cli_smb_rw_error_to_ntstatus(struct cli_state *cli) { switch(cli->smb_rw_error) { - case READ_TIMEOUT: + case SMB_READ_TIMEOUT: return NT_STATUS_IO_TIMEOUT; - case READ_EOF: + case SMB_READ_EOF: return NT_STATUS_END_OF_FILE; /* What we shoud really do for read/write errors is convert from errno. */ /* FIXME. JRA. */ - case READ_ERROR: + case SMB_READ_ERROR: return NT_STATUS_INVALID_NETWORK_RESPONSE; - case WRITE_ERROR: + case SMB_WRITE_ERROR: return NT_STATUS_UNEXPECTED_NETWORK_ERROR; - case READ_BAD_SIG: + case SMB_READ_BAD_SIG: return NT_STATUS_INVALID_PARAMETER; default: break; @@ -111,24 +111,24 @@ const char *cli_errstr(struct cli_state *cli) /* Was it server socket error ? */ if (cli->fd == -1 && cli->smb_rw_error) { switch(cli->smb_rw_error) { - case READ_TIMEOUT: + case SMB_READ_TIMEOUT: slprintf(cli_error_message, sizeof(cli_error_message) - 1, "Call timed out: server did not respond after %d milliseconds", cli->timeout); break; - case READ_EOF: + case SMB_READ_EOF: slprintf(cli_error_message, sizeof(cli_error_message) - 1, "Call returned zero bytes (EOF)" ); break; - case READ_ERROR: + case SMB_READ_ERROR: slprintf(cli_error_message, sizeof(cli_error_message) - 1, "Read error: %s", strerror(errno) ); break; - case WRITE_ERROR: + case SMB_WRITE_ERROR: slprintf(cli_error_message, sizeof(cli_error_message) - 1, "Write error: %s", strerror(errno) ); break; - case READ_BAD_SIG: + case SMB_READ_BAD_SIG: slprintf(cli_error_message, sizeof(cli_error_message) - 1, "Server packet had invalid SMB signature!"); break; diff --git a/source3/smbd/nttrans.c b/source3/smbd/nttrans.c index da926d1bce..4bd4571171 100644 --- a/source3/smbd/nttrans.c +++ b/source3/smbd/nttrans.c @@ -22,7 +22,6 @@ extern int max_send; extern enum protocol_types Protocol; -extern int smb_read_error; extern struct current_user current_user; static const char *known_nt_pipes[] = { diff --git a/source3/smbd/oplock.c b/source3/smbd/oplock.c index a84a9dbcb9..961abd277b 100644 --- a/source3/smbd/oplock.c +++ b/source3/smbd/oplock.c @@ -28,7 +28,6 @@ static int32 level_II_oplocks_open = 0; bool global_client_failed_oplock_break = False; extern uint32 global_client_caps; -extern int smb_read_error; static struct kernel_oplocks *koplocks; diff --git a/source3/smbd/oplock_irix.c b/source3/smbd/oplock_irix.c index 8dd4e27973..b8d49f03a1 100644 --- a/source3/smbd/oplock_irix.c +++ b/source3/smbd/oplock_irix.c @@ -104,7 +104,6 @@ static bool irix_oplocks_available(void) static files_struct *irix_oplock_receive_message(fd_set *fds) { - extern int smb_read_error; oplock_stat_t os; char dummy; struct file_id fileid; @@ -122,7 +121,7 @@ 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) )); - smb_read_error = READ_ERROR; + set_smb_read_error(SMB_READ_ERROR); return NULL; } @@ -142,7 +141,7 @@ static files_struct *irix_oplock_receive_message(fd_set *fds) */ return NULL; } - smb_read_error = READ_ERROR; + set_smb_read_error(SMB_READ_ERROR); return NULL; } diff --git a/source3/smbd/process.c b/source3/smbd/process.c index eca51a74a3..11fdb03d72 100644 --- a/source3/smbd/process.c +++ b/source3/smbd/process.c @@ -22,7 +22,6 @@ extern struct auth_context *negprot_global_auth_context; extern int smb_echo_count; -extern int smb_read_error; const int total_buffer_size = (BUFFER_SIZE + LARGE_WRITEX_HDR_SIZE + SAFETY_MARGIN); @@ -39,7 +38,6 @@ int max_send = BUFFER_SIZE; int max_recv = BUFFER_SIZE; extern int last_message; -extern int smb_read_error; SIG_ATOMIC_T reload_after_sighup = 0; SIG_ATOMIC_T got_sig_term = 0; extern bool global_machine_password_needs_changing; @@ -65,8 +63,7 @@ static bool valid_packet_size(len) * variables still suck :-). JRA. */ - if (smb_read_error == 0) - smb_read_error = READ_ERROR; + cond_set_smb_read_error(SMB_READ_ERROR); return false; } } @@ -95,9 +92,7 @@ static ssize_t read_packet_remainder(int fd, } if (ret != len) { - if (smb_read_error == 0) { - smb_read_error = READ_ERROR; - } + cond_set_smb_read_error(SMB_READ_ERROR); return -1; } @@ -148,9 +143,7 @@ ssize_t receive_smb_raw_talloc_partial_read(TALLOC_CTX *mem_ctx, } if (ret != STANDARD_WRITE_AND_X_HEADER_SIZE) { - if (smb_read_error == 0) { - smb_read_error = READ_ERROR; - } + cond_set_smb_read_error(SMB_READ_ERROR); return -1; } @@ -190,8 +183,7 @@ ssize_t receive_smb_raw_talloc_partial_read(TALLOC_CTX *mem_ctx, if (*buffer == NULL) { DEBUG(0, ("Could not allocate inbuf of length %d\n", (int)sizeof(writeX_header))); - if (smb_read_error == 0) - smb_read_error = READ_ERROR; + cond_set_smb_read_error(SMB_READ_ERROR); return -1; } @@ -215,8 +207,7 @@ ssize_t receive_smb_raw_talloc_partial_read(TALLOC_CTX *mem_ctx, if (*buffer == NULL) { DEBUG(0, ("Could not allocate inbuf of length %d\n", (int)len+4)); - if (smb_read_error == 0) - smb_read_error = READ_ERROR; + cond_set_smb_read_error(SMB_READ_ERROR); return -1; } @@ -249,7 +240,7 @@ static ssize_t receive_smb_raw_talloc(TALLOC_CTX *mem_ctx, ssize_t len,ret; int min_recv_size = lp_min_receive_file_size(); - smb_read_error = 0; + set_smb_read_error(SMB_READ_OK); *p_unread = 0; len = read_smb_length_return_keepalive(fd, lenbuf, timeout); @@ -262,8 +253,7 @@ static ssize_t receive_smb_raw_talloc(TALLOC_CTX *mem_ctx, * variables still suck :-). JRA. */ - if (smb_read_error == 0) - smb_read_error = READ_ERROR; + cond_set_smb_read_error(SMB_READ_ERROR); return -1; } @@ -293,8 +283,7 @@ static ssize_t receive_smb_raw_talloc(TALLOC_CTX *mem_ctx, if (*buffer == NULL) { DEBUG(0, ("Could not allocate inbuf of length %d\n", (int)len+4)); - if (smb_read_error == 0) - smb_read_error = READ_ERROR; + cond_set_smb_read_error(SMB_READ_ERROR); return -1; } @@ -323,9 +312,7 @@ ssize_t receive_smb_talloc(TALLOC_CTX *mem_ctx, int fd, char **buffer, if (!srv_check_sign_mac(*buffer, true)) { DEBUG(0, ("receive_smb: SMB Signature verification failed on " "incoming packet!\n")); - if (smb_read_error == 0) { - smb_read_error = READ_BAD_SIG; - } + cond_set_smb_read_error(SMB_READ_BAD_SIG); return -1; } @@ -695,7 +682,7 @@ static bool receive_message_or_smb(TALLOC_CTX *mem_ctx, ssize_t len; *p_unread = 0; - smb_read_error = 0; + set_smb_read_error(SMB_READ_OK); again: @@ -749,7 +736,7 @@ static bool receive_message_or_smb(TALLOC_CTX *mem_ctx, msg->buf.length); if (*buffer == NULL) { DEBUG(0, ("talloc failed\n")); - smb_read_error = READ_ERROR; + set_smb_read_error(SMB_READ_ERROR); return False; } *buffer_len = msg->buf.length; @@ -843,13 +830,13 @@ static bool receive_message_or_smb(TALLOC_CTX *mem_ctx, /* Check if error */ if (selrtn == -1) { /* something is wrong. Maybe the socket is dead? */ - smb_read_error = READ_ERROR; + set_smb_read_error(SMB_READ_ERROR); return False; } /* Did we timeout ? */ if (selrtn == 0) { - smb_read_error = READ_TIMEOUT; + set_smb_read_error(SMB_READ_TIMEOUT); return False; } @@ -1835,20 +1822,20 @@ static bool timeout_processing(int *select_timeout, { time_t t; - if (smb_read_error == READ_EOF) { + if (get_smb_read_error() == SMB_READ_EOF) { DEBUG(3,("timeout_processing: End of file from client (client has disconnected).\n")); - return False; + return false; } - if (smb_read_error == READ_ERROR) { + if (get_smb_read_error() == SMB_READ_ERROR) { DEBUG(3,("timeout_processing: receive_smb error (%s) Exiting\n", strerror(errno))); - return False; + return false; } - if (smb_read_error == READ_BAD_SIG) { + if (get_smb_read_error() == SMB_READ_BAD_SIG) { DEBUG(3,("timeout_processing: receive_smb error bad smb signature. Exiting\n")); - return False; + return false; } *last_timeout_processing_time = t = time(NULL); diff --git a/source3/smbd/trans2.c b/source3/smbd/trans2.c index c9ea02969b..dfd926ace9 100644 --- a/source3/smbd/trans2.c +++ b/source3/smbd/trans2.c @@ -27,7 +27,6 @@ extern int max_send; extern enum protocol_types Protocol; -extern int smb_read_error; extern uint32 global_client_caps; extern struct current_user current_user; |