sys-admin 1.8.1-universal-mingw32 → 1.8.3-universal-mingw32

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 8f6b5f7c944fab6ef6ff02952eb74ec5e7fe5d5367cd85d10e82c1ece2340d6e
4
- data.tar.gz: 1bec59ee54b35d84e1e46fc60bfa857ba4cf621796c223d1334cd84801080be6
3
+ metadata.gz: c3a9114756676fa5db9d9b64c90faf8a95210ce70963da3e497c6911c6d4476d
4
+ data.tar.gz: 499b4f25b5412aec43fddb603d0d55de967ed7873ff55f332a67854041037d71
5
5
  SHA512:
6
- metadata.gz: 5227fe5b8f35b3cef57b1cef90536ddff04d57bffb7ba3bc5e947a7feee78ebeb71204e1ec183bc7504aff2cf2c6779c20fef6c638a5325a2901fe1f2d6e24e7
7
- data.tar.gz: 107ccc687e75a472945104e58bd9ac1afcaac0d58fb64d1303673f0f5d29d47329cae4801a7011080dd4d655cefe245ea1c43f37554c46d7a5621220d0043cbd
6
+ metadata.gz: f65bb12071960dd2fa940a379965bdad5cc5552e67db4c79a61be77394078cf867367b1c17152e67b470ea6b3da6d93e26b4a179f059b22bc8db2b1b509cfe2b
7
+ data.tar.gz: 1e8a54333ab37374d4f6f6bbd675d5fe5bb91b15d5600d980e4a74e7215e78cf7b2658e4f0232e52128fe6082a1b1ffbeb1a03ff6598746aa6555fb48259560c
checksums.yaml.gz.sig CHANGED
Binary file
data/CHANGES.md CHANGED
@@ -1,3 +1,17 @@
1
+ ## 1.8.3 - 20-Apr-2024
2
+ * Fixed up the get_group method on most platforms. Previously it was allocating
3
+ slightly more memory than it needed (wrong struct, oops). In addition, the
4
+ error handling wasn't consistent because I can't read a man page properly.
5
+ * More specs were added to properly test the get_group updates.
6
+ * The github actions test matrix was updated.
7
+
8
+ ## 1.8.2 - 9-Apr-2023
9
+ * Lots of rubocop related updates.
10
+ * Refactored specs to use shared specs.
11
+ * The lastlog key will return nil instead of an empty struct if it can't be read.
12
+ * Added more information to the gemspec metadata.
13
+ * The rubocop and rubocop-rspec gems are now development dependencies.
14
+
1
15
  ## 1.8.1 - 25-Sep-2021
2
16
  * The users and get_user methods on Darwin now take an optional :lastlog key
3
17
  that you can set to false in order to significantly speed up those methods
data/MANIFEST.md CHANGED
@@ -15,6 +15,7 @@
15
15
  * lib/sunos/sys/admin.rb
16
16
  * lib/sys/admin/common.rb
17
17
  * lib/sys/admin/custom.rb
18
- * test/test_sys_admin.rb
19
- * test/test_sys_admin_unix.rb
20
- * test/test_sys_admin_windows.rb
18
+ * spec/spec_helper.rb
19
+ * spec/sys_admin_universal_spec.rb
20
+ * spec/sys_admin_unix_spec.rb
21
+ * spec/sys_admin_windows_spec.rb
data/README.md CHANGED
@@ -144,6 +144,11 @@ The underlying implementation is similar to core Ruby's Etc implementation.
144
144
  But, in addition to the different interface, I use the re-entrant version
145
145
  of the appropriate functions when available.
146
146
 
147
+ ### OSX
148
+ The slowdown for collecting lastlog information on OSX seems to have gotten
149
+ progressively worse over time. Do not be surprised by significant slowdowns
150
+ if you opt to collect it.
151
+
147
152
  ## Future Plans
148
153
  * Make the User and Group objects comparable.
149
154
  * Add ability to add, configure and delete users on Unix platforms.
@@ -157,7 +162,7 @@ None that I'm aware of. If you find any, please log them on the project page at:
157
162
  Apache-2.0
158
163
 
159
164
  ## Copyright
160
- (C) 2005-2020, Daniel J. Berger
165
+ (C) 2005-2024, Daniel J. Berger
161
166
  All Rights Reserved
162
167
 
163
168
  ## Author
data/Rakefile CHANGED
@@ -2,11 +2,12 @@ require 'rake'
2
2
  require 'rake/clean'
3
3
  require 'rspec/core/rake_task'
4
4
  require 'rbconfig'
5
+ require 'rubocop/rake_task'
5
6
 
6
7
  CLEAN.include("**/*.gem", "**/*.rbx", "**/*.rbc", "ruby.core", "**/*.lock")
7
8
 
8
9
  namespace :gem do
9
- desc "Create the sys-uname gem"
10
+ desc "Create the sys-admin gem"
10
11
  task :create => [:clean] do
11
12
  require 'rubygems/package'
12
13
  spec = Gem::Specification.load('sys-admin.gemspec')
@@ -14,7 +15,7 @@ namespace :gem do
14
15
  Gem::Package.build(spec)
15
16
  end
16
17
 
17
- desc "Install the sys-uname gem"
18
+ desc "Install the sys-admin gem"
18
19
  task :install => [:create] do
19
20
  file = Dir["*.gem"].first
20
21
  sh "gem install -l #{file}"
@@ -39,4 +40,6 @@ RSpec::Core::RakeTask.new(:spec) do |t|
39
40
  end
40
41
  end
41
42
 
43
+ RuboCop::RakeTask.new
44
+
42
45
  task :default => :spec
data/lib/bsd/sys/admin.rb CHANGED
@@ -1,42 +1,46 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'sys/admin/custom'
2
4
  require 'sys/admin/common'
3
5
  require 'rbconfig'
4
6
 
5
7
  # The BSD specific code.
6
8
 
9
+ # The Sys module serves as a namespace only.
7
10
  module Sys
11
+ # The Admin class provides a unified, cross platform replacement for the Etc module.
8
12
  class Admin
9
13
  # :no-doc:
10
14
  BUF_MAX = 65536 # Max buffer for retry
11
15
  private_constant :BUF_MAX
12
16
 
13
17
  # I'm making some aliases here to prevent potential conflicts
14
- attach_function :open_c, :open, [:string, :int], :int
15
- attach_function :pread_c, :pread, [:int, :pointer, :size_t, :off_t], :size_t
18
+ attach_function :open_c, :open, %i[string int], :int
19
+ attach_function :pread_c, :pread, %i[int pointer size_t off_t], :size_t
16
20
  attach_function :close_c, :close, [:int], :int
17
21
 
18
- attach_function :getlogin_r, [:pointer, :int], :int
19
- attach_function :getpwnam_r, [:string, :pointer, :pointer, :size_t, :pointer], :int
20
- attach_function :getpwuid_r, [:long, :pointer, :pointer, :size_t, :pointer], :int
21
- attach_function :getgrnam_r, [:string, :pointer, :pointer, :size_t, :pointer], :int
22
- attach_function :getgrgid_r, [:long, :pointer, :pointer, :size_t, :pointer], :int
22
+ attach_function :getlogin_r, %i[pointer int], :int
23
+ attach_function :getpwnam_r, %i[string pointer pointer size_t pointer], :int
24
+ attach_function :getpwuid_r, %i[long pointer pointer size_t pointer], :int
25
+ attach_function :getgrnam_r, %i[string pointer pointer size_t pointer], :int
26
+ attach_function :getgrgid_r, %i[long pointer pointer size_t pointer], :int
23
27
 
24
28
  private_class_method :getlogin_r, :getpwnam_r, :getpwuid_r, :getgrnam_r, :getgrgid_r
25
29
  private_class_method :open_c, :pread_c, :close_c
26
30
 
27
31
  # struct passwd from /usr/include/pwd.h
28
32
  class PasswdStruct < FFI::Struct
29
- fields = [
30
- :pw_name, :string,
31
- :pw_passwd, :string,
32
- :pw_uid, :uid_t,
33
- :pw_gid, :gid_t,
34
- :pw_change, :time_t,
35
- :pw_class, :string,
36
- :pw_gecos, :string,
37
- :pw_dir, :string,
38
- :pw_shell, :string,
39
- :pw_expire, :time_t
33
+ fields = %i[
34
+ pw_name string
35
+ pw_passwd string
36
+ pw_uid uid_t
37
+ pw_gid gid_t
38
+ pw_change time_t
39
+ pw_class string
40
+ pw_gecos string
41
+ pw_dir string
42
+ pw_shell string
43
+ pw_expire time_t
40
44
  ]
41
45
 
42
46
  if RbConfig::CONFIG['host_os'] =~ /freebsd/i
@@ -77,7 +81,7 @@ module Sys
77
81
  buf = FFI::MemoryPointer.new(:char, 256)
78
82
 
79
83
  if getlogin_r(buf, buf.size) != 0
80
- raise Error, "getlogin_r function failed: " + strerror(FFI.errno)
84
+ raise Error, "getlogin_r function failed: #{strerror(FFI.errno)}"
81
85
  end
82
86
 
83
87
  buf.read_string
@@ -98,11 +102,11 @@ module Sys
98
102
 
99
103
  if uid.is_a?(String)
100
104
  if getpwnam_r(uid, temp, buf, buf.size, pbuf) != 0
101
- raise Error, "getpwnam_r function failed: " + strerror(FFI.errno)
105
+ raise Error, "getpwnam_r function failed: #{strerror(FFI.errno)}"
102
106
  end
103
107
  else
104
108
  if getpwuid_r(uid, temp, buf, buf.size, pbuf) != 0
105
- raise Error, "getpwuid_r function failed: " + strerror(FFI.errno)
109
+ raise Error, "getpwuid_r function failed: #{strerror(FFI.errno)}"
106
110
  end
107
111
  end
108
112
 
@@ -127,7 +131,7 @@ module Sys
127
131
  def self.get_group(gid)
128
132
  size = 1024
129
133
  buf = FFI::MemoryPointer.new(:char, size)
130
- pbuf = FFI::MemoryPointer.new(PasswdStruct)
134
+ pbuf = FFI::MemoryPointer.new(GroupStruct)
131
135
  temp = GroupStruct.new
132
136
 
133
137
  begin
@@ -138,7 +142,14 @@ module Sys
138
142
  val = getgrgid_r(gid, temp, buf, buf.size, pbuf)
139
143
  fun = 'getgrgid_r'
140
144
  end
141
- raise SystemCallError.new(fun, val) if val != 0
145
+
146
+ if pbuf.null?
147
+ if val != 0
148
+ raise SystemCallError.new(fun, val)
149
+ else
150
+ raise Error, "group '#{gid}' not found"
151
+ end
152
+ end
142
153
  rescue Errno::ERANGE
143
154
  size += 1024
144
155
  raise if size > BUF_MAX
@@ -242,13 +253,13 @@ module Sys
242
253
  begin
243
254
  fd = open_c(logfile, File::RDONLY)
244
255
 
245
- if fd != -1
256
+ if fd >= 0
246
257
  bytes = pread_c(fd, lastlog, lastlog.size, uid * lastlog.size)
247
258
  if bytes < 0
248
- raise Error, "pread function failed: " + strerror(FFI.errno)
259
+ raise Error, "pread function failed: #{strerror(FFI.errno)}"
249
260
  end
250
261
  else
251
- nil # Ignore, improper permissions
262
+ lastlog = nil # Ignore, most likely improper permissions
252
263
  end
253
264
  ensure
254
265
  close_c(fd) if fd && fd >= 0
@@ -1,20 +1,24 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'sys/admin/custom'
2
4
  require 'sys/admin/common'
3
5
 
4
6
  # The Darwin specific code.
5
7
 
8
+ # The Sys module serves as a namespace only.
6
9
  module Sys
10
+ # The Admin class provides a unified, cross platform replacement for the Etc module.
7
11
  class Admin
8
12
  # :no-doc:
9
13
  BUF_MAX = 65536 # Max buf size for retry.
10
14
  private_constant :BUF_MAX
11
15
 
12
- attach_function :getlogin_r, [:pointer, :int], :int
13
- attach_function :getpwnam_r, [:string, :pointer, :pointer, :size_t, :pointer], :int
14
- attach_function :getpwuid_r, [:long, :pointer, :pointer, :size_t, :pointer], :int
15
- attach_function :getgrnam_r, [:string, :pointer, :pointer, :size_t, :pointer], :int
16
- attach_function :getgrgid_r, [:long, :pointer, :pointer, :size_t, :pointer], :int
17
- attach_function :getlastlogx, [:long, :pointer], :pointer
16
+ attach_function :getlogin_r, %i[pointer int], :int
17
+ attach_function :getpwnam_r, %i[string pointer pointer size_t pointer], :int
18
+ attach_function :getpwuid_r, %i[long pointer pointer size_t pointer], :int
19
+ attach_function :getgrnam_r, %i[string pointer pointer size_t pointer], :int
20
+ attach_function :getgrgid_r, %i[long pointer pointer size_t pointer], :int
21
+ attach_function :getlastlogx, %i[long pointer], :pointer
18
22
 
19
23
  private_class_method :getlogin_r, :getpwnam_r, :getpwuid_r
20
24
  private_class_method :getgrnam_r, :getgrgid_r, :getlastlogx
@@ -67,7 +71,7 @@ module Sys
67
71
  buf = FFI::MemoryPointer.new(:char, 256)
68
72
 
69
73
  if getlogin_r(buf, buf.size) != 0
70
- raise Error, "getlogin_r function failed: " + strerror(FFI.errno)
74
+ raise Error, "getlogin_r function failed: #{strerror(FFI.errno)}"
71
75
  end
72
76
 
73
77
  buf.read_string
@@ -92,11 +96,11 @@ module Sys
92
96
 
93
97
  if uid.is_a?(String)
94
98
  if getpwnam_r(uid, temp, buf, buf.size, pbuf) != 0
95
- raise Error, "getpwnam_r function failed: " + strerror(FFI.errno)
99
+ raise Error, "getpwnam_r function failed: #{strerror(FFI.errno)}"
96
100
  end
97
101
  else
98
102
  if getpwuid_r(uid, temp, buf, buf.size, pbuf) != 0
99
- raise Error, "getpwuid_r function failed: " + strerror(FFI.errno)
103
+ raise Error, "getpwuid_r function failed: #{strerror(FFI.errno)}"
100
104
  end
101
105
  end
102
106
 
@@ -121,7 +125,7 @@ module Sys
121
125
  def self.get_group(gid)
122
126
  size = 1024
123
127
  buf = FFI::MemoryPointer.new(:char, size)
124
- pbuf = FFI::MemoryPointer.new(PasswdStruct)
128
+ pbuf = FFI::MemoryPointer.new(GroupStruct)
125
129
  temp = GroupStruct.new
126
130
 
127
131
  begin
@@ -132,7 +136,14 @@ module Sys
132
136
  val = getgrgid_r(gid, temp, buf, buf.size, pbuf)
133
137
  fun = 'getgrgid_r'
134
138
  end
135
- raise SystemCallError.new(fun, val) if val != 0
139
+
140
+ if pbuf.null?
141
+ if val != 0
142
+ raise SystemCallError.new(fun, val)
143
+ else
144
+ raise Error, "group '#{gid}' not found"
145
+ end
146
+ end
136
147
  rescue Errno::ERANGE
137
148
  size += 1024
138
149
  raise if size > BUF_MAX
@@ -1,25 +1,29 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'sys/admin/custom'
2
4
  require 'sys/admin/common'
3
5
 
4
6
  # The Linux specific code.
5
7
 
8
+ # The Sys module serves as a namespace only.
6
9
  module Sys
10
+ # The Admin class provides a unified, cross platform replacement for the Etc module.
7
11
  class Admin
8
12
  # :no-doc:
9
13
  BUF_MAX = 65536 # Absolute max buffer size for retry attempts.
10
14
  private_constant :BUF_MAX
11
15
 
12
16
  # I'm making some aliases here to prevent potential conflicts
13
- attach_function :open_c, :open, [:string, :int], :int
14
- attach_function :pread_c, :pread, [:int, :pointer, :size_t, :off_t], :size_t
17
+ attach_function :open_c, :open, %i[string int], :int
18
+ attach_function :pread_c, :pread, %i[int pointer size_t off_t], :size_t
15
19
  attach_function :close_c, :close, [:int], :int
16
20
 
17
- attach_function :getpwnam_r, [:string, :pointer, :pointer, :size_t, :pointer], :int
18
- attach_function :getpwuid_r, [:long, :pointer, :pointer, :size_t, :pointer], :int
19
- attach_function :getpwent_r, [:pointer, :pointer, :size_t, :pointer], :int
20
- attach_function :getgrent_r, [:pointer, :pointer, :size_t, :pointer], :int
21
- attach_function :getgrnam_r, [:string, :pointer, :pointer, :size_t, :pointer], :int
22
- attach_function :getgrgid_r, [:long, :pointer, :pointer, :size_t, :pointer], :int
21
+ attach_function :getpwnam_r, %i[string pointer pointer size_t pointer], :int
22
+ attach_function :getpwuid_r, %i[long pointer pointer size_t pointer], :int
23
+ attach_function :getpwent_r, %i[pointer pointer size_t pointer], :int
24
+ attach_function :getgrent_r, %i[pointer pointer size_t pointer], :int
25
+ attach_function :getgrnam_r, %i[string pointer pointer size_t pointer], :int
26
+ attach_function :getgrgid_r, %i[long pointer pointer size_t pointer], :int
23
27
 
24
28
  private_class_method :getgrent_r, :getgrnam_r, :getgrgid_r
25
29
  private_class_method :open_c, :pread_c, :close_c
@@ -83,11 +87,11 @@ module Sys
83
87
 
84
88
  if uid.is_a?(String)
85
89
  if getpwnam_r(uid, temp, buf, buf.size, pbuf) != 0
86
- raise Error, "getpwnam_r function failed: " + strerror(FFI.errno)
90
+ raise Error, "getpwnam_r function failed: #{strerror(FFI.errno)}"
87
91
  end
88
92
  else
89
93
  if getpwuid_r(uid, temp, buf, buf.size, pbuf) != 0
90
- raise Error, "getpwuid_r function failed: " + strerror(FFI.errno)
94
+ raise Error, "getpwuid_r function failed: #{strerror(FFI.errno)}"
91
95
  end
92
96
  end
93
97
 
@@ -116,7 +120,7 @@ module Sys
116
120
  def self.get_group(gid)
117
121
  size = 1024
118
122
  buf = FFI::MemoryPointer.new(:char, size)
119
- pbuf = FFI::MemoryPointer.new(PasswdStruct)
123
+ pbuf = FFI::MemoryPointer.new(GroupStruct)
120
124
  temp = GroupStruct.new
121
125
 
122
126
  begin
@@ -127,7 +131,14 @@ module Sys
127
131
  val = getgrgid_r(gid, temp, buf, buf.size, pbuf)
128
132
  fun = 'getgrgid_r'
129
133
  end
130
- raise SystemCallError.new(fun, val) if val != 0
134
+
135
+ if pbuf.null?
136
+ if val != 0
137
+ raise SystemCallError.new(fun, val)
138
+ else
139
+ raise Error, "group '#{gid}' not found"
140
+ end
141
+ end
131
142
  rescue Errno::ERANGE # Large groups
132
143
  size += 1024
133
144
  raise if size > BUF_MAX
@@ -239,7 +250,7 @@ module Sys
239
250
 
240
251
  private_class_method :get_user_from_struct
241
252
 
242
- # Note: it seems that Linux, or at least Ubuntu, does not track logins
253
+ # NOTE: It seems that Linux, or at least Ubuntu, does not track logins
243
254
  # via GDM (Gnome Display Manager) for some reason, so this may not return
244
255
  # anything useful.
245
256
  #
@@ -252,13 +263,13 @@ module Sys
252
263
  begin
253
264
  fd = open_c(logfile, File::RDONLY)
254
265
 
255
- if fd != -1
266
+ if fd >= 0
256
267
  bytes = pread_c(fd, lastlog, lastlog.size, uid * lastlog.size)
257
268
  if bytes < 0
258
- raise Error, "pread function failed: " + strerror(FFI.errno)
269
+ raise Error, "pread function failed: #{strerror(FFI.errno)}"
259
270
  end
260
271
  else
261
- nil # Ignore, improper permissions
272
+ lastlog = nil # Ignore, most likely improper permissions
262
273
  end
263
274
  ensure
264
275
  close_c(fd) if fd && fd >= 0
@@ -1,26 +1,30 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'sys/admin/custom'
2
4
  require 'sys/admin/common'
3
5
 
4
6
  # The Solaris specific code.
5
7
 
8
+ # The Sys module serves as a namespace only.
6
9
  module Sys
10
+ # The Admin class provides a unified, cross platform replacement for the Etc module.
7
11
  class Admin
8
12
  # :no-doc:
9
13
  BUF_MAX = 65536 # Max buffer size for retry.
10
14
  private_constant :BUF_MAX
11
15
 
12
16
  # I'm making some aliases here to prevent potential conflicts
13
- attach_function :open_c, :open, [:string, :int], :int
14
- attach_function :pread_c, :pread, [:int, :pointer, :size_t, :off_t], :size_t
17
+ attach_function :open_c, :open, %i[string int], :int
18
+ attach_function :pread_c, :pread, %i[int pointer size_t off_t], :size_t
15
19
  attach_function :close_c, :close, [:int], :int
16
20
 
17
- attach_function :getlogin_r, [:pointer, :size_t], :pointer
18
- attach_function :getpwnam_r, [:string, :pointer, :pointer, :size_t], :pointer
19
- attach_function :getpwuid_r, [:long, :pointer, :pointer, :size_t], :pointer
20
- attach_function :getpwent_r, [:pointer, :pointer, :int], :pointer
21
- attach_function :getgrent_r, [:pointer, :pointer, :int], :pointer
22
- attach_function :getgrnam_r, [:string, :pointer, :pointer, :int], :pointer
23
- attach_function :getgrgid_r, [:long, :pointer, :pointer, :int], :pointer
21
+ attach_function :getlogin_r, %i[pointer size_t], :pointer
22
+ attach_function :getpwnam_r, %i[string pointer pointer size_t], :pointer
23
+ attach_function :getpwuid_r, %i[long pointer pointer size_t], :pointer
24
+ attach_function :getpwent_r, %i[pointer pointer int], :pointer
25
+ attach_function :getgrent_r, %i[pointer pointer int], :pointer
26
+ attach_function :getgrnam_r, %i[string pointer pointer int], :pointer
27
+ attach_function :getgrgid_r, %i[long pointer pointer int], :pointer
24
28
 
25
29
  private_class_method :getlogin_r, :getpwnam_r, :getpwuid_r, :getpwent_r
26
30
  private_class_method :getgrent_r, :getgrnam_r, :getgrgid_r
@@ -74,7 +78,7 @@ module Sys
74
78
  ptr = getlogin_r(buf, buf.size)
75
79
 
76
80
  if ptr.null?
77
- raise Error, "getlogin_r function failed: " + strerror(FFI.errno)
81
+ raise Error, "getlogin_r function failed: #{strerror(FFI.errno)}"
78
82
  end
79
83
 
80
84
  buf.read_string
@@ -99,7 +103,7 @@ module Sys
99
103
  end
100
104
 
101
105
  if ptr.null?
102
- raise Error, "getpwnam_r or getpwuid_r function failed: " + strerror(FFI.errno)
106
+ raise Error, "getpwnam_r or getpwuid_r function failed: #{strerror(FFI.errno)}"
103
107
  end
104
108
 
105
109
  pwd = PasswdStruct.new(ptr)
@@ -251,7 +255,7 @@ module Sys
251
255
  if fd != -1
252
256
  bytes = pread_c(fd, lastlog, lastlog.size, uid * lastlog.size)
253
257
  if bytes < 0
254
- raise Error, "pread function failed: " + strerror(FFI.errno)
258
+ raise Error, "pread function failed: #{strerror(FFI.errno)}"
255
259
  end
256
260
  else
257
261
  nil # Ignore, improper permissions
@@ -1,8 +1,9 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'ffi'
2
4
 
3
5
  # The Sys module serves as a namespace only.
4
6
  module Sys
5
-
6
7
  # The Admin class provides a unified, cross platform replacement
7
8
  # for the Etc module.
8
9
  class Admin
@@ -99,9 +100,9 @@ module Sys
99
100
  def groups
100
101
  array = []
101
102
 
102
- Sys::Admin.groups.each{ |grp|
103
- array << grp.name if grp.members.include?(self.name)
104
- }
103
+ Sys::Admin.groups.each do |grp|
104
+ array << grp.name if grp.members.include?(name)
105
+ end
105
106
 
106
107
  array
107
108
  end
@@ -1,14 +1,17 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'ffi'
2
4
 
5
+ # Re-open the FFI::Pointer class to add a custom method.
3
6
  class FFI::Pointer
4
7
  def read_array_of_string
5
8
  elements = []
6
9
 
7
10
  loc = self
8
11
 
9
- until ((element = loc.read_pointer).null?)
10
- elements << element.read_string
11
- loc += FFI::Type::POINTER.size
12
+ until (element = loc.read_pointer).null?
13
+ elements << element.read_string
14
+ loc += FFI::Type::POINTER.size
12
15
  end
13
16
 
14
17
  elements
data/lib/sys/admin.rb CHANGED
@@ -1,7 +1,13 @@
1
+ # frozen_string_literal: true
2
+
3
+ # The Sys modules serves as a namespace only.
1
4
  module Sys
5
+ # The Admin class provides a unified, cross platform replacement for the Etc module.
2
6
  class Admin
3
7
  # The version of the sys-admin library.
4
- VERSION = '1.8.1'.freeze
8
+ VERSION = '1.8.3'
9
+
10
+ private_class_method :new
5
11
  end
6
12
  end
7
13
 
data/lib/sys-admin.rb CHANGED
@@ -1 +1,3 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require_relative 'sys/admin'
@@ -1,9 +1,13 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'sys/admin/custom'
2
4
  require 'sys/admin/common'
3
5
 
4
6
  # Code used as a fallback for UNIX platforms.
5
7
 
8
+ # The Sys module serves as a namespace only.
6
9
  module Sys
10
+ # The Admin class provides a unified, cross platform replacement for the Etc module.
7
11
  class Admin
8
12
  class PasswdStruct < FFI::Struct
9
13
  layout(
@@ -55,7 +59,7 @@ module Sys
55
59
  raise Error, "no user found for: #{uid}"
56
60
  end
57
61
 
58
- user = User.new do |u|
62
+ User.new do |u|
59
63
  u.name = pwd[:pw_name]
60
64
  u.passwd = pwd[:pw_passwd]
61
65
  u.uid = pwd[:pw_uid]
@@ -64,8 +68,6 @@ module Sys
64
68
  u.dir = pwd[:pw_dir]
65
69
  u.shell = pwd[:pw_shell]
66
70
  end
67
-
68
- user
69
71
  end
70
72
 
71
73
  # Returns a Group object for the given name or uid. Raises an error
@@ -147,7 +149,7 @@ module Sys
147
149
 
148
150
  # Takes a UserStruct and converts it to a User object.
149
151
  def self.get_user_from_struct(pwd)
150
- user = User.new do |u|
152
+ User.new do |u|
151
153
  u.name = pwd[:pw_name]
152
154
  u.passwd = pwd[:pw_passwd]
153
155
  u.uid = pwd[:pw_uid]
@@ -156,8 +158,6 @@ module Sys
156
158
  u.dir = pwd[:pw_dir]
157
159
  u.shell = pwd[:pw_shell]
158
160
  end
159
-
160
- user
161
161
  end
162
162
 
163
163
  private_class_method :get_user_from_struct