From 5c7abe762451df4ff093311b2f0030cc99fc8ebe Mon Sep 17 00:00:00 2001
From: Jan Vcelak <jan.vcelak@nic.cz>
Date: Wed, 3 Apr 2013 11:57:04 +0200
Subject: [PATCH] config: prohibit multiple definition of remotes

---
 src/knot/conf/cf-parse.y | 19 ++++++++++++++++++-
 1 file changed, 18 insertions(+), 1 deletion(-)

diff --git a/src/knot/conf/cf-parse.y b/src/knot/conf/cf-parse.y
index d65e625931..78de3dd110 100644
--- a/src/knot/conf/cf-parse.y
+++ b/src/knot/conf/cf-parse.y
@@ -48,14 +48,31 @@ static void conf_start_iface(void *scanner, char* ifname)
    ++new_config->ifaces_count;
 }
 
+static conf_iface_t *conf_get_remote(const char *name)
+{
+	conf_iface_t *remote;
+	WALK_LIST (remote, new_config->remotes) {
+		if (strcmp(remote->name, name) == 0) {
+			return remote;
+		}
+	}
+
+	return NULL;
+}
+
 static void conf_start_remote(void *scanner, char *remote)
 {
+   if (conf_get_remote(remote) != NULL) {
+      cf_error(scanner, "remote '%s' already defined", remote);
+      return;
+   }
+
    this_remote = malloc(sizeof(conf_iface_t));
    if (this_remote == NULL) {
       cf_error(scanner, "not enough memory when allocating remote");
       return;
    }
-   
+
    memset(this_remote, 0, sizeof(conf_iface_t));
    this_remote->name = remote;
    add_tail(&new_config->remotes, &this_remote->n);
-- 
GitLab