Compare commits

...

3 Commits

Author SHA1 Message Date
Jan Vidar Krey 91b3de5fad Fix crash if unable to load plugin. 2018-11-21 11:04:53 +01:00
Jan Vidar Krey 602f1b8843 Fix failing autotest. 2018-11-21 09:18:01 +01:00
Jan Vidar Krey e3852b7fad Add support for guest users to register themselves if the register_self config option has been enabled. 2018-11-21 01:05:18 +01:00
3 changed files with 36 additions and 1 deletions

View File

@ -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;
});

View File

@ -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." );

View File

@ -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();