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

2569 Commits

Author SHA1 Message Date
Bram Matthys 957af0909b RPC: channel.get and channel.list now have optional object_detail_level.
This is an integer which decides the amount of details in the response object.

For the channel.* calls the object_detail_level is one of:
0: only return the channel name, nothing else
1: basic channel information only
2: this adds bans, ban_exemptions, invite_exceptions
3: also show members, but only level/name/id
4: also show members, level/name/id/hostname/ip/details/geoip
5: also show members, level and full user details like user.get

When no object_detail_level is specified, the following defaults are used:
For channel.list the default is 1 (matches current 6.0.6 behavior)
For channel.get the default is 3 (matches current 6.0.6 behavior)

Using channel.list with object_detail_level=5 is forbidden because
it would cause way too much output (and processing time).
2023-03-27 09:56:03 +02:00
Bram Matthys 04ce8f8ed7 Add helper functions 2023-03-25 12:19:44 +01:00
Bram Matthys 748f381d81 Use X509_check_host() in OpenSSL 1.1.0 and later and don't use it
for OpenSSL 1.0.2 anymore, 1.0.2 will use the fallback version.
This changes the include file.

(OpenSSL 1.0.2 is out of support since Jan 1 2020 so one may wonder
 why care at all, but i'm trying not to break that during minor
 UnrealIRCd releases)
2023-03-25 12:18:44 +01:00
Bram Matthys 78ce692357 Move ban_exists() to the core (was a helper function in channeldb) 2023-03-25 10:38:05 +01:00
Bram Matthys 5f36221869 Add OpenSSL include to fix compile warning.
X509_check_host() requires openssl/x509.h -- well except on
newer OpenSSL's apparently :D
2023-03-25 10:32:12 +01:00
Bram Matthys 24622144b1 Bump version to 6.0.8-git
[skip ci]
2023-03-25 09:19:41 +01:00
Bram Matthys 83d2498ec8 Add configure check for and use X509_check_host() instead of
always using our own implementation (that is not really ours,
by the way).
2023-03-25 08:31:25 +01:00
Bram Matthys 89611887cb Previous fix for big tags was insufficient. 4K+4K+512 rule should now be OK.
This also adds the MAXLINELENGTH define which is set to 4K+4K+512,
it can be used when you are dealing with complete lines (quite rare
in the code, mostly in socket code and labeled response).
And now also #define READBUFSIZE MAXLINELENGTH
but it is used beyond read buffers, als in write buffers of course.
2023-03-25 07:30:22 +01:00
Bram Matthys da3c1c6544 ** UnrealIRCd 6.0.7 ** 2023-03-24 13:26:29 +01:00
Bram Matthys e83c610b39 Add valid_vhost() and validate oper::vhost too just like vhost::vhost.
Actually make them both use this same function, even thought he original
vhost::vhost check was a bit more informational.

This also checks the vhost in other paths that lead to oper vhost setting.

Reported by ji in https://bugs.unrealircd.org/view.php?id=5910
2023-03-22 10:26:05 +01:00
Bram Matthys 4b4562516c Another attempt at UTF8-aware spamfilter.
This was previously tried at 19-apr-2020 in bc70882bd3
in UnrealIRCd 5.0.5. Sadly it had to be reverted immediately with a quick 5.0.5.1
release, all because of a PCRE2 100% CPU usage. Since then that bug has been fixed,
plus another bug. I'm now readding it "as an option" that is marked experimental.
Hopefully people test it out and can report back if it works well and then we can
make it the default someday.

This makes it a runtime setting so makes it much easier to switch back/forth if
there are any issues without recompiling anything. Had to use a bit more code now
though to handle the recompiling of spamfilters if the setting is changed.

Original issue was https://bugs.unrealircd.org/view.php?id=5187

* [Spamfilter](https://www.unrealircd.org/docs/Spamfilter) can be made UTF8-aware.
  * This is experimental, to enable: `set { spamfilter { utf8 yes; } }``
  * Case insensitive matches will then work better. For example, with extended
    Latin, a spamfilter on `ę` then also matches `Ę`.
  * Other PCRE2 features such as [\p](https://www.pcre.org/current/doc/html/pcre2syntax.html#SEC5)
    can then be used. For example you can then set a spamfilter with the regex
    `\p{Arabic}` to block all Arabic script.
    Please do use these new tools with care. Blocking an entire language
    or script is quite a drastic measure.
  * As a consequence of this we require PCRE2 10.36 or newer. If your system
    PCRE2 is older than this will mean the UnrealIRCd-shipped-library version
    will be compiled and `./Config` may take a little longer than usual.
2023-03-22 09:00:31 +01:00
Bram Matthys 8a48cfb664 Fix not sending CAP DEL on module unload.
Reported by westor in https://bugs.unrealircd.org/view.php?id=6104
The code was there but the order of which the checks were done was
wrong, so first it was checking which CAP's were unloaded and after
that it was unloading the CAP, instead of the other way around.

Also renamed the function to clicap_check_for_changes()
to be consistent with other runtime change detection functions
like extcmodes_check_for_changes(), umodes_check_for_changes()
and charsys_check_for_changes().
2023-03-20 10:55:22 +01:00
Bram Matthys a1e7e9f882 Move deny link { } handling to server module. 2023-03-20 09:09:03 +01:00
Bram Matthys 5c108e0ec3 Don't fetch GeoIP.dat upon blacklist-module geoip_classic;
Reported in https://bugs.unrealircd.org/view.php?id=6100

Actually this only works if you have a:
blacklist-module geoip_classic;
in your conf and that conf is read before modules.default.conf
This is true if you have that blacklist-module line in your
unrealircd.conf, so should cover most cases.
2023-03-19 11:28:23 +01:00
Bram Matthys 15c8da2be8 Send ERR_INPUTTOOLONG (417) on oversized message-tags, as per
https://ircv3.net/specs/extensions/message-tags
Reported by progval in https://bugs.unrealircd.org/view.php?id=5949
2023-03-19 10:13:58 +01:00
Bram Matthys 951b913800 Update crule.c, re-porting it from ircu, to hopefully fix some bug(s).
Reported by 9pfs in https://bugs.unrealircd.org/view.php?id=6248

This is completely untested (other than ./unrealircd start), so
feedback from people who actually use crule like in deny link { }
is very much welcomed.
2023-03-19 08:38:54 +01:00
Bram Matthys 0428819c03 Add security group "websocket-users" and add security-group options
security-group::websocket and security-group::exclude-websocket,
all similar to how security-group::webirc works but for websocket.
Suggested by PeGaSuS in https://bugs.unrealircd.org/view.php?id=5598
and Nini in https://bugs.unrealircd.org/view.php?id=6222
2023-03-17 18:57:59 +01:00
Bram Matthys cdb36e7e30 WHOWAS: Show IP address and account to IRCOps.
Thanks to Noisytoot for https://github.com/unrealircd/unrealircd/pull/227
who suggested displaying account and provided a partial patch, and
armyn in https://bugs.unrealircd.org/view.php?id=6153 suggesting IP.

I chose to use the existing RPL_WHOIS* numerics that we also use for
returning WHOIS data. We already use RPL_WHOISSERVER in WHOWAS for
ages and the use of it is mentioned in RFC1459, so seems like that
was the idea right from the beginning of times. The only change I did
was from "is" to "was" in like "was logged in" and "was connecting from"
in the text of the numerics.
2023-03-17 18:10:46 +01:00
Bram Matthys c6c8bba311 Add find_server_by_uid() which hunts a server for the SID-portion of A UID.
Not sure if this is the best name, maybe I come up with a better one later.

The purpose of this function is so we can deliver certain messages to
pre-auth users, that is: users that are not fully registered yet.
This would mostly be used (perhaps exclusively) in SASL stage.
2023-02-08 10:10:27 +01:00
Bram Matthys dd830261db Reject a link for anope or atheme if there is no ulines { } for it.
This is checked for both local and remote services linking in.

Naturally, the list can be expanded to include more services that
really need ulines { }, and not statistical services or some other
purpose non-unrealircd servers, which is the reason why cannot
blindly assume all non-unrealircd servers require ulines.

This should hopefully help users a lot with "mysterious" issues
with services that we see too often in the support channel.
Suggested in https://bugs.unrealircd.org/view.php?id=5742

Note that this does require services to communicate their software
version via EAUTH. Anope does this for years already, but atheme only
does so since 10 days ago (git only, presumably not released yet)
after Valware filed a PR.
2023-02-08 09:02:44 +01:00
Bram Matthys 01fd2da627 ** UnrealIRCd 6.0.6 ** 2023-02-03 06:56:16 +01:00
Bram Matthys b1139769e1 Do some basic filtering on the request by default.
This ensures that strings are of maximum 510 characters in length
and do not contain \n or \r.
Solves a lot of theoretical problems in many modules that .add
things or do other non-list/non-get actions.

This behavior can be turned off per-method (per handler) by setting
handler->flags = RPC_HANDLER_FLAGS_UNFILTERED;
This is currently not done in any of the modules.
2023-01-16 10:59:41 +01:00
Bram Matthys 9e887ea728 Add LoadPersistentLongLong() / SavePersistentLongLong() 2023-01-15 14:40:04 +01:00
Bram Matthys 194a0b42f7 JSON-RPC: don't log the RPC calls if they are just for listing/getting,
since these are rather noisy and generally not very interesting to log.
Of course, DO log them if they are like add/delete/etc.

The way this works is a new property in the RPCHandler, eg:

        memset(&r, 0, sizeof(r));
        r.method = "server.list";
+       r.loglevel = ULOG_DEBUG;
        r.call = rpc_server_list;
        if (!RPCHandlerAdd(modinfo->handle, &r))

All of the .list and .get (and things like .module_list) now use
the debug facility, which is not logged by default.

You can still log ALL the JSON-RPC calls if you wish, for example
to a separate file, through something like:

log {
	source { rpc; }
	destination {
		file "rpc.log" { maxsize 100M; }
	}
}
2023-01-14 16:40:48 +01:00
Bram Matthys a1800f01e9 JSON-RPC / RRPC: Announce all RPC modules and their versions over the wire via moddata.
Needed for rrpc_supported() at a later point, so one can require certain versions etc :p
2023-01-13 18:20:40 +01:00
Bram Matthys b9fcdcdb19 Make server.rehash for remote servers use two possible code paths:
* If the remote server (and all servers in-between) support RRPC
  then forward the RPC request as RRPC and let remote handle the
  response. The response will be the verbose rehash response.
* If not supported, then simply return boolean true as a response,
  and use oldskool :source_server REHASH dest_server over the wire
2023-01-13 18:09:12 +01:00
Bram Matthys c7f9dadb68 Add JSON_RPC_ERROR_REMOTE_SERVER_NO_RPC error which indicates that the
remote server does not have the JSON-RPC module(s) loaded.

Internally this uses the "rrpc" moddata property that each server will
now set on themselves if the rpc/rpc module is loaded.

Actually I am going to make this more verbose and better later...
2023-01-13 17:43:23 +01:00
Bram Matthys a3ed1eabd9 Make client->flags 64 bit on all platforms.
We just reached the 32th bit so it is not a problem yet,
but better bump it now since I will forget otherwise :D
2023-01-13 16:56:23 +01:00
Bram Matthys b8cbe63915 Support server.rehash for remote servers with full detailed response.
(Required RPC modules to be loaded on the remote server, tho)

This adds support for remote async RPC requests that take a little longer,
in such a case we don't call free_client() upon return of rpc_call().
2023-01-13 16:51:47 +01:00
Bram Matthys cbdde31c1d Move client->local->rpc to client->rpc 2023-01-13 15:49:41 +01:00
Bram Matthys bed40ccdab JSON-RPC: RPC-over-net: track requests and handle timeouts and SQUITs.
Inform the RPC client that the request timed out / server is gone.
The timeout is fixed at 15 seconds, which is fine, I think.

New rpc error codes:
JSON_RPC_ERROR_SERVER_GONE      = -32001, /**< The request was forwarded to a remote server, but this server went gone while processing the request */
JSON_RPC_ERROR_TIMEOUT          = -32002, /**< The request was forwarded to a remote server, but the request/response timed out (15 seconds) */

Unfortunately we cannot say for sure the action did not succeed at all.
It could be that the request never reached the server, but it could also
be that the request DID reach the server and we timed out during
retrieving the response. Nothing we can do about that.
2023-01-13 15:34:00 +01:00
Bram Matthys 6a4ae9d9ec Support RPC calls to remote servers, where the RPC request/response is
sent over the IRC network. This makes it possible to fetch information
from remote servers that is not known locally, and also it makes it
possible to do more things, or do it easier.

This does require the remote servers to enable RPC as well, though,
eg: include "rpc.modules.default.conf";
(They don't need any listener or rpc-user blocks)

Code-wise it looks nice, like from rpc_server_module_list it is a simple:
/* Forward to remote */
rpc_send_request_to_remote(client, targetserver, request);

This is work in progress. In particular, there is no handling yet of
timeouts (eg if the request to the remote server, or the response
from it takes ages). Nor does it handle the case where the server
quits half-way through the request/response... that is: it does free
the request and such, but does not notify the RPC client about it.
That will need to be added, of course, likely soon.

Over the IRC network this uses the new RRPC command:
:<server> RRPC <REQ|RES> <source> <destination> <requestid> [S|C|F] :<request data>
A request looks like this (assuming it is short):
:001 RRPC REQ 001ABCDEF 002 abc SF :..this is the json request...
And then the response (assuming it is long) is like:
:001 RRPC REQ 001ABCDEF 002 abc S :..this is the json response...
:001 RRPC REQ 001ABCDEF 002 abc C :..more...
:001 RRPC REQ 001ABCDEF 002 abc C :..more...
:001 RRPC REQ 001ABCDEF 002 abc F :..and that was it.
There is currently no request/response limit, it is limited by memory.

Right now the only call using this is server.module_list when called
with a param of "server":"some.remote.server"
2023-01-13 12:45:51 +01:00
Bram Matthys a024a17e87 Add strtoken_noskip() and use it from the PROTOCTL EAUTH= code
so we can deal with empty fields that get sent f.e. by anope,
like EAUTH=services.test.net,,,Anope-2.0.11

Apparently this is similar to strsep(), or actually hypothetical
strsep_r(), a function which does not seem to exist.
2023-01-13 08:56:34 +01:00
Bram Matthys d6833ae298 JSON-RPC: add server.connect API call
(directly connected server only at the moment)
This also cleans up the linking procedure (now) at 3 places,
to use find_link() and check_deny_link() everywhere.
2023-01-11 16:54:22 +01:00
Bram Matthys a5bdf317fb JSON-RPC: begin with a server.* API, also fill client->local->rpc for
RPC clients with the RPC user and such.

Most of this work is for server.rehash which causes the request to
be saved, then a rehash begins, and a few seconds later (or whenever)
the entire rehash log and success/failure is indicated in the
JSON-RPC response.

TODO: all documentation for this
2023-01-11 15:43:50 +01:00
Bram Matthys 0244c31742 Split of some code from cmd_eline() into server_ban_exception_parse_mask(),
similar to how *LINE commands use server_ban_parse_mask().
Now used by ELINE and for JSON-RPC later...
2023-01-08 14:56:56 +01:00
Bram Matthys 243958f85a Add REQUIRE_PARAM_STRING(), REQUIRE_PARAM_BOOLEAN(),
OPTIONAL_PARAM_STRING, OPTIONAL_PARAM_BOOLEAN()
and use it everywhere in the user.* API calls.
Much cleaner now :)
2023-01-07 17:54:52 +01:00
Bram Matthys 619282397e Add json_object_get_boolean():
int json_object_get_boolean(json_t *j, const char *name, int default_value)
[skip ci]
2023-01-07 15:54:49 +01:00
Bram Matthys 4378979ad5 Add valid_username() so we can use it at multiple places.
This gets rid of duplicate code in SETIDENT, CHGIDENT, and soon
in the RPC call. It does not get rid of make_valid_username()
in src/modules/nick.c which does something slightly different.
2023-01-07 15:11:52 +01:00
Bram Matthys 5589a78255 JSON-RPC: add user.set_nick
This also makes the "forced nick change" message a bit more
generic, leaving out the "by services" or "due to Services",
since it is now possible to do it via JSON-RPC.
2023-01-07 14:53:01 +01:00
Bram Matthys 7d9dcb5e0a Allow SVS* commands to be sent by non-ulined servers by default,
this is needed by various future JSON-RPC calls.
See https://www.unrealircd.org/docs/Set_block#set::limit-svscmds
2023-01-07 14:21:31 +01:00
Bram Matthys 14107d88be Add set_channel_topic() and use it from cmd_topic (TOPIC) 2023-01-07 10:16:18 +01:00
Bram Matthys 141c4bc64d Use consts in set_channel_mode()
[skip ci]
2023-01-07 09:39:44 +01:00
Bram Matthys b33628b765 JSON-RPC over Websockets: Fix bug with >64Kb responses.
Eg if there are 10.000 users online and you do user.list.
The old websocket framing assumed no response was >64Kb.

This also creates a new function websocket_create_packet_ex()
2023-01-04 13:10:09 +01:00
Bram Matthys d6a3db4ad2 Add listener::mode so for file sockets you can specify the mode permissions.
Valid choices are 0700, 0770 and 0777, see the documentation at
https://www.unrealircd.org/docs/Listen_block

Unrelated: this also documents the ConfigItem_listen struct in struct.h.
2023-01-04 10:06:39 +01:00
Bram Matthys 64e5de4c8c ExtBanAdd: Actually enforce conv_param as a required event.
This was documented as optional in include/modules.h but on
https://www.unrealircd.org/docs/Dev:Extended_Bans_API it
was always mentioned as required.
In practice, I know of no module that does not have this,
in UnrealIRCd or third party (doing zero filtering is
quite a bad idea).

Anyway, long story short: this also means we can remove some
(flawed) logic in src/api-extban.c in case conv_param was
NULL, which raised a compiler warning:

api-extban.c: In function ‘extban_conv_param_nuh_or_extban’:
cc1: error: function may return address of local variable [-Werror=return-local-addr]
api-extban.c:382:14: note: declared here
  382 |         char tmpbuf[USERLEN + NICKLEN + HOSTLEN + 32];
      |              ^~~~~~
2023-01-01 09:51:07 +01:00
Bram Matthys 75368e462a ** UnrealIRCd 6.0.5 ** 2022-12-29 10:07:19 +01:00
Valerie Pond eda57821ec Fix compile error due to previous commit (#246) 2022-12-26 18:04:37 +00:00
Bram Matthys 895bbd3a35 When authprompt kicks in and the session timeouts, show the original ban reason
from the *LINE (or other ban type).
Eg /GLINE %*@192.168.* 0 :Please authenticate using SASL
would now, if the user has authprompt enabled and the connection times
out, exit the client after ~30 secs with "Please authenticate using SASL",
instead of "Registration timeout" (pre 6.0.5-rc2) or
the generic "Account required to login" (6.0.5-rc2).
This to help clients and users who do not type or display anything.

This is an enhancement to https://bugs.unrealircd.org/view.php?id=6202

This also fixes a bug in 6.0.5-rc2 where "Registration timeout" was
always showing up as "Account required to connect", even if there
was no softban or authprompt intervention at all.
2022-12-26 10:21:59 +01:00
Bram Matthys 7897782747 *** UnrealIRCd 6.0.5-rc2 *** 2022-12-23 08:52:41 +01:00