d9898ee8 |
1 | /* |
0fde1ce3 |
2 | ** Copyright 1998 - 2008 Double Precision, Inc. See COPYING for |
d9898ee8 |
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 <ctype.h> |
12 | #include <string.h> |
13 | #include <errno.h> |
14 | |
15 | #include "auth.h" |
16 | #include "authldap.h" |
17 | #include "authstaticlist.h" |
18 | #include "courierauthdebug.h" |
19 | |
0fde1ce3 |
20 | static const char rcsid[]="$Id: authldap.c,v 1.23 2008/07/10 02:43:55 mrsam Exp $"; |
d9898ee8 |
21 | |
22 | extern void auth_ldap_enumerate( void(*cb_func)(const char *name, |
23 | uid_t uid, |
24 | gid_t gid, |
25 | const char *homedir, |
26 | const char *maildir, |
27 | const char *options, |
28 | void *void_arg), |
29 | void *void_arg); |
30 | |
31 | static int auth_ldap_login(const char *service, char *authdata, |
32 | int (*callback_func)(struct authinfo *, void *), |
33 | void *callback_arg) |
34 | { |
35 | const char *user, *pass; |
36 | |
37 | if ((user=strtok(authdata, "\n")) == 0 || |
38 | (pass=strtok(0, "\n")) == 0) |
39 | { |
40 | DPRINTF("incomplete authentication data"); |
41 | errno=EPERM; |
42 | return (-1); |
43 | } |
44 | |
45 | return authldapcommon(service, user, pass, callback_func, |
46 | callback_arg); |
47 | } |
48 | |
d9898ee8 |
49 | #include "libhmac/hmac.h" |
50 | #include "cramlib.h" |
51 | |
52 | static int auth_ldap_cram(const char *service, |
53 | const char *authtype, char *authdata, |
54 | int (*callback_func)(struct authinfo *, void *), |
55 | void *callback_arg) |
56 | { |
57 | struct cram_callback_info cci; |
58 | |
59 | if (auth_get_cram(authtype, authdata, &cci)) |
60 | return (-1); |
61 | |
62 | cci.callback_func=callback_func; |
63 | cci.callback_arg=callback_arg; |
64 | |
65 | return authldapcommon(service, cci.user, 0, &auth_cram_callback, &cci); |
66 | } |
d9898ee8 |
67 | |
68 | int auth_ldap(const char *service, const char *authtype, char *authdata, |
69 | int (*callback_func)(struct authinfo *, void *), |
70 | void *callback_arg) |
71 | { |
72 | if (strcmp(authtype, AUTHTYPE_LOGIN) == 0) |
73 | return (auth_ldap_login(service, authdata, |
74 | callback_func, callback_arg)); |
75 | |
d9898ee8 |
76 | return (auth_ldap_cram(service, authtype, authdata, |
77 | callback_func, callback_arg)); |
d9898ee8 |
78 | } |
79 | |
80 | |
81 | extern int auth_ldap_pre(const char *userid, const char *service, |
82 | int (*callback)(struct authinfo *, void *), |
83 | void *arg); |
84 | |
85 | extern int auth_ldap_changepw(const char *, const char *, const char *, |
86 | const char *); |
87 | |
88 | static struct authstaticinfo authldap_info={ |
89 | "authldap", |
90 | auth_ldap, |
91 | auth_ldap_pre, |
92 | authldapclose, |
93 | auth_ldap_changepw, |
94 | authldapclose, |
95 | auth_ldap_enumerate}; |
96 | |
97 | |
98 | struct authstaticinfo *courier_authldap_init() |
99 | { |
100 | return &authldap_info; |
101 | } |