]> git.donarmstrong.com Git - debbugs.git/blob - Debbugs/Config.pm
untaint $ENV{DEBBUGS_CONFIG_FILE} when appropriate
[debbugs.git] / Debbugs / Config.pm
1
2 package Debbugs::Config;
3
4 =head1 NAME
5
6 Debbugs::Config -- Configuration information for debbugs
7
8 =head1 SYNOPSIS
9
10  use Debbugs::Config;
11
12 # to get the compatiblity interface
13
14  use Debbugs::Config qw(:globals);
15
16 =head1 DESCRIPTION
17
18 This module provides configuration variables for all of debbugs.
19
20 =head1 CONFIGURATION FILES
21
22 The default configuration file location is /etc/debbugs/config; this
23 configuration file location can be set by modifying the
24 DEBBUGS_CONFIG_FILE env variable to point at a different location.
25
26 =cut
27
28 use warnings;
29 use strict;
30 use vars qw($VERSION $DEBUG %EXPORT_TAGS @EXPORT_OK @EXPORT $USING_GLOBALS %config);
31 use base qw(Exporter);
32
33 BEGIN {
34      # set the version for version checking
35      $VERSION     = 1.00;
36      $DEBUG = 0 unless defined $DEBUG;
37      $USING_GLOBALS = 0;
38
39      @EXPORT = ();
40      %EXPORT_TAGS = (globals => [qw($gEmailDomain $gListDomain $gWebHost $gWebHostBugDir),
41                                  qw($gWebDomain $gHTMLSuffix $gCGIDomain $gMirrors),
42                                  qw($gPackagePages $gSubscriptionDomain $gProject $gProjectTitle),
43                                  qw($gMaintainer $gMaintainerWebpage $gMaintainerEmail $gUnknownMaintainerEmail),
44                                  qw($gSubmitList $gMaintList $gQuietList $gForwardList),
45                                  qw($gDoneList $gRequestList $gSubmitterList $gControlList),
46                                  qw($gSummaryList $gMirrorList $gMailer $gBug),
47                                  qw($gBugs $gRemoveAge $gSaveOldBugs $gDefaultSeverity),
48                                  qw($gShowSeverities $gBounceFroms $gConfigDir $gSpoolDir),
49                                  qw($gIncomingDir $gWebDir $gDocDir $gMaintainerFile),
50                                  qw($gMaintainerFileOverride $gPseudoDescFile $gPackageSource),
51                                  qw($gVersionPackagesDir $gVersionIndex $gBinarySourceMap $gSourceBinaryMap),
52                                  qw($gSendmail $gLibPath),
53                                  qw(%gSeverityDisplay @gTags @gSeverityList @gStrongSeverities),
54                                  qw(%gSearchEstraier),
55                                 ],
56                      text     => [qw($gBadEmailPrefix $gHTMLTail $gHTMLExpireNote),
57                                  ],
58                      config   => [qw(%config)],
59                     );
60      @EXPORT_OK = ();
61      Exporter::export_ok_tags(qw(globals text config));
62      $EXPORT_TAGS{all} = [@EXPORT_OK];
63 }
64
65 use File::Basename qw(dirname);
66 use IO::File;
67 use Safe;
68
69 =head1 CONFIGURATION VARIABLES
70
71 =head2 General Configuration
72
73 =over
74
75 =cut
76
77 # read in the files;
78 %config = ();
79 # untaint $ENV{DEBBUGS_CONFIG_FILE} if it's owned by us
80 # This enables us to test things that are -T.
81 if (exists $ENV{DEBBUGS_CONFIG_FILE} and
82     ${[stat($ENV{DEBBUGS_CONFIG_FILE})]}[4] = $<) {
83      $ENV{DEBBUGS_CONFIG_FILE} =~ /(.+)/;
84      $ENV{DEBBUGS_CONFIG_FILE} = $1;
85 }
86 read_config(exists $ENV{DEBBUGS_CONFIG_FILE}?$ENV{DEBBUGS_CONFIG_FILE}:'/etc/debbugs/config');
87
88 =item email_domain $gEmailDomain
89
90 The email domain of the bts
91
92 =cut
93
94 set_default(\%config,'email_domain','bugs.something');
95
96 =item list_domain $gListDomain
97
98 The list domain of the bts, defaults to the email domain
99
100 =cut
101
102 set_default(\%config,'list_domain',$config{email_domain});
103
104 =item web_host $gWebHost
105
106 The web host of the bts; defaults to the email domain
107
108 =cut
109
110 set_default(\%config,'web_host',$config{email_domain});
111
112 =item web_host_bug_dir $gWebHostDir
113
114 The directory of the web host on which bugs are kept, defaults to C<''>
115
116 =cut
117
118 set_default(\%config,'web_host_bug_dir','');
119
120 =item web_domain $gWebDomain
121
122 Full path of the web domain where bugs are kept, defaults to the
123 concatenation of L</web_host> and L</web_host_bug_dir>
124
125 =cut
126
127 set_default(\%config,'web_domain',$config{web_host}.'/'.$config{web_host_bug_dir});
128
129 =item html_suffix $gHTMLSuffix
130
131 Suffix of html pages, defaults to .html
132
133 =cut
134
135 set_default(\%config,'html_suffix','.html');
136
137 =item cgi_domain $gCGIDomain
138
139 Full path of the web domain where cgi scripts are kept. Defaults to
140 the concatentation of L</web_host> and cgi.
141
142 =cut
143
144 set_default(\%config,'cgi_domain',$config{web_domain}.($config{web_domain}=~m{/$}?'':'/').'cgi');
145
146 =item mirrors @gMirrors
147
148 List of mirrors [What these mirrors are used for, no one knows.]
149
150 =cut
151
152
153 set_default(\%config,'mirrors',[]);
154
155 =item package_pages  $gPackagePages
156
157 Domain where the package pages are kept; links should work in a
158 package_pages/foopackage manner. Defaults to undef, which means that
159 package links will not be made.
160
161 =cut
162
163
164 set_default(\%config,'package_pages',undef);
165
166 =item subscription_domain $gSubscriptionDomain
167
168 Domain where subscriptions to package lists happen
169
170 =cut
171
172
173 set_default(\%config,'subscription_domain',undef);
174
175 =back
176
177 =cut
178
179
180 =head2 Project Identification
181
182 =over
183
184 =item project $gProject
185
186 Name of the project
187
188 Default: 'Something'
189
190 =cut
191
192 set_default(\%config,'project','Something');
193
194 =item project_title $gProjectTitle
195
196 Name of this install of Debbugs, defaults to "L</project> Debbugs Install"
197
198 Default: "$config{project} Debbugs Install"
199
200 =cut
201
202 set_default(\%config,'project_title',"$config{project} Debbugs Install");
203
204 =item maintainer $gMaintainer
205
206 Name of the maintainer of this debbugs install
207
208 Default: 'Local DebBugs Owner's
209
210 =cut
211
212 set_default(\%config,'maintainer','Local DebBugs Owner');
213
214 =item maintainer_webpage $gMaintainerWebpage
215
216 Webpage of the maintainer of this install of debbugs
217
218 Default: "$config{web_domain}/~owner"
219
220 =cut
221
222 set_default(\%config,'maintainer_webpage',"$config{web_domain}/~owner");
223
224 =item maintainer_email
225
226 Email address of the maintainer of this Debbugs install
227
228 Default: 'root@'.$config{email_domain}
229
230 =cut
231
232 set_default(\%config,'maintainer_email','root@'.$config{email_domain});
233
234 =item unknown_maintainer_email
235
236 Email address where packages with an unknown maintainer will be sent
237
238 Default: $config{maintainer_email}
239
240 =back
241
242 =cut
243
244 set_default(\%config,'unknown_maintainer_email',$config{maintainer_email});
245
246 =head2 BTS Mailing Lists
247
248
249 =over
250
251 =item submit_list
252
253 =item maint_list
254
255 =item forward_list
256
257 =item done_list
258
259 =item request_list
260
261 =item submitter_list
262
263 =item control_list
264
265 =item summary_list
266
267 =item mirror_list
268
269 =back
270
271 =cut
272
273 set_default(\%config,   'submit_list',   'bug-submit-list');
274 set_default(\%config,    'maint_list',    'bug-maint-list');
275 set_default(\%config,    'quiet_list',    'bug-quiet-list');
276 set_default(\%config,  'forward_list',  'bug-forward-list');
277 set_default(\%config,     'done_list',     'bug-done-list');
278 set_default(\%config,  'request_list',  'bug-request-list');
279 set_default(\%config,'submitter_list','bug-submitter-list');
280 set_default(\%config,  'control_list',  'bug-control-list');
281 set_default(\%config,  'summary_list',  'bug-summary-list');
282 set_default(\%config,   'mirror_list',   'bug-mirror-list');
283
284 =head2 Misc Options
285
286 =over
287
288 =cut
289
290 set_default(\%config,'mailer','exim');
291 set_default(\%config,'bug','bug');
292 set_default(\%config,'bugs','bugs');
293
294 =item remove_age
295
296 Age at which bugs are archived/removed
297
298 Default: 28
299
300 =cut
301
302 set_default(\%config,'remove_age',28);
303
304 =item save_old_bugs
305
306 Whether old bugs are saved or deleted
307
308 Default: 1
309
310 =cut
311
312 set_default(\%config,'save_old_bugs',1);
313
314 =item distributions
315
316 List of valid distributions
317
318 Default: qw(experimental unstable testing stable oldstable);
319
320 =cut
321
322 set_default(\%config,'distributions',[qw(experimental unstable testing stable oldstable)]);
323
324 =item removal_distribution_tags
325
326 Tags which specifiy distributions to check
327
328 Default: @{$config{distributions}}
329
330 =cut
331
332 set_default(\%config,'removal_distribution_tags',
333             [@{$config{distributions}}]);
334
335 =item removal_default_distribution_tags
336
337 For removal/archival purposes, all bugs are assumed to have these tags
338 set.
339
340 Default: qw(unstable testing);
341
342 =cut
343
344 set_default(\%config,'removal_default_distribution_tags',
345             [qw(unstable testing)]
346            );
347
348 set_default(\%config,'default_severity','normal');
349 set_default(\%config,'show_severities','critical, grave, normal, minor, wishlist');
350 set_default(\%config,'strong_severities',[qw(critical grave)]);
351 set_default(\%config,'severity_list',[qw(critical grave normal wishlist)]);
352 set_default(\%config,'severity_display',{critical => "Critical $config{bugs}",
353                                          grave    => "Grave $config{bugs}",
354                                          normal   => "Normal $config{bugs}",
355                                          wishlist => "Wishlist $config{bugs}",
356                                         });
357
358 set_default(\%config,'tags',[qw(patch wontfix moreinfo unreproducible fixed),
359                              @{$config{distributions}}
360                             ]);
361
362 set_default(\%config,'bounce_froms','^mailer|^da?emon|^post.*mast|^root|^wpuser|^mmdf|^smt.*|'.
363             '^mrgate|^vmmail|^mail.*system|^uucp|-maiser-|^mal\@|'.
364             '^mail.*agent|^tcpmail|^bitmail|^mailman');
365
366 set_default(\%config,'config_dir',dirname(exists $ENV{DEBBUGS_CONFIG_FILE}?$ENV{DEBBUGS_CONFIG_FILE}:'/etc/debbugs/config'));
367 set_default(\%config,'spool_dir','/var/lib/debbugs/spool');
368 set_default(\%config,'incoming_dir','incoming');
369 set_default(\%config,'web_dir','/var/lib/debbugs/www');
370 set_default(\%config,'doc_dir','/var/lib/debbugs/www/txt');
371 set_default(\%config,'lib_path','/usr/lib/debbugs');
372
373 set_default(\%config,'maintainer_file',$config{config_dir}.'/Maintainers');
374 set_default(\%config,'maintainer_file_override',$config{config_dir}.'/Maintainers.override');
375 set_default(\%config,'pseudo_desc_file',$config{config_dir}.'/pseudo-packages.description');
376 set_default(\%config,'package_source',$config{config_dir}.'/indices/sources');
377
378 set_default(\%config,'version_packages_dir',$config{spool_dir}.'/../versions/pkg');
379
380 =item sendmail
381
382 Sets the sendmail binary to execute; defaults to /usr/lib/sendmail
383
384 =cut
385
386 set_default(\%config,'sendmail',$config{sendmail},'/usr/lib/sendmail');
387
388 =back
389
390
391 =head2 Text Fields
392
393 The following are the only text fields in general use in the scripts;
394 a few additional text fields are defined in text.in, but are only used
395 in db2html and a few other specialty scripts.
396
397 Earlier versions of debbugs defined these values in /etc/debbugs/text,
398 but now they are required to be in the configuration file. [Eventually
399 the longer ones will move out into a fully fledged template system.]
400
401 =cut
402
403 =over
404
405 =item bad_email_prefix
406
407 This prefixes the text of all lines in a bad e-mail message ack.
408
409 =cut
410
411 set_default(\%config,'bad_email_prefix','');
412
413 =item html_tail
414
415 This shows up at the end of (most) html pages
416
417 =cut
418
419 set_default(\%config,'html_tail',<<END);
420  <ADDRESS>$config{maintainer} &lt;<A HREF=\"mailto:$config{maintainer_email}\">$config{maintainer_email}</A>&gt;.
421  Last modified:
422  <!--timestamp-->
423  SUBSTITUTE_DTIME
424  <!--timestamp-->
425  <P>
426  <A HREF=\"http://$config{web_domain}/\">Debian $config{bug} tracking system</A><BR>
427  Copyright (C) 1999 Darren O. Benham,
428  1997,2003 nCipher Corporation Ltd,
429  1994-97 Ian Jackson.
430  </ADDRESS>
431 END
432
433
434 =item html_expire_note
435
436 This message explains what happens to archive/remove-able bugs
437
438 =cut
439
440 set_default(\%config,'html_expire_note',
441             "(Closed $config{bugs} are archived $config{remove_age} days after the last related message is received.)");
442
443 =back
444
445 =cut
446
447
448 sub read_config{
449      my ($conf_file) = @_;
450      # first, figure out what type of file we're reading in.
451      my $fh = new IO::File $conf_file,'r'
452           or die "Unable to open configuration file $conf_file for reading: $!";
453      # A new version configuration file must have a comment as its first line
454      my $first_line = <$fh>;
455      my ($version) = defined $first_line?$first_line =~ /VERSION:\s*(\d+)/i:undef;
456      if (defined $version) {
457           if ($version == 1) {
458                # Do something here;
459                die "Version 1 configuration files not implemented yet";
460           }
461           else {
462                die "Version $version configuration files are not supported";
463           }
464      }
465      else {
466           # Ugh. Old configuration file
467           # What we do here is we create a new Safe compartment
468           # so fucked up crap in the config file doesn't sink us.
469           my $cpt = new Safe or die "Unable to create safe compartment";
470           # perldoc Opcode; for details
471           $cpt->permit('require',':filesys_read','entereval','caller','pack','unpack','dofile');
472           $cpt->reval(qq(require '$conf_file';));
473           die "Error in configuration file: $@" if $@;
474           # Now what we do is check out the contents of %EXPORT_TAGS to see exactly which variables
475           # we want to glob in from the configuration file
476           for my $variable (@{$EXPORT_TAGS{globals}}) {
477                my ($hash_name,$glob_name,$glob_type) = __convert_name($variable);
478                my $var_glob = $cpt->varglob($glob_name);
479                my $value; #= $cpt->reval("return $variable");
480                # print STDERR "$variable $value",qq(\n);
481                if (defined $var_glob) {{
482                     no strict 'refs';
483                     if ($glob_type eq '%') {
484                          $value = {%{*{$var_glob}}} if defined *{$var_glob}{HASH};
485                     }
486                     elsif ($glob_type eq '@') {
487                          $value = [@{*{$var_glob}}] if defined *{$var_glob}{ARRAY};
488                     }
489                     else {
490                          $value = ${*{$var_glob}};
491                     }
492                     # We punt here, because we can't tell if the value was
493                     # defined intentionally, or if it was just left alone;
494                     # this tries to set sane defaults.
495                     set_default(\%config,$hash_name,$value) if defined $value;
496                }}
497           }
498      }
499 }
500
501 sub __convert_name{
502      my ($variable) = @_;
503      my $hash_name = $variable;
504      $hash_name =~ s/^([\$\%\@])g//;
505      my $glob_type = $1;
506      my $glob_name = 'g'.$hash_name;
507      $hash_name =~ s/(HTML|CGI)/ucfirst(lc($1))/ge;
508      $hash_name =~ s/^([A-Z]+)/lc($1)/e;
509      $hash_name =~ s/([A-Z]+)/'_'.lc($1)/ge;
510      return $hash_name unless wantarray;
511      return ($hash_name,$glob_name,$glob_type);
512 }
513
514 # set_default
515
516 # sets the configuration hash to the default value if it's not set,
517 # otherwise doesn't do anything
518 # If $USING_GLOBALS, then sets an appropriate global.
519
520 sub set_default{
521      my ($config,$option,$value) = @_;
522      my $varname;
523      if ($USING_GLOBALS) {
524           # fix up the variable name
525           $varname = 'g'.join('',map {ucfirst $_} split /_/, $option);
526           # Fix stupid HTML names
527           $varname =~ s/(Html|Cgi)/uc($1)/ge;
528      }
529      # update the configuration value
530      if (not $USING_GLOBALS and not exists $config->{$option}) {
531           $config->{$option} = $value;
532      }
533      elsif ($USING_GLOBALS) {{
534           no strict 'refs';
535           # Need to check if a value has already been set in a global
536           if (defined *{"Debbugs::Config::${varname}"}) {
537                $config->{$option} = *{"Debbugs::Config::${varname}"};
538           }
539           else {
540                $config->{$option} = $value;
541           }
542      }}
543      if ($USING_GLOBALS) {{
544           no strict 'refs';
545           *{"Debbugs::Config::${varname}"} = $config->{$option};
546      }}
547 }
548
549
550 ### import magick
551
552 # All we care about here is whether we've been called with the globals or text option;
553 # if so, then we need to export some symbols back up.
554 # In any event, we call exporter.
555
556 sub import {
557      if (grep /^:(?:text|globals)$/, @_) {
558           $USING_GLOBALS=1;
559           for my $variable (map {@$_} @EXPORT_TAGS{map{(/^:(text|globals)$/?($1):())} @_}) {
560                my $tmp = $variable;
561                no strict 'refs';
562                # Yes, I don't care if these are only used once
563                no warnings 'once';
564                # No, it doesn't bother me that I'm assigning an undefined value to a typeglob
565                no warnings 'misc';
566                my ($hash_name,$glob_name,$glob_type) = __convert_name($variable);
567                $tmp =~ s/^[\%\$\@]//;
568                *{"Debbugs::Config::${tmp}"} = ref($config{$hash_name})?$config{$hash_name}:\$config{$hash_name};
569           }
570      }
571      Debbugs::Config->export_to_level(1,@_);
572 }
573
574
575 1;