Mercurial > dovecot > original-hg > dovecot-1.2
annotate src/master/login-process.c @ 3889:c7462001227b HEAD
Added support for password protected SSL private keys. The password can be
given in dovecot.conf, or when dovecot is started with -p parameter.
author | Timo Sirainen <tss@iki.fi> |
---|---|
date | Sun, 15 Jan 2006 15:16:53 +0200 |
parents | 928229f8b3e6 |
children | 0ae5f5b468b7 |
rev | line source |
---|---|
0 | 1 /* Copyright (C) 2002 Timo Sirainen */ |
2 | |
3 #include "common.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
|
4 #include "ioloop.h" |
0 | 5 #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
|
6 #include "ostream.h" |
0 | 7 #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
|
8 #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
|
9 #include "env-util.h" |
0 | 10 #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
|
11 #include "restrict-process-size.h" |
0 | 12 #include "login-process.h" |
13 #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
|
14 #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
|
15 #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
|
16 #include "log.h" |
0 | 17 |
18 #include <unistd.h> | |
19 #include <syslog.h> | |
20 | |
903
fd8888f6f037
Naming style changes, finally got tired of most of the typedefs. Also the
Timo Sirainen <tss@iki.fi>
parents:
876
diff
changeset
|
21 struct login_process { |
1055
a72bba3f8a55
Rewrote setting handling. Changed some existing settings also since POP3
Timo Sirainen <tss@iki.fi>
parents:
1039
diff
changeset
|
22 struct login_group *group; |
903
fd8888f6f037
Naming style changes, finally got tired of most of the typedefs. Also the
Timo Sirainen <tss@iki.fi>
parents:
876
diff
changeset
|
23 struct login_process *prev_nonlisten, *next_nonlisten; |
0 | 24 int refcount; |
25 | |
26 pid_t pid; | |
27 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
|
28 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
|
29 struct ostream *output; |
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
|
30 unsigned int initialized:1; |
613
1906116a62ce
Finally support for handling each login connection in it's own process.
Timo Sirainen <tss@iki.fi>
parents:
596
diff
changeset
|
31 unsigned int listening:1; |
0 | 32 unsigned int destroyed:1; |
613
1906116a62ce
Finally support for handling each login connection in it's own process.
Timo Sirainen <tss@iki.fi>
parents:
596
diff
changeset
|
33 }; |
0 | 34 |
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 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
|
36 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
|
37 unsigned int tag; |
fe49ece0f3ea
We have now separate "userdb" and "passdb". They aren't tied to each others
Timo Sirainen <tss@iki.fi>
parents:
1000
diff
changeset
|
38 |
fe49ece0f3ea
We have now separate "userdb" and "passdb". They aren't tied to each others
Timo Sirainen <tss@iki.fi>
parents:
1000
diff
changeset
|
39 unsigned int login_tag; |
0 | 40 int fd; |
41 | |
2097
4e77cb0aff21
Added %l, %r and %P variables and mail_log_prefix setting.
Timo Sirainen <tss@iki.fi>
parents:
2046
diff
changeset
|
42 struct ip_addr local_ip, remote_ip; |
903
fd8888f6f037
Naming style changes, finally got tired of most of the typedefs. Also the
Timo Sirainen <tss@iki.fi>
parents:
876
diff
changeset
|
43 }; |
0 | 44 |
1273
2cf2e08a6ee9
Somewhat working code to support loading Dovecot from inetd and such. It
Timo Sirainen <tss@iki.fi>
parents:
1237
diff
changeset
|
45 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
|
46 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
|
47 static struct io *io_listen; |
613
1906116a62ce
Finally support for handling each login connection in it's own process.
Timo Sirainen <tss@iki.fi>
parents:
596
diff
changeset
|
48 |
903
fd8888f6f037
Naming style changes, finally got tired of most of the typedefs. Also the
Timo Sirainen <tss@iki.fi>
parents:
876
diff
changeset
|
49 static struct hash_table *processes; |
1055
a72bba3f8a55
Rewrote setting handling. Changed some existing settings also since POP3
Timo Sirainen <tss@iki.fi>
parents:
1039
diff
changeset
|
50 static struct login_group *login_groups; |
0 | 51 |
903
fd8888f6f037
Naming style changes, finally got tired of most of the typedefs. Also the
Timo Sirainen <tss@iki.fi>
parents:
876
diff
changeset
|
52 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
|
53 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
|
54 static bool login_process_init_group(struct login_process *p); |
0 | 55 |
1610
6850142c4e25
New configuration file code. Some syntax changes, but tries to be somewhat
Timo Sirainen <tss@iki.fi>
parents:
1506
diff
changeset
|
56 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
|
57 { |
a72bba3f8a55
Rewrote setting handling. Changed some existing settings also since POP3
Timo Sirainen <tss@iki.fi>
parents:
1039
diff
changeset
|
58 struct login_group *group; |
a72bba3f8a55
Rewrote setting handling. Changed some existing settings also since POP3
Timo Sirainen <tss@iki.fi>
parents:
1039
diff
changeset
|
59 |
a72bba3f8a55
Rewrote setting handling. Changed some existing settings also since POP3
Timo Sirainen <tss@iki.fi>
parents:
1039
diff
changeset
|
60 group = i_new(struct login_group, 1); |
1610
6850142c4e25
New configuration file code. Some syntax changes, but tries to be somewhat
Timo Sirainen <tss@iki.fi>
parents:
1506
diff
changeset
|
61 group->set = set; |
6850142c4e25
New configuration file code. Some syntax changes, but tries to be somewhat
Timo Sirainen <tss@iki.fi>
parents:
1506
diff
changeset
|
62 group->process_type = set->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
|
63 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
|
64 |
a72bba3f8a55
Rewrote setting handling. Changed some existing settings also since POP3
Timo Sirainen <tss@iki.fi>
parents:
1039
diff
changeset
|
65 group->next = login_groups; |
a72bba3f8a55
Rewrote setting handling. Changed some existing settings also since POP3
Timo Sirainen <tss@iki.fi>
parents:
1039
diff
changeset
|
66 login_groups = group; |
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 |
a72bba3f8a55
Rewrote setting handling. Changed some existing settings also since POP3
Timo Sirainen <tss@iki.fi>
parents:
1039
diff
changeset
|
69 static void login_group_destroy(struct login_group *group) |
a72bba3f8a55
Rewrote setting handling. Changed some existing settings also since POP3
Timo Sirainen <tss@iki.fi>
parents:
1039
diff
changeset
|
70 { |
a72bba3f8a55
Rewrote setting handling. Changed some existing settings also since POP3
Timo Sirainen <tss@iki.fi>
parents:
1039
diff
changeset
|
71 i_free(group); |
a72bba3f8a55
Rewrote setting handling. Changed some existing settings also since POP3
Timo Sirainen <tss@iki.fi>
parents:
1039
diff
changeset
|
72 } |
a72bba3f8a55
Rewrote setting handling. Changed some existing settings also since POP3
Timo Sirainen <tss@iki.fi>
parents:
1039
diff
changeset
|
73 |
2736
0f31778d3c34
Changed dovecot-auth protocol to ASCII based. Should be easier now to write
Timo Sirainen <tss@iki.fi>
parents:
2691
diff
changeset
|
74 void auth_master_callback(const char *user, const char *const *args, |
0f31778d3c34
Changed dovecot-auth protocol to ASCII based. Should be easier now to write
Timo Sirainen <tss@iki.fi>
parents:
2691
diff
changeset
|
75 void *context) |
0 | 76 { |
903
fd8888f6f037
Naming style changes, finally got tired of most of the typedefs. Also the
Timo Sirainen <tss@iki.fi>
parents:
876
diff
changeset
|
77 struct login_auth_request *request = context; |
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
|
78 struct master_login_reply master_reply; |
2329 | 79 ssize_t ret; |
0 | 80 |
2736
0f31778d3c34
Changed dovecot-auth protocol to ASCII based. Should be easier now to write
Timo Sirainen <tss@iki.fi>
parents:
2691
diff
changeset
|
81 if (user == NULL) |
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
|
82 master_reply.success = FALSE; |
0 | 83 else { |
1055
a72bba3f8a55
Rewrote setting handling. Changed some existing settings also since POP3
Timo Sirainen <tss@iki.fi>
parents:
1039
diff
changeset
|
84 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
|
85 |
2097
4e77cb0aff21
Added %l, %r and %P variables and mail_log_prefix setting.
Timo Sirainen <tss@iki.fi>
parents:
2046
diff
changeset
|
86 t_push(); |
1039
793f05a7e50e
signed/unsigned/const pointer fixes
Timo Sirainen <tss@iki.fi>
parents:
1036
diff
changeset
|
87 master_reply.success = |
2097
4e77cb0aff21
Added %l, %r and %P variables and mail_log_prefix setting.
Timo Sirainen <tss@iki.fi>
parents:
2046
diff
changeset
|
88 create_mail_process(group, request->fd, |
4e77cb0aff21
Added %l, %r and %P variables and mail_log_prefix setting.
Timo Sirainen <tss@iki.fi>
parents:
2046
diff
changeset
|
89 &request->local_ip, |
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 &request->remote_ip, user, args); |
2097
4e77cb0aff21
Added %l, %r and %P variables and mail_log_prefix setting.
Timo Sirainen <tss@iki.fi>
parents:
2046
diff
changeset
|
91 t_pop(); |
0 | 92 } |
93 | |
94 /* 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
|
95 master_reply.tag = request->login_tag; |
0 | 96 |
2329 | 97 ret = o_stream_send(request->process->output, &master_reply, |
98 sizeof(master_reply)); | |
99 if (ret != sizeof(master_reply)) { | |
100 if (ret >= 0) { | |
101 i_warning("Login process %s transmit buffer full, " | |
102 "killing..", dec2str(request->process->pid)); | |
103 } | |
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
|
104 login_process_destroy(request->process); |
2329 | 105 } |
0 | 106 |
805
5ac361acb316
Marked all non-trivial buffer modifications with @UNSAFE tag. Several
Timo Sirainen <tss@iki.fi>
parents:
801
diff
changeset
|
107 if (close(request->fd) < 0) |
1055
a72bba3f8a55
Rewrote setting handling. Changed some existing settings also since POP3
Timo Sirainen <tss@iki.fi>
parents:
1039
diff
changeset
|
108 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
|
109 login_process_unref(request->process); |
0 | 110 i_free(request); |
111 } | |
112 | |
903
fd8888f6f037
Naming style changes, finally got tired of most of the typedefs. Also the
Timo Sirainen <tss@iki.fi>
parents:
876
diff
changeset
|
113 static void login_process_mark_nonlistening(struct login_process *p) |
614
e60620644af3
login_process_per_connection = yes scales now better when multiple users are
Timo Sirainen <tss@iki.fi>
parents:
613
diff
changeset
|
114 { |
e60620644af3
login_process_per_connection = yes scales now better when multiple users are
Timo Sirainen <tss@iki.fi>
parents:
613
diff
changeset
|
115 if (!p->listening) { |
e60620644af3
login_process_per_connection = yes scales now better when multiple users are
Timo Sirainen <tss@iki.fi>
parents:
613
diff
changeset
|
116 i_error("login: received another \"not listening\" " |
1338 | 117 "notification (if you can't login at all, " |
118 "see src/lib/fdpass.c)"); | |
614
e60620644af3
login_process_per_connection = yes scales now better when multiple users are
Timo Sirainen <tss@iki.fi>
parents:
613
diff
changeset
|
119 return; |
e60620644af3
login_process_per_connection = yes scales now better when multiple users are
Timo Sirainen <tss@iki.fi>
parents:
613
diff
changeset
|
120 } |
e60620644af3
login_process_per_connection = yes scales now better when multiple users are
Timo Sirainen <tss@iki.fi>
parents:
613
diff
changeset
|
121 |
e60620644af3
login_process_per_connection = yes scales now better when multiple users are
Timo Sirainen <tss@iki.fi>
parents:
613
diff
changeset
|
122 p->listening = FALSE; |
1275
af685269ead0
login: Wait until we're connected to auth process before executing command
Timo Sirainen <tss@iki.fi>
parents:
1273
diff
changeset
|
123 |
af685269ead0
login: Wait until we're connected to auth process before executing command
Timo Sirainen <tss@iki.fi>
parents:
1273
diff
changeset
|
124 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
|
125 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
|
126 p->prev_nonlisten = p->group->newest_nonlisten_process; |
af685269ead0
login: Wait until we're connected to auth process before executing command
Timo Sirainen <tss@iki.fi>
parents:
1273
diff
changeset
|
127 |
af685269ead0
login: Wait until we're connected to auth process before executing command
Timo Sirainen <tss@iki.fi>
parents:
1273
diff
changeset
|
128 if (p->group->newest_nonlisten_process != NULL) |
af685269ead0
login: Wait until we're connected to auth process before executing command
Timo Sirainen <tss@iki.fi>
parents:
1273
diff
changeset
|
129 p->group->newest_nonlisten_process->next_nonlisten = p; |
af685269ead0
login: Wait until we're connected to auth process before executing command
Timo Sirainen <tss@iki.fi>
parents:
1273
diff
changeset
|
130 p->group->newest_nonlisten_process = p; |
af685269ead0
login: Wait until we're connected to auth process before executing command
Timo Sirainen <tss@iki.fi>
parents:
1273
diff
changeset
|
131 |
af685269ead0
login: Wait until we're connected to auth process before executing command
Timo Sirainen <tss@iki.fi>
parents:
1273
diff
changeset
|
132 if (p->group->oldest_nonlisten_process == NULL) |
af685269ead0
login: Wait until we're connected to auth process before executing command
Timo Sirainen <tss@iki.fi>
parents:
1273
diff
changeset
|
133 p->group->oldest_nonlisten_process = p; |
af685269ead0
login: Wait until we're connected to auth process before executing command
Timo Sirainen <tss@iki.fi>
parents:
1273
diff
changeset
|
134 } |
af685269ead0
login: Wait until we're connected to auth process before executing command
Timo Sirainen <tss@iki.fi>
parents:
1273
diff
changeset
|
135 } |
614
e60620644af3
login_process_per_connection = yes scales now better when multiple users are
Timo Sirainen <tss@iki.fi>
parents:
613
diff
changeset
|
136 |
1610
6850142c4e25
New configuration file code. Some syntax changes, but tries to be somewhat
Timo Sirainen <tss@iki.fi>
parents:
1506
diff
changeset
|
137 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
|
138 { |
6850142c4e25
New configuration file code. Some syntax changes, but tries to be somewhat
Timo Sirainen <tss@iki.fi>
parents:
1506
diff
changeset
|
139 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
|
140 |
6850142c4e25
New configuration file code. Some syntax changes, but tries to be somewhat
Timo Sirainen <tss@iki.fi>
parents:
1506
diff
changeset
|
141 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
|
142 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
|
143 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
|
144 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
|
145 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
|
146 } |
6850142c4e25
New configuration file code. Some syntax changes, but tries to be somewhat
Timo Sirainen <tss@iki.fi>
parents:
1506
diff
changeset
|
147 } |
6850142c4e25
New configuration file code. Some syntax changes, but tries to be somewhat
Timo Sirainen <tss@iki.fi>
parents:
1506
diff
changeset
|
148 |
6850142c4e25
New configuration file code. Some syntax changes, but tries to be somewhat
Timo Sirainen <tss@iki.fi>
parents:
1506
diff
changeset
|
149 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
|
150 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
|
151 { |
af685269ead0
login: Wait until we're connected to auth process before executing command
Timo Sirainen <tss@iki.fi>
parents:
1273
diff
changeset
|
152 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
|
153 |
1610
6850142c4e25
New configuration file code. Some syntax changes, but tries to be somewhat
Timo Sirainen <tss@iki.fi>
parents:
1506
diff
changeset
|
154 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
|
155 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
|
156 |
af685269ead0
login: Wait until we're connected to auth process before executing command
Timo Sirainen <tss@iki.fi>
parents:
1273
diff
changeset
|
157 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
|
158 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
|
159 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
|
160 return group; |
af685269ead0
login: Wait until we're connected to auth process before executing command
Timo Sirainen <tss@iki.fi>
parents:
1273
diff
changeset
|
161 } |
af685269ead0
login: Wait until we're connected to auth process before executing command
Timo Sirainen <tss@iki.fi>
parents:
1273
diff
changeset
|
162 |
af685269ead0
login: Wait until we're connected to auth process before executing command
Timo Sirainen <tss@iki.fi>
parents:
1273
diff
changeset
|
163 return NULL; |
af685269ead0
login: Wait until we're connected to auth process before executing command
Timo Sirainen <tss@iki.fi>
parents:
1273
diff
changeset
|
164 } |
614
e60620644af3
login_process_per_connection = yes scales now better when multiple users are
Timo Sirainen <tss@iki.fi>
parents:
613
diff
changeset
|
165 |
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
|
166 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
|
167 { |
af685269ead0
login: Wait until we're connected to auth process before executing command
Timo Sirainen <tss@iki.fi>
parents:
1273
diff
changeset
|
168 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
|
169 const char *name, *proto; |
1275
af685269ead0
login: Wait until we're connected to auth process before executing command
Timo Sirainen <tss@iki.fi>
parents:
1273
diff
changeset
|
170 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
|
171 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
|
172 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
|
173 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
|
174 |
af685269ead0
login: Wait until we're connected to auth process before executing command
Timo Sirainen <tss@iki.fi>
parents:
1273
diff
changeset
|
175 /* read length */ |
af685269ead0
login: Wait until we're connected to auth process before executing command
Timo Sirainen <tss@iki.fi>
parents:
1273
diff
changeset
|
176 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
|
177 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
|
178 len = 0; |
af685269ead0
login: Wait until we're connected to auth process before executing command
Timo Sirainen <tss@iki.fi>
parents:
1273
diff
changeset
|
179 else { |
af685269ead0
login: Wait until we're connected to auth process before executing command
Timo Sirainen <tss@iki.fi>
parents:
1273
diff
changeset
|
180 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
|
181 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
|
182 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
|
183 return FALSE; |
af685269ead0
login: Wait until we're connected to auth process before executing command
Timo Sirainen <tss@iki.fi>
parents:
1273
diff
changeset
|
184 } |
614
e60620644af3
login_process_per_connection = yes scales now better when multiple users are
Timo Sirainen <tss@iki.fi>
parents:
613
diff
changeset
|
185 |
1275
af685269ead0
login: Wait until we're connected to auth process before executing command
Timo Sirainen <tss@iki.fi>
parents:
1273
diff
changeset
|
186 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
|
187 } |
af685269ead0
login: Wait until we're connected to auth process before executing command
Timo Sirainen <tss@iki.fi>
parents:
1273
diff
changeset
|
188 |
af685269ead0
login: Wait until we're connected to auth process before executing command
Timo Sirainen <tss@iki.fi>
parents:
1273
diff
changeset
|
189 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
|
190 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
|
191 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
|
192 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
|
193 else { |
af685269ead0
login: Wait until we're connected to auth process before executing command
Timo Sirainen <tss@iki.fi>
parents:
1273
diff
changeset
|
194 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
|
195 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
|
196 if (proto == NULL) { |
3607
a2dd3d895e00
Several fixes to make running from inetd working again
Timo Sirainen <tss@iki.fi>
parents:
3384
diff
changeset
|
197 proto = name; |
a2dd3d895e00
Several fixes to make running from inetd working again
Timo Sirainen <tss@iki.fi>
parents:
3384
diff
changeset
|
198 name = "default"; |
a2dd3d895e00
Several fixes to make running from inetd working again
Timo Sirainen <tss@iki.fi>
parents:
3384
diff
changeset
|
199 } else { |
a2dd3d895e00
Several fixes to make running from inetd working again
Timo Sirainen <tss@iki.fi>
parents:
3384
diff
changeset
|
200 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
|
201 } |
6850142c4e25
New configuration file code. Some syntax changes, but tries to be somewhat
Timo Sirainen <tss@iki.fi>
parents:
1506
diff
changeset
|
202 |
6850142c4e25
New configuration file code. Some syntax changes, but tries to be somewhat
Timo Sirainen <tss@iki.fi>
parents:
1506
diff
changeset
|
203 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
|
204 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
|
205 else if (strcmp(proto, "pop3") == 0) |
6850142c4e25
New configuration file code. Some syntax changes, but tries to be somewhat
Timo Sirainen <tss@iki.fi>
parents:
1506
diff
changeset
|
206 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
|
207 else { |
6850142c4e25
New configuration file code. Some syntax changes, but tries to be somewhat
Timo Sirainen <tss@iki.fi>
parents:
1506
diff
changeset
|
208 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
|
209 return FALSE; |
6850142c4e25
New configuration file code. Some syntax changes, but tries to be somewhat
Timo Sirainen <tss@iki.fi>
parents:
1506
diff
changeset
|
210 } |
6850142c4e25
New configuration file code. Some syntax changes, but tries to be somewhat
Timo Sirainen <tss@iki.fi>
parents:
1506
diff
changeset
|
211 |
6850142c4e25
New configuration file code. Some syntax changes, but tries to be somewhat
Timo Sirainen <tss@iki.fi>
parents:
1506
diff
changeset
|
212 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
|
213 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
|
214 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
|
215 return FALSE; |
af685269ead0
login: Wait until we're connected to auth process before executing command
Timo Sirainen <tss@iki.fi>
parents:
1273
diff
changeset
|
216 } |
af685269ead0
login: Wait until we're connected to auth process before executing command
Timo Sirainen <tss@iki.fi>
parents:
1273
diff
changeset
|
217 |
af685269ead0
login: Wait until we're connected to auth process before executing command
Timo Sirainen <tss@iki.fi>
parents:
1273
diff
changeset
|
218 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
|
219 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
|
220 } |
af685269ead0
login: Wait until we're connected to auth process before executing command
Timo Sirainen <tss@iki.fi>
parents:
1273
diff
changeset
|
221 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
|
222 } |
e60620644af3
login_process_per_connection = yes scales now better when multiple users are
Timo Sirainen <tss@iki.fi>
parents:
613
diff
changeset
|
223 |
1036
f782b3319553
Removed useless parameters from io_callback_t and timeout_callback_t.
Timo Sirainen <tss@iki.fi>
parents:
1035
diff
changeset
|
224 static void login_process_input(void *context) |
0 | 225 { |
903
fd8888f6f037
Naming style changes, finally got tired of most of the typedefs. Also the
Timo Sirainen <tss@iki.fi>
parents:
876
diff
changeset
|
226 struct login_process *p = context; |
fd8888f6f037
Naming style changes, finally got tired of most of the typedefs. Also the
Timo Sirainen <tss@iki.fi>
parents:
876
diff
changeset
|
227 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
|
228 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
|
229 struct master_login_request req; |
1275
af685269ead0
login: Wait until we're connected to auth process before executing command
Timo Sirainen <tss@iki.fi>
parents:
1273
diff
changeset
|
230 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
|
231 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
|
232 |
af685269ead0
login: Wait until we're connected to auth process before executing command
Timo Sirainen <tss@iki.fi>
parents:
1273
diff
changeset
|
233 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
|
234 /* 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
|
235 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
|
236 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
|
237 return; |
af685269ead0
login: Wait until we're connected to auth process before executing command
Timo Sirainen <tss@iki.fi>
parents:
1273
diff
changeset
|
238 } |
0 | 239 |
240 ret = fd_read(p->fd, &req, sizeof(req), &client_fd); | |
2779
1fd55b4341b9
Added version to login <-> master communication as well.
Timo Sirainen <tss@iki.fi>
parents:
2736
diff
changeset
|
241 if (ret >= (ssize_t)sizeof(req.version) && |
1fd55b4341b9
Added version to login <-> master communication as well.
Timo Sirainen <tss@iki.fi>
parents:
2736
diff
changeset
|
242 req.version != MASTER_LOGIN_PROTOCOL_VERSION) { |
1fd55b4341b9
Added version to login <-> master communication as well.
Timo Sirainen <tss@iki.fi>
parents:
2736
diff
changeset
|
243 i_error("login: Protocol version mismatch " |
1fd55b4341b9
Added version to login <-> master communication as well.
Timo Sirainen <tss@iki.fi>
parents:
2736
diff
changeset
|
244 "(mixed old and new binaries?)"); |
1fd55b4341b9
Added version to login <-> master communication as well.
Timo Sirainen <tss@iki.fi>
parents:
2736
diff
changeset
|
245 login_process_destroy(p); |
1fd55b4341b9
Added version to login <-> master communication as well.
Timo Sirainen <tss@iki.fi>
parents:
2736
diff
changeset
|
246 return; |
1fd55b4341b9
Added version to login <-> master communication as well.
Timo Sirainen <tss@iki.fi>
parents:
2736
diff
changeset
|
247 } |
1fd55b4341b9
Added version to login <-> master communication as well.
Timo Sirainen <tss@iki.fi>
parents:
2736
diff
changeset
|
248 |
0 | 249 if (ret != sizeof(req)) { |
250 if (ret == 0) { | |
251 /* disconnected, ie. the login process died */ | |
252 } else if (ret > 0) { | |
253 /* req wasn't fully read */ | |
254 i_error("login: fd_read() couldn't read all req"); | |
255 } else { | |
256 i_error("login: fd_read() failed: %m"); | |
257 } | |
258 | |
929
a763b3826762
Don't leak fds in case of errors.
Timo Sirainen <tss@iki.fi>
parents:
925
diff
changeset
|
259 if (client_fd != -1) { |
a763b3826762
Don't leak fds in case of errors.
Timo Sirainen <tss@iki.fi>
parents:
925
diff
changeset
|
260 if (close(client_fd) < 0) |
1055
a72bba3f8a55
Rewrote setting handling. Changed some existing settings also since POP3
Timo Sirainen <tss@iki.fi>
parents:
1039
diff
changeset
|
261 i_error("close(mail client) failed: %m"); |
929
a763b3826762
Don't leak fds in case of errors.
Timo Sirainen <tss@iki.fi>
parents:
925
diff
changeset
|
262 } |
a763b3826762
Don't leak fds in case of errors.
Timo Sirainen <tss@iki.fi>
parents:
925
diff
changeset
|
263 |
0 | 264 login_process_destroy(p); |
265 return; | |
266 } | |
267 | |
613
1906116a62ce
Finally support for handling each login connection in it's own process.
Timo Sirainen <tss@iki.fi>
parents:
596
diff
changeset
|
268 if (client_fd == -1) { |
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
|
269 /* just a notification that the login process */ |
2e649dec0f09
Auth and login processes send an "we're ok" reply at the end of
Timo Sirainen <tss@iki.fi>
parents:
903
diff
changeset
|
270 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
|
271 /* initialization notify */ |
2e649dec0f09
Auth and login processes send an "we're ok" reply at the end of
Timo Sirainen <tss@iki.fi>
parents:
903
diff
changeset
|
272 p->initialized = TRUE;; |
2e649dec0f09
Auth and login processes send an "we're ok" reply at the end of
Timo Sirainen <tss@iki.fi>
parents:
903
diff
changeset
|
273 } else { |
2e649dec0f09
Auth and login processes send an "we're ok" reply at the end of
Timo Sirainen <tss@iki.fi>
parents:
903
diff
changeset
|
274 /* not listening for new connections anymore */ |
2e649dec0f09
Auth and login processes send an "we're ok" reply at the end of
Timo Sirainen <tss@iki.fi>
parents:
903
diff
changeset
|
275 login_process_mark_nonlistening(p); |
2e649dec0f09
Auth and login processes send an "we're ok" reply at the end of
Timo Sirainen <tss@iki.fi>
parents:
903
diff
changeset
|
276 } |
613
1906116a62ce
Finally support for handling each login connection in it's own process.
Timo Sirainen <tss@iki.fi>
parents:
596
diff
changeset
|
277 return; |
1906116a62ce
Finally support for handling each login connection in it's own process.
Timo Sirainen <tss@iki.fi>
parents:
596
diff
changeset
|
278 } |
1906116a62ce
Finally support for handling each login connection in it's own process.
Timo Sirainen <tss@iki.fi>
parents:
596
diff
changeset
|
279 |
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
|
280 fd_close_on_exec(client_fd, TRUE); |
0 | 281 |
282 /* ask the cookie from the auth process */ | |
903
fd8888f6f037
Naming style changes, finally got tired of most of the typedefs. Also the
Timo Sirainen <tss@iki.fi>
parents:
876
diff
changeset
|
283 authreq = i_new(struct login_auth_request, 1); |
0 | 284 p->refcount++; |
285 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
|
286 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
|
287 authreq->login_tag = req.tag; |
0 | 288 authreq->fd = client_fd; |
2097
4e77cb0aff21
Added %l, %r and %P variables and mail_log_prefix setting.
Timo Sirainen <tss@iki.fi>
parents:
2046
diff
changeset
|
289 authreq->local_ip = req.local_ip; |
4e77cb0aff21
Added %l, %r and %P variables and mail_log_prefix setting.
Timo Sirainen <tss@iki.fi>
parents:
2046
diff
changeset
|
290 authreq->remote_ip = req.remote_ip; |
0 | 291 |
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
|
292 auth_process = auth_process_find(req.auth_pid); |
0 | 293 if (auth_process == NULL) { |
294 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
|
295 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
|
296 auth_master_callback(NULL, NULL, authreq); |
0 | 297 } 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
|
298 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
|
299 req.auth_id, authreq); |
0 | 300 } |
301 } | |
302 | |
1055
a72bba3f8a55
Rewrote setting handling. Changed some existing settings also since POP3
Timo Sirainen <tss@iki.fi>
parents:
1039
diff
changeset
|
303 static struct login_process * |
a72bba3f8a55
Rewrote setting handling. Changed some existing settings also since POP3
Timo Sirainen <tss@iki.fi>
parents:
1039
diff
changeset
|
304 login_process_new(struct login_group *group, pid_t pid, int fd) |
0 | 305 { |
903
fd8888f6f037
Naming style changes, finally got tired of most of the typedefs. Also the
Timo Sirainen <tss@iki.fi>
parents:
876
diff
changeset
|
306 struct login_process *p; |
0 | 307 |
1273
2cf2e08a6ee9
Somewhat working code to support loading Dovecot from inetd and such. It
Timo Sirainen <tss@iki.fi>
parents:
1237
diff
changeset
|
308 i_assert(pid != 0); |
0 | 309 |
903
fd8888f6f037
Naming style changes, finally got tired of most of the typedefs. Also the
Timo Sirainen <tss@iki.fi>
parents:
876
diff
changeset
|
310 p = i_new(struct login_process, 1); |
1055
a72bba3f8a55
Rewrote setting handling. Changed some existing settings also since POP3
Timo Sirainen <tss@iki.fi>
parents:
1039
diff
changeset
|
311 p->group = group; |
0 | 312 p->refcount = 1; |
313 p->pid = pid; | |
314 p->fd = fd; | |
613
1906116a62ce
Finally support for handling each login connection in it's own process.
Timo Sirainen <tss@iki.fi>
parents:
596
diff
changeset
|
315 p->listening = TRUE; |
0 | 316 p->io = io_add(fd, IO_READ, login_process_input, p); |
764
f57c52738f90
Renamed IBuffer and OBuffer to IStream and OStream which describes their
Timo Sirainen <tss@iki.fi>
parents:
747
diff
changeset
|
317 p->output = o_stream_create_file(fd, default_pool, |
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
|
318 sizeof(struct master_login_reply)*10, |
1499
e850252cdc7e
Removed I/O priorities. They were pretty much useless and were just getting
Timo Sirainen <tss@iki.fi>
parents:
1468
diff
changeset
|
319 FALSE); |
0 | 320 |
1273
2cf2e08a6ee9
Somewhat working code to support loading Dovecot from inetd and such. It
Timo Sirainen <tss@iki.fi>
parents:
1237
diff
changeset
|
321 PID_ADD_PROCESS_TYPE(pid, PROCESS_TYPE_LOGIN); |
195
db6e288be0e9
Replaced INT_TO_POINTER and POINTER_TO_INT macros with POINTER_CAST and
Timo Sirainen <tss@iki.fi>
parents:
10
diff
changeset
|
322 hash_insert(processes, POINTER_CAST(pid), p); |
1273
2cf2e08a6ee9
Somewhat working code to support loading Dovecot from inetd and such. It
Timo Sirainen <tss@iki.fi>
parents:
1237
diff
changeset
|
323 |
1275
af685269ead0
login: Wait until we're connected to auth process before executing command
Timo Sirainen <tss@iki.fi>
parents:
1273
diff
changeset
|
324 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
|
325 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
|
326 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
|
327 } |
0 | 328 return p; |
329 } | |
330 | |
903
fd8888f6f037
Naming style changes, finally got tired of most of the typedefs. Also the
Timo Sirainen <tss@iki.fi>
parents:
876
diff
changeset
|
331 static void login_process_remove_from_lists(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
|
332 { |
1275
af685269ead0
login: Wait until we're connected to auth process before executing command
Timo Sirainen <tss@iki.fi>
parents:
1273
diff
changeset
|
333 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
|
334 return; |
af685269ead0
login: Wait until we're connected to auth process before executing command
Timo Sirainen <tss@iki.fi>
parents:
1273
diff
changeset
|
335 |
1055
a72bba3f8a55
Rewrote setting handling. Changed some existing settings also since POP3
Timo Sirainen <tss@iki.fi>
parents:
1039
diff
changeset
|
336 if (p == p->group->oldest_nonlisten_process) |
a72bba3f8a55
Rewrote setting handling. Changed some existing settings also since POP3
Timo Sirainen <tss@iki.fi>
parents:
1039
diff
changeset
|
337 p->group->oldest_nonlisten_process = p->next_nonlisten; |
613
1906116a62ce
Finally support for handling each login connection in it's own process.
Timo Sirainen <tss@iki.fi>
parents:
596
diff
changeset
|
338 else |
1906116a62ce
Finally support for handling each login connection in it's own process.
Timo Sirainen <tss@iki.fi>
parents:
596
diff
changeset
|
339 p->prev_nonlisten->next_nonlisten = p->next_nonlisten; |
1906116a62ce
Finally support for handling each login connection in it's own process.
Timo Sirainen <tss@iki.fi>
parents:
596
diff
changeset
|
340 |
1055
a72bba3f8a55
Rewrote setting handling. Changed some existing settings also since POP3
Timo Sirainen <tss@iki.fi>
parents:
1039
diff
changeset
|
341 if (p == p->group->newest_nonlisten_process) |
a72bba3f8a55
Rewrote setting handling. Changed some existing settings also since POP3
Timo Sirainen <tss@iki.fi>
parents:
1039
diff
changeset
|
342 p->group->newest_nonlisten_process = p->prev_nonlisten; |
613
1906116a62ce
Finally support for handling each login connection in it's own process.
Timo Sirainen <tss@iki.fi>
parents:
596
diff
changeset
|
343 else |
1906116a62ce
Finally support for handling each login connection in it's own process.
Timo Sirainen <tss@iki.fi>
parents:
596
diff
changeset
|
344 p->next_nonlisten->prev_nonlisten = p->prev_nonlisten; |
1906116a62ce
Finally support for handling each login connection in it's own process.
Timo Sirainen <tss@iki.fi>
parents:
596
diff
changeset
|
345 |
1906116a62ce
Finally support for handling each login connection in it's own process.
Timo Sirainen <tss@iki.fi>
parents:
596
diff
changeset
|
346 p->next_nonlisten = p->prev_nonlisten = NULL; |
1906116a62ce
Finally support for handling each login connection in it's own process.
Timo Sirainen <tss@iki.fi>
parents:
596
diff
changeset
|
347 } |
1906116a62ce
Finally support for handling each login connection in it's own process.
Timo Sirainen <tss@iki.fi>
parents:
596
diff
changeset
|
348 |
903
fd8888f6f037
Naming style changes, finally got tired of most of the typedefs. Also the
Timo Sirainen <tss@iki.fi>
parents:
876
diff
changeset
|
349 static void login_process_destroy(struct login_process *p) |
0 | 350 { |
351 if (p->destroyed) | |
352 return; | |
353 p->destroyed = TRUE; | |
354 | |
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
|
355 if (!p->initialized && io_loop_is_running(ioloop)) { |
1000
0fbafade2d85
If auth/login process died unexpectedly, the exit status or killing signal
Timo Sirainen <tss@iki.fi>
parents:
945
diff
changeset
|
356 i_error("Login process died too early - shutting down"); |
0fbafade2d85
If auth/login process died unexpectedly, the exit status or killing signal
Timo Sirainen <tss@iki.fi>
parents:
945
diff
changeset
|
357 io_loop_stop(ioloop); |
0fbafade2d85
If auth/login process died unexpectedly, the exit status or killing signal
Timo Sirainen <tss@iki.fi>
parents:
945
diff
changeset
|
358 } |
1275
af685269ead0
login: Wait until we're connected to auth process before executing command
Timo Sirainen <tss@iki.fi>
parents:
1273
diff
changeset
|
359 |
af685269ead0
login: Wait until we're connected to auth process before executing command
Timo Sirainen <tss@iki.fi>
parents:
1273
diff
changeset
|
360 if (p->listening && p->group != NULL) |
1055
a72bba3f8a55
Rewrote setting handling. Changed some existing settings also since POP3
Timo Sirainen <tss@iki.fi>
parents:
1039
diff
changeset
|
361 p->group->listening_processes--; |
613
1906116a62ce
Finally support for handling each login connection in it's own process.
Timo Sirainen <tss@iki.fi>
parents:
596
diff
changeset
|
362 |
764
f57c52738f90
Renamed IBuffer and OBuffer to IStream and OStream which describes their
Timo Sirainen <tss@iki.fi>
parents:
747
diff
changeset
|
363 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
|
364 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
|
365 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
|
366 i_error("close(login) failed: %m"); |
0 | 367 |
613
1906116a62ce
Finally support for handling each login connection in it's own process.
Timo Sirainen <tss@iki.fi>
parents:
596
diff
changeset
|
368 if (!p->listening) |
1906116a62ce
Finally support for handling each login connection in it's own process.
Timo Sirainen <tss@iki.fi>
parents:
596
diff
changeset
|
369 login_process_remove_from_lists(p); |
1906116a62ce
Finally support for handling each login connection in it's own process.
Timo Sirainen <tss@iki.fi>
parents:
596
diff
changeset
|
370 |
1275
af685269ead0
login: Wait until we're connected to auth process before executing command
Timo Sirainen <tss@iki.fi>
parents:
1273
diff
changeset
|
371 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
|
372 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
|
373 |
1273
2cf2e08a6ee9
Somewhat working code to support loading Dovecot from inetd and such. It
Timo Sirainen <tss@iki.fi>
parents:
1237
diff
changeset
|
374 if (p->pid != 0) |
2cf2e08a6ee9
Somewhat working code to support loading Dovecot from inetd and such. It
Timo Sirainen <tss@iki.fi>
parents:
1237
diff
changeset
|
375 hash_remove(processes, POINTER_CAST(p->pid)); |
613
1906116a62ce
Finally support for handling each login connection in it's own process.
Timo Sirainen <tss@iki.fi>
parents:
596
diff
changeset
|
376 |
0 | 377 login_process_unref(p); |
378 } | |
379 | |
903
fd8888f6f037
Naming style changes, finally got tired of most of the typedefs. Also the
Timo Sirainen <tss@iki.fi>
parents:
876
diff
changeset
|
380 static void login_process_unref(struct login_process *p) |
0 | 381 { |
382 if (--p->refcount > 0) | |
383 return; | |
384 | |
3879
928229f8b3e6
deinit, unref, destroy, close, free, etc. functions now take a pointer to
Timo Sirainen <tss@iki.fi>
parents:
3863
diff
changeset
|
385 o_stream_unref(&p->output); |
0 | 386 i_free(p); |
387 } | |
388 | |
1273
2cf2e08a6ee9
Somewhat working code to support loading Dovecot from inetd and such. It
Timo Sirainen <tss@iki.fi>
parents:
1237
diff
changeset
|
389 static void login_process_init_env(struct login_group *group, pid_t pid) |
2cf2e08a6ee9
Somewhat working code to support loading Dovecot from inetd and such. It
Timo Sirainen <tss@iki.fi>
parents:
1237
diff
changeset
|
390 { |
1610
6850142c4e25
New configuration file code. Some syntax changes, but tries to be somewhat
Timo Sirainen <tss@iki.fi>
parents:
1506
diff
changeset
|
391 struct settings *set = group->set; |
6850142c4e25
New configuration file code. Some syntax changes, but tries to be somewhat
Timo Sirainen <tss@iki.fi>
parents:
1506
diff
changeset
|
392 |
2000
c7c19f5071c3
Write all logging through master process. Fixes problems with log rotation,
Timo Sirainen <tss@iki.fi>
parents:
1997
diff
changeset
|
393 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
|
394 |
2cf2e08a6ee9
Somewhat working code to support loading Dovecot from inetd and such. It
Timo Sirainen <tss@iki.fi>
parents:
1237
diff
changeset
|
395 /* setup access environment - needs to be done after |
3692 | 396 clean_child_process() since it clears environment. Don't set user |
397 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
|
398 processes. */ |
e167b71e37e3
Don't call initgroups() at the start of login processes.
Timo Sirainen <tss@iki.fi>
parents:
3607
diff
changeset
|
399 restrict_access_set_env(NULL, set->login_uid, |
1724
b3526668de78
Make sure auth process and login process don't share uids.
Timo Sirainen <tss@iki.fi>
parents:
1610
diff
changeset
|
400 set->server->login_gid, |
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
|
401 set->login_chroot ? set->login_dir : NULL, |
2141
8690d2000e33
Added mail_extra_groups setting.
Timo Sirainen <tss@iki.fi>
parents:
2097
diff
changeset
|
402 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
|
403 |
2cf2e08a6ee9
Somewhat working code to support loading Dovecot from inetd and such. It
Timo Sirainen <tss@iki.fi>
parents:
1237
diff
changeset
|
404 env_put("DOVECOT_MASTER=1"); |
2cf2e08a6ee9
Somewhat working code to support loading Dovecot from inetd and such. It
Timo Sirainen <tss@iki.fi>
parents:
1237
diff
changeset
|
405 |
2cf2e08a6ee9
Somewhat working code to support loading Dovecot from inetd and such. It
Timo Sirainen <tss@iki.fi>
parents:
1237
diff
changeset
|
406 if (!set->ssl_disable) { |
3889
c7462001227b
Added support for password protected SSL private keys. The password can be
Timo Sirainen <tss@iki.fi>
parents:
3879
diff
changeset
|
407 const char *ssl_key_password = NULL; |
c7462001227b
Added support for password protected SSL private keys. The password can be
Timo Sirainen <tss@iki.fi>
parents:
3879
diff
changeset
|
408 |
c7462001227b
Added support for password protected SSL private keys. The password can be
Timo Sirainen <tss@iki.fi>
parents:
3879
diff
changeset
|
409 ssl_key_password = set->ssl_key_password != NULL ? |
c7462001227b
Added support for password protected SSL private keys. The password can be
Timo Sirainen <tss@iki.fi>
parents:
3879
diff
changeset
|
410 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
|
411 |
1907
190f1d315ce6
Added setting ssl_ca_file, patch by Zach Bagnall
Timo Sirainen <tss@iki.fi>
parents:
1897
diff
changeset
|
412 if (set->ssl_ca_file != NULL) { |
190f1d315ce6
Added setting ssl_ca_file, patch by Zach Bagnall
Timo Sirainen <tss@iki.fi>
parents:
1897
diff
changeset
|
413 env_put(t_strconcat("SSL_CA_FILE=", |
190f1d315ce6
Added setting ssl_ca_file, patch by Zach Bagnall
Timo Sirainen <tss@iki.fi>
parents:
1897
diff
changeset
|
414 set->ssl_ca_file, NULL)); |
190f1d315ce6
Added setting ssl_ca_file, patch by Zach Bagnall
Timo Sirainen <tss@iki.fi>
parents:
1897
diff
changeset
|
415 } |
1273
2cf2e08a6ee9
Somewhat working code to support loading Dovecot from inetd and such. It
Timo Sirainen <tss@iki.fi>
parents:
1237
diff
changeset
|
416 env_put(t_strconcat("SSL_CERT_FILE=", |
2cf2e08a6ee9
Somewhat working code to support loading Dovecot from inetd and such. It
Timo Sirainen <tss@iki.fi>
parents:
1237
diff
changeset
|
417 set->ssl_cert_file, NULL)); |
1610
6850142c4e25
New configuration file code. Some syntax changes, but tries to be somewhat
Timo Sirainen <tss@iki.fi>
parents:
1506
diff
changeset
|
418 env_put(t_strconcat("SSL_KEY_FILE=", |
6850142c4e25
New configuration file code. Some syntax changes, but tries to be somewhat
Timo Sirainen <tss@iki.fi>
parents:
1506
diff
changeset
|
419 set->ssl_key_file, NULL)); |
3889
c7462001227b
Added support for password protected SSL private keys. The password can be
Timo Sirainen <tss@iki.fi>
parents:
3879
diff
changeset
|
420 env_put(t_strconcat("SSL_KEY_PASSWORD=", |
c7462001227b
Added support for password protected SSL private keys. The password can be
Timo Sirainen <tss@iki.fi>
parents:
3879
diff
changeset
|
421 ssl_key_password, NULL)); |
1273
2cf2e08a6ee9
Somewhat working code to support loading Dovecot from inetd and such. It
Timo Sirainen <tss@iki.fi>
parents:
1237
diff
changeset
|
422 env_put(t_strconcat("SSL_PARAM_FILE=", |
2cf2e08a6ee9
Somewhat working code to support loading Dovecot from inetd and such. It
Timo Sirainen <tss@iki.fi>
parents:
1237
diff
changeset
|
423 set->ssl_parameters_file, NULL)); |
1996 | 424 if (set->ssl_cipher_list != NULL) { |
425 env_put(t_strconcat("SSL_CIPHER_LIST=", | |
426 set->ssl_cipher_list, NULL)); | |
427 } | |
1997
1d0985f6bdd9
Added ssl_verify_client_cert setting.
Timo Sirainen <tss@iki.fi>
parents:
1996
diff
changeset
|
428 if (set->ssl_verify_client_cert) |
1d0985f6bdd9
Added ssl_verify_client_cert setting.
Timo Sirainen <tss@iki.fi>
parents:
1996
diff
changeset
|
429 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
|
430 } |
2cf2e08a6ee9
Somewhat working code to support loading Dovecot from inetd and such. It
Timo Sirainen <tss@iki.fi>
parents:
1237
diff
changeset
|
431 |
2cf2e08a6ee9
Somewhat working code to support loading Dovecot from inetd and such. It
Timo Sirainen <tss@iki.fi>
parents:
1237
diff
changeset
|
432 if (set->disable_plaintext_auth) |
2cf2e08a6ee9
Somewhat working code to support loading Dovecot from inetd and such. It
Timo Sirainen <tss@iki.fi>
parents:
1237
diff
changeset
|
433 env_put("DISABLE_PLAINTEXT_AUTH=1"); |
2cf2e08a6ee9
Somewhat working code to support loading Dovecot from inetd and such. It
Timo Sirainen <tss@iki.fi>
parents:
1237
diff
changeset
|
434 if (set->verbose_proctitle) |
2cf2e08a6ee9
Somewhat working code to support loading Dovecot from inetd and such. It
Timo Sirainen <tss@iki.fi>
parents:
1237
diff
changeset
|
435 env_put("VERBOSE_PROCTITLE=1"); |
2cf2e08a6ee9
Somewhat working code to support loading Dovecot from inetd and such. It
Timo Sirainen <tss@iki.fi>
parents:
1237
diff
changeset
|
436 if (set->verbose_ssl) |
2cf2e08a6ee9
Somewhat working code to support loading Dovecot from inetd and such. It
Timo Sirainen <tss@iki.fi>
parents:
1237
diff
changeset
|
437 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
|
438 if (set->server->auths->verbose) |
46f879c46b45
auth_verbose now affects imap/pop3 login processes too. Every authentication
Timo Sirainen <tss@iki.fi>
parents:
2674
diff
changeset
|
439 env_put("VERBOSE_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
|
440 |
1610
6850142c4e25
New configuration file code. Some syntax changes, but tries to be somewhat
Timo Sirainen <tss@iki.fi>
parents:
1506
diff
changeset
|
441 if (set->login_process_per_connection) { |
1273
2cf2e08a6ee9
Somewhat working code to support loading Dovecot from inetd and such. It
Timo Sirainen <tss@iki.fi>
parents:
1237
diff
changeset
|
442 env_put("PROCESS_PER_CONNECTION=1"); |
2cf2e08a6ee9
Somewhat working code to support loading Dovecot from inetd and such. It
Timo Sirainen <tss@iki.fi>
parents:
1237
diff
changeset
|
443 env_put("MAX_LOGGING_USERS=1"); |
2cf2e08a6ee9
Somewhat working code to support loading Dovecot from inetd and such. It
Timo Sirainen <tss@iki.fi>
parents:
1237
diff
changeset
|
444 } else { |
2cf2e08a6ee9
Somewhat working code to support loading Dovecot from inetd and such. It
Timo Sirainen <tss@iki.fi>
parents:
1237
diff
changeset
|
445 env_put(t_strdup_printf("MAX_LOGGING_USERS=%u", |
1610
6850142c4e25
New configuration file code. Some syntax changes, but tries to be somewhat
Timo Sirainen <tss@iki.fi>
parents:
1506
diff
changeset
|
446 set->login_max_logging_users)); |
1273
2cf2e08a6ee9
Somewhat working code to support loading Dovecot from inetd and such. It
Timo Sirainen <tss@iki.fi>
parents:
1237
diff
changeset
|
447 } |
2cf2e08a6ee9
Somewhat working code to support loading Dovecot from inetd and such. It
Timo Sirainen <tss@iki.fi>
parents:
1237
diff
changeset
|
448 |
2674
857f5f7b512b
Added login_greeting and login_greeting_capability settings.
Timo Sirainen <tss@iki.fi>
parents:
2329
diff
changeset
|
449 env_put(t_strconcat("PROCESS_UID=", dec2str(pid), NULL)); |
857f5f7b512b
Added login_greeting and login_greeting_capability settings.
Timo Sirainen <tss@iki.fi>
parents:
2329
diff
changeset
|
450 env_put(t_strconcat("GREETING=", set->login_greeting, NULL)); |
3384
3b75956d20c4
Added configurable logging for login process. Added configurable pop3 logout
Timo Sirainen <tss@iki.fi>
parents:
3083
diff
changeset
|
451 env_put(t_strconcat("LOG_FORMAT_ELEMENTS=", |
3b75956d20c4
Added configurable logging for login process. Added configurable pop3 logout
Timo Sirainen <tss@iki.fi>
parents:
3083
diff
changeset
|
452 set->login_log_format_elements, NULL)); |
3b75956d20c4
Added configurable logging for login process. Added configurable pop3 logout
Timo Sirainen <tss@iki.fi>
parents:
3083
diff
changeset
|
453 env_put(t_strconcat("LOG_FORMAT=", set->login_log_format, NULL)); |
2674
857f5f7b512b
Added login_greeting and login_greeting_capability settings.
Timo Sirainen <tss@iki.fi>
parents:
2329
diff
changeset
|
454 if (set->login_greeting_capability) |
857f5f7b512b
Added login_greeting and login_greeting_capability settings.
Timo Sirainen <tss@iki.fi>
parents:
2329
diff
changeset
|
455 env_put("GREETING_CAPABILITY=1"); |
1273
2cf2e08a6ee9
Somewhat working code to support loading Dovecot from inetd and such. It
Timo Sirainen <tss@iki.fi>
parents:
1237
diff
changeset
|
456 } |
2cf2e08a6ee9
Somewhat working code to support loading Dovecot from inetd and such. It
Timo Sirainen <tss@iki.fi>
parents:
1237
diff
changeset
|
457 |
1055
a72bba3f8a55
Rewrote setting handling. Changed some existing settings also since POP3
Timo Sirainen <tss@iki.fi>
parents:
1039
diff
changeset
|
458 static pid_t create_login_process(struct login_group *group) |
0 | 459 { |
2046 | 460 struct log_io *log; |
3083
a20882c4f092
Disable log throttlong for auth process, and for login processes if
Timo Sirainen <tss@iki.fi>
parents:
2886
diff
changeset
|
461 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
|
462 const char *prefix; |
0 | 463 pid_t pid; |
2000
c7c19f5071c3
Write all logging through master process. Fixes problems with log rotation,
Timo Sirainen <tss@iki.fi>
parents:
1997
diff
changeset
|
464 int fd[2], log_fd; |
0 | 465 |
1610
6850142c4e25
New configuration file code. Some syntax changes, but tries to be somewhat
Timo Sirainen <tss@iki.fi>
parents:
1506
diff
changeset
|
466 if (group->set->login_process_per_connection && |
1055
a72bba3f8a55
Rewrote setting handling. Changed some existing settings also since POP3
Timo Sirainen <tss@iki.fi>
parents:
1039
diff
changeset
|
467 group->processes - group->listening_processes >= |
1610
6850142c4e25
New configuration file code. Some syntax changes, but tries to be somewhat
Timo Sirainen <tss@iki.fi>
parents:
1506
diff
changeset
|
468 group->set->login_max_logging_users) { |
1055
a72bba3f8a55
Rewrote setting handling. Changed some existing settings also since POP3
Timo Sirainen <tss@iki.fi>
parents:
1039
diff
changeset
|
469 if (group->oldest_nonlisten_process != NULL) |
a72bba3f8a55
Rewrote setting handling. Changed some existing settings also since POP3
Timo Sirainen <tss@iki.fi>
parents:
1039
diff
changeset
|
470 login_process_destroy(group->oldest_nonlisten_process); |
613
1906116a62ce
Finally support for handling each login connection in it's own process.
Timo Sirainen <tss@iki.fi>
parents:
596
diff
changeset
|
471 } |
1906116a62ce
Finally support for handling each login connection in it's own process.
Timo Sirainen <tss@iki.fi>
parents:
596
diff
changeset
|
472 |
1610
6850142c4e25
New configuration file code. Some syntax changes, but tries to be somewhat
Timo Sirainen <tss@iki.fi>
parents:
1506
diff
changeset
|
473 if (group->set->login_uid == 0) |
0 | 474 i_fatal("Login process must not run as root"); |
475 | |
476 /* 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
|
477 if (socketpair(AF_UNIX, SOCK_STREAM, 0, fd) < 0) { |
0 | 478 i_error("socketpair() failed: %m"); |
479 return -1; | |
480 } | |
481 | |
3083
a20882c4f092
Disable log throttlong for auth process, and for login processes if
Timo Sirainen <tss@iki.fi>
parents:
2886
diff
changeset
|
482 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
|
483 group->set->login_process_per_connection ? 10 : 0; |
a20882c4f092
Disable log throttlong for auth process, and for login processes if
Timo Sirainen <tss@iki.fi>
parents:
2886
diff
changeset
|
484 log_fd = log_create_pipe(&log, 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
|
485 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
|
486 pid = -1; |
c7c19f5071c3
Write all logging through master process. Fixes problems with log rotation,
Timo Sirainen <tss@iki.fi>
parents:
1997
diff
changeset
|
487 else { |
c7c19f5071c3
Write all logging through master process. Fixes problems with log rotation,
Timo Sirainen <tss@iki.fi>
parents:
1997
diff
changeset
|
488 pid = fork(); |
c7c19f5071c3
Write all logging through master process. Fixes problems with log rotation,
Timo Sirainen <tss@iki.fi>
parents:
1997
diff
changeset
|
489 if (pid < 0) |
c7c19f5071c3
Write all logging through master process. Fixes problems with log rotation,
Timo Sirainen <tss@iki.fi>
parents:
1997
diff
changeset
|
490 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
|
491 } |
c7c19f5071c3
Write all logging through master process. Fixes problems with log rotation,
Timo Sirainen <tss@iki.fi>
parents:
1997
diff
changeset
|
492 |
0 | 493 if (pid < 0) { |
494 (void)close(fd[0]); | |
495 (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
|
496 (void)close(log_fd); |
0 | 497 return -1; |
498 } | |
499 | |
500 if (pid != 0) { | |
501 /* master */ | |
2046 | 502 prefix = t_strdup_printf("%s-login: ", |
503 process_names[group->process_type]); | |
504 log_set_prefix(log, prefix); | |
505 | |
1273
2cf2e08a6ee9
Somewhat working code to support loading Dovecot from inetd and such. It
Timo Sirainen <tss@iki.fi>
parents:
1237
diff
changeset
|
506 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
|
507 fd_close_on_exec(fd[0], TRUE); |
1273
2cf2e08a6ee9
Somewhat working code to support loading Dovecot from inetd and such. It
Timo Sirainen <tss@iki.fi>
parents:
1237
diff
changeset
|
508 (void)login_process_new(group, pid, fd[0]); |
0 | 509 (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
|
510 (void)close(log_fd); |
0 | 511 return pid; |
512 } | |
513 | |
2046 | 514 prefix = t_strdup_printf("master-%s-login: ", |
515 process_names[group->process_type]); | |
516 log_set_prefix(log, prefix); | |
517 | |
0 | 518 /* move the listen handle */ |
1610
6850142c4e25
New configuration file code. Some syntax changes, but tries to be somewhat
Timo Sirainen <tss@iki.fi>
parents:
1506
diff
changeset
|
519 if (dup2(group->set->listen_fd, LOGIN_LISTEN_FD) < 0) |
2046 | 520 i_fatal("dup2(listen_fd) failed: %m"); |
1055
a72bba3f8a55
Rewrote setting handling. Changed some existing settings also since POP3
Timo Sirainen <tss@iki.fi>
parents:
1039
diff
changeset
|
521 fd_close_on_exec(LOGIN_LISTEN_FD, FALSE); |
0 | 522 |
523 /* move the SSL listen handle */ | |
1610
6850142c4e25
New configuration file code. Some syntax changes, but tries to be somewhat
Timo Sirainen <tss@iki.fi>
parents:
1506
diff
changeset
|
524 if (dup2(group->set->ssl_listen_fd, LOGIN_SSL_LISTEN_FD) < 0) |
2046 | 525 i_fatal("dup2(ssl_listen_fd) failed: %m"); |
1055
a72bba3f8a55
Rewrote setting handling. Changed some existing settings also since POP3
Timo Sirainen <tss@iki.fi>
parents:
1039
diff
changeset
|
526 fd_close_on_exec(LOGIN_SSL_LISTEN_FD, FALSE); |
0 | 527 |
1273
2cf2e08a6ee9
Somewhat working code to support loading Dovecot from inetd and such. It
Timo Sirainen <tss@iki.fi>
parents:
1237
diff
changeset
|
528 /* move communication handle */ |
2cf2e08a6ee9
Somewhat working code to support loading Dovecot from inetd and such. It
Timo Sirainen <tss@iki.fi>
parents:
1237
diff
changeset
|
529 if (dup2(fd[1], LOGIN_MASTER_SOCKET_FD) < 0) |
2046 | 530 i_fatal("dup2(master) 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
|
531 fd_close_on_exec(LOGIN_MASTER_SOCKET_FD, FALSE); |
0 | 532 |
2000
c7c19f5071c3
Write all logging through master process. Fixes problems with log rotation,
Timo Sirainen <tss@iki.fi>
parents:
1997
diff
changeset
|
533 if (dup2(log_fd, 2) < 0) |
2046 | 534 i_fatal("dup2(stderr) failed: %m"); |
2000
c7c19f5071c3
Write all logging through master process. Fixes problems with log rotation,
Timo Sirainen <tss@iki.fi>
parents:
1997
diff
changeset
|
535 fd_close_on_exec(2, FALSE); |
c7c19f5071c3
Write all logging through master process. Fixes problems with log rotation,
Timo Sirainen <tss@iki.fi>
parents:
1997
diff
changeset
|
536 |
0 | 537 (void)close(fd[0]); |
538 (void)close(fd[1]); | |
539 | |
1273
2cf2e08a6ee9
Somewhat working code to support loading Dovecot from inetd and such. It
Timo Sirainen <tss@iki.fi>
parents:
1237
diff
changeset
|
540 login_process_init_env(group, getpid()); |
0 | 541 |
1610
6850142c4e25
New configuration file code. Some syntax changes, but tries to be somewhat
Timo Sirainen <tss@iki.fi>
parents:
1506
diff
changeset
|
542 if (!group->set->login_chroot) { |
0 | 543 /* 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
|
544 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
|
545 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
|
546 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
|
547 } |
0 | 548 } |
549 | |
1610
6850142c4e25
New configuration file code. Some syntax changes, but tries to be somewhat
Timo Sirainen <tss@iki.fi>
parents:
1506
diff
changeset
|
550 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
|
551 |
801
86224ff16bf6
Drop root privileges earlier. Close syslog more later in imap-master when
Timo Sirainen <tss@iki.fi>
parents:
791
diff
changeset
|
552 /* 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
|
553 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
|
554 closelog(); |
86224ff16bf6
Drop root privileges earlier. Close syslog more later in imap-master when
Timo Sirainen <tss@iki.fi>
parents:
791
diff
changeset
|
555 |
2886
634cf6aa34d1
Allow running all executables with parameters.
Timo Sirainen <tss@iki.fi>
parents:
2779
diff
changeset
|
556 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
|
557 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
|
558 group->set->login_executable); |
0 | 559 return -1; |
560 } | |
561 | |
1055
a72bba3f8a55
Rewrote setting handling. Changed some existing settings also since POP3
Timo Sirainen <tss@iki.fi>
parents:
1039
diff
changeset
|
562 void login_process_abormal_exit(pid_t pid) |
615
0d852af6842e
Master process generates DH/RSA parameters now and stores them into file
Timo Sirainen <tss@iki.fi>
parents:
614
diff
changeset
|
563 { |
1055
a72bba3f8a55
Rewrote setting handling. Changed some existing settings also since POP3
Timo Sirainen <tss@iki.fi>
parents:
1039
diff
changeset
|
564 struct login_process *p; |
a72bba3f8a55
Rewrote setting handling. Changed some existing settings also since POP3
Timo Sirainen <tss@iki.fi>
parents:
1039
diff
changeset
|
565 |
615
0d852af6842e
Master process generates DH/RSA parameters now and stores them into file
Timo Sirainen <tss@iki.fi>
parents:
614
diff
changeset
|
566 /* don't start raising the process count if they're dying all |
0d852af6842e
Master process generates DH/RSA parameters now and stores them into file
Timo Sirainen <tss@iki.fi>
parents:
614
diff
changeset
|
567 the time */ |
1055
a72bba3f8a55
Rewrote setting handling. Changed some existing settings also since POP3
Timo Sirainen <tss@iki.fi>
parents:
1039
diff
changeset
|
568 p = hash_lookup(processes, POINTER_CAST(pid)); |
1275
af685269ead0
login: Wait until we're connected to auth process before executing command
Timo Sirainen <tss@iki.fi>
parents:
1273
diff
changeset
|
569 if (p != NULL && p->group != NULL) |
1055
a72bba3f8a55
Rewrote setting handling. Changed some existing settings also since POP3
Timo Sirainen <tss@iki.fi>
parents:
1039
diff
changeset
|
570 p->group->wanted_processes_count = 0; |
615
0d852af6842e
Master process generates DH/RSA parameters now and stores them into file
Timo Sirainen <tss@iki.fi>
parents:
614
diff
changeset
|
571 } |
0d852af6842e
Master process generates DH/RSA parameters now and stores them into file
Timo Sirainen <tss@iki.fi>
parents:
614
diff
changeset
|
572 |
635
90a65c017bf0
SIGHUP reloads now settings. Logged in clients are left untouched, but
Timo Sirainen <tss@iki.fi>
parents:
615
diff
changeset
|
573 void login_processes_destroy_all(void) |
90a65c017bf0
SIGHUP reloads now settings. Logged in clients are left untouched, but
Timo Sirainen <tss@iki.fi>
parents:
615
diff
changeset
|
574 { |
1897
1e6ed8045f2b
Changed hash_foreach() to iterator.
Timo Sirainen <tss@iki.fi>
parents:
1724
diff
changeset
|
575 struct hash_iterate_context *iter; |
1e6ed8045f2b
Changed hash_foreach() to iterator.
Timo Sirainen <tss@iki.fi>
parents:
1724
diff
changeset
|
576 void *key, *value; |
1e6ed8045f2b
Changed hash_foreach() to iterator.
Timo Sirainen <tss@iki.fi>
parents:
1724
diff
changeset
|
577 |
1e6ed8045f2b
Changed hash_foreach() to iterator.
Timo Sirainen <tss@iki.fi>
parents:
1724
diff
changeset
|
578 iter = hash_iterate_init(processes); |
1e6ed8045f2b
Changed hash_foreach() to iterator.
Timo Sirainen <tss@iki.fi>
parents:
1724
diff
changeset
|
579 while (hash_iterate(iter, &key, &value)) |
1e6ed8045f2b
Changed hash_foreach() to iterator.
Timo Sirainen <tss@iki.fi>
parents:
1724
diff
changeset
|
580 login_process_destroy(value); |
1e6ed8045f2b
Changed hash_foreach() to iterator.
Timo Sirainen <tss@iki.fi>
parents:
1724
diff
changeset
|
581 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
|
582 |
1055
a72bba3f8a55
Rewrote setting handling. Changed some existing settings also since POP3
Timo Sirainen <tss@iki.fi>
parents:
1039
diff
changeset
|
583 while (login_groups != NULL) { |
a72bba3f8a55
Rewrote setting handling. Changed some existing settings also since POP3
Timo Sirainen <tss@iki.fi>
parents:
1039
diff
changeset
|
584 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
|
585 |
a72bba3f8a55
Rewrote setting handling. Changed some existing settings also since POP3
Timo Sirainen <tss@iki.fi>
parents:
1039
diff
changeset
|
586 login_groups = group->next; |
a72bba3f8a55
Rewrote setting handling. Changed some existing settings also since POP3
Timo Sirainen <tss@iki.fi>
parents:
1039
diff
changeset
|
587 login_group_destroy(group); |
a72bba3f8a55
Rewrote setting handling. Changed some existing settings also since POP3
Timo Sirainen <tss@iki.fi>
parents:
1039
diff
changeset
|
588 } |
a72bba3f8a55
Rewrote setting handling. Changed some existing settings also since POP3
Timo Sirainen <tss@iki.fi>
parents:
1039
diff
changeset
|
589 } |
a72bba3f8a55
Rewrote setting handling. Changed some existing settings also since POP3
Timo Sirainen <tss@iki.fi>
parents:
1039
diff
changeset
|
590 |
a72bba3f8a55
Rewrote setting handling. Changed some existing settings also since POP3
Timo Sirainen <tss@iki.fi>
parents:
1039
diff
changeset
|
591 static void login_group_start_missings(struct login_group *group) |
a72bba3f8a55
Rewrote setting handling. Changed some existing settings also since POP3
Timo Sirainen <tss@iki.fi>
parents:
1039
diff
changeset
|
592 { |
1610
6850142c4e25
New configuration file code. Some syntax changes, but tries to be somewhat
Timo Sirainen <tss@iki.fi>
parents:
1506
diff
changeset
|
593 if (!group->set->login_process_per_connection) { |
1055
a72bba3f8a55
Rewrote setting handling. Changed some existing settings also since POP3
Timo Sirainen <tss@iki.fi>
parents:
1039
diff
changeset
|
594 /* create max. one process every second, that way if it keeps |
a72bba3f8a55
Rewrote setting handling. Changed some existing settings also since POP3
Timo Sirainen <tss@iki.fi>
parents:
1039
diff
changeset
|
595 dying all the time we don't eat all cpu with fork()ing. */ |
1610
6850142c4e25
New configuration file code. Some syntax changes, but tries to be somewhat
Timo Sirainen <tss@iki.fi>
parents:
1506
diff
changeset
|
596 if (group->listening_processes < |
6850142c4e25
New configuration file code. Some syntax changes, but tries to be somewhat
Timo Sirainen <tss@iki.fi>
parents:
1506
diff
changeset
|
597 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
|
598 (void)create_login_process(group); |
a72bba3f8a55
Rewrote setting handling. Changed some existing settings also since POP3
Timo Sirainen <tss@iki.fi>
parents:
1039
diff
changeset
|
599 return; |
a72bba3f8a55
Rewrote setting handling. Changed some existing settings also since POP3
Timo Sirainen <tss@iki.fi>
parents:
1039
diff
changeset
|
600 } |
a72bba3f8a55
Rewrote setting handling. Changed some existing settings also since POP3
Timo Sirainen <tss@iki.fi>
parents:
1039
diff
changeset
|
601 |
a72bba3f8a55
Rewrote setting handling. Changed some existing settings also since POP3
Timo Sirainen <tss@iki.fi>
parents:
1039
diff
changeset
|
602 /* 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
|
603 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
|
604 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
|
605 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
|
606 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
|
607 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
|
608 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
|
609 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
|
610 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
|
611 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
|
612 } 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
|
613 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
|
614 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
|
615 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
|
616 group->wanted_processes_count--; |
a72bba3f8a55
Rewrote setting handling. Changed some existing settings also since POP3
Timo Sirainen <tss@iki.fi>
parents:
1039
diff
changeset
|
617 |
1610
6850142c4e25
New configuration file code. Some syntax changes, but tries to be somewhat
Timo Sirainen <tss@iki.fi>
parents:
1506
diff
changeset
|
618 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
|
619 group->set->login_max_processes_count) { |
6850142c4e25
New configuration file code. Some syntax changes, but tries to be somewhat
Timo Sirainen <tss@iki.fi>
parents:
1506
diff
changeset
|
620 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
|
621 group->set->login_max_processes_count; |
6850142c4e25
New configuration file code. Some syntax changes, but tries to be somewhat
Timo Sirainen <tss@iki.fi>
parents:
1506
diff
changeset
|
622 } |
1055
a72bba3f8a55
Rewrote setting handling. Changed some existing settings also since POP3
Timo Sirainen <tss@iki.fi>
parents:
1039
diff
changeset
|
623 |
a72bba3f8a55
Rewrote setting handling. Changed some existing settings also since POP3
Timo Sirainen <tss@iki.fi>
parents:
1039
diff
changeset
|
624 while (group->listening_processes < group->wanted_processes_count) |
a72bba3f8a55
Rewrote setting handling. Changed some existing settings also since POP3
Timo Sirainen <tss@iki.fi>
parents:
1039
diff
changeset
|
625 (void)create_login_process(group); |
635
90a65c017bf0
SIGHUP reloads now settings. Logged in clients are left untouched, but
Timo Sirainen <tss@iki.fi>
parents:
615
diff
changeset
|
626 } |
90a65c017bf0
SIGHUP reloads now settings. Logged in clients are left untouched, but
Timo Sirainen <tss@iki.fi>
parents:
615
diff
changeset
|
627 |
903
fd8888f6f037
Naming style changes, finally got tired of most of the typedefs. Also the
Timo Sirainen <tss@iki.fi>
parents:
876
diff
changeset
|
628 static void |
1036
f782b3319553
Removed useless parameters from io_callback_t and timeout_callback_t.
Timo Sirainen <tss@iki.fi>
parents:
1035
diff
changeset
|
629 login_processes_start_missing(void *context __attr_unused__) |
0 | 630 { |
1055
a72bba3f8a55
Rewrote setting handling. Changed some existing settings also since POP3
Timo Sirainen <tss@iki.fi>
parents:
1039
diff
changeset
|
631 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
|
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 (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
|
634 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
|
635 |
1055
a72bba3f8a55
Rewrote setting handling. Changed some existing settings also since POP3
Timo Sirainen <tss@iki.fi>
parents:
1039
diff
changeset
|
636 for (group = login_groups; group != NULL; group = group->next) |
a72bba3f8a55
Rewrote setting handling. Changed some existing settings also since POP3
Timo Sirainen <tss@iki.fi>
parents:
1039
diff
changeset
|
637 login_group_start_missings(group); |
0 | 638 } |
639 | |
1273
2cf2e08a6ee9
Somewhat working code to support loading Dovecot from inetd and such. It
Timo Sirainen <tss@iki.fi>
parents:
1237
diff
changeset
|
640 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
|
641 { |
2cf2e08a6ee9
Somewhat working code to support loading Dovecot from inetd and such. It
Timo Sirainen <tss@iki.fi>
parents:
1237
diff
changeset
|
642 extern char **environ; |
2cf2e08a6ee9
Somewhat working code to support loading Dovecot from inetd and such. It
Timo Sirainen <tss@iki.fi>
parents:
1237
diff
changeset
|
643 char **env; |
3607
a2dd3d895e00
Several fixes to make running from inetd working again
Timo Sirainen <tss@iki.fi>
parents:
3384
diff
changeset
|
644 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
|
645 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
|
646 |
2cf2e08a6ee9
Somewhat working code to support loading Dovecot from inetd and such. It
Timo Sirainen <tss@iki.fi>
parents:
1237
diff
changeset
|
647 /* this will clear our environment. luckily we don't need it. */ |
2cf2e08a6ee9
Somewhat working code to support loading Dovecot from inetd and such. It
Timo Sirainen <tss@iki.fi>
parents:
1237
diff
changeset
|
648 login_process_init_env(p->group, p->pid); |
2cf2e08a6ee9
Somewhat working code to support loading Dovecot from inetd and such. It
Timo Sirainen <tss@iki.fi>
parents:
1237
diff
changeset
|
649 |
2cf2e08a6ee9
Somewhat working code to support loading Dovecot from inetd and such. It
Timo Sirainen <tss@iki.fi>
parents:
1237
diff
changeset
|
650 for (env = environ; *env != NULL; env++) { |
2cf2e08a6ee9
Somewhat working code to support loading Dovecot from inetd and such. It
Timo Sirainen <tss@iki.fi>
parents:
1237
diff
changeset
|
651 len = strlen(*env); |
2cf2e08a6ee9
Somewhat working code to support loading Dovecot from inetd and such. It
Timo Sirainen <tss@iki.fi>
parents:
1237
diff
changeset
|
652 |
3607
a2dd3d895e00
Several fixes to make running from inetd working again
Timo Sirainen <tss@iki.fi>
parents:
3384
diff
changeset
|
653 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
|
654 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
|
655 ret = -1; |
2cf2e08a6ee9
Somewhat working code to support loading Dovecot from inetd and such. It
Timo Sirainen <tss@iki.fi>
parents:
1237
diff
changeset
|
656 break; |
2cf2e08a6ee9
Somewhat working code to support loading Dovecot from inetd and such. It
Timo Sirainen <tss@iki.fi>
parents:
1237
diff
changeset
|
657 } |
2cf2e08a6ee9
Somewhat working code to support loading Dovecot from inetd and such. It
Timo Sirainen <tss@iki.fi>
parents:
1237
diff
changeset
|
658 } |
2cf2e08a6ee9
Somewhat working code to support loading Dovecot from inetd and such. It
Timo Sirainen <tss@iki.fi>
parents:
1237
diff
changeset
|
659 |
3607
a2dd3d895e00
Several fixes to make running from inetd working again
Timo Sirainen <tss@iki.fi>
parents:
3384
diff
changeset
|
660 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
|
661 /* 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
|
662 where its base directory is */ |
a2dd3d895e00
Several fixes to make running from inetd working again
Timo Sirainen <tss@iki.fi>
parents:
3384
diff
changeset
|
663 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
|
664 p->group->set->login_dir); |
a2dd3d895e00
Several fixes to make running from inetd working again
Timo Sirainen <tss@iki.fi>
parents:
3384
diff
changeset
|
665 len = strlen(str); |
a2dd3d895e00
Several fixes to make running from inetd working again
Timo Sirainen <tss@iki.fi>
parents:
3384
diff
changeset
|
666 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
|
667 ret = -1; |
a2dd3d895e00
Several fixes to make running from inetd working again
Timo Sirainen <tss@iki.fi>
parents:
3384
diff
changeset
|
668 } |
a2dd3d895e00
Several fixes to make running from inetd working again
Timo Sirainen <tss@iki.fi>
parents:
3384
diff
changeset
|
669 |
1273
2cf2e08a6ee9
Somewhat working code to support loading Dovecot from inetd and such. It
Timo Sirainen <tss@iki.fi>
parents:
1237
diff
changeset
|
670 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
|
671 ret = -1; |
2cf2e08a6ee9
Somewhat working code to support loading Dovecot from inetd and such. It
Timo Sirainen <tss@iki.fi>
parents:
1237
diff
changeset
|
672 |
2cf2e08a6ee9
Somewhat working code to support loading Dovecot from inetd and such. It
Timo Sirainen <tss@iki.fi>
parents:
1237
diff
changeset
|
673 env_clean(); |
2cf2e08a6ee9
Somewhat working code to support loading Dovecot from inetd and such. It
Timo Sirainen <tss@iki.fi>
parents:
1237
diff
changeset
|
674 return ret; |
2cf2e08a6ee9
Somewhat working code to support loading Dovecot from inetd and such. It
Timo Sirainen <tss@iki.fi>
parents:
1237
diff
changeset
|
675 } |
2cf2e08a6ee9
Somewhat working code to support loading Dovecot from inetd and such. It
Timo Sirainen <tss@iki.fi>
parents:
1237
diff
changeset
|
676 |
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
|
677 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
|
678 { |
af685269ead0
login: Wait until we're connected to auth process before executing command
Timo Sirainen <tss@iki.fi>
parents:
1273
diff
changeset
|
679 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
|
680 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
|
681 |
af685269ead0
login: Wait until we're connected to auth process before executing command
Timo Sirainen <tss@iki.fi>
parents:
1273
diff
changeset
|
682 if (login_process_send_env(p) < 0) { |
af685269ead0
login: Wait until we're connected to auth process before executing command
Timo Sirainen <tss@iki.fi>
parents:
1273
diff
changeset
|
683 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
|
684 return FALSE; |
af685269ead0
login: Wait until we're connected to auth process before executing command
Timo Sirainen <tss@iki.fi>
parents:
1273
diff
changeset
|
685 } |
af685269ead0
login: Wait until we're connected to auth process before executing command
Timo Sirainen <tss@iki.fi>
parents:
1273
diff
changeset
|
686 |
af685269ead0
login: Wait until we're connected to auth process before executing command
Timo Sirainen <tss@iki.fi>
parents:
1273
diff
changeset
|
687 return TRUE; |
af685269ead0
login: Wait until we're connected to auth process before executing command
Timo Sirainen <tss@iki.fi>
parents:
1273
diff
changeset
|
688 } |
af685269ead0
login: Wait until we're connected to auth process before executing command
Timo Sirainen <tss@iki.fi>
parents:
1273
diff
changeset
|
689 |
1273
2cf2e08a6ee9
Somewhat working code to support loading Dovecot from inetd and such. It
Timo Sirainen <tss@iki.fi>
parents:
1237
diff
changeset
|
690 static void inetd_login_accept(void *context __attr_unused__) |
2cf2e08a6ee9
Somewhat working code to support loading Dovecot from inetd and such. It
Timo Sirainen <tss@iki.fi>
parents:
1237
diff
changeset
|
691 { |
2cf2e08a6ee9
Somewhat working code to support loading Dovecot from inetd and such. It
Timo Sirainen <tss@iki.fi>
parents:
1237
diff
changeset
|
692 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
|
693 int fd; |
2cf2e08a6ee9
Somewhat working code to support loading Dovecot from inetd and such. It
Timo Sirainen <tss@iki.fi>
parents:
1237
diff
changeset
|
694 |
2cf2e08a6ee9
Somewhat working code to support loading Dovecot from inetd and such. It
Timo Sirainen <tss@iki.fi>
parents:
1237
diff
changeset
|
695 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
|
696 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
|
697 if (fd < -1) |
2cf2e08a6ee9
Somewhat working code to support loading Dovecot from inetd and such. It
Timo Sirainen <tss@iki.fi>
parents:
1237
diff
changeset
|
698 i_fatal("accept(inetd_login_fd) failed: %m"); |
2cf2e08a6ee9
Somewhat working code to support loading Dovecot from inetd and such. It
Timo Sirainen <tss@iki.fi>
parents:
1237
diff
changeset
|
699 } else { |
2cf2e08a6ee9
Somewhat working code to support loading Dovecot from inetd and such. It
Timo Sirainen <tss@iki.fi>
parents:
1237
diff
changeset
|
700 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
|
701 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
|
702 |
1275
af685269ead0
login: Wait until we're connected to auth process before executing command
Timo Sirainen <tss@iki.fi>
parents:
1273
diff
changeset
|
703 p = login_process_new(NULL, ++login_pid_counter, fd); |
af685269ead0
login: Wait until we're connected to auth process before executing command
Timo Sirainen <tss@iki.fi>
parents:
1273
diff
changeset
|
704 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
|
705 } |
2cf2e08a6ee9
Somewhat working code to support loading Dovecot from inetd and such. It
Timo Sirainen <tss@iki.fi>
parents:
1237
diff
changeset
|
706 } |
2cf2e08a6ee9
Somewhat working code to support loading Dovecot from inetd and such. It
Timo Sirainen <tss@iki.fi>
parents:
1237
diff
changeset
|
707 |
0 | 708 void login_processes_init(void) |
709 { | |
1273
2cf2e08a6ee9
Somewhat working code to support loading Dovecot from inetd and such. It
Timo Sirainen <tss@iki.fi>
parents:
1237
diff
changeset
|
710 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
|
711 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
|
712 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
|
713 |
945
501f076f2e74
Rewrote hash table code, works with less memory now. Also some memory
Timo Sirainen <tss@iki.fi>
parents:
929
diff
changeset
|
714 processes = hash_create(default_pool, default_pool, 128, NULL, NULL); |
1273
2cf2e08a6ee9
Somewhat working code to support loading Dovecot from inetd and such. It
Timo Sirainen <tss@iki.fi>
parents:
1237
diff
changeset
|
715 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
|
716 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
|
717 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
|
718 } else { |
2cf2e08a6ee9
Somewhat working code to support loading Dovecot from inetd and such. It
Timo Sirainen <tss@iki.fi>
parents:
1237
diff
changeset
|
719 to = NULL; |
2cf2e08a6ee9
Somewhat working code to support loading Dovecot from inetd and such. It
Timo Sirainen <tss@iki.fi>
parents:
1237
diff
changeset
|
720 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
|
721 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
|
722 } |
0 | 723 } |
724 | |
725 void login_processes_deinit(void) | |
726 { | |
1273
2cf2e08a6ee9
Somewhat working code to support loading Dovecot from inetd and such. It
Timo Sirainen <tss@iki.fi>
parents:
1237
diff
changeset
|
727 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
|
728 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
|
729 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
|
730 io_remove(&io_listen); |
0 | 731 |
635
90a65c017bf0
SIGHUP reloads now settings. Logged in clients are left untouched, but
Timo Sirainen <tss@iki.fi>
parents:
615
diff
changeset
|
732 login_processes_destroy_all(); |
0 | 733 hash_destroy(processes); |
734 } |