* On linux, if a binary is running as sgid or suid, glibc sets
* LD_LIBRARY_PATH to the empty string for security purposes. (In
* contrast, on Solaris the LD_LIBRARY_PATH variable for a
* privileged binary does not lose its settings; but the dynamic
* linker does apply more scrutiny to the path.) The launcher uses
* the value of LD_LIBRARY_PATH to prevent an exec loop.
* Therefore, if we are running sgid or suid, this function's
* setting of LD_LIBRARY_PATH will be ineffective and we should
* return from the function now. Getting the right libraries to
* be found must be handled through other mechanisms.
*/
if((getgid() != getegid()) || (getuid() != geteuid()) ) {
return;
}
#endif
/* runpath contains current effective LD_LIBRARY_PATH setting */
jvmpath = JLI_StringDup(jvmpath);
new_runpath = JLI_MemAlloc( ((runpath!=NULL)?strlen(runpath):0) +
2*strlen(jrepath) + 2*strlen(arch) +
strlen(jvmpath) + 52);
newpath = new_runpath + strlen("LD_LIBRARY_PATH=");
/*
* Create desired LD_LIBRARY_PATH value for target data model.
*/
{
/* remove the name of the .so from the JVM path */
lastslash = strrchr(jvmpath, '/');
if (lastslash)
*lastslash = '\0';
/* jvmpath, ((running != wanted)?((wanted==64)?"/"LIBARCH64NAME:"/.."):""), */
sprintf(new_runpath, "LD_LIBRARY_PATH="
"%s:"
"%s/lib/%s:"
"%s/../lib/%s",
jvmpath,
#ifdef DUAL_MODE
jrepath, ((wanted==64)?LIBARCH64NAME:LIBARCH32NAME),
jrepath, ((wanted==64)?LIBARCH64NAME:LIBARCH32NAME)
#else
jrepath, arch,
jrepath, arch
#endif
);
/*
* Check to make sure that the prefix of the current path is the
* desired environment variable setting.
*/
if (runpath != NULL &&
strncmp(newpath, runpath, strlen(newpath))==0 &&
(runpath[strlen(newpath)] == 0 || runpath[strlen(newpath)] == ':') &&
(running == wanted) /* data model does not have to be changed */
#ifdef __sun
&& (dmpath == NULL) /* data model specific variables not set */
#endif
) {
return;
}
}
/*
* Place the desired environment setting onto the prefix of
* LD_LIBRARY_PATH. Note that this prevents any possible infinite
* loop of execv() because we test for the prefix, above.
*/
if (runpath != 0) {
strcat(new_runpath, ":");
strcat(new_runpath, runpath);
}
if( putenv(new_runpath) != 0) {
exit(1); /* problem allocating memory; LD_LIBRARY_PATH not set
properly */
}
/*
* Unix systems document that they look at LD_LIBRARY_PATH only
* once at startup, so we have to re-exec the current executable
* to get the changed environment variable to have an effect.
*/
#ifdef __sun
/*
* If dmpath is not NULL, remove the data model specific string
* in the environment for the exec'ed child.
*/
if( dmpath != NULL)
(void)UnsetEnv((wanted==32)?"LD_LIBRARY_PATH_32":"LD_LIBRARY_PATH_64");
#endif
=5= |