Bug in pututline, getutid or getutent when appending to wtmp file?

Bug in pututline, getutid or getutent when appending to wtmp file?

Post by Jonathan I. Kame » Thu, 28 Apr 1994 03:43:34



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

        utmpname("/var/adm/wtmp");
        pututline(&u);
        endutent();

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:

        utmpname("/var/adm/wtmp");
        while (getutent()) /* go to the end of the wtmp file */;
        pututline(&u);
        endutent();

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.

Three questions:

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?

Thanks,

--

 
 
 

Bug in pututline, getutid or getutent when appending to wtmp file?

Post by Charles Hedri » Sat, 30 Apr 1994 01:02:47



Quote:>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).

Here's the relevant code from our login (which is based on a BSD
version, not Sun's -- this was done before we had source code to
Solaris).  I'm not sure quite how we found out about modutx, which is
the most convenient way of doing this, but isn't documented.  Note
that the utx functions update both utmp and utmpx.  You should make
sure to use them.  Using the old ut functions, or appending to wtmp
yourself, can cause the library to rewrite wtmpx, removing the
hostnames from old entries.  This is incredibly bogus code, which
we've complained about, but so far haven't been able to get fixed.
(Some Sun utilities do this, which is why you'll often find that wtmp
lists hostnames only for the most recent entries.)

#ifdef __svr4__
        {

                /*
                 * This updates the utmpx and utmp entries and make a
                 * wtmp/x entry
                 */

                strncpy(utmpx.ut_line, tty, sizeof(utmpx.ut_line));
                utxp = getutxline(&utmpx);
                if (utxp) {
                  strncpy(utxp->ut_user, username, sizeof(utxp->ut_user));
                  utxp->ut_pid = getpid();
                  utxp->ut_type = USER_PROCESS;
                  utxp->ut_exit.e_termination = 0;
                  utxp->ut_exit.e_exit = 0;
                  if (hostname) {
                    strncpy(utxp->ut_host, hostname, sizeof(utxp->ut_host));
                    utxp->ut_syslen = strlen(hostname) + 1;
                    if (utxp->ut_syslen > sizeof(utxp->ut_host))
                      utxp->ut_syslen = sizeof(utxp->ut_host);
                  }
                  (void) time(&utmpx.ut_tv.tv_sec);
                  utmpx.ut_tv.tv_usec = 0;
                  modutx(utxp);
                }
                endutxent();
        }

 
 
 

Bug in pututline, getutid or getutent when appending to wtmp file?

Post by Charles Hedri » Sat, 30 Apr 1994 01:12:49



Quote:>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).

By the way, if you want to use only documented functions, updwtmpx is
the official way to append to wtmp and wtmpx.  It should do what you
want.
 
 
 

1. wtmp /var/adm/wtmp No such file or directory

I am running a WU-FTPD server on Solaris 8.  I was investigating
why passive mode would not work when coming through the firewall
and discovered these log entries:

ftpd[]: [ID 896167 daemon.error] wtmp /var/adm/wtmp No such file or directory

I see that wtmp is part of the past and I am running the most
current version of WU-FTPD.  Anyeone have any idea how to fix
tihs?

Sam

2. Suse 6.4 to 7.1 (future) upgrade.

3. Here's 1 solution to the Netscape Nav append-to-file bug

4. Zenith laptop video chipset woes (long)

5. sa bug "cannot append data to that file"

6. Will the /etc/aliases file do what I need?

7. appending binary file in a text file

8. HP2550L colour laser printer

9. rsh question: Append local file to a remote file

10. Help - how to append one file to every page of another file?

11. Append to files in tar-file but don't change originals.

12. RH Linux: Bizarre wtmp/utmp, log file, and file date problems

13. Does append in LILO really append?