From: Ted Lemon Date: Wed, 6 Oct 1999 01:00:07 +0000 (+0000) Subject: Implement dns-delete (from Brian Murrell) X-Git-Tag: BCTEL_SPECIAL_19991124~147 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=88886e12387470fc4144691dc9391dad99c79bd0;p=thirdparty%2Fdhcp.git Implement dns-delete (from Brian Murrell) --- diff --git a/common/conflex.c b/common/conflex.c index aaf4d0ce5..52a0dc233 100644 --- a/common/conflex.c +++ b/common/conflex.c @@ -22,7 +22,7 @@ #ifndef lint static char copyright[] = -"$Id: conflex.c,v 1.57 1999/10/05 19:43:41 mellon Exp $ Copyright (c) 1995, 1996, 1997, 1998, 1999 The Internet Software Consortium. All rights reserved.\n"; +"$Id: conflex.c,v 1.58 1999/10/06 00:59:59 mellon Exp $ Copyright (c) 1995, 1996, 1997, 1998, 1999 The Internet Software Consortium. All rights reserved.\n"; #endif /* not lint */ #include "dhcpd.h" @@ -463,6 +463,8 @@ static enum dhcp_token intern (atom, dfv) return DDNS_REV_NAME; if (!strcasecmp (atom + 1, "ns-update")) return DNS_UPDATE; + if (!strcasecmp (atom + 1, "ns-delete")) + return DNS_DELETE; if (!strcasecmp (atom + 1, "omain")) return DOMAIN; if (!strcasecmp (atom + 1, "eny")) diff --git a/common/nsupdate.c b/common/nsupdate.c index 3945f8596..6f31c8e67 100644 --- a/common/nsupdate.c +++ b/common/nsupdate.c @@ -25,7 +25,7 @@ #ifndef lint static char copyright[] = -"$Id: nsupdate.c,v 1.9 1999/10/04 23:14:58 mellon Exp $ Copyright (c) 1999 The Internet Software Consortium. All rights reserved.\n"; +"$Id: nsupdate.c,v 1.10 1999/10/06 00:59:59 mellon Exp $ Copyright (c) 1999 The Internet Software Consortium. All rights reserved.\n"; #endif /* not lint */ #include "dhcpd.h" @@ -580,6 +580,93 @@ int updatePTR (lhs, rhs, ttl, lease) return 1; } +/* public function to delete an A record */ +int deleteA (lhs, rhs, lease) + const struct data_string *lhs; + const struct data_string *rhs; + struct lease *lease; +{ + + static char hostname[MAXDNAME]; + static char ipaddr[MAXDNAME]; + int y; + + hostname[0] = '\0'; + strncat(hostname, (const char *)lhs -> data, lhs -> len); + hostname[lhs -> len] = '\0'; + + ipaddr[0] = '\0'; + strncat(ipaddr, (const char *)rhs -> data, rhs -> len); + ipaddr[rhs -> len] = '\0'; + +#if 0 /* Wrong! This causes zone churn on every DHCPREQUEST! + Besides, it is perfectly legal for a DHCP client to have more + than one lease, if (say) it was being served by two+ DHCP servers + serving the same subnet with different (i.e. disjoint) pools. + The right thing to do is have the A records cleaned by either a + DHCPRELEASE or the lease expiry. */ + + /* delete all existing A records for this host */ + nsupdateA (hostname, NULL, 0, DELETE); +#endif + + y=nsupdateA (hostname, ipaddr, 0, DELETE); + if (y < 1) + return 0; + +#if 0 /* do we really need to do this? */ + /* clear the forward DNS name pointer */ + if (lease -> ddns_fwd_name) + dfree (lease -> ddns_fwd_name, "nsupdate"); + lease -> ddns_fwd_name = 0; +#endif + + return 1; +} + +/* public function to delete a PTR record */ +int deletePTR (lhs, rhs, lease) + const struct data_string *lhs; + const struct data_string *rhs; + struct lease *lease; +{ + + static char hostname[MAXDNAME]; + static char revname[MAXDNAME]; + int y; + + revname[0] = '\0'; + strncat(revname, (const char *)lhs -> data, lhs -> len); + revname[lhs -> len] = '\0'; + + hostname[0] = '\0'; + strncat(hostname, (const char *)rhs -> data, rhs -> len); + hostname[rhs -> len] = '\0'; + +#if 0 /* Wrong! This causes zone churn on every DHCPREQUEST! + Besides, it is perfectly legal for a DHCP client to have more + than one lease, if (say) it was being served by two+ DHCP servers + serving the same subnet with different (i.e. disjoint) pools. + The right thing to do is have the PTR records cleaned by either a + DHCPRELEASE or the lease expiry. */ + + /* delete all existing PTR records */ + nsupdatePTR (revname, NULL, 0, DELETE); +#endif + + y=nsupdatePTR (revname, hostname, 0, DELETE); + if (y < 1) + return 0; + +#if 0 /* do we really need to do this? */ + /* clear the reverse DNS name pointer */ + if (lease -> ddns_rev_name) + dfree (lease -> ddns_rev_name, "nsupdate"); + lease -> ddns_rev_name = 0; +#endif + + return 1; +} #endif /* defined (NSUPDATE) */ /* vim: set tabstop=8: */ diff --git a/common/parse.c b/common/parse.c index e4aea4b79..d99f36ea7 100644 --- a/common/parse.c +++ b/common/parse.c @@ -22,7 +22,7 @@ #ifndef lint static char copyright[] = -"$Id: parse.c,v 1.42 1999/10/05 19:43:40 mellon Exp $ Copyright (c) 1995, 1996, 1997, 1998, 1999 The Internet Software Consortium. All rights reserved.\n"; +"$Id: parse.c,v 1.43 1999/10/06 01:00:00 mellon Exp $ Copyright (c) 1995, 1996, 1997, 1998, 1999 The Internet Software Consortium. All rights reserved.\n"; #endif /* not lint */ #include "dhcpd.h" @@ -1989,6 +1989,52 @@ int parse_non_binary (expr, cfile, lose, context) goto norparen; break; + case DNS_DELETE: +#if !defined (NSUPDATE) + parse_warn (cfile, + "Please rebuild dhcpd with --with-nsupdate."); +#endif + token = next_token (&val, cfile); + if (!expression_allocate (expr, + "parse_expression: DNS_DELETE")) + log_fatal ("can't allocate expression"); + (*expr) -> op = expr_dns_delete; + + token = next_token (&val, cfile); + if (token != LPAREN) + goto nolparen; + + if (!(parse_data_expression + (&(*expr) -> data.dns_update.type, cfile, lose))) { + expression_dereference (expr, + "parse_expression: noRRtype"); + parse_warn (cfile, "expecting DNS RR type."); + skip_to_semi (cfile); + *lose = 1; + return 0; + } + + token = next_token (&val, cfile); + if (token != COMMA) + goto nocomma; + + if (!(parse_data_expression + (&(*expr) -> data.dns_update.expr1, cfile, lose))) + goto nodata; + + token = next_token (&val, cfile); + if (token != COMMA) + goto nocomma; + + if (!(parse_data_expression + (&(*expr) -> data.dns_update.expr2, cfile, lose))) + goto nodata; + + token = next_token (&val, cfile); + if (token != RPAREN) + goto norparen; + break; + case OPTION: case CONFIG_OPTION: if (!expression_allocate (expr, "parse_expression: OPTION")) diff --git a/includes/dhctoken.h b/includes/dhctoken.h index 3c8702248..b729d5356 100644 --- a/includes/dhctoken.h +++ b/includes/dhctoken.h @@ -198,6 +198,7 @@ enum dhcp_token { INFINITE = 416, DELETED = 417, UPDATED_DNS_RR = 418, + DNS_DELETE = 419, }; #define is_identifier(x) ((x) >= FIRST_TOKEN && \ diff --git a/includes/tree.h b/includes/tree.h index 8673a6986..b7fee387e 100644 --- a/includes/tree.h +++ b/includes/tree.h @@ -93,6 +93,7 @@ enum expr_op { expr_dns_update, expr_static, expr_updated_dns_rr, + expr_dns_delete, }; struct expression {