Preserve Login Session Information after Accounting


Contents

About This Document
About the Problem
Workaround
    How to Use the C Program
    The C Program

About This Document

In some versions of AIX (and UNIX), there is a problem with connection accounting: it "forgets" about jobs that haven't logged off in the last 24 hours. This document applies to AIX Version 3.2 and will correct this problem.

NOTE: APAR IX42292 corrects this problem in AIX 3.2.5. The problem was corrected in AIX 3.2.5.1 and all later releases.


About the Problem

Because the runacct command removes the contents of /var/adm/wtmp every night, commands such as last lose track of users who logged in before the file was cleared.

Workaround

The C program given below will take the /etc/utmp file entries for all currently logged-in users and append them to the existing /var/adm/wtmp file. This will allow last to report the user as being logged in and will allow runacct to report connection-accounting information for that user.

How to Use the C Program

To use the program below, first run the runacct command. Typically, runacct is executed from the adm crontab with an entry of the following form:
10 23 * * 0-6 /usr/lib/acct/runacct 2>/usr/adm/acct/nite/accterr > 
/dev/null
Edit the adm crontab with the command su adm -c crontab -e and change that line to read:
10 23 * * 0-6 (/usr/lib/acct/runacct ;/usr/lib/acct/mkwtmp) 
2>/usr/adm/acct/nite/accterr> /dev/null
Now you're ready to run the C program.

The C Program

Compile the C program given below and store in /usr/lib/acct/mkwtmp. The program must be made executable by the adm user and group.

Depending on how you are viewing this document, some characters in the following code may appear incorrectly. If the characters in the following list do not match their descriptions, be sure to change them in the code.

[ left bracket
] right bracket

   #include 
   #include 
   #include 

   main (int argc, char ** argv)
   {
      char *utmp_name = "/etc/utmp";
      char *wtmp_name = "/var/adm/wtmp";
      FILE *utmp_fp = 0;
      FILE *wtmp_fp = 0;
      int  flag;
      time_t now;
      struct utmp utmp_rec;
      extern int  optind;
      extern char *optarg;

      while ((flag = getopt (argc, argv, "u:w:")) != EOF) {
         switch (flag) {
            case 'u':
               utmp_name = optarg;
               break;
            case 'w':
               wtmp_name = optarg;
               break;
            default:
               fprintf (stderr,
                  "mkwtmp [ -u utmp ] [ -w wtmp ]\n");
               exit (0);
               break;
         }
      }
      if ((utmp_fp = fopen (utmp_name, "r")) == (FILE *) 0) {
         perror (utmp_name);
         exit (1);
      }
      if ((wtmp_fp = fopen (wtmp_name, "w")) == (FILE *) 0) {
         perror (wtmp_name);
         exit (1);
      }
      time (&now);

      while (fread (&utmp_rec, sizeof utmp_rec, 1, utmp_fp) == 1) {
         if (utmp_rec.ut_type == USER_PROCESS) {
            utmp_rec.ut_time = now;
            fwrite (&utmp_rec, sizeof utmp_rec, 1, wtmp_fp);
         }
      }
      exit (0);
   }

Preserve Login Session Information after Accounting: wtmp.save.32.cmd ITEM: FAX
Dated: 98/09/17~00:00 Category: cmd
This HTML file was generated 99/06/24~12:42:11
Comments or suggestions?
Contact us