Tested:
% watch=(all); log
root has logged on /proc/10045/fd/2 from .
Студент has logged on pts/29 from 127.0.0.1.
% watch=(notme); log
root has logged on /proc/10045/fd/2 from .
% watch=(Студент); log
Студент has logged on pts/29 from 127.0.0.1.
Everything works now, thanks
Sent via Gmail
Максим 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;