public inbox for gentoo-commits@lists.gentoo.org
 help / color / mirror / Atom feed
From: "Anthony G. Basile" <blueness@gentoo.org>
To: gentoo-commits@lists.gentoo.org
Subject: [gentoo-commits] proj/elfix:master commit in: scripts/
Date: Mon, 20 May 2013 19:47:15 +0000 (UTC)	[thread overview]
Message-ID: <1369079198.55af0a5a4b0319b75cab06b78b8fc62d135cd0d4.blueness@gentoo> (raw)

commit:     55af0a5a4b0319b75cab06b78b8fc62d135cd0d4
Author:     Anthony G. Basile <blueness <AT> gentoo <DOT> org>
AuthorDate: Mon May 20 19:46:38 2013 +0000
Commit:     Anthony G. Basile <blueness <AT> gentoo <DOT> org>
CommitDate: Mon May 20 19:46:38 2013 +0000
URL:        http://git.overlays.gentoo.org/gitweb/?p=proj/elfix.git;a=commit;h=55af0a5a

scripts/pax-mark: bash utility to do what the eclass does

---
 scripts/Makefile.am |    2 +-
 scripts/pax-mark    |  111 +++++++++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 112 insertions(+), 1 deletions(-)

diff --git a/scripts/Makefile.am b/scripts/Makefile.am
index 6728a83..5cef3e1 100644
--- a/scripts/Makefile.am
+++ b/scripts/Makefile.am
@@ -1,4 +1,4 @@
 ACLOCAL_AMFLAGS = -I m4
 
-dist_sbin_SCRIPTS = pypaxctl migrate-pax revdep-pax
+dist_sbin_SCRIPTS = migrate-pax pax-mark pypaxctl revdep-pax
 EXTRA_DIST = paxmodule.c setup.py

diff --git a/scripts/pax-mark b/scripts/pax-mark
new file mode 100755
index 0000000..c8fc7ed
--- /dev/null
+++ b/scripts/pax-mark
@@ -0,0 +1,111 @@
+#!/bin/bash -l
+
+has() {
+	[[ "${2/$1/}" != "$2" ]] && return 0
+	return 1
+}
+
+pax-mark() {
+
+	local f					# loop over paxables
+	local flags				# pax flags
+	local pt_fail=0 pt_failures=""		# record PT_PAX failures
+	local xt_fail=0 xt_failures=""		# record xattr PAX marking failures
+	local ret=0				# overal return code of this function
+
+	# Only the actual PaX flags and z are accepted
+	# 1. The leading '-' is optional
+	# 2. -C -c only make sense for paxctl, but are unnecessary
+	#    because we progressively do -q -qc -qC
+	# 3. z is allowed for the default
+
+	flags="${1//[!zPpEeMmRrSs]}"
+	[[ "${flags}" ]] || return 0
+	shift
+
+	# z = default. For XATTR_PAX, the default is no xattr field at all
+	local dodefault=""
+	[[ "${flags//[!z]}" ]] && dodefault="yes"
+
+	if has PT "${PAX_MARKINGS}"; then
+
+		#First try paxctl -> this might try to create/convert program headers
+		if type -p paxctl > /dev/null; then
+			for f in "$@"; do
+				# First, try modifying the existing PAX_FLAGS header
+				paxctl -q${flags} "${f}" >/dev/null 2>&1 && continue
+				# Second, try creating a PT_PAX header (works on ET_EXEC)
+				# Even though this is less safe, most exes need it, eg bug #463170
+				paxctl -qC${flags} "${f}" >/dev/null 2>&1 && continue
+				# Third, try stealing the (unused under PaX) PT_GNU_STACK header
+				paxctl -qc${flags} "${f}" >/dev/null 2>&1 && continue
+				pt_fail=1
+				pt_failures="${pt_failures} ${f}"
+			done
+
+		#Next try paxctl-ng -> this will not create/convert any program headers
+		elif type -p paxctl-ng > /dev/null && paxctl-ng -L ; then
+			flags="${flags//z}"
+			for f in "$@"; do
+				[[ ${dodefault} == "yes" ]] && paxctl-ng -L -z "${f}" >/dev/null 2>&1
+				[[ "${flags}" ]] || continue
+				paxctl-ng -L -${flags} "${f}" >/dev/null 2>&1 && continue
+				pt_fail=1
+				pt_failures="${pt_failures} ${f}"
+			done
+
+		#Finally fall back on scanelf
+		elif type -p scanelf > /dev/null && [[ ${PAX_MARKINGS} != "none" ]]; then
+			scanelf -Xxz ${flags} "$@" >/dev/null 2>&1
+
+		#We failed to set PT_PAX flags
+		elif [[ ${PAX_MARKINGS} != "none" ]]; then
+			pt_failures="$*"
+			pt_fail=1
+		fi
+
+		if [[ ${pt_fail} == 1 ]]; then
+			ret=1
+		fi
+	fi
+
+	if has XT "${PAX_MARKINGS}"; then
+
+		flags="${flags//z}"
+
+		#First try paxctl-ng
+		if type -p paxctl-ng > /dev/null && paxctl-ng -l ; then
+			for f in "$@"; do
+				[[ ${dodefault} == "yes" ]] && paxctl-ng -d "${f}" >/dev/null 2>&1
+				[[ "${flags}" ]] || continue
+				paxctl-ng -l -${flags} "${f}" >/dev/null 2>&1 && continue
+				xt_fail=1
+				xt_failures="${tx_failures} ${f}"
+			done
+
+		#Next try setfattr
+		elif type -p setfattr > /dev/null; then
+			[[ "${flags//[!Ee]}" ]] || flags+="e" # bug 447150
+			for f in "$@"; do
+				[[ ${dodefault} == "yes" ]] && setfattr -x "user.pax.flags" "${f}" >/dev/null 2>&1
+				setfattr -n "user.pax.flags" -v "${flags}" "${f}" >/dev/null 2>&1 && continue
+				xt_fail=1
+				xt_failures="${tx_failures} ${f}"
+			done
+
+		#We failed to set XATTR_PAX flags
+		elif [[ ${PAX_MARKINGS} != "none" ]]; then
+			xt_failures="$*"
+			xt_fail=1
+		fi
+
+		if [[ ${xt_fail} == 1 ]]; then
+			ret=1
+		fi
+	fi
+
+	return ${ret}
+}
+
+PAX_MARKINGS=${PAX_MARKINGS:="PT XT"}
+pax-mark "$@"


             reply	other threads:[~2013-05-20 19:47 UTC|newest]

Thread overview: 89+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-05-20 19:47 Anthony G. Basile [this message]
  -- strict thread matches above, loose matches on Subject: below --
2019-11-18 18:21 [gentoo-commits] proj/elfix:master commit in: scripts/ Anthony G. Basile
2019-04-22 22:14 Anthony G. Basile
2015-10-27 19:37 Anthony G. Basile
2015-01-04 15:42 Anthony G. Basile
2014-12-22 17:29 Anthony G. Basile
2014-10-17 20:02 Anthony G. Basile
2014-01-23 16:22 Anthony G. Basile
2014-01-20 22:44 Anthony G. Basile
2013-03-14  2:39 Anthony G. Basile
2013-01-06 17:19 Anthony G. Basile
2012-12-28 19:34 Anthony G. Basile
2012-12-23  3:49 Anthony G. Basile
2012-12-23  2:36 Anthony G. Basile
2012-12-23  1:04 Anthony G. Basile
2012-12-22 22:20 Anthony G. Basile
2012-12-22 20:17 Anthony G. Basile
2012-12-22 19:42 Anthony G. Basile
2012-12-22 19:29 Anthony G. Basile
2012-12-22 19:02 Anthony G. Basile
2012-12-22 18:31 Anthony G. Basile
2012-12-22 16:36 Anthony G. Basile
2012-12-22  1:04 Anthony G. Basile
2012-12-20  4:26 Anthony G. Basile
2012-12-19  4:09 Anthony G. Basile
2012-12-19  3:51 Anthony G. Basile
2012-12-15 20:03 Anthony G. Basile
2012-12-14  2:19 Anthony G. Basile
2012-12-14  2:16 Anthony G. Basile
2012-12-14  2:04 Anthony G. Basile
2012-12-14  1:59 Anthony G. Basile
2012-12-14  1:26 Anthony G. Basile
2012-12-14  1:20 Anthony G. Basile
2012-07-27 22:01 Anthony G. Basile
2012-07-23 19:18 Anthony G. Basile
2012-07-23 15:46 Anthony G. Basile
2012-07-23 15:27 Anthony G. Basile
2012-07-23 14:58 Anthony G. Basile
2012-07-23 14:15 Anthony G. Basile
2012-07-23 13:06 Anthony G. Basile
2012-07-23 11:47 Anthony G. Basile
2012-07-22 23:11 Anthony G. Basile
2012-07-22 22:22 Anthony G. Basile
2012-07-21 16:28 Anthony G. Basile
2012-07-21 15:44 Anthony G. Basile
2012-07-21 15:41 Anthony G. Basile
2012-07-21 13:53 Anthony G. Basile
2011-12-28 23:19 Anthony G. Basile
2011-12-28 23:18 Anthony G. Basile
2011-12-28 16:37 Anthony G. Basile
2011-12-28 15:39 Anthony G. Basile
2011-12-28 15:31 Anthony G. Basile
2011-12-26 22:24 Anthony G. Basile
2011-12-26 20:25 Anthony G. Basile
2011-12-04 21:43 Anthony G. Basile
2011-11-27  0:17 Anthony G. Basile
2011-11-26 22:08 Anthony G. Basile
2011-11-26 21:15 Anthony G. Basile
2011-11-26 19:08 Anthony G. Basile
2011-11-26 19:07 Anthony G. Basile
2011-10-17 20:55 Anthony G. Basile
2011-10-17 20:15 Anthony G. Basile
2011-10-17 19:28 Anthony G. Basile
2011-10-16 18:27 Anthony G. Basile
2011-10-16 18:27 Anthony G. Basile
2011-10-16 18:04 Anthony G. Basile
2011-10-13  4:36 Anthony G. Basile
2011-10-13  2:27 Anthony G. Basile
2011-10-13  0:36 Anthony G. Basile
2011-10-11  0:50 Anthony G. Basile
2011-10-10 23:42 Anthony G. Basile
2011-10-10 23:21 Anthony G. Basile
2011-10-10 17:30 Anthony G. Basile
2011-10-10 17:29 Anthony G. Basile
2011-10-08 18:35 Anthony G. Basile
2011-10-08  2:03 Anthony G. Basile
2011-10-08  0:46 Anthony G. Basile
2011-10-07 22:14 Anthony G. Basile
2011-10-07 19:58 Anthony G. Basile
2011-10-07  1:56 Anthony G. Basile
2011-10-06 23:39 Anthony G. Basile
2011-10-06 20:14 Anthony G. Basile
2011-10-06 19:46 Anthony G. Basile
2011-10-06  4:19 Anthony G. Basile
2011-10-06  4:07 Anthony G. Basile
2011-10-06  3:14 Anthony G. Basile
2011-10-06  3:13 Anthony G. Basile
2011-10-06  2:20 Anthony G. Basile
2011-09-08 23:50 Anthony G. Basile

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1369079198.55af0a5a4b0319b75cab06b78b8fc62d135cd0d4.blueness@gentoo \
    --to=blueness@gentoo.org \
    --cc=gentoo-commits@lists.gentoo.org \
    --cc=gentoo-dev@lists.gentoo.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox