|
Bugzilla – Full Text Bug Listing |
| Summary: | sudo drops command output | ||
|---|---|---|---|
| Product: | Sudo | Reporter: | bob.schwartz |
| Component: | Sudo | Assignee: | Todd C. Miller <Todd.Miller> |
| Status: | RESOLVED FIXED | ||
| Severity: | normal | ||
| Priority: | low | ||
| Version: | 1.9.11 | ||
| Hardware: | PC | ||
| OS: | Linux | ||
|
Description
bob.schwartz
2022-08-10 15:18:19 MDT
This happens because you are passing the script to bash on the standard input. When "sudo ls" runs, because log_input it enabled, it will read from the standard input in order to log it. However, this means that sudo will read (and log) the standard input passed to the shell. As a result, after sudo finishes the shell reads end of file instead of the next command. Sudo has no way to distinguish between input meant for the parent shell and input meant for the command being run.
If you check the input log for the command you should see the rest of the shell script there. For example, in my case:
# cat /var/log/sudo-io/00/00/IQ/stdin
echo "end script"
As a work-around you can either:
1. make the script executable and run it directly instead of passing to bash on standard input. In other words:
chmod 755 tst.sh
./tst.sh
2. redirect standard input for the sudo command from /dev/null. For example:
#!/bin/bash
echo "start script"
sudo ls < /dev/null
echo "end script"
will work with:
bash -s < ./tst.sh
because "sudo ls" will get EOF reading from standard input.
3. Disable log_input in sudoers for commands you know will never read from standard input. For example:
Cmnd_Alias NO_INPUT = /usr/bin/ls, /usr/bin/echo, /usr/bin/printf
Defaults!NO_INPUT !log_input
A future version of sudo may include finer-grained controls for logging input and output that should make it possible to opt out of logging standard input or standard output while still logging terminal input/output.
Sudo 1.9.12 includes support for logging terminal input/output without also consuming the standard input, output or error. |