X-Git-Url: http://www.chiark.greenend.org.uk/ucgi/~ian/git?p=secnet.git;a=blobdiff_plain;f=conffile.c;h=5cce211415921556a5c384817d1278d9eb9dc158;hp=b17517b58092d800da561c44f28420dbcdd54f30;hb=e1b81bd68228f908e7e69794386947d7f7f98451;hpb=fe5e9cc422cd72526ccfceffbc7e5af8ac83b407 diff --git a/conffile.c b/conffile.c index b17517b..5cce211 100644 --- a/conffile.c +++ b/conffile.c @@ -3,16 +3,16 @@ /* #define DUMP_PARSE_TREE */ #include "secnet.h" +#include +#include #include #include #include "conffile.h" #include "conffile_internal.h" +#include "conffile.yy.h" #include "util.h" #include "ipaddr.h" -/* from modules.c */ -extern void init_builtin_modules(dict_t *dict); - static struct cloc no_loc={"none",0}; struct atomlist { @@ -35,7 +35,7 @@ struct dict { struct dict *parent; struct searchlist *search; struct entry *entries; - uint32_t size; + int32_t size; }; static struct atomlist *atoms=NULL; @@ -173,9 +173,9 @@ static string_t ntype(uint32_t type) return "**unknown**"; } -static void ptree_indent(uint32_t amount) +static void ptree_indent(int amount) { - uint32_t i; + int i; for (i=0; itype),n->loc.file,n->loc.line); ptree_indent(d); printf(" |-"); ptree_dump(n->l, d+1); @@ -466,6 +467,9 @@ static dict_t *process_config(struct p_node *c) context=root; /* Predefined keys for boolean values */ + /* "nowise" and "verily" have the advantage of being the same + length, so they line up nicely... thanks VKC and SGT (who also + point out that "mayhap" is a good "maybe" value as well) */ i=new_item(t_bool,no_loc); i->data.bool=False; false=list_append(NULL,i); @@ -478,12 +482,18 @@ static dict_t *process_config(struct p_node *c) dict_add(root,"no",false); dict_add(root,"No",false); dict_add(root,"NO",false); + dict_add(root,"nowise",false); + dict_add(root,"Nowise",false); + dict_add(root,"NOWISE",false); dict_add(root,"true",true); dict_add(root,"True",true); dict_add(root,"TRUE",true); dict_add(root,"yes",true); dict_add(root,"Yes",true); dict_add(root,"YES",true); + dict_add(root,"verily",true); + dict_add(root,"Verily",true); + dict_add(root,"VERILY",true); add_closure(root,"makelist",makelist); add_closure(root,"readfile",readfile); @@ -551,15 +561,15 @@ list_t *list_new(void) return NULL; } -uint32_t list_length(list_t *a) +int32_t list_length(list_t *a) { - uint32_t l=0; + int32_t l=0; list_t *i; - for (i=a; i; i=i->next) l++; + for (i=a; i; i=i->next) { assert(l < INT_MAX); l++; } return l; } -list_t *list_copy(list_t *a) +static list_t *list_copy(list_t *a) { list_t *r, *i, *b, *l; @@ -598,7 +608,7 @@ list_t *list_append(list_t *list, item_t *item) return list_append_list(list,l); } -item_t *list_elem(list_t *l, uint32_t index) +item_t *list_elem(list_t *l, int32_t index) { if (!l) return NULL; if (index==0) return l->item; @@ -619,6 +629,7 @@ void add_closure(dict_t *dict, cstring_t name, apply_fn apply) closure_t *c; c=safe_malloc(sizeof(*c),"add_closure"); c->description=name; + c->type=CL_PURE; c->apply=apply; c->interface=NULL; @@ -677,6 +688,9 @@ string_t dict_read_string(dict_t *dict, cstring_t key, bool_t required, if (i->type!=t_string) { cfgfatal(loc,desc,"\"%s\" must be a string\n",key); } + if (strlen(i->data.string) > INT_MAX/10) { + cfgfatal(loc,desc,"\"%s\" is unreasonably long\n",key); + } r=i->data.string; return r; } @@ -692,6 +706,9 @@ uint32_t dict_read_number(dict_t *dict, cstring_t key, bool_t required, if (i->type!=t_number) { cfgfatal(loc,desc,"\"%s\" must be a number\n",key); } + if (i->data.number >= 0x80000000) { + cfgfatal(loc,desc,"\"%s\" must fit into a 32-bit signed integer\n",key); + } r=i->data.number; return r; }