1 |
commit: f85a9ba0fc729d43fdf240da7d075eaaa09c6b62 |
2 |
Author: Anthony G. Basile <blueness <AT> gentoo <DOT> org> |
3 |
AuthorDate: Sat Nov 26 18:42:59 2011 +0000 |
4 |
Commit: Anthony G. Basile <blueness <AT> gentoo <DOT> org> |
5 |
CommitDate: Sat Nov 26 18:42:59 2011 +0000 |
6 |
URL: http://git.overlays.gentoo.org/gitweb/?p=proj/elfix.git;a=commit;h=f85a9ba0 |
7 |
|
8 |
scripts/revdep-pax: add -e switch, verbose for ~/bin:/usr/local/bin:/usr/bin:/bin:/opt/bin:/usr/x86_64-pc-linux-gnu/gcc-bin/4.5.3:/usr/lib64/subversion/bin:/usr/games/bin only |
9 |
|
10 |
--- |
11 |
doc/revdep-pax.1 | 36 +++++++++++++++------------ |
12 |
doc/revdep-pax.pod | 24 ++++++++++------- |
13 |
scripts/revdep-pax | 68 ++++++++++++++++++++++++++++----------------------- |
14 |
3 files changed, 71 insertions(+), 57 deletions(-) |
15 |
|
16 |
diff --git a/doc/revdep-pax.1 b/doc/revdep-pax.1 |
17 |
index 8e2b008..3933f76 100644 |
18 |
--- a/doc/revdep-pax.1 |
19 |
+++ b/doc/revdep-pax.1 |
20 |
@@ -135,13 +135,13 @@ revdep\-pax \- find mismatching PaX markings between ELF objects and their libra |
21 |
.IX Header "SYNOPSIS" |
22 |
\&\fBrevdep-pax\fR \-f [\-v] |
23 |
.PP |
24 |
-\&\fBrevdep-pax\fR \-r [\-v] |
25 |
+\&\fBrevdep-pax\fR \-r [\-ve] |
26 |
.PP |
27 |
\&\fBrevdep-pax\fR \-b \s-1OBJECT\s0 [\-mv] |
28 |
.PP |
29 |
-\&\fBrevdep-pax\fR \-s \s-1SONAME\s0 [\-mv] |
30 |
+\&\fBrevdep-pax\fR \-s \s-1SONAME\s0 [\-mve] |
31 |
.PP |
32 |
-\&\fBrevdep-pax\fR \-l \s-1LIBRARY\s0 [\-mv] |
33 |
+\&\fBrevdep-pax\fR \-l \s-1LIBRARY\s0 [\-mve] |
34 |
.PP |
35 |
\&\fBrevdep-pax\fR [\-h] |
36 |
.SH "DESCRIPTION" |
37 |
@@ -165,28 +165,32 @@ and in mark mode (\-m), the user is prompted whether to proceed with the migrati |
38 |
so that the PaX flags of the target inherit the flags of the source. |
39 |
.SH "OPTIONS" |
40 |
.IX Header "OPTIONS" |
41 |
-.IP "\fB\-f\fR Scan the system for all forward mappings" 4 |
42 |
-.IX Item "-f Scan the system for all forward mappings" |
43 |
+.IP "\fB\-f\fR Scan the system for all forward mappings." 4 |
44 |
+.IX Item "-f Scan the system for all forward mappings." |
45 |
.PD 0 |
46 |
.IP "" 4 |
47 |
-.IP "\fB\-r\fR Scan the system for all reverse mappings" 4 |
48 |
-.IX Item "-r Scan the system for all reverse mappings" |
49 |
+.IP "\fB\-r\fR Scan the system for all reverse mappings." 4 |
50 |
+.IX Item "-r Scan the system for all reverse mappings." |
51 |
.IP "" 4 |
52 |
-.IP "\fB\-b\fR \s-1OBJECT\s0 Retrieve only the forward mappings for this \s-1ELF\s0 \s-1OBJECT\s0" 4 |
53 |
-.IX Item "-b OBJECT Retrieve only the forward mappings for this ELF OBJECT" |
54 |
+.IP "\fB\-b\fR \s-1OBJECT\s0 Retrieve only the forward mappings for this \s-1ELF\s0 \s-1OBJECT\s0." 4 |
55 |
+.IX Item "-b OBJECT Retrieve only the forward mappings for this ELF OBJECT." |
56 |
.IP "" 4 |
57 |
-.IP "\fB\-s\fR \s-1SONAME\s0 Retrieve only the reverse mappings for this \s-1SONAME\s0" 4 |
58 |
-.IX Item "-s SONAME Retrieve only the reverse mappings for this SONAME" |
59 |
+.IP "\fB\-s\fR \s-1SONAME\s0 Retrieve only the reverse mappings for this \s-1SONAME\s0." 4 |
60 |
+.IX Item "-s SONAME Retrieve only the reverse mappings for this SONAME." |
61 |
.IP "" 4 |
62 |
-.IP "\fB\-l\fR \s-1LIBRARY\s0 Retrieve only the reverse mappings for this \s-1LIBRARY\s0" 4 |
63 |
-.IX Item "-l LIBRARY Retrieve only the reverse mappings for this LIBRARY" |
64 |
-.IP "" 4 |
65 |
-.IP "\fB\-v\fR Report all mappings, not just the mismatched ones" 4 |
66 |
-.IX Item "-v Report all mappings, not just the mismatched ones" |
67 |
+.IP "\fB\-l\fR \s-1LIBRARY\s0 Retrieve only the reverse mappings for this \s-1LIBRARY\s0." 4 |
68 |
+.IX Item "-l LIBRARY Retrieve only the reverse mappings for this LIBRARY." |
69 |
.IP "" 4 |
70 |
.IP "\fB\-m\fR Prompt the user to mark the found object with the PaX flags of the source" 4 |
71 |
.IX Item "-m Prompt the user to mark the found object with the PaX flags of the source" |
72 |
.IP "" 4 |
73 |
+.IP "\fB\-v\fR Report all mappings, not just the mismatched ones." 4 |
74 |
+.IX Item "-v Report all mappings, not just the mismatched ones." |
75 |
+.IP "" 4 |
76 |
+.ie n .IP "\fB\-e\fR If \-v is chosen, then limit the report to only those executables in the current shell's $PATH. If \-m is chosen, then limit the markings to only those executables. This flag only has effect for reverse mappings, i.e., for \-r, \-s or \-l." 4 |
77 |
+.el .IP "\fB\-e\fR If \-v is chosen, then limit the report to only those executables in the current shell's \f(CW$PATH\fR. If \-m is chosen, then limit the markings to only those executables. This flag only has effect for reverse mappings, i.e., for \-r, \-s or \-l." 4 |
78 |
+.IX Item "-e If -v is chosen, then limit the report to only those executables in the current shell's $PATH. If -m is chosen, then limit the markings to only those executables. This flag only has effect for reverse mappings, i.e., for -r, -s or -l." |
79 |
+.IP "" 4 |
80 |
.IP "\fB\-h\fR Print out a short help message and exit." 4 |
81 |
.IX Item "-h Print out a short help message and exit." |
82 |
.PD |
83 |
|
84 |
diff --git a/doc/revdep-pax.pod b/doc/revdep-pax.pod |
85 |
index fc46418..a72b0ba 100644 |
86 |
--- a/doc/revdep-pax.pod |
87 |
+++ b/doc/revdep-pax.pod |
88 |
@@ -6,13 +6,13 @@ B<revdep-pax> - find mismatching PaX markings between ELF objects and their libr |
89 |
|
90 |
B<revdep-pax> -f [-v] |
91 |
|
92 |
-B<revdep-pax> -r [-v] |
93 |
+B<revdep-pax> -r [-ve] |
94 |
|
95 |
B<revdep-pax> -b OBJECT [-mv] |
96 |
|
97 |
-B<revdep-pax> -s SONAME [-mv] |
98 |
+B<revdep-pax> -s SONAME [-mve] |
99 |
|
100 |
-B<revdep-pax> -l LIBRARY [-mv] |
101 |
+B<revdep-pax> -l LIBRARY [-mve] |
102 |
|
103 |
B<revdep-pax> [-h] |
104 |
|
105 |
@@ -40,31 +40,35 @@ so that the PaX flags of the target inherit the flags of the source. |
106 |
|
107 |
=over |
108 |
|
109 |
-=item B<-f> Scan the system for all forward mappings |
110 |
+=item B<-f> Scan the system for all forward mappings. |
111 |
|
112 |
=item |
113 |
|
114 |
-=item B<-r> Scan the system for all reverse mappings |
115 |
+=item B<-r> Scan the system for all reverse mappings. |
116 |
|
117 |
=item |
118 |
|
119 |
-=item B<-b> OBJECT Retrieve only the forward mappings for this ELF OBJECT |
120 |
+=item B<-b> OBJECT Retrieve only the forward mappings for this ELF OBJECT. |
121 |
|
122 |
=item |
123 |
|
124 |
-=item B<-s> SONAME Retrieve only the reverse mappings for this SONAME |
125 |
+=item B<-s> SONAME Retrieve only the reverse mappings for this SONAME. |
126 |
|
127 |
=item |
128 |
|
129 |
-=item B<-l> LIBRARY Retrieve only the reverse mappings for this LIBRARY |
130 |
+=item B<-l> LIBRARY Retrieve only the reverse mappings for this LIBRARY. |
131 |
|
132 |
=item |
133 |
|
134 |
-=item B<-v> Report all mappings, not just the mismatched ones |
135 |
+=item B<-m> Prompt the user to mark the found object with the PaX flags of the source. |
136 |
|
137 |
=item |
138 |
|
139 |
-=item B<-m> Prompt the user to mark the found object with the PaX flags of the source |
140 |
+=item B<-v> Report all mappings, not just the mismatched ones. |
141 |
+ |
142 |
+=item |
143 |
+ |
144 |
+=item B<-e> If -v is chosen, then limit the report to only those executables in the current shell's $PATH. If -m is chosen, then limit the markings to only those executables. This flag only has effect for reverse mappings, i.e., for -r, -s or -l. |
145 |
|
146 |
=item |
147 |
|
148 |
|
149 |
diff --git a/scripts/revdep-pax b/scripts/revdep-pax |
150 |
index bfea494..b65a65a 100755 |
151 |
--- a/scripts/revdep-pax |
152 |
+++ b/scripts/revdep-pax |
153 |
@@ -105,13 +105,10 @@ def print_forward_linkings( forward_linkings, so2library_mappings, verbose ): |
154 |
print sv |
155 |
print |
156 |
if count == 0: |
157 |
- print |
158 |
print '\tNo mismatches' |
159 |
- print |
160 |
else: |
161 |
- print |
162 |
print '\tMismatches' |
163 |
- print |
164 |
+ print |
165 |
else: |
166 |
if count != 0: |
167 |
print s |
168 |
@@ -120,14 +117,12 @@ def print_forward_linkings( forward_linkings, so2library_mappings, verbose ): |
169 |
|
170 |
missing_binaries = set(missing_binaries) |
171 |
print |
172 |
- print |
173 |
print '**** Missing binaries ****' |
174 |
for m in missing_binaries: |
175 |
print m |
176 |
|
177 |
missing_links = set(missing_links) |
178 |
print |
179 |
- print |
180 |
print '**** Missing forward linkings ****' |
181 |
for m in missing_links: |
182 |
print m |
183 |
@@ -136,7 +131,8 @@ def print_forward_linkings( forward_linkings, so2library_mappings, verbose ): |
184 |
print |
185 |
|
186 |
|
187 |
-def print_reverse_linkings( reverse_linkings, so2library_mappings, verbose ): |
188 |
+def print_reverse_linkings( reverse_linkings, so2library_mappings, verbose, executable_only ): |
189 |
+ shell_path = path = os.getenv('PATH').split(':') |
190 |
missing_sonames = [] |
191 |
missing_links = [] |
192 |
|
193 |
@@ -155,7 +151,11 @@ def print_reverse_linkings( reverse_linkings, so2library_mappings, verbose ): |
194 |
for binary in reverse_linkings[soname]: |
195 |
try: |
196 |
( binary_flags, binary_pax_flags ) = pax.getflags(binary) |
197 |
- sv = '%s\n\t%s ( %s )' % ( sv, binary, binary_flags ) |
198 |
+ if executable_only: |
199 |
+ if os.path.dirname(binary) in shell_path: |
200 |
+ sv = '%s\n\t%s ( %s )' % ( sv, binary, binary_flags ) |
201 |
+ else: |
202 |
+ sv = '%s\n\t%s ( %s )' % ( sv, binary, binary_flags ) |
203 |
if library_flags != binary_flags: |
204 |
s = '%s\n\t%s ( %s )' % ( s, binary, binary_flags ) |
205 |
count = count + 1 |
206 |
@@ -166,13 +166,10 @@ def print_reverse_linkings( reverse_linkings, so2library_mappings, verbose ): |
207 |
print sv |
208 |
print |
209 |
if count == 0: |
210 |
- print |
211 |
print '\tNo mismatches' |
212 |
- print |
213 |
else: |
214 |
- print |
215 |
print '\tMismatches' |
216 |
- print |
217 |
+ print |
218 |
else: |
219 |
if count != 0: |
220 |
print s |
221 |
@@ -181,17 +178,16 @@ def print_reverse_linkings( reverse_linkings, so2library_mappings, verbose ): |
222 |
|
223 |
missing_sonames = set(missing_sonames) |
224 |
print |
225 |
- print |
226 |
print '**** Missing sonames ****' |
227 |
for m in missing_sonames: |
228 |
print m |
229 |
|
230 |
missing_links = set(missing_links) |
231 |
print |
232 |
- print |
233 |
print '**** Missing reverse linkings ****' |
234 |
for m in missing_links: |
235 |
print m |
236 |
+ |
237 |
print |
238 |
print |
239 |
|
240 |
@@ -202,14 +198,15 @@ def run_usage(): |
241 |
print 'Program Name : revdep-pax' |
242 |
print 'Description : Get or set pax flags on an ELF object' |
243 |
print |
244 |
- print 'Usage : revdep-pax -f [-v] print out all forward mappings for all system binaries' |
245 |
- print ' : revdep-pax -r [-v] print out all reverse mappints for all system sonames' |
246 |
- print ' : revdep-pax -b OBJECT [-mv] print all forward mappings only for OBJECT' |
247 |
- print ' : revdep-pax -s SONAME [-mv] print all reverse mappings only for SONAME' |
248 |
- print ' : revdep-pax -l LIBRARY [-mv] print all reverse mappings only for LIBRARY file' |
249 |
- print ' : revdep-pax [-h] print out this help' |
250 |
- print ' : -v verbose, otherwise just print mismatching objects' |
251 |
- print ' : -m don\'t just report, but mark the mismatching objects' |
252 |
+ print 'Usage : revdep-pax -f [-v] print out all forward mappings for all system binaries' |
253 |
+ print ' : revdep-pax -r [-ve] print out all reverse mappings for all system sonames' |
254 |
+ print ' : revdep-pax -b OBJECT [-mv] print all forward mappings only for OBJECT' |
255 |
+ print ' : revdep-pax -s SONAME [-mve] print all reverse mappings only for SONAME' |
256 |
+ print ' : revdep-pax -l LIBRARY [-mve] print all reverse mappings only for LIBRARY file' |
257 |
+ print ' : revdep-pax [-h] print out this help' |
258 |
+ print ' : -v verbose, otherwise just print mismatching objects' |
259 |
+ print ' : -e assuming verbose, only print out executables in shell $PATH' |
260 |
+ print ' : -m don\'t just report, but mark the mismatching objects' |
261 |
print |
262 |
|
263 |
|
264 |
@@ -219,10 +216,10 @@ def run_forward(verbose): |
265 |
print |
266 |
|
267 |
|
268 |
-def run_reverse(verbose): |
269 |
+def run_reverse(verbose, executable_only): |
270 |
( forward_linkings, so2library_mappings ) = get_forward_linkings() |
271 |
reverse_linkings = invert_linkings( forward_linkings ) |
272 |
- print_reverse_linkings( reverse_linkings, so2library_mappings, verbose ) |
273 |
+ print_reverse_linkings( reverse_linkings, so2library_mappings, verbose, executable_only) |
274 |
print |
275 |
|
276 |
|
277 |
@@ -285,7 +282,9 @@ def invert_so2library_mappings( so2library_mappings ): |
278 |
return library2soname_mappings |
279 |
|
280 |
|
281 |
-def run_soname(name, verbose, use_soname, mark): |
282 |
+def run_soname(name, verbose, use_soname, executable_only, mark): |
283 |
+ shell_path = path = os.getenv('PATH').split(':') |
284 |
+ |
285 |
( forward_linkings, so2library_mappings ) = get_forward_linkings() |
286 |
reverse_linkings = invert_linkings( forward_linkings ) |
287 |
|
288 |
@@ -299,7 +298,7 @@ def run_soname(name, verbose, use_soname, mark): |
289 |
library = so2library_mappings[soname] |
290 |
|
291 |
( library_flags, library_pax_flags ) = pax.getflags(library) |
292 |
- print soname, '\t', library, '(', library_flags, ')' |
293 |
+ print '%s\t%s (%s)' % ( soname, library, library_flags ) |
294 |
print |
295 |
|
296 |
mismatched_binaries = [] |
297 |
@@ -307,7 +306,11 @@ def run_soname(name, verbose, use_soname, mark): |
298 |
try: |
299 |
( binary_flags, binary_pax_flags ) = pax.getflags(binary) |
300 |
if verbose: |
301 |
- print '\t%s ( %s )' % ( binary, binary_flags ) |
302 |
+ if executable_only: |
303 |
+ if os.path.dirname(binary) in shell_path: |
304 |
+ print '\t%s ( %s )' % ( binary, binary_flags ) |
305 |
+ else: |
306 |
+ print '\t%s ( %s )' % ( binary, binary_flags ) |
307 |
if library_flags != binary_flags: |
308 |
mismatched_binaries.append(binary) |
309 |
if not verbose: |
310 |
@@ -347,7 +350,7 @@ def run_soname(name, verbose, use_soname, mark): |
311 |
|
312 |
def main(): |
313 |
try: |
314 |
- opts, args = getopt.getopt(sys.argv[1:], 'hfrb:s:l:vm') |
315 |
+ opts, args = getopt.getopt(sys.argv[1:], 'hfrb:s:l:vem') |
316 |
except getopt.GetoptError, err: |
317 |
print str(err) # will print something like 'option -a not recognized' |
318 |
run_usage() |
319 |
@@ -366,6 +369,7 @@ def main(): |
320 |
library = None |
321 |
|
322 |
verbose = False |
323 |
+ executable_only = False |
324 |
mark = False |
325 |
|
326 |
opt_count = 0 |
327 |
@@ -391,6 +395,8 @@ def main(): |
328 |
opt_count += 1 |
329 |
elif o == '-v': |
330 |
verbose = True |
331 |
+ elif o == '-e': |
332 |
+ executable_only = True |
333 |
elif o == '-m': |
334 |
mark = True |
335 |
else: |
336 |
@@ -404,14 +410,14 @@ def main(): |
337 |
elif do_forward: |
338 |
run_forward(verbose) |
339 |
elif do_reverse: |
340 |
- run_reverse(verbose) |
341 |
+ run_reverse(verbose, executable_only) |
342 |
elif binary != None: |
343 |
run_binary(binary, verbose, mark) |
344 |
elif soname != None: |
345 |
- run_soname(soname, verbose, True, mark) |
346 |
+ run_soname(soname, verbose, executable_only, True, mark) |
347 |
elif library != None: |
348 |
library = os.path.realpath(library) |
349 |
- run_soname(library, verbose, False, mark) |
350 |
+ run_soname(library, verbose, executable_only, False, mark) |
351 |
|
352 |
if __name__ == '__main__': |
353 |
main() |