Make sure doasedit can work when target file to edit has a leading slash

character. ie A full path name is used.

Update doas.1 manual page to indicate problems with piping input
on Linux when processes are launched by doas.
This commit is contained in:
Jesse Smith 2024-05-10 14:16:18 -03:00
parent 7c3981ce28
commit 23818b138e
2 changed files with 12 additions and 6 deletions

5
doas.1
View file

@ -110,6 +110,11 @@ The password was incorrect.
.It
The specified command was not found or is not executable.
.El
.Sh BUGS
On Linux it is not possible to pipe output from other commands into commands run by doas.
For example, "echo hello | doas tee abc" would not work on Linux.
On other platforms, such as FreeBSD, output from another command can be piped to programs
run by doas.
.Sh SEE ALSO
.Xr su 1 ,
.Xr doas.conf 5

View file

@ -38,7 +38,8 @@ then
fi
mydir=$(dirname -- "$1")
cp "$mydir/$1" "$temp_file"
myfile=$(basename -- "$1")
cp "$mydir/$myfile" "$temp_file"
status=$?
if [ $status -ne 0 ]
then
@ -66,7 +67,7 @@ then
fi
# Check to see if the file has been changed.
cmp -s "$mydir/$1" "$temp_file"
cmp -s "$mydir/$myfile" "$temp_file"
status=$?
if [ $status -eq 0 ]
then
@ -78,16 +79,16 @@ fi
# At this point the file has been changed. Make sure it still exists.
if [ -f "$temp_file" ]
then
doas cp "$temp_file" "$mydir/$1"
cmp -s "$temp_file" "$mydir/$1"
doas cp "$temp_file" "$mydir/$myfile"
cmp -s "$temp_file" "$mydir/$myfile"
status=$?
# If file fails to copy, do not do clean-up
while [ $status -ne 0 ]
do
echo "Copying file back to $1 failed. Press Ctrl-C to abort or Enter to try again."
read abc
doas cp "$temp_file" "$mydir/$1"
cmp -s "$temp_file" "$mydir/$1"
doas cp "$temp_file" "$mydir/$myfile"
cmp -s "$temp_file" "$mydir/$myfile"
status=$?
done
fi