From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on inbox.vuxu.org X-Spam-Level: X-Spam-Status: No, score=-3.4 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,MAILING_LIST_MULTI,RCVD_IN_DNSWL_MED autolearn=ham autolearn_force=no version=3.4.4 Received: (qmail 26061 invoked from network); 8 Oct 2023 00:24:48 -0000 Received: from zero.zsh.org (2a02:898:31:0:48:4558:7a:7368) by inbox.vuxu.org with ESMTPUTF8; 8 Oct 2023 00:24:48 -0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=zsh.org; s=rsa-20210803; h=List-Archive:List-Owner:List-Post:List-Unsubscribe: List-Subscribe:List-Help:List-Id:Sender:Message-ID:Date: Content-Transfer-Encoding:Content-ID:Content-Type:MIME-Version:Subject:To: References:From:In-reply-to:cc:Reply-To:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID; bh=PbuJeLeltkWvl7YAA2DxjCVBICHqprVf/aufBsue5xk=; b=G6xS3Esa6tVeTL9s+lZfY8ZyCS Q8XipPvdPZ8zVkIujDP5HoDBJ72AtQEwA8RUFbFLkvjmP4qyeOpkOxu2cJmxZslfvLbuv2OgH8AE5 7WpqjvAOzhlqcRDlcYQhnSU++SCuk0vzCt0oTIc7O/hXt81lhTvLFRjW7WNwtI65K0pNat1/Usw+s ie6HOMikO0v/2ysOqDBH7EDp1iAfD0w4Lo/Hb//CeZZysiN/WEawyIgRWD3VqbrutgYE8bAQY3n8w NuuwmqOiKYXV6FCnp/XHjm6JZl2K6mPFkKMq8FHALzx8Op65BDxjNY2epO1uxvj6A4PljP6q8sKFQ a4HtsVEg==; Received: by zero.zsh.org with local id 1qpHbB-000KN0-De; Sun, 08 Oct 2023 00:24:45 +0000 Received: by zero.zsh.org with esmtpsa (TLS1.3:TLS_AES_256_GCM_SHA384:256) id 1qpHat-000K3t-OL; Sun, 08 Oct 2023 00:24:28 +0000 Received: from [192.168.178.21] (helo=hydra) by mail.kiddle.eu with esmtp(Exim 4.95) (envelope-from ) id 1qpHas-0001A2-CF; Sun, 08 Oct 2023 02:24:26 +0200 cc: zsh-workers@zsh.org In-reply-to: From: Oliver Kiddle References: <51326-1696644317.959346@Oqom.p2Z_.86FS> To: =?UTF-8?B?0JzQsNC60YHQuNC8?= Subject: Re: $watch, log and Cyrillic usernames MIME-Version: 1.0 Content-Type: text/plain; charset="UTF-8" Content-ID: <4464.1696724666.1@hydra> Content-Transfer-Encoding: 8bit Date: Sun, 08 Oct 2023 02:24:26 +0200 Message-ID: <4465-1696724666.376518@Uh7s.ZzUp.FcHY> X-Seq: 52211 Archived-At: X-Loop: zsh-workers@zsh.org Errors-To: zsh-workers-owner@zsh.org Precedence: list Precedence: bulk Sender: zsh-workers-request@zsh.org X-no-archive: yes List-Id: List-Help: , List-Subscribe: , List-Unsubscribe: , List-Post: List-Owner: List-Archive: Максим 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;