summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--sbin/dhclient/clparse.c122
-rw-r--r--sbin/dhclient/conflex.c271
-rw-r--r--sbin/dhclient/dhctoken.h135
-rw-r--r--sbin/dhclient/parse.c74
-rw-r--r--usr.sbin/dhcpd/conflex.c284
-rw-r--r--usr.sbin/dhcpd/confpars.c204
-rw-r--r--usr.sbin/dhcpd/dhctoken.h150
-rw-r--r--usr.sbin/dhcpd/parse.c84
8 files changed, 466 insertions, 858 deletions
diff --git a/sbin/dhclient/clparse.c b/sbin/dhclient/clparse.c
index 78ae2f16457..a6a926ca934 100644
--- a/sbin/dhclient/clparse.c
+++ b/sbin/dhclient/clparse.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: clparse.c,v 1.26 2005/08/02 02:34:03 krw Exp $ */
+/* $OpenBSD: clparse.c,v 1.27 2006/04/18 19:17:54 deraadt Exp $ */
/* Parser for dhclient config and lease files... */
@@ -123,7 +123,7 @@ read_client_leases(void)
token = next_token(&val, cfile);
if (token == EOF)
break;
- if (token != LEASE) {
+ if (token != TOK_LEASE) {
warning("Corrupt lease file - possible data loss!");
skip_to_semi(cfile);
break;
@@ -161,75 +161,75 @@ parse_client_statement(FILE *cfile)
int token, code;
switch (next_token(&val, cfile)) {
- case SEND:
+ case TOK_SEND:
parse_option_decl(cfile, &config->send_options[0]);
return;
- case DEFAULT:
+ case TOK_DEFAULT:
code = parse_option_decl(cfile, &config->defaults[0]);
if (code != -1)
config->default_actions[code] = ACTION_DEFAULT;
return;
- case SUPERSEDE:
+ case TOK_SUPERSEDE:
code = parse_option_decl(cfile, &config->defaults[0]);
if (code != -1)
config->default_actions[code] = ACTION_SUPERSEDE;
return;
- case APPEND:
+ case TOK_APPEND:
code = parse_option_decl(cfile, &config->defaults[0]);
if (code != -1)
config->default_actions[code] = ACTION_APPEND;
return;
- case PREPEND:
+ case TOK_PREPEND:
code = parse_option_decl(cfile, &config->defaults[0]);
if (code != -1)
config->default_actions[code] = ACTION_PREPEND;
return;
- case MEDIA:
+ case TOK_MEDIA:
parse_string_list(cfile, &config->media, 1);
return;
- case HARDWARE:
+ case TOK_HARDWARE:
parse_hardware_param(cfile, &ifi->hw_address);
return;
- case REQUEST:
+ case TOK_REQUEST:
config->requested_option_count =
parse_option_list(cfile, config->requested_options);
return;
- case REQUIRE:
+ case TOK_REQUIRE:
memset(config->required_options, 0,
sizeof(config->required_options));
parse_option_list(cfile, config->required_options);
return;
- case TIMEOUT:
+ case TOK_TIMEOUT:
parse_lease_time(cfile, &config->timeout);
return;
- case RETRY:
+ case TOK_RETRY:
parse_lease_time(cfile, &config->retry_interval);
return;
- case SELECT_TIMEOUT:
+ case TOK_SELECT_TIMEOUT:
parse_lease_time(cfile, &config->select_interval);
return;
- case REBOOT:
+ case TOK_REBOOT:
parse_lease_time(cfile, &config->reboot_timeout);
return;
- case BACKOFF_CUTOFF:
+ case TOK_BACKOFF_CUTOFF:
parse_lease_time(cfile, &config->backoff_cutoff);
return;
- case INITIAL_INTERVAL:
+ case TOK_INITIAL_INTERVAL:
parse_lease_time(cfile, &config->initial_interval);
return;
- case SCRIPT:
+ case TOK_SCRIPT:
config->script_name = parse_string(cfile);
return;
- case INTERFACE:
+ case TOK_INTERFACE:
parse_interface_declaration(cfile);
return;
- case LEASE:
+ case TOK_LEASE:
parse_client_lease_statement(cfile, 1);
return;
- case ALIAS:
+ case TOK_ALIAS:
parse_client_lease_statement(cfile, 2);
return;
- case REJECT:
+ case TOK_REJECT:
parse_reject_statement(cfile);
return;
default:
@@ -238,7 +238,7 @@ parse_client_statement(FILE *cfile)
break;
}
token = next_token(&val, cfile);
- if (token != SEMI) {
+ if (token != ';') {
parse_warn("semicolon expected.");
skip_to_semi(cfile);
}
@@ -252,11 +252,11 @@ parse_X(FILE *cfile, u_int8_t *buf, int max)
int len;
token = peek_token(&val, cfile);
- if (token == NUMBER_OR_NAME || token == NUMBER) {
+ if (token == TOK_NUMBER_OR_NAME || token == TOK_NUMBER) {
len = 0;
do {
token = next_token(&val, cfile);
- if (token != NUMBER && token != NUMBER_OR_NAME) {
+ if (token != TOK_NUMBER && token != TOK_NUMBER_OR_NAME) {
parse_warn("expecting hexadecimal constant.");
skip_to_semi(cfile);
return (0);
@@ -268,11 +268,11 @@ parse_X(FILE *cfile, u_int8_t *buf, int max)
return (0);
}
token = peek_token(&val, cfile);
- if (token == COLON)
+ if (token == ':')
token = next_token(&val, cfile);
- } while (token == COLON);
+ } while (token == ':');
val = (char *)buf;
- } else if (token == STRING) {
+ } else if (token == TOK_STRING) {
token = next_token(&val, cfile);
len = strlen(val);
if (len + 1 > max) {
@@ -324,8 +324,8 @@ parse_option_list(FILE *cfile, u_int8_t *list)
return (0);
}
token = next_token(&val, cfile);
- } while (token == COMMA);
- if (token != SEMI) {
+ } while (token == ',');
+ if (token != ';') {
parse_warn("expecting semicolon.");
skip_to_semi(cfile);
return (0);
@@ -344,7 +344,7 @@ parse_interface_declaration(FILE *cfile)
int token;
token = next_token(&val, cfile);
- if (token != STRING) {
+ if (token != TOK_STRING) {
parse_warn("expecting interface name (in quotes).");
skip_to_semi(cfile);
return;
@@ -356,7 +356,7 @@ parse_interface_declaration(FILE *cfile)
}
token = next_token(&val, cfile);
- if (token != LBRACE) {
+ if (token != '{') {
parse_warn("expecting left brace.");
skip_to_semi(cfile);
return;
@@ -368,7 +368,7 @@ parse_interface_declaration(FILE *cfile)
parse_warn("unterminated interface declaration.");
return;
}
- if (token == RBRACE)
+ if (token == '}')
break;
parse_client_statement(cfile);
} while (1);
@@ -393,7 +393,7 @@ parse_client_lease_statement(FILE *cfile, int is_static)
char *val;
token = next_token(&val, cfile);
- if (token != LBRACE) {
+ if (token != '{') {
parse_warn("expecting left brace.");
skip_to_semi(cfile);
return;
@@ -411,7 +411,7 @@ parse_client_lease_statement(FILE *cfile, int is_static)
parse_warn("unterminated lease declaration.");
return;
}
- if (token == RBRACE)
+ if (token == '}')
break;
parse_client_lease_declaration(cfile, lease, &ip);
} while (1);
@@ -513,12 +513,12 @@ parse_client_lease_declaration(FILE *cfile, struct client_lease *lease,
int token;
switch (next_token(&val, cfile)) {
- case BOOTP:
+ case TOK_BOOTP:
lease->is_bootp = 1;
break;
- case INTERFACE:
+ case TOK_INTERFACE:
token = next_token(&val, cfile);
- if (token != STRING) {
+ if (token != TOK_STRING) {
parse_warn("expecting interface name (in quotes).");
skip_to_semi(cfile);
break;
@@ -531,29 +531,29 @@ parse_client_lease_declaration(FILE *cfile, struct client_lease *lease,
}
*ipp = ifi;
break;
- case FIXED_ADDR:
+ case TOK_FIXED_ADDR:
if (!parse_ip_addr(cfile, &lease->address))
return;
break;
- case MEDIUM:
+ case TOK_MEDIUM:
parse_string_list(cfile, &lease->medium, 0);
return;
- case FILENAME:
+ case TOK_FILENAME:
lease->filename = parse_string(cfile);
return;
- case SERVER_NAME:
+ case TOK_SERVER_NAME:
lease->server_name = parse_string(cfile);
return;
- case RENEW:
+ case TOK_RENEW:
lease->renewal = parse_date(cfile);
return;
- case REBIND:
+ case TOK_REBIND:
lease->rebind = parse_date(cfile);
return;
- case EXPIRE:
+ case TOK_EXPIRE:
lease->expiry = parse_date(cfile);
return;
- case OPTION:
+ case TOK_OPTION:
parse_option_decl(cfile, lease->options);
return;
default:
@@ -562,7 +562,7 @@ parse_client_lease_declaration(FILE *cfile, struct client_lease *lease,
break;
}
token = next_token(&val, cfile);
- if (token != SEMI) {
+ if (token != ';') {
parse_warn("expecting semicolon.");
skip_to_semi(cfile);
}
@@ -585,7 +585,7 @@ parse_option_decl(FILE *cfile, struct option_data *options)
token = next_token(&val, cfile);
if (!is_identifier(token)) {
parse_warn("expecting identifier after option keyword.");
- if (token != SEMI)
+ if (token != ';')
skip_to_semi(cfile);
return (-1);
}
@@ -615,7 +615,7 @@ parse_option_decl(FILE *cfile, struct option_data *options)
break;
case 't': /* Text string... */
token = next_token(&val, cfile);
- if (token != STRING) {
+ if (token != TOK_STRING) {
parse_warn("expecting string.");
skip_to_semi(cfile);
return (-1);
@@ -649,10 +649,10 @@ alloc:
case 'L': /* Unsigned 32-bit integer... */
case 'l': /* Signed 32-bit integer... */
token = next_token(&val, cfile);
- if (token != NUMBER) {
+ if (token != TOK_NUMBER) {
need_number:
parse_warn("expecting number.");
- if (token != SEMI)
+ if (token != ';')
skip_to_semi(cfile);
return (-1);
}
@@ -663,7 +663,7 @@ need_number:
case 's': /* Signed 16-bit integer. */
case 'S': /* Unsigned 16-bit integer. */
token = next_token(&val, cfile);
- if (token != NUMBER)
+ if (token != TOK_NUMBER)
goto need_number;
convert_num(buf, val, 0, 16);
len = 2;
@@ -672,7 +672,7 @@ need_number:
case 'b': /* Signed 8-bit integer. */
case 'B': /* Unsigned 8-bit integer. */
token = next_token(&val, cfile);
- if (token != NUMBER)
+ if (token != TOK_NUMBER)
goto need_number;
convert_num(buf, val, 0, 8);
len = 1;
@@ -683,7 +683,7 @@ need_number:
if (!is_identifier(token)) {
parse_warn("expecting identifier.");
bad_flag:
- if (token != SEMI)
+ if (token != ';')
skip_to_semi(cfile);
return (-1);
}
@@ -708,9 +708,9 @@ bad_flag:
}
}
token = next_token(&val, cfile);
- } while (*fmt == 'A' && token == COMMA);
+ } while (*fmt == 'A' && token == ',');
- if (token != SEMI) {
+ if (token != ';') {
parse_warn("semicolon expected.");
skip_to_semi(cfile);
return (-1);
@@ -740,7 +740,7 @@ parse_string_list(FILE *cfile, struct string_list **lp, int multiple)
do {
token = next_token(&val, cfile);
- if (token != STRING) {
+ if (token != TOK_STRING) {
parse_warn("Expecting media options.");
skip_to_semi(cfile);
return;
@@ -760,9 +760,9 @@ parse_string_list(FILE *cfile, struct string_list **lp, int multiple)
cur = tmp;
token = next_token(&val, cfile);
- } while (multiple && token == COMMA);
+ } while (multiple && token == ',');
- if (token != SEMI) {
+ if (token != ';') {
parse_warn("expecting semicolon.");
skip_to_semi(cfile);
}
@@ -793,9 +793,9 @@ parse_reject_statement(FILE *cfile)
config->reject_list = list;
token = next_token(&val, cfile);
- } while (token == COMMA);
+ } while (token == ',');
- if (token != SEMI) {
+ if (token != ';') {
parse_warn("expecting semicolon.");
skip_to_semi(cfile);
}
diff --git a/sbin/dhclient/conflex.c b/sbin/dhclient/conflex.c
index 5e601cc8490..72a091a2112 100644
--- a/sbin/dhclient/conflex.c
+++ b/sbin/dhclient/conflex.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: conflex.c,v 1.10 2005/08/02 18:26:49 moritz Exp $ */
+/* $OpenBSD: conflex.c,v 1.11 2006/04/18 19:17:54 deraadt Exp $ */
/* Lexical scanner for dhcpd config file... */
@@ -250,13 +250,13 @@ read_string(FILE *cfile)
}
tokbuf[i] = 0;
tval = tokbuf;
- return (STRING);
+ return (TOK_STRING);
}
static int
read_number(int c, FILE *cfile)
{
- int seenx = 0, i = 0, token = NUMBER;
+ int seenx = 0, i = 0, token = TOK_NUMBER;
tokbuf[i++] = c;
for (; i < sizeof(tokbuf); i++) {
@@ -284,7 +284,7 @@ static int
read_num_or_name(int c, FILE *cfile)
{
int i = 0;
- int rv = NUMBER_OR_NAME;
+ int rv = TOK_NUMBER_OR_NAME;
tokbuf[i++] = c;
for (; i < sizeof(tokbuf); i++) {
@@ -295,7 +295,7 @@ read_num_or_name(int c, FILE *cfile)
break;
}
if (!isxdigit(c))
- rv = NAME;
+ rv = TOK_NAME;
tokbuf[i] = c;
}
if (i == sizeof(tokbuf)) {
@@ -308,218 +308,59 @@ read_num_or_name(int c, FILE *cfile)
return (intern(tval, rv));
}
+static const struct keywords {
+ const char *k_name;
+ int k_val;
+} keywords[] = {
+ { "alias", TOK_ALIAS },
+ { "append", TOK_APPEND },
+ { "backoff-cutoff", TOK_BACKOFF_CUTOFF },
+ { "bootp", TOK_BOOTP },
+ { "default", TOK_DEFAULT },
+ { "deny", TOK_DENY },
+ { "ethernet", TOK_ETHERNET },
+ { "expire", TOK_EXPIRE },
+ { "fddi", TOK_FDDI },
+ { "filename", TOK_FILENAME },
+ { "fixed-address", TOK_FIXED_ADDR },
+ { "hardware", TOK_HARDWARE },
+ { "initial-interval", TOK_INITIAL_INTERVAL },
+ { "interface", TOK_INTERFACE },
+ { "lease", TOK_LEASE },
+ { "media", TOK_MEDIA },
+ { "medium", TOK_MEDIUM },
+ { "option", TOK_OPTION },
+ { "prepend", TOK_PREPEND },
+ { "rebind", TOK_REBIND },
+ { "reboot", TOK_REBOOT },
+ { "reject", TOK_REJECT },
+ { "renew", TOK_RENEW },
+ { "request", TOK_REQUEST },
+ { "require", TOK_REQUIRE },
+ { "retry", TOK_RETRY },
+ { "script", TOK_SCRIPT },
+ { "select-timeout", TOK_SELECT_TIMEOUT },
+ { "send", TOK_SEND },
+ { "server-name", TOK_SERVER_NAME },
+ { "supersede", TOK_SUPERSEDE },
+ { "timeout", TOK_TIMEOUT },
+ { "token-ring", TOK_TOKEN_RING }
+};
+
+int
+kw_cmp(const void *k, const void *e)
+{
+ return (strcasecmp(k, ((const struct keywords *)e)->k_name));
+}
+
static int
intern(char *atom, int dfv)
{
- if (!isascii(atom[0]))
- return (dfv);
-
- switch (tolower(atom[0])) {
- case 'a':
- if (!strcasecmp(atom + 1, "lways-reply-rfc1048"))
- return (ALWAYS_REPLY_RFC1048);
- if (!strcasecmp(atom + 1, "ppend"))
- return (APPEND);
- if (!strcasecmp(atom + 1, "llow"))
- return (ALLOW);
- if (!strcasecmp(atom + 1, "lias"))
- return (ALIAS);
- if (!strcasecmp(atom + 1, "bandoned"))
- return (ABANDONED);
- if (!strcasecmp(atom + 1, "uthoritative"))
- return (AUTHORITATIVE);
- break;
- case 'b':
- if (!strcasecmp(atom + 1, "ackoff-cutoff"))
- return (BACKOFF_CUTOFF);
- if (!strcasecmp(atom + 1, "ootp"))
- return (BOOTP);
- if (!strcasecmp(atom + 1, "ooting"))
- return (BOOTING);
- if (!strcasecmp(atom + 1, "oot-unknown-clients"))
- return (BOOT_UNKNOWN_CLIENTS);
- break;
- case 'c':
- if (!strcasecmp(atom + 1, "lass"))
- return (CLASS);
- if (!strcasecmp(atom + 1, "iaddr"))
- return (CIADDR);
- if (!strcasecmp(atom + 1, "lient-identifier"))
- return (CLIENT_IDENTIFIER);
- if (!strcasecmp(atom + 1, "lient-hostname"))
- return (CLIENT_HOSTNAME);
- break;
- case 'd':
- if (!strcasecmp(atom + 1, "omain"))
- return (DOMAIN);
- if (!strcasecmp(atom + 1, "eny"))
- return (DENY);
- if (!strncasecmp(atom + 1, "efault", 6)) {
- if (!atom[7])
- return (DEFAULT);
- if (!strcasecmp(atom + 7, "-lease-time"))
- return (DEFAULT_LEASE_TIME);
- break;
- }
- if (!strncasecmp(atom + 1, "ynamic-bootp", 12)) {
- if (!atom[13])
- return (DYNAMIC_BOOTP);
- if (!strcasecmp(atom + 13, "-lease-cutoff"))
- return (DYNAMIC_BOOTP_LEASE_CUTOFF);
- if (!strcasecmp(atom + 13, "-lease-length"))
- return (DYNAMIC_BOOTP_LEASE_LENGTH);
- break;
- }
- break;
- case 'e':
- if (!strcasecmp(atom + 1, "thernet"))
- return (ETHERNET);
- if (!strcasecmp(atom + 1, "nds"))
- return (ENDS);
- if (!strcasecmp(atom + 1, "xpire"))
- return (EXPIRE);
- break;
- case 'f':
- if (!strcasecmp(atom + 1, "ilename"))
- return (FILENAME);
- if (!strcasecmp(atom + 1, "ixed-address"))
- return (FIXED_ADDR);
- if (!strcasecmp(atom + 1, "ddi"))
- return (FDDI);
- break;
- case 'g':
- if (!strcasecmp(atom + 1, "iaddr"))
- return (GIADDR);
- if (!strcasecmp(atom + 1, "roup"))
- return (GROUP);
- if (!strcasecmp(atom + 1, "et-lease-hostnames"))
- return (GET_LEASE_HOSTNAMES);
- break;
- case 'h':
- if (!strcasecmp(atom + 1, "ost"))
- return (HOST);
- if (!strcasecmp(atom + 1, "ardware"))
- return (HARDWARE);
- if (!strcasecmp(atom + 1, "ostname"))
- return (HOSTNAME);
- break;
- case 'i':
- if (!strcasecmp(atom + 1, "nitial-interval"))
- return (INITIAL_INTERVAL);
- if (!strcasecmp(atom + 1, "nterface"))
- return (INTERFACE);
- break;
- case 'l':
- if (!strcasecmp(atom + 1, "ease"))
- return (LEASE);
- break;
- case 'm':
- if (!strcasecmp(atom + 1, "ax-lease-time"))
- return (MAX_LEASE_TIME);
- if (!strncasecmp(atom + 1, "edi", 3)) {
- if (!strcasecmp(atom + 4, "a"))
- return (MEDIA);
- if (!strcasecmp(atom + 4, "um"))
- return (MEDIUM);
- break;
- }
- break;
- case 'n':
- if (!strcasecmp(atom + 1, "ameserver"))
- return (NAMESERVER);
- if (!strcasecmp(atom + 1, "etmask"))
- return (NETMASK);
- if (!strcasecmp(atom + 1, "ext-server"))
- return (NEXT_SERVER);
- if (!strcasecmp(atom + 1, "ot"))
- return (TOKEN_NOT);
- break;
- case 'o':
- if (!strcasecmp(atom + 1, "ption"))
- return (OPTION);
- if (!strcasecmp(atom + 1, "ne-lease-per-client"))
- return (ONE_LEASE_PER_CLIENT);
- break;
- case 'p':
- if (!strcasecmp(atom + 1, "repend"))
- return (PREPEND);
- if (!strcasecmp(atom + 1, "acket"))
- return (PACKET);
- break;
- case 'r':
- if (!strcasecmp(atom + 1, "ange"))
- return (RANGE);
- if (!strcasecmp(atom + 1, "equest"))
- return (REQUEST);
- if (!strcasecmp(atom + 1, "equire"))
- return (REQUIRE);
- if (!strcasecmp(atom + 1, "etry"))
- return (RETRY);
- if (!strcasecmp(atom + 1, "enew"))
- return (RENEW);
- if (!strcasecmp(atom + 1, "ebind"))
- return (REBIND);
- if (!strcasecmp(atom + 1, "eboot"))
- return (REBOOT);
- if (!strcasecmp(atom + 1, "eject"))
- return (REJECT);
- break;
- case 's':
- if (!strcasecmp(atom + 1, "earch"))
- return (SEARCH);
- if (!strcasecmp(atom + 1, "tarts"))
- return (STARTS);
- if (!strcasecmp(atom + 1, "iaddr"))
- return (SIADDR);
- if (!strcasecmp(atom + 1, "ubnet"))
- return (SUBNET);
- if (!strcasecmp(atom + 1, "hared-network"))
- return (SHARED_NETWORK);
- if (!strcasecmp(atom + 1, "erver-name"))
- return (SERVER_NAME);
- if (!strcasecmp(atom + 1, "erver-identifier"))
- return (SERVER_IDENTIFIER);
- if (!strcasecmp(atom + 1, "elect-timeout"))
- return (SELECT_TIMEOUT);
- if (!strcasecmp(atom + 1, "end"))
- return (SEND);
- if (!strcasecmp(atom + 1, "cript"))
- return (SCRIPT);
- if (!strcasecmp(atom + 1, "upersede"))
- return (SUPERSEDE);
- break;
- case 't':
- if (!strcasecmp(atom + 1, "imestamp"))
- return (TIMESTAMP);
- if (!strcasecmp(atom + 1, "imeout"))
- return (TIMEOUT);
- if (!strcasecmp(atom + 1, "oken-ring"))
- return (TOKEN_RING);
- break;
- case 'u':
- if (!strncasecmp(atom + 1, "se", 2)) {
- if (!strcasecmp(atom + 3, "r-class"))
- return (USER_CLASS);
- if (!strcasecmp(atom + 3, "-host-decl-names"))
- return (USE_HOST_DECL_NAMES);
- if (!strcasecmp(atom + 3,
- "-lease-addr-for-default-route"))
- return (USE_LEASE_ADDR_FOR_DEFAULT_ROUTE);
- break;
- }
- if (!strcasecmp(atom + 1, "id"))
- return (UID);
- if (!strcasecmp(atom + 1, "nknown-clients"))
- return (UNKNOWN_CLIENTS);
- break;
- case 'v':
- if (!strcasecmp(atom + 1, "endor-class"))
- return (VENDOR_CLASS);
- break;
- case 'y':
- if (!strcasecmp(atom + 1, "iaddr"))
- return (YIADDR);
- break;
- }
+ const struct keywords *p;
+
+ p = bsearch(atom, keywords, sizeof(keywords)/sizeof(keywords[0]),
+ sizeof(keywords[0]), kw_cmp);
+ if (p)
+ return (p->k_val);
return (dfv);
}
diff --git a/sbin/dhclient/dhctoken.h b/sbin/dhclient/dhctoken.h
index 7b23242fbac..8b62480e95d 100644
--- a/sbin/dhclient/dhctoken.h
+++ b/sbin/dhclient/dhctoken.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: dhctoken.h,v 1.2 2004/02/04 12:16:56 henning Exp $ */
+/* $OpenBSD: dhctoken.h,v 1.3 2006/04/18 19:17:54 deraadt Exp $ */
/* Tokens for config file lexer and parser. */
@@ -40,97 +40,46 @@
* Enterprises, see ``http://www.vix.com''.
*/
-#define SEMI ';'
-#define DOT '.'
-#define COLON ':'
-#define COMMA ','
-#define SLASH '/'
-#define LBRACE '{'
-#define RBRACE '}'
+#define TOK_FIRST_TOKEN TOK_HARDWARE
+#define TOK_HARDWARE 257
+#define TOK_FILENAME 258
+#define TOK_FIXED_ADDR 259
+#define TOK_OPTION 260
+#define TOK_ETHERNET 261
+#define TOK_STRING 262
+#define TOK_NUMBER 263
+#define TOK_NUMBER_OR_NAME 264
+#define TOK_NAME 265
+#define TOK_LEASE 266
+#define TOK_SERVER_NAME 267
+#define TOK_TOKEN_RING 268
+#define TOK_SEND 269
+#define TOK_REQUEST 270
+#define TOK_REQUIRE 271
+#define TOK_TIMEOUT 272
+#define TOK_RETRY 273
+#define TOK_SELECT_TIMEOUT 274
+#define TOK_SCRIPT 275
+#define TOK_INTERFACE 276
+#define TOK_RENEW 277
+#define TOK_REBIND 278
+#define TOK_EXPIRE 279
+#define TOK_BOOTP 280
+#define TOK_DENY 281
+#define TOK_DEFAULT 282
+#define TOK_MEDIA 283
+#define TOK_MEDIUM 284
+#define TOK_ALIAS 285
+#define TOK_REBOOT 286
+#define TOK_BACKOFF_CUTOFF 287
+#define TOK_INITIAL_INTERVAL 288
+#define TOK_SUPERSEDE 289
+#define TOK_APPEND 290
+#define TOK_PREPEND 291
+#define TOK_REJECT 292
+#define TOK_FDDI 293
-#define FIRST_TOKEN HOST
-#define HOST 256
-#define HARDWARE 257
-#define FILENAME 258
-#define FIXED_ADDR 259
-#define OPTION 260
-#define ETHERNET 261
-#define STRING 262
-#define NUMBER 263
-#define NUMBER_OR_NAME 264
-#define NAME 265
-#define TIMESTAMP 266
-#define STARTS 267
-#define ENDS 268
-#define UID 269
-#define CLASS 270
-#define LEASE 271
-#define RANGE 272
-#define PACKET 273
-#define CIADDR 274
-#define YIADDR 275
-#define SIADDR 276
-#define GIADDR 277
-#define SUBNET 278
-#define NETMASK 279
-#define DEFAULT_LEASE_TIME 280
-#define MAX_LEASE_TIME 281
-#define VENDOR_CLASS 282
-#define USER_CLASS 283
-#define SHARED_NETWORK 284
-#define SERVER_NAME 285
-#define DYNAMIC_BOOTP 286
-#define SERVER_IDENTIFIER 287
-#define DYNAMIC_BOOTP_LEASE_CUTOFF 288
-#define DYNAMIC_BOOTP_LEASE_LENGTH 289
-#define BOOT_UNKNOWN_CLIENTS 290
-#define NEXT_SERVER 291
-#define TOKEN_RING 292
-#define GROUP 293
-#define ONE_LEASE_PER_CLIENT 294
-#define GET_LEASE_HOSTNAMES 295
-#define USE_HOST_DECL_NAMES 296
-#define SEND 297
-#define CLIENT_IDENTIFIER 298
-#define REQUEST 299
-#define REQUIRE 300
-#define TIMEOUT 301
-#define RETRY 302
-#define SELECT_TIMEOUT 303
-#define SCRIPT 304
-#define INTERFACE 305
-#define RENEW 306
-#define REBIND 307
-#define EXPIRE 308
-#define UNKNOWN_CLIENTS 309
-#define ALLOW 310
-#define BOOTP 311
-#define DENY 312
-#define BOOTING 313
-#define DEFAULT 314
-#define MEDIA 315
-#define MEDIUM 316
-#define ALIAS 317
-#define REBOOT 318
-#define ABANDONED 319
-#define BACKOFF_CUTOFF 320
-#define INITIAL_INTERVAL 321
-#define NAMESERVER 322
-#define DOMAIN 323
-#define SEARCH 324
-#define SUPERSEDE 325
-#define APPEND 326
-#define PREPEND 327
-#define HOSTNAME 328
-#define CLIENT_HOSTNAME 329
-#define REJECT 330
-#define FDDI 331
-#define USE_LEASE_ADDR_FOR_DEFAULT_ROUTE 332
-#define AUTHORITATIVE 333
-#define TOKEN_NOT 334
-#define ALWAYS_REPLY_RFC1048 335
-
-#define is_identifier(x) ((x) >= FIRST_TOKEN && \
- (x) != STRING && \
- (x) != NUMBER && \
+#define is_identifier(x) ((x) >= TOK_FIRST_TOKEN && \
+ (x) != TOK_STRING && \
+ (x) != TOK_NUMBER && \
(x) != EOF)
diff --git a/sbin/dhclient/parse.c b/sbin/dhclient/parse.c
index fb88f307fcc..c17c76da67f 100644
--- a/sbin/dhclient/parse.c
+++ b/sbin/dhclient/parse.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: parse.c,v 1.13 2005/07/17 19:33:55 krw Exp $ */
+/* $OpenBSD: parse.c,v 1.14 2006/04/18 19:17:54 deraadt Exp $ */
/* Common parser code for dhcpd and dhclient. */
@@ -65,16 +65,16 @@ skip_to_semi(FILE *cfile)
do {
token = peek_token(&val, cfile);
- if (token == RBRACE) {
+ if (token == '}') {
if (brace_count) {
token = next_token(&val, cfile);
if (!--brace_count)
return;
} else
return;
- } else if (token == LBRACE) {
+ } else if (token == '{') {
brace_count++;
- } else if (token == SEMI && !brace_count) {
+ } else if (token == ';' && !brace_count) {
token = next_token(&val, cfile);
return;
} else if (token == '\n') {
@@ -98,7 +98,7 @@ parse_semi(FILE *cfile)
char *val;
token = next_token(&val, cfile);
- if (token != SEMI) {
+ if (token != ';') {
parse_warn("semicolon expected.");
skip_to_semi(cfile);
return (0);
@@ -116,7 +116,7 @@ parse_string(FILE *cfile)
int token;
token = next_token(&val, cfile);
- if (token != STRING) {
+ if (token != TOK_STRING) {
parse_warn("filename must be a string");
skip_to_semi(cfile);
return (NULL);
@@ -135,7 +135,7 @@ int
parse_ip_addr(FILE *cfile, struct iaddr *addr)
{
addr->len = 4;
- return (parse_numeric_aggregate(cfile, addr->iabuf, addr->len, DOT,
+ return (parse_numeric_aggregate(cfile, addr->iabuf, addr->len, '.',
10));
}
@@ -151,15 +151,15 @@ parse_hardware_param(FILE *cfile, struct hardware *hardware)
token = next_token(&val, cfile);
switch (token) {
- case ETHERNET:
+ case TOK_ETHERNET:
hardware->htype = HTYPE_ETHER;
hardware->hlen = 6;
break;
- case TOKEN_RING:
+ case TOK_TOKEN_RING:
hardware->htype = HTYPE_IEEE802;
hardware->hlen = 6;
break;
- case FDDI:
+ case TOK_FDDI:
hardware->htype = HTYPE_FDDI;
hardware->hlen = 6;
break;
@@ -170,11 +170,11 @@ parse_hardware_param(FILE *cfile, struct hardware *hardware)
}
if (parse_numeric_aggregate(cfile, hardware->haddr, hardware->hlen,
- COLON, 16) == 0)
+ ':', 16) == 0)
return;
token = next_token(&val, cfile);
- if (token != SEMI) {
+ if (token != ';') {
parse_warn("expecting semicolon.");
skip_to_semi(cfile);
}
@@ -190,7 +190,7 @@ parse_lease_time(FILE *cfile, time_t *timep)
int token;
token = next_token(&val, cfile);
- if (token != NUMBER) {
+ if (token != TOK_NUMBER) {
parse_warn("Expecting numeric lease time");
skip_to_semi(cfile);
return;
@@ -222,7 +222,7 @@ parse_numeric_aggregate(FILE *cfile, unsigned char *buf, int max, int separator,
token = next_token(&val, cfile);
- if (token == NUMBER || (base == 16 && token == NUMBER_OR_NAME))
+ if (token == TOK_NUMBER || (base == 16 && token == TOK_NUMBER_OR_NAME))
/* XXX Need to check if conversion was successful. */
convert_num(buf, val, base, 8);
else
@@ -357,9 +357,9 @@ parse_date(FILE *cfile)
/* Day of week... */
token = next_token(&val, cfile);
- if (token != NUMBER) {
+ if (token != TOK_NUMBER) {
parse_warn("numeric day of week expected.");
- if (token != SEMI)
+ if (token != ';')
skip_to_semi(cfile);
return (0);
}
@@ -367,9 +367,9 @@ parse_date(FILE *cfile)
/* Year... */
token = next_token(&val, cfile);
- if (token != NUMBER) {
+ if (token != TOK_NUMBER) {
parse_warn("numeric year expected.");
- if (token != SEMI)
+ if (token != ';')
skip_to_semi(cfile);
return (0);
}
@@ -379,18 +379,18 @@ parse_date(FILE *cfile)
/* Slash separating year from month... */
token = next_token(&val, cfile);
- if (token != SLASH) {
+ if (token != '/') {
parse_warn("expected slash separating year from month.");
- if (token != SEMI)
+ if (token != ';')
skip_to_semi(cfile);
return (0);
}
/* Month... */
token = next_token(&val, cfile);
- if (token != NUMBER) {
+ if (token != TOK_NUMBER) {
parse_warn("numeric month expected.");
- if (token != SEMI)
+ if (token != ';')
skip_to_semi(cfile);
return (0);
}
@@ -398,18 +398,18 @@ parse_date(FILE *cfile)
/* Slash separating month from day... */
token = next_token(&val, cfile);
- if (token != SLASH) {
+ if (token != '/') {
parse_warn("expected slash separating month from day.");
- if (token != SEMI)
+ if (token != ';')
skip_to_semi(cfile);
return (0);
}
/* Month... */
token = next_token(&val, cfile);
- if (token != NUMBER) {
+ if (token != TOK_NUMBER) {
parse_warn("numeric day of month expected.");
- if (token != SEMI)
+ if (token != ';')
skip_to_semi(cfile);
return (0);
}
@@ -417,9 +417,9 @@ parse_date(FILE *cfile)
/* Hour... */
token = next_token(&val, cfile);
- if (token != NUMBER) {
+ if (token != TOK_NUMBER) {
parse_warn("numeric hour expected.");
- if (token != SEMI)
+ if (token != ';')
skip_to_semi(cfile);
return (0);
}
@@ -427,18 +427,18 @@ parse_date(FILE *cfile)
/* Colon separating hour from minute... */
token = next_token(&val, cfile);
- if (token != COLON) {
+ if (token != ':') {
parse_warn("expected colon separating hour from minute.");
- if (token != SEMI)
+ if (token != ';')
skip_to_semi(cfile);
return (0);
}
/* Minute... */
token = next_token(&val, cfile);
- if (token != NUMBER) {
+ if (token != TOK_NUMBER) {
parse_warn("numeric minute expected.");
- if (token != SEMI)
+ if (token != ';')
skip_to_semi(cfile);
return (0);
}
@@ -446,18 +446,18 @@ parse_date(FILE *cfile)
/* Colon separating minute from second... */
token = next_token(&val, cfile);
- if (token != COLON) {
+ if (token != ':') {
parse_warn("expected colon separating hour from minute.");
- if (token != SEMI)
+ if (token != ';')
skip_to_semi(cfile);
return (0);
}
/* Minute... */
token = next_token(&val, cfile);
- if (token != NUMBER) {
+ if (token != TOK_NUMBER) {
parse_warn("numeric minute expected.");
- if (token != SEMI)
+ if (token != ';')
skip_to_semi(cfile);
return (0);
}
@@ -469,7 +469,7 @@ parse_date(FILE *cfile)
/* Make sure the date ends in a semicolon... */
token = next_token(&val, cfile);
- if (token != SEMI) {
+ if (token != ';') {
parse_warn("semicolon expected.");
skip_to_semi(cfile);
return (0);
diff --git a/usr.sbin/dhcpd/conflex.c b/usr.sbin/dhcpd/conflex.c
index 213cc84853a..64ed08595d9 100644
--- a/usr.sbin/dhcpd/conflex.c
+++ b/usr.sbin/dhcpd/conflex.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: conflex.c,v 1.6 2005/11/25 16:24:12 krw Exp $ */
+/* $OpenBSD: conflex.c,v 1.7 2006/04/18 19:18:31 deraadt Exp $ */
/* Lexical scanner for dhcpd config file... */
@@ -251,13 +251,13 @@ read_string(FILE *cfile)
}
tokbuf[i] = 0;
tval = tokbuf;
- return (STRING);
+ return (TOK_STRING);
}
static int
read_number(int c, FILE *cfile)
{
- int seenx = 0, i = 0, token = NUMBER;
+ int seenx = 0, i = 0, token = TOK_NUMBER;
tokbuf[i++] = c;
for (; i < sizeof(tokbuf); i++) {
@@ -285,7 +285,7 @@ static int
read_num_or_name(int c, FILE *cfile)
{
int i = 0;
- int rv = NUMBER_OR_NAME;
+ int rv = TOK_NUMBER_OR_NAME;
tokbuf[i++] = c;
for (; i < sizeof(tokbuf); i++) {
@@ -296,7 +296,7 @@ read_num_or_name(int c, FILE *cfile)
break;
}
if (!isxdigit(c))
- rv = NAME;
+ rv = TOK_NAME;
tokbuf[i] = c;
}
if (i == sizeof(tokbuf)) {
@@ -309,218 +309,72 @@ read_num_or_name(int c, FILE *cfile)
return (intern(tval, rv));
}
+static const struct keywords {
+ const char *k_name;
+ int k_val;
+} keywords[] = {
+ { "abandoned", TOK_ABANDONED },
+ { "allow", TOK_ALLOW },
+ { "always-reply-rfc1048", TOK_ALWAYS_REPLY_RFC1048 },
+ { "authoritative", TOK_AUTHORITATIVE },
+ { "booting", TOK_BOOTING },
+ { "bootp", TOK_BOOTP },
+ { "class", TOK_CLASS },
+ { "client-hostname", TOK_CLIENT_HOSTNAME },
+ { "default-lease-time", TOK_DEFAULT_LEASE_TIME },
+ { "deny", TOK_DENY },
+ { "domain", TOK_DOMAIN },
+ { "dynamic-bootp", TOK_DYNAMIC_BOOTP },
+ { "dynamic-bootp-lease-cutoff", TOK_DYNAMIC_BOOTP_LEASE_CUTOFF },
+ { "dynamic-bootp-lease-length", TOK_DYNAMIC_BOOTP_LEASE_LENGTH },
+ { "ends", TOK_ENDS },
+ { "ethernet", TOK_ETHERNET },
+ { "fddi", TOK_FDDI },
+ { "filename", TOK_FILENAME },
+ { "fixed-address", TOK_FIXED_ADDR },
+ { "get-lease-hostnames", TOK_GET_LEASE_HOSTNAMES },
+ { "group", TOK_GROUP },
+ { "hardware", TOK_HARDWARE },
+ { "host", TOK_HOST },
+ { "hostname", TOK_HOSTNAME },
+ { "lease", TOK_LEASE },
+ { "max-lease-time", TOK_MAX_LEASE_TIME },
+ { "netmask", TOK_NETMASK },
+ { "next-server", TOK_NEXT_SERVER },
+ { "not", TOK_TOKEN_NOT },
+ { "one-lease-per-client", TOK_ONE_LEASE_PER_CLIENT },
+ { "option", TOK_OPTION },
+ { "range", TOK_RANGE },
+ { "server-identifier", TOK_SERVER_IDENTIFIER },
+ { "server-name", TOK_SERVER_NAME },
+ { "shared-network", TOK_SHARED_NETWORK },
+ { "starts", TOK_STARTS },
+ { "subnet", TOK_SUBNET },
+ { "timeout", TOK_TIMEOUT },
+ { "timestamp", TOK_TIMESTAMP },
+ { "token-ring", TOK_TOKEN_RING },
+ { "uid", TOK_UID },
+ { "unknown-clients", TOK_UNKNOWN_CLIENTS },
+ { "user-class", TOK_USER_CLASS },
+ { "use-host-decl-names", TOK_USE_HOST_DECL_NAMES },
+ { "use-lease-addr-for-default-route", TOK_USE_LEASE_ADDR_FOR_DEFAULT_ROUTE },
+ { "vendor-class", TOK_VENDOR_CLASS }
+};
+
+int
+kw_cmp(const void *k, const void *e)
+{
+ return (strcasecmp(k, ((const struct keywords *)e)->k_name));
+}
+
static int
intern(char *atom, int dfv)
{
- if (!isascii(atom[0]))
- return (dfv);
-
- switch (tolower(atom[0])) {
- case 'a':
- if (!strcasecmp(atom + 1, "lways-reply-rfc1048"))
- return (ALWAYS_REPLY_RFC1048);
- if (!strcasecmp(atom + 1, "ppend"))
- return (APPEND);
- if (!strcasecmp(atom + 1, "llow"))
- return (ALLOW);
- if (!strcasecmp(atom + 1, "lias"))
- return (ALIAS);
- if (!strcasecmp(atom + 1, "bandoned"))
- return (ABANDONED);
- if (!strcasecmp(atom + 1, "uthoritative"))
- return (AUTHORITATIVE);
- break;
- case 'b':
- if (!strcasecmp(atom + 1, "ackoff-cutoff"))
- return (BACKOFF_CUTOFF);
- if (!strcasecmp(atom + 1, "ootp"))
- return (BOOTP);
- if (!strcasecmp(atom + 1, "ooting"))
- return (BOOTING);
- if (!strcasecmp(atom + 1, "oot-unknown-clients"))
- return (BOOT_UNKNOWN_CLIENTS);
- break;
- case 'c':
- if (!strcasecmp(atom + 1, "lass"))
- return (CLASS);
- if (!strcasecmp(atom + 1, "iaddr"))
- return (CIADDR);
- if (!strcasecmp(atom + 1, "lient-identifier"))
- return (CLIENT_IDENTIFIER);
- if (!strcasecmp(atom + 1, "lient-hostname"))
- return (CLIENT_HOSTNAME);
- break;
- case 'd':
- if (!strcasecmp(atom + 1, "omain"))
- return (DOMAIN);
- if (!strcasecmp(atom + 1, "eny"))
- return (DENY);
- if (!strncasecmp(atom + 1, "efault", 6)) {
- if (!atom[7])
- return (DEFAULT);
- if (!strcasecmp(atom + 7, "-lease-time"))
- return (DEFAULT_LEASE_TIME);
- break;
- }
- if (!strncasecmp(atom + 1, "ynamic-bootp", 12)) {
- if (!atom[13])
- return (DYNAMIC_BOOTP);
- if (!strcasecmp(atom + 13, "-lease-cutoff"))
- return (DYNAMIC_BOOTP_LEASE_CUTOFF);
- if (!strcasecmp(atom + 13, "-lease-length"))
- return (DYNAMIC_BOOTP_LEASE_LENGTH);
- break;
- }
- break;
- case 'e':
- if (!strcasecmp(atom + 1, "thernet"))
- return (ETHERNET);
- if (!strcasecmp(atom + 1, "nds"))
- return (ENDS);
- if (!strcasecmp(atom + 1, "xpire"))
- return (EXPIRE);
- break;
- case 'f':
- if (!strcasecmp(atom + 1, "ilename"))
- return (FILENAME);
- if (!strcasecmp(atom + 1, "ixed-address"))
- return (FIXED_ADDR);
- if (!strcasecmp(atom + 1, "ddi"))
- return (FDDI);
- break;
- case 'g':
- if (!strcasecmp(atom + 1, "iaddr"))
- return (GIADDR);
- if (!strcasecmp(atom + 1, "roup"))
- return (GROUP);
- if (!strcasecmp(atom + 1, "et-lease-hostnames"))
- return (GET_LEASE_HOSTNAMES);
- break;
- case 'h':
- if (!strcasecmp(atom + 1, "ost"))
- return (HOST);
- if (!strcasecmp(atom + 1, "ardware"))
- return (HARDWARE);
- if (!strcasecmp(atom + 1, "ostname"))
- return (HOSTNAME);
- break;
- case 'i':
- if (!strcasecmp(atom + 1, "nitial-interval"))
- return (INITIAL_INTERVAL);
- if (!strcasecmp(atom + 1, "nterface"))
- return (INTERFACE);
- break;
- case 'l':
- if (!strcasecmp(atom + 1, "ease"))
- return (LEASE);
- break;
- case 'm':
- if (!strcasecmp(atom + 1, "ax-lease-time"))
- return (MAX_LEASE_TIME);
- if (!strncasecmp(atom + 1, "edi", 3)) {
- if (!strcasecmp(atom + 4, "a"))
- return (MEDIA);
- if (!strcasecmp(atom + 4, "um"))
- return (MEDIUM);
- break;
- }
- break;
- case 'n':
- if (!strcasecmp(atom + 1, "ameserver"))
- return (NAMESERVER);
- if (!strcasecmp(atom + 1, "etmask"))
- return (NETMASK);
- if (!strcasecmp(atom + 1, "ext-server"))
- return (NEXT_SERVER);
- if (!strcasecmp(atom + 1, "ot"))
- return (TOKEN_NOT);
- break;
- case 'o':
- if (!strcasecmp(atom + 1, "ption"))
- return (OPTION);
- if (!strcasecmp(atom + 1, "ne-lease-per-client"))
- return (ONE_LEASE_PER_CLIENT);
- break;
- case 'p':
- if (!strcasecmp(atom + 1, "repend"))
- return (PREPEND);
- if (!strcasecmp(atom + 1, "acket"))
- return (PACKET);
- break;
- case 'r':
- if (!strcasecmp(atom + 1, "ange"))
- return (RANGE);
- if (!strcasecmp(atom + 1, "equest"))
- return (REQUEST);
- if (!strcasecmp(atom + 1, "equire"))
- return (REQUIRE);
- if (!strcasecmp(atom + 1, "etry"))
- return (RETRY);
- if (!strcasecmp(atom + 1, "enew"))
- return (RENEW);
- if (!strcasecmp(atom + 1, "ebind"))
- return (REBIND);
- if (!strcasecmp(atom + 1, "eboot"))
- return (REBOOT);
- if (!strcasecmp(atom + 1, "eject"))
- return (REJECT);
- break;
- case 's':
- if (!strcasecmp(atom + 1, "earch"))
- return (SEARCH);
- if (!strcasecmp(atom + 1, "tarts"))
- return (STARTS);
- if (!strcasecmp(atom + 1, "iaddr"))
- return (SIADDR);
- if (!strcasecmp(atom + 1, "ubnet"))
- return (SUBNET);
- if (!strcasecmp(atom + 1, "hared-network"))
- return (SHARED_NETWORK);
- if (!strcasecmp(atom + 1, "erver-name"))
- return (SERVER_NAME);
- if (!strcasecmp(atom + 1, "erver-identifier"))
- return (SERVER_IDENTIFIER);
- if (!strcasecmp(atom + 1, "elect-timeout"))
- return (SELECT_TIMEOUT);
- if (!strcasecmp(atom + 1, "end"))
- return (SEND);
- if (!strcasecmp(atom + 1, "cript"))
- return (SCRIPT);
- if (!strcasecmp(atom + 1, "upersede"))
- return (SUPERSEDE);
- break;
- case 't':
- if (!strcasecmp(atom + 1, "imestamp"))
- return (TIMESTAMP);
- if (!strcasecmp(atom + 1, "imeout"))
- return (TIMEOUT);
- if (!strcasecmp(atom + 1, "oken-ring"))
- return (TOKEN_RING);
- break;
- case 'u':
- if (!strncasecmp(atom + 1, "se", 2)) {
- if (!strcasecmp(atom + 3, "r-class"))
- return (USER_CLASS);
- if (!strcasecmp(atom + 3, "-host-decl-names"))
- return (USE_HOST_DECL_NAMES);
- if (!strcasecmp(atom + 3,
- "-lease-addr-for-default-route"))
- return (USE_LEASE_ADDR_FOR_DEFAULT_ROUTE);
- break;
- }
- if (!strcasecmp(atom + 1, "id"))
- return (UID);
- if (!strcasecmp(atom + 1, "nknown-clients"))
- return (UNKNOWN_CLIENTS);
- break;
- case 'v':
- if (!strcasecmp(atom + 1, "endor-class"))
- return (VENDOR_CLASS);
- break;
- case 'y':
- if (!strcasecmp(atom + 1, "iaddr"))
- return (YIADDR);
- break;
- }
+ const struct keywords *p;
+
+ p = bsearch(atom, keywords, sizeof(keywords)/sizeof(keywords[0]),
+ sizeof(keywords[0]), kw_cmp);
+ if (p)
+ return (p->k_val);
return (dfv);
}
diff --git a/usr.sbin/dhcpd/confpars.c b/usr.sbin/dhcpd/confpars.c
index ccd28843740..36eaf118bd6 100644
--- a/usr.sbin/dhcpd/confpars.c
+++ b/usr.sbin/dhcpd/confpars.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: confpars.c,v 1.13 2006/03/13 19:57:42 otto Exp $ */
+/* $OpenBSD: confpars.c,v 1.14 2006/04/18 19:18:32 deraadt Exp $ */
/*
* Copyright (c) 1995, 1996, 1997 The Internet Software Consortium.
@@ -120,7 +120,7 @@ read_leases(void)
token = next_token(&val, cfile);
if (token == EOF)
break;
- if (token != LEASE) {
+ if (token != TOK_LEASE) {
warning("Corrupt lease file - possible data loss!");
skip_to_semi(cfile);
} else {
@@ -182,7 +182,7 @@ int parse_statement(cfile, group, type, host_decl, declaration)
struct hardware hardware;
switch (next_token(&val, cfile)) {
- case HOST:
+ case TOK_HOST:
if (type != HOST_DECL)
parse_host_declaration(cfile, group);
else {
@@ -191,7 +191,7 @@ int parse_statement(cfile, group, type, host_decl, declaration)
}
return 1;
- case GROUP:
+ case TOK_GROUP:
if (type != HOST_DECL)
parse_group_declaration(cfile, group);
else {
@@ -200,10 +200,10 @@ int parse_statement(cfile, group, type, host_decl, declaration)
}
return 1;
- case TIMESTAMP:
+ case TOK_TIMESTAMP:
break;
- case SHARED_NETWORK:
+ case TOK_SHARED_NETWORK:
if (type == SHARED_NET_DECL ||
type == HOST_DECL ||
type == SUBNET_DECL) {
@@ -216,7 +216,7 @@ int parse_statement(cfile, group, type, host_decl, declaration)
parse_shared_net_declaration(cfile, group);
return 1;
- case SUBNET:
+ case TOK_SUBNET:
if (type == HOST_DECL || type == SUBNET_DECL) {
parse_warn("subnet declarations not allowed here.");
skip_to_semi(cfile);
@@ -262,67 +262,67 @@ int parse_statement(cfile, group, type, host_decl, declaration)
}
return 1;
- case VENDOR_CLASS:
+ case TOK_VENDOR_CLASS:
parse_class_declaration(cfile, group, 0);
return 1;
- case USER_CLASS:
+ case TOK_USER_CLASS:
parse_class_declaration(cfile, group, 1);
return 1;
- case DEFAULT_LEASE_TIME:
+ case TOK_DEFAULT_LEASE_TIME:
parse_lease_time(cfile, &group->default_lease_time);
break;
- case MAX_LEASE_TIME:
+ case TOK_MAX_LEASE_TIME:
parse_lease_time(cfile, &group->max_lease_time);
break;
- case DYNAMIC_BOOTP_LEASE_CUTOFF:
+ case TOK_DYNAMIC_BOOTP_LEASE_CUTOFF:
group->bootp_lease_cutoff = parse_date(cfile);
break;
- case DYNAMIC_BOOTP_LEASE_LENGTH:
+ case TOK_DYNAMIC_BOOTP_LEASE_LENGTH:
parse_lease_time(cfile, &group->bootp_lease_length);
break;
- case BOOT_UNKNOWN_CLIENTS:
+ case TOK_BOOT_UNKNOWN_CLIENTS:
if (type == HOST_DECL)
parse_warn("boot-unknown-clients not allowed here.");
group->boot_unknown_clients = parse_boolean(cfile);
break;
- case ONE_LEASE_PER_CLIENT:
+ case TOK_ONE_LEASE_PER_CLIENT:
if (type == HOST_DECL)
parse_warn("one-lease-per-client not allowed here.");
group->one_lease_per_client = parse_boolean(cfile);
break;
- case GET_LEASE_HOSTNAMES:
+ case TOK_GET_LEASE_HOSTNAMES:
if (type == HOST_DECL)
parse_warn("get-lease-hostnames not allowed here.");
group->get_lease_hostnames = parse_boolean(cfile);
break;
- case ALWAYS_REPLY_RFC1048:
+ case TOK_ALWAYS_REPLY_RFC1048:
group->always_reply_rfc1048 = parse_boolean(cfile);
break;
- case USE_HOST_DECL_NAMES:
+ case TOK_USE_HOST_DECL_NAMES:
if (type == HOST_DECL)
parse_warn("use-host-decl-names not allowed here.");
group->use_host_decl_names = parse_boolean(cfile);
break;
- case USE_LEASE_ADDR_FOR_DEFAULT_ROUTE:
+ case TOK_USE_LEASE_ADDR_FOR_DEFAULT_ROUTE:
group->use_lease_addr_for_default_route =
parse_boolean(cfile);
break;
- case TOKEN_NOT:
+ case TOK_TOKEN_NOT:
token = next_token(&val, cfile);
switch (token) {
- case AUTHORITATIVE:
+ case TOK_AUTHORITATIVE:
if (type == HOST_DECL)
parse_warn("authority makes no sense here.");
group->authoritative = 0;
@@ -335,14 +335,14 @@ int parse_statement(cfile, group, type, host_decl, declaration)
}
break;
- case AUTHORITATIVE:
+ case TOK_AUTHORITATIVE:
if (type == HOST_DECL)
parse_warn("authority makes no sense here.");
group->authoritative = 1;
parse_semi(cfile);
break;
- case NEXT_SERVER:
+ case TOK_NEXT_SERVER:
tree = parse_ip_addr_or_hostname(cfile, 0);
if (!tree)
break;
@@ -355,11 +355,11 @@ int parse_statement(cfile, group, type, host_decl, declaration)
parse_semi(cfile);
break;
- case OPTION:
+ case TOK_OPTION:
parse_option_param(cfile, group);
break;
- case SERVER_IDENTIFIER:
+ case TOK_SERVER_IDENTIFIER:
tree = parse_ip_addr_or_hostname(cfile, 0);
if (!tree)
return declaration;
@@ -367,15 +367,15 @@ int parse_statement(cfile, group, type, host_decl, declaration)
token = next_token(&val, cfile);
break;
- case FILENAME:
+ case TOK_FILENAME:
group->filename = parse_string(cfile);
break;
- case SERVER_NAME:
+ case TOK_SERVER_NAME:
group->server_name = parse_string(cfile);
break;
- case HARDWARE:
+ case TOK_HARDWARE:
parse_hardware_param(cfile, &hardware);
if (host_decl)
host_decl->interface = hardware;
@@ -384,7 +384,7 @@ int parse_statement(cfile, group, type, host_decl, declaration)
"not allowed here.");
break;
- case FIXED_ADDR:
+ case TOK_FIXED_ADDR:
cache = parse_fixed_addr_param(cfile);
if (host_decl)
host_decl->fixed_addr = cache;
@@ -393,7 +393,7 @@ int parse_statement(cfile, group, type, host_decl, declaration)
"allowed here.");
break;
- case RANGE:
+ case TOK_RANGE:
if (type != SUBNET_DECL || !group->subnet) {
parse_warn("range declaration not allowed here.");
skip_to_semi(cfile);
@@ -402,11 +402,11 @@ int parse_statement(cfile, group, type, host_decl, declaration)
parse_address_range(cfile, group->subnet);
return declaration;
- case ALLOW:
+ case TOK_ALLOW:
parse_allow_deny(cfile, group, 1);
break;
- case DENY:
+ case TOK_DENY:
parse_allow_deny(cfile, group, 0);
break;
@@ -442,19 +442,19 @@ void parse_allow_deny(cfile, group, flag)
token = next_token(&val, cfile);
switch (token) {
- case BOOTP:
+ case TOK_BOOTP:
group->allow_bootp = flag;
break;
- case BOOTING:
+ case TOK_BOOTING:
group->allow_booting = flag;
break;
- case DYNAMIC_BOOTP:
+ case TOK_DYNAMIC_BOOTP:
group->dynamic_bootp = flag;
break;
- case UNKNOWN_CLIENTS:
+ case TOK_UNKNOWN_CLIENTS:
group->boot_unknown_clients = flag;
break;
@@ -498,7 +498,7 @@ parse_lbrace(FILE *cfile)
char *val;
token = next_token(&val, cfile);
- if (token != LBRACE) {
+ if (token != '{') {
parse_warn("expecting left brace.");
skip_to_semi(cfile);
return 0;
@@ -507,7 +507,7 @@ parse_lbrace(FILE *cfile)
}
-/* host-declaration :== hostname RBRACE parameters declarations LBRACE */
+/* host-declaration :== hostname '{' parameters declarations '}' */
void parse_host_declaration(cfile, group)
FILE *cfile;
@@ -535,7 +535,7 @@ void parse_host_declaration(cfile, group)
do {
token = peek_token(&val, cfile);
- if (token == RBRACE) {
+ if (token == '}') {
token = next_token(&val, cfile);
break;
}
@@ -568,7 +568,7 @@ void parse_host_declaration(cfile, group)
enter_host(host);
}
-/* class-declaration :== STRING LBRACE parameters declarations RBRACE
+/* class-declaration :== STRING '{' parameters declarations '}'
*/
void parse_class_declaration(cfile, group, type)
@@ -582,7 +582,7 @@ void parse_class_declaration(cfile, group, type)
int declaration = 0;
token = next_token(&val, cfile);
- if (token != STRING) {
+ if (token != TOK_STRING) {
parse_warn("Expecting class name");
skip_to_semi(cfile);
return;
@@ -598,7 +598,7 @@ void parse_class_declaration(cfile, group, type)
do {
token = peek_token(&val, cfile);
- if (token == RBRACE) {
+ if (token == '}') {
token = next_token(&val, cfile);
break;
} else if (token == EOF) {
@@ -638,7 +638,7 @@ void parse_shared_net_declaration(cfile, group)
/* Get the name of the shared network... */
token = peek_token(&val, cfile);
- if (token == STRING) {
+ if (token == TOK_STRING) {
token = next_token(&val, cfile);
if (val[0] == 0) {
@@ -661,7 +661,7 @@ void parse_shared_net_declaration(cfile, group)
do {
token = peek_token(&val, cfile);
- if (token == RBRACE) {
+ if (token == '}') {
token = next_token(&val, cfile);
if (!share->subnets) {
parse_warn("empty shared-network decl");
@@ -703,21 +703,21 @@ void parse_subnet_declaration(cfile, share)
subnet->group->subnet = subnet;
/* Get the network number... */
- if (!parse_numeric_aggregate(cfile, addr, &len, DOT, 10, 8))
+ if (!parse_numeric_aggregate(cfile, addr, &len, '.', 10, 8))
return;
memcpy(iaddr.iabuf, addr, len);
iaddr.len = len;
subnet->net = iaddr;
token = next_token(&val, cfile);
- if (token != NETMASK) {
+ if (token != TOK_NETMASK) {
parse_warn("Expecting netmask");
skip_to_semi(cfile);
return;
}
/* Get the netmask... */
- if (!parse_numeric_aggregate(cfile, addr, &len, DOT, 10, 8))
+ if (!parse_numeric_aggregate(cfile, addr, &len, '.', 10, 8))
return;
memcpy(iaddr.iabuf, addr, len);
iaddr.len = len;
@@ -730,7 +730,7 @@ void parse_subnet_declaration(cfile, share)
do {
token = peek_token(&val, cfile);
- if (token == RBRACE) {
+ if (token == '}') {
token = next_token(&val, cfile);
break;
} else if (token == EOF) {
@@ -787,7 +787,7 @@ void parse_group_declaration(cfile, group)
do {
token = peek_token(&val, cfile);
- if (token == RBRACE) {
+ if (token == '}') {
token = next_token(&val, cfile);
break;
} else if (token == EOF) {
@@ -833,16 +833,16 @@ struct tree *parse_ip_addr_or_hostname(cfile, uniform)
rv = tree_const(h->h_addr_list[0], h->h_length);
if (!uniform)
rv = tree_limit(rv, 4);
- } else if (token == NUMBER) {
- if (!parse_numeric_aggregate(cfile, addr, &len, DOT, 10, 8))
+ } else if (token == TOK_NUMBER) {
+ if (!parse_numeric_aggregate(cfile, addr, &len, '.', 10, 8))
return NULL;
rv = tree_const(addr, len);
} else {
- if (token != RBRACE && token != LBRACE)
+ if (token != '{' && token != '}')
token = next_token(&val, cfile);
parse_warn("%s (%d): expecting IP address or hostname",
val, token);
- if (token != SEMI)
+ if (token != ';')
skip_to_semi(cfile);
return NULL;
}
@@ -870,9 +870,9 @@ struct tree_cache *parse_fixed_addr_param(cfile)
else
tree = tmp;
token = peek_token(&val, cfile);
- if (token == COMMA)
+ if (token == ',')
token = next_token(&val, cfile);
- } while (token == COMMA);
+ } while (token == ',');
if (!parse_semi(cfile))
return NULL;
@@ -903,7 +903,7 @@ void parse_option_param(cfile, group)
token = next_token(&val, cfile);
if (!is_identifier(token)) {
parse_warn("expecting identifier after option keyword.");
- if (token != SEMI)
+ if (token != ';')
skip_to_semi(cfile);
return;
}
@@ -912,7 +912,7 @@ void parse_option_param(cfile, group)
error("no memory for vendor token.");
strlcpy(vendor, val, strlen(val) + 1);
token = peek_token(&val, cfile);
- if (token == DOT) {
+ if (token == '.') {
/* Go ahead and take the DOT token... */
token = next_token(&val, cfile);
@@ -920,7 +920,7 @@ void parse_option_param(cfile, group)
token = next_token(&val, cfile);
if (!is_identifier(token)) {
parse_warn("expecting identifier after '.'");
- if (token != SEMI)
+ if (token != ';')
skip_to_semi(cfile);
return;
}
@@ -974,16 +974,16 @@ void parse_option_param(cfile, group)
switch (*fmt) {
case 'X':
token = peek_token(&val, cfile);
- if (token == NUMBER_OR_NAME ||
- token == NUMBER) {
+ if (token == TOK_NUMBER_OR_NAME ||
+ token == TOK_NUMBER) {
do {
token = next_token
(&val, cfile);
- if (token != NUMBER &&
- token != NUMBER_OR_NAME) {
+ if (token != TOK_NUMBER &&
+ token != TOK_NUMBER_OR_NAME) {
parse_warn("expecting "
"number.");
- if (token != SEMI)
+ if (token != ';')
skip_to_semi(
cfile);
return;
@@ -992,11 +992,11 @@ void parse_option_param(cfile, group)
tree = tree_concat(tree,
tree_const(buf, 1));
token = peek_token(&val, cfile);
- if (token == COLON)
+ if (token == ':')
token = next_token(&val,
cfile);
- } while (token == COLON);
- } else if (token == STRING) {
+ } while (token == ':');
+ } else if (token == TOK_STRING) {
token = next_token(&val, cfile);
tree = tree_concat(tree,
tree_const((unsigned char *)val,
@@ -1011,10 +1011,10 @@ void parse_option_param(cfile, group)
case 't': /* Text string... */
token = next_token(&val, cfile);
- if (token != STRING
+ if (token != TOK_STRING
&& !is_identifier(token)) {
parse_warn("expecting string.");
- if (token != SEMI)
+ if (token != ';')
skip_to_semi(cfile);
return;
}
@@ -1033,9 +1033,9 @@ void parse_option_param(cfile, group)
case 'L': /* Unsigned 32-bit integer... */
case 'l': /* Signed 32-bit integer... */
token = next_token(&val, cfile);
- if (token != NUMBER) {
+ if (token != TOK_NUMBER) {
parse_warn("expecting number.");
- if (token != SEMI)
+ if (token != ';')
skip_to_semi(cfile);
return;
}
@@ -1045,9 +1045,9 @@ void parse_option_param(cfile, group)
case 's': /* Signed 16-bit integer. */
case 'S': /* Unsigned 16-bit integer. */
token = next_token(&val, cfile);
- if (token != NUMBER) {
+ if (token != TOK_NUMBER) {
parse_warn("expecting number.");
- if (token != SEMI)
+ if (token != ';')
skip_to_semi(cfile);
return;
}
@@ -1057,9 +1057,9 @@ void parse_option_param(cfile, group)
case 'b': /* Signed 8-bit integer. */
case 'B': /* Unsigned 8-bit integer. */
token = next_token(&val, cfile);
- if (token != NUMBER) {
+ if (token != TOK_NUMBER) {
parse_warn("expecting number.");
- if (token != SEMI)
+ if (token != ';')
skip_to_semi(cfile);
return;
}
@@ -1070,7 +1070,7 @@ void parse_option_param(cfile, group)
token = next_token(&val, cfile);
if (!is_identifier(token)) {
parse_warn("expecting identifier.");
- if (token != SEMI)
+ if (token != ';')
skip_to_semi(cfile);
return;
}
@@ -1082,7 +1082,7 @@ void parse_option_param(cfile, group)
buf[0] = 0;
else {
parse_warn("expecting boolean.");
- if (token != SEMI)
+ if (token != ';')
skip_to_semi(cfile);
return;
}
@@ -1097,7 +1097,7 @@ void parse_option_param(cfile, group)
}
if (*fmt == 'A') {
token = peek_token(&val, cfile);
- if (token == COMMA) {
+ if (token == ',') {
token = next_token(&val, cfile);
continue;
}
@@ -1106,7 +1106,7 @@ void parse_option_param(cfile, group)
} while (*fmt == 'A');
token = next_token(&val, cfile);
- if (token != SEMI) {
+ if (token != ';') {
parse_warn("semicolon expected.");
skip_to_semi(cfile);
return;
@@ -1146,7 +1146,7 @@ parse_lease_declaration(FILE *cfile)
memset(&lease, 0, sizeof lease);
/* Get the address for which the lease has been issued. */
- if (!parse_numeric_aggregate(cfile, addr, &len, DOT, 10, 8))
+ if (!parse_numeric_aggregate(cfile, addr, &len, '.', 10, 8))
return NULL;
memcpy(lease.ip_addr.iabuf, addr, len);
lease.ip_addr.len = len;
@@ -1156,7 +1156,7 @@ parse_lease_declaration(FILE *cfile)
do {
token = next_token(&val, cfile);
- if (token == RBRACE)
+ if (token == '}')
break;
else if (token == EOF) {
parse_warn("unexpected end of file");
@@ -1165,21 +1165,21 @@ parse_lease_declaration(FILE *cfile)
strlcpy(tbuf, val, sizeof tbuf);
/* Parse any of the times associated with the lease. */
- if (token == STARTS || token == ENDS || token == TIMESTAMP) {
+ if (token == TOK_STARTS || token == TOK_ENDS || token == TOK_TIMESTAMP) {
time_t t;
t = parse_date(cfile);
switch (token) {
- case STARTS:
+ case TOK_STARTS:
seenbit = 1;
lease.starts = t;
break;
- case ENDS:
+ case TOK_ENDS:
seenbit = 2;
lease.ends = t;
break;
- case TIMESTAMP:
+ case TOK_TIMESTAMP:
seenbit = 4;
lease.timestamp = t;
break;
@@ -1192,10 +1192,10 @@ parse_lease_declaration(FILE *cfile)
} else {
switch (token) {
/* Colon-separated hexadecimal octets... */
- case UID:
+ case TOK_UID:
seenbit = 8;
token = peek_token(&val, cfile);
- if (token == STRING) {
+ if (token == TOK_STRING) {
token = next_token(&val, cfile);
lease.uid_len = strlen(val);
lease.uid = (unsigned char *)
@@ -1226,37 +1226,37 @@ parse_lease_declaration(FILE *cfile)
error("No memory for lease uid");
break;
- case CLASS:
+ case TOK_CLASS:
seenbit = 32;
token = next_token(&val, cfile);
if (!is_identifier(token)) {
- if (token != SEMI)
+ if (token != ';')
skip_to_semi(cfile);
return NULL;
}
/* for now, we aren't using this. */
break;
- case HARDWARE:
+ case TOK_HARDWARE:
seenbit = 64;
parse_hardware_param(cfile,
&lease.hardware_addr);
break;
- case DYNAMIC_BOOTP:
+ case TOK_DYNAMIC_BOOTP:
seenbit = 128;
lease.flags |= BOOTP_LEASE;
break;
- case ABANDONED:
+ case TOK_ABANDONED:
seenbit = 256;
lease.flags |= ABANDONED_LEASE;
break;
- case HOSTNAME:
+ case TOK_HOSTNAME:
seenbit = 512;
token = peek_token(&val, cfile);
- if (token == STRING)
+ if (token == TOK_STRING)
lease.hostname = parse_string(cfile);
else
lease.hostname =
@@ -1267,10 +1267,10 @@ parse_lease_declaration(FILE *cfile)
}
break;
- case CLIENT_HOSTNAME:
+ case TOK_CLIENT_HOSTNAME:
seenbit = 1024;
token = peek_token(&val, cfile);
- if (token == STRING)
+ if (token == TOK_STRING)
lease.client_hostname =
parse_string(cfile);
else
@@ -1284,9 +1284,9 @@ parse_lease_declaration(FILE *cfile)
return NULL;
}
- if (token != HARDWARE && token != STRING) {
+ if (token != TOK_HARDWARE && token != TOK_STRING) {
token = next_token(&val, cfile);
- if (token != SEMI) {
+ if (token != ';') {
parse_warn("semicolon expected.");
skip_to_semi(cfile);
return NULL;
@@ -1315,31 +1315,31 @@ parse_address_range(FILE *cfile, struct subnet *subnet)
int len = sizeof addr, token, dynamic = 0;
char *val;
- if ((token = peek_token(&val, cfile)) == DYNAMIC_BOOTP) {
+ if ((token = peek_token(&val, cfile)) == TOK_DYNAMIC_BOOTP) {
token = next_token(&val, cfile);
subnet->group->dynamic_bootp = dynamic = 1;
}
/* Get the bottom address in the range... */
- if (!parse_numeric_aggregate(cfile, addr, &len, DOT, 10, 8))
+ if (!parse_numeric_aggregate(cfile, addr, &len, '.', 10, 8))
return;
memcpy(low.iabuf, addr, len);
low.len = len;
/* Only one address? */
token = peek_token(&val, cfile);
- if (token == SEMI)
+ if (token == ';')
high = low;
else {
/* Get the top address in the range... */
- if (!parse_numeric_aggregate(cfile, addr, &len, DOT, 10, 8))
+ if (!parse_numeric_aggregate(cfile, addr, &len, '.', 10, 8))
return;
memcpy(high.iabuf, addr, len);
high.len = len;
}
token = next_token(&val, cfile);
- if (token != SEMI) {
+ if (token != ';') {
parse_warn("semicolon expected.");
skip_to_semi(cfile);
return;
diff --git a/usr.sbin/dhcpd/dhctoken.h b/usr.sbin/dhcpd/dhctoken.h
index 88a45ca4111..bfe38d96b88 100644
--- a/usr.sbin/dhcpd/dhctoken.h
+++ b/usr.sbin/dhcpd/dhctoken.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: dhctoken.h,v 1.2 2004/04/14 01:09:52 henning Exp $ */
+/* $OpenBSD: dhctoken.h,v 1.3 2006/04/18 19:18:32 deraadt Exp $ */
/* Tokens for config file lexer and parser. */
@@ -40,97 +40,61 @@
* Enterprises, see ``http://www.vix.com''.
*/
-#define SEMI ';'
-#define DOT '.'
-#define COLON ':'
-#define COMMA ','
-#define SLASH '/'
-#define LBRACE '{'
-#define RBRACE '}'
+#define TOK_FIRST_TOKEN TOK_HOST
+#define TOK_HOST 256
+#define TOK_HARDWARE 257
+#define TOK_FILENAME 258
+#define TOK_FIXED_ADDR 259
+#define TOK_OPTION 260
+#define TOK_ETHERNET 261
+#define TOK_STRING 262
+#define TOK_NUMBER 263
+#define TOK_NUMBER_OR_NAME 264
+#define TOK_NAME 265
+#define TOK_TIMESTAMP 266
+#define TOK_STARTS 267
+#define TOK_ENDS 268
+#define TOK_UID 269
+#define TOK_CLASS 270
+#define TOK_LEASE 271
+#define TOK_RANGE 272
+#define TOK_SUBNET 278
+#define TOK_NETMASK 279
+#define TOK_DEFAULT_LEASE_TIME 280
+#define TOK_MAX_LEASE_TIME 281
+#define TOK_VENDOR_CLASS 282
+#define TOK_USER_CLASS 283
+#define TOK_SHARED_NETWORK 284
+#define TOK_SERVER_NAME 285
+#define TOK_DYNAMIC_BOOTP 286
+#define TOK_SERVER_IDENTIFIER 287
+#define TOK_DYNAMIC_BOOTP_LEASE_CUTOFF 288
+#define TOK_DYNAMIC_BOOTP_LEASE_LENGTH 289
+#define TOK_BOOT_UNKNOWN_CLIENTS 290
+#define TOK_NEXT_SERVER 291
+#define TOK_TOKEN_RING 292
+#define TOK_GROUP 293
+#define TOK_ONE_LEASE_PER_CLIENT 294
+#define TOK_GET_LEASE_HOSTNAMES 295
+#define TOK_USE_HOST_DECL_NAMES 296
+#define TOK_SEND 297
+#define TOK_TIMEOUT 301
+#define TOK_UNKNOWN_CLIENTS 309
+#define TOK_ALLOW 310
+#define TOK_BOOTP 311
+#define TOK_DENY 312
+#define TOK_BOOTING 313
+#define TOK_ABANDONED 319
+#define TOK_DOMAIN 323
+#define TOK_HOSTNAME 328
+#define TOK_CLIENT_HOSTNAME 329
+#define TOK_FDDI 331
+#define TOK_USE_LEASE_ADDR_FOR_DEFAULT_ROUTE 332
+#define TOK_AUTHORITATIVE 333
+#define TOK_TOKEN_NOT 334
+#define TOK_ALWAYS_REPLY_RFC1048 335
-#define FIRST_TOKEN HOST
-#define HOST 256
-#define HARDWARE 257
-#define FILENAME 258
-#define FIXED_ADDR 259
-#define OPTION 260
-#define ETHERNET 261
-#define STRING 262
-#define NUMBER 263
-#define NUMBER_OR_NAME 264
-#define NAME 265
-#define TIMESTAMP 266
-#define STARTS 267
-#define ENDS 268
-#define UID 269
-#define CLASS 270
-#define LEASE 271
-#define RANGE 272
-#define PACKET 273
-#define CIADDR 274
-#define YIADDR 275
-#define SIADDR 276
-#define GIADDR 277
-#define SUBNET 278
-#define NETMASK 279
-#define DEFAULT_LEASE_TIME 280
-#define MAX_LEASE_TIME 281
-#define VENDOR_CLASS 282
-#define USER_CLASS 283
-#define SHARED_NETWORK 284
-#define SERVER_NAME 285
-#define DYNAMIC_BOOTP 286
-#define SERVER_IDENTIFIER 287
-#define DYNAMIC_BOOTP_LEASE_CUTOFF 288
-#define DYNAMIC_BOOTP_LEASE_LENGTH 289
-#define BOOT_UNKNOWN_CLIENTS 290
-#define NEXT_SERVER 291
-#define TOKEN_RING 292
-#define GROUP 293
-#define ONE_LEASE_PER_CLIENT 294
-#define GET_LEASE_HOSTNAMES 295
-#define USE_HOST_DECL_NAMES 296
-#define SEND 297
-#define CLIENT_IDENTIFIER 298
-#define REQUEST 299
-#define REQUIRE 300
-#define TIMEOUT 301
-#define RETRY 302
-#define SELECT_TIMEOUT 303
-#define SCRIPT 304
-#define INTERFACE 305
-#define RENEW 306
-#define REBIND 307
-#define EXPIRE 308
-#define UNKNOWN_CLIENTS 309
-#define ALLOW 310
-#define BOOTP 311
-#define DENY 312
-#define BOOTING 313
-#define DEFAULT 314
-#define MEDIA 315
-#define MEDIUM 316
-#define ALIAS 317
-#define REBOOT 318
-#define ABANDONED 319
-#define BACKOFF_CUTOFF 320
-#define INITIAL_INTERVAL 321
-#define NAMESERVER 322
-#define DOMAIN 323
-#define SEARCH 324
-#define SUPERSEDE 325
-#define APPEND 326
-#define PREPEND 327
-#define HOSTNAME 328
-#define CLIENT_HOSTNAME 329
-#define REJECT 330
-#define FDDI 331
-#define USE_LEASE_ADDR_FOR_DEFAULT_ROUTE 332
-#define AUTHORITATIVE 333
-#define TOKEN_NOT 334
-#define ALWAYS_REPLY_RFC1048 335
-
-#define is_identifier(x) ((x) >= FIRST_TOKEN && \
- (x) != STRING && \
- (x) != NUMBER && \
+#define is_identifier(x) ((x) >= TOK_FIRST_TOKEN && \
+ (x) != TOK_STRING && \
+ (x) != TOK_NUMBER && \
(x) != EOF)
diff --git a/usr.sbin/dhcpd/parse.c b/usr.sbin/dhcpd/parse.c
index 3dc693835e8..3cab5da4345 100644
--- a/usr.sbin/dhcpd/parse.c
+++ b/usr.sbin/dhcpd/parse.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: parse.c,v 1.7 2004/09/16 18:35:43 deraadt Exp $ */
+/* $OpenBSD: parse.c,v 1.8 2006/04/18 19:18:32 deraadt Exp $ */
/* Common parser code for dhcpd and dhclient. */
@@ -67,16 +67,16 @@ skip_to_semi(FILE *cfile)
do {
token = peek_token(&val, cfile);
- if (token == RBRACE) {
+ if (token == '}') {
if (brace_count) {
token = next_token(&val, cfile);
if (!--brace_count)
return;
} else
return;
- } else if (token == LBRACE) {
+ } else if (token == '{') {
brace_count++;
- } else if (token == SEMI && !brace_count) {
+ } else if (token == ';' && !brace_count) {
token = next_token(&val, cfile);
return;
} else if (token == '\n') {
@@ -100,7 +100,7 @@ parse_semi(FILE *cfile)
char *val;
token = next_token(&val, cfile);
- if (token != SEMI) {
+ if (token != ';') {
parse_warn("semicolon expected.");
skip_to_semi(cfile);
return (0);
@@ -118,7 +118,7 @@ parse_string(FILE *cfile)
int token;
token = next_token(&val, cfile);
- if (token != STRING) {
+ if (token != TOK_STRING) {
parse_warn("filename must be a string");
skip_to_semi(cfile);
return (NULL);
@@ -147,7 +147,7 @@ parse_host_name(FILE *cfile)
do {
/* Read a token, which should be an identifier. */
token = next_token(&val, cfile);
- if (!is_identifier(token) && token != NUMBER) {
+ if (!is_identifier(token) && token != TOK_NUMBER) {
parse_warn("expecting an identifier in hostname");
skip_to_semi(cfile);
return (NULL);
@@ -163,9 +163,9 @@ parse_host_name(FILE *cfile)
* we're done.
*/
token = peek_token(&val, cfile);
- if (token == DOT)
+ if (token == '.')
token = next_token(&val, cfile);
- } while (token == DOT);
+ } while (token == '.');
/* Assemble the hostname together into a string. */
if (!(s = malloc(len)))
@@ -201,13 +201,13 @@ parse_hardware_param(FILE *cfile, struct hardware *hardware)
token = next_token(&val, cfile);
switch (token) {
- case ETHERNET:
+ case TOK_ETHERNET:
hardware->htype = HTYPE_ETHER;
break;
- case TOKEN_RING:
+ case TOK_TOKEN_RING:
hardware->htype = HTYPE_IEEE802;
break;
- case FDDI:
+ case TOK_FDDI:
hardware->htype = HTYPE_FDDI;
break;
default:
@@ -226,7 +226,7 @@ parse_hardware_param(FILE *cfile, struct hardware *hardware)
* on such clients. Yuck.
*/
hlen = 0;
- t = parse_numeric_aggregate(cfile, NULL, &hlen, COLON, 16, 8);
+ t = parse_numeric_aggregate(cfile, NULL, &hlen, ':', 16, 8);
if (!t)
return;
if (hlen > sizeof(hardware->haddr)) {
@@ -242,7 +242,7 @@ parse_hardware_param(FILE *cfile, struct hardware *hardware)
}
token = next_token(&val, cfile);
- if (token != SEMI) {
+ if (token != ';') {
parse_warn("expecting semicolon.");
skip_to_semi(cfile);
}
@@ -258,7 +258,7 @@ parse_lease_time(FILE *cfile, time_t *timep)
int token;
token = next_token(&val, cfile);
- if (token != NUMBER) {
+ if (token != TOK_NUMBER) {
parse_warn("Expecting numeric lease time");
skip_to_semi(cfile);
return;
@@ -300,10 +300,10 @@ parse_numeric_aggregate(FILE *cfile, unsigned char *buf, int *max,
if (token != separator) {
if (!*max)
break;
- if (token != RBRACE && token != LBRACE)
+ if (token != '{' && token != '}')
token = next_token(&val, cfile);
parse_warn("too few numbers.");
- if (token != SEMI)
+ if (token != ';')
skip_to_semi(cfile);
return (NULL);
}
@@ -316,8 +316,8 @@ parse_numeric_aggregate(FILE *cfile, unsigned char *buf, int *max,
break;
}
/* Allow NUMBER_OR_NAME if base is 16. */
- if (token != NUMBER &&
- (base != 16 || token != NUMBER_OR_NAME)) {
+ if (token != TOK_NUMBER &&
+ (base != 16 || token != TOK_NUMBER_OR_NAME)) {
parse_warn("expecting numeric value.");
skip_to_semi(cfile);
return (NULL);
@@ -476,9 +476,9 @@ parse_date(FILE * cfile)
/* Day of week... */
token = next_token(&val, cfile);
- if (token != NUMBER) {
+ if (token != TOK_NUMBER) {
parse_warn("numeric day of week expected.");
- if (token != SEMI)
+ if (token != ';')
skip_to_semi(cfile);
return (NULL);
}
@@ -486,9 +486,9 @@ parse_date(FILE * cfile)
/* Year... */
token = next_token(&val, cfile);
- if (token != NUMBER) {
+ if (token != TOK_NUMBER) {
parse_warn("numeric year expected.");
- if (token != SEMI)
+ if (token != ';')
skip_to_semi(cfile);
return (NULL);
}
@@ -498,17 +498,17 @@ parse_date(FILE * cfile)
/* Slash separating year from month... */
token = next_token(&val, cfile);
- if (token != SLASH) {
+ if (token != '/') {
parse_warn("expected slash separating year from month.");
- if (token != SEMI)
+ if (token != ';')
skip_to_semi(cfile);
return (NULL);
}
/* Month... */
token = next_token(&val, cfile);
- if (token != NUMBER) {
+ if (token != TOK_NUMBER) {
parse_warn("numeric month expected.");
- if (token != SEMI)
+ if (token != ';')
skip_to_semi(cfile);
return (NULL);
}
@@ -516,17 +516,17 @@ parse_date(FILE * cfile)
/* Slash separating month from day... */
token = next_token(&val, cfile);
- if (token != SLASH) {
+ if (token != '/') {
parse_warn("expected slash separating month from day.");
- if (token != SEMI)
+ if (token != ';')
skip_to_semi(cfile);
return (NULL);
}
/* Month... */
token = next_token(&val, cfile);
- if (token != NUMBER) {
+ if (token != TOK_NUMBER) {
parse_warn("numeric day of month expected.");
- if (token != SEMI)
+ if (token != ';')
skip_to_semi(cfile);
return (NULL);
}
@@ -534,9 +534,9 @@ parse_date(FILE * cfile)
/* Hour... */
token = next_token(&val, cfile);
- if (token != NUMBER) {
+ if (token != TOK_NUMBER) {
parse_warn("numeric hour expected.");
- if (token != SEMI)
+ if (token != ';')
skip_to_semi(cfile);
return (NULL);
}
@@ -544,17 +544,17 @@ parse_date(FILE * cfile)
/* Colon separating hour from minute... */
token = next_token(&val, cfile);
- if (token != COLON) {
+ if (token != ':') {
parse_warn("expected colon separating hour from minute.");
- if (token != SEMI)
+ if (token != ';')
skip_to_semi(cfile);
return (NULL);
}
/* Minute... */
token = next_token(&val, cfile);
- if (token != NUMBER) {
+ if (token != TOK_NUMBER) {
parse_warn("numeric minute expected.");
- if (token != SEMI)
+ if (token != ';')
skip_to_semi(cfile);
return (NULL);
}
@@ -562,17 +562,17 @@ parse_date(FILE * cfile)
/* Colon separating minute from second... */
token = next_token(&val, cfile);
- if (token != COLON) {
+ if (token != ':') {
parse_warn("expected colon separating hour from minute.");
- if (token != SEMI)
+ if (token != ';')
skip_to_semi(cfile);
return (NULL);
}
/* Minute... */
token = next_token(&val, cfile);
- if (token != NUMBER) {
+ if (token != TOK_NUMBER) {
parse_warn("numeric minute expected.");
- if (token != SEMI)
+ if (token != ';')
skip_to_semi(cfile);
return (NULL);
}
@@ -584,7 +584,7 @@ parse_date(FILE * cfile)
/* Make sure the date ends in a semicolon... */
token = next_token(&val, cfile);
- if (token != SEMI) {
+ if (token != ';') {
parse_warn("semicolon expected.");
skip_to_semi(cfile);
return (NULL);