Commit cee822ca authored by Rafal Somla's avatar Rafal Somla

Bug#12873214 WINDOWS AUTHENTICATION PLUGIN PRODUCES EXCESSIVE RECORDS IN SERVER ERROR LOG

      
Changed semantics of AUTHENTICATION_WIN_LOG environment variable recognized by client library to accept the following values which are levels of logging done during Windows authentication handshake:
      
  0 - no logging
  1 - log only error messages
  2 - additionally log warnings
  3 - additionally log info notes
  4 - also log debug messages
      
Setting it to 'on', 'yes' or 'true' will request log level 2 and setting it to 'debug' or 'dbug' will request log level 4.
parent 0750d88c
...@@ -22,6 +22,24 @@ template <> void error_log_print<error_log_level::INFO>(const char *fmt, ...); ...@@ -22,6 +22,24 @@ template <> void error_log_print<error_log_level::INFO>(const char *fmt, ...);
template <> void error_log_print<error_log_level::WARNING>(const char *fmt, ...); template <> void error_log_print<error_log_level::WARNING>(const char *fmt, ...);
template <> void error_log_print<error_log_level::ERROR>(const char *fmt, ...); template <> void error_log_print<error_log_level::ERROR>(const char *fmt, ...);
/**
Option indicating desired level of logging. Values:
0 - no logging
1 - log only error messages
2 - additionally log warnings
3 - additionally log info notes
4 - also log debug messages
Value of this option should be taken into account in the
implementation of error_log_vprint() function (see
log_client.cc).
Note: No error or debug messages are logged in production code
(see logging macros in common.h).
*/
int opt_auth_win_log_level= 2;
/** Connection class **************************************************/ /** Connection class **************************************************/
......
...@@ -41,13 +41,15 @@ struct error_log_level ...@@ -41,13 +41,15 @@ struct error_log_level
typedef enum {INFO, WARNING, ERROR} type; typedef enum {INFO, WARNING, ERROR} type;
}; };
extern "C" int opt_auth_win_log_level;
unsigned int get_log_level(void);
void set_log_level(unsigned int);
/* /*
If DEBUG_ERROR_LOG is defined then error logging happens only If DEBUG_ERROR_LOG is defined then error logging happens only
in debug-copiled code. Otherwise ERROR_LOG() expands to in debug-copiled code. Otherwise ERROR_LOG() expands to
error_log_print() even in production code. Note that in client error_log_print() even in production code.
plugin, error_log_print() will print nothing if opt_auth_win_clinet_log
is 0.
Note: Macro ERROR_LOG() can use printf-like format string like this: Note: Macro ERROR_LOG() can use printf-like format string like this:
...@@ -57,8 +59,6 @@ struct error_log_level ...@@ -57,8 +59,6 @@ struct error_log_level
to fprintf() (see error_log_vprint() function). to fprintf() (see error_log_vprint() function).
*/ */
extern "C" int opt_auth_win_client_log;
#if defined(DEBUG_ERROR_LOG) && defined(DBUG_OFF) #if defined(DEBUG_ERROR_LOG) && defined(DBUG_OFF)
#define ERROR_LOG(Level, Msg) do {} while (0) #define ERROR_LOG(Level, Msg) do {} while (0)
#else #else
...@@ -67,7 +67,7 @@ extern "C" int opt_auth_win_client_log; ...@@ -67,7 +67,7 @@ extern "C" int opt_auth_win_client_log;
void error_log_vprint(error_log_level::type level, void error_log_vprint(error_log_level::type level,
const char *fmt, va_list args); const char *fmt, va_list args);
template <error_log_level::type Level> template <error_log_level::type Level>
void error_log_print(const char *fmt, ...) void error_log_print(const char *fmt, ...)
...@@ -96,7 +96,7 @@ const char* get_last_error_message(Error_message_buf); ...@@ -96,7 +96,7 @@ const char* get_last_error_message(Error_message_buf);
#define DBUG_PRINT_DO(Keyword, Msg) \ #define DBUG_PRINT_DO(Keyword, Msg) \
do { \ do { \
if (2 > opt_auth_win_client_log) break; \ if (4 > get_log_level()) break; \
fprintf(stderr, "winauth: %s: ", Keyword); \ fprintf(stderr, "winauth: %s: ", Keyword); \
debug_msg Msg; \ debug_msg Msg; \
} while (0) } while (0)
......
...@@ -323,13 +323,13 @@ int win_auth_handshake_client(MYSQL_PLUGIN_VIO *vio, MYSQL *mysql) ...@@ -323,13 +323,13 @@ int win_auth_handshake_client(MYSQL_PLUGIN_VIO *vio, MYSQL *mysql)
int opt_val= opt ? atoi(opt) : 0; int opt_val= opt ? atoi(opt) : 0;
if (opt && !opt_val) if (opt && !opt_val)
{ {
if (!strncasecmp("on", opt, 2)) opt_val= 1; if (!strncasecmp("on", opt, 2)) opt_val= 2;
if (!strncasecmp("yes", opt, 3)) opt_val= 1; if (!strncasecmp("yes", opt, 3)) opt_val= 2;
if (!strncasecmp("true", opt, 4)) opt_val= 1; if (!strncasecmp("true", opt, 4)) opt_val= 2;
if (!strncasecmp("debug", opt, 5)) opt_val= 2; if (!strncasecmp("debug", opt, 5)) opt_val= 4;
if (!strncasecmp("dbug", opt, 4)) opt_val= 2; if (!strncasecmp("dbug", opt, 4)) opt_val= 4;
} }
opt_auth_win_client_log= opt_val; set_log_level(opt_val);
} }
ERROR_LOG(INFO, ("Authentication handshake for account %s", mysql->user)); ERROR_LOG(INFO, ("Authentication handshake for account %s", mysql->user));
......
...@@ -16,36 +16,32 @@ ...@@ -16,36 +16,32 @@
#include <my_global.h> #include <my_global.h>
#include "common.h" #include "common.h"
/**
This option is set in win_auth_handshake_client() function
in handshake_client.cc.
Values:
0 - no logging
1 - log error/warning/info messages
2 - also log debug messages
Note: No error or debug messages are logged in production code
(see logging macros in common.h).
*/
int opt_auth_win_client_log= 0;
// Client-side logging function // Client-side logging function
void error_log_vprint(error_log_level::type level, void error_log_vprint(error_log_level::type level,
const char *fmt, va_list args) const char *fmt, va_list args)
{ {
if (0 == opt_auth_win_client_log)
return;
const char *level_string= ""; const char *level_string= "";
int log_level= get_log_level();
switch (level) switch (level)
{ {
case error_log_level::INFO: level_string= "Note"; break; case error_log_level::INFO:
case error_log_level::WARNING: level_string= "Warning"; break; if (3 > log_level)
case error_log_level::ERROR: level_string= "ERROR"; break; return;
level_string= "Note";
break;
case error_log_level::WARNING:
if (2 > log_level)
return;
level_string= "Warning";
break;
case error_log_level::ERROR:
if (1 > log_level)
return;
level_string= "ERROR";
break;
} }
fprintf(stderr, "Windows Authentication Plugin %s: ", level_string); fprintf(stderr, "Windows Authentication Plugin %s: ", level_string);
...@@ -53,3 +49,17 @@ void error_log_vprint(error_log_level::type level, ...@@ -53,3 +49,17 @@ void error_log_vprint(error_log_level::type level,
fputc('\n', stderr); fputc('\n', stderr);
fflush(stderr); fflush(stderr);
} }
// Trivial implementation of log-level setting storage.
void set_log_level(unsigned int level)
{
opt_auth_win_log_level= level;
}
unsigned int get_log_level(void)
{
return opt_auth_win_log_level;
}
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment