2003-04-07 16:21:26 +00:00
|
|
|
/*
|
|
|
|
* $FreeBSD$
|
|
|
|
*/
|
|
|
|
|
2012-04-30 21:26:35 +00:00
|
|
|
#include <sys/types.h>
|
2003-04-07 16:21:26 +00:00
|
|
|
#include <sys/param.h>
|
2012-03-12 12:16:08 +00:00
|
|
|
#include <sys/fcntl.h>
|
|
|
|
#include <sys/mman.h>
|
|
|
|
#include <sys/queue.h>
|
|
|
|
#include <sys/stat.h>
|
2012-04-30 21:26:35 +00:00
|
|
|
#include <dirent.h>
|
2012-03-12 12:16:08 +00:00
|
|
|
#include <errno.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
2003-04-07 16:21:26 +00:00
|
|
|
|
2003-05-19 07:10:12 +00:00
|
|
|
#include "debug.h"
|
|
|
|
#include "rtld.h"
|
2003-06-18 05:31:08 +00:00
|
|
|
#include "libmap.h"
|
2015-10-31 04:39:28 +00:00
|
|
|
#include "paths.h"
|
2004-03-21 01:21:26 +00:00
|
|
|
|
2003-04-07 16:21:26 +00:00
|
|
|
TAILQ_HEAD(lm_list, lm);
|
|
|
|
struct lm {
|
|
|
|
char *f;
|
|
|
|
char *t;
|
|
|
|
TAILQ_ENTRY(lm) lm_link;
|
|
|
|
};
|
|
|
|
|
|
|
|
TAILQ_HEAD(lmp_list, lmp) lmp_head = TAILQ_HEAD_INITIALIZER(lmp_head);
|
|
|
|
struct lmp {
|
|
|
|
char *p;
|
2004-05-24 01:24:13 +00:00
|
|
|
enum { T_EXACT=0, T_BASENAME, T_DIRECTORY } type;
|
2003-04-07 16:21:26 +00:00
|
|
|
struct lm_list lml;
|
|
|
|
TAILQ_ENTRY(lmp) lmp_link;
|
|
|
|
};
|
|
|
|
|
2012-04-30 21:26:35 +00:00
|
|
|
static TAILQ_HEAD(lmc_list, lmc) lmc_head = TAILQ_HEAD_INITIALIZER(lmc_head);
|
|
|
|
struct lmc {
|
|
|
|
char *path;
|
|
|
|
TAILQ_ENTRY(lmc) next;
|
|
|
|
};
|
|
|
|
|
2012-03-12 12:16:08 +00:00
|
|
|
static int lm_count;
|
2005-02-04 02:46:41 +00:00
|
|
|
|
2012-03-12 12:16:08 +00:00
|
|
|
static void lmc_parse(char *, size_t);
|
2012-04-30 21:26:35 +00:00
|
|
|
static void lmc_parse_file(char *);
|
|
|
|
static void lmc_parse_dir(char *);
|
2012-03-12 12:16:08 +00:00
|
|
|
static void lm_add(const char *, const char *, const char *);
|
|
|
|
static void lm_free(struct lm_list *);
|
|
|
|
static char *lml_find(struct lm_list *, const char *);
|
|
|
|
static struct lm_list *lmp_find(const char *);
|
|
|
|
static struct lm_list *lmp_init(char *);
|
|
|
|
static const char *quickbasename(const char *);
|
2003-04-07 16:21:26 +00:00
|
|
|
|
2003-04-10 01:44:19 +00:00
|
|
|
#define iseol(c) (((c) == '#') || ((c) == '\0') || \
|
|
|
|
((c) == '\n') || ((c) == '\r'))
|
|
|
|
|
2012-03-05 20:43:06 +00:00
|
|
|
/*
|
|
|
|
* Do not use ctype.h macros, which rely on working TLS. It is
|
|
|
|
* too early to have thread-local variables functional.
|
|
|
|
*/
|
2012-03-06 09:34:30 +00:00
|
|
|
#define rtld_isspace(c) ((c) == ' ' || (c) == '\t')
|
2012-03-05 20:43:06 +00:00
|
|
|
|
2003-09-13 21:43:08 +00:00
|
|
|
int
|
2012-03-12 12:16:08 +00:00
|
|
|
lm_init(char *libmap_override)
|
2003-04-07 16:21:26 +00:00
|
|
|
{
|
2012-04-30 21:26:35 +00:00
|
|
|
char *p;
|
2003-05-31 14:46:38 +00:00
|
|
|
|
2012-03-12 12:16:08 +00:00
|
|
|
dbg("lm_init(\"%s\")", libmap_override);
|
2003-04-07 16:21:26 +00:00
|
|
|
TAILQ_INIT(&lmp_head);
|
|
|
|
|
2012-04-30 21:26:35 +00:00
|
|
|
lmc_parse_file(_PATH_LIBMAP_CONF);
|
2005-02-04 02:46:41 +00:00
|
|
|
|
|
|
|
if (libmap_override) {
|
2012-03-12 12:16:08 +00:00
|
|
|
/*
|
2014-05-18 17:14:08 +00:00
|
|
|
* Do some character replacement to make $LDLIBMAP look
|
2012-03-12 12:16:08 +00:00
|
|
|
* like a text file, then parse it.
|
|
|
|
*/
|
2005-02-04 02:46:41 +00:00
|
|
|
libmap_override = xstrdup(libmap_override);
|
|
|
|
for (p = libmap_override; *p; p++) {
|
|
|
|
switch (*p) {
|
2012-03-12 12:16:08 +00:00
|
|
|
case '=':
|
|
|
|
*p = ' ';
|
|
|
|
break;
|
|
|
|
case ',':
|
|
|
|
*p = '\n';
|
|
|
|
break;
|
2005-02-04 02:46:41 +00:00
|
|
|
}
|
|
|
|
}
|
2014-05-18 17:14:08 +00:00
|
|
|
lmc_parse(libmap_override, p - libmap_override);
|
|
|
|
free(libmap_override);
|
2005-02-04 02:46:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return (lm_count == 0);
|
|
|
|
}
|
|
|
|
|
2012-04-30 21:26:35 +00:00
|
|
|
static void
|
|
|
|
lmc_parse_file(char *path)
|
|
|
|
{
|
|
|
|
struct lmc *p;
|
|
|
|
struct stat st;
|
|
|
|
int fd;
|
|
|
|
char *rpath;
|
|
|
|
char *lm_map;
|
|
|
|
|
|
|
|
rpath = realpath(path, NULL);
|
|
|
|
if (rpath == NULL)
|
|
|
|
return;
|
|
|
|
|
|
|
|
TAILQ_FOREACH(p, &lmc_head, next) {
|
|
|
|
if (strcmp(p->path, rpath) == 0) {
|
|
|
|
free(rpath);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-11-04 21:42:24 +00:00
|
|
|
fd = open(rpath, O_RDONLY | O_CLOEXEC);
|
2012-04-30 21:26:35 +00:00
|
|
|
if (fd == -1) {
|
2012-05-05 16:37:14 +00:00
|
|
|
dbg("lm_parse_file: open(\"%s\") failed, %s", rpath,
|
2012-04-30 21:26:35 +00:00
|
|
|
rtld_strerror(errno));
|
|
|
|
free(rpath);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (fstat(fd, &st) == -1) {
|
|
|
|
close(fd);
|
2012-05-05 16:37:14 +00:00
|
|
|
dbg("lm_parse_file: fstat(\"%s\") failed, %s", rpath,
|
2012-04-30 21:26:35 +00:00
|
|
|
rtld_strerror(errno));
|
|
|
|
free(rpath);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
lm_map = mmap(NULL, st.st_size, PROT_READ, MAP_PRIVATE, fd, 0);
|
|
|
|
if (lm_map == (const char *)MAP_FAILED) {
|
|
|
|
close(fd);
|
2012-05-05 16:37:14 +00:00
|
|
|
dbg("lm_parse_file: mmap(\"%s\") failed, %s", rpath,
|
2012-04-30 21:26:35 +00:00
|
|
|
rtld_strerror(errno));
|
|
|
|
free(rpath);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
close(fd);
|
|
|
|
p = xmalloc(sizeof(struct lmc));
|
|
|
|
p->path = rpath;
|
|
|
|
TAILQ_INSERT_HEAD(&lmc_head, p, next);
|
|
|
|
lmc_parse(lm_map, st.st_size);
|
|
|
|
munmap(lm_map, st.st_size);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
lmc_parse_dir(char *idir)
|
|
|
|
{
|
|
|
|
DIR *d;
|
|
|
|
struct dirent *dp;
|
|
|
|
struct lmc *p;
|
|
|
|
char conffile[MAXPATHLEN];
|
|
|
|
char *ext;
|
|
|
|
char *rpath;
|
|
|
|
|
|
|
|
rpath = realpath(idir, NULL);
|
|
|
|
if (rpath == NULL)
|
|
|
|
return;
|
|
|
|
|
|
|
|
TAILQ_FOREACH(p, &lmc_head, next) {
|
|
|
|
if (strcmp(p->path, rpath) == 0) {
|
|
|
|
free(rpath);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
d = opendir(idir);
|
|
|
|
if (d == NULL) {
|
|
|
|
free(rpath);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
p = xmalloc(sizeof(struct lmc));
|
|
|
|
p->path = rpath;
|
|
|
|
TAILQ_INSERT_HEAD(&lmc_head, p, next);
|
|
|
|
|
|
|
|
while ((dp = readdir(d)) != NULL) {
|
|
|
|
if (dp->d_ino == 0)
|
|
|
|
continue;
|
|
|
|
if (dp->d_type != DT_REG)
|
|
|
|
continue;
|
|
|
|
ext = strrchr(dp->d_name, '.');
|
|
|
|
if (ext == NULL)
|
|
|
|
continue;
|
|
|
|
if (strcmp(ext, ".conf") != 0)
|
|
|
|
continue;
|
|
|
|
if (strlcpy(conffile, idir, MAXPATHLEN) >= MAXPATHLEN)
|
|
|
|
continue; /* too long */
|
|
|
|
if (strlcat(conffile, "/", MAXPATHLEN) >= MAXPATHLEN)
|
|
|
|
continue; /* too long */
|
|
|
|
if (strlcat(conffile, dp->d_name, MAXPATHLEN) >= MAXPATHLEN)
|
|
|
|
continue; /* too long */
|
|
|
|
lmc_parse_file(conffile);
|
|
|
|
}
|
|
|
|
closedir(d);
|
|
|
|
}
|
|
|
|
|
2005-02-04 02:46:41 +00:00
|
|
|
static void
|
2012-03-12 12:16:08 +00:00
|
|
|
lmc_parse(char *lm_p, size_t lm_len)
|
2005-02-04 02:46:41 +00:00
|
|
|
{
|
2012-03-12 12:16:08 +00:00
|
|
|
char *cp, *f, *t, *c, *p;
|
|
|
|
char prog[MAXPATHLEN];
|
2012-04-30 21:26:35 +00:00
|
|
|
/* allow includedir + full length path */
|
|
|
|
char line[MAXPATHLEN + 13];
|
2012-03-12 12:16:08 +00:00
|
|
|
size_t cnt;
|
|
|
|
int i;
|
2012-04-30 21:26:35 +00:00
|
|
|
|
2012-03-12 12:16:08 +00:00
|
|
|
cnt = 0;
|
2003-04-07 16:21:26 +00:00
|
|
|
p = NULL;
|
2012-03-12 12:16:08 +00:00
|
|
|
while (cnt < lm_len) {
|
|
|
|
i = 0;
|
2014-08-21 02:40:33 +00:00
|
|
|
while (cnt < lm_len && lm_p[cnt] != '\n' &&
|
2012-03-12 12:16:08 +00:00
|
|
|
i < sizeof(line) - 1) {
|
|
|
|
line[i] = lm_p[cnt];
|
|
|
|
cnt++;
|
|
|
|
i++;
|
|
|
|
}
|
|
|
|
line[i] = '\0';
|
2014-08-21 02:40:33 +00:00
|
|
|
while (cnt < lm_len && lm_p[cnt] != '\n')
|
2012-03-12 12:16:08 +00:00
|
|
|
cnt++;
|
|
|
|
/* skip over nl */
|
|
|
|
cnt++;
|
|
|
|
|
|
|
|
cp = &line[0];
|
2003-05-30 00:49:16 +00:00
|
|
|
t = f = c = NULL;
|
2003-04-10 01:44:19 +00:00
|
|
|
|
2003-04-07 16:21:26 +00:00
|
|
|
/* Skip over leading space */
|
2012-03-06 09:34:30 +00:00
|
|
|
while (rtld_isspace(*cp)) cp++;
|
2003-04-10 01:44:19 +00:00
|
|
|
|
2003-04-07 16:21:26 +00:00
|
|
|
/* Found a comment or EOL */
|
2003-04-30 19:05:53 +00:00
|
|
|
if (iseol(*cp)) continue;
|
2003-04-10 01:44:19 +00:00
|
|
|
|
|
|
|
/* Found a constraint selector */
|
2003-04-07 16:21:26 +00:00
|
|
|
if (*cp == '[') {
|
|
|
|
cp++;
|
2003-04-10 01:44:19 +00:00
|
|
|
|
2003-04-07 16:21:26 +00:00
|
|
|
/* Skip leading space */
|
2012-03-06 09:34:30 +00:00
|
|
|
while (rtld_isspace(*cp)) cp++;
|
2003-04-10 01:44:19 +00:00
|
|
|
|
2003-04-07 16:21:26 +00:00
|
|
|
/* Found comment, EOL or end of selector */
|
2003-04-30 19:05:53 +00:00
|
|
|
if (iseol(*cp) || *cp == ']')
|
|
|
|
continue;
|
2003-04-10 01:44:19 +00:00
|
|
|
|
2003-05-30 00:49:16 +00:00
|
|
|
c = cp++;
|
2003-04-07 16:21:26 +00:00
|
|
|
/* Skip to end of word */
|
2012-03-06 09:34:30 +00:00
|
|
|
while (!rtld_isspace(*cp) && !iseol(*cp) && *cp != ']')
|
2003-04-30 19:05:53 +00:00
|
|
|
cp++;
|
2003-04-10 01:44:19 +00:00
|
|
|
|
|
|
|
/* Skip and zero out trailing space */
|
2012-03-06 09:34:30 +00:00
|
|
|
while (rtld_isspace(*cp)) *cp++ = '\0';
|
2003-04-10 01:44:19 +00:00
|
|
|
|
|
|
|
/* Check if there is a closing brace */
|
2003-04-30 19:05:53 +00:00
|
|
|
if (*cp != ']') continue;
|
2003-04-10 01:44:19 +00:00
|
|
|
|
|
|
|
/* Terminate string if there was no trailing space */
|
2003-04-07 16:21:26 +00:00
|
|
|
*cp++ = '\0';
|
2003-04-10 01:44:19 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* There should be nothing except whitespace or comment
|
2003-05-29 22:58:26 +00:00
|
|
|
from this point to the end of the line.
|
2003-04-10 01:44:19 +00:00
|
|
|
*/
|
2012-03-06 09:34:30 +00:00
|
|
|
while(rtld_isspace(*cp)) cp++;
|
2003-04-30 19:05:53 +00:00
|
|
|
if (!iseol(*cp)) continue;
|
|
|
|
|
2012-04-30 21:26:35 +00:00
|
|
|
if (strlcpy(prog, c, sizeof prog) >= sizeof prog)
|
|
|
|
continue;
|
2003-04-30 19:05:53 +00:00
|
|
|
p = prog;
|
|
|
|
continue;
|
2003-04-07 16:21:26 +00:00
|
|
|
}
|
2003-04-10 01:44:19 +00:00
|
|
|
|
|
|
|
/* Parse the 'from' candidate. */
|
2003-04-30 19:05:53 +00:00
|
|
|
f = cp++;
|
2012-03-06 09:34:30 +00:00
|
|
|
while (!rtld_isspace(*cp) && !iseol(*cp)) cp++;
|
2003-04-10 01:44:19 +00:00
|
|
|
|
|
|
|
/* Skip and zero out the trailing whitespace */
|
2012-03-06 09:34:30 +00:00
|
|
|
while (rtld_isspace(*cp)) *cp++ = '\0';
|
2003-04-10 01:44:19 +00:00
|
|
|
|
|
|
|
/* Found a comment or EOL */
|
2003-04-30 19:05:53 +00:00
|
|
|
if (iseol(*cp)) continue;
|
2003-04-10 01:44:19 +00:00
|
|
|
|
|
|
|
/* Parse 'to' mapping */
|
2003-04-30 19:05:53 +00:00
|
|
|
t = cp++;
|
2012-03-06 09:34:30 +00:00
|
|
|
while (!rtld_isspace(*cp) && !iseol(*cp)) cp++;
|
2003-05-29 22:58:26 +00:00
|
|
|
|
2003-04-30 19:05:53 +00:00
|
|
|
/* Skip and zero out the trailing whitespace */
|
2012-03-06 09:34:30 +00:00
|
|
|
while (rtld_isspace(*cp)) *cp++ = '\0';
|
2003-04-30 19:05:53 +00:00
|
|
|
|
|
|
|
/* Should be no extra tokens at this point */
|
|
|
|
if (!iseol(*cp)) continue;
|
2003-04-07 16:21:26 +00:00
|
|
|
|
2003-04-30 19:05:53 +00:00
|
|
|
*cp = '\0';
|
2012-04-30 21:26:35 +00:00
|
|
|
if (strcmp(f, "includedir") == 0)
|
|
|
|
lmc_parse_dir(t);
|
|
|
|
else if (strcmp(f, "include") == 0)
|
|
|
|
lmc_parse_file(t);
|
|
|
|
else
|
|
|
|
lm_add(p, f, t);
|
2003-04-07 16:21:26 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
lm_free (struct lm_list *lml)
|
|
|
|
{
|
|
|
|
struct lm *lm;
|
|
|
|
|
2003-05-31 14:46:38 +00:00
|
|
|
dbg("%s(%p)", __func__, lml);
|
|
|
|
|
2003-04-07 16:21:26 +00:00
|
|
|
while (!TAILQ_EMPTY(lml)) {
|
|
|
|
lm = TAILQ_FIRST(lml);
|
|
|
|
TAILQ_REMOVE(lml, lm, lm_link);
|
|
|
|
free(lm->f);
|
|
|
|
free(lm->t);
|
|
|
|
free(lm);
|
|
|
|
}
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
lm_fini (void)
|
|
|
|
{
|
|
|
|
struct lmp *lmp;
|
2012-04-30 21:26:35 +00:00
|
|
|
struct lmc *p;
|
2003-04-07 16:21:26 +00:00
|
|
|
|
2003-05-31 14:46:38 +00:00
|
|
|
dbg("%s()", __func__);
|
|
|
|
|
2012-04-30 21:26:35 +00:00
|
|
|
while (!TAILQ_EMPTY(&lmc_head)) {
|
|
|
|
p = TAILQ_FIRST(&lmc_head);
|
|
|
|
TAILQ_REMOVE(&lmc_head, p, next);
|
|
|
|
free(p->path);
|
|
|
|
free(p);
|
|
|
|
}
|
|
|
|
|
2003-04-07 16:21:26 +00:00
|
|
|
while (!TAILQ_EMPTY(&lmp_head)) {
|
|
|
|
lmp = TAILQ_FIRST(&lmp_head);
|
|
|
|
TAILQ_REMOVE(&lmp_head, lmp, lmp_link);
|
|
|
|
free(lmp->p);
|
|
|
|
lm_free(&lmp->lml);
|
|
|
|
free(lmp);
|
|
|
|
}
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2003-05-30 00:49:16 +00:00
|
|
|
lm_add (const char *p, const char *f, const char *t)
|
2003-04-07 16:21:26 +00:00
|
|
|
{
|
|
|
|
struct lm_list *lml;
|
|
|
|
struct lm *lm;
|
|
|
|
|
|
|
|
if (p == NULL)
|
|
|
|
p = "$DEFAULT$";
|
|
|
|
|
2003-05-31 14:46:38 +00:00
|
|
|
dbg("%s(\"%s\", \"%s\", \"%s\")", __func__, p, f, t);
|
|
|
|
|
2003-04-07 16:21:26 +00:00
|
|
|
if ((lml = lmp_find(p)) == NULL)
|
2003-05-19 07:10:12 +00:00
|
|
|
lml = lmp_init(xstrdup(p));
|
2003-04-07 16:21:26 +00:00
|
|
|
|
2003-05-19 07:10:12 +00:00
|
|
|
lm = xmalloc(sizeof(struct lm));
|
2003-05-30 00:49:16 +00:00
|
|
|
lm->f = xstrdup(f);
|
|
|
|
lm->t = xstrdup(t);
|
2003-04-07 16:21:26 +00:00
|
|
|
TAILQ_INSERT_HEAD(lml, lm, lm_link);
|
2005-02-04 02:46:41 +00:00
|
|
|
lm_count++;
|
2003-04-07 16:21:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
char *
|
|
|
|
lm_find (const char *p, const char *f)
|
|
|
|
{
|
|
|
|
struct lm_list *lml;
|
|
|
|
char *t;
|
|
|
|
|
2003-05-31 14:46:38 +00:00
|
|
|
dbg("%s(\"%s\", \"%s\")", __func__, p, f);
|
|
|
|
|
2003-04-07 16:21:26 +00:00
|
|
|
if (p != NULL && (lml = lmp_find(p)) != NULL) {
|
|
|
|
t = lml_find(lml, f);
|
2003-05-19 07:10:12 +00:00
|
|
|
if (t != NULL) {
|
|
|
|
/*
|
|
|
|
* Add a global mapping if we have
|
|
|
|
* a successful constrained match.
|
|
|
|
*/
|
2003-05-30 00:49:16 +00:00
|
|
|
lm_add(NULL, f, t);
|
2003-04-07 16:21:26 +00:00
|
|
|
return (t);
|
2003-05-19 07:10:12 +00:00
|
|
|
}
|
2003-04-07 16:21:26 +00:00
|
|
|
}
|
|
|
|
lml = lmp_find("$DEFAULT$");
|
|
|
|
if (lml != NULL)
|
|
|
|
return (lml_find(lml, f));
|
|
|
|
else
|
|
|
|
return (NULL);
|
|
|
|
}
|
|
|
|
|
2004-05-24 01:24:13 +00:00
|
|
|
/* Given a libmap translation list and a library name, return the
|
|
|
|
replacement library, or NULL */
|
2004-03-21 01:21:26 +00:00
|
|
|
char *
|
|
|
|
lm_findn (const char *p, const char *f, const int n)
|
|
|
|
{
|
|
|
|
char pathbuf[64], *s, *t;
|
|
|
|
|
2006-01-31 06:08:28 +00:00
|
|
|
if (n < sizeof(pathbuf) - 1)
|
2004-03-21 01:21:26 +00:00
|
|
|
s = pathbuf;
|
2006-01-31 06:08:28 +00:00
|
|
|
else
|
2004-03-21 01:21:26 +00:00
|
|
|
s = xmalloc(n + 1);
|
2006-01-31 06:08:28 +00:00
|
|
|
memcpy(s, f, n);
|
|
|
|
s[n] = '\0';
|
2004-03-21 01:21:26 +00:00
|
|
|
t = lm_find(p, s);
|
|
|
|
if (s != pathbuf)
|
|
|
|
free(s);
|
|
|
|
return (t);
|
|
|
|
}
|
|
|
|
|
2003-04-07 16:21:26 +00:00
|
|
|
static char *
|
|
|
|
lml_find (struct lm_list *lmh, const char *f)
|
|
|
|
{
|
|
|
|
struct lm *lm;
|
|
|
|
|
2003-05-31 14:46:38 +00:00
|
|
|
dbg("%s(%p, \"%s\")", __func__, lmh, f);
|
|
|
|
|
2003-04-07 16:21:26 +00:00
|
|
|
TAILQ_FOREACH(lm, lmh, lm_link)
|
2004-03-21 01:21:26 +00:00
|
|
|
if (strcmp(f, lm->f) == 0)
|
2003-04-07 16:21:26 +00:00
|
|
|
return (lm->t);
|
2005-02-04 02:13:37 +00:00
|
|
|
return (NULL);
|
2003-04-07 16:21:26 +00:00
|
|
|
}
|
|
|
|
|
2004-05-24 01:24:13 +00:00
|
|
|
/* Given an executable name, return a pointer to the translation list or
|
|
|
|
NULL if no matches */
|
2003-04-07 16:21:26 +00:00
|
|
|
static struct lm_list *
|
|
|
|
lmp_find (const char *n)
|
|
|
|
{
|
|
|
|
struct lmp *lmp;
|
|
|
|
|
2003-05-31 14:46:38 +00:00
|
|
|
dbg("%s(\"%s\")", __func__, n);
|
|
|
|
|
2003-04-07 16:21:26 +00:00
|
|
|
TAILQ_FOREACH(lmp, &lmp_head, lmp_link)
|
2004-05-24 01:24:13 +00:00
|
|
|
if ((lmp->type == T_EXACT && strcmp(n, lmp->p) == 0) ||
|
|
|
|
(lmp->type == T_DIRECTORY && strncmp(n, lmp->p, strlen(lmp->p)) == 0) ||
|
|
|
|
(lmp->type == T_BASENAME && strcmp(quickbasename(n), lmp->p) == 0))
|
2003-04-07 16:21:26 +00:00
|
|
|
return (&lmp->lml);
|
|
|
|
return (NULL);
|
|
|
|
}
|
|
|
|
|
|
|
|
static struct lm_list *
|
|
|
|
lmp_init (char *n)
|
|
|
|
{
|
|
|
|
struct lmp *lmp;
|
|
|
|
|
2003-05-31 14:46:38 +00:00
|
|
|
dbg("%s(\"%s\")", __func__, n);
|
|
|
|
|
2003-05-19 07:10:12 +00:00
|
|
|
lmp = xmalloc(sizeof(struct lmp));
|
2003-04-07 16:21:26 +00:00
|
|
|
lmp->p = n;
|
2004-05-24 01:24:13 +00:00
|
|
|
if (n[strlen(n)-1] == '/')
|
|
|
|
lmp->type = T_DIRECTORY;
|
|
|
|
else if (strchr(n,'/') == NULL)
|
|
|
|
lmp->type = T_BASENAME;
|
|
|
|
else
|
|
|
|
lmp->type = T_EXACT;
|
2003-04-07 16:21:26 +00:00
|
|
|
TAILQ_INIT(&lmp->lml);
|
|
|
|
TAILQ_INSERT_HEAD(&lmp_head, lmp, lmp_link);
|
|
|
|
|
|
|
|
return (&lmp->lml);
|
|
|
|
}
|
2004-05-24 01:24:13 +00:00
|
|
|
|
|
|
|
/* libc basename is overkill. Return a pointer to the character after the
|
|
|
|
last /, or the original string if there are no slashes. */
|
|
|
|
static const char *
|
|
|
|
quickbasename (const char *path)
|
|
|
|
{
|
|
|
|
const char *p = path;
|
2005-02-04 02:13:37 +00:00
|
|
|
for (; *path; path++) {
|
2004-05-24 01:24:13 +00:00
|
|
|
if (*path == '/')
|
|
|
|
p = path+1;
|
|
|
|
}
|
2005-02-04 02:13:37 +00:00
|
|
|
return (p);
|
2004-05-24 01:24:13 +00:00
|
|
|
}
|