Skip to content

Commit

Permalink
[rpt] HTTP registrations incorrectly showed as "Registered"
Browse files Browse the repository at this point in the history
When attempting to register a node w/HTTP and when not providing a valid node
and password the status was incorrectly being reported as "Registered".  This
was because the text of the response "message" was not being checked.

One could argue that this would be better handled by having the registration
server respond to the request with an non "2XX" code.  Unfortunately, this is
how the registration server was setup years ago.  Changing (correcting) the
behavior would require server changes and possible changes to this code.  We
would also need to ensure that any older (already deployed) systems would
continue to function correctly.

For now, we will check the HTTP response text (as was done in the past).
  • Loading branch information
Allan-N committed May 29, 2024
1 parent 8a8c65e commit f5ed846
Showing 1 changed file with 15 additions and 5 deletions.
20 changes: 15 additions & 5 deletions res/res_rpt_http_registrations.c
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ struct http_registry {
char username[80];
char secret[80]; /*!< Password or key name in []'s */
int refresh; /*!< How often to refresh */
char registered; /*!< Registered==1 */
struct ast_sockaddr us; /*!< Who the server thinks we are */
struct ast_dnsmgr_entry *dnsmgr; /*!< DNS refresh manager */
char perceived[80];
Expand Down Expand Up @@ -248,10 +249,15 @@ static int http_register(struct http_registry *reg)
port = ast_json_integer_get(ast_json_object_get(json, "port"));
refresh = ast_json_integer_get(ast_json_object_get(json, "refresh"));
data = ast_json_dump_string(ast_json_object_get(json, "data"));
ast_copy_string(reg->perceived, ipaddr, sizeof(reg->perceived));
reg->perceived_port = port;
reg->refresh = refresh;
ast_debug(2, "Response: ipaddr=%s, port=%d, refresh=%d, data=%s\n", ipaddr, port, refresh, data);
if (strstr(data, "successfully registered")) {
ast_copy_string(reg->perceived, ipaddr, sizeof(reg->perceived));
reg->perceived_port = port;
reg->refresh = refresh;
reg->registered = 1;
} else {
reg->registered = 0;
}
if (data) {
ast_json_free(data);
}
Expand Down Expand Up @@ -324,9 +330,13 @@ static char *handle_show_registrations(struct ast_cli_entry *e, int cmd, struct
ast_cli(a->fd, FORMAT2, "Host", "Username", "Perceived", "Refresh", "State");
AST_RWLIST_RDLOCK(&registrations);
AST_RWLIST_TRAVERSE(&registrations, reg, entry) {
snprintf(perceived, sizeof(perceived), "%s:%d", reg->perceived, reg->perceived_port);
if (!ast_sockaddr_isnull(&reg->addr)) {
snprintf(perceived, sizeof(perceived), "%s:%d", reg->perceived, reg->perceived_port);
} else {
ast_copy_string(perceived, "<Unregistered>", sizeof(perceived));
}
snprintf(host, sizeof(host), "%s", ast_sockaddr_stringify(&reg->addr));
ast_cli(a->fd, FORMAT, host, reg->username, reg->perceived_port ? perceived : "<Unregistered>", reg->refresh, reg->refresh ? "Registered" : "Not Registered");
ast_cli(a->fd, FORMAT, host, reg->username, reg->perceived_port ? perceived : "<Unregistered>", reg->refresh, reg->registered ? "Registered" : "Not Registered");
counter++;
}
AST_RWLIST_UNLOCK(&registrations);
Expand Down

0 comments on commit f5ed846

Please sign in to comment.