return 1;
}
-static void del_perm_list_entry(struct sender_command_data *scd)
+static void del_acl_entry(struct list_head *acl, struct in_addr addr,
+ int netmask)
{
struct access_info *ai, *tmp;
- list_for_each_entry_safe(ai, tmp, &http_acl, node) {
+ list_for_each_entry_safe(ai, tmp, acl, node) {
char *nad = para_strdup(inet_ntoa(ai->addr));
- if (!strcmp(nad, inet_ntoa(scd->addr)) &&
- ai->netmask == scd->netmask) {
+ if (!strcmp(nad, inet_ntoa(addr)) &&
+ ai->netmask == netmask) {
PARA_NOTICE_LOG("removing %s/%i from access list\n",
nad, ai->netmask);
list_del(&ai->node);
}
}
-static void add_perm_list_entry(struct sender_command_data *scd)
+static void add_acl_entry(struct list_head *acl, struct in_addr addr,
+ int netmask)
{
struct access_info *ai = para_malloc(sizeof(struct access_info));
- ai->addr = scd->addr;
- ai->netmask = scd->netmask;
+ ai->addr = addr;
+ ai->netmask = netmask;
PARA_INFO_LOG("adding %s/%i to access list\n", inet_ntoa(ai->addr),
ai->netmask);
- para_list_add(&ai->node, &http_acl);
+ para_list_add(&ai->node, acl);
}
static int http_com_deny(struct sender_command_data *scd)
{
if (conf.http_default_deny_given)
- del_perm_list_entry(scd);
+ del_acl_entry(&http_acl, scd->addr, scd->netmask);
else
- add_perm_list_entry(scd);
+ add_acl_entry(&http_acl, scd->addr, scd->netmask);
return 1;
}
static int http_com_allow(struct sender_command_data *scd)
{
if (conf.http_default_deny_given)
- add_perm_list_entry(scd);
+ add_acl_entry(&http_acl, scd->addr, scd->netmask);
else
- del_perm_list_entry(scd);
+ del_acl_entry(&http_acl, scd->addr, scd->netmask);
return 1;
}
static void init_acl(struct list_head *acl, char * const *acl_info, int num)
{
int i;
- struct sender_command_data scd;
INIT_LIST_HEAD(acl);
for (i = 0; i < num; i++) {
char *arg = para_strdup(acl_info[i]);
char *p = strchr(arg, '/');
+ struct in_addr addr;
+ int netmask;
+
if (!p)
goto err;
*p = '\0';
- if (!inet_pton(AF_INET, arg, &scd.addr))
+ if (!inet_pton(AF_INET, arg, &addr))
goto err;
- scd.netmask = atoi(++p);
- if (scd.netmask < 0 || scd.netmask > 32)
+ netmask = atoi(++p);
+ if (netmask < 0 || netmask > 32)
goto err;
- add_perm_list_entry(&scd);
+ add_acl_entry(acl, addr, netmask);
goto success;
err:
- PARA_CRIT_LOG("syntax error for http_access option "
- "#%d, ignoring\n", i);
+ PARA_CRIT_LOG("syntax error: %s\n", acl_info[i]);
success:
free(arg);
continue;