OPENPAM_SUBST(3)
π
OPENPAM_SUBST(3) β the openpam_subst manual, but make it make sense β¨
okay so bestie, welcome to the openpam_subst(3) page from the Library Functions Manual π β it's a real one, and it's honestly kind of iconic once you get what it does.
πΈ NAME πΈ
openpam_subst β substitute PAM item values in a string π
π¦ SYNOPSIS π¦
like, here's the vibe, exactly as written:
#include <sys/types.h>
#include <security/pam_appl.h>
#include <security/openpam.h>
int
openpam_subst(const pam_handle_t *pamh, char *buf, size_t *bufsize,
const char *template);
β¨ DESCRIPTION β¨
So openpam_subst() takes a string and expands it β like, it goes through and swaps out every occurrence of certain substitution codes for the matching PAM item value. slay. π
The template argument points at the initial string you're starting with. The result lands in the buffer pointed to by the buf argument, and the bufsize argument tells it how big that buffer is. Then β plot twist β the actual size of the resulting string, including the terminating NUL character, gets stored in the location that bufsize points to. so it's an in-and-out situation, iykyk. π«Ά
π¨ ifbufisNULL, or the buffer is too small to hold the expanded string, thenbufsizegets updated to reflect how much space you'd actually need for the whole entire string, andopenpam_subst()returnsPAM_TRY_AGAIN.
And if openpam_subst() fails for any other reason? The bufsize argument stays untouched β but heads up, part of the buffer may still have been overwritten. so don't assume your buffer is pristine. π
Substitution codes are introduced by a percent character %, and each one corresponds to a PAM item:
%Hβ replaced by the current value of thePAM_RHOSTitem π₯οΈ%hβ replaced by the current value of thePAM_HOSTitem π%sβ replaced by the current value of thePAM_SERVICEitem βοΈ%tβ replaced by the current value of thePAM_TTYitem β¨οΈ%Uβ replaced by the current value of thePAM_RUSERitem π€%uβ replaced by the current value of thePAM_USERitem π«§
π₯ RETURN VALUES π₯
openpam_subst() returns one of these, no cap:
[PAM_SUCCESS]β success, we ate π[PAM_BAD_ITEM]β unrecognized or restricted item π[PAM_TRY_AGAIN]β try again π
π SEE ALSO π
pam(3), pam_get_authtok(3), pam_get_item(3), pam_get_user(3), pam_strerror(3) β go read those too, bestie, they're all connected π§
β STANDARDS β
The openpam_subst() function is an OpenPAM extension. so like, it's special, not standard-issue π
π AUTHORS π
The openpam_subst() function and this manual page were developed by Dag-Erling SmΓΈrgrav <des@des.no>. king behavior, honestly π«‘
and that's the whole page!! π sign-off time: this one's from Debian, dated June 27, 2023, and it's OPENPAM_SUBST(3) β periodt. πβ¨
π¦ where this page comes from
- freebsd 14.5: base 14.5
- nixos 26.05: openpam 20230627
- nixpkgs unstable: openpam 20230627
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms