| 913 | } |
| 914 | |
| 915 | static struct command_result *json_checkrune(struct command *cmd, |
| 916 | const char *buffer, |
| 917 | const jsmntok_t *obj UNNEEDED, |
| 918 | const jsmntok_t *params) |
| 919 | { |
| 920 | const jsmntok_t *methodparams; |
| 921 | struct cond_info cinfo; |
| 922 | struct rune_and_string *ras; |
| 923 | struct node_id *nodeid; |
| 924 | struct json_stream *js; |
| 925 | const char *err, *method; |
| 926 | |
| 927 | if (!param(cmd, buffer, params, |
| 928 | p_req("rune", param_rune, &ras), |
| 929 | p_opt("nodeid", param_node_id, &nodeid), |
| 930 | p_opt("method", param_string, &method), |
| 931 | p_opt("params", param_params, &methodparams), |
| 932 | NULL)) |
| 933 | return command_param_failed(); |
| 934 | |
| 935 | if (is_rune_blacklisted(cmd->ld->runes, ras->rune)) |
| 936 | return command_fail(cmd, RUNE_BLACKLISTED, "Not authorized: Blacklisted rune"); |
| 937 | |
| 938 | cinfo.runes = cmd->ld->runes; |
| 939 | cinfo.peer = nodeid; |
| 940 | cinfo.buf = buffer; |
| 941 | cinfo.method = method; |
| 942 | cinfo.params = methodparams; |
| 943 | cinfo.now = clock_time(); |
| 944 | strmap_init(&cinfo.cached_params); |
| 945 | |
| 946 | err = rune_is_ours(cmd->ld, ras->rune); |
| 947 | if (err) { |
| 948 | return command_fail(cmd, RUNE_NOT_AUTHORIZED, "Not authorized: %s", err); |
| 949 | } |
| 950 | |
| 951 | err = rune_test(tmpctx, cmd->ld->runes->master, ras->rune, check_condition, &cinfo); |
| 952 | strmap_clear(&cinfo.cached_params); |
| 953 | |
| 954 | /* Just in case they manage to make us speak non-JSON, escape! */ |
| 955 | if (err) { |
| 956 | err = json_escape(tmpctx, err)->s; |
| 957 | |
| 958 | /* Turn runespeak into english! */ |
| 959 | if (strstarts(err, "pname")) |
| 960 | err = tal_strcat(tmpctx, "parameter ", err + strlen("pname")); |
| 961 | else if (strstarts(err, "parr")) |
| 962 | err = tal_strcat(tmpctx, "parameter #", err + strlen("parr")); |
| 963 | else if (strstarts(err, "pnum")) |
| 964 | err = tal_strcat(tmpctx, "number of parameters", err + strlen("pnum")); |
| 965 | else if (strstarts(err, "pinv")) |
| 966 | err = tal_strcat(tmpctx, "invoice parameter ", err + strlen("pinv")); |
| 967 | return command_fail(cmd, RUNE_NOT_PERMITTED, "Not permitted: %s", err); |
| 968 | } |
| 969 | |
| 970 | update_rune_usage_time(cmd->ld->runes, ras->rune, cinfo.now); |
| 971 | |
| 972 | js = json_stream_success(cmd); |
nothing calls this directly
no test coverage detected