/[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.140 Revision 1.141
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.140 2006/04/15 07:52:00 vapier Exp $ 4 * $Header: /var/cvsroot/gentoo-projects/pax-utils/scanelf.c,v 1.141 2006/04/23 15:24:38 flameeyes 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#ifdef __linux__ 11#if defined(__GLIBC__) || defined(__UCLIBC__)
12 #include <glob.h> 12 #include <glob.h>
13#endif 13#endif
14#if defined(__FreeBSD__) || defined(__DragonFly__)
15 #include <elf-hints.h>
16#endif
17
14static const char *rcsid = "$Id: scanelf.c,v 1.140 2006/04/15 07:52:00 vapier Exp $"; 18static const char *rcsid = "$Id: scanelf.c,v 1.141 2006/04/23 15:24:38 flameeyes Exp $";
15#define argv0 "scanelf" 19#define argv0 "scanelf"
16 20
17#define IS_MODIFIER(c) (c == '%' || c == '#' || c == '+') 21#define IS_MODIFIER(c) (c == '%' || c == '#' || c == '+')
18 22
19#define do_state(option, flag) \ 23#define do_state(option, flag) \
594#define FLAG_POWERPC_LIB64 0x0500 598#define FLAG_POWERPC_LIB64 0x0500
595#define FLAG_MIPS64_LIBN32 0x0600 599#define FLAG_MIPS64_LIBN32 0x0600
596#define FLAG_MIPS64_LIBN64 0x0700 600#define FLAG_MIPS64_LIBN64 0x0700
597 601
598static char *lookup_cache_lib(elfobj *, char *); 602static char *lookup_cache_lib(elfobj *, char *);
603#if defined(__GLIBC__) || defined(__UCLIBC__)
599static char *lookup_cache_lib(elfobj *elf, char *fname) 604static char *lookup_cache_lib(elfobj *elf, char *fname)
600{ 605{
601 int fd = 0; 606 int fd = 0;
602 char *strs; 607 char *strs;
603 static char buf[__PAX_UTILS_PATH_MAX] = ""; 608 static char buf[__PAX_UTILS_PATH_MAX] = "";
659 continue; 664 continue;
660 strncpy(buf, strs + libent[fd].liboffset, sizeof(buf)); 665 strncpy(buf, strs + libent[fd].liboffset, sizeof(buf));
661 } 666 }
662 return buf; 667 return buf;
663} 668}
664 669#else
670#warning Cache support not implemented for your current target.
671static char *lookup_cache_lib(elfobj *elf, char *fname)
672{
673 return NULL;
674}
675#endif
665 676
666static const char *scanelf_file_needed_lib(elfobj *elf, char *found_needed, char *found_lib, int op, char **ret, size_t *ret_len) 677static const char *scanelf_file_needed_lib(elfobj *elf, char *found_needed, char *found_lib, int op, char **ret, size_t *ret_len)
667{ 678{
668 unsigned long i; 679 unsigned long i;
669 char *needed; 680 char *needed;
1275 if (fp != stdin) 1286 if (fp != stdin)
1276 fclose(fp); 1287 fclose(fp);
1277 return 0; 1288 return 0;
1278} 1289}
1279 1290
1291#if defined(__GLIBC__) || defined(__UCLIBC__)
1280static int load_ld_so_conf(int i, const char *fname) 1292static int load_ld_so_conf(int i, const char *fname)
1281{ 1293{
1282 FILE *fp = NULL; 1294 FILE *fp = NULL;
1283 char *p; 1295 char *p;
1284 char path[__PAX_UTILS_PATH_MAX]; 1296 char path[__PAX_UTILS_PATH_MAX];
1292 while ((fgets(path, __PAX_UTILS_PATH_MAX, fp)) != NULL) { 1304 while ((fgets(path, __PAX_UTILS_PATH_MAX, fp)) != NULL) {
1293 if ((p = strrchr(path, '\r')) != NULL) 1305 if ((p = strrchr(path, '\r')) != NULL)
1294 *p = 0; 1306 *p = 0;
1295 if ((p = strchr(path, '\n')) != NULL) 1307 if ((p = strchr(path, '\n')) != NULL)
1296 *p = 0; 1308 *p = 0;
1297#ifdef __linux__
1298 // recursive includes of the same file will make this segfault. 1309 // recursive includes of the same file will make this segfault.
1299 if ((memcmp(path, "include", 7) == 0) && isblank(path[7])) { 1310 if ((memcmp(path, "include", 7) == 0) && isblank(path[7])) {
1300 glob64_t gl; 1311 glob64_t gl;
1301 size_t x; 1312 size_t x;
1302 char gpath[__PAX_UTILS_PATH_MAX]; 1313 char gpath[__PAX_UTILS_PATH_MAX];
1322 globfree64 (&gl); 1333 globfree64 (&gl);
1323 continue; 1334 continue;
1324 } else 1335 } else
1325 abort(); 1336 abort();
1326 } 1337 }
1327#endif
1328 if (*path != '/') 1338 if (*path != '/')
1329 continue; 1339 continue;
1330 1340
1331 ldpaths[i++] = xstrdup(path); 1341 ldpaths[i++] = xstrdup(path);
1332 1342
1336 ldpaths[i] = NULL; 1346 ldpaths[i] = NULL;
1337 1347
1338 fclose(fp); 1348 fclose(fp);
1339 return i; 1349 return i;
1340} 1350}
1351#endif
1352
1353#if defined(__FreeBSD__) || (__DragonFly__)
1354static int load_ld_so_hints(int i, const char *fname)
1355{
1356 FILE *fp = NULL;
1357 char *b = NULL, *p;
1358 struct elfhints_hdr hdr;
1359
1360 if (i + 1 == sizeof(ldpaths) / sizeof(*ldpaths))
1361 return i;
1362
1363 if ((fp = fopen(fname, "r")) == NULL)
1364 return i;
1365
1366 if ( fread(&hdr, 1, sizeof(hdr), fp) != sizeof(hdr) ||
1367 hdr.magic != ELFHINTS_MAGIC || hdr.version != 1 ||
1368 fseek(fp, hdr.strtab + hdr.dirlist, SEEK_SET) == -1
1369 ) {
1370 fclose(fp);
1371 return i;
1372 }
1373
1374 b = (char*)malloc(hdr.dirlistlen+1);
1375 if ( fread(b, 1, hdr.dirlistlen+1, fp) != hdr.dirlistlen+1 ) {
1376 fclose(fp);
1377 free(b);
1378 return i;
1379 }
1380
1381 while ( (p = strsep(&b, ":")) ) {
1382 if ( *p == '\0' ) continue;
1383 ldpaths[i++] = xstrdup(p);
1384
1385 if (i + 1 == sizeof(ldpaths) / sizeof(*ldpaths))
1386 break;
1387 }
1388 ldpaths[i] = NULL;
1389
1390 free(b);
1391 fclose(fp);
1392 return i;
1393}
1394#endif
1341 1395
1342/* scan /etc/ld.so.conf for paths */ 1396/* scan /etc/ld.so.conf for paths */
1343static void scanelf_ldpath() 1397static void scanelf_ldpath()
1344{ 1398{
1345 char scan_l, scan_ul, scan_ull; 1399 char scan_l, scan_ul, scan_ull;
1678 } 1732 }
1679 if (be_verbose > 2) printf("Format: %s\n", out_format); 1733 if (be_verbose > 2) printf("Format: %s\n", out_format);
1680 1734
1681 /* now lets actually do the scanning */ 1735 /* now lets actually do the scanning */
1682 if (scan_ldpath || use_ldcache) 1736 if (scan_ldpath || use_ldcache)
1737#if defined(__GLIBC__) || defined(__UCLIBC__)
1683 load_ld_so_conf(0, "/etc/ld.so.conf"); 1738 load_ld_so_conf(0, "/etc/ld.so.conf");
1739#elif defined(__FreeBSD__) || defined(__DragonFly__)
1740 load_ld_so_hints(0, _PATH_ELF_HINTS);
1741#endif
1684 if (scan_ldpath) scanelf_ldpath(); 1742 if (scan_ldpath) scanelf_ldpath();
1685 if (scan_envpath) scanelf_envpath(); 1743 if (scan_envpath) scanelf_envpath();
1686 if (!from_file && optind == argc && ttyname(0) == NULL) 1744 if (!from_file && optind == argc && ttyname(0) == NULL)
1687 from_file = "-"; 1745 from_file = "-";
1688 if (from_file) { 1746 if (from_file) {

Legend:
Removed from v.1.140  
changed lines
  Added in v.1.141

  ViewVC Help
Powered by ViewVC 1.1.20