aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorHisham <hisham@gobolinux.org>2017-01-08 13:31:27 -0200
committerHisham Muhammad <hisham@gobolinux.org>2017-09-12 20:35:43 -0300
commit1eb598706f9000361f0059a303c3cf99be5a8ceb (patch)
treedd56ecd9cc45b314313e29e41fa078b1cd83d2ef /src
parentd0a9e68a4125c043a6ee6a4d92ac244f2feb7ccb (diff)
downloadluarocks-1eb598706f9000361f0059a303c3cf99be5a8ceb.tar.gz
luarocks-1eb598706f9000361f0059a303c3cf99be5a8ceb.tar.bz2
luarocks-1eb598706f9000361f0059a303c3cf99be5a8ceb.zip
Improve error checking in ownership check.
See #664.
Diffstat (limited to 'src')
-rw-r--r--src/luarocks/command_line.lua15
-rw-r--r--src/luarocks/fs/lua.lua8
-rw-r--r--src/luarocks/fs/unix/tools.lua5
-rw-r--r--src/luarocks/fs/win32.lua2
4 files changed, 23 insertions, 7 deletions
diff --git a/src/luarocks/command_line.lua b/src/luarocks/command_line.lua
index 31948b33..ac5ccd35 100644
--- a/src/luarocks/command_line.lua
+++ b/src/luarocks/command_line.lua
@@ -40,6 +40,18 @@ local function replace_tree(flags, tree)
40 path.use_tree(tree) 40 path.use_tree(tree)
41end 41end
42 42
43local function is_ownership_ok(directory)
44 local me = fs.current_user()
45 for _ = 1,3 do -- try up to grandparent
46 local owner = fs.attributes(directory, "owner")
47 if owner then
48 return owner == me
49 end
50 directory = dir.dir_name(directory)
51 end
52 return false
53end
54
43--- Main command-line processor. 55--- Main command-line processor.
44-- Parses input arguments and calls the appropriate driver function 56-- Parses input arguments and calls the appropriate driver function
45-- to execute the action requested on the command-line, forwarding 57-- to execute the action requested on the command-line, forwarding
@@ -182,8 +194,7 @@ function command_line.run_command(...)
182 die("Current directory does not exist. Please run LuaRocks from an existing directory.") 194 die("Current directory does not exist. Please run LuaRocks from an existing directory.")
183 end 195 end
184 196
185 if fs.attributes(cfg.local_cache, "owner") ~= fs.current_user() or 197 if not is_ownership_ok(cfg.local_cache) then
186 fs.attributes(dir.dir_name(cfg.local_cache), "owner") ~= fs.current_user() then
187 util.warning("The directory '" .. cfg.local_cache .. "' or its parent directory ".. 198 util.warning("The directory '" .. cfg.local_cache .. "' or its parent directory "..
188 "is not owned by the current user and the cache has been disabled. ".. 199 "is not owned by the current user and the cache has been disabled. "..
189 "Please check the permissions and owner of that directory. ".. 200 "Please check the permissions and owner of that directory. "..
diff --git a/src/luarocks/fs/lua.lua b/src/luarocks/fs/lua.lua
index 097f800f..841b7243 100644
--- a/src/luarocks/fs/lua.lua
+++ b/src/luarocks/fs/lua.lua
@@ -760,11 +760,13 @@ end
760 760
761function fs_lua.attributes(file, attrtype) 761function fs_lua.attributes(file, attrtype)
762 if attrtype == "permissions" then 762 if attrtype == "permissions" then
763 return posix.stat(file, "mode") 763 return posix.stat(file, "mode") or nil
764 elseif attrtype == "owner" then 764 elseif attrtype == "owner" then
765 return posix.getpwuid(posix.stat(file, "uid")).pw_name 765 local uid = posix.stat(file, "uid")
766 if not uid then return nil end
767 return posix.getpwuid(uid).pw_name or nil
766 else 768 else
767 return "" 769 return nil
768 end 770 end
769end 771end
770 772
diff --git a/src/luarocks/fs/unix/tools.lua b/src/luarocks/fs/unix/tools.lua
index 21cc8a19..f72001cb 100644
--- a/src/luarocks/fs/unix/tools.lua
+++ b/src/luarocks/fs/unix/tools.lua
@@ -204,9 +204,12 @@ function tools.attributes(filename, attrtype)
204 local flag = ((attrtype == "permissions") and vars.STATPERMFLAG) 204 local flag = ((attrtype == "permissions") and vars.STATPERMFLAG)
205 or ((attrtype == "owner") and vars.STATOWNERFLAG) 205 or ((attrtype == "owner") and vars.STATOWNERFLAG)
206 if not flag then return "" end 206 if not flag then return "" end
207 local pipe = io.popen(vars.STAT.." "..flag.." "..fs.Q(filename)) 207 local pipe = io.popen(fs.quiet_stderr(vars.STAT.." "..flag.." "..fs.Q(filename)))
208 local ret = pipe:read("*l") 208 local ret = pipe:read("*l")
209 pipe:close() 209 pipe:close()
210 if ret == "" then
211 return nil
212 end
210 return ret 213 return ret
211end 214end
212 215
diff --git a/src/luarocks/fs/win32.lua b/src/luarocks/fs/win32.lua
index 406ee8ce..55d69f9f 100644
--- a/src/luarocks/fs/win32.lua
+++ b/src/luarocks/fs/win32.lua
@@ -197,7 +197,7 @@ function win32.attributes(filename, attrtype)
197 elseif attrtype == "owner" then 197 elseif attrtype == "owner" then
198 return os.getenv("USERNAME") -- FIXME popen_read('powershell -Command "& {(get-acl '..filename..').owner}"'):gsub("^[^\\]*\\", "") 198 return os.getenv("USERNAME") -- FIXME popen_read('powershell -Command "& {(get-acl '..filename..').owner}"'):gsub("^[^\\]*\\", "")
199 end 199 end
200 return "" 200 return nil
201end 201end
202 202
203--- Move a file on top of the other. 203--- Move a file on top of the other.