sys-admin 1.8.0 → 1.8.1

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: 72d00ed279d1871b324cf2819ba90432093b8063a30e0bbdc9fa66111b588538
4
- data.tar.gz: 31bc4f2515a391ba43c1bc9ce0b3bdeffacd6d758b7e98a29a111ced2ab14e85
3
+ metadata.gz: d20b0abf74cb8d4769f69346ac22ade3d1336bd10d3b6f83eeca2865ab9b85fe
4
+ data.tar.gz: 7c56cb4dec18928e3ea4fb1371e9c3f4e660fb5ec94519b0385a1448c07e0d84
5
5
  SHA512:
6
- metadata.gz: 36c4dc086a9929e998695ed02ce9cb89b5bd487cc4cb42aacccc26aab8a3fa3f62fde29a2bbb0792fd6657278fbe874e3366e3dc08a29c2ebc99e087bb1ea939
7
- data.tar.gz: 3f9c593cd1b2008966524683d511c1c5e7e6ada91298516adc46afe948dd39cad7da069b426f268376493e6eb28934f020d55be60c73fca2bb756cf885d1e245
6
+ metadata.gz: 55d12a7b5d4999eec9801b60a06d1da16bfb2879a4270b0d5188b7d20a397a170619fb0dc75f9fd394952c02e3228d686ff9c908f15a38750220bea7eb2a2e9d
7
+ data.tar.gz: 3ec5f6ac0690458751f5dd5e2ccaf764b977f1aa46fc6f2acf0c506417c39a4baf704338c712614728fe8d89c289bd76c20dcd62b41f6b28ab5205404ef338e3
checksums.yaml.gz.sig CHANGED
Binary file
data/CHANGES.md CHANGED
@@ -1,9 +1,15 @@
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
+
1
7
  ## 1.8.0 - 26-Aug-2021
2
8
  * Switched from test-unit to rspec, with some tests refactored. The Rakefile
3
9
  and gemspec files were updated accordingly.
4
10
  * The User and Group classes for the Windows implementation are now properly
5
11
  scoped under Sys::Admin instead of just Sys.
6
- * Fixed a bug in the get_user and get_group methods on Winodws where the WQL
12
+ * Fixed a bug in the get_user and get_group methods on Windows where the WQL
7
13
  it generates internally might not be correct.
8
14
 
9
15
  ## 1.7.6 - 24-Mar-2021
data/README.md CHANGED
@@ -1,3 +1,5 @@
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
+
1
3
  ## Description
2
4
  The sys-admin library is a unified, cross platform replacement for the Etc module.
3
5
 
data/Rakefile CHANGED
@@ -23,7 +23,6 @@ end
23
23
 
24
24
  desc "Run the specs for the sys-admin library"
25
25
  RSpec::Core::RakeTask.new(:spec) do |t|
26
- t.pattern = 'spec/sys_admin_unix_spec.rb'
27
26
  case RbConfig::CONFIG['host_os']
28
27
  when /darwin|osx/i
29
28
  t.rspec_opts = '-Ilib/darwin'
@@ -35,7 +34,6 @@ RSpec::Core::RakeTask.new(:spec) do |t|
35
34
  t.rspec_opts = '-Ilib/bsd'
36
35
  when /windows|win32|mingw|cygwin|dos/i
37
36
  t.rspec_opts = '-Ilib/windows'
38
- t.pattern = 'spec/sys_admin_windows_spec.rb'
39
37
  else
40
38
  t.rspec_opts = '-Ilib/unix'
41
39
  end
@@ -80,8 +80,12 @@ module Sys
80
80
  #
81
81
  # Sys::Admin.get_user('joe')
82
82
  # Sys::Admin.get_user(501)
83
+ # Sys::Admin.get_user('joe', :lastlog => false) # Less info but faster
83
84
  #
84
- def self.get_user(uid)
85
+ # Set the :lastlog option to false if you want to ignore lastlog
86
+ # information and speed this method up considerably.
87
+ #
88
+ def self.get_user(uid, options = {})
85
89
  buf = FFI::MemoryPointer.new(:char, 1024)
86
90
  pbuf = FFI::MemoryPointer.new(PasswdStruct)
87
91
  temp = PasswdStruct.new
@@ -103,7 +107,7 @@ module Sys
103
107
  end
104
108
 
105
109
  pwd = PasswdStruct.new(ptr)
106
- get_user_from_struct(pwd)
110
+ get_user_from_struct(pwd, options)
107
111
  end
108
112
 
109
113
  # Returns a Group object for the given name or uid. Raises an error
@@ -148,11 +152,19 @@ module Sys
148
152
 
149
153
  # Returns an array of User objects for each user on the system.
150
154
  #
155
+ # Examples:
156
+ #
157
+ # Sys::Admin.users
158
+ # Sys::Admin.users(:lastlog => false) # Less info but faster
159
+ #
160
+ # Note that on Darwin this method can be very slow. If you want to
161
+ # speed it up considerably by ignoring lastlog information then set
162
+ # the :lastlog option to false as part of the +options+ hash.
151
163
  #--
152
164
  # This method is somewhat slow on OSX because of the call to get
153
165
  # lastlog information. I'm not sure why.
154
166
  #
155
- def self.users
167
+ def self.users(options = {})
156
168
  users = []
157
169
 
158
170
  begin
@@ -160,7 +172,7 @@ module Sys
160
172
 
161
173
  until (ptr = getpwent()).null?
162
174
  pwd = PasswdStruct.new(ptr)
163
- users << get_user_from_struct(pwd)
175
+ users << get_user_from_struct(pwd, options)
164
176
  end
165
177
  ensure
166
178
  endpwent()
@@ -201,7 +213,7 @@ module Sys
201
213
  private_class_method :get_group_from_struct
202
214
 
203
215
  # Takes a UserStruct and converts it to a User object.
204
- def self.get_user_from_struct(pwd)
216
+ def self.get_user_from_struct(pwd, options)
205
217
  user = User.new do |u|
206
218
  u.name = pwd[:pw_name]
207
219
  u.passwd = pwd[:pw_passwd]
@@ -215,12 +227,14 @@ module Sys
215
227
  u.expire = Time.at(pwd[:pw_expire])
216
228
  end
217
229
 
218
- log = get_lastlog_info(user.uid)
230
+ unless options[:lastlog] == false
231
+ log = get_lastlog_info(user.uid)
219
232
 
220
- if log
221
- user.login_time = Time.at(log[:tv_sec])
222
- user.login_device = log[:ll_line].to_s
223
- user.login_host = log[:ll_host].to_s
233
+ if log
234
+ user.login_time = Time.at(log[:tv_sec])
235
+ user.login_device = log[:ll_line].to_s
236
+ user.login_host = log[:ll_host].to_s
237
+ end
224
238
  end
225
239
 
226
240
  user
data/lib/sys/admin.rb CHANGED
@@ -1,7 +1,7 @@
1
1
  module Sys
2
2
  class Admin
3
3
  # The version of the sys-admin library.
4
- VERSION = '1.8.0'.freeze
4
+ VERSION = '1.8.1'.freeze
5
5
  end
6
6
  end
7
7
 
@@ -0,0 +1,13 @@
1
+ require 'rspec'
2
+ require 'sys-admin'
3
+
4
+ RSpec.configure do |config|
5
+ config.filter_run_excluding(:darwin) if Gem::Platform.local.os != 'darwin'
6
+ config.filter_run_excluding(:windows) unless Gem.win_platform?
7
+
8
+ if Gem.win_platform?
9
+ config.filter_run_excluding(:unix)
10
+ require 'win32-security'
11
+ require 'socket'
12
+ end
13
+ end
@@ -4,8 +4,7 @@
4
4
  # Test suite for the Unix version of sys-admin. This test should be run
5
5
  # via the 'rake spec' task.
6
6
  ###############################################################################
7
- require 'rspec'
8
- require 'sys/admin'
7
+ require 'spec_helper'
9
8
 
10
9
  RSpec.describe Sys::Admin, :unix do
11
10
  let(:user) { 'nobody' }
@@ -41,9 +40,8 @@ RSpec.describe Sys::Admin, :unix do
41
40
  expect(described_class.get_user(user_id)).to be_kind_of(Sys::Admin::User)
42
41
  end
43
42
 
44
- example "get_user requires one argument only" do
43
+ example "get_user requires at least one argument" do
45
44
  expect{ described_class.get_user }.to raise_error(ArgumentError)
46
- expect{ described_class.get_user(user, user) }.to raise_error(ArgumentError)
47
45
  end
48
46
 
49
47
  example "get_user requires a string or integer argument" do
@@ -67,8 +65,11 @@ RSpec.describe Sys::Admin, :unix do
67
65
  expect(users).to all(be_kind_of(Sys::Admin::User))
68
66
  end
69
67
 
70
- example "users does not accept any arguments" do
71
- expect{ described_class.users(user_id) }.to raise_error(ArgumentError)
68
+ example "users accepts an optional lastlog argument on darwin", :darwin => true do
69
+ users = described_class.users(:lastlog => false)
70
+ expect(users).to be_kind_of(Array)
71
+ expect(users).to all(be_kind_of(Sys::Admin::User))
72
+ expect(users.first.login_time).to be_nil
72
73
  end
73
74
  end
74
75
 
@@ -0,0 +1,11 @@
1
+ require 'spec_helper'
2
+
3
+ RSpec.describe Sys::Admin do
4
+ example "version is set to expected value" do
5
+ expect(described_class::VERSION).to eq('1.8.1')
6
+ end
7
+
8
+ example "version constant is frozen" do
9
+ expect(described_class::VERSION).to be_frozen
10
+ end
11
+ end
@@ -7,10 +7,7 @@
7
7
  #
8
8
  # It is assumed that these specs will be run via the 'rake spec' task.
9
9
  ###############################################################################
10
- require 'rspec'
11
- require 'sys/admin'
12
- require 'win32/security'
13
- require 'socket'
10
+ require 'spec_helper'
14
11
 
15
12
  RSpec.describe Sys::Admin, :windows do
16
13
  let(:host) { Socket.gethostname }
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.0'
6
+ spec.version = '1.8.1'
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.0
4
+ version: 1.8.1
5
5
  platform: ruby
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: 2021-08-26 00:00:00.000000000 Z
38
+ date: 2021-09-25 00:00:00.000000000 Z
39
39
  dependencies:
40
40
  - !ruby/object:Gem::Dependency
41
41
  name: ffi
@@ -111,7 +111,9 @@ files:
111
111
  - lib/sys/admin/custom.rb
112
112
  - lib/unix/sys/admin.rb
113
113
  - lib/windows/sys/admin.rb
114
+ - spec/spec_helper.rb
114
115
  - spec/sys_admin_unix_spec.rb
116
+ - spec/sys_admin_version_spec.rb
115
117
  - spec/sys_admin_windows_spec.rb
116
118
  - sys-admin.gemspec
117
119
  homepage: http://www.github.com/djberg96/sys-admin
@@ -139,10 +141,12 @@ required_rubygems_version: !ruby/object:Gem::Requirement
139
141
  - !ruby/object:Gem::Version
140
142
  version: '0'
141
143
  requirements: []
142
- rubygems_version: 3.1.4
144
+ rubygems_version: 3.2.28
143
145
  signing_key:
144
146
  specification_version: 4
145
147
  summary: A unified, cross platform replacement for the "etc" library.
146
148
  test_files:
149
+ - spec/spec_helper.rb
147
150
  - spec/sys_admin_unix_spec.rb
151
+ - spec/sys_admin_version_spec.rb
148
152
  - spec/sys_admin_windows_spec.rb
metadata.gz.sig CHANGED
Binary file