tags:

views:

125

answers:

4

I have a Linux application that uses the libsctp.so library. When I run it as root, it runs fine.

But when I run it as an ordinary user, it gives the following error:

error while loading shared libraries: libsctp.so.1: cannot open shared object file: No such file or directory

But, when I do ldd as ordinary user, it is able to see the library:

[sanjeev@devtest6 src]$ ldd myapp

  ...
   ...
  libsctp.so.1 => /usr/local/lib/libsctp.so.1 (0x00d17000)

[sanjeev@devtest6 src]$ ls -lL /usr/local/lib/libsctp.so.1

-rwxrwxrwx 1 root root 27430 2009-06-29 11:26 /usr/local/lib/libsctp.so.1

[sanjeev@devtest6 src]$

What could be wrong? How is the ldd is able to find libsctp.so, but when actually running the app, it is not able to find the same library?

EDIT: Just observed that this problem appears only if setuid bit is set for myapp.

A: 

It could be because of environment setting difference.

You may need to add /usr/local/lib/ to LIBRARY_PATH or kind of.

S.Mark
I already have /usr/local/lib in LD_LIBRARY_PATH. AFAIK, ldd is also dependent on the same environment setting.
sankoz
@sankoz, I see, if me, I will just do `env | grep "/usr/local/lib/"` on root and will try to copy all matched lines to non-root user too. It could even need to add to PATH, which is not so normal though.
S.Mark
@S.Mark, the only env variable is PATH, which I have copied.
sankoz
A: 

You can recieve that error if a shared library that libsctp.so itself depends on is not found (yes, it is a little confusing). Try ldd on the library itself:

ldd /usr/local/lib/libsctp.so.1
caf
ldd on the library is working fine.[sanjeev@devtest6 src]$ ldd /usr/local/lib/libsctp.so.1 linux-gate.so.1 => (0x0034a000) libc.so.6 => /lib/libc.so.6 (0x008ec000) /lib/ld-linux.so.2 (0x0070b000)
sankoz
A: 

Are you setting LD_LIBRARY_PATH before switching to root user or after that? When you run ldd as root does it still find all dependent libraries?

dmitry@debian:~$ echo $LD_LIBRARY_PATH

dmitry@debian:~$ export LD_LIBRARY_PATH=/usr/local/lib
dmitry@debian:~$ echo $LD_LIBRARY_PATH
/usr/local/lib
dmitry@debian:~$ su
Password:
debian:/home/dmitry# echo $LD_LIBRARY_PATH

debian:/home/dmitry#
Dmitry Yudakov
I have set LD_LIBRARY_PATH in both cases (root and non-root). ldd as root and non-root yield the same result.
sankoz
A: 

Fixed the problem. I added a new file in /etc/ld.so.conf.d with the followng name:

libsctp.so.1.conf

The contents of libsctp.so.1.conf is as follows:

/usr/local/lib/

And then ran

/sbin/ldconfig

, after which my app ran successfully.

Explanation: Since the setuid bit was set, the program is executed as root, for whom LD_LIBRARY_PATH is not available. Hence it is not able to find libsctp.so. I was not aware of this because when I login as root, .bashrc gets executed and LD_LIBRARY_PATH becomes available.

sankoz