Skip to main content

utmp, wtmp and btmp reader module for Python 3.x

Project description

This project is a binary CPython 3.x module which allows you to interact with the user accounting databases utmp, wtmp and btmp, which keep track of the boot, login and logout events.

It was developed for the fingerd project, which needs to know the last login date of a user, if the user is still logged in, on which line they are connected to the system, and so on. I decided to make my own module to manage these files.

These files and the interfaces to them vary among systems, but this module attempts at implementing as much as possible, including the standardized form in POSIX and the Single Unix Specification.

Usage

The module defines at least the pyutmpx.utmp object, and at most it and two other databases, which are pyutmpx.wtmp and pyutmpx.btmp. The three objects behave the same, so in the rest of the description, I’ll only deal with pyutmpx.utmp.

pyutmpx.utmp is both an iterator and iterable, using itself as the iterator, which allows you to use tools such as list comprehensions with it. You can also use the .reset() and .next() methods with it.

Every return entry will be a pyutmpx.entry, which has the following properties:

type (integer)

The entry type, among the following:

pyutmpx.BOOT_TIME

Time of system boot.

pyutmpx.OLD_TIME

Time before system clock change.

pyutmpx.NEW_TIME

Time after system clock change.

pyutmpx.USER_PROCESS

Normal process.

pyutmpx.INIT_PROCESS

Process spawned by init(8).

pyutmpx.LOGIN_PROCESS

Session leader process for user login.

pyutmpx.DEAD_PROCESS

Terminated process.

id (string)

The terminal name suffix, or inittab(5) ID.

user (string)

The username.

line (string)

The line on which the user is logged in, usually the device name of the tty minus the “/dev/” part.

date (datetime.datetime instance)

The date of the event.

pid (integer)

The process identifier.

What is left to do

  • Implement other interfaces, standard and non-standard, as explained in the “Compatibility” section in utmp.c.

  • Add the pyutmpx.wtmp and pyutmpx.btmp objects when possible.

  • Add utmp filename getting and setting for these objects.

  • Add a list-like interface, with length and index.

  • Add methods to add an event, such as login or logout events.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

pyutmpx-0.3.1.tar.gz (17.8 kB view hashes)

Uploaded Source

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page