This file is indexed.

/usr/share/perl5/hostlist.pl is in libgenders-perl 1.17-4.

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
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
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
#############################################################################
#  $Id: hostlist.pl,v 1.9 2010-02-02 00:04:34 chu11 Exp $
#############################################################################
#  Copyright (C) 2007-2010 Lawrence Livermore National Security, LLC.
#  Copyright (C) 2001-2007 The Regents of the University of California.
#  Produced at Lawrence Livermore National Laboratory (cf, DISCLAIMER).
#  Written by Jim Garlick <garlick@llnl.gov>.
#  UCRL-CODE-2003-004.
#  
#  This file is part of Genders, a cluster configuration database and
#  rdist preprocessor.
#  For details, see <http://www.llnl.gov/linux/genders/>.
#  
#  Genders is free software; you can redistribute it and/or modify it under
#  the terms of the GNU General Public License as published by the Free
#  Software Foundation; either version 2 of the License, or (at your option)
#  any later version.
#  
#  Genders is distributed in the hope that it will be useful, but WITHOUT ANY
#  WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
#  FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more
#  details.
#  
#  You should have received a copy of the GNU General Public License along
#  with Genders.  If not, see <http://www.gnu.org/licenses/>.
#############################################################################

#
# Routines for reading, normalizing, and displaying lists of hosts.
#
package Hostlist;
 
use strict;
use Carp;

use Genders;

if (!$Hostlist::included) {
$Hostlist::included = 1;

# compress will generate a quadrics-style range if this is > 0
$Hostlist::quadrics_ranges = 0;

# Construct node list from hostlist file
#   $fileName (IN)	hostlist filename
#   RETURN		list of nodes
sub mk_file
{
	my ($fileName) = @_;
	my (@targetNodes);

	if (open(FILE, "< $fileName")) {
		while (<FILE>) {
			chomp;
			s/\*.*$//;              # strip comments (*)
			s/\!.*$//;              # strip comments (!)
			s/^\s+.*//;		# strip leading spaces
			s/.*\s+$//;		# strip trailing spaces
			next if (/^\s*$/);      # skip blank lines
			push(@targetNodes, $_);
		}
		close(FILE);
	}
	return @targetNodes;
}

# Construct node list from genders attribute name
#   $attrName (IN)	attribute name
#   RETURN		list of nodes
sub mk_gend
{
	my ($attrName) = @_;
        my $obj;

        $obj = Genders->new();
	return $obj->getnodes($attrName);
}

# Construct node list from command line
#   $cmdLine (IN)	comma-separated list of nodes 
#   RETURN		list of nodes
sub mk_cmdline
{
	my ($cmdLine) = @_;
	my (@targetNodes);

	@targetNodes = split(/,/, $cmdLine);
	return @targetNodes;
}

# Convert list of hostnames from reliable_hostname to initial_hostname.  
# OK if already initial_hostname.
#   @inList (IN)	list of reliable_hostnames
#   RETURN      	list of initial_hostnames
sub to_initial
{
	my (@inList) = @_;
	my (@outList, $node, $iname);

	foreach $node (@inList) {
		($node) = split(/\./, $node); 			# shorten name
		#$iname = Sdr::nn2sname(Sdr::ename2nn($node));	# convert
		push(@outList, $iname ? $iname : $node);
	}
	
	return @outList;
}

# Convert list of hostnames from initial_hostname to reliable_hostname.  
# OK if already reliable_hostname.
#   @inList (IN)	list of initial_hostnames
#   RETURN 		list of reliable_hostnames
sub to_reliable
{
	my (@inList) = @_;
	my (@outList, $node, $rname);

	foreach $node (@inList) {
		($node) = split(/\./, $node); 			# shorten name
		#$rname = Sdr::nn2ename(Sdr::sname2nn($node));	# convert
		push(@outList, $rname ? $rname : $node);
	}
	
	return @outList;
}

# Detect shell metacharacters in a hostlist entry.
#   $line (IN)		hostlist line
#   RETURN		true if metachars found, false otherwise
sub detect_metachar
{
	my ($line) = @_;

	return ($line =~ /(\;|\||\&)/);
}

# expand()
# turn a hostname range into a list of hostnames. Try to autodetect whether
# a quadrics-style range or a normal hostname range was passed in.
#
sub expand
{
	my ($list) = @_;

        # matching "[" "]" pair with stuff inside will be considered a quadrics
        # range:
        if ($list =~ /[^[]*\[.+\]/) {
		# quadrics ranges are separated by whitespace in RMS -
		# try to support that here
		$list =~ s/\s+/,/g;

		# 
		# Replace ',' chars internal to "[]" with ':"
		#
		while ($list =~ s/(\[[^\]]*),([^\[]*\])/$1:$2/) {}

		return map { expand_quadrics_range($_) } split /,/, $list;

	} else {
		return map { 
                            s/(\w*?)(\d+)-(\w*?)(\d+)/"$2".."$4"/ 
			                       || 
				          s/(.+)/""/; 
                            map {"$1$_"} eval; 
                           } split /,/, $list;
	}
}
			

# expand_quadrics_range
#
# expand nodelist in quadrics form 
#
sub expand_quadrics_range 
{
        my ($list) = @_;
        my ($pfx, $ranges) = split(/[\[\]]/, $list);

        return $list if (!defined $ranges);

        return map {"$pfx$_"} 
	           map { s/(\d+)-(\d+)/"$1".."$2"/; eval } 
		       split(/,|:/, $ranges);
}

# compress_to_quadrics
#
# compress a list of nodes to into a quadrics-style list of ranges
#
sub compress_to_quadrics 
{
	my (@list) = @_;
	local $Hostlist::quadrics_ranges = 1;
        return compress(@list) if @list;
}

# Turn long lists of nodes with numeric suffixes into ranges where possible
# optionally return a Quadrics-style range if $quadrics_ranges is nonzero.
#
#   @nodes (IN)         flat list of nodes
#   RETURN              list of nodes possibly containing ranges
#                       
sub compress {
    	my %rng = comp2(@_);
	my @list = ();

	local $"=",";

    	if (!$Hostlist::quadrics_ranges) {
       		foreach my $k (keys %rng) {
            		@{$rng{$k}} = map { "$k$_" } @{$rng{$k}};
		}
		@list = map { @{$rng{$_}} } sort keys %rng;

    	} else {
		@list = map {  $_ . 
	                      (@{$rng{$_}}>1 || ${$rng{$_}}[0] =~ /-/ ? 
		                       "[@{$rng{$_}}]" :
		                        "@{$rng{$_}}"                     
		              ) 
 		            } sort keys %rng;
    	}

	return wantarray ? @list : "@list"; 
}


# comp2():
# 
# takes a list of names and returns a hash of arrays, indexed by name prefix,
# each containing a list of numerical ranges describing the initial list.
#
# e.g.: %hash = comp2(lx01,lx02,lx03,lx05,dev0,dev1,dev21) 
#       will return:
#       $hash{"lx"}  = ["01-03", "05"]
#       $hash{"dev"} = ["0-1", "21"]
#
sub comp2 
{
    	my (%i) = ();
	my (%s) = ();

    	# turn off warnings here to avoid perl complaints about 
    	# uninitialized values for members of %i and %s
    	local ($^W) = 0;
        push(@{
               $s{$$_[0]}[ (
                            $s{ $$_[0] }[ $i{$$_[0]} ]
                              [$#{$s{$$_[0]}[$i{$$_[0]}]}] == ($$_[1]-1)
                           ) ? $i{$$_[0]} : ++$i{$$_[0]}
                         ]
              }, ($$_[1])
        ) for map { [/(.*?)(\d*)$/] } sortn(@_);

    	for my $key (keys %s) {
        	@{$s{$key}} = 
		    map { $#$_>0 ? "$$_[0]-$$_[$#$_]" : @{$_} }  @{$s{$key}};
    	} 
	
	
	return %s;
}

# uniq: remove duplicates from a hostlist
#
sub uniq
{
	my %seen   = ();
	grep { !$seen{$_}++ } @_;
}

# intersect(\@a, \@b): return the intersection of two lists, 
#                      i.e. those hosts in both @a and @b.
# IN : two array refs \@a , \@b
# OUT: flat list of hosts in =both= @a and @b
sub intersect
{
	my ($a, $b) = @_;
	(ref $a && ref $b) or 
	    croak "Error: arguments to intersect must be references";
	my @result = ();

	for my $hn (@$a) {
		push (@result, grep { $_ eq $hn } @$b);
	}

	return @result;
}

# union(\@a, \@b): return the union of two lists
#                  i.e. list of hosts from both @a and @b
# IN : two array refs \@a, \@b
# OUT: flat list of hosts from @a and @b
sub union
{
	my ($a, $b) = @_;
	(ref $a && ref $b) or 
	    croak "Error: arguments to union must be references";
	return uniq(@$a, @$b);
}

# diff(\@a, \@b): return the list of hosts in @a that are not in @b 
#		  i.e. hosts in @a - hosts in @b
# IN : two array refs \@a, \@b
# OUT: flat list of hosts in @a that are not in @b
sub diff
{
	my ($a, $b) = @_;
	(ref $a && ref $b) or 
	    croak "Error: arguments to diff must be references";
	my @result = ();

	for my $hn (@$a) {
		push(@result, $hn) if (!grep { $_ eq $hn } @$b); 
	}

	return @result;
}

# xor(\@a, \@b): exclusive OR hosts in @a and @b
#		 i.e. those hosts in @a and @b but not in both
# IN : two array refs \@a, \@b
# OUT: flat list of hosts in @a and @b but not in both
sub xor
{
	my ($a, $b) = @_;
	(ref $a && ref $b) or 
	    croak "Error: arguments to xor must be references";
	return (diff($a, $b), diff($b, $a));
}

# within(\@a, \@b): true if all hosts in @a are in @b
#		    i.e. is @a a subset of @b?
# IN : two array refs \@a, \@b
# OUT: true if @a is a subset of @b, false otherwise.
sub within
{
	my ($a, $b) = @_;
	(ref $a && ref $b) or 
	    croak "Error: arguments to within must be references";
	return (intersect($a, $b) == @$a)
}

# same(\@a, \@b) : true if @a and @b contain the exact same hosts
#		   i.e. are @a and @b the same list?
# IN : two array refs \@a, \@b
# OUT: true if @a is same as @b, false otherwise
sub same
{
	my ($a, $b) = @_;
	(ref $a && ref $b) or 
	    croak "arguments to same must be references";
	return (within($a, $b) && within($b, $a));
}

# sortn:
#
# sort a group of alphanumeric strings by the last group of digits on
# those strings, if such exists (good for numerically suffixed host lists)
#
sub sortn
{
	map {$$_[0]} sort {($$a[1]||0)<=>($$b[1]||0)} map {[$_,/(\d*)$/]} @_;
}


}	# Hostlist::included
1; 	# return a true value...