4 * The contents of this file are subject to the terms of the
5 * Common Development and Distribution License (the "License").
6 * You may not use this file except in compliance with the License.
8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9 * or http://www.opensolaris.org/os/licensing.
10 * See the License for the specific language governing permissions
11 * and limitations under the License.
13 * When distributing Covered Code, include this CDDL HEADER in each
14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15 * If applicable, add the following below this CDDL HEADER, with the
16 * fields enclosed by brackets "[]" replaced with your own identifying
17 * information: Portions Copyright [yyyy] [name of copyright owner]
23 * Copyright 2008 Sun Microsystems, Inc. All rights reserved.
24 * Use is subject to license terms.
27 #pragma ident "%Z%%M% %I% %E% SMI"
30 #include "priv_private.h"
41 #include <sys/param.h>
42 #include <sys/syscall.h>
44 #include <netinet/in.h>
46 typedef struct klpd_data
{
47 boolean_t (*kd_callback
)(void *, const priv_set_t
*, void *);
52 typedef struct klpd_ctxt
{
61 klpd_door_callback(void *kd_cookie
, char *argp
, size_t arg_size
,
62 door_desc_t
*dp
, uint_t ndesc
)
64 klpd_data_t
*p
= kd_cookie
;
71 if (argp
== DOOR_UNREF_DATA
) {
72 (void) p
->kd_callback(p
->kd_user_cookie
, NULL
, NULL
);
73 (void) door_return(NULL
, 0, NULL
, 0);
78 pset
= KLH_PRIVSET(klh
);
80 ctx
.kc_type
= ka
== NULL
? KLPDARG_NONE
: ka
->kla_type
;
82 switch (ctx
.kc_type
) {
88 ctx
.kc_path
= ka
->kla_str
;
92 ctx
.kc_int
= ka
->kla_int
;
99 if (p
->kd_callback(p
->kd_user_cookie
, pset
, &ctx
))
104 (void) door_return((char *)&res
, sizeof (res
), NULL
, 0);
108 klpd_create(boolean_t (*callback
)(void *, const priv_set_t
*, void *),
111 klpd_data_t
*p
= malloc(sizeof (klpd_data_t
));
116 p
->kd_doorfd
= door_create(klpd_door_callback
, p
,
117 DOOR_REFUSE_DESC
| DOOR_UNREF
);
118 if (p
->kd_doorfd
== -1)
121 p
->kd_user_cookie
= cookie
;
122 p
->kd_callback
= callback
;
132 klpd_register_id(const priv_set_t
*set
, void *handle
, idtype_t type
, id_t id
)
134 klpd_data_t
*p
= handle
;
139 /* We really need to have the privilege set as argument here */
140 if (syscall(SYS_privsys
, PRIVSYS_KLPD_REG
, p
->kd_doorfd
, id
,
141 set
, d
->pd_setsize
, type
) == -1)
144 /* Registration for the current process? Then do the thing. */
145 if (type
== P_PID
&& (id
== 0 || (pid_t
)id
== getpid())) {
146 (void) setppriv(PRIV_OFF
, PRIV_INHERITABLE
, set
);
147 (void) setpflags(PRIV_XPOLICY
, 1);
153 klpd_register(const priv_set_t
*set
, void *handle
)
155 return (klpd_register_id(set
, handle
, P_PID
, -1));
159 klpd_unregister_id(void *handle
, idtype_t type
, id_t id
)
161 klpd_data_t
*p
= handle
;
164 err
= syscall(SYS_privsys
, PRIVSYS_KLPD_UNREG
, p
->kd_doorfd
, id
,
166 if (close(p
->kd_doorfd
) != 0)
173 klpd_unregister(void *handle
)
175 return (klpd_unregister_id(handle
, P_PID
, -1));
179 klpd_getpath(void *context
)
181 klpd_ctxt_t
*p
= context
;
183 if (p
->kc_type
!= KLPDARG_VNODE
)
189 klpd_getport(void *context
, int *proto
)
191 klpd_ctxt_t
*p
= context
;
193 switch (p
->kc_type
) {
194 case KLPDARG_TCPPORT
:
195 *proto
= IPPROTO_TCP
;
197 case KLPDARG_UDPPORT
:
198 *proto
= IPPROTO_UDP
;
200 case KLPDARG_SCTPPORT
:
201 *proto
= IPPROTO_SCTP
;
203 case KLPDARG_SDPPORT
:
215 klpd_getucred(ucred_t
**uc
, void *context
)
217 return (door_ucred(uc
));