public inbox for gentoo-commits@lists.gentoo.org
 help / color / mirror / Atom feed
* [gentoo-commits] proj/elfix:master commit in: scripts/
@ 2011-10-17 20:55 Anthony G. Basile
  0 siblings, 0 replies; 89+ messages in thread
From: Anthony G. Basile @ 2011-10-17 20:55 UTC (permalink / raw
  To: gentoo-commits

commit:     0552fd71e796816c4ccf383b05a2592d9c0a7e1e
Author:     Anthony G. Basile <blueness <AT> gentoo <DOT> org>
AuthorDate: Mon Oct 17 20:55:00 2011 +0000
Commit:     Anthony G. Basile <blueness <AT> gentoo <DOT> org>
CommitDate: Mon Oct 17 20:55:00 2011 +0000
URL:        http://git.overlays.gentoo.org/gitweb/?p=proj/elfix.git;a=commit;h=0552fd71

scripts/{paxmodule.c,revdep-pax}: removed EI_PAX markings, bug #387459

---
 scripts/paxmodule.c |   18 +++++++++++++++++-
 scripts/revdep-pax  |    2 +-
 2 files changed, 18 insertions(+), 2 deletions(-)

diff --git a/scripts/paxmodule.c b/scripts/paxmodule.c
index 32c8768..45e9f26 100644
--- a/scripts/paxmodule.c
+++ b/scripts/paxmodule.c
@@ -9,6 +9,7 @@
 #include <fcntl.h>
 #include <unistd.h>
 
+/* Gentoo bug #387459
 
 #define HF_PAX_PAGEEXEC		1
 #define HF_PAX_EMUTRAMP		2
@@ -18,6 +19,7 @@
 #define HF_PAX_SEGMEXEC		32
 
 #define EI_PAX			14	// Index to read the PaX flags into ELF header e_ident[] array
+*/
 
 #define BUF_SIZE		7	//Buffer for holding human readable flags
 
@@ -58,7 +60,9 @@ pax_getflags(PyObject *self, PyObject *args)
 	char pax_buf[BUF_SIZE];
 	uint16_t pax_flags;
 
-	GElf_Ehdr ehdr;
+	/* Gentoo bug #387459
+	GElf_Ehdr ehdr; 
+	*/
 	GElf_Phdr phdr;
 	char found_pt_pax;
 	size_t i, phnum;
@@ -140,6 +144,12 @@ pax_getflags(PyObject *self, PyObject *args)
 
 	if(!found_pt_pax)
 	{
+		//Set to the strictest possible
+	}
+
+	/* Gentoo bug #387459
+	if(!found_pt_pax)
+	{
 		if(gelf_getehdr(elf, &ehdr) != &ehdr)
 		{
 			elf_end(elf);
@@ -157,6 +167,7 @@ pax_getflags(PyObject *self, PyObject *args)
 		pax_buf[4] = pax_flags & HF_PAX_RANDMMAP ? 'r' : 'R';
 		pax_buf[5] = pax_flags & HF_PAX_RANDEXEC ? 'X' : 'x';
 	}
+	*/
 
 	elf_end(elf);
 	close(fd);
@@ -174,8 +185,10 @@ pax_setflags(PyObject *self, PyObject *args)
 
 	Elf *elf;
 
+	/* Gentoo bug #387459
 	GElf_Ehdr ehdr;
 	uint16_t ei_flags;
+	*/
 
 	GElf_Phdr phdr;
 	size_t i, phnum;
@@ -213,6 +226,8 @@ pax_setflags(PyObject *self, PyObject *args)
 		return NULL;
 	}
 
+	/* Gentoo bug #387459
+
 	if(gelf_getehdr(elf, &ehdr) != &ehdr)
 	{
 		elf_end(elf);
@@ -276,6 +291,7 @@ pax_setflags(PyObject *self, PyObject *args)
 		PyErr_SetString(PaxError, "pax_setflags: gelf_update_ehdr() failed");
 		return NULL;
 	}
+	*/
 
 
 	elf_getphdrnum(elf, &phnum);

diff --git a/scripts/revdep-pax b/scripts/revdep-pax
index a5636bd..59b8b4e 100755
--- a/scripts/revdep-pax
+++ b/scripts/revdep-pax
@@ -314,7 +314,7 @@ def run_soname(name, verbose, use_soname, mark):
 		except:
 			print 'cannot obtain pax flags for %s' % binary
 
-	if len(mismatched_binaries) == 0
+	if len(mismatched_binaries) == 0:
 		print
 		print '\tNo mismatches'
 		print



^ permalink raw reply related	[flat|nested] 89+ messages in thread
* [gentoo-commits] proj/elfix:master commit in: scripts/
@ 2019-11-18 18:21 Anthony G. Basile
  0 siblings, 0 replies; 89+ messages in thread
From: Anthony G. Basile @ 2019-11-18 18:21 UTC (permalink / raw
  To: gentoo-commits

commit:     6adf2b864fdbcb9cd57d427e6e411e6f09f83ef2
Author:     Anthony G. Basile <blueness <AT> gentoo <DOT> org>
AuthorDate: Mon Nov 18 18:20:14 2019 +0000
Commit:     Anthony G. Basile <blueness <AT> gentoo <DOT> org>
CommitDate: Mon Nov 18 18:20:26 2019 +0000
URL:        https://gitweb.gentoo.org/proj/elfix.git/commit/?id=6adf2b86

scripts/paxmark.sh: source the profiles for PAX_MARKINGS

Thanks chutzpah <AT> gentoo.org

Signed-off-by: Anthony G. Basile <blueness <AT> gentoo.org>

 scripts/paxmark.sh | 24 +++++++++++++++---------
 1 file changed, 15 insertions(+), 9 deletions(-)

diff --git a/scripts/paxmark.sh b/scripts/paxmark.sh
index 6491af1..7fb0ead 100755
--- a/scripts/paxmark.sh
+++ b/scripts/paxmark.sh
@@ -86,15 +86,21 @@ paxmarksh() {
 	return ${ret}
 }
 
-MAKE_CONF="/etc/portage/make.conf"
-
-if [[ -d $MAKE_CONF ]]; then
-	for MC in $MAKE_CONF/*; do
-		source $MC
-	done
-elif [[ -e $MAKE_CONF ]]; then
-	source $MAKE_CONF
+if command -v portageq >/dev/null; then
+	PAX_MARKINGS="$(portageq envvar PAX_MARKINGS)"
 fi
 
-PAX_MARKINGS=${PAX_MARKINGS:="none"}
+if [[ -z ${PAX_MARKINGS} ]]; then
+	MAKE_CONF="/etc/portage/make.conf"
+
+	if [[ -d ${MAKE_CONF} ]]; then
+		for MC in "${MAKE_CONF}"/*; do
+			source "${MC}"
+		done
+	elif [[ -r ${MAKE_CONF} ]]; then
+		source "${MAKE_CONF}"
+	fi
+fi
+
+: "${PAX_MARKINGS:="none"}"
 paxmarksh "$@"


^ permalink raw reply related	[flat|nested] 89+ messages in thread
* [gentoo-commits] proj/elfix:master commit in: scripts/
@ 2019-04-22 22:14 Anthony G. Basile
  0 siblings, 0 replies; 89+ messages in thread
From: Anthony G. Basile @ 2019-04-22 22:14 UTC (permalink / raw
  To: gentoo-commits

commit:     90c388bd9253bb51ed19daafed9786f4d71c7be3
Author:     Anthony G. Basile <blueness <AT> gentoo <DOT> org>
AuthorDate: Mon Apr 22 21:19:16 2019 +0000
Commit:     Anthony G. Basile <blueness <AT> gentoo <DOT> org>
CommitDate: Mon Apr 22 22:13:53 2019 +0000
URL:        https://gitweb.gentoo.org/proj/elfix.git/commit/?id=90c388bd

scripts/paxmark.sh: have PAX_MARKINGS default to 'none'

Signed-off-by: Anthony G. Basile <blueness <AT> gentoo.org>

 scripts/paxmark.sh | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/scripts/paxmark.sh b/scripts/paxmark.sh
index c273bd8..6491af1 100755
--- a/scripts/paxmark.sh
+++ b/scripts/paxmark.sh
@@ -96,5 +96,5 @@ elif [[ -e $MAKE_CONF ]]; then
 	source $MAKE_CONF
 fi
 
-PAX_MARKINGS=${PAX_MARKINGS:="PT XT"}
+PAX_MARKINGS=${PAX_MARKINGS:="none"}
 paxmarksh "$@"


^ permalink raw reply related	[flat|nested] 89+ messages in thread
* [gentoo-commits] proj/elfix:master commit in: scripts/
@ 2015-10-27 19:37 Anthony G. Basile
  0 siblings, 0 replies; 89+ messages in thread
From: Anthony G. Basile @ 2015-10-27 19:37 UTC (permalink / raw
  To: gentoo-commits

commit:     acf0ff62ad3f22e3ea2980fe0947d648e41bd995
Author:     Anthony G. Basile <blueness <AT> gentoo <DOT> org>
AuthorDate: Tue Oct 27 19:42:35 2015 +0000
Commit:     Anthony G. Basile <blueness <AT> gentoo <DOT> org>
CommitDate: Tue Oct 27 19:42:35 2015 +0000
URL:        https://gitweb.gentoo.org/proj/elfix.git/commit/?id=acf0ff62

scripts/paxmark.sh: don't do a login bash, bug #564142.

 scripts/paxmark.sh | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/scripts/paxmark.sh b/scripts/paxmark.sh
index 71631b7..c273bd8 100755
--- a/scripts/paxmark.sh
+++ b/scripts/paxmark.sh
@@ -1,4 +1,4 @@
-#!/bin/bash -l
+#!/bin/bash
 
 has() {
 	f=$1


^ permalink raw reply related	[flat|nested] 89+ messages in thread
* [gentoo-commits] proj/elfix:master commit in: scripts/
@ 2015-01-04 15:42 Anthony G. Basile
  0 siblings, 0 replies; 89+ messages in thread
From: Anthony G. Basile @ 2015-01-04 15:42 UTC (permalink / raw
  To: gentoo-commits

commit:     9c5d66ed746deaf51033b322022b9070e0984011
Author:     Fabio Scaccabarozzi <fsvm88 <AT> gmail <DOT> com>
AuthorDate: Sun Jan  4 15:23:41 2015 +0000
Commit:     Anthony G. Basile <blueness <AT> gentoo <DOT> org>
CommitDate: Sun Jan  4 15:43:08 2015 +0000
URL:        http://sources.gentoo.org/gitweb/?p=proj/elfix.git;a=commit;h=9c5d66ed

scripts/paxmodule.c: fix build with clang

clang complains of a return with no NULL.

X-Gentoo-Bug: 526832
X-Gentoo-Bug-URL: https://bugs.gentoo.org/526832
Signed-off-by: Anthony G. Basile <blueness <AT> gentoo.org>

---
 scripts/paxmodule.c | 4 ++++
 1 file changed, 4 insertions(+)

diff --git a/scripts/paxmodule.c b/scripts/paxmodule.c
index 4ba32df..1355f86 100644
--- a/scripts/paxmodule.c
+++ b/scripts/paxmodule.c
@@ -101,7 +101,11 @@ initpax(void)
 #endif
 
 	if (m == NULL)
+#if PY_MAJOR_VERSION >= 3
+		return NULL;
+#else
 		return;
+#endif
 
 	PaxError = PyErr_NewException("pax.PaxError", NULL, NULL);
 	Py_INCREF(PaxError);


^ permalink raw reply related	[flat|nested] 89+ messages in thread
* [gentoo-commits] proj/elfix:master commit in: scripts/
@ 2014-12-22 17:29 Anthony G. Basile
  0 siblings, 0 replies; 89+ messages in thread
From: Anthony G. Basile @ 2014-12-22 17:29 UTC (permalink / raw
  To: gentoo-commits

commit:     581b53b3c1ca3166dc394d1f4b08260bd088c346
Author:     Anthony G. Basile <blueness <AT> gentoo <DOT> org>
AuthorDate: Mon Dec 22 17:30:12 2014 +0000
Commit:     Anthony G. Basile <blueness <AT> gentoo <DOT> org>
CommitDate: Mon Dec 22 17:30:12 2014 +0000
URL:        http://sources.gentoo.org/gitweb/?p=proj/elfix.git;a=commit;h=581b53b3

scripts/revdep-pax: change .get_maps() to .get_graph()

---
 scripts/revdep-pax | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/scripts/revdep-pax b/scripts/revdep-pax
index a718fd6..7c1cf85 100755
--- a/scripts/revdep-pax
+++ b/scripts/revdep-pax
@@ -465,7 +465,7 @@ def run_soname(name, verbose, use_soname, mark, allyes, executable_only):
     shell_path = os.getenv('PATH').split(':')
 
     (object_linkings, object_reverse_linkings,
-     library2soname, soname2library) = LinkGraph().get_maps()
+     library2soname, soname2library) = LinkGraph().get_graph()
 
     if use_soname:
         soname = name


^ permalink raw reply related	[flat|nested] 89+ messages in thread
* [gentoo-commits] proj/elfix:master commit in: scripts/
@ 2014-10-17 20:02 Anthony G. Basile
  0 siblings, 0 replies; 89+ messages in thread
From: Anthony G. Basile @ 2014-10-17 20:02 UTC (permalink / raw
  To: gentoo-commits

commit:     41a91c0486e881ace7deb9e44752fbe93e640b36
Author:     Anthony G. Basile <blueness <AT> gentoo <DOT> org>
AuthorDate: Fri Oct 17 20:03:19 2014 +0000
Commit:     Anthony G. Basile <blueness <AT> gentoo <DOT> org>
CommitDate: Fri Oct 17 20:03:29 2014 +0000
URL:        http://sources.gentoo.org/gitweb/?p=proj/elfix.git;a=commit;h=41a91c04

scripts/paxmark.sh: backport improvements from pax-utils.eclass

---
 scripts/paxmark.sh | 95 ++++++++++++++++++++++--------------------------------
 1 file changed, 38 insertions(+), 57 deletions(-)

diff --git a/scripts/paxmark.sh b/scripts/paxmark.sh
index 02f966e..9ec077a 100755
--- a/scripts/paxmark.sh
+++ b/scripts/paxmark.sh
@@ -1,16 +1,15 @@
 #!/bin/bash -l
 
 has() {
-	[[ "${2/$1/}" != "$2" ]] && return 0
+	f=$1
+	shift
+	[[ "${@/$f/}" != "$@" ]] && return 0
 	return 1
 }
 
 paxmarksh() {
-
 	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
@@ -27,11 +26,11 @@ paxmarksh() {
 	local dodefault=""
 	[[ "${flags//[!z]}" ]] && dodefault="yes"
 
-	if has PT "${PAX_MARKINGS}"; then
+	if has PT ${PAX_MARKINGS}; then
+		for f in "$@"; do
 
-		#First try paxctl -> this might try to create/convert program headers
-		if type -p paxctl > /dev/null; then
-			for f in "$@"; do
+			#First try paxctl -> this might try to create/convert program headers
+			if type -p paxctl > /dev/null; then
 				# 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)
@@ -39,69 +38,51 @@ paxmarksh() {
 				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
+			fi
 
-		#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
+			#Next try paxctl-ng -> this will not create/convert any program headers
+			if type -p paxctl-ng > /dev/null && paxctl-ng -L ; then
+				flags="${flags//z}"
 				[[ ${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
+
+			#Finally fall back on scanelf
+			if type -p scanelf > /dev/null && [[ ${PAX_MARKINGS} != "none" ]]; then
+				scanelf -Xxz ${flags} "$f" >/dev/null 2>&1
+			#We failed to set PT_PAX flags
+			elif [[ ${PAX_MARKINGS} != "none" ]]; then
+				elog "Failed to set PT_PAX markings -${flags} ${f}."
+				ret=1
+			fi
+		done
 	fi
 
-	if has XT "${PAX_MARKINGS}"; then
-
+	if has XT ${PAX_MARKINGS}; then
 		flags="${flags//z}"
+		for f in "$@"; do
 
-		#First try paxctl-ng
-		if type -p paxctl-ng > /dev/null && paxctl-ng -l ; then
-			for f in "$@"; do
+			#First try paxctl-ng
+			if type -p paxctl-ng > /dev/null && paxctl-ng -l ; then
 				[[ ${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
+			fi
 
-		#Next try setfattr
-		elif type -p setfattr > /dev/null; then
-			[[ "${flags//[!Ee]}" ]] || flags+="e" # bug 447150
-			for f in "$@"; do
+			#Next try setfattr
+			if type -p setfattr > /dev/null; then
+				[[ "${flags//[!Ee]}" ]] || flags+="e" # bug 447150
 				[[ ${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
+
+			#We failed to set XATTR_PAX flags
+			if [[ ${PAX_MARKINGS} != "none" ]]; then
+				elog "Failed to set XATTR_PAX markings -${flags} ${f}."
+				ret=1
+			fi
+		done
 	fi
 
 	return ${ret}


^ permalink raw reply related	[flat|nested] 89+ messages in thread
* [gentoo-commits] proj/elfix:master commit in: scripts/
@ 2014-01-23 16:22 Anthony G. Basile
  0 siblings, 0 replies; 89+ messages in thread
From: Anthony G. Basile @ 2014-01-23 16:22 UTC (permalink / raw
  To: gentoo-commits

commit:     e68a8d9fe0ac6788695bf779180db1ed790f6cb7
Author:     Matthew Thode <mthode <AT> mthode <DOT> org>
AuthorDate: Mon Jan 20 17:01:27 2014 +0000
Commit:     Anthony G. Basile <blueness <AT> gentoo <DOT> org>
CommitDate: Thu Jan 23 16:22:45 2014 +0000
URL:        http://git.overlays.gentoo.org/gitweb/?p=proj/elfix.git;a=commit;h=e68a8d9f

fix used before define on sv/s

Signed-off-by: Matthew Thode <prometheanfire <AT> gentoo.org>

---
 scripts/revdep-pax | 18 ++++++++++++------
 1 file changed, 12 insertions(+), 6 deletions(-)

diff --git a/scripts/revdep-pax b/scripts/revdep-pax
index ebdea9c..2d9de16 100755
--- a/scripts/revdep-pax
+++ b/scripts/revdep-pax
@@ -240,11 +240,13 @@ def run_forward(verbose):
             try:
                 (elf_str_flags, elf_bin_flags) = pax.getflags(elf)
                 sv = '%s :%s ( %s )' % (elf, abi, elf_str_flags)
-                s = sv
-            except pax.PaxError:
-                sv = '%s :%s ( %s )' % (elf, abi, '****')
-                s = sv
+            except (pax.PaxError, RuntimeError, TypeError, NameError):
+                #because this is a pax error (likely), we need to set elf_str_flags
+                #elf_str_flags and sv are used a few lines down
+                elf_str_flags = '****'
+                sv = '%s :%s ( %s )' % (elf, abi, elf_str_flags)
                 continue
+            s = sv
 
             count = 0
             for soname in object_linkings[abi][elf]:
@@ -291,10 +293,14 @@ def run_reverse(verbose, executable_only):
                     (library_str_flags, library_bin_flags) = pax.getflags(library)
                 except pax.PaxError:
                     library_str_flags = '****'
-                sv = '%s\t%s :%s ( %s )' % (soname, library, abi, library_str_flags)
-                s = sv
             except KeyError:
                 sonames_missing_library.append(soname)
+                library = 'unknown_library'
+                library_str_flags = '****'
+            #always gets set, and dependant variables always get set, no need to
+            #be in a try statement
+            sv = '%s\t%s :%s ( %s )' % (soname, library, abi, library_str_flags)
+            s = sv
 
             count = 0
             for elf in object_reverse_linkings[abi][soname]:


^ permalink raw reply related	[flat|nested] 89+ messages in thread
* [gentoo-commits] proj/elfix:master commit in: scripts/
@ 2014-01-20 22:44 Anthony G. Basile
  0 siblings, 0 replies; 89+ messages in thread
From: Anthony G. Basile @ 2014-01-20 22:44 UTC (permalink / raw
  To: gentoo-commits

commit:     33f3494a33b3d0dca118ede0f1f3a459176dde6d
Author:     Matthew Thode <mthode <AT> mthode <DOT> org>
AuthorDate: Mon Jan 20 16:56:57 2014 +0000
Commit:     Anthony G. Basile <blueness <AT> gentoo <DOT> org>
CommitDate: Mon Jan 20 22:42:13 2014 +0000
URL:        http://git.overlays.gentoo.org/gitweb/?p=proj/elfix.git;a=commit;h=33f3494a

updating python apps for pep8

---
 scripts/migrate-pax |  20 +++---
 scripts/pypaxctl    |  99 +++++++++++++++---------------
 scripts/revdep-pax  | 171 ++++++++++++++++++++++++++--------------------------
 3 files changed, 150 insertions(+), 140 deletions(-)

diff --git a/scripts/migrate-pax b/scripts/migrate-pax
index 429d45c..8593271 100755
--- a/scripts/migrate-pax
+++ b/scripts/migrate-pax
@@ -19,7 +19,8 @@
 
 # We use portage's NEEDED.ELF.2 file.  The format is in
 # /usr/lib/portage/bin/misc-functions.sh ~line 520
-# echo "${arch:3};${obj};${soname};${rpath};${needed}" >> "${PORTAGE_BUILDDIR}"/build-info/NEEDED.ELF.2
+# echo "${arch:3};${obj};${soname};${rpath};${needed}" \
+# >> "${PORTAGE_BUILDDIR}"/build-info/NEEDED.ELF.2
 
 import os
 import re
@@ -28,6 +29,7 @@ import sys
 import pax
 import portage
 
+
 def get_objects():
 
     vardb = portage.db[portage.root]["vartree"].dbapi
@@ -36,11 +38,11 @@ def get_objects():
 
     for pkg in vardb.cpv_all():
         needed = vardb.aux_get(pkg, ['NEEDED.ELF.2'])[0].strip()
-        if not needed: # Some packages have no NEEDED.ELF.2
+        if not needed:  # Some packages have no NEEDED.ELF.2
             continue
         for line in re.split('\n', needed):
             link = re.split(';', line)
-            objects.append(link[1]) # link[1] is the ELF object
+            objects.append(link[1])  # link[1] is the ELF object
 
     return objects
 
@@ -69,7 +71,7 @@ def main():
     try:
         opts, args = getopt.getopt(sys.argv[1:], 'vmdh')
     except getopt.GetoptError as err:
-        print(str(err)) # will print something like 'option -a not recognized'
+        print(str(err))  # will print something like 'option -a not recognized'
         run_usage()
         sys.exit(1)
 
@@ -102,7 +104,7 @@ def main():
         run_usage()
         sys.exit(0)
 
-    if opt_count == 0 or opt_count > 2 or ( do_migration and do_deleteall):
+    if opt_count == 0 or opt_count > 2 or (do_migration and do_deleteall):
         run_usage()
         sys.exit(1)
 
@@ -111,7 +113,8 @@ def main():
         try:
             from pax import deletextpax
         except ImportError:
-            print('ERROR: Python module pax.so was compiled without XATTR_PAX support, cannot migrate or delete XATTR_PAX')
+            print('ERROR: Python module pax.so was compiled without XATTR_PAX support, '
+                  'cannot migrate or delete XATTR_PAX')
             sys.exit(1)
 
     objects = get_objects()
@@ -131,8 +134,9 @@ def main():
                     print("NONE: %s" % elf)
 
             if do_migration:
-                flags = re.sub('-','',flags)
-                if flags == 'e': continue # Don't create XATTR_PAX for default
+                flags = re.sub('-', '', flags)
+                if flags == 'e':
+                    continue  # Don't create XATTR_PAX for default
                 pax.setstrflags(elf, flags)
 
             if do_deleteall:

diff --git a/scripts/pypaxctl b/scripts/pypaxctl
index cca3d2c..cfae4d3 100755
--- a/scripts/pypaxctl
+++ b/scripts/pypaxctl
@@ -24,62 +24,65 @@ import pax
 
 xattr_available = True
 try:
-	from pax import deletextpax
+    from pax import deletextpax
 except ImportError:
-	xattr_available = False
+    deletextpax = ''
+    xattr_available = False
+
 
 def run_usage():
-	print('Package Name : elfix')
-	print('Bug Reports  : http://bugs.gentoo.org/')
-	print('Program Name : pypaxctl')
-	if xattr_available:
-		print('Description  : Get/set/delete PT_PAX or XATTR_PAX flags on an ELF object')
-		print('')
-		print('Usage        : pypaxctl -g ELF                get XATTR_PAX flags first, else get PT_PAX flags')
-		print('             : pypaxctl -s [-PpEeMmRrSs] ELF  set PT_PAX and XATTR_PAX flags whenever possible')
-		print('             : pypaxctl -d ELF                delete the XATTR_PAX field')
-	else:
-		print('Description  : Get/set PT_PAX flags on an ELF object')
-		print('')
-		print('Usage        : pypaxctl -g ELF                get PT_PAX flags')
-		print('             : pypaxctl -s [-PpEeMmRrSs] ELF  set PT_PAX flags whenever possible')
-		print('')
-		print('Note         : Python module pax.so was compiled without XATTR_PAX support')
-	print('')
+    print('Package Name : elfix')
+    print('Bug Reports  : http://bugs.gentoo.org/')
+    print('Program Name : pypaxctl')
+    xattr_message = '''Description  : Get/set/delete PT_PAX or XATTR_PAX flags on an ELF object
+
+Usage        : pypaxctl -g ELF                get XATTR_PAX flags first, else get PT_PAX flags
+             : pypaxctl -s [-PpEeMmRrSs] ELF  set PT_PAX and XATTR_PAX flags whenever possible
+             : pypaxctl -d ELF                delete the XATTR_PAX field'''
+    if xattr_available:
+        print(xattr_message)
+    else:
+        print('Description  : Get/set PT_PAX flags on an ELF object')
+        print('')
+        print('Usage        : pypaxctl -g ELF                get PT_PAX flags')
+        print('             : pypaxctl -s [-PpEeMmRrSs] ELF  set PT_PAX flags whenever possible')
+        print('')
+        print('Note         : Python module pax.so was compiled without XATTR_PAX support')
+    print('')
 
 
 def main():
-	try:
-		if xattr_available:
-			opts, args = getopt.getopt(sys.argv[1:], 'gs:d')
-		else:
-			opts, args = getopt.getopt(sys.argv[1:], 'gs:')
-	except getopt.GetoptError as err:
-		print(err)
-		sys.exit(1)
+    try:
+        if xattr_available:
+            opts, args = getopt.getopt(sys.argv[1:], 'gs:d')
+        else:
+            opts, args = getopt.getopt(sys.argv[1:], 'gs:')
+    except getopt.GetoptError as err:
+        print(err)
+        sys.exit(1)
 
-	if( len(opts) != 1 or len(args) < 1 ):
-		run_usage()
-		sys.exit(1)
+    if (len(opts) != 1) or (len(args) < 1):
+        run_usage()
+        sys.exit(1)
 
-	for o, a in opts:
-		if o == '-g':
-			for elf in args:
-				( str_flags, bin_flags ) = pax.getflags(elf)
-				print('%s' % str_flags)
-		elif o == '-s':
-			for elf in args:
-				pax.setstrflags(elf, a)
+    for o, a in opts:
+        if o == '-g':
+            for elf in args:
+                (str_flags, bin_flags) = pax.getflags(elf)
+                print('%s' % str_flags)
+        elif o == '-s':
+            for elf in args:
+                pax.setstrflags(elf, a)
 
-		# Don't worry if xattr_available = False
-		# because we can't get here if it is.
-		else:
-			for elf in args:
-				try:
-					pax.deletextpax(elf)
-				except pax.PaxError:
-					print('pax_deletextpax: XATTR_PAX not supported')
-					sys.exit(1)
+        # Don't worry if xattr_available = False
+        # because we can't get here if it is.
+        else:
+            for elf in args:
+                try:
+                    pax.deletextpax(elf)
+                except pax.PaxError:
+                    print('pax_deletextpax: XATTR_PAX not supported')
+                    sys.exit(1)
 
 if __name__ == '__main__':
-	main()
+    main()

diff --git a/scripts/revdep-pax b/scripts/revdep-pax
index b919dbf..ebdea9c 100755
--- a/scripts/revdep-pax
+++ b/scripts/revdep-pax
@@ -23,14 +23,14 @@
 # information we need generated by scanelf during emerge.
 #
 # See /usr/lib/portage/bin/misc-functions.sh ~line 520
-# echo "${arch:3};${obj};${soname};${rpath};${needed}" >> "${PORTAGE_BUILDDIR}"/build-info/NEEDED.ELF.2
+# echo "${arch:3};${obj};${soname};${rpath};${needed}" >> \
+# "${PORTAGE_BUILDDIR}"/build-info/NEEDED.ELF.2
 #
 
 import getopt
 import os
 import sys
 import pax
-
 import re
 import portage
 
@@ -66,11 +66,10 @@ class LinkMap:
 
         for pkg in vardb.cpv_all():
             needed = vardb.aux_get(pkg, ['NEEDED.ELF.2'])[0].strip()
-            if needed: # Some packages have no NEEDED.ELF.2
+            if needed:  # Some packages have no NEEDED.ELF.2
                 self.pkgs.append(pkg)
                 for line in re.split('\n', needed):
-                    self.pkgs_needed.setdefault(pkg,[]).append(re.split(';', line))
-
+                    self.pkgs_needed.setdefault(pkg, []).append(re.split(';', line))
 
     def get_object_needed(self):
         """ Return object_needed dictionary which has structure
@@ -91,11 +90,10 @@ class LinkMap:
                 abi = link[0]
                 elf = link[1]
                 sonames = re.split(',', link[4])
-                object_needed.setdefault(abi,{}).update({elf:sonames})
+                object_needed.setdefault(abi, {}).update({elf: sonames})
 
         return object_needed
 
-
     def get_libraries(self):
         """ Return library2soname dictionary which has structure
 
@@ -113,14 +111,13 @@ class LinkMap:
                 abi = link[0]
                 elf = link[1]
                 soname = link[2]
-                if soname:                               #no soname => executable
-                    library2soname[elf] = (soname,abi)
-                    soname2library[(soname,abi)] = elf
-
-        return ( library2soname, soname2library )
+                if soname:  # no soname => executable
+                    library2soname[elf] = (soname, abi)
+                    soname2library[(soname, abi)] = elf
 
+        return library2soname, soname2library
 
-    def get_soname_needed(self, object_needed, library2soname ):
+    def get_soname_needed(self, object_needed, library2soname):
         """ Return soname_needed dictionary which has structure:
 
             {
@@ -137,14 +134,14 @@ class LinkMap:
             for elf in object_needed[abi]:
                 try:
                     (soname, abi_check) = library2soname[elf]
-                    assert abi == abi_check # We should get the same abi associated with the soname
-                    soname_needed.setdefault(abi,{}).update({soname:object_needed[abi][elf]})
+                    # We should get the same abi associated with the soname
+                    assert abi == abi_check
+                    soname_needed.setdefault(abi, {}).update({soname: object_needed[abi][elf]})
                 except KeyError:
                     continue  # no soname, its probably an executable
 
         return soname_needed
 
-
     def expand_linkings(self, object_needed, soname2library):
         """ Expands the object_needed dictionary which has structure
 
@@ -162,27 +159,32 @@ class LinkMap:
             for elf in object_needed[abi]:
                 while True:
                     found_new_soname = False
-                    for so in object_needed[abi][elf]:                              # For all the first links ...
+                    # For all the first links ...
+                    for so in object_needed[abi][elf]:
                         try:
-                            for sn in object_needed[abi][soname2library[(so,abi)]]: # go to the next links ...
-                                if sn in object_needed[abi][elf]:                   # skip if already included ...
+                            # go to the next links ...
+                            for sn in object_needed[abi][soname2library[(so, abi)]]:
+                                # skip if already included ...
+                                if sn in object_needed[abi][elf]:
                                     continue
-                                if not (sn,abi) in soname2library:                  # skip if vdso ...
+                                # skip if vdso ...
+                                if not (sn, abi) in soname2library:
                                     continue
 
-                                # This appends to the object_needed and soname_needed lists.  No copy was
-                                # done so its the same lists in memory for both, and its modified for both.
+                        # This appends to the object_needed and soname_needed lists.  No copy was
+                        # done so its the same lists in memory for both, and its modified for both.
 
-                                object_needed[abi][elf].append(sn)                  # otherwise collapse it back into
-                                found_new_soname = True                             # first links of the chain.
+                                # otherwise collapse it back into
+                                object_needed[abi][elf].append(sn)
+                                # first links of the chain.
+                                found_new_soname = True
 
-                        except KeyError:                 # Not all nodes in the chain have a next node
+                        except KeyError:  # Not all nodes in the chain have a next node
                             continue
 
                     if not found_new_soname:             # We're done, that last iteration found
                         break                            # no new nodes
 
-
     def get_object_reverse_linkings(self, object_linkings):
         """ Return object_reverse_linkings dictionary which has structure
 
@@ -197,11 +199,10 @@ class LinkMap:
         for abi in object_linkings:
             for elf in object_linkings[abi]:
                 for soname in object_linkings[abi][elf]:
-                    object_reverse_linkings.setdefault(abi,{}).setdefault(soname,[]).append(elf)
+                    object_reverse_linkings.setdefault(abi, {}).setdefault(soname, []).append(elf)
 
         return object_reverse_linkings
 
-
     def get_maps(self):
         """ Generate the full forward and reverse links using the above functions """
 
@@ -209,18 +210,16 @@ class LinkMap:
         # soname_linkings are only one step into the entire link chain.
 
         object_linkings = self.get_object_needed()
-        ( library2soname, soname2library ) = self.get_libraries()
-        soname_linkings = self.get_soname_needed( object_linkings, library2soname )
+        (library2soname, soname2library) = self.get_libraries()
+        soname_linkings = self.get_soname_needed(object_linkings, library2soname)
 
         # After the appending in expand_linkings(), forward_linkings and soname_linkings
         # have been extended through the entire chain of linking.  expand_linkings() is
         # a "side-effect" function, so we note it here.
-        self.expand_linkings( soname_linkings, soname2library )
-        object_reverse_linkings = self.get_object_reverse_linkings( object_linkings )
-
-        return ( object_linkings, object_reverse_linkings, library2soname, soname2library )
-
+        self.expand_linkings(soname_linkings, soname2library)
+        object_reverse_linkings = self.get_object_reverse_linkings(object_linkings)
 
+        return object_linkings, object_reverse_linkings, library2soname, soname2library
 
 
 def print_problems(sonames_missing_library):
@@ -231,7 +230,8 @@ def print_problems(sonames_missing_library):
 
 
 def run_forward(verbose):
-    (object_linkings, object_reverse_linkings, library2soname, soname2library) = LinkMap().get_maps()
+    (object_linkings, object_reverse_linkings,
+     library2soname, soname2library) = LinkMap().get_maps()
 
     sonames_missing_library = []
 
@@ -257,7 +257,7 @@ def run_forward(verbose):
                     sv = '%s\n\t%s\t%s ( %s )' % (sv, soname, library, library_str_flags)
                     if elf_str_flags != library_str_flags:
                         s = '%s\n\t%s\t%s ( %s )' % (s, soname, library, library_str_flags)
-                        count = count + 1
+                        count += 1
                 except KeyError:
                     sonames_missing_library.append(soname)
 
@@ -276,9 +276,10 @@ def run_forward(verbose):
 
 
 def run_reverse(verbose, executable_only):
-    (object_linkings, object_reverse_linkings, library2soname, soname2library) = LinkMap().get_maps()
+    (object_linkings, object_reverse_linkings,
+     library2soname, soname2library) = LinkMap().get_maps()
 
-    shell_path = path = os.getenv('PATH').split(':')
+    shell_path = os.getenv('PATH').split(':')
 
     sonames_missing_library = []
 
@@ -306,12 +307,12 @@ def run_reverse(verbose, executable_only):
                         sv = '%s\n\t%s ( %s )' % (sv, elf, elf_str_flags)
                         if library_str_flags != elf_str_flags:
                             s = '%s\n\t%s ( %s )' % (s, elf, elf_str_flags)
-                            count = count + 1
+                            count += 1
                 else:
                     sv = '%s\n\t%s ( %s )' % (sv, elf, elf_str_flags)
                     if library_str_flags != elf_str_flags:
                         s = '%s\n\t%s ( %s )' % (s, elf, elf_str_flags)
-                        count = count + 1
+                        count += 1
 
             if verbose:
                 print('%s\n' % sv)
@@ -345,12 +346,12 @@ def migrate_flags(importer, exporter_str_flags, exporter_bin_flags):
 
     #See /usr/include/elf.h for these values
     pf_flags = {
-        'P':1<<4, 'p':1<<5,
-        'S':1<<6, 's':1<<7,
-        'M':1<<8, 'm':1<<9,
-        'X':1<<10, 'x':1<<11,
-        'E':1<<12, 'e':1<<13,
-        'R':1<<14, 'r':1<<15
+        'P': 1 << 4, 'p': 1 << 5,
+        'S': 1 << 6, 's': 1 << 7,
+        'M': 1 << 8, 'm': 1 << 9,
+        'X': 1 << 10, 'x': 1 << 11,
+        'E': 1 << 12, 'e': 1 << 13,
+        'R': 1 << 14, 'r': 1 << 15
     }
 
     try:
@@ -373,10 +374,10 @@ def migrate_flags(importer, exporter_str_flags, exporter_bin_flags):
             result_bin_flags = result_bin_flags ^ pf_flags[exporter_str_flags[i]]
             result_bin_flags = result_bin_flags | pf_flags[importer_str_flags[i]]
             print('\t\tWarning: %s has %s, refusing to set to %s' % (
-                importer, importer_str_flags[i], exporter_str_flags[i] )),
+                importer, importer_str_flags[i], exporter_str_flags[i])),
 
         # The exporter's flags is off, so use the importer's flag
-        if (exporter_str_flags[i] == '-' and importer_str_flags[i] != '-'):
+        if (exporter_str_flags[i] == '-') and (importer_str_flags[i] != '-'):
             result_bin_flags = result_bin_flags | pf_flags[importer_str_flags[i]]
 
     pax.setbinflags(importer, result_bin_flags)
@@ -394,16 +395,17 @@ def run_elf(elf, verbose, mark, allyes):
         print('%s: No PAX flags found\n' % elf)
         return
 
-    (object_linkings, object_reverse_linkings, library2soname, soname2library) = LinkMap().get_maps()
+    (object_linkings, object_reverse_linkings,
+     library2soname, soname2library) = LinkMap().get_maps()
 
     mismatched_libraries = []
 
     for abi in object_linkings:
-        if not elf in object_linkings[abi]: # There may be no elf for that abi
+        if not elf in object_linkings[abi]:  # There may be no elf for that abi
             continue
         for soname in object_linkings[abi][elf]:
             try:
-                library = soname2library[(soname,abi)]
+                library = soname2library[(soname, abi)]
                 try:
                     (library_str_flags, library_bin_flags) = pax.getflags(library)
                 except pax.PaxError:
@@ -444,7 +446,7 @@ def run_elf(elf, verbose, mark, allyes):
                         try:
                             migrate_flags(library, elf_str_flags, elf_bin_flags)
                         except pax.PaxError:
-                            print('\n\tCould not set PAX flags on %s, text maybe busy' % (library, abi))
+                            print('\n\tCould not set PAX flags on %s, text maybe busy' % library)
 
                         try:
                             (library_str_flags, library_bin_flags) = pax.getflags(library)
@@ -454,9 +456,10 @@ def run_elf(elf, verbose, mark, allyes):
 
 
 def run_soname(name, verbose, use_soname, mark, allyes, executable_only):
-    shell_path = path = os.getenv('PATH').split(':')
+    shell_path = os.getenv('PATH').split(':')
 
-    (object_linkings, object_reverse_linkings, library2soname, soname2library) = LinkMap().get_maps()
+    (object_linkings, object_reverse_linkings,
+     library2soname, soname2library) = LinkMap().get_maps()
 
     if use_soname:
         soname = name
@@ -476,7 +479,6 @@ def run_soname(name, verbose, use_soname, mark, allyes, executable_only):
             print('%s\tNo such LIBRARY' % name)
             return
 
-
     mismatched_elfs = []
 
     for abi in abi_list:
@@ -487,15 +489,15 @@ def run_soname(name, verbose, use_soname, mark, allyes, executable_only):
         library = soname2library[(soname, abi)]
 
         try:
-           (library_str_flags, library_bin_flags) = pax.getflags(library)
-           print('%s\t%s :%s (%s)\n' % (soname, library, abi, library_str_flags))
+            (library_str_flags, library_bin_flags) = pax.getflags(library)
+            print('%s\t%s :%s (%s)\n' % (soname, library, abi, library_str_flags))
         except pax.PaxError:
-           print('%s :%s : No PAX flags found\n' % (library, abi))
-           continue
+            print('%s :%s : No PAX flags found\n' % (library, abi))
+            continue
 
         for elf in object_reverse_linkings[abi][soname]:
             try:
-                (elf_str_flags, elf_bin_flags ) = pax.getflags(elf)
+                (elf_str_flags, elf_bin_flags) = pax.getflags(elf)
             except pax.PaxError:
                 elf_str_flags = '****'
             if verbose:
@@ -551,22 +553,23 @@ def run_soname(name, verbose, use_soname, mark, allyes, executable_only):
 
 
 def run_usage():
-    print('Package Name : elfix')
-    print('Bug Reports  : http://bugs.gentoo.org/')
-    print('Program Name : revdep-pax')
-    print('Description  : Get or set pax flags on an ELF object')
-    print('')
-    print('Usage        : revdep-pax -f [-v]             print out all forward mappings for all system ELF objects')
-    print('             : revdep-pax -r [-ve]            print out all reverse mappings for all system sonames')
-    print('             : revdep-pax -b OBJECT  [-myv]   print all forward mappings only for OBJECT')
-    print('             : revdep-pax -s SONAME  [-myve]  print all reverse mappings only for SONAME')
-    print('             : revdep-pax -l LIBRARY [-myve]  print all reverse mappings only for LIBRARY file')
-    print('             : revdep-pax [-h]                print out this help')
-    print('             : -v                             verbose, otherwise just print mismatching objects')
-    print('             : -e                             only print out executables in shell $PATH')
-    print('             : -m                             don\'t just report, but mark the mismatching objects')
-    print('             : -y                             assume "yes" to all prompts for marking (USE CAREFULLY!)')
-    print('')
+    usage = '''Package Name : elfix
+Bug Reports  : http://bugs.gentoo.org/
+Program Name : revdep-pax
+Description  : Get or set pax flags on an ELF object
+
+Usage        : revdep-pax -f [-v]             print all forward mappings for all system ELF objects
+             : revdep-pax -r [-ve]            print all reverse mappings for all system sonames
+             : revdep-pax -b OBJECT  [-myv]   print all forward mappings only for OBJECT
+             : revdep-pax -s SONAME  [-myve]  print all reverse mappings only for SONAME
+             : revdep-pax -l LIBRARY [-myve]  print all reverse mappings only for LIBRARY file
+             : revdep-pax [-h]                print this help
+             : -v                             verbose, otherwise just print mismatching objects
+             : -e                             only print executables in shell $PATH
+             : -m                             don\'t just report, but mark the mismatching objects
+             : -y                             assume "yes" to all prompts for marking (BE CAREFULL)
+'''
+    print(usage)
 
 
 def main():
@@ -579,7 +582,7 @@ def main():
     try:
         opts, args = getopt.getopt(sys.argv[1:], 'hfrb:s:l:vemy')
     except getopt.GetoptError as err:
-        print(str(err)) # will print something like 'option -a not recognized'
+        print(str(err))  # will print something like 'option -a not recognized'
         run_usage()
         sys.exit(1)
 
@@ -587,12 +590,12 @@ def main():
         run_usage()
         sys.exit(1)
 
-    do_usage   = False
+    do_usage = False
     do_forward = False
     do_reverse = False
 
-    elf     = None
-    soname  = None
+    elf = None
+    soname = None
     library = None
 
     verbose = False
@@ -641,11 +644,11 @@ def main():
         run_forward(verbose)
     elif do_reverse:
         run_reverse(verbose, executable_only)
-    elif elf != None:
+    elif elf is not None:
         run_elf(elf, verbose, mark, allyes)
-    elif soname != None:
+    elif soname is not None:
         run_soname(soname, verbose, True, mark, allyes, executable_only)
-    elif library != None:
+    elif library is not None:
         library = os.path.realpath(library)
         run_soname(library, verbose, False, mark, allyes, executable_only)
 


^ permalink raw reply related	[flat|nested] 89+ messages in thread
* [gentoo-commits] proj/elfix:master commit in: scripts/
@ 2013-05-20 19:47 Anthony G. Basile
  0 siblings, 0 replies; 89+ messages in thread
From: Anthony G. Basile @ 2013-05-20 19:47 UTC (permalink / raw
  To: gentoo-commits

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 "$@"


^ permalink raw reply related	[flat|nested] 89+ messages in thread
* [gentoo-commits] proj/elfix:master commit in: scripts/
@ 2013-03-14  2:39 Anthony G. Basile
  0 siblings, 0 replies; 89+ messages in thread
From: Anthony G. Basile @ 2013-03-14  2:39 UTC (permalink / raw
  To: gentoo-commits

commit:     e6ae5bed6f651b8a4c901c25038427e3eb58763d
Author:     Anthony G. Basile <blueness <AT> gentoo <DOT> org>
AuthorDate: Thu Mar 14 02:38:52 2013 +0000
Commit:     Anthony G. Basile <blueness <AT> gentoo <DOT> org>
CommitDate: Thu Mar 14 02:38:52 2013 +0000
URL:        http://git.overlays.gentoo.org/gitweb/?p=proj/elfix.git;a=commit;h=e6ae5bed

scripts/setup.py: fix version number

Signed-off-by: Anthony G. Basile <blueness <AT> gentoo.org>

---
 scripts/setup.py |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)

diff --git a/scripts/setup.py b/scripts/setup.py
index f428db2..0a1bf5c 100755
--- a/scripts/setup.py
+++ b/scripts/setup.py
@@ -103,7 +103,7 @@ else:
 
 setup(
 	name = 'PaxPython',
-	version = '0.6.1',
+	version = '0.8',
 	author = 'Anthony G. Basile',
 	author_email = 'blueness@gentoo.org',
 	url = 'http://dev.gentoo.org/~blueness/elfix',


^ permalink raw reply related	[flat|nested] 89+ messages in thread
* [gentoo-commits] proj/elfix:master commit in: scripts/
@ 2013-01-06 17:19 Anthony G. Basile
  0 siblings, 0 replies; 89+ messages in thread
From: Anthony G. Basile @ 2013-01-06 17:19 UTC (permalink / raw
  To: gentoo-commits

commit:     d6991e45f5297d30b9ee764b8d0d75ab96c10caf
Author:     Anthony G. Basile <blueness <AT> gentoo <DOT> org>
AuthorDate: Sun Jan  6 17:19:10 2013 +0000
Commit:     Anthony G. Basile <blueness <AT> gentoo <DOT> org>
CommitDate: Sun Jan  6 17:19:10 2013 +0000
URL:        http://git.overlays.gentoo.org/gitweb/?p=proj/elfix.git;a=commit;h=d6991e45

scripts/migrate-pax: do not create XATTR_PAX for default flags

---
 scripts/migrate-pax |    1 +
 1 files changed, 1 insertions(+), 0 deletions(-)

diff --git a/scripts/migrate-pax b/scripts/migrate-pax
index 1460c71..429d45c 100755
--- a/scripts/migrate-pax
+++ b/scripts/migrate-pax
@@ -132,6 +132,7 @@ def main():
 
             if do_migration:
                 flags = re.sub('-','',flags)
+                if flags == 'e': continue # Don't create XATTR_PAX for default
                 pax.setstrflags(elf, flags)
 
             if do_deleteall:


^ permalink raw reply related	[flat|nested] 89+ messages in thread
* [gentoo-commits] proj/elfix:master commit in: scripts/
@ 2012-12-28 19:34 Anthony G. Basile
  0 siblings, 0 replies; 89+ messages in thread
From: Anthony G. Basile @ 2012-12-28 19:34 UTC (permalink / raw
  To: gentoo-commits

commit:     cc002a03de41cf12a9a7129c61a74499768bff45
Author:     Anthony G. Basile <blueness <AT> gentoo <DOT> org>
AuthorDate: Fri Dec 28 19:34:12 2012 +0000
Commit:     Anthony G. Basile <blueness <AT> gentoo <DOT> org>
CommitDate: Fri Dec 28 19:34:12 2012 +0000
URL:        http://git.overlays.gentoo.org/gitweb/?p=proj/elfix.git;a=commit;h=cc002a03

scripts/migrate-pax: use portage to read NEEDED.ELF.2

---
 scripts/migrate-pax |  281 ++++++++++++++++++++++++++-------------------------
 1 files changed, 143 insertions(+), 138 deletions(-)

diff --git a/scripts/migrate-pax b/scripts/migrate-pax
index 09a41e2..1460c71 100755
--- a/scripts/migrate-pax
+++ b/scripts/migrate-pax
@@ -1,160 +1,165 @@
 #!/usr/bin/env python
-
 #
-# Note: This alternative way of doing revdep-pax only
-# works on Gentoo systems where NEEDED.ELF.2 all the
-# information we need generated by scanelf during emerge.
+#    migrate-pax: this file is part of the elfix package
+#    Copyright (C) 2012  Anthony G. Basile
 #
-# See /usr/lib/portage/bin/misc-functions.sh ~line 520
-# echo "${arch:3};${obj};${soname};${rpath};${needed}" >> "${PORTAGE_BUILDDIR}"/build-info/NEEDED.ELF.2
+#    This program is free software: you can redistribute it and/or modify
+#    it under the terms of the GNU General Public License as published by
+#    the Free Software Foundation, either version 3 of the License, or
+#    (at your option) any later version.
 #
+#    This program is distributed in the hope that it will be useful,
+#    but WITHOUT ANY WARRANTY; without even the implied warranty of
+#    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+#    GNU General Public License for more details.
+#
+#    You should have received a copy of the GNU General Public License
+#    along with this program.  If not, see <http://www.gnu.org/licenses/>.
+
+
+# We use portage's NEEDED.ELF.2 file.  The format is in
+# /usr/lib/portage/bin/misc-functions.sh ~line 520
+# echo "${arch:3};${obj};${soname};${rpath};${needed}" >> "${PORTAGE_BUILDDIR}"/build-info/NEEDED.ELF.2
 
 import os
 import re
 import getopt
 import sys
 import pax
+import portage
+
+def get_objects():
 
-def get_object_needed():
+    vardb = portage.db[portage.root]["vartree"].dbapi
 
-	var_db_pkg = '/var/db/pkg'
+    objects = []
 
-	object_needed = {}
-	for cat in os.listdir(var_db_pkg):
-		catdir = '%s/%s' % (var_db_pkg, cat)
-		for pkg in os.listdir(catdir):
-			pkgdir = '%s/%s' % (catdir, pkg)
-			need = '%s/%s' % (pkgdir, 'NEEDED.ELF.2')
-			try:
-				g = open(need, 'r')
-				needs = g.readlines()
-				for line in needs:
-					line = line.strip()
-					link = re.split(';', line)
-					elf = link[1]
-					sonames = re.split(',', link[4])
-					object_needed[elf] = sonames
-			except IOError:
-				continue #File probably doesn't exist, which is okay
+    for pkg in vardb.cpv_all():
+        needed = vardb.aux_get(pkg, ['NEEDED.ELF.2'])[0].strip()
+        if not needed: # Some packages have no NEEDED.ELF.2
+            continue
+        for line in re.split('\n', needed):
+            link = re.split(';', line)
+            objects.append(link[1]) # link[1] is the ELF object
 
-	return object_needed
+    return objects
 
 
 def run_usage():
-	print('Package Name : elfix')
-	print('Bug Reports  : http://bugs.gentoo.org/')
-	print('Program Name : migrate')
-	print('Description  : Migrate PT_PAX to XATTR_PAX Flags on all system ELF objects')
-	print('')
-	print('Usage        : migrate -v        print out all system ELF objects')
-	print('             : migrate -m [-v]   migrate flags on all system ELF objects')
-	print('             : migrate -d [-v]   delete XATTR_PAX on all system ELF objects')
-	print('             : migrate [-h]      print out this help')
-	print('             : -v                be verbose when migrating')
-	print('')
+    print('Package Name : elfix')
+    print('Bug Reports  : http://bugs.gentoo.org/')
+    print('Program Name : migrate')
+    print('Description  : Migrate PT_PAX to XATTR_PAX Flags on all system ELF objects')
+    print('')
+    print('Usage        : migrate -v        print out all system ELF objects')
+    print('             : migrate -m [-v]   migrate flags on all system ELF objects')
+    print('             : migrate -d [-v]   delete XATTR_PAX on all system ELF objects')
+    print('             : migrate [-h]      print out this help')
+    print('             : -v                be verbose when migrating')
+    print('')
 
 
 def main():
-	# Are we root?
-	uid = os.getuid()
-	if uid != 0:
-		print('This program must be run as root')
-		sys.exit(1)
-
-	try:
-		opts, args = getopt.getopt(sys.argv[1:], 'vmdh')
-	except getopt.GetoptError as err:
-		print(str(err)) # will print something like 'option -a not recognized'
-		run_usage()
-		sys.exit(1)
-
-	verbose = False
-	do_migration = False
-	do_deleteall = False
-	do_usage = False
-
-	opt_count = 0
-
-	for o, a in opts:
-		if o == '-v':
-			verbose = True
-			opt_count += 1
-		elif o == '-m':
-			do_migration = True
-			opt_count += 1
-		elif o == '-d':
-			do_deleteall = True
-			opt_count += 1
-		elif o == '-h':
-			do_usage = True
-			opt_count += 1
-		else:
-			print('Option included in getopt but not handled here!')
-			print('Please file a bug')
-			sys.exit(1)
-
-	if do_usage:
-		run_usage()
-		sys.exit(0)
-
-	if opt_count == 0 or opt_count > 2 or ( do_migration and do_deleteall):
-		run_usage()
-		sys.exit(1)
-
-	# Do we have XATTR_PAX support?
-	if do_migration or do_deleteall:
-		try:
-			from pax import deletextpax
-		except ImportError:
-			print('ERROR: Python module pax.so was compiled without XATTR_PAX support, cannot migrate or delete XATTR_PAX')
-			sys.exit(1)
-
-	object_needed = get_object_needed()
-
-	fail = []
-	none = []
-
-	for elf in object_needed:
-		try:
-			flags = pax.getflags(elf)[0]
-			if flags:
-				if verbose:
-					print("%s %s" % (flags, elf))
-			else:
-				none.append(elf)
-				if verbose:
-					print("NONE: %s" % elf)
-
-			if do_migration:
-				flags = re.sub('-','',flags)
-				pax.setstrflags(elf, flags)
-
-			if do_deleteall:
-				pax.deletextpax(elf)
-
-		# We should never get here, because you can
-		# always getflags() via pax.so since you can
-		# read PT_PAX even from a busy text file, and
-		# you can always set the pax flags with pax.so
-		# even on a busy text file because it will skip
-		# setting PT_PAX and only set the XATTR_PAX
-		except pax.PaxError:
-			if uid == 0:
-				fail.append(elf)
-				if verbose:
-					print("FAIL: %s" % elf)
-
-	if verbose:
-		if fail:
-			print('\n')
-			print("ELF executables for which the migration failed:")
-			for elf in fail:
-				print("\t%s" % elf)
-		if none:
-			print('\n')
-			print("ELF executables lacking PT_PAX:")
-			for elf in none:
-				print("\t%s" % elf)
+    # Are we root?
+    uid = os.getuid()
+    if uid != 0:
+        print('This program must be run as root')
+        sys.exit(1)
+
+    try:
+        opts, args = getopt.getopt(sys.argv[1:], 'vmdh')
+    except getopt.GetoptError as err:
+        print(str(err)) # will print something like 'option -a not recognized'
+        run_usage()
+        sys.exit(1)
+
+    verbose = False
+    do_migration = False
+    do_deleteall = False
+    do_usage = False
+
+    opt_count = 0
+
+    for o, a in opts:
+        if o == '-v':
+            verbose = True
+            opt_count += 1
+        elif o == '-m':
+            do_migration = True
+            opt_count += 1
+        elif o == '-d':
+            do_deleteall = True
+            opt_count += 1
+        elif o == '-h':
+            do_usage = True
+            opt_count += 1
+        else:
+            print('Option included in getopt but not handled here!')
+            print('Please file a bug')
+            sys.exit(1)
+
+    if do_usage:
+        run_usage()
+        sys.exit(0)
+
+    if opt_count == 0 or opt_count > 2 or ( do_migration and do_deleteall):
+        run_usage()
+        sys.exit(1)
+
+    # Do we have XATTR_PAX support?
+    if do_migration or do_deleteall:
+        try:
+            from pax import deletextpax
+        except ImportError:
+            print('ERROR: Python module pax.so was compiled without XATTR_PAX support, cannot migrate or delete XATTR_PAX')
+            sys.exit(1)
+
+    objects = get_objects()
+
+    fail = []
+    none = []
+
+    for elf in objects:
+        try:
+            flags = pax.getflags(elf)[0]
+            if flags:
+                if verbose:
+                    print("%s %s" % (flags, elf))
+            else:
+                none.append(elf)
+                if verbose:
+                    print("NONE: %s" % elf)
+
+            if do_migration:
+                flags = re.sub('-','',flags)
+                pax.setstrflags(elf, flags)
+
+            if do_deleteall:
+                pax.deletextpax(elf)
+
+        # We should never get here, because you can
+        # always getflags() via pax.so since you can
+        # read PT_PAX even from a busy text file, and
+        # you can always set the pax flags with pax.so
+        # even on a busy text file because it will skip
+        # setting PT_PAX and only set the XATTR_PAX
+        except pax.PaxError:
+            if uid == 0:
+                fail.append(elf)
+                if verbose:
+                    print("FAIL: %s" % elf)
+
+    if verbose:
+        if fail:
+            print('\n')
+            print("ELF executables for which the migration failed:")
+            for elf in fail:
+                print("\t%s" % elf)
+        if none:
+            print('\n')
+            print("ELF executables lacking PT_PAX:")
+            for elf in none:
+                print("\t%s" % elf)
 
 if __name__ == '__main__':
-	main()
+    main()


^ permalink raw reply related	[flat|nested] 89+ messages in thread
* [gentoo-commits] proj/elfix:master commit in: scripts/
@ 2012-12-23  3:49 Anthony G. Basile
  0 siblings, 0 replies; 89+ messages in thread
From: Anthony G. Basile @ 2012-12-23  3:49 UTC (permalink / raw
  To: gentoo-commits

commit:     38d458a4ca02f218dbb4d292007368209c635625
Author:     Anthony G. Basile <blueness <AT> gentoo <DOT> org>
AuthorDate: Sun Dec 23 01:04:04 2012 +0000
Commit:     Anthony G. Basile <blueness <AT> gentoo <DOT> org>
CommitDate: Sun Dec 23 03:48:39 2012 +0000
URL:        http://git.overlays.gentoo.org/gitweb/?p=proj/elfix.git;a=commit;h=38d458a4

scripts/paxmodule.c: throw a PaxError when pax_getflags or set_xt_flags

---
 scripts/paxmodule.c |   17 +++++++++++++++--
 1 files changed, 15 insertions(+), 2 deletions(-)

diff --git a/scripts/paxmodule.c b/scripts/paxmodule.c
index 469e0cb..f77dabb 100644
--- a/scripts/paxmodule.c
+++ b/scripts/paxmodule.c
@@ -328,7 +328,13 @@ pax_getflags(PyObject *self, PyObject *args)
 
 	close(fd);
 
-	return Py_BuildValue("si", buf, flags);
+	if( flags == UINT16_MAX )
+	{
+		PyErr_SetString(PaxError, "pax_getflags: no PAX flags found");
+		return NULL;
+	}
+	else
+		return Py_BuildValue("si", buf, flags);
 }
 
 
@@ -488,7 +494,14 @@ set_xt_flags(int fd, uint16_t xt_flags)
 
 	memset(buf, 0, FLAGS_SIZE);
 	bin2string(xt_flags, buf);
-	fsetxattr(fd, PAX_NAMESPACE, buf, strlen(buf), 0);
+
+	if( fsetxattr(fd, PAX_NAMESPACE, buf, strlen(buf), 0))
+	{
+		PyErr_SetString(PaxError, "pax_deletextpax: fremovexattr() failed");
+		return;
+	}
+	else
+		return;
 }
 #endif
 


^ permalink raw reply related	[flat|nested] 89+ messages in thread
* [gentoo-commits] proj/elfix:master commit in: scripts/
@ 2012-12-23  2:36 Anthony G. Basile
  0 siblings, 0 replies; 89+ messages in thread
From: Anthony G. Basile @ 2012-12-23  2:36 UTC (permalink / raw
  To: gentoo-commits

commit:     69e05d04bd4796d67f6d9d89cbe2110e0679da58
Author:     Anthony G. Basile <blueness <AT> gentoo <DOT> org>
AuthorDate: Sun Dec 23 01:04:04 2012 +0000
Commit:     Anthony G. Basile <blueness <AT> gentoo <DOT> org>
CommitDate: Sun Dec 23 02:35:54 2012 +0000
URL:        http://git.overlays.gentoo.org/gitweb/?p=proj/elfix.git;a=commit;h=69e05d04

scripts/paxmodule.c: throw a PaxError when pax_getflags or set_xt_flags

---
 scripts/paxmodule.c |   17 +++++++++++++++--
 1 files changed, 15 insertions(+), 2 deletions(-)

diff --git a/scripts/paxmodule.c b/scripts/paxmodule.c
index 469e0cb..f77dabb 100644
--- a/scripts/paxmodule.c
+++ b/scripts/paxmodule.c
@@ -328,7 +328,13 @@ pax_getflags(PyObject *self, PyObject *args)
 
 	close(fd);
 
-	return Py_BuildValue("si", buf, flags);
+	if( flags == UINT16_MAX )
+	{
+		PyErr_SetString(PaxError, "pax_getflags: no PAX flags found");
+		return NULL;
+	}
+	else
+		return Py_BuildValue("si", buf, flags);
 }
 
 
@@ -488,7 +494,14 @@ set_xt_flags(int fd, uint16_t xt_flags)
 
 	memset(buf, 0, FLAGS_SIZE);
 	bin2string(xt_flags, buf);
-	fsetxattr(fd, PAX_NAMESPACE, buf, strlen(buf), 0);
+
+	if( fsetxattr(fd, PAX_NAMESPACE, buf, strlen(buf), 0))
+	{
+		PyErr_SetString(PaxError, "pax_deletextpax: fremovexattr() failed");
+		return;
+	}
+	else
+		return;
 }
 #endif
 


^ permalink raw reply related	[flat|nested] 89+ messages in thread
* [gentoo-commits] proj/elfix:master commit in: scripts/
@ 2012-12-23  1:04 Anthony G. Basile
  0 siblings, 0 replies; 89+ messages in thread
From: Anthony G. Basile @ 2012-12-23  1:04 UTC (permalink / raw
  To: gentoo-commits

commit:     20d4eca613ae2f51a35138bcbe4127746fdc4d32
Author:     Anthony G. Basile <blueness <AT> gentoo <DOT> org>
AuthorDate: Sun Dec 23 01:04:04 2012 +0000
Commit:     Anthony G. Basile <blueness <AT> gentoo <DOT> org>
CommitDate: Sun Dec 23 01:04:04 2012 +0000
URL:        http://git.overlays.gentoo.org/gitweb/?p=proj/elfix.git;a=commit;h=20d4eca6

scripts/paxmodule.c: throw a PaxError when pax_getflags or set_xt_flags

---
 scripts/paxmodule.c |   17 +++++++++++++++--
 1 files changed, 15 insertions(+), 2 deletions(-)

diff --git a/scripts/paxmodule.c b/scripts/paxmodule.c
index 469e0cb..f77dabb 100644
--- a/scripts/paxmodule.c
+++ b/scripts/paxmodule.c
@@ -328,7 +328,13 @@ pax_getflags(PyObject *self, PyObject *args)
 
 	close(fd);
 
-	return Py_BuildValue("si", buf, flags);
+	if( flags == UINT16_MAX )
+	{
+		PyErr_SetString(PaxError, "pax_getflags: no PAX flags found");
+		return NULL;
+	}
+	else
+		return Py_BuildValue("si", buf, flags);
 }
 
 
@@ -488,7 +494,14 @@ set_xt_flags(int fd, uint16_t xt_flags)
 
 	memset(buf, 0, FLAGS_SIZE);
 	bin2string(xt_flags, buf);
-	fsetxattr(fd, PAX_NAMESPACE, buf, strlen(buf), 0);
+
+	if( fsetxattr(fd, PAX_NAMESPACE, buf, strlen(buf), 0))
+	{
+		PyErr_SetString(PaxError, "pax_deletextpax: fremovexattr() failed");
+		return;
+	}
+	else
+		return;
 }
 #endif
 


^ permalink raw reply related	[flat|nested] 89+ messages in thread
* [gentoo-commits] proj/elfix:master commit in: scripts/
@ 2012-12-22 22:20 Anthony G. Basile
  0 siblings, 0 replies; 89+ messages in thread
From: Anthony G. Basile @ 2012-12-22 22:20 UTC (permalink / raw
  To: gentoo-commits

commit:     6142ff60fa04002dfab85e1499ff5adc7c5a03f4
Author:     Anthony G. Basile <blueness <AT> gentoo <DOT> org>
AuthorDate: Sat Dec 22 22:20:36 2012 +0000
Commit:     Anthony G. Basile <blueness <AT> gentoo <DOT> org>
CommitDate: Sat Dec 22 22:20:36 2012 +0000
URL:        http://git.overlays.gentoo.org/gitweb/?p=proj/elfix.git;a=commit;h=6142ff60

scripts/paxmodule.c: add important close(fd) in deletextpax()

---
 scripts/migrate-pax |    2 +-
 scripts/paxmodule.c |    4 ++++
 2 files changed, 5 insertions(+), 1 deletions(-)

diff --git a/scripts/migrate-pax b/scripts/migrate-pax
index d5bc03a..1d5c2f7 100755
--- a/scripts/migrate-pax
+++ b/scripts/migrate-pax
@@ -78,7 +78,7 @@ def main():
 			opt_count += 1
 		elif o == '-d':
 			do_deleteall = True
-			opt_cout += 1
+			opt_count += 1
 		elif o == '-h':
 			do_usage = True
 			opt_count += 1

diff --git a/scripts/paxmodule.c b/scripts/paxmodule.c
index 26d00ce..469e0cb 100644
--- a/scripts/paxmodule.c
+++ b/scripts/paxmodule.c
@@ -665,9 +665,13 @@ pax_deletextpax(PyObject *self, PyObject *args)
 	}
 
 	if( !fremovexattr(fd, PAX_NAMESPACE) )
+	{
+		close(fd);
 		return Py_BuildValue("");
+	}
 	else
 	{
+		close(fd);
 		PyErr_SetString(PaxError, "pax_deletextpax: fremovexattr() failed");
 		return NULL;
 	}


^ permalink raw reply related	[flat|nested] 89+ messages in thread
* [gentoo-commits] proj/elfix:master commit in: scripts/
@ 2012-12-22 20:17 Anthony G. Basile
  0 siblings, 0 replies; 89+ messages in thread
From: Anthony G. Basile @ 2012-12-22 20:17 UTC (permalink / raw
  To: gentoo-commits

commit:     d2e3a668071b95273c8a7d7f21370a2417b1b748
Author:     Anthony G. Basile <blueness <AT> gentoo <DOT> org>
AuthorDate: Sat Dec 22 20:17:47 2012 +0000
Commit:     Anthony G. Basile <blueness <AT> gentoo <DOT> org>
CommitDate: Sat Dec 22 20:17:47 2012 +0000
URL:        http://git.overlays.gentoo.org/gitweb/?p=proj/elfix.git;a=commit;h=d2e3a668

scripts/migrate-pax: add delete XATTR_PAX on all system ELF objects

---
 scripts/migrate-pax |   31 ++++++++++++++++++++++++++-----
 1 files changed, 26 insertions(+), 5 deletions(-)

diff --git a/scripts/migrate-pax b/scripts/migrate-pax
index e30c306..d5bc03a 100755
--- a/scripts/migrate-pax
+++ b/scripts/migrate-pax
@@ -48,6 +48,7 @@ def run_usage():
 	print('')
 	print('Usage        : migrate -v        print out all system ELF objects')
 	print('             : migrate -m [-v]   migrate flags on all system ELF objects')
+	print('             : migrate -d [-v]   delete XATTR_PAX on all system ELF objects')
 	print('             : migrate [-h]      print out this help')
 	print('             : -v                be verbose when migrating')
 	print('')
@@ -55,15 +56,15 @@ def run_usage():
 
 def main():
 	try:
-		opts, args = getopt.getopt(sys.argv[1:], 'mv')
+		opts, args = getopt.getopt(sys.argv[1:], 'vmdh')
 	except getopt.GetoptError as err:
 		print(str(err)) # will print something like 'option -a not recognized'
 		run_usage()
 		sys.exit(1)
 
-
 	verbose = False
 	do_migration = False
+	do_deleteall = False
 	do_usage = False
 
 	opt_count = 0
@@ -75,6 +76,9 @@ def main():
 		elif o == '-m':
 			do_migration = True
 			opt_count += 1
+		elif o == '-d':
+			do_deleteall = True
+			opt_cout += 1
 		elif o == '-h':
 			do_usage = True
 			opt_count += 1
@@ -83,14 +87,27 @@ def main():
 			print('Please file a bug')
 			sys.exit(1)
 
-	if opt_count == 0 or do_usage:
+	if do_usage:
 		run_usage()
 		sys.exit(0)
 
+	if opt_count == 0 or opt_count > 2 or ( do_migration and do_deleteall):
+		run_usage()
+		sys.exit(1)
+
+	# Are we root?
 	uid = os.getuid()
 	if uid != 0 and do_migration:
 		print('RUN AS ROOT: cannot migrate flags')
-		sys.exit(0)
+		sys.exit(1)
+
+	# Do we have XATTR_PAX support?
+	if do_migration or do_deleteall:
+		try:
+			from pax import deletextpax
+		except ImportError:
+			print('ERROR: Python module pax.so was compiled without XATTR_PAX support, cannot migrate or delete XATTR_PAX')
+			sys.exit(1)
 
 	object_needed = get_object_needed()
 
@@ -99,6 +116,7 @@ def main():
 
 	for elf in object_needed:
 		try:
+			flags = pax.getflags(elf)[0]
 			if flags:
 				if verbose:
 					print("%s %s" % (flags, elf))
@@ -106,11 +124,14 @@ def main():
 				none.append(elf)
 				if verbose:
 					print("NONE: %s" % elf)
+
 			if do_migration:
-				flags = pax.getflags(elf)[0]
 				flags = re.sub('-','',flags)
 				pax.setstrflags(elf, flags)
 
+			if do_deleteall:
+				pax.deletextpax(elf)
+
 		# We should never get here, because you can
 		# always getflags() via pax.so since you can
 		# read PT_PAX even from a busy text file, and


^ permalink raw reply related	[flat|nested] 89+ messages in thread
* [gentoo-commits] proj/elfix:master commit in: scripts/
@ 2012-12-22 19:42 Anthony G. Basile
  0 siblings, 0 replies; 89+ messages in thread
From: Anthony G. Basile @ 2012-12-22 19:42 UTC (permalink / raw
  To: gentoo-commits

commit:     54b0d098b92fa6e240a920a05032b2bf1694cabf
Author:     Anthony G. Basile <blueness <AT> gentoo <DOT> org>
AuthorDate: Sat Dec 22 19:42:51 2012 +0000
Commit:     Anthony G. Basile <blueness <AT> gentoo <DOT> org>
CommitDate: Sat Dec 22 19:42:51 2012 +0000
URL:        http://git.overlays.gentoo.org/gitweb/?p=proj/elfix.git;a=commit;h=54b0d098

scripts/paxmodule.c: rename pax.error -> pax.PaxError

---
 scripts/migrate-pax |    2 +-
 scripts/paxmodule.c |    4 ++--
 scripts/pypaxctl    |    2 +-
 scripts/revdep-pax  |   16 ++++++++--------
 4 files changed, 12 insertions(+), 12 deletions(-)

diff --git a/scripts/migrate-pax b/scripts/migrate-pax
index 5e46292..e30c306 100755
--- a/scripts/migrate-pax
+++ b/scripts/migrate-pax
@@ -117,7 +117,7 @@ def main():
 		# you can always set the pax flags with pax.so
 		# even on a busy text file because it will skip
 		# setting PT_PAX and only set the XATTR_PAX
-		except pax.error:
+		except pax.PaxError:
 			if uid == 0:
 				fail.append(elf)
 				if verbose:

diff --git a/scripts/paxmodule.c b/scripts/paxmodule.c
index 14a7dcc..26d00ce 100644
--- a/scripts/paxmodule.c
+++ b/scripts/paxmodule.c
@@ -103,9 +103,9 @@ initpax(void)
 	if (m == NULL)
 		return;
 
-	PaxError = PyErr_NewException("pax.error", NULL, NULL);
+	PaxError = PyErr_NewException("pax.PaxError", NULL, NULL);
 	Py_INCREF(PaxError);
-	PyModule_AddObject(m, "error", PaxError);
+	PyModule_AddObject(m, "PaxError", PaxError);
 
 #if PY_MAJOR_VERSION >= 3
 	return m;

diff --git a/scripts/pypaxctl b/scripts/pypaxctl
index 8cba7a7..0e8f3fe 100755
--- a/scripts/pypaxctl
+++ b/scripts/pypaxctl
@@ -77,7 +77,7 @@ def main():
 			for elf in args:
 				try:
 					pax.deletextpax(elf)
-				except pax.error:
+				except pax.PaxError:
 					print('pax_deletextpax: XATTR_PAX not supported')
 					sys.exit(1)
 

diff --git a/scripts/revdep-pax b/scripts/revdep-pax
index 3ac5d2d..4bb3f36 100755
--- a/scripts/revdep-pax
+++ b/scripts/revdep-pax
@@ -103,7 +103,7 @@ def print_forward_linkings( forward_linkings, so2library_mappings, verbose ):
 			( binary_str_flags, binary_bin_flags ) = pax.getflags(binary)
 			sv = '%s ( %s )\n' % ( binary, binary_str_flags )
 			s = sv
-		except pax.error:
+		except pax.PaxError:
 			missing_binaries.append(binary)
 			continue
 
@@ -116,7 +116,7 @@ def print_forward_linkings( forward_linkings, so2library_mappings, verbose ):
 				if binary_str_flags != library_str_flags:
 					s = '%s\n\t%s\t%s ( %s )' % ( s, soname, library, library_str_flags )
 					count = count + 1
-			except pax.error:
+			except pax.PaxError:
 				missing_links.append(soname)
 
 		if verbose:
@@ -151,7 +151,7 @@ def print_reverse_linkings( reverse_linkings, so2library_mappings, verbose, exec
 			( library_str_flags, library_bin_flags ) = pax.getflags(library)
 			sv = '%s\t%s ( %s )\n' % ( soname, library, library_str_flags )
 			s = sv
-		except pax.error:
+		except pax.PaxError:
 			missing_sonames.append(soname)
 			continue
 
@@ -170,7 +170,7 @@ def print_reverse_linkings( reverse_linkings, so2library_mappings, verbose, exec
 					if library_str_flags != binary_str_flags:
 						s = '%s\n\t%s ( %s )' % ( s, binary, binary_str_flags )
 						count = count + 1
-			except pax.error:
+			except pax.PaxError:
 				missing_links.append(binary)
 
 		if verbose:
@@ -275,7 +275,7 @@ def run_binary(binary, verbose, mark, allyes):
 				mismatched_libraries.append(library)
 				if not verbose:
 					print('\t%s\t%s ( %s )' % ( soname, library, library_str_flags ))
-		except pax.error:
+		except pax.PaxError:
 			print('file for soname %s not found' % soname)
 
 	if len(mismatched_libraries) == 0:
@@ -304,7 +304,7 @@ def run_binary(binary, verbose, mark, allyes):
 				if do_marking:
 					try:
 						migrate_flags(library, binary_str_flags, binary_bin_flags)
-					except pax.error:
+					except pax.PaxError:
 						print("\n\tCould not set pax flags on %s, file is probably busy" % library)
 						print("\tShut down all processes that use it and try again")
 					( library_str_flags, library_bin_flags ) = pax.getflags(library)
@@ -365,7 +365,7 @@ def run_soname(name, verbose, use_soname, mark, allyes, executable_only):
 					mismatched_binaries.append(binary)
 					if not verbose:
 						print('\t%s ( %s )' % ( binary, binary_str_flags ))
-		except pax.error:
+		except pax.PaxError:
 			print('cannot obtain pax flags for %s' % binary)
 
 	if len(mismatched_binaries) == 0:
@@ -396,7 +396,7 @@ def run_soname(name, verbose, use_soname, mark, allyes, executable_only):
 				if do_marking:
 					try:
 						migrate_flags(binary, library_str_flags, library_bin_flags)
-					except pax.error:
+					except pax.PaxError:
 						print('\n\tCould not set pax flags on %s, file is probably busy' % binary)
 						print('\tShut down all processes that use it and try again')
 					( binary_str_flags, binary_bin_flags ) = pax.getflags(binary)


^ permalink raw reply related	[flat|nested] 89+ messages in thread
* [gentoo-commits] proj/elfix:master commit in: scripts/
@ 2012-12-22 19:29 Anthony G. Basile
  0 siblings, 0 replies; 89+ messages in thread
From: Anthony G. Basile @ 2012-12-22 19:29 UTC (permalink / raw
  To: gentoo-commits

commit:     1de593d0e2f0bcdfd7e0cc7a7bcc4daf2af89471
Author:     Anthony G. Basile <blueness <AT> gentoo <DOT> org>
AuthorDate: Sat Dec 22 19:29:39 2012 +0000
Commit:     Anthony G. Basile <blueness <AT> gentoo <DOT> org>
CommitDate: Sat Dec 22 19:29:39 2012 +0000
URL:        http://git.overlays.gentoo.org/gitweb/?p=proj/elfix.git;a=commit;h=1de593d0

scripts/{paxmodule.c,pypaxctl}: rename deleteflags -> deletextpax

---
 scripts/paxmodule.c |   12 ++++++------
 scripts/pypaxctl    |    6 +++---
 2 files changed, 9 insertions(+), 9 deletions(-)

diff --git a/scripts/paxmodule.c b/scripts/paxmodule.c
index 3e335b4..14a7dcc 100644
--- a/scripts/paxmodule.c
+++ b/scripts/paxmodule.c
@@ -56,7 +56,7 @@ static PyObject * pax_getflags(PyObject *, PyObject *);
 static PyObject * pax_setbinflags(PyObject *, PyObject *);
 static PyObject * pax_setstrflags(PyObject *, PyObject *);
 #ifdef XTPAX
-static PyObject * pax_deleteflags(PyObject *, PyObject *);
+static PyObject * pax_deletextpax(PyObject *, PyObject *);
 #endif
 
 static PyMethodDef PaxMethods[] = {
@@ -64,7 +64,7 @@ static PyMethodDef PaxMethods[] = {
 	{"setbinflags",  pax_setbinflags, METH_VARARGS, "Set the pax flags using binary."},
 	{"setstrflags",  pax_setstrflags, METH_VARARGS, "Set the pax flags using string."},
 #ifdef XTPAX
-	{"deleteflags",  pax_deleteflags, METH_VARARGS, "Delete the XATTR_PAX field."},
+	{"deletextpax",  pax_deletextpax, METH_VARARGS, "Delete the XATTR_PAX field."},
 #endif
 	{NULL, NULL, 0, NULL}
 };
@@ -647,20 +647,20 @@ pax_setstrflags(PyObject *self, PyObject *args)
 
 #ifdef XTPAX
 static PyObject *
-pax_deleteflags(PyObject *self, PyObject *args)
+pax_deletextpax(PyObject *self, PyObject *args)
 {
 	const char *f_name;
 	int fd;
 
 	if(!PyArg_ParseTuple(args, "s", &f_name))
 	{
-		PyErr_SetString(PaxError, "pax_deleteflags: PyArg_ParseTuple failed");
+		PyErr_SetString(PaxError, "pax_deletextpax: PyArg_ParseTuple failed");
 		return NULL;
 	}
 
 	if((fd = open(f_name, O_RDONLY)) < 0)
 	{
-		PyErr_SetString(PaxError, "pax_deleteflags: open() failed");
+		PyErr_SetString(PaxError, "pax_deletextpax: open() failed");
 		return NULL;
 	}
 
@@ -668,7 +668,7 @@ pax_deleteflags(PyObject *self, PyObject *args)
 		return Py_BuildValue("");
 	else
 	{
-		PyErr_SetString(PaxError, "pax_deleteflags: fremovexattr() failed");
+		PyErr_SetString(PaxError, "pax_deletextpax: fremovexattr() failed");
 		return NULL;
 	}
 }

diff --git a/scripts/pypaxctl b/scripts/pypaxctl
index 809d074..8cba7a7 100755
--- a/scripts/pypaxctl
+++ b/scripts/pypaxctl
@@ -24,7 +24,7 @@ import pax
 
 xattr_available = True
 try:
-	from pax import deleteflags
+	from pax import deletextpax
 except ImportError:
 	xattr_available = False
 
@@ -76,9 +76,9 @@ def main():
 		else:
 			for elf in args:
 				try:
-					pax.deleteflags(elf)
+					pax.deletextpax(elf)
 				except pax.error:
-					print('pax_deleteflags: XATTR_PAX not supported')
+					print('pax_deletextpax: XATTR_PAX not supported')
 					sys.exit(1)
 
 if __name__ == '__main__':


^ permalink raw reply related	[flat|nested] 89+ messages in thread
* [gentoo-commits] proj/elfix:master commit in: scripts/
@ 2012-12-22 19:02 Anthony G. Basile
  0 siblings, 0 replies; 89+ messages in thread
From: Anthony G. Basile @ 2012-12-22 19:02 UTC (permalink / raw
  To: gentoo-commits

commit:     f996aa44031bb23e073c0b15d95d0c81298d0140
Author:     Anthony G. Basile <blueness <AT> gentoo <DOT> org>
AuthorDate: Sat Dec 22 19:02:46 2012 +0000
Commit:     Anthony G. Basile <blueness <AT> gentoo <DOT> org>
CommitDate: Sat Dec 22 19:02:46 2012 +0000
URL:        http://git.overlays.gentoo.org/gitweb/?p=proj/elfix.git;a=commit;h=f996aa44

scripts/pypaxctl: make aware if XATTR_PAX support is available in pax.so

---
 scripts/paxmodule.c |    6 +++-
 scripts/pypaxctl    |   70 +++++++++++++++++++++++++++------------------------
 2 files changed, 42 insertions(+), 34 deletions(-)

diff --git a/scripts/paxmodule.c b/scripts/paxmodule.c
index 9d7e4e0..3e335b4 100644
--- a/scripts/paxmodule.c
+++ b/scripts/paxmodule.c
@@ -650,8 +650,9 @@ static PyObject *
 pax_deleteflags(PyObject *self, PyObject *args)
 {
 	const char *f_name;
+	int fd;
 
-	if(!PyArg_ParseTuple(args, "s", &f_names))
+	if(!PyArg_ParseTuple(args, "s", &f_name))
 	{
 		PyErr_SetString(PaxError, "pax_deleteflags: PyArg_ParseTuple failed");
 		return NULL;
@@ -666,6 +667,9 @@ pax_deleteflags(PyObject *self, PyObject *args)
 	if( !fremovexattr(fd, PAX_NAMESPACE) )
 		return Py_BuildValue("");
 	else
+	{
+		PyErr_SetString(PaxError, "pax_deleteflags: fremovexattr() failed");
 		return NULL;
+	}
 }
 #endif

diff --git a/scripts/pypaxctl b/scripts/pypaxctl
index 6734e36..809d074 100755
--- a/scripts/pypaxctl
+++ b/scripts/pypaxctl
@@ -22,24 +22,38 @@ import sys
 import getopt
 import pax
 
+xattr_available = True
+try:
+	from pax import deleteflags
+except ImportError:
+	xattr_available = False
+
 def run_usage():
 	print('Package Name : elfix')
 	print('Bug Reports  : http://bugs.gentoo.org/')
 	print('Program Name : pypaxctl')
-	print('Description  : Get/set/delete PT_PAX or XATTR_PAX flags on an ELF object')
-	print('')
-	print('Usage        : pypaxctl -g ELF                get XATTR_PAX flags first, else get PT_PAX flags')
-	print('             : pypaxctl -s [-PpEeMmRrSs] ELF  set PT_PAX and XATTR_PAX flags whenever possible')
-	print('             : pypaxctl -d ELF                delete the XATTR_PAX field')
-	print('')
-	print('Note         : If the pax.so module is compiled without PT_PAX or XATTR_PAX, then no operation will')
-	print('             : be done on that field.  Note -d is not available unless XATTR_PAX support is present')
+	if xattr_available:
+		print('Description  : Get/set/delete PT_PAX or XATTR_PAX flags on an ELF object')
+		print('')
+		print('Usage        : pypaxctl -g ELF                get XATTR_PAX flags first, else get PT_PAX flags')
+		print('             : pypaxctl -s [-PpEeMmRrSs] ELF  set PT_PAX and XATTR_PAX flags whenever possible')
+		print('             : pypaxctl -d ELF                delete the XATTR_PAX field')
+	else:
+		print('Description  : Get/set PT_PAX flags on an ELF object')
+		print('')
+		print('Usage        : pypaxctl -g ELF                get PT_PAX flags')
+		print('             : pypaxctl -s [-PpEeMmRrSs] ELF  set PT_PAX flags whenever possible')
+		print('')
+		print('Note         : Python module pax.so was compiled without XATTR_PAX support')
 	print('')
 
 
 def main():
 	try:
-		opts, args = getopt.getopt(sys.argv[1:], 'gs:d')
+		if xattr_available:
+			opts, args = getopt.getopt(sys.argv[1:], 'gs:d')
+		else:
+			opts, args = getopt.getopt(sys.argv[1:], 'gs:')
 	except getopt.GetoptError as err:
 		print(err)
 		sys.exit(1)
@@ -48,34 +62,24 @@ def main():
 		run_usage()
 		sys.exit(1)
 
-	elf = None
-	do_get = False
-	do_set = False
-	do_del = False
-
 	for o, a in opts:
 		if o == '-g':
-			do_get = True
+			for elf in args:
+				( str_flags, bin_flags ) = pax.getflags(elf)
+				print('%s' % str_flags)
 		elif o == '-s':
-			flags = a
-			do_set = True
-		else:
-			do_del = True
+			for elf in args:
+				pax.setstrflags(elf, a)
 
-	if( do_get ):
-		for elf in args:
-			( str_flags, bin_flags ) = pax.getflags(elf)
-			print('%s' % str_flags)
-	elif( do_set ):
-		for elf in args:
-			pax.setstrflags(elf, flags)
-	else:
-		for elf in args:
-			try:
-				pax.deleteflags(elf)
-			except pax.error:
-				print('pax_deleteflags: XATTR_PAX not supported')
-				sys.exit(1)
+		# Don't worry if xattr_available = False
+		# because we can't get here if it is.
+		else:
+			for elf in args:
+				try:
+					pax.deleteflags(elf)
+				except pax.error:
+					print('pax_deleteflags: XATTR_PAX not supported')
+					sys.exit(1)
 
 if __name__ == '__main__':
 	main()


^ permalink raw reply related	[flat|nested] 89+ messages in thread
* [gentoo-commits] proj/elfix:master commit in: scripts/
@ 2012-12-22 18:31 Anthony G. Basile
  0 siblings, 0 replies; 89+ messages in thread
From: Anthony G. Basile @ 2012-12-22 18:31 UTC (permalink / raw
  To: gentoo-commits

commit:     53efaf7be4922c9dd494fafd91accb56a84a3fbc
Author:     Anthony G. Basile <blueness <AT> gentoo <DOT> org>
AuthorDate: Sat Dec 22 18:31:37 2012 +0000
Commit:     Anthony G. Basile <blueness <AT> gentoo <DOT> org>
CommitDate: Sat Dec 22 18:31:37 2012 +0000
URL:        http://git.overlays.gentoo.org/gitweb/?p=proj/elfix.git;a=commit;h=53efaf7b

scripts/{paxmodule.c,pypaxctl}: add delete XATTR_PAX field

---
 scripts/paxmodule.c |   50 +++++++++++++++++++++++++++++++-------
 scripts/pypaxctl    |   66 +++++++++++++++++++++++++++++++-------------------
 2 files changed, 82 insertions(+), 34 deletions(-)

diff --git a/scripts/paxmodule.c b/scripts/paxmodule.c
index 1001279..9d7e4e0 100644
--- a/scripts/paxmodule.c
+++ b/scripts/paxmodule.c
@@ -55,25 +55,31 @@
 static PyObject * pax_getflags(PyObject *, PyObject *);
 static PyObject * pax_setbinflags(PyObject *, PyObject *);
 static PyObject * pax_setstrflags(PyObject *, PyObject *);
+#ifdef XTPAX
+static PyObject * pax_deleteflags(PyObject *, PyObject *);
+#endif
 
 static PyMethodDef PaxMethods[] = {
-	{"getflags",  pax_getflags, METH_VARARGS, "Get the pax flags as a string."},
+	{"getflags",     pax_getflags,    METH_VARARGS, "Get the pax flags as a string."},
 	{"setbinflags",  pax_setbinflags, METH_VARARGS, "Set the pax flags using binary."},
 	{"setstrflags",  pax_setstrflags, METH_VARARGS, "Set the pax flags using string."},
+#ifdef XTPAX
+	{"deleteflags",  pax_deleteflags, METH_VARARGS, "Delete the XATTR_PAX field."},
+#endif
 	{NULL, NULL, 0, NULL}
 };
 
 #if PY_MAJOR_VERSION >= 3
     static struct PyModuleDef moduledef = {
         PyModuleDef_HEAD_INIT,
-        "pax",							/* m_name */
-        "Module for get/setting PT_PAX and XATTR_PAX flags",	/* m_doc */
-        -1,							/* m_size */
-        PaxMethods,						/* m_methods */
-        NULL,							/* m_reload */
-        NULL,							/* m_traverse */
-        NULL,							/* m_clear */
-        NULL,							/* m_free */
+        "pax",								/* m_name */
+        "Module for get/set/deleting PT_PAX and XATTR_PAX flags",	/* m_doc */
+        -1,								/* m_size */
+        PaxMethods,							/* m_methods */
+        NULL,								/* m_reload */
+        NULL,								/* m_traverse */
+        NULL,								/* m_clear */
+        NULL,								/* m_free */
     };
 #endif
 
@@ -637,3 +643,29 @@ pax_setstrflags(PyObject *self, PyObject *args)
 
 	return Py_BuildValue("");
 }
+
+
+#ifdef XTPAX
+static PyObject *
+pax_deleteflags(PyObject *self, PyObject *args)
+{
+	const char *f_name;
+
+	if(!PyArg_ParseTuple(args, "s", &f_names))
+	{
+		PyErr_SetString(PaxError, "pax_deleteflags: PyArg_ParseTuple failed");
+		return NULL;
+	}
+
+	if((fd = open(f_name, O_RDONLY)) < 0)
+	{
+		PyErr_SetString(PaxError, "pax_deleteflags: open() failed");
+		return NULL;
+	}
+
+	if( !fremovexattr(fd, PAX_NAMESPACE) )
+		return Py_BuildValue("");
+	else
+		return NULL;
+}
+#endif

diff --git a/scripts/pypaxctl b/scripts/pypaxctl
index 8edf61e..6734e36 100755
--- a/scripts/pypaxctl
+++ b/scripts/pypaxctl
@@ -22,44 +22,60 @@ import sys
 import getopt
 import pax
 
+def run_usage():
+	print('Package Name : elfix')
+	print('Bug Reports  : http://bugs.gentoo.org/')
+	print('Program Name : pypaxctl')
+	print('Description  : Get/set/delete PT_PAX or XATTR_PAX flags on an ELF object')
+	print('')
+	print('Usage        : pypaxctl -g ELF                get XATTR_PAX flags first, else get PT_PAX flags')
+	print('             : pypaxctl -s [-PpEeMmRrSs] ELF  set PT_PAX and XATTR_PAX flags whenever possible')
+	print('             : pypaxctl -d ELF                delete the XATTR_PAX field')
+	print('')
+	print('Note         : If the pax.so module is compiled without PT_PAX or XATTR_PAX, then no operation will')
+	print('             : be done on that field.  Note -d is not available unless XATTR_PAX support is present')
+	print('')
+
+
 def main():
 	try:
-		opts, args = getopt.getopt(sys.argv[1:], 's:g')
+		opts, args = getopt.getopt(sys.argv[1:], 'gs:d')
 	except getopt.GetoptError as err:
 		print(err)
 		sys.exit(1)
 
-	if len(opts) == 0:
-		print('Provide either -s <flags> <elf> xor -g <elf>')
+	if( len(opts) != 1 or len(args) < 1 ):
+		run_usage()
 		sys.exit(1)
 
-	binary = None
-
-	do_set = 0
-	do_get = 0
+	elf = None
+	do_get = False
+	do_set = False
+	do_del = False
 
 	for o, a in opts:
-		if o == '-s':
+		if o == '-g':
+			do_get = True
+		elif o == '-s':
 			flags = a
-			do_set = 1
-		elif o == '-g':
-			do_get = 1
-
-	if( (do_set + do_get) != 1 ):
-		print('Provide either -s <flags> <elf> xor -g <elf>')
-		sys.exit(1)
+			do_set = True
+		else:
+			do_del = True
 
-	if( len(args) < 1 ):
-		print('Provide either -s <flags> <elf> xor -g <elf>')
-		sys.exit(1)
-
-	if( do_set == 1 ):
-		for binary in args:
-			pax.setstrflags(binary, flags)
-	else:
-		for binary in args:
-			( str_flags, bin_flags ) = pax.getflags(binary)
+	if( do_get ):
+		for elf in args:
+			( str_flags, bin_flags ) = pax.getflags(elf)
 			print('%s' % str_flags)
+	elif( do_set ):
+		for elf in args:
+			pax.setstrflags(elf, flags)
+	else:
+		for elf in args:
+			try:
+				pax.deleteflags(elf)
+			except pax.error:
+				print('pax_deleteflags: XATTR_PAX not supported')
+				sys.exit(1)
 
 if __name__ == '__main__':
 	main()


^ permalink raw reply related	[flat|nested] 89+ messages in thread
* [gentoo-commits] proj/elfix:master commit in: scripts/
@ 2012-12-22 16:36 Anthony G. Basile
  0 siblings, 0 replies; 89+ messages in thread
From: Anthony G. Basile @ 2012-12-22 16:36 UTC (permalink / raw
  To: gentoo-commits

commit:     bacc78e6ae30f411c5bb6c433af760b2ee7127a9
Author:     Anthony G. Basile <blueness <AT> gentoo <DOT> org>
AuthorDate: Sat Dec 22 16:36:30 2012 +0000
Commit:     Anthony G. Basile <blueness <AT> gentoo <DOT> org>
CommitDate: Sat Dec 22 16:36:30 2012 +0000
URL:        http://git.overlays.gentoo.org/gitweb/?p=proj/elfix.git;a=commit;h=bacc78e6

scripts/migrate-pax: rename functions in line with misc/alt-revdep-pax

---
 scripts/migrate-pax |   17 +++++++++--------
 1 files changed, 9 insertions(+), 8 deletions(-)

diff --git a/scripts/migrate-pax b/scripts/migrate-pax
index 994d4f7..5e46292 100755
--- a/scripts/migrate-pax
+++ b/scripts/migrate-pax
@@ -15,10 +15,11 @@ import getopt
 import sys
 import pax
 
-def get_forward_linkings():
+def get_object_needed():
+
 	var_db_pkg = '/var/db/pkg'
 
-	forward_linkings = {}
+	object_needed = {}
 	for cat in os.listdir(var_db_pkg):
 		catdir = '%s/%s' % (var_db_pkg, cat)
 		for pkg in os.listdir(catdir):
@@ -32,11 +33,11 @@ def get_forward_linkings():
 					link = re.split(';', line)
 					elf = link[1]
 					sonames = re.split(',', link[4])
-					forward_linkings[elf] = sonames
+					object_needed[elf] = sonames
 			except IOError:
 				continue #File probably doesn't exist, which is okay
 
-	return forward_linkings
+	return object_needed
 
 
 def run_usage():
@@ -91,14 +92,13 @@ def main():
 		print('RUN AS ROOT: cannot migrate flags')
 		sys.exit(0)
 
-	forward_linkings = get_forward_linkings()
+	object_needed = get_object_needed()
 
 	fail = []
 	none = []
 
-	for elf in forward_linkings:
+	for elf in object_needed:
 		try:
-			flags = pax.getflags(elf)[0]
 			if flags:
 				if verbose:
 					print("%s %s" % (flags, elf))
@@ -107,6 +107,7 @@ def main():
 				if verbose:
 					print("NONE: %s" % elf)
 			if do_migration:
+				flags = pax.getflags(elf)[0]
 				flags = re.sub('-','',flags)
 				pax.setstrflags(elf, flags)
 
@@ -120,7 +121,7 @@ def main():
 			if uid == 0:
 				fail.append(elf)
 				if verbose:
-					print("BUSY: %s" % elf)
+					print("FAIL: %s" % elf)
 
 	if verbose:
 		if fail:


^ permalink raw reply related	[flat|nested] 89+ messages in thread
* [gentoo-commits] proj/elfix:master commit in: scripts/
@ 2012-12-22  1:04 Anthony G. Basile
  0 siblings, 0 replies; 89+ messages in thread
From: Anthony G. Basile @ 2012-12-22  1:04 UTC (permalink / raw
  To: gentoo-commits

commit:     220a448d3295c7e3dfa00e4c70e1eb787460c29d
Author:     Anthony G. Basile <blueness <AT> gentoo <DOT> org>
AuthorDate: Sat Dec 22 01:04:30 2012 +0000
Commit:     Anthony G. Basile <blueness <AT> gentoo <DOT> org>
CommitDate: Sat Dec 22 01:04:30 2012 +0000
URL:        http://git.overlays.gentoo.org/gitweb/?p=proj/elfix.git;a=commit;h=220a448d

scripts/Makefile.am: install pypaxctl

---
 scripts/Makefile.am |    4 ++--
 1 files changed, 2 insertions(+), 2 deletions(-)

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


^ permalink raw reply related	[flat|nested] 89+ messages in thread
* [gentoo-commits] proj/elfix:master commit in: scripts/
@ 2012-12-20  4:26 Anthony G. Basile
  0 siblings, 0 replies; 89+ messages in thread
From: Anthony G. Basile @ 2012-12-20  4:26 UTC (permalink / raw
  To: gentoo-commits

commit:     9adf6cb49c3631858ec2b68029089fb952c023e2
Author:     Anthony G. Basile <blueness <AT> gentoo <DOT> org>
AuthorDate: Thu Dec 20 04:25:54 2012 +0000
Commit:     Anthony G. Basile <blueness <AT> gentoo <DOT> org>
CommitDate: Thu Dec 20 04:25:54 2012 +0000
URL:        http://git.overlays.gentoo.org/gitweb/?p=proj/elfix.git;a=commit;h=9adf6cb4

scripts/{migrate-pax,revdep-pax}: fix print in python2/3

---
 scripts/migrate-pax |    4 ++--
 scripts/revdep-pax  |    4 ++--
 2 files changed, 4 insertions(+), 4 deletions(-)

diff --git a/scripts/migrate-pax b/scripts/migrate-pax
index 154f8fa..994d4f7 100755
--- a/scripts/migrate-pax
+++ b/scripts/migrate-pax
@@ -44,12 +44,12 @@ def run_usage():
 	print('Bug Reports  : http://bugs.gentoo.org/')
 	print('Program Name : migrate')
 	print('Description  : Migrate PT_PAX to XATTR_PAX Flags on all system ELF objects')
-	print(),
+	print('')
 	print('Usage        : migrate -v        print out all system ELF objects')
 	print('             : migrate -m [-v]   migrate flags on all system ELF objects')
 	print('             : migrate [-h]      print out this help')
 	print('             : -v                be verbose when migrating')
-	print()
+	print('')
 
 
 def main():

diff --git a/scripts/revdep-pax b/scripts/revdep-pax
index 0116971..3ac5d2d 100755
--- a/scripts/revdep-pax
+++ b/scripts/revdep-pax
@@ -408,7 +408,7 @@ def run_usage():
 	print('Bug Reports  : http://bugs.gentoo.org/')
 	print('Program Name : revdep-pax')
 	print('Description  : Get or set pax flags on an ELF object')
-	print('\n'),
+	print('')
 	print('Usage        : revdep-pax -f [-v]             print out all forward mappings for all system binaries')
 	print('             : revdep-pax -r [-ve]            print out all reverse mappings for all system sonames')
 	print('             : revdep-pax -b OBJECT  [-myv]   print all forward mappings only for OBJECT')
@@ -419,7 +419,7 @@ def run_usage():
 	print('             : -e                             only print out executables in shell $PATH')
 	print('             : -m                             don\'t just report, but mark the mismatching objects')
 	print('             : -y                             assume "yes" to all prompts for marking (USE CAREFULLY!)')
-	print('\n'),
+	print('')
 
 
 def main():


^ permalink raw reply related	[flat|nested] 89+ messages in thread
* [gentoo-commits] proj/elfix:master commit in: scripts/
@ 2012-12-19  4:09 Anthony G. Basile
  0 siblings, 0 replies; 89+ messages in thread
From: Anthony G. Basile @ 2012-12-19  4:09 UTC (permalink / raw
  To: gentoo-commits

commit:     c7550a3a9b24116077ad73ae32cf0362eff12e89
Author:     Anthony G. Basile <blueness <AT> gentoo <DOT> org>
AuthorDate: Wed Dec 19 04:09:24 2012 +0000
Commit:     Anthony G. Basile <blueness <AT> gentoo <DOT> org>
CommitDate: Wed Dec 19 04:09:24 2012 +0000
URL:        http://git.overlays.gentoo.org/gitweb/?p=proj/elfix.git;a=commit;h=c7550a3a

scripts/migrate-pax: rename and add to Makefile installs

---
 scripts/Makefile.am              |    2 +-
 scripts/{migrate => migrate-pax} |    0
 2 files changed, 1 insertions(+), 1 deletions(-)

diff --git a/scripts/Makefile.am b/scripts/Makefile.am
index 9ecc3b8..9f36bdd 100644
--- a/scripts/Makefile.am
+++ b/scripts/Makefile.am
@@ -1,4 +1,4 @@
 ACLOCAL_AMFLAGS = -I m4
 
-dist_sbin_SCRIPTS = revdep-pax
+dist_sbin_SCRIPTS = migrate-pax revdep-pax
 EXTRA_DIST = paxmodule.c setup.py pypaxctl

diff --git a/scripts/migrate b/scripts/migrate-pax
similarity index 100%
rename from scripts/migrate
rename to scripts/migrate-pax


^ permalink raw reply related	[flat|nested] 89+ messages in thread
* [gentoo-commits] proj/elfix:master commit in: scripts/
@ 2012-12-19  3:51 Anthony G. Basile
  0 siblings, 0 replies; 89+ messages in thread
From: Anthony G. Basile @ 2012-12-19  3:51 UTC (permalink / raw
  To: gentoo-commits

commit:     b56be49809d3dc882149d5b9a6d39fba1796d19a
Author:     Anthony G. Basile <blueness <AT> gentoo <DOT> org>
AuthorDate: Wed Dec 19 03:51:01 2012 +0000
Commit:     Anthony G. Basile <blueness <AT> gentoo <DOT> org>
CommitDate: Wed Dec 19 03:51:01 2012 +0000
URL:        http://git.overlays.gentoo.org/gitweb/?p=proj/elfix.git;a=commit;h=b56be498

scripts/migrate: migration script from PT_PAX to XATTR_PAX flags

---
 scripts/migrate |  138 +++++++++++++++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 138 insertions(+), 0 deletions(-)

diff --git a/scripts/migrate b/scripts/migrate
new file mode 100755
index 0000000..154f8fa
--- /dev/null
+++ b/scripts/migrate
@@ -0,0 +1,138 @@
+#!/usr/bin/env python
+
+#
+# Note: This alternative way of doing revdep-pax only
+# works on Gentoo systems where NEEDED.ELF.2 all the
+# information we need generated by scanelf during emerge.
+#
+# See /usr/lib/portage/bin/misc-functions.sh ~line 520
+# echo "${arch:3};${obj};${soname};${rpath};${needed}" >> "${PORTAGE_BUILDDIR}"/build-info/NEEDED.ELF.2
+#
+
+import os
+import re
+import getopt
+import sys
+import pax
+
+def get_forward_linkings():
+	var_db_pkg = '/var/db/pkg'
+
+	forward_linkings = {}
+	for cat in os.listdir(var_db_pkg):
+		catdir = '%s/%s' % (var_db_pkg, cat)
+		for pkg in os.listdir(catdir):
+			pkgdir = '%s/%s' % (catdir, pkg)
+			need = '%s/%s' % (pkgdir, 'NEEDED.ELF.2')
+			try:
+				g = open(need, 'r')
+				needs = g.readlines()
+				for line in needs:
+					line = line.strip()
+					link = re.split(';', line)
+					elf = link[1]
+					sonames = re.split(',', link[4])
+					forward_linkings[elf] = sonames
+			except IOError:
+				continue #File probably doesn't exist, which is okay
+
+	return forward_linkings
+
+
+def run_usage():
+	print('Package Name : elfix')
+	print('Bug Reports  : http://bugs.gentoo.org/')
+	print('Program Name : migrate')
+	print('Description  : Migrate PT_PAX to XATTR_PAX Flags on all system ELF objects')
+	print(),
+	print('Usage        : migrate -v        print out all system ELF objects')
+	print('             : migrate -m [-v]   migrate flags on all system ELF objects')
+	print('             : migrate [-h]      print out this help')
+	print('             : -v                be verbose when migrating')
+	print()
+
+
+def main():
+	try:
+		opts, args = getopt.getopt(sys.argv[1:], 'mv')
+	except getopt.GetoptError as err:
+		print(str(err)) # will print something like 'option -a not recognized'
+		run_usage()
+		sys.exit(1)
+
+
+	verbose = False
+	do_migration = False
+	do_usage = False
+
+	opt_count = 0
+
+	for o, a in opts:
+		if o == '-v':
+			verbose = True
+			opt_count += 1
+		elif o == '-m':
+			do_migration = True
+			opt_count += 1
+		elif o == '-h':
+			do_usage = True
+			opt_count += 1
+		else:
+			print('Option included in getopt but not handled here!')
+			print('Please file a bug')
+			sys.exit(1)
+
+	if opt_count == 0 or do_usage:
+		run_usage()
+		sys.exit(0)
+
+	uid = os.getuid()
+	if uid != 0 and do_migration:
+		print('RUN AS ROOT: cannot migrate flags')
+		sys.exit(0)
+
+	forward_linkings = get_forward_linkings()
+
+	fail = []
+	none = []
+
+	for elf in forward_linkings:
+		try:
+			flags = pax.getflags(elf)[0]
+			if flags:
+				if verbose:
+					print("%s %s" % (flags, elf))
+			else:
+				none.append(elf)
+				if verbose:
+					print("NONE: %s" % elf)
+			if do_migration:
+				flags = re.sub('-','',flags)
+				pax.setstrflags(elf, flags)
+
+		# We should never get here, because you can
+		# always getflags() via pax.so since you can
+		# read PT_PAX even from a busy text file, and
+		# you can always set the pax flags with pax.so
+		# even on a busy text file because it will skip
+		# setting PT_PAX and only set the XATTR_PAX
+		except pax.error:
+			if uid == 0:
+				fail.append(elf)
+				if verbose:
+					print("BUSY: %s" % elf)
+
+	if verbose:
+		if fail:
+			print('\n')
+			print("ELF executables for which the migration failed:")
+			for elf in fail:
+				print("\t%s" % elf)
+		if none:
+			print('\n')
+			print("ELF executables lacking PT_PAX:")
+			for elf in none:
+				print("\t%s" % elf)
+
+if __name__ == '__main__':
+	main()


^ permalink raw reply related	[flat|nested] 89+ messages in thread
* [gentoo-commits] proj/elfix:master commit in: scripts/
@ 2012-12-15 20:03 Anthony G. Basile
  0 siblings, 0 replies; 89+ messages in thread
From: Anthony G. Basile @ 2012-12-15 20:03 UTC (permalink / raw
  To: gentoo-commits

commit:     b7ba4e91d13b546a6b5fb6e44b9d3ac465fb9141
Author:     Anthony G. Basile <blueness <AT> gentoo <DOT> org>
AuthorDate: Sat Dec 15 20:03:23 2012 +0000
Commit:     Anthony G. Basile <blueness <AT> gentoo <DOT> org>
CommitDate: Sat Dec 15 20:03:23 2012 +0000
URL:        http://git.overlays.gentoo.org/gitweb/?p=proj/elfix.git;a=commit;h=b7ba4e91

scripts/revdep-pax: clean up flag exporter/importer logic

---
 scripts/revdep-pax |   51 ++++++++++++++++++++++-----------------------------
 1 files changed, 22 insertions(+), 29 deletions(-)

diff --git a/scripts/revdep-pax b/scripts/revdep-pax
index 9a990a2..8626e95 100755
--- a/scripts/revdep-pax
+++ b/scripts/revdep-pax
@@ -189,27 +189,19 @@ def run_reverse(verbose, executable_only):
 
 def migrate_flags(importer, exporter_str_flags, exporter_bin_flags):
 	# We implement the following logic for setting the pax flags
-	# on the target elf object, the 'importer', given that the
-	# flags from the elf object we want it to match to, the exporter.
+	# on the target elf object, the IMPORTER, given that the flags
+	# from the elf object we want it to match to, the EXPORTER.
 	#
-	#	Importer	Exporter	Result
-	#	Force On	Force On	Force On
-	#	Force On	Force Off	Force On + Warn
-	#	Force On	Nothing		Force On
-	#	Force Off	Force On	Force Off + Warn
-	#	Force Off	Force Off	Force Off
-	#	Force Off	Nothing		Force Off
-	#	Nothing		Force On	Force On
-	#	Nothing		Force Off	Force Off
-	#	Nothing		Nothing		Nothing
-	#
-	# The algorithm proceeds by assuming the resulting flags = the exporter
-	# flags and then changes them in cases where that's not what we want, ie
-	#
-	#	Force On        Force Off       Force On + Warn
-	#	Force On        Nothing         Force On
-	#	Force Off       Force On        Force Off + Warn
-	#	Force Off       Nothing         Force Off
+	#	EXPORTER	IMPORTER	RESULT
+	#	   On		   On		   On
+	#	   On		   Off		   On + Warn
+	#	   On		   -		   On
+	#	   Off		   On		   On + Warn
+	#	   Off		   Off		   Off
+	#	   Off		   -		   Off
+	#	   -		   On		   On
+	#	   -		   Off		   Off
+	#	   -		   -		   -
 
 	#See /usr/include/elf.h for these values
 	pf_flags = {
@@ -223,22 +215,23 @@ def migrate_flags(importer, exporter_str_flags, exporter_bin_flags):
 
 	( importer_str_flags, importer_bin_flags ) = pax.getflags(importer)
 
+	# Start with the exporter's flags
 	result_bin_flags = exporter_bin_flags
 
 	for i in range(len(importer_str_flags)):
-		if importer_str_flags[i].isupper() and exporter_str_flags[i].islower():
-			result_bin_flags = result_bin_flags ^ pf_flags[exporter_str_flags[i]]
-			result_bin_flags = result_bin_flags | pf_flags[importer_str_flags[i]]
-			print('\t\tWarning: %s has %s, refusing to set to %s' % (
-				importer, importer_str_flags[i], exporter_str_flags[i] )),
-		if importer_str_flags[i].isupper() and exporter_str_flags[i] == '-':
-			result_bin_flags = result_bin_flags | pf_flags[importer_str_flags[i]]
-		if importer_str_flags[i].islower() and exporter_str_flags[i].isupper():
+
+		# The exporter's flag contradicts the importer's flag, so do nothing
+		if (exporter_str_flags[i].isupper() and importer_str_flags[i].islower()) or \
+		   (exporter_str_flags[i].islower() and importer_str_flags[i].isupper()):
+
+			# Revert the exporter's flag, use the importer's flag and warn
 			result_bin_flags = result_bin_flags ^ pf_flags[exporter_str_flags[i]]
 			result_bin_flags = result_bin_flags | pf_flags[importer_str_flags[i]]
 			print('\t\tWarning: %s has %s, refusing to set to %s' % (
 				importer, importer_str_flags[i], exporter_str_flags[i] )),
-		if importer_str_flags[i].islower() and exporter_str_flags[i] == '-':
+
+		# The exporter's flags is off, so use the importer's flag
+		if (exporter_str_flags[i] == '-' and importer_str_flags[i] != '-'):
 			result_bin_flags = result_bin_flags | pf_flags[importer_str_flags[i]]
 
 	pax.setbinflags(importer, result_bin_flags)


^ permalink raw reply related	[flat|nested] 89+ messages in thread
* [gentoo-commits] proj/elfix:master commit in: scripts/
@ 2012-12-14  2:19 Anthony G. Basile
  0 siblings, 0 replies; 89+ messages in thread
From: Anthony G. Basile @ 2012-12-14  2:19 UTC (permalink / raw
  To: gentoo-commits

commit:     73a50ec221d5152722e95fc8e46900605554e64d
Author:     Anthony G. Basile <blueness <AT> gentoo <DOT> org>
AuthorDate: Fri Dec 14 02:16:06 2012 +0000
Commit:     Anthony G. Basile <blueness <AT> gentoo <DOT> org>
CommitDate: Fri Dec 14 02:19:41 2012 +0000
URL:        http://git.overlays.gentoo.org/gitweb/?p=proj/elfix.git;a=commit;h=73a50ec2

scripts/paxmodule.c: adopt the parse_cmd_args() logic of paxctl-ng.c

---
 scripts/paxmodule.c |   51 ++++++++++++++++++++++++++++++++++++++++++++++++++-
 1 files changed, 50 insertions(+), 1 deletions(-)

diff --git a/scripts/paxmodule.c b/scripts/paxmodule.c
index 40450ac..57c9ce1 100644
--- a/scripts/paxmodule.c
+++ b/scripts/paxmodule.c
@@ -538,6 +538,55 @@ pax_setbinflags(PyObject *self, PyObject *args)
 	return Py_BuildValue("");
 }
 
+
+//This logic is like parse_cmd_args() in paxctl-ng.c
+uint16_t
+parse_sflags(char *sflags)
+{
+	int i;
+	uint16_t flags = 0;
+
+	for(i = 0; i < strlen(sflags); i++)
+	{
+		switch(sflags[i])
+		{
+			case 'P':
+				flags |= PF_PAGEEXEC;
+				break;
+			case 'p':
+				flags |= PF_NOPAGEEXEC;
+				break ;
+			case 'E':
+				flags |= PF_EMUTRAMP;
+				break;
+			case 'e':
+				flags |= PF_NOEMUTRAMP;
+				break ;
+			case 'M':
+				flags |= PF_MPROTECT;
+				break;
+			case 'm':
+				flags |= PF_NOMPROTECT;
+				break ;
+			case 'R':
+				flags |= PF_RANDMMAP;
+				break;
+			case 'r':
+				flags |= PF_NORANDMMAP;
+				break ;
+			case 'S':
+				flags |= PF_SEGMEXEC;
+				break;
+			case 's':
+				flags |= PF_NOSEGMEXEC;
+				break ;
+		}
+	}
+
+	return flags;
+}
+
+
 static PyObject *
 pax_setstrflags(PyObject *self, PyObject *args)
 {
@@ -563,7 +612,7 @@ pax_setstrflags(PyObject *self, PyObject *args)
 		}
 	}
 
-	flags = string2bin(sflags);
+	flags = parse_sflags(sflags);
 
 #ifdef PTPAX
 	if(rdwr_pt_pax)


^ permalink raw reply related	[flat|nested] 89+ messages in thread
* [gentoo-commits] proj/elfix:master commit in: scripts/
@ 2012-12-14  2:16 Anthony G. Basile
  0 siblings, 0 replies; 89+ messages in thread
From: Anthony G. Basile @ 2012-12-14  2:16 UTC (permalink / raw
  To: gentoo-commits

commit:     17c54593d58d59a6ab5899b197b3e1a30071f9c6
Author:     Anthony G. Basile <blueness <AT> gentoo <DOT> org>
AuthorDate: Fri Dec 14 02:16:06 2012 +0000
Commit:     Anthony G. Basile <blueness <AT> gentoo <DOT> org>
CommitDate: Fri Dec 14 02:16:06 2012 +0000
URL:        http://git.overlays.gentoo.org/gitweb/?p=proj/elfix.git;a=commit;h=17c54593

scripts/paxmodule.c: adopt the parse_cmd_args() logic of paxctl-ng.c

---
 scripts/paxmodule.c |   51 ++++++++++++++++++++++++++++++++++++++++++++++++++-
 1 files changed, 50 insertions(+), 1 deletions(-)

diff --git a/scripts/paxmodule.c b/scripts/paxmodule.c
index 40450ac..93feca3 100644
--- a/scripts/paxmodule.c
+++ b/scripts/paxmodule.c
@@ -538,6 +538,55 @@ pax_setbinflags(PyObject *self, PyObject *args)
 	return Py_BuildValue("");
 }
 
+
+//This logic is like parse_cmd_args() in paxctl-ng.c
+uint16_t
+parse_sflags(char *sflags)
+{
+	int i;
+	uint16_t flags = 0;
+
+	for(i = 0; i < strlen(sflags); i++)
+	{
+		switch(sflags[i])
+		{
+			case 'P':
+				flags |= PF_PAGEEXEC;
+				break;
+			case 'p':
+				flags |= PF_NOPAGEEXEC;
+				break ;
+			case 'E':
+				flags |= PF_EMUTRAMP;
+				break;
+			case 'e':
+				flags |= PF_NOEMUTRAMP;
+				break ;
+			case 'M':
+				flags |= PF_MPROTECT;
+				break;
+			case 'm':
+				flags |= PF_NOMPROTECT;
+				break ;
+			case 'R':
+				flags |= PF_RANDMMAP;
+				break;
+			case 'r':
+				flags |= PF_NORANDMMAP;
+				break ;
+			case 'S':
+				flags |= PF_SEGMEXEC;
+				break;
+			case 's':
+				flags |= PF_NOSEGMEXEC;
+				break ;
+		}
+	}
+
+	return flags;
+}
+
+
 static PyObject *
 pax_setstrflags(PyObject *self, PyObject *args)
 {
@@ -563,7 +612,7 @@ pax_setstrflags(PyObject *self, PyObject *args)
 		}
 	}
 
-	flags = string2bin(sflags);
+	flags = prase_sflags(sflags);
 
 #ifdef PTPAX
 	if(rdwr_pt_pax)


^ permalink raw reply related	[flat|nested] 89+ messages in thread
* [gentoo-commits] proj/elfix:master commit in: scripts/
@ 2012-12-14  2:04 Anthony G. Basile
  0 siblings, 0 replies; 89+ messages in thread
From: Anthony G. Basile @ 2012-12-14  2:04 UTC (permalink / raw
  To: gentoo-commits

commit:     1a8460260f46c235d5d475f299bbcdc0dab3249d
Author:     Anthony G. Basile <blueness <AT> gentoo <DOT> org>
AuthorDate: Fri Dec 14 01:19:56 2012 +0000
Commit:     Anthony G. Basile <blueness <AT> gentoo <DOT> org>
CommitDate: Fri Dec 14 02:04:05 2012 +0000
URL:        http://git.overlays.gentoo.org/gitweb/?p=proj/elfix.git;a=commit;h=1a846026

scripts/paxmodule.c: adopt the update_flags() logic of paxctl-ng.c

---
 scripts/paxmodule.c |  152 ++++++++++++++++++++++++++++++++++++++++++++++----
 1 files changed, 139 insertions(+), 13 deletions(-)

diff --git a/scripts/paxmodule.c b/scripts/paxmodule.c
index 422d193..40450ac 100644
--- a/scripts/paxmodule.c
+++ b/scripts/paxmodule.c
@@ -326,6 +326,98 @@ pax_getflags(PyObject *self, PyObject *args)
 }
 
 
+uint16_t
+update_flags(uint16_t oflags, uint16_t flags)
+{
+	//PAGEEXEC
+	if(flags & PF_PAGEEXEC)
+	{
+		oflags |= PF_PAGEEXEC;
+		oflags &= ~PF_NOPAGEEXEC;
+	}
+	if(flags & PF_NOPAGEEXEC)
+	{
+		oflags &= ~PF_PAGEEXEC;
+		oflags |= PF_NOPAGEEXEC;
+	}
+	if((flags & PF_PAGEEXEC) && (flags & PF_NOPAGEEXEC))
+	{
+		oflags &= ~PF_PAGEEXEC;
+		oflags &= ~PF_NOPAGEEXEC;
+	}
+
+	//EMUTRAMP
+	if(flags & PF_EMUTRAMP)
+	{
+		oflags |= PF_EMUTRAMP;
+		oflags &= ~PF_NOEMUTRAMP;
+	}
+	if(flags & PF_NOEMUTRAMP)
+	{
+		oflags &= ~PF_EMUTRAMP;
+		oflags |= PF_NOEMUTRAMP;
+	}
+	if((flags & PF_EMUTRAMP) && (flags & PF_NOEMUTRAMP))
+	{
+		oflags &= ~PF_EMUTRAMP;
+		oflags &= ~PF_NOEMUTRAMP;
+	}
+
+	//MPROTECT
+	if(flags & PF_MPROTECT)
+	{
+		oflags |= PF_MPROTECT;
+		oflags &= ~PF_NOMPROTECT;
+	}
+	if(flags & PF_NOMPROTECT)
+	{
+		oflags &= ~PF_MPROTECT;
+		oflags |= PF_NOMPROTECT;
+	}
+	if((flags & PF_MPROTECT) && (flags & PF_NOMPROTECT))
+	{
+		oflags &= ~PF_MPROTECT;
+		oflags &= ~PF_NOMPROTECT;
+	}
+
+	//RANDMMAP
+	if(flags & PF_RANDMMAP)
+	{
+		oflags |= PF_RANDMMAP;
+		oflags &= ~PF_NORANDMMAP;
+	}
+	if(flags & PF_NORANDMMAP)
+	{
+		oflags &= ~PF_RANDMMAP;
+		oflags |= PF_NORANDMMAP;
+	}
+	if((flags & PF_RANDMMAP) && (flags & PF_NORANDMMAP))
+	{
+		oflags &= ~PF_RANDMMAP;
+		oflags &= ~PF_NORANDMMAP;
+	}
+
+	//SEGMEXEC
+	if(flags & PF_SEGMEXEC)
+	{
+		oflags |= PF_SEGMEXEC;
+		oflags &= ~PF_NOSEGMEXEC;
+	}
+	if(flags & PF_NOSEGMEXEC)
+	{
+		oflags &= ~PF_SEGMEXEC;
+		oflags |= PF_NOSEGMEXEC;
+	}
+	if((flags & PF_SEGMEXEC) && (flags & PF_NOSEGMEXEC))
+	{
+		oflags &= ~PF_SEGMEXEC;
+		oflags &= ~PF_NOSEGMEXEC;
+	}
+
+	return oflags;
+}
+
+
 #ifdef PTPAX
 void
 set_pt_flags(int fd, uint16_t pt_flags)
@@ -399,8 +491,8 @@ static PyObject *
 pax_setbinflags(PyObject *self, PyObject *args)
 {
 	const char *f_name;
-	int fd, iflags;
-	uint16_t flags;
+	int fd, iflags, rdwr_pt_pax = 1;
+	uint16_t oflags, nflags, flags;
 
 	if (!PyArg_ParseTuple(args, "si", &f_name, &iflags))
 	{
@@ -410,18 +502,35 @@ pax_setbinflags(PyObject *self, PyObject *args)
 
 	if((fd = open(f_name, O_RDWR)) < 0)
 	{
-		PyErr_SetString(PaxError, "pax_setbinflags: open() failed");
-		return NULL;
+#ifdef PTPAX
+		rdwr_pt_pax = 0;
+#endif
+		if((fd = open(f_name, O_RDONLY)) < 0)
+		{
+			PyErr_SetString(PaxError, "pax_setbinflags: open() failed");
+			return NULL;
+		}
 	}
 
 	flags = (uint16_t) iflags;
 
 #ifdef PTPAX
-	set_pt_flags(fd, flags);
+	if(rdwr_pt_pax)
+	{
+		oflags = get_pt_flags(fd);
+		if( oflags == UINT16_MAX )
+			oflags = PF_NOEMUTRAMP ;
+		nflags = update_flags( oflags, flags);
+		set_pt_flags(fd, nflags);
+        }
 #endif
 
 #ifdef XTPAX
-	set_xt_flags(fd, flags);
+	oflags = get_xt_flags(fd);
+	if( oflags == UINT16_MAX )
+		oflags = PF_NOEMUTRAMP ;
+	nflags = update_flags( oflags, flags);
+	set_xt_flags(fd, nflags);
 #endif
 
 	close(fd);
@@ -433,29 +542,46 @@ static PyObject *
 pax_setstrflags(PyObject *self, PyObject *args)
 {
 	char *f_name, *sflags;
-	int fd;
-	uint16_t flags;
+	int fd, rdwr_pt_pax = 1;
+	uint16_t oflags, nflags, flags;
 
 	if (!PyArg_ParseTuple(args, "ss", &f_name, &sflags))
 	{
-		PyErr_SetString(PaxError, "pax_setbinflags: PyArg_ParseTuple failed");
+		PyErr_SetString(PaxError, "pax_setstrflags: PyArg_ParseTuple failed");
 		return NULL;
 	}
 
 	if((fd = open(f_name, O_RDWR)) < 0)
 	{
-		PyErr_SetString(PaxError, "pax_setbinflags: open() failed");
-		return NULL;
+#ifdef PTPAX
+		rdwr_pt_pax = 0;
+#endif
+		if((fd = open(f_name, O_RDONLY)) < 0)
+		{
+			PyErr_SetString(PaxError, "pax_setstrflags: open() failed");
+			return NULL;
+		}
 	}
 
 	flags = string2bin(sflags);
 
 #ifdef PTPAX
-	set_pt_flags(fd, flags);
+	if(rdwr_pt_pax)
+	{
+		oflags = get_pt_flags(fd);
+		if( oflags == UINT16_MAX )
+			oflags = PF_NOEMUTRAMP ;
+		nflags = update_flags( oflags, flags);
+		set_pt_flags(fd, nflags);
+	}
 #endif
 
 #ifdef XTPAX
-	set_xt_flags(fd, flags);
+	oflags = get_xt_flags(fd);
+	if( oflags == UINT16_MAX )
+		oflags = PF_NOEMUTRAMP ;
+	nflags = update_flags( oflags, flags);
+	set_xt_flags(fd, nflags);
 #endif
 
 	close(fd);


^ permalink raw reply related	[flat|nested] 89+ messages in thread
* [gentoo-commits] proj/elfix:master commit in: scripts/
@ 2012-12-14  1:59 Anthony G. Basile
  0 siblings, 0 replies; 89+ messages in thread
From: Anthony G. Basile @ 2012-12-14  1:59 UTC (permalink / raw
  To: gentoo-commits

commit:     3a9cd84b861b4f224d2800f9024a44b30550e378
Author:     Anthony G. Basile <blueness <AT> gentoo <DOT> org>
AuthorDate: Fri Dec 14 01:19:56 2012 +0000
Commit:     Anthony G. Basile <blueness <AT> gentoo <DOT> org>
CommitDate: Fri Dec 14 01:58:52 2012 +0000
URL:        http://git.overlays.gentoo.org/gitweb/?p=proj/elfix.git;a=commit;h=3a9cd84b

scripts/paxmodule.c: adopt the update_flags() logic of paxctl-ng.c

---
 scripts/paxmodule.c |  148 +++++++++++++++++++++++++++++++++++++++++++++++----
 1 files changed, 137 insertions(+), 11 deletions(-)

diff --git a/scripts/paxmodule.c b/scripts/paxmodule.c
index 422d193..0198a93 100644
--- a/scripts/paxmodule.c
+++ b/scripts/paxmodule.c
@@ -326,6 +326,98 @@ pax_getflags(PyObject *self, PyObject *args)
 }
 
 
+uint16_t
+update_flags(uint16_t oflags, uint16_t flags)
+{
+	//PAGEEXEC
+	if(flags & PF_PAGEEXEC)
+	{
+		oflags |= PF_PAGEEXEC;
+		oflags &= ~PF_NOPAGEEXEC;
+	}
+	if(flags & PF_NOPAGEEXEC)
+	{
+		oflags &= ~PF_PAGEEXEC;
+		oflags |= PF_NOPAGEEXEC;
+	}
+	if((flags & PF_PAGEEXEC) && (flags & PF_NOPAGEEXEC))
+	{
+		oflags &= ~PF_PAGEEXEC;
+		oflags &= ~PF_NOPAGEEXEC;
+	}
+
+	//EMUTRAMP
+	if(flags & PF_EMUTRAMP)
+	{
+		oflags |= PF_EMUTRAMP;
+		oflags &= ~PF_NOEMUTRAMP;
+	}
+	if(flags & PF_NOEMUTRAMP)
+	{
+		oflags &= ~PF_EMUTRAMP;
+		oflags |= PF_NOEMUTRAMP;
+	}
+	if((flags & PF_EMUTRAMP) && (flags & PF_NOEMUTRAMP))
+	{
+		oflags &= ~PF_EMUTRAMP;
+		oflags &= ~PF_NOEMUTRAMP;
+	}
+
+	//MPROTECT
+	if(flags & PF_MPROTECT)
+	{
+		oflags |= PF_MPROTECT;
+		oflags &= ~PF_NOMPROTECT;
+	}
+	if(flags & PF_NOMPROTECT)
+	{
+		oflags &= ~PF_MPROTECT;
+		oflags |= PF_NOMPROTECT;
+	}
+	if((flags & PF_MPROTECT) && (flags & PF_NOMPROTECT))
+	{
+		oflags &= ~PF_MPROTECT;
+		oflags &= ~PF_NOMPROTECT;
+	}
+
+	//RANDMMAP
+	if(flags & PF_RANDMMAP)
+	{
+		oflags |= PF_RANDMMAP;
+		oflags &= ~PF_NORANDMMAP;
+	}
+	if(flags & PF_NORANDMMAP)
+	{
+		oflags &= ~PF_RANDMMAP;
+		oflags |= PF_NORANDMMAP;
+	}
+	if((flags & PF_RANDMMAP) && (flags & PF_NORANDMMAP))
+	{
+		oflags &= ~PF_RANDMMAP;
+		oflags &= ~PF_NORANDMMAP;
+	}
+
+	//SEGMEXEC
+	if(flags & PF_SEGMEXEC)
+	{
+		oflags |= PF_SEGMEXEC;
+		oflags &= ~PF_NOSEGMEXEC;
+	}
+	if(flags & PF_NOSEGMEXEC)
+	{
+		oflags &= ~PF_SEGMEXEC;
+		oflags |= PF_NOSEGMEXEC;
+	}
+	if((flags & PF_SEGMEXEC) && (flags & PF_NOSEGMEXEC))
+	{
+		oflags &= ~PF_SEGMEXEC;
+		oflags &= ~PF_NOSEGMEXEC;
+	}
+
+	return oflags;
+}
+
+
 #ifdef PTPAX
 void
 set_pt_flags(int fd, uint16_t pt_flags)
@@ -399,8 +491,8 @@ static PyObject *
 pax_setbinflags(PyObject *self, PyObject *args)
 {
 	const char *f_name;
-	int fd, iflags;
-	uint16_t flags;
+	int fd, iflags, rdwr_pt_pax = 1;
+	uint16_t oflags, flags;
 
 	if (!PyArg_ParseTuple(args, "si", &f_name, &iflags))
 	{
@@ -410,17 +502,34 @@ pax_setbinflags(PyObject *self, PyObject *args)
 
 	if((fd = open(f_name, O_RDWR)) < 0)
 	{
-		PyErr_SetString(PaxError, "pax_setbinflags: open() failed");
-		return NULL;
+#ifdef PTPAX
+		rdwr_pt_pax = 0;
+#endif
+		if((fd = open(f_name, O_RDONLY)) < 0)
+		{
+			PyErr_SetString(PaxError, "pax_setbinflags: open() failed");
+			return NULL;
+		}
 	}
 
 	flags = (uint16_t) iflags;
 
 #ifdef PTPAX
-	set_pt_flags(fd, flags);
+	if(rdwr_pt_pax)
+	{
+		oflags = get_pt_flags(fd);
+		if( oflags == UINT16_MAX )
+			oflags = PF_NOEMUTRAMP ;
+		flags = update_flags( oflags, flags);
+		set_pt_flags(fd, flags);
+        }
 #endif
 
 #ifdef XTPAX
+	oflags = get_xt_flags(fd);
+	if( oflags == UINT16_MAX )
+		oflags = PF_NOEMUTRAMP ;
+	flags = update_flags( oflags, flags);
 	set_xt_flags(fd, flags);
 #endif
 
@@ -433,28 +542,45 @@ static PyObject *
 pax_setstrflags(PyObject *self, PyObject *args)
 {
 	char *f_name, *sflags;
-	int fd;
-	uint16_t flags;
+	int fd, rdwr_pt_pax = 1;
+	uint16_t oflags, flags;
 
 	if (!PyArg_ParseTuple(args, "ss", &f_name, &sflags))
 	{
-		PyErr_SetString(PaxError, "pax_setbinflags: PyArg_ParseTuple failed");
+		PyErr_SetString(PaxError, "pax_setstrflags: PyArg_ParseTuple failed");
 		return NULL;
 	}
 
 	if((fd = open(f_name, O_RDWR)) < 0)
 	{
-		PyErr_SetString(PaxError, "pax_setbinflags: open() failed");
-		return NULL;
+#ifdef PTPAX
+		rdwr_pt_pax = 0;
+#endif
+		if((fd = open(f_name, O_RDONLY)) < 0)
+		{
+			PyErr_SetString(PaxError, "pax_setstrflags: open() failed");
+			return NULL;
+		}
 	}
 
 	flags = string2bin(sflags);
 
 #ifdef PTPAX
-	set_pt_flags(fd, flags);
+	if(rdwr_pt_pax)
+	{
+		oflags = get_pt_flags(fd);
+		if( oflags == UINT16_MAX )
+			oflags = PF_NOEMUTRAMP ;
+		flags = update_flags( oflags, flags);
+		set_pt_flags(fd, flags);
+	}
 #endif
 
 #ifdef XTPAX
+	oflags = get_xt_flags(fd);
+	if( oflags == UINT16_MAX )
+		oflags = PF_NOEMUTRAMP ;
+	flags = update_flags( oflags, flags);
 	set_xt_flags(fd, flags);
 #endif
 


^ permalink raw reply related	[flat|nested] 89+ messages in thread
* [gentoo-commits] proj/elfix:master commit in: scripts/
@ 2012-12-14  1:26 Anthony G. Basile
  0 siblings, 0 replies; 89+ messages in thread
From: Anthony G. Basile @ 2012-12-14  1:26 UTC (permalink / raw
  To: gentoo-commits

commit:     d6de0e4717d2ae793d051d48046c29c2b87ca536
Author:     Anthony G. Basile <blueness <AT> gentoo <DOT> org>
AuthorDate: Fri Dec 14 01:19:56 2012 +0000
Commit:     Anthony G. Basile <blueness <AT> gentoo <DOT> org>
CommitDate: Fri Dec 14 01:25:46 2012 +0000
URL:        http://git.overlays.gentoo.org/gitweb/?p=proj/elfix.git;a=commit;h=d6de0e47

scripts/paxmodule.c: adopt the update_flags() logic of paxctl-ng.c

---
 scripts/paxmodule.c |  148 +++++++++++++++++++++++++++++++++++++++++++++++----
 1 files changed, 137 insertions(+), 11 deletions(-)

diff --git a/scripts/paxmodule.c b/scripts/paxmodule.c
index 422d193..c7ec87e 100644
--- a/scripts/paxmodule.c
+++ b/scripts/paxmodule.c
@@ -326,6 +326,98 @@ pax_getflags(PyObject *self, PyObject *args)
 }
 
 
+uint16_t
+update_flags(uint16_t oflags, uint16_t flags)
+{
+	//PAGEEXEC
+	if(flags & PF_PAGEEXEC)
+	{
+		oflags |= PF_PAGEEXEC;
+		oflags &= ~PF_NOPAGEEXEC;
+	}
+	if(flags & PF_NOPAGEEXEC)
+	{
+		oflags &= ~PF_PAGEEXEC;
+		oflags |= PF_NOPAGEEXEC;
+	}
+	if((flags & PF_PAGEEXEC) && (flags & PF_NOPAGEEXEC))
+	{
+		oflags &= ~PF_PAGEEXEC;
+		oflags &= ~PF_NOPAGEEXEC;
+	}
+
+	//EMUTRAMP
+	if(flags & PF_EMUTRAMP)
+	{
+		oflags |= PF_EMUTRAMP;
+		oflags &= ~PF_NOEMUTRAMP;
+	}
+	if(flags & PF_NOEMUTRAMP)
+	{
+		oflags &= ~PF_EMUTRAMP;
+		oflags |= PF_NOEMUTRAMP;
+	}
+	if((flags & PF_EMUTRAMP) && (flags & PF_NOEMUTRAMP))
+	{
+		oflags &= ~PF_EMUTRAMP;
+		oflags &= ~PF_NOEMUTRAMP;
+	}
+
+	//MPROTECT
+	if(flags & PF_MPROTECT)
+	{
+		oflags |= PF_MPROTECT;
+		oflags &= ~PF_NOMPROTECT;
+	}
+	if(flags & PF_NOMPROTECT)
+	{
+		oflags &= ~PF_MPROTECT;
+		oflags |= PF_NOMPROTECT;
+	}
+	if((flags & PF_MPROTECT) && (flags & PF_NOMPROTECT))
+	{
+		oflags &= ~PF_MPROTECT;
+		oflags &= ~PF_NOMPROTECT;
+	}
+
+	//RANDMMAP
+	if(flags & PF_RANDMMAP)
+	{
+		oflags |= PF_RANDMMAP;
+		oflags &= ~PF_NORANDMMAP;
+	}
+	if(flags & PF_NORANDMMAP)
+	{
+		oflags &= ~PF_RANDMMAP;
+		oflags |= PF_NORANDMMAP;
+	}
+	if((flags & PF_RANDMMAP) && (flags & PF_NORANDMMAP))
+	{
+		oflags &= ~PF_RANDMMAP;
+		oflags &= ~PF_NORANDMMAP;
+	}
+
+	//SEGMEXEC
+	if(flags & PF_SEGMEXEC)
+	{
+		oflags |= PF_SEGMEXEC;
+		oflags &= ~PF_NOSEGMEXEC;
+	}
+	if(flags & PF_NOSEGMEXEC)
+	{
+		oflags &= ~PF_SEGMEXEC;
+		oflags |= PF_NOSEGMEXEC;
+	}
+	if((oflags & PF_SEGMEXEC) && (oflags & PF_NOSEGMEXEC))
+	{
+		oflags &= ~PF_SEGMEXEC;
+		oflags &= ~PF_NOSEGMEXEC;
+	}
+
+	return oflags;
+}
+
+
 #ifdef PTPAX
 void
 set_pt_flags(int fd, uint16_t pt_flags)
@@ -399,8 +491,8 @@ static PyObject *
 pax_setbinflags(PyObject *self, PyObject *args)
 {
 	const char *f_name;
-	int fd, iflags;
-	uint16_t flags;
+	int fd, iflags, rdwr_pt_pax = 1;
+	uint16_t oflags, flags;
 
 	if (!PyArg_ParseTuple(args, "si", &f_name, &iflags))
 	{
@@ -410,17 +502,34 @@ pax_setbinflags(PyObject *self, PyObject *args)
 
 	if((fd = open(f_name, O_RDWR)) < 0)
 	{
-		PyErr_SetString(PaxError, "pax_setbinflags: open() failed");
-		return NULL;
+#ifdef PTPAX
+		rdwr_pt_pax = 0;
+#endif
+		if((fd = open(f_name, O_RDONLY)) < 0)
+		{
+			PyErr_SetString(PaxError, "pax_setbinflags: open() failed");
+			return NULL;
+		}
 	}
 
 	flags = (uint16_t) iflags;
 
 #ifdef PTPAX
-	set_pt_flags(fd, flags);
+	if(rdwr_pt_pax)
+	{
+		oflags = get_pt_flags(fd);
+		if( oflags == UINT16_MAX )
+			oflags = PF_NOEMUTRAMP ;
+		flags = update_flags( oflags, flags);
+		set_pt_flags(fd, flags);
+        }
 #endif
 
 #ifdef XTPAX
+	oflags = get_xt_flags(fd);
+	if( oflags == UINT16_MAX )
+		oflags = PF_NOEMUTRAMP ;
+	flags = update_flags( oflags, flags);
 	set_xt_flags(fd, flags);
 #endif
 
@@ -433,28 +542,45 @@ static PyObject *
 pax_setstrflags(PyObject *self, PyObject *args)
 {
 	char *f_name, *sflags;
-	int fd;
-	uint16_t flags;
+	int fd, rdwr_pt_pax = 1;
+	uint16_t oflags, flags;
 
 	if (!PyArg_ParseTuple(args, "ss", &f_name, &sflags))
 	{
-		PyErr_SetString(PaxError, "pax_setbinflags: PyArg_ParseTuple failed");
+		PyErr_SetString(PaxError, "pax_setstrflags: PyArg_ParseTuple failed");
 		return NULL;
 	}
 
 	if((fd = open(f_name, O_RDWR)) < 0)
 	{
-		PyErr_SetString(PaxError, "pax_setbinflags: open() failed");
-		return NULL;
+#ifdef PTPAX
+		rdwr_pt_pax = 0;
+#endif
+		if((fd = open(f_name, O_RDONLY)) < 0)
+		{
+			PyErr_SetString(PaxError, "pax_setstrflags: open() failed");
+			return NULL;
+		}
 	}
 
 	flags = string2bin(sflags);
 
 #ifdef PTPAX
-	set_pt_flags(fd, flags);
+	if(rdwr_pt_pax)
+	{
+		oflags = get_pt_flags(fd);
+		if( oflags == UINT16_MAX )
+			oflags = PF_NOEMUTRAMP ;
+		flags = update_flags( oflags, flags);
+		set_pt_flags(fd, flags);
+	}
 #endif
 
 #ifdef XTPAX
+	oflags = get_xt_flags(fd);
+	if( oflags == UINT16_MAX )
+		oflags = PF_NOEMUTRAMP ;
+	flags = update_flags( oflags, flags);
 	set_xt_flags(fd, flags);
 #endif
 


^ permalink raw reply related	[flat|nested] 89+ messages in thread
* [gentoo-commits] proj/elfix:master commit in: scripts/
@ 2012-12-14  1:20 Anthony G. Basile
  0 siblings, 0 replies; 89+ messages in thread
From: Anthony G. Basile @ 2012-12-14  1:20 UTC (permalink / raw
  To: gentoo-commits

commit:     74c8971fffb545cfb3f9874506de916b09067d61
Author:     Anthony G. Basile <blueness <AT> gentoo <DOT> org>
AuthorDate: Fri Dec 14 01:19:56 2012 +0000
Commit:     Anthony G. Basile <blueness <AT> gentoo <DOT> org>
CommitDate: Fri Dec 14 01:19:56 2012 +0000
URL:        http://git.overlays.gentoo.org/gitweb/?p=proj/elfix.git;a=commit;h=74c8971f

scripts/paxmodule.c: adopte the update_flags() logic of paxctl-ng.c

---
 scripts/paxmodule.c |  148 +++++++++++++++++++++++++++++++++++++++++++++++----
 1 files changed, 137 insertions(+), 11 deletions(-)

diff --git a/scripts/paxmodule.c b/scripts/paxmodule.c
index 422d193..c7ec87e 100644
--- a/scripts/paxmodule.c
+++ b/scripts/paxmodule.c
@@ -326,6 +326,98 @@ pax_getflags(PyObject *self, PyObject *args)
 }
 
 
+uint16_t
+update_flags(uint16_t oflags, uint16_t flags)
+{
+	//PAGEEXEC
+	if(flags & PF_PAGEEXEC)
+	{
+		oflags |= PF_PAGEEXEC;
+		oflags &= ~PF_NOPAGEEXEC;
+	}
+	if(flags & PF_NOPAGEEXEC)
+	{
+		oflags &= ~PF_PAGEEXEC;
+		oflags |= PF_NOPAGEEXEC;
+	}
+	if((flags & PF_PAGEEXEC) && (flags & PF_NOPAGEEXEC))
+	{
+		oflags &= ~PF_PAGEEXEC;
+		oflags &= ~PF_NOPAGEEXEC;
+	}
+
+	//EMUTRAMP
+	if(flags & PF_EMUTRAMP)
+	{
+		oflags |= PF_EMUTRAMP;
+		oflags &= ~PF_NOEMUTRAMP;
+	}
+	if(flags & PF_NOEMUTRAMP)
+	{
+		oflags &= ~PF_EMUTRAMP;
+		oflags |= PF_NOEMUTRAMP;
+	}
+	if((flags & PF_EMUTRAMP) && (flags & PF_NOEMUTRAMP))
+	{
+		oflags &= ~PF_EMUTRAMP;
+		oflags &= ~PF_NOEMUTRAMP;
+	}
+
+	//MPROTECT
+	if(flags & PF_MPROTECT)
+	{
+		oflags |= PF_MPROTECT;
+		oflags &= ~PF_NOMPROTECT;
+	}
+	if(flags & PF_NOMPROTECT)
+	{
+		oflags &= ~PF_MPROTECT;
+		oflags |= PF_NOMPROTECT;
+	}
+	if((flags & PF_MPROTECT) && (flags & PF_NOMPROTECT))
+	{
+		oflags &= ~PF_MPROTECT;
+		oflags &= ~PF_NOMPROTECT;
+	}
+
+	//RANDMMAP
+	if(flags & PF_RANDMMAP)
+	{
+		oflags |= PF_RANDMMAP;
+		oflags &= ~PF_NORANDMMAP;
+	}
+	if(flags & PF_NORANDMMAP)
+	{
+		oflags &= ~PF_RANDMMAP;
+		oflags |= PF_NORANDMMAP;
+	}
+	if((flags & PF_RANDMMAP) && (flags & PF_NORANDMMAP))
+	{
+		oflags &= ~PF_RANDMMAP;
+		oflags &= ~PF_NORANDMMAP;
+	}
+
+	//SEGMEXEC
+	if(flags & PF_SEGMEXEC)
+	{
+		oflags |= PF_SEGMEXEC;
+		oflags &= ~PF_NOSEGMEXEC;
+	}
+	if(flags & PF_NOSEGMEXEC)
+	{
+		oflags &= ~PF_SEGMEXEC;
+		oflags |= PF_NOSEGMEXEC;
+	}
+	if((oflags & PF_SEGMEXEC) && (oflags & PF_NOSEGMEXEC))
+	{
+		oflags &= ~PF_SEGMEXEC;
+		oflags &= ~PF_NOSEGMEXEC;
+	}
+
+	return oflags;
+}
+
+
 #ifdef PTPAX
 void
 set_pt_flags(int fd, uint16_t pt_flags)
@@ -399,8 +491,8 @@ static PyObject *
 pax_setbinflags(PyObject *self, PyObject *args)
 {
 	const char *f_name;
-	int fd, iflags;
-	uint16_t flags;
+	int fd, iflags, rdwr_pt_pax = 1;
+	uint16_t oflags, flags;
 
 	if (!PyArg_ParseTuple(args, "si", &f_name, &iflags))
 	{
@@ -410,17 +502,34 @@ pax_setbinflags(PyObject *self, PyObject *args)
 
 	if((fd = open(f_name, O_RDWR)) < 0)
 	{
-		PyErr_SetString(PaxError, "pax_setbinflags: open() failed");
-		return NULL;
+#ifdef PTPAX
+		rdwr_pt_pax = 0;
+#endif
+		if((fd = open(f_name, O_RDONLY)) < 0)
+		{
+			PyErr_SetString(PaxError, "pax_setbinflags: open() failed");
+			return NULL;
+		}
 	}
 
 	flags = (uint16_t) iflags;
 
 #ifdef PTPAX
-	set_pt_flags(fd, flags);
+	if(rdwr_pt_pax)
+	{
+		oflags = get_pt_flags(fd);
+		if( oflags == UINT16_MAX )
+			oflags = PF_NOEMUTRAMP ;
+		flags = update_flags( oflags, flags);
+		set_pt_flags(fd, flags);
+        }
 #endif
 
 #ifdef XTPAX
+	oflags = get_xt_flags(fd);
+	if( oflags == UINT16_MAX )
+		oflags = PF_NOEMUTRAMP ;
+	flags = update_flags( oflags, flags);
 	set_xt_flags(fd, flags);
 #endif
 
@@ -433,28 +542,45 @@ static PyObject *
 pax_setstrflags(PyObject *self, PyObject *args)
 {
 	char *f_name, *sflags;
-	int fd;
-	uint16_t flags;
+	int fd, rdwr_pt_pax = 1;
+	uint16_t oflags, flags;
 
 	if (!PyArg_ParseTuple(args, "ss", &f_name, &sflags))
 	{
-		PyErr_SetString(PaxError, "pax_setbinflags: PyArg_ParseTuple failed");
+		PyErr_SetString(PaxError, "pax_setstrflags: PyArg_ParseTuple failed");
 		return NULL;
 	}
 
 	if((fd = open(f_name, O_RDWR)) < 0)
 	{
-		PyErr_SetString(PaxError, "pax_setbinflags: open() failed");
-		return NULL;
+#ifdef PTPAX
+		rdwr_pt_pax = 0;
+#endif
+		if((fd = open(f_name, O_RDONLY)) < 0)
+		{
+			PyErr_SetString(PaxError, "pax_setstrflags: open() failed");
+			return NULL;
+		}
 	}
 
 	flags = string2bin(sflags);
 
 #ifdef PTPAX
-	set_pt_flags(fd, flags);
+	if(rdwr_pt_pax)
+	{
+		oflags = get_pt_flags(fd);
+		if( oflags == UINT16_MAX )
+			oflags = PF_NOEMUTRAMP ;
+		flags = update_flags( oflags, flags);
+		set_pt_flags(fd, flags);
+	}
 #endif
 
 #ifdef XTPAX
+	oflags = get_xt_flags(fd);
+	if( oflags == UINT16_MAX )
+		oflags = PF_NOEMUTRAMP ;
+	flags = update_flags( oflags, flags);
 	set_xt_flags(fd, flags);
 #endif
 


^ permalink raw reply related	[flat|nested] 89+ messages in thread
* [gentoo-commits] proj/elfix:master commit in: scripts/
@ 2012-07-27 22:01 Anthony G. Basile
  0 siblings, 0 replies; 89+ messages in thread
From: Anthony G. Basile @ 2012-07-27 22:01 UTC (permalink / raw
  To: gentoo-commits

commit:     47ef483afe7bd19f2b8a9ef77b36b8887ad98518
Author:     Anthony G. Basile <blueness <AT> gentoo <DOT> org>
AuthorDate: Fri Jul 27 22:01:19 2012 +0000
Commit:     Anthony G. Basile <blueness <AT> gentoo <DOT> org>
CommitDate: Fri Jul 27 22:01:19 2012 +0000
URL:        http://git.overlays.gentoo.org/gitweb/?p=proj/elfix.git;a=commit;h=47ef483a

Revert "scripts/paxmodule.c: ELF_C_RDWR_MMAP -> ELF_C_RDWR for uclibc compat"

This reverts commit 184b349113189aee285ff9bcb1ca08235a5c29c6.

Using libelf instead of elfutils to gelf_update_phdr() fails.  Revert
for now until we figure out what's going on.

---
 scripts/paxmodule.c |    4 ++--
 1 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/scripts/paxmodule.c b/scripts/paxmodule.c
index 4a08522..c3dfc28 100644
--- a/scripts/paxmodule.c
+++ b/scripts/paxmodule.c
@@ -110,7 +110,7 @@ get_pt_flags(int fd)
 		return pt_flags;
 	}
 
-	if((elf = elf_begin(fd, ELF_C_READ, NULL)) == NULL)
+	if((elf = elf_begin(fd, ELF_C_READ_MMAP, NULL)) == NULL)
 	{
 		PyErr_SetString(PaxError, "get_pt_flags: elf_begin() failed");
 		return pt_flags;
@@ -275,7 +275,7 @@ set_pt_flags(int fd, uint16_t pt_flags)
 		return;
 	}
 
-	if((elf = elf_begin(fd, ELF_C_RDWR, NULL)) == NULL)
+	if((elf = elf_begin(fd, ELF_C_RDWR_MMAP, NULL)) == NULL)
 	{
 		PyErr_SetString(PaxError, "set_pt_flags: elf_begin() failed");
 		return;


^ permalink raw reply related	[flat|nested] 89+ messages in thread
* [gentoo-commits] proj/elfix:master commit in: scripts/
@ 2012-07-23 19:18 Anthony G. Basile
  0 siblings, 0 replies; 89+ messages in thread
From: Anthony G. Basile @ 2012-07-23 19:18 UTC (permalink / raw
  To: gentoo-commits

commit:     76fa0298351ead5a7266f746b03cef22ef715383
Author:     Anthony G. Basile <blueness <AT> gentoo <DOT> org>
AuthorDate: Mon Jul 23 19:18:09 2012 +0000
Commit:     Anthony G. Basile <blueness <AT> gentoo <DOT> org>
CommitDate: Mon Jul 23 19:18:09 2012 +0000
URL:        http://git.overlays.gentoo.org/gitweb/?p=proj/elfix.git;a=commit;h=76fa0298

scripts/revdep-pax: simplify map reversal using setdefault

---
 scripts/revdep-pax |    5 +----
 1 files changed, 1 insertions(+), 4 deletions(-)

diff --git a/scripts/revdep-pax b/scripts/revdep-pax
index d34acdc..b9fd83b 100755
--- a/scripts/revdep-pax
+++ b/scripts/revdep-pax
@@ -68,13 +68,10 @@ def get_forward_linkings():
 
 def invert_linkings( forward_linkings ):
 	reverse_linkings = {}
-	for binary in forward_linkings:
-		for library in forward_linkings[binary]:
-			reverse_linkings[library] = []
 
 	for binary in forward_linkings:
 		for library in forward_linkings[binary]:
-			reverse_linkings[library].append(binary)
+			reverse_linkings.setdefault(library,[]).append(binary)
 
 	return reverse_linkings 
 


^ permalink raw reply related	[flat|nested] 89+ messages in thread
* [gentoo-commits] proj/elfix:master commit in: scripts/
@ 2012-07-23 15:46 Anthony G. Basile
  0 siblings, 0 replies; 89+ messages in thread
From: Anthony G. Basile @ 2012-07-23 15:46 UTC (permalink / raw
  To: gentoo-commits

commit:     9d645eec26ef20d1bc6a347d0e94490870583d26
Author:     Anthony G. Basile <blueness <AT> gentoo <DOT> org>
AuthorDate: Mon Jul 23 15:45:52 2012 +0000
Commit:     Anthony G. Basile <blueness <AT> gentoo <DOT> org>
CommitDate: Mon Jul 23 15:45:52 2012 +0000
URL:        http://git.overlays.gentoo.org/gitweb/?p=proj/elfix.git;a=commit;h=9d645eec

scripts/revdep-pax: add python2/3 compat raw_input()

---
 scripts/revdep-pax |   13 +++++++++++--
 1 files changed, 11 insertions(+), 2 deletions(-)

diff --git a/scripts/revdep-pax b/scripts/revdep-pax
index 7504877..d34acdc 100755
--- a/scripts/revdep-pax
+++ b/scripts/revdep-pax
@@ -7,6 +7,15 @@ import subprocess
 import re
 import pax
 
+
+#python2/3 compat input
+def get_input(prompt):
+	if sys.hexversion > 0x03000000:
+		return input(prompt)
+	else:
+		return raw_input(prompt)
+
+
 def get_ldd_linkings(binary):
 	ldd_output = subprocess.Popen(['/usr/bin/ldd', binary], stdout=subprocess.PIPE, stderr=subprocess.PIPE)
 	ldd_lines = ldd_output.stdout.read().decode().split('\n')
@@ -274,7 +283,7 @@ def run_binary(binary, verbose, mark, allyes):
 					if allyes:
 						ans = 'y'
 					else:
-						ans = input('\tSet flags for %s (y/n): ' % library)
+						ans = get_input('\tSet flags for %s (y/n): ' % library)
 					if ans == 'y':
 						do_marking = True
 						break
@@ -367,7 +376,7 @@ def run_soname(name, verbose, use_soname, mark, allyes, executable_only):
 					if allyes:
 						ans = 'y'
 					else:
-						ans = input('\tSet flags for %s (y/n): ' % binary)
+						ans = get_input('\tSet flags for %s (y/n): ' % binary)
 					if ans == 'y':
 						do_marking = True
 						break


^ permalink raw reply related	[flat|nested] 89+ messages in thread
* [gentoo-commits] proj/elfix:master commit in: scripts/
@ 2012-07-23 15:27 Anthony G. Basile
  0 siblings, 0 replies; 89+ messages in thread
From: Anthony G. Basile @ 2012-07-23 15:27 UTC (permalink / raw
  To: gentoo-commits

commit:     d8d6c562032e0e91b92e5bbcce50b72ee863d8bf
Author:     Anthony G. Basile <blueness <AT> gentoo <DOT> org>
AuthorDate: Mon Jul 23 15:27:32 2012 +0000
Commit:     Anthony G. Basile <blueness <AT> gentoo <DOT> org>
CommitDate: Mon Jul 23 15:27:32 2012 +0000
URL:        http://git.overlays.gentoo.org/gitweb/?p=proj/elfix.git;a=commit;h=d8d6c562

scripts/revdep-pax: add sanity for OBJECT, SONAME, LIBRARY

---
 scripts/revdep-pax |   16 ++++++++++++++--
 1 files changed, 14 insertions(+), 2 deletions(-)

diff --git a/scripts/revdep-pax b/scripts/revdep-pax
index ca35ac4..7504877 100755
--- a/scripts/revdep-pax
+++ b/scripts/revdep-pax
@@ -239,6 +239,9 @@ def migrate_flags(importer, exporter_str_flags, exporter_bin_flags):
 
 
 def run_binary(binary, verbose, mark, allyes):
+	if not os.path.exists(binary):
+		print('%s\tNo such OBJECT' % binary)
+		return
 	( linkings, mappings ) = get_ldd_linkings(binary)
 	( binary_str_flags, binary_bin_flags ) = pax.getflags(binary)
 	print('%s (%s)\n' % ( binary, binary_str_flags ))
@@ -308,9 +311,18 @@ def run_soname(name, verbose, use_soname, mark, allyes, executable_only):
 		soname = name
 	else:
 		library2soname_mappings = invert_so2library_mappings(so2library_mappings)
-		soname = library2soname_mappings[name]
+		try:
+			soname = library2soname_mappings[name]
+		except KeyError:
+			print('%s\tNo such LIBRARY' % name)
+			return
+
+	try:
+		linkings = reverse_linkings[soname]
+	except KeyError:
+		print('%s\tNo such SONAME' % soname)
+		return
 
-	linkings = reverse_linkings[soname]
 	library = so2library_mappings[soname]
 
 	( library_str_flags, library_bin_flags ) = pax.getflags(library)


^ permalink raw reply related	[flat|nested] 89+ messages in thread
* [gentoo-commits] proj/elfix:master commit in: scripts/
@ 2012-07-23 14:58 Anthony G. Basile
  0 siblings, 0 replies; 89+ messages in thread
From: Anthony G. Basile @ 2012-07-23 14:58 UTC (permalink / raw
  To: gentoo-commits

commit:     643a1576a1000ef04c0b3ec192a856469404ed5f
Author:     Anthony G. Basile <blueness <AT> gentoo <DOT> org>
AuthorDate: Mon Jul 23 14:58:14 2012 +0000
Commit:     Anthony G. Basile <blueness <AT> gentoo <DOT> org>
CommitDate: Mon Jul 23 14:58:14 2012 +0000
URL:        http://git.overlays.gentoo.org/gitweb/?p=proj/elfix.git;a=commit;h=643a1576

scripts/revdep-pax: use Popen, correct exception handling

---
 scripts/revdep-pax |   49 +++++++++++++++++--------------------------------
 1 files changed, 17 insertions(+), 32 deletions(-)

diff --git a/scripts/revdep-pax b/scripts/revdep-pax
index ded09cd..ca35ac4 100755
--- a/scripts/revdep-pax
+++ b/scripts/revdep-pax
@@ -8,14 +8,8 @@ import re
 import pax
 
 def get_ldd_linkings(binary):
-	try:
-		#TODO: when subprocess.DEVNULL makes it to python, change this: http://bugs.python.org/issue5870
-		ldd_output = subprocess.check_output(['/usr/bin/ldd', binary], stderr=subprocess.PIPE)
-	except Subprocess.CalledProcessError:
-		#TODO: we should record these binaries which are probably statically linked
-		return []
-
-	ldd_lines = ldd_output.split('\n')
+	ldd_output = subprocess.Popen(['/usr/bin/ldd', binary], stdout=subprocess.PIPE, stderr=subprocess.PIPE)
+	ldd_lines = ldd_output.stdout.read().decode().split('\n')
 
 	linkings = []
 	mappings = {}
@@ -37,7 +31,7 @@ def get_ldd_linkings(binary):
 
 
 def get_forward_linkings():
-	#TODO: I'm still not sure we wan to use /var/db/pkg vs some path of binaries
+	#TODO: I'm still not sure we want to use /var/db/pkg vs some path of binaries
 	var_db_pkg = '/var/db/pkg'
 
 	forward_linkings = {}
@@ -57,8 +51,8 @@ def get_forward_linkings():
 					( linkings, mappings ) = get_ldd_linkings(binary)
 					forward_linkings[binary] = linkings 
 					so2library_mappings.update(mappings)
-			except SyntaxError:
-				continue
+			except IOError:
+				continue #File probably doesn't exist, which is okay
 
 	return ( forward_linkings, so2library_mappings )
 
@@ -85,7 +79,7 @@ def print_forward_linkings( forward_linkings, so2library_mappings, verbose ):
 			( binary_str_flags, binary_bin_flags ) = pax.getflags(binary)
 			sv = '%s ( %s )\n' % ( binary, binary_str_flags )
 			s = sv
-		except SyntaxError:
+		except pax.error:
 			missing_binaries.append(binary)
 			continue
 
@@ -98,7 +92,7 @@ def print_forward_linkings( forward_linkings, so2library_mappings, verbose ):
 				if binary_str_flags != library_str_flags:
 					s = '%s\n\t%s\t%s ( %s )' % ( s, soname, library, library_str_flags )
 					count = count + 1
-			except SyntaxError:
+			except pax.error:
 				missing_links.append(soname)
 
 		if verbose:
@@ -133,7 +127,7 @@ def print_reverse_linkings( reverse_linkings, so2library_mappings, verbose, exec
 			( library_str_flags, library_bin_flags ) = pax.getflags(library)
 			sv = '%s\t%s ( %s )\n' % ( soname, library, library_str_flags )
 			s = sv
-		except SyntaxError:
+		except pax.error:
 			missing_sonames.append(soname)
 			continue
 
@@ -152,7 +146,7 @@ def print_reverse_linkings( reverse_linkings, so2library_mappings, verbose, exec
 					if library_str_flags != binary_str_flags:
 						s = '%s\n\t%s ( %s )' % ( s, binary, binary_str_flags )
 						count = count + 1
-			except SyntaxError:
+			except pax.error:
 				missing_links.append(binary)
 
 		if verbose:
@@ -261,7 +255,7 @@ def run_binary(binary, verbose, mark, allyes):
 				mismatched_libraries.append(library)
 				if not verbose:
 					print('\t%s\t%s ( %s )' % ( soname, library, library_str_flags ))
-		except SyntaxError:
+		except pax.error:
 			print('file for soname %s not found' % soname)
 
 	if len(mismatched_libraries) == 0:
@@ -290,7 +284,7 @@ def run_binary(binary, verbose, mark, allyes):
 				if do_marking:
 					try:
 						migrate_flags(library, binary_str_flags, binary_bin_flags)
-					except SyntaxError:
+					except pax.error:
 						print("\n\tCould not set pax flags on %s, file is probably busy" % library)
 						print("\tShut down all processes that use it and try again")
 					( library_str_flags, library_bin_flags ) = pax.getflags(library)
@@ -342,7 +336,7 @@ def run_soname(name, verbose, use_soname, mark, allyes, executable_only):
 					mismatched_binaries.append(binary)
 					if not verbose:
 						print('\t%s ( %s )' % ( binary, binary_str_flags ))
-		except SyntaxError:
+		except pax.error:
 			print('cannot obtain pax flags for %s' % binary)
 
 	if len(mismatched_binaries) == 0:
@@ -373,7 +367,7 @@ def run_soname(name, verbose, use_soname, mark, allyes, executable_only):
 				if do_marking:
 					try:
 						migrate_flags(binary, library_str_flags, library_bin_flags)
-					except SyntaxError:
+					except pax.error:
 						print('\n\tCould not set pax flags on %s, file is probably busy' % binary)
 						print('\tShut down all processes that use it and try again')
 					( binary_str_flags, binary_bin_flags ) = pax.getflags(binary)
@@ -466,21 +460,12 @@ def main():
 	elif do_reverse:
 		run_reverse(verbose, executable_only)
 	elif binary != None:
-		try:
-			run_binary(binary, verbose, mark, allyes)
-		except SyntaxError:
-			print('Please check that %s exists!' % binary)
+		run_binary(binary, verbose, mark, allyes)
 	elif soname != None:
-		try:
-			run_soname(soname, verbose, True, mark, allyes, executable_only)
-		except SyntaxError:
-			print('Please check that %s exists!' % soname)
+		run_soname(soname, verbose, True, mark, allyes, executable_only)
 	elif library != None:
-		try:
-			library = os.path.realpath(library)
-			run_soname(library, verbose, False, mark, allyes, executable_only)
-		except SyntaxError:
-			print('Please check that %s exists!' % library)
+		library = os.path.realpath(library)
+		run_soname(library, verbose, False, mark, allyes, executable_only)
 
 if __name__ == '__main__':
     main()


^ permalink raw reply related	[flat|nested] 89+ messages in thread
* [gentoo-commits] proj/elfix:master commit in: scripts/
@ 2012-07-23 14:15 Anthony G. Basile
  0 siblings, 0 replies; 89+ messages in thread
From: Anthony G. Basile @ 2012-07-23 14:15 UTC (permalink / raw
  To: gentoo-commits

commit:     46351ad3ab352d18cac9c410690f046da6b430eb
Author:     Anthony G. Basile <blueness <AT> gentoo <DOT> org>
AuthorDate: Mon Jul 23 14:15:38 2012 +0000
Commit:     Anthony G. Basile <blueness <AT> gentoo <DOT> org>
CommitDate: Mon Jul 23 14:15:38 2012 +0000
URL:        http://git.overlays.gentoo.org/gitweb/?p=proj/elfix.git;a=commit;h=46351ad3

scripts/revdep-pax: remove bare exceptions

---
 scripts/revdep-pax |   26 +++++++++++++-------------
 1 files changed, 13 insertions(+), 13 deletions(-)

diff --git a/scripts/revdep-pax b/scripts/revdep-pax
index 9232a17..ded09cd 100755
--- a/scripts/revdep-pax
+++ b/scripts/revdep-pax
@@ -11,7 +11,7 @@ def get_ldd_linkings(binary):
 	try:
 		#TODO: when subprocess.DEVNULL makes it to python, change this: http://bugs.python.org/issue5870
 		ldd_output = subprocess.check_output(['/usr/bin/ldd', binary], stderr=subprocess.PIPE)
-	except:
+	except Subprocess.CalledProcessError:
 		#TODO: we should record these binaries which are probably statically linked
 		return []
 
@@ -57,7 +57,7 @@ def get_forward_linkings():
 					( linkings, mappings ) = get_ldd_linkings(binary)
 					forward_linkings[binary] = linkings 
 					so2library_mappings.update(mappings)
-			except:
+			except SyntaxError:
 				continue
 
 	return ( forward_linkings, so2library_mappings )
@@ -85,7 +85,7 @@ def print_forward_linkings( forward_linkings, so2library_mappings, verbose ):
 			( binary_str_flags, binary_bin_flags ) = pax.getflags(binary)
 			sv = '%s ( %s )\n' % ( binary, binary_str_flags )
 			s = sv
-		except:
+		except SyntaxError:
 			missing_binaries.append(binary)
 			continue
 
@@ -98,7 +98,7 @@ def print_forward_linkings( forward_linkings, so2library_mappings, verbose ):
 				if binary_str_flags != library_str_flags:
 					s = '%s\n\t%s\t%s ( %s )' % ( s, soname, library, library_str_flags )
 					count = count + 1
-			except:
+			except SyntaxError:
 				missing_links.append(soname)
 
 		if verbose:
@@ -133,7 +133,7 @@ def print_reverse_linkings( reverse_linkings, so2library_mappings, verbose, exec
 			( library_str_flags, library_bin_flags ) = pax.getflags(library)
 			sv = '%s\t%s ( %s )\n' % ( soname, library, library_str_flags )
 			s = sv
-		except:
+		except SyntaxError:
 			missing_sonames.append(soname)
 			continue
 
@@ -152,7 +152,7 @@ def print_reverse_linkings( reverse_linkings, so2library_mappings, verbose, exec
 					if library_str_flags != binary_str_flags:
 						s = '%s\n\t%s ( %s )' % ( s, binary, binary_str_flags )
 						count = count + 1
-			except:
+			except SyntaxError:
 				missing_links.append(binary)
 
 		if verbose:
@@ -261,7 +261,7 @@ def run_binary(binary, verbose, mark, allyes):
 				mismatched_libraries.append(library)
 				if not verbose:
 					print('\t%s\t%s ( %s )' % ( soname, library, library_str_flags ))
-		except:
+		except SyntaxError:
 			print('file for soname %s not found' % soname)
 
 	if len(mismatched_libraries) == 0:
@@ -290,7 +290,7 @@ def run_binary(binary, verbose, mark, allyes):
 				if do_marking:
 					try:
 						migrate_flags(library, binary_str_flags, binary_bin_flags)
-					except:
+					except SyntaxError:
 						print("\n\tCould not set pax flags on %s, file is probably busy" % library)
 						print("\tShut down all processes that use it and try again")
 					( library_str_flags, library_bin_flags ) = pax.getflags(library)
@@ -342,7 +342,7 @@ def run_soname(name, verbose, use_soname, mark, allyes, executable_only):
 					mismatched_binaries.append(binary)
 					if not verbose:
 						print('\t%s ( %s )' % ( binary, binary_str_flags ))
-		except:
+		except SyntaxError:
 			print('cannot obtain pax flags for %s' % binary)
 
 	if len(mismatched_binaries) == 0:
@@ -373,7 +373,7 @@ def run_soname(name, verbose, use_soname, mark, allyes, executable_only):
 				if do_marking:
 					try:
 						migrate_flags(binary, library_str_flags, library_bin_flags)
-					except:
+					except SyntaxError:
 						print('\n\tCould not set pax flags on %s, file is probably busy' % binary)
 						print('\tShut down all processes that use it and try again')
 					( binary_str_flags, binary_bin_flags ) = pax.getflags(binary)
@@ -468,18 +468,18 @@ def main():
 	elif binary != None:
 		try:
 			run_binary(binary, verbose, mark, allyes)
-		except:
+		except SyntaxError:
 			print('Please check that %s exists!' % binary)
 	elif soname != None:
 		try:
 			run_soname(soname, verbose, True, mark, allyes, executable_only)
-		except:
+		except SyntaxError:
 			print('Please check that %s exists!' % soname)
 	elif library != None:
 		try:
 			library = os.path.realpath(library)
 			run_soname(library, verbose, False, mark, allyes, executable_only)
-		except:
+		except SyntaxError:
 			print('Please check that %s exists!' % library)
 
 if __name__ == '__main__':


^ permalink raw reply related	[flat|nested] 89+ messages in thread
* [gentoo-commits] proj/elfix:master commit in: scripts/
@ 2012-07-23 13:06 Anthony G. Basile
  0 siblings, 0 replies; 89+ messages in thread
From: Anthony G. Basile @ 2012-07-23 13:06 UTC (permalink / raw
  To: gentoo-commits

commit:     4a1ec98435f5144e0909ba13468edd07de52137f
Author:     Anthony G. Basile <blueness <AT> gentoo <DOT> org>
AuthorDate: Mon Jul 23 13:05:55 2012 +0000
Commit:     Anthony G. Basile <blueness <AT> gentoo <DOT> org>
CommitDate: Mon Jul 23 13:05:55 2012 +0000
URL:        http://git.overlays.gentoo.org/gitweb/?p=proj/elfix.git;a=commit;h=4a1ec984

scripts/revdep-pax: fix more python2 -> 3

---
 scripts/revdep-pax |    6 +++---
 1 files changed, 3 insertions(+), 3 deletions(-)

diff --git a/scripts/revdep-pax b/scripts/revdep-pax
index 82d8683..9232a17 100755
--- a/scripts/revdep-pax
+++ b/scripts/revdep-pax
@@ -277,7 +277,7 @@ def run_binary(binary, verbose, mark, allyes):
 					if allyes:
 						ans = 'y'
 					else:
-						ans = raw_input('\tSet flags for %s (y/n): ' % library)
+						ans = input('\tSet flags for %s (y/n): ' % library)
 					if ans == 'y':
 						do_marking = True
 						break
@@ -299,7 +299,7 @@ def run_binary(binary, verbose, mark, allyes):
 
 def invert_so2library_mappings( so2library_mappings ):
 	library2soname_mappings = {}
-	for soname, library in so2library_mappings.iteritems():
+	for soname, library in so2library_mappings.items():
 		library2soname_mappings[library] = soname
 	return library2soname_mappings
 
@@ -361,7 +361,7 @@ def run_soname(name, verbose, use_soname, mark, allyes, executable_only):
 					if allyes:
 						ans = 'y'
 					else:
-						ans = raw_input('\tSet flags for %s (y/n): ' % binary)
+						ans = input('\tSet flags for %s (y/n): ' % binary)
 					if ans == 'y':
 						do_marking = True
 						break


^ permalink raw reply related	[flat|nested] 89+ messages in thread
* [gentoo-commits] proj/elfix:master commit in: scripts/
@ 2012-07-23 11:47 Anthony G. Basile
  0 siblings, 0 replies; 89+ messages in thread
From: Anthony G. Basile @ 2012-07-23 11:47 UTC (permalink / raw
  To: gentoo-commits

commit:     184b349113189aee285ff9bcb1ca08235a5c29c6
Author:     Anthony G. Basile <blueness <AT> gentoo <DOT> org>
AuthorDate: Mon Jul 23 11:47:29 2012 +0000
Commit:     Anthony G. Basile <blueness <AT> gentoo <DOT> org>
CommitDate: Mon Jul 23 11:47:29 2012 +0000
URL:        http://git.overlays.gentoo.org/gitweb/?p=proj/elfix.git;a=commit;h=184b3491

scripts/paxmodule.c: ELF_C_RDWR_MMAP -> ELF_C_RDWR for uclibc compat

---
 scripts/paxmodule.c |    4 ++--
 1 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/scripts/paxmodule.c b/scripts/paxmodule.c
index c3dfc28..4a08522 100644
--- a/scripts/paxmodule.c
+++ b/scripts/paxmodule.c
@@ -110,7 +110,7 @@ get_pt_flags(int fd)
 		return pt_flags;
 	}
 
-	if((elf = elf_begin(fd, ELF_C_READ_MMAP, NULL)) == NULL)
+	if((elf = elf_begin(fd, ELF_C_READ, NULL)) == NULL)
 	{
 		PyErr_SetString(PaxError, "get_pt_flags: elf_begin() failed");
 		return pt_flags;
@@ -275,7 +275,7 @@ set_pt_flags(int fd, uint16_t pt_flags)
 		return;
 	}
 
-	if((elf = elf_begin(fd, ELF_C_RDWR_MMAP, NULL)) == NULL)
+	if((elf = elf_begin(fd, ELF_C_RDWR, NULL)) == NULL)
 	{
 		PyErr_SetString(PaxError, "set_pt_flags: elf_begin() failed");
 		return;


^ permalink raw reply related	[flat|nested] 89+ messages in thread
* [gentoo-commits] proj/elfix:master commit in: scripts/
@ 2012-07-22 23:11 Anthony G. Basile
  0 siblings, 0 replies; 89+ messages in thread
From: Anthony G. Basile @ 2012-07-22 23:11 UTC (permalink / raw
  To: gentoo-commits

commit:     4b0bfd9caf1c4645898f1194033f66381edc3be4
Author:     Anthony G. Basile <blueness <AT> gentoo <DOT> org>
AuthorDate: Sun Jul 22 23:11:27 2012 +0000
Commit:     Anthony G. Basile <blueness <AT> gentoo <DOT> org>
CommitDate: Sun Jul 22 23:11:27 2012 +0000
URL:        http://git.overlays.gentoo.org/gitweb/?p=proj/elfix.git;a=commit;h=4b0bfd9c

scripts/paxmodule.c: python3 with python2 compat

---
 scripts/paxmodule.c |   31 ++++++++++++++++++++++++++++++-
 scripts/revdep-pax  |    8 ++++----
 2 files changed, 34 insertions(+), 5 deletions(-)

diff --git a/scripts/paxmodule.c b/scripts/paxmodule.c
index 8a3a6e6..c3dfc28 100644
--- a/scripts/paxmodule.c
+++ b/scripts/paxmodule.c
@@ -49,20 +49,49 @@ static PyMethodDef PaxMethods[] = {
 	{NULL, NULL, 0, NULL}
 };
 
+#if PY_MAJOR_VERSION >= 3
+    static struct PyModuleDef moduledef = {
+        PyModuleDef_HEAD_INIT,
+        "pax",						/* m_name */
+        "Module for setting PT_PAX and XT_PAX flags",	/* m_doc */
+        -1,						/* m_size */
+        PaxMethods,					/* m_methods */
+        NULL,						/* m_reload */
+        NULL,						/* m_traverse */
+        NULL,						/* m_clear */
+        NULL,						/* m_free */
+    };
+#endif
+
 static PyObject *PaxError;
 
 PyMODINIT_FUNC
+#if PY_MAJOR_VERSION >= 3
+PyInit_pax(void)
+#else
 initpax(void)
+#endif
 {
 	PyObject *m;
 
+#if PY_MAJOR_VERSION >= 3
+	m = PyModule_Create(&moduledef);
+#else
 	m = Py_InitModule("pax", PaxMethods);
+#endif
+
 	if (m == NULL)
 		return;
 
 	PaxError = PyErr_NewException("pax.error", NULL, NULL);
 	Py_INCREF(PaxError);
 	PyModule_AddObject(m, "error", PaxError);
+
+#if PY_MAJOR_VERSION >= 3
+	return m;
+#else
+	return;
+#endif
 }
 
 
@@ -114,7 +143,6 @@ get_pt_flags(int fd)
 }
 
 
-#ifdef XATTR
 uint16_t
 string2bin(char *buf)
 {
@@ -149,6 +177,7 @@ string2bin(char *buf)
 }
 
 
+#ifdef XATTR
 uint16_t
 get_xt_flags(int fd)
 {

diff --git a/scripts/revdep-pax b/scripts/revdep-pax
index 81d37f1..82d8683 100755
--- a/scripts/revdep-pax
+++ b/scripts/revdep-pax
@@ -268,7 +268,7 @@ def run_binary(binary, verbose, mark, allyes):
 		if not verbose:
 			print('\tNo mismatches\n')
 	else:
-		print()
+		print('\n'),
 		if mark:
 			print('\tWill mark libraries with %s\n' % binary_str_flags)
 			for library in mismatched_libraries:
@@ -349,7 +349,7 @@ def run_soname(name, verbose, use_soname, mark, allyes, executable_only):
 		if not verbose:
 			print('\tNo mismatches\n')
 	else:
-		print()
+		print('\n'),
 		if mark:
 			print('\tWill mark binaries with %s\n' % library_str_flags)
 			for binary in mismatched_binaries:
@@ -385,7 +385,7 @@ def run_usage():
 	print('Bug Reports  : http://bugs.gentoo.org/')
 	print('Program Name : revdep-pax')
 	print('Description  : Get or set pax flags on an ELF object')
-	print()
+	print('\n'),
 	print('Usage        : revdep-pax -f [-v]             print out all forward mappings for all system binaries')
 	print('             : revdep-pax -r [-ve]            print out all reverse mappings for all system sonames')
 	print('             : revdep-pax -b OBJECT  [-myv]   print all forward mappings only for OBJECT')
@@ -396,7 +396,7 @@ def run_usage():
 	print('             : -e                             only print out executables in shell $PATH')
 	print('             : -m                             don\'t just report, but mark the mismatching objects')
 	print('             : -y                             assume "yes" to all prompts for making (USE CAREFULLY!)')
-	print()
+	print('\n'),
 
 
 def main():


^ permalink raw reply related	[flat|nested] 89+ messages in thread
* [gentoo-commits] proj/elfix:master commit in: scripts/
@ 2012-07-22 22:22 Anthony G. Basile
  0 siblings, 0 replies; 89+ messages in thread
From: Anthony G. Basile @ 2012-07-22 22:22 UTC (permalink / raw
  To: gentoo-commits

commit:     c4d07d4454f0784053dbf3d41428e3601d1e336b
Author:     Anthony G. Basile <blueness <AT> gentoo <DOT> org>
AuthorDate: Sun Jul 22 22:22:41 2012 +0000
Commit:     Anthony G. Basile <blueness <AT> gentoo <DOT> org>
CommitDate: Sun Jul 22 22:22:41 2012 +0000
URL:        http://git.overlays.gentoo.org/gitweb/?p=proj/elfix.git;a=commit;h=c4d07d44

scripts/revdep-pax: print and exceptions python3 compat

---
 scripts/revdep-pax |  135 ++++++++++++++++++++++++++--------------------------
 1 files changed, 67 insertions(+), 68 deletions(-)

diff --git a/scripts/revdep-pax b/scripts/revdep-pax
index 7de3930..81d37f1 100755
--- a/scripts/revdep-pax
+++ b/scripts/revdep-pax
@@ -102,24 +102,24 @@ def print_forward_linkings( forward_linkings, so2library_mappings, verbose ):
 				missing_links.append(soname)
 
 		if verbose:
-			print '%s\n' % sv
+			print('%s\n' % sv)
 			if count == 0:
-				print '\tNo mismatches\n\n'
+				print('\tNo mismatches\n\n')
 			else:
-				print '\tMismatches\n\n'
+				print('\tMismatches\n\n')
 		else:
 			if count != 0:
-				print '%s\n\n' % s
+				print('%s\n\n' % s)
 
 	missing_binaries = set(missing_binaries)
-	print '\n**** Missing binaries ****\n'
+	print('\n**** Missing binaries ****\n')
 	for m in missing_binaries:
-		print '\t%s\n' % m
+		print('\t%s\n' % m)
 
 	missing_links = set(missing_links)
-	print '\n**** Missing forward linkings ****\n'
+	print('\n**** Missing forward linkings ****\n')
 	for m in missing_links:
-		print '\t%s\n' % m
+		print('\t%s\n' % m)
 
 
 def print_reverse_linkings( reverse_linkings, so2library_mappings, verbose, executable_only ):
@@ -156,24 +156,24 @@ def print_reverse_linkings( reverse_linkings, so2library_mappings, verbose, exec
 				missing_links.append(binary)
 
 		if verbose:
-			print '%s\n' % sv
+			print('%s\n' % sv)
 			if count == 0:
-				print '\tNo mismatches\n\n'
+				print('\tNo mismatches\n\n')
 			else:
-				print '\tMismatches\n\n'
+				print('\tMismatches\n\n')
 		else:
 			if count != 0:
-				print '%s\n\n' % s
+				print('%s\n\n' % s)
 
 	missing_sonames = set(missing_sonames)
-	print '\n**** Missing sonames ****\n'
+	print('\n**** Missing sonames ****\n')
 	for m in missing_sonames:
-		print '\t%s\n' % m
+		print('\t%s\n' % m)
 
 	missing_links = set(missing_links)
-	print '\n**** Missing reverse linkings ****\n'
+	print('\n**** Missing reverse linkings ****\n')
 	for m in missing_links:
-		print '\t%s\n' % m
+		print('\t%s\n' % m)
 
 
 def run_forward(verbose):
@@ -229,15 +229,15 @@ def migrate_flags(importer, exporter_str_flags, exporter_bin_flags):
 		if importer_str_flags[i].isupper() and exporter_str_flags[i].islower():
 			result_bin_flags = result_bin_flags ^ pf_flags[exporter_str_flags[i]]
 			result_bin_flags = result_bin_flags | pf_flags[importer_str_flags[i]]
-			print '\t\tWarning: %s has %s, refusing to set to %s' % (
-				importer, importer_str_flags[i], exporter_str_flags[i] ),
+			print('\t\tWarning: %s has %s, refusing to set to %s' % (
+				importer, importer_str_flags[i], exporter_str_flags[i] )),
 		if importer_str_flags[i].isupper() and exporter_str_flags[i] == '-':
 			result_bin_flags = result_bin_flags | pf_flags[importer_str_flags[i]]
 		if importer_str_flags[i].islower() and exporter_str_flags[i].isupper():
 			result_bin_flags = result_bin_flags ^ pf_flags[exporter_str_flags[i]]
 			result_bin_flags = result_bin_flags | pf_flags[importer_str_flags[i]]
-			print '\t\tWarning: %s has %s, refusing to set to %s' % (
-				importer, importer_str_flags[i], exporter_str_flags[i] ),
+			print('\t\tWarning: %s has %s, refusing to set to %s' % (
+				importer, importer_str_flags[i], exporter_str_flags[i] )),
 		if importer_str_flags[i].islower() and exporter_str_flags[i] == '-':
 			result_bin_flags = result_bin_flags | pf_flags[importer_str_flags[i]]
 
@@ -247,7 +247,7 @@ def migrate_flags(importer, exporter_str_flags, exporter_bin_flags):
 def run_binary(binary, verbose, mark, allyes):
 	( linkings, mappings ) = get_ldd_linkings(binary)
 	( binary_str_flags, binary_bin_flags ) = pax.getflags(binary)
-	print '%s (%s)\n' % ( binary, binary_str_flags )
+	print('%s (%s)\n' % ( binary, binary_str_flags ))
 
 	mismatched_libraries = []
 
@@ -256,22 +256,21 @@ def run_binary(binary, verbose, mark, allyes):
 			library = mappings[soname]
 			( library_str_flags, library_bin_flags ) = pax.getflags(library)
 			if verbose:
-				print '\t%s\t%s ( %s )' % ( soname, library, library_str_flags )
+				print('\t%s\t%s ( %s )' % ( soname, library, library_str_flags ))
 			if binary_str_flags != library_str_flags:
 				mismatched_libraries.append(library)
 				if not verbose:
-					print '\t%s\t%s ( %s )' % ( soname, library, library_str_flags )
+					print('\t%s\t%s ( %s )' % ( soname, library, library_str_flags ))
 		except:
-			print 'file for soname %s not found' % soname
+			print('file for soname %s not found' % soname)
 
 	if len(mismatched_libraries) == 0:
 		if not verbose:
-			print '\tNo mismatches\n'
+			print('\tNo mismatches\n')
 	else:
-		print
+		print()
 		if mark:
-			print '\tWill mark libraries with %s' % binary_str_flags
-			print
+			print('\tWill mark libraries with %s\n' % binary_str_flags)
 			for library in mismatched_libraries:
 				do_marking = False
 				while True:
@@ -286,16 +285,16 @@ def run_binary(binary, verbose, mark, allyes):
 						do_marking = False
 						break
 					else:
-						print '\t\tPlease enter y or n'
+						print('\t\tPlease enter y or n')
 
 				if do_marking:
 					try:
 						migrate_flags(library, binary_str_flags, binary_bin_flags)
 					except:
-						print "\n\tCould not set pax flags on %s, file is probably busy" % library
-						print "\tShut down all processes that use it and try again"
+						print("\n\tCould not set pax flags on %s, file is probably busy" % library)
+						print("\tShut down all processes that use it and try again")
 					( library_str_flags, library_bin_flags ) = pax.getflags(library)
-					print '\n\t\t%s ( %s )\n' % ( library, library_str_flags )
+					print('\n\t\t%s ( %s )\n' % ( library, library_str_flags ))
 
 
 def invert_so2library_mappings( so2library_mappings ):
@@ -321,7 +320,7 @@ def run_soname(name, verbose, use_soname, mark, allyes, executable_only):
 	library = so2library_mappings[soname]
 
 	( library_str_flags, library_bin_flags ) = pax.getflags(library)
-	print '%s\t%s (%s)\n' % ( soname, library, library_str_flags )
+	print('%s\t%s (%s)\n' % ( soname, library, library_str_flags ))
 
 	mismatched_binaries = []
 	for binary in linkings:
@@ -330,29 +329,29 @@ def run_soname(name, verbose, use_soname, mark, allyes, executable_only):
 			if verbose:
 				if executable_only:
 					if os.path.dirname(binary) in shell_path:	
-						print '\t%s ( %s )' % ( binary, binary_str_flags )
+						print('\t%s ( %s )' % ( binary, binary_str_flags ))
 				else:
-					print '\t%s ( %s )' % ( binary, binary_str_flags )
+					print('\t%s ( %s )' % ( binary, binary_str_flags ))
 			if library_str_flags != binary_str_flags:
 				if executable_only:
 					if os.path.dirname(binary) in shell_path:	
 						mismatched_binaries.append(binary)
 						if not verbose:
-							print '\t%s ( %s )' % ( binary, binary_str_flags )
+							print('\t%s ( %s )' % ( binary, binary_str_flags ))
 				else:
 					mismatched_binaries.append(binary)
 					if not verbose:
-						print '\t%s ( %s )' % ( binary, binary_str_flags )
+						print('\t%s ( %s )' % ( binary, binary_str_flags ))
 		except:
-			print 'cannot obtain pax flags for %s' % binary
+			print('cannot obtain pax flags for %s' % binary)
 
 	if len(mismatched_binaries) == 0:
 		if not verbose:
-			print '\tNo mismatches\n'
+			print('\tNo mismatches\n')
 	else:
-		print
+		print()
 		if mark:
-			print '\tWill mark binaries with %s\n' % library_str_flags
+			print('\tWill mark binaries with %s\n' % library_str_flags)
 			for binary in mismatched_binaries:
 				if executable_only:
 					if not os.path.dirname(binary) in shell_path:
@@ -370,41 +369,41 @@ def run_soname(name, verbose, use_soname, mark, allyes, executable_only):
 						do_marking = False
 						break
 					else:
-						print '\t\tPlease enter y or n'
+						print('\t\tPlease enter y or n')
 				if do_marking:
 					try:
 						migrate_flags(binary, library_str_flags, library_bin_flags)
 					except:
-						print "\n\tCould not set pax flags on %s, file is probably busy" % binary
-						print "\tShut down all processes that use it and try again"
+						print('\n\tCould not set pax flags on %s, file is probably busy' % binary)
+						print('\tShut down all processes that use it and try again')
 					( binary_str_flags, binary_bin_flags ) = pax.getflags(binary)
-					print '\n\t\t%s ( %s )\n' % ( binary, binary_str_flags )
+					print('\n\t\t%s ( %s )\n' % ( binary, binary_str_flags ))
 
 
 def run_usage():
-	print 'Package Name : elfix'
-	print 'Bug Reports  : http://bugs.gentoo.org/'
-	print 'Program Name : revdep-pax'
-	print 'Description  : Get or set pax flags on an ELF object'
-	print
-	print 'Usage        : revdep-pax -f [-v]             print out all forward mappings for all system binaries'
-	print '             : revdep-pax -r [-ve]            print out all reverse mappings for all system sonames'
-	print '             : revdep-pax -b OBJECT  [-myv]   print all forward mappings only for OBJECT'
-	print '             : revdep-pax -s SONAME  [-myve]  print all reverse mappings only for SONAME'
-	print '             : revdep-pax -l LIBRARY [-myve]  print all reverse mappings only for LIBRARY file'
-	print '             : revdep-pax [-h]                print out this help'
-	print '             : -v                             verbose, otherwise just print mismatching objects'
-	print '             : -e                             only print out executables in shell $PATH'
-	print '             : -m                             don\'t just report, but mark the mismatching objects'
-	print '             : -y                             assume "yes" to all prompts for making (USE CAREFULLY!)'
-	print
+	print('Package Name : elfix')
+	print('Bug Reports  : http://bugs.gentoo.org/')
+	print('Program Name : revdep-pax')
+	print('Description  : Get or set pax flags on an ELF object')
+	print()
+	print('Usage        : revdep-pax -f [-v]             print out all forward mappings for all system binaries')
+	print('             : revdep-pax -r [-ve]            print out all reverse mappings for all system sonames')
+	print('             : revdep-pax -b OBJECT  [-myv]   print all forward mappings only for OBJECT')
+	print('             : revdep-pax -s SONAME  [-myve]  print all reverse mappings only for SONAME')
+	print('             : revdep-pax -l LIBRARY [-myve]  print all reverse mappings only for LIBRARY file')
+	print('             : revdep-pax [-h]                print out this help')
+	print('             : -v                             verbose, otherwise just print mismatching objects')
+	print('             : -e                             only print out executables in shell $PATH')
+	print('             : -m                             don\'t just report, but mark the mismatching objects')
+	print('             : -y                             assume "yes" to all prompts for making (USE CAREFULLY!)')
+	print()
 
 
 def main():
 	try:
 		opts, args = getopt.getopt(sys.argv[1:], 'hfrb:s:l:vemy')
-	except getopt.GetoptError, err:
-		print str(err) # will print something like 'option -a not recognized'
+	except getopt.GetoptError as err:
+		print(str(err)) # will print something like 'option -a not recognized'
 		run_usage()
 		sys.exit(1)
 
@@ -455,8 +454,8 @@ def main():
 		elif o == '-y':
 			allyes = True
 		else:
-			print 'Option included in getopt but not handled here!'
-			print 'Please file a bug'
+			print('Option included in getopt but not handled here!')
+			print('Please file a bug')
 			sys.exit(1)
 
 	# Only allow one of -h, -f -r -b -s
@@ -470,18 +469,18 @@ def main():
 		try:
 			run_binary(binary, verbose, mark, allyes)
 		except:
-			print 'Please check that %s exists!' % binary
+			print('Please check that %s exists!' % binary)
 	elif soname != None:
 		try:
 			run_soname(soname, verbose, True, mark, allyes, executable_only)
 		except:
-			print 'Please check that %s exists!' % soname
+			print('Please check that %s exists!' % soname)
 	elif library != None:
 		try:
 			library = os.path.realpath(library)
 			run_soname(library, verbose, False, mark, allyes, executable_only)
 		except:
-			print 'Please check that %s exists!' % library
+			print('Please check that %s exists!' % library)
 
 if __name__ == '__main__':
     main()


^ permalink raw reply related	[flat|nested] 89+ messages in thread
* [gentoo-commits] proj/elfix:master commit in: scripts/
@ 2012-07-21 16:28 Anthony G. Basile
  0 siblings, 0 replies; 89+ messages in thread
From: Anthony G. Basile @ 2012-07-21 16:28 UTC (permalink / raw
  To: gentoo-commits

commit:     878bf8d6ea03740a8496b8dc27c5cf2e1a992239
Author:     Anthony G. Basile <blueness <AT> gentoo <DOT> org>
AuthorDate: Sat Jul 21 16:27:54 2012 +0000
Commit:     Anthony G. Basile <blueness <AT> gentoo <DOT> org>
CommitDate: Sat Jul 21 16:27:54 2012 +0000
URL:        http://git.overlays.gentoo.org/gitweb/?p=proj/elfix.git;a=commit;h=878bf8d6

scripts/*: rename setflags to setbinflags

---
 scripts/paxmodule.c |   20 +++++++++++---------
 scripts/pypaxctl    |    2 +-
 scripts/revdep-pax  |    2 +-
 3 files changed, 13 insertions(+), 11 deletions(-)

diff --git a/scripts/paxmodule.c b/scripts/paxmodule.c
index 18c64aa..ba81110 100644
--- a/scripts/paxmodule.c
+++ b/scripts/paxmodule.c
@@ -39,11 +39,13 @@
 
 
 static PyObject * pax_getflags(PyObject *, PyObject *);
-static PyObject * pax_setflags(PyObject *, PyObject *);
+static PyObject * pax_setbinflags(PyObject *, PyObject *);
+static PyObject * pax_setstrflags(PyObject *, PyObject *);
 
 static PyMethodDef PaxMethods[] = {
-	{"getflags",  pax_getflags, METH_VARARGS, "Get the pax flags."},
-	{"setflags",  pax_setflags, METH_VARARGS, "Set the pax flags."},
+	{"getflags",  pax_getflags, METH_VARARGS, "Get the pax flags as a string."},
+	{"setbinflags",  pax_setbinflags, METH_VARARGS, "Set the pax flags using binary."},
+	{"setstrflags",  pax_setstrflags, METH_VARARGS, "Set the pax flags using string."},
 	{NULL, NULL, 0, NULL}
 };
 
@@ -299,7 +301,7 @@ set_xt_flags(int fd, uint16_t xt_flags)
 
 
 static PyObject *
-pax_setflags(PyObject *self, PyObject *args)
+pax_setbinflags(PyObject *self, PyObject *args)
 {
 	const char *f_name;
 	int fd, iflags;
@@ -307,13 +309,13 @@ pax_setflags(PyObject *self, PyObject *args)
 
 	if (!PyArg_ParseTuple(args, "si", &f_name, &iflags))
 	{
-		PyErr_SetString(PaxError, "pax_setflags: PyArg_ParseTuple failed");
+		PyErr_SetString(PaxError, "pax_setbinflags: PyArg_ParseTuple failed");
 		return NULL;
 	}
 
 	if((fd = open(f_name, O_RDWR)) < 0)
 	{
-		PyErr_SetString(PaxError, "pax_setflags: open() failed");
+		PyErr_SetString(PaxError, "pax_setbinflags: open() failed");
 		return NULL;
 	}
 
@@ -333,19 +335,19 @@ pax_setflags(PyObject *self, PyObject *args)
 static PyObject *
 pax_setstrflags(PyObject *self, PyObject *args)
 {
-	const char *f_name, *sflags;
+	char *f_name, *sflags;
 	int fd;
 	uint16_t flags;
 
 	if (!PyArg_ParseTuple(args, "ss", &f_name, &sflags))
 	{
-		PyErr_SetString(PaxError, "pax_setflags: PyArg_ParseTuple failed");
+		PyErr_SetString(PaxError, "pax_setbinflags: PyArg_ParseTuple failed");
 		return NULL;
 	}
 
 	if((fd = open(f_name, O_RDWR)) < 0)
 	{
-		PyErr_SetString(PaxError, "pax_setflags: open() failed");
+		PyErr_SetString(PaxError, "pax_setbinflags: open() failed");
 		return NULL;
 	}
 

diff --git a/scripts/pypaxctl b/scripts/pypaxctl
index 46fee67..5993641 100755
--- a/scripts/pypaxctl
+++ b/scripts/pypaxctl
@@ -37,7 +37,7 @@ def main():
 
 	if( do_set == 1 ):
 		for binary in args:
-			pax.setflags(binary, flags)
+			pax.setstrflags(binary, flags)
 	else:
 		for binary in args:
 			( str_flags, bin_flags ) = pax.getflags(binary)

diff --git a/scripts/revdep-pax b/scripts/revdep-pax
index 76add9c..7de3930 100755
--- a/scripts/revdep-pax
+++ b/scripts/revdep-pax
@@ -241,7 +241,7 @@ def migrate_flags(importer, exporter_str_flags, exporter_bin_flags):
 		if importer_str_flags[i].islower() and exporter_str_flags[i] == '-':
 			result_bin_flags = result_bin_flags | pf_flags[importer_str_flags[i]]
 
-	pax.setflags(importer, result_bin_flags)
+	pax.setbinflags(importer, result_bin_flags)
 
 
 def run_binary(binary, verbose, mark, allyes):


^ permalink raw reply related	[flat|nested] 89+ messages in thread
* [gentoo-commits] proj/elfix:master commit in: scripts/
@ 2012-07-21 15:44 Anthony G. Basile
  0 siblings, 0 replies; 89+ messages in thread
From: Anthony G. Basile @ 2012-07-21 15:44 UTC (permalink / raw
  To: gentoo-commits

commit:     068916ffe880900f18e0c4147c2315ed05b1496e
Author:     Anthony G. Basile <blueness <AT> gentoo <DOT> org>
AuthorDate: Sat Jul 21 15:44:44 2012 +0000
Commit:     Anthony G. Basile <blueness <AT> gentoo <DOT> org>
CommitDate: Sat Jul 21 15:44:44 2012 +0000
URL:        http://git.overlays.gentoo.org/gitweb/?p=proj/elfix.git;a=commit;h=068916ff

scripts/pypaxctl: remove debug code

---
 scripts/pypaxctl |    7 +++----
 1 files changed, 3 insertions(+), 4 deletions(-)

diff --git a/scripts/pypaxctl b/scripts/pypaxctl
index 266a571..46fee67 100755
--- a/scripts/pypaxctl
+++ b/scripts/pypaxctl
@@ -22,11 +22,9 @@ def main():
 
 	for o, a in opts:
 		if o == '-s':
-			#pax.setflags(a, flags)
 			flags = a
 			do_set = 1
 		elif o == '-g':
-			#( str_flags, bin_flags ) = pax.getflags(a)
 			do_get = 1
 
 	if( (do_set + do_get) != 1 ):
@@ -39,10 +37,11 @@ def main():
 
 	if( do_set == 1 ):
 		for binary in args:
-			print('set %s on %s' % (flags,binary))
+			pax.setflags(binary, flags)
 	else:
 		for binary in args:
-			print('get on %s' % binary)
+			( str_flags, bin_flags ) = pax.getflags(binary)
+			print('%s' % str_flags)
 
 if __name__ == '__main__':
 	main()


^ permalink raw reply related	[flat|nested] 89+ messages in thread
* [gentoo-commits] proj/elfix:master commit in: scripts/
@ 2012-07-21 15:41 Anthony G. Basile
  0 siblings, 0 replies; 89+ messages in thread
From: Anthony G. Basile @ 2012-07-21 15:41 UTC (permalink / raw
  To: gentoo-commits

commit:     5090e3d0581d824640b86c7001b97837e22f7aea
Author:     Anthony G. Basile <blueness <AT> gentoo <DOT> org>
AuthorDate: Sat Jul 21 15:40:56 2012 +0000
Commit:     Anthony G. Basile <blueness <AT> gentoo <DOT> org>
CommitDate: Sat Jul 21 15:40:56 2012 +0000
URL:        http://git.overlays.gentoo.org/gitweb/?p=proj/elfix.git;a=commit;h=5090e3d0

scripts/pypaxctl: frontend to pypax module

---
 scripts/Makefile.am |    2 +-
 scripts/pypaxctl    |   48 ++++++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 49 insertions(+), 1 deletions(-)

diff --git a/scripts/Makefile.am b/scripts/Makefile.am
index 5cbc314..c4eef37 100644
--- a/scripts/Makefile.am
+++ b/scripts/Makefile.am
@@ -1,2 +1,2 @@
 dist_sbin_SCRIPTS = revdep-pax
-EXTRA_DIST = paxmodule.c setup.py
+EXTRA_DIST = paxmodule.c setup.py pypaxctl

diff --git a/scripts/pypaxctl b/scripts/pypaxctl
new file mode 100755
index 0000000..266a571
--- /dev/null
+++ b/scripts/pypaxctl
@@ -0,0 +1,48 @@
+#!/usr/bin/env python
+
+import sys
+import getopt
+import pax
+
+def main():
+	try:
+		opts, args = getopt.getopt(sys.argv[1:], 's:g')
+	except getopt.GetoptError as err:
+		print(err)
+		sys.exit(1)
+
+	if len(opts) == 0:
+		print('Provide either -s <flags> <elf> xor -g <elf>')
+		sys.exit(1)
+
+	binary = None
+
+	do_set = 0
+	do_get = 0
+
+	for o, a in opts:
+		if o == '-s':
+			#pax.setflags(a, flags)
+			flags = a
+			do_set = 1
+		elif o == '-g':
+			#( str_flags, bin_flags ) = pax.getflags(a)
+			do_get = 1
+
+	if( (do_set + do_get) != 1 ):
+		print('Provide either -s <flags> <elf> xor -g <elf>')
+		sys.exit(1)
+
+	if( len(args) < 1 ):
+		print('Provide either -s <flags> <elf> xor -g <elf>')
+		sys.exit(1)
+
+	if( do_set == 1 ):
+		for binary in args:
+			print('set %s on %s' % (flags,binary))
+	else:
+		for binary in args:
+			print('get on %s' % binary)
+
+if __name__ == '__main__':
+	main()


^ permalink raw reply related	[flat|nested] 89+ messages in thread
* [gentoo-commits] proj/elfix:master commit in: scripts/
@ 2012-07-21 13:53 Anthony G. Basile
  0 siblings, 0 replies; 89+ messages in thread
From: Anthony G. Basile @ 2012-07-21 13:53 UTC (permalink / raw
  To: gentoo-commits

commit:     4e08c6506212d895fdcac1a0db0843ca2b66fbcc
Author:     Anthony G. Basile <blueness <AT> gentoo <DOT> org>
AuthorDate: Sat Jul 21 13:52:53 2012 +0000
Commit:     Anthony G. Basile <blueness <AT> gentoo <DOT> org>
CommitDate: Sat Jul 21 13:52:53 2012 +0000
URL:        http://git.overlays.gentoo.org/gitweb/?p=proj/elfix.git;a=commit;h=4e08c650

scripts/paxmodule.c: fix FLAGS_SIZE

---
 scripts/paxmodule.c |    8 ++++----
 1 files changed, 4 insertions(+), 4 deletions(-)

diff --git a/scripts/paxmodule.c b/scripts/paxmodule.c
index 3dfc656..bd009dc 100644
--- a/scripts/paxmodule.c
+++ b/scripts/paxmodule.c
@@ -189,9 +189,9 @@ pax_getflags(PyObject *self, PyObject *args)
 	const char *f_name;
 	int fd;
 	uint16_t flags;
-	char buf[BUF_SIZE];
+	char buf[FLAGS_SIZE];
 
-	memset(buf, 0, BUF_SIZE);
+	memset(buf, 0, FLAGS_SIZE);
 
 	if (!PyArg_ParseTuple(args, "s", &f_name))
 	{
@@ -209,7 +209,7 @@ pax_getflags(PyObject *self, PyObject *args)
 	flags = get_xt_flags(fd);
 	if( flags != UINT16_MAX )
 	{
-		memset(buf, 0, BUF_SIZE);
+		memset(buf, 0, FLAGS_SIZE);
 		bin2string(flags, buf);
 	}
 	else
@@ -218,7 +218,7 @@ pax_getflags(PyObject *self, PyObject *args)
 		flags = get_pt_flags(fd);
 		if( flags != UINT16_MAX )
 		{
-			memset(buf, 0, BUF_SIZE);
+			memset(buf, 0, FLAGS_SIZE);
 			bin2string(flags, buf);
 		}
 #ifdef XATTR



^ permalink raw reply related	[flat|nested] 89+ messages in thread
* [gentoo-commits] proj/elfix:master commit in: scripts/
@ 2011-12-28 23:19 Anthony G. Basile
  0 siblings, 0 replies; 89+ messages in thread
From: Anthony G. Basile @ 2011-12-28 23:19 UTC (permalink / raw
  To: gentoo-commits

commit:     58343962c9c0457229b6040d1c45276c2e20dc69
Author:     Anthony G. Basile <blueness <AT> gentoo <DOT> org>
AuthorDate: Wed Dec 28 23:18:28 2011 +0000
Commit:     Anthony G. Basile <blueness <AT> gentoo <DOT> org>
CommitDate: Wed Dec 28 23:18:51 2011 +0000
URL:        http://git.overlays.gentoo.org/gitweb/?p=proj/elfix.git;a=commit;h=58343962

scripts/revdep-pax: cleanup output

---
 scripts/revdep-pax |   12 ++++++++----
 1 files changed, 8 insertions(+), 4 deletions(-)

diff --git a/scripts/revdep-pax b/scripts/revdep-pax
index e22d3a7..b0d8bcc 100755
--- a/scripts/revdep-pax
+++ b/scripts/revdep-pax
@@ -217,13 +217,17 @@ def migrate_flags(importer, exporter_str_flags, exporter_bin_flags):
 
 	for i in range(len(importer_str_flags)):
 		if importer_str_flags[i].isupper() and exporter_str_flags[i].islower():
-			print 'Warning: importer = %s exporter = %s' %  ( importer_str_flags[i], exporter_str_flags[i] )
+			print '\t\tWarning: %s has %s, trying to set to %s' % (
+				importer, importer_str_flags[i], exporter_str_flags[i] ),
 		if importer_str_flags[i].isupper() and exporter_str_flags[i] == '-':
-			print 'Warning: importer = %s exporter = %s' %  ( importer_str_flags[i], exporter_str_flags[i] )
+			print '\t\tWarning: %s has %s, trying to set to %s' % (
+				importer, importer_str_flags[i], exporter_str_flags[i] ),
 		if importer_str_flags[i].islower() and exporter_str_flags[i].isupper():
-			print 'Warning: importer = %s exporter = %s' %  ( importer_str_flags[i], exporter_str_flags[i] )
+			print '\t\tWarning: %s has %s, trying to set to %s' % (
+				importer, importer_str_flags[i], exporter_str_flags[i] ),
 		if importer_str_flags[i].islower() and exporter_str_flags[i] == '-':
-			print 'Warning: importer = %s exporter = %s' %  ( importer_str_flags[i], exporter_str_flags[i] )
+			print '\t\tWarning: %s has %s, trying to set to %s' % (
+				importer, importer_str_flags[i], exporter_str_flags[i] ),
 
 	pax.setflags(importer, result_bin_flags)
 



^ permalink raw reply related	[flat|nested] 89+ messages in thread
* [gentoo-commits] proj/elfix:master commit in: scripts/
@ 2011-12-28 23:18 Anthony G. Basile
  0 siblings, 0 replies; 89+ messages in thread
From: Anthony G. Basile @ 2011-12-28 23:18 UTC (permalink / raw
  To: gentoo-commits

commit:     cb964f970b988964dd3c26dfbdfd489463938517
Author:     Anthony G. Basile <blueness <AT> gentoo <DOT> org>
AuthorDate: Wed Dec 28 23:18:28 2011 +0000
Commit:     Anthony G. Basile <blueness <AT> gentoo <DOT> org>
CommitDate: Wed Dec 28 23:18:28 2011 +0000
URL:        http://git.overlays.gentoo.org/gitweb/?p=proj/elfix.git;a=commit;h=cb964f97

misc/test-revdep-pax/testrevdeppax.sh: further cleanup output

---
 scripts/revdep-pax |   12 ++++++++----
 1 files changed, 8 insertions(+), 4 deletions(-)

diff --git a/scripts/revdep-pax b/scripts/revdep-pax
index e22d3a7..b0d8bcc 100755
--- a/scripts/revdep-pax
+++ b/scripts/revdep-pax
@@ -217,13 +217,17 @@ def migrate_flags(importer, exporter_str_flags, exporter_bin_flags):
 
 	for i in range(len(importer_str_flags)):
 		if importer_str_flags[i].isupper() and exporter_str_flags[i].islower():
-			print 'Warning: importer = %s exporter = %s' %  ( importer_str_flags[i], exporter_str_flags[i] )
+			print '\t\tWarning: %s has %s, trying to set to %s' % (
+				importer, importer_str_flags[i], exporter_str_flags[i] ),
 		if importer_str_flags[i].isupper() and exporter_str_flags[i] == '-':
-			print 'Warning: importer = %s exporter = %s' %  ( importer_str_flags[i], exporter_str_flags[i] )
+			print '\t\tWarning: %s has %s, trying to set to %s' % (
+				importer, importer_str_flags[i], exporter_str_flags[i] ),
 		if importer_str_flags[i].islower() and exporter_str_flags[i].isupper():
-			print 'Warning: importer = %s exporter = %s' %  ( importer_str_flags[i], exporter_str_flags[i] )
+			print '\t\tWarning: %s has %s, trying to set to %s' % (
+				importer, importer_str_flags[i], exporter_str_flags[i] ),
 		if importer_str_flags[i].islower() and exporter_str_flags[i] == '-':
-			print 'Warning: importer = %s exporter = %s' %  ( importer_str_flags[i], exporter_str_flags[i] )
+			print '\t\tWarning: %s has %s, trying to set to %s' % (
+				importer, importer_str_flags[i], exporter_str_flags[i] ),
 
 	pax.setflags(importer, result_bin_flags)
 



^ permalink raw reply related	[flat|nested] 89+ messages in thread
* [gentoo-commits] proj/elfix:master commit in: scripts/
@ 2011-12-28 16:37 Anthony G. Basile
  0 siblings, 0 replies; 89+ messages in thread
From: Anthony G. Basile @ 2011-12-28 16:37 UTC (permalink / raw
  To: gentoo-commits

commit:     6a30317f55891c6d9637a5ac42de0fe9503fff6e
Author:     Anthony G. Basile <blueness <AT> gentoo <DOT> org>
AuthorDate: Wed Dec 28 16:37:17 2011 +0000
Commit:     Anthony G. Basile <blueness <AT> gentoo <DOT> org>
CommitDate: Wed Dec 28 16:37:17 2011 +0000
URL:        http://git.overlays.gentoo.org/gitweb/?p=proj/elfix.git;a=commit;h=6a30317f

scripts/revdep-pax: warn only for complex markings

---
 scripts/revdep-pax |   57 +++++++++++++++++++++++++++++++++++++--------------
 1 files changed, 41 insertions(+), 16 deletions(-)

diff --git a/scripts/revdep-pax b/scripts/revdep-pax
index e2073da..be6a387 100755
--- a/scripts/revdep-pax
+++ b/scripts/revdep-pax
@@ -187,20 +187,45 @@ def run_reverse(verbose, executable_only):
 	print_reverse_linkings( reverse_linkings, so2library_mappings, verbose, executable_only)
 
 
-def migrate_flags(elf, pax_flags):
-	"""
-	Importer	Exporter	Result
-	Force On	Force On	Force On
-	Force On	Force Off	Warn Only
-	Force On	Nothing		Force On
-	Force Off	Force On	Warn Only
-	Force Off	Force Off	Force Off
-	Force Off	Nothing		Force Off
-	Nothing		Force On	Force On
-	Nothing		Force Off	Force Off
-	Nothing		Nothing		Nothing
-	"""
-	pax.setflags(elf, pax_flags)
+def migrate_flags(importer, exporter_str_flags, exporter_bin_flags):
+	# We implement the following logic for setting the pax flags
+	# on the target elf object, the 'importer', given that the
+	# flags from the elf object we want it to match to, the exporter.
+	#
+	#	Importer	Exporter	Result
+	#	Force On	Force On	Force On
+	#	Force On	Force Off	Force On + Warn
+	#	Force On	Nothing		Force On
+	#	Force Off	Force On	Force Off + Warn
+	#	Force Off	Force Off	Force Off
+	#	Force Off	Nothing		Force Off
+	#	Nothing		Force On	Force On
+	#	Nothing		Force Off	Force Off
+	#	Nothing		Nothing		Nothing
+	#
+	# The algorithm proceeds by assuming the resulting flags = the exporter
+	# flags and then changes them in cases where that's not what we want, ie
+	#
+	#	Force On        Force Off       Force On + Warn
+	#	Force On        Nothing         Force On
+	#	Force Off       Force On        Force Off + Warn
+	#	Force Off       Nothing         Force Off
+
+	( importer_str_flags, importer_bin_flags ) = pax.getflags(importer)
+
+	result_bin_flags = exporter_bin_flags
+
+	for i in range(len(importer_str_flags)):
+		if importer_str_flags[i].isupper() and exporter_str_flags[i].islower():
+			print 'Warning: importer = %s exporter = %s' %  ( importer_str_flags[i], exporter_str_flags[i] )
+		if importer_str_flags[i].isupper() and exporter_str_flags[i] == '-':
+			print 'Warning: importer = %s exporter = %s' %  ( importer_str_flags[i], exporter_str_flags[i] )
+		if importer_str_flags[i].islower() and exporter_str_flags[i].isupper():
+			print 'Warning: importer = %s exporter = %s' %  ( importer_str_flags[i], exporter_str_flags[i] )
+		if importer_str_flags[i].islower() and exporter_str_flags[i] == '-':
+			print 'Warning: importer = %s exporter = %s' %  ( importer_str_flags[i], exporter_str_flags[i] )
+
+	pax.setflags(importer, result_bin_flags)
 
 
 def run_binary(binary, verbose, mark):
@@ -246,7 +271,7 @@ def run_binary(binary, verbose, mark):
 
 				if do_marking:
 					try:
-						migrate_flags(library, binary_bin_flags)
+						migrate_flags(library, binary_str_flags, binary_bin_flags)
 					except:
 						print "\n\tCould not set pax flags on %s, file is probably busy" % library
 						print "\tShut down all processes that use it and try again"
@@ -326,7 +351,7 @@ def run_soname(name, verbose, use_soname, mark, executable_only):
 						print '\t\tPlease enter y or n'
 				if do_marking:
 					try:
-						migrate_flags(binary, library_bin_flags)
+						migrate_flags(binary, library_str_flags, library_bin_flags)
 					except:
 						print "\n\tCould not set pax flags on %s, file is probably busy" % binary
 						print "\tShut down all processes that use it and try again"



^ permalink raw reply related	[flat|nested] 89+ messages in thread
* [gentoo-commits] proj/elfix:master commit in: scripts/
@ 2011-12-28 15:39 Anthony G. Basile
  0 siblings, 0 replies; 89+ messages in thread
From: Anthony G. Basile @ 2011-12-28 15:39 UTC (permalink / raw
  To: gentoo-commits

commit:     9de7abb8ed37ab97b0069aedf921c9665dfdd1e5
Author:     Anthony G. Basile <blueness <AT> gentoo <DOT> org>
AuthorDate: Wed Dec 28 15:39:08 2011 +0000
Commit:     Anthony G. Basile <blueness <AT> gentoo <DOT> org>
CommitDate: Wed Dec 28 15:39:08 2011 +0000
URL:        http://git.overlays.gentoo.org/gitweb/?p=proj/elfix.git;a=commit;h=9de7abb8

scripts/revdep-pax: fix missing colon

---
 scripts/revdep-pax |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)

diff --git a/scripts/revdep-pax b/scripts/revdep-pax
index de1fb66..e2073da 100755
--- a/scripts/revdep-pax
+++ b/scripts/revdep-pax
@@ -187,7 +187,7 @@ def run_reverse(verbose, executable_only):
 	print_reverse_linkings( reverse_linkings, so2library_mappings, verbose, executable_only)
 
 
-def migrate_flags(elf, pax_flags)
+def migrate_flags(elf, pax_flags):
 	"""
 	Importer	Exporter	Result
 	Force On	Force On	Force On



^ permalink raw reply related	[flat|nested] 89+ messages in thread
* [gentoo-commits] proj/elfix:master commit in: scripts/
@ 2011-12-28 15:31 Anthony G. Basile
  0 siblings, 0 replies; 89+ messages in thread
From: Anthony G. Basile @ 2011-12-28 15:31 UTC (permalink / raw
  To: gentoo-commits

commit:     362985814ed4b365e7e74a0a6f3178ce95c9f616
Author:     Anthony G. Basile <blueness <AT> gentoo <DOT> org>
AuthorDate: Wed Dec 28 15:31:22 2011 +0000
Commit:     Anthony G. Basile <blueness <AT> gentoo <DOT> org>
CommitDate: Wed Dec 28 15:31:22 2011 +0000
URL:        http://git.overlays.gentoo.org/gitweb/?p=proj/elfix.git;a=commit;h=36298581

scripts/revdep-pax: cleaned up namespace

---
 scripts/revdep-pax |   74 ++++++++++++++++++++++++++--------------------------
 1 files changed, 37 insertions(+), 37 deletions(-)

diff --git a/scripts/revdep-pax b/scripts/revdep-pax
index a4e9396..de1fb66 100755
--- a/scripts/revdep-pax
+++ b/scripts/revdep-pax
@@ -82,8 +82,8 @@ def print_forward_linkings( forward_linkings, so2library_mappings, verbose ):
 	for binary in forward_linkings:
 
 		try:
-			( binary_flags, binary_pax_flags ) = pax.getflags(binary)
-			sv = '%s ( %s )\n' % ( binary, binary_flags )
+			( binary_str_flags, binary_bin_flags ) = pax.getflags(binary)
+			sv = '%s ( %s )\n' % ( binary, binary_str_flags )
 			s = sv
 		except:
 			missing_binaries.append(binary)
@@ -93,10 +93,10 @@ def print_forward_linkings( forward_linkings, so2library_mappings, verbose ):
 		for soname in forward_linkings[binary]:
 			try:
 				library = so2library_mappings[soname]
-				( library_flags, library_pax_flags ) = pax.getflags(library)
-				sv = '%s\n\t%s\t%s ( %s )' % ( sv, soname, library, library_flags )
-				if binary_flags != library_flags:
-					s = '%s\n\t%s\t%s ( %s )' % ( s, soname, library, library_flags )
+				( library_str_flags, library_bin_flags ) = pax.getflags(library)
+				sv = '%s\n\t%s\t%s ( %s )' % ( sv, soname, library, library_str_flags )
+				if binary_str_flags != library_str_flags:
+					s = '%s\n\t%s\t%s ( %s )' % ( s, soname, library, library_str_flags )
 					count = count + 1
 			except:
 				missing_links.append(soname)
@@ -130,8 +130,8 @@ def print_reverse_linkings( reverse_linkings, so2library_mappings, verbose, exec
 	for soname in reverse_linkings:
 		try:
 			library = so2library_mappings[soname]
-			( library_flags, library_pax_flags ) = pax.getflags(library)
-			sv = '%s\t%s ( %s )\n' % ( soname, library, library_flags )
+			( library_str_flags, library_bin_flags ) = pax.getflags(library)
+			sv = '%s\t%s ( %s )\n' % ( soname, library, library_str_flags )
 			s = sv
 		except:
 			missing_sonames.append(soname)
@@ -140,17 +140,17 @@ def print_reverse_linkings( reverse_linkings, so2library_mappings, verbose, exec
 		count = 0
 		for binary in reverse_linkings[soname]:
 			try:
-				( binary_flags, binary_pax_flags ) = pax.getflags(binary)
+				( binary_str_flags, binary_bin_flags ) = pax.getflags(binary)
 				if executable_only:
 					if os.path.dirname(binary) in shell_path:	
-						sv = '%s\n\t%s ( %s )' % ( sv, binary, binary_flags )
-						if library_flags != binary_flags:
-							s = '%s\n\t%s ( %s )' % ( s, binary, binary_flags )
+						sv = '%s\n\t%s ( %s )' % ( sv, binary, binary_str_flags )
+						if library_str_flags != binary_str_flags:
+							s = '%s\n\t%s ( %s )' % ( s, binary, binary_str_flags )
 							count = count + 1
 				else:
-					sv = '%s\n\t%s ( %s )' % ( sv, binary, binary_flags )
-					if library_flags != binary_flags:
-						s = '%s\n\t%s ( %s )' % ( s, binary, binary_flags )
+					sv = '%s\n\t%s ( %s )' % ( sv, binary, binary_str_flags )
+					if library_str_flags != binary_str_flags:
+						s = '%s\n\t%s ( %s )' % ( s, binary, binary_str_flags )
 						count = count + 1
 			except:
 				missing_links.append(binary)
@@ -205,21 +205,21 @@ def migrate_flags(elf, pax_flags)
 
 def run_binary(binary, verbose, mark):
 	( linkings, mappings ) = get_ldd_linkings(binary)
-	( binary_flags, binary_pax_flags ) = pax.getflags(binary)
-	print '%s (%s)\n' % ( binary, binary_flags )
+	( binary_str_flags, binary_bin_flags ) = pax.getflags(binary)
+	print '%s (%s)\n' % ( binary, binary_str_flags )
 
 	mismatched_libraries = []
 
 	for soname in linkings:
 		try:
 			library = mappings[soname]
-			( library_flags, library_pax_flags ) = pax.getflags(library)
+			( library_str_flags, library_bin_flags ) = pax.getflags(library)
 			if verbose:
-				print '\t%s\t%s ( %s )' % ( soname, library, library_flags )
-			if binary_flags != library_flags:
+				print '\t%s\t%s ( %s )' % ( soname, library, library_str_flags )
+			if binary_str_flags != library_str_flags:
 				mismatched_libraries.append(library)
 				if not verbose:
-					print '\t%s\t%s ( %s )' % ( soname, library, library_flags )
+					print '\t%s\t%s ( %s )' % ( soname, library, library_str_flags )
 		except:
 			print 'file for soname %s not found' % soname
 
@@ -229,7 +229,7 @@ def run_binary(binary, verbose, mark):
 	else:
 		print
 		if mark:
-			print '\tWill mark libraries with %s' % binary_flags
+			print '\tWill mark libraries with %s' % binary_str_flags
 			print
 			for library in mismatched_libraries:
 				do_marking = False
@@ -246,12 +246,12 @@ def run_binary(binary, verbose, mark):
 
 				if do_marking:
 					try:
-						migrate_flags(library, binary_pax_flags)
+						migrate_flags(library, binary_bin_flags)
 					except:
 						print "\n\tCould not set pax flags on %s, file is probably busy" % library
 						print "\tShut down all processes that use it and try again"
-					( library_flags, library_pax_flags ) = pax.getflags(library)
-					print '\n\t\t%s ( %s )\n' % ( library, library_flags )
+					( library_str_flags, library_bin_flags ) = pax.getflags(library)
+					print '\n\t\t%s ( %s )\n' % ( library, library_str_flags )
 
 
 def invert_so2library_mappings( so2library_mappings ):
@@ -276,29 +276,29 @@ def run_soname(name, verbose, use_soname, mark, executable_only):
 	linkings = reverse_linkings[soname]
 	library = so2library_mappings[soname]
 
-	( library_flags, library_pax_flags ) = pax.getflags(library)
-	print '%s\t%s (%s)\n' % ( soname, library, library_flags )
+	( library_str_flags, library_bin_flags ) = pax.getflags(library)
+	print '%s\t%s (%s)\n' % ( soname, library, library_str_flags )
 
 	mismatched_binaries = []
 	for binary in linkings:
 		try:
-			( binary_flags, binary_pax_flags ) = pax.getflags(binary)
+			( binary_str_flags, binary_bin_flags ) = pax.getflags(binary)
 			if verbose:
 				if executable_only:
 					if os.path.dirname(binary) in shell_path:	
-						print '\t%s ( %s )' % ( binary, binary_flags )
+						print '\t%s ( %s )' % ( binary, binary_str_flags )
 				else:
-					print '\t%s ( %s )' % ( binary, binary_flags )
-			if library_flags != binary_flags:
+					print '\t%s ( %s )' % ( binary, binary_str_flags )
+			if library_str_flags != binary_str_flags:
 				if executable_only:
 					if os.path.dirname(binary) in shell_path:	
 						mismatched_binaries.append(binary)
 						if not verbose:
-							print '\t%s ( %s )' % ( binary, binary_flags )
+							print '\t%s ( %s )' % ( binary, binary_str_flags )
 				else:
 					mismatched_binaries.append(binary)
 					if not verbose:
-						print '\t%s ( %s )' % ( binary, binary_flags )
+						print '\t%s ( %s )' % ( binary, binary_str_flags )
 		except:
 			print 'cannot obtain pax flags for %s' % binary
 
@@ -308,7 +308,7 @@ def run_soname(name, verbose, use_soname, mark, executable_only):
 	else:
 		print
 		if mark:
-			print '\tWill mark binaries with %s\n' % library_flags
+			print '\tWill mark binaries with %s\n' % library_str_flags
 			for binary in mismatched_binaries:
 				if executable_only:
 					if not os.path.dirname(binary) in shell_path:
@@ -326,12 +326,12 @@ def run_soname(name, verbose, use_soname, mark, executable_only):
 						print '\t\tPlease enter y or n'
 				if do_marking:
 					try:
-						migrate_flags(binary, library_pax_flags)
+						migrate_flags(binary, library_bin_flags)
 					except:
 						print "\n\tCould not set pax flags on %s, file is probably busy" % binary
 						print "\tShut down all processes that use it and try again"
-					( binary_flags, binary_pax_flags ) = pax.getflags(binary)
-					print '\n\t\t%s ( %s )\n' % ( binary, binary_flags )
+					( binary_str_flags, binary_bin_flags ) = pax.getflags(binary)
+					print '\n\t\t%s ( %s )\n' % ( binary, binary_str_flags )
 
 
 def run_usage():



^ permalink raw reply related	[flat|nested] 89+ messages in thread
* [gentoo-commits] proj/elfix:master commit in: scripts/
@ 2011-12-26 22:24 Anthony G. Basile
  0 siblings, 0 replies; 89+ messages in thread
From: Anthony G. Basile @ 2011-12-26 22:24 UTC (permalink / raw
  To: gentoo-commits

commit:     dc3ff5d76ec1dafbbd1b5068d888c6c042310366
Author:     Anthony G. Basile <blueness <AT> gentoo <DOT> org>
AuthorDate: Mon Dec 26 22:23:57 2011 +0000
Commit:     Anthony G. Basile <blueness <AT> gentoo <DOT> org>
CommitDate: Mon Dec 26 22:23:57 2011 +0000
URL:        http://git.overlays.gentoo.org/gitweb/?p=proj/elfix.git;a=commit;h=dc3ff5d7

scripts/revdep-pax: wrap pax.setflags() to allow complex logic

---
 scripts/revdep-pax |   20 ++++++++++++++++++--
 1 files changed, 18 insertions(+), 2 deletions(-)

diff --git a/scripts/revdep-pax b/scripts/revdep-pax
index 3d8e213..a4e9396 100755
--- a/scripts/revdep-pax
+++ b/scripts/revdep-pax
@@ -187,6 +187,22 @@ def run_reverse(verbose, executable_only):
 	print_reverse_linkings( reverse_linkings, so2library_mappings, verbose, executable_only)
 
 
+def migrate_flags(elf, pax_flags)
+	"""
+	Importer	Exporter	Result
+	Force On	Force On	Force On
+	Force On	Force Off	Warn Only
+	Force On	Nothing		Force On
+	Force Off	Force On	Warn Only
+	Force Off	Force Off	Force Off
+	Force Off	Nothing		Force Off
+	Nothing		Force On	Force On
+	Nothing		Force Off	Force Off
+	Nothing		Nothing		Nothing
+	"""
+	pax.setflags(elf, pax_flags)
+
+
 def run_binary(binary, verbose, mark):
 	( linkings, mappings ) = get_ldd_linkings(binary)
 	( binary_flags, binary_pax_flags ) = pax.getflags(binary)
@@ -230,7 +246,7 @@ def run_binary(binary, verbose, mark):
 
 				if do_marking:
 					try:
-						pax.setflags(library, binary_pax_flags)
+						migrate_flags(library, binary_pax_flags)
 					except:
 						print "\n\tCould not set pax flags on %s, file is probably busy" % library
 						print "\tShut down all processes that use it and try again"
@@ -310,7 +326,7 @@ def run_soname(name, verbose, use_soname, mark, executable_only):
 						print '\t\tPlease enter y or n'
 				if do_marking:
 					try:
-						pax.setflags(binary, library_pax_flags)
+						migrate_flags(binary, library_pax_flags)
 					except:
 						print "\n\tCould not set pax flags on %s, file is probably busy" % binary
 						print "\tShut down all processes that use it and try again"



^ permalink raw reply related	[flat|nested] 89+ messages in thread
* [gentoo-commits] proj/elfix:master commit in: scripts/
@ 2011-12-26 20:25 Anthony G. Basile
  0 siblings, 0 replies; 89+ messages in thread
From: Anthony G. Basile @ 2011-12-26 20:25 UTC (permalink / raw
  To: gentoo-commits

commit:     44e1b3aa6cbb94991cb21e1340dfcb1c439471d1
Author:     Anthony G. Basile <blueness <AT> gentoo <DOT> org>
AuthorDate: Mon Dec 26 20:11:06 2011 +0000
Commit:     Anthony G. Basile <blueness <AT> gentoo <DOT> org>
CommitDate: Mon Dec 26 20:11:06 2011 +0000
URL:        http://git.overlays.gentoo.org/gitweb/?p=proj/elfix.git;a=commit;h=44e1b3aa

scripts/revdep-pax: die elegantly if binary/library/soname is not found

---
 scripts/revdep-pax |   17 +++++++++++++----
 1 files changed, 13 insertions(+), 4 deletions(-)

diff --git a/scripts/revdep-pax b/scripts/revdep-pax
index 1fe28ab..3d8e213 100755
--- a/scripts/revdep-pax
+++ b/scripts/revdep-pax
@@ -400,12 +400,21 @@ def main():
 	elif do_reverse:
 		run_reverse(verbose, executable_only)
 	elif binary != None:
-		run_binary(binary, verbose, mark)
+		try:
+			run_binary(binary, verbose, mark)
+		except:
+			print 'Please check that %s exists!' % binary
 	elif soname != None:
-		run_soname(soname, verbose, True, mark, executable_only)
+		try:
+			run_soname(soname, verbose, True, mark, executable_only)
+		except:
+			print 'Please check that %s exists!' % soname
 	elif library != None:
-		library = os.path.realpath(library)
-		run_soname(library, verbose, False, mark, executable_only)
+		try:
+			library = os.path.realpath(library)
+			run_soname(library, verbose, False, mark, executable_only)
+		except:
+			print 'Please check that %s exists!' % library
 
 if __name__ == '__main__':
     main()



^ permalink raw reply related	[flat|nested] 89+ messages in thread
* [gentoo-commits] proj/elfix:master commit in: scripts/
@ 2011-12-04 21:43 Anthony G. Basile
  0 siblings, 0 replies; 89+ messages in thread
From: Anthony G. Basile @ 2011-12-04 21:43 UTC (permalink / raw
  To: gentoo-commits

commit:     6398268cd1a5949cc019711e89dd7c1d81ef29d3
Author:     Anthony G. Basile <blueness <AT> gentoo <DOT> org>
AuthorDate: Sun Dec  4 21:43:46 2011 +0000
Commit:     Anthony G. Basile <blueness <AT> gentoo <DOT> org>
CommitDate: Sun Dec  4 21:43:46 2011 +0000
URL:        http://git.overlays.gentoo.org/gitweb/?p=proj/elfix.git;a=commit;h=6398268c

scripts/revdep-pax: add exception handling when doing pax.setflags

---
 scripts/revdep-pax |   45 +++++++++++++++++++++------------------------
 1 files changed, 21 insertions(+), 24 deletions(-)

diff --git a/scripts/revdep-pax b/scripts/revdep-pax
index 42a71fd..1fe28ab 100755
--- a/scripts/revdep-pax
+++ b/scripts/revdep-pax
@@ -114,14 +114,12 @@ def print_forward_linkings( forward_linkings, so2library_mappings, verbose ):
 	missing_binaries = set(missing_binaries)
 	print '\n**** Missing binaries ****\n'
 	for m in missing_binaries:
-		print '\t%s' % m
-	print
+		print '\t%s\n' % m
 
 	missing_links = set(missing_links)
 	print '\n**** Missing forward linkings ****\n'
 	for m in missing_links:
-		print '\t%s' % m
-	print
+		print '\t%s\n' % m
 
 
 def print_reverse_linkings( reverse_linkings, so2library_mappings, verbose, executable_only ):
@@ -170,14 +168,12 @@ def print_reverse_linkings( reverse_linkings, so2library_mappings, verbose, exec
 	missing_sonames = set(missing_sonames)
 	print '\n**** Missing sonames ****\n'
 	for m in missing_sonames:
-		print '\t%s' % m
-	print
+		print '\t%s\n' % m
 
 	missing_links = set(missing_links)
 	print '\n**** Missing reverse linkings ****\n'
 	for m in missing_links:
-		print '\t%s' % m
-	print
+		print '\t%s\n' % m
 
 
 def run_forward(verbose):
@@ -194,8 +190,7 @@ def run_reverse(verbose, executable_only):
 def run_binary(binary, verbose, mark):
 	( linkings, mappings ) = get_ldd_linkings(binary)
 	( binary_flags, binary_pax_flags ) = pax.getflags(binary)
-	print '%s (%s)' % ( binary, binary_flags )
-	print
+	print '%s (%s)\n' % ( binary, binary_flags )
 
 	mismatched_libraries = []
 
@@ -214,8 +209,7 @@ def run_binary(binary, verbose, mark):
 
 	if len(mismatched_libraries) == 0:
 		if not verbose:
-			print '\tNo mismatches'
-		print
+			print '\tNo mismatches\n'
 	else:
 		print
 		if mark:
@@ -235,10 +229,13 @@ def run_binary(binary, verbose, mark):
 						print '\t\tPlease enter y or n'
 
 				if do_marking:
-					pax.setflags(library, binary_pax_flags)
+					try:
+						pax.setflags(library, binary_pax_flags)
+					except:
+						print "\n\tCould not set pax flags on %s, file is probably busy" % library
+						print "\tShut down all processes that use it and try again"
 					( library_flags, library_pax_flags ) = pax.getflags(library)
-					print '\t%s ( %s )' % ( library, library_flags )
-					print
+					print '\n\t\t%s ( %s )\n' % ( library, library_flags )
 
 
 def invert_so2library_mappings( so2library_mappings ):
@@ -264,8 +261,7 @@ def run_soname(name, verbose, use_soname, mark, executable_only):
 	library = so2library_mappings[soname]
 
 	( library_flags, library_pax_flags ) = pax.getflags(library)
-	print '%s\t%s (%s)' % ( soname, library, library_flags )
-	print
+	print '%s\t%s (%s)\n' % ( soname, library, library_flags )
 
 	mismatched_binaries = []
 	for binary in linkings:
@@ -292,13 +288,11 @@ def run_soname(name, verbose, use_soname, mark, executable_only):
 
 	if len(mismatched_binaries) == 0:
 		if not verbose:
-			print '\tNo mismatches'
-		print
+			print '\tNo mismatches\n'
 	else:
 		print
 		if mark:
-			print '\tWill mark binaries with %s' % library_flags
-			print
+			print '\tWill mark binaries with %s\n' % library_flags
 			for binary in mismatched_binaries:
 				if executable_only:
 					if not os.path.dirname(binary) in shell_path:
@@ -315,10 +309,13 @@ def run_soname(name, verbose, use_soname, mark, executable_only):
 					else:
 						print '\t\tPlease enter y or n'
 				if do_marking:
-					pax.setflags(binary, library_pax_flags)
+					try:
+						pax.setflags(binary, library_pax_flags)
+					except:
+						print "\n\tCould not set pax flags on %s, file is probably busy" % binary
+						print "\tShut down all processes that use it and try again"
 					( binary_flags, binary_pax_flags ) = pax.getflags(binary)
-					print '\t%s ( %s )' % ( binary, binary_flags )
-					print
+					print '\n\t\t%s ( %s )\n' % ( binary, binary_flags )
 
 
 def run_usage():



^ permalink raw reply related	[flat|nested] 89+ messages in thread
* [gentoo-commits] proj/elfix:master commit in: scripts/
@ 2011-11-27  0:17 Anthony G. Basile
  0 siblings, 0 replies; 89+ messages in thread
From: Anthony G. Basile @ 2011-11-27  0:17 UTC (permalink / raw
  To: gentoo-commits

commit:     126136fabaa7f90ff7d987ae6453ba0d1bb5f720
Author:     Anthony G. Basile <blueness <AT> gentoo <DOT> org>
AuthorDate: Sun Nov 27 00:17:19 2011 +0000
Commit:     Anthony G. Basile <blueness <AT> gentoo <DOT> org>
CommitDate: Sun Nov 27 00:17:19 2011 +0000
URL:        http://git.overlays.gentoo.org/gitweb/?p=proj/elfix.git;a=commit;h=126136fa

scripts/{setup.py,paxmodule.c}: build with/without xattr support

---
 scripts/paxmodule.c |   17 +++++++++++++++++
 scripts/setup.py    |   22 +++++++++++++++++-----
 2 files changed, 34 insertions(+), 5 deletions(-)

diff --git a/scripts/paxmodule.c b/scripts/paxmodule.c
index a106ff5..b665412 100644
--- a/scripts/paxmodule.c
+++ b/scripts/paxmodule.c
@@ -21,7 +21,10 @@
 #include <string.h>
 
 #include <gelf.h>
+
+#ifdef XATTR
 #include <attr/xattr.h>
+#endif
 
 #include <sys/types.h>
 #include <sys/stat.h>
@@ -29,7 +32,10 @@
 #include <unistd.h>
 
 #define BUF_SIZE	7	//Buffer size for holding human readable flags
+
+#ifdef XATTR
 #define PAX_NAMESPACE	"user.pax"
+#endif
 
 
 static PyObject * pax_getflags(PyObject *, PyObject *);
@@ -106,6 +112,7 @@ get_pt_flags(int fd)
 }
 
 
+#ifdef XATTR
 uint16_t
 get_xt_flags(int fd)
 {
@@ -114,6 +121,7 @@ get_xt_flags(int fd)
 	fgetxattr(fd, PAX_NAMESPACE, &xt_flags, sizeof(uint16_t));
 	return xt_flags;
 }
+#endif
 
 
 void
@@ -161,6 +169,7 @@ pax_getflags(PyObject *self, PyObject *args)
 		return NULL;
 	}
 
+#ifdef XATTR
 	flags = get_xt_flags(fd);
 	if( flags != UINT16_MAX )
 	{
@@ -169,13 +178,16 @@ pax_getflags(PyObject *self, PyObject *args)
 	}
 	else
 	{
+#endif
 		flags = get_pt_flags(fd);
 		if( flags != UINT16_MAX )
 		{
 			memset(buf, 0, BUF_SIZE);
 			bin2string(flags, buf);
 		}
+#ifdef XATTR
 	}
+#endif
 
 	close(fd);
 
@@ -237,11 +249,13 @@ set_pt_flags(int fd, uint16_t pt_flags)
 }
 
 
+#ifdef XATTR
 void
 set_xt_flags(int fd, uint16_t xt_flags)
 {
 	fsetxattr(fd, PAX_NAMESPACE, &xt_flags, sizeof(uint16_t), 0);
 }
+#endif
 
 
 static PyObject *
@@ -266,7 +280,10 @@ pax_setflags(PyObject *self, PyObject *args)
 	flags = (uint16_t) iflags;
 
 	set_pt_flags(fd, flags);
+
+#ifdef XATTR
 	set_xt_flags(fd, flags);
+#endif
 
 	close(fd);
 

diff --git a/scripts/setup.py b/scripts/setup.py
index 3170930..40aecdb 100755
--- a/scripts/setup.py
+++ b/scripts/setup.py
@@ -1,12 +1,24 @@
 #!/usr/bin/env python
 
+import os
 from distutils.core import setup, Extension
 
-module1 = Extension(
-	name='pax',
-	sources = ['paxmodule.c'],
-	libraries = ['elf', 'attr'],
-)
+xattr = os.getenv('XATTR')
+
+if xattr != None:
+	module1 = Extension(
+		name='pax',
+		sources = ['paxmodule.c'],
+		libraries = ['elf', 'attr'],
+		define_macros = [('XATTR', None)]
+	)
+else:
+	module1 = Extension(
+		name='pax',
+		sources = ['paxmodule.c'],
+		libraries = ['elf'],
+		undef_macros = ['XATTR']
+	)
 
 setup(
 	name = 'PaxPython',



^ permalink raw reply related	[flat|nested] 89+ messages in thread
* [gentoo-commits] proj/elfix:master commit in: scripts/
@ 2011-11-26 22:08 Anthony G. Basile
  0 siblings, 0 replies; 89+ messages in thread
From: Anthony G. Basile @ 2011-11-26 22:08 UTC (permalink / raw
  To: gentoo-commits

commit:     184d68204ec67ea30c56921a25011e8128bb6e03
Author:     Anthony G. Basile <blueness <AT> gentoo <DOT> org>
AuthorDate: Sat Nov 26 22:08:39 2011 +0000
Commit:     Anthony G. Basile <blueness <AT> gentoo <DOT> org>
CommitDate: Sat Nov 26 22:08:39 2011 +0000
URL:        http://git.overlays.gentoo.org/gitweb/?p=proj/elfix.git;a=commit;h=184d6820

scripts/revdep-pax: fix parameter order for run_soname

---
 scripts/revdep-pax |    6 +++---
 1 files changed, 3 insertions(+), 3 deletions(-)

diff --git a/scripts/revdep-pax b/scripts/revdep-pax
index a6d2564..fdc96fe 100755
--- a/scripts/revdep-pax
+++ b/scripts/revdep-pax
@@ -262,7 +262,7 @@ def invert_so2library_mappings( so2library_mappings ):
 	return library2soname_mappings
 
 
-def run_soname(name, verbose, use_soname, executable_only, mark):
+def run_soname(name, verbose, use_soname, mark, executable_only):
 	shell_path = path = os.getenv('PATH').split(':')
 
 	( forward_linkings, so2library_mappings ) = get_forward_linkings()
@@ -415,10 +415,10 @@ def main():
 	elif binary != None:
 		run_binary(binary, verbose, mark)
 	elif soname != None:
-		run_soname(soname, verbose, executable_only, True, mark)
+		run_soname(soname, verbose, True, mark, executable_only)
 	elif library != None:
 		library = os.path.realpath(library)
-		run_soname(library, verbose, executable_only, False, mark)
+		run_soname(library, verbose, False, mark, executable_only)
 
 if __name__ == '__main__':
     main()



^ permalink raw reply related	[flat|nested] 89+ messages in thread
* [gentoo-commits] proj/elfix:master commit in: scripts/
@ 2011-11-26 21:15 Anthony G. Basile
  0 siblings, 0 replies; 89+ messages in thread
From: Anthony G. Basile @ 2011-11-26 21:15 UTC (permalink / raw
  To: gentoo-commits

commit:     031b81ac66ffbea83392ab406fa8f41e7b72cf33
Author:     Anthony G. Basile <blueness <AT> gentoo <DOT> org>
AuthorDate: Sat Nov 26 21:15:37 2011 +0000
Commit:     Anthony G. Basile <blueness <AT> gentoo <DOT> org>
CommitDate: Sat Nov 26 21:15:37 2011 +0000
URL:        http://git.overlays.gentoo.org/gitweb/?p=proj/elfix.git;a=commit;h=031b81ac

scripts/revdep-pax: cosmetic cleanup for -f and -r output

---
 scripts/revdep-pax |    6 ++----
 1 files changed, 2 insertions(+), 4 deletions(-)

diff --git a/scripts/revdep-pax b/scripts/revdep-pax
index 70e8db7..a6d2564 100755
--- a/scripts/revdep-pax
+++ b/scripts/revdep-pax
@@ -112,8 +112,7 @@ def print_forward_linkings( forward_linkings, so2library_mappings, verbose ):
 		else:
 			if count != 0:
 				print s
-
-	print
+				print
 
 	missing_binaries = set(missing_binaries)
 	print
@@ -173,8 +172,7 @@ def print_reverse_linkings( reverse_linkings, so2library_mappings, verbose, exec
 		else:
 			if count != 0:
 				print s
-
-	print
+				print
 
 	missing_sonames = set(missing_sonames)
 	print



^ permalink raw reply related	[flat|nested] 89+ messages in thread
* [gentoo-commits] proj/elfix:master commit in: scripts/
@ 2011-11-26 19:08 Anthony G. Basile
  0 siblings, 0 replies; 89+ messages in thread
From: Anthony G. Basile @ 2011-11-26 19:08 UTC (permalink / raw
  To: gentoo-commits

commit:     5842245558f2b65bcfd0d4f0fa1739cbbb1cd02e
Author:     Anthony G. Basile <blueness <AT> gentoo <DOT> org>
AuthorDate: Sat Nov 26 19:07:10 2011 +0000
Commit:     Anthony G. Basile <blueness <AT> gentoo <DOT> org>
CommitDate: Sat Nov 26 19:08:35 2011 +0000
URL:        http://git.overlays.gentoo.org/gitweb/?p=proj/elfix.git;a=commit;h=58422455

scripts/revdep-pax: improved -e switch, mark only for shell PATH

---
 scripts/revdep-pax |    3 +++
 1 files changed, 3 insertions(+), 0 deletions(-)

diff --git a/scripts/revdep-pax b/scripts/revdep-pax
index 827d700..70e8db7 100755
--- a/scripts/revdep-pax
+++ b/scripts/revdep-pax
@@ -312,6 +312,9 @@ def run_soname(name, verbose, use_soname, executable_only, mark):
 			print '\tWill mark binaries with %s' % library_flags
 			print
 			for binary in mismatched_binaries:
+				if executable_only:
+					if not os.path.dirname(binary) in shell_path:
+						continue
 				do_marking = False
 				while True:
 					ans = raw_input('\tSet flags for %s (y/n): ' % binary)



^ permalink raw reply related	[flat|nested] 89+ messages in thread
* [gentoo-commits] proj/elfix:master commit in: scripts/
@ 2011-11-26 19:07 Anthony G. Basile
  0 siblings, 0 replies; 89+ messages in thread
From: Anthony G. Basile @ 2011-11-26 19:07 UTC (permalink / raw
  To: gentoo-commits

commit:     d2886d4890893c5b11dd04ea912dfd36f67dc308
Author:     Anthony G. Basile <blueness <AT> gentoo <DOT> org>
AuthorDate: Sat Nov 26 19:07:10 2011 +0000
Commit:     Anthony G. Basile <blueness <AT> gentoo <DOT> org>
CommitDate: Sat Nov 26 19:07:10 2011 +0000
URL:        http://git.overlays.gentoo.org/gitweb/?p=proj/elfix.git;a=commit;h=d2886d48

scripts/revdep-pax: improved -e switch, mark only for shell PATH

---
 scripts/revdep-pax |    3 +++
 1 files changed, 3 insertions(+), 0 deletions(-)

diff --git a/scripts/revdep-pax b/scripts/revdep-pax
index 827d700..70e8db7 100755
--- a/scripts/revdep-pax
+++ b/scripts/revdep-pax
@@ -312,6 +312,9 @@ def run_soname(name, verbose, use_soname, executable_only, mark):
 			print '\tWill mark binaries with %s' % library_flags
 			print
 			for binary in mismatched_binaries:
+				if executable_only:
+					if not os.path.dirname(binary) in shell_path:
+						continue
 				do_marking = False
 				while True:
 					ans = raw_input('\tSet flags for %s (y/n): ' % binary)



^ permalink raw reply related	[flat|nested] 89+ messages in thread
* [gentoo-commits] proj/elfix:master commit in: scripts/
@ 2011-10-17 20:15 Anthony G. Basile
  0 siblings, 0 replies; 89+ messages in thread
From: Anthony G. Basile @ 2011-10-17 20:15 UTC (permalink / raw
  To: gentoo-commits

commit:     5727bf4f28fcb728439c3f9e8567d6045830f480
Author:     Anthony G. Basile <blueness <AT> gentoo <DOT> org>
AuthorDate: Mon Oct 17 20:15:42 2011 +0000
Commit:     Anthony G. Basile <blueness <AT> gentoo <DOT> org>
CommitDate: Mon Oct 17 20:15:42 2011 +0000
URL:        http://git.overlays.gentoo.org/gitweb/?p=proj/elfix.git;a=commit;h=5727bf4f

scripts/revdep-pax: extend setting flags to reverse mappings

---
 scripts/revdep-pax |   34 +++++++++++++++++++++++++++-------
 1 files changed, 27 insertions(+), 7 deletions(-)

diff --git a/scripts/revdep-pax b/scripts/revdep-pax
index 7a8da3e..a5636bd 100755
--- a/scripts/revdep-pax
+++ b/scripts/revdep-pax
@@ -301,20 +301,20 @@ def run_soname(name, verbose, use_soname, mark):
 	print soname, '\t', library, '(', library_flags, ')'
 	print
 
-	count = 0
+	mismatched_binaries = []
 	for binary in linkings:
 		try:
 			( binary_flags, binary_pax_flags ) = pax.getflags(binary)
 			if verbose:
-				print '\t', binary, '(', binary_flags, ')'
-			else:
-				if library_flags != binary_flags:
-					print '\t', binary, '(', binary_flags, ')'
-					count = count + 1
+				print '\t%s ( %s )' % ( binary, binary_flags )
+			if library_flags != binary_flags:
+				mismatched_binaries.append(binary)
+				if not verbose:
+					print '\t%s ( %s )' % ( binary, binary_flags )
 		except:
 			print 'cannot obtain pax flags for %s' % binary
 
-	if count == 0:
+	if len(mismatched_binaries) == 0
 		print
 		print '\tNo mismatches'
 		print
@@ -322,6 +322,26 @@ def run_soname(name, verbose, use_soname, mark):
 		print
 		print '\tMismatches'
 		print
+		if mark:
+			print '\tWill mark binaries with %s' % library_flags
+			print
+			for binary in mismatched_binaries:
+				do_marking = False
+				while True:
+					ans = raw_input('\tSet flags for %s (y/n): ' % binary)
+					if ans == 'y':
+						do_marking = True
+						break
+					elif ans == 'n':
+						do_marking = False
+						break
+					else:
+						print '\t\tPlease enter y or n'
+				if do_marking:
+					pax.setflags(binary, library_pax_flags)
+					( binary_flags, binary_pax_flags ) = pax.getflags(binary)
+					print '\t%s ( %s )' % ( binary, binary_flags )
+					print
 
 
 def main():



^ permalink raw reply related	[flat|nested] 89+ messages in thread
* [gentoo-commits] proj/elfix:master commit in: scripts/
@ 2011-10-17 19:28 Anthony G. Basile
  0 siblings, 0 replies; 89+ messages in thread
From: Anthony G. Basile @ 2011-10-17 19:28 UTC (permalink / raw
  To: gentoo-commits

commit:     f1097c9e8fc1624799f7a08c7e510e24903f1f7d
Author:     Anthony G. Basile <blueness <AT> gentoo <DOT> org>
AuthorDate: Mon Oct 17 19:28:22 2011 +0000
Commit:     Anthony G. Basile <blueness <AT> gentoo <DOT> org>
CommitDate: Mon Oct 17 19:28:22 2011 +0000
URL:        http://git.overlays.gentoo.org/gitweb/?p=proj/elfix.git;a=commit;h=f1097c9e

scripts/{paxmodule.c,revdep-pax}: add code to set pax flags

---
 scripts/paxmodule.c |  183 +++++++++++----------------------------------------
 scripts/revdep-pax  |  100 +++++++++++++++++-----------
 2 files changed, 101 insertions(+), 182 deletions(-)

diff --git a/scripts/paxmodule.c b/scripts/paxmodule.c
index eac774a..32c8768 100644
--- a/scripts/paxmodule.c
+++ b/scripts/paxmodule.c
@@ -1,6 +1,5 @@
 #include <Python.h>
 
-#include <stdio.h> //remove when you remove printf
 #include <string.h>
 
 #include <gelf.h>
@@ -53,14 +52,13 @@ static PyObject *
 pax_getflags(PyObject *self, PyObject *args)
 {
 	const char *f_name;
-	int fd, sts;
+	int fd;
 	Elf *elf;
 
 	char pax_buf[BUF_SIZE];
+	uint16_t pax_flags;
 
 	GElf_Ehdr ehdr;
-	uint16_t ei_flags;
-
 	GElf_Phdr phdr;
 	char found_pt_pax;
 	size_t i, phnum;
@@ -102,6 +100,8 @@ pax_getflags(PyObject *self, PyObject *args)
 
 
 	found_pt_pax = 0;
+	pax_flags = 0;
+
 	elf_getphdrnum(elf, &phnum);
 	for(i=0; i<phnum; ++i)
 	{
@@ -116,24 +116,25 @@ pax_getflags(PyObject *self, PyObject *args)
 		if(phdr.p_type == PT_PAX_FLAGS)
 		{
 			found_pt_pax = 1;
+			pax_flags = phdr.p_flags;
 
-			pax_buf[0] = phdr.p_flags & PF_PAGEEXEC ? 'P' :
-				phdr.p_flags & PF_NOPAGEEXEC ? 'p' : '-' ;
+			pax_buf[0] = pax_flags & PF_PAGEEXEC ? 'P' :
+				pax_flags & PF_NOPAGEEXEC ? 'p' : '-' ;
 
-			pax_buf[1] = phdr.p_flags & PF_SEGMEXEC   ? 'S' : 
-				phdr.p_flags & PF_NOSEGMEXEC ? 's' : '-';
+			pax_buf[1] = pax_flags & PF_SEGMEXEC   ? 'S' : 
+				pax_flags & PF_NOSEGMEXEC ? 's' : '-';
 
-			pax_buf[2] = phdr.p_flags & PF_MPROTECT   ? 'M' :
-				phdr.p_flags & PF_NOMPROTECT ? 'm' : '-';
+			pax_buf[2] = pax_flags & PF_MPROTECT   ? 'M' :
+				pax_flags & PF_NOMPROTECT ? 'm' : '-';
 
-			pax_buf[3] = phdr.p_flags & PF_EMUTRAMP   ? 'E' :
-				phdr.p_flags & PF_NOEMUTRAMP ? 'e' : '-';
+			pax_buf[3] = pax_flags & PF_EMUTRAMP   ? 'E' :
+				pax_flags & PF_NOEMUTRAMP ? 'e' : '-';
 
-			pax_buf[4] = phdr.p_flags & PF_RANDMMAP   ? 'R' :
-				phdr.p_flags & PF_NORANDMMAP ? 'r' : '-';
+			pax_buf[4] = pax_flags & PF_RANDMMAP   ? 'R' :
+				pax_flags & PF_NORANDMMAP ? 'r' : '-';
 
-			pax_buf[5] = phdr.p_flags & PF_RANDEXEC   ? 'X' :
-				phdr.p_flags & PF_NORANDEXEC ? 'x' : '-';
+			pax_buf[5] = pax_flags & PF_RANDEXEC   ? 'X' :
+				pax_flags & PF_NORANDEXEC ? 'x' : '-';
 		}
 	}
 
@@ -147,20 +148,20 @@ pax_getflags(PyObject *self, PyObject *args)
 			return NULL;
 		}
 
-		ei_flags = ehdr.e_ident[EI_PAX] + (ehdr.e_ident[EI_PAX + 1] << 8);
+		pax_flags = ehdr.e_ident[EI_PAX] + (ehdr.e_ident[EI_PAX + 1] << 8);
 
-  		pax_buf[0] = ei_flags & HF_PAX_PAGEEXEC ? 'p' : 'P';
-		pax_buf[1] = ei_flags & HF_PAX_SEGMEXEC ? 's' : 'S';
-		pax_buf[2] = ei_flags & HF_PAX_MPROTECT ? 'm' : 'M';
-		pax_buf[3] = ei_flags & HF_PAX_EMUTRAMP ? 'E' : 'e';
-		pax_buf[4] = ei_flags & HF_PAX_RANDMMAP ? 'r' : 'R';
-		pax_buf[5] = ei_flags & HF_PAX_RANDEXEC ? 'X' : 'x';
+  		pax_buf[0] = pax_flags & HF_PAX_PAGEEXEC ? 'p' : 'P';
+		pax_buf[1] = pax_flags & HF_PAX_SEGMEXEC ? 's' : 'S';
+		pax_buf[2] = pax_flags & HF_PAX_MPROTECT ? 'm' : 'M';
+		pax_buf[3] = pax_flags & HF_PAX_EMUTRAMP ? 'E' : 'e';
+		pax_buf[4] = pax_flags & HF_PAX_RANDMMAP ? 'r' : 'R';
+		pax_buf[5] = pax_flags & HF_PAX_RANDEXEC ? 'X' : 'x';
 	}
 
 	elf_end(elf);
 	close(fd);
 
-	return Py_BuildValue("s", pax_buf);
+	return Py_BuildValue("si", pax_buf, pax_flags);
 }
 
 
@@ -168,10 +169,11 @@ static PyObject *
 pax_setflags(PyObject *self, PyObject *args)
 {
 	const char *f_name;
-	int pax_flags;
-	int fd, sts;
+	uint16_t pax_flags;
+	int fd;
 
 	Elf *elf;
+
 	GElf_Ehdr ehdr;
 	uint16_t ei_flags;
 
@@ -190,13 +192,13 @@ pax_setflags(PyObject *self, PyObject *args)
 		return NULL;
 	}
 
-	if((fd = open(f_name, O_RDONLY)) < 0)
+	if((fd = open(f_name, O_RDWR)) < 0)
 	{
 		PyErr_SetString(PaxError, "pax_setflags: open() failed");
 		return NULL;
 	}
 
-	if((elf = elf_begin(fd, ELF_C_READ_MMAP, NULL)) == NULL)
+	if((elf = elf_begin(fd, ELF_C_RDWR_MMAP, NULL)) == NULL)
 	{
 		close(fd);
 		PyErr_SetString(PaxError, "pax_setflags: elf_begin() failed");
@@ -211,8 +213,6 @@ pax_setflags(PyObject *self, PyObject *args)
 		return NULL;
 	}
 
-
-
 	if(gelf_getehdr(elf, &ehdr) != &ehdr)
 	{
 		elf_end(elf);
@@ -223,54 +223,48 @@ pax_setflags(PyObject *self, PyObject *args)
 
 	ei_flags = ehdr.e_ident[EI_PAX] + (ehdr.e_ident[EI_PAX + 1] << 8);
 
+	ei_flags &= ~HF_PAX_PAGEEXEC;
+	ei_flags &= ~HF_PAX_SEGMEXEC;
+	ei_flags &= ~HF_PAX_MPROTECT;
+	ei_flags |= HF_PAX_EMUTRAMP;
+	ei_flags &= ~HF_PAX_RANDMMAP;
+	ei_flags |= HF_PAX_RANDEXEC;
+
 	//PAGEEXEC
 	if(pax_flags & PF_PAGEEXEC)
 		ei_flags &= ~HF_PAX_PAGEEXEC;
 	if(pax_flags & PF_NOPAGEEXEC)
 		ei_flags |= HF_PAX_PAGEEXEC;
-	if((pax_flags & PF_PAGEEXEC) && (pax_flags & PF_NOPAGEEXEC))
-		ei_flags &= ~HF_PAX_PAGEEXEC;
 
 	//SEGMEXEC
 	if(pax_flags & PF_SEGMEXEC)
 		ei_flags &= ~HF_PAX_SEGMEXEC;
 	if(pax_flags & PF_NOSEGMEXEC)
 		ei_flags |= HF_PAX_SEGMEXEC;
-	if((pax_flags & PF_SEGMEXEC) && (pax_flags & PF_NOSEGMEXEC))
-		ei_flags &= ~HF_PAX_SEGMEXEC;
 
 	//MPROTECT
 	if(pax_flags & PF_MPROTECT)
 		ei_flags &= ~HF_PAX_MPROTECT;
 	if(pax_flags & PF_NOMPROTECT)
 		ei_flags |= HF_PAX_MPROTECT;
-	if((pax_flags & PF_MPROTECT) && (pax_flags & PF_NOMPROTECT))
-		ei_flags &= ~HF_PAX_MPROTECT;
 
 	//EMUTRAMP
 	if(pax_flags & PF_EMUTRAMP)
 		ei_flags |= HF_PAX_EMUTRAMP;
 	if(pax_flags & PF_NOEMUTRAMP)
 		ei_flags &= ~HF_PAX_EMUTRAMP;
-	if((pax_flags & PF_EMUTRAMP) && (pax_flags & PF_NOEMUTRAMP))
-		ei_flags &= ~HF_PAX_EMUTRAMP;
 
 	//RANDMMAP
 	if(pax_flags & PF_RANDMMAP)
 		ei_flags &= ~HF_PAX_RANDMMAP;
 	if(pax_flags & PF_NORANDMMAP)
 		ei_flags |= HF_PAX_RANDMMAP;
-	if((pax_flags & PF_RANDMMAP) && (pax_flags & PF_NORANDMMAP))
-		ei_flags &= ~HF_PAX_RANDMMAP;
 
 	//RANDEXEC
 	if(pax_flags & PF_RANDEXEC)
 		ei_flags |= HF_PAX_RANDEXEC;
 	if(pax_flags & PF_NORANDEXEC)
 		ei_flags &= ~HF_PAX_RANDEXEC;
-	if((pax_flags & PF_RANDEXEC) && (pax_flags & PF_NORANDEXEC))
-		ei_flags |= HF_PAX_RANDEXEC;
-
 
 	ehdr.e_ident[EI_PAX] = (uint8_t)ei_flags  ;
 	ehdr.e_ident[EI_PAX + 1] = (uint8_t)(ei_flags >> 8) ;
@@ -283,6 +277,7 @@ pax_setflags(PyObject *self, PyObject *args)
 		return NULL;
 	}
 
+
 	elf_getphdrnum(elf, &phnum);
 	for(i=0; i<phnum; ++i)
 	{
@@ -296,107 +291,7 @@ pax_setflags(PyObject *self, PyObject *args)
 
 		if(phdr.p_type == PT_PAX_FLAGS)
 		{
-			//PAGEEXEC
-			if(pax_flags & PF_PAGEEXEC)
-			{
-				phdr.p_flags |= PF_PAGEEXEC;
-				phdr.p_flags &= ~PF_NOPAGEEXEC;
-			}
-			if(pax_flags & PF_NOPAGEEXEC)
-			{
-				phdr.p_flags &= ~PF_PAGEEXEC;
-				phdr.p_flags |= PF_NOPAGEEXEC;
-			}
-			if((pax_flags & PF_PAGEEXEC) && (pax_flags & PF_NOPAGEEXEC))
-			{
-				phdr.p_flags &= ~PF_PAGEEXEC;
-				phdr.p_flags &= ~PF_NOPAGEEXEC;
-			}
-
-			//SEGMEXEC
-			if(pax_flags & PF_SEGMEXEC)
-			{
-				phdr.p_flags |= PF_SEGMEXEC;
-				phdr.p_flags &= ~PF_NOSEGMEXEC;
-			}
-			if(pax_flags & PF_NOSEGMEXEC)
-			{
-				phdr.p_flags &= ~PF_SEGMEXEC;
-				phdr.p_flags |= PF_NOSEGMEXEC;
-			}
-			if((pax_flags & PF_SEGMEXEC) && (pax_flags & PF_NOSEGMEXEC))
-			{
-				phdr.p_flags &= ~PF_SEGMEXEC;
-				phdr.p_flags &= ~PF_NOSEGMEXEC;
-			}
-
-			//MPROTECT
-			if(pax_flags & PF_MPROTECT)
-			{
-				phdr.p_flags |= PF_MPROTECT;
-				phdr.p_flags &= ~PF_NOMPROTECT;
-			}
-			if(pax_flags & PF_NOMPROTECT)
-			{
-				phdr.p_flags &= ~PF_MPROTECT;
-				phdr.p_flags |= PF_NOMPROTECT;
-			}
-			if((pax_flags & PF_MPROTECT) && (pax_flags & PF_NOMPROTECT))
-			{
-				phdr.p_flags &= ~PF_MPROTECT;
-				phdr.p_flags &= ~PF_NOMPROTECT;
-			}
-
-			//EMUTRAMP
-			if(pax_flags & PF_EMUTRAMP)
-			{
-				phdr.p_flags |= PF_EMUTRAMP;
-				phdr.p_flags &= ~PF_NOEMUTRAMP;
-			}
-			if(pax_flags & PF_NOEMUTRAMP)
-			{
-				phdr.p_flags &= ~PF_EMUTRAMP;
-				phdr.p_flags |= PF_NOEMUTRAMP;
-			}
-			if((pax_flags & PF_EMUTRAMP) && (pax_flags & PF_NOEMUTRAMP))
-			{
-				phdr.p_flags &= ~PF_EMUTRAMP;
-				phdr.p_flags &= ~PF_NOEMUTRAMP;
-			}
-
-			//RANDMMAP
-			if(pax_flags & PF_RANDMMAP)
-			{
-				phdr.p_flags |= PF_RANDMMAP;
-				phdr.p_flags &= ~PF_NORANDMMAP;
-			}
-			if(pax_flags & PF_NORANDMMAP)
-			{
-				phdr.p_flags &= ~PF_RANDMMAP;
-				phdr.p_flags |= PF_NORANDMMAP;
-			}
-			if((pax_flags & PF_RANDMMAP) && (pax_flags & PF_NORANDMMAP))
-			{
-				phdr.p_flags &= ~PF_RANDMMAP;
-				phdr.p_flags &= ~PF_NORANDMMAP;
-			}
-
-			//RANDEXEC
-			if(pax_flags & PF_RANDEXEC)
-			{
-				phdr.p_flags |= PF_RANDEXEC;
-				phdr.p_flags &= ~PF_NORANDEXEC;
-			}
-			if(pax_flags & PF_NORANDEXEC)
-			{
-				phdr.p_flags &= ~PF_RANDEXEC;
-				phdr.p_flags |= PF_NORANDEXEC;
-			}
-			if((pax_flags & PF_RANDEXEC) && (pax_flags & PF_NORANDEXEC))
-			{
-				phdr.p_flags &= ~PF_RANDEXEC;
-				phdr.p_flags &= ~PF_NORANDEXEC;
-			}
+			phdr.p_flags = pax_flags;
 
 			if(!gelf_update_phdr(elf, i, &phdr))
 			{

diff --git a/scripts/revdep-pax b/scripts/revdep-pax
index 326007e..7a8da3e 100755
--- a/scripts/revdep-pax
+++ b/scripts/revdep-pax
@@ -8,7 +8,6 @@ import re
 import pax
 
 def get_ldd_linkings(binary):
-
 	try:
 		#TODO: when subprocess.DEVNULL makes it to python, change this: http://bugs.python.org/issue5870
 		ldd_output = subprocess.check_output(['/usr/bin/ldd', binary], stderr=subprocess.PIPE)
@@ -83,8 +82,8 @@ def print_forward_linkings( forward_linkings, so2library_mappings, verbose ):
 	for binary in forward_linkings:
 
 		try:
-			binary_flags = pax.getflags(binary)
-			sv = "%s ( %s )" % ( binary, binary_flags )
+			( binary_flags, binary_pax_flags ) = pax.getflags(binary)
+			sv = '%s ( %s )' % ( binary, binary_flags )
 			s = sv
 		except:
 			missing_binaries.append(binary)
@@ -94,10 +93,10 @@ def print_forward_linkings( forward_linkings, so2library_mappings, verbose ):
 		for soname in forward_linkings[binary]:
 			try:
 				library = so2library_mappings[soname]
-				library_flags = pax.getflags(library)
-				sv = "%s\n\t%s\t%s ( %s )" % ( sv, soname, library, library_flags )
+				( library_flags, library_pax_flags ) = pax.getflags(library)
+				sv = '%s\n\t%s\t%s ( %s )' % ( sv, soname, library, library_flags )
 				if binary_flags != library_flags:
-					s = "%s\n\t%s\t%s ( %s )" % ( s, soname, library, library_flags )
+					s = '%s\n\t%s\t%s ( %s )' % ( s, soname, library, library_flags )
 					count = count + 1
 			except:
 				missing_links.append(soname)
@@ -145,8 +144,8 @@ def print_reverse_linkings( reverse_linkings, so2library_mappings, verbose ):
 
 		try:
 			library = so2library_mappings[soname]
-			library_flags = pax.getflags(library)
-			sv = "%s\t%s ( %s )" % ( soname, library, library_flags )
+			( library_flags, library_pax_flags ) = pax.getflags(library)
+			sv = '%s\t%s ( %s )' % ( soname, library, library_flags )
 			s = sv
 		except:
 			missing_sonames.append(soname)
@@ -155,10 +154,10 @@ def print_reverse_linkings( reverse_linkings, so2library_mappings, verbose ):
 		count = 0
 		for binary in reverse_linkings[soname]:
 			try:
-				binary_flags = pax.getflags(binary)
-				sv = "%s\n\t%s ( %s )" % ( sv, binary, binary_flags )
+				( binary_flags, binary_pax_flags ) = pax.getflags(binary)
+				sv = '%s\n\t%s ( %s )' % ( sv, binary, binary_flags )
 				if library_flags != binary_flags:
-					s = "%s\n\t%s ( %s )" % ( s, binary, binary_flags )
+					s = '%s\n\t%s ( %s )' % ( s, binary, binary_flags )
 					count = count + 1
 			except:
 				missing_links.append(binary)
@@ -203,12 +202,13 @@ def run_usage():
 	print 'Program Name : revdep-pax'
 	print 'Description  : Get or set pax flags on an ELF object'
 	print
-	print 'Usage        : revdep-pax -f [-v]         print out all forward mappings for all system binaries'
-	print '             : revdep-pax -r [-v]         print out all reverse mappints for all system sonames'
-	print '             : revdep-pax -b BINARY [-v]  print all forward mappings only for BINARY'
-	print '             : revdep-pax -s SONAME [-v]  print all reverse mappings only for SONAME'
-	print '             : revdep-pax [-h]            print out this help'
-	print '             : -v                         verbose, otherwise just print mismatched flags'
+	print 'Usage        : revdep-pax -f [-mv]         print out all forward mappings for all system binaries'
+	print '             : revdep-pax -r [-mv]         print out all reverse mappints for all system sonames'
+	print '             : revdep-pax -b BINARY [-mv]  print all forward mappings only for BINARY'
+	print '             : revdep-pax -s SONAME [-mv]  print all reverse mappings only for SONAME'
+	print '             : revdep-pax [-h]             print out this help'
+	print '             : -v                          verbose, otherwise just print mismatched flags'
+	print '             : -m                          prompt to mark the found objects'
 	print
 
 
@@ -225,28 +225,28 @@ def run_reverse(verbose):
 	print
 
 
-def run_binary(binary, verbose):
+def run_binary(binary, verbose, mark):
 	( linkings, mappings ) = get_ldd_linkings(binary)
-
-	binary_flags = pax.getflags(binary)
-	print binary, '(', binary_flags, ')'
+	( binary_flags, binary_pax_flags ) = pax.getflags(binary)
+	print '%s (%s)' % ( binary, binary_flags )
 	print
 
-	count = 0
+	mismatched_libraries = []
+
 	for soname in linkings:
 		try:
 			library = mappings[soname]
-			library_flags = pax.getflags(library)
+			( library_flags, library_pax_flags ) = pax.getflags(library)
 			if verbose:
-				print '\t', soname, '\t', library, '(', library_flags, ')'
-			else:
-				if binary_flags != library_flags:
-					print '\t', soname, '\t', library, '(', library_flags, ')'
-					count = count + 1
+				print '\t%s\t%s ( %s )' % ( soname, library, library_flags )
+			if binary_flags != library_flags:
+				mismatched_libraries.append(library)
+				if not verbose:
+					print '\t%s\t%s ( %s )' % ( soname, library, library_flags )
 		except:
-			print "file for soname %s not found" % soname
+			print 'file for soname %s not found' % soname
 
-	if count == 0:
+	if len(mismatched_libraries) == 0:
 		print
 		print '\tNo mismatches'
 		print
@@ -254,6 +254,27 @@ def run_binary(binary, verbose):
 		print
 		print '\tMismatches'
 		print
+		if mark:
+			print '\tWill mark libraries with %s' % binary_flags
+			print
+			for library in mismatched_libraries:
+				do_marking = False
+				while True:
+					ans = raw_input('\tSet flags for %s (y/n): ' % library)
+					if ans == 'y':
+						do_marking = True
+						break
+					elif ans == 'n':
+						do_marking = False
+						break
+					else:
+						print '\t\tPlease enter y or n'
+
+				if do_marking:
+					pax.setflags(library, binary_pax_flags)
+					( library_flags, library_pax_flags ) = pax.getflags(library)
+					print '\t%s ( %s )' % ( library, library_flags )
+					print
 
 
 def invert_so2library_mappings( so2library_mappings ):
@@ -263,7 +284,7 @@ def invert_so2library_mappings( so2library_mappings ):
 	return library2soname_mappings
 
 
-def run_soname(name, verbose, use_soname):
+def run_soname(name, verbose, use_soname, mark):
 	( forward_linkings, so2library_mappings ) = get_forward_linkings()
 	reverse_linkings = invert_linkings( forward_linkings )
 
@@ -276,14 +297,14 @@ def run_soname(name, verbose, use_soname):
 	linkings = reverse_linkings[soname]
 	library = so2library_mappings[soname]
 
-	library_flags = pax.getflags(library)
+	( library_flags, library_pax_flags ) = pax.getflags(library)
 	print soname, '\t', library, '(', library_flags, ')'
 	print
 
 	count = 0
 	for binary in linkings:
 		try:
-			binary_flags = pax.getflags(binary)
+			( binary_flags, binary_pax_flags ) = pax.getflags(binary)
 			if verbose:
 				print '\t', binary, '(', binary_flags, ')'
 			else:
@@ -291,7 +312,7 @@ def run_soname(name, verbose, use_soname):
 					print '\t', binary, '(', binary_flags, ')'
 					count = count + 1
 		except:
-			print "cannot obtain pax flags for %s" % binary
+			print 'cannot obtain pax flags for %s' % binary
 
 	if count == 0:
 		print
@@ -305,7 +326,7 @@ def run_soname(name, verbose, use_soname):
 
 def main():
 	try:
-		opts, args = getopt.getopt(sys.argv[1:], 'hfrb:s:l:v')
+		opts, args = getopt.getopt(sys.argv[1:], 'hfrb:s:l:vm')
 	except getopt.GetoptError, err:
 		print str(err) # will print something like 'option -a not recognized'
 		run_usage()
@@ -324,6 +345,7 @@ def main():
 	library = None
 
 	verbose = False
+	mark = False
 
 	opt_count = 0
 
@@ -348,6 +370,8 @@ def main():
 			opt_count += 1
 		elif o == '-v':
 			verbose = True
+		elif o == '-m':
+			mark = True
 		else:
 			print 'Option included in getopt but not handled here!'
 			print 'Please file a bug'
@@ -361,12 +385,12 @@ def main():
 	elif do_reverse:
 		run_reverse(verbose)
 	elif binary != None:
-		run_binary(binary, verbose)
+		run_binary(binary, verbose, mark)
 	elif soname != None:
-		run_soname(soname, verbose, True)
+		run_soname(soname, verbose, True, mark)
 	elif library != None:
 		library = os.path.realpath(library)
-		run_soname(library, verbose, False)
+		run_soname(library, verbose, False, mark)
 
 if __name__ == '__main__':
     main()



^ permalink raw reply related	[flat|nested] 89+ messages in thread
* [gentoo-commits] proj/elfix:master commit in: scripts/
@ 2011-10-16 18:27 Anthony G. Basile
  0 siblings, 0 replies; 89+ messages in thread
From: Anthony G. Basile @ 2011-10-16 18:27 UTC (permalink / raw
  To: gentoo-commits

commit:     fa4a83ff1bbde9fabd9250b9e5bbe99d4caaab65
Author:     Anthony G. Basile <blueness <AT> gentoo <DOT> org>
AuthorDate: Sun Oct 16 18:25:54 2011 +0000
Commit:     Anthony G. Basile <blueness <AT> gentoo <DOT> org>
CommitDate: Sun Oct 16 18:26:52 2011 +0000
URL:        http://git.overlays.gentoo.org/gitweb/?p=proj/elfix.git;a=commit;h=fa4a83ff

scripts/revdep-pax: make only one of -f -r -b -s -l allowed

---
 scripts/revdep-pax |   42 +++++++++++++++++++++---------------------
 1 files changed, 21 insertions(+), 21 deletions(-)

diff --git a/scripts/revdep-pax b/scripts/revdep-pax
index e43db27..326007e 100755
--- a/scripts/revdep-pax
+++ b/scripts/revdep-pax
@@ -203,14 +203,12 @@ def run_usage():
 	print 'Program Name : revdep-pax'
 	print 'Description  : Get or set pax flags on an ELF object'
 	print
-	print 'Usage        : revdep-pax [-fv] | [-rv] | -v [-b BINARY] | -v [-s SONAME] | -h'
-	print
-	print 'Options      : -f         print out all the forward mappings for all system binaries'
-	print '             : -r         print out all the reverse mappints for all system sonames'
-	print '             : -b BINARY  print all the forward mappings only for BINARY'
-	print '             : -s SONAME  print all the reverse mappings only for SONAME'
-	print '             : -v         verbose, otherwise just print mismatched pax flags'
-	print '             : -h         print out this help'
+	print 'Usage        : revdep-pax -f [-v]         print out all forward mappings for all system binaries'
+	print '             : revdep-pax -r [-v]         print out all reverse mappints for all system sonames'
+	print '             : revdep-pax -b BINARY [-v]  print all forward mappings only for BINARY'
+	print '             : revdep-pax -s SONAME [-v]  print all reverse mappings only for SONAME'
+	print '             : revdep-pax [-h]            print out this help'
+	print '             : -v                         verbose, otherwise just print mismatched flags'
 	print
 
 
@@ -327,19 +325,27 @@ def main():
 
 	verbose = False
 
+	opt_count = 0
+
 	for o, a in opts:
 		if o == '-h':
 			do_usage = True
+			opt_count += 1
 		elif o == '-f':
 			do_forward = True
+			opt_count += 1
 		elif o == '-r':
 			do_reverse = True
+			opt_count += 1
 		elif o == '-b':
 			binary = a
+			opt_count += 1
 		elif o == '-s':
 			soname = a
+			opt_count += 1
 		elif o == '-l':
 			library = a
+			opt_count += 1
 		elif o == '-v':
 			verbose = True
 		else:
@@ -347,24 +353,18 @@ def main():
 			print 'Please file a bug'
 			sys.exit(1)
 
-	#TODO: Add code to only allow one of -h, -f -r -b -s
-
-	if do_usage:
+	# Only allow one of -h, -f -r -b -s
+	if opt_count > 1 or do_usage:
 		run_usage()
-
-	if do_forward:
+	elif do_forward:
 		run_forward(verbose)
-
-	if do_reverse:
+	elif do_reverse:
 		run_reverse(verbose)
-
-	if binary != None:
+	elif binary != None:
 		run_binary(binary, verbose)
-
-	if soname != None:
+	elif soname != None:
 		run_soname(soname, verbose, True)
-
-	if library != None:
+	elif library != None:
 		library = os.path.realpath(library)
 		run_soname(library, verbose, False)
 



^ permalink raw reply related	[flat|nested] 89+ messages in thread
* [gentoo-commits] proj/elfix:master commit in: scripts/
@ 2011-10-16 18:27 Anthony G. Basile
  0 siblings, 0 replies; 89+ messages in thread
From: Anthony G. Basile @ 2011-10-16 18:27 UTC (permalink / raw
  To: gentoo-commits

commit:     0e550ad6305c42b2112499f74c79afd0fc2da6b2
Author:     Anthony G. Basile <blueness <AT> gentoo <DOT> org>
AuthorDate: Sun Oct 16 18:03:58 2011 +0000
Commit:     Anthony G. Basile <blueness <AT> gentoo <DOT> org>
CommitDate: Sun Oct 16 18:26:45 2011 +0000
URL:        http://git.overlays.gentoo.org/gitweb/?p=proj/elfix.git;a=commit;h=0e550ad6

scripts/paxmodule.c: add pax_setflags

---
 scripts/paxmodule.c |  253 +++++++++++++++++++++++++++++++++++++++++++++++++++
 scripts/revdep-pax  |    4 +
 2 files changed, 257 insertions(+), 0 deletions(-)

diff --git a/scripts/paxmodule.c b/scripts/paxmodule.c
index 927bb50..eac774a 100644
--- a/scripts/paxmodule.c
+++ b/scripts/paxmodule.c
@@ -24,9 +24,11 @@
 
 
 static PyObject * pax_getflags(PyObject *, PyObject *);
+static PyObject * pax_setflags(PyObject *, PyObject *);
 
 static PyMethodDef PaxMethods[] = {
 	{"getflags",  pax_getflags, METH_VARARGS, "Get the pax flags."},
+	{"setflags",  pax_setflags, METH_VARARGS, "Set the pax flags."},
 	{NULL, NULL, 0, NULL}
 };
 
@@ -160,3 +162,254 @@ pax_getflags(PyObject *self, PyObject *args)
 
 	return Py_BuildValue("s", pax_buf);
 }
+
+
+static PyObject *
+pax_setflags(PyObject *self, PyObject *args)
+{
+	const char *f_name;
+	int pax_flags;
+	int fd, sts;
+
+	Elf *elf;
+	GElf_Ehdr ehdr;
+	uint16_t ei_flags;
+
+	GElf_Phdr phdr;
+	size_t i, phnum;
+
+	if (!PyArg_ParseTuple(args, "si", &f_name, &pax_flags))
+	{
+		PyErr_SetString(PaxError, "pax_setflags: PyArg_ParseTuple failed");
+		return NULL;
+	}
+
+	if(elf_version(EV_CURRENT) == EV_NONE)
+	{
+		PyErr_SetString(PaxError, "pax_setflags: library out of date");
+		return NULL;
+	}
+
+	if((fd = open(f_name, O_RDONLY)) < 0)
+	{
+		PyErr_SetString(PaxError, "pax_setflags: open() failed");
+		return NULL;
+	}
+
+	if((elf = elf_begin(fd, ELF_C_READ_MMAP, NULL)) == NULL)
+	{
+		close(fd);
+		PyErr_SetString(PaxError, "pax_setflags: elf_begin() failed");
+		return NULL;
+	}
+
+	if(elf_kind(elf) != ELF_K_ELF)
+	{
+		elf_end(elf);
+		close(fd);
+		PyErr_SetString(PaxError, "pax_setflags: elf_kind() failed: this is not an elf file.");
+		return NULL;
+	}
+
+
+
+	if(gelf_getehdr(elf, &ehdr) != &ehdr)
+	{
+		elf_end(elf);
+		close(fd);
+		PyErr_SetString(PaxError, "pax_setflags: gelf_getehdr() failed");
+		return NULL;
+	}
+
+	ei_flags = ehdr.e_ident[EI_PAX] + (ehdr.e_ident[EI_PAX + 1] << 8);
+
+	//PAGEEXEC
+	if(pax_flags & PF_PAGEEXEC)
+		ei_flags &= ~HF_PAX_PAGEEXEC;
+	if(pax_flags & PF_NOPAGEEXEC)
+		ei_flags |= HF_PAX_PAGEEXEC;
+	if((pax_flags & PF_PAGEEXEC) && (pax_flags & PF_NOPAGEEXEC))
+		ei_flags &= ~HF_PAX_PAGEEXEC;
+
+	//SEGMEXEC
+	if(pax_flags & PF_SEGMEXEC)
+		ei_flags &= ~HF_PAX_SEGMEXEC;
+	if(pax_flags & PF_NOSEGMEXEC)
+		ei_flags |= HF_PAX_SEGMEXEC;
+	if((pax_flags & PF_SEGMEXEC) && (pax_flags & PF_NOSEGMEXEC))
+		ei_flags &= ~HF_PAX_SEGMEXEC;
+
+	//MPROTECT
+	if(pax_flags & PF_MPROTECT)
+		ei_flags &= ~HF_PAX_MPROTECT;
+	if(pax_flags & PF_NOMPROTECT)
+		ei_flags |= HF_PAX_MPROTECT;
+	if((pax_flags & PF_MPROTECT) && (pax_flags & PF_NOMPROTECT))
+		ei_flags &= ~HF_PAX_MPROTECT;
+
+	//EMUTRAMP
+	if(pax_flags & PF_EMUTRAMP)
+		ei_flags |= HF_PAX_EMUTRAMP;
+	if(pax_flags & PF_NOEMUTRAMP)
+		ei_flags &= ~HF_PAX_EMUTRAMP;
+	if((pax_flags & PF_EMUTRAMP) && (pax_flags & PF_NOEMUTRAMP))
+		ei_flags &= ~HF_PAX_EMUTRAMP;
+
+	//RANDMMAP
+	if(pax_flags & PF_RANDMMAP)
+		ei_flags &= ~HF_PAX_RANDMMAP;
+	if(pax_flags & PF_NORANDMMAP)
+		ei_flags |= HF_PAX_RANDMMAP;
+	if((pax_flags & PF_RANDMMAP) && (pax_flags & PF_NORANDMMAP))
+		ei_flags &= ~HF_PAX_RANDMMAP;
+
+	//RANDEXEC
+	if(pax_flags & PF_RANDEXEC)
+		ei_flags |= HF_PAX_RANDEXEC;
+	if(pax_flags & PF_NORANDEXEC)
+		ei_flags &= ~HF_PAX_RANDEXEC;
+	if((pax_flags & PF_RANDEXEC) && (pax_flags & PF_NORANDEXEC))
+		ei_flags |= HF_PAX_RANDEXEC;
+
+
+	ehdr.e_ident[EI_PAX] = (uint8_t)ei_flags  ;
+	ehdr.e_ident[EI_PAX + 1] = (uint8_t)(ei_flags >> 8) ;
+
+	if(!gelf_update_ehdr(elf, &ehdr))
+	{
+		elf_end(elf);
+		close(fd);
+		PyErr_SetString(PaxError, "pax_setflags: gelf_update_ehdr() failed");
+		return NULL;
+	}
+
+	elf_getphdrnum(elf, &phnum);
+	for(i=0; i<phnum; ++i)
+	{
+		if(gelf_getphdr(elf, i, &phdr) != &phdr)
+		{
+			elf_end(elf);
+			close(fd);
+			PyErr_SetString(PaxError, "pax_setflags: gelf_getphdr() failed");
+			return NULL;
+		}
+
+		if(phdr.p_type == PT_PAX_FLAGS)
+		{
+			//PAGEEXEC
+			if(pax_flags & PF_PAGEEXEC)
+			{
+				phdr.p_flags |= PF_PAGEEXEC;
+				phdr.p_flags &= ~PF_NOPAGEEXEC;
+			}
+			if(pax_flags & PF_NOPAGEEXEC)
+			{
+				phdr.p_flags &= ~PF_PAGEEXEC;
+				phdr.p_flags |= PF_NOPAGEEXEC;
+			}
+			if((pax_flags & PF_PAGEEXEC) && (pax_flags & PF_NOPAGEEXEC))
+			{
+				phdr.p_flags &= ~PF_PAGEEXEC;
+				phdr.p_flags &= ~PF_NOPAGEEXEC;
+			}
+
+			//SEGMEXEC
+			if(pax_flags & PF_SEGMEXEC)
+			{
+				phdr.p_flags |= PF_SEGMEXEC;
+				phdr.p_flags &= ~PF_NOSEGMEXEC;
+			}
+			if(pax_flags & PF_NOSEGMEXEC)
+			{
+				phdr.p_flags &= ~PF_SEGMEXEC;
+				phdr.p_flags |= PF_NOSEGMEXEC;
+			}
+			if((pax_flags & PF_SEGMEXEC) && (pax_flags & PF_NOSEGMEXEC))
+			{
+				phdr.p_flags &= ~PF_SEGMEXEC;
+				phdr.p_flags &= ~PF_NOSEGMEXEC;
+			}
+
+			//MPROTECT
+			if(pax_flags & PF_MPROTECT)
+			{
+				phdr.p_flags |= PF_MPROTECT;
+				phdr.p_flags &= ~PF_NOMPROTECT;
+			}
+			if(pax_flags & PF_NOMPROTECT)
+			{
+				phdr.p_flags &= ~PF_MPROTECT;
+				phdr.p_flags |= PF_NOMPROTECT;
+			}
+			if((pax_flags & PF_MPROTECT) && (pax_flags & PF_NOMPROTECT))
+			{
+				phdr.p_flags &= ~PF_MPROTECT;
+				phdr.p_flags &= ~PF_NOMPROTECT;
+			}
+
+			//EMUTRAMP
+			if(pax_flags & PF_EMUTRAMP)
+			{
+				phdr.p_flags |= PF_EMUTRAMP;
+				phdr.p_flags &= ~PF_NOEMUTRAMP;
+			}
+			if(pax_flags & PF_NOEMUTRAMP)
+			{
+				phdr.p_flags &= ~PF_EMUTRAMP;
+				phdr.p_flags |= PF_NOEMUTRAMP;
+			}
+			if((pax_flags & PF_EMUTRAMP) && (pax_flags & PF_NOEMUTRAMP))
+			{
+				phdr.p_flags &= ~PF_EMUTRAMP;
+				phdr.p_flags &= ~PF_NOEMUTRAMP;
+			}
+
+			//RANDMMAP
+			if(pax_flags & PF_RANDMMAP)
+			{
+				phdr.p_flags |= PF_RANDMMAP;
+				phdr.p_flags &= ~PF_NORANDMMAP;
+			}
+			if(pax_flags & PF_NORANDMMAP)
+			{
+				phdr.p_flags &= ~PF_RANDMMAP;
+				phdr.p_flags |= PF_NORANDMMAP;
+			}
+			if((pax_flags & PF_RANDMMAP) && (pax_flags & PF_NORANDMMAP))
+			{
+				phdr.p_flags &= ~PF_RANDMMAP;
+				phdr.p_flags &= ~PF_NORANDMMAP;
+			}
+
+			//RANDEXEC
+			if(pax_flags & PF_RANDEXEC)
+			{
+				phdr.p_flags |= PF_RANDEXEC;
+				phdr.p_flags &= ~PF_NORANDEXEC;
+			}
+			if(pax_flags & PF_NORANDEXEC)
+			{
+				phdr.p_flags &= ~PF_RANDEXEC;
+				phdr.p_flags |= PF_NORANDEXEC;
+			}
+			if((pax_flags & PF_RANDEXEC) && (pax_flags & PF_NORANDEXEC))
+			{
+				phdr.p_flags &= ~PF_RANDEXEC;
+				phdr.p_flags &= ~PF_NORANDEXEC;
+			}
+
+			if(!gelf_update_phdr(elf, i, &phdr))
+			{
+				elf_end(elf);
+				close(fd);
+				PyErr_SetString(PaxError, "pax_setflags: gelf_update_phdr() failed");
+				return NULL;
+			}
+		}
+	}
+
+	elf_end(elf);
+	close(fd);
+
+	return Py_BuildValue("");
+}

diff --git a/scripts/revdep-pax b/scripts/revdep-pax
index 0fcb8e6..e43db27 100755
--- a/scripts/revdep-pax
+++ b/scripts/revdep-pax
@@ -104,6 +104,7 @@ def print_forward_linkings( forward_linkings, so2library_mappings, verbose ):
 
 		if verbose:
 			print sv
+			print
 			if count == 0:
 				print
 				print '\tNo mismatches'
@@ -164,6 +165,7 @@ def print_reverse_linkings( reverse_linkings, so2library_mappings, verbose ):
 
 		if verbose:
 			print sv
+			print
 			if count == 0:
 				print
 				print '\tNo mismatches'
@@ -230,6 +232,7 @@ def run_binary(binary, verbose):
 
 	binary_flags = pax.getflags(binary)
 	print binary, '(', binary_flags, ')'
+	print
 
 	count = 0
 	for soname in linkings:
@@ -277,6 +280,7 @@ def run_soname(name, verbose, use_soname):
 
 	library_flags = pax.getflags(library)
 	print soname, '\t', library, '(', library_flags, ')'
+	print
 
 	count = 0
 	for binary in linkings:



^ permalink raw reply related	[flat|nested] 89+ messages in thread
* [gentoo-commits] proj/elfix:master commit in: scripts/
@ 2011-10-16 18:04 Anthony G. Basile
  0 siblings, 0 replies; 89+ messages in thread
From: Anthony G. Basile @ 2011-10-16 18:04 UTC (permalink / raw
  To: gentoo-commits

commit:     397d854e4312428331da7cd24770156dff3a84fe
Author:     Anthony G. Basile <blueness <AT> gentoo <DOT> org>
AuthorDate: Sun Oct 16 18:03:58 2011 +0000
Commit:     Anthony G. Basile <blueness <AT> gentoo <DOT> org>
CommitDate: Sun Oct 16 18:03:58 2011 +0000
URL:        http://git.overlays.gentoo.org/gitweb/?p=proj/elfix.git;a=commit;h=397d854e

scripts/paxmodule.c: add pax_setflags

---
 scripts/paxmodule.c |  252 +++++++++++++++++++++++++++++++++++++++++++++++++++
 scripts/revdep-pax  |    4 +
 2 files changed, 256 insertions(+), 0 deletions(-)

diff --git a/scripts/paxmodule.c b/scripts/paxmodule.c
index 927bb50..8a2b0e2 100644
--- a/scripts/paxmodule.c
+++ b/scripts/paxmodule.c
@@ -27,6 +27,7 @@ static PyObject * pax_getflags(PyObject *, PyObject *);
 
 static PyMethodDef PaxMethods[] = {
 	{"getflags",  pax_getflags, METH_VARARGS, "Get the pax flags."},
+	{"setflags",  pax_setflags, METH_VARARGS, "Get the pax flags."},
 	{NULL, NULL, 0, NULL}
 };
 
@@ -160,3 +161,254 @@ pax_getflags(PyObject *self, PyObject *args)
 
 	return Py_BuildValue("s", pax_buf);
 }
+
+
+static PyObject *
+pax_setflags(PyObject *self, PyObject *args)
+{
+	const char *f_name;
+	int pax_flags;
+	int fd, sts;
+
+	Elf *elf;
+	GElf_Ehdr ehdr;
+	uint16_t ei_flags;
+
+	GElf_Phdr phdr;
+	size_t i, phnum;
+
+	if (!PyArg_ParseTuple(args, "si", &f_name, &pax_flags))
+	{
+		PyErr_SetString(PaxError, "pax_setflags: PyArg_ParseTuple failed");
+		return NULL;
+	}
+
+	if(elf_version(EV_CURRENT) == EV_NONE)
+	{
+		PyErr_SetString(PaxError, "pax_setflags: library out of date");
+		return NULL;
+	}
+
+	if((fd = open(f_name, O_RDONLY)) < 0)
+	{
+		PyErr_SetString(PaxError, "pax_setflags: open() failed");
+		return NULL;
+	}
+
+	if((elf = elf_begin(fd, ELF_C_READ_MMAP, NULL)) == NULL)
+	{
+		close(fd);
+		PyErr_SetString(PaxError, "pax_setflags: elf_begin() failed");
+		return NULL;
+	}
+
+	if(elf_kind(elf) != ELF_K_ELF)
+	{
+		elf_end(elf);
+		close(fd);
+		PyErr_SetString(PaxError, "pax_setflags: elf_kind() failed: this is not an elf file.");
+		return NULL;
+	}
+
+
+
+	if(gelf_getehdr(elf, &ehdr) != &ehdr)
+	{
+		elf_end(elf);
+		close(fd);
+		PyErr_SetString(PaxError, "pax_setflags: gelf_getehdr() failed");
+		return NULL;
+	}
+
+	ei_flags = ehdr.e_ident[EI_PAX] + (ehdr.e_ident[EI_PAX + 1] << 8);
+
+	//PAGEEXEC
+	if(*pax_flags & PF_PAGEEXEC)
+		ei_flags &= ~HF_PAX_PAGEEXEC;
+	if(*pax_flags & PF_NOPAGEEXEC)
+		ei_flags |= HF_PAX_PAGEEXEC;
+	if((*pax_flags & PF_PAGEEXEC) && (*pax_flags & PF_NOPAGEEXEC))
+		ei_flags &= ~HF_PAX_PAGEEXEC;
+
+	//SEGMEXEC
+	if(*pax_flags & PF_SEGMEXEC)
+		ei_flags &= ~HF_PAX_SEGMEXEC;
+	if(*pax_flags & PF_NOSEGMEXEC)
+		ei_flags |= HF_PAX_SEGMEXEC;
+	if((*pax_flags & PF_SEGMEXEC) && (*pax_flags & PF_NOSEGMEXEC))
+		ei_flags &= ~HF_PAX_SEGMEXEC;
+
+	//MPROTECT
+	if(*pax_flags & PF_MPROTECT)
+		ei_flags &= ~HF_PAX_MPROTECT;
+	if(*pax_flags & PF_NOMPROTECT)
+		ei_flags |= HF_PAX_MPROTECT;
+	if((*pax_flags & PF_MPROTECT) && (*pax_flags & PF_NOMPROTECT))
+		ei_flags &= ~HF_PAX_MPROTECT;
+
+	//EMUTRAMP
+	if(*pax_flags & PF_EMUTRAMP)
+		ei_flags |= HF_PAX_EMUTRAMP;
+	if(*pax_flags & PF_NOEMUTRAMP)
+		ei_flags &= ~HF_PAX_EMUTRAMP;
+	if((*pax_flags & PF_EMUTRAMP) && (*pax_flags & PF_NOEMUTRAMP))
+		ei_flags &= ~HF_PAX_EMUTRAMP;
+
+	//RANDMMAP
+	if(*pax_flags & PF_RANDMMAP)
+		ei_flags &= ~HF_PAX_RANDMMAP;
+	if(*pax_flags & PF_NORANDMMAP)
+		ei_flags |= HF_PAX_RANDMMAP;
+	if((*pax_flags & PF_RANDMMAP) && (*pax_flags & PF_NORANDMMAP))
+		ei_flags &= ~HF_PAX_RANDMMAP;
+
+	//RANDEXEC
+	if(*pax_flags & PF_RANDEXEC)
+		ei_flags |= HF_PAX_RANDEXEC;
+	if(*pax_flags & PF_NORANDEXEC)
+		ei_flags &= ~HF_PAX_RANDEXEC;
+	if((*pax_flags & PF_RANDEXEC) && (*pax_flags & PF_NORANDEXEC))
+		ei_flags |= HF_PAX_RANDEXEC;
+
+
+	ehdr.e_ident[EI_PAX] = (uint8_t)ei_flags  ;
+	ehdr.e_ident[EI_PAX + 1] = (uint8_t)(ei_flags >> 8) ;
+
+	if(!gelf_update_ehdr(elf, &ehdr))
+	{
+		elf_end(elf);
+		close(fd);
+		PyErr_SetString(PaxError, "pax_setflags: gelf_update_ehdr() failed");
+		return NULL;
+	}
+
+	elf_getphdrnum(elf, &phnum);
+	for(i=0; i<phnum; ++i)
+	{
+		if(gelf_getphdr(elf, i, &phdr) != &phdr)
+		{
+			elf_end(elf);
+			close(fd);
+			PyErr_SetString(PaxError, "pax_setflags: gelf_getphdr() failed");
+			return NULL;
+		}
+
+		if(phdr.p_type == PT_PAX_FLAGS)
+		{
+			//PAGEEXEC
+			if(*pax_flags & PF_PAGEEXEC)
+			{
+				phdr.p_flags |= PF_PAGEEXEC;
+				phdr.p_flags &= ~PF_NOPAGEEXEC;
+			}
+			if(*pax_flags & PF_NOPAGEEXEC)
+			{
+				phdr.p_flags &= ~PF_PAGEEXEC;
+				phdr.p_flags |= PF_NOPAGEEXEC;
+			}
+			if((*pax_flags & PF_PAGEEXEC) && (*pax_flags & PF_NOPAGEEXEC))
+			{
+				phdr.p_flags &= ~PF_PAGEEXEC;
+				phdr.p_flags &= ~PF_NOPAGEEXEC;
+			}
+
+			//SEGMEXEC
+			if(*pax_flags & PF_SEGMEXEC)
+			{
+				phdr.p_flags |= PF_SEGMEXEC;
+				phdr.p_flags &= ~PF_NOSEGMEXEC;
+			}
+			if(*pax_flags & PF_NOSEGMEXEC)
+			{
+				phdr.p_flags &= ~PF_SEGMEXEC;
+				phdr.p_flags |= PF_NOSEGMEXEC;
+			}
+			if((*pax_flags & PF_SEGMEXEC) && (*pax_flags & PF_NOSEGMEXEC))
+			{
+				phdr.p_flags &= ~PF_SEGMEXEC;
+				phdr.p_flags &= ~PF_NOSEGMEXEC;
+			}
+
+			//MPROTECT
+			if(*pax_flags & PF_MPROTECT)
+			{
+				phdr.p_flags |= PF_MPROTECT;
+				phdr.p_flags &= ~PF_NOMPROTECT;
+			}
+			if(*pax_flags & PF_NOMPROTECT)
+			{
+				phdr.p_flags &= ~PF_MPROTECT;
+				phdr.p_flags |= PF_NOMPROTECT;
+			}
+			if((*pax_flags & PF_MPROTECT) && (*pax_flags & PF_NOMPROTECT))
+			{
+				phdr.p_flags &= ~PF_MPROTECT;
+				phdr.p_flags &= ~PF_NOMPROTECT;
+			}
+
+			//EMUTRAMP
+			if(*pax_flags & PF_EMUTRAMP)
+			{
+				phdr.p_flags |= PF_EMUTRAMP;
+				phdr.p_flags &= ~PF_NOEMUTRAMP;
+			}
+			if(*pax_flags & PF_NOEMUTRAMP)
+			{
+				phdr.p_flags &= ~PF_EMUTRAMP;
+				phdr.p_flags |= PF_NOEMUTRAMP;
+			}
+			if((*pax_flags & PF_EMUTRAMP) && (*pax_flags & PF_NOEMUTRAMP))
+			{
+				phdr.p_flags &= ~PF_EMUTRAMP;
+				phdr.p_flags &= ~PF_NOEMUTRAMP;
+			}
+
+			//RANDMMAP
+			if(*pax_flags & PF_RANDMMAP)
+			{
+				phdr.p_flags |= PF_RANDMMAP;
+				phdr.p_flags &= ~PF_NORANDMMAP;
+			}
+			if(*pax_flags & PF_NORANDMMAP)
+			{
+				phdr.p_flags &= ~PF_RANDMMAP;
+				phdr.p_flags |= PF_NORANDMMAP;
+			}
+			if((*pax_flags & PF_RANDMMAP) && (*pax_flags & PF_NORANDMMAP))
+			{
+				phdr.p_flags &= ~PF_RANDMMAP;
+				phdr.p_flags &= ~PF_NORANDMMAP;
+			}
+
+			//RANDEXEC
+			if(*pax_flags & PF_RANDEXEC)
+			{
+				phdr.p_flags |= PF_RANDEXEC;
+				phdr.p_flags &= ~PF_NORANDEXEC;
+			}
+			if(*pax_flags & PF_NORANDEXEC)
+			{
+				phdr.p_flags &= ~PF_RANDEXEC;
+				phdr.p_flags |= PF_NORANDEXEC;
+			}
+			if((*pax_flags & PF_RANDEXEC) && (*pax_flags & PF_NORANDEXEC))
+			{
+				phdr.p_flags &= ~PF_RANDEXEC;
+				phdr.p_flags &= ~PF_NORANDEXEC;
+			}
+
+			if(!gelf_update_phdr(elf, i, &phdr))
+			{
+				elf_end(elf);
+				close(fd);
+				PyErr_SetString(PaxError, "pax_setflags: gelf_update_phdr() failed");
+				return NULL;
+			}
+		}
+	}
+
+	elf_end(elf);
+	close(fd);
+
+	return Py_BuildValue("");
+}

diff --git a/scripts/revdep-pax b/scripts/revdep-pax
index 0fcb8e6..e43db27 100755
--- a/scripts/revdep-pax
+++ b/scripts/revdep-pax
@@ -104,6 +104,7 @@ def print_forward_linkings( forward_linkings, so2library_mappings, verbose ):
 
 		if verbose:
 			print sv
+			print
 			if count == 0:
 				print
 				print '\tNo mismatches'
@@ -164,6 +165,7 @@ def print_reverse_linkings( reverse_linkings, so2library_mappings, verbose ):
 
 		if verbose:
 			print sv
+			print
 			if count == 0:
 				print
 				print '\tNo mismatches'
@@ -230,6 +232,7 @@ def run_binary(binary, verbose):
 
 	binary_flags = pax.getflags(binary)
 	print binary, '(', binary_flags, ')'
+	print
 
 	count = 0
 	for soname in linkings:
@@ -277,6 +280,7 @@ def run_soname(name, verbose, use_soname):
 
 	library_flags = pax.getflags(library)
 	print soname, '\t', library, '(', library_flags, ')'
+	print
 
 	count = 0
 	for binary in linkings:



^ permalink raw reply related	[flat|nested] 89+ messages in thread
* [gentoo-commits] proj/elfix:master commit in: scripts/
@ 2011-10-13  4:36 Anthony G. Basile
  0 siblings, 0 replies; 89+ messages in thread
From: Anthony G. Basile @ 2011-10-13  4:36 UTC (permalink / raw
  To: gentoo-commits

commit:     0308fc3a8336b7f1374ef8bd4d24e37cd663d18c
Author:     Anthony G. Basile <blueness <AT> gentoo <DOT> org>
AuthorDate: Thu Oct 13 04:36:09 2011 +0000
Commit:     Anthony G. Basile <blueness <AT> gentoo <DOT> org>
CommitDate: Thu Oct 13 04:36:09 2011 +0000
URL:        http://git.overlays.gentoo.org/gitweb/?p=proj/elfix.git;a=commit;h=0308fc3a

scripts/revdep-pax: add search by full library path

---
 scripts/revdep-pax |   32 ++++++++++++++++++++++++++++----
 1 files changed, 28 insertions(+), 4 deletions(-)

diff --git a/scripts/revdep-pax b/scripts/revdep-pax
index dd359db..0fcb8e6 100755
--- a/scripts/revdep-pax
+++ b/scripts/revdep-pax
@@ -215,12 +215,14 @@ def run_usage():
 def run_forward(verbose):
 	( forward_linkings, so2library_mappings ) = get_forward_linkings()
 	print_forward_linkings( forward_linkings, so2library_mappings, verbose)
+	print
 
 
 def run_reverse(verbose):
 	( forward_linkings, so2library_mappings ) = get_forward_linkings()
 	reverse_linkings = invert_linkings( forward_linkings )
 	print_reverse_linkings( reverse_linkings, so2library_mappings, verbose )
+	print
 
 
 def run_binary(binary, verbose):
@@ -253,9 +255,23 @@ def run_binary(binary, verbose):
 		print
 
 
-def run_soname(soname, verbose):
+def invert_so2library_mappings( so2library_mappings ):
+	library2soname_mappings = {}
+	for soname, library in so2library_mappings.iteritems():
+		library2soname_mappings[library] = soname
+	return library2soname_mappings
+
+
+def run_soname(name, verbose, use_soname):
 	( forward_linkings, so2library_mappings ) = get_forward_linkings()
 	reverse_linkings = invert_linkings( forward_linkings )
+
+	if use_soname:
+		soname = name
+	else:
+		library2soname_mappings = invert_so2library_mappings(so2library_mappings)
+		soname = library2soname_mappings[name]
+
 	linkings = reverse_linkings[soname]
 	library = so2library_mappings[soname]
 
@@ -284,9 +300,10 @@ def run_soname(soname, verbose):
 		print '\tMismatches'
 		print
 
+
 def main():
 	try:
-		opts, args = getopt.getopt(sys.argv[1:], 'hfrb:s:v')
+		opts, args = getopt.getopt(sys.argv[1:], 'hfrb:s:l:v')
 	except getopt.GetoptError, err:
 		print str(err) # will print something like 'option -a not recognized'
 		run_usage()
@@ -302,6 +319,7 @@ def main():
 
 	binary = None
 	soname = None
+	library = None
 
 	verbose = False
 
@@ -316,6 +334,8 @@ def main():
 			binary = a
 		elif o == '-s':
 			soname = a
+		elif o == '-l':
+			library = a
 		elif o == '-v':
 			verbose = True
 		else:
@@ -337,8 +357,12 @@ def main():
 	if binary != None:
 		run_binary(binary, verbose)
 
-	if soname !=None:
-		run_soname(soname, verbose)
+	if soname != None:
+		run_soname(soname, verbose, True)
+
+	if library != None:
+		library = os.path.realpath(library)
+		run_soname(library, verbose, False)
 
 if __name__ == '__main__':
     main()



^ permalink raw reply related	[flat|nested] 89+ messages in thread
* [gentoo-commits] proj/elfix:master commit in: scripts/
@ 2011-10-13  2:27 Anthony G. Basile
  0 siblings, 0 replies; 89+ messages in thread
From: Anthony G. Basile @ 2011-10-13  2:27 UTC (permalink / raw
  To: gentoo-commits

commit:     a856ce5c1eb670f5abcfdc4eca3038932fd33835
Author:     Anthony G. Basile <blueness <AT> gentoo <DOT> org>
AuthorDate: Thu Oct 13 02:27:41 2011 +0000
Commit:     Anthony G. Basile <blueness <AT> gentoo <DOT> org>
CommitDate: Thu Oct 13 02:27:41 2011 +0000
URL:        http://git.overlays.gentoo.org/gitweb/?p=proj/elfix.git;a=commit;h=a856ce5c

scripts/revdep-pax: improve format of output

---
 scripts/revdep-pax |   30 ++++++++++++++++++++++++++----
 1 files changed, 26 insertions(+), 4 deletions(-)

diff --git a/scripts/revdep-pax b/scripts/revdep-pax
index f06bf3d..dd359db 100755
--- a/scripts/revdep-pax
+++ b/scripts/revdep-pax
@@ -105,7 +105,13 @@ def print_forward_linkings( forward_linkings, so2library_mappings, verbose ):
 		if verbose:
 			print sv
 			if count == 0:
-				print 'No mismatches'
+				print
+				print '\tNo mismatches'
+				print
+			else:
+				print
+				print '\tMismatches'
+				print
 		else:
 			if count != 0:
 				print s
@@ -159,7 +165,13 @@ def print_reverse_linkings( reverse_linkings, so2library_mappings, verbose ):
 		if verbose:
 			print sv
 			if count == 0:
-				print 'No mismatches'
+				print
+				print '\tNo mismatches'
+				print
+			else:
+				print
+				print '\tMismatches'
+				print
 		else:
 			if count != 0:
 				print s
@@ -233,7 +245,12 @@ def run_binary(binary, verbose):
 
 	if count == 0:
 		print
-		print 'No mismatches'
+		print '\tNo mismatches'
+		print
+	else:
+		print
+		print '\tMismatches'
+		print
 
 
 def run_soname(soname, verbose):
@@ -260,7 +277,12 @@ def run_soname(soname, verbose):
 
 	if count == 0:
 		print
-		print 'No mismatches'
+		print '\tNo mismatches'
+		print
+	else:
+		print
+		print '\tMismatches'
+		print
 
 def main():
 	try:



^ permalink raw reply related	[flat|nested] 89+ messages in thread
* [gentoo-commits] proj/elfix:master commit in: scripts/
@ 2011-10-13  0:36 Anthony G. Basile
  0 siblings, 0 replies; 89+ messages in thread
From: Anthony G. Basile @ 2011-10-13  0:36 UTC (permalink / raw
  To: gentoo-commits

commit:     46b3a6df973d00153bef72d03d6c8e5c0e0d6f7e
Author:     Anthony G. Basile <blueness <AT> gentoo <DOT> org>
AuthorDate: Thu Oct 13 00:36:29 2011 +0000
Commit:     Anthony G. Basile <blueness <AT> gentoo <DOT> org>
CommitDate: Thu Oct 13 00:36:29 2011 +0000
URL:        http://git.overlays.gentoo.org/gitweb/?p=proj/elfix.git;a=commit;h=46b3a6df

scripts/revdep-pax: fix call to run_usage() on command line errors

---
 scripts/revdep-pax |    4 ++--
 1 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/scripts/revdep-pax b/scripts/revdep-pax
index 576025e..f06bf3d 100755
--- a/scripts/revdep-pax
+++ b/scripts/revdep-pax
@@ -267,11 +267,11 @@ def main():
 		opts, args = getopt.getopt(sys.argv[1:], 'hfrb:s:v')
 	except getopt.GetoptError, err:
 		print str(err) # will print something like 'option -a not recognized'
-		usage()
+		run_usage()
 		sys.exit(1)
 
 	if len(opts) == 0:
-		usage()
+		run_usage()
 		sys.exit(1)
 
 	do_usage   = False



^ permalink raw reply related	[flat|nested] 89+ messages in thread
* [gentoo-commits] proj/elfix:master commit in: scripts/
@ 2011-10-11  0:50 Anthony G. Basile
  0 siblings, 0 replies; 89+ messages in thread
From: Anthony G. Basile @ 2011-10-11  0:50 UTC (permalink / raw
  To: gentoo-commits

commit:     128579a15686b7759423c7ecbe5428ddef346dbc
Author:     Anthony G. Basile <blueness <AT> gentoo <DOT> org>
AuthorDate: Tue Oct 11 00:50:28 2011 +0000
Commit:     Anthony G. Basile <blueness <AT> gentoo <DOT> org>
CommitDate: Tue Oct 11 00:50:28 2011 +0000
URL:        http://git.overlays.gentoo.org/gitweb/?p=proj/elfix.git;a=commit;h=128579a1

scripts/revdep-pax: restrict non-verbose to only mismatches

---
 scripts/revdep-pax |   16 ++++++++++------
 1 files changed, 10 insertions(+), 6 deletions(-)

diff --git a/scripts/revdep-pax b/scripts/revdep-pax
index 75ec724..576025e 100755
--- a/scripts/revdep-pax
+++ b/scripts/revdep-pax
@@ -84,7 +84,8 @@ def print_forward_linkings( forward_linkings, so2library_mappings, verbose ):
 
 		try:
 			binary_flags = pax.getflags(binary)
-			s = "%s ( %s )" % ( binary, binary_flags )
+			sv = "%s ( %s )" % ( binary, binary_flags )
+			s = sv
 		except:
 			missing_binaries.append(binary)
 			continue
@@ -94,14 +95,15 @@ def print_forward_linkings( forward_linkings, so2library_mappings, verbose ):
 			try:
 				library = so2library_mappings[soname]
 				library_flags = pax.getflags(library)
-				s = "%s\n\t%s\t%s ( %s )" % ( s, soname, library, library_flags )
+				sv = "%s\n\t%s\t%s ( %s )" % ( sv, soname, library, library_flags )
 				if binary_flags != library_flags:
+					s = "%s\n\t%s\t%s ( %s )" % ( s, soname, library, library_flags )
 					count = count + 1
 			except:
 				missing_links.append(soname)
 
 		if verbose:
-			print s
+			print sv
 			if count == 0:
 				print 'No mismatches'
 		else:
@@ -137,7 +139,8 @@ def print_reverse_linkings( reverse_linkings, so2library_mappings, verbose ):
 		try:
 			library = so2library_mappings[soname]
 			library_flags = pax.getflags(library)
-			s = "%s\t%s ( %s )" % ( soname, library, library_flags )
+			sv = "%s\t%s ( %s )" % ( soname, library, library_flags )
+			s = sv
 		except:
 			missing_sonames.append(soname)
 			continue
@@ -146,14 +149,15 @@ def print_reverse_linkings( reverse_linkings, so2library_mappings, verbose ):
 		for binary in reverse_linkings[soname]:
 			try:
 				binary_flags = pax.getflags(binary)
-				s = "%s\n\t%s ( %s )" % ( s, binary, binary_flags )
+				sv = "%s\n\t%s ( %s )" % ( sv, binary, binary_flags )
 				if library_flags != binary_flags:
+					s = "%s\n\t%s ( %s )" % ( s, binary, binary_flags )
 					count = count + 1
 			except:
 				missing_links.append(binary)
 
 		if verbose:
-			print s
+			print sv
 			if count == 0:
 				print 'No mismatches'
 		else:



^ permalink raw reply related	[flat|nested] 89+ messages in thread
* [gentoo-commits] proj/elfix:master commit in: scripts/
@ 2011-10-10 23:42 Anthony G. Basile
  0 siblings, 0 replies; 89+ messages in thread
From: Anthony G. Basile @ 2011-10-10 23:42 UTC (permalink / raw
  To: gentoo-commits

commit:     24f72fe5d67a7bd2af60b7b50a78c03eea4e29c7
Author:     Anthony G. Basile <blueness <AT> gentoo <DOT> org>
AuthorDate: Mon Oct 10 23:42:31 2011 +0000
Commit:     Anthony G. Basile <blueness <AT> gentoo <DOT> org>
CommitDate: Mon Oct 10 23:42:31 2011 +0000
URL:        http://git.overlays.gentoo.org/gitweb/?p=proj/elfix.git;a=commit;h=24f72fe5

scripts/revdep-pax: code and variable name cleanup

---
 scripts/revdep-pax |   67 ++++++++++++++++++++++++++++++++-------------------
 1 files changed, 42 insertions(+), 25 deletions(-)

diff --git a/scripts/revdep-pax b/scripts/revdep-pax
index 4e35f1e..75ec724 100755
--- a/scripts/revdep-pax
+++ b/scripts/revdep-pax
@@ -8,13 +8,16 @@ import re
 import pax
 
 def get_ldd_linkings(binary):
+
 	try:
-		#When subprocess.DEVNULL makes it to python, change this: http://bugs.python.org/issue5870
+		#TODO: when subprocess.DEVNULL makes it to python, change this: http://bugs.python.org/issue5870
 		ldd_output = subprocess.check_output(['/usr/bin/ldd', binary], stderr=subprocess.PIPE)
 	except:
-		# We should record these binaries which are probably statically linked
+		#TODO: we should record these binaries which are probably statically linked
 		return []
+
 	ldd_lines = ldd_output.split('\n')
+
 	linkings = []
 	mappings = {}
 	for m in range(0,len(ldd_lines)):
@@ -30,14 +33,16 @@ def get_ldd_linkings(binary):
 		library = os.path.realpath(library)
 		linkings.append(soname)
 		mappings[soname] = library 
+
 	return ( linkings, mappings )
 
 
 def get_forward_linkings():
-	# I'm still not sure we wan to use /var/db/pkg vs some path of binaries
+	#TODO: I'm still not sure we wan to use /var/db/pkg vs some path of binaries
 	var_db_pkg = '/var/db/pkg'
+
 	forward_linkings = {}
-	so2filename_mappings = {}
+	so2library_mappings = {}
 	for cat in os.listdir(var_db_pkg):
 		catdir = '%s/%s' % (var_db_pkg, cat)
 		for pkg in os.listdir(catdir):
@@ -52,11 +57,11 @@ def get_forward_linkings():
 					binary = link[0]
 					( linkings, mappings ) = get_ldd_linkings(binary)
 					forward_linkings[binary] = linkings 
-					so2filename_mappings.update(mappings)
+					so2library_mappings.update(mappings)
 			except:
 				continue
 
-	return ( forward_linkings, so2filename_mappings )
+	return ( forward_linkings, so2library_mappings )
 
 
 def invert_linkings( forward_linkings ):
@@ -72,7 +77,7 @@ def invert_linkings( forward_linkings ):
 	return reverse_linkings 
 
 
-def print_forward_linkings( forward_linkings, so2filename_mappings, verbose ):
+def print_forward_linkings( forward_linkings, so2library_mappings, verbose ):
 	missing_binaries = []
 	missing_links = []
 	for binary in forward_linkings:
@@ -87,7 +92,7 @@ def print_forward_linkings( forward_linkings, so2filename_mappings, verbose ):
 		count = 0
 		for soname in forward_linkings[binary]:
 			try:
-				library = so2filename_mappings[soname]
+				library = so2library_mappings[soname]
 				library_flags = pax.getflags(library)
 				s = "%s\n\t%s\t%s ( %s )" % ( s, soname, library, library_flags )
 				if binary_flags != library_flags:
@@ -103,33 +108,38 @@ def print_forward_linkings( forward_linkings, so2filename_mappings, verbose ):
 			if count != 0:
 				print s
 
+	print
+
 	missing_binaries = set(missing_binaries)
-	print '\n\n'
+	print
+	print
 	print '**** Missing binaries ****'
 	for m in missing_binaries:
 		print m
 
 	missing_links = set(missing_links)
-	print '\n\n'
+	print
+	print
 	print '**** Missing forward linkings ****'
 	for m in missing_links:
 		print m
 
-	print '\n\n'
+	print
+	print
 
 
-def print_reverse_linkings( reverse_linkings, so2filename_mappings, verbose ):
+def print_reverse_linkings( reverse_linkings, so2library_mappings, verbose ):
 	missing_sonames = []
 	missing_links = []
 
 	for soname in reverse_linkings:
 
 		try:
-			library = so2filename_mappings[soname]
+			library = so2library_mappings[soname]
 			library_flags = pax.getflags(library)
 			s = "%s\t%s ( %s )" % ( soname, library, library_flags )
 		except:
-			missing_libraries.append(soname)
+			missing_sonames.append(soname)
 			continue
 
 		count = 0
@@ -150,19 +160,23 @@ def print_reverse_linkings( reverse_linkings, so2filename_mappings, verbose ):
 			if count != 0:
 				print s
 
+	print
+
 	missing_sonames = set(missing_sonames)
-	print '\n\n'
+	print
+	print
 	print '**** Missing sonames ****'
 	for m in missing_sonames:
 		print m
 
 	missing_links = set(missing_links)
-	print '\n\n'
+	print
+	print
 	print '**** Missing reverse linkings ****'
 	for m in missing_links:
 		print m
-
-	print '\n\n'
+	print
+	print
 
 
 def run_usage():
@@ -183,14 +197,14 @@ def run_usage():
 
 
 def run_forward(verbose):
-	( forward_linkings, so2filename_mappings ) = get_forward_linkings()
-	print_forward_linkings( forward_linkings, so2filename_mappings, verbose)
+	( forward_linkings, so2library_mappings ) = get_forward_linkings()
+	print_forward_linkings( forward_linkings, so2library_mappings, verbose)
 
 
 def run_reverse(verbose):
-	( forward_linkings, so2filename_mappings ) = get_forward_linkings()
+	( forward_linkings, so2library_mappings ) = get_forward_linkings()
 	reverse_linkings = invert_linkings( forward_linkings )
-	print_reverse_linkings( reverse_linkings, so2filename_mappings, verbose )
+	print_reverse_linkings( reverse_linkings, so2library_mappings, verbose )
 
 
 def run_binary(binary, verbose):
@@ -219,10 +233,10 @@ def run_binary(binary, verbose):
 
 
 def run_soname(soname, verbose):
-	( forward_linkings, so2filename_mappings ) = get_forward_linkings()
+	( forward_linkings, so2library_mappings ) = get_forward_linkings()
 	reverse_linkings = invert_linkings( forward_linkings )
 	linkings = reverse_linkings[soname]
-	library = so2filename_mappings[soname]
+	library = so2library_mappings[soname]
 
 	library_flags = pax.getflags(library)
 	print soname, '\t', library, '(', library_flags, ')'
@@ -241,7 +255,8 @@ def run_soname(soname, verbose):
 			print "cannot obtain pax flags for %s" % binary
 
 	if count == 0:
-		print '\nNo mismatches'
+		print
+		print 'No mismatches'
 
 def main():
 	try:
@@ -282,6 +297,8 @@ def main():
 			print 'Please file a bug'
 			sys.exit(1)
 
+	#TODO: Add code to only allow one of -h, -f -r -b -s
+
 	if do_usage:
 		run_usage()
 



^ permalink raw reply related	[flat|nested] 89+ messages in thread
* [gentoo-commits] proj/elfix:master commit in: scripts/
@ 2011-10-10 23:21 Anthony G. Basile
  0 siblings, 0 replies; 89+ messages in thread
From: Anthony G. Basile @ 2011-10-10 23:21 UTC (permalink / raw
  To: gentoo-commits

commit:     b92738dd6e63b951a482027e784460951e4b9967
Author:     Anthony G. Basile <blueness <AT> gentoo <DOT> org>
AuthorDate: Mon Oct 10 23:21:09 2011 +0000
Commit:     Anthony G. Basile <blueness <AT> gentoo <DOT> org>
CommitDate: Mon Oct 10 23:21:09 2011 +0000
URL:        http://git.overlays.gentoo.org/gitweb/?p=proj/elfix.git;a=commit;h=b92738dd

scripts/revdep-pax: add verbosity to output

---
 scripts/revdep-pax |  189 +++++++++++++++++++++++++++++++---------------------
 1 files changed, 114 insertions(+), 75 deletions(-)

diff --git a/scripts/revdep-pax b/scripts/revdep-pax
index bdf6004..4e35f1e 100755
--- a/scripts/revdep-pax
+++ b/scripts/revdep-pax
@@ -7,12 +7,12 @@ import subprocess
 import re
 import pax
 
-def get_ldd_linkings(elf):
+def get_ldd_linkings(binary):
 	try:
 		#When subprocess.DEVNULL makes it to python, change this: http://bugs.python.org/issue5870
-		ldd_output = subprocess.check_output(['/usr/bin/ldd', elf], stderr=subprocess.PIPE)
+		ldd_output = subprocess.check_output(['/usr/bin/ldd', binary], stderr=subprocess.PIPE)
 	except:
-		# We should record these elfs which are probably static
+		# We should record these binaries which are probably statically linked
 		return []
 	ldd_lines = ldd_output.split('\n')
 	linkings = []
@@ -24,12 +24,12 @@ def get_ldd_linkings(elf):
 		mapp = re.split('=>', ldd_lines[m] )
 		soname = mapp[0].strip()
 		soname = os.path.basename(soname)	# This is for ./libSDL-1.2.so.0
-		filename = re.sub('\(.*$', '', mapp[1]).strip()
-		if filename == '':
+		library = re.sub('\(.*$', '', mapp[1]).strip()
+		if library == '':
 			continue
-		filename = os.path.realpath(filename)
+		library = os.path.realpath(library)
 		linkings.append(soname)
-		mappings[soname] = filename
+		mappings[soname] = library 
 	return ( linkings, mappings )
 
 
@@ -49,9 +49,9 @@ def get_forward_linkings():
 				for line in needs:
 					line = line.strip()
 					link = re.split('\s', line)
-					elf = link[0]
-					( linkings, mappings ) = get_ldd_linkings(elf)
-					forward_linkings[elf] = linkings 
+					binary = link[0]
+					( linkings, mappings ) = get_ldd_linkings(binary)
+					forward_linkings[binary] = linkings 
 					so2filename_mappings.update(mappings)
 			except:
 				continue
@@ -61,38 +61,52 @@ def get_forward_linkings():
 
 def invert_linkings( forward_linkings ):
 	reverse_linkings = {}
-	for elf in forward_linkings:
-		for elf_dep in forward_linkings[elf]:
-			reverse_linkings[elf_dep] = []
+	for binary in forward_linkings:
+		for library in forward_linkings[binary]:
+			reverse_linkings[library] = []
 
-	for elf in forward_linkings:
-		for elf_dep in forward_linkings[elf]:
-			reverse_linkings[elf_dep].append(elf)
+	for binary in forward_linkings:
+		for library in forward_linkings[binary]:
+			reverse_linkings[library].append(binary)
 
 	return reverse_linkings 
 
 
-def print_forward_linkings( forward_linkings, so2filename_mappings ):
-	missing_elfs = []
+def print_forward_linkings( forward_linkings, so2filename_mappings, verbose ):
+	missing_binaries = []
 	missing_links = []
-	for elf in forward_linkings:
+	for binary in forward_linkings:
+
 		try:
-			print elf, '(',  pax.getflags(elf), ')'
+			binary_flags = pax.getflags(binary)
+			s = "%s ( %s )" % ( binary, binary_flags )
 		except:
-			missing_elfs.append(elf)
+			missing_binaries.append(binary)
 			continue
-		for elf_dep in forward_linkings[elf]:
+
+		count = 0
+		for soname in forward_linkings[binary]:
 			try:
-				filename = so2filename_mappings[elf_dep]
-				flags = pax.getflags(filename)
-				print '\t', elf_dep, '\t', filename, '(', flags, ')'
+				library = so2filename_mappings[soname]
+				library_flags = pax.getflags(library)
+				s = "%s\n\t%s\t%s ( %s )" % ( s, soname, library, library_flags )
+				if binary_flags != library_flags:
+					count = count + 1
 			except:
-				missing_links.append(elf_dep)
+				missing_links.append(soname)
+
+		if verbose:
+			print s
+			if count == 0:
+				print 'No mismatches'
+		else:
+			if count != 0:
+				print s
 
-	missing_elfs = set(missing_elfs)
+	missing_binaries = set(missing_binaries)
 	print '\n\n'
-	print '**** Missing elfs ****'
-	for m in missing_elfs:
+	print '**** Missing binaries ****'
+	for m in missing_binaries:
 		print m
 
 	missing_links = set(missing_links)
@@ -104,27 +118,42 @@ def print_forward_linkings( forward_linkings, so2filename_mappings ):
 	print '\n\n'
 
 
-def print_reverse_linkings( reverse_linkings, so2filename_mappings ):
-	missing_elfs = []
+def print_reverse_linkings( reverse_linkings, so2filename_mappings, verbose ):
+	missing_sonames = []
 	missing_links = []
-	for elf in reverse_linkings:
+
+	for soname in reverse_linkings:
+
 		try:
-			filename = so2filename_mappings[elf]
-			flags = pax.getflags(filename)
-			print elf, '\t', filename, '(', flags, ')'
+			library = so2filename_mappings[soname]
+			library_flags = pax.getflags(library)
+			s = "%s\t%s ( %s )" % ( soname, library, library_flags )
 		except:
-			missing_elfs.append(elf)
-		for elf_dep in reverse_linkings[elf]:
+			missing_libraries.append(soname)
+			continue
+
+		count = 0
+		for binary in reverse_linkings[soname]:
 			try:
-				flags = pax.getflags(elf_dep)
-				print '\t', elf_dep, '(', flags, ')'
+				binary_flags = pax.getflags(binary)
+				s = "%s\n\t%s ( %s )" % ( s, binary, binary_flags )
+				if library_flags != binary_flags:
+					count = count + 1
 			except:
-				missing_links.append(elf_dep)
+				missing_links.append(binary)
 
-	missing_elfs = set(missing_elfs)
+		if verbose:
+			print s
+			if count == 0:
+				print 'No mismatches'
+		else:
+			if count != 0:
+				print s
+
+	missing_sonames = set(missing_sonames)
 	print '\n\n'
-	print '**** Missing elfs ****'
-	for m in missing_elfs:
+	print '**** Missing sonames ****'
+	for m in missing_sonames:
 		print m
 
 	missing_links = set(missing_links)
@@ -136,29 +165,32 @@ def print_reverse_linkings( reverse_linkings, so2filename_mappings ):
 	print '\n\n'
 
 
-def usage():
-	print 'Package Name : elfix\n'
+def run_usage():
+	print 'Package Name : elfix'
 	print 'Bug Reports  : http://bugs.gentoo.org/'
-	print 'Program Name : revdep-pax\n'
-	print 'Description  : Get or set pax flags on an ELF object\n\n'
-	print 'Usage        : revdep-pax [-fv] | [-rv] | -v [-b BINARY] | -v [-s SONAME] | -h\n\n'
-	print 'Options      : -f         print out all the forward mappings for all system binaries\n'
-	print '             : -r         print out all the reverse mappints for all system sonames\n'
-	print '             : -b BINARY  print all the forward mappings only for BINARY\n'
-	print '             : -s SONAME  print all the reverse mappings only for SONAME\n'
-	print '             : -v         verbose, otherwise just print mismatched pax flags \n'
-	print '             : -h         print out this help\n\n'
-
-
-def run_forward():
+	print 'Program Name : revdep-pax'
+	print 'Description  : Get or set pax flags on an ELF object'
+	print
+	print 'Usage        : revdep-pax [-fv] | [-rv] | -v [-b BINARY] | -v [-s SONAME] | -h'
+	print
+	print 'Options      : -f         print out all the forward mappings for all system binaries'
+	print '             : -r         print out all the reverse mappints for all system sonames'
+	print '             : -b BINARY  print all the forward mappings only for BINARY'
+	print '             : -s SONAME  print all the reverse mappings only for SONAME'
+	print '             : -v         verbose, otherwise just print mismatched pax flags'
+	print '             : -h         print out this help'
+	print
+
+
+def run_forward(verbose):
 	( forward_linkings, so2filename_mappings ) = get_forward_linkings()
-	print_forward_linkings( forward_linkings, so2filename_mappings )
+	print_forward_linkings( forward_linkings, so2filename_mappings, verbose)
 
 
-def run_reverse():
+def run_reverse(verbose):
 	( forward_linkings, so2filename_mappings ) = get_forward_linkings()
 	reverse_linkings = invert_linkings( forward_linkings )
-	print_reverse_linkings( reverse_linkings, so2filename_mappings )
+	print_reverse_linkings( reverse_linkings, so2filename_mappings, verbose )
 
 
 def run_binary(binary, verbose):
@@ -170,19 +202,20 @@ def run_binary(binary, verbose):
 	count = 0
 	for soname in linkings:
 		try:
-			filename = mappings[soname]
-			soname_flags = pax.getflags(filename)
+			library = mappings[soname]
+			library_flags = pax.getflags(library)
 			if verbose:
-				print '\t', soname, '\t', filename, '(', soname_flags, ')'
+				print '\t', soname, '\t', library, '(', library_flags, ')'
 			else:
-				if binary_flags != soname_flags:
-					print '\t', soname, '\t',filename, '(', soname_flags, ')'
+				if binary_flags != library_flags:
+					print '\t', soname, '\t', library, '(', library_flags, ')'
 					count = count + 1
 		except:
 			print "file for soname %s not found" % soname
 
 	if count == 0:
-		print '\nNo mismatches'
+		print
+		print 'No mismatches'
 
 
 def run_soname(soname, verbose):
@@ -191,17 +224,24 @@ def run_soname(soname, verbose):
 	linkings = reverse_linkings[soname]
 	library = so2filename_mappings[soname]
 
-	flags = pax.getflags(library)
-	if verbose:
-		print soname, '\t', library, '(', flags, ')'
+	library_flags = pax.getflags(library)
+	print soname, '\t', library, '(', library_flags, ')'
+
+	count = 0
 	for binary in linkings:
 		try:
-			flags = pax.getflags(binary)
+			binary_flags = pax.getflags(binary)
 			if verbose:
-				print '\t', binary, '(', flags, ')'
+				print '\t', binary, '(', binary_flags, ')'
+			else:
+				if library_flags != binary_flags:
+					print '\t', binary, '(', binary_flags, ')'
+					count = count + 1
 		except:
 			print "cannot obtain pax flags for %s" % binary
 
+	if count == 0:
+		print '\nNo mismatches'
 
 def main():
 	try:
@@ -242,21 +282,20 @@ def main():
 			print 'Please file a bug'
 			sys.exit(1)
 
-
 	if do_usage:
 		run_usage()
 
 	if do_forward:
-		run_forward()
+		run_forward(verbose)
 
 	if do_reverse:
-		run_reverse()
+		run_reverse(verbose)
 
 	if binary != None:
 		run_binary(binary, verbose)
 
 	if soname !=None:
-		run_soname(soname)
+		run_soname(soname, verbose)
 
 if __name__ == '__main__':
     main()



^ permalink raw reply related	[flat|nested] 89+ messages in thread
* [gentoo-commits] proj/elfix:master commit in: scripts/
@ 2011-10-10 17:30 Anthony G. Basile
  0 siblings, 0 replies; 89+ messages in thread
From: Anthony G. Basile @ 2011-10-10 17:30 UTC (permalink / raw
  To: gentoo-commits

commit:     1317f9a59a3e42ec75814bf27cb0551967f273b0
Author:     Anthony G. Basile <blueness <AT> gentoo <DOT> org>
AuthorDate: Mon Oct 10 17:30:06 2011 +0000
Commit:     Anthony G. Basile <blueness <AT> gentoo <DOT> org>
CommitDate: Mon Oct 10 17:30:06 2011 +0000
URL:        http://git.overlays.gentoo.org/gitweb/?p=proj/elfix.git;a=commit;h=1317f9a5

scripts/revdep-pax: add help

---
 scripts/revdep-pax |   13 ++++++++++++-
 1 files changed, 12 insertions(+), 1 deletions(-)

diff --git a/scripts/revdep-pax b/scripts/revdep-pax
index 26334c7..bdf6004 100755
--- a/scripts/revdep-pax
+++ b/scripts/revdep-pax
@@ -137,7 +137,18 @@ def print_reverse_linkings( reverse_linkings, so2filename_mappings ):
 
 
 def usage():
-	print 'TODO'
+	print 'Package Name : elfix\n'
+	print 'Bug Reports  : http://bugs.gentoo.org/'
+	print 'Program Name : revdep-pax\n'
+	print 'Description  : Get or set pax flags on an ELF object\n\n'
+	print 'Usage        : revdep-pax [-fv] | [-rv] | -v [-b BINARY] | -v [-s SONAME] | -h\n\n'
+	print 'Options      : -f         print out all the forward mappings for all system binaries\n'
+	print '             : -r         print out all the reverse mappints for all system sonames\n'
+	print '             : -b BINARY  print all the forward mappings only for BINARY\n'
+	print '             : -s SONAME  print all the reverse mappings only for SONAME\n'
+	print '             : -v         verbose, otherwise just print mismatched pax flags \n'
+	print '             : -h         print out this help\n\n'
+
 
 def run_forward():
 	( forward_linkings, so2filename_mappings ) = get_forward_linkings()



^ permalink raw reply related	[flat|nested] 89+ messages in thread
* [gentoo-commits] proj/elfix:master commit in: scripts/
@ 2011-10-10 17:29 Anthony G. Basile
  0 siblings, 0 replies; 89+ messages in thread
From: Anthony G. Basile @ 2011-10-10 17:29 UTC (permalink / raw
  To: gentoo-commits

commit:     9e60775a2f9e3b39abbc42cd7c27a42310cfdbfa
Author:     Anthony G. Basile <blueness <AT> gentoo <DOT> org>
AuthorDate: Mon Oct 10 17:29:17 2011 +0000
Commit:     Anthony G. Basile <blueness <AT> gentoo <DOT> org>
CommitDate: Mon Oct 10 17:29:17 2011 +0000
URL:        http://git.overlays.gentoo.org/gitweb/?p=proj/elfix.git;a=commit;h=9e60775a

scripts/revdep-pax: move option actions to functions

---
 scripts/revdep-pax |  111 +++++++++++++++++++++++++++++++++-------------------
 1 files changed, 71 insertions(+), 40 deletions(-)

diff --git a/scripts/revdep-pax b/scripts/revdep-pax
index e91a964..26334c7 100755
--- a/scripts/revdep-pax
+++ b/scripts/revdep-pax
@@ -16,7 +16,7 @@ def get_ldd_linkings(elf):
 		return []
 	ldd_lines = ldd_output.split('\n')
 	linkings = []
-	mappings = []
+	mappings = {}
 	for m in range(0,len(ldd_lines)):
 		if not re.search('=>', ldd_lines[m]):
 			continue
@@ -29,7 +29,7 @@ def get_ldd_linkings(elf):
 			continue
 		filename = os.path.realpath(filename)
 		linkings.append(soname)
-		mappings.append([soname,filename])
+		mappings[soname] = filename
 	return ( linkings, mappings )
 
 
@@ -52,8 +52,7 @@ def get_forward_linkings():
 					elf = link[0]
 					( linkings, mappings ) = get_ldd_linkings(elf)
 					forward_linkings[elf] = linkings 
-					for m in mappings:
-						so2filename_mappings[m[0]] = m[1]
+					so2filename_mappings.update(mappings)
 			except:
 				continue
 
@@ -140,10 +139,62 @@ def print_reverse_linkings( reverse_linkings, so2filename_mappings ):
 def usage():
 	print 'TODO'
 
+def run_forward():
+	( forward_linkings, so2filename_mappings ) = get_forward_linkings()
+	print_forward_linkings( forward_linkings, so2filename_mappings )
+
+
+def run_reverse():
+	( forward_linkings, so2filename_mappings ) = get_forward_linkings()
+	reverse_linkings = invert_linkings( forward_linkings )
+	print_reverse_linkings( reverse_linkings, so2filename_mappings )
+
+
+def run_binary(binary, verbose):
+	( linkings, mappings ) = get_ldd_linkings(binary)
+
+	binary_flags = pax.getflags(binary)
+	print binary, '(', binary_flags, ')'
+
+	count = 0
+	for soname in linkings:
+		try:
+			filename = mappings[soname]
+			soname_flags = pax.getflags(filename)
+			if verbose:
+				print '\t', soname, '\t', filename, '(', soname_flags, ')'
+			else:
+				if binary_flags != soname_flags:
+					print '\t', soname, '\t',filename, '(', soname_flags, ')'
+					count = count + 1
+		except:
+			print "file for soname %s not found" % soname
+
+	if count == 0:
+		print '\nNo mismatches'
+
+
+def run_soname(soname, verbose):
+	( forward_linkings, so2filename_mappings ) = get_forward_linkings()
+	reverse_linkings = invert_linkings( forward_linkings )
+	linkings = reverse_linkings[soname]
+	library = so2filename_mappings[soname]
+
+	flags = pax.getflags(library)
+	if verbose:
+		print soname, '\t', library, '(', flags, ')'
+	for binary in linkings:
+		try:
+			flags = pax.getflags(binary)
+			if verbose:
+				print '\t', binary, '(', flags, ')'
+		except:
+			print "cannot obtain pax flags for %s" % binary
+
 
 def main():
 	try:
-		opts, args = getopt.getopt(sys.argv[1:], 'hfrb:s:')
+		opts, args = getopt.getopt(sys.argv[1:], 'hfrb:s:v')
 	except getopt.GetoptError, err:
 		print str(err) # will print something like 'option -a not recognized'
 		usage()
@@ -153,16 +204,18 @@ def main():
 		usage()
 		sys.exit(1)
 
+	do_usage   = False
 	do_forward = False
 	do_reverse = False
+
 	binary = None
 	soname = None
 
+	verbose = False
 
 	for o, a in opts:
 		if o == '-h':
-			usage()
-			sys.exit(1)
+			do_usage = True
 		elif o == '-f':
 			do_forward = True
 		elif o == '-r':
@@ -171,50 +224,28 @@ def main():
 			binary = a
 		elif o == '-s':
 			soname = a
+		elif o == '-v':
+			verbose = True
 		else:
 			print 'Option included in getopt but not handled here!'
-			usage()
+			print 'Please file a bug'
 			sys.exit(1)
 
+
+	if do_usage:
+		run_usage()
+
 	if do_forward:
-		( forward_linkings, so2filename_mappings ) = get_forward_linkings()
-		print_forward_linkings( forward_linkings, so2filename_mappings )
+		run_forward()
 
 	if do_reverse:
-		( forward_linkings, so2filename_mappings ) = get_forward_linkings()
-		reverse_linkings = invert_linkings( forward_linkings )
-		print_reverse_linkings( reverse_linkings, so2filename_mappings )
+		run_reverse()
 
 	if binary != None:
-		( forward_linkings, so2filename_mappings ) = get_forward_linkings()
-		linkings = forward_linkings[binary]
-
-		flags = pax.getflags(binary)
-		print binary, '(', flags, ')'
-		for soname in linkings:
-			try:
-				filename = so2filename_mappings[soname]
-				flags = pax.getflags(filename)
-				print '\t', soname, '\t', filename, '(', flags, ')'
-			except:
-				print "file for soname %s not found" % soname
+		run_binary(binary, verbose)
 
 	if soname !=None:
-		( forward_linkings, so2filename_mappings ) = get_forward_linkings()
-		reverse_linkings = invert_linkings( forward_linkings )
-		linkings = reverse_linkings[soname]
-		library = so2filename_mappings[soname]
-
-		flags = pax.getflags(library)
-		print soname, '\t', library, '(', flags, ')'
-		for binary in linkings:
-			try:
-				flags = pax.getflags(binary)
-				print '\t', binary, '(', flags, ')'
-			except:
-				print "cannot obtain pax flags for %s" % binary
-
+		run_soname(soname)
 
 if __name__ == '__main__':
     main()
-



^ permalink raw reply related	[flat|nested] 89+ messages in thread
* [gentoo-commits] proj/elfix:master commit in: scripts/
@ 2011-10-08 18:35 Anthony G. Basile
  0 siblings, 0 replies; 89+ messages in thread
From: Anthony G. Basile @ 2011-10-08 18:35 UTC (permalink / raw
  To: gentoo-commits

commit:     67057c3c0a24cb9ccfc0654acaedcdb7b2eedf5c
Author:     Anthony G. Basile <blueness <AT> gentoo <DOT> org>
AuthorDate: Sat Oct  8 18:35:30 2011 +0000
Commit:     Anthony G. Basile <blueness <AT> gentoo <DOT> org>
CommitDate: Sat Oct  8 18:35:30 2011 +0000
URL:        http://git.overlays.gentoo.org/gitweb/?p=proj/elfix.git;a=commit;h=67057c3c

scripts/Makefile.am: fix to work with make dist

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

diff --git a/scripts/Makefile.am b/scripts/Makefile.am
index 9faaeac..089cc3c 100644
--- a/scripts/Makefile.am
+++ b/scripts/Makefile.am
@@ -1 +1 @@
-sbin_SCRIPTS = revdep-pax
+dist_sbin_SCRIPTS = revdep-pax



^ permalink raw reply related	[flat|nested] 89+ messages in thread
* [gentoo-commits] proj/elfix:master commit in: scripts/
@ 2011-10-08  2:03 Anthony G. Basile
  0 siblings, 0 replies; 89+ messages in thread
From: Anthony G. Basile @ 2011-10-08  2:03 UTC (permalink / raw
  To: gentoo-commits

commit:     36e13b75a70b687561cba3cef219642e346e2ce6
Author:     Anthony G. Basile <blueness <AT> gentoo <DOT> org>
AuthorDate: Sat Oct  8 02:01:44 2011 +0000
Commit:     Anthony G. Basile <blueness <AT> gentoo <DOT> org>
CommitDate: Sat Oct  8 02:01:44 2011 +0000
URL:        http://git.overlays.gentoo.org/gitweb/?p=proj/elfix.git;a=commit;h=36e13b75

scripts/revdep-pax: completed four command line options

-f all forward linkings from binary to their libraries
-r all reverse linkings from libraries to binaries that consume them
-b binary - forward mapping for given binary
-s soname - reverse mapping for given library identified by soname

---
 scripts/revdep-pax |   40 ++++++++++++++++++++++++++--------------
 1 files changed, 26 insertions(+), 14 deletions(-)

diff --git a/scripts/revdep-pax b/scripts/revdep-pax
index 98a2985..e91a964 100755
--- a/scripts/revdep-pax
+++ b/scripts/revdep-pax
@@ -143,7 +143,7 @@ def usage():
 
 def main():
 	try:
-		opts, args = getopt.getopt(sys.argv[1:], 'hfrb:l:')
+		opts, args = getopt.getopt(sys.argv[1:], 'hfrb:s:')
 	except getopt.GetoptError, err:
 		print str(err) # will print something like 'option -a not recognized'
 		usage()
@@ -156,7 +156,7 @@ def main():
 	do_forward = False
 	do_reverse = False
 	binary = None
-	library = None
+	soname = None
 
 
 	for o, a in opts:
@@ -169,8 +169,8 @@ def main():
 			do_reverse = True
 		elif o == '-b':
 			binary = a
-		elif o == '-l':
-			library = a
+		elif o == '-s':
+			soname = a
 		else:
 			print 'Option included in getopt but not handled here!'
 			usage()
@@ -188,20 +188,32 @@ def main():
 	if binary != None:
 		( forward_linkings, so2filename_mappings ) = get_forward_linkings()
 		linkings = forward_linkings[binary]
-		print linkings
 
-		"""
-		try:
-			filename = so2filename_mappings[binary]
-			flags = pax.getflags(filename)
-			print binary, '\t', filename, '(', flags, ')'
-		except:
-			print "%s doesn't link to anything that I know of" % binary
-		"""
+		flags = pax.getflags(binary)
+		print binary, '(', flags, ')'
+		for soname in linkings:
+			try:
+				filename = so2filename_mappings[soname]
+				flags = pax.getflags(filename)
+				print '\t', soname, '\t', filename, '(', flags, ')'
+			except:
+				print "file for soname %s not found" % soname
 
-	if library !=None:
+	if soname !=None:
 		( forward_linkings, so2filename_mappings ) = get_forward_linkings()
 		reverse_linkings = invert_linkings( forward_linkings )
+		linkings = reverse_linkings[soname]
+		library = so2filename_mappings[soname]
+
+		flags = pax.getflags(library)
+		print soname, '\t', library, '(', flags, ')'
+		for binary in linkings:
+			try:
+				flags = pax.getflags(binary)
+				print '\t', binary, '(', flags, ')'
+			except:
+				print "cannot obtain pax flags for %s" % binary
+
 
 if __name__ == '__main__':
     main()



^ permalink raw reply related	[flat|nested] 89+ messages in thread
* [gentoo-commits] proj/elfix:master commit in: scripts/
@ 2011-10-08  0:46 Anthony G. Basile
  0 siblings, 0 replies; 89+ messages in thread
From: Anthony G. Basile @ 2011-10-08  0:46 UTC (permalink / raw
  To: gentoo-commits

commit:     867d4048244e27cb269cf4dfeca98dad3e60da19
Author:     Anthony G. Basile <blueness <AT> gentoo <DOT> org>
AuthorDate: Sat Oct  8 00:45:06 2011 +0000
Commit:     Anthony G. Basile <blueness <AT> gentoo <DOT> org>
CommitDate: Sat Oct  8 00:45:06 2011 +0000
URL:        http://git.overlays.gentoo.org/gitweb/?p=proj/elfix.git;a=commit;h=867d4048

scripts/revdep-pax: fixed two bugs

1) We need to continue to the next pkg not break out of the loop
when /var/db/pkg/cat/pkg/NEEDED is missing

2) print_forward_linkings needs so2filename_mappings to do its job

---
 scripts/revdep-pax |   29 ++++++++++++++++++++++++-----
 1 files changed, 24 insertions(+), 5 deletions(-)

diff --git a/scripts/revdep-pax b/scripts/revdep-pax
index 6a28a72..98a2985 100755
--- a/scripts/revdep-pax
+++ b/scripts/revdep-pax
@@ -12,6 +12,7 @@ def get_ldd_linkings(elf):
 		#When subprocess.DEVNULL makes it to python, change this: http://bugs.python.org/issue5870
 		ldd_output = subprocess.check_output(['/usr/bin/ldd', elf], stderr=subprocess.PIPE)
 	except:
+		# We should record these elfs which are probably static
 		return []
 	ldd_lines = ldd_output.split('\n')
 	linkings = []
@@ -54,7 +55,7 @@ def get_forward_linkings():
 					for m in mappings:
 						so2filename_mappings[m[0]] = m[1]
 			except:
-				break
+				continue
 
 	return ( forward_linkings, so2filename_mappings )
 
@@ -104,7 +105,7 @@ def print_forward_linkings( forward_linkings, so2filename_mappings ):
 	print '\n\n'
 
 
-def print_reverse_linkings( reverse_linkings ):
+def print_reverse_linkings( reverse_linkings, so2filename_mappings ):
 	missing_elfs = []
 	missing_links = []
 	for elf in reverse_linkings:
@@ -152,11 +153,11 @@ def main():
 		usage()
 		sys.exit(1)
 
+	do_forward = False
+	do_reverse = False
 	binary = None
 	library = None
 
-	do_forward = False
-	do_reverse = False
 
 	for o, a in opts:
 		if o == '-h':
@@ -182,7 +183,25 @@ def main():
 	if do_reverse:
 		( forward_linkings, so2filename_mappings ) = get_forward_linkings()
 		reverse_linkings = invert_linkings( forward_linkings )
-		print_reverse_linkings( reverse_linkings )
+		print_reverse_linkings( reverse_linkings, so2filename_mappings )
+
+	if binary != None:
+		( forward_linkings, so2filename_mappings ) = get_forward_linkings()
+		linkings = forward_linkings[binary]
+		print linkings
+
+		"""
+		try:
+			filename = so2filename_mappings[binary]
+			flags = pax.getflags(filename)
+			print binary, '\t', filename, '(', flags, ')'
+		except:
+			print "%s doesn't link to anything that I know of" % binary
+		"""
+
+	if library !=None:
+		( forward_linkings, so2filename_mappings ) = get_forward_linkings()
+		reverse_linkings = invert_linkings( forward_linkings )
 
 if __name__ == '__main__':
     main()



^ permalink raw reply related	[flat|nested] 89+ messages in thread
* [gentoo-commits] proj/elfix:master commit in: scripts/
@ 2011-10-07 22:14 Anthony G. Basile
  0 siblings, 0 replies; 89+ messages in thread
From: Anthony G. Basile @ 2011-10-07 22:14 UTC (permalink / raw
  To: gentoo-commits

commit:     ae012c0b97d99d8d0abdfabbea4931c1616b8519
Author:     Anthony G. Basile <blueness <AT> gentoo <DOT> org>
AuthorDate: Fri Oct  7 22:14:35 2011 +0000
Commit:     Anthony G. Basile <blueness <AT> gentoo <DOT> org>
CommitDate: Fri Oct  7 22:14:35 2011 +0000
URL:        http://git.overlays.gentoo.org/gitweb/?p=proj/elfix.git;a=commit;h=ae012c0b

scripts/revdep-pax: added main() and command line opts

---
 scripts/revdep-pax |   60 +++++++++++++++++++++++++++++++++++++++++++++-------
 1 files changed, 52 insertions(+), 8 deletions(-)

diff --git a/scripts/revdep-pax b/scripts/revdep-pax
index 48b11d4..6a28a72 100755
--- a/scripts/revdep-pax
+++ b/scripts/revdep-pax
@@ -1,5 +1,7 @@
 #!/usr/bin/env python
 
+import sys
+import getopt
 import os
 import subprocess
 import re
@@ -31,7 +33,7 @@ def get_ldd_linkings(elf):
 
 
 def get_forward_linkings():
-	""" I'm still not sure we wan to use /var/db/pkg vs some path of binaries """
+	# I'm still not sure we wan to use /var/db/pkg vs some path of binaries
 	var_db_pkg = '/var/db/pkg'
 	forward_linkings = {}
 	so2filename_mappings = {}
@@ -70,7 +72,7 @@ def invert_linkings( forward_linkings ):
 	return reverse_linkings 
 
 
-def print_forward_linkings( forward_linkings ):
+def print_forward_linkings( forward_linkings, so2filename_mappings ):
 	missing_elfs = []
 	missing_links = []
 	for elf in forward_linkings:
@@ -87,7 +89,6 @@ def print_forward_linkings( forward_linkings ):
 			except:
 				missing_links.append(elf_dep)
 
-
 	missing_elfs = set(missing_elfs)
 	print '\n\n'
 	print '**** Missing elfs ****'
@@ -135,11 +136,54 @@ def print_reverse_linkings( reverse_linkings ):
 	print '\n\n'
 
 
-( forward_linkings, so2filename_mappings ) = get_forward_linkings()
-reverse_linkings = invert_linkings( forward_linkings )
-
-print_forward_linkings( forward_linkings )
-#print_reverse_linkings( reverse_linkings )
+def usage():
+	print 'TODO'
 
 
+def main():
+	try:
+		opts, args = getopt.getopt(sys.argv[1:], 'hfrb:l:')
+	except getopt.GetoptError, err:
+		print str(err) # will print something like 'option -a not recognized'
+		usage()
+		sys.exit(1)
+
+	if len(opts) == 0:
+		usage()
+		sys.exit(1)
+
+	binary = None
+	library = None
+
+	do_forward = False
+	do_reverse = False
+
+	for o, a in opts:
+		if o == '-h':
+			usage()
+			sys.exit(1)
+		elif o == '-f':
+			do_forward = True
+		elif o == '-r':
+			do_reverse = True
+		elif o == '-b':
+			binary = a
+		elif o == '-l':
+			library = a
+		else:
+			print 'Option included in getopt but not handled here!'
+			usage()
+			sys.exit(1)
+
+	if do_forward:
+		( forward_linkings, so2filename_mappings ) = get_forward_linkings()
+		print_forward_linkings( forward_linkings, so2filename_mappings )
+
+	if do_reverse:
+		( forward_linkings, so2filename_mappings ) = get_forward_linkings()
+		reverse_linkings = invert_linkings( forward_linkings )
+		print_reverse_linkings( reverse_linkings )
+
+if __name__ == '__main__':
+    main()
 



^ permalink raw reply related	[flat|nested] 89+ messages in thread
* [gentoo-commits] proj/elfix:master commit in: scripts/
@ 2011-10-07 19:58 Anthony G. Basile
  0 siblings, 0 replies; 89+ messages in thread
From: Anthony G. Basile @ 2011-10-07 19:58 UTC (permalink / raw
  To: gentoo-commits

commit:     f7dd2775675d1181bf4d72d625effbffe789dcda
Author:     Anthony G. Basile <blueness <AT> gentoo <DOT> org>
AuthorDate: Fri Oct  7 19:58:34 2011 +0000
Commit:     Anthony G. Basile <blueness <AT> gentoo <DOT> org>
CommitDate: Fri Oct  7 19:58:34 2011 +0000
URL:        http://git.overlays.gentoo.org/gitweb/?p=proj/elfix.git;a=commit;h=f7dd2775

scripts/revdep-pax: use ldd instead of ldconfig to get so2filename mappings

---
 scripts/revdep-pax |  130 +++++++++++++++++++++++++++++++--------------------
 1 files changed, 79 insertions(+), 51 deletions(-)

diff --git a/scripts/revdep-pax b/scripts/revdep-pax
index 1a5a2bb..48b11d4 100755
--- a/scripts/revdep-pax
+++ b/scripts/revdep-pax
@@ -7,27 +7,34 @@ import pax
 
 def get_ldd_linkings(elf):
 	try:
-		ldd_output = subprocess.check_output(["/usr/bin/ldd", elf])
+		#When subprocess.DEVNULL makes it to python, change this: http://bugs.python.org/issue5870
+		ldd_output = subprocess.check_output(['/usr/bin/ldd', elf], stderr=subprocess.PIPE)
 	except:
 		return []
 	ldd_lines = ldd_output.split('\n')
 	linkings = []
+	mappings = []
 	for m in range(0,len(ldd_lines)):
 		if not re.search('=>', ldd_lines[m]):
 			continue
 		ldd_lines[m] = ldd_lines[m].strip()
 		mapp = re.split('=>', ldd_lines[m] )
 		soname = mapp[0].strip()
+		soname = os.path.basename(soname)	# This is for ./libSDL-1.2.so.0
 		filename = re.sub('\(.*$', '', mapp[1]).strip()
 		if filename == '':
 			continue
-		filename =  os.path.realpath(filename)
+		filename = os.path.realpath(filename)
 		linkings.append(soname)
-	return linkings
+		mappings.append([soname,filename])
+	return ( linkings, mappings )
+
 
 def get_forward_linkings():
+	""" I'm still not sure we wan to use /var/db/pkg vs some path of binaries """
 	var_db_pkg = '/var/db/pkg'
 	forward_linkings = {}
+	so2filename_mappings = {}
 	for cat in os.listdir(var_db_pkg):
 		catdir = '%s/%s' % (var_db_pkg, cat)
 		for pkg in os.listdir(catdir):
@@ -40,13 +47,14 @@ def get_forward_linkings():
 					line = line.strip()
 					link = re.split('\s', line)
 					elf = link[0]
-					linkings = get_ldd_linkings(elf)
-					#linkings = re.split(',', link[1]) #this uses NEEDS to determine linkage
+					( linkings, mappings ) = get_ldd_linkings(elf)
 					forward_linkings[elf] = linkings 
+					for m in mappings:
+						so2filename_mappings[m[0]] = m[1]
 			except:
 				break
 
-	return forward_linkings 
+	return ( forward_linkings, so2filename_mappings )
 
 
 def invert_linkings( forward_linkings ):
@@ -62,56 +70,76 @@ def invert_linkings( forward_linkings ):
 	return reverse_linkings 
 
 
-def get_soname2file_mappings():
-	ldconfig_output = subprocess.check_output(["/sbin/ldconfig", "-p"])
-	ldconfig_lines = ldconfig_output.split('\n')
-	ldconfig_lines.pop(0)			#first line is a header
-	ldconfig_lines.pop()			#last line empty because of previous split
-	mappings = {}
-	for m in range(0,len(ldconfig_lines)):
-		ldconfig_lines[m] = ldconfig_lines[m].strip()
-		mapp = re.split('=>', ldconfig_lines[m] )
-		soname = re.sub('\(.*$', '', mapp[0]).strip()
-		abi = re.search('\(.+\)', mapp[0]).group(0)
-		abi = abi.strip().strip('(').strip(')').strip()
-		filename = mapp[1].strip()
-		filename =  os.path.realpath(filename)
-		mappings[soname] = [ filename, pax.getflags(filename), abi ]
-	return mappings 
-
-forward_linkings = get_forward_linkings()
-reverse_linkings = invert_linkings( forward_linkings )
-soname2file_mappings = get_soname2file_mappings()
+def print_forward_linkings( forward_linkings ):
+	missing_elfs = []
+	missing_links = []
+	for elf in forward_linkings:
+		try:
+			print elf, '(',  pax.getflags(elf), ')'
+		except:
+			missing_elfs.append(elf)
+			continue
+		for elf_dep in forward_linkings[elf]:
+			try:
+				filename = so2filename_mappings[elf_dep]
+				flags = pax.getflags(filename)
+				print '\t', elf_dep, '\t', filename, '(', flags, ')'
+			except:
+				missing_links.append(elf_dep)
+
+
+	missing_elfs = set(missing_elfs)
+	print '\n\n'
+	print '**** Missing elfs ****'
+	for m in missing_elfs:
+		print m
+
+	missing_links = set(missing_links)
+	print '\n\n'
+	print '**** Missing forward linkings ****'
+	for m in missing_links:
+		print m
+
+	print '\n\n'
+
+
+def print_reverse_linkings( reverse_linkings ):
+	missing_elfs = []
+	missing_links = []
+	for elf in reverse_linkings:
+		try:
+			filename = so2filename_mappings[elf]
+			flags = pax.getflags(filename)
+			print elf, '\t', filename, '(', flags, ')'
+		except:
+			missing_elfs.append(elf)
+		for elf_dep in reverse_linkings[elf]:
+			try:
+				flags = pax.getflags(elf_dep)
+				print '\t', elf_dep, '(', flags, ')'
+			except:
+				missing_links.append(elf_dep)
 
+	missing_elfs = set(missing_elfs)
+	print '\n\n'
+	print '**** Missing elfs ****'
+	for m in missing_elfs:
+		print m
 
-""" Print out mapping: binary -> library, library, library ... """
-unmapped = []
-for elf in forward_linkings:
-	print elf
-	for elf_dep in forward_linkings[elf]:
-		print "\t", elf_dep
-		#try:
-		#	print "\t\t", soname2file_mappings[elf_dep]
-		#except:
-		#	unmapped.append(elf_dep)
-		#	print "%s doesn't have a mapping" % elf_dep
+	missing_links = set(missing_links)
+	print '\n\n'
+	print '**** Missing reverse linkings ****'
+	for m in missing_links:
+		print m
 
-raw_input()
+	print '\n\n'
 
-print unmapped
 
-raw_input()
+( forward_linkings, so2filename_mappings ) = get_forward_linkings()
+reverse_linkings = invert_linkings( forward_linkings )
+
+print_forward_linkings( forward_linkings )
+#print_reverse_linkings( reverse_linkings )
 
 
-""" Print out mapping: library -> binary, binary, binary ...
-for elf_dep in reverse_linkings:
-	print elf_dep
-	for elf in reverse_linkings[elf_dep]:
-		print "\t", elf
-		#if not path.exists(elf):
-		#	print "%s doesn't exist!" % elf
-raw_input()
 
-for s in soname2file_mappings:
-	print s, soname2file_mappings[s]
-"""



^ permalink raw reply related	[flat|nested] 89+ messages in thread
* [gentoo-commits] proj/elfix:master commit in: scripts/
@ 2011-10-07  1:56 Anthony G. Basile
  0 siblings, 0 replies; 89+ messages in thread
From: Anthony G. Basile @ 2011-10-07  1:56 UTC (permalink / raw
  To: gentoo-commits

commit:     2950a1bfca41b4f8e139a438f0b14a7e3326aca5
Author:     Anthony G. Basile <blueness <AT> gentoo <DOT> org>
AuthorDate: Fri Oct  7 01:56:14 2011 +0000
Commit:     Anthony G. Basile <blueness <AT> gentoo <DOT> org>
CommitDate: Fri Oct  7 01:56:14 2011 +0000
URL:        http://git.overlays.gentoo.org/gitweb/?p=proj/elfix.git;a=commit;h=2950a1bf

scripts/revdep-pax: use ldd to get mappings rather than NEEDS

---
 scripts/revdep-pax |   39 +++++++++++++++++++++++++++++++++++----
 1 files changed, 35 insertions(+), 4 deletions(-)

diff --git a/scripts/revdep-pax b/scripts/revdep-pax
index 4873518..1a5a2bb 100755
--- a/scripts/revdep-pax
+++ b/scripts/revdep-pax
@@ -5,6 +5,25 @@ import subprocess
 import re
 import pax
 
+def get_ldd_linkings(elf):
+	try:
+		ldd_output = subprocess.check_output(["/usr/bin/ldd", elf])
+	except:
+		return []
+	ldd_lines = ldd_output.split('\n')
+	linkings = []
+	for m in range(0,len(ldd_lines)):
+		if not re.search('=>', ldd_lines[m]):
+			continue
+		ldd_lines[m] = ldd_lines[m].strip()
+		mapp = re.split('=>', ldd_lines[m] )
+		soname = mapp[0].strip()
+		filename = re.sub('\(.*$', '', mapp[1]).strip()
+		if filename == '':
+			continue
+		filename =  os.path.realpath(filename)
+		linkings.append(soname)
+	return linkings
 
 def get_forward_linkings():
 	var_db_pkg = '/var/db/pkg'
@@ -21,7 +40,8 @@ def get_forward_linkings():
 					line = line.strip()
 					link = re.split('\s', line)
 					elf = link[0]
-					linkings = re.split(',', link[1])
+					linkings = get_ldd_linkings(elf)
+					#linkings = re.split(',', link[1]) #this uses NEEDS to determine linkage
 					forward_linkings[elf] = linkings 
 			except:
 				break
@@ -46,7 +66,7 @@ def get_soname2file_mappings():
 	ldconfig_output = subprocess.check_output(["/sbin/ldconfig", "-p"])
 	ldconfig_lines = ldconfig_output.split('\n')
 	ldconfig_lines.pop(0)			#first line is a header
-	ldconfig_lines.pop()				#last line empty because of previous split
+	ldconfig_lines.pop()			#last line empty because of previous split
 	mappings = {}
 	for m in range(0,len(ldconfig_lines)):
 		ldconfig_lines[m] = ldconfig_lines[m].strip()
@@ -65,15 +85,25 @@ soname2file_mappings = get_soname2file_mappings()
 
 
 """ Print out mapping: binary -> library, library, library ... """
+unmapped = []
 for elf in forward_linkings:
 	print elf
 	for elf_dep in forward_linkings[elf]:
 		print "\t", elf_dep
-		#print "\t\t", soname2file_mappings[elf_dep]
+		#try:
+		#	print "\t\t", soname2file_mappings[elf_dep]
+		#except:
+		#	unmapped.append(elf_dep)
+		#	print "%s doesn't have a mapping" % elf_dep
 
 raw_input()
 
-""" Print out mapping: library -> binary, binary, binary ... """
+print unmapped
+
+raw_input()
+
+
+""" Print out mapping: library -> binary, binary, binary ...
 for elf_dep in reverse_linkings:
 	print elf_dep
 	for elf in reverse_linkings[elf_dep]:
@@ -84,3 +114,4 @@ raw_input()
 
 for s in soname2file_mappings:
 	print s, soname2file_mappings[s]
+"""



^ permalink raw reply related	[flat|nested] 89+ messages in thread
* [gentoo-commits] proj/elfix:master commit in: scripts/
@ 2011-10-06 23:39 Anthony G. Basile
  0 siblings, 0 replies; 89+ messages in thread
From: Anthony G. Basile @ 2011-10-06 23:39 UTC (permalink / raw
  To: gentoo-commits

commit:     81ae64185b7a145f81c92d1663dc459aae45c6a5
Author:     Anthony G. Basile <blueness <AT> gentoo <DOT> org>
AuthorDate: Thu Oct  6 23:39:08 2011 +0000
Commit:     Anthony G. Basile <blueness <AT> gentoo <DOT> org>
CommitDate: Thu Oct  6 23:39:08 2011 +0000
URL:        http://git.overlays.gentoo.org/gitweb/?p=proj/elfix.git;a=commit;h=81ae6418

scripts/revdep-pax: add soname to real file mappings

---
 scripts/revdep-pax |   32 +++++++++++++++++++++++++++-----
 1 files changed, 27 insertions(+), 5 deletions(-)

diff --git a/scripts/revdep-pax b/scripts/revdep-pax
index 697a41d..4873518 100755
--- a/scripts/revdep-pax
+++ b/scripts/revdep-pax
@@ -1,18 +1,17 @@
 #!/usr/bin/env python
 
-from os import listdir
-#from os import listdir, path
+import os
+import subprocess
 import re
-
 import pax
 
 
 def get_forward_linkings():
 	var_db_pkg = '/var/db/pkg'
 	forward_linkings = {}
-	for cat in listdir(var_db_pkg):
+	for cat in os.listdir(var_db_pkg):
 		catdir = '%s/%s' % (var_db_pkg, cat)
-		for pkg in listdir(catdir):
+		for pkg in os.listdir(catdir):
 			pkgdir = '%s/%s' % (catdir, pkg)
 			need = '%s/%s' % (pkgdir, 'NEEDED')
 			try:
@@ -43,8 +42,26 @@ def invert_linkings( forward_linkings ):
 	return reverse_linkings 
 
 
+def get_soname2file_mappings():
+	ldconfig_output = subprocess.check_output(["/sbin/ldconfig", "-p"])
+	ldconfig_lines = ldconfig_output.split('\n')
+	ldconfig_lines.pop(0)			#first line is a header
+	ldconfig_lines.pop()				#last line empty because of previous split
+	mappings = {}
+	for m in range(0,len(ldconfig_lines)):
+		ldconfig_lines[m] = ldconfig_lines[m].strip()
+		mapp = re.split('=>', ldconfig_lines[m] )
+		soname = re.sub('\(.*$', '', mapp[0]).strip()
+		abi = re.search('\(.+\)', mapp[0]).group(0)
+		abi = abi.strip().strip('(').strip(')').strip()
+		filename = mapp[1].strip()
+		filename =  os.path.realpath(filename)
+		mappings[soname] = [ filename, pax.getflags(filename), abi ]
+	return mappings 
+
 forward_linkings = get_forward_linkings()
 reverse_linkings = invert_linkings( forward_linkings )
+soname2file_mappings = get_soname2file_mappings()
 
 
 """ Print out mapping: binary -> library, library, library ... """
@@ -52,6 +69,7 @@ for elf in forward_linkings:
 	print elf
 	for elf_dep in forward_linkings[elf]:
 		print "\t", elf_dep
+		#print "\t\t", soname2file_mappings[elf_dep]
 
 raw_input()
 
@@ -62,3 +80,7 @@ for elf_dep in reverse_linkings:
 		print "\t", elf
 		#if not path.exists(elf):
 		#	print "%s doesn't exist!" % elf
+raw_input()
+
+for s in soname2file_mappings:
+	print s, soname2file_mappings[s]



^ permalink raw reply related	[flat|nested] 89+ messages in thread
* [gentoo-commits] proj/elfix:master commit in: scripts/
@ 2011-10-06 20:14 Anthony G. Basile
  0 siblings, 0 replies; 89+ messages in thread
From: Anthony G. Basile @ 2011-10-06 20:14 UTC (permalink / raw
  To: gentoo-commits

commit:     54370ba0e04f2be32117e7197caa52f71afd3053
Author:     Anthony G. Basile <blueness <AT> gentoo <DOT> org>
AuthorDate: Thu Oct  6 20:14:11 2011 +0000
Commit:     Anthony G. Basile <blueness <AT> gentoo <DOT> org>
CommitDate: Thu Oct  6 20:14:11 2011 +0000
URL:        http://git.overlays.gentoo.org/gitweb/?p=proj/elfix.git;a=commit;h=54370ba0

scripts/revdep-pax: improved variable names

---
 scripts/revdep-pax |   63 ++++++++++++++++++++++++++-------------------------
 1 files changed, 32 insertions(+), 31 deletions(-)

diff --git a/scripts/revdep-pax b/scripts/revdep-pax
index df78e35..697a41d 100755
--- a/scripts/revdep-pax
+++ b/scripts/revdep-pax
@@ -7,9 +7,9 @@ import re
 import pax
 
 
-def forward_linkings():
+def get_forward_linkings():
 	var_db_pkg = '/var/db/pkg'
-	elf_objects = {}
+	forward_linkings = {}
 	for cat in listdir(var_db_pkg):
 		catdir = '%s/%s' % (var_db_pkg, cat)
 		for pkg in listdir(catdir):
@@ -20,44 +20,45 @@ def forward_linkings():
 				needs = g.readlines()
 				for line in needs:
 					line = line.strip()
-					linking = re.split('\s', line)
-					elf = linking[0]
-					elf_deps = re.split(',', linking[1])
-					elf_objects[elf] = elf_deps 
+					link = re.split('\s', line)
+					elf = link[0]
+					linkings = re.split(',', link[1])
+					forward_linkings[elf] = linkings 
 			except:
 				break
 
-	return elf_objects 
+	return forward_linkings 
 
 
-def reverse_linkings( binaries ):
-	libraries = {}
-	for binary in binaries:
-		for library in binaries[binary]:
-			libraries[library] = []
+def invert_linkings( forward_linkings ):
+	reverse_linkings = {}
+	for elf in forward_linkings:
+		for elf_dep in forward_linkings[elf]:
+			reverse_linkings[elf_dep] = []
 
-	for binary in binaries:
-		for library in binaries[binary]:
-			libraries[library].append(binary)
+	for elf in forward_linkings:
+		for elf_dep in forward_linkings[elf]:
+			reverse_linkings[elf_dep].append(elf)
 
-	return libraries
+	return reverse_linkings 
 
 
-elf_objects = forward_linkings()
-elf_deps = reverse_linkings( elf_objects )
+forward_linkings = get_forward_linkings()
+reverse_linkings = invert_linkings( forward_linkings )
 
-""" Print out mapping: binary -> library, library, library ...
-for elf in elf_objects:
-	print elf
-	for elf_deps in elf_objects[elf]:
-		print "\t", elf_deps
-"""
 
-""" Print out mapping: library -> binary, binary, binary ...
-for elf in elf_deps:
+""" Print out mapping: binary -> library, library, library ... """
+for elf in forward_linkings:
 	print elf
-	for elf_object in elf_deps[elf]:
-		print "\t", elf_object
-		#if not path.exists(binary):
-		#	print "%s doesn't exist!" % binary
-"""
+	for elf_dep in forward_linkings[elf]:
+		print "\t", elf_dep
+
+raw_input()
+
+""" Print out mapping: library -> binary, binary, binary ... """
+for elf_dep in reverse_linkings:
+	print elf_dep
+	for elf in reverse_linkings[elf_dep]:
+		print "\t", elf
+		#if not path.exists(elf):
+		#	print "%s doesn't exist!" % elf



^ permalink raw reply related	[flat|nested] 89+ messages in thread
* [gentoo-commits] proj/elfix:master commit in: scripts/
@ 2011-10-06 19:46 Anthony G. Basile
  0 siblings, 0 replies; 89+ messages in thread
From: Anthony G. Basile @ 2011-10-06 19:46 UTC (permalink / raw
  To: gentoo-commits

commit:     406e2dc4ad36b188872149359a5f65dd4cd79fe8
Author:     Anthony G. Basile <blueness <AT> gentoo <DOT> org>
AuthorDate: Thu Oct  6 19:46:25 2011 +0000
Commit:     Anthony G. Basile <blueness <AT> gentoo <DOT> org>
CommitDate: Thu Oct  6 19:46:25 2011 +0000
URL:        http://git.overlays.gentoo.org/gitweb/?p=proj/elfix.git;a=commit;h=406e2dc4

scripts/revdep-pax: organize into functions

---
 scripts/revdep-pax |   89 ++++++++++++++++++++++++++++------------------------
 1 files changed, 48 insertions(+), 41 deletions(-)

diff --git a/scripts/revdep-pax b/scripts/revdep-pax
index ac21bae..df78e35 100755
--- a/scripts/revdep-pax
+++ b/scripts/revdep-pax
@@ -1,56 +1,63 @@
 #!/usr/bin/env python
 
 from os import listdir
-#from os import path
+#from os import listdir, path
 import re
 
 import pax
 
-var_db_pkg = '/var/db/pkg'
-
-binaries = {}
-for cat in listdir(var_db_pkg):
-	catdir = '%s/%s' % (var_db_pkg, cat)
-	for pkg in listdir(catdir):
-		pkgdir = '%s/%s' % (catdir, pkg)
-		need = '%s/%s' % (pkgdir, 'NEEDED')
-		try:
-			g = open(need, 'r')
-			needs = g.readlines()
-			for line in needs:
-				line = line.strip()
-				linking = re.split('\s', line)
-				binary = linking[0]
-				print binary
-				library_list = re.split(',', linking[1])
-				print "\t%s" % library_list
-				binaries[binary] = library_list
-		except:
-			break
 
-""" Print out mapping: binary -> library, library, library ...
-for binary in binaries:
-	print binary
-	for library in binaries[binary]:
-		print "\t", library
-"""
+def forward_linkings():
+	var_db_pkg = '/var/db/pkg'
+	elf_objects = {}
+	for cat in listdir(var_db_pkg):
+		catdir = '%s/%s' % (var_db_pkg, cat)
+		for pkg in listdir(catdir):
+			pkgdir = '%s/%s' % (catdir, pkg)
+			need = '%s/%s' % (pkgdir, 'NEEDED')
+			try:
+				g = open(need, 'r')
+				needs = g.readlines()
+				for line in needs:
+					line = line.strip()
+					linking = re.split('\s', line)
+					elf = linking[0]
+					elf_deps = re.split(',', linking[1])
+					elf_objects[elf] = elf_deps 
+			except:
+				break
+
+	return elf_objects 
+
+
+def reverse_linkings( binaries ):
+	libraries = {}
+	for binary in binaries:
+		for library in binaries[binary]:
+			libraries[library] = []
+
+	for binary in binaries:
+		for library in binaries[binary]:
+			libraries[library].append(binary)
 
-libraries = {}
-for binary in binaries:
-	for library in binaries[binary]:
-		libraries[library] = []
+	return libraries
 
-for binary in binaries:
-	for library in binaries[binary]:
-		libraries[library].append(binary)
+
+elf_objects = forward_linkings()
+elf_deps = reverse_linkings( elf_objects )
+
+""" Print out mapping: binary -> library, library, library ...
+for elf in elf_objects:
+	print elf
+	for elf_deps in elf_objects[elf]:
+		print "\t", elf_deps
+"""
 
 """ Print out mapping: library -> binary, binary, binary ...
-for library in libraries:
-	print library
-	for binary in libraries[library]:
-		print "\t", binary
+for elf in elf_deps:
+	print elf
+	for elf_object in elf_deps[elf]:
+		print "\t", elf_object
 		#if not path.exists(binary):
 		#	print "%s doesn't exist!" % binary
 """
-
-



^ permalink raw reply related	[flat|nested] 89+ messages in thread
* [gentoo-commits] proj/elfix:master commit in: scripts/
@ 2011-10-06  4:19 Anthony G. Basile
  0 siblings, 0 replies; 89+ messages in thread
From: Anthony G. Basile @ 2011-10-06  4:19 UTC (permalink / raw
  To: gentoo-commits

commit:     4e8f465fd70faffada1f99f0096c269080fa967a
Author:     Anthony G. Basile <blueness <AT> gentoo <DOT> org>
AuthorDate: Thu Oct  6 04:19:08 2011 +0000
Commit:     Anthony G. Basile <blueness <AT> gentoo <DOT> org>
CommitDate: Thu Oct  6 04:19:08 2011 +0000
URL:        http://git.overlays.gentoo.org/gitweb/?p=proj/elfix.git;a=commit;h=4e8f465f

scripts/paxmodule.c: return pax flags as string

---
 scripts/paxmodule.c |   46 ++++++++++++++++++++++++----------------------
 1 files changed, 24 insertions(+), 22 deletions(-)

diff --git a/scripts/paxmodule.c b/scripts/paxmodule.c
index 1b3e1eb..927bb50 100644
--- a/scripts/paxmodule.c
+++ b/scripts/paxmodule.c
@@ -54,17 +54,16 @@ pax_getflags(PyObject *self, PyObject *args)
 	int fd, sts;
 	Elf *elf;
 
+	char pax_buf[BUF_SIZE];
+
 	GElf_Ehdr ehdr;
-	char ei_buf[BUF_SIZE];
 	uint16_t ei_flags;
 
 	GElf_Phdr phdr;
-	char pt_buf[BUF_SIZE];
 	char found_pt_pax;
 	size_t i, phnum;
 
-	memset(ei_buf, 0, BUF_SIZE);
-	memset(pt_buf, 0, BUF_SIZE);
+	memset(pax_buf, 0, BUF_SIZE);
 
 	if (!PyArg_ParseTuple(args, "s", &f_name))
 	{
@@ -86,12 +85,15 @@ pax_getflags(PyObject *self, PyObject *args)
 
 	if((elf = elf_begin(fd, ELF_C_READ_MMAP, NULL)) == NULL)
 	{
+		close(fd);
 		PyErr_SetString(PaxError, "pax_getflags: elf_begin() failed");
 		return NULL;
 	}
 
 	if(elf_kind(elf) != ELF_K_ELF)
 	{
+		elf_end(elf);
+		close(fd);
 		PyErr_SetString(PaxError, "pax_getflags: elf_kind() failed: this is not an elf file.");
 		return NULL;
 	}
@@ -103,6 +105,8 @@ pax_getflags(PyObject *self, PyObject *args)
 	{
 		if(gelf_getphdr(elf, i, &phdr) != &phdr)
 		{
+			elf_end(elf);
+			close(fd);
 			PyErr_SetString(PaxError, "pax_getflags: gelf_getphdr() failed");
 			return NULL;
 		}
@@ -111,50 +115,48 @@ pax_getflags(PyObject *self, PyObject *args)
 		{
 			found_pt_pax = 1;
 
-			pt_buf[0] = phdr.p_flags & PF_PAGEEXEC ? 'P' :
+			pax_buf[0] = phdr.p_flags & PF_PAGEEXEC ? 'P' :
 				phdr.p_flags & PF_NOPAGEEXEC ? 'p' : '-' ;
 
-			pt_buf[1] = phdr.p_flags & PF_SEGMEXEC   ? 'S' : 
+			pax_buf[1] = phdr.p_flags & PF_SEGMEXEC   ? 'S' : 
 				phdr.p_flags & PF_NOSEGMEXEC ? 's' : '-';
 
-			pt_buf[2] = phdr.p_flags & PF_MPROTECT   ? 'M' :
+			pax_buf[2] = phdr.p_flags & PF_MPROTECT   ? 'M' :
 				phdr.p_flags & PF_NOMPROTECT ? 'm' : '-';
 
-			pt_buf[3] = phdr.p_flags & PF_EMUTRAMP   ? 'E' :
+			pax_buf[3] = phdr.p_flags & PF_EMUTRAMP   ? 'E' :
 				phdr.p_flags & PF_NOEMUTRAMP ? 'e' : '-';
 
-			pt_buf[4] = phdr.p_flags & PF_RANDMMAP   ? 'R' :
+			pax_buf[4] = phdr.p_flags & PF_RANDMMAP   ? 'R' :
 				phdr.p_flags & PF_NORANDMMAP ? 'r' : '-';
 
-			pt_buf[5] = phdr.p_flags & PF_RANDEXEC   ? 'X' :
+			pax_buf[5] = phdr.p_flags & PF_RANDEXEC   ? 'X' :
 				phdr.p_flags & PF_NORANDEXEC ? 'x' : '-';
 		}
 	}
 
-	if(found_pt_pax)
-		printf("PT_PAX: %s\n", pt_buf);
-	else
+	if(!found_pt_pax)
 	{
 		if(gelf_getehdr(elf, &ehdr) != &ehdr)
 		{
+			elf_end(elf);
+			close(fd);
 			PyErr_SetString(PaxError, "pax_getflags: gelf_getehdr() failed");
 			return NULL;
 		}
 
 		ei_flags = ehdr.e_ident[EI_PAX] + (ehdr.e_ident[EI_PAX + 1] << 8);
 
-  		ei_buf[0] = ei_flags & HF_PAX_PAGEEXEC ? 'p' : 'P';
-		ei_buf[1] = ei_flags & HF_PAX_SEGMEXEC ? 's' : 'S';
-		ei_buf[2] = ei_flags & HF_PAX_MPROTECT ? 'm' : 'M';
-		ei_buf[3] = ei_flags & HF_PAX_EMUTRAMP ? 'E' : 'e';
-		ei_buf[4] = ei_flags & HF_PAX_RANDMMAP ? 'r' : 'R';
-		ei_buf[5] = ei_flags & HF_PAX_RANDEXEC ? 'X' : 'x';
-
-		printf("EI_PAX: %s\n", ei_buf);
+  		pax_buf[0] = ei_flags & HF_PAX_PAGEEXEC ? 'p' : 'P';
+		pax_buf[1] = ei_flags & HF_PAX_SEGMEXEC ? 's' : 'S';
+		pax_buf[2] = ei_flags & HF_PAX_MPROTECT ? 'm' : 'M';
+		pax_buf[3] = ei_flags & HF_PAX_EMUTRAMP ? 'E' : 'e';
+		pax_buf[4] = ei_flags & HF_PAX_RANDMMAP ? 'r' : 'R';
+		pax_buf[5] = ei_flags & HF_PAX_RANDEXEC ? 'X' : 'x';
 	}
 
 	elf_end(elf);
 	close(fd);
 
-	return Py_BuildValue("i", sts);
+	return Py_BuildValue("s", pax_buf);
 }



^ permalink raw reply related	[flat|nested] 89+ messages in thread
* [gentoo-commits] proj/elfix:master commit in: scripts/
@ 2011-10-06  4:07 Anthony G. Basile
  0 siblings, 0 replies; 89+ messages in thread
From: Anthony G. Basile @ 2011-10-06  4:07 UTC (permalink / raw
  To: gentoo-commits

commit:     91cb263f60d7caf8298aee02e45dcb7bc8fe280a
Author:     Anthony G. Basile <blueness <AT> gentoo <DOT> org>
AuthorDate: Thu Oct  6 04:07:33 2011 +0000
Commit:     Anthony G. Basile <blueness <AT> gentoo <DOT> org>
CommitDate: Thu Oct  6 04:07:33 2011 +0000
URL:        http://git.overlays.gentoo.org/gitweb/?p=proj/elfix.git;a=commit;h=91cb263f

scripts/paxmodule.c: add code to read pax flags

---
 scripts/paxmodule.c |  127 ++++++++++++++++++++++++++++++++++++++++++++++++---
 scripts/setup.py    |    3 +-
 2 files changed, 122 insertions(+), 8 deletions(-)

diff --git a/scripts/paxmodule.c b/scripts/paxmodule.c
index 03ba794..1b3e1eb 100644
--- a/scripts/paxmodule.c
+++ b/scripts/paxmodule.c
@@ -1,5 +1,28 @@
 #include <Python.h>
 
+#include <stdio.h> //remove when you remove printf
+#include <string.h>
+
+#include <gelf.h>
+
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <fcntl.h>
+#include <unistd.h>
+
+
+#define HF_PAX_PAGEEXEC		1
+#define HF_PAX_EMUTRAMP		2
+#define HF_PAX_MPROTECT		4
+#define HF_PAX_RANDMMAP		8
+#define HF_PAX_RANDEXEC		16
+#define HF_PAX_SEGMEXEC		32
+
+#define EI_PAX			14	// Index to read the PaX flags into ELF header e_ident[] array
+
+#define BUF_SIZE		7	//Buffer for holding human readable flags
+
+
 static PyObject * pax_getflags(PyObject *, PyObject *);
 
 static PyMethodDef PaxMethods[] = {
@@ -27,21 +50,111 @@ initpax(void)
 static PyObject *
 pax_getflags(PyObject *self, PyObject *args)
 {
-	const char *value;
-	int sts;
+	const char *f_name;
+	int fd, sts;
+	Elf *elf;
+
+	GElf_Ehdr ehdr;
+	char ei_buf[BUF_SIZE];
+	uint16_t ei_flags;
+
+	GElf_Phdr phdr;
+	char pt_buf[BUF_SIZE];
+	char found_pt_pax;
+	size_t i, phnum;
+
+	memset(ei_buf, 0, BUF_SIZE);
+	memset(pt_buf, 0, BUF_SIZE);
 
-	if (!PyArg_ParseTuple(args, "s", &value))
+	if (!PyArg_ParseTuple(args, "s", &f_name))
+	{
+		PyErr_SetString(PaxError, "pax_getflags: PyArg_ParseTuple failed");
 		return NULL;
+	}
 
-	printf("%s\n", value);
+	if(elf_version(EV_CURRENT) == EV_NONE)
+	{
+		PyErr_SetString(PaxError, "pax_getflags: library out of date");
+		return NULL;
+	}
 
-	sts = 1;
+	if((fd = open(f_name, O_RDONLY)) < 0)
+	{
+		PyErr_SetString(PaxError, "pax_getflags: open() failed");
+		return NULL;
+	}
 
-	if (sts < 0)
+	if((elf = elf_begin(fd, ELF_C_READ_MMAP, NULL)) == NULL)
 	{
-		PyErr_SetString(PaxError, "pax_getflags failed");
+		PyErr_SetString(PaxError, "pax_getflags: elf_begin() failed");
 		return NULL;
 	}
 
+	if(elf_kind(elf) != ELF_K_ELF)
+	{
+		PyErr_SetString(PaxError, "pax_getflags: elf_kind() failed: this is not an elf file.");
+		return NULL;
+	}
+
+
+	found_pt_pax = 0;
+	elf_getphdrnum(elf, &phnum);
+	for(i=0; i<phnum; ++i)
+	{
+		if(gelf_getphdr(elf, i, &phdr) != &phdr)
+		{
+			PyErr_SetString(PaxError, "pax_getflags: gelf_getphdr() failed");
+			return NULL;
+		}
+
+		if(phdr.p_type == PT_PAX_FLAGS)
+		{
+			found_pt_pax = 1;
+
+			pt_buf[0] = phdr.p_flags & PF_PAGEEXEC ? 'P' :
+				phdr.p_flags & PF_NOPAGEEXEC ? 'p' : '-' ;
+
+			pt_buf[1] = phdr.p_flags & PF_SEGMEXEC   ? 'S' : 
+				phdr.p_flags & PF_NOSEGMEXEC ? 's' : '-';
+
+			pt_buf[2] = phdr.p_flags & PF_MPROTECT   ? 'M' :
+				phdr.p_flags & PF_NOMPROTECT ? 'm' : '-';
+
+			pt_buf[3] = phdr.p_flags & PF_EMUTRAMP   ? 'E' :
+				phdr.p_flags & PF_NOEMUTRAMP ? 'e' : '-';
+
+			pt_buf[4] = phdr.p_flags & PF_RANDMMAP   ? 'R' :
+				phdr.p_flags & PF_NORANDMMAP ? 'r' : '-';
+
+			pt_buf[5] = phdr.p_flags & PF_RANDEXEC   ? 'X' :
+				phdr.p_flags & PF_NORANDEXEC ? 'x' : '-';
+		}
+	}
+
+	if(found_pt_pax)
+		printf("PT_PAX: %s\n", pt_buf);
+	else
+	{
+		if(gelf_getehdr(elf, &ehdr) != &ehdr)
+		{
+			PyErr_SetString(PaxError, "pax_getflags: gelf_getehdr() failed");
+			return NULL;
+		}
+
+		ei_flags = ehdr.e_ident[EI_PAX] + (ehdr.e_ident[EI_PAX + 1] << 8);
+
+  		ei_buf[0] = ei_flags & HF_PAX_PAGEEXEC ? 'p' : 'P';
+		ei_buf[1] = ei_flags & HF_PAX_SEGMEXEC ? 's' : 'S';
+		ei_buf[2] = ei_flags & HF_PAX_MPROTECT ? 'm' : 'M';
+		ei_buf[3] = ei_flags & HF_PAX_EMUTRAMP ? 'E' : 'e';
+		ei_buf[4] = ei_flags & HF_PAX_RANDMMAP ? 'r' : 'R';
+		ei_buf[5] = ei_flags & HF_PAX_RANDEXEC ? 'X' : 'x';
+
+		printf("EI_PAX: %s\n", ei_buf);
+	}
+
+	elf_end(elf);
+	close(fd);
+
 	return Py_BuildValue("i", sts);
 }

diff --git a/scripts/setup.py b/scripts/setup.py
index 317efbd..77854f1 100755
--- a/scripts/setup.py
+++ b/scripts/setup.py
@@ -4,7 +4,8 @@ from distutils.core import setup, Extension
 
 module1 = Extension(
 	name='pax',
-	sources = ['paxmodule.c']
+	sources = ['paxmodule.c'],
+	libraries = ['elf'],
 )
 
 setup(



^ permalink raw reply related	[flat|nested] 89+ messages in thread
* [gentoo-commits] proj/elfix:master commit in: scripts/
@ 2011-10-06  3:14 Anthony G. Basile
  0 siblings, 0 replies; 89+ messages in thread
From: Anthony G. Basile @ 2011-10-06  3:14 UTC (permalink / raw
  To: gentoo-commits

commit:     b3247791db973583e62c517d6ab8a4c3bbb4c95e
Author:     Anthony G. Basile <blueness <AT> gentoo <DOT> org>
AuthorDate: Thu Oct  6 03:14:09 2011 +0000
Commit:     Anthony G. Basile <blueness <AT> gentoo <DOT> org>
CommitDate: Thu Oct  6 03:14:09 2011 +0000
URL:        http://git.overlays.gentoo.org/gitweb/?p=proj/elfix.git;a=commit;h=b3247791

scripts/revdep-paxmark: deprecated

---
 scripts/revdep-paxmark |  639 ------------------------------------------------
 1 files changed, 0 insertions(+), 639 deletions(-)

diff --git a/scripts/revdep-paxmark b/scripts/revdep-paxmark
deleted file mode 100755
index fd07c3c..0000000
--- a/scripts/revdep-paxmark
+++ /dev/null
@@ -1,639 +0,0 @@
-#!/bin/bash
-# Copyright 1999-2011 Gentoo Foundation
-
-#
-# This utility will look for any binaries which do not have
-# the same pax markings as the corresponding libraries which
-# they link against.
-#
-# This code is mostly derived from revdep-rebuild.
-#
-
-# Readonly variables:
-declare -r APP_NAME="${0##*/}" # The name of this application
-declare -r VERSION="0.1.0.0"
-declare -r OIFS="$IFS"         # Save the IFS
-declare -r     ENV_FILE=0_env.rr     # Contains environment variables
-declare -r   FILES_FILE=1_files.rr   # Contains a list of files to search
-declare -r  LDPATH_FILE=2_ldpath.rr  # Contains the LDPATH
-declare -r  BROKEN_FILE=3_broken.rr  # Contains the list of broken files
-declare -r  ERRORS_FILE=3_errors.rr  # Contains the ldd error output
-declare -ra FILES=(
-	"$ENV_FILE"
-	"$FILES_FILE"
-	"$LDPATH_FILE"
-	"$BROKEN_FILE"
-	"$ERRORS_FILE"
-)
-
-# "Boolean" variables: Considered "true" if it has any value at all
-# "True" indicates we should...
-declare FULL_LD_PATH           # ...search across the COMPLETE_LD_LIBRARY_PATH
-declare ORDER_PKGS             # ...sort the atoms in deep dependency order
-declare RM_OLD_TEMPFILES       # ...remove tempfiles from prior runs
-declare SEARCH_BROKEN          # ...search for broken libraries and binaries
-
-# Globals that impact portage directly:
-declare EMERGE_DEFAULT_OPTS    # String of options portage assumes to be set
-declare PORTAGE_NICENESS       # Renice to this value
-declare PORTAGE_ROOT           # The root path for portage
-
-# Customizable incremental variables:
-# These variables can be prepended to either by setting the variable in
-# your environment prior to execution, or by placing an entry in
-# /etc/make.conf.
-#
-# An entry of "-*" means to clear the variable from that point forward.
-# Example: env SEARCH_DIRS="/usr/bin -*" revdep-rebuild will set SEARCH_DIRS
-# to contain only /usr/bin
-declare LD_LIBRARY_MASK  # Mask of specially evaluated libraries
-declare SEARCH_DIRS      # List of dirs to search for executables and libraries
-declare SEARCH_DIRS_MASK # List of dirs not to search
-
-# Other globals:
-declare OLDPROG                # Previous pass through the progress meter
-declare EXACT_PKG              # Versionated atom to emerge
-declare HEAD_TEXT              # Feedback string about the search
-declare OK_TEXT                # Feedback about a search which found no errors
-declare REBUILD_LIST           # Array of atoms to emerge
-declare SONAME                 # Soname/soname path pattern given on commandline
-declare SONAME_SEARCH          # Value of SONAME modified to match ldd's output
-declare WORKING_TEXT           # Feedback about the search
-declare WORKING_DIR            # Working directory where cache files are kept
-
-main() {
-	portage_settings
-	get_opts "$@"
-	setup_search_paths_and_masks
-	get_search_env
-	get_files
-	get_ldpath
-	main_checks
-	cleanup
-}
-##
-# GNU find has -executable, but if our users' finds do not have that flag
-# we emulate it with this function. Also emulates -writable and -readable.
-# Usage: find PATH ARGS -- use find like normal, except use -executable instead
-# of various versions of -perm /+ blah blah and hacks
-find() {
-	hash find || { die 1 'find not found!'; }
-	# We can be pretty sure find itself should be executable.
-	local testsubject="$(type -P find)"
-	if [[ $(command find "$testsubject" -executable 2> /dev/null) ]]; then
-		unset -f find # We can just use the command find
-	elif [[ $(command find "$testsubject" -perm /u+x 2> /dev/null) ]]; then
-		find() {
-			a=(${@//-executable/-perm \/u+x})
-			a=(${a[@]//-writable/-perm \/u+w})
-			a=(${a[@]//-readable/-perm \/r+w})
-			command find "${a[@]}"
-		}
-	elif [[ $(command find "$testsubject" -perm +u+x 2> /dev/null) ]]; then
-		find() {
-			a=(${@//-executable/-perm +u+x})
-			a=(${a[@]//-writable/-perm +u+w})
-			a=(${a[@]//-readable/-perm +r+w})
-			command find "${a[@]}"
-		}
-	else # Last resort
-		find() {
-			a=(${@//-executable/-exec test -x '{}' \; -print})
-			a=(${a[@]//-writable/-exec test -w '{}' \; -print})
-			a=(${a[@]//-readable/-exec test -r '{}' \; -print})
-			command find "${a[@]}"
-		}
-	fi
-	find "$@"
-}
-
-print_usage() {
-cat << EOF
-${APP_NAME}: (${VERSION})
-
-Copyright (C) 2003-2010 Gentoo Foundation, Inc.
-This is free software; see the source for copying conditions.
-
-Usage: $APP_NAME [OPTIONS] [--]
-
-Broken reverse dependency rebuilder.
-
-  -C, --nocolor        Turn off colored output
-  -d, --debug          Print way too much information (uses bash's set -xv)
-  -h, --help           Print this usage
-  -i, --ignore         Ignore temporary files from previous runs
-  -k, --keep-temp      Do not delete temporary files on exit
-  -L, --library NAME   Emerge existing packages that use the library with NAME
-      --library=NAME   NAME can be a full path to the library or a basic
-                       regular expression (man grep)
-  -l, --no-ld-path     Do not set LD_LIBRARY_PATH
-  -P, --no-progress    Turn off the progress meter
-  -q, --quiet          Be less verbose (also passed to emerge command)
-  -v, --verbose        Be more verbose (also passed to emerge command)
-
-Calls emerge, options after -- are ignored by $APP_NAME
-and passed directly to emerge.
-
-Report bugs to <http://bugs.gentoo.org>
-
-EOF
-}
-##
-# Usage: progress i n
-#        i: current item
-#        n: total number of items to process
-progress() {
-	if [[ -t 1 ]]; then
-		progress() {
-			local curProg=$(( $1 * 100 / $2 ))
-			(( curProg == OLDPROG )) && return # no change, output nothing
-			OLDPROG="$curProg" # must be a global variable
-			(( $1 == $2 )) && local lb=$'\n'
-			echo -ne '\r                         \r'"[ $curProg% ] $lb"
-		}
-		progress $@
-	else # STDOUT is not a tty. Disable progress meter.
-		progress() { :; }
-	fi
-}
-##
-# Replace whitespace with linebreaks, normalize repeated '/' chars, and sort -u
-# (If any libs have whitespace in their filenames, someone needs punishment.)
-clean_var() {
-	gawk 'BEGIN         {RS="[[:space:]]"}
-	     /-\*/         {exit}
-	     /[^[:space:]]/ {gsub(/\/\/+/, "/"); print}' | sort -u
-}
-##
-# Exit and optionally output to sterr
-die() {
-	local status=$1
-	shift
-
-	type eerror &> /dev/null
-
-	if [[ $? -eq 0 ]];
-	then
-		eerror "$@"
-	else
-		echo " * ${@}" >> /dev/stderr
-	fi
-	exit $status
-}
-##
-# What to do when dynamic linking is consistent
-clean_exit() {
-	echo
-	einfo "$OK_TEXT... All done. "
-	exit 0
-}
-##
-# Get the name of the package that owns a file or list of files given as args.
-# NOTE: depends on app-misc/realpath!
-get_file_owner() {
-	local IFS=$'\n'
-
-	rpath=$(realpath "${*}" 2>/dev/null)
-	# To ensure we always have something in rpath...
-	[[ -z $rpath ]] && rpath=${*}
-
-	# Workaround for bug 280341
-	mlib=$(echo ${*}|sed 's:/lib/:/lib64/:')
-	[[ "${*}" == "${mlib}" ]] && mlib=$(echo ${*}|sed 's:/lib64/:/lib/:')
-
-	# Add a space to the end of each object name to prevent false
-	# matches, for example /usr/bin/dia matching /usr/bin/dialog (bug #196460).
-	# The same for "${rpath} ".
-	# Don't match an entry with a '-' at the start of the package name. This
-	# prevents us from matching invalid -MERGING entries. (bug #338031)
-	find -L /var/db/pkg -type f -name CONTENTS -print0 |
-		xargs -0 grep -m 1 -Fl -e "${*} " -e "${rpath} " -e "${mlib} " |
-		sed 's:/var/db/pkg/\(.*\)/\([^-].*\)/CONTENTS:\1/\2:'
-}
-##
-# Die if an argument is missing.
-die_if_missing_arg() {
-	[[ ! $2 || $2 = -* ]] && die 1 "Missing expected argument to $1"
-}
-##
-# Die because an option is not recognized.
-die_invalid_option() {
-	# Can't use eerror and einfo because this gets called before function.sh
-	# is sourced
-	echo
-	echo  "Encountered unrecognized option $1." >&2
-	echo
-	echo  "$APP_NAME no longer automatically passes unrecognized options to portage."
-	echo  "Separate emerge-only options from revdep-rebuild options with the -- flag."
-	echo
-	echo  "For example, $APP_NAME -v -- --ask"
-	echo
-	echo  "See the man page or $APP_NAME -h for more detail."
-	echo
-	exit 1
-}
-##
-# Get whole-word commandline options preceded by two dashes.
-get_longopts() {
-	case $1 in
-		                                 --debug) set -xv;;
-		                                  --help) print_usage
-		                                          exit 0;;
-		                                --ignore) RM_OLD_TEMPFILES=1;;
-		                             --library=*) SONAME="${1#*=}"
-		                                          unset SEARCH_BROKEN;;
-		                               --library) die_if_missing_arg $1 $2
-		                                          shift
-		                                          SONAME="$1"
-		                                          unset SEARCH_BROKEN;;
-		                            --no-ld-path) unset FULL_LD_PATH;;
-		                           --no-progress) progress() { :; };;
-		                                       *) die_invalid_option $1;;
-	esac
-}
-
-##
-# Get single-letter commandline options preceded by a single dash.
-get_shortopts() {
-	local OPT OPTSTRING OPTARG OPTIND
-	while getopts ":CdehikL:loPpqu:vX" OPT; do
-		case "$OPT" in
-			d) set -xv;;
-			h) print_usage
-			   exit 0;;
-			i) RM_OLD_TEMPFILES=1;;
-			L) SONAME="${OPTARG#*=}"
-			   unset SEARCH_BROKEN;;
-			l) unset FULL_LD_PATH;;
-			P) progress() { :; };;
-			*) die_invalid_option "-$OPTARG";;
-		esac
-	done
-}
-##
-# Get command-line options.
-get_opts() {
-	local avoid_utils
-	local -a args
-	echo_v() { ewarn "$@"; }
-	unset RM_OLD_TEMPFILES
-	ORDER_PKGS=1
-	SONAME="not found"
-	SEARCH_BROKEN=1
-	FULL_LD_PATH=1
-	while [[ $1 ]]; do
-		case $1 in
-			-*) while true; do
-			      args+=("$1")
-			      shift
-			      [[ ${1:--} = -* ]] && break
-			    done
-			    if [[ ${args[0]} = --* ]]; then
-			      get_longopts  "${args[@]}"
-			    else
-			      get_shortopts "${args[@]}"
-			    fi;;
-			 *) die_invalid_option "$1";;
-		esac
-		unset args
-	done
-
-	. /etc/init.d/functions.sh
-}
-##
-# Clean up temporary files and exit
-cleanup_and_die() {
-	rm -f "$@"
-	die 1 "  ...terminated. Removing incomplete $@."
-}
-##
-# Clean trap
-clean_trap() {
-	trap "cleanup_and_die $*" SIGHUP SIGINT SIGQUIT SIGABRT SIGTERM
-	rm -f "$@"
-}
-
-get_search_env() {
-	local new_env
-	WORKING_DIR="$(mktemp -d -t revdep-paxmark.XXXXXXXXXX)"
-	cd ${WORKING_DIR}
-
-	# From here on all work is done inside the temporary directory
-
-	rm -f "${FILES[@]}"
-
-	if [[ $SEARCH_BROKEN ]]; then
-		SONAME_SEARCH="$SONAME"
-		HEAD_TEXT="broken by a package update"
-		OK_TEXT="Dynamic linking on your system is consistent"
-		WORKING_TEXT="consistency"
-	else
-		# first case is needed to test against /path/to/foo.so
-		if [[ $SONAME = /* ]]; then
-			# Set to "<space>$SONAME<space>"
-			SONAME_SEARCH=" $SONAME "
-			# Escape the "/" characters
-			SONAME_SEARCH="${SONAME_SEARCH//\//\\/}"
-		else
-			# Set to "<tab>$SONAME<space>"
-			SONAME_SEARCH=$'\t'"$SONAME "
-		fi
-		HEAD_TEXT="using $SONAME"
-		OK_TEXT="There are no dynamic links to $SONAME"
-		unset WORKING_TEXT
-	fi
-
-	new_env=$(
-		cat <<- EOF
-			SEARCH_DIRS="$SEARCH_DIRS"
-			SEARCH_DIRS_MASK="$SEARCH_DIRS_MASK"
-			LD_LIBRARY_MASK="$LD_LIBRARY_MASK"
-			PORTAGE_ROOT="$PORTAGE_ROOT"
-			ORDER_PKGS="$ORDER_PKGS"
-			FULL_LD_PATH="$FULL_LD_PATH"
-		EOF
-	)
-
-
-	echo "$new_env" > "$ENV_FILE"
-
-	echo
-	einfo "Checking reverse dependencies"
-	einfo "Packages containing binaries and libraries $HEAD_TEXT"
-	einfo "will be emerged."
-}
-
-get_files() {
-	einfo "Collecting system binaries and libraries"
-
-	clean_trap "$FILES_FILE"
-
-	if [[ $SEARCH_DIRS_MASK ]]; then
-		findMask=($SEARCH_DIRS_MASK)
-		findMask="${findMask[@]/#/-o -path }"
-		findMask="( ${findMask#-o } ) -prune -o"
-	fi
-	# TODO: Check this -- afaict SEARCH_DIRS isn't an array, so this should just be $SEARCH_DIRS?
-	find ${SEARCH_DIRS[@]} $findMask -type f \( -perm -u+x -o -perm -g+x -o -perm -o+x -o \
-		-name '*.so' -o -name '*.so.*' -o -name '*.la' \) -print 2> /dev/null |
-		sort -u > "$FILES_FILE" ||
-		die $? "find failed to list binary files (This is a bug.)"
-	einfo "Generated new $FILES_FILE"
-}
-
-parse_ld_so_conf() {
-	# FIXME: not safe for paths with spaces
-	local include
-	for path in $(sed '/^#/d;s/#.*$//' < /etc/ld.so.conf); do
-		if [[ $include = true ]]; then
-			for include_path in $(sed '/^#/d;s/#.*$//' /etc/${path} 2>/dev/null); do
-				echo $include_path
-			done
-			include=""
-			continue
-		fi
-		if [[ $path != include ]]; then
-			echo $path
-		else
-			include="true"
-			continue
-		fi
-	done
-}
-
-get_ldpath() {
-	local COMPLETE_LD_LIBRARY_PATH
-	[[ $SEARCH_BROKEN && $FULL_LD_PATH ]] || return
-	einfo 'Collecting complete LD_LIBRARY_PATH'
-
-	clean_trap "$LDPATH_FILE"
-	# Ensure that the "trusted" lib directories are at the start of the path
-	COMPLETE_LD_LIBRARY_PATH=(
-		/lib*
-		/usr/lib*
-		$(parse_ld_so_conf)
-		$(sed 's:/[^/]*$::' < "$FILES_FILE" | sort -ru)
-	)
-	IFS=':'
-	COMPLETE_LD_LIBRARY_PATH="${COMPLETE_LD_LIBRARY_PATH[*]}"
-	IFS="$OIFS"
-	echo "$COMPLETE_LD_LIBRARY_PATH" > "$LDPATH_FILE"
-	einfo "Generated new $LDPATH_FILE"
-}
-
-main_checks() {
-	local target_file
-	local -a files
-	local i=0
-	local ldd_output
-	local ldd_status
-	local numFiles
-	local COMPLETE_LD_LIBRARY_PATH
-
-	if [[ $SEARCH_BROKEN && $FULL_LD_PATH ]]; then
-		[[ -r "$LDPATH_FILE" && -s "$LDPATH_FILE" ]] ||
-			die 1 "Unable to find $LDPATH_FILE"
-		COMPLETE_LD_LIBRARY_PATH=$(<"$LDPATH_FILE")
-	fi
-
-	einfo "Checking dynamic linking $WORKING_TEXT"
-
-	clean_trap "$BROKEN_FILE" "$ERRORS_FILE"
-	files=($(<"$FILES_FILE"))
-	numFiles="${#files[@]}"
-	for target_file in "${files[@]}"; do
-		if [[ $target_file != *.la ]]; then
-			# Note: double checking seems to be faster than single with complete path
-			# (special add ons are rare).
-			ldd_output=$(ldd "$target_file" 2>> "$ERRORS_FILE" | sort -u)
-			ldd_status=$? # TODO: Check this for problems with sort
-			# HACK: if LD_LIBRARY_MASK is null or undefined grep -vF doesn't work
-			if grep -vF "${LD_LIBRARY_MASK:=$'\a'}" <<< "$ldd_output" |
-				grep -q -E "$SONAME_SEARCH"; then
-				if [[ $SEARCH_BROKEN && $FULL_LD_PATH ]]; then
-					if LD_LIBRARY_PATH="$COMPLETE_LD_LIBRARY_PATH" ldd "$target_file" 2>/dev/null |
-						grep -vF "$LD_LIBRARY_MASK" | grep -q -E "$SONAME_SEARCH"; then
-						# FIXME: I hate duplicating code
-						# Only build missing direct dependencies
-						MISSING_LIBS=$(
-							expr='s/[[:space:]]*\([^[:space:]]*\) => not found/\1/p'
-							sed -n "$expr" <<< "$ldd_output"
-						)
-						REQUIRED_LIBS=$(
-							expr='s/^[[:space:]]*NEEDED[[:space:]]*\([^[:space:]]*\).*/\1/p';
-							objdump -x "$target_file" | grep NEEDED | sed "$expr" | sort -u
-						)
-						MISSING_LIBS=$(grep -F "$REQUIRED_LIBS" <<< "$MISSING_LIBS")
-						if [[ $MISSING_LIBS ]]; then
-							echo "obj $target_file" >> "$BROKEN_FILE"
-							echo_v "  broken $target_file (requires $MISSING_LIBS)"
-						fi
-					fi
-				else
-					# FIXME: I hate duplicating code
-					# Only rebuild for direct dependencies
-					MISSING_LIBS=$(
-						expr="s/^[[:space:]]*\([^[:space:]]*\).*$/\1/p"
-						sort -u <<< "$ldd_output" | grep -E "$SONAME" | sed -n "$expr"
-					)
-					REQUIRED_LIBS=$(
-						expr='s/^[[:space:]]*NEEDED[[:space:]]*\([^[:space:]]*\).*/\1/p';
-						objdump -x "$target_file" | grep NEEDED | sed "$expr" | sort -u
-					)
-					MISSING_LIBS=$(grep -F "$REQUIRED_LIBS" <<< "$MISSING_LIBS")
-					if [[ $MISSING_LIBS ]]; then
-						echo "obj $target_file" >> "$BROKEN_FILE"
-						if [[ $SEARCH_BROKEN ]]; then
-							echo_v "  broken $target_file (requires $MISSING_LIBS)"
-						else
-							echo_v "  found $target_file"
-						fi
-					fi
-				fi
-			fi
-		elif [[ $SEARCH_BROKEN ]]; then
-			# Look for broken .la files
-			la_SEARCH_DIRS="$SEARCH_DIRS"
-			la_search_dir=""
-			la_broken=""
-			la_lib=""
-			for depend in $(
-				gawk -F"[=']" '/^dependency_libs/{
-					print $3
-				}' "$target_file"
-			); do
-				if [[ $depend = /* && ! -e $depend ]]; then
-					echo "obj $target_file" >> "$BROKEN_FILE"
-					echo_v "  broken $target_file (requires $depend)"
-				elif [[ $depend = -[LR]/* ]]; then
-					if ! [[ $'\n'${la_SEARCH_DIRS}$'\n' == *$'\n'${depend#-?}$'\n'* ]]; then
-						la_SEARCH_DIRS+=$'\n'"${depend#-?}"
-					fi
-				elif [[ $depend = "-l"* ]]; then
-					la_lib="lib${depend#-l}"
-					la_broken="yes"
-					IFS=$'\n'
-					for la_search_dir in $la_SEARCH_DIRS; do
-						if [[ -e ${la_search_dir}/${la_lib}.so || -e ${la_search_dir}/${la_lib}.a ]]; then
-							la_broken="no"
-						fi
-					done
-					IFS="$OIFS"
-					if [[ $la_broken = yes ]]; then
-						echo "obj $target_file" >> "$BROKEN_FILE"
-						echo_v "  broken $target_file (requires $depend)"
-					fi
-				fi
-			done
-			unset la_SEARCH_DIRS la_search_dir la_broken la_lib
-		fi
-		progress $((++i)) $numFiles
-	done
-
-	if [[ $SEARCH_BROKEN && -f $ERRORS_FILE ]]; then
-		# Look for missing version
-		while read target_file; do
-			echo "obj $target_file" >> "$BROKEN_FILE"
-			echo_v "  broken $target_file (no version information available)"
-		done < <(
-			# Regexify LD_LIBRARY_MASK. Exclude it from the search.
-			LD_LIBRARY_MASK="${LD_LIBRARY_MASK//$'\n'/|}"
-			gawk -v ldmask="(${LD_LIBRARY_MASK//./\\\.})" '
-				/no version information available/ && $0 !~ ldmask {
-					gsub(/[()]/, "", $NF)
-					if (seen[$NF]++)  next
-					print $NF
-				}' "$ERRORS_FILE"
-		)
-	fi
-
-	[[ -r "$BROKEN_FILE" && -s "$BROKEN_FILE" ]] || clean_exit
-	sort -u "$BROKEN_FILE" -o "$BROKEN_FILE"
-
-	einfo "Generated new $BROKEN_FILE"
-}
-
-
-# Get multiple portage variables at once to speedup revdep-rebuild.
-portage_settings() {
-	local ORIG_SEARCH_DIRS="$SEARCH_DIRS"
-	local ORIG_SEARCH_DIRS_MASK="$SEARCH_DIRS_MASK"
-	local ORIG_LD_LIBRARY_MASK="$LD_LIBRARY_MASK"
-	unset SEARCH_DIRS
-	unset SEARCH_DIRS_MASK
-	unset LD_LIBRARY_MASK
-
-	eval $(portageq envvar -v PORTAGE_ROOT PORTAGE_NICENESS EMERGE_DEFAULT_OPTS SEARCH_DIRS SEARCH_DIRS_MASK LD_LIBRARY_MASK)
-
-	SEARCH_DIRS="$ORIG_SEARCH_DIRS $SEARCH_DIRS"
-	SEARCH_DIRS_MASK="$ORIG_SEARCH_DIRS_MASK $SEARCH_DIRS_MASK"
-	LD_LIBRARY_MASK="$ORIG_LD_LIBRARY_MASK $LD_LIBRARY_MASK"
-}
-
-##
-# Setup the paths to search (and filter the ones to avoid)
-setup_search_paths_and_masks() {
-	local configfile sdir mdir skip_me filter_SEARCH_DIRS
-
-	einfo "Configuring search environment for $APP_NAME"
-
-	# Update the incremental variables using /etc/profile.env, /etc/ld.so.conf,
-	# portage, and the environment
-
-	# Read the incremental variables from environment and portage
-	# Until such time as portage supports these variables as incrementals
-	# The value will be what is in /etc/make.conf
-#	SEARCH_DIRS+=" "$(unset SEARCH_DIRS; portageq envvar SEARCH_DIRS)
-#	SEARCH_DIRS_MASK+=" "$(unset SEARCH_DIRS_MASK; portageq envvar SEARCH_DIRS_MASK)
-#	LD_LIBRARY_MASK+=" "$(unset LD_LIBRARY_MASK; portageq envvar LD_LIBRARY_MASK)
-
-	# Add the defaults
-	if [[ -d /etc/revdep-rebuild ]]; then
-		for configfile in /etc/revdep-rebuild/*; do
-			SEARCH_DIRS+=" "$(. $configfile; echo $SEARCH_DIRS)
-			SEARCH_DIRS_MASK+=" "$(. $configfile; echo $SEARCH_DIRS_MASK)
-			LD_LIBRARY_MASK+=" "$(. $configfile; echo $LD_LIBRARY_MASK)
-		done
-	else
-		SEARCH_DIRS+=" /bin /sbin /usr/bin /usr/sbin /lib* /usr/lib*"
-		SEARCH_DIRS_MASK+=" /opt/OpenOffice /usr/lib/openoffice"
-		LD_LIBRARY_MASK+=" libodbcinst.so libodbc.so libjava.so libjvm.so"
-	fi
-
-	# Get the ROOTPATH and PATH from /etc/profile.env
-	if [[ -r "/etc/profile.env" && -s "/etc/profile.env" ]]; then
-		SEARCH_DIRS+=" "$(. /etc/profile.env; /usr/bin/tr ':' ' ' <<< "$ROOTPATH $PATH")
-	fi
-
-	# Get the directories from /etc/ld.so.conf
-	if [[ -r /etc/ld.so.conf && -s /etc/ld.so.conf ]]; then
-		SEARCH_DIRS+=" "$(parse_ld_so_conf)
-	fi
-
-	# Set the final variables
-	SEARCH_DIRS=$(clean_var <<< "$SEARCH_DIRS")
-	SEARCH_DIRS_MASK=$(clean_var <<< "$SEARCH_DIRS_MASK")
-	LD_LIBRARY_MASK=$(clean_var <<< "$LD_LIBRARY_MASK")
-	# Filter masked paths from SEARCH_DIRS
-	for sdir in ${SEARCH_DIRS} ; do
-		skip_me=
-		for mdir in ${SEARCH_DIRS_MASK}; do
-			[[ ${sdir} == ${mdir}/* ]] && skip_me=1 && break
-		done
-		[[ -n ${skip_me} ]] || filter_SEARCH_DIRS+=" ${sdir}"
-	done
-	SEARCH_DIRS=$(clean_var <<< "${filter_SEARCH_DIRS}")
-	[[ $SEARCH_DIRS ]] || die 1 "No search defined -- this is a bug."
-}
-##
-# Finish up
-cleanup() {
-		trap_cmd() {
-			eerror "terminated. Please remove the temporary files manually:"
-			eerror "rm ${WORKING_DIR}/*.rr"
-			exit 1
-		}
-		trap trap_cmd SIGHUP SIGINT SIGQUIT SIGABRT SIGTERM
-}
-
-main "$@"



^ permalink raw reply related	[flat|nested] 89+ messages in thread
* [gentoo-commits] proj/elfix:master commit in: scripts/
@ 2011-10-06  3:13 Anthony G. Basile
  0 siblings, 0 replies; 89+ messages in thread
From: Anthony G. Basile @ 2011-10-06  3:13 UTC (permalink / raw
  To: gentoo-commits

commit:     905e67170b9dda4b3770270843c6ca182c195d25
Author:     Anthony G. Basile <blueness <AT> gentoo <DOT> org>
AuthorDate: Thu Oct  6 03:13:28 2011 +0000
Commit:     Anthony G. Basile <blueness <AT> gentoo <DOT> org>
CommitDate: Thu Oct  6 03:13:28 2011 +0000
URL:        http://git.overlays.gentoo.org/gitweb/?p=proj/elfix.git;a=commit;h=905e6717

scripts/paxmodule.c: stub python binding for paxctl

---
 scripts/paxmodule.c |   47 +++++++++++++++++++++++++++++++++++++++++++++++
 scripts/revdep-pax  |    3 +++
 scripts/setup.py    |   19 +++++++++++++++++++
 3 files changed, 69 insertions(+), 0 deletions(-)

diff --git a/scripts/paxmodule.c b/scripts/paxmodule.c
new file mode 100644
index 0000000..03ba794
--- /dev/null
+++ b/scripts/paxmodule.c
@@ -0,0 +1,47 @@
+#include <Python.h>
+
+static PyObject * pax_getflags(PyObject *, PyObject *);
+
+static PyMethodDef PaxMethods[] = {
+	{"getflags",  pax_getflags, METH_VARARGS, "Get the pax flags."},
+	{NULL, NULL, 0, NULL}
+};
+
+static PyObject *PaxError;
+
+PyMODINIT_FUNC
+initpax(void)
+{
+	PyObject *m;
+
+	m = Py_InitModule("pax", PaxMethods);
+	if (m == NULL)
+		return;
+
+	PaxError = PyErr_NewException("pax.error", NULL, NULL);
+	Py_INCREF(PaxError);
+	PyModule_AddObject(m, "error", PaxError);
+}
+
+
+static PyObject *
+pax_getflags(PyObject *self, PyObject *args)
+{
+	const char *value;
+	int sts;
+
+	if (!PyArg_ParseTuple(args, "s", &value))
+		return NULL;
+
+	printf("%s\n", value);
+
+	sts = 1;
+
+	if (sts < 0)
+	{
+		PyErr_SetString(PaxError, "pax_getflags failed");
+		return NULL;
+	}
+
+	return Py_BuildValue("i", sts);
+}

diff --git a/scripts/revdep-pax b/scripts/revdep-pax
index 75e833a..ac21bae 100755
--- a/scripts/revdep-pax
+++ b/scripts/revdep-pax
@@ -4,6 +4,8 @@ from os import listdir
 #from os import path
 import re
 
+import pax
+
 var_db_pkg = '/var/db/pkg'
 
 binaries = {}
@@ -21,6 +23,7 @@ for cat in listdir(var_db_pkg):
 				binary = linking[0]
 				print binary
 				library_list = re.split(',', linking[1])
+				print "\t%s" % library_list
 				binaries[binary] = library_list
 		except:
 			break

diff --git a/scripts/setup.py b/scripts/setup.py
new file mode 100755
index 0000000..317efbd
--- /dev/null
+++ b/scripts/setup.py
@@ -0,0 +1,19 @@
+#!/usr/bin/env python
+
+from distutils.core import setup, Extension
+
+module1 = Extension(
+	name='pax',
+	sources = ['paxmodule.c']
+)
+
+setup(
+	name = 'PaxPython',
+	version = '1.0',
+	author = 'Anthony G. Basile',
+	author_email = 'blueness@gentoo.org',
+	url = 'http://dev.gentoo.org/~blueness/elfix',
+	description = 'This is bindings between paxctl and python',
+	license = 'GPL-2',
+	ext_modules = [module1]
+)



^ permalink raw reply related	[flat|nested] 89+ messages in thread
* [gentoo-commits] proj/elfix:master commit in: scripts/
@ 2011-10-06  2:20 Anthony G. Basile
  0 siblings, 0 replies; 89+ messages in thread
From: Anthony G. Basile @ 2011-10-06  2:20 UTC (permalink / raw
  To: gentoo-commits

commit:     320f445deb14ed5c7596d33eae43a03dff988e3a
Author:     Anthony G. Basile <blueness <AT> gentoo <DOT> org>
AuthorDate: Thu Oct  6 02:20:09 2011 +0000
Commit:     Anthony G. Basile <blueness <AT> gentoo <DOT> org>
CommitDate: Thu Oct  6 02:20:09 2011 +0000
URL:        http://git.overlays.gentoo.org/gitweb/?p=proj/elfix.git;a=commit;h=320f445d

scripts/revdep-pax: python rewrite of revdep-paxmark

---
 scripts/revdep-pax |   53 ++++++++++++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 53 insertions(+), 0 deletions(-)

diff --git a/scripts/revdep-pax b/scripts/revdep-pax
new file mode 100755
index 0000000..75e833a
--- /dev/null
+++ b/scripts/revdep-pax
@@ -0,0 +1,53 @@
+#!/usr/bin/env python
+
+from os import listdir
+#from os import path
+import re
+
+var_db_pkg = '/var/db/pkg'
+
+binaries = {}
+for cat in listdir(var_db_pkg):
+	catdir = '%s/%s' % (var_db_pkg, cat)
+	for pkg in listdir(catdir):
+		pkgdir = '%s/%s' % (catdir, pkg)
+		need = '%s/%s' % (pkgdir, 'NEEDED')
+		try:
+			g = open(need, 'r')
+			needs = g.readlines()
+			for line in needs:
+				line = line.strip()
+				linking = re.split('\s', line)
+				binary = linking[0]
+				print binary
+				library_list = re.split(',', linking[1])
+				binaries[binary] = library_list
+		except:
+			break
+
+""" Print out mapping: binary -> library, library, library ...
+for binary in binaries:
+	print binary
+	for library in binaries[binary]:
+		print "\t", library
+"""
+
+libraries = {}
+for binary in binaries:
+	for library in binaries[binary]:
+		libraries[library] = []
+
+for binary in binaries:
+	for library in binaries[binary]:
+		libraries[library].append(binary)
+
+""" Print out mapping: library -> binary, binary, binary ...
+for library in libraries:
+	print library
+	for binary in libraries[library]:
+		print "\t", binary
+		#if not path.exists(binary):
+		#	print "%s doesn't exist!" % binary
+"""
+
+



^ permalink raw reply related	[flat|nested] 89+ messages in thread
* [gentoo-commits] proj/elfix:master commit in: scripts/
@ 2011-09-08 23:50 Anthony G. Basile
  0 siblings, 0 replies; 89+ messages in thread
From: Anthony G. Basile @ 2011-09-08 23:50 UTC (permalink / raw
  To: gentoo-commits

commit:     04b4f8c968b65194ef68856fa5fba1777d22c539
Author:     Anthony G. Basile <blueness <AT> gentoo <DOT> org>
AuthorDate: Thu Sep  8 23:47:10 2011 +0000
Commit:     Anthony G. Basile <blueness <AT> gentoo <DOT> org>
CommitDate: Thu Sep  8 23:47:10 2011 +0000
URL:        http://git.overlays.gentoo.org/gitweb/?p=proj/elfix.git;a=commit;h=04b4f8c9

scripts/revdep-paxmark: tool to find mismatched pax markings

This tool will search for binaries which have different pax
markings than the libraries they link against.  Since running
processes run with the pax enforcings of the binary, not the
libraries they link against, this utility can be used to locate
such binaries and mark them with the same flags as their libraries.

This code is derived from revdep-rebuild.

---
 scripts/revdep-paxmark |  639 ++++++++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 639 insertions(+), 0 deletions(-)

diff --git a/scripts/revdep-paxmark b/scripts/revdep-paxmark
new file mode 100755
index 0000000..fd07c3c
--- /dev/null
+++ b/scripts/revdep-paxmark
@@ -0,0 +1,639 @@
+#!/bin/bash
+# Copyright 1999-2011 Gentoo Foundation
+
+#
+# This utility will look for any binaries which do not have
+# the same pax markings as the corresponding libraries which
+# they link against.
+#
+# This code is mostly derived from revdep-rebuild.
+#
+
+# Readonly variables:
+declare -r APP_NAME="${0##*/}" # The name of this application
+declare -r VERSION="0.1.0.0"
+declare -r OIFS="$IFS"         # Save the IFS
+declare -r     ENV_FILE=0_env.rr     # Contains environment variables
+declare -r   FILES_FILE=1_files.rr   # Contains a list of files to search
+declare -r  LDPATH_FILE=2_ldpath.rr  # Contains the LDPATH
+declare -r  BROKEN_FILE=3_broken.rr  # Contains the list of broken files
+declare -r  ERRORS_FILE=3_errors.rr  # Contains the ldd error output
+declare -ra FILES=(
+	"$ENV_FILE"
+	"$FILES_FILE"
+	"$LDPATH_FILE"
+	"$BROKEN_FILE"
+	"$ERRORS_FILE"
+)
+
+# "Boolean" variables: Considered "true" if it has any value at all
+# "True" indicates we should...
+declare FULL_LD_PATH           # ...search across the COMPLETE_LD_LIBRARY_PATH
+declare ORDER_PKGS             # ...sort the atoms in deep dependency order
+declare RM_OLD_TEMPFILES       # ...remove tempfiles from prior runs
+declare SEARCH_BROKEN          # ...search for broken libraries and binaries
+
+# Globals that impact portage directly:
+declare EMERGE_DEFAULT_OPTS    # String of options portage assumes to be set
+declare PORTAGE_NICENESS       # Renice to this value
+declare PORTAGE_ROOT           # The root path for portage
+
+# Customizable incremental variables:
+# These variables can be prepended to either by setting the variable in
+# your environment prior to execution, or by placing an entry in
+# /etc/make.conf.
+#
+# An entry of "-*" means to clear the variable from that point forward.
+# Example: env SEARCH_DIRS="/usr/bin -*" revdep-rebuild will set SEARCH_DIRS
+# to contain only /usr/bin
+declare LD_LIBRARY_MASK  # Mask of specially evaluated libraries
+declare SEARCH_DIRS      # List of dirs to search for executables and libraries
+declare SEARCH_DIRS_MASK # List of dirs not to search
+
+# Other globals:
+declare OLDPROG                # Previous pass through the progress meter
+declare EXACT_PKG              # Versionated atom to emerge
+declare HEAD_TEXT              # Feedback string about the search
+declare OK_TEXT                # Feedback about a search which found no errors
+declare REBUILD_LIST           # Array of atoms to emerge
+declare SONAME                 # Soname/soname path pattern given on commandline
+declare SONAME_SEARCH          # Value of SONAME modified to match ldd's output
+declare WORKING_TEXT           # Feedback about the search
+declare WORKING_DIR            # Working directory where cache files are kept
+
+main() {
+	portage_settings
+	get_opts "$@"
+	setup_search_paths_and_masks
+	get_search_env
+	get_files
+	get_ldpath
+	main_checks
+	cleanup
+}
+##
+# GNU find has -executable, but if our users' finds do not have that flag
+# we emulate it with this function. Also emulates -writable and -readable.
+# Usage: find PATH ARGS -- use find like normal, except use -executable instead
+# of various versions of -perm /+ blah blah and hacks
+find() {
+	hash find || { die 1 'find not found!'; }
+	# We can be pretty sure find itself should be executable.
+	local testsubject="$(type -P find)"
+	if [[ $(command find "$testsubject" -executable 2> /dev/null) ]]; then
+		unset -f find # We can just use the command find
+	elif [[ $(command find "$testsubject" -perm /u+x 2> /dev/null) ]]; then
+		find() {
+			a=(${@//-executable/-perm \/u+x})
+			a=(${a[@]//-writable/-perm \/u+w})
+			a=(${a[@]//-readable/-perm \/r+w})
+			command find "${a[@]}"
+		}
+	elif [[ $(command find "$testsubject" -perm +u+x 2> /dev/null) ]]; then
+		find() {
+			a=(${@//-executable/-perm +u+x})
+			a=(${a[@]//-writable/-perm +u+w})
+			a=(${a[@]//-readable/-perm +r+w})
+			command find "${a[@]}"
+		}
+	else # Last resort
+		find() {
+			a=(${@//-executable/-exec test -x '{}' \; -print})
+			a=(${a[@]//-writable/-exec test -w '{}' \; -print})
+			a=(${a[@]//-readable/-exec test -r '{}' \; -print})
+			command find "${a[@]}"
+		}
+	fi
+	find "$@"
+}
+
+print_usage() {
+cat << EOF
+${APP_NAME}: (${VERSION})
+
+Copyright (C) 2003-2010 Gentoo Foundation, Inc.
+This is free software; see the source for copying conditions.
+
+Usage: $APP_NAME [OPTIONS] [--]
+
+Broken reverse dependency rebuilder.
+
+  -C, --nocolor        Turn off colored output
+  -d, --debug          Print way too much information (uses bash's set -xv)
+  -h, --help           Print this usage
+  -i, --ignore         Ignore temporary files from previous runs
+  -k, --keep-temp      Do not delete temporary files on exit
+  -L, --library NAME   Emerge existing packages that use the library with NAME
+      --library=NAME   NAME can be a full path to the library or a basic
+                       regular expression (man grep)
+  -l, --no-ld-path     Do not set LD_LIBRARY_PATH
+  -P, --no-progress    Turn off the progress meter
+  -q, --quiet          Be less verbose (also passed to emerge command)
+  -v, --verbose        Be more verbose (also passed to emerge command)
+
+Calls emerge, options after -- are ignored by $APP_NAME
+and passed directly to emerge.
+
+Report bugs to <http://bugs.gentoo.org>
+
+EOF
+}
+##
+# Usage: progress i n
+#        i: current item
+#        n: total number of items to process
+progress() {
+	if [[ -t 1 ]]; then
+		progress() {
+			local curProg=$(( $1 * 100 / $2 ))
+			(( curProg == OLDPROG )) && return # no change, output nothing
+			OLDPROG="$curProg" # must be a global variable
+			(( $1 == $2 )) && local lb=$'\n'
+			echo -ne '\r                         \r'"[ $curProg% ] $lb"
+		}
+		progress $@
+	else # STDOUT is not a tty. Disable progress meter.
+		progress() { :; }
+	fi
+}
+##
+# Replace whitespace with linebreaks, normalize repeated '/' chars, and sort -u
+# (If any libs have whitespace in their filenames, someone needs punishment.)
+clean_var() {
+	gawk 'BEGIN         {RS="[[:space:]]"}
+	     /-\*/         {exit}
+	     /[^[:space:]]/ {gsub(/\/\/+/, "/"); print}' | sort -u
+}
+##
+# Exit and optionally output to sterr
+die() {
+	local status=$1
+	shift
+
+	type eerror &> /dev/null
+
+	if [[ $? -eq 0 ]];
+	then
+		eerror "$@"
+	else
+		echo " * ${@}" >> /dev/stderr
+	fi
+	exit $status
+}
+##
+# What to do when dynamic linking is consistent
+clean_exit() {
+	echo
+	einfo "$OK_TEXT... All done. "
+	exit 0
+}
+##
+# Get the name of the package that owns a file or list of files given as args.
+# NOTE: depends on app-misc/realpath!
+get_file_owner() {
+	local IFS=$'\n'
+
+	rpath=$(realpath "${*}" 2>/dev/null)
+	# To ensure we always have something in rpath...
+	[[ -z $rpath ]] && rpath=${*}
+
+	# Workaround for bug 280341
+	mlib=$(echo ${*}|sed 's:/lib/:/lib64/:')
+	[[ "${*}" == "${mlib}" ]] && mlib=$(echo ${*}|sed 's:/lib64/:/lib/:')
+
+	# Add a space to the end of each object name to prevent false
+	# matches, for example /usr/bin/dia matching /usr/bin/dialog (bug #196460).
+	# The same for "${rpath} ".
+	# Don't match an entry with a '-' at the start of the package name. This
+	# prevents us from matching invalid -MERGING entries. (bug #338031)
+	find -L /var/db/pkg -type f -name CONTENTS -print0 |
+		xargs -0 grep -m 1 -Fl -e "${*} " -e "${rpath} " -e "${mlib} " |
+		sed 's:/var/db/pkg/\(.*\)/\([^-].*\)/CONTENTS:\1/\2:'
+}
+##
+# Die if an argument is missing.
+die_if_missing_arg() {
+	[[ ! $2 || $2 = -* ]] && die 1 "Missing expected argument to $1"
+}
+##
+# Die because an option is not recognized.
+die_invalid_option() {
+	# Can't use eerror and einfo because this gets called before function.sh
+	# is sourced
+	echo
+	echo  "Encountered unrecognized option $1." >&2
+	echo
+	echo  "$APP_NAME no longer automatically passes unrecognized options to portage."
+	echo  "Separate emerge-only options from revdep-rebuild options with the -- flag."
+	echo
+	echo  "For example, $APP_NAME -v -- --ask"
+	echo
+	echo  "See the man page or $APP_NAME -h for more detail."
+	echo
+	exit 1
+}
+##
+# Get whole-word commandline options preceded by two dashes.
+get_longopts() {
+	case $1 in
+		                                 --debug) set -xv;;
+		                                  --help) print_usage
+		                                          exit 0;;
+		                                --ignore) RM_OLD_TEMPFILES=1;;
+		                             --library=*) SONAME="${1#*=}"
+		                                          unset SEARCH_BROKEN;;
+		                               --library) die_if_missing_arg $1 $2
+		                                          shift
+		                                          SONAME="$1"
+		                                          unset SEARCH_BROKEN;;
+		                            --no-ld-path) unset FULL_LD_PATH;;
+		                           --no-progress) progress() { :; };;
+		                                       *) die_invalid_option $1;;
+	esac
+}
+
+##
+# Get single-letter commandline options preceded by a single dash.
+get_shortopts() {
+	local OPT OPTSTRING OPTARG OPTIND
+	while getopts ":CdehikL:loPpqu:vX" OPT; do
+		case "$OPT" in
+			d) set -xv;;
+			h) print_usage
+			   exit 0;;
+			i) RM_OLD_TEMPFILES=1;;
+			L) SONAME="${OPTARG#*=}"
+			   unset SEARCH_BROKEN;;
+			l) unset FULL_LD_PATH;;
+			P) progress() { :; };;
+			*) die_invalid_option "-$OPTARG";;
+		esac
+	done
+}
+##
+# Get command-line options.
+get_opts() {
+	local avoid_utils
+	local -a args
+	echo_v() { ewarn "$@"; }
+	unset RM_OLD_TEMPFILES
+	ORDER_PKGS=1
+	SONAME="not found"
+	SEARCH_BROKEN=1
+	FULL_LD_PATH=1
+	while [[ $1 ]]; do
+		case $1 in
+			-*) while true; do
+			      args+=("$1")
+			      shift
+			      [[ ${1:--} = -* ]] && break
+			    done
+			    if [[ ${args[0]} = --* ]]; then
+			      get_longopts  "${args[@]}"
+			    else
+			      get_shortopts "${args[@]}"
+			    fi;;
+			 *) die_invalid_option "$1";;
+		esac
+		unset args
+	done
+
+	. /etc/init.d/functions.sh
+}
+##
+# Clean up temporary files and exit
+cleanup_and_die() {
+	rm -f "$@"
+	die 1 "  ...terminated. Removing incomplete $@."
+}
+##
+# Clean trap
+clean_trap() {
+	trap "cleanup_and_die $*" SIGHUP SIGINT SIGQUIT SIGABRT SIGTERM
+	rm -f "$@"
+}
+
+get_search_env() {
+	local new_env
+	WORKING_DIR="$(mktemp -d -t revdep-paxmark.XXXXXXXXXX)"
+	cd ${WORKING_DIR}
+
+	# From here on all work is done inside the temporary directory
+
+	rm -f "${FILES[@]}"
+
+	if [[ $SEARCH_BROKEN ]]; then
+		SONAME_SEARCH="$SONAME"
+		HEAD_TEXT="broken by a package update"
+		OK_TEXT="Dynamic linking on your system is consistent"
+		WORKING_TEXT="consistency"
+	else
+		# first case is needed to test against /path/to/foo.so
+		if [[ $SONAME = /* ]]; then
+			# Set to "<space>$SONAME<space>"
+			SONAME_SEARCH=" $SONAME "
+			# Escape the "/" characters
+			SONAME_SEARCH="${SONAME_SEARCH//\//\\/}"
+		else
+			# Set to "<tab>$SONAME<space>"
+			SONAME_SEARCH=$'\t'"$SONAME "
+		fi
+		HEAD_TEXT="using $SONAME"
+		OK_TEXT="There are no dynamic links to $SONAME"
+		unset WORKING_TEXT
+	fi
+
+	new_env=$(
+		cat <<- EOF
+			SEARCH_DIRS="$SEARCH_DIRS"
+			SEARCH_DIRS_MASK="$SEARCH_DIRS_MASK"
+			LD_LIBRARY_MASK="$LD_LIBRARY_MASK"
+			PORTAGE_ROOT="$PORTAGE_ROOT"
+			ORDER_PKGS="$ORDER_PKGS"
+			FULL_LD_PATH="$FULL_LD_PATH"
+		EOF
+	)
+
+
+	echo "$new_env" > "$ENV_FILE"
+
+	echo
+	einfo "Checking reverse dependencies"
+	einfo "Packages containing binaries and libraries $HEAD_TEXT"
+	einfo "will be emerged."
+}
+
+get_files() {
+	einfo "Collecting system binaries and libraries"
+
+	clean_trap "$FILES_FILE"
+
+	if [[ $SEARCH_DIRS_MASK ]]; then
+		findMask=($SEARCH_DIRS_MASK)
+		findMask="${findMask[@]/#/-o -path }"
+		findMask="( ${findMask#-o } ) -prune -o"
+	fi
+	# TODO: Check this -- afaict SEARCH_DIRS isn't an array, so this should just be $SEARCH_DIRS?
+	find ${SEARCH_DIRS[@]} $findMask -type f \( -perm -u+x -o -perm -g+x -o -perm -o+x -o \
+		-name '*.so' -o -name '*.so.*' -o -name '*.la' \) -print 2> /dev/null |
+		sort -u > "$FILES_FILE" ||
+		die $? "find failed to list binary files (This is a bug.)"
+	einfo "Generated new $FILES_FILE"
+}
+
+parse_ld_so_conf() {
+	# FIXME: not safe for paths with spaces
+	local include
+	for path in $(sed '/^#/d;s/#.*$//' < /etc/ld.so.conf); do
+		if [[ $include = true ]]; then
+			for include_path in $(sed '/^#/d;s/#.*$//' /etc/${path} 2>/dev/null); do
+				echo $include_path
+			done
+			include=""
+			continue
+		fi
+		if [[ $path != include ]]; then
+			echo $path
+		else
+			include="true"
+			continue
+		fi
+	done
+}
+
+get_ldpath() {
+	local COMPLETE_LD_LIBRARY_PATH
+	[[ $SEARCH_BROKEN && $FULL_LD_PATH ]] || return
+	einfo 'Collecting complete LD_LIBRARY_PATH'
+
+	clean_trap "$LDPATH_FILE"
+	# Ensure that the "trusted" lib directories are at the start of the path
+	COMPLETE_LD_LIBRARY_PATH=(
+		/lib*
+		/usr/lib*
+		$(parse_ld_so_conf)
+		$(sed 's:/[^/]*$::' < "$FILES_FILE" | sort -ru)
+	)
+	IFS=':'
+	COMPLETE_LD_LIBRARY_PATH="${COMPLETE_LD_LIBRARY_PATH[*]}"
+	IFS="$OIFS"
+	echo "$COMPLETE_LD_LIBRARY_PATH" > "$LDPATH_FILE"
+	einfo "Generated new $LDPATH_FILE"
+}
+
+main_checks() {
+	local target_file
+	local -a files
+	local i=0
+	local ldd_output
+	local ldd_status
+	local numFiles
+	local COMPLETE_LD_LIBRARY_PATH
+
+	if [[ $SEARCH_BROKEN && $FULL_LD_PATH ]]; then
+		[[ -r "$LDPATH_FILE" && -s "$LDPATH_FILE" ]] ||
+			die 1 "Unable to find $LDPATH_FILE"
+		COMPLETE_LD_LIBRARY_PATH=$(<"$LDPATH_FILE")
+	fi
+
+	einfo "Checking dynamic linking $WORKING_TEXT"
+
+	clean_trap "$BROKEN_FILE" "$ERRORS_FILE"
+	files=($(<"$FILES_FILE"))
+	numFiles="${#files[@]}"
+	for target_file in "${files[@]}"; do
+		if [[ $target_file != *.la ]]; then
+			# Note: double checking seems to be faster than single with complete path
+			# (special add ons are rare).
+			ldd_output=$(ldd "$target_file" 2>> "$ERRORS_FILE" | sort -u)
+			ldd_status=$? # TODO: Check this for problems with sort
+			# HACK: if LD_LIBRARY_MASK is null or undefined grep -vF doesn't work
+			if grep -vF "${LD_LIBRARY_MASK:=$'\a'}" <<< "$ldd_output" |
+				grep -q -E "$SONAME_SEARCH"; then
+				if [[ $SEARCH_BROKEN && $FULL_LD_PATH ]]; then
+					if LD_LIBRARY_PATH="$COMPLETE_LD_LIBRARY_PATH" ldd "$target_file" 2>/dev/null |
+						grep -vF "$LD_LIBRARY_MASK" | grep -q -E "$SONAME_SEARCH"; then
+						# FIXME: I hate duplicating code
+						# Only build missing direct dependencies
+						MISSING_LIBS=$(
+							expr='s/[[:space:]]*\([^[:space:]]*\) => not found/\1/p'
+							sed -n "$expr" <<< "$ldd_output"
+						)
+						REQUIRED_LIBS=$(
+							expr='s/^[[:space:]]*NEEDED[[:space:]]*\([^[:space:]]*\).*/\1/p';
+							objdump -x "$target_file" | grep NEEDED | sed "$expr" | sort -u
+						)
+						MISSING_LIBS=$(grep -F "$REQUIRED_LIBS" <<< "$MISSING_LIBS")
+						if [[ $MISSING_LIBS ]]; then
+							echo "obj $target_file" >> "$BROKEN_FILE"
+							echo_v "  broken $target_file (requires $MISSING_LIBS)"
+						fi
+					fi
+				else
+					# FIXME: I hate duplicating code
+					# Only rebuild for direct dependencies
+					MISSING_LIBS=$(
+						expr="s/^[[:space:]]*\([^[:space:]]*\).*$/\1/p"
+						sort -u <<< "$ldd_output" | grep -E "$SONAME" | sed -n "$expr"
+					)
+					REQUIRED_LIBS=$(
+						expr='s/^[[:space:]]*NEEDED[[:space:]]*\([^[:space:]]*\).*/\1/p';
+						objdump -x "$target_file" | grep NEEDED | sed "$expr" | sort -u
+					)
+					MISSING_LIBS=$(grep -F "$REQUIRED_LIBS" <<< "$MISSING_LIBS")
+					if [[ $MISSING_LIBS ]]; then
+						echo "obj $target_file" >> "$BROKEN_FILE"
+						if [[ $SEARCH_BROKEN ]]; then
+							echo_v "  broken $target_file (requires $MISSING_LIBS)"
+						else
+							echo_v "  found $target_file"
+						fi
+					fi
+				fi
+			fi
+		elif [[ $SEARCH_BROKEN ]]; then
+			# Look for broken .la files
+			la_SEARCH_DIRS="$SEARCH_DIRS"
+			la_search_dir=""
+			la_broken=""
+			la_lib=""
+			for depend in $(
+				gawk -F"[=']" '/^dependency_libs/{
+					print $3
+				}' "$target_file"
+			); do
+				if [[ $depend = /* && ! -e $depend ]]; then
+					echo "obj $target_file" >> "$BROKEN_FILE"
+					echo_v "  broken $target_file (requires $depend)"
+				elif [[ $depend = -[LR]/* ]]; then
+					if ! [[ $'\n'${la_SEARCH_DIRS}$'\n' == *$'\n'${depend#-?}$'\n'* ]]; then
+						la_SEARCH_DIRS+=$'\n'"${depend#-?}"
+					fi
+				elif [[ $depend = "-l"* ]]; then
+					la_lib="lib${depend#-l}"
+					la_broken="yes"
+					IFS=$'\n'
+					for la_search_dir in $la_SEARCH_DIRS; do
+						if [[ -e ${la_search_dir}/${la_lib}.so || -e ${la_search_dir}/${la_lib}.a ]]; then
+							la_broken="no"
+						fi
+					done
+					IFS="$OIFS"
+					if [[ $la_broken = yes ]]; then
+						echo "obj $target_file" >> "$BROKEN_FILE"
+						echo_v "  broken $target_file (requires $depend)"
+					fi
+				fi
+			done
+			unset la_SEARCH_DIRS la_search_dir la_broken la_lib
+		fi
+		progress $((++i)) $numFiles
+	done
+
+	if [[ $SEARCH_BROKEN && -f $ERRORS_FILE ]]; then
+		# Look for missing version
+		while read target_file; do
+			echo "obj $target_file" >> "$BROKEN_FILE"
+			echo_v "  broken $target_file (no version information available)"
+		done < <(
+			# Regexify LD_LIBRARY_MASK. Exclude it from the search.
+			LD_LIBRARY_MASK="${LD_LIBRARY_MASK//$'\n'/|}"
+			gawk -v ldmask="(${LD_LIBRARY_MASK//./\\\.})" '
+				/no version information available/ && $0 !~ ldmask {
+					gsub(/[()]/, "", $NF)
+					if (seen[$NF]++)  next
+					print $NF
+				}' "$ERRORS_FILE"
+		)
+	fi
+
+	[[ -r "$BROKEN_FILE" && -s "$BROKEN_FILE" ]] || clean_exit
+	sort -u "$BROKEN_FILE" -o "$BROKEN_FILE"
+
+	einfo "Generated new $BROKEN_FILE"
+}
+
+
+# Get multiple portage variables at once to speedup revdep-rebuild.
+portage_settings() {
+	local ORIG_SEARCH_DIRS="$SEARCH_DIRS"
+	local ORIG_SEARCH_DIRS_MASK="$SEARCH_DIRS_MASK"
+	local ORIG_LD_LIBRARY_MASK="$LD_LIBRARY_MASK"
+	unset SEARCH_DIRS
+	unset SEARCH_DIRS_MASK
+	unset LD_LIBRARY_MASK
+
+	eval $(portageq envvar -v PORTAGE_ROOT PORTAGE_NICENESS EMERGE_DEFAULT_OPTS SEARCH_DIRS SEARCH_DIRS_MASK LD_LIBRARY_MASK)
+
+	SEARCH_DIRS="$ORIG_SEARCH_DIRS $SEARCH_DIRS"
+	SEARCH_DIRS_MASK="$ORIG_SEARCH_DIRS_MASK $SEARCH_DIRS_MASK"
+	LD_LIBRARY_MASK="$ORIG_LD_LIBRARY_MASK $LD_LIBRARY_MASK"
+}
+
+##
+# Setup the paths to search (and filter the ones to avoid)
+setup_search_paths_and_masks() {
+	local configfile sdir mdir skip_me filter_SEARCH_DIRS
+
+	einfo "Configuring search environment for $APP_NAME"
+
+	# Update the incremental variables using /etc/profile.env, /etc/ld.so.conf,
+	# portage, and the environment
+
+	# Read the incremental variables from environment and portage
+	# Until such time as portage supports these variables as incrementals
+	# The value will be what is in /etc/make.conf
+#	SEARCH_DIRS+=" "$(unset SEARCH_DIRS; portageq envvar SEARCH_DIRS)
+#	SEARCH_DIRS_MASK+=" "$(unset SEARCH_DIRS_MASK; portageq envvar SEARCH_DIRS_MASK)
+#	LD_LIBRARY_MASK+=" "$(unset LD_LIBRARY_MASK; portageq envvar LD_LIBRARY_MASK)
+
+	# Add the defaults
+	if [[ -d /etc/revdep-rebuild ]]; then
+		for configfile in /etc/revdep-rebuild/*; do
+			SEARCH_DIRS+=" "$(. $configfile; echo $SEARCH_DIRS)
+			SEARCH_DIRS_MASK+=" "$(. $configfile; echo $SEARCH_DIRS_MASK)
+			LD_LIBRARY_MASK+=" "$(. $configfile; echo $LD_LIBRARY_MASK)
+		done
+	else
+		SEARCH_DIRS+=" /bin /sbin /usr/bin /usr/sbin /lib* /usr/lib*"
+		SEARCH_DIRS_MASK+=" /opt/OpenOffice /usr/lib/openoffice"
+		LD_LIBRARY_MASK+=" libodbcinst.so libodbc.so libjava.so libjvm.so"
+	fi
+
+	# Get the ROOTPATH and PATH from /etc/profile.env
+	if [[ -r "/etc/profile.env" && -s "/etc/profile.env" ]]; then
+		SEARCH_DIRS+=" "$(. /etc/profile.env; /usr/bin/tr ':' ' ' <<< "$ROOTPATH $PATH")
+	fi
+
+	# Get the directories from /etc/ld.so.conf
+	if [[ -r /etc/ld.so.conf && -s /etc/ld.so.conf ]]; then
+		SEARCH_DIRS+=" "$(parse_ld_so_conf)
+	fi
+
+	# Set the final variables
+	SEARCH_DIRS=$(clean_var <<< "$SEARCH_DIRS")
+	SEARCH_DIRS_MASK=$(clean_var <<< "$SEARCH_DIRS_MASK")
+	LD_LIBRARY_MASK=$(clean_var <<< "$LD_LIBRARY_MASK")
+	# Filter masked paths from SEARCH_DIRS
+	for sdir in ${SEARCH_DIRS} ; do
+		skip_me=
+		for mdir in ${SEARCH_DIRS_MASK}; do
+			[[ ${sdir} == ${mdir}/* ]] && skip_me=1 && break
+		done
+		[[ -n ${skip_me} ]] || filter_SEARCH_DIRS+=" ${sdir}"
+	done
+	SEARCH_DIRS=$(clean_var <<< "${filter_SEARCH_DIRS}")
+	[[ $SEARCH_DIRS ]] || die 1 "No search defined -- this is a bug."
+}
+##
+# Finish up
+cleanup() {
+		trap_cmd() {
+			eerror "terminated. Please remove the temporary files manually:"
+			eerror "rm ${WORKING_DIR}/*.rr"
+			exit 1
+		}
+		trap trap_cmd SIGHUP SIGINT SIGQUIT SIGABRT SIGTERM
+}
+
+main "$@"



^ permalink raw reply related	[flat|nested] 89+ messages in thread

end of thread, other threads:[~2019-11-18 18:21 UTC | newest]

Thread overview: 89+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2011-10-17 20:55 [gentoo-commits] proj/elfix:master commit in: scripts/ Anthony G. Basile
  -- strict thread matches above, loose matches on Subject: below --
2019-11-18 18:21 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-05-20 19:47 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: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

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox