2 * Copyright (c) 2006 nCircle Network Security, Inc.
3 * Copyright (c) 2007 Robert N. M. Watson
6 * This software was developed by Robert N. M. Watson for the TrustedBSD
7 * Project under contract to nCircle Network Security, Inc.
9 * Redistribution and use in source and binary forms, with or without
10 * modification, are permitted provided that the following conditions
12 * 1. Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer.
14 * 2. Redistributions in binary form must reproduce the above copyright
15 * notice, this list of conditions and the following disclaimer in the
16 * documentation and/or other materials provided with the distribution.
18 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
19 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
20 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
21 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR, NCIRCLE NETWORK SECURITY,
22 * INC., OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
23 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
24 * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
25 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
26 * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
27 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
28 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32 * Test NULL and non-NULL tv arguments to utimes() -- if NULL, then it is
33 * allowed without privilege if the owner or if write access is held. If
34 * non-NULL, privilege is required even if writable.
37 #include <sys/types.h>
48 static char fpath[1024];
49 static int fpath_initialized;
52 priv_vfs_utimes_froot_setup(int asroot, int injail, struct test *test)
55 setup_file("priv_vfs_utimes_froot_setup: fpath", fpath,
56 UID_ROOT, GID_WHEEL, 0600);
57 fpath_initialized = 1;
62 priv_vfs_utimes_fowner_setup(int asroot, int injail, struct test *test)
65 setup_file("priv_vfs_utimes_fowner_setup: fpath", fpath,
66 UID_OWNER, GID_OWNER, 0600);
67 fpath_initialized = 1;
72 priv_vfs_utimes_fother_setup(int asroot, int injail, struct test *test)
76 * In the 'other' case, we make the file writable by the test user so
77 * we can evaluate the difference between setting the time to NULL,
78 * which is possible as a writer, and non-NULL, which requires
81 setup_file("priv_vfs_utimes_fother_setup: fpath", fpath,
82 UID_OTHER, GID_OTHER, 0666);
83 fpath_initialized = 1;
88 priv_vfs_utimes_froot(int asroot, int injail, struct test *test)
97 error = utimes(fpath, tv);
99 expect("priv_vfs_utimes_froot(root, jail)", error, 0, 0);
100 if (asroot && !injail)
101 expect("priv_vfs_utimes_froot(root, !jail)", error, 0, 0);
102 if (!asroot && injail)
103 expect("priv_vfs_utimes_froot(!root, jail)", error, -1,
105 if (!asroot && !injail)
106 expect("priv_vfs_utimes_froot(!root, !jail)", error, -1,
111 priv_vfs_utimes_froot_null(int asroot, int injail, struct test *test)
115 error = utimes(fpath, NULL);
116 if (asroot && injail)
117 expect("priv_vfs_utimes_froot_null(root, jail)", error, 0,
119 if (asroot && !injail)
120 expect("priv_vfs_utimes_froot_null(root, !jail)", error, 0,
122 if (!asroot && injail)
123 expect("priv_vfs_utimes_froot_null(!root, jail)", error, -1,
125 if (!asroot && !injail)
126 expect("priv_vfs_utimes_froot_null(!root, !jail)", error, -1,
131 priv_vfs_utimes_fowner(int asroot, int injail, struct test *test)
133 struct timeval tv[2];
140 error = utimes(fpath, tv);
141 if (asroot && injail)
142 expect("priv_vfs_utimes_fowner(root, jail)", error, 0, 0);
143 if (asroot && !injail)
144 expect("priv_vfs_utimes_fowner(root, !jail)", error, 0, 0);
145 if (!asroot && injail)
146 expect("priv_vfs_utimes_fowner(!root, jail)", error, 0, 0);
147 if (!asroot && !injail)
148 expect("priv_vfs_utimes_fowner(!root, !jail)", error, 0, 0);
152 priv_vfs_utimes_fowner_null(int asroot, int injail, struct test *test)
156 error = utimes(fpath, NULL);
157 if (asroot && injail)
158 expect("priv_vfs_utimes_fowner_null(root, jail)", error, 0,
160 if (asroot && !injail)
161 expect("priv_vfs_utimes_fowner_null(root, !jail)", error, 0,
163 if (!asroot && injail)
164 expect("priv_vfs_utimes_fowner_null(!root, jail)", error, 0,
166 if (!asroot && !injail)
167 expect("priv_vfs_utimes_fowner_null(!root, !jail)", error, 0,
172 priv_vfs_utimes_fother(int asroot, int injail, struct test *test)
174 struct timeval tv[2];
181 error = utimes(fpath, tv);
182 if (asroot && injail)
183 expect("priv_vfs_utimes_fother(root, jail)", error, 0, 0);
184 if (asroot && !injail)
185 expect("priv_vfs_utimes_fother(root, !jail)", error, 0, 0);
186 if (!asroot && injail)
187 expect("priv_vfs_utimes_fother(!root, jail)", error, -1,
189 if (!asroot && !injail)
190 expect("priv_vfs_utimes_fother(!root, !jail)", error, -1,
195 priv_vfs_utimes_fother_null(int asroot, int injail, struct test *test)
199 error = utimes(fpath, NULL);
200 if (asroot && injail)
201 expect("priv_vfs_utimes_fother_null(root, jail)", error, 0,
203 if (asroot && !injail)
204 expect("priv_vfs_utimes_fother_null(root, !jail)", error, 0,
206 if (!asroot && injail)
207 expect("priv_vfs_utimes_fother_null(!root, jail)", error, 0,
209 if (!asroot && !injail)
210 expect("priv_vfs_utimes_fother_null(!root, !jail)", error, 0,
215 priv_vfs_utimes_cleanup(int asroot, int injail, struct test *test)
218 if (fpath_initialized) {
220 fpath_initialized = 0;