Skip to content

Commit

Permalink
libhsmd: Prefix check_client_capabilities
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
cdecker committed May 3, 2021
1 parent 32b587a commit e0065b0
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 8 deletions.
5 changes: 3 additions & 2 deletions hsmd/hsmd.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
* 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,
"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 */
switch (t) {
Expand Down
5 changes: 3 additions & 2 deletions hsmd/libhsmd.c
Original file line number Diff line number Diff line change
Expand Up @@ -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. */
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
* semantic sugar sprinkled over an int, bascally (in fact, older
Expand Down Expand Up @@ -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
* what he asks for? */
if (!check_client_capabilities(client, t))
if (!hsmd_check_client_capabilities(client, t))
return hsmd_status_bad_request_fmt(
client, msg, "does not have capability to run %d", t);

Expand Down
8 changes: 4 additions & 4 deletions hsmd/libhsmd.h
Original file line number Diff line number Diff line change
Expand Up @@ -90,9 +90,9 @@ void hsmd_status_fmt(enum log_level level,
void hsmd_status_failed(enum status_failreason code,
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 */

0 comments on commit e0065b0

Please sign in to comment.