diff options
Diffstat (limited to 'source3')
-rw-r--r-- | source3/smbd/utmp.c | 63 |
1 files changed, 46 insertions, 17 deletions
diff --git a/source3/smbd/utmp.c b/source3/smbd/utmp.c index f79cd43c5b..cc52db8462 100644 --- a/source3/smbd/utmp.c +++ b/source3/smbd/utmp.c @@ -127,7 +127,7 @@ Notes: #endif /**************************************************************************** -obtain/release a small number (0 upwards) unique within and across smbds + Obtain/release a small number (0 upwards) unique within and across smbds. ****************************************************************************/ /* * Need a "small" number to represent this connection, unique within this @@ -154,8 +154,9 @@ obtain/release a small number (0 upwards) unique within and across smbds */ /**************************************************************************** -Default paths to various {u,w}tmp{,x} files + Default paths to various {u,w}tmp{,x} files. ****************************************************************************/ + #ifdef HAVE_UTMPX_H static const char *ux_pathname = @@ -260,9 +261,11 @@ static void uw_pathname(pstring fname, const char *uw_name, const char *uw_defau } #ifndef HAVE_PUTUTLINE + /**************************************************************************** -Update utmp file directly. No subroutine interface: probably a BSD system. + Update utmp file directly. No subroutine interface: probably a BSD system. ****************************************************************************/ + static void pututline_my(pstring uname, struct utmp *u, BOOL claim) { DEBUG(1,("pututline_my: not yet implemented\n")); @@ -271,10 +274,12 @@ static void pututline_my(pstring uname, struct utmp *u, BOOL claim) #endif /* HAVE_PUTUTLINE */ #ifndef HAVE_UPDWTMP + /**************************************************************************** -Update wtmp file directly. No subroutine interface: probably a BSD system. -Credit: Michail Vidiassov <master@iaas.msu.ru> + Update wtmp file directly. No subroutine interface: probably a BSD system. + Credit: Michail Vidiassov <master@iaas.msu.ru> ****************************************************************************/ + static void updwtmp_my(pstring wname, struct utmp *u, BOOL claim) { int fd; @@ -311,8 +316,9 @@ static void updwtmp_my(pstring wname, struct utmp *u, BOOL claim) #endif /* HAVE_UPDWTMP */ /**************************************************************************** -Update via utmp/wtmp (not utmpx/wtmpx) + Update via utmp/wtmp (not utmpx/wtmpx). ****************************************************************************/ + static void utmp_nox_update(struct utmp *u, const char *host, BOOL claim) { pstring uname, wname; @@ -369,8 +375,26 @@ static void utmp_nox_update(struct utmp *u, const char *host, BOOL claim) } /**************************************************************************** -Update via utmpx/wtmpx (preferred) or via utmp/wtmp + Copy a string in the utmp structure. ****************************************************************************/ + +static void utmp_strcpy(char *dest, const char *src, size_t n) +{ + size_t 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. +****************************************************************************/ + static void sys_utmp_update(struct utmp *u, const char *hostname, BOOL claim) { #if !defined(HAVE_UTMPX_H) @@ -391,10 +415,12 @@ static void sys_utmp_update(struct utmp *u, const char *hostname, BOOL claim) getutmpx(u, &ux); #if defined(HAVE_UX_UT_SYSLEN) - if (hostname) ux.ut_syslen = strlen(hostname) + 1; /* include end NULL */ - else ux.ut_syslen = 0; + 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); @@ -424,8 +450,9 @@ static void sys_utmp_update(struct utmp *u, const char *hostname, BOOL claim) #if defined(HAVE_UT_UT_ID) /**************************************************************************** -encode the unique connection number into "ut_id" + Encode the unique connection number into "ut_id". ****************************************************************************/ + static int ut_id_encode(int i, char *fourbyte) { int nbase; @@ -467,9 +494,9 @@ static BOOL sys_utmp_fill(struct utmp *u, * 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 +512,7 @@ static BOOL sys_utmp_fill(struct utmp *u, 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 +535,7 @@ static BOOL sys_utmp_fill(struct utmp *u, #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) @@ -529,8 +556,9 @@ static BOOL sys_utmp_fill(struct utmp *u, } /**************************************************************************** -close a connection + Close a connection. ****************************************************************************/ + void sys_utmp_yield(const char *username, const char *hostname, const char *id_str, int id_num) { @@ -553,8 +581,9 @@ void sys_utmp_yield(const char *username, const char *hostname, } /**************************************************************************** -claim a entry in whatever utmp system the OS uses + Claim a entry in whatever utmp system the OS uses. ****************************************************************************/ + void sys_utmp_claim(const char *username, const char *hostname, const char *id_str, int id_num) { |