Import Linux-PAM.
[profile/ivi/pam.git] / doc / man / pam_conv.3
1 .\"     Title: pam_conv
2 .\"    Author: [FIXME: author] [see http://docbook.sf.net/el/author]
3 .\" Generator: DocBook XSL Stylesheets v1.74.0 <http://docbook.sf.net/>
4 .\"      Date: 06/21/2011
5 .\"    Manual: Linux-PAM Manual
6 .\"    Source: Linux-PAM Manual
7 .\"  Language: English
8 .\"
9 .TH "PAM_CONV" "3" "06/21/2011" "Linux-PAM Manual" "Linux-PAM Manual"
10 .\" -----------------------------------------------------------------
11 .\" * (re)Define some macros
12 .\" -----------------------------------------------------------------
13 .\" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
14 .\" toupper - uppercase a string (locale-aware)
15 .\" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
16 .de toupper
17 .tr aAbBcCdDeEfFgGhHiIjJkKlLmMnNoOpPqQrRsStTuUvVwWxXyYzZ
18 \\$*
19 .tr aabbccddeeffgghhiijjkkllmmnnooppqqrrssttuuvvwwxxyyzz
20 ..
21 .\" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
22 .\" SH-xref - format a cross-reference to an SH section
23 .\" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
24 .de SH-xref
25 .ie n \{\
26 .\}
27 .toupper \\$*
28 .el \{\
29 \\$*
30 .\}
31 ..
32 .\" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
33 .\" SH - level-one heading that works better for non-TTY output
34 .\" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
35 .de1 SH
36 .\" put an extra blank line of space above the head in non-TTY output
37 .if t \{\
38 .sp 1
39 .\}
40 .sp \\n[PD]u
41 .nr an-level 1
42 .set-an-margin
43 .nr an-prevailing-indent \\n[IN]
44 .fi
45 .in \\n[an-margin]u
46 .ti 0
47 .HTML-TAG ".NH \\n[an-level]"
48 .it 1 an-trap
49 .nr an-no-space-flag 1
50 .nr an-break-flag 1
51 \." make the size of the head bigger
52 .ps +3
53 .ft B
54 .ne (2v + 1u)
55 .ie n \{\
56 .\" if n (TTY output), use uppercase
57 .toupper \\$*
58 .\}
59 .el \{\
60 .nr an-break-flag 0
61 .\" if not n (not TTY), use normal case (not uppercase)
62 \\$1
63 .in \\n[an-margin]u
64 .ti 0
65 .\" if not n (not TTY), put a border/line under subheading
66 .sp -.6
67 \l'\n(.lu'
68 .\}
69 ..
70 .\" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
71 .\" SS - level-two heading that works better for non-TTY output
72 .\" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
73 .de1 SS
74 .sp \\n[PD]u
75 .nr an-level 1
76 .set-an-margin
77 .nr an-prevailing-indent \\n[IN]
78 .fi
79 .in \\n[IN]u
80 .ti \\n[SN]u
81 .it 1 an-trap
82 .nr an-no-space-flag 1
83 .nr an-break-flag 1
84 .ps \\n[PS-SS]u
85 \." make the size of the head bigger
86 .ps +2
87 .ft B
88 .ne (2v + 1u)
89 .if \\n[.$] \&\\$*
90 ..
91 .\" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
92 .\" BB/BE - put background/screen (filled box) around block of text
93 .\" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
94 .de BB
95 .if t \{\
96 .sp -.5
97 .br
98 .in +2n
99 .ll -2n
100 .gcolor red
101 .di BX
102 .\}
103 ..
104 .de EB
105 .if t \{\
106 .if "\\$2"adjust-for-leading-newline" \{\
107 .sp -1
108 .\}
109 .br
110 .di
111 .in
112 .ll
113 .gcolor
114 .nr BW \\n(.lu-\\n(.i
115 .nr BH \\n(dn+.5v
116 .ne \\n(BHu+.5v
117 .ie "\\$2"adjust-for-leading-newline" \{\
118 \M[\\$1]\h'1n'\v'+.5v'\D'P \\n(BWu 0 0 \\n(BHu -\\n(BWu 0 0 -\\n(BHu'\M[]
119 .\}
120 .el \{\
121 \M[\\$1]\h'1n'\v'-.5v'\D'P \\n(BWu 0 0 \\n(BHu -\\n(BWu 0 0 -\\n(BHu'\M[]
122 .\}
123 .in 0
124 .sp -.5v
125 .nf
126 .BX
127 .in
128 .sp .5v
129 .fi
130 .\}
131 ..
132 .\" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
133 .\" BM/EM - put colored marker in margin next to block of text
134 .\" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
135 .de BM
136 .if t \{\
137 .br
138 .ll -2n
139 .gcolor red
140 .di BX
141 .\}
142 ..
143 .de EM
144 .if t \{\
145 .br
146 .di
147 .ll
148 .gcolor
149 .nr BH \\n(dn
150 .ne \\n(BHu
151 \M[\\$1]\D'P -.75n 0 0 \\n(BHu -(\\n[.i]u - \\n(INu - .75n) 0 0 -\\n(BHu'\M[]
152 .in 0
153 .nf
154 .BX
155 .in
156 .fi
157 .\}
158 ..
159 .\" -----------------------------------------------------------------
160 .\" * set default formatting
161 .\" -----------------------------------------------------------------
162 .\" disable hyphenation
163 .nh
164 .\" disable justification (adjust text to left margin only)
165 .ad l
166 .\" -----------------------------------------------------------------
167 .\" * MAIN CONTENT STARTS HERE *
168 .\" -----------------------------------------------------------------
169 .SH "Name"
170 pam_conv \- PAM conversation function
171 .SH "Synopsis"
172 .sp
173 .ft B
174 .fam C
175 .ps -1
176 .nf
177 #include <security/pam_appl\&.h>
178 .fi
179 .fam
180 .ps +1
181 .ft
182 .sp
183 .fam C
184 .ps -1
185 .nf
186 struct pam_message {
187     int msg_style;
188     const char *msg;
189 };
190
191 struct pam_response {
192     char *resp;
193     int resp_retcode;
194 };
195
196 struct pam_conv {
197     int (*conv)(int num_msg, const struct pam_message **msg,
198                 struct pam_response **resp, void *appdata_ptr);
199     void *appdata_ptr;
200 };
201     
202 .fi
203 .fam
204 .ps +1
205 .SH "DESCRIPTION"
206 .PP
207 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
208 \fIstruct pam_conv\fR
209 passed to
210 \fBpam_start\fR(3)
211 at the start of the transaction\&.
212 .PP
213 When a module calls the referenced conv() function, the argument
214 \fIappdata_ptr\fR
215 is set to the second element of this structure\&.
216 .PP
217 The other arguments of a call to conv() concern the information exchanged by module and application\&. That is to say,
218 \fInum_msg\fR
219 holds the length of the array of pointers,
220 \fImsg\fR\&. After a successful return, the pointer
221 \fIresp\fR
222 points to an array of pam_response structures, holding the application supplied text\&. The
223 \fIresp_retcode\fR
224 member of this struct is unused and should be set to zero\&. It is the caller\'s responsibility to release both, this array and the responses themselves, using
225 \fBfree\fR(3)\&. Note,
226 \fI*resp\fR
227 is a
228 \fIstruct pam_response\fR
229 array and not an array of pointers\&.
230 .PP
231 The number of responses is always equal to the
232 \fInum_msg\fR
233 conversation function argument\&. This does require that the response array is
234 \fBfree\fR(3)\'d after every call to the conversation function\&. The index of the responses corresponds directly to the prompt index in the pam_message array\&.
235 .PP
236 On failure, the conversation function should release any resources it has allocated, and return one of the predefined PAM error codes\&.
237 .PP
238 Each message can have one of four types, specified by the
239 \fImsg_style\fR
240 member of
241 \fIstruct pam_message\fR:
242 .PP
243 PAM_PROMPT_ECHO_OFF
244 .RS 4
245 Obtain a string without echoing any text\&.
246 .RE
247 .PP
248 PAM_PROMPT_ECHO_ON
249 .RS 4
250 Obtain a string whilst echoing text\&.
251 .RE
252 .PP
253 PAM_ERROR_MSG
254 .RS 4
255 Display an error message\&.
256 .RE
257 .PP
258 PAM_TEXT_INFO
259 .RS 4
260 Display some text\&.
261 .RE
262 .PP
263 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\&.
264 .PP
265 In passing, it is worth noting that there is a descrepency between the way Linux\-PAM handles the const struct pam_message **msg conversation function argument from the way that Solaris\' PAM (and derivitives, 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 \'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\&.
266 .PP
267 For what its worth the two known module writer work\-arounds for trying to maintain source level compatibility with both PAM implementations are:
268 .sp
269 .RS 4
270 .ie n \{\
271 \h'-04'\(bu\h'+03'\c
272 .\}
273 .el \{\
274 .sp -1
275 .IP \(bu 2.3
276 .\}
277 never call the conversation function with num_msg greater than one\&.
278 .RE
279 .sp
280 .RS 4
281 .ie n \{\
282 \h'-04'\(bu\h'+03'\c
283 .\}
284 .el \{\
285 .sp -1
286 .IP \(bu 2.3
287 .\}
288 set up msg as doubly referenced so both types of conversation function can find the messages\&. That is, make
289 .sp
290 .if n \{\
291 .RS 4
292 .\}
293 .fam C
294 .ps -1
295 .nf
296 .if t \{\
297 .sp -1
298 .\}
299 .BB lightgray adjust-for-leading-newline
300 .sp -1
301
302        msg[n] = & (( *msg )[n])
303        
304 .EB lightgray adjust-for-leading-newline
305 .if t \{\
306 .sp 1
307 .\}
308 .fi
309 .fam
310 .ps +1
311 .if n \{\
312 .RE
313 .\}
314 .RE
315 .SH "RETURN VALUES"
316 .PP
317 PAM_BUF_ERR
318 .RS 4
319 Memory buffer error\&.
320 .RE
321 .PP
322 PAM_CONV_ERR
323 .RS 4
324 Conversation failure\&. The application should not set
325 \fI*resp\fR\&.
326 .RE
327 .PP
328 PAM_SUCCESS
329 .RS 4
330 Success\&.
331 .RE
332 .SH "SEE ALSO"
333 .PP
334
335 \fBpam_start\fR(3),
336 \fBpam_set_item\fR(3),
337 \fBpam_get_item\fR(3),
338 \fBpam_strerror\fR(3),
339 \fBpam\fR(8)