@cryptotaxi247 / netdata-1 / commits / 762701f90

fix unlocked registry access and add hostname to search response (#15426)

Costa Tsaousis committed Jul 17, 2023 at 22:48 UTC 762701f9052375e2a7137b7a60a99fc9626957c2
3 files changed +14 -6
registry/registry.c
+9 -3
@@ -113,7 +113,7 @@ static int registry_json_person_url_callback(REGISTRY_PERSON_URL *pu, struct reg
113 }
114
115 // callback for rendering MACHINE_URLs
116 -static int registry_json_machine_url_callback(REGISTRY_MACHINE_URL *mu, struct registry_json_walk_person_urls_callback *c) {
116 +static int registry_json_machine_url_callback(REGISTRY_MACHINE_URL *mu, struct registry_json_walk_person_urls_callback *c, STRING *hostname) {
117 if(unlikely(!asterisks))
118 asterisks = string_strdupz("***");
119
@@ -127,6 +127,7 @@ static int registry_json_machine_url_callback(REGISTRY_MACHINE_URL *mu, struct r
127 buffer_json_add_array_item_string(w->response.data, string2str(mu->url));
128 buffer_json_add_array_item_uint64(w->response.data, mu->last_t * (uint64_t) 1000);
129 buffer_json_add_array_item_uint64(w->response.data, mu->usages);
130 + buffer_json_add_array_item_string(w->response.data, string2str(hostname));
131 buffer_json_array_close(w->response.data);
132
133 return 1;
@@ -226,7 +227,9 @@ int registry_request_access_json(RRDHOST *host, struct web_client *w, char *pers
227 // verify the browser supports cookies or the bearer
228
229 if(registry.verify_cookies_redirects > 0 && !person_guid[0]) {
230 + registry_lock();
231 registry_request_access(REGISTRY_VERIFY_COOKIES_GUID, machine_guid, url, name, when);
232 + registry_unlock();
233
234 buffer_flush(w->response.data);
235 registry_set_cookie(w, REGISTRY_VERIFY_COOKIES_GUID);
@@ -320,11 +323,13 @@ int registry_request_search_json(RRDHOST *host, struct web_client *w, char *pers
323
324 registry_lock();
325
323 - REGISTRY_MACHINE *m = registry_request_machine(person_guid, request_machine);
326 + STRING *hostname = NULL;
327 + REGISTRY_MACHINE *m = registry_request_machine(person_guid, request_machine, &hostname);
328 if(!m) {
329 registry_json_header(host, w, "search", REGISTRY_STATUS_FAILED);
330 registry_json_footer(w);
331 registry_unlock();
332 + string_freez(hostname);
333 return HTTP_RESP_NOT_FOUND;
334 }
335
@@ -334,12 +339,13 @@ int registry_request_search_json(RRDHOST *host, struct web_client *w, char *pers
339 struct registry_json_walk_person_urls_callback c = { NULL, m, w, 0 };
340
341 for(REGISTRY_MACHINE_URL *mu = m->machine_urls; mu ; mu = mu->next)
337 - registry_json_machine_url_callback(mu, &c);
342 + registry_json_machine_url_callback(mu, &c, hostname);
343
344 buffer_json_array_close(w->response.data);
345
346 registry_json_footer(w);
347 registry_unlock();
348 + string_freez(hostname);
349 return HTTP_RESP_OK;
350 }
351
registry/registry_internals.c
+4 -2
@@ -209,7 +209,7 @@ REGISTRY_PERSON *registry_request_delete(const char *person_guid, char *machine_
209 }
210
211
212 -REGISTRY_MACHINE *registry_request_machine(const char *person_guid, char *request_machine) {
212 +REGISTRY_MACHINE *registry_request_machine(const char *person_guid, char *request_machine, STRING **hostname) {
213 char pbuf[GUID_LEN + 1];
214 char mbuf[GUID_LEN + 1];
215
@@ -239,8 +239,10 @@ REGISTRY_MACHINE *registry_request_machine(const char *person_guid, char *reques
239
240 // make sure the user has access
241 for(REGISTRY_PERSON_URL *pu = p->person_urls; pu ;pu = pu->next)
242 - if(pu->machine == m)
242 + if(pu->machine == m) {
243 + *hostname = string_dup(pu->machine_name);
244 return m;
245 + }
246
247 return NULL;
248 }
registry/registry_internals.h
+1 -1
@@ -72,7 +72,7 @@ extern struct registry registry;
72 // REGISTRY LOW-LEVEL REQUESTS (in registry-internals.c)
73 REGISTRY_PERSON *registry_request_access(const char *person_guid, char *machine_guid, char *url, char *name, time_t when);
74 REGISTRY_PERSON *registry_request_delete(const char *person_guid, char *machine_guid, char *url, char *delete_url, time_t when);
75 -REGISTRY_MACHINE *registry_request_machine(const char *person_guid, char *request_machine);
75 +REGISTRY_MACHINE *registry_request_machine(const char *person_guid, char *request_machine, STRING **hostname);
76
77 // REGISTRY LOG (in registry_log.c)
78 void registry_log(char action, REGISTRY_PERSON *p, REGISTRY_MACHINE *m, STRING *u, const char *name);