ensure tdb names end with .tdb. and any number of digits
authorWolfgang Mueller-Friedt <wolfmuel@de.ibm.com>
Wed, 28 Oct 2009 11:54:29 +0000 (14:54 +0300)
committerRonnie Sahlberg <ronniesahlberg@gmail.com>
Thu, 29 Oct 2009 02:46:37 +0000 (13:46 +1100)
server/ctdb_ltdb_server.c

index 54b4f5ee0d32de7106f6ac4a7010b2bb7419ce85..09e40c77006990de0011686fcba69cfcbd04a604 100644 (file)
@@ -26,6 +26,7 @@
 #include "../include/ctdb_private.h"
 #include "db_wrap.h"
 #include "lib/util/dlinklist.h"
+#include <ctype.h>
 
 /*
   this is the dummy null procedure that all databases support
@@ -389,26 +390,30 @@ int ctdb_attach_persistent(struct ctdb_context *ctdb)
        }
 
        while ((de=readdir(d))) {
-               char *p, *s;
+               char *p, *s, *q;
                size_t len = strlen(de->d_name);
                uint32_t node;
+               int invalid_name = 0;
                
                s = talloc_strdup(ctdb, de->d_name);
                CTDB_NO_MEMORY(ctdb, s);
 
-               /* ignore names ending in .bak */
-               p = strstr(s, ".bak");
-               if (p != NULL) {
-                       continue;
-               }
-
                /* only accept names ending in .tdb */
                p = strstr(s, ".tdb.");
                if (len < 7 || p == NULL) {
                        talloc_free(s);
                        continue;
                }
-               if (sscanf(p+5, "%u", &node) != 1 || node != ctdb->pnn) {
+
+               /* only accept names ending with .tdb. and any number of digits */
+               q = p+5;
+               while (*q != 0 && invalid_name == 0) {
+                       if (!isdigit(*q++)) {
+                               invalid_name = 1;
+                       }
+               }
+               if (invalid_name == 1 || sscanf(p+5, "%u", &node) != 1 || node != ctdb->pnn) {
+                       DEBUG(DEBUG_ERR,("Ignoring persistent database '%s'\n", de->d_name));
                        talloc_free(s);
                        continue;
                }