Hi there, I'm using samba-2.2.2 under Solaris 8 and I've got the following problem! I have configured samba with "--with-utmp" and with "--with-quota" and everything works fine. But when look for the last users logged in, in the utmp-database there are only the first seven letters of the username, not eight that we use for usernames. Can you help me with this problem please thank you Joerg Bensch +++++++++++++++++++++++++++++++++++++++++++ + J?rg Bensch + + Rechenzentrum Universit?t Hildesheim + + Marienburger Platz 22, 31141 Hildesheim + + Tel: +49 (0)5121 833-215 Fax: -205 + +++++++++++++++++++++++++++++++++++++++++++
TAKAHASHI Motonobu
2001-Dec-01 05:50 UTC
[patch] utmp ut_name length fix (Problems with utmp)
Joerg Bensch wrote:>I'm using samba-2.2.2 under Solaris 8 and I've got the following problem! > >I have configured samba with "--with-utmp" and with "--with-quota" and >everything works fine. But when look for the last users logged in, in the >utmp-database there are only the first seven letters of the username, not >eight that we use for usernames.Samba 2.2.2 truncates the utmp ut_user to max 7 bytes. Though the user name area of utmp is defined as ut_user[8], it seems to be allowed to use all 8 bytes to store an user name. /* any one knows the problems to use all 8 bytes? */ Here is the patch to fix this problem. safe_strcpy() cannot be used because it assumes an ASCIZ string. Solaris has actually utmpx only, which allows max 32bytes in username area. So the best way is that if the system has utmpx, use its feature. --- utmp.c.org Sat Jun 16 02:06:06 2001 +++ utmp.c Sat Dec 1 22:24:08 2001 @@ -368,6 +368,22 @@ } } +/* + copy a string in the utmp structure +*/ +static void utmp_strcpy(char *dest, const char *src, int n) +{ + int len; + + len = strlen(src); + if (len >= n) { + memcpy(dest, src, n); + } else { + memcpy(dest, src, len); + memset(dest + len, '\0', n - len); + } +} + /**************************************************************************** Update via utmpx/wtmpx (preferred) or via utmp/wtmp ****************************************************************************/ @@ -394,7 +410,7 @@ if (hostname) ux.ut_syslen = strlen(hostname) + 1; /* include end NULL */ else ux.ut_syslen = 0; #endif - safe_strcpy(ux.ut_host, hostname, sizeof(ux.ut_host)-1); + utmp_strcpy(ux.ut_host, hostname, sizeof(ux.ut_host)); uw_pathname(uname, "utmpx", ux_pathname); uw_pathname(wname, "wtmpx", wx_pathname); @@ -467,9 +483,9 @@ * rather than to try to detect and optimise. */ #if defined(HAVE_UT_UT_USER) - safe_strcpy(u->ut_user, username, sizeof(u->ut_user)-1); + utmp_strcpy(u->ut_user, username, sizeof(u->ut_user)); #elif defined(HAVE_UT_UT_NAME) - safe_strcpy(u->ut_name, username, sizeof(u->ut_name)-1); + utmp_strcpy(u->ut_name, username, sizeof(u->ut_name)); #endif /* @@ -485,7 +501,7 @@ id_str, sizeof(u->ut_line))); return False; } - memcpy(u->ut_line, id_str, sizeof(u->ut_line)); + utmp_strcpy(u->ut_line, id_str, sizeof(u->ut_line)); #if defined(HAVE_UT_UT_PID) u->ut_pid = sys_getpid(); @@ -508,7 +524,7 @@ #endif #if defined(HAVE_UT_UT_HOST) - safe_strcpy(u->ut_host, hostname, sizeof(u->ut_host)-1); + utmp_strcpy(u->ut_host, hostname, sizeof(u->ut_host)); #endif #if defined(HAVE_UT_UT_ADDR) ----- TAKAHASHI, Motonobu(monyo) monyo@samba.org Samba Team - http://samba.org/ Samba-JP - http://www.samba.gr.jp/ JWNTUG - http://www.jwntug.or.jp/ Analog-JP - http://www.jp.analog.cx/ MCSE(NT40,W2K), SCNA, CCNA, Turbo-CI