Closed bibliocar closed 5 months ago
stat was already used in the past, it was changed to ls because stat is not POSIX (and the flag to choose the output format is inconsistent across systems). Maybe a way to avoid this issue would be to add the -n flag to ls, which rather than outputting user names outputs uids, and that can then be compared to the output of something like id -u
, rather than $LOGNAME
?
POSIX states the maximum length of a login name to be 8 (plus NULL terminator).
{_POSIX_LOGIN_NAME_MAX}
The size of the storage required for a login name, in bytes, including the terminating null.
Value: 9
See: https://pubs.opengroup.org/onlinepubs/009696899/basedefs/limits.h.html
Not sure if this is even something worth fixing. Stat cannot be used given @E5ten's explanation above. Will think about it.
Maybe a way to avoid this issue would be to add the -n flag to ls, which rather than outputting user names outputs uids, and that can then be compared to the output of something like id -u, rather than $LOGNAME?
I played around with this (good idea) but we still need the username in "string" form as the $user
variable is
given a value in this function (which is then used in myriad places by callers). ie, some method of converting the
numerical ID to the username untruncated.
Oh, okay! I guess I'll just come up with a shorter username, then. Glad I submitted and learned something new about POSIX!
It's much nicer to see a username stream by in the output than a UID, whatever you end up doing.
Maybe the place to address it is during username creation?
Not that I'm saying this needs fixing in light of that POSIX requirement, but if this was still desired, wouldn't the UID being equal to id -u
guarantee that $LOGNAME
would be the correct username, and then user=$LOGNAME
could just be done after the comparison with id -u
?
If my assumption above about $LOGNAME
being correct if the uid comparison succeeds is wrong, then alternatively a possibility would be doing the uid comparison with plain id
output, with parsing probably going something like this:
output=$(LC_ALL=C id)
uid=${output#*=}
uid=${uid%%')'*}
user=${output#*'('}
user=${user%%')'*}
This is obviously very hacky though, and I don't really have reason to think my $LOGNAME
is wrong yet, and if it isn't then this would be totally unnecessary and undesirable.
Oh, and I forgot about the second conversion of ls to stat for the octal permissions. I think that part is just unnecessary, right? Like doesn't fix a potential problem or anything?
Thanks!! This patch saved my username of logandark
:)
Now just to figure out how to keep the patch through updates...
'ls' truncates usernames containing more than eight characters, making "bibliocar" into "biblioca". I found 'stat' worked in my kiss install without any problems in place of it. I rewrote both functions that used 'ls' to make use of 'stat', instead.
While doing so, I was unsure why:
equ "$LOGNAME/$user" "$user/$LOGNAME"
wasn't:
equ "$user" "$LOGNAME"