s3:utils: let smbstatus report anonymous signing/encryption explicitly
[metze/samba-autobuild/.git] / lib / replace / system / filesys.h
1 #ifndef _system_filesys_h
2 #define _system_filesys_h
3 /*
4    Unix SMB/CIFS implementation.
5
6    filesystem system include wrappers
7
8    Copyright (C) Andrew Tridgell 2004
9
10      ** NOTE! The following LGPL license applies to the replace
11      ** library. This does NOT imply that all of Samba is released
12      ** under the LGPL
13
14    This library is free software; you can redistribute it and/or
15    modify it under the terms of the GNU Lesser General Public
16    License as published by the Free Software Foundation; either
17    version 3 of the License, or (at your option) any later version.
18
19    This library is distributed in the hope that it will be useful,
20    but WITHOUT ANY WARRANTY; without even the implied warranty of
21    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
22    Lesser General Public License for more details.
23
24    You should have received a copy of the GNU Lesser General Public
25    License along with this library; if not, see <http://www.gnu.org/licenses/>.
26
27 */
28
29 #ifdef HAVE_UNISTD_H
30 #include <unistd.h>
31 #endif
32
33 #include <sys/stat.h>
34
35 #ifdef HAVE_SYS_PARAM_H
36 #include <sys/param.h>
37 #endif
38
39 /* This include is required on UNIX (*BSD, AIX, ...) for statfs() */
40 #if !defined(LINUX) && defined(HAVE_SYS_MOUNT_H)
41 #include <sys/mount.h>
42 #endif
43
44 #ifdef HAVE_MNTENT_H
45 #include <mntent.h>
46 #endif
47
48 /* This include is required on Linux for statfs() */
49 #ifdef HAVE_SYS_VFS_H
50 #include <sys/vfs.h>
51 #endif
52
53 #ifdef HAVE_SYS_ACL_H
54 #include <sys/acl.h>
55 #endif
56
57 #ifdef HAVE_ACL_LIBACL_H
58 #include <acl/libacl.h>
59 #endif
60
61 #ifdef HAVE_SYS_FS_S5PARAM_H
62 #include <sys/fs/s5param.h>
63 #endif
64
65 #if defined (HAVE_SYS_FILSYS_H) && !defined (_CRAY)
66 #include <sys/filsys.h>
67 #endif
68
69 #ifdef HAVE_SYS_STATFS_H
70 # include <sys/statfs.h>
71 #endif
72
73 #ifdef HAVE_DUSTAT_H
74 #include <sys/dustat.h>
75 #endif
76
77 #ifdef HAVE_SYS_STATVFS_H
78 #include <sys/statvfs.h>
79 #endif
80
81 #ifdef HAVE_SYS_FILIO_H
82 #include <sys/filio.h>
83 #endif
84
85 #ifdef HAVE_SYS_FILE_H
86 #include <sys/file.h>
87 #endif
88
89 #ifdef HAVE_FCNTL_H
90 #include <fcntl.h>
91 #else
92 #ifdef HAVE_SYS_FCNTL_H
93 #include <sys/fcntl.h>
94 #endif
95 #endif
96
97 #ifdef HAVE_SYS_MODE_H
98 /* apparently AIX needs this for S_ISLNK */
99 #ifndef S_ISLNK
100 #include <sys/mode.h>
101 #endif
102 #endif
103
104 #ifdef HAVE_SYS_IOCTL_H
105 #include <sys/ioctl.h>
106 #endif
107
108 #ifdef HAVE_SYS_UIO_H
109 #include <sys/uio.h>
110 #endif
111
112 /* mutually exclusive (SuSE 8.2) */
113 #if defined(HAVE_SYS_XATTR_H)
114 #include <sys/xattr.h>
115 #elif defined(HAVE_ATTR_XATTR_H)
116 #include <attr/xattr.h>
117 #elif defined(HAVE_SYS_ATTRIBUTES_H)
118 #include <sys/attributes.h>
119 #elif defined(HAVE_ATTR_ATTRIBUTES_H)
120 #include <attr/attributes.h>
121 #endif
122
123 #ifdef HAVE_SYS_EA_H
124 #include <sys/ea.h>
125 #endif
126
127 #ifdef HAVE_SYS_EXTATTR_H
128 #include <sys/extattr.h>
129 #endif
130
131 #ifdef HAVE_SYS_RESOURCE_H
132 #include <sys/resource.h>
133 #endif
134
135 #ifndef XATTR_CREATE
136 #define XATTR_CREATE  0x1       /* set value, fail if attr already exists */
137 #endif
138
139 #ifndef XATTR_REPLACE
140 #define XATTR_REPLACE 0x2       /* set value, fail if attr does not exist */
141 #endif
142
143 /* Some POSIX definitions for those without */
144
145 #ifndef S_IFDIR
146 #define S_IFDIR         0x4000
147 #endif
148 #ifndef S_ISDIR
149 #define S_ISDIR(mode)   ((mode & 0xF000) == S_IFDIR)
150 #endif
151 #ifndef S_IRWXU
152 #define S_IRWXU 00700           /* read, write, execute: owner */
153 #endif
154 #ifndef S_IRUSR
155 #define S_IRUSR 00400           /* read permission: owner */
156 #endif
157 #ifndef S_IWUSR
158 #define S_IWUSR 00200           /* write permission: owner */
159 #endif
160 #ifndef S_IXUSR
161 #define S_IXUSR 00100           /* execute permission: owner */
162 #endif
163 #ifndef S_IRWXG
164 #define S_IRWXG 00070           /* read, write, execute: group */
165 #endif
166 #ifndef S_IRGRP
167 #define S_IRGRP 00040           /* read permission: group */
168 #endif
169 #ifndef S_IWGRP
170 #define S_IWGRP 00020           /* write permission: group */
171 #endif
172 #ifndef S_IXGRP
173 #define S_IXGRP 00010           /* execute permission: group */
174 #endif
175 #ifndef S_IRWXO
176 #define S_IRWXO 00007           /* read, write, execute: other */
177 #endif
178 #ifndef S_IROTH
179 #define S_IROTH 00004           /* read permission: other */
180 #endif
181 #ifndef S_IWOTH
182 #define S_IWOTH 00002           /* write permission: other */
183 #endif
184 #ifndef S_IXOTH
185 #define S_IXOTH 00001           /* execute permission: other */
186 #endif
187
188 #ifndef O_ACCMODE
189 #define O_ACCMODE (O_RDONLY | O_WRONLY | O_RDWR)
190 #endif
191
192 #ifndef MAXPATHLEN
193 #define MAXPATHLEN 256
194 #endif
195
196 #ifndef SEEK_SET
197 #define SEEK_SET 0
198 #endif
199
200 #ifdef _WIN32
201 #define mkdir(d,m) _mkdir(d)
202 #endif
203
204 #ifdef DISABLE_OPATH
205 #undef O_PATH
206 #endif
207
208 /*
209    this allows us to use a uniform error handling for our xattr
210    wrappers
211 */
212 #ifndef ENOATTR
213 #define ENOATTR ENODATA
214 #endif
215
216
217 #if !defined(HAVE_XATTR_XATTR) || defined(XATTR_ADDITIONAL_OPTIONS)
218
219 ssize_t rep_getxattr (const char *path, const char *name, void *value, size_t size);
220 #define getxattr(path, name, value, size) rep_getxattr(path, name, value, size)
221 /* define is in "replace.h" */
222 ssize_t rep_fgetxattr (int filedes, const char *name, void *value, size_t size);
223 #define fgetxattr(filedes, name, value, size) rep_fgetxattr(filedes, name, value, size)
224 /* define is in "replace.h" */
225 ssize_t rep_listxattr (const char *path, char *list, size_t size);
226 #define listxattr(path, list, size) rep_listxattr(path, list, size)
227 /* define is in "replace.h" */
228 ssize_t rep_flistxattr (int filedes, char *list, size_t size);
229 #define flistxattr(filedes, value, size) rep_flistxattr(filedes, value, size)
230 /* define is in "replace.h" */
231 int rep_removexattr (const char *path, const char *name);
232 #define removexattr(path, name) rep_removexattr(path, name)
233 /* define is in "replace.h" */
234 int rep_fremovexattr (int filedes, const char *name);
235 #define fremovexattr(filedes, name) rep_fremovexattr(filedes, name)
236 /* define is in "replace.h" */
237 int rep_setxattr (const char *path, const char *name, const void *value, size_t size, int flags);
238 #define setxattr(path, name, value, size, flags) rep_setxattr(path, name, value, size, flags)
239 /* define is in "replace.h" */
240 int rep_fsetxattr (int filedes, const char *name, const void *value, size_t size, int flags);
241 #define fsetxattr(filedes, name, value, size, flags) rep_fsetxattr(filedes, name, value, size, flags)
242 /* define is in "replace.h" */
243
244 #endif /* !defined(HAVE_XATTR_XATTR) || defined(XATTR_ADDITIONAL_OPTIONS) */
245
246 #ifdef HAVE_LINUX_OPENAT2_H
247 #include <linux/openat2.h>
248 #else /* ! HAVE_LINUX_OPENAT2_H */
249 /* how->resolve flags for openat2(2). */
250 #define RESOLVE_NO_XDEV         0x01 /* Block mount-point crossings
251                                         (includes bind-mounts). */
252 #define RESOLVE_NO_MAGICLINKS   0x02 /* Block traversal through procfs-style
253                                         "magic-links". */
254 #define RESOLVE_NO_SYMLINKS     0x04 /* Block traversal through all symlinks
255                                         (implies OEXT_NO_MAGICLINKS) */
256 #define RESOLVE_BENEATH         0x08 /* Block "lexical" trickery like
257                                         "..", symlinks, and absolute
258                                         paths which escape the dirfd. */
259 #define RESOLVE_IN_ROOT         0x10 /* Make all jumps to "/" and ".."
260                                         be scoped inside the dirfd
261                                         (similar to chroot(2)). */
262 #define RESOLVE_CACHED          0x20 /* Only complete if resolution can be
263                                         completed through cached lookup. May
264                                         return -EAGAIN if that's not
265                                         possible. */
266 struct __rep_open_how {
267         uint64_t flags;
268         uint64_t mode;
269         uint64_t resolve;
270 };
271 #define open_how __rep_open_how
272 #endif /* ! HAVE_LINUX_OPENAT2_H */
273
274 #ifndef HAVE_OPENAT2
275 long rep_openat2(int dirfd, const char *pathname,
276                  struct open_how *how, size_t size);
277 #define openat2(dirfd, pathname, how, size) \
278         rep_openat2(dirfd, pathname, how, size)
279 #endif /* !HAVE_OPENAT2 */
280
281 #endif