capng_c 0.1.6 → 0.1.7

Sign up to get free protection for your applications and to get access to all the features.
@@ -19,10 +19,10 @@
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 <fcntl.h>
25
+ #include <sys/types.h>
26
26
 
27
27
  extern VALUE rb_cCapNG;
28
28
  extern VALUE rb_cCapNGPrint;
@@ -35,13 +35,22 @@ extern VALUE rb_mResult;
35
35
  extern VALUE rb_mPrint;
36
36
  extern VALUE rb_mFlags;
37
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);
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);
42
46
 
43
47
  void Init_capng_capability(VALUE);
44
48
  void Init_capng_enum(VALUE);
49
+ void Init_capng_enum_action(VALUE);
50
+ void Init_capng_enum_flags(VALUE);
51
+ void Init_capng_enum_result(VALUE);
52
+ void Init_capng_enum_select(VALUE);
53
+ void Init_capng_enum_type(VALUE);
45
54
  void Init_capng_print(VALUE);
46
55
  void Init_capng_state(VALUE);
47
56
  #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
+ }
@@ -13,50 +13,12 @@
13
13
 
14
14
  #include <capng.h>
15
15
 
16
- void Init_capng_enum(VALUE rb_cCapNG)
16
+ void
17
+ Init_capng_enum(VALUE rb_cCapNG)
17
18
  {
18
- VALUE rb_mAction = rb_define_module_under(rb_cCapNG, "Action");
19
- VALUE rb_mSelect = rb_define_module_under(rb_cCapNG, "Select");
20
- VALUE rb_mType = rb_define_module_under(rb_cCapNG, "Type");
21
- VALUE rb_mResult = rb_define_module_under(rb_cCapNG, "Result");
22
- VALUE 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(HAVE_CONST_CAPNG_SELECT_AMBIENT)
33
- rb_define_const(rb_mSelect, "AMBIENT", INT2NUM(CAPNG_SELECT_AMBIENT));
34
- #endif
35
- #if defined(HAVE_CONST_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(HAVE_CONST_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(HAVE_CONST_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
  }
@@ -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
- #include <capng.h>
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
- struct CapNGPrint {};
28
+ #include <capng.h>
17
29
 
18
- static void capng_print_free(void* capng);
30
+ struct CapNGPrint
31
+ {};
19
32
 
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
- };
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 = TypedData_Make_Struct(
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, VALUE rb_capability_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 *result = NULL;
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
- case T_SYMBOL:
63
- capability_type = capability_type_name_to_capability_type(RSTRING_PTR(rb_sym2str(rb_capability_name_or_type)));
64
- break;
65
- case T_STRING:
66
- capability_type = capability_type_name_to_capability_type(StringValuePtr(rb_capability_name_or_type));
67
- break;
68
- case T_FIXNUM:
69
- capability_type = NUM2INT(rb_capability_name_or_type);
70
- break;
71
- default:
72
- rb_raise(rb_eArgError, "Expected a String or a Symbol instance, or a capability type constant");
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
- case T_SYMBOL:
77
- print_type = print_name_to_print_type(RSTRING_PTR(rb_sym2str(rb_where_name_or_type)));
78
- break;
79
- case T_STRING:
80
- print_type = print_name_to_print_type(StringValuePtr(rb_where_name_or_type));
81
- break;
82
- case T_FIXNUM:
83
- print_type = NUM2INT(rb_where_name_or_type);
84
- break;
85
- default:
86
- rb_raise(rb_eArgError, "Expected a String or a Symbol instance, or a print type constant");
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
- case CAPNG_PRINT_STDOUT:
91
- capng_print_caps_text(CAPNG_PRINT_STDOUT, capability_type);
92
- break;
93
- case CAPNG_PRINT_BUFFER:
94
- result = capng_print_caps_text(CAPNG_PRINT_BUFFER, capability_type);
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, VALUE rb_select_name_or_enum)
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 *result = NULL;
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
- case T_SYMBOL:
112
- print_type = print_name_to_print_type(RSTRING_PTR(rb_sym2str(rb_where_name_or_type)));
113
- break;
114
- case T_STRING:
115
- print_type = print_name_to_print_type(StringValuePtr(rb_where_name_or_type));
116
- break;
117
- case T_FIXNUM:
118
- print_type = NUM2INT(rb_where_name_or_type);
119
- break;
120
- default:
121
- rb_raise(rb_eArgError, "Expected a String or a Symbol instance, or a print type constant");
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
- case T_SYMBOL:
126
- select = select_name_to_select_type(RSTRING_PTR(rb_sym2str(rb_select_name_or_enum)));
127
- break;
128
- case T_STRING:
129
- select = select_name_to_select_type(StringValuePtr(rb_select_name_or_enum));
130
- break;
131
- case T_FIXNUM:
132
- select = NUM2INT(rb_select_name_or_enum);
133
- break;
134
- default:
135
- rb_raise(rb_eArgError, "Expected a String or a Symbol instance, or a capability type constant");
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
- case CAPNG_PRINT_STDOUT:
140
- capng_print_caps_numeric(CAPNG_PRINT_STDOUT, select);
141
- break;
142
- case CAPNG_PRINT_BUFFER:
143
- result = capng_print_caps_numeric(CAPNG_PRINT_BUFFER, select);
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,7 +197,8 @@ 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 Init_capng_print(VALUE rb_cCapNG)
200
+ void
201
+ Init_capng_print(VALUE rb_cCapNG)
153
202
  {
154
203
  VALUE rb_cCapNGPrint = rb_define_class_under(rb_cCapNG, "Print", rb_cObject);
155
204
 
@@ -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
  }