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 2010 Sun Microsystems, Inc. All rights reserved.
24 * Use is subject to license terms.
33 #include <sys/errno.h>
34 #include <sys/systm.h>
35 #include <sys/policy.h>
37 #include <sys/kidmap.h>
41 allocids(int flag
, int nuids
, int ngids
)
49 zone_t
*zone
= crgetzone(CRED());
51 dh
= idmap_get_door(zone
);
54 return (set_errno(EPERM
));
56 if ((err
= door_ki_info(dh
, &di
)) != 0) {
58 return (set_errno(err
));
63 if (curproc
->p_pid
!= di
.di_target
)
64 return (set_errno(EPERM
));
67 idmap_purge_cache(zone
);
69 if (nuids
< 0 || ngids
< 0)
70 return (set_errno(EINVAL
));
72 if (flag
!= 0 || nuids
> 0)
73 err
= eph_uid_alloc(zone
, flag
, &su
, nuids
);
74 if (err
== 0 && (flag
!= 0 || ngids
> 0))
75 err
= eph_gid_alloc(zone
, flag
, &sg
, ngids
);
78 return (set_errno(EOVERFLOW
));
92 if ((err
= secpolicy_idmap(cr
)) != 0)
93 return (set_errno(err
));
95 dh
= door_ki_lookup(did
);
98 return (set_errno(EBADF
));
100 if ((err
= idmap_reg_dh(crgetzone(cr
), dh
)) != 0)
101 return (set_errno(err
));
109 door_handle_t dh
= door_ki_lookup(did
);
114 return (set_errno(EINVAL
));
116 zone
= crgetzone(CRED());
117 res
= idmap_unreg_dh(zone
, dh
);
121 return (set_errno(res
));
126 idmap_flush_kcache(void)
131 zone_t
*zone
= crgetzone(CRED());
133 dh
= idmap_get_door(zone
);
136 return (set_errno(EPERM
));
138 if ((err
= door_ki_info(dh
, &di
)) != 0) {
140 return (set_errno(err
));
145 if (curproc
->p_pid
!= di
.di_target
)
146 return (set_errno(EPERM
));
148 idmap_purge_cache(zone
);
154 sidsys(int op
, int flag
, int nuids
, int ngids
)
157 case SIDSYS_ALLOC_IDS
:
158 return (allocids(flag
, nuids
, ngids
));
159 case SIDSYS_IDMAP_REG
:
160 return (idmap_reg(flag
));
161 case SIDSYS_IDMAP_UNREG
:
162 return (idmap_unreg(flag
));
163 case SIDSYS_IDMAP_FLUSH_KCACHE
:
164 return (idmap_flush_kcache());
166 return (set_errno(EINVAL
));