sys-admin 1.4.3-x86-mswin32-60

Sign up to get free protection for your applications and to get access to all the features.
data/CHANGES ADDED
@@ -0,0 +1,69 @@
1
+ == 1.4.3 - 2-Mar-2008
2
+ * The block form of Admin.users now properly ensures that endpwent() is
3
+ called. Likewise, the block form of Admin.groups now properly ensures
4
+ that endgrent() is called. This would only have been an issue if you
5
+ broke out of the block before it terminated.
6
+ * The AdminError class is now Admin::Error.
7
+ * Some internal directory layout changes.
8
+
9
+ == 1.4.2 - 26-Jun-2007
10
+ * Fixed a bug in the Admin.get_login method where it would return junk
11
+ if the underlying getlogin() function failed (Unix). Thanks go to Gonzalo
12
+ Garramuno for the spot. This bug also resulted in some refactoring of the
13
+ underlying C code.
14
+ * Removed the install.rb file. The logic in that file has been moved directly
15
+ into the Rakefile.
16
+
17
+ == 1.4.1 - 21-Mar-2007
18
+ * Bug fix for OS X. Thanks go to an anonymous user for the spot.
19
+ * Added a Rakefile. Building, testing and installing should now use the
20
+ Rake tasks (for non-gem installs).
21
+ * Much more inline documentation, especially for User and Group attributes.
22
+
23
+ == 1.4.0 - 20-Jan-2007
24
+ * Added the following methods: add_local_user, config_local_user,
25
+ delete_local_user, add_global_group, config_global_group, and
26
+ delete_global_group. MS Windows only at the moment.
27
+ * Added corresponding tests.
28
+ * Added much more inline documentation.
29
+ * Major refactoring of the get_lastlog_info helper function in admin.h. This
30
+ fixed a major bug in some flavors of Linux where the Admin.users method
31
+ could go into an infinite loop. It also fixed some minor bugs where console
32
+ and host values were sometimes filled with junk characters.
33
+ * Added the User#change attribute, and a check for the pw_change struct member
34
+ in the extconf.rb file.
35
+ * The User#expire attribute is now handled as a Time object instead of an
36
+ integer.
37
+ * Renamed tc_win32.rb to tc_windows.rb
38
+
39
+ == 1.3.1 - 29-Jun-2005
40
+ * Fixed a bug where the inability to read the lastlog file caused an error.
41
+ From now on that error is ignored, and the lastlog attributes of the User
42
+ object are set to nil.
43
+ * Added a beta version of Admin.delete_user (Windows only).
44
+
45
+ == 1.3.0 - 3-Jun-2005
46
+ * Bug fixes for Linux.
47
+ * Removed the version.h file - no longer needed since the Win32 version is
48
+ pure Ruby.
49
+
50
+ == 1.2.0 - 30-Apr-2005
51
+ * Replaced the Win32 version with a pure Ruby version that uses Win32API and
52
+ win32ole + WMI.
53
+ * The LocalGroup class no longer exists in the Win32 version. Instead, it is
54
+ now an attribute of a Group object. The issue was forced by WMI.
55
+ * The default for users and groups on Win32 systems is now local rather than
56
+ global. See the documentation for why you probably don't want to iterate
57
+ over global accounts.
58
+ * Corresponding doc changes and test suite changes.
59
+
60
+ == 1.1.0 - 1-Apr-2005
61
+ * Fixed bug where a segfault could occur when trying to retrieve a user or
62
+ group by an ID that didn't exist (Unix).
63
+ * Added tests for intentional failures.
64
+ * Added lastlog information tothe User class (Unix).
65
+ * Modified the way User objects are created internally (Unix).
66
+ * Fixed a bug in the User#shell attribute (Unix).
67
+
68
+ == 1.0.0 - 25-Mar-2005
69
+ * Initial release
@@ -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/tc_admin.rb
13
+ * test/tc_unix.rb
14
+ * test/tc_windows.rb
data/README ADDED
@@ -0,0 +1,185 @@
1
+ == Description
2
+ The sys-admin package is a unified, cross platform replacement for the
3
+ Etc module.
4
+
5
+ == Installation
6
+ rake test (optional)
7
+ rake install
8
+
9
+ == Synopsis
10
+ require 'sys/admin'
11
+ include Sys
12
+
13
+ # Yields a User object for each user
14
+ Admin.users{ |user|
15
+ p user
16
+ }
17
+
18
+ # Returns an Array of User objects
19
+ a = Admin.users
20
+
21
+ # Yields a Group object for each group
22
+ Admin.groups{ |group|
23
+ p group
24
+ }
25
+
26
+ # Returns an Array of Group objects
27
+ g = Admin.groups
28
+
29
+ # Get information about a particular user
30
+ p Admin.get_user("nobody")
31
+
32
+ # Get information about a particular group
33
+ p Admin.get_group("adm")
34
+
35
+ == Admin
36
+ Admin.get_login
37
+ Returns the user name (only) of the current login.
38
+
39
+ Admin.get_user(name, host=localhost)
40
+ Admin.get_user(uid, host=localhost, local=true)
41
+ Returns a User object based on +name+ or +uid+.
42
+
43
+ Windows only: you may specify a host from which information is retrieved.
44
+ The default is the local machine. You may also specify whether to
45
+ retrieve a local or global account. The default is local.
46
+
47
+ Admin.get_group(name, host=localhost, local=true)
48
+ Admin.get_group(gid, host=localhost, local=true)
49
+ Returns a Group object based on +name+ or +uid+.
50
+
51
+ Windows only: you may specify a host from which information is retrieved.
52
+ The default is the local machine. You can retrieve either a global or
53
+ local group, depending on the value of the +local+ argument.
54
+
55
+ Admin.groups(host=localhost, local=true)
56
+ Admin.groups(host=localhost, local=true){ |group| ... }
57
+ In block form, yields a Group object for each user on the system. In
58
+ non-block form, returns an Array of Group objects.
59
+
60
+ Windows only: you may specify a host from which information is retrieved.
61
+ The default is the local machine. You can retrieve either a global or
62
+ local group, depending on the value of the +local+ argument.
63
+
64
+ Admin.users(host=localhost, local=true)
65
+ Admin.users(host=localhost, local=true){ |user| ... }
66
+ In block form, yields a User object for each user on the system. In
67
+ non-block form, returns an Array of User objects.
68
+
69
+ Windows only: you may specify a host from which information is retrieved.
70
+ The default is the local machine. You can retrieve either a global or
71
+ local group, depending on the value of the +local+ argument.
72
+
73
+ == User class
74
+ === User (Windows)
75
+ The User class has the following attributes on MS Windows systems:
76
+
77
+ * account_type
78
+ * caption
79
+ * description
80
+ * domain
81
+ * password
82
+ * full_name
83
+ * install_date
84
+ * name
85
+ * sid
86
+ * status
87
+ * disabled?
88
+ * local?
89
+ * lockout?
90
+ * password_changeable?
91
+ * password_expires?
92
+ * password_required?
93
+
94
+ === User (Unix)
95
+ The User class has the following attributes on Unix systems:
96
+
97
+ * name
98
+ * passwd
99
+ * uid
100
+ * gid
101
+ * dir
102
+ * shell
103
+ * gecos
104
+ * quota
105
+ * age
106
+ * class
107
+ * comment
108
+ * change
109
+ * expire
110
+
111
+ == Group Classes
112
+ === Group (Windows)
113
+ The Group class has the following attributes on MS Windows systems:
114
+
115
+ * caption
116
+ * description
117
+ * domain
118
+ * install_date
119
+ * name
120
+ * sid
121
+ * status
122
+ * gid
123
+ * local?
124
+
125
+ === Group (Unix)
126
+ The Group class has the following attributes on Unix systems:
127
+
128
+ * name
129
+ * gid
130
+ * members
131
+ * passwd
132
+
133
+ == Error Classes
134
+ Admin::Error < StandardError
135
+ Raised if anything goes wrong with any of the above methods.
136
+
137
+ == Developer's Notes
138
+ === MS Windows
139
+ The Windows version now uses a win32ole + WMI approach to getting
140
+ information. This means that the WMI service must be running on the
141
+ target machine in order to work (which it is, by default).
142
+
143
+ Note that, by default, local user and group information is retrieved
144
+ instead of global. You probably do NOT want to iterate over global users
145
+ or groups because there can be quite a few on your domain.
146
+
147
+ === UNIX
148
+ The underlying implementation is similar to core Ruby's Etc implementation.
149
+ But, in addition to the different interface, I use the re-entrant version
150
+ of the appropriate functions when available.
151
+
152
+ == Future Plans
153
+ Add the following methods for UNIX:
154
+
155
+ * Admin.add_local_user
156
+ * Admin.config_local_user
157
+ * Admin.delete_local_user
158
+ * Admin.add_global_user
159
+ * Admin.config_global_user
160
+ * Admin.delete_global_user
161
+
162
+ * Admin.add_local_group
163
+ * Admin.config_local_group
164
+ * Admin.delete_local_group
165
+ * Admin.add_global_group
166
+ * Admin.config_global_group
167
+ * Admin.delete_global_group
168
+
169
+ Make the User and Group objects comparable.
170
+
171
+ == Known Bugs
172
+ None that I'm aware of. If you find any, please log them on the project
173
+ page at http://www.rubyforge.org/projects/sysutils.
174
+
175
+ == License
176
+ Ruby's
177
+
178
+ == Copyright
179
+ (C) 2005-2008, Daniel J. Berger
180
+ All Rights Reserved
181
+
182
+ == Author
183
+ Daniel J. Berger
184
+ djberg96 at nospam at gmail dot com
185
+ IRC nickname: imperator/mok/rubyhacker1 (freenode)
@@ -0,0 +1,56 @@
1
+ require 'rake'
2
+ require 'rake/clean'
3
+ require 'rake/testtask'
4
+ require 'rbconfig'
5
+ include Config
6
+
7
+ desc "Clean the build files for the sys-admin source for UNIX systems"
8
+ task :clean do
9
+ Dir.chdir('ext') do
10
+ unless RUBY_PLATFORM.match('mswin')
11
+ build_file = 'admin.' + Config::CONFIG['DLEXT']
12
+ sh 'make distclean' if File.exists?(build_file)
13
+ File.delete("sys/#{build_file}") if File.exists?("sys/#{build_file}")
14
+ end
15
+ end
16
+ end
17
+
18
+ desc "Build the sys-admin package on UNIX systems (but don't install it)"
19
+ task :build => [:clean] do
20
+ Dir.chdir('ext') do
21
+ unless RUBY_PLATFORM.match('mswin')
22
+ ruby 'extconf.rb'
23
+ sh 'make'
24
+ build_file = 'admin.' + Config::CONFIG['DLEXT']
25
+ FileUtils.cp(build_file, 'sys')
26
+ end
27
+ end
28
+ end
29
+
30
+ if RUBY_PLATFORM.match('mswin')
31
+ desc "Install the sys-admin package for MS Windows"
32
+ task :install do
33
+ install_dir = File.join(CONFIG['sitelibdir'], 'sys')
34
+ Dir.mkdir(install_dir) unless File.exists?(install_dir)
35
+ FileUtils.cp('lib/sys/admin.rb', install_dir, :verbose => true)
36
+ end
37
+ else
38
+ desc "Install the sys-admin package for Unix platforms"
39
+ task :install => [:build] do
40
+ Dir.chdir('ext') do
41
+ sh 'make install'
42
+ end
43
+ end
44
+ end
45
+
46
+ desc "Run the test suite"
47
+ Rake::TestTask.new("test") do |t|
48
+ if RUBY_PLATFORM.match('mswin')
49
+ t.libs << 'lib'
50
+ else
51
+ task :test => :build
52
+ t.libs << 'ext'
53
+ t.libs.delete('lib')
54
+ end
55
+ t.test_files = FileList['test/tc_admin.rb']
56
+ end
@@ -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
+ Ruby's
149
+
150
+ == Copyright
151
+ Copyright 2002-2007, 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 package 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)