I'm working on a /bin/login replacement that's included in one of our
products. One of the things /bin/login needs to do is append an entry for the
user's login shell to the end of the /var/adm/wtmp file (and /var/adm/wtmpx;
most of the discussion below applies to both).
The man page for the utmp functions, i.e., getutent(), etc., implies that
these functions can be used to manipulate the wtmp file as well as the utmp
file. However, what they do not make clear is how a program should use them
to append an entry to the end of the wtmp file.
If you take the struct utmp that was just put into the utmp file (call it "u")
and try to put it into the wtmp file by using
It doesn't work, because pututline will search through the wtmp file until it
finds the first entry in it that matches the tty the user is logging in on,
and substitute in that entry rather than appending to then.
My next guess was to do this:
while (getutent()) /* go to the end of the wtmp file */;
As far as I can tell, this *should* work, because the man page claims that
pututline() uses getutid() to find the correct location for the entry, and
that getutid() will only read forward in the file, not backwards. In other
words, the while loop above should move to the end of the wtmp file, and then
the pututline() should append to the end of the file because there's nothing
for getutid(), which is supposed to only search forward, to search.
However, that does not work. The behavior of the second block of code above
appears to be identical to the behavior of the first block, i.e., the utmp
entry I'm passing to pututline ends up in the first slow in the wtmp file that
matches its ut_id field.
However, when I tried it under Linux, the second block of code above did the
right thing, i.e., it appended to the end of the file.
1) Is the method I'm trying to use to append to the end of the wtmp file
correct? I.e., what is the "right" way to add an entry to the wtmp file on a
machine which provides these routines?
2) Is the fact that Solaris is doing what it's doing in the second block of
code above a bug in the Solaris pututline routine?
3) These functions are supposedly part of XPG2, which is referred to a lot in
the Solaris man pages. I want to order a copy of that standard for our
office, but I can't find anywhere exactly what XPG2 stands for, i.e., which
standards body publishes it and which standard it is. Can anyone provide more
information about this?