LinuxQuestions.org
Visit Jeremy's Blog.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software
User Name
Password
Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.

Notices


Reply
  Search this Thread
Old 11-27-2006, 04:05 PM   #1
Byronious
LQ Newbie
 
Registered: Nov 2005
Posts: 15

Rep: Reputation: 0
Script problem


I'm currently working on creating a server/client setup (EDIT: This is using Fedora Core 4) for a class I am in. I have to write a script to remove a user from the /etc/passwd and /etc/shadow files as well as move their home directory to an /orphans directory. This file has to be run using the account named admin which is part of an administrators group that was created. Here is what my script looks like:

Quote:
read -p "Username: " username
grep -v $username /etc/passwd >> /etc/passwd.tmp
grep -v $username /etc/shadow >> /etc/shadow.tmp
mv -f /home/$username /orphans/$username
echo $username >> /var/log/deleted.log
The permissions look as follows:
Quote:
-rwsr-x---
The owner of the script is root, the group owner is administrators. I am receiving permission denieds for almost every change that is made by the script.

Any help appreciated.

Last edited by Byronious; 11-27-2006 at 04:23 PM.
 
Old 11-27-2006, 04:18 PM   #2
matthewg42
Senior Member
 
Registered: Oct 2003
Location: UK
Distribution: Kubuntu 12.10 (using awesome wm though)
Posts: 3,530

Rep: Reputation: 65
You'd do better to use "userdel"
 
Old 11-27-2006, 04:22 PM   #3
Byronious
LQ Newbie
 
Registered: Nov 2005
Posts: 15

Original Poster
Rep: Reputation: 0
Quote:
Originally Posted by matthewg42
You'd do better to use "userdel"
Believe me I would, but it doesn't work when logged in as admin.
 
Old 11-27-2006, 04:37 PM   #4
Byronious
LQ Newbie
 
Registered: Nov 2005
Posts: 15

Original Poster
Rep: Reputation: 0
Apparently my instructor just informed us that SUID doesn't work for whatever reason. Does anyone know why SUID would not work?
 
Old 11-27-2006, 04:50 PM   #5
matthewg42
Senior Member
 
Registered: Oct 2003
Location: UK
Distribution: Kubuntu 12.10 (using awesome wm though)
Posts: 3,530

Rep: Reputation: 65
The partition the script is on could be mounted with the nosuid flag.
 
Old 11-27-2006, 05:13 PM   #6
Byronious
LQ Newbie
 
Registered: Nov 2005
Posts: 15

Original Poster
Rep: Reputation: 0
Where can I check this?

Not that it really matters now as we have been told we can run the script while logged into root, but for future reference it would be nice to know.
 
Old 11-27-2006, 05:23 PM   #7
tvynr
Member
 
Registered: Apr 2004
Distribution: Debian
Posts: 143

Rep: Reputation: 15
Actually, I ran into this problem a while back. Turns out that bash ignores the SUID flag if the file is owned by root because it dissuades trivially vulnerable and rather dangerous security breaches.

Of course, it's not a very effective measure of protection; I personally think it's silly. But that's the way it is.

For my little project, I got around the problem by finding this code snippet on the web. It's a C program which is compiled and run SUID root. All it does is run the bash script in question, but that means that the bash script is being run by root, so that gets you around the problem (but definitely not through it).

Code:
int main (int argc, char** argv)
{
    setuid(0);
    seteuid(0);
    execl("/bin/bash", "bash", "/some/path/some/script.sh", 0);
}
Note that the above source snippet will not pass the program's arguments along to the bash script; you'd have to modify it to do that.

It's an ugly hack... I wouldn't recommend it for anything important and I'm not willing to swear by its safety at all. :-P
 
Old 11-27-2006, 05:28 PM   #8
matthewg42
Senior Member
 
Registered: Oct 2003
Location: UK
Distribution: Kubuntu 12.10 (using awesome wm though)
Posts: 3,530

Rep: Reputation: 65
Quote:
Originally Posted by Byronious
Where can I check this?

Not that it really matters now as we have been told we can run the script while logged into root, but for future reference it would be nice to know.
Try this command. If you see nosuid in the brackets at the end of the line, suid is not permitted for the device where that file/directory:
Code:
mount |fgrep $(df /path/to/your/file |tail -n 1 |cut -d" " -f 1)
 
  


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 Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
shell script problem, want to use shell script auto update IP~! singying304 Programming 4 11-29-2005 05:32 PM
PPPD Script problem when cron-scheduling the script andresurzagasti Linux - Networking 0 11-24-2004 02:54 PM
Script file problem (or operator problem) HELP! lostone Programming 2 05-23-2001 02:30 PM
Script file problem (or operator problem) HELP! lostone Linux - General 1 05-17-2001 06:11 PM
Script file problem (or operator problem) HELP! lostone Linux - Newbie 0 05-15-2001 07:59 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Software

All times are GMT -5. The time now is 11:12 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