2 * Copyright (c) 2008-2009 Apple Inc.
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.
13 * 3. Neither the name of Apple Inc. ("Apple") nor the names of
14 * its contributors may be used to endorse or promote products derived
15 * from this software without specific prior written permission.
17 * THIS SOFTWARE IS PROVIDED BY APPLE AND ITS CONTRIBUTORS "AS IS" AND
18 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20 * ARE DISCLAIMED. IN NO EVENT SHALL APPLE OR ITS CONTRIBUTORS BE LIABLE FOR
21 * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
22 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
23 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
24 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
25 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
26 * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
27 * POSSIBILITY OF SUCH DAMAGE.
29 * $P4: //depot/projects/trustedbsd/openbsm/libbsm/bsm_fcntl.c#2 $
32 #include <sys/param.h>
33 #include <sys/fcntl.h>
35 #include <security/audit/audit.h>
37 #include <bsm/audit_record.h>
38 #include <bsm/audit_fcntl.h>
41 struct bsm_fcntl_cmd
{
42 u_short bfc_bsm_fcntl_cmd
;
43 int bfc_local_fcntl_cmd
;
45 typedef struct bsm_fcntl_cmd bsm_fcntl_cmd_t
;
47 static const bsm_fcntl_cmd_t bsm_fcntl_cmdtab
[] = {
48 { BSM_F_DUPFD
, F_DUPFD
},
49 { BSM_F_GETFD
, F_GETFD
},
50 { BSM_F_SETFD
, F_SETFD
},
51 { BSM_F_GETFL
, F_GETFL
},
52 { BSM_F_SETFL
, F_SETFL
},
54 { BSM_F_O_GETLK
, F_O_GETLK
},
56 { BSM_F_SETLK
, F_SETLK
},
57 { BSM_F_SETLKW
, F_SETLK
},
59 { BSM_F_CHKFL
, F_CHKFL
},
62 { BSM_F_DUP2FD
, F_DUP2FD
},
65 { BSM_F_ALLOCSP
, F_ALLOCSP
},
68 { BSM_F_FREESP
, F_FREESP
},
71 { BSM_F_ISSTREAM
, F_ISSTREAM
},
73 { BSM_F_GETLK
, F_GETLK
},
75 { BSM_F_PRIV
, F_PRIV
},
78 { BSM_F_NPRIV
, F_NPRIV
},
81 { BSM_F_QUOTACTL
, F_QUOTACTL
},
84 { BSM_F_BLOCKS
, F_BLOCKS
},
87 { BSM_F_BLKSIZE
, F_BLKSIZE
},
89 { BSM_F_GETOWN
, F_GETOWN
},
90 { BSM_F_SETOWN
, F_SETOWN
},
92 { BSM_F_REVOKE
, F_REVOKE
},
94 #ifdef F_HASREMOTEBLOCKS
95 { BSM_F_HASREMOTEBLOCKS
,
99 { BSM_F_FREESP
, F_FREESP
},
102 { BSM_F_ALLOCSP
, F_ALLOCSP
},
105 { BSM_F_FREESP64
, F_FREESP64
},
108 { BSM_F_ALLOCSP64
, F_ALLOCSP64
},
111 { BSM_F_GETLK64
, F_GETLK64
},
114 { BSM_F_SETLK64
, F_SETLK64
},
117 { BSM_F_SETLKW64
, F_SETLKW64
},
120 { BSM_F_SHARE
, F_SHARE
},
123 { BSM_F_UNSHARE
, F_UNSHARE
},
125 #ifdef F_SETLK_NBMAND
126 { BSM_F_SETLK_NBMAND
, F_SETLK_NBMAND
},
128 #ifdef F_SHARE_NBMAND
129 { BSM_F_SHARE_NBMAND
, F_SHARE_NBMAND
},
131 #ifdef F_SETLK64_NBMAND
132 { BSM_F_SETLK64_NBMAND
, F_SETLK64_NBMAND
},
135 { BSM_F_GETXFL
, F_GETXFL
},
138 { BSM_F_BADFD
, F_BADFD
},
141 { BSM_F_OGETLK
, F_OGETLK
},
144 { BSM_F_OSETLK
, F_OSETLK
},
147 { BSM_F_OSETLKW
, F_OSETLKW
},
149 #ifdef F_SETLK_REMOTE
150 { BSM_F_SETLK_REMOTE
, F_SETLK_REMOTE
},
154 { BSM_F_SETSIG
, F_SETSIG
},
157 { BSM_F_GETSIG
, F_GETSIG
},
161 { BSM_F_CHKCLEAN
, F_CHKCLEAN
},
164 { BSM_F_PREALLOCATE
, F_PREALLOCATE
},
167 { BSM_F_SETSIZE
, F_SETSIZE
},
170 { BSM_F_RDADVISE
, F_RDADVISE
},
173 { BSM_F_RDAHEAD
, F_RDAHEAD
},
175 #ifdef F_READBOOTSTRAP
176 { BSM_F_READBOOTSTRAP
, F_READBOOTSTRAP
},
178 #ifdef F_WRITEBOOTSTRAP
179 { BSM_F_WRITEBOOTSTRAP
, F_WRITEBOOTSTRAP
},
182 { BSM_F_NOCACHE
, F_NOCACHE
},
185 { BSM_F_LOG2PHYS
, F_LOG2PHYS
},
188 { BSM_F_GETPATH
, F_GETPATH
},
191 { BSM_F_FULLFSYNC
, F_FULLFSYNC
},
193 #ifdef F_PATHPKG_CHECK
194 { BSM_F_PATHPKG_CHECK
, F_PATHPKG_CHECK
},
197 { BSM_F_FREEZE_FS
, F_FREEZE_FS
},
200 { BSM_F_THAW_FS
, F_THAW_FS
},
202 #ifdef F_GLOBAL_NOCACHE
203 { BSM_F_GLOBAL_NOCACHE
, F_GLOBAL_NOCACHE
},
206 { BSM_F_OPENFROM
, F_OPENFROM
},
209 { BSM_F_UNLINKFROM
, F_UNLINKFROM
},
211 #ifdef F_CHECK_OPENEVT
212 { BSM_F_CHECK_OPENEVT
, F_CHECK_OPENEVT
},
215 { BSM_F_ADDSIGS
, F_ADDSIGS
},
217 #ifdef F_MARKDEPENDENCY
218 { BSM_F_MARKDEPENDENCY
, F_MARKDEPENDENCY
},
220 #ifdef F_BARRIERFSYNC
221 { BSM_F_BARRIERFSYNC
, F_BARRIERFSYNC
},
224 { BSM_F_PUNCHHOLE
, F_PUNCHHOLE
},
226 #ifdef F_TRIM_ACTIVE_FILE
227 { BSM_F_TRIM_ACTIVE_FILE
, F_TRIM_ACTIVE_FILE
},
230 #ifdef FCNTL_FS_SPECIFIC_BASE
231 { BSM_F_FS_SPECIFIC_0
, FCNTL_FS_SPECIFIC_BASE
},
232 { BSM_F_FS_SPECIFIC_1
, FCNTL_FS_SPECIFIC_BASE
+ 1},
233 { BSM_F_FS_SPECIFIC_2
, FCNTL_FS_SPECIFIC_BASE
+ 2},
234 { BSM_F_FS_SPECIFIC_3
, FCNTL_FS_SPECIFIC_BASE
+ 3},
235 { BSM_F_FS_SPECIFIC_4
, FCNTL_FS_SPECIFIC_BASE
+ 4},
236 { BSM_F_FS_SPECIFIC_5
, FCNTL_FS_SPECIFIC_BASE
+ 5},
237 { BSM_F_FS_SPECIFIC_6
, FCNTL_FS_SPECIFIC_BASE
+ 6},
238 { BSM_F_FS_SPECIFIC_7
, FCNTL_FS_SPECIFIC_BASE
+ 7},
239 { BSM_F_FS_SPECIFIC_8
, FCNTL_FS_SPECIFIC_BASE
+ 8},
240 { BSM_F_FS_SPECIFIC_9
, FCNTL_FS_SPECIFIC_BASE
+ 9},
241 { BSM_F_FS_SPECIFIC_10
, FCNTL_FS_SPECIFIC_BASE
+ 10},
242 { BSM_F_FS_SPECIFIC_11
, FCNTL_FS_SPECIFIC_BASE
+ 11},
243 { BSM_F_FS_SPECIFIC_12
, FCNTL_FS_SPECIFIC_BASE
+ 12},
244 { BSM_F_FS_SPECIFIC_13
, FCNTL_FS_SPECIFIC_BASE
+ 13},
245 { BSM_F_FS_SPECIFIC_14
, FCNTL_FS_SPECIFIC_BASE
+ 14},
246 { BSM_F_FS_SPECIFIC_15
, FCNTL_FS_SPECIFIC_BASE
+ 15},
247 #endif /* FCNTL_FS_SPECIFIC_BASE */
249 static const int bsm_fcntl_cmd_count
= sizeof(bsm_fcntl_cmdtab
) /
250 sizeof(bsm_fcntl_cmdtab
[0]);
252 static const bsm_fcntl_cmd_t
*
253 bsm_lookup_local_fcntl_cmd(int local_fcntl_cmd
)
257 for (i
= 0; i
< bsm_fcntl_cmd_count
; i
++) {
258 if (bsm_fcntl_cmdtab
[i
].bfc_local_fcntl_cmd
==
260 return &bsm_fcntl_cmdtab
[i
];
267 au_fcntl_cmd_to_bsm(int local_fcntl_cmd
)
269 const bsm_fcntl_cmd_t
*bfcp
;
271 bfcp
= bsm_lookup_local_fcntl_cmd(local_fcntl_cmd
);
273 return BSM_F_UNKNOWN
;
275 return bfcp
->bfc_bsm_fcntl_cmd
;
278 static const bsm_fcntl_cmd_t
*
279 bsm_lookup_bsm_fcntl_cmd(u_short bsm_fcntl_cmd
)
283 for (i
= 0; i
< bsm_fcntl_cmd_count
; i
++) {
284 if (bsm_fcntl_cmdtab
[i
].bfc_bsm_fcntl_cmd
==
286 return &bsm_fcntl_cmdtab
[i
];
293 au_bsm_to_fcntl_cmd(u_short bsm_fcntl_cmd
, int *local_fcntl_cmdp
)
295 const bsm_fcntl_cmd_t
*bfcp
;
297 bfcp
= bsm_lookup_bsm_fcntl_cmd(bsm_fcntl_cmd
);
298 if (bfcp
== NULL
|| bfcp
->bfc_local_fcntl_cmd
) {
301 *local_fcntl_cmdp
= bfcp
->bfc_local_fcntl_cmd
;
304 #endif /* CONFIG_AUDIT */