linux-utmpx 0.1.0 → 0.2.0

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: c97e1b42f1cdb52f5e36237a34b1fd9a45725577d40fa95c2dc2af60bac191c7
4
- data.tar.gz: 5f4fa12738f051bb224b1122883df78ca18f5825f16913a677cc93d446682101
3
+ metadata.gz: d949aa7d9cedc8ed59720ded4a18a8ec41e2eaaa2c1dea79713dedc8110e1edf
4
+ data.tar.gz: bcc2c7417e713cc22878bf010002716ca04f27e5859e2c00dfae7a45bbcdd132
5
5
  SHA512:
6
- metadata.gz: 11be5a0e6b534a53d2b9c2f32b2314c671f8fe9afb85977a5d009bcb4290fb3f65f86ef8390c1d9ce54e3ef4657705a638734ee1c1de8d1186149975ddaa3496
7
- data.tar.gz: d0f6585ea4fd7a0a43a44b898c9d6b966f136a56605b67164e77e1f6b976cdbcac6cb5de296f2b1c65eb778d93d36063e8c14aac170de9ebc38d9e9bdd60bd71
6
+ metadata.gz: '08d56610c4f6c65c8b500ef0ee046cba28d145f59f0f8c1e2b7a327a4e0cee21bf56974cc0abebec2da7983c4d123155c9b9f1a55f66edb26bd5ba3d285a20d4'
7
+ data.tar.gz: 9659b5f10bd9f48b8ec59d61fe3026d9570caeae77397b97f0829e210f7b022bb9fe41c02c130b3677d6875908a2499d23a4eeca23fea90462d34e08fa2171a8
@@ -20,4 +20,4 @@ jobs:
20
20
  run: |
21
21
  gem install bundler
22
22
  bundle install
23
- TESTOPTS="--verbose" bundle exec rake
23
+ TZ=Asia/Tokyo TESTOPTS="--verbose" bundle exec rake
data/README.md CHANGED
@@ -30,7 +30,31 @@ while !io.eof? do
30
30
  end
31
31
  ```
32
32
 
33
-
33
+ ## Supported fields
34
+
35
+ `Linux::Utmpx::UtmpxParser` supports to read the following fields.
36
+
37
+ | parameter | type | description |
38
+ |-----------|-----------------|-----------------------------|
39
+ | ut_type | integer | Type of login |
40
+ | ut_pid | integer | Process ID of login process |
41
+ | ut_line | string | Device name |
42
+ | ut_id | string | Inittab ID |
43
+ | ut_user | string | Username |
44
+ | ut_host | string | Hostname for remote login |
45
+ | ut_tv | BinData::Record | Time entry |
46
+
47
+ For making access easy, these accessor methods are provided.
48
+
49
+ | parameter | type | description |
50
+ |-----------|---------|-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
51
+ | type | integer | Type of login. It returns `:EMPTY`, `:RUN_LVL`, `:BOOT_TIME`, `:NEW_TIME`, `:OLD_TIME`, `:INIT_PROCESS`, `:LOGIN_PROCESS`, `:USER_PROCESS`, `:DEAD_PROCESS` or `:ACCOUNTING`. |
52
+ | pid | integer | Process ID of login process |
53
+ | line | string | Device name |
54
+ | id | string | Inittab ID |
55
+ | user | string | Username |
56
+ | host | string | Hostname for remote login |
57
+ | time | Time | Time entry.it returns the value of `Time`. |
34
58
  ## Development
35
59
 
36
60
  After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake test-unit` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
data/examples/utmpx.rb ADDED
@@ -0,0 +1,49 @@
1
+ require "linux/utmpx"
2
+ require "optparse"
3
+
4
+ options = {}
5
+ parser = OptionParser.new
6
+ parser.on("-u", "--utmp", "Dump /var/run/utmp") do |v|
7
+ options[:utmp] = v
8
+ end
9
+ parser.on("-w", "--wtmp", "Dump /var/log/wtmp") do |v|
10
+ options[:wtmp] = v
11
+ end
12
+ parser.on("-d", "--delayed", "Dump with delayed IO") do |v|
13
+ options[:delayed] = v
14
+ end
15
+ parser.parse!(ARGV)
16
+
17
+ path = "/var/run/utmp"
18
+ if options[:utmp]
19
+ path = "/var/run/utmp"
20
+ end
21
+ if options[:wtmp]
22
+ path = "/var/log/wtmp"
23
+ end
24
+
25
+ unless options[:utmp] or options[:wtmp]
26
+ puts parser.help
27
+ exit 1
28
+ end
29
+
30
+ File.open(path, "rb") do |io|
31
+ utmpx = Linux::Utmpx::UtmpxParser.new
32
+ printf("%25s %14s %7s %10s %20s %10s %10s\n", "TIME", "TYPE", "PID", "USER", "HOST", "ID", "LINE")
33
+ if options[:delayed]
34
+ obj = BinData::DelayedIO.new(type: Linux::Utmpx::UtmpxParser, read_abs_offset: 0)
35
+ while !io.eof?
36
+ obj.read(io.read(384)) do
37
+ obj.read_now!
38
+ printf("%25s %14s %7d %10s %20s %10s %10s\n",
39
+ obj.time, obj.type, obj.pid, obj.user, obj.host, obj.id, obj.line)
40
+ end
41
+ end
42
+ else
43
+ while !io.eof?
44
+ entry = utmpx.read(io)
45
+ printf("%25s %14s %7d %10s %20s %10s %10s\n",
46
+ entry.time, entry.type, entry.pid, entry.user, entry.host, entry.id, entry.line)
47
+ end
48
+ end
49
+ end
@@ -33,12 +33,12 @@ module Linux
33
33
  int32 :ut_session
34
34
  uttv :ut_tv
35
35
  array :ut_addr_v6, :initial_length => 4 do
36
- int32
36
+ int32be
37
37
  end
38
38
  string :reserved, :length => 20
39
39
 
40
40
  def time
41
- Time.at(ut_tv.tv_sec, ut_tv.tv_usec)
41
+ Time.at(ut_tv.tv_sec, ut_tv.tv_usec).iso8601
42
42
  end
43
43
 
44
44
  def type
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Linux
4
4
  module Utmpx
5
- VERSION = "0.1.0"
5
+ VERSION = "0.2.0"
6
6
  end
7
7
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: linux-utmpx
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Kentaro Hayashi
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2021-03-24 00:00:00.000000000 Z
11
+ date: 2021-03-30 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bindata
@@ -53,6 +53,7 @@ files:
53
53
  - Rakefile
54
54
  - bin/console
55
55
  - bin/setup
56
+ - examples/utmpx.rb
56
57
  - lib/linux/utmpx.rb
57
58
  - lib/linux/utmpx/parser.rb
58
59
  - lib/linux/utmpx/type.rb