PAM_CONV(3)
π PAM_CONV(3) β the Linux-PAM bestie chat page π
okay so this is PAM_CONV(3) from the Linux-PAM manual, and honestly bestie, this one is the glue β it's the whole how-do-modules-talk-to-apps situation. buckle up, it's giving very important plumbing β¨
πΈ NAME πΈ
pam_conv β the PAM conversation function. that's it, that's the vibe. it's literally the callback that lets a module and your app have a little chat π¬
π¦ SYNOPSIS π¦
#include <security/pam_appl.h>
struct pam_message {
int msg_style;
const char *msg;
};
struct pam_response {
char *resp;
int resp_retcode;
};
struct pam_conv {
int (*conv)(int num_msg, const struct pam_message **msg,
struct pam_response **resp, void *appdata_ptr);
void *appdata_ptr;
};
no cap, those three structs are the entire personality of this manpage π
β¨ DESCRIPTION β¨
so,, the PAM library uses an application-defined callback so a loaded module and the application can communicate directly, like, no middleman. this callback is specified by the struct pam_conv that you pass to pam_start(3) at the very start of the transaction. periodt. π
when a module calls the referenced conv() function, the argument appdata_ptr is set to the second element of this structure. yes, that one. the same one. π«Ά
the other arguments of a call to conv() are all about the information that gets exchanged between module and application. so basically: num_msg holds the length of the array of pointers, msg. after a successful return, the pointer resp points to an array of pam_response structures holding the application-supplied text. the resp_retcode member of this struct is unused and should be set to zero (yes really, just zero it, don't be cute about it π). and it is the caller's responsibility to release both β this array and the responses themselves β using free(3). note!! *resp is a struct pam_response array and not an array of pointers. this distinction has ruined people's whole afternoons, ngl π
the number of responses is always equal to the num_msg conversation function argument. this does require that the response array is free(3)'d after every call to the conversation function. no hoarding, bestie. the index of the responses corresponds directly to the prompt index in the pam_message array β so response 0 answers prompt 0, and so on. iconic, honestly. π₯
on failure, the conversation function should release any resources it has allocated and return one of the predefined PAM error codes. like, clean up after yourself, we are not leaving a mess in the group chat π§Ή
each message can have one of four types, specified by the msg_style member of struct pam_message:
PAM_PROMPT_ECHO_OFFβ obtain a string without echoing any text. secret stuff, eyes off the screen πPAM_PROMPT_ECHO_ONβ obtain a string whilst echoing text. yes, you can see what you're typing πPAM_ERROR_MSGβ display an error message. bad news time πPAM_TEXT_INFOβ display some text. just some friendly informational text π
the point of having an array of messages is that it becomes possible to pass a number of things to the application in a single call from the module. it can also be super convenient for the application that related things come at once: a windows-based application can then present a single form with many messages/prompts on at once. efficiency queen π
in passing (and this is the juicy lore), it is worth noting that there is a discrepancy between the way Linux-PAM handles the const struct pam_message **msg conversation function argument and the way Solaris' PAM (and derivatives, known to include HP/UX, are there others?) does. dramatic. πΏ
Linux-PAM interprets the msg argument as entirely equivalent to the following prototype:
const struct pam_message *msg[]
which, in spirit, is consistent with the commonly used prototypes for the argv argument to the familiar main() function: char **argv; and char *argv[].
said another way (iykyk): Linux-PAM interprets the msg argument as a pointer to an array of num_msg read-only struct pam_message pointers. Solaris' PAM implementation interprets this argument as a pointer to a pointer to an array of num_msg pam_message structures. π
fortunately, perhaps, for most module/application developers, when num_msg has a value of one, these two definitions are entirely equivalent. unfortunately, casually raising this number to two has led to unanticipated compatibility problems. π so like. be normal about it.
for what it's worth (and it's worth something), the two known module-writer work-arounds for trying to maintain source-level compatibility with both PAM implementations are:
- never call the conversation function with
num_msggreater than one. - set up
msgas doubly referenced so both types of conversation function can find the messages. that is, make:
msg[n] = & (( *msg )[n])
pick your fighter, bestie. whichever keeps your code compiling π«‘
β RETURN VALUES β
PAM_BUF_ERRβ memory buffer error. a buffer went oop πPAM_CONV_ERRβ conversation failure. the application should not set*resp. like, don't. seriously. π«PAM_SUCCESSβ success. we love to see it π
π SEE ALSO π
pam_start(3), pam_set_item(3), pam_get_item(3), pam_strerror(3), pam(8)
πΈ that's the whole page, and yes you do need all of it. this came to you straight from the Linux-PAM manual, dated 07/08/2026 β go forth and write a conversation function that frees its own memory, queen ππ¦β¨
π¦ where this page comes from
- fedora 44: pam-devel 1.7.2-2.fc44 Β· BSD-3-Clause AND GPL-2.0-or-later
- fedora 44: pam-devel 1.7.2-2.fc44 Β· BSD-3-Clause AND GPL-2.0-or-later
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms