linux-utmpx 0.1.0 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.github/workflows/main.yml +1 -1
- data/README.md +25 -1
- data/examples/utmpx.rb +49 -0
- data/lib/linux/utmpx/parser.rb +2 -2
- data/lib/linux/utmpx/version.rb +1 -1
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d949aa7d9cedc8ed59720ded4a18a8ec41e2eaaa2c1dea79713dedc8110e1edf
|
4
|
+
data.tar.gz: bcc2c7417e713cc22878bf010002716ca04f27e5859e2c00dfae7a45bbcdd132
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: '08d56610c4f6c65c8b500ef0ee046cba28d145f59f0f8c1e2b7a327a4e0cee21bf56974cc0abebec2da7983c4d123155c9b9f1a55f66edb26bd5ba3d285a20d4'
|
7
|
+
data.tar.gz: 9659b5f10bd9f48b8ec59d61fe3026d9570caeae77397b97f0829e210f7b022bb9fe41c02c130b3677d6875908a2499d23a4eeca23fea90462d34e08fa2171a8
|
data/.github/workflows/main.yml
CHANGED
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
|
data/lib/linux/utmpx/parser.rb
CHANGED
@@ -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
|
-
|
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
|
data/lib/linux/utmpx/version.rb
CHANGED
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.
|
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-
|
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
|