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 * Check that privilege is required to set the sticky bit on a file but not a
47 int fpath_initialized;
50 int dpath_initialized;
53 priv_vfs_stickyfile_dir_fowner_setup(int asroot, int injail,
57 setup_dir("priv_vfs_stickyfile_fowner_setup: dpath", dpath,
58 UID_OWNER, GID_OWNER, 0700);
59 dpath_initialized = 1;
64 priv_vfs_stickyfile_dir_fother_setup(int asroot, int injail,
68 setup_dir("priv_vfs_stickyfile_fother_setup: dpath", dpath,
69 UID_OTHER, GID_OTHER, 0700);
70 dpath_initialized = 1;
75 priv_vfs_stickyfile_file_fowner_setup(int asroot, int injail,
79 setup_file("priv_vfs_stickyfile_fowner_setup: fpath", fpath,
80 UID_OWNER, GID_OWNER, 0600);
81 fpath_initialized = 1;
86 priv_vfs_stickyfile_file_fother_setup(int asroot, int injail,
90 setup_file("priv_vfs_stickyfile_fother_setup: fpath", fpath,
91 UID_OTHER, GID_OTHER, 0600);
92 fpath_initialized = 1;
97 priv_vfs_stickyfile_dir_fowner(int asroot, int injail, struct test *test)
101 error = chmod(dpath, 0700 | S_ISTXT);
102 if (asroot && injail)
103 expect("priv_vfs_stickyfile_dir_fowner(root, jail)", error,
105 if (asroot && !injail)
106 expect("priv_vfs_stickyfile_dir_fowner(root, !jail)", error,
108 if (!asroot && injail)
109 expect("priv_vfs_stickyfile_dir_fowner(!root, jail)", error,
111 if (!asroot && !injail)
112 expect("priv_vfs_stickyfile_dir_fowner(!root, !jail)", error,
117 priv_vfs_stickyfile_dir_fother(int asroot, int injail, struct test *test)
121 error = chmod(dpath, 0700 | S_ISTXT);
122 if (asroot && injail)
123 expect("priv_vfs_stickyfile_dir_fother(root, jail)", error,
125 if (asroot && !injail)
126 expect("priv_vfs_stickyfile_dir_fother(root, !jail)", error,
128 if (!asroot && injail)
129 expect("priv_vfs_stickyfile_dir_fother(!root, jail)", error,
131 if (!asroot && !injail)
132 expect("priv_vfs_stickyfile_dir_fother(!root, !jail)", error,
137 priv_vfs_stickyfile_file_fowner(int asroot, int injail, struct test *test)
141 error = chmod(fpath, 0600 | S_ISTXT);
142 if (asroot && injail)
143 expect("priv_vfs_stickyfile_file_fowner(root, jail)", error,
145 if (asroot && !injail)
146 expect("priv_vfs_stickyfile_file_fowner(root, !jail)", error,
148 if (!asroot && injail)
149 expect("priv_vfs_stickyfile_file_fowner(!root, jail)", error,
151 if (!asroot && !injail)
152 expect("priv_vfs_stickyfile_file_fowner(!root, !jail)", error,
157 priv_vfs_stickyfile_file_fother(int asroot, int injail, struct test *test)
161 error = chmod(fpath, 0600 | S_ISTXT);
162 if (asroot && injail)
163 expect("priv_vfs_stickyfile_file_fother(root, jail)", error,
165 if (asroot && !injail)
166 expect("priv_vfs_stickyfile_file_fother(root, !jail)", error,
168 if (!asroot && injail)
169 expect("priv_vfs_stickyfile_file_fother(!root, jail)", error,
171 if (!asroot && !injail)
172 expect("priv_vfs_stickyfile_file_fother(!root, !jail)", error,
177 priv_vfs_stickyfile_dir_cleanup(int asroot, int injail, struct test *test)
180 if (dpath_initialized) {
182 dpath_initialized = 0;
187 priv_vfs_stickyfile_file_cleanup(int asroot, int injail, struct test *test)
190 if (fpath_initialized) {
192 fpath_initialized = 0;