]> granicus.if.org Git - linux-pam/blob - modules/pam_pwdb/pam_pwdb.c
Relevant BUGIDs: 527965
[linux-pam] / modules / pam_pwdb / pam_pwdb.c
1 /*
2  * $Id$
3  *
4  * This is the single file that will be compiled for pam_unix.
5  * it includes each of the modules that have beed defined in the .-c
6  * files in this directory.
7  *
8  * It is a little ugly to do it this way, but it is a simple way of
9  * defining static functions only once, and yet keeping the separate
10  * files modular. If you can think of something better, please email
11  * Andrew Morgan <morgan@linux.kernel.org>
12  *
13  * See the end of this file for Copyright information.
14  */
15
16 static const char rcsid[] =
17 "$Id$\n"
18 " - PWDB Pluggable Authentication module. <morgan@linux.kernel.org>"
19 ;
20
21 /* #define DEBUG */
22
23 #include <security/_pam_aconf.h>
24
25 #include <sys/types.h>
26 #include <stdarg.h>
27 #include <stdlib.h>
28 #include <stdio.h>
29 #include <errno.h>
30 #include <string.h>
31 #include <syslog.h>
32 #include <time.h>       /* for time() */
33 #include <fcntl.h>
34 #include <ctype.h>
35
36 #include <sys/time.h>
37 #include <unistd.h>
38
39 #include <pwdb/pwdb_public.h>
40
41 /* indicate the following groups are defined */
42
43 #define PAM_SM_AUTH
44 #define PAM_SM_ACCOUNT
45 #define PAM_SM_SESSION
46 #define PAM_SM_PASSWORD
47
48 #include <security/_pam_macros.h>
49 #include <security/pam_modules.h>
50
51 #ifndef LINUX_PAM 
52 #include <security/pam_appl.h>
53 #endif  /* LINUX_PAM */
54
55 #include "./support.-c"
56
57 /*
58  * PAM framework looks for these entry-points to pass control to the
59  * authentication module.
60  */
61
62 #include "./pam_unix_auth.-c"
63
64 PAM_EXTERN int pam_sm_authenticate(pam_handle_t *pamh, int flags
65                                    , int argc, const char **argv)
66 {
67     unsigned int ctrl;
68     int retval;
69
70     D(("called."));
71
72     pwdb_start();
73     ctrl = set_ctrl(flags, argc, argv);
74     retval = _unix_auth( pamh, ctrl );
75     pwdb_end();
76
77     if ( on(UNIX_LIKE_AUTH, ctrl) ) {
78         D(("recording return code for next time [%d]", retval));
79         pam_set_data(pamh, "pwdb_setcred_return", (void *) retval, NULL);
80     }
81
82     D(("done. [%s]", pam_strerror(pamh, retval)));
83
84     return retval;
85 }
86
87 PAM_EXTERN int pam_sm_setcred(pam_handle_t *pamh, int flags
88                               , int argc, const char **argv)
89 {
90     unsigned int ctrl;
91     int retval;
92
93     D(("called."));
94
95     pwdb_start();
96     ctrl = set_ctrl(flags, argc, argv);
97     retval = _unix_set_credentials(pamh, ctrl);
98     pwdb_end();
99
100     if ( on(UNIX_LIKE_AUTH, ctrl) ) {
101         int *pretval = &retval;
102
103         D(("recovering return code from auth call"));
104         pam_get_data(pamh, "pwdb_setcred_return", (const void **) pretval);
105         D(("recovered data indicates that old retval was %d", retval));
106     }
107
108     return retval;
109 }
110
111 /*
112  * PAM framework looks for these entry-points to pass control to the
113  * account management module.
114  */
115
116 #include "./pam_unix_acct.-c"
117
118 PAM_EXTERN int pam_sm_acct_mgmt(pam_handle_t *pamh, int flags,
119                                 int argc, const char **argv)
120 {
121     unsigned int ctrl;
122     int retval;
123
124     D(("called."));
125
126     pwdb_start();
127     ctrl = set_ctrl(flags, argc, argv);
128     retval = _unix_acct_mgmt(pamh, ctrl);
129     pwdb_end();
130
131     D(("done."));
132
133     return retval;
134 }
135
136 /*
137  * PAM framework looks for these entry-points to pass control to the
138  * session module.
139  */
140  
141 #include "./pam_unix_sess.-c"
142
143 PAM_EXTERN int pam_sm_open_session(pam_handle_t *pamh, int flags,
144                                    int argc, const char **argv)
145 {
146     unsigned int ctrl;
147     int retval;
148
149     D(("called."));
150
151     pwdb_start();
152     ctrl = set_ctrl(flags, argc, argv);
153     retval = _unix_open_session(pamh, ctrl);
154     pwdb_end();
155
156     return retval;
157 }
158
159 PAM_EXTERN int pam_sm_close_session(pam_handle_t *pamh, int flags,
160                                     int argc, const char **argv)
161 {
162     unsigned int ctrl;
163     int retval;
164
165     D(("called."));
166
167     pwdb_start();
168     ctrl = set_ctrl(flags, argc, argv);
169     retval = _unix_close_session(pamh, ctrl);
170     pwdb_end();
171
172     return retval;
173 }
174
175 /*
176  * PAM framework looks for these entry-points to pass control to the
177  * password changing module.
178  */
179  
180 #include "./pam_unix_passwd.-c"
181
182 PAM_EXTERN int pam_sm_chauthtok(pam_handle_t *pamh, int flags,
183                                 int argc, const char **argv)
184 {
185     unsigned int ctrl;
186     int retval;
187
188     D(("called."));
189
190     pwdb_start();
191     ctrl = set_ctrl(flags, argc, argv);
192     retval = _unix_chauthtok(pamh, ctrl);
193     pwdb_end();
194
195     D(("done."));
196
197     return retval;
198 }
199
200 /* static module data */
201
202 #ifdef PAM_STATIC
203 struct pam_module _pam_pwdb_modstruct = {
204      "pam_pwdb",
205      pam_sm_authenticate,
206      pam_sm_setcred,
207      pam_sm_acct_mgmt,
208      pam_sm_open_session,
209      pam_sm_close_session,
210      pam_sm_chauthtok
211 };
212
213 #endif
214
215 /*
216  * Copyright (c) Andrew G. Morgan, 1996. All rights reserved
217  *
218  * Redistribution and use in source and binary forms, with or without
219  * modification, are permitted provided that the following conditions
220  * are met:
221  * 1. Redistributions of source code must retain the above copyright
222  *    notice, and the entire permission notice in its entirety,
223  *    including the disclaimer of warranties.
224  * 2. Redistributions in binary form must reproduce the above copyright
225  *    notice, this list of conditions and the following disclaimer in the
226  *    documentation and/or other materials provided with the distribution.
227  * 3. The name of the author may not be used to endorse or promote
228  *    products derived from this software without specific prior
229  *    written permission.
230  * 
231  * ALTERNATIVELY, this product may be distributed under the terms of
232  * the GNU Public License, in which case the provisions of the GPL are
233  * required INSTEAD OF the above restrictions.  (This clause is
234  * necessary due to a potential bad interaction between the GPL and
235  * the restrictions contained in a BSD-style copyright.)
236  * 
237  * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED
238  * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
239  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
240  * DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT,
241  * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
242  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
243  * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
244  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
245  * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
246  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
247  * OF THE POSSIBILITY OF SUCH DAMAGE.
248  */