Mercurial > dovecot > original-hg > dovecot-1.2
annotate src/master/login-process.c @ 8331:8fb20b423f8b HEAD
Login processes: If auth_debug=yes, log about received unknown passdb extra fields.
author | Timo Sirainen <tss@iki.fi> |
---|---|
date | Sat, 25 Oct 2008 16:07:28 +0300 |
parents | 0db37acdc59f |
children | f9166a09423a |
rev | line source |
---|---|
7086
7ed926ed7aa4
Updated copyright notices to include year 2008.
Timo Sirainen <tss@iki.fi>
parents:
6940
diff
changeset
|
1 /* Copyright (c) 2002-2008 Dovecot authors, see the included COPYING file */ |
0 | 2 |
3 #include "common.h" | |
5887
3f2eb1b9c555
Support listening multiple sockets. SIGHUP also doesn't anymore recreate
Timo Sirainen <tss@iki.fi>
parents:
5846
diff
changeset
|
4 #include "array.h" |
532
3b53dd1280c6
I/O buffers now use real blocking instead of setting up a sub-ioloop to
Timo Sirainen <tss@iki.fi>
parents:
410
diff
changeset
|
5 #include "ioloop.h" |
5843
f655c4d4a419
Moved child process handling to child-process.[ch]. The hash table now uses
Timo Sirainen <tss@iki.fi>
parents:
5632
diff
changeset
|
6 #include "hash.h" |
0 | 7 #include "network.h" |
764
f57c52738f90
Renamed IBuffer and OBuffer to IStream and OStream which describes their
Timo Sirainen <tss@iki.fi>
parents:
747
diff
changeset
|
8 #include "ostream.h" |
0 | 9 #include "fdpass.h" |
727
8dd8ebe6bcac
We use close-on-exec flag now to make sure that master process closes the
Timo Sirainen <tss@iki.fi>
parents:
722
diff
changeset
|
10 #include "fd-close-on-exec.h" |
697
7814b29d0862
Created env_put() and env_clean() for a bit easier handling of environment
Timo Sirainen <tss@iki.fi>
parents:
666
diff
changeset
|
11 #include "env-util.h" |
0 | 12 #include "restrict-access.h" |
722
0438621d25ff
Added virtual memory size limits to processes. Default values are pretty
Timo Sirainen <tss@iki.fi>
parents:
699
diff
changeset
|
13 #include "restrict-process-size.h" |
5887
3f2eb1b9c555
Support listening multiple sockets. SIGHUP also doesn't anymore recreate
Timo Sirainen <tss@iki.fi>
parents:
5846
diff
changeset
|
14 #include "dup2-array.h" |
0 | 15 #include "login-process.h" |
16 #include "auth-process.h" | |
1055
a72bba3f8a55
Rewrote setting handling. Changed some existing settings also since POP3
Timo Sirainen <tss@iki.fi>
parents:
1039
diff
changeset
|
17 #include "mail-process.h" |
1035
fe49ece0f3ea
We have now separate "userdb" and "passdb". They aren't tied to each others
Timo Sirainen <tss@iki.fi>
parents:
1000
diff
changeset
|
18 #include "master-login-interface.h" |
2000
c7c19f5071c3
Write all logging through master process. Fixes problems with log rotation,
Timo Sirainen <tss@iki.fi>
parents:
1997
diff
changeset
|
19 #include "log.h" |
3901
0ae5f5b468b7
Put ssl-parameters file into login directory so it still can be accessed
Timo Sirainen <tss@iki.fi>
parents:
3889
diff
changeset
|
20 #include "ssl-init.h" |
0 | 21 |
22 #include <unistd.h> | |
23 #include <syslog.h> | |
4649
a3d6a3462745
Send inode number in login requests and verify that they match.
Timo Sirainen <tss@iki.fi>
parents:
4640
diff
changeset
|
24 #include <sys/stat.h> |
0 | 25 |
903
fd8888f6f037
Naming style changes, finally got tired of most of the typedefs. Also the
Timo Sirainen <tss@iki.fi>
parents:
876
diff
changeset
|
26 struct login_process { |
5843
f655c4d4a419
Moved child process handling to child-process.[ch]. The hash table now uses
Timo Sirainen <tss@iki.fi>
parents:
5632
diff
changeset
|
27 struct child_process process; |
f655c4d4a419
Moved child process handling to child-process.[ch]. The hash table now uses
Timo Sirainen <tss@iki.fi>
parents:
5632
diff
changeset
|
28 |
1055
a72bba3f8a55
Rewrote setting handling. Changed some existing settings also since POP3
Timo Sirainen <tss@iki.fi>
parents:
1039
diff
changeset
|
29 struct login_group *group; |
4538
9d9e72374164
Fixes to login process handling, especially with
Timo Sirainen <tss@iki.fi>
parents:
4388
diff
changeset
|
30 struct login_process *prev_prelogin, *next_prelogin; |
0 | 31 int refcount; |
32 | |
33 pid_t pid; | |
34 int fd; | |
903
fd8888f6f037
Naming style changes, finally got tired of most of the typedefs. Also the
Timo Sirainen <tss@iki.fi>
parents:
876
diff
changeset
|
35 struct io *io; |
fd8888f6f037
Naming style changes, finally got tired of most of the typedefs. Also the
Timo Sirainen <tss@iki.fi>
parents:
876
diff
changeset
|
36 struct ostream *output; |
4538
9d9e72374164
Fixes to login process handling, especially with
Timo Sirainen <tss@iki.fi>
parents:
4388
diff
changeset
|
37 enum master_login_state state; |
9d9e72374164
Fixes to login process handling, especially with
Timo Sirainen <tss@iki.fi>
parents:
4388
diff
changeset
|
38 |
925
2e649dec0f09
Auth and login processes send an "we're ok" reply at the end of
Timo Sirainen <tss@iki.fi>
parents:
903
diff
changeset
|
39 unsigned int initialized:1; |
0 | 40 unsigned int destroyed:1; |
4538
9d9e72374164
Fixes to login process handling, especially with
Timo Sirainen <tss@iki.fi>
parents:
4388
diff
changeset
|
41 unsigned int inetd_child:1; |
613
1906116a62ce
Finally support for handling each login connection in it's own process.
Timo Sirainen <tss@iki.fi>
parents:
596
diff
changeset
|
42 }; |
0 | 43 |
903
fd8888f6f037
Naming style changes, finally got tired of most of the typedefs. Also the
Timo Sirainen <tss@iki.fi>
parents:
876
diff
changeset
|
44 struct login_auth_request { |
fd8888f6f037
Naming style changes, finally got tired of most of the typedefs. Also the
Timo Sirainen <tss@iki.fi>
parents:
876
diff
changeset
|
45 struct login_process *process; |
1035
fe49ece0f3ea
We have now separate "userdb" and "passdb". They aren't tied to each others
Timo Sirainen <tss@iki.fi>
parents:
1000
diff
changeset
|
46 unsigned int tag; |
7928
9e226056a208
Send login command OK reply in IMAP/POP3 process.
Timo Sirainen <tss@iki.fi>
parents:
7927
diff
changeset
|
47 unsigned int login_tag; |
1035
fe49ece0f3ea
We have now separate "userdb" and "passdb". They aren't tied to each others
Timo Sirainen <tss@iki.fi>
parents:
1000
diff
changeset
|
48 |
7928
9e226056a208
Send login command OK reply in IMAP/POP3 process.
Timo Sirainen <tss@iki.fi>
parents:
7927
diff
changeset
|
49 struct mail_login_request mail_request; |
7927
2351a81ce699
If commands are pipelined after the login command, pass them to the
Timo Sirainen <tss@iki.fi>
parents:
7922
diff
changeset
|
50 unsigned char data[]; |
903
fd8888f6f037
Naming style changes, finally got tired of most of the typedefs. Also the
Timo Sirainen <tss@iki.fi>
parents:
876
diff
changeset
|
51 }; |
0 | 52 |
1273
2cf2e08a6ee9
Somewhat working code to support loading Dovecot from inetd and such. It
Timo Sirainen <tss@iki.fi>
parents:
1237
diff
changeset
|
53 static unsigned int auth_id_counter, login_pid_counter; |
903
fd8888f6f037
Naming style changes, finally got tired of most of the typedefs. Also the
Timo Sirainen <tss@iki.fi>
parents:
876
diff
changeset
|
54 static struct timeout *to; |
1273
2cf2e08a6ee9
Somewhat working code to support loading Dovecot from inetd and such. It
Timo Sirainen <tss@iki.fi>
parents:
1237
diff
changeset
|
55 static struct io *io_listen; |
4148
f60d73c96618
If master process runs out of file descriptors, try to handle it more nicely
Timo Sirainen <tss@iki.fi>
parents:
3901
diff
changeset
|
56 static bool logins_stalled = FALSE; |
613
1906116a62ce
Finally support for handling each login connection in it's own process.
Timo Sirainen <tss@iki.fi>
parents:
596
diff
changeset
|
57 |
1055
a72bba3f8a55
Rewrote setting handling. Changed some existing settings also since POP3
Timo Sirainen <tss@iki.fi>
parents:
1039
diff
changeset
|
58 static struct login_group *login_groups; |
0 | 59 |
4651
2fe8f6a0bc5b
If login process dies before initialization, stall creation of them instead
Timo Sirainen <tss@iki.fi>
parents:
4649
diff
changeset
|
60 static void login_processes_stall(void); |
903
fd8888f6f037
Naming style changes, finally got tired of most of the typedefs. Also the
Timo Sirainen <tss@iki.fi>
parents:
876
diff
changeset
|
61 static void login_process_destroy(struct login_process *p); |
fd8888f6f037
Naming style changes, finally got tired of most of the typedefs. Also the
Timo Sirainen <tss@iki.fi>
parents:
876
diff
changeset
|
62 static void login_process_unref(struct login_process *p); |
3863
55df57c028d4
Added "bool" type and changed all ints that were used as booleans to bool.
Timo Sirainen <tss@iki.fi>
parents:
3692
diff
changeset
|
63 static bool login_process_init_group(struct login_process *p); |
4148
f60d73c96618
If master process runs out of file descriptors, try to handle it more nicely
Timo Sirainen <tss@iki.fi>
parents:
3901
diff
changeset
|
64 static void login_processes_start_missing(void *context); |
0 | 65 |
1610
6850142c4e25
New configuration file code. Some syntax changes, but tries to be somewhat
Timo Sirainen <tss@iki.fi>
parents:
1506
diff
changeset
|
66 static void login_group_create(struct settings *set) |
1055
a72bba3f8a55
Rewrote setting handling. Changed some existing settings also since POP3
Timo Sirainen <tss@iki.fi>
parents:
1039
diff
changeset
|
67 { |
a72bba3f8a55
Rewrote setting handling. Changed some existing settings also since POP3
Timo Sirainen <tss@iki.fi>
parents:
1039
diff
changeset
|
68 struct login_group *group; |
a72bba3f8a55
Rewrote setting handling. Changed some existing settings also since POP3
Timo Sirainen <tss@iki.fi>
parents:
1039
diff
changeset
|
69 |
a72bba3f8a55
Rewrote setting handling. Changed some existing settings also since POP3
Timo Sirainen <tss@iki.fi>
parents:
1039
diff
changeset
|
70 group = i_new(struct login_group, 1); |
4631
f5d53a684856
SIGHUP caused memory corruption
Timo Sirainen <tss@iki.fi>
parents:
4630
diff
changeset
|
71 group->refcount = 1; |
1610
6850142c4e25
New configuration file code. Some syntax changes, but tries to be somewhat
Timo Sirainen <tss@iki.fi>
parents:
1506
diff
changeset
|
72 group->set = set; |
5843
f655c4d4a419
Moved child process handling to child-process.[ch]. The hash table now uses
Timo Sirainen <tss@iki.fi>
parents:
5632
diff
changeset
|
73 group->mail_process_type = set->protocol == MAIL_PROTOCOL_IMAP ? |
1610
6850142c4e25
New configuration file code. Some syntax changes, but tries to be somewhat
Timo Sirainen <tss@iki.fi>
parents:
1506
diff
changeset
|
74 PROCESS_TYPE_IMAP : PROCESS_TYPE_POP3; |
1055
a72bba3f8a55
Rewrote setting handling. Changed some existing settings also since POP3
Timo Sirainen <tss@iki.fi>
parents:
1039
diff
changeset
|
75 |
a72bba3f8a55
Rewrote setting handling. Changed some existing settings also since POP3
Timo Sirainen <tss@iki.fi>
parents:
1039
diff
changeset
|
76 group->next = login_groups; |
a72bba3f8a55
Rewrote setting handling. Changed some existing settings also since POP3
Timo Sirainen <tss@iki.fi>
parents:
1039
diff
changeset
|
77 login_groups = group; |
a72bba3f8a55
Rewrote setting handling. Changed some existing settings also since POP3
Timo Sirainen <tss@iki.fi>
parents:
1039
diff
changeset
|
78 } |
a72bba3f8a55
Rewrote setting handling. Changed some existing settings also since POP3
Timo Sirainen <tss@iki.fi>
parents:
1039
diff
changeset
|
79 |
4631
f5d53a684856
SIGHUP caused memory corruption
Timo Sirainen <tss@iki.fi>
parents:
4630
diff
changeset
|
80 static void login_group_unref(struct login_group *group) |
1055
a72bba3f8a55
Rewrote setting handling. Changed some existing settings also since POP3
Timo Sirainen <tss@iki.fi>
parents:
1039
diff
changeset
|
81 { |
4631
f5d53a684856
SIGHUP caused memory corruption
Timo Sirainen <tss@iki.fi>
parents:
4630
diff
changeset
|
82 i_assert(group->refcount > 0); |
f5d53a684856
SIGHUP caused memory corruption
Timo Sirainen <tss@iki.fi>
parents:
4630
diff
changeset
|
83 |
f5d53a684856
SIGHUP caused memory corruption
Timo Sirainen <tss@iki.fi>
parents:
4630
diff
changeset
|
84 if (--group->refcount > 0) |
f5d53a684856
SIGHUP caused memory corruption
Timo Sirainen <tss@iki.fi>
parents:
4630
diff
changeset
|
85 return; |
f5d53a684856
SIGHUP caused memory corruption
Timo Sirainen <tss@iki.fi>
parents:
4630
diff
changeset
|
86 |
1055
a72bba3f8a55
Rewrote setting handling. Changed some existing settings also since POP3
Timo Sirainen <tss@iki.fi>
parents:
1039
diff
changeset
|
87 i_free(group); |
a72bba3f8a55
Rewrote setting handling. Changed some existing settings also since POP3
Timo Sirainen <tss@iki.fi>
parents:
1039
diff
changeset
|
88 } |
a72bba3f8a55
Rewrote setting handling. Changed some existing settings also since POP3
Timo Sirainen <tss@iki.fi>
parents:
1039
diff
changeset
|
89 |
2736
0f31778d3c34
Changed dovecot-auth protocol to ASCII based. Should be easier now to write
Timo Sirainen <tss@iki.fi>
parents:
2691
diff
changeset
|
90 void auth_master_callback(const char *user, const char *const *args, |
4907
5b4c9b20eba0
Replaced void *context from a lot of callbacks with the actual context
Timo Sirainen <tss@iki.fi>
parents:
4740
diff
changeset
|
91 struct login_auth_request *request) |
0 | 92 { |
1035
fe49ece0f3ea
We have now separate "userdb" and "passdb". They aren't tied to each others
Timo Sirainen <tss@iki.fi>
parents:
1000
diff
changeset
|
93 struct master_login_reply master_reply; |
2329 | 94 ssize_t ret; |
0 | 95 |
4740
0a1fa29ac87f
inetd logins kept crashing dovecot master.
Timo Sirainen <tss@iki.fi>
parents:
4734
diff
changeset
|
96 memset(&master_reply, 0, sizeof(master_reply)); |
2736
0f31778d3c34
Changed dovecot-auth protocol to ASCII based. Should be easier now to write
Timo Sirainen <tss@iki.fi>
parents:
2691
diff
changeset
|
97 if (user == NULL) |
5846
21e529b8a701
Initial implementation for mail_max_user_connections setting.
Timo Sirainen <tss@iki.fi>
parents:
5843
diff
changeset
|
98 master_reply.status = MASTER_LOGIN_STATUS_INTERNAL_ERROR; |
7226
e6693a0ec8e1
Renamed T_FRAME_BEGIN/END to T_BEGIN/END. Removed T_FRAME() macro and
Timo Sirainen <tss@iki.fi>
parents:
7109
diff
changeset
|
99 else T_BEGIN { |
1055
a72bba3f8a55
Rewrote setting handling. Changed some existing settings also since POP3
Timo Sirainen <tss@iki.fi>
parents:
1039
diff
changeset
|
100 struct login_group *group = request->process->group; |
a72bba3f8a55
Rewrote setting handling. Changed some existing settings also since POP3
Timo Sirainen <tss@iki.fi>
parents:
1039
diff
changeset
|
101 |
5846
21e529b8a701
Initial implementation for mail_max_user_connections setting.
Timo Sirainen <tss@iki.fi>
parents:
5843
diff
changeset
|
102 master_reply.status = |
5843
f655c4d4a419
Moved child process handling to child-process.[ch]. The hash table now uses
Timo Sirainen <tss@iki.fi>
parents:
5632
diff
changeset
|
103 create_mail_process(group->mail_process_type, |
7928
9e226056a208
Send login command OK reply in IMAP/POP3 process.
Timo Sirainen <tss@iki.fi>
parents:
7927
diff
changeset
|
104 group->set, &request->mail_request, |
8092
29b623366e1e
Pass the created mail process PID back to login process so it can log it.
Timo Sirainen <tss@iki.fi>
parents:
8088
diff
changeset
|
105 user, args, request->data, FALSE, |
29b623366e1e
Pass the created mail process PID back to login process so it can log it.
Timo Sirainen <tss@iki.fi>
parents:
8088
diff
changeset
|
106 &master_reply.mail_pid); |
7226
e6693a0ec8e1
Renamed T_FRAME_BEGIN/END to T_BEGIN/END. Removed T_FRAME() macro and
Timo Sirainen <tss@iki.fi>
parents:
7109
diff
changeset
|
107 } T_END; |
0 | 108 |
109 /* reply to login */ | |
1035
fe49ece0f3ea
We have now separate "userdb" and "passdb". They aren't tied to each others
Timo Sirainen <tss@iki.fi>
parents:
1000
diff
changeset
|
110 master_reply.tag = request->login_tag; |
0 | 111 |
2329 | 112 ret = o_stream_send(request->process->output, &master_reply, |
113 sizeof(master_reply)); | |
114 if (ret != sizeof(master_reply)) { | |
115 if (ret >= 0) { | |
116 i_warning("Login process %s transmit buffer full, " | |
117 "killing..", dec2str(request->process->pid)); | |
118 } | |
1035
fe49ece0f3ea
We have now separate "userdb" and "passdb". They aren't tied to each others
Timo Sirainen <tss@iki.fi>
parents:
1000
diff
changeset
|
119 login_process_destroy(request->process); |
2329 | 120 } |
0 | 121 |
7928
9e226056a208
Send login command OK reply in IMAP/POP3 process.
Timo Sirainen <tss@iki.fi>
parents:
7927
diff
changeset
|
122 if (close(request->mail_request.fd) < 0) |
1055
a72bba3f8a55
Rewrote setting handling. Changed some existing settings also since POP3
Timo Sirainen <tss@iki.fi>
parents:
1039
diff
changeset
|
123 i_error("close(mail client) failed: %m"); |
1035
fe49ece0f3ea
We have now separate "userdb" and "passdb". They aren't tied to each others
Timo Sirainen <tss@iki.fi>
parents:
1000
diff
changeset
|
124 login_process_unref(request->process); |
0 | 125 i_free(request); |
126 } | |
127 | |
4538
9d9e72374164
Fixes to login process handling, especially with
Timo Sirainen <tss@iki.fi>
parents:
4388
diff
changeset
|
128 static void process_remove_from_prelogin_lists(struct login_process *p) |
9d9e72374164
Fixes to login process handling, especially with
Timo Sirainen <tss@iki.fi>
parents:
4388
diff
changeset
|
129 { |
9d9e72374164
Fixes to login process handling, especially with
Timo Sirainen <tss@iki.fi>
parents:
4388
diff
changeset
|
130 if (p->state != LOGIN_STATE_FULL_PRELOGINS) |
9d9e72374164
Fixes to login process handling, especially with
Timo Sirainen <tss@iki.fi>
parents:
4388
diff
changeset
|
131 return; |
9d9e72374164
Fixes to login process handling, especially with
Timo Sirainen <tss@iki.fi>
parents:
4388
diff
changeset
|
132 |
9d9e72374164
Fixes to login process handling, especially with
Timo Sirainen <tss@iki.fi>
parents:
4388
diff
changeset
|
133 if (p->prev_prelogin == NULL) |
9d9e72374164
Fixes to login process handling, especially with
Timo Sirainen <tss@iki.fi>
parents:
4388
diff
changeset
|
134 p->group->oldest_prelogin_process = p->next_prelogin; |
9d9e72374164
Fixes to login process handling, especially with
Timo Sirainen <tss@iki.fi>
parents:
4388
diff
changeset
|
135 else |
9d9e72374164
Fixes to login process handling, especially with
Timo Sirainen <tss@iki.fi>
parents:
4388
diff
changeset
|
136 p->prev_prelogin->next_prelogin = p->next_prelogin; |
9d9e72374164
Fixes to login process handling, especially with
Timo Sirainen <tss@iki.fi>
parents:
4388
diff
changeset
|
137 |
9d9e72374164
Fixes to login process handling, especially with
Timo Sirainen <tss@iki.fi>
parents:
4388
diff
changeset
|
138 if (p->next_prelogin == NULL) |
9d9e72374164
Fixes to login process handling, especially with
Timo Sirainen <tss@iki.fi>
parents:
4388
diff
changeset
|
139 p->group->newest_prelogin_process = p->prev_prelogin; |
9d9e72374164
Fixes to login process handling, especially with
Timo Sirainen <tss@iki.fi>
parents:
4388
diff
changeset
|
140 else |
9d9e72374164
Fixes to login process handling, especially with
Timo Sirainen <tss@iki.fi>
parents:
4388
diff
changeset
|
141 p->next_prelogin->prev_prelogin = p->prev_prelogin; |
9d9e72374164
Fixes to login process handling, especially with
Timo Sirainen <tss@iki.fi>
parents:
4388
diff
changeset
|
142 |
9d9e72374164
Fixes to login process handling, especially with
Timo Sirainen <tss@iki.fi>
parents:
4388
diff
changeset
|
143 p->prev_prelogin = p->next_prelogin = NULL; |
9d9e72374164
Fixes to login process handling, especially with
Timo Sirainen <tss@iki.fi>
parents:
4388
diff
changeset
|
144 } |
9d9e72374164
Fixes to login process handling, especially with
Timo Sirainen <tss@iki.fi>
parents:
4388
diff
changeset
|
145 |
9d9e72374164
Fixes to login process handling, especially with
Timo Sirainen <tss@iki.fi>
parents:
4388
diff
changeset
|
146 static void process_mark_nonlistening(struct login_process *p, |
9d9e72374164
Fixes to login process handling, especially with
Timo Sirainen <tss@iki.fi>
parents:
4388
diff
changeset
|
147 enum master_login_state new_state) |
614
e60620644af3
login_process_per_connection = yes scales now better when multiple users are
Timo Sirainen <tss@iki.fi>
parents:
613
diff
changeset
|
148 { |
4538
9d9e72374164
Fixes to login process handling, especially with
Timo Sirainen <tss@iki.fi>
parents:
4388
diff
changeset
|
149 if (p->group == NULL) |
9d9e72374164
Fixes to login process handling, especially with
Timo Sirainen <tss@iki.fi>
parents:
4388
diff
changeset
|
150 return; |
9d9e72374164
Fixes to login process handling, especially with
Timo Sirainen <tss@iki.fi>
parents:
4388
diff
changeset
|
151 |
9d9e72374164
Fixes to login process handling, especially with
Timo Sirainen <tss@iki.fi>
parents:
4388
diff
changeset
|
152 if (p->state == LOGIN_STATE_LISTENING) |
9d9e72374164
Fixes to login process handling, especially with
Timo Sirainen <tss@iki.fi>
parents:
4388
diff
changeset
|
153 p->group->listening_processes--; |
9d9e72374164
Fixes to login process handling, especially with
Timo Sirainen <tss@iki.fi>
parents:
4388
diff
changeset
|
154 |
9d9e72374164
Fixes to login process handling, especially with
Timo Sirainen <tss@iki.fi>
parents:
4388
diff
changeset
|
155 if (new_state == LOGIN_STATE_FULL_PRELOGINS) { |
9d9e72374164
Fixes to login process handling, especially with
Timo Sirainen <tss@iki.fi>
parents:
4388
diff
changeset
|
156 /* add to prelogin list */ |
9d9e72374164
Fixes to login process handling, especially with
Timo Sirainen <tss@iki.fi>
parents:
4388
diff
changeset
|
157 i_assert(p->state != new_state); |
9d9e72374164
Fixes to login process handling, especially with
Timo Sirainen <tss@iki.fi>
parents:
4388
diff
changeset
|
158 |
9d9e72374164
Fixes to login process handling, especially with
Timo Sirainen <tss@iki.fi>
parents:
4388
diff
changeset
|
159 p->prev_prelogin = p->group->newest_prelogin_process; |
9d9e72374164
Fixes to login process handling, especially with
Timo Sirainen <tss@iki.fi>
parents:
4388
diff
changeset
|
160 if (p->group->newest_prelogin_process == NULL) |
9d9e72374164
Fixes to login process handling, especially with
Timo Sirainen <tss@iki.fi>
parents:
4388
diff
changeset
|
161 p->group->oldest_prelogin_process = p; |
9d9e72374164
Fixes to login process handling, especially with
Timo Sirainen <tss@iki.fi>
parents:
4388
diff
changeset
|
162 else |
9d9e72374164
Fixes to login process handling, especially with
Timo Sirainen <tss@iki.fi>
parents:
4388
diff
changeset
|
163 p->group->newest_prelogin_process->next_prelogin = p; |
9d9e72374164
Fixes to login process handling, especially with
Timo Sirainen <tss@iki.fi>
parents:
4388
diff
changeset
|
164 p->group->newest_prelogin_process = p; |
9d9e72374164
Fixes to login process handling, especially with
Timo Sirainen <tss@iki.fi>
parents:
4388
diff
changeset
|
165 } else { |
9d9e72374164
Fixes to login process handling, especially with
Timo Sirainen <tss@iki.fi>
parents:
4388
diff
changeset
|
166 process_remove_from_prelogin_lists(p); |
9d9e72374164
Fixes to login process handling, especially with
Timo Sirainen <tss@iki.fi>
parents:
4388
diff
changeset
|
167 } |
9d9e72374164
Fixes to login process handling, especially with
Timo Sirainen <tss@iki.fi>
parents:
4388
diff
changeset
|
168 } |
9d9e72374164
Fixes to login process handling, especially with
Timo Sirainen <tss@iki.fi>
parents:
4388
diff
changeset
|
169 |
9d9e72374164
Fixes to login process handling, especially with
Timo Sirainen <tss@iki.fi>
parents:
4388
diff
changeset
|
170 static void process_mark_listening(struct login_process *p) |
9d9e72374164
Fixes to login process handling, especially with
Timo Sirainen <tss@iki.fi>
parents:
4388
diff
changeset
|
171 { |
9d9e72374164
Fixes to login process handling, especially with
Timo Sirainen <tss@iki.fi>
parents:
4388
diff
changeset
|
172 if (p->group == NULL) |
9d9e72374164
Fixes to login process handling, especially with
Timo Sirainen <tss@iki.fi>
parents:
4388
diff
changeset
|
173 return; |
9d9e72374164
Fixes to login process handling, especially with
Timo Sirainen <tss@iki.fi>
parents:
4388
diff
changeset
|
174 |
9d9e72374164
Fixes to login process handling, especially with
Timo Sirainen <tss@iki.fi>
parents:
4388
diff
changeset
|
175 if (p->state != LOGIN_STATE_LISTENING) |
9d9e72374164
Fixes to login process handling, especially with
Timo Sirainen <tss@iki.fi>
parents:
4388
diff
changeset
|
176 p->group->listening_processes++; |
9d9e72374164
Fixes to login process handling, especially with
Timo Sirainen <tss@iki.fi>
parents:
4388
diff
changeset
|
177 |
9d9e72374164
Fixes to login process handling, especially with
Timo Sirainen <tss@iki.fi>
parents:
4388
diff
changeset
|
178 process_remove_from_prelogin_lists(p); |
9d9e72374164
Fixes to login process handling, especially with
Timo Sirainen <tss@iki.fi>
parents:
4388
diff
changeset
|
179 } |
9d9e72374164
Fixes to login process handling, especially with
Timo Sirainen <tss@iki.fi>
parents:
4388
diff
changeset
|
180 |
4651
2fe8f6a0bc5b
If login process dies before initialization, stall creation of them instead
Timo Sirainen <tss@iki.fi>
parents:
4649
diff
changeset
|
181 static void login_process_set_initialized(struct login_process *p) |
2fe8f6a0bc5b
If login process dies before initialization, stall creation of them instead
Timo Sirainen <tss@iki.fi>
parents:
4649
diff
changeset
|
182 { |
2fe8f6a0bc5b
If login process dies before initialization, stall creation of them instead
Timo Sirainen <tss@iki.fi>
parents:
4649
diff
changeset
|
183 p->initialized = TRUE; |
2fe8f6a0bc5b
If login process dies before initialization, stall creation of them instead
Timo Sirainen <tss@iki.fi>
parents:
4649
diff
changeset
|
184 |
2fe8f6a0bc5b
If login process dies before initialization, stall creation of them instead
Timo Sirainen <tss@iki.fi>
parents:
4649
diff
changeset
|
185 if (logins_stalled) { |
2fe8f6a0bc5b
If login process dies before initialization, stall creation of them instead
Timo Sirainen <tss@iki.fi>
parents:
4649
diff
changeset
|
186 /* processes were created successfully */ |
2fe8f6a0bc5b
If login process dies before initialization, stall creation of them instead
Timo Sirainen <tss@iki.fi>
parents:
4649
diff
changeset
|
187 i_info("Created login processes successfully, unstalling"); |
2fe8f6a0bc5b
If login process dies before initialization, stall creation of them instead
Timo Sirainen <tss@iki.fi>
parents:
4649
diff
changeset
|
188 |
2fe8f6a0bc5b
If login process dies before initialization, stall creation of them instead
Timo Sirainen <tss@iki.fi>
parents:
4649
diff
changeset
|
189 logins_stalled = FALSE; |
2fe8f6a0bc5b
If login process dies before initialization, stall creation of them instead
Timo Sirainen <tss@iki.fi>
parents:
4649
diff
changeset
|
190 timeout_remove(&to); |
2fe8f6a0bc5b
If login process dies before initialization, stall creation of them instead
Timo Sirainen <tss@iki.fi>
parents:
4649
diff
changeset
|
191 to = timeout_add(1000, login_processes_start_missing, NULL); |
2fe8f6a0bc5b
If login process dies before initialization, stall creation of them instead
Timo Sirainen <tss@iki.fi>
parents:
4649
diff
changeset
|
192 } |
2fe8f6a0bc5b
If login process dies before initialization, stall creation of them instead
Timo Sirainen <tss@iki.fi>
parents:
4649
diff
changeset
|
193 } |
2fe8f6a0bc5b
If login process dies before initialization, stall creation of them instead
Timo Sirainen <tss@iki.fi>
parents:
4649
diff
changeset
|
194 |
4538
9d9e72374164
Fixes to login process handling, especially with
Timo Sirainen <tss@iki.fi>
parents:
4388
diff
changeset
|
195 static void |
9d9e72374164
Fixes to login process handling, especially with
Timo Sirainen <tss@iki.fi>
parents:
4388
diff
changeset
|
196 login_process_set_state(struct login_process *p, enum master_login_state state) |
9d9e72374164
Fixes to login process handling, especially with
Timo Sirainen <tss@iki.fi>
parents:
4388
diff
changeset
|
197 { |
9d9e72374164
Fixes to login process handling, especially with
Timo Sirainen <tss@iki.fi>
parents:
4388
diff
changeset
|
198 if (state == p->state || state > LOGIN_STATE_COUNT || |
9d9e72374164
Fixes to login process handling, especially with
Timo Sirainen <tss@iki.fi>
parents:
4388
diff
changeset
|
199 (state < p->state && p->group->set->login_process_per_connection)) { |
9d9e72374164
Fixes to login process handling, especially with
Timo Sirainen <tss@iki.fi>
parents:
4388
diff
changeset
|
200 i_error("login: tried to change state %d -> %d " |
9d9e72374164
Fixes to login process handling, especially with
Timo Sirainen <tss@iki.fi>
parents:
4388
diff
changeset
|
201 "(if you can't login at all, see src/lib/fdpass.c)", |
9d9e72374164
Fixes to login process handling, especially with
Timo Sirainen <tss@iki.fi>
parents:
4388
diff
changeset
|
202 p->state, state); |
4640
f5772851ac91
If login process sends wrong state information, restart it.
Timo Sirainen <tss@iki.fi>
parents:
4632
diff
changeset
|
203 login_process_destroy(p); |
614
e60620644af3
login_process_per_connection = yes scales now better when multiple users are
Timo Sirainen <tss@iki.fi>
parents:
613
diff
changeset
|
204 return; |
e60620644af3
login_process_per_connection = yes scales now better when multiple users are
Timo Sirainen <tss@iki.fi>
parents:
613
diff
changeset
|
205 } |
e60620644af3
login_process_per_connection = yes scales now better when multiple users are
Timo Sirainen <tss@iki.fi>
parents:
613
diff
changeset
|
206 |
4538
9d9e72374164
Fixes to login process handling, especially with
Timo Sirainen <tss@iki.fi>
parents:
4388
diff
changeset
|
207 if (state == LOGIN_STATE_LISTENING) { |
9d9e72374164
Fixes to login process handling, especially with
Timo Sirainen <tss@iki.fi>
parents:
4388
diff
changeset
|
208 process_mark_listening(p); |
9d9e72374164
Fixes to login process handling, especially with
Timo Sirainen <tss@iki.fi>
parents:
4388
diff
changeset
|
209 } else { |
9d9e72374164
Fixes to login process handling, especially with
Timo Sirainen <tss@iki.fi>
parents:
4388
diff
changeset
|
210 process_mark_nonlistening(p, state); |
9d9e72374164
Fixes to login process handling, especially with
Timo Sirainen <tss@iki.fi>
parents:
4388
diff
changeset
|
211 } |
1275
af685269ead0
login: Wait until we're connected to auth process before executing command
Timo Sirainen <tss@iki.fi>
parents:
1273
diff
changeset
|
212 |
4538
9d9e72374164
Fixes to login process handling, especially with
Timo Sirainen <tss@iki.fi>
parents:
4388
diff
changeset
|
213 p->state = state; |
1275
af685269ead0
login: Wait until we're connected to auth process before executing command
Timo Sirainen <tss@iki.fi>
parents:
1273
diff
changeset
|
214 } |
614
e60620644af3
login_process_per_connection = yes scales now better when multiple users are
Timo Sirainen <tss@iki.fi>
parents:
613
diff
changeset
|
215 |
1610
6850142c4e25
New configuration file code. Some syntax changes, but tries to be somewhat
Timo Sirainen <tss@iki.fi>
parents:
1506
diff
changeset
|
216 static void login_process_groups_create(void) |
6850142c4e25
New configuration file code. Some syntax changes, but tries to be somewhat
Timo Sirainen <tss@iki.fi>
parents:
1506
diff
changeset
|
217 { |
6850142c4e25
New configuration file code. Some syntax changes, but tries to be somewhat
Timo Sirainen <tss@iki.fi>
parents:
1506
diff
changeset
|
218 struct server_settings *server; |
6850142c4e25
New configuration file code. Some syntax changes, but tries to be somewhat
Timo Sirainen <tss@iki.fi>
parents:
1506
diff
changeset
|
219 |
6850142c4e25
New configuration file code. Some syntax changes, but tries to be somewhat
Timo Sirainen <tss@iki.fi>
parents:
1506
diff
changeset
|
220 for (server = settings_root; server != NULL; server = server->next) { |
6850142c4e25
New configuration file code. Some syntax changes, but tries to be somewhat
Timo Sirainen <tss@iki.fi>
parents:
1506
diff
changeset
|
221 if (server->imap != NULL) |
6850142c4e25
New configuration file code. Some syntax changes, but tries to be somewhat
Timo Sirainen <tss@iki.fi>
parents:
1506
diff
changeset
|
222 login_group_create(server->imap); |
6850142c4e25
New configuration file code. Some syntax changes, but tries to be somewhat
Timo Sirainen <tss@iki.fi>
parents:
1506
diff
changeset
|
223 if (server->pop3 != NULL) |
6850142c4e25
New configuration file code. Some syntax changes, but tries to be somewhat
Timo Sirainen <tss@iki.fi>
parents:
1506
diff
changeset
|
224 login_group_create(server->pop3); |
6850142c4e25
New configuration file code. Some syntax changes, but tries to be somewhat
Timo Sirainen <tss@iki.fi>
parents:
1506
diff
changeset
|
225 } |
6850142c4e25
New configuration file code. Some syntax changes, but tries to be somewhat
Timo Sirainen <tss@iki.fi>
parents:
1506
diff
changeset
|
226 } |
6850142c4e25
New configuration file code. Some syntax changes, but tries to be somewhat
Timo Sirainen <tss@iki.fi>
parents:
1506
diff
changeset
|
227 |
6850142c4e25
New configuration file code. Some syntax changes, but tries to be somewhat
Timo Sirainen <tss@iki.fi>
parents:
1506
diff
changeset
|
228 static struct login_group * |
6850142c4e25
New configuration file code. Some syntax changes, but tries to be somewhat
Timo Sirainen <tss@iki.fi>
parents:
1506
diff
changeset
|
229 login_group_process_find(const char *name, enum mail_protocol protocol) |
1275
af685269ead0
login: Wait until we're connected to auth process before executing command
Timo Sirainen <tss@iki.fi>
parents:
1273
diff
changeset
|
230 { |
af685269ead0
login: Wait until we're connected to auth process before executing command
Timo Sirainen <tss@iki.fi>
parents:
1273
diff
changeset
|
231 struct login_group *group; |
af685269ead0
login: Wait until we're connected to auth process before executing command
Timo Sirainen <tss@iki.fi>
parents:
1273
diff
changeset
|
232 |
1610
6850142c4e25
New configuration file code. Some syntax changes, but tries to be somewhat
Timo Sirainen <tss@iki.fi>
parents:
1506
diff
changeset
|
233 if (login_groups == NULL) |
6850142c4e25
New configuration file code. Some syntax changes, but tries to be somewhat
Timo Sirainen <tss@iki.fi>
parents:
1506
diff
changeset
|
234 login_process_groups_create(); |
1275
af685269ead0
login: Wait until we're connected to auth process before executing command
Timo Sirainen <tss@iki.fi>
parents:
1273
diff
changeset
|
235 |
af685269ead0
login: Wait until we're connected to auth process before executing command
Timo Sirainen <tss@iki.fi>
parents:
1273
diff
changeset
|
236 for (group = login_groups; group != NULL; group = group->next) { |
1610
6850142c4e25
New configuration file code. Some syntax changes, but tries to be somewhat
Timo Sirainen <tss@iki.fi>
parents:
1506
diff
changeset
|
237 if (strcmp(group->set->server->name, name) == 0 && |
6850142c4e25
New configuration file code. Some syntax changes, but tries to be somewhat
Timo Sirainen <tss@iki.fi>
parents:
1506
diff
changeset
|
238 group->set->protocol == protocol) |
1275
af685269ead0
login: Wait until we're connected to auth process before executing command
Timo Sirainen <tss@iki.fi>
parents:
1273
diff
changeset
|
239 return group; |
af685269ead0
login: Wait until we're connected to auth process before executing command
Timo Sirainen <tss@iki.fi>
parents:
1273
diff
changeset
|
240 } |
af685269ead0
login: Wait until we're connected to auth process before executing command
Timo Sirainen <tss@iki.fi>
parents:
1273
diff
changeset
|
241 |
af685269ead0
login: Wait until we're connected to auth process before executing command
Timo Sirainen <tss@iki.fi>
parents:
1273
diff
changeset
|
242 return NULL; |
af685269ead0
login: Wait until we're connected to auth process before executing command
Timo Sirainen <tss@iki.fi>
parents:
1273
diff
changeset
|
243 } |
614
e60620644af3
login_process_per_connection = yes scales now better when multiple users are
Timo Sirainen <tss@iki.fi>
parents:
613
diff
changeset
|
244 |
3863
55df57c028d4
Added "bool" type and changed all ints that were used as booleans to bool.
Timo Sirainen <tss@iki.fi>
parents:
3692
diff
changeset
|
245 static bool login_process_read_group(struct login_process *p) |
1275
af685269ead0
login: Wait until we're connected to auth process before executing command
Timo Sirainen <tss@iki.fi>
parents:
1273
diff
changeset
|
246 { |
af685269ead0
login: Wait until we're connected to auth process before executing command
Timo Sirainen <tss@iki.fi>
parents:
1273
diff
changeset
|
247 struct login_group *group; |
1610
6850142c4e25
New configuration file code. Some syntax changes, but tries to be somewhat
Timo Sirainen <tss@iki.fi>
parents:
1506
diff
changeset
|
248 const char *name, *proto; |
5089 | 249 unsigned char buf[256]; |
1610
6850142c4e25
New configuration file code. Some syntax changes, but tries to be somewhat
Timo Sirainen <tss@iki.fi>
parents:
1506
diff
changeset
|
250 enum mail_protocol protocol; |
1275
af685269ead0
login: Wait until we're connected to auth process before executing command
Timo Sirainen <tss@iki.fi>
parents:
1273
diff
changeset
|
251 unsigned int len; |
af685269ead0
login: Wait until we're connected to auth process before executing command
Timo Sirainen <tss@iki.fi>
parents:
1273
diff
changeset
|
252 ssize_t ret; |
af685269ead0
login: Wait until we're connected to auth process before executing command
Timo Sirainen <tss@iki.fi>
parents:
1273
diff
changeset
|
253 |
af685269ead0
login: Wait until we're connected to auth process before executing command
Timo Sirainen <tss@iki.fi>
parents:
1273
diff
changeset
|
254 /* read length */ |
af685269ead0
login: Wait until we're connected to auth process before executing command
Timo Sirainen <tss@iki.fi>
parents:
1273
diff
changeset
|
255 ret = read(p->fd, buf, 1); |
af685269ead0
login: Wait until we're connected to auth process before executing command
Timo Sirainen <tss@iki.fi>
parents:
1273
diff
changeset
|
256 if (ret != 1) |
af685269ead0
login: Wait until we're connected to auth process before executing command
Timo Sirainen <tss@iki.fi>
parents:
1273
diff
changeset
|
257 len = 0; |
af685269ead0
login: Wait until we're connected to auth process before executing command
Timo Sirainen <tss@iki.fi>
parents:
1273
diff
changeset
|
258 else { |
af685269ead0
login: Wait until we're connected to auth process before executing command
Timo Sirainen <tss@iki.fi>
parents:
1273
diff
changeset
|
259 len = buf[0]; |
af685269ead0
login: Wait until we're connected to auth process before executing command
Timo Sirainen <tss@iki.fi>
parents:
1273
diff
changeset
|
260 if (len >= sizeof(buf)) { |
1610
6850142c4e25
New configuration file code. Some syntax changes, but tries to be somewhat
Timo Sirainen <tss@iki.fi>
parents:
1506
diff
changeset
|
261 i_error("login: Server name length too large"); |
1275
af685269ead0
login: Wait until we're connected to auth process before executing command
Timo Sirainen <tss@iki.fi>
parents:
1273
diff
changeset
|
262 return FALSE; |
af685269ead0
login: Wait until we're connected to auth process before executing command
Timo Sirainen <tss@iki.fi>
parents:
1273
diff
changeset
|
263 } |
614
e60620644af3
login_process_per_connection = yes scales now better when multiple users are
Timo Sirainen <tss@iki.fi>
parents:
613
diff
changeset
|
264 |
1275
af685269ead0
login: Wait until we're connected to auth process before executing command
Timo Sirainen <tss@iki.fi>
parents:
1273
diff
changeset
|
265 ret = read(p->fd, buf, len); |
af685269ead0
login: Wait until we're connected to auth process before executing command
Timo Sirainen <tss@iki.fi>
parents:
1273
diff
changeset
|
266 } |
af685269ead0
login: Wait until we're connected to auth process before executing command
Timo Sirainen <tss@iki.fi>
parents:
1273
diff
changeset
|
267 |
af685269ead0
login: Wait until we're connected to auth process before executing command
Timo Sirainen <tss@iki.fi>
parents:
1273
diff
changeset
|
268 if (ret < 0) |
af685269ead0
login: Wait until we're connected to auth process before executing command
Timo Sirainen <tss@iki.fi>
parents:
1273
diff
changeset
|
269 i_error("login: read() failed: %m"); |
af685269ead0
login: Wait until we're connected to auth process before executing command
Timo Sirainen <tss@iki.fi>
parents:
1273
diff
changeset
|
270 else if (len == 0 || (size_t)ret != len) |
1610
6850142c4e25
New configuration file code. Some syntax changes, but tries to be somewhat
Timo Sirainen <tss@iki.fi>
parents:
1506
diff
changeset
|
271 i_error("login: Server name wasn't sent"); |
1275
af685269ead0
login: Wait until we're connected to auth process before executing command
Timo Sirainen <tss@iki.fi>
parents:
1273
diff
changeset
|
272 else { |
af685269ead0
login: Wait until we're connected to auth process before executing command
Timo Sirainen <tss@iki.fi>
parents:
1273
diff
changeset
|
273 name = t_strndup(buf, len); |
3607
a2dd3d895e00
Several fixes to make running from inetd working again
Timo Sirainen <tss@iki.fi>
parents:
3384
diff
changeset
|
274 proto = strchr(name, '/'); |
1610
6850142c4e25
New configuration file code. Some syntax changes, but tries to be somewhat
Timo Sirainen <tss@iki.fi>
parents:
1506
diff
changeset
|
275 if (proto == NULL) { |
3607
a2dd3d895e00
Several fixes to make running from inetd working again
Timo Sirainen <tss@iki.fi>
parents:
3384
diff
changeset
|
276 proto = name; |
a2dd3d895e00
Several fixes to make running from inetd working again
Timo Sirainen <tss@iki.fi>
parents:
3384
diff
changeset
|
277 name = "default"; |
a2dd3d895e00
Several fixes to make running from inetd working again
Timo Sirainen <tss@iki.fi>
parents:
3384
diff
changeset
|
278 } else { |
a2dd3d895e00
Several fixes to make running from inetd working again
Timo Sirainen <tss@iki.fi>
parents:
3384
diff
changeset
|
279 name = t_strdup_until(name, proto++); |
1610
6850142c4e25
New configuration file code. Some syntax changes, but tries to be somewhat
Timo Sirainen <tss@iki.fi>
parents:
1506
diff
changeset
|
280 } |
6850142c4e25
New configuration file code. Some syntax changes, but tries to be somewhat
Timo Sirainen <tss@iki.fi>
parents:
1506
diff
changeset
|
281 |
6850142c4e25
New configuration file code. Some syntax changes, but tries to be somewhat
Timo Sirainen <tss@iki.fi>
parents:
1506
diff
changeset
|
282 if (strcmp(proto, "imap") == 0) |
6850142c4e25
New configuration file code. Some syntax changes, but tries to be somewhat
Timo Sirainen <tss@iki.fi>
parents:
1506
diff
changeset
|
283 protocol = MAIL_PROTOCOL_IMAP; |
6850142c4e25
New configuration file code. Some syntax changes, but tries to be somewhat
Timo Sirainen <tss@iki.fi>
parents:
1506
diff
changeset
|
284 else if (strcmp(proto, "pop3") == 0) |
4353
3e542f308cb5
Starting pop3 processes from inetd started actually imap processes after
Timo Sirainen <tss@iki.fi>
parents:
4197
diff
changeset
|
285 protocol = MAIL_PROTOCOL_POP3; |
1610
6850142c4e25
New configuration file code. Some syntax changes, but tries to be somewhat
Timo Sirainen <tss@iki.fi>
parents:
1506
diff
changeset
|
286 else { |
6850142c4e25
New configuration file code. Some syntax changes, but tries to be somewhat
Timo Sirainen <tss@iki.fi>
parents:
1506
diff
changeset
|
287 i_error("login: Unknown protocol '%s'", proto); |
6850142c4e25
New configuration file code. Some syntax changes, but tries to be somewhat
Timo Sirainen <tss@iki.fi>
parents:
1506
diff
changeset
|
288 return FALSE; |
6850142c4e25
New configuration file code. Some syntax changes, but tries to be somewhat
Timo Sirainen <tss@iki.fi>
parents:
1506
diff
changeset
|
289 } |
6850142c4e25
New configuration file code. Some syntax changes, but tries to be somewhat
Timo Sirainen <tss@iki.fi>
parents:
1506
diff
changeset
|
290 |
6850142c4e25
New configuration file code. Some syntax changes, but tries to be somewhat
Timo Sirainen <tss@iki.fi>
parents:
1506
diff
changeset
|
291 group = login_group_process_find(name, protocol); |
1275
af685269ead0
login: Wait until we're connected to auth process before executing command
Timo Sirainen <tss@iki.fi>
parents:
1273
diff
changeset
|
292 if (group == NULL) { |
1610
6850142c4e25
New configuration file code. Some syntax changes, but tries to be somewhat
Timo Sirainen <tss@iki.fi>
parents:
1506
diff
changeset
|
293 i_error("login: Unknown server name '%s'", name); |
1275
af685269ead0
login: Wait until we're connected to auth process before executing command
Timo Sirainen <tss@iki.fi>
parents:
1273
diff
changeset
|
294 return FALSE; |
af685269ead0
login: Wait until we're connected to auth process before executing command
Timo Sirainen <tss@iki.fi>
parents:
1273
diff
changeset
|
295 } |
af685269ead0
login: Wait until we're connected to auth process before executing command
Timo Sirainen <tss@iki.fi>
parents:
1273
diff
changeset
|
296 |
af685269ead0
login: Wait until we're connected to auth process before executing command
Timo Sirainen <tss@iki.fi>
parents:
1273
diff
changeset
|
297 p->group = group; |
af685269ead0
login: Wait until we're connected to auth process before executing command
Timo Sirainen <tss@iki.fi>
parents:
1273
diff
changeset
|
298 return login_process_init_group(p); |
af685269ead0
login: Wait until we're connected to auth process before executing command
Timo Sirainen <tss@iki.fi>
parents:
1273
diff
changeset
|
299 } |
af685269ead0
login: Wait until we're connected to auth process before executing command
Timo Sirainen <tss@iki.fi>
parents:
1273
diff
changeset
|
300 return FALSE; |
614
e60620644af3
login_process_per_connection = yes scales now better when multiple users are
Timo Sirainen <tss@iki.fi>
parents:
613
diff
changeset
|
301 } |
e60620644af3
login_process_per_connection = yes scales now better when multiple users are
Timo Sirainen <tss@iki.fi>
parents:
613
diff
changeset
|
302 |
4649
a3d6a3462745
Send inode number in login requests and verify that they match.
Timo Sirainen <tss@iki.fi>
parents:
4640
diff
changeset
|
303 static int |
a3d6a3462745
Send inode number in login requests and verify that they match.
Timo Sirainen <tss@iki.fi>
parents:
4640
diff
changeset
|
304 login_read_request(struct login_process *p, struct master_login_request *req, |
7927
2351a81ce699
If commands are pipelined after the login command, pass them to the
Timo Sirainen <tss@iki.fi>
parents:
7922
diff
changeset
|
305 unsigned char data[MASTER_LOGIN_MAX_DATA_SIZE], |
4649
a3d6a3462745
Send inode number in login requests and verify that they match.
Timo Sirainen <tss@iki.fi>
parents:
4640
diff
changeset
|
306 int *client_fd_r) |
a3d6a3462745
Send inode number in login requests and verify that they match.
Timo Sirainen <tss@iki.fi>
parents:
4640
diff
changeset
|
307 { |
a3d6a3462745
Send inode number in login requests and verify that they match.
Timo Sirainen <tss@iki.fi>
parents:
4640
diff
changeset
|
308 struct stat st; |
a3d6a3462745
Send inode number in login requests and verify that they match.
Timo Sirainen <tss@iki.fi>
parents:
4640
diff
changeset
|
309 ssize_t ret; |
a3d6a3462745
Send inode number in login requests and verify that they match.
Timo Sirainen <tss@iki.fi>
parents:
4640
diff
changeset
|
310 |
a3d6a3462745
Send inode number in login requests and verify that they match.
Timo Sirainen <tss@iki.fi>
parents:
4640
diff
changeset
|
311 *client_fd_r = -1; |
a3d6a3462745
Send inode number in login requests and verify that they match.
Timo Sirainen <tss@iki.fi>
parents:
4640
diff
changeset
|
312 |
a3d6a3462745
Send inode number in login requests and verify that they match.
Timo Sirainen <tss@iki.fi>
parents:
4640
diff
changeset
|
313 ret = fd_read(p->fd, req, sizeof(*req), client_fd_r); |
a3d6a3462745
Send inode number in login requests and verify that they match.
Timo Sirainen <tss@iki.fi>
parents:
4640
diff
changeset
|
314 if (ret >= (ssize_t)sizeof(req->version) && |
a3d6a3462745
Send inode number in login requests and verify that they match.
Timo Sirainen <tss@iki.fi>
parents:
4640
diff
changeset
|
315 req->version != MASTER_LOGIN_PROTOCOL_VERSION) { |
a3d6a3462745
Send inode number in login requests and verify that they match.
Timo Sirainen <tss@iki.fi>
parents:
4640
diff
changeset
|
316 i_error("login: Protocol version mismatch " |
a3d6a3462745
Send inode number in login requests and verify that they match.
Timo Sirainen <tss@iki.fi>
parents:
4640
diff
changeset
|
317 "(mixed old and new binaries?)"); |
a3d6a3462745
Send inode number in login requests and verify that they match.
Timo Sirainen <tss@iki.fi>
parents:
4640
diff
changeset
|
318 return -1; |
a3d6a3462745
Send inode number in login requests and verify that they match.
Timo Sirainen <tss@iki.fi>
parents:
4640
diff
changeset
|
319 } |
a3d6a3462745
Send inode number in login requests and verify that they match.
Timo Sirainen <tss@iki.fi>
parents:
4640
diff
changeset
|
320 |
a3d6a3462745
Send inode number in login requests and verify that they match.
Timo Sirainen <tss@iki.fi>
parents:
4640
diff
changeset
|
321 if (ret != sizeof(*req)) { |
a3d6a3462745
Send inode number in login requests and verify that they match.
Timo Sirainen <tss@iki.fi>
parents:
4640
diff
changeset
|
322 if (ret == 0) { |
a3d6a3462745
Send inode number in login requests and verify that they match.
Timo Sirainen <tss@iki.fi>
parents:
4640
diff
changeset
|
323 /* disconnected, ie. the login process died */ |
a3d6a3462745
Send inode number in login requests and verify that they match.
Timo Sirainen <tss@iki.fi>
parents:
4640
diff
changeset
|
324 } else if (ret > 0) { |
a3d6a3462745
Send inode number in login requests and verify that they match.
Timo Sirainen <tss@iki.fi>
parents:
4640
diff
changeset
|
325 /* request wasn't fully read */ |
4734
f032a5d2bc0d
Error message fix for 64bit systems.
Timo Sirainen <tss@iki.fi>
parents:
4670
diff
changeset
|
326 i_error("login: fd_read() returned partial %d", |
f032a5d2bc0d
Error message fix for 64bit systems.
Timo Sirainen <tss@iki.fi>
parents:
4670
diff
changeset
|
327 (int)ret); |
4649
a3d6a3462745
Send inode number in login requests and verify that they match.
Timo Sirainen <tss@iki.fi>
parents:
4640
diff
changeset
|
328 } else { |
a3d6a3462745
Send inode number in login requests and verify that they match.
Timo Sirainen <tss@iki.fi>
parents:
4640
diff
changeset
|
329 if (errno == EAGAIN) |
a3d6a3462745
Send inode number in login requests and verify that they match.
Timo Sirainen <tss@iki.fi>
parents:
4640
diff
changeset
|
330 return 0; |
a3d6a3462745
Send inode number in login requests and verify that they match.
Timo Sirainen <tss@iki.fi>
parents:
4640
diff
changeset
|
331 |
a3d6a3462745
Send inode number in login requests and verify that they match.
Timo Sirainen <tss@iki.fi>
parents:
4640
diff
changeset
|
332 i_error("login: fd_read() failed: %m"); |
a3d6a3462745
Send inode number in login requests and verify that they match.
Timo Sirainen <tss@iki.fi>
parents:
4640
diff
changeset
|
333 } |
a3d6a3462745
Send inode number in login requests and verify that they match.
Timo Sirainen <tss@iki.fi>
parents:
4640
diff
changeset
|
334 return -1; |
a3d6a3462745
Send inode number in login requests and verify that they match.
Timo Sirainen <tss@iki.fi>
parents:
4640
diff
changeset
|
335 } |
a3d6a3462745
Send inode number in login requests and verify that they match.
Timo Sirainen <tss@iki.fi>
parents:
4640
diff
changeset
|
336 |
a3d6a3462745
Send inode number in login requests and verify that they match.
Timo Sirainen <tss@iki.fi>
parents:
4640
diff
changeset
|
337 if (req->ino == (ino_t)-1) { |
a3d6a3462745
Send inode number in login requests and verify that they match.
Timo Sirainen <tss@iki.fi>
parents:
4640
diff
changeset
|
338 if (*client_fd_r != -1) { |
a3d6a3462745
Send inode number in login requests and verify that they match.
Timo Sirainen <tss@iki.fi>
parents:
4640
diff
changeset
|
339 i_error("login: Notification request sent " |
a3d6a3462745
Send inode number in login requests and verify that they match.
Timo Sirainen <tss@iki.fi>
parents:
4640
diff
changeset
|
340 "a file descriptor"); |
a3d6a3462745
Send inode number in login requests and verify that they match.
Timo Sirainen <tss@iki.fi>
parents:
4640
diff
changeset
|
341 return -1; |
a3d6a3462745
Send inode number in login requests and verify that they match.
Timo Sirainen <tss@iki.fi>
parents:
4640
diff
changeset
|
342 } |
a3d6a3462745
Send inode number in login requests and verify that they match.
Timo Sirainen <tss@iki.fi>
parents:
4640
diff
changeset
|
343 return 1; |
a3d6a3462745
Send inode number in login requests and verify that they match.
Timo Sirainen <tss@iki.fi>
parents:
4640
diff
changeset
|
344 } |
7927
2351a81ce699
If commands are pipelined after the login command, pass them to the
Timo Sirainen <tss@iki.fi>
parents:
7922
diff
changeset
|
345 if (req->data_size != 0) { |
2351a81ce699
If commands are pipelined after the login command, pass them to the
Timo Sirainen <tss@iki.fi>
parents:
7922
diff
changeset
|
346 if (req->data_size > MASTER_LOGIN_MAX_DATA_SIZE) { |
2351a81ce699
If commands are pipelined after the login command, pass them to the
Timo Sirainen <tss@iki.fi>
parents:
7922
diff
changeset
|
347 i_error("login: Too large data_size sent"); |
2351a81ce699
If commands are pipelined after the login command, pass them to the
Timo Sirainen <tss@iki.fi>
parents:
7922
diff
changeset
|
348 return -1; |
2351a81ce699
If commands are pipelined after the login command, pass them to the
Timo Sirainen <tss@iki.fi>
parents:
7922
diff
changeset
|
349 } |
2351a81ce699
If commands are pipelined after the login command, pass them to the
Timo Sirainen <tss@iki.fi>
parents:
7922
diff
changeset
|
350 /* @UNSAFE */ |
2351a81ce699
If commands are pipelined after the login command, pass them to the
Timo Sirainen <tss@iki.fi>
parents:
7922
diff
changeset
|
351 ret = read(p->fd, data, req->data_size); |
2351a81ce699
If commands are pipelined after the login command, pass them to the
Timo Sirainen <tss@iki.fi>
parents:
7922
diff
changeset
|
352 if (ret != req->data_size) { |
2351a81ce699
If commands are pipelined after the login command, pass them to the
Timo Sirainen <tss@iki.fi>
parents:
7922
diff
changeset
|
353 if (ret == 0) { |
2351a81ce699
If commands are pipelined after the login command, pass them to the
Timo Sirainen <tss@iki.fi>
parents:
7922
diff
changeset
|
354 /* disconnected */ |
2351a81ce699
If commands are pipelined after the login command, pass them to the
Timo Sirainen <tss@iki.fi>
parents:
7922
diff
changeset
|
355 } else if (ret > 0) { |
2351a81ce699
If commands are pipelined after the login command, pass them to the
Timo Sirainen <tss@iki.fi>
parents:
7922
diff
changeset
|
356 /* request wasn't fully read */ |
2351a81ce699
If commands are pipelined after the login command, pass them to the
Timo Sirainen <tss@iki.fi>
parents:
7922
diff
changeset
|
357 i_error("login: Data read partially %d/%u", |
2351a81ce699
If commands are pipelined after the login command, pass them to the
Timo Sirainen <tss@iki.fi>
parents:
7922
diff
changeset
|
358 (int)ret, req->data_size); |
2351a81ce699
If commands are pipelined after the login command, pass them to the
Timo Sirainen <tss@iki.fi>
parents:
7922
diff
changeset
|
359 } else { |
2351a81ce699
If commands are pipelined after the login command, pass them to the
Timo Sirainen <tss@iki.fi>
parents:
7922
diff
changeset
|
360 i_error("login: read(data) failed: %m"); |
2351a81ce699
If commands are pipelined after the login command, pass them to the
Timo Sirainen <tss@iki.fi>
parents:
7922
diff
changeset
|
361 } |
2351a81ce699
If commands are pipelined after the login command, pass them to the
Timo Sirainen <tss@iki.fi>
parents:
7922
diff
changeset
|
362 return -1; |
2351a81ce699
If commands are pipelined after the login command, pass them to the
Timo Sirainen <tss@iki.fi>
parents:
7922
diff
changeset
|
363 } |
2351a81ce699
If commands are pipelined after the login command, pass them to the
Timo Sirainen <tss@iki.fi>
parents:
7922
diff
changeset
|
364 } |
4649
a3d6a3462745
Send inode number in login requests and verify that they match.
Timo Sirainen <tss@iki.fi>
parents:
4640
diff
changeset
|
365 |
a3d6a3462745
Send inode number in login requests and verify that they match.
Timo Sirainen <tss@iki.fi>
parents:
4640
diff
changeset
|
366 if (*client_fd_r == -1) { |
a3d6a3462745
Send inode number in login requests and verify that they match.
Timo Sirainen <tss@iki.fi>
parents:
4640
diff
changeset
|
367 i_error("login: Login request missing a file descriptor"); |
a3d6a3462745
Send inode number in login requests and verify that they match.
Timo Sirainen <tss@iki.fi>
parents:
4640
diff
changeset
|
368 return -1; |
a3d6a3462745
Send inode number in login requests and verify that they match.
Timo Sirainen <tss@iki.fi>
parents:
4640
diff
changeset
|
369 } |
a3d6a3462745
Send inode number in login requests and verify that they match.
Timo Sirainen <tss@iki.fi>
parents:
4640
diff
changeset
|
370 |
a3d6a3462745
Send inode number in login requests and verify that they match.
Timo Sirainen <tss@iki.fi>
parents:
4640
diff
changeset
|
371 if (fstat(*client_fd_r, &st) < 0) { |
a3d6a3462745
Send inode number in login requests and verify that they match.
Timo Sirainen <tss@iki.fi>
parents:
4640
diff
changeset
|
372 i_error("login: fstat(mail client) failed: %m"); |
a3d6a3462745
Send inode number in login requests and verify that they match.
Timo Sirainen <tss@iki.fi>
parents:
4640
diff
changeset
|
373 return -1; |
a3d6a3462745
Send inode number in login requests and verify that they match.
Timo Sirainen <tss@iki.fi>
parents:
4640
diff
changeset
|
374 } |
a3d6a3462745
Send inode number in login requests and verify that they match.
Timo Sirainen <tss@iki.fi>
parents:
4640
diff
changeset
|
375 if (st.st_ino != req->ino) { |
a3d6a3462745
Send inode number in login requests and verify that they match.
Timo Sirainen <tss@iki.fi>
parents:
4640
diff
changeset
|
376 i_error("login: Login request inode mismatch: %s != %s", |
a3d6a3462745
Send inode number in login requests and verify that they match.
Timo Sirainen <tss@iki.fi>
parents:
4640
diff
changeset
|
377 dec2str(st.st_ino), dec2str(req->ino)); |
a3d6a3462745
Send inode number in login requests and verify that they match.
Timo Sirainen <tss@iki.fi>
parents:
4640
diff
changeset
|
378 return -1; |
a3d6a3462745
Send inode number in login requests and verify that they match.
Timo Sirainen <tss@iki.fi>
parents:
4640
diff
changeset
|
379 } |
a3d6a3462745
Send inode number in login requests and verify that they match.
Timo Sirainen <tss@iki.fi>
parents:
4640
diff
changeset
|
380 return 1; |
a3d6a3462745
Send inode number in login requests and verify that they match.
Timo Sirainen <tss@iki.fi>
parents:
4640
diff
changeset
|
381 } |
a3d6a3462745
Send inode number in login requests and verify that they match.
Timo Sirainen <tss@iki.fi>
parents:
4640
diff
changeset
|
382 |
4907
5b4c9b20eba0
Replaced void *context from a lot of callbacks with the actual context
Timo Sirainen <tss@iki.fi>
parents:
4740
diff
changeset
|
383 static void login_process_input(struct login_process *p) |
0 | 384 { |
903
fd8888f6f037
Naming style changes, finally got tired of most of the typedefs. Also the
Timo Sirainen <tss@iki.fi>
parents:
876
diff
changeset
|
385 struct auth_process *auth_process; |
fd8888f6f037
Naming style changes, finally got tired of most of the typedefs. Also the
Timo Sirainen <tss@iki.fi>
parents:
876
diff
changeset
|
386 struct login_auth_request *authreq; |
1035
fe49ece0f3ea
We have now separate "userdb" and "passdb". They aren't tied to each others
Timo Sirainen <tss@iki.fi>
parents:
1000
diff
changeset
|
387 struct master_login_request req; |
7927
2351a81ce699
If commands are pipelined after the login command, pass them to the
Timo Sirainen <tss@iki.fi>
parents:
7922
diff
changeset
|
388 unsigned char data[MASTER_LOGIN_MAX_DATA_SIZE]; |
1275
af685269ead0
login: Wait until we're connected to auth process before executing command
Timo Sirainen <tss@iki.fi>
parents:
1273
diff
changeset
|
389 int client_fd; |
af685269ead0
login: Wait until we're connected to auth process before executing command
Timo Sirainen <tss@iki.fi>
parents:
1273
diff
changeset
|
390 ssize_t ret; |
af685269ead0
login: Wait until we're connected to auth process before executing command
Timo Sirainen <tss@iki.fi>
parents:
1273
diff
changeset
|
391 |
af685269ead0
login: Wait until we're connected to auth process before executing command
Timo Sirainen <tss@iki.fi>
parents:
1273
diff
changeset
|
392 if (p->group == NULL) { |
af685269ead0
login: Wait until we're connected to auth process before executing command
Timo Sirainen <tss@iki.fi>
parents:
1273
diff
changeset
|
393 /* we want to read the group */ |
af685269ead0
login: Wait until we're connected to auth process before executing command
Timo Sirainen <tss@iki.fi>
parents:
1273
diff
changeset
|
394 if (!login_process_read_group(p)) |
af685269ead0
login: Wait until we're connected to auth process before executing command
Timo Sirainen <tss@iki.fi>
parents:
1273
diff
changeset
|
395 login_process_destroy(p); |
af685269ead0
login: Wait until we're connected to auth process before executing command
Timo Sirainen <tss@iki.fi>
parents:
1273
diff
changeset
|
396 return; |
af685269ead0
login: Wait until we're connected to auth process before executing command
Timo Sirainen <tss@iki.fi>
parents:
1273
diff
changeset
|
397 } |
0 | 398 |
7927
2351a81ce699
If commands are pipelined after the login command, pass them to the
Timo Sirainen <tss@iki.fi>
parents:
7922
diff
changeset
|
399 ret = login_read_request(p, &req, data, &client_fd); |
4649
a3d6a3462745
Send inode number in login requests and verify that they match.
Timo Sirainen <tss@iki.fi>
parents:
4640
diff
changeset
|
400 if (ret == 0) |
a3d6a3462745
Send inode number in login requests and verify that they match.
Timo Sirainen <tss@iki.fi>
parents:
4640
diff
changeset
|
401 return; |
a3d6a3462745
Send inode number in login requests and verify that they match.
Timo Sirainen <tss@iki.fi>
parents:
4640
diff
changeset
|
402 if (ret < 0) { |
a3d6a3462745
Send inode number in login requests and verify that they match.
Timo Sirainen <tss@iki.fi>
parents:
4640
diff
changeset
|
403 if (client_fd != -1) { |
a3d6a3462745
Send inode number in login requests and verify that they match.
Timo Sirainen <tss@iki.fi>
parents:
4640
diff
changeset
|
404 if (close(client_fd) < 0) |
a3d6a3462745
Send inode number in login requests and verify that they match.
Timo Sirainen <tss@iki.fi>
parents:
4640
diff
changeset
|
405 i_error("login: close(mail client) failed: %m"); |
a3d6a3462745
Send inode number in login requests and verify that they match.
Timo Sirainen <tss@iki.fi>
parents:
4640
diff
changeset
|
406 } |
2779
1fd55b4341b9
Added version to login <-> master communication as well.
Timo Sirainen <tss@iki.fi>
parents:
2736
diff
changeset
|
407 login_process_destroy(p); |
1fd55b4341b9
Added version to login <-> master communication as well.
Timo Sirainen <tss@iki.fi>
parents:
2736
diff
changeset
|
408 return; |
1fd55b4341b9
Added version to login <-> master communication as well.
Timo Sirainen <tss@iki.fi>
parents:
2736
diff
changeset
|
409 } |
1fd55b4341b9
Added version to login <-> master communication as well.
Timo Sirainen <tss@iki.fi>
parents:
2736
diff
changeset
|
410 |
4649
a3d6a3462745
Send inode number in login requests and verify that they match.
Timo Sirainen <tss@iki.fi>
parents:
4640
diff
changeset
|
411 if (req.ino == (ino_t)-1) { |
a3d6a3462745
Send inode number in login requests and verify that they match.
Timo Sirainen <tss@iki.fi>
parents:
4640
diff
changeset
|
412 /* state notification */ |
4538
9d9e72374164
Fixes to login process handling, especially with
Timo Sirainen <tss@iki.fi>
parents:
4388
diff
changeset
|
413 enum master_login_state state = req.tag; |
9d9e72374164
Fixes to login process handling, especially with
Timo Sirainen <tss@iki.fi>
parents:
4388
diff
changeset
|
414 |
925
2e649dec0f09
Auth and login processes send an "we're ok" reply at the end of
Timo Sirainen <tss@iki.fi>
parents:
903
diff
changeset
|
415 if (!p->initialized) { |
2e649dec0f09
Auth and login processes send an "we're ok" reply at the end of
Timo Sirainen <tss@iki.fi>
parents:
903
diff
changeset
|
416 /* initialization notify */ |
4651
2fe8f6a0bc5b
If login process dies before initialization, stall creation of them instead
Timo Sirainen <tss@iki.fi>
parents:
4649
diff
changeset
|
417 login_process_set_initialized(p); |
925
2e649dec0f09
Auth and login processes send an "we're ok" reply at the end of
Timo Sirainen <tss@iki.fi>
parents:
903
diff
changeset
|
418 } else { |
4538
9d9e72374164
Fixes to login process handling, especially with
Timo Sirainen <tss@iki.fi>
parents:
4388
diff
changeset
|
419 /* change "listening for new connections" status */ |
9d9e72374164
Fixes to login process handling, especially with
Timo Sirainen <tss@iki.fi>
parents:
4388
diff
changeset
|
420 login_process_set_state(p, state); |
925
2e649dec0f09
Auth and login processes send an "we're ok" reply at the end of
Timo Sirainen <tss@iki.fi>
parents:
903
diff
changeset
|
421 } |
613
1906116a62ce
Finally support for handling each login connection in it's own process.
Timo Sirainen <tss@iki.fi>
parents:
596
diff
changeset
|
422 return; |
1906116a62ce
Finally support for handling each login connection in it's own process.
Timo Sirainen <tss@iki.fi>
parents:
596
diff
changeset
|
423 } |
1906116a62ce
Finally support for handling each login connection in it's own process.
Timo Sirainen <tss@iki.fi>
parents:
596
diff
changeset
|
424 |
4661
885bef091d1a
Make sure we don't kill login processes that haven't yet even sent their
Timo Sirainen <tss@iki.fi>
parents:
4651
diff
changeset
|
425 if (!p->initialized) { |
885bef091d1a
Make sure we don't kill login processes that haven't yet even sent their
Timo Sirainen <tss@iki.fi>
parents:
4651
diff
changeset
|
426 i_error("login: trying to log in before initialization"); |
885bef091d1a
Make sure we don't kill login processes that haven't yet even sent their
Timo Sirainen <tss@iki.fi>
parents:
4651
diff
changeset
|
427 login_process_destroy(p); |
885bef091d1a
Make sure we don't kill login processes that haven't yet even sent their
Timo Sirainen <tss@iki.fi>
parents:
4651
diff
changeset
|
428 return; |
885bef091d1a
Make sure we don't kill login processes that haven't yet even sent their
Timo Sirainen <tss@iki.fi>
parents:
4651
diff
changeset
|
429 } |
885bef091d1a
Make sure we don't kill login processes that haven't yet even sent their
Timo Sirainen <tss@iki.fi>
parents:
4651
diff
changeset
|
430 |
1035
fe49ece0f3ea
We have now separate "userdb" and "passdb". They aren't tied to each others
Timo Sirainen <tss@iki.fi>
parents:
1000
diff
changeset
|
431 fd_close_on_exec(client_fd, TRUE); |
0 | 432 |
433 /* ask the cookie from the auth process */ | |
7927
2351a81ce699
If commands are pipelined after the login command, pass them to the
Timo Sirainen <tss@iki.fi>
parents:
7922
diff
changeset
|
434 authreq = i_malloc(sizeof(*authreq) + req.data_size); |
0 | 435 p->refcount++; |
436 authreq->process = p; | |
1035
fe49ece0f3ea
We have now separate "userdb" and "passdb". They aren't tied to each others
Timo Sirainen <tss@iki.fi>
parents:
1000
diff
changeset
|
437 authreq->tag = ++auth_id_counter; |
fe49ece0f3ea
We have now separate "userdb" and "passdb". They aren't tied to each others
Timo Sirainen <tss@iki.fi>
parents:
1000
diff
changeset
|
438 authreq->login_tag = req.tag; |
7928
9e226056a208
Send login command OK reply in IMAP/POP3 process.
Timo Sirainen <tss@iki.fi>
parents:
7927
diff
changeset
|
439 authreq->mail_request.fd = client_fd; |
9e226056a208
Send login command OK reply in IMAP/POP3 process.
Timo Sirainen <tss@iki.fi>
parents:
7927
diff
changeset
|
440 authreq->mail_request.local_ip = req.local_ip; |
9e226056a208
Send login command OK reply in IMAP/POP3 process.
Timo Sirainen <tss@iki.fi>
parents:
7927
diff
changeset
|
441 authreq->mail_request.remote_ip = req.remote_ip; |
9e226056a208
Send login command OK reply in IMAP/POP3 process.
Timo Sirainen <tss@iki.fi>
parents:
7927
diff
changeset
|
442 authreq->mail_request.cmd_tag_size = req.cmd_tag_size; |
9e226056a208
Send login command OK reply in IMAP/POP3 process.
Timo Sirainen <tss@iki.fi>
parents:
7927
diff
changeset
|
443 authreq->mail_request.data_size = req.data_size; |
7927
2351a81ce699
If commands are pipelined after the login command, pass them to the
Timo Sirainen <tss@iki.fi>
parents:
7922
diff
changeset
|
444 memcpy(authreq->data, data, req.data_size); |
0 | 445 |
1035
fe49ece0f3ea
We have now separate "userdb" and "passdb". They aren't tied to each others
Timo Sirainen <tss@iki.fi>
parents:
1000
diff
changeset
|
446 auth_process = auth_process_find(req.auth_pid); |
0 | 447 if (auth_process == NULL) { |
448 i_error("login: Authentication process %u doesn't exist", | |
1035
fe49ece0f3ea
We have now separate "userdb" and "passdb". They aren't tied to each others
Timo Sirainen <tss@iki.fi>
parents:
1000
diff
changeset
|
449 req.auth_pid); |
fe49ece0f3ea
We have now separate "userdb" and "passdb". They aren't tied to each others
Timo Sirainen <tss@iki.fi>
parents:
1000
diff
changeset
|
450 auth_master_callback(NULL, NULL, authreq); |
0 | 451 } else { |
1035
fe49ece0f3ea
We have now separate "userdb" and "passdb". They aren't tied to each others
Timo Sirainen <tss@iki.fi>
parents:
1000
diff
changeset
|
452 auth_process_request(auth_process, p->pid, |
fe49ece0f3ea
We have now separate "userdb" and "passdb". They aren't tied to each others
Timo Sirainen <tss@iki.fi>
parents:
1000
diff
changeset
|
453 req.auth_id, authreq); |
0 | 454 } |
455 } | |
456 | |
1055
a72bba3f8a55
Rewrote setting handling. Changed some existing settings also since POP3
Timo Sirainen <tss@iki.fi>
parents:
1039
diff
changeset
|
457 static struct login_process * |
6519
66e5f514355e
Login processes started by inetd aren't ours, don't treat them as such.
Timo Sirainen <tss@iki.fi>
parents:
6429
diff
changeset
|
458 login_process_new(struct login_group *group, pid_t pid, int fd, |
66e5f514355e
Login processes started by inetd aren't ours, don't treat them as such.
Timo Sirainen <tss@iki.fi>
parents:
6429
diff
changeset
|
459 bool inetd_child) |
0 | 460 { |
903
fd8888f6f037
Naming style changes, finally got tired of most of the typedefs. Also the
Timo Sirainen <tss@iki.fi>
parents:
876
diff
changeset
|
461 struct login_process *p; |
0 | 462 |
1273
2cf2e08a6ee9
Somewhat working code to support loading Dovecot from inetd and such. It
Timo Sirainen <tss@iki.fi>
parents:
1237
diff
changeset
|
463 i_assert(pid != 0); |
0 | 464 |
903
fd8888f6f037
Naming style changes, finally got tired of most of the typedefs. Also the
Timo Sirainen <tss@iki.fi>
parents:
876
diff
changeset
|
465 p = i_new(struct login_process, 1); |
5843
f655c4d4a419
Moved child process handling to child-process.[ch]. The hash table now uses
Timo Sirainen <tss@iki.fi>
parents:
5632
diff
changeset
|
466 p->process.type = PROCESS_TYPE_LOGIN; |
1055
a72bba3f8a55
Rewrote setting handling. Changed some existing settings also since POP3
Timo Sirainen <tss@iki.fi>
parents:
1039
diff
changeset
|
467 p->group = group; |
4670 | 468 p->refcount = 2; /* once for fd close, another for process exit */ |
0 | 469 p->pid = pid; |
470 p->fd = fd; | |
6519
66e5f514355e
Login processes started by inetd aren't ours, don't treat them as such.
Timo Sirainen <tss@iki.fi>
parents:
6429
diff
changeset
|
471 p->inetd_child = inetd_child; |
0 | 472 p->io = io_add(fd, IO_READ, login_process_input, p); |
6161
c62f7ee79446
Split o_stream_create_file() to _create_fd() and _create_fd_file().
Timo Sirainen <tss@iki.fi>
parents:
6142
diff
changeset
|
473 p->output = o_stream_create_fd(fd, sizeof(struct master_login_reply)*10, |
c62f7ee79446
Split o_stream_create_file() to _create_fd() and _create_fd_file().
Timo Sirainen <tss@iki.fi>
parents:
6142
diff
changeset
|
474 FALSE); |
6519
66e5f514355e
Login processes started by inetd aren't ours, don't treat them as such.
Timo Sirainen <tss@iki.fi>
parents:
6429
diff
changeset
|
475 if (!inetd_child) |
66e5f514355e
Login processes started by inetd aren't ours, don't treat them as such.
Timo Sirainen <tss@iki.fi>
parents:
6429
diff
changeset
|
476 child_process_add(pid, &p->process); |
1273
2cf2e08a6ee9
Somewhat working code to support loading Dovecot from inetd and such. It
Timo Sirainen <tss@iki.fi>
parents:
1237
diff
changeset
|
477 |
4538
9d9e72374164
Fixes to login process handling, especially with
Timo Sirainen <tss@iki.fi>
parents:
4388
diff
changeset
|
478 p->state = LOGIN_STATE_LISTENING; |
9d9e72374164
Fixes to login process handling, especially with
Timo Sirainen <tss@iki.fi>
parents:
4388
diff
changeset
|
479 |
1275
af685269ead0
login: Wait until we're connected to auth process before executing command
Timo Sirainen <tss@iki.fi>
parents:
1273
diff
changeset
|
480 if (p->group != NULL) { |
4631
f5d53a684856
SIGHUP caused memory corruption
Timo Sirainen <tss@iki.fi>
parents:
4630
diff
changeset
|
481 p->group->refcount++; |
1275
af685269ead0
login: Wait until we're connected to auth process before executing command
Timo Sirainen <tss@iki.fi>
parents:
1273
diff
changeset
|
482 p->group->processes++; |
af685269ead0
login: Wait until we're connected to auth process before executing command
Timo Sirainen <tss@iki.fi>
parents:
1273
diff
changeset
|
483 p->group->listening_processes++; |
af685269ead0
login: Wait until we're connected to auth process before executing command
Timo Sirainen <tss@iki.fi>
parents:
1273
diff
changeset
|
484 } |
0 | 485 return p; |
486 } | |
487 | |
4538
9d9e72374164
Fixes to login process handling, especially with
Timo Sirainen <tss@iki.fi>
parents:
4388
diff
changeset
|
488 static void login_process_exited(struct login_process *p) |
613
1906116a62ce
Finally support for handling each login connection in it's own process.
Timo Sirainen <tss@iki.fi>
parents:
596
diff
changeset
|
489 { |
4538
9d9e72374164
Fixes to login process handling, especially with
Timo Sirainen <tss@iki.fi>
parents:
4388
diff
changeset
|
490 if (p->group != NULL) |
9d9e72374164
Fixes to login process handling, especially with
Timo Sirainen <tss@iki.fi>
parents:
4388
diff
changeset
|
491 p->group->processes--; |
1275
af685269ead0
login: Wait until we're connected to auth process before executing command
Timo Sirainen <tss@iki.fi>
parents:
1273
diff
changeset
|
492 |
4538
9d9e72374164
Fixes to login process handling, especially with
Timo Sirainen <tss@iki.fi>
parents:
4388
diff
changeset
|
493 login_process_unref(p); |
613
1906116a62ce
Finally support for handling each login connection in it's own process.
Timo Sirainen <tss@iki.fi>
parents:
596
diff
changeset
|
494 } |
1906116a62ce
Finally support for handling each login connection in it's own process.
Timo Sirainen <tss@iki.fi>
parents:
596
diff
changeset
|
495 |
903
fd8888f6f037
Naming style changes, finally got tired of most of the typedefs. Also the
Timo Sirainen <tss@iki.fi>
parents:
876
diff
changeset
|
496 static void login_process_destroy(struct login_process *p) |
0 | 497 { |
498 if (p->destroyed) | |
499 return; | |
500 p->destroyed = TRUE; | |
501 | |
4651
2fe8f6a0bc5b
If login process dies before initialization, stall creation of them instead
Timo Sirainen <tss@iki.fi>
parents:
4649
diff
changeset
|
502 if (!p->initialized) |
2fe8f6a0bc5b
If login process dies before initialization, stall creation of them instead
Timo Sirainen <tss@iki.fi>
parents:
4649
diff
changeset
|
503 login_processes_stall(); |
1275
af685269ead0
login: Wait until we're connected to auth process before executing command
Timo Sirainen <tss@iki.fi>
parents:
1273
diff
changeset
|
504 |
764
f57c52738f90
Renamed IBuffer and OBuffer to IStream and OStream which describes their
Timo Sirainen <tss@iki.fi>
parents:
747
diff
changeset
|
505 o_stream_close(p->output); |
3879
928229f8b3e6
deinit, unref, destroy, close, free, etc. functions now take a pointer to
Timo Sirainen <tss@iki.fi>
parents:
3863
diff
changeset
|
506 io_remove(&p->io); |
805
5ac361acb316
Marked all non-trivial buffer modifications with @UNSAFE tag. Several
Timo Sirainen <tss@iki.fi>
parents:
801
diff
changeset
|
507 if (close(p->fd) < 0) |
5ac361acb316
Marked all non-trivial buffer modifications with @UNSAFE tag. Several
Timo Sirainen <tss@iki.fi>
parents:
801
diff
changeset
|
508 i_error("close(login) failed: %m"); |
0 | 509 |
4538
9d9e72374164
Fixes to login process handling, especially with
Timo Sirainen <tss@iki.fi>
parents:
4388
diff
changeset
|
510 process_mark_nonlistening(p, LOGIN_STATE_FULL_LOGINS); |
613
1906116a62ce
Finally support for handling each login connection in it's own process.
Timo Sirainen <tss@iki.fi>
parents:
596
diff
changeset
|
511 |
4538
9d9e72374164
Fixes to login process handling, especially with
Timo Sirainen <tss@iki.fi>
parents:
4388
diff
changeset
|
512 if (p->inetd_child) |
9d9e72374164
Fixes to login process handling, especially with
Timo Sirainen <tss@iki.fi>
parents:
4388
diff
changeset
|
513 login_process_exited(p); |
4670 | 514 login_process_unref(p); |
0 | 515 } |
516 | |
903
fd8888f6f037
Naming style changes, finally got tired of most of the typedefs. Also the
Timo Sirainen <tss@iki.fi>
parents:
876
diff
changeset
|
517 static void login_process_unref(struct login_process *p) |
0 | 518 { |
4670 | 519 i_assert(p->refcount > 0); |
0 | 520 if (--p->refcount > 0) |
521 return; | |
522 | |
4631
f5d53a684856
SIGHUP caused memory corruption
Timo Sirainen <tss@iki.fi>
parents:
4630
diff
changeset
|
523 if (p->group != NULL) |
f5d53a684856
SIGHUP caused memory corruption
Timo Sirainen <tss@iki.fi>
parents:
4630
diff
changeset
|
524 login_group_unref(p->group); |
f5d53a684856
SIGHUP caused memory corruption
Timo Sirainen <tss@iki.fi>
parents:
4630
diff
changeset
|
525 |
3879
928229f8b3e6
deinit, unref, destroy, close, free, etc. functions now take a pointer to
Timo Sirainen <tss@iki.fi>
parents:
3863
diff
changeset
|
526 o_stream_unref(&p->output); |
0 | 527 i_free(p); |
528 } | |
529 | |
7109
e6823d781317
Reverted "environment array" changes. It broke overriding imap/pop3 settings
Timo Sirainen <tss@iki.fi>
parents:
7091
diff
changeset
|
530 static void login_process_init_env(struct login_group *group, pid_t pid) |
1273
2cf2e08a6ee9
Somewhat working code to support loading Dovecot from inetd and such. It
Timo Sirainen <tss@iki.fi>
parents:
1237
diff
changeset
|
531 { |
1610
6850142c4e25
New configuration file code. Some syntax changes, but tries to be somewhat
Timo Sirainen <tss@iki.fi>
parents:
1506
diff
changeset
|
532 struct settings *set = group->set; |
8302
0db37acdc59f
Login process: Log auth failure reasons better in disconnect message.
Timo Sirainen <tss@iki.fi>
parents:
8092
diff
changeset
|
533 const struct auth_settings *auth; |
0db37acdc59f
Login process: Log auth failure reasons better in disconnect message.
Timo Sirainen <tss@iki.fi>
parents:
8092
diff
changeset
|
534 bool require_cert; |
1610
6850142c4e25
New configuration file code. Some syntax changes, but tries to be somewhat
Timo Sirainen <tss@iki.fi>
parents:
1506
diff
changeset
|
535 |
7109
e6823d781317
Reverted "environment array" changes. It broke overriding imap/pop3 settings
Timo Sirainen <tss@iki.fi>
parents:
7091
diff
changeset
|
536 child_process_init_env(); |
1273
2cf2e08a6ee9
Somewhat working code to support loading Dovecot from inetd and such. It
Timo Sirainen <tss@iki.fi>
parents:
1237
diff
changeset
|
537 |
2cf2e08a6ee9
Somewhat working code to support loading Dovecot from inetd and such. It
Timo Sirainen <tss@iki.fi>
parents:
1237
diff
changeset
|
538 /* setup access environment - needs to be done after |
3692 | 539 clean_child_process() since it clears environment. Don't set user |
540 parameter since we don't want to call initgroups() for login | |
3691
e167b71e37e3
Don't call initgroups() at the start of login processes.
Timo Sirainen <tss@iki.fi>
parents:
3607
diff
changeset
|
541 processes. */ |
7109
e6823d781317
Reverted "environment array" changes. It broke overriding imap/pop3 settings
Timo Sirainen <tss@iki.fi>
parents:
7091
diff
changeset
|
542 restrict_access_set_env(NULL, set->login_uid, |
7341
af998ae4254b
Replaced mail_extra_groups setting with mail_privileged_group and
Timo Sirainen <tss@iki.fi>
parents:
7226
diff
changeset
|
543 set->server->login_gid, (gid_t)-1, |
1506
e7c627bacaaf
Allow first_valid_gid to be 0. Drop any supplementary groups not in valid
Timo Sirainen <tss@iki.fi>
parents:
1499
diff
changeset
|
544 set->login_chroot ? set->login_dir : NULL, |
2141
8690d2000e33
Added mail_extra_groups setting.
Timo Sirainen <tss@iki.fi>
parents:
2097
diff
changeset
|
545 0, 0, NULL); |
1273
2cf2e08a6ee9
Somewhat working code to support loading Dovecot from inetd and such. It
Timo Sirainen <tss@iki.fi>
parents:
1237
diff
changeset
|
546 |
7109
e6823d781317
Reverted "environment array" changes. It broke overriding imap/pop3 settings
Timo Sirainen <tss@iki.fi>
parents:
7091
diff
changeset
|
547 env_put("DOVECOT_MASTER=1"); |
1273
2cf2e08a6ee9
Somewhat working code to support loading Dovecot from inetd and such. It
Timo Sirainen <tss@iki.fi>
parents:
1237
diff
changeset
|
548 |
2cf2e08a6ee9
Somewhat working code to support loading Dovecot from inetd and such. It
Timo Sirainen <tss@iki.fi>
parents:
1237
diff
changeset
|
549 if (!set->ssl_disable) { |
4388
af61031c746f
Settings parser nowadays returns "" instead of NULL when it reads an empty
Timo Sirainen <tss@iki.fi>
parents:
4353
diff
changeset
|
550 const char *ssl_key_password; |
3889
c7462001227b
Added support for password protected SSL private keys. The password can be
Timo Sirainen <tss@iki.fi>
parents:
3879
diff
changeset
|
551 |
4388
af61031c746f
Settings parser nowadays returns "" instead of NULL when it reads an empty
Timo Sirainen <tss@iki.fi>
parents:
4353
diff
changeset
|
552 ssl_key_password = *set->ssl_key_password != '\0' ? |
3889
c7462001227b
Added support for password protected SSL private keys. The password can be
Timo Sirainen <tss@iki.fi>
parents:
3879
diff
changeset
|
553 set->ssl_key_password : ssl_manual_key_password; |
c7462001227b
Added support for password protected SSL private keys. The password can be
Timo Sirainen <tss@iki.fi>
parents:
3879
diff
changeset
|
554 |
7109
e6823d781317
Reverted "environment array" changes. It broke overriding imap/pop3 settings
Timo Sirainen <tss@iki.fi>
parents:
7091
diff
changeset
|
555 if (*set->ssl_ca_file != '\0') { |
e6823d781317
Reverted "environment array" changes. It broke overriding imap/pop3 settings
Timo Sirainen <tss@iki.fi>
parents:
7091
diff
changeset
|
556 env_put(t_strconcat("SSL_CA_FILE=", |
e6823d781317
Reverted "environment array" changes. It broke overriding imap/pop3 settings
Timo Sirainen <tss@iki.fi>
parents:
7091
diff
changeset
|
557 set->ssl_ca_file, NULL)); |
e6823d781317
Reverted "environment array" changes. It broke overriding imap/pop3 settings
Timo Sirainen <tss@iki.fi>
parents:
7091
diff
changeset
|
558 } |
e6823d781317
Reverted "environment array" changes. It broke overriding imap/pop3 settings
Timo Sirainen <tss@iki.fi>
parents:
7091
diff
changeset
|
559 env_put(t_strconcat("SSL_CERT_FILE=", |
e6823d781317
Reverted "environment array" changes. It broke overriding imap/pop3 settings
Timo Sirainen <tss@iki.fi>
parents:
7091
diff
changeset
|
560 set->ssl_cert_file, NULL)); |
e6823d781317
Reverted "environment array" changes. It broke overriding imap/pop3 settings
Timo Sirainen <tss@iki.fi>
parents:
7091
diff
changeset
|
561 env_put(t_strconcat("SSL_KEY_FILE=", |
e6823d781317
Reverted "environment array" changes. It broke overriding imap/pop3 settings
Timo Sirainen <tss@iki.fi>
parents:
7091
diff
changeset
|
562 set->ssl_key_file, NULL)); |
e6823d781317
Reverted "environment array" changes. It broke overriding imap/pop3 settings
Timo Sirainen <tss@iki.fi>
parents:
7091
diff
changeset
|
563 env_put(t_strconcat("SSL_KEY_PASSWORD=", |
e6823d781317
Reverted "environment array" changes. It broke overriding imap/pop3 settings
Timo Sirainen <tss@iki.fi>
parents:
7091
diff
changeset
|
564 ssl_key_password, NULL)); |
e6823d781317
Reverted "environment array" changes. It broke overriding imap/pop3 settings
Timo Sirainen <tss@iki.fi>
parents:
7091
diff
changeset
|
565 env_put("SSL_PARAM_FILE="SSL_PARAMETERS_FILENAME); |
7091
59ac3628b8d8
Build environment using envarr and pass it to execve(). This is faster than
Timo Sirainen <tss@iki.fi>
parents:
7086
diff
changeset
|
566 if (*set->ssl_cipher_list != '\0') { |
7109
e6823d781317
Reverted "environment array" changes. It broke overriding imap/pop3 settings
Timo Sirainen <tss@iki.fi>
parents:
7091
diff
changeset
|
567 env_put(t_strconcat("SSL_CIPHER_LIST=", |
e6823d781317
Reverted "environment array" changes. It broke overriding imap/pop3 settings
Timo Sirainen <tss@iki.fi>
parents:
7091
diff
changeset
|
568 set->ssl_cipher_list, NULL)); |
1907
190f1d315ce6
Added setting ssl_ca_file, patch by Zach Bagnall
Timo Sirainen <tss@iki.fi>
parents:
1897
diff
changeset
|
569 } |
7109
e6823d781317
Reverted "environment array" changes. It broke overriding imap/pop3 settings
Timo Sirainen <tss@iki.fi>
parents:
7091
diff
changeset
|
570 env_put(t_strconcat("SSL_CERT_USERNAME_FIELD=", |
e6823d781317
Reverted "environment array" changes. It broke overriding imap/pop3 settings
Timo Sirainen <tss@iki.fi>
parents:
7091
diff
changeset
|
571 set->ssl_cert_username_field, NULL)); |
1997
1d0985f6bdd9
Added ssl_verify_client_cert setting.
Timo Sirainen <tss@iki.fi>
parents:
1996
diff
changeset
|
572 if (set->ssl_verify_client_cert) |
7109
e6823d781317
Reverted "environment array" changes. It broke overriding imap/pop3 settings
Timo Sirainen <tss@iki.fi>
parents:
7091
diff
changeset
|
573 env_put("SSL_VERIFY_CLIENT_CERT=1"); |
1273
2cf2e08a6ee9
Somewhat working code to support loading Dovecot from inetd and such. It
Timo Sirainen <tss@iki.fi>
parents:
1237
diff
changeset
|
574 } |
2cf2e08a6ee9
Somewhat working code to support loading Dovecot from inetd and such. It
Timo Sirainen <tss@iki.fi>
parents:
1237
diff
changeset
|
575 |
2cf2e08a6ee9
Somewhat working code to support loading Dovecot from inetd and such. It
Timo Sirainen <tss@iki.fi>
parents:
1237
diff
changeset
|
576 if (set->disable_plaintext_auth) |
7109
e6823d781317
Reverted "environment array" changes. It broke overriding imap/pop3 settings
Timo Sirainen <tss@iki.fi>
parents:
7091
diff
changeset
|
577 env_put("DISABLE_PLAINTEXT_AUTH=1"); |
1273
2cf2e08a6ee9
Somewhat working code to support loading Dovecot from inetd and such. It
Timo Sirainen <tss@iki.fi>
parents:
1237
diff
changeset
|
578 if (set->verbose_proctitle) |
7109
e6823d781317
Reverted "environment array" changes. It broke overriding imap/pop3 settings
Timo Sirainen <tss@iki.fi>
parents:
7091
diff
changeset
|
579 env_put("VERBOSE_PROCTITLE=1"); |
1273
2cf2e08a6ee9
Somewhat working code to support loading Dovecot from inetd and such. It
Timo Sirainen <tss@iki.fi>
parents:
1237
diff
changeset
|
580 if (set->verbose_ssl) |
7109
e6823d781317
Reverted "environment array" changes. It broke overriding imap/pop3 settings
Timo Sirainen <tss@iki.fi>
parents:
7091
diff
changeset
|
581 env_put("VERBOSE_SSL=1"); |
2691
46f879c46b45
auth_verbose now affects imap/pop3 login processes too. Every authentication
Timo Sirainen <tss@iki.fi>
parents:
2674
diff
changeset
|
582 if (set->server->auths->verbose) |
7109
e6823d781317
Reverted "environment array" changes. It broke overriding imap/pop3 settings
Timo Sirainen <tss@iki.fi>
parents:
7091
diff
changeset
|
583 env_put("VERBOSE_AUTH=1"); |
8331
8fb20b423f8b
Login processes: If auth_debug=yes, log about received unknown passdb extra fields.
Timo Sirainen <tss@iki.fi>
parents:
8302
diff
changeset
|
584 if (set->server->auths->debug) |
8fb20b423f8b
Login processes: If auth_debug=yes, log about received unknown passdb extra fields.
Timo Sirainen <tss@iki.fi>
parents:
8302
diff
changeset
|
585 env_put("AUTH_DEBUG=1"); |
8302
0db37acdc59f
Login process: Log auth failure reasons better in disconnect message.
Timo Sirainen <tss@iki.fi>
parents:
8092
diff
changeset
|
586 require_cert = TRUE; |
0db37acdc59f
Login process: Log auth failure reasons better in disconnect message.
Timo Sirainen <tss@iki.fi>
parents:
8092
diff
changeset
|
587 for (auth = set->server->auths; auth != NULL; auth = auth->next) { |
0db37acdc59f
Login process: Log auth failure reasons better in disconnect message.
Timo Sirainen <tss@iki.fi>
parents:
8092
diff
changeset
|
588 if (!auth->ssl_require_client_cert) |
0db37acdc59f
Login process: Log auth failure reasons better in disconnect message.
Timo Sirainen <tss@iki.fi>
parents:
8092
diff
changeset
|
589 require_cert = FALSE; |
0db37acdc59f
Login process: Log auth failure reasons better in disconnect message.
Timo Sirainen <tss@iki.fi>
parents:
8092
diff
changeset
|
590 } |
0db37acdc59f
Login process: Log auth failure reasons better in disconnect message.
Timo Sirainen <tss@iki.fi>
parents:
8092
diff
changeset
|
591 if (require_cert) |
0db37acdc59f
Login process: Log auth failure reasons better in disconnect message.
Timo Sirainen <tss@iki.fi>
parents:
8092
diff
changeset
|
592 env_put("SSL_REQUIRE_CLIENT_CERT=1"); |
1273
2cf2e08a6ee9
Somewhat working code to support loading Dovecot from inetd and such. It
Timo Sirainen <tss@iki.fi>
parents:
1237
diff
changeset
|
593 |
1610
6850142c4e25
New configuration file code. Some syntax changes, but tries to be somewhat
Timo Sirainen <tss@iki.fi>
parents:
1506
diff
changeset
|
594 if (set->login_process_per_connection) { |
7109
e6823d781317
Reverted "environment array" changes. It broke overriding imap/pop3 settings
Timo Sirainen <tss@iki.fi>
parents:
7091
diff
changeset
|
595 env_put("PROCESS_PER_CONNECTION=1"); |
e6823d781317
Reverted "environment array" changes. It broke overriding imap/pop3 settings
Timo Sirainen <tss@iki.fi>
parents:
7091
diff
changeset
|
596 env_put("MAX_CONNECTIONS=1"); |
1273
2cf2e08a6ee9
Somewhat working code to support loading Dovecot from inetd and such. It
Timo Sirainen <tss@iki.fi>
parents:
1237
diff
changeset
|
597 } else { |
7109
e6823d781317
Reverted "environment array" changes. It broke overriding imap/pop3 settings
Timo Sirainen <tss@iki.fi>
parents:
7091
diff
changeset
|
598 env_put(t_strdup_printf("MAX_CONNECTIONS=%u", |
e6823d781317
Reverted "environment array" changes. It broke overriding imap/pop3 settings
Timo Sirainen <tss@iki.fi>
parents:
7091
diff
changeset
|
599 set->login_max_connections)); |
1273
2cf2e08a6ee9
Somewhat working code to support loading Dovecot from inetd and such. It
Timo Sirainen <tss@iki.fi>
parents:
1237
diff
changeset
|
600 } |
2cf2e08a6ee9
Somewhat working code to support loading Dovecot from inetd and such. It
Timo Sirainen <tss@iki.fi>
parents:
1237
diff
changeset
|
601 |
7109
e6823d781317
Reverted "environment array" changes. It broke overriding imap/pop3 settings
Timo Sirainen <tss@iki.fi>
parents:
7091
diff
changeset
|
602 env_put(t_strconcat("PROCESS_UID=", dec2str(pid), NULL)); |
e6823d781317
Reverted "environment array" changes. It broke overriding imap/pop3 settings
Timo Sirainen <tss@iki.fi>
parents:
7091
diff
changeset
|
603 env_put(t_strconcat("GREETING=", set->login_greeting, NULL)); |
e6823d781317
Reverted "environment array" changes. It broke overriding imap/pop3 settings
Timo Sirainen <tss@iki.fi>
parents:
7091
diff
changeset
|
604 env_put(t_strconcat("LOG_FORMAT_ELEMENTS=", |
e6823d781317
Reverted "environment array" changes. It broke overriding imap/pop3 settings
Timo Sirainen <tss@iki.fi>
parents:
7091
diff
changeset
|
605 set->login_log_format_elements, NULL)); |
e6823d781317
Reverted "environment array" changes. It broke overriding imap/pop3 settings
Timo Sirainen <tss@iki.fi>
parents:
7091
diff
changeset
|
606 env_put(t_strconcat("LOG_FORMAT=", set->login_log_format, NULL)); |
7917
ca2ff54ee9b4
Added support for IMAP ID extension.
Timo Sirainen <tss@iki.fi>
parents:
7852
diff
changeset
|
607 env_put(t_strconcat("IMAP_ID_SEND=", set->imap_id_send, NULL)); |
ca2ff54ee9b4
Added support for IMAP ID extension.
Timo Sirainen <tss@iki.fi>
parents:
7852
diff
changeset
|
608 env_put(t_strconcat("IMAP_ID_LOG=", set->imap_id_log, NULL)); |
4197
c3ded5b815aa
If we have plugins set and imap_capability unset, figure out the IMAP
Timo Sirainen <tss@iki.fi>
parents:
4148
diff
changeset
|
609 |
5843
f655c4d4a419
Moved child process handling to child-process.[ch]. The hash table now uses
Timo Sirainen <tss@iki.fi>
parents:
5632
diff
changeset
|
610 if (group->mail_process_type == PROCESS_TYPE_IMAP) { |
7109
e6823d781317
Reverted "environment array" changes. It broke overriding imap/pop3 settings
Timo Sirainen <tss@iki.fi>
parents:
7091
diff
changeset
|
611 env_put(t_strconcat("CAPABILITY_STRING=", |
e6823d781317
Reverted "environment array" changes. It broke overriding imap/pop3 settings
Timo Sirainen <tss@iki.fi>
parents:
7091
diff
changeset
|
612 *set->imap_capability != '\0' ? |
e6823d781317
Reverted "environment array" changes. It broke overriding imap/pop3 settings
Timo Sirainen <tss@iki.fi>
parents:
7091
diff
changeset
|
613 set->imap_capability : |
e6823d781317
Reverted "environment array" changes. It broke overriding imap/pop3 settings
Timo Sirainen <tss@iki.fi>
parents:
7091
diff
changeset
|
614 set->imap_generated_capability, NULL)); |
4197
c3ded5b815aa
If we have plugins set and imap_capability unset, figure out the IMAP
Timo Sirainen <tss@iki.fi>
parents:
4148
diff
changeset
|
615 } |
7920
3644883cf44e
Support transferring original IPs and ports through IMAP proxies.
Timo Sirainen <tss@iki.fi>
parents:
7917
diff
changeset
|
616 if (*set->login_trusted_networks != '\0') { |
3644883cf44e
Support transferring original IPs and ports through IMAP proxies.
Timo Sirainen <tss@iki.fi>
parents:
7917
diff
changeset
|
617 env_put(t_strconcat("TRUSTED_NETWORKS=", |
3644883cf44e
Support transferring original IPs and ports through IMAP proxies.
Timo Sirainen <tss@iki.fi>
parents:
7917
diff
changeset
|
618 set->login_trusted_networks, NULL)); |
3644883cf44e
Support transferring original IPs and ports through IMAP proxies.
Timo Sirainen <tss@iki.fi>
parents:
7917
diff
changeset
|
619 } |
1273
2cf2e08a6ee9
Somewhat working code to support loading Dovecot from inetd and such. It
Timo Sirainen <tss@iki.fi>
parents:
1237
diff
changeset
|
620 } |
2cf2e08a6ee9
Somewhat working code to support loading Dovecot from inetd and such. It
Timo Sirainen <tss@iki.fi>
parents:
1237
diff
changeset
|
621 |
1055
a72bba3f8a55
Rewrote setting handling. Changed some existing settings also since POP3
Timo Sirainen <tss@iki.fi>
parents:
1039
diff
changeset
|
622 static pid_t create_login_process(struct login_group *group) |
0 | 623 { |
2046 | 624 struct log_io *log; |
5887
3f2eb1b9c555
Support listening multiple sockets. SIGHUP also doesn't anymore recreate
Timo Sirainen <tss@iki.fi>
parents:
5846
diff
changeset
|
625 const struct listener *listens; |
3083
a20882c4f092
Disable log throttlong for auth process, and for login processes if
Timo Sirainen <tss@iki.fi>
parents:
2886
diff
changeset
|
626 unsigned int max_log_lines_per_sec; |
2000
c7c19f5071c3
Write all logging through master process. Fixes problems with log rotation,
Timo Sirainen <tss@iki.fi>
parents:
1997
diff
changeset
|
627 const char *prefix; |
0 | 628 pid_t pid; |
5887
3f2eb1b9c555
Support listening multiple sockets. SIGHUP also doesn't anymore recreate
Timo Sirainen <tss@iki.fi>
parents:
5846
diff
changeset
|
629 ARRAY_TYPE(dup2) dups; |
7852
53604857c7d2
Change fd limit in login process after it's execed. This fixes OSes which
Timo Sirainen <tss@iki.fi>
parents:
7851
diff
changeset
|
630 unsigned int i, listen_count = 0, ssl_listen_count = 0; |
6396
1b21dfee7bd7
Calculate needed fd count better. Make sure we have one unused fd available
Timo Sirainen <tss@iki.fi>
parents:
6364
diff
changeset
|
631 int fd[2], log_fd, cur_fd, tmp_fd; |
0 | 632 |
1610
6850142c4e25
New configuration file code. Some syntax changes, but tries to be somewhat
Timo Sirainen <tss@iki.fi>
parents:
1506
diff
changeset
|
633 if (group->set->login_uid == 0) |
0 | 634 i_fatal("Login process must not run as root"); |
635 | |
636 /* create communication to process with a socket pair */ | |
2000
c7c19f5071c3
Write all logging through master process. Fixes problems with log rotation,
Timo Sirainen <tss@iki.fi>
parents:
1997
diff
changeset
|
637 if (socketpair(AF_UNIX, SOCK_STREAM, 0, fd) < 0) { |
0 | 638 i_error("socketpair() failed: %m"); |
639 return -1; | |
640 } | |
641 | |
3083
a20882c4f092
Disable log throttlong for auth process, and for login processes if
Timo Sirainen <tss@iki.fi>
parents:
2886
diff
changeset
|
642 max_log_lines_per_sec = |
a20882c4f092
Disable log throttlong for auth process, and for login processes if
Timo Sirainen <tss@iki.fi>
parents:
2886
diff
changeset
|
643 group->set->login_process_per_connection ? 10 : 0; |
5632
2ed5abe3aaef
Moved SSL listen fd to 4. stdout is now redirected to log.
Timo Sirainen <tss@iki.fi>
parents:
5358
diff
changeset
|
644 log_fd = log_create_pipe(&log, /*max_log_lines_per_sec*/0); |
2000
c7c19f5071c3
Write all logging through master process. Fixes problems with log rotation,
Timo Sirainen <tss@iki.fi>
parents:
1997
diff
changeset
|
645 if (log_fd < 0) |
c7c19f5071c3
Write all logging through master process. Fixes problems with log rotation,
Timo Sirainen <tss@iki.fi>
parents:
1997
diff
changeset
|
646 pid = -1; |
c7c19f5071c3
Write all logging through master process. Fixes problems with log rotation,
Timo Sirainen <tss@iki.fi>
parents:
1997
diff
changeset
|
647 else { |
c7c19f5071c3
Write all logging through master process. Fixes problems with log rotation,
Timo Sirainen <tss@iki.fi>
parents:
1997
diff
changeset
|
648 pid = fork(); |
c7c19f5071c3
Write all logging through master process. Fixes problems with log rotation,
Timo Sirainen <tss@iki.fi>
parents:
1997
diff
changeset
|
649 if (pid < 0) |
c7c19f5071c3
Write all logging through master process. Fixes problems with log rotation,
Timo Sirainen <tss@iki.fi>
parents:
1997
diff
changeset
|
650 i_error("fork() failed: %m"); |
c7c19f5071c3
Write all logging through master process. Fixes problems with log rotation,
Timo Sirainen <tss@iki.fi>
parents:
1997
diff
changeset
|
651 } |
c7c19f5071c3
Write all logging through master process. Fixes problems with log rotation,
Timo Sirainen <tss@iki.fi>
parents:
1997
diff
changeset
|
652 |
0 | 653 if (pid < 0) { |
654 (void)close(fd[0]); | |
655 (void)close(fd[1]); | |
2000
c7c19f5071c3
Write all logging through master process. Fixes problems with log rotation,
Timo Sirainen <tss@iki.fi>
parents:
1997
diff
changeset
|
656 (void)close(log_fd); |
0 | 657 return -1; |
658 } | |
659 | |
660 if (pid != 0) { | |
661 /* master */ | |
2046 | 662 prefix = t_strdup_printf("%s-login: ", |
5843
f655c4d4a419
Moved child process handling to child-process.[ch]. The hash table now uses
Timo Sirainen <tss@iki.fi>
parents:
5632
diff
changeset
|
663 process_names[group->mail_process_type]); |
2046 | 664 log_set_prefix(log, prefix); |
6542
402d14b5ef8b
If child process logged a fatal failure, don't show "returned error 89"
Timo Sirainen <tss@iki.fi>
parents:
6519
diff
changeset
|
665 log_set_pid(log, pid); |
2046 | 666 |
1273
2cf2e08a6ee9
Somewhat working code to support loading Dovecot from inetd and such. It
Timo Sirainen <tss@iki.fi>
parents:
1237
diff
changeset
|
667 net_set_nonblock(fd[0], TRUE); |
727
8dd8ebe6bcac
We use close-on-exec flag now to make sure that master process closes the
Timo Sirainen <tss@iki.fi>
parents:
722
diff
changeset
|
668 fd_close_on_exec(fd[0], TRUE); |
6519
66e5f514355e
Login processes started by inetd aren't ours, don't treat them as such.
Timo Sirainen <tss@iki.fi>
parents:
6429
diff
changeset
|
669 (void)login_process_new(group, pid, fd[0], FALSE); |
0 | 670 (void)close(fd[1]); |
2000
c7c19f5071c3
Write all logging through master process. Fixes problems with log rotation,
Timo Sirainen <tss@iki.fi>
parents:
1997
diff
changeset
|
671 (void)close(log_fd); |
0 | 672 return pid; |
673 } | |
674 | |
2046 | 675 prefix = t_strdup_printf("master-%s-login: ", |
5843
f655c4d4a419
Moved child process handling to child-process.[ch]. The hash table now uses
Timo Sirainen <tss@iki.fi>
parents:
5632
diff
changeset
|
676 process_names[group->mail_process_type]); |
2046 | 677 log_set_prefix(log, prefix); |
678 | |
5887
3f2eb1b9c555
Support listening multiple sockets. SIGHUP also doesn't anymore recreate
Timo Sirainen <tss@iki.fi>
parents:
5846
diff
changeset
|
679 t_array_init(&dups, 16); |
3f2eb1b9c555
Support listening multiple sockets. SIGHUP also doesn't anymore recreate
Timo Sirainen <tss@iki.fi>
parents:
5846
diff
changeset
|
680 dup2_append(&dups, null_fd, STDIN_FILENO); |
5632
2ed5abe3aaef
Moved SSL listen fd to 4. stdout is now redirected to log.
Timo Sirainen <tss@iki.fi>
parents:
5358
diff
changeset
|
681 /* redirect writes to stdout also to error log. For example OpenSSL |
2ed5abe3aaef
Moved SSL listen fd to 4. stdout is now redirected to log.
Timo Sirainen <tss@iki.fi>
parents:
5358
diff
changeset
|
682 can be made to log its debug messages to stdout. */ |
5887
3f2eb1b9c555
Support listening multiple sockets. SIGHUP also doesn't anymore recreate
Timo Sirainen <tss@iki.fi>
parents:
5846
diff
changeset
|
683 dup2_append(&dups, log_fd, STDOUT_FILENO); |
3f2eb1b9c555
Support listening multiple sockets. SIGHUP also doesn't anymore recreate
Timo Sirainen <tss@iki.fi>
parents:
5846
diff
changeset
|
684 dup2_append(&dups, log_fd, STDERR_FILENO); |
3f2eb1b9c555
Support listening multiple sockets. SIGHUP also doesn't anymore recreate
Timo Sirainen <tss@iki.fi>
parents:
5846
diff
changeset
|
685 dup2_append(&dups, fd[1], LOGIN_MASTER_SOCKET_FD); |
3f2eb1b9c555
Support listening multiple sockets. SIGHUP also doesn't anymore recreate
Timo Sirainen <tss@iki.fi>
parents:
5846
diff
changeset
|
686 |
3f2eb1b9c555
Support listening multiple sockets. SIGHUP also doesn't anymore recreate
Timo Sirainen <tss@iki.fi>
parents:
5846
diff
changeset
|
687 /* redirect listener fds */ |
3f2eb1b9c555
Support listening multiple sockets. SIGHUP also doesn't anymore recreate
Timo Sirainen <tss@iki.fi>
parents:
5846
diff
changeset
|
688 cur_fd = LOGIN_MASTER_SOCKET_FD + 1; |
3f2eb1b9c555
Support listening multiple sockets. SIGHUP also doesn't anymore recreate
Timo Sirainen <tss@iki.fi>
parents:
5846
diff
changeset
|
689 if (array_is_created(&group->set->listens)) { |
3f2eb1b9c555
Support listening multiple sockets. SIGHUP also doesn't anymore recreate
Timo Sirainen <tss@iki.fi>
parents:
5846
diff
changeset
|
690 listens = array_get(&group->set->listens, &listen_count); |
3f2eb1b9c555
Support listening multiple sockets. SIGHUP also doesn't anymore recreate
Timo Sirainen <tss@iki.fi>
parents:
5846
diff
changeset
|
691 for (i = 0; i < listen_count; i++, cur_fd++) |
3f2eb1b9c555
Support listening multiple sockets. SIGHUP also doesn't anymore recreate
Timo Sirainen <tss@iki.fi>
parents:
5846
diff
changeset
|
692 dup2_append(&dups, listens[i].fd, cur_fd); |
3f2eb1b9c555
Support listening multiple sockets. SIGHUP also doesn't anymore recreate
Timo Sirainen <tss@iki.fi>
parents:
5846
diff
changeset
|
693 } |
3f2eb1b9c555
Support listening multiple sockets. SIGHUP also doesn't anymore recreate
Timo Sirainen <tss@iki.fi>
parents:
5846
diff
changeset
|
694 |
3f2eb1b9c555
Support listening multiple sockets. SIGHUP also doesn't anymore recreate
Timo Sirainen <tss@iki.fi>
parents:
5846
diff
changeset
|
695 if (array_is_created(&group->set->ssl_listens)) { |
3f2eb1b9c555
Support listening multiple sockets. SIGHUP also doesn't anymore recreate
Timo Sirainen <tss@iki.fi>
parents:
5846
diff
changeset
|
696 listens = array_get(&group->set->ssl_listens, |
3f2eb1b9c555
Support listening multiple sockets. SIGHUP also doesn't anymore recreate
Timo Sirainen <tss@iki.fi>
parents:
5846
diff
changeset
|
697 &ssl_listen_count); |
3f2eb1b9c555
Support listening multiple sockets. SIGHUP also doesn't anymore recreate
Timo Sirainen <tss@iki.fi>
parents:
5846
diff
changeset
|
698 for (i = 0; i < ssl_listen_count; i++, cur_fd++) |
3f2eb1b9c555
Support listening multiple sockets. SIGHUP also doesn't anymore recreate
Timo Sirainen <tss@iki.fi>
parents:
5846
diff
changeset
|
699 dup2_append(&dups, listens[i].fd, cur_fd); |
3f2eb1b9c555
Support listening multiple sockets. SIGHUP also doesn't anymore recreate
Timo Sirainen <tss@iki.fi>
parents:
5846
diff
changeset
|
700 } |
3f2eb1b9c555
Support listening multiple sockets. SIGHUP also doesn't anymore recreate
Timo Sirainen <tss@iki.fi>
parents:
5846
diff
changeset
|
701 |
3f2eb1b9c555
Support listening multiple sockets. SIGHUP also doesn't anymore recreate
Timo Sirainen <tss@iki.fi>
parents:
5846
diff
changeset
|
702 if (dup2_array(&dups) < 0) |
3f2eb1b9c555
Support listening multiple sockets. SIGHUP also doesn't anymore recreate
Timo Sirainen <tss@iki.fi>
parents:
5846
diff
changeset
|
703 i_fatal("Failed to dup2() fds"); |
3f2eb1b9c555
Support listening multiple sockets. SIGHUP also doesn't anymore recreate
Timo Sirainen <tss@iki.fi>
parents:
5846
diff
changeset
|
704 |
3f2eb1b9c555
Support listening multiple sockets. SIGHUP also doesn't anymore recreate
Timo Sirainen <tss@iki.fi>
parents:
5846
diff
changeset
|
705 /* don't close any of these */ |
8088
14a061acbb7b
Master process leaked one fd to login process. Typically it was listener fd,
Timo Sirainen <tss@iki.fi>
parents:
7943
diff
changeset
|
706 for (tmp_fd = 0; tmp_fd < cur_fd; tmp_fd++) |
6396
1b21dfee7bd7
Calculate needed fd count better. Make sure we have one unused fd available
Timo Sirainen <tss@iki.fi>
parents:
6364
diff
changeset
|
707 fd_close_on_exec(tmp_fd, FALSE); |
2000
c7c19f5071c3
Write all logging through master process. Fixes problems with log rotation,
Timo Sirainen <tss@iki.fi>
parents:
1997
diff
changeset
|
708 |
0 | 709 (void)close(fd[0]); |
710 (void)close(fd[1]); | |
711 | |
7109
e6823d781317
Reverted "environment array" changes. It broke overriding imap/pop3 settings
Timo Sirainen <tss@iki.fi>
parents:
7091
diff
changeset
|
712 login_process_init_env(group, getpid()); |
0 | 713 |
7109
e6823d781317
Reverted "environment array" changes. It broke overriding imap/pop3 settings
Timo Sirainen <tss@iki.fi>
parents:
7091
diff
changeset
|
714 env_put(t_strdup_printf("LISTEN_FDS=%u", listen_count)); |
e6823d781317
Reverted "environment array" changes. It broke overriding imap/pop3 settings
Timo Sirainen <tss@iki.fi>
parents:
7091
diff
changeset
|
715 env_put(t_strdup_printf("SSL_LISTEN_FDS=%u", ssl_listen_count)); |
5887
3f2eb1b9c555
Support listening multiple sockets. SIGHUP also doesn't anymore recreate
Timo Sirainen <tss@iki.fi>
parents:
5846
diff
changeset
|
716 |
1610
6850142c4e25
New configuration file code. Some syntax changes, but tries to be somewhat
Timo Sirainen <tss@iki.fi>
parents:
1506
diff
changeset
|
717 if (!group->set->login_chroot) { |
0 | 718 /* no chrooting, but still change to the directory */ |
1610
6850142c4e25
New configuration file code. Some syntax changes, but tries to be somewhat
Timo Sirainen <tss@iki.fi>
parents:
1506
diff
changeset
|
719 if (chdir(group->set->login_dir) < 0) { |
6850142c4e25
New configuration file code. Some syntax changes, but tries to be somewhat
Timo Sirainen <tss@iki.fi>
parents:
1506
diff
changeset
|
720 i_fatal("chdir(%s) failed: %m", |
6850142c4e25
New configuration file code. Some syntax changes, but tries to be somewhat
Timo Sirainen <tss@iki.fi>
parents:
1506
diff
changeset
|
721 group->set->login_dir); |
6850142c4e25
New configuration file code. Some syntax changes, but tries to be somewhat
Timo Sirainen <tss@iki.fi>
parents:
1506
diff
changeset
|
722 } |
0 | 723 } |
724 | |
1610
6850142c4e25
New configuration file code. Some syntax changes, but tries to be somewhat
Timo Sirainen <tss@iki.fi>
parents:
1506
diff
changeset
|
725 restrict_process_size(group->set->login_process_size, (unsigned int)-1); |
722
0438621d25ff
Added virtual memory size limits to processes. Default values are pretty
Timo Sirainen <tss@iki.fi>
parents:
699
diff
changeset
|
726 |
801
86224ff16bf6
Drop root privileges earlier. Close syslog more later in imap-master when
Timo Sirainen <tss@iki.fi>
parents:
791
diff
changeset
|
727 /* make sure we don't leak syslog fd, but do it last so that |
86224ff16bf6
Drop root privileges earlier. Close syslog more later in imap-master when
Timo Sirainen <tss@iki.fi>
parents:
791
diff
changeset
|
728 any errors above will be logged */ |
86224ff16bf6
Drop root privileges earlier. Close syslog more later in imap-master when
Timo Sirainen <tss@iki.fi>
parents:
791
diff
changeset
|
729 closelog(); |
86224ff16bf6
Drop root privileges earlier. Close syslog more later in imap-master when
Timo Sirainen <tss@iki.fi>
parents:
791
diff
changeset
|
730 |
7109
e6823d781317
Reverted "environment array" changes. It broke overriding imap/pop3 settings
Timo Sirainen <tss@iki.fi>
parents:
7091
diff
changeset
|
731 client_process_exec(group->set->login_executable, ""); |
1441
a83ce8395316
If exec() fails, show the full path rather than argv[0]
Timo Sirainen <tss@iki.fi>
parents:
1398
diff
changeset
|
732 i_fatal_status(FATAL_EXEC, "execv(%s) failed: %m", |
1610
6850142c4e25
New configuration file code. Some syntax changes, but tries to be somewhat
Timo Sirainen <tss@iki.fi>
parents:
1506
diff
changeset
|
733 group->set->login_executable); |
0 | 734 return -1; |
735 } | |
736 | |
5843
f655c4d4a419
Moved child process handling to child-process.[ch]. The hash table now uses
Timo Sirainen <tss@iki.fi>
parents:
5632
diff
changeset
|
737 static void |
5846
21e529b8a701
Initial implementation for mail_max_user_connections setting.
Timo Sirainen <tss@iki.fi>
parents:
5843
diff
changeset
|
738 login_process_destroyed(struct child_process *process, |
6411
6a64e64fa3a3
Renamed __attr_*__ to ATTR_*. Renamed __attrs_used__ to ATTRS_DEFINED.
Timo Sirainen <tss@iki.fi>
parents:
6396
diff
changeset
|
739 pid_t pid ATTR_UNUSED, bool abnormal_exit) |
615
0d852af6842e
Master process generates DH/RSA parameters now and stores them into file
Timo Sirainen <tss@iki.fi>
parents:
614
diff
changeset
|
740 { |
5843
f655c4d4a419
Moved child process handling to child-process.[ch]. The hash table now uses
Timo Sirainen <tss@iki.fi>
parents:
5632
diff
changeset
|
741 struct login_process *p = (struct login_process *)process; |
1055
a72bba3f8a55
Rewrote setting handling. Changed some existing settings also since POP3
Timo Sirainen <tss@iki.fi>
parents:
1039
diff
changeset
|
742 |
4538
9d9e72374164
Fixes to login process handling, especially with
Timo Sirainen <tss@iki.fi>
parents:
4388
diff
changeset
|
743 i_assert(!p->inetd_child); |
9d9e72374164
Fixes to login process handling, especially with
Timo Sirainen <tss@iki.fi>
parents:
4388
diff
changeset
|
744 |
9d9e72374164
Fixes to login process handling, especially with
Timo Sirainen <tss@iki.fi>
parents:
4388
diff
changeset
|
745 if (abnormal_exit) { |
9d9e72374164
Fixes to login process handling, especially with
Timo Sirainen <tss@iki.fi>
parents:
4388
diff
changeset
|
746 /* don't start raising the process count if they're dying all |
9d9e72374164
Fixes to login process handling, especially with
Timo Sirainen <tss@iki.fi>
parents:
4388
diff
changeset
|
747 the time */ |
9d9e72374164
Fixes to login process handling, especially with
Timo Sirainen <tss@iki.fi>
parents:
4388
diff
changeset
|
748 if (p->group != NULL) |
9d9e72374164
Fixes to login process handling, especially with
Timo Sirainen <tss@iki.fi>
parents:
4388
diff
changeset
|
749 p->group->wanted_processes_count = 0; |
9d9e72374164
Fixes to login process handling, especially with
Timo Sirainen <tss@iki.fi>
parents:
4388
diff
changeset
|
750 } |
9d9e72374164
Fixes to login process handling, especially with
Timo Sirainen <tss@iki.fi>
parents:
4388
diff
changeset
|
751 |
9d9e72374164
Fixes to login process handling, especially with
Timo Sirainen <tss@iki.fi>
parents:
4388
diff
changeset
|
752 login_process_exited(p); |
615
0d852af6842e
Master process generates DH/RSA parameters now and stores them into file
Timo Sirainen <tss@iki.fi>
parents:
614
diff
changeset
|
753 } |
0d852af6842e
Master process generates DH/RSA parameters now and stores them into file
Timo Sirainen <tss@iki.fi>
parents:
614
diff
changeset
|
754 |
4670 | 755 void login_processes_destroy_all(void) |
635
90a65c017bf0
SIGHUP reloads now settings. Logged in clients are left untouched, but
Timo Sirainen <tss@iki.fi>
parents:
615
diff
changeset
|
756 { |
1897
1e6ed8045f2b
Changed hash_foreach() to iterator.
Timo Sirainen <tss@iki.fi>
parents:
1724
diff
changeset
|
757 struct hash_iterate_context *iter; |
1e6ed8045f2b
Changed hash_foreach() to iterator.
Timo Sirainen <tss@iki.fi>
parents:
1724
diff
changeset
|
758 void *key, *value; |
1e6ed8045f2b
Changed hash_foreach() to iterator.
Timo Sirainen <tss@iki.fi>
parents:
1724
diff
changeset
|
759 |
1e6ed8045f2b
Changed hash_foreach() to iterator.
Timo Sirainen <tss@iki.fi>
parents:
1724
diff
changeset
|
760 iter = hash_iterate_init(processes); |
5843
f655c4d4a419
Moved child process handling to child-process.[ch]. The hash table now uses
Timo Sirainen <tss@iki.fi>
parents:
5632
diff
changeset
|
761 while (hash_iterate(iter, &key, &value)) { |
f655c4d4a419
Moved child process handling to child-process.[ch]. The hash table now uses
Timo Sirainen <tss@iki.fi>
parents:
5632
diff
changeset
|
762 struct login_process *p = value; |
f655c4d4a419
Moved child process handling to child-process.[ch]. The hash table now uses
Timo Sirainen <tss@iki.fi>
parents:
5632
diff
changeset
|
763 |
f655c4d4a419
Moved child process handling to child-process.[ch]. The hash table now uses
Timo Sirainen <tss@iki.fi>
parents:
5632
diff
changeset
|
764 if (p->process.type == PROCESS_TYPE_LOGIN) |
f655c4d4a419
Moved child process handling to child-process.[ch]. The hash table now uses
Timo Sirainen <tss@iki.fi>
parents:
5632
diff
changeset
|
765 login_process_destroy(p); |
f655c4d4a419
Moved child process handling to child-process.[ch]. The hash table now uses
Timo Sirainen <tss@iki.fi>
parents:
5632
diff
changeset
|
766 } |
6417
047d0d8bbf0a
hash_destroy() and hash_iterate_deinit() now take ** pointer.
Timo Sirainen <tss@iki.fi>
parents:
6411
diff
changeset
|
767 hash_iterate_deinit(&iter); |
635
90a65c017bf0
SIGHUP reloads now settings. Logged in clients are left untouched, but
Timo Sirainen <tss@iki.fi>
parents:
615
diff
changeset
|
768 |
1055
a72bba3f8a55
Rewrote setting handling. Changed some existing settings also since POP3
Timo Sirainen <tss@iki.fi>
parents:
1039
diff
changeset
|
769 while (login_groups != NULL) { |
a72bba3f8a55
Rewrote setting handling. Changed some existing settings also since POP3
Timo Sirainen <tss@iki.fi>
parents:
1039
diff
changeset
|
770 struct login_group *group = login_groups; |
a72bba3f8a55
Rewrote setting handling. Changed some existing settings also since POP3
Timo Sirainen <tss@iki.fi>
parents:
1039
diff
changeset
|
771 |
a72bba3f8a55
Rewrote setting handling. Changed some existing settings also since POP3
Timo Sirainen <tss@iki.fi>
parents:
1039
diff
changeset
|
772 login_groups = group->next; |
4631
f5d53a684856
SIGHUP caused memory corruption
Timo Sirainen <tss@iki.fi>
parents:
4630
diff
changeset
|
773 login_group_unref(group); |
1055
a72bba3f8a55
Rewrote setting handling. Changed some existing settings also since POP3
Timo Sirainen <tss@iki.fi>
parents:
1039
diff
changeset
|
774 } |
a72bba3f8a55
Rewrote setting handling. Changed some existing settings also since POP3
Timo Sirainen <tss@iki.fi>
parents:
1039
diff
changeset
|
775 } |
a72bba3f8a55
Rewrote setting handling. Changed some existing settings also since POP3
Timo Sirainen <tss@iki.fi>
parents:
1039
diff
changeset
|
776 |
4538
9d9e72374164
Fixes to login process handling, especially with
Timo Sirainen <tss@iki.fi>
parents:
4388
diff
changeset
|
777 static void login_processes_notify_group(struct login_group *group) |
9d9e72374164
Fixes to login process handling, especially with
Timo Sirainen <tss@iki.fi>
parents:
4388
diff
changeset
|
778 { |
9d9e72374164
Fixes to login process handling, especially with
Timo Sirainen <tss@iki.fi>
parents:
4388
diff
changeset
|
779 struct hash_iterate_context *iter; |
9d9e72374164
Fixes to login process handling, especially with
Timo Sirainen <tss@iki.fi>
parents:
4388
diff
changeset
|
780 struct master_login_reply reply; |
9d9e72374164
Fixes to login process handling, especially with
Timo Sirainen <tss@iki.fi>
parents:
4388
diff
changeset
|
781 void *key, *value; |
9d9e72374164
Fixes to login process handling, especially with
Timo Sirainen <tss@iki.fi>
parents:
4388
diff
changeset
|
782 |
9d9e72374164
Fixes to login process handling, especially with
Timo Sirainen <tss@iki.fi>
parents:
4388
diff
changeset
|
783 memset(&reply, 0, sizeof(reply)); |
9d9e72374164
Fixes to login process handling, especially with
Timo Sirainen <tss@iki.fi>
parents:
4388
diff
changeset
|
784 |
9d9e72374164
Fixes to login process handling, especially with
Timo Sirainen <tss@iki.fi>
parents:
4388
diff
changeset
|
785 iter = hash_iterate_init(processes); |
9d9e72374164
Fixes to login process handling, especially with
Timo Sirainen <tss@iki.fi>
parents:
4388
diff
changeset
|
786 while (hash_iterate(iter, &key, &value)) { |
9d9e72374164
Fixes to login process handling, especially with
Timo Sirainen <tss@iki.fi>
parents:
4388
diff
changeset
|
787 struct login_process *p = value; |
9d9e72374164
Fixes to login process handling, especially with
Timo Sirainen <tss@iki.fi>
parents:
4388
diff
changeset
|
788 |
5843
f655c4d4a419
Moved child process handling to child-process.[ch]. The hash table now uses
Timo Sirainen <tss@iki.fi>
parents:
5632
diff
changeset
|
789 if (p->process.type == PROCESS_TYPE_LOGIN && p->group == group) |
4538
9d9e72374164
Fixes to login process handling, especially with
Timo Sirainen <tss@iki.fi>
parents:
4388
diff
changeset
|
790 (void)o_stream_send(p->output, &reply, sizeof(reply)); |
9d9e72374164
Fixes to login process handling, especially with
Timo Sirainen <tss@iki.fi>
parents:
4388
diff
changeset
|
791 } |
6417
047d0d8bbf0a
hash_destroy() and hash_iterate_deinit() now take ** pointer.
Timo Sirainen <tss@iki.fi>
parents:
6411
diff
changeset
|
792 hash_iterate_deinit(&iter); |
4538
9d9e72374164
Fixes to login process handling, especially with
Timo Sirainen <tss@iki.fi>
parents:
4388
diff
changeset
|
793 } |
9d9e72374164
Fixes to login process handling, especially with
Timo Sirainen <tss@iki.fi>
parents:
4388
diff
changeset
|
794 |
4148
f60d73c96618
If master process runs out of file descriptors, try to handle it more nicely
Timo Sirainen <tss@iki.fi>
parents:
3901
diff
changeset
|
795 static int login_group_start_missings(struct login_group *group) |
1055
a72bba3f8a55
Rewrote setting handling. Changed some existing settings also since POP3
Timo Sirainen <tss@iki.fi>
parents:
1039
diff
changeset
|
796 { |
4538
9d9e72374164
Fixes to login process handling, especially with
Timo Sirainen <tss@iki.fi>
parents:
4388
diff
changeset
|
797 if (group->set->login_process_per_connection && |
9d9e72374164
Fixes to login process handling, especially with
Timo Sirainen <tss@iki.fi>
parents:
4388
diff
changeset
|
798 group->processes >= group->set->login_max_processes_count && |
9d9e72374164
Fixes to login process handling, especially with
Timo Sirainen <tss@iki.fi>
parents:
4388
diff
changeset
|
799 group->listening_processes == 0) { |
9d9e72374164
Fixes to login process handling, especially with
Timo Sirainen <tss@iki.fi>
parents:
4388
diff
changeset
|
800 /* destroy the oldest listening process. non-listening |
9d9e72374164
Fixes to login process handling, especially with
Timo Sirainen <tss@iki.fi>
parents:
4388
diff
changeset
|
801 processes are logged in users who we don't want to kick out |
9d9e72374164
Fixes to login process handling, especially with
Timo Sirainen <tss@iki.fi>
parents:
4388
diff
changeset
|
802 because someone's started flooding */ |
4661
885bef091d1a
Make sure we don't kill login processes that haven't yet even sent their
Timo Sirainen <tss@iki.fi>
parents:
4651
diff
changeset
|
803 if (group->oldest_prelogin_process != NULL && |
885bef091d1a
Make sure we don't kill login processes that haven't yet even sent their
Timo Sirainen <tss@iki.fi>
parents:
4651
diff
changeset
|
804 group->oldest_prelogin_process->initialized) |
4538
9d9e72374164
Fixes to login process handling, especially with
Timo Sirainen <tss@iki.fi>
parents:
4388
diff
changeset
|
805 login_process_destroy(group->oldest_prelogin_process); |
1055
a72bba3f8a55
Rewrote setting handling. Changed some existing settings also since POP3
Timo Sirainen <tss@iki.fi>
parents:
1039
diff
changeset
|
806 } |
a72bba3f8a55
Rewrote setting handling. Changed some existing settings also since POP3
Timo Sirainen <tss@iki.fi>
parents:
1039
diff
changeset
|
807 |
a72bba3f8a55
Rewrote setting handling. Changed some existing settings also since POP3
Timo Sirainen <tss@iki.fi>
parents:
1039
diff
changeset
|
808 /* we want to respond fast when multiple clients are connecting |
a72bba3f8a55
Rewrote setting handling. Changed some existing settings also since POP3
Timo Sirainen <tss@iki.fi>
parents:
1039
diff
changeset
|
809 at once, but we also want to prevent fork-bombing. use the |
a72bba3f8a55
Rewrote setting handling. Changed some existing settings also since POP3
Timo Sirainen <tss@iki.fi>
parents:
1039
diff
changeset
|
810 same method as apache: check once a second if we need new |
a72bba3f8a55
Rewrote setting handling. Changed some existing settings also since POP3
Timo Sirainen <tss@iki.fi>
parents:
1039
diff
changeset
|
811 processes. if yes and we've used all the existing processes, |
a72bba3f8a55
Rewrote setting handling. Changed some existing settings also since POP3
Timo Sirainen <tss@iki.fi>
parents:
1039
diff
changeset
|
812 double their amount (unless we've hit the high limit). |
a72bba3f8a55
Rewrote setting handling. Changed some existing settings also since POP3
Timo Sirainen <tss@iki.fi>
parents:
1039
diff
changeset
|
813 Then for each second that didn't use all existing processes, |
a72bba3f8a55
Rewrote setting handling. Changed some existing settings also since POP3
Timo Sirainen <tss@iki.fi>
parents:
1039
diff
changeset
|
814 drop the max. process count by one. */ |
1610
6850142c4e25
New configuration file code. Some syntax changes, but tries to be somewhat
Timo Sirainen <tss@iki.fi>
parents:
1506
diff
changeset
|
815 if (group->wanted_processes_count < group->set->login_processes_count) { |
6850142c4e25
New configuration file code. Some syntax changes, but tries to be somewhat
Timo Sirainen <tss@iki.fi>
parents:
1506
diff
changeset
|
816 group->wanted_processes_count = |
6850142c4e25
New configuration file code. Some syntax changes, but tries to be somewhat
Timo Sirainen <tss@iki.fi>
parents:
1506
diff
changeset
|
817 group->set->login_processes_count; |
6850142c4e25
New configuration file code. Some syntax changes, but tries to be somewhat
Timo Sirainen <tss@iki.fi>
parents:
1506
diff
changeset
|
818 } else if (group->listening_processes == 0) |
1055
a72bba3f8a55
Rewrote setting handling. Changed some existing settings also since POP3
Timo Sirainen <tss@iki.fi>
parents:
1039
diff
changeset
|
819 group->wanted_processes_count *= 2; |
1610
6850142c4e25
New configuration file code. Some syntax changes, but tries to be somewhat
Timo Sirainen <tss@iki.fi>
parents:
1506
diff
changeset
|
820 else if (group->wanted_processes_count > |
6850142c4e25
New configuration file code. Some syntax changes, but tries to be somewhat
Timo Sirainen <tss@iki.fi>
parents:
1506
diff
changeset
|
821 group->set->login_processes_count) |
1055
a72bba3f8a55
Rewrote setting handling. Changed some existing settings also since POP3
Timo Sirainen <tss@iki.fi>
parents:
1039
diff
changeset
|
822 group->wanted_processes_count--; |
a72bba3f8a55
Rewrote setting handling. Changed some existing settings also since POP3
Timo Sirainen <tss@iki.fi>
parents:
1039
diff
changeset
|
823 |
4538
9d9e72374164
Fixes to login process handling, especially with
Timo Sirainen <tss@iki.fi>
parents:
4388
diff
changeset
|
824 while (group->listening_processes < group->wanted_processes_count && |
9d9e72374164
Fixes to login process handling, especially with
Timo Sirainen <tss@iki.fi>
parents:
4388
diff
changeset
|
825 group->processes < group->set->login_max_processes_count) { |
9d9e72374164
Fixes to login process handling, especially with
Timo Sirainen <tss@iki.fi>
parents:
4388
diff
changeset
|
826 if (create_login_process(group) < 0) |
9d9e72374164
Fixes to login process handling, especially with
Timo Sirainen <tss@iki.fi>
parents:
4388
diff
changeset
|
827 return -1; |
1610
6850142c4e25
New configuration file code. Some syntax changes, but tries to be somewhat
Timo Sirainen <tss@iki.fi>
parents:
1506
diff
changeset
|
828 } |
1055
a72bba3f8a55
Rewrote setting handling. Changed some existing settings also since POP3
Timo Sirainen <tss@iki.fi>
parents:
1039
diff
changeset
|
829 |
4538
9d9e72374164
Fixes to login process handling, especially with
Timo Sirainen <tss@iki.fi>
parents:
4388
diff
changeset
|
830 if (group->listening_processes == 0 && |
9d9e72374164
Fixes to login process handling, especially with
Timo Sirainen <tss@iki.fi>
parents:
4388
diff
changeset
|
831 !group->set->login_process_per_connection) { |
9d9e72374164
Fixes to login process handling, especially with
Timo Sirainen <tss@iki.fi>
parents:
4388
diff
changeset
|
832 /* we've reached our limit. notify the processes to start |
9d9e72374164
Fixes to login process handling, especially with
Timo Sirainen <tss@iki.fi>
parents:
4388
diff
changeset
|
833 listening again which makes them kill some of their |
9d9e72374164
Fixes to login process handling, especially with
Timo Sirainen <tss@iki.fi>
parents:
4388
diff
changeset
|
834 oldest clients when accepting the next connection */ |
9d9e72374164
Fixes to login process handling, especially with
Timo Sirainen <tss@iki.fi>
parents:
4388
diff
changeset
|
835 login_processes_notify_group(group); |
4148
f60d73c96618
If master process runs out of file descriptors, try to handle it more nicely
Timo Sirainen <tss@iki.fi>
parents:
3901
diff
changeset
|
836 } |
f60d73c96618
If master process runs out of file descriptors, try to handle it more nicely
Timo Sirainen <tss@iki.fi>
parents:
3901
diff
changeset
|
837 return 0; |
635
90a65c017bf0
SIGHUP reloads now settings. Logged in clients are left untouched, but
Timo Sirainen <tss@iki.fi>
parents:
615
diff
changeset
|
838 } |
90a65c017bf0
SIGHUP reloads now settings. Logged in clients are left untouched, but
Timo Sirainen <tss@iki.fi>
parents:
615
diff
changeset
|
839 |
4148
f60d73c96618
If master process runs out of file descriptors, try to handle it more nicely
Timo Sirainen <tss@iki.fi>
parents:
3901
diff
changeset
|
840 static void login_processes_stall(void) |
f60d73c96618
If master process runs out of file descriptors, try to handle it more nicely
Timo Sirainen <tss@iki.fi>
parents:
3901
diff
changeset
|
841 { |
4665 | 842 if (logins_stalled || IS_INETD()) |
4148
f60d73c96618
If master process runs out of file descriptors, try to handle it more nicely
Timo Sirainen <tss@iki.fi>
parents:
3901
diff
changeset
|
843 return; |
f60d73c96618
If master process runs out of file descriptors, try to handle it more nicely
Timo Sirainen <tss@iki.fi>
parents:
3901
diff
changeset
|
844 |
f60d73c96618
If master process runs out of file descriptors, try to handle it more nicely
Timo Sirainen <tss@iki.fi>
parents:
3901
diff
changeset
|
845 i_error("Temporary failure in creating login processes, " |
f60d73c96618
If master process runs out of file descriptors, try to handle it more nicely
Timo Sirainen <tss@iki.fi>
parents:
3901
diff
changeset
|
846 "slowing down for now"); |
f60d73c96618
If master process runs out of file descriptors, try to handle it more nicely
Timo Sirainen <tss@iki.fi>
parents:
3901
diff
changeset
|
847 logins_stalled = TRUE; |
f60d73c96618
If master process runs out of file descriptors, try to handle it more nicely
Timo Sirainen <tss@iki.fi>
parents:
3901
diff
changeset
|
848 |
f60d73c96618
If master process runs out of file descriptors, try to handle it more nicely
Timo Sirainen <tss@iki.fi>
parents:
3901
diff
changeset
|
849 timeout_remove(&to); |
f60d73c96618
If master process runs out of file descriptors, try to handle it more nicely
Timo Sirainen <tss@iki.fi>
parents:
3901
diff
changeset
|
850 to = timeout_add(60*1000, login_processes_start_missing, NULL); |
f60d73c96618
If master process runs out of file descriptors, try to handle it more nicely
Timo Sirainen <tss@iki.fi>
parents:
3901
diff
changeset
|
851 } |
f60d73c96618
If master process runs out of file descriptors, try to handle it more nicely
Timo Sirainen <tss@iki.fi>
parents:
3901
diff
changeset
|
852 |
903
fd8888f6f037
Naming style changes, finally got tired of most of the typedefs. Also the
Timo Sirainen <tss@iki.fi>
parents:
876
diff
changeset
|
853 static void |
6411
6a64e64fa3a3
Renamed __attr_*__ to ATTR_*. Renamed __attrs_used__ to ATTRS_DEFINED.
Timo Sirainen <tss@iki.fi>
parents:
6396
diff
changeset
|
854 login_processes_start_missing(void *context ATTR_UNUSED) |
0 | 855 { |
1055
a72bba3f8a55
Rewrote setting handling. Changed some existing settings also since POP3
Timo Sirainen <tss@iki.fi>
parents:
1039
diff
changeset
|
856 struct login_group *group; |
614
e60620644af3
login_process_per_connection = yes scales now better when multiple users are
Timo Sirainen <tss@iki.fi>
parents:
613
diff
changeset
|
857 |
5136
86625faa49b5
Start auth processes immediately at startup, not after one second delay.
Timo Sirainen <tss@iki.fi>
parents:
5089
diff
changeset
|
858 if (!have_initialized_auth_processes) { |
86625faa49b5
Start auth processes immediately at startup, not after one second delay.
Timo Sirainen <tss@iki.fi>
parents:
5089
diff
changeset
|
859 /* don't create login processes before at least one auth |
86625faa49b5
Start auth processes immediately at startup, not after one second delay.
Timo Sirainen <tss@iki.fi>
parents:
5089
diff
changeset
|
860 process has finished initializing */ |
86625faa49b5
Start auth processes immediately at startup, not after one second delay.
Timo Sirainen <tss@iki.fi>
parents:
5089
diff
changeset
|
861 return; |
86625faa49b5
Start auth processes immediately at startup, not after one second delay.
Timo Sirainen <tss@iki.fi>
parents:
5089
diff
changeset
|
862 } |
86625faa49b5
Start auth processes immediately at startup, not after one second delay.
Timo Sirainen <tss@iki.fi>
parents:
5089
diff
changeset
|
863 |
1610
6850142c4e25
New configuration file code. Some syntax changes, but tries to be somewhat
Timo Sirainen <tss@iki.fi>
parents:
1506
diff
changeset
|
864 if (login_groups == NULL) |
6850142c4e25
New configuration file code. Some syntax changes, but tries to be somewhat
Timo Sirainen <tss@iki.fi>
parents:
1506
diff
changeset
|
865 login_process_groups_create(); |
614
e60620644af3
login_process_per_connection = yes scales now better when multiple users are
Timo Sirainen <tss@iki.fi>
parents:
613
diff
changeset
|
866 |
4148
f60d73c96618
If master process runs out of file descriptors, try to handle it more nicely
Timo Sirainen <tss@iki.fi>
parents:
3901
diff
changeset
|
867 for (group = login_groups; group != NULL; group = group->next) { |
f60d73c96618
If master process runs out of file descriptors, try to handle it more nicely
Timo Sirainen <tss@iki.fi>
parents:
3901
diff
changeset
|
868 if (login_group_start_missings(group) < 0) { |
f60d73c96618
If master process runs out of file descriptors, try to handle it more nicely
Timo Sirainen <tss@iki.fi>
parents:
3901
diff
changeset
|
869 login_processes_stall(); |
f60d73c96618
If master process runs out of file descriptors, try to handle it more nicely
Timo Sirainen <tss@iki.fi>
parents:
3901
diff
changeset
|
870 return; |
f60d73c96618
If master process runs out of file descriptors, try to handle it more nicely
Timo Sirainen <tss@iki.fi>
parents:
3901
diff
changeset
|
871 } |
f60d73c96618
If master process runs out of file descriptors, try to handle it more nicely
Timo Sirainen <tss@iki.fi>
parents:
3901
diff
changeset
|
872 } |
0 | 873 } |
874 | |
1273
2cf2e08a6ee9
Somewhat working code to support loading Dovecot from inetd and such. It
Timo Sirainen <tss@iki.fi>
parents:
1237
diff
changeset
|
875 static int login_process_send_env(struct login_process *p) |
2cf2e08a6ee9
Somewhat working code to support loading Dovecot from inetd and such. It
Timo Sirainen <tss@iki.fi>
parents:
1237
diff
changeset
|
876 { |
7109
e6823d781317
Reverted "environment array" changes. It broke overriding imap/pop3 settings
Timo Sirainen <tss@iki.fi>
parents:
7091
diff
changeset
|
877 extern char **environ; |
e6823d781317
Reverted "environment array" changes. It broke overriding imap/pop3 settings
Timo Sirainen <tss@iki.fi>
parents:
7091
diff
changeset
|
878 char **env; |
3607
a2dd3d895e00
Several fixes to make running from inetd working again
Timo Sirainen <tss@iki.fi>
parents:
3384
diff
changeset
|
879 ssize_t len; |
1273
2cf2e08a6ee9
Somewhat working code to support loading Dovecot from inetd and such. It
Timo Sirainen <tss@iki.fi>
parents:
1237
diff
changeset
|
880 int ret = 0; |
2cf2e08a6ee9
Somewhat working code to support loading Dovecot from inetd and such. It
Timo Sirainen <tss@iki.fi>
parents:
1237
diff
changeset
|
881 |
2cf2e08a6ee9
Somewhat working code to support loading Dovecot from inetd and such. It
Timo Sirainen <tss@iki.fi>
parents:
1237
diff
changeset
|
882 /* this will clear our environment. luckily we don't need it. */ |
7109
e6823d781317
Reverted "environment array" changes. It broke overriding imap/pop3 settings
Timo Sirainen <tss@iki.fi>
parents:
7091
diff
changeset
|
883 login_process_init_env(p->group, p->pid); |
1273
2cf2e08a6ee9
Somewhat working code to support loading Dovecot from inetd and such. It
Timo Sirainen <tss@iki.fi>
parents:
1237
diff
changeset
|
884 |
7109
e6823d781317
Reverted "environment array" changes. It broke overriding imap/pop3 settings
Timo Sirainen <tss@iki.fi>
parents:
7091
diff
changeset
|
885 for (env = environ; *env != NULL; env++) { |
e6823d781317
Reverted "environment array" changes. It broke overriding imap/pop3 settings
Timo Sirainen <tss@iki.fi>
parents:
7091
diff
changeset
|
886 len = strlen(*env); |
1273
2cf2e08a6ee9
Somewhat working code to support loading Dovecot from inetd and such. It
Timo Sirainen <tss@iki.fi>
parents:
1237
diff
changeset
|
887 |
7109
e6823d781317
Reverted "environment array" changes. It broke overriding imap/pop3 settings
Timo Sirainen <tss@iki.fi>
parents:
7091
diff
changeset
|
888 if (o_stream_send(p->output, *env, len) != len || |
1273
2cf2e08a6ee9
Somewhat working code to support loading Dovecot from inetd and such. It
Timo Sirainen <tss@iki.fi>
parents:
1237
diff
changeset
|
889 o_stream_send(p->output, "\n", 1) != 1) { |
2cf2e08a6ee9
Somewhat working code to support loading Dovecot from inetd and such. It
Timo Sirainen <tss@iki.fi>
parents:
1237
diff
changeset
|
890 ret = -1; |
2cf2e08a6ee9
Somewhat working code to support loading Dovecot from inetd and such. It
Timo Sirainen <tss@iki.fi>
parents:
1237
diff
changeset
|
891 break; |
2cf2e08a6ee9
Somewhat working code to support loading Dovecot from inetd and such. It
Timo Sirainen <tss@iki.fi>
parents:
1237
diff
changeset
|
892 } |
2cf2e08a6ee9
Somewhat working code to support loading Dovecot from inetd and such. It
Timo Sirainen <tss@iki.fi>
parents:
1237
diff
changeset
|
893 } |
2cf2e08a6ee9
Somewhat working code to support loading Dovecot from inetd and such. It
Timo Sirainen <tss@iki.fi>
parents:
1237
diff
changeset
|
894 |
3607
a2dd3d895e00
Several fixes to make running from inetd working again
Timo Sirainen <tss@iki.fi>
parents:
3384
diff
changeset
|
895 if (!p->group->set->login_chroot) { |
a2dd3d895e00
Several fixes to make running from inetd working again
Timo Sirainen <tss@iki.fi>
parents:
3384
diff
changeset
|
896 /* if we're not chrooting, we need to tell login process |
a2dd3d895e00
Several fixes to make running from inetd working again
Timo Sirainen <tss@iki.fi>
parents:
3384
diff
changeset
|
897 where its base directory is */ |
a2dd3d895e00
Several fixes to make running from inetd working again
Timo Sirainen <tss@iki.fi>
parents:
3384
diff
changeset
|
898 const char *str = t_strdup_printf("LOGIN_DIR=%s\n", |
a2dd3d895e00
Several fixes to make running from inetd working again
Timo Sirainen <tss@iki.fi>
parents:
3384
diff
changeset
|
899 p->group->set->login_dir); |
a2dd3d895e00
Several fixes to make running from inetd working again
Timo Sirainen <tss@iki.fi>
parents:
3384
diff
changeset
|
900 len = strlen(str); |
a2dd3d895e00
Several fixes to make running from inetd working again
Timo Sirainen <tss@iki.fi>
parents:
3384
diff
changeset
|
901 if (o_stream_send(p->output, str, len) != len) |
a2dd3d895e00
Several fixes to make running from inetd working again
Timo Sirainen <tss@iki.fi>
parents:
3384
diff
changeset
|
902 ret = -1; |
a2dd3d895e00
Several fixes to make running from inetd working again
Timo Sirainen <tss@iki.fi>
parents:
3384
diff
changeset
|
903 } |
a2dd3d895e00
Several fixes to make running from inetd working again
Timo Sirainen <tss@iki.fi>
parents:
3384
diff
changeset
|
904 |
1273
2cf2e08a6ee9
Somewhat working code to support loading Dovecot from inetd and such. It
Timo Sirainen <tss@iki.fi>
parents:
1237
diff
changeset
|
905 if (ret == 0 && o_stream_send(p->output, "\n", 1) != 1) |
2cf2e08a6ee9
Somewhat working code to support loading Dovecot from inetd and such. It
Timo Sirainen <tss@iki.fi>
parents:
1237
diff
changeset
|
906 ret = -1; |
2cf2e08a6ee9
Somewhat working code to support loading Dovecot from inetd and such. It
Timo Sirainen <tss@iki.fi>
parents:
1237
diff
changeset
|
907 |
2cf2e08a6ee9
Somewhat working code to support loading Dovecot from inetd and such. It
Timo Sirainen <tss@iki.fi>
parents:
1237
diff
changeset
|
908 env_clean(); |
2cf2e08a6ee9
Somewhat working code to support loading Dovecot from inetd and such. It
Timo Sirainen <tss@iki.fi>
parents:
1237
diff
changeset
|
909 return ret; |
2cf2e08a6ee9
Somewhat working code to support loading Dovecot from inetd and such. It
Timo Sirainen <tss@iki.fi>
parents:
1237
diff
changeset
|
910 } |
2cf2e08a6ee9
Somewhat working code to support loading Dovecot from inetd and such. It
Timo Sirainen <tss@iki.fi>
parents:
1237
diff
changeset
|
911 |
3863
55df57c028d4
Added "bool" type and changed all ints that were used as booleans to bool.
Timo Sirainen <tss@iki.fi>
parents:
3692
diff
changeset
|
912 static bool login_process_init_group(struct login_process *p) |
1275
af685269ead0
login: Wait until we're connected to auth process before executing command
Timo Sirainen <tss@iki.fi>
parents:
1273
diff
changeset
|
913 { |
4740
0a1fa29ac87f
inetd logins kept crashing dovecot master.
Timo Sirainen <tss@iki.fi>
parents:
4734
diff
changeset
|
914 p->group->refcount++; |
1275
af685269ead0
login: Wait until we're connected to auth process before executing command
Timo Sirainen <tss@iki.fi>
parents:
1273
diff
changeset
|
915 p->group->processes++; |
af685269ead0
login: Wait until we're connected to auth process before executing command
Timo Sirainen <tss@iki.fi>
parents:
1273
diff
changeset
|
916 p->group->listening_processes++; |
af685269ead0
login: Wait until we're connected to auth process before executing command
Timo Sirainen <tss@iki.fi>
parents:
1273
diff
changeset
|
917 |
7109
e6823d781317
Reverted "environment array" changes. It broke overriding imap/pop3 settings
Timo Sirainen <tss@iki.fi>
parents:
7091
diff
changeset
|
918 if (login_process_send_env(p) < 0) { |
1275
af685269ead0
login: Wait until we're connected to auth process before executing command
Timo Sirainen <tss@iki.fi>
parents:
1273
diff
changeset
|
919 i_error("login: Couldn't send environment"); |
af685269ead0
login: Wait until we're connected to auth process before executing command
Timo Sirainen <tss@iki.fi>
parents:
1273
diff
changeset
|
920 return FALSE; |
af685269ead0
login: Wait until we're connected to auth process before executing command
Timo Sirainen <tss@iki.fi>
parents:
1273
diff
changeset
|
921 } |
af685269ead0
login: Wait until we're connected to auth process before executing command
Timo Sirainen <tss@iki.fi>
parents:
1273
diff
changeset
|
922 |
af685269ead0
login: Wait until we're connected to auth process before executing command
Timo Sirainen <tss@iki.fi>
parents:
1273
diff
changeset
|
923 return TRUE; |
af685269ead0
login: Wait until we're connected to auth process before executing command
Timo Sirainen <tss@iki.fi>
parents:
1273
diff
changeset
|
924 } |
af685269ead0
login: Wait until we're connected to auth process before executing command
Timo Sirainen <tss@iki.fi>
parents:
1273
diff
changeset
|
925 |
6411
6a64e64fa3a3
Renamed __attr_*__ to ATTR_*. Renamed __attrs_used__ to ATTRS_DEFINED.
Timo Sirainen <tss@iki.fi>
parents:
6396
diff
changeset
|
926 static void inetd_login_accept(void *context ATTR_UNUSED) |
1273
2cf2e08a6ee9
Somewhat working code to support loading Dovecot from inetd and such. It
Timo Sirainen <tss@iki.fi>
parents:
1237
diff
changeset
|
927 { |
2cf2e08a6ee9
Somewhat working code to support loading Dovecot from inetd and such. It
Timo Sirainen <tss@iki.fi>
parents:
1237
diff
changeset
|
928 struct login_process *p; |
2cf2e08a6ee9
Somewhat working code to support loading Dovecot from inetd and such. It
Timo Sirainen <tss@iki.fi>
parents:
1237
diff
changeset
|
929 int fd; |
2cf2e08a6ee9
Somewhat working code to support loading Dovecot from inetd and such. It
Timo Sirainen <tss@iki.fi>
parents:
1237
diff
changeset
|
930 |
2cf2e08a6ee9
Somewhat working code to support loading Dovecot from inetd and such. It
Timo Sirainen <tss@iki.fi>
parents:
1237
diff
changeset
|
931 fd = net_accept(inetd_login_fd, NULL, NULL); |
2cf2e08a6ee9
Somewhat working code to support loading Dovecot from inetd and such. It
Timo Sirainen <tss@iki.fi>
parents:
1237
diff
changeset
|
932 if (fd < 0) { |
2cf2e08a6ee9
Somewhat working code to support loading Dovecot from inetd and such. It
Timo Sirainen <tss@iki.fi>
parents:
1237
diff
changeset
|
933 if (fd < -1) |
5358
a977ad033903
net_listen_unix() API changed a bit. -1 is now returned for errors that can
Timo Sirainen <tss@iki.fi>
parents:
5136
diff
changeset
|
934 i_error("accept(inetd_login_fd) failed: %m"); |
1273
2cf2e08a6ee9
Somewhat working code to support loading Dovecot from inetd and such. It
Timo Sirainen <tss@iki.fi>
parents:
1237
diff
changeset
|
935 } else { |
2cf2e08a6ee9
Somewhat working code to support loading Dovecot from inetd and such. It
Timo Sirainen <tss@iki.fi>
parents:
1237
diff
changeset
|
936 net_set_nonblock(fd, TRUE); |
2cf2e08a6ee9
Somewhat working code to support loading Dovecot from inetd and such. It
Timo Sirainen <tss@iki.fi>
parents:
1237
diff
changeset
|
937 fd_close_on_exec(fd, TRUE); |
2cf2e08a6ee9
Somewhat working code to support loading Dovecot from inetd and such. It
Timo Sirainen <tss@iki.fi>
parents:
1237
diff
changeset
|
938 |
6519
66e5f514355e
Login processes started by inetd aren't ours, don't treat them as such.
Timo Sirainen <tss@iki.fi>
parents:
6429
diff
changeset
|
939 p = login_process_new(NULL, ++login_pid_counter, fd, TRUE); |
1275
af685269ead0
login: Wait until we're connected to auth process before executing command
Timo Sirainen <tss@iki.fi>
parents:
1273
diff
changeset
|
940 p->initialized = TRUE; |
1273
2cf2e08a6ee9
Somewhat working code to support loading Dovecot from inetd and such. It
Timo Sirainen <tss@iki.fi>
parents:
1237
diff
changeset
|
941 } |
2cf2e08a6ee9
Somewhat working code to support loading Dovecot from inetd and such. It
Timo Sirainen <tss@iki.fi>
parents:
1237
diff
changeset
|
942 } |
2cf2e08a6ee9
Somewhat working code to support loading Dovecot from inetd and such. It
Timo Sirainen <tss@iki.fi>
parents:
1237
diff
changeset
|
943 |
0 | 944 void login_processes_init(void) |
945 { | |
1273
2cf2e08a6ee9
Somewhat working code to support loading Dovecot from inetd and such. It
Timo Sirainen <tss@iki.fi>
parents:
1237
diff
changeset
|
946 auth_id_counter = 0; |
2cf2e08a6ee9
Somewhat working code to support loading Dovecot from inetd and such. It
Timo Sirainen <tss@iki.fi>
parents:
1237
diff
changeset
|
947 login_pid_counter = 0; |
1055
a72bba3f8a55
Rewrote setting handling. Changed some existing settings also since POP3
Timo Sirainen <tss@iki.fi>
parents:
1039
diff
changeset
|
948 login_groups = NULL; |
613
1906116a62ce
Finally support for handling each login connection in it's own process.
Timo Sirainen <tss@iki.fi>
parents:
596
diff
changeset
|
949 |
5843
f655c4d4a419
Moved child process handling to child-process.[ch]. The hash table now uses
Timo Sirainen <tss@iki.fi>
parents:
5632
diff
changeset
|
950 child_process_set_destroy_callback(PROCESS_TYPE_LOGIN, |
f655c4d4a419
Moved child process handling to child-process.[ch]. The hash table now uses
Timo Sirainen <tss@iki.fi>
parents:
5632
diff
changeset
|
951 login_process_destroyed); |
f655c4d4a419
Moved child process handling to child-process.[ch]. The hash table now uses
Timo Sirainen <tss@iki.fi>
parents:
5632
diff
changeset
|
952 |
1273
2cf2e08a6ee9
Somewhat working code to support loading Dovecot from inetd and such. It
Timo Sirainen <tss@iki.fi>
parents:
1237
diff
changeset
|
953 if (!IS_INETD()) { |
2cf2e08a6ee9
Somewhat working code to support loading Dovecot from inetd and such. It
Timo Sirainen <tss@iki.fi>
parents:
1237
diff
changeset
|
954 to = timeout_add(1000, login_processes_start_missing, NULL); |
2cf2e08a6ee9
Somewhat working code to support loading Dovecot from inetd and such. It
Timo Sirainen <tss@iki.fi>
parents:
1237
diff
changeset
|
955 io_listen = NULL; |
2cf2e08a6ee9
Somewhat working code to support loading Dovecot from inetd and such. It
Timo Sirainen <tss@iki.fi>
parents:
1237
diff
changeset
|
956 } else { |
2cf2e08a6ee9
Somewhat working code to support loading Dovecot from inetd and such. It
Timo Sirainen <tss@iki.fi>
parents:
1237
diff
changeset
|
957 to = NULL; |
2cf2e08a6ee9
Somewhat working code to support loading Dovecot from inetd and such. It
Timo Sirainen <tss@iki.fi>
parents:
1237
diff
changeset
|
958 io_listen = io_add(inetd_login_fd, IO_READ, |
2cf2e08a6ee9
Somewhat working code to support loading Dovecot from inetd and such. It
Timo Sirainen <tss@iki.fi>
parents:
1237
diff
changeset
|
959 inetd_login_accept, NULL); |
2cf2e08a6ee9
Somewhat working code to support loading Dovecot from inetd and such. It
Timo Sirainen <tss@iki.fi>
parents:
1237
diff
changeset
|
960 } |
0 | 961 } |
962 | |
963 void login_processes_deinit(void) | |
964 { | |
1273
2cf2e08a6ee9
Somewhat working code to support loading Dovecot from inetd and such. It
Timo Sirainen <tss@iki.fi>
parents:
1237
diff
changeset
|
965 if (to != NULL) |
3879
928229f8b3e6
deinit, unref, destroy, close, free, etc. functions now take a pointer to
Timo Sirainen <tss@iki.fi>
parents:
3863
diff
changeset
|
966 timeout_remove(&to); |
1273
2cf2e08a6ee9
Somewhat working code to support loading Dovecot from inetd and such. It
Timo Sirainen <tss@iki.fi>
parents:
1237
diff
changeset
|
967 if (io_listen != NULL) |
3879
928229f8b3e6
deinit, unref, destroy, close, free, etc. functions now take a pointer to
Timo Sirainen <tss@iki.fi>
parents:
3863
diff
changeset
|
968 io_remove(&io_listen); |
0 | 969 } |