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
5*67dbe2beSCasper H.S. Dik * Common Development and Distribution License (the "License").
6*67dbe2beSCasper H.S. Dik * You may not use this file except in compliance with the License.
77c478bd9Sstevel@tonic-gate *
87c478bd9Sstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
97c478bd9Sstevel@tonic-gate * or http://www.opensolaris.org/os/licensing.
107c478bd9Sstevel@tonic-gate * See the License for the specific language governing permissions
117c478bd9Sstevel@tonic-gate * and limitations under the License.
127c478bd9Sstevel@tonic-gate *
137c478bd9Sstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each
147c478bd9Sstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
157c478bd9Sstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the
167c478bd9Sstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying
177c478bd9Sstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner]
187c478bd9Sstevel@tonic-gate *
197c478bd9Sstevel@tonic-gate * CDDL HEADER END
2061961e0fSrobinson */
2161961e0fSrobinson
2261961e0fSrobinson /*
23*67dbe2beSCasper H.S. Dik * Copyright 2009 Sun Microsystems, Inc. All rights reserved.
247c478bd9Sstevel@tonic-gate * Use is subject to license terms.
257c478bd9Sstevel@tonic-gate */
267c478bd9Sstevel@tonic-gate /* Copyright (c) 1983, 1984, 1985, 1986, 1987, 1988, 1989 AT&T */
277c478bd9Sstevel@tonic-gate /* All Rights Reserved */
287c478bd9Sstevel@tonic-gate /*
297c478bd9Sstevel@tonic-gate * Portions of this source code were derived from Berkeley
307c478bd9Sstevel@tonic-gate * 4.3 BSD under license from the Regents of the University of
317c478bd9Sstevel@tonic-gate * California.
327c478bd9Sstevel@tonic-gate */
337c478bd9Sstevel@tonic-gate
347c478bd9Sstevel@tonic-gate /*
357c478bd9Sstevel@tonic-gate * auth_sys.c, Implements UNIX (system) style authentication parameters.
367c478bd9Sstevel@tonic-gate *
377c478bd9Sstevel@tonic-gate * The system is very weak. The client uses no encryption for its
387c478bd9Sstevel@tonic-gate * credentials and only sends null verifiers. The server sends backs
397c478bd9Sstevel@tonic-gate * null verifiers or optionally a verifier that suggests a new short hand
407c478bd9Sstevel@tonic-gate * for the credentials.
417c478bd9Sstevel@tonic-gate *
427c478bd9Sstevel@tonic-gate */
437c478bd9Sstevel@tonic-gate #include "mt.h"
447c478bd9Sstevel@tonic-gate #include "rpc_mt.h"
45*67dbe2beSCasper H.S. Dik #include <alloca.h>
467c478bd9Sstevel@tonic-gate #include <stdio.h>
477c478bd9Sstevel@tonic-gate #include <syslog.h>
487c478bd9Sstevel@tonic-gate #include <stdlib.h>
497c478bd9Sstevel@tonic-gate #include <unistd.h>
507c478bd9Sstevel@tonic-gate #include <string.h>
517c478bd9Sstevel@tonic-gate #include <rpc/types.h>
527c478bd9Sstevel@tonic-gate #include <rpc/xdr.h>
537c478bd9Sstevel@tonic-gate #include <rpc/auth.h>
547c478bd9Sstevel@tonic-gate #include <rpc/auth_sys.h>
557c478bd9Sstevel@tonic-gate #include <synch.h>
567c478bd9Sstevel@tonic-gate
5761961e0fSrobinson extern int gethostname(char *, int);
5861961e0fSrobinson extern bool_t xdr_opaque_auth(XDR *, struct opaque_auth *);
597c478bd9Sstevel@tonic-gate
6061961e0fSrobinson static struct auth_ops *authsys_ops(void);
617c478bd9Sstevel@tonic-gate
627c478bd9Sstevel@tonic-gate /*
637c478bd9Sstevel@tonic-gate * This struct is pointed to by the ah_private field of an auth_handle.
647c478bd9Sstevel@tonic-gate */
657c478bd9Sstevel@tonic-gate struct audata {
667c478bd9Sstevel@tonic-gate struct opaque_auth au_origcred; /* original credentials */
677c478bd9Sstevel@tonic-gate struct opaque_auth au_shcred; /* short hand cred */
687c478bd9Sstevel@tonic-gate uint_t au_shfaults; /* short hand cache faults */
697c478bd9Sstevel@tonic-gate char au_marshed[MAX_AUTH_BYTES];
707c478bd9Sstevel@tonic-gate uint_t au_mpos; /* xdr pos at end of marshed */
717c478bd9Sstevel@tonic-gate };
727c478bd9Sstevel@tonic-gate #define AUTH_PRIVATE(auth) ((struct audata *)auth->ah_private)
737c478bd9Sstevel@tonic-gate
747c478bd9Sstevel@tonic-gate static void marshal_new_auth();
757c478bd9Sstevel@tonic-gate
767c478bd9Sstevel@tonic-gate static const char auth_sys_str[] = "%s : %s";
777c478bd9Sstevel@tonic-gate static const char authsys_create_str[] = "authsys_create";
787c478bd9Sstevel@tonic-gate static const char __no_mem_auth[] = "out of memory";
797c478bd9Sstevel@tonic-gate
807c478bd9Sstevel@tonic-gate /*
817c478bd9Sstevel@tonic-gate * Create a (sys) unix style authenticator.
827c478bd9Sstevel@tonic-gate * Returns an auth handle with the given stuff in it.
837c478bd9Sstevel@tonic-gate */
847c478bd9Sstevel@tonic-gate AUTH *
authsys_create(const char * machname,const uid_t uid,const gid_t gid,const int len,const gid_t * aup_gids)8561961e0fSrobinson authsys_create(const char *machname, const uid_t uid, const gid_t gid,
8661961e0fSrobinson const int len, const gid_t *aup_gids)
877c478bd9Sstevel@tonic-gate {
887c478bd9Sstevel@tonic-gate struct authsys_parms aup;
897c478bd9Sstevel@tonic-gate char mymem[MAX_AUTH_BYTES];
907c478bd9Sstevel@tonic-gate struct timeval now;
917c478bd9Sstevel@tonic-gate XDR xdrs;
927c478bd9Sstevel@tonic-gate AUTH *auth;
937c478bd9Sstevel@tonic-gate struct audata *au;
947c478bd9Sstevel@tonic-gate
957c478bd9Sstevel@tonic-gate /*
967c478bd9Sstevel@tonic-gate * Allocate and set up auth handle
977c478bd9Sstevel@tonic-gate */
9861961e0fSrobinson auth = malloc(sizeof (*auth));
997c478bd9Sstevel@tonic-gate if (auth == NULL) {
1007c478bd9Sstevel@tonic-gate (void) syslog(LOG_ERR, auth_sys_str, authsys_create_str,
1017c478bd9Sstevel@tonic-gate __no_mem_auth);
1027c478bd9Sstevel@tonic-gate return (NULL);
1037c478bd9Sstevel@tonic-gate }
10461961e0fSrobinson au = malloc(sizeof (*au));
1057c478bd9Sstevel@tonic-gate if (au == NULL) {
1067c478bd9Sstevel@tonic-gate (void) syslog(LOG_ERR, auth_sys_str, authsys_create_str,
1077c478bd9Sstevel@tonic-gate __no_mem_auth);
10861961e0fSrobinson free(auth);
1097c478bd9Sstevel@tonic-gate return (NULL);
1107c478bd9Sstevel@tonic-gate }
1117c478bd9Sstevel@tonic-gate auth->ah_ops = authsys_ops();
1127c478bd9Sstevel@tonic-gate auth->ah_private = (caddr_t)au;
1137c478bd9Sstevel@tonic-gate auth->ah_verf = au->au_shcred = _null_auth;
1147c478bd9Sstevel@tonic-gate au->au_shfaults = 0;
1157c478bd9Sstevel@tonic-gate
1167c478bd9Sstevel@tonic-gate /*
1177c478bd9Sstevel@tonic-gate * fill in param struct from the given params
1187c478bd9Sstevel@tonic-gate */
1197c478bd9Sstevel@tonic-gate (void) gettimeofday(&now, (struct timezone *)0);
1207c478bd9Sstevel@tonic-gate aup.aup_time = now.tv_sec;
1217c478bd9Sstevel@tonic-gate aup.aup_machname = (char *)machname;
1227c478bd9Sstevel@tonic-gate aup.aup_uid = uid;
1237c478bd9Sstevel@tonic-gate aup.aup_gid = gid;
1247c478bd9Sstevel@tonic-gate aup.aup_len = (uint_t)len;
1257c478bd9Sstevel@tonic-gate aup.aup_gids = (gid_t *)aup_gids;
1267c478bd9Sstevel@tonic-gate
1277c478bd9Sstevel@tonic-gate /*
1287c478bd9Sstevel@tonic-gate * Serialize the parameters into origcred
1297c478bd9Sstevel@tonic-gate */
1307c478bd9Sstevel@tonic-gate xdrmem_create(&xdrs, mymem, MAX_AUTH_BYTES, XDR_ENCODE);
1317c478bd9Sstevel@tonic-gate if (!xdr_authsys_parms(&xdrs, &aup)) {
1327c478bd9Sstevel@tonic-gate (void) syslog(LOG_ERR, auth_sys_str, authsys_create_str,
1337c478bd9Sstevel@tonic-gate ": xdr_authsys_parms failed");
1347c478bd9Sstevel@tonic-gate return (NULL);
1357c478bd9Sstevel@tonic-gate }
13661961e0fSrobinson au->au_origcred.oa_length = XDR_GETPOS(&xdrs);
1377c478bd9Sstevel@tonic-gate au->au_origcred.oa_flavor = AUTH_SYS;
13861961e0fSrobinson if ((au->au_origcred.oa_base = malloc(au->au_origcred.oa_length)) ==
13961961e0fSrobinson NULL) {
1407c478bd9Sstevel@tonic-gate (void) syslog(LOG_ERR, auth_sys_str, authsys_create_str,
1417c478bd9Sstevel@tonic-gate __no_mem_auth);
14261961e0fSrobinson free(au);
14361961e0fSrobinson free(auth);
1447c478bd9Sstevel@tonic-gate return (NULL);
1457c478bd9Sstevel@tonic-gate }
14661961e0fSrobinson (void) memcpy(au->au_origcred.oa_base, mymem,
14761961e0fSrobinson (size_t)au->au_origcred.oa_length);
1487c478bd9Sstevel@tonic-gate
1497c478bd9Sstevel@tonic-gate /*
1507c478bd9Sstevel@tonic-gate * set auth handle to reflect new cred.
1517c478bd9Sstevel@tonic-gate */
1527c478bd9Sstevel@tonic-gate auth->ah_cred = au->au_origcred;
1537c478bd9Sstevel@tonic-gate (void) marshal_new_auth(auth);
1547c478bd9Sstevel@tonic-gate return (auth);
1557c478bd9Sstevel@tonic-gate }
1567c478bd9Sstevel@tonic-gate
1577c478bd9Sstevel@tonic-gate /*
1587c478bd9Sstevel@tonic-gate * authsys_create_default is a public interface.
1597c478bd9Sstevel@tonic-gate *
1607c478bd9Sstevel@tonic-gate * Returns an auth handle with parameters determined by doing lots of
1617c478bd9Sstevel@tonic-gate * syscalls.
1627c478bd9Sstevel@tonic-gate */
1637c478bd9Sstevel@tonic-gate
1647c478bd9Sstevel@tonic-gate static const char authsys_def_str[] =
1657c478bd9Sstevel@tonic-gate "authsys_create_default: get%s failed: %m";
1667c478bd9Sstevel@tonic-gate
1677c478bd9Sstevel@tonic-gate AUTH *
authsys_create_default(void)1687c478bd9Sstevel@tonic-gate authsys_create_default(void)
1697c478bd9Sstevel@tonic-gate {
1707c478bd9Sstevel@tonic-gate int len;
1717c478bd9Sstevel@tonic-gate char machname[MAX_MACHINE_NAME + 1];
1727c478bd9Sstevel@tonic-gate uid_t uid;
1737c478bd9Sstevel@tonic-gate gid_t gid;
174*67dbe2beSCasper H.S. Dik int maxgrp = getgroups(0, NULL);
175*67dbe2beSCasper H.S. Dik gid_t *gids = alloca(maxgrp * sizeof (gid_t));
1767c478bd9Sstevel@tonic-gate
1777c478bd9Sstevel@tonic-gate if (gethostname(machname, MAX_MACHINE_NAME) == -1) {
1787c478bd9Sstevel@tonic-gate (void) syslog(LOG_ERR, authsys_def_str, "hostname");
1797c478bd9Sstevel@tonic-gate return (NULL);
1807c478bd9Sstevel@tonic-gate }
1817c478bd9Sstevel@tonic-gate machname[MAX_MACHINE_NAME] = 0;
1827c478bd9Sstevel@tonic-gate uid = geteuid();
1837c478bd9Sstevel@tonic-gate gid = getegid();
184*67dbe2beSCasper H.S. Dik if ((len = getgroups(maxgrp, gids)) < 0) {
1857c478bd9Sstevel@tonic-gate (void) syslog(LOG_ERR, authsys_def_str, "groups");
1867c478bd9Sstevel@tonic-gate return (NULL);
1877c478bd9Sstevel@tonic-gate }
188*67dbe2beSCasper H.S. Dik if (len > NGRPS)
189*67dbe2beSCasper H.S. Dik len = NGRPS;
19061961e0fSrobinson return (authsys_create(machname, uid, gid, len, gids));
1917c478bd9Sstevel@tonic-gate }
1927c478bd9Sstevel@tonic-gate
1937c478bd9Sstevel@tonic-gate /*
1947c478bd9Sstevel@tonic-gate * authsys_create_ruid() is a private routine and is a
1957c478bd9Sstevel@tonic-gate * variant of authsys_create_default().
1967c478bd9Sstevel@tonic-gate *
1977c478bd9Sstevel@tonic-gate * authsys_create_default() is using the effective uid.
1987c478bd9Sstevel@tonic-gate * authsys_create_ruid() is using the real uid.
1997c478bd9Sstevel@tonic-gate *
2007c478bd9Sstevel@tonic-gate * This routine is used by key_call_ext() in key_call.c
2017c478bd9Sstevel@tonic-gate */
2027c478bd9Sstevel@tonic-gate AUTH *
authsys_create_ruid(void)2037c478bd9Sstevel@tonic-gate authsys_create_ruid(void)
2047c478bd9Sstevel@tonic-gate {
2057c478bd9Sstevel@tonic-gate int len;
2067c478bd9Sstevel@tonic-gate char machname[MAX_MACHINE_NAME + 1];
2077c478bd9Sstevel@tonic-gate uid_t uid;
2087c478bd9Sstevel@tonic-gate gid_t gid;
209*67dbe2beSCasper H.S. Dik int maxgrp = getgroups(0, NULL);
210*67dbe2beSCasper H.S. Dik gid_t *gids = alloca(maxgrp * sizeof (gid_t));
2117c478bd9Sstevel@tonic-gate AUTH *res;
2127c478bd9Sstevel@tonic-gate
2137c478bd9Sstevel@tonic-gate if (gethostname(machname, MAX_MACHINE_NAME) == -1) {
2147c478bd9Sstevel@tonic-gate (void) syslog(LOG_ERR,
2157c478bd9Sstevel@tonic-gate "authsys_create_ruid:gethostname failed");
2167c478bd9Sstevel@tonic-gate return (NULL);
2177c478bd9Sstevel@tonic-gate }
2187c478bd9Sstevel@tonic-gate machname[MAX_MACHINE_NAME] = 0;
2197c478bd9Sstevel@tonic-gate uid = getuid();
2207c478bd9Sstevel@tonic-gate gid = getgid();
221*67dbe2beSCasper H.S. Dik if ((len = getgroups(maxgrp, gids)) < 0) {
2227c478bd9Sstevel@tonic-gate (void) syslog(LOG_ERR,
2237c478bd9Sstevel@tonic-gate "authsys_create_ruid:getgroups failed");
2247c478bd9Sstevel@tonic-gate return (NULL);
2257c478bd9Sstevel@tonic-gate }
226*67dbe2beSCasper H.S. Dik if (len > NGRPS)
227*67dbe2beSCasper H.S. Dik len = NGRPS;
2287c478bd9Sstevel@tonic-gate res = authsys_create(machname, uid, gid, len, gids);
2297c478bd9Sstevel@tonic-gate return (res);
2307c478bd9Sstevel@tonic-gate }
2317c478bd9Sstevel@tonic-gate
2327c478bd9Sstevel@tonic-gate /*
2337c478bd9Sstevel@tonic-gate * authsys operations
2347c478bd9Sstevel@tonic-gate */
2357c478bd9Sstevel@tonic-gate
2367c478bd9Sstevel@tonic-gate /*ARGSUSED*/
2377c478bd9Sstevel@tonic-gate static void
authsys_nextverf(AUTH * auth)2387c478bd9Sstevel@tonic-gate authsys_nextverf(AUTH *auth)
2397c478bd9Sstevel@tonic-gate {
2407c478bd9Sstevel@tonic-gate /* no action necessary */
2417c478bd9Sstevel@tonic-gate }
2427c478bd9Sstevel@tonic-gate
2437c478bd9Sstevel@tonic-gate static bool_t
authsys_marshal(AUTH * auth,XDR * xdrs)2447c478bd9Sstevel@tonic-gate authsys_marshal(AUTH *auth, XDR *xdrs)
2457c478bd9Sstevel@tonic-gate {
2467c478bd9Sstevel@tonic-gate /* LINTED pointer alignment */
2477c478bd9Sstevel@tonic-gate struct audata *au = AUTH_PRIVATE(auth);
2487c478bd9Sstevel@tonic-gate
24961961e0fSrobinson return (XDR_PUTBYTES(xdrs, au->au_marshed, au->au_mpos));
2507c478bd9Sstevel@tonic-gate }
2517c478bd9Sstevel@tonic-gate
2527c478bd9Sstevel@tonic-gate static bool_t
authsys_validate(AUTH * auth,struct opaque_auth * verf)2537c478bd9Sstevel@tonic-gate authsys_validate(AUTH *auth, struct opaque_auth *verf)
2547c478bd9Sstevel@tonic-gate {
2557c478bd9Sstevel@tonic-gate struct audata *au;
2567c478bd9Sstevel@tonic-gate XDR xdrs;
2577c478bd9Sstevel@tonic-gate
2587c478bd9Sstevel@tonic-gate if (verf->oa_flavor == AUTH_SHORT) {
2597c478bd9Sstevel@tonic-gate /* LINTED pointer alignment */
2607c478bd9Sstevel@tonic-gate au = AUTH_PRIVATE(auth);
2617c478bd9Sstevel@tonic-gate xdrmem_create(&xdrs, verf->oa_base,
2627c478bd9Sstevel@tonic-gate verf->oa_length, XDR_DECODE);
2637c478bd9Sstevel@tonic-gate
2647c478bd9Sstevel@tonic-gate if (au->au_shcred.oa_base != NULL) {
26561961e0fSrobinson free(au->au_shcred.oa_base);
2667c478bd9Sstevel@tonic-gate au->au_shcred.oa_base = NULL;
2677c478bd9Sstevel@tonic-gate }
2687c478bd9Sstevel@tonic-gate if (xdr_opaque_auth(&xdrs, &au->au_shcred)) {
2697c478bd9Sstevel@tonic-gate auth->ah_cred = au->au_shcred;
2707c478bd9Sstevel@tonic-gate } else {
2717c478bd9Sstevel@tonic-gate xdrs.x_op = XDR_FREE;
2727c478bd9Sstevel@tonic-gate (void) xdr_opaque_auth(&xdrs, &au->au_shcred);
2737c478bd9Sstevel@tonic-gate au->au_shcred.oa_base = NULL;
2747c478bd9Sstevel@tonic-gate auth->ah_cred = au->au_origcred;
2757c478bd9Sstevel@tonic-gate }
2767c478bd9Sstevel@tonic-gate (void) marshal_new_auth(auth);
2777c478bd9Sstevel@tonic-gate }
2787c478bd9Sstevel@tonic-gate return (TRUE);
2797c478bd9Sstevel@tonic-gate }
2807c478bd9Sstevel@tonic-gate
2817c478bd9Sstevel@tonic-gate /*ARGSUSED*/
2827c478bd9Sstevel@tonic-gate static bool_t
authsys_refresh(AUTH * auth,void * dummy)2837c478bd9Sstevel@tonic-gate authsys_refresh(AUTH *auth, void *dummy)
2847c478bd9Sstevel@tonic-gate {
2857c478bd9Sstevel@tonic-gate /* LINTED pointer alignment */
2867c478bd9Sstevel@tonic-gate struct audata *au = AUTH_PRIVATE(auth);
2877c478bd9Sstevel@tonic-gate struct authsys_parms aup;
2887c478bd9Sstevel@tonic-gate struct timeval now;
2897c478bd9Sstevel@tonic-gate XDR xdrs;
2907c478bd9Sstevel@tonic-gate int stat;
2917c478bd9Sstevel@tonic-gate
29261961e0fSrobinson if (auth->ah_cred.oa_base == au->au_origcred.oa_base)
29361961e0fSrobinson return (FALSE); /* there is no hope. Punt */
2947c478bd9Sstevel@tonic-gate au->au_shfaults ++;
2957c478bd9Sstevel@tonic-gate
2967c478bd9Sstevel@tonic-gate /* first deserialize the creds back into a struct authsys_parms */
2977c478bd9Sstevel@tonic-gate aup.aup_machname = NULL;
29861961e0fSrobinson aup.aup_gids = NULL;
2997c478bd9Sstevel@tonic-gate xdrmem_create(&xdrs, au->au_origcred.oa_base,
3007c478bd9Sstevel@tonic-gate au->au_origcred.oa_length, XDR_DECODE);
3017c478bd9Sstevel@tonic-gate stat = xdr_authsys_parms(&xdrs, &aup);
3027c478bd9Sstevel@tonic-gate if (!stat)
3037c478bd9Sstevel@tonic-gate goto done;
3047c478bd9Sstevel@tonic-gate
3057c478bd9Sstevel@tonic-gate /* update the time and serialize in place */
3067c478bd9Sstevel@tonic-gate (void) gettimeofday(&now, (struct timezone *)0);
3077c478bd9Sstevel@tonic-gate aup.aup_time = now.tv_sec;
3087c478bd9Sstevel@tonic-gate xdrs.x_op = XDR_ENCODE;
3097c478bd9Sstevel@tonic-gate XDR_SETPOS(&xdrs, 0);
3107c478bd9Sstevel@tonic-gate stat = xdr_authsys_parms(&xdrs, &aup);
3117c478bd9Sstevel@tonic-gate if (!stat)
3127c478bd9Sstevel@tonic-gate goto done;
3137c478bd9Sstevel@tonic-gate auth->ah_cred = au->au_origcred;
3147c478bd9Sstevel@tonic-gate (void) marshal_new_auth(auth);
3157c478bd9Sstevel@tonic-gate done:
3167c478bd9Sstevel@tonic-gate /* free the struct authsys_parms created by deserializing */
3177c478bd9Sstevel@tonic-gate xdrs.x_op = XDR_FREE;
3187c478bd9Sstevel@tonic-gate (void) xdr_authsys_parms(&xdrs, &aup);
3197c478bd9Sstevel@tonic-gate XDR_DESTROY(&xdrs);
3207c478bd9Sstevel@tonic-gate return (stat);
3217c478bd9Sstevel@tonic-gate }
3227c478bd9Sstevel@tonic-gate
3237c478bd9Sstevel@tonic-gate static void
authsys_destroy(AUTH * auth)3247c478bd9Sstevel@tonic-gate authsys_destroy(AUTH *auth)
3257c478bd9Sstevel@tonic-gate {
3267c478bd9Sstevel@tonic-gate /* LINTED pointer alignment */
3277c478bd9Sstevel@tonic-gate struct audata *au = AUTH_PRIVATE(auth);
3287c478bd9Sstevel@tonic-gate
32961961e0fSrobinson free(au->au_origcred.oa_base);
3307c478bd9Sstevel@tonic-gate if (au->au_shcred.oa_base != NULL)
33161961e0fSrobinson free(au->au_shcred.oa_base);
33261961e0fSrobinson free(auth->ah_private);
3337c478bd9Sstevel@tonic-gate if (auth->ah_verf.oa_base != NULL)
33461961e0fSrobinson free(auth->ah_verf.oa_base);
33561961e0fSrobinson free(auth);
3367c478bd9Sstevel@tonic-gate }
3377c478bd9Sstevel@tonic-gate
3387c478bd9Sstevel@tonic-gate /*
3397c478bd9Sstevel@tonic-gate * Marshals (pre-serializes) an auth struct.
3407c478bd9Sstevel@tonic-gate * sets private data, au_marshed and au_mpos
3417c478bd9Sstevel@tonic-gate */
3427c478bd9Sstevel@tonic-gate
3437c478bd9Sstevel@tonic-gate static const char marshal_new_auth_str[] =
3447c478bd9Sstevel@tonic-gate "marshal_new_auth - Fatal marshalling problem";
3457c478bd9Sstevel@tonic-gate static void
marshal_new_auth(AUTH * auth)3467c478bd9Sstevel@tonic-gate marshal_new_auth(AUTH *auth)
3477c478bd9Sstevel@tonic-gate {
3487c478bd9Sstevel@tonic-gate XDR xdr_stream;
3497c478bd9Sstevel@tonic-gate XDR *xdrs = &xdr_stream;
3507c478bd9Sstevel@tonic-gate /* LINTED pointer alignment */
3517c478bd9Sstevel@tonic-gate struct audata *au = AUTH_PRIVATE(auth);
3527c478bd9Sstevel@tonic-gate
3537c478bd9Sstevel@tonic-gate xdrmem_create(xdrs, au->au_marshed, MAX_AUTH_BYTES, XDR_ENCODE);
3547c478bd9Sstevel@tonic-gate if ((!xdr_opaque_auth(xdrs, &(auth->ah_cred))) ||
3557c478bd9Sstevel@tonic-gate (!xdr_opaque_auth(xdrs, &(auth->ah_verf)))) {
3567c478bd9Sstevel@tonic-gate (void) syslog(LOG_ERR, marshal_new_auth_str);
3577c478bd9Sstevel@tonic-gate } else {
3587c478bd9Sstevel@tonic-gate au->au_mpos = XDR_GETPOS(xdrs);
3597c478bd9Sstevel@tonic-gate }
3607c478bd9Sstevel@tonic-gate XDR_DESTROY(xdrs);
3617c478bd9Sstevel@tonic-gate }
3627c478bd9Sstevel@tonic-gate
3637c478bd9Sstevel@tonic-gate static struct auth_ops *
authsys_ops(void)3647c478bd9Sstevel@tonic-gate authsys_ops(void)
3657c478bd9Sstevel@tonic-gate {
3667c478bd9Sstevel@tonic-gate static struct auth_ops ops;
3677c478bd9Sstevel@tonic-gate extern mutex_t ops_lock;
3687c478bd9Sstevel@tonic-gate
3697c478bd9Sstevel@tonic-gate /* VARIABLES PROTECTED BY ops_lock: ops */
3707c478bd9Sstevel@tonic-gate
37161961e0fSrobinson (void) mutex_lock(&ops_lock);
3727c478bd9Sstevel@tonic-gate if (ops.ah_nextverf == NULL) {
3737c478bd9Sstevel@tonic-gate ops.ah_nextverf = authsys_nextverf;
3747c478bd9Sstevel@tonic-gate ops.ah_marshal = authsys_marshal;
3757c478bd9Sstevel@tonic-gate ops.ah_validate = authsys_validate;
3767c478bd9Sstevel@tonic-gate ops.ah_refresh = authsys_refresh;
3777c478bd9Sstevel@tonic-gate ops.ah_destroy = authsys_destroy;
3787c478bd9Sstevel@tonic-gate }
37961961e0fSrobinson (void) mutex_unlock(&ops_lock);
3807c478bd9Sstevel@tonic-gate return (&ops);
3817c478bd9Sstevel@tonic-gate }
382