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 "authcustom.h" |
b0322a85 |
17 | #include "courierauthstaticlist.h" |
d9898ee8 |
18 | |
d9898ee8 |
19 | |
20 | static int auth_custom_login(const char *service, char *authdata, |
21 | int (*callback_func)(struct authinfo *, void *), |
22 | int *callback_arg) |
23 | { |
24 | const char *user, *pass; |
25 | |
26 | if ((user=strtok(authdata, "\n")) == 0 || |
27 | (pass=strtok(0, "\n")) == 0) |
28 | { |
29 | errno=EPERM; |
30 | return (-1); |
31 | } |
32 | |
33 | return authcustomcommon(user, pass, callback_func, callback_arg); |
34 | } |
35 | |
d9898ee8 |
36 | #include "libhmac/hmac.h" |
37 | #include "cramlib.h" |
38 | |
39 | static int auth_custom_cram(const char *service, |
40 | const char *authtype, |
41 | char *authdata, |
42 | int (*callback_func)(struct authinfo *, void *), |
43 | void *callback_arg) |
44 | { |
45 | struct cram_callback_info cci; |
46 | |
47 | if (auth_get_cram(authtype, authdata, &cci)) |
48 | return (-1); |
49 | |
50 | cci.callback_func=callback_func; |
51 | cci.callback_arg=callback_arg; |
52 | |
53 | return authcustomcommon(cci.user, 0, &auth_cram_callback, &cci); |
54 | } |
d9898ee8 |
55 | |
56 | int auth_custom(const char *service, const char *authtype, char *authdata, |
57 | int (*callback_func)(struct authinfo *, void *), |
58 | void *callback_arg) |
59 | { |
60 | if (strcmp(authtype, AUTHTYPE_LOGIN) == 0) |
61 | return (auth_custom_login(service, authdata, |
62 | callback_func, callback_arg)); |
63 | |
d9898ee8 |
64 | return (auth_custom_cram(service, authtype, authdata, |
65 | callback_func, callback_arg)); |
d9898ee8 |
66 | } |
67 | |
68 | |
69 | extern int auth_custom_pre(const char *userid, const char *service, |
70 | int (*callback)(struct authinfo *, void *), |
71 | void *arg); |
72 | |
73 | static int auth_custom_chgpwd(const char *service, |
74 | const char *uid, |
75 | const char *oldpwd, |
76 | const char *newpwd) |
77 | { |
78 | /* |
79 | ** Insert code to change the account's password here. |
80 | ** |
81 | ** return 0 if changed. |
82 | ** |
83 | ** return 1 if failed. |
84 | ** Set errno to EPERM if we had a temporary failure (such as invalid |
85 | ** old pwd). |
86 | ** |
87 | ** Set errno to EINVAL if we failed because we did not recognize uid. |
88 | */ |
89 | |
90 | errno=EINVAL; |
91 | return (-1); |
92 | } |
93 | |
94 | static void auth_custom_idle() |
95 | { |
96 | /* |
97 | ** Insert code to temporarily deallocate resources after remaining |
98 | ** idle (as part of authdaemond) for more than 5 minutes. |
99 | */ |
100 | } |
101 | |
102 | static struct authstaticinfo authcustom_info={ |
103 | "authcustom", |
104 | auth_custom, |
105 | auth_custom_pre, |
106 | authcustomclose, |
107 | auth_custom_chgpwd, |
108 | auth_custom_idle}; |
109 | |
110 | |
111 | struct authstaticinfo *courier_authcustom_init() |
112 | { |
113 | return &authcustom_info; |
114 | } |