zsh-workers
 help / color / mirror / code / Atom feed
From: Oliver Kiddle <opk@zsh.org>
To: Максим <herobrine135111@gmail.com>
Cc: zsh-workers@zsh.org
Subject: Re: $watch, log and Cyrillic usernames
Date: Sun, 08 Oct 2023 02:24:26 +0200	[thread overview]
Message-ID: <4465-1696724666.376518@Uh7s.ZzUp.FcHY> (raw)
In-Reply-To: <CAHJ=x4bJMREcasAK_CdR7qd9uKH8NgT-_qxXimEb3EADNZzOkw@mail.gmail.com>

Максим wrote:
> Found out that there is no need in bypassing "adduser", as this command works
> just fine:

These utilities can be quite distribution specific. There is no adduser
command on my system but the old manual approach is always possible. I
also looked into how last is able to print longer usernames and it's
using sqlite and a library for access. The 32 char limit is specific to
the getutxent() interface and could be different on other systems.

> % watch=(notme); log # Broken
>     root has logged on /proc/10045/fd/2 from .
>     Студент has logged on pts/29 from 127.0.0.1.

Thanks for testing. "notme" is handled separately and the patch below
should be applied on top of the previous one.

The w++ line is a minor change from the old behaviour - moving on from
a notme entry. An alternative would be to move the return from just
above to that line.

The code is arguably now wasting time and memory metafying the same
strings multiple times. We could convert the whole utmp structure
up-front. Not sure that's worth the bother, though (?).

Oliver

diff --git a/Src/Modules/watch.c b/Src/Modules/watch.c
index 2ad962fb6..d30f5ff98 100644
--- a/Src/Modules/watch.c
+++ b/Src/Modules/watch.c
@@ -458,10 +458,14 @@ watchlog(int inout, WATCH_STRUCT_UTMP *u, char **w, char *fmt)
 	(void)watchlog2(inout, u, fmt, 1, 0);
 	return;
     }
-    if (*w && !strcmp(*w, "notme") &&
-	strncmp(u->ut_name, get_username(), sizeof(u->ut_name))) {
-	(void)watchlog2(inout, u, fmt, 1, 0);
-	return;
+    if (*w && !strcmp(*w, "notme")) {
+        char *username = metafy(u->ut_name,
+		strnlen(u->ut_name, sizeof(u->ut_name)), META_USEHEAP);
+	if (strcmp(username, get_username())) {
+	    (void)watchlog2(inout, u, fmt, 1, 0);
+	    return;
+	}
+	w++;
     }
     for (; *w; w++) {
 	bad = 0;


  reply	other threads:[~2023-10-08  0:24 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-10-05 21:29 Максим
2023-10-05 21:42 ` Bart Schaefer
2023-10-07  2:05 ` Oliver Kiddle
2023-10-07 16:49   ` Максим
2023-10-08  0:24     ` Oliver Kiddle [this message]
2023-10-08  6:20       ` Максим
2023-10-08 21:47   ` metafy() (was Re: $watch, log and Cyrillic usernames) Oliver Kiddle
2023-10-09  2:01     ` Bart Schaefer
2023-10-10 21:46       ` Oliver Kiddle

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=4465-1696724666.376518@Uh7s.ZzUp.FcHY \
    --to=opk@zsh.org \
    --cc=herobrine135111@gmail.com \
    --cc=zsh-workers@zsh.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/zsh/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).