Debian Codegraph @

liblastlog2/src/lastlog2.h.in

raw
1 /* SPDX-License-Identifier: BSD-2-Clause
2
3 Copyright (c) 2023, Thorsten Kukuk <[email protected]>
4
5 Redistribution and use in source and binary forms, with or without
6 modification, are permitted provided that the following conditions are met:
7
8 1. Redistributions of source code must retain the above copyright notice,
9 this list of conditions and the following disclaimer.
10
11 2. Redistributions in binary form must reproduce the above copyright
12 notice, this list of conditions and the following disclaimer in the
13 documentation and/or other materials provided with the distribution.
14
15 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
16 AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
17 IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
18 ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
19 LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
20 CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
21 SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
22 INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
23 CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
24 ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
25 POSSIBILITY OF SUCH DAMAGE.
26 */
27
28 #ifndef _LIBLASTLOG2_H
29 #define _LIBLASTLOG2_H
30
31 #ifdef __cplusplus
32 extern "C" {
33 #endif
34
35 #define LIBLASTLOG2_VERSION "@LIBLASTLOG2_VERSION@"
36 #define LIBLASTLOG2_MAJOR_VERSION @LIBLASTLOG2_MAJOR_VERSION@
37 #define LIBLASTLOG2_MINOR_VERSION @LIBLASTLOG2_MINOR_VERSION@
38 #define LIBLASTLOG2_PATCH_VERSION @LIBLASTLOG2_PATCH_VERSION@
39
40 #define LL2_DEFAULT_DATABASE _PATH_LOCALSTATEDIR "/lib/lastlog/lastlog2.db"
41
42 #include <stdint.h>
43
44 struct ll2_context;
45
46 /* Set the ll2 context/environment */
47 /* Returns the context or NULL if an error has happened. */
48 extern struct ll2_context * ll2_new_context(const char *db_path);
49
50 /* Release ll2 context/environment */
51 extern void ll2_unref_context(struct ll2_context *context);
52
53 /* Writes a new entry. Returns 0 on success, -ENOMEM or -1 on other failure. */
54 extern int ll2_write_entry (struct ll2_context *context, const char *user,
55 int64_t ll_time, const char *tty,
56 const char *rhost, const char *pam_service,
57 char **error);
58
59 /* Calling a defined function for each entry. Returns 0 on success, -ENOMEM or -1 on other failure. */
60 extern int ll2_read_all (struct ll2_context *context,
61 int (*callback)(const char *user, int64_t ll_time,
62 const char *tty, const char *rhost,
63 const char *pam_service, const char *cb_error),
64 char **error);
65
66 /* Reads one entry from database and returns that.
67 Returns 0 on success, -ENOMEM or -1 on other failure. */
68 extern int ll2_read_entry (struct ll2_context *context, const char *user,
69 int64_t *ll_time, char **tty, char **rhost,
70 char **pam_service, char **error);
71
72 /* Write a new entry with updated login time.
73 Returns 0 on success, -ENOMEM or -1 on other failure. */
74 extern int ll2_update_login_time (struct ll2_context *context,
75 const char *user, int64_t ll_time,
76 char **error);
77
78 /* Remove an user entry. Returns 0 on success, -ENOMEM or -1 on other failure. */
79 extern int ll2_remove_entry (struct ll2_context *context, const char *user,
80 char **error);
81
82 /* Renames an user entry. Returns 0 on success, -ENOMEM or -1 on other failure. */
83 extern int ll2_rename_user (struct ll2_context *context, const char *user,
84 const char *newname, char **error);
85
86
87 /* Import old lastlog file.
88 Returns 0 on success, -ENOMEM or -1 on other failure. */
89 extern int ll2_import_lastlog (struct ll2_context *context,
90 const char *lastlog_file, char **error);
91
92 #ifdef __cplusplus
93 }
94 #endif
95
96 #endif /* _LIBLASTLOG2_H */