/[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.160 Revision 1.161
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.160 2006/11/23 23:50:33 solar Exp $ 4 * $Header: /var/cvsroot/gentoo-projects/pax-utils/scanelf.c,v 1.161 2006/11/28 03:55:57 vapier 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.160 2006/11/23 23:50:33 solar Exp $"; 12static const char *rcsid = "$Id: scanelf.c,v 1.161 2006/11/28 03:55:57 vapier Exp $";
13#define argv0 "scanelf" 13#define argv0 "scanelf"
14 14
15#define IS_MODIFIER(c) (c == '%' || c == '#' || c == '+') 15#define IS_MODIFIER(c) (c == '%' || c == '#' || c == '+')
16 16
17#define do_state(option, flag) \ 17#define do_state(option, flag) \
27/* prototypes */ 27/* prototypes */
28static int file_matches_list(const char *filename, char **matchlist); 28static int file_matches_list(const char *filename, char **matchlist);
29static int scanelf_elfobj(elfobj *elf); 29static int scanelf_elfobj(elfobj *elf);
30static int scanelf_elf(const char *filename, int fd, size_t len); 30static int scanelf_elf(const char *filename, int fd, size_t len);
31static int scanelf_archive(const char *filename, int fd, size_t len); 31static int scanelf_archive(const char *filename, int fd, size_t len);
32static void scanelf_file(const char *filename); 32static void scanelf_file(const char *filename, const struct stat *st_cache);
33static void scanelf_dir(const char *path); 33static void scanelf_dir(const char *path);
34static void scanelf_ldpath(void); 34static void scanelf_ldpath(void);
35static void scanelf_envpath(void); 35static void scanelf_envpath(void);
36static void usage(int status); 36static void usage(int status);
37static char **get_split_env(const char *envvar); 37static char **get_split_env(const char *envvar);
1229 munmap(ar_buffer, len); 1229 munmap(ar_buffer, len);
1230 1230
1231 return 0; 1231 return 0;
1232} 1232}
1233/* scan a file which may be an elf or an archive or some other magical beast */ 1233/* scan a file which may be an elf or an archive or some other magical beast */
1234static void scanelf_file(const char *filename) 1234static void scanelf_file(const char *filename, const struct stat *st_cache)
1235{ 1235{
1236 const struct stat *st = st_cache;
1236 struct stat st; 1237 struct stat symlink_st;
1237 int fd; 1238 int fd;
1238 1239
1239 /* make sure 'filename' exists */
1240 if (lstat(filename, &st) == -1) {
1241 if (be_verbose > 2) printf("%s: does not exist\n", filename);
1242 return;
1243 }
1244
1245 /* always handle regular files and handle symlinked files if no -y */ 1240 /* always handle regular files and handle symlinked files if no -y */
1246 if (S_ISLNK(st.st_mode)) { 1241 if (S_ISLNK(st->st_mode)) {
1247 if (!scan_symlink) return; 1242 if (!scan_symlink) return;
1248 stat(filename, &st); 1243 stat(filename, &symlink_st);
1244 st = &symlink_st;
1249 } 1245 }
1246
1250 if (!S_ISREG(st.st_mode)) { 1247 if (!S_ISREG(st->st_mode)) {
1251 if (be_verbose > 2) printf("%s: skipping non-file\n", filename); 1248 if (be_verbose > 2) printf("%s: skipping non-file\n", filename);
1252 return; 1249 return;
1253 } 1250 }
1254 1251
1255 if ((fd=open(filename, (fix_elf ? O_RDWR : O_RDONLY))) == -1) 1252 if ((fd=open(filename, (fix_elf ? O_RDWR : O_RDONLY))) == -1)
1256 return; 1253 return;
1257 1254
1258 if (scanelf_elf(filename, fd, st.st_size) == 1 && scan_archives) 1255 if (scanelf_elf(filename, fd, st->st_size) == 1 && scan_archives)
1259 /* if it isn't an ELF, maybe it's an .a archive */ 1256 /* if it isn't an ELF, maybe it's an .a archive */
1260 scanelf_archive(filename, fd, st.st_size); 1257 scanelf_archive(filename, fd, st->st_size);
1261 1258
1262 close(fd); 1259 close(fd);
1263} 1260}
1264 1261
1265/* scan a directory for ET_EXEC files and print when we find one */ 1262/* scan a directory for ET_EXEC files and print when we find one */
1277 return; 1274 return;
1278 } 1275 }
1279 1276
1280 /* ok, if it isn't a directory, assume we can open it */ 1277 /* ok, if it isn't a directory, assume we can open it */
1281 if (!S_ISDIR(st_top.st_mode)) { 1278 if (!S_ISDIR(st_top.st_mode)) {
1282 scanelf_file(path); 1279 scanelf_file(path, &st_top);
1283 return; 1280 return;
1284 } 1281 }
1285 1282
1286 /* now scan the dir looking for fun stuff */ 1283 /* now scan the dir looking for fun stuff */
1287 if ((dir = opendir(path)) == NULL) { 1284 if ((dir = opendir(path)) == NULL) {
1301 continue; 1298 continue;
1302 } 1299 }
1303 snprintf(buf, sizeof(buf), "%s%s%s", path, (path[pathlen-1] == '/') ? "" : "/", dentry->d_name); 1300 snprintf(buf, sizeof(buf), "%s%s%s", path, (path[pathlen-1] == '/') ? "" : "/", dentry->d_name);
1304 if (lstat(buf, &st) != -1) { 1301 if (lstat(buf, &st) != -1) {
1305 if (S_ISREG(st.st_mode)) 1302 if (S_ISREG(st.st_mode))
1306 scanelf_file(buf); 1303 scanelf_file(buf, &st);
1307 else if (dir_recurse && S_ISDIR(st.st_mode)) { 1304 else if (dir_recurse && S_ISDIR(st.st_mode)) {
1308 if (dir_crossmount || (st_top.st_dev == st.st_dev)) 1305 if (dir_crossmount || (st_top.st_dev == st.st_dev))
1309 scanelf_dir(buf); 1306 scanelf_dir(buf);
1310 } 1307 }
1311 } 1308 }

Legend:
Removed from v.1.160  
changed lines
  Added in v.1.161

  ViewVC Help
Powered by ViewVC 1.1.20