Import Debian changes 0.69.0-2
[hcoop/debian/courier-authlib.git] / README_authlib.html.in
CommitLineData
d9898ee8 1<?xml version="1.0"?>
b0322a85 2<html xmlns="http://www.w3.org/1999/xhtml"><head><meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/><title>Courier Authentication Library</title><link rel="stylesheet" type="text/css" href="style.css"/><meta name="generator" content="DocBook XSL Stylesheets V1.78.1"/><link rel="home" href="#authlib" title="Courier Authentication Library"/><link rel="next" href="#authpwd" title="The authpwd authentication module"/><link xmlns="" rel="stylesheet" type="text/css" href="manpage.css"/><meta xmlns="" name="MSSmartTagsPreventParsing" content="TRUE"/><link xmlns="" rel="icon" href="icon.gif" type="image/gif"/><!--
d9898ee8 3
8d138742 4Copyright 1998 - 2009 Double Precision, Inc. See COPYING for distribution
d9898ee8 5information.
6
b0322a85 7--></head><body><div class="chapter"><div class="titlepage"><div><div><h1 class="title"><a id="authlib" shape="rect"> </a>Courier Authentication Library</h1></div></div></div><div class="toc"><p><strong>Table of Contents</strong></p><dl class="toc"><dt><span class="sect1"><a href="#authpwd" shape="rect">The <code class="literal">authpwd</code> authentication module</a></span></dt><dt><span class="sect1"><a href="#authshadow" shape="rect">The <code class="literal">authshadow</code> authentication module</a></span></dt><dt><span class="sect1"><a href="#authpam" shape="rect">The <code class="literal">authpam</code> authentication module</a></span></dt><dt><span class="sect1"><a href="#authpipe" shape="rect">The <code class="literal">authpipe</code> authentication module</a></span></dt><dt><span class="sect1"><a href="#authpipeproto" shape="rect">The <code class="literal">authpipe</code> protocol</a></span></dt><dt><span class="sect1"><a href="#authuserdb" shape="rect">The <code class="literal">authuserdb</code> authentication module</a></span></dt><dd><dl><dt><span class="sect2"><a href="#userdbprimer" shape="rect">A brief <code class="literal">userdb</code> primer</a></span></dt><dt><span class="sect2"><a href="#userdbsimple" shape="rect">A simple userdb setup</a></span></dt><dt><span class="sect2"><a href="#userdbcomplex" shape="rect">Large virtual domain farm</a></span></dt><dt><span class="sect2"><a href="#moreuserdb" shape="rect">Beyond <code class="literal">userdb</code></a></span></dt></dl></dd><dt><span class="sect1"><a href="#authmysql" shape="rect">The <code class="literal">authmysql</code> authentication module</a></span></dt><dt><span class="sect1"><a href="#authpgsql" shape="rect">The <code class="literal">authpgsql</code> authentication module</a></span></dt><dt><span class="sect1"><a href="#authsqlite" shape="rect">The <code class="literal">authsqlite</code> authentication module</a></span></dt><dt><span class="sect1"><a href="#authldap" shape="rect">The <code class="literal">authldap</code> authentication module</a></span></dt><dt><span class="sect1"><a href="#authcustom" shape="rect"><code class="literal">authcustom</code></a></span></dt><dt><span class="sect1"><a href="#options" shape="rect">Account options</a></span></dt><dt><span class="sect1"><a href="#authtest" shape="rect">Running <span class="command"><strong>authtest</strong></span></a></span></dt><dd><dl><dt><span class="sect2"><a href="#pwchange" shape="rect">Changing account passwords</a></span></dt></dl></dd><dt><span class="sect1"><a href="#internals" shape="rect">Authentication internals</a></span></dt><dt><span class="sect1"><a href="#files" shape="rect">FILES</a></span></dt><dt><span class="sect1"><a href="#seealso" shape="rect">SEE ALSO</a></span></dt></dl></div><p>
d9898ee8 8This library is used for two purposes:</p><p>
91. Read the name of a mail account.
10Determine the local account's home directory, and system userid and
11groupid.</p><p>
122. Read an account name, and a password.
13If valid, determine the account's home directory, system userid, and
14groupid.</p><p>
15The term "authentication" is used in the following documentation to refer
16to either one of these two functions.
17The library contains several alternative authentication modules to choose
18from, described below.</p><p>
19The configuration file <code class="filename">@authdaemonrc@</code> contains several
b0322a85 20settings. The most important of them are:</p><div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: disc; "><li class="listitem"><p>
d9898ee8 21A list of authentication modules to activate.
22By default, this list includes all available authentication modules,
23even if some are not actually installed at the moment.
24When the authentication library is set up, only those authentication
25modules that can be supported by the operating system will be installed.
26Some of the listed modules may not actually be there,
27however that's not a problem.
28Any unavailable authentication modules will be ignored.
29Also, on some platforms certain authentication modules are installed by
30optional sub-packages.
31Installing the sub-package is the only action needed to make use of it.</p><p>
32The only time the list of authentication modules need to be adjusted is
33when an available authentication module must be disabled for some reason.
b0322a85 34This should only be needed in the most unusual circumstances.</p></li><li class="listitem"><p>
d9898ee8 35Number of authentication processes.
36The default setting is to start five authentication processes, which should be
37sufficient for normal usage.
38Try increasing this setting if its taking too long to log into an account,
39and you have determined that this is not due to a bottleneck in the whatever
b0322a85
CE
40authentication database you're using (LDAP, MySQL, SQLite,
41or PostgreSQL).</p><p>
d9898ee8 42An authentication request must be completed within thirty seconds, otherwise
43it gets rejected.
44When authentication requests come in faster than all five authentication
45processes can get to them, delays build up, and the timer is ticking.
46If all the activity maxes out the CPU or I/O bandwidth,
47nothing can be done about it, short
48of getting another server. However if there's plenty of available CPU and
b0322a85 49I/O, increasing the number of processes will do the trick.</p></li></ul></div><div class="sect1"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a id="authpwd" shape="rect"> </a>The <code class="literal">authpwd</code> authentication module</h2></div></div></div><p>
d9898ee8 50This modules obtains account information and passwords from the
51<code class="filename">/etc/passwd</code> file.</p><div class="note" style="margin-left: 0.5in; margin-right: 0.5in;"><h3 class="title">Note</h3><p>
52This module doesn't actually read the <code class="filename">/etc/passwd</code>
53file, it uses the C library's getpw() functions.
54The C library implementation could use any mechanism to obtain the equivalent
b0322a85 55information.</p></div></div><div class="sect1"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a id="authshadow" shape="rect"> </a>The <code class="literal">authshadow</code> authentication module</h2></div></div></div><p>
d9898ee8 56This module is a version of the <code class="literal">authpwd</code> module that
57reads passwords
58from <code class="filename">/etc/shadow</code> (the C library's getsp()
b0322a85 59functions).</p></div><div class="sect1"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a id="authpam" shape="rect"> </a>The <code class="literal">authpam</code> authentication module</h2></div></div></div><p>
d9898ee8 60This modules uses the system's PAM library
61(pluggable authentication modules) for authentication.
62This is, essentially, a way to use existing PAM modules for authentication.
63Note, however, that the authenticated account's home directory, userid and
64groupid are still read from the <code class="filename">/etc/passwd</code> file,
65since PAM functionality is limited to validating account passwords.</p><div class="note" style="margin-left: 0.5in; margin-right: 0.5in;"><h3 class="title">Note</h3><p>
66Not all PAM modules are compatible with Courier's authentication library.
67PAM modules that make use of PAM's session functions, or authentication token
68functions, like <code class="literal">pam_krb5</code> will not work with Courier.</p></div><div class="note" style="margin-left: 0.5in; margin-right: 0.5in;"><h3 class="title">Note</h3><p>
69Additional configuration steps will be required to set up
70the PAM library to authenticate Courier's services.
71Courier's IMAP and POP3 servers, for example, require that the
b0322a85 72<span class="quote">“<span class="quote">imap</span>”</span> and <span class="quote">“<span class="quote">pop3</span>”</span> PAM service to be
d9898ee8 73configured.</p><p>
74The specific configuration steps differ from system to system.
75Consult the system documentation for more information.
76It might be tempting to throw in a towel and use
77<code class="literal">authshadow</code> or <code class="literal">authpwd</code>
78if you cannot figure out how to install PAM support,
79however that is not advisable.
80It is highly recommended to use
81<code class="filename">authpam</code> wherever the PAM library is available.</p><p>
82The exact configuration procedure depends on the PAM implementation.
83Most PAM libraries use configuration files in the
84<code class="filename">/etc/pam.d</code> directory.
85Therefore, it will be necessary to install the configuration files
86<code class="filename">/etc/pam.d/imap</code> and
87<code class="filename">/etc/pam.d/pop3</code>. Similarly, Courier's webmail
88server, SqWebMail, uses <code class="filename">/etc/pam.d/webmail</code>, and
89its optional calendar component uses <code class="filename">/etc/pam.d/webmail</code>.
90Courier-MTA's authenticated SMTP component uses the
91<code class="filename">/etc/pam.d/smtp</code> service.</p><p>
92In nearly all cases all these configuration files will specify an
93identical PAM library configuration for all services.
94The exact configuration details are site-specific.
95Here's an example of a PAM configuration file for a recent version of the
96most common PAM library:</p><div class="informalexample"><pre class="programlisting" xml:space="preserve">
97auth required pam_nologin.so
98auth required pam_stack.so service=system-auth
99account required pam_stack.so service=system-auth
100session required pam_stack.so service=system-auth
101</pre></div><p>
102Again, the actual configuration is site specific.
103Examine the contents of existing configuration files in
104<code class="filename">/etc/pam.d</code> for similar services (if there's
105<code class="filename">/etc/pam.d/ppp</code>
106it's often a good example to follow) in order
107to derive the correct setup for Courier.</p><p>
108Older PAM libraries use a single configuration file, usually
109<code class="filename">/etc/pam.conf</code>.
110Append Courier-specific PAM settings to this configuration file, again
111using settings for existing services as a guide.
112For example:</p><div class="informalexample"><pre class="programlisting" xml:space="preserve">
113imap auth required pam_unix.so try_first_pass
114imap account required pam_unix.so
115imap session required pam_permit.so
116pop3 auth required pam_unix.so try_first_pass
117pop3 account required pam_unix.so
118</pre></div><p>
119Some PAM libraries use
120<code class="filename">pam_pwdb.so</code> instead of
121<code class="filename">pam_unix.so</code>; consult the PAM library's
b0322a85 122documentation for more information.</p></div></div><div class="sect1"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a id="authpipe" shape="rect"> </a>The <code class="literal">authpipe</code> authentication module</h2></div></div></div><p>This is a generic plug-in module that runs an external script,
d9898ee8 123or a program, in response to authentication requests.</p><p>The external program reads from stdin and writes to stdout. It
124can be persistent and handle many authentication requests. Only one request
125will be sent to it at a time; each authdaemon process starts its own copy of
126the external script.</p><p>The location of the external program is set by the
127<code class="literal">--with-pipeprog</code> configure option,
128which defaults to
129<code class="filename">@sysconfdir@/authlib/authProg</code>. A sample program
b0322a85 130is included in the courier-authlib source.</p></div><div class="sect1"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a id="authpipeproto" shape="rect"> </a>The <code class="literal">authpipe</code> protocol</h2></div></div></div><p>
d9898ee8 131authpipe uses the same protocol as authdaemon clients use to communicate
132with authdaemond.</p><p>There are four possible requests: <code class="literal">PRE</code>,
133<code class="literal">AUTH</code>, <code class="literal">PASSWD</code> and
134<code class="literal">ENUMERATE</code>. Apart from <code class="literal">AUTH</code>, each
135request is a single line terminated by newline.
b0322a85 136</p><div class="variablelist"><dl class="variablelist"><dt><span class="term">PRE . <em class="replaceable"><code>authservice</code></em> <em class="replaceable"><code>username</code></em> <span class="emphasis"><em>&lt;newline&gt;</em></span></span></dt><dd><p>Look up data for an account.
d9898ee8 137 <em class="replaceable"><code>authservice</code></em> identifies the service the
138 user is trying to use - e.g. pop3, imap, webmail etc.</p><p>If the account exists, return the account
139 data as a series of ATTR=value newline-terminated lines, followed by a
140 period on a line of its own. Valid attributes are:
141 </p><pre class="screen" xml:space="preserve">
142 USERNAME=username -- system account which owns mailbox (name)
143 UID=uid -- system account which owns mailbox (numeric uid)
144 GID=gid -- numeric groupid
145 HOME=homedir -- home directory
146 ADDRESS=addr -- e-mail address
147 NAME=name -- full name
148 MAILDIR=maildir -- Maildir relative to home directory
149 QUOTA=quota -- quota string: maxbytesS,maxfilesC
150 PASSWD=cryptpasswd -- encrypted password
151 PASSWD2=plainpasswd -- plain text password
152 OPTIONS=acctoptions -- option1=val1,option2=val2,...
153 .
154 </pre><p>
155 Of these, it is mandatory to return ADDRESS, HOME, GID, and either UID
156 or USERNAME; the others are optional.
157 </p><p>If the account is not known, return <code class="literal">FAIL</code><span class="emphasis"><em><code class="literal">&lt;newline&gt;</code></em></span>.
158 If there is a temporary failure, such as a database being down, authProg
159 should terminate (thereby closing stdin/stdout) without sending any
160 response. authdaemon will restart the pipe module for the next
161 request, thus ensuring it is properly reinitialized.
162 </p></dd><dt><span class="term">AUTH <em class="replaceable"><code>len</code></em><span class="emphasis"><em>&lt;newline&gt;</em></span><em class="replaceable"><code>len-bytes</code></em></span></dt><dd><p>
163 Validate a login attempt. The AUTH line is followed by
164 <span class="emphasis"><em>len-bytes</em></span> of authentication data, which does not
165 necessarily end with a newline. The currently defined authentication
166 requests are:
167 </p><pre class="screen" xml:space="preserve">
8d138742
CE
168 service \n login \n username \n password [\n] -- plaintext login
169 service \n cram-md5 \n challenge \n response [\n] -- base-64 encoded challenge and response
170 service \n cram-sha1 \n challenge \n response [\n] -- ditto
171 service \n cram-sha256 \n challenge \n response [\n] -- ditto
d9898ee8 172 </pre><p>
173 In the case of success, return the complete set of
d50284c4 174 account parameters in the same format as PRE, ending with a period on
d9898ee8 175 a line of its own. In the case of failure (e.g. username does not exist,
176 password wrong, unsupported authentication type), return
177 <code class="literal">FAIL</code><span class="emphasis"><em><code class="literal">&lt;newline&gt;</code></em></span>.
178 If there is a temporary failure, such as a database being down, authProg
179 should terminate without sending any response.
180 </p><p>
181 Note: if the user provides a plaintext password and authenticates
182 successfully, then you can return it as PASSWD2 (plain text password)
183 even if the database contains an encrypted password. This is useful
184 when using the POP3/IMAP proxy functions of courier-imap.
185 </p></dd><dt><span class="term">PASSWD <em class="replaceable"><code>service</code></em><span class="emphasis"><em>&lt;tab&gt;</em></span>
186 <em class="replaceable"><code>username</code></em><span class="emphasis"><em>&lt;tab&gt;</em></span>
187 <em class="replaceable"><code>oldpasswd</code></em><span class="emphasis"><em>&lt;tab&gt;</em></span>
188 <em class="replaceable"><code>newpasswd</code></em><span class="emphasis"><em>&lt;tab&gt;</em></span>
189 <span class="emphasis"><em>&lt;newline&gt;</em></span>
190 </span></dt><dd><p>Request a password change for the given account: validate that
191 the oldpassword is correct, and if so, change it to the newpassword.
d50284c4 192 </p><p>Reply: the string <code class="literal">OK</code><span class="emphasis"><em><code class="literal">&lt;newline&gt;</code></em></span>
d9898ee8 193 for success, or <code class="literal">FAIL</code><span class="emphasis"><em><code class="literal">&lt;newline&gt;</code></em></span> for
194 a data error (e.g. no such account, old password wrong, new password not
195 acceptable). In the case of a temporary failure, such as a database
196 being down, authProg should terminate without sending any response.
197 </p></dd><dt><span class="term">ENUMERATE <span class="emphasis"><em>&lt;newline&gt;</em></span></span></dt><dd><p>
198 Return a list of all accounts, one per line in the following format,
199 ending with a period on a line of its own:
200 </p><pre class="screen" xml:space="preserve">
201 username \t uid \t gid \t homedir \t maildir \t options \n
202 .
203 </pre><p>
204 If your module does not support the ENUMERATE command then return just
205 a period on a line of its own (which will still allow enumeration data
206 from other modules to be returned). In the case of a temporary failure,
207 such as a database being down or an error occuring mid-way through
208 returning account data, authProg should terminate before sending
209 the terminating period.
b0322a85 210 </p></dd></dl></div></div><div class="sect1"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a id="authuserdb" shape="rect"> </a>The <code class="literal">authuserdb</code> authentication module</h2></div></div></div><p>
d9898ee8 211This module
212uses a GDBM or a DB-based
ac40fd9e 213<a class="ulink" href="userdb.html" target="_top" shape="rect"><span class="citerefentry"><span class="refentrytitle">userdb</span>(8)</span></a> database.
d9898ee8 214This module also incorporates userdb-based challenge-response authentication
215implementation that was done by a separate <code class="literal">authcram</code> module
216in previous versions of the Courier authentication library.</p><p>
217<code class="filename">@sysconfdir@/authlib/userdb</code> is a plain file that
218can be edited with any text editor.
219The file contains a list of account names, and their pertinent information.
220<code class="filename">@sysconfdir@/authlib/userdb</code> may alternatively be a
221directory containing plain text files, which are effectively concatenated
222together to form the actual list of accounts.
ac40fd9e 223The <span class="command"><strong>makeuserdb</strong></span> script compiles the account information
d9898ee8 224into a GDBM or DB database file, which can be quickly looked up.</p><p>
225<code class="filename">@sysconfdir@/authlib/userdb</code> is loosely equivalent in
226function to <code class="filename">/etc/passwd</code> and
227<code class="filename">/etc/shadow</code>, and contain analous information: account
228name, its numeric userid and groupid, home directory, and passwords.
229<code class="filename">@sysconfdir@/authlib/userdb</code> also contains additional
230Courier-specific metadata, such as account quotas and other account-specific
231settings.
232<code class="filename">@sysconfdir@/authlib/userdb</code> files can also be
233maintained by custom-written Perl scripts, instead of being edited
234by hand.</p><p>
235<code class="filename">@sysconfdir@/authlib/userdb</code>
236allows creation of virtual mail accounts that do not have a corresponding
237login account -- virtual mail accounts that can share the same, reserved,
238system userid.
239<code class="filename">@sysconfdir@/authlib/userdb</code>
240can also be used to completely supersede
241<code class="filename">/etc/passwd</code>.
242With many accounts it can be quite a drain to have to continuously linearly
243scan <code class="filename">/etc/passwd</code> in order to look up an account.
244Instead, a fast database lookup can retrieve the same information from the
245database file.
246Review the included manual pages, starting with
b0322a85 247<a class="ulink" href="userdb.html" target="_top" shape="rect"><span class="citerefentry"><span class="refentrytitle">userdb</span>(8)</span></a>, for more information.</p><div class="sect2"><div class="titlepage"><div><div><h3 class="title"><a id="userdbprimer" shape="rect"> </a>A brief <code class="literal">userdb</code> primer</h3></div></div></div><p>
d9898ee8 248<code class="literal">userdb</code> is a way to implement many virtual mailboxes - many
249mailboxes that do not have to have a separate system userid allocated for
250each one, and there is no system login associated with each mailbox.
251<code class="literal">userdb</code> uses a database for mapping virtual addresses to physical
252maildirs. It should be scalable to thousands of mailboxes. It can also be
253used to replace linear searches of <code class="filename">/etc/passwd</code> with a database
254lookup, see
b0322a85 255<a class="ulink" href="userdb.html" target="_top" shape="rect"><span class="citerefentry"><span class="refentrytitle">userdb</span>(8)</span></a>.</p><p>
d9898ee8 256Note - you still MUST use some valid system userid and groupid that is
257shared by all virtual mailboxes. Instead of allocating a single userid and
258groupid per each mailbox, the same userid and groupid is used for all of
259them.</p><p>
260This is a rough overview of using userdb. For additional information, read
ac40fd9e 261<a class="ulink" href="userdb.html" target="_top" shape="rect"><span class="citerefentry"><span class="refentrytitle">userdb</span>(8)</span></a>
d9898ee8 262and
ac40fd9e 263<a class="ulink" href="makeuserdb.html" target="_top" shape="rect"><span class="citerefentry"><span class="refentrytitle">makeuserdb</span>(8)</span></a>. All the scripts will
d9898ee8 264be installed in <code class="filename">@sbindir@</code>, so look for them there.</p><p>
265The best way to describe how <code class="literal">userdb</code> works is to try to create
266one virtual mail account. As mentioned before, virtual mailboxes still need
267one system account to be used for uid/gid purposes. Let's call this system
b0322a85 268account "vmail".</p></div><div class="sect2"><div class="titlepage"><div><div><h3 class="title"><a id="userdbsimple" shape="rect"> </a>A simple userdb setup</h3></div></div></div><p>
d9898ee8 269This approach should be used if you do not have many virtual mailboxes.
270It's very simple, but quickly becomes cumbersome if you administer many
271virtual mailboxes.</p><p>Create an empty <code class="filename">@userdb@</code> file:</p><div class="informalexample"><pre class="programlisting" xml:space="preserve">
272# cp /dev/null @userdb@
273# chmod 700 @userdb@</pre></div><p>
274<code class="filename">@userdb@</code> must have 700 permissions,
275since it will contain passwords.</p><p>
ac40fd9e 276Now, run the script <span class="command"><strong>pw2userdb</strong></span>, as root.
d9898ee8 277This script converts the
278contents of <code class="filename">/etc/passwd</code>
279to the <code class="filename">@userdb@</code> format
280(including the contents of <code class="filename">/etc/shadow</code>,
281this is why permissions
282on <code class="filename">@userdb@</code> must be 700). This script is usually used
283where you
284want to convert a very large <code class="filename">/etc/passwd</code> to
285<code class="filename">@userdb@</code>. <code class="literal">userdb</code> applications can now
286use a fast
287<code class="literal">userdb</code> database instead of a linear scan
288of <code class="filename">/etc/passwd</code>
289in order to look up system accounts. However, you probably don't want to
290use this feature right now, so what you want to do is take the output
ac40fd9e 291of <span class="command"><strong>pw2userdb</strong></span>, and find the entry for the vmail account
d9898ee8 292that you
293created earlier. Look for a line that starts with 'vmail' followed by tab,
294followed by familiar fields from <code class="filename">/etc/passwd</code>. Save the
295output of
ac40fd9e 296<span class="command"><strong>pw2userdb</strong></span> in a temporary file, edit it, and remove
d9898ee8 297everything
298except the line containing vmail, and the very next line, which is a special
299entry that maps vmail's userid back to the vmail record.</p><p>
300Here's what you might find in the output of
ac40fd9e 301<span class="command"><strong>pw2userdb</strong></span>:</p><div class="informalexample"><pre class="programlisting" xml:space="preserve">
d9898ee8 302vmail uid=1012|gid=1012|home=/home/vmail|systempw=*
3031012= vmail</pre></div><p>
304The actual numerical values and the home directory location may vary.
305Save
306these two lines as <code class="filename">@userdb@</code>, and set the permissions on
307<code class="filename">@userdb@</code> to 700:</p><div class="informalexample"><pre class="programlisting" xml:space="preserve">
308$ chmod 700 <code class="filename">@userdb@</code>
309</pre></div><p>
310Now, with that out of the way, let's really create a virtual account. In
311this example we'll create a virtual mailbox for 'john@example.com'.</p><div class="informalexample"><pre class="programlisting" xml:space="preserve">
312# su vmail
313$ cd ~vmail
314$ mkdir john-example
315$ maildirmake john-example/Maildir
316$ exit
317#
318</pre></div><p>
ac40fd9e 319You may need to specify a full path to your <span class="command"><strong>maildirmake</strong></span>
d9898ee8 320program. The end result is that you created
321<code class="filename">$HOME/john-example</code> in vmail's account, which
b0322a85
CE
322can be thought of as a <span class="quote">“<span class="quote">virtual home directory</span>”</span> for
323<span class="quote">“<span class="quote">john@example.com</span>”</span>, that contains the account's maildir
d9898ee8 324mailbox.</p><p>
325Now, let's connect the dots here, and create an entry in
326<code class="filename">@userdb@</code> for <code class="filename">john@example.com</code>:</p><div class="informalexample"><pre class="programlisting" xml:space="preserve">
327# userdb "john@example.com" set home=/home/vmail/john-example \
328 uid=UUU gid=GGG
329</pre></div><p>
330This command runs the script named <code class="filename">userdb</code> , which is
331installed, by default in <code class="filename">@sbindir@</code>. Replace UUU and
332GGG with the userid and groupid of the vmail account. If you now look in
333<code class="filename">@userdb@</code>, you will see that a new record for
b0322a85 334<span class="quote">“<span class="quote">john@example.com</span>”</span>
d9898ee8 335has been appended to the end of the file.</p><p>
336One more detail: we need to set the IMAP password for this
337mailbox:</p><div class="informalexample"><pre class="programlisting" xml:space="preserve">
338# userdbpw | userdb "john@example.com" set imappw</pre></div><p>
339On most modern Linux and BSD distributions, you can specify the -md5
ac40fd9e 340option to <span class="command"><strong>userdbpw</strong></span>, in order to use MD5 password hashes,
d9898ee8 341instead of crypt. The traditional password function allows passwords only
342up to 8 characters long; everything in excess is ignored.
343The newer MD5 passwords, now supported by most modern systems, allow
344longer passwords.</p><p>
345Use "<code class="literal">systempw</code>" instead of
346"<code class="literal">imappw</code>" if you would like to use the same password for the POP3
347server, and for all other services.
348The "<code class="literal">imappw</code>" field is only checked by the IMAP server.
349If not
350defined, "<code class="literal">systempw</code>" is used instead. The field
351<code class="literal">pop3pw</code>
352is checked only by Courier's POP3 server. If it is
353not defined the POP3 server will check <code class="literal">systempw</code> too.</p><p>Finally, compile the database:</p><div class="informalexample"><pre class="programlisting" xml:space="preserve">
354# makeuserdb
355</pre></div><p>
356This command creates the actual database, <code class="filename">@userdb@.dat</code> and
357<code class="filename">@userdb@shadow.dat</code> from the plain text file
358<code class="filename">@userdb@</code>. Courier will now start accepting logins to this
359mailbox. Adding and removing mailboxes can be done while Courier is
360running.</p><p>
361Courier reads <code class="filename">@userdb@.dat</code> and
362<code class="filename">@userdb@shadow.dat</code> only. The plain text source,
363<code class="filename">@userdb@</code> is not read by Courier itself. Changes take
364effect
b0322a85 365only when <span class="command"><strong>makeuserdb</strong></span> runs.</p></div><div class="sect2"><div class="titlepage"><div><div><h3 class="title"><a id="userdbcomplex" shape="rect"> </a>Large virtual domain farm</h3></div></div></div><p>
d9898ee8 366The previous approach used a single flat file, <code class="filename">@userdb@</code>.
367This
368will work for up to a couple of hundred accounts.
369An slightly different approach can scale to thousands of
370domains and mailboxes.</p><p>
371Instead of creating a <code class="filename">@userdb@</code> file, create a
372subdirectory:</p><div class="informalexample"><pre class="programlisting" xml:space="preserve">
373# mkdir @userdb@
374# chmod 700 @userdb@
375</pre></div><p>
376Now, create <code class="filename">@userdb@/default</code>, containing pw2userdb's
377output
378for the vmail account, as previously described.</p><p>
379This time, you probably want to create all mailboxes for the same domain
380in a separate subdirectory:</p><div class="informalexample"><pre class="programlisting" xml:space="preserve">
381# su - vmail
382$ cd ~vmail
383$ mkdir -p domains/example-com
384$ mkdir domains/example-com/john
385$ maildirmake domains/example-com/john
386$ exit
387</pre></div><p>
388The idea is that all the maildirs for <code class="literal">@example.com</code> will
389now be found
390in <code class="filename">~vmail/domains/example-com</code>. All maildirs for
391<code class="literal">domain.org</code> will be in
392<code class="filename">~vmail/domains/domain.org</code>. The actual layout and naming
393conventions are entirely up to you to define.</p><p>Here's how configure <code class="filename">@userdb@</code>:</p><div class="informalexample"><pre class="programlisting" xml:space="preserve">
394$ userdb "example-com/john@example.com" set \
395 home=/home/vmail/domains/example-com/john \
396 uid=UUU gid=GGG</pre></div><p>
397This creates the file <code class="filename">@userdb@/example-com</code> (the first
ac40fd9e 398parameter to the <span class="command"><strong>userdb</strong></span> command), and appends a record named
d9898ee8 399"john@example.com". You will store all <code class="literal">userdb</code> entries for
400<code class="literal">@example.com</code> in the file
401<code class="filename">@userdb@/example-com</code>. All
402entries for <code class="literal">@domain.org</code> will be maintained in
403<code class="filename">@userdb@/domain-org</code>, and so on.</p><div class="informalexample"><pre class="programlisting" xml:space="preserve">
404$ userdbpw | userdb "example-com/john@example.com" set imappw
405</pre></div><p>
406This sets the IMAP access password for this account. Finally:</p><div class="informalexample"><pre class="programlisting" xml:space="preserve">
407$ makeuserdb
b0322a85 408</pre></div></div><div class="sect2"><div class="titlepage"><div><div><h3 class="title"><a id="moreuserdb" shape="rect"> </a>Beyond <code class="literal">userdb</code></h3></div></div></div><p>
d9898ee8 409<code class="literal">userdb</code> is a simple, straightforward solution that scales
410to a couple of thousand of mail accounts, depending on the hardware.
411Beyond that, one of database-based modules will need to be used,
412such as
413<code class="literal">authldap</code>,
414<code class="literal">authmysql</code>,
b0322a85 415<code class="literal">authsqlite</code>,
d9898ee8 416<code class="literal">authpgsql</code>.
417Since <code class="literal">userdb</code> is maintained as plain text files that
418are easily parsed by a script, migrating data from userdb will not be
b0322a85 419difficult.</p></div></div><div class="sect1"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a id="authmysql" shape="rect"> </a>The <code class="literal">authmysql</code> authentication module</h2></div></div></div><p>
d9898ee8 420This module reads
421the list of mail accounts and passwords from a table in a
422MySQL database.
423The <code class="filename">@authmysqlrc@</code> configuration file defines the
424particular details regarding the MySQL database and the schema of the
b0322a85 425mail account table.</p></div><div class="sect1"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a id="authpgsql" shape="rect"> </a>The <code class="literal">authpgsql</code> authentication module</h2></div></div></div><p>
d9898ee8 426This module reads
427the list of mail accounts and passwords from a table in a
428PostgreSQL database.
429The <code class="filename">@authpgsqlrc@</code> configuration file defines the
430particular details regarding the PostgreSQL database and the schema of the
b0322a85
CE
431mail account table.</p></div><div class="sect1"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a id="authsqlite" shape="rect"> </a>The <code class="literal">authsqlite</code> authentication module</h2></div></div></div><p>
432This module reads
433the list of mail accounts and passwords from a table in a
434SQLite database file.
435The <code class="filename">@authsqliterc@</code> configuration file defines the
436particular details regarding the SQLite database file and the schema of the
437mail account table.</p></div><div class="sect1"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a id="authldap" shape="rect"> </a>The <code class="literal">authldap</code> authentication module</h2></div></div></div><p>
d9898ee8 438This module reads
439the list of mail accounts and passwords from an LDAP directory.
440The <code class="filename">@authldaprc@</code> configuration file defines the
441particular details regarding the LDAP directory layout.</p><p>
0e333c05
CE
442A suggested LDAP schema can be found in the files
443<code class="filename">authldap.schema</code> and
444<code class="filename">authldap.ldif</code>,
d9898ee8 445which is included in Courier authentication library's source code, and
b0322a85 446may be installed on your system.</p></div><div class="sect1"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a id="authcustom" shape="rect"> </a><code class="literal">authcustom</code></h2></div></div></div><p>
d9898ee8 447This is a do-nothing module where custom authentication code
448can be added.
449This authentication module is just a stub that doesn't really do anything.
450It's purpose is to serve as a placeholder where custom authentication code
b0322a85 451can be easily implement.</p></div><div class="sect1"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a id="options" shape="rect"> </a>Account options</h2></div></div></div><p>
d9898ee8 452The authentication library has a facility for keep arbitrary
b0322a85
CE
453<span class="quote">“<span class="quote">name=value</span>”</span>-type settings,
454called <span class="quote">“<span class="quote">options</span>”</span>, for individual accounts. This feature is
d9898ee8 455only available with
456<code class="literal">userdb</code>,
b0322a85 457<code class="literal">LDAP</code>, <code class="literal">MySQL</code>, <code class="literal">SQLite</code> and
d9898ee8 458<code class="literal">PostgresSQL</code>
459modules. Individual account options are not supported with
460system-based authentication modules (password/shadow files, or PAM).</p><p>
b0322a85 461See
ac40fd9e 462<a class="ulink" href="auth_generic.html" target="_top" shape="rect"><span class="citerefentry"><span class="refentrytitle">auth_generic</span>(3)</span></a>
d9898ee8 463for a description of option names used by various Courier packages.
464Other applications can make up names for their own settings, and
465use them in the same way.</p><p>
466Account options are specified via the authentication modules in the
b0322a85 467following manner:</p><div class="variablelist"><dl class="variablelist"><dt><span class="term"><code class="literal">userdb</code></span></dt><dd><p>
ac40fd9e 468Use the <span class="command"><strong>userdb</strong></span> command to set a field called
d9898ee8 469"<code class="literal">options</code>". Example:</p><div class="informalexample"><pre class="programlisting" xml:space="preserve">
470userdb user1@example.com set options=disableimap=1,sharedgroup=44
471makeuserdb
472</pre></div><p>
473The option text string here is
474"<code class="literal">disableimap=1,sharedgroup=44</code>".
475It specifies two options.</p></dd><dt><span class="term"><code class="literal">LDAP</code></span></dt><dd><p>
476Account options are defined by the <code class="literal">LDAP_AUXOPTIONS</code>
477setting in the <code class="filename">authldaprc</code> configuration file.
478<code class="literal">LDAP_AUXOPTIONS</code> consists of a comma-separated list of
479"<code class="literal">attribute=setting</code>". "attribute" is the name of an LDAP
480attribute, and "setting" is the corresponding account setting name. The
481value of the attribute becomes the value of the setting. Unless you
482value your sanity, the names of LDAP attributes should be the same as
483the actual setting names (in which case "=setting" may be dropped and
484<code class="literal">LDAP_AUXOPTIONS</code> becomes a simple comma-separated list of
485supported settings), but they don't have to be.</p><p>
486<code class="literal">LDAP_AUXOPTIONS</code> is nothing more than a simple mapping
487of LDAP attributes to account settings. A <code class="literal">LDAP_AUXOPTIONS</code>
488of "shared=sharedgroup,disableimap" means that the LDAP attribute
489called "shared" contains the "sharedgroup" setting, as described
490previously; and an LDAP attribute of disableimap contains the setting
b0322a85
CE
491of the same name.</p></dd><dt><span class="term"><span class="application">MySQL</span>,
492<span class="application">SQLite</span>, and <span class="application">PostgreSQL</span></span></dt><dd><p>
493Account options are defined by <code class="literal">MYSQL_AUXOPTIONS_FIELD</code>,
494<code class="literal">SQLITE_AUXOPTIONS_FIELD</code>,
d9898ee8 495or <code class="literal">POSTGRESQL_AUXOPTIONS_FIELD</code>, in its corresponding
496configuration file. In the most simplest case, add a character field to
497the database, and put the field name into the
b0322a85
CE
498<code class="literal">MYSQL_AUXOPTIONS_FIELD</code>,
499<code class="literal">SQLITE_AUXOPTIONS_FIELD</code>, or
d9898ee8 500<code class="literal">POSTGRESQL_AUXOPTIONS_FIELD</code> configuration file setting.
501For each account, the character field should contain the literal option
502string. Yes, you'll just put "shared=sharedgroup,disableimap"
503literally, in that field.</p><p>
504Fortunately, there is a cleaner way to do this, which avoid driving
505a database designer batty. Keep in mind that the contents of
b0322a85 506<code class="literal">MYSQL_AUXOPTIONS_FIELD</code>/<code class="literal">SQLITE_AUXOPTIONS_FIELD</code>/<code class="literal">POSTGRESQL_AUXOPTIONS_FIELD</code>
d9898ee8 507are simply inserted directly into the SQL query that fetches the
b0322a85 508account information. MySQL, SQLite, and PostgreSQL have a rich SQL that can
d9898ee8 509be used to manufacture a suitable option string from plain,
510garden-variety, database fields. That is, you may define individual
511table fields like "disableimap", and "disablepop3", then provide a
512suitable (albeit ugly) SQL fragment that combines them together into
513the expected option string. An example of such an SQL string is
514provided in the comments portion of the configuration file.</p><div class="note" style="margin-left: 0.5in; margin-right: 0.5in;"><h3 class="title">Note</h3><p>
515When using the alternative custom query option, the option string
b0322a85
CE
516 is the last field that the custom SQL query should return.</p></div></dd></dl></div><div class="note" style="margin-left: 0.5in; margin-right: 0.5in;"><h3 class="title">Note</h3><p>
517The following list of account options is a combined list of implemented
518options supported by Courier, Courier-IMAP, and
519SqWebMail packages. Some of the following information is obviously
520not applicable for a particular package.
521The inapplicable bits should be obvious.</p></div><p>
522The following options are recognized by the various Courier
523packages:</p><div class="variablelist"><dl class="variablelist"><dt><span class="term"><code class="literal">disableimap=</code><em class="replaceable"><code>n</code></em></span></dt><dd><p>
524If "n" is 1, IMAP access to this account should be disabled.</p></dd><dt><span class="term"><code class="literal">disablepop3=</code><em class="replaceable"><code>n</code></em></span></dt><dd><p>
525If "n" is 1, POP3 access to this account should be disabled.</p></dd><dt><span class="term"><code class="literal">disableinsecureimap=</code><em class="replaceable"><code>n</code></em></span></dt><dd><p>
526If "n" is 1, unencrypted IMAP access to this account should be disabled.</p></dd><dt><span class="term"><code class="literal">disableinsecurepop3=</code><em class="replaceable"><code>n</code></em></span></dt><dd><p>
527If "n" is 1, unencrypted POP3 access to this account should be disabled.</p></dd><dt><span class="term"><code class="literal">disablewebmail=</code><em class="replaceable"><code>n</code></em></span></dt><dd><p>
528If "n" is 1, webmail access to this account should be disabled.</p></dd><dt><span class="term"><code class="literal">disableshared=</code><em class="replaceable"><code>n</code></em></span></dt><dd><p>
529If "n" is 1, this account should not have access to shared folders or be able
530to share its own folders with other people.</p></dd><dt><span class="term"><code class="literal">group=</code><em class="replaceable"><code>name</code></em></span></dt><dd><p>
531This option is used by Courier-IMAP in calculating access control lists.
532This option places the account as a member of access group
533<em class="replaceable"><code>name</code></em>.
534Instead of granting access rights on individual mail folders to individual
535accounts, the access rights can be granted to an access group
536<span class="quote">“<span class="quote">name</span>”</span>, and all members of this group get the specified access
537rights.</p><p>
538The access group name <span class="quote">“<span class="quote">administrators</span>”</span> is a reserved group.
539All accounts in the <code class="literal">administrators</code> group automatically
540receive all rights to all accessible folders.</p><div class="note" style="margin-left: 0.5in; margin-right: 0.5in;"><h3 class="title">Note</h3><p>
541This option may be specified multiple times to specify that the account
542belongs to multiple account groups.</p></div></dd><dt><span class="term"><code class="literal">sharedgroup=</code><em class="replaceable"><code>name</code></em></span></dt><dd><p>
543Another option used by Courier-IMAP.
544Append "name" to the name of the top level virtual shared folder
545index file. This setting restricts which virtual shared folders this
546account could possibly access (and that's on top of whatever else the
547access control lists say). See the virtual shared folder documentation
548for more information.</p><p>
549For technical reasons, group names may not include comma, tab, "/" or "|"
550characters.</p></dd></dl></div></div><div class="sect1"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a id="authtest" shape="rect"> </a>Running <span class="command"><strong>authtest</strong></span></h2></div></div></div><p>
ac40fd9e 551The <span class="command"><strong>authtest</strong></span> command may be used to verify that the
d9898ee8 552authentication library is working:</p><div class="informalexample"><pre class="programlisting" xml:space="preserve">
553authtest userid
554authtest userid password
555authtest userid password newpassword
556authenumerate</pre></div><p>
557Running
ac40fd9e 558<span class="command"><strong>authtest</strong></span>
d9898ee8 559with one argument should display the selected account's
560home directory, userid, groupid,
561and other related data.
562The second argument to
ac40fd9e 563<span class="command"><strong>authtest</strong></span>,
d9898ee8 564if supplied, specifies the account's password.
565The two argument form of
ac40fd9e 566<span class="command"><strong>authtest</strong></span>
d9898ee8 567validates the password, and displays an indication whether the given
568password is valid, or not.
569The three argument form of the
ac40fd9e 570<span class="command"><strong>authtest</strong></span>
d9898ee8 571command attemps to change the account's password.
572The second argument is the old password, the third argument is the
573new password.</p><p>
b0322a85
CE
574See <a class="ulink" href="README.authdebug.html" target="_top" shape="rect"><code class="filename">README.authdebug.html</code></a> for more information.</p><div class="sect2"><div class="titlepage"><div><div><h3 class="title"><a id="pwchange" shape="rect"> </a>Changing account passwords</h3></div></div></div><p>For the virtual domain modules (<code class="literal">authldap</code>,
575<code class="literal">authmysql</code>,
576<code class="literal">authsqlite</code>,
577<code class="literal">authpgsql</code> and friends) changing the
d9898ee8 578login is a no-brainer. The tricky situation is when SqWebMail uses system
579passwords to log in (the <code class="literal">authpwd</code>, <code class="literal">authshadow</code>, or
580<code class="literal">authpam</code> authentication module). Different systems use different
581ways to keep login passwords. Many systems use the traditional
582<code class="filename">/etc/passwd</code> and <code class="filename">/etc/shadow</code> files. Other systems
583use a binary database; other systems use NIS. And on some systems the
584password file lookup library is a wrapper that goes against an external LDAP
585directory, or a database. For maximum compatibility, SqWebMail changes login
ac40fd9e 586passwords by running the <span class="command"><strong>passwd</strong></span> command. This is the traditinal
587*nix command that changes login passwords. <span class="command"><strong>passwd</strong></span> is an
d9898ee8 588interactive command. It's normally run from a terminal.
589 SqWebMail uses an
ac40fd9e 590<span class="command"><strong>expect</strong></span> script - as mentioned in
d9898ee8 591the introduction - to answer interactive
ac40fd9e 592prompts from <span class="command"><strong>passwd</strong></span>. The <span class="command"><strong>expect</strong></span> script expects to
593get a plain, garden-variety, <span class="command"><strong>passwd</strong></span> command, which acts
d9898ee8 594something like this:</p><div class="informalexample"><pre class="programlisting" xml:space="preserve">
595 # passwd
596 Changing password for luser
597 (current) UNIX password: (old password typed here)
598 New UNIX password: (new password typed here)
599 Retype new UNIX password: (new password retyped here)
600 passwd: all authentication tokens updated successfully
601 #
602</pre></div><p>
ac40fd9e 603Systems that use a <span class="command"><strong>passwd</strong></span> command with very different prompts
604may find that the default <span class="command"><strong>expect</strong></span> script will fail. In which case
605it will be necessary to tweak the <span class="command"><strong>expect</strong></span> script to match the
606prompts from the system's <span class="command"><strong>passwd</strong></span> command.</p><p>
607Modern systems use a <span class="command"><strong>passwd</strong></span> command that rejects "bad"
d9898ee8 608passwords - passwords that are based on dictionary words, are too short, or
609are obvious for other reasons. When testing the ability to change
610system passwords be sure to use randomly-generated gibberish for the test
ac40fd9e 611passwords. Otherwise, the default <span class="command"><strong>expect</strong></span> script will
d9898ee8 612actually be
613working, but you won't be the wiser. For security reasons, the actual
ac40fd9e 614messages from <span class="command"><strong>passwd</strong></span> will not be shown by.</p><p>
615The <span class="command"><strong>expect</strong></span> script is installed as
d9898ee8 616<code class="filename">/usr/local/libexec/courier-authlib/authsystem.passwd</code>
b0322a85
CE
617(assuming default options to the <span class="command"><strong>configure</strong></span> script).</p></div></div><div class="sect1"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a id="internals" shape="rect"> </a>Authentication internals</h2></div></div></div><p>
618The following structure describes an authentication module:</p><div class="blockquote"><blockquote class="blockquote"><div class="example"><a id="authstaticinfo" shape="rect"> </a><p class="title"><strong>Example 1. struct authstaticinfo</strong></p><div class="example-contents"><pre class="programlisting" xml:space="preserve">
d9898ee8 619struct authstaticinfo {
620 const char *auth_name;
621 int (*auth_func)(const char *, const char *, char *, int,
622 int (*)(struct authinfo *, void *),
623 void *);
624 int (*auth_prefunc)(const char *, const char *,
625 int (*)(struct authinfo *, void *),
626 void *);
627 void (*auth_cleanupfunc)();
628 int (*auth_changepwd)(const char *, /* service */
629 const char *, /* userid */
630 const char *, /* oldpassword */
631 const char *); /* new password */
632
633 void (*auth_idle)();
634 /* Not null - gets called every 5 mins when we're idle */
635
636 void (*auth_enumerate)( void(*cb_func)(const char *name,
637 uid_t uid,
638 gid_t gid,
639 const char *homedir,
640 const char *maildir,
641 void *void_arg),
642 void *void_arg);
643 } ;
644</pre></div></div><br class="example-break" clear="none"/></blockquote></div><p>
645An authentication module is a shared library that defines a single function
646called
b0322a85
CE
647<span class="quote">“<span class="quote">courier_auth_<em class="replaceable"><code>NAME</code></em>_init</span>”</span>, where
648<span class="quote">“<span class="quote">NAME</span>”</span> is the name of the authentication module.
d9898ee8 649The shared library does not need to export any other symbols, this is the
650only function that needs to be exported.
651The function returns a pointer to the <span class="structname">authstaticinfo</span>
652structure.
653For example, the relevant code from the <code class="literal">authmysql</code> module is:
b0322a85 654</p><div class="blockquote"><blockquote class="blockquote"><div class="example"><a id="authmysqlex" shape="rect"> </a><p class="title"><strong>Example 2. authmysql</strong></p><div class="example-contents"><pre class="programlisting" xml:space="preserve">
d9898ee8 655static struct authstaticinfo authmysql_info={
656 "authmysql",
657 auth_mysql,
658 auth_mysql_pre,
659 auth_mysql_cleanup,
660 auth_mysql_changepw,
661 auth_mysql_cleanup,
662 auth_mysql_enumerate};
663
664
665struct authstaticinfo *courier_authmysql_init()
666{
667 return &amp;authmysql_info;
668}
669</pre></div></div><br class="example-break" clear="none"/></blockquote></div><p>
670<code class="function">auth_func</code> points to a function that handles an
b0322a85 671authentication request. The function is invoked as follows:</p><div class="blockquote"><blockquote class="blockquote"><div class="example"><a id="auth_func" shape="rect"> </a><p class="title"><strong>Example 3. auth_func</strong></p><div class="example-contents"><pre class="programlisting" xml:space="preserve">
d9898ee8 672int result=auth_func(const char *service, const char *authtype,
673 const char *authdata,
674 int (*callback_func)(struct authinfo *, void *),
675 void *callback_arg);
676</pre></div></div><br class="example-break" clear="none"/></blockquote></div><p>
b0322a85
CE
677<span class="quote">“<span class="quote">service</span>”</span> is the name of the service being authenticated,
678such as <span class="quote">“<span class="quote"><code class="literal">imap</code></span>”</span> or
679<span class="quote">“<span class="quote"><code class="literal">pop3</code></span>”</span>.
680<span class="quote">“<span class="quote">authtype</span>”</span> defines the authentication format,
681and <span class="quote">“<span class="quote">authdata</span>”</span> is the actual authentication request.</p><p>
d9898ee8 682Two authentication formats are defined at this time.
b0322a85
CE
683The <span class="quote">“<span class="quote">authtype</span>”</span> string is set to one of the following
684strings:</p><div class="variablelist"><dl class="variablelist"><dt><span class="term"><span class="quote">“<span class="quote">login</span>”</span></span></dt><dd><p>
d9898ee8 685Tradition userid/password authentication.
686<code class="literal">authdata</code> points to a string that consists of:
687the userid; a newline character; the password; a final newline
b0322a85 688character.</p></dd><dt><span class="term"><span class="quote">“<span class="quote">cram-md5</span>”</span>, or <span class="quote">“<span class="quote">cram-sha1</span>”</span></span></dt><dd><p>
d9898ee8 689Challenge/response authentication.
690<code class="literal">authdata</code> points to a string that consists of:
691the base64-encoded challenge; a newline character;
692the base64-encoded response string; and a final newline
693character. Furthermore, the base64-encoded response string consists of:
694the login ID, a space character, and the response as a hexadecimal
695string (yes, base64-encoding of the response string is not strictly
696necessary).</p></dd></dl></div><div class="note" style="margin-left: 0.5in; margin-right: 0.5in;"><h3 class="title">Note</h3><p>
697Not all authentication modules may implement all authentication formats.
698An authentication module that does not implement a particular authentication
699format should handle it the same way as an invalid login ID.</p></div><p>
700The authentication function should return a negative value if the login ID
701is invalid. The authentication library will try the next authentication
702module.</p><p>
703The authentication function should return a positive value if the login ID
704is valid, but the password is invalid. The authentication library will not
705try any more authentication modules.</p><p>
706Otherwise, the authentication module should call the
707<code class="function">callback_func</code> function, and return the same value that's
708returned by this function.</p><p>
709The authentication module should pass through <code class="literal">callback_arg</code>
710to the callback function as a second argument.
711The first argument is a pointer to the
712<span class="structname">authinfo</span> structure, which is described in detail
713in the
ac40fd9e 714<a class="ulink" href="auth_generic.html" target="_top" shape="rect"><span class="citerefentry"><span class="refentrytitle">auth_generic</span>(3)</span></a>
d9898ee8 715manual page.
716The authentication module is responsible for allocating this structure.
717After the callback function returns this structure can be deallocated.
718The authentication module initializes the following fields:</p><p>
719<code class="function">auth_pre_func</code> points to a function that obtains
b0322a85 720account information. The function is invoked as follows:</p><div class="blockquote"><blockquote class="blockquote"><div class="example"><a id="auth_pre_func" shape="rect"> </a><p class="title"><strong>Example 4. auth_pre_func</strong></p><div class="example-contents"><pre class="programlisting" xml:space="preserve">
d9898ee8 721int auth_pre_func(const char *user, const char *service,
722 int (*callback)(struct authinfo *, void *), void *arg);
723</pre></div></div><br class="example-break" clear="none"/></blockquote></div><p>
b0322a85 724This function does the same thing as <span class="quote">“<span class="quote">auth_func</span>”</span> except that
d9898ee8 725the password is not actually verified.
726If the account exists, the callback function is invoked with the
727same callback arguments.</p><p>
728<code class="function">auth_cleanup_func</code> points to a function that will be
729invoked just before the authentication module is uninstalled, giving it
730the opportunity for some last-minute cleanup.</p><p>
731<code class="function">auth_idle</code> points to a function that will be
732invoked when no authentication requests are received for a couple of minutes,
733giving the authentication module an opportunity to close any database
734connections, so that they do not get shut down by the server, for inactivity,
735resulting in an error the next time an authentication request is
736received.</p><p>
737<code class="function">auth_changepwd</code> points to a function that will be
b0322a85 738invoked to change a password on an account, as follows.</p><div class="blockquote"><blockquote class="blockquote"><div class="example"><a id="auth_changepwd" shape="rect"> </a><p class="title"><strong>Example 5. auth_changepwd</strong></p><div class="example-contents"><pre class="programlisting" xml:space="preserve">
d9898ee8 739int auth_changepwd(const char *service, const char *user,
740 const char *oldpw, const char *newpw);
741</pre></div></div><br class="example-break" clear="none"/></blockquote></div><p>
742<code class="literal">service</code> is the name of the service whose password is to
b0322a85 743be changed (such as <span class="quote">“<span class="quote">imap</span>”</span> or <span class="quote">“<span class="quote">pop3</span>”</span>).
d9898ee8 744<code class="function">auth_changepwd</code> should return 0 if the password was
745changed succesfully, a negative value if <code class="literal">user</code> is invalid
746(the next authentication module will be tried), or a positive value if
747the password change request failed (no more modules will be tried).</p><p>
748<code class="function">auth_enumerate</code> points to a function that enumerates
749the list of all login IDs known to the authentication module.
750The first argument <code class="function">auth_enumerate</code> is a callback
751function. <code class="function">auth_enumerate</code> invokes the callback
752function once for each login ID, supplying the login ID, the userid,
753groupid, home directory and maildir as arguments.
754The last argument to the callback function is passed through from the
755second argument to <code class="function">auth_enumerate</code>.</p><p>
756After enumerating all login IDs <code class="function">auth_enumerate</code> calls
757the callback function one last time, with a NULL pointer for the login ID,
758then returns. If an error is encountered while enumerating the login IDs,
759<code class="function">auth_enumerate</code> terminates without invoking
b0322a85 760the callback function with a NULL login ID.</p></div><div class="sect1"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a id="files" shape="rect"> </a>FILES</h2></div></div></div><p>
ac40fd9e 761<code class="filename"> @authdaemonrc@</code> - <span class="command"><strong>authdaemond</strong></span> configuration file</p><p>
762<code class="filename"> @authldaprc@</code> - <span class="command"><strong>authldap</strong></span> configuration file</p><p>
763<code class="filename"> @authmysqlrc@</code> - <span class="command"><strong>authmysql</strong></span> configuration file</p><p>
b0322a85
CE
764<code class="filename"> @authsqliterc@</code> - <span class="command"><strong>authsqlite</strong></span> configuration file</p><p>
765<code class="filename"> @authpgsqlrc@</code> - <span class="command"><strong>authpgsql</strong></span> configuration file</p></div><div class="sect1"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a id="seealso" shape="rect"> </a>SEE ALSO</h2></div></div></div><p>
ac40fd9e 766<a class="ulink" href="courier.html" target="_top" shape="rect"><span class="citerefentry"><span class="refentrytitle">courier</span>(8)</span></a>,
d50284c4 767
ac40fd9e 768<a class="ulink" href="userdb.html" target="_top" shape="rect"><span class="citerefentry"><span class="refentrytitle">userdb</span>(8)</span></a></p></div></div></body></html>