1 | /*
|
---|
2 | setup.c
|
---|
3 | */
|
---|
4 |
|
---|
5 | #include <sys/types.h>
|
---|
6 | #include <sys/ioctl.h>
|
---|
7 | #include <errno.h>
|
---|
8 | #include <stdio.h>
|
---|
9 | #include <stdlib.h>
|
---|
10 | #include <string.h>
|
---|
11 | #include <unistd.h>
|
---|
12 | #include <net/netlib.h>
|
---|
13 | #include <net/gen/in.h>
|
---|
14 | #include <net/gen/inet.h>
|
---|
15 | #include <net/gen/tcp.h>
|
---|
16 | #include <net/gen/tcp_io.h>
|
---|
17 | #include <net/gen/netdb.h>
|
---|
18 | #include <net/gen/socket.h>
|
---|
19 | #include "rlogind.h"
|
---|
20 |
|
---|
21 | static void getstr(char *buf, int cnt, char *errmsg);
|
---|
22 |
|
---|
23 | void authenticate(void)
|
---|
24 | {
|
---|
25 | int result;
|
---|
26 | struct nwio_tcpconf tcpconf;
|
---|
27 | struct hostent *hostent;
|
---|
28 | char c;
|
---|
29 |
|
---|
30 | /* Let's lookup the hostname for the connection. */
|
---|
31 | result= ioctl (0, NWIOGTCPCONF, &tcpconf);
|
---|
32 | if (result<0)
|
---|
33 | {
|
---|
34 | fprintf(stderr, "%s: ioctl(NWIOTCPCONF): %s\r\n",
|
---|
35 | prog_name, strerror(errno));
|
---|
36 | exit(1);
|
---|
37 | }
|
---|
38 | hostent= gethostbyaddr((char *)&tcpconf.nwtc_remaddr,
|
---|
39 | sizeof(tcpconf.nwtc_remaddr), AF_INET);
|
---|
40 | if (hostent)
|
---|
41 | {
|
---|
42 | strncpy(hostname, hostent->h_name, sizeof(hostname)-1);
|
---|
43 | hostname[sizeof(hostname)-1]= '\0';
|
---|
44 | }
|
---|
45 | else
|
---|
46 | {
|
---|
47 | strcpy(hostname, inet_ntoa(tcpconf.nwtc_remaddr));
|
---|
48 | }
|
---|
49 |
|
---|
50 | authenticated = 0;
|
---|
51 |
|
---|
52 | getstr(&c, 1, "protocol violation");
|
---|
53 | getstr(rusername, sizeof(rusername), "remuser too long");
|
---|
54 | getstr(lusername, sizeof(lusername), "locuser too long");
|
---|
55 | strcpy(term, "TERM=");
|
---|
56 | getstr(term+5, sizeof(term)-5, "Terminal type too long");
|
---|
57 |
|
---|
58 | #if DEBUG
|
---|
59 | fprintf(stderr, "got lu= %s, ru= %s, te= %s\r\n", lusername, rusername,
|
---|
60 | term);
|
---|
61 | #endif
|
---|
62 | if (iruserok(tcpconf.nwtc_remaddr, 0, rusername, lusername) == 0)
|
---|
63 | authenticated = 1;
|
---|
64 | }
|
---|
65 |
|
---|
66 | static void getstr(char *buf, int cnt, char *errmsg)
|
---|
67 | {
|
---|
68 | char c;
|
---|
69 |
|
---|
70 | errno= 0;
|
---|
71 | do
|
---|
72 | {
|
---|
73 | if (read(0, &c, 1) != 1)
|
---|
74 | fatal(1, "read failed", errno);
|
---|
75 | cnt--;
|
---|
76 | if (cnt < 0)
|
---|
77 | fatal(1, errmsg, 0);
|
---|
78 | *buf++= c;
|
---|
79 | } while(c != 0);
|
---|
80 | }
|
---|
81 |
|
---|
82 | void tcp_urg(int fd, int on)
|
---|
83 | {
|
---|
84 | struct nwio_tcpopt tcpopt;
|
---|
85 |
|
---|
86 | tcpopt.nwto_flags= on ? (NWTO_BSD_URG | NWTO_SND_URG) : NWTO_SND_NOTURG;
|
---|
87 | if (ioctl(1, NWIOSTCPOPT, &tcpopt) == -1)
|
---|
88 | {
|
---|
89 | fprintf(stderr, "rlogind: NWIOSTCPOPT failed: %s\r\n",
|
---|
90 | strerror(errno));
|
---|
91 | }
|
---|
92 | }
|
---|