/usr/share/doc/libpam-doc/html/mwg-expected-by-module-item.html is in libpam-doc 1.1.8-3.6.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 | <html><head><meta http-equiv="Content-Type" content="text/html; charset=UTF-8"><title>2.1. Getting and setting PAM_ITEMs and data</title><meta name="generator" content="DocBook XSL Stylesheets V1.79.1"><link rel="home" href="Linux-PAM_MWG.html" title="The Linux-PAM Module Writers' Guide"><link rel="up" href="mwg-expected-by-module.html" title="Chapter 2. What can be expected by the module"><link rel="prev" href="mwg-expected-by-module.html" title="Chapter 2. What can be expected by the module"><link rel="next" href="mwg-expected-by-module-other.html" title="2.2. Other functions provided by libpam"></head><body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF"><div class="navheader"><table width="100%" summary="Navigation header"><tr><th colspan="3" align="center">2.1.
Getting and setting <span class="emphasis"><em>PAM_ITEM</em></span>s and
<span class="emphasis"><em>data</em></span>
</th></tr><tr><td width="20%" align="left"><a accesskey="p" href="mwg-expected-by-module.html">Prev</a> </td><th width="60%" align="center">Chapter 2. What can be expected by the module</th><td width="20%" align="right"> <a accesskey="n" href="mwg-expected-by-module-other.html">Next</a></td></tr></table><hr></div><div class="section"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a name="mwg-expected-by-module-item"></a>2.1.
Getting and setting <span class="emphasis"><em>PAM_ITEM</em></span>s and
<span class="emphasis"><em>data</em></span>
</h2></div></div></div><p>
First, we cover what the module should expect from the
<span class="emphasis"><em>Linux-PAM</em></span> library and a
<span class="emphasis"><em>Linux-PAM</em></span> aware application.
Essentially this is the <code class="filename">libpam.*</code> library.
</p><div class="section"><div class="titlepage"><div><div><h3 class="title"><a name="mwg-pam_set_data"></a>2.1.1. Set module internal data</h3></div></div></div><div class="funcsynopsis"><pre class="funcsynopsisinfo">#include <security/pam_modules.h></pre><table border="0" class="funcprototype-table" summary="Function synopsis" style="cellspacing: 0; cellpadding: 0;"><tr><td><code class="funcdef">int <b class="fsfunc">pam_set_data</b>(</code></td><td><var class="pdparam">pamh</var>, </td><td> </td></tr><tr><td> </td><td><var class="pdparam">module_data_name</var>, </td><td> </td></tr><tr><td> </td><td><var class="pdparam">data</var>, </td><td> </td></tr><tr><td> </td><td><var class="pdparam">(*cleanup)(pam_handle_t *pamh, void *data, int error_status)</var><code>)</code>;</td><td> </td></tr></table><div class="paramdef-list"><code>pam_handle_t *<var class="pdparam">pamh</var></code>;<br><code>const char *<var class="pdparam">module_data_name</var></code>;<br><code>void *<var class="pdparam">data</var></code>;<br><code>void <var class="pdparam">(*cleanup)(pam_handle_t *pamh, void *data, int error_status)</var></code>;</div><div class="funcprototype-spacer"> </div></div><div class="section"><div class="titlepage"><div><div><h4 class="title"><a name="mwg-pam_set_data-description"></a>2.1.1.1. DESCRIPTION</h4></div></div></div><p>
The <code class="function">pam_set_data</code> function associates a pointer
to an object with the (hopefully) unique string
<span class="emphasis"><em>module_data_name</em></span> in the PAM context specified
by the <span class="emphasis"><em>pamh</em></span> argument.
</p><p>
PAM modules may be dynamically loadable objects. In general such files
should not contain <span class="emphasis"><em>static</em></span> variables. This function
and its counterpart
<span class="citerefentry"><span class="refentrytitle">pam_get_data</span>(3)</span>,
provide a mechanism for a module to associate some data with
the handle <span class="emphasis"><em>pamh</em></span>. Typically a module will call the
<code class="function">pam_set_data</code> function to register some data
under a (hopefully) unique <span class="emphasis"><em>module_data_name</em></span>.
The data is available for use by other modules too but
<span class="emphasis"><em>not</em></span> by an application. Since this functions
stores only a pointer to the <span class="emphasis"><em>data</em></span>, the module
should not modify or free the content of it.
</p><p>
The function <code class="function">cleanup()</code> is associated with the
<span class="emphasis"><em>data</em></span> and, if non-NULL, it is called when this
data is over-written or following a call to
<span class="citerefentry"><span class="refentrytitle">pam_end</span>(3)</span>.
</p><p>
The <span class="emphasis"><em>error_status</em></span> argument is used to indicate
to the module the sort of action it is to take in cleaning this data
item. As an example, Kerberos creates a ticket file during the
authentication phase, this file might be associated with a data item.
When
<span class="citerefentry"><span class="refentrytitle">pam_end</span>(3)</span>
is called by the module, the <span class="emphasis"><em>error_status</em></span>
carries the return value of the
<span class="citerefentry"><span class="refentrytitle">pam_authenticate</span>(3)</span>
or other <span class="emphasis"><em>libpam</em></span> function as appropriate. Based
on this value the Kerberos module may choose to delete the ticket file
(<span class="emphasis"><em>authentication failure</em></span>) or leave it in place.
</p><p>
The <span class="emphasis"><em>error_status</em></span> may have been logically
OR'd with either of the following two values:
</p><div class="variablelist"><dl class="variablelist"><dt><span class="term">PAM_DATA_REPLACE</span></dt><dd><p>
When a data item is being replaced (through a second call to
<code class="function">pam_set_data</code>) this mask is used.
Otherwise, the call is assumed to be from
<span class="citerefentry"><span class="refentrytitle">pam_end</span>(3)</span>.
</p></dd><dt><span class="term">PAM_DATA_SILENT</span></dt><dd><p>
Which indicates that the process would prefer to perform the
<code class="function">cleanup()</code> quietly. That is, discourages
logging/messages to the user.
</p></dd></dl></div></div><div class="section"><div class="titlepage"><div><div><h4 class="title"><a name="mwg-pam_set_data-return_values"></a>2.1.1.2. RETURN VALUES</h4></div></div></div><div class="variablelist"><dl class="variablelist"><dt><span class="term">PAM_BUF_ERR</span></dt><dd><p>
Memory buffer error.
</p></dd><dt><span class="term">PAM_SUCCESS</span></dt><dd><p>
Data was successful stored.
</p></dd><dt><span class="term">PAM_SYSTEM_ERR</span></dt><dd><p>
A NULL pointer was submitted as PAM handle or the
function was called by an application.
</p></dd></dl></div></div></div><div class="section"><div class="titlepage"><div><div><h3 class="title"><a name="mwg-pam_get_data"></a>2.1.2. Get module internal data</h3></div></div></div><div class="funcsynopsis"><pre class="funcsynopsisinfo">#include <security/pam_modules.h></pre><table border="0" class="funcprototype-table" summary="Function synopsis" style="cellspacing: 0; cellpadding: 0;"><tr><td><code class="funcdef">int <b class="fsfunc">pam_get_data</b>(</code></td><td><var class="pdparam">pamh</var>, </td><td> </td></tr><tr><td> </td><td><var class="pdparam">module_data_name</var>, </td><td> </td></tr><tr><td> </td><td><var class="pdparam">data</var><code>)</code>;</td><td> </td></tr></table><div class="paramdef-list"><code>const pam_handle_t *<var class="pdparam">pamh</var></code>;<br><code>const char *<var class="pdparam">module_data_name</var></code>;<br><code>const void **<var class="pdparam">data</var></code>;</div><div class="funcprototype-spacer"> </div></div><div class="section"><div class="titlepage"><div><div><h4 class="title"><a name="mwg-pam_get_data-description"></a>2.1.2.1. DESCRIPTION</h4></div></div></div><p>
This function together with the
<span class="citerefentry"><span class="refentrytitle">pam_set_data</span>(3)</span> function
is useful to manage module-specific data meaningful only to
the calling PAM module.
</p><p>
The <code class="function">pam_get_data</code> function looks up the
object associated with the (hopefully) unique string
<span class="emphasis"><em>module_data_name</em></span> in the PAM context
specified by the <span class="emphasis"><em>pamh</em></span> argument.
A successful call to
<code class="function">pam_get_data</code> will result in
<span class="emphasis"><em>data</em></span> pointing to the object. Note,
this data is <span class="emphasis"><em>not</em></span> a copy and should be
treated as <span class="emphasis"><em>constant</em></span> by the module.
</p></div><div class="section"><div class="titlepage"><div><div><h4 class="title"><a name="mwg-pam_get_data-return_values"></a>2.1.2.2. RETURN VALUES</h4></div></div></div><div class="variablelist"><dl class="variablelist"><dt><span class="term">PAM_SUCCESS</span></dt><dd><p>
Data was successful retrieved.
</p></dd><dt><span class="term">PAM_SYSTEM_ERR</span></dt><dd><p>
A NULL pointer was submitted as PAM handle or the
function was called by an application.
</p></dd><dt><span class="term">PAM_NO_MODULE_DATA</span></dt><dd><p>
Module data not found or there is an entry, but it has
the value NULL.
</p></dd></dl></div></div></div><div class="section"><div class="titlepage"><div><div><h3 class="title"><a name="mwg-pam_set_item"></a>2.1.3. Setting PAM items</h3></div></div></div><div class="funcsynopsis"><pre class="funcsynopsisinfo">#include <security/pam_modules.h></pre><table border="0" class="funcprototype-table" summary="Function synopsis" style="cellspacing: 0; cellpadding: 0;"><tr><td><code class="funcdef">int <b class="fsfunc">pam_set_item</b>(</code></td><td><var class="pdparam">pamh</var>, </td><td> </td></tr><tr><td> </td><td><var class="pdparam">item_type</var>, </td><td> </td></tr><tr><td> </td><td><var class="pdparam">item</var><code>)</code>;</td><td> </td></tr></table><div class="paramdef-list"><code>pam_handle_t *<var class="pdparam">pamh</var></code>;<br><code>int <var class="pdparam">item_type</var></code>;<br><code>const void *<var class="pdparam">item</var></code>;</div><div class="funcprototype-spacer"> </div></div><div class="section"><div class="titlepage"><div><div><h4 class="title"><a name="mwg-pam_set_item-description"></a>2.1.3.1. DESCRIPTION</h4></div></div></div><p>
The <code class="function">pam_set_item</code> function allows applications
and PAM service modules to access and to update PAM informations
of <span class="emphasis"><em>item_type</em></span>. For this a copy
of the object pointed to by the <span class="emphasis"><em>item</em></span> argument
is created. The following <span class="emphasis"><em>item_type</em></span>s are
supported:
</p><div class="variablelist"><dl class="variablelist"><dt><span class="term">PAM_SERVICE</span></dt><dd><p>
The service name (which identifies that PAM stack that
the PAM functions will use to authenticate the program).
</p></dd><dt><span class="term">PAM_USER</span></dt><dd><p>
The username of the entity under whose identity service
will be given. That is, following authentication,
<span class="emphasis"><em>PAM_USER</em></span> identifies the local entity
that gets to use the service. Note, this value can be mapped
from something (eg., "anonymous") to something else (eg.
"guest119") by any module in the PAM stack. As such an
application should consult the value of
<span class="emphasis"><em>PAM_USER</em></span> after each call to a PAM function.
</p></dd><dt><span class="term">PAM_USER_PROMPT</span></dt><dd><p>
The string used when prompting for a user's name. The default
value for this string is a localized version of "login: ".
</p></dd><dt><span class="term">PAM_TTY</span></dt><dd><p>
The terminal name: prefixed by <code class="filename">/dev/</code> if
it is a device file; for graphical, X-based, applications the
value for this item should be the
<span class="emphasis"><em>$DISPLAY</em></span> variable.
</p></dd><dt><span class="term">PAM_RUSER</span></dt><dd><p>
The requesting user name: local name for a locally
requesting user or a remote user name for a remote
requesting user.
</p><p>
Generally an application or module will attempt to supply
the value that is most strongly authenticated (a local account
before a remote one. The level of trust in this value is
embodied in the actual authentication stack associated with
the application, so it is ultimately at the discretion of the
system administrator.
</p><p>
<span class="emphasis"><em>PAM_RUSER@PAM_RHOST</em></span> should always identify
the requesting user. In some cases,
<span class="emphasis"><em>PAM_RUSER</em></span> may be NULL. In such situations,
it is unclear who the requesting entity is.
</p></dd><dt><span class="term">PAM_RHOST</span></dt><dd><p>
The requesting hostname (the hostname of the machine from
which the <span class="emphasis"><em>PAM_RUSER</em></span> entity is requesting
service). That is <span class="emphasis"><em>PAM_RUSER@PAM_RHOST</em></span>
does identify the requesting user. In some applications,
<span class="emphasis"><em>PAM_RHOST</em></span> may be NULL. In such situations,
it is unclear where the authentication request is originating
from.
</p></dd><dt><span class="term">PAM_AUTHTOK</span></dt><dd><p>
The authentication token (often a password). This token
should be ignored by all module functions besides
<span class="citerefentry"><span class="refentrytitle">pam_sm_authenticate</span>(3)</span> and
<span class="citerefentry"><span class="refentrytitle">pam_sm_chauthtok</span>(3)</span>.
In the former function it is used to pass the most recent
authentication token from one stacked module to another. In
the latter function the token is used for another purpose.
It contains the currently active authentication token.
</p></dd><dt><span class="term">PAM_OLDAUTHTOK</span></dt><dd><p>
The old authentication token. This token should be ignored
by all module functions except
<span class="citerefentry"><span class="refentrytitle">pam_sm_chauthtok</span>(3)</span>.
</p></dd><dt><span class="term">PAM_CONV</span></dt><dd><p>
The pam_conv structure. See
<span class="citerefentry"><span class="refentrytitle">pam_conv</span>(3)</span>.
</p></dd></dl></div><p>
The following additional items are specific to Linux-PAM and should not be used in
portable applications:
</p><div class="variablelist"><dl class="variablelist"><dt><span class="term">PAM_FAIL_DELAY</span></dt><dd><p>
A function pointer to redirect centrally managed
failure delays. See
<span class="citerefentry"><span class="refentrytitle">pam_fail_delay</span>(3)</span>.
</p></dd><dt><span class="term">PAM_XDISPLAY</span></dt><dd><p>
The name of the X display. For graphical, X-based applications the
value for this item should be the <span class="emphasis"><em>$DISPLAY</em></span>
variable. This value may be used independently of
<span class="emphasis"><em>PAM_TTY</em></span> for passing the
name of the display.
</p></dd><dt><span class="term">PAM_XAUTHDATA</span></dt><dd><p>
A pointer to a structure containing the X authentication data
required to make a connection to the display specified by
<span class="emphasis"><em>PAM_XDISPLAY</em></span>, if such information is
necessary. See
<span class="citerefentry"><span class="refentrytitle">pam_xauth_data</span>(3)</span>.
</p></dd><dt><span class="term">PAM_AUTHTOK_TYPE</span></dt><dd><p>
The default action is for the module to use the
following prompts when requesting passwords:
"New UNIX password: " and "Retype UNIX password: ".
The example word <span class="emphasis"><em>UNIX</em></span> can
be replaced with this item, by default it is empty.
This item is used by <span class="citerefentry"><span class="refentrytitle">pam_get_authtok</span>(3)</span>.
</p></dd></dl></div><p>
For all <span class="emphasis"><em>item_type</em></span>s, other than PAM_CONV and
PAM_FAIL_DELAY, <span class="emphasis"><em>item</em></span> is a pointer to a <NUL>
terminated character string. In the case of PAM_CONV,
<span class="emphasis"><em>item</em></span> points to an initialized
<span class="emphasis"><em>pam_conv</em></span> structure. In the case of
PAM_FAIL_DELAY, <span class="emphasis"><em>item</em></span> is a function pointer:
<code class="function">void (*delay_fn)(int retval, unsigned usec_delay, void *appdata_ptr)</code>
</p><p>
Both, PAM_AUTHTOK and PAM_OLDAUTHTOK, will be reseted before
returning to the application. Which means an application is not
able to access the authentication tokens.
</p></div><div class="section"><div class="titlepage"><div><div><h4 class="title"><a name="mwg-pam_set_item-return_values"></a>2.1.3.2. RETURN VALUES</h4></div></div></div><div class="variablelist"><dl class="variablelist"><dt><span class="term">PAM_BAD_ITEM</span></dt><dd><p>
The application attempted to set an undefined or inaccessible
item.
</p></dd><dt><span class="term">PAM_BUF_ERR</span></dt><dd><p>
Memory buffer error.
</p></dd><dt><span class="term">PAM_SUCCESS</span></dt><dd><p>
Data was successful updated.
</p></dd><dt><span class="term">PAM_SYSTEM_ERR</span></dt><dd><p>
The <span class="emphasis"><em>pam_handle_t</em></span> passed as first
argument was invalid.
</p></dd></dl></div></div></div><div class="section"><div class="titlepage"><div><div><h3 class="title"><a name="mwg-pam_get_item"></a>2.1.4. Getting PAM items</h3></div></div></div><div class="funcsynopsis"><pre class="funcsynopsisinfo">#include <security/pam_modules.h></pre><table border="0" class="funcprototype-table" summary="Function synopsis" style="cellspacing: 0; cellpadding: 0;"><tr><td><code class="funcdef">int <b class="fsfunc">pam_get_item</b>(</code></td><td><var class="pdparam">pamh</var>, </td><td> </td></tr><tr><td> </td><td><var class="pdparam">item_type</var>, </td><td> </td></tr><tr><td> </td><td><var class="pdparam">item</var><code>)</code>;</td><td> </td></tr></table><div class="paramdef-list"><code>const pam_handle_t *<var class="pdparam">pamh</var></code>;<br><code>int <var class="pdparam">item_type</var></code>;<br><code>const void **<var class="pdparam">item</var></code>;</div><div class="funcprototype-spacer"> </div></div><div class="section"><div class="titlepage"><div><div><h4 class="title"><a name="mwg-pam_get_item-description"></a>2.1.4.1. DESCRIPTION</h4></div></div></div><p>
The <code class="function">pam_get_item</code> function allows applications
and PAM service modules to access and retrieve PAM informations
of <span class="emphasis"><em>item_type</em></span>. Upon successful return,
<span class="emphasis"><em>item</em></span> contains a pointer to the value of the
corresponding item. Note, this is a pointer to the
<span class="emphasis"><em>actual</em></span> data and should
<span class="emphasis"><em>not</em></span> be <span class="emphasis"><em>free()</em></span>'ed or
over-written! The following values are supported for
<span class="emphasis"><em>item_type</em></span>:
</p><div class="variablelist"><dl class="variablelist"><dt><span class="term">PAM_SERVICE</span></dt><dd><p>
The service name (which identifies that PAM stack that
the PAM functions will use to authenticate the program).
</p></dd><dt><span class="term">PAM_USER</span></dt><dd><p>
The username of the entity under whose identity service
will be given. That is, following authentication,
<span class="emphasis"><em>PAM_USER</em></span> identifies the local entity
that gets to use the service. Note, this value can be mapped
from something (eg., "anonymous") to something else (eg.
"guest119") by any module in the PAM stack. As such an
application should consult the value of
<span class="emphasis"><em>PAM_USER</em></span> after each call to a PAM function.
</p></dd><dt><span class="term">PAM_USER_PROMPT</span></dt><dd><p>
The string used when prompting for a user's name. The default
value for this string is a localized version of "login: ".
</p></dd><dt><span class="term">PAM_TTY</span></dt><dd><p>
The terminal name: prefixed by <code class="filename">/dev/</code> if
it is a device file; for graphical, X-based, applications the
value for this item should be the
<span class="emphasis"><em>$DISPLAY</em></span> variable.
</p></dd><dt><span class="term">PAM_RUSER</span></dt><dd><p>
The requesting user name: local name for a locally
requesting user or a remote user name for a remote
requesting user.
</p><p>
Generally an application or module will attempt to supply
the value that is most strongly authenticated (a local account
before a remote one. The level of trust in this value is
embodied in the actual authentication stack associated with
the application, so it is ultimately at the discretion of the
system administrator.
</p><p>
<span class="emphasis"><em>PAM_RUSER@PAM_RHOST</em></span> should always identify
the requesting user. In some cases,
<span class="emphasis"><em>PAM_RUSER</em></span> may be NULL. In such situations,
it is unclear who the requesting entity is.
</p></dd><dt><span class="term">PAM_RHOST</span></dt><dd><p>
The requesting hostname (the hostname of the machine from
which the <span class="emphasis"><em>PAM_RUSER</em></span> entity is requesting
service). That is <span class="emphasis"><em>PAM_RUSER@PAM_RHOST</em></span>
does identify the requesting user. In some applications,
<span class="emphasis"><em>PAM_RHOST</em></span> may be NULL. In such situations,
it is unclear where the authentication request is originating
from.
</p></dd><dt><span class="term">PAM_AUTHTOK</span></dt><dd><p>
The authentication token (often a password). This token
should be ignored by all module functions besides
<span class="citerefentry"><span class="refentrytitle">pam_sm_authenticate</span>(3)</span> and
<span class="citerefentry"><span class="refentrytitle">pam_sm_chauthtok</span>(3)</span>.
In the former function it is used to pass the most recent
authentication token from one stacked module to another. In
the latter function the token is used for another purpose.
It contains the currently active authentication token.
</p></dd><dt><span class="term">PAM_OLDAUTHTOK</span></dt><dd><p>
The old authentication token. This token should be ignored
by all module functions except
<span class="citerefentry"><span class="refentrytitle">pam_sm_chauthtok</span>(3)</span>.
</p></dd><dt><span class="term">PAM_CONV</span></dt><dd><p>
The pam_conv structure. See
<span class="citerefentry"><span class="refentrytitle">pam_conv</span>(3)</span>.
</p></dd></dl></div><p>
The following additional items are specific to Linux-PAM and should not be used in
portable applications:
</p><div class="variablelist"><dl class="variablelist"><dt><span class="term">PAM_FAIL_DELAY</span></dt><dd><p>
A function pointer to redirect centrally managed
failure delays. See
<span class="citerefentry"><span class="refentrytitle">pam_fail_delay</span>(3)</span>.
</p></dd><dt><span class="term">PAM_XDISPLAY</span></dt><dd><p>
The name of the X display. For graphical, X-based applications the
value for this item should be the <span class="emphasis"><em>$DISPLAY</em></span>
variable. This value may be used independently of
<span class="emphasis"><em>PAM_TTY</em></span> for passing the
name of the display.
</p></dd><dt><span class="term">PAM_XAUTHDATA</span></dt><dd><p>
A pointer to a structure containing the X authentication data
required to make a connection to the display specified by
<span class="emphasis"><em>PAM_XDISPLAY</em></span>, if such information is
necessary. See
<span class="citerefentry"><span class="refentrytitle">pam_xauth_data</span>(3)</span>.
</p></dd><dt><span class="term">PAM_AUTHTOK_TYPE</span></dt><dd><p>
The default action is for the module to use the
following prompts when requesting passwords:
"New UNIX password: " and "Retype UNIX password: ".
The example word <span class="emphasis"><em>UNIX</em></span> can
be replaced with this item, by default it is empty.
This item is used by <span class="citerefentry"><span class="refentrytitle">pam_get_authtok</span>(3)</span>.
</p></dd></dl></div><p>
If a service module wishes to obtain the name of the user,
it should not use this function, but instead perform a call to
<span class="citerefentry"><span class="refentrytitle">pam_get_user</span>(3)</span>.
</p><p>
Only a service module is privileged to read the
authentication tokens, PAM_AUTHTOK and PAM_OLDAUTHTOK.
</p></div><div class="section"><div class="titlepage"><div><div><h4 class="title"><a name="mwg-pam_get_item-return_values"></a>2.1.4.2. RETURN VALUES</h4></div></div></div><div class="variablelist"><dl class="variablelist"><dt><span class="term">PAM_BAD_ITEM</span></dt><dd><p>
The application attempted to set an undefined or inaccessible
item.
</p></dd><dt><span class="term">PAM_BUF_ERR</span></dt><dd><p>
Memory buffer error.
</p></dd><dt><span class="term">PAM_PERM_DENIED</span></dt><dd><p>
The value of <span class="emphasis"><em>item</em></span> was NULL.
</p></dd><dt><span class="term">PAM_SUCCESS</span></dt><dd><p>
Data was successful updated.
</p></dd><dt><span class="term">PAM_SYSTEM_ERR</span></dt><dd><p>
The <span class="emphasis"><em>pam_handle_t</em></span> passed as first
argument was invalid.
</p></dd></dl></div></div></div><div class="section"><div class="titlepage"><div><div><h3 class="title"><a name="mwg-pam_get_user"></a>2.1.5. Get user name</h3></div></div></div><div class="funcsynopsis"><pre class="funcsynopsisinfo">#include <security/pam_modules.h></pre><table border="0" class="funcprototype-table" summary="Function synopsis" style="cellspacing: 0; cellpadding: 0;"><tr><td><code class="funcdef">int <b class="fsfunc">pam_get_user</b>(</code></td><td><var class="pdparam">pamh</var>, </td><td> </td></tr><tr><td> </td><td><var class="pdparam">user</var>, </td><td> </td></tr><tr><td> </td><td><var class="pdparam">prompt</var><code>)</code>;</td><td> </td></tr></table><div class="paramdef-list"><code>const pam_handle_t *<var class="pdparam">pamh</var></code>;<br><code>const char **<var class="pdparam">user</var></code>;<br><code>const char *<var class="pdparam">prompt</var></code>;</div><div class="funcprototype-spacer"> </div></div><div class="section"><div class="titlepage"><div><div><h4 class="title"><a name="mwg-pam_get_user-description"></a>2.1.5.1. DESCRIPTION</h4></div></div></div><p>
The <code class="function">pam_get_user</code> function returns the
name of the user specified by
<span class="citerefentry"><span class="refentrytitle">pam_start</span>(3)</span>. If no user was specified it what
<code class="function">pam_get_item (pamh, PAM_USER, ... );</code> would
have returned. If this is NULL it obtains the username via the
<span class="citerefentry"><span class="refentrytitle">pam_conv</span>(3)</span> mechanism, it prompts the user with the first
non-NULL string in the following list:
</p><div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: disc; "><li class="listitem"><p>
The <span class="emphasis"><em>prompt</em></span> argument passed to the function.
</p></li><li class="listitem"><p>
What is returned by pam_get_item (pamh, PAM_USER_PROMPT, ... );
</p></li><li class="listitem"><p>
The default prompt: "login: "
</p></li></ul></div><p>
By whatever means the username is obtained, a pointer to it is
returned as the contents of <span class="emphasis"><em>*user</em></span>. Note,
this memory should <span class="emphasis"><em>not</em></span> be
<span class="emphasis"><em>free()</em></span>'d or <span class="emphasis"><em>modified</em></span>
by the module.
</p><p>
This function sets the <span class="emphasis"><em>PAM_USER</em></span> item
associated with the
<span class="citerefentry"><span class="refentrytitle">pam_set_item</span>(3)</span> and
<span class="citerefentry"><span class="refentrytitle">pam_get_item</span>(3)</span> functions.
</p></div><div class="section"><div class="titlepage"><div><div><h4 class="title"><a name="mwg-pam_get_user-return_values"></a>2.1.5.2. RETURN VALUES</h4></div></div></div><div class="variablelist"><dl class="variablelist"><dt><span class="term">PAM_SUCCESS</span></dt><dd><p>
User name was successful retrieved.
</p></dd><dt><span class="term">PAM_SYSTEM_ERR</span></dt><dd><p>
A NULL pointer was submitted.
</p></dd><dt><span class="term">PAM_CONV_ERR</span></dt><dd><p>
The conversation method supplied by the
application failed to obtain the username.
</p></dd></dl></div></div></div><div class="section"><div class="titlepage"><div><div><h3 class="title"><a name="mwg-pam_conv"></a>2.1.6. The conversation function</h3></div></div></div><div class="funcsynopsis"><pre class="funcsynopsisinfo">#include <security/pam_appl.h></pre></div><pre class="programlisting">
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;
};
</pre><div class="section"><div class="titlepage"><div><div><h4 class="title"><a name="mwg-pam_conv-description"></a>2.1.6.1. DESCRIPTION</h4></div></div></div><p>
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
<span class="emphasis"><em>struct pam_conv</em></span> passed to
<span class="citerefentry"><span class="refentrytitle">pam_start</span>(3)</span>
at the start of the transaction.
</p><p>
When a module calls the referenced conv() function, the argument
<span class="emphasis"><em>appdata_ptr</em></span> is set to the second element of
this structure.
</p><p>
The other arguments of a call to conv() concern the information
exchanged by module and application. That is to say,
<span class="emphasis"><em>num_msg</em></span> holds the length of the array of
pointers, <span class="emphasis"><em>msg</em></span>. After a successful return, the
pointer <span class="emphasis"><em>resp</em></span> points to an array of pam_response
structures, holding the application supplied text. The
<span class="emphasis"><em>resp_retcode</em></span> 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
<span class="citerefentry"><span class="refentrytitle">free</span>(3)</span>. Note, <span class="emphasis"><em>*resp</em></span> is a
<span class="emphasis"><em>struct pam_response</em></span> array and not an array of
pointers.
</p><p>
The number of responses is always equal to the
<span class="emphasis"><em>num_msg</em></span> conversation function argument.
This does require that the response array is
<span class="citerefentry"><span class="refentrytitle">free</span>(3)</span>'d after
every call to the conversation function. The index of the
responses corresponds directly to the prompt index in the
pam_message array.
</p><p>
On failure, the conversation function should release any resources
it has allocated, and return one of the predefined PAM error codes.
</p><p>
Each message can have one of four types, specified by the
<span class="emphasis"><em>msg_style</em></span> member of
<span class="emphasis"><em>struct pam_message</em></span>:
</p><div class="variablelist"><dl class="variablelist"><dt><span class="term">PAM_PROMPT_ECHO_OFF</span></dt><dd><p>
Obtain a string without echoing any text.
</p></dd><dt><span class="term">PAM_PROMPT_ECHO_ON</span></dt><dd><p>
Obtain a string whilst echoing text.
</p></dd><dt><span class="term">PAM_ERROR_MSG</span></dt><dd><p>
Display an error message.
</p></dd><dt><span class="term">PAM_TEXT_INFO</span></dt><dd><p>
Display some text.
</p></dd></dl></div><p>
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.
</p><p>
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.
</p><p>
For what its worth the two known module writer work-arounds for trying
to maintain source level compatibility with both PAM implementations
are:
</p><div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: disc; "><li class="listitem"><p>
never call the conversation function with num_msg greater than one.
</p></li><li class="listitem"><p>
set up msg as doubly referenced so both types of conversation
function can find the messages. That is, make
</p><pre class="programlisting">
msg[n] = & (( *msg )[n])
</pre></li></ul></div></div><div class="section"><div class="titlepage"><div><div><h4 class="title"><a name="mwg-pam_conv-return_values"></a>2.1.6.2. RETURN VALUES</h4></div></div></div><div class="variablelist"><dl class="variablelist"><dt><span class="term">PAM_BUF_ERR</span></dt><dd><p>
Memory buffer error.
</p></dd><dt><span class="term">PAM_CONV_ERR</span></dt><dd><p>
Conversation failure. The application should not set
<span class="emphasis"><em>*resp</em></span>.
</p></dd><dt><span class="term">PAM_SUCCESS</span></dt><dd><p>
Success.
</p></dd></dl></div></div></div><div class="section"><div class="titlepage"><div><div><h3 class="title"><a name="adg-pam_putenv"></a>2.1.7. Set or change PAM environment variable</h3></div></div></div><div class="funcsynopsis"><pre class="funcsynopsisinfo">#include <security/pam_appl.h></pre><table border="0" class="funcprototype-table" summary="Function synopsis" style="cellspacing: 0; cellpadding: 0;"><tr><td><code class="funcdef">int <b class="fsfunc">pam_putenv</b>(</code></td><td><var class="pdparam">pamh</var>, </td><td> </td></tr><tr><td> </td><td><var class="pdparam">name_value</var><code>)</code>;</td><td> </td></tr></table><div class="paramdef-list"><code>pam_handle_t *<var class="pdparam">pamh</var></code>;<br><code>const char *<var class="pdparam">name_value</var></code>;</div><div class="funcprototype-spacer"> </div></div><div class="section"><div class="titlepage"><div><div><h4 class="title"><a name="adg-pam_putenv-description"></a>2.1.7.1. DESCRIPTION</h4></div></div></div><p>
The <code class="function">pam_putenv</code> function is used to
add or change the value of PAM environment variables as
associated with the <span class="emphasis"><em>pamh</em></span> handle.
</p><p>
The <span class="emphasis"><em>pamh</em></span> argument is an authentication
handle obtained by a prior call to pam_start().
The <span class="emphasis"><em>name_value</em></span> argument is a single NUL
terminated string of one of the following forms:
</p><div class="variablelist"><dl class="variablelist"><dt><span class="term">NAME=value of variable</span></dt><dd><p>
In this case the environment variable of the given NAME
is set to the indicated value:
<span class="emphasis"><em>value of variable</em></span>. If this variable
is already known, it is overwritten. Otherwise it is added
to the PAM environment.
</p></dd><dt><span class="term">NAME=</span></dt><dd><p>
This function sets the variable to an empty value. It is
listed separately to indicate that this is the correct way
to achieve such a setting.
</p></dd><dt><span class="term">NAME</span></dt><dd><p>
Without an '=' the <code class="function">pam_putenv</code>() function
will delete the
corresponding variable from the PAM environment.
</p></dd></dl></div><p>
<code class="function">pam_putenv</code>() operates on a copy of
<span class="emphasis"><em>name_value</em></span>, which means in contrast to
<span class="citerefentry"><span class="refentrytitle">putenv</span>(3)</span>, the application is responsible to free the data.
</p></div><div class="section"><div class="titlepage"><div><div><h4 class="title"><a name="adg-pam_putenv-return_values"></a>2.1.7.2. RETURN VALUES</h4></div></div></div><div class="variablelist"><dl class="variablelist"><dt><span class="term">PAM_PERM_DENIED</span></dt><dd><p>
Argument <span class="emphasis"><em>name_value</em></span> given is a NULL pointer.
</p></dd><dt><span class="term">PAM_BAD_ITEM</span></dt><dd><p>
Variable requested (for deletion) is not currently set.
</p></dd><dt><span class="term">PAM_ABORT</span></dt><dd><p>
The <span class="emphasis"><em>pamh</em></span> handle is corrupt.
</p></dd><dt><span class="term">PAM_BUF_ERR</span></dt><dd><p>
Memory buffer error.
</p></dd><dt><span class="term">PAM_SUCCESS</span></dt><dd><p>
The environment variable was successfully updated.
</p></dd></dl></div></div></div><div class="section"><div class="titlepage"><div><div><h3 class="title"><a name="adg-pam_getenv"></a>2.1.8. Get a PAM environment variable</h3></div></div></div><div class="funcsynopsis"><pre class="funcsynopsisinfo">#include <security/pam_appl.h></pre><table border="0" class="funcprototype-table" summary="Function synopsis" style="cellspacing: 0; cellpadding: 0;"><tr><td><code class="funcdef">const char *<b class="fsfunc">pam_getenv</b>(</code></td><td><var class="pdparam">pamh</var>, </td><td> </td></tr><tr><td> </td><td><var class="pdparam">name</var><code>)</code>;</td><td> </td></tr></table><div class="paramdef-list"><code>pam_handle_t *<var class="pdparam">pamh</var></code>;<br><code>const char *<var class="pdparam">name</var></code>;</div><div class="funcprototype-spacer"> </div></div><div class="section"><div class="titlepage"><div><div><h4 class="title"><a name="adg-pam_getenv-description"></a>2.1.8.1. DESCRIPTION</h4></div></div></div><p>
The <code class="function">pam_getenv</code> function searches the
PAM environment list as associated with the handle
<span class="emphasis"><em>pamh</em></span> for an item that matches the string
pointed to by <span class="emphasis"><em>name</em></span> and returns a pointer
to the value of the environment variable. The application is
not allowed to free the data.
</p></div><div class="section"><div class="titlepage"><div><div><h4 class="title"><a name="adg-pam_getenv-return_values"></a>2.1.8.2. RETURN VALUES</h4></div></div></div><p>
The <code class="function">pam_getenv</code> function returns NULL
on failure.
</p></div></div><div class="section"><div class="titlepage"><div><div><h3 class="title"><a name="adg-pam_getenvlist"></a>2.1.9. Getting the PAM environment</h3></div></div></div><div class="funcsynopsis"><pre class="funcsynopsisinfo">#include <security/pam_appl.h></pre><table border="0" class="funcprototype-table" summary="Function synopsis" style="cellspacing: 0; cellpadding: 0;"><tr><td><code class="funcdef">char **<b class="fsfunc">pam_getenvlist</b>(</code></td><td><var class="pdparam">pamh</var><code>)</code>;</td><td> </td></tr></table><div class="paramdef-list"><code>pam_handle_t *<var class="pdparam">pamh</var></code>;</div><div class="funcprototype-spacer"> </div></div><div class="section"><div class="titlepage"><div><div><h4 class="title"><a name="adg-pam_getenvlist-description"></a>2.1.9.1. DESCRIPTION</h4></div></div></div><p>
The <code class="function">pam_getenvlist</code> function returns a complete
copy of the PAM environment as associated with the handle
<span class="emphasis"><em>pamh</em></span>. The PAM environment variables
represent the contents of the regular environment variables of the
authenticated user when service is granted.
</p><p>
The format of the memory is a malloc()'d array of char pointers,
the last element of which is set to NULL. Each of the non-NULL
entries in this array point to a NUL terminated and malloc()'d
char string of the form: "<span class="emphasis"><em>name=value</em></span>".
</p><p>
It should be noted that this memory will never be free()'d by
libpam. Once obtained by a call to
<code class="function">pam_getenvlist</code>, it is the responsibility of
the calling application to free() this memory.
</p><p>
It is by design, and not a coincidence, that the format and contents
of the returned array matches that required for the third argument of
the
<span class="citerefentry"><span class="refentrytitle">execle</span>(3)</span> function call.
</p></div><div class="section"><div class="titlepage"><div><div><h4 class="title"><a name="adg-pam_getenvlist-return_values"></a>2.1.9.2. RETURN VALUES</h4></div></div></div><p>
The <code class="function">pam_getenvlist</code> function returns NULL
on failure.
</p></div></div></div><div class="navfooter"><hr><table width="100%" summary="Navigation footer"><tr><td width="40%" align="left"><a accesskey="p" href="mwg-expected-by-module.html">Prev</a> </td><td width="20%" align="center"><a accesskey="u" href="mwg-expected-by-module.html">Up</a></td><td width="40%" align="right"> <a accesskey="n" href="mwg-expected-by-module-other.html">Next</a></td></tr><tr><td width="40%" align="left" valign="top">Chapter 2. What can be expected by the module </td><td width="20%" align="center"><a accesskey="h" href="Linux-PAM_MWG.html">Home</a></td><td width="40%" align="right" valign="top"> 2.2.
Other functions provided by <code class="filename">libpam</code>
</td></tr></table></div></body></html>
|