diff --git a/gcc_secure.spec b/gcc_secure.spec index cb6edd96a899c9311d9220a83fba853dc23203fb..04485ff883620293b28cfdde4cd0ea0d291252d1 100644 --- a/gcc_secure.spec +++ b/gcc_secure.spec @@ -3,7 +3,7 @@ Summary: Enforcing secure compile options for abuild License: GPL-2.0-only Group: System/Management Version: 1.0 -Release: 0.12 +Release: 0.13 BuildRoot: %{_tmppath}/%{name}-%{version} BuildRequires: util-linux coreutils @@ -26,8 +26,19 @@ echo -e '*cc1_options:\n+ %{!r:%{!D__KERNEL__:%{!pie:%{!fpic:%{!fPIC:%{!fpie:%{! echo -e '*self_spec:\n+ %{!D__KERNEL__:%{!pie:%{!A:%{!fno-pie:%{!fno-PIE:%{!fno-pic:%{!fno-PIC:%{!shared:%{!static:%{!r:%{!nostdlib:%{!nostartfiles:-pie}}}}}}}}}}}}' >/opt/gcc-specs-pie-ld +#only if src is LSB executable +function replace() { + if ! [ -e $1"_old" ] ; then + mv $1 $1"_old" + else + if file $1 | grep LSB > /dev/zero ; then + mv $1 $1"_old" + fi + fi +} + old_gcc=/usr/bin/gcc -mv $old_gcc $old_gcc"_old" +replace $old_gcc cat < $old_gcc #!/bin/sh gcc_secure_exclude=\`rpm --eval %{gcc_secure_exclude}\` @@ -71,8 +82,7 @@ END1 chmod 755 $old_gcc $old_gcc"_old" old_gplus=/usr/bin/g++ -if [ -f $old_gplus ]; then -mv $old_gplus $old_gplus"_old" +replace $old_gplus cat < $old_gplus #!/bin/sh gcc_secure_exclude=\`rpm --eval %{gcc_secure_exclude}\` @@ -108,11 +118,9 @@ else fi END1 chmod 755 $old_gplus $old_gplus"_old" -fi old_cpp=/usr/bin/c++ -if [ -f $old_cpp ]; then -mv $old_cpp $old_cpp"_old" +replace $old_cpp cat < $old_cpp #!/bin/sh gcc_secure_exclude=\`rpm --eval %{gcc_secure_exclude}\` @@ -144,12 +152,28 @@ else fi END1 chmod 755 $old_cpp $old_cpp"_old" -fi %preun %postun - +function restore() { + if [ -e $1"_old" ] ; then + if file $1"_old" | grep LSB > /dev/zero ; then + rm -f $1 + mv $1"_old" $1 + else + echo "Please reinstall $1" + fi + else + echo "Please reinstall $1" + fi +} +old_gcc=/usr/bin/gcc +old_gplus=/usr/bin/g++ +old_cpp=/usr/bin/c++ +restore $old_gcc +restore $old_gplus +restore $old_cpp %files %defattr(-,root,root) @@ -160,6 +184,10 @@ rm -rf %{_tmppath}/%{name}-%{version} rm -rf $RPM_BUILD_DIR/%{name}-%{version} %changelog +* Tue Nov 15 2022 yuelg - 1.0-0.13 +- Avoid replacing original binary recursively +- Restore original binary when uninstall + * Thu Jul 28 2022 Chenyx - 1.0-0.12 - License compliance rectification