LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - General (https://www.linuxquestions.org/questions/linux-general-1/)
-   -   Strip command problem (https://www.linuxquestions.org/questions/linux-general-1/strip-command-problem-4175734793/)

tuxuser1 03-11-2024 12:07 PM

Strip command problem
 
Hi,

I have a weird problem with strip command of binutils package.
When I run this command from a shell script, I get a permission denied error.
Instead, if I run the same command for the same user from a terminal session, it works!
Moreover, I always used this script and it always worked but
I don't understand the reason for which it fails on these resources.
Any advice?

Best regards

jayjwa 03-11-2024 12:34 PM

It might help for us to see the script, at least the strip bit and surrounding lines.

tuxuser1 03-11-2024 01:01 PM

Quote:

Originally Posted by jayjwa (Post 6489036)
It might help for us to see the script, at least the strip bit and surrounding lines.

The command is :
Code:

strip --strip-all "$res"
I didn't posted other code because is useless.
Anyway, I tried to run that script as root ad it worked.
Why? I don't understand the reason.
Basically, I download a tar archive from internet, extract it into a folder and
strip the executables and shared objects.
This script always worked, just for this archive it fails with permission denied error.
I tried to inspect the previous tar archives than this one,
I also saw that for those archive the owner and group are set to root, hence, that seem useless (theorically).
Why does it not work in this case as normal user ?

pan64 03-11-2024 02:27 PM

The most obvious answer is: because the user has no right to write that file. strip tries to modify a file, so it requires both read and write permission.
Check them.

MadeInGermany 03-11-2024 03:21 PM

Does your script extract to /tmp or /var/tmp?
The Linux kernel behavior changed, now root is restricted in directories with a t-bit.
https://www.claudiokuenzler.com/blog...-tmp-even-root
You can change it back to the Unix standard:
Code:

echo 0 > /proc/sys/fs/protected_regular
or
Code:

sysctl fs.protected_regular=0

tuxuser1 03-11-2024 03:42 PM

Quote:

Originally Posted by pan64 (Post 6489057)
The most obvious answer is: because the user has no right to write that file. strip tries to modify a file, so it requires both read and write permission.
Check them.

I am fully agree with you but like I wrote above,
if I run the same command for the same user in a terminal session, it works.
The problem only exist when it is executed from shell script
and that's very weird.

tuxuser1 03-11-2024 03:46 PM

Quote:

Originally Posted by MadeInGermany (Post 6489065)
Does your script extract to /tmp or /var/tmp?
The Linux kernel behavior changed, now root is restricted in directories with a t-bit.
https://www.claudiokuenzler.com/blog...-tmp-even-root
You can change it back to the Unix standard:
Code:

echo 0 > /proc/sys/fs/protected_regular
or
Code:

sysctl fs.protected_regular=0

Actually, my script is not extract but the files are extracted which will be stripped instead.
fs.protected_regular is already set to zero.

sundialsvcs 03-11-2024 03:47 PM

Heh ... Looking up the manual page, I very-innocently used the search term: "man strip."

:eek:

tuxuser1 03-11-2024 03:48 PM

Quote:

Originally Posted by sundialsvcs (Post 6489074)
Heh ... Looking up the manual page, I very-innocently used the search term: "man strip."

:eek:

precious ;)

tuxuser1 03-11-2024 04:28 PM

Quote:

Originally Posted by tuxuser1 (Post 6489069)
I am fully agree with you but like I wrote above,
if I run the same command for the same user in a terminal session, it works.
The problem only exist when it is executed from shell script
and that's very weird.

I just added "chmod u+w $res" before strip execution and it worked but, anyway
that's is weird because:
1) The resource has already write permission.
2) If I run the same command for the same user into terminal session, it works.

Likely, when the files are extracted from tar archive, inherit the fake permissions....
Just a thought.

Mark as solved.

pan64 03-12-2024 02:52 AM

Quote:

Originally Posted by tuxuser1 (Post 6489085)
Likely, when the files are extracted from tar archive, inherit the fake permissions....

tar itself restores the original permissions, at least it tries. You need to read the man page for details, it may work differently for users and root.

tuxuser1 03-12-2024 03:09 AM

Quote:

Originally Posted by pan64 (Post 6489150)
tar itself restores the original permissions, at least it tries. You need to read the man page for details, it may work differently for users and root.

I agree again, but if I extract tar archive and see that the permissions are correct (read, write and execution in my case) for the current user then expect it works, regardless man page reading.
When I run "chmod u+w", on the file system nothing changes occurs but i have to do that otherwise doesn't work.
According tar man page:
Code:

--no-same-owner
      Extract files as yourself (default for ordinary users).

--no-same-permissions
      Apply the user's umask when extracting permissions from
      the archive (default for ordinary users).

The umask for my user is 0022 which is 0644 like permissions.
It should works without any changes but it doesn't....

MadeInGermany 03-13-2024 10:11 AM

Is a special file system type involved?
Code:

df -T "$res"

tuxuser1 03-13-2024 10:19 AM

Quote:

Originally Posted by MadeInGermany (Post 6489486)
Is a special file system type involved?
Code:

df -T "$res"

"$res" is a simply resource (file/folder/symlink) extracted from tar archive.
Filesystem is Ext4 on Luks.

pan64 03-13-2024 10:58 AM

Quote:

Originally Posted by tuxuser1 (Post 6489153)
I agree again, but if I extract tar archive and see that the permissions are correct (read, write and execution in my case) for the current user then expect it works, regardless man page reading.
When I run "chmod u+w", on the file system nothing changes occurs but i have to do that otherwise doesn't work.
According tar man page:
Code:

--no-same-owner
      Extract files as yourself (default for ordinary users).

--no-same-permissions
      Apply the user's umask when extracting permissions from
      the archive (default for ordinary users).

The umask for my user is 0022 which is 0644 like permissions.
It should works without any changes but it doesn't....

If it is true you did not tell us the full story. If it is a remote drive, if several hosts are involved, if <whatever>... which was not explained.
Otherwise would be nice to see the exact commands, the exact result and obviously the real environment.


All times are GMT -5. The time now is 06:54 PM.