Closed rtczza closed 1 year ago
In your test you open fds 4-5 but then run "sudo -C 4" which closes fds 4 and up. Here's what I see with sudo 1.9.14p3:
$ exec 4<>/dev/null && exec 5<>/dev/null && ls /dev/fd
0 1 2 3 4 5
$ exec 4<>/dev/null && exec 5<>/dev/null && sudo ls /dev/fd
0 1 2 3
$ exec 4<>/dev/null && exec 5<>/dev/null && sudo -C 6 ls /dev/fd
0 1 2 3 4 5
The use case for the -C option is to be able to preserve inherited file descriptors that sudo would otherwise close. It is only allowed if sudoers has the _closefromoverride option enabled for the invoking user.
Thanks, I've already enabled closefrom_override in sudoers
According to the command you provided, I have tested on 1.8.29, and the situation is the same as that of 1.9.14p3, which meets my expectations.
[test@localhost sudo]$ sudo -V
Sudo version 1.8.29
Sudoers policy plugin version 1.8.29
Sudoers file grammar version 46
Sudoers I/O plugin version 1.8.29
[test@localhost sudo]$
[test@localhost sudo]$ exec 4<>/dev/null && exec 5<>/dev/null && ls /dev/fd
0 1 2 3 4 5
[test@localhost sudo]$ exec 4<>/dev/null && exec 5<>/dev/null && sudo ls /dev/fd
0 1 2 3
[test@localhost sudo]$
[test@localhost sudo]$ exec 4<>/dev/null && exec 5<>/dev/null && sudo -C 5 ls /dev/fd
0 1 2 3 4
[test@localhost sudo]$
Thanks again
but,
exec 4<>1.txt && echo $$ && exec 5<>2.txt && ls /proc/`echo $$`/fd -l && echo $$ && sudo -C 4 echo $$ && ls /proc/`echo $$`/fd -l && echo $$
Why not closes fds 4 and up, I don't think clearly. Don't know what's wrong with it
In your example you are listing the file descriptors that are open in the shell, which is sudo's parent process. The fds are only closed in the sudo process itself and the command it runs, which in your example is echo
. Changes in a child process do not affect the parent.
The -C parameter is described as follows:
Using the following command, first create 2 fd and then use sudo -C, and there is no difference between using the -C parameter.
The question I want to ask you is how to use the -C parameter, or how to prove that the -C parameter works. What is the application scenario of the -C parameter?
Thank you very much and look forward to your reply.