From 9a914f7a51b1563086eb57a736ceff133e6eb21f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ren=C3=A9=20Nussbaumer?= <rn@google.com> Date: Thu, 19 May 2011 10:37:58 +0200 Subject: [PATCH] RPC/Backend: Make UploadFile uid and gid agnostic MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: RenΓ© Nussbaumer <rn@google.com> Reviewed-by: Iustin Pop <iustin@google.com> --- lib/backend.py | 15 +++++++++++---- lib/rpc.py | 6 ++++-- 2 files changed, 15 insertions(+), 6 deletions(-) diff --git a/lib/backend.py b/lib/backend.py index 339440b3a..a3c3fa16f 100644 --- a/lib/backend.py +++ b/lib/backend.py @@ -1801,10 +1801,10 @@ def UploadFile(file_name, data, mode, uid, gid, atime, mtime): @param data: the new contents of the file @type mode: int @param mode: the mode to give the file (can be None) - @type uid: int - @param uid: the owner of the file (can be -1 for default) - @type gid: int - @param gid: the group of the file (can be -1 for default) + @type uid: string + @param uid: the owner of the file + @type gid: string + @param gid: the group of the file @type atime: float @param atime: the atime to set on the file (can be None) @type mtime: float @@ -1821,6 +1821,13 @@ def UploadFile(file_name, data, mode, uid, gid, atime, mtime): raw_data = _Decompress(data) + if not (isinstance(uid, basestring) and isinstance(gid, basestring)): + _Fail("Invalid username/groupname type") + + getents = runtime.GetEnts() + uid = getents.LookupUser(uid) + gid = getents.LookupGroup(gid) + utils.SafeWriteFile(file_name, None, data=raw_data, mode=mode, uid=uid, gid=gid, atime=atime, mtime=mtime) diff --git a/lib/rpc.py b/lib/rpc.py index 4e2693e55..1414170ac 100644 --- a/lib/rpc.py +++ b/lib/rpc.py @@ -45,6 +45,7 @@ from ganeti import constants from ganeti import errors from ganeti import netutils from ganeti import ssconf +from ganeti import runtime # pylint has a bug here, doesn't see this import import ganeti.http.client # pylint: disable-msg=W0611 @@ -1168,8 +1169,9 @@ class RpcRunner(object): file_contents = utils.ReadFile(file_name) data = cls._Compress(file_contents) st = os.stat(file_name) - params = [file_name, data, st.st_mode, st.st_uid, st.st_gid, - st.st_atime, st.st_mtime] + getents = runtime.GetEnts() + params = [file_name, data, st.st_mode, getents.LookupUid(st.st_uid), + getents.LookupGid(st.st_gid), st.st_atime, st.st_mtime] return cls._StaticMultiNodeCall(node_list, "upload_file", params, address_list=address_list) -- GitLab