parser BUGFIX does not check duplicated identifiers in identity
diff --git a/src/parser.c b/src/parser.c
index b5d24d1..82186cc 100644
--- a/src/parser.c
+++ b/src/parser.c
@@ -1255,6 +1255,46 @@
     return ret;
 }
 
+
+/* does not log */
+static
+int
+dup_identity_check(const char *id, struct lys_ident *ident, uint32_t size)
+{
+    uint32_t i;
+
+    for (i = 0; i < size; i++) {
+        if (id == ident[i].name) {
+            /* name collision */
+            return EXIT_FAILURE;
+        }
+    }
+
+    return EXIT_SUCCESS;
+}
+
+int
+dup_identities_check(const char *id, struct lys_module *module)
+{
+    struct lys_module *main;    
+    int i;
+
+    if (dup_identity_check(id, module->ident, module->ident_size)) {
+        LOGVAL(LYE_DUPID, LY_VLOG_NONE, NULL, "identity", id);
+        return EXIT_FAILURE;
+    }
+
+    /* check identity in submodules */
+    main = lys_main_module(module);
+    for (i = 0; i < main->inc_size && main->inc[i].submodule; ++i)
+    if (dup_identity_check(id, main->inc[i].submodule->ident, main->inc[i].submodule->ident_size)) {
+        LOGVAL(LYE_DUPID, LY_VLOG_NONE, NULL, "identity", id);
+        return EXIT_FAILURE;
+    }
+
+    return EXIT_SUCCESS;
+}
+
 /* does not log */
 int
 dup_typedef_check(const char *type, struct lys_tpdf *tpdf, int size)
diff --git a/src/parser.h b/src/parser.h
index 12ad1bf..a499a33 100644
--- a/src/parser.h
+++ b/src/parser.h
@@ -75,6 +75,9 @@
                      const struct lys_node *node);
 
 int dup_typedef_check(const char *type, struct lys_tpdf *tpdf, int size);
+
+int dup_identities_check(const char *id, struct lys_module *module);
+
 /**
  * @brief Get know if the node is part of the RPC's input/output
  *
diff --git a/src/parser_yang.c b/src/parser_yang.c
index 6b03e3d..f95a8d9 100644
--- a/src/parser_yang.c
+++ b/src/parser_yang.c
@@ -311,6 +311,10 @@
     ret = &module->ident[module->ident_size];
     ret->name = lydict_insert_zc(module->ctx, value);
     ret->module = module;
+    if (dup_identities_check(ret->name, module)) {
+        lydict_remove(module->ctx, ret->name);
+        return NULL;
+    }
     module->ident_size++;
     return ret;
 }
diff --git a/src/parser_yin.c b/src/parser_yin.c
index 0a29e46..73e5600 100644
--- a/src/parser_yin.c
+++ b/src/parser_yin.c
@@ -127,6 +127,10 @@
         return EXIT_FAILURE;
     }
 
+    if (dup_identities_check(ident->name, module)) {
+        return EXIT_FAILURE;
+    }
+
     LY_TREE_FOR(yin->child, node) {
         if (!node->ns || strcmp(node->ns->value, LY_NSYIN)) {
             /* garbage */