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.
@@ -34,7 +34,7 @@ module Sys
34
34
  public
35
35
 
36
36
  # The version of the sys-admin library.
37
- VERSION = '1.6.1'
37
+ VERSION = '1.6.2'
38
38
 
39
39
  # Error typically raised if any of the Sys::Admin methods fail.
40
40
  class Error < StandardError; end
@@ -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
- case type
200
- when TEMP_DUPLICATE
201
- @account_type = 'duplicate'
202
- when NORMAL
203
- @account_type = 'normal'
204
- when INTERDOMAIN_TRUST
205
- @account_type = 'interdomain_trust'
206
- when WORKSTATION_TRUST
207
- @account_type = 'workstation_trust'
208
- when SERVER_TRUST
209
- @account_type = 'server_trust'
210
- else
211
- @account_type = 'unknown'
212
- end
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
- @sid_type
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
- case stype
236
- when Admin::SidTypeUser
237
- @sid_type = 'user'
238
- when Admin::SidTypeGroup
239
- @sid_type = 'group'
240
- when Admin::SidTypeDomain
241
- @sid_type = 'domain'
242
- when Admin::SidTypeAlias
243
- @sid_type = 'alias'
244
- when Admin::SidTypeWellKnownGroup
245
- @sid_type = 'well_known_group'
246
- when Admin::SidTypeDeletedAccount
247
- @sid_type = 'deleted_account'
248
- when Admin::SidTypeInvalid
249
- @sid_type = 'invalid'
250
- when Admin::SidTypeUnknown
251
- @sid_type = 'unknown'
252
- when Admin::SidTypeComputer
253
- @sid_type = 'computer'
254
- else
255
- @sid_type = 'unknown'
256
- end
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
- @disabled
265
+ @disabled
263
266
  end
264
267
 
265
268
  # Returns whether or not the account is local.
266
269
  #
267
270
  def local?
268
- @local
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
- @lockout
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
- @password_changeable
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
- @password_expires
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
- @password_required
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.1'
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.groups = get_groups(domain, user.name)
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.1'
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'
@@ -14,6 +14,6 @@ end
14
14
 
15
15
  class TC_Sys_Admin_All < Test::Unit::TestCase
16
16
  test "version is set to expected value" do
17
- assert_equal('1.6.1', Sys::Admin::VERSION)
17
+ assert_equal('1.6.2', Sys::Admin::VERSION)
18
18
  end
19
19
  end
@@ -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
- def test_get_login_basic
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
- def test_get_login
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
- def test_get_login_expected_errors
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
- def test_get_user_basic
106
+ test "get_user basic functionality" do
106
107
  assert_respond_to(Admin, :get_user)
107
108
  end
108
109
 
109
- def test_get_user_by_string
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
- def test_get_user_by_uid
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
- def test_get_user_by_string_with_options
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
- def test_get_user_by_uid_with_options
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
- def test_get_user_expected_errors
132
+ test "get_user method requires an argument" do
132
133
  assert_raises(ArgumentError){ Admin.get_user }
133
134
  end
134
135
 
135
- def test_users_basic
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
- def test_users
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
- def test_get_group_basic
146
+ test "get_group basic functionality" do
146
147
  assert_respond_to(Admin, :get_group)
147
148
  end
148
149
 
149
- def test_get_group_by_name
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
- def test_get_group_by_gid
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
- def test_get_group_with_options
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
- def test_get_group_expected_errors
166
+ test "get_group method requires an argument" do
165
167
  assert_raise(ArgumentError){ Admin.get_group }
166
168
  end
167
169
 
168
- def test_groups_basic
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
- def test_groups
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
- def test_user_instance_caption
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
- def test_user_instance_description
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
- def test_user_instance_domain
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
- def test_user_instance_password
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
- def test_user_instance_full_name
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
- def test_user_instance_name
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
- def test_user_instance_sid
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
- def test_user_instance_status
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
- def test_user_instance_disabled
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
- def test_user_instance_local
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
- def test_user_instance_lockout
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
- def test_user_instance_password_changeable
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
- def test_user_instance_password_expires
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
- def test_user_instance_password_required
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
- def test_user_instance_account_type
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
- def test_user_instance_uid
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
- def test_user_dir_basic
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
- def test_user_dir
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
- def test_group_instance_caption
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
- def test_group_instance_description
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
- def test_group_instance_domain
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
- def test_group_instance_install_date
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
- def test_group_instance_name
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
- def test_group_instance_gid
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
- def test_group_instance_status
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
- def test_group_instance_sid
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
- def test_group_instance_sid_type
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
- def test_group_instance_local
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