|
Harald Hoyer |
401ad9 |
From 4637c5c24252d636fc57af1a9aaaf629140a77c7 Mon Sep 17 00:00:00 2001
|
|
Harald Hoyer |
401ad9 |
From: Harald Hoyer <harald@redhat.com>
|
|
Harald Hoyer |
401ad9 |
Date: Fri, 21 Oct 2011 10:09:55 +0200
|
|
Harald Hoyer |
401ad9 |
Subject: [PATCH] dracut-functions: do not install files from current
|
|
Harald Hoyer |
401ad9 |
directory
|
|
Harald Hoyer |
401ad9 |
|
|
Harald Hoyer |
401ad9 |
Protect against relative pathnames without a slash for all inst_*()
|
|
Harald Hoyer |
401ad9 |
functions.
|
|
Harald Hoyer |
401ad9 |
---
|
|
Harald Hoyer |
401ad9 |
dracut-functions | 38 +++++++++++++++++++++-----------------
|
|
Harald Hoyer |
401ad9 |
1 files changed, 21 insertions(+), 17 deletions(-)
|
|
Harald Hoyer |
401ad9 |
|
|
Harald Hoyer |
401ad9 |
diff --git a/dracut-functions b/dracut-functions
|
|
Harald Hoyer |
401ad9 |
index 70a467b..a56e460 100755
|
|
Harald Hoyer |
401ad9 |
--- a/dracut-functions
|
|
Harald Hoyer |
401ad9 |
+++ b/dracut-functions
|
|
Harald Hoyer |
401ad9 |
@@ -272,10 +272,10 @@ check_vol_slaves() {
|
|
Harald Hoyer |
401ad9 |
# will create ${initdir}/lib64, ${initdir}/lib64/file,
|
|
Harald Hoyer |
401ad9 |
# and a symlink ${initdir}/lib -> lib64.
|
|
Harald Hoyer |
401ad9 |
inst_dir() {
|
|
Harald Hoyer |
401ad9 |
- [[ -e ${initdir}"$1" ]] && return 0 # already there
|
|
Harald Hoyer |
401ad9 |
+ [[ -e ${initdir}/"$1" ]] && return 0 # already there
|
|
Harald Hoyer |
401ad9 |
|
|
Harald Hoyer |
401ad9 |
local _dir="$1" _part="${1%/*}" _file
|
|
Harald Hoyer |
401ad9 |
- while [[ "$_part" != "${_part%/*}" ]] && ! [[ -e "${initdir}${_part}" ]]; do
|
|
Harald Hoyer |
401ad9 |
+ while [[ "$_part" != "${_part%/*}" ]] && ! [[ -e "${initdir}/${_part}" ]]; do
|
|
Harald Hoyer |
401ad9 |
_dir="$_part $_dir"
|
|
Harald Hoyer |
401ad9 |
_part=${_part%/*}
|
|
Harald Hoyer |
401ad9 |
done
|
|
Harald Hoyer |
401ad9 |
@@ -306,12 +306,13 @@ inst_dir() {
|
|
Harald Hoyer |
401ad9 |
# Location of the image dir is assumed to be $initdir
|
|
Harald Hoyer |
401ad9 |
# We never overwrite the target if it exists.
|
|
Harald Hoyer |
401ad9 |
inst_simple() {
|
|
Harald Hoyer |
401ad9 |
- [[ -f $1 ]] || return 1
|
|
Harald Hoyer |
401ad9 |
+ [[ -f "$1" ]] || return 1
|
|
Harald Hoyer |
401ad9 |
+ strstr "$1" "/" || return 1
|
|
Harald Hoyer |
401ad9 |
|
|
Harald Hoyer |
401ad9 |
local _src=$1 target="${2:-$1}"
|
|
Harald Hoyer |
401ad9 |
- if ! [[ -d ${initdir}$target ]]; then
|
|
Harald Hoyer |
401ad9 |
- [[ -e ${initdir}$target ]] && return 0
|
|
Harald Hoyer |
401ad9 |
- [[ -h ${initdir}$target ]] && return 0
|
|
Harald Hoyer |
401ad9 |
+ if ! [[ -d ${initdir}/$target ]]; then
|
|
Harald Hoyer |
401ad9 |
+ [[ -e ${initdir}/$target ]] && return 0
|
|
Harald Hoyer |
401ad9 |
+ [[ -h ${initdir}/$target ]] && return 0
|
|
Harald Hoyer |
401ad9 |
inst_dir "${target%/*}"
|
|
Harald Hoyer |
401ad9 |
fi
|
|
Harald Hoyer |
401ad9 |
# install checksum files also
|
|
Harald Hoyer |
401ad9 |
@@ -319,7 +320,7 @@ inst_simple() {
|
|
Harald Hoyer |
401ad9 |
inst "${_src%/*}/.${_src##*/}.hmac" "${target%/*}/.${target##*/}.hmac"
|
|
Harald Hoyer |
401ad9 |
fi
|
|
Harald Hoyer |
401ad9 |
ddebug "Installing $_src"
|
|
Harald Hoyer |
401ad9 |
- cp --sparse=always -pfL "$_src" "${initdir}$target"
|
|
Harald Hoyer |
401ad9 |
+ cp --sparse=always -pfL "$_src" "${initdir}/$target"
|
|
Harald Hoyer |
401ad9 |
}
|
|
Harald Hoyer |
401ad9 |
|
|
Harald Hoyer |
401ad9 |
# find symlinks linked to given library file
|
|
Harald Hoyer |
401ad9 |
@@ -351,8 +352,9 @@ rev_lib_symlinks() {
|
|
Harald Hoyer |
401ad9 |
# It handles making symlinks according to how the original library
|
|
Harald Hoyer |
401ad9 |
# is referenced.
|
|
Harald Hoyer |
401ad9 |
inst_library() {
|
|
Harald Hoyer |
401ad9 |
- local _src=$1 _dest=${2:-$1} _lib _reallib _symlink
|
|
Harald Hoyer |
401ad9 |
- [[ -e $initdir$_dest ]] && return 0
|
|
Harald Hoyer |
401ad9 |
+ local _src="$1" _dest=${2:-$1} _lib _reallib _symlink
|
|
Harald Hoyer |
401ad9 |
+ strstr "$1" "/" || return 1
|
|
Harald Hoyer |
401ad9 |
+ [[ -e $initdir/$_dest ]] && return 0
|
|
Harald Hoyer |
401ad9 |
if [[ -L $_src ]]; then
|
|
Harald Hoyer |
401ad9 |
# install checksum files also
|
|
Harald Hoyer |
401ad9 |
if [[ -e "${_src%/*}/.${_src##*/}.hmac" ]]; then
|
|
Harald Hoyer |
401ad9 |
@@ -361,14 +363,14 @@ inst_library() {
|
|
Harald Hoyer |
401ad9 |
_reallib=$(readlink -f "$_src")
|
|
Harald Hoyer |
401ad9 |
inst_simple "$_reallib" "$_reallib"
|
|
Harald Hoyer |
401ad9 |
inst_dir "${_dest%/*}"
|
|
Harald Hoyer |
401ad9 |
- ln -sfn $(convert_abs_rel "${_dest}" "${_reallib}") "${initdir}${_dest}"
|
|
Harald Hoyer |
401ad9 |
+ ln -sfn $(convert_abs_rel "${_dest}" "${_reallib}") "${initdir}/${_dest}"
|
|
Harald Hoyer |
401ad9 |
else
|
|
Harald Hoyer |
401ad9 |
inst_simple "$_src" "$_dest"
|
|
Harald Hoyer |
401ad9 |
fi
|
|
Harald Hoyer |
401ad9 |
|
|
Harald Hoyer |
401ad9 |
# Create additional symlinks. See rev_symlinks description.
|
|
Harald Hoyer |
401ad9 |
for _symlink in $(rev_lib_symlinks $_src) $(rev_lib_symlinks $_reallib); do
|
|
Harald Hoyer |
401ad9 |
- [[ ! -e $initdir$_symlink ]] && {
|
|
Harald Hoyer |
401ad9 |
+ [[ ! -e $initdir/$_symlink ]] && {
|
|
Harald Hoyer |
401ad9 |
ddebug "Creating extra symlink: $_symlink"
|
|
Harald Hoyer |
401ad9 |
inst_symlink $_symlink
|
|
Harald Hoyer |
401ad9 |
}
|
|
Harald Hoyer |
401ad9 |
@@ -396,7 +398,7 @@ inst_binary() {
|
|
Harald Hoyer |
401ad9 |
_bin=$(find_binary "$1") || return 1
|
|
Harald Hoyer |
401ad9 |
_target=${2:-$_bin}
|
|
Harald Hoyer |
401ad9 |
inst_symlink $_bin $_target && return 0
|
|
Harald Hoyer |
401ad9 |
- [[ -e $initdir$_target ]] && return 0
|
|
Harald Hoyer |
401ad9 |
+ [[ -e $initdir/$_target ]] && return 0
|
|
Harald Hoyer |
401ad9 |
|
|
Harald Hoyer |
401ad9 |
# If the binary being installed is also a library, add it to the loop.
|
|
Harald Hoyer |
401ad9 |
_so_regex='([^ ]*/lib[^/]*/[^ ]*\.so[^ ]*)'
|
|
Harald Hoyer |
401ad9 |
@@ -414,7 +416,7 @@ inst_binary() {
|
|
Harald Hoyer |
401ad9 |
fi
|
|
Harald Hoyer |
401ad9 |
[[ $_line =~ $_so_regex ]] || continue
|
|
Harald Hoyer |
401ad9 |
_file=${BASH_REMATCH[1]}
|
|
Harald Hoyer |
401ad9 |
- [[ -e ${initdir}$_file ]] && continue
|
|
Harald Hoyer |
401ad9 |
+ [[ -e ${initdir}/$_file ]] && continue
|
|
Harald Hoyer |
401ad9 |
|
|
Harald Hoyer |
401ad9 |
# See if we are loading an optimized version of a shared lib.
|
|
Harald Hoyer |
401ad9 |
if [[ $_file =~ $_lib_regex ]]; then
|
|
Harald Hoyer |
401ad9 |
@@ -439,19 +441,21 @@ inst_binary() {
|
|
Harald Hoyer |
401ad9 |
# same as above, except for shell scripts.
|
|
Harald Hoyer |
401ad9 |
# If your shell script does not start with shebang, it is not a shell script.
|
|
Harald Hoyer |
401ad9 |
inst_script() {
|
|
Harald Hoyer |
401ad9 |
- [[ -f $1 ]] || return 1
|
|
Harald Hoyer |
401ad9 |
+ local _bin
|
|
Harald Hoyer |
401ad9 |
+ _bin=$(find_binary "$1") || return 1
|
|
Harald Hoyer |
401ad9 |
local _line _shebang_regex
|
|
Harald Hoyer |
401ad9 |
- read -r -n 80 _line <"$1"
|
|
Harald Hoyer |
401ad9 |
+ read -r -n 80 _line <"$_bin"
|
|
Harald Hoyer |
401ad9 |
# If debug is set, clean unprintable chars to prevent messing up the term
|
|
Harald Hoyer |
401ad9 |
[[ $debug ]] && _line=$(echo -n "$_line" | tr -c -d '[:print:][:space:]')
|
|
Harald Hoyer |
401ad9 |
_shebang_regex='(#! *)(/[^ ]+).*'
|
|
Harald Hoyer |
401ad9 |
[[ $_line =~ $_shebang_regex ]] || return 1
|
|
Harald Hoyer |
401ad9 |
- inst "${BASH_REMATCH[2]}" && inst_simple "$@"
|
|
Harald Hoyer |
401ad9 |
+ inst "${BASH_REMATCH[2]}" && inst_binary "$@"
|
|
Harald Hoyer |
401ad9 |
}
|
|
Harald Hoyer |
401ad9 |
|
|
Harald Hoyer |
401ad9 |
# same as above, but specialized for symlinks
|
|
Harald Hoyer |
401ad9 |
inst_symlink() {
|
|
Harald Hoyer |
401ad9 |
- local _src=$1 _target=$initdir${2:-$1} _realsrc
|
|
Harald Hoyer |
401ad9 |
+ local _src=$1 _target=$initdir/${2:-$1} _realsrc
|
|
Harald Hoyer |
401ad9 |
+ strstr "$1" "/" || return 1
|
|
Harald Hoyer |
401ad9 |
[[ -L $1 ]] || return 1
|
|
Harald Hoyer |
401ad9 |
[[ -L $_target ]] && return 0
|
|
Harald Hoyer |
401ad9 |
_realsrc=$(readlink -f "$_src")
|