File Coverage

blib/lib/Slackware/Slackget/Network/Auth.pm
Criterion Covered Total %
statement 6 133 4.5
branch 0 112 0.0
condition 0 102 0.0
subroutine 2 14 14.2
pod 12 12 100.0
total 20 373 5.3


line stmt bran cond sub pod time code
1             package Slackware::Slackget::Network::Auth;
2              
3 1     1   1189 use warnings;
  1         20  
  1         35  
4 1     1   6 use strict;
  1         1  
  1         3063  
5              
6             =head1 NAME
7              
8             Slackware::Slackget::Network::Auth - The authentification/authorization class for slack-getd network deamons.
9              
10             =head1 VERSION
11              
12             Version 1.0.0
13              
14             =cut
15              
16             our $VERSION = '1.0.0';
17              
18             =head1 SYNOPSIS
19              
20             This class is used by slack-get daemon's to verify the permission of an host.
21              
22             use Slackware::Slackget::Network::Auth;
23              
24             my $auth = Slackware::Slackget::Network::Auth->new($config);
25             if(!$auth->can_connect($client->peerhost()))
26             {
27             $client->close ;
28             }
29            
30              
31             =cut
32              
33             sub new
34             {
35 0     0 1   my ($class,$config) = @_ ;
36 0 0 0       return undef if(!defined($config) && ref($config) ne 'Slackware::Slackget::Config') ;
37 0           my $self={};
38 0           $self->{CONF} = $config ;
39 0           bless($self,$class);
40            
41 0           return $self;
42             }
43              
44             =head1 CONSTRUCTOR
45              
46             =head2 new
47              
48             The constructor just take one argument: a Slackware::Slackget::Config object :
49              
50             my $auth = new Slackware::Slackget::Network::Auth ($config);
51              
52             =head1 FUNCTIONS
53              
54             All methods name are the same as configuration file directives, but you need to change '-' to '_'.
55              
56             =head2 RETURNED VALUES
57              
58             All methods return TRUE (1) if directive is set to 'yes', FALSE (0) if set to 'no' and undef if the directive cannot be found in the Slackware::Slackget::Config. For some secure reasons, all directives are in read-only access.
59             But in the real use the undef value must never been returned, because all method fall back to the section on undefined value. So if a method return undef, this is because the -> -> section is not complete, and that's really a very very bad idea !
60              
61             =head2 can_connect
62              
63             Take an host address and return the appropriate value.
64              
65             $auth->can_connect($client->peerhost) or die "client is not allow to connect\n";
66              
67             =cut
68              
69             sub can_connect {
70 0     0 1   my ($self,$host) = @_ ;
71 0 0 0       if(exists($self->{CONF}->{daemon}->{'connection-policy'}->{host}->{"$host"}) && defined($self->{CONF}->{daemon}->{'connection-policy'}->{host}->{"$host"}))
72             {
73 0 0 0       if(exists($self->{CONF}->{daemon}->{'connection-policy'}->{host}->{"$host"}->{'can-connect'}) && defined($self->{CONF}->{daemon}->{'connection-policy'}->{host}->{"$host"}->{'can-connect'}))
74             {
75 0 0         if($self->{CONF}->{daemon}->{'connection-policy'}->{host}->{"$host"}->{'can-connect'}=~ /yes/i)
76             {
77 0           return 1;
78             }
79             else
80             {
81 0           return 0;
82             }
83             }
84             }
85 0 0 0       if(exists($self->{CONF}->{daemon}->{'connection-policy'}->{all}->{'can-connect'}) && defined($self->{CONF}->{daemon}->{'connection-policy'}->{all}->{'can-connect'}))
86             {
87 0 0         if($self->{CONF}->{daemon}->{'connection-policy'}->{all}->{'can-connect'}=~ /yes/i)
88             {
89 0           return 1;
90             }
91             else
92             {
93 0           return 0;
94             }
95             }
96             else
97             {
98 0           return undef;
99             }
100             }
101              
102             =head2 can_build_packages_list
103              
104             =cut
105              
106             sub can_build_packages_list {
107 0     0 1   my ($self,$host) = @_ ;
108 0 0 0       if(exists($self->{CONF}->{daemon}->{'connection-policy'}->{host}->{"$host"}) && defined($self->{CONF}->{daemon}->{'connection-policy'}->{host}->{"$host"}))
109             {
110 0 0 0       if(exists($self->{CONF}->{daemon}->{'connection-policy'}->{host}->{"$host"}->{'can-build-packages-list'}) && defined($self->{CONF}->{daemon}->{'connection-policy'}->{host}->{"$host"}->{'can-build-packages-list'}))
111             {
112 0 0         if($self->{CONF}->{daemon}->{'connection-policy'}->{host}->{"$host"}->{'can-build-packages-list'}=~ /yes/i)
113             {
114 0           return 1;
115             }
116             else
117             {
118 0           return 0;
119             }
120             }
121             }
122 0 0 0       if(exists($self->{CONF}->{daemon}->{'connection-policy'}->{all}->{'can-build-packages-list'}) && defined($self->{CONF}->{daemon}->{'connection-policy'}->{all}->{'can-build-packages-list'}))
123             {
124 0 0         if($self->{CONF}->{daemon}->{'connection-policy'}->{all}->{'can-build-packages-list'}=~ /yes/i)
125             {
126 0           return 1;
127             }
128             else
129             {
130 0           return 0;
131             }
132             }
133             else
134             {
135 0           return undef;
136             }
137             }
138              
139             =head2 can_build_installed_list
140              
141             =cut
142              
143             sub can_build_installed_list {
144 0     0 1   my ($self,$host) = @_ ;
145 0 0 0       if(exists($self->{CONF}->{daemon}->{'connection-policy'}->{host}->{"$host"}) && defined($self->{CONF}->{daemon}->{'connection-policy'}->{host}->{"$host"}))
146             {
147 0 0 0       if(exists($self->{CONF}->{daemon}->{'connection-policy'}->{host}->{"$host"}->{'can-build-installed-list'}) && defined($self->{CONF}->{daemon}->{'connection-policy'}->{host}->{"$host"}->{'can-build-installed-list'}))
148             {
149 0 0         if($self->{CONF}->{daemon}->{'connection-policy'}->{host}->{"$host"}->{'can-build-installed-list'}=~ /yes/i)
150             {
151 0           return 1;
152             }
153             else
154             {
155 0           return 0;
156             }
157             }
158             }
159 0 0 0       if(exists($self->{CONF}->{daemon}->{'connection-policy'}->{all}->{'can-build-installed-list'}) && defined($self->{CONF}->{daemon}->{'connection-policy'}->{all}->{'can-build-installed-list'}))
160             {
161 0 0         if($self->{CONF}->{daemon}->{'connection-policy'}->{all}->{'can-build-installed-list'}=~ /yes/i)
162             {
163 0           return 1;
164             }
165             else
166             {
167 0           return 0;
168             }
169             }
170             else
171             {
172 0           return undef;
173             }
174             }
175              
176             =head2 can_install_packages
177              
178             =cut
179              
180             sub can_install_packages {
181 0     0 1   my ($self,$host) = @_ ;
182 0 0 0       if(exists($self->{CONF}->{daemon}->{'connection-policy'}->{host}->{"$host"}) && defined($self->{CONF}->{daemon}->{'connection-policy'}->{host}->{"$host"}))
183             {
184 0 0 0       if(exists($self->{CONF}->{daemon}->{'connection-policy'}->{host}->{"$host"}->{'can-install-packages'}) && defined($self->{CONF}->{daemon}->{'connection-policy'}->{host}->{"$host"}->{'can-install-packages'}))
185             {
186 0 0         if($self->{CONF}->{daemon}->{'connection-policy'}->{host}->{"$host"}->{'can-install-packages'}=~ /yes/i)
187             {
188 0           return 1;
189             }
190             else
191             {
192 0           return 0;
193             }
194             }
195             }
196 0 0 0       if(exists($self->{CONF}->{daemon}->{'connection-policy'}->{all}->{'can-install-packages'}) && defined($self->{CONF}->{daemon}->{'connection-policy'}->{all}->{'can-install-packages'}))
197             {
198 0 0         if($self->{CONF}->{daemon}->{'connection-policy'}->{all}->{'can-install-packages'}=~ /yes/i)
199             {
200 0           return 1;
201             }
202             else
203             {
204 0           return 0;
205             }
206             }
207             else
208             {
209 0           return undef;
210             }
211             }
212              
213             =head2 can_upgrade_packages
214              
215             =cut
216              
217             sub can_upgrade_packages {
218 0     0 1   my ($self,$host) = @_ ;
219 0 0 0       if(exists($self->{CONF}->{daemon}->{'connection-policy'}->{host}->{"$host"}) && defined($self->{CONF}->{daemon}->{'connection-policy'}->{host}->{"$host"}))
220             {
221 0 0 0       if(exists($self->{CONF}->{daemon}->{'connection-policy'}->{host}->{"$host"}->{'can-upgrade-packages'}) && defined($self->{CONF}->{daemon}->{'connection-policy'}->{host}->{"$host"}->{'can-upgrade-packages'}))
222             {
223 0 0         if($self->{CONF}->{daemon}->{'connection-policy'}->{host}->{"$host"}->{'can-upgrade-packages'}=~ /yes/i)
224             {
225 0           return 1;
226             }
227             else
228             {
229 0           return 0;
230             }
231             }
232             }
233 0 0 0       if(exists($self->{CONF}->{daemon}->{'connection-policy'}->{all}->{'can-upgrade-packages'}) && defined($self->{CONF}->{daemon}->{'connection-policy'}->{all}->{'can-upgrade-packages'}))
234             {
235 0 0         if($self->{CONF}->{daemon}->{'connection-policy'}->{all}->{'can-upgrade-packages'}=~ /yes/i)
236             {
237 0           return 1;
238             }
239             else
240             {
241 0           return 0;
242             }
243             }
244             else
245             {
246 0           return undef;
247             }
248             }
249              
250             =head2 can_remove_packages
251              
252             =cut
253              
254             sub can_remove_packages {
255 0     0 1   my ($self,$host) = @_ ;
256 0 0 0       if(exists($self->{CONF}->{daemon}->{'connection-policy'}->{host}->{"$host"}) && defined($self->{CONF}->{daemon}->{'connection-policy'}->{host}->{"$host"}))
257             {
258 0 0 0       if(exists($self->{CONF}->{daemon}->{'connection-policy'}->{host}->{"$host"}->{'can-remove-packages'}) && defined($self->{CONF}->{daemon}->{'connection-policy'}->{host}->{"$host"}->{'can-remove-packages'}))
259             {
260 0 0         if($self->{CONF}->{daemon}->{'connection-policy'}->{host}->{"$host"}->{'can-remove-packages'}=~ /yes/i)
261             {
262 0           return 1;
263             }
264             else
265             {
266 0           return 0;
267             }
268             }
269             }
270 0 0 0       if(exists($self->{CONF}->{daemon}->{'connection-policy'}->{all}->{'can-remove-packages'}) && defined($self->{CONF}->{daemon}->{'connection-policy'}->{all}->{'can-remove-packages'}))
271             {
272 0 0         if($self->{CONF}->{daemon}->{'connection-policy'}->{all}->{'can-remove-packages'}=~ /yes/i)
273             {
274 0           return 1;
275             }
276             else
277             {
278 0           return 0;
279             }
280             }
281             else
282             {
283 0           return undef;
284             }
285             }
286              
287             =head2 can_require_installed_list
288              
289             =cut
290              
291             sub can_require_installed_list {
292 0     0 1   my ($self,$host) = @_ ;
293 0 0 0       if(exists($self->{CONF}->{daemon}->{'connection-policy'}->{host}->{"$host"}) && defined($self->{CONF}->{daemon}->{'connection-policy'}->{host}->{"$host"}))
294             {
295 0 0 0       if(exists($self->{CONF}->{daemon}->{'connection-policy'}->{host}->{"$host"}->{'can-require-installed-list'}) && defined($self->{CONF}->{daemon}->{'connection-policy'}->{host}->{"$host"}->{'can-require-installed-list'}))
296             {
297 0 0         if($self->{CONF}->{daemon}->{'connection-policy'}->{host}->{"$host"}->{'can-require-installed-list'}=~ /yes/i)
298             {
299 0           return 1;
300             }
301             else
302             {
303 0           return 0;
304             }
305             }
306             }
307 0 0 0       if(exists($self->{CONF}->{daemon}->{'connection-policy'}->{all}->{'can-require-installed-list'}) && defined($self->{CONF}->{daemon}->{'connection-policy'}->{all}->{'can-require-installed-list'}))
308             {
309 0 0         if($self->{CONF}->{daemon}->{'connection-policy'}->{all}->{'can-require-installed-list'}=~ /yes/i)
310             {
311 0           return 1;
312             }
313             else
314             {
315 0           return 0;
316             }
317             }
318             else
319             {
320 0           return undef;
321             }
322             }
323              
324             =head2 can_require_servers_list
325              
326             =cut
327              
328             sub can_require_servers_list {
329 0     0 1   my ($self,$host) = @_ ;
330 0 0 0       if(exists($self->{CONF}->{daemon}->{'connection-policy'}->{host}->{"$host"}) && defined($self->{CONF}->{daemon}->{'connection-policy'}->{host}->{"$host"}))
331             {
332 0 0 0       if(exists($self->{CONF}->{daemon}->{'connection-policy'}->{host}->{"$host"}->{'can-require-servers-list'}) && defined($self->{CONF}->{daemon}->{'connection-policy'}->{host}->{"$host"}->{'can-require-servers-list'}))
333             {
334 0 0         if($self->{CONF}->{daemon}->{'connection-policy'}->{host}->{"$host"}->{'can-require-servers-list'}=~ /yes/i)
335             {
336 0           return 1;
337             }
338             else
339             {
340 0           return 0;
341             }
342             }
343             }
344 0 0 0       if(exists($self->{CONF}->{daemon}->{'connection-policy'}->{all}->{'can-require-servers-list'}) && defined($self->{CONF}->{daemon}->{'connection-policy'}->{all}->{'can-require-servers-list'}))
345             {
346 0 0         if($self->{CONF}->{daemon}->{'connection-policy'}->{all}->{'can-require-servers-list'}=~ /yes/i)
347             {
348 0           return 1;
349             }
350             else
351             {
352 0           return 0;
353             }
354             }
355             else
356             {
357 0           return undef;
358             }
359             }
360              
361             =head2 can_require_packages_list
362              
363             =cut
364              
365             sub can_require_packages_list {
366 0     0 1   my ($self,$host) = @_ ;
367 0 0 0       if(exists($self->{CONF}->{daemon}->{'connection-policy'}->{host}->{"$host"}) && defined($self->{CONF}->{daemon}->{'connection-policy'}->{host}->{"$host"}))
368             {
369 0 0 0       if(exists($self->{CONF}->{daemon}->{'connection-policy'}->{host}->{"$host"}->{'can-require-packages-list'}) && defined($self->{CONF}->{daemon}->{'connection-policy'}->{host}->{"$host"}->{'can-require-packages-list'}))
370             {
371 0 0         if($self->{CONF}->{daemon}->{'connection-policy'}->{host}->{"$host"}->{'can-require-packages-list'}=~ /yes/i)
372             {
373 0           return 1;
374             }
375             else
376             {
377 0           return 0;
378             }
379             }
380             }
381 0 0 0       if(exists($self->{CONF}->{daemon}->{'connection-policy'}->{all}->{'can-require-packages-list'}) && defined($self->{CONF}->{daemon}->{'connection-policy'}->{all}->{'can-require-packages-list'}))
382             {
383 0 0         if($self->{CONF}->{daemon}->{'connection-policy'}->{all}->{'can-require-packages-list'}=~ /yes/i)
384             {
385 0           return 1;
386             }
387             else
388             {
389 0           return 0;
390             }
391             }
392             else
393             {
394 0           return undef;
395             }
396             }
397              
398              
399             =head2 can_search
400              
401             =cut
402              
403             sub can_search {
404 0     0 1   my ($self,$host) = @_ ;
405 0 0 0       if(exists($self->{CONF}->{daemon}->{'connection-policy'}->{host}->{"$host"}) && defined($self->{CONF}->{daemon}->{'connection-policy'}->{host}->{"$host"}))
406             {
407 0 0 0       if(exists($self->{CONF}->{daemon}->{'connection-policy'}->{host}->{"$host"}->{'can-search'}) && defined($self->{CONF}->{daemon}->{'connection-policy'}->{host}->{"$host"}->{'can-search'}))
408             {
409 0 0         if($self->{CONF}->{daemon}->{'connection-policy'}->{host}->{"$host"}->{'can-search'}=~ /yes/i)
410             {
411 0           return 1;
412             }
413             else
414             {
415 0           return 0;
416             }
417             }
418             }
419 0 0 0       if(exists($self->{CONF}->{daemon}->{'connection-policy'}->{all}->{'can-search'}) && defined($self->{CONF}->{daemon}->{'connection-policy'}->{all}->{'can-search'}))
420             {
421 0 0         if($self->{CONF}->{daemon}->{'connection-policy'}->{all}->{'can-search'}=~ /yes/i)
422             {
423 0           return 1;
424             }
425             else
426             {
427 0           return 0;
428             }
429             }
430             else
431             {
432 0           return undef;
433             }
434             }
435              
436             =head2 is_allowed_to
437              
438             =cut
439              
440             sub is_allowed_to {
441 0     0 1   my ($self,$rule,$host) = @_ ;
442 0 0 0       if(exists($self->{CONF}->{daemon}->{'connection-policy'}->{host}->{"$host"}) && defined($self->{CONF}->{daemon}->{'connection-policy'}->{host}->{"$host"}))
443             {
444 0 0 0       if(exists($self->{CONF}->{daemon}->{'connection-policy'}->{host}->{"$host"}->{$rule}) && defined($self->{CONF}->{daemon}->{'connection-policy'}->{host}->{"$host"}->{$rule}))
445             {
446 0 0         if($self->{CONF}->{daemon}->{'connection-policy'}->{host}->{"$host"}->{$rule}=~ /yes/i)
447             {
448 0           return 1;
449             }
450             else
451             {
452 0           return 0;
453             }
454             }
455             }
456 0 0 0       if(exists($self->{CONF}->{daemon}->{'connection-policy'}->{all}->{$rule}) && defined($self->{CONF}->{daemon}->{'connection-policy'}->{all}->{$rule}))
457             {
458 0 0         if($self->{CONF}->{daemon}->{'connection-policy'}->{all}->{$rule}=~ /yes/i)
459             {
460 0           return 1;
461             }
462             else
463             {
464 0           return 0;
465             }
466             }
467             else
468             {
469 0           return undef;
470             }
471             }
472              
473              
474              
475             =head1 AUTHOR
476              
477             DUPUIS Arnaud, C<< >>
478              
479             =head1 BUGS
480              
481             Please report any bugs or feature requests to
482             C, or through the web interface at
483             L.
484             I will be notified, and then you'll automatically be notified of progress on
485             your bug as I make changes.
486              
487             =head1 SUPPORT
488              
489             You can find documentation for this module with the perldoc command.
490              
491             perldoc Slackware::Slackget
492              
493              
494             You can also look for information at:
495              
496             =over 4
497              
498             =item * Infinity Perl website
499              
500             L
501              
502             =item * slack-get specific website
503              
504             L
505              
506             =item * RT: CPAN's request tracker
507              
508             L
509              
510             =item * AnnoCPAN: Annotated CPAN documentation
511              
512             L
513              
514             =item * CPAN Ratings
515              
516             L
517              
518             =item * Search CPAN
519              
520             L
521              
522             =back
523              
524             =head1 ACKNOWLEDGEMENTS
525              
526             Thanks to Bertrand Dupuis (yes my brother) for his contribution to the documentation.
527              
528              
529             =head1 COPYRIGHT & LICENSE
530              
531             Copyright 2005 DUPUIS Arnaud, All Rights Reserved.
532              
533             This program is free software; you can redistribute it and/or modify it
534             under the same terms as Perl itself.
535              
536             =cut
537              
538             1; # End of Slackware::Slackget::Network::Auth