diff options
author | Volker Lendecke <vl@samba.org> | 2022-06-03 15:53:29 +0200 |
---|---|---|
committer | Jeremy Allison <jra@samba.org> | 2022-08-06 01:43:50 +0000 |
commit | 5fc016f26852a1cc1d7809919ff00cc0404e23e3 (patch) | |
tree | db391ac330045c54731107c5452be14dd1e38fb0 /source3/torture | |
parent | 5aaf38949aba3176f43719c4c0ec29ae1398f962 (diff) | |
download | samba-5fc016f26852a1cc1d7809919ff00cc0404e23e3.tar.gz |
vfs: change openat propotype to match linux openat2
The Linux prototype for openat2 looks like this:
long openat2(int dirfd, const char *pathname,
struct open_how *how, size_t size);
where "struct open_how" is defined in "linux/openat2.h". It is
designed to be extensible with further flags.
The "size" parameter is required because there is no type checking
between userland and kernelspace, so the way for Linux to find which
version of open_how is being passed in is looking at the size:
"open_how" is expected to only every grow with additional fields,
should a change be necessary in the future.
Samba does not have this problem, we can typecheck the struct and
pointers, we expect all VFS modules to be compiled against the current
vfs.h.
For now this adds no functionality, but it will make further patches
much smaller.
Pair-programmed-with: Stefan Metzmacher <metze@samba.org>
Signed-off-by: Volker Lendecke <vl@samba.org>
Signed-off-by: Stefan Metzmacher <metze@samba.org>
Reviewed-by: Jeremy Allison <jra@samba.org>
Diffstat (limited to 'source3/torture')
-rw-r--r-- | source3/torture/cmd_vfs.c | 57 |
1 files changed, 24 insertions, 33 deletions
diff --git a/source3/torture/cmd_vfs.c b/source3/torture/cmd_vfs.c index e068fb2f2b1..896197fbd5c 100644 --- a/source3/torture/cmd_vfs.c +++ b/source3/torture/cmd_vfs.c @@ -298,8 +298,7 @@ static NTSTATUS cmd_closedir(struct vfs_state *vfs, TALLOC_CTX *mem_ctx, int arg static NTSTATUS cmd_open(struct vfs_state *vfs, TALLOC_CTX *mem_ctx, int argc, const char **argv) { - int flags; - mode_t mode; + struct vfs_open_how how = { .mode = 0400, }; const char *flagstr; files_struct *fsp; struct files_struct *fspcwd = NULL; @@ -307,8 +306,6 @@ static NTSTATUS cmd_open(struct vfs_state *vfs, TALLOC_CTX *mem_ctx, int argc, c NTSTATUS status; int fd; - mode = 00400; - if (argc < 3 || argc > 5) { printf("Usage: open <filename> <flags> <mode>\n"); printf(" flags: O = O_RDONLY\n"); @@ -330,42 +327,41 @@ static NTSTATUS cmd_open(struct vfs_state *vfs, TALLOC_CTX *mem_ctx, int argc, c printf(" mode defaults to 00400\n"); return NT_STATUS_OK; } - flags = 0; flagstr = argv[2]; while (*flagstr) { switch (*flagstr) { case 'O': - flags |= O_RDONLY; + how.flags |= O_RDONLY; break; case 'R': - flags |= O_RDWR; + how.flags |= O_RDWR; break; case 'W': - flags |= O_WRONLY; + how.flags |= O_WRONLY; break; case 'C': - flags |= O_CREAT; + how.flags |= O_CREAT; break; case 'E': - flags |= O_EXCL; + how.flags |= O_EXCL; break; case 'T': - flags |= O_TRUNC; + how.flags |= O_TRUNC; break; case 'A': - flags |= O_APPEND; + how.flags |= O_APPEND; break; case 'N': - flags |= O_NONBLOCK; + how.flags |= O_NONBLOCK; break; #ifdef O_SYNC case 'S': - flags |= O_SYNC; + how.flags |= O_SYNC; break; #endif #ifdef O_NOFOLLOW case 'F': - flags |= O_NOFOLLOW; + how.flags |= O_NOFOLLOW; break; #endif default: @@ -374,8 +370,8 @@ static NTSTATUS cmd_open(struct vfs_state *vfs, TALLOC_CTX *mem_ctx, int argc, c } flagstr++; } - if ((flags & O_CREAT) && argc == 4) { - if (sscanf(argv[3], "%ho", (unsigned short *)&mode) == 0) { + if ((how.flags & O_CREAT) && argc == 4) { + if (sscanf(argv[3], "%ho", (unsigned short *)&how.mode) == 0) { printf("open: error=-1 (invalid mode!)\n"); return NT_STATUS_UNSUCCESSFUL; } @@ -427,8 +423,7 @@ static NTSTATUS cmd_open(struct vfs_state *vfs, TALLOC_CTX *mem_ctx, int argc, c fspcwd, smb_fname, fsp, - flags, - mode); + &how); if (fd == -1) { printf("open: error=%d (%s)\n", errno, strerror(errno)); status = map_nt_error_from_unix(errno); @@ -1733,8 +1728,7 @@ static NTSTATUS cmd_fset_nt_acl(struct vfs_state *vfs, TALLOC_CTX *mem_ctx, static NTSTATUS cmd_set_nt_acl(struct vfs_state *vfs, TALLOC_CTX *mem_ctx, int argc, const char **argv) { - int flags; - mode_t mode; + struct vfs_open_how how = { .mode = 0400, }; files_struct *fsp; struct files_struct *fspcwd = NULL; struct smb_filename *smb_fname = NULL; @@ -1747,7 +1741,6 @@ static NTSTATUS cmd_set_nt_acl(struct vfs_state *vfs, TALLOC_CTX *mem_ctx, int a return NT_STATUS_OK; } - mode = 00400; fsp = talloc_zero(vfs, struct files_struct); if (fsp == NULL) { @@ -1770,31 +1763,29 @@ static NTSTATUS cmd_set_nt_acl(struct vfs_state *vfs, TALLOC_CTX *mem_ctx, int a fsp->fsp_name = smb_fname; -#ifdef O_DIRECTORY - flags = O_RDONLY|O_DIRECTORY; -#else - /* POSIX allows us to open a directory with O_RDONLY. */ - flags = O_RDONLY; -#endif - status = vfs_at_fspcwd(fsp, vfs->conn, &fspcwd); if (!NT_STATUS_IS_OK(status)) { return status; } + how.flags = O_RDWR; fd = SMB_VFS_OPENAT(vfs->conn, fspcwd, smb_fname, fsp, - O_RDWR, - mode); + &how); if (fd == -1 && errno == EISDIR) { +#ifdef O_DIRECTORY + how.flags = O_RDONLY|O_DIRECTORY; +#else + /* POSIX allows us to open a directory with O_RDONLY. */ + how.flags = O_RDONLY; +#endif fd = SMB_VFS_OPENAT(vfs->conn, fspcwd, smb_fname, fsp, - flags, - mode); + &how); } if (fd == -1) { printf("open: error=%d (%s)\n", errno, strerror(errno)); |