mirror of
https://github.com/pissnet/pissircd.git
synced 2025-08-08 19:25:25 +01:00
Add listener->start_handshake function pointer.
This is start_of_normal_client_handshake() by default, but is start_of_control_client_handshake() for the control channel (for './unrealircd rehash' and such). Previously that was hardcoded. It is also used by the RPC code now.
This commit is contained in:
parent
2bf41a47d2
commit
5e81a6ee67
6 changed files with 27 additions and 13 deletions
|
@ -1738,6 +1738,7 @@ struct ConfigItem_listen {
|
|||
SSL_CTX *ssl_ctx;
|
||||
TLSOptions *tls_options;
|
||||
WebServer *webserver;
|
||||
void (*start_handshake)(Client *client); /**< Function to call on accept() */
|
||||
int websocket_options; /* should be in module, but lazy */
|
||||
int rpc_options;
|
||||
char *websocket_forward;
|
||||
|
|
|
@ -4990,6 +4990,7 @@ int _conf_listen(ConfigFile *conf, ConfigEntry *ce)
|
|||
} else {
|
||||
isnew = 0;
|
||||
}
|
||||
listen->start_handshake = start_of_normal_client_handshake;
|
||||
|
||||
if (listen->options & LISTENER_BOUND)
|
||||
tmpflags |= LISTENER_BOUND;
|
||||
|
@ -5052,6 +5053,8 @@ int _conf_listen(ConfigFile *conf, ConfigEntry *ce)
|
|||
} else
|
||||
isnew = 0;
|
||||
|
||||
listen->start_handshake = start_of_normal_client_handshake;
|
||||
|
||||
if (listen->options & LISTENER_BOUND)
|
||||
tmpflags |= LISTENER_BOUND;
|
||||
|
||||
|
@ -5137,6 +5140,8 @@ int _conf_listen(ConfigFile *conf, ConfigEntry *ce)
|
|||
} else
|
||||
isnew = 0;
|
||||
|
||||
listen->start_handshake = start_of_normal_client_handshake;
|
||||
|
||||
if (listen->options & LISTENER_BOUND)
|
||||
tmpflags |= LISTENER_BOUND;
|
||||
|
||||
|
|
|
@ -21,7 +21,8 @@ int rpc_config_test(ConfigFile *cf, ConfigEntry *ce, int type, int *errs);
|
|||
int rpc_config_run_ex(ConfigFile *cf, ConfigEntry *ce, int type, void *ptr);
|
||||
//int rpc_packet_out(Client *from, Client *to, Client *intended_to, char **msg, int *length);
|
||||
void rpc_mdata_free(ModData *m);
|
||||
int rpc_client_handshake(Client *client);
|
||||
int rpc_client_accept(Client *client);
|
||||
void rpc_client_handshake(Client *client);
|
||||
int rpc_handle_request(Client *client, WebRequest *web);
|
||||
int rpc_handle_request_data(Client *client, WebRequest *web, const char *readbuf2, int length2);
|
||||
int rpc_packet_in(Client *client, const char *readbuf, int *length);
|
||||
|
@ -61,7 +62,7 @@ MOD_INIT()
|
|||
MARK_AS_OFFICIAL_MODULE(modinfo);
|
||||
|
||||
HookAdd(modinfo->handle, HOOKTYPE_CONFIGRUN_EX, 0, rpc_config_run_ex);
|
||||
HookAdd(modinfo->handle, HOOKTYPE_HANDSHAKE, INT_MIN, rpc_client_handshake);
|
||||
HookAdd(modinfo->handle, HOOKTYPE_HANDSHAKE, -5000, rpc_client_accept);
|
||||
//HookAdd(modinfo->handle, HOOKTYPE_PACKET, INT_MAX, rpc_packet_out);
|
||||
HookAdd(modinfo->handle, HOOKTYPE_RAWPACKET_IN, INT_MIN, rpc_packet_in);
|
||||
|
||||
|
@ -143,6 +144,7 @@ int rpc_config_run_ex(ConfigFile *cf, ConfigEntry *ce, int type, void *ptr)
|
|||
|
||||
l = (ConfigItem_listen *)ptr;
|
||||
l->options |= LISTENER_NO_CHECK_CONNECT_FLOOD;
|
||||
l->start_handshake = rpc_client_handshake;
|
||||
l->webserver = safe_alloc(sizeof(WebServer));
|
||||
l->webserver->handle_request = rpc_handle_request;
|
||||
l->webserver->handle_data = rpc_handle_request_data;
|
||||
|
@ -376,12 +378,18 @@ void rpc_call(Client *client, json_t *request)
|
|||
handler->call(client, request, params);
|
||||
}
|
||||
|
||||
int rpc_client_handshake(Client *client)
|
||||
/** Called very early on accept() of the socket, before TLS is ready */
|
||||
int rpc_client_accept(Client *client)
|
||||
{
|
||||
if (RPC_PORT(client))
|
||||
{
|
||||
// FIXME: do access control here immediately, reject the client if needed.
|
||||
SetRPC(client);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
void rpc_client_handshake(Client *client)
|
||||
{
|
||||
SetRPC(client); /* explicit set due to TLS */
|
||||
fd_setselect(client->local->fd, FD_SELECT_READ, read_packet, client);
|
||||
|
||||
/* FIXME: IP Access checks here (if possible) */
|
||||
}
|
||||
|
|
|
@ -26,12 +26,13 @@
|
|||
#include "unrealircd.h"
|
||||
#include <ares.h>
|
||||
|
||||
/* Forward declarations */
|
||||
CMD_FUNC(procio_status);
|
||||
CMD_FUNC(procio_modules);
|
||||
CMD_FUNC(procio_rehash);
|
||||
CMD_FUNC(procio_exit);
|
||||
CMD_FUNC(procio_help);
|
||||
|
||||
void start_of_control_client_handshake(Client *client);
|
||||
int procio_accept(Client *client);
|
||||
|
||||
/** Create the unrealircd.ctl socket (server-side) */
|
||||
|
@ -48,6 +49,7 @@ void add_proc_io_server(void)
|
|||
safe_strdup(listener->file, CONTROLFILE);
|
||||
listener->socket_type = SOCKET_TYPE_UNIX;
|
||||
listener->options = LISTENER_CONTROL|LISTENER_NO_CHECK_CONNECT_FLOOD|LISTENER_NO_CHECK_ZLINED;
|
||||
listener->start_handshake = start_of_control_client_handshake;
|
||||
listener->fd = -1;
|
||||
AddListItem(listener, conf_listen);
|
||||
if (add_listener(listener) == -1)
|
||||
|
|
|
@ -41,7 +41,6 @@ extern char *version;
|
|||
MODVAR time_t last_allinuse = 0;
|
||||
|
||||
void start_of_normal_client_handshake(Client *client);
|
||||
extern void start_of_control_client_handshake(Client *client);
|
||||
void proceed_normal_client_handshake(Client *client, struct hostent *he);
|
||||
|
||||
/** Close all connections - only used when we terminate the server (eg: /DIE or SIGTERM) */
|
||||
|
@ -895,10 +894,9 @@ refuse_client:
|
|||
}
|
||||
}
|
||||
} else
|
||||
if (listener->options & LISTENER_CONTROL)
|
||||
start_of_control_client_handshake(client);
|
||||
else
|
||||
start_of_normal_client_handshake(client);
|
||||
{
|
||||
listener->start_handshake(client);
|
||||
}
|
||||
return client;
|
||||
}
|
||||
|
||||
|
|
|
@ -780,7 +780,7 @@ int unreal_tls_accept(Client *client, int fd)
|
|||
return -1;
|
||||
}
|
||||
|
||||
start_of_normal_client_handshake(client);
|
||||
client->local->listener->start_handshake(client);
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue