This file is indexed.

/usr/sbin/grid-mapfile-add-entry is in globus-gss-assist-progs 11.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
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
#! /usr/bin/perl

# 
# Copyright 1999-2016 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.
# 

use strict;
use warnings;

use Fcntl qw( SEEK_END );
use Getopt::Long;

#
# grid-mapfile-add-entry
#

my $PROGRAM_NAME=$0; $PROGRAM_NAME =~ s|.*/||;
my $PROGRAM_VERSION="11.1";

my $VERSION="11.1";
my $PACKAGE="globus_gss_assist";

my $DIRT_TIMESTAMP="1506371041";
my $DIRT_BRANCH_ID="85";

my $NEW_GRID_MAP_FILE;
my $secconfdir="/etc/grid-security";
my $GRID_MAP_FILE = $ENV{GRIDMAP} || "${secconfdir}/grid-mapfile";
my $dryrun = 0;

my $short_usage="$PROGRAM_NAME -dn DN -ln LN [-help] [-d] [-f mapfile FILE]";

sub long_usage
{
    print STDERR <<EOF;
${short_usage}

$PROGRAM_NAME adds an entry to a Grid mapfile.

Options:
  -help, -usage           Displays help
  -version                Displays version
  -dn DN                  Distinguished Name (DN) to add. Remember to 
                          quote the DN if it contains spaces.
  -ln LN1 [LN2...]        Local login name(s) to map DN to
  -dryrun, -d             Shows what would be done but will not add the entry
  -mapfile FILE, -f FILE  Path of Grid map file to be used

EOF
}

sub globus_args_option_error
{
    print STDERR <<EOF;
ERROR: option $1 : $2

Syntax : ${short_usage}

Use -help to display full usage.
EOF
    exit(1);
}

my $help = 0;
my $version = 0;
my $versions = 0;
my $dn;
my @ln;
my $lnstring;

Getopt::Long::Configure('no_auto_abbrev');
GetOptions(
    "help|h|usage" => \$help,
    "version" => \$version,
    "versions" => \$versions,
    "dn=s" => \$dn,
    "ln=s{1,}" => \@ln,
    "d|dryrun" => \$dryrun,
    "f|mapfile=s" => \$GRID_MAP_FILE);
$lnstring = join(" ", @ln);
if ($help)
{
    &long_usage();
    exit(0);
}
elsif ($version)
{
    print "$0: ${PROGRAM_VERSION}\n";
    exit(0);
}
elsif ($versions)
{
    print "${PACKAGE}: ${VERSION} (${DIRT_TIMESTAMP}-${DIRT_BRANCH_ID})\n";
    exit(0);
}

if (scalar(@ln) == 0 || $dn eq '')
{
    print STDERR <<EOF;
Syntax : ${short_usage}

Use -help to display full usage.

EOF
    exit(1);
}


my $secure_tmpdir=$GRID_MAP_FILE;
if ($secure_tmpdir =~ m|/|) {
    $secure_tmpdir =~ s|/[^/]*$||;
} else {
    $secure_tmpdir = ".";
}


if (! (-r $secure_tmpdir && -w $secure_tmpdir) )
{
    print STDERR "ERROR: This script requires read/write permissions in ${secure_tmpdir}";
    exit(1);
}

$NEW_GRID_MAP_FILE="${secure_tmpdir}/.new_mapfile.$$";

# Verify mapfile existence
print "Modifying $GRID_MAP_FILE ...\n";
local(*GRID_MAP_FILE);

if (! -f $GRID_MAP_FILE)
{
    umask 022;
    open(GRID_MAP_FILE, "+>", $GRID_MAP_FILE)
        || die "ERROR: Could not create $GRID_MAP_FILE";
}
else
{
    open(GRID_MAP_FILE, "+<", $GRID_MAP_FILE)
        || globus_args_option_error("-f", \"${GRID_MAP_FILE}\" is not readable.");
}

# Change mode of existing map file to read only (logical UNIX lock)
chmod 0400, $GRID_MAP_FILE
    || die "ERROR: Could not change mode of $GRID_MAP_FILE\n";

print "Verifying that Local Name(s)=($lnstring) are legitimate local accounts.\n"
    if ($dryrun);

for my $name (@ln)
{
    print "Checking ln(s)=$name\n" if ($dryrun);

    my @s = getpwnam($name);
    if (scalar(@s) > 0)
    {
        print "Local Name=$name does exist\n" if ($dryrun);
    }
    else
    {
        my $res = $!;
        print "entry not added because the LN(s) is/are not legitimate\n";
        print "Local Name=$name does *NOT* exist\n" if ($dryrun);
        print "Entry *NOT* added\n" if ($dryrun);
        print "Result: $res\n" if ($dryrun);
        exit(1);
    }
}

print "Local Name(s)=($lnstring) is/are valid. Requested entry will be added.\n"
    if ($dryrun);


my $updated_existing_dn;

my $dn_already_exists=0;
my $omitted_map = "";
my $added_map = "";
my @map_entries=();
my $new_mapfile_entry="";
my $new_grid_mapfile_data="";
my $orig_grid_mapfile_data="";

while (my $line = <GRID_MAP_FILE>)
{
    my $existing_dn;
    my %existing_lns;

    $orig_grid_mapfile_data .= $line;

    chomp($line);
    next if ($line eq '');

    if ($line !~ m/^["][^"]*["]/ && $line !~ m/^[^"]/)
    {
        print "The following entry is missing a closing double quote\n";
        print "$line\n";
        exit(1);
    }
    if ($line =~ m/^"([^"]*)"\s+(.*)$/)
    {
        $existing_dn = $1;
        if ($existing_dn eq $dn)
        {
            push(@map_entries, split(",", $2));
            %existing_lns = map { $_ => 1 } @map_entries;
        }
    }
    elsif ($line =~ m/^([^"]\S+)\s+(.*$)/)
    {
        $existing_dn = $1;
        if ($existing_dn eq $dn)
        {
            push(@map_entries, split(",", $2));
            %existing_lns = map { $_ => 1 } @map_entries;
        }
    }

    if ($existing_dn eq $dn)
    {
        $dn_already_exists=1;
        for my $name (@ln)
        {
            if (exists $existing_lns{$name})
            {
                $omitted_map .= " $name";
            }
            else
            {
                $added_map .= " $name";
                push(@map_entries, $name);
            }
        }
    }
    else
    {
        $new_grid_mapfile_data .= "$line\n";
    }
}
push(@map_entries, @ln);
if (@map_entries)
{
    my %seen = ();
    my $delim="";
    $new_mapfile_entry = "\"$dn\" ";

    foreach my $entry (@map_entries) 
    {
        if (!exists $seen{$entry})
        {
            $new_mapfile_entry .= "${delim}${entry}";
            $delim=",";
            $seen{$entry} = 1;
        }
    }
    $new_grid_mapfile_data .= "$new_mapfile_entry\n";
}

# Verify that no changes to original map file
# during the execution of this program
local(*CONSISTENCY_CHECK);
open(CONSISTENCY_CHECK, "<", $GRID_MAP_FILE)
    || die "ERROR: Unable to compare $GRID_MAP_FILE with original contents\n";
my $consistency_check = "";
while (<CONSISTENCY_CHECK>)
{
    $consistency_check .= $_;
}
close(CONSISTENCY_CHECK);

if ($orig_grid_mapfile_data ne $consistency_check)
{
    print STDERR "ERROR: $GRID_MAP_FILE has changed since this program started\n";
    print STDERR "No changes will be made.\n";
    exit(1);
}
else
{
    local(*GRID_MAP_FILE_COPY);
    open(GRID_MAP_FILE_COPY, ">", "$GRID_MAP_FILE.old")
        || die "ERROR: Could not create a copy of $GRID_MAP_FILE\n";
    print GRID_MAP_FILE_COPY $orig_grid_mapfile_data;
    close(GRID_MAP_FILE_COPY);

    # Restore proper permissions to original grid map file
    chmod 0644, $GRID_MAP_FILE
        || die "ERROR: Could not change mode of $GRID_MAP_FILE\n";
}

if (!$dn_already_exists)
{
    if ($dryrun)
    {
        print "Appending new entry $new_mapfile_entry\n";
        print "Since ( dryrun, -d ) option was used no actions were carried out";
        exit(0);
    }
    seek(GRID_MAP_FILE, 0, SEEK_END);
    print GRID_MAP_FILE "$new_mapfile_entry\n";

    print "New entry:\n";
    print "$new_mapfile_entry\n";
    print "(1) entry added\n";
}
else
{
    print "DN $dn already exists\n";

    print "Updating entry to $new_mapfile_entry\n";
    if ($dryrun)
    {
        print "Since ( dryrun, -d ) option was used no actions were carried out\n";
        exit(0);
    }
    if ($added_map ne '')
    {
        local(*NEW_GRID_MAP_FILE);
        open(NEW_GRID_MAP_FILE, ">", $NEW_GRID_MAP_FILE)
            || die "Could not create temporary gridmap file $NEW_GRID_MAP_FILE\n";
        print NEW_GRID_MAP_FILE $new_grid_mapfile_data;
        close(NEW_GRID_MAP_FILE);
        rename($NEW_GRID_MAP_FILE, $GRID_MAP_FILE)
            || die "ERROR: Could not create a new $GRID_MAP_FILE\n";
        $NEW_GRID_MAP_FILE=undef;

        if ($omitted_map ne '')
        {
            $omitted_map=", already present and ignored:$omitted_map";
        }
        print "(added mappings:$added_map$omitted_map)\n";
        print "Updated entry:";
        print "$new_mapfile_entry\n";
        print "(1) entry modified\n";
    }
    else
    {
        print "No changes were made - already present and ignored:$omitted_map\n"
    }
}

END
{

    unlink($NEW_GRID_MAP_FILE) if ($NEW_GRID_MAP_FILE && -f $NEW_GRID_MAP_FILE);

    if ($GRID_MAP_FILE)
    {
        chmod 0644, $GRID_MAP_FILE
            || die "ERROR: Could not change mode of $GRID_MAP_FILE back to 0644";
    }
}