| 1 | /* |
| 2 | ** Copyright 2000-2008 Double Precision, Inc. See COPYING for |
| 3 | ** distribution information. |
| 4 | */ |
| 5 | #if HAVE_CONFIG_H |
| 6 | #include "courier_auth_config.h" |
| 7 | #endif |
| 8 | #include <stdio.h> |
| 9 | #include <stdlib.h> |
| 10 | #include <string.h> |
| 11 | #include <errno.h> |
| 12 | #include <pwd.h> |
| 13 | #if HAVE_UNISTD_H |
| 14 | #include <unistd.h> |
| 15 | #endif |
| 16 | |
| 17 | #include "auth.h" |
| 18 | #include "authpgsql.h" |
| 19 | #include "courierauth.h" |
| 20 | #include "courierauthstaticlist.h" |
| 21 | #include "courierauthdebug.h" |
| 22 | #include "libhmac/hmac.h" |
| 23 | |
| 24 | extern void auth_pgsql_enumerate( void(*cb_func)(const char *name, |
| 25 | uid_t uid, |
| 26 | gid_t gid, |
| 27 | const char *homedir, |
| 28 | const char *maildir, |
| 29 | const char *options, |
| 30 | void *void_arg), |
| 31 | void *void_arg); |
| 32 | |
| 33 | static int auth_pgsql_cram(const char *service, |
| 34 | const char *authtype, char *authdata, |
| 35 | int (*callback_func)(struct authinfo *, void *), |
| 36 | void *callback_arg) |
| 37 | { |
| 38 | struct cram_callback_info cci; |
| 39 | |
| 40 | if (auth_get_cram(authtype, authdata, &cci)) |
| 41 | return (-1); |
| 42 | |
| 43 | cci.callback_func=callback_func; |
| 44 | cci.callback_arg=callback_arg; |
| 45 | |
| 46 | return auth_pgsql_pre(cci.user, service, &auth_cram_callback, &cci); |
| 47 | } |
| 48 | |
| 49 | int auth_pgsql(const char *service, const char *authtype, char *authdata, |
| 50 | int (*callback_func)(struct authinfo *, void *), |
| 51 | void *callback_arg) |
| 52 | { |
| 53 | if (strcmp(authtype, AUTHTYPE_LOGIN) == 0) |
| 54 | return (auth_pgsql_login(service, authdata, |
| 55 | callback_func, callback_arg)); |
| 56 | |
| 57 | return (auth_pgsql_cram(service, authtype, authdata, |
| 58 | callback_func, callback_arg)); |
| 59 | } |
| 60 | |
| 61 | extern int auth_pgsql_pre(const char *user, const char *service, |
| 62 | int (*callback)(struct authinfo *, void *), |
| 63 | void *arg); |
| 64 | |
| 65 | static struct authstaticinfo authpgsql_info={ |
| 66 | "authpgsql", |
| 67 | auth_pgsql, |
| 68 | auth_pgsql_pre, |
| 69 | auth_pgsql_cleanup, |
| 70 | auth_pgsql_changepw, |
| 71 | auth_pgsql_cleanup, |
| 72 | auth_pgsql_enumerate}; |
| 73 | |
| 74 | struct authstaticinfo *courier_authpgsql_init() |
| 75 | { |
| 76 | return &authpgsql_info; |
| 77 | } |