3 *
4 * The contents of this file are subject to the terms of the
5 * Common Development and Distribution License, Version 1.0 only
6 * (the "License"). You may not use this file except in compliance
7 * with the License.
8 *
9 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10 * or http://www.opensolaris.org/os/licensing.
11 * See the License for the specific language governing permissions
12 * and limitations under the License.
13 *
14 * When distributing Covered Code, include this CDDL HEADER in each
15 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16 * If applicable, add the following below this CDDL HEADER, with the
17 * fields enclosed by brackets "[]" replaced with your own identifying
18 * information: Portions Copyright [yyyy] [name of copyright owner]
19 *
20 * CDDL HEADER END
21 */
22 /*
23 * Copyright 2001 Sun Microsystems, Inc. All rights reserved.
24 * Use is subject to license terms.
25 */
26
27 /* Copyright (c) 1983, 1984, 1985, 1986, 1987, 1988, 1989 AT&T */
28 /* All Rights Reserved */
29
30 /*
31 * Portions of this source code were derived from Berkeley 4.3 BSD
32 * under license from the Regents of the University of California.
33 */
34
35 #pragma ident "%Z%%M% %I% %E% SMI"
36
37 /*
38 * Miscellaneous support routines for kernel implentation of AUTH_DES
39 */
40
41 /*
42 * rtime - get time from remote machine
43 *
44 * sets time, obtaining value from host
45 * on the udp/time socket. Since timeserver returns
46 * with time of day in seconds since Jan 1, 1900, must
47 * subtract 86400(365*70 + 17) to get time
48 * since Jan 1, 1970, which is what get/settimeofday
49 * uses.
50 */
51 #include <sys/param.h>
52 #include <sys/types.h>
53 #include <sys/time.h>
54 #include <sys/systm.h>
55 #include <sys/errno.h>
56 #include <sys/proc.h>
94 mblk_t *mp;
95 mblk_t *mp2;
96
97 retries = 5;
98 if (calltype == 0) {
99 again:
100 RPCLOG0(8, "rtime: using old method\n");
101 if ((error = t_kopen(NULL, synconfig->knc_rdev,
102 FREAD|FWRITE, &tiptr, CRED())) != 0) {
103 RPCLOG(1, "rtime: t_kopen %d\n", error);
104 return (-1);
105 }
106
107 if ((error = t_kbind(tiptr, NULL, NULL)) != 0) {
108 (void) t_kclose(tiptr, 1);
109 RPCLOG(1, "rtime: t_kbind %d\n", error);
110 return (-1);
111 }
112
113 if (synconfig->knc_semantics == NC_TPI_CLTS) {
114 if ((error = t_kalloc(tiptr, T_UNITDATA, T_UDATA|T_ADDR,
115 (char **)&unitdata)) != 0) {
116 RPCLOG(1, "rtime: t_kalloc %d\n", error);
117 (void) t_kclose(tiptr, 1);
118 return (-1);
119 }
120
121 unitdata->addr.len = addrp->len;
122 bcopy(addrp->buf, unitdata->addr.buf, unitdata->addr.len);
123
124 dummy = 0;
125 unitdata->udata.buf = (caddr_t)&dummy;
126 unitdata->udata.len = sizeof (dummy);
127
128 if ((error = t_ksndudata(tiptr, unitdata, NULL)) != 0) {
129 RPCLOG(1, "rtime: t_ksndudata %d\n", error);
130 (void) t_kfree(tiptr, (char *)unitdata, T_UNITDATA);
131 (void) t_kclose(tiptr, 1);
132 return (-1);
133 }
134
135 timo = TIMEVAL_TO_TICK(wait);
136
137 RPCLOG(8, "rtime: timo %x\n", timo);
138 if ((error = t_kspoll(tiptr, timo, READWAIT, &type)) != 0) {
139 RPCLOG(1, "rtime: t_kspoll %d\n", error);
140 (void) t_kfree(tiptr, (char *)unitdata, T_UNITDATA);
141 (void) t_kclose(tiptr, 1);
142 return (-1);
143 }
144
145 if (type == 0) {
146 RPCLOG0(1, "rtime: t_kspoll timed out\n");
147 (void) t_kfree(tiptr, (char *)unitdata, T_UNITDATA);
148 (void) t_kclose(tiptr, 1);
149 return (-1);
150 }
151
152 error = t_krcvudata(tiptr, unitdata, &type, &uderr);
153 if (error != 0) {
154 RPCLOG(1, "rtime: t_krcvudata %d\n", error);
155 (void) t_kfree(tiptr, (char *)unitdata, T_UNITDATA);
156 (void) t_kclose(tiptr, 1);
157 return (-1);
158 }
159
160 if (type == T_UDERR) {
161 if (bcmp(addrp->buf, unitdata->addr.buf,
162 unitdata->addr.len) != 0) {
163 /*
164 * Response comes from some other
165 * destination:
166 * ignore it since it's not related to the
167 * request we just sent out.
168 */
169 (void) t_kfree(tiptr, (char *)unitdata,
170 T_UNITDATA);
171 (void) t_kclose(tiptr, 1);
172 goto again;
173 }
174 }
175
176 if (type != T_DATA) {
177 RPCLOG(1, "rtime: t_krcvudata returned type %d\n",
178 type);
179 (void) t_kfree(tiptr, (char *)unitdata, T_UNITDATA);
180 (void) t_kclose(tiptr, 1);
181 if (retries-- == 0)
182 return (-1);
183 goto again;
184 }
185
186 if (unitdata->udata.len < sizeof (uint32_t)) {
187 RPCLOG(1, "rtime: bad rcvd length %d\n",
188 unitdata->udata.len);
189 (void) t_kfree(tiptr, (char *)unitdata, T_UNITDATA);
190 (void) t_kclose(tiptr, 1);
191 if (retries-- == 0)
192 return (-1);
193 goto again;
194 }
195
196 /* LINTED pointer alignment */
197 thetime = (time_t)ntohl(*(uint32_t *)unitdata->udata.buf);
198 (void) t_kfree(tiptr, (char *)unitdata, T_UNITDATA);
199
200 } else {
201
202 if ((error = t_kalloc(tiptr, T_CALL, T_ADDR,
203 (char **)&server)) != 0) {
204 RPCLOG(1, "rtime: t_kalloc %d\n", error);
205 (void) t_kclose(tiptr, 1);
206 return (-1);
207 }
208
209 server->addr.len = addrp->len;
210 bcopy(addrp->buf, server->addr.buf, server->addr.len);
211
212 if ((error = t_kconnect(tiptr, server, NULL)) != 0) {
213 RPCLOG(1, "rtime: t_kconnect %d\n", error);
214 (void) t_kfree(tiptr, (char *)server, T_CALL);
215 (void) t_kclose(tiptr, 1);
216 return (-1);
217 }
218 (void) t_kfree(tiptr, (char *)server, T_CALL);
219
220 timo = TIMEVAL_TO_TICK(wait);
221
222 RPCLOG(8, "rtime: timo %x\n", timo);
223
224 i = 0;
225 dummy = 0;
226
227 /* now read up to 4 bytes from the TIME server */
228 while (i < sizeof (dummy)) {
229
230 error = t_kspoll(tiptr, timo, READWAIT, &type);
231 if (error != 0) {
232 RPCLOG(1, "rtime: t_kspoll %d\n", error);
233 (void) t_kclose(tiptr, 1);
234 return (-1);
235 }
236
237 if (type == 0) {
238 RPCLOG0(1, "rtime: t_kspoll timed out\n");
239 (void) t_kclose(tiptr, 1);
240 return (-1);
241 }
242
243 error = tli_recv(tiptr, &mp, tiptr->fp->f_flag);
244 if (error != 0) {
245 RPCLOG(1, "rtime: tli_recv %d\n", error);
246 (void) t_kclose(tiptr, 1);
247 return (-1);
248 }
249
250 if (mp->b_datap->db_type != M_DATA) {
251 RPCLOG(1, "rtime: wrong msg type %d\n",
252 mp->b_datap->db_type);
253 RPCLOG(1, "rtime: wrong msg type: read %d"
254 " bytes\n", i);
255 (void) t_kclose(tiptr, 1);
256 freemsg(mp);
257 return (-1);
258 }
259
260 mp2 = mp;
261
262 /*
263 * The outer loop iterates until we reach the end of
264 * the mblk chain.
265 */
266 while (mp2 != NULL) {
267
268 /*
269 * The inner loop iterates until we've gotten
270 * 4 bytes or until the mblk is exhausted.
271 */
272 while (i < sizeof (dummy) &&
273 mp2->b_rptr < mp2->b_wptr) {
274
275 i++;
276
277 /*
278 * We avoid big-endian/little-endian
279 * issues by serializing the result
280 * one byte at a time.
281 */
282 dummy <<= 8;
283 dummy += ((*mp2->b_rptr) & 0xFF);
284
285 mp2->b_rptr++;
286 }
287
288 mp2 = mp2->b_cont;
289 }
290
291 freemsg(mp);
292 }
293
294 thetime = (time_t)dummy;
295 }
296
297 (void) t_kclose(tiptr, 1);
298
299 } else {
300 CLIENT *client;
301 struct timeval timout;
302
303 RPCLOG0(8, "rtime: using new method\n");
|
3 *
4 * The contents of this file are subject to the terms of the
5 * Common Development and Distribution License, Version 1.0 only
6 * (the "License"). You may not use this file except in compliance
7 * with the License.
8 *
9 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10 * or http://www.opensolaris.org/os/licensing.
11 * See the License for the specific language governing permissions
12 * and limitations under the License.
13 *
14 * When distributing Covered Code, include this CDDL HEADER in each
15 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16 * If applicable, add the following below this CDDL HEADER, with the
17 * fields enclosed by brackets "[]" replaced with your own identifying
18 * information: Portions Copyright [yyyy] [name of copyright owner]
19 *
20 * CDDL HEADER END
21 */
22 /*
23 * Copyright 2014 Gary Mills
24 * Copyright 2001 Sun Microsystems, Inc. All rights reserved.
25 * Use is subject to license terms.
26 */
27
28 /* Copyright (c) 1983, 1984, 1985, 1986, 1987, 1988, 1989 AT&T */
29 /* All Rights Reserved */
30
31 /*
32 * Portions of this source code were derived from Berkeley 4.3 BSD
33 * under license from the Regents of the University of California.
34 */
35
36 /*
37 * Miscellaneous support routines for kernel implentation of AUTH_DES
38 */
39
40 /*
41 * rtime - get time from remote machine
42 *
43 * sets time, obtaining value from host
44 * on the udp/time socket. Since timeserver returns
45 * with time of day in seconds since Jan 1, 1900, must
46 * subtract 86400(365*70 + 17) to get time
47 * since Jan 1, 1970, which is what get/settimeofday
48 * uses.
49 */
50 #include <sys/param.h>
51 #include <sys/types.h>
52 #include <sys/time.h>
53 #include <sys/systm.h>
54 #include <sys/errno.h>
55 #include <sys/proc.h>
93 mblk_t *mp;
94 mblk_t *mp2;
95
96 retries = 5;
97 if (calltype == 0) {
98 again:
99 RPCLOG0(8, "rtime: using old method\n");
100 if ((error = t_kopen(NULL, synconfig->knc_rdev,
101 FREAD|FWRITE, &tiptr, CRED())) != 0) {
102 RPCLOG(1, "rtime: t_kopen %d\n", error);
103 return (-1);
104 }
105
106 if ((error = t_kbind(tiptr, NULL, NULL)) != 0) {
107 (void) t_kclose(tiptr, 1);
108 RPCLOG(1, "rtime: t_kbind %d\n", error);
109 return (-1);
110 }
111
112 if (synconfig->knc_semantics == NC_TPI_CLTS) {
113 if ((error = t_kalloc(tiptr, T_UNITDATA,
114 T_UDATA|T_ADDR, (char **)&unitdata)) != 0) {
115 RPCLOG(1, "rtime: t_kalloc %d\n", error);
116 (void) t_kclose(tiptr, 1);
117 return (-1);
118 }
119
120 unitdata->addr.len = addrp->len;
121 bcopy(addrp->buf, unitdata->addr.buf,
122 unitdata->addr.len);
123
124 dummy = 0;
125 unitdata->udata.buf = (caddr_t)&dummy;
126 unitdata->udata.len = sizeof (dummy);
127
128 if ((error = t_ksndudata(tiptr, unitdata, NULL)) !=
129 0) {
130 RPCLOG(1, "rtime: t_ksndudata %d\n", error);
131 (void) t_kfree(tiptr, (char *)unitdata,
132 T_UNITDATA);
133 (void) t_kclose(tiptr, 1);
134 return (-1);
135 }
136
137 timo = TIMEVAL_TO_TICK(wait);
138
139 RPCLOG(8, "rtime: timo %x\n", timo);
140 if ((error = t_kspoll(tiptr, timo, READWAIT,
141 &type)) != 0) {
142 RPCLOG(1, "rtime: t_kspoll %d\n", error);
143 (void) t_kfree(tiptr, (char *)unitdata,
144 T_UNITDATA);
145 (void) t_kclose(tiptr, 1);
146 return (-1);
147 }
148
149 if (type == 0) {
150 RPCLOG0(1, "rtime: t_kspoll timed out\n");
151 (void) t_kfree(tiptr, (char *)unitdata,
152 T_UNITDATA);
153 (void) t_kclose(tiptr, 1);
154 return (-1);
155 }
156
157 error = t_krcvudata(tiptr, unitdata, &type, &uderr);
158 if (error != 0) {
159 RPCLOG(1, "rtime: t_krcvudata %d\n", error);
160 (void) t_kfree(tiptr, (char *)unitdata,
161 T_UNITDATA);
162 (void) t_kclose(tiptr, 1);
163 if (error == EBADMSG && retries-- > 0)
164 goto again;
165 return (-1);
166 }
167
168 if (type == T_UDERR) {
169 if (bcmp(addrp->buf, unitdata->addr.buf,
170 unitdata->addr.len) != 0) {
171 /*
172 * Response comes from some other
173 * destination:
174 * ignore it since it's not related to the
175 * request we just sent out.
176 */
177 (void) t_kfree(tiptr, (char *)unitdata,
178 T_UNITDATA);
179 (void) t_kclose(tiptr, 1);
180 goto again;
181 }
182 }
183
184 if (type != T_DATA) {
185 RPCLOG(1,
186 "rtime: t_krcvudata returned type %d\n",
187 type);
188 (void) t_kfree(tiptr, (char *)unitdata,
189 T_UNITDATA);
190 (void) t_kclose(tiptr, 1);
191 if (retries-- == 0)
192 return (-1);
193 goto again;
194 }
195
196 if (unitdata->udata.len < sizeof (uint32_t)) {
197 RPCLOG(1, "rtime: bad rcvd length %d\n",
198 unitdata->udata.len);
199 (void) t_kfree(tiptr, (char *)unitdata,
200 T_UNITDATA);
201 (void) t_kclose(tiptr, 1);
202 if (retries-- == 0)
203 return (-1);
204 goto again;
205 }
206
207 thetime = (time_t)ntohl(
208 /* LINTED pointer alignment */
209 *(uint32_t *)unitdata->udata.buf);
210 (void) t_kfree(tiptr, (char *)unitdata, T_UNITDATA);
211
212 } else {
213
214 if ((error = t_kalloc(tiptr, T_CALL, T_ADDR,
215 (char **)&server)) != 0) {
216 RPCLOG(1, "rtime: t_kalloc %d\n", error);
217 (void) t_kclose(tiptr, 1);
218 return (-1);
219 }
220
221 server->addr.len = addrp->len;
222 bcopy(addrp->buf, server->addr.buf, server->addr.len);
223
224 if ((error = t_kconnect(tiptr, server, NULL)) != 0) {
225 RPCLOG(1, "rtime: t_kconnect %d\n", error);
226 (void) t_kfree(tiptr, (char *)server, T_CALL);
227 (void) t_kclose(tiptr, 1);
228 return (-1);
229 }
230 (void) t_kfree(tiptr, (char *)server, T_CALL);
231
232 timo = TIMEVAL_TO_TICK(wait);
233
234 RPCLOG(8, "rtime: timo %x\n", timo);
235
236 i = 0;
237 dummy = 0;
238
239 /* now read up to 4 bytes from the TIME server */
240 while (i < sizeof (dummy)) {
241
242 error = t_kspoll(tiptr, timo, READWAIT, &type);
243 if (error != 0) {
244 RPCLOG(1, "rtime: t_kspoll %d\n",
245 error);
246 (void) t_kclose(tiptr, 1);
247 return (-1);
248 }
249
250 if (type == 0) {
251 RPCLOG0(1,
252 "rtime: t_kspoll timed out\n");
253 (void) t_kclose(tiptr, 1);
254 return (-1);
255 }
256
257 error = tli_recv(tiptr, &mp,
258 tiptr->fp->f_flag);
259 if (error != 0) {
260 RPCLOG(1, "rtime: tli_recv %d\n",
261 error);
262 (void) t_kclose(tiptr, 1);
263 return (-1);
264 }
265
266 if (mp->b_datap->db_type != M_DATA) {
267 RPCLOG(1, "rtime: wrong msg type %d\n",
268 mp->b_datap->db_type);
269 RPCLOG(1,
270 "rtime: wrong msg type: read %d"
271 " bytes\n", i);
272 (void) t_kclose(tiptr, 1);
273 freemsg(mp);
274 return (-1);
275 }
276
277 mp2 = mp;
278
279 /*
280 * The outer loop iterates until we reach the
281 * end of the mblk chain.
282 */
283 while (mp2 != NULL) {
284
285 /*
286 * The inner loop iterates until
287 * we've gotten 4 bytes or until
288 * the mblk is exhausted.
289 */
290 while (i < sizeof (dummy) &&
291 mp2->b_rptr < mp2->b_wptr) {
292
293 i++;
294
295 /*
296 * We avoid big-endian/little-endian
297 * issues by serializing the result
298 * one byte at a time.
299 */
300 dummy <<= 8;
301 dummy += ((*mp2->b_rptr) &
302 0xFF);
303
304 mp2->b_rptr++;
305 }
306
307 mp2 = mp2->b_cont;
308 }
309
310 freemsg(mp);
311 }
312
313 thetime = (time_t)dummy;
314 }
315
316 (void) t_kclose(tiptr, 1);
317
318 } else {
319 CLIENT *client;
320 struct timeval timout;
321
322 RPCLOG0(8, "rtime: using new method\n");
|