ACL_CALC_MASK(3)

๐Ÿ“ฆ
version 2.4.0 ยท 2 versions
  • 2.4.0 ยท alpine 3.22, alpine 3.23, alpine 3.24, arch rolling, centos-stream 10, centos-stream 9, debian bookworm, debian trixie, fedora 43, fedora 44, nixpkgs unstable, opensuse-leap 16.0, ubuntu jammy, ubuntu noble, ubuntu resolute, ubuntu stonking (latest)
  • 15.1 ยท freebsd 14.5, freebsd 15.1
, in alpine 3.22, alpine 3.23, alpine 3.24, arch rolling, centos-stream 10, centos-stream 9, debian bookworm, debian trixie, fedora 43, fedora 44, nixpkgs unstable, opensuse-leap 16.0, ubuntu jammy, ubuntu noble, ubuntu resolute, ubuntu stonking

๐Ÿ’– ACL_CALC_MASK ๐Ÿ’–

okay bestie, so this is a page from the Linux Access Control Lists library manual โ€” section 3, library functions, the whole vibe. it's called acl_calc_mask and it's literally here to do math for you. no cap. ๐Ÿงฎโœจ


โœจ NAME โœจ

acl_calc_mask โ€” calculate the file group class mask


๐Ÿ“š LIBRARY ๐Ÿ“š

Linux Access Control Lists library (libacl, -lacl).

like, that's the library you're linking against, babes. -lacl. put it in your build and go ๐Ÿ’…


๐ŸŒธ SYNOPSIS ๐ŸŒธ

#include <sys/types.h>
#include <sys/acl.h>

int
acl_calc_mask(acl_t *acl_p);

so you include the two headers, and then the function takes a pointer to an acl_t and hands you back an int. that's it. that's the whole signature. ๐ŸŽ€


๐Ÿฆ‹ DESCRIPTION ๐Ÿฆ‹

okay so here's what's actually happening. the acl_calc_mask() function calculates and sets the permissions that go with the ACL_MASK ACL entry of the ACL that acl_p points at. ๐Ÿซถ

and the value it computes for those new permissions? it's the union of the permissions granted by all entries whose tag type is ACL_GROUP, ACL_GROUP_OBJ, or ACL_USER. every single one of them, smooshed together into one mask. iconic behavior honestly.

now, two scenarios, pay attention bestie:

  • if the ACL that acl_p refers to already has an ACL_MASK entry, its permissions get overwritten. bye old permissions ๐Ÿ‘‹
  • if it doesn't have an ACL_MASK entry, one gets added. surprise! you have a mask now ๐ŸŽ

and here's the part where it gets a lil spicy: if the ACL that acl_p points at doesn't have enough space for that new ACL entry, then extra working storage may get allocated. and if that working storage can't be grown where it currently lives, then it may get relocated โ€” the previous working storage is released, and a pointer to the new working storage comes back to you via acl_p. so yeah, your pointer might move. it's giving glow-up relocation ๐Ÿงณโœจ

also important, and don't skip this:

the order of existing entries in the ACL is undefined after this function runs. undefined!! don't build your whole personality on the order, it's not guaranteed to survive this call. ๐Ÿ’€

but good news for your pointers:

  • any existing ACL entry descriptors that refer to entries in the ACL continue to refer to those entries. they stay valid, they stay pointing at the right stuff.
  • any existing ACL pointers that refer to the ACL referred to by acl_p continue to refer to that ACL. still your ACL. still valid.

so the order is chaotic but the identity is stable. we love a consistent queen ๐Ÿ‘‘


๐Ÿ”ฅ RETURN VALUE ๐Ÿ”ฅ

  • it returns the value 0 if it's successful ๐ŸŽ‰
  • otherwise it returns the value -1, and the global variable errno gets set to indicate the error ๐Ÿ˜ญ

that's the whole contract. 0 good, -1 check errno.


๐Ÿ™ˆ ERRORS ๐Ÿ™ˆ

if any of these conditions happen, acl_calc_mask() returns -1 and sets errno to the corresponding value:

  • [EINVAL] โ€” the argument acl is not a valid pointer to an ACL. bestie. that's not an ACL. ๐Ÿšซ
  • [ENOMEM] โ€” the acl_calc_mask() function is unable to allocate the memory required for an ACL_MASK ACL entry. out of memory, out of luck ๐Ÿ’€

โญ STANDARDS โญ

IEEE Std 1003.1e draft 17 (โ€œPOSIX.1eโ€, abandoned)

yeah. abandoned. the standard said "nvm" but we're still here using it, and honestly? main character energy. periodt. ๐Ÿ’…


๐Ÿ‘€ SEE ALSO ๐Ÿ‘€

go read those too, they're part of the lore ๐Ÿ“–โœจ


๐ŸŽ€ AUTHOR ๐ŸŽ€

derived from the FreeBSD manual pages written by Robert N M Watson <rwatson@FreeBSD.org>, and adapted for Linux by Andreas Gruenbacher <andreas.gruenbacher@gmail.com>.

thank you for your service, legends ๐Ÿซก๐Ÿ’–


Linux ACL โ€” dated March 23, 2002. that's the source and the date, bestie, and that's a wrap on ACL_CALC_MASK(3). go forth and mask responsibly ๐ŸŒˆโญ๐Ÿฆ‹

๐Ÿ“ฆ where this page comes from