From a37a83f6143e672a71ee4436fa24aaa2f9c81877 Mon Sep 17 00:00:00 2001 From: Sergey Poznyakoff Date: Wed, 23 Dec 2009 23:51:39 +0200 Subject: Limit number of connections per socket (IP). * src/inetd-bi.c (fd_write): Remove. Use fd_report instead. * src/pies.c (component_keywords): New keywords: max-instances-message, max-ip-connections, max-ip-connections-message, access-denied-message. * src/pies.h (struct component): New members: max_ip_connections, access_denied_message, max_instances_message, max_ip_connections_message. (fd_report): New extern. * src/progman.c (conn_class): New struct. (struct prog.p): New member cclass. (conn_tab): New static. (conn_class_lookup, conn_class_report): New functions. (progman_run_comp): Set cclass. (fd_report): New function. (_prog_accept): In case of failure (access denied, etc.) optionally send response strings over the fd. Limit number of connections per socket (IP). (progman_cleanup): Update cclass counter. --- src/inetd-bi.c | 21 ++++++++------------- 1 file changed, 8 insertions(+), 13 deletions(-) (limited to 'src/inetd-bi.c') diff --git a/src/inetd-bi.c b/src/inetd-bi.c index d002e4c..b771936 100644 --- a/src/inetd-bi.c +++ b/src/inetd-bi.c @@ -295,12 +295,6 @@ fd_getline (int fd, char *buf, int len) return count; } -static int -fd_write (int fd, const char *text) -{ - return write (fd, text, strlen (text)); -} - static int tcpmux_help (struct component *comp, void *data) { @@ -308,8 +302,8 @@ tcpmux_help (struct component *comp, void *data) if (!(comp->flags & CF_DISABLED) && ISCF_TCPMUX (comp->flags)) { - fd_write (*pfd, comp->service); - fd_write (*pfd, "\r\n"); + fd_report (*pfd, comp->service); + fd_report (*pfd, "\r\n"); } return 0; } @@ -327,7 +321,7 @@ tcpmux (int fd, struct component const *comp) /* Read service name */ if ((len = fd_getline (fd, service, MAX_SERV_LEN)) < 0) { - fd_write (fd, "-Error reading service name\r\n"); + fd_report (fd, "-Error reading service name\r\n"); return; } service[len] = 0; @@ -343,7 +337,7 @@ tcpmux (int fd, struct component const *comp) srv_comp = progman_lookup_tcpmux (service, comp->tag); if (!srv_comp) { - fd_write (fd, "-Service not available\r\n"); + fd_report (fd, "-Service not available\r\n"); return; } @@ -356,19 +350,20 @@ tcpmux (int fd, struct component const *comp) { if (rc) { - fd_write (fd, "-Service not available\r\n"); + fd_report (fd, "-Service not available\r\n"); return; } if (check_acl (comp->acl, (struct sockaddr *) &sa, salen)) { - fd_write (fd, "-Service not available\r\n"); + fd_report (fd, "-Service not available\r\n"); return; } } + /* FIXME: What about max-instances, etc.? */ if (srv_comp->flags & CF_TCPMUXPLUS) - fd_write (fd, "+Go\r\n"); + fd_report (fd, "+Go\r\n"); progman_run_comp (srv_comp, fd, &sa, salen); } -- cgit v1.2.1