sys-admin 1.4.3-x86-mswin32-60 → 1.4.4-x86-mswin32-60

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.
data/CHANGES CHANGED
@@ -1,3 +1,10 @@
1
+ == 1.4.4 - 19-Nov-2008
2
+ * Added the User#uid method for MS Windows (which is just the user's relative
3
+ identifier).
4
+ * Now requires test-unit 2.x.
5
+ * Some updates to the test suite to take advantage of test-unit 2.x features.
6
+ * Some minor gemspec tweaks.
7
+
1
8
  == 1.4.3 - 2-Mar-2008
2
9
  * The block form of Admin.users now properly ensures that endpwent() is
3
10
  called. Likewise, the block form of Admin.groups now properly ensures
@@ -148,13 +148,13 @@ User#uid
148
148
  Ruby's
149
149
 
150
150
  == Copyright
151
- Copyright 2002-2007, Daniel J. Berger
151
+ Copyright 2002-2008, Daniel J. Berger
152
152
 
153
153
  All Rights Reserved. This module is free software. It may be used,
154
154
  redistributed and/or modified under the same terms as Ruby itself.
155
155
 
156
156
  == Warranty
157
- This package is provided "as is" and without any express or
157
+ This library is provided "as is" and without any express or
158
158
  implied warranties, including, without limitation, the implied
159
159
  warranties of merchantability and fitness for a particular purpose.
160
160
 
@@ -23,7 +23,7 @@ get information about users and groups.
23
23
  = Constants
24
24
  == Sys::Admin
25
25
  VERSION
26
- The version of this package, returned as a String.
26
+ The version of this library, returned as a String.
27
27
 
28
28
  == Sys::Admin::User
29
29
  TEMP_DUPLICATE
@@ -314,13 +314,13 @@ User#status
314
314
  Ruby's
315
315
 
316
316
  == Copyright
317
- Copyright 2002-2007, Daniel J. Berger
317
+ Copyright 2002-2008, Daniel J. Berger
318
318
 
319
319
  All Rights Reserved. This module is free software. It may be used,
320
320
  redistributed and/or modified under the same terms as Ruby itself.
321
321
 
322
322
  == Warranty
323
- This package is provided "as is" and without any express or
323
+ This library is provided "as is" and without any express or
324
324
  implied warranties, including, without limitation, the implied
325
325
  warranties of merchantability and fitness for a particular purpose.
326
326
 
data/lib/sys/admin.rb CHANGED
@@ -1,6 +1,6 @@
1
- require "win32ole"
2
- require "Win32API"
3
- require "socket"
1
+ require 'win32ole'
2
+ require 'Win32API'
3
+ require 'socket'
4
4
 
5
5
  module Sys
6
6
  class Group
@@ -142,6 +142,9 @@ module Sys
142
142
  # Current status for the user, such as "ok", "error", etc.
143
143
  attr_accessor :status
144
144
 
145
+ # The user's id (RID).
146
+ attr_accessor :uid
147
+
145
148
  # Used to set whether or not the account is disabled.
146
149
  attr_writer :disabled
147
150
 
@@ -279,14 +282,13 @@ module Sys
279
282
  end
280
283
 
281
284
  class Admin
282
- VERSION = '1.4.3'
285
+ VERSION = '1.4.4'
283
286
 
284
287
  # This is the error raised in the majority of cases if anything goes wrong
285
288
  # with any of the Sys::Admin methods.
286
289
  #
287
290
  class Error < StandardError; end
288
-
289
-
291
+
290
292
  SidTypeUser = 1
291
293
  SidTypeGroup = 2
292
294
  SidTypeDomain = 3
@@ -296,10 +298,14 @@ module Sys
296
298
  SidTypeInvalid = 7
297
299
  SidTypeUnknown = 8
298
300
  SidTypeComputer = 9
301
+
302
+ private
299
303
 
300
304
  # Used by the get_login method
301
305
  GetUserName = Win32API.new('advapi32', 'GetUserName', 'PP', 'L') # :nodoc:
302
-
306
+
307
+ public
308
+
303
309
  # Configures the global +user+ on +domain+ using options.
304
310
  #
305
311
  # See http://tinyurl.com/3hjv9 for a list of valid options.
@@ -468,7 +474,7 @@ module Sys
468
474
  raise Error, 'GetUserName() call failed in get_login'
469
475
  end
470
476
 
471
- length = nsize.unpack("L")[0]
477
+ length = nsize.unpack('L')[0]
472
478
  username = buffer[0 ... length].chop
473
479
  username
474
480
  end
@@ -483,7 +489,7 @@ module Sys
483
489
  # default is the local machine. You may also specify whether to
484
490
  # retrieve a local or global account. The default is local.
485
491
  #
486
- def self.get_user(uid, host=Socket.gethostname, local=true)
492
+ def self.get_user(usr, host=Socket.gethostname, local=true)
487
493
  host = Socket.gethostname if host.nil?
488
494
  cs = "winmgmts:{impersonationLevel=impersonate}!"
489
495
  cs << "//#{host}/root/cimv2"
@@ -497,29 +503,30 @@ module Sys
497
503
  query = "select * from win32_useraccount"
498
504
  query << " where localaccount = true" if local
499
505
 
500
- if uid.kind_of?(Fixnum)
506
+ if usr.kind_of?(Fixnum)
501
507
  if local
502
- query << " and sid like '%-#{uid}'"
508
+ query << " and sid like '%-#{usr}'"
503
509
  else
504
- query << " where sid like '%-#{uid}'"
510
+ query << " where sid like '%-#{usr}'"
505
511
  end
506
512
  else
507
513
  if local
508
- query << " and name = '#{uid}'"
514
+ query << " and name = '#{usr}'"
509
515
  else
510
- query << " where name = '#{uid}'"
516
+ query << " where name = '#{usr}'"
511
517
  end
512
518
  end
513
519
 
514
520
  wmi.execquery(query).each{ |user|
521
+ uid = user.sid.split('-').last.to_i
522
+
515
523
  # Because our 'like' query isn't fulproof, let's parse
516
524
  # the SID again to make sure
517
- if uid.kind_of?(Fixnum)
518
- if user.sid.split("-").last.to_i != uid
519
- next
520
- end
525
+ if usr.kind_of?(Fixnum)
526
+ next if usr != uid
521
527
  end
522
- usr = User.new do |u|
528
+
529
+ user_object = User.new do |u|
523
530
  u.account_type = user.accounttype
524
531
  u.caption = user.caption
525
532
  u.description = user.description
@@ -536,9 +543,14 @@ module Sys
536
543
  u.sid = user.sid
537
544
  u.sid_type = user.sidtype
538
545
  u.status = user.status
546
+ u.uid = uid
539
547
  end
540
- return usr
548
+
549
+ return user_object
541
550
  }
551
+
552
+ # If we're here, it means it wasn't found.
553
+ raise Error, "no user found for '#{usr}'"
542
554
  end
543
555
 
544
556
  # In block form, yields a User object for each user on the system. In
@@ -644,7 +656,7 @@ module Sys
644
656
  next if grp != gid
645
657
  end
646
658
 
647
- grp = Group.new do |g|
659
+ group_object = Group.new do |g|
648
660
  g.caption = group.caption
649
661
  g.description = group.description
650
662
  g.domain = group.domain
@@ -656,8 +668,10 @@ module Sys
656
668
  g.sid_type = group.sidtype
657
669
  g.status = group.status
658
670
  end
659
- return grp
671
+
672
+ return group_object
660
673
  }
674
+
661
675
  # If we're here, it means it wasn't found.
662
676
  raise Error, "no group found for '#{grp}'"
663
677
  end
data/sys-admin.gemspec CHANGED
@@ -2,27 +2,27 @@ require 'rubygems'
2
2
 
3
3
  spec = Gem::Specification.new do |gem|
4
4
  gem.name = 'sys-admin'
5
- gem.version = '1.4.3'
5
+ gem.version = '1.4.4'
6
6
  gem.author = 'Daniel J. Berger'
7
7
  gem.email = 'djberg96@gmail.com'
8
8
  gem.homepage = 'http://www.rubyforge.org/projects/sysutils'
9
- gem.platform = Gem::Platform::CURRENT
9
+ gem.platform = Gem::Platform::RUBY
10
10
  gem.summary = 'A unified, cross platform replacement for the "etc" package.'
11
11
  gem.description = 'A unified, cross platform replacement for the "etc" package.'
12
12
  gem.test_file = 'test/tc_admin.rb'
13
13
  gem.has_rdoc = true
14
14
  gem.extra_rdoc_files = ['CHANGES', 'README', 'MANIFEST']
15
15
  gem.rubyforge_project = 'sysutils'
16
+ gem.required_ruby_version = '>= 1.8.2'
16
17
 
17
18
  files = Dir["doc/*"] + Dir["examples/*"]
18
19
  files += Dir["test/*"] + Dir["[A-Z]*"]
19
20
 
20
- if RUBY_PLATFORM.match('mswin')
21
+ if Config::CONFIG['host_os'].match('mswin')
21
22
  files += Dir["lib/sys/admin.rb"]
22
- gem.required_ruby_version = '>= 1.8.2'
23
+ gem.platform = Gem::Platform::CURRENT
23
24
  else
24
- files += Dir["ext/**/*"]
25
- gem.required_ruby_version = '>= 1.8.0'
25
+ files += Dir["ext/**/*.{c,h}"]
26
26
  gem.extensions = ['ext/extconf.rb']
27
27
  gem.extra_rdoc_files << 'ext/sys/admin.c'
28
28
  gem.require_path = 'lib'
@@ -34,6 +34,5 @@ spec = Gem::Specification.new do |gem|
34
34
  end
35
35
 
36
36
  if $PROGRAM_NAME == __FILE__
37
- Gem.manage_gems
38
37
  Gem::Builder.new(spec).build
39
38
  end
data/test/tc_admin.rb CHANGED
@@ -5,10 +5,10 @@
5
5
  # test suite based on the platform.
6
6
  ###############################################################################
7
7
  $LOAD_PATH.unshift Dir.pwd
8
- $LOAD_PATH.unshift Dir.pwd + "/test"
8
+ $LOAD_PATH.unshift File.join(Dir.pwd, 'test')
9
9
 
10
10
  if File::ALT_SEPARATOR
11
- require "tc_windows"
11
+ require 'tc_windows'
12
12
  else
13
- require "tc_unix"
13
+ require 'tc_unix'
14
14
  end
data/test/tc_unix.rb CHANGED
@@ -17,7 +17,7 @@ class TC_Sys_Admin_Unix < Test::Unit::TestCase
17
17
  end
18
18
 
19
19
  def test_version
20
- assert_equal('1.4.3', Admin::VERSION)
20
+ assert_equal('1.4.4', Admin::VERSION)
21
21
  end
22
22
 
23
23
  def test_get_login
data/test/tc_windows.rb CHANGED
@@ -7,29 +7,35 @@
7
7
  #
8
8
  # It is assumed that this test will be run via the 'rake test' task.
9
9
  ###############################################################################
10
- require "test/unit"
11
- require "sys/admin"
12
- require "socket"
10
+ require 'rubygems'
11
+ gem 'test-unit'
12
+
13
+ require 'test/unit'
14
+ require 'sys/admin'
15
+ require 'socket'
13
16
  include Sys
14
17
 
15
18
  class TC_Sys_Admin_Win32 < Test::Unit::TestCase
19
+ def self.startup
20
+ @@host = Socket.gethostname
21
+ end
22
+
16
23
  def setup
17
- @host = Socket.gethostname
18
- @user = User.new
19
- @user_name = "guest"
20
- @user_id = 501 # best guess, may fail
21
- @group = Group.new
22
- @group_name = "guests"
23
- @group_id = 546 # best guess, may fail
24
+ @user = User.new
25
+ @user_name = 'guest'
26
+ @user_id = 501 # best guess, may fail
27
+ @group = Group.new
28
+ @group_name = 'guests'
29
+ @group_id = 546 # best guess, may fail
24
30
  end
25
31
 
26
32
  def test_version
27
- assert_equal('1.4.3', Admin::VERSION)
33
+ assert_equal('1.4.4', Admin::VERSION)
28
34
  end
29
35
 
30
36
  def test_01_add_local_user
31
37
  assert_respond_to(Admin, :add_local_user)
32
- assert_nothing_raised{ Admin.add_local_user("foo") }
38
+ assert_nothing_raised{ Admin.add_local_user('foo') }
33
39
  end
34
40
 
35
41
  def test_add_global_user
@@ -39,7 +45,7 @@ class TC_Sys_Admin_Win32 < Test::Unit::TestCase
39
45
  def test_02_config_local_user
40
46
  assert_respond_to(Admin, :config_local_user)
41
47
  assert_nothing_raised{
42
- Admin.config_local_user("foo",{
48
+ Admin.config_local_user("foo", {
43
49
  :description => "delete me",
44
50
  :fullname => "fubar"
45
51
  })
@@ -71,7 +77,7 @@ class TC_Sys_Admin_Win32 < Test::Unit::TestCase
71
77
  def test_02_config_local_group
72
78
  assert_respond_to(Admin, :config_local_group)
73
79
  assert_nothing_raised{
74
- Admin.config_local_group("bar",{:description=>"delete me"})
80
+ Admin.config_local_group('bar', {:description => 'delete me'})
75
81
  }
76
82
  end
77
83
 
@@ -107,10 +113,10 @@ class TC_Sys_Admin_Win32 < Test::Unit::TestCase
107
113
  end
108
114
 
109
115
  def test_get_user_remote
110
- assert_nothing_raised{ Admin.get_user(@user_name, @host) }
111
- assert_nothing_raised{ Admin.get_user(@user_id, @host) }
112
- assert_kind_of(User, Admin.get_user(@user_name, @host))
113
- assert_kind_of(User, Admin.get_user(@user_id, @host))
116
+ assert_nothing_raised{ Admin.get_user(@user_name, @@host) }
117
+ assert_nothing_raised{ Admin.get_user(@user_id, @@host) }
118
+ assert_kind_of(User, Admin.get_user(@user_name, @@host))
119
+ assert_kind_of(User, Admin.get_user(@user_id, @@host))
114
120
  end
115
121
 
116
122
  def test_users
@@ -127,8 +133,8 @@ class TC_Sys_Admin_Win32 < Test::Unit::TestCase
127
133
  end
128
134
 
129
135
  def test_users_remote
130
- assert_nothing_raised{ Admin.users(@host) }
131
- assert_nothing_raised{ Admin.users(@host){ |u| } }
136
+ assert_nothing_raised{ Admin.users(@@host) }
137
+ assert_nothing_raised{ Admin.users(@@host){ |u| } }
132
138
  end
133
139
 
134
140
  def test_user_instance_caption
@@ -205,6 +211,11 @@ class TC_Sys_Admin_Win32 < Test::Unit::TestCase
205
211
  assert_respond_to(@user, :account_type)
206
212
  assert_respond_to(@user, :account_type=)
207
213
  end
214
+
215
+ def test_user_instance_uid
216
+ assert_respond_to(@user, :uid)
217
+ assert_respond_to(@user, :uid=)
218
+ end
208
219
 
209
220
  def test_get_group
210
221
  assert_respond_to(Admin, :get_group)
@@ -219,8 +230,8 @@ class TC_Sys_Admin_Win32 < Test::Unit::TestCase
219
230
  end
220
231
 
221
232
  def test_get_group_remote
222
- assert_nothing_raised{ Admin.get_group(@group_name, @host) }
223
- assert_kind_of(Group, Admin.get_group(@group_name, @host))
233
+ assert_nothing_raised{ Admin.get_group(@group_name, @@host) }
234
+ assert_kind_of(Group, Admin.get_group(@group_name, @@host))
224
235
  end
225
236
 
226
237
  def test_groups
@@ -235,10 +246,10 @@ class TC_Sys_Admin_Win32 < Test::Unit::TestCase
235
246
  end
236
247
 
237
248
  def test_groups_remote
238
- assert_nothing_raised{ Admin.groups(@host) }
239
- assert_nothing_raised{ Admin.groups(@host){ |g| } }
240
- assert_kind_of(Array, Admin.groups(@host))
241
- assert_kind_of(Group, Admin.groups(@host).first)
249
+ assert_nothing_raised{ Admin.groups(@@host) }
250
+ assert_nothing_raised{ Admin.groups(@@host){ |g| } }
251
+ assert_kind_of(Array, Admin.groups(@@host))
252
+ assert_kind_of(Group, Admin.groups(@@host).first)
242
253
  end
243
254
 
244
255
  def test_group_instance_caption
@@ -292,7 +303,6 @@ class TC_Sys_Admin_Win32 < Test::Unit::TestCase
292
303
  end
293
304
 
294
305
  def teardown
295
- @host = nil
296
306
  @user = nil
297
307
  @user_name = nil
298
308
  @user_id = nil
@@ -300,4 +310,8 @@ class TC_Sys_Admin_Win32 < Test::Unit::TestCase
300
310
  @group_name = nil
301
311
  @group_id = nil
302
312
  end
313
+
314
+ def self.shutdown
315
+ @@host = nil
316
+ end
303
317
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sys-admin
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.4.3
4
+ version: 1.4.4
5
5
  platform: x86-mswin32-60
6
6
  authors:
7
7
  - Daniel J. Berger
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2008-03-02 00:00:00 -07:00
12
+ date: 2008-11-19 00:00:00 -07:00
13
13
  default_executable:
14
14
  dependencies: []
15
15
 
@@ -39,10 +39,7 @@ files:
39
39
  - MANIFEST
40
40
  - Rakefile
41
41
  - README
42
- - sys-admin-1.4.0-x86-mswin32-60.gem
43
- - sys-admin-1.4.3.gem
44
42
  - sys-admin.gemspec
45
- - sys-admin.gemspec~
46
43
  - test
47
44
  - lib/sys/admin.rb
48
45
  has_rdoc: true
@@ -67,7 +64,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
67
64
  requirements: []
68
65
 
69
66
  rubyforge_project: sysutils
70
- rubygems_version: 1.0.1
67
+ rubygems_version: 1.3.1
71
68
  signing_key:
72
69
  specification_version: 2
73
70
  summary: A unified, cross platform replacement for the "etc" package.
Binary file
data/sys-admin-1.4.3.gem DELETED
Binary file
data/sys-admin.gemspec~ DELETED
@@ -1,39 +0,0 @@
1
- require 'rubygems'
2
-
3
- spec = Gem::Specification.new do |gem|
4
- gem.name = 'sys-admin'
5
- gem.version = '1.4.3'
6
- gem.author = 'Daniel J. Berger'
7
- gem.email = 'djberg96@gmail.com'
8
- gem.homepage = 'http://www.rubyforge.org/projects/sysutils'
9
- gem.platform = Gem::Platform::RUBY
10
- gem.summary = 'A unified, cross platform replacement for the "etc" package.'
11
- gem.description = 'A unified, cross platform replacement for the "etc" package.'
12
- gem.test_file = 'test/tc_admin.rb'
13
- gem.has_rdoc = true
14
- gem.extra_rdoc_files = ['CHANGES', 'README', 'MANIFEST']
15
- gem.rubyforge_project = 'sysutils'
16
-
17
- files = Dir["doc/*"] + Dir["examples/*"]
18
- files += Dir["test/*"] + Dir["[A-Z]*"]
19
-
20
- if RUBY_PLATFORM.match('mswin')
21
- files += Dir["lib/sys/admin.rb"]
22
- gem.required_ruby_version = '>= 1.8.2'
23
- else
24
- files += Dir["ext/**/*"]
25
- gem.required_ruby_version = '>= 1.8.0'
26
- gem.extensions = ['ext/extconf.rb']
27
- gem.extra_rdoc_files << 'ext/sys/admin.c'
28
- gem.require_path = 'lib'
29
- end
30
-
31
- files.delete_if{ |item| item.include?('CVS') }
32
-
33
- gem.files = files
34
- end
35
-
36
- if $PROGRAM_NAME == __FILE__
37
- Gem.manage_gems
38
- Gem::Builder.new(spec).build
39
- end