New build path variable
[freeradius.git] / src / main / conffile.c
index b391c22..5157f14 100644 (file)
@@ -1168,6 +1168,7 @@ static int condition_looks_ok(const char **ptr)
                                 *      Parse error.
                                 */
                                if (*q != '{') {
+                                       DEBUG2("Expected open brace '{' after condition at %s", p);
                                        return 0;
                                }
 
@@ -1191,6 +1192,7 @@ static int condition_looks_ok(const char **ptr)
                }
        }
 
+       DEBUG3("Unexpected error");
        return 0;
 }
 
@@ -1509,6 +1511,7 @@ static int cf_section_read(const char *filename, int *lineno, FILE *fp,
                case T_EOL:
                case T_HASH:
                do_bare_word:
+                       t3 = t2;
                        t2 = T_OP_EQ;
                        value = NULL;
                        goto do_set;
@@ -1527,7 +1530,6 @@ static int cf_section_read(const char *filename, int *lineno, FILE *fp,
 
                case T_OP_EQ:
                case T_OP_SET:
-               do_set:
                        t3 = getstring(&ptr, buf3, sizeof(buf3));
                        if (t3 == T_OP_INVALID) {
                                radlog(L_ERR, "%s[%d]: Parse error: %s",
@@ -1554,6 +1556,7 @@ static int cf_section_read(const char *filename, int *lineno, FILE *fp,
                        /*
                         *      Add this CONF_PAIR to our CONF_SECTION
                         */
+               do_set:
                        cpn = cf_pair_alloc(buf1, value, t2, t3, this);
                        cpn->item.filename = filename;
                        cpn->item.lineno = *lineno;
@@ -1707,6 +1710,7 @@ int cf_file_include(const char *filename, CONF_SECTION *cs)
        }
 
        if (cf_data_find_internal(cs, filename, PW_TYPE_FILENAME)) {
+               fclose(fp);
                radlog(L_ERR, "Cannot include the same file twice: \"%s\"",
                       filename);
                return -1;
@@ -2577,7 +2581,7 @@ static const char *cf_pair_print_value(const CONF_PAIR *cp,
 }
 
 
-int cf_pair2xml(FILE *fp, CONF_PAIR *cp)
+int cf_pair2xml(FILE *fp, const CONF_PAIR *cp)
 {
        fprintf(fp, "<%s>", cp->attr);
        if (cp->value) {
@@ -2586,7 +2590,7 @@ int cf_pair2xml(FILE *fp, CONF_PAIR *cp)
                char *p = buffer;
                const char *q = cp->value;
 
-               while (*q && (p < (buffer + sizeof(buffer)))) {
+               while (*q && (p < (buffer + sizeof(buffer) - 1))) {
                        if (q[0] == '&') {
                                memcpy(p, "&amp;", 4);
                                p += 5;
@@ -2614,7 +2618,7 @@ int cf_pair2xml(FILE *fp, CONF_PAIR *cp)
        return 1;
 }
 
-int cf_section2xml(FILE *fp, CONF_SECTION *cs)
+int cf_section2xml(FILE *fp, const CONF_SECTION *cs)
 {
        CONF_ITEM *ci, *next;
 
@@ -2652,7 +2656,7 @@ int cf_section2xml(FILE *fp, CONF_SECTION *cs)
        return 1;               /* success */
 }
 
-int cf_pair2file(FILE *fp, CONF_PAIR *cp)
+int cf_pair2file(FILE *fp, const CONF_PAIR *cp)
 {
        char buffer[2048];
 
@@ -2662,9 +2666,9 @@ int cf_pair2file(FILE *fp, CONF_PAIR *cp)
        return 1;
 }
 
-int cf_section2file(FILE *fp, CONF_SECTION *cs)
+int cf_section2file(FILE *fp, const CONF_SECTION *cs)
 {
-       CONF_ITEM *ci, *next;
+       const CONF_ITEM *ci, *next;
 
        /*
         *      Section header
@@ -2684,11 +2688,11 @@ int cf_section2file(FILE *fp, CONF_SECTION *cs)
 
                switch (ci->type) {
                case CONF_ITEM_PAIR:
-                       if (!cf_pair2file(fp, (CONF_PAIR *) ci)) return 0;
+                       if (!cf_pair2file(fp, (const CONF_PAIR *) ci)) return 0;
                        break;
 
                case CONF_ITEM_SECTION:
-                       if (!cf_section2file(fp, (CONF_SECTION *) ci)) return 0;
+                       if (!cf_section2file(fp, (const CONF_SECTION *) ci)) return 0;
                        break;
 
                default:        /* should really be an error. */