Compare commits
3 Commits
plugin_rew
...
acl/user_s
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
91b3de5fad | ||
|
|
602f1b8843 | ||
|
|
e3852b7fad |
@@ -1,6 +1,6 @@
|
||||
##
|
||||
## Makefile for uhub
|
||||
## Copyright (C) 2007-2019, Jan Vidar Krey <janvidar@extatic.org>
|
||||
## Copyright (C) 2007-2013, Jan Vidar Krey <janvidar@extatic.org>
|
||||
#
|
||||
|
||||
cmake_minimum_required (VERSION 2.8.2)
|
||||
@@ -120,7 +120,6 @@ add_library(mod_chat_only MODULE ${PROJECT_SOURCE_DIR}/plugins/mod_chat_only.c)
|
||||
add_library(mod_topic MODULE ${PROJECT_SOURCE_DIR}/plugins/mod_topic.c)
|
||||
add_library(mod_no_guest_downloads MODULE ${PROJECT_SOURCE_DIR}/plugins/mod_no_guest_downloads.c)
|
||||
add_library(mod_auth_sqlite MODULE ${PROJECT_SOURCE_DIR}/plugins/mod_auth_sqlite.c)
|
||||
add_library(mod_require_tls MODULE ${PROJECT_SOURCE_DIR}/plugins/mod_require_tls.c)
|
||||
|
||||
if(WIN32)
|
||||
target_link_libraries(uhub ws2_32)
|
||||
@@ -140,7 +139,6 @@ set_target_properties(
|
||||
mod_chat_only
|
||||
mod_no_guest_downloads
|
||||
mod_topic
|
||||
mod_require_tls
|
||||
PROPERTIES PREFIX "")
|
||||
|
||||
target_link_libraries(uhub ${CMAKE_DL_LIBS} adc network utils)
|
||||
@@ -156,7 +154,6 @@ target_link_libraries(mod_no_guest_downloads utils)
|
||||
target_link_libraries(mod_chat_only utils)
|
||||
target_link_libraries(mod_logging utils)
|
||||
target_link_libraries(mod_topic utils)
|
||||
target_link_libraries(mod_require_tls utils)
|
||||
target_link_libraries(utils network)
|
||||
target_link_libraries(mod_welcome network)
|
||||
target_link_libraries(mod_logging network)
|
||||
|
||||
@@ -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." );
|
||||
|
||||
@@ -96,29 +96,6 @@ static int cbfunc_user_disconnect(struct plugin_handle* plugin, struct plugin_us
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int cbfunc_user_redirect(struct plugin_handle* plugin, struct plugin_user* user, const char* address)
|
||||
{
|
||||
char* buffer = adc_msg_escape(address);
|
||||
struct adc_message* command = adc_msg_construct(ADC_CMD_IQUI, strlen(buffer) + 10);
|
||||
adc_msg_add_named_argument(command, ADC_QUI_FLAG_REDIRECT, buffer);
|
||||
route_to_user(plugin_get_hub(plugin), convert_user_type(user), command);
|
||||
adc_msg_free(command);
|
||||
hub_free(buffer);
|
||||
hub_disconnect_user(plugin_get_hub(plugin), convert_user_type(user), quit_disconnected);
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int cbfunc_user_is_tls_connected(struct plugin_handle* plugin, struct plugin_user* user)
|
||||
{
|
||||
#ifdef SSL_SUPPORT
|
||||
struct hub_user* u = convert_user_type(user);
|
||||
return net_con_is_ssl(u->connection);
|
||||
#else
|
||||
return 0;
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
static int cbfunc_command_add(struct plugin_handle* plugin, struct plugin_command_handle* cmdh)
|
||||
{
|
||||
struct plugin_callback_data* data = get_callback_data(plugin);
|
||||
@@ -226,8 +203,6 @@ void plugin_register_callback_functions(struct plugin_handle* handle)
|
||||
handle->hub.send_broadcast_message = cbfunc_send_broadcast;
|
||||
handle->hub.send_status_message = cbfunc_send_status;
|
||||
handle->hub.user_disconnect = cbfunc_user_disconnect;
|
||||
handle->hub.user_redirect = cbfunc_user_redirect;
|
||||
handle->hub.user_is_tls_connected = cbfunc_user_is_tls_connected;
|
||||
handle->hub.command_add = cbfunc_command_add;
|
||||
handle->hub.command_del = cbfunc_command_del;
|
||||
handle->hub.command_arg_reset = cbfunc_command_arg_reset;
|
||||
|
||||
@@ -35,16 +35,6 @@ struct plugin_command
|
||||
struct linked_list* args;
|
||||
};
|
||||
|
||||
enum plugin_command_arg_type
|
||||
{
|
||||
plugin_cmd_arg_type_integer,
|
||||
plugin_cmd_arg_type_string,
|
||||
plugin_cmd_arg_type_user,
|
||||
plugin_cmd_arg_type_address,
|
||||
plugin_cmd_arg_type_range,
|
||||
plugin_cmd_arg_type_credentials,
|
||||
};
|
||||
|
||||
struct plugin_command_arg_data
|
||||
{
|
||||
enum plugin_command_arg_type type;
|
||||
|
||||
@@ -28,7 +28,6 @@
|
||||
#include "util/credentials.h"
|
||||
#include "network/ipcalc.h"
|
||||
#include "plugin_api/types.h"
|
||||
#include "plugin_api/command_api.h"
|
||||
|
||||
typedef void (*on_connection_accepted_t)(struct plugin_handle*, struct ip_addr_encap*);
|
||||
typedef void (*on_connection_refused_t)(struct plugin_handle*, struct ip_addr_encap*);
|
||||
@@ -114,8 +113,6 @@ typedef int (*hfunc_send_message)(struct plugin_handle*, struct plugin_user* use
|
||||
typedef int (*hfunc_send_broadcast_message)(struct plugin_handle*, const char* message);
|
||||
typedef int (*hfunc_send_status)(struct plugin_handle*, struct plugin_user* to, int code, const char* message);
|
||||
typedef int (*hfunc_user_disconnect)(struct plugin_handle*, struct plugin_user* user);
|
||||
typedef int (*hfunc_user_redirect)(struct plugin_handle*, struct plugin_user* user, const char* address);
|
||||
typedef int (*hfunc_user_is_tls_connected)(struct plugin_handle*, struct plugin_user* user);
|
||||
typedef int (*hfunc_command_add)(struct plugin_handle*, struct plugin_command_handle*);
|
||||
typedef int (*hfunc_command_del)(struct plugin_handle*, struct plugin_command_handle*);
|
||||
|
||||
@@ -139,8 +136,6 @@ struct plugin_hub_funcs
|
||||
hfunc_send_broadcast_message send_broadcast_message;
|
||||
hfunc_send_status send_status_message;
|
||||
hfunc_user_disconnect user_disconnect;
|
||||
hfunc_user_redirect user_redirect;
|
||||
hfunc_user_is_tls_connected user_is_tls_connected;
|
||||
hfunc_command_add command_add;
|
||||
hfunc_command_del command_del;
|
||||
hfunc_command_arg_reset command_arg_reset;
|
||||
|
||||
@@ -93,6 +93,15 @@ struct ban_info
|
||||
time_t expiry; /* Time when the ban record expires */
|
||||
};
|
||||
|
||||
enum plugin_command_arg_type
|
||||
{
|
||||
plugin_cmd_arg_type_integer,
|
||||
plugin_cmd_arg_type_string,
|
||||
plugin_cmd_arg_type_user,
|
||||
plugin_cmd_arg_type_address,
|
||||
plugin_cmd_arg_type_range,
|
||||
plugin_cmd_arg_type_credentials,
|
||||
};
|
||||
|
||||
|
||||
#endif /* HAVE_UHUB_PLUGIN_TYPES_H */
|
||||
|
||||
@@ -1,41 +0,0 @@
|
||||
/*
|
||||
* uhub - A tiny ADC p2p connection hub
|
||||
* Copyright (C) 2007-2018, Jan Vidar Krey
|
||||
*
|
||||
* 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 "plugin_api/handle.h"
|
||||
#include "plugin_api/command_api.h"
|
||||
#include "util/memory.h"
|
||||
|
||||
struct example_plugin_data
|
||||
{
|
||||
struct plugin_command_handle* redirect;
|
||||
};
|
||||
|
||||
|
||||
|
||||
int plugin_register(struct plugin_handle* plugin, const char* config)
|
||||
{
|
||||
PLUGIN_INITIALIZE(plugin, "TLS redirect plugin", "1.0", "A simple redirect to TLS plug-in");
|
||||
return 0;
|
||||
}
|
||||
|
||||
int plugin_unregister(struct plugin_handle* plugin)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user