| 3287 | */ |
| 3288 | #ifdef CAPABILITIES |
| 3289 | int |
| 3290 | fget_only_user(struct filedesc *fdp, int fd, cap_rights_t *needrightsp, |
| 3291 | struct file **fpp) |
| 3292 | { |
| 3293 | const struct filedescent *fde; |
| 3294 | const struct fdescenttbl *fdt; |
| 3295 | const cap_rights_t *haverights; |
| 3296 | struct file *fp; |
| 3297 | int error; |
| 3298 | |
| 3299 | MPASS(FILEDESC_IS_ONLY_USER(fdp)); |
| 3300 | |
| 3301 | if (__predict_false(fd >= fdp->fd_nfiles)) |
| 3302 | return (EBADF); |
| 3303 | |
| 3304 | fdt = fdp->fd_files; |
| 3305 | fde = &fdt->fdt_ofiles[fd]; |
| 3306 | fp = fde->fde_file; |
| 3307 | if (__predict_false(fp == NULL)) |
| 3308 | return (EBADF); |
| 3309 | MPASS(refcount_load(&fp->f_count) > 0); |
| 3310 | haverights = cap_rights_fde_inline(fde); |
| 3311 | error = cap_check_inline(haverights, needrightsp); |
| 3312 | if (__predict_false(error != 0)) |
| 3313 | return (EBADF); |
| 3314 | *fpp = fp; |
| 3315 | return (0); |
| 3316 | } |
| 3317 | #else |
| 3318 | int |
| 3319 | fget_only_user(struct filedesc *fdp, int fd, cap_rights_t *needrightsp, |
no test coverage detected