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

Diff of /pax-utils/scanelf.c

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

Revision 1.35 Revision 1.37
1/* 1/*
2 * Copyright 2003 Ned Ludd <solar@gentoo.org> 2 * Copyright 2003 Ned Ludd <solar@gentoo.org>
3 * Copyright 1999-2005 Gentoo Foundation 3 * Copyright 1999-2005 Gentoo Foundation
4 * Distributed under the terms of the GNU General Public License v2 4 * Distributed under the terms of the GNU General Public License v2
5 * $Header: /var/cvsroot/gentoo-projects/pax-utils/Attic/scanelf.c,v 1.35 2005/04/14 00:17:30 solar Exp $ 5 * $Header: /var/cvsroot/gentoo-projects/pax-utils/Attic/scanelf.c,v 1.37 2005/04/16 06:34:39 vapier Exp $
6 * 6 *
7 ******************************************************************** 7 ********************************************************************
8 * This program is free software; you can redistribute it and/or 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 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 10 * published by the Free Software Foundation; either version 2 of the
33#include <getopt.h> 33#include <getopt.h>
34#include <assert.h> 34#include <assert.h>
35 35
36#include "paxelf.h" 36#include "paxelf.h"
37 37
38static const char *rcsid = "$Id: scanelf.c,v 1.35 2005/04/14 00:17:30 solar Exp $"; 38static const char *rcsid = "$Id: scanelf.c,v 1.37 2005/04/16 06:34:39 vapier Exp $";
39 39#define argv0 "scanelf"
40
41/* helper functions for showing errors */
42#define argv0 "scanelf" /*((*argv != NULL) ? argv[0] : __FILE__ "\b\b")*/
43#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 40
52 41
53 42
54/* prototypes */ 43/* prototypes */
55static void scanelf_file(const char *filename); 44static void scanelf_file(const char *filename);
60static void parseargs(int argc, char *argv[]); 49static void parseargs(int argc, char *argv[]);
61 50
62/* variables to control behavior */ 51/* variables to control behavior */
63static char scan_ldpath = 0; 52static char scan_ldpath = 0;
64static char scan_envpath = 0; 53static char scan_envpath = 0;
54static char scan_symlink = 1;
65static char dir_recurse = 0; 55static char dir_recurse = 0;
66static char dir_crossmount = 1; 56static char dir_crossmount = 1;
67static char show_pax = 0; 57static char show_pax = 0;
68static char show_stack = 0; 58static char show_stack = 0;
69static char show_textrel = 0; 59static char show_textrel = 0;
83 char found_pax, found_stack, found_relro, found_textrel, 73 char found_pax, found_stack, found_relro, found_textrel,
84 found_rpath, found_needed, found_sym; 74 found_rpath, found_needed, found_sym;
85 elfobj *elf; 75 elfobj *elf;
86 struct stat st; 76 struct stat st;
87 77
88 /* make sure path exists */ 78 /* make sure 'filename' exists */
89 if (lstat(filename, &st) == -1) 79 if (lstat(filename, &st) == -1)
90 return; 80 return;
91 if (!S_ISREG(st.st_mode)) 81 /* always handle regular files and handle symlinked files if no -y */
82 if (!(S_ISREG(st.st_mode) || (S_ISLNK(st.st_mode) && scan_symlink)))
92 return; 83 return;
84
93 found_pax = found_stack = found_relro = found_textrel = \ 85 found_pax = found_stack = found_relro = found_textrel = \
94 found_rpath = found_needed = found_sym = 0; 86 found_rpath = found_needed = found_sym = 0;
95 87
96 /* verify this is real ELF */ 88 /* verify this is real ELF */
97 if ((elf = readelf(filename)) == NULL) { 89 if ((elf = readelf(filename)) == NULL) {
426} 418}
427 419
428 420
429 421
430/* usage / invocation handling functions */ 422/* usage / invocation handling functions */
431#define PARSE_FLAGS "plRmxetrns:aqvo:BhV" 423#define PARSE_FLAGS "plRmyxetrns:aqvo:BhV"
432#define a_argument required_argument 424#define a_argument required_argument
433static struct option const long_opts[] = { 425static struct option const long_opts[] = {
434 {"path", no_argument, NULL, 'p'}, 426 {"path", no_argument, NULL, 'p'},
435 {"ldpath", no_argument, NULL, 'l'}, 427 {"ldpath", no_argument, NULL, 'l'},
436 {"recursive", no_argument, NULL, 'R'}, 428 {"recursive", no_argument, NULL, 'R'},
437 {"mount", no_argument, NULL, 'm'}, 429 {"mount", no_argument, NULL, 'm'},
430 {"symlink", no_argument, NULL, 'y'},
438 {"pax", no_argument, NULL, 'x'}, 431 {"pax", no_argument, NULL, 'x'},
439 {"header", no_argument, NULL, 'e'}, 432 {"header", no_argument, NULL, 'e'},
440 {"textrel", no_argument, NULL, 't'}, 433 {"textrel", no_argument, NULL, 't'},
441 {"rpath", no_argument, NULL, 'r'}, 434 {"rpath", no_argument, NULL, 'r'},
442 {"needed", no_argument, NULL, 'n'}, 435 {"needed", no_argument, NULL, 'n'},
452}; 445};
453static char *opts_help[] = { 446static char *opts_help[] = {
454 "Scan all directories in PATH environment", 447 "Scan all directories in PATH environment",
455 "Scan all directories in /etc/ld.so.conf", 448 "Scan all directories in /etc/ld.so.conf",
456 "Scan directories recursively", 449 "Scan directories recursively",
457 "Don't recursively cross mount points\n", 450 "Don't recursively cross mount points",
451 "Don't scan symlinks\n",
458 "Print PaX markings", 452 "Print PaX markings",
459 "Print GNU_STACK markings", 453 "Print GNU_STACK markings",
460 "Print TEXTREL information", 454 "Print TEXTREL information",
461 "Print RPATH information", 455 "Print RPATH information",
462 "Print NEEDED information", 456 "Print NEEDED information",
473 467
474/* display usage and exit */ 468/* display usage and exit */
475static void usage(int status) 469static void usage(int status)
476{ 470{
477 int i; 471 int i;
478 printf(" Scan ELF binaries for stuff\n" 472 printf(" Scan ELF binaries for stuff\n\n"
479 "Usage: %s [options] <dir1/file1> [dir2 dirN fileN ...]\n\n", argv0); 473 "Usage: %s [options] <dir1/file1> [dir2 dirN fileN ...]\n\n", argv0);
480 printf("Options: -[%s]\n", PARSE_FLAGS); 474 printf("Options: -[%s]\n", PARSE_FLAGS);
481 for (i = 0; long_opts[i].name; ++i) 475 for (i = 0; long_opts[i].name; ++i)
482 if (long_opts[i].has_arg == no_argument) 476 if (long_opts[i].has_arg == no_argument)
483 printf(" -%c, --%-13s %s\n", long_opts[i].val, 477 printf(" -%c, --%-13s %s\n", long_opts[i].val,
514 break; 508 break;
515 } 509 }
516 510
517 case 's': find_sym = strdup(optarg); break; 511 case 's': find_sym = strdup(optarg); break;
518 512
513 case 'y': scan_symlink = 0; break;
519 case 'B': show_banner = 0; break; 514 case 'B': show_banner = 0; break;
520 case 'l': scan_ldpath = 1; break; 515 case 'l': scan_ldpath = 1; break;
521 case 'p': scan_envpath = 1; break; 516 case 'p': scan_envpath = 1; break;
522 case 'R': dir_recurse = 1; break; 517 case 'R': dir_recurse = 1; break;
523 case 'm': dir_crossmount = 0; break; 518 case 'm': dir_crossmount = 0; break;

Legend:
Removed from v.1.35  
changed lines
  Added in v.1.37

  ViewVC Help
Powered by ViewVC 1.1.20