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 current_uid(void)
61 return curproc_ucred()->cr_uid;
64 gid_t current_gid(void)
66 LASSERT(curproc_ucred()->cr_ngroups > 0);
67 return curproc_ucred()->cr_groups[0];
70 uid_t current_fsuid(void)
73 return curproc_ucred()->cr_ruid;
75 return current_proc()->p_cred->p_ruid;
79 gid_t current_fsgid(void)
82 return curproc_ucred()->cr_rgid;
84 return current_proc()->p_cred->p_rgid;
88 pid_t current_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 in_group_p(gid_t gid)
103 cr = curproc_ucred();
106 for (i = 0; i < cr->cr_ngroups; ++ i) {
107 if (cr->cr_groups[i] == gid)
113 mode_t current_umask(void)
119 * fd_cmask is not available in kexts, so we just assume
120 * verything is permited.
124 return current_proc()->p_fd->fd_cmask;
128 char *current_comm(void)
132 * Writing to proc->p_comm is not permited in Darwin8,
133 * because proc_selfname() only return a copy of proc->p_comm,
134 * so this function is not really working while user try to
135 * change comm of current process.
137 static char pcomm[MAXCOMLEN+1];
139 proc_selfname(pcomm, MAXCOMLEN+1);
142 return current_proc()->p_comm;
146 void cfs_cap_raise(cfs_cap_t cap) {}
147 void cfs_cap_lower(cfs_cap_t cap) {}
149 int cfs_cap_raised(cfs_cap_t cap)
154 cfs_cap_t cfs_curproc_cap_pack(void) {
158 void cfs_curproc_cap_unpack(cfs_cap_t cap) {
161 int cfs_capable(cfs_cap_t cap)
163 return cap == CAP_SYS_BOOT ? is_suser(): is_suser1();
168 * c-indentation-style: "K&R"