From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from lists.gentoo.org (pigeon.gentoo.org [208.92.234.80]) by finch.gentoo.org (Postfix) with ESMTP id 55E7B1381F3 for ; Wed, 19 Dec 2012 03:51:34 +0000 (UTC) Received: from pigeon.gentoo.org (localhost [127.0.0.1]) by pigeon.gentoo.org (Postfix) with SMTP id 0063D21C001; Wed, 19 Dec 2012 03:51:23 +0000 (UTC) Received: from smtp.gentoo.org (smtp.gentoo.org [140.211.166.183]) (using TLSv1 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by pigeon.gentoo.org (Postfix) with ESMTPS id 5E9E221C001 for ; Wed, 19 Dec 2012 03:51:23 +0000 (UTC) Received: from hornbill.gentoo.org (hornbill.gentoo.org [94.100.119.163]) (using TLSv1 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by smtp.gentoo.org (Postfix) with ESMTPS id 4B6CB33D978 for ; Wed, 19 Dec 2012 03:51:22 +0000 (UTC) Received: from localhost.localdomain (localhost [127.0.0.1]) by hornbill.gentoo.org (Postfix) with ESMTP id D55A0E543C for ; Wed, 19 Dec 2012 03:51:20 +0000 (UTC) From: "Anthony G. Basile" To: gentoo-commits@lists.gentoo.org Content-Transfer-Encoding: 8bit Content-type: text/plain; charset=UTF-8 Reply-To: gentoo-dev@lists.gentoo.org, "Anthony G. Basile" Message-ID: <1355889061.b56be49809d3dc882149d5b9a6d39fba1796d19a.blueness@gentoo> Subject: [gentoo-commits] proj/elfix:master commit in: scripts/ X-VCS-Repository: proj/elfix X-VCS-Files: scripts/migrate X-VCS-Directories: scripts/ X-VCS-Committer: blueness X-VCS-Committer-Name: Anthony G. Basile X-VCS-Revision: b56be49809d3dc882149d5b9a6d39fba1796d19a X-VCS-Branch: master Date: Wed, 19 Dec 2012 03:51:20 +0000 (UTC) Precedence: bulk List-Post: List-Help: List-Unsubscribe: List-Subscribe: List-Id: Gentoo Linux mail X-BeenThere: gentoo-commits@lists.gentoo.org X-Archives-Salt: 6271b962-e477-4f28-ae43-de82c8a9101d X-Archives-Hash: a03b4636264663482f0fd5abd81488d0 commit: b56be49809d3dc882149d5b9a6d39fba1796d19a Author: Anthony G. Basile gentoo org> AuthorDate: Wed Dec 19 03:51:01 2012 +0000 Commit: Anthony G. Basile gentoo 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()