user_list.c: Simplify populate_user_list().
[paraslash.git] / dccp_send.c
index 7b7c805..d0f9448 100644 (file)
 #include "close_on_fork.h"
 #include "chunk_queue.h"
 #include "server.cmdline.h"
+#include "acl.h"
 
 /** the list of connected clients **/
 static struct list_head clients;
+/** The whitelist/blacklist. */
+static struct list_head dccp_acl;
 static int listen_fd = -1;
 
 /** Maximal number of bytes in a chunk queue. */
@@ -69,6 +72,9 @@ static void dccp_post_select(fd_set *rfds, __a_unused fd_set *wfds)
                goto err;
        }
        ret = mark_fd_nonblocking(fd);
+       if (ret < 0)
+               goto err;
+       ret = acl_check_access(fd, &dccp_acl, conf.dccp_default_deny_given);
        if (ret < 0)
                goto err;
        sc = para_calloc(sizeof(*sc));
@@ -102,6 +108,20 @@ static void dccp_shutdown_clients(void)
                shutdown_client(sc);
 }
 
+static int dccp_com_deny(struct sender_command_data *scd)
+{
+       acl_deny(scd->addr, scd->netmask, &dccp_acl,
+               conf.dccp_default_deny_given);
+       return 1;
+}
+
+static int dccp_com_allow(struct sender_command_data *scd)
+{
+       acl_allow(scd->addr, scd->netmask, &dccp_acl,
+               conf.dccp_default_deny_given);
+       return 1;
+}
+
 static char *dccp_info(void)
 {
        int num_clients = 0;
@@ -138,10 +158,11 @@ void dccp_send_init(struct sender *s)
        s->help = dccp_help;
        s->client_cmds[SENDER_ON] = NULL;
        s->client_cmds[SENDER_OFF] = NULL;
-       s->client_cmds[SENDER_DENY] = NULL;
-       s->client_cmds[SENDER_ALLOW] = NULL;
+       s->client_cmds[SENDER_DENY] = dccp_com_deny;
+       s->client_cmds[SENDER_ALLOW] = dccp_com_allow;
        s->client_cmds[SENDER_ADD] = NULL;
        s->client_cmds[SENDER_DELETE] = NULL;
+       acl_init(&dccp_acl, conf.dccp_access_arg, conf.dccp_access_given);
        ret = open_sender(IPPROTO_DCCP, conf.dccp_port_arg);
        if (ret < 0)
                PARA_ERROR_LOG("%s\n", para_strerror(-ret));