summaryrefslogtreecommitdiffstats
path: root/src/rest.c
diff options
context:
space:
mode:
authorOpenGnSys Support Team <soporte-og@soleta.eu>2024-09-30 14:39:36 +0200
committerOpenGnSys Support Team <soporte-og@soleta.eu>2024-10-01 12:33:59 +0200
commite81685bba0d9f1d6a28c0375f118df57667bedf0 (patch)
tree97652952f7f31f7e633be3f8b07ff85034280b21 /src/rest.c
parent85ca21be00b2521db5c6eb2f4dc6118fd85173ea (diff)
rest: do not allow two repositories to use the same IP address
repository need to have unique IP address, otherwise bail out.
Diffstat (limited to 'src/rest.c')
-rw-r--r--src/rest.c42
1 files changed, 42 insertions, 0 deletions
diff --git a/src/rest.c b/src/rest.c
index f233f6b..a9eae33 100644
--- a/src/rest.c
+++ b/src/rest.c
@@ -4783,6 +4783,38 @@ static int og_cmd_post_center_delete(json_t *element,
return 0;
}
+static int og_repo_list_find_ips(const char *ips_array[], uint32_t ips_array_len,
+ uint32_t exclude_repo_id)
+{
+ struct og_repo *repo;
+ LIST_HEAD(repo_list);
+ struct in_addr addr;
+ uint32_t i;
+
+ if (og_repo_list(&repo_list) < 0)
+ return -1;
+
+ for (i = 0; i < ips_array_len; i++) {
+ if (!inet_aton(ips_array[i], &addr))
+ return -1;
+
+ list_for_each_entry(repo, &repo_list, list) {
+ if (exclude_repo_id && exclude_repo_id == repo->id)
+ continue;
+
+ if (addr.s_addr == repo->addr[i].s_addr) {
+ syslog(LOG_ERR, "Cannot add new repository, IP %s is already in used by repository '%s'\n",
+ ips_array[i], repo->name);
+ return -1;
+ }
+ }
+ }
+
+ og_repo_free_list(&repo_list);
+
+ return 0;
+}
+
static int og_cmd_post_repository_update(json_t *element,
struct og_msg_params *params,
char *buffer_reply)
@@ -4815,6 +4847,11 @@ static int og_cmd_post_repository_update(json_t *element,
OG_REST_PARAM_ADDR))
return -1;
+ if (og_repo_list_find_ips(params->ips_array, params->ips_array_len, repo_id)) {
+ syslog(LOG_ERR, "Repository IP already in use, cannot define overlapping\n");
+ return -1;
+ }
+
dbi = og_dbi_open(&ogconfig.db);
if (!dbi) {
syslog(LOG_ERR, "cannot open connection database (%s:%d)\n",
@@ -4899,6 +4936,11 @@ static int og_cmd_post_repository_add(json_t *element,
OG_REST_PARAM_NAME))
return -1;
+ if (og_repo_list_find_ips(params->ips_array, params->ips_array_len, 0)) {
+ syslog(LOG_ERR, "Repository IP already in use, cannot define overlapping\n");
+ return -1;
+ }
+
dbi = og_dbi_open(&ogconfig.db);
if (!dbi) {
syslog(LOG_ERR, "cannot open connection database (%s:%d)\n",