1 |
commit: 646f75362042124158b075efb3c7eb8cd779539f |
2 |
Author: Anthony G. Basile <basile <AT> opensource <DOT> dyc <DOT> edu> |
3 |
AuthorDate: Thu May 5 23:50:15 2011 +0000 |
4 |
Commit: Anthony G. Basile <blueness <AT> gentoo <DOT> org> |
5 |
CommitDate: Thu May 5 23:50:15 2011 +0000 |
6 |
URL: http://git.overlays.gentoo.org/gitweb/?p=proj/elfix.git;a=commit;h=646f7536 |
7 |
|
8 |
poc/mangle-paxflags.c and src/fix-gnustack.c: added help option |
9 |
|
10 |
--- |
11 |
autogen.sh | 1 + |
12 |
configure.ac | 4 ++-- |
13 |
poc/mangle-paxflags.c | 29 ++++++++++++++++++++++++++--- |
14 |
src/fix-gnustack.c | 26 ++++++++++++++++++++++++-- |
15 |
4 files changed, 53 insertions(+), 7 deletions(-) |
16 |
|
17 |
diff --git a/autogen.sh b/autogen.sh |
18 |
index 66ed103..3888ff3 100755 |
19 |
--- a/autogen.sh |
20 |
+++ b/autogen.sh |
21 |
@@ -1,5 +1,6 @@ |
22 |
#!/bin/sh |
23 |
|
24 |
aclocal && \ |
25 |
+autoheader && \ |
26 |
autoconf && \ |
27 |
automake --add-missing --copy |
28 |
|
29 |
diff --git a/configure.ac b/configure.ac |
30 |
index 039a269..560cc82 100644 |
31 |
--- a/configure.ac |
32 |
+++ b/configure.ac |
33 |
@@ -2,9 +2,9 @@ |
34 |
# Process this file with autoconf to produce a configure script. |
35 |
|
36 |
AC_PREREQ([2.65]) |
37 |
-AC_INIT([elfix], [0.1], [blueness@g.o]) |
38 |
+AC_INIT([elfix], [0.1.3], [http://bugs.gentoo.org/]) |
39 |
AC_CONFIG_SRCDIR([src/fix-gnustack.c]) |
40 |
-#AC_CONFIG_HEADERS([config.h]) |
41 |
+AC_CONFIG_HEADERS([config.h]) |
42 |
AM_INIT_AUTOMAKE([1.11 foreign]) |
43 |
|
44 |
AC_ARG_ENABLE( |
45 |
|
46 |
diff --git a/poc/mangle-paxflags.c b/poc/mangle-paxflags.c |
47 |
index 8853b13..301dad7 100644 |
48 |
--- a/poc/mangle-paxflags.c |
49 |
+++ b/poc/mangle-paxflags.c |
50 |
@@ -28,6 +28,8 @@ |
51 |
#include <fcntl.h> |
52 |
#include <unistd.h> |
53 |
|
54 |
+#include <config.h> |
55 |
+ |
56 |
// From chpax.h |
57 |
#define EI_PAX 14 // Index in e_ident[] where to read flags |
58 |
#define HF_PAX_PAGEEXEC 1 // 0: Paging based non-exec pages |
59 |
@@ -37,22 +39,40 @@ |
60 |
#define HF_PAX_RANDEXEC 16 // 1: Randomize ET_EXEC base |
61 |
#define HF_PAX_SEGMEXEC 32 // 0: Segmentation based non-exec pages |
62 |
|
63 |
- |
64 |
#define PRINT(E,F,I) printf("%s:\t%s\n", #E, E & F ? ( I ? "enabled" : "disabled" ) : ( I ? "disabled" : "enabled" ) ); |
65 |
#define CASE(N,P) case P: printf("%d: %s\n", (int)N, #P); break |
66 |
|
67 |
|
68 |
+void |
69 |
+print_help(char *v) |
70 |
+{ |
71 |
+ printf( |
72 |
+ "Package Name : " PACKAGE_STRING "\n" |
73 |
+ "Bug Reports : " PACKAGE_BUGREPORT "\n" |
74 |
+ "Description : Check for, or conditionally remove, executable flag from PT_GNU_STACK\n\n" |
75 |
+ "Usage : %s {-h | [-e] [-p] ELFfile}\n" |
76 |
+ "options : Print out EI_PAX and PT_PAX_FLAGS information\n" |
77 |
+ " : -e Set all EI_PAX flags to least secure setting, pEmrXs\n" |
78 |
+ " : -p Remove PT_PAX_FLAGS program header\n" |
79 |
+ " : -h Print out this help\n", |
80 |
+ v |
81 |
+ ); |
82 |
+ |
83 |
+ exit(EXIT_SUCCESS); |
84 |
+} |
85 |
+ |
86 |
+ |
87 |
char * |
88 |
parse_cmd_args( int c, char *v[], int *flag_ei_pax, int *flag_pt_pax_flags ) |
89 |
{ |
90 |
int i, oc; |
91 |
|
92 |
if((c != 2)&&(c != 3)&&(c != 4)) |
93 |
- error(EXIT_FAILURE, 0, "Usage: %s [-e] [-p] elffile", v[0]); |
94 |
+ error(EXIT_FAILURE, 0, "Usage: %s {[-e] [-p] ELFfile | [-h]}", v[0]); |
95 |
|
96 |
*flag_ei_pax = 0; |
97 |
*flag_pt_pax_flags = 0; |
98 |
- while((oc = getopt(c, v,":ep")) != -1) |
99 |
+ while((oc = getopt(c, v,":eph")) != -1) |
100 |
switch(oc) |
101 |
{ |
102 |
case 'e': |
103 |
@@ -61,6 +81,9 @@ parse_cmd_args( int c, char *v[], int *flag_ei_pax, int *flag_pt_pax_flags ) |
104 |
case 'p': |
105 |
*flag_pt_pax_flags = 1; |
106 |
break; |
107 |
+ case 'h': |
108 |
+ print_help(v[0]); |
109 |
+ break; |
110 |
case '?': |
111 |
default: |
112 |
error(EXIT_FAILURE, 0, "option -%c is invalid: ignored.", optopt ) ; |
113 |
|
114 |
diff --git a/src/fix-gnustack.c b/src/fix-gnustack.c |
115 |
index 75d72ea..02eb4d5 100644 |
116 |
--- a/src/fix-gnustack.c |
117 |
+++ b/src/fix-gnustack.c |
118 |
@@ -28,6 +28,25 @@ |
119 |
#include <fcntl.h> |
120 |
#include <unistd.h> |
121 |
|
122 |
+#include <config.h> |
123 |
+ |
124 |
+ |
125 |
+void |
126 |
+print_help(char *v) |
127 |
+{ |
128 |
+ printf( |
129 |
+ "Package Name : " PACKAGE_STRING "\n" |
130 |
+ "Bug Reports : " PACKAGE_BUGREPORT "\n" |
131 |
+ "Description : Check for, or conditionally remove, executable flag from PT_GNU_STACK\n\n" |
132 |
+ "Usage : %s {[-f] ELFfile | [-h]}\n" |
133 |
+ "options : Print out protection flags on PT_GNU_STACK\n" |
134 |
+ " : -f Remove X if WX flags are set on PT_GNU_STACK\n" |
135 |
+ " : -h Print out this help\n", |
136 |
+ v |
137 |
+ ); |
138 |
+ |
139 |
+ exit(EXIT_SUCCESS); |
140 |
+} |
141 |
|
142 |
|
143 |
char * |
144 |
@@ -36,15 +55,18 @@ parse_cmd_args( int c, char *v[], int *flagv ) |
145 |
int i, oc; |
146 |
|
147 |
if((c != 2)&&(c != 3)) |
148 |
- error(EXIT_FAILURE, 0, "Usage: %s [-f] elffile", v[0]); |
149 |
+ error(EXIT_FAILURE, 0, "Usage: %s {-h | [-f] ELFfile}", v[0]); |
150 |
|
151 |
*flagv = 0 ; |
152 |
- while((oc = getopt(c, v,":f")) != -1) |
153 |
+ while((oc = getopt(c, v,":fh")) != -1) |
154 |
switch(oc) |
155 |
{ |
156 |
case 'f': |
157 |
*flagv = 1 ; |
158 |
break ; |
159 |
+ case 'h': |
160 |
+ print_help(v[0]); |
161 |
+ break; |
162 |
case '?': |
163 |
default: |
164 |
error(EXIT_FAILURE, 0, "option -%c is invalid: ignored.", optopt ) ; |