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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: d234ea5f580422f9afe3ca568dca698212b4c31c
4
- data.tar.gz: a3bee9399b1407bc23609a44315194cb361ef9c3
3
+ metadata.gz: 6c24eb63a2d55e6fcf4ee4b4c4769f76f48be445
4
+ data.tar.gz: ab52ba7a0c646b38879a515e15f2df5689f084cb
5
5
  SHA512:
6
- metadata.gz: 3e119edd6768169b2b37995be0656b59d3dbf304eedc2ba7f1ddffa4d3f130d3519e6cbf1cbe6e918813a04cf0049820630c3c71c23093603f5f2be19b7308ec
7
- data.tar.gz: f3e9124fdd6acaea83dfd678ad150ea057695e2e600cfa443047776efa4877ae0b59c3c40975be6404dd0e59eb72e5f96696230f99d020754a2c78ec3e8b18f7
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
@@ -35,7 +35,7 @@
35
35
  Artistic 2.0
36
36
 
37
37
  == Copyright
38
- (C) 2003-2014, Daniel J. Berger, All Rights Reserved
38
+ (C) 2003-2015, Daniel J. Berger, All Rights Reserved
39
39
 
40
40
  == Warranty
41
41
  This package is provided "as is" and without any express or
@@ -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.5'
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
- unless domain.empty?
320
- name = domain + '\\' + name
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
- # Convenience method for converting strings to UTF-16LE for wide character
3
- # functions that require it.
4
- def wincode
5
- (self.tr(File::SEPARATOR, File::ALT_SEPARATOR) + 0.chr).encode('UTF-16LE')
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
- # Read a wide character string up until the first double null, and delete
9
- # any remaining null characters.
10
- def wstrip
11
- self.force_encoding('UTF-16LE').encode('UTF-8',:invalid=>:replace,:undef=>:replace).split("\x00")[0].encode(Encoding.default_external)
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.5', File::WIN32_FILE_SECURITY_VERSION)
11
+ assert_equal('1.0.6', File::WIN32_FILE_SECURITY_VERSION)
12
12
  end
13
13
  end
@@ -2,7 +2,7 @@ require 'rubygems'
2
2
 
3
3
  Gem::Specification.new do |spec|
4
4
  spec.name = 'win32-file-security'
5
- spec.version = '1.0.5'
5
+ spec.version = '1.0.6'
6
6
  spec.authors = ['Daniel J. Berger', 'Park Heesob']
7
7
  spec.license = 'Artistic 2.0'
8
8
  spec.email = 'djberg96@gmail.com'
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.5
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-25 00:00:00.000000000 Z
12
+ date: 2015-05-28 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: ffi