Bug 2489 - utmp hostname logging on Solaris 9
Summary: utmp hostname logging on Solaris 9
Status: RESOLVED FIXED
Alias: None
Product: Samba 4.1 and newer
Classification: Unclassified
Component: Other (show other bugs)
Version: 4.9.4
Hardware: Sparc Solaris
: P3 normal (vote)
Target Milestone: 4.10
Assignee: Andrew Bartlett
QA Contact: Samba QA Contact
URL:
Keywords:
: 4743 (view as bug list)
Depends on:
Blocks:
 
Reported: 2005-03-18 13:36 UTC by Adam Copeland (mail address dead)
Modified: 2019-01-11 08:26 UTC (History)
1 user (show)

See Also:


Attachments
Portable patch which detects and corrects usage of ut_host in utmpx (1.64 KB, patch)
2007-07-12 10:51 UTC, David Gajewski
no flags Details

Note You need to log in before you can comment on or make changes to this bug.
Description Adam Copeland (mail address dead) 2005-03-18 13:36:56 UTC
I apologize if this is a known bug. I tried looking for it and nothing came 
up, so I figured it wasn't solved yet.
this is for Samba-3.0.11, on Solaris 9 (Sparc)
last -5 acopelan reports:
acopelan  pts/1        ni101303.ni.utol Fri Mar 18 13:18 - 14:48  (01:30)
acopelan  pts/7        ni101303.ni.utol Fri Mar 18 13:10 - 13:10  (00:00)
acopelan  smb/2                         Fri Mar 18 13:00   still logged in
acopelan  smb/1                         Fri Mar 18 13:00   still logged in
acopelan  smb/1                         Fri Mar 18 13:00 - 13:00  (00:00)


The samba connections leave the hostname blank. That was a problem here, so I 
looked into it.
On Solaris 9, the utmp struct does not have a ut_host member, but the utmpx 
struct does.
The configure script only checks utmp, and doesn't find it. HAVE_UT_UT_HOST is 
0, and the hostname is not recorded.
here's what config.log says about it:
configure:23587: checking for ut_host in utmp
configure:23610: gcc -c -O -D_LARGEFILE_SOUR
CE -D_REENTRANT -D_FILE_OFFSET_BITS=64 conftest.c >&5
conftest.c: In function `main':
conftest.c:265: error: structure has no member named `ut_host'


the man files agree. utmp has no ut_host member, but utmpx does.
from man getutent:
The utmp structure contains the following members:


     char                ut_user[8];   /* user login name */
     char                ut_id[4];     /* /sbin/inittab id (usually line #) */
     char                ut_line[12];  /* device name (console, lnxx) */
     short               ut_pid;       /* process id */
     short               ut_type;      /* type of entry */
     struct exit_status  ut_exit;      /* exit status of a process */
                                       /* marked as DEAD_PROCESS */
     time_t              ut_time;      /* time entry was made */


     The structure exit_status includes the following members:


     short   e_termination;   /* termination status */
     short   e_exit;          /* exit status */
from man getutxent:
The utmpx structure contains the following members:


     char                 ut_user[32];   /* user login name */
     char                 ut_id[4];      /* /etc/inittab id (usually line #) */
     char                 ut_line[32];   /* device name (console, lnxx) */
     pid_t                ut_pid;        /* process id */
     short                ut_type;       /* type of entry */
     struct exit_status   ut_exit;       /* exit status of a process */
                                         /* marked as DEAD_PROCESS */
     struct timeval       ut_tv;         /* time entry was made */
     int                  ut_session;    /* session ID, used for windowing */
     short                ut_syslen;     /* significant length of ut_host */
                                         /* including terminating null */
     char                 ut_host[257];  /* host name, if remote */


SunOS 5.9            Last change: 6 Oct 1999                    1


Standard C Library Functions                        getutxent(3C)


     The exit_status structure includes the following members:


     short   e_termination;   /* termination status */
     short   e_exit;          /* exit status */


To fix this, I made a change to utmp.c (The change I made is definitely not 
portable)
I changed :
 #if defined(HAVE_UX_UT_SYSLEN) 
        if (hostname)
                ux.ut_syslen = strlen(hostname) + 1;    /* include end NULL */
        else
                ux.ut_syslen = 0;
 #endif 
 #if defined(HAVE_UT_UT_HOST) 
        utmp_strcpy(ux.ut_host, hostname, sizeof(ux.ut_host));
 #endif 


To this:
/* #if defined(HAVE_UX_UT_SYSLEN) */
        if (hostname)
                ux.ut_syslen = strlen(hostname) + 1;    /* include end NULL */
        else
                ux.ut_syslen = 0;
/* #endif */
/* #if defined(HAVE_UT_UT_HOST) */
        utmp_strcpy(ux.ut_host, hostname, sizeof(ux.ut_host));
/* #endif */


This worked. The new log:
acopelan  pts/3        ni101303.ni.utol Fri Mar 18 14:48 - 14:49  (00:01)
acopelan  smb/1        NI101308.ni.utol Fri Mar 18 14:40 - 14:43  (00:03)
acopelan  smb/1        NI101308.ni.utol Fri Mar 18 14:39 - 14:40  (00:00)
acopelan  smb/1        NI101308.ni.utol Fri Mar 18 14:39 - 14:39  (00:00)
acopelan  smb/1        NI101308.ni.utol Fri Mar 18 14:39 - 14:39  (00:00)

Thank you for your time, I hope it's helpful.
Comment 1 Adam Copeland (mail address dead) 2005-03-18 14:58:23 UTC
Oh, the "fix" I made only causes the IP address to be logged for the hostname. 
To get the hostname there, "hostname lookups = yes" has to be in the smb.conf 
file.
Comment 2 Adam Copeland (mail address dead) 2005-03-24 13:48:03 UTC
Possible (portable) fix:
have configure check for ut_host in utmpx, just as it does for utmp. 
(currently, if utmp has ut_host, HAVE_UT_UT_HOST is defined (as 1).)
Have configure define HAVE_UTX_UT_HOST if utmpx has ut_host
slightly modify utmp.c - change: 

#if defined(HAVE_UT_UT_HOST)
        utmp_strcpy(ux.ut_host, hostname, sizeof(ux.ut_host));
#endif
to:

#if defined(HAVE_UTX_UT_HOST)
       	utmp_strcpy(ux.ut_host, hostname, sizeof(ux.ut_host));
#endif

Note: This is a little different than before. Before, you just needed ut_host 
in utmp for utmp_strcpy(ux.ut_host, hostname, sizeof(ux.ut_host)); to be 
compiled. However - ux is a utmpx struct. It's more accurate to check utmpx 
for ut_host before putting anything in it.

The other HAVE_UT_UT_HOST sections don't need to be changed. This minor change 
allows the hostname to be logged using utmpx for me.
Comment 3 David Gajewski 2007-07-12 10:51:42 UTC
Created attachment 2813 [details]
Portable patch which detects and corrects usage of ut_host in utmpx
Comment 4 Björn Jacke 2019-01-06 15:35:11 UTC
*** Bug 4743 has been marked as a duplicate of this bug. ***
Comment 5 Björn Jacke 2019-01-11 08:26:06 UTC
sorry for the 14 years delay but now fixed in master with 7643ee2ea857cfbf727f9bf03f9e3e8cddf84a21