Skip to content

Commit

Permalink
Make wtmpdbd support compiletime config
Browse files Browse the repository at this point in the history
  • Loading branch information
thkukuk committed Dec 16, 2024
1 parent 1caf255 commit 9a7ffcd
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 15 deletions.
16 changes: 15 additions & 1 deletion lib/libwtmpdb.c
Original file line number Diff line number Diff line change
Expand Up @@ -25,16 +25,21 @@
POSSIBILITY OF SUCH DAMAGE.
*/

#include "config.h"

#include <errno.h>
#include <stddef.h>
#include <stdlib.h>

#include "basics.h"
#include "wtmpdb.h"
#include "sqlite.h"

#if WITH_WTMPDBD
#include "varlink.h"

static int varlink_is_active = 1;
#endif

/*
Add new wtmp entry to db.
Expand All @@ -46,6 +51,7 @@ wtmpdb_login (const char *db_path, int type, const char *user,
uint64_t usec_login, const char *tty, const char *rhost,
const char *service, char **error)
{
#if WITH_WTMPDBD
/* we can use varlink only if no specific database is requested */
if (varlink_is_active && db_path == NULL)
{
Expand All @@ -64,7 +70,7 @@ wtmpdb_login (const char *db_path, int type, const char *user,
else
return id; /* return the error if wtmpdbd is active */
}

#endif
return sqlite_login (db_path?db_path:_PATH_WTMPDB, type, user,
usec_login, tty, rhost, service, error);
}
Expand All @@ -79,6 +85,7 @@ int
wtmpdb_logout (const char *db_path, int64_t id, uint64_t usec_logout,
char **error)
{
#if WITH_WTMPDBD
/* we can use varlink only if no specific database is requested */
if (varlink_is_active && db_path == NULL)
{
Expand All @@ -96,13 +103,15 @@ wtmpdb_logout (const char *db_path, int64_t id, uint64_t usec_logout,
else
return r; /* return the error if wtmpdbd is active */
}
#endif

return sqlite_logout (db_path?db_path:_PATH_WTMPDB, id, usec_logout, error);
}

int64_t
wtmpdb_get_id (const char *db_path, const char *tty, char **error)
{
#if WITH_WTMPDBD
/* we can use varlink only if no specific database is requested */
if (varlink_is_active && db_path == NULL)
{
Expand All @@ -120,6 +129,7 @@ wtmpdb_get_id (const char *db_path, const char *tty, char **error)
else
return id; /* return the error if wtmpdbd is active */
}
#endif

return sqlite_get_id (db_path?db_path:_PATH_WTMPDB, tty, error);
}
Expand Down Expand Up @@ -153,6 +163,7 @@ int
wtmpdb_rotate (const char *db_path, const int days, char **error,
char **wtmpdb_name, uint64_t *entries)
{
#if WITH_WTMPDBD
/* we can use varlink only if no specific database is requested */
if (varlink_is_active && db_path == NULL)
{
Expand All @@ -170,6 +181,7 @@ wtmpdb_rotate (const char *db_path, const int days, char **error,
else
return r; /* return the error if wtmpdbd is active */
}
#endif

return sqlite_rotate (db_path?db_path:_PATH_WTMPDB, days, wtmpdb_name, entries, error);
}
Expand All @@ -178,6 +190,7 @@ wtmpdb_rotate (const char *db_path, const int days, char **error,
uint64_t
wtmpdb_get_boottime (const char *db_path, char **error)
{
#if WITH_WTMPDBD
/* we can use varlink only if no specific database is requested */
if (varlink_is_active && db_path == NULL)
{
Expand All @@ -196,6 +209,7 @@ wtmpdb_get_boottime (const char *db_path, char **error)
else
return 0; /* return the error if wtmpdbd is active */
}
#endif

return sqlite_get_boottime (db_path?db_path:_PATH_WTMPDB, error);
}
2 changes: 1 addition & 1 deletion lib/varlink.c
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@

#include "config.h"

#if HAVE_SYSTEMD
#if WITH_WTMPDBD

#include <stdlib.h>
#include <stdbool.h>
Expand Down
42 changes: 29 additions & 13 deletions meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ project(
'default_library=shared',
'b_pie=true',
'b_lto=true',
'warning_level=3',],
license : ['BSD-2-Clause',],
'warning_level=2'],
license : ['BSD-2-Clause'],
version : '0.50.0',
)

Expand Down Expand Up @@ -103,14 +103,28 @@ else
endif
conf.set10('HAVE_AUDIT', have_audit)

want_systemd = get_option('systemd')
if want_systemd != 'false'
libsystemd = dependency('libsystemd', required : want_systemd == 'true')
have_systemd = libsystemd.found()
want_wtmpdbd = get_option('wtmpdbd')
if want_wtmpdbd != 'false'
libsystemd = dependency('libsystemd', version: '>= 257', required : want_wtmpdbd == 'true')
have_systemd257 = libsystemd.found()
else
have_systemd = false
have_systemd257 = false
libsystemd = []
endif
conf.set10('WITH_WTMPDBD', have_systemd257)

want_systemd = get_option('systemd')
if have_systemd257 == false
if want_systemd != 'false'
libsystemd = dependency('libsystemd', required : want_systemd == 'true')
have_systemd = libsystemd.found()
else
have_systemd = false
libsystemd = []
endif
else
have_systemd = true
endif
conf.set10('HAVE_SYSTEMD', have_systemd)

libwtmpdb_c = files('lib/libwtmpdb.c', 'lib/logwtmpdb.c', 'lib/sqlite.c', 'lib/varlink.c', 'lib/mkdir_p.c')
Expand Down Expand Up @@ -158,12 +172,14 @@ pam_wtmpdb = shared_library(
wtmpdb_c = ['src/wtmpdb.c']
wtmpdbd_c = ['src/wtmpdbd.c', 'src/varlink-org.openSUSE.wtmpdb.c', 'lib/mkdir_p.c']

executable('wtmpdbd',
wtmpdbd_c,
include_directories : inc,
link_with : libwtmpdb,
dependencies : [libsystemd],
install : true)
if have_systemd257
executable('wtmpdbd',
wtmpdbd_c,
include_directories : inc,
link_with : libwtmpdb,
dependencies : [libsystemd],
install : true)
endif

executable('wtmpdb',
wtmpdb_c,
Expand Down
3 changes: 3 additions & 0 deletions meson_options.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
option('wtmpdbd', type : 'combo', choices : ['auto', 'true', 'false'],
value : 'auto',
description : 'build daemon with sd-varlink support')
option('split-usr', type : 'combo', choices : ['auto', 'true', 'false'],
description : '''/bin, /sbin aren't symlinks into /usr''')
option('rootprefix', type : 'string',
Expand Down

0 comments on commit 9a7ffcd

Please sign in to comment.