[ale] Adding entry to utmp
Joe Steele
joe at madewell.com
Thu Dec 13 17:21:00 EST 2001
1) When you use pututent() with type USER_PROCESS, it will first
search through utmp for an existing entry that matches entry.ut_id,
if entry.ut_id is not an empty string. If entry.ut_id is empty, then
a match will be attempted with entry.ut_line. If no match is found,
a new entry is added.
I can't tell from your code whether entry is declared static or auto,
which affects whether it's initialized to zero or not. If entry is
uninitialized, then entry.ut_id may be a non-empty string at runtime.
And by chance, it may be the same non-empty string every time it is
run. If so, then the second time it is run will it will match the
ut_id of the entry that was made the first time it was run, thus
overwriting it.
2) As for the removal of the entry on logout -- this is handled by
telnetd (along with an entry in wtmp).
--Joe
-----Original Message-----
From: Chris Fowler [SMTP:cfowler at outpostsentinel.com]
Sent: Wednesday, December 12, 2001 4:26 PM
To: ale at ale.org
Subject: [ale] Adding entry to utmp
I'm creating my own replacement for login.c and I'm am assuming that it is login's responsibility to add entries to /var/run/utmp. Basically the standard netkit-telnet
daemon calls my login program via exec(). My login program continues the process of loging in a user. Below it my utmp code.
struct utmp entry;
/* Time to write to UTMP */
entry.ut_type = USER_PROCESS;
entry.ut_pid = getpid();
strcpy(entry.ut_line, ttyname(0) + strlen("/dev/"));
time(&entry.ut_time);
strcpy(entry.ut_user, user->username);
memset(entry.ut_host, 0 , UT_HOSTSIZE);
entry.ut_addr = 0;
setutent();
pututline(&entry);
endutent();
/* Do some stuff */
exec("/bin/sh", "/bin/sh", environ);
Output of who It will be cleaned up.
Users:
user port login idle host
root /dev/ports/kvm Dec 12 13:24 00:04 local
root ttyp0 Dec 12 13:30 local
Now if I go to another machine and telnet in again I get the following who output
Users:
user port login idle host
root /dev/ports/kvm Dec 12 13:24 00:04 local
root ttyp1 Dec 12 13:30 local
It appears to have overwritten my last entry and now I have an invisible user. What did I do wrong?
I also notice that if I exit from the shell on ttyp1 then the entry is removed. My login does exec() so it is not removing the
entry. Who is? Or is a value changed that my Who skips over?
Thanks,
Chris Fowler
---
This message has been sent through the ALE general discussion list.
See http://www.ale.org/mailing-lists.shtml for more info. Problems should be
sent to listmaster at ale dot org.
More information about the Ale
mailing list