kern_linkat: modify to accept AT_ flags instead of FOLLOW/NOFOLLOW

This makes this API match other kern_xxxat() functions.

Reviewed By:	kib
Sponsored By:	EPSRC
Differential Revision:	https://reviews.freebsd.org/D29776
This commit is contained in:
Edward Tomasz Napierala 2021-04-25 14:13:02 +01:00
parent b68e656922
commit 5d1d844a77
4 changed files with 16 additions and 15 deletions

View File

@ -185,7 +185,7 @@ cloudabi_sys_file_link(struct thread *td,
error = kern_linkat(td, uap->fd1.fd, uap->fd2, path1, path2,
UIO_SYSSPACE, (uap->fd1.flags & CLOUDABI_LOOKUP_SYMLINK_FOLLOW) ?
FOLLOW : NOFOLLOW);
AT_SYMLINK_FOLLOW : 0);
cloudabi_freestr(path1);
cloudabi_freestr(path2);
return (error);

View File

@ -1111,7 +1111,7 @@ linux_link(struct thread *td, struct linux_link_args *args)
if (!LUSECONVPATH(td)) {
return (kern_linkat(td, AT_FDCWD, AT_FDCWD, args->path, args->to,
UIO_USERSPACE, FOLLOW));
UIO_USERSPACE, AT_SYMLINK_FOLLOW));
}
LCONVPATHEXIST(td, args->path, &path);
/* Expand LCONVPATHCREATE so that `path' can be freed on errors */
@ -1121,7 +1121,7 @@ linux_link(struct thread *td, struct linux_link_args *args)
return (error);
}
error = kern_linkat(td, AT_FDCWD, AT_FDCWD, path, to, UIO_SYSSPACE,
FOLLOW);
AT_SYMLINK_FOLLOW);
LFREEPATH(path);
LFREEPATH(to);
return (error);
@ -1132,18 +1132,19 @@ int
linux_linkat(struct thread *td, struct linux_linkat_args *args)
{
char *path, *to;
int error, olddfd, newdfd, follow;
int error, olddfd, newdfd, flag;
if (args->flag & ~LINUX_AT_SYMLINK_FOLLOW)
return (EINVAL);
flag = (args->flag & LINUX_AT_SYMLINK_FOLLOW) == 0 ? AT_SYMLINK_FOLLOW :
0;
olddfd = (args->olddfd == LINUX_AT_FDCWD) ? AT_FDCWD : args->olddfd;
newdfd = (args->newdfd == LINUX_AT_FDCWD) ? AT_FDCWD : args->newdfd;
follow = (args->flag & LINUX_AT_SYMLINK_FOLLOW) == 0 ? NOFOLLOW :
FOLLOW;
if (!LUSECONVPATH(td)) {
return (kern_linkat(td, olddfd, newdfd, args->oldname,
args->newname, UIO_USERSPACE, follow));
args->newname, UIO_USERSPACE, flag));
}
LCONVPATHEXIST_AT(td, args->oldname, &path, olddfd);
/* Expand LCONVPATHCREATE so that `path' can be freed on errors */
@ -1152,7 +1153,7 @@ linux_linkat(struct thread *td, struct linux_linkat_args *args)
LFREEPATH(path);
return (error);
}
error = kern_linkat(td, olddfd, newdfd, path, to, UIO_SYSSPACE, follow);
error = kern_linkat(td, olddfd, newdfd, path, to, UIO_SYSSPACE, flag);
LFREEPATH(path);
LFREEPATH(to);
return (error);

View File

@ -1495,7 +1495,7 @@ sys_link(struct thread *td, struct link_args *uap)
{
return (kern_linkat(td, AT_FDCWD, AT_FDCWD, uap->path, uap->link,
UIO_USERSPACE, FOLLOW));
UIO_USERSPACE, AT_SYMLINK_FOLLOW));
}
#ifndef _SYS_SYSPROTO_H_
@ -1518,8 +1518,7 @@ sys_linkat(struct thread *td, struct linkat_args *uap)
return (EINVAL);
return (kern_linkat(td, uap->fd1, uap->fd2, uap->path1, uap->path2,
UIO_USERSPACE, at2cnpflags(flag, AT_SYMLINK_FOLLOW |
AT_RESOLVE_BENEATH | AT_EMPTY_PATH)));
UIO_USERSPACE, flag));
}
int hardlink_check_uid = 0;
@ -1563,15 +1562,16 @@ can_hardlink(struct vnode *vp, struct ucred *cred)
int
kern_linkat(struct thread *td, int fd1, int fd2, const char *path1,
const char *path2, enum uio_seg segflag, int follow)
const char *path2, enum uio_seg segflag, int flag)
{
struct nameidata nd;
int error;
do {
bwillwrite();
NDINIT_ATRIGHTS(&nd, LOOKUP, follow | AUDITVNODE1, segflag,
path1, fd1, &cap_linkat_source_rights, td);
NDINIT_ATRIGHTS(&nd, LOOKUP, AUDITVNODE1 | at2cnpflags(flag,
AT_SYMLINK_FOLLOW | AT_RESOLVE_BENEATH | AT_EMPTY_PATH),
segflag, path1, fd1, &cap_linkat_source_rights, td);
if ((error = namei(&nd)) != 0)
return (error);
NDFREE(&nd, NDF_ONLY_PNBUF);

View File

@ -184,7 +184,7 @@ int kern_kldload(struct thread *td, const char *file, int *fileid);
int kern_kldstat(struct thread *td, int fileid, struct kld_file_stat *stat);
int kern_kldunload(struct thread *td, int fileid, int flags);
int kern_linkat(struct thread *td, int fd1, int fd2, const char *path1,
const char *path2, enum uio_seg segflg, int follow);
const char *path2, enum uio_seg segflg, int flag);
int kern_listen(struct thread *td, int s, int backlog);
int kern_lseek(struct thread *td, int fd, off_t offset, int whence);
int kern_lutimes(struct thread *td, const char *path, enum uio_seg pathseg,