Changeset View
Changeset View
Standalone View
Standalone View
sbin/ldconfig/elfhints.c
Show First 20 Lines • Show All 42 Lines • ▼ Show 20 Lines | |||||
#include <string.h> | #include <string.h> | ||||
#include <unistd.h> | #include <unistd.h> | ||||
#include "ldconfig.h" | #include "ldconfig.h" | ||||
#define MAXDIRS 1024 /* Maximum directories in path */ | #define MAXDIRS 1024 /* Maximum directories in path */ | ||||
#define MAXFILESIZE (16*1024) /* Maximum hints file size */ | #define MAXFILESIZE (16*1024) /* Maximum hints file size */ | ||||
static void add_dir(const char *, const char *, int); | static void add_dir(const char *, const char *, bool); | ||||
static void read_dirs_from_file(const char *, const char *); | static void read_dirs_from_file(const char *, const char *); | ||||
static void read_elf_hints(const char *, int); | static void read_elf_hints(const char *, bool); | ||||
static void write_elf_hints(const char *); | static void write_elf_hints(const char *); | ||||
static const char *dirs[MAXDIRS]; | static const char *dirs[MAXDIRS]; | ||||
static int ndirs; | static int ndirs; | ||||
int insecure; | bool insecure; | ||||
static void | static void | ||||
add_dir(const char *hintsfile, const char *name, int trusted) | add_dir(const char *hintsfile, const char *name, bool trusted) | ||||
{ | { | ||||
struct stat stbuf; | struct stat stbuf; | ||||
int i; | int i; | ||||
/* Do some security checks */ | /* Do some security checks */ | ||||
if (!trusted && !insecure) { | if (!trusted && !insecure) { | ||||
if (stat(name, &stbuf) == -1) { | if (stat(name, &stbuf) == -1) { | ||||
warn("%s", name); | warn("%s", name); | ||||
▲ Show 20 Lines • Show All 111 Lines • ▼ Show 20 Lines | if ((sp = strdup(sp)) == NULL) | ||||
errx(1, "Out of memory"); | errx(1, "Out of memory"); | ||||
add_dir(hintsfile, sp, 0); | add_dir(hintsfile, sp, 0); | ||||
} | } | ||||
fclose(fp); | fclose(fp); | ||||
} | } | ||||
static void | static void | ||||
read_elf_hints(const char *hintsfile, int must_exist) | read_elf_hints(const char *hintsfile, bool must_exist) | ||||
{ | { | ||||
int fd; | int fd; | ||||
struct stat s; | struct stat s; | ||||
void *mapbase; | void *mapbase; | ||||
struct elfhints_hdr *hdr; | struct elfhints_hdr *hdr; | ||||
char *strtab; | char *strtab; | ||||
char *dirlist; | char *dirlist; | ||||
char *p; | char *p; | ||||
Show All 28 Lines | read_elf_hints(const char *hintsfile, bool must_exist) | ||||
dirlist = strtab + hdr->dirlist; | dirlist = strtab + hdr->dirlist; | ||||
if (*dirlist != '\0') | if (*dirlist != '\0') | ||||
while ((p = strsep(&dirlist, ":")) != NULL) | while ((p = strsep(&dirlist, ":")) != NULL) | ||||
add_dir(hintsfile, p, 1); | add_dir(hintsfile, p, 1); | ||||
} | } | ||||
void | void | ||||
update_elf_hints(const char *hintsfile, int argc, char **argv, int merge) | update_elf_hints(const char *hintsfile, int argc, char **argv, bool merge) | ||||
{ | { | ||||
struct stat s; | |||||
int i; | int i; | ||||
if (merge) | if (merge) | ||||
read_elf_hints(hintsfile, 0); | read_elf_hints(hintsfile, false); | ||||
for (i = 0; i < argc; i++) { | for (i = 0; i < argc; i++) { | ||||
struct stat s; | |||||
if (stat(argv[i], &s) == -1) | if (stat(argv[i], &s) == -1) | ||||
warn("warning: %s", argv[i]); | warn("warning: %s", argv[i]); | ||||
else if (S_ISREG(s.st_mode)) | else if (S_ISREG(s.st_mode)) | ||||
read_dirs_from_file(hintsfile, argv[i]); | read_dirs_from_file(hintsfile, argv[i]); | ||||
else | else | ||||
add_dir(hintsfile, argv[i], 0); | add_dir(hintsfile, argv[i], 0); | ||||
} | } | ||||
write_elf_hints(hintsfile); | write_elf_hints(hintsfile); | ||||
▲ Show 20 Lines • Show All 54 Lines • Show Last 20 Lines |