1997-02-06 17:52:29 +00:00
|
|
|
/* insecure.c: The opieinsecure() library function.
|
|
|
|
|
1997-09-29 08:53:38 +00:00
|
|
|
%%% portions-copyright-cmetz-96
|
2002-03-21 23:42:52 +00:00
|
|
|
Portions of this software are Copyright 1996-1999 by Craig Metz, All Rights
|
1997-02-06 17:52:29 +00:00
|
|
|
Reserved. The Inner Net License Version 2 applies to these portions of
|
|
|
|
the software.
|
|
|
|
You should have received a copy of the license with this software. If
|
|
|
|
you didn't get a copy, you may request one from <license@inner.net>.
|
|
|
|
|
|
|
|
Portions of this software are Copyright 1995 by Randall Atkinson and Dan
|
|
|
|
McDonald, All Rights Reserved. All Rights under this copyright are assigned
|
|
|
|
to the U.S. Naval Research Laboratory (NRL). The NRL Copyright Notice and
|
|
|
|
License Agreement applies to this software.
|
|
|
|
|
|
|
|
History:
|
|
|
|
|
2002-03-21 23:42:52 +00:00
|
|
|
Modified by cmetz for OPIE 2.4. Do utmp checks on utmpx systems.
|
|
|
|
Handle unterminated ut_host.
|
1997-09-29 08:53:38 +00:00
|
|
|
Modified by cmetz for OPIE 2.31. Fixed a logic bug. Call endut[x]ent().
|
1997-02-06 17:52:29 +00:00
|
|
|
Modified by cmetz for OPIE 2.3. Added result caching. Use
|
|
|
|
__opiegetutmpentry(). Ifdef around ut_host check. Eliminate
|
|
|
|
unused variable.
|
|
|
|
Modified by cmetz for OPIE 2.2. Use FUNCTION declaration et al.
|
|
|
|
Allow IP loopback. DISPLAY and ut_host must match exactly,
|
|
|
|
not just the part before the colon. Added work-around for
|
|
|
|
Sun CDE dtterm bug. Leave the environment as it was
|
|
|
|
found. Use uname().
|
|
|
|
Created at NRL for OPIE 2.2 from opiesubr.c. Fixed pointer
|
|
|
|
assignment that should have been a comparison.
|
2001-08-29 13:17:02 +00:00
|
|
|
|
|
|
|
$FreeBSD$
|
|
|
|
|
1997-02-06 17:52:29 +00:00
|
|
|
*/
|
|
|
|
#include "opie_cfg.h"
|
|
|
|
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <stdlib.h> /* ANSI C standard library */
|
|
|
|
#include <sys/param.h>
|
|
|
|
#include <unistd.h>
|
|
|
|
|
|
|
|
#if DOUTMPX
|
|
|
|
#include <utmpx.h>
|
|
|
|
#define utmp utmpx
|
1997-09-29 08:53:38 +00:00
|
|
|
#define endutent endutxent
|
2010-01-11 16:27:56 +00:00
|
|
|
#else
|
|
|
|
#include <utmp.h>
|
1997-02-06 17:52:29 +00:00
|
|
|
#endif /* DOUTMPX */
|
|
|
|
|
|
|
|
#if HAVE_SYS_UTSNAME_H
|
|
|
|
#include <sys/utsname.h>
|
|
|
|
#endif /* HAVE_SYS_UTSNAME_H */
|
|
|
|
|
|
|
|
#include "opie.h"
|
|
|
|
|
1997-09-29 08:53:38 +00:00
|
|
|
char *remote_terms[] = { "xterm", "xterms", "kterm", NULL };
|
|
|
|
|
1997-02-06 17:52:29 +00:00
|
|
|
int opieinsecure FUNCTION_NOARGS
|
|
|
|
{
|
|
|
|
#ifndef NO_INSECURE_CHECK
|
|
|
|
char *display_name;
|
|
|
|
char *s;
|
|
|
|
char *term_name;
|
|
|
|
int insecure = 0;
|
2002-03-21 23:42:52 +00:00
|
|
|
#if HAVE_UT_HOST || DOUTMPX
|
1997-02-06 17:52:29 +00:00
|
|
|
struct utmp utmp;
|
2002-03-21 23:42:52 +00:00
|
|
|
#endif /* HAVE_UT_HOST || DOUTMPX */
|
1997-02-06 17:52:29 +00:00
|
|
|
static int result = -1;
|
|
|
|
|
|
|
|
if (result != -1)
|
|
|
|
return result;
|
|
|
|
|
2001-08-29 13:17:02 +00:00
|
|
|
if (getenv("SSH_CLIENT") != NULL)
|
|
|
|
return (result = 0);
|
1997-02-06 17:52:29 +00:00
|
|
|
display_name = (char *) getenv("DISPLAY");
|
|
|
|
term_name = (char *) getenv("TERM");
|
|
|
|
|
|
|
|
if (display_name) {
|
|
|
|
insecure = 1;
|
|
|
|
if (s = strchr(display_name, ':')) {
|
|
|
|
int n = s - display_name;
|
|
|
|
if (!n)
|
|
|
|
insecure = 0;
|
|
|
|
else {
|
|
|
|
if (!strncmp("unix", display_name, n))
|
|
|
|
insecure = 0;
|
|
|
|
else if (!strncmp("localhost", display_name, n))
|
|
|
|
insecure = 0;
|
|
|
|
else if (!strncmp("loopback", display_name, n))
|
|
|
|
insecure = 0;
|
|
|
|
else if (!strncmp("127.0.0.1", display_name, n))
|
|
|
|
insecure = 0;
|
|
|
|
else {
|
|
|
|
struct utsname utsname;
|
|
|
|
|
|
|
|
if (!uname(&utsname)) {
|
|
|
|
if (!strncmp(utsname.nodename, display_name, n))
|
|
|
|
insecure = 0;
|
|
|
|
else {
|
|
|
|
if (s = strchr(display_name, '.')) {
|
|
|
|
int n2 = s - display_name;
|
|
|
|
if (n < n2)
|
|
|
|
n2 = n;
|
1997-09-29 08:53:38 +00:00
|
|
|
if (!strncmp(utsname.nodename, display_name, n2))
|
1997-02-06 17:52:29 +00:00
|
|
|
insecure = 0;
|
|
|
|
} /* endif display_name is '.' */
|
|
|
|
} /* endif hostname != display_name */
|
|
|
|
} /* endif was able to get hostname */
|
|
|
|
} /* endif display_name == UNIX */
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} /* endif display_name == ":" */
|
|
|
|
if (insecure)
|
|
|
|
return (result = 1);
|
|
|
|
|
|
|
|
/* If no DISPLAY variable exists and TERM=xterm,
|
|
|
|
then we probably have an xterm executing on a remote system
|
|
|
|
with an rlogin or telnet to our system. If it were a local
|
|
|
|
xterm, then the DISPLAY environment variable would
|
|
|
|
have to exist. rja */
|
1997-09-29 08:53:38 +00:00
|
|
|
if (!display_name && term_name) {
|
|
|
|
int i;
|
|
|
|
for (i = 0; remote_terms[i]; i++)
|
|
|
|
if (!strcmp(term_name, remote_terms[i]))
|
|
|
|
return (result = 1);
|
|
|
|
};
|
1997-02-06 17:52:29 +00:00
|
|
|
|
2002-03-21 23:42:52 +00:00
|
|
|
#if HAVE_UT_HOST || DOUTMPX
|
2000-04-10 11:09:42 +00:00
|
|
|
if (isatty(0)) {
|
|
|
|
memset(&utmp, 0, sizeof(struct utmp));
|
|
|
|
{
|
|
|
|
int i = __opiegetutmpentry(ttyname(0), &utmp);
|
|
|
|
endutent();
|
|
|
|
if (!i && utmp.ut_host[0]) {
|
2002-03-21 23:42:52 +00:00
|
|
|
char host[sizeof(utmp.ut_host) + 1];
|
2000-04-10 11:09:42 +00:00
|
|
|
insecure = 1;
|
|
|
|
|
2002-03-21 23:42:52 +00:00
|
|
|
strncpy(host, utmp.ut_host, sizeof(utmp.ut_host));
|
|
|
|
host[sizeof(utmp.ut_host)] = 0;
|
|
|
|
|
|
|
|
if (s = strchr(host, ':')) {
|
|
|
|
int n = s - host;
|
2000-04-10 11:09:42 +00:00
|
|
|
if (!n)
|
|
|
|
insecure = 0;
|
|
|
|
else
|
|
|
|
if (display_name) {
|
2002-03-21 23:42:52 +00:00
|
|
|
if (!strncmp(host, display_name, n))
|
2000-04-10 11:09:42 +00:00
|
|
|
insecure = 0;
|
2002-03-21 23:42:52 +00:00
|
|
|
#if 1 /* def SOLARIS */
|
2000-04-10 11:09:42 +00:00
|
|
|
else
|
2002-03-21 23:42:52 +00:00
|
|
|
if (s = strchr(host, ' ')) {
|
2000-04-10 11:09:42 +00:00
|
|
|
*s = ':';
|
|
|
|
if (s = strchr(s + 1, ' '))
|
|
|
|
*s = '.';
|
2002-03-21 23:42:52 +00:00
|
|
|
if (!strncmp(host, display_name, n))
|
2000-04-10 11:09:42 +00:00
|
|
|
insecure = 0;
|
|
|
|
}
|
1997-02-06 17:52:29 +00:00
|
|
|
#endif /* SOLARIS */
|
2000-04-10 11:09:42 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
1997-09-29 08:53:38 +00:00
|
|
|
};
|
2002-03-21 23:42:52 +00:00
|
|
|
#endif /* HAVE_UT_HOST || DOUTMPX */
|
1997-02-06 17:52:29 +00:00
|
|
|
if (insecure)
|
|
|
|
return (result = 1);
|
|
|
|
|
|
|
|
return (result = 0);
|
|
|
|
#else /* NO_INSECURE_CHECK */
|
|
|
|
return 0;
|
|
|
|
#endif /* NO_INSECURE_CHECK */
|
|
|
|
}
|