From 4b90800a2bb41a31fc788b3e3cb9619a5cb785a2 Mon Sep 17 00:00:00 2001 From: Jordan Bancino Date: Tue, 7 Nov 2023 01:26:26 -0500 Subject: [PATCH] Fix leak in RouteConfig, update documentation. Closes #15. --- docs/CHANGELOG.md | 2 ++ docs/user/admin/config.md | 22 +++++++++++++++++++++- src/Routes/RouteConfig.c | 5 ++--- 3 files changed, 25 insertions(+), 4 deletions(-) diff --git a/docs/CHANGELOG.md b/docs/CHANGELOG.md index b9b7a3a..6e8015c 100644 --- a/docs/CHANGELOG.md +++ b/docs/CHANGELOG.md @@ -31,6 +31,8 @@ Matrix clients. (#35) - Implemented `/_telodendria/admin/v1/deactivate/[localpart]` for admins to be able to deactivate users. +- Added a **PUT** option to `/_telodendria/admin/v1/config` that gives the ability to change +only a subset of the configuration. - Moved all administrator API endpoints to `/_telodendria/admin/v1`, because later revisions of the administrator API may break clients, so we want a way to give those breaking revisions new endpoints. diff --git a/docs/user/admin/config.md b/docs/user/admin/config.md index 0466403..8394f7b 100644 --- a/docs/user/admin/config.md +++ b/docs/user/admin/config.md @@ -4,7 +4,7 @@ As mentioned in [Setup](../setup.md), Telodendria's configuration is intended to be managed via the configuration API. Consult the [Configuration](../config.md) document for a complete list of supported configuration options. This document simply describes the API used to -update the configuration. +update the configuration described in that document. ## API Endpoints @@ -40,3 +40,23 @@ configuration with the new one. |-------|------|-------------| | `restart_required` | `Boolean` | Whether or not the process needs to be restarted to finish applying the configuration. If this is `true`, then the restart endpoint should be used at a convenient time to apply the configuration. +### **PUT** `/_telodendria/admin/config` + +Update the currently installed configuration instead of completely replacing it. This endpoint +validates the request body, merges it on top of the current configuration, validates the resulting +configuration, then updates it in the database. This is useful when only one or two properties +in the configuration needs to be changed. + +| Requires Token | Rate Limited | +|----------------|--------------| +| Yes | Yes | + +| Response Code | Description | +|---------------|-------------| +| 200 | The new configuration was successfully installed.| + +#### 200 Response Format + +| Field | Type | Description | +|-------|------|-------------| +| `restart_required` | `Boolean` | Whether or not the process needs to be restarted to finish applying the configuration. If this is `true`, then the restart endpoint should be used at a convenient time to apply the configuration. diff --git a/src/Routes/RouteConfig.c b/src/Routes/RouteConfig.c index 1a31bb9..5f0c91e 100644 --- a/src/Routes/RouteConfig.c +++ b/src/Routes/RouteConfig.c @@ -135,8 +135,6 @@ ROUTE_IMPL(RouteConfig, path, argp) newConf = ConfigParse(newJson); - /* TODO: Don't leak newJson. */ - if (!newConf) { HttpResponseStatus(args->context, HTTP_INTERNAL_SERVER_ERROR); @@ -169,10 +167,11 @@ ROUTE_IMPL(RouteConfig, path, argp) ConfigFree(newConf); JsonFree(request); + JsonFree(newJson); break; default: HttpResponseStatus(args->context, HTTP_BAD_REQUEST); - response = MatrixErrorCreate(M_UNRECOGNIZED, NULL); + response = MatrixErrorCreate(M_UNRECOGNIZED, "Unknown request method."); break; }