line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Sys::Config::Manage::Perms; |
2
|
|
|
|
|
|
|
|
3
|
1
|
|
|
1
|
|
20876
|
use warnings; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
33
|
|
4
|
1
|
|
|
1
|
|
6
|
use strict; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
33
|
|
5
|
1
|
|
|
1
|
|
5
|
use File::Basename; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
85
|
|
6
|
1
|
|
|
1
|
|
5
|
use base 'Error::Helper'; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
792
|
|
7
|
1
|
|
|
1
|
|
1456
|
use String::ShellQuote; |
|
1
|
|
|
|
|
847
|
|
|
1
|
|
|
|
|
3749
|
|
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
=head1 NAME |
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
Sys::Config::Manage::Perms - Handles file permissions for files in a configuration directory. |
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
=head1 VERSION |
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
Version 0.0.0 |
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
=cut |
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
our $VERSION = '0.0.0'; |
20
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
=head1 SYNOPSIS |
23
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
use Sys::Config::Manage::Perms; |
25
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
my $foo = Sys::Config::Manage::Perms->new(); |
27
|
|
|
|
|
|
|
... |
28
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
=head1 METHODS |
30
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
=head2 new |
32
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
This initiates the object. |
34
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
One argument is required and it is a hash reference. |
36
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
=head3 args hash ref |
38
|
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
=head4 scm |
40
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
This is a initiated Sys::Config::Manage object. |
42
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
=head4 default |
44
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
Default value to use for the mode. |
46
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
If not specified, it defaults to '0644'. |
48
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
$foo=Sys::Config::Manage::Perms->new(\%args); |
50
|
|
|
|
|
|
|
if($foo->error){ |
51
|
|
|
|
|
|
|
warn('error:'.$foo->error.': '.$foo->errorString); |
52
|
|
|
|
|
|
|
} |
53
|
|
|
|
|
|
|
|
54
|
|
|
|
|
|
|
=cut |
55
|
|
|
|
|
|
|
|
56
|
|
|
|
|
|
|
sub new{ |
57
|
0
|
|
|
0
|
1
|
|
my %args; |
58
|
0
|
0
|
|
|
|
|
if(defined($_[1])){ |
59
|
0
|
|
|
|
|
|
%args= %{$_[1]}; |
|
0
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
}; |
61
|
0
|
|
|
|
|
|
my $method='new'; |
62
|
|
|
|
|
|
|
|
63
|
0
|
|
|
|
|
|
my $self = { |
64
|
|
|
|
|
|
|
module=>'Sys-Config-Manage-Perms', |
65
|
|
|
|
|
|
|
perror=>undef, |
66
|
|
|
|
|
|
|
error=>undef, |
67
|
|
|
|
|
|
|
errorString=>"", |
68
|
|
|
|
|
|
|
default=>'0644', |
69
|
|
|
|
|
|
|
}; |
70
|
0
|
|
|
|
|
|
bless $self; |
71
|
|
|
|
|
|
|
|
72
|
|
|
|
|
|
|
#make sure we have a Sys::Config::Manage |
73
|
0
|
0
|
|
|
|
|
if(!defined( $args{scm} ) ){ |
74
|
0
|
|
|
|
|
|
$self->{perror}=1; |
75
|
0
|
|
|
|
|
|
$self->{error}=1; |
76
|
0
|
|
|
|
|
|
$self->{errorString}='Nothing passed for the Sys::Config::Manage object'; |
77
|
0
|
|
|
|
|
|
$self->warn; |
78
|
0
|
|
|
|
|
|
return $self; |
79
|
|
|
|
|
|
|
} |
80
|
|
|
|
|
|
|
|
81
|
|
|
|
|
|
|
#make sure that it is really a Sys::Config::Manage object |
82
|
0
|
0
|
|
|
|
|
if( ref( $args{scm} ) ne "Sys::Config::Manage" ){ |
83
|
0
|
|
|
|
|
|
$self->{perror}=1; |
84
|
0
|
|
|
|
|
|
$self->{error}=2; |
85
|
0
|
|
|
|
|
|
$self->{errorString}='$args{scm} is not a Sys::Config::Manage object'; |
86
|
0
|
|
|
|
|
|
$self->warn; |
87
|
0
|
|
|
|
|
|
return $self; |
88
|
|
|
|
|
|
|
} |
89
|
|
|
|
|
|
|
|
90
|
|
|
|
|
|
|
#figures out what the defualt is |
91
|
0
|
0
|
|
|
|
|
if ( defined( $args{default} ) ){ |
92
|
|
|
|
|
|
|
#make sure the perms are sane |
93
|
0
|
0
|
|
|
|
|
if ( $args{default} !~ /^[01246][01234567][01234567][01234567]$/ ){ |
94
|
0
|
|
|
|
|
|
$self->{perror}=1; |
95
|
0
|
|
|
|
|
|
$self->{error}=12; |
96
|
0
|
|
|
|
|
|
$self->{errorString}='"'.$args{default}.'" does not appear to be a valid value'; |
97
|
0
|
|
|
|
|
|
$self->warn; |
98
|
0
|
|
|
|
|
|
return $self; |
99
|
|
|
|
|
|
|
} |
100
|
0
|
|
|
|
|
|
$self->{default}=$args{default}; |
101
|
|
|
|
|
|
|
} |
102
|
|
|
|
|
|
|
|
103
|
0
|
|
|
|
|
|
$self->{scm}=$args{scm}; |
104
|
|
|
|
|
|
|
|
105
|
0
|
|
|
|
|
|
return $self; |
106
|
|
|
|
|
|
|
} |
107
|
|
|
|
|
|
|
|
108
|
|
|
|
|
|
|
=head2 downSync |
109
|
|
|
|
|
|
|
|
110
|
|
|
|
|
|
|
This syncs the file permissions down from the configuration |
111
|
|
|
|
|
|
|
directory to the system. |
112
|
|
|
|
|
|
|
|
113
|
|
|
|
|
|
|
Two arguments can be used. |
114
|
|
|
|
|
|
|
|
115
|
|
|
|
|
|
|
The first is the configuration directory. If not specified, it will |
116
|
|
|
|
|
|
|
be automaticallly choosen. |
117
|
|
|
|
|
|
|
|
118
|
|
|
|
|
|
|
The second is the files to sync. If not specifiedm, all files will |
119
|
|
|
|
|
|
|
be synced. |
120
|
|
|
|
|
|
|
|
121
|
|
|
|
|
|
|
#sync the specified files |
122
|
|
|
|
|
|
|
$foo->downSync( $configDir, \@files); |
123
|
|
|
|
|
|
|
if($foo->error){ |
124
|
|
|
|
|
|
|
warn('error:'.$foo->error.': '.$foo->errorString); |
125
|
|
|
|
|
|
|
} |
126
|
|
|
|
|
|
|
|
127
|
|
|
|
|
|
|
#syncs all the files |
128
|
|
|
|
|
|
|
$foo->downSync( $configDir ); |
129
|
|
|
|
|
|
|
if($foo->error){ |
130
|
|
|
|
|
|
|
warn('error:'.$foo->error.': '.$foo->errorString); |
131
|
|
|
|
|
|
|
} |
132
|
|
|
|
|
|
|
|
133
|
|
|
|
|
|
|
=cut |
134
|
|
|
|
|
|
|
|
135
|
|
|
|
|
|
|
sub downSync{ |
136
|
0
|
|
|
0
|
1
|
|
my $self=$_[0]; |
137
|
0
|
|
|
|
|
|
my $configDir=$_[1]; |
138
|
0
|
|
|
|
|
|
my @files; |
139
|
0
|
0
|
|
|
|
|
if (defined($_[2])) { |
140
|
0
|
|
|
|
|
|
@files=@{$_[2]}; |
|
0
|
|
|
|
|
|
|
141
|
|
|
|
|
|
|
} |
142
|
0
|
|
|
|
|
|
my $method='downSync'; |
143
|
|
|
|
|
|
|
|
144
|
|
|
|
|
|
|
#blank any previous errors |
145
|
0
|
0
|
|
|
|
|
if (!$self->errorblank) { |
146
|
0
|
|
|
|
|
|
return undef; |
147
|
|
|
|
|
|
|
} |
148
|
|
|
|
|
|
|
|
149
|
|
|
|
|
|
|
#make sure we have a directory to use |
150
|
0
|
0
|
|
|
|
|
if (!defined($configDir)) { |
151
|
0
|
|
|
|
|
|
$configDir=$self->{scm}->selectConfigDir; |
152
|
0
|
0
|
|
|
|
|
if ($self->{scm}->error) { |
153
|
0
|
|
|
|
|
|
$self->{error}=5; |
154
|
0
|
|
|
|
|
|
$self->{errorString}='Sys::Config::Manage->selectConfigDir errored error="'. |
155
|
|
|
|
|
|
|
$self->{scm}->error.'" errorString="'.$self->{scm}->errorString.'"'; |
156
|
0
|
|
|
|
|
|
$self->warn; |
157
|
0
|
|
|
|
|
|
return undef; |
158
|
|
|
|
|
|
|
} |
159
|
|
|
|
|
|
|
} |
160
|
|
|
|
|
|
|
|
161
|
|
|
|
|
|
|
#make sure the config directory is valid |
162
|
0
|
|
|
|
|
|
my $valid=$self->{scm}->validConfigDirName($configDir); |
163
|
0
|
0
|
|
|
|
|
if ($self->{scm}->error) { |
164
|
0
|
|
|
|
|
|
$self->{error}=6; |
165
|
0
|
|
|
|
|
|
$self->{errorString}='Sys::Config::Manage->validConfigDirName errored error="'. |
166
|
|
|
|
|
|
|
$self->{scm}->error.'" errorString="'.$self->{scm}->errorString.'"'; |
167
|
0
|
|
|
|
|
|
$self->warn; |
168
|
0
|
|
|
|
|
|
return undef; |
169
|
|
|
|
|
|
|
} |
170
|
0
|
0
|
|
|
|
|
if (defined( $valid )) { |
171
|
0
|
|
|
|
|
|
$self->{error}=3; |
172
|
0
|
|
|
|
|
|
$self->{errorString}='The configuration directory name '.$valid; |
173
|
0
|
|
|
|
|
|
$self->warn; |
174
|
0
|
|
|
|
|
|
return undef; |
175
|
|
|
|
|
|
|
} |
176
|
|
|
|
|
|
|
|
177
|
|
|
|
|
|
|
#makes sure it exists |
178
|
0
|
0
|
|
|
|
|
if ( ! -d $self->{scm}->{baseDir}.'/'.$configDir ) { |
179
|
0
|
|
|
|
|
|
$self->{error}=4; |
180
|
0
|
|
|
|
|
|
$self->{errorString}='The configuration directory, "'.$self->{baseDir}.'/'.$configDir.'", does not exist'; |
181
|
0
|
|
|
|
|
|
$self->warn; |
182
|
0
|
|
|
|
|
|
return undef; |
183
|
|
|
|
|
|
|
} |
184
|
|
|
|
|
|
|
|
185
|
|
|
|
|
|
|
#checks and make sure all the files exist |
186
|
0
|
|
|
|
|
|
my $int=0; |
187
|
0
|
0
|
|
|
|
|
if(defined( $files[$int] )){ |
188
|
0
|
|
|
|
|
|
my @allfiles=$self->{scm}->listConfigFiles($configDir); |
189
|
0
|
0
|
|
|
|
|
if( $self->{scm}->error ){ |
190
|
0
|
|
|
|
|
|
$self->{error}='16'; |
191
|
0
|
|
|
|
|
|
$self->{errorString}='Sys::Config::Manage->listConfigFiles errored error="'. |
192
|
|
|
|
|
|
|
$self->{scm}->error.'" errorString="'.$self->{scm}->errorString.'"'; |
193
|
0
|
|
|
|
|
|
$self->warn; |
194
|
0
|
|
|
|
|
|
return undef; |
195
|
|
|
|
|
|
|
} |
196
|
|
|
|
|
|
|
|
197
|
|
|
|
|
|
|
#make sure each file asked to be synced is tracked |
198
|
0
|
|
|
|
|
|
while(defined( $files[$int] )){ |
199
|
|
|
|
|
|
|
|
200
|
0
|
|
|
|
|
|
my $matched=0; |
201
|
0
|
|
|
|
|
|
my $int2=0; |
202
|
0
|
|
|
|
|
|
while(defined( $allfiles[$int2] )){ |
203
|
0
|
0
|
|
|
|
|
if( $files[$int] eq $allfiles[$int2] ){ |
204
|
0
|
|
|
|
|
|
$matched=1; |
205
|
|
|
|
|
|
|
} |
206
|
|
|
|
|
|
|
|
207
|
0
|
|
|
|
|
|
$int2++; |
208
|
|
|
|
|
|
|
} |
209
|
|
|
|
|
|
|
|
210
|
0
|
0
|
|
|
|
|
if(! $matched){ |
211
|
0
|
|
|
|
|
|
$self->{error}='8'; |
212
|
0
|
|
|
|
|
|
$self->{errorString}='"'.$files[$int].'" does not exist under the configuration directory, "'.$configDir.'",'; |
213
|
0
|
|
|
|
|
|
$self->warn; |
214
|
0
|
|
|
|
|
|
return undef; |
215
|
|
|
|
|
|
|
} |
216
|
|
|
|
|
|
|
|
217
|
0
|
|
|
|
|
|
$int++; |
218
|
|
|
|
|
|
|
} |
219
|
|
|
|
|
|
|
|
220
|
|
|
|
|
|
|
}else{ |
221
|
|
|
|
|
|
|
#if we get here, no files have been specified so we do them all |
222
|
0
|
|
|
|
|
|
@files=$self->{scm}->listConfigFiles($configDir); |
223
|
0
|
0
|
|
|
|
|
if( $self->{scm}->error ){ |
224
|
0
|
|
|
|
|
|
$self->{error}='16'; |
225
|
0
|
|
|
|
|
|
$self->{errorString}='Sys::Config::Manage->listConfigFiles errored error="'. |
226
|
|
|
|
|
|
|
$self->{scm}->error.'" errorString="'.$self->{scm}->errorString.'"'; |
227
|
0
|
|
|
|
|
|
$self->warn; |
228
|
0
|
|
|
|
|
|
return undef; |
229
|
|
|
|
|
|
|
} |
230
|
|
|
|
|
|
|
} |
231
|
|
|
|
|
|
|
|
232
|
|
|
|
|
|
|
#process each file |
233
|
0
|
|
|
|
|
|
$int=0; |
234
|
0
|
|
|
|
|
|
while( defined( $files[$int] ) ){ |
235
|
|
|
|
|
|
|
#get the perms for the file we will set it on |
236
|
0
|
|
|
|
|
|
my $perms=$self->getPerms( $configDir, $files[$int] ); |
237
|
0
|
0
|
|
|
|
|
if( $self->error ){ |
238
|
0
|
|
|
|
|
|
warn($self->{module}.' '.$method.': Sys::Config::Manage::Perms->getPerms errored'); |
239
|
0
|
|
|
|
|
|
return undef; |
240
|
|
|
|
|
|
|
} |
241
|
|
|
|
|
|
|
|
242
|
|
|
|
|
|
|
#try to chmod it |
243
|
0
|
0
|
|
|
|
|
if(!chmod( oct($perms), $files[$int] )){ |
244
|
0
|
|
|
|
|
|
$self->{error}='17'; |
245
|
0
|
|
|
|
|
|
$self->{errorString}='chmod( '.$perms.', "'.$files[$int].'") errored'; |
246
|
0
|
|
|
|
|
|
$self->warn; |
247
|
0
|
|
|
|
|
|
return undef; |
248
|
|
|
|
|
|
|
} |
249
|
|
|
|
|
|
|
|
250
|
0
|
|
|
|
|
|
$int++; |
251
|
|
|
|
|
|
|
} |
252
|
|
|
|
|
|
|
|
253
|
0
|
|
|
|
|
|
return 1; |
254
|
|
|
|
|
|
|
} |
255
|
|
|
|
|
|
|
|
256
|
|
|
|
|
|
|
=head2 getPerms |
257
|
|
|
|
|
|
|
|
258
|
|
|
|
|
|
|
This retrieves the mode for a file. |
259
|
|
|
|
|
|
|
|
260
|
|
|
|
|
|
|
Two arguments are taken.The first is the configuration directory, |
261
|
|
|
|
|
|
|
which if not defined is automatically chosen. The second is the |
262
|
|
|
|
|
|
|
file in question. |
263
|
|
|
|
|
|
|
|
264
|
|
|
|
|
|
|
my $mode=$foo->getPerms( $configDir, $file ); |
265
|
|
|
|
|
|
|
if($foo->error){ |
266
|
|
|
|
|
|
|
warn('error:'.$foo->error.': '.$foo->errorString); |
267
|
|
|
|
|
|
|
} |
268
|
|
|
|
|
|
|
|
269
|
|
|
|
|
|
|
=cut |
270
|
|
|
|
|
|
|
|
271
|
|
|
|
|
|
|
sub getPerms{ |
272
|
0
|
|
|
0
|
1
|
|
my $self=$_[0]; |
273
|
0
|
|
|
|
|
|
my $configDir=$_[1]; |
274
|
0
|
|
|
|
|
|
my $file=$_[2]; |
275
|
0
|
|
|
|
|
|
my $method='getPerms'; |
276
|
|
|
|
|
|
|
|
277
|
|
|
|
|
|
|
#blank any previous errors |
278
|
0
|
0
|
|
|
|
|
if (!$self->errorblank) { |
279
|
0
|
|
|
|
|
|
return undef; |
280
|
|
|
|
|
|
|
} |
281
|
|
|
|
|
|
|
|
282
|
|
|
|
|
|
|
#make sure we have a directory to use |
283
|
0
|
0
|
|
|
|
|
if (!defined($configDir)) { |
284
|
0
|
|
|
|
|
|
$configDir=$self->{scm}->selectConfigDir; |
285
|
0
|
0
|
|
|
|
|
if ($self->{scm}->error) { |
286
|
0
|
|
|
|
|
|
$self->{error}=5; |
287
|
0
|
|
|
|
|
|
$self->{errorString}='Sys::Config::Manage->selectConfigDir errored error="'. |
288
|
|
|
|
|
|
|
$self->{scm}->error.'" errorString="'.$self->{scm}->errorString.'"'; |
289
|
0
|
|
|
|
|
|
$self->warn; |
290
|
0
|
|
|
|
|
|
return undef; |
291
|
|
|
|
|
|
|
} |
292
|
|
|
|
|
|
|
} |
293
|
|
|
|
|
|
|
|
294
|
|
|
|
|
|
|
#make sure the config directory is valid |
295
|
0
|
|
|
|
|
|
my $valid=$self->{scm}->validConfigDirName($configDir); |
296
|
0
|
0
|
|
|
|
|
if ($self->{scm}->error) { |
297
|
0
|
|
|
|
|
|
$self->{error}=6; |
298
|
0
|
|
|
|
|
|
$self->{errorString}='Sys::Config::Manage->validConfigDirName errored error="'. |
299
|
|
|
|
|
|
|
$self->{scm}->error.'" errorString="'.$self->{scm}->errorString.'"'; |
300
|
0
|
|
|
|
|
|
$self->warn; |
301
|
0
|
|
|
|
|
|
return undef; |
302
|
|
|
|
|
|
|
} |
303
|
0
|
0
|
|
|
|
|
if (defined( $valid )) { |
304
|
0
|
|
|
|
|
|
$self->{error}=3; |
305
|
0
|
|
|
|
|
|
$self->{errorString}='The configuration directory name '.$valid; |
306
|
0
|
|
|
|
|
|
$self->warn; |
307
|
0
|
|
|
|
|
|
return undef; |
308
|
|
|
|
|
|
|
} |
309
|
|
|
|
|
|
|
|
310
|
|
|
|
|
|
|
#makes sure it exists |
311
|
0
|
0
|
|
|
|
|
if ( ! -d $self->{scm}->{baseDir}.'/'.$configDir ) { |
312
|
0
|
|
|
|
|
|
$self->{error}=4; |
313
|
0
|
|
|
|
|
|
$self->{errorString}='The configuration directory, "'.$self->{baseDir}.'/'.$configDir.'", does not exist'; |
314
|
0
|
|
|
|
|
|
$self->warn; |
315
|
0
|
|
|
|
|
|
return undef; |
316
|
|
|
|
|
|
|
} |
317
|
|
|
|
|
|
|
|
318
|
|
|
|
|
|
|
#make value for the file is specified |
319
|
0
|
0
|
|
|
|
|
if (!defined( $file )) { |
320
|
0
|
|
|
|
|
|
$self->{error}=7; |
321
|
0
|
|
|
|
|
|
$self->{errorString}='No file specified'; |
322
|
0
|
|
|
|
|
|
$self->warn; |
323
|
0
|
|
|
|
|
|
return undef; |
324
|
|
|
|
|
|
|
} |
325
|
|
|
|
|
|
|
|
326
|
|
|
|
|
|
|
#make sure the file exists, under the config dir |
327
|
0
|
0
|
|
|
|
|
if (! -f $self->{scm}->{baseDir}.'/'.$configDir.'/'.$file ) { |
328
|
0
|
|
|
|
|
|
$self->{error}=8; |
329
|
0
|
|
|
|
|
|
$self->{errorString}='The file does not exist in the configuration directory'; |
330
|
0
|
|
|
|
|
|
$self->warn; |
331
|
0
|
|
|
|
|
|
return undef; |
332
|
|
|
|
|
|
|
} |
333
|
|
|
|
|
|
|
|
334
|
|
|
|
|
|
|
#figure out what the perms file is |
335
|
0
|
|
|
|
|
|
my ($name,$path,$suffix) = fileparse($file); |
336
|
0
|
|
|
|
|
|
my $permsfile=$self->{scm}->{baseDir}.'/'.$configDir.'/'.$path.'/.SysConfigManage/Perms/'.$name; |
337
|
|
|
|
|
|
|
|
338
|
|
|
|
|
|
|
#make sure the file has some perms |
339
|
0
|
0
|
|
|
|
|
if (! -f $permsfile ){ |
340
|
0
|
|
|
|
|
|
return $self->{default}; |
341
|
|
|
|
|
|
|
} |
342
|
|
|
|
|
|
|
|
343
|
|
|
|
|
|
|
#read the file |
344
|
0
|
|
|
|
|
|
my $fh; |
345
|
0
|
0
|
|
|
|
|
if ( ! open( $fh, '<', $permsfile ) ){ |
346
|
0
|
|
|
|
|
|
$self->{error}=15; |
347
|
0
|
|
|
|
|
|
$self->{errorString}='Unable to open "'.$permsfile.'"'; |
348
|
0
|
|
|
|
|
|
$self->warn; |
349
|
0
|
|
|
|
|
|
return undef; |
350
|
|
|
|
|
|
|
} |
351
|
0
|
|
|
|
|
|
my $perms=<$fh>; |
352
|
0
|
|
|
|
|
|
chomp($perms); |
353
|
0
|
|
|
|
|
|
close( $fh ); |
354
|
|
|
|
|
|
|
|
355
|
0
|
|
|
|
|
|
return $perms; |
356
|
|
|
|
|
|
|
} |
357
|
|
|
|
|
|
|
|
358
|
|
|
|
|
|
|
=head2 listConfigFiles |
359
|
|
|
|
|
|
|
|
360
|
|
|
|
|
|
|
This lists the various config files that are being |
361
|
|
|
|
|
|
|
tracked that actually have a value specified. |
362
|
|
|
|
|
|
|
|
363
|
|
|
|
|
|
|
Not all files returned by Sys::Config::Manage->listConfigFiles |
364
|
|
|
|
|
|
|
will have a value specified. |
365
|
|
|
|
|
|
|
|
366
|
|
|
|
|
|
|
my @files=$foo->listConfigFiles; |
367
|
|
|
|
|
|
|
if($foo->error){ |
368
|
|
|
|
|
|
|
warn('error:'.$foo->error.': '.$foo->errorString); |
369
|
|
|
|
|
|
|
} |
370
|
|
|
|
|
|
|
|
371
|
|
|
|
|
|
|
=cut |
372
|
|
|
|
|
|
|
|
373
|
|
|
|
|
|
|
sub listConfigFiles{ |
374
|
0
|
|
|
0
|
1
|
|
my $self=$_[0]; |
375
|
0
|
|
|
|
|
|
my $configDir=$_[1]; |
376
|
0
|
|
|
|
|
|
my $method='listConfigFiles'; |
377
|
|
|
|
|
|
|
|
378
|
|
|
|
|
|
|
#blank any previous errors |
379
|
0
|
0
|
|
|
|
|
if (!$self->errorblank) { |
380
|
0
|
|
|
|
|
|
return undef; |
381
|
|
|
|
|
|
|
} |
382
|
|
|
|
|
|
|
|
383
|
|
|
|
|
|
|
#make sure we have a directory to use |
384
|
0
|
0
|
|
|
|
|
if (!defined($configDir)) { |
385
|
0
|
|
|
|
|
|
$configDir=$self->{scm}->selectConfigDir; |
386
|
0
|
0
|
|
|
|
|
if ($self->{scm}->error) { |
387
|
0
|
|
|
|
|
|
$self->{error}=5; |
388
|
0
|
|
|
|
|
|
$self->{errorString}='Sys::Config::Manage->selectConfigDir errored error="'. |
389
|
|
|
|
|
|
|
$self->{scm}->error.'" errorString="'.$self->{scm}->errorString.'"'; |
390
|
0
|
|
|
|
|
|
$self->warn; |
391
|
0
|
|
|
|
|
|
return undef; |
392
|
|
|
|
|
|
|
} |
393
|
|
|
|
|
|
|
} |
394
|
|
|
|
|
|
|
|
395
|
|
|
|
|
|
|
#make sure the config directory is valid |
396
|
0
|
|
|
|
|
|
my $valid=$self->{scm}->validConfigDirName($configDir); |
397
|
0
|
0
|
|
|
|
|
if ($self->{scm}->error) { |
398
|
0
|
|
|
|
|
|
$self->{error}=6; |
399
|
0
|
|
|
|
|
|
$self->{errorString}='Sys::Config::Manage->validConfigDirName errored error="'. |
400
|
|
|
|
|
|
|
$self->{scm}->error.'" errorString="'.$self->{scm}->errorString.'"'; |
401
|
0
|
|
|
|
|
|
$self->warn; |
402
|
0
|
|
|
|
|
|
return undef; |
403
|
|
|
|
|
|
|
} |
404
|
0
|
0
|
|
|
|
|
if (defined( $valid )) { |
405
|
0
|
|
|
|
|
|
$self->{error}=3; |
406
|
0
|
|
|
|
|
|
$self->{errorString}='The configuration directory name '.$valid; |
407
|
0
|
|
|
|
|
|
$self->warn; |
408
|
0
|
|
|
|
|
|
return undef; |
409
|
|
|
|
|
|
|
} |
410
|
|
|
|
|
|
|
|
411
|
|
|
|
|
|
|
#makes sure it exists |
412
|
0
|
0
|
|
|
|
|
if ( ! -d $self->{scm}->{baseDir}.'/'.$configDir ) { |
413
|
0
|
|
|
|
|
|
$self->{error}=4; |
414
|
0
|
|
|
|
|
|
$self->{errorString}='The configuration directory, "'.$self->{baseDir}.'/'.$configDir.'", does not exist'; |
415
|
0
|
|
|
|
|
|
$self->warn; |
416
|
0
|
|
|
|
|
|
return undef; |
417
|
|
|
|
|
|
|
} |
418
|
|
|
|
|
|
|
|
419
|
|
|
|
|
|
|
#holds what will be returned |
420
|
0
|
|
|
|
|
|
my @found; |
421
|
|
|
|
|
|
|
|
422
|
|
|
|
|
|
|
#get a list of files |
423
|
0
|
|
|
|
|
|
my @files=$self->{scm}->listConfigFiles($configDir); |
424
|
|
|
|
|
|
|
|
425
|
|
|
|
|
|
|
|
426
|
|
|
|
|
|
|
#process every found file |
427
|
0
|
|
|
|
|
|
my $int=0; |
428
|
0
|
|
|
|
|
|
while (defined( $files[$int] )) { |
429
|
0
|
|
|
|
|
|
my ($name,$path,$suffix)=fileparse($self->{scm}->{baseDir} |
430
|
|
|
|
|
|
|
.'/'.$configDir.'/'.$files[$int]); |
431
|
|
|
|
|
|
|
|
432
|
|
|
|
|
|
|
|
433
|
0
|
|
|
|
|
|
my $permsFile=$path.'/.SysConfigManage/Perms/'.$name; |
434
|
0
|
|
|
|
|
|
$permsFile=~s/\/\/*/\//g; |
435
|
|
|
|
|
|
|
|
436
|
|
|
|
|
|
|
#make sure the perms file exists and if so add it |
437
|
0
|
0
|
|
|
|
|
if ( -f $permsFile ) { |
438
|
0
|
|
|
|
|
|
push(@found, $files[$int]); |
439
|
|
|
|
|
|
|
} |
440
|
|
|
|
|
|
|
|
441
|
0
|
|
|
|
|
|
$int++; |
442
|
|
|
|
|
|
|
} |
443
|
|
|
|
|
|
|
|
444
|
0
|
|
|
|
|
|
return @found; |
445
|
|
|
|
|
|
|
} |
446
|
|
|
|
|
|
|
|
447
|
|
|
|
|
|
|
=head2 setPerms |
448
|
|
|
|
|
|
|
|
449
|
|
|
|
|
|
|
This sets the permissions for a file. This does require the numeric value. |
450
|
|
|
|
|
|
|
|
451
|
|
|
|
|
|
|
Three arguments are taken. |
452
|
|
|
|
|
|
|
|
453
|
|
|
|
|
|
|
The first one is the configuration directory to use. If none is |
454
|
|
|
|
|
|
|
specified, it will automatically be choosen. |
455
|
|
|
|
|
|
|
|
456
|
|
|
|
|
|
|
The second is the config file to add the perms for. |
457
|
|
|
|
|
|
|
|
458
|
|
|
|
|
|
|
The third numeric value for the permissions. |
459
|
|
|
|
|
|
|
|
460
|
|
|
|
|
|
|
$foo->setPerms($configDir, $file, '0640'); |
461
|
|
|
|
|
|
|
if($foo->error){ |
462
|
|
|
|
|
|
|
warn('error:'.$foo->error.': '.$foo->errorString); |
463
|
|
|
|
|
|
|
} |
464
|
|
|
|
|
|
|
|
465
|
|
|
|
|
|
|
=cut |
466
|
|
|
|
|
|
|
|
467
|
|
|
|
|
|
|
sub setPerms{ |
468
|
0
|
|
|
0
|
1
|
|
my $self=$_[0]; |
469
|
0
|
|
|
|
|
|
my $configDir=$_[1]; |
470
|
0
|
|
|
|
|
|
my $file=$_[2]; |
471
|
0
|
|
|
|
|
|
my $perms=$_[3]; |
472
|
0
|
|
|
|
|
|
my $method='setPerms'; |
473
|
|
|
|
|
|
|
|
474
|
|
|
|
|
|
|
#blank any previous errors |
475
|
0
|
0
|
|
|
|
|
if (!$self->errorblank) { |
476
|
0
|
|
|
|
|
|
return undef; |
477
|
|
|
|
|
|
|
} |
478
|
|
|
|
|
|
|
|
479
|
|
|
|
|
|
|
#make sure we have a directory to use |
480
|
0
|
0
|
|
|
|
|
if (!defined($configDir)) { |
481
|
0
|
|
|
|
|
|
$configDir=$self->{scm}->selectConfigDir; |
482
|
0
|
0
|
|
|
|
|
if ($self->{scm}->error) { |
483
|
0
|
|
|
|
|
|
$self->{error}=5; |
484
|
0
|
|
|
|
|
|
$self->{errorString}='Sys::Config::Manage->selectConfigDir errored error="'. |
485
|
|
|
|
|
|
|
$self->{scm}->error.'" errorString="'.$self->{scm}->errorString.'"'; |
486
|
0
|
|
|
|
|
|
$self->warn; |
487
|
0
|
|
|
|
|
|
return undef; |
488
|
|
|
|
|
|
|
} |
489
|
|
|
|
|
|
|
} |
490
|
|
|
|
|
|
|
|
491
|
|
|
|
|
|
|
#make sure the config directory is valid |
492
|
0
|
|
|
|
|
|
my $valid=$self->{scm}->validConfigDirName($configDir); |
493
|
0
|
0
|
|
|
|
|
if ($self->{scm}->error) { |
494
|
0
|
|
|
|
|
|
$self->{error}=6; |
495
|
0
|
|
|
|
|
|
$self->{errorString}='Sys::Config::Manage->validConfigDirName errored error="'. |
496
|
|
|
|
|
|
|
$self->{scm}->error.'" errorString="'.$self->{scm}->errorString.'"'; |
497
|
0
|
|
|
|
|
|
$self->warn; |
498
|
0
|
|
|
|
|
|
return undef; |
499
|
|
|
|
|
|
|
} |
500
|
0
|
0
|
|
|
|
|
if (defined( $valid )) { |
501
|
0
|
|
|
|
|
|
$self->{error}=3; |
502
|
0
|
|
|
|
|
|
$self->{errorString}='The configuration directory name '.$valid; |
503
|
0
|
|
|
|
|
|
$self->warn; |
504
|
0
|
|
|
|
|
|
return undef; |
505
|
|
|
|
|
|
|
} |
506
|
|
|
|
|
|
|
|
507
|
|
|
|
|
|
|
#makes sure it exists |
508
|
0
|
0
|
|
|
|
|
if ( ! -d $self->{scm}->{baseDir}.'/'.$configDir ) { |
509
|
0
|
|
|
|
|
|
$self->{error}=4; |
510
|
0
|
|
|
|
|
|
$self->{errorString}='The configuration directory, "'.$self->{baseDir}.'/'.$configDir.'", does not exist'; |
511
|
0
|
|
|
|
|
|
$self->warn; |
512
|
0
|
|
|
|
|
|
return undef; |
513
|
|
|
|
|
|
|
} |
514
|
|
|
|
|
|
|
|
515
|
|
|
|
|
|
|
#make value for the file is specified |
516
|
0
|
0
|
|
|
|
|
if (!defined( $file )) { |
517
|
0
|
|
|
|
|
|
$self->{error}=7; |
518
|
0
|
|
|
|
|
|
$self->{errorString}='No file specified'; |
519
|
0
|
|
|
|
|
|
$self->warn; |
520
|
0
|
|
|
|
|
|
return undef; |
521
|
|
|
|
|
|
|
} |
522
|
|
|
|
|
|
|
|
523
|
|
|
|
|
|
|
#make sure the file exists, under the config dir |
524
|
0
|
0
|
|
|
|
|
if (! -f $self->{scm}->{baseDir}.'/'.$configDir.'/'.$file ) { |
525
|
0
|
|
|
|
|
|
$self->{error}=8; |
526
|
0
|
|
|
|
|
|
$self->{errorString}='The file does not exist in the configuration directory'; |
527
|
0
|
|
|
|
|
|
$self->warn; |
528
|
0
|
|
|
|
|
|
return undef; |
529
|
|
|
|
|
|
|
} |
530
|
|
|
|
|
|
|
|
531
|
|
|
|
|
|
|
#make sure we have a some perms passed |
532
|
0
|
0
|
|
|
|
|
if ( ! defined( $perms ) ){ |
533
|
0
|
|
|
|
|
|
$self->{error}=11; |
534
|
0
|
|
|
|
|
|
$self->{errorString}='No value for the permissions specified'; |
535
|
0
|
|
|
|
|
|
$self->warn; |
536
|
0
|
|
|
|
|
|
return undef; |
537
|
|
|
|
|
|
|
} |
538
|
|
|
|
|
|
|
|
539
|
|
|
|
|
|
|
#make sure the perms are sane |
540
|
0
|
0
|
|
|
|
|
if ( $perms !~ /^[01246][01234567][01234567][01234567]$/ ){ |
541
|
0
|
|
|
|
|
|
$self->{error}=12; |
542
|
0
|
|
|
|
|
|
$self->{errorString}='"'.$perms.'" does not appear to be a valid value'; |
543
|
0
|
|
|
|
|
|
warn($self->{module}.' '.$method.':'.$self->error.': '.$self->errorString); |
544
|
0
|
|
|
|
|
|
return undef; |
545
|
|
|
|
|
|
|
} |
546
|
|
|
|
|
|
|
|
547
|
|
|
|
|
|
|
#creates the .SysConfigManage if needed |
548
|
0
|
|
|
|
|
|
my ($name,$path,$suffix) = fileparse($file); |
549
|
0
|
|
|
|
|
|
my $scmd=$self->{scm}->{baseDir}.'/'.$configDir.'/'.$path.'/.SysConfigManage'; |
550
|
0
|
0
|
|
|
|
|
if ( ! -d $scmd ){ |
551
|
0
|
0
|
|
|
|
|
if ( ! mkdir( $scmd ) ){ |
552
|
0
|
|
|
|
|
|
$self->{error}=13; |
553
|
0
|
|
|
|
|
|
$self->{errorString}='Unable to create "'.$scmd.'"'; |
554
|
0
|
|
|
|
|
|
$self->warn; |
555
|
0
|
|
|
|
|
|
return undef; |
556
|
|
|
|
|
|
|
} |
557
|
|
|
|
|
|
|
} |
558
|
|
|
|
|
|
|
|
559
|
|
|
|
|
|
|
#makes sure that the perms dir exists |
560
|
0
|
|
|
|
|
|
my $permsdir=$scmd.'/Perms'; |
561
|
0
|
0
|
|
|
|
|
if ( ! -d $permsdir ){ |
562
|
0
|
0
|
|
|
|
|
if ( ! mkdir( $permsdir ) ){ |
563
|
0
|
|
|
|
|
|
$self->{error}=14; |
564
|
0
|
|
|
|
|
|
$self->{errorString}='Unable to create "'.$permsdir.'"'; |
565
|
0
|
|
|
|
|
|
$self->warn; |
566
|
0
|
|
|
|
|
|
return undef; |
567
|
|
|
|
|
|
|
} |
568
|
|
|
|
|
|
|
} |
569
|
|
|
|
|
|
|
|
570
|
|
|
|
|
|
|
#this is the file that will store the perms |
571
|
0
|
|
|
|
|
|
my $permsfile=$permsdir.'/'.$name; |
572
|
|
|
|
|
|
|
|
573
|
|
|
|
|
|
|
#check if it exists |
574
|
0
|
|
|
|
|
|
my $exists=0; |
575
|
0
|
0
|
|
|
|
|
if ( -f $permsfile ){ |
576
|
0
|
|
|
|
|
|
$exists=1; |
577
|
|
|
|
|
|
|
} |
578
|
|
|
|
|
|
|
|
579
|
0
|
|
|
|
|
|
my $fh; |
580
|
0
|
0
|
|
|
|
|
if ( ! open( $fh, '>', $permsfile ) ){ |
581
|
0
|
|
|
|
|
|
$self->{error}=15; |
582
|
0
|
|
|
|
|
|
$self->{errorString}='Unable to open "'.$permsfile.'"'; |
583
|
0
|
|
|
|
|
|
$self->warn; |
584
|
0
|
|
|
|
|
|
return undef; |
585
|
|
|
|
|
|
|
} |
586
|
0
|
|
|
|
|
|
print $fh $perms; |
587
|
0
|
|
|
|
|
|
close( $fh ); |
588
|
|
|
|
|
|
|
|
589
|
|
|
|
|
|
|
#add it if it, if it did not exist previously |
590
|
0
|
0
|
|
|
|
|
if ( ! $exists ){ |
591
|
0
|
0
|
|
|
|
|
if (defined( $self->{scm}->{addCommand} )) { |
592
|
0
|
|
|
|
|
|
my $command=$self->{scm}->{addCommand}; |
593
|
0
|
|
|
|
|
|
my $newfile=shell_quote($permsfile); |
594
|
|
|
|
|
|
|
|
595
|
0
|
|
|
|
|
|
$command=~s/\%\%\%file\%\%\%/$newfile/g; |
596
|
0
|
|
|
|
|
|
system($command); |
597
|
0
|
|
|
|
|
|
my $exit = $?<<8; |
598
|
0
|
0
|
|
|
|
|
if ($exit ne '0') { |
599
|
0
|
|
|
|
|
|
$self->{error}=16; |
600
|
0
|
|
|
|
|
|
$self->{errorString}='The add command failed. command="'.$command.'" exit="'.$exit.'"'; |
601
|
0
|
|
|
|
|
|
$self->warn; |
602
|
0
|
|
|
|
|
|
return undef; |
603
|
|
|
|
|
|
|
} |
604
|
|
|
|
|
|
|
} |
605
|
|
|
|
|
|
|
} |
606
|
|
|
|
|
|
|
|
607
|
0
|
|
|
|
|
|
return 1; |
608
|
|
|
|
|
|
|
} |
609
|
|
|
|
|
|
|
|
610
|
|
|
|
|
|
|
=head2 setPermsFromFile |
611
|
|
|
|
|
|
|
|
612
|
|
|
|
|
|
|
This sets the permissions for a file, from a already existing file. |
613
|
|
|
|
|
|
|
|
614
|
|
|
|
|
|
|
Three arguments are taken. |
615
|
|
|
|
|
|
|
|
616
|
|
|
|
|
|
|
The first one is the configuration directory to use. If none is |
617
|
|
|
|
|
|
|
specified, it will automatically be choosen. |
618
|
|
|
|
|
|
|
|
619
|
|
|
|
|
|
|
The second is the config file to add the perms for. |
620
|
|
|
|
|
|
|
|
621
|
|
|
|
|
|
|
$foo->setPermsFromFile($configDir, $file); |
622
|
|
|
|
|
|
|
if($foo->error){ |
623
|
|
|
|
|
|
|
warn('error:'.$foo->error.': '.$foo->errorString); |
624
|
|
|
|
|
|
|
} |
625
|
|
|
|
|
|
|
|
626
|
|
|
|
|
|
|
=cut |
627
|
|
|
|
|
|
|
|
628
|
|
|
|
|
|
|
sub setPermsFromFile{ |
629
|
0
|
|
|
0
|
1
|
|
my $self=$_[0]; |
630
|
0
|
|
|
|
|
|
my $configDir=$_[1]; |
631
|
0
|
|
|
|
|
|
my $file=$_[2]; |
632
|
0
|
|
|
|
|
|
my $method='setPermsFromFile'; |
633
|
|
|
|
|
|
|
|
634
|
|
|
|
|
|
|
#blank any previous errors |
635
|
0
|
0
|
|
|
|
|
if (!$self->errorblank) { |
636
|
0
|
|
|
|
|
|
return undef; |
637
|
|
|
|
|
|
|
} |
638
|
|
|
|
|
|
|
|
639
|
|
|
|
|
|
|
#make sure we have a directory to use |
640
|
0
|
0
|
|
|
|
|
if (!defined($configDir)) { |
641
|
0
|
|
|
|
|
|
$configDir=$self->{scm}->selectConfigDir; |
642
|
0
|
0
|
|
|
|
|
if ($self->{scm}->error) { |
643
|
0
|
|
|
|
|
|
$self->{error}=5; |
644
|
0
|
|
|
|
|
|
$self->{errorString}='Sys::Config::Manage->selectConfigDir errored error="'. |
645
|
|
|
|
|
|
|
$self->{scm}->error.'" errorString="'.$self->{scm}->errorString.'"'; |
646
|
0
|
|
|
|
|
|
$self->warn; |
647
|
0
|
|
|
|
|
|
return undef; |
648
|
|
|
|
|
|
|
} |
649
|
|
|
|
|
|
|
} |
650
|
|
|
|
|
|
|
|
651
|
|
|
|
|
|
|
#make sure the config directory is valid |
652
|
0
|
|
|
|
|
|
my $valid=$self->{scm}->validConfigDirName($configDir); |
653
|
0
|
0
|
|
|
|
|
if ($self->{scm}->error) { |
654
|
0
|
|
|
|
|
|
$self->{error}=6; |
655
|
0
|
|
|
|
|
|
$self->{errorString}='Sys::Config::Manage->validConfigDirName errored error="'. |
656
|
|
|
|
|
|
|
$self->{scm}->error.'" errorString="'.$self->{scm}->errorString.'"'; |
657
|
0
|
|
|
|
|
|
$self->warn; |
658
|
0
|
|
|
|
|
|
return undef; |
659
|
|
|
|
|
|
|
} |
660
|
0
|
0
|
|
|
|
|
if (defined( $valid )) { |
661
|
0
|
|
|
|
|
|
$self->{error}=3; |
662
|
0
|
|
|
|
|
|
$self->{errorString}='The configuration directory name '.$valid; |
663
|
0
|
|
|
|
|
|
$self->warn; |
664
|
0
|
|
|
|
|
|
return undef; |
665
|
|
|
|
|
|
|
} |
666
|
|
|
|
|
|
|
|
667
|
|
|
|
|
|
|
#makes sure it exists |
668
|
0
|
0
|
|
|
|
|
if ( ! -d $self->{scm}->{baseDir}.'/'.$configDir ) { |
669
|
0
|
|
|
|
|
|
$self->{error}=4; |
670
|
0
|
|
|
|
|
|
$self->{errorString}='The configuration directory, "'.$self->{baseDir}.'/'.$configDir.'", does not exist'; |
671
|
0
|
|
|
|
|
|
$self->warn; |
672
|
0
|
|
|
|
|
|
return undef; |
673
|
|
|
|
|
|
|
} |
674
|
|
|
|
|
|
|
|
675
|
|
|
|
|
|
|
#make value for the file is specified |
676
|
0
|
0
|
|
|
|
|
if (!defined( $file )) { |
677
|
0
|
|
|
|
|
|
$self->{error}=7; |
678
|
0
|
|
|
|
|
|
$self->{errorString}='No file specified'; |
679
|
0
|
|
|
|
|
|
$self->warn; |
680
|
0
|
|
|
|
|
|
return undef; |
681
|
|
|
|
|
|
|
} |
682
|
|
|
|
|
|
|
|
683
|
|
|
|
|
|
|
#make sure the file exists, under the config dir |
684
|
0
|
0
|
|
|
|
|
if (! -f $self->{scm}->{baseDir}.'/'.$configDir.'/'.$file ) { |
685
|
0
|
|
|
|
|
|
$self->{error}=8; |
686
|
0
|
|
|
|
|
|
$self->{errorString}='The file does not exist in the configuration directory'; |
687
|
0
|
|
|
|
|
|
$self->warn; |
688
|
0
|
|
|
|
|
|
return undef; |
689
|
|
|
|
|
|
|
} |
690
|
|
|
|
|
|
|
|
691
|
|
|
|
|
|
|
#make sure the file exists, on the fs |
692
|
0
|
0
|
|
|
|
|
if (! -f $file ) { |
693
|
0
|
|
|
|
|
|
$self->{error}=9; |
694
|
0
|
|
|
|
|
|
$self->{errorString}='The file does not exist in the configuration directory'; |
695
|
0
|
|
|
|
|
|
$self->warn; |
696
|
0
|
|
|
|
|
|
return undef; |
697
|
|
|
|
|
|
|
} |
698
|
|
|
|
|
|
|
|
699
|
|
|
|
|
|
|
#make sure it is not under the base directory |
700
|
0
|
0
|
|
|
|
|
if ( ! $self->{scm}->notUnderBase($file) ){ |
701
|
0
|
|
|
|
|
|
$self->{error}=10; |
702
|
0
|
|
|
|
|
|
$self->{errorString}='"'.$file.'" exists under the base directory, "'.$self->{scm}->{baseDir}.'"'; |
703
|
0
|
|
|
|
|
|
$self->warn; |
704
|
0
|
|
|
|
|
|
return undef; |
705
|
|
|
|
|
|
|
} |
706
|
|
|
|
|
|
|
|
707
|
|
|
|
|
|
|
#stat the file |
708
|
0
|
|
|
|
|
|
my $mode = (stat($file))[2] & 07777; |
709
|
0
|
|
|
|
|
|
$mode=sprintf("%04o", $mode); |
710
|
|
|
|
|
|
|
|
711
|
0
|
|
|
|
|
|
$self->setPerms($configDir, $file, $mode); |
712
|
0
|
0
|
|
|
|
|
if ( $self->error ){ |
713
|
0
|
|
|
|
|
|
warn($self->{module}.' '.$method.': : setPerm errored'); |
714
|
0
|
|
|
|
|
|
return undef; |
715
|
|
|
|
|
|
|
} |
716
|
|
|
|
|
|
|
|
717
|
0
|
|
|
|
|
|
return 1; |
718
|
|
|
|
|
|
|
} |
719
|
|
|
|
|
|
|
|
720
|
|
|
|
|
|
|
=head2 upSync |
721
|
|
|
|
|
|
|
|
722
|
|
|
|
|
|
|
This syncs the file permissions up from the file system to |
723
|
|
|
|
|
|
|
configuration directory. |
724
|
|
|
|
|
|
|
|
725
|
|
|
|
|
|
|
Two arguments can be used. |
726
|
|
|
|
|
|
|
|
727
|
|
|
|
|
|
|
The first is the configuration directory. If not specified, it will |
728
|
|
|
|
|
|
|
be automaticallly choosen. |
729
|
|
|
|
|
|
|
|
730
|
|
|
|
|
|
|
The second is the files to sync. If not specifiedm, all files will |
731
|
|
|
|
|
|
|
be synced. |
732
|
|
|
|
|
|
|
|
733
|
|
|
|
|
|
|
#sync the specified files |
734
|
|
|
|
|
|
|
$foo->upSync( $configDir, \@files); |
735
|
|
|
|
|
|
|
if($foo->error){ |
736
|
|
|
|
|
|
|
warn('error:'.$foo->error.': '.$foo->errorString); |
737
|
|
|
|
|
|
|
} |
738
|
|
|
|
|
|
|
|
739
|
|
|
|
|
|
|
#syncs all the files |
740
|
|
|
|
|
|
|
$foo->upSync( $configDir ); |
741
|
|
|
|
|
|
|
if($foo->error){ |
742
|
|
|
|
|
|
|
warn('error:'.$foo->error.': '.$foo->errorString); |
743
|
|
|
|
|
|
|
} |
744
|
|
|
|
|
|
|
|
745
|
|
|
|
|
|
|
=cut |
746
|
|
|
|
|
|
|
|
747
|
|
|
|
|
|
|
sub upSync{ |
748
|
0
|
|
|
0
|
1
|
|
my $self=$_[0]; |
749
|
0
|
|
|
|
|
|
my $configDir=$_[1]; |
750
|
0
|
|
|
|
|
|
my @files; |
751
|
0
|
0
|
|
|
|
|
if (defined($_[2])) { |
752
|
0
|
|
|
|
|
|
@files=@{$_[2]}; |
|
0
|
|
|
|
|
|
|
753
|
|
|
|
|
|
|
} |
754
|
0
|
|
|
|
|
|
my $method='downSync'; |
755
|
|
|
|
|
|
|
|
756
|
|
|
|
|
|
|
#blank any previous errors |
757
|
0
|
0
|
|
|
|
|
if (!$self->errorblank) { |
758
|
0
|
|
|
|
|
|
return undef; |
759
|
|
|
|
|
|
|
} |
760
|
|
|
|
|
|
|
|
761
|
|
|
|
|
|
|
#make sure we have a directory to use |
762
|
0
|
0
|
|
|
|
|
if (!defined($configDir)) { |
763
|
0
|
|
|
|
|
|
$configDir=$self->{scm}->selectConfigDir; |
764
|
0
|
0
|
|
|
|
|
if ($self->{scm}->error) { |
765
|
0
|
|
|
|
|
|
$self->{error}=5; |
766
|
0
|
|
|
|
|
|
$self->{errorString}='Sys::Config::Manage->selectConfigDir errored error="'. |
767
|
|
|
|
|
|
|
$self->{scm}->error.'" errorString="'.$self->{scm}->errorString.'"'; |
768
|
0
|
|
|
|
|
|
$self->warn; |
769
|
0
|
|
|
|
|
|
return undef; |
770
|
|
|
|
|
|
|
} |
771
|
|
|
|
|
|
|
} |
772
|
|
|
|
|
|
|
|
773
|
|
|
|
|
|
|
#make sure the config directory is valid |
774
|
0
|
|
|
|
|
|
my $valid=$self->{scm}->validConfigDirName($configDir); |
775
|
0
|
0
|
|
|
|
|
if ($self->{scm}->error) { |
776
|
0
|
|
|
|
|
|
$self->{error}=6; |
777
|
0
|
|
|
|
|
|
$self->{errorString}='Sys::Config::Manage->validConfigDirName errored error="'. |
778
|
|
|
|
|
|
|
$self->{scm}->error.'" errorString="'.$self->{scm}->errorString.'"'; |
779
|
0
|
|
|
|
|
|
$self->warn; |
780
|
0
|
|
|
|
|
|
return undef; |
781
|
|
|
|
|
|
|
} |
782
|
0
|
0
|
|
|
|
|
if (defined( $valid )) { |
783
|
0
|
|
|
|
|
|
$self->{error}=3; |
784
|
0
|
|
|
|
|
|
$self->{errorString}='The configuration directory name '.$valid; |
785
|
0
|
|
|
|
|
|
$self->warn; |
786
|
0
|
|
|
|
|
|
return undef; |
787
|
|
|
|
|
|
|
} |
788
|
|
|
|
|
|
|
|
789
|
|
|
|
|
|
|
#makes sure it exists |
790
|
0
|
0
|
|
|
|
|
if ( ! -d $self->{scm}->{baseDir}.'/'.$configDir ) { |
791
|
0
|
|
|
|
|
|
$self->{error}=4; |
792
|
0
|
|
|
|
|
|
$self->{errorString}='The configuration directory, "'.$self->{baseDir}.'/'.$configDir.'", does not exist'; |
793
|
0
|
|
|
|
|
|
$self->warn; |
794
|
0
|
|
|
|
|
|
return undef; |
795
|
|
|
|
|
|
|
} |
796
|
|
|
|
|
|
|
|
797
|
|
|
|
|
|
|
#checks and make sure all the files exist |
798
|
0
|
|
|
|
|
|
my $int=0; |
799
|
0
|
0
|
|
|
|
|
if(defined( $files[$int] )){ |
800
|
0
|
|
|
|
|
|
my @allfiles=$self->{scm}->listConfigFiles($configDir); |
801
|
0
|
0
|
|
|
|
|
if( $self->{scm}->error ){ |
802
|
0
|
|
|
|
|
|
$self->{error}='16'; |
803
|
0
|
|
|
|
|
|
$self->{errorString}='Sys::Config::Manage->listConfigFiles errored error="'. |
804
|
|
|
|
|
|
|
$self->{scm}->error.'" errorString="'.$self->{scm}->errorString.'"'; |
805
|
0
|
|
|
|
|
|
$self->warn; |
806
|
0
|
|
|
|
|
|
return undef; |
807
|
|
|
|
|
|
|
} |
808
|
|
|
|
|
|
|
|
809
|
|
|
|
|
|
|
#make sure each file asked to be synced is tracked |
810
|
0
|
|
|
|
|
|
while(defined( $files[$int] )){ |
811
|
|
|
|
|
|
|
|
812
|
0
|
|
|
|
|
|
my $matched=0; |
813
|
0
|
|
|
|
|
|
my $int2=0; |
814
|
0
|
|
|
|
|
|
while(defined( $allfiles[$int2] )){ |
815
|
0
|
0
|
|
|
|
|
if( $files[$int] eq $allfiles[$int2] ){ |
816
|
0
|
|
|
|
|
|
$matched=1; |
817
|
|
|
|
|
|
|
} |
818
|
|
|
|
|
|
|
|
819
|
0
|
|
|
|
|
|
$int2++; |
820
|
|
|
|
|
|
|
} |
821
|
|
|
|
|
|
|
|
822
|
0
|
0
|
|
|
|
|
if(! $matched){ |
823
|
0
|
|
|
|
|
|
$self->{error}='8'; |
824
|
0
|
|
|
|
|
|
$self->{errorString}='"'.$files[$int].'" does not exist under the configuration directory, "'.$configDir.'",'; |
825
|
0
|
|
|
|
|
|
$self->warn; |
826
|
0
|
|
|
|
|
|
return undef; |
827
|
|
|
|
|
|
|
} |
828
|
|
|
|
|
|
|
|
829
|
0
|
|
|
|
|
|
$int++; |
830
|
|
|
|
|
|
|
} |
831
|
|
|
|
|
|
|
|
832
|
|
|
|
|
|
|
}else{ |
833
|
|
|
|
|
|
|
#if we get here, no files have been specified so we do them all |
834
|
0
|
|
|
|
|
|
@files=$self->{scm}->listConfigFiles($configDir); |
835
|
0
|
0
|
|
|
|
|
if( $self->{scm}->error ){ |
836
|
0
|
|
|
|
|
|
$self->{error}='16'; |
837
|
0
|
|
|
|
|
|
$self->{errorString}='Sys::Config::Manage->listConfigFiles errored error="'. |
838
|
|
|
|
|
|
|
$self->{scm}->error.'" errorString="'.$self->{scm}->errorString.'"'; |
839
|
0
|
|
|
|
|
|
$self->warn; |
840
|
0
|
|
|
|
|
|
return undef; |
841
|
|
|
|
|
|
|
} |
842
|
|
|
|
|
|
|
} |
843
|
|
|
|
|
|
|
|
844
|
|
|
|
|
|
|
#process each file |
845
|
0
|
|
|
|
|
|
$int=0; |
846
|
0
|
|
|
|
|
|
while( defined( $files[$int] ) ){ |
847
|
|
|
|
|
|
|
#try to sync it from what it currently is |
848
|
0
|
|
|
|
|
|
$self->setPermsFromFile( $configDir, $files[$int] ); |
849
|
0
|
0
|
|
|
|
|
if( $self->error ){ |
850
|
0
|
|
|
|
|
|
warn( $self->{module}.' '.$method.': $self->setPermsFromFile( $configDir, $files[$int] ) errored' ); |
851
|
0
|
|
|
|
|
|
return undef; |
852
|
|
|
|
|
|
|
} |
853
|
|
|
|
|
|
|
|
854
|
0
|
|
|
|
|
|
$int++; |
855
|
|
|
|
|
|
|
} |
856
|
|
|
|
|
|
|
|
857
|
0
|
|
|
|
|
|
return 1; |
858
|
|
|
|
|
|
|
} |
859
|
|
|
|
|
|
|
|
860
|
|
|
|
|
|
|
=head1 ERROR CODES |
861
|
|
|
|
|
|
|
|
862
|
|
|
|
|
|
|
=head2 1 |
863
|
|
|
|
|
|
|
|
864
|
|
|
|
|
|
|
Nothing passed for the Sys::Config::Manage object. |
865
|
|
|
|
|
|
|
|
866
|
|
|
|
|
|
|
=head2 2 |
867
|
|
|
|
|
|
|
|
868
|
|
|
|
|
|
|
$args{scm} is not a Sys::Config::Manage object. |
869
|
|
|
|
|
|
|
|
870
|
|
|
|
|
|
|
=head2 3 |
871
|
|
|
|
|
|
|
|
872
|
|
|
|
|
|
|
Invalid configuration directory name. |
873
|
|
|
|
|
|
|
|
874
|
|
|
|
|
|
|
=head2 4 |
875
|
|
|
|
|
|
|
|
876
|
|
|
|
|
|
|
The configuration directory does not exist. |
877
|
|
|
|
|
|
|
|
878
|
|
|
|
|
|
|
=head2 5 |
879
|
|
|
|
|
|
|
|
880
|
|
|
|
|
|
|
Sys::Config::Manage->selectConfigDir errored. |
881
|
|
|
|
|
|
|
|
882
|
|
|
|
|
|
|
=head2 6 |
883
|
|
|
|
|
|
|
|
884
|
|
|
|
|
|
|
Sys::Config::Manage->validConfigDirName errored. |
885
|
|
|
|
|
|
|
|
886
|
|
|
|
|
|
|
=head2 7 |
887
|
|
|
|
|
|
|
|
888
|
|
|
|
|
|
|
No filename specified. |
889
|
|
|
|
|
|
|
|
890
|
|
|
|
|
|
|
=head2 8 |
891
|
|
|
|
|
|
|
|
892
|
|
|
|
|
|
|
The specified file does not exist under the configuration directory. |
893
|
|
|
|
|
|
|
|
894
|
|
|
|
|
|
|
=head2 9 |
895
|
|
|
|
|
|
|
|
896
|
|
|
|
|
|
|
The specified file does not exist on the file system. |
897
|
|
|
|
|
|
|
|
898
|
|
|
|
|
|
|
=head2 10 |
899
|
|
|
|
|
|
|
|
900
|
|
|
|
|
|
|
The file specified file is under the base directory. |
901
|
|
|
|
|
|
|
|
902
|
|
|
|
|
|
|
=head2 11 |
903
|
|
|
|
|
|
|
|
904
|
|
|
|
|
|
|
No value for the permissions specified. |
905
|
|
|
|
|
|
|
|
906
|
|
|
|
|
|
|
=head2 12 |
907
|
|
|
|
|
|
|
|
908
|
|
|
|
|
|
|
The value specified for the permissions does not appear to be valid. |
909
|
|
|
|
|
|
|
|
910
|
|
|
|
|
|
|
Validity is checked via the regexp below. |
911
|
|
|
|
|
|
|
|
912
|
|
|
|
|
|
|
/^[01246][01234567][01234567][01234567]$/ |
913
|
|
|
|
|
|
|
|
914
|
|
|
|
|
|
|
=head2 13 |
915
|
|
|
|
|
|
|
|
916
|
|
|
|
|
|
|
The ".SysConfigManage" directory does not exist and could not be created. |
917
|
|
|
|
|
|
|
|
918
|
|
|
|
|
|
|
=head2 14 |
919
|
|
|
|
|
|
|
|
920
|
|
|
|
|
|
|
The ".SysConfigManage/Perms" directory does not exist and could not be created. |
921
|
|
|
|
|
|
|
|
922
|
|
|
|
|
|
|
=head2 15 |
923
|
|
|
|
|
|
|
|
924
|
|
|
|
|
|
|
Unable to opens the permissions file. |
925
|
|
|
|
|
|
|
|
926
|
|
|
|
|
|
|
=head2 16 |
927
|
|
|
|
|
|
|
|
928
|
|
|
|
|
|
|
The add command failed. |
929
|
|
|
|
|
|
|
|
930
|
|
|
|
|
|
|
=head1 AUTHOR |
931
|
|
|
|
|
|
|
|
932
|
|
|
|
|
|
|
Zane C. Bowers-Hadley, C<< >> |
933
|
|
|
|
|
|
|
|
934
|
|
|
|
|
|
|
=head1 BUGS |
935
|
|
|
|
|
|
|
|
936
|
|
|
|
|
|
|
Please report any bugs or feature requests to C, or through |
937
|
|
|
|
|
|
|
the web interface at L. I will be notified, and then you'll |
938
|
|
|
|
|
|
|
automatically be notified of progress on your bug as I make changes. |
939
|
|
|
|
|
|
|
|
940
|
|
|
|
|
|
|
=head1 SUPPORT |
941
|
|
|
|
|
|
|
|
942
|
|
|
|
|
|
|
You can find documentation for this module with the perldoc command. |
943
|
|
|
|
|
|
|
|
944
|
|
|
|
|
|
|
perldoc Sys::Config::Manage::Perms |
945
|
|
|
|
|
|
|
|
946
|
|
|
|
|
|
|
|
947
|
|
|
|
|
|
|
You can also look for information at: |
948
|
|
|
|
|
|
|
|
949
|
|
|
|
|
|
|
=over 4 |
950
|
|
|
|
|
|
|
|
951
|
|
|
|
|
|
|
=item * RT: CPAN's request tracker |
952
|
|
|
|
|
|
|
|
953
|
|
|
|
|
|
|
L |
954
|
|
|
|
|
|
|
|
955
|
|
|
|
|
|
|
=item * AnnoCPAN: Annotated CPAN documentation |
956
|
|
|
|
|
|
|
|
957
|
|
|
|
|
|
|
L |
958
|
|
|
|
|
|
|
|
959
|
|
|
|
|
|
|
=item * CPAN Ratings |
960
|
|
|
|
|
|
|
|
961
|
|
|
|
|
|
|
L |
962
|
|
|
|
|
|
|
|
963
|
|
|
|
|
|
|
=item * Search CPAN |
964
|
|
|
|
|
|
|
|
965
|
|
|
|
|
|
|
L |
966
|
|
|
|
|
|
|
|
967
|
|
|
|
|
|
|
=back |
968
|
|
|
|
|
|
|
|
969
|
|
|
|
|
|
|
|
970
|
|
|
|
|
|
|
=head1 ACKNOWLEDGEMENTS |
971
|
|
|
|
|
|
|
|
972
|
|
|
|
|
|
|
|
973
|
|
|
|
|
|
|
=head1 LICENSE AND COPYRIGHT |
974
|
|
|
|
|
|
|
|
975
|
|
|
|
|
|
|
Copyright 2011 Zane C. Bowers-Hadley. |
976
|
|
|
|
|
|
|
|
977
|
|
|
|
|
|
|
This program is free software; you can redistribute it and/or modify it |
978
|
|
|
|
|
|
|
under the terms of either: the GNU General Public License as published |
979
|
|
|
|
|
|
|
by the Free Software Foundation; or the Artistic License. |
980
|
|
|
|
|
|
|
|
981
|
|
|
|
|
|
|
See http://dev.perl.org/licenses/ for more information. |
982
|
|
|
|
|
|
|
|
983
|
|
|
|
|
|
|
|
984
|
|
|
|
|
|
|
=cut |
985
|
|
|
|
|
|
|
|
986
|
|
|
|
|
|
|
1; # End of Sys::Config::Manage::Perms |