Question

I have an executable which is dynamically linked to foo.so.0 and bar.so.0. The problem is that when I try to run the executable the loader cannot find the dynamically linked libraries. (The executable was linked to a static library which loaded the dynamic version so I dont control any of that directly). I found that I can edit LD_LIBRARY_PATH to include the current directory and then it will find it. The problem is that when the program is run as root, for some reason it still cant find the library. Is the LD_LIBRARY_PATH approach the wrong one? If it is acceptable then why does the program not find the library when run under sudo?

Was it helpful?

Solution

Antons answer: if it's your program, you can use ld's -rpath (gcc's -Wl,-rpath) to modify library search path for it. (Not that it doesn't feel like a hack too). Or you can install a script starting the program with LD_LIBRARY_PATH. Or you can put the libraries where they are searched by default.

OTHER TIPS

By default sudo doesn't propagate environment variables, especially dangerous ones like LD_LIBRARY_PATH -- this is by design because otherwise an unprivileged user could inject libraries into a privileged process by setting environment variables, which would be a pretty huge security hole.

Probably the best solution would be to have a separate launcher stub which can set up the environment for your main program. For instance, you could have a setuid program that could launch your main program, or you could have a shell script that users would launch, that would construct the appropriate sudo command.

But this feels like a case of if it hurts, don't do that then. It sounds like you're intentionally trying to circumvent normal security and administrative measures on a system, which is usually a bad idea. It sounds like you may have an X-Y problem, so you might be better served by trying to explain what you're actually trying to do, instead of asking about how you're trying to do it.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top