Skip to content

Commit

Permalink
reckless-rpc: accept and pass generic subcommands
Browse files Browse the repository at this point in the history
This allows generic subcommands to be passed to reckless-rpc along with
the target to search/install/etc..  These commands are unvalidated so
far and may crash the reckless process.

Changelog-Added: reckless-rpc plugin: issue commands to reckless over rpc.
  • Loading branch information
endothermicdev committed Jul 31, 2024
1 parent b51424d commit ecb4a3f
Showing 1 changed file with 23 additions and 15 deletions.
38 changes: 23 additions & 15 deletions plugins/recklessrpc.c
Original file line number Diff line number Diff line change
Expand Up @@ -163,9 +163,11 @@ static struct io_plan *stderr_conn_init(struct io_conn *conn,
}

static struct command_result *reckless_call(struct command *cmd,
const char *call)
const char *subcommand,
const char *target,
const char *target2)
{
if (!call)
if (!subcommand || !target)
return command_fail(cmd, PLUGIN_ERROR, "invalid reckless call");
char **my_call;
my_call = tal_arrz(tmpctx, char *, 0);
Expand All @@ -180,8 +182,10 @@ static struct command_result *reckless_call(struct command *cmd,
tal_arr_expand(&my_call, "--conf");
tal_arr_expand(&my_call, lconfig.config);
}
tal_arr_expand(&my_call, "search");
tal_arr_expand(&my_call, (char *) call);
tal_arr_expand(&my_call, (char *) subcommand);
tal_arr_expand(&my_call, (char *) target);
if (target2)
tal_arr_expand(&my_call, (char *) target2);
tal_arr_expand(&my_call, NULL);
struct reckless *reckless;
reckless = tal(NULL, struct reckless);
Expand Down Expand Up @@ -212,17 +216,21 @@ static struct command_result *reckless_call(struct command *cmd,
return command_still_pending(cmd);
}

static struct command_result *json_search(struct command *cmd,
const char *buf,
const jsmntok_t *params)
static struct command_result *json_reckless(struct command *cmd,
const char *buf,
const jsmntok_t *params)
{
const char *search_target;
const char *subcommand;
const char *target;
const char *target2;
/* Allow check command to evaluate. */
if (!param(cmd, buf, params,
p_req("plugin", param_string, &search_target),
p_req("subcommand", param_string, &subcommand),
p_req("target/subcommand2", param_string, &target),
p_opt("target", param_string, &target2),
NULL))
return command_param_failed();
return reckless_call(cmd, search_target);
return reckless_call(cmd, subcommand, target, target2);
}

static const char *init(struct plugin *p,
Expand Down Expand Up @@ -253,11 +261,11 @@ static const char *init(struct plugin *p,

static const struct plugin_command commands[] = {
{
"reckless-search", /* Name */
"reckless", /* Category */
"ask reckless to search for a plugin", /* Descr */
"long description here", /* Long descr */
json_search, /* Command pointer */
"reckless",
"utility",
"Issue a command to the reckless utility.",
"",
json_reckless,
},
};

Expand Down

0 comments on commit ecb4a3f

Please sign in to comment.