sys-admin 1.7.0 → 1.7.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +5 -5
- checksums.yaml.gz.sig +0 -0
- data.tar.gz.sig +0 -0
- data/{CHANGES → CHANGES.md} +188 -168
- data/LICENSE +177 -0
- data/{MANIFEST → MANIFEST.md} +19 -18
- data/README.md +159 -0
- data/Rakefile +47 -47
- data/certs/djberg96_pub.pem +21 -21
- data/doc/sys-admin-unix.txt +162 -162
- data/doc/sys-admin-windows.txt +346 -346
- data/examples/example_groups.rb +27 -27
- data/examples/example_users.rb +41 -41
- data/lib/bsd/sys/admin.rb +256 -256
- data/lib/darwin/sys/admin.rb +237 -237
- data/lib/linux/sys/admin.rb +273 -273
- data/lib/sunos/sys/admin.rb +261 -261
- data/lib/sys-admin.rb +1 -1
- data/lib/sys/admin.rb +24 -24
- data/lib/sys/admin/common.rb +137 -137
- data/lib/sys/admin/custom.rb +16 -16
- data/lib/unix/sys/admin.rb +163 -163
- data/lib/windows/sys/admin.rb +997 -997
- data/sys-admin.gemspec +37 -31
- data/test/test_sys_admin.rb +23 -19
- data/test/test_sys_admin_unix.rb +260 -260
- data/test/test_sys_admin_windows.rb +337 -337
- metadata +67 -64
- metadata.gz.sig +0 -0
- data/README +0 -148
data/{MANIFEST → MANIFEST.md}
RENAMED
|
@@ -1,18 +1,19 @@
|
|
|
1
|
-
* sys-admin.gemspec
|
|
2
|
-
* CHANGES
|
|
3
|
-
*
|
|
4
|
-
*
|
|
5
|
-
*
|
|
6
|
-
*
|
|
7
|
-
*
|
|
8
|
-
* examples/
|
|
9
|
-
*
|
|
10
|
-
* lib/
|
|
11
|
-
* lib/
|
|
12
|
-
* lib/
|
|
13
|
-
* lib/
|
|
14
|
-
* lib/sys/admin
|
|
15
|
-
* lib/sys/admin/
|
|
16
|
-
*
|
|
17
|
-
* test/
|
|
18
|
-
* test/
|
|
1
|
+
* sys-admin.gemspec
|
|
2
|
+
* CHANGES.rdoc
|
|
3
|
+
* LICENSE
|
|
4
|
+
* MANIFEST.rdoc
|
|
5
|
+
* Rakefile
|
|
6
|
+
* README.rdoc
|
|
7
|
+
* certs/djberg96_pub.pem
|
|
8
|
+
* examples/groups.rb
|
|
9
|
+
* examples/users.rb
|
|
10
|
+
* lib/sys/admin.rb
|
|
11
|
+
* lib/darwin/sys/admin.rb
|
|
12
|
+
* lib/linux/sys/admin.rb
|
|
13
|
+
* lib/bsd/sys/admin.rb
|
|
14
|
+
* lib/sunos/sys/admin.rb
|
|
15
|
+
* lib/sys/admin/common.rb
|
|
16
|
+
* lib/sys/admin/custom.rb
|
|
17
|
+
* test/test_sys_admin.rb
|
|
18
|
+
* test/test_sys_admin_unix.rb
|
|
19
|
+
* test/test_sys_admin_windows.rb
|
data/README.md
ADDED
|
@@ -0,0 +1,159 @@
|
|
|
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
|
+
```ruby
|
|
9
|
+
require 'sys/admin' # or sys-admin
|
|
10
|
+
include Sys
|
|
11
|
+
|
|
12
|
+
# Returns an Array of User objects
|
|
13
|
+
a = Admin.users
|
|
14
|
+
|
|
15
|
+
# Returns an Array of Group objects
|
|
16
|
+
g = Admin.groups
|
|
17
|
+
|
|
18
|
+
# Get information about a particular user
|
|
19
|
+
p Admin.get_user("nobody")
|
|
20
|
+
p Admin.get_user("nobody", :localaccount => true)
|
|
21
|
+
|
|
22
|
+
# Get information about a particular group
|
|
23
|
+
p Admin.get_group("adm")
|
|
24
|
+
p Admin.get_group("adm", :localaccount => true)
|
|
25
|
+
```
|
|
26
|
+
|
|
27
|
+
## Admin
|
|
28
|
+
`Admin.get_login`
|
|
29
|
+
|
|
30
|
+
Returns the user name (only) of the current login.
|
|
31
|
+
|
|
32
|
+
```
|
|
33
|
+
Admin.get_user(name, options = {})
|
|
34
|
+
Admin.get_user(uid, options = {})
|
|
35
|
+
```
|
|
36
|
+
|
|
37
|
+
Returns a User object based on `name` or `uid`. The `options` hash is
|
|
38
|
+
for MS Windows only, and allows you to restrict the search based on the
|
|
39
|
+
options you provide, e.g. 'domain' or 'localaccount'.
|
|
40
|
+
|
|
41
|
+
```
|
|
42
|
+
Admin.get_group(name, options = {})
|
|
43
|
+
Admin.get_group(gid, options = {})
|
|
44
|
+
```
|
|
45
|
+
|
|
46
|
+
Returns a Group object based on `name` or `uid`. The `options` hash is
|
|
47
|
+
for MS Windows only, and allows you to restrict the search based on the
|
|
48
|
+
options you provide, e.g. 'domain' or 'localaccount'.
|
|
49
|
+
|
|
50
|
+
`Admin.groups(options = {})`
|
|
51
|
+
|
|
52
|
+
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
|
+
|
|
59
|
+
Returns an Array of User objects.
|
|
60
|
+
|
|
61
|
+
The `options` hash is for MS Windows only, and allows you to restrict the
|
|
62
|
+
search based on the options you provide, e.g. 'domain' or 'localaccount'.
|
|
63
|
+
|
|
64
|
+
## User class
|
|
65
|
+
### User (Windows)
|
|
66
|
+
The User class has the following attributes on MS Windows systems:
|
|
67
|
+
|
|
68
|
+
* account_type
|
|
69
|
+
* caption
|
|
70
|
+
* description
|
|
71
|
+
* domain
|
|
72
|
+
* password
|
|
73
|
+
* full_name
|
|
74
|
+
* gid
|
|
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
|
+
* uid
|
|
86
|
+
|
|
87
|
+
### User (Unix)
|
|
88
|
+
The User class has the following attributes on Unix systems:
|
|
89
|
+
|
|
90
|
+
* name
|
|
91
|
+
* passwd
|
|
92
|
+
* uid
|
|
93
|
+
* gid
|
|
94
|
+
* dir
|
|
95
|
+
* shell
|
|
96
|
+
* gecos
|
|
97
|
+
* quota
|
|
98
|
+
* age
|
|
99
|
+
* class
|
|
100
|
+
* comment
|
|
101
|
+
* change
|
|
102
|
+
* expire
|
|
103
|
+
|
|
104
|
+
## Group Classes
|
|
105
|
+
### Group (Windows)
|
|
106
|
+
The Group class has the following attributes on MS Windows systems:
|
|
107
|
+
|
|
108
|
+
* caption
|
|
109
|
+
* description
|
|
110
|
+
* domain
|
|
111
|
+
* install_date
|
|
112
|
+
* name
|
|
113
|
+
* sid
|
|
114
|
+
* status
|
|
115
|
+
* gid
|
|
116
|
+
* local?
|
|
117
|
+
|
|
118
|
+
### Group (Unix)
|
|
119
|
+
The Group class has the following attributes on Unix systems:
|
|
120
|
+
|
|
121
|
+
* name
|
|
122
|
+
* gid
|
|
123
|
+
* members
|
|
124
|
+
* passwd
|
|
125
|
+
|
|
126
|
+
## Error Classes
|
|
127
|
+
`Admin::Error < StandardError`
|
|
128
|
+
|
|
129
|
+
Raised if anything goes wrong with any of the above methods.
|
|
130
|
+
|
|
131
|
+
## Developer's Notes
|
|
132
|
+
### MS Windows
|
|
133
|
+
The Windows version now uses a win32ole + WMI approach to getting
|
|
134
|
+
information. This means that the WMI service must be running on the
|
|
135
|
+
target machine in order to work (which it is, by default).
|
|
136
|
+
|
|
137
|
+
### UNIX
|
|
138
|
+
The underlying implementation is similar to core Ruby's Etc implementation.
|
|
139
|
+
But, in addition to the different interface, I use the re-entrant version
|
|
140
|
+
of the appropriate functions when available.
|
|
141
|
+
|
|
142
|
+
## Future Plans
|
|
143
|
+
* Make the User and Group objects comparable.
|
|
144
|
+
* Add ability to add, configure and delete users on Unix platforms.
|
|
145
|
+
|
|
146
|
+
## Known Bugs
|
|
147
|
+
None that I'm aware of. If you find any, please log them on the project page at:
|
|
148
|
+
|
|
149
|
+
https://github.com/djberg96/sys-admin
|
|
150
|
+
|
|
151
|
+
## License
|
|
152
|
+
Apache-2.0
|
|
153
|
+
|
|
154
|
+
## Copyright
|
|
155
|
+
(C) 2005-2020, Daniel J. Berger
|
|
156
|
+
All Rights Reserved
|
|
157
|
+
|
|
158
|
+
## Author
|
|
159
|
+
Daniel J. Berger
|
data/Rakefile
CHANGED
|
@@ -1,47 +1,47 @@
|
|
|
1
|
-
require 'rake'
|
|
2
|
-
require 'rake/clean'
|
|
3
|
-
require 'rake/testtask'
|
|
4
|
-
require 'rbconfig'
|
|
5
|
-
|
|
6
|
-
CLEAN.include("**/*.gem", "**/*.rbx", "**/*.rbc", "ruby.core")
|
|
7
|
-
|
|
8
|
-
namespace :gem do
|
|
9
|
-
desc "Create the sys-uname gem"
|
|
10
|
-
task :create => [:clean] do
|
|
11
|
-
require 'rubygems/package'
|
|
12
|
-
spec = eval(IO.read('sys-admin.gemspec'))
|
|
13
|
-
spec.signing_key = File.join(Dir.home, '.ssh', 'gem-private_key.pem')
|
|
14
|
-
Gem::Package.build(spec, true)
|
|
15
|
-
end
|
|
16
|
-
|
|
17
|
-
desc "Install the sys-uname gem"
|
|
18
|
-
task :install => [:create] do
|
|
19
|
-
file = Dir["*.gem"].first
|
|
20
|
-
sh "gem install -l #{file}"
|
|
21
|
-
end
|
|
22
|
-
end
|
|
23
|
-
|
|
24
|
-
Rake::TestTask.new('test') do |t|
|
|
25
|
-
case RbConfig::CONFIG['host_os']
|
|
26
|
-
when /darwin|osx/i
|
|
27
|
-
t.libs << 'lib/darwin'
|
|
28
|
-
when /linux/i
|
|
29
|
-
t.libs << 'lib/linux'
|
|
30
|
-
when /sunos|solaris/i
|
|
31
|
-
t.libs << 'lib/sunos'
|
|
32
|
-
when /bsd/i
|
|
33
|
-
t.libs << 'lib/bsd'
|
|
34
|
-
when /windows|win32|mingw|cygwin|dos/i
|
|
35
|
-
t.libs << 'lib/windows'
|
|
36
|
-
else
|
|
37
|
-
t.libs << 'lib/unix'
|
|
38
|
-
end
|
|
39
|
-
|
|
40
|
-
t.warning = true
|
|
41
|
-
t.verbose = true
|
|
42
|
-
|
|
43
|
-
t.libs << 'test'
|
|
44
|
-
t.test_files = FileList['test/test_sys_admin.rb']
|
|
45
|
-
end
|
|
46
|
-
|
|
47
|
-
task :default => :test
|
|
1
|
+
require 'rake'
|
|
2
|
+
require 'rake/clean'
|
|
3
|
+
require 'rake/testtask'
|
|
4
|
+
require 'rbconfig'
|
|
5
|
+
|
|
6
|
+
CLEAN.include("**/*.gem", "**/*.rbx", "**/*.rbc", "ruby.core")
|
|
7
|
+
|
|
8
|
+
namespace :gem do
|
|
9
|
+
desc "Create the sys-uname gem"
|
|
10
|
+
task :create => [:clean] do
|
|
11
|
+
require 'rubygems/package'
|
|
12
|
+
spec = eval(IO.read('sys-admin.gemspec'))
|
|
13
|
+
spec.signing_key = File.join(Dir.home, '.ssh', 'gem-private_key.pem')
|
|
14
|
+
Gem::Package.build(spec, true)
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
desc "Install the sys-uname gem"
|
|
18
|
+
task :install => [:create] do
|
|
19
|
+
file = Dir["*.gem"].first
|
|
20
|
+
sh "gem install -l #{file}"
|
|
21
|
+
end
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
Rake::TestTask.new('test') do |t|
|
|
25
|
+
case RbConfig::CONFIG['host_os']
|
|
26
|
+
when /darwin|osx/i
|
|
27
|
+
t.libs << 'lib/darwin'
|
|
28
|
+
when /linux/i
|
|
29
|
+
t.libs << 'lib/linux'
|
|
30
|
+
when /sunos|solaris/i
|
|
31
|
+
t.libs << 'lib/sunos'
|
|
32
|
+
when /bsd/i
|
|
33
|
+
t.libs << 'lib/bsd'
|
|
34
|
+
when /windows|win32|mingw|cygwin|dos/i
|
|
35
|
+
t.libs << 'lib/windows'
|
|
36
|
+
else
|
|
37
|
+
t.libs << 'lib/unix'
|
|
38
|
+
end
|
|
39
|
+
|
|
40
|
+
t.warning = true
|
|
41
|
+
t.verbose = true
|
|
42
|
+
|
|
43
|
+
t.libs << 'test'
|
|
44
|
+
t.test_files = FileList['test/test_sys_admin.rb']
|
|
45
|
+
end
|
|
46
|
+
|
|
47
|
+
task :default => :test
|
data/certs/djberg96_pub.pem
CHANGED
|
@@ -1,26 +1,26 @@
|
|
|
1
1
|
-----BEGIN CERTIFICATE-----
|
|
2
2
|
MIIEcDCCAtigAwIBAgIBATANBgkqhkiG9w0BAQsFADA/MREwDwYDVQQDDAhkamJl
|
|
3
3
|
cmc5NjEVMBMGCgmSJomT8ixkARkWBWdtYWlsMRMwEQYKCZImiZPyLGQBGRYDY29t
|
|
4
|
-
|
|
4
|
+
MB4XDTE4MDMxODE1MjIwN1oXDTI4MDMxNTE1MjIwN1owPzERMA8GA1UEAwwIZGpi
|
|
5
5
|
ZXJnOTYxFTATBgoJkiaJk/IsZAEZFgVnbWFpbDETMBEGCgmSJomT8ixkARkWA2Nv
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
6
|
+
bTCCAaIwDQYJKoZIhvcNAQEBBQADggGPADCCAYoCggGBALgfaroVM6CI06cxr0/h
|
|
7
|
+
A+j+pc8fgpRgBVmHFaFunq28GPC3IvW7Nvc3Y8SnAW7pP1EQIbhlwRIaQzJ93/yj
|
|
8
|
+
u95KpkP7tA9erypnV7dpzBkzNlX14ACaFD/6pHoXoe2ltBxk3CCyyzx70mTqJpph
|
|
9
|
+
75IB03ni9a8yqn8pmse+s83bFJOAqddSj009sGPcQO+QOWiNxqYv1n5EHcvj2ebO
|
|
10
|
+
6hN7YTmhx7aSia4qL/quc4DlIaGMWoAhvML7u1fmo53CYxkKskfN8MOecq2vfEmL
|
|
11
|
+
iLu+SsVVEAufMDDFMXMJlvDsviolUSGMSNRTujkyCcJoXKYYxZSNtIiyd9etI0X3
|
|
12
|
+
ctu0uhrFyrMZXCedutvXNjUolD5r9KGBFSWH1R9u2I3n3SAyFF2yzv/7idQHLJJq
|
|
13
|
+
74BMnx0FIq6fCpu5slAipvxZ3ZkZpEXZFr3cIBtO1gFvQWW7E/Y3ijliWJS1GQFq
|
|
14
|
+
058qERadHGu1yu1dojmFRo6W2KZvY9al2yIlbkpDrD5MYQIDAQABo3cwdTAJBgNV
|
|
15
|
+
HRMEAjAAMAsGA1UdDwQEAwIEsDAdBgNVHQ4EFgQUFZsMapgzJimzsbaBG2Tm8j5e
|
|
16
|
+
AzgwHQYDVR0RBBYwFIESZGpiZXJnOTZAZ21haWwuY29tMB0GA1UdEgQWMBSBEmRq
|
|
17
|
+
YmVyZzk2QGdtYWlsLmNvbTANBgkqhkiG9w0BAQsFAAOCAYEAW2tnYixXQtKxgGXq
|
|
18
|
+
/3iSWG2bLwvxS4go3srO+aRXZHrFUMlJ5W0mCxl03aazxxKTsVVpZD8QZxvK91OQ
|
|
19
|
+
h9zr9JBYqCLcCVbr8SkmYCi/laxIZxsNE5YI8cC8vvlLI7AMgSfPSnn/Epq1GjGY
|
|
20
|
+
6L1iRcEDtanGCIvjqlCXO9+BmsnCfEVehqZkQHeYczA03tpOWb6pon2wzvMKSsKH
|
|
21
|
+
ks0ApVdstSLz1kzzAqem/uHdG9FyXdbTAwH1G4ZPv69sQAFAOCgAqYmdnzedsQtE
|
|
22
|
+
1LQfaQrx0twO+CZJPcRLEESjq8ScQxWRRkfuh2VeR7cEU7L7KqT10mtUwrvw7APf
|
|
23
|
+
DYoeCY9KyjIBjQXfbj2ke5u1hZj94Fsq9FfbEQg8ygCgwThnmkTrrKEiMSs3alYR
|
|
24
|
+
ORVCZpRuCPpmC8qmqxUnARDArzucjaclkxjLWvCVHeFa9UP7K3Nl9oTjJNv+7/jM
|
|
25
|
+
WZs4eecIcUc4tKdHxcAJ0MO/Dkqq7hGaiHpwKY76wQ1+8xAh
|
|
26
26
|
-----END CERTIFICATE-----
|
data/doc/sys-admin-unix.txt
CHANGED
|
@@ -1,162 +1,162 @@
|
|
|
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-2014, 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
|
|
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-2014, 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
|