win32-security 0.1.1 → 0.1.2
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGES +5 -0
- data/README +1 -1
- data/lib/win32/security.rb +1 -1
- data/lib/win32/security/ace.rb +39 -0
- data/lib/win32/security/acl.rb +148 -0
- data/lib/win32/security/sid.rb +10 -4
- data/test/test_security.rb +1 -1
- data/test/test_sid.rb +1 -1
- data/win32-security.gemspec +4 -4
- metadata +7 -5
data/CHANGES
CHANGED
@@ -1,3 +1,8 @@
|
|
1
|
+
= 0.1.2 - 2-Aug-2009
|
2
|
+
* Now compatible with Ruby 1.9.x.
|
3
|
+
* Switched test-unit and sys-admin from standard dependencies to development
|
4
|
+
dependencies.
|
5
|
+
|
1
6
|
= 0.1.1 - 14-Jul-2009
|
2
7
|
* Added some well known SID's as constants to the Win32::Security::SID class
|
3
8
|
for convenience, e.g. SID::World, SID::Everyone.
|
data/README
CHANGED
data/lib/win32/security.rb
CHANGED
@@ -0,0 +1,39 @@
|
|
1
|
+
# The Win32 module serves as a namespace only.
|
2
|
+
module Win32
|
3
|
+
|
4
|
+
# The Security class serves as a toplevel class namespace.
|
5
|
+
class Security
|
6
|
+
|
7
|
+
# The ACE class encapsulates an Access Control Entry, an element within
|
8
|
+
# an Access Control List.
|
9
|
+
class ACE
|
10
|
+
# The version of the Win32::Security::ACE class.
|
11
|
+
VERSION = '0.1.0'
|
12
|
+
|
13
|
+
# The ACE type, e.g. ACCESS_ALLOWED, ACCESS_DENIED, etc.
|
14
|
+
attr_accessor :ace_type
|
15
|
+
|
16
|
+
# The ACE mask, e.g. INHERITED_ACE
|
17
|
+
attr_accessor :ace_mask
|
18
|
+
|
19
|
+
# Standard access rights, e.g. GENERIC_READ, GENERIC_WRITE, etc
|
20
|
+
attr_accessor :access_mask
|
21
|
+
|
22
|
+
# Bit flags that indicate whether the ObjectType and
|
23
|
+
# InheritedObjectType members are present. This value is set
|
24
|
+
# internally based on the values passed to the ACE#object_type or
|
25
|
+
# ACE#inherited_object_type methods, if any.
|
26
|
+
attr_reader :flags
|
27
|
+
|
28
|
+
# A Win32::Security::GUID object that identifies the type of child
|
29
|
+
# object that can inherit the ACE.
|
30
|
+
attr_accessor :object_type
|
31
|
+
|
32
|
+
attr_accessor :inherited_object_type
|
33
|
+
|
34
|
+
def initialize
|
35
|
+
yield self if block_given?
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
@@ -0,0 +1,148 @@
|
|
1
|
+
require 'windows/security'
|
2
|
+
require 'windows/error'
|
3
|
+
require 'windows/limits'
|
4
|
+
require 'windows/msvcrt/buffer'
|
5
|
+
|
6
|
+
# The Win32 module serves as a namespace only.
|
7
|
+
module Win32
|
8
|
+
|
9
|
+
# The Security class serves as a toplevel class namespace.
|
10
|
+
class Security
|
11
|
+
|
12
|
+
# The ACL class encapsulates an Access Control List.
|
13
|
+
class ACL
|
14
|
+
include Windows::Error
|
15
|
+
include Windows::Security
|
16
|
+
include Windows::Limits
|
17
|
+
include Windows::MSVCRT::Buffer
|
18
|
+
|
19
|
+
# The version of the Win32::Security::ACL class.
|
20
|
+
VERSION = '0.1.0'
|
21
|
+
|
22
|
+
# The binary representation of the ACL structure
|
23
|
+
attr_reader :acl
|
24
|
+
|
25
|
+
# The revision level.
|
26
|
+
attr_reader :revision
|
27
|
+
|
28
|
+
# Creates and returns a new Win32::Security::ACL object. This object
|
29
|
+
# encapsulates an ACL structure, including a binary representation of
|
30
|
+
# the ACL itself, and the revision information.
|
31
|
+
#
|
32
|
+
def initialize(revision = ACL_REVISION)
|
33
|
+
acl = 0.chr * 8 # This can be increased later as needed
|
34
|
+
|
35
|
+
unless InitializeAcl(acl, acl.size, revision)
|
36
|
+
raise Error, get_last_error
|
37
|
+
end
|
38
|
+
|
39
|
+
@acl = acl
|
40
|
+
@revision = revision
|
41
|
+
end
|
42
|
+
|
43
|
+
# Returns the number of ACE's in the ACL object.
|
44
|
+
#
|
45
|
+
def ace_count
|
46
|
+
buf = 0.chr * 12 # sizeof(ACL_SIZE_INFORMATION)
|
47
|
+
|
48
|
+
unless GetAclInformation(@acl, buf, buf.size, AclSizeInformation)
|
49
|
+
raise Error, get_last_error
|
50
|
+
end
|
51
|
+
|
52
|
+
buf[0, 4].unpack('L')[0]
|
53
|
+
end
|
54
|
+
|
55
|
+
# Adds an access allowed ACE to the given +sid+. The +mask+ is a
|
56
|
+
# bitwise OR'd value of access rights.
|
57
|
+
#
|
58
|
+
def add_access_allowed_ace(sid, mask=0)
|
59
|
+
unless AddAccessAllowedAce(@acl, @revision, mask, sid)
|
60
|
+
raise Error, get_last_error
|
61
|
+
end
|
62
|
+
end
|
63
|
+
|
64
|
+
# Adds an access denied ACE to the given +sid+.
|
65
|
+
#
|
66
|
+
def add_access_denied_ace(sid, mask=0)
|
67
|
+
unless AddAccessDeniedAce(@acl, @revision, mask, sid)
|
68
|
+
raise Error, get_last_error
|
69
|
+
end
|
70
|
+
end
|
71
|
+
|
72
|
+
# Adds an ACE to the ACL object with the given +revision+ at +index+
|
73
|
+
# or the end of the chain if no index is specified.
|
74
|
+
#
|
75
|
+
# Returns the index if successful.
|
76
|
+
#--
|
77
|
+
# This is untested and will require an actual implementation of
|
78
|
+
# Win32::Security::Ace before it can work properly.
|
79
|
+
#
|
80
|
+
def add_ace(ace, index=MAXDWORD)
|
81
|
+
unless AddAce(@acl, @revision, index, ace, ace.length)
|
82
|
+
raise Error, get_last_error
|
83
|
+
end
|
84
|
+
|
85
|
+
index
|
86
|
+
end
|
87
|
+
|
88
|
+
# Deletes an ACE from the ACL object at +index+, or from the end of
|
89
|
+
# the chain if no index is specified.
|
90
|
+
#
|
91
|
+
# Returns the index if successful.
|
92
|
+
#--
|
93
|
+
# This is untested and will require an actual implementation of
|
94
|
+
# Win32::Security::Ace before it can work properly.
|
95
|
+
#
|
96
|
+
def delete_ace(index=MAXDWORD)
|
97
|
+
unless DeleteAce(@ace, index)
|
98
|
+
raise Error, get_last_error
|
99
|
+
end
|
100
|
+
|
101
|
+
index
|
102
|
+
end
|
103
|
+
|
104
|
+
# Finds and returns a pointer (address) to an ACE in the ACL at the
|
105
|
+
# given +index+. If no index is provided, then an address to the
|
106
|
+
# first free byte of the ACL is returned.
|
107
|
+
#
|
108
|
+
def find_ace(index = nil)
|
109
|
+
ptr = [0].pack('L')
|
110
|
+
|
111
|
+
if index.nil?
|
112
|
+
unless FindFirstFreeAce(@acl, ptr)
|
113
|
+
raise Error, get_last_error
|
114
|
+
end
|
115
|
+
else
|
116
|
+
unless GetAce(@acl, index, ptr)
|
117
|
+
raise Error, get_last_error
|
118
|
+
end
|
119
|
+
end
|
120
|
+
|
121
|
+
[ptr].pack('p*').unpack('L')[0]
|
122
|
+
end
|
123
|
+
|
124
|
+
# Sets the revision information level, where the +revision_level+
|
125
|
+
# can be ACL_REVISION1, ACL_REVISION2, ACL_REVISION3 or ACL_REVISION4.
|
126
|
+
#
|
127
|
+
# Returns the revision level if successful.
|
128
|
+
#
|
129
|
+
def revision=(revision_level)
|
130
|
+
buf = [revision_level].pack('L')
|
131
|
+
|
132
|
+
unless SetAclInformation(@acl, buf, buf.size, AclRevisionInformation)
|
133
|
+
raise Error, get_last_error
|
134
|
+
end
|
135
|
+
|
136
|
+
@revision = revision_level
|
137
|
+
|
138
|
+
revision_level
|
139
|
+
end
|
140
|
+
|
141
|
+
# Returns whether or not the ACL is a valid ACL.
|
142
|
+
#
|
143
|
+
def valid?
|
144
|
+
IsValidAcl(@acl)
|
145
|
+
end
|
146
|
+
end
|
147
|
+
end
|
148
|
+
end
|
data/lib/win32/security/sid.rb
CHANGED
@@ -25,7 +25,7 @@ module Win32
|
|
25
25
|
class Error < StandardError; end
|
26
26
|
|
27
27
|
# The version of the Win32::Security::SID class.
|
28
|
-
VERSION = '0.1.
|
28
|
+
VERSION = '0.1.2'
|
29
29
|
|
30
30
|
# Some constant SID's for your convenience, in string format.
|
31
31
|
# See http://support.microsoft.com/kb/243330 for details.
|
@@ -108,7 +108,11 @@ module Win32
|
|
108
108
|
raise Error, get_last_error
|
109
109
|
end
|
110
110
|
|
111
|
-
|
111
|
+
if RUBY_VERSION.to_f < 1.9
|
112
|
+
sid_buf.strip
|
113
|
+
else
|
114
|
+
sid_buf.force_encoding('ASCII-8BIT').strip
|
115
|
+
end
|
112
116
|
end
|
113
117
|
|
114
118
|
# Creates a new SID with +authority+ and up to 8 +subauthorities+,
|
@@ -182,9 +186,11 @@ module Win32
|
|
182
186
|
domain_cch = [domain_buf.size].pack('L')
|
183
187
|
|
184
188
|
sid_name_use = 0.chr * 4
|
189
|
+
ordinal_val = account[0]
|
190
|
+
ordinal_val = ordinal_val.ord if RUBY_VERSION.to_f >= 1.9
|
185
191
|
|
186
192
|
# If characters in the 0-10 range, assume it's a binary SID.
|
187
|
-
if
|
193
|
+
if ordinal_val < 10
|
188
194
|
bool = LookupAccountSid(
|
189
195
|
host,
|
190
196
|
[account].pack('p*').unpack('L')[0],
|
@@ -211,7 +217,7 @@ module Win32
|
|
211
217
|
end
|
212
218
|
|
213
219
|
# The arguments are flipped if the account argument is binary
|
214
|
-
if
|
220
|
+
if ordinal_val < 10
|
215
221
|
@sid = account
|
216
222
|
@account = sid.strip
|
217
223
|
else
|
data/test/test_security.rb
CHANGED
data/test/test_sid.rb
CHANGED
data/win32-security.gemspec
CHANGED
@@ -2,7 +2,7 @@ require 'rubygems'
|
|
2
2
|
|
3
3
|
spec = Gem::Specification.new do |gem|
|
4
4
|
gem.name = 'win32-security'
|
5
|
-
gem.version = '0.1.
|
5
|
+
gem.version = '0.1.2'
|
6
6
|
gem.authors = ['Daniel J. Berger', 'Park Heesob']
|
7
7
|
gem.email = 'djberg96@gmail.com'
|
8
8
|
gem.homepage = 'http://www.rubyforge.org/projects/win32utils'
|
@@ -17,8 +17,9 @@ spec = Gem::Specification.new do |gem|
|
|
17
17
|
gem.rubyforge_project = 'win32utils'
|
18
18
|
|
19
19
|
gem.add_dependency('windows-pr', '>= 0.9.8')
|
20
|
-
|
21
|
-
gem.
|
20
|
+
|
21
|
+
gem.add_development_dependency('test-unit', '>= 2.0.1')
|
22
|
+
gem.add_development_dependency('sys-admin', '>= 1.4.4')
|
22
23
|
|
23
24
|
gem.description = <<-EOF
|
24
25
|
The win32-security library provides an interface for dealing with
|
@@ -27,5 +28,4 @@ spec = Gem::Specification.new do |gem|
|
|
27
28
|
EOF
|
28
29
|
end
|
29
30
|
|
30
|
-
Gem.manage_gems if Gem::RubyGemsVersion.to_f < 1.0
|
31
31
|
Gem::Builder.new(spec).build
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: win32-security
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Daniel J. Berger
|
@@ -10,7 +10,7 @@ autorequire:
|
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
12
|
|
13
|
-
date: 2009-
|
13
|
+
date: 2009-08-02 00:00:00 -06:00
|
14
14
|
default_executable:
|
15
15
|
dependencies:
|
16
16
|
- !ruby/object:Gem::Dependency
|
@@ -25,7 +25,7 @@ dependencies:
|
|
25
25
|
version:
|
26
26
|
- !ruby/object:Gem::Dependency
|
27
27
|
name: test-unit
|
28
|
-
type: :
|
28
|
+
type: :development
|
29
29
|
version_requirement:
|
30
30
|
version_requirements: !ruby/object:Gem::Requirement
|
31
31
|
requirements:
|
@@ -35,7 +35,7 @@ dependencies:
|
|
35
35
|
version:
|
36
36
|
- !ruby/object:Gem::Dependency
|
37
37
|
name: sys-admin
|
38
|
-
type: :
|
38
|
+
type: :development
|
39
39
|
version_requirement:
|
40
40
|
version_requirements: !ruby/object:Gem::Requirement
|
41
41
|
requirements:
|
@@ -55,6 +55,8 @@ extra_rdoc_files:
|
|
55
55
|
- MANIFEST
|
56
56
|
files:
|
57
57
|
- CHANGES
|
58
|
+
- lib/win32/security/ace.rb
|
59
|
+
- lib/win32/security/acl.rb
|
58
60
|
- lib/win32/security/sid.rb
|
59
61
|
- lib/win32/security.rb
|
60
62
|
- MANIFEST
|
@@ -88,7 +90,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
88
90
|
requirements: []
|
89
91
|
|
90
92
|
rubyforge_project: win32utils
|
91
|
-
rubygems_version: 1.3.
|
93
|
+
rubygems_version: 1.3.5
|
92
94
|
signing_key:
|
93
95
|
specification_version: 3
|
94
96
|
summary: A library for dealing with aspects of Windows security.
|