sys-admin 1.5.3-x86-mingw32

Sign up to get free protection for your applications and to get access to all the features.
data/CHANGES ADDED
@@ -0,0 +1,112 @@
1
+ == 1.5.3 - 6-Oct-2010
2
+ * Refactored the Rakefile. The old installation tasks have been replaced
3
+ with gem build and install tasks. In addition, the platform handling has
4
+ been updated for MS Windows.
5
+ * Portions of the gemspec have been moved into the Rakefile gem tasks.
6
+ * Deploying the mingw gem by default for MS Windows now.
7
+
8
+ == 1.5.2 - 2-Aug-2009
9
+ * Now compatible with Ruby 1.9.x.
10
+ * Added test-unit as a development dependency.
11
+
12
+ == 1.5.1 - 23-Jul-2009
13
+ * Added the User#dir attribute. This attribute contains a user's home
14
+ directory if set, or nil if it isn't.
15
+ * User objects returned by the Admin.users method now include the uid.
16
+ Previously only the Admin.get_user method set it.
17
+ * Added win32-security as a dependency.
18
+ * Changed license to Artistic 2.0.
19
+
20
+ == 1.5.0 - 29-Mar-2009
21
+ * INTERFACE CHANGE (WINDOWS ONLY): The interface for MS Windows has undergone
22
+ a radical change. Most methods now accept a hash of options that are
23
+ passed directly to the underlying WMI class. Please see the documentation
24
+ for details.
25
+ * Now works on various BSD flavors.
26
+ * Added the User#groups method. This returns an array of groups that the
27
+ user belongs to. Suggestion inspired by Gonzalo Garramuno.
28
+ * Added the Group#members method. The returns an array of users that the
29
+ group contains.
30
+ * Changed User#class to User#access_class for UNIX flavors to avoid
31
+ conflicts with the Ruby core Object method.
32
+ * Added more tests and renamed the test files.
33
+ * Removed an unnecessary function call where a platform might try to
34
+ get lastlog information even if the lastlog.h or utmp.h headers couldn't
35
+ be found.
36
+
37
+ == 1.4.4 - 19-Nov-2008
38
+ * Added the User#uid method for MS Windows (which is just the user's relative
39
+ identifier).
40
+ * Now requires test-unit 2.x.
41
+ * Some updates to the test suite to take advantage of test-unit 2.x features.
42
+ * Some minor gemspec tweaks.
43
+
44
+ == 1.4.3 - 2-Mar-2008
45
+ * The block form of Admin.users now properly ensures that endpwent() is
46
+ called. Likewise, the block form of Admin.groups now properly ensures
47
+ that endgrent() is called. This would only have been an issue if you
48
+ broke out of the block before it terminated.
49
+ * The AdminError class is now Admin::Error.
50
+ * Some internal directory layout changes.
51
+
52
+ == 1.4.2 - 26-Jun-2007
53
+ * Fixed a bug in the Admin.get_login method where it would return junk
54
+ if the underlying getlogin() function failed (Unix). Thanks go to Gonzalo
55
+ Garramuno for the spot. This bug also resulted in some refactoring of the
56
+ underlying C code.
57
+ * Removed the install.rb file. The logic in that file has been moved directly
58
+ into the Rakefile.
59
+
60
+ == 1.4.1 - 21-Mar-2007
61
+ * Bug fix for OS X. Thanks go to an anonymous user for the spot.
62
+ * Added a Rakefile. Building, testing and installing should now use the
63
+ Rake tasks (for non-gem installs).
64
+ * Much more inline documentation, especially for User and Group attributes.
65
+
66
+ == 1.4.0 - 20-Jan-2007
67
+ * Added the following methods: add_local_user, config_local_user,
68
+ delete_local_user, add_global_group, config_global_group, and
69
+ delete_global_group. MS Windows only at the moment.
70
+ * Added corresponding tests.
71
+ * Added much more inline documentation.
72
+ * Major refactoring of the get_lastlog_info helper function in admin.h. This
73
+ fixed a major bug in some flavors of Linux where the Admin.users method
74
+ could go into an infinite loop. It also fixed some minor bugs where console
75
+ and host values were sometimes filled with junk characters.
76
+ * Added the User#change attribute, and a check for the pw_change struct member
77
+ in the extconf.rb file.
78
+ * The User#expire attribute is now handled as a Time object instead of an
79
+ integer.
80
+ * Renamed tc_win32.rb to tc_windows.rb
81
+
82
+ == 1.3.1 - 29-Jun-2005
83
+ * Fixed a bug where the inability to read the lastlog file caused an error.
84
+ From now on that error is ignored, and the lastlog attributes of the User
85
+ object are set to nil.
86
+ * Added a beta version of Admin.delete_user (Windows only).
87
+
88
+ == 1.3.0 - 3-Jun-2005
89
+ * Bug fixes for Linux.
90
+ * Removed the version.h file - no longer needed since the Win32 version is
91
+ pure Ruby.
92
+
93
+ == 1.2.0 - 30-Apr-2005
94
+ * Replaced the Win32 version with a pure Ruby version that uses Win32API and
95
+ win32ole + WMI.
96
+ * The LocalGroup class no longer exists in the Win32 version. Instead, it is
97
+ now an attribute of a Group object. The issue was forced by WMI.
98
+ * The default for users and groups on Win32 systems is now local rather than
99
+ global. See the documentation for why you probably don't want to iterate
100
+ over global accounts.
101
+ * Corresponding doc changes and test suite changes.
102
+
103
+ == 1.1.0 - 1-Apr-2005
104
+ * Fixed bug where a segfault could occur when trying to retrieve a user or
105
+ group by an ID that didn't exist (Unix).
106
+ * Added tests for intentional failures.
107
+ * Added lastlog information tothe User class (Unix).
108
+ * Modified the way User objects are created internally (Unix).
109
+ * Fixed a bug in the User#shell attribute (Unix).
110
+
111
+ == 1.0.0 - 25-Mar-2005
112
+ * Initial release
data/MANIFEST ADDED
@@ -0,0 +1,14 @@
1
+ * sys-admin.gemspec
2
+ * CHANGES
3
+ * MANIFEST
4
+ * Rakefile
5
+ * README
6
+ * examples/groups.rb
7
+ * examples/users.rb
8
+ * ext/admin.c
9
+ * ext/admin.h
10
+ * ext/extconf.rb
11
+ * lib/sys/admin.rb
12
+ * test/test_sys_admin.rb
13
+ * test/test_sys_admin_unix.rb
14
+ * test/test_sys_admin_windows.rb
data/README ADDED
@@ -0,0 +1,156 @@
1
+ == Description
2
+ The sys-admin library is a unified, cross platform replacement for the Etc module.
3
+
4
+ == Installation
5
+ gem install sys-admin
6
+
7
+ == Synopsis
8
+ require 'sys/admin'
9
+ include Sys
10
+
11
+ # Yields a User object for each user
12
+ Admin.users{ |user|
13
+ p user
14
+ }
15
+
16
+ # Returns an Array of User objects
17
+ a = Admin.users
18
+
19
+ # Yields a Group object for each group
20
+ Admin.groups{ |group|
21
+ p group
22
+ }
23
+
24
+ # Returns an Array of Group objects
25
+ g = Admin.groups
26
+
27
+ # Get information about a particular user
28
+ p Admin.get_user("nobody")
29
+
30
+ # Get information about a particular group
31
+ p Admin.get_group("adm")
32
+
33
+ == Admin
34
+ Admin.get_login
35
+ Returns the user name (only) of the current login.
36
+
37
+ Admin.get_user(name, options = {})
38
+ Admin.get_user(uid, options = {})
39
+ Returns a User object based on +name+ or +uid+. The +options+ hash is
40
+ for MS Windows only, and allows you to restrict the search based on the
41
+ options you provide, e.g. 'domain' or 'localaccount'.
42
+
43
+ Admin.get_group(name, options = {})
44
+ Admin.get_group(gid, options = {})
45
+ Returns a Group object based on +name+ or +uid+. The +options+ hash is
46
+ for MS Windows only, and allows you to restrict the search based on the
47
+ options you provide, e.g. 'domain' or 'localaccount'.
48
+
49
+ Admin.groups(options = {})
50
+ Admin.groups(options = {}){ |group| ... }
51
+ In block form, yields a Group object for each user on the system. In
52
+ non-block form, returns an Array of Group objects.
53
+
54
+ The +options+ hash is for MS Windows only, and allows you to restrict the
55
+ search based on the options you provide, e.g. 'domain' or 'localaccount'.
56
+
57
+ Admin.users(options = {})
58
+ Admin.users(options = {}){ |user| ... }
59
+ In block form, yields a User object for each user on the system. In
60
+ non-block form, returns an Array of User objects.
61
+
62
+ The +options+ hash is for MS Windows only, and allows you to restrict the
63
+ search based on the options you provide, e.g. 'domain' or 'localaccount'.
64
+
65
+ == User class
66
+ === User (Windows)
67
+ The User class has the following attributes on MS Windows systems:
68
+
69
+ * account_type
70
+ * caption
71
+ * description
72
+ * domain
73
+ * password
74
+ * full_name
75
+ * install_date
76
+ * name
77
+ * sid
78
+ * status
79
+ * disabled?
80
+ * local?
81
+ * lockout?
82
+ * password_changeable?
83
+ * password_expires?
84
+ * password_required?
85
+
86
+ === User (Unix)
87
+ The User class has the following attributes on Unix systems:
88
+
89
+ * name
90
+ * passwd
91
+ * uid
92
+ * gid
93
+ * dir
94
+ * shell
95
+ * gecos
96
+ * quota
97
+ * age
98
+ * class
99
+ * comment
100
+ * change
101
+ * expire
102
+
103
+ == Group Classes
104
+ === Group (Windows)
105
+ The Group class has the following attributes on MS Windows systems:
106
+
107
+ * caption
108
+ * description
109
+ * domain
110
+ * install_date
111
+ * name
112
+ * sid
113
+ * status
114
+ * gid
115
+ * local?
116
+
117
+ === Group (Unix)
118
+ The Group class has the following attributes on Unix systems:
119
+
120
+ * name
121
+ * gid
122
+ * members
123
+ * passwd
124
+
125
+ == Error Classes
126
+ Admin::Error < StandardError
127
+ Raised if anything goes wrong with any of the above methods.
128
+
129
+ == Developer's Notes
130
+ === MS Windows
131
+ The Windows version now uses a win32ole + WMI approach to getting
132
+ information. This means that the WMI service must be running on the
133
+ target machine in order to work (which it is, by default).
134
+
135
+ === UNIX
136
+ The underlying implementation is similar to core Ruby's Etc implementation.
137
+ But, in addition to the different interface, I use the re-entrant version
138
+ of the appropriate functions when available.
139
+
140
+ == Future Plans
141
+ Make the User and Group objects comparable.
142
+ Add ability to add, configure and delete users on Unix platforms.
143
+
144
+ == Known Bugs
145
+ None that I'm aware of. If you find any, please log them on the project
146
+ page at http://www.rubyforge.org/projects/sysutils.
147
+
148
+ == License
149
+ Artistic 2.0
150
+
151
+ == Copyright
152
+ (C) 2005-2010, Daniel J. Berger
153
+ All Rights Reserved
154
+
155
+ == Author
156
+ Daniel J. Berger
data/Rakefile ADDED
@@ -0,0 +1,74 @@
1
+ require 'rake'
2
+ require 'rake/clean'
3
+ require 'rake/testtask'
4
+ require 'rbconfig'
5
+
6
+ WINDOWS = Config::CONFIG['host_os'] =~ /msdos|mswin|win32|mingw|cygwin/i
7
+
8
+ desc "Clean the build files for the sys-admin source for UNIX systems"
9
+ task :clean do
10
+ Dir['*.gem'].each{ |f| File.delete(f) } # Remove any .gem files
11
+ unless WINDOWS
12
+ Dir.chdir('ext') do
13
+ build_file = 'admin.' + Config::CONFIG['DLEXT']
14
+ sh 'make distclean' if File.exists?(build_file)
15
+ File.delete("sys/#{build_file}") if File.exists?("sys/#{build_file}")
16
+ end
17
+ end
18
+ end
19
+
20
+ desc "Build the sys-admin library on UNIX systems (but don't install it)"
21
+ task :build => [:clean] do
22
+ unless WINDOWS
23
+ Dir.chdir('ext') do
24
+ ruby 'extconf.rb'
25
+ sh 'make'
26
+ build_file = 'admin.' + Config::CONFIG['DLEXT']
27
+ FileUtils.cp(build_file, 'sys')
28
+ end
29
+ end
30
+ end
31
+
32
+ namespace :gem do
33
+ desc "Create a sys-admin gem file."
34
+ task :create => [:clean] do
35
+ spec = eval(IO.read('sys-admin.gemspec'))
36
+
37
+ if WINDOWS
38
+ spec.platform = Gem::Platform::CURRENT
39
+ spec.files = spec.files.reject{ |f| f.include?('ext') }
40
+ spec.add_dependency('win32-security', '>= 0.1.2')
41
+ else
42
+ spec.files = spec.files.reject{ |f| f.include?('lib') }
43
+ spec.extensions = ['ext/extconf.rb']
44
+ spec.extra_rdoc_files << 'ext/sys/admin.c'
45
+ end
46
+
47
+ Gem::Builder.new(spec).build
48
+ end
49
+
50
+ desc "Install the sys-admin gem."
51
+ task :install => [:create] do
52
+ gem = Dir['*.gem'].first
53
+ sh "gem install #{gem}"
54
+ end
55
+ end
56
+
57
+ desc "Run the test suite"
58
+ Rake::TestTask.new('test') do |t|
59
+ if WINDOWS
60
+ t.libs << 'lib'
61
+ else
62
+ task :test => :build
63
+ t.libs << 'ext'
64
+ t.libs.delete('lib')
65
+ end
66
+ t.libs << 'test'
67
+ t.test_files = FileList['test/test_sys_admin.rb']
68
+ end
69
+
70
+ task :test do
71
+ Rake.application[:clean].execute
72
+ end
73
+
74
+ task :default => :test
@@ -0,0 +1,164 @@
1
+ = Description
2
+ A unified, cross-platform replacement for the Etc module that allows you to
3
+ get information about users and groups.
4
+
5
+ = Synopsis
6
+ require 'sys/admin'
7
+ include Sys
8
+
9
+ Admin.get_login # -> 'djberge'
10
+ Admin.get_user('djberge') # -> Admin::User object
11
+ Admin.get_group(501) # -> Admin::Group object
12
+
13
+ # Iterate over all users
14
+ Admin.users do |usr|
15
+ p usr
16
+ end
17
+
18
+ # Iterate over all groups
19
+ Admin.groups do |grp|
20
+ p grp
21
+ end
22
+
23
+ = Constants
24
+
25
+ = Class Methods
26
+ == Sys::Admin
27
+ Admin.get_group(name)
28
+ Admin.get_group(gid)
29
+ Returns a Group object for the given name or gid. Raises an Admin::Error
30
+ if a group cannot be found for that name or GID.
31
+
32
+ Admin.get_login
33
+ Returns the login for the process. If this is called from a process that
34
+ has no controlling terminal, then it resorts to returning the "LOGNAME"
35
+ or "USER" environment variable. If neither of those is defined, then nil
36
+ is returned.
37
+
38
+ Note that this method will probably return the real user login, but may
39
+ return the effective user login. YMMV depending on your platform and how
40
+ the program is run.
41
+
42
+ Admin.get_user(name)
43
+ Admin.get_user(uid)
44
+ Returns a User object for the given name or uid. Raises an Admin::Error if
45
+ a user cannot be found for that name or user ID.
46
+
47
+ Admin.groups
48
+ Admin.groups{ |grp| ... }
49
+ In block form, yields a Group object for each group on the system. In
50
+ non-block form, returns an Array of Group objects.
51
+
52
+ Admin.users
53
+ Admin.users{ |grp| ... }
54
+ In block form, yields a User object for each group on the system. In
55
+ non-block form, returns an Array of User objects.
56
+
57
+ == Sys::Admin::Group
58
+ Group.new
59
+ Group.new{ |grp| ... }
60
+ Creates and returns a Group object, which encapsulates the information
61
+ typically found within an /etc/group entry, i.e. a struct group. If a
62
+ block is provided, yields the object back to the block.
63
+
64
+ At the moment this is only useful for MS Windows.
65
+
66
+ == Sys::Admin::User
67
+ User.new
68
+ User.new{ |usr| ... }
69
+ Creates and returns a User object, which encapsulates the information
70
+ typically found within an /etc/passwd entry, i.e. a struct passwd. If a
71
+ block is provided, yields the object back to the block.
72
+
73
+ At the moment this is only useful for MS Windows.
74
+
75
+ = Instance Methods
76
+ == Sys::Admin::Group
77
+ Group#gid
78
+ The group id.
79
+
80
+ Group#members
81
+ An array of users that are members of the group.
82
+
83
+ Group#name
84
+ The name of the group.
85
+
86
+ Group#passwd
87
+ The group password, if any.
88
+
89
+ == Sys::Admin::User
90
+ User#age
91
+ Used in the past for password aging. Deprecated in favor of /etc/shadow.
92
+
93
+ User#change
94
+ Next date a password change will be needed.
95
+
96
+ User#class
97
+ The user's access class.
98
+
99
+ User#comment
100
+ Another comment field. Rarely used.
101
+
102
+ User#dir
103
+ The absolute pathname of the user's home directory.
104
+
105
+ User#expire
106
+ Account expiration date.
107
+
108
+ User#gecos
109
+ A comment field. Rarely used.
110
+
111
+ User#gid
112
+ The user's primary group id.
113
+
114
+ User#login_device
115
+ The name of the terminal device the user last logged on with.
116
+
117
+ User#login_host
118
+ The hostname from which the user last logged in.
119
+
120
+ User#login_time
121
+ The last time the user logged in.
122
+
123
+ User#name
124
+ The user name associated with the account.
125
+
126
+ User#passwd
127
+ The user's encrypted password. Deprecated in favor of /etc/shadow.
128
+
129
+ User#quota
130
+ The user's alloted amount of disk space.
131
+
132
+ User#shell
133
+ The user's login shell.
134
+
135
+ User#uid
136
+ The user's user id.
137
+
138
+ == Notes
139
+ Not all platforms support all of the User members. The only ones that are
140
+ supported on all platforms are name, uid, gid, dir and shell. The rest
141
+ will simply return nil if they aren't supported.
142
+
143
+ == Known Bugs
144
+ None that I am aware of. Please log any bugs you find on the project
145
+ website at http://www.rubyforge.org/projects/sysutils.
146
+
147
+ == License
148
+ Artistic 2.0
149
+
150
+ == Copyright
151
+ Copyright 2002-2009, Daniel J. Berger
152
+
153
+ All Rights Reserved. This module is free software. It may be used,
154
+ redistributed and/or modified under the same terms as Ruby itself.
155
+
156
+ == Warranty
157
+ This library is provided "as is" and without any express or
158
+ implied warranties, including, without limitation, the implied
159
+ warranties of merchantability and fitness for a particular purpose.
160
+
161
+ == Author
162
+ Daniel J. Berger
163
+ djberg96 at nospam at gmail dot com
164
+ imperator on IRC (Freenode)