PAM_GETENVLIST(3)

πŸ¦‹ PAM_GETENVLIST(3) πŸ¦‹

okay so bestie, this is a page from the Linux-PAM Manual β€” yes the whole pam_getenvlist of it all, we're doing this πŸ’…


✨ NAME ✨

pam_getenvlist β€” literally just, getting the PAM environment 🌸


✨ SYNOPSIS ✨

#include <security/pam_appl.h>

char **pam_getenvlist(pam_handle_t *pamh);

✨ DESCRIPTION ✨

okay so picture this: the pam_getenvlist function hands you back a complete copy of the PAM environment that's associated with the handle pamh. πŸŽ€ and like, what even is the PAM environment? it's the contents of the regular environment variables of the authenticated user, at the moment service is granted. that's the vibe. ✨

now the memory format β€” this is the part where you gotta pay attention, no cap πŸ‘€ β€” it's a malloc()'d array of char pointers, and the last element of that array is set to NULL. classic. each of the non-NULL entries in this array points to a NUL terminated and malloc()'d char string of the form:

"name=value"

and here's the thing you cannot skip, bestie 🫢 β€” this memory will never be free()'d by libpam. nope. not ever. once you've obtained it by a call to pam_getenvlist, it is 100% the responsibility of the calling application to free() this memory. it's yours now. you own it. take care of it or it's a leak, and leaks are not the moment πŸ’€

and okay, this next bit is genuinely iconic: it is by design, and not a coincidence, that the format and contents of the returned array matches exactly what's required for the third argument of the execle(3) function call. like, they did that on purpose. king behavior fr fr πŸ‘‘


✨ RETURN VALUES ✨

the pam_getenvlist function returns NULL on failure. that's it, that's the whole section 😭


✨ SEE ALSO ✨


aaaand that's the page!! πŸŽ€ mwah πŸ’‹

this cutie came to you courtesy of Linux-PAM, dated 07/08/2026 β€” go forth and free() responsibly, bestie 🫢✨
πŸ“¦ where this page comes from