shared/utmp-wtmp: pass information if entry is local to filter function
authorZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>
Tue, 31 May 2022 13:10:18 +0000 (15:10 +0200)
committerZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>
Tue, 31 May 2022 13:54:16 +0000 (15:54 +0200)
This just adds an unused parameter for future use. No change in
behaviour.

src/login/logind-utmp.c
src/login/logind.h
src/shared/utmp-wtmp.c
src/shared/utmp-wtmp.h
src/tty-ask-password-agent/tty-ask-password-agent.c

index 1db5050c3b6eb25eabece99cace57ce5a62b2510..ccea8f968f9f473ad5df7950f2bf30cd6305c73d 100644 (file)
@@ -42,7 +42,7 @@ _const_ static usec_t when_wall(usec_t n, usec_t elapse) {
         return left % USEC_PER_HOUR;
 }
 
-bool logind_wall_tty_filter(const char *tty, void *userdata) {
+bool logind_wall_tty_filter(const char *tty, bool is_local, void *userdata) {
         Manager *m = userdata;
         const char *p;
 
index 2136486c60efcc7025f0fa86f9e8b530a74e42c0..27f9e9729fc91503c63becb560aceaccd2fcd5e0 100644 (file)
@@ -180,6 +180,6 @@ CONFIG_PARSER_PROTOTYPE(config_parse_n_autovts);
 CONFIG_PARSER_PROTOTYPE(config_parse_tmpfs_size);
 
 int manager_setup_wall_message_timer(Manager *m);
-bool logind_wall_tty_filter(const char *tty, void *userdata);
+bool logind_wall_tty_filter(const char *tty, bool is_local, void *userdata);
 
 int manager_read_efi_boot_loader_entries(Manager *m);
index f2f53380adfbf8e9c716e81152973589f3520a44..c7e89ba6a6a39498e6de69601db20d0141476f65 100644 (file)
@@ -337,7 +337,7 @@ int utmp_wall(
         const char *message,
         const char *username,
         const char *origin_tty,
-        bool (*match_tty)(const char *tty, void *userdata),
+        bool (*match_tty)(const char *tty, bool is_local, void *userdata),
         void *userdata) {
 
         _unused_ _cleanup_(utxent_cleanup) bool utmpx = false;
@@ -381,17 +381,20 @@ int utmp_wall(
                 if (u->ut_type != USER_PROCESS || u->ut_user[0] == 0)
                         continue;
 
-                /* this access is fine, because STRLEN("/dev/") << 32 (UT_LINESIZE) */
+                /* This access is fine, because strlen("/dev/") < 32 (UT_LINESIZE) */
                 if (path_startswith(u->ut_line, "/dev/"))
                         path = u->ut_line;
                 else {
                         if (asprintf(&buf, "/dev/%.*s", (int) sizeof(u->ut_line), u->ut_line) < 0)
                                 return -ENOMEM;
-
                         path = buf;
                 }
 
-                if (!match_tty || match_tty(path, userdata)) {
+                /* It seems that the address field is always set for remote logins.
+                 * For local logins and other local entries, we get [0,0,0,0]. */
+                bool is_local = memeqzero(u->ut_addr_v6, sizeof(u->ut_addr_v6));
+
+                if (!match_tty || match_tty(path, is_local, userdata)) {
                         q = write_to_terminal(path, text);
                         if (q < 0)
                                 r = q;
index 3e71f76b27dbdc3ec15473908e48f71db2d02436..36e4203b4f7dd704a15eec21b15e1cb74f734104 100644 (file)
@@ -23,7 +23,7 @@ int utmp_wall(
         const char *message,
         const char *username,
         const char *origin_tty,
-        bool (*match_tty)(const char *tty, void *userdata),
+        bool (*match_tty)(const char *tty, bool is_local, void *userdata),
         void *userdata);
 
 static inline bool utxent_start(void) {
index 09835ca90369ab767a9c7eb920d4ca2cca428a5e..b7d279cc22c632f2242a7d6642b064fea55dbe3c 100644 (file)
@@ -94,7 +94,7 @@ static int send_passwords(const char *socket_name, char **passwords) {
         return (int) n;
 }
 
-static bool wall_tty_match(const char *path, void *userdata) {
+static bool wall_tty_match(const char *path, bool is_local, void *userdata) {
         _cleanup_free_ char *p = NULL;
         _cleanup_close_ int fd = -1;
         struct stat st;