sys-admin 1.7.6 → 1.8.0
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/CHANGES.md +8 -0
- data/Gemfile +2 -3
- data/README.md +3 -0
- data/Rakefile +13 -16
- data/lib/linux/sys/admin.rb +0 -2
- data/lib/sys/admin.rb +1 -1
- data/lib/windows/sys/admin.rb +313 -295
- data/spec/sys_admin_unix_spec.rb +262 -0
- data/spec/sys_admin_windows_spec.rb +350 -0
- data/sys-admin.gemspec +11 -5
- data.tar.gz.sig +0 -0
- metadata +13 -13
- metadata.gz.sig +0 -0
- data/test/test_sys_admin.rb +0 -23
- data/test/test_sys_admin_unix.rb +0 -260
- data/test/test_sys_admin_windows.rb +0 -337
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 72d00ed279d1871b324cf2819ba90432093b8063a30e0bbdc9fa66111b588538
|
4
|
+
data.tar.gz: 31bc4f2515a391ba43c1bc9ce0b3bdeffacd6d758b7e98a29a111ced2ab14e85
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 36c4dc086a9929e998695ed02ce9cb89b5bd487cc4cb42aacccc26aab8a3fa3f62fde29a2bbb0792fd6657278fbe874e3366e3dc08a29c2ebc99e087bb1ea939
|
7
|
+
data.tar.gz: 3f9c593cd1b2008966524683d511c1c5e7e6ada91298516adc46afe948dd39cad7da069b426f268376493e6eb28934f020d55be60c73fca2bb756cf885d1e245
|
checksums.yaml.gz.sig
CHANGED
Binary file
|
data/CHANGES.md
CHANGED
@@ -1,3 +1,11 @@
|
|
1
|
+
## 1.8.0 - 26-Aug-2021
|
2
|
+
* Switched from test-unit to rspec, with some tests refactored. The Rakefile
|
3
|
+
and gemspec files were updated accordingly.
|
4
|
+
* The User and Group classes for the Windows implementation are now properly
|
5
|
+
scoped under Sys::Admin instead of just Sys.
|
6
|
+
* Fixed a bug in the get_user and get_group methods on Winodws where the WQL
|
7
|
+
it generates internally might not be correct.
|
8
|
+
|
1
9
|
## 1.7.6 - 24-Mar-2021
|
2
10
|
* Changed the implementation for `Admin.get_login` on Linux since the
|
3
11
|
underlying `getlogin` C function is unreliable, especially in certain
|
data/Gemfile
CHANGED
@@ -1,3 +1,2 @@
|
|
1
|
-
source 'https://rubygems.org'
|
2
|
-
|
3
|
-
end
|
1
|
+
source 'https://rubygems.org'
|
2
|
+
gemspec
|
data/README.md
CHANGED
@@ -4,6 +4,9 @@ The sys-admin library is a unified, cross platform replacement for the Etc modul
|
|
4
4
|
## Installation
|
5
5
|
`gem install sys-admin`
|
6
6
|
|
7
|
+
## Adding the trusted cert
|
8
|
+
`gem cert --add <(curl -Ls https://raw.githubusercontent.com/djberg96/sys-admin/main/certs/djberg96_pub.pem)`
|
9
|
+
|
7
10
|
## Synopsis
|
8
11
|
```ruby
|
9
12
|
require 'sys/admin' # or sys-admin
|
data/Rakefile
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
require 'rake'
|
2
2
|
require 'rake/clean'
|
3
|
-
require '
|
3
|
+
require 'rspec/core/rake_task'
|
4
4
|
require 'rbconfig'
|
5
5
|
|
6
6
|
CLEAN.include("**/*.gem", "**/*.rbx", "**/*.rbc", "ruby.core", "**/*.lock")
|
@@ -9,7 +9,7 @@ namespace :gem do
|
|
9
9
|
desc "Create the sys-uname gem"
|
10
10
|
task :create => [:clean] do
|
11
11
|
require 'rubygems/package'
|
12
|
-
spec =
|
12
|
+
spec = Gem::Specification.load('sys-admin.gemspec')
|
13
13
|
spec.signing_key = File.join(Dir.home, '.ssh', 'gem-private_key.pem')
|
14
14
|
Gem::Package.build(spec)
|
15
15
|
end
|
@@ -21,27 +21,24 @@ namespace :gem do
|
|
21
21
|
end
|
22
22
|
end
|
23
23
|
|
24
|
-
|
24
|
+
desc "Run the specs for the sys-admin library"
|
25
|
+
RSpec::Core::RakeTask.new(:spec) do |t|
|
26
|
+
t.pattern = 'spec/sys_admin_unix_spec.rb'
|
25
27
|
case RbConfig::CONFIG['host_os']
|
26
28
|
when /darwin|osx/i
|
27
|
-
t.
|
29
|
+
t.rspec_opts = '-Ilib/darwin'
|
28
30
|
when /linux/i
|
29
|
-
t.
|
31
|
+
t.rspec_opts = '-Ilib/linux'
|
30
32
|
when /sunos|solaris/i
|
31
|
-
t.
|
33
|
+
t.rspec_opts = '-Ilib/sunos'
|
32
34
|
when /bsd/i
|
33
|
-
t.
|
35
|
+
t.rspec_opts = '-Ilib/bsd'
|
34
36
|
when /windows|win32|mingw|cygwin|dos/i
|
35
|
-
t.
|
37
|
+
t.rspec_opts = '-Ilib/windows'
|
38
|
+
t.pattern = 'spec/sys_admin_windows_spec.rb'
|
36
39
|
else
|
37
|
-
t.
|
40
|
+
t.rspec_opts = '-Ilib/unix'
|
38
41
|
end
|
39
|
-
|
40
|
-
t.warning = true
|
41
|
-
t.verbose = true
|
42
|
-
|
43
|
-
t.libs << 'test'
|
44
|
-
t.test_files = FileList['test/test_sys_admin.rb']
|
45
42
|
end
|
46
43
|
|
47
|
-
task :default => :
|
44
|
+
task :default => :spec
|
data/lib/linux/sys/admin.rb
CHANGED
@@ -14,7 +14,6 @@ module Sys
|
|
14
14
|
attach_function :pread_c, :pread, [:int, :pointer, :size_t, :off_t], :size_t
|
15
15
|
attach_function :close_c, :close, [:int], :int
|
16
16
|
|
17
|
-
attach_function :getlogin_r, [:pointer, :size_t], :int
|
18
17
|
attach_function :getpwnam_r, [:string, :pointer, :pointer, :size_t, :pointer], :int
|
19
18
|
attach_function :getpwuid_r, [:long, :pointer, :pointer, :size_t, :pointer], :int
|
20
19
|
attach_function :getpwent_r, [:pointer, :pointer, :size_t, :pointer], :int
|
@@ -22,7 +21,6 @@ module Sys
|
|
22
21
|
attach_function :getgrnam_r, [:string, :pointer, :pointer, :size_t, :pointer], :int
|
23
22
|
attach_function :getgrgid_r, [:long, :pointer, :pointer, :size_t, :pointer], :int
|
24
23
|
|
25
|
-
private_class_method :getlogin_r, :getpwnam_r, :getpwuid_r, :getpwent_r
|
26
24
|
private_class_method :getgrent_r, :getgrnam_r, :getgrgid_r
|
27
25
|
private_class_method :open_c, :pread_c, :close_c
|
28
26
|
|
data/lib/sys/admin.rb
CHANGED
data/lib/windows/sys/admin.rb
CHANGED
@@ -5,295 +5,6 @@ require 'win32/registry'
|
|
5
5
|
require 'socket'
|
6
6
|
|
7
7
|
module Sys
|
8
|
-
class Group
|
9
|
-
# Short description of the object.
|
10
|
-
attr_accessor :caption
|
11
|
-
|
12
|
-
# Description of the group.
|
13
|
-
attr_accessor :description
|
14
|
-
|
15
|
-
# Name of the Windows domain to which the group account belongs.
|
16
|
-
attr_accessor :domain
|
17
|
-
|
18
|
-
# Date the group was added.
|
19
|
-
attr_accessor :install_date
|
20
|
-
|
21
|
-
# Name of the Windows group account on the Group#domain specified.
|
22
|
-
attr_accessor :name
|
23
|
-
|
24
|
-
# Security identifier for this group.
|
25
|
-
attr_accessor :sid
|
26
|
-
|
27
|
-
# Current status for the group, such as "ok", "error", etc.
|
28
|
-
attr_accessor :status
|
29
|
-
|
30
|
-
# The group ID.
|
31
|
-
attr_accessor :gid
|
32
|
-
|
33
|
-
# Sets whether or not the group is local (as opposed to global).
|
34
|
-
attr_writer :local
|
35
|
-
|
36
|
-
# An array of members for that group. May contain SID's.
|
37
|
-
attr_accessor :members
|
38
|
-
|
39
|
-
# Creates and returns a new Group object. This class encapsulates
|
40
|
-
# the information for a group account, whether it be global or local.
|
41
|
-
#
|
42
|
-
# Yields +self+ if a block is given.
|
43
|
-
#
|
44
|
-
def initialize
|
45
|
-
yield self if block_given?
|
46
|
-
end
|
47
|
-
|
48
|
-
# Returns whether or not the group is a local group.
|
49
|
-
#
|
50
|
-
def local?
|
51
|
-
@local
|
52
|
-
end
|
53
|
-
|
54
|
-
# Returns the type of SID (Security Identifier) as a stringified value.
|
55
|
-
#
|
56
|
-
def sid_type
|
57
|
-
@sid_type
|
58
|
-
end
|
59
|
-
|
60
|
-
# Sets the SID (Security Identifier) type to +stype+, which can be
|
61
|
-
# one of the following constant values:
|
62
|
-
#
|
63
|
-
# * Admin::SidTypeUser
|
64
|
-
# * Admin::SidTypeGroup
|
65
|
-
# * Admin::SidTypeDomain
|
66
|
-
# * Admin::SidTypeAlias
|
67
|
-
# * Admin::SidTypeWellKnownGroup
|
68
|
-
# * Admin::SidTypeDeletedAccount
|
69
|
-
# * Admin::SidTypeInvalid
|
70
|
-
# * Admin::SidTypeUnknown
|
71
|
-
# * Admin::SidTypeComputer
|
72
|
-
#
|
73
|
-
def sid_type=(stype)
|
74
|
-
if stype.kind_of?(String)
|
75
|
-
@sid_type = stype.downcase
|
76
|
-
else
|
77
|
-
case stype
|
78
|
-
when Admin::SidTypeUser
|
79
|
-
@sid_type = "user"
|
80
|
-
when Admin::SidTypeGroup
|
81
|
-
@sid_type = "group"
|
82
|
-
when Admin::SidTypeDomain
|
83
|
-
@sid_type = "domain"
|
84
|
-
when Admin::SidTypeAlias
|
85
|
-
@sid_type = "alias"
|
86
|
-
when Admin::SidTypeWellKnownGroup
|
87
|
-
@sid_type = "well_known_group"
|
88
|
-
when Admin::SidTypeDeletedAccount
|
89
|
-
@sid_type = "deleted_account"
|
90
|
-
when Admin::SidTypeInvalid
|
91
|
-
@sid_type = "invalid"
|
92
|
-
when Admin::SidTypeUnknown
|
93
|
-
@sid_type = "unknown"
|
94
|
-
when Admin::SidTypeComputer
|
95
|
-
@sid_type = "computer"
|
96
|
-
else
|
97
|
-
@sid_type = "unknown"
|
98
|
-
end
|
99
|
-
end
|
100
|
-
end
|
101
|
-
end
|
102
|
-
|
103
|
-
class User
|
104
|
-
# An account for users whose primary account is in another domain.
|
105
|
-
TEMP_DUPLICATE = 0x0100
|
106
|
-
|
107
|
-
# Default account type that represents a typical user.
|
108
|
-
NORMAL = 0x0200
|
109
|
-
|
110
|
-
# A permit to trust account for a domain that trusts other domains.
|
111
|
-
INTERDOMAIN_TRUST = 0x0800
|
112
|
-
|
113
|
-
# An account for a Windows NT/2000 workstation or server that is a
|
114
|
-
# member of this domain.
|
115
|
-
WORKSTATION_TRUST = 0x1000
|
116
|
-
|
117
|
-
# A computer account for a backup domain controller that is a member
|
118
|
-
# of this domain.
|
119
|
-
SERVER_TRUST = 0x2000
|
120
|
-
|
121
|
-
# Domain and username of the account.
|
122
|
-
attr_accessor :caption
|
123
|
-
|
124
|
-
# Description of the account.
|
125
|
-
attr_accessor :description
|
126
|
-
|
127
|
-
# Name of the Windows domain to which a user account belongs.
|
128
|
-
attr_accessor :domain
|
129
|
-
|
130
|
-
# The user's password.
|
131
|
-
attr_accessor :password
|
132
|
-
|
133
|
-
# Full name of a local user.
|
134
|
-
attr_accessor :full_name
|
135
|
-
|
136
|
-
# An array of groups to which the user belongs.
|
137
|
-
attr_accessor :groups
|
138
|
-
|
139
|
-
# Date the user account was created.
|
140
|
-
attr_accessor :install_date
|
141
|
-
|
142
|
-
# Name of the Windows user account on the domain that the User#domain
|
143
|
-
# property specifies.
|
144
|
-
attr_accessor :name
|
145
|
-
|
146
|
-
# The user's security identifier.
|
147
|
-
attr_accessor :sid
|
148
|
-
|
149
|
-
# Current status for the user, such as "ok", "error", etc.
|
150
|
-
attr_accessor :status
|
151
|
-
|
152
|
-
# The user's id (RID).
|
153
|
-
attr_accessor :uid
|
154
|
-
|
155
|
-
# The user's primary group ID.
|
156
|
-
attr_accessor :gid
|
157
|
-
|
158
|
-
# The user's home directory
|
159
|
-
attr_accessor :dir
|
160
|
-
|
161
|
-
# Used to set whether or not the account is disabled.
|
162
|
-
attr_writer :disabled
|
163
|
-
|
164
|
-
# Sets whether or not the account is defined on the local computer.
|
165
|
-
attr_writer :local
|
166
|
-
|
167
|
-
# Sets whether or not the account is locked out of the OS.
|
168
|
-
attr_writer :lockout
|
169
|
-
|
170
|
-
# Sets whether or not the password for the account can be changed.
|
171
|
-
attr_writer :password_changeable
|
172
|
-
|
173
|
-
# Sets whether or not the password for the account expires.
|
174
|
-
attr_writer :password_expires
|
175
|
-
|
176
|
-
# Sets whether or not a password is required for the account.
|
177
|
-
attr_writer :password_required
|
178
|
-
|
179
|
-
# Returns the account type as a human readable string.
|
180
|
-
attr_reader :account_type
|
181
|
-
|
182
|
-
# Creates an returns a new User object. A User object encapsulates a
|
183
|
-
# user account on the operating system.
|
184
|
-
#
|
185
|
-
# Yields +self+ if a block is provided.
|
186
|
-
#
|
187
|
-
def initialize
|
188
|
-
yield self if block_given?
|
189
|
-
end
|
190
|
-
|
191
|
-
# Sets the account type for the account. Possible values are:
|
192
|
-
#
|
193
|
-
# * User::TEMP_DUPLICATE
|
194
|
-
# * User::NORMAL
|
195
|
-
# * User::INTERDOMAIN_TRUST
|
196
|
-
# * User::WORKSTATION_TRUST
|
197
|
-
# * User::SERVER_TRUST
|
198
|
-
#
|
199
|
-
def account_type=(type)
|
200
|
-
case type
|
201
|
-
when TEMP_DUPLICATE
|
202
|
-
@account_type = 'duplicate'
|
203
|
-
when NORMAL
|
204
|
-
@account_type = 'normal'
|
205
|
-
when INTERDOMAIN_TRUST
|
206
|
-
@account_type = 'interdomain_trust'
|
207
|
-
when WORKSTATION_TRUST
|
208
|
-
@account_type = 'workstation_trust'
|
209
|
-
when SERVER_TRUST
|
210
|
-
@account_type = 'server_trust'
|
211
|
-
else
|
212
|
-
@account_type = 'unknown'
|
213
|
-
end
|
214
|
-
end
|
215
|
-
|
216
|
-
# Returns the SID type as a human readable string.
|
217
|
-
#
|
218
|
-
def sid_type
|
219
|
-
@sid_type
|
220
|
-
end
|
221
|
-
|
222
|
-
# Sets the SID (Security Identifier) type to +stype+, which can be
|
223
|
-
# one of the following constant values:
|
224
|
-
#
|
225
|
-
# * Admin::SidTypeUser
|
226
|
-
# * Admin::SidTypeGroup
|
227
|
-
# * Admin::SidTypeDomain
|
228
|
-
# * Admin::SidTypeAlias
|
229
|
-
# * Admin::SidTypeWellKnownGroup
|
230
|
-
# * Admin::SidTypeDeletedAccount
|
231
|
-
# * Admin::SidTypeInvalid
|
232
|
-
# * Admin::SidTypeUnknown
|
233
|
-
# * Admin::SidTypeComputer
|
234
|
-
#
|
235
|
-
def sid_type=(stype)
|
236
|
-
case stype
|
237
|
-
when Admin::SidTypeUser
|
238
|
-
@sid_type = 'user'
|
239
|
-
when Admin::SidTypeGroup
|
240
|
-
@sid_type = 'group'
|
241
|
-
when Admin::SidTypeDomain
|
242
|
-
@sid_type = 'domain'
|
243
|
-
when Admin::SidTypeAlias
|
244
|
-
@sid_type = 'alias'
|
245
|
-
when Admin::SidTypeWellKnownGroup
|
246
|
-
@sid_type = 'well_known_group'
|
247
|
-
when Admin::SidTypeDeletedAccount
|
248
|
-
@sid_type = 'deleted_account'
|
249
|
-
when Admin::SidTypeInvalid
|
250
|
-
@sid_type = 'invalid'
|
251
|
-
when Admin::SidTypeUnknown
|
252
|
-
@sid_type = 'unknown'
|
253
|
-
when Admin::SidTypeComputer
|
254
|
-
@sid_type = 'computer'
|
255
|
-
else
|
256
|
-
@sid_type = 'unknown'
|
257
|
-
end
|
258
|
-
end
|
259
|
-
|
260
|
-
# Returns whether or not the account is disabled.
|
261
|
-
#
|
262
|
-
def disabled?
|
263
|
-
@disabled
|
264
|
-
end
|
265
|
-
|
266
|
-
# Returns whether or not the account is local.
|
267
|
-
#
|
268
|
-
def local?
|
269
|
-
@local
|
270
|
-
end
|
271
|
-
|
272
|
-
# Returns whether or not the account is locked out.
|
273
|
-
#
|
274
|
-
def lockout?
|
275
|
-
@lockout
|
276
|
-
end
|
277
|
-
|
278
|
-
# Returns whether or not the password for the account is changeable.
|
279
|
-
#
|
280
|
-
def password_changeable?
|
281
|
-
@password_changeable
|
282
|
-
end
|
283
|
-
|
284
|
-
# Returns whether or not the password for the account is changeable.
|
285
|
-
#
|
286
|
-
def password_expires?
|
287
|
-
@password_expires
|
288
|
-
end
|
289
|
-
|
290
|
-
# Returns whether or not the a password is required for the account.
|
291
|
-
#
|
292
|
-
def password_required?
|
293
|
-
@password_required
|
294
|
-
end
|
295
|
-
end
|
296
|
-
|
297
8
|
class Admin
|
298
9
|
extend FFI::Library
|
299
10
|
|
@@ -708,10 +419,18 @@ module Sys
|
|
708
419
|
end
|
709
420
|
}
|
710
421
|
|
711
|
-
if usr.kind_of?(
|
712
|
-
|
422
|
+
if usr.kind_of?(Numeric)
|
423
|
+
if i == 0
|
424
|
+
query << " where sid like '%-#{usr}'"
|
425
|
+
else
|
426
|
+
query << " and sid like '%-#{usr}'"
|
427
|
+
end
|
713
428
|
else
|
714
|
-
|
429
|
+
if i == 0
|
430
|
+
query << " where name = '#{usr}'"
|
431
|
+
else
|
432
|
+
query << " and name = '#{usr}'"
|
433
|
+
end
|
715
434
|
end
|
716
435
|
|
717
436
|
domain = options[:domain] || host
|
@@ -721,7 +440,7 @@ module Sys
|
|
721
440
|
|
722
441
|
# Because our 'like' query isn't fulproof, let's parse
|
723
442
|
# the SID again to make sure
|
724
|
-
if usr.kind_of?(
|
443
|
+
if usr.kind_of?(Numeric)
|
725
444
|
next if usr != uid
|
726
445
|
end
|
727
446
|
|
@@ -890,9 +609,17 @@ module Sys
|
|
890
609
|
}
|
891
610
|
|
892
611
|
if grp.kind_of?(Integer)
|
893
|
-
|
612
|
+
if i == 0
|
613
|
+
query << " where sid like '%-#{grp}'"
|
614
|
+
else
|
615
|
+
query << " and sid like '%-#{grp}'"
|
616
|
+
end
|
894
617
|
else
|
895
|
-
|
618
|
+
if i == 0
|
619
|
+
query << " where name = '#{grp}'"
|
620
|
+
else
|
621
|
+
query << " and name = '#{grp}'"
|
622
|
+
end
|
896
623
|
end
|
897
624
|
|
898
625
|
domain = options[:domain] || host
|
@@ -996,5 +723,296 @@ module Sys
|
|
996
723
|
|
997
724
|
array
|
998
725
|
end
|
726
|
+
|
727
|
+
class User
|
728
|
+
# An account for users whose primary account is in another domain.
|
729
|
+
TEMP_DUPLICATE = 0x0100
|
730
|
+
|
731
|
+
# Default account type that represents a typical user.
|
732
|
+
NORMAL = 0x0200
|
733
|
+
|
734
|
+
# A permit to trust account for a domain that trusts other domains.
|
735
|
+
INTERDOMAIN_TRUST = 0x0800
|
736
|
+
|
737
|
+
# An account for a Windows NT/2000 workstation or server that is a
|
738
|
+
# member of this domain.
|
739
|
+
WORKSTATION_TRUST = 0x1000
|
740
|
+
|
741
|
+
# A computer account for a backup domain controller that is a member
|
742
|
+
# of this domain.
|
743
|
+
SERVER_TRUST = 0x2000
|
744
|
+
|
745
|
+
# Domain and username of the account.
|
746
|
+
attr_accessor :caption
|
747
|
+
|
748
|
+
# Description of the account.
|
749
|
+
attr_accessor :description
|
750
|
+
|
751
|
+
# Name of the Windows domain to which a user account belongs.
|
752
|
+
attr_accessor :domain
|
753
|
+
|
754
|
+
# The user's password.
|
755
|
+
attr_accessor :password
|
756
|
+
|
757
|
+
# Full name of a local user.
|
758
|
+
attr_accessor :full_name
|
759
|
+
|
760
|
+
# An array of groups to which the user belongs.
|
761
|
+
attr_accessor :groups
|
762
|
+
|
763
|
+
# Date the user account was created.
|
764
|
+
attr_accessor :install_date
|
765
|
+
|
766
|
+
# Name of the Windows user account on the domain that the User#domain
|
767
|
+
# property specifies.
|
768
|
+
attr_accessor :name
|
769
|
+
|
770
|
+
# The user's security identifier.
|
771
|
+
attr_accessor :sid
|
772
|
+
|
773
|
+
# Current status for the user, such as "ok", "error", etc.
|
774
|
+
attr_accessor :status
|
775
|
+
|
776
|
+
# The user's id (RID).
|
777
|
+
attr_accessor :uid
|
778
|
+
|
779
|
+
# The user's primary group ID.
|
780
|
+
attr_accessor :gid
|
781
|
+
|
782
|
+
# The user's home directory
|
783
|
+
attr_accessor :dir
|
784
|
+
|
785
|
+
# Used to set whether or not the account is disabled.
|
786
|
+
attr_writer :disabled
|
787
|
+
|
788
|
+
# Sets whether or not the account is defined on the local computer.
|
789
|
+
attr_writer :local
|
790
|
+
|
791
|
+
# Sets whether or not the account is locked out of the OS.
|
792
|
+
attr_writer :lockout
|
793
|
+
|
794
|
+
# Sets whether or not the password for the account can be changed.
|
795
|
+
attr_writer :password_changeable
|
796
|
+
|
797
|
+
# Sets whether or not the password for the account expires.
|
798
|
+
attr_writer :password_expires
|
799
|
+
|
800
|
+
# Sets whether or not a password is required for the account.
|
801
|
+
attr_writer :password_required
|
802
|
+
|
803
|
+
# Returns the account type as a human readable string.
|
804
|
+
attr_reader :account_type
|
805
|
+
|
806
|
+
# Creates an returns a new User object. A User object encapsulates a
|
807
|
+
# user account on the operating system.
|
808
|
+
#
|
809
|
+
# Yields +self+ if a block is provided.
|
810
|
+
#
|
811
|
+
def initialize
|
812
|
+
yield self if block_given?
|
813
|
+
end
|
814
|
+
|
815
|
+
# Sets the account type for the account. Possible values are:
|
816
|
+
#
|
817
|
+
# * User::TEMP_DUPLICATE
|
818
|
+
# * User::NORMAL
|
819
|
+
# * User::INTERDOMAIN_TRUST
|
820
|
+
# * User::WORKSTATION_TRUST
|
821
|
+
# * User::SERVER_TRUST
|
822
|
+
#
|
823
|
+
def account_type=(type)
|
824
|
+
case type
|
825
|
+
when TEMP_DUPLICATE
|
826
|
+
@account_type = 'duplicate'
|
827
|
+
when NORMAL
|
828
|
+
@account_type = 'normal'
|
829
|
+
when INTERDOMAIN_TRUST
|
830
|
+
@account_type = 'interdomain_trust'
|
831
|
+
when WORKSTATION_TRUST
|
832
|
+
@account_type = 'workstation_trust'
|
833
|
+
when SERVER_TRUST
|
834
|
+
@account_type = 'server_trust'
|
835
|
+
else
|
836
|
+
@account_type = 'unknown'
|
837
|
+
end
|
838
|
+
end
|
839
|
+
|
840
|
+
# Returns the SID type as a human readable string.
|
841
|
+
#
|
842
|
+
def sid_type
|
843
|
+
@sid_type
|
844
|
+
end
|
845
|
+
|
846
|
+
# Sets the SID (Security Identifier) type to +stype+, which can be
|
847
|
+
# one of the following constant values:
|
848
|
+
#
|
849
|
+
# * Admin::SidTypeUser
|
850
|
+
# * Admin::SidTypeGroup
|
851
|
+
# * Admin::SidTypeDomain
|
852
|
+
# * Admin::SidTypeAlias
|
853
|
+
# * Admin::SidTypeWellKnownGroup
|
854
|
+
# * Admin::SidTypeDeletedAccount
|
855
|
+
# * Admin::SidTypeInvalid
|
856
|
+
# * Admin::SidTypeUnknown
|
857
|
+
# * Admin::SidTypeComputer
|
858
|
+
#
|
859
|
+
def sid_type=(stype)
|
860
|
+
case stype
|
861
|
+
when Admin::SidTypeUser
|
862
|
+
@sid_type = 'user'
|
863
|
+
when Admin::SidTypeGroup
|
864
|
+
@sid_type = 'group'
|
865
|
+
when Admin::SidTypeDomain
|
866
|
+
@sid_type = 'domain'
|
867
|
+
when Admin::SidTypeAlias
|
868
|
+
@sid_type = 'alias'
|
869
|
+
when Admin::SidTypeWellKnownGroup
|
870
|
+
@sid_type = 'well_known_group'
|
871
|
+
when Admin::SidTypeDeletedAccount
|
872
|
+
@sid_type = 'deleted_account'
|
873
|
+
when Admin::SidTypeInvalid
|
874
|
+
@sid_type = 'invalid'
|
875
|
+
when Admin::SidTypeUnknown
|
876
|
+
@sid_type = 'unknown'
|
877
|
+
when Admin::SidTypeComputer
|
878
|
+
@sid_type = 'computer'
|
879
|
+
else
|
880
|
+
@sid_type = 'unknown'
|
881
|
+
end
|
882
|
+
end
|
883
|
+
|
884
|
+
# Returns whether or not the account is disabled.
|
885
|
+
#
|
886
|
+
def disabled?
|
887
|
+
@disabled
|
888
|
+
end
|
889
|
+
|
890
|
+
# Returns whether or not the account is local.
|
891
|
+
#
|
892
|
+
def local?
|
893
|
+
@local
|
894
|
+
end
|
895
|
+
|
896
|
+
# Returns whether or not the account is locked out.
|
897
|
+
#
|
898
|
+
def lockout?
|
899
|
+
@lockout
|
900
|
+
end
|
901
|
+
|
902
|
+
# Returns whether or not the password for the account is changeable.
|
903
|
+
#
|
904
|
+
def password_changeable?
|
905
|
+
@password_changeable
|
906
|
+
end
|
907
|
+
|
908
|
+
# Returns whether or not the password for the account is changeable.
|
909
|
+
#
|
910
|
+
def password_expires?
|
911
|
+
@password_expires
|
912
|
+
end
|
913
|
+
|
914
|
+
# Returns whether or not the a password is required for the account.
|
915
|
+
#
|
916
|
+
def password_required?
|
917
|
+
@password_required
|
918
|
+
end
|
919
|
+
end
|
920
|
+
|
921
|
+
class Group
|
922
|
+
# Short description of the object.
|
923
|
+
attr_accessor :caption
|
924
|
+
|
925
|
+
# Description of the group.
|
926
|
+
attr_accessor :description
|
927
|
+
|
928
|
+
# Name of the Windows domain to which the group account belongs.
|
929
|
+
attr_accessor :domain
|
930
|
+
|
931
|
+
# Date the group was added.
|
932
|
+
attr_accessor :install_date
|
933
|
+
|
934
|
+
# Name of the Windows group account on the Group#domain specified.
|
935
|
+
attr_accessor :name
|
936
|
+
|
937
|
+
# Security identifier for this group.
|
938
|
+
attr_accessor :sid
|
939
|
+
|
940
|
+
# Current status for the group, such as "ok", "error", etc.
|
941
|
+
attr_accessor :status
|
942
|
+
|
943
|
+
# The group ID.
|
944
|
+
attr_accessor :gid
|
945
|
+
|
946
|
+
# Sets whether or not the group is local (as opposed to global).
|
947
|
+
attr_writer :local
|
948
|
+
|
949
|
+
# An array of members for that group. May contain SID's.
|
950
|
+
attr_accessor :members
|
951
|
+
|
952
|
+
# Creates and returns a new Group object. This class encapsulates
|
953
|
+
# the information for a group account, whether it be global or local.
|
954
|
+
#
|
955
|
+
# Yields +self+ if a block is given.
|
956
|
+
#
|
957
|
+
def initialize
|
958
|
+
yield self if block_given?
|
959
|
+
end
|
960
|
+
|
961
|
+
# Returns whether or not the group is a local group.
|
962
|
+
#
|
963
|
+
def local?
|
964
|
+
@local
|
965
|
+
end
|
966
|
+
|
967
|
+
# Returns the type of SID (Security Identifier) as a stringified value.
|
968
|
+
#
|
969
|
+
def sid_type
|
970
|
+
@sid_type
|
971
|
+
end
|
972
|
+
|
973
|
+
# Sets the SID (Security Identifier) type to +stype+, which can be
|
974
|
+
# one of the following constant values:
|
975
|
+
#
|
976
|
+
# * Admin::SidTypeUser
|
977
|
+
# * Admin::SidTypeGroup
|
978
|
+
# * Admin::SidTypeDomain
|
979
|
+
# * Admin::SidTypeAlias
|
980
|
+
# * Admin::SidTypeWellKnownGroup
|
981
|
+
# * Admin::SidTypeDeletedAccount
|
982
|
+
# * Admin::SidTypeInvalid
|
983
|
+
# * Admin::SidTypeUnknown
|
984
|
+
# * Admin::SidTypeComputer
|
985
|
+
#
|
986
|
+
def sid_type=(stype)
|
987
|
+
if stype.kind_of?(String)
|
988
|
+
@sid_type = stype.downcase
|
989
|
+
else
|
990
|
+
case stype
|
991
|
+
when Admin::SidTypeUser
|
992
|
+
@sid_type = "user"
|
993
|
+
when Admin::SidTypeGroup
|
994
|
+
@sid_type = "group"
|
995
|
+
when Admin::SidTypeDomain
|
996
|
+
@sid_type = "domain"
|
997
|
+
when Admin::SidTypeAlias
|
998
|
+
@sid_type = "alias"
|
999
|
+
when Admin::SidTypeWellKnownGroup
|
1000
|
+
@sid_type = "well_known_group"
|
1001
|
+
when Admin::SidTypeDeletedAccount
|
1002
|
+
@sid_type = "deleted_account"
|
1003
|
+
when Admin::SidTypeInvalid
|
1004
|
+
@sid_type = "invalid"
|
1005
|
+
when Admin::SidTypeUnknown
|
1006
|
+
@sid_type = "unknown"
|
1007
|
+
when Admin::SidTypeComputer
|
1008
|
+
@sid_type = "computer"
|
1009
|
+
else
|
1010
|
+
@sid_type = "unknown"
|
1011
|
+
end
|
1012
|
+
end
|
1013
|
+
|
1014
|
+
@sid_type
|
1015
|
+
end
|
1016
|
+
end
|
999
1017
|
end
|
1000
1018
|
end
|