solaris-file 0.3.5 → 0.3.6
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGES +6 -0
- data/README +24 -30
- data/Rakefile +34 -40
- data/ext/solaris/sfile.c +244 -231
- data/ext/solaris/sfile.h +68 -59
- data/solaris-file.gemspec +28 -30
- data/test/test_solaris_file.rb +273 -273
- metadata +40 -16
data/CHANGES
CHANGED
@@ -1,3 +1,9 @@
|
|
1
|
+
== 0.3.6 - 12-Dec-2010
|
2
|
+
* Fixed a warning regarding an unused variable.
|
3
|
+
* Fixed a potential bug with an internal helper function's switch statement.
|
4
|
+
* Refactored the Rakefile and the gemspec.
|
5
|
+
* Updated the installation instructions in the README.
|
6
|
+
|
1
7
|
== 0.3.5 - 28-Aug-2009
|
2
8
|
* Changed the license to Artistic 2.0.
|
3
9
|
* Added test-unit 2.x and sys-filesystem as development dependencies.
|
data/README
CHANGED
@@ -1,51 +1,45 @@
|
|
1
1
|
== Description
|
2
|
-
|
3
|
-
|
4
|
-
== Prerequisites
|
5
|
-
Ruby 1.8.x
|
2
|
+
Adds ACL support and door methods for the File class on Solaris.
|
6
3
|
|
7
4
|
== Installation
|
8
|
-
|
9
|
-
gem install solaris-file
|
10
|
-
=== Local Installation
|
11
|
-
rake install
|
5
|
+
gem install solaris-file
|
12
6
|
|
13
7
|
== Synopsis
|
14
|
-
|
8
|
+
require 'solaris/file'
|
15
9
|
|
16
|
-
|
17
|
-
|
10
|
+
file = 'some_file.txt'
|
11
|
+
acl_text = "user::rw-,user:nobody:r--,group::r--,group:sys:r--,mask:r--,other:r--"
|
18
12
|
|
19
|
-
|
20
|
-
|
13
|
+
File.trivial?(file) # => true (probably)
|
14
|
+
File.acl_write_text(acl_text)
|
21
15
|
|
22
|
-
|
23
|
-
|
24
|
-
|
16
|
+
# No longer a trivial file
|
17
|
+
File.trivial?(file) # => false
|
18
|
+
File.acl_read(file).each{ |acl| p acl }
|
25
19
|
|
26
|
-
|
27
|
-
|
28
|
-
|
20
|
+
# Door file?
|
21
|
+
File.door?("/var/run/syslog_door") # => true
|
22
|
+
File.ftype("/var/run/syslog_door") # => 'door'
|
29
23
|
|
30
24
|
== Known Bugs
|
31
|
-
|
32
|
-
|
25
|
+
None that I am aware of. Please report any bugs using the tracker on the
|
26
|
+
project page at http://www.rubyforge.org/projects/solarisutils
|
33
27
|
|
34
28
|
== Future Plans
|
35
|
-
|
36
|
-
|
29
|
+
Add acl_write methods that accept an array of ACLStruct's.
|
30
|
+
Add support for extended file attributes.
|
37
31
|
|
38
32
|
== Copyright
|
39
|
-
|
40
|
-
|
33
|
+
(C) 2005-2010 Daniel J. Berger
|
34
|
+
All Rights Reserved
|
41
35
|
|
42
36
|
== Warranty
|
43
|
-
|
44
|
-
|
45
|
-
|
37
|
+
This package is provided "as is" and without any express or
|
38
|
+
implied warranties, including, without limitation, the implied
|
39
|
+
warranties of merchantability and fitness for a particular purpose.
|
46
40
|
|
47
41
|
== License
|
48
|
-
|
42
|
+
Artistic 2.0
|
49
43
|
|
50
44
|
== Author
|
51
|
-
|
45
|
+
Daniel J. Berger
|
data/Rakefile
CHANGED
@@ -4,56 +4,50 @@ require 'rake/testtask'
|
|
4
4
|
require 'rbconfig'
|
5
5
|
include Config
|
6
6
|
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
end
|
17
|
-
end
|
7
|
+
CLEAN.include(
|
8
|
+
'**/*.gem', # Gem files
|
9
|
+
'**/*.rbc', # Rubinius
|
10
|
+
'**/*.o', # C object file
|
11
|
+
'**/*.log', # Ruby extension build log
|
12
|
+
'**/Makefile', # C Makefile
|
13
|
+
'**/conftest.dSYM', # OS X build directory
|
14
|
+
"**/*.#{CONFIG['DLEXT']}" # C shared object
|
15
|
+
)
|
18
16
|
|
19
17
|
desc "Build the solaris-file package (but don't install it)"
|
20
18
|
task :build => [:clean] do
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
end
|
28
|
-
|
29
|
-
desc "Install the solaris-file package (non-gem)"
|
30
|
-
task :install => [:build] do
|
31
|
-
Dir.chdir('ext') do
|
32
|
-
sh 'make install'
|
33
|
-
end
|
19
|
+
Dir.chdir('ext') do
|
20
|
+
ruby 'extconf.rb'
|
21
|
+
sh 'make'
|
22
|
+
Dir.mkdir('solaris') unless File.exists?('solaris')
|
23
|
+
FileUtils.cp('file.so', 'solaris')
|
24
|
+
end
|
34
25
|
end
|
35
26
|
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
end
|
42
|
-
|
43
|
-
desc "
|
44
|
-
task :
|
45
|
-
|
46
|
-
|
27
|
+
namespace :gem do
|
28
|
+
desc "Create the solaris-file gem"
|
29
|
+
task :create => [:clean] do
|
30
|
+
spec = eval(IO.read('solaris-file.gemspec'))
|
31
|
+
Gem::Builder.new(spec).build
|
32
|
+
end
|
33
|
+
|
34
|
+
desc "Install the solaris-file gem"
|
35
|
+
task :install => [:create] do
|
36
|
+
file = Dir["*.gem"].first
|
37
|
+
sh "gem install #{file}"
|
38
|
+
end
|
47
39
|
end
|
48
40
|
|
49
41
|
desc "Run the example program"
|
50
42
|
task :example => [:build] do
|
51
|
-
|
43
|
+
ruby "-Iext examples/example_solaris_file.rb"
|
52
44
|
end
|
53
45
|
|
54
46
|
Rake::TestTask.new do |t|
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
47
|
+
task :test => :build
|
48
|
+
t.libs << 'ext'
|
49
|
+
t.warning = true
|
50
|
+
t.verbose = true
|
59
51
|
end
|
52
|
+
|
53
|
+
task :default => :test
|
data/ext/solaris/sfile.c
CHANGED
@@ -15,21 +15,21 @@
|
|
15
15
|
* is a trivial file.
|
16
16
|
*/
|
17
17
|
static VALUE acl_count(VALUE klass, VALUE v_path){
|
18
|
-
|
19
|
-
|
18
|
+
int num_acls = 0;
|
19
|
+
char pathp[PATH_MAX];
|
20
20
|
|
21
|
-
|
21
|
+
SafeStringValue(v_path);
|
22
22
|
|
23
|
-
|
24
|
-
|
23
|
+
if(strlcpy(pathp, StringValuePtr(v_path), PATH_MAX) >= PATH_MAX)
|
24
|
+
rb_raise(rb_eArgError, "path length exceeds limit of: %i", PATH_MAX);
|
25
25
|
|
26
|
-
|
27
|
-
|
26
|
+
if((num_acls = acl(pathp, GETACLCNT, 0, NULL)) == -1)
|
27
|
+
rb_sys_fail(0);
|
28
28
|
|
29
|
-
|
30
|
-
|
29
|
+
if(num_acls == MIN_ACL_ENTRIES)
|
30
|
+
num_acls = 0;
|
31
31
|
|
32
|
-
|
32
|
+
return INT2FIX(num_acls);
|
33
33
|
}
|
34
34
|
|
35
35
|
/*
|
@@ -40,16 +40,16 @@ static VALUE acl_count(VALUE klass, VALUE v_path){
|
|
40
40
|
* the file is a trivial file.
|
41
41
|
*/
|
42
42
|
static VALUE acl_icount(VALUE self){
|
43
|
-
|
44
|
-
|
43
|
+
int num_acls = 0;
|
44
|
+
int fd = FIX2INT(rb_funcall(self, rb_intern("fileno"), 0, 0));
|
45
45
|
|
46
|
-
|
47
|
-
|
46
|
+
if((num_acls = facl(fd, GETACLCNT, 0, NULL)) == -1)
|
47
|
+
rb_sys_fail(0);
|
48
48
|
|
49
|
-
|
50
|
-
|
49
|
+
if(num_acls == MIN_ACL_ENTRIES)
|
50
|
+
num_acls = 0;
|
51
51
|
|
52
|
-
|
52
|
+
return INT2FIX(num_acls);
|
53
53
|
}
|
54
54
|
|
55
55
|
/*
|
@@ -65,43 +65,43 @@ static VALUE acl_icount(VALUE self){
|
|
65
65
|
* Returns nil if +file_name+ is a trivial file.
|
66
66
|
*/
|
67
67
|
static VALUE acl_read(VALUE klass, VALUE v_path){
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
68
|
+
int num_acls = 0;
|
69
|
+
char pathp[PATH_MAX];
|
70
|
+
VALUE v_array = Qnil;
|
71
|
+
int i;
|
72
72
|
|
73
|
-
|
73
|
+
SafeStringValue(v_path);
|
74
74
|
|
75
|
-
|
76
|
-
|
75
|
+
if(strlcpy(pathp, StringValuePtr(v_path), PATH_MAX) >= PATH_MAX)
|
76
|
+
rb_raise(rb_eArgError, "path length exceeds limit of: %i", PATH_MAX);
|
77
77
|
|
78
|
-
|
79
|
-
|
78
|
+
if((num_acls = acl(pathp, GETACLCNT, 0, NULL)) == -1)
|
79
|
+
rb_sys_fail(0);
|
80
80
|
|
81
|
-
|
82
|
-
|
83
|
-
|
81
|
+
if(num_acls != MIN_ACL_ENTRIES){
|
82
|
+
aclent_t* acl_buf;
|
83
|
+
v_array = rb_ary_new();
|
84
84
|
|
85
|
-
|
86
|
-
|
85
|
+
if((acl_buf = malloc(sizeof(aclent_t) * num_acls) ) == NULL)
|
86
|
+
rb_sys_fail(0);
|
87
87
|
|
88
|
-
|
89
|
-
|
88
|
+
if(acl(pathp, GETACL, num_acls, acl_buf) != num_acls)
|
89
|
+
rb_sys_fail(0);
|
90
90
|
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
91
|
+
for(i = 0; i < num_acls; i++){
|
92
|
+
rb_ary_push(v_array,
|
93
|
+
rb_struct_new(sACLStruct,
|
94
|
+
acl_type_string(acl_buf[i].a_type),
|
95
|
+
INT2FIX(acl_buf[i].a_id),
|
96
|
+
INT2FIX(acl_buf[i].a_perm)
|
97
|
+
)
|
98
|
+
);
|
99
|
+
}
|
100
100
|
|
101
|
-
|
102
|
-
|
101
|
+
free(acl_buf);
|
102
|
+
}
|
103
103
|
|
104
|
-
|
104
|
+
return v_array;
|
105
105
|
}
|
106
106
|
|
107
107
|
/*
|
@@ -117,37 +117,38 @@ static VALUE acl_read(VALUE klass, VALUE v_path){
|
|
117
117
|
* Returns nil if the file is a trivial file.
|
118
118
|
*/
|
119
119
|
static VALUE acl_iread(VALUE self){
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
120
|
+
int i;
|
121
|
+
int num_acls = 0;
|
122
|
+
int fd = FIX2INT(rb_funcall(self, rb_intern("fileno"), 0, 0));
|
123
|
+
VALUE v_array = Qnil;
|
124
|
+
|
125
|
+
if((num_acls = facl(fd, GETACLCNT, 0, NULL)) == -1)
|
126
|
+
rb_sys_fail(0);
|
127
|
+
|
128
|
+
if(num_acls != MIN_ACL_ENTRIES){
|
129
|
+
aclent_t* acl_buf;
|
130
|
+
v_array = rb_ary_new();
|
131
|
+
|
132
|
+
if((acl_buf = malloc(sizeof(aclent_t) * num_acls) ) == NULL)
|
133
|
+
rb_sys_fail(0);
|
124
134
|
|
125
|
-
|
135
|
+
if(facl(fd, GETACL, num_acls, acl_buf) != num_acls)
|
126
136
|
rb_sys_fail(0);
|
127
137
|
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
INT2FIX(acl_buf[i].a_id),
|
143
|
-
INT2FIX(acl_buf[i].a_perm)
|
144
|
-
)
|
145
|
-
);
|
146
|
-
}
|
147
|
-
|
148
|
-
free(acl_buf);
|
149
|
-
}
|
150
|
-
return v_array;
|
138
|
+
for(i = 0; i < num_acls; i++){
|
139
|
+
rb_ary_push(v_array,
|
140
|
+
rb_struct_new(sACLStruct,
|
141
|
+
acl_type_string(acl_buf[i].a_type),
|
142
|
+
INT2FIX(acl_buf[i].a_id),
|
143
|
+
INT2FIX(acl_buf[i].a_perm)
|
144
|
+
)
|
145
|
+
);
|
146
|
+
}
|
147
|
+
|
148
|
+
free(acl_buf);
|
149
|
+
}
|
150
|
+
|
151
|
+
return v_array;
|
151
152
|
}
|
152
153
|
|
153
154
|
/*
|
@@ -158,34 +159,34 @@ static VALUE acl_iread(VALUE self){
|
|
158
159
|
* is a trivial file, nil is returned.
|
159
160
|
*/
|
160
161
|
static VALUE acl_read_text(VALUE klass, VALUE v_path){
|
161
|
-
|
162
|
-
|
163
|
-
|
164
|
-
|
165
|
-
|
162
|
+
aclent_t* acl_buf;
|
163
|
+
int num_acls = 0;
|
164
|
+
char* acl_text;
|
165
|
+
char pathp[PATH_MAX];
|
166
|
+
VALUE v_text = Qnil;
|
166
167
|
|
167
|
-
|
168
|
+
SafeStringValue(v_path);
|
168
169
|
|
169
|
-
|
170
|
-
|
170
|
+
if(strlcpy(pathp, StringValuePtr(v_path), PATH_MAX) >= PATH_MAX)
|
171
|
+
rb_raise(rb_eArgError, "path length exceeds limit of: %i", PATH_MAX);
|
171
172
|
|
172
|
-
|
173
|
-
|
173
|
+
if((num_acls = acl(pathp, GETACLCNT, 0, NULL)) == -1)
|
174
|
+
rb_sys_fail(0);
|
174
175
|
|
175
|
-
|
176
|
-
|
177
|
-
|
176
|
+
if(num_acls != MIN_ACL_ENTRIES){
|
177
|
+
if((acl_buf = malloc(sizeof(aclent_t) * num_acls) ) == NULL)
|
178
|
+
rb_sys_fail(0);
|
178
179
|
|
179
|
-
|
180
|
-
|
180
|
+
if(acl(pathp, GETACL, num_acls, acl_buf) != num_acls)
|
181
|
+
rb_sys_fail(0);
|
181
182
|
|
182
|
-
|
183
|
+
acl_text = acltotext(acl_buf, num_acls);
|
183
184
|
|
184
|
-
|
185
|
-
|
186
|
-
|
185
|
+
free(acl_buf);
|
186
|
+
v_text = rb_str_new2(acl_text);
|
187
|
+
}
|
187
188
|
|
188
|
-
|
189
|
+
return v_text;
|
189
190
|
}
|
190
191
|
|
191
192
|
/*
|
@@ -199,33 +200,32 @@ static VALUE acl_read_text(VALUE klass, VALUE v_path){
|
|
199
200
|
* cases the offending entry number will be identified.
|
200
201
|
*/
|
201
202
|
static VALUE acl_write_text(VALUE klass, VALUE v_path, VALUE v_text){
|
202
|
-
|
203
|
-
|
204
|
-
|
205
|
-
|
206
|
-
int rv;
|
203
|
+
aclent_t* acl_buf;
|
204
|
+
int num_acls, which, rv;
|
205
|
+
char pathp[PATH_MAX];
|
206
|
+
char* acl_text = StringValuePtr(v_text);
|
207
207
|
|
208
|
-
|
209
|
-
|
208
|
+
SafeStringValue(v_path);
|
209
|
+
SafeStringValue(v_text);
|
210
210
|
|
211
|
-
|
212
|
-
|
211
|
+
if(strlcpy(pathp, StringValuePtr(v_path), PATH_MAX) >= PATH_MAX)
|
212
|
+
rb_raise(rb_eArgError, "path length exceeds limit of: %i", PATH_MAX);
|
213
213
|
|
214
|
-
|
215
|
-
|
214
|
+
if((acl_buf = aclfromtext(acl_text, &num_acls)) == NULL)
|
215
|
+
rb_raise(cSolarisFileError, "invalid ACL text");
|
216
216
|
|
217
|
-
|
218
|
-
|
217
|
+
rv = aclcheck(acl_buf, num_acls, &which);
|
218
|
+
do_acl_check(rv, which);
|
219
219
|
|
220
|
-
|
221
|
-
|
222
|
-
|
223
|
-
|
220
|
+
if(acl(pathp, SETACL, num_acls, acl_buf) == -1){
|
221
|
+
free(acl_text);
|
222
|
+
rb_sys_fail(0);
|
223
|
+
}
|
224
224
|
|
225
|
-
|
226
|
-
|
225
|
+
free(acl_text);
|
226
|
+
free(acl_buf);
|
227
227
|
|
228
|
-
|
228
|
+
return klass;
|
229
229
|
}
|
230
230
|
|
231
231
|
/*
|
@@ -238,15 +238,15 @@ static VALUE acl_write_text(VALUE klass, VALUE v_path, VALUE v_text){
|
|
238
238
|
* are replaced by "/".
|
239
239
|
*/
|
240
240
|
static VALUE solaris_resolvepath(VALUE klass, VALUE v_path){
|
241
|
-
|
241
|
+
char pathp[PATH_MAX];
|
242
242
|
|
243
|
-
|
244
|
-
|
243
|
+
SafeStringValue(v_path);
|
244
|
+
memset(pathp, 0, PATH_MAX);
|
245
245
|
|
246
|
-
|
247
|
-
|
246
|
+
if(resolvepath(StringValuePtr(v_path), pathp, PATH_MAX) == -1)
|
247
|
+
rb_sys_fail(0);
|
248
248
|
|
249
|
-
|
249
|
+
return rb_str_new2(pathp);
|
250
250
|
}
|
251
251
|
|
252
252
|
/*
|
@@ -260,14 +260,14 @@ static VALUE solaris_resolvepath(VALUE klass, VALUE v_path){
|
|
260
260
|
* will resolve to an absolute pathname where possible.
|
261
261
|
*/
|
262
262
|
static VALUE solaris_realpath(VALUE klass, VALUE v_path){
|
263
|
-
|
263
|
+
char pathp[PATH_MAX];
|
264
264
|
|
265
|
-
|
265
|
+
SafeStringValue(v_path);
|
266
266
|
|
267
|
-
|
268
|
-
|
267
|
+
if(realpath(StringValuePtr(v_path), pathp) == NULL)
|
268
|
+
rb_sys_fail(0);
|
269
269
|
|
270
|
-
|
270
|
+
return rb_str_new2(pathp);
|
271
271
|
}
|
272
272
|
|
273
273
|
/* Instance Methods */
|
@@ -283,29 +283,28 @@ static VALUE solaris_realpath(VALUE klass, VALUE v_path){
|
|
283
283
|
* cases the offending entry number will be identified.
|
284
284
|
*/
|
285
285
|
static VALUE acl_iwrite_text(VALUE self, VALUE v_text){
|
286
|
-
|
287
|
-
|
288
|
-
|
289
|
-
|
290
|
-
int rv;
|
286
|
+
aclent_t* acl_buf;
|
287
|
+
int num_acls, which, rv;
|
288
|
+
char* acl_text = StringValuePtr(v_text);
|
289
|
+
int fd = FIX2INT(rb_funcall(self, rb_intern("fileno"), 0, 0));
|
291
290
|
|
292
|
-
|
291
|
+
SafeStringValue(v_text);
|
293
292
|
|
294
|
-
|
295
|
-
|
293
|
+
if((acl_buf = aclfromtext(acl_text, &num_acls)) == NULL)
|
294
|
+
rb_raise(cSolarisFileError, "invalid ACL text");
|
296
295
|
|
297
|
-
|
298
|
-
|
296
|
+
rv = aclcheck(acl_buf, num_acls, &which);
|
297
|
+
do_acl_check(rv, which);
|
299
298
|
|
300
|
-
|
301
|
-
|
302
|
-
|
303
|
-
|
299
|
+
if(facl(fd, SETACL, num_acls, acl_buf) == -1){
|
300
|
+
free(acl_text);
|
301
|
+
rb_sys_fail(0);
|
302
|
+
}
|
304
303
|
|
305
|
-
|
306
|
-
|
304
|
+
free(acl_text);
|
305
|
+
free(acl_buf);
|
307
306
|
|
308
|
-
|
307
|
+
return self;
|
309
308
|
}
|
310
309
|
|
311
310
|
|
@@ -317,30 +316,30 @@ static VALUE acl_iwrite_text(VALUE self, VALUE v_text){
|
|
317
316
|
* the file is a trivial file, nil is returned.
|
318
317
|
*/
|
319
318
|
static VALUE acl_iread_text(VALUE self){
|
320
|
-
|
321
|
-
|
322
|
-
|
323
|
-
|
319
|
+
char* acl_text;
|
320
|
+
int num_acls = 0;
|
321
|
+
int fd = FIX2INT(rb_funcall(self,rb_intern("fileno"),0,0));
|
322
|
+
VALUE v_text = Qnil;
|
324
323
|
|
325
|
-
|
326
|
-
|
324
|
+
if((num_acls = facl(fd,GETACLCNT,0,NULL)) == -1)
|
325
|
+
rb_sys_fail(0);
|
327
326
|
|
328
|
-
|
329
|
-
|
327
|
+
if(num_acls != MIN_ACL_ENTRIES){
|
328
|
+
aclent_t* acl_buf;
|
330
329
|
|
331
|
-
|
332
|
-
|
330
|
+
if((acl_buf = malloc(sizeof(aclent_t) * num_acls) ) == NULL)
|
331
|
+
rb_sys_fail(0);
|
333
332
|
|
334
|
-
|
335
|
-
|
333
|
+
if(facl(fd, GETACL, num_acls, acl_buf) != num_acls)
|
334
|
+
rb_sys_fail(0);
|
336
335
|
|
337
|
-
|
336
|
+
acl_text = acltotext(acl_buf,num_acls);
|
338
337
|
|
339
|
-
|
340
|
-
|
341
|
-
|
338
|
+
free(acl_buf);
|
339
|
+
v_text = rb_str_new2(acl_text);
|
340
|
+
}
|
342
341
|
|
343
|
-
|
342
|
+
return v_text;
|
344
343
|
}
|
345
344
|
|
346
345
|
/*
|
@@ -351,22 +350,22 @@ static VALUE acl_iread_text(VALUE self){
|
|
351
350
|
* entries. Otherwise, it returns false.
|
352
351
|
*/
|
353
352
|
static VALUE acl_is_trivial(VALUE klass, VALUE v_path){
|
354
|
-
|
355
|
-
|
356
|
-
|
353
|
+
char pathp[PATH_MAX];
|
354
|
+
int num_acls = 0;
|
355
|
+
VALUE v_bool = Qfalse;
|
357
356
|
|
358
|
-
|
357
|
+
SafeStringValue(v_path);
|
359
358
|
|
360
|
-
|
361
|
-
|
359
|
+
if(strlcpy(pathp, StringValuePtr(v_path), PATH_MAX) >= PATH_MAX)
|
360
|
+
rb_raise(rb_eArgError, "path length exceeds limit of: %i", PATH_MAX);
|
362
361
|
|
363
|
-
|
364
|
-
|
362
|
+
if((num_acls = acl(pathp, GETACLCNT, 0, NULL)) == -1)
|
363
|
+
rb_sys_fail(0);
|
365
364
|
|
366
|
-
|
367
|
-
|
365
|
+
if(num_acls == MIN_ACL_ENTRIES)
|
366
|
+
v_bool = Qtrue;
|
368
367
|
|
369
|
-
|
368
|
+
return v_bool;
|
370
369
|
}
|
371
370
|
|
372
371
|
/*
|
@@ -377,17 +376,17 @@ static VALUE acl_is_trivial(VALUE klass, VALUE v_path){
|
|
377
376
|
* ACL entries. Otherwise, it returns false.
|
378
377
|
*/
|
379
378
|
static VALUE acl_itrivial(VALUE self){
|
380
|
-
|
381
|
-
|
382
|
-
|
379
|
+
int fd = FIX2INT(rb_funcall(self, rb_intern("fileno"), 0, 0));
|
380
|
+
int num_acls = 0;
|
381
|
+
VALUE v_bool = Qfalse;
|
383
382
|
|
384
|
-
|
385
|
-
|
383
|
+
if((num_acls = facl(fd, GETACLCNT, 0, NULL)) == -1)
|
384
|
+
rb_sys_fail(0);
|
386
385
|
|
387
|
-
|
388
|
-
|
386
|
+
if(num_acls == MIN_ACL_ENTRIES)
|
387
|
+
v_bool = Qtrue;
|
389
388
|
|
390
|
-
|
389
|
+
return v_bool;
|
391
390
|
}
|
392
391
|
|
393
392
|
/* File::Stat Additions */
|
@@ -399,83 +398,97 @@ static VALUE acl_itrivial(VALUE self){
|
|
399
398
|
* Returns true if +statfile+ is a door, false otherwise.
|
400
399
|
*/
|
401
400
|
static VALUE solaris_stat_is_door(VALUE self){
|
402
|
-
|
403
|
-
|
404
|
-
int mode = FIX2INT(rb_funcall(self, rb_intern("mode"), 0, 0));
|
401
|
+
VALUE v_bool = Qtrue;
|
402
|
+
int mode = FIX2INT(rb_funcall(self, rb_intern("mode"), 0, 0));
|
405
403
|
|
406
|
-
|
407
|
-
|
404
|
+
if(S_ISDOOR(mode) == 0)
|
405
|
+
v_bool = Qfalse;
|
408
406
|
|
409
|
-
|
407
|
+
return v_bool;
|
410
408
|
}
|
411
409
|
|
410
|
+
/*
|
411
|
+
* call-seq:
|
412
|
+
* statfile.ftype
|
413
|
+
*
|
414
|
+
* Returns the file type. This method is identical to the core Ruby method
|
415
|
+
* except that it returns "door" if the file is a door file.
|
416
|
+
*/
|
412
417
|
static VALUE solaris_stat_ftype(VALUE self){
|
413
|
-
|
418
|
+
int mode = FIX2INT(rb_funcall(self, rb_intern("mode"), 0, 0));
|
414
419
|
|
415
|
-
|
416
|
-
|
417
|
-
|
418
|
-
|
420
|
+
if(S_ISDOOR(mode))
|
421
|
+
return rb_str_new2("door");
|
422
|
+
else
|
423
|
+
return rb_funcall(self, rb_intern("old_ftype"), 0, 0);
|
419
424
|
}
|
420
425
|
|
421
|
-
/*
|
422
|
-
*
|
426
|
+
/*
|
427
|
+
* call-seq:
|
428
|
+
* File.door?(file)
|
423
429
|
*
|
424
430
|
* Returns true if +file+ is a door file, false otherwise.
|
425
431
|
*/
|
426
432
|
static VALUE solaris_file_is_door(VALUE klass, VALUE v_file){
|
427
|
-
|
428
|
-
|
433
|
+
VALUE v_stat = rb_funcall(rb_cStat, rb_intern("new"), 1, v_file);
|
434
|
+
return solaris_stat_is_door(v_stat);
|
429
435
|
}
|
430
436
|
|
431
|
-
/*
|
432
|
-
*
|
437
|
+
/*
|
438
|
+
* call-seq:
|
439
|
+
* File.ftype(file)
|
433
440
|
*
|
434
441
|
* The File.ftype method was modified so that 'door' is returned if the
|
435
442
|
* +file+ is a door file.
|
436
443
|
*/
|
437
444
|
static VALUE solaris_file_ftype(VALUE klass, VALUE v_file){
|
438
|
-
|
439
|
-
|
445
|
+
VALUE v_stat = rb_funcall(rb_cStat, rb_intern("new"), 1, v_file);
|
446
|
+
return solaris_stat_ftype(v_stat);
|
440
447
|
}
|
441
448
|
|
442
449
|
/*
|
443
450
|
* Adds ACL support for the File class on Solaris
|
444
451
|
*/
|
445
452
|
void Init_file(){
|
446
|
-
|
447
|
-
|
448
|
-
|
449
|
-
|
450
|
-
|
451
|
-
|
452
|
-
|
453
|
-
|
454
|
-
|
455
|
-
|
456
|
-
|
457
|
-
|
458
|
-
|
459
|
-
|
460
|
-
|
461
|
-
|
462
|
-
|
463
|
-
|
464
|
-
|
465
|
-
|
466
|
-
|
467
|
-
|
468
|
-
|
469
|
-
|
470
|
-
|
471
|
-
|
472
|
-
|
473
|
-
|
474
|
-
|
475
|
-
|
476
|
-
|
477
|
-
|
478
|
-
|
479
|
-
|
480
|
-
|
453
|
+
/* Error raised if an error occurs when reading or writing ACL properties */
|
454
|
+
cSolarisFileError = rb_define_class_under(
|
455
|
+
rb_cFile,
|
456
|
+
"SolarisError",
|
457
|
+
rb_eStandardError
|
458
|
+
);
|
459
|
+
|
460
|
+
// Singleton Methods
|
461
|
+
|
462
|
+
rb_define_singleton_method(rb_cFile, "acl_count", acl_count, 1);
|
463
|
+
rb_define_singleton_method(rb_cFile, "acl_read", acl_read, 1);
|
464
|
+
rb_define_singleton_method(rb_cFile, "acl_read_text", acl_read_text, 1);
|
465
|
+
rb_define_singleton_method(rb_cFile, "acl_write_text", acl_write_text, 2);
|
466
|
+
rb_define_singleton_method(rb_cFile, "door?", solaris_file_is_door, 1);
|
467
|
+
rb_define_singleton_method(rb_cFile, "ftype", solaris_file_ftype, 1);
|
468
|
+
rb_define_singleton_method(rb_cFile, "realpath", solaris_realpath, 1);
|
469
|
+
rb_define_singleton_method(rb_cFile, "resolvepath", solaris_resolvepath, 1);
|
470
|
+
rb_define_singleton_method(rb_cFile, "trivial?", acl_is_trivial, 1);
|
471
|
+
|
472
|
+
// File Instance Methods
|
473
|
+
|
474
|
+
rb_define_method(rb_cFile, "acl_count", acl_icount, 0);
|
475
|
+
rb_define_method(rb_cFile, "acl_read", acl_iread, 0);
|
476
|
+
rb_define_method(rb_cFile, "acl_read_text", acl_iread_text, 0);
|
477
|
+
rb_define_method(rb_cFile, "acl_write_text", acl_iwrite_text, 1);
|
478
|
+
rb_define_method(rb_cFile, "trivial?", acl_itrivial, 0);
|
479
|
+
|
480
|
+
// File::Stat Instance Methods
|
481
|
+
|
482
|
+
rb_define_alias(rb_cStat, "old_ftype", "ftype");
|
483
|
+
rb_define_method(rb_cStat, "door?", solaris_stat_is_door, 0);
|
484
|
+
rb_define_method(rb_cStat, "ftype", solaris_stat_ftype, 0);
|
485
|
+
|
486
|
+
// Structs
|
487
|
+
|
488
|
+
sACLStruct = rb_struct_define("ACLStruct",
|
489
|
+
"acl_type", "acl_id", "acl_perm", NULL
|
490
|
+
);
|
491
|
+
|
492
|
+
/* 0.3.5: The version of the solaris-file library */
|
493
|
+
rb_define_const(rb_cFile, "SOLARIS_VERSION", rb_str_new2(SOLARIS_VERSION));
|
481
494
|
}
|