Issue Details (XML | Word | Printable)

Key: MODPYTHON-126
Type: Bug Bug
Status: Closed Closed
Resolution: Fixed
Priority: Major Major
Assignee: Graham Dumpleton
Reporter: Graham Dumpleton
Votes: 0
Watchers: 0
Operations

If you were logged in you would be able to see more operations.
mod_python

PythonHandler in <Files> directive sets req.hlist.directory to useless value.

Created: 10/Feb/06 07:17 AM   Updated: 05/Apr/07 11:47 AM
Return to search
Component/s: core
Affects Version/s: 3.2.7
Fix Version/s: 3.3.1

Time Tracking:
Not Specified

Resolution Date: 07/May/06 02:11 PM


 Description  « Hide
When you have Apache ".htaccess" configuration like:

  SetHandler mod_python
  #PythonPath "['/Users/grahamd/Sites/auth']+sys.path"

  <Files "page1.txt">
  PythonHandler page1::handler_txt
  </Files>
  <Files "page2.txt">
  PythonHandler page2::handler_txt
  </Files>

and "page1.txt" is accessed, the req.hlist.directory attribute, which is supposed to list the name of the directory the PythonHandler directive was used in, gets set to "page1.txt/" instead.

This value then gets added into "sys.path". Because it doesn't actually identify the directory, the module "page1" cannot actually be found when the import is performed.

[Fri Feb 10 09:08:40 2006] [error] [client 127.0.0.1] PythonHandler page1::handler_txt: Traceback (most recent call last):
[Fri Feb 10 09:08:40 2006] [error] [client 127.0.0.1] PythonHandler page1::handler_txt: File "/System/Library/Frameworks/Python.framework/Versions/2.3/lib/python2.3/site-packages/mod_python/apache.py", line 288, in HandlerDispatch\n log=debug)
[Fri Feb 10 09:08:40 2006] [error] [client 127.0.0.1] PythonHandler page1::handler_txt: File "/System/Library/Frameworks/Python.framework/Versions/2.3/lib/python2.3/site-packages/mod_python/apache.py", line 508, in import_module\n f, p, d = imp.find_module(parts[i], path)
[Fri Feb 10 09:08:40 2006] [error] [client 127.0.0.1] PythonHandler page1::handler_txt: ImportError: No module named page1

The only workaround at this point is to explicitly define the PythonPath directive to include the directory the modules and ".htaccess" file are in. Not sure yet whether there is a way in Apache of determining the directory the "Files" directive is used in and set "req.hlist.directory" correctly.

 All   Comments   Work Log   Change History   Subversion Commits      Sort Order: Ascending order - Click to sort in descending order
Graham Dumpleton added a comment - 10/Feb/06 12:55 PM
It is impossible to fix this in a way that wouldn't require additional configuration directives to be added to the example.

The only way to get access to the directory associated with the explicit/implicit "Directory" directive enclosing the "Files" directive is for there to exist some other Python directive outside of the "Files" directive so as to trigger the creation of a per_dir_config which would then hold the config_dir. This would still require the code which merges the per_dir_config's to give precedence to a config_dir in a parent context when it is an absolute pathname and the current isn't. Determining if a directory on Win32 is an absolute pathname can be hard and can't find a Apache routine which does it. Either way, it still would require another mod_python directive to have been used, meaning a dummy one may need to be added to fake things so it works properly.

Overall, what might be better is that support for using "Python*Handler" inside of "Files" directives be accomodated using other means based on future changes to be made to the module importer. Thus, need to revisit this problem when importer is fixed.

Graham Dumpleton added a comment - 14/Feb/06 07:12 PM
FWIW, I think I know how to fix the above so it works. This time I stumbled onto the fact that in Apache one can programmatically query back through the contexts of directives defined in a configuration. This will allow the code which deals with Python*Handler directives to query back looking for the Directory or DirectoryMatch directive it was used in.

If it can't find either, then it would have been a Location directive and it now will know the URL should not be used as the handler directory. If it did find Directory, it could work out the argument to it and use that as the basis for working out the directory. Ie., it would skip past any File directives and go direct to the Directory context.

The only trick to solve is the best way of dealing with wildcards or regexes for directory. One probably has to leave it until the very point that request is being handled, which means that Apache wildcard/regex matching routines may need to be exposed in mod_python Python APIs to ensure same matching scheme can be used against the req.filename member.

Thus, my whole idea of being able to mark base directories as discussed on mailing list is no longer relevant to solving this particular issue.

Repository Revision Date User Message
ASF #392692 Sun Apr 09 08:58:35 UTC 2006 grahamd The PythonImport directive makes use of the handler list data structure
even though it specifically is for a different purpose. The handler list
data structure needs to be changed a bit in order to support changes
required to address MODPYTHON-63 and MODPYTHON-126. These changes may
make it unusable in the way that the PythonImport directive was using it,
or at least it will not be a good match. The PythonImport directive has
therefore been modified to use a standard Apache table object thereby
allowing arbitrary changes to the handler list data structure to be made as
necessary.

Note that although the current Apache table implementation probably results
in module imports occuring in the order they appear in the Apache
configuration file, if how it is implemented is changed, this may no longer
be the case. This is not seen as an issue as the documentation for the
PythonImport directive does not give any guarantees about ordering of
imports within the context of a specific interpreter and it would be bad
practice for modules to rely on mod_python importing them in a specific
order. If there are ordering requirements, it should be dealt with internal
to the module being imported so that it is self contained.
Files Changed
MODIFY /httpd/mod_python/trunk/src/include/mod_python.h
MODIFY /httpd/mod_python/trunk/src/mod_python.c
MODIFY /httpd/mod_python/trunk/lib/python/mod_python/__init__.py
MODIFY /httpd/mod_python/trunk/src/include/mpversion.h
MODIFY /httpd/mod_python/trunk/src/include/mod_python.h.in

Graham Dumpleton made changes - 09/Apr/06 02:16 PM
Field Original Value New Value
Assignee Graham Dumpleton [ grahamd ]
Graham Dumpleton made changes - 09/Apr/06 02:17 PM
Status Open [ 1 ] In Progress [ 3 ]
Repository Revision Date User Message
ASF #394455 Sun Apr 16 10:49:39 UTC 2006 grahamd When Python*Handler or Python*Filter directive is used inside of a Files
directive container, the handler/filter directory value will now correctly
resolve to the directory corresponding to any parent Directory directive or
the location of the .htaccess file the Files directive is contained in.
(MODPYTHON-126])

The patch also lays the ground work for being able to support Directory
directive with glob style wildcards or Directory/DirectoryMatch directive
with a regular expression. (MODPYTHON-63)
Files Changed
MODIFY /httpd/mod_python/trunk/test/htdocs/tests.py
MODIFY /httpd/mod_python/trunk/src/hlist.c
MODIFY /httpd/mod_python/trunk/src/include/mod_python.h
MODIFY /httpd/mod_python/trunk/test/httpdconf.py
MODIFY /httpd/mod_python/trunk/test/test.py
MODIFY /httpd/mod_python/trunk/src/mod_python.c
MODIFY /httpd/mod_python/trunk/src/requestobject.c
MODIFY /httpd/mod_python/trunk/Doc/appendixc.tex
MODIFY /httpd/mod_python/trunk/src/include/hlist.h
MODIFY /httpd/mod_python/trunk/src/include/mod_python.h.in

Repository Revision Date User Message
ASF #395072 Tue Apr 18 22:16:48 UTC 2006 grahamd Need to canonicalize directory path so as to normalize on POSIX style directory
naming conventions, else backslashes on Win32 propogate through. (MODPYTHON-126)
Files Changed
MODIFY /httpd/mod_python/trunk/src/mod_python.c
MODIFY /httpd/mod_python/trunk/lib/python/mod_python/__init__.py
MODIFY /httpd/mod_python/trunk/src/include/mpversion.h

Repository Revision Date User Message
ASF #395571 Thu Apr 20 12:04:23 UTC 2006 grahamd Debian backported ap_regex_t to Apache 2.0 and thus made official version
checking break for this feature. Use explicit check for AP_REG_EXTENDED
in addition to version check. (MODPYTHON-63) (MODPYTHON-126)
Files Changed
MODIFY /httpd/mod_python/trunk/src/include/mod_python.h
MODIFY /httpd/mod_python/trunk/lib/python/mod_python/__init__.py
MODIFY /httpd/mod_python/trunk/src/include/mpversion.h
MODIFY /httpd/mod_python/trunk/src/include/mod_python.h.in

Graham Dumpleton made changes - 24/Apr/06 06:29 AM
Resolution Fixed [ 1 ]
Status In Progress [ 3 ] Resolved [ 5 ]
Fix Version/s 3.3 [ 12310101 ]
Graham Dumpleton made changes - 07/May/06 02:09 PM
Resolution Fixed [ 1 ]
Status Resolved [ 5 ] Reopened [ 4 ]
Graham Dumpleton added a comment - 07/May/06 02:11 PM
Whoops, reopened wrong issue was supposed to be MODPYTHON-103.

Graham Dumpleton made changes - 07/May/06 02:11 PM
Status Reopened [ 4 ] Resolved [ 5 ]
Resolution Fixed [ 1 ]
Graham Dumpleton made changes - 07/May/06 02:11 PM
Comment [ Reopened because using PythonInterpPerDirective in conjunction with dynamically registered filters causes mod_python to crash. Problem code is in select_interp_name().

            py_handler *fh;
                
            if (fname) {
                if (is_input) {
                    fh = (py_handler *)apr_hash_get(conf->in_filters, fname,
                                                           APR_HASH_KEY_STRING);
                } else {
                    fh = (py_handler *)apr_hash_get(conf->out_filters, fname,
                                                           APR_HASH_KEY_STRING);
                }
                s = fh->directory;
            }
            else {
                s = hle->directory;
            }

For a dynamically registered filter, fname is "mod_python" and the context provided with the filter handler is used to get details of dynamically registered filter. This information isn't available or used by select_interp_name() which assumes that filter is part of globally registered filters. It will not find the filter and so "fh" is NULL and accessing directory attribute causes a crash. ]
Graham Dumpleton made changes - 05/Apr/07 11:47 AM
Status Resolved [ 5 ] Closed [ 6 ]