| 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 | |
| 23 | |
| 24 | int auth_pgsql_pre(const char *user, const char *service, |
| 25 | int (*callback)(struct authinfo *, void *), void *arg) |
| 26 | { |
| 27 | struct authpgsqluserinfo *authinfo; |
| 28 | struct authinfo aa; |
| 29 | |
| 30 | authinfo=auth_pgsql_getuserinfo(user, service); |
| 31 | |
| 32 | if (!authinfo) /* Fatal error - such as PgSQL being down */ |
| 33 | return (1); |
| 34 | |
| 35 | if (!authinfo->home) /* User not found */ |
| 36 | return (-1); |
| 37 | |
| 38 | memset(&aa, 0, sizeof(aa)); |
| 39 | |
| 40 | /*aa.sysusername=user;*/ |
| 41 | aa.sysuserid= &authinfo->uid; |
| 42 | aa.sysgroupid= authinfo->gid; |
| 43 | aa.homedir=authinfo->home; |
| 44 | aa.maildir=authinfo->maildir && authinfo->maildir[0] ? |
| 45 | authinfo->maildir:0; |
| 46 | aa.address=authinfo->username; |
| 47 | aa.passwd=authinfo->cryptpw; |
| 48 | aa.clearpasswd=authinfo->clearpw; |
| 49 | aa.fullname=authinfo->fullname; |
| 50 | aa.quota=authinfo->quota && authinfo->quota[0] ? |
| 51 | authinfo->quota:0; |
| 52 | aa.options=authinfo->options; |
| 53 | return ((*callback)(&aa, arg)); |
| 54 | } |