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