Hi Jim, Everyone,

I had an earlier query regarding Derek Dresser's utmp logging solution and some 
problems i had with it using 
'who' and 'last'.

I'm sharing with you here some of my findings and modifications to Derek's scripts so 
that 'who' and 'last' 
works as it should ;-)

Jim, sorry if you receive this twice already. My mails here sometimes get clobbered.

Cheers,

Phil


+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
'Instantaneous' UTMP Logging for LTSP Workstations
(modifications from Derek Dresser's utmp scripts)

Philip A. Roa
Intelisoft Microcomputer Systems
March 7, 2002

Purpose:  To monitor currently connected LTSP thin clients on an LTSP server.
Problem:  LTSP thin clients are not correctly reported by 'who' and 'last'

Disclaimer: I cannot be responsible for anything that happens to your system. Use at 
            your own risk. If you're not comfortable doing this, then i suggest you 
have
            someone qualified do stuff. You have been warned.

The source of the problem:
=========================

Sessions are appended to the utmp / wtmp logs via file:/usr/X11R6/bin/sessreg. From 
the manual page of 
sessreg, the -l (line-name option) option determines the record name of the utmp 
entry. That is, a session 
name is looked-up (or deleted in the future) via its line-name.This creates no 
problems for terminal devices 
since the final pathname segment of the terminal device filename accessing the server 
is unique (e.g.  ttyd0).

On the other hand, for X terminal sessions, the line-name normalizes to the host's 
local display number 
(usually the default ':0').  That is if you specify your line-name option as the 
$DISPLAY, utmp only gets the ':0' - 
a non-unique name. This is where our problem begins. When multiple clients (remote 
thin clients) starts 
accessing the LTSP server, it is only the last connected host that will be reported as 
'still logged in'. The rest 
of the current record entries get 'stepped-on' and purged from utmp (we don't want 
that to happen).

The solution:
=============

To 'get-around' with this problem, we have to make 'line-name' unique. One way of 
doing this is by extracting 
the hostname component of the $DISPLAY variable (which is initially setup for us by 
LTSP). This way, all our 
connected LTSP thin clients will be correctly logged into utmp so our 'who' and 'last' 
will work as it should.

Scripts:
========

There are 3 script files used here: sessreg.h, GiveConsole, & TakeConsole (on some 
distributions you may 
have Xstartup and Xreset scripts respectively).

Don't forget to set file permissions for all the 3 scripts to 755 (i.e. chmod 755 
/etc/X11/xdm/sessreg.h...do..same..thing..to..the..rest..of..the..scripts...) when 
you're done editing.

===============================================
file:/etc/X11/xdm/sessreg.h
---------------------------
Purpose: Prepares the line-name (-l), 
         and hostname (-h) options for sessreg

$LINENAME - contains the host portion of
            $DISPLAY for our remote hosts.
            Howerver, it resolves to
            $HOSTNAME if the access is
            done on the LTSP server itself

$LTSNAME  - contains the hostname of the LTSP
            server
===============================================

# to be used by GiveConsole and TakeConsole
LINENAME=`echo $DISPLAY | awk '{print substr($1,1,length($1)-2)}'`
if [ -z $LINENAME ]
then
 LINENAME=$HOSTNAME
fi
LTSHOST="LTSP("$HOSTNAME":0)"



==========================================
file:/etc/X11/xdm/GiveConsole
-----------------------------
Purpose:  Logs the start of an X session
          The original file shown here
          comes from Mandrake 7.0 (Air)
          distribution. Modifications
          are indicated.
==========================================

#!/bin/sh
# Assign ownership of the console to the invoking user
# $XConsortium: GiveConsole,v 1.2 93/09/28 14:29:20 gildea Exp $
#
# By convention, both xconsole and xterm -C check that the
# console is owned by the invoking user and is readable before attaching
# the console output.  This way a random user can invoke xterm -C without
# causing serious grief.
#
chown $USER /dev/console

# Original line from distribution / commented out
#/usr/X11R6/bin/sessreg  -a -w "/var/log/wtmp" -u "/var/run/utmp" \
#       -x "/etc/X11/xdm/Xservers" -l $DISPLAY -h "" $USER

# Modified / PAR 02/02 to accomodate instantaneous utmp logging
source '/etc/X11/xdm/sessreg.h'
/usr/X11R6/bin/sessreg  -a -w "/var/log/wtmp" -u "/var/run/utmp" \
        -x "/etc/X11/xdm/Xservers" -l $LINENAME -h $LTSHOST $USER


==========================================
file:/etc/X11/xdm/TakeConsole
-----------------------------
Purpose:  Releases an X session
          The original file shown here
          comes from Mandrake 7.0 (Air)
          distribution. Modifications
          are indicated.
==========================================

#!/bin/sh
# Reassign ownership of the console to root, this should disallow
# assignment of console output to any random users's xterm
# $XConsortium: TakeConsole,v 1.2 93/09/28 14:30:29 gildea Exp $
#
chmod 622 /dev/console
chown root /dev/console

# Original line from distribution / commented out
#/usr/X11R6/bin/sessreg -d -w "/var/log/wtmp" -u "/var/run/utmp" \
#       -x "/etc/X11/xdm/Xservers" -l $DISPLAY -h "" $USER

# Modified / PAR 02/02 to accomodate hostname
source /etc/X11/xdm/sessreg.h
/usr/X11R6/bin/sessreg  -d -w "/var/log/wtmp" -u "/var/run/utmp" \
        -x "/etc/X11/xdm/Xservers" -l $LINENAME -h $LTSHOST $USER

# Scripts that you might want to run on exit (for housekeeping purposes) follows
#/usr/bin/umountncp-vol 2&> /dev/null

==========================
Output of 'who' and 'last':
==========================

------------------------------
bash# who -H
USER     LINE     LOGIN-TIME   FROM
root     admin1   Mar  7 11:23
abeng    sales3   Mar  7 09:14
------------------------------

Note: 'admin1' and 'sales3' under the 2nd column (LINE) are our 
      LTSP thin clients (hostnames from $DISPLAY)


-------------------------------------------------------------------------
bash# last | head -n13
root     admin1       LTSP(lts1:0)     Thu Mar  7 11:23   still logged in
root     admin1       LTSP(lts1:0)     Thu Mar  7 10:40 - 11:23  (00:43)
amy      acct1        LTSP(lts1:0)     Thu Mar  7 10:39 - 10:42  (00:02)
abeng    sales3       LTSP(lts1:0)     Thu Mar  7 09:14   still logged in
abeng    sales3       LTSP(lts1:0)     Thu Mar  7 09:12 - 09:13  (00:01)
joey     sales3       LTSP(lts1:0)     Thu Mar  7 09:11 - 09:12  (00:00)
root     lts1         LTSP(lts1:0)     Thu Mar  7 09:09 - 09:21  (00:12)  
proa     admin1       LTSP(lts1:0)     Thu Mar  7 09:11 - 09:36  (00:25)
proa     admin1       LTSP(lts1:0)     Thu Mar  7 09:09 - 09:11  (00:01)
reboot   system boot  2.2.14-15mdk     Wed Jan 23 13:52          (00:35)
proa     pts/0        192.168.1.32     Wed Jan 23 11:28 - 11:32  (00:04)
proa     ftp          192.168.1.32     Wed Jan 23 11:27 - 11:27  (00:00)
root     pts/0                         Wed Jan 23 11:23 - 11:23  (00:00)
reboot   system boot  2.2.14-15mdk     Wed Jan 23 10:29          (03:58)     
-------------------------------------------------------------------------

Note:  Entries with 'LTSP({hostname:0)' (3rd column) are log entries from
       our scripts. Other entries were added to distinguish them from ours
       ;-). Entries #1 and #4 (from the top) are still currently still
       connected.

       Entry #7 shows an X Session done on the server itself (lts1)


Cheers!,

Phil


_____________________________________________________________________
Ltsp-discuss mailing list.   To un-subscribe, or change prefs, goto:
      https://lists.sourceforge.net/lists/listinfo/ltsp-discuss
For additional LTSP help,   try #ltsp channel on irc.openprojects.net

Reply via email to