1
0
mirror of https://github.com/unrealircd/unrealircd.git synced 2026-06-30 09:06:37 +02:00
Commit Graph

2882 Commits

Author SHA1 Message Date
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 3666d1d728 JSON-RPC: Add some more sanity checking on the 'id'
(Mainly because the id might be used in RRPC)
2023-01-16 11:10:47 +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 bdb5541def minor code cleanup (do things the libjansson way..) 2023-01-16 10:38:54 +01:00
Bram Matthys 1d1766a895 Send buildid in server version in EAUTH/SINFO and in server.* JSON-RPC.
This reveals the full git version.
2023-01-15 10:13:16 +01:00
Bram Matthys 462ce7fcfa JSON-RPC: add stats.get call which can be used in "Network Overview" in
UnrealIRCd Admin panel and for other statistical purposes.
This can be expanded when needed.
2023-01-14 18:48:18 +01:00
Bram Matthys 2fcddd1655 JSON-RPC: Send 401 error response on invalid auth (instead of lingering the connection). 2023-01-14 17:18:00 +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 58db5b0845 Fix crash in JSON-RPC. Reported by multiple people past few days,
including Lord255, armyn and others.
The issue was not there when running with ASan, which is why it
was non-reproducible for so long. Valgrind picked it up correctly.

The bug was that in rpc_response() and rpc_error() I do:
id = json_object_get(request, "id");
[..]
json_object_set_new(j, "id", id);

which is wrong, since json_object_get() "borrows the reference"
and json_object_set_new "steals the reference".
In this particular case it should be:
json_object_set(j, "id", id);

Fixed in both functions. Would have to audit the code if the mistake
is made elsewhere too though. On first sight, it seems not.
2023-01-14 10:36:54 +01:00
Bram Matthys 53150c0e68 Fix double-wrapping of JSON reply for remote RPC (RRPC) calls such as
server.module_list and server.rehash for remote servers.
Reported by Valware.
2023-01-14 09:10:32 +01:00
Bram Matthys 405b59eb07 JSON-RPC: server.list/server.add: new property server->features->rpc_modules
This is an array with name/version elements, eg server.list or.get look like:
      {
        "name": "testlink.test.net",
        "server": {
          "features": {
            "rpc_modules": [
              {
                "name": "rpc",
                "version": "1.0.2"
              },
              {
                "name": "user",
                "version": "1.0.5"
              },
etc. etc.
2023-01-13 19:42:20 +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 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 e2ef83bd6e Fix crash on REHASH 2023-01-13 15:57:45 +01:00
Bram Matthys cbdde31c1d Move client->local->rpc to client->rpc 2023-01-13 15:49:41 +01:00
Bram Matthys 16e4990f83 Fix memory leaks created in commit from 15 minutes ago 2023-01-13 15:45:12 +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 07d2b6745b JSON-RPC: add server.module_list - only works for locally connected server atm 2023-01-13 09:46:02 +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 aa2d3c026e JSON-RPC: add server.disconnect 2023-01-11 17:08: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 0578346b12 Make server.rehash work for remote servers too, just no real status atm. 2023-01-11 16:24:50 +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 c5d8bc5d9b Fix ~account:* matching both logged in and logged out users (so quite useless).
This bug exists since 5.2.1 already, so i guess the functionality is
not used much ;). Makes sense, since for simple ~account:* you have +R already,
so it is only useful in stacked bans such as +e ~nickchange:~account:*

We now have a test case so that this bug won't "ever" reoccur.

Reported by rafaelgrether in https://bugs.unrealircd.org/view.php?id=6211
2023-01-09 09:00:58 +01:00
Bram Matthys 5897ce3aad Version bump various modules.
[skip ci]
2023-01-08 15:50:25 +01:00
Bram Matthys 35c49108df JSON-RPC: Add optional "set_by" field when adding/removing TKL's,
so in name_ban, server_ban, server_ban_exception and spamfilter.

This could be used, for example, by an admin panel to tell which
end-user that authenticated to the panel (eg 'OperX') added/removed
the TKL, instead of showing up as 'RPC:xyz' in the logs and bans.
2023-01-08 15:43:00 +01:00
Bram Matthys ed8a3f0336 JSON-RPC add server_ban_exception.* API calls
Docs: https://www.unrealircd.org/docs/JSON-RPC:Server_ban_exception
2023-01-08 15:35:08 +01:00
Bram Matthys d0ad776e93 Minor code cleanup (move error out of params into local vars,
as it didn't belong there..)
[skip ci]
2023-01-08 15:03:18 +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 c95e3f249e JSON-RPC: add name_ban.list, name_ban.get, name_ban.add, name_ban.del 2023-01-08 09:56:41 +01:00
Bram Matthys 5db86cb442 Fix crash in server_ban.* when using non-serverban types such as
qlines and exceptions (for which no interface exists yet, btw :D).
2023-01-08 09:20:12 +01:00
Bram Matthys 9d04710e3a In DEBUGMODE allow for verbose rpc logging with request/responses.
(And also fix a logging statement that had the wrong category)

log {
        source {
                rpc.debug;
        }
        destination {
                file "rpc.log" { maxsize 100M; }
        }
}
2023-01-08 09:02:01 +01:00
Bram Matthys 20d1487922 JSON-RPC: add channel.kick, update struct initalization,
and use REQUIRE_PARAM_* and OPTIONAL_PARAM_* everywhere
in the channel.* API handlers.

For docs see:
https://www.unrealircd.org/docs/JSON-RPC:Channel
2023-01-07 19:05:05 +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 fb96e4581b JSON-RPC: add user.part and slightly change user.join
the option is now called 'force':true for consistency.

Docs updated:
https://www.unrealircd.org/docs/JSON-RPC:User#user.part
https://www.unrealircd.org/docs/JSON-RPC:User#user.join
2023-01-07 17:38:38 +01:00
Bram Matthys 046c8654c6 JSON-RPC: add user.join, which uses SVSJOIN (normal join) or SAJOIN (bypass
all channel restrictions).
See https://www.unrealircd.org/docs/JSON-RPC:User#user.join
2023-01-07 17:31:33 +01:00
Bram Matthys 884cc7f04d JSON-RPC: add user.quit. The difference between that and user.kill
is explained at https://www.unrealircd.org/docs/JSON-RPC:User
2023-01-07 16:57:48 +01:00
Bram Matthys 6a2a8e798b JSON-RPC: add user.kill 2023-01-07 16:48:41 +01:00
Bram Matthys 9d65b8a4ed Use better defaults in user.set_oper
Already documented at https://www.unrealircd.org/docs/JSON-RPC:User#user.set_oper
2023-01-07 16:41:52 +01:00
Bram Matthys aef8611f91 Change SVSO to use the prefix "remote:<name>" instead of "services:<name>"
because it can be used by JSON-RPC now and this fits for both :D.
2023-01-07 16:19:17 +01:00
Bram Matthys e7615210a7 JSON-RPC: add user.set_oper
[skip ci]
2023-01-07 16:18:47 +01:00
Bram Matthys 541eba0670 JSON-RPC: add user.set_mode & user.set_snomask 2023-01-07 15:59:52 +01:00
Bram Matthys 9898d332ab JSON-RPC: add user.set_vhost 2023-01-07 15:30:08 +01:00
Bram Matthys 318d183f23 JSON-RPC: add user.set_username and user.set_realname 2023-01-07 15:23:34 +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 a9d0c6fd1a JSON-RPC: make channel.set_mode and channel.set_topic return just result:true.
I don't think it should return the whole channel struct here as if it
was a channel.get. Only thing is that, especially or only with set_mode,
it may actually be 100% success... eg if your mode line is wrong :D.

Also bump API versions on user.* and channel.*
2023-01-07 14:58:00 +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