sys-admin 1.7.4 → 1.8.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- checksums.yaml.gz.sig +0 -0
- data/{CHANGES.rdoc → CHANGES.md} +54 -26
- data/Gemfile +2 -0
- data/{MANIFEST.rdoc → MANIFEST.md} +4 -3
- data/{README.rdoc → README.md} +55 -44
- data/Rakefile +13 -18
- data/lib/bsd/sys/admin.rb +13 -7
- data/lib/darwin/sys/admin.rb +38 -17
- data/lib/linux/sys/admin.rb +13 -14
- data/lib/sunos/sys/admin.rb +12 -5
- data/lib/sys/admin/common.rb +3 -6
- data/lib/sys/admin.rb +1 -1
- data/lib/unix/sys/admin.rb +7 -5
- data/lib/windows/sys/admin.rb +324 -303
- data/spec/spec_helper.rb +13 -0
- data/spec/sys_admin_unix_spec.rb +263 -0
- data/spec/sys_admin_version_spec.rb +11 -0
- data/spec/sys_admin_windows_spec.rb +347 -0
- data/sys-admin.gemspec +10 -5
- data.tar.gz.sig +0 -0
- metadata +37 -54
- metadata.gz.sig +0 -0
- data/test/test_sys_admin.rb +0 -23
- data/test/test_sys_admin_unix.rb +0 -260
- data/test/test_sys_admin_windows.rb +0 -337
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d20b0abf74cb8d4769f69346ac22ade3d1336bd10d3b6f83eeca2865ab9b85fe
|
4
|
+
data.tar.gz: 7c56cb4dec18928e3ea4fb1371e9c3f4e660fb5ec94519b0385a1448c07e0d84
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 55d12a7b5d4999eec9801b60a06d1da16bfb2879a4270b0d5188b7d20a397a170619fb0dc75f9fd394952c02e3228d686ff9c908f15a38750220bea7eb2a2e9d
|
7
|
+
data.tar.gz: 3ec5f6ac0690458751f5dd5e2ccaf764b977f1aa46fc6f2acf0c506417c39a4baf704338c712614728fe8d89c289bd76c20dcd62b41f6b28ab5205404ef338e3
|
checksums.yaml.gz.sig
CHANGED
Binary file
|
data/{CHANGES.rdoc → CHANGES.md}
RENAMED
@@ -1,39 +1,67 @@
|
|
1
|
-
|
1
|
+
## 1.8.1 - 25-Sep-2021
|
2
|
+
* The users and get_user methods on Darwin now take an optional :lastlog key
|
3
|
+
that you can set to false in order to significantly speed up those methods
|
4
|
+
at the expense of taking away lastlog information.
|
5
|
+
* Some internal rspec refactoring.
|
6
|
+
|
7
|
+
## 1.8.0 - 26-Aug-2021
|
8
|
+
* Switched from test-unit to rspec, with some tests refactored. The Rakefile
|
9
|
+
and gemspec files were updated accordingly.
|
10
|
+
* The User and Group classes for the Windows implementation are now properly
|
11
|
+
scoped under Sys::Admin instead of just Sys.
|
12
|
+
* Fixed a bug in the get_user and get_group methods on Windows where the WQL
|
13
|
+
it generates internally might not be correct.
|
14
|
+
|
15
|
+
## 1.7.6 - 24-Mar-2021
|
16
|
+
* Changed the implementation for `Admin.get_login` on Linux since the
|
17
|
+
underlying `getlogin` C function is unreliable, especially in certain
|
18
|
+
virtualized environments.
|
19
|
+
* Added win32-security back to the gemspec as a dependency for Windows.
|
20
|
+
I'm not sure why I removed it, and bundler definitely needs it.
|
21
|
+
* Fixed some private access modifiers that weren't actually doing anything.
|
22
|
+
|
23
|
+
## 1.7.5 - 30-Dec-2020
|
24
|
+
* Switched from rdoc to markdown since github isn't rendering rdoc properly.
|
25
|
+
|
26
|
+
## 1.7.4 - 19-Mar-2020
|
27
|
+
* Properly include a LICENSE file as per the Apache-2.0 license.
|
28
|
+
|
29
|
+
## 1.7.3 - 16-Jan-2020
|
2
30
|
* Add explicit .rdoc extension to various rdoc files so that they show up
|
3
31
|
better in github.
|
4
32
|
* Some formatting adjustments to the rdoc files.
|
5
33
|
|
6
|
-
|
34
|
+
## 1.7.2 - 28-Jan-2019
|
7
35
|
* Fixed the license name, was missing a hyphen.
|
8
36
|
* Fixed the homepage in the gemspec.
|
9
37
|
|
10
|
-
|
38
|
+
## 1.7.1 - 19-Mar-2018
|
11
39
|
* Fixed deprecation warnings in tests.
|
12
40
|
* Added gemspec metadata.
|
13
41
|
* Updated cert again, this one should last 10 years.
|
14
42
|
|
15
|
-
|
43
|
+
## 1.7.0 - 21-Feb-2018
|
16
44
|
* Changed the license to Apache 2.0.
|
17
45
|
* VERSION constant is now frozen.
|
18
46
|
* Ignore dependency warnings in gem:create task.
|
19
47
|
* Minor README updates.
|
20
48
|
* Updated cert.
|
21
49
|
|
22
|
-
|
50
|
+
## 1.6.4 - 6-Sep-2015
|
23
51
|
* Added a sys-admin.rb file for convenience.
|
24
52
|
* Set VERSION in a single place.
|
25
53
|
* Assume Rubygems 2.x for Rakefile tasks.
|
26
54
|
* This gem is now signed.
|
27
55
|
|
28
|
-
|
56
|
+
## 1.6.3 - 8-Mar-2014
|
29
57
|
* The Admin#get_group method now handles groups with very large numbers
|
30
58
|
of members more robustly.
|
31
59
|
|
32
|
-
|
60
|
+
## 1.6.2 - 11-Feb-2014
|
33
61
|
* The User#gid method is now supported on MS Windows. It returns the user's
|
34
62
|
primary group ID.
|
35
63
|
|
36
|
-
|
64
|
+
## 1.6.1 - 24-Jan-2014
|
37
65
|
* Added the Admin.add_group_member and Admin.remove_group member methods. These
|
38
66
|
let you add a user to a specific group. Thanks go to Alexey Kolyanov for the
|
39
67
|
idea and the code.
|
@@ -43,7 +71,7 @@
|
|
43
71
|
* Updated the gem:create task in the Rakefile.
|
44
72
|
* Added rake as a development dependency.
|
45
73
|
|
46
|
-
|
74
|
+
## 1.6.0 - 5-Jan-2013
|
47
75
|
* Converted code to use FFI. This mostly only affects the unix flavors.
|
48
76
|
* The Admin.users and Admin.groups methods no longer accept a block.
|
49
77
|
* Some test suite updates.
|
@@ -51,13 +79,13 @@
|
|
51
79
|
separate gems. There is now a single, unified gem that works on all
|
52
80
|
supported platforms.
|
53
81
|
|
54
|
-
|
82
|
+
## 1.5.6 - 30-Jul-2011
|
55
83
|
* Fixed issue for non-gnu platforms where it would use the wrong function
|
56
84
|
prototype because the Ruby core team took it upon themselves to explicitly
|
57
85
|
defined _GNU_SOURCE in config.h in 1.8.7 and later for reasons that baffle me.
|
58
86
|
* Some tests on Windows are now skipped unless run with elevated security.
|
59
87
|
|
60
|
-
|
88
|
+
## 1.5.5 - 5-Jul-2011
|
61
89
|
* Modified lastlog handling, and ignore getpwent_r and getgrent_r, on AIX.
|
62
90
|
Thanks go to Rick Ohnemus for the spot and patches.
|
63
91
|
* Explicitly set spec.cpu on Windows to 'universal' in the gem creation task.
|
@@ -65,21 +93,21 @@
|
|
65
93
|
being generated was incorrect if no options were passed. Thanks go to
|
66
94
|
Matthew Brown for the spot.
|
67
95
|
|
68
|
-
|
96
|
+
## 1.5.4 - 7-Oct-2010
|
69
97
|
* Prefer the getlastlogx() function over lastlog() where supported.
|
70
98
|
|
71
|
-
|
99
|
+
## 1.5.3 - 6-Oct-2010
|
72
100
|
* Refactored the Rakefile. The old installation tasks have been replaced
|
73
101
|
with gem build and install tasks. In addition, the platform handling has
|
74
102
|
been updated for MS Windows.
|
75
103
|
* Portions of the gemspec have been moved into the Rakefile gem tasks.
|
76
104
|
* Deploying the mingw gem by default for MS Windows now.
|
77
105
|
|
78
|
-
|
106
|
+
## 1.5.2 - 2-Aug-2009
|
79
107
|
* Now compatible with Ruby 1.9.x.
|
80
108
|
* Added test-unit as a development dependency.
|
81
109
|
|
82
|
-
|
110
|
+
## 1.5.1 - 23-Jul-2009
|
83
111
|
* Added the User#dir attribute. This attribute contains a user's home
|
84
112
|
directory if set, or nil if it isn't.
|
85
113
|
* User objects returned by the Admin.users method now include the uid.
|
@@ -87,7 +115,7 @@
|
|
87
115
|
* Added win32-security as a dependency.
|
88
116
|
* Changed license to Artistic 2.0.
|
89
117
|
|
90
|
-
|
118
|
+
## 1.5.0 - 29-Mar-2009
|
91
119
|
* INTERFACE CHANGE (WINDOWS ONLY): The interface for MS Windows has undergone
|
92
120
|
a radical change. Most methods now accept a hash of options that are
|
93
121
|
passed directly to the underlying WMI class. Please see the documentation
|
@@ -104,14 +132,14 @@
|
|
104
132
|
get lastlog information even if the lastlog.h or utmp.h headers couldn't
|
105
133
|
be found.
|
106
134
|
|
107
|
-
|
135
|
+
## 1.4.4 - 19-Nov-2008
|
108
136
|
* Added the User#uid method for MS Windows (which is just the user's relative
|
109
137
|
identifier).
|
110
138
|
* Now requires test-unit 2.x.
|
111
139
|
* Some updates to the test suite to take advantage of test-unit 2.x features.
|
112
140
|
* Some minor gemspec tweaks.
|
113
141
|
|
114
|
-
|
142
|
+
## 1.4.3 - 2-Mar-2008
|
115
143
|
* The block form of Admin.users now properly ensures that endpwent() is
|
116
144
|
called. Likewise, the block form of Admin.groups now properly ensures
|
117
145
|
that endgrent() is called. This would only have been an issue if you
|
@@ -119,7 +147,7 @@
|
|
119
147
|
* The AdminError class is now Admin::Error.
|
120
148
|
* Some internal directory layout changes.
|
121
149
|
|
122
|
-
|
150
|
+
## 1.4.2 - 26-Jun-2007
|
123
151
|
* Fixed a bug in the Admin.get_login method where it would return junk
|
124
152
|
if the underlying getlogin() function failed (Unix). Thanks go to Gonzalo
|
125
153
|
Garramuno for the spot. This bug also resulted in some refactoring of the
|
@@ -127,13 +155,13 @@
|
|
127
155
|
* Removed the install.rb file. The logic in that file has been moved directly
|
128
156
|
into the Rakefile.
|
129
157
|
|
130
|
-
|
158
|
+
## 1.4.1 - 21-Mar-2007
|
131
159
|
* Bug fix for OS X. Thanks go to an anonymous user for the spot.
|
132
160
|
* Added a Rakefile. Building, testing and installing should now use the
|
133
161
|
Rake tasks (for non-gem installs).
|
134
162
|
* Much more inline documentation, especially for User and Group attributes.
|
135
163
|
|
136
|
-
|
164
|
+
## 1.4.0 - 20-Jan-2007
|
137
165
|
* Added the following methods: add_local_user, config_local_user,
|
138
166
|
delete_local_user, add_global_group, config_global_group, and
|
139
167
|
delete_global_group. MS Windows only at the moment.
|
@@ -149,18 +177,18 @@
|
|
149
177
|
integer.
|
150
178
|
* Renamed tc_win32.rb to tc_windows.rb
|
151
179
|
|
152
|
-
|
180
|
+
## 1.3.1 - 29-Jun-2005
|
153
181
|
* Fixed a bug where the inability to read the lastlog file caused an error.
|
154
182
|
From now on that error is ignored, and the lastlog attributes of the User
|
155
183
|
object are set to nil.
|
156
184
|
* Added a beta version of Admin.delete_user (Windows only).
|
157
185
|
|
158
|
-
|
186
|
+
## 1.3.0 - 3-Jun-2005
|
159
187
|
* Bug fixes for Linux.
|
160
188
|
* Removed the version.h file - no longer needed since the Win32 version is
|
161
189
|
pure Ruby.
|
162
190
|
|
163
|
-
|
191
|
+
## 1.2.0 - 30-Apr-2005
|
164
192
|
* Replaced the Win32 version with a pure Ruby version that uses Win32API and
|
165
193
|
win32ole + WMI.
|
166
194
|
* The LocalGroup class no longer exists in the Win32 version. Instead, it is
|
@@ -170,7 +198,7 @@
|
|
170
198
|
over global accounts.
|
171
199
|
* Corresponding doc changes and test suite changes.
|
172
200
|
|
173
|
-
|
201
|
+
## 1.1.0 - 1-Apr-2005
|
174
202
|
* Fixed bug where a segfault could occur when trying to retrieve a user or
|
175
203
|
group by an ID that didn't exist (Unix).
|
176
204
|
* Added tests for intentional failures.
|
@@ -178,5 +206,5 @@
|
|
178
206
|
* Modified the way User objects are created internally (Unix).
|
179
207
|
* Fixed a bug in the User#shell attribute (Unix).
|
180
208
|
|
181
|
-
|
209
|
+
## 1.0.0 - 25-Mar-2005
|
182
210
|
* Initial release
|
data/Gemfile
ADDED
data/{README.rdoc → README.md}
RENAMED
@@ -1,62 +1,73 @@
|
|
1
|
-
|
1
|
+
[![Ruby](https://github.com/djberg96/sys-admin/actions/workflows/ruby.yml/badge.svg)](https://github.com/djberg96/sys-admin/actions/workflows/ruby.yml)
|
2
|
+
|
3
|
+
## Description
|
2
4
|
The sys-admin library is a unified, cross platform replacement for the Etc module.
|
3
5
|
|
4
|
-
|
5
|
-
|
6
|
+
## Installation
|
7
|
+
`gem install sys-admin`
|
8
|
+
|
9
|
+
## Adding the trusted cert
|
10
|
+
`gem cert --add <(curl -Ls https://raw.githubusercontent.com/djberg96/sys-admin/main/certs/djberg96_pub.pem)`
|
6
11
|
|
7
|
-
|
8
|
-
|
9
|
-
|
12
|
+
## Synopsis
|
13
|
+
```ruby
|
14
|
+
require 'sys/admin' # or sys-admin
|
15
|
+
include Sys
|
10
16
|
|
11
|
-
|
12
|
-
|
17
|
+
# Returns an Array of User objects
|
18
|
+
a = Admin.users
|
13
19
|
|
14
|
-
|
15
|
-
|
20
|
+
# Returns an Array of Group objects
|
21
|
+
g = Admin.groups
|
16
22
|
|
17
|
-
|
18
|
-
|
19
|
-
|
23
|
+
# Get information about a particular user
|
24
|
+
p Admin.get_user("nobody")
|
25
|
+
p Admin.get_user("nobody", :localaccount => true)
|
20
26
|
|
21
|
-
|
22
|
-
|
23
|
-
|
27
|
+
# Get information about a particular group
|
28
|
+
p Admin.get_group("adm")
|
29
|
+
p Admin.get_group("adm", :localaccount => true)
|
30
|
+
```
|
24
31
|
|
25
|
-
|
26
|
-
Admin.get_login
|
32
|
+
## Admin
|
33
|
+
`Admin.get_login`
|
27
34
|
|
28
35
|
Returns the user name (only) of the current login.
|
29
36
|
|
30
|
-
|
31
|
-
|
37
|
+
```
|
38
|
+
Admin.get_user(name, options = {})
|
39
|
+
Admin.get_user(uid, options = {})
|
40
|
+
```
|
32
41
|
|
33
|
-
Returns a User object based on
|
42
|
+
Returns a User object based on `name` or `uid`. The `options` hash is
|
34
43
|
for MS Windows only, and allows you to restrict the search based on the
|
35
44
|
options you provide, e.g. 'domain' or 'localaccount'.
|
36
45
|
|
37
|
-
|
38
|
-
|
46
|
+
```
|
47
|
+
Admin.get_group(name, options = {})
|
48
|
+
Admin.get_group(gid, options = {})
|
49
|
+
```
|
39
50
|
|
40
|
-
Returns a Group object based on
|
51
|
+
Returns a Group object based on `name` or `uid`. The `options` hash is
|
41
52
|
for MS Windows only, and allows you to restrict the search based on the
|
42
53
|
options you provide, e.g. 'domain' or 'localaccount'.
|
43
54
|
|
44
|
-
|
55
|
+
`Admin.groups(options = {})`
|
45
56
|
|
46
57
|
Returns an Array of Group objects.
|
47
58
|
|
48
|
-
The
|
59
|
+
The `options` hash is for MS Windows only, and allows you to restrict the
|
49
60
|
search based on the options you provide, e.g. 'domain' or 'localaccount'.
|
50
61
|
|
51
|
-
|
62
|
+
`Admin.users(options = {})`
|
52
63
|
|
53
64
|
Returns an Array of User objects.
|
54
65
|
|
55
|
-
The
|
66
|
+
The `options` hash is for MS Windows only, and allows you to restrict the
|
56
67
|
search based on the options you provide, e.g. 'domain' or 'localaccount'.
|
57
68
|
|
58
|
-
|
59
|
-
|
69
|
+
## User class
|
70
|
+
### User (Windows)
|
60
71
|
The User class has the following attributes on MS Windows systems:
|
61
72
|
|
62
73
|
* account_type
|
@@ -78,7 +89,7 @@ The User class has the following attributes on MS Windows systems:
|
|
78
89
|
* password_required?
|
79
90
|
* uid
|
80
91
|
|
81
|
-
|
92
|
+
### User (Unix)
|
82
93
|
The User class has the following attributes on Unix systems:
|
83
94
|
|
84
95
|
* name
|
@@ -95,8 +106,8 @@ The User class has the following attributes on Unix systems:
|
|
95
106
|
* change
|
96
107
|
* expire
|
97
108
|
|
98
|
-
|
99
|
-
|
109
|
+
## Group Classes
|
110
|
+
### Group (Windows)
|
100
111
|
The Group class has the following attributes on MS Windows systems:
|
101
112
|
|
102
113
|
* caption
|
@@ -109,7 +120,7 @@ The Group class has the following attributes on MS Windows systems:
|
|
109
120
|
* gid
|
110
121
|
* local?
|
111
122
|
|
112
|
-
|
123
|
+
### Group (Unix)
|
113
124
|
The Group class has the following attributes on Unix systems:
|
114
125
|
|
115
126
|
* name
|
@@ -117,37 +128,37 @@ The Group class has the following attributes on Unix systems:
|
|
117
128
|
* members
|
118
129
|
* passwd
|
119
130
|
|
120
|
-
|
121
|
-
|
131
|
+
## Error Classes
|
132
|
+
`Admin::Error < StandardError`
|
122
133
|
|
123
134
|
Raised if anything goes wrong with any of the above methods.
|
124
135
|
|
125
|
-
|
126
|
-
|
136
|
+
## Developer's Notes
|
137
|
+
### MS Windows
|
127
138
|
The Windows version now uses a win32ole + WMI approach to getting
|
128
139
|
information. This means that the WMI service must be running on the
|
129
140
|
target machine in order to work (which it is, by default).
|
130
141
|
|
131
|
-
|
142
|
+
### UNIX
|
132
143
|
The underlying implementation is similar to core Ruby's Etc implementation.
|
133
144
|
But, in addition to the different interface, I use the re-entrant version
|
134
145
|
of the appropriate functions when available.
|
135
146
|
|
136
|
-
|
147
|
+
## Future Plans
|
137
148
|
* Make the User and Group objects comparable.
|
138
149
|
* Add ability to add, configure and delete users on Unix platforms.
|
139
150
|
|
140
|
-
|
151
|
+
## Known Bugs
|
141
152
|
None that I'm aware of. If you find any, please log them on the project page at:
|
142
153
|
|
143
154
|
https://github.com/djberg96/sys-admin
|
144
155
|
|
145
|
-
|
156
|
+
## License
|
146
157
|
Apache-2.0
|
147
158
|
|
148
|
-
|
159
|
+
## Copyright
|
149
160
|
(C) 2005-2020, Daniel J. Berger
|
150
161
|
All Rights Reserved
|
151
162
|
|
152
|
-
|
163
|
+
## Author
|
153
164
|
Daniel J. Berger
|
data/Rakefile
CHANGED
@@ -1,17 +1,17 @@
|
|
1
1
|
require 'rake'
|
2
2
|
require 'rake/clean'
|
3
|
-
require '
|
3
|
+
require 'rspec/core/rake_task'
|
4
4
|
require 'rbconfig'
|
5
5
|
|
6
|
-
CLEAN.include("**/*.gem", "**/*.rbx", "**/*.rbc", "ruby.core")
|
6
|
+
CLEAN.include("**/*.gem", "**/*.rbx", "**/*.rbc", "ruby.core", "**/*.lock")
|
7
7
|
|
8
8
|
namespace :gem do
|
9
9
|
desc "Create the sys-uname gem"
|
10
10
|
task :create => [:clean] do
|
11
11
|
require 'rubygems/package'
|
12
|
-
spec =
|
12
|
+
spec = Gem::Specification.load('sys-admin.gemspec')
|
13
13
|
spec.signing_key = File.join(Dir.home, '.ssh', 'gem-private_key.pem')
|
14
|
-
Gem::Package.build(spec
|
14
|
+
Gem::Package.build(spec)
|
15
15
|
end
|
16
16
|
|
17
17
|
desc "Install the sys-uname gem"
|
@@ -21,27 +21,22 @@ namespace :gem do
|
|
21
21
|
end
|
22
22
|
end
|
23
23
|
|
24
|
-
|
24
|
+
desc "Run the specs for the sys-admin library"
|
25
|
+
RSpec::Core::RakeTask.new(:spec) do |t|
|
25
26
|
case RbConfig::CONFIG['host_os']
|
26
27
|
when /darwin|osx/i
|
27
|
-
t.
|
28
|
+
t.rspec_opts = '-Ilib/darwin'
|
28
29
|
when /linux/i
|
29
|
-
t.
|
30
|
+
t.rspec_opts = '-Ilib/linux'
|
30
31
|
when /sunos|solaris/i
|
31
|
-
t.
|
32
|
+
t.rspec_opts = '-Ilib/sunos'
|
32
33
|
when /bsd/i
|
33
|
-
t.
|
34
|
+
t.rspec_opts = '-Ilib/bsd'
|
34
35
|
when /windows|win32|mingw|cygwin|dos/i
|
35
|
-
t.
|
36
|
+
t.rspec_opts = '-Ilib/windows'
|
36
37
|
else
|
37
|
-
t.
|
38
|
+
t.rspec_opts = '-Ilib/unix'
|
38
39
|
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
40
|
end
|
46
41
|
|
47
|
-
task :default => :
|
42
|
+
task :default => :spec
|
data/lib/bsd/sys/admin.rb
CHANGED
@@ -6,10 +6,9 @@ require 'rbconfig'
|
|
6
6
|
|
7
7
|
module Sys
|
8
8
|
class Admin
|
9
|
-
private
|
10
|
-
|
11
9
|
# :no-doc:
|
12
10
|
BUF_MAX = 65536 # Max buffer for retry
|
11
|
+
private_constant :BUF_MAX
|
13
12
|
|
14
13
|
# I'm making some aliases here to prevent potential conflicts
|
15
14
|
attach_function :open_c, :open, [:string, :int], :int
|
@@ -22,8 +21,7 @@ module Sys
|
|
22
21
|
attach_function :getgrnam_r, [:string, :pointer, :pointer, :size_t, :pointer], :int
|
23
22
|
attach_function :getgrgid_r, [:long, :pointer, :pointer, :size_t, :pointer], :int
|
24
23
|
|
25
|
-
private_class_method :getlogin_r, :getpwnam_r, :getpwuid_r, :getgrnam_r
|
26
|
-
private_class_method :getgrgid_r
|
24
|
+
private_class_method :getlogin_r, :getpwnam_r, :getpwuid_r, :getgrnam_r, :getgrgid_r
|
27
25
|
private_class_method :open_c, :pread_c, :close_c
|
28
26
|
|
29
27
|
# struct passwd from /usr/include/pwd.h
|
@@ -48,6 +46,8 @@ module Sys
|
|
48
46
|
layout(*fields)
|
49
47
|
end
|
50
48
|
|
49
|
+
private_constant :PasswdStruct
|
50
|
+
|
51
51
|
# struct group from /usr/include/grp.h
|
52
52
|
class GroupStruct < FFI::Struct
|
53
53
|
layout(
|
@@ -58,6 +58,8 @@ module Sys
|
|
58
58
|
)
|
59
59
|
end
|
60
60
|
|
61
|
+
private_constant :GroupStruct
|
62
|
+
|
61
63
|
# I'm blending the timeval struct in directly here
|
62
64
|
class LastlogStruct < FFI::Struct
|
63
65
|
layout(
|
@@ -67,7 +69,7 @@ module Sys
|
|
67
69
|
)
|
68
70
|
end
|
69
71
|
|
70
|
-
|
72
|
+
private_constant :LastlogStruct
|
71
73
|
|
72
74
|
# Returns the login for the current process.
|
73
75
|
#
|
@@ -192,8 +194,6 @@ module Sys
|
|
192
194
|
groups
|
193
195
|
end
|
194
196
|
|
195
|
-
private
|
196
|
-
|
197
197
|
# Takes a GroupStruct and converts it to a Group object.
|
198
198
|
def self.get_group_from_struct(grp)
|
199
199
|
Group.new do |g|
|
@@ -204,6 +204,8 @@ module Sys
|
|
204
204
|
end
|
205
205
|
end
|
206
206
|
|
207
|
+
private_class_method :get_group_from_struct
|
208
|
+
|
207
209
|
# Takes a UserStruct and converts it to a User object.
|
208
210
|
def self.get_user_from_struct(pwd)
|
209
211
|
user = User.new do |u|
|
@@ -230,6 +232,8 @@ module Sys
|
|
230
232
|
user
|
231
233
|
end
|
232
234
|
|
235
|
+
private_class_method :get_user_from_struct
|
236
|
+
|
233
237
|
# Get lastlog information for the given user.
|
234
238
|
def self.get_lastlog_info(uid)
|
235
239
|
logfile = '/var/log/lastlog'
|
@@ -252,5 +256,7 @@ module Sys
|
|
252
256
|
|
253
257
|
lastlog
|
254
258
|
end
|
259
|
+
|
260
|
+
private_class_method :get_lastlog_info
|
255
261
|
end
|
256
262
|
end
|