sys-admin 1.5.0-x86-mswin32-60 → 1.5.1-x86-mswin32-60

Sign up to get free protection for your applications and to get access to all the features.
data/CHANGES CHANGED
@@ -1,3 +1,11 @@
1
+ == 1.5.1 - 23-Jul-2009
2
+ * Added the User#dir attribute. This attribute contains a user's home
3
+ directory if set, or nil if it isn't.
4
+ * User objects returned by the Admin.users method now include the uid.
5
+ Previously only the Admin.get_user method set it.
6
+ * Added win32-security as a dependency.
7
+ * Changed license to Artistic 2.0.
8
+
1
9
  == 1.5.0 - 29-Mar-2009
2
10
  * INTERFACE CHANGE (WINDOWS ONLY): The interface for MS Windows has undergone
3
11
  a radical change. Most methods now accept a hash of options that are
data/MANIFEST CHANGED
@@ -9,6 +9,6 @@
9
9
  * ext/admin.h
10
10
  * ext/extconf.rb
11
11
  * lib/sys/admin.rb
12
- * test/tc_admin.rb
13
- * test/tc_unix.rb
14
- * test/tc_windows.rb
12
+ * test/test_sys_admin.rb
13
+ * test/test_sys_admin_unix.rb
14
+ * test/test_sys_admin_windows.rb
data/README CHANGED
@@ -151,7 +151,7 @@ Admin::Error < StandardError
151
151
  page at http://www.rubyforge.org/projects/sysutils.
152
152
 
153
153
  == License
154
- Ruby's
154
+ Artistic 2.0
155
155
 
156
156
  == Copyright
157
157
  (C) 2005-2009, Daniel J. Berger
@@ -145,10 +145,10 @@ User#uid
145
145
  website at http://www.rubyforge.org/projects/sysutils.
146
146
 
147
147
  == License
148
- Ruby's
148
+ Artistic 2.0
149
149
 
150
150
  == Copyright
151
- Copyright 2002-2008, Daniel J. Berger
151
+ Copyright 2002-2009, 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.
@@ -226,6 +226,12 @@ User#description
226
226
 
227
227
  User#description=
228
228
  Sets the description of the account.
229
+
230
+ User#dir
231
+ Returns the user's home directory.
232
+
233
+ User#dir=
234
+ Sets the user's home directory.
229
235
 
230
236
  User#disabled?
231
237
  Returns whether or not the account is disabled.
@@ -311,10 +317,10 @@ User#status
311
317
  website at http://www.rubyforge.org/projects/sysutils.
312
318
 
313
319
  == License
314
- Ruby's
320
+ Artistic 2.0
315
321
 
316
322
  == Copyright
317
- Copyright 2002-2008, Daniel J. Berger
323
+ Copyright 2002-2009, Daniel J. Berger
318
324
 
319
325
  All Rights Reserved. This module is free software. It may be used,
320
326
  redistributed and/or modified under the same terms as Ruby itself.
data/lib/sys/admin.rb CHANGED
@@ -1,5 +1,6 @@
1
1
  require 'win32ole'
2
- require 'Win32API'
2
+ require 'win32/security'
3
+ require 'win32/registry'
3
4
  require 'socket'
4
5
 
5
6
  module Sys
@@ -151,6 +152,9 @@ module Sys
151
152
  # The user's id (RID).
152
153
  attr_accessor :uid
153
154
 
155
+ # The user's home directory
156
+ attr_accessor :dir
157
+
154
158
  # Used to set whether or not the account is disabled.
155
159
  attr_writer :disabled
156
160
 
@@ -192,17 +196,17 @@ module Sys
192
196
  def account_type=(type)
193
197
  case type
194
198
  when TEMP_DUPLICATE
195
- @account_type = "duplicate"
199
+ @account_type = 'duplicate'
196
200
  when NORMAL
197
- @account_type = "normal"
201
+ @account_type = 'normal'
198
202
  when INTERDOMAIN_TRUST
199
- @account_type = "interdomain_trust"
203
+ @account_type = 'interdomain_trust'
200
204
  when WORKSTATION_TRUST
201
- @account_type = "workstation_trust"
205
+ @account_type = 'workstation_trust'
202
206
  when SERVER_TRUST
203
- @account_type = "server_trust"
207
+ @account_type = 'server_trust'
204
208
  else
205
- @account_type = "unknown"
209
+ @account_type = 'unknown'
206
210
  end
207
211
  end
208
212
 
@@ -228,25 +232,25 @@ module Sys
228
232
  def sid_type=(stype)
229
233
  case stype
230
234
  when Admin::SidTypeUser
231
- @sid_type = "user"
235
+ @sid_type = 'user'
232
236
  when Admin::SidTypeGroup
233
- @sid_type = "group"
237
+ @sid_type = 'group'
234
238
  when Admin::SidTypeDomain
235
- @sid_type = "domain"
239
+ @sid_type = 'domain'
236
240
  when Admin::SidTypeAlias
237
- @sid_type = "alias"
241
+ @sid_type = 'alias'
238
242
  when Admin::SidTypeWellKnownGroup
239
- @sid_type = "well_known_group"
243
+ @sid_type = 'well_known_group'
240
244
  when Admin::SidTypeDeletedAccount
241
- @sid_type = "deleted_account"
245
+ @sid_type = 'deleted_account'
242
246
  when Admin::SidTypeInvalid
243
- @sid_type = "invalid"
247
+ @sid_type = 'invalid'
244
248
  when Admin::SidTypeUnknown
245
- @sid_type = "unknown"
249
+ @sid_type = 'unknown'
246
250
  when Admin::SidTypeComputer
247
- @sid_type = "computer"
251
+ @sid_type = 'computer'
248
252
  else
249
- @sid_type = "unknown"
253
+ @sid_type = 'unknown'
250
254
  end
251
255
  end
252
256
 
@@ -288,7 +292,7 @@ module Sys
288
292
  end
289
293
 
290
294
  class Admin
291
- VERSION = '1.5.0'
295
+ VERSION = '1.5.1'
292
296
 
293
297
  # This is the error raised in the majority of cases if anything goes wrong
294
298
  # with any of the Sys::Admin methods.
@@ -307,6 +311,33 @@ module Sys
307
311
 
308
312
  private
309
313
 
314
+ HKEY = "SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\ProfileList\\"
315
+
316
+ # Retrieves the user's home directory. For local accounts query the
317
+ # registry. For domain accounts use ADSI and use the HomeDirectory.
318
+ #
319
+ def self.get_home_dir(user, local = false, domain = nil)
320
+ if local
321
+ sec = Win32::Security::SID.open(user)
322
+ key = HKEY + sec.to_s
323
+ dir = nil
324
+
325
+ begin
326
+ Win32::Registry::HKEY_LOCAL_MACHINE.open(key) do |reg|
327
+ dir = reg['ProfileImagePath']
328
+ end
329
+ rescue Win32::Registry::Error
330
+ # Not every local user has a home directory
331
+ end
332
+ else
333
+ domain ||= Socket.gethostname
334
+ adsi = WIN32OLE.connect("WinNT://#{domain}/#{user},user")
335
+ dir = adsi.get('HomeDirectory')
336
+ end
337
+
338
+ dir
339
+ end
340
+
310
341
  # A private method that lower cases all keys, and converts them
311
342
  # all to symbols.
312
343
  #
@@ -342,7 +373,7 @@ module Sys
342
373
  end
343
374
 
344
375
  # Used by the get_login method
345
- GetUserName = Win32API.new('advapi32', 'GetUserName', 'PP', 'L') # :nodoc:
376
+ GetUserName = Win32::API.new('GetUserName', 'PP', 'L', 'advapi32') # :nodoc:
346
377
 
347
378
  public
348
379
 
@@ -677,6 +708,7 @@ module Sys
677
708
  u.status = user.status
678
709
  u.uid = uid
679
710
  u.groups = get_groups(domain, user.name)
711
+ u.dir = get_home_dir(user.name, options[:localaccount], domain)
680
712
  end
681
713
 
682
714
  return user_object
@@ -740,6 +772,8 @@ module Sys
740
772
  domain = options[:domain] || host
741
773
 
742
774
  wmi.execquery(query).each{ |user|
775
+ uid = user.sid.split('-').last.to_i
776
+
743
777
  usr = User.new do |u|
744
778
  u.account_type = user.accounttype
745
779
  u.caption = user.caption
@@ -758,6 +792,8 @@ module Sys
758
792
  u.sid_type = user.sidtype
759
793
  u.status = user.status
760
794
  u.groups = get_groups(domain, user.name)
795
+ u.uid = uid
796
+ u.dir = get_home_dir(user.name, options[:localaccount], host)
761
797
  end
762
798
 
763
799
  if block_given?
data/sys-admin.gemspec CHANGED
@@ -1,16 +1,17 @@
1
1
  require 'rubygems'
2
2
 
3
3
  spec = Gem::Specification.new do |gem|
4
- gem.name = 'sys-admin'
5
- gem.version = '1.5.0'
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" library.'
11
- gem.description = 'A unified, cross platform replacement for the "etc" library.'
12
- gem.test_file = 'test/test_sys_admin.rb'
13
- gem.has_rdoc = true
4
+ gem.name = 'sys-admin'
5
+ gem.version = '1.5.1'
6
+ gem.author = 'Daniel J. Berger'
7
+ gem.license = 'Artistic 2.0'
8
+ gem.email = 'djberg96@gmail.com'
9
+ gem.homepage = 'http://www.rubyforge.org/projects/sysutils'
10
+ gem.platform = Gem::Platform::RUBY
11
+ gem.summary = 'A unified, cross platform replacement for the "etc" library.'
12
+ gem.test_file = 'test/test_sys_admin.rb'
13
+ gem.has_rdoc = true
14
+
14
15
  gem.extra_rdoc_files = ['CHANGES', 'README', 'MANIFEST']
15
16
  gem.rubyforge_project = 'sysutils'
16
17
  gem.required_ruby_version = '>= 1.8.2'
@@ -31,8 +32,15 @@ spec = Gem::Specification.new do |gem|
31
32
  files.delete_if{ |item| item.include?('CVS') }
32
33
 
33
34
  gem.files = files
34
- end
35
35
 
36
- if $PROGRAM_NAME == __FILE__
37
- Gem::Builder.new(spec).build
36
+ gem.description = <<-EOF
37
+ The sys-admin library is a unified, cross platform replacement for the
38
+ 'etc' library that ships as part of the Ruby standard library. It
39
+ provides a common interface for all platforms, including MS Windows. In
40
+ addition, it provides an interface for adding, deleting and configuring
41
+ users on MS Windows.
42
+ EOF
38
43
  end
44
+
45
+ Gem.manage_gems if Gem::RubyGemsVersion.to_f < 1.0
46
+ Gem::Builder.new(spec).build
@@ -16,6 +16,6 @@ end
16
16
 
17
17
  class TC_Sys_Admin_All < Test::Unit::TestCase
18
18
  def test_version
19
- assert_equal('1.5.0', Sys::Admin::VERSION)
19
+ assert_equal('1.5.1', Sys::Admin::VERSION)
20
20
  end
21
21
  end
@@ -256,6 +256,16 @@ class TC_Sys_Admin_Win32 < Test::Unit::TestCase
256
256
  assert_respond_to(@user, :uid=)
257
257
  end
258
258
 
259
+ def test_user_dir_basic
260
+ assert_respond_to(@user, :dir)
261
+ assert_respond_to(@user, :dir=)
262
+ end
263
+
264
+ def test_user_dir
265
+ assert_nothing_raised{ Admin.get_user(@user_name, :localaccount => true) }
266
+ assert_kind_of(String, @user_name.dir)
267
+ end
268
+
259
269
  # Group class
260
270
 
261
271
  def test_group_instance_caption
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.5.0
4
+ version: 1.5.1
5
5
  platform: x86-mswin32-60
6
6
  authors:
7
7
  - Daniel J. Berger
@@ -9,11 +9,11 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2009-03-29 00:00:00 -06:00
12
+ date: 2009-07-23 00:00:00 -06:00
13
13
  default_executable:
14
14
  dependencies: []
15
15
 
16
- description: A unified, cross platform replacement for the "etc" library.
16
+ description: " The sys-admin library is a unified, cross platform replacement for the\n 'etc' library that ships as part of the Ruby standard library. It\n provides a common interface for all platforms, including MS Windows. In\n addition, it provides an interface for adding, deleting and configuring\n users on MS Windows.\n"
17
17
  email: djberg96@gmail.com
18
18
  executables: []
19
19
 
@@ -32,20 +32,15 @@ files:
32
32
  - test/test_sys_admin_unix.rb
33
33
  - test/test_sys_admin_windows.rb
34
34
  - CHANGES
35
- - doc
36
- - examples
37
- - ext
38
- - lib
39
35
  - MANIFEST
40
36
  - Rakefile
41
37
  - README
42
38
  - sys-admin.gemspec
43
- - test
44
39
  - lib/sys/admin.rb
45
40
  has_rdoc: true
46
41
  homepage: http://www.rubyforge.org/projects/sysutils
47
- licenses: []
48
-
42
+ licenses:
43
+ - Artistic 2.0
49
44
  post_install_message:
50
45
  rdoc_options: []
51
46
 
@@ -66,7 +61,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
66
61
  requirements: []
67
62
 
68
63
  rubyforge_project: sysutils
69
- rubygems_version: 1.3.1.2403
64
+ rubygems_version: 1.3.4
70
65
  signing_key:
71
66
  specification_version: 3
72
67
  summary: A unified, cross platform replacement for the "etc" library.