diff options
| author | George Roman <george.roman.99@gmail.com> | 2018-07-07 16:23:07 +0300 |
|---|---|---|
| committer | Hisham Muhammad <hisham@gobolinux.org> | 2018-07-16 20:34:30 -0300 |
| commit | 1b3b6525a4313404af84fce0fbbc29695e664f73 (patch) | |
| tree | 76ad679d512e216ace739662ac60d1785d43af2c /src | |
| parent | f2772aee0d4ee5012d9b1be65f685b535d7380bd (diff) | |
| download | luarocks-1b3b6525a4313404af84fce0fbbc29695e664f73.tar.gz luarocks-1b3b6525a4313404af84fce0fbbc29695e664f73.tar.bz2 luarocks-1b3b6525a4313404af84fce0fbbc29695e664f73.zip | |
Update the behavior of fs.set_permissions on Windows
Diffstat (limited to 'src')
| -rw-r--r-- | src/luarocks/fs/win32/tools.lua | 57 |
1 files changed, 41 insertions, 16 deletions
diff --git a/src/luarocks/fs/win32/tools.lua b/src/luarocks/fs/win32/tools.lua index c03b0d7b..c267b316 100644 --- a/src/luarocks/fs/win32/tools.lua +++ b/src/luarocks/fs/win32/tools.lua | |||
| @@ -182,33 +182,58 @@ end | |||
| 182 | function tools.set_permissions(filename, mode, scope) | 182 | function tools.set_permissions(filename, mode, scope) |
| 183 | assert(filename and mode and scope) | 183 | assert(filename and mode and scope) |
| 184 | 184 | ||
| 185 | local who, what | ||
| 186 | if scope == "user" then | 185 | if scope == "user" then |
| 187 | who = os.getenv("USERNAME") | 186 | local perms |
| 188 | elseif scope == "all" then | 187 | if mode == "read" then |
| 189 | who = "Everyone" | 188 | perms = "(R,W,M)" |
| 190 | end | 189 | elseif mode == "exec" then |
| 191 | if mode == "read" then | 190 | perms = "(F)" |
| 192 | what = "(RD)" | 191 | end |
| 193 | elseif mode == "exec" then | ||
| 194 | what = "(X)" | ||
| 195 | end | ||
| 196 | if not who or not what then | ||
| 197 | return false, "Invalid permission " .. mode .. " for " .. scope | ||
| 198 | end | ||
| 199 | 192 | ||
| 200 | if scope == "user" then | 193 | local ok |
| 194 | -- Take ownership of the given file | ||
| 195 | ok = fs.execute_quiet("takeown /f " .. fs.Q(filename)) | ||
| 196 | if not ok then | ||
| 197 | return false, "Could not take ownership of the given file" | ||
| 198 | end | ||
| 199 | -- Grant the current user the proper rights | ||
| 200 | ok = fs.execute_quiet(fs.Q(vars.ICACLS) .. " " .. fs.Q(filename) .. " /inheritance:d /grant:r %USERNAME%:" .. perms) | ||
| 201 | if not ok then | ||
| 202 | return false, "Failed setting permission " .. mode .. " for " .. scope | ||
| 203 | end | ||
| 204 | -- Finally, remove all the other users from the ACL in order to deny them access to the file | ||
| 201 | for _, user in pairs(get_system_users()) do | 205 | for _, user in pairs(get_system_users()) do |
| 202 | if user ~= who then | 206 | if user ~= who then |
| 203 | local ok = fs.execute(fs.Q(vars.ICACLS) .. " " .. fs.Q(filename) .. " /deny " .. fs.Q(user) .. ":" .. fs.Q(what)) | 207 | local ok = fs.execute_quiet(fs.Q(vars.ICACLS) .. " " .. fs.Q(filename) .. " /remove " .. fs.Q(user)) |
| 204 | if not ok then | 208 | if not ok then |
| 205 | return false, "Failed setting permission " .. mode .. " for " .. scope | 209 | return false, "Failed setting permission " .. mode .. " for " .. scope |
| 206 | end | 210 | end |
| 207 | end | 211 | end |
| 208 | end | 212 | end |
| 213 | elseif scope == "all" then | ||
| 214 | local my_perms, others_perms | ||
| 215 | if mode == "read" then | ||
| 216 | my_perms = "(R,W,M)" | ||
| 217 | others_perms = "(R)" | ||
| 218 | elseif mode == "exec" then | ||
| 219 | my_perms = "(F)" | ||
| 220 | others_perms = "(RX)" | ||
| 221 | end | ||
| 222 | |||
| 223 | local ok | ||
| 224 | -- Grant permissions available to all users | ||
| 225 | ok = fs.execute_quiet(fs.Q(vars.ICACLS) .. " " .. fs.Q(filename) .. " /inheritance:d /grant:r Everyone:" .. others_perms) | ||
| 226 | if not ok then | ||
| 227 | return false, "Failed setting permission " .. mode .. " for " .. scope | ||
| 228 | end | ||
| 229 | -- Grant permissions available only to the current user | ||
| 230 | ok = fs.execute_quiet(fs.Q(vars.ICACLS) .. " " .. fs.Q(filename) .. " /inheritance:d /grant %USERNAME%:" .. my_perms) | ||
| 231 | if not ok then | ||
| 232 | return false, "Failed setting permission " .. mode .. " for " .. scope | ||
| 233 | end | ||
| 209 | end | 234 | end |
| 210 | 235 | ||
| 211 | return fs.execute(fs.Q(vars.ICACLS) .. " " .. fs.Q(filename) .. " /grant " .. fs.Q(who) .. ":" .. fs.Q(what)) | 236 | return true |
| 212 | end | 237 | end |
| 213 | 238 | ||
| 214 | 239 | ||
