What is the best, secure way to write to a named pipe in Linux? Or, how can I make a named pipe secure?
Here's how I write to the pipe on linux using PHP:
$con = fopen("/tmp/myFIFO", "w");
fwrite($con, "UP\n");
fclose($con);
I wish to make it more secure.
This is how I create the pipe in C:
int pc;
char mode[] = "0777";
int i = strtol(mode, 0, 8);
pc = mkfifo(FIFO, 0);
if(pc < 0) {
printf("Failed in creating a pipe\n");
printf("Exiting...\n");
exit(1);
}
else {
printf("Success in Creating Pipe\n");
chmod("/tmp/myFIFO", i);
}
You can use umask
to control the permissions of the files you create. You also have chmod
in php as well.
However, you also have posix_mkfifo
available, which exactly fits your purpose:
bool posix_mkfifo ( string $pathname , int $mode )
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.