Added more 'const'
[freeradius.git] / src / main / conffile.c
index cde38ab..b56f5ba 100644 (file)
@@ -908,7 +908,9 @@ int cf_item_parse(CONF_SECTION *cs, const char *name,
                if (value == dflt) {
                        char buffer[8192];
 
-                       int lineno = cs->item.lineno;
+                       int lineno = 0;
+
+                       if (cs) lineno = cs->item.lineno;
 
                        /*
                         *      FIXME: sizeof(buffer)?
@@ -942,7 +944,9 @@ int cf_item_parse(CONF_SECTION *cs, const char *name,
                if (value == dflt) {
                        char buffer[8192];
 
-                       int lineno = cs->item.lineno;
+                       int lineno = 0;
+
+                       if (cs) lineno = cs->item.lineno;
 
                        /*
                         *      FIXME: sizeof(buffer)?
@@ -1458,12 +1462,19 @@ static int cf_section_read(const char *filename, int *lineno, FILE *fp,
 
               if (strcasecmp(buf1, "$template") == 0) {
                       CONF_ITEM *ci;
-                      CONF_SECTION *parentcs;
+                      CONF_SECTION *parentcs, *templatecs;
                       t2 = getword(&ptr, buf2, sizeof(buf2));
 
                       parentcs = cf_top_section(current);
 
-                      ci = cf_reference_item(parentcs, this, buf2);
+                      templatecs = cf_section_sub_find(parentcs, "templates");
+                      if (!templatecs) {
+                               radlog(L_ERR, "%s[%d]: No \"templates\" section for reference \"%s\"",
+                                      filename, *lineno, buf2);
+                               return -1;
+                      }
+
+                      ci = cf_reference_item(parentcs, templatecs, buf2);
                       if (!ci || (ci->type != CONF_ITEM_SECTION)) {
                                radlog(L_ERR, "%s[%d]: Reference \"%s\" not found",
                                       filename, *lineno, buf2);
@@ -1507,6 +1518,7 @@ static int cf_section_read(const char *filename, int *lineno, FILE *fp,
                case T_OP_SUB:
                case T_OP_LE:
                case T_OP_GE:
+               case T_OP_CMP_FALSE:
                        if (!this || (strcmp(this->name1, "update") != 0)) {
                                radlog(L_ERR, "%s[%d]: Invalid operator in assignment",
                                       filename, *lineno);
@@ -1517,6 +1529,12 @@ static int cf_section_read(const char *filename, int *lineno, FILE *fp,
                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",
+                                      filename, *lineno,
+                                      fr_strerror());
+                               return -1;
+                       }
 
                        /*
                         *      Handle variable substitution via ${foo}
@@ -2555,7 +2573,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) {
@@ -2592,7 +2610,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;
 
@@ -2630,7 +2648,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];
 
@@ -2640,9 +2658,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