1 /* -*- mode: c; c-basic-offset: 8; indent-tabs-mode: nil; -*-
2 * vim:expandtab:shiftwidth=8:tabstop=8:
6 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License version 2 only,
10 * as published by the Free Software Foundation.
12 * This program is distributed in the hope that it will be useful, but
13 * WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * General Public License version 2 for more details (a copy is included
16 * in the LICENSE file that accompanied this code).
18 * You should have received a copy of the GNU General Public License
19 * version 2 along with this program; If not, see
20 * http://www.sun.com/software/products/lustre/docs/GPLv2.pdf
22 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
23 * CA 95054 USA or visit www.sun.com if you need additional information or
29 * Copyright 2008 Sun Microsystems, Inc. All rights reserved
30 * Use is subject to license terms.
33 * This file is part of Lustre, http://www.lustre.org/
34 * Lustre is a trademark of Sun Microsystems, Inc.
36 * lnet/libcfs/linux/linux-curproc.c
38 * Lustre curproc API implementation for Linux kernel
40 * Author: Nikita Danilov <nikita@clusterfs.com>
43 #include <linux/sched.h>
45 #define DEBUG_SUBSYSTEM S_LNET
47 #include <libcfs/libcfs.h>
48 #include <libcfs/kp30.h>
51 * Implementation of cfs_curproc API (see portals/include/libcfs/curproc.h)
55 uid_t cfs_curproc_uid(void)
60 gid_t cfs_curproc_gid(void)
65 uid_t cfs_curproc_fsuid(void)
67 return current->fsuid;
70 gid_t cfs_curproc_fsgid(void)
72 return current->fsgid;
75 pid_t cfs_curproc_pid(void)
80 int cfs_curproc_groups_nr(void)
84 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,4)
86 nr = current->group_info->ngroups;
89 nr = current->ngroups;
94 void cfs_curproc_groups_dump(gid_t *array, int size)
96 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,4)
98 size = min_t(int, size, current->group_info->ngroups);
99 memcpy(array, current->group_info->blocks[0], size * sizeof(__u32));
100 task_unlock(current);
102 LASSERT(size <= NGROUPS);
103 size = min_t(int, size, current->ngroups);
104 memcpy(array, current->groups, size * sizeof(__u32));
109 int cfs_curproc_is_in_groups(gid_t gid)
111 return in_group_p(gid);
114 mode_t cfs_curproc_umask(void)
116 return current->fs->umask;
119 char *cfs_curproc_comm(void)
121 return current->comm;
124 /* Currently all the CFS_CAP_* defines match CAP_* ones. */
125 #define cfs_cap_pack(cap) (cap)
126 #define cfs_cap_unpack(cap) (cap)
128 void cfs_cap_raise(cfs_cap_t cap)
130 cap_raise(cfs_current()->cap_effective, cfs_cap_unpack(cap));
133 void cfs_cap_lower(cfs_cap_t cap)
135 cap_lower(cfs_current()->cap_effective, cfs_cap_unpack(cap));
138 int cfs_cap_raised(cfs_cap_t cap)
140 return cap_raised(cfs_current()->cap_effective, cfs_cap_unpack(cap));
143 void cfs_kernel_cap_pack(cfs_kernel_cap_t kcap, cfs_cap_t *cap)
145 #if defined (_LINUX_CAPABILITY_VERSION) && _LINUX_CAPABILITY_VERSION == 0x19980330
146 *cap = cfs_cap_pack(kcap);
147 #elif defined (_LINUX_CAPABILITY_VERSION) && _LINUX_CAPABILITY_VERSION == 0x20071026
148 *cap = cfs_cap_pack(kcap[0]);
149 #elif defined(_KERNEL_CAPABILITY_VERSION) && _KERNEL_CAPABILITY_VERSION == 0x20080522
150 /* XXX lost high byte */
151 *cap = cfs_cap_pack(kcap.cap[0]);
153 #error "need correct _KERNEL_CAPABILITY_VERSION "
157 void cfs_kernel_cap_unpack(cfs_kernel_cap_t *kcap, cfs_cap_t cap)
159 #if defined (_LINUX_CAPABILITY_VERSION) && _LINUX_CAPABILITY_VERSION == 0x19980330
160 *kcap = cfs_cap_unpack(cap);
161 #elif defined (_LINUX_CAPABILITY_VERSION) && _LINUX_CAPABILITY_VERSION == 0x20071026
162 (*kcap)[0] = cfs_cap_unpack(cap);
163 #elif defined(_KERNEL_CAPABILITY_VERSION) && _KERNEL_CAPABILITY_VERSION == 0x20080522
164 kcap->cap[0] = cfs_cap_unpack(cap);
166 #error "need correct _KERNEL_CAPABILITY_VERSION "
170 cfs_cap_t cfs_curproc_cap_pack(void)
173 cfs_kernel_cap_pack(current->cap_effective, &cap);
177 void cfs_curproc_cap_unpack(cfs_cap_t cap)
179 cfs_kernel_cap_unpack(¤t->cap_effective, cap);
182 int cfs_capable(cfs_cap_t cap)
184 return capable(cfs_cap_unpack(cap));
187 EXPORT_SYMBOL(cfs_curproc_uid);
188 EXPORT_SYMBOL(cfs_curproc_pid);
189 EXPORT_SYMBOL(cfs_curproc_gid);
190 EXPORT_SYMBOL(cfs_curproc_fsuid);
191 EXPORT_SYMBOL(cfs_curproc_fsgid);
192 EXPORT_SYMBOL(cfs_curproc_umask);
193 EXPORT_SYMBOL(cfs_curproc_comm);
194 EXPORT_SYMBOL(cfs_curproc_groups_nr);
195 EXPORT_SYMBOL(cfs_curproc_groups_dump);
196 EXPORT_SYMBOL(cfs_curproc_is_in_groups);
197 EXPORT_SYMBOL(cfs_cap_raise);
198 EXPORT_SYMBOL(cfs_cap_lower);
199 EXPORT_SYMBOL(cfs_cap_raised);
200 EXPORT_SYMBOL(cfs_kernel_cap_pack);
201 EXPORT_SYMBOL(cfs_kernel_cap_unpack);
202 EXPORT_SYMBOL(cfs_curproc_cap_pack);
203 EXPORT_SYMBOL(cfs_curproc_cap_unpack);
204 EXPORT_SYMBOL(cfs_capable);
208 * c-indentation-style: "K&R"