/usr/sbin/grid-mapfile-check-consistency is in globus-gss-assist-progs 9.0-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 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 | #! /usr/bin/perl
#
# Copyright 1999-2006 University of Chicago
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
# grid-mapfile-check-consistency
use strict;
use warnings;
use English;
use FileHandle;
use File::Spec;
use Getopt::Long;
# Prototypes
sub main ( @ );
sub check_gridmap_location ();
sub parse_options ();
sub display_help ();
sub display_version ();
sub verify_mapfile_existence ();
sub load_gridmap_file ( $ );
sub check_valid_login_names ( $ );
# Gridmap file name, handle, and hash
my $GRID_MAP_FILE = "";
my $gridmap_handle;
my %LINES;
# Gridmap file check status codes
my $existence_check = 0;
my $load_check = 0;
my $valid_login_names_check = 0;
# DiRT support
# DIRT_TIMESTAMP="1382981921"
# DIRT_BRANCH_ID="83"
# Invoke "main"
main ( @ARGV );
#######################################################################
# Function: main
# Description:
# Main function of the program
# Parameters:
# command line options
# Returns:
# 0 if checks passed
# 1 if gridmap file is not readable
# 2 if gridmap file is empty
# 3 if loading gridmap file failed (e.g. hardware errors)
# 4 if there are invalid login names in gridmap file
#######################################################################
sub main ( @ )
{
check_gridmap_location();
parse_options();
print "Checking " . $GRID_MAP_FILE . " grid mapfile\n";
print "Verifying grid mapfile existence...";
$existence_check = verify_mapfile_existence();
if ($existence_check == 1)
{
print "ERROR: " . $GRID_MAP_FILE . " file is not readable\n";
exit 1;
}
elsif ($existence_check == 2)
{
print "\nGrid mapfile " . $GRID_MAP_FILE . " is empty\n";
exit 2;
}
print "OK\n";
print "Checking for duplicate entries...";
$load_check = load_gridmap_file(\%LINES);
if ($load_check == 1)
{
print "ERROR: Cannot load " . $GRID_MAP_FILE . "\n";
exit 3;
}
elsif ($load_check == 0)
{
print "OK\n";
}
print "Checking for valid user names...";
$valid_login_names_check = check_valid_login_names(\%LINES);
if ($valid_login_names_check == 0)
{
print "OK\n";
}
elsif ($valid_login_names_check == 1)
{
exit 4;
}
exit 0;
}
#######################################################################
# Helper functions
#######################################################################
# Function: check_gridmap_location
# Description:
# Checks location of gridmap file conforming to rules
# defined by GSI
# Parameters:
# None
# Returns:
# None
#######################################################################
sub check_gridmap_location ()
{
if (defined $ENV{"GRIDMAP"})
{
$GRID_MAP_FILE = $ENV{"GRIDMAP"};
}
else
{
if ($REAL_USER_ID == 0)
{
$GRID_MAP_FILE = "/etc/grid-security/grid-mapfile";
}
else
{
my $local_gridmap_file = $ENV{"HOME"} . "/.gridmap";
if (-e $local_gridmap_file && -r $local_gridmap_file)
{
$GRID_MAP_FILE = $local_gridmap_file;
}
else
{
$GRID_MAP_FILE = "/etc/grid-security/grid-mapfile";
}
}
}
}
#######################################################################
# Function: parse_options
# Description:
# Parses script options. If gridmap file was specified,
# new value overrides previous one.
# Parameters:
# None
# Returns:
# 0 help of version options selected
#######################################################################
sub parse_options ()
{
my $parser;
my $help = 0;
my $version = 0;
my $mapfile = "";
$parser = new Getopt::Long::Parser;
$parser->getoptions("usage|help|h" => \$help,
"version|v" => \$version,
"mapfile|file|f=s" => \$mapfile);
if ($help == 1)
{
display_help();
exit 0;
}
elsif ($version == 1)
{
display_version();
exit 0;
}
elsif ($mapfile ne "")
{
$GRID_MAP_FILE = File::Spec->rel2abs($mapfile);
}
}
#######################################################################
# Function: display_help
# Description:
# Displays help information
# Parameters:
# None
# Returns:
# None
#######################################################################
sub display_help ()
{
my ($volume, $directory, $file) = File::Spec->splitpath($0);
print $file . " checks the consistency of the Grid mapfile\n";
print "Options:\n";
print "--help, -help, --usage, -usage, --h, -h Displays help\n";
print "--version, -version, --v, -v Displays version\n";
print "--mapfile FILE, -mapfile FILE, --file FILE,
-file FILE, --f FILE, -f FILE Path of gridmap to be used\n";
}
#######################################################################
# Function: display_version
# Description:
# Displays version information
# Parameters:
# None
# Returns:
# None
#######################################################################
sub display_version ()
{
my ($volume, $directory, $file) = File::Spec->splitpath($0);
my $program_version = '$Revision: 1.13 $';
$program_version =~ /Revision: ([\d\.]+)/;
print $file . ": " . $1 . "\n";
}
######################################################################
# Function: verify_mapfile_existence
# Description:
# If a gridmap file is a symlink, follows it.
# Checks if the gridmap file is readable.
# Checks if the gridmap file is writable.
# Checks if the gridmap file is empty.
# If the file is either non-writable or empty,
# appropriate warning is printed.
# Parameters:
# None
# Returns:
# 0 gridmap file is readable, writable and non-empty
# 1 gridmap file is non-readable (failed)
# 2 gridmap file is non-writable
#######################################################################
sub verify_mapfile_existence ()
{
if (-l $GRID_MAP_FILE)
{
my $link = readlink($GRID_MAP_FILE);
$GRID_MAP_FILE = $link;
}
if (! -r $GRID_MAP_FILE)
{
return 1;
}
if (! -w $GRID_MAP_FILE)
{
print "\nWARNING: Grid mapfile " . $GRID_MAP_FILE . " is not writable\n";
}
if (-z $GRID_MAP_FILE)
{
return 2;
}
return 0;
}
#####################################################
# Function: load_gridmap_file
# Description:
# Loads entire gridmap into a single hash.
# Single DN may be mapped to multiple users
# therefore hash contains lists not scalars.
# It speeds up later non-sequential access.
# It detects some errors:
# - missing double quotes
# - missing usernames
# - duplicate entries (logical names)
# Parameters:
# Hash which is to hold entire gridmap as lines
# Returns:
# 0 gridmap file loaded successfully
# 1 gridmap file loading failed
# 2 if there are duplicate entries
#####################################################
sub load_gridmap_file ( $ )
{
$gridmap_handle = new FileHandle ("< $GRID_MAP_FILE");
if (!defined ($gridmap_handle))
{
return 1;
}
my ($key, $value);
my $href = shift;
my $duplicate_counter = 0;
my $buffer;
while (! $gridmap_handle->eof() )
{
$buffer = $gridmap_handle->getline();
chomp ($buffer);
if ($buffer !~ /^\s*$/ && $buffer !~ /^\s*\#/)
{
$buffer =~ s/^\s*//;
$buffer =~ /^"(.*)"\s*(\S*)\s*$/;
if (! defined ($1))
{
print "\nERROR: Missing double quotes in the following entry: " . $buffer . "\n";
}
elsif (! defined ($2))
{
print "\nERROR: Missing user name(s) in the following entry: " . $buffer . "\n";
}
else
{
($key, $value) = ($1,$2);
if (exists ($$href{$key}) )
{
$duplicate_counter++;
print "\nERROR: Found duplicate entry: " . $buffer . "\n";
}
else
{
$$href{$key} = $value;
}
}
}
}
if ($duplicate_counter > 0)
{
print "ERROR: Found " . $duplicate_counter . " duplicate(s)\n";
return 2;
}
return 0;
}
#####################################################
# Function: check_valid_login_names
# Description:
# Checks all gridmap entries if user names are
# valid login names.
# If invalid user names are found, then each
# invalid entry is printed.
# Prints number of invalid entries if this
# number is non-zero.
# Parameters:
# Reference to a hash holding gridmap entries
# Returns:
# 0 all entries are valid
# 1 if there are invalid login names
#####################################################
sub check_valid_login_names ( $ )
{
my ($href, $entry, $user, $user_id);
my @user_names;
my %invalid_login_names = ();
$href = shift;
foreach $entry (values(%$href))
{
if ($entry =~ /,/)
{
@user_names = split (/,/, $entry);
}
else
{
$user_names[0] = $entry;
}
foreach $user (@user_names)
{
$user_id = getpwnam("$user");
if (! defined ($user_id) || $user_id < 0)
{
print "\nERROR: " . $user . " is not a valid local username\n";
if (! exists ($invalid_login_names{"$user"}) )
{
$invalid_login_names{"$user"} = 1;
}
}
}
}
my $counter = keys (%invalid_login_names);
if ($counter > 0)
{
print "ERROR: Found " . $counter . " invalid username(s)\n";
return 1;
}
else
{
return 0;
}
}
|