]> eyrie.org Git - kerberos/krb5-sync.git/commitdiff
New syslog option to suppress syslog logging
authorRuss Allbery <eagle@eyrie.org>
Thu, 5 Dec 2013 00:48:08 +0000 (16:48 -0800)
committerRuss Allbery <eagle@eyrie.org>
Thu, 5 Dec 2013 00:48:08 +0000 (16:48 -0800)
Add a new boolean krb5.conf option, syslog, which can be set to false
to suppress syslog logging of the actions taken by the plugin and
error messages leading to queuing the change.  Always log the error
that leads to queuing a status change.

Makefile.am
NEWS
README
plugin/ad.c
plugin/api.c
plugin/internal.h
plugin/logging.c [new file with mode: 0644]
tests/data/krb5.conf
tests/data/queue.conf

index eb90b675f542a61ff1ac3780d4bf26f221a706e6..234a10037bce3f3a5cfa9b26ddccb2d1fb7551cc 100644 (file)
@@ -34,7 +34,7 @@ moduledir = $(libdir)/krb5/plugins/kadm5_hook
 module_LTLIBRARIES = plugin/krb5_sync.la
 plugin_krb5_sync_la_SOURCES = plugin/ad.c plugin/api.c plugin/config.c     \
        plugin/error.c plugin/internal.h plugin/heimdal.c plugin/instance.c \
-       plugin/mit.c plugin/queue.c plugin/vector.c
+       plugin/logging.c plugin/mit.c plugin/queue.c plugin/vector.c
 plugin_krb5_sync_la_CPPFLAGS = $(KADM5SRV_CPPFLAGS) $(LDAP_CPPFLAGS) \
        $(AM_CPPFLAGS)
 plugin_krb5_sync_la_LDFLAGS = -module -avoid-version $(KADM5SRV_LDFLAGS) \
diff --git a/NEWS b/NEWS
index d851416e6a5cc7d89f3d73fc60a30a0d01f98c6e..3f46fe1f0f52a63f4a49600e3bd8727985da92c5 100644 (file)
--- a/NEWS
+++ b/NEWS
@@ -40,6 +40,11 @@ krb5-sync 3.0 (unreleased)
     Directory cause performance issues in kadmind or kpasswdd.  kpasswd
     clients in particular are often intolerant of delays.
 
+    Add a new boolean krb5.conf option, syslog, which can be set to false
+    to suppress syslog logging of the actions taken by the plugin and
+    error messages leading to queuing the change.  Always log the error
+    that leads to queuing a status change.
+
     Any time an Active Directory password change fails, queue the change
     instead of failing it, rather than trying to distinguish between local
     errors that should fail the change and errors that should be queued.
diff --git a/README b/README
index 11cf9ec8ca158b32fe6ea332e99f861ab9269a32..c7acd27d6537e1d6f511390c5a52d191bb8fc710 100644 (file)
--- a/README
+++ b/README
@@ -212,6 +212,7 @@ CONFIGURATION
           ad_queue_only    = false
 
           queue_dir        = /var/spool/krb5-sync
+          syslog           = true
       }
 
   It is possible to add realm-specific configuration here following the
@@ -306,6 +307,14 @@ CONFIGURATION
       you'll want to either change the path in that script or always use
       the -d option.
 
+  syslog
+
+      Whether or not to log errors, warnings, and informational messages
+      from the plugin to syslog.  By default, this is enabled.  Set this
+      configuration option to false to suppress this logging, in which
+      case the only logging will be for errors returned to the kadmind or
+      kpasswdd servers.
+
   With MIT Kerberos 1.9 or later, support for kadmind plugins is built in.
   To load this plugin, add the following to the kdc.conf or krb5.conf file
   used by kadmind:
index 29930530b18f08d9f4e9dbed6cacd67149a5dbe6..8c3803d7f0a3ea97189c25bfaaf1bb27ed356c3c 100644 (file)
@@ -20,7 +20,6 @@
 #include <errno.h>
 #include <lber.h>
 #include <ldap.h>
-#include <syslog.h>
 
 #include <plugin/internal.h>
 #include <util/macros.h>
@@ -228,7 +227,7 @@ sync_ad_chpass(kadm5_hook_modinfo *config, krb5_context ctx,
     }
     free(result_string.data);
     free(result_code_string.data);
-    syslog(LOG_INFO, "krb5-sync: %s password changed", target);
+    sync_syslog_info(config, "krb5-sync: %s password changed", target);
 
 done:
     krb5_cc_destroy(ctx, ccache);
@@ -412,8 +411,8 @@ sync_ad_status(kadm5_hook_modinfo *config, krb5_context ctx,
 
     /* Success. */
     code = 0;
-    syslog(LOG_INFO, "successfully %s account %s",
-           enabled ? "enabled" : "disabled", target);
+    sync_syslog_info(config, "successfully %s account %s",
+                     enabled ? "enabled" : "disabled", target);
 
 done:
     free(ldapuri);
index 7aa147224b2103aa10cf812733b41d023ee0ed28..adc869b0fc8570b115b1edca196a21cb866e34b5 100644 (file)
@@ -24,7 +24,6 @@
 #include <portable/system.h>
 
 #include <errno.h>
-#include <syslog.h>
 
 #include <plugin/internal.h>
 #include <util/macros.h>
@@ -65,6 +64,10 @@ sync_init(krb5_context ctx, kadm5_hook_modinfo **result)
     /* Get the directory for queued changes from krb5.conf. */
     sync_config_string(ctx, "queue_dir", &config->queue_dir);
 
+    /* Whether to log informational and warning messages to syslog. */
+    config->syslog = true;
+    sync_config_boolean(ctx, "syslog", &config->syslog);
+
     /* Initialized.  Set data and return. */
     *result = config;
     return 0;
@@ -152,13 +155,11 @@ principal_allowed(kadm5_hook_modinfo *config, krb5_context ctx,
         if (exists) {
             code = krb5_unparse_name(ctx, principal, &display);
             if (code != 0)
-                display = NULL;
-            syslog(LOG_DEBUG, "account synchronization skipping principal"
-                   " \"%s\" for Active Directory because %s instance exists",
-                   display != NULL ? display : "???",
-                   config->ad_base_instance);
-            if (display != NULL)
-                krb5_free_unparsed_name(ctx, display);
+                return code;
+            sync_syslog_debug(config, "krb5-sync: ignoring principal \"%s\""
+                              " because %s instance exists", display,
+                              config->ad_base_instance);
+            krb5_free_unparsed_name(ctx, display);
             *allowed = false;
         }
     } else if (ncomp > 1) {
@@ -168,12 +169,10 @@ principal_allowed(kadm5_hook_modinfo *config, krb5_context ctx,
         if (!instance_allowed(config, instance)) {
             code = krb5_unparse_name(ctx, principal, &display);
             if (code != 0)
-                display = NULL;
-            syslog(LOG_DEBUG, "account synchronization skipping principal"
-                   " \"%s\" with non-null instance for Active Directory",
-                   display != NULL ? display : "???");
-            if (display != NULL)
-                krb5_free_unparsed_name(ctx, display);
+                return code;
+            sync_syslog_debug(config, "krb5-sync: ignoring principal \"%s\""
+                              " with non-null instance", display);
+            krb5_free_unparsed_name(ctx, display);
             *allowed = false;
         }
     }
@@ -210,23 +209,13 @@ sync_chpass(kadm5_hook_modinfo *config, krb5_context ctx,
     if (password == NULL)
         return 0;
     code = principal_allowed(config, ctx, principal, true, &allowed);
-    if (code != 0) {
-        message = krb5_get_error_message(ctx, code);
-        syslog(LOG_WARNING, "krb5-sync: cannot check if password change"
-               " should be propagated: %s", message);
-        krb5_free_error_message(ctx, message);
+    if (code != 0)
         return code;
-    }
     if (!allowed)
         return 0;
     code = sync_queue_conflict(config, ctx, principal, "enable", &conflict);
-    if (code != 0) {
-        message = krb5_get_error_message(ctx, code);
-        syslog(LOG_WARNING, "krb5-sync: cannot check for queue conflicts: %s",
-               message);
-        krb5_free_error_message(ctx, message);
+    if (code != 0)
         return code;
-    }
     if (conflict)
         goto queue;
     if (config->ad_queue_only)
@@ -234,8 +223,8 @@ sync_chpass(kadm5_hook_modinfo *config, krb5_context ctx,
     code = sync_ad_chpass(config, ctx, principal, password);
     if (code != 0) {
         message = krb5_get_error_message(ctx, code);
-        syslog(LOG_INFO, "krb5-sync: AD password change failed, queuing: %s",
-               message);
+        sync_syslog_notice(config, "krb5-sync: AD password change failed,"
+                           " queuing: %s", message);
         krb5_free_error_message(ctx, message);
         goto queue;
     }
@@ -271,30 +260,25 @@ sync_status(kadm5_hook_modinfo *config, krb5_context ctx,
         || config->ad_realm == NULL)
         return 0;
     code = principal_allowed(config, ctx, principal, true, &allowed);
-    if (code != 0) {
-        message = krb5_get_error_message(ctx, code);
-        syslog(LOG_WARNING, "krb5-sync: cannot check if password change"
-               " should be propagated: %s", message);
-        krb5_free_error_message(ctx, message);
+    if (code != 0)
         return code;
-    }
     if (!allowed)
         return 0;
     code = sync_queue_conflict(config, ctx, principal, "enable", &conflict);
-    if (code != 0) {
-        message = krb5_get_error_message(ctx, code);
-        syslog(LOG_WARNING, "krb5-sync: cannot check for queue conflicts: %s",
-               message);
-        krb5_free_error_message(ctx, message);
+    if (code != 0)
         return code;
-    }
     if (conflict)
         goto queue;
     if (config->ad_queue_only)
         goto queue;
     code = sync_ad_status(config, ctx, principal, enabled);
-    if (code != 0)
+    if (code != 0) {
+        message = krb5_get_error_message(ctx, code);
+        sync_syslog_notice(config, "krb5-sync: AD status change failed,"
+                           " queuing: %s", message);
+        krb5_free_error_message(ctx, message);
         goto queue;
+    }
     return 0;
 
 queue:
index d0b57401c969a7d7e0bb440cce0520592a834e06..2135a40e2ed41c39fb557e19a981b781f7635271 100644 (file)
@@ -50,6 +50,7 @@ struct kadm5_hook_modinfo_st {
     bool ad_queue_only;
     char *ad_realm;
     char *queue_dir;
+    bool syslog;
 };
 
 BEGIN_DECLS
@@ -151,6 +152,16 @@ krb5_error_code sync_error_ldap(krb5_context, int, const char *format, ...)
 krb5_error_code sync_error_system(krb5_context, const char *format, ...)
     __attribute__((__nonnull__, __format__(printf, 2, 3)));
 
+/* Log messages to syslog if configured to do so. */
+void sync_syslog_debug(kadm5_hook_modinfo *, const char *format, ...)
+    __attribute__((__nonnull__, __format__(printf, 2, 3)));
+void sync_syslog_info(kadm5_hook_modinfo *, const char *format, ...)
+    __attribute__((__nonnull__, __format__(printf, 2, 3)));
+void sync_syslog_notice(kadm5_hook_modinfo *, const char *format, ...)
+    __attribute__((__nonnull__, __format__(printf, 2, 3)));
+void sync_syslog_warning(kadm5_hook_modinfo *, const char *format, ...)
+    __attribute__((__nonnull__, __format__(printf, 2, 3)));
+
 /* Undo default visibility change. */
 #pragma GCC visibility pop
 
diff --git a/plugin/logging.c b/plugin/logging.c
new file mode 100644 (file)
index 0000000..d95922c
--- /dev/null
@@ -0,0 +1,66 @@
+/*
+ * Syslog logging.
+ *
+ * Functions to log informational and warning messages through syslog.  There
+ * are cases, such as when we queue changes, where we want to log the reason
+ * but return success to kadmind or kpasswdd, which means that they won't log
+ * anything.  In those cases, we log directly to syslog unless the syslog
+ * configuration option is set to false.
+ *
+ * Written by Russ Allbery <eagle@eyrie.org>
+ * Copyright 2013
+ *     The Board of Trustees of the Leland Stanford Junior University
+ *
+ * See LICENSE for licensing terms.
+ */
+
+#include <config.h>
+#include <portable/system.h>
+
+#include <syslog.h>
+
+#include <plugin/internal.h>
+
+
+/*
+ * Log a message to syslog.  This is a helper function used to implement all
+ * of the syslog logging functions.  If we can't allocate memory for the
+ * message to log, we just do nothing, since these functions are only used for
+ * supplemental logging.
+ */
+static void
+log_syslog(kadm5_hook_modinfo *config, int priority, const char *fmt,
+           va_list args)
+{
+    char *message;
+    int status;
+
+    /* If configured not to log, do nothing. */
+    if (!config->syslog)
+        return;
+
+    /* Log the message. */
+    status = vasprintf(&message, fmt, args);
+    if (status < 0)
+        return;
+    syslog(priority, "%s", message);
+    free(message);
+}
+
+
+/*
+ * Generate the functions for the various priority levels we use.
+ */
+#define SYSLOG_FUNCTION(name, type)                                     \
+    void                                                                \
+    sync_syslog_ ## name(kadm5_hook_modinfo *c, const char *f, ...)     \
+    {                                                                   \
+        va_list args;                                                   \
+        va_start(args, f);                                              \
+        log_syslog(c, LOG_ ## type, f, args);                           \
+        va_end(args);                                                   \
+    }
+SYSLOG_FUNCTION(debug,   DEBUG)
+SYSLOG_FUNCTION(info,    INFO)
+SYSLOG_FUNCTION(notice,  NOTICE)
+SYSLOG_FUNCTION(warning, WARNING)
index b77c8698a11ebdc18c84720fd61bcb7a54bbb233..2eff6b7b5568848164fef8886891700b3b6746fa 100644 (file)
@@ -11,6 +11,7 @@
         ad_instances      = exclude
 
         queue_dir         = queue
+        syslog            = false
     }
 
 [libdefaults]
index 5c27fa4b2fc4070ce5db7aeccc6b31c3db524f9b..6c9b986877469a7c97bd999d5671058501bc1e7c 100644 (file)
@@ -12,6 +12,7 @@
         ad_queue_only     = true
 
         queue_dir         = queue
+        syslog            = false
     }
 
 [libdefaults]