Hi -

I've patched the 3.3.3r2 UNIX Xvnc server to link against the ORBit
CORBA library and export a CORBA management interface.  Here's the IDL:

interface VNC {
  void enableClientKeyboard(in string ipaddr);
  void disableClientKeyboard(in string ipaddr);
  void enableClientPointer(in string ipaddr);
  void disableClientPointer(in string ipaddr);
  void disconnectClient(in string ipaddr);
  void disconnectAllClients();
};

As you can see, it permits client keyboards and pointers to be
individually enabled or disabled by IP address.  I've also added a
server option "-foreignersdisabled" to start foreign (non-localhost)
clients with keyboard and pointer disabled.  I use this in a class I
teach to have the students start all their VNCs disabled.  Then I
connect from localhost as the one enabled client and use a Perl script
to turn their keyboards on and off.  I've attached both the patch and a
simple Perl script to manipulate the CORBA interface.

I guess what I'd like to see next (I don't know if I'll do this myself)
is to have two different passwords, one to attached enabled, one to
attach disabled; the second one possibly NULL.  This should probably
done with a real config file for the server.

Comments?

-- 
                                        -bwb

                                        Brent Baccala
                                        [EMAIL PROTECTED]

==============================================================================
       For news from freesoft.org, subscribe to [EMAIL PROTECTED]:
   
mailto:[EMAIL PROTECTED]?subject=subscribe&body=subscribe
==============================================================================
#!/usr/bin/perl -w
#
# Simple Perl script to send commands to a CORBA-enabled VNC server
#
# May 2001, by Brent Baccala <[EMAIL PROTECTED]>
#
# Uses Owen Taylor's CORBA::ORBit module (available from CPAN)
#
# The script will use its own name as the function to invoke on the server,
# either {enable/disable}Client{Keyboard/Pointer} or disconnectClient
#
# Looks for the CORBA address (IOR) of the VNC server in a file called
# /tmp/.X{0,1}.vnc - that's where the VNC server writes it.  Also looks
# for the vnc IDL file in the current directory.
#

use strict;

use CORBA::ORBit idl => [ qw(vnc.idl) ];


my $progname = $0;
$progname =~ s!.*/!!;

$#ARGV == 0 or die "Usage: $progname IPADDR\n";

my $orb = CORBA::ORB_init("orbit-local-orb");

open IOR, "/tmp/.X0.ior"
    or open IOR, "/tmp/.X1.ior"
    or die "Couldn't open IOR file\n";
my $ior = <IOR>;
close IOR;

my $vnc = $orb->string_to_object($ior);

$vnc->$progname($ARGV[0]);
//
// CORBA interface for VNC
//

interface VNC {
  void enableClientKeyboard(in string ipaddr);
  void disableClientKeyboard(in string ipaddr);
  void enableClientPointer(in string ipaddr);
  void disableClientPointer(in string ipaddr);
  void disconnectClient(in string ipaddr);
  void disconnectAllClients();
};
diff -cr vnc_unixsrc/Xvnc/config/cf/vnc.def vnc_unixsrc.new/Xvnc/config/cf/vnc.def
*** vnc_unixsrc/Xvnc/config/cf/vnc.def  Thu Oct 26 07:31:46 2000
--- vnc_unixsrc.new/Xvnc/config/cf/vnc.def      Fri May  4 01:02:43 2001
***************
*** 103,108 ****
--- 103,110 ----
  #define BuildServersOnly      YES
  #define BuildServer           YES
  
+ #define UseORBIT              YES
+ 
  #define XVendorString         "AT&T Laboratories Cambridge"
  #define XVendorRelease                3332
  #define XvncRelease           "3r2"
diff -cr vnc_unixsrc/Xvnc/config/cf/vnclibs.def 
vnc_unixsrc.new/Xvnc/config/cf/vnclibs.def
*** vnc_unixsrc/Xvnc/config/cf/vnclibs.def      Tue May 19 11:41:58 1998
--- vnc_unixsrc.new/Xvnc/config/cf/vnclibs.def  Fri May  4 01:05:34 2001
***************
*** 7,9 ****
--- 7,14 ----
  
  VNCLIBS = $(TOP)/../libvncauth/libvncauth.a
  VNCCPPFLAGS = -I$(TOP)/../include
+ 
+ #ifdef UseORBIT
+ VNCLIBS += -lORBit -lIIOP -lORBitutil -lglib -lnsl -lm
+ VNCCPPFLAGS += -I/usr/lib/glib/include -DUseORBIT
+ #endif
diff -cr vnc_unixsrc/Xvnc/programs/Xserver/hw/vnc/Imakefile 
vnc_unixsrc.new/Xvnc/programs/Xserver/hw/vnc/Imakefile
*** vnc_unixsrc/Xvnc/programs/Xserver/hw/vnc/Imakefile  Thu Mar  9 10:43:36 2000
--- vnc_unixsrc.new/Xvnc/programs/Xserver/hw/vnc/Imakefile      Fri May  4 21:11:30 
2001
***************
*** 14,19 ****
--- 14,24 ----
           -I../../cfb -I../../mfb -I../../mi -I../../include -I../../os \
           $(VNCCPPFLAGS)
  
+ #ifdef UseORBIT
+ SRCS += vnc.idl
+ OBJS += vnc-common.o vnc-skels.o
+ #endif
+ 
  DEFINES = ServerOSDefines
  
  all:: $(OBJS)
***************
*** 21,25 ****
--- 26,52 ----
  NormalLibraryObjectRule()
  NormalLibraryTarget(vnc,$(OBJS))
  SpecialCObjectRule(init,$(ICONFIGFILES),-DXVNCRELEASE=\"XvncRelease\")
+ 
+ #ifdef UseORBIT
+ 
+ # rules for ORBit IDL files
+ 
+ ORBIT_IDL = /usr/bin/orbit-idl
+ 
+ vnc-stubs.c : vnc.idl
+       $(ORBIT_IDL) vnc.idl
+ 
+ vnc-common.c : vnc.idl
+       $(ORBIT_IDL) vnc.idl
+ 
+ vnc-skels.c : vnc.idl
+       $(ORBIT_IDL) vnc.idl
+ 
+ vnc.h : vnc.idl
+       $(ORBIT_IDL) vnc.idl
+ 
+ init.o : vnc.h
+ 
+ #endif
  
  DependTarget()
diff -cr vnc_unixsrc/Xvnc/programs/Xserver/hw/vnc/init.c 
vnc_unixsrc.new/Xvnc/programs/Xserver/hw/vnc/init.c
*** vnc_unixsrc/Xvnc/programs/Xserver/hw/vnc/init.c     Wed Oct 25 15:12:30 2000
--- vnc_unixsrc.new/Xvnc/programs/Xserver/hw/vnc/init.c Sun May  6 03:05:04 2001
***************
*** 84,89 ****
--- 84,94 ----
  #include <vncserverctrl.h>
  #endif
  
+ #ifdef UseORBIT
+ #include "orb/orbit.h"
+ #include "vnc.h"
+ #endif
+ 
  #define RFB_DEFAULT_WIDTH  640
  #define RFB_DEFAULT_HEIGHT 480
  #define RFB_DEFAULT_DEPTH  8
***************
*** 133,138 ****
--- 138,330 ----
  static char inetdDisplayNumStr[10];
  
  
+ #ifdef UseORBIT
+ 
+ CORBA_Environment ev;
+ CORBA_ORB orb;
+ 
+ /* This is so we can get out a valid IOR later... */
+ VNC vnc_client = CORBA_OBJECT_NIL;
+ 
+ static void
+ do_enableClientKeyboard(PortableServer_Servant servant,
+                       CORBA_char *ipaddr,
+                       CORBA_Environment *ev)
+ {
+   rfbClientPtr cl;
+ 
+   rfbLog("enableClientKeyboard %s\n", ipaddr);
+ 
+   for (cl = rfbClientHead; cl; cl = cl->next) {
+     if (!strcmp(ipaddr,cl->host)) {
+       cl->keyboardEnabled = TRUE;
+     }
+   }
+ }
+ 
+ static void
+ do_disableClientKeyboard(PortableServer_Servant servant,
+                        CORBA_char *ipaddr,
+                        CORBA_Environment *ev)
+ {
+   rfbClientPtr cl;
+ 
+   rfbLog("disableClientKeyboard %s\n", ipaddr);
+ 
+   for (cl = rfbClientHead; cl; cl = cl->next) {
+     if (!strcmp(ipaddr,cl->host)) {
+       cl->keyboardEnabled = FALSE;
+     }
+   }
+ }
+ 
+ static void
+ do_enableClientPointer(PortableServer_Servant servant,
+                       CORBA_char *ipaddr,
+                       CORBA_Environment *ev)
+ {
+   rfbClientPtr cl;
+ 
+   rfbLog("enableClientPointer %s\n", ipaddr);
+ 
+   for (cl = rfbClientHead; cl; cl = cl->next) {
+     if (!strcmp(ipaddr,cl->host)) {
+       cl->pointerEnabled = TRUE;
+     }
+   }
+ }
+ 
+ static void
+ do_disableClientPointer(PortableServer_Servant servant,
+                        CORBA_char *ipaddr,
+                        CORBA_Environment *ev)
+ {
+   rfbClientPtr cl;
+ 
+   rfbLog("disableClientPointer %s\n", ipaddr);
+ 
+   for (cl = rfbClientHead; cl; cl = cl->next) {
+     if (!strcmp(ipaddr,cl->host)) {
+       cl->pointerEnabled = FALSE;
+     }
+   }
+ }
+ 
+ static void
+ do_disconnectClient(PortableServer_Servant servant,
+                   CORBA_char *ipaddr,
+                   CORBA_Environment *ev)
+ {
+   rfbClientPtr cl, next;;
+ 
+   rfbLog("disconnectClient %s\n", ipaddr);
+ 
+   for (cl = rfbClientHead; cl; cl = next) {
+     next = cl->next;
+     if (!strcmp(ipaddr,cl->host)) {
+       rfbCloseSock(cl->sock);
+     }
+   }
+ }
+ 
+ static void
+ do_disconnectAllClients(PortableServer_Servant servant,
+                       CORBA_Environment *ev)
+ {
+   rfbClientPtr cl, next;
+ 
+   rfbLog("disconnectAllClients\n");
+ 
+   for (cl = rfbClientHead; cl; cl = next) {
+     next = cl->next;
+     rfbCloseSock(cl->sock);
+   }
+ }
+ 
+ /*
+  * I have **no** idea what this bit does
+  */
+ PortableServer_ServantBase__epv base_epv = {
+   NULL,
+   NULL,
+   NULL
+ };
+ POA_VNC__epv VNC_epv = { NULL,
+                        do_enableClientKeyboard, do_disableClientKeyboard,
+                        do_enableClientPointer, do_disableClientPointer,
+                        do_disconnectClient, do_disconnectAllClients };
+ POA_VNC__vepv poa_VNC_vepv = { &base_epv, &VNC_epv };
+ POA_VNC poa_VNC_servant = { NULL, &poa_VNC_vepv };
+ 
+ static void
+ orb_add_connection(GIOPConnection *cnx)
+ {
+   int fd = GIOP_CONNECTION_GET_FD(cnx);
+   /* rfbLog("orb_add_connection(%d)\n", fd); */
+   AddEnabledDevice(fd);
+ }
+ 
+ static void
+ orb_remove_connection(GIOPConnection *cnx)
+ {
+   int fd = GIOP_CONNECTION_GET_FD(cnx);
+   /* rfbLog("orb_remove_connection(%d)\n", fd); */
+   RemoveEnabledDevice(fd);
+ }
+ 
+ 
+ static void
+ ORBIT_init(int *argcp, char *argv[])
+ {
+   PortableServer_ObjectId objid = {0, sizeof("myVNC"), "myVNC"};
+   PortableServer_POA poa;
+ 
+ 
+   CORBA_exception_init(&ev);
+   IIOPAddConnectionHandler = orb_add_connection;
+   IIOPRemoveConnectionHandler = orb_remove_connection;
+   orb = CORBA_ORB_init(argcp, argv, "orbit-local-orb", &ev);
+ 
+   POA_VNC__init(&poa_VNC_servant, &ev);
+ 
+   poa = (PortableServer_POA)CORBA_ORB_resolve_initial_references(orb, "RootPOA", 
+&ev);
+   PortableServer_POAManager_activate(PortableServer_POA__get_the_POAManager(poa, 
+&ev), &ev);
+   PortableServer_POA_activate_object_with_id(poa,
+                                            &objid, &poa_VNC_servant, &ev);
+ 
+   vnc_client = PortableServer_POA_servant_to_reference(poa,
+                                                      &poa_VNC_servant,
+                                                      &ev);
+   if (vnc_client) {
+     char * retval;
+     FILE * ofp;
+     char filename[32];
+ 
+     retval = CORBA_ORB_object_to_string(orb, vnc_client, &ev);
+ 
+     snprintf(filename, sizeof(filename), "/tmp/.X%s.ior", display);
+     ofp = fopen(filename, "w");
+ 
+     fprintf(ofp,"%s", retval);
+     fclose(ofp);
+ 
+     CORBA_free(retval);
+   }
+ 
+   ORBit_custom_run_setup(orb, &ev);
+ 
+ }
+ 
+ static void ORBIT_shutdown()
+ {
+     char filename[32];
+ 
+     snprintf(filename, sizeof(filename), "/tmp/.X%s.ior", display);
+     unlink(filename);
+ }
+ 
+ #endif
+ 
  /*
   * ddxProcessArgument is our first entry point and will be called at the
   * very start for each argument.  It is not called again on server reset.
***************
*** 288,293 ****
--- 480,490 ----
        return 1;
      }
  
+     if (strcmp(argv[i], "-foreignersdisabled") == 0) {
+       rfbForeignersStartDisabled = TRUE;
+       return 1;
+     }
+ 
      if (strcmp(argv[i], "-localhost") == 0) {
        rfbLocalhostOnly = TRUE;
        return 1;
***************
*** 362,367 ****
--- 559,568 ----
      initialiseCORBA(argc, argv, desktopName);
  #endif
  
+ #ifdef UseORBIT
+     ORBIT_init(&argc, argv);
+ #endif
+ 
      /* initialize pixmap formats */
  
      screenInfo->imageByteOrder = IMAGE_BYTE_ORDER;
***************
*** 665,670 ****
--- 866,874 ----
  #ifdef CORBA
      corbaCheckFds();
  #endif
+ #ifdef UseORBIT
+     giop_main_iterate(FALSE);
+ #endif
      if (*mieqCheckForInput[0] != *mieqCheckForInput[1]) {
        mieqProcessInputEvents();
        miPointerUpdate();
***************
*** 803,808 ****
--- 1007,1015 ----
  #ifdef CORBA
        shutdownCORBA();
  #endif
+ #ifdef UseORBIT
+       ORBIT_shutdown();
+ #endif
      }
  }
  
***************
*** 856,861 ****
--- 1063,1070 ----
                                                               "new non-shared\n"
           "                       connection comes in (refuse new connection "
                                                                 "instead)\n");
+     ErrorF("-foreignersdisabled    foreign connections (not from 127.0.0.1) "
+                                                           "start disabled\n");
      ErrorF("-localhost             only allow connections from localhost\n");
      ErrorF("-inetd                 Xvnc is launched by inetd\n");
      exit(1);
diff -cr vnc_unixsrc/Xvnc/programs/Xserver/hw/vnc/rfb.h 
vnc_unixsrc.new/Xvnc/programs/Xserver/hw/vnc/rfb.h
*** vnc_unixsrc/Xvnc/programs/Xserver/hw/vnc/rfb.h      Wed Oct 25 14:08:48 2000
--- vnc_unixsrc.new/Xvnc/programs/Xserver/hw/vnc/rfb.h  Fri May  4 01:52:30 2001
***************
*** 198,203 ****
--- 198,206 ----
  
      rfbPixelFormat format;
  
+     Bool keyboardEnabled;
+     Bool pointerEnabled;
+ 
      /* statistics */
  
      int rfbBytesSent[MAX_ENCODINGS];
***************
*** 211,216 ****
--- 214,221 ----
  
  } rfbClientRec, *rfbClientPtr;
  
+ #define isKeyboardEnabled(cl) (cl->keyboardEnabled)
+ #define isPointerEnabled(cl) (cl->pointerEnabled)
  
  /*
   * This macro is used to test whether there is a framebuffer update needing to
***************
*** 377,382 ****
--- 382,388 ----
  extern Bool rfbAlwaysShared;
  extern Bool rfbNeverShared;
  extern Bool rfbDontDisconnect;
+ extern Bool rfbForeignersStartDisabled;
  
  extern void rfbNewClientConnection(int sock);
  extern rfbClientPtr rfbReverseConnection(char *host, int port);
diff -cr vnc_unixsrc/Xvnc/programs/Xserver/hw/vnc/rfbserver.c 
vnc_unixsrc.new/Xvnc/programs/Xserver/hw/vnc/rfbserver.c
*** vnc_unixsrc/Xvnc/programs/Xserver/hw/vnc/rfbserver.c        Wed Oct 25 14:06:49 
2000
--- vnc_unixsrc.new/Xvnc/programs/Xserver/hw/vnc/rfbserver.c    Fri May  4 01:52:46 
2001
***************
*** 50,55 ****
--- 50,56 ----
  Bool rfbAlwaysShared = FALSE;
  Bool rfbNeverShared = FALSE;
  Bool rfbDontDisconnect = FALSE;
+ Bool rfbForeignersStartDisabled = FALSE;
  
  static rfbClientPtr rfbNewClient(int sock);
  static void rfbProcessClientProtocolVersion(rfbClientPtr cl);
***************
*** 136,141 ****
--- 137,150 ----
      getpeername(sock, (struct sockaddr *)&addr, &addrlen);
      cl->host = strdup(inet_ntoa(addr.sin_addr));
  
+     if (rfbForeignersStartDisabled && (strcmp(cl->host, "127.0.0.1") != 0)) {
+       cl->keyboardEnabled = FALSE;
+       cl->pointerEnabled = FALSE;
+     } else {
+       cl->keyboardEnabled = TRUE;
+       cl->pointerEnabled = TRUE;
+     }
+ 
      cl->state = RFB_PROTOCOL_VERSION;
  
      cl->reverseConnection = FALSE;
***************
*** 634,643 ****
  
  #ifdef CORBA
        addCapability(cl, KEYBOARD_DEVICE);
! 
        if (!isKeyboardEnabled(cl))
            return;
! #endif
        KbdAddEvent(msg.ke.down, (KeySym)Swap32IfLE(msg.ke.key), cl);
        return;
  
--- 643,652 ----
  
  #ifdef CORBA
        addCapability(cl, KEYBOARD_DEVICE);
! #endif
        if (!isKeyboardEnabled(cl))
            return;
! 
        KbdAddEvent(msg.ke.down, (KeySym)Swap32IfLE(msg.ke.key), cl);
        return;
  
***************
*** 656,665 ****
  
  #ifdef CORBA
        addCapability(cl, POINTER_DEVICE);
! 
        if (!isPointerEnabled(cl))
            return;
! #endif
  
        if (pointerClient && (pointerClient != cl))
            return;
--- 665,674 ----
  
  #ifdef CORBA
        addCapability(cl, POINTER_DEVICE);
! #endif
        if (!isPointerEnabled(cl))
            return;
! 
  
        if (pointerClient && (pointerClient != cl))
            return;
*** vnc_unixsrc/Xvnc/programs/Xserver/hw/vnc/vnc.idl    Wed Dec 31 19:00:00 1969
--- vnc_unixsrc.new/Xvnc/programs/Xserver/hw/vnc/vnc.idl        Fri May  4 02:05:24 
2001
***************
*** 0 ****
--- 1,12 ----
+ //
+ // CORBA interface for VNC
+ //
+ 
+ interface VNC {
+   void enableClientKeyboard(in string ipaddr);
+   void disableClientKeyboard(in string ipaddr);
+   void enableClientPointer(in string ipaddr);
+   void disableClientPointer(in string ipaddr);
+   void disconnectClient(in string ipaddr);
+   void disconnectAllClients();
+ };
---------------------------------------------------------------------
To unsubscribe, send a message with the line: unsubscribe vnc-list
to [EMAIL PROTECTED]
See also: http://www.uk.research.att.com/vnc/intouch.html
---------------------------------------------------------------------

Reply via email to