libacl-ruby 0.0.1.dev
Sign up to get free protection for your applications and to get access to all the features.
- data/COPYING.txt +339 -0
- data/README.rdoc +80 -0
- data/ext/acl.cpp +217 -0
- data/ext/entry.cpp +337 -0
- data/ext/extconf.rb +23 -0
- data/ext/main.hpp +70 -0
- metadata +80 -0
data/COPYING.txt
ADDED
@@ -0,0 +1,339 @@
|
|
1
|
+
GNU GENERAL PUBLIC LICENSE
|
2
|
+
Version 2, June 1991
|
3
|
+
|
4
|
+
Copyright (C) 1989, 1991 Free Software Foundation, Inc.,
|
5
|
+
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
6
|
+
Everyone is permitted to copy and distribute verbatim copies
|
7
|
+
of this license document, but changing it is not allowed.
|
8
|
+
|
9
|
+
Preamble
|
10
|
+
|
11
|
+
The licenses for most software are designed to take away your
|
12
|
+
freedom to share and change it. By contrast, the GNU General Public
|
13
|
+
License is intended to guarantee your freedom to share and change free
|
14
|
+
software--to make sure the software is free for all its users. This
|
15
|
+
General Public License applies to most of the Free Software
|
16
|
+
Foundation's software and to any other program whose authors commit to
|
17
|
+
using it. (Some other Free Software Foundation software is covered by
|
18
|
+
the GNU Lesser General Public License instead.) You can apply it to
|
19
|
+
your programs, too.
|
20
|
+
|
21
|
+
When we speak of free software, we are referring to freedom, not
|
22
|
+
price. Our General Public Licenses are designed to make sure that you
|
23
|
+
have the freedom to distribute copies of free software (and charge for
|
24
|
+
this service if you wish), that you receive source code or can get it
|
25
|
+
if you want it, that you can change the software or use pieces of it
|
26
|
+
in new free programs; and that you know you can do these things.
|
27
|
+
|
28
|
+
To protect your rights, we need to make restrictions that forbid
|
29
|
+
anyone to deny you these rights or to ask you to surrender the rights.
|
30
|
+
These restrictions translate to certain responsibilities for you if you
|
31
|
+
distribute copies of the software, or if you modify it.
|
32
|
+
|
33
|
+
For example, if you distribute copies of such a program, whether
|
34
|
+
gratis or for a fee, you must give the recipients all the rights that
|
35
|
+
you have. You must make sure that they, too, receive or can get the
|
36
|
+
source code. And you must show them these terms so they know their
|
37
|
+
rights.
|
38
|
+
|
39
|
+
We protect your rights with two steps: (1) copyright the software, and
|
40
|
+
(2) offer you this license which gives you legal permission to copy,
|
41
|
+
distribute and/or modify the software.
|
42
|
+
|
43
|
+
Also, for each author's protection and ours, we want to make certain
|
44
|
+
that everyone understands that there is no warranty for this free
|
45
|
+
software. If the software is modified by someone else and passed on, we
|
46
|
+
want its recipients to know that what they have is not the original, so
|
47
|
+
that any problems introduced by others will not reflect on the original
|
48
|
+
authors' reputations.
|
49
|
+
|
50
|
+
Finally, any free program is threatened constantly by software
|
51
|
+
patents. We wish to avoid the danger that redistributors of a free
|
52
|
+
program will individually obtain patent licenses, in effect making the
|
53
|
+
program proprietary. To prevent this, we have made it clear that any
|
54
|
+
patent must be licensed for everyone's free use or not licensed at all.
|
55
|
+
|
56
|
+
The precise terms and conditions for copying, distribution and
|
57
|
+
modification follow.
|
58
|
+
|
59
|
+
GNU GENERAL PUBLIC LICENSE
|
60
|
+
TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
|
61
|
+
|
62
|
+
0. This License applies to any program or other work which contains
|
63
|
+
a notice placed by the copyright holder saying it may be distributed
|
64
|
+
under the terms of this General Public License. The "Program", below,
|
65
|
+
refers to any such program or work, and a "work based on the Program"
|
66
|
+
means either the Program or any derivative work under copyright law:
|
67
|
+
that is to say, a work containing the Program or a portion of it,
|
68
|
+
either verbatim or with modifications and/or translated into another
|
69
|
+
language. (Hereinafter, translation is included without limitation in
|
70
|
+
the term "modification".) Each licensee is addressed as "you".
|
71
|
+
|
72
|
+
Activities other than copying, distribution and modification are not
|
73
|
+
covered by this License; they are outside its scope. The act of
|
74
|
+
running the Program is not restricted, and the output from the Program
|
75
|
+
is covered only if its contents constitute a work based on the
|
76
|
+
Program (independent of having been made by running the Program).
|
77
|
+
Whether that is true depends on what the Program does.
|
78
|
+
|
79
|
+
1. You may copy and distribute verbatim copies of the Program's
|
80
|
+
source code as you receive it, in any medium, provided that you
|
81
|
+
conspicuously and appropriately publish on each copy an appropriate
|
82
|
+
copyright notice and disclaimer of warranty; keep intact all the
|
83
|
+
notices that refer to this License and to the absence of any warranty;
|
84
|
+
and give any other recipients of the Program a copy of this License
|
85
|
+
along with the Program.
|
86
|
+
|
87
|
+
You may charge a fee for the physical act of transferring a copy, and
|
88
|
+
you may at your option offer warranty protection in exchange for a fee.
|
89
|
+
|
90
|
+
2. You may modify your copy or copies of the Program or any portion
|
91
|
+
of it, thus forming a work based on the Program, and copy and
|
92
|
+
distribute such modifications or work under the terms of Section 1
|
93
|
+
above, provided that you also meet all of these conditions:
|
94
|
+
|
95
|
+
a) You must cause the modified files to carry prominent notices
|
96
|
+
stating that you changed the files and the date of any change.
|
97
|
+
|
98
|
+
b) You must cause any work that you distribute or publish, that in
|
99
|
+
whole or in part contains or is derived from the Program or any
|
100
|
+
part thereof, to be licensed as a whole at no charge to all third
|
101
|
+
parties under the terms of this License.
|
102
|
+
|
103
|
+
c) If the modified program normally reads commands interactively
|
104
|
+
when run, you must cause it, when started running for such
|
105
|
+
interactive use in the most ordinary way, to print or display an
|
106
|
+
announcement including an appropriate copyright notice and a
|
107
|
+
notice that there is no warranty (or else, saying that you provide
|
108
|
+
a warranty) and that users may redistribute the program under
|
109
|
+
these conditions, and telling the user how to view a copy of this
|
110
|
+
License. (Exception: if the Program itself is interactive but
|
111
|
+
does not normally print such an announcement, your work based on
|
112
|
+
the Program is not required to print an announcement.)
|
113
|
+
|
114
|
+
These requirements apply to the modified work as a whole. If
|
115
|
+
identifiable sections of that work are not derived from the Program,
|
116
|
+
and can be reasonably considered independent and separate works in
|
117
|
+
themselves, then this License, and its terms, do not apply to those
|
118
|
+
sections when you distribute them as separate works. But when you
|
119
|
+
distribute the same sections as part of a whole which is a work based
|
120
|
+
on the Program, the distribution of the whole must be on the terms of
|
121
|
+
this License, whose permissions for other licensees extend to the
|
122
|
+
entire whole, and thus to each and every part regardless of who wrote it.
|
123
|
+
|
124
|
+
Thus, it is not the intent of this section to claim rights or contest
|
125
|
+
your rights to work written entirely by you; rather, the intent is to
|
126
|
+
exercise the right to control the distribution of derivative or
|
127
|
+
collective works based on the Program.
|
128
|
+
|
129
|
+
In addition, mere aggregation of another work not based on the Program
|
130
|
+
with the Program (or with a work based on the Program) on a volume of
|
131
|
+
a storage or distribution medium does not bring the other work under
|
132
|
+
the scope of this License.
|
133
|
+
|
134
|
+
3. You may copy and distribute the Program (or a work based on it,
|
135
|
+
under Section 2) in object code or executable form under the terms of
|
136
|
+
Sections 1 and 2 above provided that you also do one of the following:
|
137
|
+
|
138
|
+
a) Accompany it with the complete corresponding machine-readable
|
139
|
+
source code, which must be distributed under the terms of Sections
|
140
|
+
1 and 2 above on a medium customarily used for software interchange; or,
|
141
|
+
|
142
|
+
b) Accompany it with a written offer, valid for at least three
|
143
|
+
years, to give any third party, for a charge no more than your
|
144
|
+
cost of physically performing source distribution, a complete
|
145
|
+
machine-readable copy of the corresponding source code, to be
|
146
|
+
distributed under the terms of Sections 1 and 2 above on a medium
|
147
|
+
customarily used for software interchange; or,
|
148
|
+
|
149
|
+
c) Accompany it with the information you received as to the offer
|
150
|
+
to distribute corresponding source code. (This alternative is
|
151
|
+
allowed only for noncommercial distribution and only if you
|
152
|
+
received the program in object code or executable form with such
|
153
|
+
an offer, in accord with Subsection b above.)
|
154
|
+
|
155
|
+
The source code for a work means the preferred form of the work for
|
156
|
+
making modifications to it. For an executable work, complete source
|
157
|
+
code means all the source code for all modules it contains, plus any
|
158
|
+
associated interface definition files, plus the scripts used to
|
159
|
+
control compilation and installation of the executable. However, as a
|
160
|
+
special exception, the source code distributed need not include
|
161
|
+
anything that is normally distributed (in either source or binary
|
162
|
+
form) with the major components (compiler, kernel, and so on) of the
|
163
|
+
operating system on which the executable runs, unless that component
|
164
|
+
itself accompanies the executable.
|
165
|
+
|
166
|
+
If distribution of executable or object code is made by offering
|
167
|
+
access to copy from a designated place, then offering equivalent
|
168
|
+
access to copy the source code from the same place counts as
|
169
|
+
distribution of the source code, even though third parties are not
|
170
|
+
compelled to copy the source along with the object code.
|
171
|
+
|
172
|
+
4. You may not copy, modify, sublicense, or distribute the Program
|
173
|
+
except as expressly provided under this License. Any attempt
|
174
|
+
otherwise to copy, modify, sublicense or distribute the Program is
|
175
|
+
void, and will automatically terminate your rights under this License.
|
176
|
+
However, parties who have received copies, or rights, from you under
|
177
|
+
this License will not have their licenses terminated so long as such
|
178
|
+
parties remain in full compliance.
|
179
|
+
|
180
|
+
5. You are not required to accept this License, since you have not
|
181
|
+
signed it. However, nothing else grants you permission to modify or
|
182
|
+
distribute the Program or its derivative works. These actions are
|
183
|
+
prohibited by law if you do not accept this License. Therefore, by
|
184
|
+
modifying or distributing the Program (or any work based on the
|
185
|
+
Program), you indicate your acceptance of this License to do so, and
|
186
|
+
all its terms and conditions for copying, distributing or modifying
|
187
|
+
the Program or works based on it.
|
188
|
+
|
189
|
+
6. Each time you redistribute the Program (or any work based on the
|
190
|
+
Program), the recipient automatically receives a license from the
|
191
|
+
original licensor to copy, distribute or modify the Program subject to
|
192
|
+
these terms and conditions. You may not impose any further
|
193
|
+
restrictions on the recipients' exercise of the rights granted herein.
|
194
|
+
You are not responsible for enforcing compliance by third parties to
|
195
|
+
this License.
|
196
|
+
|
197
|
+
7. If, as a consequence of a court judgment or allegation of patent
|
198
|
+
infringement or for any other reason (not limited to patent issues),
|
199
|
+
conditions are imposed on you (whether by court order, agreement or
|
200
|
+
otherwise) that contradict the conditions of this License, they do not
|
201
|
+
excuse you from the conditions of this License. If you cannot
|
202
|
+
distribute so as to satisfy simultaneously your obligations under this
|
203
|
+
License and any other pertinent obligations, then as a consequence you
|
204
|
+
may not distribute the Program at all. For example, if a patent
|
205
|
+
license would not permit royalty-free redistribution of the Program by
|
206
|
+
all those who receive copies directly or indirectly through you, then
|
207
|
+
the only way you could satisfy both it and this License would be to
|
208
|
+
refrain entirely from distribution of the Program.
|
209
|
+
|
210
|
+
If any portion of this section is held invalid or unenforceable under
|
211
|
+
any particular circumstance, the balance of the section is intended to
|
212
|
+
apply and the section as a whole is intended to apply in other
|
213
|
+
circumstances.
|
214
|
+
|
215
|
+
It is not the purpose of this section to induce you to infringe any
|
216
|
+
patents or other property right claims or to contest validity of any
|
217
|
+
such claims; this section has the sole purpose of protecting the
|
218
|
+
integrity of the free software distribution system, which is
|
219
|
+
implemented by public license practices. Many people have made
|
220
|
+
generous contributions to the wide range of software distributed
|
221
|
+
through that system in reliance on consistent application of that
|
222
|
+
system; it is up to the author/donor to decide if he or she is willing
|
223
|
+
to distribute software through any other system and a licensee cannot
|
224
|
+
impose that choice.
|
225
|
+
|
226
|
+
This section is intended to make thoroughly clear what is believed to
|
227
|
+
be a consequence of the rest of this License.
|
228
|
+
|
229
|
+
8. If the distribution and/or use of the Program is restricted in
|
230
|
+
certain countries either by patents or by copyrighted interfaces, the
|
231
|
+
original copyright holder who places the Program under this License
|
232
|
+
may add an explicit geographical distribution limitation excluding
|
233
|
+
those countries, so that distribution is permitted only in or among
|
234
|
+
countries not thus excluded. In such case, this License incorporates
|
235
|
+
the limitation as if written in the body of this License.
|
236
|
+
|
237
|
+
9. The Free Software Foundation may publish revised and/or new versions
|
238
|
+
of the General Public License from time to time. Such new versions will
|
239
|
+
be similar in spirit to the present version, but may differ in detail to
|
240
|
+
address new problems or concerns.
|
241
|
+
|
242
|
+
Each version is given a distinguishing version number. If the Program
|
243
|
+
specifies a version number of this License which applies to it and "any
|
244
|
+
later version", you have the option of following the terms and conditions
|
245
|
+
either of that version or of any later version published by the Free
|
246
|
+
Software Foundation. If the Program does not specify a version number of
|
247
|
+
this License, you may choose any version ever published by the Free Software
|
248
|
+
Foundation.
|
249
|
+
|
250
|
+
10. If you wish to incorporate parts of the Program into other free
|
251
|
+
programs whose distribution conditions are different, write to the author
|
252
|
+
to ask for permission. For software which is copyrighted by the Free
|
253
|
+
Software Foundation, write to the Free Software Foundation; we sometimes
|
254
|
+
make exceptions for this. Our decision will be guided by the two goals
|
255
|
+
of preserving the free status of all derivatives of our free software and
|
256
|
+
of promoting the sharing and reuse of software generally.
|
257
|
+
|
258
|
+
NO WARRANTY
|
259
|
+
|
260
|
+
11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY
|
261
|
+
FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN
|
262
|
+
OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES
|
263
|
+
PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED
|
264
|
+
OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
265
|
+
MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS
|
266
|
+
TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE
|
267
|
+
PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING,
|
268
|
+
REPAIR OR CORRECTION.
|
269
|
+
|
270
|
+
12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
|
271
|
+
WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR
|
272
|
+
REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES,
|
273
|
+
INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING
|
274
|
+
OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED
|
275
|
+
TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY
|
276
|
+
YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER
|
277
|
+
PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE
|
278
|
+
POSSIBILITY OF SUCH DAMAGES.
|
279
|
+
|
280
|
+
END OF TERMS AND CONDITIONS
|
281
|
+
|
282
|
+
How to Apply These Terms to Your New Programs
|
283
|
+
|
284
|
+
If you develop a new program, and you want it to be of the greatest
|
285
|
+
possible use to the public, the best way to achieve this is to make it
|
286
|
+
free software which everyone can redistribute and change under these terms.
|
287
|
+
|
288
|
+
To do so, attach the following notices to the program. It is safest
|
289
|
+
to attach them to the start of each source file to most effectively
|
290
|
+
convey the exclusion of warranty; and each file should have at least
|
291
|
+
the "copyright" line and a pointer to where the full notice is found.
|
292
|
+
|
293
|
+
<one line to give the program's name and a brief idea of what it does.>
|
294
|
+
Copyright (C) <year> <name of author>
|
295
|
+
|
296
|
+
This program is free software; you can redistribute it and/or modify
|
297
|
+
it under the terms of the GNU General Public License as published by
|
298
|
+
the Free Software Foundation; either version 2 of the License, or
|
299
|
+
(at your option) any later version.
|
300
|
+
|
301
|
+
This program is distributed in the hope that it will be useful,
|
302
|
+
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
303
|
+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
304
|
+
GNU General Public License for more details.
|
305
|
+
|
306
|
+
You should have received a copy of the GNU General Public License along
|
307
|
+
with this program; if not, write to the Free Software Foundation, Inc.,
|
308
|
+
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
309
|
+
|
310
|
+
Also add information on how to contact you by electronic and paper mail.
|
311
|
+
|
312
|
+
If the program is interactive, make it output a short notice like this
|
313
|
+
when it starts in an interactive mode:
|
314
|
+
|
315
|
+
Gnomovision version 69, Copyright (C) year name of author
|
316
|
+
Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
|
317
|
+
This is free software, and you are welcome to redistribute it
|
318
|
+
under certain conditions; type `show c' for details.
|
319
|
+
|
320
|
+
The hypothetical commands `show w' and `show c' should show the appropriate
|
321
|
+
parts of the General Public License. Of course, the commands you use may
|
322
|
+
be called something other than `show w' and `show c'; they could even be
|
323
|
+
mouse-clicks or menu items--whatever suits your program.
|
324
|
+
|
325
|
+
You should also get your employer (if you work as a programmer) or your
|
326
|
+
school, if any, to sign a "copyright disclaimer" for the program, if
|
327
|
+
necessary. Here is a sample; alter the names:
|
328
|
+
|
329
|
+
Yoyodyne, Inc., hereby disclaims all copyright interest in the program
|
330
|
+
`Gnomovision' (which makes passes at compilers) written by James Hacker.
|
331
|
+
|
332
|
+
<signature of Ty Coon>, 1 April 1989
|
333
|
+
Ty Coon, President of Vice
|
334
|
+
|
335
|
+
This General Public License does not permit incorporating your program into
|
336
|
+
proprietary programs. If your program is a subroutine library, you may
|
337
|
+
consider it more useful to permit linking proprietary applications with the
|
338
|
+
library. If this is what you want to do, use the GNU Lesser General
|
339
|
+
Public License instead of this License.
|
data/README.rdoc
ADDED
@@ -0,0 +1,80 @@
|
|
1
|
+
= libacl-ruby
|
2
|
+
|
3
|
+
== Prerequesites
|
4
|
+
|
5
|
+
In order to successfully install libacl-ruby, you need the following:
|
6
|
+
|
7
|
+
* Ruby >= 1.9.2
|
8
|
+
* A C++ compiler (we use the {GNU project's}[http://www.gnu.org] <tt>g++</tt>)
|
9
|
+
* libacl
|
10
|
+
|
11
|
+
== How to install?
|
12
|
+
|
13
|
+
=== RubyGems
|
14
|
+
|
15
|
+
This is the easiest and preferred way. Ensure you have a proper built
|
16
|
+
environment for C++ code, and then do
|
17
|
+
|
18
|
+
# gem install libacl-ruby
|
19
|
+
|
20
|
+
=== Building from source
|
21
|
+
|
22
|
+
If you want to be on the bleeding etch, clone the our
|
23
|
+
{git repository at GitHub}[https://github.com/Hanmac/libacl-ruby]:
|
24
|
+
|
25
|
+
$ git clone https://github.com/Hanmac/libacl-ruby.git
|
26
|
+
$ cd libacl-ruby
|
27
|
+
|
28
|
+
Then you can either choose to use the library from that directory by running
|
29
|
+
|
30
|
+
$ rake compile
|
31
|
+
|
32
|
+
or to make a gem and install that one.
|
33
|
+
|
34
|
+
$ rake gem
|
35
|
+
# gem install --local pkg/libacl-ruby-x.x.x
|
36
|
+
|
37
|
+
== How to use?
|
38
|
+
|
39
|
+
First, you have to require the library:
|
40
|
+
|
41
|
+
require "acl" #Note this is NOT "libacl-ruby"
|
42
|
+
|
43
|
+
Then you can use the beautiful rubyish API:
|
44
|
+
|
45
|
+
|
46
|
+
== Further reading
|
47
|
+
|
48
|
+
Have a look at the documentation for the ACL and ACL::Entry classes
|
49
|
+
for more information.
|
50
|
+
|
51
|
+
== Contributors
|
52
|
+
|
53
|
+
The following people have worked on libacl-ruby beside
|
54
|
+
me:
|
55
|
+
|
56
|
+
* Quintus <sutniuq ÄT gmx DÖT net> contributed to the docs
|
57
|
+
|
58
|
+
== License
|
59
|
+
|
60
|
+
libacl-ruby is a Ruby binding for the C library libacl.
|
61
|
+
|
62
|
+
Copyright © 2011 Hans Mackowiak
|
63
|
+
|
64
|
+
This program is free software; you can redistribute it and/or modify
|
65
|
+
it under the terms of the GNU General Public License as published by
|
66
|
+
the Free Software Foundation; either version 2 of the License, or
|
67
|
+
(at your option) any later version.
|
68
|
+
|
69
|
+
This program is distributed in the hope that it will be useful,
|
70
|
+
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
71
|
+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
72
|
+
GNU General Public License for more details.
|
73
|
+
|
74
|
+
You should have received a copy of the GNU General Public License along
|
75
|
+
with this program; if not, write to the Free Software Foundation, Inc.,
|
76
|
+
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
77
|
+
|
78
|
+
=== Contact
|
79
|
+
|
80
|
+
You can read me via the email address hanmac ÄT gmx DÖT de.
|
data/ext/acl.cpp
ADDED
@@ -0,0 +1,217 @@
|
|
1
|
+
#include "main.hpp"
|
2
|
+
|
3
|
+
VALUE rb_cAcl,rb_cAclEntry;
|
4
|
+
|
5
|
+
#define _self wrap<acl_t>(self)
|
6
|
+
|
7
|
+
VALUE ACL_alloc(VALUE self)
|
8
|
+
{
|
9
|
+
acl_t acl = acl_init(1);
|
10
|
+
return wrap(acl);
|
11
|
+
}
|
12
|
+
|
13
|
+
VALUE IO_acl(VALUE self)
|
14
|
+
{
|
15
|
+
acl_t acl = acl_get_fd(NUM2INT(rb_funcall(self,rb_intern("to_i"),0)));
|
16
|
+
return acl ? wrap(acl) : Qnil;
|
17
|
+
}
|
18
|
+
|
19
|
+
VALUE IO_set_acl(VALUE self,VALUE acl)
|
20
|
+
{
|
21
|
+
acl_set_fd(NUM2INT(rb_funcall(self,rb_intern("to_i"),0)),wrap<acl_t>(acl));
|
22
|
+
return acl;
|
23
|
+
}
|
24
|
+
VALUE File_single_access_acl(VALUE self,VALUE name)
|
25
|
+
{
|
26
|
+
acl_t acl = acl_get_file(rb_string_value_cstr(&name), ACL_TYPE_ACCESS);
|
27
|
+
return acl ? wrap(acl) : Qnil;
|
28
|
+
}
|
29
|
+
|
30
|
+
VALUE File_single_default_acl(VALUE self,VALUE name)
|
31
|
+
{
|
32
|
+
acl_t acl = acl_get_file(rb_string_value_cstr(&name), ACL_TYPE_DEFAULT);
|
33
|
+
return acl ? wrap(acl) : Qnil;
|
34
|
+
}
|
35
|
+
|
36
|
+
VALUE File_single_set_access_acl(VALUE self,VALUE name,VALUE acl)
|
37
|
+
{
|
38
|
+
acl_set_file(rb_string_value_cstr(&name), ACL_TYPE_ACCESS,wrap<acl_t>(acl));
|
39
|
+
return acl;
|
40
|
+
}
|
41
|
+
|
42
|
+
VALUE File_single_set_default_acl(VALUE self,VALUE name,VALUE acl)
|
43
|
+
{
|
44
|
+
acl_set_file(rb_string_value_cstr(&name), ACL_TYPE_DEFAULT,wrap<acl_t>(acl));
|
45
|
+
return acl;
|
46
|
+
}
|
47
|
+
|
48
|
+
VALUE File_access_acl(VALUE self)
|
49
|
+
{
|
50
|
+
VALUE name = rb_get_path(self);
|
51
|
+
acl_t acl = acl_get_file(rb_string_value_cstr(&name), ACL_TYPE_ACCESS);
|
52
|
+
return acl ? wrap(acl) : Qnil;
|
53
|
+
}
|
54
|
+
|
55
|
+
VALUE File_set_access_acl(VALUE self,VALUE acl)
|
56
|
+
{
|
57
|
+
if(rb_obj_is_kind_of(acl,rb_cAcl)){
|
58
|
+
VALUE name = rb_get_path(self);
|
59
|
+
acl_set_file(rb_string_value_cstr(&name), ACL_TYPE_ACCESS,wrap<acl_t>(acl));
|
60
|
+
}else
|
61
|
+
rb_raise(rb_eTypeError,"exepted %s!",rb_class2name(rb_cAcl));
|
62
|
+
return acl;
|
63
|
+
}
|
64
|
+
|
65
|
+
VALUE File_default_acl(VALUE self)
|
66
|
+
{
|
67
|
+
VALUE name = rb_get_path(self);
|
68
|
+
acl_t acl = acl_get_file(rb_string_value_cstr(&name), ACL_TYPE_DEFAULT);
|
69
|
+
return acl ? wrap(acl) : Qnil;
|
70
|
+
}
|
71
|
+
|
72
|
+
VALUE File_set_default_acl(VALUE self,VALUE acl)
|
73
|
+
{
|
74
|
+
if(rb_obj_is_kind_of(acl,rb_cAcl)){
|
75
|
+
VALUE name = rb_get_path(self);
|
76
|
+
acl_set_file(rb_string_value_cstr(&name), ACL_TYPE_DEFAULT,wrap<acl_t>(acl));
|
77
|
+
}else
|
78
|
+
rb_raise(rb_eTypeError,"exepted %s!",rb_class2name(rb_cAcl));
|
79
|
+
return acl;
|
80
|
+
}
|
81
|
+
|
82
|
+
|
83
|
+
VALUE ACL_size(VALUE self)
|
84
|
+
{
|
85
|
+
return INT2NUM(acl_entries(_self));
|
86
|
+
}
|
87
|
+
|
88
|
+
VALUE ACL_valid(VALUE self)
|
89
|
+
{
|
90
|
+
// int i = acl_check(_self,NULL);
|
91
|
+
// if(i)
|
92
|
+
// rb_warn("%d:%s",i,acl_error(i));
|
93
|
+
return acl_valid(_self)==0 ? Qtrue : Qfalse;
|
94
|
+
}
|
95
|
+
|
96
|
+
|
97
|
+
VALUE ACL_inspect(VALUE self)
|
98
|
+
{
|
99
|
+
return rb_str_new2(acl_to_text(_self,NULL));
|
100
|
+
}
|
101
|
+
|
102
|
+
VALUE ACL_entries(VALUE self)
|
103
|
+
{
|
104
|
+
RETURN_ENUMERATOR(self,0,NULL);
|
105
|
+
VALUE result = rb_ary_new();
|
106
|
+
acl_entry_t entry;
|
107
|
+
int i = -1;
|
108
|
+
for(int id = ACL_FIRST_ENTRY;i > 0;id=ACL_NEXT_ENTRY){
|
109
|
+
i = acl_get_entry(_self,id, &entry);
|
110
|
+
if(i>0){
|
111
|
+
VALUE temp = wrap(entry);
|
112
|
+
rb_yield(temp);
|
113
|
+
rb_ary_push(result,temp);
|
114
|
+
}
|
115
|
+
}
|
116
|
+
return result;
|
117
|
+
}
|
118
|
+
|
119
|
+
VALUE ACL_add(VALUE self,VALUE entry)
|
120
|
+
{
|
121
|
+
acl_entry_t newentry;
|
122
|
+
acl_t acl = _self;
|
123
|
+
int i = -1;
|
124
|
+
bool found_mask=false;
|
125
|
+
acl_tag_t tag,oldtag;
|
126
|
+
acl_get_tag_type(wrap<acl_entry_t>(entry),&tag);
|
127
|
+
switch(tag){
|
128
|
+
case ACL_USER_OBJ:
|
129
|
+
case ACL_GROUP_OBJ:
|
130
|
+
case ACL_OTHER:
|
131
|
+
case ACL_MASK:
|
132
|
+
for(int id = ACL_FIRST_ENTRY;i>0;id=ACL_NEXT_ENTRY){
|
133
|
+
i = acl_get_entry(_self,id, &newentry);
|
134
|
+
if(i){
|
135
|
+
acl_get_tag_type(newentry,&oldtag);
|
136
|
+
if(tag==oldtag)
|
137
|
+
acl_delete_entry(_self,newentry);
|
138
|
+
}
|
139
|
+
}
|
140
|
+
break;
|
141
|
+
case ACL_USER:
|
142
|
+
case ACL_GROUP:
|
143
|
+
|
144
|
+
for(int id = ACL_FIRST_ENTRY;i>0;id=ACL_NEXT_ENTRY){
|
145
|
+
i = acl_get_entry(_self,id, &newentry);
|
146
|
+
if(i>0){
|
147
|
+
acl_get_tag_type(newentry,&oldtag);
|
148
|
+
if(oldtag == ACL_MASK)
|
149
|
+
found_mask=true;
|
150
|
+
if((tag==oldtag) && (acl_get_qualifier(newentry)==acl_get_qualifier(wrap<acl_entry_t>(entry))))
|
151
|
+
acl_delete_entry(_self,newentry);
|
152
|
+
}
|
153
|
+
}
|
154
|
+
if(!found_mask)
|
155
|
+
acl_calc_mask(&acl);
|
156
|
+
}
|
157
|
+
acl_create_entry(&acl,&newentry);
|
158
|
+
acl_copy_entry(newentry,wrap<acl_entry_t>(entry));
|
159
|
+
return self;
|
160
|
+
}
|
161
|
+
|
162
|
+
VALUE ACL_get(VALUE self,VALUE nr)
|
163
|
+
{
|
164
|
+
if(acl_entries(_self) <= NUM2INT(nr))
|
165
|
+
return Qnil;
|
166
|
+
acl_entry_t entry;
|
167
|
+
int i = 0;
|
168
|
+
for(int id = ACL_FIRST_ENTRY;i <= NUM2INT(nr) ;i++){
|
169
|
+
acl_get_entry(_self,id, &entry);
|
170
|
+
id=ACL_NEXT_ENTRY;
|
171
|
+
}
|
172
|
+
return wrap(entry);
|
173
|
+
}
|
174
|
+
|
175
|
+
VALUE ACL_delete_if(VALUE self)
|
176
|
+
{
|
177
|
+
RETURN_ENUMERATOR(self,0,NULL);
|
178
|
+
VALUE result = rb_ary_new();
|
179
|
+
acl_entry_t entry;
|
180
|
+
int i = -1;
|
181
|
+
for(int id = ACL_FIRST_ENTRY;i>0;id=ACL_NEXT_ENTRY){
|
182
|
+
i = acl_get_entry(_self,id, &entry);
|
183
|
+
if(i>0){
|
184
|
+
VALUE temp = wrap(entry);
|
185
|
+
if(RTEST(rb_yield(temp))){
|
186
|
+
acl_delete_entry(_self,entry);
|
187
|
+
rb_ary_push(result,temp);
|
188
|
+
}
|
189
|
+
}
|
190
|
+
}
|
191
|
+
return result;
|
192
|
+
}
|
193
|
+
|
194
|
+
extern "C" void Init_acl(void){
|
195
|
+
rb_cAcl = rb_define_class("ACL",rb_cObject);
|
196
|
+
rb_define_alloc_func(rb_cAcl,ACL_alloc);
|
197
|
+
rb_define_method(rb_cIO,"acl",RUBY_METHOD_FUNC(IO_acl),0);
|
198
|
+
rb_define_method(rb_cIO,"acl=",RUBY_METHOD_FUNC(IO_set_acl),1);
|
199
|
+
rb_define_method(rb_cFile,"access_acl",RUBY_METHOD_FUNC(File_access_acl),0);
|
200
|
+
rb_define_method(rb_cFile,"access_acl=",RUBY_METHOD_FUNC(File_set_access_acl),1);
|
201
|
+
rb_define_method(rb_cFile,"default_acl",RUBY_METHOD_FUNC(File_default_acl),0);
|
202
|
+
rb_define_method(rb_cFile,"default_acl=",RUBY_METHOD_FUNC(File_set_default_acl),1);
|
203
|
+
rb_define_singleton_method(rb_cFile,"get_access_acl",RUBY_METHOD_FUNC(File_single_access_acl),1);
|
204
|
+
rb_define_singleton_method(rb_cFile,"set_access_acl",RUBY_METHOD_FUNC(File_single_set_access_acl),2);
|
205
|
+
rb_define_singleton_method(rb_cFile,"get_default_acl",RUBY_METHOD_FUNC(File_single_default_acl),1);
|
206
|
+
rb_define_singleton_method(rb_cFile,"set_default_acl",RUBY_METHOD_FUNC(File_single_set_default_acl),2);
|
207
|
+
rb_define_method(rb_cAcl,"size",RUBY_METHOD_FUNC(ACL_size),0);
|
208
|
+
rb_define_method(rb_cAcl,"[]",RUBY_METHOD_FUNC(ACL_get),1);
|
209
|
+
|
210
|
+
rb_define_method(rb_cAcl,"delete_if",RUBY_METHOD_FUNC(ACL_delete_if),0);
|
211
|
+
//rb_define_method(rb_cAcl,"inspect",RUBY_METHOD_FUNC(ACL_inspect),0);
|
212
|
+
rb_define_method(rb_cAcl,"valid?",RUBY_METHOD_FUNC(ACL_valid),0);
|
213
|
+
rb_define_method(rb_cAcl,"each",RUBY_METHOD_FUNC(ACL_entries),0);
|
214
|
+
rb_define_method(rb_cAcl,"<<",RUBY_METHOD_FUNC(ACL_add),1);
|
215
|
+
rb_include_module(rb_cAcl,rb_mEnumerable);
|
216
|
+
Init_aclEntry(rb_cAcl);
|
217
|
+
}
|
data/ext/entry.cpp
ADDED
@@ -0,0 +1,337 @@
|
|
1
|
+
#include "main.hpp"
|
2
|
+
#define _self wrap<acl_entry_t>(self)
|
3
|
+
|
4
|
+
VALUE ACLEntry_set_perm(VALUE self,VALUE perm);
|
5
|
+
VALUE ACLEntry_set_id(VALUE self,VALUE id);
|
6
|
+
|
7
|
+
VALUE ACLEntry_alloc(VALUE self)
|
8
|
+
{
|
9
|
+
acl_t acl = acl_init(1);
|
10
|
+
acl_entry_t entry;
|
11
|
+
acl_create_entry(&acl,&entry);
|
12
|
+
acl_free(acl);
|
13
|
+
return wrap(entry);
|
14
|
+
}
|
15
|
+
|
16
|
+
VALUE ACLEntry_initialize_copy(VALUE self, VALUE other)
|
17
|
+
{
|
18
|
+
rb_call_super(1,&other);
|
19
|
+
acl_copy_entry(_self,wrap<acl_entry_t>(other));
|
20
|
+
return self;
|
21
|
+
}
|
22
|
+
|
23
|
+
VALUE ACLEntry_initialize(int argc, VALUE *argv,VALUE self)
|
24
|
+
{
|
25
|
+
VALUE type,perm,id;
|
26
|
+
rb_scan_args(argc, argv, "21", &type,&perm,&id);
|
27
|
+
type = rb_funcall(type,rb_intern("to_sym"),0);
|
28
|
+
if(SYM2ID(type) == rb_intern("user")){
|
29
|
+
if(NIL_P(id))
|
30
|
+
acl_set_tag_type(_self,ACL_USER_OBJ);
|
31
|
+
else
|
32
|
+
acl_set_tag_type(_self,ACL_USER);
|
33
|
+
}else if(SYM2ID(type) == rb_intern("group")){
|
34
|
+
if(NIL_P(id))
|
35
|
+
acl_set_tag_type(_self,ACL_GROUP_OBJ);
|
36
|
+
else
|
37
|
+
acl_set_tag_type(_self,ACL_GROUP);
|
38
|
+
}else if(SYM2ID(type) == rb_intern("other")){
|
39
|
+
acl_set_tag_type(_self,ACL_OTHER);
|
40
|
+
}else if(SYM2ID(type) == rb_intern("mask")){
|
41
|
+
acl_set_tag_type(_self,ACL_MASK);
|
42
|
+
}else
|
43
|
+
rb_raise(rb_eTypeError,"exepted one of :user,:group,:other,:mask!");
|
44
|
+
ACLEntry_set_perm(self,perm);
|
45
|
+
if(!NIL_P(id))
|
46
|
+
ACLEntry_set_id(self,id);
|
47
|
+
return self;
|
48
|
+
}
|
49
|
+
|
50
|
+
VALUE ACLEntry_id(VALUE self)
|
51
|
+
{
|
52
|
+
int* id = (int*) acl_get_qualifier(_self);
|
53
|
+
return id==NULL ? Qnil : INT2NUM(*id);
|
54
|
+
}
|
55
|
+
|
56
|
+
VALUE ACLEntry_id_name(VALUE self)
|
57
|
+
{
|
58
|
+
acl_tag_t tag;
|
59
|
+
acl_get_tag_type(_self,&tag);
|
60
|
+
int* id = (int*) acl_get_qualifier(_self);
|
61
|
+
passwd* pwd;
|
62
|
+
group* grp;
|
63
|
+
VALUE result = Qnil;
|
64
|
+
switch(tag){
|
65
|
+
case ACL_USER:
|
66
|
+
pwd = getpwuid(*id);
|
67
|
+
if(pwd)
|
68
|
+
result = rb_str_new2(pwd->pw_name);
|
69
|
+
break;
|
70
|
+
case ACL_GROUP:
|
71
|
+
grp = getgrgid(*id);
|
72
|
+
if(grp)
|
73
|
+
result = rb_str_new2(grp->gr_name);
|
74
|
+
break;
|
75
|
+
}
|
76
|
+
return result;
|
77
|
+
}
|
78
|
+
|
79
|
+
VALUE ACLEntry_set_id(VALUE self,VALUE id)
|
80
|
+
{
|
81
|
+
acl_tag_t tag;
|
82
|
+
acl_get_tag_type(_self,&tag);
|
83
|
+
if(NIL_P(id)){
|
84
|
+
switch(tag){
|
85
|
+
case ACL_USER:
|
86
|
+
acl_set_tag_type(_self,ACL_USER_OBJ);
|
87
|
+
break;
|
88
|
+
case ACL_GROUP:
|
89
|
+
acl_set_tag_type(_self,ACL_GROUP_OBJ);
|
90
|
+
break;
|
91
|
+
}
|
92
|
+
acl_set_qualifier(_self,NULL);
|
93
|
+
}else if(rb_obj_is_kind_of(id,rb_cInteger)){
|
94
|
+
int i;
|
95
|
+
switch(tag){
|
96
|
+
case ACL_USER_OBJ:
|
97
|
+
case ACL_USER:
|
98
|
+
case ACL_GROUP_OBJ:
|
99
|
+
case ACL_GROUP:
|
100
|
+
i = NUM2INT(id);
|
101
|
+
acl_set_qualifier(_self,&i);
|
102
|
+
default:
|
103
|
+
rb_raise(rb_eArgError,"id only supported with user or group.");
|
104
|
+
}
|
105
|
+
}else{
|
106
|
+
passwd* pwd;
|
107
|
+
group* grp;
|
108
|
+
id= rb_funcall(id,rb_intern("to_s"),0);
|
109
|
+
const char* name = rb_string_value_cstr(&id);
|
110
|
+
switch(tag){
|
111
|
+
case ACL_USER_OBJ:
|
112
|
+
case ACL_USER:
|
113
|
+
pwd = getpwnam(name);
|
114
|
+
if(pwd){
|
115
|
+
uid_t u = pwd->pw_uid;
|
116
|
+
acl_set_tag_type(_self,ACL_USER);
|
117
|
+
acl_set_qualifier(_self,&u);
|
118
|
+
}else
|
119
|
+
rb_raise(rb_eArgError,"There is no User with the name:%s!",name);
|
120
|
+
break;
|
121
|
+
case ACL_GROUP_OBJ:
|
122
|
+
case ACL_GROUP:
|
123
|
+
grp = getgrnam(name);
|
124
|
+
if(grp){
|
125
|
+
gid_t g = grp->gr_gid;
|
126
|
+
acl_set_tag_type(_self,ACL_GROUP);
|
127
|
+
acl_set_qualifier(_self,&g);
|
128
|
+
}else
|
129
|
+
rb_raise(rb_eArgError,"There is no Group with the name:%s!",name);
|
130
|
+
break;
|
131
|
+
default:
|
132
|
+
rb_raise(rb_eArgError,"id only supported with user or group.");
|
133
|
+
}
|
134
|
+
}
|
135
|
+
return id;
|
136
|
+
}
|
137
|
+
VALUE ACLEntry_perm(VALUE self)
|
138
|
+
{
|
139
|
+
acl_permset_t set;
|
140
|
+
acl_get_permset(_self,&set);
|
141
|
+
char perm[3];
|
142
|
+
perm[0] = acl_get_perm(set,ACL_READ) ? 'r' : '-';
|
143
|
+
perm[1] = acl_get_perm(set,ACL_WRITE) ? 'w' : '-';
|
144
|
+
perm[2] = acl_get_perm(set,ACL_EXECUTE) ? 'x' : '-';
|
145
|
+
return rb_str_new(perm,3);
|
146
|
+
}
|
147
|
+
|
148
|
+
VALUE ACLEntry_set_perm(VALUE self,VALUE perm)
|
149
|
+
{
|
150
|
+
acl_permset_t set;
|
151
|
+
acl_get_permset(_self,&set);
|
152
|
+
acl_clear_perms(set);
|
153
|
+
if(rb_obj_is_kind_of(perm,rb_cInteger)){
|
154
|
+
int cperm = NUM2INT(perm);
|
155
|
+
if((cperm & ACL_READ) == ACL_READ)
|
156
|
+
acl_add_perm(set,ACL_READ);
|
157
|
+
if((cperm & ACL_WRITE) == ACL_WRITE)
|
158
|
+
acl_add_perm(set,ACL_WRITE);
|
159
|
+
if((cperm & ACL_EXECUTE) == ACL_EXECUTE)
|
160
|
+
acl_add_perm(set,ACL_EXECUTE);
|
161
|
+
}else{
|
162
|
+
perm= rb_funcall(perm,rb_intern("to_s"),0);
|
163
|
+
const char* cperm = rb_string_value_cstr(&perm);
|
164
|
+
for(unsigned int i = 0;i<strlen(cperm);i++){
|
165
|
+
switch(cperm[i]){
|
166
|
+
case 'r':
|
167
|
+
acl_add_perm(set,ACL_READ);
|
168
|
+
break;
|
169
|
+
case 'w':
|
170
|
+
acl_add_perm(set,ACL_WRITE);
|
171
|
+
break;
|
172
|
+
case 'x':
|
173
|
+
acl_add_perm(set,ACL_EXECUTE);
|
174
|
+
break;
|
175
|
+
}
|
176
|
+
}
|
177
|
+
}
|
178
|
+
return perm;
|
179
|
+
}
|
180
|
+
|
181
|
+
VALUE ACLEntry_type(VALUE self)
|
182
|
+
{
|
183
|
+
acl_tag_t tag;
|
184
|
+
acl_get_tag_type(_self,&tag);
|
185
|
+
return INT2NUM(tag);
|
186
|
+
}
|
187
|
+
VALUE ACLEntry_readable(VALUE self)
|
188
|
+
{
|
189
|
+
acl_permset_t set;
|
190
|
+
acl_get_permset(_self,&set);
|
191
|
+
return acl_get_perm(set,ACL_READ) ? Qtrue : Qfalse;
|
192
|
+
}
|
193
|
+
VALUE ACLEntry_writeable(VALUE self)
|
194
|
+
{
|
195
|
+
acl_permset_t set;
|
196
|
+
acl_get_permset(_self,&set);
|
197
|
+
return acl_get_perm(set,ACL_WRITE) ? Qtrue : Qfalse;
|
198
|
+
}
|
199
|
+
VALUE ACLEntry_executable(VALUE self)
|
200
|
+
{
|
201
|
+
acl_permset_t set;
|
202
|
+
acl_get_permset(_self,&set);
|
203
|
+
return acl_get_perm(set,ACL_EXECUTE) ? Qtrue : Qfalse;
|
204
|
+
}
|
205
|
+
VALUE ACLEntry_clear(VALUE self)
|
206
|
+
{
|
207
|
+
acl_permset_t set;
|
208
|
+
acl_get_permset(_self,&set);
|
209
|
+
acl_clear_perms(set);
|
210
|
+
return self;
|
211
|
+
}
|
212
|
+
|
213
|
+
VALUE ACLEntry_to_i(VALUE self)
|
214
|
+
{
|
215
|
+
acl_permset_t set;
|
216
|
+
acl_get_permset(_self,&set);
|
217
|
+
int i = 0;
|
218
|
+
if(acl_get_perm(set,ACL_READ))
|
219
|
+
i += ACL_READ;
|
220
|
+
if(acl_get_perm(set,ACL_WRITE))
|
221
|
+
i += ACL_WRITE;
|
222
|
+
if(acl_get_perm(set,ACL_EXECUTE))
|
223
|
+
i += ACL_EXECUTE;
|
224
|
+
return INT2NUM(i);
|
225
|
+
}
|
226
|
+
|
227
|
+
VALUE ACLEntry_inspect(VALUE self)
|
228
|
+
{
|
229
|
+
acl_tag_t tag;
|
230
|
+
acl_get_tag_type(_self,&tag);
|
231
|
+
passwd* pwd;
|
232
|
+
group* grp;
|
233
|
+
int* id = (int*) acl_get_qualifier(_self);
|
234
|
+
VALUE array[4], result = Qnil;
|
235
|
+
array[2]=array[3]=ACLEntry_perm(self);
|
236
|
+
switch(tag){
|
237
|
+
case ACL_MASK:
|
238
|
+
array[0]=rb_str_new2("#<%s:Mask:%s>");
|
239
|
+
array[1]=rb_class_of(self);
|
240
|
+
result = rb_f_sprintf(3,array);
|
241
|
+
break;
|
242
|
+
case ACL_OTHER:
|
243
|
+
array[0]=rb_str_new2("#<%s:Other:%s>");
|
244
|
+
array[1]=rb_class_of(self);
|
245
|
+
result = rb_f_sprintf(3,array);
|
246
|
+
break;
|
247
|
+
case ACL_USER:
|
248
|
+
pwd = getpwuid(*id);
|
249
|
+
if(pwd){
|
250
|
+
array[0]=rb_str_new2("#<%s:User(%s):%s>");
|
251
|
+
array[2]=rb_str_new2(pwd->pw_name);
|
252
|
+
}else{
|
253
|
+
array[0]=rb_str_new2("#<%s:User(%d):%s>");
|
254
|
+
array[2]=INT2NUM(*id);
|
255
|
+
}
|
256
|
+
array[1]=rb_class_of(self);
|
257
|
+
result = rb_f_sprintf(4,array);
|
258
|
+
break;
|
259
|
+
case ACL_USER_OBJ:
|
260
|
+
array[0]=rb_str_new2("#<%s:User:%s>");
|
261
|
+
array[1]=rb_class_of(self);
|
262
|
+
result = rb_f_sprintf(3,array);
|
263
|
+
break;
|
264
|
+
case ACL_GROUP:
|
265
|
+
grp = getgrgid(*id);
|
266
|
+
if(grp){
|
267
|
+
array[0]=rb_str_new2("#<%s:Group(%s):%s>");
|
268
|
+
array[2]=rb_str_new2(grp->gr_name);
|
269
|
+
}else{
|
270
|
+
array[0]=rb_str_new2("#<%s:Group(%d):%s>");
|
271
|
+
array[2]=INT2NUM(*id);
|
272
|
+
}
|
273
|
+
array[1]=rb_class_of(self);
|
274
|
+
result = rb_f_sprintf(4,array);
|
275
|
+
break;
|
276
|
+
case ACL_GROUP_OBJ:
|
277
|
+
array[0]=rb_str_new2("#<%s:Group:%s>");
|
278
|
+
array[1]=rb_class_of(self);
|
279
|
+
result = rb_f_sprintf(3,array);
|
280
|
+
break;
|
281
|
+
}
|
282
|
+
return result;
|
283
|
+
}
|
284
|
+
|
285
|
+
VALUE ACLEntry_set_readable(VALUE self,VALUE val){
|
286
|
+
acl_permset_t set;
|
287
|
+
acl_get_permset(_self,&set);
|
288
|
+
RTEST(val) ? acl_add_perm(set,ACL_READ) : acl_delete_perm(set,ACL_READ);
|
289
|
+
return val;
|
290
|
+
}
|
291
|
+
VALUE ACLEntry_set_writeable(VALUE self,VALUE val){
|
292
|
+
acl_permset_t set;
|
293
|
+
acl_get_permset(_self,&set);
|
294
|
+
RTEST(val) ? acl_add_perm(set,ACL_WRITE) : acl_delete_perm(set,ACL_WRITE);
|
295
|
+
return val;
|
296
|
+
}
|
297
|
+
VALUE ACLEntry_set_executable(VALUE self,VALUE val){
|
298
|
+
acl_permset_t set;
|
299
|
+
acl_get_permset(_self,&set);
|
300
|
+
RTEST(val) ? acl_add_perm(set,ACL_EXECUTE) : acl_delete_perm(set,ACL_EXECUTE);
|
301
|
+
return val;
|
302
|
+
}
|
303
|
+
|
304
|
+
VALUE ACLEntry_cmp(VALUE self,VALUE val){
|
305
|
+
return rb_funcall(ACLEntry_to_i(self),rb_intern("<=>"),1,rb_funcall(val,rb_intern("to_i"),0));
|
306
|
+
}
|
307
|
+
void Init_aclEntry(VALUE m){
|
308
|
+
rb_cAclEntry = rb_define_class_under(m,"Entry",rb_cObject);
|
309
|
+
rb_define_alloc_func(rb_cAclEntry,ACLEntry_alloc);
|
310
|
+
rb_define_private_method(rb_cAclEntry,"initialize_copy",RUBY_METHOD_FUNC(ACLEntry_initialize_copy),1);
|
311
|
+
|
312
|
+
rb_define_method(rb_cAclEntry,"initialize",RUBY_METHOD_FUNC(ACLEntry_initialize),-1);
|
313
|
+
|
314
|
+
rb_define_method(rb_cAclEntry,"id",RUBY_METHOD_FUNC(ACLEntry_id),0);
|
315
|
+
rb_define_method(rb_cAclEntry,"id_name",RUBY_METHOD_FUNC(ACLEntry_id_name),0);
|
316
|
+
rb_define_method(rb_cAclEntry,"id_name=",RUBY_METHOD_FUNC(ACLEntry_set_id),1);
|
317
|
+
rb_define_alias(rb_cAclEntry,"id=","id_name=");
|
318
|
+
rb_define_method(rb_cAclEntry,"perm",RUBY_METHOD_FUNC(ACLEntry_perm),0);
|
319
|
+
rb_define_method(rb_cAclEntry,"perm=",RUBY_METHOD_FUNC(ACLEntry_set_perm),1);
|
320
|
+
rb_define_method(rb_cAclEntry,"type",RUBY_METHOD_FUNC(ACLEntry_type),0);
|
321
|
+
|
322
|
+
rb_define_method(rb_cAclEntry,"readable",RUBY_METHOD_FUNC(ACLEntry_readable),0);
|
323
|
+
rb_define_method(rb_cAclEntry,"writeable",RUBY_METHOD_FUNC(ACLEntry_writeable),0);
|
324
|
+
rb_define_method(rb_cAclEntry,"executable",RUBY_METHOD_FUNC(ACLEntry_executable),0);
|
325
|
+
|
326
|
+
rb_define_method(rb_cAclEntry,"readable=",RUBY_METHOD_FUNC(ACLEntry_set_readable),1);
|
327
|
+
rb_define_method(rb_cAclEntry,"writeable=",RUBY_METHOD_FUNC(ACLEntry_set_writeable),1);
|
328
|
+
rb_define_method(rb_cAclEntry,"executable=",RUBY_METHOD_FUNC(ACLEntry_set_executable),1);
|
329
|
+
|
330
|
+
rb_define_method(rb_cAclEntry,"clear",RUBY_METHOD_FUNC(ACLEntry_clear),0);
|
331
|
+
rb_define_method(rb_cAclEntry,"to_i",RUBY_METHOD_FUNC(ACLEntry_to_i),0);
|
332
|
+
|
333
|
+
rb_define_method(rb_cAclEntry,"inspect",RUBY_METHOD_FUNC(ACLEntry_inspect),0);
|
334
|
+
|
335
|
+
rb_define_method(rb_cAclEntry,"<=>",RUBY_METHOD_FUNC(ACLEntry_cmp),1);
|
336
|
+
rb_include_module(rb_cAclEntry,rb_mComparable);
|
337
|
+
}
|
data/ext/extconf.rb
ADDED
@@ -0,0 +1,23 @@
|
|
1
|
+
require 'mkmf'
|
2
|
+
|
3
|
+
#find_library("acl","acl_get_file")
|
4
|
+
#find_library("acl","acl_get_fd")
|
5
|
+
|
6
|
+
dir_config("acl")
|
7
|
+
|
8
|
+
unless(find_header("sys/acl.h") &&
|
9
|
+
find_header("acl/libacl.h") &&
|
10
|
+
find_library("acl",nil,"/usr/lib"))
|
11
|
+
abort("libacl is missing.")
|
12
|
+
end
|
13
|
+
|
14
|
+
have_header("pwd.h") if find_header("pwd.h")
|
15
|
+
have_header("grp.h") if find_header("grp.h")
|
16
|
+
|
17
|
+
unless have_func("rb_string_value_cstr","ruby.h")
|
18
|
+
abort("missing VALUE to char convert!")
|
19
|
+
end
|
20
|
+
|
21
|
+
$CFLAGS += " -Wall"
|
22
|
+
|
23
|
+
create_makefile("acl")
|
data/ext/main.hpp
ADDED
@@ -0,0 +1,70 @@
|
|
1
|
+
#ifndef __RubyAclMain_H__
|
2
|
+
#define __RubyAclMain_H__
|
3
|
+
#include <ruby.h>
|
4
|
+
#include <sys/acl.h>
|
5
|
+
#include <acl/libacl.h>
|
6
|
+
|
7
|
+
#include <pwd.h>
|
8
|
+
#include <grp.h>
|
9
|
+
|
10
|
+
extern VALUE rb_cAcl,rb_cAclEntry;
|
11
|
+
|
12
|
+
void Init_aclEntry(VALUE m);
|
13
|
+
//template <typename T>
|
14
|
+
//VALUE wrap(T *arg){ return Qnil;};
|
15
|
+
template <typename T>
|
16
|
+
VALUE wrap(T arg){ return Qnil;};
|
17
|
+
template <typename T>
|
18
|
+
T wrap(const VALUE &arg){};
|
19
|
+
|
20
|
+
struct ruby_acl_entry{
|
21
|
+
acl_t acl;
|
22
|
+
acl_entry_t entry;
|
23
|
+
};
|
24
|
+
inline void ruby_acl_free(ruby_acl_entry* entry){
|
25
|
+
acl_free(entry->acl);
|
26
|
+
free(entry);
|
27
|
+
}
|
28
|
+
|
29
|
+
template <>
|
30
|
+
inline VALUE wrap< acl_entry_t >(acl_entry_t entry )
|
31
|
+
{
|
32
|
+
ruby_acl_entry *obj = new ruby_acl_entry;
|
33
|
+
acl_entry_t newentry;
|
34
|
+
acl_t acl = acl_init(0);
|
35
|
+
obj->acl = acl;
|
36
|
+
acl_create_entry(&acl,&newentry);
|
37
|
+
obj->entry =newentry;
|
38
|
+
acl_copy_entry(newentry,entry);
|
39
|
+
return Data_Wrap_Struct(rb_cAclEntry, NULL, ruby_acl_free, obj);
|
40
|
+
}
|
41
|
+
|
42
|
+
template <>
|
43
|
+
inline VALUE wrap< acl_t >(acl_t file )
|
44
|
+
{
|
45
|
+
return Data_Wrap_Struct(rb_cAcl, NULL, acl_free, file);
|
46
|
+
}
|
47
|
+
|
48
|
+
template <>
|
49
|
+
inline acl_t wrap< acl_t >(const VALUE &vfile)
|
50
|
+
{
|
51
|
+
if ( ! rb_obj_is_kind_of(vfile, rb_cAcl) )
|
52
|
+
return NULL;
|
53
|
+
acl_t file;
|
54
|
+
Data_Get_Struct( vfile, __acl_ext, file);
|
55
|
+
return file;
|
56
|
+
}
|
57
|
+
|
58
|
+
|
59
|
+
template <>
|
60
|
+
inline acl_entry_t wrap< acl_entry_t >(const VALUE &vfile)
|
61
|
+
{
|
62
|
+
if ( ! rb_obj_is_kind_of(vfile, rb_cAclEntry) )
|
63
|
+
return NULL;
|
64
|
+
ruby_acl_entry *obj;
|
65
|
+
Data_Get_Struct( vfile, ruby_acl_entry, obj);
|
66
|
+
return obj->entry;
|
67
|
+
}
|
68
|
+
|
69
|
+
#endif /* __RubyAclMain_H__ */
|
70
|
+
|
metadata
ADDED
@@ -0,0 +1,80 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: libacl-ruby
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
prerelease: true
|
5
|
+
segments:
|
6
|
+
- 0
|
7
|
+
- 0
|
8
|
+
- 1
|
9
|
+
- dev
|
10
|
+
version: 0.0.1.dev
|
11
|
+
platform: ruby
|
12
|
+
authors:
|
13
|
+
- Hanmac
|
14
|
+
autorequire:
|
15
|
+
bindir: bin
|
16
|
+
cert_chain: []
|
17
|
+
|
18
|
+
date: 2011-03-12 00:00:00 +01:00
|
19
|
+
default_executable:
|
20
|
+
dependencies: []
|
21
|
+
|
22
|
+
description: |
|
23
|
+
libacl-ruby provides Ruby bindings for the libacl library that
|
24
|
+
allows you to access the Access Control Lists.
|
25
|
+
|
26
|
+
email: hanmac@gmx.de
|
27
|
+
executables: []
|
28
|
+
|
29
|
+
extensions:
|
30
|
+
- ext/extconf.rb
|
31
|
+
extra_rdoc_files:
|
32
|
+
- README.rdoc
|
33
|
+
files:
|
34
|
+
- README.rdoc
|
35
|
+
- COPYING.txt
|
36
|
+
- ext/entry.cpp
|
37
|
+
- ext/acl.cpp
|
38
|
+
- ext/main.hpp
|
39
|
+
- ext/extconf.rb
|
40
|
+
has_rdoc: true
|
41
|
+
homepage:
|
42
|
+
licenses: []
|
43
|
+
|
44
|
+
post_install_message:
|
45
|
+
rdoc_options:
|
46
|
+
- -t
|
47
|
+
- libacl-ruby RDocs
|
48
|
+
- -m
|
49
|
+
- README.rdoc
|
50
|
+
require_paths:
|
51
|
+
- lib
|
52
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
53
|
+
none: false
|
54
|
+
requirements:
|
55
|
+
- - ">="
|
56
|
+
- !ruby/object:Gem::Version
|
57
|
+
segments:
|
58
|
+
- 1
|
59
|
+
- 9
|
60
|
+
version: "1.9"
|
61
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
62
|
+
none: false
|
63
|
+
requirements:
|
64
|
+
- - ">"
|
65
|
+
- !ruby/object:Gem::Version
|
66
|
+
segments:
|
67
|
+
- 1
|
68
|
+
- 3
|
69
|
+
- 1
|
70
|
+
version: 1.3.1
|
71
|
+
requirements:
|
72
|
+
- A C++ compiler
|
73
|
+
- libacl library
|
74
|
+
rubyforge_project:
|
75
|
+
rubygems_version: 1.3.7
|
76
|
+
signing_key:
|
77
|
+
specification_version: 3
|
78
|
+
summary: Ruby bindings for libacl
|
79
|
+
test_files: []
|
80
|
+
|