2009-02-19 16:14:09 +00:00
|
|
|
/*
|
|
|
|
* uhub - A tiny ADC p2p connection hub
|
2010-05-25 17:35:00 +00:00
|
|
|
* Copyright (C) 2007-2010, Jan Vidar Krey
|
2009-02-19 16:14:09 +00:00
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation; either version 3 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "uhub.h"
|
|
|
|
|
|
|
|
#define ACL_ADD_USER(S, L, V) do { ret = check_cmd_user(S, V, L, line, line_count); if (ret != 0) return ret; } while(0)
|
|
|
|
#define ACL_ADD_BOOL(S, L) do { ret = check_cmd_bool(S, L, line, line_count); if (ret != 0) return ret; } while(0)
|
|
|
|
#define ACL_ADD_ADDR(S, L) do { ret = check_cmd_addr(S, L, line, line_count); if (ret != 0) return ret; } while(0)
|
|
|
|
|
|
|
|
static int check_cmd_bool(const char* cmd, struct linked_list* list, char* line, int line_count)
|
|
|
|
{
|
|
|
|
char* data;
|
|
|
|
|
|
|
|
if (!strncmp(line, cmd, strlen(cmd)))
|
|
|
|
{
|
|
|
|
data = &line[strlen(cmd)];
|
|
|
|
data[0] = '\0';
|
|
|
|
data++;
|
|
|
|
|
|
|
|
data = strip_white_space(data);
|
2009-03-02 18:41:49 +00:00
|
|
|
if (!*data)
|
2009-02-19 16:14:09 +00:00
|
|
|
{
|
2009-07-25 23:38:38 +00:00
|
|
|
LOG_FATAL("ACL parse error on line %d", line_count);
|
2009-02-19 16:14:09 +00:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
list_append(list, hub_strdup(data));
|
2009-07-25 23:38:38 +00:00
|
|
|
LOG_DEBUG("ACL: Deny access for: '%s' (%s)", data, cmd);
|
2009-02-19 16:14:09 +00:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int check_cmd_user(const char* cmd, int status, struct linked_list* list, char* line, int line_count)
|
|
|
|
{
|
|
|
|
char* data;
|
|
|
|
char* data_extra;
|
2010-07-22 23:23:13 +00:00
|
|
|
struct auth_info* info = 0;
|
|
|
|
|
2009-02-19 16:14:09 +00:00
|
|
|
if (!strncmp(line, cmd, strlen(cmd)))
|
|
|
|
{
|
|
|
|
data = &line[strlen(cmd)];
|
|
|
|
data_extra = 0;
|
|
|
|
data[0] = '\0';
|
|
|
|
data++;
|
2010-07-22 23:23:13 +00:00
|
|
|
|
2009-02-19 16:14:09 +00:00
|
|
|
data = strip_white_space(data);
|
2009-03-02 18:41:49 +00:00
|
|
|
if (!*data)
|
2009-02-19 16:14:09 +00:00
|
|
|
{
|
2009-07-25 23:38:38 +00:00
|
|
|
LOG_FATAL("ACL parse error on line %d", line_count);
|
2009-02-19 16:14:09 +00:00
|
|
|
return -1;
|
|
|
|
}
|
2010-07-22 23:23:13 +00:00
|
|
|
|
|
|
|
info = hub_malloc_zero(sizeof(struct auth_info));
|
|
|
|
|
2009-02-19 16:14:09 +00:00
|
|
|
if (!info)
|
|
|
|
{
|
2009-07-25 23:38:38 +00:00
|
|
|
LOG_ERROR("ACL parse error. Out of memory!");
|
2009-02-19 16:14:09 +00:00
|
|
|
return -1;
|
|
|
|
}
|
2010-07-22 23:23:13 +00:00
|
|
|
|
2009-02-19 16:14:09 +00:00
|
|
|
if (strncmp(cmd, "user_", 5) == 0)
|
|
|
|
{
|
|
|
|
data_extra = strrchr(data, ':');
|
|
|
|
if (data_extra)
|
|
|
|
{
|
|
|
|
data_extra[0] = 0;
|
|
|
|
data_extra++;
|
|
|
|
}
|
|
|
|
}
|
2010-07-22 23:23:13 +00:00
|
|
|
|
|
|
|
strncpy(info->nickname, data, MAX_NICK_LEN);
|
|
|
|
strncpy(info->password, data_extra, MAX_PASS_LEN);
|
|
|
|
info->credentials = status;
|
2009-02-19 16:14:09 +00:00
|
|
|
list_append(list, info);
|
2010-07-22 23:23:13 +00:00
|
|
|
LOG_DEBUG("ACL: Added user '%s' (%s)", info->nickname, auth_cred_to_string(info->credentials));
|
2009-02-19 16:14:09 +00:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-07-26 01:12:35 +00:00
|
|
|
static void add_ip_range(struct linked_list* list, struct ip_range* info)
|
2009-02-19 16:14:09 +00:00
|
|
|
{
|
|
|
|
char buf1[INET6_ADDRSTRLEN+1];
|
|
|
|
char buf2[INET6_ADDRSTRLEN+1];
|
2010-02-07 22:29:38 +00:00
|
|
|
|
2009-02-19 16:14:09 +00:00
|
|
|
if (info->lo.af == AF_INET)
|
|
|
|
{
|
|
|
|
net_address_to_string(AF_INET, &info->lo.internal_ip_data.in.s_addr, buf1, INET6_ADDRSTRLEN);
|
|
|
|
net_address_to_string(AF_INET, &info->hi.internal_ip_data.in.s_addr, buf2, INET6_ADDRSTRLEN);
|
|
|
|
}
|
|
|
|
else if (info->lo.af == AF_INET6)
|
|
|
|
{
|
|
|
|
net_address_to_string(AF_INET6, &info->lo.internal_ip_data.in6, buf1, INET6_ADDRSTRLEN);
|
|
|
|
net_address_to_string(AF_INET6, &info->hi.internal_ip_data.in6, buf2, INET6_ADDRSTRLEN);
|
|
|
|
}
|
2010-02-07 22:29:38 +00:00
|
|
|
LOG_DEBUG("ACL: Added ip range: %s-%s", buf1, buf2);
|
|
|
|
|
2009-02-19 16:14:09 +00:00
|
|
|
list_append(list, info);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static int check_cmd_addr(const char* cmd, struct linked_list* list, char* line, int line_count)
|
|
|
|
{
|
2009-07-26 01:12:35 +00:00
|
|
|
char* data;
|
|
|
|
struct ip_range* range = 0;
|
|
|
|
|
2009-02-19 16:14:09 +00:00
|
|
|
if (!strncmp(line, cmd, strlen(cmd)))
|
|
|
|
{
|
2009-07-26 01:12:35 +00:00
|
|
|
data = &line[strlen(cmd)];
|
|
|
|
data[0] = '\0';
|
|
|
|
data++;
|
|
|
|
|
|
|
|
data = strip_white_space(data);
|
|
|
|
if (!*data)
|
2009-02-19 16:14:09 +00:00
|
|
|
{
|
2009-07-25 23:38:38 +00:00
|
|
|
LOG_FATAL("ACL parse error on line %d", line_count);
|
2009-02-19 16:14:09 +00:00
|
|
|
return -1;
|
|
|
|
}
|
2009-07-26 01:12:35 +00:00
|
|
|
|
|
|
|
range = hub_malloc_zero(sizeof(struct ip_range));
|
|
|
|
|
|
|
|
if (!range)
|
2009-02-19 16:14:09 +00:00
|
|
|
{
|
2009-07-25 23:38:38 +00:00
|
|
|
LOG_ERROR("ACL parse error. Out of memory!");
|
2009-02-19 16:14:09 +00:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2009-07-26 01:12:35 +00:00
|
|
|
if (ip_convert_address_to_range(data, range))
|
2009-02-19 16:14:09 +00:00
|
|
|
{
|
2009-07-26 01:12:35 +00:00
|
|
|
add_ip_range(list, range);
|
2009-02-19 16:14:09 +00:00
|
|
|
return 1;
|
|
|
|
}
|
2009-07-26 01:12:35 +00:00
|
|
|
hub_free(range);
|
2009-02-19 16:14:09 +00:00
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
static int acl_parse_line(char* line, int line_count, void* ptr_data)
|
|
|
|
{
|
|
|
|
struct acl_handle* handle = (struct acl_handle*) ptr_data;
|
|
|
|
int ret;
|
2009-08-31 17:39:09 +00:00
|
|
|
|
2010-05-25 17:35:00 +00:00
|
|
|
strip_off_ini_line_comments(line, line_count);
|
2009-02-19 16:14:09 +00:00
|
|
|
|
|
|
|
line = strip_white_space(line);
|
2009-03-02 18:41:49 +00:00
|
|
|
if (!*line)
|
2009-08-31 17:39:09 +00:00
|
|
|
return 0;
|
2009-02-19 16:14:09 +00:00
|
|
|
|
2009-07-25 23:38:38 +00:00
|
|
|
LOG_DEBUG("acl_parse_line: '%s'", line);
|
2009-08-31 17:39:09 +00:00
|
|
|
|
2010-07-12 15:00:42 +00:00
|
|
|
ACL_ADD_USER("bot", handle->users, auth_cred_bot);
|
|
|
|
ACL_ADD_USER("user_admin", handle->users, auth_cred_admin);
|
|
|
|
ACL_ADD_USER("user_super", handle->users, auth_cred_super);
|
|
|
|
ACL_ADD_USER("user_op", handle->users, auth_cred_operator);
|
|
|
|
ACL_ADD_USER("user_reg", handle->users, auth_cred_user);
|
|
|
|
ACL_ADD_USER("link", handle->users, auth_cred_link);
|
2009-02-19 16:14:09 +00:00
|
|
|
ACL_ADD_BOOL("deny_nick", handle->users_denied);
|
|
|
|
ACL_ADD_BOOL("ban_nick", handle->users_banned);
|
|
|
|
ACL_ADD_BOOL("ban_cid", handle->cids);
|
|
|
|
ACL_ADD_ADDR("deny_ip", handle->networks);
|
|
|
|
ACL_ADD_ADDR("nat_ip", handle->nat_override);
|
2009-08-31 17:39:09 +00:00
|
|
|
|
2009-07-25 23:38:38 +00:00
|
|
|
LOG_ERROR("Unknown ACL command on line %d: '%s'", line_count, line);
|
2009-02-19 16:14:09 +00:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
int acl_initialize(struct hub_config* config, struct acl_handle* handle)
|
|
|
|
{
|
|
|
|
int ret;
|
|
|
|
memset(handle, 0, sizeof(struct acl_handle));
|
|
|
|
|
|
|
|
handle->users = list_create();
|
|
|
|
handle->users_denied = list_create();
|
|
|
|
handle->users_banned = list_create();
|
|
|
|
handle->cids = list_create();
|
|
|
|
handle->networks = list_create();
|
|
|
|
handle->nat_override = list_create();
|
|
|
|
|
|
|
|
if (!handle->users || !handle->cids || !handle->networks || !handle->users_denied || !handle->users_banned || !handle->nat_override)
|
|
|
|
{
|
2009-07-25 23:38:38 +00:00
|
|
|
LOG_FATAL("acl_initialize: Out of memory");
|
2009-02-19 16:14:09 +00:00
|
|
|
|
|
|
|
list_destroy(handle->users);
|
|
|
|
list_destroy(handle->users_denied);
|
|
|
|
list_destroy(handle->users_banned);
|
|
|
|
list_destroy(handle->cids);
|
|
|
|
list_destroy(handle->networks);
|
|
|
|
list_destroy(handle->nat_override);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (config)
|
|
|
|
{
|
2009-03-02 18:41:49 +00:00
|
|
|
if (!*config->file_acl) return 0;
|
2009-02-19 16:14:09 +00:00
|
|
|
|
|
|
|
ret = file_read_lines(config->file_acl, handle, &acl_parse_line);
|
|
|
|
if (ret == -1)
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static void acl_free_access_info(void* ptr)
|
|
|
|
{
|
2010-07-22 23:23:13 +00:00
|
|
|
struct auth_info* info = (struct auth_info*) ptr;
|
2009-02-19 16:14:09 +00:00
|
|
|
if (info)
|
|
|
|
{
|
|
|
|
hub_free(info);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static void acl_free_ip_info(void* ptr)
|
|
|
|
{
|
|
|
|
struct access_info* info = (struct access_info*) ptr;
|
|
|
|
if (info)
|
|
|
|
{
|
|
|
|
hub_free(info);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
int acl_shutdown(struct acl_handle* handle)
|
|
|
|
{
|
|
|
|
if (handle->users)
|
|
|
|
{
|
|
|
|
list_clear(handle->users, &acl_free_access_info);
|
|
|
|
list_destroy(handle->users);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (handle->users_denied)
|
|
|
|
{
|
|
|
|
list_clear(handle->users_denied, &hub_free);
|
|
|
|
list_destroy(handle->users_denied);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (handle->users_banned)
|
|
|
|
{
|
|
|
|
list_clear(handle->users_banned, &hub_free);
|
|
|
|
list_destroy(handle->users_banned);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (handle->cids)
|
|
|
|
{
|
|
|
|
list_clear(handle->cids, &hub_free);
|
|
|
|
list_destroy(handle->cids);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (handle->networks)
|
|
|
|
{
|
|
|
|
list_clear(handle->networks, &acl_free_ip_info);
|
|
|
|
list_destroy(handle->networks);
|
|
|
|
}
|
2010-11-12 17:14:15 +00:00
|
|
|
|
2009-02-19 16:14:09 +00:00
|
|
|
if (handle->nat_override)
|
|
|
|
{
|
|
|
|
list_clear(handle->nat_override, &acl_free_ip_info);
|
|
|
|
list_destroy(handle->nat_override);
|
|
|
|
}
|
2010-11-12 17:14:15 +00:00
|
|
|
|
2009-02-19 16:14:09 +00:00
|
|
|
memset(handle, 0, sizeof(struct acl_handle));
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2010-11-12 17:14:15 +00:00
|
|
|
extern int acl_register_user(struct hub_info* hub, struct auth_info* info)
|
|
|
|
{
|
|
|
|
#ifdef PLUGIN_SUPPORT
|
|
|
|
if (plugin_auth_register_user(hub, info) != st_allow)
|
|
|
|
{
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
return 1;
|
|
|
|
#else
|
|
|
|
// NOT SUPPORTED!
|
|
|
|
return 0;
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
extern int acl_update_user(struct hub_info* hub, struct auth_info* info)
|
|
|
|
{
|
|
|
|
#ifdef PLUGIN_SUPPORT
|
|
|
|
if (plugin_auth_update_user(hub, info) != st_allow)
|
|
|
|
{
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
return 1;
|
|
|
|
#else
|
|
|
|
// NOT SUPPORTED!
|
|
|
|
return 0;
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
extern int acl_delete_user(struct hub_info* hub, const char* name)
|
|
|
|
{
|
|
|
|
#ifdef PLUGIN_SUPPORT
|
|
|
|
struct auth_info data;
|
|
|
|
strncpy(data.nickname, name, MAX_NICK_LEN);
|
|
|
|
data.nickname[MAX_NICK_LEN] = '\0';
|
|
|
|
data.password[0] = '\0';
|
|
|
|
data.credentials = auth_cred_none;
|
|
|
|
if (plugin_auth_delete_user(hub, &data) != st_allow)
|
|
|
|
{
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
return 1;
|
|
|
|
#else
|
|
|
|
// NOT SUPPORTED!
|
|
|
|
return 0;
|
|
|
|
#endif
|
|
|
|
}
|
2009-02-19 16:14:09 +00:00
|
|
|
|
2010-07-29 06:43:22 +00:00
|
|
|
struct auth_info* acl_get_access_info(struct hub_info* hub, const char* name)
|
2009-02-19 16:14:09 +00:00
|
|
|
{
|
2010-07-29 06:43:22 +00:00
|
|
|
struct auth_info* info = 0;
|
|
|
|
#ifdef PLUGIN_SUPPORT
|
|
|
|
info = (struct auth_info*) hub_malloc(sizeof(struct auth_info));
|
|
|
|
if (plugin_auth_get_user(hub, name, info) != st_allow)
|
|
|
|
{
|
|
|
|
hub_free(info);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
return info;
|
|
|
|
#else
|
|
|
|
info = (struct auth_info*) list_get_first(hub->acl->users);
|
2009-02-19 16:14:09 +00:00
|
|
|
while (info)
|
|
|
|
{
|
2010-07-22 23:23:13 +00:00
|
|
|
if (strcasecmp((char*)info->nickname, name) == 0)
|
2009-02-19 16:14:09 +00:00
|
|
|
{
|
|
|
|
return info;
|
|
|
|
}
|
2010-07-29 06:43:22 +00:00
|
|
|
info = (struct auth_info*) list_get_next(hub->acl->users);
|
2009-02-19 16:14:09 +00:00
|
|
|
}
|
|
|
|
return NULL;
|
2010-07-29 06:43:22 +00:00
|
|
|
#endif
|
2009-02-19 16:14:09 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#define STR_LIST_CONTAINS(LIST, STR) \
|
2010-01-28 00:06:41 +00:00
|
|
|
str = (char*) list_get_first(LIST); \
|
2009-02-19 16:14:09 +00:00
|
|
|
while (str) \
|
|
|
|
{ \
|
|
|
|
if (strcasecmp(str, STR) == 0) \
|
|
|
|
return 1; \
|
|
|
|
str = (char*) list_get_next(LIST); \
|
|
|
|
} \
|
|
|
|
return 0
|
|
|
|
|
|
|
|
int acl_is_cid_banned(struct acl_handle* handle, const char* data)
|
|
|
|
{
|
2010-01-28 00:06:41 +00:00
|
|
|
char* str;
|
2009-02-19 16:14:09 +00:00
|
|
|
if (!handle) return 0;
|
|
|
|
STR_LIST_CONTAINS(handle->cids, data);
|
|
|
|
}
|
|
|
|
|
|
|
|
int acl_is_user_banned(struct acl_handle* handle, const char* data)
|
|
|
|
{
|
2010-01-28 00:06:41 +00:00
|
|
|
char* str;
|
2009-02-19 16:14:09 +00:00
|
|
|
if (!handle) return 0;
|
|
|
|
STR_LIST_CONTAINS(handle->users_banned, data);
|
|
|
|
}
|
|
|
|
|
|
|
|
int acl_is_user_denied(struct acl_handle* handle, const char* data)
|
|
|
|
{
|
2010-01-28 00:06:41 +00:00
|
|
|
char* str;
|
2009-02-19 16:14:09 +00:00
|
|
|
if (!handle) return 0;
|
|
|
|
STR_LIST_CONTAINS(handle->users_denied, data);
|
|
|
|
}
|
|
|
|
|
2009-06-23 21:16:09 +00:00
|
|
|
int acl_user_ban_nick(struct acl_handle* handle, const char* nick)
|
|
|
|
{
|
2010-04-21 16:34:55 +00:00
|
|
|
char* data = hub_strdup(nick);
|
2009-11-18 16:41:28 +00:00
|
|
|
if (!data)
|
|
|
|
{
|
|
|
|
LOG_ERROR("ACL error: Out of memory!");
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
list_append(handle->users_banned, data);
|
2009-06-23 21:16:09 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
int acl_user_ban_cid(struct acl_handle* handle, const char* cid)
|
|
|
|
{
|
2010-04-21 16:34:55 +00:00
|
|
|
char* data = hub_strdup(cid);
|
2009-11-18 16:41:28 +00:00
|
|
|
if (!data)
|
|
|
|
{
|
|
|
|
LOG_ERROR("ACL error: Out of memory!");
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
list_append(handle->cids, data);
|
2009-06-23 21:16:09 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
int acl_user_unban_nick(struct acl_handle* handle, const char* nick)
|
|
|
|
{
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
int acl_user_unban_cid(struct acl_handle* handle, const char* cid)
|
|
|
|
{
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-02-19 16:14:09 +00:00
|
|
|
int acl_is_ip_banned(struct acl_handle* handle, const char* ip_address)
|
|
|
|
{
|
|
|
|
struct ip_addr_encap raw;
|
2009-07-26 01:12:35 +00:00
|
|
|
struct ip_range* info = (struct ip_range*) list_get_first(handle->networks);
|
2009-02-19 16:14:09 +00:00
|
|
|
ip_convert_to_binary(ip_address, &raw);
|
|
|
|
|
|
|
|
while (info)
|
|
|
|
{
|
2009-07-26 01:12:35 +00:00
|
|
|
if (ip_in_range(&raw, info))
|
2009-02-19 16:14:09 +00:00
|
|
|
{
|
|
|
|
return 1;
|
|
|
|
}
|
2009-07-26 01:12:35 +00:00
|
|
|
info = (struct ip_range*) list_get_next(handle->networks);
|
2009-02-19 16:14:09 +00:00
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
int acl_is_ip_nat_override(struct acl_handle* handle, const char* ip_address)
|
|
|
|
{
|
|
|
|
struct ip_addr_encap raw;
|
2009-07-26 01:12:35 +00:00
|
|
|
struct ip_range* info = (struct ip_range*) list_get_first(handle->nat_override);
|
2009-02-19 16:14:09 +00:00
|
|
|
ip_convert_to_binary(ip_address, &raw);
|
|
|
|
|
|
|
|
while (info)
|
|
|
|
{
|
2009-07-26 01:12:35 +00:00
|
|
|
if (ip_in_range(&raw, info))
|
2009-02-19 16:14:09 +00:00
|
|
|
{
|
|
|
|
return 1;
|
|
|
|
}
|
2009-07-26 01:12:35 +00:00
|
|
|
info = (struct ip_range*) list_get_next(handle->nat_override);
|
2009-02-19 16:14:09 +00:00
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* This will generate the same challenge to the same user, always.
|
|
|
|
* The challenge is made up of the time of the user connected
|
|
|
|
* seconds since the unix epoch (modulus 1 million)
|
|
|
|
* and the SID of the user (0-1 million).
|
|
|
|
*/
|
2010-07-29 06:43:22 +00:00
|
|
|
const char* acl_password_generate_challenge(struct hub_info* hub, struct hub_user* user)
|
2009-02-19 16:14:09 +00:00
|
|
|
{
|
2009-11-18 16:41:28 +00:00
|
|
|
char buf[64];
|
2009-02-19 16:14:09 +00:00
|
|
|
uint64_t tiger_res[3];
|
|
|
|
static char tiger_buf[MAX_CID_LEN+1];
|
2009-10-07 15:37:31 +00:00
|
|
|
|
|
|
|
// FIXME: Generate a better nonce scheme.
|
2009-12-10 22:12:04 +00:00
|
|
|
snprintf(buf, 64, "%p%d%d", user, (int) user->id.sid, (int) net_con_get_sd(user->connection));
|
2009-10-07 15:37:31 +00:00
|
|
|
|
2009-02-19 16:14:09 +00:00
|
|
|
tiger((uint64_t*) buf, strlen(buf), (uint64_t*) tiger_res);
|
|
|
|
base32_encode((unsigned char*) tiger_res, TIGERSIZE, tiger_buf);
|
|
|
|
tiger_buf[MAX_CID_LEN] = 0;
|
|
|
|
return (const char*) tiger_buf;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-07-29 06:43:22 +00:00
|
|
|
int acl_password_verify(struct hub_info* hub, struct hub_user* user, const char* password)
|
2009-02-19 16:14:09 +00:00
|
|
|
{
|
|
|
|
char buf[1024];
|
2010-07-22 23:23:13 +00:00
|
|
|
struct auth_info* access;
|
2009-02-19 16:14:09 +00:00
|
|
|
const char* challenge;
|
|
|
|
char raw_challenge[64];
|
|
|
|
char password_calc[64];
|
|
|
|
uint64_t tiger_res[3];
|
2010-07-22 23:23:13 +00:00
|
|
|
size_t password_len;
|
|
|
|
|
2009-02-19 16:14:09 +00:00
|
|
|
if (!password || !user || strlen(password) != MAX_CID_LEN)
|
2009-07-02 23:29:04 +00:00
|
|
|
return 0;
|
2009-02-19 16:14:09 +00:00
|
|
|
|
2010-07-29 06:43:22 +00:00
|
|
|
access = acl_get_access_info(hub, user->id.nick);
|
|
|
|
if (!access)
|
2009-07-02 23:29:04 +00:00
|
|
|
return 0;
|
2009-02-19 16:14:09 +00:00
|
|
|
|
2010-07-29 06:43:22 +00:00
|
|
|
challenge = acl_password_generate_challenge(hub, user);
|
2009-02-19 16:14:09 +00:00
|
|
|
|
|
|
|
base32_decode(challenge, (unsigned char*) raw_challenge, MAX_CID_LEN);
|
|
|
|
|
2010-07-22 23:23:13 +00:00
|
|
|
password_len = strlen(access->password);
|
2009-02-19 16:14:09 +00:00
|
|
|
|
2010-07-22 23:23:13 +00:00
|
|
|
memcpy(&buf[0], access->password, password_len);
|
|
|
|
memcpy(&buf[password_len], raw_challenge, TIGERSIZE);
|
|
|
|
|
|
|
|
tiger((uint64_t*) buf, TIGERSIZE+password_len, (uint64_t*) tiger_res);
|
2009-02-19 16:14:09 +00:00
|
|
|
base32_encode((unsigned char*) tiger_res, TIGERSIZE, password_calc);
|
|
|
|
password_calc[MAX_CID_LEN] = 0;
|
|
|
|
|
2010-07-22 23:23:13 +00:00
|
|
|
#ifdef PLUGIN_SUPPORT
|
|
|
|
hub_free(access);
|
|
|
|
#endif
|
|
|
|
|
2009-02-19 16:14:09 +00:00
|
|
|
if (strcasecmp(password, password_calc) == 0)
|
|
|
|
{
|
2009-07-02 23:29:04 +00:00
|
|
|
return 1;
|
2009-02-19 16:14:09 +00:00
|
|
|
}
|
2009-07-02 23:29:04 +00:00
|
|
|
return 0;
|
2009-02-19 16:14:09 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|