Skip to content

Commit a0929b3

Browse files
Merge remote-tracking branch 'origin/master' into modular-chassis
2 parents 1a46b20 + ce7abad commit a0929b3

File tree

19 files changed

+1391
-12
lines changed

19 files changed

+1391
-12
lines changed

files/build_templates/sonic_debian_extension.j2

+4
Original file line numberDiff line numberDiff line change
@@ -265,6 +265,10 @@ sudo rm -rf $FILESYSTEM_ROOT/$SONIC_UTILITIES_PY3_WHEEL_NAME
265265
sudo dpkg --root=$FILESYSTEM_ROOT -i $debs_path/sonic-utilities-data_*.deb || \
266266
sudo LANG=C DEBIAN_FRONTEND=noninteractive chroot $FILESYSTEM_ROOT apt-get -y install -f
267267

268+
# Install customized bash version to patch bash plugin support.
269+
sudo dpkg --root=$FILESYSTEM_ROOT -i target/debs/bash_*.deb || \
270+
sudo LANG=C DEBIAN_FRONTEND=noninteractive chroot $FILESYSTEM_ROOT apt-get -y install -f
271+
268272
# sonic-utilities-data installs bash-completion as a dependency. However, it is disabled by default
269273
# in bash.bashrc, so we copy a version of the file with it enabled here.
270274
sudo cp -f $IMAGE_CONFIGS/bash/bash.bashrc $FILESYSTEM_ROOT/etc/

platform/mellanox/mlnx-sai.mk

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# Mellanox SAI
22

3-
MLNX_SAI_VERSION = SAIRel1.19.2
3+
MLNX_SAI_VERSION = SAIRel1.19.4
44

55
export MLNX_SAI_VERSION
66

rules/bash.mk

+6-8
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,12 @@
11
# bash package
22
#
3-
# Created to patch memory-leak issue in the bash-package included in Debian-8 (Jessie)
4-
# release. This rule file, and the associated building-infra created to solve this
5-
# bug (src/bash/), should be eliminated once the migration to Debian-9 (Stretch) is
6-
# completed.
3+
# Created to patch plugin support in the bash-package included in Debian-11 (Bullseye)
4+
# release.
75

8-
# Bash major release-number corresponding to Debian-8 (Jessie)
9-
BASH_VERSION_MAJOR = 4.3
10-
# Bash complete release-number. This image contains all 4.3 fixes up to patch '42'.
11-
BASH_VERSION_FULL = $(BASH_VERSION_MAJOR)-14
6+
# Bash major release-number corresponding to Debian-11 (Bullseye)
7+
BASH_VERSION_MAJOR = 5.1
8+
# Bash complete release-number. This image contains all 5.1 fixes up to patch '2'.
9+
BASH_VERSION_FULL = $(BASH_VERSION_MAJOR)-2
1210

1311
export BASH_VERSION_MAJOR BASH_VERSION_FULL
1412

slave.mk

+2-1
Original file line numberDiff line numberDiff line change
@@ -910,7 +910,8 @@ $(addprefix $(TARGET_PATH)/, $(SONIC_INSTALLERS)) : $(TARGET_PATH)/% : \
910910
$(PYTHON_SWSSCOMMON) \
911911
$(PYTHON3_SWSSCOMMON) \
912912
$(SONIC_UTILITIES_DATA) \
913-
$(SONIC_HOST_SERVICES_DATA)) \
913+
$(SONIC_HOST_SERVICES_DATA) \
914+
$(BASH)) \
914915
$$(addprefix $(TARGET_PATH)/,$$($$*_DOCKERS)) \
915916
$$(addprefix $(TARGET_PATH)/,$$(SONIC_PACKAGES_LOCAL)) \
916917
$$(addprefix $(FILES_PATH)/,$$($$*_FILES)) \

sonic-slave-bullseye/Dockerfile.j2

+6
Original file line numberDiff line numberDiff line change
@@ -250,6 +250,12 @@ RUN apt-get update && apt-get install -y \
250250
iproute2 \
251251
# For bash
252252
texi2html \
253+
sharutils \
254+
locales \
255+
time \
256+
man2html-base \
257+
libcunit1 \
258+
libcunit1-dev \
253259
# For initramfs
254260
shellcheck \
255261
bash-completion \

sonic-slave-buster/Dockerfile.j2

+6
Original file line numberDiff line numberDiff line change
@@ -258,6 +258,12 @@ RUN apt-get update && apt-get install -y \
258258
iproute2 \
259259
# For bash
260260
texi2html \
261+
sharutils \
262+
locales \
263+
time \
264+
man2html-base \
265+
libcunit1 \
266+
libcunit1-dev \
261267
# For initramfs
262268
shellcheck \
263269
bash-completion \

sonic-slave-jessie/Dockerfile.j2

+6
Original file line numberDiff line numberDiff line change
@@ -231,6 +231,12 @@ RUN apt-get update && apt-get install -y \
231231
texlive-latex-recommended \
232232
# For bash
233233
texi2html \
234+
sharutils \
235+
locales \
236+
time \
237+
man2html-base \
238+
libcunit1 \
239+
libcunit1-dev \
234240
# For initramfs
235241
bash-completion \
236242
{% if CONFIGURED_ARCH == "amd64" -%}

sonic-slave-stretch/Dockerfile.j2

+6
Original file line numberDiff line numberDiff line change
@@ -254,6 +254,12 @@ RUN apt-get update && apt-get install -y \
254254
iproute2 \
255255
# For bash
256256
texi2html \
257+
sharutils \
258+
locales \
259+
time \
260+
man2html-base \
261+
libcunit1 \
262+
libcunit1-dev \
257263
# For initramfs
258264
bash-completion \
259265
{%- if CONFIGURED_ARCH == "amd64" %}

src/bash/.gitignore

+4
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
11
*
22
!.gitignore
33
!Makefile
4+
!Files/
5+
!Files/*
6+
!patches/
7+
!patches/*

src/bash/Files/unittest/Makefile

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
#disable some warning because UT need test functions not in header file.
2+
CFLAGS = -Wno-parentheses -Wno-format-security -Wno-implicit-function-declaration -c
3+
IFLAGS = -I.. -I../include -I../lib
4+
MFLAG = -DDEBUG -DBASH_PLUGIN_UT
5+
6+
all:
7+
gcc plugin_test.c $(IFLAGS) $(CFLAGS) -o plugin_test.o
8+
gcc mock_helper.c $(IFLAGS) $(CFLAGS) -o mock_helper.o
9+
gcc ../plugin.c $(IFLAGS) $(CFLAGS) $(MFLAG) -o plugin.o
10+
gcc plugin_test.o mock_helper.o plugin.o -o plugin_test -lc -lcunit
11+
12+
test:
13+
# run unit test, if UT failed, build will break
14+
./plugin_test
15+
16+
clean:
17+
rm *.o
18+
rm plugin_test
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
# tacacs authorization plugin
2+
plugin=/home/liuh/tacacs-bash-plugin/tacacs-authorization.so
3+
plugin=/usr/lib/bash-plugins/another_test_plugin.so # test comments
4+
5+
6+
# test line

src/bash/Files/unittest/mock_helper.c

+218
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,218 @@
1+
/* mock_helper.c -- mock helper for bash plugin UT. */
2+
#include <stdarg.h>
3+
#include <stdio.h>
4+
#include <stdlib.h>
5+
#include <string.h>
6+
#include <CUnit/CUnit.h>
7+
#include <CUnit/Basic.h>
8+
#include "mock_helper.h"
9+
10+
// define BASH_PLUGIN_UT_DEBUG to output UT debug message.
11+
//#define BASH_PLUGIN_UT_DEBUG
12+
#if defined (BASH_PLUGIN_UT_DEBUG)
13+
# define debug_printf printf
14+
#else
15+
# define debug_printf
16+
#endif
17+
18+
/* itrace buffer */
19+
char mock_itrace_message_buffer[1024];
20+
21+
/* bash run command buffer */
22+
char mock_onshell_execve_command_buffer[1024];
23+
24+
/* plugin handles. */
25+
void* mock_plugin_handle = (void*)TEST_MOCK_PLUGIN_HANDLE;
26+
void* mock_plugin_default_function_handle = (void*)0x2234;
27+
void* mock_plugin_on_shell_execve_handle = (void*)0x3234;
28+
char* mock_dlerror_failed = "MOCK error";
29+
char* mock_dlerror = NULL;
30+
31+
/* define test scenarios for mock functions return different value by scenario. */
32+
int test_scenario;
33+
34+
/* define test scenarios for different return value. */
35+
int plugin_init_status;
36+
37+
/* define memory allocate counter. */
38+
int memory_allocate_count;
39+
40+
/* Set test scenario for test*/
41+
void set_test_scenario(int scenario)
42+
{
43+
test_scenario = scenario;
44+
}
45+
46+
/* Get test scenario for test*/
47+
int get_test_scenario()
48+
{
49+
return test_scenario;
50+
}
51+
52+
/* Set plugin init status for test*/
53+
void set_plugin_init_status(int status)
54+
{
55+
plugin_init_status = status;
56+
}
57+
58+
/* Get plugin init status for test*/
59+
int get_plugin_init_status()
60+
{
61+
return plugin_init_status;
62+
}
63+
64+
/* Set memory allocate count for test*/
65+
void set_memory_allocate_count(int count)
66+
{
67+
memory_allocate_count = count;
68+
}
69+
70+
/* Get memory allocate count for test*/
71+
int get_memory_allocate_count()
72+
{
73+
return memory_allocate_count;
74+
}
75+
76+
/* MOCK plugin_init method*/
77+
int mock_plugin_init()
78+
{
79+
set_plugin_init_status(PLUGIN_INITIALIZED);
80+
}
81+
82+
/* MOCK plugin_init method*/
83+
int mock_plugin_uninit()
84+
{
85+
set_plugin_init_status(PLUGIN_NOT_INITIALIZE);
86+
}
87+
88+
/* MOCK on_shell_execve method*/
89+
int mock_on_shell_execve (char *user, int shell_level, char *cmd, char **argv)
90+
{
91+
// set mock command data to buffer for UT.
92+
memset(mock_onshell_execve_command_buffer, 0, sizeof(mock_onshell_execve_command_buffer));
93+
94+
snprintf(mock_onshell_execve_command_buffer, sizeof(mock_onshell_execve_command_buffer), "on_shell_execve: user: %s, level: %d, command: %s, argv: %p\n", user, shell_level, cmd, argv);
95+
96+
debug_printf("MOCK: mock_on_shell_execve: %s\n", mock_onshell_execve_command_buffer);
97+
}
98+
99+
/* MOCK dlopen*/
100+
void *dlopen(const char *filename, int flags)
101+
{
102+
debug_printf("MOCK: dlopen: %s\n", filename);
103+
if (TEST_SCEANRIO_PLUGIN_NOT_EXIT == test_scenario)
104+
{
105+
// return null when plugin not exist
106+
mock_dlerror = mock_dlerror_failed;
107+
return NULL;
108+
}
109+
110+
// all other case return mock handle
111+
mock_dlerror = NULL;
112+
return mock_plugin_handle;
113+
}
114+
115+
/* MOCK dlclose*/
116+
int dlclose(void *handle)
117+
{
118+
debug_printf("MOCK: dlclose: %p\n", handle);
119+
// check if the close handle match the opened handle
120+
CU_ASSERT_EQUAL(handle, mock_plugin_handle);
121+
}
122+
123+
/* MOCK dlsym*/
124+
void *dlsym(void *restrict handle, const char *restrict symbol)
125+
{
126+
debug_printf("MOCK: dlsym: %p, %s\n", handle, symbol);
127+
mock_dlerror = NULL;
128+
switch (test_scenario)
129+
{
130+
case TEST_SCEANRIO_PLUGIN_EXECVE_NOT_EXIT:
131+
if (strcmp(symbol, "on_shell_execve") == 0)
132+
{
133+
mock_dlerror = mock_dlerror_failed;
134+
return NULL;
135+
}
136+
137+
case TEST_SCEANRIO_PLUGIN_UNINIT_NOT_EXIT:
138+
if (strcmp(symbol, "plugin_uninit") == 0)
139+
{
140+
mock_dlerror = mock_dlerror_failed;
141+
return NULL;
142+
}
143+
144+
case TEST_SCEANRIO_PLUGIN_INIT_NOT_EXIT:
145+
if (strcmp(symbol, "plugin_init") == 0)
146+
{
147+
mock_dlerror = mock_dlerror_failed;
148+
return NULL;
149+
}
150+
151+
case TEST_SCEANRIO_PLUGIN_INIT_SUCCESS:
152+
if (strcmp(symbol, "plugin_init") == 0)
153+
{
154+
// return mock method handle so plugin framework will call it to initialize
155+
return mock_plugin_init;
156+
}
157+
else if (strcmp(symbol, "plugin_uninit") == 0)
158+
{
159+
// return mock method handle so plugin framework will call it to initialize
160+
return mock_plugin_uninit;
161+
}
162+
else if (strcmp(symbol, "on_shell_execve") == 0)
163+
{
164+
// return mock method handle so plugin framework will call it to initialize
165+
return mock_on_shell_execve;
166+
}
167+
}
168+
169+
return mock_plugin_default_function_handle;
170+
}
171+
172+
/* MOCK dlerror*/
173+
char *dlerror(void)
174+
{
175+
return mock_dlerror;
176+
}
177+
178+
/* MOCK get_string_value*/
179+
char *get_string_value(const char * str)
180+
{
181+
return "1";
182+
}
183+
184+
/* MOCK absolute_program*/
185+
int absolute_program (const char * str)
186+
{
187+
return 0;
188+
}
189+
190+
/* MOCK itrace*/
191+
void itrace (const char * format, ...)
192+
{
193+
// set mock message data to buffer for UT.
194+
memset(mock_itrace_message_buffer, 0, sizeof(mock_itrace_message_buffer));
195+
196+
va_list args;
197+
va_start(args, format);
198+
// save message to buffer to UT check later
199+
vsnprintf(mock_itrace_message_buffer, sizeof(mock_itrace_message_buffer), format, args);
200+
va_end(args);
201+
debug_printf("MOCK: itrace: %s\n", mock_itrace_message_buffer);
202+
}
203+
204+
/* MOCK malloc method*/
205+
void* mock_malloc (size_t size)
206+
{
207+
memory_allocate_count++;
208+
debug_printf("MOCK: malloc memory count: %d\n", memory_allocate_count);
209+
return malloc(size);
210+
}
211+
212+
/* MOCK free method*/
213+
void mock_free (void* ptr)
214+
{
215+
memory_allocate_count--;
216+
debug_printf("MOCK: free memory count: %d\n", memory_allocate_count);
217+
free(ptr);
218+
}

0 commit comments

Comments
 (0)