Re: [mod_perl2] PerlChildInitHandlers with multiple (Win32) threads
Thanks for the info, its exactly what I needed. -pete Stas Bekman wrote: Peter Rothermel wrote: Stas Bekman wrote: Peter Rothermel wrote: PerlChildInitHandler Apache::foo-loadkey Will the genkey method get execute at the initialization of each thread? Apache doesn't provide such a hook yet. May be in the future. child_init is for child process init, not threads. http://perl.apache.org/release/docs/2.0/user/handlers/handlers.html#PerlChildInitHandler what are you trying to do? I'm encrypting/decrypting data within cookies that are holding session keys for authentication purposes. I decrypt the session key within the cookie data, whenever I get an http request that has a cookie in the header. The RSA keys that I use for encrytion/decryption are regenerated when the Apache server is started. My module has a load_key subroutine that I call before I do any encryption or decryption. This returns a RSA object that is initialized with a global var that hold a 2048 bit RSA key. If the global var is empty I generate a new key. The code works OK but I seem to be generating a 2048 bit key the first time that a user logs into my site. This key generation takes awhile. I would prefer generating the key when server/thread/interupter is started. I was hoping that a PerlClhildInitHandler could be used to call the gen_key subroutine to load the data into global var $private_key_string. There are a few possible approaches to this: 1. for mod_perl to provide hooks for the following events: interp_init (INIT) interp_destroy(DESTROY) so these can be run when a new interpreter is initialized after it has been cloned and when it's going to be destroyed. 2. Using the thread interpreter pool mechanism for managing other items. But it's not clear whether this interface will ever have a Perl API, because threads::shared already does that. 3. Build a pool based on threads::shared. Similar to what Doug has described in his overview: http://perl.apache.org/release/docs/2.0/user/overview/overview.html#Thread_Item_Pool_API and which is now doable in pure Perl based on threads::shared. This is an interesting vacant module, but really you can just duplicate the concepts that Doug has described in the URL above. You want to be able to add new items, remove them, pop and push from the pool. should it be called Threads::TIPool as coined by Doug? (Thread Items Pool) Using this (currently not-existing) module you can create a pool of keys at the server startup and then use them whenever you need a key at run time. This is the same concept that the threaded version of Apache::DBI is going to use, and AFAIK is vacant as well. The challenge is to make it possible to have modules like Apache::DBI work transparently under various mpms, including the preforked and perchild mpms. __ Stas BekmanJAm_pH -- Just Another mod_perl Hacker http://stason.org/ mod_perl Guide --- http://perl.apache.org mailto:[EMAIL PROTECTED] http://use.perl.org http://apacheweek.com http://modperlbook.org http://apache.org http://ticketmaster.com
[mod_perl2] PerlChildInitHandlers with multiple (Win32) threads
greetings, I'm looking for the documentation that describes how PerlChildInitHandlers work with multiple threads on Win32 platforms. Here's a specific question: I have the following in my httpd.conf: IfModule mpm_winnt.c ThreadsPerChild 10 MaxRequestsPerChild 0 /IfModule PerlChildInitHandler Apache::foo-genkey Will the genkey method get execute at the initialization of each thread? -pete
Re: [mod_perl2] PerlChildInitHandlers with multiple (Win32) threads
Stas Bekman wrote: Peter Rothermel wrote: PerlChildInitHandler Apache::foo-loadkey Will the genkey method get execute at the initialization of each thread? Apache doesn't provide such a hook yet. May be in the future. child_init is for child process init, not threads. http://perl.apache.org/release/docs/2.0/user/handlers/handlers.html#PerlChildInitHandler what are you trying to do? I'm encrypting/decrypting data within cookies that are holding session keys for authentication purposes. I decrypt the session key within the cookie data, whenever I get an http request that has a cookie in the header. The RSA keys that I use for encrytion/decryption are regenerated when the Apache server is started. My module has a load_key subroutine that I call before I do any encryption or decryption. This returns a RSA object that is initialized with a global var that hold a 2048 bit RSA key. If the global var is empty I generate a new key. The code works OK but I seem to be generating a 2048 bit key the first time that a user logs into my site. This key generation takes awhile. I would prefer generating the key when server/thread/interupter is started. I was hoping that a PerlClhildInitHandler could be used to call the gen_key subroutine to load the data into global var $private_key_string. my $self = shift;use vars qw($VERSION $private_key_string @ISA); sub gen_key : method { my ($self,$r) = @_; my $rlog = $r-log; my $tmprsa = Crypt::OpenSSL::RSA-new(); $rlog-notice(Generating a RSA key); $tmprsa-generate_key(2048); $private_key_string = $tmprsa-get_private_key_string(); } sub load_key : method { my ($self,$r) = @_; my $rlog = $r-log; my $rsa; if (length($private_key_string)) { $rsa = Crypt::OpenSSL::RSA-new(); $rsa-load_private_key( $private_key_string ); } else { $rsa = $self-gen_key; } return $rsa; } You should try to write your code in mpm-agnostic way if possible. so the same code can run under various mpms. __ Stas BekmanJAm_pH -- Just Another mod_perl Hacker http://stason.org/ mod_perl Guide --- http://perl.apache.org mailto:[EMAIL PROTECTED] http://use.perl.org http://apacheweek.com http://modperlbook.org http://apache.org http://ticketmaster.com
Re: [mod_perl2] PerlChildInitHandlers with multiple (Win32) threads
David Dyer-Bennet wrote: Peter Rothermel [EMAIL PROTECTED] writes: Stas Bekman wrote: Peter Rothermel wrote: PerlChildInitHandler Apache::foo-loadkey Will the genkey method get execute at the initialization of each thread? Apache doesn't provide such a hook yet. May be in the future. child_init is for child process init, not threads. http://perl.apache.org/release/docs/2.0/user/handlers/handlers.html#PerlChildInitHandler what are you trying to do? I'm encrypting/decrypting data within cookies that are holding session keys for authentication purposes. I decrypt the session key within the cookie data, whenever I get an http request that has a cookie in the header. What's the benefit of encrypting the session keys in the cookie? If they're randomly chosen from a very large space, the probability of guessing a valid session key can be made exactly equal to the probability of guessing the encryption key. I am using the term session key in the context of the the Apache::AuthCookie module that is maintained by Michael Schout. In my system, the session key holds some group membership and access rights information that is returned by an authentication server when the user provides credentials (username, password,..) via a login page. The session key is not very large or randomly selected. In particular, if the *result* of the encryption is, say, a 32-bit encrypted session key, is that any more secure than simply picking a random 32-bit session key to begin with? Even with a 2048-bit encryption key, there are actually only 32 bits of space to search for a hit. (So you don't need to have a 2048-bit session key space to match the security of a 2048-bit encryption key applied to a 32-bit session key space; a 32-bit session key space alone is just as safe.) And of course the key generation, encryption, and decryption take CPU power, *and* require additional code that could have bugs, which could be security problems. I've seen people (including one client) *very* committed to this encrypted session key concept before, and I've never been able to understand what benefit it buys them. I ask because I'm NOT yet totally convinced I'm right; though I'm convinced enough that the sites I design depend on it. (One obvious answer is there are big wins for us in having session keys that *aren't* randomly chosen). -- David Dyer-Bennet, [EMAIL PROTECTED] / New TMDA anti-spam in test John Dyer-Bennet 1915-2002 Memorial Site http://john.dyer-bennet.net Book log: http://www.dd-b.net/dd-b/Ouroboros/booknotes/ New Dragaera mailing lists, see http://dragaera.info
Re: Getting mod_perl to work under Win2k
Michael Lawrie wrote: Hello, I've spent several days working on this problem, reading various FAQ and whatnot and finally decided to try this email list, hoping that I might find an answer here. I'm running Win2KPro and Apache 1.3.23 I downloaded mod_perl2.ppd, and installed the *.so file in the default modules directory for my web server. I edited the httpd.conf file to include the following line: LoadModule perl_module modules/mod_perl.so When I attempt to start httpd I get this message: Syntax Error on line 193 of c:/apache/apache/conf/httpd.conf Can not load c:/apache/apache/modules/mod_perl.so into server: (126) The specified module could not be found. Is there something I've missed? Looks like your PATH env variable needs to be modified to include your Perl executable. Make sure you are getting the correct the with a perl -V from the command prompt. -pete Thanks! Michael
Re: [modperl2] Note on the win32 docs
I've run into a problem with mod_perl configuration instructions with for Registry scripts. I've built mod_perl and copied the blib directly under my Apache2 (server root) directory. Here's the errors I get run I start apache: C:\WGTI\Apache2\binapache Using C:\WGTI\Apache2/blib [Mon May 20 13:42:35 2002] [error] Attempt to free unreferenced scalar at C:\WGT I\Apache2/blib/lib/Apache2/ModPerl/RegistryCooker.pm line 45. BEGIN failed--compilation aborted at C:\WGTI\Apache2/blib/lib/Apache2/ModPerl/Re gistryCooker.pm line 48. Compilation failed in require at C:\WGTI\Apache2/blib/lib/Apache2/ModPerl/Regist ry.pm line 11. BEGIN failed--compilation aborted at C:\WGTI\Apache2/blib/lib/Apache2/ModPerl/Re gistry.pm line 11. Compilation failed in require at C:/WGTI/Apache2/conf/extra.pl line 15. BEGIN failed--compilation aborted at C:/WGTI/Apache2/conf/extra.pl line 15. Compilation failed in require at (eval 1) line 1. [Mon May 20 13:42:35 2002] [error] Can't load Perl file: C:/WGTI/Apache2/conf/ex tra.pl for server spider.inside.sealabs.com:80, exiting... Here's snipet of my httpd.conf file: LoadModule perl_module modules/mod_perl.so PerlSwitches -Mblib=C:\WGTI\Apache2 PerlModule Apache2 PerlModule Apache::compat PerlRequire C:/WGTI/Apache2/conf/extra.pl Here's my extra.pl use Apache2 (); use ModPerl::Util (); use Apache::RequestRec (); use Apache::RequestIO (); use Apache::RequestUtil (); use Apache::Server (); use Apache::ServerUtil (); use Apache::Connection (); use Apache::Log (); use Apache::Const -compile = ':common'; use APR::Const -compile = ':common'; use APR::Table (); use Apache::compat (); use ModPerl::Registry (); use CGI (); 1;
Re: [modperl2] Note on the win32 docs
Thanks for the info. Latest from cvs works fine. Any idea how close _02 might be to release? -pete Doug MacEachern wrote: On Mon, 20 May 2002, Peter Rothermel wrote: I've run into a problem with mod_perl configuration instructions with for Registry scripts. I've built mod_perl and copied the blib directly under my Apache2 (server root) directory. sounds like a bug that has been fixed in cvs. try the cvs version or wait for _02 or try the patch below. Index: ModPerl-Registry/lib/ModPerl/RegistryCooker.pm === RCS file: /home/cvs/modperl-2.0/ModPerl-Registry/lib/ModPerl/RegistryCooker.pm,v retrieving revision 1.5 retrieving revision 1.6 diff -u -r1.5 -r1.6 --- ModPerl-Registry/lib/ModPerl/RegistryCooker.pm 13 Nov 2001 04:34:31 - 1.5 +++ ModPerl-Registry/lib/ModPerl/RegistryCooker.pm 16 Apr 2002 17:14:16 - 1.6 -42,10 +42,11 # httpd.conf with: # PerlSetVar ModPerl::RegistryCooker::DEBUG 4 use Apache::ServerUtil (); -use constant DEBUG = -defined Apache-server-dir_config('ModPerl::RegistryCooker::DEBUG') -? Apache-server-dir_config('ModPerl::RegistryCooker::DEBUG') -: D_NONE; +use constant DEBUG = 0; +#XXX: below currently crashes the server on win32 +#defined Apache-server-dir_config('ModPerl::RegistryCooker::DEBUG') +#? Apache-server-dir_config('ModPerl::RegistryCooker::DEBUG') +#: D_NONE; # # object's array index's access constants
Re: compatibility problem
You'll find a few other issues with AuthCookie and mod_perl-1.9.9_01 beyond the REDIRECT constant. Here's a quick summary: 1) move all the $r-connection-user() calls to $r-user() calls 2) change all the err_header_out() calls to err_headers_out() calls. $r-err_headers_out-{'Pragma'} = no-cache; --- $r-err_header_out(Pragma = no-cache); This is the bulk of the changes that I did to get things going. I'm going to send my in to the maintainer of the Module as soon as I get some help with method handles. This module makes use of the technique of derived method handlers. I have been able to get a regular, much less a derived, method handler working in mod_perl1.99. As a temporary hack I hacked the module code to be a non-method handler. good luck, -pete Stas Bekman wrote: Jie Gao wrote: Hi all, I've been trying to get httpd-2.0.35 + mod_perl-1.99_01 work with backward compatibility. MY startupl.pl: #! /usr/bin/perl use lib '/usr/lib/perl5/site_perl/5.6.1/i386-linux/Apache2'; use strict; use Apache::compat (); use Apache2 (); use My::AuthCookieHandler; 1; and this script won't run to finish with the error: unknown group `response' at /usr/lib/perl5/site_perl/5.6.1/My/AuthCookieHandler.pm line 6. BEGIN failed--compilation aborted at /usr/lib/perl5/site_perl/5.6.1/My/AuthCookieHandler.pm line 6. Compilation failed in require at ./startup.pl line 6. BEGIN failed--compilation aborted at ./startup.pl line 6. And this is the line in question: use Apache::Constants qw(:common :response M_GET M_POST AUTH_REQUIRED REDIRECT); If I take out response, it croaks at REDIRECT. Any ideas why? Yes, it's not fully compatible :( in 2.0 we take all the Constants from APR and Apache, and they have changed. I guess we can manually do the adjustments in compat.pm. Currently there is no group :response in Apache::Const, these mainly reside in the new group :http and all the codes start with HTTP_ For now try to replace REDIRECT with HTTP_TEMPORARY_REDIRECT and whatever constants you need from :response by looking them up in xs/ModPerl/Const/modperl_constants.c (which is autogenerated when you build mod_perl). We will discuss this issue at the dev list and the compat docs will be updated appropriately. __ Stas BekmanJAm_pH -- Just Another mod_perl Hacker http://stason.org/ mod_perl Guide --- http://perl.apache.org mailto:[EMAIL PROTECTED] http://use.perl.org http://apacheweek.com http://modperlbook.org http://apache.org http://ticketmaster.com
Re: [modperl2] Note on the win32 docs
Excellent document. A slight enhancement request. Could you give some details on how to separate the modperl installation from the Perl installation? I believe the latest binary release has the mod_perl installed in a separate blib under the C:\Apache2 directory. thanks -pete __ Stas BekmanJAm_pH -- Just Another mod_perl Hacker http://stason.org/ mod_perl Guide --- http://perl.apache.org mailto:[EMAIL PROTECTED] http://use.perl.org http://apacheweek.com http://modperlbook.org http://apache.org http://ticketmaster.com
Re: [modperl2] Note on the win32 docs
Randy Kobes wrote: On Mon, 13 May 2002, Peter Rothermel wrote: The blib/ directory under C:/Apache2 doesn't actually have to be moved anywhere - one includes it with the directive PerlSwitches -Mblib=C:\Apache2 specified in the supplied httpd.conf So, for this distribution, one doesn't need to do anything with the Perl stuff ... Or am I misunderstanding something? When you built the mod_perl distribution did you use perl Makefile.PL MP_AP_PREFIX=C\Apache2 MP_INST_APACHE2=1 LIB=C:\Apache2\blib\lib thanks pete best regards, randy
Re: cannot build mod_perl-1.99_01 with httpd-2.0.36
I'm getting the same error on Win32 builds. I just assumed that mod_perl-1.99_01 and httpd-2.0.36 were not compatible. I've been compiling with httpd-2.0.35 and to avoid the error. The file apr_lock.h is missing in the httpd-2.0.36 include directory but present in the httpd-2.0.35 source tree. -pete Tom Kralidis wrote: % perl Makefile.PL MP_AP_PREFIX=/usr/local/src/apache/httpd-2.0.36 MP_AP_PREFIX needs to be a directory where apache is installed, not the source tree. when apache is installed it puts all headers into the installed include/ directory. Thanks for the info. That didn't seem to work either cd src/modules/perl make make[1]: Entering directory `/usr/local/src/apache/httpd-2.0.36/mod_perl-1.99_01/src/modules/p erl' gcc -I/usr/local/src/apache/httpd-2.0.36/mod_perl-1.99_01/src/modules/perl -I/usr/local/src/ap ache/httpd-2.0.36/mod_perl-1.99_01/xs -I/www/include -fno-strict-aliasing -I/usr/local/include -I/usr/lib/perl5/5.6.1/i386-linux/CORE -DMOD_PERL -O2 -march=i386 -mcpu=i686 -fPIC \ -c mod_perl.c mv mod_perl.o mod_perl.lo In file included from mod_perl.h:4, from mod_perl.c:1: modperl_apache_includes.h:46:22: apr_lock.h: No such file or directory make[1]: *** [mod_perl.lo] Error 1 make[1]: Leaving directory `/usr/local/src/apache/httpd-2.0.36/mod_perl-1.99_01/src/modules/pe rl' make: *** [modperl_lib] Error 2 ...I have no apr_lock.h in /www/includes. Do I need libapreq? If so, that install does not work either: ... apache_cookie.c:117: `c' undeclared (first use in this function) apache_cookie.c:118: invalid lvalue in assignment apache_cookie.c:120: request for member `r' in something not a structure or union apache_cookie.c: At top level: apache_cookie.c:144: parse error before `*' apache_cookie.c: In function `ApacheCookie_parse': apache_cookie.c:147: `retval' undeclared (first use in this function) apache_cookie.c:148: parse error before `)' apache_cookie.c:148: invalid lvalue in assignment apache_cookie.c:151: warning: assignment makes pointer from integer without a cast apache_cookie.c:156: `c' undeclared (first use in this function) apache_cookie.c:182: parse error before `)' apache_cookie.c: At top level: apache_cookie.c:196: parse error before `*' apache_cookie.c: In function `escape_url': apache_cookie.c:198: `p' undeclared (first use in this function) apache_cookie.c:198: `val' undeclared (first use in this function) apache_cookie.c: At top level: apache_cookie.c:230: parse error before `*' apache_cookie.c: In function `ApacheCookie_as_string': apache_cookie.c:232: `array_header' undeclared (first use in this function) apache_cookie.c:232: `values' undeclared (first use in this function) apache_cookie.c:233: `pool' undeclared (first use in this function) apache_cookie.c:233: `p' undeclared (first use in this function) apache_cookie.c:233: `c' undeclared (first use in this function) apache_cookie.c:234: parse error before `char' apache_cookie.c:248: `cookie' undeclared (first use in this function) apache_cookie.c:249: `i' undeclared (first use in this function) apache_cookie.c:256: `retval' undeclared (first use in this function) apache_cookie.c: At top level: apache_cookie.c:265: parse error before `*' apache_cookie.c: In function `ApacheCookie_bake': apache_cookie.c:267: `c' undeclared (first use in this function) make[1]: *** [apache_cookie.lo] Error 1 make[1]: Leaving directory `/usr/local/src/apache/httpd-2.0.36/libapreq-1.0/c' make: *** [all-recursive] Error 1 Any suggestions? Thanks ..Tom _ MSN Photos is the easiest way to share and print your photos: http://photos.msn.com/support/worldwide.aspx
err_header_out() not found in mod_perl 1.99
greetings, I'm using Apache2/mod_perl 1.99 on WinNT. Here's the error: [error] [client 127.0.0.1] Can't locate object method err_header_out via package Apache::RequestRec at C:\Apach... thanks in advance -pete
Re: err_header_out() not found in mod_perl 1.99
Nevermind, I found that err_headers_out() provides the needed functionality. Peter Rothermel wrote: greetings, I'm using Apache2/mod_perl 1.99 on WinNT. Here's the error: [error] [client 127.0.0.1] Can't locate object method err_header_out via package Apache::RequestRec at C:\Apach... thanks in advance -pete
Re: Problems with Apache-AuthCookie mod_perl 1.99
Michael, I've got most of the changes done. No major changes were required but I'm still stuck on mod_perl 2's new method handlers. To get past this hurdle I've moved away from method handlers and put everything into a single package. As soon as somebody gives me a hand with method handlers ala 2.0 I'll forward the code to you. -pete Michael J Schout wrote: On Thu, 2 May 2002, Per Einar Ellefsen wrote: At 21:25 02.05.2002, Peter Rothermel wrote: greetings, Has anybody had any luck getting Apache-AuthCookie going on an Apache 2.0 / mod_perl 1.99 setup? The first thing that I hit was $r-connection-user is deprecated. I've changed these to $r-user. The next hurdle is that the status code REDIRECT does not seen to be Apache::Constants. mod_perl 2 doesn't have Apache::Constants. You should use: use Apache::Const -compile = qw(... REDIRECT ..); Good luck on porting it to mod_perl 2! once you get it to work, it would be great if you could contribute it to the community! If you do get it working, feel free to forward patches to me as I am the AuthCookie maintainer. An apache 2.0 port is on my TODO list. Mike
Help with Method Handlers in mod_perl 1.99
Can somebody help me out with Method Handlers in Apache2 - mod_perl 1.99? I'm new to windows and its threading issues. Here's a simple authentication handler that shows where I'm getting stuck. I need to initialize a AuthDerivedHandler object but I'm not sure exactly how to do this. package Apache::AuthBaseHandler; use strict; use Apache::Constants qw(:common); use vars qw($VERSION); $VERSION = '3.00'; sub authenticate ($$) { my ($self, $r) = _; return OK; } sub new { my $this = shift; my $class = ref($this) || $this; my $self = {}; bless $self, $class; return $self; } 1; __END__ package Apache::AuthDerivedHandler; use strict; use Apache; use Apache::Constants qw(:common); use Apache::AuthBaseHandler; use vars qw($VERSION ISA); $VERSION = 1.0; ISA = qw(Apache::AuthBaseHandler); sub NonMethodAuthHandler($) { my $r = shift; my $authhandler = Apache::AuthDerivedHandler-new(); return $authhandler-authenticate($r); } 1; In my httpd.conf I have the following directives: Location /modperl/crash PerlOptions +GlobalRequest SetHandler perl-script AuthType Apache::AuthCookieHandler PerlAuthenHandler Apache::AuthDerivedHandler-authenticate PerlHandler Apache::hello require valid-user /Location Location /modperl/ok PerlOptions +GlobalRequest SetHandler perl-script AuthType Apache::AuthCookieHandler PerlAuthenHandler Apache::AuthDerivedHandler-authenticate PerlHandler Apache::hello require valid-user /Location In my startup.pl in have: $ENV{MOD_PERL} or die not running under mod_perl!; use Apache2 (); use Apache::compat (); use Carp (); use CGI (); CGI-compile(':all'); CGI-compile(':standard'); use CGI::Carp; use Apache::AuthDerivedHandler; 1;
Re: Help with Method Handlers in mod_perl 1.99
I tried the mehod attribute and now I get this error: Error message: Can't locate object method via package Apache::AuthDerivedHandler. Geoffrey Young wrote: Peter Rothermel wrote: Can somebody help me out with Method Handlers in Apache2 - mod_perl 1.99? I'm new to windows and its threading issues. [snip] sub authenticate ($$) { my ($self, $r) = _; return OK; } I haven't played much with mod_perl 2.0 yet, but I know that this format is deprecated now. instead, try sub authenticate : method { ... } and look for method handlers in design.pod and compat.pod HTH --Geoff
Problems with Apache-AuthCookie mod_perl 1.99
greetings, Has anybody had any luck getting Apache-AuthCookie going on an Apache 2.0 / mod_perl 1.99 setup? The first thing that I hit was $r-connection-user is deprecated. I've changed these to $r-user. The next hurdle is that the status code REDIRECT does not seen to be Apache::Constants. -pete
Is ActivePerl required with a mod_perl-Apache installation
Is there anyway to build mod_perl and Apache so that my target installation does not require ActivePerl on WinNT platforms. I'm currently doing my development on a WinNT that has ActivePerl installed and in my PATH. This is where I'm developing perl modules. When I move my installation over to a test WinNT machine without ActivePerl I get an error when Apache hits the LoadModule line for mod_perl.so. -pete