user_list.c: Simplify populate_user_list().
[paraslash.git] / dccp_send.c
index c94e1624493e511b59c41c61c17205426b869754..d0f9448e8e048445ce0e0c6a6adf8d0d903449cc 100644 (file)
 #include "close_on_fork.h"
 #include "chunk_queue.h"
 #include "server.cmdline.h"
 #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 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. */
 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);
                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));
        if (ret < 0)
                goto err;
        sc = para_calloc(sizeof(*sc));
@@ -102,16 +108,28 @@ static void dccp_shutdown_clients(void)
                shutdown_client(sc);
 }
 
                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)
 {
 static char *dccp_info(void)
 {
-       char *buf;
        int num_clients = 0;
        struct sender_client *sc, *tmp;
 
        list_for_each_entry_safe(sc, tmp, &clients, node)
                num_clients++;
        int num_clients = 0;
        struct sender_client *sc, *tmp;
 
        list_for_each_entry_safe(sc, tmp, &clients, node)
                num_clients++;
-       buf = make_message("dccp connected clients: %d\n", num_clients);
-       return buf;
+       return make_message("dccp connected clients: %d\n", num_clients);
 }
 
 static char *dccp_help(void)
 }
 
 static char *dccp_help(void)
@@ -140,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->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;
        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));
        ret = open_sender(IPPROTO_DCCP, conf.dccp_port_arg);
        if (ret < 0)
                PARA_ERROR_LOG("%s\n", para_strerror(-ret));