key_control 0.0.3 → 0.0.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/key_control/key_ring.rb +9 -16
- data/lib/key_control/system.rb +64 -16
- data/lib/key_control/version.rb +1 -1
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a226c9ceecfaba7c34e789b1b075803b1c31fda1
|
4
|
+
data.tar.gz: f5205dc20534d1be565527d3905ac2e51a6b0853
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c7f52114b183f8c1be55fd2e9c49ae3f81cf2bde49e8d2940e4bd1b1deeba0bdba811634c2ed1258e0afe9599efc2d0aeed10b5751e60ce1790d64a7208c07e6
|
7
|
+
data.tar.gz: 73b9a063cfe17fdda8ccce6dfb1d61cc5838a0f8130c345d96e4e7a1a9bc4cc66a6097610f4e1c44865a8e6a0cbeb212ef3fc780798916fc6f1f3b84be8fe2ad
|
data/lib/key_control/key_ring.rb
CHANGED
@@ -2,6 +2,8 @@ module KeyControl
|
|
2
2
|
|
3
3
|
class KeyRing
|
4
4
|
|
5
|
+
attr_reader :system
|
6
|
+
|
5
7
|
# Public: Get a new KeyControl::KeyRing instance with the specified keyring
|
6
8
|
# identifier.
|
7
9
|
#
|
@@ -20,7 +22,7 @@ module KeyControl
|
|
20
22
|
#
|
21
23
|
# Returns nothing.
|
22
24
|
def []=(name, data)
|
23
|
-
|
25
|
+
system.run(:add, "user", name, data, data.length, @keyring)
|
24
26
|
end
|
25
27
|
|
26
28
|
# Public: Get the data matching the passed description from the keychain.
|
@@ -29,26 +31,17 @@ module KeyControl
|
|
29
31
|
#
|
30
32
|
# Returns the requested data or nil.
|
31
33
|
def [](name)
|
32
|
-
handle =
|
34
|
+
handle = system.run(:search, "user", name, nil, @keyring)
|
33
35
|
return nil if handle == -1
|
34
36
|
|
35
|
-
|
36
|
-
buffer = "\x00" * length
|
37
|
-
execute(:read, handle, buffer, length)
|
38
|
-
|
39
|
-
buffer
|
37
|
+
system.get(:read, handle)
|
40
38
|
end
|
41
39
|
|
42
|
-
|
43
|
-
|
44
|
-
# Private: Execute the requested action in keyctl.
|
45
|
-
#
|
46
|
-
# action - The action to perform.
|
47
|
-
# args - A list of arguments which should be passed to the action.
|
40
|
+
# Public: Inspect the structure of and data stored in the current keyring.
|
48
41
|
#
|
49
|
-
# Returns
|
50
|
-
def
|
51
|
-
|
42
|
+
# Returns
|
43
|
+
def inspect
|
44
|
+
system.get(:describe, @keyring)
|
52
45
|
end
|
53
46
|
end
|
54
47
|
end
|
data/lib/key_control/system.rb
CHANGED
@@ -4,7 +4,59 @@ module KeyControl
|
|
4
4
|
|
5
5
|
class System
|
6
6
|
|
7
|
-
# Public:
|
7
|
+
# Public: Execute the requested action in keyctl.
|
8
|
+
#
|
9
|
+
# action - The action to perform.
|
10
|
+
# args - A list of arguments which should be passed to the action.
|
11
|
+
#
|
12
|
+
# Returns the stdout value returned by the call.
|
13
|
+
def run(action, *args)
|
14
|
+
send(action).call(*args)
|
15
|
+
end
|
16
|
+
|
17
|
+
# Public: Execute the requested keyctl action, buffering the output into a
|
18
|
+
# string in multiple passes.
|
19
|
+
#
|
20
|
+
# action - The action to perform.
|
21
|
+
# args - A list of arguments which should be passed to the action.
|
22
|
+
#
|
23
|
+
# Returns a String containing the buffered output.
|
24
|
+
def get(action, *args)
|
25
|
+
length = run(action, *args, "", 0)
|
26
|
+
buffer = "\x00" * length
|
27
|
+
run(action, *args, buffer, length)
|
28
|
+
|
29
|
+
buffer
|
30
|
+
end
|
31
|
+
|
32
|
+
# Public: Get a symbol representing the reason for the last error set by a
|
33
|
+
# system call.
|
34
|
+
#
|
35
|
+
# Returns a Symbol or nil.
|
36
|
+
def error
|
37
|
+
Errno.constants.detect do |error_name|
|
38
|
+
errno = Errno.const_get(error_name)
|
39
|
+
errno::Errno == Fiddle.last_error
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
private
|
44
|
+
|
45
|
+
# Private: Get a handle representing the system calls available through
|
46
|
+
# libkeyutils.so.
|
47
|
+
#
|
48
|
+
# Returns a Fiddle::Handle.
|
49
|
+
def keyutils
|
50
|
+
@keyutils ||= KeyControl::LIBRARIES.detect do |library|
|
51
|
+
begin
|
52
|
+
break Fiddle::Handle.new(library)
|
53
|
+
rescue Fiddle::DLError
|
54
|
+
nil
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
59
|
+
# Private: Get a proc representing the add_key system call.
|
8
60
|
#
|
9
61
|
# Returns a Fiddle::Function.
|
10
62
|
def add
|
@@ -18,7 +70,7 @@ module KeyControl
|
|
18
70
|
Fiddle::TYPE_INT )
|
19
71
|
end
|
20
72
|
|
21
|
-
#
|
73
|
+
# Private: Get a proc representing the request_key system call.
|
22
74
|
#
|
23
75
|
# Returns a Fiddle::Function.
|
24
76
|
def search
|
@@ -31,7 +83,7 @@ module KeyControl
|
|
31
83
|
Fiddle::TYPE_INT )
|
32
84
|
end
|
33
85
|
|
34
|
-
#
|
86
|
+
# Private: Get a proc representing the keyctl_read system call.
|
35
87
|
#
|
36
88
|
# Returns a Fiddle::Function.
|
37
89
|
def read
|
@@ -43,20 +95,16 @@ module KeyControl
|
|
43
95
|
Fiddle::TYPE_LONG )
|
44
96
|
end
|
45
97
|
|
46
|
-
|
47
|
-
|
48
|
-
# Private: Get a handle representing the system calls available through
|
49
|
-
# libkeyutils.so.
|
98
|
+
# Private: Get a proc representing the keyctl_describe system call.
|
50
99
|
#
|
51
|
-
# Returns a Fiddle::
|
52
|
-
def
|
53
|
-
@
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
end
|
100
|
+
# Returns a Fiddle::Function.
|
101
|
+
def describe
|
102
|
+
@describe ||= Fiddle::Function.new(
|
103
|
+
keyutils["keyctl_describe"],
|
104
|
+
[ Fiddle::TYPE_INT,
|
105
|
+
Fiddle::ALIGN_CHAR,
|
106
|
+
Fiddle::TYPE_SIZE_T ],
|
107
|
+
Fiddle::TYPE_INT )
|
60
108
|
end
|
61
109
|
end
|
62
110
|
end
|
data/lib/key_control/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: key_control
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Andrew Horner
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-
|
11
|
+
date: 2014-04-09 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -81,7 +81,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
81
81
|
version: '0'
|
82
82
|
requirements: []
|
83
83
|
rubyforge_project:
|
84
|
-
rubygems_version: 2.
|
84
|
+
rubygems_version: 2.0.6
|
85
85
|
signing_key:
|
86
86
|
specification_version: 4
|
87
87
|
summary: A simple wrapper for the `keyctl` utility.
|