1

I am experimenting with private file system, done custom way :) .

There is file system/files/test.txt (That is, private://test.txt).

When I try to access the file, I get access denied from Drupal, as expected (site redirects to Access denied page, and dblog shows that accesss have been denied).

But now I want to know what module/function have blocked access to the file. I am blindly trying to check hook_file_download or hook_file_download_access, but as far as I can see it does not go through that functions.

All that in attempt to solve this.

3

If the Drupal log shows you that the access has been denied, then you have a simple way to debug this: if you have a debugger, simply set a breakpoint in drupal_set_message. Skip calls to that function (there shouldn't be too many) until you get the one with the access denied message - and then look at the backtrace. This should show you which function denied the access.

If you don't have a debugger, you can simply (temporarily) add some extra code in that function to test for the relevant error message, and then output a backtrace using debug_backtrace. You can output the data on the screen, to a log file using drupal_debug (if you have the devel module enabled), add it to the generated error message, etc.

  • nice tips, but problem is that I do not know what functions are being called when access was denied. I use devel and using drupal_set_message to see if some function has been triggered, but here simply I dont know where to look :( – NenadP Apr 8 '13 at 10:16
  • What do you mean by "dblog shows that accesss have been denied" ? Do you get an error in the Drupal Reports ? If so that calls drupal_set_message. What do you get when you output a backtrace from that function when that specific error is logged ? – Alice Heaton Apr 8 '13 at 10:26
  • yes, dblog says that access has been denied (and that was what I expected). But I cannot figure which module blocks access, so I can customize access with an hook. – NenadP Apr 8 '13 at 10:28
  • Alice, error message was generated by Drupal core, it is not message that I output to watchdog. – NenadP Apr 8 '13 at 10:30
  • 1
    Understood - the error is generated by Core. So what I'm suggesting is to add some code at the point where the error is generated (ie. drupal_set_message), and to output a backtrace at that point. The backtrace will show you which function is generating the error - and therefore which function is denying the access. Once you know that, you might be able to work out how to customize access by looking at that function's code. This does require you to change Core, but that's only temporarily to debug what is happening. – Alice Heaton Apr 8 '13 at 10:58
0

This sounds as though its not Drupal blocking the access to this file but the filesystem. When Drupal runs it runs with the permissions of the webserver its running on. If the webserver can't access these files neither can PHP and subsequently Drupal.

A way to see if this is the problem is to set the file permissions on this test file to 777 and see what happens then.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.