sys-admin 1.8.2-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: e0a5f8abb2d51fd89dfaba1749f6ebedc824e53c16f5d19c7a09d8e5964643f6
4
- data.tar.gz: b15cbcbdcb14f3c8067f0d445acad1eb4a106a9a0670640b03d04fd45d49ff03
3
+ metadata.gz: c3a9114756676fa5db9d9b64c90faf8a95210ce70963da3e497c6911c6d4476d
4
+ data.tar.gz: 499b4f25b5412aec43fddb603d0d55de967ed7873ff55f332a67854041037d71
5
5
  SHA512:
6
- metadata.gz: 5344588bd21a2d4cbff3e845cf3dd1bff33f1e5e1996f499e874b100d40861c01f5646212bd0e860b48c6e67c458a4664092efd136beea30deef467476289b4e
7
- data.tar.gz: 7b8852c72276c2480320f3fe680baf1a1339b8b51f87a4558eb96610288ffebef45a53f247bf6ed129c2de838c32db37ce883d0d59d6a449287b9e26313830a9
6
+ metadata.gz: f65bb12071960dd2fa940a379965bdad5cc5552e67db4c79a61be77394078cf867367b1c17152e67b470ea6b3da6d93e26b4a179f059b22bc8db2b1b509cfe2b
7
+ data.tar.gz: 1e8a54333ab37374d4f6f6bbd675d5fe5bb91b15d5600d980e4a74e7215e78cf7b2658e4f0232e52128fe6082a1b1ffbeb1a03ff6598746aa6555fb48259560c
checksums.yaml.gz.sig CHANGED
Binary file
data/CHANGES.md CHANGED
@@ -1,3 +1,10 @@
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
+
1
8
  ## 1.8.2 - 9-Apr-2023
2
9
  * Lots of rubocop related updates.
3
10
  * Refactored specs to use shared specs.
data/README.md CHANGED
@@ -162,7 +162,7 @@ None that I'm aware of. If you find any, please log them on the project page at:
162
162
  Apache-2.0
163
163
 
164
164
  ## Copyright
165
- (C) 2005-2020, Daniel J. Berger
165
+ (C) 2005-2024, Daniel J. Berger
166
166
  All Rights Reserved
167
167
 
168
168
  ## Author
data/lib/bsd/sys/admin.rb CHANGED
@@ -131,7 +131,7 @@ module Sys
131
131
  def self.get_group(gid)
132
132
  size = 1024
133
133
  buf = FFI::MemoryPointer.new(:char, size)
134
- pbuf = FFI::MemoryPointer.new(PasswdStruct)
134
+ pbuf = FFI::MemoryPointer.new(GroupStruct)
135
135
  temp = GroupStruct.new
136
136
 
137
137
  begin
@@ -142,7 +142,14 @@ module Sys
142
142
  val = getgrgid_r(gid, temp, buf, buf.size, pbuf)
143
143
  fun = 'getgrgid_r'
144
144
  end
145
- 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
146
153
  rescue Errno::ERANGE
147
154
  size += 1024
148
155
  raise if size > BUF_MAX
@@ -125,7 +125,7 @@ module Sys
125
125
  def self.get_group(gid)
126
126
  size = 1024
127
127
  buf = FFI::MemoryPointer.new(:char, size)
128
- pbuf = FFI::MemoryPointer.new(PasswdStruct)
128
+ pbuf = FFI::MemoryPointer.new(GroupStruct)
129
129
  temp = GroupStruct.new
130
130
 
131
131
  begin
@@ -136,7 +136,14 @@ module Sys
136
136
  val = getgrgid_r(gid, temp, buf, buf.size, pbuf)
137
137
  fun = 'getgrgid_r'
138
138
  end
139
- 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
140
147
  rescue Errno::ERANGE
141
148
  size += 1024
142
149
  raise if size > BUF_MAX
@@ -120,7 +120,7 @@ module Sys
120
120
  def self.get_group(gid)
121
121
  size = 1024
122
122
  buf = FFI::MemoryPointer.new(:char, size)
123
- pbuf = FFI::MemoryPointer.new(PasswdStruct)
123
+ pbuf = FFI::MemoryPointer.new(GroupStruct)
124
124
  temp = GroupStruct.new
125
125
 
126
126
  begin
@@ -131,7 +131,14 @@ module Sys
131
131
  val = getgrgid_r(gid, temp, buf, buf.size, pbuf)
132
132
  fun = 'getgrgid_r'
133
133
  end
134
- 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
135
142
  rescue Errno::ERANGE # Large groups
136
143
  size += 1024
137
144
  raise if size > BUF_MAX
data/lib/sys/admin.rb CHANGED
@@ -5,7 +5,7 @@ module Sys
5
5
  # The Admin class provides a unified, cross platform replacement for the Etc module.
6
6
  class Admin
7
7
  # The version of the sys-admin library.
8
- VERSION = '1.8.2'
8
+ VERSION = '1.8.3'
9
9
 
10
10
  private_class_method :new
11
11
  end
@@ -2,7 +2,7 @@
2
2
 
3
3
  RSpec.shared_examples Sys::Admin do
4
4
  example 'version is set to expected value' do
5
- expect(described_class::VERSION).to eq('1.8.2')
5
+ expect(described_class::VERSION).to eq('1.8.3')
6
6
  end
7
7
 
8
8
  example 'version constant is frozen' do
@@ -76,6 +76,12 @@ RSpec.describe Sys::Admin, :unix do
76
76
  end
77
77
 
78
78
  describe 'get_group' do
79
+ before do
80
+ described_class.class_eval do
81
+ public :getgrgid_r
82
+ end
83
+ end
84
+
79
85
  example 'get_group basic functionality' do
80
86
  expect(described_class).to respond_to(:get_group)
81
87
  expect{ described_class.get_group(group) }.not_to raise_error
@@ -100,8 +106,31 @@ RSpec.describe Sys::Admin, :unix do
100
106
  end
101
107
 
102
108
  example 'get_group raises an Error if the group cannot be found' do
109
+ expect{ described_class.get_group(123456789) }.to raise_error(Sys::Admin::Error)
103
110
  expect{ described_class.get_group('foofoofoo') }.to raise_error(Sys::Admin::Error)
104
111
  end
112
+
113
+ example 'get_group handles large groups and will retry an ERANGE' do
114
+ allow(Sys::Admin).to receive(:getgrgid_r).with(any_args).and_return(34)
115
+ allow(Sys::Admin).to receive(:getgrgid_r).with(any_args).and_call_original
116
+ expect{ described_class.get_group(group_id) }.not_to raise_error
117
+ end
118
+
119
+ example 'get_group will raise the expected error for an ENOENT' do
120
+ allow(Sys::Admin).to receive(:getgrgid_r).with(any_args).and_return(2)
121
+ expect{ described_class.get_group(group_id) }.to raise_error(Sys::Admin::Error)
122
+ end
123
+
124
+ example 'get_group will raise the expected error for a failed getgrxxx function call' do
125
+ allow(Sys::Admin).to receive(:getgrgid_r).with(any_args).and_return(22)
126
+ allow_any_instance_of(FFI::MemoryPointer).to receive(:null?).and_return(true)
127
+ expect{ described_class.get_group(group_id) }.to raise_error(Errno::EINVAL)
128
+ end
129
+
130
+ example 'get_group will not retry failures other than an ERANGE' do
131
+ allow(Sys::Admin).to receive(:getgrgid_r).with(any_args).and_return(35)
132
+ expect{ described_class.get_group(group_id) }.to raise_error(Sys::Admin::Error)
133
+ end
105
134
  end
106
135
 
107
136
  describe 'groups' do
data/sys-admin.gemspec CHANGED
@@ -3,7 +3,7 @@ require 'rubygems'
3
3
 
4
4
  Gem::Specification.new do |spec|
5
5
  spec.name = 'sys-admin'
6
- spec.version = '1.8.2'
6
+ spec.version = '1.8.3'
7
7
  spec.author = 'Daniel J. Berger'
8
8
  spec.license = 'Apache-2.0'
9
9
  spec.email = 'djberg96@gmail.com'
data.tar.gz.sig CHANGED
Binary file
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sys-admin
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.8.2
4
+ version: 1.8.3
5
5
  platform: universal-mingw32
6
6
  authors:
7
7
  - Daniel J. Berger
@@ -35,7 +35,7 @@ cert_chain:
35
35
  ORVCZpRuCPpmC8qmqxUnARDArzucjaclkxjLWvCVHeFa9UP7K3Nl9oTjJNv+7/jM
36
36
  WZs4eecIcUc4tKdHxcAJ0MO/Dkqq7hGaiHpwKY76wQ1+8xAh
37
37
  -----END CERTIFICATE-----
38
- date: 2023-04-09 00:00:00.000000000 Z
38
+ date: 2024-04-20 00:00:00.000000000 Z
39
39
  dependencies:
40
40
  - !ruby/object:Gem::Dependency
41
41
  name: ffi
@@ -185,7 +185,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
185
185
  - !ruby/object:Gem::Version
186
186
  version: '0'
187
187
  requirements: []
188
- rubygems_version: 3.2.19
188
+ rubygems_version: 3.5.7
189
189
  signing_key:
190
190
  specification_version: 4
191
191
  summary: A unified, cross platform replacement for the "etc" library.
metadata.gz.sig CHANGED
Binary file