Commit Graph

48 Commits

Author SHA1 Message Date
Jari Sundell eb96876eb2 Moved Thread header to torrent/system directory. 2026-04-22 23:02:05 +09:00
Jari Sundell b7a21b1e9d Added support for gzip accepted_encoding in scgi headers. 2026-04-12 22:19:49 +09:00
rakshasa 21e399d099 Remove unneeded MSG_NOSIGNAL. 2026-04-06 10:48:35 +02:00
Xirvik d935e0ffe9 Address review feedback: explicit mark_safe whitelist and rpc trust flow 2026-03-23 15:11:07 +01:00
Xirvik ba239bc8c5 Address code review: fix setter exposure and narrow catch blocks
1. network.rpc.use_xmlrpc and network.rpc.use_jsonrpc: change from
   CMD2_VAR_BOOL_U (getter+setter both safe) to CMD2_VAR_BOOL_U_GET
   (getter safe, setter trusted-only). Untrusted callers could
   previously disable RPC transports entirely.

2. Remove broad catch(std::exception&) and catch(...) from xmlrpc_c.cc
   that masked real defects and altered fault semantics.

3. Revert SCGI callback catch-all to re-throw instead of swallowing
   exceptions with a generic error response.
2026-03-23 15:11:07 +01:00
Xirvik ea16276773 Fix crash on untrusted XMLRPC connections
Root cause: network.rpc.use_xmlrpc and network.rpc.use_jsonrpc were not
marked as untrusted-safe, but RpcManager::process() calls them before
dispatching to the protocol handler. When an untrusted request arrived,
call_command() threw untrusted_error for these gatekeepers, which escaped
the callback_interrupt_pollling callback and crashed rtorrent.

Fix: Mark network.rpc.use_xmlrpc/jsonrpc as safe (CMD2_VAR_BOOL_U).

Also harden exception safety:
- SCGI callback catch-all now sends a generic error response instead of
  re-throwing, since the callback infrastructure may not support
  exception propagation.
- xmlrpc_c.cc now has catch(std::exception&) and catch(...) safety nets
  after the specific exception handlers.
2026-03-23 15:11:07 +01:00
Xirvik 598914908f Add untrusted connection security infrastructure (v3)
Replace the v2 blacklist approach with a per-command flag system.
Commands must opt in to being available for untrusted connections
via flag_untrusted_safe (0x400), checked in call_command() which
catches all execution paths including nested commands.

Infrastructure changes:
- Add flag_untrusted_safe to CommandMap
- Add untrusted_error exception type for proper error codes
- Enforce trust check in both call_command() overloads
- Add catch blocks in xmlrpc_c, xmlrpc_tinyxml2, and jsonrpc handlers
- Port SCGI trust state management from v2 (thread_local, header parsing)
- Add _U macro variants in command_helpers.h for safe command registration
- Add CMD2_VAR_*_U and CMD2_VAR_*_U_GET variants for variables
2026-03-23 15:11:07 +01:00
Jari Sundell 70e6964823 Fixed various SCGI issues. 2026-03-10 23:25:28 +09:00
rakshasa 5dfb2ae938 Allow dht bootstrap nodes to be added when dht is off. 2026-03-02 09:45:09 +01:00
Jari Sundell 87666199b3 Added SocketManager to handle reuse of uninterested fd's by the kernel. 2026-01-29 04:00:31 +09:00
Jari Sundell 2fa7568165 Remove obsolete SocketFd class. 2026-01-26 19:13:03 +09:00
Jari Sundell a8b6a47054 Removed deprecated rak errno and file headers. 2026-01-04 03:22:02 +09:00
Jari Sundell 30cec98799 Moved Poll to net namespace. 2025-11-20 03:05:16 +09:00
Rosen Penev 3ab38583b8 remove __UNUSED
No need since we have C++17.

Signed-off-by: Rosen Penev <rosenp@gmail.com>
2025-06-01 08:07:37 +02:00
Rosen Penev 1003013f10 remove allocators.h
Unused.

Signed-off-by: Rosen Penev <rosenp@gmail.com>
2025-06-01 08:07:37 +02:00
Jari Sundell f0809ec29d Various pool_event_* and thread API cleanups. 2025-06-01 01:22:14 +09:00
Jari Sundell e8c1f3ed2c Update to use new this_thread::Poll(). 2025-05-31 22:22:31 +09:00
rakshasa 55615abe9e Use poll interrupting callbacks for SCGI requests. 2025-05-04 11:57:04 +02:00
rakshasa 303edab9ec Detect content type when there's multiple elements. 2025-05-04 11:28:18 +02:00
rakshasa a8622e5c80 Cleaned up thread-related code. 2025-04-12 23:03:08 +02:00
Jari Sundell 2ab7460cbc Fix SCGI threading and added missing header. 2025-04-01 01:26:07 +09:00
kannibalox 9f48226663 Add JSON-RPC capability
Inline nlohmann/json for the JSON parsing itself, and handle requests
with the same SCGI interface as XML-RPC.

Based off the work in https://github.com/jesec/rtorrent
2025-01-20 12:31:04 +01:00
stickz e3be3b2c12 scgi: Fix Apple and Solaris compatibility
This is a follow up to #1310. Apple and Solaris do not support MSG_NOSIGNAL, so disable this flag for these platforms until we find a better solution. Other platforms remain unaffected.
2024-12-14 23:34:48 +09:00
stickz b284be6a66 Resolve scgi software crash
This commit resolves a scgi software crash when the scgi socket is closed before the message can be sent. It instructs `::send()` not to send a SIGPIPE termination signal. Instead the value -1 is returned and handled bellow. The SCgiTask is closed and a new one is sent to complete the task.

```
Thread 3 "rtorrent scgi" received signal SIGPIPE, Broken pipe.
                                                             [Switching to Thread 0x7fffe635c6c0 (LWP 2443872)]
0x00007ffff7929a84 in send () from /lib/x86_64-linux-gnu/libc.so.6
```
2024-10-29 22:42:33 +09:00
rakshasa d396c8e058 Changed rpc log types. 2014-04-25 19:55:47 +09:00
rakshasa 639af87e53 Use new logging API. 2012-02-21 15:37:50 +09:00
rakshasa 1b4d8f9626 Removed old thread test code. 2012-02-16 15:08:30 +09:00
Jari Sundell e11be5cdbe Fixed some compile issues. 2011-11-22 16:46:59 +09:00
rakshasa 4d313e6353 Updated copyright information.
git-svn-id: svn://rakshasa.no/libtorrent/trunk/rtorrent@1301 e378c898-3ddf-0310-93e7-cc216c733640
2011-10-09 06:30:14 +00:00
rakshasa 4914d798f1 * Changing push_log calls to the new logging facility.
git-svn-id: svn://rakshasa.no/libtorrent/trunk/rtorrent@1284 e378c898-3ddf-0310-93e7-cc216c733640
2011-09-21 05:07:06 +00:00
rakshasa 18a6c61956 * Fixed a corner-case where initial seeding would end up crashing rtorrent.
* Fixed a bad conditional that would result in write syscall being called with -1 for logging executing external commands.


git-svn-id: svn://rakshasa.no/libtorrent/trunk/rtorrent@1201 e378c898-3ddf-0310-93e7-cc216c733640
2011-04-06 09:59:54 +00:00
rakshasa 0e69677dbc * Added xmlrpc calls for peer snubbed, banned and disconnect.
git-svn-id: svn://rakshasa.no/libtorrent/trunk/rtorrent@1180 e378c898-3ddf-0310-93e7-cc216c733640
2010-10-08 08:10:08 +00:00
rakshasa 74bae32243 * Fixed more redirected commands.
* Cleaned up the Command stack implementation.

* Added framework for object_storage class that will hold variables and user-defined command lists.


git-svn-id: svn://rakshasa.no/libtorrent/trunk/rtorrent@1162 e378c898-3ddf-0310-93e7-cc216c733640
2010-04-11 14:19:27 +00:00
rakshasa 588f9e80c7 * Threaded XMLRPC support. Sponsored by Xirvik.
git-svn-id: svn://rakshasa.no/libtorrent/trunk/rtorrent@1123 e378c898-3ddf-0310-93e7-cc216c733640
2010-01-25 13:14:09 +00:00
rakshasa b635f8c852 * More work on threading.
git-svn-id: svn://rakshasa.no/libtorrent/trunk/rtorrent@1112 e378c898-3ddf-0310-93e7-cc216c733640
2009-12-12 21:30:52 +00:00
rakshasa 667c4c3562 * Created ThreadBase holding poll manager, etc, and added a this_thread global object.
* Cleaned up main initialization, SCGI and polling code.

* Fixed a bug that would cause reading of a piece to hang if the incoming data contains only data up to the file boundary, but not the next file's data. The bug did not trigger if the file boundary and piece boundaries were the same.


git-svn-id: svn://rakshasa.no/libtorrent/trunk/rtorrent@1101 e378c898-3ddf-0310-93e7-cc216c733640
2009-11-12 09:28:35 +00:00
rakshasa a60c330d3b * Logging for scgi calls.
git-svn-id: svn://rakshasa.no/libtorrent/trunk/rtorrent@1100 e378c898-3ddf-0310-93e7-cc216c733640
2009-10-27 15:11:32 +00:00
rakshasa 63af7078a3 * Include locally available chunks in the "chunks seen" statistics for completed/distributed copies. Patch by Josef Drexler.
* Added 'd.get_bitfield' command for retrieving the bitfield in hex format. Patch by Thomas Rosner. (PD)

* Fixed include headers for gcc-4.4.0. Patch by 'kloeri'.

* Switched a 'long long' with 'int64_t' in xmlrpc.cc to avoid incompatible types for some systems.


git-svn-id: svn://rakshasa.no/libtorrent/trunk/rtorrent@1092 e378c898-3ddf-0310-93e7-cc216c733640
2009-05-14 13:07:47 +00:00
rakshasa 3ddd04a9a5 * Fixed another bug in scgi_tast.cc.
git-svn-id: svn://rakshasa.no/libtorrent/trunk/rtorrent@1053 e378c898-3ddf-0310-93e7-cc216c733640
2008-04-16 10:58:04 +00:00
rakshasa 12b43d78a3 * Fixed a potential leak in scgi_task.cc.
* Removed std:: from snprintf in window_file_list.cc.


git-svn-id: svn://rakshasa.no/libtorrent/trunk/rtorrent@1052 e378c898-3ddf-0310-93e7-cc216c733640
2008-04-15 11:50:14 +00:00
rakshasa 32b74ffc48 * Proper fault handling for bad SCGI requests.
* Cleaned up duplicate code in 'xmlrpc.cc'.

* Cleaned up 'parse_commands.h'.


git-svn-id: svn://rakshasa.no/libtorrent/trunk/rtorrent@966 e378c898-3ddf-0310-93e7-cc216c733640
2007-08-27 23:00:48 +00:00
rakshasa 11976871ac * Dynamically sized SCGI read buffer.
* Added 'call_command' that takes a view as the first parameter and
then a list of commands. It will return a list of lists containing the
results from those commands.

* Fixed the xmlrpc-c-config usage.


git-svn-id: svn://rakshasa.no/libtorrent/trunk/rtorrent@954 e378c898-3ddf-0310-93e7-cc216c733640
2007-08-15 21:38:44 +00:00
rakshasa 7d0be56c83 * Set the content type to text/xml in XMLRPC replies.
* Fixed a compile error when using xmlrpc-c >= 1.07.

* Added various download commands for getting torrent sizes, peers,
etc.


git-svn-id: svn://rakshasa.no/libtorrent/trunk/rtorrent@940 e378c898-3ddf-0310-93e7-cc216c733640
2007-07-20 18:05:17 +00:00
rakshasa 535db16850 * Bumping copyright year to 2007.
git-svn-id: svn://rakshasa.no/libtorrent/trunk/rtorrent@938 e378c898-3ddf-0310-93e7-cc216c733640
2007-07-19 21:29:34 +00:00
rakshasa 13dc0c942a * Allow binding of the SCGI socket to a specific address, and added
"scgi_dont_route" variable.


git-svn-id: svn://rakshasa.no/libtorrent/trunk/rtorrent@908 e378c898-3ddf-0310-93e7-cc216c733640
2007-05-23 21:47:11 +00:00
rakshasa bebce18368 * Added "http_ca{path/cert}" options. Patch by Johan Gunnarsson,
public domain.

* Minor bugfixes to SCgi.


git-svn-id: svn://rakshasa.no/libtorrent/trunk/rtorrent@907 e378c898-3ddf-0310-93e7-cc216c733640
2007-05-23 14:03:02 +00:00
rakshasa 2db205a89d * Added support for named pipes and proper parseing of arguments for
SCGI.


git-svn-id: svn://rakshasa.no/libtorrent/trunk/rtorrent@906 e378c898-3ddf-0310-93e7-cc216c733640
2007-05-21 01:51:52 +00:00
rakshasa 5f274b2619 * Added support for SCGI rpc calls.
git-svn-id: svn://rakshasa.no/libtorrent/trunk/rtorrent@905 e378c898-3ddf-0310-93e7-cc216c733640
2007-05-20 17:30:00 +00:00