/[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.201 Revision 1.206
1/* 1/*
2 * Copyright 2003-2007 Gentoo Foundation 2 * Copyright 2003-2007 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/Attic/scanelf.c,v 1.201 2008/12/30 12:00:06 vapier Exp $ 4 * $Header: /var/cvsroot/gentoo-projects/pax-utils/Attic/scanelf.c,v 1.206 2008/12/30 13:34:46 vapier Exp $
5 * 5 *
6 * Copyright 2003-2007 Ned Ludd - <solar@gentoo.org> 6 * Copyright 2003-2007 Ned Ludd - <solar@gentoo.org>
7 * Copyright 2004-2007 Mike Frysinger - <vapier@gentoo.org> 7 * Copyright 2004-2007 Mike Frysinger - <vapier@gentoo.org>
8 */ 8 */
9 9
10static const char *rcsid = "$Id: scanelf.c,v 1.201 2008/12/30 12:00:06 vapier Exp $"; 10static const char *rcsid = "$Id: scanelf.c,v 1.206 2008/12/30 13:34:46 vapier Exp $";
11const char * const argv0 = "scanelf"; 11const char * const argv0 = "scanelf";
12 12
13#include "paxinc.h" 13#include "paxinc.h"
14 14
15#define IS_MODIFIER(c) (c == '%' || c == '#' || c == '+') 15#define IS_MODIFIER(c) (c == '%' || c == '#' || c == '+')
68 68
69static char **qa_textrels = NULL; 69static char **qa_textrels = NULL;
70static char **qa_execstack = NULL; 70static char **qa_execstack = NULL;
71static char **qa_wx_load = NULL; 71static char **qa_wx_load = NULL;
72 72
73int match_bits = 0; 73static int match_bits = 0;
74unsigned int match_perms = 0; 74static unsigned int match_perms = 0;
75caddr_t ldcache = 0; 75static caddr_t ldcache = 0;
76size_t ldcache_size = 0; 76static size_t ldcache_size = 0;
77unsigned long setpax = 0UL; 77static unsigned long setpax = 0UL;
78 78
79int has_objdump = 0; 79static int has_objdump = 0;
80
81static char *getstr_perms(const char *fname);
82static char *getstr_perms(const char *fname)
83{
84 struct stat st;
85 static char buf[8];
86
87 if ((stat(fname, &st)) == (-1))
88 return (char *) "";
89
90 snprintf(buf, sizeof(buf), "%o", st.st_mode);
91
92 return (char *) buf + 2;
93}
94 80
95/* find the path to a file by name */ 81/* find the path to a file by name */
96static char *which(const char *fname) 82static char *which(const char *fname)
97{ 83{
98 static char fullpath[BUFSIZ]; 84 static char fullpath[BUFSIZ];
104 90
105 path = xstrdup(path); 91 path = xstrdup(path);
106 while ((p = strrchr(path, ':')) != NULL) { 92 while ((p = strrchr(path, ':')) != NULL) {
107 snprintf(fullpath, sizeof(fullpath), "%s/%s", p + 1, fname); 93 snprintf(fullpath, sizeof(fullpath), "%s/%s", p + 1, fname);
108 *p = 0; 94 *p = 0;
109 if (access(fullpath, R_OK) != (-1)) { 95 if (access(fullpath, R_OK) != -1) {
110 free(path); 96 free(path);
111 return (char *) fullpath; 97 return fullpath;
112 } 98 }
113 } 99 }
114 free(path); 100 free(path);
115 return NULL; 101 return NULL;
116} 102}
738 ldcache_size = st.st_size; 724 ldcache_size = st.st_size;
739 ldcache = mmap(0, ldcache_size, PROT_READ, MAP_SHARED, fd, 0); 725 ldcache = mmap(0, ldcache_size, PROT_READ, MAP_SHARED, fd, 0);
740 726
741 close(fd); 727 close(fd);
742 728
743 if (ldcache == (caddr_t)-1) { 729 if (ldcache == MAP_FAILED) {
744 ldcache = 0; 730 ldcache = 0;
745 return NULL; 731 return NULL;
746 } 732 }
747 733
748 if (memcmp(((header_t *) ldcache)->magic, LDSO_CACHE_MAGIC, LDSO_CACHE_MAGIC_LEN)) 734 if (memcmp(((header_t *) ldcache)->magic, LDSO_CACHE_MAGIC, LDSO_CACHE_MAGIC_LEN))
1235 case 't': out = scanelf_file_textrel(elf, &found_textrel); break; 1221 case 't': out = scanelf_file_textrel(elf, &found_textrel); break;
1236 case 'T': out = scanelf_file_textrels(elf, &found_textrels, &found_textrel); break; 1222 case 'T': out = scanelf_file_textrels(elf, &found_textrels, &found_textrel); break;
1237 case 'r': scanelf_file_rpath(elf, &found_rpath, &out_buffer, &out_len); break; 1223 case 'r': scanelf_file_rpath(elf, &found_rpath, &out_buffer, &out_len); break;
1238 case 'M': out = get_elfeitype(EI_CLASS, elf->data[EI_CLASS]); break; 1224 case 'M': out = get_elfeitype(EI_CLASS, elf->data[EI_CLASS]); break;
1239 case 'D': out = get_endian(elf); break; 1225 case 'D': out = get_endian(elf); break;
1240 case 'O': out = getstr_perms(elf->filename); break; 1226 case 'O': out = strfileperms(elf->filename); break;
1241 case 'n': 1227 case 'n':
1242 case 'N': out = scanelf_file_needed_lib(elf, &found_needed, &found_lib, (out_format[i]=='N'), &out_buffer, &out_len); break; 1228 case 'N': out = scanelf_file_needed_lib(elf, &found_needed, &found_lib, (out_format[i]=='N'), &out_buffer, &out_len); break;
1243 case 'i': out = scanelf_file_interp(elf, &found_interp); break; 1229 case 'i': out = scanelf_file_interp(elf, &found_interp); break;
1244 case 'b': out = scanelf_file_bind(elf, &found_bind); break; 1230 case 'b': out = scanelf_file_bind(elf, &found_bind); break;
1245 case 'S': out = scanelf_file_soname(elf, &found_soname); break; 1231 case 'S': out = scanelf_file_soname(elf, &found_soname); break;
1761 if (strcmp(optarg, "ELFCLASS64") == 0) 1747 if (strcmp(optarg, "ELFCLASS64") == 0)
1762 match_bits = 64; 1748 match_bits = 64;
1763 } 1749 }
1764 break; 1750 break;
1765 case 'O': 1751 case 'O':
1766 if (sscanf(optarg, "%o", &match_perms) == (-1)) 1752 if (sscanf(optarg, "%o", &match_perms) == -1)
1767 match_bits = 0; 1753 match_bits = 0;
1768 break; 1754 break;
1769 case 'o': { 1755 case 'o': {
1770 if (freopen(optarg, "w", stdout) == NULL) 1756 if (freopen(optarg, "w", stdout) == NULL)
1771 err("Could not open output stream '%s': %s", optarg, strerror(errno)); 1757 err("Could not open output stream '%s': %s", optarg, strerror(errno));

Legend:
Removed from v.1.201  
changed lines
  Added in v.1.206

  ViewVC Help
Powered by ViewVC 1.1.20