]> git.ipfire.org Git - thirdparty/dhcp.git/commitdiff
Implement dns-delete (from Brian Murrell)
authorTed Lemon <source@isc.org>
Wed, 6 Oct 1999 01:00:07 +0000 (01:00 +0000)
committerTed Lemon <source@isc.org>
Wed, 6 Oct 1999 01:00:07 +0000 (01:00 +0000)
common/conflex.c
common/nsupdate.c
common/parse.c
includes/dhctoken.h
includes/tree.h

index aaf4d0ce520a5a10555899a218b36f627a8bb79d..52a0dc233e8e71259b74e13dcddb49b0894c68e9 100644 (file)
@@ -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"))
index 3945f8596f1bbfd4a74a4154b9a8a1c1f6e42cb4..6f31c8e67139ff450c5c246fa0064e07fcf6424f 100644 (file)
@@ -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: */
index e4aea4b791e5898ed067c9eca48c4fa4616bb3b9..d99f36ea7051333e8fa259d418b0048d3e8117ec 100644 (file)
@@ -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"))
index 3c8702248b043145f218f33d0af93fad41548481..b729d53568a58d97cf7edebbcdf9280a80be5f5e 100644 (file)
@@ -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 &&  \
index 8673a69864e27f3c961d59f4d785e8652838e4f4..b7fee387e1354e2908b07f9993be5cd760a6c3f5 100644 (file)
@@ -93,6 +93,7 @@ enum expr_op {
        expr_dns_update,
        expr_static,
        expr_updated_dns_rr,
+       expr_dns_delete,
 };
 
 struct expression {