3

I have an executible which requires root privilages. But it seems to work only when it's present in the system path. When I execute it like this:

$ ./prog

The program complains of having no root access. Looks like it's another security restriction on suid programs, but I've searched and I can't find anything related to it on the net. Why does it work like that? And is there an elegant way to do some testing on this program other than adding . to PATH, or calling make as root?

Edit: It doesn't work even when the current directory is in PATH.

  • What is the error message? and what is the output of ls -ld ./prog? – ctrl-alt-delor Dec 24 '18 at 11:28
3

There is nothing whatsoever special about which pathname you use to invoke a program that can make a difference to whether or not its setuid bit will be honoured. It is certain that one of two things is happening here. Either

  • the prog found in the $PATH and the prog found in the current directory are not in fact the same prog. Are you sure that prog alone is finding the same copy of prog via the $PATH?
    • (Exception: I can think of an unlikely edge case here where they might be the same file as in they are the same inode, but they are reached via different mount points, one of which has nosuid and one of which doesn't.)
  • prog itself is consulting its argv[0] to see how it was invoked and is refusing to act on its setuid powers (or is dropping them) if it doesn't find what it expects.
  • The $HOME/bin and home partition are different on my pc and the bin folder mounts with suid option. And I've checked the source and the program starts arg parsing from position 1. And no, I don't have another copy of that program in my path. – saga Jan 22 '17 at 15:32
  • The prog actually tries to read /etc/shadow, and complains if it's unsuccessful. – saga Jan 23 '17 at 6:31

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.