LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - General
User Name
Password
Linux - General This Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.

Notices


Reply
  Search this Thread
Old 03-11-2024, 12:07 PM   #1
tuxuser1
Member
 
Registered: Nov 2021
Posts: 165

Rep: Reputation: Disabled
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
 
Old 03-11-2024, 12:34 PM   #2
jayjwa
Member
 
Registered: Jul 2003
Location: NY
Distribution: Slackware, Termux
Posts: 779

Rep: Reputation: 246Reputation: 246Reputation: 246
It might help for us to see the script, at least the strip bit and surrounding lines.
 
Old 03-11-2024, 01:01 PM   #3
tuxuser1
Member
 
Registered: Nov 2021
Posts: 165

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by jayjwa View Post
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 ?
 
Old 03-11-2024, 02:27 PM   #4
pan64
LQ Addict
 
Registered: Mar 2012
Location: Hungary
Distribution: debian/ubuntu/suse ...
Posts: 21,855

Rep: Reputation: 7311Reputation: 7311Reputation: 7311Reputation: 7311Reputation: 7311Reputation: 7311Reputation: 7311Reputation: 7311Reputation: 7311Reputation: 7311Reputation: 7311
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.
 
Old 03-11-2024, 03:21 PM   #5
MadeInGermany
Senior Member
 
Registered: Dec 2011
Location: Simplicity
Posts: 2,796

Rep: Reputation: 1201Reputation: 1201Reputation: 1201Reputation: 1201Reputation: 1201Reputation: 1201Reputation: 1201Reputation: 1201Reputation: 1201
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

Last edited by MadeInGermany; 03-11-2024 at 03:23 PM.
 
Old 03-11-2024, 03:42 PM   #6
tuxuser1
Member
 
Registered: Nov 2021
Posts: 165

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by pan64 View Post
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.
 
Old 03-11-2024, 03:46 PM   #7
tuxuser1
Member
 
Registered: Nov 2021
Posts: 165

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by MadeInGermany View Post
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.
 
Old 03-11-2024, 03:47 PM   #8
sundialsvcs
LQ Guru
 
Registered: Feb 2004
Location: SE Tennessee, USA
Distribution: Gentoo, LFS
Posts: 10,662
Blog Entries: 4

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

 
Old 03-11-2024, 03:48 PM   #9
tuxuser1
Member
 
Registered: Nov 2021
Posts: 165

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by sundialsvcs View Post
Heh ... Looking up the manual page, I very-innocently used the search term: "man strip."

precious
 
Old 03-11-2024, 04:28 PM   #10
tuxuser1
Member
 
Registered: Nov 2021
Posts: 165

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by tuxuser1 View Post
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.
 
Old 03-12-2024, 02:52 AM   #11
pan64
LQ Addict
 
Registered: Mar 2012
Location: Hungary
Distribution: debian/ubuntu/suse ...
Posts: 21,855

Rep: Reputation: 7311Reputation: 7311Reputation: 7311Reputation: 7311Reputation: 7311Reputation: 7311Reputation: 7311Reputation: 7311Reputation: 7311Reputation: 7311Reputation: 7311
Quote:
Originally Posted by tuxuser1 View Post
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.
 
Old 03-12-2024, 03:09 AM   #12
tuxuser1
Member
 
Registered: Nov 2021
Posts: 165

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by pan64 View Post
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....
 
Old 03-13-2024, 10:11 AM   #13
MadeInGermany
Senior Member
 
Registered: Dec 2011
Location: Simplicity
Posts: 2,796

Rep: Reputation: 1201Reputation: 1201Reputation: 1201Reputation: 1201Reputation: 1201Reputation: 1201Reputation: 1201Reputation: 1201Reputation: 1201
Is a special file system type involved?
Code:
df -T "$res"
 
Old 03-13-2024, 10:19 AM   #14
tuxuser1
Member
 
Registered: Nov 2021
Posts: 165

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by MadeInGermany View Post
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.
 
Old 03-13-2024, 10:58 AM   #15
pan64
LQ Addict
 
Registered: Mar 2012
Location: Hungary
Distribution: debian/ubuntu/suse ...
Posts: 21,855

Rep: Reputation: 7311Reputation: 7311Reputation: 7311Reputation: 7311Reputation: 7311Reputation: 7311Reputation: 7311Reputation: 7311Reputation: 7311Reputation: 7311Reputation: 7311
Quote:
Originally Posted by tuxuser1 View Post
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.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
URGENT: strip: Unable to recognise the format of the input file: doesn't strip any libraries c_kvasud Linux - Newbie 3 06-05-2017 07:27 PM
strip directory in tar command m_pahlevanzadeh Linux - General 1 09-05-2011 01:25 AM
strip command varun_shrivastava Programming 3 09-03-2007 11:04 AM
command for "strip out every line that doesn't contain xxxxx" Rotwang Linux - General 6 08-02-2005 03:08 PM
strip command? blackzone Linux - General 2 07-09-2004 03:20 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - General

All times are GMT -5. The time now is 01:18 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration