diff --git a/libexec/rtld-elf/libmap.c b/libexec/rtld-elf/libmap.c index e710fd586b29..4705bc69d125 100644 --- a/libexec/rtld-elf/libmap.c +++ b/libexec/rtld-elf/libmap.c @@ -33,6 +33,7 @@ struct lm { TAILQ_HEAD(lmp_list, lmp) lmp_head = TAILQ_HEAD_INITIALIZER(lmp_head); struct lmp { char *p; + enum { T_EXACT=0, T_BASENAME, T_DIRECTORY } type; struct lm_list lml; TAILQ_ENTRY(lmp) lmp_link; }; @@ -42,6 +43,7 @@ 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 *); #define iseol(c) (((c) == '#') || ((c) == '\0') || \ ((c) == '\n') || ((c) == '\r')) @@ -216,6 +218,8 @@ lm_find (const char *p, const char *f) return (NULL); } +/* Given a libmap translation list and a library name, return the + replacement library, or NULL */ #ifdef COMPAT_32BIT char * lm_findn (const char *p, const char *f, const int n) @@ -250,6 +254,8 @@ lml_find (struct lm_list *lmh, const char *f) return NULL; } +/* Given an executable name, return a pointer to the translation list or + NULL if no matches */ static struct lm_list * lmp_find (const char *n) { @@ -258,7 +264,9 @@ lmp_find (const char *n) dbg("%s(\"%s\")", __func__, n); TAILQ_FOREACH(lmp, &lmp_head, lmp_link) - if (strcmp(n, lmp->p) == 0) + 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)) return (&lmp->lml); return (NULL); } @@ -272,8 +280,28 @@ lmp_init (char *n) lmp = xmalloc(sizeof(struct lmp)); lmp->p = n; + if (n[strlen(n)-1] == '/') + lmp->type = T_DIRECTORY; + else if (strchr(n,'/') == NULL) + lmp->type = T_BASENAME; + else + lmp->type = T_EXACT; TAILQ_INIT(&lmp->lml); TAILQ_INSERT_HEAD(&lmp_head, lmp, lmp_link); return (&lmp->lml); } + +/* 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; + for (; *path; path++) + { + if (*path == '/') + p = path+1; + } + return p; +} diff --git a/share/man/man5/libmap.conf.5 b/share/man/man5/libmap.conf.5 index b89d2e449a31..eb2987e427c7 100644 --- a/share/man/man5/libmap.conf.5 +++ b/share/man/man5/libmap.conf.5 @@ -46,14 +46,44 @@ Dependencies are matched against candidates and replaced with the mappings. Constrained mappings may be specified by enclosing the name of the executable or library in brackets. All mappings following a constraint will only be evaluated for that constraint. -Currently, constraints -are matched literally so that an executable with a fully qualified pathname -will only match the same constraint. -This means that +Constraints can be one of three types: +.Bl -tag -width indent +.It Exact +The constraint is matched literally so that only an executable with an +identical fully qualified pathname will match the constraint. +This means that the executable .Pa /usr/bin/foo will not match a constraint for -.Pa foo +.Pa /usr/bin/./foo and vise-versa. +This is the default constraint type. +.It Basename +A constraint with no path is matched against the basename of the +executable. +.Pa foo +will match +.Pa /bin/foo , +.Pa /usr/local/sbin/foo , +or any other executable named +.Pa foo , +no matter what its path is. +.It Directory +A constraint with a trailing slash is prefix-matched against the full +pathname of the executable. +.Pa /usr/bin/ +will match any executable with a path starting with /usr/bin. +.El +.Pp +Note that the executable path matched against is the +.Pa path +parameter in an +.Fn exec* +function call. +The Directory or Exact constraints can only match when the executable +is called with a full pathname. +Most programs executed from a shell are run without a full path, via +.Fn exec*p , +so the Basename constraint type is the most useful. .Pp WARNING! Constrained mappings must never appear first in the configuration file. @@ -77,19 +107,17 @@ libpthread.so libpthread.so libc_r.so.5 libpthread.so.1 # Everything that uses 'libc_r' libc_r.so libpthread.so # now uses 'libpthread' -[/usr/local/bin/mplayer] # 'mplayer' uses libc_r. +[/tmp/mplayer] # Test version of mplayer uses libc_r libpthread.so.1 libc_r.so.5 libpthread.so libc_r.so -[mplayer] -libpthread.so.1 libc_r.so.5 -libpthread.so libc_r.so +[mplayer] # All other mplayers use libpthread +libpthread.so.1 libpthread.so.1 +libpthread.so libpthread.so -[/usr/local/sbin/httpd] # Apache uses libthr -libpthread.so.1 libthr.so.1 -libpthread.so libthr.so - -[httpd] +[/usr/local/jdk1.4.1/] # All Java 1.4.1 programs use libthr + # This works because "javavms" executes + # programs with the full pathname libpthread.so.1 libthr.so.1 libpthread.so libthr.so .Ed