Skip to content

Commit a4ed3ae

Browse files
committed
commando: make blacklist effective.
Actually check them when we're going to use a rune.
1 parent fb86529 commit a4ed3ae

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed

plugins/commando.c

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,24 @@ static bool usage_eq_id(const struct usage *u, u64 id)
7676
HTABLE_DEFINE_TYPE(struct usage, usage_id, id_hash, usage_eq_id, usage_table);
7777
static struct usage_table *usage_table;
7878

79+
static bool is_rune_blacklisted(const struct rune *rune)
80+
{
81+
u64 uid;
82+
83+
/* Every rune *we produce* has a unique_id which is a number, but
84+
* it's legal to have a rune without one. */
85+
if (rune->unique_id == NULL) {
86+
return false;
87+
}
88+
uid = atol(rune->unique_id);
89+
for (size_t i = 0; i < tal_count(blacklist); i++) {
90+
if (blacklist[i].start <= uid && blacklist[i].end >= uid) {
91+
return true;
92+
}
93+
}
94+
return false;
95+
}
96+
7997
/* Every minute we forget entries. */
8098
static void flush_usage_table(void *unused)
8199
{
@@ -363,6 +381,9 @@ static const char *check_rune(const tal_t *ctx,
363381
if (!rune)
364382
return "Invalid rune";
365383

384+
if (is_rune_blacklisted(rune))
385+
return "Blacklisted rune";
386+
366387
cinfo.peer = peer;
367388
cinfo.buf = buf;
368389
cinfo.method = method;

0 commit comments

Comments
 (0)