]> jfr.im git - irc/rqf/shadowircd.git/commitdiff
Porting accept callback functions
authorValery Yatsko <redacted>
Wed, 2 Apr 2008 16:39:36 +0000 (20:39 +0400)
committerValery Yatsko <redacted>
Wed, 2 Apr 2008 16:39:36 +0000 (20:39 +0400)
src/listener.c

index d3ceb2ae28d42424487361619a5197fd39ae532f..02e589bc84dabd10d016f327e99fb012b9c648ab 100644 (file)
@@ -164,6 +164,7 @@ static int
 inetport(listener_t *listener)
 {
        rb_fde_t *F;
+       int ret;
        int opt = 1;
 
        /*
@@ -477,3 +478,79 @@ add_connection(listener_t *listener, int fd, struct sockaddr *sai, int exempt)
 
        start_auth(new_client);
 }
+
+static int\r
+accept_precallback(rb_fde_t *F, struct sockaddr *addr, rb_socklen_t addrlen, void *data)\r
+{\r
+       struct Listener *listener = (struct Listener *)data;\r
+       char buf[BUFSIZE];\r
+       struct ConfItem *aconf;\r
+\r
+       if((maxconnections - 10) < rb_get_fd(F)) /* XXX this is kinda bogus */\r
+       {\r
+               ++ServerStats->is_ref;\r
+               /*\r
+                * slow down the whining to opers bit\r
+                */\r
+               if((last_oper_notice + 20) <= rb_current_time())\r
+               {\r
+                       sendto_realops_flags(SNO_GENERAL, L_ALL,\r
+                                            "All connections in use. (%s)",\r
+                                            get_listener_name(listener));\r
+                       last_oper_notice = rb_current_time();\r
+               }\r
+                       \r
+               rb_write(F, "ERROR :All connections in use\r\n", 32);\r
+               rb_close(F);\r
+               /* Re-register a new IO request for the next accept .. */\r
+               return 0;\r
+       }\r
+\r
+       aconf = find_dline(addr);\r
+       if(aconf != NULL && (aconf->status & CONF_EXEMPTDLINE))\r
+               return 1;\r
+       \r
+       /* Do an initial check we aren't connecting too fast or with too many\r
+        * from this IP... */\r
+       if(aconf != NULL)\r
+       {\r
+               ServerStats->is_ref++;\r
+                       \r
+               if(ConfigFileEntry.dline_with_reason)\r
+               {\r
+                       if (rb_snprintf(buf, sizeof(buf), "ERROR :*** Banned: %s\r\n", aconf->passwd) >= (int)(sizeof(buf)-1))\r
+                       {\r
+                               buf[sizeof(buf) - 3] = '\r';\r
+                               buf[sizeof(buf) - 2] = '\n';\r
+                               buf[sizeof(buf) - 1] = '\0';\r
+                       }\r
+               }\r
+               else\r
+                       strcpy(buf, "ERROR :You have been D-lined.\r\n");\r
+       \r
+               rb_write(F, buf, strlen(buf));\r
+               rb_close(F);\r
+               return 0;\r
+       }\r
+\r
+       return 1;\r
+}\r
+\r
+static void\r
+accept_callback(rb_fde_t *F, int status, struct sockaddr *addr, rb_socklen_t addrlen, void *data)\r
+{\r
+       struct Listener *listener = data;\r
+       struct rb_sockaddr_storage lip;\r
+       unsigned int locallen = sizeof(struct rb_sockaddr_storage);\r
+       \r
+       ServerStats->is_ac++;\r
+\r
+       if(getsockname(rb_get_fd(F), (struct sockaddr *) &lip, &locallen) < 0)\r
+       {\r
+               /* this shouldn't fail so... */\r
+               /* XXX add logging of this */\r
+               rb_close(F);\r
+       }\r
+       \r
+       add_connection(listener, F, addr, (struct sockaddr *)&lip, NULL);\r
+}