This file is indexed.

/usr/sbin/a2enmod is in apache2.2-common 2.2.22-1ubuntu1.11.

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

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
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
#!/usr/bin/perl -w
#
# a2enmod by Stefan Fritsch <sf@debian.org>
# Licensed under Apache License 2.0

use strict;
use Cwd 'realpath';
use File::Spec;
use File::Basename;
use Getopt::Long;

my $quiet;
my $force;
Getopt::Long::Configure('bundling');
GetOptions(
    'quiet|q' => \$quiet,
    'force|f' => \$force
) or exit 2;

my $basename = basename($0);
$basename =~ /^a2(en|dis)(mod|site)((?:-.+)?)$/
    or die "$basename call name unknown\n";
my $act        = $1;
my $obj        = $2;
my $dir_suffix = $3;

my $env_file = $ENV{APACHE_ENVVARS}
    || (
    $ENV{APACHE_CONFDIR}
    ? "$ENV{APACHE_CONFDIR}/envvars"
    : "/etc/apache2$dir_suffix/envvars"
    );
$ENV{LANG}='C';
read_env_file($env_file);

$act .= 'able';
my ( $name, $dir, $sffx, $reload );
if ( $obj eq 'mod' ) {
    $obj    = 'module';
    $dir    = 'mods';
    $sffx   = '.load';
    $reload = 'restart';
}
else {
    $dir    = 'sites';
    $sffx   = '';
    $reload = 'reload';
}
$name = ucfirst($obj);

my $confdir  = $ENV{APACHE_CONFDIR}                  || "/etc/apache2$dir_suffix";
my $availdir = $ENV{ uc("APACHE_${dir}_AVAILABLE") } || "$confdir/$dir-available";
my $enabldir = $ENV{ uc("APACHE_${dir}_ENABLED") }   || "$confdir/$dir-enabled";

my $choicedir = $act eq 'enable' ? $availdir : $enabldir;
my $linkdir = File::Spec->abs2rel( $availdir, $enabldir );

my $request_reload = 0;

my $rc = 0;

if ( !scalar @ARGV ) {
    my @choices = myglob('*');
    print "Your choices are: @choices\n";
    print "Which ${obj}(s) do you want to $act (wildcards ok)?\n";
    my $input = <>;
    @ARGV = split /\s+/, $input;

}

my @objs;
foreach my $arg (@ARGV) {
    my @glob = myglob($arg);
    if ( !@glob ) {
        error("No $obj found matching $arg!\n");
        $rc = 1;
    }
    else {
        push @objs, @glob;
    }
}

foreach my $acton (@objs) {
    doit($acton) or $rc = 1;
}

info("To activate the new configuration, you need to run:\n  service apache2 $reload\n")
    if $request_reload;

exit($rc);

##############################################################################

sub myglob {
    my $arg = shift;

    my @glob = map {
        s{^$choicedir/}{};
        s{$sffx$}{};
        s{^000-default$}{default};
        $_
    } glob("$choicedir/$arg$sffx");

    # use same rules as apache's Include directive
    @glob = grep( /^[[:alnum:]][-._[:alnum:]]*$/, @glob );
    @glob = grep( !/\.dpkg/, @glob );

    return @glob;
}

sub doit {
    my $acton = shift;

    my $prio = "";
    if ( $obj eq 'site' && $acton eq 'default' ) {
        $prio = '000-';
    }

    my ( $conftgt, $conflink );
    if ( $obj eq 'module' ) {
        if ( $acton eq 'cgi' && threaded() ) {
            print "Your MPM seems to be threaded. Selecting cgid instead of cgi.\n";
            $acton = 'cgid';
        }

        $conftgt = "$availdir/$acton.conf";
        if ( -e $conftgt ) {
            $conflink = "$enabldir/$acton.conf";
        }
    }

    my $tgt  = "$availdir/$acton$sffx";
    my $link = "$enabldir/$prio$acton$sffx";

    if ( !-e $tgt ) {
        if ( -l $link && !-e $link ) {
		if ( $act eq 'disable' ) {
			info("removing dangling symlink $link\n");
			unlink($link);
			return 1;
		}
		else {
			error("$link is a dangling symlink!\n");
		}
	}

        error("$name $acton does not exist!\n");
        return 0;
    }

    # handle module dependencies
    if ( $obj eq 'module' ) {
        if ( $act eq 'enable' ) {
            my $depends = qx{grep "# Depends:" "$availdir/$acton.load"|cut -f2 -d:};
            $depends =~ s,^[\s\n]+,,;
            $depends =~ s,[\s\n]+$,,;
            do_deps( $acton, split( /[\n\s]+/, $depends ) ) or return 0;
        }
        else {
            my @depends = qx{egrep "# Depends:.*${acton}( |\$)" $enabldir/*.load};
            @depends = grep {s{^.*?/([^/]*?)\.load:.*}{$1}s} @depends;
            if ( scalar @depends ) {
                if ($force) {
                    do_deps( $acton, @depends ) or return 0;
                }
                else {
                    error(
                        "The following modules depend on $acton ",
                        "and need to be disabled first: @depends\n"
                    );
                    return 0;
                }
            }
        }
    }

    if ( $act eq 'enable' ) {
        my $check = check_link( $tgt, $link );
        if ( $check eq 'ok' ) {
            if ($conflink) {

                # handle .conf file
                my $confcheck = check_link( $conftgt, $conflink );
                if ( $confcheck eq 'ok' ) {
                    info("$name $acton already enabled\n");
                    return 1;
                }
                elsif ( $confcheck eq 'missing' ) {
                    print "Enabling config file $acton.conf.\n";
                    add_link( $conftgt, $conflink ) or return 0;
                }
                else {
                    error("Config file $acton.conf not properly enabled: $confcheck\n");
                    return 0;
                }
            }
            else {
                info("$name $acton already enabled\n");
                return 1;
            }
        }
        elsif ( $check eq 'missing' ) {
            if ($conflink) {

                # handle .conf file
                my $confcheck = check_link( $conftgt, $conflink );
                if ( $confcheck eq 'missing' ) {
                    add_link( $conftgt, $conflink ) or return 0;
                }
                elsif ( $confcheck ne 'ok' ) {
                    error("Config file $acton.conf not properly enabled: $confcheck\n");
                    return 0;
                }
            }

            print "Enabling $obj $acton.\n";
            if ( $acton eq 'ssl' ) {
                info("See /usr/share/doc/apache2.2-common/README.Debian.gz on " .
                     "how to configure SSL and create self-signed certificates.\n");
	    }
            return add_link( $tgt, $link );
        }
        else {
            error("$name $acton not properly enabled: $check\n");
            return 0;
        }
    }
    else {
        if ( -e $link || -l $link ) {
            remove_link($link);
            if ( $conflink && -e $conflink ) {
                remove_link($conflink);
            }
            print "$name $acton disabled.\n";
        }
        elsif ( $conflink && -e $conflink ) {
            print "Disabling stale config file $acton.conf.\n";
            remove_link($conflink);
        }
        else {
            info("$name $acton already disabled\n");
            return 1;
        }
    }

    return 1;
}

sub do_deps {
    my $acton = shift;
    foreach my $d (@_) {
        info("Considering dependency $d for $acton:\n");
        if ( !doit($d) ) {
            error("Could not $act dependency $d for $acton, aborting\n");
            return 0;
        }
    }
    return 1;
}

sub add_link {
    my ( $tgt, $link ) = @_;

    # create relative link
    if ( !symlink( File::Spec->abs2rel( $tgt, dirname($link) ), $link ) ) {
        die("Could not create $link: $!\n");
    }
    $request_reload = 1;
    return 1;
}

sub check_link {
    my ( $tgt, $link ) = @_;

    if ( !-e $link ) {
        if ( -l $link ) {

            # points to nowhere
            info("Removing dangling link $link");
            unlink($link) or die "Could not remove $link\n";
        }
        return 'missing';
    }

    if ( -e $link && !-l $link ) {
        return "$link is a real file, not touching it";
    }
    if ( realpath($link) ne realpath($tgt) ) {
        return "$link exists but does not point to $tgt, not touching it";
    }
    return 'ok';
}

sub remove_link {
    my ($link) = @_;

    if ( -l $link ) {
        unlink($link) or die "Could not remove $link: $!\n";
    }
    elsif ( -e $link ) {
        error("$link is not a symbolic link, not deleting\n");
        return 0;
    }
    $request_reload = 1;
    return 1;
}

sub threaded {
    my $result = "";
    $result = qx{/usr/sbin/apache2 -V | grep 'threaded'} if -x '/usr/sbin/apache2';
    if ( $result =~ / no/ ) {
        return 0;
    }
    else {
        return 1;
    }
}

sub info {
    print @_ if !$quiet;
}

sub error {
    print STDERR 'ERROR: ', @_;
}

sub read_env_file {
    my $file = shift;

    -r $file or return;
    my @lines = qx{env - sh -c '. $file && env'};
    if ($?) {
        die "Could not read $file\n";
    }

    foreach my $l (@lines) {
        chomp $l;
        $l =~ /^(.*)?=(.*)$/ or die "Could not parse $file\n";
        $ENV{$1} = $2;
    }
}