forked from sympa-community/sympa
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathConf.pm
2091 lines (1792 loc) · 66.4 KB
/
Conf.pm
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
# -*- indent-tabs-mode: nil; -*-
# vim:ft=perl:et:sw=4
# $Id$
# Sympa - SYsteme de Multi-Postage Automatique
#
# Copyright (c) 1997, 1998, 1999 Institut Pasteur & Christophe Wolfhugel
# Copyright (c) 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005,
# 2006, 2007, 2008, 2009, 2010, 2011 Comite Reseau des Universites
# Copyright (c) 2011, 2012, 2013, 2014, 2015, 2016, 2017 GIP RENATER
# Copyright 2017, 2018, 2019, 2020, 2021, 2022 The Sympa Community. See the
# AUTHORS.md file at the top-level directory of this distribution and at
# <https://github.com/sympa-community/sympa.git>.
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
## This module handles the configuration file for Sympa.
package Conf;
use strict;
use warnings;
use English qw(-no_match_vars);
use Sympa;
use Sympa::ConfDef;
use Sympa::Constants;
use Sympa::Language;
use Sympa::Log;
use Sympa::Regexps;
use Sympa::Tools::Data;
use Sympa::Tools::File;
use Sympa::Tools::Text;
my $log = Sympa::Log->instance;
=encoding utf-8
#=head1 NAME
#
#Conf - Sympa configuration
=head1 DESCRIPTION
=head2 CONSTANTS AND EXPORTED VARIABLES
=cut
# parameters hash, keyed by parameter name
our %params =
map { $_->{name} => $_ }
grep { $_->{name} } @Sympa::ConfDef::params;
# valid virtual host parameters, keyed by parameter name
my %valid_robot_key_words;
my %optional_key_words;
foreach my $hash (@Sympa::ConfDef::params) {
$valid_robot_key_words{$hash->{'name'}} = 1 if ($hash->{'vhost'});
$optional_key_words{$hash->{'name'}} = 1 if ($hash->{'optional'});
}
our $params_by_categories = _get_parameters_names_by_category();
my %trusted_applications = (
'trusted_application' => {
'occurrence' => '0-n',
'format' => {
'name' => {
'format' => '\S*',
'occurrence' => '1',
'case' => 'insensitive',
},
'ip' => {
'format' => '\d+\.\d+\.\d+\.\d+',
'occurrence' => '0-1'
},
'md5password' => {
'format' => '.*',
'occurrence' => '0-1'
},
'proxy_for_variables' => {
'format' => '.*',
'occurrence' => '0-n',
'split_char' => ','
},
'set_variables' => {
'format' => '\S+=.*',
'occurrence' => '0-n',
'split_char' => ',',
},
'allow_commands' => {
'format' => '\S+',
'occurrence' => '0-n',
'split_char' => ',',
},
}
}
);
#XXXmy $binary_file_extension = ".bin";
our $wwsconf;
our %Conf = ();
=head2 FUNCTIONS
=over 4
=item load ( [ CONFIG_FILE ], [ NO_DB ], [ RETURN_RESULT ] )
Loads and parses the configuration file. Reports errors if any.
do not try to load database values if NO_DB is set;
do not change gloval hash %Conf if RETURN_RESULT is set;
## we known that's dirty, this proc should be rewritten without this global
## var %Conf
=back
=cut
sub load {
my $config_file = shift || get_sympa_conf();
my $no_db = shift; # No longer used.
my $return_result = shift;
my $force_reload;
my $config_err = 0;
my $unknown;
my %line_numbered_config;
$log->syslog('debug3',
'File %s has changed since the last cache. Loading file',
$config_file);
# Will force the robot.conf reloading, as sympa.conf is the default.
$force_reload = 1;
## Loading the Sympa main config file.
if (my $config_loading_result = _load_config_file_to_hash($config_file)) {
%line_numbered_config =
%{$config_loading_result->{'numbered_config'}};
%Conf = %{$config_loading_result->{'config'}};
$config_err = $config_loading_result->{'errors'};
$unknown = $config_loading_result->{unknown};
} else {
return undef;
}
# Returning the config file content if this is what has been asked.
return (\%line_numbered_config) if ($return_result);
# Users may define parameters with a typo or other errors. Check that
# the parameters
# we found in the config file are all well defined Sympa parameters.
$config_err += $unknown;
_set_listmasters_entry(\%Conf);
## Some parameters must have a value specifically defined in the
## config. If not, it is an error.
$config_err += _detect_missing_mandatory_parameters(\%Conf);
# Some parameters need special treatments to get their final values.
_infer_server_specific_parameter_values({'config_hash' => \%Conf,});
_infer_robot_parameter_values({'config_hash' => \%Conf});
if ($config_err) {
$log->syslog('err', 'Errors while parsing main config file %s',
$config_file);
return undef;
}
_store_source_file_name(
{'config_hash' => \%Conf, 'config_file' => $config_file});
#XXX_save_config_hash_to_binary({'config_hash' => \%Conf,});
if (my $missing_modules_count =
_check_cpan_modules_required_by_config({'config_hash' => \%Conf,})) {
$log->syslog('err', 'Warning: %d required modules are missing',
$missing_modules_count);
}
_load_server_specific_secondary_config_files({'config_hash' => \%Conf,});
_load_robot_secondary_config_files({'config_hash' => \%Conf});
## Load robot.conf files
unless (
load_robots(
{ 'config_hash' => \%Conf,
'force_reload' => $force_reload
}
)
) {
return undef;
}
##_create_robot_like_config_for_main_robot();
return 1;
}
## load each virtual robots configuration files
sub load_robots {
my $param = shift;
my @robots;
my $robots_list_ref = get_robots_list();
unless (defined $robots_list_ref) {
$log->syslog('err', 'Robots config loading failed');
return undef;
} else {
@robots = @{$robots_list_ref};
}
unless ($#robots > -1) {
return 1;
}
my $exiting = 0;
foreach my $robot (@robots) {
my $robot_config_file = "$Conf{'etc'}/$robot/robot.conf";
my $robot_conf = undef;
unless (
$robot_conf = _load_single_robot_config(
{ 'robot' => $robot,
'force_reload' => $param->{'force_reload'}
}
)
) {
$log->syslog(
'err',
'The config for robot %s contain errors: it could not be correctly loaded',
$robot
);
$exiting = 1;
} else {
$param->{'config_hash'}{'robots'}{$robot} = $robot_conf;
}
#_check_double_url_usage(
# {'config_hash' => $param->{'config_hash'}{'robots'}{$robot}});
}
return undef if ($exiting);
return 1;
}
## returns a robot conf parameter
sub get_robot_conf {
my ($robot, $key) = @_;
# Resolve alias.
my ($k, $o) = ($key, $key);
do {
($k, $o) = ($o, ($params{$o} // {})->{obsolete});
} while ($o and $params{$o});
$key = $k;
if (defined $robot and $robot ne '*') {
return $Conf{'robots'}{$robot}{$key}
if defined $Conf{'robots'}{$robot}
and defined $Conf{'robots'}{$robot}{$key};
}
# default
return $Conf{$key};
}
=over 4
=item get_sympa_conf
Gets path name of main config file.
Path name is taken from:
=over 4
=item 1
C<--config> command line option
=item 2
C<SYMPA_CONFIG> environment variable
=item 3
built-in default
=back
=back
=cut
our $sympa_config;
sub get_sympa_conf {
return $sympa_config || $ENV{'SYMPA_CONFIG'} || Sympa::Constants::CONFIG;
}
=over 4
=item get_wwsympa_conf
Gets path name of wwsympa.conf file.
Path name is taken from:
=over 4
=item 1
C<SYMPA_WWSCONFIG> environment variable
=item 2
built-in default
=back
=back
=cut
sub get_wwsympa_conf {
return $ENV{'SYMPA_WWSCONFIG'} || Sympa::Constants::WWSCONFIG;
}
# deletes all the *.conf.bin files.
# No longer used.
#sub delete_binaries;
# Return a reference to an array containing the names of the robots on the
# server.
sub get_robots_list {
$log->syslog('debug2', "Retrieving the list of robots on the server");
my $dh;
unless (opendir $dh, $Conf{'etc'}) {
$log->syslog('err',
'Unable to open directory %s for virtual robots config',
$Conf{'etc'});
return undef;
}
my @robots_list =
grep { !/\A[.]/ and -f ($Conf{'etc'} . '/' . $_ . '/robot.conf') }
readdir $dh;
closedir $dh;
return [@robots_list];
}
## Returns a hash containing the values of all the parameters of the group
## (as defined in Sympa::ConfDef) whose name is given as argument, in the
## context of the robot given as argument.
sub get_parameters_group {
my ($robot, $group) = @_;
$log->syslog('debug3', 'Getting parameters for group "%s"', $group);
my $param_hash;
foreach my $param_name (keys %{$params_by_categories->{$group}}) {
$param_hash->{$param_name} = get_robot_conf($robot, $param_name);
}
return $param_hash;
}
# Moved to: Sympa::WWW::Tools::get_color().
#sub get_db_conf;
# Moved to: Sympa::WWW::Tools::set_color().
#sub set_robot_conf;
# Store configs to database
# Deprecated.
#sub conf_2_db;
## Check required files and create them if required
sub checkfiles_as_root {
my $config_err = 0;
## Check aliases file
unless (-f $Conf{'sendmail_aliases'}
or lc $Conf{'sendmail_aliases'} eq 'none') {
my $ofh;
unless (open $ofh, '>', $Conf{'sendmail_aliases'}) {
$log->syslog(
'err',
"Failed to create aliases file %s",
$Conf{'sendmail_aliases'}
);
return undef;
}
print $ofh
"## This aliases file is dedicated to Sympa Mailing List Manager\n";
print $ofh
"## You should edit your sendmail.mc or sendmail.cf file to declare it\n";
close $ofh;
$log->syslog(
'notice',
"Created missing file %s",
$Conf{'sendmail_aliases'}
);
unless (
Sympa::Tools::File::set_file_rights(
file => $Conf{'sendmail_aliases'},
user => Sympa::Constants::USER,
group => Sympa::Constants::GROUP,
mode => 0644,
)
) {
$log->syslog('err', 'Unable to set rights on %s',
$Conf{'db_name'});
return undef;
}
}
foreach my $robot (keys %{$Conf{'robots'}}) {
# create static content directory
my $dir = get_robot_conf($robot, 'static_content_path');
if ($dir ne '' && !-d $dir) {
unless (mkdir($dir, 0775)) {
$log->syslog('err', 'Unable to create directory %s: %m',
$dir);
$config_err++;
}
unless (
Sympa::Tools::File::set_file_rights(
file => $dir,
user => Sympa::Constants::USER,
group => Sympa::Constants::GROUP,
)
) {
$log->syslog('err', 'Unable to set rights on %s',
$Conf{'db_name'});
return undef;
}
}
}
return 1;
}
## Check if data structures are uptodate
## If not, no operation should be performed before the upgrade process is run
sub data_structure_uptodate {
my $version_file =
Conf::get_robot_conf('*', 'etc') . '/data_structure.version';
my $data_structure_version;
if (-f $version_file) {
my $fh;
unless (open $fh, '<', $version_file) {
$log->syslog('err', 'Unable to open %s: %m', $version_file);
return undef;
}
while (<$fh>) {
next if /^\s*$/;
next if /^\s*\#/;
chomp;
$data_structure_version = $_;
last;
}
close $fh;
}
if (defined $data_structure_version
and $data_structure_version ne Sympa::Constants::VERSION) {
$log->syslog('err',
"Data structure (%s) is not uptodate for current release (%s)",
$data_structure_version, Sympa::Constants::VERSION);
return 0;
}
return 1;
}
# Check if cookie parameter was changed.
# Old name: tools::cookie_changed().
# Deprecated: No longer used.
#sub cookie_changed;
## Check a few files
sub checkfiles {
my $config_err = 0;
foreach my $p (qw(sendmail antivirus_path)) {
next unless $Conf{$p};
unless (-x $Conf{$p}) {
$log->syslog('err', "File %s does not exist or is not executable",
$Conf{$p});
$config_err++;
}
}
foreach my $qdir (qw(spool queuetask tmpdir)) {
unless (-d $Conf{$qdir}) {
$log->syslog('info', 'Creating spool %s', $Conf{$qdir});
unless (mkdir($Conf{$qdir}, 0775)) {
$log->syslog('err', 'Unable to create spool %s',
$Conf{$qdir});
$config_err++;
}
unless (
Sympa::Tools::File::set_file_rights(
file => $Conf{$qdir},
user => Sympa::Constants::USER,
group => Sympa::Constants::GROUP,
)
) {
$log->syslog('err', 'Unable to set rights on %s',
$Conf{$qdir});
$config_err++;
}
}
}
# Check if directory parameters point to the same directory.
my @keys = qw(bounce_path etc home
queue queueauth queuebounce queuebulk queuedigest
queuemod queueoutgoing queuesubscribe queuetask
queuetopic spool tmpdir viewmail_dir);
push @keys, 'queueautomatic'
if $Conf::Conf{'automatic_list_feature'} eq 'on';
my %dirs = (Sympa::Constants::PIDDIR() => 'PID directory');
foreach my $key (@keys) {
my $val = $Conf::Conf{$key};
next unless $val;
if ($dirs{$val}) {
$log->syslog(
'err',
'Error in config: %s and %s parameters pointing to the same directory (%s)',
$dirs{$val},
$key,
$val
);
$config_err++;
} else {
$dirs{$val} = $key;
}
}
# Create pictures directory. FIXME: Would be created on demand.
my $pictures_dir = $Conf::Conf{'pictures_path'};
unless (-d $pictures_dir) {
unless (mkdir $pictures_dir, 0775) {
$log->syslog('err', 'Unable to create directory %s',
$pictures_dir);
$config_err++;
} else {
chmod 0775, $pictures_dir; # set masked bits.
my $index_path = $pictures_dir . '/index.html';
my $fh;
unless (open $fh, '>', $index_path) {
$log->syslog(
'err',
'Unable to create %s as an empty file to protect directory',
$index_path
);
} else {
close $fh;
}
}
}
#update_css();
return undef if ($config_err);
return 1;
}
## return 1 if the parameter is a known robot
## Valid options :
## 'just_try' : prevent error logs if robot is not valid
sub valid_robot {
my $robot = shift;
my $options = shift;
## Main host
return 1 if ($robot eq $Conf{'domain'});
## Missing etc directory
unless (-d $Conf{'etc'} . '/' . $robot) {
$log->syslog(
'err', 'Robot %s undefined; no %s directory',
$robot, $Conf{'etc'} . '/' . $robot
) unless ($options->{'just_try'});
return undef;
}
## Missing expl directory
unless (-d $Conf{'home'} . '/' . $robot) {
$log->syslog(
'err', 'Robot %s undefined; no %s directory',
$robot, $Conf{'home'} . '/' . $robot
) unless ($options->{'just_try'});
return undef;
}
## Robot not loaded
unless (defined $Conf{'robots'}{$robot}) {
$log->syslog('err', 'Robot %s was not loaded by this Sympa process',
$robot)
unless ($options->{'just_try'});
return undef;
}
return 1;
}
# Returns the SSO record correponding to the provided service_id
# return undef if none was found
# Old name: get_sso_by_id().
sub get_auth_service {
my $robot = shift;
my $auth_type = shift;
my $service_id = shift;
if ($auth_type eq 'cas') {
return undef unless $service_id;
return [
grep {
$_->{auth_type} eq $auth_type
and $_->{auth_service_name}
and $_->{auth_service_name} eq $service_id
} @{$Conf{'auth_services'}{$robot}}
]->[-1];
} elsif ($auth_type eq 'generic_sso') {
return undef unless $service_id;
return [
grep {
$_->{auth_type} eq $auth_type
and $_->{service_id}
and $_->{service_id} eq $service_id
} @{$Conf{'auth_services'}{$robot}}
]->[-1];
}
return undef;
}
##########################################
## Low level subs. Not supposed to be called from other modules.
##########################################
sub _load_auth {
$log->syslog('debug3', '(%s, %s)', @_);
my $that = shift || '*';
my $config_file = Sympa::search_fullpath($that, 'auth.conf');
die sprintf 'No auth.conf for %s', $that
unless $config_file and -r $config_file;
my $robot = ($that and $that ne '*') ? $that : $Conf{'domain'};
my $line_num = 0;
my $config_err = 0;
my @paragraphs;
my %result;
my $current_paragraph;
my %valid_keywords = (
'cgi' => {
'auth_scheme' => '.*',
'remote_user_variable' => '.+',
'regexp' => '.*',
'negative_regexp' => '.*',
},
'ldap' => {
'regexp' => '.*',
'negative_regexp' => '.*',
'host' => '[\w\.\-]+(:\d+)?(\s*,\s*[\w\.\-]+(:\d+)?)*',
'timeout' => '\d+',
'suffix' => '.+',
'bind_dn' => '.+',
'bind_password' => '.+',
'get_dn_by_uid_filter' => '.+',
'get_dn_by_email_filter' => '.+',
'email_attribute' => Sympa::Regexps::ldap_attrdesc(),
'alternative_email_attribute' => '.*', # Obsoleted
'scope' => 'base|one|sub',
'deref' => 'never|search|find|always',
'authentication_info_url' => 'http(s)?:/.*',
'use_tls' => 'starttls|ldaps|none',
'use_ssl' => '1', # Obsoleted
'use_start_tls' => '1', # Obsoleted
'ssl_version' => 'sslv2/3|sslv2|sslv3|tlsv1|tlsv1_[123]',
'ssl_ciphers' => '[\w:]+',
'ssl_cert' => '.+',
'ssl_key' => '.+',
'ca_verify' => '\w+',
'ca_path' => '.+',
'ca_file' => '.+',
},
'user_table' => {
'regexp' => '.*',
'negative_regexp' => '.*'
},
'cas' => {
'base_url' => 'http(s)?:/.*',
'non_blocking_redirection' => 'on|off',
'login_path' => '.*',
'logout_path' => '.*',
'service_validate_path' => '.*',
'proxy_path' => '.*',
'proxy_validate_path' => '.*',
'auth_service_name' => '[\w\-\.]+',
'auth_service_friendly_name' => '.*',
'authentication_info_url' => 'http(s)?:/.*',
'host' => '[\w\.\-]+(:\d+)?(\s*,\s*[\w\.\-]+(:\d+)?)*',
'bind_dn' => '.+',
'bind_password' => '.+',
'timeout' => '\d+',
'suffix' => '.+',
'scope' => 'base|one|sub',
'deref' => 'never|search|find|always',
'get_email_by_uid_filter' => '.+',
'email_attribute' => Sympa::Regexps::ldap_attrdesc(),
'use_tls' => 'starttls|ldaps|none',
'use_ssl' => '1', # Obsoleted
'use_start_tls' => '1', # Obsoleted
'ssl_version' => 'sslv2/3|sslv2|sslv3|tlsv1|tlsv1_[123]',
'ssl_ciphers' => '[\w:]+',
'ssl_cert' => '.+',
'ssl_key' => '.+',
'ca_verify' => '\w+',
'ca_path' => '.+',
'ca_file' => '.+',
},
'generic_sso' => {
'service_name' => '.+',
'service_id' => '\S+',
'http_header_prefix' => '\w+',
'http_header_list' => '[\w\.\-\,]+',
'email_http_header' => '\w+',
'http_header_value_separator' => '.+',
'logout_url' => '.+',
'host' => '[\w\.\-]+(:\d+)?(\s*,\s*[\w\.\-]+(:\d+)?)*',
'bind_dn' => '.+',
'bind_password' => '.+',
'timeout' => '\d+',
'suffix' => '.+',
'scope' => 'base|one|sub',
'deref' => 'never|search|find|always',
'get_email_by_uid_filter' => '.+',
'email_attribute' => Sympa::Regexps::ldap_attrdesc(),
'use_tls' => 'starttls|ldaps|none',
'use_ssl' => '1', # Obsoleted
'use_start_tls' => '1', # Obsoleted
'ssl_version' => 'sslv2/3|sslv2|sslv3|tlsv1|tlsv1_[123]',
'ssl_ciphers' => '[\w:]+',
'ssl_cert' => '.+',
'ssl_key' => '.+',
'ca_verify' => '\w+',
'ca_path' => '.+',
'ca_file' => '.+',
'force_email_verify' => '1',
'internal_email_by_netid' => '1',
'netid_http_header' => '[\w\-\.]+',
},
'authentication_info_url' => 'http(s)?:/.*'
);
# Open the configuration file or return and read the lines.
my $ifh;
unless (open $ifh, '<', $config_file) {
$log->syslog('notice', 'Unable to open %s: %m', $config_file);
return undef;
}
## Parsing auth.conf
while (<$ifh>) {
$line_num++;
next if (/^\s*[\#\;]/o);
if (/^\s*authentication_info_url\s+(.*\S)\s*$/o) {
$Conf{'authentication_info_url'}{$robot} = $1;
next;
} elsif (/^\s*(cgi|ldap|user_table|cas|generic_sso)\s*$/io) {
$current_paragraph->{'auth_type'} = lc($1);
} elsif (/^\s*(\S+)\s+(.*\S)\s*$/o) {
my ($keyword, $value) = ($1, $2);
# Workaround: Some parameters required by cas and generic_sso auth
# types may be prefixed by "ldap_", but LDAP database driver
# requires those not prefixed.
$keyword =~ s/\Aldap_//;
unless (
defined $valid_keywords{$current_paragraph->{'auth_type'}}
{$keyword}) {
$log->syslog('err', 'Unknown keyword "%s" in %s line %d',
$keyword, $config_file, $line_num);
next;
}
unless ($value =~
/^$valid_keywords{$current_paragraph->{'auth_type'}}{$keyword}$/
) {
$log->syslog('err',
'Unknown format "%s" for keyword "%s" in %s line %d',
$value, $keyword, $config_file, $line_num);
next;
}
## Allow white spaces between hosts
if ($keyword =~ /host$/) {
$value =~ s/\s//g;
}
$current_paragraph->{$keyword} = $value;
}
## process current paragraph
if (/^\s+$/o or eof $ifh) {
if (defined($current_paragraph)) {
# Parameters obsoleted as of 6.2.15.
if ($current_paragraph->{use_start_tls}) {
$current_paragraph->{use_tls} = 'starttls';
} elsif ($current_paragraph->{use_ssl}) {
$current_paragraph->{use_tls} = 'ldaps';
}
delete $current_paragraph->{use_start_tls};
delete $current_paragraph->{use_ssl};
if ($current_paragraph->{'auth_type'} eq 'cas') {
unless (defined $current_paragraph->{'base_url'}) {
$log->syslog('err',
'Incorrect CAS paragraph in auth.conf');
next;
}
eval "require AuthCAS";
if ($EVAL_ERROR) {
$log->syslog('err',
'Failed to load AuthCAS perl module');
return undef;
}
my $cas_param =
{casUrl => $current_paragraph->{'base_url'}};
## Optional parameters
## We should also cope with X509 CAs
$cas_param->{'loginPath'} =
$current_paragraph->{'login_path'}
if (defined $current_paragraph->{'login_path'});
$cas_param->{'logoutPath'} =
$current_paragraph->{'logout_path'}
if (defined $current_paragraph->{'logout_path'});
$cas_param->{'serviceValidatePath'} =
$current_paragraph->{'service_validate_path'}
if (
defined $current_paragraph->{'service_validate_path'}
);
$cas_param->{'proxyPath'} =
$current_paragraph->{'proxy_path'}
if (defined $current_paragraph->{'proxy_path'});
$cas_param->{'proxyValidatePath'} =
$current_paragraph->{'proxy_validate_path'}
if (
defined $current_paragraph->{'proxy_validate_path'});
$current_paragraph->{'cas_server'} =
AuthCAS->new(%{$cas_param});
unless (defined $current_paragraph->{'cas_server'}) {
$log->syslog(
'err',
'Failed to create CAS object for %s: %s',
$current_paragraph->{'base_url'},
AuthCAS::get_errors()
);
next;
}
## Force the default scope because '' is interpreted as
## 'base'
$current_paragraph->{'scope'} ||= 'sub';
$current_paragraph->{'deref'} ||= 'find';
} elsif ($current_paragraph->{'auth_type'} eq 'generic_sso') {
## Force the default scope because '' is interpreted as
## 'base'
$current_paragraph->{'scope'} ||= 'sub';
$current_paragraph->{'deref'} ||= 'find';
## default value for http_header_value_separator is ';'
$current_paragraph->{'http_header_value_separator'} ||=
';';
## CGI.pm changes environment variable names ('-' => '_')
## declared environment variable names needs to be
## transformed accordingly
foreach my $parameter ('http_header_list',
'email_http_header', 'netid_http_header') {
$current_paragraph->{$parameter} =~ s/\-/\_/g
if (defined $current_paragraph->{$parameter});
}
} elsif ($current_paragraph->{'auth_type'} eq 'ldap') {
## Force the default scope because '' is interpreted as
## 'base'
$current_paragraph->{'scope'} ||= 'sub';
$current_paragraph->{'deref'} ||= 'find';
} elsif ($current_paragraph->{'auth_type'} eq 'user_table') {
;
} elsif ($current_paragraph->{'auth_type'} eq 'cgi') {
$current_paragraph->{'remote_user_variable'} ||=
'REMOTE_USER';
}
# setting default
$current_paragraph->{'regexp'} = '.*'
unless (defined($current_paragraph->{'regexp'}));
$current_paragraph->{'non_blocking_redirection'} = 'on'
unless (
defined($current_paragraph->{'non_blocking_redirection'})
);
push(@paragraphs, $current_paragraph);
undef $current_paragraph;
}
next;
}
}
close $ifh;
return \@paragraphs;
}
## load charset.conf file (charset mapping for service messages)
sub load_charset {
my $charset = {};
my $config_file = Sympa::search_fullpath('*', 'charset.conf');
return {} unless $config_file;
my $ifh;
unless (open $ifh, '<', $config_file) {
$log->syslog('err', 'Unable to read configuration file %s: %m',
$config_file);
return {};
}
while (<$ifh>) {
chomp $_;
s/\s*#.*//;
s/^\s+//;
next unless /\S/;
my ($lang, $cset) = split(/\s+/, $_);
unless ($cset) {
$log->syslog('err',
'Charset name is missing in configuration file %s line %d',
$config_file, $NR);
next;
}
# canonicalize lang if possible.
$lang = Sympa::Language::canonic_lang($lang) || $lang;
$charset->{$lang} = $cset;
}
close $ifh;
return $charset;
}
=over
=item lang2charset ( $lang )
Gets charset for e-mail messages sent by Sympa.
Parameters:
$lang - language.
Returns:
Charset name.
If it is not known, returns default charset.
=back
=cut
# Old name: tools::lang2charset().
# FIXME: This would be moved to such as Site package.
sub lang2charset {
my $lang = shift;
my $locale2charset;
if ($lang and %Conf::Conf # configuration loaded
and $locale2charset = $Conf::Conf{'locale2charset'}
) {