1 /* insecure.c: The opieinsecure() library function.
3 %%% portions-copyright-cmetz-96
4 Portions of this software are Copyright 1996-1999 by Craig Metz, All Rights
5 Reserved. The Inner Net License Version 2 applies to these portions of
7 You should have received a copy of the license with this software. If
8 you didn't get a copy, you may request one from <license@inner.net>.
10 Portions of this software are Copyright 1995 by Randall Atkinson and Dan
11 McDonald, All Rights Reserved. All Rights under this copyright are assigned
12 to the U.S. Naval Research Laboratory (NRL). The NRL Copyright Notice and
13 License Agreement applies to this software.
17 Modified by cmetz for OPIE 2.4. Do utmp checks on utmpx systems.
18 Handle unterminated ut_host.
19 Modified by cmetz for OPIE 2.31. Fixed a logic bug. Call endut[x]ent().
20 Modified by cmetz for OPIE 2.3. Added result caching. Use
21 __opiegetutmpentry(). Ifdef around ut_host check. Eliminate
23 Modified by cmetz for OPIE 2.2. Use FUNCTION declaration et al.
24 Allow IP loopback. DISPLAY and ut_host must match exactly,
25 not just the part before the colon. Added work-around for
26 Sun CDE dtterm bug. Leave the environment as it was
28 Created at NRL for OPIE 2.2 from opiesubr.c. Fixed pointer
29 assignment that should have been a comparison.
31 $FreeBSD: src/contrib/opie/libopie/insecure.c,v 1.1.1.2.6.2 2002/07/15 14:48:47 des Exp $
32 $DragonFly: src/contrib/opie/libopie/insecure.c,v 1.2 2003/06/17 04:24:05 dillon Exp $
39 #include <stdlib.h> /* ANSI C standard library */
40 #include <sys/param.h>
47 #define endutent endutxent
50 #if HAVE_SYS_UTSNAME_H
51 #include <sys/utsname.h>
52 #endif /* HAVE_SYS_UTSNAME_H */
56 char *remote_terms
[] = { "xterm", "xterms", "kterm", NULL
};
58 int opieinsecure FUNCTION_NOARGS
60 #ifndef NO_INSECURE_CHECK
65 #if HAVE_UT_HOST || DOUTMPX
67 #endif /* HAVE_UT_HOST || DOUTMPX */
68 static int result
= -1;
73 if (getenv("SSH_CLIENT") != NULL
)
75 display_name
= (char *) getenv("DISPLAY");
76 term_name
= (char *) getenv("TERM");
80 if (s
= strchr(display_name
, ':')) {
81 int n
= s
- display_name
;
85 if (!strncmp("unix", display_name
, n
))
87 else if (!strncmp("localhost", display_name
, n
))
89 else if (!strncmp("loopback", display_name
, n
))
91 else if (!strncmp("127.0.0.1", display_name
, n
))
94 struct utsname utsname
;
96 if (!uname(&utsname
)) {
97 if (!strncmp(utsname
.nodename
, display_name
, n
))
100 if (s
= strchr(display_name
, '.')) {
101 int n2
= s
- display_name
;
104 if (!strncmp(utsname
.nodename
, display_name
, n2
))
106 } /* endif display_name is '.' */
107 } /* endif hostname != display_name */
108 } /* endif was able to get hostname */
109 } /* endif display_name == UNIX */
112 } /* endif display_name == ":" */
116 /* If no DISPLAY variable exists and TERM=xterm,
117 then we probably have an xterm executing on a remote system
118 with an rlogin or telnet to our system. If it were a local
119 xterm, then the DISPLAY environment variable would
120 have to exist. rja */
121 if (!display_name
&& term_name
) {
123 for (i
= 0; remote_terms
[i
]; i
++)
124 if (!strcmp(term_name
, remote_terms
[i
]))
128 #if HAVE_UT_HOST || DOUTMPX
130 memset(&utmp
, 0, sizeof(struct utmp
));
132 int i
= __opiegetutmpentry(ttyname(0), &utmp
);
134 if (!i
&& utmp
.ut_host
[0]) {
135 char host
[sizeof(utmp
.ut_host
) + 1];
138 strncpy(host
, utmp
.ut_host
, sizeof(utmp
.ut_host
));
139 host
[sizeof(utmp
.ut_host
)] = 0;
141 if (s
= strchr(host
, ':')) {
147 if (!strncmp(host
, display_name
, n
))
149 #if 1 /* def SOLARIS */
151 if (s
= strchr(host
, ' ')) {
153 if (s
= strchr(s
+ 1, ' '))
155 if (!strncmp(host
, display_name
, n
))
164 #endif /* HAVE_UT_HOST || DOUTMPX */
169 #else /* NO_INSECURE_CHECK */
171 #endif /* NO_INSECURE_CHECK */