From b32d98f7a4a87b4ad20aac21dc83183511748e22 Mon Sep 17 00:00:00 2001 From: Dmitry Baryshkov Date: Wed, 8 Nov 2023 17:16:49 +0300 Subject: [PATCH 1/2] cdba-server: provide fallbacks for the username value We use the CDBA_USER value as a way to pass info from cdba-shell to cdba-server. However if it is not provide (e.g. because the cdba-server is started directly by shell) add a fallback to the system's USER variable. And if that's also not set, provide a safe default of 'nobody'. Signed-off-by: Dmitry Baryshkov --- cdba-server.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/cdba-server.c b/cdba-server.c index c65f606..39ea1d7 100644 --- a/cdba-server.c +++ b/cdba-server.c @@ -356,6 +356,10 @@ int main(int argc, char **argv) signal(SIGPIPE, sigpipe_handler); username = getenv("CDBA_USER"); + if (!username) + username = getenv("USER"); + if (!username) + username = "nobody"; ret = device_parser(".cdba"); if (ret) { From 43ed93357dfd7782d2d36cbd87dc164569d48391 Mon Sep 17 00:00:00 2001 From: Dmitry Baryshkov Date: Wed, 8 Nov 2023 17:15:27 +0300 Subject: [PATCH 2/2] cdba-server: add syslog support Log messages to the syslog when the user opens a board. Signed-off-by: Dmitry Baryshkov --- cdba-server.c | 3 +++ device.c | 9 ++++++++- 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/cdba-server.c b/cdba-server.c index 39ea1d7..425b2b0 100644 --- a/cdba-server.c +++ b/cdba-server.c @@ -38,6 +38,7 @@ #include #include #include +#include #include "cdba-server.h" #include "circ_buf.h" @@ -361,6 +362,8 @@ int main(int argc, char **argv) if (!username) username = "nobody"; + openlog("cdba-server", 0, LOG_DAEMON); + ret = device_parser(".cdba"); if (ret) { ret = device_parser("/etc/cdba"); diff --git a/device.c b/device.c index 95cded8..329cf4f 100644 --- a/device.c +++ b/device.c @@ -39,6 +39,7 @@ #include #include #include +#include #include "cdba-server.h" #include "device.h" @@ -127,11 +128,17 @@ struct device *device_open(const char *board, goto found; } + syslog(LOG_INFO, "user %s asked for non-existing board %s", username, board); return NULL; found: - if (!device_check_access(device, username)) + if (!device_check_access(device, username)) { + syslog(LOG_INFO, "user %s access denied to the board %s", username, board); + return NULL; + } + + syslog(LOG_INFO, "user %s opening board %s", username, board); assert(device->console_ops); assert(device->console_ops->open);