Skip to content

Commit

Permalink
libwtmpdb: set varlink_is_active to 0 without systemd
Browse files Browse the repository at this point in the history
  • Loading branch information
thkukuk committed Jan 8, 2025
1 parent 7479582 commit 5b120a0
Show file tree
Hide file tree
Showing 4 changed files with 68 additions and 4 deletions.
3 changes: 3 additions & 0 deletions NEWS
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
Version 0.50.0
* Introduce wtmpdbd as single daemon accessing the database (#12)

Version 0.13.0
* Fix variable overflow on 32bit systems and check for this (#15)

Expand Down
8 changes: 7 additions & 1 deletion lib/libwtmpdb.c
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,11 @@

#include "varlink.h"

#if WITH_WTMPDBD
static int varlink_is_active = 1;
#else
static int varlink_is_active = 0;
#endif
static int varlink_is_enforced = 0;

#define VARLINK_CHECKS \
Expand Down Expand Up @@ -207,8 +211,10 @@ wtmpdb_read_all_v2 (const char *db_path,
}
else
return r; /* return the error if wtmpdbd is active */
}
#else
return -EPROTONOSUPPORT;
#endif
}

return sqlite_read_all (db_path?db_path:_PATH_WTMPDB, cb_func, userdata, error);
}
Expand Down
53 changes: 53 additions & 0 deletions src/wtmpdbd.c
Original file line number Diff line number Diff line change
Expand Up @@ -620,9 +620,15 @@ static int
run_varlink (void)
{
int r;
#if 0 /* XXX */
_cleanup_(sd_event_unrefp) sd_event *event = NULL;
#if 0
_cleanup_(sd_varlink_server_unrefp) sd_varlink_server *varlink_reader = NULL;
_cleanup_(sd_varlink_server_unrefp) sd_varlink_server *varlink_writer = NULL;
#else
sd_varlink_server *varlink_reader = NULL;
sd_varlink_server *varlink_writer = NULL;
#endif

r = mkdir_p(_VARLINK_WTMPDB_SOCKET_DIR, 0755);
if (r < 0)
Expand Down Expand Up @@ -688,6 +694,53 @@ run_varlink (void)
announce_ready();

r = sd_event_loop (event);
#else
_cleanup_(sd_varlink_server_unrefp) sd_varlink_server *varlink_server = NULL;

/* Invocation as Varlink service */

r = sd_varlink_server_new(&varlink_server, SD_VARLINK_SERVER_INHERIT_USERDATA);
if (r < 0)
{
log_msg(LOG_ERR, "Failed to allocate Varlink server: %s", strerror(-r));
return r;
}

r = sd_varlink_server_add_interface(varlink_server, &vl_interface_org_openSUSE_wtmpdb);
if (r < 0)
{
log_msg(LOG_ERR, "Failed to add Varlink interface: %s", strerror(-r));
return r;
}

r = sd_varlink_server_bind_method_many (varlink_server,
"org.openSUSE.wtmpdb.GetBootTime", vl_method_get_boottime,
"org.openSUSE.wtmpdb.GetID", vl_method_get_id,
"org.openSUSE.wtmpdb.ReadAll", vl_method_read_all);
if (r < 0)
{
log_msg(LOG_ERR, "Failed to bind Varlink methods: %s",
strerror(-r));
return r;
}

r = sd_varlink_server_listen_address(varlink_server, _VARLINK_WTMPDB_SOCKET_READER, 0666);
if (r < 0)
{
log_msg (LOG_ERR, "Failed to bind to Varlink socket (reader): %s", strerror (-r));
return r;
}

announce_ready();

r = sd_varlink_server_loop_auto(varlink_server);
if (r < 0)
{
log_msg(LOG_ERR, "Failed to run Varlink event loop: %s", strerror(-r));
return r;
}

#endif

announce_stopping();

Expand Down
8 changes: 5 additions & 3 deletions tests/meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

libdl = cc.find_library('dl')


tst_dlopen_exe = executable('tst-dlopen', 'tst-dlopen.c', dependencies : libdl)
test('tst-dlopen', tst_dlopen_exe, args : ['pam_wtmpdb.so'])

Expand All @@ -14,10 +13,14 @@ tst_logwtmpdb = executable ('tst-logwtmpdb', 'tst-logwtmpdb.c',
link_with : libwtmpdb)
test('tst-logwtmpdb', tst_logwtmpdb)

tst_login_logout = executable ('tst-login-logout', 'tst-login-logout.c',
tst_login_logout = executable ('tst-login-logout', 'tst-login-logout.c',
include_directories : inc,
link_with : libwtmpdb)
test('tst-login-logout', tst_login_logout)
tst_login_logout2 = executable ('tst-login-logout2', 'tst-login-logout2.c',
include_directories : inc,
link_with : libwtmpdb)
test('tst-login-logout2', tst_login_logout2)

tst_get_id = executable ('tst-get_id', 'tst-get_id.c',
include_directories : inc,
Expand All @@ -28,4 +31,3 @@ tst_varlink = executable ('tst-varlink', 'tst-varlink.c',
include_directories : inc,
link_with : libwtmpdb)
test('tst-varlink', tst_varlink)

0 comments on commit 5b120a0

Please sign in to comment.