Hi,
Brian told me that the printout of client's username has a limit of 8 characters
and as this is frequently too little for grid-username-slots I decided to have
to look into it.
So, I traced it down to usege of cuserid() in XrdClient/XrdClientSock.cc:487,
function:
int XrdClientSock::Socks4Handshake(int sockid);
This function always returns at most L_cuserid - 1 characters, which is 8. So,
the username is truncated already in client, during handshake.
Here's what GNU manpage says about cuserid():
Nobody knows precisely what cuserid() does; avoid it in portable pro-
grams. Or avoid it altogether: use getpwuid(geteuid()) instead, if
that is what you meant. Do not use cuserid().
I played with this a bit on my machine, mini program attached. That's what I get
with a specially created username: :)
[root@greed tmp]# sudo -u alongusername666 ./xxx
getlogin='matevz'; _r='matevz', ret=0
cuserid='alonguse'
getpwuid='alongusername666' -- 0x7fff7513b2c0 vs 0x7fff7513b2c0
I can provide a patch using getpwuid(geteuid()) ... but can't really test it on
anything but GNU/Linux.
Cheers,
Matevz
/*
gcc xxx.c -o xxx
*/
#include <stdio.h>
#include <unistd.h>
#include <pwd.h>
int main()
{
char buf[64];
int ret = getlogin_r(buf, sizeof(buf));
printf("getlogin='%s'; _r='%s', ret=%d\n",
getlogin(), buf, ret);
char cbuf[64];
cuserid(cbuf); /* return value seems random ?? */
printf("cuserid='%s'\n", cbuf);
uid_t id = geteuid();
struct passwd pwd, *ppwd;
char bufbuf[1024];
int pret = getpwuid_r(id, &pwd, bufbuf, sizeof(bufbuf), &ppwd);
printf("getpwuid='%s' -- %p vs %p\n", ppwd->pw_name, &pwd, ppwd);
return 0;
}
|