Compare commits
3 Commits
master
...
acl/user_s
Author | SHA1 | Date |
---|---|---|
Jan Vidar Krey | 91b3de5fad | |
Jan Vidar Krey | 602f1b8843 | |
Jan Vidar Krey | e3852b7fad |
|
@ -17,6 +17,8 @@ static int result = 0;
|
|||
|
||||
EXO_TEST(setup, {
|
||||
hub = hub_malloc_zero(sizeof(struct hub_info));
|
||||
hub->config = hub_malloc_zero(sizeof(struct hub_config));
|
||||
config_defaults(hub->config);
|
||||
cbase = command_initialize(hub);
|
||||
hub->commands = cbase;
|
||||
hub->users = uman_init();
|
||||
|
@ -246,6 +248,8 @@ EXO_TEST(command_destroy, {
|
|||
EXO_TEST(cleanup, {
|
||||
uman_shutdown(hub->users);
|
||||
command_shutdown(hub->commands);
|
||||
free_config(hub->config);
|
||||
hub_free(hub->config);
|
||||
hub_free(hub);
|
||||
return 1;
|
||||
});
|
||||
|
|
|
@ -574,6 +574,33 @@ static int command_stats(struct command_base* cbase, struct hub_user* user, stru
|
|||
return command_status(cbase, user, cmd, buf);
|
||||
}
|
||||
|
||||
static int command_register_self(struct command_base* cbase, struct hub_user* user, struct hub_command* cmd)
|
||||
{
|
||||
if (user_is_registered(user))
|
||||
return command_status(cbase, user, cmd, cbuf_create_const("You are already registered!"));
|
||||
|
||||
struct hub_command_arg_data* arg = hub_command_arg_next(cmd, type_string);
|
||||
char* password = arg->data.string;
|
||||
|
||||
if (!*password || strlen(password) > MAX_PASS_LEN)
|
||||
return command_status(cbase, user, cmd, cbuf_create_const("Invalid password!"));
|
||||
|
||||
struct auth_info info;
|
||||
memset(&info, 0, sizeof(info));
|
||||
memcpy(&info.nickname, user->id.nick, MAX_NICK_LEN);
|
||||
memcpy(&info.password, password, MAX_PASS_LEN);
|
||||
info.credentials = auth_cred_user;
|
||||
|
||||
|
||||
if (acl_register_user(cbase->hub, &info))
|
||||
{
|
||||
return command_status(cbase, user, cmd, cbuf_create_const("You are now registered."));
|
||||
}
|
||||
|
||||
// NOTE: No good reason for this can be given here!
|
||||
return command_status(cbase, user, cmd, cbuf_create_const("Unable to register user."));
|
||||
}
|
||||
|
||||
static struct command_handle* add_builtin(struct command_base* cbase, const char* prefix, const char* args, enum auth_credentials cred, command_handler handler, const char* description)
|
||||
{
|
||||
struct command_handle* handle = (struct command_handle*) hub_malloc_zero(sizeof(struct command_handle));
|
||||
|
@ -601,6 +628,10 @@ void commands_builtin_add(struct command_base* cbase)
|
|||
ADD_COMMAND("myip", 4, "", auth_cred_guest, command_myip, "Show your own IP." );
|
||||
ADD_COMMAND("reload", 6, "", auth_cred_admin, command_reload, "Reload configuration files." );
|
||||
ADD_COMMAND("shutdown", 8, "", auth_cred_admin, command_shutdown_hub, "Shutdown hub." );
|
||||
|
||||
if (cbase->hub->config->register_self)
|
||||
ADD_COMMAND("register", 8, "p", auth_cred_guest, command_register_self, "Register yourself." );
|
||||
|
||||
ADD_COMMAND("stats", 5, "", auth_cred_super, command_stats, "Show hub statistics." );
|
||||
ADD_COMMAND("uptime", 6, "", auth_cred_guest, command_uptime, "Display hub uptime info." );
|
||||
ADD_COMMAND("version", 7, "", auth_cred_guest, command_version, "Show hub version info." );
|
||||
|
|
|
@ -102,7 +102,6 @@ struct plugin_handle* plugin_load(const char* filename, const char* config, stru
|
|||
int ret;
|
||||
struct plugin_handle* handle = (struct plugin_handle*) hub_malloc_zero(sizeof(struct plugin_handle));
|
||||
struct uhub_plugin* plugin = plugin_open(filename);
|
||||
struct plugin_hub_internals* internals = (struct plugin_hub_internals*) plugin->internals;
|
||||
|
||||
if (!plugin)
|
||||
return NULL;
|
||||
|
@ -118,6 +117,7 @@ struct plugin_handle* plugin_load(const char* filename, const char* config, stru
|
|||
unregister_f = plugin_lookup_symbol(plugin, "plugin_unregister");
|
||||
|
||||
// register hub internals
|
||||
struct plugin_hub_internals* internals = (struct plugin_hub_internals*) plugin->internals;
|
||||
internals->unregister = unregister_f;
|
||||
internals->hub = hub;
|
||||
internals->callback_data = plugin_callback_data_create();
|
||||
|
|
Loading…
Reference in New Issue