Free Trial

Safari Books Online is a digital library providing on-demand subscription access to thousands of learning resources.


  • Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • PrintPrint
Share this Page URL
Help

40. Login Accounting > Updating the utmp and wtmp Files for a Login Session

Updating the utmp and wtmp Files for a Login Session

When writing an application that creates a login session (in the manner of, say, login or sshd), we should update the utmp and wtmp files as follows:

  • On login, a record should be written to the utmp file to indicate that this user logged in. The application must check whether a record for this terminal already exists in the utmp file. If a previous record exists, it is overwritten; otherwise, a new record is appended to the file. Often, calling pututxline() (described shortly) is enough to ensure that these steps are correctly performed (see Example 40-3 for an example). The output utmpx record should have at least the ut_type, ut_user, ut_tv, ut_pid, ut_id, and ut_line fields filled in. The ut_type field should be set to USER_PROCESS. The ut_id field should contain the suffix of the name of the device (i.e., the terminal or pseudoterminal) on which the user is logging in, and the ut_line field should contain the name of the login device, with the leading /dev/ string removed. (Examples of the contents of these two fields are shown in the sample runs of the program in Example 40-2.) A record containing exactly the same information is appended to the wtmp file.


  

You are currently reading a PREVIEW of this book.

                                                                                                                    

Get instant access to over $1 million worth of books and videos.

  

Start a Free 10-Day Trial


  
  • Safari Books Online
  • Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • PrintPrint