]> git.ipfire.org Git - thirdparty/dhcp.git/commitdiff
- Require user to declare a ddns update style.
authorTed Lemon <source@isc.org>
Fri, 29 Dec 2000 06:49:38 +0000 (06:49 +0000)
committerTed Lemon <source@isc.org>
Fri, 29 Dec 2000 06:49:38 +0000 (06:49 +0000)
- Put back support for old-style ddns updates.
- Add ddns-update-style parameter, which can be ad-hoc, interim or none.

server/dhcpd.c

index b6f888ceb2dd220379d8b68fd506ff0d0f7db291..193c7021e59ae84b6b69286c70d4040111d928f5 100644 (file)
@@ -43,7 +43,7 @@
 
 #ifndef lint
 static char ocopyright[] =
-"$Id: dhcpd.c,v 1.105 2000/12/11 18:56:43 neild Exp $ Copyright 1995-2000 Internet Software Consortium.";
+"$Id: dhcpd.c,v 1.106 2000/12/29 06:49:38 mellon Exp $ Copyright 1995-2000 Internet Software Consortium.";
 #endif
 
   static char copyright[] =
@@ -64,14 +64,99 @@ struct iaddr server_identifier;
 int server_identifier_matched;
 
 #if defined (NSUPDATE)
+
+/* This stuff is always executed to figure the default values for certain
+   ddns variables. */
+
 char std_nsupdate [] = "                                                   \n\
 option server.ddns-hostname =                                               \n\
   pick (option fqdn.hostname, option host-name);                            \n\
 option server.ddns-domainname =                                             \n\
   pick (option fqdn.domainname, option domain-name);                        \n\
 option server.ddns-ttl = encode-int(lease-time / 2, 32);                    \n\
-option server.ddns-rev-domainname = \"in-addr.arpa.\";                      \n\
-";
+option server.ddns-rev-domainname = \"in-addr.arpa.\";";
+
+/* This is the old-style name service updater that is executed
+   whenever a lease is committed.  It does not follow the DHCP-DNS
+   draft at all. */
+
+char old_nsupdate [] = "                                                   \n\
+on commit {                                                                \n\
+  if (not static and                                                       \n\
+      ((config-option server.ddns-updates = null) or                       \n\
+       (config-option server.ddns-updates != 0))) {                        \n\
+    set new-ddns-fwd-name =                                                \n\
+      concat (pick (config-option server.ddns-hostname,                            \n\
+                   option host-name), \".\",                               \n\
+             pick (config-option server.ddns-domainname,                   \n\
+                   config-option domain-name));                            \n\
+    if (defined (ddns-fwd-name) and ddns-fwd-name != new-ddns-fwd-name) {   \n\
+      switch (ns-update (delete (IN, A, ddns-fwd-name, leased-address))) {  \n\
+      case NOERROR:                                                        \n\
+       unset ddns-fwd-name;                                                \n\
+       on expiry or release {                                              \n\
+       }                                                                   \n\
+      }                                                                            \n\
+    }                                                                      \n\
+                                                                           \n\
+    if (not defined (ddns-fwd-name)) {                                     \n\
+      set ddns-fwd-name = new-ddns-fwd-name;                               \n\
+      if defined (ddns-fwd-name) {                                         \n\
+       switch (ns-update (not exists (IN, A, ddns-fwd-name, null),         \n\
+                          add (IN, A, ddns-fwd-name, leased-address,       \n\
+                               lease-time / 2))) {                         \n\
+       default:                                                            \n\
+         unset ddns-fwd-name;                                              \n\
+         break;                                                            \n\
+                                                                           \n\
+       case NOERROR:                                                       \n\
+         set ddns-rev-name =                                               \n\
+           concat (binary-to-ascii (10, 8, \".\",                          \n\
+                                    reverse (1,                            \n\
+                                             leased-address)), \".\",      \n\
+                   pick (config-option server.ddns-rev-domainname,         \n\
+                         \"in-addr.arpa.\"));                              \n\
+         switch (ns-update (delete (IN, PTR, ddns-rev-name, null),         \n\
+                            add (IN, PTR, ddns-rev-name, ddns-fwd-name,    \n\
+                                 lease-time / 2)))                         \n\
+           {                                                               \n\
+           default:                                                        \n\
+             unset ddns-rev-name;                                          \n\
+             on release or expiry {                                        \n\
+               switch (ns-update (delete (IN, A, ddns-fwd-name,            \n\
+                                          leased-address))) {              \n\
+               case NOERROR:                                               \n\
+                 unset ddns-fwd-name;                                      \n\
+                 break;                                                    \n\
+               }                                                           \n\
+               on release or expiry;                                       \n\
+             }                                                             \n\
+             break;                                                        \n\
+                                                                           \n\
+           case NOERROR:                                                   \n\
+             on release or expiry {                                        \n\
+               switch (ns-update (delete (IN, PTR, ddns-rev-name, null))) {\n\
+               case NOERROR:                                               \n\
+                 unset ddns-rev-name;                                      \n\
+                 break;                                                    \n\
+               }                                                           \n\
+               switch (ns-update (delete (IN, A, ddns-fwd-name,            \n\
+                                          leased-address))) {              \n\
+               case NOERROR:                                               \n\
+                 unset ddns-fwd-name;                                      \n\
+                 break;                                                    \n\
+               }                                                           \n\
+               on release or expiry;                                       \n\
+             }                                                             \n\
+           }                                                               \n\
+       }                                                                   \n\
+      }                                                                            \n\
+    }                                                                      \n\
+    unset new-ddns-fwd-name;                                               \n\
+  }                                                                        \n\
+}";
+
+int ddns_update_style;
 #endif /* NSUPDATE */
 
 const char *path_dhcpd_conf = _PATH_DHCPD_CONF;
@@ -135,9 +220,10 @@ int main (argc, argv, envp)
                log_fatal ("Can't initialize OMAPI: %s",
                           isc_result_totext (result));
 
+       /* Set up the OMAPI wrappers for common objects. */
+       dhcp_db_objects_setup ();
        /* Set up the OMAPI wrappers for various server database internal
           objects. */
-       dhcp_db_objects_setup ();
        dhcp_common_objects_setup ();
 
        /* Initially, log errors to stderr as well as to syslogd. */
@@ -287,6 +373,9 @@ int main (argc, argv, envp)
        initialize_common_option_spaces ();
        initialize_server_option_spaces ();
 
+       /* Add the ddns update style enumeration prior to parsing. */
+       add_enumeration (&ddns_styles);
+
        if (!group_allocate (&root_group, MDL))
                log_fatal ("Can't allocate root group!");
        root_group -> authoritative = 0;
@@ -447,9 +536,49 @@ int main (argc, argv, envp)
                data_string_forget (&db, MDL);
        }
 
+       oc = lookup_option (&server_universe, options, SV_DDNS_UPDATE_STYLE);
+       if (oc) {
+               if (evaluate_option_cache (&db, (struct packet *)0,
+                                          (struct lease *)0,
+                                          (struct client_state *)0,
+                                          options,
+                                          (struct option_state *)0,
+                                          &global_scope, oc, MDL)) {
+                       if (db.len == 1) {
+                               ddns_update_style = db.data [0];
+                       } else
+                               log_fatal ("invalid dns update type");
+                       data_string_forget (&db, MDL);
+               }
+       } else
+               log_fatal ("Please set ddns-update-type.");
+
        /* Don't need the options anymore. */
        option_state_dereference (&options, MDL);
        
+#if defined (NSUPDATE)
+       /* If old-style ddns updates have been requested, parse the
+          old-style ddns updater. */
+       if (ddns_update_style == 1) {
+               /* Set up the standard name service updater routine. */
+               parse = (struct parse *)0;
+               status = new_parse (&parse, -1,
+                                   old_nsupdate, (sizeof old_nsupdate) - 1,
+                                   "old name service update routine");
+               if (status != ISC_R_SUCCESS)
+                       log_fatal ("can't begin parsing old ddns updater!");
+
+               lose = 0;
+               if (!(parse_executable_statements (&root_group -> statements,
+                                                  parse,
+                                                  &lose, context_any))) {
+                       end_parse (&parse);
+                       log_fatal ("can't parse standard ddns updater!");
+               }
+               end_parse (&parse);
+       }
+#endif
+
        group_write_hook = group_writer;
 
        /* Start up the database... */