Hi,
Today I made it my task to hack role based access control to uploaded files into Drupal. It turned out to be considerably easier than I originally anticipated. I'm new to drupal development, so I'm posting to ask how well my approach conforms with the "drupal way" and how secure it is.
This was done using a checkout from drupal cvs on the 15th of August. First of all, the filestore2 module makes a call to filter_tips_short which has been removed in the current version of drupal, so I changed this to filter_filter_tips(0, FI
LTER_HTML_STRIP). I don't know if this is right, but it works at least.
It is reasonable to assume that if someone has access to the node with which the file is associated, then they should have access to the file itself. Someone can only really know the url for the file itself without appropriate access permissions if they are doing something bold. Therefore, all we have to do before making a call to fscache_download is call node_access() to see if the user is allowed to read the node associated with the file. If it is, we proceed as normal by calling fscache, otherwise we do nothing and a blank document gets returned.
Comments very gratefully received.
PATCH:
91d90
<
94,97c93,98
< $node = node_load(array("nid" => arg(2)));
< if (fscache_download(array("fsid" => $node->fsid), TRUE)) {
< db_query("UPDATE {filestore2} SET downloads = downloads + 1 WHERE nid = $node->nid");