From: Jeremy Allison Date: Thu, 22 Aug 2019 20:42:26 +0000 (-0700) Subject: s3: VFS: Add SMB_VFS_READLINKAT(). X-Git-Tag: tevent-0.10.1~185 X-Git-Url: http://git.samba.org/?a=commitdiff_plain;h=515c062b9e67a9f7016bcce3a02b75ab6d61385d;p=samba.git s3: VFS: Add SMB_VFS_READLINKAT(). Currently identical to SMB_VFS_READLINK(). Next, add to all VFS modules that implement readlink and eventually remove readlink. Signed-off-by: Jeremy Allison Reviewed-by: Ralph Böhme --- diff --git a/examples/VFS/skel_opaque.c b/examples/VFS/skel_opaque.c index 48d8e3df7f6..603ddd46446 100644 --- a/examples/VFS/skel_opaque.c +++ b/examples/VFS/skel_opaque.c @@ -473,6 +473,16 @@ static int skel_vfs_readlink(vfs_handle_struct *handle, return -1; } +static int skel_vfs_readlinkat(vfs_handle_struct *handle, + files_struct *dirfsp, + const struct smb_filename *smb_fname, + char *buf, + size_t bufsiz) +{ + errno = ENOSYS; + return -1; +} + static int skel_linkat(vfs_handle_struct *handle, files_struct *srcfsp, const struct smb_filename *old_smb_fname, @@ -1090,6 +1100,7 @@ static struct vfs_fn_pointers skel_opaque_fns = { .getlock_fn = skel_getlock, .symlink_fn = skel_symlink, .readlink_fn = skel_vfs_readlink, + .readlinkat_fn = skel_vfs_readlinkat, .linkat_fn = skel_linkat, .mknodat_fn = skel_mknodat, .realpath_fn = skel_realpath, diff --git a/examples/VFS/skel_transparent.c b/examples/VFS/skel_transparent.c index ab43118ce37..cb240791b66 100644 --- a/examples/VFS/skel_transparent.c +++ b/examples/VFS/skel_transparent.c @@ -571,6 +571,19 @@ static int skel_vfs_readlink(vfs_handle_struct *handle, return SMB_VFS_NEXT_READLINK(handle, smb_fname, buf, bufsiz); } +static int skel_vfs_readlinkat(vfs_handle_struct *handle, + files_struct *dirfsp, + const struct smb_filename *smb_fname, + char *buf, + size_t bufsiz) +{ + return SMB_VFS_NEXT_READLINKAT(handle, + dirfsp, + smb_fname, + buf, + bufsiz); +} + static int skel_linkat(vfs_handle_struct *handle, files_struct *srcfsp, const struct smb_filename *old_smb_fname, @@ -1365,6 +1378,7 @@ static struct vfs_fn_pointers skel_transparent_fns = { .getlock_fn = skel_getlock, .symlink_fn = skel_symlink, .readlink_fn = skel_vfs_readlink, + .readlinkat_fn = skel_vfs_readlinkat, .linkat_fn = skel_linkat, .mknodat_fn = skel_mknodat, .realpath_fn = skel_realpath, diff --git a/source3/include/smbprofile.h b/source3/include/smbprofile.h index 048ce8504cd..d4717f5286b 100644 --- a/source3/include/smbprofile.h +++ b/source3/include/smbprofile.h @@ -83,6 +83,7 @@ struct tevent_context; SMBPROFILE_STATS_BASIC(syscall_linux_setlease) \ SMBPROFILE_STATS_BASIC(syscall_fcntl_getlock) \ SMBPROFILE_STATS_BASIC(syscall_readlink) \ + SMBPROFILE_STATS_BASIC(syscall_readlinkat) \ SMBPROFILE_STATS_BASIC(syscall_symlink) \ SMBPROFILE_STATS_BASIC(syscall_linkat) \ SMBPROFILE_STATS_BASIC(syscall_mknodat) \ diff --git a/source3/include/vfs.h b/source3/include/vfs.h index 3463b574e5b..70bf50a5119 100644 --- a/source3/include/vfs.h +++ b/source3/include/vfs.h @@ -275,6 +275,7 @@ /* Version 42 - Move SMB_VFS_RENAME -> SMB_VFS_RENAMEAT */ /* Version 42 - Move SMB_VFS_LINK -> SMB_VFS_LINKAT. */ /* Version 42 - Move SMB_VFS_MKNOD -> SMB_VFS_MKDNODAT. */ +/* Version 42 - Add SMB_VFS_READLINKAT. */ #define SMB_VFS_INTERFACE_VERSION 42 @@ -801,6 +802,11 @@ struct vfs_fn_pointers { const struct smb_filename *smb_fname, char *buf, size_t bufsiz); + int (*readlinkat_fn)(struct vfs_handle_struct *handle, + struct files_struct *dirfsp, + const struct smb_filename *smb_fname, + char *buf, + size_t bufsiz); int (*linkat_fn)(struct vfs_handle_struct *handle, struct files_struct *srcfsp, const struct smb_filename *old_smb_fname, @@ -1334,6 +1340,11 @@ int smb_vfs_call_readlink(struct vfs_handle_struct *handle, const struct smb_filename *smb_fname, char *buf, size_t bufsiz); +int smb_vfs_call_readlinkat(struct vfs_handle_struct *handle, + struct files_struct *dirfsp, + const struct smb_filename *smb_fname, + char *buf, + size_t bufsiz); int smb_vfs_call_linkat(struct vfs_handle_struct *handle, struct files_struct *srcfsp, const struct smb_filename *old_smb_fname, @@ -1764,6 +1775,11 @@ int vfs_not_implemented_vfs_readlink(vfs_handle_struct *handle, const struct smb_filename *smb_fname, char *buf, size_t bufsiz); +int vfs_not_implemented_vfs_readlinkat(vfs_handle_struct *handle, + struct files_struct *dirfsp, + const struct smb_filename *smb_fname, + char *buf, + size_t bufsiz); int vfs_not_implemented_linkat(vfs_handle_struct *handle, struct files_struct *srcfsp, const struct smb_filename *old_smb_fname, diff --git a/source3/include/vfs_macros.h b/source3/include/vfs_macros.h index 0f317ecbe31..61a45240c1e 100644 --- a/source3/include/vfs_macros.h +++ b/source3/include/vfs_macros.h @@ -306,6 +306,11 @@ #define SMB_VFS_NEXT_READLINK(handle, smb_fname, buf, bufsiz) \ smb_vfs_call_readlink((handle)->next, (smb_fname), (buf), (bufsiz)) +#define SMB_VFS_READLINKAT(conn, dirfsp, smb_fname, buf, bufsiz) \ + smb_vfs_call_readlinkat((conn)->vfs_handles, (dirfsp), (smb_fname), (buf), (bufsiz)) +#define SMB_VFS_NEXT_READLINKAT(handle, dirfsp, smb_fname, buf, bufsiz) \ + smb_vfs_call_readlinkat((handle)->next, (dirfsp), (smb_fname), (buf), (bufsiz)) + #define SMB_VFS_LINKAT(conn, srcfsp, oldpath, dstfsp, newpath, flags) \ smb_vfs_call_linkat((conn)->vfs_handles, (srcfsp), (oldpath), (dstfsp), (newpath), (flags)) #define SMB_VFS_NEXT_LINKAT(handle, srcfsp, oldpath, dstfsp, newpath, flags) \ diff --git a/source3/modules/vfs_default.c b/source3/modules/vfs_default.c index 51928fd0b04..70e7b31e5cb 100644 --- a/source3/modules/vfs_default.c +++ b/source3/modules/vfs_default.c @@ -2663,6 +2663,27 @@ static int vfswrap_readlink(vfs_handle_struct *handle, return result; } +static int vfswrap_readlinkat(vfs_handle_struct *handle, + files_struct *dirfsp, + const struct smb_filename *smb_fname, + char *buf, + size_t bufsiz) +{ + int result; + + START_PROFILE(syscall_readlinkat); + + SMB_ASSERT(dirfsp == dirfsp->conn->cwd_fsp); + + result = readlinkat(dirfsp->fh->fd, + smb_fname->base_name, + buf, + bufsiz); + + END_PROFILE(syscall_readlinkat); + return result; +} + static int vfswrap_linkat(vfs_handle_struct *handle, files_struct *srcfsp, const struct smb_filename *old_smb_fname, @@ -3487,6 +3508,7 @@ static struct vfs_fn_pointers vfs_default_fns = { .getlock_fn = vfswrap_getlock, .symlink_fn = vfswrap_symlink, .readlink_fn = vfswrap_readlink, + .readlinkat_fn = vfswrap_readlinkat, .linkat_fn = vfswrap_linkat, .mknodat_fn = vfswrap_mknodat, .realpath_fn = vfswrap_realpath, diff --git a/source3/modules/vfs_not_implemented.c b/source3/modules/vfs_not_implemented.c index 02d36ecbaa4..d8e92849aa4 100644 --- a/source3/modules/vfs_not_implemented.c +++ b/source3/modules/vfs_not_implemented.c @@ -471,6 +471,16 @@ int vfs_not_implemented_vfs_readlink(vfs_handle_struct *handle, return -1; } +int vfs_not_implemented_vfs_readlinkat(vfs_handle_struct *handle, + files_struct *dirfsp, + const struct smb_filename *smb_fname, + char *buf, + size_t bufsiz) +{ + errno = ENOSYS; + return -1; +} + int vfs_not_implemented_linkat(vfs_handle_struct *handle, files_struct *srcfsp, const struct smb_filename *old_smb_fname, @@ -1094,6 +1104,7 @@ static struct vfs_fn_pointers vfs_not_implemented_fns = { .getlock_fn = vfs_not_implemented_getlock, .symlink_fn = vfs_not_implemented_symlink, .readlink_fn = vfs_not_implemented_vfs_readlink, + .readlinkat_fn = vfs_not_implemented_vfs_readlinkat, .linkat_fn = vfs_not_implemented_linkat, .mknodat_fn = vfs_not_implemented_mknodat, .realpath_fn = vfs_not_implemented_realpath, diff --git a/source3/smbd/vfs.c b/source3/smbd/vfs.c index 6f348da2fe8..27bb294be7a 100644 --- a/source3/smbd/vfs.c +++ b/source3/smbd/vfs.c @@ -2210,6 +2210,20 @@ int smb_vfs_call_readlink(struct vfs_handle_struct *handle, return handle->fns->readlink_fn(handle, smb_fname, buf, bufsiz); } +int smb_vfs_call_readlinkat(struct vfs_handle_struct *handle, + struct files_struct *dirfsp, + const struct smb_filename *smb_fname, + char *buf, + size_t bufsiz) +{ + VFS_FIND(readlinkat); + return handle->fns->readlinkat_fn(handle, + dirfsp, + smb_fname, + buf, + bufsiz); +} + int smb_vfs_call_linkat(struct vfs_handle_struct *handle, struct files_struct *srcfsp, const struct smb_filename *old_smb_fname,