capng_c 0.1.5 → 0.2.1
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 +3 -1
- data/README.md +14 -2
- data/capng_c.gemspec +2 -1
- 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 +375 -25
- data/ext/capng/capability_info.c +82 -0
- data/ext/capng/capng.c +299 -149
- data/ext/capng/capng.h +33 -17
- 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/extconf.rb +4 -0
- data/ext/capng/print.c +127 -76
- data/ext/capng/state.c +55 -21
- data/ext/capng/utils.c +7 -7
- data/lib/capng.rb +7 -13
- data/lib/capng/version.rb +1 -1
- metadata +30 -5
@@ -0,0 +1,82 @@
|
|
1
|
+
/* capng_c */
|
2
|
+
/* Copyright 2020- Hiroshi Hatake*/
|
3
|
+
/* */
|
4
|
+
/* Licensed under the Apache License, Version 2.0 (the "License"); */
|
5
|
+
/* you may not use this file except in compliance with the License. */
|
6
|
+
/* You may obtain a copy of the License at */
|
7
|
+
/* http://www.apache.org/licenses/LICENSE-2.0 */
|
8
|
+
/* Unless required by applicable law or agreed to in writing, software */
|
9
|
+
/* distributed under the License is distributed on an "AS IS" BASIS, */
|
10
|
+
/* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. */
|
11
|
+
/* See the License for the specific language governing permissions and */
|
12
|
+
/* limitations under the License. */
|
13
|
+
|
14
|
+
#include <capng.h>
|
15
|
+
|
16
|
+
CapabilityInfo capabilityInfoTable[] = {
|
17
|
+
{CAP_CHOWN, "chown"},
|
18
|
+
{CAP_DAC_OVERRIDE, "dac_override"},
|
19
|
+
{CAP_DAC_READ_SEARCH, "dac_read_search"},
|
20
|
+
{CAP_FOWNER, "fowner"},
|
21
|
+
{CAP_FSETID, "fsetid"},
|
22
|
+
{CAP_KILL, "kill"},
|
23
|
+
{CAP_SETGID, "setgid"},
|
24
|
+
{CAP_SETUID, "setuid"},
|
25
|
+
{CAP_SETPCAP, "setpcap"},
|
26
|
+
{CAP_LINUX_IMMUTABLE, "linux_immutable"},
|
27
|
+
{CAP_NET_BIND_SERVICE, "net_bind_service"},
|
28
|
+
{CAP_NET_BROADCAST, "net_broadcast"},
|
29
|
+
{CAP_NET_ADMIN, "net_admin"},
|
30
|
+
{CAP_NET_RAW, "net_raw"},
|
31
|
+
{CAP_IPC_LOCK, "ipc_lock"},
|
32
|
+
{CAP_IPC_OWNER, "ipc_owner"},
|
33
|
+
{CAP_SYS_MODULE, "sys_module"},
|
34
|
+
{CAP_SYS_RAWIO, "sys_rawio"},
|
35
|
+
{CAP_SYS_CHROOT, "sys_chroot"},
|
36
|
+
{CAP_SYS_PTRACE, "sys_ptrace"},
|
37
|
+
{CAP_SYS_PACCT, "sys_pacct"},
|
38
|
+
{CAP_SYS_ADMIN, "sys_admin"},
|
39
|
+
{CAP_SYS_BOOT, "sys_boot"},
|
40
|
+
{CAP_SYS_NICE, "sys_nice"},
|
41
|
+
{CAP_SYS_RESOURCE, "sys_resource"},
|
42
|
+
{CAP_SYS_TIME, "sys_time"},
|
43
|
+
{CAP_SYS_TTY_CONFIG, "sys_tty_config"},
|
44
|
+
{CAP_MKNOD, "mknod"},
|
45
|
+
{CAP_LEASE, "lease"},
|
46
|
+
{CAP_AUDIT_WRITE, "audit_write"},
|
47
|
+
{CAP_AUDIT_CONTROL, "audit_control"},
|
48
|
+
#ifdef CAP_SETFCAP
|
49
|
+
{CAP_SETFCAP, "setfcap"},
|
50
|
+
#endif
|
51
|
+
#ifdef CAP_MAC_OVERRIDE
|
52
|
+
{CAP_MAC_OVERRIDE, "mac_override"},
|
53
|
+
#endif
|
54
|
+
#ifdef CAP_MAC_ADMIN
|
55
|
+
{CAP_MAC_ADMIN, "mac_admin"},
|
56
|
+
#endif
|
57
|
+
#ifdef CAP_SYSLOG
|
58
|
+
{CAP_SYSLOG, "syslog"},
|
59
|
+
#endif
|
60
|
+
#ifdef CAP_EPOLLWAKEUP
|
61
|
+
{CAP_EPOLLWAKEUP, "epollwakeup"},
|
62
|
+
#endif
|
63
|
+
#ifdef CAP_WAKE_ALARM
|
64
|
+
{CAP_WAKE_ALARM, "wake_alarm"},
|
65
|
+
#endif
|
66
|
+
#ifdef CAP_BLOCK_SUSPEND
|
67
|
+
{CAP_BLOCK_SUSPEND, "block_suspend"},
|
68
|
+
#endif
|
69
|
+
#ifdef CAP_AUDIT_READ
|
70
|
+
{CAP_AUDIT_READ, "audit_read"},
|
71
|
+
#endif
|
72
|
+
#ifdef CAP_PERFMON
|
73
|
+
{CAP_PERFMON, "perfmon"},
|
74
|
+
#endif
|
75
|
+
#ifdef CAP_BPF
|
76
|
+
{CAP_BPF, "bpf"},
|
77
|
+
#endif
|
78
|
+
#ifdef CAP_CHECKPOINT_RESTORE
|
79
|
+
{CAP_CHECKPOINT_RESTORE, "checkpoint_restore"},
|
80
|
+
#endif
|
81
|
+
{-1, NULL},
|
82
|
+
};
|
data/ext/capng/capng.c
CHANGED
@@ -13,21 +13,44 @@
|
|
13
13
|
|
14
14
|
#include <capng.h>
|
15
15
|
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
16
|
+
/* clang-format off */
|
17
|
+
/*
|
18
|
+
* Document-class: CapNG
|
19
|
+
*
|
20
|
+
* CapNG class.
|
21
|
+
*
|
22
|
+
* @example
|
23
|
+
* # Current process capability example
|
24
|
+
* require 'capng'
|
25
|
+
*
|
26
|
+
* @capng = CapNG.new(:current_process)
|
27
|
+
* @capng.have_capability?(:effective, :dac_read_search)
|
28
|
+
*
|
29
|
+
* @example
|
30
|
+
* # Other process capability example
|
31
|
+
* require 'capng'
|
32
|
+
*
|
33
|
+
* @capng = CapNG.new(:other_process, 12345)
|
34
|
+
* @capng.have_capability?(:effective, :dac_override)
|
35
|
+
*
|
36
|
+
*/
|
37
|
+
/* clang-format on */
|
38
|
+
|
39
|
+
struct CapNG
|
40
|
+
{};
|
41
|
+
|
42
|
+
static void
|
43
|
+
capng_free(void* capng);
|
44
|
+
|
45
|
+
static const rb_data_type_t rb_capng_type = { "capng/capng",
|
46
|
+
{
|
47
|
+
0,
|
48
|
+
capng_free,
|
49
|
+
0,
|
50
|
+
},
|
51
|
+
NULL,
|
52
|
+
NULL,
|
53
|
+
RUBY_TYPED_FREE_IMMEDIATELY };
|
31
54
|
|
32
55
|
static void
|
33
56
|
capng_free(void* ptr)
|
@@ -40,21 +63,28 @@ rb_capng_alloc(VALUE klass)
|
|
40
63
|
{
|
41
64
|
VALUE obj;
|
42
65
|
struct CapNG* capng;
|
43
|
-
obj = TypedData_Make_Struct(
|
44
|
-
klass, struct CapNG, &rb_capng_type, capng);
|
66
|
+
obj = TypedData_Make_Struct(klass, struct CapNG, &rb_capng_type, capng);
|
45
67
|
return obj;
|
46
68
|
}
|
47
69
|
|
70
|
+
/*
|
71
|
+
* Initalize CapNG class.
|
72
|
+
*
|
73
|
+
* @overload initialize(target=nil, pid_or_file=nil)
|
74
|
+
* @option param target [String or Symbol] Specify capability target.
|
75
|
+
* @option param pid_or_file [String or Symbol] Querying XPath.
|
76
|
+
* @return [nil]
|
77
|
+
*
|
78
|
+
*/
|
48
79
|
static VALUE
|
49
|
-
rb_capng_initialize(int argc, VALUE
|
80
|
+
rb_capng_initialize(int argc, VALUE* argv, VALUE self)
|
50
81
|
{
|
51
|
-
VALUE rb_target,
|
82
|
+
VALUE rb_target, rb_pid;
|
52
83
|
int result = 0;
|
53
|
-
char
|
54
|
-
int pid = 0
|
55
|
-
rb_io_t *fptr = NULL;
|
84
|
+
char* target = NULL;
|
85
|
+
int pid = 0;
|
56
86
|
|
57
|
-
rb_scan_args(argc, argv, "02", &rb_target, &
|
87
|
+
rb_scan_args(argc, argv, "02", &rb_target, &rb_pid);
|
58
88
|
|
59
89
|
if (NIL_P(rb_target)) {
|
60
90
|
return Qnil;
|
@@ -74,51 +104,47 @@ rb_capng_initialize(int argc, VALUE *argv, VALUE self)
|
|
74
104
|
rb_raise(rb_eRuntimeError, "Couldn't get current process' capability");
|
75
105
|
}
|
76
106
|
} else if (strcmp(target, "other_process") == 0) {
|
77
|
-
Check_Type(
|
107
|
+
Check_Type(rb_pid, T_FIXNUM);
|
78
108
|
|
79
|
-
pid = NUM2INT(
|
109
|
+
pid = NUM2INT(rb_pid);
|
80
110
|
capng_setpid(pid);
|
81
111
|
result = capng_get_caps_process();
|
82
112
|
if (result != 0) {
|
83
113
|
rb_raise(rb_eRuntimeError, "Couldn't get current process' capability");
|
84
114
|
}
|
85
|
-
} else if (strcmp(target, "file") == 0) {
|
86
|
-
Check_Type(rb_pid_or_file, T_FILE);
|
87
|
-
|
88
|
-
fptr = RFILE(rb_pid_or_file)->fptr;
|
89
|
-
fd = fptr->fd;
|
90
|
-
result = capng_get_caps_fd(fd);
|
91
|
-
/* Just store result into instance variable. */
|
92
|
-
/* This is because capng_get_caps_fd should return 0 if file cap is not set. */
|
93
|
-
rb_iv_set(self, "@return_code", INT2NUM(result));
|
94
115
|
}
|
95
116
|
|
96
117
|
return Qnil;
|
97
118
|
}
|
98
119
|
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
120
|
+
/*
|
121
|
+
* Clear capabilities on specified target.
|
122
|
+
*
|
123
|
+
* @param rb_select_name_or_enum [Symbol or String or Fixnum] targets are CAPS, BOUNDS,
|
124
|
+
* BOTH, and AMBIENT for supported platform.
|
125
|
+
*
|
126
|
+
* @return [nil]
|
127
|
+
*
|
128
|
+
*/
|
105
129
|
static VALUE
|
106
130
|
rb_capng_clear(VALUE self, VALUE rb_select_name_or_enum)
|
107
131
|
{
|
108
132
|
capng_select_t select = 0;
|
109
133
|
|
110
134
|
switch (TYPE(rb_select_name_or_enum)) {
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
135
|
+
case T_SYMBOL:
|
136
|
+
select =
|
137
|
+
select_name_to_select_type(RSTRING_PTR(rb_sym2str(rb_select_name_or_enum)));
|
138
|
+
break;
|
139
|
+
case T_STRING:
|
140
|
+
select = select_name_to_select_type(StringValuePtr(rb_select_name_or_enum));
|
141
|
+
break;
|
142
|
+
case T_FIXNUM:
|
143
|
+
select = NUM2INT(rb_select_name_or_enum);
|
144
|
+
break;
|
145
|
+
default:
|
146
|
+
rb_raise(rb_eArgError,
|
147
|
+
"Expected a String or a Symbol instance, or a capability type constant");
|
122
148
|
}
|
123
149
|
|
124
150
|
capng_clear(select);
|
@@ -126,23 +152,34 @@ rb_capng_clear(VALUE self, VALUE rb_select_name_or_enum)
|
|
126
152
|
return Qnil;
|
127
153
|
}
|
128
154
|
|
155
|
+
/*
|
156
|
+
* Fill capabilities on specified target.
|
157
|
+
*
|
158
|
+
* @param rb_select_name_or_enum [Symbol or String or Fixnum] targets are CAPS, BOUNDS,
|
159
|
+
* BOTH, and AMBIENT for supported platform.
|
160
|
+
*
|
161
|
+
* @return [nil]
|
162
|
+
*
|
163
|
+
*/
|
129
164
|
static VALUE
|
130
165
|
rb_capng_fill(VALUE self, VALUE rb_select_name_or_enum)
|
131
166
|
{
|
132
167
|
capng_select_t select = 0;
|
133
168
|
|
134
169
|
switch (TYPE(rb_select_name_or_enum)) {
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
|
170
|
+
case T_SYMBOL:
|
171
|
+
select =
|
172
|
+
select_name_to_select_type(RSTRING_PTR(rb_sym2str(rb_select_name_or_enum)));
|
173
|
+
break;
|
174
|
+
case T_STRING:
|
175
|
+
select = select_name_to_select_type(StringValuePtr(rb_select_name_or_enum));
|
176
|
+
break;
|
177
|
+
case T_FIXNUM:
|
178
|
+
select = NUM2INT(rb_select_name_or_enum);
|
179
|
+
break;
|
180
|
+
default:
|
181
|
+
rb_raise(rb_eArgError,
|
182
|
+
"Expected a String or a Symbol instance, or a capability type constant");
|
146
183
|
}
|
147
184
|
|
148
185
|
capng_fill(select);
|
@@ -150,6 +187,14 @@ rb_capng_fill(VALUE self, VALUE rb_select_name_or_enum)
|
|
150
187
|
return Qnil;
|
151
188
|
}
|
152
189
|
|
190
|
+
/*
|
191
|
+
* Specify process ID to retrieve other process capabilities.
|
192
|
+
*
|
193
|
+
* @param rb_pid [Fixnum] Process ID.
|
194
|
+
*
|
195
|
+
* @return [nil]
|
196
|
+
*
|
197
|
+
*/
|
153
198
|
static VALUE
|
154
199
|
rb_capng_setpid(VALUE self, VALUE rb_pid)
|
155
200
|
{
|
@@ -160,6 +205,13 @@ rb_capng_setpid(VALUE self, VALUE rb_pid)
|
|
160
205
|
return Qnil;
|
161
206
|
}
|
162
207
|
|
208
|
+
/*
|
209
|
+
* Specify process ID to retrieve process capabilities. If not
|
210
|
+
* calling #setpid before, it returns current process' capabilities.
|
211
|
+
*
|
212
|
+
* @return [Boolean]
|
213
|
+
*
|
214
|
+
*/
|
163
215
|
static VALUE
|
164
216
|
rb_capng_get_caps_process(VALUE self)
|
165
217
|
{
|
@@ -172,55 +224,82 @@ rb_capng_get_caps_process(VALUE self)
|
|
172
224
|
return Qfalse;
|
173
225
|
}
|
174
226
|
|
227
|
+
/*
|
228
|
+
* Update capabilities.
|
229
|
+
*
|
230
|
+
* @param rb_action_name_or_action [Symbol or String or Fixnum] ADD or DROP.
|
231
|
+
* @param rb_capability_name_or_type [Symbol or String or Fixnum]
|
232
|
+
* Effective/Inheritable/Permitted/Ambient (If supported) or their combinations
|
233
|
+
* @param rb_capability_or_name [Symbol or String or Fixnum] Capability name or constants.
|
234
|
+
*
|
235
|
+
* @see: [CapNG::Capability])
|
236
|
+
*
|
237
|
+
* @return [Boolean]
|
238
|
+
*/
|
175
239
|
static VALUE
|
176
|
-
rb_capng_update(VALUE self,
|
177
|
-
VALUE
|
240
|
+
rb_capng_update(VALUE self, VALUE rb_action_name_or_action,
|
241
|
+
VALUE rb_capability_name_or_type, VALUE rb_capability_or_name)
|
178
242
|
{
|
179
243
|
int result = 0;
|
180
|
-
|
244
|
+
int capability = 0;
|
181
245
|
capng_type_t capability_type = 0;
|
182
246
|
capng_act_t action = 0;
|
183
247
|
|
184
248
|
switch (TYPE(rb_action_name_or_action)) {
|
185
|
-
|
186
|
-
|
187
|
-
|
188
|
-
|
189
|
-
|
190
|
-
|
191
|
-
|
192
|
-
|
193
|
-
|
194
|
-
|
195
|
-
|
249
|
+
case T_SYMBOL:
|
250
|
+
action =
|
251
|
+
action_name_to_action_type(RSTRING_PTR(rb_sym2str(rb_action_name_or_action)));
|
252
|
+
break;
|
253
|
+
case T_STRING:
|
254
|
+
action = action_name_to_action_type(StringValuePtr(rb_action_name_or_action));
|
255
|
+
break;
|
256
|
+
case T_FIXNUM:
|
257
|
+
action = NUM2INT(rb_action_name_or_action);
|
258
|
+
break;
|
259
|
+
default:
|
260
|
+
rb_raise(rb_eArgError,
|
261
|
+
"Expected a String or a Symbol instance, or a capability type constant");
|
196
262
|
}
|
197
263
|
|
198
264
|
switch (TYPE(rb_capability_name_or_type)) {
|
199
|
-
|
200
|
-
|
201
|
-
|
202
|
-
|
203
|
-
|
204
|
-
|
205
|
-
|
206
|
-
|
207
|
-
|
208
|
-
|
209
|
-
|
265
|
+
case T_SYMBOL:
|
266
|
+
capability_type = capability_type_name_to_capability_type(
|
267
|
+
RSTRING_PTR(rb_sym2str(rb_capability_name_or_type)));
|
268
|
+
break;
|
269
|
+
case T_STRING:
|
270
|
+
capability_type = capability_type_name_to_capability_type(
|
271
|
+
StringValuePtr(rb_capability_name_or_type));
|
272
|
+
break;
|
273
|
+
case T_FIXNUM:
|
274
|
+
capability_type = NUM2INT(rb_capability_name_or_type);
|
275
|
+
break;
|
276
|
+
default:
|
277
|
+
rb_raise(rb_eArgError,
|
278
|
+
"Expected a String or a Symbol instance, or a capability type constant");
|
210
279
|
}
|
211
280
|
|
212
281
|
switch (TYPE(rb_capability_or_name)) {
|
213
|
-
|
214
|
-
|
215
|
-
|
216
|
-
|
217
|
-
|
218
|
-
|
219
|
-
|
220
|
-
|
221
|
-
|
222
|
-
|
223
|
-
|
282
|
+
case T_SYMBOL:
|
283
|
+
capability =
|
284
|
+
capng_name_to_capability(RSTRING_PTR(rb_sym2str(rb_capability_or_name)));
|
285
|
+
if (capability == -1) {
|
286
|
+
rb_raise(rb_eRuntimeError, "Unknown capability: %s",
|
287
|
+
RSTRING_PTR(rb_sym2str(rb_capability_or_name)));
|
288
|
+
}
|
289
|
+
break;
|
290
|
+
case T_STRING:
|
291
|
+
capability = capng_name_to_capability(StringValuePtr(rb_capability_or_name));
|
292
|
+
if (capability == -1) {
|
293
|
+
rb_raise(rb_eRuntimeError, "Unknown capability: %s",
|
294
|
+
StringValuePtr(rb_capability_or_name));
|
295
|
+
}
|
296
|
+
break;
|
297
|
+
case T_FIXNUM:
|
298
|
+
capability = NUM2INT(rb_capability_or_name);
|
299
|
+
break;
|
300
|
+
default:
|
301
|
+
rb_raise(rb_eArgError,
|
302
|
+
"Expected a String or a Symbol instance, or a capability constant");
|
224
303
|
}
|
225
304
|
|
226
305
|
result = capng_update(action, capability_type, capability);
|
@@ -231,6 +310,15 @@ rb_capng_update(VALUE self,
|
|
231
310
|
return Qfalse;
|
232
311
|
}
|
233
312
|
|
313
|
+
/*
|
314
|
+
* Apply capabilities on specified target.
|
315
|
+
*
|
316
|
+
* @param rb_select_name_or_enum [Symbol or String or Fixnum]
|
317
|
+
* targets are CAPS, BOUNDS, BOTH, and AMBIENT for supported platform.
|
318
|
+
*
|
319
|
+
* @return [Boolean]
|
320
|
+
*
|
321
|
+
*/
|
234
322
|
static VALUE
|
235
323
|
rb_capng_apply(VALUE self, VALUE rb_select_name_or_enum)
|
236
324
|
{
|
@@ -238,17 +326,19 @@ rb_capng_apply(VALUE self, VALUE rb_select_name_or_enum)
|
|
238
326
|
capng_select_t select = 0;
|
239
327
|
|
240
328
|
switch (TYPE(rb_select_name_or_enum)) {
|
241
|
-
|
242
|
-
|
243
|
-
|
244
|
-
|
245
|
-
|
246
|
-
|
247
|
-
|
248
|
-
|
249
|
-
|
250
|
-
|
251
|
-
|
329
|
+
case T_SYMBOL:
|
330
|
+
select =
|
331
|
+
select_name_to_select_type(RSTRING_PTR(rb_sym2str(rb_select_name_or_enum)));
|
332
|
+
break;
|
333
|
+
case T_STRING:
|
334
|
+
select = select_name_to_select_type(StringValuePtr(rb_select_name_or_enum));
|
335
|
+
break;
|
336
|
+
case T_FIXNUM:
|
337
|
+
select = NUM2INT(rb_select_name_or_enum);
|
338
|
+
break;
|
339
|
+
default:
|
340
|
+
rb_raise(rb_eArgError,
|
341
|
+
"Expected a String or a Symbol instance, or a capability type constant");
|
252
342
|
}
|
253
343
|
|
254
344
|
result = capng_apply(select);
|
@@ -259,6 +349,12 @@ rb_capng_apply(VALUE self, VALUE rb_select_name_or_enum)
|
|
259
349
|
return Qfalse;
|
260
350
|
}
|
261
351
|
|
352
|
+
/*
|
353
|
+
* Lock capabilities.
|
354
|
+
*
|
355
|
+
* @return [Boolean]
|
356
|
+
*
|
357
|
+
*/
|
262
358
|
static VALUE
|
263
359
|
rb_capng_lock(VALUE self)
|
264
360
|
{
|
@@ -272,6 +368,14 @@ rb_capng_lock(VALUE self)
|
|
272
368
|
return Qfalse;
|
273
369
|
}
|
274
370
|
|
371
|
+
/*
|
372
|
+
* Change the credentials retaining capabilities.
|
373
|
+
* @param rb_uid [Fixnum] User ID.
|
374
|
+
* @param rb_gid [Fixnum] Group ID.
|
375
|
+
* @param rb_flags [Fixnum] CapNG::Flags constants.
|
376
|
+
*
|
377
|
+
* @see: capng_change_id(3)
|
378
|
+
*/
|
275
379
|
static VALUE
|
276
380
|
rb_capng_change_id(VALUE self, VALUE rb_uid, VALUE rb_gid, VALUE rb_flags)
|
277
381
|
{
|
@@ -282,9 +386,20 @@ rb_capng_change_id(VALUE self, VALUE rb_uid, VALUE rb_gid, VALUE rb_flags)
|
|
282
386
|
if (result == 0)
|
283
387
|
return Qtrue;
|
284
388
|
else
|
285
|
-
rb_raise(rb_eRuntimeError,
|
389
|
+
rb_raise(rb_eRuntimeError,
|
390
|
+
"Calling capng_change_id is failed with: (exitcode: %d)\n",
|
391
|
+
result);
|
286
392
|
}
|
287
393
|
|
394
|
+
/*
|
395
|
+
* Check whether capabilities on specified target or not.
|
396
|
+
*
|
397
|
+
* @param rb_select_name_or_enum [Symbol or String or Fixnum]
|
398
|
+
* targets are CAPS, BOUNDS, BOTH, and AMBIENT for supported platform.
|
399
|
+
*
|
400
|
+
* @return [Integer]
|
401
|
+
*
|
402
|
+
*/
|
288
403
|
static VALUE
|
289
404
|
rb_capng_have_capabilities_p(VALUE self, VALUE rb_select_name_or_enum)
|
290
405
|
{
|
@@ -292,56 +407,77 @@ rb_capng_have_capabilities_p(VALUE self, VALUE rb_select_name_or_enum)
|
|
292
407
|
capng_select_t select = 0;
|
293
408
|
|
294
409
|
switch (TYPE(rb_select_name_or_enum)) {
|
295
|
-
|
296
|
-
|
297
|
-
|
298
|
-
|
299
|
-
|
300
|
-
|
301
|
-
|
302
|
-
|
303
|
-
|
304
|
-
|
305
|
-
|
410
|
+
case T_SYMBOL:
|
411
|
+
select =
|
412
|
+
select_name_to_select_type(RSTRING_PTR(rb_sym2str(rb_select_name_or_enum)));
|
413
|
+
break;
|
414
|
+
case T_STRING:
|
415
|
+
select = select_name_to_select_type(StringValuePtr(rb_select_name_or_enum));
|
416
|
+
break;
|
417
|
+
case T_FIXNUM:
|
418
|
+
select = NUM2INT(rb_select_name_or_enum);
|
419
|
+
break;
|
420
|
+
default:
|
421
|
+
rb_raise(rb_eArgError,
|
422
|
+
"Expected a String or a Symbol instance, or a capability type constant");
|
306
423
|
}
|
307
424
|
result = capng_have_capabilities(select);
|
308
425
|
|
309
426
|
return INT2NUM(result);
|
310
427
|
}
|
311
428
|
|
429
|
+
/*
|
430
|
+
* Check whether capabilities on specified target or not.
|
431
|
+
*
|
432
|
+
* @param rb_capability_name_or_type [Symbol or String or Fixnum] types are EFFECTIVE,
|
433
|
+
* INHERITABLE, PERMITTED, and AMBIENT for supported platform.
|
434
|
+
* @param rb_capability_or_name [Symbol or String or Fixnum]
|
435
|
+
* Capability name or constants.
|
436
|
+
*
|
437
|
+
* @see: [CapNG::Capability]
|
438
|
+
*
|
439
|
+
* @return [Boolean]
|
440
|
+
*
|
441
|
+
*/
|
312
442
|
static VALUE
|
313
|
-
rb_capng_have_capability_p(VALUE self, VALUE rb_capability_name_or_type,
|
443
|
+
rb_capng_have_capability_p(VALUE self, VALUE rb_capability_name_or_type,
|
444
|
+
VALUE rb_capability_or_name)
|
314
445
|
{
|
315
446
|
int result = 0;
|
316
447
|
unsigned int capability = 0;
|
317
448
|
capng_type_t capability_type = 0;
|
318
449
|
|
319
450
|
switch (TYPE(rb_capability_name_or_type)) {
|
320
|
-
|
321
|
-
|
322
|
-
|
323
|
-
|
324
|
-
|
325
|
-
|
326
|
-
|
327
|
-
|
328
|
-
|
329
|
-
|
330
|
-
|
451
|
+
case T_SYMBOL:
|
452
|
+
capability_type = capability_type_name_to_capability_type(
|
453
|
+
RSTRING_PTR(rb_sym2str(rb_capability_name_or_type)));
|
454
|
+
break;
|
455
|
+
case T_STRING:
|
456
|
+
capability_type = capability_type_name_to_capability_type(
|
457
|
+
StringValuePtr(rb_capability_name_or_type));
|
458
|
+
break;
|
459
|
+
case T_FIXNUM:
|
460
|
+
capability_type = NUM2INT(rb_capability_name_or_type);
|
461
|
+
break;
|
462
|
+
default:
|
463
|
+
rb_raise(rb_eArgError,
|
464
|
+
"Expected a String or a Symbol instance, or a capability type constant");
|
331
465
|
}
|
332
466
|
|
333
467
|
switch (TYPE(rb_capability_or_name)) {
|
334
|
-
|
335
|
-
|
336
|
-
|
337
|
-
|
338
|
-
|
339
|
-
|
340
|
-
|
341
|
-
|
342
|
-
|
343
|
-
|
344
|
-
|
468
|
+
case T_SYMBOL:
|
469
|
+
capability =
|
470
|
+
capng_name_to_capability(RSTRING_PTR(rb_sym2str(rb_capability_or_name)));
|
471
|
+
break;
|
472
|
+
case T_STRING:
|
473
|
+
capability = capng_name_to_capability(StringValuePtr(rb_capability_or_name));
|
474
|
+
break;
|
475
|
+
case T_FIXNUM:
|
476
|
+
capability = NUM2INT(rb_capability_or_name);
|
477
|
+
break;
|
478
|
+
default:
|
479
|
+
rb_raise(rb_eArgError,
|
480
|
+
"Expected a String or a Symbol instance, or a capability constant");
|
345
481
|
}
|
346
482
|
|
347
483
|
result = capng_have_capability(capability_type, capability);
|
@@ -352,11 +488,19 @@ rb_capng_have_capability_p(VALUE self, VALUE rb_capability_name_or_type, VALUE r
|
|
352
488
|
return Qfalse;
|
353
489
|
}
|
354
490
|
|
491
|
+
/*
|
492
|
+
* Retrieve capabilities from file.
|
493
|
+
*
|
494
|
+
* @param rb_file [File] target file object
|
495
|
+
*
|
496
|
+
* @return [Boolean]
|
497
|
+
*
|
498
|
+
*/
|
355
499
|
static VALUE
|
356
500
|
rb_capng_get_caps_file(VALUE self, VALUE rb_file)
|
357
501
|
{
|
358
502
|
int result = 0, fd = 0;
|
359
|
-
rb_io_t
|
503
|
+
rb_io_t* fptr = NULL;
|
360
504
|
|
361
505
|
Check_Type(rb_file, T_FILE);
|
362
506
|
|
@@ -373,11 +517,19 @@ rb_capng_get_caps_file(VALUE self, VALUE rb_file)
|
|
373
517
|
return Qfalse;
|
374
518
|
}
|
375
519
|
|
520
|
+
/*
|
521
|
+
* Apply capabilities on specified target (file specific version).
|
522
|
+
*
|
523
|
+
* @param rb_file [File] target file object
|
524
|
+
*
|
525
|
+
* @return [Boolean]
|
526
|
+
*
|
527
|
+
*/
|
376
528
|
static VALUE
|
377
529
|
rb_capng_apply_caps_file(VALUE self, VALUE rb_file)
|
378
530
|
{
|
379
531
|
int result = 0, fd = 0;
|
380
|
-
rb_io_t
|
532
|
+
rb_io_t* fptr = NULL;
|
381
533
|
|
382
534
|
Check_Type(rb_file, T_FILE);
|
383
535
|
|
@@ -395,16 +547,14 @@ rb_capng_apply_caps_file(VALUE self, VALUE rb_file)
|
|
395
547
|
return Qfalse;
|
396
548
|
}
|
397
549
|
|
398
|
-
|
399
550
|
void
|
400
551
|
Init_capng(void)
|
401
552
|
{
|
402
|
-
rb_cCapNG = rb_define_class("CapNG", rb_cObject);
|
553
|
+
VALUE rb_cCapNG = rb_define_class("CapNG", rb_cObject);
|
403
554
|
|
404
555
|
rb_define_alloc_func(rb_cCapNG, rb_capng_alloc);
|
405
556
|
|
406
557
|
rb_define_method(rb_cCapNG, "initialize", rb_capng_initialize, -1);
|
407
|
-
rb_define_method(rb_cCapNG, "return_code", rb_capng_return_code, 0);
|
408
558
|
rb_define_method(rb_cCapNG, "clear", rb_capng_clear, 1);
|
409
559
|
rb_define_method(rb_cCapNG, "fill", rb_capng_fill, 1);
|
410
560
|
rb_define_method(rb_cCapNG, "setpid", rb_capng_setpid, 1);
|