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

[TACACS+] Add plugin support to bash. #8660

Merged
merged 29 commits into from
Oct 11, 2021
Merged
Show file tree
Hide file tree
Changes from 8 commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
cda3fa8
[TACACS] Add plugin support to bash.
liuh-80 Sep 2, 2021
cadfc8f
Build bash from source code
Sep 3, 2021
79b5004
Change diff file to based on 5.0-4 version
liuh-80 Sep 3, 2021
bea3b28
Change make file to apply plugin support diff.
liuh-80 Sep 3, 2021
2a167f5
Fix whitespace issue.
liuh-80 Sep 3, 2021
6b57fe2
Improve build config
Sep 3, 2021
6dc2564
Improve build config
Sep 3, 2021
1904a40
Improve build config
Sep 3, 2021
f1b55e8
Improve PR code
liuh-80 Sep 6, 2021
de63753
Merge branch 'dev/liuh/bash_plugin_support' of https://github.com/liu…
liuh-80 Sep 6, 2021
da9d484
Add files.
liuh-80 Sep 6, 2021
c6cef30
Improve PR.
liuh-80 Sep 6, 2021
ff0af03
Install patched bash package.
liuh-80 Sep 6, 2021
1b46066
Use quilt to manage patches.
liuh-80 Sep 9, 2021
3cfd4ce
Fix PR comments
liuh-80 Sep 9, 2021
e85a16b
Integrate UT.
liuh-80 Sep 9, 2021
112a656
Fix UT build issue.
liuh-80 Sep 9, 2021
84e57cc
Fix build issue.
liuh-80 Sep 10, 2021
a0593bc
Merge branch 'dev/liuh/bash_plugin_support' of https://github.com/liu…
liuh-80 Sep 10, 2021
9fa560c
Improve code.
liuh-80 Sep 10, 2021
989c52c
Fix CUnit missing issue
Sep 14, 2021
614c2ce
Fix CUnit missing issue
Sep 14, 2021
317619d
Merge branch 'dev/liuh/bash_plugin_support' of https://github.com/liu…
liuh-80 Sep 14, 2021
c8a7734
Fix UT build issue.
liuh-80 Sep 14, 2021
d4d1846
Fix UT build break issue.
liuh-80 Sep 15, 2021
fa97701
Improve code by PR comments.
liuh-80 Sep 16, 2021
849a9a8
Merge branch 'dev/liuh/bash_plugin_support' of https://github.com/liu…
liuh-80 Sep 16, 2021
a1c51f9
Merge remote-tracking branch 'origin/master' into dev/liuh/bash_plugi…
liuh-80 Sep 17, 2021
ec852b4
Change to use 5.1-2 for debian-11 bullseye.
liuh-80 Oct 8, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions rules/bash.mk
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@
# completed.

# Bash major release-number corresponding to Debian-8 (Jessie)
liuh-80 marked this conversation as resolved.
Show resolved Hide resolved
liuh-80 marked this conversation as resolved.
Show resolved Hide resolved
BASH_VERSION_MAJOR = 4.3
BASH_VERSION_MAJOR = 5.0
Copy link
Collaborator

@qiluo-msft qiluo-msft Sep 18, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

5.0

Bullseye is using even newer version. It is not a good idea to build an old version for it. #Closed

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Bullseye using 5.1-2+b3 version: https://packages.debian.org/stable/shells/bash
will change to this version.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed.

# Bash complete release-number. This image contains all 4.3 fixes up to patch '42'.
BASH_VERSION_FULL = $(BASH_VERSION_MAJOR)-14
BASH_VERSION_FULL = $(BASH_VERSION_MAJOR)-4

export BASH_VERSION_MAJOR BASH_VERSION_FULL

Expand Down
3 changes: 2 additions & 1 deletion slave.mk
Original file line number Diff line number Diff line change
Expand Up @@ -910,7 +910,8 @@ $(addprefix $(TARGET_PATH)/, $(SONIC_INSTALLERS)) : $(TARGET_PATH)/% : \
$(PYTHON_SWSSCOMMON) \
$(PYTHON3_SWSSCOMMON) \
$(SONIC_UTILITIES_DATA) \
$(SONIC_HOST_SERVICES_DATA)) \
$(SONIC_HOST_SERVICES_DATA) \
$(BASH)) \
$$(addprefix $(TARGET_PATH)/,$$($$*_DOCKERS)) \
$$(addprefix $(TARGET_PATH)/,$$(SONIC_PACKAGES_LOCAL)) \
$$(addprefix $(FILES_PATH)/,$$($$*_FILES)) \
Expand Down
4 changes: 4 additions & 0 deletions sonic-slave-bullseye/Dockerfile.j2
Original file line number Diff line number Diff line change
Expand Up @@ -250,6 +250,10 @@ RUN apt-get update && apt-get install -y \
iproute2 \
# For bash
texi2html \
sharutils \
locales \
time \
man2html-base \
# For initramfs
shellcheck \
bash-completion \
Expand Down
4 changes: 4 additions & 0 deletions sonic-slave-buster/Dockerfile.j2
Original file line number Diff line number Diff line change
Expand Up @@ -258,6 +258,10 @@ RUN apt-get update && apt-get install -y \
iproute2 \
# For bash
texi2html \
sharutils \
locales \
time \
man2html-base \
# For initramfs
shellcheck \
bash-completion \
Expand Down
4 changes: 4 additions & 0 deletions sonic-slave-jessie/Dockerfile.j2
Original file line number Diff line number Diff line change
Expand Up @@ -231,6 +231,10 @@ RUN apt-get update && apt-get install -y \
texlive-latex-recommended \
# For bash
texi2html \
sharutils \
locales \
time \
man2html-base \
# For initramfs
bash-completion \
{% if CONFIGURED_ARCH == "amd64" -%}
Expand Down
4 changes: 4 additions & 0 deletions sonic-slave-stretch/Dockerfile.j2
Original file line number Diff line number Diff line change
Expand Up @@ -254,6 +254,10 @@ RUN apt-get update && apt-get install -y \
iproute2 \
# For bash
texi2html \
sharutils \
locales \
time \
man2html-base \
# For initramfs
bash-completion \
{%- if CONFIGURED_ARCH == "amd64" %}
Expand Down
4 changes: 4 additions & 0 deletions src/bash/.gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
*
!.gitignore
!Makefile
!*.patch
!*.c
!*.h
!unittest/
222 changes: 222 additions & 0 deletions src/bash/0001-Add-plugin-support-to-bash.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,222 @@
From b4962d09ab2d41a5e993bf3d8e4ebe32114999dc Mon Sep 17 00:00:00 2001
From: liuh-80 <[email protected]>
Date: Fri, 3 Sep 2021 14:05:36 +0800
Subject: [PATCH] Add plugin support to bash.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

bash

Please also submit a PR to upstream.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

After check with liuxin about the license issue, will submit PR to bash.


---
Makefile.in | 9 +++++----
config.h.in | 3 +++
configure | 9 +++++++++
configure.ac | 7 +++++++
execute_cmd.c | 8 ++++++++
shell.c | 12 ++++++++++++
6 files changed, 44 insertions(+), 4 deletions(-)

diff --git a/Makefile.in b/Makefile.in
index 5fcb44b..2a11f69 100644
--- a/Makefile.in
+++ b/Makefile.in
@@ -440,7 +440,7 @@ CSOURCES = shell.c eval.c parse.y general.c make_cmd.c print_cmd.c y.tab.c \
input.c bashhist.c array.c arrayfunc.c assoc.c sig.c pathexp.c \
unwind_prot.c siglist.c bashline.c bracecomp.c error.c \
list.c stringlib.c locale.c findcmd.c redir.c \
- pcomplete.c pcomplib.c syntax.c xmalloc.c
+ pcomplete.c pcomplib.c syntax.c xmalloc.c plugin.c

HSOURCES = shell.h flags.h trap.h hashcmd.h hashlib.h jobs.h builtins.h \
general.h variables.h config.h $(ALLOC_HEADERS) alias.h \
@@ -448,7 +448,7 @@ HSOURCES = shell.h flags.h trap.h hashcmd.h hashlib.h jobs.h builtins.h \
command.h input.h error.h bashansi.h dispose_cmd.h make_cmd.h \
subst.h externs.h siglist.h bashhist.h bashline.h bashtypes.h \
array.h arrayfunc.h sig.h mailcheck.h bashintl.h bashjmp.h \
- execute_cmd.h parser.h pathexp.h pathnames.h pcomplete.h assoc.h \
+ execute_cmd.h parser.h pathexp.h pathnames.h pcomplete.h assoc.h plugin.h \
$(BASHINCFILES)

SOURCES = $(CSOURCES) $(HSOURCES) $(BUILTIN_DEFS)
@@ -481,7 +481,7 @@ OBJECTS = shell.o eval.o y.tab.o general.o make_cmd.o print_cmd.o $(GLOBO) \
trap.o input.o unwind_prot.o pathexp.o sig.o test.o version.o \
alias.o array.o arrayfunc.o assoc.o braces.o bracecomp.o bashhist.o \
bashline.o $(SIGLIST_O) list.o stringlib.o locale.o findcmd.o redir.o \
- pcomplete.o pcomplib.o syntax.o xmalloc.o $(SIGNAMES_O)
+ pcomplete.o pcomplib.o syntax.o xmalloc.o plugin.o $(SIGNAMES_O)

# Where the source code of the shell builtins resides.
BUILTIN_SRCDIR=$(srcdir)/builtins
@@ -1015,7 +1015,7 @@ eval.o: quit.h ${BASHINCDIR}/maxpath.h unwind_prot.h dispose_cmd.h
eval.o: make_cmd.h subst.h sig.h pathnames.h externs.h parser.h
eval.o: input.h execute_cmd.h
execute_cmd.o: config.h bashtypes.h ${BASHINCDIR}/filecntl.h ${BASHINCDIR}/posixstat.h bashansi.h ${BASHINCDIR}/ansi_stdlib.h
-execute_cmd.o: shell.h syntax.h config.h bashjmp.h ${BASHINCDIR}/posixjmp.h command.h ${BASHINCDIR}/stdc.h error.h
+execute_cmd.o: shell.h syntax.h config.h bashjmp.h ${BASHINCDIR}/posixjmp.h command.h ${BASHINCDIR}/stdc.h error.h plugin.h
execute_cmd.o: general.h xmalloc.h bashtypes.h variables.h arrayfunc.h conftypes.h array.h hashlib.h
execute_cmd.o: quit.h ${BASHINCDIR}/maxpath.h unwind_prot.h dispose_cmd.h
execute_cmd.o: make_cmd.h subst.h sig.h pathnames.h externs.h parser.h
@@ -1024,6 +1024,7 @@ execute_cmd.o: execute_cmd.h findcmd.h redir.h trap.h test.h pathexp.h
execute_cmd.o: $(DEFSRC)/common.h ${DEFDIR}/builtext.h ${GLOB_LIBSRC}/strmatch.h
execute_cmd.o: ${BASHINCDIR}/posixtime.h ${BASHINCDIR}/chartypes.h
execute_cmd.o: $(DEFSRC)/getopt.h
+plugin.o: plugin.h
expr.o: config.h bashansi.h ${BASHINCDIR}/ansi_stdlib.h
expr.o: shell.h syntax.h config.h bashjmp.h ${BASHINCDIR}/posixjmp.h command.h ${BASHINCDIR}/stdc.h error.h
expr.o: general.h xmalloc.h bashtypes.h variables.h arrayfunc.h conftypes.h array.h hashlib.h
diff --git a/config.h.in b/config.h.in
index 8554aec..b2b57de 100644
--- a/config.h.in
+++ b/config.h.in
@@ -38,6 +38,9 @@
BSD-like job control. */
#undef JOB_CONTROL

+/* Define BASH_PLUGIN if need plugin support. */
+#undef BASH_PLUGIN
+
/* Define ALIAS if you want the alias features. */
#undef ALIAS

diff --git a/configure b/configure
index 2f62662..fb033d5 100644
--- a/configure
+++ b/configure
@@ -827,6 +827,7 @@ enable_single_help_strings
enable_strict_posix_default
enable_usg_echo_default
enable_xpg_echo_default
+enable_bash_plugin
enable_mem_scramble
enable_profiling
enable_static_link
@@ -1535,6 +1536,7 @@ Optional Features:
--enable-xpg-echo-default
make the echo builtin expand escape sequences by
default
+ --enable-bash-plugin enable bash plugin features
--enable-mem-scramble scramble memory on calls to malloc and free
--enable-profiling allow profiling with gprof
--enable-static-link link bash statically, for use as a root shell
@@ -2989,6 +2991,7 @@ opt_dircomplete_expand_default=no
opt_globascii_default=yes
opt_function_import=yes
opt_dev_fd_stat_broken=no
+opt_bash_plugin=yes

opt_static_link=no
opt_profiling=no
@@ -3010,6 +3013,7 @@ if test $opt_minimal_config = yes; then
opt_multibyte=yes opt_cond_regexp=no opt_coproc=no
opt_casemod_attrs=no opt_casemod_expansions=no opt_extglob_default=no
opt_globascii_default=yes
+ opt_bash_plugin=no
fi

# Check whether --enable-alias was given.
@@ -3197,6 +3201,11 @@ if test "${enable_xpg_echo_default+set}" = set; then :
enableval=$enable_xpg_echo_default; opt_xpg_echo=$enableval
fi

+# Check whether --enable-bash-plugin was given.
+if test "${enable_bash_plugin+set}" = set; then :
+ enableval=$enable_bash_plugin; opt_bash_plugin=$enableval
+fi
+

# Check whether --enable-mem-scramble was given.
if test "${enable_mem_scramble+set}" = set; then :
diff --git a/configure.ac b/configure.ac
index 52b4cdb..2d73d90 100644
--- a/configure.ac
+++ b/configure.ac
@@ -185,6 +185,7 @@ opt_dircomplete_expand_default=no
opt_globascii_default=yes
opt_function_import=yes
opt_dev_fd_stat_broken=no
+opt_bash_plugin=yes

dnl options that affect how bash is compiled and linked
opt_static_link=no
@@ -206,6 +207,7 @@ if test $opt_minimal_config = yes; then
opt_multibyte=yes opt_cond_regexp=no opt_coproc=no
opt_casemod_attrs=no opt_casemod_expansions=no opt_extglob_default=no
opt_globascii_default=yes
+ opt_bash_plugin=no
fi

AC_ARG_ENABLE(alias, AC_HELP_STRING([--enable-alias], [enable shell aliases]), opt_alias=$enableval)
@@ -245,6 +247,7 @@ AC_ARG_ENABLE(single-help-strings, AC_HELP_STRING([--enable-single-help-strings]
AC_ARG_ENABLE(strict-posix-default, AC_HELP_STRING([--enable-strict-posix-default], [configure bash to be posix-conformant by default]), opt_strict_posix=$enableval)
AC_ARG_ENABLE(usg-echo-default, AC_HELP_STRING([--enable-usg-echo-default], [a synonym for --enable-xpg-echo-default]), opt_xpg_echo=$enableval)
AC_ARG_ENABLE(xpg-echo-default, AC_HELP_STRING([--enable-xpg-echo-default], [make the echo builtin expand escape sequences by default]), opt_xpg_echo=$enableval)
+AC_ARG_ENABLE(bash-plugin, AC_HELP_STRING([--enable-bash-plugin], [enable bash plugin features]), opt_bash_plugin=$enableval)

dnl options that alter how bash is compiled and linked
AC_ARG_ENABLE(mem-scramble, AC_HELP_STRING([--enable-mem-scramble], [scramble memory on calls to malloc and free]), opt_memscramble=$enableval)
@@ -263,6 +266,10 @@ dnl opt_readline and opt_history are handled later, because AC_PROG_CC needs
dnl to be run before we can check the version of an already-installed readline
dnl library

+
+if test $opt_bash_plugin = yes; then
+AC_DEFINE(BASH_PLUGIN)
+fi
if test $opt_alias = yes; then
AC_DEFINE(ALIAS)
fi
diff --git a/execute_cmd.c b/execute_cmd.c
index 8b3c83a..c83efea 100644
--- a/execute_cmd.c
+++ b/execute_cmd.c
@@ -5458,6 +5458,14 @@ execute_disk_command (words, redirects, command_line, pipe_in, pipe_out,
leave it there, in the same format that the user used to
type it in. */
args = strvec_from_word_list (words, 0, 0, (int *)NULL);
+
+#if defined (BASH_PLUGIN)
liuh-80 marked this conversation as resolved.
Show resolved Hide resolved
+ result = invoke_plugin_on_shell_execve (current_user.user_name, command, args);
+ if (result) {
+ exit (EXECUTION_FAILURE);
liuh-80 marked this conversation as resolved.
Show resolved Hide resolved
+ }
+#endif /* BASH_PLUGIN */
+
exit (shell_execve (command, args, export_env));
}
else
diff --git a/shell.c b/shell.c
index a2b2a55..fb94b22 100644
--- a/shell.c
+++ b/shell.c
@@ -46,6 +46,10 @@
# include <unistd.h>
#endif

+#if defined (BASH_PLUGIN)
+#include "plugin.h"
+#endif /* BASH_PLUGIN */
+
#include "bashintl.h"

#define NEED_SH_SETLINEBUF_DECL /* used in externs.h */
@@ -561,6 +565,10 @@ main (argc, argv, env)
if (shopt_alist)
run_shopt_alist ();

+#if defined (BASH_PLUGIN)
+ load_plugins ();
+#endif /* BASH_PLUGIN */
+
/* From here on in, the shell must be a normal functioning shell.
Variables from the environment are expected to be set, etc. */
shell_initialize ();
@@ -804,6 +812,10 @@ main (argc, argv, env)
/* Read commands until exit condition. */
reader_loop ();
exit_shell (last_command_exit_value);
+
+#if defined (BASH_PLUGIN)
+ free_plugins ();
+#endif /* BASH_PLUGIN */
}

static int
--
2.17.1.windows.2

9 changes: 9 additions & 0 deletions src/bash/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,17 @@ $(addprefix $(DEST)/, $(MAIN_TARGET)): $(DEST)/% :

dget -u https://launchpad.net/debian/+archive/primary/+sourcefiles/bash/$(BASH_VERSION_FULL)/bash_$(BASH_VERSION_FULL).dsc


pushd bash-$(BASH_VERSION_MAJOR)

# Apply plugin suport patch
patch -p1 < ../0001-Add-plugin-support-to-bash.patch
liuh-80 marked this conversation as resolved.
Show resolved Hide resolved
cp ../plugin.h ./plugin.h
liuh-80 marked this conversation as resolved.
Show resolved Hide resolved
cp ../plugin.c ./plugin.c
cp ../unittest ./unittest
DEB_BUILD_OPTIONS=nocheck dpkg-buildpackage -us -uc -b -j$(SONIC_CONFIG_MAKE_JOBS) --admindir $(SONIC_DPKG_ADMINDIR)


popd

mv $* $(DEST)/
Loading