d9898ee8 |
1 | /* |
2 | ** Copyright 1998 - 2003 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 "authpgsql.h" |
20 | |
21 | |
22 | static const char rcsid[]="$Id: preauthpgsql.c,v 1.5 2004/11/25 15:08:27 mrsam Exp $"; |
23 | |
24 | |
25 | int auth_pgsql_pre(const char *user, const char *service, |
26 | int (*callback)(struct authinfo *, void *), void *arg) |
27 | { |
28 | struct authpgsqluserinfo *authinfo; |
29 | struct authinfo aa; |
30 | |
31 | authinfo=auth_pgsql_getuserinfo(user, service); |
32 | |
33 | if (!authinfo) /* Fatal error - such as PgSQL being down */ |
34 | return (1); |
35 | |
36 | if (!authinfo->home) /* User not found */ |
37 | return (-1); |
38 | |
39 | memset(&aa, 0, sizeof(aa)); |
40 | |
41 | /*aa.sysusername=user;*/ |
42 | aa.sysuserid= &authinfo->uid; |
43 | aa.sysgroupid= authinfo->gid; |
44 | aa.homedir=authinfo->home; |
45 | aa.maildir=authinfo->maildir && authinfo->maildir[0] ? |
46 | authinfo->maildir:0; |
47 | aa.address=authinfo->username; |
48 | aa.passwd=authinfo->cryptpw; |
49 | aa.clearpasswd=authinfo->clearpw; |
50 | aa.fullname=authinfo->fullname; |
51 | aa.quota=authinfo->quota && authinfo->quota[0] ? |
52 | authinfo->quota:0; |
53 | aa.options=authinfo->options; |
54 | return ((*callback)(&aa, arg)); |
55 | } |