/[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.5 Revision 1.6
1/* 1/*
2 * Copyright 2003 Ned Ludd <solar@gentoo.org> 2 * Copyright 2003 Ned Ludd <solar@gentoo.org>
3 * Copyright 1999-2003 Gentoo Technologies, Inc. 3 * Copyright 1999-2003 Gentoo Technologies, Inc.
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/Attic/scanelf.c,v 1.5 2003/11/09 17:46:41 solar Exp $ 5 * $Header: /var/cvsroot/gentoo-projects/pax-utils/Attic/scanelf.c,v 1.6 2004/01/10 08:20:07 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
31#include <getopt.h> 31#include <getopt.h>
32 32
33#include "paxelf.h" 33#include "paxelf.h"
34 34
35static const char *rcsid = 35static const char *rcsid =
36 "$Id: scanelf.c,v 1.5 2003/11/09 17:46:41 solar Exp $"; 36 "$Id: scanelf.c,v 1.6 2004/01/10 08:20:07 solar Exp $";
37 37
38#define PARSE_FLAGS "hvlp" 38#define PARSE_FLAGS "hvlp"
39static struct option const long_options[] = { 39static struct option const long_options[] = {
40 {"help", no_argument, 0, 'h'}, 40 {"help", no_argument, 0, 'h'},
41 {"version", no_argument, 0, 'v'}, 41 {"version", no_argument, 0, 'v'},
42 {"path", no_argument, 0, 'p'}, 42 {"path", no_argument, 0, 'p'},
43 {"ldpath", no_argument, 0, 'l'}, 43 {"ldpath", no_argument, 0, 'l'},
44 {NULL, no_argument, NULL, 0} 44 {NULL, no_argument, NULL, 0}
45}; 45};
46 46
47void scanelf_file(char *filename)
48{
49 elfobj *elf = NULL;
50 /* verify this is real ELF */
51 if ((elf = readelf(filename)) != NULL) {
52 if (!check_elf_header(elf->ehdr))
53 if (IS_ELF(elf))
54 printf("%s %s %s\n",
55 pax_short_flags(PAX_FLAGS(elf)),
56 get_elfetype(elf->ehdr->e_type), filename);
57
58 if (elf != NULL) {
59 munmap(elf->data, elf->len);
60 free(elf);
61 elf = NULL;
62 }
63 }
64}
65
47/* scan a directory for ET_EXEC files and print when we find one */ 66/* scan a directory for ET_EXEC files and print when we find one */
48void scanelf(const char *path) 67void scanelf(const char *path)
49{ 68{
50 elfobj *elf = NULL;
51 register DIR *dir; 69 register DIR *dir;
52 register struct dirent *dentry; 70 register struct dirent *dentry;
71 char *p;
72 int len = 0;
53 73
54 if ((chdir(path) == 0) && ((dir = opendir(path)))) { 74 if ((chdir(path) == 0) && ((dir = opendir(path)))) {
55 while ((dentry = readdir(dir))) { 75 while ((dentry = readdir(dir))) {
56 /* verify this is real ELF */ 76 len = (strlen(path) + 2 + strlen(dentry->d_name));
57 if ((elf = readelf(dentry->d_name)) != NULL) { 77 p = malloc(len);
58 if (!check_elf_header(elf->ehdr)) 78 strncpy(p, path, len);
59 if (IS_ELF(elf)) 79 strncat(p, "/", len);
60 printf("%s %s %s/%s\n", 80 strncat(p, dentry->d_name, len);
61 pax_short_flags(PAX_FLAGS(elf)), 81 scanelf_file(p);
62 get_elfetype(elf->ehdr->e_type), path, 82 free(p);
63 dentry->d_name);
64
65 if (elf != NULL) {
66 munmap(elf->data, elf->len);
67 free(elf);
68 elf = NULL;
69 }
70 }
71 } 83 }
72 closedir(dir); 84 closedir(dir);
73 } 85 }
74} 86}
75 87

Legend:
Removed from v.1.5  
changed lines
  Added in v.1.6

  ViewVC Help
Powered by ViewVC 1.1.20