Page 1 of 1

[Solved] cp -p not a bug in Porteus 5.0rc2 and 4.0-i568

Posted: 27 Dec 2020, 13:55
by Rava
Probably a cp bug not a Porteus one.

Tested on a recent x86-64 and older i586 Porteus:

System Porteus 5.0rc2
cp V 8.32


My cp is aliased to

Code: Select all

guest@porteus:~$ alias cp
alias cp='/bin/cp -pi'
cp --help|grep -- -p tells us -p means

Code: Select all

same as --preserve=mode,ownership,timestamps
Now I copied this script file owned by root
-rwxr-xr-x 1 root root 363 Dec 27 12:27 /usr/bin/ffplay-hide_banner
to a folder on an ext3 partition guest can write to:

Code: Select all

guest@porteus:~$ cp /usr/bin/ffplay-hide_banner /mnt/ext3/porteus/debug/5.0xxx/
guest@porteus:~$ ls -l /usr/bin/ffplay-hide_banner /mnt/ext3/porteus/debug/5.0xxx/ffplay-hide_banner 
-rwxr-xr-x 1 guest users 363 Dec 27 12:27 /mnt/ext3/porteus/debug/5.0xxx/ffplay-hide_banner
-rwxr-xr-x 1 root  root  363 Dec 27 12:27 /usr/bin/ffplay-hide_banner
Same is true for Porteus 4.0 i568
cp V 8.29

Code: Select all

guest@porteus:/mnt/sda3/tmp$ ls -ld .
drwxr-xr-t 5 guest users 4096 Dec 25 21:53 .
guest@porteus:/mnt/sda3/tmp$ alias cp
alias cp='cp -pi'
guest@porteus:/mnt/sda3/tmp$ ls -l /usr/local/bin/aliasset 
-rw-r--r-- 1 root root 7256 Jan 30  2018 /usr/local/bin/aliasset
guest@porteus:/mnt/sda3/tmp$ cp /usr/local/bin/aliasset .
guest@porteus:/mnt/sda3/tmp$ ls -l aliasset
-rw-r--r-- 1 guest users 7256 Jan 30  2018 aliasset
guest@porteus:/mnt/sda3/tmp$ cp --version
cp (GNU coreutils) 8.29
[…]
Unlike what -p should have told cp, ownership and group was changed from root,root to guest,users.
According to cp --help at least the ownership should have been preserved.

Why is cp acting against what its explicitly told?

cp -p bug in Porteus 5.0rc2 and 4.0-i568

Posted: 27 Dec 2020, 16:18
by babam
Copy as root

Code: Select all

$ sudo cp -p /usr/bin/ffplay-hide_banner /mnt/ext3/porteus/debug/5.0xxx/

cp -p bug in Porteus 5.0rc2 and 4.0-i568

Posted: 27 Dec 2020, 19:37
by donald
@Rava
You cannot preserve ownerships while copying unless you are root.

non-root users are able to preserve ownership of their files that they own
and are owned by a group that the specific non-root user belongs to.
they cannot preserve ownership of files owned by other users,

root can preserve the ownership of files owned by different users,
because root has full system privileges.

cp -p bug in Porteus 5.0rc2 and 4.0-i568

Posted: 28 Dec 2020, 00:48
by Rava
^
makes sense. I would have liked a warning that as a non-root user ownership of files owned by other users cannot be preserved… and if I want to continue nonetheless.