pci: don't do sanity check for missing pci bus, the check can misfire.
[minix.git] / commands / rlogind / setup.c
blob72a059be1bcd04ddf25c59fc65309d52cbeb4b73
1 /*
2 setup.c
3 */
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"
21 static void getstr(char *buf, int cnt, char *errmsg);
23 void authenticate(void)
25 int result;
26 struct nwio_tcpconf tcpconf;
27 struct hostent *hostent;
28 char c;
30 /* Let's lookup the hostname for the connection. */
31 result= ioctl (0, NWIOGTCPCONF, &tcpconf);
32 if (result<0)
34 fprintf(stderr, "%s: ioctl(NWIOTCPCONF): %s\r\n",
35 prog_name, strerror(errno));
36 exit(1);
38 hostent= gethostbyaddr((char *)&tcpconf.nwtc_remaddr,
39 sizeof(tcpconf.nwtc_remaddr), AF_INET);
40 if (hostent)
42 strncpy(hostname, hostent->h_name, sizeof(hostname)-1);
43 hostname[sizeof(hostname)-1]= '\0';
45 else
47 strcpy(hostname, inet_ntoa(tcpconf.nwtc_remaddr));
50 authenticated = 0;
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");
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;
66 static void getstr(char *buf, int cnt, char *errmsg)
68 char c;
70 errno= 0;
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);
82 void tcp_urg(int fd, int on)
84 struct nwio_tcpopt tcpopt;
86 tcpopt.nwto_flags= on ? (NWTO_BSD_URG | NWTO_SND_URG) : NWTO_SND_NOTURG;
87 if (ioctl(1, NWIOSTCPOPT, &tcpopt) == -1)
89 fprintf(stderr, "rlogind: NWIOSTCPOPT failed: %s\r\n",
90 strerror(errno));