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