This file is indexed.

/usr/share/perl5/EB/Config.pm is in eekboek 2.00.03-1.

This file is owned by root:root, with mode 0o644.

The actual contents of the file can be viewed below.

  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
#! perl --			-*- coding: utf-8 -*-

use utf8;

# Config.pm -- Configuration files.
# RCS Info        : $Id: Config.pm,v 1.33 2010/03/27 15:36:58 jv Exp $
# Author          : Johan Vromans
# Created On      : Fri Jan 20 17:57:13 2006
# Last Modified By: Johan Vromans
# Last Modified On: Sat Mar 27 16:36:56 2010
# Update Count    : 237
# Status          : Unknown, Use with caution!

package main;

our $cfg;
our $dbh;

package EB::Config;

use strict;
use warnings;
use Carp;
use File::Spec;

sub init_config {
    my ($pkg, $opts) = @_;
    my $app;

    Carp::croak("Internal error -- missing package arg for __PACKAGE__\n")
	unless $app = delete $opts->{app};

    $app = lc($app);

    return if $::cfg && $app && $::cfg->{app} eq lc($app);

    # Pre-parse @ARGV for "-f configfile".
    my $extraconf = $opts->{config};
    my $skipconfig = $opts->{nostdconf};

    # Resolve extraconf to a file name. It must exist.
    if ( $extraconf ) {
	if ( -d $extraconf ) {
	    my $f = File::Spec->catfile( $extraconf,
					 EB::Config::Handler::std_config($app) );
	    if ( -e $f ) {
		$extraconf = $f;
	    }
	    else {
		$extraconf = File::Spec->catfile($extraconf,
						 EB::Config::Handler::std_config_alt($app));
	    }
	}
	die("$extraconf: $!\n") unless -f $extraconf;
    }

    # Build the list of config files.
    my @cfgs;
    if ( !$skipconfig ) {
	@cfgs = ( File::Spec->catfile( "etc", $app,
				       EB::Config::Handler::std_config($app) ),
		  EB::Config::Handler::user_dir
		    ( $app, EB::Config::Handler::std_config($app) ),
		);
	unless ( $extraconf ) {
	    push(@cfgs, EB::Config::Handler::std_config($app));
	    $cfgs[-1] = EB::Config::Handler::std_config_alt($app) unless -e $cfgs[-1];
	}
    }
    push(@cfgs, $extraconf) if $extraconf;

    # Load configs.
    my $cfg = EB::Config::Handler->new($app);
    for my $file ( @cfgs ) {
	next unless -s $file;
	$cfg->load($file);
    }

    if ( $opts->{define} ) {
	while ( my ($k, $v) = each( %{ $opts->{define} } ) ) {
	    if ( $k =~ /^(\w+(?:::\w+)*)::?(\w+)/ ) {
		$cfg->newval($1, $2, $v);
	    }
	    else {
		warn("define error: \"$k\" = \"$v\"\n");
	    }
	}
    }

    $ENV{EB_LANG} = $cfg->val('locale','lang',
			      $ENV{EB_LANG}||$ENV{LANG}||
			      ($^O =~ /^(ms)?win/i ? "nl_NL.utf8" : "nl_NL"));

    $cfg->_plug(qw(locale       lang         EB_LANG));
    $ENV{LANG} = $cfg->val(qw(locale lang));

    $cfg->_plug(qw(database     name         EB_DB_NAME));

    if ( my $db = $cfg->val(qw(database name), undef) ) {
	$db =~ s/^eekboek_//;	# legacy
	$cfg->newval(qw(database     name), $db);
	$ENV{EB_DB_NAME} = $db;
    }

    $cfg->_plug(qw(database     host         EB_DB_HOST));
    $cfg->_plug(qw(database     port         EB_DB_PORT));
    $cfg->_plug(qw(database     user         EB_DB_USER));
    $cfg->_plug(qw(database     password     EB_DB_PASSWORD));

    $cfg->_plug(qw(csv          separator    EB_CSV_SEPARATOR));

    $cfg->_plug(qw(internal     now          EB_SQL_NOW));

    $cfg->_plug("internal sql", qw(trace     EB_SQL_TRACE));
    $cfg->_plug("internal sql", qw(prepstats EB_SQL_PREP_STATS));
    $cfg->_plug("internal sql", qw(replayout EB_SQL_REP_LAYOUT));

    if ( $cfg->val(__PACKAGE__, "showfiles", 0) ) {
	warn("Config files:\n  ",
	     join( "\n  ", $cfg->files ),  "\n");
    }

    if ( $cfg->val(__PACKAGE__, "dumpcfg", 0) ) {
	use Data::Dumper;
	warn(Dumper($cfg));
    }
    $::cfg = $cfg;
}

sub import {
    my ($self, $app) = @_;
    my $opts = ref($app) ? { %$app } : { app => $app };
    return if $cfg && $opts->{app} && $cfg->app eq lc($opts->{app});
    $cfg = $self->init_config($opts);
}

package EB::Config::Handler;

# Very simple inifile handler (read-only).

sub _key {
    my ($section, $parameter) = @_;
    $section.'::'.$parameter;
}

sub val {
    my ($self, $section, $parameter, $default) = @_;
    my $res;
    $res = $self->{data}->{ _key($section, $parameter) };
    $res = $default unless defined $res;
    Carp::cluck("=> missing config: \"" . _key($section, $parameter) . "\"\n")
      unless defined $res || @_ > 3;
    $res;
}

sub newval {
    my ($self, $section, $parameter, $value) = @_;
    $self->{data}->{ _key($section, $parameter) } = $value;
}

sub setval {
    my ($self, $section, $parameter, $value) = @_;
    my $key = _key( $section, $parameter );
    Carp::cluck("=> missing config: \"$key\"\n")
      unless exists $self->{data}->{ $key };
    $self->{data}->{ $key } = $value;
}

sub _plug {
    my ($self, $section, $parameter, $env) = @_;
    $self->newval($section, $parameter, $ENV{$env})
      if $ENV{$env} && !$self->val($section, $parameter, undef);
}

sub files {
    my ($self) = @_;
    return $self->{files}->[-1] unless wantarray;
    return @{ $self->{files} };
}

sub file {
    goto &files;		# for convenience
}

sub set_file {
    my ( $self, $file ) = @_;
    if ( $self->{files}->[0] eq '<empty>' ) {
	$self->{files} = [];
    }
    push( @{ $self->{files} }, $file );
}

sub app {
    my ($self) = @_;
    $self->{app};
}

sub new {
    my ($package, $app, $file) = @_;
    my $self = bless {}, $package;
    $self->{files} = [ '<empty>' ];
    $self->{data} = {};
    $self->{app} = $app;
    $self->load($file) if defined $file;
    return $self;
}

sub load {
    my ($self, $file) = @_;

    open( my $fd, "<:encoding(utf-8)", $file )
      or Carp::croak("Error opening config $file: $!\n");

    $self->set_file($file);

    my $section = "global";
    my $fail;
    while ( <$fd> ) {
	chomp;
	next unless /\S/;
	next if /^[#;]/;
	if ( /^\s*\[\s*(.*?)\s*\]\s*$/ ) {
	    $section = lc $1;
	    next;
	}
	if ( /^\s*(.*?)\s*=\s*(.*?)\s*$/ ) {
	    $self->{data}->{ _key($section, lc($1)) } = $2;
	    next;
	}
	Carp::cluck("Error in config $file, line $.:\n$_\n");
	$fail++;
    }
    Carp::croak("Error processing config $file, aborted\n")
	if $fail;

    $self;
}

sub printconf {
    my ( $self, $list ) = @_;
    return unless @$list > 0;
    foreach my $conf ( @$list ) {
	unless ( $conf =~ /^(.+?):([^:]+)/ ) {
	    print STDOUT ("<error $conf>\n");
	    next;
	}
	my ($sec, $conf) = ($1, $2);
	$sec =~ s/:+$//;
	my $val = $self->val($sec, $conf, undef);
	print STDOUT ($val) if defined $val;
	print STDOUT ("\n");
    }
}

sub user_dir {
    my ( $app, $item ) = @_;
    eval { $app = $app->app };

    if ( $^O =~ /^mswin/i ) {
	my $f = File::Spec->catpath( $ENV{HOMEDRIVE}, $ENV{HOMEPATH},
				     File::Spec->catfile( $app, $item ));

	return $f;
    }
    File::Spec->catfile( glob("~"),
			 "." . lc( $app),
			 defined($item) ? $item : (),
		       );
}

sub std_config {
    my ( $app ) = @_;
    eval { $app = $app->app };
    lc($app) . ".conf";
}

sub std_config_alt {
    "." . &std_config;
}

1;