[comp.windows.x] How to get xdm to make wtmp and utmp file entries?

mjd@central.cis.upenn.edu (Mark-Jason Dominus) (06/01/90)

Our xdm's don't seem to be logging logins and logouts in the
/etc/wtmp and /etc/utmp files.  Is there a good way to get
them to do this, or is there a good reason why they
shouldn't?

Thanks.
--

 In some sense a stochastic process can do better; at least it has a chance.
Mark-Jason Dominus 	  			    mjd@central.cis.upenn.edu 

envbvs@epb2.lbl.gov (Brian V. Smith) (06/01/90)

In article <MJD.90May31173254@central.cis.upenn.edu>,
mjd@central.cis.upenn.edu (Mark-Jason Dominus) writes:
|> 
|> Our xdm's don't seem to be logging logins and logouts in the
|> /etc/wtmp and /etc/utmp files.  Is there a good way to get
|> them to do this, or is there a good reason why they
|> shouldn't?

xdm doesn't make the entries in these files, but you can make the main
xterm do it with the +ut and -ls options.  The +ut makes it write in the
/etc/utmp file and the -ls is required to make it write in the /etc/wtmp
file.  The -ls also makes it read and execute your .login file.
_____________________________________
Brian V. Smith    (bvsmith@lbl.gov)
Lawrence Berkeley Laboratory
I don't speak for LBL, these non-opinions are all mine.

mjd@central.cis.upenn.edu (Mark-Jason Dominus) (06/01/90)

In article <5723@helios.ee.lbl.gov> envbvs@epb2.lbl.gov (Brian V. Smith) writes:
>   mjd@central.cis.upenn.edu (Mark-Jason Dominus) writes:
>   |> 
>   |> Our xdm's don't seem to be logging logins and logouts in the
>   |> /etc/wtmp and /etc/utmp files.
>
>   The -ls is required to make it write in the /etc/wtmp
>   file.  The -ls also makes it read and execute your .login file.

Thanks for the +ut tip; I must have missed it when I read
the man page.  But neither the R3 nor the R4 man pages say
that -ls makes xterm write a wtmp entry, and, in fact, we
had the -ls option set already, and no wtmp entries.

Does it work for you?

--

 In some sense a stochastic process can do better; at least it has a chance.
Mark-Jason Dominus 	  			    mjd@central.cis.upenn.edu 

kit@EXPO.LCS.MIT.EDU (Chris D. Peterson) (06/01/90)

In article <MJD.90May31173254@central.cis.upenn.edu>,
mjd@central.cis.upenn.edu (Mark-Jason Dominus) writes:
|> 
|> Our xdm's don't seem to be logging logins and logouts in the
|> /etc/wtmp and /etc/utmp files.  Is there a good way to get
|> them to do this, or is there a good reason why they
|> shouldn't?

Yes.  We feel that a session manager should be logging the user as "on" the
system.  The display manager is only responsible for managing your display, and
this is outside its realm.  Unfortunatly session managers are not widely
avaliable (a shell script is NOT a session manager :-), and so this piece of
useful functionality has been dropped on the floor.  As session managers become
avaliable they should fill this gap.

On a more technical note, Xdm does not have a tty, so adding a utmp or wtmp
entry will confuse programs that depend on this behavior.  For example, finger
and who will not work correctly.


						Chris D. Peterson     
						MIT X Consortium 

Net:	 kit@expo.lcs.mit.edu
Phone:   (617) 253 - 9608	
Address: MIT - Room NE43-213

envbvs@epb2.lbl.gov (Brian V. Smith) (06/01/90)

In article <MJD.90May31194223@central.cis.upenn.edu>,
mjd@central.cis.upenn.edu (Mark-Jason Dominus) writes:
|> In article <5723@helios.ee.lbl.gov> envbvs@epb2.lbl.gov (Brian V.
Smith) writes:
|> >   mjd@central.cis.upenn.edu (Mark-Jason Dominus) writes:
|> >   |> 
|> >   |> Our xdm's don't seem to be logging logins and logouts in the
|> >   |> /etc/wtmp and /etc/utmp files.
|> >
|> >   The -ls is required to make it write in the /etc/wtmp
|> >   file.  The -ls also makes it read and execute your .login file.
|> 
|> Thanks for the +ut tip; I must have missed it when I read
|> the man page.  But neither the R3 nor the R4 man pages say
|> that -ls makes xterm write a wtmp entry, and, in fact, we
|> had the -ls option set already, and no wtmp entries.
|> 
|> Does it work for you?

There is something strange that I didn't notice at first.  You must
use BOTH +ut and -ls to get xterm to write to both files.

If you only specify +ut, you will see the use logged in (/etc/utmp),
but the "last" command (/etc/wtmp) shows nothing for that user.

The -ls option  *BY ITSELF* doesn't seem to do anything with either
file, but both options together will write to both files.

_____________________________________
Brian V. Smith    (bvsmith@lbl.gov)
Lawrence Berkeley Laboratory
I don't speak for LBL, these non-opinions are all mine.

mjd@central.cis.upenn.edu (Mark-Jason Dominus) (06/02/90)

In article <MJD.90May31173254@central.cis.upenn.edu> mjd@central.cis.upenn.edu (Mark-Jason Dominus) writes:
   Our xdm's don't seem to be logging logins and logouts in the
   /etc/wtmp and /etc/utmp files.  Is there a good way to get
   them to do this,

It turns out that the right answer is the `sessreg' program,
which is distributed in the same directory as xdm and which
is designed to solve exactly this problem.  Duh.  If someone
had pointed this out before I found it, they could have had
the pleasure of heaving a brick at my head, but as it is
I'll just have to do it myself.

Oh, well.  Bring on the brickbats.

--

 In some sense a stochastic process can do better; at least it has a chance.
Mark-Jason Dominus 	  			    mjd@central.cis.upenn.edu 

Mark.Bush@prg.oxford.ac.UK (06/02/90)

> In article <MJD.90May31173254@central.cis.upenn.edu>,
> mjd@central.cis.upenn.edu (Mark-Jason Dominus) writes:
> |> 
> |> Our xdm's don't seem to be logging logins and logouts in the
> |> /etc/wtmp and /etc/utmp files.  Is there a good way to get
> |> them to do this, or is there a good reason why they
> |> shouldn't?
> 
> xdm doesn't make the entries in these files, but you can make the main
> xterm do it with the +ut and -ls options.  The +ut makes it write in the
> /etc/utmp file and the -ls is required to make it write in the /etc/wtmp
> file.  The -ls also makes it read and execute your .login file.

The utmp file is world writable on many systems, but the wtmp file usually
isn't.  Even so, all that the -ls flag means is that the shell that is
started is a login shell.  This is done by prepending a `-' to the name of
the shell.  The xterm will add an entry to the utmp file but not the wtmp
file.

Normally it is `login' that writes the entry to the wtmp file.

This hassle with these files is a pain.  I have written two programs to sort
this stuff out.  One (xlogin) is called from the Xstartup file (see xdm(1))
and sticks a fake console entry into the utmp file for the user logging in
and adds an entry to wtmp.  The other (xlogout) is called from the Xreset
file and removes the console entry from utmp and adds a logout entry to wtmp.

In Xstartup I have:
-------------------------------------------------------------------------------
#! /bin/sh

if [ -f /etc/xlogin ]; then
   /etc/xlogin $USER
fi

if [ -f /etc/motd ]; then
   (cat /etc/motd)                                              > /dev/console
fi

if [ -f /usr/ucb/quota ]; then
   (/usr/ucb/quota $USER)                                       > /dev/console
fi

if [ -s /usr/spool/mail/$USER ]; then
   (echo You have mail)                                         > /dev/console
fi

if [ -f /etc/nologin ]; then
    (cat /etc/nologin)                                          > /dev/console
    exit 1
fi
exit 0
-------------------------------------------------------------------------------

and in Xreset I have:
-------------------------------------------------------------------------------
#! /bin/sh

if [ -f /etc/xlogout ]; then
   /etc/xlogout
fi
-------------------------------------------------------------------------------

This keeps logging info happy, but since the console is never used, the
person's fake console entry has a looooonnnng idle time.

Does anyone have a better way of doing this sort of thing?

If anyone wants the source for my xlogin and xlogout then mail me.  They are
not exactly elegant, but they do their job.

Mark

Mark.Bush@prg.oxford.ac.UK (06/11/90)

I've had a few requests for my xlogin/xlogout programs so I thought I'd
include them here---I didn't think it was worth posting them to
comp.sources.x.  We have a network of Sun workstations here (no x-terminals
or anything) so I no longer use xdm or these programs to run X sessions but
get users to invoke startx.

WARNING:  These programs assume that the console entry in the utmp file
is the second slot.  I was only using these programs on my machine and I
could guarantee that the first utmp slot was all NULLs and the second was
the console slot.  To make them more general, ttyslot() should be used.  I
think they will only run on Suns as they are (though they may well run on
general BSD4.{2,3} boxes).

DISCLAIMER:  These programs are supplied `as is' and without warranty.  I
accept no responsibility for any problems/errors/faults that may occur due
to their use.

If you want to take these programs and change them and/or distribute them then
feel free.

I wrote these one afternoon as a hack so they are not exactly elegant and I
don't claim that they will always work so, please, no flames.

Share and enjoy,
Mark
-------------------------------------------------------------------------------
/*
 * xlogin.c
 * Mark Bush
 * Mark.Bush@uk.ac.oxford.prg
 */

#include <sys/time.h>
#include <stdio.h>
#include <utmp.h>

main(argc, argv)
int argc;
char *argv[];
{
    char *p;
    FILE *ufp, *wfp;
    struct utmp ut;
    int i, length;

    if ((ufp = fopen("/etc/utmp", "r+")) == NULL ||
        (wfp = fopen("/usr/adm/wtmp", "a")) == NULL)
    {
        perror("Can't log login.");
        exit(1);
    }

    length = strlen(argv[1]);
    length = (length>8 ? 8 : length);

    fseek(ufp, (long)36, 0);    /* Go to second slot */
    p = (char *)&ut;
    for (i=0; i<36; i++)
        *p++ = getc(ufp);
    fseek(ufp, (long)-36, 1);
    sprintf(ut.ut_name, "\0\0\0\0\0\0\0\0");
    for (i=0; i<length; i++)
        ut.ut_name[i] = argv[1][i];
    for (i=length; i<8; i++)
        ut.ut_name[i] = '\0';
    ut.ut_time = time(0);
    sprintf(ut.ut_host, "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0");
    sprintf(ut.ut_line, "console\0");
    p = (char *)&ut;
    for (i=0; i<36; i++)
    {
        putc(*p, ufp);
        putc(*p++, wfp);
    }
    
    fclose(ufp);
    fclose(wfp);
}
-------------------------------------------------------------------------------
/*
 * xlogout.c
 * Mark Bush
 * Mark.Bush@uk.ac.oxford.prg
 */

#include <sys/time.h>
#include <stdio.h>
#include <utmp.h>

main(argc, argv)
int argc;
char *argv[];
{
    char *p;
    FILE *ufp, *wfp;
    struct utmp ut;
    int i;

    if ((ufp = fopen("/etc/utmp", "r+")) == NULL ||
        (wfp = fopen("/usr/adm/wtmp", "a")) == NULL)
    {
        perror("Can't log logout.");
        exit(1);
    }

    fseek(ufp, (long)36, 0);    /* Go to second slot */
    p = (char *)&ut;
    for (i=0; i<36; i++)
        *p++ = getc(ufp);
    fseek(ufp, (long)-36, 1);
    sprintf(ut.ut_name, "\0\0\0\0\0\0\0\0");
    ut.ut_time = time(0);
    sprintf(ut.ut_host, "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0");
    p = (char *)&ut;
    for (i=0; i<36; i++)
    {
        putc('\0', ufp);
        putc(*p++, wfp);
    }

    fclose(ufp);
    fclose(wfp);
}
-------------------------------------------------------------------------------