#ifndef lint
static char copyright[] =
-"$Id: execute.c,v 1.18 1999/09/15 17:22:52 mellon Exp $ Copyright (c) 1998, 1999 The Internet Software Consortium. All rights reserved.\n";
+"$Id: execute.c,v 1.19 1999/09/22 01:45:49 mellon Exp $ Copyright (c) 1998, 1999 The Internet Software Consortium. All rights reserved.\n";
#endif /* not lint */
#include "dhcpd.h"
*ptr = (struct executable_statement *)0;
return 1;
}
+
+void write_statements (file, statements, indent)
+ FILE *file;
+ struct executable_statement *statements;
+ int indent;
+{
+ struct executable_statement *r, *x;
+ int result;
+ int status;
+ char *s, *t, *dot;
+ int col;
+
+ if (!statements)
+ return;
+
+ for (r = statements; r; r = r -> next) {
+ switch (r -> op) {
+ case statements_statement:
+ write_statements (file, r -> data.statements, indent);
+ break;
+
+ case on_statement:
+ switch (r -> data.on.evtype) {
+ case expiry:
+ s = "expiry";
+ break;
+ case commit:
+ s = "commit";
+ break;
+ case release:
+ s = "release";
+ break;
+ default:
+ log_fatal ("unknown event type %d %s",
+ r -> data.on.evtype,
+ "in on statement.");
+ }
+ indent_spaces (file, indent);
+ fprintf (file, "on %s {", s);
+ write_statements (file, r -> data.on.statements,
+ indent + 2);
+ indent_spaces (file, indent);
+ fprintf (file, "}");
+ break;
+
+ case if_statement:
+ indent_spaces (file, indent);
+ fprintf (file, "if ");
+ x = r;
+ col = write_expression (file,
+ x -> data.ie.expr,
+ indent + 3, indent + 3);
+ else_if:
+ token_print_indent (file, col, indent, " ", "", "{");
+ write_statements (file, x -> data.ie.true, indent + 2);
+ if (x -> data.ie.false &&
+ x -> data.ie.false -> op == if_statement &&
+ !x -> data.ie.false -> next) {
+ indent_spaces (file, indent);
+ fprintf (file, "} elsif ");
+ x = x -> data.ie.false;
+ col = write_expression (file,
+ x -> data.ie.expr,
+ indent + 6,
+ indent + 6);
+ goto else_if;
+ }
+ if (x -> data.ie.false) {
+ indent_spaces (file, indent);
+ fprintf (file, "} else {");
+ write_statements (file, x -> data.ie.false,
+ indent + 2);
+ }
+ indent_spaces (file, indent);
+ fprintf (file, "}");
+ break;
+
+ case eval_statement:
+ indent_spaces (file, indent);
+ fprintf (file, "eval ");
+ col = write_expression (file, r -> data.eval,
+ indent + 5, indent + 5);
+ fprintf (file, ";");
+ break;
+
+ case add_statement:
+ indent_spaces (file, indent);
+ fprintf (file, "add \"%s\"", r -> data.add -> name);
+ break;
+
+ case break_statement:
+ indent_spaces (file, indent);
+ fprintf (file, "break;");
+ break;
+
+ case supersede_option_statement:
+ s = "supersede";
+ goto option_statement;
+
+ case default_option_statement:
+ s = "default";
+ goto option_statement;
+
+ case append_option_statement:
+ s = "append";
+ goto option_statement;
+
+ case prepend_option_statement:
+ s = "prepend";
+ option_statement:
+ /* Note: the reason we don't try to pretty print
+ the option here is that the format of the option
+ may change in dhcpd.conf, and then when this
+ statement was read back, it would cause a syntax
+ error. */
+ if (r -> data.option -> option -> universe ==
+ &dhcp_universe) {
+ t = (char *)0;
+ dot = "";
+ } else {
+ t = (r -> data.option -> option ->
+ universe -> name);
+ dot = ".";
+ }
+ indent_spaces (file, indent);
+ fprintf (file, "%s %s%s%s = ", s, t, dot,
+ r -> data.option -> option -> name);
+ col = (indent + strlen (s) + strlen (t) +
+ strlen (dot) + strlen (r -> data.option ->
+ option -> name) + 4);
+ if (r -> data.option -> expression)
+ write_expression
+ (file,
+ r -> data.option -> expression,
+ col, indent + 8);
+ else
+ token_indent_data_string
+ (file, col, indent + 8, "", "",
+ &r -> data.option -> data);
+
+ fprintf (file, ";"); /* XXX */
+ break;
+
+ default:
+ log_fatal ("bogus statement type %d\n", r -> op);
+ }
+ }
+}
#ifndef lint
static char copyright[] =
-"$Id: tree.c,v 1.48 1999/09/16 01:10:19 mellon Exp $ Copyright (c) 1995, 1996, 1997, 1998 The Internet Software Consortium. All rights reserved.\n";
+"$Id: tree.c,v 1.49 1999/09/22 01:45:49 mellon Exp $ Copyright (c) 1995, 1996, 1997, 1998 The Internet Software Consortium. All rights reserved.\n";
#endif /* not lint */
#include "dhcpd.h"
break;
case TRY_AGAIN:
log_error ("%s: temporary name server failure",
- dns -> hostname);
+ dns -> hostname);
break;
case NO_RECOVERY:
log_error ("%s: name server failed", dns -> hostname);
break;
case NO_DATA:
log_error ("%s: no A record associated with address",
- dns -> hostname);
+ dns -> hostname);
}
#endif /* !NO_H_ERRNO */
}
return context_any;
}
+
+int write_expression (file, expr, col, indent)
+ FILE *file;
+ struct expression *expr;
+ int col;
+ int indent;
+{
+ struct expression *e;
+ char *s;
+ char obuf [65];
+ int scol;
+ int width;
+
+ switch (expr -> op) {
+ case expr_none:
+ col = token_print_indent (file, col, indent, "", "", "null");
+ break;
+
+ case expr_check:
+ col = token_print_indent (file, col, indent, "", "", "check");
+ col = token_print_indent_concat (file, col, indent,
+ " ", "", "\"",
+ expr -> data.check -> name,
+ "\"", (char *)0);
+ break;
+
+ case expr_equal:
+ s = "=";
+ binary:
+ col = write_expression (file,
+ expr -> data.equal [0], col, indent);
+ col = token_print_indent (file, col, indent, " ", " ", s);
+ col = write_expression (file,
+ expr -> data.equal [0], col, indent);
+ break;
+
+ case expr_substring:
+ col = token_print_indent (file, col, indent, "", "",
+ "substring");
+ col = token_print_indent (file, col, indent, " ", "", "(");
+ scol = col;
+ col = write_expression (file, expr -> data.substring.expr,
+ col, scol);
+ col = token_print_indent (file, col, indent, "", " ", ",");
+ col = write_expression (file, expr -> data.substring.offset,
+ col, indent);
+ col = token_print_indent (file, col, scol, "", " ", ",");
+ col = write_expression (file, expr -> data.substring.len,
+ col, scol);
+ col = token_print_indent (file, col, indent, "", "", ")");
+ break;
+
+ case expr_suffix:
+ col = token_print_indent (file, col, indent, "", "", "suffix");
+ col = token_print_indent (file, col, indent, " ", "", "(");
+ scol = col;
+ col = write_expression (file, expr -> data.suffix.expr,
+ col, scol);
+ col = token_print_indent (file, col, scol, "", " ", ",");
+ col = write_expression (file, expr -> data.suffix.len,
+ col, scol);
+ col = token_print_indent (file, col, indent, "", "", ")");
+ break;
+
+ case expr_concat:
+ e = expr;
+ col = token_print_indent (file, col, indent, "", "",
+ "concat");
+ col = token_print_indent (file, col, indent, " ", "", "(");
+ scol = col;
+ concat_again:
+ col = write_expression (file, e -> data.concat [0],
+ col, scol);
+ col = token_print_indent (file, col, scol, "", " ", ",");
+ if (e -> data.concat [1] -> op == expr_concat) {
+ e = e -> data.concat [1];
+ goto concat_again;
+ }
+ col = write_expression (file, e -> data.concat [1],
+ col, scol);
+ col = token_print_indent (file, col, indent, "", "", ")");
+ break;
+
+ case expr_host_lookup:
+ col = token_print_indent (file, col, indent, "", "",
+ "gethostbyname");
+ col = token_print_indent (file, col, indent, " ", "", "(");
+ col = token_print_indent_concat
+ (file, col, indent, "", "",
+ "\"", expr -> data.host_lookup -> hostname, "\"",
+ (char *)0);
+ col = token_print_indent (file, col, indent, "", "", ")");
+ break;
+
+ case expr_and:
+ s = "and";
+ goto binary;
+
+ case expr_or:
+ s = "or";
+ goto binary;
+
+ case expr_not:
+ col = token_print_indent (file, col, indent, "", " ", "not");
+ col = write_expression (file,
+ expr -> data.not, col, indent);
+ break;
+
+ case expr_option:
+ s = "option";
+
+ print_option_name:
+ col = token_print_indent (file, col, indent, "", "", s);
+
+ if (expr -> data.option -> universe != &dhcp_universe) {
+ col = token_print_indent (file, col, indent,
+ " ", "",
+ (expr -> data.option ->
+ universe -> name));
+ col = token_print_indent (file, col, indent, "", "",
+ ".");
+ col = token_print_indent (file, col, indent, "", "",
+ expr -> data.option -> name);
+ } else {
+ col = token_print_indent (file, col, indent, " ", "",
+ expr -> data.option -> name);
+ }
+ break;
+
+ case expr_hardware:
+ col = token_print_indent (file, col, indent, "", "",
+ "hardware");
+ break;
+
+ case expr_packet:
+ col = token_print_indent (file, col, indent, "", "",
+ "packet");
+ col = token_print_indent (file, col, indent, " ", "", "(");
+ scol = col;
+ col = write_expression (file, expr -> data.packet.offset,
+ col, indent);
+ col = token_print_indent (file, col, scol, "", " ", ",");
+ col = write_expression (file, expr -> data.packet.len,
+ col, scol);
+ col = token_print_indent (file, col, indent, "", "", ")");
+ break;
+
+ case expr_const_data:
+ col = token_indent_data_string (file, col, indent, "", "",
+ &expr -> data.const_data);
+ break;
+
+ case expr_extract_int8:
+ width = 8;
+ extract_int:
+ col = token_print_indent (file, col, indent, "", "",
+ "extract-int");
+ col = token_print_indent (file, col, indent, " ", "", "(");
+ scol = col;
+ col = write_expression (file, expr -> data.extract_int,
+ col, indent);
+ col = token_print_indent (file, col, scol, "", " ", ",");
+ sprintf (obuf, "%d", width);
+ col = token_print_indent (file, col, scol, " ", "", obuf);
+ col = token_print_indent (file, col, indent, "", "", ")");
+ break;
+
+ case expr_extract_int16:
+ width = 16;
+ goto extract_int;
+
+ case expr_extract_int32:
+ width = 32;
+ goto extract_int;
+
+ case expr_encode_int8:
+ width = 8;
+ encode_int:
+ col = token_print_indent (file, col, indent, "", "",
+ "encode-int");
+ col = token_print_indent (file, col, indent, " ", "", "(");
+ scol = col;
+ col = write_expression (file, expr -> data.extract_int,
+ col, indent);
+ col = token_print_indent (file, col, scol, "", " ", ",");
+ sprintf (obuf, "%d", width);
+ col = token_print_indent (file, col, scol, " ", "", obuf);
+ col = token_print_indent (file, col, indent, "", "",
+ ")");
+ break;
+
+ case expr_encode_int16:
+ width = 16;
+ goto encode_int;
+
+ case expr_encode_int32:
+ width = 32;
+ goto encode_int;
+
+ case expr_const_int:
+ sprintf (obuf, "%lu", expr -> data.const_int);
+ col = token_print_indent (file, col, indent, "", "", obuf);
+ break;
+
+ case expr_exists:
+ s = "exists";
+ goto print_option_name;
+
+ case expr_encapsulate:
+ col = token_print_indent (file, col, indent, "", "",
+ "encapsulate");
+ col = token_indent_data_string (file, col, indent, " ", "",
+ &expr -> data.encapsulate);
+ break;
+
+ case expr_known:
+ col = token_print_indent (file, col, indent, "", "", "known");
+ break;
+
+ case expr_reverse:
+ col = token_print_indent (file, col, indent, "", "",
+ "reverse");
+ col = token_print_indent (file, col, indent, " ", "", "(");
+ scol = col;
+ col = write_expression (file, expr -> data.reverse.width,
+ col, scol);
+ col = token_print_indent (file, col, scol, "", " ", ",");
+ col = write_expression (file, expr -> data.reverse.buffer,
+ col, scol);
+ col = token_print_indent (file, col, indent, "", "",
+ ")");
+ break;
+
+ case expr_leased_address:
+ col = token_print_indent (file, col, indent, "", "",
+ "leased-address");
+ break;
+
+ case expr_binary_to_ascii:
+ col = token_print_indent (file, col, indent, "", "",
+ "binary-to-ascii");
+ col = token_print_indent (file, col, indent, " ", "",
+ "(");
+ scol = col;
+ col = write_expression (file, expr -> data.b2a.base,
+ col, scol);
+ col = token_print_indent (file, col, scol, "", " ",
+ ",");
+ col = write_expression (file, expr -> data.b2a.width,
+ col, scol);
+ col = token_print_indent (file, col, scol, "", " ",
+ ",");
+ col = write_expression (file, expr -> data.b2a.seperator,
+ col, scol);
+ col = token_print_indent (file, col, scol, "", " ",
+ ",");
+ col = write_expression (file, expr -> data.b2a.buffer,
+ col, scol);
+ col = token_print_indent (file, col, indent, "", "",
+ ")");
+ break;
+
+ case expr_config_option:
+ s = "exists";
+ goto print_option_name;
+
+ case expr_host_decl_name:
+ col = token_print_indent (file, col, indent, "", "",
+ "host-decl-name");
+ break;
+
+ case expr_pick_first_value:
+ e = expr;
+ col = token_print_indent (file, col, indent, "", "",
+ "concat");
+ col = token_print_indent (file, col, indent, " ", "",
+ "(");
+ scol = col;
+ pick_again:
+ col = write_expression (file,
+ e -> data.pick_first_value.car,
+ col, scol);
+ col = token_print_indent (file, col, scol, "", " ",
+ ",");
+ if (e -> data.pick_first_value.cdr -> op ==
+ expr_pick_first_value) {
+ e = e -> data.pick_first_value.cdr;
+ goto pick_again;
+ }
+ col = write_expression (file,
+ e -> data.pick_first_value.cdr,
+ col, scol);
+ col = token_print_indent (file, col, indent, "", "",
+ ")");
+ break;
+
+ case expr_lease_time:
+ col = token_print_indent (file, col, indent, "", "",
+ "lease-time");
+ break;
+
+ case expr_dns_update:
+ col = token_print_indent (file, col, indent, "", "",
+ "dns-update");
+ col = token_print_indent (file, col, indent, " ", "",
+ "(");
+ scol = col;
+ col = write_expression (file, expr -> data.dns_update.type,
+ col, scol);
+ col = token_print_indent (file, col, scol, "", " ",
+ ",");
+ col = write_expression (file, expr -> data.dns_update.expr1,
+ col, scol);
+ col = token_print_indent (file, col, scol, "", " ",
+ ",");
+ col = write_expression (file, expr -> data.dns_update.expr2,
+ col, scol);
+ col = token_print_indent (file, col, scol, "", " ",
+ ",");
+ col = write_expression (file, expr -> data.dns_update.ttl,
+ col, scol);
+ col = token_print_indent (file, col, indent, "", "",
+ ")");
+ break;
+
+ default:
+ log_fatal ("invalid expression type in print_expression: %d",
+ expr -> op);
+ }
+ return col;
+}