Whamcloud - gitweb
* Landed portals:b_port_step as follows...
[fs/lustre-release.git] / lnet / libcfs / darwin / darwin-curproc.c
1 /* -*- mode: c; c-basic-offset: 8; indent-tabs-mode: nil; -*-
2  * vim:expandtab:shiftwidth=8:tabstop=8:
3  *
4  * Lustre curproc API implementation for XNU kernel
5  *
6  * Copyright (C) 2004 Cluster File Systems, Inc.
7  * Author: Nikita Danilov <nikita@clusterfs.com>
8  *
9  * This file is part of Lustre, http://www.lustre.org.
10  *
11  * Lustre is free software; you can redistribute it and/or modify it under the
12  * terms of version 2 of the GNU General Public License as published by the
13  * Free Software Foundation. Lustre is distributed in the hope that it will be
14  * useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General
16  * Public License for more details. You should have received a copy of the GNU
17  * General Public License along with Lustre; if not, write to the Free
18  * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
19  */
20
21 #define DEBUG_SUBSYSTEM S_PORTALS
22
23 #include <libcfs/libcfs.h>
24 #include <libcfs/kp30.h>
25
26 /*
27  * Implementation of cfs_curproc API (see portals/include/libcfs/curproc.h)
28  * for XNU kernel.
29  */
30
31 static inline struct ucred *curproc_ucred(void)
32 {
33         return current_proc()->p_cred->pc_ucred;
34 }
35
36 uid_t  cfs_curproc_uid(void)
37 {
38         return curproc_ucred()->cr_uid;
39 }
40
41 gid_t  cfs_curproc_gid(void)
42 {
43         LASSERT(curproc_ucred()->cr_ngroups > 0);
44         return curproc_ucred()->cr_groups[0];
45 }
46
47 uid_t  cfs_curproc_fsuid(void)
48 {
49         return current_proc()->p_cred->p_ruid;
50 }
51
52 gid_t  cfs_curproc_fsgid(void)
53 {
54         return current_proc()->p_cred->p_rgid;
55 }
56
57 pid_t  cfs_curproc_pid(void)
58 {
59         return current_proc()->p_pid;
60 }
61
62 int    cfs_curproc_groups_nr(void)
63 {
64         LASSERT(curproc_ucred()->cr_ngroups > 0);
65         return curproc_ucred()->cr_ngroups - 1;
66 }
67
68 int    cfs_curproc_is_in_groups(gid_t gid)
69 {
70         int i;
71         struct ucred *cr;
72
73         cr = curproc_ucred();
74         LASSERT(cr != NULL);
75
76         for (i = 0; i < cr->cr_ngroups; ++ i) {
77                 if (cr->cr_groups[i] == gid)
78                         return 1;
79         }
80         return 0;
81 }
82
83 void   cfs_curproc_groups_dump(gid_t *array, int size)
84 {
85         struct ucred *cr;
86
87         cr = curproc_ucred();
88         LASSERT(cr != NULL);
89         CLASSERT(sizeof array[0] == sizeof (__u32));
90
91         size = min_t(int, size, cr->cr_ngroups);
92         memcpy(array, &cr->cr_groups[1], size * sizeof(gid_t));
93 }
94
95 mode_t cfs_curproc_umask(void)
96 {
97         return current_proc()->p_fd->fd_cmask;
98 }
99
100 char  *cfs_curproc_comm(void)
101 {
102         return current_proc()->p_comm;
103 }
104
105 cfs_kernel_cap_t cfs_curproc_cap_get(void)
106 {
107         return 0;
108 }
109
110 void cfs_curproc_cap_set(cfs_kernel_cap_t cap)
111 {
112         return;
113 }
114
115
116 /*
117  * Local variables:
118  * c-indentation-style: "K&R"
119  * c-basic-offset: 8
120  * tab-width: 8
121  * fill-column: 80
122  * scroll-step: 1
123  * End:
124  */