Home: Perl Programming Help: Intermediate:
Setting setuid/setgid permission using mkdir



blahyn8
New User

Oct 7, 2009, 8:45 AM


Views: 1369
Setting setuid/setgid permission using mkdir

I was trying to set the setgid bit for a new directory using perl's mkdir subroutine. It didn't work so I created a script to find out more about mkdir:

umask 7;

# both set sticky bit
mkdir ("blah1", oct(1755));
mkdir ("blah2", 01755);

# does nothing
mkdir ("blah3", 02755);
mkdir ("blah4", oct(2755));
mkdir ("blah5", oct(4755));
mkdir ("blah6", 04755);

The permissions that result are:

drwxr-x--T 2 tdc_user 80 2009-10-07 10:30 blah1/
drwxr-x--T 2 tdc_user 80 2009-10-07 10:30 blah2/
drwxr-x--- 2 tdc_user 80 2009-10-07 10:30 blah3/
drwxr-x--- 2 tdc_user 80 2009-10-07 10:30 blah4/
drwxr-x--- 2 tdc_user 80 2009-10-07 10:30 blah5/
drwxr-x--- 2 tdc_user 80 2009-10-07 10:30 blah6/

Does anybody know if it's possible to set the setgid bit at the same time as creating the directory using mkdir?


shawnhcorey
Enthusiast


Oct 7, 2009, 9:34 AM


Views: 1368
Re: [blahyn8] Setting setuid/setgid permission using mkdir

Do you run the program as root? Only root can setuid and setgid.

__END__

I love Perl; it's the only language where you can bless your thingy.

Perl documentation is available at perldoc.perl.org. The list of standard modules and pragmatics is available in perlmodlib.

Get Markup Help. Please note the markup tag of "code".


blahyn8
New User

Oct 7, 2009, 2:34 PM


Views: 1361
Re: [shawnhcorey] Setting setuid/setgid permission using mkdir

but i can set the setgid bit by doing a chmod right after mkdir in the script. why doesn't mkdir allow me to set the setgid bit?