pam_conv.3 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177
  1. '\" t
  2. .\" Title: pam_conv
  3. .\" Author: [FIXME: author] [see http://docbook.sf.net/el/author]
  4. .\" Generator: DocBook XSL Stylesheets v1.79.1 <http://docbook.sf.net/>
  5. .\" Date: 09/03/2021
  6. .\" Manual: Linux-PAM Manual
  7. .\" Source: Linux-PAM Manual
  8. .\" Language: English
  9. .\"
  10. .TH "PAM_CONV" "3" "09/03/2021" "Linux-PAM Manual" "Linux-PAM Manual"
  11. .\" -----------------------------------------------------------------
  12. .\" * Define some portability stuff
  13. .\" -----------------------------------------------------------------
  14. .\" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  15. .\" http://bugs.debian.org/507673
  16. .\" http://lists.gnu.org/archive/html/groff/2009-02/msg00013.html
  17. .\" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  18. .ie \n(.g .ds Aq \(aq
  19. .el .ds Aq '
  20. .\" -----------------------------------------------------------------
  21. .\" * set default formatting
  22. .\" -----------------------------------------------------------------
  23. .\" disable hyphenation
  24. .nh
  25. .\" disable justification (adjust text to left margin only)
  26. .ad l
  27. .\" -----------------------------------------------------------------
  28. .\" * MAIN CONTENT STARTS HERE *
  29. .\" -----------------------------------------------------------------
  30. .SH "NAME"
  31. pam_conv \- PAM conversation function
  32. .SH "SYNOPSIS"
  33. .sp
  34. .ft B
  35. .nf
  36. #include <security/pam_appl\&.h>
  37. .fi
  38. .ft
  39. .sp
  40. .nf
  41. struct pam_message {
  42. int msg_style;
  43. const char *msg;
  44. };
  45. struct pam_response {
  46. char *resp;
  47. int resp_retcode;
  48. };
  49. struct pam_conv {
  50. int (*conv)(int num_msg, const struct pam_message **msg,
  51. struct pam_response **resp, void *appdata_ptr);
  52. void *appdata_ptr;
  53. };
  54. .fi
  55. .SH "DESCRIPTION"
  56. .PP
  57. The PAM library uses an application\-defined callback to allow a direct communication between a loaded module and the application\&. This callback is specified by the
  58. \fIstruct pam_conv\fR
  59. passed to
  60. \fBpam_start\fR(3)
  61. at the start of the transaction\&.
  62. .PP
  63. When a module calls the referenced conv() function, the argument
  64. \fIappdata_ptr\fR
  65. is set to the second element of this structure\&.
  66. .PP
  67. The other arguments of a call to conv() concern the information exchanged by module and application\&. That is to say,
  68. \fInum_msg\fR
  69. holds the length of the array of pointers,
  70. \fImsg\fR\&. After a successful return, the pointer
  71. \fIresp\fR
  72. points to an array of pam_response structures, holding the application supplied text\&. The
  73. \fIresp_retcode\fR
  74. member of this struct is unused and should be set to zero\&. It is the caller\*(Aqs responsibility to release both, this array and the responses themselves, using
  75. \fBfree\fR(3)\&. Note,
  76. \fI*resp\fR
  77. is a
  78. \fIstruct pam_response\fR
  79. array and not an array of pointers\&.
  80. .PP
  81. The number of responses is always equal to the
  82. \fInum_msg\fR
  83. conversation function argument\&. This does require that the response array is
  84. \fBfree\fR(3)\*(Aqd after every call to the conversation function\&. The index of the responses corresponds directly to the prompt index in the pam_message array\&.
  85. .PP
  86. On failure, the conversation function should release any resources it has allocated, and return one of the predefined PAM error codes\&.
  87. .PP
  88. Each message can have one of four types, specified by the
  89. \fImsg_style\fR
  90. member of
  91. \fIstruct pam_message\fR:
  92. .PP
  93. PAM_PROMPT_ECHO_OFF
  94. .RS 4
  95. Obtain a string without echoing any text\&.
  96. .RE
  97. .PP
  98. PAM_PROMPT_ECHO_ON
  99. .RS 4
  100. Obtain a string whilst echoing text\&.
  101. .RE
  102. .PP
  103. PAM_ERROR_MSG
  104. .RS 4
  105. Display an error message\&.
  106. .RE
  107. .PP
  108. PAM_TEXT_INFO
  109. .RS 4
  110. Display some text\&.
  111. .RE
  112. .PP
  113. 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 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\&.
  114. .PP
  115. In passing, 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 that Solaris\*(Aq PAM (and derivatives, known to include HP/UX, are there others?) does\&. 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 argv argument to the familiar main() function: char **argv; and char *argv[])\&. Said another way Linux\-PAM interprets the msg argument as a pointer to an array of num_msg read only \*(Aqstruct pam_message\*(Aq pointers\&. Solaris\*(Aq 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\&.
  116. .PP
  117. For what its worth the two known module writer work\-arounds for trying to maintain source level compatibility with both PAM implementations are:
  118. .sp
  119. .RS 4
  120. .ie n \{\
  121. \h'-04'\(bu\h'+03'\c
  122. .\}
  123. .el \{\
  124. .sp -1
  125. .IP \(bu 2.3
  126. .\}
  127. never call the conversation function with num_msg greater than one\&.
  128. .RE
  129. .sp
  130. .RS 4
  131. .ie n \{\
  132. \h'-04'\(bu\h'+03'\c
  133. .\}
  134. .el \{\
  135. .sp -1
  136. .IP \(bu 2.3
  137. .\}
  138. set up msg as doubly referenced so both types of conversation function can find the messages\&. That is, make
  139. .sp
  140. .if n \{\
  141. .RS 4
  142. .\}
  143. .nf
  144. msg[n] = & (( *msg )[n])
  145. .fi
  146. .if n \{\
  147. .RE
  148. .\}
  149. .RE
  150. .SH "RETURN VALUES"
  151. .PP
  152. PAM_BUF_ERR
  153. .RS 4
  154. Memory buffer error\&.
  155. .RE
  156. .PP
  157. PAM_CONV_ERR
  158. .RS 4
  159. Conversation failure\&. The application should not set
  160. \fI*resp\fR\&.
  161. .RE
  162. .PP
  163. PAM_SUCCESS
  164. .RS 4
  165. Success\&.
  166. .RE
  167. .SH "SEE ALSO"
  168. .PP
  169. \fBpam_start\fR(3),
  170. \fBpam_set_item\fR(3),
  171. \fBpam_get_item\fR(3),
  172. \fBpam_strerror\fR(3),
  173. \fBpam\fR(8)