capng_c 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 88da08aa05f1a6e84b2b57fb2fca90a1d0c0d4dde8585dbad9e2f848e286cef6
4
+ data.tar.gz: 28a4762a3f921fbe0b06d1913d151d907b12a4558d1941fd7b9fed2440974eb6
5
+ SHA512:
6
+ metadata.gz: d6880731ae31f78a4b8ff1734b8638c1eddb86ec0bf519f9a6a13fe1b3410d7f1488103548954ba17fd5fa6e834eacd94275c46bdb650cf70f15ab901ab8ac84
7
+ data.tar.gz: 381f2a5abde2165d4f31513d3ae9086ae7d183747f53993ff492b7e255fbcfa9bbefdf9da8035027cc6cf0e330c9cf6efea69b260e329d685e4d95f81a25f988
@@ -0,0 +1,11 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /_yardoc/
4
+ /coverage/
5
+ /doc/
6
+ /pkg/
7
+ /spec/reports/
8
+ /tmp/
9
+ /vendor/
10
+ Gemfile.lock
11
+ /lib/capng/capng.so
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source "https://rubygems.org"
2
+
3
+ # Specify your gem's dependencies in ioext.gemspec
4
+ gemspec
data/LICENSE ADDED
@@ -0,0 +1,201 @@
1
+ Apache License
2
+ Version 2.0, January 2004
3
+ http://www.apache.org/licenses/
4
+
5
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6
+
7
+ 1. Definitions.
8
+
9
+ "License" shall mean the terms and conditions for use, reproduction,
10
+ and distribution as defined by Sections 1 through 9 of this document.
11
+
12
+ "Licensor" shall mean the copyright owner or entity authorized by
13
+ the copyright owner that is granting the License.
14
+
15
+ "Legal Entity" shall mean the union of the acting entity and all
16
+ other entities that control, are controlled by, or are under common
17
+ control with that entity. For the purposes of this definition,
18
+ "control" means (i) the power, direct or indirect, to cause the
19
+ direction or management of such entity, whether by contract or
20
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
21
+ outstanding shares, or (iii) beneficial ownership of such entity.
22
+
23
+ "You" (or "Your") shall mean an individual or Legal Entity
24
+ exercising permissions granted by this License.
25
+
26
+ "Source" form shall mean the preferred form for making modifications,
27
+ including but not limited to software source code, documentation
28
+ source, and configuration files.
29
+
30
+ "Object" form shall mean any form resulting from mechanical
31
+ transformation or translation of a Source form, including but
32
+ not limited to compiled object code, generated documentation,
33
+ and conversions to other media types.
34
+
35
+ "Work" shall mean the work of authorship, whether in Source or
36
+ Object form, made available under the License, as indicated by a
37
+ copyright notice that is included in or attached to the work
38
+ (an example is provided in the Appendix below).
39
+
40
+ "Derivative Works" shall mean any work, whether in Source or Object
41
+ form, that is based on (or derived from) the Work and for which the
42
+ editorial revisions, annotations, elaborations, or other modifications
43
+ represent, as a whole, an original work of authorship. For the purposes
44
+ of this License, Derivative Works shall not include works that remain
45
+ separable from, or merely link (or bind by name) to the interfaces of,
46
+ the Work and Derivative Works thereof.
47
+
48
+ "Contribution" shall mean any work of authorship, including
49
+ the original version of the Work and any modifications or additions
50
+ to that Work or Derivative Works thereof, that is intentionally
51
+ submitted to Licensor for inclusion in the Work by the copyright owner
52
+ or by an individual or Legal Entity authorized to submit on behalf of
53
+ the copyright owner. For the purposes of this definition, "submitted"
54
+ means any form of electronic, verbal, or written communication sent
55
+ to the Licensor or its representatives, including but not limited to
56
+ communication on electronic mailing lists, source code control systems,
57
+ and issue tracking systems that are managed by, or on behalf of, the
58
+ Licensor for the purpose of discussing and improving the Work, but
59
+ excluding communication that is conspicuously marked or otherwise
60
+ designated in writing by the copyright owner as "Not a Contribution."
61
+
62
+ "Contributor" shall mean Licensor and any individual or Legal Entity
63
+ on behalf of whom a Contribution has been received by Licensor and
64
+ subsequently incorporated within the Work.
65
+
66
+ 2. Grant of Copyright License. Subject to the terms and conditions of
67
+ this License, each Contributor hereby grants to You a perpetual,
68
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69
+ copyright license to reproduce, prepare Derivative Works of,
70
+ publicly display, publicly perform, sublicense, and distribute the
71
+ Work and such Derivative Works in Source or Object form.
72
+
73
+ 3. Grant of Patent License. Subject to the terms and conditions of
74
+ this License, each Contributor hereby grants to You a perpetual,
75
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76
+ (except as stated in this section) patent license to make, have made,
77
+ use, offer to sell, sell, import, and otherwise transfer the Work,
78
+ where such license applies only to those patent claims licensable
79
+ by such Contributor that are necessarily infringed by their
80
+ Contribution(s) alone or by combination of their Contribution(s)
81
+ with the Work to which such Contribution(s) was submitted. If You
82
+ institute patent litigation against any entity (including a
83
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
84
+ or a Contribution incorporated within the Work constitutes direct
85
+ or contributory patent infringement, then any patent licenses
86
+ granted to You under this License for that Work shall terminate
87
+ as of the date such litigation is filed.
88
+
89
+ 4. Redistribution. You may reproduce and distribute copies of the
90
+ Work or Derivative Works thereof in any medium, with or without
91
+ modifications, and in Source or Object form, provided that You
92
+ meet the following conditions:
93
+
94
+ (a) You must give any other recipients of the Work or
95
+ Derivative Works a copy of this License; and
96
+
97
+ (b) You must cause any modified files to carry prominent notices
98
+ stating that You changed the files; and
99
+
100
+ (c) You must retain, in the Source form of any Derivative Works
101
+ that You distribute, all copyright, patent, trademark, and
102
+ attribution notices from the Source form of the Work,
103
+ excluding those notices that do not pertain to any part of
104
+ the Derivative Works; and
105
+
106
+ (d) If the Work includes a "NOTICE" text file as part of its
107
+ distribution, then any Derivative Works that You distribute must
108
+ include a readable copy of the attribution notices contained
109
+ within such NOTICE file, excluding those notices that do not
110
+ pertain to any part of the Derivative Works, in at least one
111
+ of the following places: within a NOTICE text file distributed
112
+ as part of the Derivative Works; within the Source form or
113
+ documentation, if provided along with the Derivative Works; or,
114
+ within a display generated by the Derivative Works, if and
115
+ wherever such third-party notices normally appear. The contents
116
+ of the NOTICE file are for informational purposes only and
117
+ do not modify the License. You may add Your own attribution
118
+ notices within Derivative Works that You distribute, alongside
119
+ or as an addendum to the NOTICE text from the Work, provided
120
+ that such additional attribution notices cannot be construed
121
+ as modifying the License.
122
+
123
+ You may add Your own copyright statement to Your modifications and
124
+ may provide additional or different license terms and conditions
125
+ for use, reproduction, or distribution of Your modifications, or
126
+ for any such Derivative Works as a whole, provided Your use,
127
+ reproduction, and distribution of the Work otherwise complies with
128
+ the conditions stated in this License.
129
+
130
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
131
+ any Contribution intentionally submitted for inclusion in the Work
132
+ by You to the Licensor shall be under the terms and conditions of
133
+ this License, without any additional terms or conditions.
134
+ Notwithstanding the above, nothing herein shall supersede or modify
135
+ the terms of any separate license agreement you may have executed
136
+ with Licensor regarding such Contributions.
137
+
138
+ 6. Trademarks. This License does not grant permission to use the trade
139
+ names, trademarks, service marks, or product names of the Licensor,
140
+ except as required for reasonable and customary use in describing the
141
+ origin of the Work and reproducing the content of the NOTICE file.
142
+
143
+ 7. Disclaimer of Warranty. Unless required by applicable law or
144
+ agreed to in writing, Licensor provides the Work (and each
145
+ Contributor provides its Contributions) on an "AS IS" BASIS,
146
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147
+ implied, including, without limitation, any warranties or conditions
148
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149
+ PARTICULAR PURPOSE. You are solely responsible for determining the
150
+ appropriateness of using or redistributing the Work and assume any
151
+ risks associated with Your exercise of permissions under this License.
152
+
153
+ 8. Limitation of Liability. In no event and under no legal theory,
154
+ whether in tort (including negligence), contract, or otherwise,
155
+ unless required by applicable law (such as deliberate and grossly
156
+ negligent acts) or agreed to in writing, shall any Contributor be
157
+ liable to You for damages, including any direct, indirect, special,
158
+ incidental, or consequential damages of any character arising as a
159
+ result of this License or out of the use or inability to use the
160
+ Work (including but not limited to damages for loss of goodwill,
161
+ work stoppage, computer failure or malfunction, or any and all
162
+ other commercial damages or losses), even if such Contributor
163
+ has been advised of the possibility of such damages.
164
+
165
+ 9. Accepting Warranty or Additional Liability. While redistributing
166
+ the Work or Derivative Works thereof, You may choose to offer,
167
+ and charge a fee for, acceptance of support, warranty, indemnity,
168
+ or other liability obligations and/or rights consistent with this
169
+ License. However, in accepting such obligations, You may act only
170
+ on Your own behalf and on Your sole responsibility, not on behalf
171
+ of any other Contributor, and only if You agree to indemnify,
172
+ defend, and hold each Contributor harmless for any liability
173
+ incurred by, or claims asserted against, such Contributor by reason
174
+ of your accepting any such warranty or additional liability.
175
+
176
+ END OF TERMS AND CONDITIONS
177
+
178
+ APPENDIX: How to apply the Apache License to your work.
179
+
180
+ To apply the Apache License to your work, attach the following
181
+ boilerplate notice, with the fields enclosed by brackets "[]"
182
+ replaced with your own identifying information. (Don't include
183
+ the brackets!) The text should be enclosed in the appropriate
184
+ comment syntax for the file format. We also recommend that a
185
+ file or class name and description of purpose be included on the
186
+ same "printed page" as the copyright notice for easier
187
+ identification within third-party archives.
188
+
189
+ Copyright [yyyy] [name of copyright owner]
190
+
191
+ Licensed under the Apache License, Version 2.0 (the "License");
192
+ you may not use this file except in compliance with the License.
193
+ You may obtain a copy of the License at
194
+
195
+ http://www.apache.org/licenses/LICENSE-2.0
196
+
197
+ Unless required by applicable law or agreed to in writing, software
198
+ distributed under the License is distributed on an "AS IS" BASIS,
199
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
200
+ See the License for the specific language governing permissions and
201
+ limitations under the License.
@@ -0,0 +1,29 @@
1
+ # Capng_c
2
+
3
+ libcap-ng bindings for Ruby.
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ ```ruby
10
+ gem 'capng_c'
11
+ ```
12
+
13
+ And then execute:
14
+
15
+ $ bundle
16
+
17
+ Or install it yourself as:
18
+
19
+ $ gem install capng_c
20
+
21
+ ## Development
22
+
23
+ After checking out the repo, run `bin/setup` to install dependencies. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
24
+
25
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
26
+
27
+ ## Contributing
28
+
29
+ Bug reports and pull requests are welcome on GitHub at https://github.com/cosmo0920/capng_c.
@@ -0,0 +1,23 @@
1
+ require 'bundler'
2
+ Bundler::GemHelper.install_tasks
3
+
4
+ require "rake/testtask"
5
+ require "rake/clean"
6
+
7
+ Rake::TestTask.new(:test) do |t|
8
+ t.libs << "test"
9
+ t.libs << "lib"
10
+ t.test_files = FileList["test/**/test_*.rb"]
11
+ end
12
+
13
+ require "rake/extensiontask"
14
+
15
+ spec = eval File.read("capng_c.gemspec")
16
+
17
+ Rake::ExtensionTask.new("capng", spec) do |ext|
18
+ ext.lib_dir = "lib/capng"
19
+ end
20
+
21
+ CLEAN.include('lib/capng/capng.*')
22
+
23
+ task :default => [:clobber, :compile, :test]
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "capng"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start(__FILE__)
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,35 @@
1
+ lib = File.expand_path("lib", __dir__)
2
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
3
+ require "capng/version"
4
+
5
+ Gem::Specification.new do |spec|
6
+ spec.name = "capng_c"
7
+ spec.version = CapNG::VERSION
8
+ spec.authors = ["Hiroshi Hatake"]
9
+ spec.email = ["cosmo0920.wp@gmail.com"]
10
+
11
+ spec.summary = %q{libcap-ng bindings for Ruby.}
12
+ spec.description = spec.summary
13
+ spec.homepage = "https://github.com/cosmo0920/cap-ng_c"
14
+
15
+ spec.metadata["allowed_push_host"] = "https://rubygems.org"
16
+
17
+ spec.metadata["homepage_uri"] = spec.homepage
18
+ spec.metadata["source_code_uri"] = spec.homepage
19
+
20
+ # Specify which files should be added to the gem when it is released.
21
+ # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
22
+ spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
23
+ `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
24
+ end
25
+ spec.bindir = "exe"
26
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
27
+ spec.require_paths = ["lib"]
28
+ spec.extensions = ["ext/capng/extconf.rb"]
29
+ spec.required_ruby_version = Gem::Requirement.new(">= 2.4".freeze)
30
+
31
+ spec.add_development_dependency "bundler", [">= 1.16", "< 3"]
32
+ spec.add_development_dependency "rake", "~> 12.0"
33
+ spec.add_development_dependency "rake-compiler", "~> 1.0"
34
+ spec.add_development_dependency "test-unit", "~> 3.3.3"
35
+ end
@@ -0,0 +1,162 @@
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
+ struct CapNGCapability {};
17
+
18
+ static void capng_capability_free(void* capng);
19
+
20
+ static const rb_data_type_t rb_capng_capability_type = {
21
+ "capng_capability/c_runtime",
22
+ {
23
+ 0,
24
+ capng_capability_free,
25
+ 0,
26
+ },
27
+ NULL,
28
+ NULL,
29
+ RUBY_TYPED_FREE_IMMEDIATELY
30
+ };
31
+
32
+ static void
33
+ capng_capability_free(void* ptr)
34
+ {
35
+ xfree(ptr);
36
+ }
37
+
38
+ static VALUE
39
+ rb_capng_capability_alloc(VALUE klass)
40
+ {
41
+ VALUE obj;
42
+ struct CapNGCapability* capng_capability;
43
+ obj = TypedData_Make_Struct(
44
+ klass, struct CapNGCapability, &rb_capng_capability_type, capng_capability);
45
+ return obj;
46
+ }
47
+
48
+ static VALUE
49
+ rb_capng_capability_initialize(VALUE self)
50
+ {
51
+ return Qnil;
52
+ }
53
+
54
+ static VALUE
55
+ rb_capng_capability_to_name(VALUE self, VALUE rb_capability)
56
+ {
57
+ const char *name = capng_capability_to_name(NUM2UINT(rb_capability));
58
+
59
+ if (name)
60
+ return rb_str_new2(name);
61
+ else
62
+ return rb_str_new2("unknown");
63
+ }
64
+
65
+ static VALUE
66
+ rb_capng_capability_from_name(VALUE self, VALUE rb_capability_name_or_symbol)
67
+ {
68
+ unsigned int capability;
69
+
70
+ switch (TYPE(rb_capability_name_or_symbol)) {
71
+ case T_SYMBOL:
72
+ capability = capng_name_to_capability(RSTRING_PTR(rb_sym2str(rb_capability_name_or_symbol)));
73
+ break;
74
+ case T_STRING:
75
+ capability = capng_name_to_capability(StringValuePtr(rb_capability_name_or_symbol));
76
+ break;
77
+ default:
78
+ rb_raise(rb_eArgError, "Expected a String or a Symbol instance");
79
+ }
80
+ return INT2NUM(capability);
81
+ }
82
+
83
+ void
84
+ Init_capng_capability(VALUE rb_cCapNG)
85
+ {
86
+ rb_cCapability = rb_define_class_under(rb_cCapNG, "Capability", rb_cObject);
87
+
88
+ rb_define_alloc_func(rb_cCapability, rb_capng_capability_alloc);
89
+
90
+ rb_define_method(rb_cCapability, "initialize", rb_capng_capability_initialize, 0);
91
+ rb_define_method(rb_cCapability, "to_name", rb_capng_capability_to_name, 1);
92
+ rb_define_method(rb_cCapability, "from_name", rb_capng_capability_from_name, 1);
93
+
94
+ // Capability constants.
95
+ rb_define_const(rb_cCapability, "CHOWN", INT2NUM(CAP_CHOWN));
96
+ rb_define_const(rb_cCapability, "DAC_OVERRIDE", INT2NUM(CAP_DAC_OVERRIDE));
97
+ rb_define_const(rb_cCapability, "DAC_READ_SEARCH", INT2NUM(CAP_DAC_READ_SEARCH));
98
+ rb_define_const(rb_cCapability, "FOWNER", INT2NUM(CAP_FOWNER));
99
+ rb_define_const(rb_cCapability, "FSETID", INT2NUM(CAP_FSETID));
100
+ rb_define_const(rb_cCapability, "KILL", INT2NUM(CAP_KILL));
101
+ rb_define_const(rb_cCapability, "SETGID", INT2NUM(CAP_SETGID));
102
+ rb_define_const(rb_cCapability, "SETUID", INT2NUM(CAP_SETUID));
103
+ rb_define_const(rb_cCapability, "SETPCAP", INT2NUM(CAP_SETPCAP));
104
+ rb_define_const(rb_cCapability, "LINUX_IMMUTABLE", INT2NUM(CAP_LINUX_IMMUTABLE));
105
+ rb_define_const(rb_cCapability, "NET_BIND_SERIVCE", INT2NUM(CAP_NET_BIND_SERVICE));
106
+ rb_define_const(rb_cCapability, "NET_BROATCAST", INT2NUM(CAP_NET_BROADCAST));
107
+ rb_define_const(rb_cCapability, "NET_ADMIN", INT2NUM(CAP_NET_ADMIN));
108
+ rb_define_const(rb_cCapability, "NET_RAW", INT2NUM(CAP_NET_RAW));
109
+ rb_define_const(rb_cCapability, "IPC_LOCK", INT2NUM(CAP_IPC_LOCK));
110
+ rb_define_const(rb_cCapability, "IPC_OWNER", INT2NUM(CAP_IPC_OWNER));
111
+ rb_define_const(rb_cCapability, "SYS_MODULE", INT2NUM(CAP_SYS_MODULE));
112
+ rb_define_const(rb_cCapability, "SYS_RAWIO", INT2NUM(CAP_SYS_RAWIO));
113
+ rb_define_const(rb_cCapability, "SYS_CHROOT", INT2NUM(CAP_SYS_CHROOT));
114
+ rb_define_const(rb_cCapability, "SYS_PTRACE", INT2NUM(CAP_SYS_PTRACE));
115
+ rb_define_const(rb_cCapability, "SYS_PACCT", INT2NUM(CAP_SYS_PACCT));
116
+ rb_define_const(rb_cCapability, "SYS_ADMIN", INT2NUM(CAP_SYS_ADMIN));
117
+ rb_define_const(rb_cCapability, "SYS_BOOT", INT2NUM(CAP_SYS_BOOT));
118
+ rb_define_const(rb_cCapability, "SYS_NICE", INT2NUM(CAP_SYS_NICE));
119
+ rb_define_const(rb_cCapability, "SYS_RESOURCE", INT2NUM(CAP_SYS_RESOURCE));
120
+ rb_define_const(rb_cCapability, "SYS_TIME", INT2NUM(CAP_SYS_TIME));
121
+ rb_define_const(rb_cCapability, "TTY_CONFIG", INT2NUM(CAP_SYS_TTY_CONFIG));
122
+ rb_define_const(rb_cCapability, "MKNOD", INT2NUM(CAP_MKNOD));
123
+ rb_define_const(rb_cCapability, "LEASE", INT2NUM(CAP_LEASE));
124
+ rb_define_const(rb_cCapability, "AUDIT_WRITE", INT2NUM(CAP_AUDIT_WRITE));
125
+ rb_define_const(rb_cCapability, "AUDIT_CONTROL", INT2NUM(CAP_AUDIT_CONTROL));
126
+ #ifdef CAP_SETFCAP
127
+ rb_define_const(rb_cCapability, "SETFCAP", INT2NUM(CAP_SETFCAP));
128
+ #endif
129
+ #ifdef CAP_MAC_OVERRIDE
130
+ rb_define_const(rb_cCapability, "MAC_OVERRIDE", INT2NUM(CAP_MAC_OVERRIDE));
131
+ #endif
132
+ #ifdef CAP_MAC_ADMIN
133
+ rb_define_const(rb_cCapability, "MAC_ADMIN", INT2NUM(CAP_MAC_ADMIN));
134
+ #endif
135
+ #ifdef CAP_SYSLOG
136
+ rb_define_const(rb_cCapability, "SYSLOG", INT2NUM(CAP_SYSLOG));
137
+ #endif
138
+ #if defined(CAP_EPOLLWAKEUP) && defined(CAP_BLOCK_SUSPEND)
139
+ #error "Both CAP_EPOLLWAKEUP and CAP_BLOCK_SUSPEND are defined"
140
+ #endif
141
+ #ifdef CAP_EPOLLWAKEUP
142
+ rb_define_const(rb_cCapability, "EPOLLWAKEUP", INT2NUM(CAP_EPOLLWAKEUP));
143
+ #endif
144
+ #ifdef CAP_WAKE_ALARM
145
+ rb_define_const(rb_cCapability, "WAKE_ALARM", INT2NUM(CAP_WAKE_ALARM));
146
+ #endif
147
+ #ifdef CAP_BLOCK_SUSPEND
148
+ rb_define_const(rb_cCapability, "BLOCK_SUSPEND", INT2NUM(CAP_BLOCK_SUSPEND));
149
+ #endif
150
+ #ifdef CAP_AUDIT_READ
151
+ rb_define_const(rb_cCapability, "AUDIT_READ", INT2NUM(CAP_AUDIT_READ));
152
+ #endif
153
+ #ifdef CAP_PERFMON
154
+ rb_define_const(rb_cCapability, "PERFMON", INT2NUM(CAP_PERFMON));
155
+ #endif
156
+ #ifdef CAP_BPF
157
+ rb_define_const(rb_cCapability, "BPF", INT2NUM(CAP_BPF));
158
+ #endif
159
+ #ifdef CAP_CHECKPOINT_RESTORE
160
+ rb_define_const(rb_cCapability, "CHECKPOINT_RESTORE", INT2NUM(CAP_CHECKPOINT_RESTORE));
161
+ #endif
162
+ }
@@ -0,0 +1,277 @@
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
+ struct CapNG {};
17
+
18
+ static void capng_free(void* capng);
19
+
20
+ static const rb_data_type_t rb_capng_type = {
21
+ "capng/capng",
22
+ {
23
+ 0,
24
+ capng_free,
25
+ 0,
26
+ },
27
+ NULL,
28
+ NULL,
29
+ RUBY_TYPED_FREE_IMMEDIATELY
30
+ };
31
+
32
+ static void
33
+ capng_free(void* ptr)
34
+ {
35
+ xfree(ptr);
36
+ }
37
+
38
+ static VALUE
39
+ rb_capng_alloc(VALUE klass)
40
+ {
41
+ VALUE obj;
42
+ struct CapNG* capng;
43
+ obj = TypedData_Make_Struct(
44
+ klass, struct CapNG, &rb_capng_type, capng);
45
+ return obj;
46
+ }
47
+
48
+ static VALUE
49
+ rb_capng_initialize(VALUE self)
50
+ {
51
+ return Qnil;
52
+ }
53
+
54
+ static VALUE
55
+ rb_capng_clear(VALUE self, VALUE rb_action_set)
56
+ {
57
+ Check_Type(rb_action_set, T_FIXNUM);
58
+
59
+ capng_clear(NUM2INT(rb_action_set));
60
+
61
+ return Qnil;
62
+ }
63
+
64
+ static VALUE
65
+ rb_capng_fill(VALUE self, VALUE rb_action_set)
66
+ {
67
+ Check_Type(rb_action_set, T_FIXNUM);
68
+
69
+ capng_fill(NUM2INT(rb_action_set));
70
+
71
+ return Qnil;
72
+ }
73
+
74
+ static VALUE
75
+ rb_capng_setpid(VALUE self, VALUE rb_pid)
76
+ {
77
+ Check_Type(rb_pid, T_FIXNUM);
78
+
79
+ capng_setpid(NUM2INT(rb_pid));
80
+
81
+ return Qnil;
82
+ }
83
+
84
+ static VALUE
85
+ rb_capng_get_caps_process(VALUE self)
86
+ {
87
+ int result = 0;
88
+ result = capng_get_caps_process();
89
+
90
+ if (result == 0)
91
+ return Qtrue;
92
+ else
93
+ return Qfalse;
94
+ }
95
+
96
+ static VALUE
97
+ rb_capng_update(VALUE self, VALUE rb_action_set, VALUE rb_update_type, VALUE rb_capability_or_name)
98
+ {
99
+ int result = 0;
100
+ unsigned int capability = 0;
101
+
102
+ Check_Type(rb_action_set, T_FIXNUM);
103
+ Check_Type(rb_update_type, T_FIXNUM);
104
+
105
+ switch (TYPE(rb_capability_or_name)) {
106
+ case T_SYMBOL:
107
+ capability = capng_name_to_capability(RSTRING_PTR(rb_sym2str(rb_capability_or_name)));
108
+ break;
109
+ case T_STRING:
110
+ capability = capng_name_to_capability(StringValuePtr(rb_capability_or_name));
111
+ break;
112
+ case T_FIXNUM:
113
+ capability = NUM2INT(rb_capability_or_name);
114
+ break;
115
+ default:
116
+ rb_raise(rb_eArgError, "Expected a String or a Symbol instance, or a capability constant");
117
+ }
118
+
119
+ result = capng_update(NUM2UINT(rb_action_set), NUM2INT(rb_update_type), capability);
120
+
121
+ if (result == 0)
122
+ return Qtrue;
123
+ else
124
+ return Qfalse;
125
+ }
126
+
127
+ static VALUE
128
+ rb_capng_apply(VALUE self, VALUE rb_action_set)
129
+ {
130
+ int result = 0;
131
+
132
+ Check_Type(rb_action_set, T_FIXNUM);
133
+
134
+ result = capng_apply(NUM2INT(rb_action_set));
135
+
136
+ if (result == 0)
137
+ return Qtrue;
138
+ else
139
+ return Qfalse;
140
+ }
141
+
142
+ static VALUE
143
+ rb_capng_lock(VALUE self)
144
+ {
145
+ int result = 0;
146
+
147
+ result = capng_lock();
148
+
149
+ if (result == 0)
150
+ return Qtrue;
151
+ else
152
+ return Qfalse;
153
+ }
154
+
155
+ static VALUE
156
+ rb_capng_change_id(VALUE self, VALUE rb_uid, VALUE rb_gid, VALUE rb_flags)
157
+ {
158
+ int result = 0;
159
+
160
+ result = capng_change_id(NUM2INT(rb_uid), NUM2INT(rb_gid), NUM2INT(rb_flags));
161
+
162
+ if (result == 0)
163
+ return Qtrue;
164
+ else
165
+ return Qfalse;
166
+ }
167
+
168
+ static VALUE
169
+ rb_capng_have_capabilities_p(VALUE self, VALUE rb_select_enum)
170
+ {
171
+ int result = 0;
172
+
173
+ result = capng_have_capabilities(NUM2INT(rb_select_enum));
174
+
175
+ return INT2NUM(result);
176
+ }
177
+
178
+ static VALUE
179
+ rb_capng_have_capability_p(VALUE self, VALUE rb_update_type, VALUE rb_capability_or_name)
180
+ {
181
+ int result = 0;
182
+ unsigned int capability = 0;
183
+
184
+ switch (TYPE(rb_capability_or_name)) {
185
+ case T_SYMBOL:
186
+ capability = capng_name_to_capability(RSTRING_PTR(rb_sym2str(rb_capability_or_name)));
187
+ break;
188
+ case T_STRING:
189
+ capability = capng_name_to_capability(StringValuePtr(rb_capability_or_name));
190
+ break;
191
+ case T_FIXNUM:
192
+ capability = NUM2INT(rb_capability_or_name);
193
+ break;
194
+ default:
195
+ rb_raise(rb_eArgError, "Expected a String or a Symbol instance, or a capability constant");
196
+ }
197
+
198
+ result = capng_have_capability(NUM2INT(rb_update_type), capability);
199
+
200
+ if (result == 1)
201
+ return Qtrue;
202
+ else
203
+ return Qfalse;
204
+ }
205
+
206
+ static VALUE
207
+ rb_capng_get_caps_file(VALUE self, VALUE rb_file)
208
+ {
209
+ int result = 0, fd = 0;
210
+ rb_io_t *fptr = NULL;
211
+
212
+ Check_Type(rb_file, T_FILE);
213
+
214
+ if (NIL_P(rb_file)) {
215
+ return Qfalse;
216
+ }
217
+ fptr = RFILE(rb_file)->fptr;
218
+ fd = fptr->fd;
219
+ result = capng_get_caps_fd(fd);
220
+
221
+ if (result == 0)
222
+ return Qtrue;
223
+ else
224
+ return Qfalse;
225
+ }
226
+
227
+ static VALUE
228
+ rb_capng_apply_caps_file(VALUE self, VALUE rb_file)
229
+ {
230
+ int result = 0, fd = 0;
231
+ rb_io_t *fptr = NULL;
232
+
233
+ Check_Type(rb_file, T_FILE);
234
+
235
+ if (NIL_P(rb_file)) {
236
+ return Qfalse;
237
+ }
238
+
239
+ fptr = RFILE(rb_file)->fptr;
240
+ fd = fptr->fd;
241
+ result = capng_apply_caps_fd(fd);
242
+
243
+ if (result == 0)
244
+ return Qtrue;
245
+ else
246
+ return Qfalse;
247
+ }
248
+
249
+
250
+ void
251
+ Init_capng(void)
252
+ {
253
+ rb_cCapNG = rb_define_class("CapNG", rb_cObject);
254
+
255
+ rb_define_alloc_func(rb_cCapNG, rb_capng_alloc);
256
+
257
+ rb_define_method(rb_cCapNG, "initialize", rb_capng_initialize, 0);
258
+ rb_define_method(rb_cCapNG, "clear", rb_capng_clear, 1);
259
+ rb_define_method(rb_cCapNG, "fill", rb_capng_fill, 1);
260
+ rb_define_method(rb_cCapNG, "setpid", rb_capng_setpid, 1);
261
+ rb_define_method(rb_cCapNG, "caps_process", rb_capng_get_caps_process, 0);
262
+ rb_define_method(rb_cCapNG, "get_caps_process", rb_capng_get_caps_process, 0);
263
+ rb_define_method(rb_cCapNG, "update", rb_capng_update, 3);
264
+ rb_define_method(rb_cCapNG, "apply", rb_capng_apply, 1);
265
+ rb_define_method(rb_cCapNG, "lock", rb_capng_lock, 0);
266
+ rb_define_method(rb_cCapNG, "change_id", rb_capng_change_id, 3);
267
+ rb_define_method(rb_cCapNG, "have_capabilities?", rb_capng_have_capabilities_p, 1);
268
+ rb_define_method(rb_cCapNG, "have_capability?", rb_capng_have_capability_p, 2);
269
+ rb_define_method(rb_cCapNG, "get_caps_file", rb_capng_get_caps_file, 1);
270
+ rb_define_method(rb_cCapNG, "caps_file", rb_capng_get_caps_file, 1);
271
+ rb_define_method(rb_cCapNG, "apply_caps_file", rb_capng_apply_caps_file, 1);
272
+
273
+ Init_capng_enum(rb_cCapNG);
274
+ Init_capng_capability(rb_cCapNG);
275
+ Init_capng_print(rb_cCapNG);
276
+ Init_capng_state(rb_cCapNG);
277
+ }
@@ -0,0 +1,39 @@
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
+ #ifndef _CAPNG_H_
15
+ #define _CAPNG_H_
16
+
17
+ #include <ruby.h>
18
+ #include <ruby/encoding.h>
19
+ #include <ruby/io.h>
20
+
21
+ #include <cap-ng.h>
22
+ #include <stdio.h>
23
+
24
+ VALUE rb_cCapNG;
25
+ VALUE rb_cCapNGPrint;
26
+ VALUE rb_cCapability;
27
+ VALUE rb_cState;
28
+ VALUE rb_mAction;
29
+ VALUE rb_mSelect;
30
+ VALUE rb_mType;
31
+ VALUE rb_mResult;
32
+ VALUE rb_mPrint;
33
+ VALUE rb_mFlags;
34
+
35
+ void Init_capng_capability(VALUE);
36
+ void Init_capng_enum(VALUE);
37
+ void Init_capng_print(VALUE);
38
+ void Init_capng_state(VALUE);
39
+ #endif // _CAPNG_H
@@ -0,0 +1,59 @@
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
+ void Init_capng_enum(VALUE rb_cCapNG)
17
+ {
18
+ rb_mAction = rb_define_module_under(rb_cCapNG, "Action");
19
+ rb_mSelect = rb_define_module_under(rb_cCapNG, "Select");
20
+ rb_mType = rb_define_module_under(rb_cCapNG, "Type");
21
+ rb_mResult = rb_define_module_under(rb_cCapNG, "Result");
22
+ rb_mFlags = rb_define_module_under(rb_cCapNG, "Flags");
23
+
24
+ // capng_cat_t enum constants
25
+ rb_define_const(rb_mAction, "DROP", INT2NUM(CAPNG_DROP));
26
+ rb_define_const(rb_mAction, "ADD", INT2NUM(CAPNG_ADD));
27
+
28
+ // capng_select_t enum constants
29
+ rb_define_const(rb_mSelect, "CAPS", INT2NUM(CAPNG_SELECT_CAPS));
30
+ rb_define_const(rb_mSelect, "BOUNDS", INT2NUM(CAPNG_SELECT_BOUNDS));
31
+ rb_define_const(rb_mSelect, "BOTH", INT2NUM(CAPNG_SELECT_BOTH));
32
+ #if defined(CAPNG_SELECT_AMBIENT)
33
+ rb_define_const(rb_mSelect, "AMBIENT", INT2NUM(CAPNG_SELECT_AMBIENT));
34
+ #endif
35
+ #if defined(CAPNG_SELECT_ALL)
36
+ rb_define_const(rb_mSelect, "ALL", INT2NUM(CAPNG_SELECT_ALL));
37
+ #endif
38
+
39
+ // capng_type_t enum constants
40
+ rb_define_const(rb_mType, "EFFECTIVE", INT2NUM(CAPNG_EFFECTIVE));
41
+ rb_define_const(rb_mType, "PERMITTED", INT2NUM(CAPNG_PERMITTED));
42
+ rb_define_const(rb_mType, "INHERITABLE", INT2NUM(CAPNG_INHERITABLE));
43
+ rb_define_const(rb_mType, "BOUNDING_SET", INT2NUM(CAPNG_BOUNDING_SET));
44
+ #if defined(CAPNG_AMBIENT)
45
+ rb_define_const(rb_mType, "AMBIENT", INT2NUM(CAPNG_AMBIENT));
46
+ #endif
47
+
48
+ // capng_result_t enum constants
49
+ rb_define_const(rb_mResult, "FAIL", LONG2NUM(CAPNG_FAIL));
50
+ rb_define_const(rb_mResult, "NONE", LONG2NUM(CAPNG_NONE));
51
+ rb_define_const(rb_mResult, "PARTIAL", LONG2NUM(CAPNG_PARTIAL));
52
+ rb_define_const(rb_mResult, "FULL", LONG2NUM(CAPNG_FULL));
53
+
54
+ // capng_flags_t enum constants
55
+ rb_define_const(rb_mFlags, "NO_FLAG", LONG2NUM(CAPNG_NO_FLAG));
56
+ rb_define_const(rb_mFlags, "DROP_SUPP_GRP", LONG2NUM(CAPNG_DROP_SUPP_GRP));
57
+ rb_define_const(rb_mFlags, "CLEAR_BOUNDING", LONG2NUM(CAPNG_CLEAR_BOUNDING));
58
+ rb_define_const(rb_mFlags, "INIT_SUPP_GRP", LONG2NUM(CAPNG_INIT_SUPP_GRP));
59
+ }
@@ -0,0 +1,29 @@
1
+ # Copyright 2020- Hiroshi Hatake
2
+
3
+ # Licensed under the Apache License, Version 2.0 (the "License");
4
+ # you may not use this file except in compliance with the License.
5
+ # You may obtain a copy of the License at
6
+
7
+ # http://www.apache.org/licenses/LICENSE-2.0
8
+
9
+ # Unless required by applicable law or agreed to in writing, software
10
+ # distributed under the License is distributed on an "AS IS" BASIS,
11
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ # See the License for the specific language governing permissions and
13
+ # limitations under the License.
14
+
15
+ require "mkmf"
16
+ require "rbconfig"
17
+
18
+ libdir = RbConfig::CONFIG["libdir"]
19
+ includedir = RbConfig::CONFIG["includedir"]
20
+
21
+ dir_config("capng", includedir, libdir)
22
+
23
+ $LDFLAGS << " -lcap-ng "
24
+ $CFLAGS << " -Wall -std=c99 -fPIC "
25
+ # $CFLAGS << " -g -O0"
26
+
27
+ have_func("rb_sym2str", "ruby.h")
28
+ have_func("capng_get_caps_fd", "cap-ng.h")
29
+ create_makefile("capng/capng")
@@ -0,0 +1,105 @@
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
+ struct CapNGPrint {};
17
+
18
+ static void capng_print_free(void* capng);
19
+
20
+ static const rb_data_type_t rb_capng_print_type = {
21
+ "capng/print",
22
+ {
23
+ 0,
24
+ capng_print_free,
25
+ 0,
26
+ },
27
+ NULL,
28
+ NULL,
29
+ RUBY_TYPED_FREE_IMMEDIATELY
30
+ };
31
+
32
+ static void
33
+ capng_print_free(void* ptr)
34
+ {
35
+ xfree(ptr);
36
+ }
37
+
38
+ static VALUE
39
+ rb_capng_print_alloc(VALUE klass)
40
+ {
41
+ VALUE obj;
42
+ struct CapNGPrint* capng_print;
43
+ obj = TypedData_Make_Struct(
44
+ klass, struct CapNGPrint, &rb_capng_print_type, capng_print);
45
+ return obj;
46
+ }
47
+
48
+ static VALUE
49
+ rb_capng_print_initialize(VALUE self)
50
+ {
51
+ return Qnil;
52
+ }
53
+
54
+ static VALUE
55
+ rb_capng_print_caps_text(VALUE self, VALUE rb_where, VALUE rb_select_set)
56
+ {
57
+ char *result = NULL;
58
+
59
+ switch (NUM2LONG(rb_where)) {
60
+ case CAPNG_PRINT_STDOUT:
61
+ capng_print_caps_text(CAPNG_PRINT_STDOUT, NUM2LONG(rb_select_set));
62
+ break;
63
+ case CAPNG_PRINT_BUFFER:
64
+ result = capng_print_caps_text(CAPNG_PRINT_BUFFER, NUM2INT(rb_select_set));
65
+ }
66
+
67
+ if (result)
68
+ return rb_str_new2(result);
69
+ else
70
+ return rb_str_new2("(NULL)");
71
+ }
72
+
73
+ static VALUE
74
+ rb_capng_print_caps_numeric(VALUE self, VALUE rb_where, VALUE rb_select_set)
75
+ {
76
+ char *result = NULL;
77
+
78
+ switch (NUM2LONG(rb_where)) {
79
+ case CAPNG_PRINT_STDOUT:
80
+ capng_print_caps_numeric(CAPNG_PRINT_STDOUT, NUM2INT(rb_select_set));
81
+ break;
82
+ case CAPNG_PRINT_BUFFER:
83
+ result = capng_print_caps_numeric(CAPNG_PRINT_BUFFER, NUM2LONG(rb_select_set));
84
+ }
85
+
86
+ if (result)
87
+ return rb_str_new2(result);
88
+ else
89
+ return rb_str_new2("(NULL)");
90
+ }
91
+
92
+ void Init_capng_print(VALUE rb_cCapNG)
93
+ {
94
+ rb_cCapNGPrint = rb_define_class_under(rb_cCapNG, "Print", rb_cObject);
95
+
96
+ rb_define_alloc_func(rb_cCapNGPrint, rb_capng_print_alloc);
97
+
98
+ rb_define_method(rb_cCapNGPrint, "initialize", rb_capng_print_initialize, 0);
99
+ rb_define_method(rb_cCapNGPrint, "caps_text", rb_capng_print_caps_text, 2);
100
+ rb_define_method(rb_cCapNGPrint, "caps_numeric", rb_capng_print_caps_numeric, 2);
101
+
102
+ // capng_print_t enum constants
103
+ rb_define_const(rb_cCapNGPrint, "STDOUT", LONG2NUM(CAPNG_PRINT_STDOUT));
104
+ rb_define_const(rb_cCapNGPrint, "BUFFER", LONG2NUM(CAPNG_PRINT_BUFFER));
105
+ }
@@ -0,0 +1,100 @@
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
+ struct CapNGState {
17
+ void *state;
18
+ };
19
+
20
+ static void capng_state_free(void* capng);
21
+
22
+ static const rb_data_type_t rb_capng_state_type = {
23
+ "capng/state",
24
+ {
25
+ 0,
26
+ capng_state_free,
27
+ 0,
28
+ },
29
+ NULL,
30
+ NULL,
31
+ RUBY_TYPED_FREE_IMMEDIATELY
32
+ };
33
+
34
+ static void
35
+ capng_state_free(void* ptr)
36
+ {
37
+ xfree(ptr);
38
+ }
39
+
40
+ static VALUE
41
+ rb_capng_state_alloc(VALUE klass)
42
+ {
43
+ VALUE obj;
44
+ struct CapNGState* capng_state;
45
+ obj = TypedData_Make_Struct(
46
+ klass, struct CapNGState, &rb_capng_state_type, capng_state);
47
+ return obj;
48
+ }
49
+
50
+ static VALUE
51
+ rb_capng_state_initialize(VALUE self)
52
+ {
53
+ struct CapNGState* capng_state;
54
+
55
+ TypedData_Get_Struct(self, struct CapNGState, &rb_capng_state_type, capng_state);
56
+
57
+ capng_state->state = NULL;
58
+ return Qnil;
59
+ }
60
+
61
+
62
+ static VALUE
63
+ rb_capng_state_save(VALUE self)
64
+ {
65
+ struct CapNGState* capng_state;
66
+ void *state = NULL;
67
+
68
+ TypedData_Get_Struct(self, struct CapNGState, &rb_capng_state_type, capng_state);
69
+
70
+ state = capng_save_state();
71
+ capng_state->state = state;
72
+
73
+ return Qnil;
74
+ }
75
+
76
+ static VALUE
77
+ rb_capng_state_restore(VALUE self)
78
+ {
79
+ struct CapNGState* capng_state;
80
+ void *state = NULL;
81
+
82
+ TypedData_Get_Struct(self, struct CapNGState, &rb_capng_state_type, capng_state);
83
+
84
+ state = capng_state->state;
85
+ capng_restore_state(&state);
86
+
87
+ return Qnil;
88
+ }
89
+
90
+ void
91
+ Init_capng_state(VALUE rb_cCapNG)
92
+ {
93
+ rb_cState = rb_define_class_under(rb_cCapNG, "State", rb_cObject);
94
+
95
+ rb_define_alloc_func(rb_cState, rb_capng_state_alloc);
96
+
97
+ rb_define_method(rb_cState, "initialize", rb_capng_state_initialize, 0);
98
+ rb_define_method(rb_cState, "save", rb_capng_state_save, 0);
99
+ rb_define_method(rb_cState, "restore", rb_capng_state_restore, 0);
100
+ }
@@ -0,0 +1,33 @@
1
+ require "capng/capng"
2
+ require "capng/version"
3
+
4
+ class CapNG
5
+ class Error < StandardError; end
6
+
7
+ alias_method :caps_file_raw, :caps_file
8
+ alias_method :apply_caps_file_raw, :apply_caps_file
9
+
10
+ def caps_file(file_or_string_path)
11
+ if file_or_string_path.is_a?(String) && File.exist?(file_or_string_path)
12
+ File.open(file_or_string_path) do |f|
13
+ caps_file_raw(f)
14
+ end
15
+ elsif file_or_string_path.is_a?(File)
16
+ caps_file_raw(file_or_string_path)
17
+ else
18
+ raise ArgumentError, "#{file_or_string_path} should be File class or String class instance."
19
+ end
20
+ end
21
+
22
+ def apply_caps_file(file_or_string_path)
23
+ if file_or_string_path.is_a?(String) && File.exist?(file_or_string_path)
24
+ File.open(file_or_string_path) do |f|
25
+ apply_cps_file_raw(f)
26
+ end
27
+ elsif file_or_string_path.is_a?(File)
28
+ apply_caps_file_raw(file_or_string_path)
29
+ else
30
+ raise ArgumentError, "#{file_or_string_path} should be File class or String class instance."
31
+ end
32
+ end
33
+ end
@@ -0,0 +1,3 @@
1
+ class CapNG
2
+ VERSION = "0.1.0"
3
+ end
metadata ADDED
@@ -0,0 +1,125 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: capng_c
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Hiroshi Hatake
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2020-10-26 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '1.16'
20
+ - - "<"
21
+ - !ruby/object:Gem::Version
22
+ version: '3'
23
+ type: :development
24
+ prerelease: false
25
+ version_requirements: !ruby/object:Gem::Requirement
26
+ requirements:
27
+ - - ">="
28
+ - !ruby/object:Gem::Version
29
+ version: '1.16'
30
+ - - "<"
31
+ - !ruby/object:Gem::Version
32
+ version: '3'
33
+ - !ruby/object:Gem::Dependency
34
+ name: rake
35
+ requirement: !ruby/object:Gem::Requirement
36
+ requirements:
37
+ - - "~>"
38
+ - !ruby/object:Gem::Version
39
+ version: '12.0'
40
+ type: :development
41
+ prerelease: false
42
+ version_requirements: !ruby/object:Gem::Requirement
43
+ requirements:
44
+ - - "~>"
45
+ - !ruby/object:Gem::Version
46
+ version: '12.0'
47
+ - !ruby/object:Gem::Dependency
48
+ name: rake-compiler
49
+ requirement: !ruby/object:Gem::Requirement
50
+ requirements:
51
+ - - "~>"
52
+ - !ruby/object:Gem::Version
53
+ version: '1.0'
54
+ type: :development
55
+ prerelease: false
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ requirements:
58
+ - - "~>"
59
+ - !ruby/object:Gem::Version
60
+ version: '1.0'
61
+ - !ruby/object:Gem::Dependency
62
+ name: test-unit
63
+ requirement: !ruby/object:Gem::Requirement
64
+ requirements:
65
+ - - "~>"
66
+ - !ruby/object:Gem::Version
67
+ version: 3.3.3
68
+ type: :development
69
+ prerelease: false
70
+ version_requirements: !ruby/object:Gem::Requirement
71
+ requirements:
72
+ - - "~>"
73
+ - !ruby/object:Gem::Version
74
+ version: 3.3.3
75
+ description: libcap-ng bindings for Ruby.
76
+ email:
77
+ - cosmo0920.wp@gmail.com
78
+ executables: []
79
+ extensions:
80
+ - ext/capng/extconf.rb
81
+ extra_rdoc_files: []
82
+ files:
83
+ - ".gitignore"
84
+ - Gemfile
85
+ - LICENSE
86
+ - README.md
87
+ - Rakefile
88
+ - bin/console
89
+ - bin/setup
90
+ - capng_c.gemspec
91
+ - ext/capng/capability.c
92
+ - ext/capng/capng.c
93
+ - ext/capng/capng.h
94
+ - ext/capng/enum.c
95
+ - ext/capng/extconf.rb
96
+ - ext/capng/print.c
97
+ - ext/capng/state.c
98
+ - lib/capng.rb
99
+ - lib/capng/version.rb
100
+ homepage: https://github.com/cosmo0920/cap-ng_c
101
+ licenses: []
102
+ metadata:
103
+ allowed_push_host: https://rubygems.org
104
+ homepage_uri: https://github.com/cosmo0920/cap-ng_c
105
+ source_code_uri: https://github.com/cosmo0920/cap-ng_c
106
+ post_install_message:
107
+ rdoc_options: []
108
+ require_paths:
109
+ - lib
110
+ required_ruby_version: !ruby/object:Gem::Requirement
111
+ requirements:
112
+ - - ">="
113
+ - !ruby/object:Gem::Version
114
+ version: '2.4'
115
+ required_rubygems_version: !ruby/object:Gem::Requirement
116
+ requirements:
117
+ - - ">="
118
+ - !ruby/object:Gem::Version
119
+ version: '0'
120
+ requirements: []
121
+ rubygems_version: 3.0.3
122
+ signing_key:
123
+ specification_version: 4
124
+ summary: libcap-ng bindings for Ruby.
125
+ test_files: []