/[gentoo-projects]/pax-utils/scanelf.c
Gentoo

Contents of /pax-utils/scanelf.c

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.33 - (hide annotations) (download) (as text)
Sun Apr 10 15:15:40 2005 UTC (9 years, 8 months ago) by solar
Branch: MAIN
Changes since 1.32: +15 -9 lines
File MIME type: text/x-csrc
- free orig pointer locations and not ptr that has been incremented. Use puts/fputs in place of printf() when no format identifier is used. Don't scan symlinks in scanelf_file()

1 solar 1.1 /*
2     * Copyright 2003 Ned Ludd <solar@gentoo.org>
3 vapier 1.8 * Copyright 1999-2005 Gentoo Foundation
4 solar 1.1 * Distributed under the terms of the GNU General Public License v2
5 solar 1.33 * $Header: /var/cvsroot/gentoo-projects/pax-utils/scanelf.c,v 1.32 2005/04/07 00:01:40 vapier Exp $
6 solar 1.1 *
7     ********************************************************************
8     * This program is free software; you can redistribute it and/or
9     * modify it under the terms of the GNU General Public License as
10     * published by the Free Software Foundation; either version 2 of the
11     * License, or (at your option) any later version.
12     *
13     * This program is distributed in the hope that it will be useful, but
14     * WITHOUT ANY WARRANTY; without even the implied warranty of
15     * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16     * General Public License for more details.
17     *
18     * You should have received a copy of the GNU General Public License
19     * along with this program; if not, write to the Free Software
20     * Foundation, Inc., 59 Temple Place - Suite 330, Boston,
21     * MA 02111-1307, USA.
22     */
23    
24     #include <stdio.h>
25     #include <stdlib.h>
26     #include <sys/types.h>
27 solar 1.28 #define __USE_GNU
28 solar 1.1 #include <string.h>
29 vapier 1.10 #include <errno.h>
30 solar 1.1 #include <unistd.h>
31     #include <sys/stat.h>
32     #include <dirent.h>
33     #include <getopt.h>
34 solar 1.20 #include <assert.h>
35 solar 1.21
36 solar 1.1 #include "paxelf.h"
37    
38 solar 1.33 static const char *rcsid = "$Id: scanelf.c,v 1.32 2005/04/07 00:01:40 vapier Exp $";
39 vapier 1.10
40    
41     /* helper functions for showing errors */
42 vapier 1.18 #define argv0 "scanelf" /*((*argv != NULL) ? argv[0] : __FILE__ "\b\b")*/
43 vapier 1.10 #define warn(fmt, args...) \
44     fprintf(stderr, "%s: " fmt "\n", argv0, ## args)
45     #define warnf(fmt, args...) warn("%s(): " fmt, __FUNCTION__, ## args)
46     #define err(fmt, args...) \
47     do { \
48     warn(fmt, ## args); \
49     exit(EXIT_FAILURE); \
50     } while (0)
51    
52    
53    
54     /* prototypes */
55     static void scanelf_file(const char *filename);
56     static void scanelf_dir(const char *path);
57     static void scanelf_ldpath();
58     static void scanelf_envpath();
59     static void usage(int status);
60     static void parseargs(int argc, char *argv[]);
61    
62     /* variables to control behavior */
63     static char scan_ldpath = 0;
64     static char scan_envpath = 0;
65     static char dir_recurse = 0;
66 vapier 1.14 static char dir_crossmount = 1;
67 vapier 1.10 static char show_pax = 0;
68     static char show_stack = 0;
69     static char show_textrel = 0;
70     static char show_rpath = 0;
71 vapier 1.32 static char show_needed = 0;
72 solar 1.16 static char show_banner = 1;
73 vapier 1.10 static char be_quiet = 0;
74 vapier 1.14 static char be_verbose = 0;
75 vapier 1.27 static char *find_sym = NULL;
76 vapier 1.10
77 solar 1.1
78    
79 vapier 1.10 /* scan an elf file and show all the fun stuff */
80     static void scanelf_file(const char *filename)
81 solar 1.6 {
82 vapier 1.10 int i;
83 vapier 1.32 char found_pax, found_stack, found_relro, found_textrel,
84     found_rpath, found_needed, found_sym;
85 vapier 1.26 elfobj *elf;
86 solar 1.33 struct stat st;
87 vapier 1.10
88 solar 1.33 /* make sure path exists */
89     if (lstat(filename, &st) == -1)
90     return;
91     if (!S_ISREG(st.st_mode))
92     return;
93 vapier 1.32 found_pax = found_stack = found_relro = found_textrel = \
94     found_rpath = found_needed = found_sym = 0;
95 solar 1.12
96 vapier 1.10 /* verify this is real ELF */
97 vapier 1.14 if ((elf = readelf(filename)) == NULL) {
98 vapier 1.26 if (be_verbose > 2) printf("%s: not an ELF\n", filename);
99 vapier 1.10 return;
100 vapier 1.14 }
101    
102 vapier 1.26 if (be_verbose > 1)
103     printf("%s: {%s,%s} scanning file\n", filename,
104     get_elfeitype(elf, EI_CLASS, elf->elf_class),
105     get_elfeitype(elf, EI_DATA, elf->data[EI_DATA]));
106     else if (be_verbose)
107     printf("%s: scanning file\n", filename);
108 vapier 1.10
109     /* show the header */
110 solar 1.16 if (!be_quiet && show_banner) {
111 vapier 1.32 printf(" TYPE ");
112     if (show_pax) printf(" PAX ");
113     if (show_stack) printf("STK/REL ");
114 vapier 1.23 if (show_textrel) printf("TEXTREL ");
115     if (show_rpath) printf("RPATH ");
116 vapier 1.32 if (show_needed) printf("NEEDED ");
117 vapier 1.23 printf(" FILE\n");
118 solar 1.16 show_banner = 0;
119 vapier 1.10 }
120    
121     /* dump all the good stuff */
122     if (!be_quiet)
123 vapier 1.26 printf("%-7s ", get_elfetype(elf));
124 vapier 1.10
125 vapier 1.14 if (show_pax) {
126     char *paxflags = pax_short_hf_flags(PAX_FLAGS(elf));
127     if (!be_quiet || (be_quiet && strncmp(paxflags, "PeMRxS", 6))) {
128     found_pax = 1;
129     printf("%s ", pax_short_hf_flags(PAX_FLAGS(elf)));
130     }
131     }
132 vapier 1.10
133     /* stack fun */
134     if (show_stack) {
135 vapier 1.26 #define SHOW_STACK(B) \
136     if (elf->elf_class == ELFCLASS ## B) { \
137     Elf ## B ## _Ehdr *ehdr = EHDR ## B (elf->ehdr); \
138     Elf ## B ## _Phdr *phdr = PHDR ## B (elf->phdr); \
139     for (i = 0; i < EGET(ehdr->e_phnum); i++) { \
140     if (EGET(phdr[i].p_type) != PT_GNU_STACK && \
141     EGET(phdr[i].p_type) != PT_GNU_RELRO) continue; \
142     if (be_quiet && !(EGET(phdr[i].p_flags) & PF_X)) \
143     continue; \
144     if (EGET(phdr[i].p_type) == PT_GNU_STACK) \
145     found_stack = 1; \
146     if (EGET(phdr[i].p_type) == PT_GNU_RELRO) \
147     found_relro = 1; \
148     printf("%s ", gnu_short_stack_flags(EGET(phdr[i].p_flags))); \
149     } \
150 vapier 1.10 }
151 vapier 1.26 SHOW_STACK(32)
152     SHOW_STACK(64)
153 vapier 1.23 if (!be_quiet && !found_stack) printf("--- ");
154     if (!be_quiet && !found_relro) printf("--- ");
155 vapier 1.10 }
156    
157     /* textrel fun */
158     if (show_textrel) {
159 vapier 1.26 #define SHOW_TEXTREL(B) \
160     if (elf->elf_class == ELFCLASS ## B) { \
161     Elf ## B ## _Dyn *dyn; \
162     Elf ## B ## _Ehdr *ehdr = EHDR ## B (elf->ehdr); \
163     Elf ## B ## _Phdr *phdr = PHDR ## B (elf->phdr); \
164     for (i = 0; i < EGET(ehdr->e_phnum); i++) { \
165     if (phdr[i].p_type != PT_DYNAMIC) continue; \
166     dyn = DYN ## B (elf->data + EGET(phdr[i].p_offset)); \
167     while (EGET(dyn->d_tag) != DT_NULL) { \
168     if (EGET(dyn->d_tag) == DT_TEXTREL) { /*dyn->d_tag != DT_FLAGS)*/ \
169     found_textrel = 1; \
170     /*if (dyn->d_un.d_val & DF_TEXTREL)*/ \
171 solar 1.33 fputs("TEXTREL ", stdout); \
172 vapier 1.26 } \
173     ++dyn; \
174     } \
175     } }
176     SHOW_TEXTREL(32)
177     SHOW_TEXTREL(64)
178 solar 1.33 if (!be_quiet && !found_textrel) fputs("------- ", stdout);
179 vapier 1.10 }
180    
181     /* rpath fun */
182     /* TODO: if be_quiet, only output RPATH's which aren't in /etc/ld.so.conf */
183     if (show_rpath) {
184 vapier 1.23 char *rpath, *runpath;
185 vapier 1.26 void *strtbl_void = elf_findsecbyname(elf, ".dynstr");
186 vapier 1.23 rpath = runpath = NULL;
187 vapier 1.10
188 vapier 1.26 if (strtbl_void) {
189     #define SHOW_RPATH(B) \
190     if (elf->elf_class == ELFCLASS ## B) { \
191     Elf ## B ## _Dyn *dyn; \
192     Elf ## B ## _Ehdr *ehdr = EHDR ## B (elf->ehdr); \
193     Elf ## B ## _Phdr *phdr = PHDR ## B (elf->phdr); \
194     Elf ## B ## _Shdr *strtbl = SHDR ## B (strtbl_void); \
195     for (i = 0; i < EGET(ehdr->e_phnum); i++) { \
196     if (EGET(phdr[i].p_type) != PT_DYNAMIC) continue; \
197     dyn = DYN ## B (elf->data + EGET(phdr[i].p_offset)); \
198     while (EGET(dyn->d_tag) != DT_NULL) { \
199     if (EGET(dyn->d_tag) == DT_RPATH) { \
200     rpath = elf->data + EGET(strtbl->sh_offset) + EGET(dyn->d_un.d_ptr); \
201     found_rpath = 1; \
202     } else if (EGET(dyn->d_tag) == DT_RUNPATH) { \
203     runpath = elf->data + EGET(strtbl->sh_offset) + EGET(dyn->d_un.d_ptr); \
204     found_rpath = 1; \
205     } \
206     ++dyn; \
207     } \
208     } }
209     SHOW_RPATH(32)
210     SHOW_RPATH(64)
211 vapier 1.10 }
212 vapier 1.23 if (rpath && runpath) {
213     if (!strcmp(rpath, runpath))
214     printf("%-5s ", runpath);
215     else {
216     fprintf(stderr, "%s's RPATH [%s] != RUNPATH [%s]\n", filename, rpath, runpath);
217     printf("{%s,%s} ", rpath, runpath);
218     }
219     } else if (rpath || runpath)
220     printf("%-5s ", (runpath ? runpath : rpath));
221     else if (!be_quiet && !found_rpath)
222     printf(" - ");
223 vapier 1.10 }
224    
225 vapier 1.32 /* print out all the NEEDED entries */
226     if (show_needed) {
227     char *needed;
228     void *strtbl_void = elf_findsecbyname(elf, ".dynstr");
229    
230     if (strtbl_void) {
231     #define SHOW_NEEDED(B) \
232     if (elf->elf_class == ELFCLASS ## B) { \
233     Elf ## B ## _Dyn *dyn; \
234     Elf ## B ## _Ehdr *ehdr = EHDR ## B (elf->ehdr); \
235     Elf ## B ## _Phdr *phdr = PHDR ## B (elf->phdr); \
236     Elf ## B ## _Shdr *strtbl = SHDR ## B (strtbl_void); \
237     for (i = 0; i < EGET(ehdr->e_phnum); i++) { \
238     if (be_verbose && EGET(phdr[i].p_type) == PT_INTERP) { \
239     dyn = DYN ## B (elf->data + EGET(phdr[i].p_offset)); \
240     printf("%s\n", elf->data + EGET(strtbl->sh_offset) + EGET(dyn->d_un.d_ptr)); \
241     exit(0); \
242     } \
243     if (EGET(phdr[i].p_type) != PT_DYNAMIC) continue; \
244     dyn = DYN ## B (elf->data + EGET(phdr[i].p_offset)); \
245     while (EGET(dyn->d_tag) != DT_NULL) { \
246     if (EGET(dyn->d_tag) == DT_NEEDED) { \
247     needed = elf->data + EGET(strtbl->sh_offset) + EGET(dyn->d_un.d_ptr); \
248     if (found_needed) printf(","); \
249     printf("%s", needed); \
250     found_needed = 1; \
251     } \
252     ++dyn; \
253     } \
254     } }
255     SHOW_NEEDED(32)
256     SHOW_NEEDED(64)
257     }
258     if (!be_quiet && !found_needed)
259     printf(" - ");
260     else if (found_needed)
261     printf(" ");
262     }
263    
264     /* search the symbol table for a specified symbol */
265 vapier 1.27 if (find_sym) {
266     void *symtab_void, *strtab_void;
267 vapier 1.32 char *versioned_symname;
268     size_t len;
269 solar 1.28
270 vapier 1.32 len = strlen(find_sym) + 1;
271     versioned_symname = (char *)malloc(sizeof(char) * (len+1));
272     if (!versioned_symname) {
273     warnf("Could not malloc() mem for sym scan");
274     return;
275     }
276 solar 1.28 sprintf(versioned_symname, "%s@", find_sym);
277 vapier 1.32
278 vapier 1.27 symtab_void = elf_findsecbyname(elf, ".symtab");
279     strtab_void = elf_findsecbyname(elf, ".strtab");
280    
281     if (symtab_void && strtab_void) {
282     #define FIND_SYM(B) \
283     if (elf->elf_class == ELFCLASS ## B) { \
284     Elf ## B ## _Shdr *symtab = SHDR ## B (symtab_void); \
285     Elf ## B ## _Shdr *strtab = SHDR ## B (strtab_void); \
286     Elf ## B ## _Sym *sym = SYM ## B (elf->data + EGET(symtab->sh_offset)); \
287     int cnt = EGET(symtab->sh_size) / EGET(symtab->sh_entsize); \
288     char *symname; \
289     for (i = 0; i < cnt; ++i) { \
290     if (sym->st_name) { \
291     symname = (char *)(elf->data + EGET(strtab->sh_offset) + EGET(sym->st_name)); \
292 solar 1.28 if (*find_sym == '*') { \
293 vapier 1.32 printf("%s(%s) %5lX %15s %s\n", \
294     ((found_sym == 0) ? "\n\t" : "\t"), \
295     (char *)basename(filename), \
296     (long)sym->st_size, \
297     (char *)get_elfstttype(sym->st_info), \
298     symname); \
299     found_sym = 1; \
300     } else if ((strcmp(find_sym, symname) == 0) || \
301     (strncmp(symname, versioned_symname, len) == 0)) \
302 solar 1.28 found_sym++; \
303 vapier 1.27 } \
304     ++sym; \
305     } }
306     FIND_SYM(32)
307     FIND_SYM(64)
308     }
309 solar 1.28 free(versioned_symname);
310 vapier 1.29 if (*find_sym != '*') {
311     if (found_sym)
312     printf(" %s ", find_sym);
313     else if (!be_quiet)
314 solar 1.33 fputs(" - ", stdout);
315 vapier 1.29 }
316 vapier 1.27 }
317 vapier 1.10
318 vapier 1.32 if (!be_quiet || found_pax || found_stack || found_textrel || \
319     found_rpath || found_needed || found_sym)
320 solar 1.33 puts(filename);
321 solar 1.28
322 vapier 1.10 unreadelf(elf);
323 solar 1.6 }
324    
325 solar 1.1 /* scan a directory for ET_EXEC files and print when we find one */
326 vapier 1.10 static void scanelf_dir(const char *path)
327 solar 1.1 {
328 vapier 1.10 register DIR *dir;
329     register struct dirent *dentry;
330 vapier 1.14 struct stat st_top, st;
331 solar 1.21 char buf[_POSIX_PATH_MAX];
332 vapier 1.32 size_t pathlen = 0, len = 0;
333 vapier 1.10
334     /* make sure path exists */
335 vapier 1.14 if (lstat(path, &st_top) == -1)
336 vapier 1.10 return;
337 solar 1.11
338 vapier 1.10 /* ok, if it isn't a directory, assume we can open it */
339 vapier 1.14 if (!S_ISDIR(st_top.st_mode)) {
340 vapier 1.10 scanelf_file(path);
341     return;
342     }
343    
344     /* now scan the dir looking for fun stuff */
345     if ((dir = opendir(path)) == NULL) {
346     warnf("could not opendir %s: %s", path, strerror(errno));
347     return;
348     }
349 vapier 1.15 if (be_verbose) printf("%s: scanning dir\n", path);
350 solar 1.11
351 vapier 1.32 pathlen = strlen(path);
352 vapier 1.10 while ((dentry = readdir(dir))) {
353     if (!strcmp(dentry->d_name, ".") || !strcmp(dentry->d_name, ".."))
354     continue;
355 vapier 1.32 len = (pathlen + 1 + strlen(dentry->d_name) + 1);
356     if (len >= sizeof(buf)) {
357     warnf("Skipping '%s': len > sizeof(buf); %d > %d\n", path, (int)len, (int)sizeof(buf));
358     continue;
359     }
360 solar 1.31 sprintf(buf, "%s/%s", path, dentry->d_name);
361 solar 1.20 if (lstat(buf, &st) != -1) {
362 vapier 1.10 if (S_ISREG(st.st_mode))
363 solar 1.20 scanelf_file(buf);
364 vapier 1.10 else if (dir_recurse && S_ISDIR(st.st_mode)) {
365 vapier 1.14 if (dir_crossmount || (st_top.st_dev == st.st_dev))
366 solar 1.20 scanelf_dir(buf);
367 vapier 1.10 }
368     }
369     }
370     closedir(dir);
371 solar 1.1 }
372    
373 vapier 1.10 /* scan /etc/ld.so.conf for paths */
374     static void scanelf_ldpath()
375     {
376 vapier 1.17 char scan_l, scan_ul, scan_ull;
377 vapier 1.10 char *path, *p;
378     FILE *fp;
379    
380     if ((fp = fopen("/etc/ld.so.conf", "r")) == NULL)
381     err("Unable to open ld.so.conf: %s", strerror(errno));
382    
383 vapier 1.17 scan_l = scan_ul = scan_ull = 0;
384    
385 solar 1.30 if ((path = malloc(_POSIX_PATH_MAX)) == NULL) {
386     warn("Can not malloc() memory for ldpath scanning");
387     return;
388     }
389 vapier 1.10 while ((fgets(path, _POSIX_PATH_MAX, fp)) != NULL)
390     if (*path == '/') {
391     if ((p = strrchr(path, '\r')) != NULL)
392     *p = 0;
393     if ((p = strrchr(path, '\n')) != NULL)
394     *p = 0;
395 vapier 1.17 if (!scan_l && !strcmp(path, "/lib")) scan_l = 1;
396     if (!scan_ul && !strcmp(path, "/usr/lib")) scan_ul = 1;
397     if (!scan_ull && !strcmp(path, "/usr/local/lib")) scan_ull = 1;
398 vapier 1.10 scanelf_dir(path);
399     }
400     free(path);
401 vapier 1.32 fclose(fp);
402 vapier 1.10
403 vapier 1.17 if (!scan_l) scanelf_dir("/lib");
404     if (!scan_ul) scanelf_dir("/usr/lib");
405     if (!scan_ull) scanelf_dir("/usr/local/lib");
406 vapier 1.10 }
407 solar 1.1
408 vapier 1.10 /* scan env PATH for paths */
409     static void scanelf_envpath()
410 solar 1.1 {
411 solar 1.33 char *orig_path, *path, *p;
412 vapier 1.10
413     path = getenv("PATH");
414     if (!path)
415     err("PATH is not set in your env !");
416    
417 solar 1.33 if ((orig_path = path = strdup(path)) == NULL)
418 vapier 1.32 err("strdup failed: %s", strerror(errno));
419 vapier 1.10
420     while ((p = strrchr(path, ':')) != NULL) {
421     scanelf_dir(p + 1);
422     *p = 0;
423     }
424 vapier 1.17
425 solar 1.33 free(orig_path);
426 solar 1.1 }
427    
428    
429 vapier 1.10
430     /* usage / invocation handling functions */
431 vapier 1.32 #define PARSE_FLAGS "plRmxetrns:aqvo:BhV"
432 vapier 1.27 #define a_argument required_argument
433 vapier 1.10 static struct option const long_opts[] = {
434     {"path", no_argument, NULL, 'p'},
435     {"ldpath", no_argument, NULL, 'l'},
436     {"recursive", no_argument, NULL, 'R'},
437 vapier 1.14 {"mount", no_argument, NULL, 'm'},
438 vapier 1.10 {"pax", no_argument, NULL, 'x'},
439 solar 1.16 {"header", no_argument, NULL, 'e'},
440 vapier 1.10 {"textrel", no_argument, NULL, 't'},
441     {"rpath", no_argument, NULL, 'r'},
442 vapier 1.32 {"needed", no_argument, NULL, 'n'},
443 vapier 1.27 {"symbol", a_argument, NULL, 's'},
444 vapier 1.10 {"all", no_argument, NULL, 'a'},
445     {"quiet", no_argument, NULL, 'q'},
446 vapier 1.14 {"verbose", no_argument, NULL, 'v'},
447 vapier 1.27 {"file", a_argument, NULL, 'o'},
448 solar 1.16 {"nobanner", no_argument, NULL, 'B'},
449 vapier 1.10 {"help", no_argument, NULL, 'h'},
450     {"version", no_argument, NULL, 'V'},
451     {NULL, no_argument, NULL, 0x0}
452     };
453     static char *opts_help[] = {
454     "Scan all directories in PATH environment",
455     "Scan all directories in /etc/ld.so.conf",
456 vapier 1.14 "Scan directories recursively",
457     "Don't recursively cross mount points\n",
458 vapier 1.10 "Print PaX markings",
459     "Print GNU_STACK markings",
460     "Print TEXTREL information",
461     "Print RPATH information",
462 vapier 1.32 "Print NEEDED information",
463 vapier 1.27 "Find a specified symbol",
464 solar 1.16 "Print all scanned info (-x -e -t -r)\n",
465 vapier 1.14 "Only output 'bad' things",
466     "Be verbose (can be specified more than once)",
467 vapier 1.24 "Write output stream to a filename",
468 vapier 1.14 "Don't display the header",
469 vapier 1.10 "Print this help and exit",
470     "Print version and exit",
471     NULL
472     };
473    
474     /* display usage and exit */
475     static void usage(int status)
476 solar 1.1 {
477 vapier 1.10 int i;
478 vapier 1.27 printf(" Scan ELF binaries for stuff\n"
479 vapier 1.10 "Usage: %s [options] <dir1> [dir2 dirN ...]\n\n", argv0);
480 vapier 1.23 printf("Options:\n");
481 vapier 1.10 for (i = 0; long_opts[i].name; ++i)
482 vapier 1.27 if (long_opts[i].has_arg == no_argument)
483     printf(" -%c, --%-13s %s\n", long_opts[i].val,
484     long_opts[i].name, opts_help[i]);
485     else
486     printf(" -%c, --%-6s <arg> %s\n", long_opts[i].val,
487     long_opts[i].name, opts_help[i]);
488 vapier 1.10 exit(status);
489 solar 1.1 }
490    
491     /* parse command line arguments and preform needed actions */
492 vapier 1.10 static void parseargs(int argc, char *argv[])
493     {
494     int flag;
495    
496     opterr = 0;
497     while ((flag=getopt_long(argc, argv, PARSE_FLAGS, long_opts, NULL)) != -1) {
498     switch (flag) {
499    
500     case 'V': /* version info */
501 solar 1.19 printf("%s compiled %s\n%s\n"
502     "%s written for Gentoo Linux by <solar and vapier @ gentoo.org>\n",
503     __FILE__, __DATE__, rcsid, argv0);
504 vapier 1.10 exit(EXIT_SUCCESS);
505     break;
506     case 'h': usage(EXIT_SUCCESS); break;
507    
508 vapier 1.24 case 'o': {
509 solar 1.21 FILE *fp = NULL;
510     fp = freopen(optarg, "w", stdout);
511 vapier 1.24 if (fp == NULL)
512     err("Could not open output stream '%s': %s", optarg, strerror(errno));
513     stdout = fp;
514 solar 1.21 break;
515     }
516 vapier 1.24
517 vapier 1.27 case 's': find_sym = strdup(optarg); break;
518    
519 solar 1.16 case 'B': show_banner = 0; break;
520 vapier 1.10 case 'l': scan_ldpath = 1; break;
521     case 'p': scan_envpath = 1; break;
522     case 'R': dir_recurse = 1; break;
523 vapier 1.14 case 'm': dir_crossmount = 0; break;
524 vapier 1.10 case 'x': show_pax = 1; break;
525 solar 1.16 case 'e': show_stack = 1; break;
526 vapier 1.10 case 't': show_textrel = 1; break;
527     case 'r': show_rpath = 1; break;
528 vapier 1.32 case 'n': show_needed = 1; break;
529 vapier 1.10 case 'q': be_quiet = 1; break;
530 vapier 1.14 case 'v': be_verbose = (be_verbose % 20) + 1; break;
531 vapier 1.32 case 'a': show_pax = show_stack = show_textrel = show_needed = show_rpath = 1; break;
532 vapier 1.10
533     case ':':
534     warn("Option missing parameter");
535     usage(EXIT_FAILURE);
536     break;
537     case '?':
538     warn("Unknown option");
539     usage(EXIT_FAILURE);
540     break;
541     default:
542     err("Unhandled option '%c'", flag);
543     break;
544     }
545     }
546    
547 vapier 1.14 if (be_quiet && be_verbose)
548     err("You can be quiet or you can be verbose, not both, stupid");
549    
550 vapier 1.10 if (scan_ldpath) scanelf_ldpath();
551     if (scan_envpath) scanelf_envpath();
552 vapier 1.25 if (optind == argc && !scan_ldpath && !scan_envpath)
553     err("Nothing to scan !?");
554 vapier 1.10 while (optind < argc)
555     scanelf_dir(argv[optind++]);
556 vapier 1.27
557     if (find_sym) free(find_sym);
558 vapier 1.10 }
559    
560    
561    
562     int main(int argc, char *argv[])
563 solar 1.1 {
564 vapier 1.10 if (argc < 2)
565     usage(EXIT_FAILURE);
566     parseargs(argc, argv);
567 solar 1.21 fclose(stdout);
568 vapier 1.10 return EXIT_SUCCESS;
569 solar 1.1 }

  ViewVC Help
Powered by ViewVC 1.1.20