capng_c 0.1.8 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: d8fb8b88d94a62f191e40dd68b4ec9b2e8c088de2d58d11eee06acee1fccff5a
4
- data.tar.gz: fef4a3cfb603eb2399453adb308b3e573e07916504c63ac93fd65caab4455f13
3
+ metadata.gz: '09424f043b085bf67c01b1b452d4a4f2fc7c60c1afc6c747b1c0d2fe6a993885'
4
+ data.tar.gz: 5ca5f2a6d6532d6a4a5e3101003790217704739be145c437194fbfc71f6bcd45
5
5
  SHA512:
6
- metadata.gz: b9852afd96a5821ec3133c8b72c783af1ea0a5a5cf85645a9491335a76d8eb03e50e170abec25b9e18255a66952bb1ae2aef4505d883981dd7a928f2c8f83be3
7
- data.tar.gz: 4d4ea024e06ce6d55276bc4e87b227836a7eab13d75417e457ab1adec6cf4042e7f0a8b39494f484f164681fb46704eaeebf15aa5fd06e75d92aa7a73ec2f4f2
6
+ metadata.gz: 8f3a2e7470baece0fe2b391a9b90f798b5a3eb1ba57327793212bc4fcfaaf419316dd42e7d08ac616705495dfcf33097dcaa6060cfaa256f2e3428ebfddb50bd
7
+ data.tar.gz: e9fdef39ef5ae17e7f825cf3fea0cbc45a27345eecd7790d95eb0e90d2b83fc63d759bd57bb3081e32493f41175954db86f9d5f7f2a0830ba0c818ebc78c0954
@@ -25,7 +25,8 @@ if Process.uid != 0
25
25
  end
26
26
 
27
27
  path = ARGV[0]
28
- capng = CapNG.new(:file, path)
28
+ capng = CapNG.new
29
+ capng.caps_file(path)
29
30
  print = CapNG::Print.new
30
31
  puts "capability: #{print.caps_text(:buffer, :effective)}"
31
32
  capng.clear(:caps)
@@ -33,12 +33,6 @@
33
33
  * @capng = CapNG.new(:other_process, 12345)
34
34
  * @capng.have_capability?(:effective, :dac_override)
35
35
  *
36
- * @example
37
- * # File capability example
38
- * require 'capng'
39
- *
40
- * @capng = CapNG.new(:file, "/path/to/file")
41
- * @capng.have_capability?(:effective, :chown)
42
36
  */
43
37
  /* clang-format on */
44
38
 
@@ -85,13 +79,12 @@ rb_capng_alloc(VALUE klass)
85
79
  static VALUE
86
80
  rb_capng_initialize(int argc, VALUE* argv, VALUE self)
87
81
  {
88
- VALUE rb_target, rb_pid_or_file;
82
+ VALUE rb_target, rb_pid;
89
83
  int result = 0;
90
84
  char* target = NULL;
91
- int pid = 0, fd = 0;
92
- rb_io_t* fptr = NULL;
85
+ int pid = 0;
93
86
 
94
- rb_scan_args(argc, argv, "02", &rb_target, &rb_pid_or_file);
87
+ rb_scan_args(argc, argv, "02", &rb_target, &rb_pid);
95
88
 
96
89
  if (NIL_P(rb_target)) {
97
90
  return Qnil;
@@ -111,40 +104,19 @@ rb_capng_initialize(int argc, VALUE* argv, VALUE self)
111
104
  rb_raise(rb_eRuntimeError, "Couldn't get current process' capability");
112
105
  }
113
106
  } else if (strcmp(target, "other_process") == 0) {
114
- Check_Type(rb_pid_or_file, T_FIXNUM);
107
+ Check_Type(rb_pid, T_FIXNUM);
115
108
 
116
- pid = NUM2INT(rb_pid_or_file);
109
+ pid = NUM2INT(rb_pid);
117
110
  capng_setpid(pid);
118
111
  result = capng_get_caps_process();
119
112
  if (result != 0) {
120
113
  rb_raise(rb_eRuntimeError, "Couldn't get current process' capability");
121
114
  }
122
- } else if (strcmp(target, "file") == 0) {
123
- Check_Type(rb_pid_or_file, T_FILE);
124
-
125
- fptr = RFILE(rb_pid_or_file)->fptr;
126
- fd = fptr->fd;
127
- result = capng_get_caps_fd(fd);
128
- /* Just store result into instance variable. */
129
- /* This is because capng_get_caps_fd should return 0 if file cap is not set. */
130
- rb_iv_set(self, "@return_code", INT2NUM(result));
131
115
  }
132
116
 
133
117
  return Qnil;
134
118
  }
135
119
 
136
- /*
137
- * Retrieve capability API status code on [CapNG#initialize] and file capability target.
138
- *
139
- * @return [@return_code]
140
- *
141
- */
142
- static VALUE
143
- rb_capng_return_code(VALUE self)
144
- {
145
- return rb_iv_get(self, "@return_code");
146
- }
147
-
148
120
  /*
149
121
  * Clear capabilities on specified target.
150
122
  *
@@ -269,7 +241,7 @@ rb_capng_update(VALUE self, VALUE rb_action_name_or_action,
269
241
  VALUE rb_capability_name_or_type, VALUE rb_capability_or_name)
270
242
  {
271
243
  int result = 0;
272
- unsigned int capability = 0;
244
+ int capability = 0;
273
245
  capng_type_t capability_type = 0;
274
246
  capng_act_t action = 0;
275
247
 
@@ -310,10 +282,18 @@ rb_capng_update(VALUE self, VALUE rb_action_name_or_action,
310
282
  case T_SYMBOL:
311
283
  capability =
312
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
+ }
313
289
  break;
314
290
  case T_STRING:
315
291
  capability = capng_name_to_capability(StringValuePtr(rb_capability_or_name));
316
- break;
292
+ if (capability == -1) {
293
+ rb_raise(rb_eRuntimeError, "Unknown capability: %s",
294
+ StringValuePtr(rb_capability_or_name));
295
+ }
296
+ break;
317
297
  case T_FIXNUM:
318
298
  capability = NUM2INT(rb_capability_or_name);
319
299
  break;
@@ -575,7 +555,6 @@ Init_capng(void)
575
555
  rb_define_alloc_func(rb_cCapNG, rb_capng_alloc);
576
556
 
577
557
  rb_define_method(rb_cCapNG, "initialize", rb_capng_initialize, -1);
578
- rb_define_method(rb_cCapNG, "return_code", rb_capng_return_code, 0);
579
558
  rb_define_method(rb_cCapNG, "clear", rb_capng_clear, 1);
580
559
  rb_define_method(rb_cCapNG, "fill", rb_capng_fill, 1);
581
560
  rb_define_method(rb_cCapNG, "setpid", rb_capng_setpid, 1);
@@ -14,21 +14,6 @@ class CapNG
14
14
  # :nodoc:
15
15
  # @private
16
16
  alias_method :update_raw, :update
17
- # :nodoc:
18
- # @private
19
- alias_method :initialize_raw, :initialize
20
-
21
- def initialize(target = nil, pid_or_path = nil)
22
- if target && pid_or_path.is_a?(Integer)
23
- initialize_raw(target, pid_or_path)
24
- elsif target && pid_or_path.is_a?(String) && File.exist?(pid_or_path)
25
- File.open(pid_or_path) do |file|
26
- initialize_raw(target, file);
27
- end
28
- else
29
- initialize_raw(target, pid_or_path)
30
- end
31
- end
32
17
 
33
18
  def caps_file(file_or_string_path)
34
19
  if file_or_string_path.is_a?(String) && File.exist?(file_or_string_path)
@@ -1,3 +1,3 @@
1
1
  class CapNG
2
- VERSION = "0.1.8"
2
+ VERSION = "0.2.0"
3
3
  end
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.1.8
4
+ version: 0.2.0
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-09 00:00:00.000000000 Z
11
+ date: 2020-11-10 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler