fdf563
From 07b32184ee337ec06a405724b4b88cad22829c6d Mon Sep 17 00:00:00 2001
fdf563
From: Robbie Harwood <rharwood@redhat.com>
fdf563
Date: Mon, 30 Sep 2019 15:00:56 -0400
fdf563
Subject: [PATCH] Make syslog of call status configurable
fdf563
fdf563
Add a parameter (syslog_status) to configuration and
fdf563
CLI (--syslog-status).  This logs the results of GSSAPI calls at
fdf563
LOG_DEBUG.  Typically these calls resemble:
fdf563
fdf563
    gssproxy[28914]: (OID: { 1 2 840 113554 1 2 2 }) Unspecified GSS
fdf563
    failure.  Minor code may provide more information, No credentials
fdf563
    cache found
fdf563
fdf563
Since these messages worry some admins, turn them off by default.
fdf563
fdf563
Signed-off-by: Robbie Harwood <rharwood@redhat.com>
fdf563
(cherry picked from commit 116618e1523038691fcb481107ba15ffd42942ac)
fdf563
(cherry picked from commit cc61409b7b20974332549dd028d889b87dbff98d)
fdf563
---
fdf563
 man/gssproxy.8.xml      |  8 ++++++++
fdf563
 man/gssproxy.conf.5.xml | 10 ++++++++++
fdf563
 src/gp_config.c         |  6 ++++++
fdf563
 src/gp_log.c            |  9 +++++++--
fdf563
 src/gp_log.h            |  3 +++
fdf563
 src/gssproxy.c          |  6 ++++++
fdf563
 6 files changed, 40 insertions(+), 2 deletions(-)
fdf563
fdf563
diff --git a/man/gssproxy.8.xml b/man/gssproxy.8.xml
fdf563
index 21f7e6a..4019135 100644
fdf563
--- a/man/gssproxy.8.xml
fdf563
+++ b/man/gssproxy.8.xml
fdf563
@@ -151,6 +151,14 @@
fdf563
                 </listitem>
fdf563
             </varlistentry>
fdf563
 
fdf563
+            <varlistentry>
fdf563
+                <term>
fdf563
+                    <option>--syslog-status</option>
fdf563
+                </term>
fdf563
+                <listitem>
fdf563
+                    <para>Enable additional logging to syslog.</para>
fdf563
+                </listitem>
fdf563
+            </varlistentry>
fdf563
             <varlistentry>
fdf563
                 <term>
fdf563
                     <option>--version</option>
fdf563
diff --git a/man/gssproxy.conf.5.xml b/man/gssproxy.conf.5.xml
fdf563
index 21c9653..53cae3d 100644
fdf563
--- a/man/gssproxy.conf.5.xml
fdf563
+++ b/man/gssproxy.conf.5.xml
fdf563
@@ -365,6 +365,16 @@
fdf563
                     </listitem>
fdf563
                 </varlistentry>
fdf563
 
fdf563
+                <varlistentry>
fdf563
+                    <term>syslog_status (boolean)</term>
fdf563
+                    <listitem>
fdf563
+                        <para>Enable per-call debugging output to the syslog.
fdf563
+                        This may be useful for investigating problems in
fdf563
+                        applications using gssproxy.</para>
fdf563
+                        <para>Default: syslog_status = false</para>
fdf563
+                    </listitem>
fdf563
+                </varlistentry>
fdf563
+
fdf563
                 <varlistentry>
fdf563
                     <term>trusted (boolean)</term>
fdf563
                         <listitem><para>Defines whether this service is considered trusted. Use with caution, this enables impersonation.</para>
fdf563
diff --git a/src/gp_config.c b/src/gp_config.c
fdf563
index 78474ed..88d5f29 100644
fdf563
--- a/src/gp_config.c
fdf563
+++ b/src/gp_config.c
fdf563
@@ -611,6 +611,12 @@ int load_config(struct gp_config *cfg)
fdf563
         goto done;
fdf563
     }
fdf563
 
fdf563
+    ret = gp_config_get_string(ctx, "gssproxy", "syslog_status", &tmpstr);
fdf563
+    if (ret == 0)
fdf563
+        gp_syslog_status = gp_boolean_is_true(tmpstr);
fdf563
+    else if (ret != ENOENT)
fdf563
+        goto done;
fdf563
+
fdf563
     ret = gp_config_get_string(ctx, "gssproxy", "run_as_user", &tmpstr);
fdf563
     if (ret == 0) {
fdf563
         cfg->proxy_user = strdup(tmpstr);
fdf563
diff --git a/src/gp_log.c b/src/gp_log.c
fdf563
index b6eb161..e67e8d3 100644
fdf563
--- a/src/gp_log.c
fdf563
+++ b/src/gp_log.c
fdf563
@@ -5,6 +5,9 @@
fdf563
 #include <stdio.h>
fdf563
 #include <stdarg.h>
fdf563
 
fdf563
+/* global logging switch */
fdf563
+bool gp_syslog_status = false;
fdf563
+
fdf563
 void gp_logging_init(void)
fdf563
 {
fdf563
     openlog("gssproxy",
fdf563
@@ -55,7 +58,9 @@ void gp_log_status(gss_OID mech, uint32_t maj, uint32_t min)
fdf563
 {
fdf563
     char buf[MAX_LOG_LINE];
fdf563
 
fdf563
-    gp_fmt_status(mech, maj, min, buf, MAX_LOG_LINE);
fdf563
+    if (!gp_syslog_status)
fdf563
+        return;
fdf563
 
fdf563
-    GPERROR("%s\n", buf);
fdf563
+    gp_fmt_status(mech, maj, min, buf, MAX_LOG_LINE);
fdf563
+    syslog(LOG_DEBUG, "%s\n", buf);
fdf563
 }
fdf563
diff --git a/src/gp_log.h b/src/gp_log.h
fdf563
index fc8cbdb..31ad648 100644
fdf563
--- a/src/gp_log.h
fdf563
+++ b/src/gp_log.h
fdf563
@@ -3,9 +3,12 @@
fdf563
 #ifndef _GP_LOG_H_
fdf563
 #define _GP_LOG_H_
fdf563
 
fdf563
+#include <stdbool.h>
fdf563
 #include <syslog.h>
fdf563
 #include <gssapi/gssapi.h>
fdf563
 
fdf563
+extern bool gp_syslog_status;
fdf563
+
fdf563
 #define MAX_LOG_LINE 1024
fdf563
 #define GPERROR(...) syslog(LOG_ERR, __VA_ARGS__);
fdf563
 #define GPAUDIT(...) syslog(LOG_INFO, __VA_ARGS__);
fdf563
diff --git a/src/gssproxy.c b/src/gssproxy.c
fdf563
index db6e89b..6b72a9b 100644
fdf563
--- a/src/gssproxy.c
fdf563
+++ b/src/gssproxy.c
fdf563
@@ -157,6 +157,7 @@ int main(int argc, const char *argv[])
fdf563
     int opt_version = 0;
fdf563
     int opt_debug = 0;
fdf563
     int opt_debug_level = 0;
fdf563
+    int opt_syslog_status = 0;
fdf563
     verto_ctx *vctx;
fdf563
     verto_ev *ev;
fdf563
     int wait_fd;
fdf563
@@ -182,6 +183,8 @@ int main(int argc, const char *argv[])
fdf563
          _("Enable debugging"), NULL}, \
fdf563
         {"debug-level", '\0', POPT_ARG_INT, &opt_debug_level, 0, \
fdf563
          _("Set debugging level"), NULL}, \
fdf563
+        {"syslog-status", '\0', POPT_ARG_NONE, &opt_syslog_status, 0, \
fdf563
+         _("Enable GSSAPI status logging to syslog"), NULL}, \
fdf563
         {"version", '\0', POPT_ARG_NONE, &opt_version, 0, \
fdf563
          _("Print version number and exit"), NULL }, \
fdf563
         POPT_TABLEEND
fdf563
@@ -211,6 +214,9 @@ int main(int argc, const char *argv[])
fdf563
         gp_debug_toggle(opt_debug_level);
fdf563
     }
fdf563
 
fdf563
+    if (opt_syslog_status)
fdf563
+        gp_syslog_status = true;
fdf563
+
fdf563
     if (opt_daemon && opt_interactive) {
fdf563
         fprintf(stderr, "Option -i|--interactive is not allowed together with -D|--daemon\n");
fdf563
         poptPrintUsage(pc, stderr, 0);