# Copyright (c) 2007, 2015, 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/common/rfb/Makefile.am b/common/rfb/Makefile.am
index 1894871..ad4956e 100644
--- a/common/rfb/Makefile.am
+++ b/common/rfb/Makefile.am
@@ -55,7 +55,7 @@ librfb_la_SOURCES += $(VENCRYPT_HDRS) $(VENCRYPT_SRCS)
 endif
 
 librfb_la_CPPFLAGS = -I$(top_srcdir)/common -I$(top_srcdir)/win
-librfb_la_LIBADD = @GNUTLS_LIBS@
+librfb_la_LIBADD = @GNUTLS_LIBS@ $(LIBS)
 
 if HAVE_PAM
 librfb_la_SOURCES += UnixPasswordValidator.cxx UnixPasswordValidator.h pam.c pam.h
diff --git a/unix/vncserver b/unix/vncserver
index f3468ed..b8682f6 100755
--- a/unix/vncserver
+++ b/unix/vncserver
@@ -40,6 +40,7 @@ $vncClasses = "";
 
 $xauth = "xauth";
 
+$ENV{PATH} = "/usr/X11/bin:" . $ENV{PATH};
 &SanityCheck();
 
 #
@@ -76,6 +77,15 @@ $defaultXStartup
        "if [ -f /etc/X11/xinit/xinitrc ]; then\n".
        "  exec sh /etc/X11/xinit/xinitrc\n".
        "fi\n".
+       "if [ -x /etc/gdm/Xsession ] && [ -x /usr/bin/dtstart ] ; then\n".
+       "  exec /etc/gdm/Xsession /usr/bin/dtstart jds\n".
+       "fi\n".
+       "if [ -x /etc/X11/gdm/Xsession ] && [ -x /usr/bin/dtstart ] ; then\n".
+       "  exec /etc/X11/gdm/Xsession /usr/bin/dtstart jds\n".
+       "fi\n".
+       "if [ -x /usr/dt/config/Xsession.jds ]; then\n".
+       "  exec /usr/dt/config/Xsession.jds\n".
+       "fi\n".
        "[ -r \$HOME/.Xresources ] && xrdb \$HOME/.Xresources\n".
        "xsetroot -solid grey\n".
        "xterm -geometry 80x24+10+10 -ls -title \"\$VNCDESKTOP Desktop\" &\n".
diff --git a/unix/xserver/hw/vnc/Makefile.am b/unix/xserver/hw/vnc/Makefile.am
index 8c49429..50b03e5 100644
--- a/unix/xserver/hw/vnc/Makefile.am
+++ b/unix/xserver/hw/vnc/Makefile.am
@@ -17,7 +17,7 @@ libvnccommon_la_SOURCES = $(HDRS) vncExtInit.cc vncHooks.cc XserverDesktop.cc \
 
 libvnccommon_la_CPPFLAGS = -DVENDOR_RELEASE="$(VENDOR_RELEASE)" \
 	-DVENDOR_STRING="\"$(VENDOR_STRING)\"" -I$(TIGERVNC_SRCDIR)/common -UHAVE_CONFIG_H \
-	-I$(TIGERVNC_SRCDIR)/unix/vncconfig $(XVNC_CPPFLAGS) -I$(includedir)/pixman-1 -I$(includedir)
+	-I$(TIGERVNC_SRCDIR)/unix/vncconfig $(XVNC_CPPFLAGS) $(PIXMAN_CFLAGS) -I$(includedir)
 
 bin_PROGRAMS = Xvnc
 
@@ -33,13 +33,16 @@ Xvnc_CPPFLAGS = $(XVNC_CPPFLAGS) -DTIGERVNC -DNO_HW_ONLY_EXTS -DNO_MODULE_EXTS \
 	-UHAVE_CONFIG_H \
 	-DXFree86Server -DVENDOR_RELEASE="$(VENDOR_RELEASE)" \
 	-DVENDOR_STRING="\"$(VENDOR_STRING)\"" -I$(TIGERVNC_SRCDIR)/common \
-	-I$(top_srcdir)/include -I$(includedir)/pixman-1 -I$(includedir)
+	-I$(top_srcdir)/include $(PIXMAN_CFLAGS)
 
 Xvnc_LDADD = $(XVNC_LIBS) libvnccommon.la $(COMMON_LIBS) \
-	$(XSERVER_LIBS) $(XSERVER_SYS_LIBS) $(XVNC_SYS_LIBS) -lX11
+	-ljpeg -lz \
+	../../IA/libIA.la \
+	$(XSERVER_LIBS) $(XSERVER_SYS_LIBS) $(XVNC_SYS_LIBS)
 
 Xvnc_LDFLAGS = $(LD_EXPORT_SYMBOLS_FLAG)
 
+if XORG
 libvnc_la_LTLIBRARIES = libvnc.la
 libvnc_ladir = $(moduledir)/extensions
 
@@ -49,11 +57,12 @@ libvnc_la_CPPFLAGS = $(XVNC_CPPFLAGS) -I$(TIGERVNC_SRCDIR)/common -UHAVE_CONFIG_
 	-I$(top_srcdir)/hw/xfree86/common \
 	-I$(top_srcdir)/hw/xfree86/os-support \
 	-I$(top_srcdir)/hw/xfree86/os-support/bus \
-	-I$(includedir)/pixman-1 -I$(includedir)
+	$(PIXMAN_CFLAGS)
 
 libvnc_la_LDFLAGS = -module -avoid-version
 
 libvnc_la_LIBADD = libvnccommon.la $(COMMON_LIBS)
+endif
 
 EXTRA_DIST = Xvnc.man
 
@@ -63,8 +72,8 @@ BUILT_SOURCES = $(nodist_Xvnc_SOURCES)
 fb.h: $(top_srcdir)/fb/fb.h
 	cat $(top_srcdir)/fb/fb.h | sed -e 's,and,c_and,g' -e 's,xor,c_xor,g' > $(srcdir)/fb.h
 
-pixman.h: $(includedir)/pixman-1/pixman.h
-	cat $(includedir)/pixman-1/pixman.h | sed 's/xor/c_xor/' > $(srcdir)/pixman.h
+pixman.h: $(PROTODIR)$(includedir)/pixman-1/pixman.h
+	cat $(PROTODIR)$(includedir)/pixman-1/pixman.h | sed 's/xor/c_xor/g' > $(srcdir)/pixman.h
 
 fbrop.h: $(top_srcdir)/fb/fbrop.h
 	cat $(top_srcdir)/fb/fbrop.h | sed -e 's,and,c_and,g' -e 's,xor,c_xor,g' > $(srcdir)/fbrop.h
diff --git a/unix/xserver/hw/vnc/Xvnc.man b/unix/xserver/hw/vnc/Xvnc.man
index 356925d..ea9ee56 100644
--- a/unix/xserver/hw/vnc/Xvnc.man
+++ b/unix/xserver/hw/vnc/Xvnc.man
@@ -71,8 +71,7 @@ List all the options and parameters
 
 .SH PARAMETERS
 VNC parameters can be set both via the command-line and through the
-\fBvncconfig\fP(1) program, and with a VNC-enabled Xorg server via Options
-entries in the xorg.conf file.
+\fBvncconfig\fP(1) program.
 
 Parameters can be turned on with -\fIparam\fP or off with
 -\fIparam\fP=0.  Parameters which take a value can be specified as
@@ -225,12 +224,12 @@ is a hexadecimal keysym. For example, to exchange the " and @ symbols you would
 RemapKeys=0x22<>0x40
 
 .SH USAGE WITH INETD
-By configuring the \fBinetd\fP(1) service appropriately, Xvnc can be launched
+By configuring the \fBinetd\fP(1M) service appropriately, Xvnc can be launched
 on demand when a connection comes in, rather than having to be started
 manually.  When given the \fB-inetd\fP option, instead of listening for TCP
 connections on a given port it uses its standard input and standard output.
 There are two modes controlled by the wait/nowait entry in the inetd.conf file.
-
+.PP
 In the nowait mode, Xvnc uses its standard input and output directly as the
 connection to a viewer.  It never has a listening socket, so cannot accept
 further connections from viewers (it can however connect out to listening
@@ -238,17 +237,26 @@ viewers by use of the vncconfig program).  Further viewer connections to the
 same TCP port result in inetd spawning off a new Xvnc to deal with each
 connection.  When the connection to the viewer dies, the Xvnc and any
 associated X clients die.  This behaviour is most useful when combined with the
-XDMCP options -query and -once.  An typical example in inetd.conf might be (all
-on one line):
-
-5950   stream   tcp nowait nobody  /usr/local/bin/Xvnc Xvnc -inetd -query
-localhost -once securitytypes=none
-
-In this example a viewer connection to :50 will result in a new Xvnc for that
-connection which should display the standard XDM login screen on that machine.
-Because the user needs to login via XDM, it is usually OK to accept connections
-without a VNC password in this case.
-
+XDMCP options -query and -once.  
+.PP
+The provided application/x11/xvnc-inetd service defaults to running
+
+.B "/usr/bin/Xvnc -inetd -query localhost -once securitytypes=none"
+
+in nowait mode.   This service can be enabled via 
+.BR svcadm (1m),
+and configured to use other modes or arguments via
+.BR svccfg (1m).
+.PP
+In this configuration, connecting to :0 will result in a new Xvnc for that
+connection which should display the standard graphical login screen on that 
+machine.   (To enable this, you will also have to enable XDMCP network 
+connections on the login screen.   See 
+.BR gdm (1)
+for details.)
+Because the user needs to login via this screen, it is usually OK to accept 
+connections without a VNC password in this case.
+.PP
 In the wait mode, when the first connection comes in, inetd gives the listening
 socket to Xvnc.  This means that for a given TCP port, there is only ever one
 Xvnc at a time.  Further viewer connections to the same port are accepted by
@@ -256,14 +264,14 @@ the same Xvnc in the normal way.  Even when the original connection is broken,
 the Xvnc will continue to run.  If this is used with the XDMCP options -query
 and -once, the Xvnc and associated X clients will die when the user logs out of
 the X session in the normal way.  It is important to use a VNC password in this
-case.  A typical entry in inetd.conf might be:
-
-5951   stream   tcp wait   james     /usr/local/bin/Xvnc Xvnc -inetd -query localhost -once passwordFile=/home/james/.vnc/passwd
+case.  A typical command line to include in the service exec property might be:
 
+.B "/usr/bin/Xvnc Xvnc -inetd -query localhost -once passwordFile=/home/james/.vnc/passwd"
+.PP
 In fact typically, you would have one entry for each user who uses VNC
 regularly, each of whom has their own dedicated TCP port which they use.  In
-this example, when user "james" connects to :51, he enters his VNC password,
-then gets the XDM login screen where he logs in in the normal way.  However,
+this example, when user "james" connects, he enters his VNC password,
+then gets the login screen where he logs in in the normal way.  However,
 unlike the previous example, if he disconnects, the session remains persistent,
 and when he reconnects he will get the same session back again.  When he logs
 out of the X session, the Xvnc will die, but of course a new one will be
