On Wed, 27 Sep 2000, Todd Chapman wrote:
>
> Problems with your suggestion:
>
> 1. The realm will not be known until I get path_info so
> <Location></Location> directives will not work.
you can use $r->auth_name($realm) to set it at request time.
> 2. How can I get Perl to do the password lookup in the dynamically
> selected AuthUserFile?
since mod_auth.c's structure defs are private to mod_auth.c, there's no
$r->api for this. what you can do use .htaccess like so:
<Perl>
my $r = Apache->request;
my $testing = $r->path_info =~ /test/;
$AuthType = "Basic";
$AuthName = $testing ? "Testing" : "Whatever";
$Require = "user dougm";
$AuthUserFile = $testing ? "/tmp/htpasswd" : "/whatever/htpasswd";
</Perl>
also, i just committed this patch that makes $r->auth_type writable, the
same way $r->auth_name is. and, defaults auth_type to Basic when unset
and $r->get_basic_auth_pw is called.
Index: src/modules/perl/Apache.xs
===================================================================
RCS file: /home/cvs/modperl/src/modules/perl/Apache.xs,v
retrieving revision 1.110
diff -u -r1.110 Apache.xs
--- src/modules/perl/Apache.xs 2000/09/27 19:44:23 1.110
+++ src/modules/perl/Apache.xs 2000/09/27 23:43:33
@@ -824,8 +824,9 @@
char *val
const char *
-auth_type(r)
+mod_perl_auth_type(r, val=NULL)
Apache r
+ char *val
const char *
document_root(r, ...)
@@ -887,6 +888,9 @@
int ret;
PPCODE:
+ if (!auth_type(r)) {
+ (void)mod_perl_auth_type(r, "Basic");
+ }
ret = get_basic_auth_pw(r, &sent_pw);
XPUSHs(sv_2mortal((SV*)newSViv(ret)));
if(ret == OK)
Index: src/modules/perl/mod_perl.h
===================================================================
RCS file: /home/cvs/modperl/src/modules/perl/mod_perl.h,v
retrieving revision 1.103
diff -u -r1.103 mod_perl.h
--- src/modules/perl/mod_perl.h 2000/09/22 18:51:59 1.103
+++ src/modules/perl/mod_perl.h 2000/09/27 23:43:46
@@ -1185,6 +1185,7 @@
perl_require_module("Apache", s)
char *mod_perl_auth_name(request_rec *r, char *val);
+char *mod_perl_auth_type(request_rec *r, char *val);
module *perl_get_module_ptr(char *name, int len);
void *perl_merge_server_config(pool *p, void *basev, void *addv);
Index: src/modules/perl/perl_config.c
===================================================================
RCS file: /home/cvs/modperl/src/modules/perl/perl_config.c,v
retrieving revision 1.105
diff -u -r1.105 perl_config.c
--- src/modules/perl/perl_config.c 2000/09/27 15:37:33 1.105
+++ src/modules/perl/perl_config.c 2000/09/27 23:44:03
@@ -158,6 +158,24 @@
#endif
}
+char *mod_perl_auth_type(request_rec *r, char *val)
+{
+#ifndef WIN32
+ core_dir_config *conf =
+ (core_dir_config *)get_module_config(r->per_dir_config, &core_module);
+
+ if(val) {
+ conf->auth_type = pstrdup(r->pool, val);
+ set_module_config(r->per_dir_config, &core_module, (void*)conf);
+ MP_TRACE_g(fprintf(stderr, "mod_perl: setting auth_type to %s\n",
+conf->auth_name));
+ }
+
+ return conf->auth_type;
+#else
+ return (char *) auth_type(r);
+#endif
+}
+
void mod_perl_dir_env(request_rec *r, perl_dir_config *cld)
{
if(MP_HASENV(cld)) {