You are viewing a plain text version of this content. The canonical link for it is here.
Posted to test-dev@httpd.apache.org by Randy Kobes <ra...@theoryx5.uwinnipeg.ca> on 2004/12/05 06:23:02 UTC

apxs calls on Win32

If apxs is installed on Win32, it is usually specified as a
.bat file. In querying apxs in apxs() of Apache::TestConfig,
however, Win32 needs both the path to cmd.exe (for running a
.bat command) and to Perl (in order to run apxs.bat) in
order to get something from
   $val = qx($apxs -q $q 2>$devnull);
This diff:
==========================================================
Index: lib/Apache/TestConfig.pm
===================================================================
--- lib/Apache/TestConfig.pm	(revision 109825)
+++ lib/Apache/TestConfig.pm	(working copy)
@@ -1658,6 +1658,12 @@
     my $val;
     unless (exists $self->{_apxs}{$q}) {
         local @ENV{ qw(PATH IFS CDPATH ENV BASH_ENV) };
+        # need path to Perl and to cmd.exe on Win32
+        if (WIN32) {
+            $ENV{PATH} = sprintf("%s;%s",
+                                 dirname($ENV{COMSPEC}),
+                                 dirname($self->{vars}->{perl}));
+        }
         my $devnull = devnull();
         my $apxs = shell_ready($self->{APXS});
         $val = qx($apxs -q $q 2>$devnull);

=================================================================
populates $ENV{PATH} with the needed paths so that these
calls succeeed.

-- 
best regards,
randy

Re: apxs calls on Win32

Posted by Stas Bekman <st...@stason.org>.
>>Also is there some File::Spec thingy that defines record
>>separator in paths?
> 
> 
> I looked through there - there's not one specifically
> defined. There are special cases for various platforms:
>    Mac => uses ',', but needs $ENV{Commands}, not $ENV{PATH}
>    OS2 => uses ';', but also translates '\' to '/'
>    VMS => uses a different $ENV variable
> So some of these (eg, Mac and VMS) would require special
> handling just to get at the equivalent of $ENV{PATH}.

Thanks for the research, Randy.

> Is leaving it just as is OK for the moment (using ';' for
> WIN32, ':' otherwise), and if someone has problems with it,
> we can fix it then?

+1

> Also, I haven't tried it yet, but just to make sure the
> email messages go to the right place - can one do a commit
> to Apache-Test from within modperl-2.0 svn (from within
> the Apache-Test subdirectory)?

I think you can diff/ci only if you first cd into A-T dir. so it'll go to 
the right list anyway. So there is no way you can commit the two at once I 
think.


-- 
__________________________________________________________________
Stas Bekman            JAm_pH ------> Just Another mod_perl Hacker
http://stason.org/     mod_perl Guide ---> http://perl.apache.org
mailto:stas@stason.org http://use.perl.org http://apacheweek.com
http://modperlbook.org http://apache.org   http://ticketmaster.com

Re: apxs calls on Win32

Posted by Randy Kobes <ra...@theoryx5.uwinnipeg.ca>.
On Tue, 7 Dec 2004, Stas Bekman wrote:

> Randy Kobes wrote:
[ ... ]
> > ==============================================================
> > Index: lib/Apache/TestConfig.pm
> > ===================================================================
> > --- lib/Apache/TestConfig.pm	(revision 110064)
> > +++ lib/Apache/TestConfig.pm	(working copy)
> > @@ -1043,7 +1043,8 @@
> >      # Temporarily untaint PATH
> >      (local $ENV{PATH}) = ( $ENV{PATH} =~ /(.*)/ );
> >      # -T disallows relative directories in the PATH
> > -    $ENV{PATH} = join ':', grep !/^\./, split /:/, $ENV{PATH};
> > +    my $sep = WIN32 ? ';' : ':';
> > +    $ENV{PATH} = join $sep, grep !/^\./, split /$sep/, $ENV{PATH};
> >
> >      # launder for -T
> >      $cmd = $1 if $cmd =~ /(.*)/;
> > @@ -1657,7 +1658,12 @@
> >      return unless $self->{APXS};
> >      my $val;
> >      unless (exists $self->{_apxs}{$q}) {
> > -        local @ENV{ qw(PATH IFS CDPATH ENV BASH_ENV) };
> > +        local @ENV{ qw(IFS CDPATH ENV BASH_ENV) };
> > +        # Temporarily untaint PATH
> > +        (local $ENV{PATH}) = ( $ENV{PATH} =~ /(.*)/ );
> > +        # -T disallows relative directories in the PATH
> > +        my $sep = WIN32 ? ';' : ':';
> > +        $ENV{PATH} = join $sep, grep !/^\./, split /$sep/, $ENV{PATH};
> >          my $devnull = devnull();
> >          my $apxs = shell_ready($self->{APXS});
> >          $val = qx($apxs -q $q 2>$devnull);
>
> As soon as you see dup like this, think refactoring :) e.g. add
> untaint_path(), that does the work and call it:
>
>    local $ENV{PATH}) = untaint_path($ENV{PATH});
>
> Otherwise +1.
>
> And of course this wrapper should probably used in open_cmd too!

OK, I'll do that - thanks!

> Also is there some File::Spec thingy that defines record
> separator in paths?

I looked through there - there's not one specifically
defined. There are special cases for various platforms:
   Mac => uses ',', but needs $ENV{Commands}, not $ENV{PATH}
   OS2 => uses ';', but also translates '\' to '/'
   VMS => uses a different $ENV variable
So some of these (eg, Mac and VMS) would require special
handling just to get at the equivalent of $ENV{PATH}.

Is leaving it just as is OK for the moment (using ';' for
WIN32, ':' otherwise), and if someone has problems with it,
we can fix it then?

Also, I haven't tried it yet, but just to make sure the
email messages go to the right place - can one do a commit
to Apache-Test from within modperl-2.0 svn (from within
the Apache-Test subdirectory)?

-- 
best regards,
randy

Re: apxs calls on Win32

Posted by Stas Bekman <st...@stason.org>.
Randy Kobes wrote:
> On Wed, 8 Dec 2004, Stas Bekman wrote:
> 
> 
>>I've requested to restore it (you indeed don't have it). Let me know if
>>you want me to commit this or wait for when you get the access again
>>(should hopefully be restored tomorrow).
> 
> 
> Thanks, Stas. If you have a minute, feel free to commit it;
> otherwise, I'll do it when it's restored. Thanks.

It's in.

-- 
__________________________________________________________________
Stas Bekman            JAm_pH ------> Just Another mod_perl Hacker
http://stason.org/     mod_perl Guide ---> http://perl.apache.org
mailto:stas@stason.org http://use.perl.org http://apacheweek.com
http://modperlbook.org http://apache.org   http://ticketmaster.com

Re: apxs calls on Win32

Posted by Randy Kobes <ra...@theoryx5.uwinnipeg.ca>.
On Wed, 8 Dec 2004, Stas Bekman wrote:

> I've requested to restore it (you indeed don't have it). Let me know if
> you want me to commit this or wait for when you get the access again
> (should hopefully be restored tomorrow).

Thanks, Stas. If you have a minute, feel free to commit it;
otherwise, I'll do it when it's restored. Thanks.

-- 
best regards,
randy

Re: apxs calls on Win32

Posted by Joe Schaefer <jo...@sunstarsys.com>.
Stas Bekman <st...@stason.org> writes:

> I've requested to restore it (you indeed don't have it).

Sorry about that Randy.  I've been trying for weeks to 
get our httpd-test commit access restored.

-- 
Joe Schaefer


Re: apxs calls on Win32

Posted by Stas Bekman <st...@stason.org>.
Randy Kobes wrote:
> On Tue, 7 Dec 2004, Stas Bekman wrote:
> 
> 
>>As soon as you see dup like this, think refactoring :) e.g. add
>>untaint_path(), that does the work and call it:
>>
>>   local $ENV{PATH}) = untaint_path($ENV{PATH});
>>
>>Otherwise +1.
>>
>>And of course this wrapper should probably used in open_cmd too!
> 
> 
> Here's a patch that does that:

Looks good. Randy++

> ==============================================================
> I tried committing it, but was denied access (I ensured I
> did a co with https); perhaps some permissions need
> adjusting (I did have commit access under cvs).

I've requested to restore it (you indeed don't have it). Let me know if 
you want me to commit this or wait for when you get the access again 
(should hopefully be restored tomorrow).


-- 
__________________________________________________________________
Stas Bekman            JAm_pH ------> Just Another mod_perl Hacker
http://stason.org/     mod_perl Guide ---> http://perl.apache.org
mailto:stas@stason.org http://use.perl.org http://apacheweek.com
http://modperlbook.org http://apache.org   http://ticketmaster.com

Re: apxs calls on Win32

Posted by Randy Kobes <ra...@theoryx5.uwinnipeg.ca>.
On Tue, 7 Dec 2004, Stas Bekman wrote:

> As soon as you see dup like this, think refactoring :) e.g. add
> untaint_path(), that does the work and call it:
>
>    local $ENV{PATH}) = untaint_path($ENV{PATH});
>
> Otherwise +1.
>
> And of course this wrapper should probably used in open_cmd too!

Here's a patch that does that:
==================================================================
Index: lib/Apache/TestConfig.pm
===================================================================
--- lib/Apache/TestConfig.pm	(revision 111156)
+++ lib/Apache/TestConfig.pm	(working copy)
@@ -1045,12 +1045,8 @@
     my($self, $cmd) = @_;
     # untaint some %ENV fields
     local @ENV{ qw(IFS CDPATH ENV BASH_ENV) };
+    local $ENV{PATH} = untaint_path($ENV{PATH});

-    # Temporarily untaint PATH
-    (local $ENV{PATH}) = ( $ENV{PATH} =~ /(.*)/ );
-    # -T disallows relative directories in the PATH
-    $ENV{PATH} = join ':', grep !/^\./, split /:/, $ENV{PATH};
-
     # launder for -T
     $cmd = $1 if $cmd =~ /(.*)/;

@@ -1663,7 +1659,8 @@
     return unless $self->{APXS};
     my $val;
     unless (exists $self->{_apxs}{$q}) {
-        local @ENV{ qw(PATH IFS CDPATH ENV BASH_ENV) };
+        local @ENV{ qw(IFS CDPATH ENV BASH_ENV) };
+        local $ENV{PATH} = untaint_path($ENV{PATH});
         my $devnull = devnull();
         my $apxs = shell_ready($self->{APXS});
         $val = qx($apxs -q $q 2>$devnull);
@@ -1684,6 +1681,17 @@
     $self->{_apxs}{$q};
 }

+# Temporarily untaint PATH
+sub untaint_path {
+    my $path = shift;
+    ($path) = ( $path =~ /(.*)/ );
+    # win32 uses ';' for a path separator, assume others use ':'
+    my $sep = WIN32 ? ';' : ':';
+    # -T disallows relative directories in the PATH
+    $path = join $sep, grep !/^\./, split /$sep/, $path;
+    return $path;
+}
+
 sub pop_dir {
     my $dir = shift;

==============================================================
I tried committing it, but was denied access (I ensured I
did a co with https); perhaps some permissions need
adjusting (I did have commit access under cvs).

-- 
best regards,
randy

Re: apxs calls on Win32

Posted by Stas Bekman <st...@stason.org>.
Randy Kobes wrote:
> On Sun, 5 Dec 2004, Stas Bekman wrote:
> 
> 
>>Randy Kobes wrote:
>>
>>>If apxs is installed on Win32, it is usually specified as a
>>>.bat file. In querying apxs in apxs() of Apache::TestConfig,
>>>however, Win32 needs both the path to cmd.exe (for running a
>>>.bat command) and to Perl (in order to run apxs.bat) in
>>>order to get something from
>>>   $val = qx($apxs -q $q 2>$devnull);
>>>This diff:
>>
>>If it's only win32 case then +1 but if other platforms may have the same
>>problem, may be it's better to blindly launder $ENV{PATH} like we do in a
>>few other places (in which case there will be no need for this change, as
>>the right paths will be there already, correct?)
> 
> 
> That's right - what about the following, copied from
> the open_cmd sub of Apache::Build (for Win32, this needs
> to use the ';' as the directory separator within $ENV{PATH},
> rather than ':'.
> ==============================================================
> Index: lib/Apache/TestConfig.pm
> ===================================================================
> --- lib/Apache/TestConfig.pm	(revision 110064)
> +++ lib/Apache/TestConfig.pm	(working copy)
> @@ -1043,7 +1043,8 @@
>      # Temporarily untaint PATH
>      (local $ENV{PATH}) = ( $ENV{PATH} =~ /(.*)/ );
>      # -T disallows relative directories in the PATH
> -    $ENV{PATH} = join ':', grep !/^\./, split /:/, $ENV{PATH};
> +    my $sep = WIN32 ? ';' : ':';
> +    $ENV{PATH} = join $sep, grep !/^\./, split /$sep/, $ENV{PATH};
> 
>      # launder for -T
>      $cmd = $1 if $cmd =~ /(.*)/;
> @@ -1657,7 +1658,12 @@
>      return unless $self->{APXS};
>      my $val;
>      unless (exists $self->{_apxs}{$q}) {
> -        local @ENV{ qw(PATH IFS CDPATH ENV BASH_ENV) };
> +        local @ENV{ qw(IFS CDPATH ENV BASH_ENV) };
> +        # Temporarily untaint PATH
> +        (local $ENV{PATH}) = ( $ENV{PATH} =~ /(.*)/ );
> +        # -T disallows relative directories in the PATH
> +        my $sep = WIN32 ? ';' : ':';
> +        $ENV{PATH} = join $sep, grep !/^\./, split /$sep/, $ENV{PATH};
>          my $devnull = devnull();
>          my $apxs = shell_ready($self->{APXS});
>          $val = qx($apxs -q $q 2>$devnull);

As soon as you see dup like this, think refactoring :) e.g. add 
untaint_path(), that does the work and call it:

   local $ENV{PATH}) = untaint_path($ENV{PATH});

Otherwise +1.

And of course this wrapper should probably used in open_cmd too!

Also is there some File::Spec thingy that defines record separator in paths?

-- 
__________________________________________________________________
Stas Bekman            JAm_pH ------> Just Another mod_perl Hacker
http://stason.org/     mod_perl Guide ---> http://perl.apache.org
mailto:stas@stason.org http://use.perl.org http://apacheweek.com
http://modperlbook.org http://apache.org   http://ticketmaster.com

Re: apxs calls on Win32

Posted by Randy Kobes <ra...@theoryx5.uwinnipeg.ca>.
On Sun, 5 Dec 2004, Stas Bekman wrote:

> Randy Kobes wrote:
> > If apxs is installed on Win32, it is usually specified as a
> > .bat file. In querying apxs in apxs() of Apache::TestConfig,
> > however, Win32 needs both the path to cmd.exe (for running a
> > .bat command) and to Perl (in order to run apxs.bat) in
> > order to get something from
> >    $val = qx($apxs -q $q 2>$devnull);
> > This diff:
>
> If it's only win32 case then +1 but if other platforms may have the same
> problem, may be it's better to blindly launder $ENV{PATH} like we do in a
> few other places (in which case there will be no need for this change, as
> the right paths will be there already, correct?)

That's right - what about the following, copied from
the open_cmd sub of Apache::Build (for Win32, this needs
to use the ';' as the directory separator within $ENV{PATH},
rather than ':'.
==============================================================
Index: lib/Apache/TestConfig.pm
===================================================================
--- lib/Apache/TestConfig.pm	(revision 110064)
+++ lib/Apache/TestConfig.pm	(working copy)
@@ -1043,7 +1043,8 @@
     # Temporarily untaint PATH
     (local $ENV{PATH}) = ( $ENV{PATH} =~ /(.*)/ );
     # -T disallows relative directories in the PATH
-    $ENV{PATH} = join ':', grep !/^\./, split /:/, $ENV{PATH};
+    my $sep = WIN32 ? ';' : ':';
+    $ENV{PATH} = join $sep, grep !/^\./, split /$sep/, $ENV{PATH};

     # launder for -T
     $cmd = $1 if $cmd =~ /(.*)/;
@@ -1657,7 +1658,12 @@
     return unless $self->{APXS};
     my $val;
     unless (exists $self->{_apxs}{$q}) {
-        local @ENV{ qw(PATH IFS CDPATH ENV BASH_ENV) };
+        local @ENV{ qw(IFS CDPATH ENV BASH_ENV) };
+        # Temporarily untaint PATH
+        (local $ENV{PATH}) = ( $ENV{PATH} =~ /(.*)/ );
+        # -T disallows relative directories in the PATH
+        my $sep = WIN32 ? ';' : ':';
+        $ENV{PATH} = join $sep, grep !/^\./, split /$sep/, $ENV{PATH};
         my $devnull = devnull();
         my $apxs = shell_ready($self->{APXS});
         $val = qx($apxs -q $q 2>$devnull);

=================================================================

-- 
best regards,
randy

Re: apxs calls on Win32

Posted by Stas Bekman <st...@stason.org>.
Randy Kobes wrote:
> If apxs is installed on Win32, it is usually specified as a
> .bat file. In querying apxs in apxs() of Apache::TestConfig,
> however, Win32 needs both the path to cmd.exe (for running a
> .bat command) and to Perl (in order to run apxs.bat) in
> order to get something from
>    $val = qx($apxs -q $q 2>$devnull);
> This diff:

If it's only win32 case then +1 but if other platforms may have the same 
problem, may be it's better to blindly launder $ENV{PATH} like we do in a 
few other places (in which case there will be no need for this change, as 
the right paths will be there already, correct?)

> ==========================================================
> Index: lib/Apache/TestConfig.pm
> ===================================================================
> --- lib/Apache/TestConfig.pm	(revision 109825)
> +++ lib/Apache/TestConfig.pm	(working copy)
> @@ -1658,6 +1658,12 @@
>      my $val;
>      unless (exists $self->{_apxs}{$q}) {
>          local @ENV{ qw(PATH IFS CDPATH ENV BASH_ENV) };
> +        # need path to Perl and to cmd.exe on Win32
> +        if (WIN32) {
> +            $ENV{PATH} = sprintf("%s;%s",
> +                                 dirname($ENV{COMSPEC}),
> +                                 dirname($self->{vars}->{perl}));
> +        }
>          my $devnull = devnull();
>          my $apxs = shell_ready($self->{APXS});
>          $val = qx($apxs -q $q 2>$devnull);
> 
> =================================================================
> populates $ENV{PATH} with the needed paths so that these
> calls succeeed.
> 


-- 
__________________________________________________________________
Stas Bekman            JAm_pH ------> Just Another mod_perl Hacker
http://stason.org/     mod_perl Guide ---> http://perl.apache.org
mailto:stas@stason.org http://use.perl.org http://apacheweek.com
http://modperlbook.org http://apache.org   http://ticketmaster.com