| 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 "courierauthstaticlist.h" |
| 20 | #include "courierauthdebug.h" |
| 21 | |
| 22 | |
| 23 | |
| 24 | struct callback_info { |
| 25 | const char *pass; |
| 26 | int (*callback_func)(struct authinfo *, void *); |
| 27 | void *callback_arg; |
| 28 | }; |
| 29 | |
| 30 | static int check_pw(struct authinfo *a, void *v) |
| 31 | { |
| 32 | struct callback_info *ci=(struct callback_info *)v; |
| 33 | int rc; |
| 34 | |
| 35 | if (a->passwd == NULL) |
| 36 | { |
| 37 | DPRINTF("no password available to compare"); |
| 38 | errno=EPERM; |
| 39 | return (-1); |
| 40 | } |
| 41 | |
| 42 | if (authcheckpassword(ci->pass, a->passwd)) |
| 43 | { |
| 44 | errno=EPERM; |
| 45 | return (-1); |
| 46 | } |
| 47 | a->clearpasswd=ci->pass; |
| 48 | rc=(*ci->callback_func)(a, ci->callback_arg); |
| 49 | a->clearpasswd=NULL; |
| 50 | return rc; |
| 51 | } |
| 52 | |
| 53 | int auth_sys_common( int (*auth_pre_func)(const char *, |
| 54 | const char *, |
| 55 | int (*)(struct authinfo *, |
| 56 | void *), |
| 57 | void *), |
| 58 | const char *user, |
| 59 | const char *pass, |
| 60 | const char *service, |
| 61 | int (*callback_func)(struct authinfo *, void *), |
| 62 | void *callback_arg) |
| 63 | { |
| 64 | struct callback_info ci; |
| 65 | |
| 66 | ci.pass=pass; |
| 67 | ci.callback_func=callback_func; |
| 68 | ci.callback_arg=callback_arg; |
| 69 | return (*auth_pre_func)(user, service, check_pw, &ci); |
| 70 | } |
| 71 | |