1、 运行二进制文件和脚本文件时,如何设置权限?
二进制文件,需要执行权限。
脚本文件,需要读和执行权限
2、 目录的执行位有何用途?
目录的执行位,能够遍历文件的索引节点,找到相应的文件
有目录的执行位,才能操作相应的文件或目录
3、 读/home/abc/aaa.txt文件所需权限?删除/home/abc/aaa.txt需要什么权限?
读/home/abc/aaa.txt文件
删除/home/abc:
目录 / /home /abc 具有读和执行权限
目录 abc 具有写权限
4、 用fork创建进程,和用exec执行文件的进程,其euid,suid,ruid分别有何差别?
Fork创建的进程,子进程和父进程的euid,suid,ruid相同
exec执行设置setuid位的程序,euid为root,ruid是登录用户id,suid为0或登录用户id
5、 函数setuid含义在不同操作系统版本以及不同情况下结果不同,请问如何避免歧义?
Setuid函数中不同操作系统,不同版本下含义不同。
使用seteuid,setreuid,setresuid函数,含义清晰。
也可以使用封装函数drop_priv_temp,drop_priv_perm,restore_priv等。或者自己封装函数。
不使用setuid函数,这个函数是有歧义的,使用后euid与设想的不同,造成程序以高权限运行。
6、 文件、目录的权限设置
读文件,需要文件的读权限,层层目录的读和执行权限。
运行可执行文件,需要文件的执行权限,层层目录的读和执行权限。
脚本文件,运行时需要读和执行权限。
硬连接,删除时,需要找到文件的inode指针,对inode指针里的链接数进行修改,当硬连接数大于1的时候不能删除该文件。硬连接数为1的时候删除该文件。
- write the file /d1/d2/f3
x on / and /d1 and /d2, w on f3 - delete the file /d1/d2/f3
x and w on /d1/d2, x on / and /d1 - execute the file /d1/d2/f3, which is a binary file
x on f3 and / and /d1 and /d1/d2, - execute the file /d1/d2/f3, which is a shell script
r and x on f3, x on / and /d1 and /d2 - list the file names under the directory /d1/d2s
x on / and /d1 , r on /d2s - delete the directory /d1/d2, where the directory is empty
x on / and /d1, w on /d1 - delete the directory /d1/d2, where /d1/d2 contains one file /d1/d2/f3
x on / and /d1, w on /d1, w and x on /d2 - delete the directory /d1/d2, where /d1/d2 contains a subdirectory /d1/d2/d3, which contains one file /d1/d2/d3/f4
x on / , w and x on /d1, w and x on /d1/d2, w and x on /d1/d2/d3 - create the directory /d1/d2/d3, when /d1/d2 exists, and /d1/d2/d3 does not
x on / and /d1, x and w and r on /d1/d2 - rename a file from /d1/d2/f3 to /d1/d2/f4
改文件名,需要文件夹的w权限
x on / and /d1, w and x on /d2 - create a hard link /d1/d2/f3, which points to /d4/f5
/d2文件夹有写权限, f5文件有写权限
x on / and /d1 , x and w on /d2,
r and x on /d4, w on f5 - remove /d1/d2/f3, which is a hard link pointing to /d4/f5
回答:/d2有wx权限,f5有w权限
x on / and /d1 , w and x on /d1/d2 , 对目录d2要有写和执行权限
r and x on /d4,w on f5对文件有写权限才能修改连接数 - create a symbolic link /d1/d2/f3, which points to the directory /d4
Symbolic link 符号链接
回答:目录d2有wx权限,f3有rx权限
x on / and /d1 and /d2, w on /d2, r x on f3
14 read the file /d1/d2/f3/f5, where /d1/d2/f3 is a symbolic link pointing to the directory /d4, and /d4 contains a file /d4/f5。读文件/d1/d2/f3/f5,/d1/d2/f3是符号链接执向目录/d4,/d4目录下包含文件d5
回答:符号链接文件f3有rx权限,/d4有x权限,f5有r权限
x on / and /d1 and /d2
rx on f3 , rx on /d4 , r on f5
15 delete the file /d1/d2/f3/f5, in the same setting as above
回答:
x on / and /d1 and /d1/d2 and /d4 , w on f3 and /d4