]> git.ipfire.org Git - thirdparty/FORT-validator.git/commitdiff
Add syslog
authorAlberto Leiva Popper <ydahhrk@gmail.com>
Fri, 13 Sep 2019 16:44:55 +0000 (11:44 -0500)
committerAlberto Leiva Popper <ydahhrk@gmail.com>
Fri, 13 Sep 2019 16:44:55 +0000 (11:44 -0500)
23 files changed:
docs/README.md
docs/_layouts/default.html
docs/incidence.md
docs/logging.md [new file with mode: 0644]
docs/run.md
docs/usage.md
src/asn1/signed_data.c
src/config.c
src/config/string_array.c
src/crypto/hash.c
src/debug.c
src/incidence/incidence.c
src/log.c
src/log.h
src/main.c
src/object/certificate.c
src/object/crl.c
src/object/ghostbusters.c
src/object/manifest.c
src/object/roa.c
src/object/tal.c
src/rtr/rtr.c
src/thread_var.c

index 281e8a99d09eb1937dfd1a208e2eee3c8965713c..e64cd8a8ca9481e4d86594263f825d38c2c971e2 100644 (file)
@@ -2,7 +2,7 @@
 
 This directory contains the source files of FORT's site and documentation.
 
-Github automatically compiles and publishes it at [https://nicmx.github.io/FORT-validator/](https://nicmx.github.io/FORT-validator/). **It's still under construction**.
+Github automatically compiles and publishes it at [https://nicmx.github.io/FORT-validator/](https://nicmx.github.io/FORT-validator/).
 
 You can also compile the documentation yourself by running [Jekyll](http://jekyllrb.com/) right here.
 
index fbc8a4d076731069d7c55719dc054fd9e47cf7c8..c69afa329cec7b0c13856a435cc8f904ddc541bd 100644 (file)
                                                        <a class="item-menu{% if page.url == '/installation.html' %} active{% endif %}" href="installation.html">Compilation and Installation</a>
                                                </li>
                                                <li>
-                                                       <a class="item-menu{% if page.url == '/run.html' %} active{% endif %}" href="run.html">Running Fort</a>
+                                                       <a class="item-menu{% if page.url == '/run.html' %} active{% endif %}" href="run.html">Basic Usage</a>
                                                </li>
                                                <li>
-                                                       <a class="item-menu{% if page.url == '/usage.html' %} active{% endif %}" href="usage.html">Fort usage</a>
+                                                       <a class="item-menu{% if page.url == '/usage.html' %} active{% endif %}" href="usage.html">Program Arguments</a>
+                                               </li>
+                                               <li>
+                                                       <a class="item-menu{% if page.url == '/logging.html' %} active{% endif %}" href="logging.html">Logging</a>
                                                </li>
                                                <li>
                                                        <a class="item-menu{% if page.url == '/slurm.html' %} active{% endif %}" href="slurm.html">SLURM</a>
index 5749ca20055defe65e894e17f5e067f2d4aaa05a..236ea96bb98e8d97199eac05e18c20ac44edf225 100644 (file)
@@ -13,9 +13,9 @@ title: Incidence
 
 ## Introduction
 
-The RPKI RFCs define fairly strict profiles for RPKI objects, and are unequivocal in stating that incorrectly-formed objects are supposed to be rejected by Relying Party validation. In practice, however, this does not prevent a significant amount of Certificate Authorities from issuing incorrect objects.
+The RPKI RFCs define fairly strict profiles for RPKI objects, and are unequivocal in stating that incorrectly-formed objects are supposed to be rejected by Relying Party validation. In practice, however, this does not prevent a significant amount of legitimate Certificate Authorities from issuing incorrect objects.
 
-By default, Fort is lax with some of this bad practices. The `incidence` section of its configuration file is a means to modify its behavior upon encountering profile violations that, from experience, are often overlooked.
+The `incidence` section of Fort's configuration file is a means to modify its behavior upon encountering profile violations that, from experience, are often overlooked.
 
 ## `incidences` definition
 
@@ -30,7 +30,7 @@ By default, Fort is lax with some of this bad practices. The `incidence` section
 ]
 ```
 
-`name` is the identifier of an incidence. It is case-sensitive and developer-defined. It states an ID of the particular error condition that will be handled by the remaining field.
+`name` is the identifier of an incidence. It is case-sensitive and developer-defined. It states the ID of the particular error condition that will be handled by the remaining field.
 
 `action` is an enumeration that states the outcome of a violation of the corresponding incidence. It can take one of three values:
 
@@ -38,7 +38,7 @@ By default, Fort is lax with some of this bad practices. The `incidence` section
 2. `warn`: Print error message in `warning` log level, continue validation as if nothing happened.
 3. `ignore`: Do not print error message, continue validation as if nothing happened.
 
-Since most of the incidences are result of a bad practice at the global RPKI, they have an `action` of `ignore` by default. If a strict behavior is desired, then the corresponding incidences should be configured with an `action` of `error`.
+Some incidences are `ignore`d by default, because they stem from bad practices (which are nonetheless likely harmless) in the global RPKI repositories. If a strict behavior is desired, then the corresponding incidence `action` should be upgraded.
 
 ## Incidence types
 
diff --git a/docs/logging.md b/docs/logging.md
new file mode 100644 (file)
index 0000000..89a776e
--- /dev/null
@@ -0,0 +1,11 @@
+---
+title: Logging
+---
+
+# {{ page.title }}
+
+- If Fort is run in [server mode](usage.html#--mode), all logging is sent to syslog.
+- If Fort is run in standalone mode, informational messages are printed in standard output and error messages are thrown to standard error.
+
+During the brief period in which configuration has not been completely parsed yet (and therefore, Fort is not yet aware of the desired running mode), the standard streams and syslog are used simultaneously.
+
index 27a48c31d348f2769761e442cc3649e39cc409b9..bb7da434c187b9b5cdebd656feadf82d7ab871db 100644 (file)
@@ -1,5 +1,5 @@
 ---
-title: Running Fort
+title: Basic Usage
 ---
 
 # {{ page.title }}
@@ -35,4 +35,4 @@ fort \
        --server.port <your intended RTR server port>
 {% endhighlight %}
 
-These are some examples to run Fort with distinct configurations; see [usage](usage.html) for more details.
\ No newline at end of file
+These are some examples to run Fort with distinct configurations; see [Program Arguments](usage.html) for more details.
index 8a2db419fda41e0d29cb62e4371c30b316fccec0..9aac448e1e7f8014cd6627d73b04e572a9399b7b 100644 (file)
@@ -1,5 +1,5 @@
 ---
-title: Fort Usage
+title: Program Arguments
 command: fort
 ---
 
index 7bcd57b06d6e6e8a7fea21803f4d58a8256ceb7c..5bf7bd86509f29979e02a08f997e56422361a6b9 100644 (file)
@@ -73,7 +73,7 @@ handle_sdata_certificate(ANY_t *cert_encoded, struct signed_object_args *args,
         * to a tree leaf. Loops aren't possible.
         */
 
-       pr_debug_add("EE Certificate (embedded) {");
+       pr_debug("EE Certificate (embedded) {");
 
        /*
         * "If the call is successful *in is incremented to the byte following
@@ -114,7 +114,7 @@ handle_sdata_certificate(ANY_t *cert_encoded, struct signed_object_args *args,
 end2:
        X509_free(cert);
 end1:
-       pr_debug_rm("}");
+       pr_debug("}");
        return error;
 }
 
index 98e348b268874cb73d5f326e23cf8c99776b6fc5..dbd349ebc864dcaa04d42ce11be24d1781a976ac 100644 (file)
@@ -478,13 +478,11 @@ print_config(void)
        struct option_field const *opt;
 
        pr_info("Configuration {");
-       pr_indent_add();
 
        FOREACH_OPTION(options, opt, 0xFFFF)
                if (is_rpki_config_field(opt) && opt->type->print != NULL)
                        opt->type->print(opt, get_rpki_config_field(opt));
 
-       pr_indent_rm();
        pr_info("}");
 }
 
index c0ccae9d947f08110b37b175c9ccab2be830f668..f401d876151e508c3eb5142b4670b3c3c763f6d5 100644 (file)
@@ -60,14 +60,11 @@ string_array_print(struct option_field const *field, void *_value)
        size_t i;
 
        pr_info("%s:", field->name);
-       pr_indent_add();
 
        if (value->length == 0)
-               pr_info("<Nothing>");
+               pr_info("  <Nothing>");
        else for (i = 0; i < value->length; i++)
-               pr_info("%s", value->array[i]);
-
-       pr_indent_rm();
+               pr_info("  %s", value->array[i]);
 }
 
 static int
index fa5ecdf84ba3936c52a0aeaaf6879c8ebfd59e60..e7cc0ed19c17dd63c9ba54a0d149dd7035ee4693 100644 (file)
@@ -15,7 +15,7 @@ get_md(char const *algorithm, EVP_MD const **result)
 
        md = EVP_get_digestbyname(algorithm);
        if (md == NULL) {
-               printf("Unknown message digest %s\n", algorithm);
+               pr_err("Unknown message digest %s", algorithm);
                return -EINVAL;
        }
 
index f1e325ee0ff60a6656a656924fd5d1f33cba603f..49c5f68a31de465c0bcdcb0cb253833015519788 100644 (file)
@@ -7,7 +7,7 @@
 
 /**
  * Important: -rdynamic needs to be enabled, otherwise this does not print
- * function names. See rpki_validator_LDFLAGS in Makefile.am.
+ * function names. See LDFLAGS_DEBUG in Makefile.am.
  * Also: Only non-static functions will be labeled.
  *
  * During a segfault, the first three printed entries are usually not
index d9a7b77d58366a8d920ad82308283c7121c27eb0..336206ec3c4b391f280d96c4d926c76e4d4035de 100644 (file)
@@ -134,15 +134,12 @@ incidence_print(void)
        array_index i;
 
        pr_info("Custom incidences:");
-       pr_indent_add();
 
        for (i = 0; i < __INID_MAX; i++) {
-               pr_info("%s (%s): %s", incidences[i].name,
+               pr_info("  %s (%s): %s", incidences[i].name,
                    incidences[i].description,
                    action2str(incidences[i].action));
        }
-
-       pr_indent_rm();
 }
 
 enum incidence_action
index e343de997cb4885746c73bd4f499354a2b48c2a1..a801d3b1a66573714e1f0a4109f89409fe4e4081 100644 (file)
--- a/src/log.c
+++ b/src/log.c
 
 #include <openssl/bio.h>
 #include <openssl/err.h>
+#include <syslog.h>
 
 #include "config.h"
 #include "debug.h"
 #include "thread_var.h"
 
-#ifdef DEBUG
-#define COLOR_DEBUG    "\x1B[36m"      /* Cyan */
-#endif
-
-#define COLOR_INFO     "\x1B[37m"      /* Gray */
-#define COLOR_WARNING  "\x1B[33m"      /* Yellow */
-#define COLOR_ERROR    "\x1B[31m"      /* Red */
-#define COLOR_CRITICAL "\x1B[35m"      /* Pink */
-#define COLOR_RESET    "\x1B[0m"       /* Reset */
+struct level {
+       char const *label;
+       char const *color;
+       FILE *stream;
+};
 
-#define STDOUT stdout
-#define STDERR stderr
+static struct level DBG = { "DBG", "\x1B[36m" };
+static struct level INF = { "INF", "\x1B[37m" };
+static struct level WRN = { "WRN", "\x1B[33m" };
+static struct level ERR = { "ERR", "\x1B[31m" };
+static struct level CRT = { "CRT", "\x1B[35m" };
+static struct level UNK = { "UNK", "" };
+#define COLOR_RESET "\x1B[0m"
 
-static unsigned int indent;
+/* LOG_PERROR is not portable, apparently, so I implemented it myself */
+static bool fprintf_enabled;
+static bool syslog_enabled;
 
-static void
-pr_prefix(FILE *stream, char const *color, char const *level)
+void
+log_setup(void)
 {
-       unsigned int i;
-       if (config_get_color_output())
-               fprintf(stream, "%s", color);
-       fprintf(stream, "%s: ", level);
-       for (i = 0; i < indent; i++)
-               fprintf(stream, "  ");
-}
-
-static void
-pr_file_name(FILE *stream)
-{
-#ifndef UNIT_TESTING
-       char const *file = fnstack_peek();
-       if (file == NULL)
-               return;
-       fprintf(stream, "%s: ", file);
-#endif
+       /* =_= */
+       DBG.stream = stdout;
+       INF.stream = stdout;
+       WRN.stream = stderr;
+       ERR.stream = stderr;
+       CRT.stream = stderr;
+       UNK.stream = stdout;
+
+       openlog("Fort", LOG_CONS | LOG_PID, LOG_DAEMON);
+       fprintf_enabled = true;
+       syslog_enabled = true;
 }
 
 void
-pr_indent_add(void)
+log_disable_std(void)
 {
-       indent++;
+       fprintf_enabled = false;
 }
 
 void
-pr_indent_rm(void)
+log_disable_syslog(void)
 {
-       if (indent > 0)
-               indent--;
-       else
-               fprintf(STDERR, "Programming error: Too many pr_rm_indent()s.\n");
+       if (syslog_enabled) {
+               closelog();
+               syslog_enabled = false;
+       }
 }
 
-#ifdef DEBUG
-
 void
-pr_debug_prefix(void)
+log_teardown(void)
 {
-       pr_prefix(STDOUT, COLOR_DEBUG, "DBG");
+       log_disable_std();
+       log_disable_syslog();
 }
 
-void
-pr_debug_suffix(void)
+static struct level const *
+level2struct(int level)
 {
-       if (config_get_color_output())
-               fprintf(STDOUT, "%s", COLOR_RESET);
-       fprintf(STDOUT, "\n");
+       switch (level) {
+       case LOG_CRIT:
+               return &CRT;
+       case LOG_ERR:
+               return &ERR;
+       case LOG_WARNING:
+               return &WRN;
+       case LOG_INFO:
+               return &INF;
+       case LOG_DEBUG:
+               return &DBG;
+       }
+
+       return &UNK;
 }
 
-void
-pr_debug(const char *format, ...)
+static void
+__fprintf(int level, char const *format, ...)
 {
+       struct level const *lvl;
        va_list args;
 
-       pr_debug_prefix();
+       lvl = level2struct(level);
 
+       if (config_get_color_output())
+               fprintf(lvl->stream, "%s", lvl->color);
+
+       fprintf(lvl->stream, "%s: ", lvl->label);
        va_start(args, format);
-       vfprintf(STDOUT, format, args);
+       vfprintf(lvl->stream, format, args);
        va_end(args);
-       pr_debug_suffix();
+
+       if (config_get_color_output())
+               fprintf(lvl->stream, COLOR_RESET);
+
+       fprintf(lvl->stream, "\n");
 }
 
-void
-pr_debug_add(const char *format, ...)
+static bool
+pr_file_name(int level)
 {
-       va_list args;
+       char const *file_name;
 
-       pr_debug_prefix();
+       file_name = fnstack_peek();
+       if (file_name == NULL)
+               return false;
 
-       va_start(args, format);
-       vfprintf(STDOUT, format, args);
-       va_end(args);
-       pr_debug_suffix();
+       if (syslog_enabled)
+               syslog(level, "%s:", file_name);
+       if (fprintf_enabled)
+               __fprintf(level, "%s:", file_name);
 
-       pr_indent_add();
+       return true;
 }
 
-void
-pr_debug_rm(const char *format, ...)
+#define MSG_LEN 512
+
+static void
+pr_syslog(int level, bool indent, const char *format, va_list args)
 {
-       va_list args;
+       char msg[MSG_LEN];
+       /* Can't use vsyslog(); it's not portable. */
+       vsnprintf(msg, MSG_LEN, format, args);
+       syslog(level, "%s%s", indent ? "  " : "", msg);
+}
+
+static void
+pr_stream(int level, bool indent, const char *format, va_list args)
+{
+       struct level const *lvl = level2struct(level);
 
-       pr_indent_rm();
+       if (config_get_color_output())
+               fprintf(lvl->stream, "%s", lvl->color);
 
-       pr_debug_prefix();
+       fprintf(lvl->stream, "%s: ", lvl->label);
+       if (indent)
+               fprintf(lvl->stream, "  ");
+       vfprintf(lvl->stream, format, args);
 
-       va_start(args, format);
-       vfprintf(STDOUT, format, args);
-       va_end(args);
-       pr_debug_suffix();
-}
+       if (config_get_color_output())
+               fprintf(lvl->stream, "%s", COLOR_RESET);
 
-#endif
+       fprintf(lvl->stream, "\n");
+}
 
-#define PR_PREFIX(stream, color, level, args) do {                     \
-       pr_prefix(stream, color, level);                                \
-       pr_file_name(stream);                                           \
+#define PR_SIMPLE(level)                                               \
+       do {                                                            \
+               va_list args;                                           \
+               bool indent;                                            \
+                                                                       \
+               indent = pr_file_name(level);                           \
                                                                        \
-       va_start(args, format);                                         \
-       vfprintf(stream, format, args);                                 \
-       va_end(args);                                                   \
-} while (0)
+               if (syslog_enabled) {                                   \
+                       va_start(args, format);                         \
+                       pr_syslog(level, indent, format, args);         \
+                       va_end(args);                                   \
+               }                                                       \
+                                                                       \
+               if (fprintf_enabled) {                                  \
+                       va_start(args, format);                         \
+                       pr_stream(level, indent, format, args);         \
+                       va_end(args);                                   \
+               }                                                       \
+       } while (0)
 
-#define PR_SUFFIX(stream) do {                                         \
-       if (config_get_color_output())                                  \
-               fprintf(stream, "%s", COLOR_RESET);                     \
-       fprintf(stream, "\n");                                          \
-} while (0)
+#ifdef DEBUG
+
+void
+pr_debug(const char *format, ...)
+{
+       PR_SIMPLE(LOG_DEBUG);
+}
+
+#endif
 
 void
 pr_info(const char *format, ...)
 {
-       va_list args;
-       PR_PREFIX(STDOUT, COLOR_INFO, "INF", args);
-       PR_SUFFIX(STDOUT);
+       PR_SIMPLE(LOG_INFO);
 }
 
 /**
@@ -150,9 +195,7 @@ pr_info(const char *format, ...)
 int
 pr_warn(const char *format, ...)
 {
-       va_list args;
-       PR_PREFIX(STDERR, COLOR_WARNING, "WRN", args);
-       PR_SUFFIX(STDERR);
+       PR_SIMPLE(LOG_WARNING);
        return 0;
 }
 
@@ -162,9 +205,7 @@ pr_warn(const char *format, ...)
 int
 pr_err(const char *format, ...)
 {
-       va_list args;
-       PR_PREFIX(STDERR, COLOR_ERROR, "ERR", args);
-       PR_SUFFIX(STDERR);
+       PR_SIMPLE(LOG_ERR);
        return -EINVAL;
 }
 
@@ -185,89 +226,78 @@ pr_err(const char *format, ...)
 int
 pr_errno(int error, const char *format, ...)
 {
-       va_list args;
+       PR_SIMPLE(LOG_ERR);
 
-       PR_PREFIX(STDERR, COLOR_ERROR, "ERR", args);
-
-       if (error) {
-               fprintf(STDERR, ": %s", strerror(error));
-       } else {
-               /*
-                * If this function was called, then we need to assume that
-                * there WAS an error; go generic.
-                */
-               fprintf(STDERR, ": (Unknown)");
-               error = -EINVAL;
-       }
+       if (!error)
+               return -EINVAL;
+
+       if (syslog_enabled)
+               syslog(LOG_ERR, "  - %s", strerror(error));
+       if (fprintf_enabled)
+               __fprintf(LOG_ERR, "  - %s", strerror(error));
 
-       PR_SUFFIX(STDERR);
        return error;
 }
 
+static int log_crypto_error(const char *str, size_t len, void *arg)
+{
+       if (syslog_enabled)
+               syslog(LOG_ERR, "  - %s", str);
+       if (fprintf_enabled)
+               __fprintf(LOG_ERR, "  - %s", str);
+       return 1;
+}
+
 /**
  * This is like pr_err() and pr_errno(), except meant to log an error made
  * during a libcrypto routine.
  *
  * This differs from usual printf-like functions:
  *
- * - It returns the last error code libcrypto threw, not bytes written.
+ * - It returns -EINVAL, not bytes written.
  * - It prints a newline.
- * - Also prints the cryptolib's error message after a colon.
- *   (So don't include periods at the end of @format.)
+ * - Also prints the cryptolib's error message stack.
  *
  * Always appends a newline at the end.
  */
 int
 crypto_err(const char *format, ...)
 {
-       va_list args;
-       int error;
-
-       PR_PREFIX(STDERR, COLOR_ERROR, "ERR", args);
-       fprintf(STDERR, ": ");
-
-       error = ERR_GET_REASON(ERR_peek_last_error());
-       if (error) {
-               /*
-                * Reminder: This clears the error queue.
-                * BTW: The string format is pretty ugly. Maybe override this.
-                */
-               ERR_print_errors_fp(STDERR);
-       } else {
-               /*
-                * If this function was called, then we need to assume that
-                * there WAS an error; go generic.
-                */
-               fprintf(STDERR, "(There are no error messages in libcrypto's stack.)");
-               error = -EINVAL;
+       unsigned int stack_size;
+
+       PR_SIMPLE(LOG_ERR);
+
+       if (syslog_enabled)
+               syslog(LOG_ERR, "  libcrypto error stack:");
+       if (fprintf_enabled)
+               __fprintf(LOG_ERR, "  libcrypto error stack:");
+
+       stack_size = 0;
+       ERR_print_errors_cb(log_crypto_error, &stack_size);
+       if (stack_size == 0) {
+               if (syslog_enabled)
+                       syslog(LOG_ERR, "    <Empty>");
+               if (fprintf_enabled)
+                       __fprintf(LOG_ERR, "    <Empty>\n");
        }
 
-       PR_SUFFIX(STDERR);
-       return error;
+       return -EINVAL;
 }
 
 int
 pr_enomem(void)
 {
-       pr_err("Out of memory.");
+       if (syslog_enabled)
+               syslog(LOG_ERR, "Out of memory.");
+       if (fprintf_enabled)
+               __fprintf(LOG_ERR, "Out of memory.\n");
        return -ENOMEM;
 }
 
 __dead void
 pr_crit(const char *format, ...)
 {
-       va_list args;
-
-       pr_prefix(STDERR, COLOR_CRITICAL, "CRT");
-       pr_file_name(STDERR);
-
-       fprintf(STDERR, "Programming error: ");
-       va_start(args, format);
-       vfprintf(STDERR, format, args);
-       va_end(args);
-
-       PR_SUFFIX(STDERR);
-
+       PR_SIMPLE(LOG_CRIT);
        print_stack_trace();
        exit(-1);
 }
@@ -280,19 +310,16 @@ int
 incidence(enum incidence_id id, const char *format, ...)
 {
        enum incidence_action action;
-       va_list args;
 
        action = incidence_get_action(id);
        switch (action) {
        case INAC_IGNORE:
                return 0;
        case INAC_WARN:
-               PR_PREFIX(STDERR, COLOR_WARNING, "WRN", args);
-               PR_SUFFIX(STDERR);
+               PR_SIMPLE(LOG_WARNING);
                return 0;
        case INAC_ERROR:
-               PR_PREFIX(STDERR, COLOR_ERROR, "ERR", args);
-               PR_SUFFIX(STDERR);
+               PR_SIMPLE(LOG_ERR);
                return -EINVAL;
        }
 
index 146179da221073666fd44195167b360a629b9270..51cf6c401a95602f5d03a9d9f49cb77dbd376a15 100644 (file)
--- a/src/log.h
+++ b/src/log.h
@@ -21,8 +21,9 @@
  * error printing functions, but we kind of need to do it:
  *
  * - It's convoluted to use err() and warn() on libcrypto errors.
- * - If debug is enabled, we want the error messages to be printed as a tree
- *   to ease debugging.
+ * - I was tasked with using syslog anyway, but the API is kind of limited
+ *   (especially since vsyslog() is not portable.)
+ * - We want to transparently always print offending file name.
  */
 
 #if __GNUC__
 #define CHECK_FORMAT(str, args) /* Nothing */
 #endif
 
-void pr_indent_add(void);
-void pr_indent_rm(void);
+/* Only call this group of functions when you know there's only one thread. */
+void log_setup(void);
+void log_disable_std(void);
+void log_disable_syslog(void);
+void log_teardown(void);
 
-#ifdef DEBUG
-
-void pr_debug(const char *, ...) CHECK_FORMAT(1, 2);
-void pr_debug_add(const char *, ...) CHECK_FORMAT(1, 2);
-void pr_debug_rm(const char *, ...) CHECK_FORMAT(1, 2);
-void pr_debug_prefix(void);
-void pr_debug_suffix(void);
-
-#else
 
 /*
- * I want to define these as empty, but then we get compiler warnings on
- *
- * ```
- * else
- *     pr_debug(...);
- * ```
- *
- * Oh well.
+ * Please note: The log message (excluding pr_errno's strerror and libcrypto's
+ * error stack) cannot exceed 512 bytes at present.
  */
 
+#ifdef DEBUG
+void pr_debug(const char *, ...) CHECK_FORMAT(1, 2);
+#else
 #define pr_debug(...) do {} while (0)
-#define pr_debug_add(...) do {} while (0)
-#define pr_debug_rm(...) do {} while (0)
-
 #endif
 
 void pr_info(const char *, ...) CHECK_FORMAT(1, 2);
index 66ffb346dbbc71f82cf76e5b434d54b6f7feb762..6b05427fcd108f1678c80024ab543a6f46a53606 100644 (file)
@@ -24,7 +24,7 @@ just_quit:
 }
 
 int
-main(int argc, char **argv)
+__main(int argc, char **argv)
 {
        int error;
 
@@ -41,6 +41,19 @@ main(int argc, char **argv)
        if (error)
                return error;
 
+       switch (config_get_mode()) {
+       case SERVER:
+               pr_info("Server mode configured; disabling logging on standard streams.");
+               pr_info("(Logs will be sent to syslog only.)");
+               log_disable_std();
+               break;
+       case STANDALONE:
+               pr_info("Standalone mode configured; disabling logging on syslog.");
+               pr_info("(Logs will be sent to the standard streams only.)");
+               log_disable_syslog();
+               break;
+       }
+
        error = nid_init();
        if (error)
                goto revert_config;
@@ -56,3 +69,15 @@ revert_config:
        free_rpki_config();
        return error;
 }
+
+int
+main(int argc, char **argv)
+{
+       int error;
+
+       log_setup();
+       error = __main(argc, argv);
+       log_teardown();
+
+       return error;
+}
index 78f4aef3749132430bd3cb854da86d229d0f8eaa..0036e1b47b0d8e4dc62ef50db10d059ea1c60534 100644 (file)
@@ -64,7 +64,7 @@ validate_serial_number(X509 *cert)
        pr_debug_prefix();
        fprintf(stdout, "serial Number: ");
        BN_print_fp(stdout, number);
-       fprintf(stdout, "\n");
+       pr_debug_suffix();
 #endif
 
        error = x509stack_store_serial(validation_certstack(state), number);
@@ -758,9 +758,9 @@ __certificate_get_resources(X509 *cert, struct resources *resources,
                        if (!X509_EXTENSION_get_critical(ext))
                                return pr_err("The IP extension is not marked as critical.");
 
-                       pr_debug_add("IP {");
+                       pr_debug("IP {");
                        error = handle_ip_extension(ext, resources);
-                       pr_debug_rm("}");
+                       pr_debug("}");
                        ip_ext_found = true;
 
                        if (error)
@@ -772,10 +772,10 @@ __certificate_get_resources(X509 *cert, struct resources *resources,
                        if (!X509_EXTENSION_get_critical(ext))
                                return pr_err("The AS extension is not marked as critical.");
 
-                       pr_debug_add("ASN {");
+                       pr_debug("ASN {");
                        error = handle_asn_extension(ext, resources,
                            allow_asn_inherit);
-                       pr_debug_rm("}");
+                       pr_debug("}");
                        asn_ext_found = true;
 
                        if (error)
@@ -1553,10 +1553,10 @@ certificate_traverse(struct rpp *rpp_parent, struct rpki_uri *cert_uri)
 
 #ifdef DEBUG
        if (IS_TA)
-               pr_debug_add("TA Certificate '%s' {",
+               pr_debug("TA Certificate '%s' {",
                    uri_get_printable(cert_uri));
        else
-               pr_debug_add("Certificate '%s' {",
+               pr_debug("Certificate '%s' {",
                    uri_get_printable(cert_uri));
 #endif
        fnstack_push_uri(cert_uri);
@@ -1688,6 +1688,6 @@ revert_cert:
                X509_free(cert);
 revert_fnstack_and_debug:
        fnstack_pop();
-       pr_debug_rm("}");
+       pr_debug("}");
        return error;
 }
index 53d0d6f47c325ab0daa9637f414894faae5b91c1..911217c62e08c44010327d0ce7fdc9d0054d1772 100644 (file)
@@ -72,8 +72,8 @@ validate_revoked(X509_CRL *crl)
                pr_debug_prefix();
                fprintf(stdout, "Revoked: ");
                BN_print_fp(stdout, serial_bn);
-               fprintf(stdout, "\n");
                BN_free(serial_bn);
+               pr_debug_suffix();
 #endif
 
                if (X509_REVOKED_get0_revocationDate(revoked) == NULL) {
@@ -142,12 +142,12 @@ int
 crl_load(struct rpki_uri *uri, X509_CRL **result)
 {
        int error;
-       pr_debug_add("CRL '%s' {", uri_get_printable(uri));
+       pr_debug("CRL '%s' {", uri_get_printable(uri));
 
        error = __crl_load(uri, result);
        if (!error)
                error = crl_validate(*result);
 
-       pr_debug_rm("}");
+       pr_debug("}");
        return error;
 }
index 5dabb9633ad42f0b9b3bff671ad1ca5d5576b61b..46abc41d034f3d3d58f7349651f44023a9f783d8 100644 (file)
@@ -25,7 +25,7 @@ ghostbusters_traverse(struct rpki_uri *uri, struct rpp *pp)
        int error;
 
        /* Prepare */
-       pr_debug_add("Ghostbusters '%s' {", uri_get_printable(uri));
+       pr_debug("Ghostbusters '%s' {", uri_get_printable(uri));
        fnstack_push_uri(uri);
 
        /* Decode */
@@ -55,7 +55,7 @@ revert_args:
 revert_sobj:
        signed_object_cleanup(&sobj);
 revert_log:
-       pr_debug_rm("}");
+       pr_debug("}");
        fnstack_pop();
        return error;
 }
index 7806925629c825588aabe5405fc95afb821e9678..af910170d300475d18b1b612f81ec1e4428fdf32 100644 (file)
@@ -221,7 +221,7 @@ handle_manifest(struct rpki_uri *uri, struct rpp **pp)
        int error;
 
        /* Prepare */
-       pr_debug_add("Manifest '%s' {", uri_get_printable(uri));
+       pr_debug("Manifest '%s' {", uri_get_printable(uri));
        fnstack_push_uri(uri);
 
        /* Decode */
@@ -269,7 +269,7 @@ revert_manifest:
 revert_sobj:
        signed_object_cleanup(&sobj);
 revert_log:
-       pr_debug_rm("}");
+       pr_debug("}");
        fnstack_pop();
        return error;
 }
index 71024026844eb3cdae668430d22b0d2c85434b98..55da9ead156dddce62407453d8f99c089a4f08c4 100644 (file)
@@ -35,7 +35,7 @@ ____handle_roa_v4(struct resources *parent, unsigned long asn,
        if (error)
                return error;
 
-       pr_debug_add("ROAIPAddress {");
+       pr_debug("ROAIPAddress {");
        pr_debug("address: %s/%u", v4addr2str(&prefix.addr), prefix.len);
 
        if (roa_addr->maxLength != NULL) {
@@ -70,10 +70,10 @@ ____handle_roa_v4(struct resources *parent, unsigned long asn,
                goto end_error;
        }
 
-       pr_debug_rm("}");
+       pr_debug("}");
        return vhandler_handle_roa_v4(asn, &prefix, max_length);
 end_error:
-       pr_debug_rm("}");
+       pr_debug("}");
        return error;
 }
 
@@ -89,7 +89,7 @@ ____handle_roa_v6(struct resources *parent, unsigned long asn,
        if (error)
                return error;
 
-       pr_debug_add("ROAIPAddress {");
+       pr_debug("ROAIPAddress {");
        pr_debug("address: %s/%u", v6addr2str(&prefix.addr), prefix.len);
 
        if (roa_addr->maxLength != NULL) {
@@ -124,10 +124,10 @@ ____handle_roa_v6(struct resources *parent, unsigned long asn,
                goto end_error;
        }
 
-       pr_debug_rm("}");
+       pr_debug("}");
        return vhandler_handle_roa_v6(asn, &prefix, max_length);
 end_error:
-       pr_debug_rm("}");
+       pr_debug("}");
        return error;
 }
 
@@ -155,7 +155,7 @@ __handle_roa(struct RouteOriginAttestation *roa, struct resources *parent)
        int a;
        int error;
 
-       pr_debug_add("eContent {");
+       pr_debug("eContent {");
        if (roa->version != NULL) {
                error = asn_INTEGER2ulong(roa->version, &version);
                if (error) {
@@ -193,7 +193,7 @@ __handle_roa(struct RouteOriginAttestation *roa, struct resources *parent)
                goto end_error;
        }
 
-       pr_debug_add("ipAddrBlocks {");
+       pr_debug("ipAddrBlocks {");
        for (b = 0; b < roa->ipAddrBlocks.list.count; b++) {
                block = roa->ipAddrBlocks.list.array[b];
                if (block == NULL) {
@@ -208,12 +208,12 @@ __handle_roa(struct RouteOriginAttestation *roa, struct resources *parent)
                if (block->addressFamily.buf[1] != 1
                    && block->addressFamily.buf[1] != 2)
                        goto family_error;
-               pr_debug_add("%s {",
+               pr_debug("%s {",
                    block->addressFamily.buf[1] == 1 ? "v4" : "v6");
 
                if (block->addresses.list.array == NULL) {
                        error = pr_err("ROA's address list array is NULL.");
-                       pr_debug_rm("}");
+                       pr_debug("}");
                        goto ip_error;
                }
 
@@ -222,11 +222,11 @@ __handle_roa(struct RouteOriginAttestation *roa, struct resources *parent)
                            block->addressFamily.buf[1],
                            block->addresses.list.array[a]);
                        if (error) {
-                               pr_debug_rm("}");
+                               pr_debug("}");
                                goto ip_error;
                        }
                }
-               pr_debug_rm("}");
+               pr_debug("}");
        }
 
        /* Error 0 it's ok */
@@ -236,9 +236,9 @@ __handle_roa(struct RouteOriginAttestation *roa, struct resources *parent)
 family_error:
        error = pr_err("ROA's IP family is not v4 or v6.");
 ip_error:
-       pr_debug_rm("}");
+       pr_debug("}");
 end_error:
-       pr_debug_rm("}");
+       pr_debug("}");
        return error;
 }
 
@@ -254,7 +254,7 @@ roa_traverse(struct rpki_uri *uri, struct rpp *pp)
        int error;
 
        /* Prepare */
-       pr_debug_add("ROA '%s' {", uri_get_printable(uri));
+       pr_debug("ROA '%s' {", uri_get_printable(uri));
        fnstack_push_uri(uri);
 
        /* Decode */
@@ -290,6 +290,6 @@ revert_sobj:
        signed_object_cleanup(&sobj);
 revert_log:
        fnstack_pop();
-       pr_debug_rm("}");
+       pr_debug("}");
        return error;
 }
index c198cf5c48f76c502ce55590e8463f09c95bfe80..f35fa4891e44f6db0afd9b351e82c0fa6858f71f 100644 (file)
@@ -454,7 +454,7 @@ handle_tal_uri(struct tal *tal, struct rpki_uri *uri, void *arg)
                return ENSURE_NEGATIVE(error);
        }
 
-       pr_debug_add("TAL URI '%s' {", uri_get_printable(uri));
+       pr_debug("TAL URI '%s' {", uri_get_printable(uri));
 
        if (!uri_is_certificate(uri)) {
                error = pr_err("TAL file does not point to a certificate. (Expected .cer, got '%s')",
@@ -510,7 +510,7 @@ handle_tal_uri(struct tal *tal, struct rpki_uri *uri, void *arg)
 
 fail:  error = ENSURE_NEGATIVE(error);
 end:   validation_destroy(state);
-       pr_debug_rm("}");
+       pr_debug("}");
        return error;
 }
 
index e767b32016e69fab4763fa79240406098d742dd6..1345ece63ef97f369a365857ecdf85fbc75f861b 100644 (file)
@@ -97,8 +97,8 @@ create_server_socket(int *result)
                return error;
 
        for (addr = addrs; addr != NULL; addr = addr->ai_next) {
-               printf(
-                   "Attempting to bind socket to address '%s', port '%s'.\n",
+               pr_info(
+                   "Attempting to bind socket to address '%s', port '%s'.",
                    (addr->ai_canonname != NULL) ? addr->ai_canonname : "any",
                    config_get_server_port());
 
@@ -122,7 +122,7 @@ create_server_socket(int *result)
 
                port = (unsigned char)(addr->ai_addr->sa_data[0]) << 8;
                port += (unsigned char)(addr->ai_addr->sa_data[1]);
-               printf("Success, bound to address '%s', port '%ld'.\n",
+               pr_info("Success; bound to address '%s', port '%ld'.",
                    (addr->ai_canonname != NULL) ? addr->ai_canonname : "any",
                    port);
                freeaddrinfo(addrs);
@@ -388,6 +388,8 @@ rtr_listen(void)
                if (error)
                        pr_err("Error %d while trying to update the ROA database.",
                            error);
+               else
+                       pr_info("Validation finished.");
                goto revert_clients_db; /* Error 0 it's ok */
        }
 
index 05f1fdc4998170ec2edbde78aed2b24df84384d3..077c31382497157120bfb8782b1f6730fb1d26c8 100644 (file)
@@ -36,8 +36,8 @@ thvar_init(void)
 
        error = pthread_key_create(&state_key, NULL);
        if (error) {
-               fprintf(stderr,
-                   "Fatal: Errcode %d while initializing the validation state thread variable.\n",
+               pr_err(
+                   "Fatal: Errcode %d while initializing the validation state thread variable.",
                    error);
                return error;
        }
@@ -50,8 +50,8 @@ thvar_init(void)
         */
        error = pthread_key_create(&filenames_key, fnstack_discard);
        if (error) {
-               fprintf(stderr,
-                   "Fatal: Errcode %d while initializing the file name stack thread variable.\n",
+               pr_err(
+                   "Fatal: Errcode %d while initializing the file name stack thread variable.",
                    error);
                return error;
        }
@@ -67,7 +67,7 @@ state_store(struct validation *state)
 
        error = pthread_setspecific(state_key, state);
        if (error)
-               fprintf(stderr, "pthread_setspecific() returned %d.", error);
+               pr_err("pthread_setspecific() returned %d.", error);
 
        return error;
 }
@@ -80,7 +80,7 @@ state_retrieve(void)
 
        state = pthread_getspecific(state_key);
        if (state == NULL)
-               fprintf(stderr, "Programming error: This thread lacks a validation state.\n");
+               pr_err("Programming error: This thread lacks a validation state.");
 
        return state;
 }
@@ -107,7 +107,7 @@ fnstack_init(void)
 
        error = pthread_setspecific(filenames_key, files);
        if (error)
-               fprintf(stderr, "pthread_setspecific() returned %d.", error);
+               pr_err("pthread_setspecific() returned %d.", error);
 }
 
 void
@@ -124,7 +124,7 @@ fnstack_cleanup(void)
 
        error = pthread_setspecific(filenames_key, NULL);
        if (error)
-               fprintf(stderr, "pthread_setspecific() returned %d.", error);
+               pr_err("pthread_setspecific() returned %d.", error);
 }
 
 /**