简体   繁体   English

在Linux中写入命名管道的最佳,最安全的方法是什么?

[英]What is the best, most secure way to write to a named pipe in Linux?

What is the best, secure way to write to a named pipe in Linux? 在Linux中写入命名管道的最佳安全方法是什么? Or, how can I make a named pipe secure? 或者,如何使命名管道安全?

Here's how I write to the pipe on linux using PHP: 这是我使用PHP在Linux上写入管道的方式:

$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: 这就是我在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. 您可以使用umask来控制所创建文件的权限。 You also have chmod in php as well. 您也有php中的chmod

However, you also have posix_mkfifo available, which exactly fits your purpose: 但是,您也可以使用posix_mkfifo ,它完全符合您的目的:

bool posix_mkfifo ( string $pathname , int $mode ) bool posix_mkfifo (字符串$ pathname ,int $ mode

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM