win32-security 0.3.1 → 0.3.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- checksums.yaml.gz.sig +0 -0
- data.tar.gz.sig +0 -0
- data/CHANGES +63 -57
- data/MANIFEST +11 -9
- data/README +53 -53
- data/Rakefile +58 -61
- data/certs/djberg96_pub.pem +21 -0
- data/lib/win32-security.rb +1 -0
- data/lib/win32/security.rb +91 -91
- data/lib/win32/security/ace.rb +75 -75
- data/lib/win32/security/acl.rb +224 -224
- data/lib/win32/security/sid.rb +394 -394
- data/lib/win32/security/windows/constants.rb +184 -184
- data/lib/win32/security/windows/functions.rb +116 -116
- data/lib/win32/security/windows/structs.rb +94 -94
- data/test/test_ace.rb +48 -48
- data/test/test_acl.rb +101 -101
- data/test/test_security.rb +23 -23
- data/test/test_sid.rb +142 -142
- data/win32-security.gemspec +28 -27
- metadata +48 -18
- metadata.gz.sig +0 -0
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 33ce1c2dc5905f666656e1e91ccccf4c68895071
|
4
|
+
data.tar.gz: 59d8f0ea5c8bed6db0ab4474ea6b8cf3bbdeaccf
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 9f1644cbd1d6bf1072e8d9bb3844b55d200cb21a13876ffcae54ef46acdfe6046ca1e1bc19de33ef2fa12830ea6ac49ad1ca50d0cf6f8310bd84b514da01d576
|
7
|
+
data.tar.gz: 1e2ee6736e1f24390985c03b176f49da020128dc60846bb7f4eed91ab87f7b7e0c97ccf29f1e704f8a7714c8c72cfd00eaff4ed4cdb20108537c97c731d1f8f5
|
checksums.yaml.gz.sig
ADDED
Binary file
|
data.tar.gz.sig
ADDED
Binary file
|
data/CHANGES
CHANGED
@@ -1,57 +1,63 @@
|
|
1
|
-
== 0.3.
|
2
|
-
*
|
3
|
-
|
4
|
-
|
5
|
-
*
|
6
|
-
|
7
|
-
|
8
|
-
*
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
*
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
*
|
43
|
-
|
44
|
-
|
45
|
-
= 0.1.
|
46
|
-
*
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
*
|
54
|
-
|
55
|
-
|
56
|
-
= 0.1.
|
57
|
-
*
|
1
|
+
== 0.3.2 - 4-Dec-2015
|
2
|
+
* This gem is now signed.
|
3
|
+
* Added a win32-security.rb file for convenience.
|
4
|
+
* The gem related tasks in the Rakefile now assume Rubygems 2.x.
|
5
|
+
* Fixed a function and struct prototype.
|
6
|
+
|
7
|
+
== 0.3.1 - 8-Dec-2014
|
8
|
+
* Work around a bug in 64-bit JRuby, which doesn't handle uintptr_t properly.
|
9
|
+
|
10
|
+
== 0.3.0 - 31-Oct-2014
|
11
|
+
* Implemented an ACL class that lets you create and inspect acccess
|
12
|
+
control lists.
|
13
|
+
* Implemented a basic ACE class that encapsulates an ACE object.
|
14
|
+
* Removed Windows XP support.
|
15
|
+
* Some minor updates to the Rakefile and gemspec.
|
16
|
+
|
17
|
+
== 0.2.5 - 24-Feb-2014
|
18
|
+
* Fixed a bug in the SID#string_to_sid method. Thanks go to Rob Reynolds
|
19
|
+
for the spot.
|
20
|
+
|
21
|
+
== 0.2.4 - 8-Nov-2013
|
22
|
+
* Added rake as a development dependency.
|
23
|
+
* Attempted to make FFI related constants and structs more private.
|
24
|
+
* Updated the gem:create task for Rubygems 2.
|
25
|
+
|
26
|
+
== 0.2.3 - 27-Jun-2013
|
27
|
+
* Fixed a bug where a sid could be inappropriately stripped. Thanks
|
28
|
+
go to Josh Cooper for the spot.
|
29
|
+
|
30
|
+
== 0.2.2 - 8-Apr-2013
|
31
|
+
* Fixed HANDLE prototypes in the underlying FFI code. This affected
|
32
|
+
64 bit versions of Ruby.
|
33
|
+
|
34
|
+
== 0.2.1 - 19-Feb-2013
|
35
|
+
* Removed a trailing comma that was causing problems.
|
36
|
+
|
37
|
+
== 0.2.0 - 11-Jan-2013
|
38
|
+
* Converted the code to FFI.
|
39
|
+
* Refactored some of the tests.
|
40
|
+
|
41
|
+
= 0.1.4 - 4-Oct-2012
|
42
|
+
* Updated the SID.string_to_sid method so that it completes a string/sid
|
43
|
+
round trip successfully now. Thanks go to Josh Cooper for the patch.
|
44
|
+
|
45
|
+
= 0.1.3 - 12-Jul-2012
|
46
|
+
* The SID.new method now defaults to the owner of the current thread if
|
47
|
+
no account name is provided.
|
48
|
+
* Updates to the gemspec, Rakefile, and SID tests, including updates to
|
49
|
+
some of the gemspec dependencies.
|
50
|
+
|
51
|
+
= 0.1.2 - 2-Aug-2009
|
52
|
+
* Now compatible with Ruby 1.9.x.
|
53
|
+
* Switched test-unit and sys-admin from standard dependencies to development
|
54
|
+
dependencies.
|
55
|
+
|
56
|
+
= 0.1.1 - 14-Jul-2009
|
57
|
+
* Added some well known SID's as constants to the Win32::Security::SID class
|
58
|
+
for convenience, e.g. SID::World, SID::Everyone.
|
59
|
+
* Fixes for the gemspec.
|
60
|
+
* Changed license to Artistic 2.0.
|
61
|
+
|
62
|
+
= 0.1.0 - 17-Dec-2008
|
63
|
+
* Initial release
|
data/MANIFEST
CHANGED
@@ -1,9 +1,11 @@
|
|
1
|
-
* CHANGES
|
2
|
-
* MANIFEST
|
3
|
-
* README
|
4
|
-
* Rakefile
|
5
|
-
* win32-security.gemspec
|
6
|
-
*
|
7
|
-
* lib/win32
|
8
|
-
*
|
9
|
-
*
|
1
|
+
* CHANGES
|
2
|
+
* MANIFEST
|
3
|
+
* README
|
4
|
+
* Rakefile
|
5
|
+
* win32-security.gemspec
|
6
|
+
* certs/djberg96_pub.pem
|
7
|
+
* lib/win32-security.rb
|
8
|
+
* lib/win32/security.rb
|
9
|
+
* lib/win32/security/sid.rb
|
10
|
+
* test/test_security.rb
|
11
|
+
* test/test_sid.rb
|
data/README
CHANGED
@@ -1,53 +1,53 @@
|
|
1
|
-
= Description
|
2
|
-
A security library for MS Windows that allows you to open existing or
|
3
|
-
create new security identifiers (SID's), as well as create access
|
4
|
-
control lists (ACL's) and access control entries (ACE's).
|
5
|
-
|
6
|
-
= Synopsis
|
7
|
-
require 'win32/security'
|
8
|
-
include Win32
|
9
|
-
|
10
|
-
sid = Security::SID.open('some_user')
|
11
|
-
|
12
|
-
sid.valid? # => true
|
13
|
-
sid.to_s # => "S-1-5-21-3733855671-1102023144-2002619019-1000"
|
14
|
-
sid.length # => 28
|
15
|
-
sid.sid # => "\001\005\000\000\000\000\000\005\025\000\000\000..."
|
16
|
-
|
17
|
-
acl = Security::ACL.new
|
18
|
-
mask = Security::ACL::GENERIC_READ | Security::ACL::GENERIC_WRITE
|
19
|
-
|
20
|
-
acl.add_access_allowed_ace('some_user', mask)
|
21
|
-
acl.add_access_denied_ace('some_user', Security::ACL::GENERIC_EXECUTE)
|
22
|
-
|
23
|
-
acl.acl_count # => 2
|
24
|
-
acl.valid? # => true
|
25
|
-
|
26
|
-
== Future Plans
|
27
|
-
None at the moment. Suggestions welcome.
|
28
|
-
|
29
|
-
== Known Issues
|
30
|
-
There appears to be an issue with 64-bit versions of JRuby. I believe this
|
31
|
-
is related to this issue: https://github.com/jruby/jruby/issues/1315. There
|
32
|
-
is nothing I can do about it here.
|
33
|
-
|
34
|
-
Please file any other bug reports on the project page at:
|
35
|
-
|
36
|
-
https://github.com/djberg96/win32-security
|
37
|
-
|
38
|
-
== Contributions
|
39
|
-
Although this library is free, please consider having your company
|
40
|
-
setup a gittip if used by your company professionally.
|
41
|
-
|
42
|
-
http://www.gittip.com/djberg96/
|
43
|
-
|
44
|
-
== License
|
45
|
-
Artistic 2.0
|
46
|
-
|
47
|
-
== Copyright
|
48
|
-
(C) 2003-
|
49
|
-
All Rights Reserved
|
50
|
-
|
51
|
-
== Authors
|
52
|
-
Daniel J. Berger
|
53
|
-
Park Heesob
|
1
|
+
= Description
|
2
|
+
A security library for MS Windows that allows you to open existing or
|
3
|
+
create new security identifiers (SID's), as well as create access
|
4
|
+
control lists (ACL's) and access control entries (ACE's).
|
5
|
+
|
6
|
+
= Synopsis
|
7
|
+
require 'win32/security'
|
8
|
+
include Win32
|
9
|
+
|
10
|
+
sid = Security::SID.open('some_user')
|
11
|
+
|
12
|
+
sid.valid? # => true
|
13
|
+
sid.to_s # => "S-1-5-21-3733855671-1102023144-2002619019-1000"
|
14
|
+
sid.length # => 28
|
15
|
+
sid.sid # => "\001\005\000\000\000\000\000\005\025\000\000\000..."
|
16
|
+
|
17
|
+
acl = Security::ACL.new
|
18
|
+
mask = Security::ACL::GENERIC_READ | Security::ACL::GENERIC_WRITE
|
19
|
+
|
20
|
+
acl.add_access_allowed_ace('some_user', mask)
|
21
|
+
acl.add_access_denied_ace('some_user', Security::ACL::GENERIC_EXECUTE)
|
22
|
+
|
23
|
+
acl.acl_count # => 2
|
24
|
+
acl.valid? # => true
|
25
|
+
|
26
|
+
== Future Plans
|
27
|
+
None at the moment. Suggestions welcome.
|
28
|
+
|
29
|
+
== Known Issues
|
30
|
+
There appears to be an issue with 64-bit versions of JRuby. I believe this
|
31
|
+
is related to this issue: https://github.com/jruby/jruby/issues/1315. There
|
32
|
+
is nothing I can do about it here.
|
33
|
+
|
34
|
+
Please file any other bug reports on the project page at:
|
35
|
+
|
36
|
+
https://github.com/djberg96/win32-security
|
37
|
+
|
38
|
+
== Contributions
|
39
|
+
Although this library is free, please consider having your company
|
40
|
+
setup a gittip if used by your company professionally.
|
41
|
+
|
42
|
+
http://www.gittip.com/djberg96/
|
43
|
+
|
44
|
+
== License
|
45
|
+
Artistic 2.0
|
46
|
+
|
47
|
+
== Copyright
|
48
|
+
(C) 2003-2015 Daniel J. Berger
|
49
|
+
All Rights Reserved
|
50
|
+
|
51
|
+
== Authors
|
52
|
+
Daniel J. Berger
|
53
|
+
Park Heesob
|
data/Rakefile
CHANGED
@@ -1,61 +1,58 @@
|
|
1
|
-
require 'rake'
|
2
|
-
require 'rake/clean'
|
3
|
-
require 'rake/testtask'
|
4
|
-
require 'rbconfig'
|
5
|
-
|
6
|
-
CLEAN.include('**/*.gem', '**/*.rbc')
|
7
|
-
|
8
|
-
namespace :gem do
|
9
|
-
desc "Create the win32-security gem"
|
10
|
-
task :create => [:clean] do
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
end
|
60
|
-
|
61
|
-
task :default => 'test:all'
|
1
|
+
require 'rake'
|
2
|
+
require 'rake/clean'
|
3
|
+
require 'rake/testtask'
|
4
|
+
require 'rbconfig'
|
5
|
+
|
6
|
+
CLEAN.include('**/*.gem', '**/*.rbc')
|
7
|
+
|
8
|
+
namespace :gem do
|
9
|
+
desc "Create the win32-security gem"
|
10
|
+
task :create => [:clean] do
|
11
|
+
require 'rubygems/package'
|
12
|
+
spec = eval(IO.read('win32-security.gemspec'))
|
13
|
+
spec.signing_key = File.join(Dir.home, '.ssh', 'gem-private_key.pem')
|
14
|
+
Gem::Package.build(spec, true)
|
15
|
+
end
|
16
|
+
|
17
|
+
desc "Install the win32-security gem"
|
18
|
+
task :install => [:create] do
|
19
|
+
ruby 'win32-security.gemspec'
|
20
|
+
file = Dir["*.gem"].first
|
21
|
+
sh "gem install -l #{file}"
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
namespace :test do
|
26
|
+
Rake::TestTask.new(:security) do |t|
|
27
|
+
t.verbose = true
|
28
|
+
t.warning = true
|
29
|
+
t.test_files = Dir['test/test_security.rb']
|
30
|
+
end
|
31
|
+
|
32
|
+
Rake::TestTask.new(:acl) do |t|
|
33
|
+
t.verbose = true
|
34
|
+
t.warning = true
|
35
|
+
t.test_files = Dir['test/test_acl.rb']
|
36
|
+
end
|
37
|
+
|
38
|
+
Rake::TestTask.new(:ace) do |t|
|
39
|
+
t.verbose = true
|
40
|
+
t.warning = true
|
41
|
+
t.test_files = Dir['test/test_ace.rb']
|
42
|
+
end
|
43
|
+
|
44
|
+
Rake::TestTask.new(:sid) do |t|
|
45
|
+
t.verbose = true
|
46
|
+
t.warning = true
|
47
|
+
t.test_files = Dir['test/test_sid.rb']
|
48
|
+
end
|
49
|
+
|
50
|
+
# ACL class isn't ready yet
|
51
|
+
Rake::TestTask.new(:all) do |t|
|
52
|
+
t.verbose = true
|
53
|
+
t.warning = true
|
54
|
+
t.test_files = Dir['test/test_sid.rb', 'test/test_security.rb']
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
58
|
+
task :default => 'test:all'
|
@@ -0,0 +1,21 @@
|
|
1
|
+
-----BEGIN CERTIFICATE-----
|
2
|
+
MIIDcDCCAligAwIBAgIBATANBgkqhkiG9w0BAQUFADA/MREwDwYDVQQDDAhkamJl
|
3
|
+
cmc5NjEVMBMGCgmSJomT8ixkARkWBWdtYWlsMRMwEQYKCZImiZPyLGQBGRYDY29t
|
4
|
+
MB4XDTE1MDkwMjIwNDkxOFoXDTE2MDkwMTIwNDkxOFowPzERMA8GA1UEAwwIZGpi
|
5
|
+
ZXJnOTYxFTATBgoJkiaJk/IsZAEZFgVnbWFpbDETMBEGCgmSJomT8ixkARkWA2Nv
|
6
|
+
bTCCASIwDQYJKoZIhvcNAQEBBQADggEPADCCAQoCggEBAMyTkvXqRp6hLs9eoJOS
|
7
|
+
Hmi8kRYbq9Vkf15/hMxJpotYMgJVHHWrmDcC5Dye2PbnXjTkKf266Zw0PtT9h+lI
|
8
|
+
S3ts9HO+vaCFSMwFFZmnWJSpQ3CNw2RcHxjWkk9yF7imEM8Kz9ojhiDXzBetdV6M
|
9
|
+
gr0lV/alUr7TNVBDngbXEfTWscyXh1qd7xZ4EcOdsDktCe5G45N/o3662tPQvJsi
|
10
|
+
FOF0CM/KuBsa/HL1/eoEmF4B3EKIRfTHrQ3hu20Kv3RJ88QM4ec2+0dd97uX693O
|
11
|
+
zv6981fyEg+aXLkxrkViM/tz2qR2ZE0jPhHTREPYeMEgptRkTmWSKAuLVWrJEfgl
|
12
|
+
DtkCAwEAAaN3MHUwCQYDVR0TBAIwADALBgNVHQ8EBAMCBLAwHQYDVR0OBBYEFEwe
|
13
|
+
nn6bfJADmuIDiMSOzedOrL+xMB0GA1UdEQQWMBSBEmRqYmVyZzk2QGdtYWlsLmNv
|
14
|
+
bTAdBgNVHRIEFjAUgRJkamJlcmc5NkBnbWFpbC5jb20wDQYJKoZIhvcNAQEFBQAD
|
15
|
+
ggEBAHmNOCWoDVD75zHFueY0viwGDVP1BNGFC+yXcb7u2GlK+nEMCORqzURbYPf7
|
16
|
+
tL+/hzmePIRz7i30UM//64GI1NLv9jl7nIwjhPpXpf7/lu2I9hOTsvwSumb5UiKC
|
17
|
+
/sqBxI3sfj9pr79Wpv4MuikX1XPik7Ncb7NPsJPw06Lvyc3Hkg5X2XpPtLtS+Gr2
|
18
|
+
wKJnmzb5rIPS1cmsqv0M9LPWflzfwoZ/SpnmhagP+g05p8bRNKjZSA2iImM/GyYZ
|
19
|
+
EJYzxdPOrx2n6NYR3Hk+vHP0U7UBSveI6+qx+ndQYaeyCn+GRX2PKS9h66YF/Q1V
|
20
|
+
tGSHgAmcLlkdGgan182qsE/4kKM=
|
21
|
+
-----END CERTIFICATE-----
|
@@ -0,0 +1 @@
|
|
1
|
+
require_relative 'win32/security'
|
data/lib/win32/security.rb
CHANGED
@@ -1,91 +1,91 @@
|
|
1
|
-
# This file allows users to require all security related classes from
|
2
|
-
# a single file, instead of having to require individual files.
|
3
|
-
|
4
|
-
require_relative 'security/windows/constants'
|
5
|
-
require_relative 'security/windows/structs'
|
6
|
-
require_relative 'security/windows/functions'
|
7
|
-
|
8
|
-
# The Win32 module serves as a namespace only.
|
9
|
-
module Win32
|
10
|
-
|
11
|
-
# The Security class encapsulates security aspects of MS Windows.
|
12
|
-
class Security
|
13
|
-
|
14
|
-
# Base error class for all Win32::Security errors.
|
15
|
-
class Error < StandardError; end
|
16
|
-
|
17
|
-
include Windows::Security::Functions
|
18
|
-
include Windows::Security::Constants
|
19
|
-
include Windows::Security::Structs
|
20
|
-
extend Windows::Security::Functions
|
21
|
-
|
22
|
-
# The version of the win32-security library
|
23
|
-
VERSION = '0.3.
|
24
|
-
|
25
|
-
# Used by OpenProcessToken
|
26
|
-
TOKEN_QUERY = 8
|
27
|
-
|
28
|
-
# Returns whether or not the owner of the current process is running
|
29
|
-
# with elevated security privileges.
|
30
|
-
#
|
31
|
-
def self.elevated_security?
|
32
|
-
result = false
|
33
|
-
|
34
|
-
# Work around a 64-bit JRuby bug
|
35
|
-
if RUBY_PLATFORM == 'java' && ENV_JAVA['sun.arch.data.model'] == '64'
|
36
|
-
ptr_type = :ulong_long
|
37
|
-
else
|
38
|
-
ptr_type = :uintptr_t
|
39
|
-
end
|
40
|
-
|
41
|
-
FFI::MemoryPointer.new(ptr_type) do |token|
|
42
|
-
unless OpenProcessToken(GetCurrentProcess(), TOKEN_QUERY, token)
|
43
|
-
raise SystemCallError.new("OpenProcessToken", FFI.errno)
|
44
|
-
end
|
45
|
-
|
46
|
-
begin
|
47
|
-
token = token.read_pointer.to_i
|
48
|
-
|
49
|
-
# Since the TokenElevation struct only has 1 member, we use a pointer.
|
50
|
-
te = FFI::MemoryPointer.new(:ulong)
|
51
|
-
rl = FFI::MemoryPointer.new(:ulong)
|
52
|
-
|
53
|
-
bool = GetTokenInformation(
|
54
|
-
token,
|
55
|
-
:TokenElevation,
|
56
|
-
te,
|
57
|
-
te.size,
|
58
|
-
rl
|
59
|
-
)
|
60
|
-
|
61
|
-
raise SystemCallError.new("GetTokenInformation", FFI.errno) unless bool
|
62
|
-
|
63
|
-
result = te.read_ulong != 0
|
64
|
-
ensure
|
65
|
-
CloseHandle(token)
|
66
|
-
te.free
|
67
|
-
rl.free
|
68
|
-
end
|
69
|
-
end
|
70
|
-
|
71
|
-
result
|
72
|
-
end
|
73
|
-
|
74
|
-
private
|
75
|
-
|
76
|
-
def self.windows_version
|
77
|
-
ver = OSVERSIONINFO.new
|
78
|
-
ver[:dwOSVersionInfoSize] = ver.size
|
79
|
-
|
80
|
-
unless GetVersionExA(ver)
|
81
|
-
raise SystemCallError.new("GetVersionEx", FFI.errno)
|
82
|
-
end
|
83
|
-
|
84
|
-
ver[:dwMajorVersion]
|
85
|
-
end
|
86
|
-
end
|
87
|
-
end
|
88
|
-
|
89
|
-
require 'win32/security/sid'
|
90
|
-
require 'win32/security/acl'
|
91
|
-
require 'win32/security/ace'
|
1
|
+
# This file allows users to require all security related classes from
|
2
|
+
# a single file, instead of having to require individual files.
|
3
|
+
|
4
|
+
require_relative 'security/windows/constants'
|
5
|
+
require_relative 'security/windows/structs'
|
6
|
+
require_relative 'security/windows/functions'
|
7
|
+
|
8
|
+
# The Win32 module serves as a namespace only.
|
9
|
+
module Win32
|
10
|
+
|
11
|
+
# The Security class encapsulates security aspects of MS Windows.
|
12
|
+
class Security
|
13
|
+
|
14
|
+
# Base error class for all Win32::Security errors.
|
15
|
+
class Error < StandardError; end
|
16
|
+
|
17
|
+
include Windows::Security::Functions
|
18
|
+
include Windows::Security::Constants
|
19
|
+
include Windows::Security::Structs
|
20
|
+
extend Windows::Security::Functions
|
21
|
+
|
22
|
+
# The version of the win32-security library
|
23
|
+
VERSION = '0.3.2'
|
24
|
+
|
25
|
+
# Used by OpenProcessToken
|
26
|
+
TOKEN_QUERY = 8
|
27
|
+
|
28
|
+
# Returns whether or not the owner of the current process is running
|
29
|
+
# with elevated security privileges.
|
30
|
+
#
|
31
|
+
def self.elevated_security?
|
32
|
+
result = false
|
33
|
+
|
34
|
+
# Work around a 64-bit JRuby bug
|
35
|
+
if RUBY_PLATFORM == 'java' && ENV_JAVA['sun.arch.data.model'] == '64'
|
36
|
+
ptr_type = :ulong_long
|
37
|
+
else
|
38
|
+
ptr_type = :uintptr_t
|
39
|
+
end
|
40
|
+
|
41
|
+
FFI::MemoryPointer.new(ptr_type) do |token|
|
42
|
+
unless OpenProcessToken(GetCurrentProcess(), TOKEN_QUERY, token)
|
43
|
+
raise SystemCallError.new("OpenProcessToken", FFI.errno)
|
44
|
+
end
|
45
|
+
|
46
|
+
begin
|
47
|
+
token = token.read_pointer.to_i
|
48
|
+
|
49
|
+
# Since the TokenElevation struct only has 1 member, we use a pointer.
|
50
|
+
te = FFI::MemoryPointer.new(:ulong)
|
51
|
+
rl = FFI::MemoryPointer.new(:ulong)
|
52
|
+
|
53
|
+
bool = GetTokenInformation(
|
54
|
+
token,
|
55
|
+
:TokenElevation,
|
56
|
+
te,
|
57
|
+
te.size,
|
58
|
+
rl
|
59
|
+
)
|
60
|
+
|
61
|
+
raise SystemCallError.new("GetTokenInformation", FFI.errno) unless bool
|
62
|
+
|
63
|
+
result = te.read_ulong != 0
|
64
|
+
ensure
|
65
|
+
CloseHandle(token)
|
66
|
+
te.free
|
67
|
+
rl.free
|
68
|
+
end
|
69
|
+
end
|
70
|
+
|
71
|
+
result
|
72
|
+
end
|
73
|
+
|
74
|
+
private
|
75
|
+
|
76
|
+
def self.windows_version
|
77
|
+
ver = OSVERSIONINFO.new
|
78
|
+
ver[:dwOSVersionInfoSize] = ver.size
|
79
|
+
|
80
|
+
unless GetVersionExA(ver)
|
81
|
+
raise SystemCallError.new("GetVersionEx", FFI.errno)
|
82
|
+
end
|
83
|
+
|
84
|
+
ver[:dwMajorVersion]
|
85
|
+
end
|
86
|
+
end
|
87
|
+
end
|
88
|
+
|
89
|
+
require 'win32/security/sid'
|
90
|
+
require 'win32/security/acl'
|
91
|
+
require 'win32/security/ace'
|