svn commit: samba r18918 - in branches/SAMBA_4_0/source/lib/socket_wrapper: .

metze at samba.org metze at samba.org
Tue Sep 26 13:15:32 GMT 2006


Author: metze
Date: 2006-09-26 13:15:31 +0000 (Tue, 26 Sep 2006)
New Revision: 18918

WebSVN: http://websvn.samba.org/cgi-bin/viewcvs.cgi?view=rev&root=samba&rev=18918

Log:
- bail out with unsupported option to socket()
- don't reuse portnumbers in the autobind code
- use if (!...) return; logic instead of if (...) { do everything } return
  for swrap_close

metze
Modified:
   branches/SAMBA_4_0/source/lib/socket_wrapper/socket_wrapper.c


Changeset:
Modified: branches/SAMBA_4_0/source/lib/socket_wrapper/socket_wrapper.c
===================================================================
--- branches/SAMBA_4_0/source/lib/socket_wrapper/socket_wrapper.c	2006-09-26 11:31:14 UTC (rev 18917)
+++ branches/SAMBA_4_0/source/lib/socket_wrapper/socket_wrapper.c	2006-09-26 13:15:31 UTC (rev 18918)
@@ -470,7 +470,25 @@
 		errno = EAFNOSUPPORT;
 		return -1;
 	}
-	
+
+	switch (type) {
+	case SOCK_STREAM:
+		break;
+	case SOCK_DGRAM:
+		break;
+	default:
+		errno = EPROTONOSUPPORT;
+		return -1;
+	}
+
+	switch (protocol) {
+	case 0:
+		break;
+	default:
+		errno = EPROTONOSUPPORT;
+		return -1;
+	}
+
 	fd = real_socket(AF_UNIX, type, 0);
 
 	if (fd == -1) return -1;
@@ -557,6 +575,9 @@
 	return fd;
 }
 
+static int autobind_start_init;
+static int autobind_start;
+
 /* using sendto() or connect() on an unbound socket would give the
    recipient no way to reply, as unlike UDP and TCP, a unix domain
    socket can't auto-assign emphemeral port numbers, so we need to
@@ -570,7 +591,14 @@
 	int ret;
 	int port;
 	struct stat st;
-	
+
+	if (autobind_start_init != 1) {
+		autobind_start_init = 1;
+		autobind_start = getpid();
+		autobind_start %= 50000;
+		autobind_start += 10000;
+	}
+
 	un_addr.sun_family = AF_UNIX;
 
 	switch (si->type) {
@@ -584,9 +612,13 @@
 		errno = ESOCKTNOSUPPORT;
 		return -1;
 	}
-	
+
+	if (autobind_start > 60000) {
+		autobind_start = 10000;
+	}
+
 	for (i=0;i<1000;i++) {
-		port = 10000 + i;
+		port = autobind_start + i;
 		snprintf(un_addr.sun_path, sizeof(un_addr.sun_path), 
 			 "%s/"SOCKET_FORMAT, socket_wrapper_dir(),
 			 type, socket_wrapper_default_iface(), port);
@@ -597,13 +629,14 @@
 
 		si->tmp_path = strdup(un_addr.sun_path);
 		si->bound = 1;
+		autobind_start = port + 1;
 		break;
 	}
 	if (i == 1000) {
 		errno = ENFILE;
 		return -1;
 	}
-	
+
 	memset(&in, 0, sizeof(in));
 	in.sin_family = AF_INET;
 	in.sin_port   = htons(port);
@@ -611,7 +644,6 @@
 	
 	si->myname_len = sizeof(in);
 	si->myname = sockaddr_dup(&in, si->myname_len);
-	si->bound = 1;
 	return 0;
 }
 
@@ -872,21 +904,24 @@
 _PUBLIC_ int swrap_close(int fd)
 {
 	struct socket_info *si = find_socket_info(fd);
+	int ret;
 
-	if (si) {
-		DLIST_REMOVE(sockets, si);
+	if (!si) {
+		return real_close(fd);
+	}
 
-		swrap_dump_packet(si, NULL, SWRAP_CLOSE, NULL, 0, 0);
+	DLIST_REMOVE(sockets, si);
 
-		free(si->path);
-		free(si->myname);
-		free(si->peername);
-		if (si->tmp_path) {
-			unlink(si->tmp_path);
-			free(si->tmp_path);
-		}
-		free(si);
+	ret = real_close(fd);
+
+	free(si->path);
+	free(si->myname);
+	free(si->peername);
+	if (si->tmp_path) {
+		unlink(si->tmp_path);
+		free(si->tmp_path);
 	}
+	free(si);
 
-	return real_close(fd);
+	return ret;
 }



More information about the samba-cvs mailing list