sys-admin 1.7.1 → 1.7.6
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 +4 -4
- checksums.yaml.gz.sig +0 -0
- data.tar.gz.sig +0 -0
- data/{CHANGES → CHANGES.md} +48 -25
- data/Gemfile +3 -0
- data/LICENSE +177 -0
- data/{MANIFEST → MANIFEST.md} +5 -3
- data/README.md +159 -0
- data/Rakefile +2 -2
- data/lib/bsd/sys/admin.rb +13 -7
- data/lib/darwin/sys/admin.rb +14 -7
- data/lib/linux/sys/admin.rb +13 -12
- data/lib/sunos/sys/admin.rb +12 -5
- data/lib/sys/admin.rb +1 -1
- data/lib/sys/admin/common.rb +3 -6
- data/lib/unix/sys/admin.rb +7 -5
- data/lib/windows/sys/admin.rb +13 -10
- data/sys-admin.gemspec +6 -7
- data/test/test_sys_admin.rb +1 -1
- metadata +22 -43
- metadata.gz.sig +0 -0
- data/README +0 -148
data/Rakefile
CHANGED
@@ -3,7 +3,7 @@ require 'rake/clean'
|
|
3
3
|
require 'rake/testtask'
|
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"
|
@@ -11,7 +11,7 @@ namespace :gem do
|
|
11
11
|
require 'rubygems/package'
|
12
12
|
spec = eval(IO.read('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"
|
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
|
data/lib/darwin/sys/admin.rb
CHANGED
@@ -5,10 +5,9 @@ require 'sys/admin/common'
|
|
5
5
|
|
6
6
|
module Sys
|
7
7
|
class Admin
|
8
|
-
private
|
9
|
-
|
10
8
|
# :no-doc:
|
11
9
|
BUF_MAX = 65536 # Max buf size for retry.
|
10
|
+
private_constant :BUF_MAX
|
12
11
|
|
13
12
|
attach_function :getlogin_r, [:pointer, :int], :int
|
14
13
|
attach_function :getpwnam_r, [:string, :pointer, :pointer, :size_t, :pointer], :int
|
@@ -17,8 +16,8 @@ module Sys
|
|
17
16
|
attach_function :getgrgid_r, [:long, :pointer, :pointer, :size_t, :pointer], :int
|
18
17
|
attach_function :getlastlogx, [:long, :pointer], :pointer
|
19
18
|
|
20
|
-
private_class_method :getlogin_r, :getpwnam_r, :getpwuid_r
|
21
|
-
private_class_method :getgrgid_r, :getlastlogx
|
19
|
+
private_class_method :getlogin_r, :getpwnam_r, :getpwuid_r
|
20
|
+
private_class_method :getgrnam_r, :getgrgid_r, :getlastlogx
|
22
21
|
|
23
22
|
# struct passwd from /usr/include/pwd.h
|
24
23
|
class PasswdStruct < FFI::Struct
|
@@ -36,6 +35,8 @@ module Sys
|
|
36
35
|
)
|
37
36
|
end
|
38
37
|
|
38
|
+
private_constant :PasswdStruct
|
39
|
+
|
39
40
|
# struct group from /usr/include/grp.h
|
40
41
|
class GroupStruct < FFI::Struct
|
41
42
|
layout(
|
@@ -46,6 +47,8 @@ module Sys
|
|
46
47
|
)
|
47
48
|
end
|
48
49
|
|
50
|
+
private_constant :GroupStruct
|
51
|
+
|
49
52
|
# I'm blending the timeval struct in directly here
|
50
53
|
class LastlogxStruct < FFI::Struct
|
51
54
|
layout(
|
@@ -56,7 +59,7 @@ module Sys
|
|
56
59
|
)
|
57
60
|
end
|
58
61
|
|
59
|
-
|
62
|
+
private_constant :LastlogxStruct
|
60
63
|
|
61
64
|
# Returns the login for the current process.
|
62
65
|
#
|
@@ -185,8 +188,6 @@ module Sys
|
|
185
188
|
groups
|
186
189
|
end
|
187
190
|
|
188
|
-
private
|
189
|
-
|
190
191
|
# Takes a GroupStruct and converts it to a Group object.
|
191
192
|
def self.get_group_from_struct(grp)
|
192
193
|
Group.new do |g|
|
@@ -197,6 +198,8 @@ module Sys
|
|
197
198
|
end
|
198
199
|
end
|
199
200
|
|
201
|
+
private_class_method :get_group_from_struct
|
202
|
+
|
200
203
|
# Takes a UserStruct and converts it to a User object.
|
201
204
|
def self.get_user_from_struct(pwd)
|
202
205
|
user = User.new do |u|
|
@@ -223,6 +226,8 @@ module Sys
|
|
223
226
|
user
|
224
227
|
end
|
225
228
|
|
229
|
+
private_class_method :get_user_from_struct
|
230
|
+
|
226
231
|
# Gets lastlog information for the given user.
|
227
232
|
def self.get_lastlog_info(uid)
|
228
233
|
lastlog = LastlogxStruct.new
|
@@ -233,5 +238,7 @@ module Sys
|
|
233
238
|
|
234
239
|
ptr.null? ? nil : lastlog
|
235
240
|
end
|
241
|
+
|
242
|
+
private_class_method :get_lastlog_info
|
236
243
|
end
|
237
244
|
end
|
data/lib/linux/sys/admin.rb
CHANGED
@@ -5,10 +5,9 @@ require 'sys/admin/common'
|
|
5
5
|
|
6
6
|
module Sys
|
7
7
|
class Admin
|
8
|
-
private
|
9
|
-
|
10
8
|
# :no-doc:
|
11
9
|
BUF_MAX = 65536 # Absolute max buffer size for retry attempts.
|
10
|
+
private_constant :BUF_MAX
|
12
11
|
|
13
12
|
# I'm making some aliases here to prevent potential conflicts
|
14
13
|
attach_function :open_c, :open, [:string, :int], :int
|
@@ -40,6 +39,8 @@ module Sys
|
|
40
39
|
)
|
41
40
|
end
|
42
41
|
|
42
|
+
private_constant :PasswdStruct
|
43
|
+
|
43
44
|
# struct group from /usr/include/grp.h
|
44
45
|
class GroupStruct < FFI::Struct
|
45
46
|
layout(
|
@@ -50,6 +51,8 @@ module Sys
|
|
50
51
|
)
|
51
52
|
end
|
52
53
|
|
54
|
+
private_constant :GroupStruct
|
55
|
+
|
53
56
|
# I'm blending the timeval struct in directly here
|
54
57
|
class LastlogStruct < FFI::Struct
|
55
58
|
layout(
|
@@ -59,18 +62,12 @@ module Sys
|
|
59
62
|
)
|
60
63
|
end
|
61
64
|
|
62
|
-
|
65
|
+
private_constant :LastlogStruct
|
63
66
|
|
64
67
|
# Returns the login for the current process.
|
65
68
|
#
|
66
69
|
def self.get_login
|
67
|
-
|
68
|
-
|
69
|
-
if getlogin_r(buf, buf.size) != 0
|
70
|
-
raise Error, "getlogin_r function failed: " + strerror(FFI.errno)
|
71
|
-
end
|
72
|
-
|
73
|
-
buf.read_string
|
70
|
+
get_user(geteuid()).name
|
74
71
|
end
|
75
72
|
|
76
73
|
# Returns a User object for the given name or uid. Raises an error
|
@@ -204,8 +201,6 @@ module Sys
|
|
204
201
|
groups
|
205
202
|
end
|
206
203
|
|
207
|
-
private
|
208
|
-
|
209
204
|
# Takes a GroupStruct and converts it to a Group object.
|
210
205
|
def self.get_group_from_struct(grp)
|
211
206
|
Group.new do |g|
|
@@ -216,6 +211,8 @@ module Sys
|
|
216
211
|
end
|
217
212
|
end
|
218
213
|
|
214
|
+
private_class_method :get_group_from_struct
|
215
|
+
|
219
216
|
# Takes a UserStruct and converts it to a User object.
|
220
217
|
def self.get_user_from_struct(pwd)
|
221
218
|
user = User.new do |u|
|
@@ -242,6 +239,8 @@ module Sys
|
|
242
239
|
user
|
243
240
|
end
|
244
241
|
|
242
|
+
private_class_method :get_user_from_struct
|
243
|
+
|
245
244
|
# Note: it seems that Linux, or at least Ubuntu, does not track logins
|
246
245
|
# via GDM (Gnome Display Manager) for some reason, so this may not return
|
247
246
|
# anything useful.
|
@@ -269,5 +268,7 @@ module Sys
|
|
269
268
|
|
270
269
|
lastlog
|
271
270
|
end
|
271
|
+
|
272
|
+
private_class_method :get_lastlog_info
|
272
273
|
end
|
273
274
|
end
|
data/lib/sunos/sys/admin.rb
CHANGED
@@ -5,10 +5,9 @@ require 'sys/admin/common'
|
|
5
5
|
|
6
6
|
module Sys
|
7
7
|
class Admin
|
8
|
-
private
|
9
|
-
|
10
8
|
# :no-doc:
|
11
9
|
BUF_MAX = 65536 # Max buffer size for retry.
|
10
|
+
private_constant :BUF_MAX
|
12
11
|
|
13
12
|
# I'm making some aliases here to prevent potential conflicts
|
14
13
|
attach_function :open_c, :open, [:string, :int], :int
|
@@ -42,6 +41,8 @@ module Sys
|
|
42
41
|
)
|
43
42
|
end
|
44
43
|
|
44
|
+
private_constant :PasswdStruct
|
45
|
+
|
45
46
|
# struct group from /usr/include/grp.h
|
46
47
|
class GroupStruct < FFI::Struct
|
47
48
|
layout(
|
@@ -52,6 +53,8 @@ module Sys
|
|
52
53
|
)
|
53
54
|
end
|
54
55
|
|
56
|
+
private_constant :GroupStruct
|
57
|
+
|
55
58
|
# I'm blending the timeval struct in directly here
|
56
59
|
class LastlogStruct < FFI::Struct
|
57
60
|
layout(
|
@@ -61,7 +64,7 @@ module Sys
|
|
61
64
|
)
|
62
65
|
end
|
63
66
|
|
64
|
-
|
67
|
+
private_constant :LastlogStruct
|
65
68
|
|
66
69
|
# Returns the login for the current process.
|
67
70
|
#
|
@@ -194,8 +197,6 @@ module Sys
|
|
194
197
|
groups
|
195
198
|
end
|
196
199
|
|
197
|
-
private
|
198
|
-
|
199
200
|
# Takes a GroupStruct and converts it to a Group object.
|
200
201
|
def self.get_group_from_struct(grp)
|
201
202
|
Group.new do |g|
|
@@ -206,6 +207,8 @@ module Sys
|
|
206
207
|
end
|
207
208
|
end
|
208
209
|
|
210
|
+
private_class_method :get_group_from_struct
|
211
|
+
|
209
212
|
# Takes a UserStruct and converts it to a User object.
|
210
213
|
def self.get_user_from_struct(pwd)
|
211
214
|
user = User.new do |u|
|
@@ -232,6 +235,8 @@ module Sys
|
|
232
235
|
user
|
233
236
|
end
|
234
237
|
|
238
|
+
private_class_method :get_use_from_struct
|
239
|
+
|
235
240
|
# The use of pread was necessary here because it's a sparse file. Note
|
236
241
|
# also that while Solaris supports the getuserattr function, it doesn't
|
237
242
|
# appear to store anything regarding login information.
|
@@ -257,5 +262,7 @@ module Sys
|
|
257
262
|
|
258
263
|
lastlog
|
259
264
|
end
|
265
|
+
|
266
|
+
private_class_method :get_lastlog_info
|
260
267
|
end
|
261
268
|
end
|
data/lib/sys/admin.rb
CHANGED
data/lib/sys/admin/common.rb
CHANGED
@@ -9,12 +9,11 @@ module Sys
|
|
9
9
|
extend FFI::Library
|
10
10
|
ffi_lib FFI::Library::LIBC
|
11
11
|
|
12
|
-
private
|
13
|
-
|
14
12
|
attach_function :strerror, [:int], :string
|
15
13
|
|
16
14
|
attach_function :getlogin, [], :string
|
17
15
|
attach_function :getuid, [], :long
|
16
|
+
attach_function :geteuid, [], :long
|
18
17
|
attach_function :getpwnam, [:string], :pointer
|
19
18
|
attach_function :getpwuid, [:long], :pointer
|
20
19
|
attach_function :getpwent, [], :pointer
|
@@ -27,12 +26,10 @@ module Sys
|
|
27
26
|
attach_function :endgrent, [], :void
|
28
27
|
attach_function :setgrent, [], :void
|
29
28
|
|
30
|
-
private_class_method :getlogin, :getuid, :
|
31
|
-
private_class_method :setpwent, :endpwent, :getgrgid, :getgrnam
|
29
|
+
private_class_method :getlogin, :getuid, :geteuid, :getpwnam, :getpwuid
|
30
|
+
private_class_method :getpwent, :setpwent, :endpwent, :getgrgid, :getgrnam
|
32
31
|
private_class_method :getgrent, :endgrent, :setgrent, :strerror
|
33
32
|
|
34
|
-
public
|
35
|
-
|
36
33
|
# Error typically raised if any of the Sys::Admin methods fail.
|
37
34
|
class Error < StandardError; end
|
38
35
|
|
data/lib/unix/sys/admin.rb
CHANGED
@@ -5,8 +5,6 @@ require 'sys/admin/common'
|
|
5
5
|
|
6
6
|
module Sys
|
7
7
|
class Admin
|
8
|
-
private
|
9
|
-
|
10
8
|
class PasswdStruct < FFI::Struct
|
11
9
|
layout(
|
12
10
|
:pw_name, :string,
|
@@ -19,6 +17,8 @@ module Sys
|
|
19
17
|
)
|
20
18
|
end
|
21
19
|
|
20
|
+
private_constant :PasswdStruct
|
21
|
+
|
22
22
|
class GroupStruct < FFI::Struct
|
23
23
|
layout(
|
24
24
|
:gr_name, :string,
|
@@ -28,7 +28,7 @@ module Sys
|
|
28
28
|
)
|
29
29
|
end
|
30
30
|
|
31
|
-
|
31
|
+
private_constant :GroupStruct
|
32
32
|
|
33
33
|
# Returns the login for the current process.
|
34
34
|
#
|
@@ -133,8 +133,6 @@ module Sys
|
|
133
133
|
groups
|
134
134
|
end
|
135
135
|
|
136
|
-
private
|
137
|
-
|
138
136
|
# Takes a GroupStruct and converts it to a Group object.
|
139
137
|
def self.get_group_from_struct(grp)
|
140
138
|
Group.new do |g|
|
@@ -145,6 +143,8 @@ module Sys
|
|
145
143
|
end
|
146
144
|
end
|
147
145
|
|
146
|
+
private_class_method :get_group_from_struct
|
147
|
+
|
148
148
|
# Takes a UserStruct and converts it to a User object.
|
149
149
|
def self.get_user_from_struct(pwd)
|
150
150
|
user = User.new do |u|
|
@@ -159,5 +159,7 @@ module Sys
|
|
159
159
|
|
160
160
|
user
|
161
161
|
end
|
162
|
+
|
163
|
+
private_class_method :get_user_from_struct
|
162
164
|
end
|
163
165
|
end
|
data/lib/windows/sys/admin.rb
CHANGED
@@ -97,8 +97,6 @@ module Sys
|
|
97
97
|
@sid_type = "unknown"
|
98
98
|
end
|
99
99
|
end
|
100
|
-
|
101
|
-
@sid_type
|
102
100
|
end
|
103
101
|
end
|
104
102
|
|
@@ -314,9 +312,8 @@ module Sys
|
|
314
312
|
SidTypeUnknown = 8
|
315
313
|
SidTypeComputer = 9
|
316
314
|
|
317
|
-
private
|
318
|
-
|
319
315
|
HKEY = "SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\ProfileList\\"
|
316
|
+
private_constant :HKEY
|
320
317
|
|
321
318
|
# Retrieves the user's home directory. For local accounts query the
|
322
319
|
# registry. For domain accounts use ADSI and use the HomeDirectory.
|
@@ -343,6 +340,8 @@ module Sys
|
|
343
340
|
dir
|
344
341
|
end
|
345
342
|
|
343
|
+
private_class_method :get_home_dir
|
344
|
+
|
346
345
|
# A private method that lower cases all keys, and converts them
|
347
346
|
# all to symbols.
|
348
347
|
#
|
@@ -357,6 +356,8 @@ module Sys
|
|
357
356
|
rhash
|
358
357
|
end
|
359
358
|
|
359
|
+
private_class_method :munge_options
|
360
|
+
|
360
361
|
# An internal, private method for getting a list of groups for
|
361
362
|
# a particular user. The first member is a list of group names,
|
362
363
|
# the second member is the primary group ID.
|
@@ -368,6 +369,8 @@ module Sys
|
|
368
369
|
[array, adsi.PrimaryGroupId]
|
369
370
|
end
|
370
371
|
|
372
|
+
private_class_method :get_groups
|
373
|
+
|
371
374
|
# An internal, private method for getting a list of members for
|
372
375
|
# any particular group.
|
373
376
|
#
|
@@ -378,13 +381,13 @@ module Sys
|
|
378
381
|
array
|
379
382
|
end
|
380
383
|
|
384
|
+
private_class_method :get_members
|
385
|
+
|
381
386
|
# Used by the get_login method
|
382
387
|
ffi_lib :advapi32
|
383
388
|
attach_function :GetUserNameW, [:pointer, :pointer], :bool
|
384
389
|
private_class_method :GetUserNameW
|
385
390
|
|
386
|
-
public
|
387
|
-
|
388
391
|
# Creates the given +user+. If no domain option is specified,
|
389
392
|
# then it defaults to your local host, i.e. a local account is
|
390
393
|
# created.
|
@@ -705,7 +708,7 @@ module Sys
|
|
705
708
|
end
|
706
709
|
}
|
707
710
|
|
708
|
-
if usr.kind_of?(
|
711
|
+
if usr.kind_of?(Integer)
|
709
712
|
query << " and sid like '%-#{usr}'"
|
710
713
|
else
|
711
714
|
query << " and name = '#{usr}'"
|
@@ -718,7 +721,7 @@ module Sys
|
|
718
721
|
|
719
722
|
# Because our 'like' query isn't fulproof, let's parse
|
720
723
|
# the SID again to make sure
|
721
|
-
if usr.kind_of?(
|
724
|
+
if usr.kind_of?(Integer)
|
722
725
|
next if usr != uid
|
723
726
|
end
|
724
727
|
|
@@ -886,7 +889,7 @@ module Sys
|
|
886
889
|
end
|
887
890
|
}
|
888
891
|
|
889
|
-
if grp.kind_of?(
|
892
|
+
if grp.kind_of?(Integer)
|
890
893
|
query << " and sid like '%-#{grp}'"
|
891
894
|
else
|
892
895
|
query << " and name = '#{grp}'"
|
@@ -899,7 +902,7 @@ module Sys
|
|
899
902
|
|
900
903
|
# Because our 'like' query isn't fulproof, let's parse
|
901
904
|
# the SID again to make sure
|
902
|
-
if grp.kind_of?(
|
905
|
+
if grp.kind_of?(Integer)
|
903
906
|
next if grp != gid
|
904
907
|
end
|
905
908
|
|