rfc86.0.txt 66 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845
  1. Open Software Foundation V. Samar (SunSoft)
  2. Request For Comments: 86.0 R. Schemers (SunSoft)
  3. October 1995
  4. UNIFIED LOGIN WITH
  5. PLUGGABLE AUTHENTICATION MODULES (PAM)
  6. 1. INTRODUCTION
  7. Since low-level authentication mechanisms constantly evolve, it is
  8. important to shield the high-level consumers of these mechanisms
  9. (system-entry services and users) from such low-level changes. With
  10. the Pluggable Authentication Module (PAM) framework, we can provide
  11. pluggability for a variety of system-entry services -- not just
  12. system authentication _per se_, but also for account, session and
  13. password management. PAM's ability to _stack_ authentication modules
  14. can be used to integrate `login' with different authentication
  15. mechanisms such as RSA, DCE, and Kerberos, and thus unify login
  16. mechanisms. The PAM framework can also provide easy integration of
  17. smart cards into the system.
  18. Modular design and pluggability have become important for users who
  19. want ease of use. In the PC hardware arena, no one wants to set the
  20. interrupt vector numbers or resolve the addressing conflict between
  21. various devices. In the software arena, people also want to be able
  22. to replace components easily for easy customization, maintenance, and
  23. upgrades.
  24. Authentication software deserves special attention because
  25. authentication forms a very critical component of any secure computer
  26. system. The authentication infrastructure and its components may
  27. have to be modified or replaced either because some deficiencies have
  28. been found in the current algorithms, or because sites want to
  29. enforce a different security policy than what was provided by the
  30. system vendor. The replacement and modification should be done in
  31. such a way that the user is not affected by these changes.
  32. The solution has to address not just how the applications use the new
  33. authentication mechanisms in a generic fashion, but also how the user
  34. will be authenticated to these mechanisms in a generic way. The
  35. former is addressed by GSS-API [Linn 93], while this RFC addresses
  36. the later; these two efforts are complementary to each other.
  37. Since most system-entry services (for example, `login', `dtlogin',
  38. `rlogin', `ftp', `rsh') may want to be independent of the specific
  39. authentication mechanisms used by the machine, it is important that
  40. there be a framework for _plugging_ in various mechanisms. This
  41. requires that the system applications use a standard API to interact
  42. Samar, Schemers Page 1
  43. OSF-RFC 86.0 PAM October 1995
  44. with the authentication services. If these system-entry services
  45. remain independent of the actual mechanism used on that machine, the
  46. system administrator can install suitable authentication modules
  47. without requiring changes to these applications.
  48. For any security system to be successful, it has to be easy to use.
  49. In the case of authentication, the single most important ease-of-use
  50. characteristic is that the user should not be required to learn about
  51. various ways of authentication and remember multiple passwords.
  52. Ideally, there should be one all-encompassing authentication system
  53. where there is only one password, but for heterogeneous sites,
  54. multiple authentication mechanisms have to co-exist. The problem of
  55. integrating multiple authentication mechanisms such as Kerberos
  56. [Steiner 88], RSA [Rivest 78], and Diffie-Hellman [Diffie 76, Taylor
  57. 88], is also referred to as _integrated login_, or _unified login_
  58. problem. Even if the user has to use multiple authentication
  59. mechanisms, the user should not be forced to type multiple passwords.
  60. Furthermore, the user should be able to use the new network identity
  61. without taking any further actions. The key here is in modular
  62. integration of the network authentication technologies with `login'
  63. and other system-entry services.
  64. In this RFC we discuss the architecture and design of pluggable
  65. authentication modules. This design gives the capability to use
  66. field-replaceable authentication modules along with unified login
  67. capability. It thus provides for both _pluggability_ and _ease-of-
  68. use_.
  69. The RFC is organized as follows. We first motivate the need for a
  70. generic way to authenticate the user by various system-entry services
  71. within the operating system. We describe the goals and constraints
  72. of the design. This leads to the architecture, description of the
  73. interfaces, and _stacking_ of modules to get unified login
  74. functionality. We then describe our experience with the design, and
  75. end with a description of future work.
  76. 2. OVERVIEW OF IDENTIFICATION AND AUTHENTICATION MECHANISMS
  77. An identification and authentication ("I&A") mechanism is used to
  78. establish a user's identity the system (i.e., to a local machine's
  79. operating system) and to other principals on the network. On a
  80. typical UNIX system, there are various ports of entry into the
  81. system, such as `login', `dtlogin', `rlogin', `ftp', `rsh', `su', and
  82. `telnet'. In all cases, the user has to be identified and
  83. authenticated before granting appropriate access rights to the user.
  84. The user identification and authentication for all these entry points
  85. needs to be coordinated to ensure a secure system.
  86. In most of the current UNIX systems, the login mechanism is based
  87. upon verification of the password using the modified DES algorithm.
  88. Samar, Schemers Page 2
  89. OSF-RFC 86.0 PAM October 1995
  90. The security of the implementation assumes that the password cannot
  91. be guessed, and that the password does not go over the wire in the
  92. clear. These assumptions, however, are not universally valid.
  93. Various programs are now available freely on the Internet that can
  94. run dictionary attack against the encrypted password. Further, some
  95. of the network services (for example, `rlogin', `ftp', `telnet') send
  96. the password over in clear, and there are "sniffer" programs freely
  97. available to steal these passwords. The classical assumptions may be
  98. acceptable on a trusted network, but in an open environment there is
  99. a need to use more restrictive and stronger authentication
  100. mechanisms. Examples of such mechanisms include Kerberos, RSA,
  101. Diffie-Hellman, one-time password [Skey 94], and challenge-response
  102. based smart card authentication systems. Since this list will
  103. continue to evolve, it is important that the system-entry services do
  104. not have hard-coded dependencies on any of these authentication
  105. mechanisms.
  106. 3. DESIGN GOALS
  107. The goals of the PAM framework are as follows:
  108. (a) The system administrator should be able to choose the default
  109. authentication mechanism for the machine. This can range from
  110. a simple password-based mechanism to a biometric or a smart
  111. card based system.
  112. (b) It should be possible to configure the user authentication
  113. mechanism on a per application basis. For example, a site may
  114. require S/Key password authentication for `telnet' access,
  115. while allowing machine `login' sessions with just UNIX password
  116. authentication.
  117. (c) The framework should support the display requirements of the
  118. applications. For example, for a graphical login session such
  119. as `dtlogin', the user name and the password may have to be
  120. entered in a new window. For networking system-entry
  121. applications such as `ftp' and `telnet', the user name and
  122. password has to be transmitted over the network to the client
  123. machine.
  124. (d) It should be possible to configure multiple authentication
  125. protocols for each of those applications. For example, one may
  126. want the users to get authenticated by both Kerberos and RSA
  127. authentication systems.
  128. (e) The system administrator should be able to _stack_ multiple
  129. user authentication mechanisms such that the user is
  130. authenticated with all authentication protocols without
  131. retyping the password.
  132. Samar, Schemers Page 3
  133. OSF-RFC 86.0 PAM October 1995
  134. (f) The architecture should allow for multiple passwords if
  135. necessary to achieve higher security for users with specific
  136. security requirements.
  137. (g) The system-entry services should not be required to change when
  138. the underlying mechanism changes. This can be very useful for
  139. third-party developers because they often do not have the
  140. source code for these services.
  141. (h) The architecture should provide for a _pluggable_ model for
  142. system authentication, as well as for other related tasks such
  143. as password, account, and session management.
  144. (i) For backward-compatibility reasons, the PAM API should support
  145. the authentication requirements of the current system-entry
  146. services.
  147. There are certain issues that the PAM framework does not specifically
  148. address:
  149. (a) We focus only on providing a generic scheme through which users
  150. use passwords to establish their identities to the machine.
  151. Once the identity is established, how the identity is
  152. communicated to other interested parties is outside the scope
  153. of this design. There are efforts underway at IETF [Linn 93]
  154. to develop a Generic Security Services Application Interface
  155. (GSSAPI) that can be used by applications for secure and
  156. authenticated communication without knowing the underlying
  157. mechanism.
  158. (b) The _single-signon_ problem of securely transferring the
  159. identity of the caller to a remote site is not addressed. For
  160. example, the problem of delegating credentials from the
  161. `rlogin' client to the other machine without typing the
  162. password is not addressed by our work. We also do not address
  163. the problem of sending the passwords over the network in the
  164. clear.
  165. (c) We do not address the source of information obtained from the
  166. "`getXbyY()'" family of calls (e.g., `getpwnam()'). Different
  167. operating systems address this problem differently. For
  168. example, Solaris uses the name service switch (NSS) to
  169. determine the source of information for the "`getXbyY()'"
  170. calls. It is expected that data which is stored in multiple
  171. sources (such as passwd entries in NIS+ and the DCE registry)
  172. is kept in sync using the appropriate commands (such as
  173. `passwd_export').
  174. Samar, Schemers Page 4
  175. OSF-RFC 86.0 PAM October 1995
  176. 4. OVERVIEW OF THE PAM FRAMEWORK
  177. We propose that the goals listed above can be met through a framework
  178. in which authentication modules can be _plugged_ independently of the
  179. application. We call this the _Pluggable Authentication Modules_
  180. (PAM) framework.
  181. The core components of the PAM framework are the authentication
  182. library API (the front end) and the authentication mechanism-specific
  183. modules (the back end), connected through the Service Provider
  184. Interface (SPI). Applications write to the PAM API, while the
  185. authentication-system providers write to the PAM SPI and supply the
  186. back end modules that are independent of the application.
  187. ftp telnet login (Applications)
  188. | | |
  189. | | |
  190. +--------+--------+
  191. |
  192. +-----+-----+
  193. | PAM API | <-- pam.conf file
  194. +-----+-----+
  195. |
  196. +--------+--------+
  197. UNIX Kerberos Smart Cards (Mechanisms)
  198. Figure 1: The Basic PAM Architecture
  199. Figure 1 illustrates the relationship between the application, the
  200. PAM library, and the authentication modules. Three applications
  201. (`login', `telnet' and `ftp') are shown which use the PAM
  202. authentication interfaces. When an application makes a call to the
  203. PAM API, it loads the appropriate authentication module as determined
  204. by the configuration file, `pam.conf'. The request is forwarded to
  205. the underlying authentication module (for example, UNIX password,
  206. Kerberos, smart cards) to perform the specified operation. The PAM
  207. layer then returns the response from the authentication module to the
  208. application.
  209. PAM unifies system authentication and access control for the system,
  210. and allows plugging of associated authentication modules through well
  211. defined interfaces. The plugging can be defined through various
  212. means, one of which uses a configuration file, such as the one in
  213. Table 1. For each of the system applications, the file specifies the
  214. authentication module that should be loaded. In the example below,
  215. `login' uses the UNIX password module, while `ftp' and `telnet' use
  216. the S/Key module.
  217. Samar, Schemers Page 5
  218. OSF-RFC 86.0 PAM October 1995
  219. Table 1: A Simplified View of a Sample PAM Configuration File.
  220. service module_path
  221. ------- -----------
  222. login pam_unix.so
  223. ftp pam_skey.so
  224. telnet pam_skey.so
  225. Authentication configuration is only one aspect of this interface.
  226. Other critical components include account management, session
  227. management, and password management. For example, the `login'
  228. program may want to verify not only the password but also whether the
  229. account has aged or expired. Generic interfaces also need to be
  230. provided so that the password can be changed according to the
  231. requirements of the module. Furthermore, the application may want to
  232. log information about the current session as determined by the
  233. module.
  234. Not all applications or services may need all of the above
  235. components, and not each authentication module may need to provide
  236. support for all of the interfaces. For example, while `login' may
  237. need access to all four components, `su' may need access to just the
  238. authentication component. Some applications may use some specific
  239. authentication and password management modules but share the account
  240. and session management modules with others.
  241. This reasoning leads to a partitioning of the entire set of
  242. interfaces into four areas of functionality: (1) authentication, (2)
  243. account, (3) session, and (4) password. The concept of PAM was
  244. extended to these functional areas by implementing each of them as a
  245. separate pluggable module.
  246. Breaking the functionality into four modules helps the module
  247. providers because they can use the system-provided libraries for the
  248. modules that they are not changing. For example, if a supplier wants
  249. to provide a better version of Kerberos, they can just provide that
  250. new authentication and password module, and reuse the existing ones
  251. for account and session.
  252. 4.1. Module Description
  253. More details on specific API's are described in Appendix A. A brief
  254. description of four modules follows:
  255. (a) Authentication management: This set includes the
  256. `pam_authenticate()' function to authenticate the user, and the
  257. `pam_setcred()' interface to set, refresh or destroy the user
  258. credentials.
  259. (b) Account management: This set includes the `pam_acct_mgmt()'
  260. function to check whether the authenticated user should be
  261. Samar, Schemers Page 6
  262. OSF-RFC 86.0 PAM October 1995
  263. given access to his/her account. This function can implement
  264. account expiration and access hour restrictions.
  265. (c) Session management: This set includes the `pam_open_session()'
  266. and `pam_close_session()' functions for session management and
  267. accounting. For example, the system may want to store the
  268. total time for the session.
  269. (d) Password management: This set includes a function,
  270. `pam_chauthtok()', to change the password.
  271. 5. FRAMEWORK INTERFACES
  272. The PAM framework further provides a set of administrative interfaces
  273. to support the above modules and to provide for application-module
  274. communication. There is no corresponding service provider interface
  275. (SPI) for such functions.
  276. 5.1. Administrative Interfaces
  277. Each set of PAM transactions starts with `pam_start()' and ends with
  278. the `pam_end()' function. The interfaces `pam_get_item()' and
  279. `pam_set_item()' are used to read and write the state information
  280. associated with the PAM transaction.
  281. If there is any error with any of the PAM interfaces, the error
  282. message can be printed with `pam_strerror()'.
  283. 5.2. Application-Module Communication
  284. During application initialization, certain data such as the user name
  285. is saved in the PAM framework layer through `pam_start()' so that it
  286. can be used by the underlying modules. The application can also pass
  287. opaque data to the module which the modules will pass back while
  288. communicating with the user.
  289. 5.3. User-Module Communication
  290. The `pam_start()' function also passes conversation function that has
  291. to be used by the underlying modules to read and write module
  292. specific authentication information. For example, these functions
  293. can be used to prompt the user for the password in a way determined
  294. by the application. PAM can thus be used by graphical, non-
  295. graphical, or networked applications.
  296. Samar, Schemers Page 7
  297. OSF-RFC 86.0 PAM October 1995
  298. 5.4. Inter-Module Communication
  299. Though the modules are independent, they can share certain common
  300. information about the authentication session such as user name,
  301. service name, password, and conversation function through the
  302. `pam_get_item()' and `pam_set_item()' interfaces. These API's can
  303. also be used by the application to change the state information after
  304. having called `pam_start()' once.
  305. 5.5. Module State Information
  306. The PAM service modules may want to keep certain module-specific
  307. state information about the session. The interfaces `pam_get_data()'
  308. and `pam_set_data()' can be used by the service modules to access and
  309. update module-specific information as needed from the PAM handle.
  310. The modules can also attach a cleanup function with the data. The
  311. cleanup function is executed when `pam_end()' is called to indicate
  312. the end of the current authentication activity.
  313. Since the PAM modules are loaded upon demand, there is no direct
  314. module initialization support in the PAM framework. If there are
  315. certain initialization tasks that the PAM service modules have to do,
  316. they should be done upon the first invocation. However, if there are
  317. certain clean-up tasks to be done when the authentication session
  318. ends, the modules should use `pam_set_data()' to specify the clean-up
  319. functions, which would be called when `pam_end()' is called by the
  320. application.
  321. 6. MODULE CONFIGURATION MANAGEMENT
  322. Table 2 shows an example of a configuration file `pam.conf' with
  323. support for authentication, session, account, and password management
  324. modules. `login' has three entries: one each for authentication
  325. processing, session management and account management. Each entry
  326. specifies the module name that should be loaded for the given module
  327. type. In this example, the `ftp' service uses the authentication and
  328. session modules. Note that all services here share the same session
  329. management module, while having different authentication modules.
  330. Samar, Schemers Page 8
  331. OSF-RFC 86.0 PAM October 1995
  332. Table 2: Configuration File (pam.conf) with Different Modules
  333. and Control Flow
  334. service module_type control_flag module_path options
  335. ------- ----------- ------------ ----------- -------
  336. login auth required pam_unix_auth.so nowarn
  337. login session required pam_unix_session.so
  338. login account required pam_unix_account.so
  339. ftp auth required pam_skey_auth.so debug
  340. ftp session required pam_unix_session.so
  341. telnet session required pam_unix_session.so
  342. login password required pam_unix_passwd.so
  343. passwd password required pam_unix_passwd.so
  344. OTHER auth required pam_unix_auth.so
  345. OTHER session required pam_unix_session.so
  346. OTHER account required pam_unix_account.so
  347. The first field, _service_, denotes the service (for example,
  348. `login', `passwd', `rlogin'). The name `OTHER' indicates the module
  349. used by all other applications that have not been specified in this
  350. file. This name can also be used if all services have the same
  351. requirements. In the example, since all the services use the same
  352. session module, we could have replaced those lines with a single
  353. `OTHER' line.
  354. The second field, _module_type_, indicates the type of the PAM
  355. functional module. It can be one of `auth', `account', `session', or
  356. `password' modules.
  357. The third field, _control_flag_ determines the behavior of stacking
  358. multiple modules by specifying whether any particular module is
  359. _required_, _sufficient_, or _optional_. The next section describes
  360. stacking in more detail.
  361. The fourth field, _module_path_, specifies the location of the
  362. module. The PAM framework loads this module upon demand to invoke
  363. the required function.
  364. The fifth field, _options_, is used by the PAM framework layer to
  365. pass module specific options to the modules. It is up to the module
  366. to parse and interpret the options. This field can be used by the
  367. modules to turn on debugging or to pass any module specific
  368. parameters such as a timeout value. It is also used to support
  369. unified login as described below. The options field can be used by
  370. the system administrator to fine-tune the PAM modules.
  371. If any of the fields are invalid, or if a module is not found, that
  372. line is ignored and the error is logged as a critical error via
  373. `syslog(3)'. If no entries are found for the given module type, then
  374. the PAM framework returns an error to the application.
  375. Samar, Schemers Page 9
  376. OSF-RFC 86.0 PAM October 1995
  377. 7. INTEGRATING MULTIPLE AUTHENTICATION SERVICES WITH STACKING
  378. In the world of heterogeneous systems, the system administrator often
  379. has to deal with the problem of integrating multiple authentication
  380. mechanisms. The user is often required to know about the
  381. authentication command of the new authentication module (for example,
  382. `kinit', `dce_login') after logging into the system. This is not
  383. user-friendly because it forces people to remember to type the new
  384. command and enter the new password. This functionality should be
  385. invisible instead of burdening the user with it.
  386. There are two problems to be addressed here:
  387. (a) Supporting multiple authentication mechanisms.
  388. (b) Providing unified login in the presence of multiple mechanisms.
  389. In the previous section, we described how one could replace the
  390. default authentication module with any other module of choice. Now
  391. we demonstrate how the same model can be extended to provide support
  392. for multiple modules.
  393. 7.1. Design for Stacked Modules
  394. One possibility was to provide hard-coded rules in `login' or other
  395. applications requiring authentication services [Adamson 95]. But
  396. this becomes very specific to the particular combination of
  397. authentication protocols, and also requires the source code of the
  398. application. Digital's Security Integration Architecture [SIA 95]
  399. addresses this problem by specifying the same list of authentication
  400. modules for all applications. Since requirements for various
  401. applications can vary, it is essential that the configuration be on a
  402. per-application basis.
  403. To support multiple authentication mechanisms, the PAM framework was
  404. extended to support _stacking_. When any API is called, the back
  405. ends for the stacked modules are invoked in the order listed, and the
  406. result returned to the caller. In Figure 2, the authentication
  407. service of `login' is stacked and the user is authenticated by UNIX,
  408. Kerberos, and RSA authentication mechanisms. Note that in this
  409. example, there is no stacking for session or account management
  410. modules.
  411. Samar, Schemers Page 10
  412. OSF-RFC 86.0 PAM October 1995
  413. login
  414. |
  415. +--------+--------+
  416. | | |
  417. session auth account
  418. | | |
  419. +--+--+ +--+--+ +--+--+
  420. | PAM | | PAM | | PAM |
  421. +--+--+ +--+--+ +--+--+
  422. | | |
  423. UNIX UNIX UNIX
  424. session auth account
  425. |
  426. Kerberos
  427. auth
  428. |
  429. RSA
  430. auth
  431. Figure 2: Stacking With the PAM Architecture
  432. Stacking is specified through additional entries in the configuration
  433. file shown earlier. As shown in Table 2, for each application (such
  434. as `login') the configuration file can specify multiple mechanisms
  435. that have to be invoked in the specified order. When mechanisms
  436. fail, the _control_flag_ decides which error should be returned to
  437. the application. Since the user should not know which authentication
  438. module failed when a bad password was typed, the PAM framework
  439. continues to call other authentication modules on the stack even on
  440. failure. The semantics of the control flag are as follows:
  441. (a) `required': With this flag, the module failure results in the
  442. PAM framework returning the error to the caller _after_
  443. executing all other modules on the stack. For the function to
  444. be able to return success to the application all `required'
  445. modules have to report success. This flag is normally set when
  446. authentication by this module is a _must_.
  447. (b) `optional': With this flag, the PAM framework ignores the
  448. module failure and continues with the processing of the next
  449. module in sequence. This flag is used when the user is allowed
  450. to login even if that particular module has failed.
  451. (c) `sufficient': With this flag, if the module succeeds the PAM
  452. framework returns success to the application immediately
  453. without trying any other modules. For failure cases, the
  454. _sufficient_ modules are treated as `optional'.
  455. Table 3 shows a sample configuration file that stacks the `login'
  456. command. Here the user is authenticated by UNIX, Kerberos, and RSA
  457. authentication services. The `required' key word for _control_flag_
  458. Samar, Schemers Page 11
  459. OSF-RFC 86.0 PAM October 1995
  460. enforces that the user is allowed to login only if he/she is
  461. authenticated by _both_ UNIX and Kerberos services. RSA
  462. authentication is optional by virtue of the `optional' key word in
  463. the _control_flag_ field. The user can still log in even if RSA
  464. authentication fails.
  465. Table 3: PAM Configuration File with Support for Stacking
  466. service module_type control_flag module_path options
  467. ------- ----------- ------------ ----------- -------
  468. login auth required pam_unix.so debug
  469. login auth required pam_kerb.so use_mapped_pass
  470. login auth optional pam_rsa.so use_first_pass
  471. Table 4 illustrates the use of the sufficient flag for the `rlogin'
  472. service. The Berkeley `rlogin' protocol specifies that if the remote
  473. host is trusted (as specified in the `/etc/hosts.equiv' file or in
  474. the `.rhosts' file in the home directory of the user), then the
  475. `rlogin' daemon should not require the user to type the password. If
  476. this is not the case, then the user is required to type the password.
  477. Instead of hard coding this policy in the `rlogin' daemon, this can
  478. be expressed with the `pam.conf' file in Table 4. The PAM module
  479. `pam_rhosts_auth.so.1' implements the `.rhosts' policy described
  480. above. If a site administrator wants to enable remote login with
  481. only passwords, then the first line should be deleted.
  482. Table 4: PAM Configuration File for the rlogin service
  483. service module_type control_flag module_path options
  484. ------- ----------- ------------ ----------- -------
  485. rlogin auth sufficient pam_rhosts_auth.so
  486. rlogin auth required pam_unix.so
  487. 7.2. Password-Mapping
  488. Multiple authentication mechanisms on a machine can lead to multiple
  489. passwords that users have to remember. One attractive solution from
  490. the ease-of-use viewpoint is to use the same password for all
  491. mechanisms. This, however, can also weaken the security because if
  492. that password were to be compromised in any of the multiple
  493. mechanisms, all mechanisms would be compromised at the same time.
  494. Furthermore, different authentication mechanisms may have their own
  495. distinctive password requirements in regards to its length, allowed
  496. characters, time interval between updates, aging, locking, and so
  497. forth. These requirements make it problematic to use the same
  498. password for multiple authentication mechanisms.
  499. The solution we propose, while not precluding use of the same
  500. password for every mechanism, allows for a different password for
  501. each mechanism through what we call _password-mapping_. This
  502. basically means using the user's _primary_ password to encrypt the
  503. Samar, Schemers Page 12
  504. OSF-RFC 86.0 PAM October 1995
  505. user's other (_secondary_) passwords, and storing these encrypted
  506. passwords in a place where they are available to the user. Once the
  507. primary password is verified, the authentication modules would obtain
  508. the other passwords for their own mechanisms by decrypting the
  509. mechanism-specific encrypted password with the primary password, and
  510. passing it to the authentication service. The security of this
  511. design for password-mapping assumes that the primary password is the
  512. user's strongest password, in terms of its unguessability (length,
  513. type and mix of characters used, etc.).
  514. If there is any error in password-mapping, or if the mapping does not
  515. exist, the user will be prompted for the password by each
  516. authentication module.
  517. To support password-mapping, the PAM framework saves the primary
  518. password and provides it to stacked authentication modules. The
  519. password is cleared out before the `pam_authenticate' function
  520. returns.
  521. How the password is encrypted depends completely on the module
  522. implementation. The encrypted secondary password (also called a
  523. "mapped password") can be stored in a trusted or untrusted place,
  524. such as a smart card, a local file, or a directory service. If the
  525. encrypted passwords are stored in an untrusted publicly accessible
  526. place, this does provide an intruder with opportunities for potential
  527. dictionary attack.
  528. Though password-mapping is voluntary, it is recommended that all
  529. module providers add support for the following four mapping options:
  530. (a) `use_first_pass': Use the same password used by the first
  531. mechanism that asked for a password. The module should not ask
  532. for the password if the user cannot be authenticated by the
  533. first password. This option is normally used when the system
  534. administrator wants to enforce the same password across
  535. multiple modules.
  536. (b) `try_first_pass': This is the same as `use_first_pass', except
  537. that if the primary password is not valid, it should prompt the
  538. user for the password.
  539. (c) `use_mapped_pass': Use the password-mapping scheme to get the
  540. actual password for this module. One possible implementation
  541. is to get the mapped-password using the XFN API [XFN 94], and
  542. decrypt it with the primary password to get the module-specific
  543. password. The module should not ask for the password if the
  544. user cannot be authenticated by the first password. The XFN
  545. API allows user-defined attributes (such as _mapped-password_)
  546. to be stored in the _user-context_. Using the XFN API is
  547. particularly attractive because support for the XFN may be
  548. found on many systems in the future.
  549. Samar, Schemers Page 13
  550. OSF-RFC 86.0 PAM October 1995
  551. (d) `try_mapped_pass': This is the same as `use_mapped_pass',
  552. except that if the primary password is not valid, it should
  553. prompt the user for the password.
  554. When passwords get updated, the PAM framework stores both the old as
  555. well as the new password to be able to inform other dependent
  556. authentication modules about the change. Other modules can use this
  557. information to update the encrypted password without forcing the user
  558. to type the sequence of passwords again. The PAM framework clears
  559. out the passwords before returning to the application.
  560. Table 3 illustrates how the same password can be used by `login' for
  561. authenticating to the standard UNIX login, Kerberos and RSA services.
  562. Once the user has been authenticated to the primary authentication
  563. service (UNIX `login' in this example) with the primary password, the
  564. option `use_mapped_pass' indicates to the Kerberos module that it
  565. should use the primary password to decrypt the stored Kerberos
  566. password and then use the Kerberos password to get the ticket for the
  567. ticket-granting-service. After that succeeds, the option
  568. `use_first_pass' indicates to the RSA module that instead of
  569. prompting the user for a password, it should use the primary password
  570. typed earlier for authenticating the user. Note that in this
  571. scenario, the user has to enter the password just once.
  572. Note that if a one-time password scheme (e.g., S/Key) is used,
  573. password mapping cannot apply.
  574. 7.3. Implications of Stacking on the PAM Design
  575. Because of the stacking capability of PAM, we have designed the PAM
  576. API's to not return any data to the application, except status. If
  577. this were not the case, it would be difficult for the PAM framework
  578. to decide which module should return data to the application. When
  579. there is any error, the application does not know which of the
  580. modules failed. This behavior enables (even requires) the
  581. application to be completely independent from the modules.
  582. Another design decision we have made is that PAM gives only the user
  583. name to all the underlying PAM modules, hence it is the
  584. responsibility of the PAM modules to convert the name to their own
  585. internal format. For example, the Kerberos module may have to
  586. convert the UNIX user name to a Kerberos principal name.
  587. Stacking also forces the modules to be designed such that they can
  588. occur anywhere in the stack without any side-effects.
  589. Since modules such as the authentication and the password module are
  590. very closely related, it is important they be configured in the same
  591. order and with compatible options.
  592. Samar, Schemers Page 14
  593. OSF-RFC 86.0 PAM October 1995
  594. 8. INTEGRATION WITH SMART CARDS
  595. Many networking authentication protocols require possession of a long
  596. key to establish the user identity. For ease-of-use reasons, that
  597. long key is normally encrypted with the user's password so that the
  598. user is not required to memorize it. However, weak passwords can be
  599. compromised through a dictionary attack and thus undermine the
  600. stronger network authentication mechanism. Furthermore, the
  601. encrypted data is normally stored in a centrally accessible service
  602. whose availability depends upon the reliability of the associated
  603. service. Solutions have been proposed to use a pass-phrase or one-
  604. time-password, but those are much longer than the regular eight
  605. character passwords traditionally used with UNIX `login'. This makes
  606. the solution user-unfriendly because it requires longer strings to be
  607. remembered and typed.
  608. For most authentication protocol implementations, the trust boundary
  609. is the local machine. This assumption may not be valid in cases
  610. where the user is mobile and has to use publicly available networked
  611. computers. In such cases, it is required that the clear text of the
  612. key or the password never be made available to the machine.
  613. Smart cards solve the above problems by reducing password exposure by
  614. supporting a _two factor_ authentication mechanism: the first with
  615. the possession of the card, and the second with the knowledge of the
  616. PIN associated with the card. Not only can the smart cards be a
  617. secure repository of multiple passwords, they can also provide the
  618. encryption and authentication functions such that the long (private)
  619. key is never exposed outside the card.
  620. The PAM framework allows for integrating smart cards to the system by
  621. providing a smart card specific module for authentication.
  622. Furthermore, the unified login problem is simplified because the
  623. multiple passwords for various authentication mechanisms can be
  624. stored on the smart card itself. This can be enabled by adding a
  625. suitable key-word such as `use_smart_card' in the _options_ field.
  626. 9. SECURITY ISSUES
  627. It is important to understand the impact of PAM on the security of
  628. any system so that the site-administrator can make an informed
  629. decision.
  630. (a) Sharing of passwords with multiple authentication mechanisms.
  631. If there are multiple authentication modules, one possibility
  632. is to use the same password for all of them. If the password
  633. for any of the multiple authentication system is compromised,
  634. the user's password in all systems would be compromised. If
  635. this is a concern, then multiple passwords might be considered
  636. Samar, Schemers Page 15
  637. OSF-RFC 86.0 PAM October 1995
  638. at the cost of ease-of-use.
  639. (b) Password-mapping.
  640. This technique of encrypting all other passwords with the
  641. primary password assumes that it is lot more difficult to crack
  642. the primary password and that reasonable steps have been taken
  643. to ensure limited availability of the encrypted primary
  644. password. If this is not done, an intruder could target the
  645. primary password as the first point of dictionary attack. If
  646. one of the other modules provide stronger security than the
  647. password based security, the site would be negating the strong
  648. security by using password-mapping. If this is a concern, then
  649. multiple passwords might be considered at the cost of ease-of-
  650. use. If smart cards are used, they obviate the need for
  651. password-mapping completely.
  652. (c) Security of the configuration file.
  653. Since the policy file dictates how the user is authenticated,
  654. this file should be protected from unauthorized modifications.
  655. (d) Stacking various PAM modules.
  656. The system administrator should fully understand the
  657. implications of stacking various modules that will be installed
  658. on the system and their respective orders and interactions.
  659. The composition of various authentication modules should be
  660. carefully examined. The trusted computing base of the machine
  661. now includes the PAM modules.
  662. 10. EXPERIENCE WITH PAM
  663. The PAM framework was first added in Solaris 2.3 release as a private
  664. internal interface. PAM is currently being used by several system
  665. entry applications such as `login', `passwd', `su', `dtlogin',
  666. `rlogind', `rshd', `telnetd', `ftpd', `in.rexecd', `uucpd', `init',
  667. `sac', and `ttymon'. We have found that PAM provides an excellent
  668. framework to encapsulate the authentication-related tasks for the
  669. entire system. The Solaris 2.3 PAM API's were hence enhanced and
  670. simplified to support stacking.
  671. PAM modules have been developed for UNIX, DCE, Kerberos, S/Key,
  672. remote user authentication, and dialpass authentication. Other PAM
  673. modules are under development, and integration with smart cards is
  674. being planned.
  675. Some third parties have used the PAM interface to extend the security
  676. mechanisms offered by the Solaris environment.
  677. Samar, Schemers Page 16
  678. OSF-RFC 86.0 PAM October 1995
  679. The PAM API has been accepted by Common Desktop Environment (CDE)
  680. vendors as the API to be used for integrating the graphical interface
  681. for login, `dtlogin' with multiple authentication mechanisms.
  682. 11. FUTURE WORK
  683. Amongst the various components of PAM, the password component needs
  684. to be carefully examined to see whether the stacking semantics are
  685. particularly applicable, and how PAM should deal with partial
  686. failures when changing passwords.
  687. The _control_flag_ of the configuration file can be extended to
  688. include other semantics. For example, if the error is "name service
  689. not available", one may want to retry. It is also possible to offer
  690. semantics of "return success if any of the modules return success".
  691. In an earlier section, we had mentioned integration of smart cards
  692. with PAM. Though we feel that integration should be straight forward
  693. from the PAM architecture point of view, there may be some issues
  694. with implementation because the interfaces to the smart cards have
  695. not yet been standardized.
  696. One possible extension to PAM is to allow the passing of module-
  697. specific data between applications and PAM modules. For example, the
  698. `login' program likes to build its new environment from a select list
  699. of variables, yet the DCE module needs the `KRB5CCNAME' variable to
  700. be exported to the child process. For now we have modified the
  701. `login' program to explicitly export the `KRB5CCNAME' variable.
  702. Administrative tools are needed to help system administrators modify
  703. `pam.conf', and perform sanity checks on it (i.e., a `pam_check'
  704. utility).
  705. 12. CONCLUSION
  706. The PAM framework and the module interfaces provide pluggability for
  707. user authentication, as well as for account, session and password
  708. management. The PAM architecture can be used by `login' and by all
  709. other system-entry services, and thus ensure that all entry points
  710. for the system have been secured. This architecture enables
  711. replacement and modification of authentication modules in the field
  712. to secure the system against the newly found weaknesses without
  713. changing any of the system services.
  714. The PAM framework can be used to integrate `login' and `dtlogin' with
  715. different authentication mechanisms such as RSA and Kerberos.
  716. Multiple authentication systems can be accessed with the same
  717. password. The PAM framework also provides easy integration of smart
  718. cards into the system.
  719. Samar, Schemers Page 17
  720. OSF-RFC 86.0 PAM October 1995
  721. PAM provides complementary functionality to GSS-API, in that it
  722. provides mechanisms through which the user gets authenticated to any
  723. new system-level authentication service on the machine. GSS-API then
  724. uses the credentials for authenticated and secure communications with
  725. other application-level service entities on the network.
  726. 13. ACKNOWLEDGEMENTS
  727. PAM development has spanned several release cycles at SunSoft.
  728. Shau-Ping Lo, Chuck Hickey, and Alex Choy did the first design and
  729. implementation. Bill Shannon and Don Stephenson helped with the PAM
  730. architecture. Rocky Wu prototyped stacking of multiple modules.
  731. Paul Fronberg, Charlie Lai, and Roland Schemers made very significant
  732. enhancements to the PAM interfaces and took the project to completion
  733. within a very short time. Kathy Slattery wrote the PAM
  734. documentation. John Perry integrated PAM within the CDE framework.
  735. APPENDIX A. PAM API'S
  736. This appendix gives an informal description of the various interfaces
  737. of PAM. Since the goal here is just for the reader to get a working
  738. knowledge about the PAM interfaces, not all flags and options have
  739. been fully defined and explained. The API's described here are
  740. subject to change.
  741. The PAM Service Provider Interface is very similar to the PAM API,
  742. except for one extra parameter to pass module-specific options to the
  743. underlying modules.
  744. A.1. Framework Layer API's
  745. int
  746. pam_start(
  747. char *service_name,
  748. char *user,
  749. struct pam_conv *pam_conversation,
  750. pam_handle_t **pamh
  751. );
  752. `pam_start()' is called to initiate an authentication transaction.
  753. `pam_start()' takes as arguments the name of the service, the name of
  754. the user to be authenticated, the address of the conversation
  755. structure. `pamh' is later used as a handle for subsequent calls to
  756. the PAM library.
  757. The PAM modules do not communicate directly with the user; instead
  758. they rely on the application to perform all such interaction. The
  759. application needs to provide the conversation functions, `conv()',
  760. and associated application data pointers through a `pam_conv'
  761. Samar, Schemers Page 18
  762. OSF-RFC 86.0 PAM October 1995
  763. structure when it initiates an authentication transaction. The
  764. module uses the `conv()' function to prompt the user for data,
  765. display error messages, or text information.
  766. int
  767. pam_end(
  768. pam_handle_t *pamh,
  769. int pam_status
  770. );
  771. `pam_end()' is called to terminate the PAM transaction as specified
  772. by `pamh', and to free any storage area allocated by the PAM modules
  773. with `pam_set_item()'.
  774. int
  775. pam_set_item(
  776. pam_handle_t *pamh,
  777. int item_type,
  778. void *item
  779. );
  780. int
  781. pam_get_item(
  782. pam_handle_t *pamh,
  783. int item_type,
  784. void **item);
  785. `pam_get_item()' and `pam_set_item()' allow the parameters specified
  786. in the initial call to `pam_start()' to be read and updated. This is
  787. useful when a particular parameter is not available when
  788. `pam_start()' is called or must be modified after the initial call to
  789. `pam_start()'. `pam_set_item()' is passed a pointer to the object,
  790. `item', and its type, `item_type'. `pam_get_item()' is passed the
  791. address of the pointer, `item', which is assigned the address of the
  792. requested object.
  793. The `item_type' is one of the following:
  794. Table 5: Possible Values for Item_type
  795. Item Name Description
  796. --------- -----------
  797. PAM_SERVICE The service name
  798. PAM_USER The user name
  799. PAM_TTY The tty name
  800. PAM_RHOST The remote host name
  801. PAM_CONV The pam_conv structure
  802. PAM_AUTHTOK The authentication token (password)
  803. PAM_OLDAUTHTOK The old authentication token
  804. PAM_RUSER The remote user name
  805. Samar, Schemers Page 19
  806. OSF-RFC 86.0 PAM October 1995
  807. Note that the values of `PAM_AUTHTOK' and `PAM_OLDAUTHTOK' are only
  808. available to PAM modules and not to the applications. They are
  809. explicitly cleared out by the framework before returning to the
  810. application.
  811. char *
  812. pam_strerror(
  813. int errnum
  814. );
  815. `pam_strerror()' maps the error number to a PAM error message string,
  816. and returns a pointer to that string.
  817. int
  818. pam_set_data(
  819. pam_handle_t *pamh,
  820. char *module_data_name,
  821. char *data,
  822. (*cleanup)(pam_handle_t *pamh, char *data,
  823. int error_status)
  824. );
  825. The `pam_set_data()' function stores module specific data within the
  826. PAM handle. The `module_data_name' uniquely specifies the name to
  827. which some data and cleanup callback function can be attached. The
  828. cleanup function is called when `pam_end()' is invoked.
  829. int
  830. pam_get_data(
  831. pam_handle_t *pamh,
  832. char *module_data_name,
  833. void **datap
  834. );
  835. The `pam_get_data()' function obtains module-specific data from the
  836. PAM handle stored previously by the `pam_get_data()' function. The
  837. `module_data_name' uniquely specifies the name for which data has to
  838. be obtained. This function is normally used to retrieve module
  839. specific state information.
  840. A.2. Authentication API's
  841. int
  842. pam_authenticate(
  843. pam_handle_t *pamh,
  844. int flags
  845. );
  846. The `pam_authenticate()' function is called to verify the identity of
  847. the current user. The user is usually required to enter a password
  848. or similar authentication token, depending upon the authentication
  849. Samar, Schemers Page 20
  850. OSF-RFC 86.0 PAM October 1995
  851. module configured with the system. The user in question is specified
  852. by a prior call to `pam_start()', and is referenced by the
  853. authentication handle, `pamh'.
  854. int
  855. pam_setcred(
  856. pam_handle_t *pamh,
  857. int flags
  858. );
  859. The `pam_setcred()' function is called to set the credentials of the
  860. current process associated with the authentication handle, `pamh'.
  861. The actions that can be denoted through `flags' include credential
  862. initialization, refresh, reinitialization and deletion.
  863. A.3. Account Management API
  864. int
  865. pam_acct_mgmt(
  866. pam_handle_t *pamh,
  867. int flags
  868. );
  869. The function `pam_acct_mgmt()' is called to determine whether the
  870. current user's account and password are valid. This typically
  871. includes checking for password and account expiration, valid login
  872. times, etc. The user in question is specified by a prior call to
  873. `pam_start()', and is referenced by the authentication handle,
  874. `pamh'.
  875. A.4. Session Management API's
  876. int
  877. pam_open_session(
  878. pam_handle_t *pamh,
  879. int flags
  880. );
  881. `pam_open_session()' is called to inform the session modules that a
  882. new session has been initialized. All programs which use PAM should
  883. invoke `pam_open_session()' when beginning a new session.
  884. int
  885. pam_close_session(
  886. pam_handle_t *pamh,
  887. int flags
  888. );
  889. Upon termination of this session, the `pam_close_session()' function
  890. should be invoked to inform the underlying modules that the session
  891. has terminated.
  892. Samar, Schemers Page 21
  893. OSF-RFC 86.0 PAM October 1995
  894. A.5. Password Management API's
  895. int
  896. pam_chauthtok(
  897. pam_handle_t *pamh,
  898. int flags
  899. );
  900. `pam_chauthtok()' is called to change the authentication token
  901. associated with the user referenced by the authentication handle
  902. `pamh'. After the call, the authentication token of the user will be
  903. changed in accordance with the authentication module configured on
  904. the system.
  905. APPENDIX B. SAMPLE PAM APPLICATION
  906. This appendix shows a sample `login' application which uses the PAM
  907. API's. It is not meant to be a fully functional login program, as
  908. some functionality has been left out in order to emphasize the use of
  909. PAM API's.
  910. #include <security/pam_appl.h>
  911. static int login_conv(int num_msg, struct pam_message **msg,
  912. struct pam_response **response, void *appdata_ptr);
  913. static struct pam_conv pam_conv = {login_conv, NULL};
  914. static pam_handle_t *pamh; /* Authentication handle */
  915. void
  916. main(int argc, char *argv[], char **renvp)
  917. {
  918. /*
  919. * Call pam_start to initiate a PAM authentication operation
  920. */
  921. if ((pam_start("login", user_name, &pam_conv, &pamh))
  922. != PAM_SUCCESS)
  923. login_exit(1);
  924. pam_set_item(pamh, PAM_TTY, ttyn);
  925. pam_set_item(pamh, PAM_RHOST, remote_host);
  926. while (!authenticated && retry < MAX_RETRIES) {
  927. status = pam_authenticate(pamh, 0);
  928. authenticated = (status == PAM_SUCCESS);
  929. }
  930. Samar, Schemers Page 22
  931. OSF-RFC 86.0 PAM October 1995
  932. if (status != PAM_SUCCESS) {
  933. fprintf(stderr,"error: %s\n", pam_strerror(status));
  934. login_exit(1);
  935. }
  936. /* now check if the authenticated user is allowed to login. */
  937. if ((status = pam_acct_mgmt(pamh, 0)) != PAM_SUCCESS) {
  938. if (status == PAM_AUTHTOK_EXPIRED) {
  939. status = pam_chauthtok(pamh, 0);
  940. if (status != PAM_SUCCESS)
  941. login_exit(1);
  942. } else {
  943. login_exit(1);
  944. }
  945. }
  946. /*
  947. * call pam_open_session to open the authenticated session
  948. * pam_close_session gets called by the process that
  949. * cleans up the utmp entry (i.e., init)
  950. */
  951. if (status = pam_open_session(pamh, 0) != PAM_SUCCESS) {
  952. login_exit(status);
  953. }
  954. /* set up the process credentials */
  955. setgid(pwd->pw_gid);
  956. /*
  957. * Initialize the supplementary group access list.
  958. * This should be done before pam_setcred because
  959. * the PAM modules might add groups during the pam_setcred call
  960. */
  961. initgroups(user_name, pwd->pw_gid);
  962. status = pam_setcred(pamh, PAM_ESTABLISH_CRED);
  963. if (status != PAM_SUCCESS) {
  964. login_exit(status);
  965. }
  966. /* set the real (and effective) UID */
  967. setuid(pwd->pw_uid);
  968. pam_end(pamh, PAM_SUCCESS); /* Done using PAM */
  969. /*
  970. * Add DCE/Kerberos cred name, if any.
  971. * XXX - The module specific stuff should be removed from login
  972. * program eventually. This is better placed in DCE module and
  973. * will be once PAM has routines for "exporting" environment
  974. Samar, Schemers Page 23
  975. OSF-RFC 86.0 PAM October 1995
  976. * variables.
  977. */
  978. krb5p = getenv("KRB5CCNAME");
  979. if (krb5p != NULL) {
  980. ENVSTRNCAT(krb5ccname, krb5p);
  981. envinit[basicenv++] = krb5ccname;
  982. }
  983. environ = envinit; /* Switch to the new environment. */
  984. exec_the_shell();
  985. /* All done */
  986. }
  987. /*
  988. * login_exit - Call exit() and terminate.
  989. * This function is here for PAM so cleanup can
  990. * be done before the process exits.
  991. */
  992. static void
  993. login_exit(int exit_code)
  994. {
  995. if (pamh)
  996. pam_end(pamh, PAM_ABORT);
  997. exit(exit_code);
  998. /*NOTREACHED*/
  999. }
  1000. /*
  1001. * login_conv():
  1002. * This is the conv (conversation) function called from
  1003. * a PAM authentication module to print error messages
  1004. * or garner information from the user.
  1005. */
  1006. static int
  1007. login_conv(int num_msg, struct pam_message **msg,
  1008. struct pam_response **response, void *appdata_ptr)
  1009. {
  1010. while (num_msg--) {
  1011. switch (m->msg_style) {
  1012. case PAM_PROMPT_ECHO_OFF:
  1013. r->resp = strdup(getpass(m->msg));
  1014. break;
  1015. case PAM_PROMPT_ECHO_ON:
  1016. (void) fputs(m->msg, stdout);
  1017. r->resp = malloc(PAM_MAX_RESP_SIZE);
  1018. fgets(r->resp, PAM_MAX_RESP_SIZE, stdin);
  1019. /* add code here to remove \n from fputs */
  1020. Samar, Schemers Page 24
  1021. OSF-RFC 86.0 PAM October 1995
  1022. break;
  1023. case PAM_ERROR_MSG:
  1024. (void) fputs(m->msg, stderr);
  1025. break;
  1026. case PAM_TEXT_INFO:
  1027. (void) fputs(m->msg, stdout);
  1028. break;
  1029. default:
  1030. /* add code here to log error message, etc */
  1031. break;
  1032. }
  1033. }
  1034. return (PAM_SUCCESS);
  1035. }
  1036. APPENDIX C. DCE MODULE
  1037. This appendix describes a sample implementation of a DCE PAM module.
  1038. In order to simplify the description, we do not address the issues
  1039. raised by password-mapping or stacking. The intent is to show which
  1040. DCE calls are being made by the DCE module.
  1041. The `pam_sm_*()' functions implement the PAM SPI functions which are
  1042. called from the PAM API functions.
  1043. C.1. DCE Authentication Management
  1044. The algorithm for authenticating with DCE (not including error
  1045. checking, prompting for passwords, etc.) is as follows:
  1046. pam_sm_authenticate()
  1047. {
  1048. sec_login_setup_identity(...);
  1049. pam_set_data(...);
  1050. sec_login_valid_and_cert_ident(...);
  1051. }
  1052. pam_sm_setcred()
  1053. {
  1054. pam_get_data(...);
  1055. sec_login_set_context(...);
  1056. }
  1057. The `pam_sm_authenticate()' function for DCE uses the
  1058. `pam_set_data()' and `pam_get_data()' functions to keep state (like
  1059. the `sec_login_handle_t' context) between calls. The following
  1060. cleanup function is also registered and gets called when `pam_end()'
  1061. Samar, Schemers Page 25
  1062. OSF-RFC 86.0 PAM October 1995
  1063. is called:
  1064. dce_cleanup()
  1065. {
  1066. if (/* PAM_SUCCESS and
  1067. sec_login_valid_and_cert_ident success */) {
  1068. sec_login_release_context(...);
  1069. } else {
  1070. sec_login_purge_context(...);
  1071. }
  1072. }
  1073. If everything was successful we release the login context, but leave
  1074. the credentials file intact. If the status passed to `pam_end()' was
  1075. not `PAM_SUCCESS' (i.e., a required module failed) we purge the login
  1076. context which also removes the credentials file.
  1077. C.2. DCE Account Management
  1078. The algorithm for DCE account management is as follows:
  1079. pam_sm_acct_mgmt()
  1080. {
  1081. pam_get_data(...);
  1082. sec_login_inquire_net_info(...);
  1083. /* check for expired password and account */
  1084. sec_login_free_net_info(...);
  1085. }
  1086. The `sec_login_inquire_net_info()' function is called to obtain
  1087. information about when the user's account and/or password are going
  1088. to expire. A warning message is displayed (using the conversation
  1089. function) if the user's account or password is going to expire in the
  1090. near future, or has expired. These warning messages can be disabled
  1091. using the `nowarn' option in the `pam.conf' file.
  1092. C.3. DCE Session Management
  1093. The DCE session management functions are currently empty. They could
  1094. be modified to optionally remove the DCE credentials file upon
  1095. logout, etc.
  1096. C.4. DCE Password Management
  1097. The algorithm for DCE password management is as follows:
  1098. Samar, Schemers Page 26
  1099. OSF-RFC 86.0 PAM October 1995
  1100. pam_sm_chauthtok
  1101. {
  1102. sec_rgy_site_open(...);
  1103. sec_rgy_acct_lookup(...);
  1104. sec_rgy_acct_passwd(...);
  1105. sec_rgy_site_close(...);
  1106. }
  1107. The `sec_rgy_acct_passwd()' function is called to change the user's
  1108. password in the DCE registry.
  1109. REFERENCES
  1110. [Adamson 95] W. A. Adamson, J. Rees, and P. Honeyman, "Joining
  1111. Security Realms: A Single Login for Netware and
  1112. Kerberos", CITI Technical Report 95-1, Center for
  1113. Information Technology Integration, University of
  1114. Michigan, Ann Arbor, MI, February 1995.
  1115. [Diffie 76] W. Diffie and M. E. Hellman, "New Directions in
  1116. Cryptography", IEEE Transactions on Information
  1117. Theory, November 1976.
  1118. [Linn 93] J. Linn, "Generic Security Service Application
  1119. Programming Interface", Internet RFC 1508, 1509, 1993.
  1120. [Rivest 78] R. L. Rivest, A. Shamir, and L. Adleman., "A Method
  1121. for Obtaining Digital Signatures and Pubic-key
  1122. Cryptosystems", Communications of the ACM, 21(2),
  1123. 1978.
  1124. [SIA 95] "Digital UNIX Security", Digital Equipment
  1125. Corporation, Order Number AA-Q0R2C-TE, July 1995.
  1126. [Skey 94] N. M. Haller, "The S/Key One-Time Password System",
  1127. ISOC Symposium on Network and Distributed Security,
  1128. 1994.
  1129. [Steiner 88] J.G. Steiner, B. C. Neuman, and J. I. Schiller,
  1130. "Kerberos, An Authentication Service for Open Network
  1131. Systems", in Proceedings of the Winter USENIX
  1132. Conference, Dallas, Jan 1988.
  1133. [Taylor 88] B. Taylor and D. Goldberg, "Secure Networking in the
  1134. Sun Environment", Sun Microsystems Technical Paper,
  1135. 1988.
  1136. [XFN 94] "Federated Naming: the XFN Specifications", X/Open
  1137. Preliminary Specification, X/Open Document #P403,
  1138. ISBN:1-85912-045-8, X/Open Co. Ltd., July 1994.
  1139. Samar, Schemers Page 27
  1140. OSF-RFC 86.0 PAM October 1995
  1141. AUTHOR'S ADDRESS
  1142. Vipin Samar Internet email: vipin@eng.sun.com
  1143. SunSoft, Inc. Telephone: +1-415-336-1002
  1144. 2550 Garcia Avenue
  1145. Mountain View, CA 94043
  1146. USA
  1147. Roland J. Schemers III Internet email: schemers@eng.sun.com
  1148. SunSoft, Inc. Telephone: +1-415-336-1035
  1149. 2550 Garcia Avenue
  1150. Mountain View, CA 94043
  1151. USA
  1152. Samar, Schemers Page 28