~percona-dev/percona-server/release-5.1.49-12-rnt-pre

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
# name       : mysql-syslog.patch
# introduced : 12
# maintainer : Oleg
#
#!!! notice !!!
# Any small change to this file in the main branch
# should be done or reviewed by the maintainer!

diff -Nur a/client/client_priv.h b/client/client_priv.h
--- a/client/client_priv.h	2010-08-08 14:12:42.229338865 +0400
+++ b/client/client_priv.h	2010-08-08 14:12:43.068089277 +0400
@@ -90,6 +90,7 @@
   OPT_FIX_TABLE_NAMES, OPT_FIX_DB_NAMES, OPT_SSL_VERIFY_SERVER_CERT,
   OPT_DEBUG_INFO, OPT_DEBUG_CHECK, OPT_COLUMN_TYPES, OPT_ERROR_LOG_FILE,
   OPT_WRITE_BINLOG, OPT_DUMP_DATE,
+  OPT_SYSLOG,
   OPT_FIRST_SLAVE,
   OPT_ALL,
   OPT_MAX_CLIENT_OPTION,
diff -Nur a/client/mysql.cc b/client/mysql.cc
--- a/client/mysql.cc	2010-08-08 14:12:42.229338865 +0400
+++ b/client/mysql.cc	2010-08-08 14:12:43.488088866 +0400
@@ -43,6 +43,9 @@
 #include "my_readline.h"
 #include <signal.h>
 #include <violite.h>
+#ifndef __WIN__
+#include "syslog.h"
+#endif
 
 #if defined(USE_LIBEDIT_INTERFACE) && defined(HAVE_LOCALE_H)
 #include <locale.h>
@@ -154,7 +157,7 @@
 	       default_charset_used= 0, opt_secure_auth= 0,
                default_pager_set= 0, opt_sigint_ignore= 0,
                show_warnings= 0, executing_query= 0, interrupted_query= 0,
-               ignore_spaces= 0;
+               opt_syslog=0, ignore_spaces= 0;
 static my_bool debug_info_flag, debug_check_flag;
 static my_bool column_types_flag;
 static my_bool preserve_comments= 0;
@@ -209,6 +212,7 @@
 void tee_fputs(const char *s, FILE *file);
 void tee_puts(const char *s, FILE *file);
 void tee_putc(int c, FILE *file);
+void write_syslog(char *line);
 static void tee_print_sized_data(const char *, unsigned int, unsigned int, bool);
 /* The names of functions that actually do the manipulation. */
 static int get_options(int argc,char **argv);
@@ -1568,6 +1572,10 @@
   {"show-warnings", OPT_SHOW_WARNINGS, "Show warnings after every statement.",
     &show_warnings, &show_warnings, 0, GET_BOOL, NO_ARG,
     0, 0, 0, 0, 0, 0},
+#ifndef __WIN__
+  {"syslog", OPT_SYSLOG, "Logs all queries to syslog", 0, 0, 0, GET_NO_ARG,
+   NO_ARG, 0, 0, 0, 0, 0, 0},
+#endif
   { 0, 0, 0, 0, 0, 0, GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0}
 };
 
@@ -1691,6 +1699,12 @@
                                     opt->name);
 #endif
     break;
+  case OPT_SYSLOG:
+    /*if (connect_flag == CLIENT_INTERACTIVE){
+      printf("Logging queries to syslog.\n");
+    }*/
+    opt_syslog = 1;
+    break;
   case OPT_SERVER_ARG:
 #ifdef EMBEDDED_LIBRARY
     /*
@@ -2067,6 +2081,39 @@
   DBUG_RETURN((COMMANDS *) 0);
 }
 
+void write_syslog(char *line){
+#ifndef __WIN__
+  char buff[901];
+  int i, buff_pos=0;
+  for (i=0;i < strlen(line); i++){
+    buff[buff_pos] = line[i];
+    buff_pos++;
+    if (buff_pos >= 900){
+      buff[900] = NULL;
+      buff_pos = 0;
+      syslog(LOG_INFO, "SYSTEM_USER:%s, MYSQL_USER:%s, CONNECTION_ID:%lu, DB_SERVER:%s, DB:%s, QUERY:%s",
+             getenv("SUDO_USER") ? getenv("SUDO_USER") :
+             getenv("USER") ? getenv("USER") : "--",
+             current_user ? current_user : "--",
+             mysql_thread_id(&mysql),
+             current_host ? current_host : "--",
+             current_db ? current_db : "--",
+             buff);
+    }
+  }
+  if (buff_pos > 0){
+    buff[buff_pos] = NULL;
+    syslog(LOG_INFO, "SYSTEM_USER:%s, MYSQL_USER:%s, CONNECTION_ID:%lu, DB_SERVER:%s, DB:%s, QUERY:%s",
+           getenv("SUDO_USER") ? getenv("SUDO_USER") :
+           getenv("USER") ? getenv("USER") : "--",
+           current_user ? current_user : "--",
+           mysql_thread_id(&mysql),
+           current_host ? current_host : "--",
+           current_db ? current_db : "--",
+           buff);
+  }
+#endif
+}
 
 static bool add_line(String &buffer,char *line,char *in_string,
                      bool *ml_comment, bool truncated)
@@ -3038,6 +3085,11 @@
     fix_history(buffer);
   }
 #endif
+#ifndef __WIN__
+  if (opt_syslog && buffer->length() && connect_flag == CLIENT_INTERACTIVE){
+    write_syslog(buffer->c_ptr());
+  }
+#endif
 
   buffer->length(0);