win32-file-security 1.0.5 → 1.0.6
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGES +7 -0
- data/README +1 -1
- data/lib/win32/file/security.rb +10 -4
- data/lib/win32/file/security/helper.rb +18 -8
- data/test/test_win32_file_security_ownership.rb +19 -2
- data/test/test_win32_file_security_version.rb +1 -1
- data/win32-file-security.gemspec +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 6c24eb63a2d55e6fcf4ee4b4c4769f76f48be445
|
4
|
+
data.tar.gz: ab52ba7a0c646b38879a515e15f2df5689f084cb
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 7c8dc91168b6eb32ced302c3c3f4336aabdeb40819187fb233db82e64b5aeb95f769feebf6127a6a0f1c48aad32719ba8cd7026b41c6b72c3de1252aea5a682b
|
7
|
+
data.tar.gz: ea1905dce18c874e5dce984265c90d0ad8cf51df042af8b4af54a34811c331122f58abf0d695e999ec2d87bbb7612b26f8737a2868abd2d2bac53413861a50d2
|
data/CHANGES
CHANGED
@@ -1,3 +1,10 @@
|
|
1
|
+
= 1.0.6 - 28-May-2015
|
2
|
+
* Handle the possibility of an empty/nil domain. Thanks go to n-nishizawa
|
3
|
+
for the spot.
|
4
|
+
* Helper methods are only defined if not already defined.
|
5
|
+
* Tests that were failing when run as admins in non-domain environments have
|
6
|
+
been modified to check for a domain first.
|
7
|
+
|
1
8
|
= 1.0.5 - 2-May-2015
|
2
9
|
* Added the File.supports_acls? singleton method.
|
3
10
|
* The File.get_permissions and File.set_permissions methods now explicitly
|
data/README
CHANGED
data/lib/win32/file/security.rb
CHANGED
@@ -12,7 +12,7 @@ class File
|
|
12
12
|
extend Windows::File::Functions
|
13
13
|
|
14
14
|
# The version of the win32-file library
|
15
|
-
WIN32_FILE_SECURITY_VERSION = '1.0.
|
15
|
+
WIN32_FILE_SECURITY_VERSION = '1.0.6'
|
16
16
|
|
17
17
|
class << self
|
18
18
|
remove_method(:chown)
|
@@ -314,10 +314,16 @@ class File
|
|
314
314
|
|
315
315
|
# The x2 multiplier is necessary due to wide char strings.
|
316
316
|
name = name.read_string(name_size.read_ulong * 2).wstrip
|
317
|
-
domain = domain.read_string(domain_size.read_ulong * 2).wstrip
|
318
317
|
|
319
|
-
|
320
|
-
|
318
|
+
dsize = domain_size.read_ulong
|
319
|
+
|
320
|
+
# It's possible there is no domain.
|
321
|
+
if dsize > 0
|
322
|
+
domain = domain.read_string(dsize * 2).wstrip
|
323
|
+
|
324
|
+
unless domain.empty?
|
325
|
+
name = domain + '\\' + name
|
326
|
+
end
|
321
327
|
end
|
322
328
|
|
323
329
|
perms_hash[name] = access[:Mask]
|
@@ -1,13 +1,23 @@
|
|
1
1
|
class String
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
2
|
+
unless instance_methods.include?(:wincode)
|
3
|
+
# Convenience method for converting strings to UTF-16LE for wide character
|
4
|
+
# functions that require it.
|
5
|
+
def wincode
|
6
|
+
unless encoding == Encoding::UTF_16LE
|
7
|
+
(self.tr(File::SEPARATOR, File::ALT_SEPARATOR) + 0.chr).encode('UTF-16LE')
|
8
|
+
end
|
9
|
+
end
|
6
10
|
end
|
7
11
|
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
+
unless instance_methods.include?(:wstrip)
|
13
|
+
# Read a wide character string up until the first double null, and delete
|
14
|
+
# any remaining null characters.
|
15
|
+
def wstrip
|
16
|
+
unless encoding == Encoding::UTF_16LE
|
17
|
+
self.force_encoding('UTF-16LE')
|
18
|
+
end
|
19
|
+
|
20
|
+
self.encode('UTF-8',:invalid=>:replace,:undef=>:replace).split("\x00")[0].encode(Encoding.default_external)
|
21
|
+
end
|
12
22
|
end
|
13
23
|
end
|
@@ -12,6 +12,21 @@ require 'win32/file/security'
|
|
12
12
|
require 'pathname'
|
13
13
|
|
14
14
|
class TC_Win32_File_Security_Ownership < Test::Unit::TestCase
|
15
|
+
extend FFI::Library
|
16
|
+
ffi_lib :netapi32
|
17
|
+
attach_function :NetGetDCName, [:pointer, :pointer, :buffer_out], :int
|
18
|
+
attach_function :NetApiBufferFree, [:pointer], :int
|
19
|
+
|
20
|
+
# Helper method to determine if we're on a domain controller
|
21
|
+
def self.in_domain?
|
22
|
+
bool = true
|
23
|
+
buf = (0.chr * 256).encode('UTF-16LE')
|
24
|
+
rv = NetGetDCName(nil, nil, buf)
|
25
|
+
bool = false if rv != 0
|
26
|
+
NetApiBufferFree(buf)
|
27
|
+
bool
|
28
|
+
end
|
29
|
+
|
15
30
|
def self.startup
|
16
31
|
Dir.chdir(File.dirname(File.expand_path(File.basename(__FILE__))))
|
17
32
|
@@file = File.join(Dir.pwd, 'ownership_test.txt')
|
@@ -19,6 +34,7 @@ class TC_Win32_File_Security_Ownership < Test::Unit::TestCase
|
|
19
34
|
@@host = Socket.gethostname
|
20
35
|
@@temp = "Temp"
|
21
36
|
@@login = Etc.getlogin
|
37
|
+
@@domain = in_domain?
|
22
38
|
|
23
39
|
if Win32::Security.elevated_security?
|
24
40
|
Sys::Admin.add_user(:name => @@temp, :description => "Delete Me")
|
@@ -81,7 +97,7 @@ class TC_Win32_File_Security_Ownership < Test::Unit::TestCase
|
|
81
97
|
end
|
82
98
|
|
83
99
|
test "grpowned? method returns expected result" do
|
84
|
-
if Win32::Security.elevated_security?
|
100
|
+
if Win32::Security.elevated_security? && @@domain
|
85
101
|
assert_false(File.grpowned?(@@file))
|
86
102
|
else
|
87
103
|
assert_true(File.grpowned?(@@file))
|
@@ -101,7 +117,7 @@ class TC_Win32_File_Security_Ownership < Test::Unit::TestCase
|
|
101
117
|
end
|
102
118
|
|
103
119
|
test "group method returns the expected value" do
|
104
|
-
if Win32::Security.elevated_security?
|
120
|
+
if Win32::Security.elevated_security? && @@domain
|
105
121
|
expected = "BUILTIN\\Administrators"
|
106
122
|
else
|
107
123
|
expected = @@host + "\\None"
|
@@ -153,5 +169,6 @@ class TC_Win32_File_Security_Ownership < Test::Unit::TestCase
|
|
153
169
|
@@file = nil
|
154
170
|
@@login = nil
|
155
171
|
@@host = nil
|
172
|
+
@@domain = nil
|
156
173
|
end
|
157
174
|
end
|
@@ -8,6 +8,6 @@ require 'win32/file/security'
|
|
8
8
|
|
9
9
|
class TC_Win32_File_Security_Version < Test::Unit::TestCase
|
10
10
|
test "version is set to expected value" do
|
11
|
-
assert_equal('1.0.
|
11
|
+
assert_equal('1.0.6', File::WIN32_FILE_SECURITY_VERSION)
|
12
12
|
end
|
13
13
|
end
|
data/win32-file-security.gemspec
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: win32-file-security
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.
|
4
|
+
version: 1.0.6
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Daniel J. Berger
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2015-05-
|
12
|
+
date: 2015-05-28 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: ffi
|