845aa97dc24e84c65b37faef12eb84e50b9b174d
[openafs.git] / src / afs / NBSD / osi_misc.c
1 /*
2  * osi_misc.c
3  *
4  * $Id: osi_misc.c,v 1.4 2003/10/09 16:13:16 rees Exp $
5  */
6
7 /*
8 copyright 2002
9 the regents of the university of michigan
10 all rights reserved
11
12 permission is granted to use, copy, create derivative works
13 and redistribute this software and such derivative works
14 for any purpose, so long as the name of the university of
15 michigan is not used in any advertising or publicity
16 pertaining to the use or distribution of this software
17 without specific, written prior authorization.  if the
18 above copyright notice or any other identification of the
19 university of michigan is included in any copy of any
20 portion of this software, then the disclaimer below must
21 also be included.
22
23 this software is provided as is, without representation
24 from the university of michigan as to its fitness for any
25 purpose, and without warranty by the university of
26 michigan of any kind, either express or implied, including
27 without limitation the implied warranties of
28 merchantability and fitness for a particular purpose. the
29 regents of the university of michigan shall not be liable
30 for any damages, including special, indirect, incidental, or
31 consequential damages, with respect to any claim arising
32 out of or in connection with the use of the software, even
33 if it has been or is hereafter advised of the possibility of
34 such damages.
35 */
36
37 /*
38  * Copyright 2000, International Business Machines Corporation and others.
39  * All Rights Reserved.
40  *
41  * This software has been released under the terms of the IBM Public
42  * License.  For details, see the LICENSE file in the top-level source
43  * directory or online at http://www.openafs.org/dl/license10.html
44  */
45
46 #include <afsconfig.h>
47 #include "afs/param.h"
48
49
50
51 #include "afs/sysincludes.h"    /* Standard vendor system headers */
52 #include "afs/afsincludes.h"    /* Afs-based standard headers */
53
54 /*
55  * afs_suser() returns true if the caller is superuser, false otherwise.
56  *
57  * Note that it must NOT set errno.
58  */
59
60 /*
61  * Modern NetBSD version of afs_osi_suser().  For cognate code calling
62  * traditional BSD suser, see OBSD/osi_misc.c.
63  */
64 int
65 afs_osi_suser(void *credp)
66 {
67     int code;
68 /*
69  *      lwp->l_acflag is gone in NBSD50. It was "Accounting" stuff.
70  *      lwp->l_ru is what is listed as "accounting information" now, so this
71  *      may or may not work...
72  */
73 #ifdef AFS_NBSD50_ENV
74         code = kauth_authorize_generic(credp,
75                                    KAUTH_GENERIC_ISSUSER,
76                                    &curlwp->l_ru);
77 #else
78     code = kauth_authorize_generic(credp,
79                                    KAUTH_GENERIC_ISSUSER,
80                                    &curlwp->l_acflag);
81 #endif
82     return (code == 0);
83 }
84
85 /*
86  * Support Alloc_NoSleep.  This should propagate back to OBSD.
87  * Matt.
88  */
89 void *
90 osi_nbsd_Alloc(size_t asize, int cansleep)
91 {
92     void *p;
93     int glocked;
94
95     if (cansleep) {
96         glocked = ISAFS_GLOCK();
97         if (glocked)
98             AFS_GUNLOCK();
99         MALLOC(p, void *, asize, M_AFSGENERIC, M_WAITOK);
100         if (glocked)
101             AFS_GLOCK();
102     } else {
103         MALLOC(p, void *, asize, M_AFSGENERIC, M_NOWAIT);
104     }
105
106     return (p);
107 }
108
109 void
110 osi_nbsd_Free(void *p, size_t asize)
111 {
112     FREE(p, M_AFSGENERIC);
113 }
114
115 inline void *
116 afs_osi_Alloc(size_t asize) {
117     return (osi_nbsd_Alloc(asize, 1));
118 }
119
120 inline void *
121 afs_osi_Alloc_NoSleep(size_t asize) {
122     return (osi_nbsd_Alloc(asize, 0));
123 }
124
125 inline void
126 afs_osi_Free(void *buf, size_t asize) {
127     osi_nbsd_Free(buf, asize);
128 }
129
130 inline void
131 afs_osi_FreeStr(char *x)
132 {
133     afs_osi_Free(x, strlen(x) + 1);
134 }
135
136 /* XXXX OpenBSD avoids space pool, presumably Rees believed the kernel
137  * allocator did as well or better */
138 #if 0
139 void
140 osi_FreeLargeSpace(void *p)
141 {
142     osi_nbsd_Free(p, 0);
143 }
144
145 /* XXXX OpenBSD avoids space pool, presumably Rees believed the kernel
146  * allocator did as well or better */
147 #if 0
148 void
149 osi_FreeSmallSpace(void *p)
150 {
151     osi_nbsd_Free(p, 0);
152 }
153
154 void *
155 osi_AllocLargeSpace(size_t size)
156 {
157     AFS_ASSERT_GLOCK();
158     AFS_STATCNT(osi_AllocLargeSpace);
159     return (osi_nbsd_Alloc(size, 1));
160 }
161
162 void *
163 osi_AllocSmallSpace(size_t size)
164 {
165     AFS_ASSERT_GLOCK();
166     AFS_STATCNT(osi_AllocSmallSpace);
167     return (osi_nbsd_Alloc(size, 1));
168 }
169
170 #endif /* Space undef */
171
172 #endif /* Space undef */
173
174 int
175 afs_syscall_icreate(dev, near_inode, param1, param2, param3, param4, retval)
176     long *retval;
177     long dev, near_inode, param1, param2, param3, param4;
178 {
179     return EINVAL;
180 }
181
182 int
183 afs_syscall_iopen(dev, inode, usrmod, retval)
184     long *retval;
185     int dev, inode, usrmod;
186 {
187     return EINVAL;
188 }
189
190 int
191 afs_syscall_iincdec(dev, inode, inode_p1, amount)
192      int dev, inode, inode_p1, amount;
193 {
194     return EINVAL;
195 }
196
197 inline gid_t
198 osi_crgroupbyid(afs_ucred_t *acred, int gindex)
199 {
200     struct kauth_cred *cr = acred;
201     return (cr->cr_groups[gindex]);
202 }
203
204 /*
205  * just calls kern_time.c:settime()
206  */
207 void
208 afs_osi_SetTime(osi_timeval_t *atv)
209 {
210 #if 0
211     printf("afs attempted to set clock; use \"afsd -nosettime\"\n");
212 #else
213     struct timespec ts;
214     AFS_GUNLOCK();
215     ts.tv_sec = atv->tv_sec;
216     ts.tv_nsec = atv->tv_usec * 1000;
217     settime(osi_curproc()->l_proc, &ts); /* really takes a process */
218     AFS_GLOCK();
219 #endif
220 }