Smart questions
Smart answers
Smart people
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Member Login

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips now!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

Join Tek-Tips
*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

LINK TO THIS FORUM!

Add Stickiness To Your Site By Linking To This Professionally Managed Technical Forum.
Just copy and paste the
code below into your site.

Partner With Us!

"Best Of Breed" Forums Add Stickiness To Your Site
Partner Button
(Download This Button Today!)

Feedback

"...Thanks for a great forum. My problem was answered just by scrolling through previously solved problems. Great service!!..."

Geography

Where in the world do Tek-Tips members come from?

Create a file with setuid from Perl script

redrafiki (Programmer)
11 May 12 14:53
Hello, I have a perl script that runs in a Linux system, it basically reads a list of files and attributes and copies them to the right directory and set the attributes accordingly.

The script works fine with files with "regular" attributes like 0755, I'm doing something like this:
copy($filezip, $filetarget) or die "File cannot be copied.";
chmod oct($fileperms),$filetarget or die "Perms not changed.";
chown $uid, $gid, $filetarget;

But when the file has attributes that set the suid permissions (4755) the target file is not set with these attributes.

I tried running chmod from a system call and it didn't work:
system("/bin/chmod $fileperms $filetarget");

I tried using a umask as follows and it didn't work either:
my $perms = ((stat($filezip))[2] & 07777);
my $newperms = $perms ^ 04000;
chmod $newperms, $filetarget or die "Perms not changed.";

Does anyone knows how to set the suid permission from a perl script?

Thanks
tarn (TechnicalUser)
12 May 12 7:39
Strange as this works for me ....

CODE --> test_perl

-bash-3.00$ cat testperl.pl #!/bin/perl system("/bin/touch fredtest.tat"); system("/bin/chmod 4777 fredtest.tat"); -bash-3.00$ -bash-3.00$ perl ./testperl.pl -bash-3.00$ ls -alrth total 10 drwxr-xr-x 40 fred other 2.5K May 12 11:16 .. -rw-r--r-- 1 fred other 89 May 12 11:26 testperl.pl drwxr-xr-x 2 fred other 512 May 12 11:28 . -rwsrwxrwx 1 fred other 0 May 12 11:28 fredtest.tat -bash-3.00$

So maybe it's where you get your variables, are they strings? I suggest printing them to confirm.

I hope that helps

Laurie.
redrafiki (Programmer)
14 May 12 10:19
Thanks Laurie, I found the answer for this already.

chown always resets the set-uid and set-gid values, so it always has to run before chmod in order to set the set-uid.

I ran the chown command first then chmod and it worked.

Thanks

I think this post can be closed now

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members!

Back To Forum

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close