Skip to content

Commit ecb4a3f

Browse files
reckless-rpc: accept and pass generic subcommands
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.
1 parent b51424d commit ecb4a3f

File tree

1 file changed

+23
-15
lines changed

1 file changed

+23
-15
lines changed

plugins/recklessrpc.c

Lines changed: 23 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -163,9 +163,11 @@ static struct io_plan *stderr_conn_init(struct io_conn *conn,
163163
}
164164

165165
static struct command_result *reckless_call(struct command *cmd,
166-
const char *call)
166+
const char *subcommand,
167+
const char *target,
168+
const char *target2)
167169
{
168-
if (!call)
170+
if (!subcommand || !target)
169171
return command_fail(cmd, PLUGIN_ERROR, "invalid reckless call");
170172
char **my_call;
171173
my_call = tal_arrz(tmpctx, char *, 0);
@@ -180,8 +182,10 @@ static struct command_result *reckless_call(struct command *cmd,
180182
tal_arr_expand(&my_call, "--conf");
181183
tal_arr_expand(&my_call, lconfig.config);
182184
}
183-
tal_arr_expand(&my_call, "search");
184-
tal_arr_expand(&my_call, (char *) call);
185+
tal_arr_expand(&my_call, (char *) subcommand);
186+
tal_arr_expand(&my_call, (char *) target);
187+
if (target2)
188+
tal_arr_expand(&my_call, (char *) target2);
185189
tal_arr_expand(&my_call, NULL);
186190
struct reckless *reckless;
187191
reckless = tal(NULL, struct reckless);
@@ -212,17 +216,21 @@ static struct command_result *reckless_call(struct command *cmd,
212216
return command_still_pending(cmd);
213217
}
214218

215-
static struct command_result *json_search(struct command *cmd,
216-
const char *buf,
217-
const jsmntok_t *params)
219+
static struct command_result *json_reckless(struct command *cmd,
220+
const char *buf,
221+
const jsmntok_t *params)
218222
{
219-
const char *search_target;
223+
const char *subcommand;
224+
const char *target;
225+
const char *target2;
220226
/* Allow check command to evaluate. */
221227
if (!param(cmd, buf, params,
222-
p_req("plugin", param_string, &search_target),
228+
p_req("subcommand", param_string, &subcommand),
229+
p_req("target/subcommand2", param_string, &target),
230+
p_opt("target", param_string, &target2),
223231
NULL))
224232
return command_param_failed();
225-
return reckless_call(cmd, search_target);
233+
return reckless_call(cmd, subcommand, target, target2);
226234
}
227235

228236
static const char *init(struct plugin *p,
@@ -253,11 +261,11 @@ static const char *init(struct plugin *p,
253261

254262
static const struct plugin_command commands[] = {
255263
{
256-
"reckless-search", /* Name */
257-
"reckless", /* Category */
258-
"ask reckless to search for a plugin", /* Descr */
259-
"long description here", /* Long descr */
260-
json_search, /* Command pointer */
264+
"reckless",
265+
"utility",
266+
"Issue a command to the reckless utility.",
267+
"",
268+
json_reckless,
261269
},
262270
};
263271

0 commit comments

Comments
 (0)