1 |
solar 11/07/30 17:08:30 |
2 |
|
3 |
Modified: scanelf.c |
4 |
Log: |
5 |
[PATCH pax-utils 1/2] add --root option # Ludwig Nussel <ludwig.nussel@××××.de> |
6 |
|
7 |
Revision Changes Path |
8 |
1.223 pax-utils/scanelf.c |
9 |
|
10 |
file : http://sources.gentoo.org/viewvc.cgi/gentoo-projects/pax-utils/scanelf.c?rev=1.223&view=markup |
11 |
plain: http://sources.gentoo.org/viewvc.cgi/gentoo-projects/pax-utils/scanelf.c?rev=1.223&content-type=text/plain |
12 |
diff : http://sources.gentoo.org/viewvc.cgi/gentoo-projects/pax-utils/scanelf.c?r1=1.222&r2=1.223 |
13 |
|
14 |
Index: scanelf.c |
15 |
=================================================================== |
16 |
RCS file: /var/cvsroot/gentoo-projects/pax-utils/scanelf.c,v |
17 |
retrieving revision 1.222 |
18 |
retrieving revision 1.223 |
19 |
diff -u -r1.222 -r1.223 |
20 |
--- scanelf.c 8 Dec 2010 01:24:01 -0000 1.222 |
21 |
+++ scanelf.c 30 Jul 2011 17:08:30 -0000 1.223 |
22 |
@@ -1,13 +1,13 @@ |
23 |
/* |
24 |
* Copyright 2003-2007 Gentoo Foundation |
25 |
* Distributed under the terms of the GNU General Public License v2 |
26 |
- * $Header: /var/cvsroot/gentoo-projects/pax-utils/scanelf.c,v 1.222 2010/12/08 01:24:01 vapier Exp $ |
27 |
+ * $Header: /var/cvsroot/gentoo-projects/pax-utils/scanelf.c,v 1.223 2011/07/30 17:08:30 solar Exp $ |
28 |
* |
29 |
* Copyright 2003-2007 Ned Ludd - <solar@g.o> |
30 |
* Copyright 2004-2007 Mike Frysinger - <vapier@g.o> |
31 |
*/ |
32 |
|
33 |
-static const char *rcsid = "$Id: scanelf.c,v 1.222 2010/12/08 01:24:01 vapier Exp $"; |
34 |
+static const char *rcsid = "$Id: scanelf.c,v 1.223 2011/07/30 17:08:30 solar Exp $"; |
35 |
const char argv0[] = "scanelf"; |
36 |
|
37 |
#include "paxinc.h" |
38 |
@@ -68,6 +68,7 @@ |
39 |
static char **qa_textrels = NULL; |
40 |
static char **qa_execstack = NULL; |
41 |
static char **qa_wx_load = NULL; |
42 |
+static char *root; |
43 |
|
44 |
static int match_bits = 0; |
45 |
static unsigned int match_perms = 0; |
46 |
@@ -1497,6 +1498,16 @@ |
47 |
return 0; |
48 |
} |
49 |
|
50 |
+static const char* maybe_add_root(const char* fname, char* buf) |
51 |
+{ |
52 |
+ if (root && strncmp(fname, root, strlen(root))) { |
53 |
+ strcpy(buf, root); |
54 |
+ strncat(buf, fname, __PAX_UTILS_PATH_MAX-strlen(root)-1); |
55 |
+ fname = buf; |
56 |
+ } |
57 |
+ return fname; |
58 |
+} |
59 |
+ |
60 |
/* scan a directory for ET_EXEC files and print when we find one */ |
61 |
static int scanelf_dir(const char *path) |
62 |
{ |
63 |
@@ -1504,9 +1515,12 @@ |
64 |
register struct dirent *dentry; |
65 |
struct stat st_top, st; |
66 |
char buf[__PAX_UTILS_PATH_MAX]; |
67 |
+ char _path[__PAX_UTILS_PATH_MAX]; |
68 |
size_t pathlen = 0, len = 0; |
69 |
int ret = 0; |
70 |
|
71 |
+ path = maybe_add_root(path, _path); |
72 |
+ |
73 |
/* make sure path exists */ |
74 |
if (lstat(path, &st_top) == -1) { |
75 |
if (be_verbose > 2) printf("%s: does not exist\n", path); |
76 |
@@ -1579,6 +1593,9 @@ |
77 |
FILE *fp = NULL; |
78 |
char *p; |
79 |
char path[__PAX_UTILS_PATH_MAX]; |
80 |
+ char _fname[__PAX_UTILS_PATH_MAX]; |
81 |
+ |
82 |
+ fname = maybe_add_root(fname, _fname); |
83 |
|
84 |
if (i + 1 == ARRAY_SIZE(ldpaths)) |
85 |
return i; |
86 |
@@ -1599,11 +1616,13 @@ |
87 |
char gpath[__PAX_UTILS_PATH_MAX]; |
88 |
|
89 |
memset(gpath, 0, sizeof(gpath)); |
90 |
+ if (root) |
91 |
+ strcpy(gpath, root); |
92 |
|
93 |
if (path[8] != '/') |
94 |
- snprintf(gpath, sizeof(gpath), "/etc/%s", &path[8]); |
95 |
+ snprintf(gpath+strlen(gpath), sizeof(gpath)-strlen(gpath), "/etc/%s", &path[8]); |
96 |
else |
97 |
- strncpy(gpath, &path[8], sizeof(gpath)); |
98 |
+ strncpy(gpath+strlen(gpath), &path[8], sizeof(gpath)-strlen(gpath)); |
99 |
|
100 |
if (glob(gpath, 0, NULL, &gl) == 0) { |
101 |
for (x = 0; x < gl.gl_pathc; ++x) { |
102 |
@@ -1642,6 +1661,9 @@ |
103 |
FILE *fp = NULL; |
104 |
char *b = NULL, *p; |
105 |
struct elfhints_hdr hdr; |
106 |
+ char _fname[__PAX_UTILS_PATH_MAX]; |
107 |
+ |
108 |
+ fname = maybe_add_root(fname, _fname); |
109 |
|
110 |
if (i + 1 == ARRAY_SIZE(ldpaths)) |
111 |
return i; |
112 |
@@ -1737,6 +1759,7 @@ |
113 |
static struct option const long_opts[] = { |
114 |
{"path", no_argument, NULL, 'p'}, |
115 |
{"ldpath", no_argument, NULL, 'l'}, |
116 |
+ {"root", a_argument, NULL, 128}, |
117 |
{"recursive", no_argument, NULL, 'R'}, |
118 |
{"mount", no_argument, NULL, 'm'}, |
119 |
{"symlink", no_argument, NULL, 'y'}, |
120 |
@@ -1780,6 +1803,7 @@ |
121 |
static const char * const opts_help[] = { |
122 |
"Scan all directories in PATH environment", |
123 |
"Scan all directories in /etc/ld.so.conf", |
124 |
+ "Root directory (use with -l or -p)", |
125 |
"Scan directories recursively", |
126 |
"Don't recursively cross mount points", |
127 |
"Don't scan symlinks", |
128 |
@@ -1831,6 +1855,9 @@ |
129 |
if (long_opts[i].has_arg == no_argument) |
130 |
printf(" -%c, --%-14s* %s\n", long_opts[i].val, |
131 |
long_opts[i].name, opts_help[i]); |
132 |
+ else if (long_opts[i].val > '~') |
133 |
+ printf(" --%-7s <arg> * %s\n", |
134 |
+ long_opts[i].name, opts_help[i]); |
135 |
else |
136 |
printf(" -%c, --%-7s <arg> * %s\n", long_opts[i].val, |
137 |
long_opts[i].name, opts_help[i]); |
138 |
@@ -1980,6 +2007,9 @@ |
139 |
case 'D': show_endian = 1; break; |
140 |
case 'I': show_osabi = 1; break; |
141 |
case 'Y': show_eabi = 1; break; |
142 |
+ case 128: |
143 |
+ root = optarg; |
144 |
+ break; |
145 |
case ':': |
146 |
err("Option '%c' is missing parameter", optopt); |
147 |
case '?': |