X-Git-Url: http://www.chiark.greenend.org.uk/ucgi/~ian/git?p=secnet.git;a=blobdiff_plain;f=conffile.c;h=318d608a77ca7e7befcd6f7876ac770c987f1dc3;hp=f33354e6e075b36b38e2d20ad21c3c6ab9f2d5e1;hb=d3fe100dfc120244d316e083ce87b1eb130fe4fd;hpb=469fd1d95b2528212a46b155cb115c078de4228f diff --git a/conffile.c b/conffile.c index f33354e..318d608 100644 --- a/conffile.c +++ b/conffile.c @@ -76,8 +76,6 @@ static list_t *dict_ilookup(dict_t *dict, atom_t key) static void dict_iadd(dict_t *dict, atom_t key, list_t *val) { struct entry *e; - /* XXX May want to permit redefinition of keys in the future */ - /* (although it could be very confusing) */ if (dict_ilookup_primitive(dict, key)) { fatal("duplicate key \"%s\" in dictionary\n",key); } @@ -717,101 +715,6 @@ bool_t dict_read_bool(dict_t *dict, string_t key, bool_t required, return r; } -static struct subnet string_to_subnet(item_t *i, string_t desc) -{ - struct subnet s; - uint32_t a, b, c, d, n; - uint32_t match; - - /* i is not guaranteed to be a string */ - if (i->type!=t_string) { - cfgfatal(i->loc,desc,"expecting a string (subnet specification)\n"); - } - - if (strcmp(i->data.string,"default")==0) { - s.prefix=0; - s.mask=0; - s.len=0; - return s; - } - - /* We expect strings of the form "a.b.c.d[/n]", i.e. the dots are - NOT optional. The subnet mask is optional; if missing it is assumed - to be /32. */ - match=sscanf(i->data.string,"%u.%u.%u.%u/%u", &a, &b, &c, &d, &n); - if (match<4) { - cfgfatal(i->loc,desc,"\"%s\" is not a valid " - "subnet specification\n",i->data.string); - } - if (match<5) { - n=32; - } - if (a>255 || b>255 || c>255 || d>255 || n>32) { - cfgfatal(i->loc,desc,"\"%s\": range error\n",i->data.string); - } - s.prefix=(a<<24)|(b<<16)|(c<<8)|(d); - s.mask=n?(~0UL << (32-n)):0; - s.len=n; - if (s.prefix & ~s.mask) { - cfgfatal(i->loc,desc,"\"%s\": prefix not fully contained " - "in mask\n",i->data.string); - } - return s; -} - -uint32_t string_to_ipaddr(item_t *i, string_t desc) -{ - uint32_t a, b, c, d; - uint32_t match; - - /* i is not guaranteed to be a string */ - if (i->type!=t_string) { - cfgfatal(i->loc,desc,"expecting a string (IP address)\n"); - } - - match=sscanf(i->data.string,"%u.%u.%u.%u", &a, &b, &c, &d); - if (match<4) { - cfgfatal(i->loc,desc,"\"%s\" is not a valid " - "IP address\n",i->data.string); - } - if (a>255 || b>255 || c>255 || d>255) { - cfgfatal(i->loc,desc,"\"%s\": range error\n",i->data.string); - } - return (a<<24)|(b<<16)|(c<<8)|(d); -} - -void dict_read_subnet_list(dict_t *dict, string_t key, bool_t required, - string_t desc, struct cloc loc, - struct subnet_list *sl) -{ - list_t *l, *li; - item_t *i; - uint32_t e=0; - - sl->entries=0; - sl->list=NULL; - l=dict_lookup(dict, key); - if (!l) { - if (!required) return; - cfgfatal(loc,desc,"required parameter \"%s\" not found\n",key); - } - /* Count the items in the list */ - e=list_length(l); - if (e==0) return; - sl->entries=e; - sl->list=safe_malloc(sizeof(struct subnet)*e, "dict_read_subnet_list"); - e=0; - /* Fill in the list */ - for (li=l; li; li=li->next) { - i=li->item; - if (i->type!=t_string) { - cfgfatal(loc,desc,"parameter \"%s\": all elements must " - "be strings\n",key); - } - sl->list[e++]=string_to_subnet(i,desc); - } -} - uint32_t string_to_word(string_t s, struct cloc loc, struct flagstr *f, string_t desc) {