| 1011 | } |
| 1012 | |
| 1013 | static struct command_result *json_checkrune(struct command *cmd, |
| 1014 | const char *buffer, |
| 1015 | const jsmntok_t *obj UNNEEDED, |
| 1016 | const jsmntok_t *params) |
| 1017 | { |
| 1018 | const jsmntok_t *methodparams; |
| 1019 | struct cond_info cinfo; |
| 1020 | struct rune_and_string *ras; |
| 1021 | struct node_id *nodeid; |
| 1022 | struct json_stream *js; |
| 1023 | const char *err, *method; |
| 1024 | |
| 1025 | if (!param(cmd, buffer, params, |
| 1026 | p_req("rune", param_rune, &ras), |
| 1027 | p_opt("nodeid", param_node_id, &nodeid), |
| 1028 | p_opt("method", param_string, &method), |
| 1029 | p_opt("params", param_params, &methodparams), |
| 1030 | NULL)) |
| 1031 | return command_param_failed(); |
| 1032 | |
| 1033 | if (is_rune_blacklisted(cmd->ld->runes, ras->rune)) |
| 1034 | return command_fail(cmd, RUNE_BLACKLISTED, "Not authorized: Blacklisted rune"); |
| 1035 | |
| 1036 | cinfo.runes = cmd->ld->runes; |
| 1037 | cinfo.peer = nodeid; |
| 1038 | cinfo.buf = buffer; |
| 1039 | cinfo.method = canonical_method(method); |
| 1040 | cinfo.params = methodparams; |
| 1041 | cinfo.now = clock_time(); |
| 1042 | strmap_init(&cinfo.cached_params); |
| 1043 | |
| 1044 | err = rune_is_ours(cmd->ld, ras->rune); |
| 1045 | if (err) { |
| 1046 | return command_fail(cmd, RUNE_NOT_AUTHORIZED, "Not authorized: %s", err); |
| 1047 | } |
| 1048 | |
| 1049 | err = rune_test(tmpctx, cmd->ld->runes->master, ras->rune, check_condition, &cinfo); |
| 1050 | strmap_clear(&cinfo.cached_params); |
| 1051 | |
| 1052 | /* Just in case they manage to make us speak non-JSON, escape! */ |
| 1053 | if (err) { |
| 1054 | err = json_escape(tmpctx, err)->s; |
| 1055 | |
| 1056 | /* Turn runespeak into english! */ |
| 1057 | if (strstarts(err, "pname")) |
| 1058 | err = tal_strcat(tmpctx, "parameter ", err + strlen("pname")); |
| 1059 | else if (strstarts(err, "parr")) |
| 1060 | err = tal_strcat(tmpctx, "parameter #", err + strlen("parr")); |
| 1061 | else if (strstarts(err, "pnum")) |
| 1062 | err = tal_strcat(tmpctx, "number of parameters", err + strlen("pnum")); |
| 1063 | else if (strstarts(err, "pinv")) |
| 1064 | err = tal_strcat(tmpctx, "invoice parameter ", err + strlen("pinv")); |
| 1065 | return command_fail(cmd, RUNE_NOT_PERMITTED, "Not permitted: %s", err); |
| 1066 | } |
| 1067 | |
| 1068 | if (tal_count(ras->rune->restrs) > 1 |
| 1069 | && relists_runes(buffer, method, methodparams)) |
| 1070 | return command_fail(cmd, RUNE_NOT_PERMITTED, |
nothing calls this directly
no test coverage detected