From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from pigeon.gentoo.org ([208.92.234.80] helo=lists.gentoo.org) by finch.gentoo.org with esmtp (Exim 4.60) (envelope-from ) id 1RM1qJ-0002tb-Jj for garchives@archives.gentoo.org; Thu, 03 Nov 2011 18:16:47 +0000 Received: from pigeon.gentoo.org (localhost [127.0.0.1]) by pigeon.gentoo.org (Postfix) with SMTP id 80B4D21C047; Thu, 3 Nov 2011 18:16:39 +0000 (UTC) Received: from smtp.gentoo.org (smtp.gentoo.org [140.211.166.183]) by pigeon.gentoo.org (Postfix) with ESMTP id 3C17121C047 for ; Thu, 3 Nov 2011 18:16:39 +0000 (UTC) Received: from pelican.gentoo.org (unknown [66.219.59.40]) (using TLSv1 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by smtp.gentoo.org (Postfix) with ESMTPS id 82B351B4013 for ; Thu, 3 Nov 2011 18:16:38 +0000 (UTC) Received: from localhost.localdomain (localhost [127.0.0.1]) by pelican.gentoo.org (Postfix) with ESMTP id B8F3E80042 for ; Thu, 3 Nov 2011 18:16:37 +0000 (UTC) From: "Anthony G. Basile" To: gentoo-commits@lists.gentoo.org Content-type: text/plain; charset=UTF-8 Reply-To: gentoo-dev@lists.gentoo.org, "Anthony G. Basile" Message-ID: <490d000a2d2538ca44cf9647e326caa15958e07e.blueness@gentoo> Subject: [gentoo-commits] proj/elfix:master commit in: src/ X-VCS-Repository: proj/elfix X-VCS-Files: src/paxctl-ng.c X-VCS-Directories: src/ X-VCS-Committer: blueness X-VCS-Committer-Name: Anthony G. Basile X-VCS-Revision: 490d000a2d2538ca44cf9647e326caa15958e07e Date: Thu, 3 Nov 2011 18:16:37 +0000 (UTC) Precedence: bulk List-Post: List-Help: List-Unsubscribe: List-Subscribe: List-Id: Gentoo Linux mail X-BeenThere: gentoo-commits@lists.gentoo.org Content-Transfer-Encoding: quoted-printable X-Archives-Salt: 51c551c3-591c-4363-b331-18a6d5745af2 X-Archives-Hash: 66398f0697ddc6b1cda3766d5e1bded8 commit: 490d000a2d2538ca44cf9647e326caa15958e07e Author: Anthony G. Basile gentoo org> AuthorDate: Thu Nov 3 18:16:31 2011 +0000 Commit: Anthony G. Basile gentoo org> CommitDate: Thu Nov 3 18:16:31 2011 +0000 URL: http://git.overlays.gentoo.org/gitweb/?p=3Dproj/elfix.git;a=3D= commit;h=3D490d000a src/paxctl-ng.c: added file globbing --- src/paxctl-ng.c | 119 +++++++++++++++++++++++++++++++++----------------= ------ 1 files changed, 71 insertions(+), 48 deletions(-) diff --git a/src/paxctl-ng.c b/src/paxctl-ng.c index 94dea09..bc1933b 100644 --- a/src/paxctl-ng.c +++ b/src/paxctl-ng.c @@ -35,7 +35,8 @@ =20 =20 #define PAX_NAMESPACE "user.pax" -#define BUF_SIZE 7 +#define BUF_SIZE 8 +#define FILE_NAME_SIZE 32768 =20 #define CREATE_XT_FLAGS_SECURE 1 #define CREATE_XT_FLAGS_DEFAULT 2 @@ -43,7 +44,7 @@ #define COPY_XT_TO_PT_FLAGS 4 =20 void -print_help(char *v) +print_help_exit(char *v) { printf( "\n" @@ -78,8 +79,9 @@ print_help(char *v) } =20 =20 -char * -parse_cmd_args(int c, char *v[], uint16_t *pax_flags, int *view_flags, i= nt *cp_flags) +void +parse_cmd_args(int argc, char *argv[], uint16_t *pax_flags, int *view_fl= ags, int *cp_flags, + int *begin, int *end) { int i, oc; int compat, solitaire; @@ -89,7 +91,7 @@ parse_cmd_args(int c, char *v[], uint16_t *pax_flags, i= nt *view_flags, int *cp_f *pax_flags =3D 0; *view_flags =3D 0; *cp_flags =3D 0;=20 - while((oc =3D getopt(c, v,":PpEeMmRrXxSsZzCcFfvh")) !=3D -1) + while((oc =3D getopt(argc, argv,":PpEeMmRrXxSsZzCcFfvh")) !=3D -1) { switch(oc) { @@ -172,7 +174,7 @@ parse_cmd_args(int c, char *v[], uint16_t *pax_flags,= int *view_flags, int *cp_f *view_flags =3D 1; break; case 'h': - print_help(v[0]); + print_help_exit(argv[0]); break; case '?': default: @@ -180,17 +182,16 @@ parse_cmd_args(int c, char *v[], uint16_t *pax_flag= s, int *view_flags, int *cp_f } } =20 - if - ( - ( - (compat =3D=3D 1 && solitaire =3D=3D 0) || - (compat =3D=3D 0 && solitaire =3D=3D 1) || - (compat =3D=3D 0 && solitaire =3D=3D 0 && *view_flags =3D=3D 1) - ) && v[optind] !=3D NULL - ) - return v[optind] ; + if( ((compat =3D=3D 1 && solitaire =3D=3D 0) || + (compat =3D=3D 0 && solitaire =3D=3D 1) || + (compat =3D=3D 0 && solitaire =3D=3D 0 && *view_flags =3D=3D 1) + ) && argv[optind] !=3D NULL) + { + *begin =3D optind; + *end =3D argc; + } else - print_help(v[0]); + print_help_exit(argv[0]); } =20 =20 @@ -204,15 +205,22 @@ get_pt_flags(int fd) uint16_t pt_flags =3D UINT16_MAX; =20 if(elf_version(EV_CURRENT) =3D=3D EV_NONE) - error(EXIT_FAILURE, 0, "Library out of date."); + { + printf("\tELF ERROR: Library out of date.\n"); + return pt_flags; + } =20 if((elf =3D elf_begin(fd, ELF_C_READ_MMAP, NULL)) =3D=3D NULL) - error(EXIT_FAILURE, 0, "elf_begin() fail: %s", elf_errmsg(elf_errno())= ); + { + printf("\tELF ERROR: elf_begin() fail: %s\n", elf_errmsg(elf_errno()))= ; + return pt_flags; + } =20 if(elf_kind(elf) !=3D ELF_K_ELF) { elf_end(elf); - error(EXIT_FAILURE, 0, "elf_kind() fail: this is not an elf file."); + printf("\tELF ERROR: elf_kind() fail: this is not an elf file.\n"); + return pt_flags; } =20 elf_getphdrnum(elf, &phnum); @@ -222,7 +230,8 @@ get_pt_flags(int fd) if(gelf_getphdr(elf, i, &phdr) !=3D &phdr) { elf_end(elf); - error(EXIT_FAILURE, 0, "gelf_getphdr(): %s", elf_errmsg(elf_errno()))= ; + printf("\tELF ERROR: gelf_getphdr(): %s\n", elf_errmsg(elf_errno())); + return pt_flags; } =20 if(phdr.p_type =3D=3D PT_PAX_FLAGS) @@ -275,23 +284,25 @@ print_flags(int fd) =20 flags =3D get_pt_flags(fd); if( flags =3D=3D UINT16_MAX ) - printf("PT_PAX: not found\n"); + printf("\tPT_PAX: not found\n"); else { memset(buf, 0, BUF_SIZE); bin2string(flags, buf); - printf("PT_PAX: %s\n", buf); + printf("\tPT_PAX: %s\n", buf); } =20 flags =3D get_xt_flags(fd); if( flags =3D=3D UINT16_MAX ) - printf("XT_PAX: not found\n"); + printf("\tXT_PAX: not found\n"); else { memset(buf, 0, BUF_SIZE); bin2string(flags, buf); - printf("XT_PAX: %s\n", buf); + printf("\tXT_PAX: %s\n", buf); } + + printf("\n"); } =20 =20 @@ -413,15 +424,22 @@ set_pt_flags(int fd, uint16_t pt_flags) size_t i, phnum; =20 if(elf_version(EV_CURRENT) =3D=3D EV_NONE) - error(EXIT_FAILURE, 0, "Library out of date."); + { + printf("\tELF ERROR: Library out of date.\n"); + return; + } =20 if((elf =3D elf_begin(fd, ELF_C_RDWR_MMAP, NULL)) =3D=3D NULL) - error(EXIT_FAILURE, 0, "elf_begin() fail: %s", elf_errmsg(elf_errno())= ); + { + printf("\tELF ERROR: elf_begin() fail: %s\n", elf_errmsg(elf_errno()))= ; + return; + } =20 if(elf_kind(elf) !=3D ELF_K_ELF) { elf_end(elf); - error(EXIT_FAILURE, 0, "elf_kind() fail: this is not an elf file."); + printf("\tELF ERROR: elf_kind() fail: this is not an elf file.\n"); + return;=20 } =20 elf_getphdrnum(elf, &phnum); @@ -431,7 +449,8 @@ set_pt_flags(int fd, uint16_t pt_flags) if(gelf_getphdr(elf, i, &phdr) !=3D &phdr) { elf_end(elf); - error(EXIT_FAILURE, 0, "gelf_getphdr(): %s", elf_errmsg(elf_errno()))= ; + printf("\tELF ERROR: gelf_getphdr(): %s\n", elf_errmsg(elf_errno())); + return; } =20 if(phdr.p_type =3D=3D PT_PAX_FLAGS) @@ -441,7 +460,7 @@ set_pt_flags(int fd, uint16_t pt_flags) if(!gelf_update_phdr(elf, i, &phdr)) { elf_end(elf); - error(EXIT_FAILURE, 0, "gelf_update_phdr(): %s", elf_errmsg(elf_errn= o())); + printf("\tELF ERROR: gelf_update_phdr(): %s", elf_errmsg(elf_errno()= )); } } } @@ -514,33 +533,37 @@ copy_xt_flags(fd, cp_flags) int main( int argc, char *argv[]) { - const char *f_name; - int fd; + int fd, fi; uint16_t pax_flags; - int view_flags, cp_flags; + int view_flags, cp_flags, begin, end; int rdwr_pt_pax =3D 1; =20 - f_name =3D parse_cmd_args(argc, argv, &pax_flags, &view_flags, &cp_flag= s); + parse_cmd_args(argc, argv, &pax_flags, &view_flags, &cp_flags, &begin, = &end); =20 - if((fd =3D open(f_name, O_RDWR)) < 0) + for(fi =3D begin; fi < end; fi++) { - rdwr_pt_pax =3D 0; - printf("open(O_RDWR) failed: cannot change PT_PAX flags\n"); - if((fd =3D open(f_name, O_RDONLY)) < 0) - error(EXIT_FAILURE, 0, "open() failed"); - } + printf("%s:\n", argv[fi]); =20 - if(cp_flags =3D=3D CREATE_XT_FLAGS_SECURE || cp_flags =3D=3D CREATE_XT_= FLAGS_DEFAULT) - create_xt_flags(fd, cp_flags); + if((fd =3D open(argv[fi], O_RDWR)) < 0) + { + rdwr_pt_pax =3D 0; + printf("\topen(O_RDWR) failed: cannot change PT_PAX flags\n"); + if((fd =3D open(argv[fi], O_RDONLY)) < 0) + error(EXIT_FAILURE, 0, "open() failed"); + } =20 - if(cp_flags =3D=3D COPY_PT_TO_XT_FLAGS || (cp_flags =3D=3D COPY_XT_TO_P= T_FLAGS && rdwr_pt_pax)) - copy_xt_flags(fd, cp_flags); + if(cp_flags =3D=3D CREATE_XT_FLAGS_SECURE || cp_flags =3D=3D CREATE_XT= _FLAGS_DEFAULT) + create_xt_flags(fd, cp_flags); =20 - if(pax_flags !=3D 1) - set_flags(fd, &pax_flags, rdwr_pt_pax); + if(cp_flags =3D=3D COPY_PT_TO_XT_FLAGS || (cp_flags =3D=3D COPY_XT_TO_= PT_FLAGS && rdwr_pt_pax)) + copy_xt_flags(fd, cp_flags); =20 - if(view_flags =3D=3D 1) - print_flags(fd); + if(pax_flags !=3D 1) + set_flags(fd, &pax_flags, rdwr_pt_pax); =20 - close(fd); + if(view_flags =3D=3D 1) + print_flags(fd); + + close(fd); + } }