pam_conv.3.xml 7.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228
  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <!DOCTYPE refentry PUBLIC "-//OASIS//DTD DocBook XML V4.1.2//EN"
  3. "http://www.oasis-open.org/docbook/xml/4.1.2/docbookx.dtd">
  4. <refentry id='pam_conv'>
  5. <refmeta>
  6. <refentrytitle>pam_conv</refentrytitle>
  7. <manvolnum>3</manvolnum>
  8. <refmiscinfo class='setdesc'>Linux-PAM Manual</refmiscinfo>
  9. </refmeta>
  10. <refnamediv id="pam_conv-name">
  11. <refname>pam_conv</refname>
  12. <refpurpose>PAM conversation function</refpurpose>
  13. </refnamediv>
  14. <!-- body begins here -->
  15. <refsynopsisdiv>
  16. <funcsynopsis id="pam_conv-synopsis">
  17. <funcsynopsisinfo>#include &lt;security/pam_appl.h&gt;</funcsynopsisinfo>
  18. </funcsynopsis>
  19. <programlisting>
  20. struct pam_message {
  21. int msg_style;
  22. const char *msg;
  23. };
  24. struct pam_response {
  25. char *resp;
  26. int resp_retcode;
  27. };
  28. struct pam_conv {
  29. int (*conv)(int num_msg, const struct pam_message **msg,
  30. struct pam_response **resp, void *appdata_ptr);
  31. void *appdata_ptr;
  32. };
  33. </programlisting>
  34. </refsynopsisdiv>
  35. <refsect1 id='pam_conv-description'>
  36. <title>DESCRIPTION</title>
  37. <para>
  38. The PAM library uses an application-defined callback to allow
  39. a direct communication between a loaded module and the application.
  40. This callback is specified by the
  41. <emphasis>struct pam_conv</emphasis> passed to
  42. <citerefentry>
  43. <refentrytitle>pam_start</refentrytitle><manvolnum>3</manvolnum>
  44. </citerefentry>
  45. at the start of the transaction.
  46. </para>
  47. <para>
  48. When a module calls the referenced conv() function, the argument
  49. <emphasis>appdata_ptr</emphasis> is set to the second element of
  50. this structure.
  51. </para>
  52. <para>
  53. The other arguments of a call to conv() concern the information
  54. exchanged by module and application. That is to say,
  55. <emphasis>num_msg</emphasis> holds the length of the array of
  56. pointers, <emphasis>msg</emphasis>. After a successful return, the
  57. pointer <emphasis>resp</emphasis> points to an array of pam_response
  58. structures, holding the application supplied text. The
  59. <emphasis>resp_retcode</emphasis> member of this struct is unused and
  60. should be set to zero. It is the caller's responsibility to release
  61. both, this array and the responses themselves, using
  62. <citerefentry>
  63. <refentrytitle>free</refentrytitle><manvolnum>3</manvolnum>
  64. </citerefentry>. Note, <emphasis>*resp</emphasis> is a
  65. <emphasis>struct pam_response</emphasis> array and not an array of
  66. pointers.
  67. </para>
  68. <para>
  69. The number of responses is always equal to the
  70. <emphasis>num_msg</emphasis> conversation function argument.
  71. This does require that the response array is
  72. <citerefentry>
  73. <refentrytitle>free</refentrytitle><manvolnum>3</manvolnum>
  74. </citerefentry>'d after
  75. every call to the conversation function. The index of the
  76. responses corresponds directly to the prompt index in the
  77. pam_message array.
  78. </para>
  79. <para>
  80. On failure, the conversation function should release any resources
  81. it has allocated, and return one of the predefined PAM error codes.
  82. </para>
  83. <para>
  84. Each message can have one of four types, specified by the
  85. <emphasis>msg_style</emphasis> member of
  86. <emphasis>struct pam_message</emphasis>:
  87. </para>
  88. <variablelist>
  89. <varlistentry>
  90. <term>PAM_PROMPT_ECHO_OFF</term>
  91. <listitem>
  92. <para>
  93. Obtain a string without echoing any text.
  94. </para>
  95. </listitem>
  96. </varlistentry>
  97. <varlistentry>
  98. <term>PAM_PROMPT_ECHO_ON</term>
  99. <listitem>
  100. <para>
  101. Obtain a string whilst echoing text.
  102. </para>
  103. </listitem>
  104. </varlistentry>
  105. <varlistentry>
  106. <term>PAM_ERROR_MSG</term>
  107. <listitem>
  108. <para>
  109. Display an error message.
  110. </para>
  111. </listitem>
  112. </varlistentry>
  113. <varlistentry>
  114. <term>PAM_TEXT_INFO</term>
  115. <listitem>
  116. <para>
  117. Display some text.
  118. </para>
  119. </listitem>
  120. </varlistentry>
  121. </variablelist>
  122. <para>
  123. The point of having an array of messages is that it becomes possible
  124. to pass a number of things to the application in a single call from
  125. the module. It can also be convenient for the application that related
  126. things come at once: a windows based application can then present a
  127. single form with many messages/prompts on at once.
  128. </para>
  129. <para>
  130. In passing, it is worth noting that there is a discrepancy between
  131. the way Linux-PAM handles the const struct pam_message **msg
  132. conversation function argument and the way that Solaris' PAM
  133. (and derivatives, known to include HP/UX, are there others?) does.
  134. Linux-PAM interprets the msg argument as entirely equivalent to the
  135. following prototype
  136. const struct pam_message *msg[] (which, in spirit, is consistent with
  137. the commonly used prototypes for argv argument to the familiar main()
  138. function: char **argv; and char *argv[]). Said another way Linux-PAM
  139. interprets the msg argument as a pointer to an array of num_msg read
  140. only 'struct pam_message' pointers. Solaris' PAM implementation
  141. interprets this argument as a pointer to a pointer to an array of
  142. num_msg pam_message structures. Fortunately, perhaps, for most
  143. module/application developers when num_msg has a value of one these
  144. two definitions are entirely equivalent. Unfortunately, casually
  145. raising this number to two has led to unanticipated compatibility
  146. problems.
  147. </para>
  148. <para>
  149. For what its worth the two known module writer work-arounds for trying
  150. to maintain source level compatibility with both PAM implementations
  151. are:
  152. </para>
  153. <itemizedlist>
  154. <listitem>
  155. <para>
  156. never call the conversation function with num_msg greater than one.
  157. </para>
  158. </listitem>
  159. <listitem>
  160. <para>
  161. set up msg as doubly referenced so both types of conversation
  162. function can find the messages. That is, make
  163. </para>
  164. <programlisting>
  165. msg[n] = &amp; (( *msg )[n])
  166. </programlisting>
  167. </listitem>
  168. </itemizedlist>
  169. </refsect1>
  170. <refsect1 id="pam_conv-return_values">
  171. <title>RETURN VALUES</title>
  172. <variablelist>
  173. <varlistentry>
  174. <term>PAM_BUF_ERR</term>
  175. <listitem>
  176. <para>
  177. Memory buffer error.
  178. </para>
  179. </listitem>
  180. </varlistentry>
  181. <varlistentry>
  182. <term>PAM_CONV_ERR</term>
  183. <listitem>
  184. <para>
  185. Conversation failure. The application should not set
  186. <emphasis>*resp</emphasis>.
  187. </para>
  188. </listitem>
  189. </varlistentry>
  190. <varlistentry>
  191. <term>PAM_SUCCESS</term>
  192. <listitem>
  193. <para>
  194. Success.
  195. </para>
  196. </listitem>
  197. </varlistentry>
  198. </variablelist>
  199. </refsect1>
  200. <refsect1 id='pam_conv-see_also'>
  201. <title>SEE ALSO</title>
  202. <para>
  203. <citerefentry>
  204. <refentrytitle>pam_start</refentrytitle><manvolnum>3</manvolnum>
  205. </citerefentry>,
  206. <citerefentry>
  207. <refentrytitle>pam_set_item</refentrytitle><manvolnum>3</manvolnum>
  208. </citerefentry>,
  209. <citerefentry>
  210. <refentrytitle>pam_get_item</refentrytitle><manvolnum>3</manvolnum>
  211. </citerefentry>,
  212. <citerefentry>
  213. <refentrytitle>pam_strerror</refentrytitle><manvolnum>3</manvolnum>
  214. </citerefentry>,
  215. <citerefentry>
  216. <refentrytitle>pam</refentrytitle><manvolnum>8</manvolnum>
  217. </citerefentry>
  218. </para>
  219. </refsect1>
  220. </refentry>