Author Topic: [solved] perl scriptlet question  (Read 367 times)

Offline ghostbunny

  • PCLinuxOS Tester
  • Hero Member
  • *******
  • Posts: 1171
[solved] perl scriptlet question
« on: August 07, 2012, 01:54:05 PM »
Hi dudes,

i'm working on a solution for the webmin tmp folder permission problem but i need a perl "guru" which can explain what the following does

Code: [Select]
perl <<EOD;
# maketemp.pl
# Create the /tmp/.webmin directory if needed

\$tmp_dir = \$ENV{'tempdir'} || "/tmp/.webmin";

while(\$tries++ < 10) {
local @st = lstat(\$tmp_dir);
exit(0) if (\$st[4] == \$< && (-d _) && (\$st[2] & 0777) == 0755);
if (@st) {
unlink(\$tmp_dir) || rmdir(\$tmp_dir) ||
system("/bin/rm -rf ".quotemeta(\$tmp_dir));
}
mkdir(\$tmp_dir, 0755) || next;
chown(\$<, \$(, \$tmp_dir);
chmod(0755, \$tmp_dir);
}
exit(1);
EOD

regards
ghostbunny
« Last Edit: August 07, 2012, 11:30:03 PM by ghostbunny »
The full life is a big mess

PS:
I'm German. Sorry because of possible mistakes in my written messages xD


Offline TerryN

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 732
Re: perl scriptlet question
« Reply #1 on: August 07, 2012, 02:34:43 PM »
Set variable $tmp_dir to be the value of $tempdir from the shell environment or /tmp/.webmin if $tempdir is not set.
Exit if $tmp_dir is a directory owned by current user (REAL UID) and has permissions 755
otherwise delete it  and then:
create it with permissions 755
change owner to current user (REAL UID)
change permissions to 755

It will try up to 10 times to achieve correct directory and will exit with return code=0 if it succeeds or return code=1 if it fails.

Terry


« Last Edit: August 07, 2012, 03:05:35 PM by TerryN »
Dell E521 - AMD 64 X2 5000+, 4GB RAM, ATI X1300 graphics
PCLinuxOS 2013 (KDE)
|Twitter|

Offline ghostbunny

  • PCLinuxOS Tester
  • Hero Member
  • *******
  • Posts: 1171
Re: perl scriptlet question
« Reply #2 on: August 07, 2012, 04:11:34 PM »
thanks terry,

i hopefully fixed that permission problem now.  i replaced this code by three lines of bash script xD
The full life is a big mess

PS:
I'm German. Sorry because of possible mistakes in my written messages xD


Offline gseaman

  • PCLinuxOS Tester
  • Hero Member
  • *******
  • Posts: 3801
Re: perl scriptlet question
« Reply #3 on: August 07, 2012, 04:37:33 PM »
Please, show us the code. ;D

Galen

Offline ghostbunny

  • PCLinuxOS Tester
  • Hero Member
  • *******
  • Posts: 1171
Re: perl scriptlet question
« Reply #4 on: August 07, 2012, 11:29:08 PM »
here it is

Code: [Select]
if [ ! -d /tmp/.webmin ]; then
mkdir -p /tmp/.webmin
fi

the only thing is i don't know what webmin places there so i don't know whether the rights are correctly set.
The full life is a big mess

PS:
I'm German. Sorry because of possible mistakes in my written messages xD