public inbox for gentoo-commits@lists.gentoo.org
 help / color / mirror / Atom feed
From: "Anthony G. Basile" <blueness@gentoo.org>
To: gentoo-commits@lists.gentoo.org
Subject: [gentoo-commits] proj/elfix:elfix-0.7.x commit in: scripts/
Date: Mon, 24 Dec 2012 10:59:06 +0000 (UTC)	[thread overview]
Message-ID: <1356346677.162448531916e2c8ed68f0c67b74d3a9ad097fcb.blueness@gentoo> (raw)

commit:     162448531916e2c8ed68f0c67b74d3a9ad097fcb
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: Mon Dec 24 10:57:57 2012 +0000
URL:        http://git.overlays.gentoo.org/gitweb/?p=proj/elfix.git;a=commit;h=16244853

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()


             reply	other threads:[~2012-12-24 11:00 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-12-24 10:59 Anthony G. Basile [this message]
  -- strict thread matches above, loose matches on Subject: below --
2012-12-29  1:16 [gentoo-commits] proj/elfix:elfix-0.7.x commit in: scripts/ Anthony G. Basile
2012-12-24 10:59 Anthony G. Basile
2012-12-24 10:59 Anthony G. Basile
2012-12-24 10:59 Anthony G. Basile
2012-12-24 10:59 Anthony G. Basile
2012-12-24 10:59 Anthony G. Basile
2012-12-24 10:59 Anthony G. Basile
2012-12-24 10:59 Anthony G. Basile
2012-12-24 10:59 Anthony G. Basile

Reply instructions:

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

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

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

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

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

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

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