diff options
author | Stefan Metzmacher <metze@samba.org> | 2022-07-27 18:43:14 +0000 |
---|---|---|
committer | Volker Lendecke <vl@samba.org> | 2022-08-15 15:03:37 +0000 |
commit | 8544f4490a0b5e54b807daedddb96778744b62ee (patch) | |
tree | 8676ac35005887b47c86021395b33b804e4b45ce | |
parent | d6653067b20e61af1f05423764c8486a1a5445c8 (diff) | |
download | samba-8544f4490a0b5e54b807daedddb96778744b62ee.tar.gz |
vfs_default: prepare O_PATH usage with openat2()
When O_PATH is specified in flags, flag bits other than O_CLOEXEC,
O_DIRECTORY, and O_NOFOLLOW are ignored.
In preparation to use openat2(), which gives an error instead of
ignoring flags, we better remove unexpected flags, callers typically
pass O_RDONLY and O_NONBLOCK.
Signed-off-by: Stefan Metzmacher <metze@samba.org>
Reviewed-by: Volker Lendecke <vl@samba.org>
-rw-r--r-- | source3/modules/vfs_default.c | 18 |
1 files changed, 18 insertions, 0 deletions
diff --git a/source3/modules/vfs_default.c b/source3/modules/vfs_default.c index dee8ff50df4..847eddd8991 100644 --- a/source3/modules/vfs_default.c +++ b/source3/modules/vfs_default.c @@ -714,6 +714,24 @@ static int vfswrap_openat(vfs_handle_struct *handle, if (fsp->fsp_flags.is_pathref) { flags |= O_PATH; } + if (flags & O_PATH) { + /* + * From "man 2 openat": + * + * When O_PATH is specified in flags, flag bits other than + * O_CLOEXEC, O_DIRECTORY, and O_NOFOLLOW are ignored. + * + * From "man 2 openat2": + * + * Whereas openat(2) ignores unknown bits in its flags + * argument, openat2() returns an error if unknown or + * conflicting flags are specified in how.flags. + * + * So we better clear ignored/invalid flags + * and only keep the exptected once. + */ + flags &= (O_PATH|O_CLOEXEC|O_DIRECTORY|O_NOFOLLOW); + } #endif if (fsp->fsp_flags.is_pathref && !have_opath) { |