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 | #if HAVE_UNISTD_H |
15 | #include <unistd.h> |
16 | #endif |
17 | |
18 | #include "auth.h" |
19 | #include "courierauthdebug.h" |
20 | |
21 | static const char rcsid[]="$Id: preauthpwd.c,v 1.8 2004/10/21 00:10:49 mrsam Exp $"; |
22 | |
23 | int auth_pwd_pre(const char *userid, const char *service, |
24 | int (*callback)(struct authinfo *, void *), |
25 | void *arg) |
26 | { |
27 | struct authinfo auth; |
28 | struct passwd *pw; |
29 | |
30 | memset(&auth, 0, sizeof(auth)); |
31 | |
32 | if ((pw=getpwnam(userid)) == 0) |
33 | { |
34 | if (errno == ENOMEM) return (1); |
35 | return (-1); |
36 | } |
37 | |
38 | auth.sysusername=userid; |
39 | auth.sysgroupid=pw->pw_gid; |
40 | auth.homedir=pw->pw_dir; |
41 | auth.address=userid; |
42 | auth.fullname=pw->pw_gecos; |
43 | auth.passwd=pw->pw_passwd; |
44 | |
45 | courier_authdebug_authinfo("DEBUG: authpwd: ", &auth, 0, pw->pw_passwd); |
46 | return ((*callback)(&auth, arg)); |
47 | } |