| 1 | /* |
| 2 | ** Copyright 1998 - 2004 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 "authstaticlist.h" |
| 20 | #include "courierauthdebug.h" |
| 21 | |
| 22 | static const char rcsid[]="$Id: authpwd.c,v 1.15 2004/11/14 02:58:16 mrsam Exp $"; |
| 23 | |
| 24 | extern int auth_pwd_pre(const char *userid, const char *service, |
| 25 | int (*callback)(struct authinfo *, void *), |
| 26 | void *arg); |
| 27 | extern void auth_pwd_enumerate( void(*cb_func)(const char *name, |
| 28 | uid_t uid, |
| 29 | gid_t gid, |
| 30 | const char *homedir, |
| 31 | const char *maildir, |
| 32 | const char *options, |
| 33 | void *void_arg), |
| 34 | void *void_arg); |
| 35 | |
| 36 | int auth_pwd(const char *service, const char *authtype, char *authdata, |
| 37 | int (*callback_func)(struct authinfo *, void *), |
| 38 | void *callback_arg) |
| 39 | { |
| 40 | const char *user, *pass; |
| 41 | |
| 42 | if (strcmp(authtype, AUTHTYPE_LOGIN) || |
| 43 | (user=strtok(authdata, "\n")) == 0 || |
| 44 | (pass=strtok(0, "\n")) == 0) |
| 45 | { |
| 46 | errno=EPERM; |
| 47 | return (-1); |
| 48 | } |
| 49 | |
| 50 | return auth_sys_common(&auth_pwd_pre, |
| 51 | user, |
| 52 | pass, |
| 53 | service, |
| 54 | callback_func, |
| 55 | callback_arg); |
| 56 | } |
| 57 | |
| 58 | static void auth_pwd_cleanup() |
| 59 | { |
| 60 | #if HAVE_ENDPWENT |
| 61 | |
| 62 | endpwent(); |
| 63 | #endif |
| 64 | } |
| 65 | |
| 66 | static struct authstaticinfo authpwd_info={ |
| 67 | "authpwd", |
| 68 | auth_pwd, |
| 69 | auth_pwd_pre, |
| 70 | auth_pwd_cleanup, |
| 71 | auth_syspasswd, |
| 72 | auth_pwd_cleanup, |
| 73 | auth_pwd_enumerate, |
| 74 | } ; |
| 75 | |
| 76 | |
| 77 | struct authstaticinfo *courier_authpwd_init() |
| 78 | { |
| 79 | return &authpwd_info; |
| 80 | } |