You are here: Foswiki>Tasks Web>Item10240 (05 Jul 2015, GeorgeClark)Edit Attach

Item10240: Extension installer fails from shell if $Foswiki::cfg{ScriptDir} contains $Foswiki::cfg variables.

pencil
Priority: Normal
Current State: Closed
Released In: 2.0.0
Target Release: major
Applies To: Engine
Component: Configure
Branches: trunk
Reported By: KerstinPuschke
Waiting For:
Last Change By: GeorgeClark
If the value of $Foswiki::cfg{ScriptDir} contains a $Foswiki::cfg variable, extender.pl fails since sub getScriptDir does not expand that variable.

Example: if your LocalSite.cfg has $Foswiki::cfg{ScriptDir} = /some/path/$Foswiki::cfg{foo}/whatever and $Foswiki::cfg{foo} = bar, extender.pl tries to use /some/path/$Foswiki::cfg{foo}/whatever instead of /some/path/bar/whatever.

Might be fixed by calling Foswiki::Configure::Load::expandValue within getScriptDir or something similar.

-- KerstinPuschke - 11 Jan 2011

extender.pl doesn't have the full Foswiki environment loaded yet. It parses LocalSite.cfg manually in order to find the bin directory so that it can then run the setlib.cfg script. setlib.cfg does the work to set up the libpath so that the rest of the Foswiki environment can be loaded.

Not all installations use bin as the script directory. In some cases it's removed from the web root and stored in a cgi-bin location. We can't really assume much of anything this early in the code.

-- GeorgeClark - 12 Jan 2011

I don't really understand why the script dir has to be read in the way it is; it looks harmless to me to eval $cfgfile but maybe I'm missing something. Anyway, the following patch resolves this problem of embedded vars (and it is a major problem, as it blocks anyone trying to do simple virtual hosting from installing using extender.pl)

Index: extender.pl
===================================================================
--- extender.pl   (revision 13696)
+++ extender.pl   (working copy)
@@ -468,7 +468,7 @@
 
 ---++ StaticMethod getScriptDir( )
 This routine will recover the Script Directory from LocalSite.cfg
-without processing the entire file.  
+without processing the entire file (unless it has to to expand embedded vars) 
 
 =cut
 
@@ -504,8 +504,21 @@
     my $cfgfile = do { local $/; <$cfg> };
 
     $cfgfile =~ m/$reBinDir/ms;
-    return $1 || $2;
 
+    my $val = $1 || $2;
+    if ($val =~ /\$Foswiki::cfg/) {
+   # if there's at least one unexpanded cfg var in the value,
+   # slurp LSC and expand
+   local %Foswiki::cfg; # local namespace, won't pollute anything else
+   eval $cfgfile;
+   unless ($@) {
+       while ($val =~ s<(\$Foswiki::cfg{[A-Za-z0-9{}]+})>
+                             <eval $1>gex) {
+       }
+   }
+    }
+    return $val;
+
 }
 
 #
Marked for George to clarify why the read is done the way it is.

-- CrawfordCurrie - 18 Jan 2012

TBH I don't remember the exact reasons. The change was made in distro:9faa8279149a - and had to deal with the catch22 of not being able to find the script dir. to be able to run setlib.cfg required to require Foswiki.

extender.pl is only used by the cli installer now. The web implementation run as a script already has the bin directory location and setlib. Is there any possible impact of a simple eval of LocalSite.cfg to the subsequent building of a real foswiki environment?

Anyway, if it works, go for it!

-- GeorgeClark - 19 Jan 2012

OK, done in trunk.

-- CrawfordCurrie - 19 Jan 2012
 

ItemTemplate edit

Summary Extension installer fails from shell if $Foswiki::cfg{ScriptDir} contains $Foswiki::cfg variables.
ReportedBy KerstinPuschke
Codebase 1.1.2
SVN Range
AppliesTo Engine
Component Configure
Priority Normal
CurrentState Closed
WaitingFor
Checkins distro:5e7748f95724
TargetRelease major
ReleasedIn 2.0.0
CheckinsOnBranches trunk
trunkCheckins distro:5e7748f95724
masterCheckins
ItemBranchCheckins
Release01x01Checkins
Topic revision: r9 - 05 Jul 2015, GeorgeClark
The copyright of the content on this website is held by the contributing authors, except where stated elsewhere. See Copyright Statement. Creative Commons License    Legal Imprint    Privacy Policy