/[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.122 Revision 1.123
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.122 2006/02/11 04:11:44 vapier Exp $ 4 * $Header: /var/cvsroot/gentoo-projects/pax-utils/scanelf.c,v 1.123 2006/02/12 16:51:21 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.122 2006/02/11 04:11:44 vapier Exp $"; 12static const char *rcsid = "$Id: scanelf.c,v 1.123 2006/02/12 16:51:21 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
1187 if (fp != stdin) 1187 if (fp != stdin)
1188 fclose(fp); 1188 fclose(fp);
1189 return 0; 1189 return 0;
1190} 1190}
1191 1191
1192static void load_ld_so_conf() 1192static int load_ld_so_conf(int i, const char *fname)
1193{ 1193{
1194 FILE *fp = NULL; 1194 FILE *fp = NULL;
1195 char *p; 1195 char *p;
1196 char path[__PAX_UTILS_PATH_MAX]; 1196 char path[__PAX_UTILS_PATH_MAX];
1197 int i = 0;
1198 1197
1199 if ((fp = fopen("/etc/ld.so.conf", "r")) == NULL) 1198 if (i + 1 == sizeof(ldpaths) / sizeof(*ldpaths))
1200 return; 1199 return i;
1200
1201 if ((fp = fopen(fname, "r")) == NULL)
1202 return i;
1201 1203
1202 while ((fgets(path, __PAX_UTILS_PATH_MAX, fp)) != NULL) { 1204 while ((fgets(path, __PAX_UTILS_PATH_MAX, fp)) != NULL) {
1203 if (*path != '/')
1204 continue;
1205
1206 if ((p = strrchr(path, '\r')) != NULL) 1205 if ((p = strrchr(path, '\r')) != NULL)
1207 *p = 0; 1206 *p = 0;
1208 if ((p = strchr(path, '\n')) != NULL) 1207 if ((p = strchr(path, '\n')) != NULL)
1209 *p = 0; 1208 *p = 0;
1209#ifdef HAVE_GLOB
1210 // recursive includes of the same file will make this segfault.
1211 if ((*path == 'i') && (strncmp(path, "include", 7) == 0) && isblank(path[7])) {
1212 glob64_t gl;
1213 size_t x;
1214 char gpath[__PAX_UTILS_PATH_MAX];
1215
1216 gpath[sizeof(gpath)] = 0;
1217
1218 if (path[8] != '/')
1219 snprintf(gpath, sizeof(gpath)-1, "/etc/%s", &path[8]);
1220 else
1221 strncpy(gpath, &path[8], sizeof(gpath)-1);
1222
1223 if ((glob64(gpath, 0, NULL, &gl)) == 0) {
1224 for (x = 0; x < gl.gl_pathc; ++x) {
1225 /* try to avoid direct loops */
1226 if (strcmp(gl.gl_pathv[x], fname) == 0)
1227 continue;
1228 i = load_ld_so_conf(i, gl.gl_pathv[x]);
1229 if (i + 1 >= sizeof(ldpaths) / sizeof(*ldpaths)) {
1230 globfree64(&gl);
1231 return i;
1232 }
1233 }
1234 globfree64 (&gl);
1235 continue;
1236 } else
1237 abort();
1238 }
1239#endif
1240 if (*path != '/')
1241 continue;
1210 1242
1211 ldpaths[i++] = xstrdup(path); 1243 ldpaths[i++] = xstrdup(path);
1212 1244
1213 if (i + 1 == sizeof(ldpaths) / sizeof(*ldpaths)) 1245 if (i + 1 == sizeof(ldpaths) / sizeof(*ldpaths))
1214 break; 1246 break;
1215 } 1247 }
1216 ldpaths[i] = NULL; 1248 ldpaths[i] = NULL;
1217 1249
1218 fclose(fp); 1250 fclose(fp);
1251 return i;
1219} 1252}
1220 1253
1221/* scan /etc/ld.so.conf for paths */ 1254/* scan /etc/ld.so.conf for paths */
1222static void scanelf_ldpath() 1255static void scanelf_ldpath()
1223{ 1256{
1506 } 1539 }
1507 if (be_verbose > 2) printf("Format: %s\n", out_format); 1540 if (be_verbose > 2) printf("Format: %s\n", out_format);
1508 1541
1509 /* now lets actually do the scanning */ 1542 /* now lets actually do the scanning */
1510 if (scan_ldpath || use_ldcache) 1543 if (scan_ldpath || use_ldcache)
1511 load_ld_so_conf(); 1544 load_ld_so_conf(0, "/etc/ld.so.conf");
1512 if (scan_ldpath) scanelf_ldpath(); 1545 if (scan_ldpath) scanelf_ldpath();
1513 if (scan_envpath) scanelf_envpath(); 1546 if (scan_envpath) scanelf_envpath();
1514 if (from_file) { 1547 if (from_file) {
1515 scanelf_from_file(from_file); 1548 scanelf_from_file(from_file);
1516 from_file = *argv; 1549 from_file = *argv;

Legend:
Removed from v.1.122  
changed lines
  Added in v.1.123

  ViewVC Help
Powered by ViewVC 1.1.20