setup DISPLAY variable during login

setup DISPLAY variable during login

Post by Michael Salm » Fri, 16 Sep 1994 17:14:50




|> I would like to setup the DISPLAY variable automatically as follows when
|> a user login:
|>
|>   DISPLAY = from_ip_address:0
|> or
|>   DISPLAY = 'name of from_ip_address in /etc/hosts':0
|>
|> Is this possible?  How can I get the user's from_ip_address during the login
|> process?

It is possible though there are problems, when you rlogin the first 16
characters of your hostname are stored and you can see that with e.g.
who. The perl script does its best to get the entire name from those 16
characters, N.B. I didn't write it, please direct queries to the author

#!/bin/perl

# Find the name of the host from which a user is logged in.
# This is necessary because utmp entries truncate the host name,
# often losing necessary information.
#
# USAGE: setenv DISPLAY `displayhost`:0
#

#
# Inspired by a shell script of the same name written by

$aix = 1 if -e '/usr/lib/boot/unix';
$utmpsize = $aix ? 64 : 36;

#require 'sys/socket.ph';
$AF_INET = 2;

# Use `tty` to get the name of the tty device.  Look around in
# utmp file to find entry with a matching device.  The first
# 16 characters of the remote host name is in utmp.

$ttyname = (`tty`)[0];
$host = "";
open (UTMP, "/etc/utmp") || die "Can't open /etc/utmp\n";
while (read(UTMP, $utmp_rec, $utmpsize)) {
  if ($aix) {
    ($userid,$id,$tty,$type,$pid,$term,$exit,$time,$ut_host) =
      unpack("A8 A14 A12 s I s s L A16", $utmp_rec);
  } else {
    ($tty,$userid,$ut_host,$time) = unpack("A8 A8 A16 L", $utmp_rec);
  }
  $host = $ut_host if $tty && ($ttyname =~ /$tty/);
  last if $host;

Quote:}

close(UTMP);

# If there's no valid host, then we are logged in locally.  This is easy.

if ($host eq "" || $host eq ":0.0") {
   print `hostname`;   # Already contains \n
   exit;  }

else {

# This is a remote login.
# Use netstat -n to get the host address associated with each
# established net connection.  Find the full hostname associated
# with each one.  Take the first one which contains our partial
# hostname.

   foreach (`netstat -n`) {
     if (/ESTABLISHED/) {
       $adrs = pack("C4", split(/\./, (split)[4]));  # Convert addrs to word
       $fullname = (gethostbyaddr($adrs, $AF_INET))[0];
       if ($fullname =~ $host) {  # See if it matches partial host
         print $fullname,"\n";
         exit;
         }
      }
   }
   exit -1;

Quote:}

--

Michael Salmon

#include        <standard.disclaimer>
#include        <witty.saying>
#include        <fancy.pseudo.graphics>

Ericsson Telecom AB
Stockholm

 
 
 

setup DISPLAY variable during login

Post by Mario Klebsch DG1 » Sat, 17 Sep 1994 01:42:29


Hello!


>I would like to setup the DISPLAY variable automatically as follows when
>a user login:
>    DISPLAY = from_ip_address:0
>or
>    DISPLAY = 'name of from_ip_address in /etc/hosts':0
>Is this possible?  How can I get the user's from_ip_address during the login
>process?

Of cource, this is possible, but this will not lead to DISPLAY set
correctly. Whan a user on machineA does rlogin machineB and then
rlogin machineC, on machineC DISPLAY will be set to machineB:0. This
is wrong!. The only way I know, is to pass DISPLAY on top of TERM
trough rlogin. The machine, where you type rlogin, has to take its
current DISPLAY, change it, if it is unix:*, and append it to TERM. On
the machine, where you log in, you have to split TERM into the
original TERM and DISPLAY.

There are several scripts to do this, if anybody wants mine, I can
mail them.

        Mario
--

Institut fuer Robotik und Prozessinformatik der TU Braunschweig
Hamburger Strasse 267, 38114 Braunschweig, Germany

 
 
 

setup DISPLAY variable during login

Post by Stephen Kw » Fri, 16 Sep 1994 12:48:49


I would like to setup the DISPLAY variable automatically as follows when
a user login:

        DISPLAY = from_ip_address:0
or
        DISPLAY = 'name of from_ip_address in /etc/hosts':0

Is this possible?  How can I get the user's from_ip_address during the login
process?

Thanks for any help in advance.

Stephen.

--
+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+




+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+

 
 
 

setup DISPLAY variable during login

Post by Anthony Thyss » Sat, 01 Oct 1994 11:08:29




|
| >I would like to setup the DISPLAY variable automatically as follows when
| >a user login:
|
| >  DISPLAY = from_ip_address:0
| >or
| >  DISPLAY = 'name of from_ip_address in /etc/hosts':0
|
| >Is this possible?  How can I get the user's from_ip_address during the login
| >process?
|
| Of cource, this is possible, but this will not lead to DISPLAY set
| correctly. Whan a user on machineA does rlogin machineB and then
| rlogin machineC, on machineC DISPLAY will be set to machineB:0. This
| is wrong!. The only way I know, is to pass DISPLAY on top of TERM
| trough rlogin. The machine, where you type rlogin, has to take its
| current DISPLAY, change it, if it is unix:*, and append it to TERM. On
| the machine, where you log in, you have to split TERM into the
| original TERM and DISPLAY.
|
| There are several scripts to do this, if anybody wants mine, I can
| mail them.
|
|       Mario

The following is an extract from my hint 'n' tips area for X windows
     http://www.cit.gu.edu.au/~anthony/info/X/

--------------8<-----------CUT HERE--------------8<---------------
Automatically pass X Authorization & Display from one machine to another.

All the methods I have seen to do this fall into one of the following
general techniques.

1/ Use rsh/rexec/on...  (this is also the method in the xauth manual)
      Set up the your .rhosts file in the home directory on the remote
  machine so that a password in not required to remotly execute commands.

         xauth extract - $DISPLAY | rsh other xauth merge -

     Basically this method passes the authorization (and maybe other info)
  via a stdout/stdin command pipeline, which is completely invisiable
  to everyone. Except network monitors, which can see everything anyway.

     Included in this method is the use of `xrlogin' and `xrsh' to do
  this job for you. These programs usally (the newer ones that is) allow
  you to pass a secified list of ENVIRONMENT variables which includes
  the `DISPLAY' and/or a copy of the authorization code as required.

     The `on' program available (if enabled) on sun machines will also
  pass environment variables, as well as the current directory.  You will
  however be required to store the Authority in such a variable for
  passing. Unless you are also have shared home directories.

    WARNING: Environment variables and command line arguments are visible
  in `ps' listing with the appropiate flags. As such passing authorization
  information in environment variables or as arguments is not recomended.
  The recommended method as given in the manual (shown above) is safe from
  the view of other users.

2/ Wrap it as part of the TERM environment variable.
      This method uses the fact that most remote command executors do pass
  the TERM environment variable to the remote host. It is then a matter of
  an appropiate script in your remote .login file to extract the information
  from the TERM environment variable and set up things appropiatly.
    A version of the xrlogin script is available on the network which does
  this. Basically you change the TERM environment variable before the
  actual call to rlogin is performed, to include your DISPLAY and your
  authorization.
    On the remote machine you then extract this information and return the
  TERM environment variable to normal BEFORE you use it for reseting or
  stty'ing your terminal.

  script for launching rlogin:
    #!/bin/sh
    # ~/bin/rl   --- Rlogin with display:
    if [ -n "$DISPLAY" ]; then
      case "$DISPLAY" in
        :*) DISPLAY=`hostname`$DISPLAY ;;
      esac
      TERM="$TERM&$DISPLAY&`xauth nextract - $DISPLAY`"
      export TERM
    fi
    rlogin $*
  ---8<---
  add to your .cshrc or .login
    if ( $?TERM ) then
      if ( `echo $TERM | tr -cd '&'` != '' ) then
        echo "$TERM" | cut '-d&' -f3 | xauth nmerge -
        setenv DISPLAY `echo "$TERM" | cut '-d&' -f2`
        setenv TERM    `echo "$TERM" | cut '-d&' -f1`
      endif
    endif
  ---8<---
  xterm command to use
    xterm -T hostname -e ~/bin/rl hostname
  ---8<---

  UPDATE NOTE: On some systems a `ps' command option will allow any user
  to view the environment of a command. On these systems it may be posible
  to look at the TERM environment variable on the rlogind program that
  forked the users shell. This is on a problem with the actual shell as
  the variable is `corrected' after the user logged in. Even so it would
  also be visible with the users process if the `ps' is performed before
  the user is fully logged in.
3/ NFS.
     Write it to a file on a shared NFS partition you have access to.
   Note that if the home directories are NFS mounted, then authorization
   is automatically passed, Hoever you will still have to pass your
   DISPLAY environment variable via a file or other means. IE:

      login host:       echo $DISPLAY > ~/.X11host
      remote host:      setenv DISPLAY `cat ~/.X11host`

4/ Finger for the info in a .plan file
      This involves encrypting the information into your `.plan' or
  `.project' and having the remote machine finger for the information.
  This has the disadvantage of having the information to anyone fingering
  the user.  Thus requiring a encryption method that is uniq to each
  individual.  IE: the method of decyrption must not be shared or known
  by others, nor should it be easy to determine.
    A improvement is to use the `who fingered me' technique to only give
  the information only to your own remote accounts and not just to anyone
  who is asking.
    This last method was developed last year by a second year here, untill
  I explained to him the need for the encryption, at which point he gave
  up this method. It is however a valid method. It is easer than (2) but
  less secure.

--------------8<-----------CUT HERE--------------8<---------------

If anyone else comes up with a method that does not fit in any of the
above. mail me.

  Anthony Thyssen ( System Programmer )    http://www.cit.gu.edu.au/~anthony/
-------------------------------------------------------------------------------
              There are no bugs, only unrecognized features.
-------------------------------------------------------------------------------

 
 
 

1. How may I override the LC_MESSAGES variable during login (JDS)

Hello..

How do I override just the LC_MESSAGES variable when I log into my
Solaris box? Unfortunately "someone" has added Norwegian language
support to the JDS, but I can't stand localized menues. I do however
like dates, numbers etc to be presented in the norwegian locale.

BTW. I would like to avoid removing the actual language files, since I'm
not the only one using the machines..

Trond

2. 2.4.18 hangs on boot: "sim 710: No NCR53710 adapter found"

3. All Ports Not Displayed During Setup

4. What Library has SmcInteractDone??????????????

5. ADSL setup ... and DISPLAY variable

6. How to start FTP service on Soalris2.5 ?

7. How to setup Display variable?

8. Fedora 5 - Intel Pro/Wireless LAN 2100 3B Mini PCI adapter woes.

9. DISPLAY variable automatic set-up

10. TZ & HZ setup during login

11. variable DISPLAY variable

12. netcfg: TclError: no display name and no $display environment variable

13. no display name and no $DISPLAY environment variable