olschema2ldif: be more strict where checking for open/closed braces
authorMatthieu Patou <mat@matws.net>
Sun, 15 Apr 2012 21:02:41 +0000 (14:02 -0700)
committerMatthieu Patou <mat@matws.net>
Sun, 6 May 2012 00:26:10 +0000 (17:26 -0700)
source4/utils/oLschema2ldif.c

index ae69db19bc3620c396e8d41f9f9375c5f8e6c730..be86daafb7177215ed8ef8dfa74ffd2248a9fbcf 100644 (file)
@@ -82,7 +82,12 @@ static int check_braces(const char *string)
                c = strpbrk(c, "()");
                if (c == NULL) return 1;
                if (*c == '(') b++;
-               if (*c == ')') b--;
+               if (*c == ')') {
+                       b--;
+                       if (*(c - 1) != ' ' && c && (*(c + 1) == '\0')) {
+                               return 2;
+                       }
+               }
                c++;
        }
        return 0;
@@ -538,8 +543,10 @@ static struct schema_conv process_file(FILE *in, FILE *out)
 
                do { 
                        if (c == '\n') {
-                               entry[t] = '\0';        
-                               if (check_braces(entry) == 0) {
+                               int ret2 = 0;
+                               entry[t] = '\0';
+                               ret2 = check_braces(entry);
+                               if (ret2 == 0) {
                                        ret.count++;
                                        ldif.msg = process_entry(ctx, entry);
                                        if (ldif.msg == NULL) {
@@ -550,6 +557,11 @@ static struct schema_conv process_file(FILE *in, FILE *out)
                                        ldb_ldif_write_file(ldb_ctx, out, &ldif);
                                        break;
                                }
+                               if (ret2 == 2) {
+                                       fprintf(stderr, "Invalid entry %s, closing braces needs to be preceeded by a space\n", entry);
+                                       ret.failures++;
+                                       break;
+                               }
                                line++;
                        } else {
                                entry[t] = c;