sys-admin 1.5.3-x86-mingw32

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,336 @@
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 library, 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#dir
231
+ Returns the user's home directory.
232
+
233
+ User#dir=
234
+ Sets the user's home directory.
235
+
236
+ User#disabled?
237
+ Returns whether or not the account is disabled.
238
+
239
+ User#disabled=
240
+ Sets whether or not the account is disabled.
241
+
242
+ User#domain
243
+ Name of the Windows domain to which a user account belongs.
244
+
245
+ User#domain=
246
+ Sets the name of the Windows domain to which a user account belongs.
247
+
248
+ User#full_name
249
+ Full name of a local user.
250
+
251
+ User#full_name=
252
+ Sets the full name of a local user.
253
+
254
+ User#install_date
255
+ Date the user account was created.
256
+
257
+ User#local?
258
+ Returns whether or not the account is defined on the local computer.
259
+
260
+ User#local=
261
+ Sets whether or not the account is defined on the local computer.
262
+
263
+ User#lockout?
264
+ Returns whether or not the account is locked out of the OS.
265
+
266
+ User#lockout=
267
+ Sets whether or not the account is locked out of the OS.
268
+
269
+ User#name
270
+ Name of the Windows user account on the domain that the User#domain
271
+ property specifies.
272
+
273
+ User#name=
274
+ Sets the name of the Windows user account on the domain that the User#domain
275
+ property specifies.
276
+
277
+ User#password
278
+ The user's password.
279
+
280
+ User#password=
281
+ Sets the user's password.
282
+
283
+ User#password_changeable?
284
+ Returns whether or not the password for the account can be changed.
285
+
286
+ User#password_changeable=
287
+ Sets whether or not the password for the account can be changed.
288
+
289
+ User#password_expires?
290
+ Returns whether or not the password for the account expires.
291
+
292
+ User#password_expires=
293
+ Sets whether or not the password for the account expires.
294
+
295
+ User#password_required?
296
+ Returns whether or not a password is required for the account.
297
+
298
+ User#password_required=
299
+ Sets whether or not a password is required for the account.
300
+
301
+ User#sid
302
+ The user's security identifier.
303
+
304
+ User#sid=
305
+ Sets the user's security identifier.
306
+
307
+ User#status
308
+ Current status for the user, such as "ok", "error", etc.
309
+
310
+ == Notes
311
+ Not all platforms support all of the User members. The only ones that are
312
+ supported on all platforms are name, uid, gid, dir and shell. The rest
313
+ will simply return nil if they aren't supported.
314
+
315
+ == Known Bugs
316
+ None that I am aware of. Please log any bugs you find on the project
317
+ website at http://www.rubyforge.org/projects/sysutils.
318
+
319
+ == License
320
+ Artistic 2.0
321
+
322
+ == Copyright
323
+ Copyright 2002-2009, Daniel J. Berger
324
+
325
+ All Rights Reserved. This module is free software. It may be used,
326
+ redistributed and/or modified under the same terms as Ruby itself.
327
+
328
+ == Warranty
329
+ This library is provided "as is" and without any express or
330
+ implied warranties, including, without limitation, the implied
331
+ warranties of merchantability and fitness for a particular purpose.
332
+
333
+ == Author
334
+ Daniel J. Berger
335
+ djberg96 at nospam at gmail dot com
336
+ imperator on IRC (Freenode)
@@ -0,0 +1,39 @@
1
+ ###########################################################################
2
+ # groups.rb
3
+ #
4
+ # Sample script to demonstrate some of the various group methods. Alter
5
+ # as you see fit.
6
+ ###########################################################################
7
+ base = File.basename(Dir.pwd)
8
+
9
+ if base == "examples" || base =~ /sys-admin.*/
10
+ require "ftools"
11
+ Dir.chdir("..") if base == "examples"
12
+ Dir.mkdir("sys") unless File.exists?("sys")
13
+ if RUBY_PLATFORM.match("mswin")
14
+ File.copy("lib/sys/admin.rb", "sys/admin.rb")
15
+ else
16
+ File.copy("admin.so","sys") if File.exists?("admin.so")
17
+ end
18
+ $LOAD_PATH.unshift(Dir.pwd)
19
+ end
20
+
21
+ require "pp"
22
+ require "sys/admin"
23
+ include Sys
24
+
25
+ if PLATFORM.match("mswin")
26
+ pp Admin.get_group("guests")
27
+ pp Admin.get_group(513)
28
+ else
29
+ pp Admin.get_group("adm")
30
+ pp Admin.get_group(7)
31
+ end
32
+
33
+ Admin.groups{ |g|
34
+ pp g
35
+ puts
36
+ }
37
+
38
+ # This should raise an error
39
+ Admin.get_group("fofofofof")
data/examples/users.rb ADDED
@@ -0,0 +1,53 @@
1
+ ###########################################################################
2
+ # users.rb
3
+ #
4
+ # Sample script to demonstrate some of the various user methods. Alter
5
+ # as you see fit.
6
+ ###########################################################################
7
+ base = File.basename(Dir.pwd)
8
+
9
+ if base == "examples" || base =~ /sys-admin.*/
10
+ require "ftools"
11
+ Dir.chdir("..") if base == "examples"
12
+ Dir.mkdir("sys") unless File.exists?("sys")
13
+ if RUBY_PLATFORM.match("mswin")
14
+ File.copy("lib/sys/admin.rb", "sys/admin.rb")
15
+ else
16
+ File.copy("admin.so","sys") if File.exists?("admin.so")
17
+ end
18
+ $LOAD_PATH.unshift(Dir.pwd)
19
+ end
20
+
21
+ require "pp"
22
+ require "sys/admin"
23
+ include Sys
24
+
25
+ user = User.new do |u|
26
+ u.name = "Foo"
27
+ u.description = "Test account"
28
+ u.password = "changeme"
29
+ #u.lockout = false
30
+ u.disabled = true
31
+ #u.password_required = true
32
+ end
33
+
34
+ Admin.delete_user(u.name) rescue nil
35
+ Admin.add_user(user)
36
+
37
+ #pp Admin.get_user("Foo")
38
+
39
+ #Admin.delete_user("Foo")
40
+
41
+ =begin
42
+ user = Admin.get_login
43
+
44
+ puts "User: #{user}"
45
+
46
+ Admin.users{ |u|
47
+ pp u
48
+ puts
49
+ }
50
+
51
+ pp Admin.get_user(user)
52
+ pp Admin.get_user(501)
53
+ =end