17c478bd9Sstevel@tonic-gate /*
27c478bd9Sstevel@tonic-gate * CDDL HEADER START
37c478bd9Sstevel@tonic-gate *
47c478bd9Sstevel@tonic-gate * The contents of this file are subject to the terms of the
57c478bd9Sstevel@tonic-gate * Common Development and Distribution License, Version 1.0 only
67c478bd9Sstevel@tonic-gate * (the "License"). You may not use this file except in compliance
77c478bd9Sstevel@tonic-gate * with the License.
87c478bd9Sstevel@tonic-gate *
97c478bd9Sstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
107c478bd9Sstevel@tonic-gate * or http://www.opensolaris.org/os/licensing.
117c478bd9Sstevel@tonic-gate * See the License for the specific language governing permissions
127c478bd9Sstevel@tonic-gate * and limitations under the License.
137c478bd9Sstevel@tonic-gate *
147c478bd9Sstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each
157c478bd9Sstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
167c478bd9Sstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the
177c478bd9Sstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying
187c478bd9Sstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner]
197c478bd9Sstevel@tonic-gate *
207c478bd9Sstevel@tonic-gate * CDDL HEADER END
217c478bd9Sstevel@tonic-gate */
227c478bd9Sstevel@tonic-gate /*
23*09b0d01cSGary Mills * Copyright 2014 Gary Mills
247c478bd9Sstevel@tonic-gate * Copyright 2001 Sun Microsystems, Inc. All rights reserved.
257c478bd9Sstevel@tonic-gate * Use is subject to license terms.
267c478bd9Sstevel@tonic-gate */
277c478bd9Sstevel@tonic-gate
287c478bd9Sstevel@tonic-gate /* Copyright (c) 1983, 1984, 1985, 1986, 1987, 1988, 1989 AT&T */
297c478bd9Sstevel@tonic-gate /* All Rights Reserved */
307c478bd9Sstevel@tonic-gate
317c478bd9Sstevel@tonic-gate /*
327c478bd9Sstevel@tonic-gate * Portions of this source code were derived from Berkeley 4.3 BSD
337c478bd9Sstevel@tonic-gate * under license from the Regents of the University of California.
347c478bd9Sstevel@tonic-gate */
357c478bd9Sstevel@tonic-gate
367c478bd9Sstevel@tonic-gate /*
377c478bd9Sstevel@tonic-gate * Miscellaneous support routines for kernel implentation of AUTH_DES
387c478bd9Sstevel@tonic-gate */
397c478bd9Sstevel@tonic-gate
407c478bd9Sstevel@tonic-gate /*
417c478bd9Sstevel@tonic-gate * rtime - get time from remote machine
427c478bd9Sstevel@tonic-gate *
437c478bd9Sstevel@tonic-gate * sets time, obtaining value from host
447c478bd9Sstevel@tonic-gate * on the udp/time socket. Since timeserver returns
457c478bd9Sstevel@tonic-gate * with time of day in seconds since Jan 1, 1900, must
467c478bd9Sstevel@tonic-gate * subtract 86400(365*70 + 17) to get time
477c478bd9Sstevel@tonic-gate * since Jan 1, 1970, which is what get/settimeofday
487c478bd9Sstevel@tonic-gate * uses.
497c478bd9Sstevel@tonic-gate */
507c478bd9Sstevel@tonic-gate #include <sys/param.h>
517c478bd9Sstevel@tonic-gate #include <sys/types.h>
527c478bd9Sstevel@tonic-gate #include <sys/time.h>
537c478bd9Sstevel@tonic-gate #include <sys/systm.h>
547c478bd9Sstevel@tonic-gate #include <sys/errno.h>
557c478bd9Sstevel@tonic-gate #include <sys/proc.h>
567c478bd9Sstevel@tonic-gate #include <sys/user.h>
577c478bd9Sstevel@tonic-gate #include <sys/socket.h>
587c478bd9Sstevel@tonic-gate #include <sys/sysmacros.h>
597c478bd9Sstevel@tonic-gate #include <netinet/in.h>
607c478bd9Sstevel@tonic-gate #include <rpc/rpc.h>
617c478bd9Sstevel@tonic-gate #include <sys/stream.h>
627c478bd9Sstevel@tonic-gate #include <sys/strsubr.h>
637c478bd9Sstevel@tonic-gate #include <sys/cred.h>
647c478bd9Sstevel@tonic-gate #include <sys/utsname.h>
657c478bd9Sstevel@tonic-gate #include <sys/vnode.h>
667c478bd9Sstevel@tonic-gate #include <sys/file.h>
677c478bd9Sstevel@tonic-gate #include <sys/uio.h>
687c478bd9Sstevel@tonic-gate #include <sys/systeminfo.h>
697c478bd9Sstevel@tonic-gate #include <rpc/rpcb_prot.h>
707c478bd9Sstevel@tonic-gate #include <sys/cmn_err.h>
717c478bd9Sstevel@tonic-gate
727c478bd9Sstevel@tonic-gate #define TOFFSET ((uint32_t)86400 * (365 * 70 + (70 / 4)))
737c478bd9Sstevel@tonic-gate #define WRITTEN ((uint32_t)86400 * (365 * 86 + (86 / 4)))
747c478bd9Sstevel@tonic-gate
757c478bd9Sstevel@tonic-gate #define NC_INET "inet" /* XXX */
767c478bd9Sstevel@tonic-gate
777c478bd9Sstevel@tonic-gate int
rtime(struct knetconfig * synconfig,struct netbuf * addrp,int calltype,struct timeval * timep,struct timeval * wait)787c478bd9Sstevel@tonic-gate rtime(struct knetconfig *synconfig, struct netbuf *addrp, int calltype,
797c478bd9Sstevel@tonic-gate struct timeval *timep, struct timeval *wait)
807c478bd9Sstevel@tonic-gate {
817c478bd9Sstevel@tonic-gate int error;
827c478bd9Sstevel@tonic-gate int timo;
837c478bd9Sstevel@tonic-gate time_t thetime;
847c478bd9Sstevel@tonic-gate int32_t srvtime;
857c478bd9Sstevel@tonic-gate uint32_t dummy;
867c478bd9Sstevel@tonic-gate struct t_kunitdata *unitdata;
877c478bd9Sstevel@tonic-gate struct t_call *server;
887c478bd9Sstevel@tonic-gate TIUSER *tiptr;
897c478bd9Sstevel@tonic-gate int type;
907c478bd9Sstevel@tonic-gate int uderr;
917c478bd9Sstevel@tonic-gate int i;
927c478bd9Sstevel@tonic-gate int retries;
937c478bd9Sstevel@tonic-gate mblk_t *mp;
947c478bd9Sstevel@tonic-gate mblk_t *mp2;
957c478bd9Sstevel@tonic-gate
967c478bd9Sstevel@tonic-gate retries = 5;
977c478bd9Sstevel@tonic-gate if (calltype == 0) {
987c478bd9Sstevel@tonic-gate again:
997c478bd9Sstevel@tonic-gate RPCLOG0(8, "rtime: using old method\n");
1007c478bd9Sstevel@tonic-gate if ((error = t_kopen(NULL, synconfig->knc_rdev,
1017c478bd9Sstevel@tonic-gate FREAD|FWRITE, &tiptr, CRED())) != 0) {
1027c478bd9Sstevel@tonic-gate RPCLOG(1, "rtime: t_kopen %d\n", error);
1037c478bd9Sstevel@tonic-gate return (-1);
1047c478bd9Sstevel@tonic-gate }
1057c478bd9Sstevel@tonic-gate
1067c478bd9Sstevel@tonic-gate if ((error = t_kbind(tiptr, NULL, NULL)) != 0) {
1077c478bd9Sstevel@tonic-gate (void) t_kclose(tiptr, 1);
1087c478bd9Sstevel@tonic-gate RPCLOG(1, "rtime: t_kbind %d\n", error);
1097c478bd9Sstevel@tonic-gate return (-1);
1107c478bd9Sstevel@tonic-gate }
1117c478bd9Sstevel@tonic-gate
1127c478bd9Sstevel@tonic-gate if (synconfig->knc_semantics == NC_TPI_CLTS) {
113*09b0d01cSGary Mills if ((error = t_kalloc(tiptr, T_UNITDATA,
114*09b0d01cSGary Mills T_UDATA|T_ADDR, (char **)&unitdata)) != 0) {
1157c478bd9Sstevel@tonic-gate RPCLOG(1, "rtime: t_kalloc %d\n", error);
1167c478bd9Sstevel@tonic-gate (void) t_kclose(tiptr, 1);
1177c478bd9Sstevel@tonic-gate return (-1);
1187c478bd9Sstevel@tonic-gate }
1197c478bd9Sstevel@tonic-gate
1207c478bd9Sstevel@tonic-gate unitdata->addr.len = addrp->len;
121*09b0d01cSGary Mills bcopy(addrp->buf, unitdata->addr.buf,
122*09b0d01cSGary Mills unitdata->addr.len);
1237c478bd9Sstevel@tonic-gate
1247c478bd9Sstevel@tonic-gate dummy = 0;
1257c478bd9Sstevel@tonic-gate unitdata->udata.buf = (caddr_t)&dummy;
1267c478bd9Sstevel@tonic-gate unitdata->udata.len = sizeof (dummy);
1277c478bd9Sstevel@tonic-gate
128*09b0d01cSGary Mills if ((error = t_ksndudata(tiptr, unitdata, NULL)) !=
129*09b0d01cSGary Mills 0) {
1307c478bd9Sstevel@tonic-gate RPCLOG(1, "rtime: t_ksndudata %d\n", error);
131*09b0d01cSGary Mills (void) t_kfree(tiptr, (char *)unitdata,
132*09b0d01cSGary Mills T_UNITDATA);
1337c478bd9Sstevel@tonic-gate (void) t_kclose(tiptr, 1);
1347c478bd9Sstevel@tonic-gate return (-1);
1357c478bd9Sstevel@tonic-gate }
1367c478bd9Sstevel@tonic-gate
1377c478bd9Sstevel@tonic-gate timo = TIMEVAL_TO_TICK(wait);
1387c478bd9Sstevel@tonic-gate
1397c478bd9Sstevel@tonic-gate RPCLOG(8, "rtime: timo %x\n", timo);
140*09b0d01cSGary Mills if ((error = t_kspoll(tiptr, timo, READWAIT,
141*09b0d01cSGary Mills &type)) != 0) {
1427c478bd9Sstevel@tonic-gate RPCLOG(1, "rtime: t_kspoll %d\n", error);
143*09b0d01cSGary Mills (void) t_kfree(tiptr, (char *)unitdata,
144*09b0d01cSGary Mills T_UNITDATA);
1457c478bd9Sstevel@tonic-gate (void) t_kclose(tiptr, 1);
1467c478bd9Sstevel@tonic-gate return (-1);
1477c478bd9Sstevel@tonic-gate }
1487c478bd9Sstevel@tonic-gate
1497c478bd9Sstevel@tonic-gate if (type == 0) {
1507c478bd9Sstevel@tonic-gate RPCLOG0(1, "rtime: t_kspoll timed out\n");
151*09b0d01cSGary Mills (void) t_kfree(tiptr, (char *)unitdata,
152*09b0d01cSGary Mills T_UNITDATA);
1537c478bd9Sstevel@tonic-gate (void) t_kclose(tiptr, 1);
1547c478bd9Sstevel@tonic-gate return (-1);
1557c478bd9Sstevel@tonic-gate }
1567c478bd9Sstevel@tonic-gate
1577c478bd9Sstevel@tonic-gate error = t_krcvudata(tiptr, unitdata, &type, &uderr);
1587c478bd9Sstevel@tonic-gate if (error != 0) {
1597c478bd9Sstevel@tonic-gate RPCLOG(1, "rtime: t_krcvudata %d\n", error);
160*09b0d01cSGary Mills (void) t_kfree(tiptr, (char *)unitdata,
161*09b0d01cSGary Mills T_UNITDATA);
1627c478bd9Sstevel@tonic-gate (void) t_kclose(tiptr, 1);
163*09b0d01cSGary Mills if (error == EBADMSG && retries-- > 0)
164*09b0d01cSGary Mills goto again;
1657c478bd9Sstevel@tonic-gate return (-1);
1667c478bd9Sstevel@tonic-gate }
1677c478bd9Sstevel@tonic-gate
1687c478bd9Sstevel@tonic-gate if (type == T_UDERR) {
1697c478bd9Sstevel@tonic-gate if (bcmp(addrp->buf, unitdata->addr.buf,
1707c478bd9Sstevel@tonic-gate unitdata->addr.len) != 0) {
1717c478bd9Sstevel@tonic-gate /*
1727c478bd9Sstevel@tonic-gate * Response comes from some other
1737c478bd9Sstevel@tonic-gate * destination:
1747c478bd9Sstevel@tonic-gate * ignore it since it's not related to the
1757c478bd9Sstevel@tonic-gate * request we just sent out.
1767c478bd9Sstevel@tonic-gate */
1777c478bd9Sstevel@tonic-gate (void) t_kfree(tiptr, (char *)unitdata,
1787c478bd9Sstevel@tonic-gate T_UNITDATA);
1797c478bd9Sstevel@tonic-gate (void) t_kclose(tiptr, 1);
1807c478bd9Sstevel@tonic-gate goto again;
1817c478bd9Sstevel@tonic-gate }
1827c478bd9Sstevel@tonic-gate }
1837c478bd9Sstevel@tonic-gate
1847c478bd9Sstevel@tonic-gate if (type != T_DATA) {
185*09b0d01cSGary Mills RPCLOG(1,
186*09b0d01cSGary Mills "rtime: t_krcvudata returned type %d\n",
1877c478bd9Sstevel@tonic-gate type);
188*09b0d01cSGary Mills (void) t_kfree(tiptr, (char *)unitdata,
189*09b0d01cSGary Mills T_UNITDATA);
1907c478bd9Sstevel@tonic-gate (void) t_kclose(tiptr, 1);
1917c478bd9Sstevel@tonic-gate if (retries-- == 0)
1927c478bd9Sstevel@tonic-gate return (-1);
1937c478bd9Sstevel@tonic-gate goto again;
1947c478bd9Sstevel@tonic-gate }
1957c478bd9Sstevel@tonic-gate
1967c478bd9Sstevel@tonic-gate if (unitdata->udata.len < sizeof (uint32_t)) {
1977c478bd9Sstevel@tonic-gate RPCLOG(1, "rtime: bad rcvd length %d\n",
1987c478bd9Sstevel@tonic-gate unitdata->udata.len);
199*09b0d01cSGary Mills (void) t_kfree(tiptr, (char *)unitdata,
200*09b0d01cSGary Mills T_UNITDATA);
2017c478bd9Sstevel@tonic-gate (void) t_kclose(tiptr, 1);
2027c478bd9Sstevel@tonic-gate if (retries-- == 0)
2037c478bd9Sstevel@tonic-gate return (-1);
2047c478bd9Sstevel@tonic-gate goto again;
2057c478bd9Sstevel@tonic-gate }
2067c478bd9Sstevel@tonic-gate
207*09b0d01cSGary Mills thetime = (time_t)ntohl(
2087c478bd9Sstevel@tonic-gate /* LINTED pointer alignment */
209*09b0d01cSGary Mills *(uint32_t *)unitdata->udata.buf);
2107c478bd9Sstevel@tonic-gate (void) t_kfree(tiptr, (char *)unitdata, T_UNITDATA);
2117c478bd9Sstevel@tonic-gate
2127c478bd9Sstevel@tonic-gate } else {
2137c478bd9Sstevel@tonic-gate
2147c478bd9Sstevel@tonic-gate if ((error = t_kalloc(tiptr, T_CALL, T_ADDR,
2157c478bd9Sstevel@tonic-gate (char **)&server)) != 0) {
2167c478bd9Sstevel@tonic-gate RPCLOG(1, "rtime: t_kalloc %d\n", error);
2177c478bd9Sstevel@tonic-gate (void) t_kclose(tiptr, 1);
2187c478bd9Sstevel@tonic-gate return (-1);
2197c478bd9Sstevel@tonic-gate }
2207c478bd9Sstevel@tonic-gate
2217c478bd9Sstevel@tonic-gate server->addr.len = addrp->len;
2227c478bd9Sstevel@tonic-gate bcopy(addrp->buf, server->addr.buf, server->addr.len);
2237c478bd9Sstevel@tonic-gate
2247c478bd9Sstevel@tonic-gate if ((error = t_kconnect(tiptr, server, NULL)) != 0) {
2257c478bd9Sstevel@tonic-gate RPCLOG(1, "rtime: t_kconnect %d\n", error);
2267c478bd9Sstevel@tonic-gate (void) t_kfree(tiptr, (char *)server, T_CALL);
2277c478bd9Sstevel@tonic-gate (void) t_kclose(tiptr, 1);
2287c478bd9Sstevel@tonic-gate return (-1);
2297c478bd9Sstevel@tonic-gate }
2307c478bd9Sstevel@tonic-gate (void) t_kfree(tiptr, (char *)server, T_CALL);
2317c478bd9Sstevel@tonic-gate
2327c478bd9Sstevel@tonic-gate timo = TIMEVAL_TO_TICK(wait);
2337c478bd9Sstevel@tonic-gate
2347c478bd9Sstevel@tonic-gate RPCLOG(8, "rtime: timo %x\n", timo);
2357c478bd9Sstevel@tonic-gate
2367c478bd9Sstevel@tonic-gate i = 0;
2377c478bd9Sstevel@tonic-gate dummy = 0;
2387c478bd9Sstevel@tonic-gate
2397c478bd9Sstevel@tonic-gate /* now read up to 4 bytes from the TIME server */
2407c478bd9Sstevel@tonic-gate while (i < sizeof (dummy)) {
2417c478bd9Sstevel@tonic-gate
2427c478bd9Sstevel@tonic-gate error = t_kspoll(tiptr, timo, READWAIT, &type);
2437c478bd9Sstevel@tonic-gate if (error != 0) {
244*09b0d01cSGary Mills RPCLOG(1, "rtime: t_kspoll %d\n",
245*09b0d01cSGary Mills error);
2467c478bd9Sstevel@tonic-gate (void) t_kclose(tiptr, 1);
2477c478bd9Sstevel@tonic-gate return (-1);
2487c478bd9Sstevel@tonic-gate }
2497c478bd9Sstevel@tonic-gate
2507c478bd9Sstevel@tonic-gate if (type == 0) {
251*09b0d01cSGary Mills RPCLOG0(1,
252*09b0d01cSGary Mills "rtime: t_kspoll timed out\n");
2537c478bd9Sstevel@tonic-gate (void) t_kclose(tiptr, 1);
2547c478bd9Sstevel@tonic-gate return (-1);
2557c478bd9Sstevel@tonic-gate }
2567c478bd9Sstevel@tonic-gate
257*09b0d01cSGary Mills error = tli_recv(tiptr, &mp,
258*09b0d01cSGary Mills tiptr->fp->f_flag);
2597c478bd9Sstevel@tonic-gate if (error != 0) {
260*09b0d01cSGary Mills RPCLOG(1, "rtime: tli_recv %d\n",
261*09b0d01cSGary Mills error);
2627c478bd9Sstevel@tonic-gate (void) t_kclose(tiptr, 1);
2637c478bd9Sstevel@tonic-gate return (-1);
2647c478bd9Sstevel@tonic-gate }
2657c478bd9Sstevel@tonic-gate
2667c478bd9Sstevel@tonic-gate if (mp->b_datap->db_type != M_DATA) {
2677c478bd9Sstevel@tonic-gate RPCLOG(1, "rtime: wrong msg type %d\n",
2687c478bd9Sstevel@tonic-gate mp->b_datap->db_type);
269*09b0d01cSGary Mills RPCLOG(1,
270*09b0d01cSGary Mills "rtime: wrong msg type: read %d"
2717c478bd9Sstevel@tonic-gate " bytes\n", i);
2727c478bd9Sstevel@tonic-gate (void) t_kclose(tiptr, 1);
2737c478bd9Sstevel@tonic-gate freemsg(mp);
2747c478bd9Sstevel@tonic-gate return (-1);
2757c478bd9Sstevel@tonic-gate }
2767c478bd9Sstevel@tonic-gate
2777c478bd9Sstevel@tonic-gate mp2 = mp;
2787c478bd9Sstevel@tonic-gate
2797c478bd9Sstevel@tonic-gate /*
280*09b0d01cSGary Mills * The outer loop iterates until we reach the
281*09b0d01cSGary Mills * end of the mblk chain.
2827c478bd9Sstevel@tonic-gate */
2837c478bd9Sstevel@tonic-gate while (mp2 != NULL) {
2847c478bd9Sstevel@tonic-gate
2857c478bd9Sstevel@tonic-gate /*
286*09b0d01cSGary Mills * The inner loop iterates until
287*09b0d01cSGary Mills * we've gotten 4 bytes or until
288*09b0d01cSGary Mills * the mblk is exhausted.
2897c478bd9Sstevel@tonic-gate */
2907c478bd9Sstevel@tonic-gate while (i < sizeof (dummy) &&
2917c478bd9Sstevel@tonic-gate mp2->b_rptr < mp2->b_wptr) {
2927c478bd9Sstevel@tonic-gate
2937c478bd9Sstevel@tonic-gate i++;
2947c478bd9Sstevel@tonic-gate
2957c478bd9Sstevel@tonic-gate /*
2967c478bd9Sstevel@tonic-gate * We avoid big-endian/little-endian
2977c478bd9Sstevel@tonic-gate * issues by serializing the result
2987c478bd9Sstevel@tonic-gate * one byte at a time.
2997c478bd9Sstevel@tonic-gate */
3007c478bd9Sstevel@tonic-gate dummy <<= 8;
301*09b0d01cSGary Mills dummy += ((*mp2->b_rptr) &
302*09b0d01cSGary Mills 0xFF);
3037c478bd9Sstevel@tonic-gate
3047c478bd9Sstevel@tonic-gate mp2->b_rptr++;
3057c478bd9Sstevel@tonic-gate }
3067c478bd9Sstevel@tonic-gate
3077c478bd9Sstevel@tonic-gate mp2 = mp2->b_cont;
3087c478bd9Sstevel@tonic-gate }
3097c478bd9Sstevel@tonic-gate
3107c478bd9Sstevel@tonic-gate freemsg(mp);
3117c478bd9Sstevel@tonic-gate }
3127c478bd9Sstevel@tonic-gate
3137c478bd9Sstevel@tonic-gate thetime = (time_t)dummy;
3147c478bd9Sstevel@tonic-gate }
3157c478bd9Sstevel@tonic-gate
3167c478bd9Sstevel@tonic-gate (void) t_kclose(tiptr, 1);
3177c478bd9Sstevel@tonic-gate
3187c478bd9Sstevel@tonic-gate } else {
3197c478bd9Sstevel@tonic-gate CLIENT *client;
3207c478bd9Sstevel@tonic-gate struct timeval timout;
3217c478bd9Sstevel@tonic-gate
3227c478bd9Sstevel@tonic-gate RPCLOG0(8, "rtime: using new method\n");
3237c478bd9Sstevel@tonic-gate
3247c478bd9Sstevel@tonic-gate new_again:
3257c478bd9Sstevel@tonic-gate /*
3267c478bd9Sstevel@tonic-gate * We talk to rpcbind.
3277c478bd9Sstevel@tonic-gate */
3287c478bd9Sstevel@tonic-gate error = clnt_tli_kcreate(synconfig, addrp, (rpcprog_t)RPCBPROG,
3297c478bd9Sstevel@tonic-gate (rpcvers_t)RPCBVERS, 0, retries, CRED(), &client);
3307c478bd9Sstevel@tonic-gate
3317c478bd9Sstevel@tonic-gate if (error != 0) {
3327c478bd9Sstevel@tonic-gate RPCLOG(1,
3337c478bd9Sstevel@tonic-gate "rtime: clnt_tli_kcreate returned %d\n", error);
3347c478bd9Sstevel@tonic-gate return (-1);
3357c478bd9Sstevel@tonic-gate }
3367c478bd9Sstevel@tonic-gate timout.tv_sec = 60;
3377c478bd9Sstevel@tonic-gate timout.tv_usec = 0;
3387c478bd9Sstevel@tonic-gate error = clnt_call(client, RPCBPROC_GETTIME, (xdrproc_t)xdr_void,
3397c478bd9Sstevel@tonic-gate NULL, (xdrproc_t)xdr_u_int,
3407c478bd9Sstevel@tonic-gate (caddr_t)&srvtime, timout);
3417c478bd9Sstevel@tonic-gate thetime = srvtime;
3427c478bd9Sstevel@tonic-gate auth_destroy(client->cl_auth);
3437c478bd9Sstevel@tonic-gate clnt_destroy(client);
3447c478bd9Sstevel@tonic-gate if (error == RPC_UDERROR) {
3457c478bd9Sstevel@tonic-gate if (retries-- > 0)
3467c478bd9Sstevel@tonic-gate goto new_again;
3477c478bd9Sstevel@tonic-gate }
3487c478bd9Sstevel@tonic-gate if (error != RPC_SUCCESS) {
3497c478bd9Sstevel@tonic-gate RPCLOG(1, "rtime: time sync clnt_call returned %d\n",
3507c478bd9Sstevel@tonic-gate error);
3517c478bd9Sstevel@tonic-gate error = EIO;
3527c478bd9Sstevel@tonic-gate return (-1);
3537c478bd9Sstevel@tonic-gate }
3547c478bd9Sstevel@tonic-gate }
3557c478bd9Sstevel@tonic-gate
3567c478bd9Sstevel@tonic-gate if (calltype != 0)
3577c478bd9Sstevel@tonic-gate thetime += TOFFSET;
3587c478bd9Sstevel@tonic-gate
3597c478bd9Sstevel@tonic-gate RPCLOG(8, "rtime: thetime = %lx\n", thetime);
3607c478bd9Sstevel@tonic-gate
3617c478bd9Sstevel@tonic-gate if (thetime < WRITTEN) {
3627c478bd9Sstevel@tonic-gate RPCLOG(1, "rtime: time returned is too far in past %lx",
3637c478bd9Sstevel@tonic-gate thetime);
3647c478bd9Sstevel@tonic-gate RPCLOG(1, "rtime: WRITTEN %x", WRITTEN);
3657c478bd9Sstevel@tonic-gate return (-1);
3667c478bd9Sstevel@tonic-gate }
3677c478bd9Sstevel@tonic-gate thetime -= TOFFSET;
3687c478bd9Sstevel@tonic-gate
3697c478bd9Sstevel@tonic-gate timep->tv_sec = thetime;
3707c478bd9Sstevel@tonic-gate RPCLOG(8, "rtime: timep->tv_sec = %lx\n", timep->tv_sec);
3717c478bd9Sstevel@tonic-gate RPCLOG(8, "rtime: machine time = %lx\n", gethrestime_sec());
3727c478bd9Sstevel@tonic-gate timep->tv_usec = 0;
3737c478bd9Sstevel@tonic-gate RPCLOG0(8, "rtime: returning success\n");
3747c478bd9Sstevel@tonic-gate return (0);
3757c478bd9Sstevel@tonic-gate }
3767c478bd9Sstevel@tonic-gate
3777c478bd9Sstevel@tonic-gate /*
3787c478bd9Sstevel@tonic-gate * What is my network name?
3797c478bd9Sstevel@tonic-gate * WARNING: this gets the network name in sun unix format.
3807c478bd9Sstevel@tonic-gate * Other operating systems (non-unix) are free to put something else
3817c478bd9Sstevel@tonic-gate * here.
3827c478bd9Sstevel@tonic-gate *
3837c478bd9Sstevel@tonic-gate * Return 0 on success
3847c478bd9Sstevel@tonic-gate * Return RPC errors (non-zero values) if failed.
3857c478bd9Sstevel@tonic-gate */
3867c478bd9Sstevel@tonic-gate enum clnt_stat
kgetnetname(char * netname)3877c478bd9Sstevel@tonic-gate kgetnetname(char *netname)
3887c478bd9Sstevel@tonic-gate {
3897c478bd9Sstevel@tonic-gate return (key_getnetname(netname, CRED()));
3907c478bd9Sstevel@tonic-gate }
391