sys-admin 1.6.1 → 1.6.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGES +4 -0
- data/README +2 -0
- data/doc/sys-admin-unix.txt +162 -164
- data/doc/sys-admin-windows.txt +346 -336
- data/lib/sys/admin/common.rb +1 -1
- data/lib/windows/sys/admin.rb +55 -48
- data/sys-admin.gemspec +2 -3
- data/test/test_sys_admin.rb +1 -1
- data/test/test_sys_admin_windows.rb +48 -46
- metadata +7 -7
data/lib/sys/admin/common.rb
CHANGED
data/lib/windows/sys/admin.rb
CHANGED
@@ -154,6 +154,9 @@ module Sys
|
|
154
154
|
# The user's id (RID).
|
155
155
|
attr_accessor :uid
|
156
156
|
|
157
|
+
# The user's primary group ID.
|
158
|
+
attr_accessor :gid
|
159
|
+
|
157
160
|
# The user's home directory
|
158
161
|
attr_accessor :dir
|
159
162
|
|
@@ -196,26 +199,26 @@ module Sys
|
|
196
199
|
# * User::SERVER_TRUST
|
197
200
|
#
|
198
201
|
def account_type=(type)
|
199
|
-
|
200
|
-
|
201
|
-
|
202
|
-
|
203
|
-
|
204
|
-
|
205
|
-
|
206
|
-
|
207
|
-
|
208
|
-
|
209
|
-
|
210
|
-
|
211
|
-
|
212
|
-
|
202
|
+
case type
|
203
|
+
when TEMP_DUPLICATE
|
204
|
+
@account_type = 'duplicate'
|
205
|
+
when NORMAL
|
206
|
+
@account_type = 'normal'
|
207
|
+
when INTERDOMAIN_TRUST
|
208
|
+
@account_type = 'interdomain_trust'
|
209
|
+
when WORKSTATION_TRUST
|
210
|
+
@account_type = 'workstation_trust'
|
211
|
+
when SERVER_TRUST
|
212
|
+
@account_type = 'server_trust'
|
213
|
+
else
|
214
|
+
@account_type = 'unknown'
|
215
|
+
end
|
213
216
|
end
|
214
217
|
|
215
218
|
# Returns the SID type as a human readable string.
|
216
219
|
#
|
217
220
|
def sid_type
|
218
|
-
|
221
|
+
@sid_type
|
219
222
|
end
|
220
223
|
|
221
224
|
# Sets the SID (Security Identifier) type to +stype+, which can be
|
@@ -232,64 +235,64 @@ module Sys
|
|
232
235
|
# * Admin::SidTypeComputer
|
233
236
|
#
|
234
237
|
def sid_type=(stype)
|
235
|
-
|
236
|
-
|
237
|
-
|
238
|
-
|
239
|
-
|
240
|
-
|
241
|
-
|
242
|
-
|
243
|
-
|
244
|
-
|
245
|
-
|
246
|
-
|
247
|
-
|
248
|
-
|
249
|
-
|
250
|
-
|
251
|
-
|
252
|
-
|
253
|
-
|
254
|
-
|
255
|
-
|
256
|
-
|
238
|
+
case stype
|
239
|
+
when Admin::SidTypeUser
|
240
|
+
@sid_type = 'user'
|
241
|
+
when Admin::SidTypeGroup
|
242
|
+
@sid_type = 'group'
|
243
|
+
when Admin::SidTypeDomain
|
244
|
+
@sid_type = 'domain'
|
245
|
+
when Admin::SidTypeAlias
|
246
|
+
@sid_type = 'alias'
|
247
|
+
when Admin::SidTypeWellKnownGroup
|
248
|
+
@sid_type = 'well_known_group'
|
249
|
+
when Admin::SidTypeDeletedAccount
|
250
|
+
@sid_type = 'deleted_account'
|
251
|
+
when Admin::SidTypeInvalid
|
252
|
+
@sid_type = 'invalid'
|
253
|
+
when Admin::SidTypeUnknown
|
254
|
+
@sid_type = 'unknown'
|
255
|
+
when Admin::SidTypeComputer
|
256
|
+
@sid_type = 'computer'
|
257
|
+
else
|
258
|
+
@sid_type = 'unknown'
|
259
|
+
end
|
257
260
|
end
|
258
261
|
|
259
262
|
# Returns whether or not the account is disabled.
|
260
263
|
#
|
261
264
|
def disabled?
|
262
|
-
|
265
|
+
@disabled
|
263
266
|
end
|
264
267
|
|
265
268
|
# Returns whether or not the account is local.
|
266
269
|
#
|
267
270
|
def local?
|
268
|
-
|
271
|
+
@local
|
269
272
|
end
|
270
273
|
|
271
274
|
# Returns whether or not the account is locked out.
|
272
275
|
#
|
273
276
|
def lockout?
|
274
|
-
|
277
|
+
@lockout
|
275
278
|
end
|
276
279
|
|
277
280
|
# Returns whether or not the password for the account is changeable.
|
278
281
|
#
|
279
282
|
def password_changeable?
|
280
|
-
|
283
|
+
@password_changeable
|
281
284
|
end
|
282
285
|
|
283
286
|
# Returns whether or not the password for the account is changeable.
|
284
287
|
#
|
285
288
|
def password_expires?
|
286
|
-
|
289
|
+
@password_expires
|
287
290
|
end
|
288
291
|
|
289
292
|
# Returns whether or not the a password is required for the account.
|
290
293
|
#
|
291
294
|
def password_required?
|
292
|
-
|
295
|
+
@password_required
|
293
296
|
end
|
294
297
|
end
|
295
298
|
|
@@ -297,7 +300,7 @@ module Sys
|
|
297
300
|
extend FFI::Library
|
298
301
|
|
299
302
|
# The version of the sys-admin library.
|
300
|
-
VERSION = '1.6.
|
303
|
+
VERSION = '1.6.2'
|
301
304
|
|
302
305
|
# This is the error raised in the majority of cases if anything goes wrong
|
303
306
|
# with any of the Sys::Admin methods.
|
@@ -358,13 +361,14 @@ module Sys
|
|
358
361
|
end
|
359
362
|
|
360
363
|
# An internal, private method for getting a list of groups for
|
361
|
-
# a particular user.
|
364
|
+
# a particular user. The first member is a list of group names,
|
365
|
+
# the second member is the primary group ID.
|
362
366
|
#
|
363
367
|
def self.get_groups(domain, user)
|
364
368
|
array = []
|
365
|
-
adsi = WIN32OLE.connect("WinNT://#{domain}/#{user}")
|
369
|
+
adsi = WIN32OLE.connect("WinNT://#{domain}/#{user},user")
|
366
370
|
adsi.groups.each{ |g| array << g.name }
|
367
|
-
array
|
371
|
+
[array, adsi.PrimaryGroupId]
|
368
372
|
end
|
369
373
|
|
370
374
|
# An internal, private method for getting a list of members for
|
@@ -721,6 +725,8 @@ module Sys
|
|
721
725
|
next if usr != uid
|
722
726
|
end
|
723
727
|
|
728
|
+
groups, primary_group = *get_groups(domain, user.name)
|
729
|
+
|
724
730
|
user_object = User.new do |u|
|
725
731
|
u.account_type = user.accounttype
|
726
732
|
u.caption = user.caption
|
@@ -739,7 +745,8 @@ module Sys
|
|
739
745
|
u.sid_type = user.sidtype
|
740
746
|
u.status = user.status
|
741
747
|
u.uid = uid
|
742
|
-
u.
|
748
|
+
u.gid = primary_group
|
749
|
+
u.groups = groups
|
743
750
|
u.dir = get_home_dir(user.name, options[:localaccount], domain)
|
744
751
|
end
|
745
752
|
|
data/sys-admin.gemspec
CHANGED
@@ -1,10 +1,9 @@
|
|
1
|
-
require 'rubygems'
|
2
|
-
|
3
1
|
# Do not use this file directly. Build the gem via the Rake tasks.
|
2
|
+
require 'rubygems'
|
4
3
|
|
5
4
|
Gem::Specification.new do |spec|
|
6
5
|
spec.name = 'sys-admin'
|
7
|
-
spec.version = '1.6.
|
6
|
+
spec.version = '1.6.2'
|
8
7
|
spec.author = 'Daniel J. Berger'
|
9
8
|
spec.license = 'Artistic 2.0'
|
10
9
|
spec.email = 'djberg96@gmail.com'
|
data/test/test_sys_admin.rb
CHANGED
@@ -89,232 +89,234 @@ class TC_Sys_Admin_Win32 < Test::Unit::TestCase
|
|
89
89
|
assert_nothing_raised{ Admin.delete_group('bar') }
|
90
90
|
end
|
91
91
|
|
92
|
-
|
92
|
+
test "get_login basic functionality" do
|
93
93
|
assert_respond_to(Admin, :get_login)
|
94
94
|
assert_nothing_raised{ Admin.get_login }
|
95
95
|
end
|
96
96
|
|
97
|
-
|
97
|
+
test "get_login returns a string" do
|
98
98
|
assert_kind_of(String, Admin.get_login)
|
99
|
+
assert_true(Admin.get_login.size > 0)
|
99
100
|
end
|
100
101
|
|
101
|
-
|
102
|
+
test "get_login does not accept any arguments" do
|
102
103
|
assert_raise(ArgumentError){ Admin.get_login('foo') }
|
103
104
|
end
|
104
105
|
|
105
|
-
|
106
|
+
test "get_user basic functionality" do
|
106
107
|
assert_respond_to(Admin, :get_user)
|
107
108
|
end
|
108
109
|
|
109
|
-
|
110
|
+
test "get_user with string argument works as expected" do
|
110
111
|
assert_nothing_raised{ Admin.get_user(@user_name, :localaccount => true) }
|
111
112
|
assert_kind_of(User, Admin.get_user(@user_name, :localaccount => true))
|
112
113
|
end
|
113
114
|
|
114
|
-
|
115
|
+
test "get user with integer argument works as expected" do
|
115
116
|
assert_nothing_raised{ Admin.get_user(@user_id, :localaccount => true) }
|
116
117
|
assert_kind_of(User, Admin.get_user(@user_id, :localaccount => true))
|
117
118
|
end
|
118
119
|
|
119
|
-
|
120
|
+
test "get_user method by string accepts a hash of options" do
|
120
121
|
options = {:host => @@host, :localaccount => true}
|
121
122
|
assert_nothing_raised{ Admin.get_user(@user_name, options) }
|
122
123
|
assert_kind_of(User, Admin.get_user(@user_name, options))
|
123
124
|
end
|
124
125
|
|
125
|
-
|
126
|
+
test "get_user method by uid accepts a hash of options" do
|
126
127
|
options = {:host => @@host, :localaccount => true}
|
127
128
|
assert_nothing_raised{ Admin.get_user(@user_id, options) }
|
128
129
|
assert_kind_of(User, Admin.get_user(@user_id, options))
|
129
130
|
end
|
130
131
|
|
131
|
-
|
132
|
+
test "get_user method requires an argument" do
|
132
133
|
assert_raises(ArgumentError){ Admin.get_user }
|
133
134
|
end
|
134
135
|
|
135
|
-
|
136
|
+
test "users method basic functionality" do
|
136
137
|
assert_respond_to(Admin, :users)
|
137
138
|
assert_nothing_raised{ Admin.users(:localaccount => true) }
|
138
139
|
end
|
139
140
|
|
140
|
-
|
141
|
+
test "users method returns an array of User objects" do
|
141
142
|
assert_kind_of(Array, Admin.users(:localaccount => true))
|
142
143
|
assert_kind_of(User, Admin.users(:localaccount => true).first)
|
143
144
|
end
|
144
145
|
|
145
|
-
|
146
|
+
test "get_group basic functionality" do
|
146
147
|
assert_respond_to(Admin, :get_group)
|
147
148
|
end
|
148
149
|
|
149
|
-
|
150
|
+
test "get_group method returns expected results with a string argument" do
|
150
151
|
assert_nothing_raised{ Admin.get_group(@group_name, :localaccount => true) }
|
151
152
|
assert_kind_of(Group, Admin.get_group(@group_name, :localaccount => true))
|
152
153
|
end
|
153
154
|
|
154
|
-
|
155
|
+
test "get_group method returns expected results with an integer argument" do
|
155
156
|
assert_nothing_raised{ Admin.get_group(@group_id, :localaccount => true) }
|
156
157
|
assert_kind_of(Group, Admin.get_group(@group_id, :localaccount => true))
|
157
158
|
end
|
158
159
|
|
159
|
-
|
160
|
+
# TODO: Update
|
161
|
+
test "get_group method accepts a hash of options" do
|
160
162
|
assert_nothing_raised{ Admin.get_group(@group_name, :localaccount => true) }
|
161
163
|
assert_kind_of(Group, Admin.get_group(@group_name, :localaccount => true))
|
162
164
|
end
|
163
165
|
|
164
|
-
|
166
|
+
test "get_group method requires an argument" do
|
165
167
|
assert_raise(ArgumentError){ Admin.get_group }
|
166
168
|
end
|
167
169
|
|
168
|
-
|
170
|
+
test "get_groups method basic functionality" do
|
169
171
|
assert_respond_to(Admin, :groups)
|
170
172
|
assert_nothing_raised{ Admin.groups(:localaccount => true) }
|
171
173
|
end
|
172
174
|
|
173
|
-
|
175
|
+
test "get_groups method returns an array of Group objects" do
|
174
176
|
assert_kind_of(Array, Admin.groups(:localaccount => true))
|
175
177
|
assert_kind_of(Group, Admin.groups(:localaccount => true).first)
|
176
178
|
end
|
177
179
|
|
178
180
|
# User class
|
179
181
|
|
180
|
-
|
182
|
+
test "caption accessor for User class" do
|
181
183
|
assert_respond_to(@user, :caption)
|
182
184
|
assert_respond_to(@user, :caption=)
|
183
185
|
end
|
184
186
|
|
185
|
-
|
187
|
+
test "description accessor for User class" do
|
186
188
|
assert_respond_to(@user, :description)
|
187
189
|
assert_respond_to(@user, :description=)
|
188
190
|
end
|
189
191
|
|
190
|
-
|
192
|
+
test "domain accessor for User class" do
|
191
193
|
assert_respond_to(@user, :domain)
|
192
194
|
assert_respond_to(@user, :domain=)
|
193
195
|
end
|
194
196
|
|
195
|
-
|
197
|
+
test "password accessor for User class" do
|
196
198
|
assert_respond_to(@user, :password)
|
197
199
|
assert_respond_to(@user, :password=)
|
198
200
|
end
|
199
201
|
|
200
|
-
|
202
|
+
test "full_name accessor for User class" do
|
201
203
|
assert_respond_to(@user, :full_name)
|
202
204
|
assert_respond_to(@user, :full_name=)
|
203
205
|
end
|
204
206
|
|
205
|
-
|
207
|
+
test "name accessor for User class" do
|
206
208
|
assert_respond_to(@user, :name)
|
207
209
|
assert_respond_to(@user, :name=)
|
208
210
|
end
|
209
211
|
|
210
|
-
|
212
|
+
test "sid accessor for User class" do
|
211
213
|
assert_respond_to(@user, :sid)
|
212
214
|
assert_respond_to(@user, :sid=)
|
213
215
|
end
|
214
216
|
|
215
|
-
|
217
|
+
test "status accessor for User class" do
|
216
218
|
assert_respond_to(@user, :status)
|
217
219
|
assert_respond_to(@user, :status=)
|
218
220
|
end
|
219
221
|
|
220
|
-
|
222
|
+
test "disabled accessor for User class" do
|
221
223
|
assert_respond_to(@user, :disabled?)
|
222
224
|
assert_respond_to(@user, :disabled=)
|
223
225
|
end
|
224
226
|
|
225
|
-
|
227
|
+
test "local accessor for User class" do
|
226
228
|
assert_respond_to(@user, :local?)
|
227
229
|
assert_respond_to(@user, :local=)
|
228
230
|
end
|
229
231
|
|
230
|
-
|
232
|
+
test "lockout accessor for User class" do
|
231
233
|
assert_respond_to(@user, :lockout?)
|
232
234
|
assert_respond_to(@user, :lockout=)
|
233
235
|
end
|
234
236
|
|
235
|
-
|
237
|
+
test "password_changeable accessor for User class" do
|
236
238
|
assert_respond_to(@user, :password_changeable?)
|
237
239
|
assert_respond_to(@user, :password_changeable=)
|
238
240
|
end
|
239
241
|
|
240
|
-
|
242
|
+
test "password_expires accessor for User class" do
|
241
243
|
assert_respond_to(@user, :password_expires?)
|
242
244
|
assert_respond_to(@user, :password_expires=)
|
243
245
|
end
|
244
246
|
|
245
|
-
|
247
|
+
test "password_required accessor for User class" do
|
246
248
|
assert_respond_to(@user, :password_required?)
|
247
249
|
assert_respond_to(@user, :password_required=)
|
248
250
|
end
|
249
251
|
|
250
|
-
|
252
|
+
test "account_type accessor for User class" do
|
251
253
|
assert_respond_to(@user, :account_type)
|
252
254
|
assert_respond_to(@user, :account_type=)
|
253
255
|
end
|
254
256
|
|
255
|
-
|
257
|
+
test "uid accessor for User class" do
|
256
258
|
assert_respond_to(@user, :uid)
|
257
259
|
assert_respond_to(@user, :uid=)
|
258
260
|
end
|
259
261
|
|
260
|
-
|
262
|
+
test "dir accessor for User class" do
|
261
263
|
assert_respond_to(@user, :dir)
|
262
264
|
assert_respond_to(@user, :dir=)
|
263
265
|
end
|
264
266
|
|
265
|
-
|
267
|
+
test "dir method returns either a string or nil" do
|
266
268
|
assert_nothing_raised{ @user = Admin.get_user(@user_name, :localaccount => true) }
|
267
269
|
assert_kind_of([String, NilClass], @user.dir)
|
268
270
|
end
|
269
271
|
|
270
272
|
# Group class
|
271
273
|
|
272
|
-
|
274
|
+
test "caption accessor for Group class" do
|
273
275
|
assert_respond_to(@group, :caption)
|
274
276
|
assert_respond_to(@group, :caption=)
|
275
277
|
end
|
276
278
|
|
277
|
-
|
279
|
+
test "description accessor for Group class" do
|
278
280
|
assert_respond_to(@group, :description)
|
279
281
|
assert_respond_to(@group, :description=)
|
280
282
|
end
|
281
283
|
|
282
|
-
|
284
|
+
test "domain accessor for Group class" do
|
283
285
|
assert_respond_to(@group, :domain)
|
284
286
|
assert_respond_to(@group, :domain=)
|
285
287
|
end
|
286
288
|
|
287
|
-
|
289
|
+
test "install_date accessor for Group class" do
|
288
290
|
assert_respond_to(@group, :install_date)
|
289
291
|
assert_respond_to(@group, :install_date=)
|
290
292
|
end
|
291
293
|
|
292
|
-
|
294
|
+
test "name accessor for Group class" do
|
293
295
|
assert_respond_to(@group, :name)
|
294
296
|
assert_respond_to(@group, :name)
|
295
297
|
end
|
296
298
|
|
297
|
-
|
299
|
+
test "gid accessor for Group class" do
|
298
300
|
assert_respond_to(@group, :gid)
|
299
301
|
assert_respond_to(@group, :gid=)
|
300
302
|
end
|
301
303
|
|
302
|
-
|
304
|
+
test "status accessor for Group class" do
|
303
305
|
assert_respond_to(@group, :status)
|
304
306
|
assert_respond_to(@group, :status=)
|
305
307
|
end
|
306
308
|
|
307
|
-
|
309
|
+
test "sid accessor for Group class" do
|
308
310
|
assert_respond_to(@group, :sid)
|
309
311
|
assert_respond_to(@group, :sid=)
|
310
312
|
end
|
311
313
|
|
312
|
-
|
314
|
+
test "sid_type accessor for Group class" do
|
313
315
|
assert_respond_to(@group, :sid_type)
|
314
316
|
assert_respond_to(@group, :sid_type=)
|
315
317
|
end
|
316
318
|
|
317
|
-
|
319
|
+
test "local accessor for Group class" do
|
318
320
|
assert_respond_to(@group, :local?)
|
319
321
|
assert_respond_to(@group, :local=)
|
320
322
|
end
|