mirror of
https://git.hardenedbsd.org/hardenedbsd/HardenedBSD.git
synced 2024-11-24 17:44:17 +01:00
Trim a domain part for wtmp as same as showed by "netstat -r".
Here is a some example for avoiding a confusion. It asssumes a logged host domain is "spec.co.jp". All example is longer than UT_HOSTNAMELEN value. 1) turbo.tama.spec.co.jp: 192.19.0.2 -> trubo.tama 2) turbo.tama.foo.co.jp : 192.19.0.2 -> 192.19.0.2 3) specgw.spec.co.jp : 202.32.13.1 -> specgw Submitted by: Atsushi Murai <amurai@spec.co.jp>
This commit is contained in:
parent
f66ca81068
commit
89caae2932
Notes:
svn2git
2020-12-20 02:59:44 +00:00
svn path=/head/; revision=36559
@ -18,7 +18,7 @@
|
||||
* 5. Modifications may be freely made to this file providing the above
|
||||
* conditions are met.
|
||||
*
|
||||
* $Id: libutil.h,v 1.13 1997/09/04 22:38:58 pst Exp $
|
||||
* $Id: libutil.h,v 1.14 1998/05/28 23:17:07 brian Exp $
|
||||
*/
|
||||
|
||||
#ifndef _LIBUTIL_H_
|
||||
@ -37,13 +37,13 @@ void login __P((struct utmp *_ut));
|
||||
int login_tty __P((int _fd));
|
||||
int logout __P((char *_line));
|
||||
void logwtmp __P((const char *_line, const char *_name, const char *_host));
|
||||
void trimdomain __P((char *_fullhost, int _hostsize));
|
||||
int openpty __P((int *_amaster, int *_aslave, char *_name,
|
||||
struct termios *_termp, struct winsize *_winp));
|
||||
int forkpty __P((int *_amaster, char *_name,
|
||||
struct termios *_termp, struct winsize *_winp));
|
||||
const char *uu_lockerr __P((int _uu_lockresult));
|
||||
int uu_lock __P((const char *_ttyname));
|
||||
int uu_lock_txfr __P((const char *_ttyname, pid_t _pid));
|
||||
int uu_unlock __P((const char *_ttyname));
|
||||
int _secure_path __P((const char *_path, uid_t _uid, gid_t _gid));
|
||||
__END_DECLS
|
||||
|
@ -36,10 +36,11 @@
|
||||
static char sccsid[] = "@(#)logwtmp.c 8.1 (Berkeley) 6/4/93";
|
||||
#else
|
||||
static const char rcsid[] =
|
||||
"$Id: logwtmp.c,v 1.4 1997/08/13 20:42:18 steve Exp $";
|
||||
"$Id: logwtmp.c,v 1.5 1997/09/04 22:38:59 pst Exp $";
|
||||
#endif
|
||||
#endif /* LIBC_SCCS and not lint */
|
||||
|
||||
#include <sys/param.h>
|
||||
#include <sys/types.h>
|
||||
#include <sys/file.h>
|
||||
#include <sys/stat.h>
|
||||
@ -53,6 +54,37 @@ static const char rcsid[] =
|
||||
#include <unistd.h>
|
||||
#include <utmp.h>
|
||||
|
||||
void
|
||||
trimdomain( char * fullhost, int hostsize )
|
||||
{
|
||||
static char domain[MAXHOSTNAMELEN + 1];
|
||||
static int first = 1;
|
||||
char *s;
|
||||
|
||||
if (first) {
|
||||
first = 0;
|
||||
if (gethostname(domain, MAXHOSTNAMELEN) == 0 &&
|
||||
(s = strchr(domain, '.')))
|
||||
(void) strcpy(domain, s + 1);
|
||||
else
|
||||
domain[0] = 0;
|
||||
}
|
||||
|
||||
if (domain[0]) {
|
||||
s = fullhost;
|
||||
while ((fullhost = strchr(fullhost, '.'))) {
|
||||
if (!strcasecmp(fullhost + 1, domain)) {
|
||||
if ( fullhost - s < hostsize ) {
|
||||
*fullhost = '\0'; /* hit it and acceptable size*/
|
||||
}
|
||||
break;
|
||||
} else {
|
||||
fullhost++;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
logwtmp(line, name, host)
|
||||
const char *line;
|
||||
@ -61,7 +93,14 @@ logwtmp(line, name, host)
|
||||
{
|
||||
struct utmp ut;
|
||||
struct stat buf;
|
||||
char fullhost[MAXHOSTNAMELEN + 1];
|
||||
char *whost = fullhost;
|
||||
int fd;
|
||||
|
||||
strncpy( whost, host, MAXHOSTNAMELEN );
|
||||
fullhost[MAXHOSTNAMELEN] = '\0';
|
||||
trimdomain( whost, UT_HOSTSIZE );
|
||||
host = whost;
|
||||
|
||||
if (strlen(host) > UT_HOSTSIZE) {
|
||||
struct hostent *hp = gethostbyname(host);
|
||||
|
@ -42,7 +42,7 @@ static char copyright[] =
|
||||
static char sccsid[] = "@(#)login.c 8.4 (Berkeley) 4/2/94";
|
||||
#endif
|
||||
static const char rcsid[] =
|
||||
"$Id: login.c,v 1.33 1998/04/30 16:48:20 peter Exp $";
|
||||
"$Id: login.c,v 1.34 1998/04/30 16:50:07 peter Exp $";
|
||||
#endif /* not lint */
|
||||
|
||||
/*
|
||||
@ -118,6 +118,7 @@ int klogin __P((struct passwd *, char *, char *, char *));
|
||||
#endif
|
||||
|
||||
extern void login __P((struct utmp *));
|
||||
extern void trimdomain __P((char *, int));
|
||||
static void usage __P((void));
|
||||
|
||||
#define TTYGRPNAME "tty" /* name of group to own ttys */
|
||||
@ -213,6 +214,9 @@ main(argc, argv)
|
||||
if (domain && (p = strchr(optarg, '.')) &&
|
||||
strcasecmp(p, domain) == 0)
|
||||
*p = 0;
|
||||
|
||||
trimdomain(optarg, UT_HOSTSIZE );
|
||||
|
||||
if (strlen(optarg) > UT_HOSTSIZE) {
|
||||
struct hostent *hp = gethostbyname(optarg);
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user