capng_c 0.1.6 → 0.2.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.clang-format +5 -0
- data/.github/workflows/apt.yml +35 -0
- data/.github/workflows/linux.yml +1 -1
- data/.github/workflows/yum.yml +39 -0
- data/Gemfile +2 -0
- data/README.md +17 -2
- data/capng_c.gemspec +3 -2
- data/ci/apt-test.sh +15 -0
- data/ci/yum-test.sh +64 -0
- data/example/file_capability.rb +2 -1
- data/ext/capng/capability.c +374 -24
- data/ext/capng/capability_info.c +82 -0
- data/ext/capng/capng.c +298 -148
- data/ext/capng/capng.h +22 -6
- data/ext/capng/enum-action.c +35 -0
- data/ext/capng/enum-flags.c +44 -0
- data/ext/capng/enum-result.c +38 -0
- data/ext/capng/enum-select.c +39 -0
- data/ext/capng/enum-type.c +42 -0
- data/ext/capng/enum.c +7 -45
- data/ext/capng/print.c +126 -75
- data/ext/capng/state.c +59 -20
- data/ext/capng/utils.c +4 -4
- data/lib/capng.rb +7 -13
- data/lib/capng/version.rb +1 -1
- metadata +33 -8
data/ext/capng/state.c
CHANGED
@@ -11,29 +11,50 @@
|
|
11
11
|
/* See the License for the specific language governing permissions and */
|
12
12
|
/* limitations under the License. */
|
13
13
|
|
14
|
+
/* clang-format off */
|
15
|
+
/*
|
16
|
+
* Document-class: CapNG::State
|
17
|
+
*
|
18
|
+
* Handle CapNG state.
|
19
|
+
*
|
20
|
+
* @example
|
21
|
+
* require 'capng'
|
22
|
+
*
|
23
|
+
* @state = CapNG::State.new
|
24
|
+
* @state.save
|
25
|
+
* # Some capability operations
|
26
|
+
* @state.restore
|
27
|
+
*/
|
28
|
+
/* clang-format on */
|
29
|
+
|
14
30
|
#include <capng.h>
|
15
31
|
|
16
|
-
struct CapNGState
|
17
|
-
|
32
|
+
struct CapNGState
|
33
|
+
{
|
34
|
+
void* state;
|
18
35
|
};
|
19
36
|
|
20
|
-
static void
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
};
|
37
|
+
static void
|
38
|
+
capng_state_free(void* capng);
|
39
|
+
|
40
|
+
static const rb_data_type_t rb_capng_state_type = { "capng/state",
|
41
|
+
{
|
42
|
+
0,
|
43
|
+
capng_state_free,
|
44
|
+
0,
|
45
|
+
},
|
46
|
+
NULL,
|
47
|
+
NULL,
|
48
|
+
RUBY_TYPED_FREE_IMMEDIATELY };
|
33
49
|
|
34
50
|
static void
|
35
51
|
capng_state_free(void* ptr)
|
36
52
|
{
|
53
|
+
struct CapNGState* state = (struct CapNGState*)ptr;
|
54
|
+
if (state) {
|
55
|
+
state->state = NULL;
|
56
|
+
}
|
57
|
+
|
37
58
|
xfree(ptr);
|
38
59
|
}
|
39
60
|
|
@@ -42,11 +63,17 @@ rb_capng_state_alloc(VALUE klass)
|
|
42
63
|
{
|
43
64
|
VALUE obj;
|
44
65
|
struct CapNGState* capng_state;
|
45
|
-
obj =
|
46
|
-
klass, struct CapNGState, &rb_capng_state_type, capng_state);
|
66
|
+
obj =
|
67
|
+
TypedData_Make_Struct(klass, struct CapNGState, &rb_capng_state_type, capng_state);
|
47
68
|
return obj;
|
48
69
|
}
|
49
70
|
|
71
|
+
/*
|
72
|
+
* Initalize State class.
|
73
|
+
*
|
74
|
+
* @return [nil]
|
75
|
+
*
|
76
|
+
*/
|
50
77
|
static VALUE
|
51
78
|
rb_capng_state_initialize(VALUE self)
|
52
79
|
{
|
@@ -58,12 +85,17 @@ rb_capng_state_initialize(VALUE self)
|
|
58
85
|
return Qnil;
|
59
86
|
}
|
60
87
|
|
61
|
-
|
88
|
+
/*
|
89
|
+
* Save current capability state.
|
90
|
+
*
|
91
|
+
* @return [nil]
|
92
|
+
*
|
93
|
+
*/
|
62
94
|
static VALUE
|
63
95
|
rb_capng_state_save(VALUE self)
|
64
96
|
{
|
65
97
|
struct CapNGState* capng_state;
|
66
|
-
void
|
98
|
+
void* state = NULL;
|
67
99
|
|
68
100
|
TypedData_Get_Struct(self, struct CapNGState, &rb_capng_state_type, capng_state);
|
69
101
|
|
@@ -73,11 +105,18 @@ rb_capng_state_save(VALUE self)
|
|
73
105
|
return Qnil;
|
74
106
|
}
|
75
107
|
|
108
|
+
/*
|
109
|
+
* Restore saved capability state.
|
110
|
+
*
|
111
|
+
* @return [nil]
|
112
|
+
*
|
113
|
+
*/
|
114
|
+
|
76
115
|
static VALUE
|
77
116
|
rb_capng_state_restore(VALUE self)
|
78
117
|
{
|
79
118
|
struct CapNGState* capng_state;
|
80
|
-
void
|
119
|
+
void* state = NULL;
|
81
120
|
|
82
121
|
TypedData_Get_Struct(self, struct CapNGState, &rb_capng_state_type, capng_state);
|
83
122
|
|
data/ext/capng/utils.c
CHANGED
@@ -14,7 +14,7 @@
|
|
14
14
|
#include <capng.h>
|
15
15
|
|
16
16
|
capng_select_t
|
17
|
-
select_name_to_select_type(char
|
17
|
+
select_name_to_select_type(char* select_name)
|
18
18
|
{
|
19
19
|
if (strcmp(select_name, "caps") == 0) {
|
20
20
|
return CAPNG_SELECT_CAPS;
|
@@ -36,7 +36,7 @@ select_name_to_select_type(char *select_name)
|
|
36
36
|
}
|
37
37
|
|
38
38
|
capng_act_t
|
39
|
-
action_name_to_action_type(char
|
39
|
+
action_name_to_action_type(char* action_name)
|
40
40
|
{
|
41
41
|
if (strcmp(action_name, "drop") == 0) {
|
42
42
|
return CAPNG_DROP;
|
@@ -48,7 +48,7 @@ action_name_to_action_type(char *action_name)
|
|
48
48
|
}
|
49
49
|
|
50
50
|
capng_print_t
|
51
|
-
print_name_to_print_type(char
|
51
|
+
print_name_to_print_type(char* print_name)
|
52
52
|
{
|
53
53
|
if (strcmp(print_name, "stdout") == 0) {
|
54
54
|
return CAPNG_PRINT_STDOUT;
|
@@ -60,7 +60,7 @@ print_name_to_print_type(char *print_name)
|
|
60
60
|
}
|
61
61
|
|
62
62
|
capng_type_t
|
63
|
-
capability_type_name_to_capability_type(char
|
63
|
+
capability_type_name_to_capability_type(char* capability_name)
|
64
64
|
{
|
65
65
|
if (strcmp(capability_name, "effective") == 0) {
|
66
66
|
return CAPNG_EFFECTIVE;
|
data/lib/capng.rb
CHANGED
@@ -2,24 +2,18 @@ require "capng/capng"
|
|
2
2
|
require "capng/version"
|
3
3
|
|
4
4
|
class CapNG
|
5
|
+
# Predefined Error class.
|
5
6
|
class Error < StandardError; end
|
6
7
|
|
8
|
+
# :nodoc:
|
9
|
+
# @private
|
7
10
|
alias_method :caps_file_raw, :caps_file
|
11
|
+
# :nodoc:
|
12
|
+
# @private
|
8
13
|
alias_method :apply_caps_file_raw, :apply_caps_file
|
14
|
+
# :nodoc:
|
15
|
+
# @private
|
9
16
|
alias_method :update_raw, :update
|
10
|
-
alias_method :initialize_raw, :initialize
|
11
|
-
|
12
|
-
def initialize(target = nil, pid_or_path = nil)
|
13
|
-
if target && pid_or_path.is_a?(Integer)
|
14
|
-
initialize_raw(target, pid_or_path)
|
15
|
-
elsif target && pid_or_path.is_a?(String) && File.exist?(pid_or_path)
|
16
|
-
File.open(pid_or_path) do |file|
|
17
|
-
initialize_raw(target, file);
|
18
|
-
end
|
19
|
-
else
|
20
|
-
initialize_raw(target, pid_or_path)
|
21
|
-
end
|
22
|
-
end
|
23
17
|
|
24
18
|
def caps_file(file_or_string_path)
|
25
19
|
if file_or_string_path.is_a?(String) && File.exist?(file_or_string_path)
|
data/lib/capng/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: capng_c
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Hiroshi Hatake
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2020-
|
11
|
+
date: 2020-12-25 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -36,14 +36,14 @@ dependencies:
|
|
36
36
|
requirements:
|
37
37
|
- - "~>"
|
38
38
|
- !ruby/object:Gem::Version
|
39
|
-
version: '
|
39
|
+
version: '13.0'
|
40
40
|
type: :development
|
41
41
|
prerelease: false
|
42
42
|
version_requirements: !ruby/object:Gem::Requirement
|
43
43
|
requirements:
|
44
44
|
- - "~>"
|
45
45
|
- !ruby/object:Gem::Version
|
46
|
-
version: '
|
46
|
+
version: '13.0'
|
47
47
|
- !ruby/object:Gem::Dependency
|
48
48
|
name: rake-compiler
|
49
49
|
requirement: !ruby/object:Gem::Requirement
|
@@ -72,6 +72,20 @@ dependencies:
|
|
72
72
|
- - "~>"
|
73
73
|
- !ruby/object:Gem::Version
|
74
74
|
version: 3.3.3
|
75
|
+
- !ruby/object:Gem::Dependency
|
76
|
+
name: yard
|
77
|
+
requirement: !ruby/object:Gem::Requirement
|
78
|
+
requirements:
|
79
|
+
- - "~>"
|
80
|
+
- !ruby/object:Gem::Version
|
81
|
+
version: '0.9'
|
82
|
+
type: :development
|
83
|
+
prerelease: false
|
84
|
+
version_requirements: !ruby/object:Gem::Requirement
|
85
|
+
requirements:
|
86
|
+
- - "~>"
|
87
|
+
- !ruby/object:Gem::Version
|
88
|
+
version: '0.9'
|
75
89
|
description: libcap-ng bindings for Ruby.
|
76
90
|
email:
|
77
91
|
- cosmo0920.wp@gmail.com
|
@@ -80,7 +94,10 @@ extensions:
|
|
80
94
|
- ext/capng/extconf.rb
|
81
95
|
extra_rdoc_files: []
|
82
96
|
files:
|
97
|
+
- ".clang-format"
|
98
|
+
- ".github/workflows/apt.yml"
|
83
99
|
- ".github/workflows/linux.yml"
|
100
|
+
- ".github/workflows/yum.yml"
|
84
101
|
- ".gitignore"
|
85
102
|
- Gemfile
|
86
103
|
- LICENSE
|
@@ -89,12 +106,20 @@ files:
|
|
89
106
|
- bin/console
|
90
107
|
- bin/setup
|
91
108
|
- capng_c.gemspec
|
109
|
+
- ci/apt-test.sh
|
110
|
+
- ci/yum-test.sh
|
92
111
|
- example/file_capability.rb
|
93
112
|
- example/process_capability.rb
|
94
113
|
- example/process_capability_without_root.rb
|
95
114
|
- ext/capng/capability.c
|
115
|
+
- ext/capng/capability_info.c
|
96
116
|
- ext/capng/capng.c
|
97
117
|
- ext/capng/capng.h
|
118
|
+
- ext/capng/enum-action.c
|
119
|
+
- ext/capng/enum-flags.c
|
120
|
+
- ext/capng/enum-result.c
|
121
|
+
- ext/capng/enum-select.c
|
122
|
+
- ext/capng/enum-type.c
|
98
123
|
- ext/capng/enum.c
|
99
124
|
- ext/capng/extconf.rb
|
100
125
|
- ext/capng/print.c
|
@@ -102,13 +127,13 @@ files:
|
|
102
127
|
- ext/capng/utils.c
|
103
128
|
- lib/capng.rb
|
104
129
|
- lib/capng/version.rb
|
105
|
-
homepage: https://github.com/
|
130
|
+
homepage: https://github.com/fluent-plugins-nursery/capng_c
|
106
131
|
licenses:
|
107
132
|
- Apache-2.0
|
108
133
|
metadata:
|
109
134
|
allowed_push_host: https://rubygems.org
|
110
|
-
homepage_uri: https://github.com/
|
111
|
-
source_code_uri: https://github.com/
|
135
|
+
homepage_uri: https://github.com/fluent-plugins-nursery/capng_c
|
136
|
+
source_code_uri: https://github.com/fluent-plugins-nursery/capng_c
|
112
137
|
post_install_message:
|
113
138
|
rdoc_options: []
|
114
139
|
require_paths:
|
@@ -124,7 +149,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
124
149
|
- !ruby/object:Gem::Version
|
125
150
|
version: '0'
|
126
151
|
requirements: []
|
127
|
-
rubygems_version: 3.
|
152
|
+
rubygems_version: 3.2.3
|
128
153
|
signing_key:
|
129
154
|
specification_version: 4
|
130
155
|
summary: libcap-ng bindings for Ruby.
|