GENFS_CAN_ACCESS(9)

πŸ“¦ version 11.0, in nixpkgs unstable

πŸ’… GENFS_CAN_ACCESS πŸ’…

okay so this is GENFS_CAN_ACCESS(9) from the Kernel Developer's Manual β€” yeah, the Kernel Developer's Manual, she's fancy, she's lowkey iconic πŸŽ€ β€” and bestie, it's literally the page about the function that decides whether you're allowed to touch a file. access control decision time, let's go ✨


🌸 NAME 🌸

genfs_can_access β€” generate an access control decision using vnode parameters

like, it looks at your vnode situation and says "yes queen" or "no bestie" πŸ’…


✨ SYNOPSIS ✨

#include <miscfs/genfs/genfs.h>

int
genfs_can_access(vnode_t *vp, kauth_cred_t cred, uid_t file_uid,
    gid_t file_gid, mode_t file_mode, struct acl *acl,
    accmode_t accmode);

copy it exactly, don't come for me πŸ™ˆ


πŸ¦‹ DESCRIPTION πŸ¦‹

This call implements the logic for the Unix discretionary file security model common to many file systems in FreeBSD. fr fr, that's the whole vibe of this function β€” it's the bouncer at the club checking if your cred is on the list 🫢

It accepts the vnode vp, requesting credential cred, permissions via owning UID file_uid, owning GID file_gid, file permissions file_mode, access ACL for the file acl, desired access mode accmode, (yes the original sentence ends in a comma, we respect the comma, periodt)

This call is intended to support implementations of VOP_ACCESS(9), which will use their own access methods to retrieve the vnode properties, and then invoke vaccess() in order to perform the actual check. Implementations of VOP_ACCESS(9) may choose to implement additional security mechanisms whose results will be composed with the return value. so like, the results get combined with whatever you return β€” main character energy, but make it composable πŸ’«

The algorithm used by genfs_can_access() selects a component of the file permission bits based on comparing the passed credential, file owner, and file group. here's the tea, step by step πŸ‘‘

  • If the credential's effective UID matches the file owner, then the owner component of the permission bits is selected. ✨
  • If the UID does not match, then the credential's effective GID, followed by additional groups, are compared with the file group β€” if there is a match, then the group component of the permission bits is selected. πŸŽ€
  • If neither the credential UID or GIDs match the passed file owner and group, then the other component of the permission bits is selected. πŸ™ˆ

Once appropriate protections are selected for the current credential, the requested access mode, in combination with the vnode type, will be compared with the discretionary rights available for the credential. and if the rights granted by discretionary protections are insufficient? then super-user privilege, if available for the credential, will also be considered. so the superuser gets a lil cameo appearance πŸ‘‘βœ¨


πŸ”₯ RETURN VALUES πŸ”₯

genfs_can_access() will return 0 on success, or a non-zero error value on failure. no cap, that's it β€” 0 means slay, non-zero means something went sideways 😭


πŸ’€ ERRORS πŸ’€

  • [EACCES] β€” Permission denied. An attempt was made to access a file in a way forbidden by its file access permissions. literally the "you're not on the list" moment πŸ™…β€β™€οΈ
  • [EPERM] β€” Operation not permitted. An attempt was made to perform an operation limited to processes with appropriate privileges or to the owner of a file or other resource. like, this one's for the privileged kids only πŸ’…
okay real talk: these are the errors it can hand you back, don't shoot the messenger 🫢

🌈 SEE ALSO 🌈

the whole friend group, read them together, iykyk πŸ§šβ€β™€οΈπŸ’œ


πŸ“ AUTHORS πŸ“

This manual page and the current implementation of vaccess() were written by Robert Watson. thank you Robert, king behaviour πŸ‘‘βœ¨


and that's the page bestie!! signed, sealed, delivered by Debian, dated January 17, 2022, filed under GENFS_CAN_ACCESS(9) β€” mwah, go read some source code πŸ’‹πŸŽ€πŸ¦‹

πŸ“¦ where this page comes from