diff options
Diffstat (limited to 'src/net.c')
-rw-r--r-- | src/net.c | 87 |
1 files changed, 56 insertions, 31 deletions
@@ -23,8 +23,5 @@ open_listener () | |||
23 | 23 | ||
24 | if (listen_sockaddr.sa == NULL) | 24 | if (listen_sockaddr.sa == NULL) |
25 | { | 25 | return -1; |
26 | logmsg (LOG_CRIT, _("listener address is not configured")); | ||
27 | exit (EX_CONFIG); | ||
28 | } | ||
29 | 26 | ||
30 | fd = socket (listen_sockaddr.sa->sa_family, SOCK_STREAM, 0); | 27 | fd = socket (listen_sockaddr.sa->sa_family, SOCK_STREAM, 0); |
@@ -100,5 +97,5 @@ handle_connection (FILE *in, FILE *out) | |||
100 | char *buf = NULL; | 97 | char *buf = NULL; |
101 | size_t buflen = 0; | 98 | size_t buflen = 0; |
102 | const struct spool *spool; | 99 | struct spool *spool; |
103 | char *p; | 100 | char *p; |
104 | struct passwd *pw; | 101 | struct passwd *pw; |
@@ -175,5 +172,20 @@ wydawca_listener () | |||
175 | { | 172 | { |
176 | int ctlfd = open_listener (); | 173 | int ctlfd = open_listener (); |
174 | int wfd = watcher_init (); | ||
175 | int maxfd = 0; | ||
176 | |||
177 | if (ctlfd != -1) | ||
178 | maxfd = ctlfd; | ||
179 | |||
180 | if (wfd != -1 && wfd > maxfd) | ||
181 | maxfd = wfd; | ||
177 | 182 | ||
183 | if (maxfd == 0) | ||
184 | { | ||
185 | logmsg (LOG_CRIT, | ||
186 | _("listener address is not configured and inotify is not available")); | ||
187 | exit (EX_CONFIG); | ||
188 | } | ||
189 | |||
178 | job_init (); | 190 | job_init (); |
179 | signal (SIGHUP, sig_hup); | 191 | signal (SIGHUP, sig_hup); |
@@ -183,19 +195,14 @@ wydawca_listener () | |||
183 | while (!terminate) | 195 | while (!terminate) |
184 | { | 196 | { |
185 | int fd; | ||
186 | FILE *in, *out; | ||
187 | int rc; | 197 | int rc; |
188 | fd_set rset; | 198 | fd_set rset; |
189 | struct timeval to, *pto; | 199 | struct timeval to, *pto; |
190 | union { | ||
191 | struct sockaddr sa; | ||
192 | struct sockaddr_in s_in; | ||
193 | struct sockaddr_un s_un; | ||
194 | } addr; | ||
195 | socklen_t len; | ||
196 | 200 | ||
197 | job_queue_runner (); | 201 | job_queue_runner (); |
198 | FD_ZERO (&rset); | 202 | FD_ZERO (&rset); |
199 | FD_SET (ctlfd, &rset); | 203 | if (ctlfd != -1) |
204 | FD_SET (ctlfd, &rset); | ||
205 | if (wfd != -1) | ||
206 | FD_SET (wfd, &rset); | ||
200 | 207 | ||
201 | if (wakeup_interval) | 208 | if (wakeup_interval) |
@@ -208,5 +215,5 @@ wydawca_listener () | |||
208 | pto = NULL; | 215 | pto = NULL; |
209 | 216 | ||
210 | rc = select (ctlfd + 1, &rset, NULL, NULL, pto); | 217 | rc = select (maxfd + 1, &rset, NULL, NULL, pto); |
211 | if (rc == 0) | 218 | if (rc == 0) |
212 | continue; | 219 | continue; |
@@ -219,24 +226,42 @@ wydawca_listener () | |||
219 | } | 226 | } |
220 | 227 | ||
221 | len = sizeof (addr); | 228 | if (wfd != -1 && FD_ISSET (wfd, &rset)) |
222 | fd = accept (ctlfd, (struct sockaddr*) &addr, &len); | ||
223 | if (fd == -1) | ||
224 | continue; | ||
225 | /* FIXME: Use Mailutils ACLs? */ | ||
226 | #ifdef WITH_LIBWRAP | ||
227 | if (!tcpwrap_access(fd)) | ||
228 | { | 229 | { |
229 | close(fd); | 230 | watcher_run (wfd); |
230 | continue; | ||
231 | } | 231 | } |
232 | |||
233 | if (ctlfd != -1 && FD_ISSET (ctlfd, &rset)) | ||
234 | { | ||
235 | int fd; | ||
236 | FILE *in, *out; | ||
237 | union | ||
238 | { | ||
239 | struct sockaddr sa; | ||
240 | struct sockaddr_in s_in; | ||
241 | struct sockaddr_un s_un; | ||
242 | } addr; | ||
243 | socklen_t len; | ||
244 | |||
245 | len = sizeof (addr); | ||
246 | fd = accept (ctlfd, (struct sockaddr*) &addr, &len); | ||
247 | if (fd == -1) | ||
248 | continue; | ||
249 | /* FIXME: Use Mailutils ACLs? */ | ||
250 | #ifdef WITH_LIBWRAP | ||
251 | if (!tcpwrap_access(fd)) | ||
252 | { | ||
253 | close(fd); | ||
254 | continue; | ||
255 | } | ||
232 | #endif | 256 | #endif |
233 | 257 | ||
234 | in = fdopen (fd, "r"); | 258 | in = fdopen (fd, "r"); |
235 | setlinebuf (in); | 259 | setlinebuf (in); |
236 | out = fdopen (fd, "w"); | 260 | out = fdopen (fd, "w"); |
237 | setlinebuf (out); | 261 | setlinebuf (out); |
238 | handle_connection (in, out); | 262 | handle_connection (in, out); |
239 | fclose (in); | 263 | fclose (in); |
240 | fclose (out); | 264 | fclose (out); |
265 | } | ||
241 | } | 266 | } |
242 | } | 267 | } |