This file is indexed.

/usr/bin/xen-list-images is in xen-tools 4.2.1-1.

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
342
343
344
#!/usr/bin/perl -w

=head1 NAME

xen-list-images - List all the created and configured Xen images.

=head1 SYNOPSIS

  xen-list-image [options]

  Help Options:
   --help     Show this scripts help information.
   --manual   Read this scripts manual.
   --version  Show the version number and exit.

  Testing options:
   --test     Specify an alternate Xen configuration directory.

=head1 OPTIONS

=over 8

=item B<--help>
Show the scripts help information.

=item B<--manual>
Read the manual.

=item B<--test>
This flag causes the script to load the Xen configuration files from a different directory than the default of B</etc/xen>.

=item B<--version>
Show the version number and exit.

=back


=head1 DESCRIPTION

  xen-list-images is a simple script which will display all the
 Xen images which have been created.

  This works by iterating over all files matching the pattern
 /etc/xen/*.cfg which is what the xen-create-image script would
 create.

  For each instance which has been created we'll display the name,
 and then either the IP address configured, or "DHCP" to denote
 a dynamic host.

=cut

=head1 TODO

  It should be possible to determine the disk(s) used by the images,
 and then display their sizes.

=cut


=head1 AUTHORS

 Steve Kemp, http://www.steve.org.uk/
 Stéphane Jourdois

=cut

=head1 LICENSE

Copyright (c) 2005-2009 by Steve Kemp, (c) 2010 by The Xen-Tools
Development Team. All rights reserved.

This module is free software;
you can redistribute it and/or modify it under
the same terms as Perl itself.
The LICENSE file contains the full text of the license.

=cut


use strict;
use English;
use File::Temp qw/ tempdir /;
use Getopt::Long;
use Pod::Usage;


#
#  Configuration options, initially read from the configuration files
# but may be overridden by the command line.
#
#  Command line flags *always* take precedence over the configuration file.
#
my %CONFIG;

#
#  Default prefix
#
$CONFIG{ 'prefix' } = "/etc/xen";

#
# Release number.
#
my $RELEASE = '4.2.1';



#
#  Read the global configuration file if it exists.
#
readConfigurationFile("/etc/xen-tools/xen-tools.conf");


#
#  Parse command line arguments, these override the values from the
# configuration file.
#
parseCommandLineArguments();


#
#  Read all the xen configuration files.
#
my @instances = findXenInstances();


#
#  Now process each instance.
#
my $count = 0;
foreach my $instance (@instances)
{
    if ($count) {print "\n";}

    displayInstance($instance);
    $count += 1;
}


#
#  All done.
#
exit;



=begin doc

  Read the configuration file specified.

=end doc

=cut

sub readConfigurationFile
{
    my ($file) = (@_);

    # Don't read the file if it doesn't exist.
    return if ( !-e $file );

    open( FILE, "<", $file ) or die "Cannot read file '$file' - $!";


    while ( defined( my $line = <FILE> ) )
    {
        chomp $line;
        if ( $line =~ s/\\$// )
        {
            $line .= <FILE>;
            redo unless eof(FILE);
        }

        # Skip lines beginning with comments
        next if ( $line =~ /^([ \t]*)\#/ );

        # Skip blank lines
        next if ( length($line) < 1 );

        # Strip trailing comments.
        if ( $line =~ /(.*)\#(.*)/ )
        {
            $line = $1;
        }

        # Find variable settings
        if ( $line =~ /([^=]+)=([^\n]+)/ )
        {
            my $key = $1;
            my $val = $2;

            # Strip leading and trailing whitespace.
            $key =~ s/^\s+//;
            $key =~ s/\s+$//;
            $val =~ s/^\s+//;
            $val =~ s/\s+$//;

            # command expansion?
            if ( $val =~ /(.*)`([^`]+)`(.*)/ )
            {

                # store
                my $pre  = $1;
                my $cmd  = $2;
                my $post = $3;

                # get output
                my $output = `$cmd`;
                chomp($output);

                # build up replacement.
                $val = $pre . $output . $post;
            }

            # Store value.
            $CONFIG{ $key } = $val;
        }
    }
    close(FILE);
}



=begin doc

  Parse the arguments specified upon the command line.

=end doc

=cut

sub parseCommandLineArguments
{
    my $HELP    = 0;
    my $MANUAL  = 0;
    my $VERSION = 0;

    #  Parse options.
    #
    GetOptions( "test=s", \$CONFIG{ 'prefix' },
                "help", \$HELP,
                "manual", \$MANUAL,
                "version", \$VERSION );

    pod2usage(1) if $HELP;
    pod2usage( -verbose => 2 ) if $MANUAL;


    if ($VERSION)
    {
        my $REVISION = '$Revision: 1.30 $';
        if ( $REVISION =~ /1.([0-9.]+) / )
        {
            $REVISION = $1;
        }

        print "xen-list-images release $RELEASE - CVS: $REVISION\n";
        exit;
    }
}



=begin doc

  Return an array containing the names of each xen configuration
 file we found.

=end doc

=cut

sub findXenInstances
{
    my @found;

    foreach my $file ( sort( glob( $CONFIG{ 'prefix' } . "/*.cfg" ) ) )
    {
        push @found, $file if ( -e $file );
    }

    return (@found);
}



=begin doc

  Show details about the the Xen instance contained in the given
 configuration file.

=end doc

=cut

sub displayInstance
{
    my ($file) = (@_);

    #
    #  Read each line.
    #
    open( FILY, "<", $file );
    my @LINES = <FILY>;
    close(FILY);

    #
    #  Is it dynamic?
    #
    my $dhcp = 0;
    my $ip   = '';
    my $mac  = '';
    my $name = '';
    my $mem  = 0;

    foreach my $line (@LINES)
    {
        if ( $line =~ /^\s*dhcp\s*=\s*"dhcp\"/i )
        {
            $dhcp = 1;
        }
        if ( $line =~ /^\s*name\s*=\s*["']([^'"]+)['"]/i )
        {
            $name = $1;
        }
        if ( $line =~ /.*memory[^0-9]*([0-9]+)/i )
        {
            $mem = $1;
        }
        if ( $line =~ /ip=([0-9\.]+)/ )
        {
            $ip = $1;
        }
        if ( $line =~ /mac=['\"]([^'\"]+)['\"]/ )
        {
            $mac = " [MAC: $1]";
        }
    }

    print "Name: $name\n";
    print "Memory: $mem\n";
    print "IP: " . $ip . $mac . "\n" if length($ip);
    print "DHCP" . $mac . "\n" if $dhcp;
}