我是靠谱客的博主 合适老虎,这篇文章主要介绍access and faccessat 按照实际用户Id和实际组ID进行文件权限测试,现在分享给大家,希望可以做个参考。

一、源代码:

<bldc:/home/tingbinz/apue.3e/SBSCODE/4>R*_*G:vim 4_8.c
  1 #include "apue.h"
  2 #include <fcntl.h>
  3
  4 int main(int argc, char *argv[])
  5 {
  6         if ( argc != 2 )
  7                 err_quit("Usage: access <pathname>");
  8         if ( access(argv[1], R_OK) < 0 )
  9                 err_ret("access error");
 10         else
 11                 printf("real user id has read permission of %sn",argv[1]);
 12         if ( open(argv[1],O_RDONLY) < 0 )
 13                 err_ret("open error");
 14         else
 15                 printf("open file %s successfullyn", argv[1]);
 16
 17         exit(0);
 18
 19 }
 20
~


二、运行结果:

<bldc:/home/tingbinz/apue.3e/SBSCODE/4>R*_*G:access error.c
real user id has read permission of error.c
open file error.c successfully
<bldc:/home/tingbinz/apue.3e/SBSCODE/4>R*_*G:access /etc/passwd
real user id has read permission of /etc/passwd
open file /etc/passwd successfully
<bldc:/home/tingbinz/apue.3e/SBSCODE/4>R*_*G:access /etc/shadow
access error: Permission denied
open error: Permission denied
<bldc:/home/tingbinz/apue.3e/SBSCODE/4>R*_*G:


最后

以上就是合适老虎最近收集整理的关于access and faccessat 按照实际用户Id和实际组ID进行文件权限测试的全部内容,更多相关access内容请搜索靠谱客的其他文章。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(49)

评论列表共有 0 条评论

立即
投稿
返回
顶部