Mercurial > dovecot > original-hg > dovecot-1.2
annotate src/auth/passdb-vpopmail.c @ 3474:9096b7957413 HEAD
Removed direct config.h including. I'm not sure why it was done before,
probably to reduce compile times a few milliseconds. Ugly anyway..
author | Timo Sirainen <tss@iki.fi> |
---|---|
date | Tue, 12 Jul 2005 15:58:47 +0300 |
parents | 06fc33bcfa28 |
children | fda241fa5d77 |
rev | line source |
---|---|
1035
fe49ece0f3ea
We have now separate "userdb" and "passdb". They aren't tied to each others
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
1 /* Copyright (C) 2002-2003 Timo Sirainen */ |
fe49ece0f3ea
We have now separate "userdb" and "passdb". They aren't tied to each others
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
2 |
fe49ece0f3ea
We have now separate "userdb" and "passdb". They aren't tied to each others
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
3 /* Thanks to Courier-IMAP for showing how the vpopmail API should be used */ |
fe49ece0f3ea
We have now separate "userdb" and "passdb". They aren't tied to each others
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
4 |
3474
9096b7957413
Removed direct config.h including. I'm not sure why it was done before,
Timo Sirainen <tss@iki.fi>
parents:
3367
diff
changeset
|
5 #include "common.h" |
1035
fe49ece0f3ea
We have now separate "userdb" and "passdb". They aren't tied to each others
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
6 |
fe49ece0f3ea
We have now separate "userdb" and "passdb". They aren't tied to each others
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
7 #ifdef PASSDB_VPOPMAIL |
fe49ece0f3ea
We have now separate "userdb" and "passdb". They aren't tied to each others
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
8 |
fe49ece0f3ea
We have now separate "userdb" and "passdb". They aren't tied to each others
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
9 #include "safe-memset.h" |
fe49ece0f3ea
We have now separate "userdb" and "passdb". They aren't tied to each others
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
10 #include "passdb.h" |
2366
33c584ef528a
Support MD5 passwords. Patch by Pascal Malterre
Timo Sirainen <tss@iki.fi>
parents:
2132
diff
changeset
|
11 #include "password-scheme.h" |
1035
fe49ece0f3ea
We have now separate "userdb" and "passdb". They aren't tied to each others
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
12 |
fe49ece0f3ea
We have now separate "userdb" and "passdb". They aren't tied to each others
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
13 #include "userdb-vpopmail.h" |
fe49ece0f3ea
We have now separate "userdb" and "passdb". They aren't tied to each others
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
14 |
2132
91358abe5874
Added support for vpopmail pop-before-smtp relay
Timo Sirainen <tss@iki.fi>
parents:
2099
diff
changeset
|
15 #include <stdlib.h> |
91358abe5874
Added support for vpopmail pop-before-smtp relay
Timo Sirainen <tss@iki.fi>
parents:
2099
diff
changeset
|
16 |
3266 | 17 extern struct passdb_module passdb_vpopmail; |
18 | |
1046
561da07883b6
Async userdb and passdb interface.
Timo Sirainen <tss@iki.fi>
parents:
1035
diff
changeset
|
19 static void |
1075
f1401fa7ab03
auth process fixes, LDAP seems to be working (with the kludge define or
Timo Sirainen <tss@iki.fi>
parents:
1046
diff
changeset
|
20 vpopmail_verify_plain(struct auth_request *request, const char *password, |
f1401fa7ab03
auth process fixes, LDAP seems to be working (with the kludge define or
Timo Sirainen <tss@iki.fi>
parents:
1046
diff
changeset
|
21 verify_plain_callback_t *callback) |
1035
fe49ece0f3ea
We have now separate "userdb" and "passdb". They aren't tied to each others
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
22 { |
fe49ece0f3ea
We have now separate "userdb" and "passdb". They aren't tied to each others
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
23 char vpop_user[VPOPMAIL_LIMIT], vpop_domain[VPOPMAIL_LIMIT]; |
fe49ece0f3ea
We have now separate "userdb" and "passdb". They aren't tied to each others
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
24 struct vqpasswd *vpw; |
2366
33c584ef528a
Support MD5 passwords. Patch by Pascal Malterre
Timo Sirainen <tss@iki.fi>
parents:
2132
diff
changeset
|
25 const char *crypted_pass; |
33c584ef528a
Support MD5 passwords. Patch by Pascal Malterre
Timo Sirainen <tss@iki.fi>
parents:
2132
diff
changeset
|
26 const char *scheme; |
33c584ef528a
Support MD5 passwords. Patch by Pascal Malterre
Timo Sirainen <tss@iki.fi>
parents:
2132
diff
changeset
|
27 int ret; |
1035
fe49ece0f3ea
We have now separate "userdb" and "passdb". They aren't tied to each others
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
28 |
3069 | 29 vpw = vpopmail_lookup_vqp(request, vpop_user, vpop_domain); |
1046
561da07883b6
Async userdb and passdb interface.
Timo Sirainen <tss@iki.fi>
parents:
1035
diff
changeset
|
30 if (vpw == NULL) { |
1075
f1401fa7ab03
auth process fixes, LDAP seems to be working (with the kludge define or
Timo Sirainen <tss@iki.fi>
parents:
1046
diff
changeset
|
31 callback(PASSDB_RESULT_USER_UNKNOWN, request); |
1046
561da07883b6
Async userdb and passdb interface.
Timo Sirainen <tss@iki.fi>
parents:
1035
diff
changeset
|
32 return; |
561da07883b6
Async userdb and passdb interface.
Timo Sirainen <tss@iki.fi>
parents:
1035
diff
changeset
|
33 } |
1035
fe49ece0f3ea
We have now separate "userdb" and "passdb". They aren't tied to each others
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
34 |
1075
f1401fa7ab03
auth process fixes, LDAP seems to be working (with the kludge define or
Timo Sirainen <tss@iki.fi>
parents:
1046
diff
changeset
|
35 if (((vpw->pw_gid & NO_IMAP) != 0 && |
2781
e44a84dc947c
s/protocol/service/ in authentication
Timo Sirainen <tss@iki.fi>
parents:
2678
diff
changeset
|
36 strcmp(request->service, "IMAP") == 0) || |
1075
f1401fa7ab03
auth process fixes, LDAP seems to be working (with the kludge define or
Timo Sirainen <tss@iki.fi>
parents:
1046
diff
changeset
|
37 ((vpw->pw_gid & NO_POP) != 0 && |
2781
e44a84dc947c
s/protocol/service/ in authentication
Timo Sirainen <tss@iki.fi>
parents:
2678
diff
changeset
|
38 strcmp(request->service, "POP3") == 0)) { |
3069 | 39 auth_request_log_info(request, "vpopmail", |
40 "%s disabled", request->service); | |
1075
f1401fa7ab03
auth process fixes, LDAP seems to be working (with the kludge define or
Timo Sirainen <tss@iki.fi>
parents:
1046
diff
changeset
|
41 callback(PASSDB_RESULT_USER_DISABLED, request); |
1046
561da07883b6
Async userdb and passdb interface.
Timo Sirainen <tss@iki.fi>
parents:
1035
diff
changeset
|
42 return; |
1035
fe49ece0f3ea
We have now separate "userdb" and "passdb". They aren't tied to each others
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
43 } |
fe49ece0f3ea
We have now separate "userdb" and "passdb". They aren't tied to each others
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
44 |
3069 | 45 auth_request_log_debug(request, "vpopmail", |
46 "crypted password=%s", vpw->pw_passwd); | |
3036
fcecff14e470
Added authentication debugging logging.
Timo Sirainen <tss@iki.fi>
parents:
2942
diff
changeset
|
47 |
2366
33c584ef528a
Support MD5 passwords. Patch by Pascal Malterre
Timo Sirainen <tss@iki.fi>
parents:
2132
diff
changeset
|
48 crypted_pass = vpw->pw_passwd; |
33c584ef528a
Support MD5 passwords. Patch by Pascal Malterre
Timo Sirainen <tss@iki.fi>
parents:
2132
diff
changeset
|
49 scheme = password_get_scheme(&crypted_pass); |
3366 | 50 if (scheme == NULL) scheme = passdb_vpopmail.default_pass_scheme; |
3036
fcecff14e470
Added authentication debugging logging.
Timo Sirainen <tss@iki.fi>
parents:
2942
diff
changeset
|
51 |
2366
33c584ef528a
Support MD5 passwords. Patch by Pascal Malterre
Timo Sirainen <tss@iki.fi>
parents:
2132
diff
changeset
|
52 ret = password_verify(password, crypted_pass, scheme, request->user); |
33c584ef528a
Support MD5 passwords. Patch by Pascal Malterre
Timo Sirainen <tss@iki.fi>
parents:
2132
diff
changeset
|
53 |
1035
fe49ece0f3ea
We have now separate "userdb" and "passdb". They aren't tied to each others
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
54 safe_memset(vpw->pw_passwd, 0, strlen(vpw->pw_passwd)); |
2366
33c584ef528a
Support MD5 passwords. Patch by Pascal Malterre
Timo Sirainen <tss@iki.fi>
parents:
2132
diff
changeset
|
55 if (vpw->pw_clear_passwd != NULL) { |
33c584ef528a
Support MD5 passwords. Patch by Pascal Malterre
Timo Sirainen <tss@iki.fi>
parents:
2132
diff
changeset
|
56 safe_memset(vpw->pw_clear_passwd, 0, |
33c584ef528a
Support MD5 passwords. Patch by Pascal Malterre
Timo Sirainen <tss@iki.fi>
parents:
2132
diff
changeset
|
57 strlen(vpw->pw_clear_passwd)); |
33c584ef528a
Support MD5 passwords. Patch by Pascal Malterre
Timo Sirainen <tss@iki.fi>
parents:
2132
diff
changeset
|
58 } |
1035
fe49ece0f3ea
We have now separate "userdb" and "passdb". They aren't tied to each others
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
59 |
2366
33c584ef528a
Support MD5 passwords. Patch by Pascal Malterre
Timo Sirainen <tss@iki.fi>
parents:
2132
diff
changeset
|
60 if (ret <= 0) { |
33c584ef528a
Support MD5 passwords. Patch by Pascal Malterre
Timo Sirainen <tss@iki.fi>
parents:
2132
diff
changeset
|
61 if (ret < 0) { |
3069 | 62 auth_request_log_error(request, "vpopmail", |
63 "Unknown password scheme %s", scheme); | |
64 } else { | |
65 auth_request_log_info(request, "vpopmail", | |
66 "password mismatch"); | |
1075
f1401fa7ab03
auth process fixes, LDAP seems to be working (with the kludge define or
Timo Sirainen <tss@iki.fi>
parents:
1046
diff
changeset
|
67 } |
f1401fa7ab03
auth process fixes, LDAP seems to be working (with the kludge define or
Timo Sirainen <tss@iki.fi>
parents:
1046
diff
changeset
|
68 callback(PASSDB_RESULT_PASSWORD_MISMATCH, request); |
1046
561da07883b6
Async userdb and passdb interface.
Timo Sirainen <tss@iki.fi>
parents:
1035
diff
changeset
|
69 return; |
1035
fe49ece0f3ea
We have now separate "userdb" and "passdb". They aren't tied to each others
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
70 } |
fe49ece0f3ea
We have now separate "userdb" and "passdb". They aren't tied to each others
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
71 |
2132
91358abe5874
Added support for vpopmail pop-before-smtp relay
Timo Sirainen <tss@iki.fi>
parents:
2099
diff
changeset
|
72 #ifdef HAVE_VPOPMAIL_OPEN_SMTP_RELAY |
2781
e44a84dc947c
s/protocol/service/ in authentication
Timo Sirainen <tss@iki.fi>
parents:
2678
diff
changeset
|
73 if (strcmp(request->service, "POP3") == 0 || |
e44a84dc947c
s/protocol/service/ in authentication
Timo Sirainen <tss@iki.fi>
parents:
2678
diff
changeset
|
74 strcmp(request->service, "IMAP") == 0) { |
2132
91358abe5874
Added support for vpopmail pop-before-smtp relay
Timo Sirainen <tss@iki.fi>
parents:
2099
diff
changeset
|
75 const char *host = net_ip2addr(&request->remote_ip); |
91358abe5874
Added support for vpopmail pop-before-smtp relay
Timo Sirainen <tss@iki.fi>
parents:
2099
diff
changeset
|
76 if (host != NULL) { |
91358abe5874
Added support for vpopmail pop-before-smtp relay
Timo Sirainen <tss@iki.fi>
parents:
2099
diff
changeset
|
77 /* use putenv() directly rather than env_put() which |
91358abe5874
Added support for vpopmail pop-before-smtp relay
Timo Sirainen <tss@iki.fi>
parents:
2099
diff
changeset
|
78 would leak memory every time we got here. use a |
91358abe5874
Added support for vpopmail pop-before-smtp relay
Timo Sirainen <tss@iki.fi>
parents:
2099
diff
changeset
|
79 static buffer for putenv() as SUSv2 requirements |
91358abe5874
Added support for vpopmail pop-before-smtp relay
Timo Sirainen <tss@iki.fi>
parents:
2099
diff
changeset
|
80 would otherwise corrupt our environment later. */ |
91358abe5874
Added support for vpopmail pop-before-smtp relay
Timo Sirainen <tss@iki.fi>
parents:
2099
diff
changeset
|
81 static char ip_env[256]; |
91358abe5874
Added support for vpopmail pop-before-smtp relay
Timo Sirainen <tss@iki.fi>
parents:
2099
diff
changeset
|
82 |
91358abe5874
Added support for vpopmail pop-before-smtp relay
Timo Sirainen <tss@iki.fi>
parents:
2099
diff
changeset
|
83 i_snprintf(ip_env, sizeof(ip_env), |
91358abe5874
Added support for vpopmail pop-before-smtp relay
Timo Sirainen <tss@iki.fi>
parents:
2099
diff
changeset
|
84 "TCPREMOTEIP=%s", host); |
91358abe5874
Added support for vpopmail pop-before-smtp relay
Timo Sirainen <tss@iki.fi>
parents:
2099
diff
changeset
|
85 putenv(ip_env); |
91358abe5874
Added support for vpopmail pop-before-smtp relay
Timo Sirainen <tss@iki.fi>
parents:
2099
diff
changeset
|
86 open_smtp_relay(); |
91358abe5874
Added support for vpopmail pop-before-smtp relay
Timo Sirainen <tss@iki.fi>
parents:
2099
diff
changeset
|
87 } |
91358abe5874
Added support for vpopmail pop-before-smtp relay
Timo Sirainen <tss@iki.fi>
parents:
2099
diff
changeset
|
88 } |
91358abe5874
Added support for vpopmail pop-before-smtp relay
Timo Sirainen <tss@iki.fi>
parents:
2099
diff
changeset
|
89 #endif |
91358abe5874
Added support for vpopmail pop-before-smtp relay
Timo Sirainen <tss@iki.fi>
parents:
2099
diff
changeset
|
90 |
1075
f1401fa7ab03
auth process fixes, LDAP seems to be working (with the kludge define or
Timo Sirainen <tss@iki.fi>
parents:
1046
diff
changeset
|
91 callback(PASSDB_RESULT_OK, request); |
1035
fe49ece0f3ea
We have now separate "userdb" and "passdb". They aren't tied to each others
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
92 } |
fe49ece0f3ea
We have now separate "userdb" and "passdb". They aren't tied to each others
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
93 |
fe49ece0f3ea
We have now separate "userdb" and "passdb". They aren't tied to each others
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
94 static void vpopmail_deinit(void) |
fe49ece0f3ea
We have now separate "userdb" and "passdb". They aren't tied to each others
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
95 { |
fe49ece0f3ea
We have now separate "userdb" and "passdb". They aren't tied to each others
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
96 vclose(); |
fe49ece0f3ea
We have now separate "userdb" and "passdb". They aren't tied to each others
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
97 } |
fe49ece0f3ea
We have now separate "userdb" and "passdb". They aren't tied to each others
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
98 |
fe49ece0f3ea
We have now separate "userdb" and "passdb". They aren't tied to each others
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
99 struct passdb_module passdb_vpopmail = { |
2942
c7d426f8cb58
Added name variable for userdb_module and passdb_module and changed their
Timo Sirainen <tss@iki.fi>
parents:
2781
diff
changeset
|
100 "vpopmail", |
3166
e6a487d80288
Restructuring of auth code. Balancer auth processes were a bad idea. Usually
Timo Sirainen <tss@iki.fi>
parents:
3161
diff
changeset
|
101 "%u", "CRYPT", FALSE, |
2942
c7d426f8cb58
Added name variable for userdb_module and passdb_module and changed their
Timo Sirainen <tss@iki.fi>
parents:
2781
diff
changeset
|
102 |
2648
cc2e39912eb3
Added preinit() call to userdb/passdbs, which is called before dropping
Timo Sirainen <tss@iki.fi>
parents:
2366
diff
changeset
|
103 NULL, NULL, |
1035
fe49ece0f3ea
We have now separate "userdb" and "passdb". They aren't tied to each others
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
104 vpopmail_deinit, |
fe49ece0f3ea
We have now separate "userdb" and "passdb". They aren't tied to each others
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
105 |
fe49ece0f3ea
We have now separate "userdb" and "passdb". They aren't tied to each others
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
106 vpopmail_verify_plain, |
fe49ece0f3ea
We have now separate "userdb" and "passdb". They aren't tied to each others
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
107 NULL |
fe49ece0f3ea
We have now separate "userdb" and "passdb". They aren't tied to each others
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
108 }; |
fe49ece0f3ea
We have now separate "userdb" and "passdb". They aren't tied to each others
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
109 |
fe49ece0f3ea
We have now separate "userdb" and "passdb". They aren't tied to each others
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
110 #endif |