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

815 Commits

Author SHA1 Message Date
Bram Matthys 2fcb5b4669 * Server to server lines can now be 16384 bytes in size when
`PROTOCTL BIGLINES` is set. This will allow us to do things more
  efficiently and possibly raise some other limits in the future.
  This 16k is the size of the complete line, including sender,
  message tags, content and \r\n. Also, in server-to-server traffic
  we now allow 30 parameters (MAXPARA*2).
  The original input size limits for non-servers remain the same: the
  complete line can be 4k+512, with the non-mtag portion limit set
  at 512 bytes (including \r\n), and MAXPARA is still 15 as well.
* I chose 16k because I don't want to first raise it to like 8k
  and then realize later that 16k would be better and raise it again.
* To receive BIGLINES in a command, you need to `CommandAdd()` with
  flags `CMD_BIGLINES`, without it you still get regular 512 max.
  This is so, because a lot of the code does not expect longer than
  512 bytes lines or in parameters, so we can gradually change that
  (where needed).
2023-05-28 15:06:32 +02:00
Bram Matthys 55670c5865 Fix memory leak created today on REHASH (free the proxy blocks) 2023-05-26 16:41:02 +02:00
Bram Matthys cf5808dc44 Error on listen::options::websocket::forward and tell to use proxy { } block.
[skip ci]
2023-05-26 14:36:20 +02:00
Bram Matthys fb54d4a2c6 Replace do_parse_forwarded_header() and set WEB(client)->forwarded
depending on what we get from the proxy, so it can be used later
in the websocket module for setting the user secure or not
(the latter similar to what k4be already did in the old code).
2023-05-26 13:31:01 +02:00
Bram Matthys c537a72c10 Make proxy::mask and webirc::mask a generic mask item almost all
others in the config - https://www.unrealircd.org/docs/Mask_item
2023-05-26 12:39:11 +02:00
Bram Matthys 9aafdb7f9c Move handling of webirc { } block into new proxy { } block (allow the old name)
This is untested, as I'm first working on the rest...
2023-05-26 12:23:51 +02:00
Bram Matthys 52472a9a88 Add support for set unknown-users { } and the like:
It is now possible to override some set settings per-security group by
having a set block with a name, like `set unknown-users { }`
* You could use this to set more limitations for unknown-users:
  ```
  set unknown-users {
          max-channels-per-user 5;
          static-quit "Quit";
          static-part yes;
  }
  ```
* Or to set higher values (higher than the normal set block)
  for trusted users:
  ```
  security-group trusted-bots {
          account { BotOne; BotTwo; }
  }
  set trusted-bots {
          max-channels-per-user 25;
  }
  ```
* Currently the following settings can be used in a set xxx { } block:
  set::auto-join, set::modes-on-connect, set::restrict-usermodes,
  set::max-channels-per-user, set::static-quit, set::static-part.
2023-05-22 12:07:43 +02:00
Bram Matthys 3652940c2c Add set::anti-flood::<secgroup>::max-channels-per-user setting to override
the default set::max-channels-per-user (also called set::maxchannelsperuser).

This way you can give known-users a higher max-channels-per-user,
or even a special security group for trusted users (that you may
already have given a more lax flood setting and lower lag-penalty
etc. etc. so that fits in nicely)

And yeah this also:
* Makes it both in set and the anti-flood block accept both
  maxchannelsperuser and max-channels-per-user.
* Removes old MAXCHANNELS= in 005, as we already have CHANLIMIT=
This does not:
* Re-announce the 005 CHANLIMIT= if someone transitions from a security
  group with a different max-channels-per-user. We don't do that for
  IRCOps either, and I think no IRCd does that actually...
  To be honest i wonder if sending the limit in 005 is useful at all,
  do client really track this and limit their GUI based on it?? Doubt it!
2023-05-19 21:47:23 +02:00
Bram Matthys 9b9434e442 Delay throttling check until IP is resolved or failed to resolve.
This so you can use throttling exceptions (eg in ELINE) on hostnames.

That is, the above is during normal circumstances. Similar to previous
commit we will turn this feature of during high connection rates.
That is a TODO item.
2023-05-18 11:51:22 +02:00
Bram Matthys 89075e532a Send throttling and some other error messages to SSL/TLS users (encrypted).
This is the start of "be more friendly to TLS users with disconnect
error messages" from https://bugs.unrealircd.org/view.php?id=5532

As that bug explains:
Consider doing the SSL/TLS handshake even for throttling errors and such
when the (reject) connection rate is below a certain amount per second.  If
it is higher than a certain rate, then fall back to the original behavior to
reject the user instantly without handshake or looking at any data.
Rationale: the current/original behavior is there so the ircd can handle
floods, both in terms of traffic and in terms of CPU usage (the SSL/TLS
handshake is quite costly after all).  The downside of the current behavior
is that TLS users don't see the error message, usually.  This feature
request tries to find a middle ground.

Still a TODO item:
* We don't detect high rates yet, so we only do this new behavior atm
  and not yet the old behavior during high connection rates.
* Verify that error messages/behavior hasn't changed (too) much,
  like the throttling and the banning disconnect messages.
2023-05-18 11:17:37 +02:00
Bram Matthys 40bdef6cd9 Make exceeds_maxperip() use a hash table (performance improvement) 2023-05-17 19:44:10 +02:00
Bram Matthys 0874e376bc Add LineCache which is used when sending a message to a channel.
When sending to channel members this will cache full IRC protocol
lines, including message tags and \r\n, for similar clients.
This avoid the need for many mtags_to_string() calls and also
entire parts of sendbuf_to_one() can be skipped as well.
The "Similar clients" cache entries are defined as clients that:
1) Are of the same type: normal local client, ircop local client
   or remote client.
2) Have the same CAPs set, that is: we only look at CAPs that actually
   have anything to do with message tags ('clicaps_affecting_mtag')
3) Optionally there can be an explicit line_opts. It is not used yet
   but could be used when there are different type of lines sent
   depending on other criteria, such as chanop status or something
   else that doesn't fit in #1 and #2.
2023-05-15 15:27:52 +02:00
Bram Matthys d48ccb1ec8 When rpc.modules.default.conf is loaded, remember last 1000 lines of log
entries for a maximum of 7 days, in memory.
[skip ci]
2023-05-05 12:16:54 +02:00
Bram Matthys 4b448f2aaa New option listen::spoof-ip, only valid when using UNIX domain sockets
(so listen::file). This way you can override the IP address that users come
online with when they use the socket (default was and still is `127.0.0.1`).

Add a new guide https://www.unrealircd.org/docs/Running_Tor_hidden_service_with_UnrealIRCd
which uses the new listen::spoof-ip and optionally requires a services account.
2023-04-15 10:37:30 +02:00
Bram Matthys 7ad160f57a JSON-RPC: WHOWAS fetching is now whowas.get, also expose not only
logon_time/logoff_time but also connected_since.

This also fixes the Makefile for the Windows build (i hope)
2023-04-15 09:24:57 +02:00
Bram Matthys 2184f38e7e Expose more WHOWAS fields in JSON-RPC and change add_history() to take a reason
for the add, like: nick-change, quit, server terminating. Add logon time.

I also think i will move from user.get_whowas to a whowas.XXX since the
returned object is not a user object and getting more different each commit :D.
2023-04-15 09:00:06 +02:00
Bram Matthys 7c22f37a9f JSON-RPC: add log.subscribe and log.unsubscribe
https://www.unrealircd.org/docs/JSON-RPC:Log
2023-04-08 17:56:59 +02:00
Bram Matthys a3c151a16a RPC: add rpc.set_issuer, eg set to logged in user on the admin panel.
This so UnrealIRCd knows who is issuing the commands.
This information is then passed on to unrealircd.org/issued-by and
is planned to be used by the logging system too.

https://www.unrealircd.org/docs/JSON-RPC:Rpc#rpc.set_issuer
2023-03-31 12:55:31 +02:00
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 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 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 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 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 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 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 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 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 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 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 dc55c3ec9f Add CALL_CMD_FUNC(cmd_func_name) and use it.
This is only for calls within the same module, as otherwise you
should use do_cmd().

Benefit of this way is that it is short and you don't have to worry
about passing the right command parameters, which may change over time.
Example as used in src/modules/nick.c:
-               cmd_nick_remote(client, recv_mtags, parc, parv);
+               CALL_CMD_FUNC(cmd_nick_remote);
2022-08-28 09:04:12 +02:00
Bram Matthys 7c8918e22d Update rpc_error() to use JsonRpcError (enum) and add more error values. 2022-06-20 19:02:52 +02:00
Bram Matthys b38b0f5086 Set loop.config_state to one of CONFIG_STATE_* so modules (and core)
can track at what step we are during configuration file and module
processing.
2022-06-20 12:54:22 +02:00
Bram Matthys c24a8e43e3 Fix outdated doxygen information on 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 0eb42155dd Limit request body to 4k by default. 2022-06-19 13:13:33 +00:00
Bram Matthys 467e3d847a Handle chunked encoding in webserver (mostly meant for RPC). 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 5e81a6ee67 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.
2022-06-19 13:13:33 +00:00
Bram Matthys df8c5cfd76 Add ability to skip connect-flood and zlined checks via listener->options
with LISTENER_NO_CHECK_CONNECT_FLOOD and LISTENER_NO_CHECK_ZLINED.
2022-06-19 13:13:33 +00:00
Bram Matthys a09d4a7e88 Add CLIENT_STATUS_RPC and add SetRPC() and IsRPC(). 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