I tried to edit files by using nano and rnano. The latter is really in restrict mode, but they are exactly same binary files. Why do they behave differently?
# which nano rnano
/usr/bin/nano
/bin/rnano
# md5sum /usr/bin/nano /bin/rnano
fa670e309a033718bad4b2051f5974fd /usr/bin/nano
fa670e309a033718bad4b2051f5974fd /bin/rnano
(In ubuntu 12.04 x64 LTS)
They behave differently because of the argument vector (
argv
), whose first element (argv[0]
) contains the name of the file being executed.Because
rnano
is a separate file fromnano
(even though it is just a symbolic link), it has its own, separateargv[0]
.You can see this check in nano.c's main function:
You can also test this with a simple shell script. Create a shell script with only one statement,
echo $0
. Then, create a symbolic link to it with a separate name. Observe the difference.