utmp

package module
v0.0.0-...-9cd12f6 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 3, 2023 License: GPL-3.0 Imports: 3 Imported by: 0

README

Package utmp

The utmp package provides functionality to read and manipulate utmp entries in Go. The package includes structs and methods to work with the utmp file, which contains information about user login sessions and terminated processes.

Types

exit_status struct

type exit_status struct {
	e_termination int16
	e_exit        int16
}

The exit_status struct represents the exit status of a terminated process. It has two fields: e_termination and e_exit, which store the termination and exit values, respectively.

Utmp struct

type Utmp struct {
	Type      int
	Pid       int
	Device    string
	Id        string
	Username  string
	HostName  string
	Exit      exit_status
	Session   int
	Seconds   int64
	MicroSecs int64
	Login     time.Time
	AddrV6    [4]int
}

The Utmp struct represents a utmp entry. It contains various fields to store information such as the entry type, process ID, device, user ID, username, hostname, exit status, session ID, timestamp, login time, and IPv6 address.

Users struct

type Users struct {
	Users []Utmp
}

The Users struct holds a collection of Utmp entries. It has a single field Users, which is a slice of Utmp structs.

LiveUsers struct

type LiveUsers struct {
	Users []*Utmp
}

The LiveUsers struct represents currently logged in users. It contains a field Users, which is a slice of pointers to Utmp structs.

Functions and Methods

Read function
func Read() *Users

The Read function reads the utmp entries and returns a pointer to a Users struct. It iterates over the entries using the C function getutent() and converts the C struct to Go struct (Utmp). The function populates the Users struct with the converted entries and returns a pointer to it.

Live method
func (u *Users) Live() *LiveUsers

The Live method filters the Users array and returns a pointer to a LiveUsers struct. It iterates over the Users array and checks if the entry type is 7 (representing a normal process). If the entry type is 7, it appends a pointer to the entry (Utmp) to the LiveUsers struct. The method returns a pointer to the filtered LiveUsers struct.

Please note that the code includes C imports and uses unsafe operations for converting the ut_addr_v6 field. Caution should be exercised when working with these parts of the code.

It is recommended to refer to the man utmp manual for a deeper understanding of the utmp entries and their fields.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type LiveUsers

type LiveUsers struct {
	Users []*Utmp // Use pointer to Utmp instead of Utmp
}

struct that holds currently logged in users

type Users

type Users struct {
	Users []Utmp
}

struct that holds all the login history since booting, including terminated processess, see man utmp

func Read

func Read() *Users

ReadUtmp reads the utmp entries and returns a pointer to Users

func (*Users) Live

func (u *Users) Live() *LiveUsers

Live filters the Users array and returns a pointer to LiveUsers

type Utmp

type Utmp struct {
	Type      int
	Pid       int
	Device    string
	Id        string
	Username  string
	HostName  string
	Exit      exit_status
	Session   int
	Seconds   int64
	MicroSecs int64
	Login     time.Time // added to make it easier getting the time
	AddrV6    [4]int    // issue?
}

man utmp

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL