d9898ee8 |
1 | /* |
2 | ** Copyright 1998 - 1999 Double Precision, Inc. See COPYING for |
3 | ** distribution information. |
4 | */ |
5 | |
6 | #if HAVE_CONFIG_H |
7 | #include "courier_auth_config.h" |
8 | #endif |
9 | #include <stdio.h> |
10 | #include <stdlib.h> |
11 | #include <string.h> |
12 | #include <errno.h> |
13 | #include <pwd.h> |
14 | #include "auth.h" |
15 | #include "courierauthdebug.h" |
16 | |
17 | #if HAVE_SHADOW_H |
18 | #include <shadow.h> |
19 | #endif |
20 | |
d9898ee8 |
21 | |
22 | int auth_pam_pre(const char *userid, const char *service, |
23 | int (*callback)(struct authinfo *, void *), |
24 | void *arg) |
25 | { |
26 | struct authinfo auth; |
27 | struct passwd *pw; |
28 | #if HAVE_GETSPENT |
29 | struct spwd *spw; |
30 | #endif |
31 | |
32 | memset(&auth, 0, sizeof(auth)); |
33 | |
34 | if ((pw=getpwnam(userid)) == 0) |
35 | { |
36 | if (errno == ENOMEM) return (1); |
37 | DPRINTF("authpam: username '%s' not found in password file", userid); |
38 | errno=EPERM; |
39 | return (-1); |
40 | } |
41 | |
42 | auth.sysusername=userid; |
43 | auth.sysgroupid=pw->pw_gid; |
44 | auth.homedir=pw->pw_dir; |
45 | auth.address=userid; |
46 | auth.fullname=pw->pw_gecos; |
47 | auth.passwd=pw->pw_passwd; |
48 | |
49 | #if HAVE_GETSPENT |
50 | if ((spw=getspnam(userid)) != 0) |
51 | auth.passwd=spw->sp_pwdp; |
52 | #endif |
53 | courier_authdebug_authinfo("DEBUG: authpam: ", &auth, 0, pw->pw_passwd); |
54 | |
55 | return ((*callback)(&auth, arg)); |
56 | } |