Skip to content

Commit

Permalink
Merge branch 'lastlog2' of https://github.com/stoeckmann/util-linux
Browse files Browse the repository at this point in the history
* 'lastlog2' of https://github.com/stoeckmann/util-linux:
  lastlog2: Improve comments and documentation
  Treat out of memory as error
  • Loading branch information
karelzak committed Aug 14, 2024
2 parents a5af422 + 8818717 commit e3df81c
Show file tree
Hide file tree
Showing 14 changed files with 45 additions and 35 deletions.
6 changes: 3 additions & 3 deletions liblastlog2/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,15 @@ Since there are only few applications which really support `lastlog`, the data i

## lastlog2

`lastlog2` tries to solve this problems:
`lastlog2` tries to solve these problems:

* It's using sqlite3 as database backend.
* Data is only collected via a PAM module, so that every tools can make use of it, without modifying existing packages.
* Data is only collected via a PAM module, so that all tools can make use of it, without modifying existing packages.
* The output is as compatible as possible with the old lastlog implementation.
* The old `/var/log/lastlog` file can be imported into the new database.
* The size of the database depends on the amount of users, not how big the biggest UID is.

**IMPORTANT** To be Y2038 safe on 32bit architectures, the binaries needs to be build with a **64bit time_t**. This should be the standard on 64bit architectures.
**IMPORTANT** To be Y2038 safe on 32bit architectures, the binaries need to be built with a **64bit time_t**. This should be the standard on 64bit architectures.

Besides the lastlog2 library in this directory there are additional parts like service definition, PAM module and applications:

Expand Down
2 changes: 1 addition & 1 deletion liblastlog2/man/lastlog2.3.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ lastlog2 - Y2038 safe version of lastlog library.

*lastlog2* reports the last login of a given user or of all users who did ever login on a system.

It's using sqlite3 as database backend. Data is only collected via a PAM module, so that every
It's using sqlite3 as database backend. Data is only collected via a PAM module, so that all
tools can make use of it, without modifying existing packages.
The output is as compatible as possible with the old lastlog implementation.
By default the database will be written as `/var/lib/lastlog/lastlog2.db`.
Expand Down
4 changes: 2 additions & 2 deletions liblastlog2/man/ll2_import_lastlog.3.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

== NAME

ll2_import_lastlog - Import old lastlog file.
ll2_import_lastlog - Imports old lastlog file.

== SYNOPSIS

Expand All @@ -21,7 +21,7 @@ ll2_import_lastlog - Import old lastlog file.

== DESCRIPTION

Importing all entries from _lastlog_file_ file (lastlog(8)) into
Imports all entries from _lastlog_file_ file (lastlog(8)) into
lastlog2 database defined with _context_.
If _context_ is NULL, the default database, defined in _LL2_DEFAULT_DATABASE_,
will be taken.
Expand Down
8 changes: 4 additions & 4 deletions liblastlog2/man/ll2_new_context.3.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

== NAME

ll2_new_context - Context which defines the lastlog2 environment.
ll2_new_context - Allocates context which defines the lastlog2 environment.

== SYNOPSIS

Expand All @@ -19,8 +19,8 @@ ll2_new_context - Context which defines the lastlog2 environment.

== DESCRIPTION

Defining lastlog2 context e.g. database file, which will be used for
any other lastlog2 calls. If _db_path_ is NULL, the default path defined
Defines lastlog2 context e.g. database file, which will be used for
any other lastlog2 call. If _db_path_ is NULL, the default path defined
in _LL2_DEFAULT_DATABASE_ will be taken.

--------------------------------------
Expand All @@ -32,7 +32,7 @@ ll2_context *context = ll2_new_context(db_path);

== RETURN VALUE

Returns context which will used for all other lastlog2 library calls.
Returns context which will be used for all other lastlog2 library calls.
This context should be released with _ll2_unref_context_ when it is not
needed anymore.
Returns NULL on an error.
Expand Down
2 changes: 1 addition & 1 deletion liblastlog2/man/ll2_read_all.3.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ Returns 0 on success, -ENOMEM or -1 on other failure.
_error_ contains an error string if the return value is -1.
_error_ is not guaranteed to contain an error string, could also be NULL.
_error_ should be freed by the caller.
If lastlog2 database does not exist at all, the errno ENOENT has been set
If lastlog2 database does not exist at all, the errno ENOENT is set
and can be checked.

== AUTHORS
Expand Down
2 changes: 1 addition & 1 deletion liblastlog2/man/ll2_read_entry.3.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ Returns 0 on success, -ENOMEM or -1 on other failure.
_error_ contains an error string if the return value is -1.
_error_ is not guaranteed to contain an error string, could also be NULL.
_error_ should be freed by the caller.
If lastlog2 database does not exist at all, the errno ENOENT has been set
If lastlog2 database does not exist at all, the errno ENOENT is set
and can be checked.

The evaluated values are returned by _ll_time_, _tty_, _rhost_ and _pam_service_.
Expand Down
4 changes: 2 additions & 2 deletions liblastlog2/man/ll2_remove_entry.3.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

== NAME

ll2_remove_entry - Remove all entries of an user.
ll2_remove_entry - Removes all entries of a user.

== SYNOPSIS

Expand All @@ -20,7 +20,7 @@ ll2_remove_entry - Remove all entries of an user.

== DESCRIPTION

Removing all database entries, defined in _context_, with the user name _user_.
Removes all database entries, defined in _context_, with the user name _user_.
If _context_ is NULL, the default database, defined in _LL2_DEFAULT_DATABASE_,
will be taken.

Expand Down
4 changes: 2 additions & 2 deletions liblastlog2/man/ll2_rename_user.3.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

== NAME

ll2_rename_user - Renames an user entry.
ll2_rename_user - Renames a user entry.

== SYNOPSIS

Expand All @@ -20,7 +20,7 @@ ll2_rename_user - Renames an user entry.

== DESCRIPTION

Changing user name from _user_ to _newname_ of one entry in
Changes user name from _user_ to _newname_ of one entry in
database, which is defined by _context_. All other entries with the user _user_
will be deleted.
If _context_ is NULL, the default database, defined in _LL2_DEFAULT_DATABASE_,
Expand Down
4 changes: 2 additions & 2 deletions liblastlog2/man/ll2_unref_context.3.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

== NAME

ll2_unref_context - Freeing lastlog2 context.
ll2_unref_context - Frees lastlog2 context.

== SYNOPSIS

Expand All @@ -19,7 +19,7 @@ ll2_unref_context - Freeing lastlog2 context.

== DESCRIPTION

Freeing lastlog2 context, which has been generated by
Frees lastlog2 context, which has been allocated by
_ll2_new_context_.

--------------------------------------
Expand Down
6 changes: 3 additions & 3 deletions liblastlog2/man/ll2_update_login_time.3.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

== NAME

ll2_update_login_time - Writes an *new* entry with updated login time.
ll2_update_login_time - Writes a *new* entry with updated login time.

== SYNOPSIS

Expand All @@ -21,7 +21,7 @@ ll2_update_login_time - Writes an *new* entry with updated login time.

== DESCRIPTION

Writes an *new* entry to database, defined in _context_, for user _user_.
Writes a *new* entry to database, defined in _context_, for user _user_.
Time is set by _ll_time_ whereas the other values are taken from
an already existing entry.
If _context_ is NULL, the default database, defined in _LL2_DEFAULT_DATABASE_,
Expand All @@ -39,7 +39,7 @@ int ret = ll2_update_login_time (NULL, user, login_time, &error);

Returns 0 on success, -ENOMEM or -1 on other failure.
_error_ contains an error string if the return value is -1.
_error_ is not guaranteed to contain an error string. It could also be NULL if the return value is -1.
_error_ is not guaranteed to contain an error string, could also be NULL.
_error_ should be freed by the caller.

== AUTHORS
Expand Down
4 changes: 2 additions & 2 deletions liblastlog2/man/ll2_write_entry.3.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

== NAME

ll2_write_entry - Write a new entry into the database.
ll2_write_entry - Writes a new entry into the database.

== SYNOPSIS

Expand All @@ -22,7 +22,7 @@ ll2_write_entry - Write a new entry into the database.

== DESCRIPTION

Writes an new entry into database, which is defined in _context_.
Writes a new entry into database, which is defined in _context_.
If _context_ is NULL, the default database, defined in _LL2_DEFAULT_DATABASE_,
will be taken.

Expand Down
28 changes: 17 additions & 11 deletions liblastlog2/src/lastlog2.c
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
#include "lastlog2P.h"
#include "strutils.h"

/* Set the ll2 context/environment */
/* Sets the ll2 context/environment. */
/* Returns the context or NULL if an error has happened. */
extern struct ll2_context * ll2_new_context(const char *db_path)
{
Expand All @@ -61,7 +61,7 @@ extern struct ll2_context * ll2_new_context(const char *db_path)
return context;
}

/* Release ll2 context/environment */
/* Releases ll2 context/environment. */
extern void ll2_unref_context(struct ll2_context *context)
{
if (context)
Expand Down Expand Up @@ -206,7 +206,8 @@ read_entry(sqlite3 *db, const char *user,
return retval;
}

/* reads 1 entry from database and returns that. Returns 0 on success, -ENOMEM or -1 on other failure. */
/* Reads one entry from database and returns that.
Returns 0 on success, -ENOMEM or -1 on other failure. */
int
ll2_read_entry(struct ll2_context *context, const char *user,
int64_t *ll_time, char **tty, char **rhost,
Expand All @@ -225,7 +226,8 @@ ll2_read_entry(struct ll2_context *context, const char *user,
return retval;
}

/* Write a new entry. Returns 0 on success, -ENOMEM or -1 on other failure. */
/* Writes a new entry.
Returns 0 on success, -ENOMEM or -1 on other failure. */
static int
write_entry(sqlite3 *db, const char *user,
int64_t ll_time, const char *tty, const char *rhost,
Expand Down Expand Up @@ -324,7 +326,8 @@ write_entry(sqlite3 *db, const char *user,
return retval;
}

/* Write a new entry. Returns 0 on success, -ENOMEM or -1 on other failure. */
/* Writes a new entry.
Returns 0 on success, -ENOMEM or -1 on other failure. */
int
ll2_write_entry(struct ll2_context *context, const char *user,
int64_t ll_time, const char *tty, const char *rhost,
Expand All @@ -343,7 +346,7 @@ ll2_write_entry(struct ll2_context *context, const char *user,
return retval;
}

/* Write a new entry with updated login time.
/* Writes a new entry with updated login time.
Returns 0 on success, -ENOMEM or -1 on other failure. */
int
ll2_update_login_time(struct ll2_context *context, const char *user,
Expand Down Expand Up @@ -409,7 +412,7 @@ ll2_read_all(struct ll2_context *context,
char **error)
{
sqlite3 *db;
char *err_msg = 0;
char *err_msg = NULL;
int retval = 0;

if ((retval = open_database_ro(context, &db, error)) != 0)
Expand All @@ -431,7 +434,8 @@ ll2_read_all(struct ll2_context *context,
return retval;
}

/* Remove an user entry. Returns 0 on success, -ENOMEM or -1 on other failure. */
/* Removes a user entry.
Returns 0 on success, -ENOMEM or -1 on other failure. */
static int
remove_entry(sqlite3 *db, const char *user, char **error)
{
Expand Down Expand Up @@ -480,7 +484,8 @@ remove_entry(sqlite3 *db, const char *user, char **error)
return retval;
}

/* Remove an user entry. Returns 0 on success, -ENOMEM or -1 on other failure. */
/* Removes a user entry.
Returns 0 on success, -ENOMEM or -1 on other failure. */
int
ll2_remove_entry(struct ll2_context *context, const char *user,
char **error)
Expand All @@ -498,7 +503,8 @@ ll2_remove_entry(struct ll2_context *context, const char *user,
return retval;
}

/* Renames an user entry. Returns 0 on success, -ENOMEM or -1 on other failure. */
/* Renames a user entry.
Returns 0 on success, -ENOMEM or -1 on other failure. */
int
ll2_rename_user(struct ll2_context *context, const char *user,
const char *newname, char **error)
Expand Down Expand Up @@ -536,7 +542,7 @@ ll2_rename_user(struct ll2_context *context, const char *user,
return retval;
}

/* Import old lastlog file.
/* Imports old lastlog file.
Returns 0 on success, -ENOMEM or -1 on other failure. */
int
ll2_import_lastlog(struct ll2_context *context, const char *lastlog_file,
Expand Down
2 changes: 1 addition & 1 deletion misc-utils/lastlog2.8.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ This file may be copied under the terms of the GNU General Public License.

== NAME

lastlog2 - display date of last login for all users or a specific one
lastlog2 - displays date of last login for all users or a specific one

== SYNOPSIS

Expand Down
4 changes: 4 additions & 0 deletions pam_lastlog2/src/pam_lastlog2.c
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,8 @@ write_login_data (pam_handle_t *pamh, int ctrl, const char *user)
return PAM_SYSTEM_ERR;

struct ll2_context *context = ll2_new_context(lastlog2_path);
if (context == NULL)
return PAM_SYSTEM_ERR;
if (ll2_write_entry (context, user, ll_time, tty, rhost,
pam_service, &error) != 0) {
if (error) {
Expand Down Expand Up @@ -220,6 +222,8 @@ show_lastlogin (pam_handle_t *pamh, int ctrl, const char *user)
return retval;

struct ll2_context *context = ll2_new_context(lastlog2_path);
if (context == NULL)
return PAM_SYSTEM_ERR;
if (ll2_read_entry (context, user, &ll_time, &tty, &rhost,
&service, &error) != 0) {
if (errno == ENOENT)
Expand Down

0 comments on commit e3df81c

Please sign in to comment.