Make syslog history configurable

2017-01-25 Thread Siteshwar Vashisht
Hello,

Bash history is logged to syslog if SYSLOG_HISTORY macro is defined in 
config-top.h. There is no option to enable/disable it at runtime. I am adding a 
shell option 'syshist' that can be used to configure logging bash history to 
syslog at runtime.


-- 
--
Siteshwar Vashisht
From c6ec0d751ded75188f64d1d1ac9916c44153c305 Mon Sep 17 00:00:00 2001
From: Siteshwar Vashisht 
Date: Tue, 24 Jan 2017 17:28:14 +0100
Subject: [PATCH] Make syslog history configurable

---
 bashhist.c   | 3 ++-
 builtins/set.def | 9 +
 config-top.h | 4 ++--
 flags.c  | 7 +++
 flags.h  | 4 
 5 files changed, 24 insertions(+), 3 deletions(-)

diff --git a/bashhist.c b/bashhist.c
index 9979f99..e6127c8 100644
--- a/bashhist.c
+++ b/bashhist.c
@@ -851,7 +851,8 @@ bash_add_history (line)
 really_add_history (line);
 
 #if defined (SYSLOG_HISTORY)
-  bash_syslog_history (line);
+  if (syslog_history)
+bash_syslog_history (line);
 #endif
 
   using_history ();
diff --git a/builtins/set.def b/builtins/set.def
index 8122361..718ba39 100644
--- a/builtins/set.def
+++ b/builtins/set.def
@@ -116,6 +116,9 @@ Options:
operation differs from the Posix standard to
match the standard
   privileged   same as -p
+#if defined (SYSLOG_HISTORY)
+  syshist  same as -S
+#endif
   verbose  same as -v
 #if defined (READLINE)
   vi   use a vi-style line editing interface
@@ -141,6 +144,9 @@ Options:
 #endif /* BANG_HISTORY */
   -P  If set, do not resolve symbolic links when executing commands
   such as cd which change the current directory.
+#if defined (SYSLOG_HISTORY)
+  -S  If set, log history to syslog
+#endif
   -T  If set, the DEBUG and RETURN traps are inherited by shell functions.
   --  Assign any remaining arguments to the positional parameters.
   If there are no remaining arguments, the positional parameters
@@ -231,6 +237,9 @@ const struct {
   { "pipefail",  '\0', &pipefail_opt, (setopt_set_func_t *)NULL, (setopt_get_func_t *)NULL  },
   { "posix", '\0', &posixly_correct, set_posix_mode, (setopt_get_func_t *)NULL },
   { "privileged", 'p', (int *)NULL, (setopt_set_func_t *)NULL, (setopt_get_func_t *)NULL  },
+#if defined (SYSLOG_HISTORY)
+  { "syshist", 'S', (int *)NULL, (setopt_set_func_t *)NULL, (setopt_get_func_t *)NULL  },
+#endif
   { "verbose",	  'v', (int *)NULL, (setopt_set_func_t *)NULL, (setopt_get_func_t *)NULL  },
 #if defined (READLINE)
   { "vi",'\0', (int *)NULL, set_edit_mode, get_edit_mode },
diff --git a/config-top.h b/config-top.h
index cb0e002..ae8d124 100644
--- a/config-top.h
+++ b/config-top.h
@@ -114,8 +114,8 @@
 /* #define NOTFOUND_HOOK "command_not_found_handle" */
 
 /* Define if you want each line saved to the history list in bashhist.c:
-   bash_add_history() to be sent to syslog(). */
-/* #define SYSLOG_HISTORY */
+   If syshist shell option is set, bash_add_history() to be sent to syslog(). */
+#define SYSLOG_HISTORY
 #if defined (SYSLOG_HISTORY)
 #  define SYSLOG_FACILITY LOG_USER
 #  define SYSLOG_LEVEL LOG_INFO
diff --git a/flags.c b/flags.c
index 4b94fb0..cc16221 100644
--- a/flags.c
+++ b/flags.c
@@ -137,6 +137,10 @@ int history_expansion = 1;
 #  endif
 #endif /* BANG_HISTORY */
 
+#if defined (SYSLOG_HISTORY)
+int syslog_history = 0;
+#endif 
+
 /* Non-zero means that we allow comments to appear in interactive commands. */
 int interactive_comments = 1;
 
@@ -215,6 +219,9 @@ const struct flags_alist shell_flags[] = {
 #endif /* BANG_HISTORY */
   { 'I', &no_invisible_vars },
   { 'P', &no_symbolic_links },
+#if defined (SYSLOG_HISTORY)
+  { 'S', &syslog_history},
+#endif /* SYSLOG_HISTORY */
   { 'T', &function_trace_mode },
   {0, (int *)NULL}
 };
diff --git a/flags.h b/flags.h
index d5ed334..7fe25d5 100644
--- a/flags.h
+++ b/flags.h
@@ -62,6 +62,10 @@ extern int brace_expansion;
 extern int history_expansion;
 #endif /* BANG_HISTORY */
 
+#if defined (SYSLOG_HISTORY)
+extern int syslog_history;
+#endif
+
 #if defined (RESTRICTED_SHELL)
 extern int restricted;
 extern int restricted_shell;
-- 
2.9.3



Re: Make syslog history configurable

2017-01-25 Thread Chet Ramey
On 1/25/17 7:39 AM, Siteshwar Vashisht wrote:
> Hello,
> 
> Bash history is logged to syslog if SYSLOG_HISTORY macro is defined in 
> config-top.h. There is no option to enable/disable it at runtime. I am adding 
> a shell option 'syshist' that can be used to configure logging bash history 
> to syslog at runtime.

Thanks. I'll take a look at including this in a future bash version.

Chet
-- 
``The lyf so short, the craft so long to lerne.'' - Chaucer
 ``Ars longa, vita brevis'' - Hippocrates
Chet Ramey, UTech, CWRUc...@case.eduhttp://cnswww.cns.cwru.edu/~chet/



Re: Make syslog history configurable

2017-01-25 Thread Siteshwar Vashisht


- Original Message -
> From: "Siteshwar Vashisht" 
> To: bug-bash@gnu.org
> Sent: Wednesday, January 25, 2017 1:39:12 PM
> Subject: Make syslog history configurable
> 
> Hello,
> 
> Bash history is logged to syslog if SYSLOG_HISTORY macro is defined in
> config-top.h. There is no option to enable/disable it at runtime. I am
> adding a shell option 'syshist' that can be used to configure logging bash
> history to syslog at runtime.

I modified the patch to use shopt instead of set to enable/disable syslog 
history.
> 
> 
> --
> --
> Siteshwar Vashisht
> 

-- 
--
Siteshwar Vashisht
From 49d2435aefca79b08d19f67c139d2091634853f5 Mon Sep 17 00:00:00 2001
From: Siteshwar Vashisht 
Date: Wed, 25 Jan 2017 15:58:59 +0100
Subject: [PATCH] Make syslog history configurable with shopt

---
 bashhist.c |  5 +++--
 builtins/shopt.def | 11 +++
 config-top.h   |  2 +-
 3 files changed, 15 insertions(+), 3 deletions(-)

diff --git a/bashhist.c b/bashhist.c
index 9979f99..7ab6486 100644
--- a/bashhist.c
+++ b/bashhist.c
@@ -749,7 +749,7 @@ check_add_history (line, force)
 #define SYSLOG_MAXLEN 600
 
 extern char *shell_name;
-
+int syslog_history = 0;
 #ifndef OPENLOG_OPTS
 #define OPENLOG_OPTS 0
 #endif
@@ -851,7 +851,8 @@ bash_add_history (line)
 really_add_history (line);
 
 #if defined (SYSLOG_HISTORY)
-  bash_syslog_history (line);
+  if (syslog_history)
+bash_syslog_history (line);
 #endif
 
   using_history ();
diff --git a/builtins/shopt.def b/builtins/shopt.def
index 2febb7e..848bab3 100644
--- a/builtins/shopt.def
+++ b/builtins/shopt.def
@@ -118,6 +118,10 @@ extern char *shell_name;
 extern int debugging_mode;
 #endif
 
+#if defined (SYSLOG_HISTORY)
+extern int syslog_history;
+#endif
+
 static void shopt_error __P((char *));
 
 static int set_shellopts_after_change __P((char *, int));
@@ -223,6 +227,9 @@ static struct {
 #endif
   { "shift_verbose", &print_shift_error, (shopt_set_func_t *)NULL },
   { "sourcepath", &source_uses_path, (shopt_set_func_t *)NULL },
+#if defined (SYSLOG_HISTORY)
+  { "syslog_history", &syslog_history, (shopt_set_func_t *)NULL },
+#endif
   { "xpg_echo", &xpg_echo, (shopt_set_func_t *)NULL },
   { (char *)0, (int *)0, (shopt_set_func_t *)NULL }
 };
@@ -345,6 +352,10 @@ reset_shopt_options ()
   command_oriented_history = 1;
 #endif
 
+#if defined (SYSLOG_HISTORY)
+  syslog_history = 0;
+#endif
+
 #if defined (READLINE)
   complete_fullquote = 1;
   force_fignore = 1;
diff --git a/config-top.h b/config-top.h
index cb0e002..8051fad 100644
--- a/config-top.h
+++ b/config-top.h
@@ -115,7 +115,7 @@
 
 /* Define if you want each line saved to the history list in bashhist.c:
bash_add_history() to be sent to syslog(). */
-/* #define SYSLOG_HISTORY */
+#define SYSLOG_HISTORY
 #if defined (SYSLOG_HISTORY)
 #  define SYSLOG_FACILITY LOG_USER
 #  define SYSLOG_LEVEL LOG_INFO
-- 
2.9.3



Re: null pointer deref, segfault

2017-01-25 Thread L A Walsh

Andreas Schwab wrote:

On Jan 24 2017, "Brian 'geeknik' Carpenter"  wrote:

  

<<$(()())|>_[$($(<<0)) crashes bash on Debian, Red Hat, FreeBSD, etc.



Worksforme with bash 4.4.
  

---
   I duplicated it under bash 4.3.42, but not under 4.4.5.


-l