/[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.222 Revision 1.223
1/* 1/*
2 * Copyright 2003-2007 Gentoo Foundation 2 * Copyright 2003-2007 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.222 2010/12/08 01:24:01 vapier Exp $ 4 * $Header: /var/cvsroot/gentoo-projects/pax-utils/scanelf.c,v 1.223 2011/07/30 17:08:30 solar Exp $
5 * 5 *
6 * Copyright 2003-2007 Ned Ludd - <solar@gentoo.org> 6 * Copyright 2003-2007 Ned Ludd - <solar@gentoo.org>
7 * Copyright 2004-2007 Mike Frysinger - <vapier@gentoo.org> 7 * Copyright 2004-2007 Mike Frysinger - <vapier@gentoo.org>
8 */ 8 */
9 9
10static const char *rcsid = "$Id: scanelf.c,v 1.222 2010/12/08 01:24:01 vapier Exp $"; 10static const char *rcsid = "$Id: scanelf.c,v 1.223 2011/07/30 17:08:30 solar Exp $";
11const char argv0[] = "scanelf"; 11const char argv0[] = "scanelf";
12 12
13#include "paxinc.h" 13#include "paxinc.h"
14 14
15#define IS_MODIFIER(c) (c == '%' || c == '#' || c == '+') 15#define IS_MODIFIER(c) (c == '%' || c == '#' || c == '+')
66static char use_ldcache = 0; 66static char use_ldcache = 0;
67 67
68static char **qa_textrels = NULL; 68static char **qa_textrels = NULL;
69static char **qa_execstack = NULL; 69static char **qa_execstack = NULL;
70static char **qa_wx_load = NULL; 70static char **qa_wx_load = NULL;
71static char *root;
71 72
72static int match_bits = 0; 73static int match_bits = 0;
73static unsigned int match_perms = 0; 74static unsigned int match_perms = 0;
74static void *ldcache = NULL; 75static void *ldcache = NULL;
75static size_t ldcache_size = 0; 76static size_t ldcache_size = 0;
1495 1496
1496 close(fd); 1497 close(fd);
1497 return 0; 1498 return 0;
1498} 1499}
1499 1500
1501static const char* maybe_add_root(const char* fname, char* buf)
1502{
1503 if (root && strncmp(fname, root, strlen(root))) {
1504 strcpy(buf, root);
1505 strncat(buf, fname, __PAX_UTILS_PATH_MAX-strlen(root)-1);
1506 fname = buf;
1507 }
1508 return fname;
1509}
1510
1500/* scan a directory for ET_EXEC files and print when we find one */ 1511/* scan a directory for ET_EXEC files and print when we find one */
1501static int scanelf_dir(const char *path) 1512static int scanelf_dir(const char *path)
1502{ 1513{
1503 register DIR *dir; 1514 register DIR *dir;
1504 register struct dirent *dentry; 1515 register struct dirent *dentry;
1505 struct stat st_top, st; 1516 struct stat st_top, st;
1506 char buf[__PAX_UTILS_PATH_MAX]; 1517 char buf[__PAX_UTILS_PATH_MAX];
1518 char _path[__PAX_UTILS_PATH_MAX];
1507 size_t pathlen = 0, len = 0; 1519 size_t pathlen = 0, len = 0;
1508 int ret = 0; 1520 int ret = 0;
1521
1522 path = maybe_add_root(path, _path);
1509 1523
1510 /* make sure path exists */ 1524 /* make sure path exists */
1511 if (lstat(path, &st_top) == -1) { 1525 if (lstat(path, &st_top) == -1) {
1512 if (be_verbose > 2) printf("%s: does not exist\n", path); 1526 if (be_verbose > 2) printf("%s: does not exist\n", path);
1513 return 1; 1527 return 1;
1577static int load_ld_cache_config(int i, const char *fname) 1591static int load_ld_cache_config(int i, const char *fname)
1578{ 1592{
1579 FILE *fp = NULL; 1593 FILE *fp = NULL;
1580 char *p; 1594 char *p;
1581 char path[__PAX_UTILS_PATH_MAX]; 1595 char path[__PAX_UTILS_PATH_MAX];
1596 char _fname[__PAX_UTILS_PATH_MAX];
1597
1598 fname = maybe_add_root(fname, _fname);
1582 1599
1583 if (i + 1 == ARRAY_SIZE(ldpaths)) 1600 if (i + 1 == ARRAY_SIZE(ldpaths))
1584 return i; 1601 return i;
1585 1602
1586 if ((fp = fopen(fname, "r")) == NULL) 1603 if ((fp = fopen(fname, "r")) == NULL)
1597 glob_t gl; 1614 glob_t gl;
1598 size_t x; 1615 size_t x;
1599 char gpath[__PAX_UTILS_PATH_MAX]; 1616 char gpath[__PAX_UTILS_PATH_MAX];
1600 1617
1601 memset(gpath, 0, sizeof(gpath)); 1618 memset(gpath, 0, sizeof(gpath));
1619 if (root)
1620 strcpy(gpath, root);
1602 1621
1603 if (path[8] != '/') 1622 if (path[8] != '/')
1604 snprintf(gpath, sizeof(gpath), "/etc/%s", &path[8]); 1623 snprintf(gpath+strlen(gpath), sizeof(gpath)-strlen(gpath), "/etc/%s", &path[8]);
1605 else 1624 else
1606 strncpy(gpath, &path[8], sizeof(gpath)); 1625 strncpy(gpath+strlen(gpath), &path[8], sizeof(gpath)-strlen(gpath));
1607 1626
1608 if (glob(gpath, 0, NULL, &gl) == 0) { 1627 if (glob(gpath, 0, NULL, &gl) == 0) {
1609 for (x = 0; x < gl.gl_pathc; ++x) { 1628 for (x = 0; x < gl.gl_pathc; ++x) {
1610 /* try to avoid direct loops */ 1629 /* try to avoid direct loops */
1611 if (strcmp(gl.gl_pathv[x], fname) == 0) 1630 if (strcmp(gl.gl_pathv[x], fname) == 0)
1640static int load_ld_cache_config(int i, const char *fname) 1659static int load_ld_cache_config(int i, const char *fname)
1641{ 1660{
1642 FILE *fp = NULL; 1661 FILE *fp = NULL;
1643 char *b = NULL, *p; 1662 char *b = NULL, *p;
1644 struct elfhints_hdr hdr; 1663 struct elfhints_hdr hdr;
1664 char _fname[__PAX_UTILS_PATH_MAX];
1665
1666 fname = maybe_add_root(fname, _fname);
1645 1667
1646 if (i + 1 == ARRAY_SIZE(ldpaths)) 1668 if (i + 1 == ARRAY_SIZE(ldpaths))
1647 return i; 1669 return i;
1648 1670
1649 if ((fp = fopen(fname, "r")) == NULL) 1671 if ((fp = fopen(fname, "r")) == NULL)
1735#define PARSE_FLAGS "plRmyAXz:xetrnLibSs:k:gN:TaqvF:f:o:E:M:DIYO:ZCBhV" 1757#define PARSE_FLAGS "plRmyAXz:xetrnLibSs:k:gN:TaqvF:f:o:E:M:DIYO:ZCBhV"
1736#define a_argument required_argument 1758#define a_argument required_argument
1737static struct option const long_opts[] = { 1759static struct option const long_opts[] = {
1738 {"path", no_argument, NULL, 'p'}, 1760 {"path", no_argument, NULL, 'p'},
1739 {"ldpath", no_argument, NULL, 'l'}, 1761 {"ldpath", no_argument, NULL, 'l'},
1762 {"root", a_argument, NULL, 128},
1740 {"recursive", no_argument, NULL, 'R'}, 1763 {"recursive", no_argument, NULL, 'R'},
1741 {"mount", no_argument, NULL, 'm'}, 1764 {"mount", no_argument, NULL, 'm'},
1742 {"symlink", no_argument, NULL, 'y'}, 1765 {"symlink", no_argument, NULL, 'y'},
1743 {"archives", no_argument, NULL, 'A'}, 1766 {"archives", no_argument, NULL, 'A'},
1744 {"ldcache", no_argument, NULL, 'L'}, 1767 {"ldcache", no_argument, NULL, 'L'},
1778}; 1801};
1779 1802
1780static const char * const opts_help[] = { 1803static const char * const opts_help[] = {
1781 "Scan all directories in PATH environment", 1804 "Scan all directories in PATH environment",
1782 "Scan all directories in /etc/ld.so.conf", 1805 "Scan all directories in /etc/ld.so.conf",
1806 "Root directory (use with -l or -p)",
1783 "Scan directories recursively", 1807 "Scan directories recursively",
1784 "Don't recursively cross mount points", 1808 "Don't recursively cross mount points",
1785 "Don't scan symlinks", 1809 "Don't scan symlinks",
1786 "Scan archives (.a files)", 1810 "Scan archives (.a files)",
1787 "Utilize ld.so.cache information (use with -r/-n)", 1811 "Utilize ld.so.cache information (use with -r/-n)",
1829 printf("Options: -[%s]\n", PARSE_FLAGS); 1853 printf("Options: -[%s]\n", PARSE_FLAGS);
1830 for (i = 0; long_opts[i].name; ++i) 1854 for (i = 0; long_opts[i].name; ++i)
1831 if (long_opts[i].has_arg == no_argument) 1855 if (long_opts[i].has_arg == no_argument)
1832 printf(" -%c, --%-14s* %s\n", long_opts[i].val, 1856 printf(" -%c, --%-14s* %s\n", long_opts[i].val,
1833 long_opts[i].name, opts_help[i]); 1857 long_opts[i].name, opts_help[i]);
1858 else if (long_opts[i].val > '~')
1859 printf(" --%-7s <arg> * %s\n",
1860 long_opts[i].name, opts_help[i]);
1834 else 1861 else
1835 printf(" -%c, --%-7s <arg> * %s\n", long_opts[i].val, 1862 printf(" -%c, --%-7s <arg> * %s\n", long_opts[i].val,
1836 long_opts[i].name, opts_help[i]); 1863 long_opts[i].name, opts_help[i]);
1837 1864
1838 puts("\nFor more information, see the scanelf(1) manpage"); 1865 puts("\nFor more information, see the scanelf(1) manpage");
1978 case 'v': be_verbose = (be_verbose % 20) + 1; break; 2005 case 'v': be_verbose = (be_verbose % 20) + 1; break;
1979 case 'a': show_perms = show_pax = show_phdr = show_textrel = show_rpath = show_bind = show_endian = 1; break; 2006 case 'a': show_perms = show_pax = show_phdr = show_textrel = show_rpath = show_bind = show_endian = 1; break;
1980 case 'D': show_endian = 1; break; 2007 case 'D': show_endian = 1; break;
1981 case 'I': show_osabi = 1; break; 2008 case 'I': show_osabi = 1; break;
1982 case 'Y': show_eabi = 1; break; 2009 case 'Y': show_eabi = 1; break;
2010 case 128:
2011 root = optarg;
2012 break;
1983 case ':': 2013 case ':':
1984 err("Option '%c' is missing parameter", optopt); 2014 err("Option '%c' is missing parameter", optopt);
1985 case '?': 2015 case '?':
1986 err("Unknown option '%c' or argument missing", optopt); 2016 err("Unknown option '%c' or argument missing", optopt);
1987 default: 2017 default:

Legend:
Removed from v.1.222  
changed lines
  Added in v.1.223

  ViewVC Help
Powered by ViewVC 1.1.20