4 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License version 2 only,
8 * as published by the Free Software Foundation.
10 * This program is distributed in the hope that it will be useful, but
11 * WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * General Public License version 2 for more details (a copy is included
14 * in the LICENSE file that accompanied this code).
16 * You should have received a copy of the GNU General Public License
17 * version 2 along with this program; If not, see
18 * http://www.sun.com/software/products/lustre/docs/GPLv2.pdf
20 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
21 * CA 95054 USA or visit www.sun.com if you need additional information or
27 * Copyright (c) 2008, 2010, Oracle and/or its affiliates. All rights reserved.
28 * Use is subject to license terms.
31 * This file is part of Lustre, http://www.lustre.org/
32 * Lustre is a trademark of Sun Microsystems, Inc.
34 * libcfs/libcfs/darwin/darwin-curproc.c
36 * Lustre curproc API implementation for XNU kernel
38 * Author: Nikita Danilov <nikita@clusterfs.com>
41 #define DEBUG_SUBSYSTEM S_LNET
43 #include <libcfs/libcfs.h>
46 * Implementation of cfs_curproc API (see lnet/include/libcfs/curproc.h)
50 static inline struct ucred *curproc_ucred(void)
53 return proc_ucred(current_proc());
55 return current_proc()->p_cred->pc_ucred;
59 uid_t cfs_curproc_uid(void)
61 return curproc_ucred()->cr_uid;
64 gid_t cfs_curproc_gid(void)
66 LASSERT(curproc_ucred()->cr_ngroups > 0);
67 return curproc_ucred()->cr_groups[0];
70 uid_t cfs_curproc_fsuid(void)
73 return curproc_ucred()->cr_ruid;
75 return current_proc()->p_cred->p_ruid;
79 gid_t cfs_curproc_fsgid(void)
82 return curproc_ucred()->cr_rgid;
84 return current_proc()->p_cred->p_rgid;
88 pid_t cfs_curproc_pid(void)
91 /* no pid for each thread, return address of thread struct */
92 return (pid_t)current_thread();
94 return current_proc()->p_pid;
98 int cfs_curproc_groups_nr(void)
100 LASSERT(curproc_ucred()->cr_ngroups > 0);
101 return curproc_ucred()->cr_ngroups - 1;
104 int cfs_curproc_is_in_groups(gid_t gid)
109 cr = curproc_ucred();
112 for (i = 0; i < cr->cr_ngroups; ++ i) {
113 if (cr->cr_groups[i] == gid)
119 void cfs_curproc_groups_dump(gid_t *array, int size)
123 cr = curproc_ucred();
125 CLASSERT(sizeof array[0] == sizeof (__u32));
127 size = min_t(int, size, cr->cr_ngroups);
128 memcpy(array, &cr->cr_groups[1], size * sizeof(gid_t));
131 mode_t cfs_curproc_umask(void)
137 * fd_cmask is not available in kexts, so we just assume
138 * verything is permited.
142 return current_proc()->p_fd->fd_cmask;
146 char *cfs_curproc_comm(void)
150 * Writing to proc->p_comm is not permited in Darwin8,
151 * because proc_selfname() only return a copy of proc->p_comm,
152 * so this function is not really working while user try to
153 * change comm of current process.
155 static char pcomm[MAXCOMLEN+1];
157 proc_selfname(pcomm, MAXCOMLEN+1);
160 return current_proc()->p_comm;
164 void cfs_cap_raise(cfs_cap_t cap) {}
165 void cfs_cap_lower(cfs_cap_t cap) {}
167 int cfs_cap_raised(cfs_cap_t cap)
172 cfs_cap_t cfs_curproc_cap_pack(void) {
176 void cfs_curproc_cap_unpack(cfs_cap_t cap) {
179 int cfs_capable(cfs_cap_t cap)
181 return cap == CFS_CAP_SYS_BOOT ? is_suser(): is_suser1();
186 * c-indentation-style: "K&R"