2011-05-29 95 views
2

我目前嘗試配置collective.xsendfile,阿帕奇mod_xsendfile和Plone 4collective.xsendfile,ZODB斑點和UNIX文件權限

顯然,Apache進程沒有看到文件系統上的文件blobstrage因爲它們包含的權限:

LS -lh VAR/blobstorage/0×00/0×00/0×00/0×00/0×00 /爲0x18/0xd5/0x19/0x038ea09d0eddc611.blob -r -------- 1周的Plone Plone的1006K 15年5月28日: 30 var/blobstorage/0x00/0x00/0x00/0x00/0x00/0x18/0xd5/0x19/0x038ea09d0eddc611.blob

如何配置blobstorage以添加addit離子的權限,以便Apache可以訪問這些文件?

回答

4

blobstorage寫入目錄和文件的模式在ZODB.blob中被硬編碼。具體來說,默認情況下,標準ZODB.blob.FileSystemHelper類創建安全目錄(只對當前用戶可讀和可寫)。

你可以自己實現的FileSystemHelper這要麼使這個配置,或者只是設置目錄模式0750,然後打補丁ZODB.blob.BlobStorageMixin使用而不是默認的類:

import os 
from ZODB import utils 
from ZODB.blob import FilesystemHelper, BlobStorageMixin 
from ZODB.blob import log, LAYOUT_MARKER 

class GroupReadableFilesystemHelper(FilesystemHelper): 
    def create(self): 
     if not os.path.exists(self.base_dir): 
      os.makedirs(self.base_dir, 0750) 
      log("Blob directory '%s' does not exist. " 
       "Created new directory." % self.base_dir) 
     if not os.path.exists(self.temp_dir): 
      os.makedirs(self.temp_dir, 0750) 
      log("Blob temporary directory '%s' does not exist. " 
       "Created new directory." % self.temp_dir) 

     if not os.path.exists(os.path.join(self.base_dir, LAYOUT_MARKER)): 
      layout_marker = open(
       os.path.join(self.base_dir, LAYOUT_MARKER), 'wb') 
      layout_marker.write(self.layout_name) 
     else: 
      layout = open(os.path.join(self.base_dir, LAYOUT_MARKER), 'rb' 
         ).read().strip() 
      if layout != self.layout_name: 
       raise ValueError(
        "Directory layout `%s` selected for blob directory %s, but " 
        "marker found for layout `%s`" % 
        (self.layout_name, self.base_dir, layout)) 

    def isSecure(self, path): 
     """Ensure that (POSIX) path mode bits are 0750.""" 
     return (os.stat(path).st_mode & 027) == 0 

    def getPathForOID(self, oid, create=False): 
     """Given an OID, return the path on the filesystem where 
     the blob data relating to that OID is stored. 

     If the create flag is given, the path is also created if it didn't 
     exist already. 

     """ 
     # OIDs are numbers and sometimes passed around as integers. For our 
     # computations we rely on the 64-bit packed string representation. 
     if isinstance(oid, int): 
      oid = utils.p64(oid) 

     path = self.layout.oid_to_path(oid) 
     path = os.path.join(self.base_dir, path) 

     if create and not os.path.exists(path): 
      try: 
       os.makedirs(path, 0750) 
      except OSError: 
       # We might have lost a race. If so, the directory 
       # must exist now 
       assert os.path.exists(path) 
     return path 


def _blob_init_groupread(self, blob_dir, layout='automatic'): 
    self.fshelper = GroupReadableFilesystemHelper(blob_dir, layout) 
    self.fshelper.create() 
    self.fshelper.checkSecure() 
    self.dirty_oids = [] 

BlobStorageMixin._blob_init = _blob_init_groupread 

相當滿意,您可能希望將其作爲ZODB3的功能請求:-)

+0

在ZEO設置中,我應該打補丁ZEO服務器,對吧?用服務器和客戶端做了一些測試,看起來像客戶端的猴子補丁沒有運行(嘗試上傳文件,沒有發生任何事情)。 – 2011-05-29 20:05:21

+1

@Mikko:在ZEO設置中,您確實想要修補ZEO服務器和客戶端。據推測,你已將shared-blob-dir設置爲True,在這種情況下,客戶端和服務器都將使用blob數據目錄。 無論如何,您可能首先想要在獨立的設置上進行測試。此外,現有的blob datadir結構必須更新權限(chmod -R g + r),因爲此修補程序不會更改現有目錄,而只會更改新創建的目錄。 – 2011-05-29 20:24:35

+0

謝謝Martjin。這裏是正在進行的工作:https://github.com/miohtama/collective.xsendfile – 2011-05-29 22:54:12

2

在設置ZOPE/ZEO設置的備份例程時,我遇到了與blob權限相同的問題。

在嘗試應用Mikko寫的猴子補丁(這並不容易)後,我想出了一個「真正的」補丁來解決這個問題。

Martijn建議的修補程序不完整,它仍然沒有在blob文件上設置正確的模式。

因此,這裏是我的解決方案:

1)創建一個包含補丁:

Index: ZODB/blob.py 
=================================================================== 
--- ZODB/blob.py (Revision 121959) 
+++ ZODB/blob.py (Arbeitskopie) 
@@ -337,11 +337,11 @@ 

    def create(self): 
     if not os.path.exists(self.base_dir): 
-   os.makedirs(self.base_dir, 0700) 
+   os.makedirs(self.base_dir, 0750) 
      log("Blob directory '%s' does not exist. " 
       "Created new directory." % self.base_dir) 
     if not os.path.exists(self.temp_dir): 
-   os.makedirs(self.temp_dir, 0700) 
+   os.makedirs(self.temp_dir, 0750) 
      log("Blob temporary directory '%s' does not exist. " 
       "Created new directory." % self.temp_dir) 

@@ -359,8 +359,8 @@ 
        (self.layout_name, self.base_dir, layout)) 

    def isSecure(self, path): 
-  """Ensure that (POSIX) path mode bits are 0700.""" 
-  return (os.stat(path).st_mode & 077) == 0 
+  """Ensure that (POSIX) path mode bits are 0750.""" 
+  return (os.stat(path).st_mode & 027) == 0 

    def checkSecure(self): 
     if not self.isSecure(self.base_dir): 
@@ -385,7 +385,7 @@ 

     if create and not os.path.exists(path): 
      try: 
-    os.makedirs(path, 0700) 
+    os.makedirs(path, 0750) 
      except OSError: 
       # We might have lost a race. If so, the directory 
       # must exist now 
@@ -891,7 +891,7 @@ 
      file2.close() 
     remove_committed(f1) 
    if chmod: 
-  os.chmod(f2, stat.S_IREAD) 
+  os.chmod(f2, stat.S_IRUSR | stat.S_IRGRP) 

if sys.platform == 'win32': 
    # On Windows, you can't remove read-only files, so make the 

您還可以看看這裏的補丁 - >http://pastebin.com/wNLYyXvw

2)存儲在您的buildout根目錄中名稱爲'blob.patch'的補丁

3.)擴展您的buildout配置:

parts += 
    patchblob 
    postinstall 

[patchblob] 
recipe = collective.recipe.patch 
egg = ZODB3 
patches = blob.patch 

[postinstall] 
recipe = plone.recipe.command 
command = 
    chmod -R g+r ${buildout:directory}/var 
    find ${buildout:directory}/var -type d | xargs chmod g+x 
update-command = ${:command} 

postinstall部分在已存在的斑點上設置所需的組讀取權限。請注意,還必須將執行權限授予blob文件夾,該組可以進入目錄。

我用ZODB 3.10.2和3.10.3測試了這個補丁。

正如Martijn所建議的,這應該是可配置的,並且可以直接作爲ZODB的一部分。

+0

你真的不想在蛋上做一個直接的補丁。改爲使用monkeypatch。 – 2011-06-17 08:32:39