/[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.44 Revision 1.45
1/* 1/*
2 * Copyright 2003 Ned Ludd <solar@gentoo.org> 2 * Copyright 2003 Ned Ludd <solar@gentoo.org>
3 * Copyright 1999-2005 Gentoo Foundation 3 * Copyright 1999-2005 Gentoo Foundation
4 * Distributed under the terms of the GNU General Public License v2 4 * Distributed under the terms of the GNU General Public License v2
5 * $Header: /var/cvsroot/gentoo-projects/pax-utils/scanelf.c,v 1.44 2005/05/10 22:54:25 vapier Exp $ 5 * $Header: /var/cvsroot/gentoo-projects/pax-utils/scanelf.c,v 1.45 2005/05/14 00:18:56 solar Exp $
6 * 6 *
7 ******************************************************************** 7 ********************************************************************
8 * This program is free software; you can redistribute it and/or 8 * This program is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU General Public License as 9 * modify it under the terms of the GNU General Public License as
10 * published by the Free Software Foundation; either version 2 of the 10 * published by the Free Software Foundation; either version 2 of the
33#include <getopt.h> 33#include <getopt.h>
34#include <assert.h> 34#include <assert.h>
35 35
36#include "paxelf.h" 36#include "paxelf.h"
37 37
38static const char *rcsid = "$Id: scanelf.c,v 1.44 2005/05/10 22:54:25 vapier Exp $"; 38static const char *rcsid = "$Id: scanelf.c,v 1.45 2005/05/14 00:18:56 solar Exp $";
39#define argv0 "scanelf" 39#define argv0 "scanelf"
40 40
41 41
42 42
43/* prototypes */ 43/* prototypes */
490 } 490 }
491 } 491 }
492 closedir(dir); 492 closedir(dir);
493} 493}
494 494
495int scanelf_from_file(char *filename) {
496 FILE *fp = NULL;
497 char *p;
498 char path[_POSIX_PATH_MAX];
499
500 if (((strcmp(filename, "-")) == 0) && (ttyname(0) == NULL))
501 fp = stdin;
502 else if ((fp = fopen(filename, "r")) == NULL)
503 return 1;
504
505 while ((fgets(path, _POSIX_PATH_MAX, fp)) != NULL) {
506 if ((p = strchr(path, '\n')) != NULL)
507 *p = 0;
508 scanelf_dir(path);
509 }
510 if (fp != stdin)
511 fclose(fp);
512 return 0;
513}
514
495/* scan /etc/ld.so.conf for paths */ 515/* scan /etc/ld.so.conf for paths */
496static void scanelf_ldpath() 516static void scanelf_ldpath()
497{ 517{
498 char scan_l, scan_ul, scan_ull; 518 char scan_l, scan_ul, scan_ull;
499 char *path, *p; 519 char *path, *p;
543} 563}
544 564
545 565
546 566
547/* usage / invocation handling functions */ 567/* usage / invocation handling functions */
548#define PARSE_FLAGS "plRmyxetrnis:aqvF:o:BhV" 568#define PARSE_FLAGS "plRmyxetrnis:aqvF:f:o:BhV"
549#define a_argument required_argument 569#define a_argument required_argument
550static struct option const long_opts[] = { 570static struct option const long_opts[] = {
551 {"path", no_argument, NULL, 'p'}, 571 {"path", no_argument, NULL, 'p'},
552 {"ldpath", no_argument, NULL, 'l'}, 572 {"ldpath", no_argument, NULL, 'l'},
553 {"recursive", no_argument, NULL, 'R'}, 573 {"recursive", no_argument, NULL, 'R'},
562 {"symbol", a_argument, NULL, 's'}, 582 {"symbol", a_argument, NULL, 's'},
563 {"all", no_argument, NULL, 'a'}, 583 {"all", no_argument, NULL, 'a'},
564 {"quiet", no_argument, NULL, 'q'}, 584 {"quiet", no_argument, NULL, 'q'},
565 {"verbose", no_argument, NULL, 'v'}, 585 {"verbose", no_argument, NULL, 'v'},
566 {"format", a_argument, NULL, 'F'}, 586 {"format", a_argument, NULL, 'F'},
587 {"from", a_argument, NULL, 'f'},
567 {"file", a_argument, NULL, 'o'}, 588 {"file", a_argument, NULL, 'o'},
568 {"nobanner", no_argument, NULL, 'B'}, 589 {"nobanner", no_argument, NULL, 'B'},
569 {"help", no_argument, NULL, 'h'}, 590 {"help", no_argument, NULL, 'h'},
570 {"version", no_argument, NULL, 'V'}, 591 {"version", no_argument, NULL, 'V'},
571 {NULL, no_argument, NULL, 0x0} 592 {NULL, no_argument, NULL, 0x0}
585 "Find a specified symbol", 606 "Find a specified symbol",
586 "Print all scanned info (-x -e -t -r)\n", 607 "Print all scanned info (-x -e -t -r)\n",
587 "Only output 'bad' things", 608 "Only output 'bad' things",
588 "Be verbose (can be specified more than once)", 609 "Be verbose (can be specified more than once)",
589 "Use specified format for output", 610 "Use specified format for output",
611 "Read input stream from a filename",
590 "Write output stream to a filename", 612 "Write output stream to a filename",
591 "Don't display the header", 613 "Don't display the header",
592 "Print this help and exit", 614 "Print this help and exit",
593 "Print version and exit", 615 "Print version and exit",
594 NULL 616 NULL
606 printf(" -%c, --%-13s %s\n", long_opts[i].val, 628 printf(" -%c, --%-13s %s\n", long_opts[i].val,
607 long_opts[i].name, opts_help[i]); 629 long_opts[i].name, opts_help[i]);
608 else 630 else
609 printf(" -%c, --%-6s <arg> %s\n", long_opts[i].val, 631 printf(" -%c, --%-6s <arg> %s\n", long_opts[i].val,
610 long_opts[i].name, opts_help[i]); 632 long_opts[i].name, opts_help[i]);
633
634 if (status != EXIT_SUCCESS)
635 exit(status);
636
637 puts("\nThe format modifiers for the -F option are");
638 puts(" %F Filename");
639 puts(" %x PaX Flags");
640 puts(" %e STACK/RELRO");
641 puts(" %t TEXTREL");
642 puts(" %r RPATH");
643 puts(" %n NEEDED");
644 puts(" %i INTERP");
645 puts(" %s symbol");
646
611 exit(status); 647 exit(status);
612} 648}
613 649
614/* parse command line arguments and preform needed actions */ 650/* parse command line arguments and preform needed actions */
615static void parseargs(int argc, char *argv[]) 651static void parseargs(int argc, char *argv[])
616{ 652{
617 int flag; 653 int flag;
654 char *from_file = NULL;
618 655
619 opterr = 0; 656 opterr = 0;
620 while ((flag=getopt_long(argc, argv, PARSE_FLAGS, long_opts, NULL)) != -1) { 657 while ((flag=getopt_long(argc, argv, PARSE_FLAGS, long_opts, NULL)) != -1) {
621 switch (flag) { 658 switch (flag) {
622 659
625 "%s written for Gentoo Linux by <solar and vapier @ gentoo.org>\n", 662 "%s written for Gentoo Linux by <solar and vapier @ gentoo.org>\n",
626 __FILE__, __DATE__, rcsid, argv0); 663 __FILE__, __DATE__, rcsid, argv0);
627 exit(EXIT_SUCCESS); 664 exit(EXIT_SUCCESS);
628 break; 665 break;
629 case 'h': usage(EXIT_SUCCESS); break; 666 case 'h': usage(EXIT_SUCCESS); break;
630 667 case 'f':
668 if (from_file == NULL)
669 from_file = xstrdup(optarg);
670 break;
631 case 'o': { 671 case 'o': {
632 FILE *fp = NULL; 672 FILE *fp = NULL;
633 fp = freopen(optarg, "w", stdout); 673 fp = freopen(optarg, "w", stdout);
634 if (fp == NULL) 674 if (fp == NULL)
635 err("Could not open output stream '%s': %s", optarg, strerror(errno)); 675 err("Could not open output stream '%s': %s", optarg, strerror(errno));
645 sprintf(versioned_symname, "%s@", find_sym); 685 sprintf(versioned_symname, "%s@", find_sym);
646 break; 686 break;
647 } 687 }
648 688
649 case 'F': { 689 case 'F': {
650 out_format = strdup(optarg); 690 out_format = xstrdup(optarg);
651 break; 691 break;
652 } 692 }
653 693
654 case 'y': scan_symlink = 0; break; 694 case 'y': scan_symlink = 0; break;
655 case 'B': show_banner = 0; break; 695 case 'B': show_banner = 0; break;
724 if (be_verbose > 2) printf("Format: %s\n", out_format); 764 if (be_verbose > 2) printf("Format: %s\n", out_format);
725 765
726 /* now lets actually do the scanning */ 766 /* now lets actually do the scanning */
727 if (scan_ldpath) scanelf_ldpath(); 767 if (scan_ldpath) scanelf_ldpath();
728 if (scan_envpath) scanelf_envpath(); 768 if (scan_envpath) scanelf_envpath();
769 if (from_file) {
770 scanelf_from_file(from_file);
771 free(from_file);
772 from_file = *argv;
773 }
729 if (optind == argc && !scan_ldpath && !scan_envpath) 774 if (optind == argc && !scan_ldpath && !scan_envpath && !from_file)
730 err("Nothing to scan !?"); 775 err("Nothing to scan !?");
731 while (optind < argc) 776 while (optind < argc)
732 scanelf_dir(argv[optind++]); 777 scanelf_dir(argv[optind++]);
733 778
734 /* clean up */ 779 /* clean up */

Legend:
Removed from v.1.44  
changed lines
  Added in v.1.45

  ViewVC Help
Powered by ViewVC 1.1.20