diff options
-rw-r--r-- | src/rest.c | 42 |
1 files changed, 42 insertions, 0 deletions
@@ -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", |