xtrans ChangeLog, 3.8, 3.9 Xtrans.c, 3.34, 3.35 Xtransdnet.c, 3.8, 3.9 Xtransint.h, 3.41, 3.42 Xtranssock.c, 3.65, 3.66 Xtransutil.c, 3.28, 3.29

Daniel Stone xlibs-commit@pdx.freedesktop.org
Fri Jan 28 11:53:29 PST 2005


Committed by: daniels

Update of /cvs/xlibs/xtrans
In directory gabe:/tmp/cvs-serv7374

Modified Files:
	ChangeLog Xtrans.c Xtransdnet.c Xtransint.h Xtranssock.c 
	Xtransutil.c 
Log Message:
Resync from X.Org HEAD (mainly Cygwin changes).

Index: ChangeLog
===================================================================
RCS file: /cvs/xlibs/xtrans/ChangeLog,v
retrieving revision 3.8
retrieving revision 3.9
diff -u -d -r3.8 -r3.9
--- ChangeLog	21 Oct 2004 09:17:19 -0000	3.8
+++ ChangeLog	28 Jan 2005 19:53:27 -0000	3.9
@@ -1,3 +1,12 @@
+2005-01-29  Daniel Stone  <daniel@freedesktop.org>
+
+	* Xtrans.c:
+	* Xtransdnet.c:
+	* Xtransint.h:
+	* Xtranssock.c:
+	* Xtransutil.c:
+	Resync from X.Org HEAD -- mainly Cygwin changes.
+
 2004-10-21  Daniel Stone  <daniel@freedesktop.org>
 
 	* configure.ac:

Index: Xtrans.c
===================================================================
RCS file: /cvs/xlibs/xtrans/Xtrans.c,v
retrieving revision 3.34
retrieving revision 3.35
diff -u -d -r3.34 -r3.35
--- Xtrans.c	18 Apr 2004 11:10:53 -0000	3.34
+++ Xtrans.c	28 Jan 2005 19:53:27 -0000	3.35
@@ -1,4 +1,4 @@
-/* $XdotOrg: xc/lib/xtrans/Xtrans.c,v 1.1.4.3.4.1 2004/03/04 17:47:15 eich Exp $ */
+/* $XdotOrg: xc/lib/xtrans/Xtrans.c,v 1.4 2004/11/15 15:06:56 ago Exp $ */
 /* $Xorg: Xtrans.c,v 1.4 2001/02/09 02:04:06 xorgcvs Exp $ */
 /*
 
@@ -726,7 +726,11 @@
 #else
 #if (defined(AIXV3) || defined(uniosu) || defined(WIN32) || defined(__UNIXOS2__) || defined(__QNX__)) && defined(FIONBIO)
 	{
+#ifdef WIN32
+	    u_long arg;
+#else
 	    int arg;
+#endif
 	    arg = 1;
 /* IBM TCP/IP understands this option too well: it causes TRANS(Read) to fail
  * eventually with EWOULDBLOCK */
@@ -1132,7 +1136,7 @@
     *partial = (*count_ret < complete_network_count());
 
     PRMSG (5,
-     "MakeAllCLTSServerListeners: partial=%d, actual=%d, complete=%d \n",
+     "MakeAllCOTSServerListeners: partial=%d, actual=%d, complete=%d \n",
 	*partial, *count_ret, complete_network_count());
 
     if (*count_ret > 0)

Index: Xtransdnet.c
===================================================================
RCS file: /cvs/xlibs/xtrans/Xtransdnet.c,v
retrieving revision 3.8
retrieving revision 3.9
diff -u -d -r3.8 -r3.9
--- Xtransdnet.c	26 Aug 2003 15:38:39 -0000	3.8
+++ Xtransdnet.c	28 Jan 2005 19:53:27 -0000	3.9
@@ -525,7 +525,11 @@
     PRMSG (2,"DNETBytesReadable(%x,%d,%x)\n", ciptr, ciptr->fd, pend);
 
 #ifdef WIN32
-    return ioctlsocket ((SOCKET) ciptr->fd, FIONREAD, (u_long *) pend);
+    {
+	int ret = ioctlsocket ((SOCKET) ciptr->fd, FIONREAD, (u_long *) pend);
+	errno = WSAGetLastError();
+	return ret;
+    }
 #else
     return ioctl(ciptr->fd, FIONREAD, (char *)pend);
 #endif /* WIN32 */
@@ -539,7 +543,11 @@
     PRMSG (2,"DNETRead(%d,%x,%d)\n", ciptr->fd, buf, size);
 
 #ifdef WIN32
-    return recv ((SOCKET)ciptr->fd, buf, size, 0);
+    {
+	int ret = recv ((SOCKET)ciptr->fd, buf, size, 0);
+	errno = WSAGetLastError();
+	return ret;
+    }
 #else
     return read (ciptr->fd, buf, size);
 #endif /* WIN32 */
@@ -553,7 +561,11 @@
     PRMSG (2,"DNETWrite(%d,%x,%d)\n", ciptr->fd, buf, size);
 
 #ifdef WIN32
-    return send ((SOCKET)ciptr->fd, buf, size, 0);
+    {
+	int ret = send ((SOCKET)ciptr->fd, buf, size, 0);
+	errno = WSAGetLastError();
+	return ret;
+    }
 #else
     return write (ciptr->fd, buf, size);
 #endif /* WIN32 */
@@ -586,7 +598,15 @@
 {
     PRMSG (2,"DNETDisconnect(%x,%d)\n", ciptr, ciptr->fd, 0);
 
+#ifdef WIN32
+    {
+	int ret = shutdown (ciptr->fd, 2);
+	errno = WSAGetLastError();
+	return ret;
+    }
+#else
     return shutdown (ciptr->fd, 2); /* disallow further sends and receives */
+#endif
 }
 
 
@@ -596,7 +616,15 @@
 {
     PRMSG (2,"DNETClose(%x,%d)\n", ciptr, ciptr->fd, 0);
 
+#ifdef WIN32
+    {
+	int ret = close (ciptr->fd);
+	errno = WSAGetLastError();
+	return ret;
+    }
+#else
     return close (ciptr->fd);
+#endif
 }
 
 

Index: Xtransint.h
===================================================================
RCS file: /cvs/xlibs/xtrans/Xtransint.h,v
retrieving revision 3.41
retrieving revision 3.42
diff -u -d -r3.41 -r3.42
--- Xtransint.h	28 Aug 2003 00:35:23 -0000	3.41
+++ Xtransint.h	28 Jan 2005 19:53:27 -0000	3.42
@@ -1,3 +1,4 @@
+/* $XdotOrg: xc/lib/xtrans/Xtransint.h,v 1.2 2004/04/23 18:44:27 eich Exp $ */
 /* $Xorg: Xtransint.h,v 1.4 2001/02/09 02:04:06 xorgcvs Exp $ */
 /*
 
@@ -26,7 +27,7 @@
 from The Open Group.
 
 */
-/* $XFree86: xc/lib/xtrans/Xtransint.h,v 3.40 2003/08/27 21:58:28 tsi Exp $ */
+/* $XFree86: xc/lib/xtrans/Xtransint.h,v 3.41 2003/08/28 00:35:23 tsi Exp $ */
 
 /* Copyright 1993, 1994 NCR Corporation - Dayton, Ohio, USA
  *
@@ -132,7 +133,7 @@
 #   endif
 #  endif
 #  ifndef OPEN_MAX
-#   if defined(_SC_OPEN_MAX)
+#   if defined(_SC_OPEN_MAX) && !defined(__UNIXOS2__)
 #    define OPEN_MAX (sysconf(_SC_OPEN_MAX))
 #   else
 #    ifdef SVR4

Index: Xtranssock.c
===================================================================
RCS file: /cvs/xlibs/xtrans/Xtranssock.c,v
retrieving revision 3.65
retrieving revision 3.66
diff -u -d -r3.65 -r3.66
--- Xtranssock.c	18 Apr 2004 11:10:53 -0000	3.65
+++ Xtranssock.c	28 Jan 2005 19:53:27 -0000	3.66
@@ -1,4 +1,4 @@
-/* $XdotOrg: xc/lib/xtrans/Xtranssock.c,v 1.1.4.6.2.2 2004/03/24 18:56:22 eich Exp $ */
+/* $XdotOrg: xc/lib/xtrans/Xtranssock.c,v 1.3 2004/11/15 15:06:56 ago Exp $ */
 /* $Xorg: Xtranssock.c,v 1.11 2001/02/09 02:04:06 xorgcvs Exp $ */
 /*
 
@@ -114,6 +114,7 @@
 #else /* !WIN32 */
 
 #include <X11/Xwinsock.h>
+#include <X11/Xwindows.h>
 #include <X11/Xw32defs.h>
 #undef close
 #define close closesocket
@@ -122,6 +123,7 @@
 #define EPROTOTYPE WSAEPROTOTYPE
 #undef EWOULDBLOCK
 #define EWOULDBLOCK WSAEWOULDBLOCK
+#define EINPROGRESS WSAEINPROGRESS
 #undef EINTR
 #define EINTR WSAEINTR
 #define X_INCLUDE_NETDB_H
@@ -348,6 +350,9 @@
     if (getsockname (ciptr->fd,(struct sockaddr *) socknamePtr,
 		     (void *)&namelen) < 0)
     {
+#ifdef WIN32
+	errno = WSAGetLastError();
+#endif
 	PRMSG (1,"SocketINETGetAddr: getsockname() failed: %d\n",
 	    EGET(),0, 0);
 	return -1;
@@ -420,6 +425,9 @@
     if (getpeername (ciptr->fd, (struct sockaddr *) socknamePtr,
 		     (void *)&namelen) < 0)
     {
+#ifdef WIN32
+	errno = WSAGetLastError();
+#endif
 	PRMSG (1,"SocketINETGetPeerAddr: getpeername() failed: %d\n",
 	    EGET(), 0, 0);
 	return -1;
@@ -475,6 +483,9 @@
 #endif
 #endif
       ) {
+#ifdef WIN32
+	errno = WSAGetLastError();
+#endif
 	PRMSG (2, "SocketOpen: socket() failed for %s\n",
 	    Sockettrans2devtab[i].transname, 0, 0);
 
@@ -1233,6 +1244,9 @@
     if ((newciptr->fd = accept (ciptr->fd,
 	(struct sockaddr *) &sockname, (void *)&namelen)) < 0)
     {
+#ifdef WIN32
+	errno = WSAGetLastError();
+#endif
 	PRMSG (1, "SocketINETAccept: accept() failed\n", 0, 0, 0);
 	xfree (newciptr);
 	*status = TRANS_ACCEPT_FAILED;
@@ -2081,7 +2095,11 @@
     *pend = 0L; /* FIONREAD only returns a short. Zero out upper bits */
 #endif
 #ifdef WIN32
-    return ioctlsocket ((SOCKET) ciptr->fd, FIONREAD, (u_long *) pend);
+    {
+	int ret = ioctlsocket ((SOCKET) ciptr->fd, FIONREAD, (u_long *) pend);
+	errno = WSAGetLastError();
+	return ret;
+    }
 #else
 #if (defined(i386) && defined(SYSV) && !defined(sco)) || (defined(_SEQUENT_) && _SOCKET_VERSION == 1)
     return ioctl (ciptr->fd, I_NREAD, (char *) pend);
@@ -2103,7 +2121,13 @@
     PRMSG (2,"SocketRead(%d,%p,%d)\n", ciptr->fd, buf, size);
 
 #if defined(WIN32) || defined(__UNIXOS2__)
-    return recv ((SOCKET)ciptr->fd, buf, size, 0);
+    {
+	int ret = recv ((SOCKET)ciptr->fd, buf, size, 0);
+#ifdef WIN32
+	errno = WSAGetLastError();
+#endif
+	return ret;
+    }
 #else
     return read (ciptr->fd, buf, size);
 #endif /* WIN32 */
@@ -2117,7 +2141,13 @@
     PRMSG (2,"SocketWrite(%d,%p,%d)\n", ciptr->fd, buf, size);
 
 #if defined(WIN32) || defined(__UNIXOS2__)
-    return send ((SOCKET)ciptr->fd, buf, size, 0);
+    {
+	int ret = send ((SOCKET)ciptr->fd, buf, size, 0);
+#ifdef WIN32
+	errno = WSAGetLastError();
+#endif
+	return ret;
+    }
 #else
     return write (ciptr->fd, buf, size);
 #endif /* WIN32 */
@@ -2150,7 +2180,15 @@
 {
     PRMSG (2,"SocketDisconnect(%p,%d)\n", ciptr, ciptr->fd, 0);
 
+#ifdef WIN32
+    { 
+	int ret = shutdown (ciptr->fd, 2);
+	errno = WSAGetLastError();
+	return ret;
+    }
+#else
     return shutdown (ciptr->fd, 2); /* disallow further sends and receives */
+#endif
 }
 
 
@@ -2161,7 +2199,15 @@
 {
     PRMSG (2,"SocketINETClose(%p,%d)\n", ciptr, ciptr->fd, 0);
 
+#ifdef WIN32
+    {
+	int ret = close (ciptr->fd);
+	errno = WSAGetLastError();
+	return ret;
+    }
+#else
     return close (ciptr->fd);
+#endif
 }
 
 #endif /* TCPCONN */

Index: Xtransutil.c
===================================================================
RCS file: /cvs/xlibs/xtrans/Xtransutil.c,v
retrieving revision 3.28
retrieving revision 3.29
diff -u -d -r3.28 -r3.29
--- Xtransutil.c	18 Apr 2004 11:10:53 -0000	3.28
+++ Xtransutil.c	28 Jan 2005 19:53:27 -0000	3.29
@@ -190,7 +190,7 @@
 	*familyp=FamilyLocal;
 	break;
     }
-#endif /* defined(UNIXCONN) || defined(LOCALCONN) || defined(OS2PIPECONN*/
+#endif /* defined(UNIXCONN) || defined(LOCALCONN) || defined(OS2PIPECONN)*/
 
 
     default:
@@ -472,7 +472,7 @@
 
     PRMSG (2,"WSAStartup()\n", 0, 0, 0);
 
-    if (!wsadata.wVersion && WSAStartup(MAKEWORD(1,1), &wsadata))
+    if (!wsadata.wVersion && WSAStartup(0x0101, &wsadata))
         return 1;
     return 0;
 }
@@ -498,34 +498,84 @@
 #include <errno.h>
 
 #if !defined(S_IFLNK) && !defined(S_ISLNK)
+#undef lstat
 #define lstat(a,b) stat(a,b)
 #endif
 
+#define FAIL_IF_NOMODE  1
+#define FAIL_IF_NOT_ROOT 2
+#define WARN_NO_ACCESS 4
+
+/*
+ * We make the assumption that when the 'sticky' (t) bit is requested
+ * it's not save if the directory has non-root ownership or the sticky
+ * bit cannot be set and fail.
+ */
 static int 
 trans_mkdir(char *path, int mode)
 {
     struct stat buf;
 
-    if (mkdir(path, mode) == 0) {
-	chmod(path, mode);
-	return 0;
-    }
-    /* If mkdir failed with EEXIST, test if it is a directory with 
-       the right modes, else fail */
-    if (errno == EEXIST) {
-	if (lstat(path, &buf) != 0) {
-	    PRMSG(1, "mkdir: (l)stat failed for %s (%d)\n",
+    if (lstat(path, &buf) != 0) {
+	if (errno != ENOENT) {
+	    PRMSG(1, "mkdir: ERROR: (l)stat failed for %s (%d)\n",
 		  path, errno, 0);
 	    return -1;
 	}
+	/* Dir doesn't exist. Try to create it */
+
+#ifndef WIN32
+	/*
+	 * 'sticky' bit requested: assume application makes
+	 * certain security implications. If effective user ID
+	 * is != 0: fail as we may not be able to meet them.
+	 */
+	if (geteuid() != 0) {
+	    if (mode & 01000) {
+		PRMSG(1, "mkdir: ERROR: euid != 0,"
+		      "directory %s will not be created.\n",
+		      path, 0, 0);	    
+#ifdef FAIL_HARD
+		return -1;
+#endif
+	    } else {
+		PRMSG(1, "mkdir: Cannot create %s with root ownership\n",
+		      path, 0, 0);
+	    }
+	}
+#endif
+
+#ifndef WIN32
+	if (mkdir(path, mode) == 0) {
+	    if (chmod(path, mode)) {
+		PRMSG(1, "mkdir: ERROR: Mode of %s should be set to %04o\n",
+		      path, mode, 0);
+#ifdef FAIL_HARD
+		return -1;
+#endif
+	    }
+#else
+	if (mkdir(path) == 0) {
+#endif
+	} else {
+	    PRMSG(1, "mkdir: ERROR: Cannot create %s\n",
+		  path, 0, 0);
+	    return -1;
+	}
+
+	return 0;
+	
+    } else {
 	if (S_ISDIR(buf.st_mode)) {
 	    int updateOwner = 0;
 	    int updateMode = 0;
 	    int updatedOwner = 0;
 	    int updatedMode = 0;
+	    int status = 0;
 	    /* Check if the directory's ownership is OK. */
 	    if (buf.st_uid != 0)
 		updateOwner = 1;
+
 	    /*
 	     * Check if the directory's mode is OK.  An exact match isn't
 	     * required, just a mode that isn't more permissive than the
@@ -533,9 +583,29 @@
 	     */
 	    if ((~mode) & 0077 & buf.st_mode)
 		updateMode = 1;
-	    if ((mode & 01000) &&
-		(buf.st_mode & 0002) && !(buf.st_mode & 01000))
+	    
+	    /*
+	     * If the directory is not writeable not everybody may
+	     * be able to create sockets. Therefore warn if mode
+	     * cannot be fixed.
+	     */
+	    if ((~buf.st_mode) & 0022 & mode) {
 		updateMode = 1;
+		status |= WARN_NO_ACCESS;
+	    }
+	    
+	    /*
+	     * If 'sticky' bit is requested fail if owner isn't root
+	     * as we assume the caller makes certain security implications
+	     */
+	    if (mode & 01000) {
+		status |= FAIL_IF_NOT_ROOT;
+		if (!(buf.st_mode & 01000)) {
+		    status |= FAIL_IF_NOMODE;
+		    updateMode = 1;
+		}
+	    }
+	    
 #ifdef HAS_FCHOWN
 	    /*
 	     * If fchown(2) and fchmod(2) are available, try to correct the
@@ -547,7 +617,7 @@
 		struct stat fbuf;
 		if ((fd = open(path, O_RDONLY)) != -1) {
 		    if (fstat(fd, &fbuf) == -1) {
-			PRMSG(1, "mkdir: fstat failed for %s (%d)\n",
+			PRMSG(1, "mkdir: ERROR: fstat failed for %s (%d)\n",
 			      path, errno, 0);
 			return -1;
 		    }
@@ -558,7 +628,7 @@
 		    if (!S_ISDIR(fbuf.st_mode) ||
 			buf.st_dev != fbuf.st_dev ||
 			buf.st_ino != fbuf.st_ino) {
-			PRMSG(1, "mkdir: inode for %s changed\n",
+			PRMSG(1, "mkdir: ERROR: inode for %s changed\n",
 			      path, 0, 0);
 			return -1;
 		    }
@@ -570,23 +640,39 @@
 		}
 	    }
 #endif
+	    
 	    if (updateOwner && !updatedOwner) {
+#ifdef FAIL_HARD
+		if (status & FAIL_IF_NOT_ROOT) {
+		    PRMSG(1, "mkdir: ERROR: Owner of %s must be set to root\n",
+			  path, 0, 0);
+		    return -1;
+		}
+#endif
 	  	PRMSG(1, "mkdir: Owner of %s should be set to root\n",
 		      path, 0, 0);
-#if 0 && !defined(__CYGWIN__) && !defined(__DARWIN__)
-		sleep(5);
-#endif
 	    }
+	    
 	    if (updateMode && !updatedMode) {
+#ifdef FAIL_HARD
+		if (status & FAIL_IF_NOMODE) {
+		    PRMSG(1, "mkdir: ERROR: Mode of %s must be set to %04o\n",
+			  path, mode, 0);
+		    return -1;
+		}
+#endif
 	  	PRMSG(1, "mkdir: Mode of %s should be set to %04o\n",
 		      path, mode, 0);
-#if 0 && !defined(__CYGWIN__) && !defined(__DARWIN__)
-		sleep(5);
-#endif
+		if (status & WARN_NO_ACCESS) {
+		    PRMSG(1, "mkdir: this may cause subsequent errors\n",
+			  0, 0, 0);
+		}
 	    }
 	    return 0;
 	}
+	return -1;
     }
+
     /* In all other cases, fail */
     return -1;
 }



More information about the xlibs-commit mailing list