]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
MINOR: pattern: Check if the file reference is not used with acl and map
authorThierry FOURNIER <tfournier@exceliance.fr>
Wed, 29 Jan 2014 11:32:58 +0000 (12:32 +0100)
committerWilly Tarreau <w@1wt.eu>
Mon, 17 Mar 2014 17:06:08 +0000 (18:06 +0100)
The format of the acl file are not the same than the format of the map
files. In some case, the same file can be used, but this is ambiguous
for the user because the patterns are not the expected.

include/types/pattern.h
src/pattern.c

index 99f68cd75e515d0179152812c017b9adc527efb5..bf13bf78f9e6088efbeb2379ab75dec39615ba41 100644 (file)
@@ -89,6 +89,7 @@ enum {
 
 #define PAT_REF_MAP 0x1 /* Set if the reference is used by at least one map. */
 #define PAT_REF_ACL 0x2 /* Set if the reference is used by at least one acl. */
+#define PAT_REF_SMP 0x4 /* Flag used if the reference contains a sample. */
 
 /* This struct contain a list of reference strings for dunamically
  * updatable patterns.
index 7cab38930df06927906c68cd2b8469e5225e7b0b..4a3b05ad466dd36f3d234a9d7626cf8c6f23a2c8 100644 (file)
@@ -1956,6 +1956,7 @@ int pattern_read_from_file(struct pattern_head *head, unsigned int refflags,
                }
 
                if (load_smp) {
+                       ref->flags |= PAT_REF_SMP;
                        if (!pat_ref_read_from_file_smp(ref, filename, err))
                                return 0;
                }
@@ -1965,7 +1966,32 @@ int pattern_read_from_file(struct pattern_head *head, unsigned int refflags,
                }
        }
        else {
-               /* The reference already exists, Merge flags. */
+               /* The reference already exists, check the map compatibility. */
+
+               /* If the load require samples and the flag PAT_REF_SMP is not set,
+                * the reference doesn't contain sample, and cannot be used.
+                */
+               if (load_smp) {
+                       if (!(ref->flags & PAT_REF_SMP)) {
+                               memprintf(err, "The file \"%s\" is already used as one column file "
+                                              "and cannot be used by as two column file.",
+                                              filename);
+                               return 0;
+                       }
+               }
+               else {
+                       /* The load doesn't require samples. If the flag PAT_REF_SMP is
+                        * set, the reference contains a sample, and cannot be used.
+                        */
+                       if (ref->flags & PAT_REF_SMP) {
+                               memprintf(err, "The file \"%s\" is already used as two column file "
+                                              "and cannot be used by as one column file.",
+                                              filename);
+                               return 0;
+                       }
+               }
+
+               /* Merge flags. */
                ref->flags |= refflags;
        }