* Test whether a capability grants the given ioctl command. * If descriptor doesn't have CAP_IOCTL, then ioctls list is empty and * ENOTCAPABLE will be returned. */
| 357 | * ENOTCAPABLE will be returned. |
| 358 | */ |
| 359 | int |
| 360 | cap_ioctl_check(struct filedesc *fdp, int fd, u_long cmd) |
| 361 | { |
| 362 | struct filedescent *fdep; |
| 363 | u_long *cmds; |
| 364 | ssize_t ncmds; |
| 365 | long i; |
| 366 | |
| 367 | KASSERT(fd >= 0 && fd < fdp->fd_nfiles, |
| 368 | ("%s: invalid fd=%d", __func__, fd)); |
| 369 | |
| 370 | fdep = fdeget_locked(fdp, fd); |
| 371 | KASSERT(fdep != NULL, |
| 372 | ("%s: invalid fd=%d", __func__, fd)); |
| 373 | |
| 374 | ncmds = fdep->fde_nioctls; |
| 375 | if (ncmds == -1) |
| 376 | return (0); |
| 377 | |
| 378 | cmds = fdep->fde_ioctls; |
| 379 | for (i = 0; i < ncmds; i++) { |
| 380 | if (cmds[i] == cmd) |
| 381 | return (0); |
| 382 | } |
| 383 | |
| 384 | return (ENOTCAPABLE); |
| 385 | } |
| 386 | |
| 387 | /* |
| 388 | * Check if the current ioctls list can be replaced by the new one. |
no test coverage detected