Skip to content

Commit e3df81c

Browse files
committed
Merge branch 'lastlog2' of https://github.com/stoeckmann/util-linux
* 'lastlog2' of https://github.com/stoeckmann/util-linux: lastlog2: Improve comments and documentation Treat out of memory as error
2 parents a5af422 + 8818717 commit e3df81c

14 files changed

+45
-35
lines changed

liblastlog2/README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,15 +18,15 @@ Since there are only few applications which really support `lastlog`, the data i
1818

1919
## lastlog2
2020

21-
`lastlog2` tries to solve this problems:
21+
`lastlog2` tries to solve these problems:
2222

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

29-
**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.
29+
**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.
3030

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

liblastlog2/man/lastlog2.3.adoc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ lastlog2 - Y2038 safe version of lastlog library.
1919

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

22-
It's using sqlite3 as database backend. Data is only collected via a PAM module, so that every
22+
It's using sqlite3 as database backend. Data is only collected via a PAM module, so that all
2323
tools can make use of it, without modifying existing packages.
2424
The output is as compatible as possible with the old lastlog implementation.
2525
By default the database will be written as `/var/lib/lastlog/lastlog2.db`.

liblastlog2/man/ll2_import_lastlog.3.adoc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99

1010
== NAME
1111

12-
ll2_import_lastlog - Import old lastlog file.
12+
ll2_import_lastlog - Imports old lastlog file.
1313

1414
== SYNOPSIS
1515

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

2222
== DESCRIPTION
2323

24-
Importing all entries from _lastlog_file_ file (lastlog(8)) into
24+
Imports all entries from _lastlog_file_ file (lastlog(8)) into
2525
lastlog2 database defined with _context_.
2626
If _context_ is NULL, the default database, defined in _LL2_DEFAULT_DATABASE_,
2727
will be taken.

liblastlog2/man/ll2_new_context.3.adoc

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99

1010
== NAME
1111

12-
ll2_new_context - Context which defines the lastlog2 environment.
12+
ll2_new_context - Allocates context which defines the lastlog2 environment.
1313

1414
== SYNOPSIS
1515

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

2020
== DESCRIPTION
2121

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

2626
--------------------------------------
@@ -32,7 +32,7 @@ ll2_context *context = ll2_new_context(db_path);
3232

3333
== RETURN VALUE
3434

35-
Returns context which will used for all other lastlog2 library calls.
35+
Returns context which will be used for all other lastlog2 library calls.
3636
This context should be released with _ll2_unref_context_ when it is not
3737
needed anymore.
3838
Returns NULL on an error.

liblastlog2/man/ll2_read_all.3.adoc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ Returns 0 on success, -ENOMEM or -1 on other failure.
4646
_error_ contains an error string if the return value is -1.
4747
_error_ is not guaranteed to contain an error string, could also be NULL.
4848
_error_ should be freed by the caller.
49-
If lastlog2 database does not exist at all, the errno ENOENT has been set
49+
If lastlog2 database does not exist at all, the errno ENOENT is set
5050
and can be checked.
5151

5252
== AUTHORS

liblastlog2/man/ll2_read_entry.3.adoc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ Returns 0 on success, -ENOMEM or -1 on other failure.
4242
_error_ contains an error string if the return value is -1.
4343
_error_ is not guaranteed to contain an error string, could also be NULL.
4444
_error_ should be freed by the caller.
45-
If lastlog2 database does not exist at all, the errno ENOENT has been set
45+
If lastlog2 database does not exist at all, the errno ENOENT is set
4646
and can be checked.
4747

4848
The evaluated values are returned by _ll_time_, _tty_, _rhost_ and _pam_service_.

liblastlog2/man/ll2_remove_entry.3.adoc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99

1010
== NAME
1111

12-
ll2_remove_entry - Remove all entries of an user.
12+
ll2_remove_entry - Removes all entries of a user.
1313

1414
== SYNOPSIS
1515

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

2121
== DESCRIPTION
2222

23-
Removing all database entries, defined in _context_, with the user name _user_.
23+
Removes all database entries, defined in _context_, with the user name _user_.
2424
If _context_ is NULL, the default database, defined in _LL2_DEFAULT_DATABASE_,
2525
will be taken.
2626

liblastlog2/man/ll2_rename_user.3.adoc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99

1010
== NAME
1111

12-
ll2_rename_user - Renames an user entry.
12+
ll2_rename_user - Renames a user entry.
1313

1414
== SYNOPSIS
1515

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

2121
== DESCRIPTION
2222

23-
Changing user name from _user_ to _newname_ of one entry in
23+
Changes user name from _user_ to _newname_ of one entry in
2424
database, which is defined by _context_. All other entries with the user _user_
2525
will be deleted.
2626
If _context_ is NULL, the default database, defined in _LL2_DEFAULT_DATABASE_,

liblastlog2/man/ll2_unref_context.3.adoc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99

1010
== NAME
1111

12-
ll2_unref_context - Freeing lastlog2 context.
12+
ll2_unref_context - Frees lastlog2 context.
1313

1414
== SYNOPSIS
1515

@@ -19,7 +19,7 @@ ll2_unref_context - Freeing lastlog2 context.
1919

2020
== DESCRIPTION
2121

22-
Freeing lastlog2 context, which has been generated by
22+
Frees lastlog2 context, which has been allocated by
2323
_ll2_new_context_.
2424

2525
--------------------------------------

liblastlog2/man/ll2_update_login_time.3.adoc

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99

1010
== NAME
1111

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

1414
== SYNOPSIS
1515

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

2222
== DESCRIPTION
2323

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

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

4545
== AUTHORS

liblastlog2/man/ll2_write_entry.3.adoc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99

1010
== NAME
1111

12-
ll2_write_entry - Write a new entry into the database.
12+
ll2_write_entry - Writes a new entry into the database.
1313

1414
== SYNOPSIS
1515

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

2323
== DESCRIPTION
2424

25-
Writes an new entry into database, which is defined in _context_.
25+
Writes a new entry into database, which is defined in _context_.
2626
If _context_ is NULL, the default database, defined in _LL2_DEFAULT_DATABASE_,
2727
will be taken.
2828

liblastlog2/src/lastlog2.c

Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@
3939
#include "lastlog2P.h"
4040
#include "strutils.h"
4141

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

64-
/* Release ll2 context/environment */
64+
/* Releases ll2 context/environment. */
6565
extern void ll2_unref_context(struct ll2_context *context)
6666
{
6767
if (context)
@@ -206,7 +206,8 @@ read_entry(sqlite3 *db, const char *user,
206206
return retval;
207207
}
208208

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

228-
/* Write a new entry. Returns 0 on success, -ENOMEM or -1 on other failure. */
229+
/* Writes a new entry.
230+
Returns 0 on success, -ENOMEM or -1 on other failure. */
229231
static int
230232
write_entry(sqlite3 *db, const char *user,
231233
int64_t ll_time, const char *tty, const char *rhost,
@@ -324,7 +326,8 @@ write_entry(sqlite3 *db, const char *user,
324326
return retval;
325327
}
326328

327-
/* Write a new entry. Returns 0 on success, -ENOMEM or -1 on other failure. */
329+
/* Writes a new entry.
330+
Returns 0 on success, -ENOMEM or -1 on other failure. */
328331
int
329332
ll2_write_entry(struct ll2_context *context, const char *user,
330333
int64_t ll_time, const char *tty, const char *rhost,
@@ -343,7 +346,7 @@ ll2_write_entry(struct ll2_context *context, const char *user,
343346
return retval;
344347
}
345348

346-
/* Write a new entry with updated login time.
349+
/* Writes a new entry with updated login time.
347350
Returns 0 on success, -ENOMEM or -1 on other failure. */
348351
int
349352
ll2_update_login_time(struct ll2_context *context, const char *user,
@@ -409,7 +412,7 @@ ll2_read_all(struct ll2_context *context,
409412
char **error)
410413
{
411414
sqlite3 *db;
412-
char *err_msg = 0;
415+
char *err_msg = NULL;
413416
int retval = 0;
414417

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

434-
/* Remove an user entry. Returns 0 on success, -ENOMEM or -1 on other failure. */
437+
/* Removes a user entry.
438+
Returns 0 on success, -ENOMEM or -1 on other failure. */
435439
static int
436440
remove_entry(sqlite3 *db, const char *user, char **error)
437441
{
@@ -480,7 +484,8 @@ remove_entry(sqlite3 *db, const char *user, char **error)
480484
return retval;
481485
}
482486

483-
/* Remove an user entry. Returns 0 on success, -ENOMEM or -1 on other failure. */
487+
/* Removes a user entry.
488+
Returns 0 on success, -ENOMEM or -1 on other failure. */
484489
int
485490
ll2_remove_entry(struct ll2_context *context, const char *user,
486491
char **error)
@@ -498,7 +503,8 @@ ll2_remove_entry(struct ll2_context *context, const char *user,
498503
return retval;
499504
}
500505

501-
/* Renames an user entry. Returns 0 on success, -ENOMEM or -1 on other failure. */
506+
/* Renames a user entry.
507+
Returns 0 on success, -ENOMEM or -1 on other failure. */
502508
int
503509
ll2_rename_user(struct ll2_context *context, const char *user,
504510
const char *newname, char **error)
@@ -536,7 +542,7 @@ ll2_rename_user(struct ll2_context *context, const char *user,
536542
return retval;
537543
}
538544

539-
/* Import old lastlog file.
545+
/* Imports old lastlog file.
540546
Returns 0 on success, -ENOMEM or -1 on other failure. */
541547
int
542548
ll2_import_lastlog(struct ll2_context *context, const char *lastlog_file,

misc-utils/lastlog2.8.adoc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ This file may be copied under the terms of the GNU General Public License.
1212

1313
== NAME
1414

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

1717
== SYNOPSIS
1818

pam_lastlog2/src/pam_lastlog2.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -189,6 +189,8 @@ write_login_data (pam_handle_t *pamh, int ctrl, const char *user)
189189
return PAM_SYSTEM_ERR;
190190

191191
struct ll2_context *context = ll2_new_context(lastlog2_path);
192+
if (context == NULL)
193+
return PAM_SYSTEM_ERR;
192194
if (ll2_write_entry (context, user, ll_time, tty, rhost,
193195
pam_service, &error) != 0) {
194196
if (error) {
@@ -220,6 +222,8 @@ show_lastlogin (pam_handle_t *pamh, int ctrl, const char *user)
220222
return retval;
221223

222224
struct ll2_context *context = ll2_new_context(lastlog2_path);
225+
if (context == NULL)
226+
return PAM_SYSTEM_ERR;
223227
if (ll2_read_entry (context, user, &ll_time, &tty, &rhost,
224228
&service, &error) != 0) {
225229
if (errno == ENOENT)

0 commit comments

Comments
 (0)