2
0
mirror of https://gitlab.isc.org/isc-projects/dhcp synced 2025-08-31 14:25:41 +00:00

-n [master]

Add code to support the standards version of DDNS
This commit is contained in:
Shawn Routhier
2013-10-14 15:53:24 -07:00
parent 1d851cff2c
commit d7d9c0c7c3
38 changed files with 2630 additions and 2114 deletions

View File

@@ -3514,42 +3514,7 @@ int parse_numeric_expression (expr, cfile, lose)
}
return 1;
}
#if defined (NSUPDATE_OLD)
/*
* dns-expression :==
* UPDATE LPAREN ns-class COMMA ns-type COMMA data-expression COMMA
* data-expression COMMA numeric-expression RPAREN
* DELETE LPAREN ns-class COMMA ns-type COMMA data-expression COMMA
* data-expression RPAREN
* EXISTS LPAREN ns-class COMMA ns-type COMMA data-expression COMMA
* data-expression RPAREN
* NOT EXISTS LPAREN ns-class COMMA ns-type COMMA data-expression COMMA
* data-expression RPAREN
* ns-class :== IN | CHAOS | HS | NUMBER
* ns-type :== A | PTR | MX | TXT | NUMBER
*/
int parse_dns_expression (expr, cfile, lose)
struct expression **expr;
struct parse *cfile;
int *lose;
{
/* Parse an expression... */
if (!parse_expression (expr, cfile, lose, context_dns,
(struct expression **)0, expr_none))
return 0;
if (!is_dns_expression (*expr) &&
(*expr) -> op != expr_variable_reference &&
(*expr) -> op != expr_funcall) {
expression_dereference (expr, MDL);
parse_warn (cfile, "Expecting a dns update subexpression.");
*lose = 1;
return 0;
}
return 1;
}
#endif /* NSUPDATE_OLD */
/* Parse a subexpression that does not contain a binary operator. */
int parse_non_binary (expr, cfile, lose, context)
@@ -3564,11 +3529,6 @@ int parse_non_binary (expr, cfile, lose, context)
struct expression *nexp, **ep;
int known;
char *cptr;
#if defined (NSUPDATE_OLD)
enum expr_op opcode;
const char *s;
unsigned long u;
#endif
isc_result_t status;
unsigned len;
@@ -3600,17 +3560,11 @@ int parse_non_binary (expr, cfile, lose, context)
break;
case TOKEN_NOT:
skip_token(&val, (unsigned *)0, cfile);
#if defined(NSUPDATE_OLD)
if (context == context_dns) {
token = peek_token (&val, (unsigned *)0, cfile);
goto not_exists;
}
#endif
skip_token(&val, NULL, cfile);
if (!expression_allocate (expr, MDL))
log_fatal ("can't allocate expression");
(*expr) -> op = expr_not;
if (!parse_non_binary (&(*expr) -> data.not,
(*expr)->op = expr_not;
if (!parse_non_binary (&(*expr)->data.not,
cfile, lose, context_boolean)) {
if (!*lose) {
parse_warn (cfile, "expression expected");
@@ -3618,7 +3572,7 @@ int parse_non_binary (expr, cfile, lose, context)
}
*lose = 1;
expression_dereference (expr, MDL);
return 0;
return (0);
}
if (!is_boolean_expression ((*expr) -> data.not)) {
*lose = 1;
@@ -3650,14 +3604,10 @@ int parse_non_binary (expr, cfile, lose, context)
break;
case EXISTS:
#if defined(NSUPDATE_OLD)
if (context == context_dns)
goto ns_exists;
#endif
skip_token(&val, (unsigned *)0, cfile);
skip_token(&val, NULL, cfile);
if (!expression_allocate (expr, MDL))
log_fatal ("can't allocate expression");
(*expr) -> op = expr_exists;
(*expr)->op = expr_exists;
known = 0;
/* Pass reference directly to expression structure. */
status = parse_option_name(cfile, 0, &known,
@@ -3666,7 +3616,7 @@ int parse_non_binary (expr, cfile, lose, context)
(*expr)->data.option == NULL) {
*lose = 1;
expression_dereference (expr, MDL);
return 0;
return (0);
}
break;
@@ -3967,285 +3917,6 @@ int parse_non_binary (expr, cfile, lose, context)
goto norparen;
break;
#if defined(NSUPDATE_OLD)
/* dns-update and dns-delete are present for historical
purposes, but are deprecated in favor of ns-update
in combination with update, delete, exists and not
exists. */
case DNS_UPDATE:
case DNS_DELETE:
#if !defined (NSUPDATE)
parse_warn (cfile,
"Please rebuild dhcpd with --with-nsupdate.");
#endif
skip_token(&val, (unsigned *)0, cfile);
if (token == DNS_UPDATE)
opcode = expr_ns_add;
else
opcode = expr_ns_delete;
token = next_token (&val, (unsigned *)0, cfile);
if (token != LPAREN)
goto nolparen;
token = next_token (&val, (unsigned *)0, cfile);
if (token != STRING) {
parse_warn (cfile,
"parse_expression: expecting string.");
badnsupdate:
skip_to_semi (cfile);
*lose = 1;
return 0;
}
if (!strcasecmp (val, "a"))
u = T_A;
else if (!strcasecmp (val, "aaaa"))
u = T_AAAA;
else if (!strcasecmp (val, "ptr"))
u = T_PTR;
else if (!strcasecmp (val, "mx"))
u = T_MX;
else if (!strcasecmp (val, "cname"))
u = T_CNAME;
else if (!strcasecmp (val, "TXT"))
u = T_TXT;
else {
parse_warn (cfile, "unexpected rrtype: %s", val);
goto badnsupdate;
}
s = (opcode == expr_ns_add
? "old-dns-update"
: "old-dns-delete");
cptr = dmalloc (strlen (s) + 1, MDL);
if (!cptr)
log_fatal ("can't allocate name for %s", s);
strcpy (cptr, s);
if (!expression_allocate (expr, MDL))
log_fatal ("can't allocate expression");
(*expr) -> op = expr_funcall;
(*expr) -> data.funcall.name = cptr;
/* Fake up a function call. */
ep = &(*expr) -> data.funcall.arglist;
if (!expression_allocate (ep, MDL))
log_fatal ("can't allocate expression");
(*ep) -> op = expr_arg;
if (!make_const_int (&(*ep) -> data.arg.val, u))
log_fatal ("can't allocate rrtype value.");
token = next_token (&val, (unsigned *)0, cfile);
if (token != COMMA)
goto nocomma;
ep = &((*ep) -> data.arg.next);
if (!expression_allocate (ep, MDL))
log_fatal ("can't allocate expression");
(*ep) -> op = expr_arg;
if (!(parse_data_expression (&(*ep) -> data.arg.val,
cfile, lose)))
goto nodata;
token = next_token (&val, (unsigned *)0, cfile);
if (token != COMMA)
goto nocomma;
ep = &((*ep) -> data.arg.next);
if (!expression_allocate (ep, MDL))
log_fatal ("can't allocate expression");
(*ep) -> op = expr_arg;
if (!(parse_data_expression (&(*ep) -> data.arg.val,
cfile, lose)))
goto nodata;
if (opcode == expr_ns_add) {
token = next_token (&val, (unsigned *)0, cfile);
if (token != COMMA)
goto nocomma;
ep = &((*ep) -> data.arg.next);
if (!expression_allocate (ep, MDL))
log_fatal ("can't allocate expression");
(*ep) -> op = expr_arg;
if (!(parse_numeric_expression (&(*ep) -> data.arg.val,
cfile, lose))) {
parse_warn (cfile,
"expecting numeric expression.");
goto badnsupdate;
}
}
token = next_token (&val, (unsigned *)0, cfile);
if (token != RPAREN)
goto norparen;
break;
case NS_UPDATE:
#if !defined (NSUPDATE)
parse_warn (cfile,
"Please rebuild dhcpd with --with-nsupdate.");
#endif
skip_token(&val, (unsigned *)0, cfile);
if (!expression_allocate (expr, MDL))
log_fatal ("can't allocate expression");
token = next_token (&val, (unsigned *)0, cfile);
if (token != LPAREN)
goto nolparen;
nexp = *expr;
do {
nexp -> op = expr_dns_transaction;
if (!(parse_dns_expression
(&nexp -> data.dns_transaction.car,
cfile, lose)))
{
if (!*lose)
parse_warn
(cfile,
"expecting dns expression.");
expression_dereference (expr, MDL);
*lose = 1;
return 0;
}
token = next_token (&val, (unsigned *)0, cfile);
if (token == COMMA) {
if (!(expression_allocate
(&nexp -> data.dns_transaction.cdr,
MDL)))
log_fatal
("can't allocate expression");
nexp = nexp -> data.dns_transaction.cdr;
}
} while (token == COMMA);
if (token != RPAREN)
goto norparen;
break;
/* NOT EXISTS is special cased above... */
not_exists:
token = peek_token (&val, (unsigned *)0, cfile);
if (token != EXISTS) {
parse_warn (cfile, "expecting DNS prerequisite.");
*lose = 1;
return 0;
}
opcode = expr_ns_not_exists;
goto nsupdatecode;
case TOKEN_ADD:
opcode = expr_ns_add;
goto nsupdatecode;
case TOKEN_DELETE:
opcode = expr_ns_delete;
goto nsupdatecode;
ns_exists:
opcode = expr_ns_exists;
nsupdatecode:
token = next_token (&val, (unsigned *)0, cfile);
#if !defined (NSUPDATE)
parse_warn (cfile,
"Please rebuild dhcpd with --with-nsupdate.");
#endif
if (!expression_allocate (expr, MDL))
log_fatal ("can't allocate expression");
(*expr) -> op = opcode;
token = next_token (&val, (unsigned *)0, cfile);
if (token != LPAREN)
goto nolparen;
token = next_token (&val, (unsigned *)0, cfile);
if (!is_identifier (token) && token != NUMBER) {
parse_warn (cfile, "expecting identifier or number.");
badnsop:
expression_dereference (expr, MDL);
skip_to_semi (cfile);
*lose = 1;
return 0;
}
if (token == NUMBER)
(*expr) -> data.ns_add.rrclass = atoi (val);
else if (!strcasecmp (val, "in"))
(*expr) -> data.ns_add.rrclass = C_IN;
else if (!strcasecmp (val, "chaos"))
(*expr) -> data.ns_add.rrclass = C_CHAOS;
else if (!strcasecmp (val, "hs"))
(*expr) -> data.ns_add.rrclass = C_HS;
else {
parse_warn (cfile, "unexpected rrclass: %s", val);
goto badnsop;
}
token = next_token (&val, (unsigned *)0, cfile);
if (token != COMMA)
goto nocomma;
token = next_token (&val, (unsigned *)0, cfile);
if (!is_identifier (token) && token != NUMBER) {
parse_warn (cfile, "expecting identifier or number.");
goto badnsop;
}
if (token == NUMBER)
(*expr) -> data.ns_add.rrtype = atoi (val);
else if (!strcasecmp (val, "a"))
(*expr) -> data.ns_add.rrtype = T_A;
else if (!strcasecmp (val, "aaaa"))
(*expr) -> data.ns_add.rrtype = T_AAAA;
else if (!strcasecmp (val, "ptr"))
(*expr) -> data.ns_add.rrtype = T_PTR;
else if (!strcasecmp (val, "mx"))
(*expr) -> data.ns_add.rrtype = T_MX;
else if (!strcasecmp (val, "cname"))
(*expr) -> data.ns_add.rrtype = T_CNAME;
else if (!strcasecmp (val, "TXT"))
(*expr) -> data.ns_add.rrtype = T_TXT;
else {
parse_warn (cfile, "unexpected rrtype: %s", val);
goto badnsop;
}
token = next_token (&val, (unsigned *)0, cfile);
if (token != COMMA)
goto nocomma;
if (!(parse_data_expression
(&(*expr) -> data.ns_add.rrname, cfile, lose)))
goto nodata;
token = next_token (&val, (unsigned *)0, cfile);
if (token != COMMA)
goto nocomma;
if (!(parse_data_expression
(&(*expr) -> data.ns_add.rrdata, cfile, lose)))
goto nodata;
if (opcode == expr_ns_add) {
token = next_token (&val, (unsigned *)0, cfile);
if (token != COMMA)
goto nocomma;
if (!(parse_numeric_expression
(&(*expr) -> data.ns_add.ttl, cfile,
lose))) {
if (!*lose)
parse_warn (cfile,
"expecting numeric expression.");
goto badnsupdate;
}
}
token = next_token (&val, (unsigned *)0, cfile);
if (token != RPAREN)
goto norparen;
break;
#endif /* NSUPDATE_OLD */
case OPTION:
case CONFIG_OPTION:
if (!expression_allocate (expr, MDL))
@@ -4322,43 +3993,6 @@ int parse_non_binary (expr, cfile, lose, context)
(*expr) -> op = expr_host_decl_name;
break;
#if defined(NSUPDATE_OLD)
case UPDATED_DNS_RR:
skip_token(&val, (unsigned *)0, cfile);
token = next_token (&val, (unsigned *)0, cfile);
if (token != LPAREN)
goto nolparen;
token = next_token (&val, (unsigned *)0, cfile);
if (token != STRING) {
parse_warn (cfile, "expecting string.");
bad_rrtype:
*lose = 1;
return 0;
}
if (!strcasecmp (val, "a"))
s = "ddns-fwd-name";
else if (!strcasecmp (val, "ptr"))
s = "ddns-rev-name";
else {
parse_warn (cfile, "invalid DNS rrtype: %s", val);
goto bad_rrtype;
}
token = next_token (&val, (unsigned *)0, cfile);
if (token != RPAREN)
goto norparen;
if (!expression_allocate (expr, MDL))
log_fatal ("can't allocate expression");
(*expr) -> op = expr_variable_reference;
(*expr) -> data.variable =
dmalloc (strlen (s) + 1, MDL);
if (!(*expr) -> data.variable)
log_fatal ("can't allocate variable name.");
strcpy ((*expr) -> data.variable, s);
break;
#endif /* NSUPDATE_OLD */
case PACKET:
skip_token(&val, (unsigned *)0, cfile);
if (!expression_allocate (expr, MDL))