sys-admin 1.4.2 → 1.4.3
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGES +8 -0
- data/README +4 -2
- data/Rakefile +1 -2
- data/doc/sys-admin-unix.txt +164 -0
- data/doc/sys-admin-windows.txt +330 -0
- data/ext/extconf.rb +1 -1
- data/ext/{admin.c → sys/admin.c} +44 -24
- data/ext/{admin.h → sys/admin.h} +25 -1
- data/test/tc_unix.rb +17 -5
- data/test/tc_windows.rb +1 -1
- metadata +50 -40
data/CHANGES
CHANGED
@@ -1,3 +1,11 @@
|
|
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
|
+
|
1
9
|
== 1.4.2 - 26-Jun-2007
|
2
10
|
* Fixed a bug in the Admin.get_login method where it would return junk
|
3
11
|
if the underlying getlogin() function failed (Unix). Thanks go to Gonzalo
|
data/README
CHANGED
@@ -131,7 +131,7 @@ Admin.users(host=localhost, local=true){ |user| ... }
|
|
131
131
|
* passwd
|
132
132
|
|
133
133
|
== Error Classes
|
134
|
-
|
134
|
+
Admin::Error < StandardError
|
135
135
|
Raised if anything goes wrong with any of the above methods.
|
136
136
|
|
137
137
|
== Developer's Notes
|
@@ -166,6 +166,8 @@ AdminError < StandardError
|
|
166
166
|
* Admin.config_global_group
|
167
167
|
* Admin.delete_global_group
|
168
168
|
|
169
|
+
Make the User and Group objects comparable.
|
170
|
+
|
169
171
|
== Known Bugs
|
170
172
|
None that I'm aware of. If you find any, please log them on the project
|
171
173
|
page at http://www.rubyforge.org/projects/sysutils.
|
@@ -174,7 +176,7 @@ AdminError < StandardError
|
|
174
176
|
Ruby's
|
175
177
|
|
176
178
|
== Copyright
|
177
|
-
(C) 2005-
|
179
|
+
(C) 2005-2008, Daniel J. Berger
|
178
180
|
All Rights Reserved
|
179
181
|
|
180
182
|
== Author
|
data/Rakefile
CHANGED
@@ -8,9 +8,9 @@ desc "Clean the build files for the sys-admin source for UNIX systems"
|
|
8
8
|
task :clean do
|
9
9
|
Dir.chdir('ext') do
|
10
10
|
unless RUBY_PLATFORM.match('mswin')
|
11
|
-
FileUtils.rm_rf('sys') if File.exists?('sys')
|
12
11
|
build_file = 'admin.' + Config::CONFIG['DLEXT']
|
13
12
|
sh 'make distclean' if File.exists?(build_file)
|
13
|
+
File.delete("sys/#{build_file}") if File.exists?("sys/#{build_file}")
|
14
14
|
end
|
15
15
|
end
|
16
16
|
end
|
@@ -22,7 +22,6 @@ task :build => [:clean] do
|
|
22
22
|
ruby 'extconf.rb'
|
23
23
|
sh 'make'
|
24
24
|
build_file = 'admin.' + Config::CONFIG['DLEXT']
|
25
|
-
Dir.mkdir('sys') unless File.exists?('sys')
|
26
25
|
FileUtils.cp(build_file, 'sys')
|
27
26
|
end
|
28
27
|
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)
|
@@ -0,0 +1,330 @@
|
|
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
|
+
== Sys::Admin
|
25
|
+
VERSION
|
26
|
+
The version of this package, returned as a String.
|
27
|
+
|
28
|
+
== Sys::Admin::User
|
29
|
+
TEMP_DUPLICATE
|
30
|
+
An account for users whose primary account is in another domain.
|
31
|
+
|
32
|
+
NORMAL
|
33
|
+
Default account type that represents a typical user.
|
34
|
+
|
35
|
+
INTERDOMAIN_TRUST
|
36
|
+
A permit to trust account for a domain that trusts other domains.
|
37
|
+
|
38
|
+
WORKSTATION_TRUST
|
39
|
+
An account for a Windows NT/2000 workstation or server that is a member
|
40
|
+
member of this domain.
|
41
|
+
|
42
|
+
SERVER_TRUST
|
43
|
+
A computer account for a backup domain controller that is a member of this
|
44
|
+
domain.
|
45
|
+
|
46
|
+
= Class Methods
|
47
|
+
== Sys::Admin
|
48
|
+
Admin.add_global_group(group, domain)
|
49
|
+
Adds the global +group+ on +domain+.
|
50
|
+
|
51
|
+
Admin.add_global_user(user, domain)
|
52
|
+
Adds the global +user+ on +domain+.
|
53
|
+
|
54
|
+
Admin.add_local_group(group, host=localhost)
|
55
|
+
Adds the local +group+ on +host+, or the localhost if no host is specified.
|
56
|
+
|
57
|
+
Admin.add_local_user(user, host=localhost)
|
58
|
+
Adds the local +user+ on +host+, or the localhost if no host is specified.
|
59
|
+
|
60
|
+
Admin.config_global_group(user, option, domain)
|
61
|
+
Configures +group+ on +domain+ using +options+. There are too many options
|
62
|
+
to list here.
|
63
|
+
|
64
|
+
See http://tinyurl.com/cjkzl for a list of valid options.
|
65
|
+
|
66
|
+
Admin.config_local_group(user, option, host=localhost)
|
67
|
+
Configures +group+ on +host+ using +options+. There are too many options
|
68
|
+
to list here.
|
69
|
+
|
70
|
+
See http://tinyurl.com/cjkzl for a list of valid options.
|
71
|
+
|
72
|
+
Admin.config_global_user(user, option, domain)
|
73
|
+
Configures +user+ on +domain+ using +options+. There are too many options
|
74
|
+
to list here.
|
75
|
+
|
76
|
+
See http://tinyurl.com/3hjv9 for a list of valid options.
|
77
|
+
|
78
|
+
Admin.config_local_user(user, options, host=localhost)
|
79
|
+
Configures the local +user+ on +host+ using +options+. If no host is
|
80
|
+
specified, the default is localhost.
|
81
|
+
|
82
|
+
See http://tinyurl.com/3hjv9 for a list of valid options.
|
83
|
+
|
84
|
+
Admin.delete_global_group(group, domain)
|
85
|
+
Deletes the global +group+ from +domain+.
|
86
|
+
|
87
|
+
Admin.delete_global_user(user, domain)
|
88
|
+
Deletes the global +user+ from +domain+.
|
89
|
+
|
90
|
+
Admin.delete_local_group(group, host=localhost)
|
91
|
+
Deletes the local +group+ from +host+, or localhost if no host is specified.
|
92
|
+
|
93
|
+
Admin.delete_local_user(user, host=localhost)
|
94
|
+
Deletes the local +user+ from +host+, or localhost if no host is specified.
|
95
|
+
|
96
|
+
Admin.get_group(name, host=localhost, local=true)
|
97
|
+
Admin.get_group(gid, host=localhost, local=true)
|
98
|
+
Returns a Group object for the given name or gid. Raises an Admin::Error
|
99
|
+
if a group cannot be found for that name or GID.
|
100
|
+
|
101
|
+
You may specify a host from which information is retrieved.
|
102
|
+
The default is the local machine. You can retrieve either a global or
|
103
|
+
local group, depending on the value of the +local+ argument.
|
104
|
+
|
105
|
+
Admin.get_login
|
106
|
+
Returns the user name of the current login.
|
107
|
+
|
108
|
+
Admin.get_user(name, host=localhost, local=true)
|
109
|
+
Admin.get_user(uid, host=localhost, local=true)
|
110
|
+
Returns a User object for the given name or uid. Raises an Admin::Error if
|
111
|
+
a user cannot be found for that name or user ID.
|
112
|
+
|
113
|
+
You may specify a +host+ from which information is retrieved. The
|
114
|
+
default is the local machine. You may also specify whether to
|
115
|
+
retrieve a local or global account. The default is local.
|
116
|
+
|
117
|
+
Admin.groups(host=localhost, local=true)
|
118
|
+
Admin.groups(host=localhost, local=true){ |grp| ... }
|
119
|
+
In block form, yields a Group object for each group on the system. In
|
120
|
+
non-block form, returns an Array of Group objects.
|
121
|
+
|
122
|
+
You may specify a +host+ from which information is retrieved. The default
|
123
|
+
is the local machine. You can retrieve either a global or local groups,
|
124
|
+
depending on the value of the +local+ argument. The default is local.
|
125
|
+
|
126
|
+
Admin.users(host=localhost, local=true)
|
127
|
+
Admin.users(host=localhost, local=true){ |grp| ... }
|
128
|
+
In block form, yields a User object for each group on the system. In
|
129
|
+
non-block form, returns an Array of User objects.
|
130
|
+
|
131
|
+
You may specify a +host+ from which information is retrieved. The default
|
132
|
+
is the local machine. You can retrieve either a global or local users,
|
133
|
+
depending on the value of the +local+ argument. The default is local.
|
134
|
+
|
135
|
+
== Sys::Admin::Group
|
136
|
+
Group.new
|
137
|
+
Group.new{ |grp| ... }
|
138
|
+
Creates and returns a Group object, which encapsulates the information
|
139
|
+
typically found within an /etc/group entry, i.e. a struct group. If a
|
140
|
+
block is provided, yields the object back to the block.
|
141
|
+
|
142
|
+
== Sys::Admin::User
|
143
|
+
User.new
|
144
|
+
User.new{ |usr| ... }
|
145
|
+
Creates and returns a User object, which encapsulates the information
|
146
|
+
typically found within an /etc/passwd entry, i.e. a struct passwd. If a
|
147
|
+
block is provided, yields the object back to the block.
|
148
|
+
|
149
|
+
= Instance Methods
|
150
|
+
== Sys::Admin::Group
|
151
|
+
Group#caption
|
152
|
+
Short description of the group.
|
153
|
+
|
154
|
+
Group#caption=
|
155
|
+
Sets the caption for the group. Use only when creating a new group.
|
156
|
+
|
157
|
+
Group#description
|
158
|
+
Description of the group.
|
159
|
+
|
160
|
+
Group#description=
|
161
|
+
Sets the description of the group. Use only when creating a new group.
|
162
|
+
|
163
|
+
Group#domain
|
164
|
+
The name of the Windows domain to which the group account belongs.
|
165
|
+
|
166
|
+
Group#domain=
|
167
|
+
Sets the name of the Windows domain to which the group account belongs.
|
168
|
+
Use only when creating a new group.
|
169
|
+
|
170
|
+
Group#install_date
|
171
|
+
The date the group was added.
|
172
|
+
|
173
|
+
Group#gid
|
174
|
+
The group id.
|
175
|
+
|
176
|
+
Group#local?
|
177
|
+
Returns whether or not the group is local (vs global).
|
178
|
+
|
179
|
+
Group#local=
|
180
|
+
Sets whether or not the group is local (vs global).
|
181
|
+
|
182
|
+
Group#name
|
183
|
+
The name of the Windows group account on the given domain.
|
184
|
+
|
185
|
+
Group#name=
|
186
|
+
Sets the name of the Windows group account on the given domain.
|
187
|
+
Use only when creating a new group.
|
188
|
+
|
189
|
+
Group#sid
|
190
|
+
The security identifer for the group.
|
191
|
+
|
192
|
+
Group#sid=
|
193
|
+
Sets the security identifer for the group.
|
194
|
+
|
195
|
+
Group#sid_type
|
196
|
+
The type of security identifier as a stringified value.
|
197
|
+
|
198
|
+
Group#sid_type=
|
199
|
+
Sets the type of security identifier as a stringified value. Use only when
|
200
|
+
creating a new group.
|
201
|
+
|
202
|
+
See the +constants+ section for a list of valid sid types.
|
203
|
+
|
204
|
+
Group#status
|
205
|
+
Current status for the group, such as "ok", "error", etc.
|
206
|
+
|
207
|
+
Group#status=
|
208
|
+
Sets the status for the group.
|
209
|
+
|
210
|
+
== Sys::Admin::User
|
211
|
+
User#account_type
|
212
|
+
Returns the account type as a human readable string.
|
213
|
+
|
214
|
+
User#account_type=
|
215
|
+
Sets the account type. See the +constants+ section for a list of valid
|
216
|
+
values you can set this to.
|
217
|
+
|
218
|
+
User#caption
|
219
|
+
Domain and username of the account.
|
220
|
+
|
221
|
+
User#caption=
|
222
|
+
Sets the domain and username of the account.
|
223
|
+
|
224
|
+
User#description
|
225
|
+
Description of the account.
|
226
|
+
|
227
|
+
User#description=
|
228
|
+
Sets the description of the account.
|
229
|
+
|
230
|
+
User#disabled?
|
231
|
+
Returns whether or not the account is disabled.
|
232
|
+
|
233
|
+
User#disabled=
|
234
|
+
Sets whether or not the account is disabled.
|
235
|
+
|
236
|
+
User#domain
|
237
|
+
Name of the Windows domain to which a user account belongs.
|
238
|
+
|
239
|
+
User#domain=
|
240
|
+
Sets the name of the Windows domain to which a user account belongs.
|
241
|
+
|
242
|
+
User#full_name
|
243
|
+
Full name of a local user.
|
244
|
+
|
245
|
+
User#full_name=
|
246
|
+
Sets the full name of a local user.
|
247
|
+
|
248
|
+
User#install_date
|
249
|
+
Date the user account was created.
|
250
|
+
|
251
|
+
User#local?
|
252
|
+
Returns whether or not the account is defined on the local computer.
|
253
|
+
|
254
|
+
User#local=
|
255
|
+
Sets whether or not the account is defined on the local computer.
|
256
|
+
|
257
|
+
User#lockout?
|
258
|
+
Returns whether or not the account is locked out of the OS.
|
259
|
+
|
260
|
+
User#lockout=
|
261
|
+
Sets whether or not the account is locked out of the OS.
|
262
|
+
|
263
|
+
User#name
|
264
|
+
Name of the Windows user account on the domain that the User#domain
|
265
|
+
property specifies.
|
266
|
+
|
267
|
+
User#name=
|
268
|
+
Sets the name of the Windows user account on the domain that the User#domain
|
269
|
+
property specifies.
|
270
|
+
|
271
|
+
User#password
|
272
|
+
The user's password.
|
273
|
+
|
274
|
+
User#password=
|
275
|
+
Sets the user's password.
|
276
|
+
|
277
|
+
User#password_changeable?
|
278
|
+
Returns whether or not the password for the account can be changed.
|
279
|
+
|
280
|
+
User#password_changeable=
|
281
|
+
Sets whether or not the password for the account can be changed.
|
282
|
+
|
283
|
+
User#password_expires?
|
284
|
+
Returns whether or not the password for the account expires.
|
285
|
+
|
286
|
+
User#password_expires=
|
287
|
+
Sets whether or not the password for the account expires.
|
288
|
+
|
289
|
+
User#password_required?
|
290
|
+
Returns whether or not a password is required for the account.
|
291
|
+
|
292
|
+
User#password_required=
|
293
|
+
Sets whether or not a password is required for the account.
|
294
|
+
|
295
|
+
User#sid
|
296
|
+
The user's security identifier.
|
297
|
+
|
298
|
+
User#sid=
|
299
|
+
Sets the user's security identifier.
|
300
|
+
|
301
|
+
User#status
|
302
|
+
Current status for the user, such as "ok", "error", etc.
|
303
|
+
|
304
|
+
== Notes
|
305
|
+
Not all platforms support all of the User members. The only ones that are
|
306
|
+
supported on all platforms are name, uid, gid, dir and shell. The rest
|
307
|
+
will simply return nil if they aren't supported.
|
308
|
+
|
309
|
+
== Known Bugs
|
310
|
+
None that I am aware of. Please log any bugs you find on the project
|
311
|
+
website at http://www.rubyforge.org/projects/sysutils.
|
312
|
+
|
313
|
+
== License
|
314
|
+
Ruby's
|
315
|
+
|
316
|
+
== Copyright
|
317
|
+
Copyright 2002-2007, Daniel J. Berger
|
318
|
+
|
319
|
+
All Rights Reserved. This module is free software. It may be used,
|
320
|
+
redistributed and/or modified under the same terms as Ruby itself.
|
321
|
+
|
322
|
+
== Warranty
|
323
|
+
This package is provided "as is" and without any express or
|
324
|
+
implied warranties, including, without limitation, the implied
|
325
|
+
warranties of merchantability and fitness for a particular purpose.
|
326
|
+
|
327
|
+
== Author
|
328
|
+
Daniel J. Berger
|
329
|
+
djberg96 at nospam at gmail dot com
|
330
|
+
imperator on IRC (Freenode)
|
data/ext/extconf.rb
CHANGED
data/ext/{admin.c → sys/admin.c}
RENAMED
@@ -49,8 +49,6 @@ static VALUE group_init(VALUE self){
|
|
49
49
|
* the program is run.
|
50
50
|
*/
|
51
51
|
static VALUE admin_get_login(VALUE klass){
|
52
|
-
VALUE v_login = Qnil;
|
53
|
-
|
54
52
|
#ifdef HAVE_GETLOGIN_R
|
55
53
|
char login[_POSIX_LOGIN_NAME_MAX];
|
56
54
|
|
@@ -103,7 +101,7 @@ static VALUE admin_get_login(VALUE klass){
|
|
103
101
|
* Admin.get_user(name)
|
104
102
|
* Admin.get_user(uid)
|
105
103
|
*
|
106
|
-
* Returns a User object for the given +name+ or +uid+. Raises an
|
104
|
+
* Returns a User object for the given +name+ or +uid+. Raises an Admin::Error
|
107
105
|
* if a user cannot be found for that name or user ID.
|
108
106
|
*/
|
109
107
|
static VALUE admin_get_user(VALUE klass, VALUE v_value){
|
@@ -121,7 +119,7 @@ static VALUE admin_get_user(VALUE klass, VALUE v_value){
|
|
121
119
|
* Admin.get_group(name)
|
122
120
|
* Admin.get_group(gid)
|
123
121
|
*
|
124
|
-
* Returns a Group object for the given +name+ or +gid+. Raises an
|
122
|
+
* Returns a Group object for the given +name+ or +gid+. Raises an Admin::Error
|
125
123
|
* if a group cannot be found for that name or GID.
|
126
124
|
*
|
127
125
|
*--
|
@@ -142,14 +140,13 @@ static VALUE admin_get_group(VALUE klass, VALUE v_value){
|
|
142
140
|
return v_group;
|
143
141
|
}
|
144
142
|
|
145
|
-
/*
|
146
|
-
*
|
147
|
-
* Admin.groups{ |group| ... }
|
143
|
+
/*
|
144
|
+
* :no-doc:
|
148
145
|
*
|
149
|
-
*
|
150
|
-
*
|
146
|
+
* This is the main body of the Admin.groups method. It is wrapped separately
|
147
|
+
* for the sake of an rb_ensure() call.
|
151
148
|
*/
|
152
|
-
static VALUE
|
149
|
+
static VALUE admin_groups_body(VALUE klass){
|
153
150
|
VALUE v_array = Qnil;
|
154
151
|
|
155
152
|
if(!rb_block_given_p())
|
@@ -188,19 +185,29 @@ static VALUE admin_groups(VALUE klass){
|
|
188
185
|
rb_raise(rb_eNotImpError, "groups method not supported on this platform");
|
189
186
|
#endif
|
190
187
|
|
191
|
-
|
192
|
-
|
193
|
-
return v_array;
|
188
|
+
return v_array; /* Nil or an array */
|
194
189
|
}
|
195
190
|
|
196
191
|
/* call-seq:
|
197
|
-
* Admin.
|
198
|
-
* Admin.
|
192
|
+
* Admin.groups
|
193
|
+
* Admin.groups{ |group| ... }
|
199
194
|
*
|
200
|
-
* In block form, yields a
|
201
|
-
* non-block form, returns an Array of
|
195
|
+
* In block form, yields a Group object for each group on the system. In
|
196
|
+
* non-block form, returns an Array of Group objects.
|
202
197
|
*/
|
203
|
-
static VALUE
|
198
|
+
static VALUE admin_groups(VALUE klass){
|
199
|
+
return rb_ensure(admin_groups_body, rb_ary_new3(1, klass),
|
200
|
+
admin_groups_cleanup, Qnil
|
201
|
+
);
|
202
|
+
}
|
203
|
+
|
204
|
+
/*
|
205
|
+
* :no-doc:
|
206
|
+
*
|
207
|
+
* This is the main body of the Admin.users method. It is wrapped separately
|
208
|
+
* for the sake of an rb_ensure() call.
|
209
|
+
*/
|
210
|
+
static VALUE admin_users_body(VALUE klass){
|
204
211
|
VALUE v_array = Qnil;
|
205
212
|
|
206
213
|
if(!rb_block_given_p())
|
@@ -241,14 +248,27 @@ static VALUE admin_users(VALUE klass){
|
|
241
248
|
rb_raise(rb_eNotImpError, "users method not supported on this platform");
|
242
249
|
#endif
|
243
250
|
|
244
|
-
|
251
|
+
return v_array; /* Nil or an array */
|
252
|
+
}
|
245
253
|
|
246
|
-
if(rb_block_given_p())
|
247
|
-
return Qnil;
|
248
254
|
|
249
|
-
|
255
|
+
/* call-seq:
|
256
|
+
* Admin.users
|
257
|
+
* Admin.users{ |user| ... }
|
258
|
+
*
|
259
|
+
* In block form, yields a User object for each user on the system. In
|
260
|
+
* non-block form, returns an Array of User objects.
|
261
|
+
*/
|
262
|
+
static VALUE admin_users(VALUE klass){
|
263
|
+
return rb_ensure(admin_users_body, rb_ary_new3(1, klass),
|
264
|
+
admin_users_cleanup, Qnil
|
265
|
+
);
|
250
266
|
}
|
251
267
|
|
268
|
+
/*
|
269
|
+
* The Sys::Admin class encapsulates typical operations surrounding the query
|
270
|
+
* of user and group information.
|
271
|
+
*/
|
252
272
|
void Init_admin(){
|
253
273
|
VALUE mSys, cAdmin;
|
254
274
|
|
@@ -265,7 +285,7 @@ void Init_admin(){
|
|
265
285
|
cGroup = rb_define_class_under(mSys, "Group", rb_cObject);
|
266
286
|
|
267
287
|
/* Error raised if any of the Sys::Admin methods fail */
|
268
|
-
cAdminError = rb_define_class_under(
|
288
|
+
cAdminError = rb_define_class_under(cAdmin, "Error", rb_eStandardError);
|
269
289
|
|
270
290
|
/* Class Methods */
|
271
291
|
rb_define_singleton_method(cAdmin, "get_login", admin_get_login, 0);
|
@@ -344,6 +364,6 @@ void Init_admin(){
|
|
344
364
|
|
345
365
|
/* Constants */
|
346
366
|
|
347
|
-
/* 1.4.
|
367
|
+
/* 1.4.3: The version of this library */
|
348
368
|
rb_define_const(cAdmin, "VERSION", rb_str_new2(SYS_ADMIN_VERSION));
|
349
369
|
}
|
data/ext/{admin.h → sys/admin.h}
RENAMED
@@ -8,7 +8,7 @@
|
|
8
8
|
#include <errno.h>
|
9
9
|
#include <string.h>
|
10
10
|
|
11
|
-
#define SYS_ADMIN_VERSION "1.4.
|
11
|
+
#define SYS_ADMIN_VERSION "1.4.3"
|
12
12
|
|
13
13
|
#ifdef HAVE_LASTLOG_H
|
14
14
|
#include <lastlog.h>
|
@@ -47,6 +47,8 @@
|
|
47
47
|
#endif
|
48
48
|
|
49
49
|
/* Function prototypes */
|
50
|
+
static VALUE admin_users_cleanup();
|
51
|
+
static VALUE admin_groups_cleanup();
|
50
52
|
static VALUE get_user(struct passwd* p);
|
51
53
|
static VALUE get_group(struct group* g);
|
52
54
|
int get_lastlog_info(struct passwd* p, VALUE v_value);
|
@@ -437,3 +439,25 @@ int get_lastlog_info(struct passwd* pwd, VALUE v_user){
|
|
437
439
|
|
438
440
|
return 0;
|
439
441
|
}
|
442
|
+
|
443
|
+
/*
|
444
|
+
* :no-doc:
|
445
|
+
*
|
446
|
+
* This function is used for an rb_ensure() call where we need to make sure
|
447
|
+
* that endpwent() is called in the block form of Admin.groups.
|
448
|
+
*/
|
449
|
+
static VALUE admin_groups_cleanup(){
|
450
|
+
endgrent();
|
451
|
+
return Qnil;
|
452
|
+
}
|
453
|
+
|
454
|
+
/*
|
455
|
+
* :no-doc:
|
456
|
+
*
|
457
|
+
* This function is used for an rb_ensure() call where we need to make sure
|
458
|
+
* that endpwent() is called in the block form of Admin.users.
|
459
|
+
*/
|
460
|
+
static VALUE admin_users_cleanup(){
|
461
|
+
endpwent();
|
462
|
+
return Qnil;
|
463
|
+
}
|
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(
|
20
|
+
assert_equal('1.4.3', Admin::VERSION)
|
21
21
|
end
|
22
22
|
|
23
23
|
def test_get_login
|
@@ -32,34 +32,46 @@ class TC_Sys_Admin_Unix < Test::Unit::TestCase
|
|
32
32
|
assert_nothing_raised{ Admin.get_user(@userid) }
|
33
33
|
assert_kind_of(User, Admin.get_user(@user))
|
34
34
|
assert_kind_of(User, Admin.get_user(@userid))
|
35
|
-
assert_raises(
|
35
|
+
assert_raises(Admin::Error){ Admin.get_user("foofoo") }
|
36
36
|
end
|
37
37
|
|
38
38
|
def test_users
|
39
39
|
assert_respond_to(Admin, :users)
|
40
40
|
assert_nothing_raised{ Admin.users }
|
41
|
-
assert_nothing_raised{ Admin.users{ |g| } }
|
42
41
|
assert_kind_of(Array, Admin.users)
|
43
42
|
assert_kind_of(User, Admin.users.first)
|
44
43
|
end
|
45
44
|
|
45
|
+
def test_users_block_form
|
46
|
+
array = []
|
47
|
+
assert_nothing_raised{ Admin.users{ |g| array << g } }
|
48
|
+
assert_equal(true, Admin.users.length == array.length)
|
49
|
+
assert_nothing_raised{ Admin.users{ |g| break } }
|
50
|
+
end
|
51
|
+
|
46
52
|
def test_get_group
|
47
53
|
assert_respond_to(Admin, :get_group)
|
48
54
|
assert_nothing_raised{ Admin.get_group(@group) }
|
49
55
|
assert_nothing_raised{ Admin.get_group(@groupid) }
|
50
56
|
assert_kind_of(Group, Admin.get_group(@group))
|
51
57
|
assert_kind_of(Group, Admin.get_group(@groupid))
|
52
|
-
assert_raises(
|
58
|
+
assert_raises(Admin::Error){ Admin.get_group("foofoo") }
|
53
59
|
end
|
54
60
|
|
55
61
|
def test_groups
|
56
62
|
assert_respond_to(Admin, :groups)
|
57
63
|
assert_nothing_raised{ Admin.groups }
|
58
|
-
assert_nothing_raised{ Admin.groups{ |g| } }
|
59
64
|
assert_kind_of(Array, Admin.groups)
|
60
65
|
assert_kind_of(Group, Admin.groups.first)
|
61
66
|
end
|
62
67
|
|
68
|
+
def test_groups_block_form
|
69
|
+
array = []
|
70
|
+
assert_nothing_raised{ Admin.groups{ |g| array << g } }
|
71
|
+
assert_equal(true, Admin.groups.length == array.length)
|
72
|
+
assert_nothing_raised{ Admin.groups{ |g| break } }
|
73
|
+
end
|
74
|
+
|
63
75
|
def teardown
|
64
76
|
@user = nil
|
65
77
|
@userid = nil
|
data/test/tc_windows.rb
CHANGED
metadata
CHANGED
@@ -1,34 +1,32 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
|
-
rubygems_version: 0.9.4
|
3
|
-
specification_version: 1
|
4
2
|
name: sys-admin
|
5
3
|
version: !ruby/object:Gem::Version
|
6
|
-
version: 1.4.
|
7
|
-
date: 2007-06-26 00:00:00 -06:00
|
8
|
-
summary: A unified, cross platform replacement for the "etc" package.
|
9
|
-
require_paths:
|
10
|
-
- lib
|
11
|
-
email: djberg96@gmail.com
|
12
|
-
homepage: http://www.rubyforge.org/projects/sysutils
|
13
|
-
rubyforge_project: sysutils
|
14
|
-
description: A unified, cross platform replacement for the "etc" package.
|
15
|
-
autorequire:
|
16
|
-
default_executable:
|
17
|
-
bindir: bin
|
18
|
-
has_rdoc: true
|
19
|
-
required_ruby_version: !ruby/object:Gem::Version::Requirement
|
20
|
-
requirements:
|
21
|
-
- - ">="
|
22
|
-
- !ruby/object:Gem::Version
|
23
|
-
version: 1.8.0
|
24
|
-
version:
|
4
|
+
version: 1.4.3
|
25
5
|
platform: ruby
|
26
|
-
signing_key:
|
27
|
-
cert_chain:
|
28
|
-
post_install_message:
|
29
6
|
authors:
|
30
7
|
- Daniel J. Berger
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
|
12
|
+
date: 2008-03-02 00:00:00 -07:00
|
13
|
+
default_executable:
|
14
|
+
dependencies: []
|
15
|
+
|
16
|
+
description: A unified, cross platform replacement for the "etc" package.
|
17
|
+
email: djberg96@gmail.com
|
18
|
+
executables: []
|
19
|
+
|
20
|
+
extensions:
|
21
|
+
- ext/extconf.rb
|
22
|
+
extra_rdoc_files:
|
23
|
+
- CHANGES
|
24
|
+
- README
|
25
|
+
- MANIFEST
|
26
|
+
- ext/sys/admin.c
|
31
27
|
files:
|
28
|
+
- doc/sys-admin-unix.txt
|
29
|
+
- doc/sys-admin-windows.txt
|
32
30
|
- examples/groups.rb
|
33
31
|
- examples/users.rb
|
34
32
|
- test/tc_admin.rb
|
@@ -36,25 +34,37 @@ files:
|
|
36
34
|
- test/tc_windows.rb
|
37
35
|
- CHANGES
|
38
36
|
- MANIFEST
|
39
|
-
- README
|
40
37
|
- Rakefile
|
41
|
-
-
|
42
|
-
- ext/admin.h
|
38
|
+
- README
|
43
39
|
- ext/extconf.rb
|
44
|
-
|
45
|
-
-
|
40
|
+
- ext/sys
|
41
|
+
- ext/sys/admin.c
|
42
|
+
- ext/sys/admin.h
|
43
|
+
has_rdoc: true
|
44
|
+
homepage: http://www.rubyforge.org/projects/sysutils
|
45
|
+
post_install_message:
|
46
46
|
rdoc_options: []
|
47
47
|
|
48
|
-
|
49
|
-
-
|
50
|
-
|
51
|
-
|
52
|
-
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
48
|
+
require_paths:
|
49
|
+
- lib
|
50
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: 1.8.0
|
55
|
+
version:
|
56
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
57
|
+
requirements:
|
58
|
+
- - ">="
|
59
|
+
- !ruby/object:Gem::Version
|
60
|
+
version: "0"
|
61
|
+
version:
|
57
62
|
requirements: []
|
58
63
|
|
59
|
-
|
60
|
-
|
64
|
+
rubyforge_project: sysutils
|
65
|
+
rubygems_version: 1.0.1
|
66
|
+
signing_key:
|
67
|
+
specification_version: 2
|
68
|
+
summary: A unified, cross platform replacement for the "etc" package.
|
69
|
+
test_files:
|
70
|
+
- test/tc_admin.rb
|