CAP_FCNTLS_LIMIT(2)

πŸ’– CAP_FCNTLS_LIMIT(2) β€” the system calls manual page, bestie edition πŸ’–

okay so this is cap_fcntls_limit and cap_fcntls_get, two little syscalls from the System Calls Manual section of the FreeBSD man pages. they manage which fcntl commands are allowed on a file descriptor. slay. let's get into it πŸ¦‹


✨ NAME ✨

cap_fcntls_limit, cap_fcntls_get β€” manage allowed fcntl commands


πŸ“š LIBRARY πŸ“š

Standard C Library (libc, -lc)


🌸 SYNOPSIS 🌸

#include <sys/capsicum.h>

int
cap_fcntls_limit(int fd, uint32_t fcntlrights);

int
cap_fcntls_get(int fd, uint32_t *fcntlrightsp);

πŸ’… DESCRIPTION πŸ’…

so here's the vibe. if a file descriptor has been granted the CAP_FCNTL capability right, you can take that list of allowed fcntl(2) commands and selectively reduce it with the cap_fcntls_limit() system call. and like β€” reduce only. never expand. the way that it's a one-way street is honestly iconic. once you take a right away, it's gone. periodt. πŸ’€

and if you wanna know what's still allowed? you grab a bitmask of the allowed fcntl commands for a given file descriptor with the cap_fcntls_get() system call. easy. cute. done. ✨


πŸŽ€ FLAGS πŸŽ€

these are the flags you can shove into the fcntlrights argument, or that come back to you in the fcntlrightsp argument:

  • CAP_FCNTL_GETFL β€” permits the F_GETFL command. yes ma'am 🫢
  • CAP_FCNTL_SETFL β€” permits the F_SETFL command. πŸ’…
  • CAP_FCNTL_GETOWN β€” permits the F_GETOWN command. πŸ‘‘
  • CAP_FCNTL_SETOWN β€” permits the F_SETOWN command. 🌈

⭐ RETURN VALUES ⭐

if it works? you get 0. blessed. 🧚

if it doesn't? you get -1, and the global variable errno gets set to tell you what went wrong. not the moment. 😭


πŸ”₯ ERRORS πŸ”₯

cap_fcntls_limit() succeeds unless:

  • [EBADF] β€” the fd argument is not a valid descriptor. bestie that's not a real fd, be so fr. πŸ’€
  • [EINVAL] β€” an invalid flag has been passed in fcntlrights. who let that in.
  • [ENOTCAPABLE] β€” fcntlrights would expand the list of allowed fcntl(2) commands. nope. you can only ever shrink it, not grow it. that's the whole point. πŸ™ˆ

cap_fcntls_get() succeeds unless:

  • [EBADF] β€” the fd argument is not a valid descriptor. again. girl.
  • [EFAULT] β€” the fcntlrightsp argument points at an invalid address. bad pointer energy fr fr. 😭

🌟 SEE ALSO 🌟


πŸ“œ HISTORY πŸ“œ

the cap_fcntls_get() and cap_fcntls_limit() system calls first appeared in FreeBSD 8.3. and support for capabilities and capabilities mode was developed as part of the TrustedBSD Project. lowkey a historic moment ngl. πŸ•°οΈ


πŸ‘‘ AUTHORS πŸ‘‘

this function was created by Pawel Jakub Dawidek <pawel@dawidek.net> under sponsorship of the FreeBSD Foundation. give him his flowers. πŸ’


also hi, quick note: this is the Debian build of the page, dated May 5, 2020. so like, shoutout to Debian for shipping it, and that's the whole page. you understood it, you're a genius, go reduce some fcntl rights responsibly. mwah. πŸ’–βœ¨πŸ¦‹
πŸ“¦ where this page comes from