capng_c 0.1.5 → 0.2.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- 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
data/ext/capng/capng.h
CHANGED
@@ -19,29 +19,45 @@
|
|
19
19
|
#include <ruby/io.h>
|
20
20
|
|
21
21
|
#include <cap-ng.h>
|
22
|
+
#include <fcntl.h>
|
22
23
|
#include <stdio.h>
|
23
|
-
#include <sys/types.h>
|
24
24
|
#include <sys/stat.h>
|
25
|
-
#include <
|
25
|
+
#include <sys/types.h>
|
26
|
+
|
27
|
+
extern VALUE rb_cCapNG;
|
28
|
+
extern VALUE rb_cCapNGPrint;
|
29
|
+
extern VALUE rb_cCapability;
|
30
|
+
extern VALUE rb_cState;
|
31
|
+
extern VALUE rb_mAction;
|
32
|
+
extern VALUE rb_mSelect;
|
33
|
+
extern VALUE rb_mType;
|
34
|
+
extern VALUE rb_mResult;
|
35
|
+
extern VALUE rb_mPrint;
|
36
|
+
extern VALUE rb_mFlags;
|
37
|
+
|
38
|
+
capng_select_t
|
39
|
+
select_name_to_select_type(char* select_name);
|
40
|
+
capng_act_t
|
41
|
+
action_name_to_action_type(char* action_name);
|
42
|
+
capng_print_t
|
43
|
+
print_name_to_print_type(char* print_name);
|
44
|
+
capng_type_t
|
45
|
+
capability_type_name_to_capability_type(char* capability_name);
|
46
|
+
|
47
|
+
typedef struct {
|
48
|
+
int code;
|
49
|
+
const char* name;
|
50
|
+
} CapabilityInfo;
|
26
51
|
|
27
|
-
|
28
|
-
VALUE rb_cCapNGPrint;
|
29
|
-
VALUE rb_cCapability;
|
30
|
-
VALUE rb_cState;
|
31
|
-
VALUE rb_mAction;
|
32
|
-
VALUE rb_mSelect;
|
33
|
-
VALUE rb_mType;
|
34
|
-
VALUE rb_mResult;
|
35
|
-
VALUE rb_mPrint;
|
36
|
-
VALUE rb_mFlags;
|
37
|
-
|
38
|
-
capng_select_t select_name_to_select_type(char *select_name);
|
39
|
-
capng_act_t action_name_to_action_type(char *action_name);
|
40
|
-
capng_print_t print_name_to_print_type(char *print_name);
|
41
|
-
capng_type_t capability_type_name_to_capability_type(char *capability_name);
|
52
|
+
extern CapabilityInfo capabilityInfoTable[];
|
42
53
|
|
43
54
|
void Init_capng_capability(VALUE);
|
44
55
|
void Init_capng_enum(VALUE);
|
56
|
+
void Init_capng_enum_action(VALUE);
|
57
|
+
void Init_capng_enum_flags(VALUE);
|
58
|
+
void Init_capng_enum_result(VALUE);
|
59
|
+
void Init_capng_enum_select(VALUE);
|
60
|
+
void Init_capng_enum_type(VALUE);
|
45
61
|
void Init_capng_print(VALUE);
|
46
62
|
void Init_capng_state(VALUE);
|
47
63
|
#endif // _CAPNG_H
|
@@ -0,0 +1,35 @@
|
|
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
|
+
/* clang-format off */
|
15
|
+
/*
|
16
|
+
* Document-module: CapNG::Action
|
17
|
+
*
|
18
|
+
* Define ADD or Drop constants.
|
19
|
+
*
|
20
|
+
*/
|
21
|
+
/* clang-format on */
|
22
|
+
|
23
|
+
#include <capng.h>
|
24
|
+
|
25
|
+
void
|
26
|
+
Init_capng_enum_action(VALUE rb_cCapNG)
|
27
|
+
{
|
28
|
+
VALUE rb_mAction = rb_define_module_under(rb_cCapNG, "Action");
|
29
|
+
|
30
|
+
// capng_cat_t enum constants
|
31
|
+
/* Mark as DROP action */
|
32
|
+
rb_define_const(rb_mAction, "DROP", INT2NUM(CAPNG_DROP));
|
33
|
+
/* Mark as ADD action */
|
34
|
+
rb_define_const(rb_mAction, "ADD", INT2NUM(CAPNG_ADD));
|
35
|
+
}
|
@@ -0,0 +1,44 @@
|
|
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
|
+
/* clang-format off */
|
15
|
+
/*
|
16
|
+
* Document-module: CapNG::Flags
|
17
|
+
*
|
18
|
+
* Define NO_FLAGS, DROP_SUPP_GRP, CLEAR_BOUNDING, and INIT_SUPP_GRP (if available) constants.
|
19
|
+
*/
|
20
|
+
/* clang-format on */
|
21
|
+
|
22
|
+
#include <capng.h>
|
23
|
+
|
24
|
+
void
|
25
|
+
Init_capng_enum_flags(VALUE rb_cCapNG)
|
26
|
+
{
|
27
|
+
VALUE rb_mFlags = rb_define_module_under(rb_cCapNG, "Flags");
|
28
|
+
|
29
|
+
// capng_flags_t enum constants
|
30
|
+
/* Simply change uid and retain specified capabilities and that's
|
31
|
+
* all. */
|
32
|
+
rb_define_const(rb_mFlags, "NO_FLAG", LONG2NUM(CAPNG_NO_FLAG));
|
33
|
+
/* it will have no effect. */
|
34
|
+
rb_define_const(rb_mFlags, "DROP_SUPP_GRP", LONG2NUM(CAPNG_DROP_SUPP_GRP));
|
35
|
+
/* Clear the bounding set regardless to the internal representation
|
36
|
+
* already setup prior to changing the uid/gid.*/
|
37
|
+
rb_define_const(rb_mFlags, "CLEAR_BOUNDING", LONG2NUM(CAPNG_CLEAR_BOUNDING));
|
38
|
+
#if defined(HAVE_CONST_CAPNG_INIT_SUPP_GRP)
|
39
|
+
/* After changing id, initialize any supplement groups that may come with the new
|
40
|
+
* account. If given with Note: Ubuntu Trusty's libcap-ng-dev doesn't have
|
41
|
+
* CAPNG_INIT_SUPP_GRP constant. */
|
42
|
+
rb_define_const(rb_mFlags, "INIT_SUPP_GRP", LONG2NUM(CAPNG_INIT_SUPP_GRP));
|
43
|
+
#endif
|
44
|
+
}
|
@@ -0,0 +1,38 @@
|
|
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
|
+
/* clang-format off */
|
15
|
+
/*
|
16
|
+
* Document-module: CapNG::Result
|
17
|
+
*
|
18
|
+
* Define FAIL, NONE, PARTAIL, and FULL constants.
|
19
|
+
*/
|
20
|
+
/* clang-format on */
|
21
|
+
|
22
|
+
#include <capng.h>
|
23
|
+
|
24
|
+
void
|
25
|
+
Init_capng_enum_result(VALUE rb_cCapNG)
|
26
|
+
{
|
27
|
+
VALUE rb_mResult = rb_define_module_under(rb_cCapNG, "Result");
|
28
|
+
|
29
|
+
// capng_result_t enum constants
|
30
|
+
/* Fail to retrieve result */
|
31
|
+
rb_define_const(rb_mResult, "FAIL", LONG2NUM(CAPNG_FAIL));
|
32
|
+
/* Retrieve no result */
|
33
|
+
rb_define_const(rb_mResult, "NONE", LONG2NUM(CAPNG_NONE));
|
34
|
+
/* Retrieve partial result. Some capabilities are set up. */
|
35
|
+
rb_define_const(rb_mResult, "PARTIAL", LONG2NUM(CAPNG_PARTIAL));
|
36
|
+
/* Retrieve partial result. Full capabilities are set up. */
|
37
|
+
rb_define_const(rb_mResult, "FULL", LONG2NUM(CAPNG_FULL));
|
38
|
+
}
|
@@ -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
|
+
/* clang-format off */
|
15
|
+
/*
|
16
|
+
* Document-module: CapNG::Select
|
17
|
+
*
|
18
|
+
* Define CAPS, BOUNDS, BOTH, and AMBIENT (if available) constants.
|
19
|
+
*/
|
20
|
+
/* clang-format on */
|
21
|
+
|
22
|
+
#include <capng.h>
|
23
|
+
|
24
|
+
void
|
25
|
+
Init_capng_enum_select(VALUE rb_cCapNG)
|
26
|
+
{
|
27
|
+
VALUE rb_mSelect = rb_define_module_under(rb_cCapNG, "Select");
|
28
|
+
|
29
|
+
// capng_select_t enum constants
|
30
|
+
rb_define_const(rb_mSelect, "CAPS", INT2NUM(CAPNG_SELECT_CAPS));
|
31
|
+
rb_define_const(rb_mSelect, "BOUNDS", INT2NUM(CAPNG_SELECT_BOUNDS));
|
32
|
+
rb_define_const(rb_mSelect, "BOTH", INT2NUM(CAPNG_SELECT_BOTH));
|
33
|
+
#if defined(HAVE_CONST_CAPNG_SELECT_AMBIENT)
|
34
|
+
rb_define_const(rb_mSelect, "AMBIENT", INT2NUM(CAPNG_SELECT_AMBIENT));
|
35
|
+
#endif
|
36
|
+
#if defined(HAVE_CONST_CAPNG_SELECT_ALL)
|
37
|
+
rb_define_const(rb_mSelect, "ALL", INT2NUM(CAPNG_SELECT_ALL));
|
38
|
+
#endif
|
39
|
+
}
|
@@ -0,0 +1,42 @@
|
|
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
|
+
/* clang-format off */
|
15
|
+
/*
|
16
|
+
* Document-module: CapNG::Type
|
17
|
+
*
|
18
|
+
* Define EFFECTIVE, PERMITTED, INHERITABLE, BOUNDING_SET and AMBIENT (if available) constants.
|
19
|
+
*/
|
20
|
+
/* clang-format on */
|
21
|
+
|
22
|
+
#include <capng.h>
|
23
|
+
|
24
|
+
void
|
25
|
+
Init_capng_enum_type(VALUE rb_cCapNG)
|
26
|
+
{
|
27
|
+
VALUE rb_mType = rb_define_module_under(rb_cCapNG, "Type");
|
28
|
+
|
29
|
+
// capng_type_t enum constants
|
30
|
+
/* Effective type */
|
31
|
+
rb_define_const(rb_mType, "EFFECTIVE", INT2NUM(CAPNG_EFFECTIVE));
|
32
|
+
/* Permitted type */
|
33
|
+
rb_define_const(rb_mType, "PERMITTED", INT2NUM(CAPNG_PERMITTED));
|
34
|
+
/* Inheritable type */
|
35
|
+
rb_define_const(rb_mType, "INHERITABLE", INT2NUM(CAPNG_INHERITABLE));
|
36
|
+
/* Bounding Set type */
|
37
|
+
rb_define_const(rb_mType, "BOUNDING_SET", INT2NUM(CAPNG_BOUNDING_SET));
|
38
|
+
#if defined(HAVE_CONST_CAPNG_AMBIENT)
|
39
|
+
/* Ambient type */
|
40
|
+
rb_define_const(rb_mType, "AMBIENT", INT2NUM(CAPNG_AMBIENT));
|
41
|
+
#endif
|
42
|
+
}
|
data/ext/capng/enum.c
CHANGED
@@ -13,50 +13,12 @@
|
|
13
13
|
|
14
14
|
#include <capng.h>
|
15
15
|
|
16
|
-
void
|
16
|
+
void
|
17
|
+
Init_capng_enum(VALUE rb_cCapNG)
|
17
18
|
{
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
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
|
-
#if defined(CAPNG_INIT_SUPP_GRP)
|
59
|
-
// Ubuntu Trusty's libcap-ng-dev doesn't have CAPNG_INIT_SUPP_GRP constant.
|
60
|
-
rb_define_const(rb_mFlags, "INIT_SUPP_GRP", LONG2NUM(CAPNG_INIT_SUPP_GRP));
|
61
|
-
#endif
|
19
|
+
Init_capng_enum_action(rb_cCapNG);
|
20
|
+
Init_capng_enum_flags(rb_cCapNG);
|
21
|
+
Init_capng_enum_result(rb_cCapNG);
|
22
|
+
Init_capng_enum_select(rb_cCapNG);
|
23
|
+
Init_capng_enum_type(rb_cCapNG);
|
62
24
|
}
|
data/ext/capng/extconf.rb
CHANGED
@@ -24,6 +24,10 @@ pkg_config("libcap-ng")
|
|
24
24
|
$CFLAGS << " -Wall -std=c99 -fPIC "
|
25
25
|
# $CFLAGS << " -g -O0"
|
26
26
|
|
27
|
+
have_const("CAPNG_SELECT_AMBIENT", "cap-ng.h")
|
28
|
+
have_const("CAPNG_SELECT_ALL", "cap-ng.h")
|
29
|
+
have_const("CAPNG_AMBIENT", "cap-ng.h")
|
30
|
+
have_const("CAPNG_INIT_SUPP_GRP", "cap-ng.h")
|
27
31
|
have_func("rb_sym2str", "ruby.h")
|
28
32
|
have_func("capng_get_caps_fd", "cap-ng.h")
|
29
33
|
create_makefile("capng/capng")
|
data/ext/capng/print.c
CHANGED
@@ -11,23 +11,37 @@
|
|
11
11
|
/* See the License for the specific language governing permissions and */
|
12
12
|
/* limitations under the License. */
|
13
13
|
|
14
|
-
|
14
|
+
/* clang-format off */
|
15
|
+
/*
|
16
|
+
* Document-class: CapNG::Print
|
17
|
+
*
|
18
|
+
* Print Linux capabitlities.
|
19
|
+
*
|
20
|
+
* @example
|
21
|
+
* require 'capng'
|
22
|
+
*
|
23
|
+
* @print = CapNG::Print.new
|
24
|
+
* @print.caps_text(:buffer, :effective)
|
25
|
+
*/
|
26
|
+
/* clang-format on */
|
15
27
|
|
16
|
-
|
28
|
+
#include <capng.h>
|
17
29
|
|
18
|
-
|
30
|
+
struct CapNGPrint
|
31
|
+
{};
|
19
32
|
|
20
|
-
static
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
33
|
+
static void
|
34
|
+
capng_print_free(void* capng);
|
35
|
+
|
36
|
+
static const rb_data_type_t rb_capng_print_type = { "capng/print",
|
37
|
+
{
|
38
|
+
0,
|
39
|
+
capng_print_free,
|
40
|
+
0,
|
41
|
+
},
|
42
|
+
NULL,
|
43
|
+
NULL,
|
44
|
+
RUBY_TYPED_FREE_IMMEDIATELY };
|
31
45
|
|
32
46
|
static void
|
33
47
|
capng_print_free(void* ptr)
|
@@ -40,58 +54,79 @@ rb_capng_print_alloc(VALUE klass)
|
|
40
54
|
{
|
41
55
|
VALUE obj;
|
42
56
|
struct CapNGPrint* capng_print;
|
43
|
-
obj =
|
44
|
-
klass, struct CapNGPrint, &rb_capng_print_type, capng_print);
|
57
|
+
obj =
|
58
|
+
TypedData_Make_Struct(klass, struct CapNGPrint, &rb_capng_print_type, capng_print);
|
45
59
|
return obj;
|
46
60
|
}
|
47
61
|
|
62
|
+
/*
|
63
|
+
* Initalize Print class.
|
64
|
+
*
|
65
|
+
* @return [nil]
|
66
|
+
*
|
67
|
+
*/
|
48
68
|
static VALUE
|
49
69
|
rb_capng_print_initialize(VALUE self)
|
50
70
|
{
|
51
71
|
return Qnil;
|
52
72
|
}
|
53
73
|
|
74
|
+
/*
|
75
|
+
* Print capability as text.
|
76
|
+
*
|
77
|
+
* @param rb_where_name_or_type [String or Symbol or Fixnum] Print target.
|
78
|
+
* @param rb_capability_name_or_type [String or Symbol or Fixnum] Capability name or
|
79
|
+
* constants
|
80
|
+
* @return [Integer]
|
81
|
+
*
|
82
|
+
*/
|
54
83
|
static VALUE
|
55
|
-
rb_capng_print_caps_text(VALUE self, VALUE rb_where_name_or_type,
|
84
|
+
rb_capng_print_caps_text(VALUE self, VALUE rb_where_name_or_type,
|
85
|
+
VALUE rb_capability_name_or_type)
|
56
86
|
{
|
57
|
-
char
|
87
|
+
char* result = NULL;
|
58
88
|
capng_type_t capability_type = 0;
|
59
89
|
capng_print_t print_type = 0;
|
60
90
|
|
61
91
|
switch (TYPE(rb_capability_name_or_type)) {
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
92
|
+
case T_SYMBOL:
|
93
|
+
capability_type = capability_type_name_to_capability_type(
|
94
|
+
RSTRING_PTR(rb_sym2str(rb_capability_name_or_type)));
|
95
|
+
break;
|
96
|
+
case T_STRING:
|
97
|
+
capability_type = capability_type_name_to_capability_type(
|
98
|
+
StringValuePtr(rb_capability_name_or_type));
|
99
|
+
break;
|
100
|
+
case T_FIXNUM:
|
101
|
+
capability_type = NUM2INT(rb_capability_name_or_type);
|
102
|
+
break;
|
103
|
+
default:
|
104
|
+
rb_raise(rb_eArgError,
|
105
|
+
"Expected a String or a Symbol instance, or a capability type constant");
|
73
106
|
}
|
74
107
|
|
75
108
|
switch (TYPE(rb_where_name_or_type)) {
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
109
|
+
case T_SYMBOL:
|
110
|
+
print_type =
|
111
|
+
print_name_to_print_type(RSTRING_PTR(rb_sym2str(rb_where_name_or_type)));
|
112
|
+
break;
|
113
|
+
case T_STRING:
|
114
|
+
print_type = print_name_to_print_type(StringValuePtr(rb_where_name_or_type));
|
115
|
+
break;
|
116
|
+
case T_FIXNUM:
|
117
|
+
print_type = NUM2INT(rb_where_name_or_type);
|
118
|
+
break;
|
119
|
+
default:
|
120
|
+
rb_raise(rb_eArgError,
|
121
|
+
"Expected a String or a Symbol instance, or a print type constant");
|
87
122
|
}
|
88
123
|
|
89
124
|
switch (print_type) {
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
125
|
+
case CAPNG_PRINT_STDOUT:
|
126
|
+
capng_print_caps_text(CAPNG_PRINT_STDOUT, capability_type);
|
127
|
+
break;
|
128
|
+
case CAPNG_PRINT_BUFFER:
|
129
|
+
result = capng_print_caps_text(CAPNG_PRINT_BUFFER, capability_type);
|
95
130
|
}
|
96
131
|
|
97
132
|
if (result)
|
@@ -100,47 +135,60 @@ rb_capng_print_caps_text(VALUE self, VALUE rb_where_name_or_type, VALUE rb_capab
|
|
100
135
|
return rb_str_new2("none");
|
101
136
|
}
|
102
137
|
|
138
|
+
/*
|
139
|
+
* Print capability as numeric.
|
140
|
+
*
|
141
|
+
* @param rb_where_name_or_type [String or Symbol or Fixnum] Print target.
|
142
|
+
* @param rb_select_name_or_enum [String or Symbol or Fixnum] Select set name or constants
|
143
|
+
* @return [Integer]
|
144
|
+
*
|
145
|
+
*/
|
103
146
|
static VALUE
|
104
|
-
rb_capng_print_caps_numeric(VALUE self, VALUE rb_where_name_or_type,
|
147
|
+
rb_capng_print_caps_numeric(VALUE self, VALUE rb_where_name_or_type,
|
148
|
+
VALUE rb_select_name_or_enum)
|
105
149
|
{
|
106
|
-
char
|
150
|
+
char* result = NULL;
|
107
151
|
capng_select_t select = 0;
|
108
152
|
capng_print_t print_type = 0;
|
109
153
|
|
110
154
|
switch (TYPE(rb_where_name_or_type)) {
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
155
|
+
case T_SYMBOL:
|
156
|
+
print_type =
|
157
|
+
print_name_to_print_type(RSTRING_PTR(rb_sym2str(rb_where_name_or_type)));
|
158
|
+
break;
|
159
|
+
case T_STRING:
|
160
|
+
print_type = print_name_to_print_type(StringValuePtr(rb_where_name_or_type));
|
161
|
+
break;
|
162
|
+
case T_FIXNUM:
|
163
|
+
print_type = NUM2INT(rb_where_name_or_type);
|
164
|
+
break;
|
165
|
+
default:
|
166
|
+
rb_raise(rb_eArgError,
|
167
|
+
"Expected a String or a Symbol instance, or a print type constant");
|
122
168
|
}
|
123
169
|
|
124
170
|
switch (TYPE(rb_select_name_or_enum)) {
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
171
|
+
case T_SYMBOL:
|
172
|
+
select =
|
173
|
+
select_name_to_select_type(RSTRING_PTR(rb_sym2str(rb_select_name_or_enum)));
|
174
|
+
break;
|
175
|
+
case T_STRING:
|
176
|
+
select = select_name_to_select_type(StringValuePtr(rb_select_name_or_enum));
|
177
|
+
break;
|
178
|
+
case T_FIXNUM:
|
179
|
+
select = NUM2INT(rb_select_name_or_enum);
|
180
|
+
break;
|
181
|
+
default:
|
182
|
+
rb_raise(rb_eArgError,
|
183
|
+
"Expected a String or a Symbol instance, or a capability type constant");
|
136
184
|
}
|
137
185
|
|
138
186
|
switch (print_type) {
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
187
|
+
case CAPNG_PRINT_STDOUT:
|
188
|
+
capng_print_caps_numeric(CAPNG_PRINT_STDOUT, select);
|
189
|
+
break;
|
190
|
+
case CAPNG_PRINT_BUFFER:
|
191
|
+
result = capng_print_caps_numeric(CAPNG_PRINT_BUFFER, select);
|
144
192
|
}
|
145
193
|
|
146
194
|
if (result)
|
@@ -149,9 +197,10 @@ rb_capng_print_caps_numeric(VALUE self, VALUE rb_where_name_or_type, VALUE rb_se
|
|
149
197
|
return rb_str_new2("none");
|
150
198
|
}
|
151
199
|
|
152
|
-
void
|
200
|
+
void
|
201
|
+
Init_capng_print(VALUE rb_cCapNG)
|
153
202
|
{
|
154
|
-
rb_cCapNGPrint = rb_define_class_under(rb_cCapNG, "Print", rb_cObject);
|
203
|
+
VALUE rb_cCapNGPrint = rb_define_class_under(rb_cCapNG, "Print", rb_cObject);
|
155
204
|
|
156
205
|
rb_define_alloc_func(rb_cCapNGPrint, rb_capng_print_alloc);
|
157
206
|
|
@@ -160,6 +209,8 @@ void Init_capng_print(VALUE rb_cCapNG)
|
|
160
209
|
rb_define_method(rb_cCapNGPrint, "caps_numeric", rb_capng_print_caps_numeric, 2);
|
161
210
|
|
162
211
|
// capng_print_t enum constants
|
212
|
+
/* Print target into STDOUT. */
|
163
213
|
rb_define_const(rb_cCapNGPrint, "STDOUT", LONG2NUM(CAPNG_PRINT_STDOUT));
|
214
|
+
/* Print target into buffer varible. */
|
164
215
|
rb_define_const(rb_cCapNGPrint, "BUFFER", LONG2NUM(CAPNG_PRINT_BUFFER));
|
165
216
|
}
|