1
0
mirror of https://github.com/unrealircd/unrealircd.git synced 2026-06-26 07:16:38 +02:00
Commit Graph

392 Commits

Author SHA1 Message Date
Bram Matthys c3824ad47d Fix potentially sending invalid data over websockets on REHASH.
This makes websocket_common unload last (and near-last: rpc & websocket)
and makes us call Mod_Init for these three modules first.
This way, the period where the websocket handler is unavailable is kept
to a minimum.

This also renames the ModuleSetOptions option MOD_OPT_UNLOAD_PRIORITY
to MOD_OPT_PRIORITY since it dynamically changes the module priority
in the list. For 6.x compatibility, MOD_OPT_UNLOAD_PRIORITY can still
be used.
2022-11-04 10:54:53 +01:00
Bram Matthys 4e5598b6cf Create and use new CALL_NEXT_COMMAND_OVERRIDE() instead of CallCommandOverride().
This is an easier way to call the next command override handler from command
override functions. It passes the standard parameters so you don't have to
worry about which parameters a CMD_OVERRIDE_FUNC() contains.
This so it is easier to change command parameters in future UnrealIRCd versions,
should it be needed, then it may be possible without any source code changes
on the module developer side.

-       CallCommandOverride(ovr, client, recv_mtags, parc, parv);
+       CALL_NEXT_COMMAND_OVERRIDE();
2022-08-28 08:52:51 +02:00
Bram Matthys 0d139c6e7c Make /INVITE bypass (nearly) all channel mode restrictions, as it used to be
and as it should be IMO. Both for invites by channel ops and for OperOverride.

This also fixes a bug where an IRCOp with OperOverride could not bypass +l
and other restrictions. Only +b and +i could be bypassed.

Module coders: HOOKTYPE_OPER_INVITE_BAN is now gone and HOOKTYPE_INVITE_BYPASS
is now new. The HOOKTYPE_INVITE_BYPASS is called when the user is joining
a channel to which they were invited to. If you return HOOK_DENY there then
the join is still blocked, otherwise it is allowed.
Using this hook would be sortof unusual since usually you would want users
to be able to bypass restrictions when they were invited by another user
or when they invited themselves using OperOverride.
The only example where we use it in UnrealIRCd is for +O channels so an
IRCOp cannot use OperOverride to join +O channels when they would otherwise
not be allowed to do so. Actually even that is a corner case that you could
debate about, but.. whatever.
2022-08-06 15:52:16 +02:00
Bram Matthys c60fdad7eb RPC: add server_ban.add
This also moves some of the adding code (sending notice, broadcasting to
other servers, etc) to a function tkl_added().

We should probably do the same for deletion and not use the tkllayer
anymore for that?
2022-06-24 19:49:32 +02:00
Bram Matthys 3d9b7e4b70 RPC: remove tkl, split this up.. starting with server_ban.
Currently available:
* server_ban.list
* server_ban.get with params: name="*@1.2.3.4", type="kline"

This also adds server_ban_parse_mask() which is now used by both GLINE/etc
and the RPC API to parse the same way and convey the same error messages.
2022-06-24 18:53:10 +02:00
Bram Matthys 941439a710 Use RPC_CALL_FUNC() just like how we have CMD_FUNC() 2022-06-19 13:13:33 +00:00
Bram Matthys 853f0685ed Split off big chunk of websocket module into websocket_common module.
And load the websocket_common module by default (which is just an API).
2022-06-19 13:13:33 +00:00
Bram Matthys 4a68008b81 Rename some more:
* WEB() now has handle_request() and handle_body(), makes more sense.
* webserver_handle_body_data() -> webserver_handle_body()
* and similar cases
2022-06-19 13:13:33 +00:00
Bram Matthys 9afdcb7ff0 Add request body handler in webserver -- only a beginning, the
chunked encoding stuff is copied from the modulemanager and #if'd out.
The non-chunked is not OK yet either, as it must check the Content-Length,
while we currently assume a single packet == the complete request.
2022-06-19 13:13:33 +00:00
Bram Matthys 46588db89a Fix rehash crash since adding RPC code. 2022-06-19 13:13:33 +00:00
Bram Matthys 60c83b4ba1 Move connect-flood and max-unknown-connections-per-ip into their own module.
These deal with set::anti-flood::everyone::connect-flood and
set::max-unknown-connections-per-ip respectively.

This adds a new hook HOOKTYPE_ACCEPT, that is mostly meant for internal
usage by UnrealIRCd. Most module coders will want to use the existing
hook HOOKTYPE_HANDSHAKE instead.

This also gets of check_banned() which is now spread over the individual
modules (eg: checking banned is done in tkl on HOOKTYPE_ACCEPT and
HOOKTYPE_IP_CHANGE).
2022-06-19 13:13:33 +00:00
Bram Matthys 61ba3727df JSON-RPC: Use proper error response with error codes according to
the official specification (one of JSON_RPC_ERROR_*).

Add proper rpc_error() and rpc_error_fmt()

Don't steal reference in rpc_response().
2022-06-19 13:13:33 +00:00
Bram Matthys 4cd520d327 Make user.list() RPC API return a list of all users with details.
This is the 1st RPC API call that actually works :D
2022-06-19 13:13:33 +00:00
Bram Matthys 97c8274695 Add RPC API (the beginning..) 2022-06-19 13:13:33 +00:00
Bram Matthys 2397fb8a49 Split 'websocket' module up in 'webserver' and 'websocket' 2022-06-19 13:13:33 +00:00
Bram Matthys b28d8aecd7 Add "ip" to mask item and security-group for easy matching on IP.
So you can just use mask { ip { 127.*; 192.168.*; } } without
having to worry about hostnames like 127.example.net.
(Of course you could also have used CIDR notation)

Another benefit is that, since we are dealing with IP's only,
the matching is faster than going through the more universal
match_user() routine.
2022-05-25 08:34:22 +02:00
Bram Matthys 16264e944f Add HOOKTYPE_JSON_EXPAND_CLIENT etc. so modules can add more fields when
clients etc. are expanded in the logging routines.

HOOKTYPE_JSON_EXPAND_CLIENT - for all clients
HOOKTYPE_JSON_EXPAND_CLIENT_USER - for clients that are users
HOOKTYPE_JSON_EXPAND_CLIENT_SERVER - for clients that are servers
HOOKTYPE_JSON_EXPAND_CHANNEL - for channels
2022-05-23 11:02:05 +02:00
Bram Matthys 3fbdb7fd4b Move StripControlCodes() from message.c to misc.c.
Because I need in the core (again) due to early calls / calls during
rehashes / etc...
2022-05-23 10:10:47 +02:00
Bram Matthys 10bddc1232 Extended server bans are now more clearly exposed in security-group { }.
The extban module API is used behind the scenes. To the server admin
the functionality appears in a more natural way:
        account { <list>; };
        country { <list>; };
        realname { <list>; };
        certfp { <list>; };
In the same way, they appear as exclude-xxx options too:
        exclude-account { <list>; };
        exclude-country { <list>; };
        exclude-realname { <list>; };
        exclude-certfp { <list>; };

Modules can add additional fields (3rd party modules too!).

Module coders:
See src/modules/extbans/realname.c for a simple example. In short:
1) You need to register your extban in both MOD_TEST and MOD_INIT
2) Other than that, the existing rules for extended server bans apply:
   a) Your req.is_banned_events needs to include BANCHK_TKL
   b) Your req.options needs to include EXTBOPT_TKL
Be advised that for modules that are called in extended server bans
the client may be missing several fields, for example client->user could
be NULL, so be careful with accessing everything in your module.
2022-05-13 20:13:34 +02:00
Bram Matthys 50e5d91c79 Add SVSO command which services can use to make someone IRCOp.
This existed in UnrealIRCd 3.2.x but was later removed when
switching to the new operclass system.
Requested by Valware in https://bugs.unrealircd.org/view.php?id=6041

Syntax: SVSO <uid|nick> <oper account> <operclass> <class> <modes> <snomask> <vhost>
All these parameters need to be set, you cannot leave any of them out,
HOWEVER some can be set to "-" to skip setting them, this is true for:
<class>, <modes>, <snomask>, <vhost>

In UnrealIRCd the <operclass> will be prefixed by "services:" if not already
present. It is up to you to include or omit it.

If you want to set any swhoises you need to use the SWHOIS s2s command,
other than that this command basically does everything for you,
in fact it uses the same code as the OPER command does.
Most of the "user is now ircop" code has been moved out of cmd_oper() to
a new function make_oper() that is called by both cmd_oper() and cmd_svso().

This function also changes the hook HOOKTYPE_LOCAL_OPER:
It no longer passes a ConfigItem_oper struct, since we can't do that for
remote opers. Instead it passes oper name and oper class.
The complete definition is now:
int hooktype_local_oper(Client *client, int add, const char *oper_block, const char *operclass);
2022-05-07 18:53:59 +02:00
Bram Matthys d4f09f8fed HOOKTYPE_*_CHANGED -> HOOKTYPE_*_CHANGE to be a bit more consistent with
the rest of the hooks, most of which do not use the past tense.
Only affects HOOKTYPE_USERHOST_CHANGE / HOOKTYPE_REALNAME_CHANGE.

This does, however, make it inconsistent with the userhost_changed()
call, though :D.
2022-01-17 08:02:18 +01:00
Bram Matthys f3d827c577 Add HOOKTYPE_IP_CHANGE and call it when the IP address changes.
Eg for WEBIRC or other proxy.

This does not yet fix any problem, it just changes the way things are
called. More to follow.
2022-01-17 07:55:45 +01:00
Bram Matthys 834736070e Make "SVS(2)MODE -b user" work properly for extended bans.
It was missing for a lot of extbans (removing too little) and
for ~t it was removing too much (eg quiet bans).
Bug reported and changes suggested by k4be.

Coders:
Setting extban.options to EXTBOPT_CHSVSMODE has no effect anymore,
just didn't want to remove it so modules would still compile.
We now purely match based on .is_banned_events including BANCHK_JOIN.
2022-01-02 13:12:33 +01:00
Bram Matthys 4bc2848b9e Fix a prototype and change a largely unused log category to avoid clashes. 2021-12-10 10:28:35 +01:00
Bram Matthys 4af7a541f8 Add 'oldnick' to HOOKTYPE_POST_LOCAL_NICKCHANGE and HOOKTYPE_POST_REMOTE_NICKCHANGE 2021-12-01 08:40:02 +01:00
Bram Matthys b078a9c8b5 Fix cut-off and expansion issues with MODE, which is a possible problem when
using mixed UnrealIRCd 5 and UnrealIRCd 6 networks.

This is a slightly complex rewrite of make_mode_str() and do_mode(),
as we nog go from single mode lines to potentially multiple mode lines.

In short: whenever we would be near buffer cut-off point (the famous
512 byte limit) then previously we would prevent the mode, though not
succesfully in all cases where a network consists of mixed 5.x and 6.x.
From this point onward we no longer do that. Instead we convert one
MODE command to two MODE lines if that is needed.
The benefit of this is that we no longer prevent it BEFORE processing
the MODE, which is a flawed method and could be wrong (causing desyncs).
And also, we no longer partially ignore MODE lines from clients when
they would cause the limit to be exceeded, as we replace them with
two MODE lines instead.

These are more changes than I wanted at such a late point but.. they seem
to be necessary to prevent U5-U6 compatibility issues.
2021-11-19 13:53:21 +01:00
Bram Matthys 520804edc2 Add set::whois-detail which allows you to configure which items
to expose to which users and in what detail.

The default configuration is as follows:

set {
	whois-details {
		basic		{ everyone full; }
		modes		{ everyone none;	self full;	oper full; }
		realhost	{ everyone none;	self full;	oper full; }
		registered-nick	{ everyone full; }
		channels	{ everyone limited;	self full;	oper full; }
		server		{ everyone full; }
		away		{ everyone full; }
		oper		{ everyone limited;	self full;	oper full; }
		secure		{ everyone limited;	self full;	oper full; }
		bot		{ everyone full; }
		services	{ everyone full; }
		reputation	{ everyone none;	self none;	oper full; }
		geo		{ everyone none;	self none;	oper full; }
		certfp		{ everyone full; }
		shunned		{ everyone none;	self none;	oper full; }
		account		{ everyone full; }
		swhois		{ everyone full; }
		idle		{ everyone limited;	self full;	oper full; }
	}
}

Oh, yeah, and for "secure" this also adds displaying of the TLS cipher
in /WHOIS for ircops and self by default. For all others it is limited
to just "is using a Secure Connection".

This also removes the newly added set::geoip::whois-for-anyone since
it is now configured via set::whois-details::geo.

Module coders: HOOKTYPE_WHOIS changed and you may no longer send
directly to the client from this hook. Instead, you should use
add to the NameValuePrioList, usually via the functions
add_nvplist_numeric() and add_nvplist_numeric_fmt().
For inspiration see bot_whois in src/modules/usermodes/bot.c
and reputation_whois in src/modules/reputation.c
2021-09-27 17:27:26 +02:00
Bram Matthys c06f423643 Get rid of ExtBan_Table[] and use a linked list called extbans.
Just like already done for Usermode_Table[] and Channelmode_Table[].

This also adds support for ->unloading=1 and re-use etc etc,
something that seemed to be missing before (but also wasn't
an issue apparently...).
2021-09-26 13:11:21 +02:00
Bram Matthys ee8cc0e8e2 Get rid of Usermode_Table[] and use a linked list called usermodes.
Just like already done for Channelmode_Table[] -> channelmodes.
2021-09-26 12:46:34 +02:00
Bram Matthys e4b449adf8 Add set_channel_mode() which can be used to issue a server mode.
It's usage would be rare, but this is f.e. used from channeldb.
Other uses may be in some 3rd party module.
Example: set_channel_mode(channel, "+k", "key")
2021-09-25 17:42:21 +02:00
Bram Matthys 0e9d7a669f Update HOOKTYPE_LOG to work with new logging system (lots of different args) 2021-09-25 17:33:02 +02:00
Bram Matthys 35ae1bcc42 Update a comment about a hook
[skip ci]
2021-09-25 17:23:52 +02:00
Bram Matthys c6ef13b258 Remove HOOKTYPE_REQUIRE_SASL which was never called.
Apparently the other hooks were sufficient after all for authprompt ;D
2021-09-25 17:15:49 +02:00
Bram Matthys 834d38e904 Update HOOKTYPE_PRE_KNOCK to include reason (not used, though) 2021-09-25 17:08:53 +02:00
Bram Matthys 3033fd9b6d Fix some todo items such as validating extban letter and names in ExtbanAdd() 2021-09-25 16:38:15 +02:00
Bram Matthys 73b908e413 Changes to BanContext struct (extended ban API):
* Now ban_check_types (previously checktype):
  this is one or more of BANCHK_* OR'd together, eg BANCHK_JOIN, BANCHK_MSG..
* Now ban_type (previously what2):
  this is the type of the ban, eg EXBTYPE_BAN, EXBTYPE_EXCEPT, etc.
* Now is_ok_check (previously is_ok_checktype)
  this is one of EXBCHK_* for is_ok, eg EXBCHK_PARAM to check parameter.
2021-09-25 16:28:10 +02:00
Bram Matthys b37b190fdd Add enums ExtbanCheck and ExtbanType for use in BanContext. 2021-09-25 16:16:42 +02:00
Bram Matthys ec8f54ec26 Update cloaking key mismatch error and rename some stuff. 2021-09-25 11:19:15 +02:00
Bram Matthys ce5917e0d9 Expose operlogin and operclass via moddata so they can be seen in WHOIS
and used for auditting purposes across servers (assuming the servers
itself can be trusted).
This is done via the 'operlogin' module which is loaded by default.
Obviously for opers of U5 and below this information is not available.

This also changes the HOOKTYPE_LOCAL_OPER hook to include oper block info:
-int hooktype_local_oper(Client *client, int add);
+int hooktype_local_oper(Client *client, int add, ConfigItem_oper *oper_block);
2021-09-25 10:28:36 +02:00
Bram Matthys bf7a72a850 Usermode_Table[].flag -> Usermode_Table[].letter
just like how it is now in U6 in channel modes and extended bans
2021-09-25 09:13:34 +02:00
Bram Matthys fbf3a51517 Add HOOKTYPE_CAN_SET_TOPIC, which works similar to HOOKTYPE_CAN_KICK.
Move checking of +t restrictions to chanmodes/topiclimit.
Move checking for +m restrictions to chanmodes/moderated.
Now the only check remaining in topic is for +b (banned users)
which is fine I think.
2021-09-25 09:04:19 +02:00
Bram Matthys 720f597ad6 Get rid of current snomask system and allow ircops to set any snomask
(that is: a-z A-Z) so to use the dynamic system with the new logging.
Largely untested.
2021-09-22 15:49:20 +02:00
Bram Matthys 381454bd1d 1) Change from .prefix_priority to .rank.
2) Make higher value = higher ranking
3) Ship with defines for these:
 #define RANK_CHANOWNER  4000
 #define RANK_CHANADMIN  3000
 #define RANK_CHANOP     2000
 #define RANK_HALFOP     1000
 #define RANK_VOICE        -1
2021-09-20 16:09:14 +02:00
Bram Matthys 139098919b Get rid of PREFIX_* in sendto_channel(), message.c and in chanmsg hook.
We use char *member_modes like we now have at all the other places,
which contains eg "o".

TODO: fix prefix sending rules or remove some if 0'd out code

And not sure if we want to do it entirely this way :D
2021-09-20 15:54:57 +02:00
Bram Matthys 4cea88645c Modularize member modes (vhoaq).
Still need to clean up a bit after this, but it passes all tests :)
2021-09-13 18:44:18 +02:00
Bram Matthys 4392468c3e Update HOOKTYPE_CAN_JOIN and HOOKTYPE_CAN_JOIN_LIMITEXCEEDED to take
an extra char **errmsg argument. Upon failure (non zero return value)
this should contain a format string to be sent to the client
(with the return value denoting the number of the numeric).

This gets rid of sendnumeric_legacy() in join.c
2021-09-12 16:09:36 +02:00
Bram Matthys 8353a9e17b Change char *parv[] to const char *parv[] everywhere. This is a BIG change.
It means you can no longer modify eg parv[1] in-place with strtoken and such.

The main reason for this is that as a command handler you have no idea
where the arguments may come from. It could be from a do_cmd() with
read-only storage (eg a string literal) and so on.

It started with an experiment of how far I could get and how annoying the
side-effects would be, but they seem to be quite managable, so I'm
committing this stuff.

Hopefully this catches/solves some stupid bugs somewhere :)
2021-09-11 16:02:44 +02:00
Bram Matthys 7cabd4b79e Const const const 2021-09-11 08:17:12 +02:00
Bram Matthys ac84d4f207 Const const const... modules.c and elsewhere. 2021-09-11 07:53:30 +02:00
Bram Matthys 5bc244c1f3 Add a lot more consts. This finishes the work for all hooktypes. 2021-09-10 20:36:38 +02:00