This file is indexed.

/usr/share/perl5/Debian/DocBase/Utils.pm is in doc-base 0.10.8.

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
# vim:cindent:ts=2:sw=2:et:fdm=marker:cms=\ #\ %s
#
# $Id: Utils.pm 223 2011-02-28 23:34:22Z robert $
#

package Debian::DocBase::Utils;

use Exporter();
use strict;
use warnings;

use vars qw(@ISA @EXPORT);
@ISA = qw(Exporter);
@EXPORT = qw(Execute HTMLEncode HTMLEncodeDescription Inform Debug Warn Error ErrorNF Fatal
            IgnoreSignals RestoreSignals SetupSignals ReadMap);

use Debian::DocBase::Common;
use Debian::DocBase::Gettext;

sub HTMLEncode($) { # {{{
  my $text        = shift;

  $text =~ s/&/&/g;
  $text =~ s/</&lt;/g;
  $text =~ s/>/&gt;/g;
  $text =~ s/"/&quot;/g;
  return $text;
} # }}}

sub HTMLEncodeDescription($) { # {{{
  my $text        = shift;

  $text = HTMLEncode($text);
  my @lines=split(/\n/, $text);
  $text = "";
  my $in_pre = 0;
  foreach $_  (@lines) {
    s/^\s//;
    if (/^\s/) {
      $_ = "<pre>\n$_" unless $in_pre;
      $in_pre = 1;
    } else {
      $_ = "$_\n<\\pre>" if $in_pre;
      $in_pre = 0;
    }
    s/^\.\s*$/<br>&nbsp;<br>/;
    s/(http|ftp)s?:\/([\w\/~\.%#-])+[\w\/]/<a href="$&">$&<\/a>/g;

    $text .= $_ . "\n";
   }
  $text .= "</pre>\n" if $in_pre;
  return $text;
} # }}}

sub Execute(@) { # {{{
  my @args = @_;
  my $sargs = join " ", @args;

  Fatal ($ERR_INTERNAL, _g("No arguments passed to %s.", "Execute()")) if $#args < 0;

  if (-x $args[0]) {
    Debug (_g("Executing `%s'"), $sargs);
    if (system(@args) != 0) {
      Warn (_g("Error occurred during execution of `%s'."), $sargs);
    }
  } else {
    Debug (_g("Skipping execution of `%s'."), $sargs);
  }
} # }}}


sub Debug(@) { # {{{
  printf STDOUT  ((shift) . "\n", @_) if $opt_debug;
} #  }}}

sub Inform(@) { # {{{
  printf STDOUT ((shift) . "\n", @_);
} # }}}

sub Warn(@) { # {{{
  printf STDERR ((shift) . "\n", @_) if $opt_verbose;
} # }}}

sub Error(@) { # {{{
  printf STDERR ((shift) . "\n", @_);
  $exitval = $ERR_PARSING;
} # }}}

# non-fatal error - doesn't set exitval
sub ErrorNF(@) { # {{{
  printf STDERR ((shift) . "\n", @_);
} # }}}

# fatal error, runs $on_fatal_handler and exits
sub Fatal($@) { # {{{
  my $errCode = shift;

  print STDERR _g("Internal error: ") if $errCode == $ERR_INTERNAL;
  print STDERR _g("Database error: ") if $errCode == $ERR_DATABASE;

  printf STDERR ((shift) . "\n", @_);
  if ($on_fatal_handler and $errCode != $ERR_DATABASE)
  {
    Debug(_g("Running fatal errors handler."));
    my $handler = $on_fatal_handler;
    $on_fatal_handler = undef;
    $handler->();
  }
  exit ($errCode);
} # }}}

{ # Signal handling routines - IgnoreSignals, RestoreSignals, SetupSignals # {{{

sub _SigHandler { # {{{
  Fatal($ERR_PROCESSING, _g("Signal %s received, terminating."), shift);
} # }}}

our %sigactions = ('ignore_cnt' => 0);

sub _IgnoreRestoreSignals($) { # {{{
  my $mode      = shift;

  my $ign_cnt   = undef;


  if ($mode eq "ignore") {
    $ign_cnt = $sigactions{'ignore_cnt'}++;
    Debug(_g("Ignore signals."));

  } elsif ($mode eq "restore") {
    $ign_cnt = --$sigactions{'ignore_cnt'};
    Debug(_g("Restore signals."));

  } elsif ($mode eq "setup") {
    Debug(_g("Setup signals."));
  }
  else {
    Fatal($ERR_INTERNAL, _g("Invalid argument of IgnoreRestoreSignals(): %s."), $mode);
  }

  if ($mode ne "setup")
  {
    Fatal($ERR_INTERNAL, _g("Invalid counter (%d) in IgnoreRestoreSignals(%s)."), $ign_cnt, $mode)
      if $ign_cnt < 0;

    return unless $ign_cnt == 0;
  }

  foreach my $sig ('INT', 'QUIT', 'HUP', 'TSTP', 'TERM') {
    if ($mode eq "ignore") {
      $sigactions{$sig} = $SIG{$sig} if defined $SIG{$sig};
      $SIG{$sig} = "IGNORE";
    } elsif ($mode eq "restore") {
      $SIG{$sig} = defined $sigactions{$sig} ? $sigactions{$sig} : "DEFAULT";
    } elsif ($mode eq "setup") {
      $SIG{$sig} = \&_SigHandler;
    } else {
      Fatal($ERR_INTERNAL, _g("Invalid argument of IgnoreRestoreSignals(): %s."), $mode);
    }
  }
} # }}}

sub IgnoreSignals() {
  return _IgnoreRestoreSignals("ignore");
}


sub RestoreSignals() {
  return _IgnoreRestoreSignals("restore");
}

sub SetupSignals() {
  return _IgnoreRestoreSignals("setup");
}
} # }}}


sub ReadMap($$;$) { # {{{
  my $file    = shift;
  my $map     = shift;
  my $defval  = shift;
  $defval     = "" unless $defval;
  open (MAP, "<", $file) or Fatal($ERR_FSACCESS, _g("Cannot open file `%s' for reading: %s."), $file, $!);
  while(<MAP>) {
          chomp;
          next if /^\s*$/;
          next if /^#/;
          my ($lv,$rv) = split(/\s*:\s*/, $_, 2);
          $map->{lc($lv)} = $rv ? $rv : $defval;
  }
  close(MAP);
} # }}}



1;