libhsmd: Prefix check_client_capabilities

I wante to hide it inside the library, but it is good to have a single
place to verify that the client was permitted to send a message we are
handling, so make it officially part of the interface by prefixing it.
This commit is contained in:
Christian Decker 2021-04-23 10:53:02 +02:00 committed by Rusty Russell
parent fb2b107bef
commit 96acafcef3
3 changed files with 10 additions and 8 deletions

View File

@ -633,9 +633,10 @@ static struct io_plan *handle_client(struct io_conn *conn, struct client *c)
/* Before we do anything else, is this client allowed to do /* Before we do anything else, is this client allowed to do
* what he asks for? */ * what he asks for? */
if (!check_client_capabilities(c->hsmd_client, t)) if (!hsmd_check_client_capabilities(c->hsmd_client, t))
return bad_req_fmt(conn, c, c->msg_in, return bad_req_fmt(conn, c, c->msg_in,
"does not have capability to run %d", t); "client does not have capability to run %d",
t);
/* Now actually go and do what the client asked for */ /* Now actually go and do what the client asked for */
switch (t) { switch (t) {

View File

@ -50,7 +50,8 @@ struct hsmd_client *hsmd_client_new_peer(const tal_t *ctx, u64 capabilities,
} }
/*~ This routine checks that a client is allowed to call the handler. */ /*~ This routine checks that a client is allowed to call the handler. */
bool check_client_capabilities(struct hsmd_client *client, enum hsmd_wire t) bool hsmd_check_client_capabilities(struct hsmd_client *client,
enum hsmd_wire t)
{ {
/*~ Here's a useful trick: enums in C are not real types, they're /*~ Here's a useful trick: enums in C are not real types, they're
* semantic sugar sprinkled over an int, bascally (in fact, older * semantic sugar sprinkled over an int, bascally (in fact, older
@ -1319,7 +1320,7 @@ u8 *hsmd_handle_client_message(const tal_t *ctx, struct hsmd_client *client,
/* Before we do anything else, is this client allowed to do /* Before we do anything else, is this client allowed to do
* what he asks for? */ * what he asks for? */
if (!check_client_capabilities(client, t)) if (!hsmd_check_client_capabilities(client, t))
return hsmd_status_bad_request_fmt( return hsmd_status_bad_request_fmt(
client, msg, "does not have capability to run %d", t); client, msg, "does not have capability to run %d", t);

View File

@ -90,9 +90,9 @@ void hsmd_status_fmt(enum log_level level,
void hsmd_status_failed(enum status_failreason code, void hsmd_status_failed(enum status_failreason code,
const char *fmt, ...) PRINTF_FMT(2,3); const char *fmt, ...) PRINTF_FMT(2,3);
/* The following declarations are here only temporarily while we migrate logic from hsmd.c to libhsmd.c */ /* Given a message type and a client that sent the message, determine
* whether the client was permitted to send such a message. */
bool hsmd_check_client_capabilities(struct hsmd_client *client,
enum hsmd_wire t);
bool check_client_capabilities(struct hsmd_client *client, enum hsmd_wire t);
/* end of temporary global declarations. The above will be removed once we complete the migration. */
#endif /* LIGHTNING_HSMD_LIBHSMD_H */ #endif /* LIGHTNING_HSMD_LIBHSMD_H */