[net.unix-wizards] watch out when you modify /etc/ttys !!

puder@burdvax.UUCP (06/10/83)

On our 4.1bsd system, we have discovered an interesting phenomenon.

Summary:
If lines are inserted or deleted from /etc/ttys, mail will be sent with the
wrong From username.

Details:

If a line is added to /etc/ttys before the line describing ttyh1,
(signalling init makes no difference to the mail problem) a user on ttyh1
who sends mail will have the name of the user on ttyh2 on the From line.  I
presume that deleting a line would cause the reverse problem.

What seems to be happening is that mail is looking up the terminal name in
/etc/ttys, and then indexing into /etc/utmp to find the user name.  Am I
right?  Why is it done this way?  Why is this not documented ?!?  (And
anyway, why doesn't init rebuild /etc/utmp when it gets the HUP signal?)

Karl Puder   burdvax!puder   SDC-aBC, R & D   Paoli, Pa.   (215)648-7555

dbj.rice%rand-relay@sri-unix.UUCP (06/13/83)

From:  Dave Johnson <dbj.rice@rand-relay>

UCB Mail does a getlogin() to decide who to say the message is "From:", and
if this returns a NULL, it instead tries a getpwuid(getuid()).  Getlogin
uses ttyslot() to find the "slot" number of this tty in /etc/ttys, and then
uses this number also as the slot number in /etc/utmp (init maintains
/etc/utmp in order of tty "slot" number as returned by ttyslot()).  Thus, if
you change /etc/ttys, you change what value is returned by ttyslot(), and
thus, getlogin() starts looking at a different entry in /etc/utmp than was
used to record when this person logged on to this terminal.  Presumably,
Mail thought it was faster to read through /etc/ttys than to read all of
/etc/passwd to translate the uid...

It should be "safe" to add new entries to the bottom of /etc/ttys.  To
"delete" lines from /etc/ttys, you can just put a "0" as the first character
on the line and everybody will ignore that line.

                                        Dave Johnson
                                        Dept. of Math Science
                                        Rice University