fd: simplify fgetvp_rights by using fget_cap_locked

Reviewed by:	mjg
This commit is contained in:
Mariusz Zaborski 2016-09-22 11:54:20 +00:00
parent 85b0f9de11
commit 6490bc6529

View File

@ -2781,30 +2781,31 @@ fgetvp_rights(struct thread *td, int fd, cap_rights_t *needrightsp,
struct filecaps *havecaps, struct vnode **vpp)
{
struct filedesc *fdp;
struct filecaps caps;
struct file *fp;
#ifdef CAPABILITIES
int error;
#endif
fdp = td->td_proc->p_fd;
fp = fget_locked(fdp, fd);
if (fp == NULL || fp->f_ops == &badfileops)
return (EBADF);
#ifdef CAPABILITIES
error = cap_check(cap_rights(fdp, fd), needrightsp);
error = fget_cap_locked(fdp, fd, needrightsp, &fp, &caps);
if (error != 0)
return (error);
#endif
if (fp->f_vnode == NULL)
return (EINVAL);
if (fp->f_ops == &badfileops) {
error = EBADF;
goto out;
}
if (fp->f_vnode == NULL) {
error = EINVAL;
goto out;
}
*havecaps = caps;
*vpp = fp->f_vnode;
vref(*vpp);
filecaps_copy(&fdp->fd_ofiles[fd].fde_caps, havecaps, true);
return (0);
out:
filecaps_free(&caps);
return (error);
}
int