21630031 VNC Infrastructure for the Sonoma Platform
authorPhi Tran <Phi.N.Tran@Oracle.COM>
Thu, 11 Feb 2016 13:32:25 -0800
changeset 1604 7c1d3d58ca69
parent 1603 1dce897616eb
child 1605 e8b3582b40fc
21630031 VNC Infrastructure for the Sonoma Platform
open-src/xserver/xorg/vt.patch
open-src/xserver/xserver-common/Xserver
open-src/xserver/xserver-common/x11-server.xml
open-src/xserver/xvnc/Makefile
open-src/xserver/xvnc/screenlock.patch
open-src/xserver/xvnc/vnclock.sh
pkg/manifests/x11-server-xvnc.p5m
--- a/open-src/xserver/xorg/vt.patch	Wed Feb 03 12:04:10 2016 -0800
+++ b/open-src/xserver/xorg/vt.patch	Thu Feb 11 13:32:25 2016 -0800
@@ -1,5 +1,5 @@
 diff --git a/dix/main.c b/dix/main.c
-index 0eaa6aa..f466c25 100644
+index 0fb2a18..68d5263 100644
 --- a/dix/main.c
 +++ b/dix/main.c
 @@ -78,6 +78,8 @@ Equipment Corporation.
@@ -11,12 +11,13 @@
  #include <X11/X.h>
  #include <X11/Xos.h>            /* for unistd.h  */
  #include <X11/Xproto.h>
-@@ -123,6 +125,30 @@ extern void DtloginCloseDown(void);
+@@ -123,6 +125,36 @@ extern void DtloginCloseDown(void);
  
  extern void Dispatch(void);
  
 +#if defined(sun) 
 +extern const char * GetAuthFilename(void);
++static char sym_authfile[40];
 +
 +#define LOCK_PREFIX	"/var/xauth/"
 +
@@ -28,7 +29,6 @@
 +SetupXauthFile(char *filename)
 +{
 +        struct stat buf;
-+        char sym_authfile[40];
 +
 +        snprintf(sym_authfile, 40, LOCK_PREFIX "%s", display);
 +
@@ -37,12 +37,18 @@
 +        remove(sym_authfile);
 +        symlink(filename, sym_authfile);
 +}
++
++void
++RemoveXauthSymFile(void)
++{
++        remove(sym_authfile);
++}
 +#endif
 +
  #ifdef XQUARTZ
  #include <pthread.h>
  
-@@ -141,6 +167,9 @@ main(int argc, char *argv[], char *envp[])
+@@ -137,6 +169,9 @@ dix_main(int argc, char *argv[], char *envp[])
  {
      int i;
      HWEventQueueType alwaysCheckForInput[2];
@@ -52,7 +58,7 @@
  
      display = "0";
  
-@@ -154,6 +183,12 @@ main(int argc, char *argv[], char *envp[])
+@@ -150,6 +185,12 @@ dix_main(int argc, char *argv[], char *envp[])
  
      ProcessCommandLine(argc, argv);
  
@@ -66,10 +72,10 @@
      alwaysCheckForInput[1] = 1;
      while (1) {
 diff --git a/hw/xfree86/os-support/solaris/sun_init.c b/hw/xfree86/os-support/solaris/sun_init.c
-index 4b75a98..3113186 100644
+index 15e5645..7c5dc25 100644
 --- a/hw/xfree86/os-support/solaris/sun_init.c
 +++ b/hw/xfree86/os-support/solaris/sun_init.c
-@@ -45,6 +45,9 @@
+@@ -46,6 +46,9 @@
  #define	CONSOLE_VTNO	1
  #define	SOL_CONSOLE_DEV	"/dev/console"
  
@@ -77,9 +83,9 @@
 +extern int xf86ConsoleFd;
 +
  static Bool KeepTty = FALSE;
- static Bool Protect0 = FALSE;
  static Bool UseConsole = FALSE;
-@@ -240,6 +243,8 @@ xf86OpenConsole(void)
+ 
+@@ -232,6 +235,8 @@ xf86OpenConsole(void)
  
              if (ioctl(xf86Info.consoleFd, VT_SETDISPINFO, atoi(display)) < 0)
                  xf86Msg(X_WARNING, "xf86OpenConsole: VT_SETDISPINFO failed\n");
@@ -88,3 +94,28 @@
          }
  #endif
  
+diff --git a/os/log.c b/os/log.c
+index 3db5c53..258c09f 100644
+--- a/os/log.c
++++ b/os/log.c
+@@ -107,6 +107,10 @@ OR PERFORMANCE OF THIS SOFTWARE.
+ void (*OsVendorVErrorFProc) (const char *, va_list args) = NULL;
+ #endif
+ 
++#ifdef sun
++extern void RemoveXauthSymFile(void);
++#endif
++
+ static FILE *logFile = NULL;
+ static int logFileFd = -1;
+ static Bool logFlush = FALSE;
+@@ -937,6 +941,9 @@ FatalError(const char *f, ...)
+     VErrorFSigSafe(f, args);
+     va_end(args);
+     ErrorFSigSafe("\n");
++#ifdef sun
++    RemoveXauthSymFile();
++#endif
+     if (!beenhere)
+         OsVendorFatalError(f, args2);
+     va_end(args2);
--- a/open-src/xserver/xserver-common/Xserver	Wed Feb 03 12:04:10 2016 -0800
+++ b/open-src/xserver/xserver-common/Xserver	Thu Feb 11 13:32:25 2016 -0800
@@ -1,7 +1,7 @@
 #!/bin/ksh93
 #
 #
-# Copyright (c) 2004, 2015, Oracle and/or its affiliates. All rights reserved.
+# Copyright (c) 2004, 2016, 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"),
@@ -119,6 +119,35 @@
 getprop options/tcp_listen TCP_LISTEN
 getprop options/display_0_on_console CONSOLE
 getprop options/config_file CONFIG_FILE
+getprop options/vncplatform VNCPLATFORM
+
+hwname=$(prtconf -b | nawk -F':[ \t]*' '/^banner-name:/ {print $2}')
+# Get the platform name that uses Xvnc instead of Xorg and clean it up. 
+VNCPLATFORM=$(echo ${VNCPLATFORM}| tr -d '\\')
+
+# Check if this is a platform that should use Xvnc or Xorg.
+if [[ "${XSERVER}" == "/usr/bin/Xorg" ]] ; then
+    # Configure x11-server to run Xvnc instead of Xorg for ${VNCPLATFORM}
+    if [[ ("${hwname}" != "") && ("${hwname}" == "${VNCPLATFORM}") ]] ; then
+        XSERVER="/usr/bin/Xvnc"
+        SERVERARGS="-SecurityTypes=TLSNone -DisconnectClients=false -NeverShared -IdleTimeout=3600 -interface 169.254.182.77 -screenlock"
+        svccfg -s application/x11/x11-server setprop \
+             options/server = astring: "${XSERVER}"
+        # Need single quotes due to some shells having issue with spaces.
+        svccfg -s application/x11/x11-server setprop \
+             options/server_args = astring: '"-SecurityTypes=TLSNone -DisconnectClients=false -NeverShared -IdleTimeout=3600 -interface 169.254.182.77 -screenlock"'
+    fi
+else
+    # This check is needed in case the system is booted from a cloned archive.
+    if [[ ("${hwname}" == "") || ("${hwname}" != "${VNCPLATFORM}") ]] ; then
+        XSERVER="/usr/bin/Xorg"
+        SERVERARGS=""
+        svccfg -s application/x11/x11-server setprop \
+             options/server = astring: "${XSERVER}"
+        svccfg -s application/x11/x11-server setprop \
+             options/server_args = astring: '""'
+    fi 
+fi
 
 ORIGINAL_XSERVER="${XSERVER}"
 
@@ -224,5 +253,10 @@
 fi
 
 ALLARGS="${DEPTHARG} ${LISTENARG} ${SERVERARGS} ${CONSOLE} ${CONFIGARG} $*"
+# Remove unneeded arguments for Xvnc.
+if [[ "${XSERVER}" == "/usr/bin/Xvnc" ]] ; then
+    ALLARGSVNC=$(echo ${ALLARGS}| sed 's/-novtswitch//'| tr -d '\\')
+    ALLARGS=${ALLARGSVNC}
+fi
 
 exec ${XSERVER} :${DISPLAY} ${ALLARGS}
--- a/open-src/xserver/xserver-common/x11-server.xml	Wed Feb 03 12:04:10 2016 -0800
+++ b/open-src/xserver/xserver-common/x11-server.xml	Thu Feb 11 13:32:25 2016 -0800
@@ -2,7 +2,7 @@
 <!DOCTYPE service_bundle SYSTEM "/usr/share/lib/xml/dtd/service_bundle.dtd.1">
 <!--
 
-Copyright (c) 2004, 2010, Oracle and/or its affiliates. All rights reserved.
+Copyright (c) 2004, 2016, 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"),
@@ -91,6 +91,8 @@
                	<propval name='display_0_on_console' type='boolean' 
 		 value='false' />
                	<propval name='config_file' type='astring' value='' />
+		<propval name='vncplatform' type='astring'
+		 value='SPARC SN-2' />
 	</property_group> 	
 
 	<stability value='Evolving' />
--- a/open-src/xserver/xvnc/Makefile	Wed Feb 03 12:04:10 2016 -0800
+++ b/open-src/xserver/xvnc/Makefile	Thu Feb 11 13:32:25 2016 -0800
@@ -87,6 +87,7 @@
 SOURCE_PATCHES += vnc-Makefile.patch,-p1
 SOURCE_PATCHES += gnutls-3.patch,-p1
 SOURCE_PATCHES += gnutls-drop-ecdh.patch,-p1
+SOURCE_PATCHES += screenlock.patch,-p1
 
 # Need to regenerate autoconf/automake files after patching
 AUTORECONF=yes
@@ -267,6 +268,8 @@
 		$(PROTODIR)/usr/share/man/man1/x0vncserver.1
 	$(INSTALL_SCRIPT) -m 0444 xvnc-inetd.xml \
 		$(PROTODIR)$(SMF_MANIFEST_DIR)/application/x11/
+	$(INSTALL_SCRIPT) -m 0555 vnclock.sh \
+		$(PROTODIR)/usr/lib/vnclock
 
 # Java VNCviewer applet for connecting from a web browser
 JAVA_INSTALL_DIR = $(PROTODIR)/usr/share/vnc/classes
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/open-src/xserver/xvnc/screenlock.patch	Thu Feb 11 13:32:25 2016 -0800
@@ -0,0 +1,151 @@
+diff --git a/common/rfb/VNCServerST.h b/common/rfb/VNCServerST.h
+index aa9ade0..cc4f9a8 100644
+--- a/common/rfb/VNCServerST.h
++++ b/common/rfb/VNCServerST.h
+@@ -189,6 +189,9 @@ namespace rfb {
+     bool getDisable() { return disableclients;};
+     void setDisable(bool disable) { disableclients = disable;};
+ 
++    // - Check how many of the clients are authenticated.
++    int authClientCount();
++
+   protected:
+ 
+     friend class VNCSConnectionST;
+@@ -219,9 +222,6 @@ namespace rfb {
+     ManagedPixelBuffer renderedCursor;
+     bool renderedCursorInvalid;
+ 
+-    // - Check how many of the clients are authenticated.
+-    int authClientCount();
+-
+     bool needRenderedCursor();
+     void checkUpdate();
+ 
+diff --git a/unix/xserver/dix/main.c b/unix/xserver/dix/main.c
+index 68d5263..34ed329 100644
+--- a/unix/xserver/dix/main.c
++++ b/unix/xserver/dix/main.c
+@@ -118,6 +118,10 @@ Equipment Corporation.
+ #include "dpmsproc.h"
+ #endif
+ 
++#ifdef sun
++#include <priv.h>
++#endif
++
+ #ifdef SUNSOFT
+ extern void DtloginInit(void);
+ extern void DtloginCloseDown(void);
+@@ -153,6 +157,38 @@ RemoveXauthSymFile(void)
+ {
+         remove(sym_authfile);
+ }
++
++void
++SetPrivileges(void)
++{   
++        priv_set_t *pPrivSet;  
++
++        if ((pPrivSet = priv_allocset()) == NULL) {
++                return;
++        }
++
++        /*
++         * Establish the basic set of privileges.
++         */
++        priv_basicset(pPrivSet);
++
++        /* Add needed privileges. */
++        (void) priv_addset(pPrivSet, PRIV_PROC_AUDIT);
++	(void) priv_addset(pPrivSet, PRIV_FILE_DAC_READ);
++	(void) priv_addset(pPrivSet, PRIV_FILE_DAC_WRITE);
++
++	/* Set the permitted privilege set. */
++	if (setppriv(PRIV_SET, PRIV_PERMITTED, pPrivSet) !=0) {
++		ErrorF("Could not setppriv() PRIV_PERMITTED");
++	}
++
++	/* Set the limit privilege set. */
++	if (setppriv(PRIV_SET, PRIV_LIMIT, pPrivSet) !=0) {
++		ErrorF("Could not setppriv() PRIV_LIMT");
++	}
++
++	priv_freeset(pPrivSet);
++}
+ #endif
+ 
+ #ifdef XQUARTZ
+@@ -186,6 +222,7 @@ dix_main(int argc, char *argv[], char *envp[])
+     ProcessCommandLine(argc, argv);
+ 
+ #if defined(sun)
++    SetPrivileges();
+     xauthfile = GetAuthFilename();
+     if (xauthfile)
+         SetupXauthFile(xauthfile);
+diff --git a/unix/xserver/hw/vnc/XserverDesktop.cc b/unix/xserver/hw/vnc/XserverDesktop.cc
+index 742e517..b89f87d 100644
+--- a/unix/xserver/hw/vnc/XserverDesktop.cc
++++ b/unix/xserver/hw/vnc/XserverDesktop.cc
+@@ -49,6 +49,7 @@ extern "C" {
+ #define class c_class
+ 
+ extern const char *display;
++extern bool screenlock;
+ 
+ #include "colormapst.h"
+ #ifdef RANDR
+@@ -509,11 +510,28 @@ void XserverDesktop::blockHandler(fd_set* fds)
+     std::list<Socket*>::iterator i;
+     for (i = sockets.begin(); i != sockets.end(); i++) {
+       int fd = (*i)->getFd();
++      int status;
++      pid_t pid;
+       if ((*i)->isShutdown()) {
+         vlog.debug("client gone, sock %d",fd);
+         server->removeSocket(*i);
+         vncClientGone(fd);
+         delete (*i);
++	/*
++	 * If the screenlock option is chosen, lock the screen when the client
++	 * disconnects.
++	 */
++        if (screenlock && (server->authClientCount() == 0)) {
++          if ((pid = fork()) < 0) {
++            vlog.error("Could not fork");
++          } else if (pid == 0) {
++            if (execlp("/usr/lib/vnclock", "vnclock",
++	      display, NULL) < 0) {
++              vlog.error("Could not exec vnclock");
++            }
++            exit(0);
++          } 
++        } 
+       } else {
+         FD_SET(fd, fds);
+       }
+diff --git a/unix/xserver/hw/vnc/xvnc.cc b/unix/xserver/hw/vnc/xvnc.cc
+index 55fe9b5..2af6f81 100644
+--- a/unix/xserver/hw/vnc/xvnc.cc
++++ b/unix/xserver/hw/vnc/xvnc.cc
+@@ -167,6 +167,7 @@ static bool displaySpecified = false;
+ static char displayNumStr[16];
+ 
+ char *listenaddr = NULL;
++bool screenlock = false;
+ 
+ 
+ static void
+@@ -581,6 +582,11 @@ ddxProcessArgument(int argc, char *argv[], int i)
+ 	return 2;
+     }
+ 
++    if (strcmp(argv[i], "-screenlock") == 0) {
++        screenlock = true;
++        return 1;
++    }
++
+     if (strcmp(argv[i], "-noclipboard") == 0) {
+ 	noclipboard = true;
+ 	return 1;
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/open-src/xserver/xvnc/vnclock.sh	Thu Feb 11 13:32:25 2016 -0800
@@ -0,0 +1,8 @@
+#!/usr/sbin/sh
+#
+# Copyright (c) 2016, Oracle and/or its affiliates. All rights reserved.
+#
+
+XAUTHORITY=/var/xauth/$1
+export XAUTHORITY
+xscreensaver-command -display :$1 -lock
--- a/pkg/manifests/x11-server-xvnc.p5m	Wed Feb 03 12:04:10 2016 -0800
+++ b/pkg/manifests/x11-server-xvnc.p5m	Thu Feb 11 13:32:25 2016 -0800
@@ -1,4 +1,4 @@
-# Copyright (c) 2010, 2012, Oracle and/or its affiliates. All rights reserved.
+# Copyright (c) 2010, 2016, 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"),
@@ -24,6 +24,7 @@
 set name=pkg.description \
     value="X Window System server based on X.Org Foundation open source release and TigerVNC open source release that displays over RFB protocol to a VNC client"
 file path=lib/svc/manifest/application/x11/xvnc-inetd.xml
+file path=usr/lib/vnclock mode=0555
 link path=usr/X11/bin/Xvnc target=../../bin/Xvnc
 $(i386_ONLY)link path=usr/bin/$(ARCH64)/Xvnc target=../Xvnc
 file path=usr/bin/Xvnc group=root mode=2555
@@ -65,3 +66,6 @@
 # vncserver script requires xauth & xrdb programs
 depend type=require fmri=pkg:/x11/session/xauth
 depend type=require fmri=pkg:/x11/x11-server-utilities
+
+# Xvnc depends on xscreensaver
+depend type=require fmri=pkg:/desktop/xscreensaver