Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Obey debug_level when syslog()ing #7

Merged
merged 1 commit into from Aug 31, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
8 changes: 8 additions & 0 deletions man/gssproxy.8.xml
Expand Up @@ -148,6 +148,14 @@
</para>
</listitem>
</varlistentry>
<varlistentry>
<term>
<option>--syslog-status</option>
</term>
<listitem>
<para>Enable additional logging to syslog.</para>
</listitem>
</varlistentry>
<varlistentry>
<term>
<option>--version</option>
Expand Down
10 changes: 10 additions & 0 deletions man/gssproxy.conf.5.xml
Expand Up @@ -373,6 +373,16 @@
</listitem>
</varlistentry>

<varlistentry>
<term>syslog_status (boolean)</term>
<listitem>
<para>Enable per-call debugging output to the syslog.
This may be useful for investigating problems in
applications using gssproxy.</para>
<para>Default: syslog_status = false</para>
</listitem>
</varlistentry>

<varlistentry>
<term>trusted (boolean)</term>
<listitem><para>Defines whether this service is considered trusted. Use with caution, this enables impersonation.</para>
Expand Down
6 changes: 6 additions & 0 deletions src/gp_config.c
Expand Up @@ -611,6 +611,12 @@ int load_config(struct gp_config *cfg)
goto done;
}

ret = gp_config_get_string(ctx, "gssproxy", "syslog_status", &tmpstr);
if (ret == 0)
gp_syslog_status = gp_boolean_is_true(tmpstr);
else if (ret != ENOENT)
goto done;

ret = gp_config_get_string(ctx, "gssproxy", "run_as_user", &tmpstr);
if (ret == 0) {
cfg->proxy_user = strdup(tmpstr);
Expand Down
9 changes: 7 additions & 2 deletions src/gp_log.c
Expand Up @@ -5,6 +5,9 @@
#include <stdio.h>
#include <stdarg.h>

/* global logging switch */
bool gp_syslog_status = false;

void gp_logging_init(void)
{
openlog("gssproxy",
Expand Down Expand Up @@ -55,7 +58,9 @@ void gp_log_status(gss_OID mech, uint32_t maj, uint32_t min)
{
char buf[MAX_LOG_LINE];

gp_fmt_status(mech, maj, min, buf, MAX_LOG_LINE);
if (!gp_syslog_status)
return;

GPERROR("%s\n", buf);
gp_fmt_status(mech, maj, min, buf, MAX_LOG_LINE);
syslog(LOG_DEBUG, "%s\n", buf);
}
3 changes: 3 additions & 0 deletions src/gp_log.h
Expand Up @@ -3,9 +3,12 @@
#ifndef _GP_LOG_H_
#define _GP_LOG_H_

#include <stdbool.h>
#include <syslog.h>
#include <gssapi/gssapi.h>

extern bool gp_syslog_status;

#define MAX_LOG_LINE 1024
#define GPERROR(...) syslog(LOG_ERR, __VA_ARGS__);
#define GPAUDIT(...) syslog(LOG_INFO, __VA_ARGS__);
Expand Down
6 changes: 6 additions & 0 deletions src/gssproxy.c
Expand Up @@ -158,6 +158,7 @@ int main(int argc, const char *argv[])
int opt_version = 0;
int opt_debug = 0;
int opt_debug_level = 0;
int opt_syslog_status = 0;
verto_ctx *vctx;
verto_ev *ev;
int wait_fd;
Expand All @@ -183,6 +184,8 @@ int main(int argc, const char *argv[])
_("Enable debugging"), NULL}, \
{"debug-level", '\0', POPT_ARG_INT, &opt_debug_level, 0, \
_("Set debugging level"), NULL}, \
{"syslog-status", '\0', POPT_ARG_NONE, &opt_syslog_status, 0, \
_("Enable GSSAPI status logging to syslog"), NULL}, \
{"version", '\0', POPT_ARG_NONE, &opt_version, 0, \
_("Print version number and exit"), NULL }, \
POPT_TABLEEND
Expand Down Expand Up @@ -212,6 +215,9 @@ int main(int argc, const char *argv[])
gp_debug_toggle(opt_debug_level);
}

if (opt_syslog_status)
gp_syslog_status = true;

if (opt_daemon && opt_interactive) {
fprintf(stderr, "Option -i|--interactive is not allowed together with -D|--daemon\n");
poptPrintUsage(pc, stderr, 0);
Expand Down