/[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.118 Revision 1.119
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.118 2006/02/03 00:10:05 vapier Exp $ 4 * $Header: /var/cvsroot/gentoo-projects/pax-utils/scanelf.c,v 1.119 2006/02/05 02:25:58 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.118 2006/02/03 00:10:05 vapier Exp $"; 12static const char *rcsid = "$Id: scanelf.c,v 1.119 2006/02/05 02:25:58 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 == '#')
16 16
17 17
31static void xstrncat(char **dst, const char *src, size_t *curr_len, size_t n); 31static void xstrncat(char **dst, const char *src, size_t *curr_len, size_t n);
32#define xstrcat(dst,src,curr_len) xstrncat(dst,src,curr_len,0) 32#define xstrcat(dst,src,curr_len) xstrncat(dst,src,curr_len,0)
33static inline void xchrcat(char **dst, const char append, size_t *curr_len); 33static inline void xchrcat(char **dst, const char append, size_t *curr_len);
34 34
35/* variables to control behavior */ 35/* variables to control behavior */
36static char match_etypes[126] = "";
36static char *ldpaths[256]; 37static char *ldpaths[256];
37static char scan_ldpath = 0; 38static char scan_ldpath = 0;
38static char scan_envpath = 0; 39static char scan_envpath = 0;
39static char scan_symlink = 1; 40static char scan_symlink = 1;
40static char scan_archives = 0; 41static char scan_archives = 0;
867 if (be_quiet) 868 if (be_quiet)
868 return NULL; 869 return NULL;
869 else 870 else
870 return (char *)" - "; 871 return (char *)" - ";
871} 872}
873
874
872/* scan an elf file and show all the fun stuff */ 875/* scan an elf file and show all the fun stuff */
873#define prints(str) write(fileno(stdout), str, strlen(str)) 876#define prints(str) write(fileno(stdout), str, strlen(str))
874static int scanelf_elfobj(elfobj *elf) 877static int scanelf_elfobj(elfobj *elf)
875{ 878{
876 unsigned long i; 879 unsigned long i;
1026 if ((elf = _readelf_fd(filename, fd, len, !fix_elf)) == NULL) { 1029 if ((elf = _readelf_fd(filename, fd, len, !fix_elf)) == NULL) {
1027 if (be_verbose > 2) printf("%s: not an ELF\n", filename); 1030 if (be_verbose > 2) printf("%s: not an ELF\n", filename);
1028 return 1; 1031 return 1;
1029 } 1032 }
1030 1033
1034 if (strlen(match_etypes)) {
1035 char sbuf[126];
1036 strncpy(sbuf, match_etypes, sizeof(sbuf));
1037 if (strchr(match_etypes, ',') != NULL) {
1038 char *p;
1039 while((p = strrchr(sbuf, ',')) != NULL) {
1040 *p = 0;
1041 if (atoi(p+1) == get_etype(elf))
1042 goto label_ret;
1043 }
1044 }
1045 if (atoi(sbuf) != get_etype(elf)) {
1046 ret = 1;
1047 goto label_done;
1048 }
1049 }
1050
1051label_ret:
1031 ret = scanelf_elfobj(elf); 1052 ret = scanelf_elfobj(elf);
1053
1054label_done:
1032 unreadelf(elf); 1055 unreadelf(elf);
1033 return ret; 1056 return ret;
1034} 1057}
1058
1035/* scan an archive of elfs */ 1059/* scan an archive of elfs */
1036static int scanelf_archive(const char *filename, int fd, size_t len) 1060static int scanelf_archive(const char *filename, int fd, size_t len)
1037{ 1061{
1038 archive_handle *ar; 1062 archive_handle *ar;
1039 archive_member *m; 1063 archive_member *m;
1232 free(path); 1256 free(path);
1233} 1257}
1234 1258
1235 1259
1236/* usage / invocation handling functions */ 1260/* usage / invocation handling functions */
1237#define PARSE_FLAGS "plRmyAXxetrnLibSs:gN:TaqvF:f:o:BhV" 1261#define PARSE_FLAGS "plRmyAXxetrnLibSs:gN:TaqvF:f:o:E:BhV"
1238#define a_argument required_argument 1262#define a_argument required_argument
1239static struct option const long_opts[] = { 1263static struct option const long_opts[] = {
1240 {"path", no_argument, NULL, 'p'}, 1264 {"path", no_argument, NULL, 'p'},
1241 {"ldpath", no_argument, NULL, 'l'}, 1265 {"ldpath", no_argument, NULL, 'l'},
1242 {"recursive", no_argument, NULL, 'R'}, 1266 {"recursive", no_argument, NULL, 'R'},
1255 {"soname", no_argument, NULL, 'S'}, 1279 {"soname", no_argument, NULL, 'S'},
1256 {"symbol", a_argument, NULL, 's'}, 1280 {"symbol", a_argument, NULL, 's'},
1257 {"lib", a_argument, NULL, 'N'}, 1281 {"lib", a_argument, NULL, 'N'},
1258 {"gmatch", no_argument, NULL, 'g'}, 1282 {"gmatch", no_argument, NULL, 'g'},
1259 {"textrels", no_argument, NULL, 'T'}, 1283 {"textrels", no_argument, NULL, 'T'},
1284 {"etype", a_argument, NULL, 'E'},
1260 {"all", no_argument, NULL, 'a'}, 1285 {"all", no_argument, NULL, 'a'},
1261 {"quiet", no_argument, NULL, 'q'}, 1286 {"quiet", no_argument, NULL, 'q'},
1262 {"verbose", no_argument, NULL, 'v'}, 1287 {"verbose", no_argument, NULL, 'v'},
1263 {"format", a_argument, NULL, 'F'}, 1288 {"format", a_argument, NULL, 'F'},
1264 {"from", a_argument, NULL, 'f'}, 1289 {"from", a_argument, NULL, 'f'},
1288 "Print SONAME information", 1313 "Print SONAME information",
1289 "Find a specified symbol", 1314 "Find a specified symbol",
1290 "Find a specified library", 1315 "Find a specified library",
1291 "Use strncmp to match libraries. (use with -N)", 1316 "Use strncmp to match libraries. (use with -N)",
1292 "Locate cause of TEXTREL", 1317 "Locate cause of TEXTREL",
1318 "Print only ELF files matching numeric constant",
1293 "Print all scanned info (-x -e -t -r -b)\n", 1319 "Print all scanned info (-x -e -t -r -b)\n",
1294 "Only output 'bad' things", 1320 "Only output 'bad' things",
1295 "Be verbose (can be specified more than once)", 1321 "Be verbose (can be specified more than once)",
1296 "Use specified format for output", 1322 "Use specified format for output",
1297 "Read input stream from a filename", 1323 "Read input stream from a filename",
1351 break; 1377 break;
1352 case 'h': usage(EXIT_SUCCESS); break; 1378 case 'h': usage(EXIT_SUCCESS); break;
1353 case 'f': 1379 case 'f':
1354 if (from_file) warn("You prob don't want to specify -f twice"); 1380 if (from_file) warn("You prob don't want to specify -f twice");
1355 from_file = optarg; 1381 from_file = optarg;
1382 break;
1383 case 'E':
1384 strncpy(match_etypes, optarg, sizeof(match_etypes));
1356 break; 1385 break;
1357 case 'o': { 1386 case 'o': {
1358 FILE *fp = NULL; 1387 FILE *fp = NULL;
1359 if ((fp = freopen(optarg, "w", stdout)) == NULL) 1388 if ((fp = freopen(optarg, "w", stdout)) == NULL)
1360 err("Could not open output stream '%s': %s", optarg, strerror(errno)); 1389 err("Could not open output stream '%s': %s", optarg, strerror(errno));
1405 case 'a': show_pax = show_phdr = show_textrel = show_rpath = show_bind = 1; break; 1434 case 'a': show_pax = show_phdr = show_textrel = show_rpath = show_bind = 1; break;
1406 1435
1407 case ':': 1436 case ':':
1408 err("Option '%c' is missing parameter", optopt); 1437 err("Option '%c' is missing parameter", optopt);
1409 case '?': 1438 case '?':
1410 err("Unknown option '%c'", optopt); 1439 err("Unknown option '%c' or argument missing", optopt);
1411 default: 1440 default:
1412 err("Unhandled option '%c'; please report this", i); 1441 err("Unhandled option '%c'; please report this", i);
1413 } 1442 }
1414 } 1443 }
1415 1444

Legend:
Removed from v.1.118  
changed lines
  Added in v.1.119

  ViewVC Help
Powered by ViewVC 1.1.20