line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package File::Ownership::Unix; |
2
|
|
|
|
|
|
|
|
3
|
1
|
|
|
1
|
|
20758
|
use warnings; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
29
|
|
4
|
1
|
|
|
1
|
|
5
|
use strict; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
34
|
|
5
|
1
|
|
|
1
|
|
6
|
use base 'Error::Helper'; |
|
1
|
|
|
|
|
5
|
|
|
1
|
|
|
|
|
869
|
|
6
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
=head1 NAME |
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
File::Ownership::Unix - A object oriented system for working with file ownership under unix. |
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
=head1 VERSION |
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
Version 0.0.0 |
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
=cut |
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
our $VERSION = '0.0.0'; |
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
=head1 SYNOPSIS |
20
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
use File::Ownership::Unix; |
22
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
my $foo=File::Ownership::Unix->new( 1001, 1001 ); |
24
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
#gets the ownership info for a file |
26
|
|
|
|
|
|
|
$foo->setFromFile('/tmp/foo'); |
27
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
#chowns a file using the current [GU]ID |
29
|
|
|
|
|
|
|
$foo->chown('/tmp/bar'); |
30
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
#copies the ownership info from one file to another |
32
|
|
|
|
|
|
|
$foo->setFromFile('/tmp/foo'); |
33
|
|
|
|
|
|
|
$foo->chown('/tmp/bar'); |
34
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
=head1 METHODS |
36
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
=head2 new |
38
|
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
This initiates the object. |
40
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
There are two optional arguments taken. The first |
42
|
|
|
|
|
|
|
one is the UID and the second is the GID. |
43
|
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
Both default to zero. |
45
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
my $foo=File::Ownership::Unix->new; |
47
|
|
|
|
|
|
|
if( $foo->error ){ |
48
|
|
|
|
|
|
|
warn('error:'.$foo->error.': '.$foo->errorString); |
49
|
|
|
|
|
|
|
} |
50
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
=cut |
52
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
sub new{ |
54
|
0
|
|
|
0
|
1
|
|
my $uid=$_[1]; |
55
|
0
|
|
|
|
|
|
my $gid=$_[2]; |
56
|
|
|
|
|
|
|
|
57
|
0
|
|
|
|
|
|
my $self={ |
58
|
|
|
|
|
|
|
perror=>undef, |
59
|
|
|
|
|
|
|
error=>undef, |
60
|
|
|
|
|
|
|
errorString=>'', |
61
|
|
|
|
|
|
|
uid=>0, |
62
|
|
|
|
|
|
|
gid=>0, |
63
|
|
|
|
|
|
|
}; |
64
|
0
|
|
|
|
|
|
bless $self; |
65
|
|
|
|
|
|
|
|
66
|
0
|
0
|
|
|
|
|
if(defined($uid)){ |
67
|
0
|
|
|
|
|
|
$self->{uid}=$uid; |
68
|
|
|
|
|
|
|
} |
69
|
0
|
0
|
|
|
|
|
if(defined($gid)){ |
70
|
0
|
|
|
|
|
|
$self->{gid}=$gid; |
71
|
|
|
|
|
|
|
} |
72
|
|
|
|
|
|
|
|
73
|
0
|
0
|
|
|
|
|
if( $self->{gid} !~ /[0123456789]*/ ){ |
74
|
0
|
|
|
|
|
|
$self->{perror}=1; |
75
|
0
|
|
|
|
|
|
$self->{error}=1; |
76
|
0
|
|
|
|
|
|
$self->{errorString}='"'.$self->{gid}.'" is not a valid value for GID'; |
77
|
0
|
|
|
|
|
|
return $self; |
78
|
|
|
|
|
|
|
} |
79
|
|
|
|
|
|
|
|
80
|
0
|
0
|
|
|
|
|
if( $self->{uid} !~ /[0123456789]*/ ){ |
81
|
0
|
|
|
|
|
|
$self->{perror}=1; |
82
|
0
|
|
|
|
|
|
$self->{error}=1; |
83
|
0
|
|
|
|
|
|
$self->{errorString}='"'.$self->{uid}.'" is not a valid value for the UID'; |
84
|
0
|
|
|
|
|
|
return $self; |
85
|
|
|
|
|
|
|
} |
86
|
|
|
|
|
|
|
|
87
|
0
|
|
|
|
|
|
return $self; |
88
|
|
|
|
|
|
|
} |
89
|
|
|
|
|
|
|
|
90
|
|
|
|
|
|
|
=head2 chown |
91
|
|
|
|
|
|
|
|
92
|
|
|
|
|
|
|
This chowns the specified file. |
93
|
|
|
|
|
|
|
|
94
|
|
|
|
|
|
|
$foo->chown('/tmp/foo'); |
95
|
|
|
|
|
|
|
if( $foo->error ){ |
96
|
|
|
|
|
|
|
warn('error:'.$foo->error.': '.$foo->errorString); |
97
|
|
|
|
|
|
|
} |
98
|
|
|
|
|
|
|
|
99
|
|
|
|
|
|
|
=cut |
100
|
|
|
|
|
|
|
|
101
|
|
|
|
|
|
|
sub chown{ |
102
|
0
|
|
|
0
|
1
|
|
my $self=$_[0]; |
103
|
0
|
|
|
|
|
|
my $file=$_[1]; |
104
|
|
|
|
|
|
|
|
105
|
0
|
|
|
|
|
|
$self->errorblank; |
106
|
0
|
0
|
|
|
|
|
if($self->error){ |
107
|
0
|
|
|
|
|
|
return undef; |
108
|
|
|
|
|
|
|
} |
109
|
|
|
|
|
|
|
|
110
|
0
|
0
|
|
|
|
|
if(!defined($file)){ |
111
|
0
|
|
|
|
|
|
$self->{error}=2; |
112
|
0
|
|
|
|
|
|
$self->{errorString}='No file specified'; |
113
|
0
|
|
|
|
|
|
return undef; |
114
|
|
|
|
|
|
|
} |
115
|
|
|
|
|
|
|
|
116
|
0
|
0
|
|
|
|
|
if (! -e $file){ |
117
|
0
|
|
|
|
|
|
$self->{error}=3; |
118
|
0
|
|
|
|
|
|
$self->{errorString}='"'.$file.'" does not exist'; |
119
|
0
|
|
|
|
|
|
return undef; |
120
|
|
|
|
|
|
|
} |
121
|
|
|
|
|
|
|
|
122
|
0
|
0
|
|
|
|
|
if(!chown( $self->{uid}, $self->{gid}, $file )){ |
123
|
0
|
|
|
|
|
|
$self->{error}=4; |
124
|
0
|
|
|
|
|
|
$self->{errorString}='Failed to chown "'.$file.'" to "'.$self->{uid}.':'.$self->{gid}.'"'; |
125
|
0
|
|
|
|
|
|
return undef; |
126
|
|
|
|
|
|
|
} |
127
|
|
|
|
|
|
|
|
128
|
0
|
|
|
|
|
|
return 1; |
129
|
|
|
|
|
|
|
} |
130
|
|
|
|
|
|
|
|
131
|
|
|
|
|
|
|
=head2 getGID |
132
|
|
|
|
|
|
|
|
133
|
|
|
|
|
|
|
This returns the currently set GID. |
134
|
|
|
|
|
|
|
|
135
|
|
|
|
|
|
|
my $gid=$foo->getGID; |
136
|
|
|
|
|
|
|
|
137
|
|
|
|
|
|
|
=cut |
138
|
|
|
|
|
|
|
|
139
|
|
|
|
|
|
|
sub getGID{ |
140
|
0
|
|
|
0
|
1
|
|
my $self=$_[0]; |
141
|
|
|
|
|
|
|
|
142
|
0
|
|
|
|
|
|
$self->errorblank; |
143
|
0
|
0
|
|
|
|
|
if($self->error){ |
144
|
0
|
|
|
|
|
|
return undef; |
145
|
|
|
|
|
|
|
} |
146
|
|
|
|
|
|
|
|
147
|
0
|
|
|
|
|
|
return $self->{gid}; |
148
|
|
|
|
|
|
|
} |
149
|
|
|
|
|
|
|
|
150
|
|
|
|
|
|
|
=head2 getUID |
151
|
|
|
|
|
|
|
|
152
|
|
|
|
|
|
|
This returns the currently set UID. |
153
|
|
|
|
|
|
|
|
154
|
|
|
|
|
|
|
my $gid=$foo->getGID; |
155
|
|
|
|
|
|
|
|
156
|
|
|
|
|
|
|
=cut |
157
|
|
|
|
|
|
|
|
158
|
|
|
|
|
|
|
sub getUID{ |
159
|
0
|
|
|
0
|
1
|
|
my $self=$_[0]; |
160
|
|
|
|
|
|
|
|
161
|
0
|
|
|
|
|
|
$self->errorblank; |
162
|
0
|
0
|
|
|
|
|
if($self->error){ |
163
|
0
|
|
|
|
|
|
return undef; |
164
|
|
|
|
|
|
|
} |
165
|
|
|
|
|
|
|
|
166
|
0
|
|
|
|
|
|
return $self->{uid}; |
167
|
|
|
|
|
|
|
} |
168
|
|
|
|
|
|
|
|
169
|
|
|
|
|
|
|
=head2 setGID |
170
|
|
|
|
|
|
|
|
171
|
|
|
|
|
|
|
This sets the current GID. |
172
|
|
|
|
|
|
|
|
173
|
|
|
|
|
|
|
$foo->setGID('1001'); |
174
|
|
|
|
|
|
|
if( $foo->error ){ |
175
|
|
|
|
|
|
|
warn('error:'.$foo->error.': '.$foo->errorString); |
176
|
|
|
|
|
|
|
} |
177
|
|
|
|
|
|
|
|
178
|
|
|
|
|
|
|
=cut |
179
|
|
|
|
|
|
|
|
180
|
|
|
|
|
|
|
sub setGID{ |
181
|
0
|
|
|
0
|
1
|
|
my $self=$_[0]; |
182
|
0
|
|
|
|
|
|
my $gid=$_[1]; |
183
|
|
|
|
|
|
|
|
184
|
0
|
|
|
|
|
|
$self->errorblank; |
185
|
0
|
0
|
|
|
|
|
if($self->error){ |
186
|
0
|
|
|
|
|
|
return undef; |
187
|
|
|
|
|
|
|
} |
188
|
|
|
|
|
|
|
|
189
|
0
|
0
|
|
|
|
|
if( $gid !~ /[0123456789]*/ ){ |
190
|
0
|
|
|
|
|
|
$self->{error}=1; |
191
|
0
|
|
|
|
|
|
$self->{errorString}='"'.$gid.'" is not a valid value for GID'; |
192
|
0
|
|
|
|
|
|
return $self; |
193
|
|
|
|
|
|
|
} |
194
|
|
|
|
|
|
|
|
195
|
0
|
|
|
|
|
|
$self->{gid}=$gid; |
196
|
|
|
|
|
|
|
|
197
|
0
|
|
|
|
|
|
return 1; |
198
|
|
|
|
|
|
|
} |
199
|
|
|
|
|
|
|
|
200
|
|
|
|
|
|
|
=head2 setUID |
201
|
|
|
|
|
|
|
|
202
|
|
|
|
|
|
|
This sets the current UID. |
203
|
|
|
|
|
|
|
|
204
|
|
|
|
|
|
|
$foo->setUID('1001'); |
205
|
|
|
|
|
|
|
if( $foo->error ){ |
206
|
|
|
|
|
|
|
warn('error:'.$foo->error.': '.$foo->errorString); |
207
|
|
|
|
|
|
|
} |
208
|
|
|
|
|
|
|
|
209
|
|
|
|
|
|
|
=cut |
210
|
|
|
|
|
|
|
|
211
|
|
|
|
|
|
|
sub setUID{ |
212
|
0
|
|
|
0
|
1
|
|
my $self=$_[0]; |
213
|
0
|
|
|
|
|
|
my $uid=$_[1]; |
214
|
|
|
|
|
|
|
|
215
|
0
|
|
|
|
|
|
$self->errorblank; |
216
|
0
|
0
|
|
|
|
|
if($self->error){ |
217
|
0
|
|
|
|
|
|
return undef; |
218
|
|
|
|
|
|
|
} |
219
|
|
|
|
|
|
|
|
220
|
0
|
0
|
|
|
|
|
if( $uid !~ /[0123456789]*/ ){ |
221
|
0
|
|
|
|
|
|
$self->{error}=1; |
222
|
0
|
|
|
|
|
|
$self->{errorString}='"'.$uid.'" is not a valid value for UID'; |
223
|
0
|
|
|
|
|
|
return $self; |
224
|
|
|
|
|
|
|
} |
225
|
|
|
|
|
|
|
|
226
|
0
|
|
|
|
|
|
$self->{uid}=$uid; |
227
|
|
|
|
|
|
|
|
228
|
0
|
|
|
|
|
|
return 1; |
229
|
|
|
|
|
|
|
} |
230
|
|
|
|
|
|
|
|
231
|
|
|
|
|
|
|
=head2 setFromFile |
232
|
|
|
|
|
|
|
|
233
|
|
|
|
|
|
|
This sets the current [GU]ID from the specified file. |
234
|
|
|
|
|
|
|
|
235
|
|
|
|
|
|
|
$foo->setFromFile('/tmp/foo'); |
236
|
|
|
|
|
|
|
if( $foo->error ){ |
237
|
|
|
|
|
|
|
warn('error:'.$foo->error.': '.$foo->errorString); |
238
|
|
|
|
|
|
|
} |
239
|
|
|
|
|
|
|
|
240
|
|
|
|
|
|
|
=cut |
241
|
|
|
|
|
|
|
|
242
|
|
|
|
|
|
|
sub setFromFile{ |
243
|
0
|
|
|
0
|
1
|
|
my $self=$_[0]; |
244
|
0
|
|
|
|
|
|
my $file=$_[1]; |
245
|
|
|
|
|
|
|
|
246
|
0
|
|
|
|
|
|
$self->errorblank; |
247
|
0
|
0
|
|
|
|
|
if($self->error){ |
248
|
0
|
|
|
|
|
|
return undef; |
249
|
|
|
|
|
|
|
} |
250
|
|
|
|
|
|
|
|
251
|
0
|
0
|
|
|
|
|
if(!defined($file)){ |
252
|
0
|
|
|
|
|
|
$self->{error}=2; |
253
|
0
|
|
|
|
|
|
$self->{errorString}='No file specified'; |
254
|
0
|
|
|
|
|
|
return undef; |
255
|
|
|
|
|
|
|
} |
256
|
|
|
|
|
|
|
|
257
|
0
|
0
|
|
|
|
|
if (! -e $file){ |
258
|
0
|
|
|
|
|
|
$self->{error}=3; |
259
|
0
|
|
|
|
|
|
$self->{errorString}='"'.$file.'" does not exist'; |
260
|
0
|
|
|
|
|
|
return undef; |
261
|
|
|
|
|
|
|
} |
262
|
|
|
|
|
|
|
|
263
|
0
|
|
|
|
|
|
$self->{uid}=(stat($file))[4]; |
264
|
0
|
|
|
|
|
|
$self->{gid}=(stat($file))[5]; |
265
|
|
|
|
|
|
|
|
266
|
0
|
|
|
|
|
|
return 1; |
267
|
|
|
|
|
|
|
} |
268
|
|
|
|
|
|
|
|
269
|
|
|
|
|
|
|
=head1 ERROR CODES |
270
|
|
|
|
|
|
|
|
271
|
|
|
|
|
|
|
=head2 1 |
272
|
|
|
|
|
|
|
|
273
|
|
|
|
|
|
|
Invalid value for a [GU]ID. |
274
|
|
|
|
|
|
|
|
275
|
|
|
|
|
|
|
=head2 2 |
276
|
|
|
|
|
|
|
|
277
|
|
|
|
|
|
|
No file specified. |
278
|
|
|
|
|
|
|
|
279
|
|
|
|
|
|
|
=head2 3 |
280
|
|
|
|
|
|
|
|
281
|
|
|
|
|
|
|
The specified file does not exist. |
282
|
|
|
|
|
|
|
|
283
|
|
|
|
|
|
|
=head2 4 |
284
|
|
|
|
|
|
|
|
285
|
|
|
|
|
|
|
Failed to cown the specified file. |
286
|
|
|
|
|
|
|
|
287
|
|
|
|
|
|
|
=head1 AUTHOR |
288
|
|
|
|
|
|
|
|
289
|
|
|
|
|
|
|
Zane C. Bowers-Hadley, C<< >> |
290
|
|
|
|
|
|
|
|
291
|
|
|
|
|
|
|
=head1 BUGS |
292
|
|
|
|
|
|
|
|
293
|
|
|
|
|
|
|
Please report any bugs or feature requests to C, or through |
294
|
|
|
|
|
|
|
the web interface at L. I will be notified, and then you'll |
295
|
|
|
|
|
|
|
automatically be notified of progress on your bug as I make changes. |
296
|
|
|
|
|
|
|
|
297
|
|
|
|
|
|
|
|
298
|
|
|
|
|
|
|
|
299
|
|
|
|
|
|
|
|
300
|
|
|
|
|
|
|
=head1 SUPPORT |
301
|
|
|
|
|
|
|
|
302
|
|
|
|
|
|
|
You can find documentation for this module with the perldoc command. |
303
|
|
|
|
|
|
|
|
304
|
|
|
|
|
|
|
perldoc File::Ownership::Unix |
305
|
|
|
|
|
|
|
|
306
|
|
|
|
|
|
|
|
307
|
|
|
|
|
|
|
You can also look for information at: |
308
|
|
|
|
|
|
|
|
309
|
|
|
|
|
|
|
=over 4 |
310
|
|
|
|
|
|
|
|
311
|
|
|
|
|
|
|
=item * RT: CPAN's request tracker |
312
|
|
|
|
|
|
|
|
313
|
|
|
|
|
|
|
L |
314
|
|
|
|
|
|
|
|
315
|
|
|
|
|
|
|
=item * AnnoCPAN: Annotated CPAN documentation |
316
|
|
|
|
|
|
|
|
317
|
|
|
|
|
|
|
L |
318
|
|
|
|
|
|
|
|
319
|
|
|
|
|
|
|
=item * CPAN Ratings |
320
|
|
|
|
|
|
|
|
321
|
|
|
|
|
|
|
L |
322
|
|
|
|
|
|
|
|
323
|
|
|
|
|
|
|
=item * Search CPAN |
324
|
|
|
|
|
|
|
|
325
|
|
|
|
|
|
|
L |
326
|
|
|
|
|
|
|
|
327
|
|
|
|
|
|
|
=back |
328
|
|
|
|
|
|
|
|
329
|
|
|
|
|
|
|
|
330
|
|
|
|
|
|
|
=head1 ACKNOWLEDGEMENTS |
331
|
|
|
|
|
|
|
|
332
|
|
|
|
|
|
|
|
333
|
|
|
|
|
|
|
=head1 LICENSE AND COPYRIGHT |
334
|
|
|
|
|
|
|
|
335
|
|
|
|
|
|
|
Copyright 2011 Zane C. Bowers-Hadley. |
336
|
|
|
|
|
|
|
|
337
|
|
|
|
|
|
|
This program is free software; you can redistribute it and/or modify it |
338
|
|
|
|
|
|
|
under the terms of either: the GNU General Public License as published |
339
|
|
|
|
|
|
|
by the Free Software Foundation; or the Artistic License. |
340
|
|
|
|
|
|
|
|
341
|
|
|
|
|
|
|
See http://dev.perl.org/licenses/ for more information. |
342
|
|
|
|
|
|
|
|
343
|
|
|
|
|
|
|
|
344
|
|
|
|
|
|
|
=cut |
345
|
|
|
|
|
|
|
|
346
|
|
|
|
|
|
|
1; # End of File::Ownership::Unix |