1 | /* |
---|
2 | * $Header: /afs/dev.mit.edu/source/repository/athena/bin/rkinit/rkinitd/rpc.c,v 1.1 1989-11-12 19:35:18 qjb Exp $ |
---|
3 | * $Source: /afs/dev.mit.edu/source/repository/athena/bin/rkinit/rkinitd/rpc.c,v $ |
---|
4 | * $Author: qjb $ |
---|
5 | * |
---|
6 | * This file contains the network parts of the rkinit server. |
---|
7 | */ |
---|
8 | |
---|
9 | #if !defined(lint) && !defined(SABER) |
---|
10 | static char *rcsid = "$Header: /afs/dev.mit.edu/source/repository/athena/bin/rkinit/rkinitd/rpc.c,v 1.1 1989-11-12 19:35:18 qjb Exp $"; |
---|
11 | #endif lint || SABER |
---|
12 | |
---|
13 | #include <stdio.h> |
---|
14 | #include <sys/types.h> |
---|
15 | #include <netinet/in.h> |
---|
16 | #include <sys/time.h> |
---|
17 | #include <syslog.h> |
---|
18 | #include <signal.h> |
---|
19 | #include <errno.h> |
---|
20 | |
---|
21 | #include <rkinit.h> |
---|
22 | #include <rkinit_err.h> |
---|
23 | #include <rkinit_private.h> |
---|
24 | |
---|
25 | #define RKINITD_TIMEOUT 60 |
---|
26 | |
---|
27 | extern int errno; |
---|
28 | extern char *sys_errlist[]; |
---|
29 | |
---|
30 | static int in; /* sockets */ |
---|
31 | static int out; |
---|
32 | |
---|
33 | static char errbuf[BUFSIZ]; |
---|
34 | |
---|
35 | void error(); |
---|
36 | |
---|
37 | static int timeout() |
---|
38 | { |
---|
39 | syslog(LOG_WARNING, "rkinitd timed out.\n"); |
---|
40 | exit(1); |
---|
41 | |
---|
42 | return(0); /* To make the compiler happy... */ |
---|
43 | } |
---|
44 | |
---|
45 | /* |
---|
46 | * This function does all the network setup for rkinitd. |
---|
47 | * It returns true if we were started from inetd, or false if |
---|
48 | * we were started from the commandline. |
---|
49 | * It causes the program to exit if there is an error. |
---|
50 | */ |
---|
51 | int setup_rpc(notimeout) |
---|
52 | int notimeout; /* True if we should not timeout */ |
---|
53 | { |
---|
54 | struct itimerval timer; /* Time structure for timeout */ |
---|
55 | |
---|
56 | /* For now, support only inetd. */ |
---|
57 | in = 0; |
---|
58 | out = 1; |
---|
59 | |
---|
60 | if (! notimeout) { |
---|
61 | SBCLEAR(timer); |
---|
62 | |
---|
63 | /* Set up an itimer structure to send an alarm signal after timeout |
---|
64 | seconds. */ |
---|
65 | timer.it_interval.tv_sec = RKINITD_TIMEOUT; |
---|
66 | timer.it_interval.tv_usec = 0; |
---|
67 | timer.it_value = timer.it_interval; |
---|
68 | |
---|
69 | /* Start the timer. */ |
---|
70 | if (setitimer (ITIMER_REAL, &timer, (struct itimerval *)0) < 0) { |
---|
71 | sprintf(errbuf, "setitimer: %s", sys_errlist[errno]); |
---|
72 | rkinit_errmsg(errbuf); |
---|
73 | error(); |
---|
74 | exit(1); |
---|
75 | } |
---|
76 | |
---|
77 | signal(SIGALRM, timeout); |
---|
78 | } |
---|
79 | |
---|
80 | return(TRUE); |
---|
81 | } |
---|
82 | |
---|
83 | void rpc_exchange_version_info(c_lversion, c_hversion, |
---|
84 | s_lversion, s_hversion) |
---|
85 | int *c_lversion; |
---|
86 | int *c_hversion; |
---|
87 | int s_lversion; |
---|
88 | int s_hversion; |
---|
89 | { |
---|
90 | u_char version_info[VERSION_INFO_SIZE]; |
---|
91 | int length = sizeof(version_info); |
---|
92 | |
---|
93 | if (rki_get_packet(in, MT_CVERSION, &length, version_info) != |
---|
94 | RKINIT_SUCCESS) { |
---|
95 | error(); |
---|
96 | exit(1); |
---|
97 | } |
---|
98 | |
---|
99 | *c_lversion = version_info[0]; |
---|
100 | *c_hversion = version_info[1]; |
---|
101 | |
---|
102 | version_info[0] = s_lversion; |
---|
103 | version_info[1] = s_hversion; |
---|
104 | |
---|
105 | if (rki_send_packet(out, MT_SVERSION, length, version_info) != |
---|
106 | RKINIT_SUCCESS) { |
---|
107 | error(); |
---|
108 | exit(1); |
---|
109 | } |
---|
110 | } |
---|
111 | |
---|
112 | void rpc_get_rkinit_info(info) |
---|
113 | rkinit_info *info; |
---|
114 | { |
---|
115 | u_long length = sizeof(rkinit_info); |
---|
116 | |
---|
117 | if (rki_get_packet(in, MT_RKINIT_INFO, &length, (char *)info)) { |
---|
118 | error(); |
---|
119 | exit(1); |
---|
120 | } |
---|
121 | |
---|
122 | info->lifetime = ntohl(info->lifetime); |
---|
123 | } |
---|
124 | |
---|
125 | void rpc_send_error(errmsg) |
---|
126 | char *errmsg; |
---|
127 | { |
---|
128 | if (rki_send_packet(out, MT_STATUS, strlen(errmsg), errmsg)) { |
---|
129 | error(); |
---|
130 | exit(1); |
---|
131 | } |
---|
132 | } |
---|
133 | |
---|
134 | void rpc_send_success() |
---|
135 | { |
---|
136 | if (rki_send_packet(out, MT_STATUS, 0, "")) { |
---|
137 | error(); |
---|
138 | exit(1); |
---|
139 | } |
---|
140 | } |
---|
141 | |
---|
142 | void rpc_exchange_tkt(cip, scip) |
---|
143 | KTEXT cip; |
---|
144 | MSG_DAT *scip; |
---|
145 | { |
---|
146 | int length = MAX_KTXT_LEN; |
---|
147 | |
---|
148 | if (rki_send_packet(out, MT_SKDC, cip->length, cip->dat)) { |
---|
149 | error(); |
---|
150 | exit(1); |
---|
151 | } |
---|
152 | |
---|
153 | if (rki_get_packet(in, MT_CKDC, &length, scip->app_data)) { |
---|
154 | error(); |
---|
155 | exit(1); |
---|
156 | } |
---|
157 | scip->app_length = length; |
---|
158 | } |
---|
159 | |
---|
160 | void rpc_getauth(auth, caddr, saddr) |
---|
161 | KTEXT auth; |
---|
162 | struct sockaddr_in *caddr; |
---|
163 | struct sockaddr_in *saddr; |
---|
164 | { |
---|
165 | int addrlen = sizeof(struct sockaddr_in); |
---|
166 | |
---|
167 | if (rki_rpc_get_ktext(in, auth, MT_AUTH)) { |
---|
168 | error(); |
---|
169 | exit(1); |
---|
170 | } |
---|
171 | |
---|
172 | if (getpeername(in, caddr, &addrlen) < 0) { |
---|
173 | sprintf(errbuf, "getpeername: %s", sys_errlist[errno]); |
---|
174 | rkinit_errmsg(errbuf); |
---|
175 | error(); |
---|
176 | exit(1); |
---|
177 | } |
---|
178 | |
---|
179 | if (getsockname(out, saddr, &addrlen) < 0) { |
---|
180 | sprintf(errbuf, "getsockname: %s", sys_errlist[errno]); |
---|
181 | rkinit_errmsg(errbuf); |
---|
182 | error(); |
---|
183 | exit(1); |
---|
184 | } |
---|
185 | } |
---|