diff options
author | Jeremy Allison <jra@samba.org> | 2007-11-03 23:20:10 -0700 |
---|---|---|
committer | Jeremy Allison <jra@samba.org> | 2007-11-03 23:20:10 -0700 |
commit | 5b0b4f23ef5fec3d1ad518237f973d4e014b5766 (patch) | |
tree | f75cdfaef81e5fcc0cf7061e0141b97831508ee1 | |
parent | 51a0354d751f48a2542984c81e218da33669bbeb (diff) | |
download | samba-5b0b4f23ef5fec3d1ad518237f973d4e014b5766.tar.gz samba-5b0b4f23ef5fec3d1ad518237f973d4e014b5766.tar.bz2 samba-5b0b4f23ef5fec3d1ad518237f973d4e014b5766.zip |
Remove most of the remaining globals out of lib/util_sock.c.
I have a plan for dealing with the remaining..... Watch
this space.
Jeremy.
(This used to be commit 963fc7685212689f02b3adcc05b4273ee5c382d4)
-rw-r--r-- | source3/auth/pampass.c | 4 | ||||
-rw-r--r-- | source3/lib/dummysmbd.c | 5 | ||||
-rw-r--r-- | source3/lib/substitute.c | 9 | ||||
-rw-r--r-- | source3/lib/util_sock.c | 68 | ||||
-rw-r--r-- | source3/modules/vfs_expand_msdfs.c | 2 | ||||
-rw-r--r-- | source3/printing/print_cups.c | 4 | ||||
-rw-r--r-- | source3/printing/print_iprint.c | 4 | ||||
-rw-r--r-- | source3/rpc_server/srv_netlog_nt.c | 4 | ||||
-rw-r--r-- | source3/smbd/connection.c | 3 | ||||
-rw-r--r-- | source3/smbd/process.c | 2 | ||||
-rw-r--r-- | source3/smbd/server.c | 5 | ||||
-rw-r--r-- | source3/smbd/service.c | 7 | ||||
-rw-r--r-- | source3/smbd/session.c | 7 | ||||
-rw-r--r-- | source3/smbd/sesssetup.c | 4 | ||||
-rw-r--r-- | source3/torture/vfstest.c | 5 |
15 files changed, 71 insertions, 62 deletions
diff --git a/source3/auth/pampass.c b/source3/auth/pampass.c index c7ec79b969..739e0a78fd 100644 --- a/source3/auth/pampass.c +++ b/source3/auth/pampass.c @@ -468,9 +468,9 @@ static bool smb_pam_start(pam_handle_t **pamh, const char *user, const char *rho } if (rhost == NULL) { - our_rhost = client_name(); + our_rhost = client_name(get_client_fd()); if (strequal(our_rhost,"UNKNOWN")) - our_rhost = client_addr(addr,sizeof(addr)); + our_rhost = client_addr(get_client_fd(),addr,sizeof(addr)); } else { our_rhost = rhost; } diff --git a/source3/lib/dummysmbd.c b/source3/lib/dummysmbd.c index 038a945c92..e3b179b763 100644 --- a/source3/lib/dummysmbd.c +++ b/source3/lib/dummysmbd.c @@ -23,6 +23,11 @@ #include "includes.h" +int get_client_fd(void) +{ + return -1; +} + int find_service(fstring service) { return -1; diff --git a/source3/lib/substitute.c b/source3/lib/substitute.c index bd15399b13..7f357e9f67 100644 --- a/source3/lib/substitute.c +++ b/source3/lib/substitute.c @@ -52,7 +52,8 @@ void set_local_machine_name(const char* local_name, bool perm) */ if ( strequal(tmp_local_machine, "*SMBSERVER") || strequal(tmp_local_machine, "*SMBSERV") ) { - fstrcpy( local_machine, client_socket_addr(addr, sizeof(addr)) ); + fstrcpy( local_machine, + client_socket_addr(get_client_fd(), addr, sizeof(addr)) ); return; } @@ -497,11 +498,11 @@ char *alloc_sub_basic(const char *smb_name, const char *domain_name, break; case 'I' : a_string = realloc_string_sub(a_string, "%I", - client_addr(addr, sizeof(addr))); + client_addr(get_client_fd(),addr, sizeof(addr))); break; case 'i': a_string = realloc_string_sub( a_string, "%i", - client_socket_addr(addr, sizeof(addr)) ); + client_socket_addr(get_client_fd(), addr, sizeof(addr)) ); break; case 'L' : if ( StrnCaseCmp(p, "%LOGONSERVER%", strlen("%LOGONSERVER%")) == 0 ) { @@ -517,7 +518,7 @@ char *alloc_sub_basic(const char *smb_name, const char *domain_name, a_string = realloc_string_sub(a_string, "%N", automount_server(smb_name)); break; case 'M' : - a_string = realloc_string_sub(a_string, "%M", client_name()); + a_string = realloc_string_sub(a_string, "%M", client_name(get_client_fd())); break; case 'R' : a_string = realloc_string_sub(a_string, "%R", remote_proto); diff --git a/source3/lib/util_sock.c b/source3/lib/util_sock.c index b31736430e..4b39e32115 100644 --- a/source3/lib/util_sock.c +++ b/source3/lib/util_sock.c @@ -21,13 +21,6 @@ #include "includes.h" -/* the following 3 client_*() functions are nasty ways of allowing - some generic functions to get info that really should be hidden in - particular modules */ -static int client_fd = -1; -/* What to print out on a client disconnect error. */ -static char client_ip_string[INET6_ADDRSTRLEN]; - /**************************************************************************** Return true if a string could be an IPv4 address. ****************************************************************************/ @@ -573,19 +566,6 @@ char *print_canonical_sockaddr(TALLOC_CTX *ctx, } /**************************************************************************** - Set the global client_fd variable. -****************************************************************************/ - -void client_setfd(int fd) -{ - char addr[INET6_ADDRSTRLEN]; - client_fd = fd; - safe_strcpy(client_ip_string, - get_peer_addr(client_fd,addr,sizeof(addr)), - sizeof(client_ip_string)-1); -} - -/**************************************************************************** Return the string of an IP address (IPv4 or IPv6). ****************************************************************************/ @@ -614,6 +594,8 @@ static const char *get_socket_addr(int fd, char *addr_buf, size_t addr_len) return print_sockaddr_len(addr_buf, addr_len, &sa, length); } +#if 0 +/* Not currently used. JRA. */ /**************************************************************************** Return the port number we've bound to on a socket. ****************************************************************************/ @@ -643,26 +625,30 @@ static int get_socket_port(int fd) } return -1; } +#endif -const char *client_name(void) +const char *client_name(int fd) { - return get_peer_name(client_fd,false); + return get_peer_name(fd,false); } -const char *client_addr(char *addr, size_t addrlen) +const char *client_addr(int fd, char *addr, size_t addrlen) { - return get_peer_addr(client_fd,addr,addrlen); + return get_peer_addr(fd,addr,addrlen); } -const char *client_socket_addr(char *addr, size_t addr_len) +const char *client_socket_addr(int fd, char *addr, size_t addr_len) { - return get_socket_addr(client_fd, addr, addr_len); + return get_socket_addr(fd, addr, addr_len); } -int client_socket_port(void) +#if 0 +/* Not currently used. JRA. */ +int client_socket_port(int fd) { - return get_socket_port(client_fd); + return get_socket_port(fd); } +#endif /**************************************************************************** Accessor functions to make thread-safe code easier later... @@ -904,6 +890,7 @@ ssize_t read_socket_with_timeout(int fd, ssize_t readret; size_t nread = 0; struct timeval timeout; + char addr[INET6_ADDRSTRLEN]; /* just checking .... */ if (maxcnt <= 0) @@ -928,12 +915,12 @@ ssize_t read_socket_with_timeout(int fd, } if (readret == -1) { - if (fd == client_fd) { + if (fd == get_client_fd()) { /* Try and give an error message * saying what client failed. */ DEBUG(0,("read_socket_with_timeout: " "client %s read error = %s.\n", - client_ip_string, + get_peer_addr(fd,addr,sizeof(addr)), strerror(errno) )); } else { DEBUG(0,("read_socket_with_timeout: " @@ -967,12 +954,13 @@ ssize_t read_socket_with_timeout(int fd, /* Check if error */ if (selrtn == -1) { /* something is wrong. Maybe the socket is dead? */ - if (fd == client_fd) { + if (fd == get_client_fd()) { /* Try and give an error message saying * what client failed. */ DEBUG(0,("read_socket_with_timeout: timeout " "read for client %s. select error = %s.\n", - client_ip_string, strerror(errno) )); + get_peer_addr(fd,addr,sizeof(addr)), + strerror(errno) )); } else { DEBUG(0,("read_socket_with_timeout: timeout " "read. select error = %s.\n", @@ -1002,12 +990,13 @@ ssize_t read_socket_with_timeout(int fd, if (readret == -1) { /* the descriptor is probably dead */ - if (fd == client_fd) { + if (fd == get_client_fd()) { /* Try and give an error message * saying what client failed. */ DEBUG(0,("read_socket_with_timeout: timeout " "read to client %s. read error = %s.\n", - client_ip_string, strerror(errno) )); + get_peer_addr(fd,addr,sizeof(addr)), + strerror(errno) )); } else { DEBUG(0,("read_socket_with_timeout: timeout " "read. read error = %s.\n", @@ -1032,6 +1021,7 @@ ssize_t read_data(int fd,char *buffer,size_t N) { ssize_t ret; size_t total=0; + char addr[INET6_ADDRSTRLEN]; set_smb_read_error(SMB_READ_OK); @@ -1047,13 +1037,13 @@ ssize_t read_data(int fd,char *buffer,size_t N) } if (ret == -1) { - if (fd == client_fd) { + if (fd == get_client_fd()) { /* Try and give an error message saying * what client failed. */ DEBUG(0,("read_data: read failure for %d " "bytes to client %s. Error = %s\n", (int)(N - total), - client_ip_string, + get_peer_addr(fd,addr,sizeof(addr)), strerror(errno) )); } else { DEBUG(0,("read_data: read failure for %d. " @@ -1077,17 +1067,19 @@ ssize_t write_data(int fd, const char *buffer, size_t N) { size_t total=0; ssize_t ret; + char addr[INET6_ADDRSTRLEN]; while (total < N) { ret = sys_write(fd,buffer + total,N - total); if (ret == -1) { - if (fd == client_fd) { + if (fd == get_client_fd()) { /* Try and give an error message saying * what client failed. */ DEBUG(0,("write_data: write failure in " "writing to client %s. Error %s\n", - client_ip_string, strerror(errno) )); + get_peer_addr(fd,addr,sizeof(addr)), + strerror(errno) )); } else { DEBUG(0,("write_data: write failure. " "Error = %s\n", strerror(errno) )); diff --git a/source3/modules/vfs_expand_msdfs.c b/source3/modules/vfs_expand_msdfs.c index 4b670d5172..2a16b5a731 100644 --- a/source3/modules/vfs_expand_msdfs.c +++ b/source3/modules/vfs_expand_msdfs.c @@ -71,7 +71,7 @@ static bool read_target_host(const char *mapfile, pstring targethost) *space = '\0'; - if (strncmp(client_addr(addr,sizeof(addr)), + if (strncmp(client_addr(get_client_fd(),addr,sizeof(addr)), buf, strlen(buf)) == 0) { found = True; break; diff --git a/source3/printing/print_cups.c b/source3/printing/print_cups.c index 5709d93624..2ffd322b45 100644 --- a/source3/printing/print_cups.c +++ b/source3/printing/print_cups.c @@ -618,9 +618,9 @@ static int cups_job_submit(int snum, struct printjob *pjob) ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_NAME, "requesting-user-name", NULL, pjob->user); - clientname = client_name(); + clientname = client_name(get_client_fd()); if (strcmp(clientname, "UNKNOWN") == 0) { - clientname = client_addr(addr,sizeof(addr)); + clientname = client_addr(get_client_fd(),addr,sizeof(addr)); } ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_NAME, diff --git a/source3/printing/print_iprint.c b/source3/printing/print_iprint.c index 6dd19577f1..b038f8d1fe 100644 --- a/source3/printing/print_iprint.c +++ b/source3/printing/print_iprint.c @@ -779,9 +779,9 @@ static int iprint_job_submit(int snum, struct printjob *pjob) ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_NAME, "requesting-user-name", NULL, pjob->user); - clientname = client_name(); + clientname = client_name(get_client_fd()); if (strcmp(clientname, "UNKNOWN") == 0) { - clientname = client_addr(addr,sizeof(addr)); + clientname = client_addr(get_client_fd(),addr,sizeof(addr)); } ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_NAME, diff --git a/source3/rpc_server/srv_netlog_nt.c b/source3/rpc_server/srv_netlog_nt.c index f876ee976d..b6ae104d1c 100644 --- a/source3/rpc_server/srv_netlog_nt.c +++ b/source3/rpc_server/srv_netlog_nt.c @@ -210,8 +210,8 @@ static NTSTATUS get_md4pw(char *md4pw, char *mach_acct, uint16 sec_chan_type) */ if (!allow_access(lp_domain_hostsdeny(), lp_domain_hostsallow(), - client_name(), client_addr(addr,sizeof(addr)))) - { + client_name(get_client_fd()), + client_addr(get_client_fd(),addr,sizeof(addr)))) { DEBUG(0,("get_md4pw: Workstation %s denied access to domain\n", mach_acct)); return False; } diff --git a/source3/smbd/connection.c b/source3/smbd/connection.c index f041513820..95e45a6990 100644 --- a/source3/smbd/connection.c +++ b/source3/smbd/connection.c @@ -152,7 +152,8 @@ bool claim_connection(connection_struct *conn, const char *name, crec.bcast_msg_flags = msg_flags; strlcpy(crec.machine,get_remote_machine_name(),sizeof(crec.machine)); - strlcpy(crec.addr,conn?conn->client_address:client_addr(addr,sizeof(addr)), + strlcpy(crec.addr,conn?conn->client_address: + client_addr(get_client_fd(),addr,sizeof(addr)), sizeof(crec.addr)); dbuf.dptr = (uint8 *)&crec; diff --git a/source3/smbd/process.c b/source3/smbd/process.c index 24feac4630..aa39b01258 100644 --- a/source3/smbd/process.c +++ b/source3/smbd/process.c @@ -1472,7 +1472,7 @@ static void process_smb(char *inbuf, size_t nread, size_t unread_bytes) /* send a negative session response "not listening on calling name" */ static unsigned char buf[5] = {0x83, 0, 0, 1, 0x81}; DEBUG( 1, ( "Connection denied from %s\n", - client_addr(addr,sizeof(addr)) ) ); + client_addr(get_client_fd(),addr,sizeof(addr)) ) ); (void)send_smb(smbd_server_fd(),(char *)buf); exit_server_cleanly("connection denied"); } diff --git a/source3/smbd/server.c b/source3/smbd/server.c index e77573b9c6..fbf886ee67 100644 --- a/source3/smbd/server.c +++ b/source3/smbd/server.c @@ -59,9 +59,12 @@ int smbd_server_fd(void) static void smbd_set_server_fd(int fd) { server_fd = fd; - client_setfd(fd); } +int get_client_fd(void) +{ + return server_fd; +} struct event_context *smbd_event_context(void) { diff --git a/source3/smbd/service.c b/source3/smbd/service.c index 502fadedc7..2402be3aed 100644 --- a/source3/smbd/service.c +++ b/source3/smbd/service.c @@ -758,8 +758,9 @@ static connection_struct *make_connection_snum(int snum, user_struct *vuser, add_session_user(user); - safe_strcpy(conn->client_address, client_addr(addr,sizeof(addr)), - sizeof(conn->client_address)-1); + safe_strcpy(conn->client_address, + client_addr(get_client_fd(),addr,sizeof(addr)), + sizeof(conn->client_address)-1); conn->num_files_open = 0; conn->lastused = conn->lastused_count = time(NULL); conn->used = True; @@ -1303,7 +1304,7 @@ connection_struct *make_connection(const char *service_in, DATA_BLOB password, DEBUG(0,("%s (%s) couldn't find service %s\n", get_remote_machine_name(), - client_addr(addr,sizeof(addr)), + client_addr(get_client_fd(),addr,sizeof(addr)), service)); *status = NT_STATUS_BAD_NETWORK_NAME; return NULL; diff --git a/source3/smbd/session.c b/source3/smbd/session.c index 69f4a37c85..000b2f5d9c 100644 --- a/source3/smbd/session.c +++ b/source3/smbd/session.c @@ -159,9 +159,9 @@ bool session_claim(user_struct *vuser) client_name() handles this case internally. */ - hostname = client_name(); + hostname = client_name(get_client_fd()); if (strcmp(hostname, "UNKNOWN") == 0) { - hostname = client_addr(addr,sizeof(addr)); + hostname = client_addr(get_client_fd(),addr,sizeof(addr)); } fstrcpy(sessionid.username, vuser->user.unix_name); @@ -171,7 +171,8 @@ bool session_claim(user_struct *vuser) sessionid.uid = vuser->uid; sessionid.gid = vuser->gid; fstrcpy(sessionid.remote_machine, get_remote_machine_name()); - fstrcpy(sessionid.ip_addr_str, client_addr(addr,sizeof(addr))); + fstrcpy(sessionid.ip_addr_str, + client_addr(get_client_fd(),addr,sizeof(addr))); sessionid.connect_start = time(NULL); if (!smb_pam_claim_session(sessionid.username, sessionid.id_str, diff --git a/source3/smbd/sesssetup.c b/source3/smbd/sesssetup.c index 87cb3b435b..0e8483c81e 100644 --- a/source3/smbd/sesssetup.c +++ b/source3/smbd/sesssetup.c @@ -1317,8 +1317,8 @@ static void setup_new_vc_session(void) #endif if (lp_reset_on_zero_vc()) { connections_forall(shutdown_other_smbds, - CONST_DISCARD(void *, - client_addr(addr,sizeof(addr)))); + CONST_DISCARD(void *, + client_addr(get_client_fd(),addr,sizeof(addr)))); } } diff --git a/source3/torture/vfstest.c b/source3/torture/vfstest.c index bdbb9511c7..0633d0c2e7 100644 --- a/source3/torture/vfstest.c +++ b/source3/torture/vfstest.c @@ -34,6 +34,11 @@ static struct cmd_list { extern pstring user_socket_options; +int get_client_fd(void) +{ + return -1; +} + /**************************************************************************** handle completion of commands for readline ****************************************************************************/ |