Cleaned up the credentials handling, and made it ready for plugins.

This commit is contained in:
Jan Vidar Krey
2010-07-12 17:00:42 +02:00
parent e4977606a7
commit 56e5557146
16 changed files with 190 additions and 117 deletions

View File

@@ -23,23 +23,6 @@
#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)
const char* get_user_credential_string(enum user_credentials cred)
{
switch (cred)
{
case cred_none: return "none";
case cred_bot: return "bot";
case cred_guest: return "guest";
case cred_user: return "user";
case cred_operator: return "operator";
case cred_super: return "super";
case cred_admin: return "admin";
case cred_link: return "link";
}
return "";
};
static int check_cmd_bool(const char* cmd, struct linked_list* list, char* line, int line_count)
{
char* data;
@@ -108,7 +91,7 @@ static int check_cmd_user(const char* cmd, int status, struct linked_list* list,
info->password = data_extra ? hub_strdup(data_extra) : 0;
info->status = status;
list_append(list, info);
LOG_DEBUG("ACL: Added user '%s' (%s)", info->username, get_user_credential_string(info->status));
LOG_DEBUG("ACL: Added user '%s' (%s)", info->username, auth_cred_to_string(info->status));
return 1;
}
return 0;
@@ -187,12 +170,12 @@ static int acl_parse_line(char* line, int line_count, void* ptr_data)
LOG_DEBUG("acl_parse_line: '%s'", line);
ACL_ADD_USER("bot", handle->users, cred_bot);
ACL_ADD_USER("user_admin", handle->users, cred_admin);
ACL_ADD_USER("user_super", handle->users, cred_super);
ACL_ADD_USER("user_op", handle->users, cred_operator);
ACL_ADD_USER("user_reg", handle->users, cred_user);
ACL_ADD_USER("link", handle->users, cred_link);
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);
ACL_ADD_BOOL("deny_nick", handle->users_denied);
ACL_ADD_BOOL("ban_nick", handle->users_banned);
ACL_ADD_BOOL("ban_cid", handle->cids);

View File

@@ -24,25 +24,11 @@ struct hub_config;
struct hub_user;
struct ip_addr_encap;
enum user_credentials
{
cred_none, /**<<< "User has no credentials (not yet logged in)" */
cred_bot, /**<<< "User is a robot" */
cred_guest, /**<<< "User is a guest (unregistered user)" */
cred_user, /**<<< "User is identified as a registered user" */
cred_operator, /**<<< "User is identified as a hub operator" */
cred_super, /**<<< "User is a super user" (not used) */
cred_admin, /**<<< "User is identified as a hub administrator/owner" */
cred_link, /**<<< "User is a link (not used currently)" */
};
const char* get_user_credential_string(enum user_credentials cred);
struct hub_user_access_info
{
char* username; /* name of user, cid or IP range */
char* password; /* password */
enum user_credentials status;
enum auth_credentials status;
};
struct acl_handle

View File

@@ -40,7 +40,7 @@ struct commands_handler
const char* prefix;
size_t length;
const char* args;
enum user_credentials cred;
enum auth_credentials cred;
command_handler handler;
const char* description;
};
@@ -637,28 +637,28 @@ int command_dipatcher(struct hub_info* hub, struct hub_user* user, const char* m
}
static struct commands_handler command_handlers[] = {
{ "ban", 3, "n", cred_operator, command_ban, "Ban a user" },
{ "broadcast", 9, "m", cred_operator, command_broadcast,"Send a message to all users" },
{ "ban", 3, "n", auth_cred_operator, command_ban, "Ban a user" },
{ "broadcast", 9, "m", auth_cred_operator, command_broadcast,"Send a message to all users" },
#ifdef CRASH_DEBUG
{ "crash", 5, 0, cred_admin, command_crash, "Crash the hub (DEBUG)." },
{ "crash", 5, 0, auth_cred_admin, command_crash, "Crash the hub (DEBUG)." },
#endif
{ "getip", 5, "n", cred_operator, command_getip, "Show IP address for a user" },
{ "help", 4, 0, cred_guest, command_help, "Show this help message." },
{ "history", 7, 0, cred_guest, command_history, "Show the last chat messages." },
{ "kick", 4, "n", cred_operator, command_kick, "Kick a user" },
{ "log", 3, 0, cred_operator, command_log, "Display log" },
{ "motd", 4, 0, cred_guest, command_motd, "Show the message of the day" },
{ "mute", 4, "n", cred_operator, command_mute, "Mute user" },
{ "myip", 4, 0, cred_guest, command_myip, "Show your own IP." },
{ "reload", 6, 0, cred_admin, command_reload, "Reload configuration files." },
{ "rules", 5, 0, cred_guest, command_rules, "Show the hub rules" },
{ "shutdown", 8, 0, cred_admin, command_shutdown, "Shutdown hub." },
{ "stats", 5, 0, cred_super, command_stats, "Show hub statistics." },
{ "unban", 5, "n", cred_operator, command_unban, "Lift ban on a user" },
{ "unmute", 6, "n", cred_operator, command_mute, "Unmute user" },
{ "uptime", 6, 0, cred_guest, command_uptime, "Display hub uptime info." },
{ "version", 7, 0, cred_guest, command_version, "Show hub version info." },
{ "whoip", 5, "a", cred_operator, command_whoip, "Show users matching IP range" },
{ 0, 0, 0, cred_none, command_help, "" }
{ "getip", 5, "n", auth_cred_operator, command_getip, "Show IP address for a user" },
{ "help", 4, 0, auth_cred_guest, command_help, "Show this help message." },
{ "history", 7, 0, auth_cred_guest, command_history, "Show the last chat messages." },
{ "kick", 4, "n", auth_cred_operator, command_kick, "Kick a user" },
{ "log", 3, 0, auth_cred_operator, command_log, "Display log" },
{ "motd", 4, 0, auth_cred_guest, command_motd, "Show the message of the day" },
{ "mute", 4, "n", auth_cred_operator, command_mute, "Mute user" },
{ "myip", 4, 0, auth_cred_guest, command_myip, "Show your own IP." },
{ "reload", 6, 0, auth_cred_admin, command_reload, "Reload configuration files." },
{ "rules", 5, 0, auth_cred_guest, command_rules, "Show the hub rules" },
{ "shutdown", 8, 0, auth_cred_admin, command_shutdown, "Shutdown hub." },
{ "stats", 5, 0, auth_cred_super, command_stats, "Show hub statistics." },
{ "unban", 5, "n", auth_cred_operator, command_unban, "Lift ban on a user" },
{ "unmute", 6, "n", auth_cred_operator, command_mute, "Unmute user" },
{ "uptime", 6, 0, auth_cred_guest, command_uptime, "Display hub uptime info." },
{ "version", 7, 0, auth_cred_guest, command_version, "Show hub version info." },
{ "whoip", 5, "a", auth_cred_operator, command_whoip, "Show users matching IP range" },
{ 0, 0, 0, auth_cred_none, command_help, "" }
};

View File

@@ -22,7 +22,7 @@
struct hub_info* g_hub = 0;
#define CHECK_CHAT_ONLY \
if (hub->config->chat_only && u->credentials < cred_operator) \
if (hub->config->chat_only && u->credentials < auth_cred_operator) \
break
#define CHECK_FLOOD(TYPE, WARN) \

View File

@@ -22,7 +22,7 @@
static void log_user_login(struct hub_user* u)
{
const char* cred = get_user_credential_string(u->credentials);
const char* cred = auth_cred_to_string(u->credentials);
const char* addr = user_get_address(u);
LOG_USER("LoginOK %s/%s %s \"%s\" (%s) \"%s\"", sid_to_string(u->id.sid), u->id.cid, addr, u->id.nick, cred, u->user_agent);
}

View File

@@ -544,39 +544,39 @@ static int set_credentials(struct hub_info* hub, struct hub_user* user, struct a
}
else
{
user->credentials = cred_guest;
user->credentials = auth_cred_guest;
}
switch (user->credentials)
{
case cred_none:
case auth_cred_none:
break;
case cred_bot:
case auth_cred_bot:
adc_msg_add_argument(cmd, ADC_INF_FLAG_CLIENT_TYPE ADC_CLIENT_TYPE_BOT);
break;
case cred_guest:
case auth_cred_guest:
/* Nothing to be added to the info message */
break;
case cred_user:
case auth_cred_user:
adc_msg_add_argument(cmd, ADC_INF_FLAG_CLIENT_TYPE ADC_CLIENT_TYPE_REGISTERED_USER);
break;
case cred_operator:
case auth_cred_operator:
adc_msg_add_argument(cmd, ADC_INF_FLAG_CLIENT_TYPE ADC_CLIENT_TYPE_OPERATOR);
break;
case cred_super:
case auth_cred_super:
adc_msg_add_argument(cmd, ADC_INF_FLAG_CLIENT_TYPE ADC_CLIENT_TYPE_SUPER_USER);
break;
case cred_admin:
case auth_cred_admin:
adc_msg_add_argument(cmd, ADC_INF_FLAG_CLIENT_TYPE ADC_CLIENT_TYPE_ADMIN);
break;
case cred_link:
case auth_cred_link:
break;
}

View File

@@ -69,6 +69,7 @@ void plugin_log_connection_denied(struct hub_info* hub, struct ip_addr_encap* ip
void plugin_log_user_login_success(struct hub_info* hub, struct hub_user* user)
{
}
void plugin_log_user_login_error(struct hub_info* hub, struct hub_user* user)
@@ -80,10 +81,11 @@ void plugin_log_user_logout(struct hub_info* hub, struct hub_user* user)
}
void convert_user_to_plugin_user(struct plugin_user* puser, struct hub_user* user)
static void convert_user_to_plugin_user(struct plugin_user* puser, struct hub_user* user)
{
puser->sid = user->id.sid;
puser->nick = user->id.nick;
puser->cid = user->id.cid;
puser->addr = user->id.addr;
puser->credentials = user->credentials;
}

View File

@@ -288,18 +288,7 @@ int user_is_disconnecting(struct hub_user* user)
int user_is_protected(struct hub_user* user)
{
switch (user->credentials)
{
case cred_bot:
case cred_operator:
case cred_super:
case cred_admin:
case cred_link:
return 1;
default:
break;
}
return 0;
return auth_cred_is_protected(user->credentials);
}
/**
@@ -309,19 +298,7 @@ int user_is_protected(struct hub_user* user)
*/
int user_is_registered(struct hub_user* user)
{
switch (user->credentials)
{
case cred_bot:
case cred_user:
case cred_operator:
case cred_super:
case cred_admin:
case cred_link:
return 1;
default:
break;
}
return 0;
return auth_cred_is_registered(user->credentials);
}
void user_net_io_want_write(struct hub_user* user)

View File

@@ -106,7 +106,7 @@ struct hub_user_limits
struct hub_user
{
enum user_state state; /** see enum user_state */
enum user_credentials credentials; /** see enum user_credentials */
enum auth_credentials credentials; /** see enum user_credentials */
struct hub_user_info id; /** Contains nick name and CID */
uint32_t flags; /** see enum user_features */
char user_agent[MAX_UA_LEN+1];/** User agent string */

View File

@@ -33,7 +33,7 @@ static void clear_user_list_callback(void* ptr)
* This prevents the hub from trying to send
* quit messages to other users.
*/
u->credentials = cred_none;
u->credentials = auth_cred_none;
user_destroy(u);
}
}