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_msg greater than one.
  • set up msg as 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