]>
git.proxmox.com Git - mirror_spl-debian.git/blob - module/spl/spl-cred.c
1 /*****************************************************************************\
2 * Copyright (C) 2007-2010 Lawrence Livermore National Security, LLC.
3 * Copyright (C) 2007 The Regents of the University of California.
4 * Produced at Lawrence Livermore National Laboratory (cf, DISCLAIMER).
5 * Written by Brian Behlendorf <behlendorf1@llnl.gov>.
8 * This file is part of the SPL, Solaris Porting Layer.
9 * For details, see <http://github.com/behlendorf/spl/>.
11 * The SPL is free software; you can redistribute it and/or modify it
12 * under the terms of the GNU General Public License as published by the
13 * Free Software Foundation; either version 2 of the License, or (at your
14 * option) any later version.
16 * The SPL is distributed in the hope that it will be useful, but WITHOUT
17 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
18 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
21 * You should have received a copy of the GNU General Public License along
22 * with the SPL. If not, see <http://www.gnu.org/licenses/>.
23 *****************************************************************************
24 * Solaris Porting Layer (SPL) Credential Implementation.
25 \*****************************************************************************/
29 #ifdef DEBUG_SUBSYSTEM
30 #undef DEBUG_SUBSYSTEM
33 #define DEBUG_SUBSYSTEM S_CRED
35 #ifdef HAVE_GROUPS_SEARCH
36 /* Symbol may be exported by custom kernel patch */
37 #define cr_groups_search(gi, grp) groups_search(gi, grp)
39 /* Implementation from 2.6.30 kernel */
41 cr_groups_search(const struct group_info
*group_info
, gid_t grp
)
43 unsigned int left
, right
;
49 right
= group_info
->ngroups
;
50 while (left
< right
) {
51 unsigned int mid
= (left
+right
)/2;
52 int cmp
= grp
- GROUP_AT(group_info
, mid
);
64 #ifdef HAVE_CRED_STRUCT
67 * As of 2.6.29 a clean credential API appears in the linux kernel.
68 * We attempt to layer the Solaris API on top of the linux API.
71 /* Hold a reference on the credential and group info */
75 (void)get_cred((const cred_t
*)cr
);
76 (void)get_group_info(cr
->group_info
);
79 /* Free a reference on the credential and group info */
83 put_group_info(cr
->group_info
);
84 put_cred((const cred_t
*)cr
);
87 /* Return the number of supplemental groups */
89 crgetngroups(const cred_t
*cr
)
91 struct group_info
*gi
;
94 gi
= get_group_info(cr
->group_info
);
102 * Return an array of supplemental gids. The returned address is safe
103 * to use as long as the caller has taken a reference with crhold().
104 * The caller is responsible for releasing the reference with crfree().
107 crgetgroups(const cred_t
*cr
)
109 struct group_info
*gi
;
112 gi
= get_group_info(cr
->group_info
);
113 gids
= gi
->blocks
[0];
119 /* Check if the passed gid is available is in supplied credential. */
121 groupmember(gid_t gid
, const cred_t
*cr
)
123 struct group_info
*gi
;
126 gi
= get_group_info(cr
->group_info
);
127 rc
= cr_groups_search(cr
->group_info
, gid
);
133 #else /* HAVE_CRED_STRUCT */
136 * Until very recently all credential information was embedded in
137 * the linux task struct. For this reason to simulate a Solaris
138 * cred_t we need to pass the entire task structure around.
141 /* Hold a reference on the credential and group info */
142 void crhold(cred_t
*cr
) { }
144 /* Free a reference on the credential and group info */
145 void crfree(cred_t
*cr
) { }
147 /* Return the number of supplemental groups */
149 crgetngroups(const cred_t
*cr
)
153 lock
= (cr
!= current
);
155 task_lock((struct task_struct
*)cr
);
157 get_group_info(cr
->group_info
);
158 rc
= cr
->group_info
->ngroups
;
159 put_group_info(cr
->group_info
);
162 task_unlock((struct task_struct
*)cr
);
168 * Return an array of supplemental gids. The returned address is safe
169 * to use as long as the caller has taken a reference with crhold().
170 * The caller is responsible for releasing the reference with crfree().
173 crgetgroups(const cred_t
*cr
)
178 lock
= (cr
!= current
);
180 task_lock((struct task_struct
*)cr
);
182 get_group_info(cr
->group_info
);
183 gids
= cr
->group_info
->blocks
[0];
184 put_group_info(cr
->group_info
);
187 task_unlock((struct task_struct
*)cr
);
192 /* Check if the passed gid is available is in supplied credential. */
194 groupmember(gid_t gid
, const cred_t
*cr
)
198 lock
= (cr
!= current
);
200 task_lock((struct task_struct
*)cr
);
202 get_group_info(cr
->group_info
);
203 rc
= cr_groups_search(cr
->group_info
, gid
);
204 put_group_info(cr
->group_info
);
207 task_unlock((struct task_struct
*)cr
);
212 #endif /* HAVE_CRED_STRUCT */
214 /* Return the effective user id */
216 crgetuid(const cred_t
*cr
)
221 /* Return the real user id */
223 crgetruid(const cred_t
*cr
)
228 /* Return the saved user id */
230 crgetsuid(const cred_t
*cr
)
235 /* Return the filesystem user id */
237 crgetfsuid(const cred_t
*cr
)
242 /* Return the effective group id */
244 crgetgid(const cred_t
*cr
)
249 /* Return the real group id */
251 crgetrgid(const cred_t
*cr
)
256 /* Return the saved group id */
258 crgetsgid(const cred_t
*cr
)
263 /* Return the filesystem group id */
265 crgetfsgid(const cred_t
*cr
)
270 EXPORT_SYMBOL(crhold
);
271 EXPORT_SYMBOL(crfree
);
272 EXPORT_SYMBOL(crgetuid
);
273 EXPORT_SYMBOL(crgetruid
);
274 EXPORT_SYMBOL(crgetsuid
);
275 EXPORT_SYMBOL(crgetfsuid
);
276 EXPORT_SYMBOL(crgetgid
);
277 EXPORT_SYMBOL(crgetrgid
);
278 EXPORT_SYMBOL(crgetsgid
);
279 EXPORT_SYMBOL(crgetfsgid
);
280 EXPORT_SYMBOL(crgetngroups
);
281 EXPORT_SYMBOL(crgetgroups
);
282 EXPORT_SYMBOL(groupmember
);