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
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.
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]
24 * Copyright 2015 Nexenta Systems, Inc. All rights reserved.
28 * Copyright 2003 Sun Microsystems, Inc. All rights reserved.
29 * Use is subject to license terms.
33 * Kernel code to obtain client handle to gssd server
36 #include <sys/types.h>
37 #include <gssapi/gssapi.h>
38 #include <gssapi/gssd_prot.h>
39 #include <gssapi/kgssapi_defs.h>
41 #include <sys/systm.h>
42 #include <sys/vnode.h>
44 #include <sys/pathname.h>
48 kmutex_t gssrpcb_lock
;
49 zone_key_t gss_zone_key
;
52 enum clnt_stat gss_last_stat
;
53 struct netbuf gss_netaddr
;
54 struct knetconfig gss_config
;
59 gss_zone_init(zoneid_t zoneid
)
61 struct gss_globals
*gssg
;
63 gssg
= kmem_zalloc(sizeof (*gssg
), KM_SLEEP
);
69 gss_zone_fini(zoneid_t zoneid
, void *data
)
71 struct gss_globals
*gssg
= data
;
72 struct netbuf
*netaddrp
= &gssg
->gss_netaddr
;
74 if (netaddrp
->len
!= 0)
75 kmem_free(netaddrp
->buf
, netaddrp
->maxlen
);
76 kmem_free(gssg
, sizeof (*gssg
));
80 killgssd_handle(CLIENT
*client
)
82 struct rpc_err rpcerr
;
83 struct gss_globals
*gssg
;
85 gssg
= zone_getspecific(gss_zone_key
, curproc
->p_zone
);
86 CLNT_GETERR(client
, &rpcerr
);
87 gssg
->gss_last_stat
= rpcerr
.re_status
;
89 AUTH_DESTROY(client
->cl_auth
);
100 struct netbuf tmpaddr
;
101 struct gss_globals
*gssg
;
102 struct netbuf
*netaddrp
;
104 gssg
= zone_getspecific(gss_zone_key
, curproc
->p_zone
);
106 * Cribbed from kerb_krpc.c. Really should do the config set up
107 * in the _init routine.
109 if (gssg
->gss_config
.knc_rdev
== 0) {
110 if ((error
= lookupname("/dev/ticotsord", UIO_SYSSPACE
,
111 FOLLOW
, NULLVPP
, &vp
)) != 0) {
112 GSSLOG(1, "getgssd_handle: lookupname: %d\n", error
);
115 gssg
->gss_config
.knc_rdev
= vp
->v_rdev
;
116 gssg
->gss_config
.knc_protofmly
= loopback_name
;
118 gssg
->gss_config
.knc_semantics
= NC_TPI_COTS_ORD
;
122 * Contact rpcbind to get gssd's address only
123 * once and re-use the address.
125 mutex_enter(&gssrpcb_lock
);
126 netaddrp
= &gssg
->gss_netaddr
;
128 if (netaddrp
->len
== 0 || gssg
->gss_last_stat
!= RPC_SUCCESS
) {
129 if (netaddrp
->buf
!= NULL
)
130 kmem_free(netaddrp
->buf
, netaddrp
->maxlen
);
132 /* Set up netaddr to be "localhost." (strlen is 10) */
133 netaddrp
->len
= netaddrp
->maxlen
= 10;
134 netaddrp
->buf
= kmem_alloc(netaddrp
->len
, KM_SLEEP
);
135 (void) strncpy(netaddrp
->buf
, "localhost.", netaddrp
->len
);
137 /* Get address of gssd from rpcbind */
138 stat
= rpcbind_getaddr(&gssg
->gss_config
, GSSPROG
, GSSVERS
,
140 if (stat
!= RPC_SUCCESS
) {
141 kmem_free(netaddrp
->buf
, netaddrp
->maxlen
);
142 netaddrp
->buf
= NULL
;
143 netaddrp
->len
= netaddrp
->maxlen
= 0;
144 mutex_exit(&gssrpcb_lock
);
150 * Copy the netaddr information into a tmp location to
151 * be used by clnt_tli_kcreate. The purpose of this
152 * is for MT race condition (ie. netaddr being modified
153 * while it is being used.)
155 tmpaddr
.buf
= kmem_zalloc(netaddrp
->maxlen
, KM_SLEEP
);
156 bcopy(netaddrp
->buf
, tmpaddr
.buf
, netaddrp
->maxlen
);
157 tmpaddr
.maxlen
= netaddrp
->maxlen
;
158 tmpaddr
.len
= netaddrp
->len
;
160 mutex_exit(&gssrpcb_lock
);
162 error
= clnt_tli_kcreate(&gssg
->gss_config
, &tmpaddr
, GSSPROG
,
163 GSSVERS
, 0, GSSD_RETRY
, kcred
, &clnt
);
165 kmem_free(tmpaddr
.buf
, tmpaddr
.maxlen
);
169 "getgssd_handle: clnt_tli_kcreate: error %d\n", error
);