Reputation: 16837
Referring the tutorial on system V message queue.
It contains the following sample for ftok
:
#include <sys/msg.h>
key = ftok("/home/beej/somefile", 'b');
msqid = msgget(key, 0666 | IPC_CREAT);
Why is it necessary for the file (/home/beej/somefile) to be readable by the process to generate the key for message queue ?
Also, is it easy for an attacker to just guess the key value for message queue (key's type is long) ?
Upvotes: 0
Views: 328
Reputation: 916
As of man page of ftok, file should be accessible (not readable):
The ftok() function uses the identity of the file named by the given pathname (which must refer to an existing, accessible file)
At least the process have to stat it. You can test it with totally unreadable file but in directory which you can access and the file which is word readable but in directory you can not access.
As per attacker question may be it will be easier for attacker if he knows file which is used and trying to guess proj_id
which as per man page again: Today proj_id is an int, but still only 8 bits are used.
Upvotes: 1