/[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.131 Revision 1.132
1/* 1/*
2 * Copyright 2003-2006 Gentoo Foundation 2 * Copyright 2003-2006 Gentoo Foundation
3 * Distributed under the terms of the GNU General Public License v2 3 * Distributed under the terms of the GNU General Public License v2
4 * $Header: /var/cvsroot/gentoo-projects/pax-utils/scanelf.c,v 1.131 2006/03/02 14:40:53 solar Exp $ 4 * $Header: /var/cvsroot/gentoo-projects/pax-utils/scanelf.c,v 1.132 2006/03/07 17:48:17 solar Exp $
5 * 5 *
6 * Copyright 2003-2006 Ned Ludd - <solar@gentoo.org> 6 * Copyright 2003-2006 Ned Ludd - <solar@gentoo.org>
7 * Copyright 2004-2006 Mike Frysinger - <vapier@gentoo.org> 7 * Copyright 2004-2006 Mike Frysinger - <vapier@gentoo.org>
8 */ 8 */
9 9
10#include "paxinc.h" 10#include "paxinc.h"
11 11
12static const char *rcsid = "$Id: scanelf.c,v 1.131 2006/03/02 14:40:53 solar Exp $"; 12static const char *rcsid = "$Id: scanelf.c,v 1.132 2006/03/07 17:48:17 solar Exp $";
13#define argv0 "scanelf" 13#define argv0 "scanelf"
14 14
15#define IS_MODIFIER(c) (c == '%' || c == '#') 15#define IS_MODIFIER(c) (c == '%' || c == '#' || c == '+')
16 16
17
18#define do_state(option, flag) \
19 if (islower(option)) { \
20 flags &= ~PF_##flag; \
21 flags |= PF_NO##flag; \
22 } else { \
23 flags &= ~PF_NO##flag; \
24 flags |= PF_##flag; \
25 }
17 26
18 27
19/* prototypes */ 28/* prototypes */
20static int scanelf_elfobj(elfobj *elf); 29static int scanelf_elfobj(elfobj *elf);
21static int scanelf_elf(const char *filename, int fd, size_t len); 30static int scanelf_elf(const char *filename, int fd, size_t len);
52static char show_textrels = 0; 61static char show_textrels = 0;
53static char show_banner = 1; 62static char show_banner = 1;
54static char be_quiet = 0; 63static char be_quiet = 0;
55static char be_verbose = 0; 64static char be_verbose = 0;
56static char be_wewy_wewy_quiet = 0; 65static char be_wewy_wewy_quiet = 0;
66static char be_semi_verbose = 0;
57static char *find_sym = NULL, *versioned_symname = NULL; 67static char *find_sym = NULL, *versioned_symname = NULL;
58static char *find_lib = NULL; 68static char *find_lib = NULL;
59static char *find_section = NULL; 69static char *find_section = NULL;
60static char *out_format = NULL; 70static char *out_format = NULL;
61static char *search_path = NULL; 71static char *search_path = NULL;
865 next_sym = strchr(this_sym, ','); \ 875 next_sym = strchr(this_sym, ','); \
866 if (next_sym == NULL) \ 876 if (next_sym == NULL) \
867 next_sym = this_sym + strlen(this_sym); \ 877 next_sym = this_sym + strlen(this_sym); \
868 if ((strncmp(this_sym, symname, (next_sym-this_sym)) == 0 && symname[next_sym-this_sym] == '\0') || \ 878 if ((strncmp(this_sym, symname, (next_sym-this_sym)) == 0 && symname[next_sym-this_sym] == '\0') || \
869 (strcmp(symname, versioned_symname) == 0)) { \ 879 (strcmp(symname, versioned_symname) == 0)) { \
880 if (be_semi_verbose) { \
881 char buf[126]; \
882 snprintf(buf, sizeof(buf), "%lX %s %s", \
883 (unsigned long)sym->st_size, get_elfstttype(sym->st_info), this_sym); \
884 ret = buf; \
885 } else \
870 ret = this_sym; \ 886 ret = this_sym; \
871 (*found_sym)++; \ 887 (*found_sym)++; \
872 goto break_out; \ 888 goto break_out; \
873 } \ 889 } \
874 this_sym = next_sym + 1; \ 890 this_sym = next_sym + 1; \
875 } while (*next_sym != '\0'); \ 891 } while (*next_sym != '\0'); \
953 if (!be_quiet && show_banner) { 969 if (!be_quiet && show_banner) {
954 for (i = 0; out_format[i]; ++i) { 970 for (i = 0; out_format[i]; ++i) {
955 if (!IS_MODIFIER(out_format[i])) continue; 971 if (!IS_MODIFIER(out_format[i])) continue;
956 972
957 switch (out_format[++i]) { 973 switch (out_format[++i]) {
974 case '+': break;
958 case '%': break; 975 case '%': break;
959 case '#': break; 976 case '#': break;
960 case 'F': 977 case 'F':
961 case 'p': 978 case 'p':
962 case 'f': prints("FILE "); found_file = 1; break; 979 case 'f': prints("FILE "); found_file = 1; break;
992 continue; 1009 continue;
993 } 1010 }
994 1011
995 out = NULL; 1012 out = NULL;
996 be_wewy_wewy_quiet = (out_format[i] == '#'); 1013 be_wewy_wewy_quiet = (out_format[i] == '#');
1014 be_semi_verbose = (out_format[i] == '+');
997 switch (out_format[++i]) { 1015 switch (out_format[++i]) {
1016 case '+':
998 case '%': 1017 case '%':
999 case '#': 1018 case '#':
1000 xchrcat(&out_buffer, out_format[i], &out_len); break; 1019 xchrcat(&out_buffer, out_format[i], &out_len); break;
1001 case 'F': 1020 case 'F':
1002 found_file = 1; 1021 found_file = 1;
1221{ 1240{
1222 FILE *fp = NULL; 1241 FILE *fp = NULL;
1223 char *p; 1242 char *p;
1224 char path[__PAX_UTILS_PATH_MAX]; 1243 char path[__PAX_UTILS_PATH_MAX];
1225 1244
1226 if (((strcmp(filename, "-")) == 0) && (ttyname(0) == NULL)) 1245 if (strcmp(filename, "-") == 0)
1227 fp = stdin; 1246 fp = stdin;
1228 else if ((fp = fopen(filename, "r")) == NULL) 1247 else if ((fp = fopen(filename, "r")) == NULL)
1229 return 1; 1248 return 1;
1230 1249
1231 while ((fgets(path, __PAX_UTILS_PATH_MAX, fp)) != NULL) { 1250 while ((fgets(path, __PAX_UTILS_PATH_MAX, fp)) != NULL) {
1512 } 1531 }
1513 case 'z': { 1532 case 'z': {
1514 unsigned long flags = (PF_NOEMUTRAMP | PF_NORANDEXEC); 1533 unsigned long flags = (PF_NOEMUTRAMP | PF_NORANDEXEC);
1515 size_t x; 1534 size_t x;
1516 1535
1517#define do_state(option, flag) \
1518 if (islower(option)) { \
1519 flags &= ~PF_##flag; \
1520 flags |= PF_NO##flag; \
1521 } else { \
1522 flags &= ~PF_NO##flag; \
1523 flags |= PF_##flag; \
1524 }
1525
1526 for (x = 0 ; x < strlen(optarg); x++) { 1536 for (x = 0 ; x < strlen(optarg); x++) {
1527 switch(optarg[x]) { 1537 switch(optarg[x]) {
1528 case 'p': 1538 case 'p':
1529 case 'P': 1539 case 'P':
1530 do_state(optarg[x], PAGEEXEC); 1540 do_state(optarg[x], PAGEEXEC);
1601 show_textrels = 0; 1611 show_textrels = 0;
1602 for (i = 0; out_format[i]; ++i) { 1612 for (i = 0; out_format[i]; ++i) {
1603 if (!IS_MODIFIER(out_format[i])) continue; 1613 if (!IS_MODIFIER(out_format[i])) continue;
1604 1614
1605 switch (out_format[++i]) { 1615 switch (out_format[++i]) {
1616 case '+': break;
1606 case '%': break; 1617 case '%': break;
1607 case '#': break; 1618 case '#': break;
1608 case 'F': break; 1619 case 'F': break;
1609 case 'p': break; 1620 case 'p': break;
1610 case 'f': break; 1621 case 'f': break;
1651 /* now lets actually do the scanning */ 1662 /* now lets actually do the scanning */
1652 if (scan_ldpath || use_ldcache) 1663 if (scan_ldpath || use_ldcache)
1653 load_ld_so_conf(0, "/etc/ld.so.conf"); 1664 load_ld_so_conf(0, "/etc/ld.so.conf");
1654 if (scan_ldpath) scanelf_ldpath(); 1665 if (scan_ldpath) scanelf_ldpath();
1655 if (scan_envpath) scanelf_envpath(); 1666 if (scan_envpath) scanelf_envpath();
1667 if (!from_file && ttyname(0) == NULL)
1668 from_file = (char *) "-";
1656 if (from_file) { 1669 if (from_file) {
1657 scanelf_from_file(from_file); 1670 scanelf_from_file(from_file);
1658 from_file = *argv; 1671 from_file = *argv;
1659 } 1672 }
1660 if (optind == argc && !scan_ldpath && !scan_envpath && !from_file) 1673 if (optind == argc && !scan_ldpath && !scan_envpath && !from_file)

Legend:
Removed from v.1.131  
changed lines
  Added in v.1.132

  ViewVC Help
Powered by ViewVC 1.1.20