Bug 51991 - Mod_authn_socache seg faults when configured from .htaccess
Summary: Mod_authn_socache seg faults when configured from .htaccess
Status: RESOLVED WORKSFORME
Alias: None
Product: Apache httpd-2
Classification: Unclassified
Component: mod_authn_socache (show other bugs)
Version: 2.3.14-beta
Hardware: PC Linux
: P2 major (vote)
Target Milestone: ---
Assignee: Apache HTTPD Bugs Mailing List
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2011-10-07 14:38 UTC by Jan Wolter
Modified: 2013-03-19 23:00 UTC (History)
1 user (show)



Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Jan Wolter 2011-10-07 14:38:04 UTC
First this is 2.3.14-beta, which wasn't an option on the Version select.

I was trying to modify an authentication module I maintain to work with mod_authn_socache, and set up a test directory with a .htaccess file. Apache seg faulted every time I hit the directory. Eventually, I took my module out and tried mod_authn_file instead, using the .htaccess file below:

AuthType Basic
AuthName "This is a test"
AuthBasicProvider socache file
AuthUserFile /home/jan/apache2.3/htdocs/mae2/htpasswd
AuthnCacheProvideFor file
Require valid-user

Still crashed. So, huh, maybe not my module at fault? Looked at it under gdb. It was crashing because mod_authn_socache's check_password() function was calling

   rv = socache_provider->retrieve(socache_instance, r->server,
                                    (unsigned char*)key, strlen(key),
                                    val, &vallen, r->pool);

while socache_instance was NULL. This looks like it is supposed to be initialized from the authn_cache_post_config() function which is called on the "post_config" hook. Well, yeah, but I have the vague idea that that occurs only after reading the server config, not after reading .htaccess. So since I had no AuthnCacheProvideFor directives in the server config, it wouldn't initialize at that time. It doesn't encounter the AuthnCacheProvideFor directives in my .htaccess file until later.

So I took the configuration directives out of my .htaccess file, and stuck them in a <Directory> block in httpd.conf.  No more segmentation fault.
Comment 1 Nick Kew 2011-10-07 16:05:14 UTC
Good catch, though not 100% right.  The issue is that the post_config hook tests for "configured", and doesn't set anything up if there's no authn_socache configuration.

Solution: an extra configuration directive that'll just say "yes, enable me" in post_config, together with testing "configured" flag in the later functions.  Bug me if I haven't committed a fix by Sunday.
Comment 2 Nick Kew 2011-10-08 14:54:04 UTC
Fixed in r1180384

Introduces AuthnCacheEnable directive to determine whether initialisation happens so it can be used in .htaccess.  If not enabled, it just fails silently from htaccess.
Comment 3 Jan Wolter 2011-10-10 02:07:48 UTC
Do I understand correctly that to able to use authn_socache from a .htaccess file, there now needs to be this argumentless "AuthnCacheEnable" command someplace in the main config file? So if I'm an ISP with thousands of clients on my servers and I think one of them might someday want to use authn_socache, then I ought to put "AuthnCacheEnable" in my config files? This seems bizarre. If I have the mod_authn_socache module installed, then haven't I already indicated my desire that it be available? Why do I need a directive that says "Not only do I want you to be installed, I want you to work too!" I don't understand it.

Philosophy aside, I think there is still a problem. I haven't tested it, just looked at the code, but it looks to me like if you forget to put "AuthnCacheEnable" into the config file, and try to use it from a .htaccess file, then you'd still get a Segmentation Violation.  Wouldn't it be better if it generated a nice neat "You forgot to put the meaningless AuthnCacheEnable directive into your config file so I'm going to ignore you, neener neener" message? Or better yet, just went ahead and initialized itself?
Comment 4 Tianyin Xu 2012-03-04 04:44:00 UTC
Hi, Jan, did you test and confirm that "if you forget to put 'AuthnCacheEnable' into the config file, and try to use it from a .htaccess file, then you'd still get a Segmentation Violation"?

Thanks a lot!