From 307fb0708efd6e84aec5836819a2dfb318b97f5c Mon Sep 17 00:00:00 2001 From: darosior Date: Thu, 18 Jul 2019 15:32:48 +0200 Subject: [PATCH] lightningd/plugin_control: don't control non-dynamic plugins --- lightningd/plugin_control.c | 4 ++++ tests/plugins/static.py | 25 +++++++++++++++++++++++++ tests/test_plugin.py | 7 +++++++ 3 files changed, 36 insertions(+) create mode 100755 tests/plugins/static.py diff --git a/lightningd/plugin_control.c b/lightningd/plugin_control.c index e4461f2e1..89393d557 100644 --- a/lightningd/plugin_control.c +++ b/lightningd/plugin_control.c @@ -39,6 +39,10 @@ static struct command_result *json_plugin_control(struct command *cmd, plugin_found = false; list_for_each(&cmd->ld->plugins->plugins, p, list) { if (plugin_paths_match(p->cmd, plugin_name)) { + if (!p->dynamic) + return command_fail(cmd, JSONRPC2_INVALID_PARAMS, + "%s plugin cannot be managed when lightningd is up", + plugin_name); plugin_found = true; plugin_hook_unregister_all(p); plugin_kill(p, "%s stopped by lightningd via RPC", diff --git a/tests/plugins/static.py b/tests/plugins/static.py new file mode 100755 index 000000000..ff89eeffc --- /dev/null +++ b/tests/plugins/static.py @@ -0,0 +1,25 @@ +#!/usr/bin/env python3 +"""Simple plugin to test the dynamic behavior. + +A plugin started with dynamic to False cannot be controlled after lightningd +has been started. +""" + +from lightning import Plugin + +plugin = Plugin(dynamic=False) + + +@plugin.init() +def init(configuration, options, plugin): + plugin.log("Static plugin initialized.") + + +@plugin.method('hello') +def reject(plugin): + """Mark a given node_id as reject for future connections. + """ + return "Hello, you cannot stop me without stopping lightningd" + + +plugin.run() diff --git a/tests/test_plugin.py b/tests/test_plugin.py index e13154a3d..42023bd44 100644 --- a/tests/test_plugin.py +++ b/tests/test_plugin.py @@ -130,6 +130,13 @@ def test_plugin_command(node_factory): cmd = [hlp for hlp in n.rpc.help()["help"] if "hello" in hlp["command"]] assert(len(cmd) == 0) + # Test that we cannot stop a plugin with 'dynamic' set to False in + # getmanifest + n.rpc.plugin_start(plugin=os.path.join(os.getcwd(), "tests/plugins/static.py")) + n.daemon.wait_for_log(r"Static plugin initialized.") + with pytest.raises(RpcError, match=r"plugin cannot be managed when lightningd is up"): + n.rpc.plugin_stop(plugin="static.py") + def test_plugin_disable(node_factory): """--disable-plugin works"""