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.
34 * Test NULL and non-NULL tv arguments to utimes() -- if NULL, then it is
35 * allowed without privilege if the owner or if write access is held. If
36 * non-NULL, privilege is required even if writable.
39 #include <sys/types.h>
50 static char fpath
[1024];
51 static int fpath_initialized
;
54 priv_vfs_utimes_froot_setup(int asroot
, int injail
, struct test
*test
)
57 setup_file("priv_vfs_utimes_froot_setup: fpath", fpath
,
58 UID_ROOT
, GID_WHEEL
, 0600);
59 fpath_initialized
= 1;
64 priv_vfs_utimes_fowner_setup(int asroot
, int injail
, struct test
*test
)
67 setup_file("priv_vfs_utimes_fowner_setup: fpath", fpath
,
68 UID_OWNER
, GID_OWNER
, 0600);
69 fpath_initialized
= 1;
74 priv_vfs_utimes_fother_setup(int asroot
, int injail
, struct test
*test
)
78 * In the 'other' case, we make the file writable by the test user so
79 * we can evaluate the difference between setting the time to NULL,
80 * which is possible as a writer, and non-NULL, which requires
83 setup_file("priv_vfs_utimes_fother_setup: fpath", fpath
,
84 UID_OTHER
, GID_OTHER
, 0666);
85 fpath_initialized
= 1;
90 priv_vfs_utimes_froot(int asroot
, int injail
, struct test
*test
)
99 error
= utimes(fpath
, tv
);
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
, 0, 0);
104 if (!asroot
&& injail
)
105 expect("priv_vfs_utimes_froot(!root, jail)", error
, -1,
107 if (!asroot
&& !injail
)
108 expect("priv_vfs_utimes_froot(!root, !jail)", error
, -1,
113 priv_vfs_utimes_froot_null(int asroot
, int injail
, struct test
*test
)
117 error
= utimes(fpath
, NULL
);
118 if (asroot
&& injail
)
119 expect("priv_vfs_utimes_froot_null(root, jail)", error
, 0,
121 if (asroot
&& !injail
)
122 expect("priv_vfs_utimes_froot_null(root, !jail)", error
, 0,
124 if (!asroot
&& injail
)
125 expect("priv_vfs_utimes_froot_null(!root, jail)", error
, -1,
127 if (!asroot
&& !injail
)
128 expect("priv_vfs_utimes_froot_null(!root, !jail)", error
, -1,
133 priv_vfs_utimes_fowner(int asroot
, int injail
, struct test
*test
)
135 struct timeval tv
[2];
142 error
= utimes(fpath
, tv
);
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);
149 if (!asroot
&& !injail
)
150 expect("priv_vfs_utimes_fowner(!root, !jail)", error
, 0, 0);
154 priv_vfs_utimes_fowner_null(int asroot
, int injail
, struct test
*test
)
158 error
= utimes(fpath
, NULL
);
159 if (asroot
&& injail
)
160 expect("priv_vfs_utimes_fowner_null(root, jail)", error
, 0,
162 if (asroot
&& !injail
)
163 expect("priv_vfs_utimes_fowner_null(root, !jail)", error
, 0,
165 if (!asroot
&& injail
)
166 expect("priv_vfs_utimes_fowner_null(!root, jail)", error
, 0,
168 if (!asroot
&& !injail
)
169 expect("priv_vfs_utimes_fowner_null(!root, !jail)", error
, 0,
174 priv_vfs_utimes_fother(int asroot
, int injail
, struct test
*test
)
176 struct timeval tv
[2];
183 error
= utimes(fpath
, tv
);
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
, 0, 0);
188 if (!asroot
&& injail
)
189 expect("priv_vfs_utimes_fother(!root, jail)", error
, -1,
191 if (!asroot
&& !injail
)
192 expect("priv_vfs_utimes_fother(!root, !jail)", error
, -1,
197 priv_vfs_utimes_fother_null(int asroot
, int injail
, struct test
*test
)
201 error
= utimes(fpath
, NULL
);
202 if (asroot
&& injail
)
203 expect("priv_vfs_utimes_fother_null(root, jail)", error
, 0,
205 if (asroot
&& !injail
)
206 expect("priv_vfs_utimes_fother_null(root, !jail)", error
, 0,
208 if (!asroot
&& injail
)
209 expect("priv_vfs_utimes_fother_null(!root, jail)", error
, 0,
211 if (!asroot
&& !injail
)
212 expect("priv_vfs_utimes_fother_null(!root, !jail)", error
, 0,
217 priv_vfs_utimes_cleanup(int asroot
, int injail
, struct test
*test
)
220 if (fpath_initialized
) {
222 fpath_initialized
= 0;