]>
git.proxmox.com Git - mirror_zfs.git/blob - module/spl/spl-cred.c
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://zfsonlinux.org/>.
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/>.
24 * Solaris Porting Layer (SPL) Credential Implementation.
31 cr_groups_search(const struct group_info
*group_info
, kgid_t grp
)
33 cr_groups_search(const struct group_info
*group_info
, gid_t grp
)
36 unsigned int left
, right
, mid
;
43 right
= group_info
->ngroups
;
44 while (left
< right
) {
45 mid
= (left
+ right
) / 2;
46 cmp
= KGID_TO_SGID(grp
) -
47 KGID_TO_SGID(GROUP_AT(group_info
, mid
));
59 /* Hold a reference on the credential */
63 (void) get_cred((const cred_t
*)cr
);
66 /* Free a reference on the credential */
70 put_cred((const cred_t
*)cr
);
73 /* Return the number of supplemental groups */
75 crgetngroups(const cred_t
*cr
)
77 struct group_info
*gi
;
82 #ifndef HAVE_GROUP_INFO_GID
85 * crgetgroups will only returns gi->blocks[0], which contains only
86 * the first NGROUPS_PER_BLOCK groups.
88 if (rc
> NGROUPS_PER_BLOCK
) {
90 rc
= NGROUPS_PER_BLOCK
;
97 * Return an array of supplemental gids. The returned address is safe
98 * to use as long as the caller has taken a reference with crhold().
100 * Linux 4.9 API change, group_info changed from 2d array via ->blocks to 1d
104 crgetgroups(const cred_t
*cr
)
106 struct group_info
*gi
;
110 #ifdef HAVE_GROUP_INFO_GID
111 gids
= KGIDP_TO_SGIDP(gi
->gid
);
114 gids
= KGIDP_TO_SGIDP(gi
->blocks
[0]);
119 /* Check if the passed gid is available in supplied credential. */
121 groupmember(gid_t gid
, const cred_t
*cr
)
123 struct group_info
*gi
;
127 rc
= cr_groups_search(gi
, SGID_TO_KGID(gid
));
132 /* Return the effective user id */
134 crgetuid(const cred_t
*cr
)
136 return (KUID_TO_SUID(cr
->euid
));
139 /* Return the real user id */
141 crgetruid(const cred_t
*cr
)
143 return (KUID_TO_SUID(cr
->uid
));
146 /* Return the saved user id */
148 crgetsuid(const cred_t
*cr
)
150 return (KUID_TO_SUID(cr
->suid
));
153 /* Return the filesystem user id */
155 crgetfsuid(const cred_t
*cr
)
157 return (KUID_TO_SUID(cr
->fsuid
));
160 /* Return the effective group id */
162 crgetgid(const cred_t
*cr
)
164 return (KGID_TO_SGID(cr
->egid
));
167 /* Return the real group id */
169 crgetrgid(const cred_t
*cr
)
171 return (KGID_TO_SGID(cr
->gid
));
174 /* Return the saved group id */
176 crgetsgid(const cred_t
*cr
)
178 return (KGID_TO_SGID(cr
->sgid
));
181 /* Return the filesystem group id */
183 crgetfsgid(const cred_t
*cr
)
185 return (KGID_TO_SGID(cr
->fsgid
));
188 EXPORT_SYMBOL(crhold
);
189 EXPORT_SYMBOL(crfree
);
190 EXPORT_SYMBOL(crgetuid
);
191 EXPORT_SYMBOL(crgetruid
);
192 EXPORT_SYMBOL(crgetsuid
);
193 EXPORT_SYMBOL(crgetfsuid
);
194 EXPORT_SYMBOL(crgetgid
);
195 EXPORT_SYMBOL(crgetrgid
);
196 EXPORT_SYMBOL(crgetsgid
);
197 EXPORT_SYMBOL(crgetfsgid
);
198 EXPORT_SYMBOL(crgetngroups
);
199 EXPORT_SYMBOL(crgetgroups
);
200 EXPORT_SYMBOL(groupmember
);