c++ - setuid bit on, yet program can't open a superuser file -
i have file superuser.cpp
created superuser access permissions 770
. now, superuser creates file setuiddemonstration.cpp
in superuser.cpp opened using open("superuser.cpp", o_rdonly).
.cpp , object file of setuiddemonstration.cpp have permissions rwxrwxr-x
. now, questions are:-
when ran program setuiddemonstration, in both normal , superuser mode not open superuser.cpp. why? @ least, superuser mode should have succeeded in opening it.
now,
sudo chmod 4775 setuiddemonstration
. should allow program open superuser.cpp in normal mode because euid of superuser during execution setuid bit has been set whensudo chmod 4775 setuiddemonstration
had been run. couldn't. also, when printed euid while running normal mode, printed1000
, not0
. why?
update: pointing out mistake. have removed '/' file path , work superuser. after sudo chmod 4775 setuiddemonstration, normal mode run program falis open file. pls explain.
because /superuser.cpp
name of file in filesystem root, not in current working directory. use superuser.cpp
or ./superuser.cpp
if file in same path when run program.
Comments
Post a Comment