timedb.c revision e6f82b9dbba43699d9f8231a566ec4830da2cee5
1fdd2470b625a58b57d0b155e6caf8c4fc0afe8aAutomatic Updater * Copyright (C) 2000 Internet Software Consortium.
5a4557e8de2951a2796676b5ec4b6a90caa5be14Mark Andrews * Permission to use, copy, modify, and distribute this software for any
4a14ce5ba00ab7bc55c99ffdcf59c7a4ab902721Automatic Updater * purpose with or without fee is hereby granted, provided that the above
5a4557e8de2951a2796676b5ec4b6a90caa5be14Mark Andrews * copyright notice and this permission notice appear in all copies.
5a4557e8de2951a2796676b5ec4b6a90caa5be14Mark Andrews * THE SOFTWARE IS PROVIDED "AS IS" AND INTERNET SOFTWARE CONSORTIUM
5a4557e8de2951a2796676b5ec4b6a90caa5be14Mark Andrews * DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL
5a4557e8de2951a2796676b5ec4b6a90caa5be14Mark Andrews * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL
5a4557e8de2951a2796676b5ec4b6a90caa5be14Mark Andrews * INTERNET SOFTWARE CONSORTIUM BE LIABLE FOR ANY SPECIAL, DIRECT,
5a4557e8de2951a2796676b5ec4b6a90caa5be14Mark Andrews * INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING
5a4557e8de2951a2796676b5ec4b6a90caa5be14Mark Andrews * FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT,
5a4557e8de2951a2796676b5ec4b6a90caa5be14Mark Andrews * NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION
5a4557e8de2951a2796676b5ec4b6a90caa5be14Mark Andrews * WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
5a4557e8de2951a2796676b5ec4b6a90caa5be14Mark Andrews/* $Id: timedb.c,v 1.3 2000/11/17 22:01:43 bwelling Exp $ */
5a4557e8de2951a2796676b5ec4b6a90caa5be14Mark Andrews * A simple database driver that enables the server to return the
5a4557e8de2951a2796676b5ec4b6a90caa5be14Mark Andrews * current time in a DNS record.
5a4557e8de2951a2796676b5ec4b6a90caa5be14Mark Andrews * This database operates on relative names.
5a4557e8de2951a2796676b5ec4b6a90caa5be14Mark Andrews * "time" and "@" return the time in a TXT record.
5a4557e8de2951a2796676b5ec4b6a90caa5be14Mark Andrews * "clock" is a CNAME to "time"
5a4557e8de2951a2796676b5ec4b6a90caa5be14Mark Andrews * "current" is a DNAME to "@" (try time.current.time)
5a4557e8de2951a2796676b5ec4b6a90caa5be14Mark Andrewstimedb_lookup(const char *zone, const char *name, void *dbdata,
5a4557e8de2951a2796676b5ec4b6a90caa5be14Mark Andrews if (strcmp(name, "@") == 0 || strcmp(name, "time") == 0) {
5a4557e8de2951a2796676b5ec4b6a90caa5be14Mark Andrews * Call ctime to create the string, put it in quotes, and
8ec3c085233cedb22b05da36e2773c8f357a7e45Automatic Updater * remove the trailing newline.
5a4557e8de2951a2796676b5ec4b6a90caa5be14Mark Andrews n = snprintf(buf, sizeof(buf), "\"%s", ctime(&now));
2895f101b5585a19015ac2c2c1e1812ac467fa12Automatic Updater result = dns_sdb_putrr(lookup, "cname", 1, "time");
2895f101b5585a19015ac2c2c1e1812ac467fa12Automatic Updater } else if (strcmp(name, "current") == 0) {
2895f101b5585a19015ac2c2c1e1812ac467fa12Automatic Updater result = dns_sdb_putrr(lookup, "dname", 1, "@");
8ec3c085233cedb22b05da36e2773c8f357a7e45Automatic Updater * lookup() does not return SOA or NS records, so authority() must be defined.
8ec3c085233cedb22b05da36e2773c8f357a7e45Automatic Updatertimedb_authority(const char *zone, void *dbdata, dns_sdblookup_t *lookup) {
0a7ed88633a680bb881868b75ded4d09a7bbbc50Automatic Updater result = dns_sdb_putsoa(lookup, "localhost.", "root.localhost.", 0);
0a7ed88633a680bb881868b75ded4d09a7bbbc50Automatic Updater result = dns_sdb_putrr(lookup, "ns", 86400, "ns1.localdomain.");
0a7ed88633a680bb881868b75ded4d09a7bbbc50Automatic Updater result = dns_sdb_putrr(lookup, "ns", 86400, "ns2.localdomain.");
5a4557e8de2951a2796676b5ec4b6a90caa5be14Mark Andrews * This zone does not support zone transfer, so allnodes() is NULL. There
5a4557e8de2951a2796676b5ec4b6a90caa5be14Mark Andrews * is no database specific data, so create() and destroy() are NULL.
5a4557e8de2951a2796676b5ec4b6a90caa5be14Mark Andrews * Wrapper around dns_sdb_register().
5a4557e8de2951a2796676b5ec4b6a90caa5be14Mark Andrews unsigned int flags;
5a4557e8de2951a2796676b5ec4b6a90caa5be14Mark Andrews flags = DNS_SDBFLAG_RELATIVEOWNER | DNS_SDBFLAG_RELATIVERDATA;
5a4557e8de2951a2796676b5ec4b6a90caa5be14Mark Andrews return (dns_sdb_register("time", &timedb_methods, NULL, flags,
5a4557e8de2951a2796676b5ec4b6a90caa5be14Mark Andrews * Wrapper around dns_sdb_unregister().