summaryrefslogtreecommitdiffabout
path: root/src/net.c
Unidiff
Diffstat (limited to 'src/net.c') (more/less context) (ignore whitespace changes)
-rw-r--r--src/net.c87
1 files changed, 56 insertions, 31 deletions
diff --git a/src/net.c b/src/net.c
index 4857fa2..3157fe8 100644
--- a/src/net.c
+++ b/src/net.c
@@ -24,6 +24,3 @@ open_listener ()
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
@@ -101,3 +98,3 @@ handle_connection (FILE *in, FILE *out)
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;
@@ -176,3 +173,18 @@ wydawca_listener ()
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 ();
@@ -184,4 +196,2 @@ wydawca_listener ()
184 { 196 {
185 int fd;
186 FILE *in, *out;
187 int rc; 197 int rc;
@@ -189,8 +199,2 @@ wydawca_listener ()
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
@@ -198,3 +202,6 @@ wydawca_listener ()
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
@@ -209,3 +216,3 @@ wydawca_listener ()
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)
@@ -220,22 +227,40 @@ wydawca_listener ()
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 }

Return to:

Send suggestions and report system problems to the System administrator.