[SCM] Samba Shared Repository - branch v3-2-test updated - initial-v3-2-unstable-177-g963fc76

Jeremy Allison jra at samba.org
Sun Nov 4 06:28:30 GMT 2007


The branch, v3-2-test has been updated
       via  963fc7685212689f02b3adcc05b4273ee5c382d4 (commit)
      from  35aaa36f82c70964cee5d0778eb04547b226dd3f (commit)

http://gitweb.samba.org/?p=samba.git;a=shortlog;h=v3-2-test


- Log -----------------------------------------------------------------
commit 963fc7685212689f02b3adcc05b4273ee5c382d4
Author: Jeremy Allison <jra at samba.org>
Date:   Sat Nov 3 23:20:10 2007 -0700

    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.

-----------------------------------------------------------------------

Summary of changes:
 source/auth/pampass.c             |    4 +-
 source/lib/dummysmbd.c            |    5 +++
 source/lib/substitute.c           |    9 +++--
 source/lib/util_sock.c            |   68 ++++++++++++++++--------------------
 source/modules/vfs_expand_msdfs.c |    2 +-
 source/printing/print_cups.c      |    4 +-
 source/printing/print_iprint.c    |    4 +-
 source/rpc_server/srv_netlog_nt.c |    4 +-
 source/smbd/connection.c          |    3 +-
 source/smbd/process.c             |    2 +-
 source/smbd/server.c              |    5 ++-
 source/smbd/service.c             |    7 ++--
 source/smbd/session.c             |    7 ++--
 source/smbd/sesssetup.c           |    4 +-
 source/torture/vfstest.c          |    5 +++
 15 files changed, 71 insertions(+), 62 deletions(-)


Changeset truncated at 500 lines:

diff --git a/source/auth/pampass.c b/source/auth/pampass.c
index c7ec79b..739e0a7 100644
--- a/source/auth/pampass.c
+++ b/source/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/source/lib/dummysmbd.c b/source/lib/dummysmbd.c
index 038a945..e3b179b 100644
--- a/source/lib/dummysmbd.c
+++ b/source/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/source/lib/substitute.c b/source/lib/substitute.c
index bd15399..7f357e9 100644
--- a/source/lib/substitute.c
+++ b/source/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/source/lib/util_sock.c b/source/lib/util_sock.c
index b317364..4b39e32 100644
--- a/source/lib/util_sock.c
+++ b/source/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/source/modules/vfs_expand_msdfs.c b/source/modules/vfs_expand_msdfs.c
index 4b670d5..2a16b5a 100644
--- a/source/modules/vfs_expand_msdfs.c
+++ b/source/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/source/printing/print_cups.c b/source/printing/print_cups.c
index 5709d93..2ffd322 100644
--- a/source/printing/print_cups.c
+++ b/source/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/source/printing/print_iprint.c b/source/printing/print_iprint.c
index 6dd1957..b038f8d 100644
--- a/source/printing/print_iprint.c
+++ b/source/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/source/rpc_server/srv_netlog_nt.c b/source/rpc_server/srv_netlog_nt.c
index f876ee9..b6ae104 100644
--- a/source/rpc_server/srv_netlog_nt.c
+++ b/source/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/source/smbd/connection.c b/source/smbd/connection.c
index f041513..95e45a6 100644
--- a/source/smbd/connection.c
+++ b/source/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/source/smbd/process.c b/source/smbd/process.c
index 24feac4..aa39b01 100644
--- a/source/smbd/process.c
+++ b/source/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/source/smbd/server.c b/source/smbd/server.c
index e77573b..fbf886e 100644
--- a/source/smbd/server.c
+++ b/source/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/source/smbd/service.c b/source/smbd/service.c
index 502fade..2402be3 100644
--- a/source/smbd/service.c
+++ b/source/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/source/smbd/session.c b/source/smbd/session.c
index 69f4a37..000b2f5 100644
--- a/source/smbd/session.c
+++ b/source/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/source/smbd/sesssetup.c b/source/smbd/sesssetup.c
index 87cb3b4..0e8483c 100644
--- a/source/smbd/sesssetup.c
+++ b/source/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/source/torture/vfstest.c b/source/torture/vfstest.c
index bdbb951..0633d0c 100644
--- a/source/torture/vfstest.c
+++ b/source/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
 ****************************************************************************/


-- 
Samba Shared Repository


More information about the samba-cvs mailing list