Redistribute user's list of files.

Signed-off-by: Luca Bigliardi <shamm...@google.com>
---
 lib/backend.py |   21 ++++++++++++++++++++-
 lib/cmdlib.py  |   13 +++++++++++++
 2 files changed, 33 insertions(+), 1 deletions(-)

diff --git a/lib/backend.py b/lib/backend.py
index e10d4c8..30be8d6 100644
--- a/lib/backend.py
+++ b/lib/backend.py
@@ -177,6 +177,24 @@ def _BuildGanetiUploadFileList():
 _GANETI_ALLOWED_UPLOAD_FILES = _BuildGanetiUploadFileList()
 
 
+def _GenerateUserUploadFileList():
+  """Generate the list of upload files allowed by the users.
+
+  This information must be generated upon each request because the list might
+  have changed after import time.
+
+  """
+  try:
+    extra_files = set(utils.ReadFile(constants.EXTRA_REDIST).splitlines())
+  except EnvironmentError, err:
+    msg = ("Not allowing redistribution of extra files from %s : %s" %
+           (constants.EXTRA_REDIST, err.strerror))
+    logging.warning(msg)
+    return frozenset()
+
+  return frozenset(extra_files)
+
+
 def JobQueuePurge():
   """Removes job queue files and archived jobs.
 
@@ -1460,7 +1478,8 @@ def UploadFile(file_name, data, mode, uid, gid, atime, 
mtime):
   if not os.path.isabs(file_name):
     _Fail("Filename passed to UploadFile is not absolute: '%s'", file_name)
 
-  if file_name not in _GANETI_ALLOWED_UPLOAD_FILES:
+  if not ((file_name in _GANETI_ALLOWED_UPLOAD_FILES) or
+          (file_name in _GenerateUserUploadFileList())):
     _Fail("Filename passed to UploadFile not in allowed upload targets: '%s'",
           file_name)
 
diff --git a/lib/cmdlib.py b/lib/cmdlib.py
index 5596b0c..f5db4ea 100644
--- a/lib/cmdlib.py
+++ b/lib/cmdlib.py
@@ -1785,6 +1785,19 @@ def _RedistributeAncillaryFiles(lu, 
additional_nodes=None):
     hv_class = hypervisor.GetHypervisor(hv_name)
     dist_files.update(hv_class.GetAncillaryFiles())
 
+  try:
+    extra_dist_list = utils.ReadFile(constants.EXTRA_REDIST).splitlines()
+    for file in extra_dist_list:
+      if os.path.isabs(file):
+        dist_files.update([file])
+      else:
+        msg = ("Not redistributing %s : not absolute path" % file)
+        lu.proc.LogInfo(msg)
+  except EnvironmentError, err:
+    msg = ("Not redistributing extra files from %s : %s" %
+           (constants.EXTRA_REDIST, err.strerror))
+    lu.proc.LogInfo(msg)
+
   # 3. Perform the files upload
   for fname in dist_files:
     if os.path.exists(fname):
-- 
1.5.4.3

Reply via email to