diff options
author | Niklas Hallqvist <niklas@cvs.openbsd.org> | 1998-11-20 07:38:31 +0000 |
---|---|---|
committer | Niklas Hallqvist <niklas@cvs.openbsd.org> | 1998-11-20 07:38:31 +0000 |
commit | 3b26e616b18a92442cb9be54959f0909c578e2c0 (patch) | |
tree | 5e560e0c0bd3fcb50ea8b594c813b97bb7d4dfe6 | |
parent | 68cb4b53b221cb3023845612808db7ad1210f1a0 (diff) |
Add iterator for tags in a section. Add range checking for numbers.
-rw-r--r-- | sbin/isakmpd/conf.c | 61 | ||||
-rw-r--r-- | sbin/isakmpd/conf.h | 12 |
2 files changed, 66 insertions, 7 deletions
diff --git a/sbin/isakmpd/conf.c b/sbin/isakmpd/conf.c index 9fb12f8916d..d1fa4c6755a 100644 --- a/sbin/isakmpd/conf.c +++ b/sbin/isakmpd/conf.c @@ -1,5 +1,5 @@ -/* $OpenBSD: conf.c,v 1.3 1998/11/17 11:10:08 niklas Exp $ */ -/* $EOM: conf.c,v 1.9 1998/10/08 21:21:37 niklas Exp $ */ +/* $OpenBSD: conf.c,v 1.4 1998/11/20 07:38:30 niklas Exp $ */ +/* $EOM: conf.c,v 1.10 1998/11/20 07:19:21 niklas Exp $ */ /* * Copyright (c) 1998 Niklas Hallqvist. All rights reserved. @@ -266,6 +266,33 @@ conf_get_num (char *section, char *tag) return 0; } +/* Validate X according to the range denoted by TAG in section SECTION. */ +int +conf_match_num (char *section, char *tag, int x) +{ + char *value = conf_get_str (section, tag); + int val, min, max, n; + + if (!value) + return 0; + n = sscanf (value, "%d,%d:%d", &val, &min, &max); + switch (n) + { + case 1: + log_debug (LOG_MISC, 90, "conf_match_num: %s:%s %d==%d?", section, tag, + val, x); + return x == val; + case 3: + log_debug (LOG_MISC, 90, "conf_match_num: %s:%s %d<=%d<=%d?", section, + tag, min, x, max); + return min <= x && max >= x; + default: + log_error ("conf_match_num: section %s tag %s: invalid number spec %s", + section, tag, value); + } + return 0; +} + /* Return the string value denoted by TAG in section SECTION. */ char * conf_get_str (char *section, char *tag) @@ -329,6 +356,36 @@ conf_get_list (char *section, char *tag) return 0; } +struct conf_list * +conf_get_tag_list (char *section) +{ + struct conf_list *list = 0; + struct conf_list_node *node; + struct conf_binding *cb; + + list = malloc (sizeof *list); + if (!list) + goto cleanup; + TAILQ_INIT (&list->fields); + list->cnt = 0; + for (cb = LIST_FIRST (&conf_bindings); cb; cb = LIST_NEXT (cb, link)) + if (strcasecmp (section, cb->section) == 0) + { + list->cnt++; + node = malloc (sizeof *node); + if (!node) + goto cleanup; + node->field = cb->tag; + TAILQ_INSERT_TAIL (&list->fields, node, link); + } + return list; + + cleanup: + if (list) + conf_free_list (list); + return 0; +} + /* Decode a PEM encoded buffer. */ int conf_decode_base64(u_int8_t *out, u_int32_t *len, u_char *buf) diff --git a/sbin/isakmpd/conf.h b/sbin/isakmpd/conf.h index a0d41ff7dbd..a503fe3a7f1 100644 --- a/sbin/isakmpd/conf.h +++ b/sbin/isakmpd/conf.h @@ -1,5 +1,5 @@ -/* $OpenBSD: conf.h,v 1.3 1998/11/17 11:10:08 niklas Exp $ */ -/* $EOM: conf.h,v 1.4 1998/08/28 23:04:26 niklas Exp $ */ +/* $OpenBSD: conf.h,v 1.4 1998/11/20 07:38:30 niklas Exp $ */ +/* $EOM: conf.h,v 1.5 1998/11/20 07:19:22 niklas Exp $ */ /* * Copyright (c) 1998 Niklas Hallqvist. All rights reserved. @@ -54,12 +54,14 @@ struct conf_list { extern char *conf_path; -extern void conf_init (void); +extern int conf_decode_base64 (u_int8_t *out, u_int32_t *len, u_char *buf); extern void conf_free_list (struct conf_list *); +extern int conf_get_line (FILE *, char *, u_int32_t); extern struct conf_list *conf_get_list (char *, char *); +extern struct conf_list *conf_get_tag_list (char *); extern int conf_get_num (char *, char *); extern char *conf_get_str (char *, char *); -extern int conf_get_line (FILE *, char *, u_int32_t); -extern int conf_decode_base64 (u_int8_t *out, u_int32_t *len, u_char *buf); +extern void conf_init (void); +extern int conf_match_num (char *, char *, int); #endif /* _CONF_H_ */ |