Mercurial > dovecot > original-hg > dovecot-1.2
annotate src/master/login-process.c @ 613:1906116a62ce HEAD
Finally support for handling each login connection in it's own process.
Enabled by default. Also a few bugfixes to master process.
author | Timo Sirainen <tss@iki.fi> |
---|---|
date | Sat, 16 Nov 2002 07:21:21 +0200 |
parents | ab3590c3a7d9 |
children | e60620644af3 |
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" |
410
1f0e7229ee58
Split IOBuffer into mmaped IBuffer, file IBuffer, memory data IBuffer and
Timo Sirainen <tss@iki.fi>
parents:
364
diff
changeset
|
6 #include "obuffer.h" |
0 | 7 #include "fdpass.h" |
8 #include "restrict-access.h" | |
9 #include "login-process.h" | |
10 #include "auth-process.h" | |
11 #include "master-interface.h" | |
12 | |
13 #include <stdlib.h> | |
14 #include <unistd.h> | |
15 #include <syslog.h> | |
16 | |
613
1906116a62ce
Finally support for handling each login connection in it's own process.
Timo Sirainen <tss@iki.fi>
parents:
596
diff
changeset
|
17 typedef struct _LoginProcess LoginProcess; |
1906116a62ce
Finally support for handling each login connection in it's own process.
Timo Sirainen <tss@iki.fi>
parents:
596
diff
changeset
|
18 |
1906116a62ce
Finally support for handling each login connection in it's own process.
Timo Sirainen <tss@iki.fi>
parents:
596
diff
changeset
|
19 struct _LoginProcess { |
1906116a62ce
Finally support for handling each login connection in it's own process.
Timo Sirainen <tss@iki.fi>
parents:
596
diff
changeset
|
20 LoginProcess *prev_nonlisten, *next_nonlisten; |
0 | 21 int refcount; |
22 | |
23 pid_t pid; | |
24 int fd; | |
25 IO io; | |
410
1f0e7229ee58
Split IOBuffer into mmaped IBuffer, file IBuffer, memory data IBuffer and
Timo Sirainen <tss@iki.fi>
parents:
364
diff
changeset
|
26 OBuffer *outbuf; |
613
1906116a62ce
Finally support for handling each login connection in it's own process.
Timo Sirainen <tss@iki.fi>
parents:
596
diff
changeset
|
27 unsigned int listening:1; |
0 | 28 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
|
29 }; |
0 | 30 |
31 typedef struct { | |
32 LoginProcess *process; | |
33 int login_id; | |
34 int auth_id; | |
35 int fd; | |
36 | |
596
ab3590c3a7d9
Added verbose_proctitle setting: Show more verbose process titles (in ps).
Timo Sirainen <tss@iki.fi>
parents:
532
diff
changeset
|
37 IPADDR ip; |
0 | 38 char login_tag[LOGIN_TAG_SIZE]; |
39 } LoginAuthRequest; | |
40 | |
41 static int auth_id_counter; | |
42 static Timeout to; | |
613
1906116a62ce
Finally support for handling each login connection in it's own process.
Timo Sirainen <tss@iki.fi>
parents:
596
diff
changeset
|
43 |
1906116a62ce
Finally support for handling each login connection in it's own process.
Timo Sirainen <tss@iki.fi>
parents:
596
diff
changeset
|
44 static HashTable *processes; |
1906116a62ce
Finally support for handling each login connection in it's own process.
Timo Sirainen <tss@iki.fi>
parents:
596
diff
changeset
|
45 static LoginProcess *oldest_nonlisten_process, *newest_nonlisten_process; |
1906116a62ce
Finally support for handling each login connection in it's own process.
Timo Sirainen <tss@iki.fi>
parents:
596
diff
changeset
|
46 static unsigned int listening_processes; |
0 | 47 |
48 static void login_process_destroy(LoginProcess *p); | |
49 static void login_process_unref(LoginProcess *p); | |
50 | |
10
82b7de533f98
s/user_data/context/ and some s/Data/Context/
Timo Sirainen <tss@iki.fi>
parents:
0
diff
changeset
|
51 static void auth_callback(AuthCookieReplyData *cookie_reply, void *context) |
0 | 52 { |
53 const char *env[] = { | |
54 "MAIL", NULL, | |
55 "LOGIN_TAG", NULL, | |
56 NULL | |
57 }; | |
10
82b7de533f98
s/user_data/context/ and some s/Data/Context/
Timo Sirainen <tss@iki.fi>
parents:
0
diff
changeset
|
58 LoginAuthRequest *request = context; |
0 | 59 LoginProcess *process; |
60 MasterReply reply; | |
61 | |
62 env[1] = cookie_reply->mail; | |
63 env[3] = request->login_tag; | |
64 | |
65 if (cookie_reply == NULL || !cookie_reply->success) | |
66 reply.result = MASTER_RESULT_FAILURE; | |
67 else { | |
68 reply.result = create_imap_process(request->fd, | |
596
ab3590c3a7d9
Added verbose_proctitle setting: Show more verbose process titles (in ps).
Timo Sirainen <tss@iki.fi>
parents:
532
diff
changeset
|
69 &request->ip, |
0 | 70 cookie_reply->user, |
71 cookie_reply->uid, | |
72 cookie_reply->gid, | |
73 cookie_reply->home, | |
74 cookie_reply->chroot, env); | |
75 } | |
76 | |
77 /* reply to login */ | |
78 reply.id = request->login_id; | |
79 | |
80 process = request->process; | |
410
1f0e7229ee58
Split IOBuffer into mmaped IBuffer, file IBuffer, memory data IBuffer and
Timo Sirainen <tss@iki.fi>
parents:
364
diff
changeset
|
81 if (o_buffer_send(process->outbuf, &reply, sizeof(reply)) < 0) |
0 | 82 login_process_destroy(process); |
83 | |
84 (void)close(request->fd); | |
85 login_process_unref(process); | |
86 i_free(request); | |
87 } | |
88 | |
10
82b7de533f98
s/user_data/context/ and some s/Data/Context/
Timo Sirainen <tss@iki.fi>
parents:
0
diff
changeset
|
89 static void login_process_input(void *context, int fd __attr_unused__, |
0 | 90 IO io __attr_unused__) |
91 { | |
10
82b7de533f98
s/user_data/context/ and some s/Data/Context/
Timo Sirainen <tss@iki.fi>
parents:
0
diff
changeset
|
92 LoginProcess *p = context; |
0 | 93 AuthProcess *auth_process; |
94 LoginAuthRequest *authreq; | |
95 MasterRequest req; | |
96 int client_fd, ret; | |
97 | |
98 ret = fd_read(p->fd, &req, sizeof(req), &client_fd); | |
99 if (ret != sizeof(req)) { | |
100 if (ret == 0) { | |
101 /* disconnected, ie. the login process died */ | |
102 } else if (ret > 0) { | |
103 /* req wasn't fully read */ | |
104 i_error("login: fd_read() couldn't read all req"); | |
105 } else { | |
106 i_error("login: fd_read() failed: %m"); | |
107 } | |
108 | |
109 login_process_destroy(p); | |
110 return; | |
111 } | |
112 | |
613
1906116a62ce
Finally support for handling each login connection in it's own process.
Timo Sirainen <tss@iki.fi>
parents:
596
diff
changeset
|
113 if (client_fd == -1) { |
1906116a62ce
Finally support for handling each login connection in it's own process.
Timo Sirainen <tss@iki.fi>
parents:
596
diff
changeset
|
114 /* just a notification that the login process isn't |
1906116a62ce
Finally support for handling each login connection in it's own process.
Timo Sirainen <tss@iki.fi>
parents:
596
diff
changeset
|
115 listening for new connections anymore */ |
1906116a62ce
Finally support for handling each login connection in it's own process.
Timo Sirainen <tss@iki.fi>
parents:
596
diff
changeset
|
116 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
|
117 i_error("login: received another \"not listening\" " |
1906116a62ce
Finally support for handling each login connection in it's own process.
Timo Sirainen <tss@iki.fi>
parents:
596
diff
changeset
|
118 "notification"); |
1906116a62ce
Finally support for handling each login connection in it's own process.
Timo Sirainen <tss@iki.fi>
parents:
596
diff
changeset
|
119 } else { |
1906116a62ce
Finally support for handling each login connection in it's own process.
Timo Sirainen <tss@iki.fi>
parents:
596
diff
changeset
|
120 p->listening = FALSE; |
1906116a62ce
Finally support for handling each login connection in it's own process.
Timo Sirainen <tss@iki.fi>
parents:
596
diff
changeset
|
121 listening_processes--; |
1906116a62ce
Finally support for handling each login connection in it's own process.
Timo Sirainen <tss@iki.fi>
parents:
596
diff
changeset
|
122 |
1906116a62ce
Finally support for handling each login connection in it's own process.
Timo Sirainen <tss@iki.fi>
parents:
596
diff
changeset
|
123 p->prev_nonlisten = newest_nonlisten_process; |
1906116a62ce
Finally support for handling each login connection in it's own process.
Timo Sirainen <tss@iki.fi>
parents:
596
diff
changeset
|
124 |
1906116a62ce
Finally support for handling each login connection in it's own process.
Timo Sirainen <tss@iki.fi>
parents:
596
diff
changeset
|
125 if (newest_nonlisten_process != NULL) |
1906116a62ce
Finally support for handling each login connection in it's own process.
Timo Sirainen <tss@iki.fi>
parents:
596
diff
changeset
|
126 newest_nonlisten_process->next_nonlisten = p; |
1906116a62ce
Finally support for handling each login connection in it's own process.
Timo Sirainen <tss@iki.fi>
parents:
596
diff
changeset
|
127 newest_nonlisten_process = p; |
1906116a62ce
Finally support for handling each login connection in it's own process.
Timo Sirainen <tss@iki.fi>
parents:
596
diff
changeset
|
128 |
1906116a62ce
Finally support for handling each login connection in it's own process.
Timo Sirainen <tss@iki.fi>
parents:
596
diff
changeset
|
129 if (oldest_nonlisten_process == NULL) |
1906116a62ce
Finally support for handling each login connection in it's own process.
Timo Sirainen <tss@iki.fi>
parents:
596
diff
changeset
|
130 oldest_nonlisten_process = p; |
1906116a62ce
Finally support for handling each login connection in it's own process.
Timo Sirainen <tss@iki.fi>
parents:
596
diff
changeset
|
131 } |
1906116a62ce
Finally support for handling each login connection in it's own process.
Timo Sirainen <tss@iki.fi>
parents:
596
diff
changeset
|
132 return; |
1906116a62ce
Finally support for handling each login connection in it's own process.
Timo Sirainen <tss@iki.fi>
parents:
596
diff
changeset
|
133 } |
1906116a62ce
Finally support for handling each login connection in it's own process.
Timo Sirainen <tss@iki.fi>
parents:
596
diff
changeset
|
134 |
0 | 135 /* login process isn't trusted, validate all data to make sure |
136 it's not trying to exploit us */ | |
137 if (!VALIDATE_STR(req.login_tag)) { | |
138 i_error("login: Received corrupted data"); | |
139 login_process_destroy(p); | |
140 return; | |
141 } | |
142 | |
143 /* ask the cookie from the auth process */ | |
144 authreq = i_new(LoginAuthRequest, 1); | |
145 p->refcount++; | |
146 authreq->process = p; | |
147 authreq->login_id = req.id; | |
148 authreq->auth_id = ++auth_id_counter; | |
149 authreq->fd = client_fd; | |
596
ab3590c3a7d9
Added verbose_proctitle setting: Show more verbose process titles (in ps).
Timo Sirainen <tss@iki.fi>
parents:
532
diff
changeset
|
150 memcpy(&authreq->ip, &req.ip, sizeof(IPADDR)); |
0 | 151 strcpy(authreq->login_tag, req.login_tag); |
152 | |
153 auth_process = auth_process_find(req.auth_process); | |
154 if (auth_process == NULL) { | |
155 i_error("login: Authentication process %u doesn't exist", | |
156 req.auth_process); | |
613
1906116a62ce
Finally support for handling each login connection in it's own process.
Timo Sirainen <tss@iki.fi>
parents:
596
diff
changeset
|
157 auth_callback(NULL, authreq); |
0 | 158 } else { |
159 auth_process_request(auth_process, authreq->auth_id, req.cookie, | |
160 auth_callback, authreq); | |
161 } | |
162 } | |
163 | |
164 static LoginProcess *login_process_new(pid_t pid, int fd) | |
165 { | |
166 LoginProcess *p; | |
167 | |
168 PID_ADD_PROCESS_TYPE(pid, PROCESS_TYPE_LOGIN); | |
169 | |
170 p = i_new(LoginProcess, 1); | |
171 p->refcount = 1; | |
172 p->pid = pid; | |
173 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
|
174 p->listening = TRUE; |
0 | 175 p->io = io_add(fd, IO_READ, login_process_input, p); |
410
1f0e7229ee58
Split IOBuffer into mmaped IBuffer, file IBuffer, memory data IBuffer and
Timo Sirainen <tss@iki.fi>
parents:
364
diff
changeset
|
176 p->outbuf = o_buffer_create_file(fd, default_pool, |
1f0e7229ee58
Split IOBuffer into mmaped IBuffer, file IBuffer, memory data IBuffer and
Timo Sirainen <tss@iki.fi>
parents:
364
diff
changeset
|
177 sizeof(MasterReply)*10, |
1f0e7229ee58
Split IOBuffer into mmaped IBuffer, file IBuffer, memory data IBuffer and
Timo Sirainen <tss@iki.fi>
parents:
364
diff
changeset
|
178 IO_PRIORITY_DEFAULT, FALSE); |
0 | 179 |
195
db6e288be0e9
Replaced INT_TO_POINTER and POINTER_TO_INT macros with POINTER_CAST and
Timo Sirainen <tss@iki.fi>
parents:
10
diff
changeset
|
180 hash_insert(processes, POINTER_CAST(pid), p); |
613
1906116a62ce
Finally support for handling each login connection in it's own process.
Timo Sirainen <tss@iki.fi>
parents:
596
diff
changeset
|
181 listening_processes++; |
0 | 182 return p; |
183 } | |
184 | |
613
1906116a62ce
Finally support for handling each login connection in it's own process.
Timo Sirainen <tss@iki.fi>
parents:
596
diff
changeset
|
185 void login_process_remove_from_lists(LoginProcess *p) |
1906116a62ce
Finally support for handling each login connection in it's own process.
Timo Sirainen <tss@iki.fi>
parents:
596
diff
changeset
|
186 { |
1906116a62ce
Finally support for handling each login connection in it's own process.
Timo Sirainen <tss@iki.fi>
parents:
596
diff
changeset
|
187 if (p == oldest_nonlisten_process) |
1906116a62ce
Finally support for handling each login connection in it's own process.
Timo Sirainen <tss@iki.fi>
parents:
596
diff
changeset
|
188 oldest_nonlisten_process = 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
|
189 else |
1906116a62ce
Finally support for handling each login connection in it's own process.
Timo Sirainen <tss@iki.fi>
parents:
596
diff
changeset
|
190 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
|
191 |
1906116a62ce
Finally support for handling each login connection in it's own process.
Timo Sirainen <tss@iki.fi>
parents:
596
diff
changeset
|
192 if (p == newest_nonlisten_process) |
1906116a62ce
Finally support for handling each login connection in it's own process.
Timo Sirainen <tss@iki.fi>
parents:
596
diff
changeset
|
193 newest_nonlisten_process = 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
|
194 else |
1906116a62ce
Finally support for handling each login connection in it's own process.
Timo Sirainen <tss@iki.fi>
parents:
596
diff
changeset
|
195 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
|
196 |
1906116a62ce
Finally support for handling each login connection in it's own process.
Timo Sirainen <tss@iki.fi>
parents:
596
diff
changeset
|
197 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
|
198 } |
1906116a62ce
Finally support for handling each login connection in it's own process.
Timo Sirainen <tss@iki.fi>
parents:
596
diff
changeset
|
199 |
0 | 200 static void login_process_destroy(LoginProcess *p) |
201 { | |
202 if (p->destroyed) | |
203 return; | |
204 p->destroyed = TRUE; | |
205 | |
613
1906116a62ce
Finally support for handling each login connection in it's own process.
Timo Sirainen <tss@iki.fi>
parents:
596
diff
changeset
|
206 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
|
207 listening_processes--; |
1906116a62ce
Finally support for handling each login connection in it's own process.
Timo Sirainen <tss@iki.fi>
parents:
596
diff
changeset
|
208 |
410
1f0e7229ee58
Split IOBuffer into mmaped IBuffer, file IBuffer, memory data IBuffer and
Timo Sirainen <tss@iki.fi>
parents:
364
diff
changeset
|
209 o_buffer_close(p->outbuf); |
0 | 210 io_remove(p->io); |
211 (void)close(p->fd); | |
212 | |
613
1906116a62ce
Finally support for handling each login connection in it's own process.
Timo Sirainen <tss@iki.fi>
parents:
596
diff
changeset
|
213 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
|
214 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
|
215 |
195
db6e288be0e9
Replaced INT_TO_POINTER and POINTER_TO_INT macros with POINTER_CAST and
Timo Sirainen <tss@iki.fi>
parents:
10
diff
changeset
|
216 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
|
217 |
0 | 218 login_process_unref(p); |
219 } | |
220 | |
221 static void login_process_unref(LoginProcess *p) | |
222 { | |
223 if (--p->refcount > 0) | |
224 return; | |
225 | |
410
1f0e7229ee58
Split IOBuffer into mmaped IBuffer, file IBuffer, memory data IBuffer and
Timo Sirainen <tss@iki.fi>
parents:
364
diff
changeset
|
226 o_buffer_unref(p->outbuf); |
0 | 227 i_free(p); |
228 } | |
229 | |
230 static pid_t create_login_process(void) | |
231 { | |
232 static const char *argv[] = { NULL, NULL }; | |
233 pid_t pid; | |
234 int fd[2]; | |
235 | |
613
1906116a62ce
Finally support for handling each login connection in it's own process.
Timo Sirainen <tss@iki.fi>
parents:
596
diff
changeset
|
236 if (set_login_process_per_connection && |
1906116a62ce
Finally support for handling each login connection in it's own process.
Timo Sirainen <tss@iki.fi>
parents:
596
diff
changeset
|
237 hash_size(processes)-listening_processes >= set_max_logging_users) { |
1906116a62ce
Finally support for handling each login connection in it's own process.
Timo Sirainen <tss@iki.fi>
parents:
596
diff
changeset
|
238 if (oldest_nonlisten_process != NULL) |
1906116a62ce
Finally support for handling each login connection in it's own process.
Timo Sirainen <tss@iki.fi>
parents:
596
diff
changeset
|
239 login_process_destroy(oldest_nonlisten_process); |
1906116a62ce
Finally support for handling each login connection in it's own process.
Timo Sirainen <tss@iki.fi>
parents:
596
diff
changeset
|
240 } |
1906116a62ce
Finally support for handling each login connection in it's own process.
Timo Sirainen <tss@iki.fi>
parents:
596
diff
changeset
|
241 |
0 | 242 if (set_login_uid == 0) |
243 i_fatal("Login process must not run as root"); | |
244 | |
245 /* create communication to process with a socket pair */ | |
246 if (socketpair(AF_UNIX, SOCK_STREAM, 0, fd) == -1) { | |
247 i_error("socketpair() failed: %m"); | |
248 return -1; | |
249 } | |
250 | |
251 pid = fork(); | |
252 if (pid < 0) { | |
253 (void)close(fd[0]); | |
254 (void)close(fd[1]); | |
255 i_error("fork() failed: %m"); | |
256 return -1; | |
257 } | |
258 | |
259 if (pid != 0) { | |
260 /* master */ | |
261 login_process_new(pid, fd[0]); | |
262 (void)close(fd[1]); | |
263 return pid; | |
264 } | |
265 | |
266 /* move communication handle */ | |
267 if (dup2(fd[1], LOGIN_MASTER_SOCKET_FD) < 0) | |
268 i_fatal("login: dup2() failed: %m"); | |
269 | |
270 /* move the listen handle */ | |
271 if (dup2(imap_fd, LOGIN_IMAP_LISTEN_FD) < 0) | |
272 i_fatal("login: dup2() failed: %m"); | |
273 | |
274 /* move the SSL listen handle */ | |
275 if (dup2(imaps_fd, LOGIN_IMAPS_LISTEN_FD) < 0) | |
276 i_fatal("login: dup2() failed: %m"); | |
277 | |
278 /* imap_fd and imaps_fd are closed by clean_child_process() */ | |
279 | |
280 (void)close(fd[0]); | |
281 (void)close(fd[1]); | |
282 | |
283 clean_child_process(); | |
284 | |
285 /* setup access environment - needs to be done after | |
286 clean_child_process() since it clears environment */ | |
287 restrict_access_set_env(set_login_user, set_login_uid, set_login_gid, | |
288 set_login_chroot ? set_login_dir : NULL); | |
289 | |
290 if (!set_login_chroot) { | |
291 /* no chrooting, but still change to the directory */ | |
292 if (chdir(set_login_dir) < 0) { | |
293 i_fatal("chdir(%s) failed: %m", | |
294 set_login_dir); | |
295 } | |
296 } | |
297 | |
298 if (set_ssl_cert_file != NULL) { | |
299 putenv((char *) t_strconcat("SSL_CERT_FILE=", | |
300 set_ssl_cert_file, NULL)); | |
301 } | |
302 | |
303 if (set_ssl_key_file != NULL) { | |
304 putenv((char *) t_strconcat("SSL_KEY_FILE=", | |
305 set_ssl_key_file, NULL)); | |
306 } | |
307 | |
308 if (set_disable_plaintext_auth) | |
309 putenv("DISABLE_PLAINTEXT_AUTH=1"); | |
310 | |
613
1906116a62ce
Finally support for handling each login connection in it's own process.
Timo Sirainen <tss@iki.fi>
parents:
596
diff
changeset
|
311 if (set_login_process_per_connection) { |
1906116a62ce
Finally support for handling each login connection in it's own process.
Timo Sirainen <tss@iki.fi>
parents:
596
diff
changeset
|
312 putenv("PROCESS_PER_CONNECTION=1"); |
1906116a62ce
Finally support for handling each login connection in it's own process.
Timo Sirainen <tss@iki.fi>
parents:
596
diff
changeset
|
313 putenv("MAX_LOGGING_USERS=1"); |
1906116a62ce
Finally support for handling each login connection in it's own process.
Timo Sirainen <tss@iki.fi>
parents:
596
diff
changeset
|
314 } else { |
1906116a62ce
Finally support for handling each login connection in it's own process.
Timo Sirainen <tss@iki.fi>
parents:
596
diff
changeset
|
315 putenv((char *) t_strdup_printf("MAX_LOGGING_USERS=%d", |
1906116a62ce
Finally support for handling each login connection in it's own process.
Timo Sirainen <tss@iki.fi>
parents:
596
diff
changeset
|
316 set_max_logging_users)); |
1906116a62ce
Finally support for handling each login connection in it's own process.
Timo Sirainen <tss@iki.fi>
parents:
596
diff
changeset
|
317 } |
0 | 318 |
319 /* hide the path, it's ugly */ | |
320 argv[0] = strrchr(set_login_executable, '/'); | |
321 if (argv[0] == NULL) argv[0] = set_login_executable; else argv[0]++; | |
322 | |
323 execv(set_login_executable, (char **) argv); | |
324 | |
325 i_fatal("execv(%s) failed: %m", argv[0]); | |
326 return -1; | |
327 } | |
328 | |
329 static void login_hash_cleanup(void *key __attr_unused__, void *value, | |
10
82b7de533f98
s/user_data/context/ and some s/Data/Context/
Timo Sirainen <tss@iki.fi>
parents:
0
diff
changeset
|
330 void *context __attr_unused__) |
0 | 331 { |
332 LoginProcess *p = value; | |
333 | |
334 (void)close(p->fd); | |
335 } | |
336 | |
337 void login_processes_cleanup(void) | |
338 { | |
339 hash_foreach(processes, login_hash_cleanup, NULL); | |
340 } | |
341 | |
10
82b7de533f98
s/user_data/context/ and some s/Data/Context/
Timo Sirainen <tss@iki.fi>
parents:
0
diff
changeset
|
342 static void login_processes_start_missing(void *context __attr_unused__, |
0 | 343 Timeout timeout __attr_unused__) |
344 { | |
345 /* create max. one process every second, that way if it keeps | |
346 dying all the time we don't eat all cpu with fork()ing. */ | |
613
1906116a62ce
Finally support for handling each login connection in it's own process.
Timo Sirainen <tss@iki.fi>
parents:
596
diff
changeset
|
347 if (listening_processes < set_login_processes_count) |
0 | 348 (void)create_login_process(); |
349 } | |
350 | |
351 void login_processes_init(void) | |
352 { | |
353 auth_id_counter = 0; | |
613
1906116a62ce
Finally support for handling each login connection in it's own process.
Timo Sirainen <tss@iki.fi>
parents:
596
diff
changeset
|
354 listening_processes = 0; |
1906116a62ce
Finally support for handling each login connection in it's own process.
Timo Sirainen <tss@iki.fi>
parents:
596
diff
changeset
|
355 oldest_nonlisten_process = newest_nonlisten_process = NULL; |
1906116a62ce
Finally support for handling each login connection in it's own process.
Timo Sirainen <tss@iki.fi>
parents:
596
diff
changeset
|
356 |
1906116a62ce
Finally support for handling each login connection in it's own process.
Timo Sirainen <tss@iki.fi>
parents:
596
diff
changeset
|
357 processes = hash_create(default_pool, 128, NULL, NULL); |
0 | 358 to = timeout_add(1000, login_processes_start_missing, NULL); |
359 } | |
360 | |
361 static void login_hash_destroy(void *key __attr_unused__, void *value, | |
10
82b7de533f98
s/user_data/context/ and some s/Data/Context/
Timo Sirainen <tss@iki.fi>
parents:
0
diff
changeset
|
362 void *context __attr_unused__) |
0 | 363 { |
364 login_process_destroy(value); | |
365 } | |
366 | |
367 void login_processes_deinit(void) | |
368 { | |
369 timeout_remove(to); | |
370 | |
371 hash_foreach(processes, login_hash_destroy, NULL); | |
372 hash_destroy(processes); | |
373 } |