]> git.ipfire.org Git - thirdparty/bind9.git/commitdiff
[24702] Include key filename in logged message
authorMukund Sivaraman <muks@isc.org>
Tue, 10 Jun 2014 13:48:34 +0000 (19:18 +0530)
committerMukund Sivaraman <muks@isc.org>
Tue, 10 Jun 2014 13:48:34 +0000 (19:18 +0530)
Squashed commit of the following:

commit 593e6bc7e29938ff5c2f7508bde303fb069a97a9
Author: Mukund Sivaraman <muks@isc.org>
Date:   Tue Jun 10 19:17:40 2014 +0530

    Increase size of filename buffers

commit b8685678e026ba98b8833e26664193b6345eb00e
Author: Evan Hunt <each@isc.org>
Date:   Wed Jun 4 18:57:44 2014 -0700

    [rt24702] some tweaks during review

commit adfbc8f808716c63e9e097d92beef104527e5c6f
Author: Mukund Sivaraman <muks@isc.org>
Date:   Wed Jun 4 18:18:35 2014 +0530

    [24702] Include key filename in logged message

commit f1eff77e7e3704b145c3d65101a735467dd81dc3
Author: Mukund Sivaraman <muks@isc.org>
Date:   Wed Jun 4 18:12:43 2014 +0530

    Add dst_key_getfilename()

lib/dns/dnssec.c
lib/dns/dst_api.c
lib/dns/include/dst/dst.h
lib/dns/win32/libdns.def.in

index 86365225d01460aacd01719b5ae0c1855b7dca54..2b3db8f899614c05df895e635def176a83e0e2d1 100644 (file)
  * PERFORMANCE OF THIS SOFTWARE.
  */
 
-/*
- * $Id$
- */
-
 /*! \file */
 
 #include <config.h>
@@ -739,18 +735,36 @@ dns_dnssec_findzonekeys2(dns_db_t *db, dns_dbversion_t *ver,
                }
 
                if (result != ISC_R_SUCCESS) {
-                       char keybuf[DNS_NAME_FORMATSIZE];
-                       char algbuf[DNS_SECALG_FORMATSIZE];
-                       dns_name_format(dst_key_name(pubkey), keybuf,
-                                       sizeof(keybuf));
-                       dns_secalg_format(dst_key_alg(pubkey), algbuf,
-                                         sizeof(algbuf));
+                       char filename[ISC_DIR_NAMEMAX];
+                       isc_result_t result2;
+                       isc_buffer_t buf;
+
+                       isc_buffer_init(&buf, filename, ISC_DIR_NAMEMAX);
+                       result2 = dst_key_getfilename(dst_key_name(pubkey),
+                                                     dst_key_id(pubkey),
+                                                     dst_key_alg(pubkey),
+                                                     (DST_TYPE_PUBLIC |
+                                                      DST_TYPE_PRIVATE),
+                                                     directory, mctx,
+                                                     &buf);
+                       if (result2 != ISC_R_SUCCESS) {
+                               char namebuf[DNS_NAME_FORMATSIZE];
+                               char algbuf[DNS_SECALG_FORMATSIZE];
+
+                               dns_name_format(dst_key_name(pubkey),
+                                               namebuf, sizeof(namebuf));
+                               dns_secalg_format(dst_key_alg(pubkey),
+                                                 algbuf, sizeof(algbuf));
+                               snprintf(filename, sizeof(filename) - 1,
+                                        "key file for %s/%s/%d",
+                                        namebuf, algbuf, dst_key_id(pubkey));
+                       }
+
                        isc_log_write(dns_lctx, DNS_LOGCATEGORY_GENERAL,
                                      DNS_LOGMODULE_DNSSEC, ISC_LOG_WARNING,
                                      "dns_dnssec_findzonekeys2: error "
-                                     "reading private key file %s/%s/%d: %s",
-                                     keybuf, algbuf, dst_key_id(pubkey),
-                                     isc_result_totext(result));
+                                     "reading %s: %s",
+                                     filename, isc_result_totext(result));
                }
 
                if (result == ISC_R_FILENOTFOUND || result == ISC_R_NOPERM) {
@@ -1597,18 +1611,36 @@ dns_dnssec_keylistfromrdataset(dns_name_t *origin,
                }
 
                if (result != ISC_R_SUCCESS) {
-                       char keybuf[DNS_NAME_FORMATSIZE];
-                       char algbuf[DNS_SECALG_FORMATSIZE];
-                       dns_name_format(dst_key_name(pubkey), keybuf,
-                                       sizeof(keybuf));
-                       dns_secalg_format(dst_key_alg(pubkey), algbuf,
-                                         sizeof(algbuf));
+                       char filename[ISC_DIR_NAMEMAX];
+                       isc_result_t result2;
+                       isc_buffer_t buf;
+
+                       isc_buffer_init(&buf, filename, ISC_DIR_NAMEMAX);
+                       result2 = dst_key_getfilename(dst_key_name(pubkey),
+                                                     dst_key_id(pubkey),
+                                                     dst_key_alg(pubkey),
+                                                     (DST_TYPE_PUBLIC |
+                                                      DST_TYPE_PRIVATE),
+                                                     directory, mctx,
+                                                     &buf);
+                       if (result2 != ISC_R_SUCCESS) {
+                               char namebuf[DNS_NAME_FORMATSIZE];
+                               char algbuf[DNS_SECALG_FORMATSIZE];
+
+                               dns_name_format(dst_key_name(pubkey),
+                                               namebuf, sizeof(namebuf));
+                               dns_secalg_format(dst_key_alg(pubkey),
+                                                 algbuf, sizeof(algbuf));
+                               snprintf(filename, sizeof(filename) - 1,
+                                        "key file for %s/%s/%d",
+                                        namebuf, algbuf, dst_key_id(pubkey));
+                       }
+
                        isc_log_write(dns_lctx, DNS_LOGCATEGORY_GENERAL,
                                      DNS_LOGMODULE_DNSSEC, ISC_LOG_WARNING,
                                      "dns_dnssec_keylistfromrdataset: error "
-                                     "reading private key file %s/%s/%d: %s",
-                                     keybuf, algbuf, dst_key_id(pubkey),
-                                     isc_result_totext(result));
+                                     "reading %s: %s",
+                                     filename, isc_result_totext(result));
                }
 
                if (result == ISC_R_FILENOTFOUND || result == ISC_R_NOPERM) {
index 4e662ca8af23afbf4b73126d064b5457621cbd1c..4fd70e2289e43ed8e89eb19a85952e208fb38189 100644 (file)
@@ -504,15 +504,41 @@ dst_key_isexternal(dst_key_t *key) {
        return (key->external);
 }
 
+isc_result_t
+dst_key_getfilename(dns_name_t *name, dns_keytag_t id,
+                   unsigned int alg, int type, const char *directory,
+                   isc_mem_t *mctx, isc_buffer_t *buf)
+{
+       isc_result_t result;
+
+       REQUIRE(dst_initialized == ISC_TRUE);
+       REQUIRE(dns_name_isabsolute(name));
+       REQUIRE((type & (DST_TYPE_PRIVATE | DST_TYPE_PUBLIC)) != 0);
+       REQUIRE(mctx != NULL);
+       REQUIRE(buf != NULL);
+
+       CHECKALG(alg);
+
+       result = buildfilename(name, id, alg, type, directory, buf);
+       if (result == ISC_R_SUCCESS) {
+               if (isc_buffer_availablelength(buf) > 0)
+                       isc_buffer_putuint8(buf, 0);
+               else
+                       result = ISC_R_NOSPACE;
+       }
+
+       return (result);
+}
+
 isc_result_t
 dst_key_fromfile(dns_name_t *name, dns_keytag_t id,
                 unsigned int alg, int type, const char *directory,
                 isc_mem_t *mctx, dst_key_t **keyp)
 {
+       isc_result_t result;
        char filename[ISC_DIR_NAMEMAX];
-       isc_buffer_t b;
+       isc_buffer_t buf;
        dst_key_t *key;
-       isc_result_t result;
 
        REQUIRE(dst_initialized == ISC_TRUE);
        REQUIRE(dns_name_isabsolute(name));
@@ -522,30 +548,35 @@ dst_key_fromfile(dns_name_t *name, dns_keytag_t id,
 
        CHECKALG(alg);
 
-       isc_buffer_init(&b, filename, sizeof(filename));
-       result = buildfilename(name, id, alg, type, directory, &b);
+       key = NULL;
+
+       isc_buffer_init(&buf, filename, ISC_DIR_NAMEMAX);
+       result = dst_key_getfilename(name, id, alg, type, NULL, mctx, &buf);
        if (result != ISC_R_SUCCESS)
-               return (result);
+               goto out;
 
-       key = NULL;
-       result = dst_key_fromnamedfile(filename, NULL, type, mctx, &key);
+       result = dst_key_fromnamedfile(filename, directory, type, mctx, &key);
        if (result != ISC_R_SUCCESS)
-               return (result);
+               goto out;
 
        result = computeid(key);
-       if (result != ISC_R_SUCCESS) {
-               dst_key_free(&key);
-               return (result);
-       }
+       if (result != ISC_R_SUCCESS)
+               goto out;
 
        if (!dns_name_equal(name, key->key_name) || id != key->key_id ||
            alg != key->key_alg) {
-               dst_key_free(&key);
-               return (DST_R_INVALIDPRIVATEKEY);
+               result = DST_R_INVALIDPRIVATEKEY;
+               goto out;
        }
 
        *keyp = key;
-       return (ISC_R_SUCCESS);
+       result = ISC_R_SUCCESS;
+
+ out:
+       if ((key != NULL) && (result != ISC_R_SUCCESS))
+               dst_key_free(&key);
+
+       return (result);
 }
 
 isc_result_t
index 805f8c07b0fe11f302ad8fbdcd49ccbbef671d7c..080b405480bb497d38fc27b773660f843f890b30 100644 (file)
@@ -15,8 +15,6 @@
  * PERFORMANCE OF THIS SOFTWARE.
  */
 
-/* $Id: dst.h,v 1.34 2011/10/20 21:20:02 marka Exp $ */
-
 #ifndef DST_DST_H
 #define DST_DST_H 1
 
@@ -301,6 +299,29 @@ dst_key_computesecret(const dst_key_t *pub, const dst_key_t *priv,
  * \li If successful, secret will contain the derived shared secret.
  */
 
+isc_result_t
+dst_key_getfilename(dns_name_t *name, dns_keytag_t id, unsigned int alg,
+                   int type, const char *directory,
+                   isc_mem_t *mctx, isc_buffer_t *buf);
+/*%<
+ * Generates a key filename for the name, algorithm, and
+ * id, and places it in the buffer 'buf'. If directory is NULL, the
+ * current directory is assumed.
+ *
+ * Requires:
+ * \li "name" is a valid absolute dns name.
+ * \li "id" is a valid key tag identifier.
+ * \li "alg" is a supported key algorithm.
+ * \li "type" is DST_TYPE_PUBLIC, DST_TYPE_PRIVATE, or the bitwise union.
+ *               DST_TYPE_KEY look for a KEY record otherwise DNSKEY
+ * \li "mctx" is a valid memory context.
+ * \li "buf" is not NULL.
+ *
+ * Returns:
+ * \li ISC_R_SUCCESS
+ * \li any other result indicates failure
+ */
+
 isc_result_t
 dst_key_fromfile(dns_name_t *name, dns_keytag_t id, unsigned int alg, int type,
                 const char *directory, isc_mem_t *mctx, dst_key_t **keyp);
index b3b71d30f908b156da288e21cb7e8b9584d6b125..838b403e4f87457e21ea246f4fd5ea1bd910324d 100644 (file)
@@ -1109,6 +1109,7 @@ dst_key_fromlabel
 dst_key_fromnamedfile
 dst_key_generate
 dst_key_generate2
+dst_key_getfilename
 dst_key_getprivateformat
 dst_key_gettime
 dst_key_getttl