diff options
author | Evan Hunt <each@isc.org> | 2007-01-28 23:00:19 +0000 |
---|---|---|
committer | Evan Hunt <each@isc.org> | 2007-01-28 23:00:19 +0000 |
commit | 253c8b6ad1f0696cf631331e2ce3a6da341c240e (patch) | |
tree | 84519250b25d20d8c78c5d9011cd91568844eb59 /common/tree.c | |
parent | 85edef5cfe3f24ab0f94656454b00ceeaed2172d (diff) | |
download | isc-dhcp-253c8b6ad1f0696cf631331e2ce3a6da341c240e.tar.gz |
Change "execute" from numeric expression to executable statement, so
it will not be necessary to use eval(execute(...)) [rt16620]
Diffstat (limited to 'common/tree.c')
-rw-r--r-- | common/tree.c | 137 |
1 files changed, 1 insertions, 136 deletions
diff --git a/common/tree.c b/common/tree.c index 9965bf44..f3d8d3e3 100644 --- a/common/tree.c +++ b/common/tree.c @@ -34,7 +34,7 @@ #ifndef lint static char copyright[] = -"$Id: tree.c,v 1.110 2006/11/06 18:13:31 shane Exp $ Copyright (c) 2004-2006 Internet Systems Consortium. All rights reserved.\n"; +"$Id: tree.c,v 1.111 2007/01/28 23:00:19 each Exp $ Copyright (c) 2004-2006 Internet Systems Consortium. All rights reserved.\n"; #endif /* not lint */ #include "dhcpd.h" @@ -51,35 +51,6 @@ struct __res_state resolver_state; int resolver_inited = 0; #endif - -#ifdef ENABLE_EXECUTE -static unsigned long -execute(char **args) -{ - pid_t p; - - if (args == NULL || args[0] == NULL) - return 125; - - p = fork(); - - if (p > 0) { - int status; - waitpid(p, &status, 0); - - if (WIFEXITED(status)) - return WEXITSTATUS(status); - else - return -WTERMSIG(status); - } else if (p == 0) { - execvp(args[0], args); - log_error("Unable to execute %s: %m", args[0]); - _exit(127); - } - - return 126; -} - static void append_to_ary(char **ary_ptr, int *ary_size, int ary_capacity, char *new_element) @@ -135,66 +106,6 @@ data_string_to_char_string(struct data_string *d) return str; } -static int -evaluate_execute(unsigned long *result, struct packet *packet, - struct lease *lease, struct client_state *client_state, - struct option_state *in_options, - struct option_state *cfg_options, - struct binding_scope **scope, struct expression *expr) -{ - int status; - int cmd_status; - int i; - struct data_string ds; - struct expression *next_arg; - char **arg_ary = NULL; - int arg_ary_size = 0; - int arg_ary_capacity = 0; - - /* Need 1 bucket for the command, and 1 for the trailing NULL - * terminator. - */ - i = expr->data.execute.argc + 2; - arg_ary = dmalloc(i * sizeof(char *), MDL); - /* Leave one bucket free for the NULL terminator. */ - arg_ary_capacity = i - 1; - - if (arg_ary == NULL) - return 0; - - append_to_ary(arg_ary, &arg_ary_size, arg_ary_capacity, - expr->data.execute.command); - - for(next_arg = expr->data.execute.arglist; - next_arg; - next_arg = next_arg->data.arg.next) { - memset(&ds, 0, sizeof ds); - status = (evaluate_data_expression - (&ds, packet, lease, client_state, in_options, - cfg_options, scope, next_arg->data.arg.val, MDL)); - if (!status) { - if (arg_ary) { - for (i=1; i < arg_ary_size; i++) - dfree(arg_ary[i], MDL); - dfree(arg_ary, MDL); - } - return 0; - } - append_to_ary(arg_ary, &arg_ary_size, arg_ary_capacity, - data_string_to_char_string(&ds)); - data_string_forget(&ds, MDL); - } -# if defined (DEBUG_EXPRESSIONS) - log_debug("exec: execute"); -# endif - *result = execute(arg_ary); - for (i=1; i < arg_ary_size; i++) - dfree(arg_ary[i], MDL); - dfree(arg_ary, MDL); - return 1; -} -#endif - pair cons (car, cdr) caddr_t car; pair cdr; @@ -1008,7 +919,6 @@ int evaluate_dns_expression (result, packet, lease, client_state, in_options, case expr_extract_int8: case expr_extract_int16: case expr_extract_int32: - case expr_execute: case expr_const_int: case expr_lease_time: case expr_dns_transaction: @@ -1374,7 +1284,6 @@ int evaluate_boolean_expression (result, packet, lease, client_state, case expr_extract_int8: case expr_extract_int16: case expr_extract_int32: - case expr_execute: case expr_const_int: case expr_lease_time: case expr_dns_transaction: @@ -2311,7 +2220,6 @@ int evaluate_data_expression (result, packet, lease, client_state, case expr_extract_int8: case expr_extract_int16: case expr_extract_int32: - case expr_execute: case expr_const_int: case expr_lease_time: case expr_dns_transaction: @@ -2823,20 +2731,6 @@ int evaluate_numeric_expression (result, packet, lease, client_state, return 0; } - case expr_execute: -#if defined (ENABLE_EXECUTE) - status = evaluate_execute(result, packet, lease, - client_state, in_options, - cfg_options, scope, expr); -# if defined (DEBUG_EXPRESSIONS) - log_debug("num: execute() -> %d", status); -# endif - return status; -#else - log_fatal("Impossible case at %s:%d (ENABLE_EXECUTE " - "is not defined).", MDL); -#endif - break; case expr_ns_add: case expr_ns_delete: case expr_ns_exists: @@ -3266,7 +3160,6 @@ int is_numeric_expression (expr) return (expr -> op == expr_extract_int8 || expr -> op == expr_extract_int16 || expr -> op == expr_extract_int32 || - expr -> op == expr_execute || expr -> op == expr_const_int || expr -> op == expr_lease_time || expr -> op == expr_dns_transaction || @@ -3302,7 +3195,6 @@ int is_compound_expression (expr) expr -> op == expr_extract_int8 || expr -> op == expr_extract_int16 || expr -> op == expr_extract_int32 || - expr -> op == expr_execute || expr -> op == expr_dns_transaction); } @@ -3331,7 +3223,6 @@ static int op_val (op) case expr_extract_int8: case expr_extract_int16: case expr_extract_int32: - case expr_execute: case expr_encode_int8: case expr_encode_int16: case expr_encode_int32: @@ -3430,7 +3321,6 @@ enum expression_context op_context (op) case expr_extract_int8: case expr_extract_int16: case expr_extract_int32: - case expr_execute: case expr_encode_int8: case expr_encode_int16: case expr_encode_int32: @@ -3978,30 +3868,6 @@ int write_expression (file, expr, col, indent, firstp) expr -> data.variable); col = token_print_indent (file, col, indent, "", "", ")"); break; - case expr_execute: -#if defined(ENABLE_EXECUTE) - col = token_print_indent(file, col, indent, "", "", - "execute"); - col = token_print_indent(file, col, indent, " ", "", - "("); - scol = col; - col = token_print_indent_concat(file, col, scol, "", "", "\"", - expr->data.execute.command, - "\"", NULL); - for(next_arg = expr->data.execute.arglist; - next_arg; - next_arg = next_arg->data.arg.next) { - col = token_print_indent(file, col, scol, "", " ", - ","); - col = write_expression(file, next_arg->data.arg.val, - col, scol, 0); - } - col = token_print_indent(file, col, indent, "", "", ")"); -#else - log_fatal("Impossible case at %s:%d (ENABLE_EXECUTE is not " - "defined.", MDL); -#endif - break; default: log_fatal ("invalid expression type in print_expression: %d", @@ -4227,7 +4093,6 @@ int data_subexpression_length (int *rv, case expr_extract_int8: case expr_extract_int16: case expr_extract_int32: - case expr_execute: case expr_encode_int8: case expr_encode_int16: case expr_encode_int32: |