# Copyright (c) 2008, 2009, Oracle and/or its affiliates. All rights reserved.
#
# Permission is hereby granted, free of charge, to any person obtaining a
# copy of this software and associated documentation files (the "Software"),
# to deal in the Software without restriction, including without limitation
# the rights to use, copy, modify, merge, publish, distribute, sublicense,
# and/or sell copies of the Software, and to permit persons to whom the
# Software is furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice (including the next
# paragraph) shall be included in all copies or substantial portions of the
# Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
# THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
# FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
# DEALINGS IN THE SOFTWARE.
#
diff --git a/src/XShm.c b/src/XShm.c
index f82455c..d21f380 100644
--- a/src/XShm.c
+++ b/src/XShm.c
@@ -38,6 +38,13 @@ in this Software without prior written authorization from The Open Group.
#include <X11/extensions/Xext.h>
#include <X11/extensions/extutil.h>
+#ifdef SUNSOFT
+#include <fcntl.h>
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <ucred.h>
+#endif
+
static XExtensionInfo _shm_info_data;
static XExtensionInfo *shm_info = &_shm_info_data;
static const char *shm_extension_name = SHMNAME;
@@ -135,6 +142,46 @@ event_to_wire (Display *dpy, XEvent *re, xEvent *event)
return False;
}
+#ifdef SUNSOFT
+/*
+ * Function to determine if a connection is local or not.
+ * Returns: 0 for remote, 1 for local
+ */
+
+static int
+LocalConnection(Display *dpy)
+{
+ int c = ConnectionNumber(dpy);
+ int rv = 0;
+ struct stat statbuf;
+ ucred_t *ucred = NULL;
+
+ if (c >= 0) {
+ /*
+ * First stat the connection fd. If we succeed and the type of file
+ * is a FIFO, then we must be local.
+ */
+ if ((fstat(c, &statbuf) >= 0) && S_ISFIFO(statbuf.st_mode)) {
+ return 1;
+ }
+
+ /*
+ * Then call getpeerucred - if it succeeds, the other end of the
+ * connection must be on the same machine (though possibly in a
+ * different zone).
+ */
+ if (getpeerucred(c, &ucred) == 0) {
+ if (ucred_getzoneid(ucred) != -1) {
+ rv = 1;
+ }
+ ucred_free(ucred);
+ }
+ }
+
+ return rv;
+}
+#endif /* SUNSOFT */
+
/*****************************************************************************
* *
* public Shared Memory Extension routines *
@@ -144,6 +191,15 @@ event_to_wire (Display *dpy, XEvent *re, xEvent *event)
Bool XShmQueryExtension (Display *dpy /* int *event_basep, *error_basep */)
{
XExtDisplayInfo *info = find_display (dpy);
+#ifdef SUNSOFT
+ /*
+ * Sun Mod -- if we're dealing with a remote connection, then the
+ * shared memory extension is not valid. Sigh -- this should really
+ * be in the server somewhere... Required for pipe transport PIPECONN
+ */
+ if(!LocalConnection(dpy))
+ return False;
+#endif /* SUNSOFT */
if (XextHasExtension(info)) {
/* *event_basep = info->codes->first_event;
@@ -176,6 +232,15 @@ Bool XShmQueryVersion(
XExtDisplayInfo *info = find_display (dpy);
xShmQueryVersionReply rep;
register xShmQueryVersionReq *req;
+#ifdef SUNSOFT
+ /*
+ * Sun Mod -- if we're dealing with a remote connection, then the
+ * shared memory extension is not valid. Sigh -- this should really
+ * be in the server somewhere...
+ */
+ if(!LocalConnection(dpy))
+ return False;
+#endif /* SUNSOFT */
ShmCheckExtension (dpy, info, False);