]> git.ipfire.org Git - thirdparty/openldap.git/commitdiff
ITS#9016 Check confdir is empty before generating from scratch
authorOndřej Kuzník <ondra@mistotebe.net>
Wed, 17 Mar 2021 16:17:27 +0000 (16:17 +0000)
committerQuanah Gibson-Mount <quanah@openldap.org>
Thu, 18 Mar 2021 21:07:43 +0000 (21:07 +0000)
servers/slapd/bconfig.c

index 97656dd4754f909b2ea4dbeca62c48e0ef1bfa9a..645ecf1478626426ab1340ce80d58ffb6a93b884 100644 (file)
@@ -23,6 +23,7 @@
 #include <stdio.h>
 #include <ac/string.h>
 #include <ac/ctype.h>
+#include <ac/dirent.h>
 #include <ac/errno.h>
 #include <sys/stat.h>
 #include <ac/unistd.h>
@@ -4520,6 +4521,21 @@ config_setup_ldif( BackendDB *be, const char *dir, int readit ) {
                        rc = op->o_bd->be_add( op, &rs );
                }
                ldap_pvt_thread_pool_context_reset( thrctx );
+       } else {
+               /* ITS#9016 Check directory is empty (except perhaps hidden files) */
+               DIR *dir_of_path;
+               struct dirent *entry;
+
+               dir_of_path = opendir( dir );
+               while ( (entry = readdir( dir_of_path )) != NULL ) {
+                       if ( entry->d_name[0] != '.' ) {
+                               Debug( LDAP_DEBUG_ANY, "config_setup_ldif: "
+                                               "expected directory %s to be empty!\n",
+                                               dir );
+                               rc = LDAP_ALREADY_EXISTS;
+                               break;
+                       }
+               }
        }
 
        /* ITS#4194 - only use if it's present, or we're converting. */