aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorHisham <hisham@gobolinux.org>2017-01-06 17:30:38 -0200
committerHisham <hisham@gobolinux.org>2017-01-06 17:30:38 -0200
commite6b161fabc5a3122bc11162e3f42df2c802f3673 (patch)
treec0fad2f5af143b85e5d9c2433b4b9439094f5715 /src
parent3df4bd569e44a7e4a6a0d5d3b758c767d9b562c4 (diff)
downloadluarocks-e6b161fabc5a3122bc11162e3f42df2c802f3673.tar.gz
luarocks-e6b161fabc5a3122bc11162e3f42df2c802f3673.tar.bz2
luarocks-e6b161fabc5a3122bc11162e3f42df2c802f3673.zip
Check ownership of cache directory and emit a warning.
This prevents `sudo luarocks` to take over ownership of the user's ~/.cache/luarocks directory.
Diffstat (limited to 'src')
-rw-r--r--src/luarocks/command_line.lua12
-rw-r--r--src/luarocks/core/cfg.lua6
-rw-r--r--src/luarocks/fs/lua.lua16
-rw-r--r--src/luarocks/fs/unix.lua4
-rw-r--r--src/luarocks/fs/unix/tools.lua7
-rw-r--r--src/luarocks/fs/win32.lua11
6 files changed, 47 insertions, 9 deletions
diff --git a/src/luarocks/command_line.lua b/src/luarocks/command_line.lua
index 96891b75..3f17b18a 100644
--- a/src/luarocks/command_line.lua
+++ b/src/luarocks/command_line.lua
@@ -178,9 +178,19 @@ function command_line.run_command(...)
178 end 178 end
179 end 179 end
180 180
181 if not fs.current_dir() or fs.current_dir() == "" then 181 if (not fs.current_dir()) or fs.current_dir() == "" then
182 die("Current directory does not exist. Please run LuaRocks from an existing directory.") 182 die("Current directory does not exist. Please run LuaRocks from an existing directory.")
183 end 183 end
184
185 if fs.attributes(cfg.local_cache, "owner") ~= fs.current_user() or
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 "..
188 "is not owned by the current user and the cache has been disabled. "..
189 "Please check the permissions and owner of that directory. "..
190 "If executing pip with sudo, you may want sudo's -H flag.")
191 cfg.local_cache = fs.make_temp_dir("local_cache")
192 util.schedule_function(fs.delete, cfg.local_cache)
193 end
184 194
185 if commands[command] then 195 if commands[command] then
186 local cmd = require(commands[command]) 196 local cmd = require(commands[command])
diff --git a/src/luarocks/core/cfg.lua b/src/luarocks/core/cfg.lua
index de8b9281..250f503e 100644
--- a/src/luarocks/core/cfg.lua
+++ b/src/luarocks/core/cfg.lua
@@ -411,7 +411,8 @@ local defaults = {
411 SEVENZ = "7z", 411 SEVENZ = "7z",
412 412
413 RSYNCFLAGS = "--exclude=.git -Oavz", 413 RSYNCFLAGS = "--exclude=.git -Oavz",
414 STATFLAG = "-c '%a'", 414 STATPERMFLAG = "-c '%a'",
415 STATOWNERFLAG = "-c '%U'",
415 CURLNOCERTFLAG = "", 416 CURLNOCERTFLAG = "",
416 WGETNOCERTFLAG = "", 417 WGETNOCERTFLAG = "",
417 }, 418 },
@@ -586,7 +587,8 @@ end
586 587
587if cfg.platforms.bsd then 588if cfg.platforms.bsd then
588 defaults.variables.MAKE = "gmake" 589 defaults.variables.MAKE = "gmake"
589 defaults.variables.STATFLAG = "-f '%OLp'" 590 defaults.variables.STATPERMFLAG = "-f '%OLp'"
591 defaults.variables.STATOWNERFLAG = "-f '%Su'"
590end 592end
591 593
592if cfg.platforms.macosx then 594if cfg.platforms.macosx then
diff --git a/src/luarocks/fs/lua.lua b/src/luarocks/fs/lua.lua
index 84037b0a..a14303e1 100644
--- a/src/luarocks/fs/lua.lua
+++ b/src/luarocks/fs/lua.lua
@@ -293,7 +293,7 @@ function fs_lua.copy(src, dest, perms)
293 if destmode == "directory" then 293 if destmode == "directory" then
294 dest = dir.path(dest, dir.base_name(src)) 294 dest = dir.path(dest, dir.base_name(src))
295 end 295 end
296 if not perms then perms = fs.get_permissions(src) end 296 if not perms then perms = fs.attributes(src, "permissions") end
297 local src_h, err = io.open(src, "rb") 297 local src_h, err = io.open(src, "rb")
298 if not src_h then return nil, err end 298 if not src_h then return nil, err end
299 local dest_h, err = io.open(dest, "w+b") 299 local dest_h, err = io.open(dest, "w+b")
@@ -758,8 +758,18 @@ function fs_lua.chmod(file, mode)
758 return err == 0 758 return err == 0
759end 759end
760 760
761function fs_lua.get_permissions(file) 761function fs_lua.attributes(file, attrtype)
762 return posix.stat(file, "mode") 762 if attrtype == "permissions" then
763 return posix.stat(file, "mode")
764 elseif attrtype == "owner" then
765 return posix.getpwuid(posix.stat(file, "uid")).pw_name
766 else
767 return ""
768 end
769end
770
771function fs_lua.current_user()
772 return posix.getpwuid(posix.geteuid()).pw_name
763end 773end
764 774
765--- Create a temporary directory. 775--- Create a temporary directory.
diff --git a/src/luarocks/fs/unix.lua b/src/luarocks/fs/unix.lua
index aca64ac0..89e3ec73 100644
--- a/src/luarocks/fs/unix.lua
+++ b/src/luarocks/fs/unix.lua
@@ -132,4 +132,8 @@ function unix.tmpname()
132 return os.tmpname() 132 return os.tmpname()
133end 133end
134 134
135function unix.current_user()
136 return os.getenv("USER")
137end
138
135return unix 139return unix
diff --git a/src/luarocks/fs/unix/tools.lua b/src/luarocks/fs/unix/tools.lua
index d9dc009f..e1b28b19 100644
--- a/src/luarocks/fs/unix/tools.lua
+++ b/src/luarocks/fs/unix/tools.lua
@@ -200,8 +200,11 @@ function tools.unpack_archive(archive)
200 return true 200 return true
201end 201end
202 202
203function tools.get_permissions(filename) 203function tools.attributes(filename, attrtype)
204 local pipe = io.popen(vars.STAT.." "..vars.STATFLAG.." "..fs.Q(filename)) 204 local flag = ((attrtype == "permissions") and vars.STATPERMFLAG)
205 or ((attrtype == "owner") and vars.STATOWNERFLAG)
206 if not flag then return "" end
207 local pipe = io.popen(vars.STAT.." "..flag.." "..fs.Q(filename))
205 local ret = pipe:read("*l") 208 local ret = pipe:read("*l")
206 pipe:close() 209 pipe:close()
207 return ret 210 return ret
diff --git a/src/luarocks/fs/win32.lua b/src/luarocks/fs/win32.lua
index 789913a7..e2b37778 100644
--- a/src/luarocks/fs/win32.lua
+++ b/src/luarocks/fs/win32.lua
@@ -191,7 +191,12 @@ function win32.chmod(filename, mode)
191 return true 191 return true
192end 192end
193 193
194function win32.get_permissions(filename) 194function win32.attributes(filename, attrtype)
195 if attrtype == "permissions" then
196 return "" -- FIXME
197 elseif attrtype == "owner" then
198 return os.getenv("USERNAME") -- FIXME popen_read('powershell -Command "& {(get-acl '..filename..').owner}"'):gsub("^[^\\]*\\", "")
199 end
195 return "" 200 return ""
196end 201end
197 202
@@ -263,4 +268,8 @@ function win32.tmpname()
263 return os.getenv("TMP")..os.tmpname() 268 return os.getenv("TMP")..os.tmpname()
264end 269end
265 270
271function win32.current_user()
272 return os.getenv("USERNAME")
273end
274
266return win32 275return win32