/[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.147 Revision 1.148
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.147 2006/05/14 21:07:39 vapier Exp $ 4 * $Header: /var/cvsroot/gentoo-projects/pax-utils/scanelf.c,v 1.148 2006/05/14 21:18:38 vapier 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.147 2006/05/14 21:07:39 vapier Exp $"; 12static const char *rcsid = "$Id: scanelf.c,v 1.148 2006/05/14 21:18:38 vapier Exp $";
13#define argv0 "scanelf" 13#define argv0 "scanelf"
14 14
15#define IS_MODIFIER(c) (c == '%' || c == '#' || c == '+') 15#define IS_MODIFIER(c) (c == '%' || c == '#' || c == '+')
16 16
17#define do_state(option, flag) \ 17#define do_state(option, flag) \
674#define FLAG_POWERPC_LIB64 0x0500 674#define FLAG_POWERPC_LIB64 0x0500
675#define FLAG_MIPS64_LIBN32 0x0600 675#define FLAG_MIPS64_LIBN32 0x0600
676#define FLAG_MIPS64_LIBN64 0x0700 676#define FLAG_MIPS64_LIBN64 0x0700
677 677
678static char *lookup_cache_lib(elfobj *, char *); 678static char *lookup_cache_lib(elfobj *, char *);
679
679#if defined(__GLIBC__) || defined(__UCLIBC__) 680#if defined(__GLIBC__) || defined(__UCLIBC__)
681
680static char *lookup_cache_lib(elfobj *elf, char *fname) 682static char *lookup_cache_lib(elfobj *elf, char *fname)
681{ 683{
682 int fd = 0; 684 int fd = 0;
683 char *strs; 685 char *strs;
684 static char buf[__PAX_UTILS_PATH_MAX] = ""; 686 static char buf[__PAX_UTILS_PATH_MAX] = "";
740 continue; 742 continue;
741 strncpy(buf, strs + libent[fd].liboffset, sizeof(buf)); 743 strncpy(buf, strs + libent[fd].liboffset, sizeof(buf));
742 } 744 }
743 return buf; 745 return buf;
744} 746}
747
745#else 748#else
746#warning Cache support not implemented for your current target. 749#warning Cache support not implemented for your target
747static char *lookup_cache_lib(elfobj *elf, char *fname) 750static char *lookup_cache_lib(elfobj *elf, char *fname)
748{ 751{
749 return NULL; 752 return NULL;
750} 753}
751#endif 754#endif
1363 fclose(fp); 1366 fclose(fp);
1364 return 0; 1367 return 0;
1365} 1368}
1366 1369
1367#if defined(__GLIBC__) || defined(__UCLIBC__) 1370#if defined(__GLIBC__) || defined(__UCLIBC__)
1371
1368static int load_ld_so_conf(int i, const char *fname) 1372static int load_ld_cache_config(int i, const char *fname)
1369{ 1373{
1370 FILE *fp = NULL; 1374 FILE *fp = NULL;
1371 char *p; 1375 char *p;
1372 char path[__PAX_UTILS_PATH_MAX]; 1376 char path[__PAX_UTILS_PATH_MAX];
1373 1377
1398 if ((glob64(gpath, 0, NULL, &gl)) == 0) { 1402 if ((glob64(gpath, 0, NULL, &gl)) == 0) {
1399 for (x = 0; x < gl.gl_pathc; ++x) { 1403 for (x = 0; x < gl.gl_pathc; ++x) {
1400 /* try to avoid direct loops */ 1404 /* try to avoid direct loops */
1401 if (strcmp(gl.gl_pathv[x], fname) == 0) 1405 if (strcmp(gl.gl_pathv[x], fname) == 0)
1402 continue; 1406 continue;
1403 i = load_ld_so_conf(i, gl.gl_pathv[x]); 1407 i = load_ld_cache_config(i, gl.gl_pathv[x]);
1404 if (i + 1 >= sizeof(ldpaths) / sizeof(*ldpaths)) { 1408 if (i + 1 >= sizeof(ldpaths) / sizeof(*ldpaths)) {
1405 globfree64(&gl); 1409 globfree64(&gl);
1406 return i; 1410 return i;
1407 } 1411 }
1408 } 1412 }
1422 ldpaths[i] = NULL; 1426 ldpaths[i] = NULL;
1423 1427
1424 fclose(fp); 1428 fclose(fp);
1425 return i; 1429 return i;
1426} 1430}
1427#endif
1428 1431
1429#if defined(__FreeBSD__) || (__DragonFly__) 1432#elif defined(__FreeBSD__) || (__DragonFly__)
1433
1430static int load_ld_so_hints(int i, const char *fname) 1434static int load_ld_cache_config(int i, const char *fname)
1431{ 1435{
1432 FILE *fp = NULL; 1436 FILE *fp = NULL;
1433 char *b = NULL, *p; 1437 char *b = NULL, *p;
1434 struct elfhints_hdr hdr; 1438 struct elfhints_hdr hdr;
1435 1439
1465 1469
1466 free(b); 1470 free(b);
1467 fclose(fp); 1471 fclose(fp);
1468 return i; 1472 return i;
1469} 1473}
1474
1475#else
1476
1477#warning Cache config support not implemented for your target
1478static int load_ld_cache_config(int i, const char *fname)
1479{
1480 memset(ldpaths, 0x00, sizeof(ldpaths));
1481}
1482
1470#endif 1483#endif
1471 1484
1472/* scan /etc/ld.so.conf for paths */ 1485/* scan /etc/ld.so.conf for paths */
1473static void scanelf_ldpath() 1486static void scanelf_ldpath()
1474{ 1487{
1806 } 1819 }
1807 if (be_verbose > 2) printf("Format: %s\n", out_format); 1820 if (be_verbose > 2) printf("Format: %s\n", out_format);
1808 1821
1809 /* now lets actually do the scanning */ 1822 /* now lets actually do the scanning */
1810 if (scan_ldpath || use_ldcache) 1823 if (scan_ldpath || use_ldcache)
1811#if defined(__GLIBC__) || defined(__UCLIBC__) 1824 load_ld_cache_config(0, __PAX_UTILS_DEFAULT_LD_CACHE_CONFIG);
1812 load_ld_so_conf(0, "/etc/ld.so.conf");
1813#elif defined(__FreeBSD__) || defined(__DragonFly__)
1814 load_ld_so_hints(0, _PATH_ELF_HINTS);
1815#endif
1816 if (scan_ldpath) scanelf_ldpath(); 1825 if (scan_ldpath) scanelf_ldpath();
1817 if (scan_envpath) scanelf_envpath(); 1826 if (scan_envpath) scanelf_envpath();
1818 if (!from_file && optind == argc && ttyname(0) == NULL) 1827 if (!from_file && optind == argc && ttyname(0) == NULL)
1819 from_file = "-"; 1828 from_file = "-";
1820 if (from_file) { 1829 if (from_file) {

Legend:
Removed from v.1.147  
changed lines
  Added in v.1.148

  ViewVC Help
Powered by ViewVC 1.1.20